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