@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.1
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 +19 -1
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +293 -23
- package/dist/adapters/index.mjs +293 -23
- package/dist/base-BYQKp9TW.d.mts +263 -0
- package/dist/base-Cxq3ni0t.d.ts +263 -0
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +61 -8
- package/dist/index.d.ts +61 -8
- package/dist/index.js +71 -0
- package/dist/index.mjs +71 -0
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +360 -203
- package/dist/providers/anthropic/index.mjs +360 -203
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +49 -1
- package/dist/providers/azure/index.mjs +49 -1
- package/dist/providers/fireworks/index.d.mts +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/fireworks/index.js +56 -0
- package/dist/providers/fireworks/index.mjs +56 -0
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +303 -207
- package/dist/providers/google/index.mjs +303 -207
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +10 -2
- package/dist/providers/ollama/index.mjs +10 -2
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +318 -216
- package/dist/providers/openai/index.mjs +318 -216
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +308 -206
- package/dist/providers/openrouter/index.mjs +308 -206
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +308 -206
- package/dist/providers/togetherai/index.mjs +308 -206
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +307 -210
- package/dist/providers/xai/index.mjs +307 -210
- package/dist/{types-BctsnC3g.d.ts → types-BvkiJ1dd.d.mts} +2 -1
- package/dist/{types-38yolWJn.d.ts → types-ChORafYS.d.ts} +1 -1
- package/dist/types-D774b0dg.d.mts +1018 -0
- package/dist/types-D774b0dg.d.ts +1018 -0
- package/dist/{types-DRqxMIjF.d.mts → types-TMilS-Dz.d.ts} +2 -1
- package/dist/{types-D4YfrQJR.d.mts → types-mwMhCwOq.d.mts} +1 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/base-D-U61JaB.d.mts +0 -788
- package/dist/base-iGi9Va6Z.d.ts +0 -788
- package/dist/types-CR8mi9I0.d.mts +0 -417
- package/dist/types-CR8mi9I0.d.ts +0 -417
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { k as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, M as McpServerConfig, g as ReasoningEffort, W as WebSearchConfig, P as ProviderToolRuntimeOptions, h as StreamEvent, O as TokenUsage, Z as LLMConfig, a8 as MessageAttachment } from './types-D774b0dg.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Request-level LLM configuration overrides
|
|
5
|
+
*/
|
|
6
|
+
interface RequestLLMConfig {
|
|
7
|
+
model?: string;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
responseFormat?: ResponseFormat;
|
|
11
|
+
/** MCP servers exposed to the model for this request (provider-translated). */
|
|
12
|
+
mcpServers?: McpServerConfig[];
|
|
13
|
+
/** Reasoning/thinking effort knob (provider-translated). */
|
|
14
|
+
reasoningEffort?: ReasoningEffort;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Chat completion request
|
|
18
|
+
*/
|
|
19
|
+
interface ChatCompletionRequest {
|
|
20
|
+
/** Conversation messages */
|
|
21
|
+
messages: Message[];
|
|
22
|
+
/**
|
|
23
|
+
* Raw provider-formatted messages (for agent loop with tool calls)
|
|
24
|
+
* When provided, these are used instead of converting from Message[]
|
|
25
|
+
* This allows passing messages with tool_calls and tool role
|
|
26
|
+
*/
|
|
27
|
+
rawMessages?: Array<Record<string, unknown>>;
|
|
28
|
+
/** Available actions/tools */
|
|
29
|
+
actions?: ActionDefinition[];
|
|
30
|
+
/** Full tool definitions for provider-native tool search / deferred loading paths. */
|
|
31
|
+
toolDefinitions?: ToolDefinition[];
|
|
32
|
+
/** System prompt */
|
|
33
|
+
systemPrompt?: string;
|
|
34
|
+
/** LLM configuration overrides */
|
|
35
|
+
config?: RequestLLMConfig;
|
|
36
|
+
/** Abort signal for cancellation */
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/**
|
|
39
|
+
* Enable native web search for the provider.
|
|
40
|
+
* When true or configured, the provider's native search is enabled.
|
|
41
|
+
*/
|
|
42
|
+
webSearch?: boolean | WebSearchConfig;
|
|
43
|
+
/** Optional provider-specific tool policy hints derived from runtime selection. */
|
|
44
|
+
providerToolOptions?: ProviderToolRuntimeOptions;
|
|
45
|
+
/** Enable adapter-level provider payload logging. */
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Non-streaming completion result
|
|
50
|
+
*/
|
|
51
|
+
interface CompletionResult {
|
|
52
|
+
/** Text content */
|
|
53
|
+
content: string;
|
|
54
|
+
/** Tool calls */
|
|
55
|
+
toolCalls: Array<{
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
args: Record<string, unknown>;
|
|
59
|
+
/** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
|
|
60
|
+
extra_content?: Record<string, unknown>;
|
|
61
|
+
}>;
|
|
62
|
+
/** Thinking content (if extended thinking enabled) */
|
|
63
|
+
thinking?: string;
|
|
64
|
+
/** Token usage for billing/tracking */
|
|
65
|
+
usage?: TokenUsage;
|
|
66
|
+
/** Raw provider response for debugging */
|
|
67
|
+
rawResponse: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Base LLM adapter interface
|
|
71
|
+
*/
|
|
72
|
+
interface LLMAdapter {
|
|
73
|
+
/** Provider name */
|
|
74
|
+
readonly provider: string;
|
|
75
|
+
/** Model name */
|
|
76
|
+
readonly model: string;
|
|
77
|
+
/**
|
|
78
|
+
* Stream a chat completion
|
|
79
|
+
*/
|
|
80
|
+
stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
|
|
81
|
+
/**
|
|
82
|
+
* Non-streaming chat completion (for debugging/comparison)
|
|
83
|
+
*/
|
|
84
|
+
complete?(request: ChatCompletionRequest): Promise<CompletionResult>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Adapter factory function type
|
|
88
|
+
*/
|
|
89
|
+
type AdapterFactory = (config: LLMConfig) => LLMAdapter;
|
|
90
|
+
/**
|
|
91
|
+
* Convert messages to provider format (simple text only)
|
|
92
|
+
*/
|
|
93
|
+
declare function formatMessages(messages: Message[], systemPrompt?: string): Array<{
|
|
94
|
+
role: string;
|
|
95
|
+
content: string;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Convert actions to OpenAI tool format
|
|
99
|
+
*/
|
|
100
|
+
declare function formatTools(actions: ActionDefinition[]): Array<{
|
|
101
|
+
type: "function";
|
|
102
|
+
function: {
|
|
103
|
+
name: string;
|
|
104
|
+
description: string;
|
|
105
|
+
parameters: object;
|
|
106
|
+
};
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Content block types for multimodal messages
|
|
110
|
+
*/
|
|
111
|
+
type AnthropicContentBlock = {
|
|
112
|
+
type: "text";
|
|
113
|
+
text: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: "image";
|
|
116
|
+
source: {
|
|
117
|
+
type: "base64";
|
|
118
|
+
media_type: string;
|
|
119
|
+
data: string;
|
|
120
|
+
} | {
|
|
121
|
+
type: "url";
|
|
122
|
+
url: string;
|
|
123
|
+
};
|
|
124
|
+
} | {
|
|
125
|
+
type: "document";
|
|
126
|
+
source: {
|
|
127
|
+
type: "base64";
|
|
128
|
+
media_type: string;
|
|
129
|
+
data: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: "url";
|
|
132
|
+
url: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
type OpenAIContentBlock = {
|
|
136
|
+
type: "text";
|
|
137
|
+
text: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: "image_url";
|
|
140
|
+
image_url: {
|
|
141
|
+
url: string;
|
|
142
|
+
detail?: "low" | "high" | "auto";
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Check if a message has image attachments
|
|
147
|
+
* Supports both new format (metadata.attachments) and legacy (attachments)
|
|
148
|
+
*/
|
|
149
|
+
declare function hasImageAttachments(message: Message): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Check if a message has media attachments (images or PDFs)
|
|
152
|
+
*/
|
|
153
|
+
declare function hasMediaAttachments(message: Message): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Convert MessageAttachment to Anthropic image content block
|
|
156
|
+
*
|
|
157
|
+
* Anthropic format:
|
|
158
|
+
* {
|
|
159
|
+
* type: "image",
|
|
160
|
+
* source: {
|
|
161
|
+
* type: "base64",
|
|
162
|
+
* media_type: "image/png",
|
|
163
|
+
* data: "base64data..."
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
*/
|
|
167
|
+
declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
|
|
168
|
+
/**
|
|
169
|
+
* Convert MessageAttachment to OpenAI image_url content block
|
|
170
|
+
*
|
|
171
|
+
* OpenAI format:
|
|
172
|
+
* {
|
|
173
|
+
* type: "image_url",
|
|
174
|
+
* image_url: {
|
|
175
|
+
* url: "data:image/png;base64,..."
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
*/
|
|
179
|
+
declare function attachmentToOpenAIImage(attachment: MessageAttachment): OpenAIContentBlock | null;
|
|
180
|
+
/**
|
|
181
|
+
* Convert MessageAttachment (PDF) to Anthropic document content block
|
|
182
|
+
*
|
|
183
|
+
* Anthropic format:
|
|
184
|
+
* {
|
|
185
|
+
* type: "document",
|
|
186
|
+
* source: {
|
|
187
|
+
* type: "base64",
|
|
188
|
+
* media_type: "application/pdf",
|
|
189
|
+
* data: "base64data..."
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
*/
|
|
193
|
+
declare function attachmentToAnthropicDocument(attachment: MessageAttachment): AnthropicContentBlock | null;
|
|
194
|
+
/**
|
|
195
|
+
* Convert a Message to Anthropic multimodal content blocks
|
|
196
|
+
*/
|
|
197
|
+
declare function messageToAnthropicContent(message: Message): string | AnthropicContentBlock[];
|
|
198
|
+
/**
|
|
199
|
+
* Convert a Message to OpenAI multimodal content blocks
|
|
200
|
+
*/
|
|
201
|
+
declare function messageToOpenAIContent(message: Message): string | OpenAIContentBlock[];
|
|
202
|
+
/**
|
|
203
|
+
* Anthropic content block types (extended for tools)
|
|
204
|
+
*/
|
|
205
|
+
type AnthropicToolUseBlock = {
|
|
206
|
+
type: "tool_use";
|
|
207
|
+
id: string;
|
|
208
|
+
name: string;
|
|
209
|
+
input: Record<string, unknown>;
|
|
210
|
+
};
|
|
211
|
+
type AnthropicToolResultBlock = {
|
|
212
|
+
type: "tool_result";
|
|
213
|
+
tool_use_id: string;
|
|
214
|
+
content: string;
|
|
215
|
+
};
|
|
216
|
+
type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
|
|
217
|
+
/**
|
|
218
|
+
* Format messages for Anthropic with full tool support
|
|
219
|
+
* Handles: text, images, tool_use, and tool_result
|
|
220
|
+
*
|
|
221
|
+
* Key differences from OpenAI:
|
|
222
|
+
* - tool_calls become tool_use blocks in assistant content
|
|
223
|
+
* - tool results become tool_result blocks in user content
|
|
224
|
+
*/
|
|
225
|
+
declare function formatMessagesForAnthropic(messages: Message[], systemPrompt?: string): {
|
|
226
|
+
system: string;
|
|
227
|
+
messages: Array<{
|
|
228
|
+
role: "user" | "assistant";
|
|
229
|
+
content: AnthropicMessageContent;
|
|
230
|
+
}>;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* OpenAI message format with tool support
|
|
234
|
+
*/
|
|
235
|
+
type OpenAIMessage = {
|
|
236
|
+
role: "system";
|
|
237
|
+
content: string;
|
|
238
|
+
} | {
|
|
239
|
+
role: "user";
|
|
240
|
+
content: string | OpenAIContentBlock[];
|
|
241
|
+
} | {
|
|
242
|
+
role: "assistant";
|
|
243
|
+
content: string | null;
|
|
244
|
+
tool_calls?: Array<{
|
|
245
|
+
id: string;
|
|
246
|
+
type: "function";
|
|
247
|
+
function: {
|
|
248
|
+
name: string;
|
|
249
|
+
arguments: string;
|
|
250
|
+
};
|
|
251
|
+
}>;
|
|
252
|
+
} | {
|
|
253
|
+
role: "tool";
|
|
254
|
+
content: string;
|
|
255
|
+
tool_call_id: string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Format messages for OpenAI with full tool support
|
|
259
|
+
* Handles: text, images, tool_calls, and tool results
|
|
260
|
+
*/
|
|
261
|
+
declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
|
|
262
|
+
|
|
263
|
+
export { type AdapterFactory as A, type ChatCompletionRequest as C, type LLMAdapter as L, type OpenAIContentBlock as O, type CompletionResult as a, formatTools as b, formatMessagesForAnthropic as c, formatMessagesForOpenAI as d, messageToOpenAIContent as e, formatMessages as f, hasMediaAttachments as g, hasImageAttachments as h, attachmentToAnthropicImage as i, attachmentToAnthropicDocument as j, attachmentToOpenAIImage as k, type AnthropicContentBlock as l, messageToAnthropicContent as m };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { k as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, M as McpServerConfig, g as ReasoningEffort, W as WebSearchConfig, P as ProviderToolRuntimeOptions, h as StreamEvent, O as TokenUsage, Z as LLMConfig, a8 as MessageAttachment } from './types-D774b0dg.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Request-level LLM configuration overrides
|
|
5
|
+
*/
|
|
6
|
+
interface RequestLLMConfig {
|
|
7
|
+
model?: string;
|
|
8
|
+
temperature?: number;
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
responseFormat?: ResponseFormat;
|
|
11
|
+
/** MCP servers exposed to the model for this request (provider-translated). */
|
|
12
|
+
mcpServers?: McpServerConfig[];
|
|
13
|
+
/** Reasoning/thinking effort knob (provider-translated). */
|
|
14
|
+
reasoningEffort?: ReasoningEffort;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Chat completion request
|
|
18
|
+
*/
|
|
19
|
+
interface ChatCompletionRequest {
|
|
20
|
+
/** Conversation messages */
|
|
21
|
+
messages: Message[];
|
|
22
|
+
/**
|
|
23
|
+
* Raw provider-formatted messages (for agent loop with tool calls)
|
|
24
|
+
* When provided, these are used instead of converting from Message[]
|
|
25
|
+
* This allows passing messages with tool_calls and tool role
|
|
26
|
+
*/
|
|
27
|
+
rawMessages?: Array<Record<string, unknown>>;
|
|
28
|
+
/** Available actions/tools */
|
|
29
|
+
actions?: ActionDefinition[];
|
|
30
|
+
/** Full tool definitions for provider-native tool search / deferred loading paths. */
|
|
31
|
+
toolDefinitions?: ToolDefinition[];
|
|
32
|
+
/** System prompt */
|
|
33
|
+
systemPrompt?: string;
|
|
34
|
+
/** LLM configuration overrides */
|
|
35
|
+
config?: RequestLLMConfig;
|
|
36
|
+
/** Abort signal for cancellation */
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/**
|
|
39
|
+
* Enable native web search for the provider.
|
|
40
|
+
* When true or configured, the provider's native search is enabled.
|
|
41
|
+
*/
|
|
42
|
+
webSearch?: boolean | WebSearchConfig;
|
|
43
|
+
/** Optional provider-specific tool policy hints derived from runtime selection. */
|
|
44
|
+
providerToolOptions?: ProviderToolRuntimeOptions;
|
|
45
|
+
/** Enable adapter-level provider payload logging. */
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Non-streaming completion result
|
|
50
|
+
*/
|
|
51
|
+
interface CompletionResult {
|
|
52
|
+
/** Text content */
|
|
53
|
+
content: string;
|
|
54
|
+
/** Tool calls */
|
|
55
|
+
toolCalls: Array<{
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
args: Record<string, unknown>;
|
|
59
|
+
/** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
|
|
60
|
+
extra_content?: Record<string, unknown>;
|
|
61
|
+
}>;
|
|
62
|
+
/** Thinking content (if extended thinking enabled) */
|
|
63
|
+
thinking?: string;
|
|
64
|
+
/** Token usage for billing/tracking */
|
|
65
|
+
usage?: TokenUsage;
|
|
66
|
+
/** Raw provider response for debugging */
|
|
67
|
+
rawResponse: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Base LLM adapter interface
|
|
71
|
+
*/
|
|
72
|
+
interface LLMAdapter {
|
|
73
|
+
/** Provider name */
|
|
74
|
+
readonly provider: string;
|
|
75
|
+
/** Model name */
|
|
76
|
+
readonly model: string;
|
|
77
|
+
/**
|
|
78
|
+
* Stream a chat completion
|
|
79
|
+
*/
|
|
80
|
+
stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
|
|
81
|
+
/**
|
|
82
|
+
* Non-streaming chat completion (for debugging/comparison)
|
|
83
|
+
*/
|
|
84
|
+
complete?(request: ChatCompletionRequest): Promise<CompletionResult>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Adapter factory function type
|
|
88
|
+
*/
|
|
89
|
+
type AdapterFactory = (config: LLMConfig) => LLMAdapter;
|
|
90
|
+
/**
|
|
91
|
+
* Convert messages to provider format (simple text only)
|
|
92
|
+
*/
|
|
93
|
+
declare function formatMessages(messages: Message[], systemPrompt?: string): Array<{
|
|
94
|
+
role: string;
|
|
95
|
+
content: string;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Convert actions to OpenAI tool format
|
|
99
|
+
*/
|
|
100
|
+
declare function formatTools(actions: ActionDefinition[]): Array<{
|
|
101
|
+
type: "function";
|
|
102
|
+
function: {
|
|
103
|
+
name: string;
|
|
104
|
+
description: string;
|
|
105
|
+
parameters: object;
|
|
106
|
+
};
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Content block types for multimodal messages
|
|
110
|
+
*/
|
|
111
|
+
type AnthropicContentBlock = {
|
|
112
|
+
type: "text";
|
|
113
|
+
text: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: "image";
|
|
116
|
+
source: {
|
|
117
|
+
type: "base64";
|
|
118
|
+
media_type: string;
|
|
119
|
+
data: string;
|
|
120
|
+
} | {
|
|
121
|
+
type: "url";
|
|
122
|
+
url: string;
|
|
123
|
+
};
|
|
124
|
+
} | {
|
|
125
|
+
type: "document";
|
|
126
|
+
source: {
|
|
127
|
+
type: "base64";
|
|
128
|
+
media_type: string;
|
|
129
|
+
data: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: "url";
|
|
132
|
+
url: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
type OpenAIContentBlock = {
|
|
136
|
+
type: "text";
|
|
137
|
+
text: string;
|
|
138
|
+
} | {
|
|
139
|
+
type: "image_url";
|
|
140
|
+
image_url: {
|
|
141
|
+
url: string;
|
|
142
|
+
detail?: "low" | "high" | "auto";
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Check if a message has image attachments
|
|
147
|
+
* Supports both new format (metadata.attachments) and legacy (attachments)
|
|
148
|
+
*/
|
|
149
|
+
declare function hasImageAttachments(message: Message): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Check if a message has media attachments (images or PDFs)
|
|
152
|
+
*/
|
|
153
|
+
declare function hasMediaAttachments(message: Message): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Convert MessageAttachment to Anthropic image content block
|
|
156
|
+
*
|
|
157
|
+
* Anthropic format:
|
|
158
|
+
* {
|
|
159
|
+
* type: "image",
|
|
160
|
+
* source: {
|
|
161
|
+
* type: "base64",
|
|
162
|
+
* media_type: "image/png",
|
|
163
|
+
* data: "base64data..."
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
*/
|
|
167
|
+
declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
|
|
168
|
+
/**
|
|
169
|
+
* Convert MessageAttachment to OpenAI image_url content block
|
|
170
|
+
*
|
|
171
|
+
* OpenAI format:
|
|
172
|
+
* {
|
|
173
|
+
* type: "image_url",
|
|
174
|
+
* image_url: {
|
|
175
|
+
* url: "data:image/png;base64,..."
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
*/
|
|
179
|
+
declare function attachmentToOpenAIImage(attachment: MessageAttachment): OpenAIContentBlock | null;
|
|
180
|
+
/**
|
|
181
|
+
* Convert MessageAttachment (PDF) to Anthropic document content block
|
|
182
|
+
*
|
|
183
|
+
* Anthropic format:
|
|
184
|
+
* {
|
|
185
|
+
* type: "document",
|
|
186
|
+
* source: {
|
|
187
|
+
* type: "base64",
|
|
188
|
+
* media_type: "application/pdf",
|
|
189
|
+
* data: "base64data..."
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
*/
|
|
193
|
+
declare function attachmentToAnthropicDocument(attachment: MessageAttachment): AnthropicContentBlock | null;
|
|
194
|
+
/**
|
|
195
|
+
* Convert a Message to Anthropic multimodal content blocks
|
|
196
|
+
*/
|
|
197
|
+
declare function messageToAnthropicContent(message: Message): string | AnthropicContentBlock[];
|
|
198
|
+
/**
|
|
199
|
+
* Convert a Message to OpenAI multimodal content blocks
|
|
200
|
+
*/
|
|
201
|
+
declare function messageToOpenAIContent(message: Message): string | OpenAIContentBlock[];
|
|
202
|
+
/**
|
|
203
|
+
* Anthropic content block types (extended for tools)
|
|
204
|
+
*/
|
|
205
|
+
type AnthropicToolUseBlock = {
|
|
206
|
+
type: "tool_use";
|
|
207
|
+
id: string;
|
|
208
|
+
name: string;
|
|
209
|
+
input: Record<string, unknown>;
|
|
210
|
+
};
|
|
211
|
+
type AnthropicToolResultBlock = {
|
|
212
|
+
type: "tool_result";
|
|
213
|
+
tool_use_id: string;
|
|
214
|
+
content: string;
|
|
215
|
+
};
|
|
216
|
+
type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
|
|
217
|
+
/**
|
|
218
|
+
* Format messages for Anthropic with full tool support
|
|
219
|
+
* Handles: text, images, tool_use, and tool_result
|
|
220
|
+
*
|
|
221
|
+
* Key differences from OpenAI:
|
|
222
|
+
* - tool_calls become tool_use blocks in assistant content
|
|
223
|
+
* - tool results become tool_result blocks in user content
|
|
224
|
+
*/
|
|
225
|
+
declare function formatMessagesForAnthropic(messages: Message[], systemPrompt?: string): {
|
|
226
|
+
system: string;
|
|
227
|
+
messages: Array<{
|
|
228
|
+
role: "user" | "assistant";
|
|
229
|
+
content: AnthropicMessageContent;
|
|
230
|
+
}>;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* OpenAI message format with tool support
|
|
234
|
+
*/
|
|
235
|
+
type OpenAIMessage = {
|
|
236
|
+
role: "system";
|
|
237
|
+
content: string;
|
|
238
|
+
} | {
|
|
239
|
+
role: "user";
|
|
240
|
+
content: string | OpenAIContentBlock[];
|
|
241
|
+
} | {
|
|
242
|
+
role: "assistant";
|
|
243
|
+
content: string | null;
|
|
244
|
+
tool_calls?: Array<{
|
|
245
|
+
id: string;
|
|
246
|
+
type: "function";
|
|
247
|
+
function: {
|
|
248
|
+
name: string;
|
|
249
|
+
arguments: string;
|
|
250
|
+
};
|
|
251
|
+
}>;
|
|
252
|
+
} | {
|
|
253
|
+
role: "tool";
|
|
254
|
+
content: string;
|
|
255
|
+
tool_call_id: string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Format messages for OpenAI with full tool support
|
|
259
|
+
* Handles: text, images, tool_calls, and tool results
|
|
260
|
+
*/
|
|
261
|
+
declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
|
|
262
|
+
|
|
263
|
+
export { type AdapterFactory as A, type ChatCompletionRequest as C, type LLMAdapter as L, type OpenAIContentBlock as O, type CompletionResult as a, formatTools as b, formatMessagesForAnthropic as c, formatMessagesForOpenAI as d, messageToOpenAIContent as e, formatMessages as f, hasMediaAttachments as g, hasImageAttachments as h, attachmentToAnthropicImage as i, attachmentToAnthropicDocument as j, attachmentToOpenAIImage as k, type AnthropicContentBlock as l, messageToAnthropicContent as m };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-BYQKp9TW.mjs';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-mwMhCwOq.mjs';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-mwMhCwOq.mjs';
|
|
4
|
+
import '../types-D774b0dg.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/fallback/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LLMAdapter } from '../base-
|
|
2
|
-
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-
|
|
3
|
-
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-
|
|
4
|
-
import '../types-
|
|
1
|
+
import { L as LLMAdapter } from '../base-Cxq3ni0t.js';
|
|
2
|
+
import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-ChORafYS.js';
|
|
3
|
+
export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-ChORafYS.js';
|
|
4
|
+
import '../types-D774b0dg.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as
|
|
2
|
-
export {
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, A as ActionDefinition, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, R as ResponseFormat, M as McpServerConfig, g as ReasoningEffort, D as DoneEventMessage, h as StreamEvent, i as ToolCallInfo, j as TokenUsageRaw, P as ProviderToolRuntimeOptions, k as Message, l as ToolResponse, m as StorageMessage } from './types-D774b0dg.mjs';
|
|
2
|
+
export { a6 as AnthropicProviderToolOptions, a3 as AnthropicToolSelectionHints, r as AssistantMessage, a7 as Citation, C as CoreMessage, Y as DEFAULT_CAPABILITIES, o as DoGenerateParams, p as DoGenerateResult, N as ErrorChunk, F as FilePart, J as FinishChunk, Q as FinishReason, x as GenerateStep, I as ImagePart, Z as LLMConfig, L as LanguageModel, n as ModelCapabilities, a5 as OpenAIProviderToolOptions, a2 as OpenAIToolSelectionHints, V as ResponseOptions, X as StorageFile, z as StreamChunk, y as StreamPart, q as SystemMessage, B as TextDeltaChunk, u as TextPart, O as TokenUsage, v as ToolCall, E as ToolCallChunk, a1 as ToolExecution, _ as ToolLocation, s as ToolMessage, a4 as ToolNativeProviderHints, w as ToolResult, H as ToolResultChunk, $ as UnifiedToolCall, a0 as UnifiedToolResult, t as UserContentPart, U as UserMessage } from './types-D774b0dg.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as
|
|
5
|
-
export {
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
4
|
+
import { A as AIProvider } from './types-BvkiJ1dd.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-BvkiJ1dd.mjs';
|
|
6
|
+
import { L as LLMAdapter } from './base-BYQKp9TW.mjs';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-BYQKp9TW.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-mwMhCwOq.mjs';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
|
@@ -388,6 +388,9 @@ interface ChatRequest {
|
|
|
388
388
|
config?: {
|
|
389
389
|
temperature?: number;
|
|
390
390
|
maxTokens?: number;
|
|
391
|
+
responseFormat?: ResponseFormat;
|
|
392
|
+
mcpServers?: McpServerConfig[];
|
|
393
|
+
reasoningEffort?: ReasoningEffort;
|
|
391
394
|
};
|
|
392
395
|
/** System prompt override */
|
|
393
396
|
systemPrompt?: string;
|
|
@@ -797,6 +800,11 @@ declare function createStreamResult(generator: AsyncGenerator<StreamEvent>): Str
|
|
|
797
800
|
* ```
|
|
798
801
|
*/
|
|
799
802
|
|
|
803
|
+
interface GenerateUsage {
|
|
804
|
+
promptTokens: number;
|
|
805
|
+
completionTokens: number;
|
|
806
|
+
totalTokens: number;
|
|
807
|
+
}
|
|
800
808
|
interface GenerateResultData {
|
|
801
809
|
text: string;
|
|
802
810
|
messages: DoneEventMessage[];
|
|
@@ -810,6 +818,7 @@ interface GenerateResultData {
|
|
|
810
818
|
result: unknown;
|
|
811
819
|
}>;
|
|
812
820
|
requiresAction: boolean;
|
|
821
|
+
usage?: GenerateUsage;
|
|
813
822
|
error?: {
|
|
814
823
|
message: string;
|
|
815
824
|
code?: string;
|
|
@@ -863,6 +872,12 @@ declare class GenerateResult {
|
|
|
863
872
|
* Whether client action is required (e.g., tool approval)
|
|
864
873
|
*/
|
|
865
874
|
get requiresAction(): boolean;
|
|
875
|
+
/**
|
|
876
|
+
* Token usage for the call — present when the underlying provider emitted
|
|
877
|
+
* a usage payload on the `done` event. May be undefined for streaming
|
|
878
|
+
* responses that don't yield usage (e.g. mid-stream errors).
|
|
879
|
+
*/
|
|
880
|
+
get usage(): GenerateUsage | undefined;
|
|
866
881
|
/**
|
|
867
882
|
* Error if generation failed
|
|
868
883
|
*/
|
|
@@ -1122,6 +1137,44 @@ declare class Runtime {
|
|
|
1122
1137
|
* ```
|
|
1123
1138
|
*/
|
|
1124
1139
|
generate(request: ChatRequest, options?: GenerateOptions): Promise<GenerateResult>;
|
|
1140
|
+
/**
|
|
1141
|
+
* One-shot non-streaming call bundling MCP servers, reasoning effort, and
|
|
1142
|
+
* structured output. Thin ergonomic wrapper around `generate()` — uses the
|
|
1143
|
+
* same adapter chain and the same translators, just expressed as a single
|
|
1144
|
+
* prompt-in / text-out call.
|
|
1145
|
+
*
|
|
1146
|
+
* @example
|
|
1147
|
+
* ```ts
|
|
1148
|
+
* const result = await runtime.response({
|
|
1149
|
+
* prompt: "Extract FAQs from this conversation.",
|
|
1150
|
+
* mcpServers: [{ label: "kb", url: "https://kb.example.com/sse", headers: { Authorization: token } }],
|
|
1151
|
+
* reasoningEffort: "high",
|
|
1152
|
+
* responseFormat: { type: "json_schema", json_schema: { name: "faqs", schema } },
|
|
1153
|
+
* });
|
|
1154
|
+
* const data = JSON.parse(result.text);
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
response(request: {
|
|
1158
|
+
prompt: string;
|
|
1159
|
+
systemPrompt?: string;
|
|
1160
|
+
mcpServers?: McpServerConfig[];
|
|
1161
|
+
reasoningEffort?: ReasoningEffort;
|
|
1162
|
+
responseFormat?: ResponseFormat;
|
|
1163
|
+
maxTokens?: number;
|
|
1164
|
+
temperature?: number;
|
|
1165
|
+
}): Promise<{
|
|
1166
|
+
text: string;
|
|
1167
|
+
toolCalls: Array<{
|
|
1168
|
+
id: string;
|
|
1169
|
+
name: string;
|
|
1170
|
+
args: Record<string, unknown>;
|
|
1171
|
+
}>;
|
|
1172
|
+
usage?: {
|
|
1173
|
+
promptTokens: number;
|
|
1174
|
+
completionTokens: number;
|
|
1175
|
+
totalTokens: number;
|
|
1176
|
+
};
|
|
1177
|
+
}>;
|
|
1125
1178
|
/**
|
|
1126
1179
|
* Create Express-compatible handler middleware
|
|
1127
1180
|
*
|
|
@@ -1536,4 +1589,4 @@ declare function generateThreadId(): string;
|
|
|
1536
1589
|
*/
|
|
1537
1590
|
declare function generateToolCallId(): string;
|
|
1538
1591
|
|
|
1539
|
-
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 };
|
|
1592
|
+
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, McpServerConfig, Message, ProviderToolRuntimeOptions, ReasoningEffort, type RequestContext, ResponseFormat, 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 };
|