@nemesis-oss/ollama-sdk 1.0.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.
@@ -0,0 +1,1044 @@
1
+ import { M as Message, C as ChatResponse, G as GenerateResponse, T as ToolCall, P as ProgressResponse, a as ModelResponse, S as ShowRequestOptions, b as ShowResponse, c as PullRequestOptions, d as PushRequestOptions, e as CreateRequestOptions, D as DeleteRequestOptions, f as StatusResponse, g as CopyRequestOptions, h as PsResponse, V as VersionResponse, i as ChatRequestOptions, j as GenerateRequestOptions, E as EmbedRequestOptions, k as EmbedResponse, l as EmbeddingsRequestOptions, m as EmbeddingsResponse, W as WebSearchRequestOptions, n as WebSearchResponse, o as WebFetchRequestOptions, p as WebFetchResponse, q as ToolHandler, r as Tool, A as AnyTool, s as ToolRegistry, t as ToolExecutionResult, u as ModelOptions, v as ToolDefinition } from './compose-DC11aDJn.cjs';
2
+ export { w as AppliedSkillResult, x as ApplySkillOptions, F as FormatOption, L as ListResponse, y as ModelDetails, z as ParsedFrontmatter, R as RequestCancellationOptions, B as Role, H as Skill, I as SkillFrontmatter, J as SkillSummary, K as ToolCallFunction, N as ToolExecutionContext, O as ToolExecutionFailure, Q as ToolExecutionSuccess, U as ToolFunctionDefinition, X as ToolProperty, Y as ToolRegistryOptions, Z as WebSearchResult, _ as applySkill, $ as parseFrontmatter } from './compose-DC11aDJn.cjs';
3
+ import { z } from 'zod';
4
+ import * as Otel from '@opentelemetry/api';
5
+
6
+ /**
7
+ * Structured, typed error hierarchy for OllamaClient.
8
+ */
9
+ interface OllamaErrorRequestContext {
10
+ readonly method?: string | undefined;
11
+ readonly url?: string | undefined;
12
+ readonly model?: string | undefined;
13
+ }
14
+ interface OllamaErrorResponseContext {
15
+ readonly status?: number | undefined;
16
+ readonly headers?: Record<string, string> | undefined;
17
+ readonly body?: unknown;
18
+ }
19
+ interface OllamaClientErrorOptions extends ErrorOptions {
20
+ readonly code: string;
21
+ readonly status?: number | undefined;
22
+ readonly retryable?: boolean | undefined;
23
+ readonly request?: OllamaErrorRequestContext | undefined;
24
+ readonly response?: OllamaErrorResponseContext | undefined;
25
+ }
26
+ declare class OllamaClientError extends Error {
27
+ readonly code: string;
28
+ readonly status?: number | undefined;
29
+ readonly retryable: boolean;
30
+ readonly request?: OllamaErrorRequestContext | undefined;
31
+ readonly response?: OllamaErrorResponseContext | undefined;
32
+ constructor(message: string, options: OllamaClientErrorOptions);
33
+ }
34
+ declare class OllamaNetworkError extends OllamaClientError {
35
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
36
+ }
37
+ declare class OllamaTimeoutError extends OllamaClientError {
38
+ readonly timeoutMs?: number | undefined;
39
+ constructor(message: string, options?: (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
40
+ timeoutMs?: number | undefined;
41
+ }) | undefined);
42
+ }
43
+ declare class OllamaAuthError extends OllamaClientError {
44
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
45
+ }
46
+ declare class OllamaNotFoundError extends OllamaClientError {
47
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
48
+ }
49
+ declare class OllamaRateLimitError extends OllamaClientError {
50
+ readonly retryAfterMs?: number | undefined;
51
+ constructor(message: string, options?: (Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
52
+ retryAfterMs?: number | undefined;
53
+ }) | undefined);
54
+ }
55
+ declare class OllamaServerError extends OllamaClientError {
56
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
57
+ }
58
+ declare class OllamaAbortError extends OllamaClientError {
59
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> | undefined);
60
+ }
61
+ declare class OllamaToolValidationError extends OllamaClientError {
62
+ readonly toolName: string;
63
+ readonly issues?: unknown;
64
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
65
+ toolName: string;
66
+ issues?: unknown;
67
+ });
68
+ }
69
+ declare class OllamaToolTimeoutError extends OllamaClientError {
70
+ readonly toolName: string;
71
+ readonly timeoutMs: number;
72
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
73
+ toolName: string;
74
+ timeoutMs: number;
75
+ });
76
+ }
77
+ /**
78
+ * Thrown client-side, before a network request is made, when a request asks for a
79
+ * capability an endpoint is known not to support (e.g. structured output `format` against
80
+ * an Ollama Cloud endpoint — see `ModelCapabilities.supportsStructuredOutputRequest` in
81
+ * `src/capabilities/capabilities.ts`). Its `code` is included in `DEFAULT_FAILOVER_CODES`
82
+ * by default, so in a multi-endpoint setup it causes failover to the next candidate rather
83
+ * than failing outright — it only surfaces to the caller if every candidate is rejected.
84
+ */
85
+ declare class OllamaUnsupportedCapabilityError extends OllamaClientError {
86
+ readonly capability: string;
87
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code' | 'retryable'> & {
88
+ capability: string;
89
+ });
90
+ }
91
+ declare class OllamaAgentMaxIterationsError extends OllamaClientError {
92
+ readonly maxIterations: number;
93
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
94
+ maxIterations: number;
95
+ });
96
+ }
97
+ declare class OllamaMcpError extends OllamaClientError {
98
+ readonly mcpMethod: 'listTools' | 'callTool';
99
+ readonly toolName?: string | undefined;
100
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
101
+ mcpMethod: 'listTools' | 'callTool';
102
+ toolName?: string | undefined;
103
+ });
104
+ }
105
+ declare class OllamaSkillNotFoundError extends OllamaClientError {
106
+ readonly skillName: string;
107
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
108
+ skillName: string;
109
+ });
110
+ }
111
+ declare class OllamaSkillInvalidError extends OllamaClientError {
112
+ readonly skillName: string;
113
+ readonly path?: string | undefined;
114
+ constructor(message: string, options: Omit<OllamaClientErrorOptions, 'code'> & {
115
+ skillName: string;
116
+ path?: string | undefined;
117
+ });
118
+ }
119
+ declare class OllamaGenericClientError extends OllamaClientError {
120
+ constructor(message: string, options?: Omit<OllamaClientErrorOptions, 'code'> | undefined);
121
+ }
122
+ /**
123
+ * Maps arbitrary thrown exceptions into structured OllamaClientError instances.
124
+ */
125
+ declare function mapError(error: unknown, context?: {
126
+ request?: OllamaErrorRequestContext | undefined;
127
+ response?: OllamaErrorResponseContext | undefined;
128
+ }): OllamaClientError;
129
+
130
+ /**
131
+ * Token usage and duration calculation utilities.
132
+ */
133
+ declare const NANOS_PER_MS = 1000000;
134
+ declare const NANOS_PER_SECOND = 1000000000;
135
+ interface TokenUsage {
136
+ readonly promptTokens: number;
137
+ readonly completionTokens: number;
138
+ readonly totalTokens: number;
139
+ readonly tokensPerSecond?: number | undefined;
140
+ readonly loadDurationMs?: number | undefined;
141
+ readonly promptEvalDurationMs?: number | undefined;
142
+ readonly evalDurationMs?: number | undefined;
143
+ readonly totalDurationMs?: number | undefined;
144
+ }
145
+ interface RawUsageSource {
146
+ readonly prompt_eval_count?: number | undefined;
147
+ readonly eval_count?: number | undefined;
148
+ readonly total_duration?: number | undefined;
149
+ readonly load_duration?: number | undefined;
150
+ readonly prompt_eval_duration?: number | undefined;
151
+ readonly eval_duration?: number | undefined;
152
+ }
153
+ /**
154
+ * Extracts and normalizes token usage metrics from an Ollama response.
155
+ */
156
+ declare function extractUsage(raw: RawUsageSource): TokenUsage;
157
+
158
+ /**
159
+ * Streaming event types, listener contracts, and aggregated result shapes.
160
+ */
161
+
162
+ interface TokenEvent {
163
+ readonly type: 'token';
164
+ readonly data: {
165
+ readonly delta: string;
166
+ readonly role?: string | undefined;
167
+ };
168
+ }
169
+ interface ThinkingEvent {
170
+ readonly type: 'thinking';
171
+ readonly data: {
172
+ readonly delta: string;
173
+ };
174
+ }
175
+ interface ToolCallEvent {
176
+ readonly type: 'tool_call';
177
+ readonly data: {
178
+ readonly toolCall: ToolCall;
179
+ };
180
+ }
181
+ interface MessageEvent<TChunk> {
182
+ readonly type: 'message';
183
+ readonly data: {
184
+ readonly chunk: TChunk;
185
+ };
186
+ }
187
+ interface DoneEvent<TFinal> {
188
+ readonly type: 'done';
189
+ readonly data: {
190
+ readonly result: TFinal;
191
+ };
192
+ }
193
+ interface ErrorEvent {
194
+ readonly type: 'error';
195
+ readonly data: {
196
+ readonly error: OllamaClientError;
197
+ };
198
+ }
199
+ type OllamaStreamEvent<TChunk, TFinal> = TokenEvent | ThinkingEvent | ToolCallEvent | MessageEvent<TChunk> | DoneEvent<TFinal> | ErrorEvent;
200
+ type OllamaStreamEventType = OllamaStreamEvent<unknown, unknown>['type'];
201
+ interface ChatStreamResult {
202
+ readonly message: Message;
203
+ readonly model: string;
204
+ readonly done: boolean;
205
+ readonly totalDurationMs?: number | undefined;
206
+ readonly usage?: TokenUsage | undefined;
207
+ readonly raw?: ChatResponse | undefined;
208
+ }
209
+ interface GenerateStreamResult {
210
+ readonly response: string;
211
+ readonly model: string;
212
+ readonly done: boolean;
213
+ readonly totalDurationMs?: number | undefined;
214
+ readonly usage?: TokenUsage | undefined;
215
+ readonly raw?: GenerateResponse | undefined;
216
+ }
217
+ interface ProgressStreamResult {
218
+ readonly status: string;
219
+ readonly completed?: number | undefined;
220
+ readonly total?: number | undefined;
221
+ readonly done: boolean;
222
+ readonly raw?: ProgressResponse | undefined;
223
+ }
224
+ interface AbortableAsyncIterable<T> extends AsyncIterable<T> {
225
+ abort?: (() => void) | undefined;
226
+ }
227
+
228
+ /**
229
+ * Structured logger and request lifecycle interfaces.
230
+ */
231
+ interface LogFn {
232
+ (message: string, context?: Record<string, unknown>): void;
233
+ }
234
+ interface Logger {
235
+ readonly debug: LogFn;
236
+ readonly info: LogFn;
237
+ readonly warn: LogFn;
238
+ readonly error: LogFn;
239
+ }
240
+ interface LifecycleStartEvent {
241
+ readonly type: 'start';
242
+ readonly requestId: string;
243
+ readonly method: string;
244
+ readonly url: string;
245
+ readonly timestamp: number;
246
+ }
247
+ interface LifecycleSuccessEvent {
248
+ readonly type: 'success';
249
+ readonly requestId: string;
250
+ readonly durationMs: number;
251
+ readonly status: number;
252
+ readonly timestamp: number;
253
+ }
254
+ interface LifecycleRetryEvent {
255
+ readonly type: 'retry';
256
+ readonly requestId: string;
257
+ readonly attempt: number;
258
+ readonly error: Error;
259
+ readonly delayMs: number;
260
+ readonly timestamp: number;
261
+ }
262
+ interface LifecycleErrorEvent {
263
+ readonly type: 'error';
264
+ readonly requestId: string;
265
+ readonly durationMs: number;
266
+ readonly error: Error;
267
+ readonly timestamp: number;
268
+ }
269
+ type RequestLifecycleEvent = LifecycleStartEvent | LifecycleSuccessEvent | LifecycleRetryEvent | LifecycleErrorEvent;
270
+ interface RequestLifecycleHook {
271
+ (event: RequestLifecycleEvent): void;
272
+ }
273
+ declare const NOOP_LOGGER: Logger;
274
+ declare function createConsoleLogger(prefix?: string): Logger;
275
+
276
+ /**
277
+ * Request/response middleware pipeline.
278
+ */
279
+ interface RequestContext {
280
+ readonly url: string;
281
+ readonly method: string;
282
+ readonly headers: Record<string, string>;
283
+ readonly body?: unknown;
284
+ readonly signal?: AbortSignal;
285
+ }
286
+ interface ResponseContext {
287
+ readonly status: number;
288
+ readonly headers: Record<string, string>;
289
+ readonly body: unknown;
290
+ }
291
+ type NextFunction = () => Promise<ResponseContext>;
292
+ interface MiddlewareContext {
293
+ readonly request: RequestContext;
294
+ readonly next: NextFunction;
295
+ }
296
+ interface Middleware {
297
+ (ctx: MiddlewareContext): Promise<ResponseContext>;
298
+ }
299
+ declare function composeMiddleware(middlewares: readonly Middleware[], finalHandler: (req: RequestContext) => Promise<ResponseContext>): (req: RequestContext) => Promise<ResponseContext>;
300
+
301
+ /**
302
+ * Exponential backoff with full jitter calculation.
303
+ */
304
+ interface BackoffOptions {
305
+ readonly initialDelayMs: number;
306
+ readonly maxDelayMs: number;
307
+ readonly backoffFactor: number;
308
+ }
309
+ declare const DEFAULT_BACKOFF: BackoffOptions;
310
+ /**
311
+ * Calculates exponential backoff with full jitter for attempt (0-indexed).
312
+ */
313
+ declare function calculateBackoff(attempt: number, options?: BackoffOptions): number;
314
+
315
+ /**
316
+ * Retry policy and execution runner.
317
+ */
318
+
319
+ interface RetryConfig {
320
+ readonly maxRetries: number;
321
+ readonly backoff: BackoffOptions;
322
+ readonly shouldRetry?: (error: Error, attempt: number) => boolean;
323
+ readonly onRetry?: (error: Error, attempt: number, delayMs: number) => void;
324
+ }
325
+ declare const DEFAULT_RETRY_CONFIG: RetryConfig;
326
+ /**
327
+ * Executes an async operation with retries according to config.
328
+ */
329
+ declare function withRetry<T>(operation: (attempt: number) => Promise<T>, config?: RetryConfig): Promise<T>;
330
+
331
+ /**
332
+ * Native fetch HTTP transport client for Ollama API.
333
+ */
334
+
335
+ type FetchLike = typeof globalThis.fetch;
336
+ type BinaryBody = Uint8Array | ArrayBuffer | string | Blob | ReadableStream<Uint8Array>;
337
+ type HttpBody = unknown;
338
+ interface HttpClientOptions {
339
+ readonly baseUrl: string;
340
+ readonly apiKey?: string | undefined;
341
+ readonly headers?: Record<string, string> | undefined;
342
+ readonly fetch?: FetchLike | undefined;
343
+ }
344
+ interface HttpRequestOptions {
345
+ readonly path: string;
346
+ readonly method?: 'GET' | 'POST' | 'DELETE' | 'HEAD' | undefined;
347
+ readonly body?: HttpBody;
348
+ readonly rawBody?: BinaryBody | undefined;
349
+ readonly headers?: Record<string, string> | undefined;
350
+ readonly signal?: AbortSignal | undefined;
351
+ }
352
+ declare class HttpClient {
353
+ readonly baseUrl: string;
354
+ private readonly apiKey?;
355
+ private readonly defaultHeaders;
356
+ private readonly fetchImpl;
357
+ constructor(options: HttpClientOptions);
358
+ private buildHeaders;
359
+ request<T>(options: HttpRequestOptions): Promise<T>;
360
+ requestStream<T>(options: HttpRequestOptions): Promise<AbortableAsyncIterable<T>>;
361
+ }
362
+
363
+ /**
364
+ * Multi-endpoint registry with priority routing and circuit breaker failover.
365
+ */
366
+ interface OllamaEndpoint {
367
+ readonly name: string;
368
+ readonly baseUrl: string;
369
+ readonly apiKey?: string | undefined;
370
+ readonly headers?: Record<string, string> | undefined;
371
+ readonly priority?: number | undefined;
372
+ }
373
+ interface EndpointHealth {
374
+ readonly endpoint: OllamaEndpoint;
375
+ readonly failureCount: number;
376
+ readonly lastFailureTimestamp?: number | undefined;
377
+ readonly isCoolingDown: boolean;
378
+ }
379
+ interface EndpointRegistryOptions {
380
+ readonly failureThreshold?: number | undefined;
381
+ readonly cooldownMs?: number | undefined;
382
+ readonly now?: (() => number) | undefined;
383
+ }
384
+ declare class EndpointRegistry {
385
+ private readonly endpoints;
386
+ private readonly failureCounts;
387
+ private readonly lastFailures;
388
+ private readonly failureThreshold;
389
+ private readonly cooldownMs;
390
+ private readonly now;
391
+ constructor(endpoints: readonly OllamaEndpoint[], options?: EndpointRegistryOptions);
392
+ candidates(): OllamaEndpoint[];
393
+ reportSuccess(name: string): void;
394
+ reportFailure(name: string): void;
395
+ list(): readonly OllamaEndpoint[];
396
+ status(): EndpointHealth[];
397
+ }
398
+
399
+ /**
400
+ * Configuration options and constants for OllamaClient.
401
+ */
402
+
403
+ declare const DEFAULT_BASE_URL = "http://localhost:11434";
404
+ declare const DEFAULT_TIMEOUT_MS = 30000;
405
+ declare const DEFAULT_FAILOVER_CODES: readonly string[];
406
+ interface OllamaClientConfig {
407
+ /**
408
+ * Base URL of a single Ollama server. Ignored if `endpoints` is provided. Falls back to
409
+ * the `OLLAMA_HOST` environment variable (when set and running under Node), then
410
+ * `http://localhost:11434`.
411
+ */
412
+ readonly baseUrl?: string;
413
+ /**
414
+ * Bearer token sent as `Authorization: Bearer <apiKey>` for a single-endpoint setup.
415
+ * Falls back to the `OLLAMA_API_KEY` environment variable (when set and running under
416
+ * Node).
417
+ */
418
+ readonly apiKey?: string;
419
+ /** Static headers merged into every request. */
420
+ readonly headers?: Record<string, string>;
421
+ /** Multiple named endpoints for rotation and automatic failover. */
422
+ readonly endpoints?: readonly OllamaEndpoint[];
423
+ /** Tuning options for endpoint circuit breaker. */
424
+ readonly endpointHealth?: EndpointRegistryOptions;
425
+ /** Error codes that trigger failover to the next candidate endpoint. */
426
+ readonly failoverOn?: readonly string[];
427
+ /** Default per-request timeout in milliseconds (default 30_000ms). */
428
+ readonly timeoutMs?: number;
429
+ /** Retry configuration or retry count override. */
430
+ readonly retries?: number | Partial<RetryConfig>;
431
+ /** Custom fetch implementation (defaults to globalThis.fetch). */
432
+ readonly fetch?: FetchLike;
433
+ /** Request/Response middleware list. */
434
+ readonly middleware?: readonly Middleware[];
435
+ /** Structured logger. */
436
+ readonly logger?: Logger;
437
+ /** Enables console debug logger if true. */
438
+ readonly debug?: boolean;
439
+ /** Request lifecycle hook for telemetry/metrics. */
440
+ readonly onLifecycleEvent?: RequestLifecycleHook;
441
+ }
442
+
443
+ /**
444
+ * Active endpoint health pinging utility.
445
+ */
446
+
447
+ interface EndpointHealthCheckResult {
448
+ readonly name: string;
449
+ readonly baseUrl: string;
450
+ readonly reachable: boolean;
451
+ readonly latencyMs: number;
452
+ readonly version?: string;
453
+ readonly error?: string;
454
+ }
455
+ declare function checkEndpointHealth(endpoint: OllamaEndpoint, fetchImpl?: FetchLike, timeoutMs?: number): Promise<EndpointHealthCheckResult>;
456
+
457
+ /**
458
+ * Model capability detection and runtime environment inference.
459
+ */
460
+
461
+ type RuntimeMode = 'local' | 'cloud' | 'unknown';
462
+ interface ModelCapabilities {
463
+ readonly model: string;
464
+ readonly reported: readonly string[];
465
+ readonly supportsTools: boolean;
466
+ readonly supportsVision: boolean;
467
+ readonly supportsEmbedding: boolean;
468
+ readonly supportsCompletion: boolean;
469
+ readonly supportsThinking: boolean;
470
+ readonly supportsStreaming: true;
471
+ /**
472
+ * Best-effort inference, not a guarantee: Ollama's `/api/show` does not report structured
473
+ * output support as a queryable capability, so this is inferred from {@link inferRuntimeMode}
474
+ * — `false` for `cloud`, since Ollama Cloud does not currently support structured outputs;
475
+ * `true` for `local`/`unknown`. A locally-hosted model that genuinely can't follow a JSON
476
+ * schema will still report `true` here; the request itself is the only reliable way to find
477
+ * out. `OllamaClient.chat`/`generate` apply this same inference as a fail-fast pre-flight
478
+ * guard whenever `format` is set, throwing `OllamaUnsupportedCapabilityError` rather than
479
+ * making a network call that Ollama Cloud is known to reject.
480
+ */
481
+ readonly supportsStructuredOutputRequest: boolean;
482
+ }
483
+ declare function inferRuntimeMode(baseUrl: string): RuntimeMode;
484
+ declare function detectModelCapabilities(http: HttpClient, model: string): Promise<ModelCapabilities>;
485
+ declare function listAvailableModels(http: HttpClient): Promise<ModelResponse[]>;
486
+
487
+ /**
488
+ * Dual-mode (AsyncIterator and EventEmitter-like) stream wrapper.
489
+ */
490
+
491
+ type ChunkMapper<TChunk, TFinal> = (chunk: TChunk, accumulated: TFinal) => Array<OllamaStreamEvent<TChunk, TFinal>>;
492
+ type Aggregator<TChunk, TFinal> = (accumulated: TFinal, chunk: TChunk) => TFinal;
493
+ declare class OllamaStream<TChunk, TFinal> implements AsyncIterable<OllamaStreamEvent<TChunk, TFinal>> {
494
+ private readonly source;
495
+ private readonly mapChunk;
496
+ private readonly aggregate;
497
+ private readonly initial;
498
+ private mode;
499
+ private readonly listeners;
500
+ private readonly finalResultPromise;
501
+ private resolveFinal;
502
+ private rejectFinal;
503
+ constructor(source: AbortableAsyncIterable<TChunk>, mapChunk: ChunkMapper<TChunk, TFinal>, aggregate: Aggregator<TChunk, TFinal>, initial: TFinal);
504
+ get finalResult(): Promise<TFinal>;
505
+ abort(): void;
506
+ on<TType extends OllamaStreamEventType>(type: TType, listener: (event: Extract<OllamaStreamEvent<TChunk, TFinal>, {
507
+ type: TType;
508
+ }>) => void): () => void;
509
+ private emit;
510
+ private pump;
511
+ [Symbol.asyncIterator](): AsyncGenerator<OllamaStreamEvent<TChunk, TFinal>, void, undefined>;
512
+ }
513
+
514
+ /**
515
+ * Model and blob management operations.
516
+ */
517
+
518
+ type RequestRunner = <T>(op: (http: HttpClient, signal: AbortSignal) => Promise<T>, opts?: {
519
+ signal?: AbortSignal | undefined;
520
+ timeoutMs?: number | undefined;
521
+ singleEndpoint?: boolean | undefined;
522
+ }) => Promise<T>;
523
+ /**
524
+ * Every operation here targets one specific Ollama server's local model catalog or blob
525
+ * store — unlike `chat`/`generate`/`embed`, a different endpoint isn't an interchangeable
526
+ * substitute; it's a different catalog/store entirely. `singleEndpoint: true` disables
527
+ * `OllamaClient`'s cross-endpoint failover for these calls (same-endpoint retry via
528
+ * `withRetry` still applies), so a multi-endpoint setup never silently lists/mutates the
529
+ * wrong server just because the intended one had a transient failure. See ADR 0008.
530
+ */
531
+ declare class ModelsClient {
532
+ private readonly runner;
533
+ constructor(runner: RequestRunner);
534
+ list(): Promise<ModelResponse[]>;
535
+ show(request: ShowRequestOptions): Promise<ShowResponse>;
536
+ pull(request: PullRequestOptions & {
537
+ stream: true;
538
+ }): Promise<OllamaStream<ProgressResponse, ProgressStreamResult>>;
539
+ pull(request: PullRequestOptions & {
540
+ stream?: false | undefined;
541
+ }): Promise<ProgressResponse>;
542
+ pull(request: PullRequestOptions): Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
543
+ push(request: PushRequestOptions & {
544
+ stream: true;
545
+ }): Promise<OllamaStream<ProgressResponse, ProgressStreamResult>>;
546
+ push(request: PushRequestOptions & {
547
+ stream?: false | undefined;
548
+ }): Promise<ProgressResponse>;
549
+ push(request: PushRequestOptions): Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
550
+ create(request: CreateRequestOptions & {
551
+ stream: true;
552
+ }): Promise<OllamaStream<ProgressResponse, ProgressStreamResult>>;
553
+ create(request: CreateRequestOptions & {
554
+ stream?: false | undefined;
555
+ }): Promise<ProgressResponse>;
556
+ create(request: CreateRequestOptions): Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
557
+ delete(request: DeleteRequestOptions): Promise<StatusResponse>;
558
+ copy(request: CopyRequestOptions): Promise<StatusResponse>;
559
+ ps(): Promise<PsResponse>;
560
+ version(): Promise<VersionResponse>;
561
+ createBlob(digest: string, data: BinaryBody): Promise<void>;
562
+ checkBlob(digest: string): Promise<boolean>;
563
+ }
564
+
565
+ /**
566
+ * OpenAI Compatibility interfaces and client helpers for Ollama.
567
+ * Ollama exposes OpenAI-compatible /v1 endpoints.
568
+ *
569
+ * @remarks
570
+ * This is a typed pass-through to Ollama's own OpenAI-compatible `/v1` endpoints — it
571
+ * implements the subset of the OpenAI Chat Completions API that Ollama documents as
572
+ * supported (https://docs.ollama.com/api/openai-compatibility), not the full OpenAI
573
+ * surface (Responses API, hosted tools like web/file search, computer use, code
574
+ * interpreter, or server-side conversation state). Notably, `tools` is supported by
575
+ * Ollama's compat layer but `tool_choice` and `parallel_tool_calls` are explicitly
576
+ * **not** — deliberately omitted from {@link OpenAIChatCompletionRequest} rather than
577
+ * typed as accepted-but-ignored.
578
+ */
579
+
580
+ interface OpenAIToolCall {
581
+ readonly id: string;
582
+ readonly type: 'function';
583
+ readonly function: {
584
+ readonly name: string;
585
+ /** JSON-encoded arguments string, matching OpenAI's wire format (not a parsed object). */
586
+ readonly arguments: string;
587
+ };
588
+ }
589
+ interface OpenAIMessage {
590
+ readonly role: 'system' | 'user' | 'assistant' | 'tool';
591
+ readonly content: string;
592
+ readonly name?: string | undefined;
593
+ readonly tool_calls?: readonly OpenAIToolCall[] | undefined;
594
+ /** Set on a `role: 'tool'` message to identify which call this is a result for. */
595
+ readonly tool_call_id?: string | undefined;
596
+ }
597
+ interface OpenAIStreamOptions {
598
+ /** Emit a final SSE chunk carrying `usage` (prompt/completion/total tokens) before `[DONE]`. */
599
+ readonly include_usage?: boolean | undefined;
600
+ }
601
+ interface OpenAIFunctionDefinition {
602
+ readonly name: string;
603
+ readonly description?: string | undefined;
604
+ readonly parameters?: Record<string, unknown> | undefined;
605
+ }
606
+ interface OpenAITool {
607
+ readonly type: 'function';
608
+ readonly function: OpenAIFunctionDefinition;
609
+ }
610
+ interface OpenAIChatCompletionRequest {
611
+ readonly model: string;
612
+ readonly messages: readonly OpenAIMessage[];
613
+ readonly temperature?: number | undefined;
614
+ readonly top_p?: number | undefined;
615
+ readonly stream?: boolean | undefined;
616
+ /** Only meaningful when `stream: true`; ignored otherwise. */
617
+ readonly stream_options?: OpenAIStreamOptions | undefined;
618
+ readonly max_tokens?: number | undefined;
619
+ readonly stop?: readonly string[] | undefined;
620
+ readonly presence_penalty?: number | undefined;
621
+ readonly frequency_penalty?: number | undefined;
622
+ readonly user?: string | undefined;
623
+ readonly tools?: readonly OpenAITool[] | undefined;
624
+ }
625
+ interface OpenAIChatCompletionChoice {
626
+ readonly index: number;
627
+ readonly message: OpenAIMessage;
628
+ readonly finish_reason: string;
629
+ }
630
+ interface OpenAIChatCompletionResponse {
631
+ readonly id: string;
632
+ readonly object: 'chat.completion';
633
+ readonly created: number;
634
+ readonly model: string;
635
+ readonly choices: readonly OpenAIChatCompletionChoice[];
636
+ readonly usage?: {
637
+ readonly prompt_tokens: number;
638
+ readonly completion_tokens: number;
639
+ readonly total_tokens: number;
640
+ } | undefined;
641
+ }
642
+ interface OpenAIModelItem {
643
+ readonly id: string;
644
+ readonly object: 'model';
645
+ readonly created: number;
646
+ readonly owned_by: string;
647
+ }
648
+ interface OpenAIListModelsResponse {
649
+ readonly object: 'list';
650
+ readonly data: readonly OpenAIModelItem[];
651
+ }
652
+ declare class OpenAICompatClient {
653
+ private readonly http;
654
+ constructor(http: HttpClient);
655
+ createChatCompletion(request: OpenAIChatCompletionRequest, signal?: AbortSignal): Promise<OpenAIChatCompletionResponse>;
656
+ chatCompletions(request: OpenAIChatCompletionRequest, signal?: AbortSignal): Promise<OpenAIChatCompletionResponse>;
657
+ listModels(signal?: AbortSignal): Promise<OpenAIListModelsResponse>;
658
+ }
659
+
660
+ /**
661
+ * Anthropic Compatibility interfaces and client helpers for Ollama.
662
+ * Ollama supports Anthropic Messages API format.
663
+ *
664
+ * @remarks
665
+ * This is a typed pass-through to Ollama's Anthropic-compatible `/v1/messages` endpoint
666
+ * — a subset of Anthropic's Messages API (text content, system prompt, sampling
667
+ * parameters, ephemeral prompt-caching hints via `cache_control`), not the full Anthropic
668
+ * surface. Tool use (`tool_use`/`tool_result` content blocks), extended thinking,
669
+ * citations, files, token counting, and the Batches API are not modeled here.
670
+ */
671
+
672
+ interface AnthropicCacheControl {
673
+ readonly type: 'ephemeral';
674
+ }
675
+ interface AnthropicContentBlock {
676
+ readonly type: 'text';
677
+ readonly text: string;
678
+ /** Marks this block as a prompt-caching breakpoint (Anthropic's ephemeral cache). */
679
+ readonly cache_control?: AnthropicCacheControl | undefined;
680
+ }
681
+ interface AnthropicMessage {
682
+ readonly role: 'user' | 'assistant';
683
+ readonly content: string | readonly AnthropicContentBlock[];
684
+ }
685
+ interface AnthropicMessagesRequest {
686
+ readonly model: string;
687
+ readonly messages: readonly AnthropicMessage[];
688
+ readonly system?: string | undefined;
689
+ readonly max_tokens?: number | undefined;
690
+ readonly temperature?: number | undefined;
691
+ readonly top_p?: number | undefined;
692
+ readonly top_k?: number | undefined;
693
+ readonly stream?: boolean | undefined;
694
+ }
695
+ interface AnthropicMessagesResponse {
696
+ readonly id: string;
697
+ readonly type: 'message';
698
+ readonly role: 'assistant';
699
+ readonly content: readonly AnthropicContentBlock[];
700
+ readonly model: string;
701
+ readonly stop_reason: string;
702
+ readonly usage?: {
703
+ readonly input_tokens: number;
704
+ readonly output_tokens: number;
705
+ } | undefined;
706
+ }
707
+ declare class AnthropicCompatClient {
708
+ private readonly http;
709
+ constructor(http: HttpClient);
710
+ createMessage(request: AnthropicMessagesRequest, signal?: AbortSignal): Promise<AnthropicMessagesResponse>;
711
+ messages(request: AnthropicMessagesRequest, signal?: AbortSignal): Promise<AnthropicMessagesResponse>;
712
+ }
713
+
714
+ declare class OllamaClient {
715
+ readonly registry: EndpointRegistry;
716
+ readonly models: ModelsClient;
717
+ private readonly retryConfig;
718
+ private readonly timeoutMs;
719
+ private readonly failoverCodes;
720
+ private readonly fetchImpl;
721
+ private readonly logger;
722
+ constructor(config?: OllamaClientConfig);
723
+ get modelsClient(): ModelsClient;
724
+ /**
725
+ * Fail-fast guard for `format` (structured output) requests: throws before any network
726
+ * call if the candidate endpoint is inferred as Ollama Cloud, which does not currently
727
+ * support structured outputs (see `ModelCapabilities.supportsStructuredOutputRequest`).
728
+ * `unsupported_capability` is in `DEFAULT_FAILOVER_CODES`, so in a multi-endpoint setup
729
+ * this causes failover to the next candidate rather than failing the whole request.
730
+ */
731
+ private assertStructuredOutputSupported;
732
+ executeWithFailover<T>(operation: (http: HttpClient, signal: AbortSignal) => Promise<T>, options?: {
733
+ signal?: AbortSignal | undefined;
734
+ timeoutMs?: number | undefined;
735
+ /**
736
+ * Disables cross-endpoint failover: only the single best candidate endpoint is
737
+ * tried (same-endpoint retry via `withRetry` still applies). For operations whose
738
+ * target IS the endpoint — model catalog/blob management — a different endpoint
739
+ * isn't an interchangeable substitute, so failing over to one would silently
740
+ * operate on the wrong server's state rather than retrying "the same" request. See
741
+ * ADR 0008. Defaults to `false`, preserving normal failover for inference calls.
742
+ */
743
+ singleEndpoint?: boolean | undefined;
744
+ }): Promise<T>;
745
+ chat(req: ChatRequestOptions & {
746
+ stream: true;
747
+ }): Promise<OllamaStream<ChatResponse, ChatStreamResult>>;
748
+ chat(req: ChatRequestOptions & {
749
+ stream?: false | undefined;
750
+ }): Promise<ChatResponse>;
751
+ chat(req: ChatRequestOptions): Promise<ChatResponse | OllamaStream<ChatResponse, ChatStreamResult>>;
752
+ chatStream(req: Omit<ChatRequestOptions, 'stream'>): Promise<OllamaStream<ChatResponse, ChatStreamResult>>;
753
+ chatText(req: Omit<ChatRequestOptions, 'stream'>): Promise<string>;
754
+ chatWithSchema<T>(req: Omit<ChatRequestOptions, 'stream' | 'format'>, schema: z.ZodType<T>): Promise<T>;
755
+ generate(req: GenerateRequestOptions & {
756
+ stream: true;
757
+ }): Promise<OllamaStream<GenerateResponse, GenerateStreamResult>>;
758
+ generate(req: GenerateRequestOptions & {
759
+ stream?: false | undefined;
760
+ }): Promise<GenerateResponse>;
761
+ generate(req: GenerateRequestOptions): Promise<GenerateResponse | OllamaStream<GenerateResponse, GenerateStreamResult>>;
762
+ generateStream(req: Omit<GenerateRequestOptions, 'stream'>): Promise<OllamaStream<GenerateResponse, GenerateStreamResult>>;
763
+ generateText(req: Omit<GenerateRequestOptions, 'stream'>): Promise<string>;
764
+ generateWithSchema<T>(req: Omit<GenerateRequestOptions, 'stream' | 'format'>, schema: z.ZodType<T>): Promise<T>;
765
+ embed(req: EmbedRequestOptions): Promise<EmbedResponse>;
766
+ embedText(model: string, input: string | readonly string[]): Promise<readonly (readonly number[])[]>;
767
+ /**
768
+ * @deprecated Ollama's `/api/embeddings` endpoint has been superseded by `/api/embed`
769
+ * (exposed here as {@link OllamaClient.embed}), which additionally supports batch
770
+ * input. Kept for compatibility with existing callers; new code should use `embed`.
771
+ */
772
+ embeddings(req: EmbeddingsRequestOptions): Promise<EmbeddingsResponse>;
773
+ readonly listModels: () => Promise<ModelResponse[]>;
774
+ readonly showModel: (req: ShowRequestOptions) => Promise<ShowResponse>;
775
+ readonly pullModel: (r: PullRequestOptions) => Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
776
+ readonly pushModel: (r: PushRequestOptions) => Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
777
+ readonly createModel: (r: CreateRequestOptions) => Promise<ProgressResponse | OllamaStream<ProgressResponse, ProgressStreamResult>>;
778
+ readonly deleteModel: (req: DeleteRequestOptions) => Promise<StatusResponse>;
779
+ readonly copyModel: (req: CopyRequestOptions) => Promise<StatusResponse>;
780
+ readonly ps: () => Promise<PsResponse>;
781
+ readonly version: () => Promise<VersionResponse>;
782
+ readonly createBlob: (digest: string, data: BinaryBody) => Promise<void>;
783
+ readonly checkBlob: (digest: string) => Promise<boolean>;
784
+ webSearch(req: WebSearchRequestOptions): Promise<WebSearchResponse>;
785
+ webFetch(req: WebFetchRequestOptions): Promise<WebFetchResponse>;
786
+ capabilities(model: string): Promise<ModelCapabilities>;
787
+ runtimeMode(): RuntimeMode;
788
+ healthCheck(): Promise<EndpointHealthCheckResult[]>;
789
+ endpointStatus(): EndpointHealth[];
790
+ get openai(): OpenAICompatClient;
791
+ get anthropic(): AnthropicCompatClient;
792
+ }
793
+
794
+ /**
795
+ * AbortSignal and timeout management for HTTP requests.
796
+ */
797
+ interface TimeoutSignal {
798
+ readonly signal: AbortSignal;
799
+ readonly cancel: () => void;
800
+ }
801
+ /**
802
+ * Combines an optional timeout with an optional caller-provided AbortSignal.
803
+ */
804
+ declare function createTimeoutSignal(timeoutMs?: number, userSignal?: AbortSignal): TimeoutSignal;
805
+
806
+ /**
807
+ * Normalization mappers and aggregators for Ollama streaming responses.
808
+ */
809
+
810
+ declare function normalizeChatStream(source: AbortableAsyncIterable<ChatResponse>): OllamaStream<ChatResponse, ChatStreamResult>;
811
+ declare function normalizeGenerateStream(source: AbortableAsyncIterable<GenerateResponse>): OllamaStream<GenerateResponse, GenerateStreamResult>;
812
+ declare function normalizeProgressStream(source: AbortableAsyncIterable<ProgressResponse>): OllamaStream<ProgressResponse, ProgressStreamResult>;
813
+
814
+ /**
815
+ * NDJSON (newline-delimited JSON) stream reader for native fetch Response bodies.
816
+ */
817
+ /**
818
+ * Parses a byte stream from fetch body into an async generator of typed JSON chunks.
819
+ */
820
+ declare function parseNdjsonStream<T>(stream: ReadableStream<Uint8Array>): AsyncGenerator<T, void, undefined>;
821
+
822
+ /**
823
+ * Web Standard Stream adapters for OllamaStream.
824
+ * Enables seamless integration with Vercel AI SDK, Next.js route handlers, and standard web fetch responses.
825
+ */
826
+
827
+ /**
828
+ * Transforms an OllamaStream into a standard Web ReadableStream of token text strings.
829
+ */
830
+ declare function toTextStream<TChunk, TFinal>(stream: OllamaStream<TChunk, TFinal>): ReadableStream<string>;
831
+ /**
832
+ * Transforms an OllamaStream into a standard Web ReadableStream of encoded Uint8Array bytes.
833
+ */
834
+ declare function toDataStream<TChunk, TFinal>(stream: OllamaStream<TChunk, TFinal>): ReadableStream<Uint8Array>;
835
+ /**
836
+ * Converts an OllamaStream directly into a standard Web Response with text/plain streaming headers.
837
+ */
838
+ declare function toResponse<TChunk, TFinal>(stream: OllamaStream<TChunk, TFinal>, init?: ResponseInit): Response;
839
+
840
+ /**
841
+ * Zod schema conversion to JSON Schema for Ollama structured outputs.
842
+ */
843
+
844
+ type SupportedSchema<T = unknown> = z.ZodType<T>;
845
+ /**
846
+ * Converts a Zod schema into a JSON Schema object accepted by Ollama's `format` parameter.
847
+ *
848
+ * Uses Zod v4's native `z.toJSONSchema` when available, falling back to a structural
849
+ * walk of Zod v3's internal `_def` shape so both major versions work as peer dependencies.
850
+ */
851
+ declare function zodToJsonSchema<T>(schema: z.ZodType<T>): Record<string, unknown>;
852
+ /**
853
+ * Parses and validates a JSON output string against a Zod schema.
854
+ */
855
+ declare function parseStructuredOutput<T>(rawJson: string, schema: z.ZodType<T>, toolName?: string): T;
856
+
857
+ /**
858
+ * Type-safe tool definition helper.
859
+ */
860
+
861
+ interface DefineToolOptions<TParams, TResult> {
862
+ readonly name: string;
863
+ readonly description: string;
864
+ readonly schema: z.ZodType<TParams>;
865
+ readonly execute: ToolHandler<TParams, TResult>;
866
+ /**
867
+ * Per-tool execution timeout in milliseconds, overriding the registry's default.
868
+ * Pass `0` to explicitly disable timeout enforcement for this tool.
869
+ */
870
+ readonly timeoutMs?: number | undefined;
871
+ }
872
+ /**
873
+ * Creates a strongly-typed Tool definition with automatic JSON Schema conversion.
874
+ */
875
+ declare function defineTool<TParams, TResult>(options: DefineToolOptions<TParams, TResult>): Tool<TParams, TResult>;
876
+
877
+ /**
878
+ * Duck-typed MCP (Model Context Protocol) client interfaces.
879
+ * Decoupled from any specific MCP SDK.
880
+ */
881
+ interface McpToolDescriptor {
882
+ readonly name: string;
883
+ readonly description?: string;
884
+ readonly inputSchema?: Record<string, unknown>;
885
+ }
886
+ interface McpListToolsResult {
887
+ readonly tools: readonly McpToolDescriptor[];
888
+ }
889
+ interface McpContentBlock {
890
+ readonly type: string;
891
+ readonly text?: string;
892
+ readonly [key: string]: unknown;
893
+ }
894
+ interface McpCallToolResult {
895
+ readonly content: readonly McpContentBlock[];
896
+ readonly isError?: boolean;
897
+ }
898
+ interface McpClientLike {
899
+ listTools: () => Promise<McpListToolsResult>;
900
+ callTool: (params: {
901
+ readonly name: string;
902
+ readonly arguments?: Record<string, unknown>;
903
+ }) => Promise<McpCallToolResult>;
904
+ }
905
+
906
+ /**
907
+ * Converts MCP tools into Ollama-compatible tools.
908
+ */
909
+
910
+ interface LoadMcpToolsOptions {
911
+ readonly namePrefix?: string;
912
+ }
913
+ declare function loadMcpTools(mcpClient: McpClientLike, options?: LoadMcpToolsOptions): Promise<AnyTool[]>;
914
+ declare function registerMcpTools(registry: ToolRegistry, mcpClient: McpClientLike, options?: LoadMcpToolsOptions): Promise<void>;
915
+
916
+ /**
917
+ * Agent loop options, turn state, and execution hooks.
918
+ */
919
+
920
+ interface AgentTurn {
921
+ readonly iteration: number;
922
+ readonly message: Message;
923
+ readonly toolCalls?: readonly ToolCall[] | undefined;
924
+ readonly toolResults?: readonly ToolExecutionResult[] | undefined;
925
+ }
926
+ interface AgentResult {
927
+ readonly finalMessage: Message;
928
+ readonly turns: readonly AgentTurn[];
929
+ readonly totalIterations: number;
930
+ }
931
+ interface AgentHooks {
932
+ readonly onTurnStart?: ((iteration: number) => void) | undefined;
933
+ readonly onToken?: ((delta: string) => void) | undefined;
934
+ readonly onThinking?: ((delta: string) => void) | undefined;
935
+ readonly onToolCallStart?: ((toolCall: ToolCall) => void) | undefined;
936
+ readonly onToolCallEnd?: ((result: ToolExecutionResult) => void) | undefined;
937
+ readonly onTurnEnd?: ((turn: AgentTurn) => void) | undefined;
938
+ }
939
+ interface AgentConfig {
940
+ readonly tools?: ToolRegistry | undefined;
941
+ readonly maxIterations?: number | undefined;
942
+ readonly hooks?: AgentHooks | undefined;
943
+ }
944
+ interface AgentRunInput {
945
+ readonly model: string;
946
+ readonly messages: readonly Message[];
947
+ readonly options?: ModelOptions | undefined;
948
+ readonly think?: boolean | 'low' | 'medium' | 'high' | 'max' | undefined;
949
+ readonly signal?: AbortSignal | undefined;
950
+ }
951
+
952
+ /**
953
+ * Multi-turn tool execution loop agent.
954
+ */
955
+
956
+ interface AgentChatClient {
957
+ chat(request: {
958
+ readonly model: string;
959
+ readonly messages: readonly Message[];
960
+ readonly tools?: readonly ToolDefinition[] | undefined;
961
+ readonly options?: ModelOptions | undefined;
962
+ readonly think?: boolean | 'low' | 'medium' | 'high' | 'max' | undefined;
963
+ readonly stream?: false | undefined;
964
+ readonly signal?: AbortSignal | undefined;
965
+ }): Promise<{
966
+ readonly message: Message;
967
+ }>;
968
+ }
969
+ /**
970
+ * Runs a multi-turn `chat` + tool-execution loop until the model responds without
971
+ * requesting further tool calls, or `maxIterations` is exceeded. Tool calls within a
972
+ * single turn are handed to `ToolRegistry.executeToolCalls` and their results are
973
+ * appended to history in the same order the model requested them, each tagged with the
974
+ * originating call's `tool_call_id` — see the {@link ToolCall} type docs for how that id
975
+ * is produced (Ollama's native tool-calling protocol has none; this SDK synthesizes one).
976
+ * `Agent` assigns ids defensively even when `AgentChatClient` isn't `OllamaClient` (e.g. a
977
+ * custom/test implementation), so this guarantee holds regardless of which chat client is
978
+ * supplied.
979
+ */
980
+ declare class Agent {
981
+ private readonly client;
982
+ private readonly tools?;
983
+ private readonly maxIterations;
984
+ private readonly hooks?;
985
+ constructor(client: AgentChatClient, config?: AgentConfig);
986
+ run(input: AgentRunInput): Promise<AgentResult>;
987
+ private runLoop;
988
+ }
989
+
990
+ /**
991
+ * Optional OpenTelemetry tracing.
992
+ *
993
+ * `@opentelemetry/api` is an optional peer dependency. When it isn't installed, or when
994
+ * the host process hasn't registered a global TracerProvider, `withSpan` degrades to
995
+ * invoking its callback directly — no spans, no exporters, nothing beyond one cached
996
+ * dynamic `import()` attempt. Once a consumer wires up an OpenTelemetry SDK, spans for
997
+ * HTTP requests, endpoint failover attempts, agent turns, and tool calls appear
998
+ * automatically without any configuration on this SDK's side.
999
+ */
1000
+
1001
+ type SpanAttributeValue = string | number | boolean;
1002
+ type SpanAttributes = Record<string, SpanAttributeValue | undefined>;
1003
+ /**
1004
+ * Runs `fn` inside an active OpenTelemetry span named `name`, when OpenTelemetry is
1005
+ * available. `fn` receives the live span (to add events/attributes as work proceeds) or
1006
+ * `undefined` when tracing is a no-op. Exceptions from `fn` are recorded on the span,
1007
+ * marked as an error status, and re-thrown unchanged; the span always ends.
1008
+ *
1009
+ * On success the span status is left `Unset` rather than forced to `Ok` — per the
1010
+ * OpenTelemetry spec, `Ok` is final and silently suppresses any later `Error` status.
1011
+ * Some call sites (e.g. tool execution, which reports failure via a return value rather
1012
+ * than a throw) need to mark a successfully-*returned* span as an error after the fact,
1013
+ * via `setSpanError`; leaving success as `Unset` keeps that possible. Backends treat
1014
+ * `Unset` the same as `Ok` for filtering purposes.
1015
+ */
1016
+ declare function withSpan<T>(name: string, attributes: SpanAttributes, fn: (span: Otel.Span | undefined) => Promise<T>): Promise<T>;
1017
+ /** Adds an attribute/event to `span` if tracing is active; a cheap no-op otherwise. */
1018
+ declare function addSpanEvent(span: Otel.Span | undefined, name: string, attributes?: SpanAttributes): void;
1019
+ /**
1020
+ * Marks a span as failed without throwing — for operations (like tool execution) that
1021
+ * report failure through a return value rather than an exception. No-ops when tracing
1022
+ * is inactive.
1023
+ */
1024
+ declare function setSpanError(span: Otel.Span | undefined, error: Error): Promise<void>;
1025
+ declare const ATTR_HTTP_REQUEST_METHOD = "http.request.method";
1026
+ declare const ATTR_URL_FULL = "url.full";
1027
+ declare const ATTR_SERVER_ADDRESS = "server.address";
1028
+ declare const ATTR_SERVER_PORT = "server.port";
1029
+ declare const ATTR_HTTP_RESPONSE_STATUS_CODE = "http.response.status_code";
1030
+ declare const ATTR_GEN_AI_SYSTEM = "gen_ai.system";
1031
+ declare const ATTR_GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
1032
+ declare const ATTR_GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
1033
+ declare const ATTR_GEN_AI_RESPONSE_MODEL = "gen_ai.response.model";
1034
+ declare const ATTR_GEN_AI_USAGE_INPUT_TOKENS = "gen_ai.usage.input_tokens";
1035
+ declare const ATTR_GEN_AI_USAGE_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
1036
+ declare const ATTR_GEN_AI_TOOL_NAME = "gen_ai.tool.name";
1037
+ declare const ATTR_GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
1038
+ declare const ATTR_OLLAMA_ENDPOINT_NAME = "ollama.endpoint.name";
1039
+ declare const ATTR_OLLAMA_ENDPOINT_ATTEMPT = "ollama.endpoint.attempt";
1040
+ declare const ATTR_OLLAMA_AGENT_MAX_ITERATIONS = "ollama.agent.max_iterations";
1041
+ declare const ATTR_OLLAMA_AGENT_ITERATION = "ollama.agent.iteration";
1042
+ declare const GEN_AI_SYSTEM_OLLAMA = "ollama";
1043
+
1044
+ export { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_SYSTEM, ATTR_GEN_AI_TOOL_CALL_ID, ATTR_GEN_AI_TOOL_NAME, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_OLLAMA_AGENT_ITERATION, ATTR_OLLAMA_AGENT_MAX_ITERATIONS, ATTR_OLLAMA_ENDPOINT_ATTEMPT, ATTR_OLLAMA_ENDPOINT_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, type AbortableAsyncIterable, Agent, type AgentChatClient, type AgentConfig, type AgentHooks, type AgentResult, type AgentRunInput, type AgentTurn, type AnthropicCacheControl, AnthropicCompatClient, type AnthropicContentBlock, type AnthropicMessage, type AnthropicMessagesRequest, type AnthropicMessagesResponse, AnyTool, type BackoffOptions, ChatRequestOptions, ChatResponse, type ChatStreamResult, CopyRequestOptions, CreateRequestOptions, DEFAULT_BACKOFF, DEFAULT_BASE_URL, DEFAULT_FAILOVER_CODES, DEFAULT_RETRY_CONFIG, DEFAULT_TIMEOUT_MS, type DefineToolOptions, DeleteRequestOptions, type DoneEvent, EmbedRequestOptions, EmbedResponse, EmbeddingsRequestOptions, EmbeddingsResponse, type EndpointHealth, type EndpointHealthCheckResult, EndpointRegistry, type EndpointRegistryOptions, type ErrorEvent, type FetchLike, GEN_AI_SYSTEM_OLLAMA, GenerateRequestOptions, GenerateResponse, type GenerateStreamResult, type HttpBody, HttpClient, type HttpClientOptions, type HttpRequestOptions, type LifecycleErrorEvent, type LifecycleRetryEvent, type LifecycleStartEvent, type LifecycleSuccessEvent, type LoadMcpToolsOptions, type LogFn, type Logger, type McpCallToolResult, type McpClientLike, type McpContentBlock, type McpListToolsResult, type McpToolDescriptor, Message, type MessageEvent, type Middleware, type MiddlewareContext, type ModelCapabilities, ModelOptions, ModelResponse, ModelsClient, NANOS_PER_MS, NANOS_PER_SECOND, NOOP_LOGGER, type NextFunction, OllamaAbortError, OllamaAgentMaxIterationsError, OllamaAuthError, OllamaClient, type OllamaClientConfig, OllamaClientError, type OllamaClientErrorOptions, type OllamaEndpoint, type OllamaErrorRequestContext, type OllamaErrorResponseContext, OllamaGenericClientError, OllamaMcpError, OllamaNetworkError, OllamaNotFoundError, OllamaRateLimitError, OllamaServerError, OllamaSkillInvalidError, OllamaSkillNotFoundError, OllamaStream, type OllamaStreamEvent, type OllamaStreamEventType, OllamaTimeoutError, OllamaToolTimeoutError, OllamaToolValidationError, OllamaUnsupportedCapabilityError, type OpenAIChatCompletionChoice, type OpenAIChatCompletionRequest, type OpenAIChatCompletionResponse, OpenAICompatClient, type OpenAIFunctionDefinition, type OpenAIListModelsResponse, type OpenAIMessage, type OpenAIModelItem, type OpenAIStreamOptions, type OpenAITool, type OpenAIToolCall, ProgressResponse, type ProgressStreamResult, PsResponse, PullRequestOptions, PushRequestOptions, type RawUsageSource, type RequestContext, type RequestLifecycleEvent, type RequestLifecycleHook, type RequestRunner, type ResponseContext, type RetryConfig, type RuntimeMode, ShowRequestOptions, ShowResponse, type SpanAttributeValue, type SpanAttributes, StatusResponse, type SupportedSchema, type ThinkingEvent, type TimeoutSignal, type TokenEvent, type TokenUsage, Tool, ToolCall, type ToolCallEvent, ToolDefinition, ToolExecutionResult, ToolHandler, ToolRegistry, VersionResponse, WebFetchRequestOptions, WebFetchResponse, WebSearchRequestOptions, WebSearchResponse, addSpanEvent, calculateBackoff, checkEndpointHealth, composeMiddleware, createConsoleLogger, createTimeoutSignal, defineTool, detectModelCapabilities, extractUsage, inferRuntimeMode, listAvailableModels, loadMcpTools, mapError, normalizeChatStream, normalizeGenerateStream, normalizeProgressStream, parseNdjsonStream, parseStructuredOutput, registerMcpTools, setSpanError, toDataStream, toResponse, toTextStream, withRetry, withSpan, zodToJsonSchema };