@nemesis-oss/ollama-sdk 1.4.0 → 1.5.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 +9 -0
- package/README.md +23 -2
- package/dist/{compose-DfAqKAFj.d.ts → compose-DLStUfaF.d.ts} +2 -2
- package/dist/{compose-BR70yb4W.d.cts → compose-DS-UWFx8.d.cts} +2 -2
- package/dist/generated-api.cjs +54 -11
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +4 -3
- package/dist/generated-api.d.ts +4 -3
- package/dist/generated-api.js +54 -11
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +192 -192
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.js +192 -192
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +229 -9
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +35 -2
- package/dist/generated-runtime.d.ts +35 -2
- package/dist/generated-runtime.js +228 -10
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +403 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +403 -146
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +19 -70
- package/dist/mcp-generated.cjs +54 -11
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.d.cts +4 -3
- package/dist/mcp-generated.d.ts +4 -3
- package/dist/mcp-generated.js +54 -11
- package/dist/mcp-generated.js.map +1 -1
- package/dist/mcp-http.d.cts +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-stdio.d.cts +1 -1
- package/dist/mcp-stdio.d.ts +1 -1
- package/dist/{index-DIQ8NUbU.d.ts → runtime-CVQkbYgF.d.ts} +40 -2
- package/dist/{index-2RIErNT5.d.cts → runtime-IxRpUBjN.d.cts} +40 -2
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -3
- package/dist/skills.d.ts +3 -3
- package/dist/skills.js.map +1 -1
- package/dist/{types-BQhgW-du.d.cts → types-5PAjLoCp.d.cts} +1 -1
- package/dist/{types-BQhgW-du.d.ts → types-5PAjLoCp.d.ts} +1 -1
- package/dist/{types-B9_axjum.d.cts → types-MOsWXEE7.d.cts} +1 -1
- package/dist/{types-B9_axjum.d.ts → types-MOsWXEE7.d.ts} +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __using = (stack, value, async) => {
|
|
10
|
+
if (value != null) {
|
|
11
|
+
if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
|
|
12
|
+
var dispose, inner;
|
|
13
|
+
if (async) dispose = value[__knownSymbol("asyncDispose")];
|
|
14
|
+
if (dispose === void 0) {
|
|
15
|
+
dispose = value[__knownSymbol("dispose")];
|
|
16
|
+
if (async) inner = dispose;
|
|
17
|
+
}
|
|
18
|
+
if (typeof dispose !== "function") __typeError("Object not disposable");
|
|
19
|
+
if (inner) dispose = function() {
|
|
20
|
+
try {
|
|
21
|
+
inner.call(this);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return Promise.reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
stack.push([async, dispose, value]);
|
|
27
|
+
} else if (async) {
|
|
28
|
+
stack.push([async]);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
var __callDispose = (stack, error, hasError) => {
|
|
33
|
+
var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
|
|
34
|
+
return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
|
|
35
|
+
};
|
|
36
|
+
var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
|
|
37
|
+
var next = (it) => {
|
|
38
|
+
while (it = stack.pop()) {
|
|
39
|
+
try {
|
|
40
|
+
var result = it[1] && it[1].call(it[2]);
|
|
41
|
+
if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
fail(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (hasError) throw error;
|
|
47
|
+
};
|
|
48
|
+
return next();
|
|
49
|
+
};
|
|
50
|
+
|
|
5
51
|
// src/config.ts
|
|
6
52
|
var DEFAULT_BASE_URL = "http://localhost:11434";
|
|
7
53
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
@@ -129,6 +175,15 @@ var OllamaToolValidationError = class extends OllamaClientError {
|
|
|
129
175
|
this.issues = options.issues;
|
|
130
176
|
}
|
|
131
177
|
};
|
|
178
|
+
var OllamaRequestValidationError = class extends OllamaClientError {
|
|
179
|
+
operationId;
|
|
180
|
+
issues;
|
|
181
|
+
constructor(message, options) {
|
|
182
|
+
super(message, { ...options, code: "request_validation_error", retryable: false });
|
|
183
|
+
this.operationId = options.operationId;
|
|
184
|
+
this.issues = options.issues;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
132
187
|
var OllamaToolTimeoutError = class extends OllamaClientError {
|
|
133
188
|
toolName;
|
|
134
189
|
timeoutMs;
|
|
@@ -494,12 +549,65 @@ function composeMiddleware(middlewares, finalHandler) {
|
|
|
494
549
|
};
|
|
495
550
|
}
|
|
496
551
|
|
|
552
|
+
// src/utils.ts
|
|
553
|
+
async function encodeImage(image) {
|
|
554
|
+
if (typeof image === "string") return image;
|
|
555
|
+
const bufferCtor = globalThis.Buffer;
|
|
556
|
+
if (bufferCtor !== void 0) return bufferCtor.from(image).toString("base64");
|
|
557
|
+
const CHUNK_SIZE = 32768;
|
|
558
|
+
let binary = "";
|
|
559
|
+
for (let i = 0; i < image.length; i += CHUNK_SIZE) {
|
|
560
|
+
binary += String.fromCharCode(...image.subarray(i, i + CHUNK_SIZE));
|
|
561
|
+
}
|
|
562
|
+
return btoa(binary);
|
|
563
|
+
}
|
|
564
|
+
async function encodeImages(images) {
|
|
565
|
+
if (images === void 0) return void 0;
|
|
566
|
+
return Promise.all(images.map((image) => encodeImage(image)));
|
|
567
|
+
}
|
|
568
|
+
async function withEncodedImages(req) {
|
|
569
|
+
if (!req.images?.some((image) => image instanceof Uint8Array)) return req;
|
|
570
|
+
return { ...req, images: await encodeImages(req.images) };
|
|
571
|
+
}
|
|
572
|
+
async function withEncodedMessageImages(messages) {
|
|
573
|
+
if (!messages.some((message) => message.images?.some((image) => image instanceof Uint8Array)))
|
|
574
|
+
return messages;
|
|
575
|
+
return Promise.all(messages.map((message) => withEncodedImages(message)));
|
|
576
|
+
}
|
|
577
|
+
function disposableTimer(timer) {
|
|
578
|
+
return {
|
|
579
|
+
[Symbol.dispose]() {
|
|
580
|
+
clearTimeout(timer);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function disposableReader(reader) {
|
|
585
|
+
return {
|
|
586
|
+
async [Symbol.asyncDispose]() {
|
|
587
|
+
try {
|
|
588
|
+
await reader.cancel();
|
|
589
|
+
} catch {
|
|
590
|
+
}
|
|
591
|
+
reader.releaseLock();
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function disposableSpan(span) {
|
|
596
|
+
return {
|
|
597
|
+
[Symbol.dispose]() {
|
|
598
|
+
span.end();
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
497
603
|
// src/streaming/ndjson.ts
|
|
498
604
|
async function* parseNdjsonStream(stream) {
|
|
499
|
-
|
|
500
|
-
const decoder = new TextDecoder();
|
|
501
|
-
let buffer = "";
|
|
605
|
+
var _stack = [];
|
|
502
606
|
try {
|
|
607
|
+
const reader = stream.getReader();
|
|
608
|
+
const decoder = new TextDecoder();
|
|
609
|
+
let buffer = "";
|
|
610
|
+
const _reader = __using(_stack, disposableReader(reader), true);
|
|
503
611
|
while (true) {
|
|
504
612
|
const { done, value } = await reader.read();
|
|
505
613
|
if (done) break;
|
|
@@ -521,12 +629,11 @@ async function* parseNdjsonStream(stream) {
|
|
|
521
629
|
if (buffer.trim()) {
|
|
522
630
|
yield JSON.parse(buffer.trim());
|
|
523
631
|
}
|
|
632
|
+
} catch (_) {
|
|
633
|
+
var _error = _, _hasError = true;
|
|
524
634
|
} finally {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
} catch {
|
|
528
|
-
}
|
|
529
|
-
reader.releaseLock();
|
|
635
|
+
var _promise = __callDispose(_stack, _error, _hasError);
|
|
636
|
+
_promise && await _promise;
|
|
530
637
|
}
|
|
531
638
|
}
|
|
532
639
|
|
|
@@ -542,47 +649,51 @@ function dispatch(event, data, id, retry) {
|
|
|
542
649
|
};
|
|
543
650
|
}
|
|
544
651
|
async function* parseSseStream(stream) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (
|
|
652
|
+
var _stack = [];
|
|
653
|
+
try {
|
|
654
|
+
const reader = stream.getReader();
|
|
655
|
+
const decoder = new TextDecoder();
|
|
656
|
+
let buffer = "";
|
|
657
|
+
let eventType;
|
|
658
|
+
let data = [];
|
|
659
|
+
let lastEventId;
|
|
660
|
+
let retry;
|
|
661
|
+
const processLine = (line) => {
|
|
662
|
+
if (line.length === 0) {
|
|
663
|
+
const event = dispatch(eventType, data, lastEventId, retry);
|
|
664
|
+
eventType = void 0;
|
|
665
|
+
data = [];
|
|
666
|
+
retry = void 0;
|
|
667
|
+
return event;
|
|
668
|
+
}
|
|
669
|
+
if (line.startsWith(":")) return void 0;
|
|
670
|
+
const separator = line.indexOf(":");
|
|
671
|
+
const field = separator === -1 ? line : line.slice(0, separator);
|
|
672
|
+
let value = separator === -1 ? "" : line.slice(separator + 1);
|
|
673
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
674
|
+
switch (field) {
|
|
675
|
+
case "event":
|
|
676
|
+
eventType = value;
|
|
677
|
+
break;
|
|
678
|
+
case "data":
|
|
679
|
+
data.push(value);
|
|
680
|
+
break;
|
|
681
|
+
case "id":
|
|
682
|
+
if (!value.includes("\0")) lastEventId = value;
|
|
683
|
+
break;
|
|
684
|
+
case "retry": {
|
|
685
|
+
if (/^\d+$/.test(value)) {
|
|
686
|
+
const parsed = Number(value);
|
|
687
|
+
if (Number.isSafeInteger(parsed)) retry = parsed;
|
|
688
|
+
}
|
|
689
|
+
break;
|
|
579
690
|
}
|
|
580
|
-
|
|
691
|
+
default:
|
|
692
|
+
break;
|
|
581
693
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
try {
|
|
694
|
+
return void 0;
|
|
695
|
+
};
|
|
696
|
+
const _reader = __using(_stack, disposableReader(reader), true);
|
|
586
697
|
while (true) {
|
|
587
698
|
const { done, value } = await reader.read();
|
|
588
699
|
if (done) break;
|
|
@@ -610,12 +721,11 @@ async function* parseSseStream(stream) {
|
|
|
610
721
|
}
|
|
611
722
|
const terminal = dispatch(eventType, data, lastEventId, retry);
|
|
612
723
|
if (terminal) yield terminal;
|
|
724
|
+
} catch (_) {
|
|
725
|
+
var _error = _, _hasError = true;
|
|
613
726
|
} finally {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
} catch {
|
|
617
|
-
}
|
|
618
|
-
reader.releaseLock();
|
|
727
|
+
var _promise = __callDispose(_stack, _error, _hasError);
|
|
728
|
+
_promise && await _promise;
|
|
619
729
|
}
|
|
620
730
|
}
|
|
621
731
|
|
|
@@ -643,16 +753,22 @@ async function withSpan(name, attributes, fn) {
|
|
|
643
753
|
}
|
|
644
754
|
const tracer = api.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
645
755
|
return tracer.startActiveSpan(name, async (span) => {
|
|
646
|
-
|
|
756
|
+
var _stack = [];
|
|
647
757
|
try {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
758
|
+
span.setAttributes(cleanAttributes(attributes));
|
|
759
|
+
const _span = __using(_stack, disposableSpan(span));
|
|
760
|
+
try {
|
|
761
|
+
return await fn(span);
|
|
762
|
+
} catch (err) {
|
|
763
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
764
|
+
span.recordException(error);
|
|
765
|
+
span.setStatus({ code: api.SpanStatusCode.ERROR, message: error.message });
|
|
766
|
+
throw error;
|
|
767
|
+
}
|
|
768
|
+
} catch (_) {
|
|
769
|
+
var _error = _, _hasError = true;
|
|
654
770
|
} finally {
|
|
655
|
-
|
|
771
|
+
__callDispose(_stack, _error, _hasError);
|
|
656
772
|
}
|
|
657
773
|
});
|
|
658
774
|
}
|
|
@@ -1062,42 +1178,48 @@ var HttpClient = class {
|
|
|
1062
1178
|
|
|
1063
1179
|
// src/providers/health-check.ts
|
|
1064
1180
|
async function checkEndpointHealth(endpoint, fetchImpl, timeoutMs = 5e3, middleware, onLifecycleEvent) {
|
|
1065
|
-
|
|
1066
|
-
baseUrl: endpoint.baseUrl,
|
|
1067
|
-
apiKey: endpoint.apiKey,
|
|
1068
|
-
headers: endpoint.headers,
|
|
1069
|
-
fetch: fetchImpl,
|
|
1070
|
-
middleware,
|
|
1071
|
-
onLifecycleEvent
|
|
1072
|
-
});
|
|
1073
|
-
const startTime = Date.now();
|
|
1074
|
-
const controller = new AbortController();
|
|
1075
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1181
|
+
var _stack = [];
|
|
1076
1182
|
try {
|
|
1077
|
-
const
|
|
1078
|
-
path: "/api/version",
|
|
1079
|
-
method: "GET",
|
|
1080
|
-
signal: controller.signal
|
|
1081
|
-
});
|
|
1082
|
-
const latencyMs = Date.now() - startTime;
|
|
1083
|
-
return {
|
|
1084
|
-
name: endpoint.name,
|
|
1183
|
+
const client = new HttpClient({
|
|
1085
1184
|
baseUrl: endpoint.baseUrl,
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1185
|
+
apiKey: endpoint.apiKey,
|
|
1186
|
+
headers: endpoint.headers,
|
|
1187
|
+
fetch: fetchImpl,
|
|
1188
|
+
middleware,
|
|
1189
|
+
onLifecycleEvent
|
|
1190
|
+
});
|
|
1191
|
+
const startTime = Date.now();
|
|
1192
|
+
const controller = new AbortController();
|
|
1193
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1194
|
+
const _timer = __using(_stack, disposableTimer(timer));
|
|
1195
|
+
try {
|
|
1196
|
+
const res = await client.request({
|
|
1197
|
+
path: "/api/version",
|
|
1198
|
+
method: "GET",
|
|
1199
|
+
signal: controller.signal
|
|
1200
|
+
});
|
|
1201
|
+
const latencyMs = Date.now() - startTime;
|
|
1202
|
+
return {
|
|
1203
|
+
name: endpoint.name,
|
|
1204
|
+
baseUrl: endpoint.baseUrl,
|
|
1205
|
+
reachable: true,
|
|
1206
|
+
latencyMs,
|
|
1207
|
+
version: res.version
|
|
1208
|
+
};
|
|
1209
|
+
} catch (err) {
|
|
1210
|
+
const latencyMs = Date.now() - startTime;
|
|
1211
|
+
return {
|
|
1212
|
+
name: endpoint.name,
|
|
1213
|
+
baseUrl: endpoint.baseUrl,
|
|
1214
|
+
reachable: false,
|
|
1215
|
+
latencyMs,
|
|
1216
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
} catch (_) {
|
|
1220
|
+
var _error = _, _hasError = true;
|
|
1099
1221
|
} finally {
|
|
1100
|
-
|
|
1222
|
+
__callDispose(_stack, _error, _hasError);
|
|
1101
1223
|
}
|
|
1102
1224
|
}
|
|
1103
1225
|
|
|
@@ -2626,6 +2748,136 @@ var AnthropicCompatClient = class {
|
|
|
2626
2748
|
return this.createMessage(request, signal);
|
|
2627
2749
|
}
|
|
2628
2750
|
};
|
|
2751
|
+
var ToolCallSchema = zod.z.object({
|
|
2752
|
+
function: zod.z.object({
|
|
2753
|
+
name: zod.z.string(),
|
|
2754
|
+
description: zod.z.string().optional(),
|
|
2755
|
+
arguments: zod.z.object({}).optional()
|
|
2756
|
+
}).optional()
|
|
2757
|
+
});
|
|
2758
|
+
|
|
2759
|
+
// src/generated/models/ChatMessage.schema.ts
|
|
2760
|
+
var ChatMessageSchema = zod.z.object({
|
|
2761
|
+
role: zod.z.enum(["system", "user", "assistant", "tool"]),
|
|
2762
|
+
content: zod.z.string(),
|
|
2763
|
+
images: zod.z.array(zod.z.string()).optional(),
|
|
2764
|
+
tool_calls: zod.z.array(ToolCallSchema).optional()
|
|
2765
|
+
});
|
|
2766
|
+
var ModelOptionsSchema = zod.z.object({
|
|
2767
|
+
seed: zod.z.number().optional(),
|
|
2768
|
+
temperature: zod.z.number().optional(),
|
|
2769
|
+
top_k: zod.z.number().optional(),
|
|
2770
|
+
top_p: zod.z.number().optional(),
|
|
2771
|
+
min_p: zod.z.number().optional(),
|
|
2772
|
+
stop: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional(),
|
|
2773
|
+
num_ctx: zod.z.number().optional(),
|
|
2774
|
+
num_predict: zod.z.number().optional()
|
|
2775
|
+
}).catchall(zod.z.unknown());
|
|
2776
|
+
var ThinkValueSchema = zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.null()]);
|
|
2777
|
+
var ToolDefinitionSchema = zod.z.object({
|
|
2778
|
+
type: zod.z.enum(["function"]),
|
|
2779
|
+
function: zod.z.object({
|
|
2780
|
+
name: zod.z.string(),
|
|
2781
|
+
description: zod.z.string().optional(),
|
|
2782
|
+
parameters: zod.z.object({})
|
|
2783
|
+
})
|
|
2784
|
+
});
|
|
2785
|
+
|
|
2786
|
+
// src/generated/models/ChatRequest.schema.ts
|
|
2787
|
+
var ChatRequestSchema = zod.z.object({
|
|
2788
|
+
model: zod.z.string(),
|
|
2789
|
+
messages: zod.z.array(ChatMessageSchema),
|
|
2790
|
+
tools: zod.z.array(ToolDefinitionSchema).optional(),
|
|
2791
|
+
format: zod.z.union([zod.z.enum(["json"]), zod.z.object({})]).optional(),
|
|
2792
|
+
options: ModelOptionsSchema.optional(),
|
|
2793
|
+
stream: zod.z.boolean().optional(),
|
|
2794
|
+
think: ThinkValueSchema.optional(),
|
|
2795
|
+
keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
|
|
2796
|
+
logprobs: zod.z.boolean().optional(),
|
|
2797
|
+
top_logprobs: zod.z.number().optional()
|
|
2798
|
+
});
|
|
2799
|
+
var GenerateRequestSchema = zod.z.object({
|
|
2800
|
+
model: zod.z.string(),
|
|
2801
|
+
prompt: zod.z.string().optional(),
|
|
2802
|
+
suffix: zod.z.string().optional(),
|
|
2803
|
+
images: zod.z.array(zod.z.string()).optional(),
|
|
2804
|
+
format: zod.z.union([zod.z.string(), zod.z.object({})]).optional(),
|
|
2805
|
+
system: zod.z.string().optional(),
|
|
2806
|
+
stream: zod.z.boolean().optional(),
|
|
2807
|
+
think: ThinkValueSchema.optional(),
|
|
2808
|
+
raw: zod.z.boolean().optional(),
|
|
2809
|
+
keep_alive: zod.z.union([zod.z.string(), zod.z.number()]).optional(),
|
|
2810
|
+
options: ModelOptionsSchema.optional(),
|
|
2811
|
+
logprobs: zod.z.boolean().optional(),
|
|
2812
|
+
top_logprobs: zod.z.number().optional()
|
|
2813
|
+
});
|
|
2814
|
+
var EmbedRequestSchema = zod.z.object({
|
|
2815
|
+
model: zod.z.string(),
|
|
2816
|
+
input: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2817
|
+
truncate: zod.z.boolean().optional(),
|
|
2818
|
+
dimensions: zod.z.number().optional(),
|
|
2819
|
+
keep_alive: zod.z.string().optional(),
|
|
2820
|
+
options: ModelOptionsSchema.optional()
|
|
2821
|
+
});
|
|
2822
|
+
var CreateRequestSchema = zod.z.object({
|
|
2823
|
+
model: zod.z.string(),
|
|
2824
|
+
from: zod.z.string().optional(),
|
|
2825
|
+
template: zod.z.string().optional(),
|
|
2826
|
+
renderer: zod.z.string().optional(),
|
|
2827
|
+
parser: zod.z.string().optional(),
|
|
2828
|
+
files: zod.z.object({}).catchall(zod.z.string()).optional(),
|
|
2829
|
+
draft_files: zod.z.object({}).catchall(zod.z.string()).optional(),
|
|
2830
|
+
license: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional(),
|
|
2831
|
+
system: zod.z.string().optional(),
|
|
2832
|
+
parameters: zod.z.object({}).optional(),
|
|
2833
|
+
messages: zod.z.array(ChatMessageSchema).optional(),
|
|
2834
|
+
quantize: zod.z.string().optional(),
|
|
2835
|
+
draft_quantize: zod.z.string().optional(),
|
|
2836
|
+
requires: zod.z.string().optional(),
|
|
2837
|
+
stream: zod.z.boolean().optional()
|
|
2838
|
+
});
|
|
2839
|
+
var CopyRequestSchema = zod.z.object({
|
|
2840
|
+
source: zod.z.string(),
|
|
2841
|
+
destination: zod.z.string()
|
|
2842
|
+
});
|
|
2843
|
+
var DeleteRequestSchema = zod.z.object({
|
|
2844
|
+
model: zod.z.string()
|
|
2845
|
+
});
|
|
2846
|
+
var PullRequestSchema = zod.z.object({
|
|
2847
|
+
model: zod.z.string(),
|
|
2848
|
+
insecure: zod.z.boolean().optional(),
|
|
2849
|
+
stream: zod.z.boolean().optional()
|
|
2850
|
+
});
|
|
2851
|
+
var PushRequestSchema = zod.z.object({
|
|
2852
|
+
model: zod.z.string(),
|
|
2853
|
+
insecure: zod.z.boolean().optional(),
|
|
2854
|
+
stream: zod.z.boolean().optional()
|
|
2855
|
+
});
|
|
2856
|
+
var ShowRequestSchema = zod.z.object({
|
|
2857
|
+
model: zod.z.string(),
|
|
2858
|
+
verbose: zod.z.boolean().optional()
|
|
2859
|
+
});
|
|
2860
|
+
|
|
2861
|
+
// src/generated/runtime/schema-registry.ts
|
|
2862
|
+
var requestSchemas = {
|
|
2863
|
+
chat: ChatRequestSchema,
|
|
2864
|
+
generate: GenerateRequestSchema,
|
|
2865
|
+
embed: EmbedRequestSchema,
|
|
2866
|
+
create: CreateRequestSchema,
|
|
2867
|
+
copy: CopyRequestSchema,
|
|
2868
|
+
delete: DeleteRequestSchema,
|
|
2869
|
+
pull: PullRequestSchema,
|
|
2870
|
+
push: PushRequestSchema,
|
|
2871
|
+
show: ShowRequestSchema
|
|
2872
|
+
// Operations without a registered request schema (blobs, ps, tags,
|
|
2873
|
+
// version, systemOne, openai*, anthropic*) skip validation. This is
|
|
2874
|
+
// deliberate — the OpenAPI spec doesn't define request bodies for
|
|
2875
|
+
// GET/HEAD operations, and the compat-surface request schemas (OpenAI,
|
|
2876
|
+
// Anthropic) are richer than what the IR currently models.
|
|
2877
|
+
};
|
|
2878
|
+
function getRequestSchema(operationId) {
|
|
2879
|
+
return requestSchemas[operationId];
|
|
2880
|
+
}
|
|
2629
2881
|
|
|
2630
2882
|
// src/generated/runtime/runtime.ts
|
|
2631
2883
|
function compareVersions(a, b) {
|
|
@@ -2681,7 +2933,24 @@ var OllamaRuntime = class {
|
|
|
2681
2933
|
*/
|
|
2682
2934
|
async invoke(req) {
|
|
2683
2935
|
assertOperationAllowed(req.operation, this.options);
|
|
2684
|
-
|
|
2936
|
+
let body = buildBody(req);
|
|
2937
|
+
if (this.options.validateRequests === true && body !== void 0) {
|
|
2938
|
+
const schema = getRequestSchema(req.operation.operationId);
|
|
2939
|
+
if (schema) {
|
|
2940
|
+
const result = schema.safeParse(body);
|
|
2941
|
+
if (!result.success) {
|
|
2942
|
+
throw new OllamaRequestValidationError(
|
|
2943
|
+
`Request validation failed for operation "${req.operation.operationId}" (${req.operation.method} ${req.operation.path}): ` + result.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; "),
|
|
2944
|
+
{
|
|
2945
|
+
operationId: req.operation.operationId,
|
|
2946
|
+
issues: result.error.issues,
|
|
2947
|
+
request: { method: req.operation.method, url: req.operation.path }
|
|
2948
|
+
}
|
|
2949
|
+
);
|
|
2950
|
+
}
|
|
2951
|
+
body = result.data;
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2685
2954
|
const streaming = shouldStream(req);
|
|
2686
2955
|
const httpReq = {
|
|
2687
2956
|
path: req.operation.path,
|
|
@@ -2708,32 +2977,6 @@ var OllamaRuntime = class {
|
|
|
2708
2977
|
}
|
|
2709
2978
|
};
|
|
2710
2979
|
|
|
2711
|
-
// src/utils.ts
|
|
2712
|
-
async function encodeImage(image) {
|
|
2713
|
-
if (typeof image === "string") return image;
|
|
2714
|
-
const bufferCtor = globalThis.Buffer;
|
|
2715
|
-
if (bufferCtor !== void 0) return bufferCtor.from(image).toString("base64");
|
|
2716
|
-
const CHUNK_SIZE = 32768;
|
|
2717
|
-
let binary = "";
|
|
2718
|
-
for (let i = 0; i < image.length; i += CHUNK_SIZE) {
|
|
2719
|
-
binary += String.fromCharCode(...image.subarray(i, i + CHUNK_SIZE));
|
|
2720
|
-
}
|
|
2721
|
-
return btoa(binary);
|
|
2722
|
-
}
|
|
2723
|
-
async function encodeImages(images) {
|
|
2724
|
-
if (images === void 0) return void 0;
|
|
2725
|
-
return Promise.all(images.map((image) => encodeImage(image)));
|
|
2726
|
-
}
|
|
2727
|
-
async function withEncodedImages(req) {
|
|
2728
|
-
if (!req.images?.some((image) => image instanceof Uint8Array)) return req;
|
|
2729
|
-
return { ...req, images: await encodeImages(req.images) };
|
|
2730
|
-
}
|
|
2731
|
-
async function withEncodedMessageImages(messages) {
|
|
2732
|
-
if (!messages.some((message) => message.images?.some((image) => image instanceof Uint8Array)))
|
|
2733
|
-
return messages;
|
|
2734
|
-
return Promise.all(messages.map((message) => withEncodedImages(message)));
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
2980
|
// src/client.ts
|
|
2738
2981
|
var logicalRequestSequence = 0;
|
|
2739
2982
|
function createLogicalRequestId() {
|
|
@@ -3140,9 +3383,15 @@ var OllamaClient = class {
|
|
|
3140
3383
|
* multi-candidate loop, since `webSearch`/`webFetch` only ever have the one endpoint.
|
|
3141
3384
|
*/
|
|
3142
3385
|
async executeCloudRequest(operation, options) {
|
|
3143
|
-
|
|
3144
|
-
const requestId = createLogicalRequestId();
|
|
3386
|
+
var _stack = [];
|
|
3145
3387
|
try {
|
|
3388
|
+
const timeout = createTimeoutSignal(options.timeoutMs ?? this.timeoutMs, options.signal);
|
|
3389
|
+
const _timeout = __using(_stack, {
|
|
3390
|
+
[Symbol.dispose]() {
|
|
3391
|
+
timeout.cancel();
|
|
3392
|
+
}
|
|
3393
|
+
});
|
|
3394
|
+
const requestId = createLogicalRequestId();
|
|
3146
3395
|
const http = new HttpClient({
|
|
3147
3396
|
baseUrl: OLLAMA_CLOUD_BASE_URL,
|
|
3148
3397
|
apiKey: this.cloudApiKey,
|
|
@@ -3169,8 +3418,10 @@ var OllamaClient = class {
|
|
|
3169
3418
|
},
|
|
3170
3419
|
timeout.signal
|
|
3171
3420
|
);
|
|
3421
|
+
} catch (_) {
|
|
3422
|
+
var _error = _, _hasError = true;
|
|
3172
3423
|
} finally {
|
|
3173
|
-
|
|
3424
|
+
__callDispose(_stack, _error, _hasError);
|
|
3174
3425
|
}
|
|
3175
3426
|
}
|
|
3176
3427
|
// --- Capabilities & Health ---
|
|
@@ -3531,25 +3782,32 @@ var ToolRegistry = class {
|
|
|
3531
3782
|
return results;
|
|
3532
3783
|
}
|
|
3533
3784
|
async runWithTimeout(tool, params, ctx, toolName) {
|
|
3534
|
-
|
|
3535
|
-
if (!timeoutMs || timeoutMs <= 0) {
|
|
3536
|
-
return tool.execute(params, ctx);
|
|
3537
|
-
}
|
|
3538
|
-
const controller = new AbortController();
|
|
3539
|
-
const onParentAbort = () => controller.abort(ctx.signal?.reason);
|
|
3540
|
-
if (ctx.signal) {
|
|
3541
|
-
if (ctx.signal.aborted) {
|
|
3542
|
-
controller.abort(ctx.signal.reason);
|
|
3543
|
-
} else {
|
|
3544
|
-
ctx.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
3545
|
-
}
|
|
3546
|
-
}
|
|
3547
|
-
let timedOut = false;
|
|
3548
|
-
const timer = setTimeout(() => {
|
|
3549
|
-
timedOut = true;
|
|
3550
|
-
controller.abort();
|
|
3551
|
-
}, timeoutMs);
|
|
3785
|
+
var _stack = [];
|
|
3552
3786
|
try {
|
|
3787
|
+
const timeoutMs = tool.timeoutMs ?? this.defaultTimeoutMs;
|
|
3788
|
+
if (!timeoutMs || timeoutMs <= 0) {
|
|
3789
|
+
return tool.execute(params, ctx);
|
|
3790
|
+
}
|
|
3791
|
+
const controller = new AbortController();
|
|
3792
|
+
const onParentAbort = () => controller.abort(ctx.signal?.reason);
|
|
3793
|
+
if (ctx.signal) {
|
|
3794
|
+
if (ctx.signal.aborted) {
|
|
3795
|
+
controller.abort(ctx.signal.reason);
|
|
3796
|
+
} else {
|
|
3797
|
+
ctx.signal.addEventListener("abort", onParentAbort, { once: true });
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
let timedOut = false;
|
|
3801
|
+
const timer = setTimeout(() => {
|
|
3802
|
+
timedOut = true;
|
|
3803
|
+
controller.abort();
|
|
3804
|
+
}, timeoutMs);
|
|
3805
|
+
const _timer = __using(_stack, disposableTimer(timer));
|
|
3806
|
+
const _listener = __using(_stack, {
|
|
3807
|
+
[Symbol.dispose]() {
|
|
3808
|
+
ctx.signal?.removeEventListener("abort", onParentAbort);
|
|
3809
|
+
}
|
|
3810
|
+
});
|
|
3553
3811
|
const executePromise = Promise.resolve(
|
|
3554
3812
|
tool.execute(params, { ...ctx, signal: controller.signal })
|
|
3555
3813
|
);
|
|
@@ -3566,11 +3824,10 @@ var ToolRegistry = class {
|
|
|
3566
3824
|
});
|
|
3567
3825
|
})
|
|
3568
3826
|
]);
|
|
3827
|
+
} catch (_) {
|
|
3828
|
+
var _error = _, _hasError = true;
|
|
3569
3829
|
} finally {
|
|
3570
|
-
|
|
3571
|
-
if (ctx.signal) {
|
|
3572
|
-
ctx.signal.removeEventListener("abort", onParentAbort);
|
|
3573
|
-
}
|
|
3830
|
+
__callDispose(_stack, _error, _hasError);
|
|
3574
3831
|
}
|
|
3575
3832
|
}
|
|
3576
3833
|
truncateOutput(output) {
|
|
@@ -4163,6 +4420,7 @@ exports.OllamaNetworkError = OllamaNetworkError;
|
|
|
4163
4420
|
exports.OllamaNotFoundError = OllamaNotFoundError;
|
|
4164
4421
|
exports.OllamaQuotaExceededError = OllamaQuotaExceededError;
|
|
4165
4422
|
exports.OllamaRateLimitError = OllamaRateLimitError;
|
|
4423
|
+
exports.OllamaRequestValidationError = OllamaRequestValidationError;
|
|
4166
4424
|
exports.OllamaServerError = OllamaServerError;
|
|
4167
4425
|
exports.OllamaSkillInvalidError = OllamaSkillInvalidError;
|
|
4168
4426
|
exports.OllamaSkillNotFoundError = OllamaSkillNotFoundError;
|