@nirmos/sdk 0.3.2 → 0.3.4

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.
Files changed (73) hide show
  1. package/README.md +285 -17
  2. package/dist/cjs/core/transport.js +16 -3
  3. package/dist/cjs/core/transport.js.map +1 -1
  4. package/dist/cjs/core/version.js +6 -0
  5. package/dist/cjs/core/version.js.map +1 -0
  6. package/dist/cjs/evaluations/types.js +3 -0
  7. package/dist/cjs/evaluations/types.js.map +1 -0
  8. package/dist/cjs/gateway/chat-stream.js +10 -0
  9. package/dist/cjs/gateway/chat-stream.js.map +1 -1
  10. package/dist/cjs/gateway/chat.js +1 -0
  11. package/dist/cjs/gateway/chat.js.map +1 -1
  12. package/dist/cjs/gateway/embeddings.js +1 -0
  13. package/dist/cjs/gateway/embeddings.js.map +1 -1
  14. package/dist/cjs/gateway/mappers.js +39 -2
  15. package/dist/cjs/gateway/mappers.js.map +1 -1
  16. package/dist/cjs/memory/execution-types.js +3 -0
  17. package/dist/cjs/memory/execution-types.js.map +1 -0
  18. package/dist/esm/core/transport.js +15 -2
  19. package/dist/esm/core/transport.js.map +1 -1
  20. package/dist/esm/core/version.d.ts +2 -0
  21. package/dist/esm/core/version.d.ts.map +1 -0
  22. package/dist/esm/core/version.js +3 -0
  23. package/dist/esm/core/version.js.map +1 -0
  24. package/dist/esm/evaluations/types.d.ts +13 -0
  25. package/dist/esm/evaluations/types.d.ts.map +1 -0
  26. package/dist/esm/evaluations/types.js +2 -0
  27. package/dist/esm/evaluations/types.js.map +1 -0
  28. package/dist/esm/gateway/chat-stream.d.ts.map +1 -1
  29. package/dist/esm/gateway/chat-stream.js +11 -1
  30. package/dist/esm/gateway/chat-stream.js.map +1 -1
  31. package/dist/esm/gateway/chat.d.ts.map +1 -1
  32. package/dist/esm/gateway/chat.js +1 -0
  33. package/dist/esm/gateway/chat.js.map +1 -1
  34. package/dist/esm/gateway/embeddings.d.ts.map +1 -1
  35. package/dist/esm/gateway/embeddings.js +1 -0
  36. package/dist/esm/gateway/embeddings.js.map +1 -1
  37. package/dist/esm/gateway/mappers.d.ts +2 -0
  38. package/dist/esm/gateway/mappers.d.ts.map +1 -1
  39. package/dist/esm/gateway/mappers.js +38 -2
  40. package/dist/esm/gateway/mappers.js.map +1 -1
  41. package/dist/esm/gateway/types.d.ts +8 -0
  42. package/dist/esm/gateway/types.d.ts.map +1 -1
  43. package/dist/esm/index.d.ts +1 -0
  44. package/dist/esm/index.d.ts.map +1 -1
  45. package/dist/esm/management/contracts.d.ts +4865 -9009
  46. package/dist/esm/management/contracts.d.ts.map +1 -1
  47. package/dist/esm/memory/execution-types.d.ts +35 -0
  48. package/dist/esm/memory/execution-types.d.ts.map +1 -0
  49. package/dist/esm/memory/execution-types.js +2 -0
  50. package/dist/esm/memory/execution-types.js.map +1 -0
  51. package/dist/esm/memory/types.d.ts +9 -23
  52. package/dist/esm/memory/types.d.ts.map +1 -1
  53. package/examples/evaluation-offline.mjs +149 -0
  54. package/examples/evaluation-quickstart.mjs +205 -0
  55. package/examples/evaluation-quickstart.ts +250 -0
  56. package/examples/evaluation-trace-import.mjs +81 -0
  57. package/examples/evaluation-trace-import.ts +105 -0
  58. package/examples/memory-quickstart.mjs +199 -0
  59. package/examples/memory-quickstart.ts +240 -0
  60. package/examples/tsconfig.json +5 -0
  61. package/package.json +5 -4
  62. package/src/core/transport.ts +14 -2
  63. package/src/core/version.ts +2 -0
  64. package/src/evaluations/types.ts +18 -0
  65. package/src/gateway/chat-stream.ts +12 -1
  66. package/src/gateway/chat.ts +1 -0
  67. package/src/gateway/embeddings.ts +1 -0
  68. package/src/gateway/mappers.ts +55 -2
  69. package/src/gateway/types.ts +8 -0
  70. package/src/index.ts +11 -0
  71. package/src/management/contracts.ts +42 -79
  72. package/src/memory/execution-types.ts +2 -0
  73. package/src/memory/types.ts +10 -22
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": { "noEmit": true, "rootDir": ".." },
4
+ "include": ["*.ts"]
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirmos/sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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"
@@ -47,7 +47,7 @@ export interface TransportResponse<T> {
47
47
  response: Response;
48
48
  }
49
49
 
50
- const SDK_VERSION = "0.3.0";
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
- isRetryableStatus(response.status)
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);
@@ -0,0 +1,2 @@
1
+ // Generated from package.json by scripts/generate-version.mjs.
2
+ export const SDK_VERSION = "0.3.4";
@@ -0,0 +1,18 @@
1
+ import type { Requests } from "../management/contracts.js";
2
+
3
+ /** Built-in evaluator versions are discriminated by type. Configs follow the API schemas. */
4
+ export type EvaluationEvaluatorVersion = Requests["createEvaluatorVersion"];
5
+ export type EvaluationTargetConfig = NonNullable<
6
+ Requests["createEvaluationColumn"]["target"]
7
+ >;
8
+ export type EvaluationColumnCreate = Requests["createEvaluationColumn"];
9
+ export type EvaluationInputBinding = NonNullable<
10
+ NonNullable<EvaluationColumnCreate["config"]>["inputMapping"]
11
+ >[string];
12
+ export type EvaluationSegmentCriteria = Requests["createSegment"]["criteria"];
13
+
14
+ export type EvaluationEvaluatorType = EvaluationEvaluatorVersion["type"];
15
+ export type EvaluationEvaluatorConfig<T extends EvaluationEvaluatorType> =
16
+ Extract<EvaluationEvaluatorVersion, { type: T }>["config"];
17
+ export type EvaluationExpression =
18
+ EvaluationEvaluatorConfig<"custom_expression">["expression"];
@@ -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
  : {}),
@@ -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
  },
@@ -36,6 +36,12 @@ export function toWireMessage(message: ChatMessage): Record<string, unknown> {
36
36
  audio: { data: part.data, format: part.format },
37
37
  };
38
38
  }),
39
+ ...(message.reasoning !== undefined
40
+ ? { reasoning: message.reasoning }
41
+ : {}),
42
+ ...(message.reasoningDetails?.length
43
+ ? { reasoning_details: message.reasoningDetails }
44
+ : {}),
39
45
  ...(message.name ? { name: message.name } : {}),
40
46
  ...(message.toolCallId ? { tool_call_id: message.toolCallId } : {}),
41
47
  ...(message.toolCalls && message.toolCalls.length > 0
@@ -68,8 +74,15 @@ export function normalizeUsage(value: unknown): Usage {
68
74
  totalTokens:
69
75
  readNumber(usage, "total_tokens", "totalTokens") ??
70
76
  inputTokens + outputTokens,
71
- cachedTokens: readNumber(usage, "cached_tokens", "cachedTokens"),
72
- reasoningTokens: readNumber(usage, "reasoning_tokens", "reasoningTokens"),
77
+ cachedTokens:
78
+ readNumber(usage, "cached_tokens", "cachedTokens") ??
79
+ readNumber(asUnknownRecord(usage.prompt_tokens_details), "cached_tokens"),
80
+ reasoningTokens:
81
+ readNumber(usage, "reasoning_tokens", "reasoningTokens") ??
82
+ readNumber(
83
+ asUnknownRecord(usage.completion_tokens_details),
84
+ "reasoning_tokens",
85
+ ),
73
86
  };
74
87
  }
75
88
 
@@ -183,6 +196,12 @@ export function normalizeMessage(value: unknown): ChatMessage {
183
196
  ? content
184
197
  : "",
185
198
  name: readString(message, "name"),
199
+ reasoning: readString(message, "reasoning"),
200
+ reasoningDetails: readArray(
201
+ message,
202
+ "reasoning_details",
203
+ "reasoningDetails",
204
+ ) as ChatMessage["reasoningDetails"],
186
205
  toolCallId: readString(message, "tool_call_id", "toolCallId"),
187
206
  toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
188
207
  };
@@ -232,3 +251,37 @@ function normalizeFinishReason(
232
251
  if (value === "content_filter") return "contentFilter";
233
252
  return value;
234
253
  }
254
+
255
+ /** Assemble indexed reasoning blocks without losing encrypted continuation data. */
256
+ export function mergeReasoningDetails(
257
+ current: NonNullable<ChatMessage["reasoningDetails"]>,
258
+ incoming: NonNullable<ChatMessage["reasoningDetails"]>,
259
+ ): NonNullable<ChatMessage["reasoningDetails"]> {
260
+ const result = [...current];
261
+ for (const value of incoming) {
262
+ const detail = asUnknownRecord(value);
263
+ const position = result.findIndex((item) => {
264
+ const previous = asUnknownRecord(item);
265
+ return (
266
+ previous.type === detail.type &&
267
+ ((detail.index !== undefined && previous.index === detail.index) ||
268
+ (typeof detail.id === "string" && previous.id === detail.id))
269
+ );
270
+ });
271
+ if (position < 0) {
272
+ result.push(value);
273
+ continue;
274
+ }
275
+ const previous = asUnknownRecord(result[position]);
276
+ const merged = { ...previous, ...detail };
277
+ for (const field of ["text", "summary", "data", "signature"]) {
278
+ if (
279
+ typeof previous[field] === "string" &&
280
+ typeof detail[field] === "string"
281
+ )
282
+ merged[field] = previous[field] + detail[field];
283
+ }
284
+ result[position] = merged as (typeof result)[number];
285
+ }
286
+ return result;
287
+ }
@@ -45,6 +45,8 @@ export interface ChatMessage {
45
45
  role: ChatRole;
46
46
  content: string | readonly ChatContentPart[];
47
47
  name?: string;
48
+ reasoning?: string;
49
+ reasoningDetails?: readonly JsonValue[];
48
50
  toolCallId?: string;
49
51
  toolCalls?: readonly FunctionToolCall[];
50
52
  }
@@ -106,6 +108,8 @@ interface ChatCreateParamsBase {
106
108
  user?: string;
107
109
  /** Optional provider override. Omit to let the gateway select a provider. */
108
110
  provider?: string;
111
+ /** Options scoped to an upstream provider slug; other targets never receive them. */
112
+ providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
109
113
  fallbackModels?: readonly string[];
110
114
  routingStrategy?: RoutingStrategy;
111
115
  metadata?: Readonly<Record<string, JsonValue>>;
@@ -167,6 +171,8 @@ export interface EmbeddingCreateParams {
167
171
  user?: string;
168
172
  /** Optional provider override. Omit to use the model's configured default provider. */
169
173
  provider?: string;
174
+ /** Options scoped to an upstream provider slug; other targets never receive them. */
175
+ providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
170
176
  /** @deprecated Embeddings never fall back to another vector space. Requests with this option are rejected. */
171
177
  fallbackModels?: readonly string[];
172
178
  /** @deprecated Embeddings require direct model selection. */
@@ -204,6 +210,8 @@ export interface ImageGenerateParams {
204
210
  user?: string;
205
211
  /** Optional provider override. Omit to use the model's configured default provider. */
206
212
  provider?: string;
213
+ /** Options scoped to an upstream provider slug; other targets never receive them. */
214
+ providerOptions?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
207
215
  metadata?: Readonly<Record<string, JsonValue>>;
208
216
  }
209
217
 
package/src/index.ts CHANGED
@@ -150,3 +150,14 @@ export {
150
150
  validatePromptVariableValues,
151
151
  validatePromptSettings,
152
152
  } from "./prompts/variables.js";
153
+
154
+ export type {
155
+ EvaluationEvaluatorVersion,
156
+ EvaluationEvaluatorType,
157
+ EvaluationEvaluatorConfig,
158
+ EvaluationExpression,
159
+ EvaluationTargetConfig,
160
+ EvaluationColumnCreate,
161
+ EvaluationInputBinding,
162
+ EvaluationSegmentCriteria,
163
+ } from "./evaluations/types.js";