@nemesis-oss/ollama-sdk 1.18.0 → 1.19.1
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 +45 -0
- package/README.md +9 -9
- package/dist/{anthropic-CvGVSoVP.d.ts → anthropic-Bf16hGLL.d.cts} +3 -3
- package/dist/{anthropic-BvHOsidk.d.cts → anthropic-BmFk4Pjq.d.ts} +3 -3
- package/dist/{compose-CeFbHJeO.d.ts → compose-75UFDzOO.d.ts} +1 -1
- package/dist/{compose-DFkmtUOP.d.cts → compose-C4QxEZOS.d.cts} +1 -1
- package/dist/generated-api.cjs +5 -3
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +9 -9
- package/dist/generated-api.d.ts +9 -9
- package/dist/generated-api.js +5 -3
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-runtime.cjs +22 -4
- package/dist/generated-runtime.cjs.map +1 -1
- package/dist/generated-runtime.d.cts +2 -2
- package/dist/generated-runtime.d.ts +2 -2
- package/dist/generated-runtime.js +22 -4
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +163 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +145 -66
- package/dist/index.d.ts +145 -66
- package/dist/index.js +162 -29
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +3 -3
- package/dist/mcp-generated.cjs +5 -3
- package/dist/mcp-generated.cjs.map +1 -1
- package/dist/mcp-generated.d.cts +2 -2
- package/dist/mcp-generated.d.ts +2 -2
- package/dist/mcp-generated.js +5 -3
- package/dist/mcp-generated.js.map +1 -1
- package/dist/{runtime-CdZP-N7j.d.cts → runtime-CjCriL5A.d.cts} +56 -5
- package/dist/{runtime-CFuv7Ifh.d.ts → runtime-EwyUaNnZ.d.ts} +56 -5
- 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-DbPnfVh-.d.cts → types-Y3u0FtdN.d.cts} +10 -0
- package/dist/{types-DbPnfVh-.d.ts → types-Y3u0FtdN.d.ts} +10 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -191,6 +191,11 @@ var OllamaAuthError = class extends OllamaClientError {
|
|
|
191
191
|
super(message, { ...options, code: "auth_error", retryable: false });
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
|
+
var OllamaPaymentRequiredError = class extends OllamaClientError {
|
|
195
|
+
constructor(message, options) {
|
|
196
|
+
super(message, { ...options, code: "payment_required", retryable: false, status: 402 });
|
|
197
|
+
}
|
|
198
|
+
};
|
|
194
199
|
var OllamaNotFoundError = class extends OllamaClientError {
|
|
195
200
|
constructor(message, options) {
|
|
196
201
|
super(message, { ...options, code: "not_found", retryable: false });
|
|
@@ -421,15 +426,56 @@ function isNetworkLevelError(error) {
|
|
|
421
426
|
}
|
|
422
427
|
return false;
|
|
423
428
|
}
|
|
429
|
+
function lookupHeader(headers, name) {
|
|
430
|
+
if (headers === void 0) {
|
|
431
|
+
return void 0;
|
|
432
|
+
}
|
|
433
|
+
const needle = name.toLowerCase();
|
|
434
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
435
|
+
if (key.toLowerCase() === needle) {
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return void 0;
|
|
440
|
+
}
|
|
441
|
+
var HTTP_DATE_PATTERN = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
442
|
+
function parseRetryAfterMs(headerValue, now = Date.now()) {
|
|
443
|
+
if (headerValue === void 0) {
|
|
444
|
+
return void 0;
|
|
445
|
+
}
|
|
446
|
+
const trimmed = headerValue.trim();
|
|
447
|
+
if (trimmed === "") {
|
|
448
|
+
return void 0;
|
|
449
|
+
}
|
|
450
|
+
if (/^\d+$/.test(trimmed)) {
|
|
451
|
+
const seconds = Number(trimmed);
|
|
452
|
+
if (!Number.isSafeInteger(seconds)) {
|
|
453
|
+
return void 0;
|
|
454
|
+
}
|
|
455
|
+
return seconds * 1e3;
|
|
456
|
+
}
|
|
457
|
+
if (!HTTP_DATE_PATTERN.test(trimmed)) {
|
|
458
|
+
return void 0;
|
|
459
|
+
}
|
|
460
|
+
const instant = Date.parse(trimmed);
|
|
461
|
+
if (Number.isNaN(instant)) {
|
|
462
|
+
return void 0;
|
|
463
|
+
}
|
|
464
|
+
return Math.max(0, instant - now);
|
|
465
|
+
}
|
|
424
466
|
function statusToError(status, message, options) {
|
|
425
467
|
if (status === 401 || status === 403) {
|
|
426
468
|
return new OllamaAuthError(message, { ...options, status });
|
|
427
469
|
}
|
|
470
|
+
if (status === 402) {
|
|
471
|
+
return new OllamaPaymentRequiredError(message, options);
|
|
472
|
+
}
|
|
428
473
|
if (status === 404) {
|
|
429
474
|
return new OllamaNotFoundError(message, { ...options, status });
|
|
430
475
|
}
|
|
431
476
|
if (status === 429) {
|
|
432
|
-
|
|
477
|
+
const retryAfterMs = parseRetryAfterMs(lookupHeader(options.response?.headers, "retry-after"));
|
|
478
|
+
return new OllamaRateLimitError(message, { ...options, status, retryAfterMs });
|
|
433
479
|
}
|
|
434
480
|
if (status === 502) {
|
|
435
481
|
return new OllamaBadGatewayError(message, { ...options });
|
|
@@ -1132,6 +1178,21 @@ function sameHeaders(actual, expected) {
|
|
|
1132
1178
|
const expectedKeys = Object.keys(expectedEntries);
|
|
1133
1179
|
return actualKeys.length === expectedKeys.length && expectedKeys.every((key) => actualEntries[key] === expectedEntries[key]);
|
|
1134
1180
|
}
|
|
1181
|
+
function retryAfterHeaderFrom(response) {
|
|
1182
|
+
try {
|
|
1183
|
+
const headers = response?.headers;
|
|
1184
|
+
if (headers === null || headers === void 0 || typeof headers.get !== "function") {
|
|
1185
|
+
return void 0;
|
|
1186
|
+
}
|
|
1187
|
+
const value = headers.get("retry-after");
|
|
1188
|
+
if (value === null || value === "") {
|
|
1189
|
+
return void 0;
|
|
1190
|
+
}
|
|
1191
|
+
return { "retry-after": value };
|
|
1192
|
+
} catch {
|
|
1193
|
+
return void 0;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1135
1196
|
var HttpClient = class {
|
|
1136
1197
|
baseUrl;
|
|
1137
1198
|
apiKey;
|
|
@@ -1199,7 +1260,12 @@ var HttpClient = class {
|
|
|
1199
1260
|
durationMs: Date.now() - startedAt,
|
|
1200
1261
|
error: mapError(new Error(`HTTP ${response2.status}`), {
|
|
1201
1262
|
request: { method: request.method, url: request.url },
|
|
1202
|
-
|
|
1263
|
+
// Mirrors the middleware path, which reports context.headers:
|
|
1264
|
+
// a 429 lifecycle event carries the server's Retry-After.
|
|
1265
|
+
response: {
|
|
1266
|
+
status: response2.status,
|
|
1267
|
+
headers: retryAfterHeaderFrom(response2)
|
|
1268
|
+
}
|
|
1203
1269
|
}),
|
|
1204
1270
|
timestamp: Date.now()
|
|
1205
1271
|
});
|
|
@@ -1305,7 +1371,11 @@ var HttpClient = class {
|
|
|
1305
1371
|
const message = typeof errorBody === "object" && errorBody !== null && "error" in errorBody ? String(errorBody.error) : `HTTP ${response.status} ${response.statusText}`;
|
|
1306
1372
|
throw mapError(new Error(message), {
|
|
1307
1373
|
request: { method, url },
|
|
1308
|
-
response: {
|
|
1374
|
+
response: {
|
|
1375
|
+
status: response.status,
|
|
1376
|
+
headers: retryAfterHeaderFrom(response),
|
|
1377
|
+
body: errorBody
|
|
1378
|
+
}
|
|
1309
1379
|
});
|
|
1310
1380
|
}
|
|
1311
1381
|
if (options.method === "HEAD" || response.status === 204) {
|
|
@@ -1370,7 +1440,11 @@ var HttpClient = class {
|
|
|
1370
1440
|
const errorText = await response.text();
|
|
1371
1441
|
throw mapError(new Error(errorText || `HTTP ${response.status}`), {
|
|
1372
1442
|
request: { method, url },
|
|
1373
|
-
response: {
|
|
1443
|
+
response: {
|
|
1444
|
+
status: response.status,
|
|
1445
|
+
headers: retryAfterHeaderFrom(response),
|
|
1446
|
+
body: errorText
|
|
1447
|
+
}
|
|
1374
1448
|
});
|
|
1375
1449
|
}
|
|
1376
1450
|
if (!response.body) {
|
|
@@ -1434,7 +1508,11 @@ var HttpClient = class {
|
|
|
1434
1508
|
const errorText = await response.text();
|
|
1435
1509
|
throw mapError(new Error(errorText || `HTTP ${response.status}`), {
|
|
1436
1510
|
request: { method, url },
|
|
1437
|
-
response: {
|
|
1511
|
+
response: {
|
|
1512
|
+
status: response.status,
|
|
1513
|
+
headers: retryAfterHeaderFrom(response),
|
|
1514
|
+
body: errorText
|
|
1515
|
+
}
|
|
1438
1516
|
});
|
|
1439
1517
|
}
|
|
1440
1518
|
if (!response.body) {
|
|
@@ -1740,7 +1818,7 @@ function contextWarningMessage(check2, kind) {
|
|
|
1740
1818
|
if (check2.windowSource === "client-default") {
|
|
1741
1819
|
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\`.`;
|
|
1742
1820
|
}
|
|
1743
|
-
return `${where}: estimated prompt size ${estimate} outright exceeds
|
|
1821
|
+
return `${where}: estimated prompt size ${estimate} outright exceeds the worst-case floor for the unset-\`num_ctx\` window (${OLLAMA_FALLBACK_CONTEXT_LENGTH} tokens \u2014 current daemons default higher, tiered by VRAM: 4096 / 32768 / 262144; \`OLLAMA_CONTEXT_LENGTH\` can override either way). If your daemon's effective window is that small, 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 \u2014 or discover the real one via \`client.models.getContextLength()\` \u2014 to make truncation visible and controllable.${suggestion} Estimates are heuristic (\xB120\u201330%); see \`estimateTokens\`.`;
|
|
1744
1822
|
}
|
|
1745
1823
|
|
|
1746
1824
|
// src/context-discovery.ts
|
|
@@ -2468,6 +2546,12 @@ function sleep(ms, signal) {
|
|
|
2468
2546
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2469
2547
|
});
|
|
2470
2548
|
}
|
|
2549
|
+
function retryDelayMs(error, attempt, backoff) {
|
|
2550
|
+
if (error instanceof OllamaRateLimitError && error.retryAfterMs !== void 0) {
|
|
2551
|
+
return error.retryAfterMs;
|
|
2552
|
+
}
|
|
2553
|
+
return calculateBackoff(attempt, backoff);
|
|
2554
|
+
}
|
|
2471
2555
|
async function withRetry(operation, config = DEFAULT_RETRY_CONFIG, signal) {
|
|
2472
2556
|
let attempt = 0;
|
|
2473
2557
|
while (true) {
|
|
@@ -2479,7 +2563,7 @@ async function withRetry(operation, config = DEFAULT_RETRY_CONFIG, signal) {
|
|
|
2479
2563
|
if (attempt >= config.maxRetries || !shouldRetry(error, attempt)) {
|
|
2480
2564
|
throw error;
|
|
2481
2565
|
}
|
|
2482
|
-
const delayMs =
|
|
2566
|
+
const delayMs = retryDelayMs(error, attempt, config.backoff);
|
|
2483
2567
|
config.onRetry?.(error, attempt, delayMs);
|
|
2484
2568
|
await sleep(delayMs, signal);
|
|
2485
2569
|
attempt += 1;
|
|
@@ -2648,7 +2732,8 @@ var ModelsClient = class {
|
|
|
2648
2732
|
}
|
|
2649
2733
|
/**
|
|
2650
2734
|
* Discovers the model's real context window from the server — no more
|
|
2651
|
-
*
|
|
2735
|
+
* default-window guesswork (current daemons tier the unset-`num_ctx`
|
|
2736
|
+
* default by VRAM: 4k / 32k / 256k). Consults, in precedence order:
|
|
2652
2737
|
*
|
|
2653
2738
|
* 1. `GET /api/ps` — the window the **running instance actually
|
|
2654
2739
|
* allocated** (exact, reflects the Modelfile `num_ctx` default and
|
|
@@ -2660,7 +2745,7 @@ var ModelsClient = class {
|
|
|
2660
2745
|
* 3. `POST /api/show` `model_info["<arch>.context_length"]` — the
|
|
2661
2746
|
* model's **native GGUF maximum** (a ceiling to raise `num_ctx`
|
|
2662
2747
|
* toward, not the allocated window).
|
|
2663
|
-
* 4. Fallback —
|
|
2748
|
+
* 4. Fallback — the 2048 worst-case floor for the unset-`num_ctx` window.
|
|
2664
2749
|
*
|
|
2665
2750
|
* The result carries every signal it found, so `nativeContextLength:
|
|
2666
2751
|
* 131072` vs `contextLength: 4096` (a 32× gap seen in the official API
|
|
@@ -4423,14 +4508,25 @@ var OllamaRuntime = class {
|
|
|
4423
4508
|
const hasImages = bodyHasImages(body);
|
|
4424
4509
|
const maxBytesWithImages = req.operation.constraints?.maxRequestBytesWithImages;
|
|
4425
4510
|
const maxBytesBase = req.operation.constraints?.maxRequestBytes;
|
|
4426
|
-
const
|
|
4427
|
-
if (
|
|
4511
|
+
const textAndSchemaBytes = hasImages ? serializeWithoutImages(body).byteLength : serialized.byteLength;
|
|
4512
|
+
if (maxBytesBase !== void 0 && textAndSchemaBytes > maxBytesBase) {
|
|
4513
|
+
throw new OllamaRequestTooLargeError(
|
|
4514
|
+
`Operation ${req.operation.operationId} (${req.operation.method} ${req.operation.path}) text and schema (images excluded) is ${textAndSchemaBytes} bytes, exceeding the contract limit of ${maxBytesBase} bytes.`,
|
|
4515
|
+
{
|
|
4516
|
+
operationId: req.operation.operationId,
|
|
4517
|
+
actualBytes: textAndSchemaBytes,
|
|
4518
|
+
maxBytes: maxBytesBase,
|
|
4519
|
+
request: { method: req.operation.method, url: req.operation.path }
|
|
4520
|
+
}
|
|
4521
|
+
);
|
|
4522
|
+
}
|
|
4523
|
+
if (maxBytesWithImages !== void 0 && serialized.byteLength > maxBytesWithImages) {
|
|
4428
4524
|
throw new OllamaRequestTooLargeError(
|
|
4429
|
-
`Operation ${req.operation.operationId} (${req.operation.method} ${req.operation.path}) request body is ${serialized.byteLength} bytes, exceeding the contract limit of ${
|
|
4525
|
+
`Operation ${req.operation.operationId} (${req.operation.method} ${req.operation.path}) request body is ${serialized.byteLength} bytes, exceeding the contract limit of ${maxBytesWithImages} bytes (whole request, images included).`,
|
|
4430
4526
|
{
|
|
4431
4527
|
operationId: req.operation.operationId,
|
|
4432
4528
|
actualBytes: serialized.byteLength,
|
|
4433
|
-
maxBytes:
|
|
4529
|
+
maxBytes: maxBytesWithImages,
|
|
4434
4530
|
request: { method: req.operation.method, url: req.operation.path }
|
|
4435
4531
|
}
|
|
4436
4532
|
);
|
|
@@ -4572,6 +4668,13 @@ function bodyHasImages(body) {
|
|
|
4572
4668
|
const images = obj.images;
|
|
4573
4669
|
return Array.isArray(images) && images.length > 0;
|
|
4574
4670
|
}
|
|
4671
|
+
function serializeWithoutImages(body) {
|
|
4672
|
+
if (typeof body === "object" && body !== null && !Array.isArray(body)) {
|
|
4673
|
+
const { images: _images, ...rest } = body;
|
|
4674
|
+
return serializeForByteCount(rest);
|
|
4675
|
+
}
|
|
4676
|
+
return serializeForByteCount(body);
|
|
4677
|
+
}
|
|
4575
4678
|
function resolvePathParams(pathTemplate, pathParams) {
|
|
4576
4679
|
if (!pathTemplate.includes("{")) return pathTemplate;
|
|
4577
4680
|
const params = pathParams ?? {};
|
|
@@ -5324,7 +5427,7 @@ var systemOneOp = {
|
|
|
5324
5427
|
path: "/v1/systemone",
|
|
5325
5428
|
request: { $ref: "#/schemas/SystemOneRequest" },
|
|
5326
5429
|
response: { $ref: "#/schemas/SystemOneResponse" },
|
|
5327
|
-
environment: { local: true, cloud:
|
|
5430
|
+
environment: { local: true, cloud: true },
|
|
5328
5431
|
transport: { mode: "json", streaming: false },
|
|
5329
5432
|
capabilities: {
|
|
5330
5433
|
thinking: "unsupported",
|
|
@@ -5342,8 +5445,10 @@ var systemOneOp = {
|
|
|
5342
5445
|
status: { documented: true, experimental: true },
|
|
5343
5446
|
domain: "native",
|
|
5344
5447
|
notes: [
|
|
5345
|
-
"Local
|
|
5346
|
-
"64 KiB
|
|
5448
|
+
"Local and cloud: model accepts cloud models (e.g. clef:cloud); cloud models require Ollama >= 0.40.5 or the hosted https://ollama.com endpoint.",
|
|
5449
|
+
"Local dual cap: text and schema (excluding images) within 64 KiB AND the whole request within 32 MiB, including base64 and JSON overhead.",
|
|
5450
|
+
"Cloud requests: paid plan or usage credits required; up to 64 questions named with up to 100 ASCII letters, digits, `_`, `.`, or `-`; up to 4 images of at most 4 MiB and 16 megapixels each (8 MiB total); requests within 13 MiB; input within the model's 65,536-token context window.",
|
|
5451
|
+
"401 when a cloud model is requested without signing in or with an invalid API key (through a local server the response includes a signin_url); 402 when the cloud model is not included in the Free plan or a payment fails.",
|
|
5347
5452
|
"No tools, no generation controls (temperature, top_p, etc.).",
|
|
5348
5453
|
"Vision is model-dependent: images are accepted by vision-weighted models (Clef/Clef Flash) but not by text-only models.",
|
|
5349
5454
|
"Experimental: behavioral surface may change between Ollama releases."
|
|
@@ -6299,11 +6404,15 @@ var OllamaClient = class _OllamaClient {
|
|
|
6299
6404
|
* 1–64 typed questions (choice, noul, or score) against a provided state
|
|
6300
6405
|
* and returns typed answers with probabilities and confidence.
|
|
6301
6406
|
*
|
|
6302
|
-
* Local
|
|
6303
|
-
*
|
|
6304
|
-
*
|
|
6305
|
-
*
|
|
6306
|
-
*
|
|
6407
|
+
* Local and cloud (since the 2026-10-16 upstream System One cloud
|
|
6408
|
+
* launch): `model` also accepts cloud models such as `clef:cloud` —
|
|
6409
|
+
* cloud models require Ollama >= 0.40.5 or the hosted
|
|
6410
|
+
* `https://ollama.com` endpoint. Requires Ollama >= 0.35.0 locally.
|
|
6411
|
+
* The runtime enforces the version constraint automatically (lazily
|
|
6412
|
+
* fetching `/api/version` when `enforceVersion` is `'auto'` or
|
|
6413
|
+
* `'strict'`). Request size is checked client-side as a dual cap:
|
|
6414
|
+
* text and schema (images excluded) within 64 KiB AND the whole
|
|
6415
|
+
* request within 32 MiB.
|
|
6307
6416
|
*
|
|
6308
6417
|
* The generic `Q` parameter captures the caller's question map at
|
|
6309
6418
|
* compile time, giving key-safe answer access:
|
|
@@ -6337,7 +6446,9 @@ var OllamaClient = class _OllamaClient {
|
|
|
6337
6446
|
* through a local server. Requires an Ollama account API key: pass `apiKey` to the
|
|
6338
6447
|
* client constructor or set `OLLAMA_API_KEY`. Applies the same default `timeoutMs` and
|
|
6339
6448
|
* retry policy as inference calls, but never cross-endpoint-fails-over — there is only
|
|
6340
|
-
* ever the one cloud endpoint to call.
|
|
6449
|
+
* ever the one cloud endpoint to call. If the service answers 429 with a `Retry-After`
|
|
6450
|
+
* header, the transport parses it into `OllamaRateLimitError.retryAfterMs` and the
|
|
6451
|
+
* retry loop sleeps exactly that long instead of jittered backoff (see ADR 0035).
|
|
6341
6452
|
*/
|
|
6342
6453
|
async webSearch(req) {
|
|
6343
6454
|
const { count, max_results, ...rest } = req;
|
|
@@ -6368,8 +6479,11 @@ var OllamaClient = class _OllamaClient {
|
|
|
6368
6479
|
* web search, and web fetch, bucketed by hour (`range: '24h'`) or day (`'7d'`/`'30d'`).
|
|
6369
6480
|
*
|
|
6370
6481
|
* See {@link OllamaClient.webSearch} for the cloud-endpoint/auth/timeout/retry
|
|
6371
|
-
* behavior, which applies identically here.
|
|
6372
|
-
* endpoint
|
|
6482
|
+
* behavior, which applies identically here. The pinned contract documents this
|
|
6483
|
+
* endpoint's 429 with a `Retry-After` header ("Seconds to wait before retrying"),
|
|
6484
|
+
* which the SDK parses into `OllamaRateLimitError.retryAfterMs` and honors verbatim
|
|
6485
|
+
* when retrying. Query parameters mirror the official endpoint: `range`
|
|
6486
|
+
* (`'24h' | '7d' | '30d'`, server default `'7d'`) and `scope`
|
|
6373
6487
|
* (`'self' | 'team'`, server default `'self'`; team scope requires a team admin).
|
|
6374
6488
|
* Omitted options are left unset so the server applies its own defaults.
|
|
6375
6489
|
*
|
|
@@ -6402,7 +6516,9 @@ var OllamaClient = class _OllamaClient {
|
|
|
6402
6516
|
* object (`balance_usd`/`allowance_usd`/`period`) or, on legacy plans, session/weekly
|
|
6403
6517
|
* percentage limits; the shape is discriminated at runtime by the server response.
|
|
6404
6518
|
* See {@link OllamaClient.webSearch} for the cloud-endpoint/auth/timeout/retry
|
|
6405
|
-
* behavior, which applies identically here.
|
|
6519
|
+
* behavior, which applies identically here. Like `/api/usage`, the pinned contract
|
|
6520
|
+
* documents this endpoint's 429 with a `Retry-After` header, parsed into
|
|
6521
|
+
* `OllamaRateLimitError.retryAfterMs` and honored verbatim when retrying (ADR 0035).
|
|
6406
6522
|
*
|
|
6407
6523
|
* ```ts
|
|
6408
6524
|
* const balance = await client.balance();
|
|
@@ -6688,6 +6804,21 @@ function sleep2(ms, signal) {
|
|
|
6688
6804
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
6689
6805
|
});
|
|
6690
6806
|
}
|
|
6807
|
+
function retryAfterMsFromResponse(response) {
|
|
6808
|
+
try {
|
|
6809
|
+
const headers = response?.headers;
|
|
6810
|
+
if (headers === null || headers === void 0 || typeof headers.get !== "function") {
|
|
6811
|
+
return void 0;
|
|
6812
|
+
}
|
|
6813
|
+
const value = headers.get("retry-after");
|
|
6814
|
+
if (value === null || value === "") {
|
|
6815
|
+
return void 0;
|
|
6816
|
+
}
|
|
6817
|
+
return parseRetryAfterMs(value);
|
|
6818
|
+
} catch {
|
|
6819
|
+
return void 0;
|
|
6820
|
+
}
|
|
6821
|
+
}
|
|
6691
6822
|
async function fetchWithBackoff(input, init, config = {}) {
|
|
6692
6823
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
6693
6824
|
if (typeof fetchImpl !== "function") {
|
|
@@ -6709,7 +6840,8 @@ async function fetchWithBackoff(input, init, config = {}) {
|
|
|
6709
6840
|
...signal !== void 0 ? { signal } : {}
|
|
6710
6841
|
});
|
|
6711
6842
|
if (RETRYABLE_STATUS_CODES.has(response.status) && attempt < maxRetries) {
|
|
6712
|
-
const
|
|
6843
|
+
const serverDelayMs = response.status === 429 ? retryAfterMsFromResponse(response) : void 0;
|
|
6844
|
+
const delayMs = serverDelayMs ?? calculateBackoff(attempt, backoff);
|
|
6713
6845
|
config.onRetry?.(attempt, response.status, delayMs);
|
|
6714
6846
|
await sleep2(delayMs, signal);
|
|
6715
6847
|
continue;
|
|
@@ -8254,10 +8386,11 @@ function createModelAffinityScheduler(client, options) {
|
|
|
8254
8386
|
// src/system-one.ts
|
|
8255
8387
|
var MAX_SYSTEM_ONE_IMAGES_BYTES = 32 * 1024 * 1024;
|
|
8256
8388
|
var MAX_SYSTEM_ONE_REQUEST_BYTES = 64 * 1024;
|
|
8257
|
-
function estimateSystemOneRequestBytes(request) {
|
|
8258
|
-
|
|
8389
|
+
function estimateSystemOneRequestBytes(request, options) {
|
|
8390
|
+
const body = options?.excludeImages && request.images !== void 0 ? { ...request, images: void 0 } : request;
|
|
8391
|
+
return new TextEncoder().encode(JSON.stringify(body)).byteLength;
|
|
8259
8392
|
}
|
|
8260
8393
|
|
|
8261
|
-
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, computeProgressPercent, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createProgressSpeedTracker, 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, onProgress, parseFrontmatter, parseNdjsonStream, parseSseStream, parseStructuredOutput, recommendContextWindow, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toPullProgressEvent, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
8394
|
+
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, OllamaPaymentRequiredError, 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, computeProgressPercent, contextWarningMessage, createConsoleLogger, createDecision, createModelAffinityScheduler, createOllamaCloudFreeTierQuota, createProgressSpeedTracker, 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, onProgress, parseFrontmatter, parseNdjsonStream, parseRetryAfterMs, parseSseStream, parseStructuredOutput, recommendContextWindow, registerMcpTools, resolveContextLength, resolveCredentialEndpoints, resolveImageInput, sanitizeHistoryForNextTurn, setSpanError, toDataStream, toPullProgressEvent, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };
|
|
8262
8395
|
//# sourceMappingURL=index.js.map
|
|
8263
8396
|
//# sourceMappingURL=index.js.map
|