@nemesis-oss/ollama-sdk 1.19.1 → 1.20.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 +53 -0
- package/dist/{anthropic-Bf16hGLL.d.cts → anthropic-BFOC6eI7.d.ts} +7 -1
- package/dist/{anthropic-BmFk4Pjq.d.ts → anthropic-C2-qaxjI.d.cts} +7 -1
- package/dist/{compose-C4QxEZOS.d.cts → compose-BXXgHmrS.d.cts} +1 -1
- package/dist/{compose-75UFDzOO.d.ts → compose-DaG83yId.d.ts} +1 -1
- package/dist/generated-api.cjs +1 -1
- package/dist/generated-api.cjs.map +1 -1
- package/dist/generated-api.d.cts +7 -7
- package/dist/generated-api.d.ts +7 -7
- package/dist/generated-api.js +1 -1
- package/dist/generated-api.js.map +1 -1
- package/dist/generated-models-schemas.cjs +25 -2
- package/dist/generated-models-schemas.cjs.map +1 -1
- package/dist/generated-models-schemas.d.cts +97 -5
- package/dist/generated-models-schemas.d.ts +97 -5
- package/dist/generated-models-schemas.js +24 -3
- package/dist/generated-models-schemas.js.map +1 -1
- package/dist/generated-runtime.cjs +23 -2
- 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 +23 -2
- package/dist/generated-runtime.js.map +1 -1
- package/dist/index.cjs +126 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +112 -17
- package/dist/index.d.ts +112 -17
- package/dist/index.js +122 -22
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +1 -1
- package/dist/mcp-generated.cjs +1 -1
- 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 +1 -1
- package/dist/mcp-generated.js.map +1 -1
- package/dist/{runtime-CjCriL5A.d.cts → runtime-CpO3H6yy.d.cts} +27 -2
- package/dist/{runtime-EwyUaNnZ.d.ts → runtime-DPSrPwAa.d.ts} +27 -2
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -3
- package/dist/skills.d.ts +3 -3
- package/dist/skills.js.map +1 -1
- package/dist/{types-Y3u0FtdN.d.cts → types-CnsZ24tm.d.cts} +17 -1
- package/dist/{types-Y3u0FtdN.d.ts → types-CnsZ24tm.d.ts} +17 -1
- 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) {
|
|
@@ -1597,16 +1608,23 @@ async function checkEndpointHealth(endpoint, fetchImpl, timeoutMs = 5e3, middlew
|
|
|
1597
1608
|
|
|
1598
1609
|
// src/capabilities/capabilities.ts
|
|
1599
1610
|
function inferRuntimeMode(baseUrl) {
|
|
1611
|
+
let host;
|
|
1600
1612
|
try {
|
|
1601
|
-
|
|
1602
|
-
const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
1603
|
-
if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".local") || host.startsWith("192.168.") || host.startsWith("10.")) {
|
|
1604
|
-
return "local";
|
|
1605
|
-
}
|
|
1606
|
-
return "cloud";
|
|
1613
|
+
host = new URL(baseUrl).hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
1607
1614
|
} catch {
|
|
1608
1615
|
return "unknown";
|
|
1609
1616
|
}
|
|
1617
|
+
if (host === "ollama.com" || host.endsWith(".ollama.com")) return "cloud";
|
|
1618
|
+
if (isPrivateNetworkHost(host)) return "local";
|
|
1619
|
+
return "unknown";
|
|
1620
|
+
}
|
|
1621
|
+
function isPrivateNetworkHost(host) {
|
|
1622
|
+
if (!host.includes(".") && !host.includes(":")) return true;
|
|
1623
|
+
if (host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal"))
|
|
1624
|
+
return true;
|
|
1625
|
+
if (host === "::1" || host === "0.0.0.0") return true;
|
|
1626
|
+
if (host.includes(":") && /^f[cd][0-9a-f]{0,2}:/.test(host)) return true;
|
|
1627
|
+
return /^(?:127|10)\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(host) || /^192\.168\.\d{1,3}\.\d{1,3}$/.test(host) || /^172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}$/.test(host);
|
|
1610
1628
|
}
|
|
1611
1629
|
function extractContextLength(modelInfo) {
|
|
1612
1630
|
if (!modelInfo) return void 0;
|
|
@@ -4233,6 +4251,9 @@ var ShowResponseSchema = zod.z.object({
|
|
|
4233
4251
|
modified_at: zod.z.string().optional(),
|
|
4234
4252
|
details: zod.z.object({}).optional(),
|
|
4235
4253
|
template: zod.z.string().optional(),
|
|
4254
|
+
renderer: zod.z.string().optional(),
|
|
4255
|
+
parser: zod.z.string().optional(),
|
|
4256
|
+
template_source: zod.z.string().optional(),
|
|
4236
4257
|
capabilities: zod.z.array(zod.z.string()).optional(),
|
|
4237
4258
|
model_info: zod.z.object({}).optional()
|
|
4238
4259
|
});
|
|
@@ -4324,9 +4345,26 @@ var UsageMetricsSchema = zod.z.object({
|
|
|
4324
4345
|
output_tokens: zod.z.number().optional()
|
|
4325
4346
|
});
|
|
4326
4347
|
|
|
4348
|
+
// src/generated/models/UsageGroup.schema.ts
|
|
4349
|
+
var UsageGroupSchema = zod.z.intersection(
|
|
4350
|
+
UsageMetricsSchema,
|
|
4351
|
+
zod.z.object({
|
|
4352
|
+
model: zod.z.string()
|
|
4353
|
+
})
|
|
4354
|
+
);
|
|
4355
|
+
|
|
4356
|
+
// src/generated/models/UsageSummary.schema.ts
|
|
4357
|
+
var UsageSummarySchema = zod.z.intersection(
|
|
4358
|
+
UsageMetricsSchema,
|
|
4359
|
+
zod.z.object({
|
|
4360
|
+
groups: zod.z.array(UsageGroupSchema).optional(),
|
|
4361
|
+
remainder: UsageMetricsSchema.optional()
|
|
4362
|
+
})
|
|
4363
|
+
);
|
|
4364
|
+
|
|
4327
4365
|
// src/generated/models/UsageBucket.schema.ts
|
|
4328
4366
|
var UsageBucketSchema = zod.z.intersection(
|
|
4329
|
-
|
|
4367
|
+
UsageSummarySchema,
|
|
4330
4368
|
zod.z.object({
|
|
4331
4369
|
from: zod.z.string(),
|
|
4332
4370
|
until: zod.z.string(),
|
|
@@ -4339,9 +4377,10 @@ var UsageResponseSchema = zod.z.object({
|
|
|
4339
4377
|
range: zod.z.enum(["24h", "7d", "30d"]),
|
|
4340
4378
|
scope: zod.z.enum(["self", "team"]),
|
|
4341
4379
|
granularity: zod.z.enum(["hour", "day"]),
|
|
4380
|
+
group_by: zod.z.enum(["model"]).optional(),
|
|
4342
4381
|
from: zod.z.string(),
|
|
4343
4382
|
until: zod.z.string(),
|
|
4344
|
-
totals:
|
|
4383
|
+
totals: UsageSummarySchema,
|
|
4345
4384
|
buckets: zod.z.array(UsageBucketSchema)
|
|
4346
4385
|
});
|
|
4347
4386
|
var VersionResponseSchema = zod.z.object({
|
|
@@ -5784,6 +5823,29 @@ function createDecision(client) {
|
|
|
5784
5823
|
};
|
|
5785
5824
|
}
|
|
5786
5825
|
|
|
5826
|
+
// src/system-one.ts
|
|
5827
|
+
var MAX_SYSTEM_ONE_IMAGES_BYTES = 32 * 1024 * 1024;
|
|
5828
|
+
var MAX_SYSTEM_ONE_REQUEST_BYTES = 64 * 1024;
|
|
5829
|
+
var CLOUD_MODEL_SUFFIX = ":cloud";
|
|
5830
|
+
var CLOUD_MODEL_MIN_OLLAMA_VERSION = "0.40.5";
|
|
5831
|
+
function isCloudModel(model) {
|
|
5832
|
+
return model.endsWith(CLOUD_MODEL_SUFFIX);
|
|
5833
|
+
}
|
|
5834
|
+
function compareOllamaVersions(a, b) {
|
|
5835
|
+
const pa = a.split(".").map((s) => Number.parseInt(s, 10) || 0);
|
|
5836
|
+
const pb = b.split(".").map((s) => Number.parseInt(s, 10) || 0);
|
|
5837
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
|
|
5838
|
+
const va = pa[i] ?? 0;
|
|
5839
|
+
const vb = pb[i] ?? 0;
|
|
5840
|
+
if (va !== vb) return va - vb;
|
|
5841
|
+
}
|
|
5842
|
+
return 0;
|
|
5843
|
+
}
|
|
5844
|
+
function estimateSystemOneRequestBytes(request, options) {
|
|
5845
|
+
const body = options?.excludeImages && request.images !== void 0 ? { ...request, images: void 0 } : request;
|
|
5846
|
+
return new TextEncoder().encode(JSON.stringify(body)).byteLength;
|
|
5847
|
+
}
|
|
5848
|
+
|
|
5787
5849
|
// src/client.ts
|
|
5788
5850
|
var logicalRequestSequence = 0;
|
|
5789
5851
|
function createLogicalRequestId() {
|
|
@@ -6410,9 +6472,13 @@ var OllamaClient = class _OllamaClient {
|
|
|
6410
6472
|
* launch): `model` also accepts cloud models such as `clef:cloud` —
|
|
6411
6473
|
* cloud models require Ollama >= 0.40.5 or the hosted
|
|
6412
6474
|
* `https://ollama.com` endpoint. Requires Ollama >= 0.35.0 locally.
|
|
6413
|
-
*
|
|
6475
|
+
* Both version constraints are enforced client-side before the request
|
|
6476
|
+
* is sent: the blanket 0.35.0 floor by the generated runtime (lazily
|
|
6414
6477
|
* fetching `/api/version` when `enforceVersion` is `'auto'` or
|
|
6415
|
-
* `'strict'`)
|
|
6478
|
+
* `'strict'`), and the model-dependent 0.40.5 cloud gate by this
|
|
6479
|
+
* wrapper — a cloud model through a local server older than 0.40.5
|
|
6480
|
+
* throws {@link OllamaCloudModelVersionError} without a round-trip
|
|
6481
|
+
* (ADR 0036). Request size is checked client-side as a dual cap:
|
|
6416
6482
|
* text and schema (images excluded) within 64 KiB AND the whole
|
|
6417
6483
|
* request within 32 MiB.
|
|
6418
6484
|
*
|
|
@@ -6437,10 +6503,44 @@ var OllamaClient = class _OllamaClient {
|
|
|
6437
6503
|
* `client.native.systemOne(request)` directly.
|
|
6438
6504
|
*/
|
|
6439
6505
|
async systemOne(request) {
|
|
6506
|
+
await this.assertCloudModelSupported(request.model);
|
|
6440
6507
|
return this.native.systemOne(
|
|
6441
6508
|
request
|
|
6442
6509
|
);
|
|
6443
6510
|
}
|
|
6511
|
+
/**
|
|
6512
|
+
* Cloud-model version gate for {@link systemOne} — throws
|
|
6513
|
+
* {@link OllamaCloudModelVersionError} when a cloud model is requested
|
|
6514
|
+
* through a local server older than {@link CLOUD_MODEL_MIN_OLLAMA_VERSION}
|
|
6515
|
+
* (0.40.5). No-op for non-cloud models and for cloud-mode clients
|
|
6516
|
+
* (hosted `ollama.com`). The `/api/version` probe goes through the normal
|
|
6517
|
+
* failover machinery and is cached per client instance (reset on failure,
|
|
6518
|
+
* so a later gated call retries), so at most one extra round-trip happens
|
|
6519
|
+
* across all gated calls.
|
|
6520
|
+
*/
|
|
6521
|
+
async assertCloudModelSupported(model) {
|
|
6522
|
+
if (!isCloudModel(model)) return;
|
|
6523
|
+
const candidates = this.registry.candidates();
|
|
6524
|
+
const baseUrl = candidates[0]?.baseUrl ?? DEFAULT_BASE_URL;
|
|
6525
|
+
if (inferRuntimeMode(baseUrl) !== "local") return;
|
|
6526
|
+
let version;
|
|
6527
|
+
try {
|
|
6528
|
+
if (this.serverVersionCache === void 0) {
|
|
6529
|
+
this.serverVersionCache = this.native.version().then((v) => v.version);
|
|
6530
|
+
}
|
|
6531
|
+
version = await this.serverVersionCache;
|
|
6532
|
+
} catch {
|
|
6533
|
+
this.serverVersionCache = void 0;
|
|
6534
|
+
return;
|
|
6535
|
+
}
|
|
6536
|
+
if (version && compareOllamaVersions(version, CLOUD_MODEL_MIN_OLLAMA_VERSION) < 0) {
|
|
6537
|
+
throw new OllamaCloudModelVersionError(
|
|
6538
|
+
`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.`,
|
|
6539
|
+
{ model, serverVersion: version, minRequiredVersion: CLOUD_MODEL_MIN_OLLAMA_VERSION }
|
|
6540
|
+
);
|
|
6541
|
+
}
|
|
6542
|
+
}
|
|
6543
|
+
serverVersionCache;
|
|
6444
6544
|
// --- Web Endpoints ---
|
|
6445
6545
|
/**
|
|
6446
6546
|
* Ollama's hosted web search tool (`POST https://ollama.com/api/web_search`) — a fixed
|
|
@@ -6485,13 +6585,20 @@ var OllamaClient = class _OllamaClient {
|
|
|
6485
6585
|
* endpoint's 429 with a `Retry-After` header ("Seconds to wait before retrying"),
|
|
6486
6586
|
* which the SDK parses into `OllamaRateLimitError.retryAfterMs` and honors verbatim
|
|
6487
6587
|
* when retrying. Query parameters mirror the official endpoint: `range`
|
|
6488
|
-
* (`'24h' | '7d' | '30d'`, server default `'7d'`)
|
|
6489
|
-
* (`'self' | 'team'`, server default `'self'`; team scope requires a team
|
|
6588
|
+
* (`'24h' | '7d' | '30d'`, server default `'7d'`), `scope`
|
|
6589
|
+
* (`'self' | 'team'`, server default `'self'`; team scope requires a team
|
|
6590
|
+
* admin), and — since the 2026-10-22 pin (upstream 2476d5e) — `groupBy`
|
|
6591
|
+
* (`group_by=model`), which makes `totals` and every bucket carry up to 10
|
|
6592
|
+
* per-model `UsageGroup` entries plus a `remainder` roll-up, with the
|
|
6593
|
+
* selection echoed back as `group_by` on the response.
|
|
6490
6594
|
* Omitted options are left unset so the server applies its own defaults.
|
|
6491
6595
|
*
|
|
6492
6596
|
* ```ts
|
|
6493
|
-
* const usage = await client.usage({ range: '24h' });
|
|
6597
|
+
* const usage = await client.usage({ range: '24h', groupBy: 'model' });
|
|
6494
6598
|
* console.log(usage.totals.request_count, usage.totals.usage_usd);
|
|
6599
|
+
* for (const group of usage.totals.groups ?? []) {
|
|
6600
|
+
* console.log(group.model, group.usage_usd);
|
|
6601
|
+
* }
|
|
6495
6602
|
* for (const bucket of usage.buckets) {
|
|
6496
6603
|
* if (bucket.partial) continue; // current hour, still in progress
|
|
6497
6604
|
* // ...
|
|
@@ -6502,6 +6609,7 @@ var OllamaClient = class _OllamaClient {
|
|
|
6502
6609
|
const params = new URLSearchParams();
|
|
6503
6610
|
if (req.range !== void 0) params.set("range", req.range);
|
|
6504
6611
|
if (req.scope !== void 0) params.set("scope", req.scope);
|
|
6612
|
+
if (req.groupBy !== void 0) params.set("group_by", req.groupBy);
|
|
6505
6613
|
const query = params.toString();
|
|
6506
6614
|
return this.executeCloudRequest(
|
|
6507
6615
|
(http, signal) => http.request({
|
|
@@ -8385,14 +8493,6 @@ function createModelAffinityScheduler(client, options) {
|
|
|
8385
8493
|
return new ModelAffinityScheduler(client, options);
|
|
8386
8494
|
}
|
|
8387
8495
|
|
|
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
8496
|
exports.ATTR_GEN_AI_OPERATION_NAME = ATTR_GEN_AI_OPERATION_NAME;
|
|
8397
8497
|
exports.ATTR_GEN_AI_REQUEST_MODEL = ATTR_GEN_AI_REQUEST_MODEL;
|
|
8398
8498
|
exports.ATTR_GEN_AI_RESPONSE_MODEL = ATTR_GEN_AI_RESPONSE_MODEL;
|
|
@@ -8413,6 +8513,8 @@ exports.ATTR_URL_FULL = ATTR_URL_FULL;
|
|
|
8413
8513
|
exports.Agent = Agent;
|
|
8414
8514
|
exports.AnthropicCompatClient = AnthropicCompatClient;
|
|
8415
8515
|
exports.AnthropicMessagesStream = AnthropicMessagesStream;
|
|
8516
|
+
exports.CLOUD_MODEL_MIN_OLLAMA_VERSION = CLOUD_MODEL_MIN_OLLAMA_VERSION;
|
|
8517
|
+
exports.CLOUD_MODEL_SUFFIX = CLOUD_MODEL_SUFFIX;
|
|
8416
8518
|
exports.ConversationSession = ConversationSession;
|
|
8417
8519
|
exports.DEFAULT_BACKOFF = DEFAULT_BACKOFF;
|
|
8418
8520
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
@@ -8451,6 +8553,7 @@ exports.OllamaAuthError = OllamaAuthError;
|
|
|
8451
8553
|
exports.OllamaBadGatewayError = OllamaBadGatewayError;
|
|
8452
8554
|
exports.OllamaClient = OllamaClient;
|
|
8453
8555
|
exports.OllamaClientError = OllamaClientError;
|
|
8556
|
+
exports.OllamaCloudModelVersionError = OllamaCloudModelVersionError;
|
|
8454
8557
|
exports.OllamaGenericClientError = OllamaGenericClientError;
|
|
8455
8558
|
exports.OllamaIncompatibleModelError = OllamaIncompatibleModelError;
|
|
8456
8559
|
exports.OllamaMcpError = OllamaMcpError;
|
|
@@ -8496,6 +8599,7 @@ exports.checkEndpointHealth = checkEndpointHealth;
|
|
|
8496
8599
|
exports.checkGenerateContext = checkGenerateContext;
|
|
8497
8600
|
exports.compactConversationHistory = compactConversationHistory;
|
|
8498
8601
|
exports.compareDraftPerformance = compareDraftPerformance;
|
|
8602
|
+
exports.compareOllamaVersions = compareOllamaVersions;
|
|
8499
8603
|
exports.composeMiddleware = composeMiddleware;
|
|
8500
8604
|
exports.computeProgressPercent = computeProgressPercent;
|
|
8501
8605
|
exports.contextWarningMessage = contextWarningMessage;
|
|
@@ -8528,6 +8632,7 @@ exports.formatWebFetchResult = formatWebFetchResult;
|
|
|
8528
8632
|
exports.formatWebSearchResult = formatWebSearchResult;
|
|
8529
8633
|
exports.imageStringNeedsResolution = imageStringNeedsResolution;
|
|
8530
8634
|
exports.inferRuntimeMode = inferRuntimeMode;
|
|
8635
|
+
exports.isCloudModel = isCloudModel;
|
|
8531
8636
|
exports.isKeepAliveSugar = isKeepAliveSugar;
|
|
8532
8637
|
exports.isKnownDoneReason = isKnownDoneReason;
|
|
8533
8638
|
exports.isModelResident = isModelResident;
|