@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
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
import { M as Message, k as ChatResponse, l as GenerateResponse, a as ToolCall, e as ProgressResponse } from './types-BQhgW-du.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Request/response middleware pipeline.
|
|
5
|
+
*/
|
|
6
|
+
interface RequestContext {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly method: string;
|
|
9
|
+
readonly headers: Record<string, string>;
|
|
10
|
+
readonly body?: unknown;
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
interface ResponseContext {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly headers: Record<string, string>;
|
|
16
|
+
readonly body: unknown;
|
|
17
|
+
}
|
|
18
|
+
type NextFunction = () => Promise<ResponseContext>;
|
|
19
|
+
interface MiddlewareContext {
|
|
20
|
+
readonly request: RequestContext;
|
|
21
|
+
readonly next: NextFunction;
|
|
22
|
+
}
|
|
23
|
+
interface Middleware {
|
|
24
|
+
(ctx: MiddlewareContext): Promise<ResponseContext>;
|
|
25
|
+
}
|
|
26
|
+
declare function composeMiddleware(middlewares: readonly Middleware[], finalHandler: (req: RequestContext) => Promise<ResponseContext>): (req: RequestContext) => Promise<ResponseContext>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Structured logger and request lifecycle interfaces.
|
|
30
|
+
*/
|
|
31
|
+
interface LogFn {
|
|
32
|
+
(message: string, context?: Record<string, unknown>): void;
|
|
33
|
+
}
|
|
34
|
+
interface Logger {
|
|
35
|
+
readonly debug: LogFn;
|
|
36
|
+
readonly info: LogFn;
|
|
37
|
+
readonly warn: LogFn;
|
|
38
|
+
readonly error: LogFn;
|
|
39
|
+
}
|
|
40
|
+
interface LifecycleStartEvent {
|
|
41
|
+
readonly type: 'start';
|
|
42
|
+
readonly requestId: string;
|
|
43
|
+
readonly method: string;
|
|
44
|
+
readonly url: string;
|
|
45
|
+
readonly timestamp: number;
|
|
46
|
+
}
|
|
47
|
+
interface LifecycleSuccessEvent {
|
|
48
|
+
readonly type: 'success';
|
|
49
|
+
readonly requestId: string;
|
|
50
|
+
readonly durationMs: number;
|
|
51
|
+
readonly status: number;
|
|
52
|
+
readonly timestamp: number;
|
|
53
|
+
}
|
|
54
|
+
interface LifecycleRetryEvent {
|
|
55
|
+
readonly type: 'retry';
|
|
56
|
+
readonly requestId: string;
|
|
57
|
+
readonly attempt: number;
|
|
58
|
+
readonly error: Error;
|
|
59
|
+
readonly delayMs: number;
|
|
60
|
+
readonly timestamp: number;
|
|
61
|
+
}
|
|
62
|
+
interface LifecycleErrorEvent {
|
|
63
|
+
readonly type: 'error';
|
|
64
|
+
readonly requestId: string;
|
|
65
|
+
readonly durationMs: number;
|
|
66
|
+
readonly error: Error;
|
|
67
|
+
readonly timestamp: number;
|
|
68
|
+
}
|
|
69
|
+
type RequestLifecycleEvent = LifecycleStartEvent | LifecycleSuccessEvent | LifecycleRetryEvent | LifecycleErrorEvent;
|
|
70
|
+
interface RequestLifecycleHook {
|
|
71
|
+
(event: RequestLifecycleEvent): void;
|
|
72
|
+
}
|
|
73
|
+
declare const NOOP_LOGGER: Logger;
|
|
74
|
+
declare function createConsoleLogger(prefix?: string): Logger;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Server-Sent Events (SSE) parser for OpenAI/Anthropic-compatible streaming endpoints.
|
|
78
|
+
*
|
|
79
|
+
* Implements standard event-stream field rules without coupling the parser to
|
|
80
|
+
* any provider-specific event schema.
|
|
81
|
+
*/
|
|
82
|
+
interface SseEvent {
|
|
83
|
+
/** Event type; omitted when the server emitted no explicit event field. */
|
|
84
|
+
readonly event?: string | undefined;
|
|
85
|
+
/** Event data with consecutive data fields joined by a newline. */
|
|
86
|
+
readonly data: string;
|
|
87
|
+
/** Last event id associated with this dispatch, when present. */
|
|
88
|
+
readonly id?: string | undefined;
|
|
89
|
+
/** Reconnection delay requested by the server, in milliseconds, when valid. */
|
|
90
|
+
readonly retry?: number | undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parses an SSE byte stream into discrete events.
|
|
94
|
+
*
|
|
95
|
+
* Supports CRLF, CR, and LF line endings; comments; repeated data fields;
|
|
96
|
+
* event/id/retry fields; UTF-8 chunks split across arbitrary byte boundaries;
|
|
97
|
+
* and a terminal event without a trailing blank line.
|
|
98
|
+
*/
|
|
99
|
+
declare function parseSseStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<SseEvent, void, undefined>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Structured, typed error hierarchy for OllamaClient.
|
|
103
|
+
*/
|
|
104
|
+
interface OllamaErrorRequestContext {
|
|
105
|
+
readonly method?: string | undefined;
|
|
106
|
+
readonly url?: string | undefined;
|
|
107
|
+
readonly model?: string | undefined;
|
|
108
|
+
}
|
|
109
|
+
interface OllamaErrorResponseContext {
|
|
110
|
+
readonly status?: number | undefined;
|
|
111
|
+
readonly headers?: Record<string, string> | undefined;
|
|
112
|
+
readonly body?: unknown;
|
|
113
|
+
}
|
|
114
|
+
interface OllamaClientErrorOptions extends ErrorOptions {
|
|
115
|
+
readonly code: string;
|
|
116
|
+
readonly status?: number | undefined;
|
|
117
|
+
readonly retryable?: boolean | undefined;
|
|
118
|
+
readonly request?: OllamaErrorRequestContext | undefined;
|
|
119
|
+
readonly response?: OllamaErrorResponseContext | undefined;
|
|
120
|
+
}
|
|
121
|
+
declare class OllamaClientError extends Error {
|
|
122
|
+
readonly code: string;
|
|
123
|
+
readonly status?: number | undefined;
|
|
124
|
+
readonly retryable: boolean;
|
|
125
|
+
readonly request?: OllamaErrorRequestContext | undefined;
|
|
126
|
+
readonly response?: OllamaErrorResponseContext | undefined;
|
|
127
|
+
constructor(message: string, options: OllamaClientErrorOptions);
|
|
128
|
+
}
|
|
129
|
+
declare class OllamaNetworkError extends OllamaClientError {
|
|
130
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
|
|
131
|
+
}
|
|
132
|
+
declare class OllamaTimeoutError extends OllamaClientError {
|
|
133
|
+
readonly timeoutMs?: number | undefined;
|
|
134
|
+
constructor(message: string, options?: (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
135
|
+
timeoutMs?: number | undefined;
|
|
136
|
+
}) | undefined);
|
|
137
|
+
}
|
|
138
|
+
declare class OllamaAuthError extends OllamaClientError {
|
|
139
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
|
|
140
|
+
}
|
|
141
|
+
declare class OllamaNotFoundError extends OllamaClientError {
|
|
142
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
|
|
143
|
+
}
|
|
144
|
+
declare class OllamaRateLimitError extends OllamaClientError {
|
|
145
|
+
readonly retryAfterMs?: number | undefined;
|
|
146
|
+
constructor(message: string, options?: (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
147
|
+
retryAfterMs?: number | undefined;
|
|
148
|
+
}) | undefined);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Thrown client-side, before a network request is made, by `QuotaManager.assertCanProceed`
|
|
152
|
+
* (see `src/quota.ts`) when issuing the request would exceed a configured usage budget for
|
|
153
|
+
* one of its rolling windows. This is distinct from `OllamaRateLimitError`, which reflects
|
|
154
|
+
* the server's own 429 response — Ollama Cloud does not expose account-level quota via the
|
|
155
|
+
* API, so `QuotaManager` tracks usage against budgets the caller configures locally and
|
|
156
|
+
* fails fast rather than waiting for the server to reject the request.
|
|
157
|
+
*/
|
|
158
|
+
declare class OllamaQuotaExceededError extends OllamaClientError {
|
|
159
|
+
readonly windowId: string;
|
|
160
|
+
readonly resetAt: number;
|
|
161
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
162
|
+
windowId: string;
|
|
163
|
+
resetAt: number;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
declare class OllamaServerError extends OllamaClientError {
|
|
167
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
|
|
168
|
+
}
|
|
169
|
+
declare class OllamaAbortError extends OllamaClientError {
|
|
170
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
|
|
171
|
+
}
|
|
172
|
+
declare class OllamaToolValidationError extends OllamaClientError {
|
|
173
|
+
readonly toolName: string;
|
|
174
|
+
readonly issues?: unknown;
|
|
175
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
176
|
+
toolName: string;
|
|
177
|
+
issues?: unknown;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
declare class OllamaToolTimeoutError extends OllamaClientError {
|
|
181
|
+
readonly toolName: string;
|
|
182
|
+
readonly timeoutMs: number;
|
|
183
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
184
|
+
toolName: string;
|
|
185
|
+
timeoutMs: number;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Thrown client-side, before a network request is made, when a request asks for a
|
|
190
|
+
* capability an endpoint is known not to support (e.g. structured output `format` against
|
|
191
|
+
* an Ollama Cloud endpoint — see `ModelCapabilities.supportsStructuredOutputRequest` in
|
|
192
|
+
* `src/capabilities/capabilities.ts`). Its `code` is included in `DEFAULT_FAILOVER_CODES`
|
|
193
|
+
* by default, so in a multi-endpoint setup it causes failover to the next candidate rather
|
|
194
|
+
* than failing outright — it only surfaces to the caller if every candidate is rejected.
|
|
195
|
+
*/
|
|
196
|
+
declare class OllamaUnsupportedCapabilityError extends OllamaClientError {
|
|
197
|
+
readonly capability: string;
|
|
198
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
199
|
+
capability: string;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Thrown client-side, before any network call, when `config.endpoints` uses
|
|
204
|
+
* `OllamaEndpoint.models` to scope endpoints/credentials to specific models and the
|
|
205
|
+
* requested `model` isn't in any configured endpoint's allow-list. This is a routing
|
|
206
|
+
* misconfiguration, not a connectivity problem — the SDK deliberately does not "probe"
|
|
207
|
+
* unauthorized endpoints to find one that happens to work (that would burn quota on keys
|
|
208
|
+
* that were never entitled to the model and produce non-deterministic startup behavior).
|
|
209
|
+
*/
|
|
210
|
+
declare class OllamaModelRoutingError extends OllamaClientError {
|
|
211
|
+
readonly model: string;
|
|
212
|
+
readonly availableModels: readonly string[];
|
|
213
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
214
|
+
model: string;
|
|
215
|
+
availableModels: readonly string[];
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Thrown before an agent tool loop starts when the selected model's /api/show metadata
|
|
220
|
+
* does not advertise a capability required by the loop.
|
|
221
|
+
*/
|
|
222
|
+
declare class OllamaIncompatibleModelError extends OllamaClientError {
|
|
223
|
+
readonly model: string;
|
|
224
|
+
readonly capability: string;
|
|
225
|
+
readonly reportedCapabilities: readonly string[];
|
|
226
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
|
|
227
|
+
model: string;
|
|
228
|
+
capability: string;
|
|
229
|
+
reportedCapabilities: readonly string[];
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
declare class OllamaAgentMaxToolCallsError extends OllamaClientError {
|
|
233
|
+
readonly maxToolCalls: number;
|
|
234
|
+
readonly toolCallsExecuted: number;
|
|
235
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
236
|
+
maxToolCalls: number;
|
|
237
|
+
toolCallsExecuted: number;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
declare class OllamaAgentMaxIterationsError extends OllamaClientError {
|
|
241
|
+
readonly maxIterations: number;
|
|
242
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
243
|
+
maxIterations: number;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
declare class OllamaMcpError extends OllamaClientError {
|
|
247
|
+
readonly mcpMethod: 'listTools' | 'callTool';
|
|
248
|
+
readonly toolName?: string | undefined;
|
|
249
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
250
|
+
mcpMethod: 'listTools' | 'callTool';
|
|
251
|
+
toolName?: string | undefined;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
declare class OllamaSkillNotFoundError extends OllamaClientError {
|
|
255
|
+
readonly skillName: string;
|
|
256
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
257
|
+
skillName: string;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
declare class OllamaSkillInvalidError extends OllamaClientError {
|
|
261
|
+
readonly skillName: string;
|
|
262
|
+
readonly path?: string | undefined;
|
|
263
|
+
constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
|
|
264
|
+
skillName: string;
|
|
265
|
+
path?: string | undefined;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
declare class OllamaGenericClientError extends OllamaClientError {
|
|
269
|
+
constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code'> | undefined);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Maps arbitrary thrown exceptions into structured OllamaClientError instances.
|
|
273
|
+
*/
|
|
274
|
+
declare function mapError(error: unknown, context?: {
|
|
275
|
+
request?: OllamaErrorRequestContext | undefined;
|
|
276
|
+
response?: OllamaErrorResponseContext | undefined;
|
|
277
|
+
}): OllamaClientError;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Token usage and duration calculation utilities.
|
|
281
|
+
*/
|
|
282
|
+
declare const NANOS_PER_MS = 1000000;
|
|
283
|
+
declare const NANOS_PER_SECOND = 1000000000;
|
|
284
|
+
interface TokenUsage {
|
|
285
|
+
readonly promptTokens: number;
|
|
286
|
+
/** Prompt tokens read from Ollama's KV cache. */
|
|
287
|
+
readonly cachedPromptTokens?: number | undefined;
|
|
288
|
+
readonly completionTokens: number;
|
|
289
|
+
readonly totalTokens: number;
|
|
290
|
+
readonly tokensPerSecond?: number | undefined;
|
|
291
|
+
readonly loadDurationMs?: number | undefined;
|
|
292
|
+
readonly promptEvalDurationMs?: number | undefined;
|
|
293
|
+
readonly evalDurationMs?: number | undefined;
|
|
294
|
+
readonly totalDurationMs?: number | undefined;
|
|
295
|
+
}
|
|
296
|
+
interface RawUsageSource {
|
|
297
|
+
readonly prompt_eval_count?: number | undefined;
|
|
298
|
+
readonly prompt_eval_cached_count?: number | undefined;
|
|
299
|
+
readonly eval_count?: number | undefined;
|
|
300
|
+
readonly total_duration?: number | undefined;
|
|
301
|
+
readonly load_duration?: number | undefined;
|
|
302
|
+
readonly prompt_eval_duration?: number | undefined;
|
|
303
|
+
readonly eval_duration?: number | undefined;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Extracts and normalizes token usage metrics from an Ollama response.
|
|
307
|
+
*/
|
|
308
|
+
declare function extractUsage(raw: RawUsageSource): TokenUsage;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Streaming event types, listener contracts, and aggregated result shapes.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
interface TokenEvent {
|
|
315
|
+
readonly type: 'token';
|
|
316
|
+
readonly data: {
|
|
317
|
+
readonly delta: string;
|
|
318
|
+
readonly role?: string | undefined;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
interface ThinkingEvent {
|
|
322
|
+
readonly type: 'thinking';
|
|
323
|
+
readonly data: {
|
|
324
|
+
readonly delta: string;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
interface ToolCallEvent {
|
|
328
|
+
readonly type: 'tool_call';
|
|
329
|
+
readonly data: {
|
|
330
|
+
readonly toolCall: ToolCall;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
interface MessageEvent<TChunk> {
|
|
334
|
+
readonly type: 'message';
|
|
335
|
+
readonly data: {
|
|
336
|
+
readonly chunk: TChunk;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
interface DoneEvent<TFinal> {
|
|
340
|
+
readonly type: 'done';
|
|
341
|
+
readonly data: {
|
|
342
|
+
readonly result: TFinal;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
interface ErrorEvent {
|
|
346
|
+
readonly type: 'error';
|
|
347
|
+
readonly data: {
|
|
348
|
+
readonly error: OllamaClientError;
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
type OllamaStreamEvent<TChunk, TFinal> = TokenEvent | ThinkingEvent | ToolCallEvent | MessageEvent<TChunk> | DoneEvent<TFinal> | ErrorEvent;
|
|
352
|
+
type OllamaStreamEventType = OllamaStreamEvent<unknown, unknown>['type'];
|
|
353
|
+
interface ChatStreamResult {
|
|
354
|
+
readonly message: Message;
|
|
355
|
+
readonly model: string;
|
|
356
|
+
readonly done: boolean;
|
|
357
|
+
/** Mirrors the final chunk's `done_reason` (e.g. `"stop"`, `"load"`, `"unload"`). */
|
|
358
|
+
readonly doneReason?: string | undefined;
|
|
359
|
+
readonly totalDurationMs?: number | undefined;
|
|
360
|
+
readonly usage?: TokenUsage | undefined;
|
|
361
|
+
readonly raw?: ChatResponse | undefined;
|
|
362
|
+
}
|
|
363
|
+
interface GenerateStreamResult {
|
|
364
|
+
readonly response: string;
|
|
365
|
+
readonly model: string;
|
|
366
|
+
readonly done: boolean;
|
|
367
|
+
/** Mirrors the final chunk's `done_reason` (e.g. `"stop"`, `"load"`, `"unload"`). */
|
|
368
|
+
readonly doneReason?: string | undefined;
|
|
369
|
+
readonly totalDurationMs?: number | undefined;
|
|
370
|
+
readonly usage?: TokenUsage | undefined;
|
|
371
|
+
readonly thinking?: string | undefined;
|
|
372
|
+
readonly image?: string | undefined;
|
|
373
|
+
readonly completed?: number | undefined;
|
|
374
|
+
readonly total?: number | undefined;
|
|
375
|
+
readonly raw?: GenerateResponse | undefined;
|
|
376
|
+
}
|
|
377
|
+
interface ProgressStreamResult {
|
|
378
|
+
readonly status: string;
|
|
379
|
+
readonly completed?: number | undefined;
|
|
380
|
+
readonly total?: number | undefined;
|
|
381
|
+
readonly done: boolean;
|
|
382
|
+
readonly raw?: ProgressResponse | undefined;
|
|
383
|
+
}
|
|
384
|
+
interface AbortableAsyncIterable<T> extends AsyncIterable<T> {
|
|
385
|
+
abort?: (() => void) | undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Native fetch HTTP transport client for Ollama API.
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
type FetchLike = typeof globalThis.fetch;
|
|
393
|
+
type BinaryBody = Uint8Array | ArrayBuffer | string | Blob | ReadableStream<Uint8Array>;
|
|
394
|
+
type HttpBody = unknown;
|
|
395
|
+
interface HttpClientOptions {
|
|
396
|
+
readonly baseUrl: string;
|
|
397
|
+
readonly apiKey?: string | undefined;
|
|
398
|
+
readonly headers?: Record<string, string> | undefined;
|
|
399
|
+
readonly fetch?: FetchLike | undefined;
|
|
400
|
+
readonly middleware?: readonly Middleware[] | undefined;
|
|
401
|
+
readonly onLifecycleEvent?: RequestLifecycleHook | undefined;
|
|
402
|
+
/** Reuse a logical request id across endpoint failover/retry attempts. */
|
|
403
|
+
readonly requestId?: string | undefined;
|
|
404
|
+
}
|
|
405
|
+
interface HttpRequestOptions {
|
|
406
|
+
readonly path: string;
|
|
407
|
+
readonly method?: 'GET' | 'POST' | 'DELETE' | 'HEAD' | undefined;
|
|
408
|
+
readonly body?: HttpBody;
|
|
409
|
+
readonly rawBody?: BinaryBody | undefined;
|
|
410
|
+
readonly headers?: Record<string, string> | undefined;
|
|
411
|
+
readonly signal?: AbortSignal | undefined;
|
|
412
|
+
/**
|
|
413
|
+
* When `true`, return the raw {@link Response} object instead of parsing
|
|
414
|
+
* the body as JSON. Used by callers that need direct access to the
|
|
415
|
+
* streaming body (e.g. {@link src/generated/runtime/runtime.ts} for
|
|
416
|
+
* NDJSON streaming through the runtime seam).
|
|
417
|
+
*
|
|
418
|
+
* The returned `Response` is the same one middleware/retry/telemetry
|
|
419
|
+
* have already processed, so this option does NOT bypass any of the
|
|
420
|
+
* transport-layer concerns.
|
|
421
|
+
*/
|
|
422
|
+
readonly raw?: boolean | undefined;
|
|
423
|
+
}
|
|
424
|
+
declare class HttpClient {
|
|
425
|
+
readonly baseUrl: string;
|
|
426
|
+
private readonly apiKey?;
|
|
427
|
+
private readonly defaultHeaders;
|
|
428
|
+
private readonly fetchImpl;
|
|
429
|
+
private readonly middleware;
|
|
430
|
+
private readonly onLifecycleEvent;
|
|
431
|
+
private readonly requestId?;
|
|
432
|
+
constructor(options: HttpClientOptions);
|
|
433
|
+
private buildHeaders;
|
|
434
|
+
private fetchWithMiddleware;
|
|
435
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
436
|
+
/**
|
|
437
|
+
* Opens an event-stream response and exposes parsed SSE events.
|
|
438
|
+
*
|
|
439
|
+
* This is intentionally schema-agnostic so OpenAI and Anthropic compatibility layers
|
|
440
|
+
* can decode their provider-specific event payloads without duplicating transport logic.
|
|
441
|
+
*/
|
|
442
|
+
requestSseStream(options: HttpRequestOptions): Promise<AbortableAsyncIterable<SseEvent>>;
|
|
443
|
+
requestStream<T>(options: HttpRequestOptions): Promise<AbortableAsyncIterable<T>>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* OperationDefinition — the runtime-facing contract shape.
|
|
448
|
+
*
|
|
449
|
+
* Every generated operation in `src/generated/api/operations.ts` is typed
|
|
450
|
+
* `as const satisfies OperationDefinition`. This file is the ONLY hand-written
|
|
451
|
+
* file in `src/generated/` — it defines the contract the generated code
|
|
452
|
+
* expects the runtime to honor.
|
|
453
|
+
*
|
|
454
|
+
* The shape mirrors {@link OperationContract} from the canonical IR, with
|
|
455
|
+
* one simplification: schema refs are typed as `$ref: string` rather than
|
|
456
|
+
* the full `SchemaRef` interface, because the runtime never resolves them
|
|
457
|
+
* (it just passes the request body to the HTTP client).
|
|
458
|
+
*
|
|
459
|
+
* The types below are intentionally inlined (not imported from
|
|
460
|
+
* `generator/types.ts`) so that `src/generated/` is self-contained and
|
|
461
|
+
* the shipped package does not depend on the build-time `generator/`
|
|
462
|
+
* directory at runtime. The contract IR is regenerated by `npm run
|
|
463
|
+
* contract:generate`; the canonical type definitions live in
|
|
464
|
+
* `generator/types.ts`, and this file mirrors just the subset the runtime
|
|
465
|
+
* needs.
|
|
466
|
+
*/
|
|
467
|
+
/** Wire-format used to transport request/response bodies. */
|
|
468
|
+
type TransportMode = 'json' | 'ndjson' | 'sse';
|
|
469
|
+
/** HTTP method an operation uses. */
|
|
470
|
+
type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' | 'HEAD';
|
|
471
|
+
/** Capability support level — first-class concept in Ollama's docs. */
|
|
472
|
+
type CapabilitySupport = 'supported' | 'unsupported' | 'model-dependent' | 'version-dependent';
|
|
473
|
+
/** Schema reference, same shape as the IR's SchemaRef. */
|
|
474
|
+
interface SchemaRef {
|
|
475
|
+
readonly $ref: string;
|
|
476
|
+
}
|
|
477
|
+
/** Behavioral contract a generated operation carries into the runtime. */
|
|
478
|
+
interface OperationDefinition {
|
|
479
|
+
readonly operationId: string;
|
|
480
|
+
readonly method: HttpMethod;
|
|
481
|
+
readonly path: string;
|
|
482
|
+
readonly request?: SchemaRef;
|
|
483
|
+
readonly response?: SchemaRef;
|
|
484
|
+
readonly environment: {
|
|
485
|
+
readonly local: boolean;
|
|
486
|
+
readonly cloud: boolean;
|
|
487
|
+
};
|
|
488
|
+
readonly transport: {
|
|
489
|
+
readonly mode: TransportMode;
|
|
490
|
+
readonly streaming: boolean;
|
|
491
|
+
readonly streamingDefault?: boolean;
|
|
492
|
+
};
|
|
493
|
+
readonly capabilities: {
|
|
494
|
+
readonly thinking?: CapabilitySupport;
|
|
495
|
+
readonly tools?: CapabilitySupport;
|
|
496
|
+
readonly vision?: CapabilitySupport;
|
|
497
|
+
readonly structuredOutput?: CapabilitySupport;
|
|
498
|
+
readonly logprobs?: CapabilitySupport;
|
|
499
|
+
readonly embeddings?: CapabilitySupport;
|
|
500
|
+
};
|
|
501
|
+
readonly constraints?: {
|
|
502
|
+
readonly minOllamaVersion?: string;
|
|
503
|
+
readonly maxRequestBytes?: number;
|
|
504
|
+
};
|
|
505
|
+
readonly status: {
|
|
506
|
+
readonly documented: boolean;
|
|
507
|
+
readonly deprecated?: boolean;
|
|
508
|
+
readonly experimental?: boolean;
|
|
509
|
+
};
|
|
510
|
+
readonly domain: 'native' | 'openai' | 'anthropic';
|
|
511
|
+
readonly notes?: readonly string[];
|
|
512
|
+
}
|
|
513
|
+
/** Request descriptor passed by generated API classes to {@link OllamaRuntime.invoke}. */
|
|
514
|
+
interface InvokeRequest {
|
|
515
|
+
/** The operation definition this call corresponds to. */
|
|
516
|
+
readonly operation: OperationDefinition;
|
|
517
|
+
/** Request body, or `undefined` for GET/HEAD calls. */
|
|
518
|
+
readonly body: unknown;
|
|
519
|
+
/** Optional per-call abort signal. */
|
|
520
|
+
readonly signal?: AbortSignal;
|
|
521
|
+
/**
|
|
522
|
+
* Whether the docs say this operation streams by default. The runtime
|
|
523
|
+
* uses this to decide whether to enable streaming when the request body
|
|
524
|
+
* doesn't explicitly set `stream`.
|
|
525
|
+
*/
|
|
526
|
+
readonly streamingDefault?: boolean;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* OllamaRuntime — the runtime seam generated API classes delegate to.
|
|
531
|
+
*
|
|
532
|
+
* This is the only hand-written file in `src/generated/runtime/`. Every
|
|
533
|
+
* generated method in `src/generated/api/*-api.ts` ends with:
|
|
534
|
+
*
|
|
535
|
+
* ```ts
|
|
536
|
+
* return this.runtime.invoke({ operation: chatOp, body: request });
|
|
537
|
+
* ```
|
|
538
|
+
*
|
|
539
|
+
* The runtime is responsible for:
|
|
540
|
+
* - Method/path resolution (from {@link OperationDefinition})
|
|
541
|
+
* - Streaming default application (when the request doesn't set `stream`)
|
|
542
|
+
* - Environment guard (rejecting cloud calls for local-only operations)
|
|
543
|
+
* - Version constraint guard (failing fast when the server is too old)
|
|
544
|
+
* - Delegating to the existing {@link HttpClient} for transport, retry,
|
|
545
|
+
* telemetry, NDJSON/SSE parsing
|
|
546
|
+
*
|
|
547
|
+
* It is intentionally a thin adapter — the existing transport, streaming,
|
|
548
|
+
* middleware, and error-mapping layers are preserved verbatim. This file
|
|
549
|
+
* only adds the contract-aware glue between generated API classes and the
|
|
550
|
+
* existing HttpClient.
|
|
551
|
+
*/
|
|
552
|
+
|
|
553
|
+
/** Constructor options for {@link OllamaRuntime}. */
|
|
554
|
+
interface OllamaRuntimeOptions {
|
|
555
|
+
readonly http: HttpClient;
|
|
556
|
+
/**
|
|
557
|
+
* Whether this runtime is targeting a local Ollama instance. Defaults to
|
|
558
|
+
* `true`. When `false`, operations marked `environment.cloud === false`
|
|
559
|
+
* (i.e. local-only like `/v1/systemone`) are rejected at request time.
|
|
560
|
+
*/
|
|
561
|
+
readonly localMode?: boolean;
|
|
562
|
+
/**
|
|
563
|
+
* Server version, if known (typically from a prior `/api/version` call).
|
|
564
|
+
* When set, operations with `constraints.minOllamaVersion` are checked
|
|
565
|
+
* against this value at request time.
|
|
566
|
+
*/
|
|
567
|
+
readonly serverVersion?: string;
|
|
568
|
+
}
|
|
569
|
+
/** The runtime seam. */
|
|
570
|
+
declare class OllamaRuntime {
|
|
571
|
+
private readonly options;
|
|
572
|
+
constructor(options: OllamaRuntimeOptions);
|
|
573
|
+
/**
|
|
574
|
+
* Invoke an operation. Called by every generated API method.
|
|
575
|
+
*
|
|
576
|
+
* Returns a `Promise<T>` for non-streaming operations, or an
|
|
577
|
+
* `AsyncGenerator<T>` for streaming operations. The generated API
|
|
578
|
+
* class's overloads pick the right return type at compile time.
|
|
579
|
+
*/
|
|
580
|
+
invoke<T = unknown>(req: InvokeRequest): Promise<T>;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export { OllamaToolValidationError as $, type AbortableAsyncIterable as A, type BinaryBody as B, type ChatStreamResult as C, type DoneEvent as D, type ErrorEvent as E, type FetchLike as F, type GenerateStreamResult as G, HttpClient as H, OllamaMcpError as I, OllamaModelRoutingError as J, OllamaNetworkError as K, type Logger as L, type Middleware as M, NANOS_PER_MS as N, OllamaRuntime as O, type ProgressStreamResult as P, OllamaNotFoundError as Q, type RequestLifecycleHook as R, type SseEvent as S, type TokenUsage as T, OllamaQuotaExceededError as U, OllamaRateLimitError as V, OllamaServerError as W, OllamaSkillInvalidError as X, OllamaSkillNotFoundError as Y, OllamaTimeoutError as Z, OllamaToolTimeoutError as _, type OllamaStreamEvent as a, OllamaUnsupportedCapabilityError as a0, type RequestContext as a1, type RequestLifecycleEvent as a2, type ResponseContext as a3, type ThinkingEvent as a4, type TokenEvent as a5, type ToolCallEvent as a6, composeMiddleware as a7, createConsoleLogger as a8, extractUsage as a9, mapError as aa, parseSseStream as ab, type OperationDefinition as ac, type InvokeRequest as ad, type OllamaRuntimeOptions as ae, type SchemaRef as af, type OllamaStreamEventType as b, OllamaClientError as c, type RawUsageSource as d, type HttpBody as e, type HttpClientOptions as f, type HttpRequestOptions as g, type LifecycleErrorEvent as h, type LifecycleRetryEvent as i, type LifecycleStartEvent as j, type LifecycleSuccessEvent as k, type LogFn as l, type MessageEvent as m, type MiddlewareContext as n, NANOS_PER_SECOND as o, NOOP_LOGGER as p, type NextFunction as q, OllamaAbortError as r, OllamaAgentMaxIterationsError as s, OllamaAgentMaxToolCallsError as t, OllamaAuthError as u, type OllamaClientErrorOptions as v, type OllamaErrorRequestContext as w, type OllamaErrorResponseContext as x, OllamaGenericClientError as y, OllamaIncompatibleModelError as z };
|