@nirmos/sdk 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -16
- package/dist/cjs/core/transport.js +16 -3
- package/dist/cjs/core/transport.js.map +1 -1
- package/dist/cjs/core/version.js +6 -0
- package/dist/cjs/core/version.js.map +1 -0
- package/dist/cjs/gateway/chat-stream.js +10 -0
- package/dist/cjs/gateway/chat-stream.js.map +1 -1
- package/dist/cjs/gateway/chat.js +1 -0
- package/dist/cjs/gateway/chat.js.map +1 -1
- package/dist/cjs/gateway/embeddings.js +1 -0
- package/dist/cjs/gateway/embeddings.js.map +1 -1
- package/dist/cjs/gateway/mappers.js +39 -2
- package/dist/cjs/gateway/mappers.js.map +1 -1
- package/dist/esm/core/transport.js +15 -2
- package/dist/esm/core/transport.js.map +1 -1
- package/dist/esm/core/version.d.ts +2 -0
- package/dist/esm/core/version.d.ts.map +1 -0
- package/dist/esm/core/version.js +3 -0
- package/dist/esm/core/version.js.map +1 -0
- package/dist/esm/gateway/chat-stream.d.ts.map +1 -1
- package/dist/esm/gateway/chat-stream.js +11 -1
- package/dist/esm/gateway/chat-stream.js.map +1 -1
- package/dist/esm/gateway/chat.d.ts.map +1 -1
- package/dist/esm/gateway/chat.js +1 -0
- package/dist/esm/gateway/chat.js.map +1 -1
- package/dist/esm/gateway/embeddings.d.ts.map +1 -1
- package/dist/esm/gateway/embeddings.js +1 -0
- package/dist/esm/gateway/embeddings.js.map +1 -1
- package/dist/esm/gateway/mappers.d.ts +2 -0
- package/dist/esm/gateway/mappers.d.ts.map +1 -1
- package/dist/esm/gateway/mappers.js +38 -2
- package/dist/esm/gateway/mappers.js.map +1 -1
- package/dist/esm/gateway/types.d.ts +8 -0
- package/dist/esm/gateway/types.d.ts.map +1 -1
- package/dist/esm/management/contracts.d.ts +82 -0
- package/dist/esm/management/contracts.d.ts.map +1 -1
- package/dist/esm/memory/types.d.ts +14 -5
- package/dist/esm/memory/types.d.ts.map +1 -1
- package/examples/memory-quickstart.mjs +199 -0
- package/examples/memory-quickstart.ts +240 -0
- package/examples/tsconfig.json +5 -0
- package/package.json +5 -4
- package/src/core/transport.ts +14 -2
- package/src/core/version.ts +2 -0
- package/src/gateway/chat-stream.ts +12 -1
- package/src/gateway/chat.ts +1 -0
- package/src/gateway/embeddings.ts +1 -0
- package/src/gateway/mappers.ts +55 -2
- package/src/gateway/types.ts +8 -0
- package/src/management/contracts.ts +14 -14
- package/src/memory/types.ts +15 -4
|
@@ -65,6 +65,10 @@ export interface MemorySearchFilters {
|
|
|
65
65
|
export interface MemorySearchRequest {
|
|
66
66
|
memorySpaceId: string;
|
|
67
67
|
query: string;
|
|
68
|
+
/** Default relevant: one bounded model check. Raw returns nearest neighbors without validation. */
|
|
69
|
+
relevance?: "relevant" | "raw";
|
|
70
|
+
/** Minimum normalized vector similarity (0–1), before ranking. Calibrate per embedding model. */
|
|
71
|
+
minScore?: number;
|
|
68
72
|
limit?: number;
|
|
69
73
|
filters?: MemorySearchFilters;
|
|
70
74
|
}
|
|
@@ -75,14 +79,19 @@ export type MemoryResult = Pick<MemoryItem, "id" | "content" | "type" | "layer"
|
|
|
75
79
|
export interface MemorySearchResponse {
|
|
76
80
|
memories: Array<MemoryResult & {
|
|
77
81
|
score: number;
|
|
82
|
+
similarityScore: number;
|
|
78
83
|
}>;
|
|
84
|
+
relevance: "relevant" | "raw";
|
|
79
85
|
}
|
|
80
|
-
export
|
|
81
|
-
memories: Array<MemoryResult & {
|
|
82
|
-
score?: number;
|
|
83
|
-
}>;
|
|
84
|
-
}
|
|
86
|
+
export type MemoryContextResponse = MemorySearchResponse;
|
|
85
87
|
export interface MemoryIndexingResult {
|
|
88
|
+
/** Safe stage/provider diagnostics for partial indexing failures. */
|
|
89
|
+
diagnostics?: Array<{
|
|
90
|
+
code: string;
|
|
91
|
+
status: number;
|
|
92
|
+
retryable: boolean;
|
|
93
|
+
details?: Record<string, unknown>;
|
|
94
|
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edit.
|
|
2
|
+
import { APIError, Nirmos, } from "@nirmos/sdk";
|
|
3
|
+
async function all(load) {
|
|
4
|
+
const items = [];
|
|
5
|
+
let cursor;
|
|
6
|
+
do {
|
|
7
|
+
const page = await load(cursor);
|
|
8
|
+
items.push(...page.items);
|
|
9
|
+
cursor = page.nextCursor ?? undefined;
|
|
10
|
+
} while (cursor);
|
|
11
|
+
return items;
|
|
12
|
+
}
|
|
13
|
+
/** Server-side only. Persist eventKey with the source event before first ingestion. */
|
|
14
|
+
export async function memoryQuickstart(client, options) {
|
|
15
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, options.paceMs ?? 20000));
|
|
16
|
+
const provider = (await all((cursor) => client.providers.list({ cursor, limit: 100 }))).find((p) => p.slug === "google");
|
|
17
|
+
if (!provider)
|
|
18
|
+
throw new Error("Google provider missing from this deployment's catalog.");
|
|
19
|
+
// Optional SDK setup; dashboard Gateway Credentials → Add credential → Google is equivalent.
|
|
20
|
+
if (options.googleApiKey)
|
|
21
|
+
await client.providerCredentials.create({
|
|
22
|
+
name: "Memory quickstart Google",
|
|
23
|
+
providerId: provider.id,
|
|
24
|
+
credentialType: "api_key",
|
|
25
|
+
secretData: { apiKey: options.googleApiKey },
|
|
26
|
+
isDefault: true,
|
|
27
|
+
});
|
|
28
|
+
const models = await all((cursor) => client.models.list({ providerId: provider.id, limit: 100, cursor }));
|
|
29
|
+
const text = models.find((m) => m.slug === "google-gemini-2-5-flash-lite" && m.availability);
|
|
30
|
+
const embedding = models.find((m) => m.slug === "google-gemini-embedding-001" && m.availability);
|
|
31
|
+
if (!text || !embedding)
|
|
32
|
+
throw new Error("Configure an active Google credential and verify both models in models.list(). Availability does not guarantee provider quota.");
|
|
33
|
+
if (!embedding.knowledgeSupportedDimensions?.includes(768))
|
|
34
|
+
throw new Error("Selected embedding model does not support 768 dimensions in this deployment.");
|
|
35
|
+
const textModel = `${provider.slug}/${text.id}`;
|
|
36
|
+
const policyInput = {
|
|
37
|
+
policyKey: `${options.eventKey}-policy`,
|
|
38
|
+
name: "Memory quickstart",
|
|
39
|
+
version: 1,
|
|
40
|
+
status: "active",
|
|
41
|
+
captureTypes: [
|
|
42
|
+
"preference",
|
|
43
|
+
"fact",
|
|
44
|
+
"project_fact",
|
|
45
|
+
"decision",
|
|
46
|
+
"constraint",
|
|
47
|
+
"commitment",
|
|
48
|
+
"event",
|
|
49
|
+
"temporary_state",
|
|
50
|
+
],
|
|
51
|
+
allowInferredMemories: false,
|
|
52
|
+
minimumConfidence: 0.7,
|
|
53
|
+
minimumFutureUtility: 0.5,
|
|
54
|
+
defaultMemoryTTLSeconds: 86400,
|
|
55
|
+
extractionConfig: {
|
|
56
|
+
model: textModel,
|
|
57
|
+
reconciliationModel: textModel,
|
|
58
|
+
profileModel: textModel,
|
|
59
|
+
observationModel: textModel,
|
|
60
|
+
indexing: {
|
|
61
|
+
model: `${provider.slug}/${embedding.id}`,
|
|
62
|
+
dimensions: 768,
|
|
63
|
+
distanceMetric: "cosine",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
privacyConfig: {
|
|
67
|
+
allowPII: false,
|
|
68
|
+
allowedSensitivities: ["unclassified", "public", "internal"],
|
|
69
|
+
},
|
|
70
|
+
retentionConfig: {
|
|
71
|
+
episodeContent: "full",
|
|
72
|
+
evidenceExcerpts: true,
|
|
73
|
+
candidateContent: false,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const existing = await client.memory.policies.list({
|
|
77
|
+
policyKey: policyInput.policyKey,
|
|
78
|
+
limit: 100,
|
|
79
|
+
});
|
|
80
|
+
const policy = existing.items.find((p) => p.version === 1) ??
|
|
81
|
+
(await client.memory.policies.create(policyInput));
|
|
82
|
+
const spaceKey = `${options.eventKey}/customer-123`;
|
|
83
|
+
const spaces = await all((cursor) => client.memory.spaces.list({
|
|
84
|
+
externalSubjectId: "customer-123",
|
|
85
|
+
cursor,
|
|
86
|
+
limit: 100,
|
|
87
|
+
}));
|
|
88
|
+
const space = spaces.find((s) => s.spaceKey === spaceKey) ??
|
|
89
|
+
(await client.memory.spaces.create({
|
|
90
|
+
spaceKey,
|
|
91
|
+
name: "Disposable customer memory",
|
|
92
|
+
scopeType: "user",
|
|
93
|
+
scopeId: "customer-123",
|
|
94
|
+
externalSubjectId: "customer-123",
|
|
95
|
+
policyId: policy.id,
|
|
96
|
+
}));
|
|
97
|
+
const input = {
|
|
98
|
+
memorySpaceId: space.id,
|
|
99
|
+
conversationId: options.eventKey,
|
|
100
|
+
idempotencyKey: options.eventKey,
|
|
101
|
+
messages: [
|
|
102
|
+
{
|
|
103
|
+
id: `${options.eventKey}-message`,
|
|
104
|
+
role: "user",
|
|
105
|
+
content: "I prefer important notifications through email rather than WhatsApp.",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
let result;
|
|
110
|
+
try {
|
|
111
|
+
result = await client.memory.ingest(input, {
|
|
112
|
+
idempotencyKey: options.eventKey,
|
|
113
|
+
maxRetries: 0,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof APIError) {
|
|
118
|
+
// Safe identifiers/categories only; never print secrets, prompts or memory content.
|
|
119
|
+
console.error({
|
|
120
|
+
code: error.code,
|
|
121
|
+
status: error.status,
|
|
122
|
+
retryable: error.retryable,
|
|
123
|
+
retryAfterMs: error.retryAfterMs,
|
|
124
|
+
requestId: error.requestId,
|
|
125
|
+
diagnostics: error.details,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// After correcting configuration/quota, call ingest(input) with the SAME event identity.
|
|
129
|
+
// Do not blindly retry, mutate the input, or generate a fresh key.
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
console.log({
|
|
133
|
+
runId: result.memoryRunId,
|
|
134
|
+
accepted: result.acceptedCount,
|
|
135
|
+
rejected: result.rejectedCount,
|
|
136
|
+
indexing: result.indexing,
|
|
137
|
+
});
|
|
138
|
+
const run = await client.memory.runs.get(result.memoryRunId);
|
|
139
|
+
if (result.indexing.failed)
|
|
140
|
+
throw new Error(`Indexing incomplete for run ${run.id}; inspect diagnostics and repair through memory.reindex().`);
|
|
141
|
+
// A completed event replays without model execution or another memory write.
|
|
142
|
+
const replay = await client.memory.ingest(input, {
|
|
143
|
+
idempotencyKey: options.eventKey,
|
|
144
|
+
maxRetries: 0,
|
|
145
|
+
});
|
|
146
|
+
if (replay.memoryRunId !== result.memoryRunId || !replay.replayed)
|
|
147
|
+
throw new Error("Expected the original completed event to replay.");
|
|
148
|
+
console.log({ replayed: replay.replayed, runId: replay.memoryRunId });
|
|
149
|
+
await pause();
|
|
150
|
+
const search = await client.memory.search({
|
|
151
|
+
memorySpaceId: space.id,
|
|
152
|
+
query: "How should I send important notifications?",
|
|
153
|
+
relevance: "relevant",
|
|
154
|
+
});
|
|
155
|
+
console.log({ relevantMatches: search.memories.length });
|
|
156
|
+
await pause();
|
|
157
|
+
const context = await client.memory.context({
|
|
158
|
+
memorySpaceId: space.id,
|
|
159
|
+
messages: [{ role: "user", content: "How should you notify me?" }],
|
|
160
|
+
});
|
|
161
|
+
console.log({ contextMemories: context.memories.length });
|
|
162
|
+
await pause();
|
|
163
|
+
await client.memory.profiles.generate({ memorySpaceId: space.id });
|
|
164
|
+
const profile = await client.memory.profiles.get(space.id);
|
|
165
|
+
const items = await client.memory.items.list({
|
|
166
|
+
memorySpaceId: space.id,
|
|
167
|
+
limit: 25,
|
|
168
|
+
});
|
|
169
|
+
const first = items.items[0];
|
|
170
|
+
if (first) {
|
|
171
|
+
await client.memory.items.update(first.id, { importance: 0.8 });
|
|
172
|
+
await client.memory.items.evidence(first.id, { limit: 25 });
|
|
173
|
+
// Explicit cleanup only for this disposable example's space.
|
|
174
|
+
if (options.cleanup)
|
|
175
|
+
await client.memory.items.delete(first.id);
|
|
176
|
+
}
|
|
177
|
+
if (options.cleanup) {
|
|
178
|
+
await client.memory.spaces.delete(space.id);
|
|
179
|
+
await client.memory.erase(space.id);
|
|
180
|
+
await client.memory.policies.delete(policy.id);
|
|
181
|
+
}
|
|
182
|
+
return { space, policy, result, search, context, profile };
|
|
183
|
+
}
|
|
184
|
+
if (process.env.NIRMOS_RUN_MEMORY_EXAMPLE === "1") {
|
|
185
|
+
const token = process.env.NIRMOS_API_KEY;
|
|
186
|
+
const eventKey = process.env.MEMORY_EVENT_KEY;
|
|
187
|
+
if (!token || !eventKey)
|
|
188
|
+
throw new Error("Set NIRMOS_API_KEY and a persisted MEMORY_EVENT_KEY.");
|
|
189
|
+
await memoryQuickstart(new Nirmos({
|
|
190
|
+
auth: { type: "api-key", key: token },
|
|
191
|
+
apiBaseUrl: process.env.NIRMOS_API_BASE_URL ?? "http://localhost:4001",
|
|
192
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_BASE_URL ?? "http://localhost:4000",
|
|
193
|
+
maxRetries: 0,
|
|
194
|
+
}), {
|
|
195
|
+
eventKey,
|
|
196
|
+
googleApiKey: process.env.GOOGLE_API_KEY,
|
|
197
|
+
cleanup: process.env.MEMORY_CLEANUP === "1",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APIError,
|
|
3
|
+
Nirmos,
|
|
4
|
+
type MemoryIngestRequest,
|
|
5
|
+
type MemoryPolicyCreate,
|
|
6
|
+
} from "@nirmos/sdk";
|
|
7
|
+
|
|
8
|
+
declare const process: { env: Record<string, string | undefined> };
|
|
9
|
+
|
|
10
|
+
async function all<T>(
|
|
11
|
+
load: (cursor?: string) => Promise<{ items: T[]; nextCursor: string | null }>,
|
|
12
|
+
): Promise<T[]> {
|
|
13
|
+
const items: T[] = [];
|
|
14
|
+
let cursor: string | undefined;
|
|
15
|
+
do {
|
|
16
|
+
const page = await load(cursor);
|
|
17
|
+
items.push(...page.items);
|
|
18
|
+
cursor = page.nextCursor ?? undefined;
|
|
19
|
+
} while (cursor);
|
|
20
|
+
return items;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Server-side only. Persist eventKey with the source event before first ingestion. */
|
|
24
|
+
export async function memoryQuickstart(
|
|
25
|
+
client: Nirmos,
|
|
26
|
+
options: {
|
|
27
|
+
eventKey: string;
|
|
28
|
+
googleApiKey?: string;
|
|
29
|
+
cleanup?: boolean;
|
|
30
|
+
paceMs?: number;
|
|
31
|
+
},
|
|
32
|
+
) {
|
|
33
|
+
const pause = () =>
|
|
34
|
+
new Promise((resolve) => setTimeout(resolve, options.paceMs ?? 20000));
|
|
35
|
+
const provider = (
|
|
36
|
+
await all((cursor) => client.providers.list({ cursor, limit: 100 }))
|
|
37
|
+
).find((p) => p.slug === "google");
|
|
38
|
+
if (!provider)
|
|
39
|
+
throw new Error("Google provider missing from this deployment's catalog.");
|
|
40
|
+
// Optional SDK setup; dashboard Gateway Credentials → Add credential → Google is equivalent.
|
|
41
|
+
if (options.googleApiKey)
|
|
42
|
+
await client.providerCredentials.create({
|
|
43
|
+
name: "Memory quickstart Google",
|
|
44
|
+
providerId: provider.id,
|
|
45
|
+
credentialType: "api_key",
|
|
46
|
+
secretData: { apiKey: options.googleApiKey },
|
|
47
|
+
isDefault: true,
|
|
48
|
+
});
|
|
49
|
+
const models = await all((cursor) =>
|
|
50
|
+
client.models.list({ providerId: provider.id, limit: 100, cursor }),
|
|
51
|
+
);
|
|
52
|
+
const text = models.find(
|
|
53
|
+
(m) => m.slug === "google-gemini-2-5-flash-lite" && m.availability,
|
|
54
|
+
);
|
|
55
|
+
const embedding = models.find(
|
|
56
|
+
(m) => m.slug === "google-gemini-embedding-001" && m.availability,
|
|
57
|
+
);
|
|
58
|
+
if (!text || !embedding)
|
|
59
|
+
throw new Error(
|
|
60
|
+
"Configure an active Google credential and verify both models in models.list(). Availability does not guarantee provider quota.",
|
|
61
|
+
);
|
|
62
|
+
if (!embedding.knowledgeSupportedDimensions?.includes(768))
|
|
63
|
+
throw new Error(
|
|
64
|
+
"Selected embedding model does not support 768 dimensions in this deployment.",
|
|
65
|
+
);
|
|
66
|
+
const textModel = `${provider.slug}/${text.id}`;
|
|
67
|
+
const policyInput: MemoryPolicyCreate = {
|
|
68
|
+
policyKey: `${options.eventKey}-policy`,
|
|
69
|
+
name: "Memory quickstart",
|
|
70
|
+
version: 1,
|
|
71
|
+
status: "active",
|
|
72
|
+
captureTypes: [
|
|
73
|
+
"preference",
|
|
74
|
+
"fact",
|
|
75
|
+
"project_fact",
|
|
76
|
+
"decision",
|
|
77
|
+
"constraint",
|
|
78
|
+
"commitment",
|
|
79
|
+
"event",
|
|
80
|
+
"temporary_state",
|
|
81
|
+
],
|
|
82
|
+
allowInferredMemories: false,
|
|
83
|
+
minimumConfidence: 0.7,
|
|
84
|
+
minimumFutureUtility: 0.5,
|
|
85
|
+
defaultMemoryTTLSeconds: 86400,
|
|
86
|
+
extractionConfig: {
|
|
87
|
+
model: textModel,
|
|
88
|
+
reconciliationModel: textModel,
|
|
89
|
+
profileModel: textModel,
|
|
90
|
+
observationModel: textModel,
|
|
91
|
+
indexing: {
|
|
92
|
+
model: `${provider.slug}/${embedding.id}`,
|
|
93
|
+
dimensions: 768,
|
|
94
|
+
distanceMetric: "cosine",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
privacyConfig: {
|
|
98
|
+
allowPII: false,
|
|
99
|
+
allowedSensitivities: ["unclassified", "public", "internal"],
|
|
100
|
+
},
|
|
101
|
+
retentionConfig: {
|
|
102
|
+
episodeContent: "full",
|
|
103
|
+
evidenceExcerpts: true,
|
|
104
|
+
candidateContent: false,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const existing = await client.memory.policies.list({
|
|
108
|
+
policyKey: policyInput.policyKey,
|
|
109
|
+
limit: 100,
|
|
110
|
+
});
|
|
111
|
+
const policy =
|
|
112
|
+
existing.items.find((p) => p.version === 1) ??
|
|
113
|
+
(await client.memory.policies.create(policyInput));
|
|
114
|
+
const spaceKey = `${options.eventKey}/customer-123`;
|
|
115
|
+
const spaces = await all((cursor) =>
|
|
116
|
+
client.memory.spaces.list({
|
|
117
|
+
externalSubjectId: "customer-123",
|
|
118
|
+
cursor,
|
|
119
|
+
limit: 100,
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
const space =
|
|
123
|
+
spaces.find((s) => s.spaceKey === spaceKey) ??
|
|
124
|
+
(await client.memory.spaces.create({
|
|
125
|
+
spaceKey,
|
|
126
|
+
name: "Disposable customer memory",
|
|
127
|
+
scopeType: "user",
|
|
128
|
+
scopeId: "customer-123",
|
|
129
|
+
externalSubjectId: "customer-123",
|
|
130
|
+
policyId: policy.id,
|
|
131
|
+
}));
|
|
132
|
+
const input: MemoryIngestRequest = {
|
|
133
|
+
memorySpaceId: space.id,
|
|
134
|
+
conversationId: options.eventKey,
|
|
135
|
+
idempotencyKey: options.eventKey,
|
|
136
|
+
messages: [
|
|
137
|
+
{
|
|
138
|
+
id: `${options.eventKey}-message`,
|
|
139
|
+
role: "user",
|
|
140
|
+
content:
|
|
141
|
+
"I prefer important notifications through email rather than WhatsApp.",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
let result;
|
|
146
|
+
try {
|
|
147
|
+
result = await client.memory.ingest(input, {
|
|
148
|
+
idempotencyKey: options.eventKey,
|
|
149
|
+
maxRetries: 0,
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof APIError) {
|
|
153
|
+
// Safe identifiers/categories only; never print secrets, prompts or memory content.
|
|
154
|
+
console.error({
|
|
155
|
+
code: error.code,
|
|
156
|
+
status: error.status,
|
|
157
|
+
retryable: error.retryable,
|
|
158
|
+
retryAfterMs: error.retryAfterMs,
|
|
159
|
+
requestId: error.requestId,
|
|
160
|
+
diagnostics: error.details,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// After correcting configuration/quota, call ingest(input) with the SAME event identity.
|
|
164
|
+
// Do not blindly retry, mutate the input, or generate a fresh key.
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
console.log({
|
|
168
|
+
runId: result.memoryRunId,
|
|
169
|
+
accepted: result.acceptedCount,
|
|
170
|
+
rejected: result.rejectedCount,
|
|
171
|
+
indexing: result.indexing,
|
|
172
|
+
});
|
|
173
|
+
const run = await client.memory.runs.get(result.memoryRunId);
|
|
174
|
+
if (result.indexing.failed)
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Indexing incomplete for run ${run.id}; inspect diagnostics and repair through memory.reindex().`,
|
|
177
|
+
);
|
|
178
|
+
// A completed event replays without model execution or another memory write.
|
|
179
|
+
const replay = await client.memory.ingest(input, {
|
|
180
|
+
idempotencyKey: options.eventKey,
|
|
181
|
+
maxRetries: 0,
|
|
182
|
+
});
|
|
183
|
+
if (replay.memoryRunId !== result.memoryRunId || !replay.replayed)
|
|
184
|
+
throw new Error("Expected the original completed event to replay.");
|
|
185
|
+
console.log({ replayed: replay.replayed, runId: replay.memoryRunId });
|
|
186
|
+
await pause();
|
|
187
|
+
const search = await client.memory.search({
|
|
188
|
+
memorySpaceId: space.id,
|
|
189
|
+
query: "How should I send important notifications?",
|
|
190
|
+
relevance: "relevant",
|
|
191
|
+
});
|
|
192
|
+
console.log({ relevantMatches: search.memories.length });
|
|
193
|
+
await pause();
|
|
194
|
+
const context = await client.memory.context({
|
|
195
|
+
memorySpaceId: space.id,
|
|
196
|
+
messages: [{ role: "user", content: "How should you notify me?" }],
|
|
197
|
+
});
|
|
198
|
+
console.log({ contextMemories: context.memories.length });
|
|
199
|
+
await pause();
|
|
200
|
+
await client.memory.profiles.generate({ memorySpaceId: space.id });
|
|
201
|
+
const profile = await client.memory.profiles.get(space.id);
|
|
202
|
+
const items = await client.memory.items.list({
|
|
203
|
+
memorySpaceId: space.id,
|
|
204
|
+
limit: 25,
|
|
205
|
+
});
|
|
206
|
+
const first = items.items[0];
|
|
207
|
+
if (first) {
|
|
208
|
+
await client.memory.items.update(first.id, { importance: 0.8 });
|
|
209
|
+
await client.memory.items.evidence(first.id, { limit: 25 });
|
|
210
|
+
// Explicit cleanup only for this disposable example's space.
|
|
211
|
+
if (options.cleanup) await client.memory.items.delete(first.id);
|
|
212
|
+
}
|
|
213
|
+
if (options.cleanup) {
|
|
214
|
+
await client.memory.spaces.delete(space.id);
|
|
215
|
+
await client.memory.erase(space.id);
|
|
216
|
+
await client.memory.policies.delete(policy.id);
|
|
217
|
+
}
|
|
218
|
+
return { space, policy, result, search, context, profile };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (process.env.NIRMOS_RUN_MEMORY_EXAMPLE === "1") {
|
|
222
|
+
const token = process.env.NIRMOS_API_KEY;
|
|
223
|
+
const eventKey = process.env.MEMORY_EVENT_KEY;
|
|
224
|
+
if (!token || !eventKey)
|
|
225
|
+
throw new Error("Set NIRMOS_API_KEY and a persisted MEMORY_EVENT_KEY.");
|
|
226
|
+
await memoryQuickstart(
|
|
227
|
+
new Nirmos({
|
|
228
|
+
auth: { type: "api-key", key: token },
|
|
229
|
+
apiBaseUrl: process.env.NIRMOS_API_BASE_URL ?? "http://localhost:4001",
|
|
230
|
+
runtimeBaseUrl:
|
|
231
|
+
process.env.NIRMOS_RUNTIME_BASE_URL ?? "http://localhost:4000",
|
|
232
|
+
maxRetries: 0,
|
|
233
|
+
}),
|
|
234
|
+
{
|
|
235
|
+
eventKey,
|
|
236
|
+
googleApiKey: process.env.GOOGLE_API_KEY,
|
|
237
|
+
cleanup: process.env.MEMORY_CLEANUP === "1",
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirmos/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Official TypeScript SDK for the Nirmos AI platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"src",
|
|
11
|
-
"README.md"
|
|
11
|
+
"README.md",
|
|
12
|
+
"examples"
|
|
12
13
|
],
|
|
13
14
|
"main": "./dist/cjs/index.js",
|
|
14
15
|
"module": "./dist/esm/index.js",
|
|
@@ -21,11 +22,11 @@
|
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"scripts": {
|
|
24
|
-
"build": "node ./scripts/clean.mjs && tsc -p tsconfig.build.json && tsc -p tsconfig.cjs.json && node ./scripts/write-cjs-package.mjs",
|
|
25
|
+
"build": "node ./scripts/generate-version.mjs && node ./scripts/clean.mjs && tsc -p tsconfig.build.json && tsc -p tsconfig.cjs.json && node ./scripts/write-cjs-package.mjs && node ./scripts/generate-examples.mjs",
|
|
25
26
|
"check-types": "tsc --noEmit",
|
|
26
27
|
"lint": "eslint src tests --max-warnings 0",
|
|
27
28
|
"prepack": "pnpm build",
|
|
28
|
-
"test": "node ./scripts/ensure-built.mjs && tsc -p tests/tsconfig.json && node --test tests/*.test.mjs"
|
|
29
|
+
"test": "node ./scripts/ensure-built.mjs && tsc -p examples/tsconfig.json && tsc -p tests/tsconfig.json && node --test tests/*.test.mjs"
|
|
29
30
|
},
|
|
30
31
|
"engines": {
|
|
31
32
|
"node": ">=18"
|
package/src/core/transport.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface TransportResponse<T> {
|
|
|
47
47
|
response: Response;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
import { SDK_VERSION } from "./version.js";
|
|
51
51
|
|
|
52
52
|
export class HttpTransport {
|
|
53
53
|
readonly #config: TransportConfig;
|
|
@@ -95,7 +95,7 @@ export class HttpTransport {
|
|
|
95
95
|
if (
|
|
96
96
|
retryableMethod &&
|
|
97
97
|
attempt < maxRetries &&
|
|
98
|
-
|
|
98
|
+
(await mayRetryResponse(response))
|
|
99
99
|
) {
|
|
100
100
|
await response.body?.cancel();
|
|
101
101
|
await waitBeforeRetry(response, attempt, request.options?.signal);
|
|
@@ -319,6 +319,18 @@ function isRetryableStatus(status: number): boolean {
|
|
|
319
319
|
return status === 408 || status === 429 || status >= 500;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
/** Server retryability overrides status defaults, including daily provider quota. */
|
|
323
|
+
async function mayRetryResponse(response: Response): Promise<boolean> {
|
|
324
|
+
if (!isRetryableStatus(response.status)) return false;
|
|
325
|
+
try {
|
|
326
|
+
const payload = asUnknownRecord(await response.clone().json());
|
|
327
|
+
return readBoolean(asUnknownRecord(payload.error), "retryable") !== false;
|
|
328
|
+
} catch {
|
|
329
|
+
// Non-JSON legacy responses retain bounded status-based retry behavior.
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
322
334
|
function parseRetryAfter(value: string | null): number | undefined {
|
|
323
335
|
if (!value) return undefined;
|
|
324
336
|
const seconds = Number(value);
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
readString,
|
|
9
9
|
} from "../core/metadata.js";
|
|
10
10
|
import type { RequestMetadata, Usage } from "../core/types.js";
|
|
11
|
-
import { normalizeToolCall, normalizeUsage } from "./mappers.js";
|
|
11
|
+
import { mergeReasoningDetails, normalizeToolCall, normalizeUsage } from "./mappers.js";
|
|
12
12
|
import type {
|
|
13
13
|
ChatChoice,
|
|
14
14
|
ChatCompletion,
|
|
@@ -21,6 +21,8 @@ type MutableChoice = {
|
|
|
21
21
|
index: number;
|
|
22
22
|
role: ChatMessage["role"];
|
|
23
23
|
content: string;
|
|
24
|
+
reasoning?: string;
|
|
25
|
+
reasoningDetails?: ChatMessage["reasoningDetails"];
|
|
24
26
|
finishReason: ChatChoice["finishReason"];
|
|
25
27
|
toolCalls: Map<number, FunctionToolCall>;
|
|
26
28
|
};
|
|
@@ -140,6 +142,13 @@ export class ChatStream implements AsyncIterable<ChatStreamEvent> {
|
|
|
140
142
|
: finishReason;
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
const reasoning = readString(delta, "reasoning");
|
|
146
|
+
if (reasoning) {
|
|
147
|
+
mutable.reasoning = (mutable.reasoning ?? "") + reasoning;
|
|
148
|
+
yield { type: "reasoning.delta", id: this.#id, model: this.#model, choiceIndex: index, delta: reasoning, metadata: this.#metadata };
|
|
149
|
+
}
|
|
150
|
+
const details = readArray(delta, "reasoning_details", "reasoningDetails") as NonNullable<ChatMessage["reasoningDetails"]>;
|
|
151
|
+
if (details.length) mutable.reasoningDetails = mergeReasoningDetails(mutable.reasoningDetails ?? [], details);
|
|
143
152
|
const content = readString(delta, "content");
|
|
144
153
|
if (content) {
|
|
145
154
|
mutable.content += content;
|
|
@@ -235,6 +244,8 @@ export class ChatStream implements AsyncIterable<ChatStreamEvent> {
|
|
|
235
244
|
message: {
|
|
236
245
|
role: choice.role,
|
|
237
246
|
content: choice.content,
|
|
247
|
+
...(choice.reasoning !== undefined ? { reasoning: choice.reasoning } : {}),
|
|
248
|
+
...(choice.reasoningDetails ? { reasoningDetails: choice.reasoningDetails } : {}),
|
|
238
249
|
...(choice.toolCalls.size > 0
|
|
239
250
|
? { toolCalls: [...choice.toolCalls.values()] }
|
|
240
251
|
: {}),
|
package/src/gateway/chat.ts
CHANGED
|
@@ -77,6 +77,7 @@ export class Chat {
|
|
|
77
77
|
seed: params.seed,
|
|
78
78
|
user: params.user,
|
|
79
79
|
provider: params.provider,
|
|
80
|
+
provider_options: params.providerOptions,
|
|
80
81
|
fallback_models: params.fallbackModels,
|
|
81
82
|
routing_strategy: toWireRoutingStrategy(params.routingStrategy),
|
|
82
83
|
metadata: params.metadata,
|
|
@@ -28,6 +28,7 @@ export class Embeddings {
|
|
|
28
28
|
encoding_format: params.encoding,
|
|
29
29
|
user: params.user,
|
|
30
30
|
provider: params.provider,
|
|
31
|
+
provider_options: params.providerOptions,
|
|
31
32
|
fallback_models: params.fallbackModels,
|
|
32
33
|
routing_strategy: toWireRoutingStrategy(params.routingStrategy),
|
|
33
34
|
},
|