mirror of
https://github.com/letta-ai/claude-subconscious.git
synced 2026-04-25 17:04:56 +02:00
Use a shared URL builder across scripts and update createConversation to call /v1/conversations/ with query params to avoid HTTPS->HTTP redirect failures behind reverse proxies. This also deduplicates LETTA_API_BASE handling and adds regression tests for trailing-slash behavior. 👾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta Code <noreply@letta.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import {
|
|
buildLettaApiUrl,
|
|
getLettaApiBase,
|
|
normalizeLettaBaseUrl,
|
|
} from './letta_api_url.js';
|
|
|
|
describe('letta_api_url', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it('normalizes base URL by trimming trailing slash', () => {
|
|
expect(normalizeLettaBaseUrl('https://example.com/')).toBe(
|
|
'https://example.com',
|
|
);
|
|
expect(normalizeLettaBaseUrl('https://example.com///')).toBe(
|
|
'https://example.com',
|
|
);
|
|
});
|
|
|
|
it('builds /v1 base URL unless already present', () => {
|
|
expect(getLettaApiBase('https://example.com')).toBe(
|
|
'https://example.com/v1',
|
|
);
|
|
expect(getLettaApiBase('https://example.com/v1')).toBe(
|
|
'https://example.com/v1',
|
|
);
|
|
});
|
|
|
|
it('builds URLs with optional query params', () => {
|
|
const url = buildLettaApiUrl('/agents/agent-123', {
|
|
include: 'agent.blocks',
|
|
limit: 20,
|
|
});
|
|
|
|
expect(url).toBe(
|
|
'https://api.letta.com/v1/agents/agent-123?include=agent.blocks&limit=20',
|
|
);
|
|
});
|
|
|
|
it('preserves trailing slash path for conversations create endpoint', () => {
|
|
const url = buildLettaApiUrl('/conversations/', { agent_id: 'agent-123' });
|
|
|
|
expect(url).toBe(
|
|
'https://api.letta.com/v1/conversations/?agent_id=agent-123',
|
|
);
|
|
});
|
|
}); |