@nemesis-oss/ollama-sdk 1.1.0 → 1.4.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 +43 -92
- package/README.md +749 -11
- package/dist/compose-BR70yb4W.d.cts +164 -0
- package/dist/compose-DfAqKAFj.d.ts +164 -0
- package/dist/generated-api.cjs +454 -0
- package/dist/generated-api.cjs.map +1 -0
- package/dist/generated-api.d.cts +1651 -0
- package/dist/generated-api.d.ts +1651 -0
- package/dist/generated-api.js +428 -0
- package/dist/generated-api.js.map +1 -0
- package/dist/generated-models-schemas.cjs +328 -0
- package/dist/generated-models-schemas.cjs.map +1 -0
- package/dist/generated-models-schemas.d.cts +463 -0
- package/dist/generated-models-schemas.d.ts +463 -0
- package/dist/generated-models-schemas.js +291 -0
- package/dist/generated-models-schemas.js.map +1 -0
- package/dist/generated-runtime.cjs +145 -0
- package/dist/generated-runtime.cjs.map +1 -0
- package/dist/generated-runtime.d.cts +2 -0
- package/dist/generated-runtime.d.ts +2 -0
- package/dist/generated-runtime.js +143 -0
- package/dist/generated-runtime.js.map +1 -0
- package/dist/index-2RIErNT5.d.cts +583 -0
- package/dist/index-DIQ8NUbU.d.ts +583 -0
- package/dist/index.cjs +2308 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1123 -421
- package/dist/index.d.ts +1123 -421
- package/dist/index.js +2293 -185
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +1058 -0
- package/dist/mcp-generated.cjs +386 -0
- package/dist/mcp-generated.cjs.map +1 -0
- package/dist/mcp-generated.d.cts +35 -0
- package/dist/mcp-generated.d.ts +35 -0
- package/dist/mcp-generated.js +381 -0
- package/dist/mcp-generated.js.map +1 -0
- package/dist/mcp-http.cjs +100 -0
- package/dist/mcp-http.cjs.map +1 -0
- package/dist/mcp-http.d.cts +48 -0
- package/dist/mcp-http.d.ts +48 -0
- package/dist/mcp-http.js +96 -0
- package/dist/mcp-http.js.map +1 -0
- package/dist/mcp-stdio.cjs +49 -0
- package/dist/mcp-stdio.cjs.map +1 -0
- package/dist/mcp-stdio.d.cts +34 -0
- package/dist/mcp-stdio.d.ts +34 -0
- package/dist/mcp-stdio.js +47 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -2
- package/dist/skills.d.ts +3 -2
- package/dist/skills.js.map +1 -1
- package/dist/types-B9_axjum.d.cts +66 -0
- package/dist/types-B9_axjum.d.ts +66 -0
- package/dist/{compose-DJjVpDrk.d.cts → types-BQhgW-du.d.cts} +118 -172
- package/dist/{compose-DJjVpDrk.d.ts → types-BQhgW-du.d.ts} +118 -172
- package/package.json +96 -5
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Core protocol and message types for the Ollama REST API.
|
|
5
3
|
*/
|
|
6
4
|
type Role = 'system' | 'user' | 'assistant' | 'tool' | 'thought';
|
|
5
|
+
/** Ollama native thinking control: booleans, null for model default, or model-defined levels. */
|
|
6
|
+
type ThinkValue = boolean | string | null;
|
|
7
|
+
/** Thinking capability metadata returned by `/api/show`. */
|
|
8
|
+
interface ThinkingMetadata {
|
|
9
|
+
readonly values: readonly (boolean | string)[];
|
|
10
|
+
readonly default?: boolean | string | null | undefined;
|
|
11
|
+
}
|
|
7
12
|
interface ToolCallFunction {
|
|
8
13
|
readonly name: string;
|
|
9
14
|
readonly arguments: Record<string, unknown>;
|
|
@@ -35,7 +40,16 @@ interface Message {
|
|
|
35
40
|
*/
|
|
36
41
|
readonly images?: readonly (string | Uint8Array)[] | undefined;
|
|
37
42
|
readonly tool_calls?: readonly ToolCall[] | undefined;
|
|
38
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Ollama's native `/api/chat` field identifying which tool produced this result.
|
|
45
|
+
* For `role: 'tool'` messages this should be the registered tool's name.
|
|
46
|
+
*/
|
|
47
|
+
readonly tool_name?: string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated SDK-local correlation metadata only. Ollama's native `/api/chat` protocol
|
|
50
|
+
* does not use `tool_call_id`; native requests strip this field before transmission.
|
|
51
|
+
* OpenAI compatibility uses its own `OpenAIMessage.tool_call_id` type.
|
|
52
|
+
*/
|
|
39
53
|
readonly tool_call_id?: string | undefined;
|
|
40
54
|
readonly thinking?: string | undefined;
|
|
41
55
|
}
|
|
@@ -46,25 +60,47 @@ interface ToolProperty {
|
|
|
46
60
|
readonly items?: Record<string, unknown> | undefined;
|
|
47
61
|
readonly properties?: Record<string, unknown> | undefined;
|
|
48
62
|
readonly required?: readonly string[] | undefined;
|
|
63
|
+
/** Additional JSON Schema keywords are preserved for MCP/provider interoperability. */
|
|
64
|
+
readonly [keyword: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
interface ToolParameters {
|
|
67
|
+
readonly type: 'object';
|
|
68
|
+
readonly properties: Record<string, ToolProperty>;
|
|
69
|
+
readonly required?: readonly string[] | undefined;
|
|
70
|
+
/** Additional JSON Schema keywords such as $defs, anyOf, allOf, and additionalProperties. */
|
|
71
|
+
readonly [keyword: string]: unknown;
|
|
49
72
|
}
|
|
50
73
|
interface ToolFunctionDefinition {
|
|
51
74
|
readonly name: string;
|
|
52
75
|
readonly description: string;
|
|
53
|
-
readonly parameters:
|
|
54
|
-
readonly type: 'object';
|
|
55
|
-
readonly properties: Record<string, ToolProperty>;
|
|
56
|
-
readonly required?: readonly string[] | undefined;
|
|
57
|
-
};
|
|
76
|
+
readonly parameters: ToolParameters;
|
|
58
77
|
}
|
|
59
78
|
interface ToolDefinition {
|
|
60
79
|
readonly type: 'function';
|
|
61
80
|
readonly function: ToolFunctionDefinition;
|
|
62
81
|
}
|
|
63
82
|
type FormatOption = 'json' | Record<string, unknown>;
|
|
83
|
+
/** One alternative token considered at a generated position, and its log probability. */
|
|
84
|
+
interface LogprobToken {
|
|
85
|
+
readonly token: string;
|
|
86
|
+
readonly logprob: number;
|
|
87
|
+
readonly bytes?: readonly number[] | undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Log probability info for one generated token, returned when `logprobs: true` is set on
|
|
91
|
+
* a `/api/chat` or `/api/generate` request. `top_logprobs` holds the `top_logprobs` most
|
|
92
|
+
* likely alternative tokens considered at this position (see `top_logprobs` on
|
|
93
|
+
* {@link ChatRequestOptions}/{@link GenerateRequestOptions}).
|
|
94
|
+
*/
|
|
95
|
+
interface Logprob extends LogprobToken {
|
|
96
|
+
readonly top_logprobs?: readonly LogprobToken[] | undefined;
|
|
97
|
+
}
|
|
64
98
|
interface ModelOptions {
|
|
65
99
|
readonly num_keep?: number | undefined;
|
|
66
100
|
readonly seed?: number | undefined;
|
|
67
101
|
readonly num_predict?: number | undefined;
|
|
102
|
+
/** Number of tokens to predict with a draft/speculative model, when supported. */
|
|
103
|
+
readonly draft_num_predict?: number | undefined;
|
|
68
104
|
readonly top_k?: number | undefined;
|
|
69
105
|
readonly top_p?: number | undefined;
|
|
70
106
|
readonly min_p?: number | undefined;
|
|
@@ -103,7 +139,21 @@ interface ChatRequestOptions extends RequestCancellationOptions {
|
|
|
103
139
|
readonly options?: ModelOptions | undefined;
|
|
104
140
|
readonly stream?: boolean | undefined;
|
|
105
141
|
readonly keep_alive?: string | number | undefined;
|
|
106
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Controls thinking output. Use `client.capabilities(model).thinking` to discover
|
|
144
|
+
* model-defined string levels and the model default.
|
|
145
|
+
*/
|
|
146
|
+
readonly think?: ThinkValue | undefined;
|
|
147
|
+
/** Experimental image-generation width in pixels. */
|
|
148
|
+
readonly width?: number | undefined;
|
|
149
|
+
/** Experimental image-generation height in pixels. */
|
|
150
|
+
readonly height?: number | undefined;
|
|
151
|
+
/** Experimental image-generation diffusion steps. */
|
|
152
|
+
readonly steps?: number | undefined;
|
|
153
|
+
/** Whether to return log probabilities of the output tokens. See {@link ChatResponse.logprobs}. */
|
|
154
|
+
readonly logprobs?: boolean | undefined;
|
|
155
|
+
/** Number of most likely alternative tokens to return at each position. Requires `logprobs: true`. */
|
|
156
|
+
readonly top_logprobs?: number | undefined;
|
|
107
157
|
}
|
|
108
158
|
interface ChatResponse {
|
|
109
159
|
readonly model: string;
|
|
@@ -114,9 +164,13 @@ interface ChatResponse {
|
|
|
114
164
|
readonly total_duration?: number | undefined;
|
|
115
165
|
readonly load_duration?: number | undefined;
|
|
116
166
|
readonly prompt_eval_count?: number | undefined;
|
|
167
|
+
/** Number of prompt tokens read from the KV cache. */
|
|
168
|
+
readonly prompt_eval_cached_count?: number | undefined;
|
|
117
169
|
readonly prompt_eval_duration?: number | undefined;
|
|
118
170
|
readonly eval_count?: number | undefined;
|
|
119
171
|
readonly eval_duration?: number | undefined;
|
|
172
|
+
/** Present when the request set `logprobs: true`. */
|
|
173
|
+
readonly logprobs?: readonly Logprob[] | undefined;
|
|
120
174
|
}
|
|
121
175
|
interface GenerateRequestOptions extends RequestCancellationOptions {
|
|
122
176
|
readonly model: string;
|
|
@@ -136,7 +190,17 @@ interface GenerateRequestOptions extends RequestCancellationOptions {
|
|
|
136
190
|
readonly images?: readonly (string | Uint8Array)[] | undefined;
|
|
137
191
|
readonly options?: ModelOptions | undefined;
|
|
138
192
|
readonly keep_alive?: string | number | undefined;
|
|
139
|
-
readonly think?:
|
|
193
|
+
readonly think?: ThinkValue | undefined;
|
|
194
|
+
/** Whether to return log probabilities of the output tokens. See {@link GenerateResponse.logprobs}. */
|
|
195
|
+
readonly logprobs?: boolean | undefined;
|
|
196
|
+
/** Number of most likely alternative tokens to return at each position. Requires `logprobs: true`. */
|
|
197
|
+
readonly top_logprobs?: number | undefined;
|
|
198
|
+
/** Experimental image-generation width in pixels. */
|
|
199
|
+
readonly width?: number | undefined;
|
|
200
|
+
/** Experimental image-generation height in pixels. */
|
|
201
|
+
readonly height?: number | undefined;
|
|
202
|
+
/** Experimental image-generation diffusion steps. */
|
|
203
|
+
readonly steps?: number | undefined;
|
|
140
204
|
}
|
|
141
205
|
interface GenerateResponse {
|
|
142
206
|
readonly model: string;
|
|
@@ -148,10 +212,20 @@ interface GenerateResponse {
|
|
|
148
212
|
readonly total_duration?: number | undefined;
|
|
149
213
|
readonly load_duration?: number | undefined;
|
|
150
214
|
readonly prompt_eval_count?: number | undefined;
|
|
215
|
+
/** Number of prompt tokens read from the KV cache. */
|
|
216
|
+
readonly prompt_eval_cached_count?: number | undefined;
|
|
151
217
|
readonly prompt_eval_duration?: number | undefined;
|
|
152
218
|
readonly eval_count?: number | undefined;
|
|
153
219
|
readonly eval_duration?: number | undefined;
|
|
154
220
|
readonly thinking?: string | undefined;
|
|
221
|
+
/** Present when the request set `logprobs: true`. */
|
|
222
|
+
readonly logprobs?: readonly Logprob[] | undefined;
|
|
223
|
+
/** Base64-encoded generated image data for image-generation models. */
|
|
224
|
+
readonly image?: string | undefined;
|
|
225
|
+
/** Number of completed image-generation steps. */
|
|
226
|
+
readonly completed?: number | undefined;
|
|
227
|
+
/** Total image-generation steps. */
|
|
228
|
+
readonly total?: number | undefined;
|
|
155
229
|
}
|
|
156
230
|
interface EmbedRequestOptions extends RequestCancellationOptions {
|
|
157
231
|
readonly model: string;
|
|
@@ -195,6 +269,8 @@ interface ModelResponse {
|
|
|
195
269
|
readonly details: ModelDetails;
|
|
196
270
|
readonly expires_at?: string | undefined;
|
|
197
271
|
readonly size_vram?: number | undefined;
|
|
272
|
+
/** Context window length reported for currently running models by /api/ps. */
|
|
273
|
+
readonly context_length?: number | undefined;
|
|
198
274
|
}
|
|
199
275
|
interface ListResponse {
|
|
200
276
|
readonly models: readonly ModelResponse[];
|
|
@@ -215,6 +291,8 @@ interface ShowResponse {
|
|
|
215
291
|
readonly messages?: readonly Message[] | undefined;
|
|
216
292
|
readonly model_info?: Record<string, unknown> | undefined;
|
|
217
293
|
readonly capabilities?: readonly string[] | undefined;
|
|
294
|
+
/** Model-defined thinking levels and default, when reported by Ollama. */
|
|
295
|
+
readonly thinking?: ThinkingMetadata | undefined;
|
|
218
296
|
readonly modified_at?: string | undefined;
|
|
219
297
|
}
|
|
220
298
|
interface ProgressResponse {
|
|
@@ -247,8 +325,12 @@ interface CreateRequestOptions extends RequestCancellationOptions {
|
|
|
247
325
|
readonly modelfile?: string | undefined;
|
|
248
326
|
readonly stream?: boolean | undefined;
|
|
249
327
|
readonly quantize?: string | undefined;
|
|
328
|
+
/** Quantization level to apply to draft weights during import. */
|
|
329
|
+
readonly draft_quantize?: string | undefined;
|
|
250
330
|
readonly from?: string | undefined;
|
|
251
331
|
readonly files?: Record<string, string> | undefined;
|
|
332
|
+
/** Draft source file names mapped to their SHA-256 digests. */
|
|
333
|
+
readonly draft_files?: Record<string, string> | undefined;
|
|
252
334
|
readonly adapters?: Record<string, string> | undefined;
|
|
253
335
|
readonly template?: string | undefined;
|
|
254
336
|
readonly renderer?: string | undefined;
|
|
@@ -258,6 +340,8 @@ interface CreateRequestOptions extends RequestCancellationOptions {
|
|
|
258
340
|
/** Modelfile `PARAMETER` instructions, e.g. `{ temperature: 0.7, stop: ['\n'] }`. */
|
|
259
341
|
readonly parameters?: Record<string, unknown> | undefined;
|
|
260
342
|
readonly messages?: readonly Message[] | undefined;
|
|
343
|
+
/** Minimum Ollama version required by the model. */
|
|
344
|
+
readonly requires?: string | undefined;
|
|
261
345
|
}
|
|
262
346
|
interface DeleteRequestOptions extends RequestCancellationOptions {
|
|
263
347
|
readonly model: string;
|
|
@@ -275,183 +359,45 @@ interface VersionResponse {
|
|
|
275
359
|
interface PsResponse {
|
|
276
360
|
readonly models: readonly ModelResponse[];
|
|
277
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* `webSearch`/`webFetch` call Ollama's hosted web tools at `https://ollama.com` — a
|
|
364
|
+
* fixed cloud service, unrelated to any locally-configured `baseUrl`/`endpoints` — and
|
|
365
|
+
* require an Ollama account API key (`apiKey`/`OLLAMA_API_KEY`). See
|
|
366
|
+
* {@link OllamaClient.webSearch}.
|
|
367
|
+
*/
|
|
278
368
|
interface WebSearchRequestOptions extends RequestCancellationOptions {
|
|
279
369
|
readonly query: string;
|
|
370
|
+
/** Max results to return (server default 5, max 10). */
|
|
371
|
+
readonly max_results?: number | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* @deprecated Not a field the Ollama web search API recognizes (`max_results` is).
|
|
374
|
+
* Kept for backward compatibility with earlier (non-functional) versions of this
|
|
375
|
+
* method; mapped to `max_results` when `max_results` itself isn't set.
|
|
376
|
+
*/
|
|
280
377
|
readonly count?: number | undefined;
|
|
281
378
|
}
|
|
282
379
|
interface WebSearchResult {
|
|
283
380
|
readonly title: string;
|
|
284
381
|
readonly url: string;
|
|
285
|
-
readonly
|
|
382
|
+
readonly content: string;
|
|
383
|
+
/**
|
|
384
|
+
* @deprecated Not a field the Ollama web search API returns (`content` is) — kept, and
|
|
385
|
+
* populated by the SDK as a mirror of `content`, for backward compatibility with
|
|
386
|
+
* earlier (non-functional, wrong-endpoint) versions of `webSearch`. Use `content`.
|
|
387
|
+
*/
|
|
388
|
+
readonly snippet?: string | undefined;
|
|
286
389
|
}
|
|
287
390
|
interface WebSearchResponse {
|
|
288
391
|
readonly results: readonly WebSearchResult[];
|
|
289
392
|
}
|
|
393
|
+
/** See {@link WebSearchRequestOptions} — same fixed Ollama Cloud endpoint and auth. */
|
|
290
394
|
interface WebFetchRequestOptions extends RequestCancellationOptions {
|
|
291
395
|
readonly url: string;
|
|
292
396
|
}
|
|
293
397
|
interface WebFetchResponse {
|
|
398
|
+
readonly title?: string | undefined;
|
|
294
399
|
readonly content: string;
|
|
400
|
+
readonly links?: readonly string[] | undefined;
|
|
295
401
|
}
|
|
296
402
|
|
|
297
|
-
|
|
298
|
-
* Tool definition, handler, and execution types.
|
|
299
|
-
*/
|
|
300
|
-
|
|
301
|
-
interface ToolExecutionContext {
|
|
302
|
-
readonly signal?: AbortSignal | undefined;
|
|
303
|
-
}
|
|
304
|
-
type ToolHandler<TParams, TResult> = (params: TParams, context: ToolExecutionContext) => Promise<TResult> | TResult;
|
|
305
|
-
interface Tool<TParams = Record<string, unknown>, TResult = unknown> {
|
|
306
|
-
readonly name: string;
|
|
307
|
-
readonly description: string;
|
|
308
|
-
readonly schema: z.ZodType<TParams>;
|
|
309
|
-
readonly execute: ToolHandler<TParams, TResult>;
|
|
310
|
-
readonly definition: ToolDefinition;
|
|
311
|
-
/**
|
|
312
|
-
* Per-tool execution timeout in milliseconds, overriding the registry's default.
|
|
313
|
-
* Pass `0` to explicitly disable timeout enforcement for this tool.
|
|
314
|
-
*/
|
|
315
|
-
readonly timeoutMs?: number | undefined;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* A `Tool` of *any* parameter shape, for heterogeneous collections — i.e. what
|
|
319
|
-
* `ToolRegistry` stores and accepts.
|
|
320
|
-
*
|
|
321
|
-
* `Tool<TParams>` is **invariant** in `TParams`, because `TParams` appears both
|
|
322
|
-
* covariantly (`schema: z.ZodType<TParams>`) and contravariantly
|
|
323
|
-
* (`execute: ToolHandler<TParams, …>`). That makes `Tool<never, unknown>` — the obvious-
|
|
324
|
-
* looking "bottom" type for a mixed collection — assignable from *nothing*: a perfectly
|
|
325
|
-
* ordinary `Tool<{ city: string }, string>` from `defineTool` is rejected by it. `any` is
|
|
326
|
-
* the standard escape hatch for exactly this case, and it is confined to this one alias:
|
|
327
|
-
* `defineTool` still infers `TParams` from the Zod schema and still type-checks `execute`
|
|
328
|
-
* against it, so tool authoring keeps full type safety. Only the registry's *storage*
|
|
329
|
-
* type is widened, and the registry never does anything with a tool's params beyond
|
|
330
|
-
* handing `schema.safeParse`'s validated output straight back to that same tool's
|
|
331
|
-
* `execute`.
|
|
332
|
-
*/
|
|
333
|
-
type AnyTool = Tool<any, unknown>;
|
|
334
|
-
interface ToolExecutionSuccess {
|
|
335
|
-
readonly toolName: string;
|
|
336
|
-
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
337
|
-
readonly toolCallId?: string | undefined;
|
|
338
|
-
readonly success: true;
|
|
339
|
-
readonly result: unknown;
|
|
340
|
-
readonly outputString: string;
|
|
341
|
-
}
|
|
342
|
-
interface ToolExecutionFailure {
|
|
343
|
-
readonly toolName: string;
|
|
344
|
-
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
345
|
-
readonly toolCallId?: string | undefined;
|
|
346
|
-
readonly success: false;
|
|
347
|
-
readonly error: Error;
|
|
348
|
-
readonly outputString: string;
|
|
349
|
-
}
|
|
350
|
-
type ToolExecutionResult = ToolExecutionSuccess | ToolExecutionFailure;
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Tool registry for managing definitions and executing model tool calls.
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
interface ToolRegistryOptions {
|
|
357
|
-
readonly tools?: readonly AnyTool[] | undefined;
|
|
358
|
-
readonly onError?: ((error: Error, toolCall: ToolCall) => string) | undefined;
|
|
359
|
-
/**
|
|
360
|
-
* Default per-call execution timeout in milliseconds, applied to any tool that
|
|
361
|
-
* doesn't declare its own `timeoutMs`. Undefined (the default) means no timeout is
|
|
362
|
-
* enforced, matching prior behavior. Recommended whenever tool arguments or
|
|
363
|
-
* implementations are influenced by model output you don't fully control, since an
|
|
364
|
-
* unbounded tool call can otherwise stall the entire agent loop indefinitely.
|
|
365
|
-
*
|
|
366
|
-
* Enforcement is cooperative: it races the tool's promise against a timer and
|
|
367
|
-
* reports a timeout failure, but cannot forcibly halt synchronous or non-abort-aware
|
|
368
|
-
* asynchronous work already in flight on the same thread. Tools that perform I/O
|
|
369
|
-
* should honor `ToolExecutionContext.signal` to stop promptly on timeout.
|
|
370
|
-
*/
|
|
371
|
-
readonly timeoutMs?: number | undefined;
|
|
372
|
-
/**
|
|
373
|
-
* Maximum number of tool calls executed concurrently by `executeToolCalls`.
|
|
374
|
-
* Undefined (the default) runs all calls in parallel, matching prior behavior.
|
|
375
|
-
*/
|
|
376
|
-
readonly maxConcurrency?: number | undefined;
|
|
377
|
-
/**
|
|
378
|
-
* Maximum length of a tool's `outputString` before it is truncated. Guards against a
|
|
379
|
-
* single tool call flooding the conversation history / model context (and process
|
|
380
|
-
* memory) with unbounded output. Undefined (the default) applies no limit.
|
|
381
|
-
*/
|
|
382
|
-
readonly maxOutputChars?: number | undefined;
|
|
383
|
-
}
|
|
384
|
-
declare class ToolRegistry {
|
|
385
|
-
private readonly tools;
|
|
386
|
-
private readonly onError?;
|
|
387
|
-
private readonly defaultTimeoutMs?;
|
|
388
|
-
private readonly maxConcurrency?;
|
|
389
|
-
private readonly maxOutputChars?;
|
|
390
|
-
constructor(toolsOrOptions?: readonly AnyTool[] | ToolRegistryOptions | undefined);
|
|
391
|
-
register(tool: AnyTool): this;
|
|
392
|
-
registerMany(tools: readonly AnyTool[]): this;
|
|
393
|
-
get(name: string): AnyTool | undefined;
|
|
394
|
-
definitions(): ToolDefinition[];
|
|
395
|
-
executeToolCall(toolCall: ToolCall, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
396
|
-
private executeToolCallUninstrumented;
|
|
397
|
-
/**
|
|
398
|
-
* Executes every call in `toolCalls` and returns results in the same order, so results
|
|
399
|
-
* are always correlatable by array position regardless of `id`. Each result also echoes
|
|
400
|
-
* its call's `toolCallId` for callers who'd rather match by ID — see the {@link ToolCall}
|
|
401
|
-
* docs for how that id is produced. Runs fully in parallel (`Promise.all`) unless
|
|
402
|
-
* `maxConcurrency` was configured, in which case a bounded worker pool is used instead.
|
|
403
|
-
*/
|
|
404
|
-
executeToolCalls(toolCalls: readonly ToolCall[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
405
|
-
private runWithTimeout;
|
|
406
|
-
private truncateOutput;
|
|
407
|
-
private handleExecutionError;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* SKILL.md frontmatter and skill registry types.
|
|
412
|
-
*/
|
|
413
|
-
interface SkillFrontmatter {
|
|
414
|
-
readonly name: string;
|
|
415
|
-
readonly description: string;
|
|
416
|
-
readonly 'allowed-tools'?: readonly string[] | undefined;
|
|
417
|
-
readonly [key: string]: unknown;
|
|
418
|
-
}
|
|
419
|
-
interface SkillSummary {
|
|
420
|
-
readonly name: string;
|
|
421
|
-
readonly description: string;
|
|
422
|
-
readonly path: string;
|
|
423
|
-
}
|
|
424
|
-
interface Skill extends SkillSummary {
|
|
425
|
-
readonly frontmatter: SkillFrontmatter;
|
|
426
|
-
readonly body: string;
|
|
427
|
-
readonly allowedTools?: readonly string[] | undefined;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Lightweight frontmatter parser for SKILL.md files.
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
interface ParsedFrontmatter {
|
|
435
|
-
readonly frontmatter: SkillFrontmatter;
|
|
436
|
-
readonly body: string;
|
|
437
|
-
}
|
|
438
|
-
declare function parseFrontmatter(source: string, path?: string): ParsedFrontmatter;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Skill composition and context injection.
|
|
442
|
-
*/
|
|
443
|
-
|
|
444
|
-
interface ApplySkillOptions {
|
|
445
|
-
readonly messages: readonly Message[];
|
|
446
|
-
readonly tools?: ToolRegistry;
|
|
447
|
-
}
|
|
448
|
-
interface AppliedSkillResult {
|
|
449
|
-
readonly messages: readonly Message[];
|
|
450
|
-
readonly tools?: ToolRegistry;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Injects a skill's body into messages as a system prompt and applies allowed tool filters.
|
|
454
|
-
*/
|
|
455
|
-
declare function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult;
|
|
456
|
-
|
|
457
|
-
export { parseFrontmatter as $, type AnyTool as A, type Role as B, type ChatResponse as C, type DeleteRequestOptions as D, type EmbedRequestOptions as E, type FormatOption as F, type GenerateResponse as G, type Skill as H, type SkillFrontmatter as I, type SkillSummary as J, type ToolCallFunction as K, type ListResponse as L, type Message as M, type ToolExecutionContext as N, type ToolExecutionFailure as O, type ProgressResponse as P, type ToolExecutionSuccess as Q, type RequestCancellationOptions as R, type ShowRequestOptions as S, type ToolCall as T, type ToolFunctionDefinition as U, type VersionResponse as V, type WebSearchRequestOptions as W, type ToolProperty as X, type ToolRegistryOptions as Y, type WebSearchResult as Z, applySkill as _, type ModelResponse as a, type ShowResponse as b, type PullRequestOptions as c, type PushRequestOptions as d, type CreateRequestOptions as e, type StatusResponse as f, type CopyRequestOptions as g, type PsResponse as h, type ChatRequestOptions as i, type GenerateRequestOptions as j, type EmbedResponse as k, type EmbeddingsRequestOptions as l, type EmbeddingsResponse as m, type WebSearchResponse as n, type WebFetchRequestOptions as o, type WebFetchResponse as p, type ToolHandler as q, type Tool as r, ToolRegistry as s, type ToolExecutionResult as t, type ModelOptions as u, type ToolDefinition as v, type AppliedSkillResult as w, type ApplySkillOptions as x, type ModelDetails as y, type ParsedFrontmatter as z };
|
|
403
|
+
export type { ToolParameters as A, ToolProperty as B, CreateRequestOptions as C, DeleteRequestOptions as D, EmbedRequestOptions as E, FormatOption as F, GenerateRequestOptions as G, WebSearchResult as H, ListResponse as L, Message as M, PullRequestOptions as P, RequestCancellationOptions as R, ShowRequestOptions as S, ToolDefinition as T, VersionResponse as V, WebSearchRequestOptions as W, ToolCall as a, ThinkingMetadata as b, ModelResponse as c, ShowResponse as d, ProgressResponse as e, PushRequestOptions as f, StatusResponse as g, CopyRequestOptions as h, PsResponse as i, ChatRequestOptions as j, ChatResponse as k, GenerateResponse as l, EmbedResponse as m, EmbeddingsRequestOptions as n, EmbeddingsResponse as o, WebSearchResponse as p, WebFetchRequestOptions as q, WebFetchResponse as r, ModelOptions as s, ThinkValue as t, Logprob as u, LogprobToken as v, ModelDetails as w, Role as x, ToolCallFunction as y, ToolFunctionDefinition as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemesis-oss/ollama-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Production-grade TypeScript SDK for Ollama with native fetch, high availability failover, multi-turn tool calling, structured outputs, reasoning stream tokens, OpenAI/Anthropic bridges, MCP,
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Production-grade TypeScript SDK for Ollama with native fetch, high availability failover, multi-turn tool calling, structured outputs, reasoning stream tokens, OpenAI/Anthropic bridges, MCP, Web Stream adapters, and a contract-first hybrid architecture that generates TypeScript types, API classes, MCP tools, and Zod schemas from a single canonical IR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ollama",
|
|
7
7
|
"ollama-client",
|
|
@@ -59,12 +59,90 @@
|
|
|
59
59
|
"default": "./dist/skills.cjs"
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"./package.json": "./package.json"
|
|
62
|
+
"./package.json": "./package.json",
|
|
63
|
+
"./mcp/stdio": {
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/mcp-stdio.d.ts",
|
|
66
|
+
"default": "./dist/mcp-stdio.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/mcp-stdio.d.cts",
|
|
70
|
+
"default": "./dist/mcp-stdio.cjs"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"./mcp/http": {
|
|
74
|
+
"import": {
|
|
75
|
+
"types": "./dist/mcp-http.d.ts",
|
|
76
|
+
"default": "./dist/mcp-http.js"
|
|
77
|
+
},
|
|
78
|
+
"require": {
|
|
79
|
+
"types": "./dist/mcp-http.d.cts",
|
|
80
|
+
"default": "./dist/mcp-http.cjs"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"./generated/runtime": {
|
|
84
|
+
"import": {
|
|
85
|
+
"types": "./dist/generated-runtime.d.ts",
|
|
86
|
+
"default": "./dist/generated-runtime.js"
|
|
87
|
+
},
|
|
88
|
+
"require": {
|
|
89
|
+
"types": "./dist/generated-runtime.d.cts",
|
|
90
|
+
"default": "./dist/generated-runtime.cjs"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"./generated/api": {
|
|
94
|
+
"import": {
|
|
95
|
+
"types": "./dist/generated-api.d.ts",
|
|
96
|
+
"default": "./dist/generated-api.js"
|
|
97
|
+
},
|
|
98
|
+
"require": {
|
|
99
|
+
"types": "./dist/generated-api.d.cts",
|
|
100
|
+
"default": "./dist/generated-api.cjs"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"./generated/models/schemas": {
|
|
104
|
+
"import": {
|
|
105
|
+
"types": "./dist/generated-models-schemas.d.ts",
|
|
106
|
+
"default": "./dist/generated-models-schemas.js"
|
|
107
|
+
},
|
|
108
|
+
"require": {
|
|
109
|
+
"types": "./dist/generated-models-schemas.d.cts",
|
|
110
|
+
"default": "./dist/generated-models-schemas.cjs"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"./mcp/generated": {
|
|
114
|
+
"import": {
|
|
115
|
+
"types": "./dist/mcp-generated.d.ts",
|
|
116
|
+
"default": "./dist/mcp-generated.js"
|
|
117
|
+
},
|
|
118
|
+
"require": {
|
|
119
|
+
"types": "./dist/mcp-generated.d.cts",
|
|
120
|
+
"default": "./dist/mcp-generated.cjs"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
63
123
|
},
|
|
64
124
|
"typesVersions": {
|
|
65
125
|
"*": {
|
|
66
126
|
"skills": [
|
|
67
127
|
"dist/skills.d.ts"
|
|
128
|
+
],
|
|
129
|
+
"mcp/stdio": [
|
|
130
|
+
"dist/mcp-stdio.d.ts"
|
|
131
|
+
],
|
|
132
|
+
"mcp/http": [
|
|
133
|
+
"dist/mcp-http.d.ts"
|
|
134
|
+
],
|
|
135
|
+
"generated/runtime": [
|
|
136
|
+
"dist/generated-runtime.d.ts"
|
|
137
|
+
],
|
|
138
|
+
"generated/api": [
|
|
139
|
+
"dist/generated-api.d.ts"
|
|
140
|
+
],
|
|
141
|
+
"generated/models/schemas": [
|
|
142
|
+
"dist/generated-models-schemas.d.ts"
|
|
143
|
+
],
|
|
144
|
+
"mcp/generated": [
|
|
145
|
+
"dist/mcp-generated.d.ts"
|
|
68
146
|
]
|
|
69
147
|
}
|
|
70
148
|
},
|
|
@@ -95,21 +173,32 @@
|
|
|
95
173
|
"test:watch": "vitest",
|
|
96
174
|
"test:coverage": "vitest run --coverage",
|
|
97
175
|
"verify:edge-runtime": "tsx scripts/verify-edge-runtime.ts",
|
|
176
|
+
"verify:contract-parity": "tsx scripts/verify-contract-parity.ts",
|
|
177
|
+
"contract:fetch": "tsx scripts/fetch-contract.ts",
|
|
178
|
+
"contract:normalize": "tsx scripts/build-contract.ts",
|
|
179
|
+
"contract:validate": "tsx scripts/verify-contract.ts",
|
|
180
|
+
"contract:diff": "tsx scripts/diff-contract.ts",
|
|
181
|
+
"contract:generate": "tsx scripts/generate-contract.ts && prettier --write src/generated/",
|
|
182
|
+
"contract:drift": "tsx scripts/drift-contract.ts",
|
|
98
183
|
"bench": "vitest bench --run",
|
|
99
184
|
"bench:watch": "vitest bench",
|
|
100
185
|
"check:types": "npx --yes @arethetypeswrong/cli@latest --pack .",
|
|
101
|
-
"verify": "npm run typecheck && npm run lint && npm run test && npm run build && npm run verify:edge-runtime",
|
|
186
|
+
"verify": "npm run typecheck && npm run lint && npm run test && npm run build && npm run verify:edge-runtime && npm run verify:contract-parity",
|
|
102
187
|
"example": "tsx",
|
|
103
188
|
"lab": "tsx lab/run.ts",
|
|
104
|
-
"prepublishOnly": "npm run clean && npm run typecheck && npm run lint && npm test && npm run build && npm run verify:edge-runtime"
|
|
189
|
+
"prepublishOnly": "npm run clean && npm run typecheck && npm run lint && npm run test && npm run build && npm run verify:edge-runtime && npm run verify:contract-parity"
|
|
105
190
|
},
|
|
106
191
|
"peerDependencies": {
|
|
192
|
+
"@modelcontextprotocol/client": "^2.1.0",
|
|
107
193
|
"@opentelemetry/api": "^1.9.0",
|
|
108
194
|
"zod": "^3.22.0 || ^4.0.0"
|
|
109
195
|
},
|
|
110
196
|
"peerDependenciesMeta": {
|
|
111
197
|
"@opentelemetry/api": {
|
|
112
198
|
"optional": true
|
|
199
|
+
},
|
|
200
|
+
"@modelcontextprotocol/client": {
|
|
201
|
+
"optional": true
|
|
113
202
|
}
|
|
114
203
|
},
|
|
115
204
|
"devDependencies": {
|
|
@@ -120,6 +209,7 @@
|
|
|
120
209
|
"@opentelemetry/api": "^1.9.1",
|
|
121
210
|
"@opentelemetry/context-async-hooks": "^1.30.1",
|
|
122
211
|
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
212
|
+
"@types/js-yaml": "^4.0.9",
|
|
123
213
|
"@types/node": "^22.20.0",
|
|
124
214
|
"@vitest/coverage-v8": "^4.1.9",
|
|
125
215
|
"cross-env": "^10.1.0",
|
|
@@ -127,6 +217,7 @@
|
|
|
127
217
|
"esbuild": "^0.27.7",
|
|
128
218
|
"eslint": "^9.39.4",
|
|
129
219
|
"eslint-config-prettier": "^9.1.2",
|
|
220
|
+
"js-yaml": "^5.4.2",
|
|
130
221
|
"prettier": "^3.9.4",
|
|
131
222
|
"tsup": "^8.5.1",
|
|
132
223
|
"tsx": "^4.23.0",
|