@nemesis-oss/ollama-sdk 1.7.0 → 1.9.0

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 (46) hide show
  1. package/CHANGELOG.md +168 -1
  2. package/README.md +181 -10
  3. package/dist/anthropic-5oYIRS6D.d.ts +1649 -0
  4. package/dist/anthropic-BIh45UXj.d.cts +1649 -0
  5. package/dist/{compose-DLStUfaF.d.ts → compose-DCVYMvOL.d.ts} +1 -1
  6. package/dist/{compose-DS-UWFx8.d.cts → compose-Dj6FdF2n.d.cts} +1 -1
  7. package/dist/generated-api.cjs +116 -9
  8. package/dist/generated-api.cjs.map +1 -1
  9. package/dist/generated-api.d.cts +321 -630
  10. package/dist/generated-api.d.ts +321 -630
  11. package/dist/generated-api.js +112 -10
  12. package/dist/generated-api.js.map +1 -1
  13. package/dist/generated-models-schemas.cjs +151 -3
  14. package/dist/generated-models-schemas.cjs.map +1 -1
  15. package/dist/generated-models-schemas.d.cts +228 -3
  16. package/dist/generated-models-schemas.d.ts +228 -3
  17. package/dist/generated-models-schemas.js +134 -4
  18. package/dist/generated-models-schemas.js.map +1 -1
  19. package/dist/generated-runtime.cjs +679 -60
  20. package/dist/generated-runtime.cjs.map +1 -1
  21. package/dist/generated-runtime.d.cts +22 -24
  22. package/dist/generated-runtime.d.ts +22 -24
  23. package/dist/generated-runtime.js +678 -61
  24. package/dist/generated-runtime.js.map +1 -1
  25. package/dist/index.cjs +2468 -132
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +1666 -864
  28. package/dist/index.d.ts +1666 -864
  29. package/dist/index.js +2432 -133
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/tools.json +306 -73
  32. package/dist/mcp-generated.cjs +138 -7
  33. package/dist/mcp-generated.cjs.map +1 -1
  34. package/dist/mcp-generated.d.cts +2 -2
  35. package/dist/mcp-generated.d.ts +2 -2
  36. package/dist/mcp-generated.js +138 -7
  37. package/dist/mcp-generated.js.map +1 -1
  38. package/dist/{runtime-qwD72cpn.d.ts → runtime-C3rfpkZw.d.ts} +286 -5
  39. package/dist/{runtime-bQ48I-RC.d.cts → runtime-D2W9TfCJ.d.cts} +286 -5
  40. package/dist/skills.cjs.map +1 -1
  41. package/dist/skills.d.cts +3 -3
  42. package/dist/skills.d.ts +3 -3
  43. package/dist/skills.js.map +1 -1
  44. package/dist/{types-5PAjLoCp.d.cts → types-DVcX_zMp.d.cts} +110 -10
  45. package/dist/{types-5PAjLoCp.d.ts → types-DVcX_zMp.d.ts} +110 -10
  46. package/package.json +9 -5
@@ -65,6 +65,14 @@ var OllamaClientError = class extends Error {
65
65
  this.response = options.response;
66
66
  }
67
67
  };
68
+ var OllamaStreamError = class extends OllamaClientError {
69
+ /** Content accumulated before the in-band error frame, or '' if none. */
70
+ partialContent;
71
+ constructor(message, options) {
72
+ super(message, { ...options, code: "stream_error", retryable: false });
73
+ this.partialContent = options?.partialContent ?? "";
74
+ }
75
+ };
68
76
  var OllamaRequestValidationError = class extends OllamaClientError {
69
77
  operationId;
70
78
  issues;
@@ -74,6 +82,35 @@ var OllamaRequestValidationError = class extends OllamaClientError {
74
82
  this.issues = options.issues;
75
83
  }
76
84
  };
85
+ var OllamaRequestTooLargeError = class extends OllamaClientError {
86
+ operationId;
87
+ actualBytes;
88
+ maxBytes;
89
+ constructor(message, options) {
90
+ super(message, { ...options, code: "request_too_large", retryable: false, status: 413 });
91
+ this.operationId = options.operationId;
92
+ this.actualBytes = options.actualBytes;
93
+ this.maxBytes = options.maxBytes;
94
+ }
95
+ };
96
+ var OllamaResponseValidationError = class extends OllamaClientError {
97
+ operationId;
98
+ issues;
99
+ constructor(message, options) {
100
+ super(message, { ...options, code: "response_validation_error", retryable: false });
101
+ this.operationId = options.operationId;
102
+ this.issues = options.issues;
103
+ }
104
+ };
105
+ var OllamaServerVersionUnknownError = class extends OllamaClientError {
106
+ operationId;
107
+ minRequiredVersion;
108
+ constructor(message, options) {
109
+ super(message, { ...options, code: "server_version_unknown", retryable: false });
110
+ this.operationId = options.operationId;
111
+ this.minRequiredVersion = options.minRequiredVersion;
112
+ }
113
+ };
77
114
  var OllamaGenericClientError = class extends OllamaClientError {
78
115
  constructor(message, options) {
79
116
  super(message, { ...options, code: "client_error" });
@@ -94,6 +131,12 @@ function disposableReader(reader) {
94
131
  }
95
132
 
96
133
  // src/streaming/ndjson.ts
134
+ function isInBandErrorFrame(value) {
135
+ if (typeof value !== "object" || value === null) return false;
136
+ const record = value;
137
+ if (typeof record.error !== "string" || record.error.length === 0) return false;
138
+ return !("model" in record) && !("response" in record) && !("message" in record) && !("status" in record) && !("done" in record);
139
+ }
97
140
  async function* parseNdjsonStream(stream) {
98
141
  var _stack = [];
99
142
  try {
@@ -110,18 +153,127 @@ async function* parseNdjsonStream(stream) {
110
153
  for (const line of lines) {
111
154
  const trimmed = line.trim();
112
155
  if (!trimmed) continue;
156
+ let json;
113
157
  try {
114
- yield JSON.parse(trimmed);
158
+ json = JSON.parse(trimmed);
115
159
  } catch (err) {
116
160
  throw new OllamaGenericClientError(`Failed to parse stream JSON chunk: ${trimmed}`, {
117
161
  cause: err
118
162
  });
119
163
  }
164
+ if (isInBandErrorFrame(json)) {
165
+ throw new OllamaStreamError(json.error);
166
+ }
167
+ yield json;
120
168
  }
121
169
  }
122
170
  if (buffer.trim()) {
123
- yield JSON.parse(buffer.trim());
171
+ const trimmed = buffer.trim();
172
+ let json;
173
+ try {
174
+ json = JSON.parse(trimmed);
175
+ } catch (err) {
176
+ throw new OllamaGenericClientError(`Failed to parse stream JSON chunk: ${trimmed}`, {
177
+ cause: err
178
+ });
179
+ }
180
+ if (isInBandErrorFrame(json)) {
181
+ throw new OllamaStreamError(json.error);
182
+ }
183
+ yield json;
184
+ }
185
+ } catch (_) {
186
+ var _error = _, _hasError = true;
187
+ } finally {
188
+ var _promise = __callDispose(_stack, _error, _hasError);
189
+ _promise && await _promise;
190
+ }
191
+ }
192
+
193
+ // src/streaming/sse.ts
194
+ function dispatch(event, data, id, retry) {
195
+ if (data.length === 0) return void 0;
196
+ const joined = data.join("\n");
197
+ return {
198
+ ...event !== void 0 ? { event } : {},
199
+ data: joined.endsWith("\n") ? joined.slice(0, -1) : joined,
200
+ ...id !== void 0 ? { id } : {},
201
+ ...retry !== void 0 ? { retry } : {}
202
+ };
203
+ }
204
+ async function* parseSseStream(stream) {
205
+ var _stack = [];
206
+ try {
207
+ const reader = stream.getReader();
208
+ const decoder = new TextDecoder();
209
+ let buffer = "";
210
+ let eventType;
211
+ let data = [];
212
+ let lastEventId;
213
+ let retry;
214
+ const processLine = (line) => {
215
+ if (line.length === 0) {
216
+ const event = dispatch(eventType, data, lastEventId, retry);
217
+ eventType = void 0;
218
+ data = [];
219
+ retry = void 0;
220
+ return event;
221
+ }
222
+ if (line.startsWith(":")) return void 0;
223
+ const separator = line.indexOf(":");
224
+ const field = separator === -1 ? line : line.slice(0, separator);
225
+ let value = separator === -1 ? "" : line.slice(separator + 1);
226
+ if (value.startsWith(" ")) value = value.slice(1);
227
+ switch (field) {
228
+ case "event":
229
+ eventType = value;
230
+ break;
231
+ case "data":
232
+ data.push(value);
233
+ break;
234
+ case "id":
235
+ if (!value.includes("\0")) lastEventId = value;
236
+ break;
237
+ case "retry": {
238
+ if (/^\d+$/.test(value)) {
239
+ const parsed = Number(value);
240
+ if (Number.isSafeInteger(parsed)) retry = parsed;
241
+ }
242
+ break;
243
+ }
244
+ default:
245
+ break;
246
+ }
247
+ return void 0;
248
+ };
249
+ const _reader = __using(_stack, disposableReader(reader), true);
250
+ while (true) {
251
+ const { done, value } = await reader.read();
252
+ if (done) break;
253
+ buffer += decoder.decode(value, { stream: true });
254
+ while (true) {
255
+ const lf = buffer.indexOf("\n");
256
+ const cr = buffer.indexOf("\r");
257
+ if (lf === -1 && cr === -1) break;
258
+ if (cr !== -1 && lf === -1 && cr === buffer.length - 1) break;
259
+ const lineEnd = lf === -1 ? cr : cr === -1 ? lf : Math.min(lf, cr);
260
+ let separatorLength = 1;
261
+ if (buffer[lineEnd] === "\r" && buffer[lineEnd + 1] === "\n") {
262
+ separatorLength = 2;
263
+ }
264
+ const line = buffer.slice(0, lineEnd);
265
+ buffer = buffer.slice(lineEnd + separatorLength);
266
+ const event = processLine(line);
267
+ if (event) yield event;
268
+ }
124
269
  }
270
+ buffer += decoder.decode();
271
+ if (buffer.length > 0) {
272
+ const event = processLine(buffer);
273
+ if (event) yield event;
274
+ }
275
+ const terminal = dispatch(eventType, data, lastEventId, retry);
276
+ if (terminal) yield terminal;
125
277
  } catch (_) {
126
278
  var _error = _, _hasError = true;
127
279
  } finally {
@@ -129,6 +281,32 @@ async function* parseNdjsonStream(stream) {
129
281
  _promise && await _promise;
130
282
  }
131
283
  }
284
+ var IncludedBalanceSchema = zod.z.object({
285
+ balance_usd: zod.z.number(),
286
+ allowance_usd: zod.z.number(),
287
+ period: zod.z.object({
288
+ from: zod.z.string(),
289
+ until: zod.z.string()
290
+ })
291
+ });
292
+ var LegacyBalanceLimitSchema = zod.z.object({
293
+ remaining_percent: zod.z.number().min(0).max(100),
294
+ resets_at: zod.z.string()
295
+ });
296
+
297
+ // src/generated/models/LegacyIncludedBalance.schema.ts
298
+ var LegacyIncludedBalanceSchema = zod.z.object({
299
+ session: LegacyBalanceLimitSchema,
300
+ weekly: LegacyBalanceLimitSchema
301
+ });
302
+
303
+ // src/generated/models/BalanceResponse.schema.ts
304
+ var BalanceResponseSchema = zod.z.object({
305
+ included: zod.z.union([IncludedBalanceSchema, LegacyIncludedBalanceSchema]),
306
+ purchased: zod.z.object({
307
+ balance_usd: zod.z.number()
308
+ })
309
+ });
132
310
  var ToolCallSchema = zod.z.object({
133
311
  function: zod.z.object({
134
312
  name: zod.z.string(),
@@ -177,28 +355,45 @@ var ChatRequestSchema = zod.z.object({
177
355
  logprobs: zod.z.boolean().optional(),
178
356
  top_logprobs: zod.z.number().optional()
179
357
  });
180
- var GenerateRequestSchema = zod.z.object({
181
- model: zod.z.string(),
182
- prompt: zod.z.string().optional(),
183
- suffix: zod.z.string().optional(),
184
- images: zod.z.array(zod.z.string()).optional(),
185
- format: zod.z.union([zod.z.string(), zod.z.object({})]).optional(),
186
- system: zod.z.string().optional(),
187
- stream: zod.z.boolean().optional(),
188
- think: ThinkValueSchema.optional(),
189
- raw: zod.z.boolean().optional(),
190
- keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
191
- options: ModelOptionsSchema.optional(),
192
- logprobs: zod.z.boolean().optional(),
193
- top_logprobs: zod.z.number().optional()
358
+ var TokenLogprobSchema = zod.z.object({
359
+ token: zod.z.string().optional(),
360
+ logprob: zod.z.number().optional(),
361
+ bytes: zod.z.array(zod.z.number()).optional()
194
362
  });
195
- var EmbedRequestSchema = zod.z.object({
196
- model: zod.z.string(),
197
- input: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
198
- truncate: zod.z.boolean().optional(),
199
- dimensions: zod.z.number().optional(),
200
- keep_alive: zod.z.string().optional(),
201
- options: ModelOptionsSchema.optional()
363
+
364
+ // src/generated/models/Logprob.schema.ts
365
+ var LogprobSchema = zod.z.object({
366
+ token: zod.z.string().optional(),
367
+ logprob: zod.z.number().optional(),
368
+ bytes: zod.z.array(zod.z.number()).optional(),
369
+ top_logprobs: zod.z.array(TokenLogprobSchema).optional()
370
+ });
371
+
372
+ // src/generated/models/ChatResponse.schema.ts
373
+ var ChatResponseSchema = zod.z.object({
374
+ model: zod.z.string().optional(),
375
+ created_at: zod.z.string().optional(),
376
+ message: zod.z.object({
377
+ role: zod.z.enum(["assistant"]).optional(),
378
+ content: zod.z.string().optional(),
379
+ thinking: zod.z.string().optional(),
380
+ tool_calls: zod.z.array(ToolCallSchema).optional(),
381
+ images: zod.z.array(zod.z.string()).optional()
382
+ }).optional(),
383
+ done: zod.z.boolean().optional(),
384
+ done_reason: zod.z.string().optional(),
385
+ total_duration: zod.z.number().optional(),
386
+ load_duration: zod.z.number().optional(),
387
+ prompt_eval_count: zod.z.number().optional(),
388
+ prompt_eval_cached_count: zod.z.number().optional(),
389
+ prompt_eval_duration: zod.z.number().optional(),
390
+ eval_count: zod.z.number().optional(),
391
+ eval_duration: zod.z.number().optional(),
392
+ logprobs: zod.z.array(LogprobSchema).optional()
393
+ });
394
+ var CopyRequestSchema = zod.z.object({
395
+ source: zod.z.string(),
396
+ destination: zod.z.string()
202
397
  });
203
398
  var CreateRequestSchema = zod.z.object({
204
399
  model: zod.z.string(),
@@ -215,15 +410,94 @@ var CreateRequestSchema = zod.z.object({
215
410
  quantize: zod.z.string().optional(),
216
411
  draft_quantize: zod.z.string().optional(),
217
412
  requires: zod.z.string().optional(),
413
+ capabilities: zod.z.array(zod.z.string()).optional(),
218
414
  stream: zod.z.boolean().optional()
219
415
  });
220
- var CopyRequestSchema = zod.z.object({
221
- source: zod.z.string(),
222
- destination: zod.z.string()
223
- });
224
416
  var DeleteRequestSchema = zod.z.object({
225
417
  model: zod.z.string()
226
418
  });
419
+ var EmbedRequestSchema = zod.z.object({
420
+ model: zod.z.string(),
421
+ input: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
422
+ truncate: zod.z.boolean().optional(),
423
+ dimensions: zod.z.number().optional(),
424
+ keep_alive: zod.z.string().optional(),
425
+ options: ModelOptionsSchema.optional()
426
+ });
427
+ var EmbedResponseSchema = zod.z.object({
428
+ model: zod.z.string().optional(),
429
+ embeddings: zod.z.array(zod.z.array(zod.z.number())).optional(),
430
+ total_duration: zod.z.number().optional(),
431
+ load_duration: zod.z.number().optional(),
432
+ prompt_eval_count: zod.z.number().optional()
433
+ });
434
+ var GenerateRequestSchema = zod.z.object({
435
+ model: zod.z.string(),
436
+ prompt: zod.z.string().optional(),
437
+ suffix: zod.z.string().optional(),
438
+ images: zod.z.array(zod.z.string()).optional(),
439
+ format: zod.z.union([zod.z.string(), zod.z.object({})]).optional(),
440
+ system: zod.z.string().optional(),
441
+ stream: zod.z.boolean().optional(),
442
+ think: ThinkValueSchema.optional(),
443
+ raw: zod.z.boolean().optional(),
444
+ keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
445
+ options: ModelOptionsSchema.optional(),
446
+ logprobs: zod.z.boolean().optional(),
447
+ top_logprobs: zod.z.number().optional()
448
+ });
449
+ var GenerateResponseSchema = zod.z.object({
450
+ model: zod.z.string().optional(),
451
+ created_at: zod.z.string().optional(),
452
+ response: zod.z.string().optional(),
453
+ thinking: zod.z.string().optional(),
454
+ done: zod.z.boolean().optional(),
455
+ done_reason: zod.z.string().optional(),
456
+ total_duration: zod.z.number().optional(),
457
+ load_duration: zod.z.number().optional(),
458
+ prompt_eval_count: zod.z.number().optional(),
459
+ prompt_eval_cached_count: zod.z.number().optional(),
460
+ prompt_eval_duration: zod.z.number().optional(),
461
+ eval_count: zod.z.number().optional(),
462
+ eval_duration: zod.z.number().optional(),
463
+ logprobs: zod.z.array(LogprobSchema).optional()
464
+ });
465
+ var ModelSummarySchema = zod.z.object({
466
+ name: zod.z.string().optional(),
467
+ model: zod.z.string().optional(),
468
+ remote_model: zod.z.string().optional(),
469
+ remote_host: zod.z.string().optional(),
470
+ modified_at: zod.z.string().optional(),
471
+ size: zod.z.number().optional(),
472
+ digest: zod.z.string().optional(),
473
+ details: zod.z.object({
474
+ format: zod.z.string().optional(),
475
+ family: zod.z.string().optional(),
476
+ families: zod.z.union([zod.z.array(zod.z.string()), zod.z.null()]).optional(),
477
+ parameter_size: zod.z.string().optional(),
478
+ quantization_level: zod.z.string().optional()
479
+ }).optional()
480
+ });
481
+
482
+ // src/generated/models/ListResponse.schema.ts
483
+ var ListResponseSchema = zod.z.object({
484
+ models: zod.z.array(ModelSummarySchema).optional()
485
+ });
486
+ var PsSchema = zod.z.object({
487
+ name: zod.z.string().optional(),
488
+ model: zod.z.string().optional(),
489
+ size: zod.z.number().optional(),
490
+ digest: zod.z.string().optional(),
491
+ details: zod.z.object({}).optional(),
492
+ expires_at: zod.z.string().optional(),
493
+ size_vram: zod.z.number().optional(),
494
+ context_length: zod.z.number().optional()
495
+ });
496
+
497
+ // src/generated/models/PsResponse.schema.ts
498
+ var PsResponseSchema = zod.z.object({
499
+ models: zod.z.array(PsSchema).optional()
500
+ });
227
501
  var PullRequestSchema = zod.z.object({
228
502
  model: zod.z.string(),
229
503
  insecure: zod.z.boolean().optional(),
@@ -238,27 +512,194 @@ var ShowRequestSchema = zod.z.object({
238
512
  model: zod.z.string(),
239
513
  verbose: zod.z.boolean().optional()
240
514
  });
515
+ var ThinkingSchema = zod.z.object({
516
+ values: zod.z.array(zod.z.union([zod.z.boolean(), zod.z.string()])),
517
+ default: zod.z.union([zod.z.boolean(), zod.z.string()])
518
+ });
519
+
520
+ // src/generated/models/ShowResponse.schema.ts
521
+ var ShowResponseSchema = zod.z.object({
522
+ thinking: ThinkingSchema.optional(),
523
+ parameters: zod.z.string().optional(),
524
+ license: zod.z.string().optional(),
525
+ modified_at: zod.z.string().optional(),
526
+ details: zod.z.object({}).optional(),
527
+ template: zod.z.string().optional(),
528
+ capabilities: zod.z.array(zod.z.string()).optional(),
529
+ model_info: zod.z.object({}).optional()
530
+ });
531
+ var StatusResponseSchema = zod.z.object({
532
+ status: zod.z.string().optional()
533
+ });
534
+ var SystemOneContentSchema = zod.z.union([
535
+ zod.z.string().regex(new RegExp("\\S")),
536
+ zod.z.object({}).catchall(zod.z.unknown()),
537
+ zod.z.array(zod.z.unknown())
538
+ ]);
539
+
540
+ // src/generated/models/SystemOneChoiceQuestion.schema.ts
541
+ var SystemOneChoiceQuestionSchema = zod.z.object({
542
+ type: zod.z.enum(["choice"]),
543
+ instructions: SystemOneContentSchema,
544
+ criteria: zod.z.object({}).catchall(zod.z.union([zod.z.string(), zod.z.null()])).refine((v) => Object.keys(v).length >= 2, { message: "must have at least 2 properties" }).refine((v) => Object.keys(v).length <= 26, { message: "must have at most 26 properties" }).refine((v) => Object.keys(v).every((k) => new RegExp("\\S").test(k)), {
545
+ message: 'property names must match pattern "\\S"'
546
+ })
547
+ });
548
+ var SystemOneNoulQuestionSchema = zod.z.object({
549
+ type: zod.z.enum(["noul"]),
550
+ instructions: SystemOneContentSchema,
551
+ criteria: zod.z.object({
552
+ false: zod.z.string().optional(),
553
+ true: zod.z.string().optional()
554
+ }).optional()
555
+ });
556
+ var SystemOneScoreQuestionSchema = zod.z.object({
557
+ type: zod.z.enum(["score"]),
558
+ instructions: SystemOneContentSchema,
559
+ criteria: zod.z.array(zod.z.string()).min(2).max(26)
560
+ });
561
+
562
+ // src/generated/models/SystemOneRequest.schema.ts
563
+ var SystemOneRequestSchema = zod.z.object({
564
+ model: zod.z.string().regex(new RegExp("\\S")),
565
+ state: SystemOneContentSchema,
566
+ images: zod.z.array(zod.z.string()).optional(),
567
+ questions: zod.z.object({}).catchall(
568
+ zod.z.union([
569
+ SystemOneChoiceQuestionSchema,
570
+ SystemOneNoulQuestionSchema,
571
+ SystemOneScoreQuestionSchema
572
+ ])
573
+ ).refine((v) => Object.keys(v).length >= 1, { message: "must have at least 1 properties" }).refine((v) => Object.keys(v).length <= 64, { message: "must have at most 64 properties" }).refine((v) => Object.keys(v).every((k) => new RegExp("\\S").test(k)), {
574
+ message: 'property names must match pattern "\\S"'
575
+ }),
576
+ keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional()
577
+ });
578
+ var SystemOneConfidenceSchema = zod.z.number().min(0).max(1);
579
+ var SystemOneProbabilitiesSchema = zod.z.object({}).catchall(zod.z.number().min(0).max(1));
580
+
581
+ // src/generated/models/SystemOneChoiceAnswer.schema.ts
582
+ var SystemOneChoiceAnswerSchema = zod.z.object({
583
+ type: zod.z.enum(["choice"]),
584
+ choice: zod.z.string(),
585
+ probabilities: SystemOneProbabilitiesSchema,
586
+ confidence: SystemOneConfidenceSchema
587
+ });
588
+ var SystemOneNoulAnswerSchema = zod.z.object({
589
+ type: zod.z.enum(["noul"]),
590
+ noul: zod.z.number().min(0).max(1)
591
+ });
592
+ var SystemOneScoreAnswerSchema = zod.z.object({
593
+ type: zod.z.enum(["score"]),
594
+ score: zod.z.number().min(0).max(25),
595
+ legend: zod.z.object({}).catchall(zod.z.string()),
596
+ probabilities: SystemOneProbabilitiesSchema,
597
+ confidence: SystemOneConfidenceSchema
598
+ });
599
+
600
+ // src/generated/models/SystemOneResponse.schema.ts
601
+ var SystemOneResponseSchema = zod.z.object({
602
+ model: zod.z.string(),
603
+ answers: zod.z.object({}).catchall(
604
+ zod.z.union([SystemOneChoiceAnswerSchema, SystemOneNoulAnswerSchema, SystemOneScoreAnswerSchema])
605
+ ),
606
+ usage: zod.z.object({
607
+ input_tokens: zod.z.number().min(0),
608
+ output_tokens: zod.z.number().min(0)
609
+ })
610
+ });
611
+ var UsageMetricsSchema = zod.z.object({
612
+ request_count: zod.z.number().min(0),
613
+ usage_usd: zod.z.number().optional(),
614
+ input_tokens: zod.z.number().optional(),
615
+ cached_input_tokens: zod.z.number().optional(),
616
+ output_tokens: zod.z.number().optional()
617
+ });
618
+
619
+ // src/generated/models/UsageBucket.schema.ts
620
+ var UsageBucketSchema = zod.z.intersection(
621
+ UsageMetricsSchema,
622
+ zod.z.object({
623
+ from: zod.z.string(),
624
+ until: zod.z.string(),
625
+ partial: zod.z.boolean().optional()
626
+ })
627
+ );
628
+
629
+ // src/generated/models/UsageResponse.schema.ts
630
+ var UsageResponseSchema = zod.z.object({
631
+ range: zod.z.enum(["24h", "7d", "30d"]),
632
+ scope: zod.z.enum(["self", "team"]),
633
+ granularity: zod.z.enum(["hour", "day"]),
634
+ from: zod.z.string(),
635
+ until: zod.z.string(),
636
+ totals: UsageMetricsSchema,
637
+ buckets: zod.z.array(UsageBucketSchema)
638
+ });
639
+ var VersionResponseSchema = zod.z.object({
640
+ version: zod.z.string().optional()
641
+ });
642
+ var WebFetchRequestSchema = zod.z.object({
643
+ url: zod.z.string()
644
+ });
645
+ var WebFetchResponseSchema = zod.z.object({
646
+ title: zod.z.string().optional(),
647
+ content: zod.z.string().optional(),
648
+ links: zod.z.array(zod.z.string()).optional()
649
+ });
650
+ var WebSearchRequestSchema = zod.z.object({
651
+ query: zod.z.string(),
652
+ max_results: zod.z.number().min(1).max(10).optional()
653
+ });
654
+ var WebSearchResultSchema = zod.z.object({
655
+ title: zod.z.string().optional(),
656
+ url: zod.z.string().optional(),
657
+ content: zod.z.string().optional()
658
+ });
659
+
660
+ // src/generated/models/WebSearchResponse.schema.ts
661
+ var WebSearchResponseSchema = zod.z.object({
662
+ results: zod.z.array(WebSearchResultSchema).optional()
663
+ });
241
664
 
242
665
  // src/generated/runtime/schema-registry.ts
243
666
  var requestSchemas = {
244
667
  chat: ChatRequestSchema,
245
- generate: GenerateRequestSchema,
246
- embed: EmbedRequestSchema,
247
- create: CreateRequestSchema,
248
668
  copy: CopyRequestSchema,
669
+ create: CreateRequestSchema,
249
670
  delete: DeleteRequestSchema,
671
+ embed: EmbedRequestSchema,
672
+ generate: GenerateRequestSchema,
250
673
  pull: PullRequestSchema,
251
674
  push: PushRequestSchema,
252
- show: ShowRequestSchema
253
- // Operations without a registered request schema (blobs, ps, tags,
254
- // version, systemOne, openai*, anthropic*) skip validation. This is
255
- // deliberate — the OpenAPI spec doesn't define request bodies for
256
- // GET/HEAD operations, and the compat-surface request schemas (OpenAI,
257
- // Anthropic) are richer than what the IR currently models.
675
+ show: ShowRequestSchema,
676
+ systemOne: SystemOneRequestSchema,
677
+ webFetch: WebFetchRequestSchema,
678
+ webSearch: WebSearchRequestSchema
679
+ };
680
+ var responseSchemas = {
681
+ balance: BalanceResponseSchema,
682
+ chat: ChatResponseSchema,
683
+ create: StatusResponseSchema,
684
+ embed: EmbedResponseSchema,
685
+ generate: GenerateResponseSchema,
686
+ ps: PsResponseSchema,
687
+ pull: StatusResponseSchema,
688
+ push: StatusResponseSchema,
689
+ show: ShowResponseSchema,
690
+ systemOne: SystemOneResponseSchema,
691
+ tags: ListResponseSchema,
692
+ usage: UsageResponseSchema,
693
+ version: VersionResponseSchema,
694
+ webFetch: WebFetchResponseSchema,
695
+ webSearch: WebSearchResponseSchema
258
696
  };
259
697
  function getRequestSchema(operationId) {
260
698
  return requestSchemas[operationId];
261
699
  }
700
+ function getResponseSchema(operationId) {
701
+ return responseSchemas[operationId];
702
+ }
262
703
 
263
704
  // src/generated/runtime/runtime.ts
264
705
  function compareVersions(a, b) {
@@ -271,18 +712,13 @@ function compareVersions(a, b) {
271
712
  }
272
713
  return 0;
273
714
  }
274
- function assertOperationAllowed(operation, options) {
275
- const localMode = options.localMode ?? true;
276
- if (!localMode && !operation.environment.cloud) {
277
- throw new OllamaGenericClientError(
278
- `Operation ${operation.operationId} (${operation.method} ${operation.path}) is local-only and not supported in cloud mode.`
279
- );
280
- }
281
- if (operation.constraints?.minOllamaVersion && options.serverVersion && compareVersions(options.serverVersion, operation.constraints.minOllamaVersion) < 0) {
282
- throw new OllamaGenericClientError(
283
- `Operation ${operation.operationId} (${operation.method} ${operation.path}) requires Ollama >= ${operation.constraints.minOllamaVersion} (server reports ${options.serverVersion}).`
284
- );
285
- }
715
+ async function fetchServerVersion(http) {
716
+ const result = await http.request({
717
+ path: "/api/version",
718
+ method: "GET"
719
+ });
720
+ if (result && typeof result.version === "string") return result.version;
721
+ return void 0;
286
722
  }
287
723
  function shouldStream(req) {
288
724
  if (req.body && typeof req.body === "object" && "stream" in req.body) {
@@ -304,7 +740,35 @@ var OllamaRuntime = class {
304
740
  constructor(options) {
305
741
  this.options = options;
306
742
  }
307
- options;
743
+ /**
744
+ * Cached promise of the Ollama server version, populated lazily the first
745
+ * time a version-gated operation is invoked. `undefined` until then.
746
+ *
747
+ * Wave 12 (P0 #5): see {@link OllamaRuntimeOptions.enforceVersion}.
748
+ */
749
+ serverVersionCache;
750
+ /**
751
+ * Wave 15 (P0): resolve the HTTP backend for a given operation.
752
+ *
753
+ * Operations with a declared `host` (e.g. web search/fetch at
754
+ * https://ollama.com) must route to a HttpClient pointed at that host,
755
+ * not the default one. The runtime accepts an optional `cloudHttp`
756
+ * backend for this purpose — if the operation declares a host and no
757
+ * cloud backend is configured, the runtime throws rather than silently
758
+ * sending the request to the wrong server.
759
+ */
760
+ resolveHttpBackend(operation) {
761
+ if (operation.host) {
762
+ const cloudHttp = this.options.cloudHttp;
763
+ if (!cloudHttp) {
764
+ throw new OllamaGenericClientError(
765
+ `Operation ${operation.operationId} (${operation.method} ${operation.path}) targets host "${operation.host}" but the runtime has no cloudHttp backend configured. Use OllamaClient.webSearch() / OllamaClient.webFetch() for cloud-hosted operations, or construct OllamaRuntime with a cloudHttp option.`
766
+ );
767
+ }
768
+ return cloudHttp;
769
+ }
770
+ return this.options.http;
771
+ }
308
772
  /**
309
773
  * Invoke an operation. Called by every generated API method.
310
774
  *
@@ -313,7 +777,7 @@ var OllamaRuntime = class {
313
777
  * class's overloads pick the right return type at compile time.
314
778
  */
315
779
  async invoke(req) {
316
- assertOperationAllowed(req.operation, this.options);
780
+ await this.assertOperationAllowed(req.operation);
317
781
  let body = buildBody(req);
318
782
  if (this.options.validateRequests === true && body !== void 0) {
319
783
  const schema = getRequestSchema(req.operation.operationId);
@@ -332,34 +796,189 @@ var OllamaRuntime = class {
332
796
  body = result.data;
333
797
  }
334
798
  }
799
+ if (body !== void 0) {
800
+ const serialized = serializeForByteCount(body);
801
+ const hasImages = bodyHasImages(body);
802
+ const maxBytesWithImages = req.operation.constraints?.maxRequestBytesWithImages;
803
+ const maxBytesBase = req.operation.constraints?.maxRequestBytes;
804
+ const applicableLimit = hasImages && maxBytesWithImages !== void 0 ? maxBytesWithImages : maxBytesBase;
805
+ if (applicableLimit !== void 0 && serialized.byteLength > applicableLimit) {
806
+ throw new OllamaRequestTooLargeError(
807
+ `Operation ${req.operation.operationId} (${req.operation.method} ${req.operation.path}) request body is ${serialized.byteLength} bytes, exceeding the contract limit of ${applicableLimit} bytes` + (hasImages ? " (images limit)." : "."),
808
+ {
809
+ operationId: req.operation.operationId,
810
+ actualBytes: serialized.byteLength,
811
+ maxBytes: applicableLimit,
812
+ request: { method: req.operation.method, url: req.operation.path }
813
+ }
814
+ );
815
+ }
816
+ }
335
817
  const streaming = shouldStream(req);
818
+ const resolvedPath = resolvePathParams(req.operation.path, req.pathParams);
819
+ const pathWithQuery = applyQueryParams(resolvedPath, req.queryParams);
820
+ const model = req.model ?? extractModelFromBody(body);
821
+ const headers = {};
822
+ if (req.headerParams) {
823
+ for (const [key, value] of Object.entries(req.headerParams)) {
824
+ headers[key] = value;
825
+ }
826
+ }
336
827
  const httpReq = {
337
- path: req.operation.path,
828
+ path: pathWithQuery,
338
829
  method: req.operation.method,
339
830
  ...body !== void 0 ? { body } : {},
831
+ ...Object.keys(headers).length > 0 ? { headers } : {},
340
832
  ...req.signal !== void 0 ? { signal: req.signal } : {},
341
- // For streaming calls, request the raw Response so we can pipe it
342
- // through parseNdjsonStream directly. This inherits middleware,
343
- // retry, telemetry, and error-mapping from HttpClient — the
344
- // previous Wave 3 implementation bypassed them with a direct
345
- // `fetch()` call.
346
- ...streaming ? { raw: true } : {}
833
+ ...streaming ? { raw: true } : {},
834
+ ...model !== void 0 ? { model } : {}
347
835
  };
348
836
  if (!streaming) {
349
- return await this.options.http.request(httpReq);
837
+ const result = await this.resolveHttpBackend(req.operation).request(httpReq);
838
+ if (this.options.validateResponses === true) {
839
+ const responseSchema = getResponseSchema(req.operation.operationId);
840
+ if (responseSchema) {
841
+ const result2 = responseSchema.safeParse(result);
842
+ if (!result2.success) {
843
+ throw new OllamaResponseValidationError(
844
+ `Response validation failed for operation "${req.operation.operationId}" (${req.operation.method} ${req.operation.path}): ` + result2.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; "),
845
+ {
846
+ operationId: req.operation.operationId,
847
+ issues: result2.error.issues,
848
+ request: { method: req.operation.method, url: req.operation.path }
849
+ }
850
+ );
851
+ }
852
+ }
853
+ }
854
+ return result;
350
855
  }
351
- const response = await this.options.http.request(httpReq);
856
+ const response = await this.resolveHttpBackend(req.operation).request(httpReq);
352
857
  if (!response.body) {
353
858
  throw new OllamaGenericClientError(
354
859
  `Operation ${req.operation.operationId}: streaming response had no body.`
355
860
  );
356
861
  }
357
- return parseNdjsonStream(response.body);
862
+ return parseStreamByMode(req.operation.transport.mode, response.body);
863
+ }
864
+ /**
865
+ * Apply environment + version guards before delegating to HttpClient.
866
+ *
867
+ * Throws {@link OllamaGenericClientError} when:
868
+ * - The operation is local-only and the runtime is in cloud mode.
869
+ * - The operation has `constraints.minOllamaVersion` and the server is older.
870
+ *
871
+ * Wave 12 (P0 #5): when `minOllamaVersion` is declared but the runtime's
872
+ * `serverVersion` is unknown AND `enforceVersion` is `'auto'` or
873
+ * `'strict'`, the runtime lazily fetches `/api/version` (cached on the
874
+ * runtime instance) so the constraint is actually enforced even when the
875
+ * caller didn't supply it. Previously the constraint was only enforced
876
+ * when `serverVersion` was manually supplied — meaning in practice it was
877
+ * almost never enforced.
878
+ */
879
+ async assertOperationAllowed(operation) {
880
+ const localMode = this.options.localMode ?? true;
881
+ if (!localMode && !operation.environment.cloud) {
882
+ throw new OllamaGenericClientError(
883
+ `Operation ${operation.operationId} (${operation.method} ${operation.path}) is local-only and not supported in cloud mode.`
884
+ );
885
+ }
886
+ const minVersion = operation.constraints?.minOllamaVersion;
887
+ if (!minVersion) return;
888
+ let serverVersion = this.options.serverVersion;
889
+ const policy = this.options.enforceVersion ?? "auto";
890
+ if (!serverVersion && policy !== "off") {
891
+ if (!this.serverVersionCache) {
892
+ const p = fetchServerVersion(this.options.http).catch((err) => {
893
+ if (policy === "strict") {
894
+ throw new OllamaServerVersionUnknownError(
895
+ `Operation ${operation.operationId} requires Ollama >= ${minVersion} but the runtime could not determine the server version (enforceVersion: 'strict').`,
896
+ {
897
+ operationId: operation.operationId,
898
+ minRequiredVersion: minVersion,
899
+ cause: err
900
+ }
901
+ );
902
+ }
903
+ return void 0;
904
+ });
905
+ this.serverVersionCache = p;
906
+ }
907
+ serverVersion = await this.serverVersionCache ?? void 0;
908
+ }
909
+ if (serverVersion && compareVersions(serverVersion, minVersion) < 0) {
910
+ throw new OllamaGenericClientError(
911
+ `Operation ${operation.operationId} (${operation.method} ${operation.path}) requires Ollama >= ${minVersion} (server reports ${serverVersion}).`
912
+ );
913
+ }
358
914
  }
359
915
  };
916
+ function parseStreamByMode(mode, body) {
917
+ if (mode === "ndjson") {
918
+ return parseNdjsonStream(body);
919
+ }
920
+ if (mode === "sse") {
921
+ return parseSseStreamAsJson(body);
922
+ }
923
+ throw new OllamaGenericClientError(
924
+ `Transport mode "${mode}" is not a streaming mode; cannot parse a stream for it.`
925
+ );
926
+ }
927
+ async function* parseSseStreamAsJson(body) {
928
+ for await (const event of parseSseStream(body)) {
929
+ const data = event.data;
930
+ if (!data) continue;
931
+ if (data === "[DONE]") return;
932
+ try {
933
+ yield JSON.parse(data);
934
+ } catch (err) {
935
+ throw new OllamaGenericClientError(`Failed to parse SSE event data as JSON: ${data}`, {
936
+ cause: err
937
+ });
938
+ }
939
+ }
940
+ }
941
+ function serializeForByteCount(body) {
942
+ if (body instanceof Uint8Array) return body;
943
+ if (typeof body === "string") return new TextEncoder().encode(body);
944
+ const json = JSON.stringify(body);
945
+ return new TextEncoder().encode(json);
946
+ }
947
+ function bodyHasImages(body) {
948
+ if (typeof body !== "object" || body === null) return false;
949
+ const obj = body;
950
+ const images = obj.images;
951
+ return Array.isArray(images) && images.length > 0;
952
+ }
953
+ function resolvePathParams(pathTemplate, pathParams) {
954
+ if (!pathTemplate.includes("{")) return pathTemplate;
955
+ const params = pathParams ?? {};
956
+ return pathTemplate.replace(/\{([^}]+)\}/g, (_match, name) => {
957
+ const value = params[name];
958
+ if (value === void 0) {
959
+ throw new OllamaGenericClientError(
960
+ `Missing path parameter "${name}" for path template "${pathTemplate}". Provide it via the pathParams field on the invoke() request.`
961
+ );
962
+ }
963
+ return encodeURIComponent(value);
964
+ });
965
+ }
966
+ function extractModelFromBody(body) {
967
+ if (typeof body !== "object" || body === null) return void 0;
968
+ const obj = body;
969
+ const model = obj.model;
970
+ return typeof model === "string" ? model : void 0;
971
+ }
972
+ function applyQueryParams(path, queryParams) {
973
+ if (!queryParams || Object.keys(queryParams).length === 0) return path;
974
+ const pairs = Object.entries(queryParams).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
975
+ return `${path}?${pairs}`;
976
+ }
360
977
 
361
978
  exports.OllamaRuntime = OllamaRuntime;
362
979
  exports.getRequestSchema = getRequestSchema;
980
+ exports.getResponseSchema = getResponseSchema;
363
981
  exports.requestSchemas = requestSchemas;
982
+ exports.responseSchemas = responseSchemas;
364
983
  //# sourceMappingURL=generated-runtime.cjs.map
365
984
  //# sourceMappingURL=generated-runtime.cjs.map