diff --git a/packages/sdk-ts/src/index.test.ts b/packages/sdk-ts/src/index.test.ts index 4f9947a..a5cdf53 100644 --- a/packages/sdk-ts/src/index.test.ts +++ b/packages/sdk-ts/src/index.test.ts @@ -359,6 +359,32 @@ describe("response deserialization preserves all fields from the wire", () => { ); }); + it("deserializeIngestPathResult accepts the legacy created-memory list shape", () => { + const result = deserializeIngestPathResult({ memories: [ + { + memory_id: "11111111-1111-4111-8111-111111111111", + content: "c", + source_type: SourceType.File, + source_ref: "file://README.md", + scope: Scope.Repo, + scope_ref: "repo", + created_at: "2024-01-01T00:00:00.000Z", + updated_at: "2024-01-01T00:00:00.000Z", + expires_at: null, + trust_score: 0.8, + sensitivity: Sensitivity.Internal, + status: MemoryStatus.Active, + contradicts: [], + tags: [], + }, + ] }); + + expect(result).toEqual({ + created: 1, + memoryIds: ["11111111-1111-4111-8111-111111111111"], + }); + }); + it("deserializeContradiction preserves memoryId, sourceRef, status, reason, confidence", () => { fc.assert( fc.property(contradictionWireArb, (wire) => { diff --git a/packages/sdk-ts/src/index.ts b/packages/sdk-ts/src/index.ts index e5bc5a5..c48bed1 100644 --- a/packages/sdk-ts/src/index.ts +++ b/packages/sdk-ts/src/index.ts @@ -289,8 +289,10 @@ export interface QueryResponseWire { /** Wire shape of `IngestPathResponse` (snake_case). */ export interface IngestPathResponseWire { - created: number; - memory_ids: string[]; + created?: number; + memory_ids?: string[]; + /** Legacy OSS API shape: the created records themselves. */ + memories?: MemoryWire[]; } /** Wire shape of `ContradictionResponse` (snake_case). */ @@ -436,9 +438,11 @@ export function deserializeQueryResponse(wire: QueryResponseWire): QueryResponse export function deserializeIngestPathResult( wire: IngestPathResponseWire, ): IngestPathResult { + const memoryIds = + wire.memory_ids ?? wire.memories?.map((memory) => memory.memory_id) ?? []; return { - created: wire.created, - memoryIds: wire.memory_ids ?? [], + created: wire.created ?? wire.memories?.length ?? memoryIds.length, + memoryIds, }; } @@ -651,9 +655,10 @@ export class MemoryGuard { "/v1/ingest/path", serializeIngestPathRequest(request) as unknown as Record, ); - return deserializeIngestPathResult( - unwrapObject(payload, "result"), - ); + const response = Array.isArray(payload) + ? { memories: payload as MemoryWire[] } + : unwrapObject(payload, "result"); + return deserializeIngestPathResult(response); } /**