Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/sdk-ts/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
19 changes: 12 additions & 7 deletions packages/sdk-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -651,9 +655,10 @@ export class MemoryGuard {
"/v1/ingest/path",
serializeIngestPathRequest(request) as unknown as Record<string, unknown>,
);
return deserializeIngestPathResult(
unwrapObject<IngestPathResponseWire>(payload, "result"),
);
const response = Array.isArray(payload)
? { memories: payload as MemoryWire[] }
: unwrapObject<IngestPathResponseWire>(payload, "result");
return deserializeIngestPathResult(response);
}

/**
Expand Down
Loading