@nemesis-oss/ollama-sdk 1.15.0 → 1.17.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 +50 -0
- package/README.md +114 -2
- package/dist/{anthropic-DrDUfbfQ.d.ts → anthropic-AKbXnWJU.d.cts} +1 -1
- package/dist/{anthropic-UeaVjLeP.d.cts → anthropic-CTv2acbj.d.ts} +1 -1
- package/dist/generated-api.d.cts +4 -4
- package/dist/generated-api.d.ts +4 -4
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +1 -1
- package/dist/generated-runtime.d.ts +1 -1
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +207 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +200 -13
- package/dist/index.d.ts +200 -13
- package/dist/index.js +204 -34
- package/dist/index.js.map +1 -1
- package/dist/mcp-generated.d.cts +1 -1
- package/dist/mcp-generated.d.ts +1 -1
- package/dist/{runtime-BIjr5ME4.d.ts → runtime-CFuv7Ifh.d.ts} +29 -1
- package/dist/{runtime-C4RRHqOs.d.cts → runtime-CdZP-N7j.d.cts} +29 -1
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -391,6 +391,36 @@ var OllamaGenericClientError = class extends OllamaClientError {
|
|
|
391
391
|
function isDomAbortError(error) {
|
|
392
392
|
return typeof DOMException !== "undefined" && error instanceof DOMException && error.name === "AbortError";
|
|
393
393
|
}
|
|
394
|
+
var NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
395
|
+
"ECONNRESET",
|
|
396
|
+
"ECONNREFUSED",
|
|
397
|
+
"EPIPE",
|
|
398
|
+
"ETIMEDOUT",
|
|
399
|
+
"ECONNABORTED",
|
|
400
|
+
"EHOSTUNREACH",
|
|
401
|
+
"ENETUNREACH",
|
|
402
|
+
"ENOTFOUND",
|
|
403
|
+
"EAI_AGAIN",
|
|
404
|
+
"UND_ERR_SOCKET",
|
|
405
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
406
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
407
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
408
|
+
"UND_ERR_CLOSED"
|
|
409
|
+
]);
|
|
410
|
+
var MAX_CAUSE_DEPTH = 4;
|
|
411
|
+
function isNetworkLevelError(error) {
|
|
412
|
+
let current = error;
|
|
413
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH && current !== void 0 && current !== null; depth += 1) {
|
|
414
|
+
if (typeof current === "object" && "code" in current) {
|
|
415
|
+
const code = current.code;
|
|
416
|
+
if (typeof code === "string" && NETWORK_ERROR_CODES.has(code)) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
current = current.cause;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
394
424
|
function statusToError(status, message, options) {
|
|
395
425
|
if (status === 401 || status === 403) {
|
|
396
426
|
return new OllamaAuthError(message, { ...options, status });
|
|
@@ -422,6 +452,13 @@ function mapError(error, context = {}) {
|
|
|
422
452
|
request: context.request
|
|
423
453
|
});
|
|
424
454
|
}
|
|
455
|
+
if (isNetworkLevelError(error)) {
|
|
456
|
+
const message2 = error instanceof Error && error.message ? error.message : "Network request failed";
|
|
457
|
+
return new OllamaNetworkError(message2, {
|
|
458
|
+
cause: error,
|
|
459
|
+
request: context.request
|
|
460
|
+
});
|
|
461
|
+
}
|
|
425
462
|
if (error instanceof TypeError) {
|
|
426
463
|
return new OllamaNetworkError(error.message || "Network request failed", {
|
|
427
464
|
cause: error,
|
|
@@ -1074,6 +1111,18 @@ function createRequestId() {
|
|
|
1074
1111
|
requestSequence += 1;
|
|
1075
1112
|
return `ollama-http-${requestSequence}`;
|
|
1076
1113
|
}
|
|
1114
|
+
function isWebReadableStreamBody(body) {
|
|
1115
|
+
return typeof body === "object" && body !== null && typeof body.getReader === "function";
|
|
1116
|
+
}
|
|
1117
|
+
function buildFetchInit(req) {
|
|
1118
|
+
return {
|
|
1119
|
+
method: req.method,
|
|
1120
|
+
headers: req.headers,
|
|
1121
|
+
...req.body !== void 0 ? { body: req.body } : {},
|
|
1122
|
+
...req.signal !== void 0 ? { signal: req.signal } : {},
|
|
1123
|
+
...isWebReadableStreamBody(req.body) ? { duplex: "half" } : {}
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1077
1126
|
function sameHeaders(actual, expected) {
|
|
1078
1127
|
const actualEntries = Object.fromEntries(
|
|
1079
1128
|
Object.entries(actual).map(([key, value]) => [key.toLowerCase(), value])
|
|
@@ -1123,13 +1172,7 @@ var HttpClient = class {
|
|
|
1123
1172
|
timestamp: startedAt
|
|
1124
1173
|
});
|
|
1125
1174
|
const finalHandler = async (req) => {
|
|
1126
|
-
const
|
|
1127
|
-
method: req.method,
|
|
1128
|
-
headers: req.headers,
|
|
1129
|
-
...req.body !== void 0 ? { body: req.body } : {},
|
|
1130
|
-
...req.signal !== void 0 ? { signal: req.signal } : {}
|
|
1131
|
-
};
|
|
1132
|
-
const response = await this.fetchImpl(req.url, init);
|
|
1175
|
+
const response = await this.fetchImpl(req.url, buildFetchInit(req));
|
|
1133
1176
|
rawResponse = response;
|
|
1134
1177
|
const responseHeaders = response.headers && typeof response.headers.entries === "function" ? Object.fromEntries(response.headers.entries()) : {};
|
|
1135
1178
|
return {
|
|
@@ -1140,12 +1183,7 @@ var HttpClient = class {
|
|
|
1140
1183
|
};
|
|
1141
1184
|
try {
|
|
1142
1185
|
if (this.middleware.length === 0) {
|
|
1143
|
-
const response2 = await this.fetchImpl(request.url,
|
|
1144
|
-
method: request.method,
|
|
1145
|
-
headers: request.headers,
|
|
1146
|
-
...request.body !== void 0 ? { body: request.body } : {},
|
|
1147
|
-
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
1148
|
-
});
|
|
1186
|
+
const response2 = await this.fetchImpl(request.url, buildFetchInit(request));
|
|
1149
1187
|
if (response2.status >= 200 && response2.status < 300) {
|
|
1150
1188
|
this.onLifecycleEvent?.({
|
|
1151
1189
|
type: "success",
|
|
@@ -1647,6 +1685,13 @@ function estimateGenerateRequestTokens(req) {
|
|
|
1647
1685
|
if (req.images !== void 0) total += req.images.length * IMAGE_TOKEN_ESTIMATE;
|
|
1648
1686
|
return total;
|
|
1649
1687
|
}
|
|
1688
|
+
function recommendContextWindow(estimatedTokens) {
|
|
1689
|
+
if (!Number.isFinite(estimatedTokens) || estimatedTokens <= 0) return 4096;
|
|
1690
|
+
const target = estimatedTokens * 1.3;
|
|
1691
|
+
let window = 4096;
|
|
1692
|
+
while (window < target) window *= 2;
|
|
1693
|
+
return window;
|
|
1694
|
+
}
|
|
1650
1695
|
function checkChatContext(req, options = {}) {
|
|
1651
1696
|
return check(estimateChatRequestTokens(req), req.options?.num_ctx, options);
|
|
1652
1697
|
}
|
|
@@ -1656,39 +1701,46 @@ function checkGenerateContext(req, options = {}) {
|
|
|
1656
1701
|
function check(estimatedPromptTokens, requestNumCtx, options) {
|
|
1657
1702
|
const threshold = options.threshold ?? DEFAULT_CONTEXT_WARNING_THRESHOLD;
|
|
1658
1703
|
if (requestNumCtx !== void 0) {
|
|
1704
|
+
const exceeds2 = estimatedPromptTokens > requestNumCtx * threshold;
|
|
1659
1705
|
return {
|
|
1660
1706
|
estimatedPromptTokens,
|
|
1661
1707
|
effectiveContextLength: requestNumCtx,
|
|
1662
1708
|
windowSource: "request",
|
|
1663
|
-
exceedsThreshold:
|
|
1709
|
+
exceedsThreshold: exceeds2,
|
|
1710
|
+
...exceeds2 ? { recommendedNumCtx: recommendContextWindow(estimatedPromptTokens) } : {}
|
|
1664
1711
|
};
|
|
1665
1712
|
}
|
|
1666
1713
|
if (options.defaultContextLength !== void 0) {
|
|
1714
|
+
const exceeds2 = estimatedPromptTokens > options.defaultContextLength * threshold;
|
|
1667
1715
|
return {
|
|
1668
1716
|
estimatedPromptTokens,
|
|
1669
1717
|
effectiveContextLength: options.defaultContextLength,
|
|
1670
1718
|
windowSource: "client-default",
|
|
1671
|
-
exceedsThreshold:
|
|
1719
|
+
exceedsThreshold: exceeds2,
|
|
1720
|
+
...exceeds2 ? { recommendedNumCtx: recommendContextWindow(estimatedPromptTokens) } : {}
|
|
1672
1721
|
};
|
|
1673
1722
|
}
|
|
1723
|
+
const exceeds = estimatedPromptTokens > OLLAMA_FALLBACK_CONTEXT_LENGTH;
|
|
1674
1724
|
return {
|
|
1675
1725
|
estimatedPromptTokens,
|
|
1676
1726
|
effectiveContextLength: OLLAMA_FALLBACK_CONTEXT_LENGTH,
|
|
1677
1727
|
windowSource: "server-fallback",
|
|
1678
|
-
exceedsThreshold:
|
|
1728
|
+
exceedsThreshold: exceeds,
|
|
1729
|
+
...exceeds ? { recommendedNumCtx: recommendContextWindow(estimatedPromptTokens) } : {}
|
|
1679
1730
|
};
|
|
1680
1731
|
}
|
|
1681
1732
|
var OLLAMA_FALLBACK_CONTEXT_LENGTH = 2048;
|
|
1682
1733
|
function contextWarningMessage(check2, kind) {
|
|
1683
1734
|
const where = `OllamaClient.${kind}()`;
|
|
1684
1735
|
const estimate = `~${check2.estimatedPromptTokens} tokens`;
|
|
1736
|
+
const suggestion = check2.recommendedNumCtx !== void 0 ? ` A window of at least ${check2.recommendedNumCtx} tokens would fit this prompt with ~30% headroom (see \`recommendContextWindow\`) \u2014 verify the model's native maximum via \`client.models.getContextLength()\` before adopting it.` : "";
|
|
1685
1737
|
if (check2.windowSource === "request") {
|
|
1686
|
-
return `${where}: estimated prompt size ${estimate} is close to or beyond the request's context window (num_ctx=${check2.effectiveContextLength}). The server will likely silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Raise \`options.num_ctx\` or shorten the conversation
|
|
1738
|
+
return `${where}: estimated prompt size ${estimate} is close to or beyond the request's context window (num_ctx=${check2.effectiveContextLength}). The server will likely silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Raise \`options.num_ctx\` or shorten the conversation.${suggestion} Estimates are heuristic (\xB120\u201330%); see \`estimateTokens\`.`;
|
|
1687
1739
|
}
|
|
1688
1740
|
if (check2.windowSource === "client-default") {
|
|
1689
|
-
return `${where}: estimated prompt size ${estimate} is close to or beyond the client's \`defaultContextLength\` (${check2.effectiveContextLength}, injected as \`num_ctx\`). The server will likely silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Raise \`defaultContextLength\`, set \`options.num_ctx\` per request, or shorten the conversation
|
|
1741
|
+
return `${where}: estimated prompt size ${estimate} is close to or beyond the client's \`defaultContextLength\` (${check2.effectiveContextLength}, injected as \`num_ctx\`). The server will likely silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Raise \`defaultContextLength\`, set \`options.num_ctx\` per request, or shorten the conversation.${suggestion} Estimates are heuristic (\xB120\u201330%); see \`estimateTokens\`.`;
|
|
1690
1742
|
}
|
|
1691
|
-
return `${where}: estimated prompt size ${estimate} outright exceeds Ollama's conservative server-default context window (${OLLAMA_FALLBACK_CONTEXT_LENGTH}\u20134096 tokens when \`num_ctx\` is unset \u2014 model-dependent). Unless the model's default is larger, the server will silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Set \`options.num_ctx\` (or the client's \`defaultContextLength\`) to an explicit window to make truncation visible and controllable
|
|
1743
|
+
return `${where}: estimated prompt size ${estimate} outright exceeds Ollama's conservative server-default context window (${OLLAMA_FALLBACK_CONTEXT_LENGTH}\u20134096 tokens when \`num_ctx\` is unset \u2014 model-dependent). Unless the model's default is larger, the server will silently truncate the top of the conversation \u2014 the model loses earlier turns with no error. Set \`options.num_ctx\` (or the client's \`defaultContextLength\`) to an explicit window to make truncation visible and controllable.${suggestion} Estimates are heuristic (\xB120\u201330%); see \`estimateTokens\`.`;
|
|
1692
1744
|
}
|
|
1693
1745
|
|
|
1694
1746
|
// src/context-discovery.ts
|
|
@@ -2722,7 +2774,7 @@ var ModelsClient = class {
|
|
|
2722
2774
|
{ model, singleEndpoint: true }
|
|
2723
2775
|
);
|
|
2724
2776
|
}
|
|
2725
|
-
async createBlob(digest, data) {
|
|
2777
|
+
async createBlob(digest, data, request) {
|
|
2726
2778
|
await this.runner(
|
|
2727
2779
|
(http, signal) => http.request({
|
|
2728
2780
|
path: `/api/blobs/${encodeURIComponent(digest)}`,
|
|
@@ -2730,10 +2782,10 @@ var ModelsClient = class {
|
|
|
2730
2782
|
rawBody: data,
|
|
2731
2783
|
signal
|
|
2732
2784
|
}),
|
|
2733
|
-
{ singleEndpoint: true }
|
|
2785
|
+
{ ...request, singleEndpoint: true }
|
|
2734
2786
|
);
|
|
2735
2787
|
}
|
|
2736
|
-
async checkBlob(digest) {
|
|
2788
|
+
async checkBlob(digest, request) {
|
|
2737
2789
|
try {
|
|
2738
2790
|
await this.runner(
|
|
2739
2791
|
(http, signal) => http.request({
|
|
@@ -2741,7 +2793,7 @@ var ModelsClient = class {
|
|
|
2741
2793
|
method: "HEAD",
|
|
2742
2794
|
signal
|
|
2743
2795
|
}),
|
|
2744
|
-
{ singleEndpoint: true }
|
|
2796
|
+
{ ...request, singleEndpoint: true }
|
|
2745
2797
|
);
|
|
2746
2798
|
return true;
|
|
2747
2799
|
} catch (err) {
|
|
@@ -2783,9 +2835,32 @@ var ModelsClient = class {
|
|
|
2783
2835
|
*/
|
|
2784
2836
|
async createBlobFromData(data, opts) {
|
|
2785
2837
|
const digest = opts?.digest ?? await this.computeBlobDigest(data);
|
|
2786
|
-
const alreadyExisted = await this.checkBlob(digest);
|
|
2838
|
+
const alreadyExisted = await this.checkBlob(digest, opts);
|
|
2839
|
+
if (!alreadyExisted) {
|
|
2840
|
+
await this.createBlob(digest, data, opts);
|
|
2841
|
+
}
|
|
2842
|
+
return { digest, alreadyExisted };
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* Streams a blob upload straight from a web `ReadableStream` — the
|
|
2846
|
+
* multi-gigabyte-safe counterpart of {@link createBlobFromData}. The body
|
|
2847
|
+
* is never materialized in memory: the transport hands the stream to
|
|
2848
|
+
* `fetch` directly (setting `duplex: 'half'`, which Node 18+ requires for
|
|
2849
|
+
* stream bodies), so peak heap usage is a transport-level chunk, not the
|
|
2850
|
+
* blob size.
|
|
2851
|
+
*
|
|
2852
|
+
* The digest must be known up front — it *is* the upload URL
|
|
2853
|
+
* (`/api/blobs/<digest>`), the same content-addressed protocol
|
|
2854
|
+
* `curl -T` performs. Hash first when you don't have it: in-memory bytes
|
|
2855
|
+
* via {@link computeBlobDigest}, files via {@link createBlobFromFile}
|
|
2856
|
+
* (which hashes in a streaming pass). The server verifies the streamed
|
|
2857
|
+
* bytes against the digest and rejects mismatches, so a corrupted or
|
|
2858
|
+
* truncated stream fails the upload instead of poisoning the store.
|
|
2859
|
+
*/
|
|
2860
|
+
async createBlobFromStream(digest, stream, request) {
|
|
2861
|
+
const alreadyExisted = await this.checkBlob(digest, request);
|
|
2787
2862
|
if (!alreadyExisted) {
|
|
2788
|
-
await this.createBlob(digest,
|
|
2863
|
+
await this.createBlob(digest, stream, request);
|
|
2789
2864
|
}
|
|
2790
2865
|
return { digest, alreadyExisted };
|
|
2791
2866
|
}
|
|
@@ -2794,16 +2869,61 @@ var ModelsClient = class {
|
|
|
2794
2869
|
* `node:fs` import, so browser bundles never pull it in). The file name
|
|
2795
2870
|
* (basename) is what `/api/create`'s `files` map expects as the key, so
|
|
2796
2871
|
* this returns it alongside the digest.
|
|
2872
|
+
*
|
|
2873
|
+
* Streams both passes in fixed-size chunks — peak heap is O(chunk), not
|
|
2874
|
+
* O(file), so multi-gigabyte GGUFs never enter the Node heap:
|
|
2875
|
+
*
|
|
2876
|
+
* 1. **Hash pass** (skipped when `opts.digest` is provided): the file is
|
|
2877
|
+
* streamed through `node:crypto`'s incremental SHA-256.
|
|
2878
|
+
* 2. **Upload pass**: `node:fs` createReadStream → web ReadableStream →
|
|
2879
|
+
* `fetch` body with `duplex: 'half'` (see {@link createBlobFromStream}).
|
|
2880
|
+
*
|
|
2881
|
+
* A pre-existing blob (HEAD 200) skips the upload pass entirely, same as
|
|
2882
|
+
* {@link createBlobFromData}.
|
|
2797
2883
|
*/
|
|
2798
2884
|
async createBlobFromFile(path, opts) {
|
|
2799
2885
|
const nodeFsModule = "node:fs";
|
|
2800
|
-
const {
|
|
2801
|
-
const
|
|
2802
|
-
const
|
|
2803
|
-
|
|
2804
|
-
});
|
|
2886
|
+
const { createReadStream } = await import(nodeFsModule);
|
|
2887
|
+
const nodeCryptoModule = "node:crypto";
|
|
2888
|
+
const { createHash } = await import(nodeCryptoModule);
|
|
2889
|
+
const nodeStreamModule = "node:stream";
|
|
2890
|
+
const { Readable } = await import(nodeStreamModule);
|
|
2891
|
+
const CHUNK_BYTES = 256 * 1024;
|
|
2892
|
+
let digest = opts?.digest;
|
|
2893
|
+
if (digest === void 0) {
|
|
2894
|
+
const hash = createHash("sha256");
|
|
2895
|
+
const hashStream = createReadStream(path, { highWaterMark: CHUNK_BYTES });
|
|
2896
|
+
try {
|
|
2897
|
+
for await (const chunk of hashStream) {
|
|
2898
|
+
if (opts?.signal?.aborted) {
|
|
2899
|
+
throw new OllamaAbortError("createBlobFromFile: aborted while hashing", {});
|
|
2900
|
+
}
|
|
2901
|
+
hash.update(chunk);
|
|
2902
|
+
}
|
|
2903
|
+
} finally {
|
|
2904
|
+
hashStream.destroy();
|
|
2905
|
+
}
|
|
2906
|
+
digest = `sha256:${hash.digest("hex")}`;
|
|
2907
|
+
}
|
|
2908
|
+
const alreadyExisted = await this.checkBlob(digest, opts);
|
|
2909
|
+
if (!alreadyExisted) {
|
|
2910
|
+
const uploadStream = createReadStream(path, { highWaterMark: CHUNK_BYTES });
|
|
2911
|
+
const onAbort = () => {
|
|
2912
|
+
uploadStream.destroy();
|
|
2913
|
+
};
|
|
2914
|
+
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2915
|
+
try {
|
|
2916
|
+
await this.createBlob(
|
|
2917
|
+
digest,
|
|
2918
|
+
Readable.toWeb(uploadStream),
|
|
2919
|
+
opts
|
|
2920
|
+
);
|
|
2921
|
+
} finally {
|
|
2922
|
+
opts?.signal?.removeEventListener("abort", onAbort);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2805
2925
|
const fileName = path.split(/[\\/]/).pop() ?? path;
|
|
2806
|
-
return {
|
|
2926
|
+
return { digest, alreadyExisted, fileName };
|
|
2807
2927
|
}
|
|
2808
2928
|
/**
|
|
2809
2929
|
* One-shot custom-model publishing from raw GGUF weights, following the
|
|
@@ -6143,8 +6263,8 @@ var OllamaClient = class _OllamaClient {
|
|
|
6143
6263
|
*/
|
|
6144
6264
|
getContextLength = (request) => this.models.getContextLength(request);
|
|
6145
6265
|
version = () => this.models.version();
|
|
6146
|
-
createBlob = (digest, data) => this.models.createBlob(digest, data);
|
|
6147
|
-
checkBlob = (digest) => this.models.checkBlob(digest);
|
|
6266
|
+
createBlob = (digest, data, request) => this.models.createBlob(digest, data, request);
|
|
6267
|
+
checkBlob = (digest, request) => this.models.checkBlob(digest, request);
|
|
6148
6268
|
/**
|
|
6149
6269
|
* Immediately unloads `model` from VRAM. Convenience alias for
|
|
6150
6270
|
* {@link ModelsClient.unload} — see that method for the full
|
|
@@ -6664,6 +6784,56 @@ function toResponse(stream, init = {}) {
|
|
|
6664
6784
|
return new Response(body, { ...init, headers });
|
|
6665
6785
|
}
|
|
6666
6786
|
|
|
6787
|
+
// src/streaming/observe.ts
|
|
6788
|
+
async function* observeStream(source, callbacks = {}) {
|
|
6789
|
+
const { onChunk, onError, onDone, onAbandon, onListenerError } = callbacks;
|
|
6790
|
+
const reportListenerFailure = (error, phase) => {
|
|
6791
|
+
try {
|
|
6792
|
+
onListenerError?.(error, phase);
|
|
6793
|
+
} catch {
|
|
6794
|
+
}
|
|
6795
|
+
};
|
|
6796
|
+
let observerChain = Promise.resolve();
|
|
6797
|
+
const dispatch2 = (phase, task) => {
|
|
6798
|
+
observerChain = observerChain.then(task).then(
|
|
6799
|
+
() => void 0,
|
|
6800
|
+
(error) => {
|
|
6801
|
+
reportListenerFailure(error, phase);
|
|
6802
|
+
}
|
|
6803
|
+
);
|
|
6804
|
+
};
|
|
6805
|
+
let state = "running";
|
|
6806
|
+
try {
|
|
6807
|
+
for await (const chunk of source) {
|
|
6808
|
+
if (onChunk !== void 0) {
|
|
6809
|
+
dispatch2("chunk", () => onChunk(chunk));
|
|
6810
|
+
}
|
|
6811
|
+
yield chunk;
|
|
6812
|
+
}
|
|
6813
|
+
state = "done";
|
|
6814
|
+
if (onDone !== void 0) {
|
|
6815
|
+
dispatch2("done", () => onDone());
|
|
6816
|
+
}
|
|
6817
|
+
} catch (error) {
|
|
6818
|
+
state = "error";
|
|
6819
|
+
try {
|
|
6820
|
+
onError?.(error);
|
|
6821
|
+
} catch (listenerError) {
|
|
6822
|
+
reportListenerFailure(listenerError, "error");
|
|
6823
|
+
}
|
|
6824
|
+
throw error;
|
|
6825
|
+
} finally {
|
|
6826
|
+
if (state === "running") {
|
|
6827
|
+
state = "abandoned";
|
|
6828
|
+
try {
|
|
6829
|
+
onAbandon?.();
|
|
6830
|
+
} catch (listenerError) {
|
|
6831
|
+
reportListenerFailure(listenerError, "abandoned");
|
|
6832
|
+
}
|
|
6833
|
+
}
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
|
|
6667
6837
|
// src/quota.ts
|
|
6668
6838
|
var QuotaManager = class {
|
|
6669
6839
|
now;
|
|
@@ -8014,6 +8184,6 @@ function estimateSystemOneRequestBytes(request) {
|
|
|
8014
8184
|
return new TextEncoder().encode(JSON.stringify(request)).byteLength;
|
|
8015
8185
|
}
|
|
8016
8186
|
|
|
8017
|
-
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, ConversationSession, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, EndpointRegistry, GEN_AI_SYSTEM_OLLAMA, HttpClient, IMAGE_TOKEN_ESTIMATE, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, ModelAffinityRouter, ModelAffinityScheduler, ModelsClient, NANOS_PER_MS, NANOS_PER_SECOND, NOOP_LOGGER, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaAbortError, OllamaAgentMaxIterationsError, OllamaAgentMaxToolCallsError, OllamaAgentToolLoopError, OllamaAuthError, OllamaBadGatewayError, OllamaClient, OllamaClientError, OllamaGenericClientError, OllamaIncompatibleModelError, OllamaMcpError, OllamaModelRoutingError, OllamaNetworkError, OllamaNotFoundError, OllamaOverloadedError, OllamaQuotaExceededError, OllamaRateLimitError, OllamaRequestTooLargeError, OllamaRequestValidationError, OllamaResponseValidationError, OllamaServerError, OllamaServerVersionUnknownError, OllamaSkillInvalidError, OllamaSkillNotFoundError, OllamaStream, OllamaStreamError, OllamaTimeoutError, OllamaToolTimeoutError, OllamaToolValidationError, OllamaUnsupportedCapabilityError, OpenAIChatCompletionStream, OpenAICompatClient, OpenAICompletionStream, OpenAIResponsesStream, OpenAIResponsesStreamError, QuotaManager, RETRYABLE_STATUS_CODES, ResponsesModule, ToolCallAccumulator, ToolRegistry, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, addSpanEvent, applySkill, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, compareDraftPerformance, composeMiddleware, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, extractUsage, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, imageStringNeedsResolution, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mapError, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, parseFrontmatter, parseNdjsonStream, parseSseStream, parseStructuredOutput, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
8187
|
+
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, ConversationSession, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_CONTEXT_WARNING_THRESHOLD, DEFAULT_EMBED_BATCH_SIZE, DEFAULT_EMBED_CONCURRENCY, DEFAULT_FAILOVER_CODES, DEFAULT_FETCH_BACKOFF_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, EndpointRegistry, GEN_AI_SYSTEM_OLLAMA, HttpClient, IMAGE_TOKEN_ESTIMATE, KEEP_ALIVE_INDEFINITE, KEEP_ALIVE_UNLOAD, KNOWN_DONE_REASONS, MAX_SYSTEM_ONE_IMAGES_BYTES, MAX_SYSTEM_ONE_REQUEST_BYTES, MESSAGE_OVERHEAD_TOKENS, McpBridge, ModelAffinityRouter, ModelAffinityScheduler, ModelsClient, NANOS_PER_MS, NANOS_PER_SECOND, NETWORK_ERROR_CODES, NOOP_LOGGER, OLLAMA_CLOUD_BASE_URL, OLLAMA_FALLBACK_CONTEXT_LENGTH, OllamaAbortError, OllamaAgentMaxIterationsError, OllamaAgentMaxToolCallsError, OllamaAgentToolLoopError, OllamaAuthError, OllamaBadGatewayError, OllamaClient, OllamaClientError, OllamaGenericClientError, OllamaIncompatibleModelError, OllamaMcpError, OllamaModelRoutingError, OllamaNetworkError, OllamaNotFoundError, OllamaOverloadedError, OllamaQuotaExceededError, OllamaRateLimitError, OllamaRequestTooLargeError, OllamaRequestValidationError, OllamaResponseValidationError, OllamaServerError, OllamaServerVersionUnknownError, OllamaSkillInvalidError, OllamaSkillNotFoundError, OllamaStream, OllamaStreamError, OllamaTimeoutError, OllamaToolTimeoutError, OllamaToolValidationError, OllamaUnsupportedCapabilityError, OpenAIChatCompletionStream, OpenAICompatClient, OpenAICompletionStream, OpenAIResponsesStream, OpenAIResponsesStreamError, QuotaManager, RETRYABLE_STATUS_CODES, ResponsesModule, ToolCallAccumulator, ToolRegistry, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, addSpanEvent, applySkill, batchEmbed, calculateBackoff, canonicalToolCallSignature, checkChatContext, checkEndpointHealth, checkGenerateContext, compactConversationHistory, compareDraftPerformance, composeMiddleware, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createTimeoutSignal, createWebFetchTool, createWebSearchTool, createWebTools, defineTool, detectModelCapabilities, embedBatchOverflowMessage, encodeImage, estimateChatRequestTokens, estimateGenerateRequestTokens, estimateMessageTokens, estimateSystemOneRequestBytes, estimateTokens, extractContextLength as extractNativeContextLength, extractParameterNumCtx, extractUsage, fetchWithBackoff, findOversizedEmbedInputs, findRunningModelContextLength, formatTelemetry, formatWebFetchResult, formatWebSearchResult, imageStringNeedsResolution, inferRuntimeMode, isKeepAliveSugar, isKnownDoneReason, isModelResident, isNetworkLevelError, isSameToolCall, listAllMcpTools, listAvailableModels, loadMcpTools, mapError, mergeToolCall, mergeToolCallArgumentsString, mergeToolCallArrays, normalizeChatStream, normalizeGenerateStream, normalizeKeepAlive, normalizeProgressStream, observeStream, parseFrontmatter, parseNdjsonStream, parseSseStream, parseStructuredOutput, recommendContextWindow, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
8018
8188
|
//# sourceMappingURL=index.js.map
|
|
8019
8189
|
//# sourceMappingURL=index.js.map
|