@yourgpt/llm-sdk 2.1.4-alpha.2 → 2.1.5
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/dist/adapters/index.d.mts +3 -2
- package/dist/adapters/index.d.ts +3 -2
- package/dist/{types-DoZX2k3v.d.mts → base-5n-UuPfS.d.mts} +1 -353
- package/dist/{types-DtPQaoJi.d.ts → base-Di31iy_8.d.ts} +1 -353
- package/dist/fallback/index.d.mts +96 -0
- package/dist/fallback/index.d.ts +96 -0
- package/dist/fallback/index.js +284 -0
- package/dist/fallback/index.mjs +280 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/providers/anthropic/index.d.mts +2 -1
- package/dist/providers/anthropic/index.d.ts +2 -1
- package/dist/providers/azure/index.d.mts +2 -1
- package/dist/providers/azure/index.d.ts +2 -1
- package/dist/providers/google/index.d.mts +2 -1
- package/dist/providers/google/index.d.ts +2 -1
- package/dist/providers/ollama/index.d.mts +3 -2
- package/dist/providers/ollama/index.d.ts +3 -2
- package/dist/providers/openai/index.d.mts +2 -1
- package/dist/providers/openai/index.d.ts +2 -1
- package/dist/providers/openrouter/index.d.mts +2 -1
- package/dist/providers/openrouter/index.d.ts +2 -1
- package/dist/providers/xai/index.d.mts +2 -1
- package/dist/providers/xai/index.d.ts +2 -1
- package/dist/types-BQl1suAv.d.mts +212 -0
- package/dist/types-C0vLXzuw.d.ts +355 -0
- package/dist/types-CNL8ZRne.d.ts +212 -0
- package/dist/types-VDgiUvH2.d.mts +355 -0
- package/package.json +7 -1
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/providers/anthropic/index.js.map +0 -1
- package/dist/providers/anthropic/index.mjs.map +0 -1
- package/dist/providers/azure/index.js.map +0 -1
- package/dist/providers/azure/index.mjs.map +0 -1
- package/dist/providers/google/index.js.map +0 -1
- package/dist/providers/google/index.mjs.map +0 -1
- package/dist/providers/ollama/index.js.map +0 -1
- package/dist/providers/ollama/index.mjs.map +0 -1
- package/dist/providers/openai/index.js.map +0 -1
- package/dist/providers/openai/index.mjs.map +0 -1
- package/dist/providers/openrouter/index.js.map +0 -1
- package/dist/providers/openrouter/index.mjs.map +0 -1
- package/dist/providers/xai/index.js.map +0 -1
- package/dist/providers/xai/index.mjs.map +0 -1
- package/dist/yourgpt/index.js.map +0 -1
- package/dist/yourgpt/index.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
|
|
2
|
-
import { O as OpenAIProviderConfig, A as AIProvider } from '../../types-
|
|
2
|
+
import { O as OpenAIProviderConfig, A as AIProvider } from '../../types-VDgiUvH2.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-5n-UuPfS.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* OpenAI Provider - Modern Pattern
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.js';
|
|
2
|
-
import { O as OpenAIProviderConfig, A as AIProvider } from '../../types-
|
|
2
|
+
import { O as OpenAIProviderConfig, A as AIProvider } from '../../types-C0vLXzuw.js';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-Di31iy_8.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* OpenAI Provider - Modern Pattern
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
|
|
2
|
-
import { A as AIProvider } from '../../types-
|
|
2
|
+
import { A as AIProvider } from '../../types-VDgiUvH2.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-5n-UuPfS.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* OpenRouter Provider - Modern Pattern
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.js';
|
|
2
|
-
import { A as AIProvider } from '../../types-
|
|
2
|
+
import { A as AIProvider } from '../../types-C0vLXzuw.js';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-Di31iy_8.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* OpenRouter Provider - Modern Pattern
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
|
|
2
|
-
import { X as XAIProviderConfig, A as AIProvider } from '../../types-
|
|
2
|
+
import { X as XAIProviderConfig, A as AIProvider } from '../../types-VDgiUvH2.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-5n-UuPfS.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* xAI Provider - Modern Pattern
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { L as LanguageModel } from '../../types-CR8mi9I0.js';
|
|
2
|
-
import { X as XAIProviderConfig, A as AIProvider } from '../../types-
|
|
2
|
+
import { X as XAIProviderConfig, A as AIProvider } from '../../types-C0vLXzuw.js';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import '../../base-Di31iy_8.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* xAI Provider - Modern Pattern
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { L as LLMAdapter } from './base-5n-UuPfS.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fallback Chain & Routing Strategy Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pluggable state store for routing strategies.
|
|
9
|
+
*
|
|
10
|
+
* Round-robin and other stateful strategies use this to persist
|
|
11
|
+
* which model was last used. The default implementation is in-memory.
|
|
12
|
+
*
|
|
13
|
+
* For multi-instance or serverless deployments, plug in your own:
|
|
14
|
+
* Redis, Upstash, Cloudflare KV, DynamoDB, etc.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Redis-backed store (example — bring your own client)
|
|
19
|
+
* const redisStore: RoutingStore = {
|
|
20
|
+
* async get(key) {
|
|
21
|
+
* const val = await redis.get(key);
|
|
22
|
+
* return val ? Number(val) : undefined;
|
|
23
|
+
* },
|
|
24
|
+
* async set(key, value) {
|
|
25
|
+
* await redis.set(key, value);
|
|
26
|
+
* },
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
interface RoutingStore {
|
|
31
|
+
/** Get the stored value for a key */
|
|
32
|
+
get(key: string): Promise<number | undefined>;
|
|
33
|
+
/** Set the stored value for a key */
|
|
34
|
+
set(key: string, value: number): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A single failed model in the fallback chain (after all retries exhausted)
|
|
38
|
+
*/
|
|
39
|
+
interface FallbackFailure {
|
|
40
|
+
/** Model ID that failed */
|
|
41
|
+
model: string;
|
|
42
|
+
/** Provider name */
|
|
43
|
+
provider: string;
|
|
44
|
+
/** The last error from this model */
|
|
45
|
+
error: Error;
|
|
46
|
+
/** Which model in the chain this was (1-based) */
|
|
47
|
+
attempt: number;
|
|
48
|
+
/** How many times this model was retried before giving up */
|
|
49
|
+
retriesAttempted: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Passed to the onFallback callback when a model is abandoned and the next one is tried
|
|
53
|
+
*/
|
|
54
|
+
interface FallbackInfo {
|
|
55
|
+
/** Model that just failed (after all its retries) */
|
|
56
|
+
attemptedModel: string;
|
|
57
|
+
/** Model that will be tried next */
|
|
58
|
+
nextModel: string;
|
|
59
|
+
/** The last error from the failed model */
|
|
60
|
+
error: Error;
|
|
61
|
+
/** Which model in the chain this was (1-based) */
|
|
62
|
+
attempt: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Passed to the onRetry callback on each per-model retry attempt
|
|
66
|
+
*/
|
|
67
|
+
interface RetryInfo {
|
|
68
|
+
/** Model being retried */
|
|
69
|
+
model: string;
|
|
70
|
+
/** Provider name */
|
|
71
|
+
provider: string;
|
|
72
|
+
/** The error that triggered this retry */
|
|
73
|
+
error: Error;
|
|
74
|
+
/** Which retry attempt this is (1-based: 1 = first retry after initial failure) */
|
|
75
|
+
retryAttempt: number;
|
|
76
|
+
/** Total retries configured for this chain */
|
|
77
|
+
maxRetries: number;
|
|
78
|
+
/** How long (ms) we will wait before retrying */
|
|
79
|
+
delayMs: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* How the chain decides which model to try first.
|
|
83
|
+
*
|
|
84
|
+
* - `priority` — always try models in defined order (default)
|
|
85
|
+
* - `round-robin` — rotate starting model evenly across calls
|
|
86
|
+
*/
|
|
87
|
+
type RoutingStrategy = "priority" | "round-robin";
|
|
88
|
+
/**
|
|
89
|
+
* Backoff strategy between per-model retries.
|
|
90
|
+
*
|
|
91
|
+
* - `exponential` — delay doubles on each retry: 500ms → 1000ms → 2000ms (default)
|
|
92
|
+
* - `fixed` — same delay every retry: 500ms → 500ms → 500ms
|
|
93
|
+
*/
|
|
94
|
+
type RetryBackoff = "exponential" | "fixed";
|
|
95
|
+
/**
|
|
96
|
+
* Configuration for createFallbackChain()
|
|
97
|
+
*/
|
|
98
|
+
interface FallbackChainConfig {
|
|
99
|
+
/**
|
|
100
|
+
* Ordered list of adapters to try.
|
|
101
|
+
* On failure, the chain moves to the next adapter in this list.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { createOpenAI } from '@yourgpt/llm-sdk/openai';
|
|
106
|
+
* import { createAnthropic } from '@yourgpt/llm-sdk/anthropic';
|
|
107
|
+
*
|
|
108
|
+
* const openai = createOpenAI({ apiKey: '...' });
|
|
109
|
+
* const anthropic = createAnthropic({ apiKey: '...' });
|
|
110
|
+
*
|
|
111
|
+
* const chain = createFallbackChain({
|
|
112
|
+
* models: [
|
|
113
|
+
* openai.languageModel('gpt-4o'),
|
|
114
|
+
* anthropic.languageModel('claude-3-5-sonnet-20241022'),
|
|
115
|
+
* ],
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
models: LLMAdapter[];
|
|
120
|
+
/**
|
|
121
|
+
* Routing strategy controlling which model is tried first.
|
|
122
|
+
* @default 'priority'
|
|
123
|
+
*/
|
|
124
|
+
strategy?: RoutingStrategy;
|
|
125
|
+
/**
|
|
126
|
+
* State store for strategies that require persistence (e.g., round-robin).
|
|
127
|
+
* Defaults to an in-memory store (MemoryRoutingStore).
|
|
128
|
+
*
|
|
129
|
+
* Replace with a shared store (Redis, Upstash, etc.) for multi-instance
|
|
130
|
+
* or serverless deployments where round-robin state must be shared.
|
|
131
|
+
*/
|
|
132
|
+
store?: RoutingStore;
|
|
133
|
+
/**
|
|
134
|
+
* Number of times to retry the same model before moving to the next one.
|
|
135
|
+
*
|
|
136
|
+
* LiteLLM equivalent: `num_retries`
|
|
137
|
+
*
|
|
138
|
+
* @default 0 (no retries — fail immediately and move to next model)
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Try each model up to 3 times before falling back
|
|
143
|
+
* createFallbackChain({ models: [...], retries: 3 })
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
retries?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Base delay in milliseconds between per-model retries.
|
|
149
|
+
*
|
|
150
|
+
* With `retryBackoff: 'exponential'` (default):
|
|
151
|
+
* retry 1 → retryDelay ms
|
|
152
|
+
* retry 2 → retryDelay * 2 ms
|
|
153
|
+
* retry 3 → retryDelay * 4 ms
|
|
154
|
+
*
|
|
155
|
+
* With `retryBackoff: 'fixed'`:
|
|
156
|
+
* every retry → retryDelay ms
|
|
157
|
+
*
|
|
158
|
+
* @default 500
|
|
159
|
+
*/
|
|
160
|
+
retryDelay?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Backoff strategy between per-model retries.
|
|
163
|
+
* @default 'exponential'
|
|
164
|
+
*/
|
|
165
|
+
retryBackoff?: RetryBackoff;
|
|
166
|
+
/**
|
|
167
|
+
* Called on each per-model retry attempt (before the delay).
|
|
168
|
+
* Use for logging, metrics, or alerting per retry.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* onRetry: ({ model, retryAttempt, maxRetries, delayMs, error }) => {
|
|
173
|
+
* console.warn(`[retry] ${model} attempt ${retryAttempt}/${maxRetries} — waiting ${delayMs}ms | ${error.message}`);
|
|
174
|
+
* }
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
onRetry?: (info: RetryInfo) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Called each time a model is abandoned and the next one is tried.
|
|
180
|
+
* Use for logging, metrics, or alerting.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* onFallback: ({ attemptedModel, nextModel, error, attempt }) => {
|
|
185
|
+
* console.warn(`[fallback] attempt ${attempt}: ${attemptedModel} failed → ${nextModel}`, error.message);
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
onFallback?: (info: FallbackInfo) => void;
|
|
190
|
+
/**
|
|
191
|
+
* Custom predicate to decide whether an error should trigger a fallback.
|
|
192
|
+
*
|
|
193
|
+
* By default, the following trigger fallback:
|
|
194
|
+
* - HTTP 5xx server errors
|
|
195
|
+
* - HTTP 429 rate limit errors
|
|
196
|
+
* - Network timeouts and connection failures
|
|
197
|
+
*
|
|
198
|
+
* The following do NOT trigger fallback by default:
|
|
199
|
+
* - HTTP 4xx client errors (bad request, invalid API key, etc.)
|
|
200
|
+
*
|
|
201
|
+
* Override this to extend or restrict fallback behavior.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* // Also fall back on any error
|
|
206
|
+
* retryableErrors: () => true,
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
retryableErrors?: (error: unknown) => boolean;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export type { FallbackChainConfig as F, RoutingStore as R, RoutingStrategy as a, RetryBackoff as b, FallbackFailure as c, FallbackInfo as d, RetryInfo as e };
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { L as LLMAdapter, T as ToolDefinition, U as UnifiedToolCall, h as UnifiedToolResult } from './base-Di31iy_8.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provider Types
|
|
5
|
+
*
|
|
6
|
+
* Defines interfaces for:
|
|
7
|
+
* 1. Provider Formatters (for tool transformations in agent loop)
|
|
8
|
+
* 2. Multi-provider architecture (AIProvider, capabilities, configs)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Provider formatter interface
|
|
13
|
+
*
|
|
14
|
+
* Each provider implements this interface to handle:
|
|
15
|
+
* - Tool definition transformation
|
|
16
|
+
* - Tool call parsing from responses
|
|
17
|
+
* - Tool result formatting
|
|
18
|
+
* - Stop reason detection
|
|
19
|
+
*/
|
|
20
|
+
interface ProviderFormatter {
|
|
21
|
+
/**
|
|
22
|
+
* Transform unified tool definitions to provider format
|
|
23
|
+
*/
|
|
24
|
+
transformTools(tools: ToolDefinition[]): unknown[];
|
|
25
|
+
/**
|
|
26
|
+
* Parse tool calls from provider response
|
|
27
|
+
*/
|
|
28
|
+
parseToolCalls(response: unknown): UnifiedToolCall[];
|
|
29
|
+
/**
|
|
30
|
+
* Format tool results for provider
|
|
31
|
+
*/
|
|
32
|
+
formatToolResults(results: UnifiedToolResult[]): unknown[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if response indicates tool use is requested
|
|
35
|
+
*/
|
|
36
|
+
isToolUseStop(response: unknown): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check if response indicates end of turn
|
|
39
|
+
*/
|
|
40
|
+
isEndTurnStop(response: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get stop reason string from response
|
|
43
|
+
*/
|
|
44
|
+
getStopReason(response: unknown): string;
|
|
45
|
+
/**
|
|
46
|
+
* Extract text content from response
|
|
47
|
+
*/
|
|
48
|
+
extractTextContent(response: unknown): string;
|
|
49
|
+
/**
|
|
50
|
+
* Build assistant message with tool calls for conversation history
|
|
51
|
+
*/
|
|
52
|
+
buildAssistantToolMessage(toolCalls: UnifiedToolCall[], textContent?: string): unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Build user message with tool results for conversation history
|
|
55
|
+
*/
|
|
56
|
+
buildToolResultMessage(results: UnifiedToolResult[]): unknown;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Anthropic tool definition format
|
|
60
|
+
*/
|
|
61
|
+
interface AnthropicTool {
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
input_schema: {
|
|
65
|
+
type: "object";
|
|
66
|
+
properties: Record<string, unknown>;
|
|
67
|
+
required?: string[];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Anthropic tool_use block from response
|
|
72
|
+
*/
|
|
73
|
+
interface AnthropicToolUse {
|
|
74
|
+
type: "tool_use";
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
input: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Anthropic tool_result block
|
|
81
|
+
*/
|
|
82
|
+
interface AnthropicToolResult {
|
|
83
|
+
type: "tool_result";
|
|
84
|
+
tool_use_id: string;
|
|
85
|
+
content: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* OpenAI tool definition format
|
|
89
|
+
*/
|
|
90
|
+
interface OpenAITool {
|
|
91
|
+
type: "function";
|
|
92
|
+
function: {
|
|
93
|
+
name: string;
|
|
94
|
+
description: string;
|
|
95
|
+
parameters: {
|
|
96
|
+
type: "object";
|
|
97
|
+
properties: Record<string, unknown>;
|
|
98
|
+
required?: string[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* OpenAI tool call from response
|
|
104
|
+
*/
|
|
105
|
+
interface OpenAIToolCall {
|
|
106
|
+
id: string;
|
|
107
|
+
type: "function";
|
|
108
|
+
function: {
|
|
109
|
+
name: string;
|
|
110
|
+
arguments: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* OpenAI tool result message
|
|
115
|
+
*/
|
|
116
|
+
interface OpenAIToolResult {
|
|
117
|
+
role: "tool";
|
|
118
|
+
tool_call_id: string;
|
|
119
|
+
content: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Google Gemini function declaration
|
|
123
|
+
*/
|
|
124
|
+
interface GeminiFunctionDeclaration {
|
|
125
|
+
name: string;
|
|
126
|
+
description: string;
|
|
127
|
+
parameters?: {
|
|
128
|
+
type: "object";
|
|
129
|
+
properties: Record<string, unknown>;
|
|
130
|
+
required?: string[];
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gemini function call from response
|
|
135
|
+
*/
|
|
136
|
+
interface GeminiFunctionCall {
|
|
137
|
+
name: string;
|
|
138
|
+
args: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gemini function response
|
|
142
|
+
*/
|
|
143
|
+
interface GeminiFunctionResponse {
|
|
144
|
+
name: string;
|
|
145
|
+
response: Record<string, unknown>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Capabilities of a model for UI feature flags
|
|
149
|
+
* UI components can use this to enable/disable features
|
|
150
|
+
*/
|
|
151
|
+
interface ProviderCapabilities {
|
|
152
|
+
/** Supports image inputs */
|
|
153
|
+
supportsVision: boolean;
|
|
154
|
+
/** Supports tool/function calling */
|
|
155
|
+
supportsTools: boolean;
|
|
156
|
+
/** Supports extended thinking (Claude, DeepSeek) */
|
|
157
|
+
supportsThinking: boolean;
|
|
158
|
+
/** Supports streaming responses */
|
|
159
|
+
supportsStreaming: boolean;
|
|
160
|
+
/** Supports PDF document inputs */
|
|
161
|
+
supportsPDF: boolean;
|
|
162
|
+
/** Supports audio inputs */
|
|
163
|
+
supportsAudio: boolean;
|
|
164
|
+
/** Supports video inputs */
|
|
165
|
+
supportsVideo: boolean;
|
|
166
|
+
/** Maximum context tokens */
|
|
167
|
+
maxTokens: number;
|
|
168
|
+
/** Supported image MIME types */
|
|
169
|
+
supportedImageTypes: string[];
|
|
170
|
+
/** Supported audio MIME types */
|
|
171
|
+
supportedAudioTypes?: string[];
|
|
172
|
+
/** Supported video MIME types */
|
|
173
|
+
supportedVideoTypes?: string[];
|
|
174
|
+
/** Supports JSON mode / structured output */
|
|
175
|
+
supportsJsonMode?: boolean;
|
|
176
|
+
/** Supports system messages */
|
|
177
|
+
supportsSystemMessages?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* AI Provider interface (object form)
|
|
181
|
+
*
|
|
182
|
+
* Wraps existing LLMAdapter with additional metadata:
|
|
183
|
+
* - Supported models list
|
|
184
|
+
* - Per-model capabilities
|
|
185
|
+
* - Provider name
|
|
186
|
+
*/
|
|
187
|
+
interface AIProviderObject {
|
|
188
|
+
/** Provider name (e.g., 'openai', 'anthropic') */
|
|
189
|
+
readonly name: string;
|
|
190
|
+
/** List of supported model IDs */
|
|
191
|
+
readonly supportedModels: string[];
|
|
192
|
+
/**
|
|
193
|
+
* Get a language model adapter for the given model ID
|
|
194
|
+
* Returns the existing LLMAdapter interface - no breaking changes
|
|
195
|
+
*/
|
|
196
|
+
languageModel(modelId: string): LLMAdapter;
|
|
197
|
+
/**
|
|
198
|
+
* Get capabilities for a specific model
|
|
199
|
+
* UI components use this to enable/disable features
|
|
200
|
+
*/
|
|
201
|
+
getCapabilities(modelId: string): ProviderCapabilities;
|
|
202
|
+
/**
|
|
203
|
+
* Optional: Get an embedding model (future expansion)
|
|
204
|
+
*/
|
|
205
|
+
embeddingModel?(modelId: string): EmbeddingModel;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Callable AI Provider (Vercel AI SDK style)
|
|
209
|
+
*
|
|
210
|
+
* A function that returns a LanguageModel when called with a model ID,
|
|
211
|
+
* but also has properties for provider metadata and methods.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const openai = createOpenAI({ apiKey: '...' });
|
|
216
|
+
*
|
|
217
|
+
* // Callable - returns LanguageModel directly (Vercel AI SDK style)
|
|
218
|
+
* const model = openai('gpt-4o');
|
|
219
|
+
*
|
|
220
|
+
* // Also supports method calls (backward compatible)
|
|
221
|
+
* const model2 = openai.languageModel('gpt-4o');
|
|
222
|
+
*
|
|
223
|
+
* // Check capabilities
|
|
224
|
+
* const caps = openai.getCapabilities('gpt-4o');
|
|
225
|
+
* if (caps.supportsVision) {
|
|
226
|
+
* // Show image upload button
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
interface AIProvider extends AIProviderObject {
|
|
231
|
+
/**
|
|
232
|
+
* Call the provider directly with a model ID to get a LanguageModel
|
|
233
|
+
* This is the Vercel AI SDK style pattern
|
|
234
|
+
*/
|
|
235
|
+
(modelId: string): LLMAdapter;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Embedding model interface (for future expansion)
|
|
239
|
+
*/
|
|
240
|
+
interface EmbeddingModel {
|
|
241
|
+
readonly provider: string;
|
|
242
|
+
readonly modelId: string;
|
|
243
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Base provider configuration
|
|
247
|
+
*/
|
|
248
|
+
interface BaseProviderConfig {
|
|
249
|
+
/** API key (falls back to environment variable) */
|
|
250
|
+
apiKey?: string;
|
|
251
|
+
/** Custom base URL */
|
|
252
|
+
baseUrl?: string;
|
|
253
|
+
/** Request timeout in milliseconds */
|
|
254
|
+
timeout?: number;
|
|
255
|
+
/** Custom headers to include */
|
|
256
|
+
headers?: Record<string, string>;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* OpenAI provider configuration
|
|
260
|
+
*/
|
|
261
|
+
interface OpenAIProviderConfig extends BaseProviderConfig {
|
|
262
|
+
/** OpenAI organization ID */
|
|
263
|
+
organization?: string;
|
|
264
|
+
/** OpenAI project ID */
|
|
265
|
+
project?: string;
|
|
266
|
+
/** Vision detail level for images */
|
|
267
|
+
imageDetail?: "auto" | "low" | "high";
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Anthropic provider configuration
|
|
271
|
+
*/
|
|
272
|
+
interface AnthropicProviderConfig extends BaseProviderConfig {
|
|
273
|
+
/** Extended thinking budget in tokens (minimum 1024) */
|
|
274
|
+
thinkingBudget?: number;
|
|
275
|
+
/** Enable prompt caching */
|
|
276
|
+
cacheControl?: boolean;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Google provider configuration
|
|
280
|
+
*/
|
|
281
|
+
interface GoogleProviderConfig extends BaseProviderConfig {
|
|
282
|
+
/** Safety settings */
|
|
283
|
+
safetySettings?: GoogleSafetySetting[];
|
|
284
|
+
/** Grounding configuration (for web search) */
|
|
285
|
+
groundingConfig?: GoogleGroundingConfig;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Google safety setting
|
|
289
|
+
*/
|
|
290
|
+
interface GoogleSafetySetting {
|
|
291
|
+
category: "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_DANGEROUS_CONTENT";
|
|
292
|
+
threshold: "BLOCK_NONE" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_HIGH_AND_ABOVE";
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Google grounding configuration
|
|
296
|
+
*/
|
|
297
|
+
interface GoogleGroundingConfig {
|
|
298
|
+
/** Enable Google Search grounding */
|
|
299
|
+
googleSearchRetrieval?: boolean;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* xAI provider configuration
|
|
303
|
+
*/
|
|
304
|
+
interface XAIProviderConfig extends BaseProviderConfig {
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Azure OpenAI provider configuration
|
|
308
|
+
*/
|
|
309
|
+
interface AzureProviderConfig extends BaseProviderConfig {
|
|
310
|
+
/** Azure resource name */
|
|
311
|
+
resourceName: string;
|
|
312
|
+
/** Deployment name */
|
|
313
|
+
deploymentName: string;
|
|
314
|
+
/** API version (default: 2024-02-15-preview) */
|
|
315
|
+
apiVersion?: string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Ollama model-specific options
|
|
319
|
+
* These map to Ollama's native API options
|
|
320
|
+
*/
|
|
321
|
+
interface OllamaModelOptions {
|
|
322
|
+
/** Context window size (default varies by model) */
|
|
323
|
+
num_ctx?: number;
|
|
324
|
+
/** Max tokens to predict (-1 = infinite, -2 = fill context) */
|
|
325
|
+
num_predict?: number;
|
|
326
|
+
/** Mirostat sampling (0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0) */
|
|
327
|
+
mirostat?: 0 | 1 | 2;
|
|
328
|
+
/** Mirostat learning rate (default: 0.1) */
|
|
329
|
+
mirostat_eta?: number;
|
|
330
|
+
/** Mirostat target entropy (default: 5.0) */
|
|
331
|
+
mirostat_tau?: number;
|
|
332
|
+
/** Repeat penalty (default: 1.1) */
|
|
333
|
+
repeat_penalty?: number;
|
|
334
|
+
/** Random seed for reproducibility (-1 = random) */
|
|
335
|
+
seed?: number;
|
|
336
|
+
/** Top-k sampling (default: 40) */
|
|
337
|
+
top_k?: number;
|
|
338
|
+
/** Top-p (nucleus) sampling (default: 0.9) */
|
|
339
|
+
top_p?: number;
|
|
340
|
+
/** Min-p sampling (default: 0.0) */
|
|
341
|
+
min_p?: number;
|
|
342
|
+
/** Stop sequences */
|
|
343
|
+
stop?: string[];
|
|
344
|
+
/** Temperature override (also available in config) */
|
|
345
|
+
temperature?: number;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Ollama provider configuration
|
|
349
|
+
*/
|
|
350
|
+
interface OllamaProviderConfig extends BaseProviderConfig {
|
|
351
|
+
/** Default Ollama-specific model options */
|
|
352
|
+
options?: OllamaModelOptions;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n };
|