@nemesis-oss/ollama-sdk 1.17.0 → 1.19.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +79 -0
  3. package/dist/{anthropic-AKbXnWJU.d.cts → anthropic-CAvwqIjx.d.ts} +5 -5
  4. package/dist/{anthropic-CTv2acbj.d.ts → anthropic-DIPnBwlf.d.cts} +5 -5
  5. package/dist/{compose-CeFbHJeO.d.ts → compose-75UFDzOO.d.ts} +1 -1
  6. package/dist/{compose-DFkmtUOP.d.cts → compose-C4QxEZOS.d.cts} +1 -1
  7. package/dist/generated-api.cjs +5 -3
  8. package/dist/generated-api.cjs.map +1 -1
  9. package/dist/generated-api.d.cts +9 -9
  10. package/dist/generated-api.d.ts +9 -9
  11. package/dist/generated-api.js +5 -3
  12. package/dist/generated-api.js.map +1 -1
  13. package/dist/generated-models-schemas.cjs +2 -2
  14. package/dist/generated-models-schemas.cjs.map +1 -1
  15. package/dist/generated-models-schemas.js +2 -2
  16. package/dist/generated-models-schemas.js.map +1 -1
  17. package/dist/generated-runtime.cjs +24 -6
  18. package/dist/generated-runtime.cjs.map +1 -1
  19. package/dist/generated-runtime.d.cts +2 -2
  20. package/dist/generated-runtime.d.ts +2 -2
  21. package/dist/generated-runtime.js +24 -6
  22. package/dist/generated-runtime.js.map +1 -1
  23. package/dist/index.cjs +132 -20
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +294 -40
  26. package/dist/index.d.ts +294 -40
  27. package/dist/index.js +128 -21
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/tools.json +8 -10
  30. package/dist/mcp-generated.cjs +5 -3
  31. package/dist/mcp-generated.cjs.map +1 -1
  32. package/dist/mcp-generated.d.cts +2 -2
  33. package/dist/mcp-generated.d.ts +2 -2
  34. package/dist/mcp-generated.js +5 -3
  35. package/dist/mcp-generated.js.map +1 -1
  36. package/dist/{runtime-CdZP-N7j.d.cts → runtime-C28YEAHC.d.cts} +28 -5
  37. package/dist/{runtime-CFuv7Ifh.d.ts → runtime-DYCxYGG-.d.ts} +28 -5
  38. package/dist/skills.cjs.map +1 -1
  39. package/dist/skills.d.cts +3 -3
  40. package/dist/skills.d.ts +3 -3
  41. package/dist/skills.js.map +1 -1
  42. package/dist/{types-DbPnfVh-.d.cts → types-Y3u0FtdN.d.cts} +10 -0
  43. package/dist/{types-DbPnfVh-.d.ts → types-Y3u0FtdN.d.ts} +10 -0
  44. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -193,6 +193,11 @@ var OllamaAuthError = class extends OllamaClientError {
193
193
  super(message, { ...options, code: "auth_error", retryable: false });
194
194
  }
195
195
  };
196
+ var OllamaPaymentRequiredError = class extends OllamaClientError {
197
+ constructor(message, options) {
198
+ super(message, { ...options, code: "payment_required", retryable: false, status: 402 });
199
+ }
200
+ };
196
201
  var OllamaNotFoundError = class extends OllamaClientError {
197
202
  constructor(message, options) {
198
203
  super(message, { ...options, code: "not_found", retryable: false });
@@ -427,6 +432,9 @@ function statusToError(status, message, options) {
427
432
  if (status === 401 || status === 403) {
428
433
  return new OllamaAuthError(message, { ...options, status });
429
434
  }
435
+ if (status === 402) {
436
+ return new OllamaPaymentRequiredError(message, options);
437
+ }
430
438
  if (status === 404) {
431
439
  return new OllamaNotFoundError(message, { ...options, status });
432
440
  }
@@ -4179,7 +4187,7 @@ var SystemOneNoulQuestionSchema = zod.z.object({
4179
4187
  var SystemOneScoreQuestionSchema = zod.z.object({
4180
4188
  type: zod.z.enum(["score"]),
4181
4189
  instructions: SystemOneContentSchema,
4182
- criteria: zod.z.array(zod.z.string()).min(2).max(26)
4190
+ criteria: zod.z.array(zod.z.string()).min(2).max(10)
4183
4191
  });
4184
4192
 
4185
4193
  // src/generated/models/SystemOneRequest.schema.ts
@@ -4214,7 +4222,7 @@ var SystemOneNoulAnswerSchema = zod.z.object({
4214
4222
  });
4215
4223
  var SystemOneScoreAnswerSchema = zod.z.object({
4216
4224
  type: zod.z.enum(["score"]),
4217
- score: zod.z.number().min(0).max(25),
4225
+ score: zod.z.number().min(0).max(9),
4218
4226
  legend: zod.z.object({}).catchall(zod.z.string()),
4219
4227
  probabilities: SystemOneProbabilitiesSchema,
4220
4228
  confidence: SystemOneConfidenceSchema
@@ -4425,14 +4433,25 @@ var OllamaRuntime = class {
4425
4433
  const hasImages = bodyHasImages(body);
4426
4434
  const maxBytesWithImages = req.operation.constraints?.maxRequestBytesWithImages;
4427
4435
  const maxBytesBase = req.operation.constraints?.maxRequestBytes;
4428
- const applicableLimit = hasImages && maxBytesWithImages !== void 0 ? maxBytesWithImages : maxBytesBase;
4429
- if (applicableLimit !== void 0 && serialized.byteLength > applicableLimit) {
4436
+ const textAndSchemaBytes = hasImages ? serializeWithoutImages(body).byteLength : serialized.byteLength;
4437
+ if (maxBytesBase !== void 0 && textAndSchemaBytes > maxBytesBase) {
4438
+ throw new OllamaRequestTooLargeError(
4439
+ `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.`,
4440
+ {
4441
+ operationId: req.operation.operationId,
4442
+ actualBytes: textAndSchemaBytes,
4443
+ maxBytes: maxBytesBase,
4444
+ request: { method: req.operation.method, url: req.operation.path }
4445
+ }
4446
+ );
4447
+ }
4448
+ if (maxBytesWithImages !== void 0 && serialized.byteLength > maxBytesWithImages) {
4430
4449
  throw new OllamaRequestTooLargeError(
4431
- `Operation ${req.operation.operationId} (${req.operation.method} ${req.operation.path}) request body is ${serialized.byteLength} bytes, exceeding the contract limit of ${applicableLimit} bytes` + (hasImages ? " (images limit)." : "."),
4450
+ `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).`,
4432
4451
  {
4433
4452
  operationId: req.operation.operationId,
4434
4453
  actualBytes: serialized.byteLength,
4435
- maxBytes: applicableLimit,
4454
+ maxBytes: maxBytesWithImages,
4436
4455
  request: { method: req.operation.method, url: req.operation.path }
4437
4456
  }
4438
4457
  );
@@ -4574,6 +4593,13 @@ function bodyHasImages(body) {
4574
4593
  const images = obj.images;
4575
4594
  return Array.isArray(images) && images.length > 0;
4576
4595
  }
4596
+ function serializeWithoutImages(body) {
4597
+ if (typeof body === "object" && body !== null && !Array.isArray(body)) {
4598
+ const { images: _images, ...rest } = body;
4599
+ return serializeForByteCount(rest);
4600
+ }
4601
+ return serializeForByteCount(body);
4602
+ }
4577
4603
  function resolvePathParams(pathTemplate, pathParams) {
4578
4604
  if (!pathTemplate.includes("{")) return pathTemplate;
4579
4605
  const params = pathParams ?? {};
@@ -5326,7 +5352,7 @@ var systemOneOp = {
5326
5352
  path: "/v1/systemone",
5327
5353
  request: { $ref: "#/schemas/SystemOneRequest" },
5328
5354
  response: { $ref: "#/schemas/SystemOneResponse" },
5329
- environment: { local: true, cloud: false },
5355
+ environment: { local: true, cloud: true },
5330
5356
  transport: { mode: "json", streaming: false },
5331
5357
  capabilities: {
5332
5358
  thinking: "unsupported",
@@ -5344,8 +5370,10 @@ var systemOneOp = {
5344
5370
  status: { documented: true, experimental: true },
5345
5371
  domain: "native",
5346
5372
  notes: [
5347
- "Local-only; Ollama Cloud rejects /v1/systemone.",
5348
- "64 KiB request limit without images, 32 MiB with images (includes JSON/base64 overhead).",
5373
+ "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.",
5374
+ "Local dual cap: text and schema (excluding images) within 64 KiB AND the whole request within 32 MiB, including base64 and JSON overhead.",
5375
+ "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.",
5376
+ "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.",
5349
5377
  "No tools, no generation controls (temperature, top_p, etc.).",
5350
5378
  "Vision is model-dependent: images are accepted by vision-weighted models (Clef/Clef Flash) but not by text-only models.",
5351
5379
  "Experimental: behavioral surface may change between Ollama releases."
@@ -5525,9 +5553,16 @@ var FailoverHttpClient = class {
5525
5553
  };
5526
5554
 
5527
5555
  // src/decision.ts
5556
+ function validateThreshold(value, name) {
5557
+ if (value === void 0) return;
5558
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > 1) {
5559
+ throw new RangeError(`${name} must be a number in (0, 1] \u2014 got ${String(value)}`);
5560
+ }
5561
+ }
5528
5562
  function createDecision(client) {
5529
5563
  return {
5530
5564
  async choice(params) {
5565
+ validateThreshold(params.minConfidence, "minConfidence");
5531
5566
  const response = await client.systemOne({
5532
5567
  model: params.model,
5533
5568
  state: params.state,
@@ -5546,10 +5581,12 @@ function createDecision(client) {
5546
5581
  choice: answer.choice,
5547
5582
  probabilities: answer.probabilities,
5548
5583
  confidence: answer.confidence,
5584
+ ...params.minConfidence !== void 0 ? { isConfident: answer.confidence >= params.minConfidence } : {},
5549
5585
  usage: response.usage
5550
5586
  };
5551
5587
  },
5552
5588
  async noul(params) {
5589
+ validateThreshold(params.minProbability, "minProbability");
5553
5590
  const response = await client.systemOne({
5554
5591
  model: params.model,
5555
5592
  state: params.state,
@@ -5565,11 +5602,12 @@ function createDecision(client) {
5565
5602
  const answer = response.answers.decision;
5566
5603
  return {
5567
5604
  noul: answer.noul,
5568
- bool: answer.noul >= 0.5,
5605
+ bool: answer.noul >= (params.minProbability ?? 0.5),
5569
5606
  usage: response.usage
5570
5607
  };
5571
5608
  },
5572
5609
  async score(params) {
5610
+ validateThreshold(params.minConfidence, "minConfidence");
5573
5611
  const response = await client.systemOne({
5574
5612
  model: params.model,
5575
5613
  state: params.state,
@@ -5589,10 +5627,12 @@ function createDecision(client) {
5589
5627
  legend: answer.legend,
5590
5628
  probabilities: answer.probabilities,
5591
5629
  confidence: answer.confidence,
5630
+ ...params.minConfidence !== void 0 ? { isConfident: answer.confidence >= params.minConfidence } : {},
5592
5631
  usage: response.usage
5593
5632
  };
5594
5633
  },
5595
5634
  async route(params) {
5635
+ validateThreshold(params.minConfidence, "minConfidence");
5596
5636
  const response = await client.systemOne({
5597
5637
  model: params.model,
5598
5638
  state: params.state,
@@ -5609,10 +5649,12 @@ function createDecision(client) {
5609
5649
  const answer = response.answers.decision;
5610
5650
  return {
5611
5651
  route: answer.choice,
5612
- confidence: answer.confidence
5652
+ confidence: answer.confidence,
5653
+ ...params.minConfidence !== void 0 ? { isConfident: answer.confidence >= params.minConfidence } : {}
5613
5654
  };
5614
5655
  },
5615
5656
  async verify(params) {
5657
+ validateThreshold(params.minProbability, "minProbability");
5616
5658
  const state = {
5617
5659
  claim: params.claim,
5618
5660
  evidence: params.evidence
@@ -5631,11 +5673,12 @@ function createDecision(client) {
5631
5673
  });
5632
5674
  const answer = response.answers.decision;
5633
5675
  return {
5634
- verified: answer.noul >= 0.5,
5676
+ verified: answer.noul >= (params.minProbability ?? 0.5),
5635
5677
  probability: answer.noul
5636
5678
  };
5637
5679
  },
5638
5680
  async rank(params) {
5681
+ validateThreshold(params.minConfidence, "minConfidence");
5639
5682
  const promises = params.candidates.map(async (candidate) => {
5640
5683
  const response = await client.systemOne({
5641
5684
  model: params.model,
@@ -5654,7 +5697,8 @@ function createDecision(client) {
5654
5697
  return {
5655
5698
  candidate: candidate.id,
5656
5699
  score: answer.score,
5657
- confidence: answer.confidence
5700
+ confidence: answer.confidence,
5701
+ ...params.minConfidence !== void 0 ? { isConfident: answer.confidence >= params.minConfidence } : {}
5658
5702
  };
5659
5703
  });
5660
5704
  const results = await Promise.all(promises);
@@ -6285,11 +6329,15 @@ var OllamaClient = class _OllamaClient {
6285
6329
  * 1–64 typed questions (choice, noul, or score) against a provided state
6286
6330
  * and returns typed answers with probabilities and confidence.
6287
6331
  *
6288
- * Local-only; requires Ollama >= 0.35.0. The runtime enforces the
6289
- * version constraint automatically (lazily fetching `/api/version` when
6290
- * `enforceVersion` is `'auto'` or `'strict'`) and rejects cloud-mode
6291
- * calls. Request size is checked client-side: 64 KiB without images,
6292
- * 32 MiB with images.
6332
+ * Local and cloud (since the 2026-10-16 upstream System One cloud
6333
+ * launch): `model` also accepts cloud models such as `clef:cloud` —
6334
+ * cloud models require Ollama >= 0.40.5 or the hosted
6335
+ * `https://ollama.com` endpoint. Requires Ollama >= 0.35.0 locally.
6336
+ * The runtime enforces the version constraint automatically (lazily
6337
+ * fetching `/api/version` when `enforceVersion` is `'auto'` or
6338
+ * `'strict'`). Request size is checked client-side as a dual cap:
6339
+ * text and schema (images excluded) within 64 KiB AND the whole
6340
+ * request within 32 MiB.
6293
6341
  *
6294
6342
  * The generic `Q` parameter captures the caller's question map at
6295
6343
  * compile time, giving key-safe answer access:
@@ -6786,6 +6834,64 @@ function toResponse(stream, init = {}) {
6786
6834
  return new Response(body, { ...init, headers });
6787
6835
  }
6788
6836
 
6837
+ // src/streaming/progress.ts
6838
+ function computeProgressPercent(chunk) {
6839
+ if (typeof chunk.total !== "number" || typeof chunk.completed !== "number") return void 0;
6840
+ if (chunk.total <= 0) return void 0;
6841
+ const ratio = chunk.completed / chunk.total;
6842
+ const clamped = Math.max(0, Math.min(1, ratio));
6843
+ return Math.round(clamped * 1e4) / 100;
6844
+ }
6845
+ function toPullProgressEvent(chunk) {
6846
+ return {
6847
+ status: chunk.status,
6848
+ ...chunk.digest !== void 0 ? { digest: chunk.digest } : {},
6849
+ ...chunk.total !== void 0 ? { total: chunk.total } : {},
6850
+ ...chunk.completed !== void 0 ? { completed: chunk.completed } : {},
6851
+ percent: computeProgressPercent(chunk),
6852
+ raw: chunk
6853
+ };
6854
+ }
6855
+ function createProgressSpeedTracker() {
6856
+ let epochDigest;
6857
+ let epochStartMs = 0;
6858
+ let epochStartCompleted = 0;
6859
+ return (chunk) => {
6860
+ if (typeof chunk.completed !== "number") return {};
6861
+ const digestChanged = chunk.digest !== void 0 && chunk.digest !== epochDigest;
6862
+ const regressed = chunk.completed < epochStartCompleted;
6863
+ if (digestChanged || regressed) {
6864
+ epochDigest = chunk.digest;
6865
+ epochStartMs = performance.now();
6866
+ epochStartCompleted = chunk.completed;
6867
+ return {};
6868
+ }
6869
+ const elapsedSeconds = (performance.now() - epochStartMs) / 1e3;
6870
+ if (elapsedSeconds <= 0) return {};
6871
+ const transferred = chunk.completed - epochStartCompleted;
6872
+ if (transferred <= 0) return {};
6873
+ const bytesPerSecond = transferred / elapsedSeconds;
6874
+ const etaSeconds = typeof chunk.total === "number" ? Math.max(0, (chunk.total - chunk.completed) / bytesPerSecond) : void 0;
6875
+ return { bytesPerSecond, etaSeconds };
6876
+ };
6877
+ }
6878
+ async function onProgress(stream, callback) {
6879
+ void stream.finalResult.catch(() => void 0);
6880
+ const speed = createProgressSpeedTracker();
6881
+ for await (const event of stream) {
6882
+ if (event.type === "message") {
6883
+ callback({ ...toPullProgressEvent(event.data.chunk), ...speed(event.data.chunk) });
6884
+ }
6885
+ if (event.type === "done") {
6886
+ return event.data.result;
6887
+ }
6888
+ if (event.type === "error") {
6889
+ throw event.data.error;
6890
+ }
6891
+ }
6892
+ throw new OllamaStreamError("Pull/push stream ended before reporting success");
6893
+ }
6894
+
6789
6895
  // src/streaming/observe.ts
6790
6896
  async function* observeStream(source, callbacks = {}) {
6791
6897
  const { onChunk, onError, onDone, onAbandon, onListenerError } = callbacks;
@@ -8182,8 +8288,9 @@ function createModelAffinityScheduler(client, options) {
8182
8288
  // src/system-one.ts
8183
8289
  var MAX_SYSTEM_ONE_IMAGES_BYTES = 32 * 1024 * 1024;
8184
8290
  var MAX_SYSTEM_ONE_REQUEST_BYTES = 64 * 1024;
8185
- function estimateSystemOneRequestBytes(request) {
8186
- return new TextEncoder().encode(JSON.stringify(request)).byteLength;
8291
+ function estimateSystemOneRequestBytes(request, options) {
8292
+ const body = options?.excludeImages && request.images !== void 0 ? { ...request, images: void 0 } : request;
8293
+ return new TextEncoder().encode(JSON.stringify(body)).byteLength;
8187
8294
  }
8188
8295
 
8189
8296
  exports.ATTR_GEN_AI_OPERATION_NAME = ATTR_GEN_AI_OPERATION_NAME;
@@ -8251,6 +8358,7 @@ exports.OllamaModelRoutingError = OllamaModelRoutingError;
8251
8358
  exports.OllamaNetworkError = OllamaNetworkError;
8252
8359
  exports.OllamaNotFoundError = OllamaNotFoundError;
8253
8360
  exports.OllamaOverloadedError = OllamaOverloadedError;
8361
+ exports.OllamaPaymentRequiredError = OllamaPaymentRequiredError;
8254
8362
  exports.OllamaQuotaExceededError = OllamaQuotaExceededError;
8255
8363
  exports.OllamaRateLimitError = OllamaRateLimitError;
8256
8364
  exports.OllamaRequestTooLargeError = OllamaRequestTooLargeError;
@@ -8289,11 +8397,13 @@ exports.checkGenerateContext = checkGenerateContext;
8289
8397
  exports.compactConversationHistory = compactConversationHistory;
8290
8398
  exports.compareDraftPerformance = compareDraftPerformance;
8291
8399
  exports.composeMiddleware = composeMiddleware;
8400
+ exports.computeProgressPercent = computeProgressPercent;
8292
8401
  exports.contextWarningMessage = contextWarningMessage;
8293
8402
  exports.createConsoleLogger = createConsoleLogger;
8294
8403
  exports.createDecision = createDecision;
8295
8404
  exports.createModelAffinityScheduler = createModelAffinityScheduler;
8296
8405
  exports.createOllamaCloudFreeTierQuota = createOllamaCloudFreeTierQuota;
8406
+ exports.createProgressSpeedTracker = createProgressSpeedTracker;
8297
8407
  exports.createTimeoutSignal = createTimeoutSignal;
8298
8408
  exports.createWebFetchTool = createWebFetchTool;
8299
8409
  exports.createWebSearchTool = createWebSearchTool;
@@ -8335,6 +8445,7 @@ exports.normalizeGenerateStream = normalizeGenerateStream;
8335
8445
  exports.normalizeKeepAlive = normalizeKeepAlive;
8336
8446
  exports.normalizeProgressStream = normalizeProgressStream;
8337
8447
  exports.observeStream = observeStream;
8448
+ exports.onProgress = onProgress;
8338
8449
  exports.parseFrontmatter = parseFrontmatter;
8339
8450
  exports.parseNdjsonStream = parseNdjsonStream;
8340
8451
  exports.parseSseStream = parseSseStream;
@@ -8347,6 +8458,7 @@ exports.resolveImageInput = resolveImageInput;
8347
8458
  exports.sanitizeHistoryForNextTurn = sanitizeHistoryForNextTurn;
8348
8459
  exports.setSpanError = setSpanError;
8349
8460
  exports.toDataStream = toDataStream;
8461
+ exports.toPullProgressEvent = toPullProgressEvent;
8350
8462
  exports.toResponse = toResponse;
8351
8463
  exports.toTextStream = toTextStream;
8352
8464
  exports.withRetry = withRetry;