@nemesis-oss/ollama-sdk 1.6.0 → 1.8.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.
- package/CHANGELOG.md +14 -2
- package/README.md +31 -0
- package/dist/anthropic-B_UXplNF.d.ts +1647 -0
- package/dist/anthropic-CVDFy_a0.d.cts +1647 -0
- package/dist/generated-api.cjs +74 -6
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +230 -629
- package/dist/generated-api.d.ts +230 -629
- package/dist/generated-api.js +72 -7
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +89 -1
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.d.cts +121 -1
- package/dist/generated-models-schemas.d.ts +121 -1
- package/dist/generated-models-schemas.js +79 -2
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +576 -57
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +21 -23
- package/dist/generated-runtime.d.ts +21 -23
- package/dist/generated-runtime.js +575 -58
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +1210 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +395 -876
- package/dist/index.d.ts +395 -876
- package/dist/index.js +1207 -82
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +287 -73
- package/dist/mcp-generated.cjs +96 -7
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.d.cts +3 -3
- package/dist/mcp-generated.d.ts +3 -3
- package/dist/mcp-generated.js +96 -7
- package/dist/mcp-generated.js.map +1 -1
- package/dist/mcp-http.cjs +43 -4
- package/dist/mcp-http.cjs.map +1 -1
- package/dist/mcp-http.d.cts +5 -1
- package/dist/mcp-http.d.ts +5 -1
- package/dist/mcp-http.js +43 -4
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-stdio.cjs +43 -4
- package/dist/mcp-stdio.cjs.map +1 -1
- package/dist/mcp-stdio.d.cts +5 -1
- package/dist/mcp-stdio.d.ts +5 -1
- package/dist/mcp-stdio.js +43 -4
- package/dist/mcp-stdio.js.map +1 -1
- package/dist/{runtime-CVQkbYgF.d.ts → runtime-C6UYtBRB.d.ts} +222 -6
- package/dist/{runtime-IxRpUBjN.d.cts → runtime-DTmUeU6K.d.cts} +222 -6
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.js.map +1 -1
- package/dist/types-CI-gM2u5.d.cts +139 -0
- package/dist/types-CI-gM2u5.d.ts +139 -0
- package/package.json +4 -2
- package/dist/types-MOsWXEE7.d.cts +0 -66
- package/dist/types-MOsWXEE7.d.ts +0 -66
|
@@ -74,6 +74,35 @@ var OllamaRequestValidationError = class extends OllamaClientError {
|
|
|
74
74
|
this.issues = options.issues;
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
+
var OllamaRequestTooLargeError = class extends OllamaClientError {
|
|
78
|
+
operationId;
|
|
79
|
+
actualBytes;
|
|
80
|
+
maxBytes;
|
|
81
|
+
constructor(message, options) {
|
|
82
|
+
super(message, { ...options, code: "request_too_large", retryable: false, status: 413 });
|
|
83
|
+
this.operationId = options.operationId;
|
|
84
|
+
this.actualBytes = options.actualBytes;
|
|
85
|
+
this.maxBytes = options.maxBytes;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var OllamaResponseValidationError = class extends OllamaClientError {
|
|
89
|
+
operationId;
|
|
90
|
+
issues;
|
|
91
|
+
constructor(message, options) {
|
|
92
|
+
super(message, { ...options, code: "response_validation_error", retryable: false });
|
|
93
|
+
this.operationId = options.operationId;
|
|
94
|
+
this.issues = options.issues;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var OllamaServerVersionUnknownError = class extends OllamaClientError {
|
|
98
|
+
operationId;
|
|
99
|
+
minRequiredVersion;
|
|
100
|
+
constructor(message, options) {
|
|
101
|
+
super(message, { ...options, code: "server_version_unknown", retryable: false });
|
|
102
|
+
this.operationId = options.operationId;
|
|
103
|
+
this.minRequiredVersion = options.minRequiredVersion;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
77
106
|
var OllamaGenericClientError = class extends OllamaClientError {
|
|
78
107
|
constructor(message, options) {
|
|
79
108
|
super(message, { ...options, code: "client_error" });
|
|
@@ -129,6 +158,98 @@ async function* parseNdjsonStream(stream) {
|
|
|
129
158
|
_promise && await _promise;
|
|
130
159
|
}
|
|
131
160
|
}
|
|
161
|
+
|
|
162
|
+
// src/streaming/sse.ts
|
|
163
|
+
function dispatch(event, data, id, retry) {
|
|
164
|
+
if (data.length === 0) return void 0;
|
|
165
|
+
const joined = data.join("\n");
|
|
166
|
+
return {
|
|
167
|
+
...event !== void 0 ? { event } : {},
|
|
168
|
+
data: joined.endsWith("\n") ? joined.slice(0, -1) : joined,
|
|
169
|
+
...id !== void 0 ? { id } : {},
|
|
170
|
+
...retry !== void 0 ? { retry } : {}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async function* parseSseStream(stream) {
|
|
174
|
+
var _stack = [];
|
|
175
|
+
try {
|
|
176
|
+
const reader = stream.getReader();
|
|
177
|
+
const decoder = new TextDecoder();
|
|
178
|
+
let buffer = "";
|
|
179
|
+
let eventType;
|
|
180
|
+
let data = [];
|
|
181
|
+
let lastEventId;
|
|
182
|
+
let retry;
|
|
183
|
+
const processLine = (line) => {
|
|
184
|
+
if (line.length === 0) {
|
|
185
|
+
const event = dispatch(eventType, data, lastEventId, retry);
|
|
186
|
+
eventType = void 0;
|
|
187
|
+
data = [];
|
|
188
|
+
retry = void 0;
|
|
189
|
+
return event;
|
|
190
|
+
}
|
|
191
|
+
if (line.startsWith(":")) return void 0;
|
|
192
|
+
const separator = line.indexOf(":");
|
|
193
|
+
const field = separator === -1 ? line : line.slice(0, separator);
|
|
194
|
+
let value = separator === -1 ? "" : line.slice(separator + 1);
|
|
195
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
196
|
+
switch (field) {
|
|
197
|
+
case "event":
|
|
198
|
+
eventType = value;
|
|
199
|
+
break;
|
|
200
|
+
case "data":
|
|
201
|
+
data.push(value);
|
|
202
|
+
break;
|
|
203
|
+
case "id":
|
|
204
|
+
if (!value.includes("\0")) lastEventId = value;
|
|
205
|
+
break;
|
|
206
|
+
case "retry": {
|
|
207
|
+
if (/^\d+$/.test(value)) {
|
|
208
|
+
const parsed = Number(value);
|
|
209
|
+
if (Number.isSafeInteger(parsed)) retry = parsed;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
default:
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
return void 0;
|
|
217
|
+
};
|
|
218
|
+
const _reader = __using(_stack, disposableReader(reader), true);
|
|
219
|
+
while (true) {
|
|
220
|
+
const { done, value } = await reader.read();
|
|
221
|
+
if (done) break;
|
|
222
|
+
buffer += decoder.decode(value, { stream: true });
|
|
223
|
+
while (true) {
|
|
224
|
+
const lf = buffer.indexOf("\n");
|
|
225
|
+
const cr = buffer.indexOf("\r");
|
|
226
|
+
if (lf === -1 && cr === -1) break;
|
|
227
|
+
if (cr !== -1 && lf === -1 && cr === buffer.length - 1) break;
|
|
228
|
+
const lineEnd = lf === -1 ? cr : cr === -1 ? lf : Math.min(lf, cr);
|
|
229
|
+
let separatorLength = 1;
|
|
230
|
+
if (buffer[lineEnd] === "\r" && buffer[lineEnd + 1] === "\n") {
|
|
231
|
+
separatorLength = 2;
|
|
232
|
+
}
|
|
233
|
+
const line = buffer.slice(0, lineEnd);
|
|
234
|
+
buffer = buffer.slice(lineEnd + separatorLength);
|
|
235
|
+
const event = processLine(line);
|
|
236
|
+
if (event) yield event;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
buffer += decoder.decode();
|
|
240
|
+
if (buffer.length > 0) {
|
|
241
|
+
const event = processLine(buffer);
|
|
242
|
+
if (event) yield event;
|
|
243
|
+
}
|
|
244
|
+
const terminal = dispatch(eventType, data, lastEventId, retry);
|
|
245
|
+
if (terminal) yield terminal;
|
|
246
|
+
} catch (_) {
|
|
247
|
+
var _error = _, _hasError = true;
|
|
248
|
+
} finally {
|
|
249
|
+
var _promise = __callDispose(_stack, _error, _hasError);
|
|
250
|
+
_promise && await _promise;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
132
253
|
var ToolCallSchema = zod.z.object({
|
|
133
254
|
function: zod.z.object({
|
|
134
255
|
name: zod.z.string(),
|
|
@@ -177,28 +298,45 @@ var ChatRequestSchema = zod.z.object({
|
|
|
177
298
|
logprobs: zod.z.boolean().optional(),
|
|
178
299
|
top_logprobs: zod.z.number().optional()
|
|
179
300
|
});
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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()
|
|
301
|
+
var TokenLogprobSchema = zod.z.object({
|
|
302
|
+
token: zod.z.string().optional(),
|
|
303
|
+
logprob: zod.z.number().optional(),
|
|
304
|
+
bytes: zod.z.array(zod.z.number()).optional()
|
|
194
305
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
306
|
+
|
|
307
|
+
// src/generated/models/Logprob.schema.ts
|
|
308
|
+
var LogprobSchema = zod.z.object({
|
|
309
|
+
token: zod.z.string().optional(),
|
|
310
|
+
logprob: zod.z.number().optional(),
|
|
311
|
+
bytes: zod.z.array(zod.z.number()).optional(),
|
|
312
|
+
top_logprobs: zod.z.array(TokenLogprobSchema).optional()
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// src/generated/models/ChatResponse.schema.ts
|
|
316
|
+
var ChatResponseSchema = zod.z.object({
|
|
317
|
+
model: zod.z.string().optional(),
|
|
318
|
+
created_at: zod.z.string().optional(),
|
|
319
|
+
message: zod.z.object({
|
|
320
|
+
role: zod.z.enum(["assistant"]).optional(),
|
|
321
|
+
content: zod.z.string().optional(),
|
|
322
|
+
thinking: zod.z.string().optional(),
|
|
323
|
+
tool_calls: zod.z.array(ToolCallSchema).optional(),
|
|
324
|
+
images: zod.z.array(zod.z.string()).optional()
|
|
325
|
+
}).optional(),
|
|
326
|
+
done: zod.z.boolean().optional(),
|
|
327
|
+
done_reason: zod.z.string().optional(),
|
|
328
|
+
total_duration: zod.z.number().optional(),
|
|
329
|
+
load_duration: zod.z.number().optional(),
|
|
330
|
+
prompt_eval_count: zod.z.number().optional(),
|
|
331
|
+
prompt_eval_cached_count: zod.z.number().optional(),
|
|
332
|
+
prompt_eval_duration: zod.z.number().optional(),
|
|
333
|
+
eval_count: zod.z.number().optional(),
|
|
334
|
+
eval_duration: zod.z.number().optional(),
|
|
335
|
+
logprobs: zod.z.array(LogprobSchema).optional()
|
|
336
|
+
});
|
|
337
|
+
var CopyRequestSchema = zod.z.object({
|
|
338
|
+
source: zod.z.string(),
|
|
339
|
+
destination: zod.z.string()
|
|
202
340
|
});
|
|
203
341
|
var CreateRequestSchema = zod.z.object({
|
|
204
342
|
model: zod.z.string(),
|
|
@@ -217,13 +355,91 @@ var CreateRequestSchema = zod.z.object({
|
|
|
217
355
|
requires: zod.z.string().optional(),
|
|
218
356
|
stream: zod.z.boolean().optional()
|
|
219
357
|
});
|
|
220
|
-
var CopyRequestSchema = zod.z.object({
|
|
221
|
-
source: zod.z.string(),
|
|
222
|
-
destination: zod.z.string()
|
|
223
|
-
});
|
|
224
358
|
var DeleteRequestSchema = zod.z.object({
|
|
225
359
|
model: zod.z.string()
|
|
226
360
|
});
|
|
361
|
+
var EmbedRequestSchema = zod.z.object({
|
|
362
|
+
model: zod.z.string(),
|
|
363
|
+
input: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
364
|
+
truncate: zod.z.boolean().optional(),
|
|
365
|
+
dimensions: zod.z.number().optional(),
|
|
366
|
+
keep_alive: zod.z.string().optional(),
|
|
367
|
+
options: ModelOptionsSchema.optional()
|
|
368
|
+
});
|
|
369
|
+
var EmbedResponseSchema = zod.z.object({
|
|
370
|
+
model: zod.z.string().optional(),
|
|
371
|
+
embeddings: zod.z.array(zod.z.array(zod.z.number())).optional(),
|
|
372
|
+
total_duration: zod.z.number().optional(),
|
|
373
|
+
load_duration: zod.z.number().optional(),
|
|
374
|
+
prompt_eval_count: zod.z.number().optional()
|
|
375
|
+
});
|
|
376
|
+
var GenerateRequestSchema = zod.z.object({
|
|
377
|
+
model: zod.z.string(),
|
|
378
|
+
prompt: zod.z.string().optional(),
|
|
379
|
+
suffix: zod.z.string().optional(),
|
|
380
|
+
images: zod.z.array(zod.z.string()).optional(),
|
|
381
|
+
format: zod.z.union([zod.z.string(), zod.z.object({})]).optional(),
|
|
382
|
+
system: zod.z.string().optional(),
|
|
383
|
+
stream: zod.z.boolean().optional(),
|
|
384
|
+
think: ThinkValueSchema.optional(),
|
|
385
|
+
raw: zod.z.boolean().optional(),
|
|
386
|
+
keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
|
|
387
|
+
options: ModelOptionsSchema.optional(),
|
|
388
|
+
logprobs: zod.z.boolean().optional(),
|
|
389
|
+
top_logprobs: zod.z.number().optional()
|
|
390
|
+
});
|
|
391
|
+
var GenerateResponseSchema = zod.z.object({
|
|
392
|
+
model: zod.z.string().optional(),
|
|
393
|
+
created_at: zod.z.string().optional(),
|
|
394
|
+
response: zod.z.string().optional(),
|
|
395
|
+
thinking: zod.z.string().optional(),
|
|
396
|
+
done: zod.z.boolean().optional(),
|
|
397
|
+
done_reason: zod.z.string().optional(),
|
|
398
|
+
total_duration: zod.z.number().optional(),
|
|
399
|
+
load_duration: zod.z.number().optional(),
|
|
400
|
+
prompt_eval_count: zod.z.number().optional(),
|
|
401
|
+
prompt_eval_cached_count: zod.z.number().optional(),
|
|
402
|
+
prompt_eval_duration: zod.z.number().optional(),
|
|
403
|
+
eval_count: zod.z.number().optional(),
|
|
404
|
+
eval_duration: zod.z.number().optional(),
|
|
405
|
+
logprobs: zod.z.array(LogprobSchema).optional()
|
|
406
|
+
});
|
|
407
|
+
var ModelSummarySchema = zod.z.object({
|
|
408
|
+
name: zod.z.string().optional(),
|
|
409
|
+
model: zod.z.string().optional(),
|
|
410
|
+
remote_model: zod.z.string().optional(),
|
|
411
|
+
remote_host: zod.z.string().optional(),
|
|
412
|
+
modified_at: zod.z.string().optional(),
|
|
413
|
+
size: zod.z.number().optional(),
|
|
414
|
+
digest: zod.z.string().optional(),
|
|
415
|
+
details: zod.z.object({
|
|
416
|
+
format: zod.z.string().optional(),
|
|
417
|
+
family: zod.z.string().optional(),
|
|
418
|
+
families: zod.z.array(zod.z.string()).optional(),
|
|
419
|
+
parameter_size: zod.z.string().optional(),
|
|
420
|
+
quantization_level: zod.z.string().optional()
|
|
421
|
+
}).optional()
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// src/generated/models/ListResponse.schema.ts
|
|
425
|
+
var ListResponseSchema = zod.z.object({
|
|
426
|
+
models: zod.z.array(ModelSummarySchema).optional()
|
|
427
|
+
});
|
|
428
|
+
var PsSchema = zod.z.object({
|
|
429
|
+
name: zod.z.string().optional(),
|
|
430
|
+
model: zod.z.string().optional(),
|
|
431
|
+
size: zod.z.number().optional(),
|
|
432
|
+
digest: zod.z.string().optional(),
|
|
433
|
+
details: zod.z.object({}).optional(),
|
|
434
|
+
expires_at: zod.z.string().optional(),
|
|
435
|
+
size_vram: zod.z.number().optional(),
|
|
436
|
+
context_length: zod.z.number().optional()
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// src/generated/models/PsResponse.schema.ts
|
|
440
|
+
var PsResponseSchema = zod.z.object({
|
|
441
|
+
models: zod.z.array(PsSchema).optional()
|
|
442
|
+
});
|
|
227
443
|
var PullRequestSchema = zod.z.object({
|
|
228
444
|
model: zod.z.string(),
|
|
229
445
|
insecure: zod.z.boolean().optional(),
|
|
@@ -238,27 +454,164 @@ var ShowRequestSchema = zod.z.object({
|
|
|
238
454
|
model: zod.z.string(),
|
|
239
455
|
verbose: zod.z.boolean().optional()
|
|
240
456
|
});
|
|
457
|
+
var ThinkingSchema = zod.z.object({
|
|
458
|
+
values: zod.z.array(zod.z.union([zod.z.boolean(), zod.z.string()])),
|
|
459
|
+
default: zod.z.union([zod.z.boolean(), zod.z.string()])
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// src/generated/models/ShowResponse.schema.ts
|
|
463
|
+
var ShowResponseSchema = zod.z.object({
|
|
464
|
+
thinking: ThinkingSchema.optional(),
|
|
465
|
+
parameters: zod.z.string().optional(),
|
|
466
|
+
license: zod.z.string().optional(),
|
|
467
|
+
modified_at: zod.z.string().optional(),
|
|
468
|
+
details: zod.z.object({}).optional(),
|
|
469
|
+
template: zod.z.string().optional(),
|
|
470
|
+
capabilities: zod.z.array(zod.z.string()).optional(),
|
|
471
|
+
model_info: zod.z.object({}).optional()
|
|
472
|
+
});
|
|
473
|
+
var StatusResponseSchema = zod.z.object({
|
|
474
|
+
status: zod.z.string().optional()
|
|
475
|
+
});
|
|
476
|
+
var SystemOneContentSchema = zod.z.union([
|
|
477
|
+
zod.z.string().regex(new RegExp("\\S")),
|
|
478
|
+
zod.z.object({}).catchall(zod.z.unknown()),
|
|
479
|
+
zod.z.array(zod.z.unknown())
|
|
480
|
+
]);
|
|
481
|
+
|
|
482
|
+
// src/generated/models/SystemOneChoiceQuestion.schema.ts
|
|
483
|
+
var SystemOneChoiceQuestionSchema = zod.z.object({
|
|
484
|
+
type: zod.z.enum(["choice"]),
|
|
485
|
+
instructions: SystemOneContentSchema,
|
|
486
|
+
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)), {
|
|
487
|
+
message: 'property names must match pattern "\\S"'
|
|
488
|
+
})
|
|
489
|
+
});
|
|
490
|
+
var SystemOneNoulQuestionSchema = zod.z.object({
|
|
491
|
+
type: zod.z.enum(["noul"]),
|
|
492
|
+
instructions: SystemOneContentSchema,
|
|
493
|
+
criteria: zod.z.object({
|
|
494
|
+
false: zod.z.string().optional(),
|
|
495
|
+
true: zod.z.string().optional()
|
|
496
|
+
}).optional()
|
|
497
|
+
});
|
|
498
|
+
var SystemOneScoreQuestionSchema = zod.z.object({
|
|
499
|
+
type: zod.z.enum(["score"]),
|
|
500
|
+
instructions: SystemOneContentSchema,
|
|
501
|
+
criteria: zod.z.array(zod.z.string()).min(2).max(26)
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// src/generated/models/SystemOneRequest.schema.ts
|
|
505
|
+
var SystemOneRequestSchema = zod.z.object({
|
|
506
|
+
model: zod.z.string().regex(new RegExp("\\S")),
|
|
507
|
+
state: SystemOneContentSchema,
|
|
508
|
+
images: zod.z.array(zod.z.string()).optional(),
|
|
509
|
+
questions: zod.z.object({}).catchall(
|
|
510
|
+
zod.z.union([
|
|
511
|
+
SystemOneChoiceQuestionSchema,
|
|
512
|
+
SystemOneNoulQuestionSchema,
|
|
513
|
+
SystemOneScoreQuestionSchema
|
|
514
|
+
])
|
|
515
|
+
).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)), {
|
|
516
|
+
message: 'property names must match pattern "\\S"'
|
|
517
|
+
}),
|
|
518
|
+
keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional()
|
|
519
|
+
});
|
|
520
|
+
var SystemOneConfidenceSchema = zod.z.number().min(0).max(1);
|
|
521
|
+
var SystemOneProbabilitiesSchema = zod.z.object({}).catchall(zod.z.number().min(0).max(1));
|
|
522
|
+
|
|
523
|
+
// src/generated/models/SystemOneChoiceAnswer.schema.ts
|
|
524
|
+
var SystemOneChoiceAnswerSchema = zod.z.object({
|
|
525
|
+
type: zod.z.enum(["choice"]),
|
|
526
|
+
choice: zod.z.string(),
|
|
527
|
+
probabilities: SystemOneProbabilitiesSchema,
|
|
528
|
+
confidence: SystemOneConfidenceSchema
|
|
529
|
+
});
|
|
530
|
+
var SystemOneNoulAnswerSchema = zod.z.object({
|
|
531
|
+
type: zod.z.enum(["noul"]),
|
|
532
|
+
noul: zod.z.number().min(0).max(1)
|
|
533
|
+
});
|
|
534
|
+
var SystemOneScoreAnswerSchema = zod.z.object({
|
|
535
|
+
type: zod.z.enum(["score"]),
|
|
536
|
+
score: zod.z.number().min(0).max(25),
|
|
537
|
+
legend: zod.z.object({}).catchall(zod.z.string()),
|
|
538
|
+
probabilities: SystemOneProbabilitiesSchema,
|
|
539
|
+
confidence: SystemOneConfidenceSchema
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// src/generated/models/SystemOneResponse.schema.ts
|
|
543
|
+
var SystemOneResponseSchema = zod.z.object({
|
|
544
|
+
model: zod.z.string(),
|
|
545
|
+
answers: zod.z.object({}).catchall(
|
|
546
|
+
zod.z.union([SystemOneChoiceAnswerSchema, SystemOneNoulAnswerSchema, SystemOneScoreAnswerSchema])
|
|
547
|
+
),
|
|
548
|
+
usage: zod.z.object({
|
|
549
|
+
input_tokens: zod.z.number().min(0),
|
|
550
|
+
output_tokens: zod.z.number().min(0)
|
|
551
|
+
})
|
|
552
|
+
});
|
|
553
|
+
var VersionResponseSchema = zod.z.object({
|
|
554
|
+
version: zod.z.string().optional()
|
|
555
|
+
});
|
|
556
|
+
var WebFetchRequestSchema = zod.z.object({
|
|
557
|
+
url: zod.z.string()
|
|
558
|
+
});
|
|
559
|
+
var WebFetchResponseSchema = zod.z.object({
|
|
560
|
+
title: zod.z.string().optional(),
|
|
561
|
+
content: zod.z.string().optional(),
|
|
562
|
+
links: zod.z.array(zod.z.string()).optional()
|
|
563
|
+
});
|
|
564
|
+
var WebSearchRequestSchema = zod.z.object({
|
|
565
|
+
query: zod.z.string(),
|
|
566
|
+
max_results: zod.z.number().min(1).max(10).optional()
|
|
567
|
+
});
|
|
568
|
+
var WebSearchResultSchema = zod.z.object({
|
|
569
|
+
title: zod.z.string().optional(),
|
|
570
|
+
url: zod.z.string().optional(),
|
|
571
|
+
content: zod.z.string().optional()
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// src/generated/models/WebSearchResponse.schema.ts
|
|
575
|
+
var WebSearchResponseSchema = zod.z.object({
|
|
576
|
+
results: zod.z.array(WebSearchResultSchema).optional()
|
|
577
|
+
});
|
|
241
578
|
|
|
242
579
|
// src/generated/runtime/schema-registry.ts
|
|
243
580
|
var requestSchemas = {
|
|
244
581
|
chat: ChatRequestSchema,
|
|
245
|
-
generate: GenerateRequestSchema,
|
|
246
|
-
embed: EmbedRequestSchema,
|
|
247
|
-
create: CreateRequestSchema,
|
|
248
582
|
copy: CopyRequestSchema,
|
|
583
|
+
create: CreateRequestSchema,
|
|
249
584
|
delete: DeleteRequestSchema,
|
|
585
|
+
embed: EmbedRequestSchema,
|
|
586
|
+
generate: GenerateRequestSchema,
|
|
250
587
|
pull: PullRequestSchema,
|
|
251
588
|
push: PushRequestSchema,
|
|
252
|
-
show: ShowRequestSchema
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
589
|
+
show: ShowRequestSchema,
|
|
590
|
+
systemOne: SystemOneRequestSchema,
|
|
591
|
+
webFetch: WebFetchRequestSchema,
|
|
592
|
+
webSearch: WebSearchRequestSchema
|
|
593
|
+
};
|
|
594
|
+
var responseSchemas = {
|
|
595
|
+
chat: ChatResponseSchema,
|
|
596
|
+
create: StatusResponseSchema,
|
|
597
|
+
embed: EmbedResponseSchema,
|
|
598
|
+
generate: GenerateResponseSchema,
|
|
599
|
+
ps: PsResponseSchema,
|
|
600
|
+
pull: StatusResponseSchema,
|
|
601
|
+
push: StatusResponseSchema,
|
|
602
|
+
show: ShowResponseSchema,
|
|
603
|
+
systemOne: SystemOneResponseSchema,
|
|
604
|
+
tags: ListResponseSchema,
|
|
605
|
+
version: VersionResponseSchema,
|
|
606
|
+
webFetch: WebFetchResponseSchema,
|
|
607
|
+
webSearch: WebSearchResponseSchema
|
|
258
608
|
};
|
|
259
609
|
function getRequestSchema(operationId) {
|
|
260
610
|
return requestSchemas[operationId];
|
|
261
611
|
}
|
|
612
|
+
function getResponseSchema(operationId) {
|
|
613
|
+
return responseSchemas[operationId];
|
|
614
|
+
}
|
|
262
615
|
|
|
263
616
|
// src/generated/runtime/runtime.ts
|
|
264
617
|
function compareVersions(a, b) {
|
|
@@ -271,18 +624,13 @@ function compareVersions(a, b) {
|
|
|
271
624
|
}
|
|
272
625
|
return 0;
|
|
273
626
|
}
|
|
274
|
-
function
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
}
|
|
627
|
+
async function fetchServerVersion(http) {
|
|
628
|
+
const result = await http.request({
|
|
629
|
+
path: "/api/version",
|
|
630
|
+
method: "GET"
|
|
631
|
+
});
|
|
632
|
+
if (result && typeof result.version === "string") return result.version;
|
|
633
|
+
return void 0;
|
|
286
634
|
}
|
|
287
635
|
function shouldStream(req) {
|
|
288
636
|
if (req.body && typeof req.body === "object" && "stream" in req.body) {
|
|
@@ -305,6 +653,35 @@ var OllamaRuntime = class {
|
|
|
305
653
|
this.options = options;
|
|
306
654
|
}
|
|
307
655
|
options;
|
|
656
|
+
/**
|
|
657
|
+
* Cached promise of the Ollama server version, populated lazily the first
|
|
658
|
+
* time a version-gated operation is invoked. `undefined` until then.
|
|
659
|
+
*
|
|
660
|
+
* Wave 12 (P0 #5): see {@link OllamaRuntimeOptions.enforceVersion}.
|
|
661
|
+
*/
|
|
662
|
+
serverVersionCache;
|
|
663
|
+
/**
|
|
664
|
+
* Wave 15 (P0): resolve the HTTP backend for a given operation.
|
|
665
|
+
*
|
|
666
|
+
* Operations with a declared `host` (e.g. web search/fetch at
|
|
667
|
+
* https://ollama.com) must route to a HttpClient pointed at that host,
|
|
668
|
+
* not the default one. The runtime accepts an optional `cloudHttp`
|
|
669
|
+
* backend for this purpose — if the operation declares a host and no
|
|
670
|
+
* cloud backend is configured, the runtime throws rather than silently
|
|
671
|
+
* sending the request to the wrong server.
|
|
672
|
+
*/
|
|
673
|
+
resolveHttpBackend(operation) {
|
|
674
|
+
if (operation.host) {
|
|
675
|
+
const cloudHttp = this.options.cloudHttp;
|
|
676
|
+
if (!cloudHttp) {
|
|
677
|
+
throw new OllamaGenericClientError(
|
|
678
|
+
`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.`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return cloudHttp;
|
|
682
|
+
}
|
|
683
|
+
return this.options.http;
|
|
684
|
+
}
|
|
308
685
|
/**
|
|
309
686
|
* Invoke an operation. Called by every generated API method.
|
|
310
687
|
*
|
|
@@ -313,7 +690,7 @@ var OllamaRuntime = class {
|
|
|
313
690
|
* class's overloads pick the right return type at compile time.
|
|
314
691
|
*/
|
|
315
692
|
async invoke(req) {
|
|
316
|
-
assertOperationAllowed(req.operation
|
|
693
|
+
await this.assertOperationAllowed(req.operation);
|
|
317
694
|
let body = buildBody(req);
|
|
318
695
|
if (this.options.validateRequests === true && body !== void 0) {
|
|
319
696
|
const schema = getRequestSchema(req.operation.operationId);
|
|
@@ -332,34 +709,176 @@ var OllamaRuntime = class {
|
|
|
332
709
|
body = result.data;
|
|
333
710
|
}
|
|
334
711
|
}
|
|
712
|
+
if (body !== void 0) {
|
|
713
|
+
const serialized = serializeForByteCount(body);
|
|
714
|
+
const hasImages = bodyHasImages(body);
|
|
715
|
+
const maxBytesWithImages = req.operation.constraints?.maxRequestBytesWithImages;
|
|
716
|
+
const maxBytesBase = req.operation.constraints?.maxRequestBytes;
|
|
717
|
+
const applicableLimit = hasImages && maxBytesWithImages !== void 0 ? maxBytesWithImages : maxBytesBase;
|
|
718
|
+
if (applicableLimit !== void 0 && serialized.byteLength > applicableLimit) {
|
|
719
|
+
throw new OllamaRequestTooLargeError(
|
|
720
|
+
`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)." : "."),
|
|
721
|
+
{
|
|
722
|
+
operationId: req.operation.operationId,
|
|
723
|
+
actualBytes: serialized.byteLength,
|
|
724
|
+
maxBytes: applicableLimit,
|
|
725
|
+
request: { method: req.operation.method, url: req.operation.path }
|
|
726
|
+
}
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
335
730
|
const streaming = shouldStream(req);
|
|
731
|
+
const resolvedPath = resolvePathParams(req.operation.path, req.pathParams);
|
|
732
|
+
const model = req.model ?? extractModelFromBody(body);
|
|
336
733
|
const httpReq = {
|
|
337
|
-
path:
|
|
734
|
+
path: resolvedPath,
|
|
338
735
|
method: req.operation.method,
|
|
339
736
|
...body !== void 0 ? { body } : {},
|
|
340
737
|
...req.signal !== void 0 ? { signal: req.signal } : {},
|
|
341
|
-
|
|
342
|
-
|
|
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 } : {}
|
|
738
|
+
...streaming ? { raw: true } : {},
|
|
739
|
+
...model !== void 0 ? { model } : {}
|
|
347
740
|
};
|
|
348
741
|
if (!streaming) {
|
|
349
|
-
|
|
742
|
+
const result = await this.resolveHttpBackend(req.operation).request(httpReq);
|
|
743
|
+
if (this.options.validateResponses === true) {
|
|
744
|
+
const responseSchema = getResponseSchema(req.operation.operationId);
|
|
745
|
+
if (responseSchema) {
|
|
746
|
+
const result2 = responseSchema.safeParse(result);
|
|
747
|
+
if (!result2.success) {
|
|
748
|
+
throw new OllamaResponseValidationError(
|
|
749
|
+
`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("; "),
|
|
750
|
+
{
|
|
751
|
+
operationId: req.operation.operationId,
|
|
752
|
+
issues: result2.error.issues,
|
|
753
|
+
request: { method: req.operation.method, url: req.operation.path }
|
|
754
|
+
}
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return result;
|
|
350
760
|
}
|
|
351
|
-
const response = await this.
|
|
761
|
+
const response = await this.resolveHttpBackend(req.operation).request(httpReq);
|
|
352
762
|
if (!response.body) {
|
|
353
763
|
throw new OllamaGenericClientError(
|
|
354
764
|
`Operation ${req.operation.operationId}: streaming response had no body.`
|
|
355
765
|
);
|
|
356
766
|
}
|
|
357
|
-
return
|
|
767
|
+
return parseStreamByMode(req.operation.transport.mode, response.body);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Apply environment + version guards before delegating to HttpClient.
|
|
771
|
+
*
|
|
772
|
+
* Throws {@link OllamaGenericClientError} when:
|
|
773
|
+
* - The operation is local-only and the runtime is in cloud mode.
|
|
774
|
+
* - The operation has `constraints.minOllamaVersion` and the server is older.
|
|
775
|
+
*
|
|
776
|
+
* Wave 12 (P0 #5): when `minOllamaVersion` is declared but the runtime's
|
|
777
|
+
* `serverVersion` is unknown AND `enforceVersion` is `'auto'` or
|
|
778
|
+
* `'strict'`, the runtime lazily fetches `/api/version` (cached on the
|
|
779
|
+
* runtime instance) so the constraint is actually enforced even when the
|
|
780
|
+
* caller didn't supply it. Previously the constraint was only enforced
|
|
781
|
+
* when `serverVersion` was manually supplied — meaning in practice it was
|
|
782
|
+
* almost never enforced.
|
|
783
|
+
*/
|
|
784
|
+
async assertOperationAllowed(operation) {
|
|
785
|
+
const localMode = this.options.localMode ?? true;
|
|
786
|
+
if (!localMode && !operation.environment.cloud) {
|
|
787
|
+
throw new OllamaGenericClientError(
|
|
788
|
+
`Operation ${operation.operationId} (${operation.method} ${operation.path}) is local-only and not supported in cloud mode.`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
const minVersion = operation.constraints?.minOllamaVersion;
|
|
792
|
+
if (!minVersion) return;
|
|
793
|
+
let serverVersion = this.options.serverVersion;
|
|
794
|
+
const policy = this.options.enforceVersion ?? "auto";
|
|
795
|
+
if (!serverVersion && policy !== "off") {
|
|
796
|
+
if (!this.serverVersionCache) {
|
|
797
|
+
const p = fetchServerVersion(this.options.http).catch((err) => {
|
|
798
|
+
if (policy === "strict") {
|
|
799
|
+
throw new OllamaServerVersionUnknownError(
|
|
800
|
+
`Operation ${operation.operationId} requires Ollama >= ${minVersion} but the runtime could not determine the server version (enforceVersion: 'strict').`,
|
|
801
|
+
{
|
|
802
|
+
operationId: operation.operationId,
|
|
803
|
+
minRequiredVersion: minVersion,
|
|
804
|
+
cause: err
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
return void 0;
|
|
809
|
+
});
|
|
810
|
+
this.serverVersionCache = p;
|
|
811
|
+
}
|
|
812
|
+
serverVersion = await this.serverVersionCache ?? void 0;
|
|
813
|
+
}
|
|
814
|
+
if (serverVersion && compareVersions(serverVersion, minVersion) < 0) {
|
|
815
|
+
throw new OllamaGenericClientError(
|
|
816
|
+
`Operation ${operation.operationId} (${operation.method} ${operation.path}) requires Ollama >= ${minVersion} (server reports ${serverVersion}).`
|
|
817
|
+
);
|
|
818
|
+
}
|
|
358
819
|
}
|
|
359
820
|
};
|
|
821
|
+
function parseStreamByMode(mode, body) {
|
|
822
|
+
if (mode === "ndjson") {
|
|
823
|
+
return parseNdjsonStream(body);
|
|
824
|
+
}
|
|
825
|
+
if (mode === "sse") {
|
|
826
|
+
return parseSseStreamAsJson(body);
|
|
827
|
+
}
|
|
828
|
+
throw new OllamaGenericClientError(
|
|
829
|
+
`Transport mode "${mode}" is not a streaming mode; cannot parse a stream for it.`
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
async function* parseSseStreamAsJson(body) {
|
|
833
|
+
for await (const event of parseSseStream(body)) {
|
|
834
|
+
const data = event.data;
|
|
835
|
+
if (!data) continue;
|
|
836
|
+
if (data === "[DONE]") return;
|
|
837
|
+
try {
|
|
838
|
+
yield JSON.parse(data);
|
|
839
|
+
} catch (err) {
|
|
840
|
+
throw new OllamaGenericClientError(`Failed to parse SSE event data as JSON: ${data}`, {
|
|
841
|
+
cause: err
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
function serializeForByteCount(body) {
|
|
847
|
+
if (body instanceof Uint8Array) return body;
|
|
848
|
+
if (typeof body === "string") return new TextEncoder().encode(body);
|
|
849
|
+
const json = JSON.stringify(body);
|
|
850
|
+
return new TextEncoder().encode(json);
|
|
851
|
+
}
|
|
852
|
+
function bodyHasImages(body) {
|
|
853
|
+
if (typeof body !== "object" || body === null) return false;
|
|
854
|
+
const obj = body;
|
|
855
|
+
const images = obj.images;
|
|
856
|
+
return Array.isArray(images) && images.length > 0;
|
|
857
|
+
}
|
|
858
|
+
function resolvePathParams(pathTemplate, pathParams) {
|
|
859
|
+
if (!pathTemplate.includes("{")) return pathTemplate;
|
|
860
|
+
const params = pathParams ?? {};
|
|
861
|
+
return pathTemplate.replace(/\{([^}]+)\}/g, (_match, name) => {
|
|
862
|
+
const value = params[name];
|
|
863
|
+
if (value === void 0) {
|
|
864
|
+
throw new OllamaGenericClientError(
|
|
865
|
+
`Missing path parameter "${name}" for path template "${pathTemplate}". Provide it via the pathParams field on the invoke() request.`
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
return encodeURIComponent(value);
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
function extractModelFromBody(body) {
|
|
872
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
873
|
+
const obj = body;
|
|
874
|
+
const model = obj.model;
|
|
875
|
+
return typeof model === "string" ? model : void 0;
|
|
876
|
+
}
|
|
360
877
|
|
|
361
878
|
exports.OllamaRuntime = OllamaRuntime;
|
|
362
879
|
exports.getRequestSchema = getRequestSchema;
|
|
880
|
+
exports.getResponseSchema = getResponseSchema;
|
|
363
881
|
exports.requestSchemas = requestSchemas;
|
|
882
|
+
exports.responseSchemas = responseSchemas;
|
|
364
883
|
//# sourceMappingURL=generated-runtime.cjs.map
|
|
365
884
|
//# sourceMappingURL=generated-runtime.cjs.map
|