@nemesis-oss/ollama-sdk 1.19.1 → 1.20.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 (45) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{anthropic-Bf16hGLL.d.cts → anthropic-BFOC6eI7.d.ts} +7 -1
  3. package/dist/{anthropic-BmFk4Pjq.d.ts → anthropic-C2-qaxjI.d.cts} +7 -1
  4. package/dist/{compose-C4QxEZOS.d.cts → compose-BXXgHmrS.d.cts} +1 -1
  5. package/dist/{compose-75UFDzOO.d.ts → compose-DaG83yId.d.ts} +1 -1
  6. package/dist/generated-api.cjs +1 -1
  7. package/dist/generated-api.cjs.map +1 -1
  8. package/dist/generated-api.d.cts +7 -7
  9. package/dist/generated-api.d.ts +7 -7
  10. package/dist/generated-api.js +1 -1
  11. package/dist/generated-api.js.map +1 -1
  12. package/dist/generated-models-schemas.cjs +25 -2
  13. package/dist/generated-models-schemas.cjs.map +1 -1
  14. package/dist/generated-models-schemas.d.cts +97 -5
  15. package/dist/generated-models-schemas.d.ts +97 -5
  16. package/dist/generated-models-schemas.js +24 -3
  17. package/dist/generated-models-schemas.js.map +1 -1
  18. package/dist/generated-runtime.cjs +23 -2
  19. package/dist/generated-runtime.cjs.map +1 -1
  20. package/dist/generated-runtime.d.cts +2 -2
  21. package/dist/generated-runtime.d.ts +2 -2
  22. package/dist/generated-runtime.js +23 -2
  23. package/dist/generated-runtime.js.map +1 -1
  24. package/dist/index.cjs +113 -15
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +101 -17
  27. package/dist/index.d.ts +101 -17
  28. package/dist/index.js +109 -16
  29. package/dist/index.js.map +1 -1
  30. package/dist/mcp/tools.json +1 -1
  31. package/dist/mcp-generated.cjs +1 -1
  32. package/dist/mcp-generated.cjs.map +1 -1
  33. package/dist/mcp-generated.d.cts +2 -2
  34. package/dist/mcp-generated.d.ts +2 -2
  35. package/dist/mcp-generated.js +1 -1
  36. package/dist/mcp-generated.js.map +1 -1
  37. package/dist/{runtime-CjCriL5A.d.cts → runtime-CpO3H6yy.d.cts} +27 -2
  38. package/dist/{runtime-EwyUaNnZ.d.ts → runtime-DPSrPwAa.d.ts} +27 -2
  39. package/dist/skills.cjs.map +1 -1
  40. package/dist/skills.d.cts +3 -3
  41. package/dist/skills.d.ts +3 -3
  42. package/dist/skills.js.map +1 -1
  43. package/dist/{types-Y3u0FtdN.d.cts → types-CnsZ24tm.d.cts} +17 -1
  44. package/dist/{types-Y3u0FtdN.d.ts → types-CnsZ24tm.d.ts} +17 -1
  45. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -303,6 +303,17 @@ var OllamaToolTimeoutError = class extends OllamaClientError {
303
303
  this.timeoutMs = options.timeoutMs;
304
304
  }
305
305
  };
306
+ var OllamaCloudModelVersionError = class extends OllamaClientError {
307
+ model;
308
+ serverVersion;
309
+ minRequiredVersion;
310
+ constructor(message, options) {
311
+ super(message, { ...options, code: "cloud_model_version", retryable: false });
312
+ this.model = options.model;
313
+ this.serverVersion = options.serverVersion;
314
+ this.minRequiredVersion = options.minRequiredVersion;
315
+ }
316
+ };
306
317
  var OllamaUnsupportedCapabilityError = class extends OllamaClientError {
307
318
  capability;
308
319
  constructor(message, options) {
@@ -4233,6 +4244,9 @@ var ShowResponseSchema = zod.z.object({
4233
4244
  modified_at: zod.z.string().optional(),
4234
4245
  details: zod.z.object({}).optional(),
4235
4246
  template: zod.z.string().optional(),
4247
+ renderer: zod.z.string().optional(),
4248
+ parser: zod.z.string().optional(),
4249
+ template_source: zod.z.string().optional(),
4236
4250
  capabilities: zod.z.array(zod.z.string()).optional(),
4237
4251
  model_info: zod.z.object({}).optional()
4238
4252
  });
@@ -4324,9 +4338,26 @@ var UsageMetricsSchema = zod.z.object({
4324
4338
  output_tokens: zod.z.number().optional()
4325
4339
  });
4326
4340
 
4341
+ // src/generated/models/UsageGroup.schema.ts
4342
+ var UsageGroupSchema = zod.z.intersection(
4343
+ UsageMetricsSchema,
4344
+ zod.z.object({
4345
+ model: zod.z.string()
4346
+ })
4347
+ );
4348
+
4349
+ // src/generated/models/UsageSummary.schema.ts
4350
+ var UsageSummarySchema = zod.z.intersection(
4351
+ UsageMetricsSchema,
4352
+ zod.z.object({
4353
+ groups: zod.z.array(UsageGroupSchema).optional(),
4354
+ remainder: UsageMetricsSchema.optional()
4355
+ })
4356
+ );
4357
+
4327
4358
  // src/generated/models/UsageBucket.schema.ts
4328
4359
  var UsageBucketSchema = zod.z.intersection(
4329
- UsageMetricsSchema,
4360
+ UsageSummarySchema,
4330
4361
  zod.z.object({
4331
4362
  from: zod.z.string(),
4332
4363
  until: zod.z.string(),
@@ -4339,9 +4370,10 @@ var UsageResponseSchema = zod.z.object({
4339
4370
  range: zod.z.enum(["24h", "7d", "30d"]),
4340
4371
  scope: zod.z.enum(["self", "team"]),
4341
4372
  granularity: zod.z.enum(["hour", "day"]),
4373
+ group_by: zod.z.enum(["model"]).optional(),
4342
4374
  from: zod.z.string(),
4343
4375
  until: zod.z.string(),
4344
- totals: UsageMetricsSchema,
4376
+ totals: UsageSummarySchema,
4345
4377
  buckets: zod.z.array(UsageBucketSchema)
4346
4378
  });
4347
4379
  var VersionResponseSchema = zod.z.object({
@@ -5784,6 +5816,29 @@ function createDecision(client) {
5784
5816
  };
5785
5817
  }
5786
5818
 
5819
+ // src/system-one.ts
5820
+ var MAX_SYSTEM_ONE_IMAGES_BYTES = 32 * 1024 * 1024;
5821
+ var MAX_SYSTEM_ONE_REQUEST_BYTES = 64 * 1024;
5822
+ var CLOUD_MODEL_SUFFIX = ":cloud";
5823
+ var CLOUD_MODEL_MIN_OLLAMA_VERSION = "0.40.5";
5824
+ function isCloudModel(model) {
5825
+ return model.endsWith(CLOUD_MODEL_SUFFIX);
5826
+ }
5827
+ function compareOllamaVersions(a, b) {
5828
+ const pa = a.split(".").map((s) => Number.parseInt(s, 10) || 0);
5829
+ const pb = b.split(".").map((s) => Number.parseInt(s, 10) || 0);
5830
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
5831
+ const va = pa[i] ?? 0;
5832
+ const vb = pb[i] ?? 0;
5833
+ if (va !== vb) return va - vb;
5834
+ }
5835
+ return 0;
5836
+ }
5837
+ function estimateSystemOneRequestBytes(request, options) {
5838
+ const body = options?.excludeImages && request.images !== void 0 ? { ...request, images: void 0 } : request;
5839
+ return new TextEncoder().encode(JSON.stringify(body)).byteLength;
5840
+ }
5841
+
5787
5842
  // src/client.ts
5788
5843
  var logicalRequestSequence = 0;
5789
5844
  function createLogicalRequestId() {
@@ -6410,9 +6465,13 @@ var OllamaClient = class _OllamaClient {
6410
6465
  * launch): `model` also accepts cloud models such as `clef:cloud` —
6411
6466
  * cloud models require Ollama >= 0.40.5 or the hosted
6412
6467
  * `https://ollama.com` endpoint. Requires Ollama >= 0.35.0 locally.
6413
- * The runtime enforces the version constraint automatically (lazily
6468
+ * Both version constraints are enforced client-side before the request
6469
+ * is sent: the blanket 0.35.0 floor by the generated runtime (lazily
6414
6470
  * fetching `/api/version` when `enforceVersion` is `'auto'` or
6415
- * `'strict'`). Request size is checked client-side as a dual cap:
6471
+ * `'strict'`), and the model-dependent 0.40.5 cloud gate by this
6472
+ * wrapper — a cloud model through a local server older than 0.40.5
6473
+ * throws {@link OllamaCloudModelVersionError} without a round-trip
6474
+ * (ADR 0036). Request size is checked client-side as a dual cap:
6416
6475
  * text and schema (images excluded) within 64 KiB AND the whole
6417
6476
  * request within 32 MiB.
6418
6477
  *
@@ -6437,10 +6496,44 @@ var OllamaClient = class _OllamaClient {
6437
6496
  * `client.native.systemOne(request)` directly.
6438
6497
  */
6439
6498
  async systemOne(request) {
6499
+ await this.assertCloudModelSupported(request.model);
6440
6500
  return this.native.systemOne(
6441
6501
  request
6442
6502
  );
6443
6503
  }
6504
+ /**
6505
+ * Cloud-model version gate for {@link systemOne} — throws
6506
+ * {@link OllamaCloudModelVersionError} when a cloud model is requested
6507
+ * through a local server older than {@link CLOUD_MODEL_MIN_OLLAMA_VERSION}
6508
+ * (0.40.5). No-op for non-cloud models and for cloud-mode clients
6509
+ * (hosted `ollama.com`). The `/api/version` probe goes through the normal
6510
+ * failover machinery and is cached per client instance (reset on failure,
6511
+ * so a later gated call retries), so at most one extra round-trip happens
6512
+ * across all gated calls.
6513
+ */
6514
+ async assertCloudModelSupported(model) {
6515
+ if (!isCloudModel(model)) return;
6516
+ const candidates = this.registry.candidates();
6517
+ const baseUrl = candidates[0]?.baseUrl ?? DEFAULT_BASE_URL;
6518
+ if (inferRuntimeMode(baseUrl) !== "local") return;
6519
+ let version;
6520
+ try {
6521
+ if (this.serverVersionCache === void 0) {
6522
+ this.serverVersionCache = this.native.version().then((v) => v.version);
6523
+ }
6524
+ version = await this.serverVersionCache;
6525
+ } catch {
6526
+ this.serverVersionCache = void 0;
6527
+ return;
6528
+ }
6529
+ if (version && compareOllamaVersions(version, CLOUD_MODEL_MIN_OLLAMA_VERSION) < 0) {
6530
+ throw new OllamaCloudModelVersionError(
6531
+ `System One cloud model "${model}" requires Ollama >= ${CLOUD_MODEL_MIN_OLLAMA_VERSION} when routed through a local server (this server reports ${version}). Upgrade Ollama, or point an endpoint at https://ollama.com.`,
6532
+ { model, serverVersion: version, minRequiredVersion: CLOUD_MODEL_MIN_OLLAMA_VERSION }
6533
+ );
6534
+ }
6535
+ }
6536
+ serverVersionCache;
6444
6537
  // --- Web Endpoints ---
6445
6538
  /**
6446
6539
  * Ollama's hosted web search tool (`POST https://ollama.com/api/web_search`) — a fixed
@@ -6485,13 +6578,20 @@ var OllamaClient = class _OllamaClient {
6485
6578
  * endpoint's 429 with a `Retry-After` header ("Seconds to wait before retrying"),
6486
6579
  * which the SDK parses into `OllamaRateLimitError.retryAfterMs` and honors verbatim
6487
6580
  * when retrying. Query parameters mirror the official endpoint: `range`
6488
- * (`'24h' | '7d' | '30d'`, server default `'7d'`) and `scope`
6489
- * (`'self' | 'team'`, server default `'self'`; team scope requires a team admin).
6581
+ * (`'24h' | '7d' | '30d'`, server default `'7d'`), `scope`
6582
+ * (`'self' | 'team'`, server default `'self'`; team scope requires a team
6583
+ * admin), and — since the 2026-10-22 pin (upstream 2476d5e) — `groupBy`
6584
+ * (`group_by=model`), which makes `totals` and every bucket carry up to 10
6585
+ * per-model `UsageGroup` entries plus a `remainder` roll-up, with the
6586
+ * selection echoed back as `group_by` on the response.
6490
6587
  * Omitted options are left unset so the server applies its own defaults.
6491
6588
  *
6492
6589
  * ```ts
6493
- * const usage = await client.usage({ range: '24h' });
6590
+ * const usage = await client.usage({ range: '24h', groupBy: 'model' });
6494
6591
  * console.log(usage.totals.request_count, usage.totals.usage_usd);
6592
+ * for (const group of usage.totals.groups ?? []) {
6593
+ * console.log(group.model, group.usage_usd);
6594
+ * }
6495
6595
  * for (const bucket of usage.buckets) {
6496
6596
  * if (bucket.partial) continue; // current hour, still in progress
6497
6597
  * // ...
@@ -6502,6 +6602,7 @@ var OllamaClient = class _OllamaClient {
6502
6602
  const params = new URLSearchParams();
6503
6603
  if (req.range !== void 0) params.set("range", req.range);
6504
6604
  if (req.scope !== void 0) params.set("scope", req.scope);
6605
+ if (req.groupBy !== void 0) params.set("group_by", req.groupBy);
6505
6606
  const query = params.toString();
6506
6607
  return this.executeCloudRequest(
6507
6608
  (http, signal) => http.request({
@@ -8385,14 +8486,6 @@ function createModelAffinityScheduler(client, options) {
8385
8486
  return new ModelAffinityScheduler(client, options);
8386
8487
  }
8387
8488
 
8388
- // src/system-one.ts
8389
- var MAX_SYSTEM_ONE_IMAGES_BYTES = 32 * 1024 * 1024;
8390
- var MAX_SYSTEM_ONE_REQUEST_BYTES = 64 * 1024;
8391
- function estimateSystemOneRequestBytes(request, options) {
8392
- const body = options?.excludeImages && request.images !== void 0 ? { ...request, images: void 0 } : request;
8393
- return new TextEncoder().encode(JSON.stringify(body)).byteLength;
8394
- }
8395
-
8396
8489
  exports.ATTR_GEN_AI_OPERATION_NAME = ATTR_GEN_AI_OPERATION_NAME;
8397
8490
  exports.ATTR_GEN_AI_REQUEST_MODEL = ATTR_GEN_AI_REQUEST_MODEL;
8398
8491
  exports.ATTR_GEN_AI_RESPONSE_MODEL = ATTR_GEN_AI_RESPONSE_MODEL;
@@ -8413,6 +8506,8 @@ exports.ATTR_URL_FULL = ATTR_URL_FULL;
8413
8506
  exports.Agent = Agent;
8414
8507
  exports.AnthropicCompatClient = AnthropicCompatClient;
8415
8508
  exports.AnthropicMessagesStream = AnthropicMessagesStream;
8509
+ exports.CLOUD_MODEL_MIN_OLLAMA_VERSION = CLOUD_MODEL_MIN_OLLAMA_VERSION;
8510
+ exports.CLOUD_MODEL_SUFFIX = CLOUD_MODEL_SUFFIX;
8416
8511
  exports.ConversationSession = ConversationSession;
8417
8512
  exports.DEFAULT_BACKOFF = DEFAULT_BACKOFF;
8418
8513
  exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
@@ -8451,6 +8546,7 @@ exports.OllamaAuthError = OllamaAuthError;
8451
8546
  exports.OllamaBadGatewayError = OllamaBadGatewayError;
8452
8547
  exports.OllamaClient = OllamaClient;
8453
8548
  exports.OllamaClientError = OllamaClientError;
8549
+ exports.OllamaCloudModelVersionError = OllamaCloudModelVersionError;
8454
8550
  exports.OllamaGenericClientError = OllamaGenericClientError;
8455
8551
  exports.OllamaIncompatibleModelError = OllamaIncompatibleModelError;
8456
8552
  exports.OllamaMcpError = OllamaMcpError;
@@ -8496,6 +8592,7 @@ exports.checkEndpointHealth = checkEndpointHealth;
8496
8592
  exports.checkGenerateContext = checkGenerateContext;
8497
8593
  exports.compactConversationHistory = compactConversationHistory;
8498
8594
  exports.compareDraftPerformance = compareDraftPerformance;
8595
+ exports.compareOllamaVersions = compareOllamaVersions;
8499
8596
  exports.composeMiddleware = composeMiddleware;
8500
8597
  exports.computeProgressPercent = computeProgressPercent;
8501
8598
  exports.contextWarningMessage = contextWarningMessage;
@@ -8528,6 +8625,7 @@ exports.formatWebFetchResult = formatWebFetchResult;
8528
8625
  exports.formatWebSearchResult = formatWebSearchResult;
8529
8626
  exports.imageStringNeedsResolution = imageStringNeedsResolution;
8530
8627
  exports.inferRuntimeMode = inferRuntimeMode;
8628
+ exports.isCloudModel = isCloudModel;
8531
8629
  exports.isKeepAliveSugar = isKeepAliveSugar;
8532
8630
  exports.isKnownDoneReason = isKnownDoneReason;
8533
8631
  exports.isModelResident = isModelResident;