@yourgpt/llm-sdk 2.6.0-beta.0 → 2.6.0-beta.2
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/README.md +189 -0
- package/dist/adapters/index.d.mts +11 -13
- package/dist/adapters/index.d.ts +11 -13
- package/dist/adapters/index.js +610 -186
- package/dist/adapters/index.mjs +610 -186
- package/dist/audio-BBSwnjo8.d.mts +92 -0
- package/dist/audio-BBSwnjo8.d.ts +92 -0
- package/dist/{base-tNgbBaSo.d.mts → base-BICaQaRS.d.mts} +8 -3
- package/dist/{base-C58Dsr9p.d.ts → base-CpRPB8u8.d.ts} +8 -3
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/fallback/index.js +75 -39
- package/dist/fallback/index.mjs +75 -39
- package/dist/index.d.mts +18 -35
- package/dist/index.d.ts +18 -35
- package/dist/index.js +304 -88
- package/dist/index.mjs +302 -89
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +123 -7
- package/dist/providers/anthropic/index.mjs +123 -7
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +101 -4
- package/dist/providers/azure/index.mjs +101 -4
- package/dist/providers/fireworks/index.d.mts +3 -3
- package/dist/providers/fireworks/index.d.ts +3 -3
- package/dist/providers/fireworks/index.js +559 -178
- package/dist/providers/fireworks/index.mjs +559 -178
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +559 -178
- package/dist/providers/google/index.mjs +559 -178
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +87 -2
- package/dist/providers/ollama/index.mjs +87 -2
- package/dist/providers/openai/index.d.mts +25 -23
- package/dist/providers/openai/index.d.ts +25 -23
- package/dist/providers/openai/index.js +1397 -481
- package/dist/providers/openai/index.mjs +1396 -482
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +559 -178
- package/dist/providers/openrouter/index.mjs +559 -178
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +559 -178
- package/dist/providers/togetherai/index.mjs +559 -178
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +559 -178
- package/dist/providers/xai/index.mjs +559 -178
- package/dist/{types-B6dhnguR.d.mts → types-C3RgRbEC.d.mts} +11 -4
- package/dist/{types-CCxPmkmK.d.ts → types-DCFqkJAy.d.ts} +11 -4
- package/dist/{types-BQ31QIsA.d.ts → types-DHQEMFHA.d.mts} +3 -11
- package/dist/{types-BkQCSiIt.d.mts → types-Dg1Bcg1k.d.mts} +127 -3
- package/dist/{types-BkQCSiIt.d.ts → types-Dg1Bcg1k.d.ts} +127 -3
- package/dist/{types-BSSiJW2o.d.mts → types-Dikj3En4.d.ts} +3 -11
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/docs/multimodal-and-audio.md +170 -0
- package/package.json +117 -49
- package/LICENSE +0 -21
package/dist/fallback/index.mjs
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
// src/core/provider-error.ts
|
|
2
|
+
function errorFromEvent(event) {
|
|
3
|
+
if (event.cause instanceof Error) return event.cause;
|
|
4
|
+
return Object.assign(new Error(event.message), {
|
|
5
|
+
status: event.status,
|
|
6
|
+
code: event.providerCode ?? event.code,
|
|
7
|
+
param: event.param,
|
|
8
|
+
request_id: event.requestId
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function throwIfAborted(signal) {
|
|
12
|
+
if (!signal?.aborted) return;
|
|
13
|
+
const error = new Error("The operation was aborted");
|
|
14
|
+
error.name = "AbortError";
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
function isAbortError(error) {
|
|
18
|
+
if (!(error instanceof Error)) return false;
|
|
19
|
+
return error.name === "AbortError" || error.constructor.name === "APIUserAbortError" || /^(aborted|the operation was aborted|the user aborted a request)/i.test(
|
|
20
|
+
error.message
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
1
24
|
// src/fallback/errors.ts
|
|
2
25
|
var FallbackExhaustedError = class extends Error {
|
|
3
26
|
constructor(failures) {
|
|
@@ -72,8 +95,24 @@ function calcDelay(base, attempt, backoff) {
|
|
|
72
95
|
if (backoff === "fixed") return base;
|
|
73
96
|
return base * Math.pow(2, attempt - 1);
|
|
74
97
|
}
|
|
75
|
-
function sleep(ms) {
|
|
76
|
-
|
|
98
|
+
function sleep(ms, signal) {
|
|
99
|
+
throwIfAborted(signal);
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
const onAbort = () => {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
signal?.removeEventListener("abort", onAbort);
|
|
104
|
+
try {
|
|
105
|
+
throwIfAborted(signal);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
reject(error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const timer = setTimeout(() => {
|
|
111
|
+
signal?.removeEventListener("abort", onAbort);
|
|
112
|
+
resolve();
|
|
113
|
+
}, ms);
|
|
114
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
115
|
+
});
|
|
77
116
|
}
|
|
78
117
|
var FallbackChain = class {
|
|
79
118
|
constructor(config) {
|
|
@@ -89,7 +128,8 @@ var FallbackChain = class {
|
|
|
89
128
|
retryBackoff: config.retryBackoff ?? "exponential",
|
|
90
129
|
onFallback: config.onFallback,
|
|
91
130
|
onRetry: config.onRetry,
|
|
92
|
-
retryableErrors: config.retryableErrors
|
|
131
|
+
retryableErrors: config.retryableErrors,
|
|
132
|
+
fallbackErrors: config.fallbackErrors
|
|
93
133
|
};
|
|
94
134
|
}
|
|
95
135
|
get provider() {
|
|
@@ -109,8 +149,12 @@ var FallbackChain = class {
|
|
|
109
149
|
await this._config.store.set(ROUND_ROBIN_KEY, next);
|
|
110
150
|
}
|
|
111
151
|
_isRetryable(error) {
|
|
152
|
+
if (isAbortError(error)) return false;
|
|
112
153
|
return this._config.retryableErrors ? this._config.retryableErrors(error) : defaultIsRetryable(error);
|
|
113
154
|
}
|
|
155
|
+
_canFallback(error) {
|
|
156
|
+
return !isAbortError(error) && (this._isRetryable(error) || this._config.fallbackErrors?.(error) === true);
|
|
157
|
+
}
|
|
114
158
|
/**
|
|
115
159
|
* Try streaming from a single adapter, with per-model retries.
|
|
116
160
|
*
|
|
@@ -123,65 +167,52 @@ var FallbackChain = class {
|
|
|
123
167
|
*/
|
|
124
168
|
async *_streamWithRetries(adapter, request, out) {
|
|
125
169
|
const { retries, retryDelay, retryBackoff, onRetry } = this._config;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let failureError = null;
|
|
170
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
171
|
+
throwIfAborted(request.signal);
|
|
172
|
+
out.retriesAttempted = attempt;
|
|
130
173
|
try {
|
|
131
174
|
for await (const chunk of adapter.stream(request)) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const msg = chunk.message ?? "Unknown error";
|
|
135
|
-
failureError = new Error(msg);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
yield chunk;
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
175
|
+
throwIfAborted(request.signal);
|
|
176
|
+
if (chunk.type === "error") throw errorFromEvent(chunk);
|
|
141
177
|
if (chunk.type === "message:start") continue;
|
|
142
|
-
contentStarted = true;
|
|
178
|
+
out.contentStarted = true;
|
|
143
179
|
yield chunk;
|
|
144
180
|
}
|
|
181
|
+
throwIfAborted(request.signal);
|
|
182
|
+
return;
|
|
145
183
|
} catch (error) {
|
|
146
|
-
|
|
147
|
-
if (!this._isRetryable(error)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (!this._isRetryable(failureError)) throw failureError;
|
|
152
|
-
out.retriesAttempted = attempt - 1;
|
|
153
|
-
if (attempt < maxAttempts) {
|
|
154
|
-
const delayMs = calcDelay(retryDelay, attempt, retryBackoff);
|
|
155
|
-
const retryInfo = {
|
|
184
|
+
throwIfAborted(request.signal);
|
|
185
|
+
if (out.contentStarted || !this._isRetryable(error) || attempt === retries)
|
|
186
|
+
throw error;
|
|
187
|
+
const delayMs = calcDelay(retryDelay, attempt + 1, retryBackoff);
|
|
188
|
+
onRetry?.({
|
|
156
189
|
model: adapter.model,
|
|
157
190
|
provider: adapter.provider,
|
|
158
|
-
error:
|
|
159
|
-
retryAttempt: attempt,
|
|
191
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
192
|
+
retryAttempt: attempt + 1,
|
|
160
193
|
maxRetries: retries,
|
|
161
194
|
delayMs
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
await sleep(delayMs);
|
|
165
|
-
continue;
|
|
195
|
+
});
|
|
196
|
+
await sleep(delayMs, request.signal);
|
|
166
197
|
}
|
|
167
|
-
out.retriesAttempted = retries;
|
|
168
|
-
throw failureError;
|
|
169
198
|
}
|
|
170
199
|
}
|
|
171
200
|
async *stream(request) {
|
|
172
201
|
const { models, onFallback } = this._config;
|
|
202
|
+
throwIfAborted(request.signal);
|
|
173
203
|
const startIndex = await this._startIndex();
|
|
174
204
|
const failures = [];
|
|
175
205
|
for (let i = 0; i < models.length; i++) {
|
|
176
206
|
const index = (startIndex + i) % models.length;
|
|
177
207
|
const adapter = models[index];
|
|
178
|
-
const out = { retriesAttempted: 0 };
|
|
208
|
+
const out = { retriesAttempted: 0, contentStarted: false };
|
|
179
209
|
try {
|
|
180
210
|
yield* this._streamWithRetries(adapter, request, out);
|
|
181
211
|
await this._advanceIndex(index);
|
|
182
212
|
return;
|
|
183
213
|
} catch (error) {
|
|
184
|
-
|
|
214
|
+
throwIfAborted(request.signal);
|
|
215
|
+
if (out.contentStarted || !this._canFallback(error)) throw error;
|
|
185
216
|
const failure = {
|
|
186
217
|
model: adapter.model,
|
|
187
218
|
provider: adapter.provider,
|
|
@@ -206,6 +237,7 @@ var FallbackChain = class {
|
|
|
206
237
|
}
|
|
207
238
|
async complete(request) {
|
|
208
239
|
const { models, onFallback, retries, retryDelay, retryBackoff, onRetry } = this._config;
|
|
240
|
+
throwIfAborted(request.signal);
|
|
209
241
|
const startIndex = await this._startIndex();
|
|
210
242
|
const failures = [];
|
|
211
243
|
for (let i = 0; i < models.length; i++) {
|
|
@@ -227,14 +259,18 @@ var FallbackChain = class {
|
|
|
227
259
|
let lastError = null;
|
|
228
260
|
let retriesAttempted = 0;
|
|
229
261
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
262
|
+
throwIfAborted(request.signal);
|
|
230
263
|
try {
|
|
231
264
|
const result = await adapter.complete(request);
|
|
265
|
+
throwIfAborted(request.signal);
|
|
232
266
|
await this._advanceIndex(index);
|
|
233
267
|
return result;
|
|
234
268
|
} catch (error) {
|
|
235
|
-
|
|
269
|
+
throwIfAborted(request.signal);
|
|
270
|
+
if (!this._canFallback(error)) throw error;
|
|
236
271
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
237
272
|
retriesAttempted = attempt - 1;
|
|
273
|
+
if (!this._isRetryable(error)) break;
|
|
238
274
|
if (attempt < maxAttempts) {
|
|
239
275
|
const delayMs = calcDelay(retryDelay, attempt, retryBackoff);
|
|
240
276
|
onRetry?.({
|
|
@@ -245,7 +281,7 @@ var FallbackChain = class {
|
|
|
245
281
|
maxRetries: retries,
|
|
246
282
|
delayMs
|
|
247
283
|
});
|
|
248
|
-
await sleep(delayMs);
|
|
284
|
+
await sleep(delayMs, request.signal);
|
|
249
285
|
}
|
|
250
286
|
}
|
|
251
287
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, A as ActionDefinition,
|
|
2
|
-
export {
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as ToolModelOutput, d as Tool, A as ActionDefinition, e as ToolDefinition, f as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, g as StorageAdapter, P as ProviderMetadata, O as OpenAITransportOptions, h as OpenAIReasoningEffort, R as ResponseFormat, D as DoneEventMessage, i as StreamEvent, j as ToolCallInfo, k as TokenUsageRaw, l as ProviderToolRuntimeOptions, M as Message, m as ToolResponse, n as StorageMessage } from './types-Dg1Bcg1k.mjs';
|
|
2
|
+
export { a8 as AnthropicProviderToolOptions, a5 as AnthropicToolSelectionHints, s as AssistantMessage, a9 as Citation, C as CoreMessage, _ as DEFAULT_CAPABILITIES, p as DoGenerateParams, q as DoGenerateResult, Q as ErrorChunk, F as FilePart, N as FinishChunk, X as FinishReason, y as GenerateStep, I as ImagePart, $ as LLMConfig, L as LanguageModel, o as ModelCapabilities, a7 as OpenAIProviderToolOptions, ab as OpenAIResponseItem, ac as OpenAIResponseMetadata, aa as OpenAIResponsesOptions, a4 as OpenAIToolSelectionHints, Y as ResponseOptions, Z as StorageFile, B as StreamChunk, z as StreamPart, r as SystemMessage, E as TextDeltaChunk, v as TextPart, V as TokenUsage, w as ToolCall, H as ToolCallChunk, a3 as ToolExecution, a0 as ToolLocation, t as ToolMessage, a6 as ToolNativeProviderHints, ad as ToolOutputPart, x as ToolResult, J as ToolResultChunk, a1 as UnifiedToolCall, a2 as UnifiedToolResult, u as UserContentPart, U as UserMessage } from './types-Dg1Bcg1k.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as AIProvider } from './types-
|
|
5
|
-
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-
|
|
6
|
-
import { L as LLMAdapter } from './base-
|
|
7
|
-
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-
|
|
4
|
+
import { A as AIProvider } from './types-DHQEMFHA.mjs';
|
|
5
|
+
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-DHQEMFHA.mjs';
|
|
6
|
+
import { L as LLMAdapter } from './base-BICaQaRS.mjs';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-BICaQaRS.mjs';
|
|
8
8
|
import * as hono from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
|
-
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-
|
|
10
|
+
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-C3RgRbEC.mjs';
|
|
11
|
+
export { A as AudioAPIError, f as AudioResponseMetadata, h as AudioWarning, G as GeneratedSpeech, d as SpeechFormat, S as SpeechModel, a as SpeechOptions, e as TranscriptSegment, T as TranscriptionModel, b as TranscriptionOptions, c as TranscriptionResult, g as generateSpeech, t as transcribe } from './audio-BBSwnjo8.mjs';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* generateText - Generate text using a language model
|
|
@@ -77,30 +78,6 @@ declare function generateText(params: GenerateTextParams): Promise<GenerateTextR
|
|
|
77
78
|
*/
|
|
78
79
|
declare function streamText(params: StreamTextParams): Promise<StreamTextResult>;
|
|
79
80
|
|
|
80
|
-
/**
|
|
81
|
-
* Tool Helper
|
|
82
|
-
*
|
|
83
|
-
* Create type-safe tools with Zod schema validation.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* import { tool } from '@yourgpt/llm-sdk';
|
|
88
|
-
* import { z } from 'zod';
|
|
89
|
-
*
|
|
90
|
-
* const weatherTool = tool({
|
|
91
|
-
* description: 'Get current weather for a city',
|
|
92
|
-
* parameters: z.object({
|
|
93
|
-
* city: z.string().describe('City name'),
|
|
94
|
-
* unit: z.enum(['celsius', 'fahrenheit']).optional(),
|
|
95
|
-
* }),
|
|
96
|
-
* execute: async ({ city, unit }) => {
|
|
97
|
-
* const data = await fetchWeather(city);
|
|
98
|
-
* return { temperature: data.temp, condition: data.condition };
|
|
99
|
-
* },
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
81
|
/**
|
|
105
82
|
* Configuration for creating a tool
|
|
106
83
|
*/
|
|
@@ -111,6 +88,8 @@ interface ToolConfig<TParams extends z.ZodType, TResult = unknown> {
|
|
|
111
88
|
parameters: TParams;
|
|
112
89
|
/** Function to execute when the tool is called */
|
|
113
90
|
execute: (params: z.infer<TParams>, context: ToolContext) => Promise<TResult>;
|
|
91
|
+
/** Map the raw result to explicit text/image content for the model. */
|
|
92
|
+
toModelOutput?: (result: TResult) => ToolModelOutput | undefined;
|
|
114
93
|
/**
|
|
115
94
|
* Hide this tool's execution from the chat UI.
|
|
116
95
|
* When true, tool calls and results won't be displayed to the user,
|
|
@@ -149,7 +128,7 @@ declare function tool<TParams extends z.ZodType, TResult = unknown>(config: Tool
|
|
|
149
128
|
/**
|
|
150
129
|
* Format tools for OpenAI API format
|
|
151
130
|
*/
|
|
152
|
-
declare function formatToolsForOpenAI(tools: Record<string, Tool
|
|
131
|
+
declare function formatToolsForOpenAI(tools: Record<string, Tool<any, any>>): Array<{
|
|
153
132
|
type: "function";
|
|
154
133
|
function: {
|
|
155
134
|
name: string;
|
|
@@ -160,7 +139,7 @@ declare function formatToolsForOpenAI(tools: Record<string, Tool>): Array<{
|
|
|
160
139
|
/**
|
|
161
140
|
* Format tools for Anthropic API format
|
|
162
141
|
*/
|
|
163
|
-
declare function formatToolsForAnthropic(tools: Record<string, Tool
|
|
142
|
+
declare function formatToolsForAnthropic(tools: Record<string, Tool<any, any>>): Array<{
|
|
164
143
|
name: string;
|
|
165
144
|
description: string;
|
|
166
145
|
input_schema: object;
|
|
@@ -168,7 +147,7 @@ declare function formatToolsForAnthropic(tools: Record<string, Tool>): Array<{
|
|
|
168
147
|
/**
|
|
169
148
|
* Format tools for Google Gemini API format
|
|
170
149
|
*/
|
|
171
|
-
declare function formatToolsForGoogle(tools: Record<string, Tool
|
|
150
|
+
declare function formatToolsForGoogle(tools: Record<string, Tool<any, any>>): Array<{
|
|
172
151
|
functionDeclarations: Array<{
|
|
173
152
|
name: string;
|
|
174
153
|
description: string;
|
|
@@ -364,6 +343,8 @@ interface MessageAttachment {
|
|
|
364
343
|
interface ChatRequest {
|
|
365
344
|
/** Conversation messages */
|
|
366
345
|
messages: Array<{
|
|
346
|
+
modelOutput?: ToolModelOutput;
|
|
347
|
+
providerMetadata?: ProviderMetadata;
|
|
367
348
|
role: string;
|
|
368
349
|
content: string;
|
|
369
350
|
/** Attachments like images (for vision support) */
|
|
@@ -386,6 +367,8 @@ interface ChatRequest {
|
|
|
386
367
|
botId?: string;
|
|
387
368
|
/** LLM config overrides */
|
|
388
369
|
config?: {
|
|
370
|
+
openai?: OpenAITransportOptions;
|
|
371
|
+
reasoningEffort?: OpenAIReasoningEffort;
|
|
389
372
|
temperature?: number;
|
|
390
373
|
maxTokens?: number;
|
|
391
374
|
responseFormat?: ResponseFormat;
|
|
@@ -1537,4 +1520,4 @@ declare function generateThreadId(): string;
|
|
|
1537
1520
|
*/
|
|
1538
1521
|
declare function generateToolCallId(): string;
|
|
1539
1522
|
|
|
1540
|
-
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, Message, ProviderToolRuntimeOptions, type RequestContext, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|
|
1523
|
+
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, Message, OpenAITransportOptions, ProviderMetadata, ProviderToolRuntimeOptions, type RequestContext, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolModelOutput, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, A as ActionDefinition,
|
|
2
|
-
export {
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as ToolModelOutput, d as Tool, A as ActionDefinition, e as ToolDefinition, f as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, g as StorageAdapter, P as ProviderMetadata, O as OpenAITransportOptions, h as OpenAIReasoningEffort, R as ResponseFormat, D as DoneEventMessage, i as StreamEvent, j as ToolCallInfo, k as TokenUsageRaw, l as ProviderToolRuntimeOptions, M as Message, m as ToolResponse, n as StorageMessage } from './types-Dg1Bcg1k.js';
|
|
2
|
+
export { a8 as AnthropicProviderToolOptions, a5 as AnthropicToolSelectionHints, s as AssistantMessage, a9 as Citation, C as CoreMessage, _ as DEFAULT_CAPABILITIES, p as DoGenerateParams, q as DoGenerateResult, Q as ErrorChunk, F as FilePart, N as FinishChunk, X as FinishReason, y as GenerateStep, I as ImagePart, $ as LLMConfig, L as LanguageModel, o as ModelCapabilities, a7 as OpenAIProviderToolOptions, ab as OpenAIResponseItem, ac as OpenAIResponseMetadata, aa as OpenAIResponsesOptions, a4 as OpenAIToolSelectionHints, Y as ResponseOptions, Z as StorageFile, B as StreamChunk, z as StreamPart, r as SystemMessage, E as TextDeltaChunk, v as TextPart, V as TokenUsage, w as ToolCall, H as ToolCallChunk, a3 as ToolExecution, a0 as ToolLocation, t as ToolMessage, a6 as ToolNativeProviderHints, ad as ToolOutputPart, x as ToolResult, J as ToolResultChunk, a1 as UnifiedToolCall, a2 as UnifiedToolResult, u as UserContentPart, U as UserMessage } from './types-Dg1Bcg1k.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as AIProvider } from './types-
|
|
5
|
-
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-
|
|
6
|
-
import { L as LLMAdapter } from './base-
|
|
7
|
-
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-
|
|
4
|
+
import { A as AIProvider } from './types-Dikj3En4.js';
|
|
5
|
+
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-Dikj3En4.js';
|
|
6
|
+
import { L as LLMAdapter } from './base-CpRPB8u8.js';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-CpRPB8u8.js';
|
|
8
8
|
import * as hono from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
|
-
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-
|
|
10
|
+
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-DCFqkJAy.js';
|
|
11
|
+
export { A as AudioAPIError, f as AudioResponseMetadata, h as AudioWarning, G as GeneratedSpeech, d as SpeechFormat, S as SpeechModel, a as SpeechOptions, e as TranscriptSegment, T as TranscriptionModel, b as TranscriptionOptions, c as TranscriptionResult, g as generateSpeech, t as transcribe } from './audio-BBSwnjo8.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* generateText - Generate text using a language model
|
|
@@ -77,30 +78,6 @@ declare function generateText(params: GenerateTextParams): Promise<GenerateTextR
|
|
|
77
78
|
*/
|
|
78
79
|
declare function streamText(params: StreamTextParams): Promise<StreamTextResult>;
|
|
79
80
|
|
|
80
|
-
/**
|
|
81
|
-
* Tool Helper
|
|
82
|
-
*
|
|
83
|
-
* Create type-safe tools with Zod schema validation.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* import { tool } from '@yourgpt/llm-sdk';
|
|
88
|
-
* import { z } from 'zod';
|
|
89
|
-
*
|
|
90
|
-
* const weatherTool = tool({
|
|
91
|
-
* description: 'Get current weather for a city',
|
|
92
|
-
* parameters: z.object({
|
|
93
|
-
* city: z.string().describe('City name'),
|
|
94
|
-
* unit: z.enum(['celsius', 'fahrenheit']).optional(),
|
|
95
|
-
* }),
|
|
96
|
-
* execute: async ({ city, unit }) => {
|
|
97
|
-
* const data = await fetchWeather(city);
|
|
98
|
-
* return { temperature: data.temp, condition: data.condition };
|
|
99
|
-
* },
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
81
|
/**
|
|
105
82
|
* Configuration for creating a tool
|
|
106
83
|
*/
|
|
@@ -111,6 +88,8 @@ interface ToolConfig<TParams extends z.ZodType, TResult = unknown> {
|
|
|
111
88
|
parameters: TParams;
|
|
112
89
|
/** Function to execute when the tool is called */
|
|
113
90
|
execute: (params: z.infer<TParams>, context: ToolContext) => Promise<TResult>;
|
|
91
|
+
/** Map the raw result to explicit text/image content for the model. */
|
|
92
|
+
toModelOutput?: (result: TResult) => ToolModelOutput | undefined;
|
|
114
93
|
/**
|
|
115
94
|
* Hide this tool's execution from the chat UI.
|
|
116
95
|
* When true, tool calls and results won't be displayed to the user,
|
|
@@ -149,7 +128,7 @@ declare function tool<TParams extends z.ZodType, TResult = unknown>(config: Tool
|
|
|
149
128
|
/**
|
|
150
129
|
* Format tools for OpenAI API format
|
|
151
130
|
*/
|
|
152
|
-
declare function formatToolsForOpenAI(tools: Record<string, Tool
|
|
131
|
+
declare function formatToolsForOpenAI(tools: Record<string, Tool<any, any>>): Array<{
|
|
153
132
|
type: "function";
|
|
154
133
|
function: {
|
|
155
134
|
name: string;
|
|
@@ -160,7 +139,7 @@ declare function formatToolsForOpenAI(tools: Record<string, Tool>): Array<{
|
|
|
160
139
|
/**
|
|
161
140
|
* Format tools for Anthropic API format
|
|
162
141
|
*/
|
|
163
|
-
declare function formatToolsForAnthropic(tools: Record<string, Tool
|
|
142
|
+
declare function formatToolsForAnthropic(tools: Record<string, Tool<any, any>>): Array<{
|
|
164
143
|
name: string;
|
|
165
144
|
description: string;
|
|
166
145
|
input_schema: object;
|
|
@@ -168,7 +147,7 @@ declare function formatToolsForAnthropic(tools: Record<string, Tool>): Array<{
|
|
|
168
147
|
/**
|
|
169
148
|
* Format tools for Google Gemini API format
|
|
170
149
|
*/
|
|
171
|
-
declare function formatToolsForGoogle(tools: Record<string, Tool
|
|
150
|
+
declare function formatToolsForGoogle(tools: Record<string, Tool<any, any>>): Array<{
|
|
172
151
|
functionDeclarations: Array<{
|
|
173
152
|
name: string;
|
|
174
153
|
description: string;
|
|
@@ -364,6 +343,8 @@ interface MessageAttachment {
|
|
|
364
343
|
interface ChatRequest {
|
|
365
344
|
/** Conversation messages */
|
|
366
345
|
messages: Array<{
|
|
346
|
+
modelOutput?: ToolModelOutput;
|
|
347
|
+
providerMetadata?: ProviderMetadata;
|
|
367
348
|
role: string;
|
|
368
349
|
content: string;
|
|
369
350
|
/** Attachments like images (for vision support) */
|
|
@@ -386,6 +367,8 @@ interface ChatRequest {
|
|
|
386
367
|
botId?: string;
|
|
387
368
|
/** LLM config overrides */
|
|
388
369
|
config?: {
|
|
370
|
+
openai?: OpenAITransportOptions;
|
|
371
|
+
reasoningEffort?: OpenAIReasoningEffort;
|
|
389
372
|
temperature?: number;
|
|
390
373
|
maxTokens?: number;
|
|
391
374
|
responseFormat?: ResponseFormat;
|
|
@@ -1537,4 +1520,4 @@ declare function generateThreadId(): string;
|
|
|
1537
1520
|
*/
|
|
1538
1521
|
declare function generateToolCallId(): string;
|
|
1539
1522
|
|
|
1540
|
-
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, Message, ProviderToolRuntimeOptions, type RequestContext, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|
|
1523
|
+
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, Message, OpenAITransportOptions, ProviderMetadata, ProviderToolRuntimeOptions, type RequestContext, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolModelOutput, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|