@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/adapters/index.d.mts +4 -4
  2. package/dist/adapters/index.d.ts +4 -4
  3. package/dist/adapters/index.js +156 -13
  4. package/dist/adapters/index.mjs +156 -13
  5. package/dist/base-C58Dsr9p.d.ts +259 -0
  6. package/dist/base-tNgbBaSo.d.mts +259 -0
  7. package/dist/fallback/index.d.mts +4 -4
  8. package/dist/fallback/index.d.ts +4 -4
  9. package/dist/index.d.mts +8 -7
  10. package/dist/index.d.ts +8 -7
  11. package/dist/index.js +12 -0
  12. package/dist/index.mjs +12 -0
  13. package/dist/providers/anthropic/index.d.mts +3 -3
  14. package/dist/providers/anthropic/index.d.ts +3 -3
  15. package/dist/providers/anthropic/index.js +271 -195
  16. package/dist/providers/anthropic/index.mjs +271 -195
  17. package/dist/providers/azure/index.d.mts +3 -3
  18. package/dist/providers/azure/index.d.ts +3 -3
  19. package/dist/providers/azure/index.js +49 -1
  20. package/dist/providers/azure/index.mjs +49 -1
  21. package/dist/providers/fireworks/index.d.mts +1 -1
  22. package/dist/providers/fireworks/index.d.ts +1 -1
  23. package/dist/providers/fireworks/index.js +56 -0
  24. package/dist/providers/fireworks/index.mjs +56 -0
  25. package/dist/providers/google/index.d.mts +3 -3
  26. package/dist/providers/google/index.d.ts +3 -3
  27. package/dist/providers/google/index.js +252 -205
  28. package/dist/providers/google/index.mjs +252 -205
  29. package/dist/providers/ollama/index.d.mts +4 -4
  30. package/dist/providers/ollama/index.d.ts +4 -4
  31. package/dist/providers/ollama/index.js +10 -2
  32. package/dist/providers/ollama/index.mjs +10 -2
  33. package/dist/providers/openai/index.d.mts +3 -3
  34. package/dist/providers/openai/index.d.ts +3 -3
  35. package/dist/providers/openai/index.js +267 -214
  36. package/dist/providers/openai/index.mjs +267 -214
  37. package/dist/providers/openrouter/index.d.mts +3 -3
  38. package/dist/providers/openrouter/index.d.ts +3 -3
  39. package/dist/providers/openrouter/index.js +257 -204
  40. package/dist/providers/openrouter/index.mjs +257 -204
  41. package/dist/providers/togetherai/index.d.mts +3 -3
  42. package/dist/providers/togetherai/index.d.ts +3 -3
  43. package/dist/providers/togetherai/index.js +257 -204
  44. package/dist/providers/togetherai/index.mjs +257 -204
  45. package/dist/providers/xai/index.d.mts +3 -3
  46. package/dist/providers/xai/index.d.ts +3 -3
  47. package/dist/providers/xai/index.js +256 -208
  48. package/dist/providers/xai/index.mjs +256 -208
  49. package/dist/{types-D4YfrQJR.d.mts → types-B6dhnguR.d.mts} +1 -1
  50. package/dist/{types-DRqxMIjF.d.mts → types-BQ31QIsA.d.ts} +2 -1
  51. package/dist/{types-BctsnC3g.d.ts → types-BSSiJW2o.d.mts} +2 -1
  52. package/dist/{base-D-U61JaB.d.mts → types-BkQCSiIt.d.mts} +388 -213
  53. package/dist/{base-iGi9Va6Z.d.ts → types-BkQCSiIt.d.ts} +388 -213
  54. package/dist/{types-38yolWJn.d.ts → types-CCxPmkmK.d.ts} +1 -1
  55. package/dist/yourgpt/index.d.mts +1 -1
  56. package/dist/yourgpt/index.d.ts +1 -1
  57. package/package.json +1 -1
  58. package/dist/types-CR8mi9I0.d.mts +0 -417
  59. package/dist/types-CR8mi9I0.d.ts +0 -417
@@ -0,0 +1,259 @@
1
+ import { M as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, X as LLMConfig, a6 as MessageAttachment } from './types-BkQCSiIt.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
+ }
12
+ /**
13
+ * Chat completion request
14
+ */
15
+ interface ChatCompletionRequest {
16
+ /** Conversation messages */
17
+ messages: Message[];
18
+ /**
19
+ * Raw provider-formatted messages (for agent loop with tool calls)
20
+ * When provided, these are used instead of converting from Message[]
21
+ * This allows passing messages with tool_calls and tool role
22
+ */
23
+ rawMessages?: Array<Record<string, unknown>>;
24
+ /** Available actions/tools */
25
+ actions?: ActionDefinition[];
26
+ /** Full tool definitions for provider-native tool search / deferred loading paths. */
27
+ toolDefinitions?: ToolDefinition[];
28
+ /** System prompt */
29
+ systemPrompt?: string;
30
+ /** LLM configuration overrides */
31
+ config?: RequestLLMConfig;
32
+ /** Abort signal for cancellation */
33
+ signal?: AbortSignal;
34
+ /**
35
+ * Enable native web search for the provider.
36
+ * When true or configured, the provider's native search is enabled.
37
+ */
38
+ webSearch?: boolean | WebSearchConfig;
39
+ /** Optional provider-specific tool policy hints derived from runtime selection. */
40
+ providerToolOptions?: ProviderToolRuntimeOptions;
41
+ /** Enable adapter-level provider payload logging. */
42
+ debug?: boolean;
43
+ }
44
+ /**
45
+ * Non-streaming completion result
46
+ */
47
+ interface CompletionResult {
48
+ /** Text content */
49
+ content: string;
50
+ /** Tool calls */
51
+ toolCalls: Array<{
52
+ id: string;
53
+ name: string;
54
+ args: Record<string, unknown>;
55
+ /** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
56
+ extra_content?: Record<string, unknown>;
57
+ }>;
58
+ /** Thinking content (if extended thinking enabled) */
59
+ thinking?: string;
60
+ /** Token usage for billing/tracking */
61
+ usage?: TokenUsage;
62
+ /** Raw provider response for debugging */
63
+ rawResponse: Record<string, unknown>;
64
+ }
65
+ /**
66
+ * Base LLM adapter interface
67
+ */
68
+ interface LLMAdapter {
69
+ /** Provider name */
70
+ readonly provider: string;
71
+ /** Model name */
72
+ readonly model: string;
73
+ /**
74
+ * Stream a chat completion
75
+ */
76
+ stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
77
+ /**
78
+ * Non-streaming chat completion (for debugging/comparison)
79
+ */
80
+ complete?(request: ChatCompletionRequest): Promise<CompletionResult>;
81
+ }
82
+ /**
83
+ * Adapter factory function type
84
+ */
85
+ type AdapterFactory = (config: LLMConfig) => LLMAdapter;
86
+ /**
87
+ * Convert messages to provider format (simple text only)
88
+ */
89
+ declare function formatMessages(messages: Message[], systemPrompt?: string): Array<{
90
+ role: string;
91
+ content: string;
92
+ }>;
93
+ /**
94
+ * Convert actions to OpenAI tool format
95
+ */
96
+ declare function formatTools(actions: ActionDefinition[]): Array<{
97
+ type: "function";
98
+ function: {
99
+ name: string;
100
+ description: string;
101
+ parameters: object;
102
+ };
103
+ }>;
104
+ /**
105
+ * Content block types for multimodal messages
106
+ */
107
+ type AnthropicContentBlock = {
108
+ type: "text";
109
+ text: string;
110
+ } | {
111
+ type: "image";
112
+ source: {
113
+ type: "base64";
114
+ media_type: string;
115
+ data: string;
116
+ } | {
117
+ type: "url";
118
+ url: string;
119
+ };
120
+ } | {
121
+ type: "document";
122
+ source: {
123
+ type: "base64";
124
+ media_type: string;
125
+ data: string;
126
+ } | {
127
+ type: "url";
128
+ url: string;
129
+ };
130
+ };
131
+ type OpenAIContentBlock = {
132
+ type: "text";
133
+ text: string;
134
+ } | {
135
+ type: "image_url";
136
+ image_url: {
137
+ url: string;
138
+ detail?: "low" | "high" | "auto";
139
+ };
140
+ };
141
+ /**
142
+ * Check if a message has image attachments
143
+ * Supports both new format (metadata.attachments) and legacy (attachments)
144
+ */
145
+ declare function hasImageAttachments(message: Message): boolean;
146
+ /**
147
+ * Check if a message has media attachments (images or PDFs)
148
+ */
149
+ declare function hasMediaAttachments(message: Message): boolean;
150
+ /**
151
+ * Convert MessageAttachment to Anthropic image content block
152
+ *
153
+ * Anthropic format:
154
+ * {
155
+ * type: "image",
156
+ * source: {
157
+ * type: "base64",
158
+ * media_type: "image/png",
159
+ * data: "base64data..."
160
+ * }
161
+ * }
162
+ */
163
+ declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
164
+ /**
165
+ * Convert MessageAttachment to OpenAI image_url content block
166
+ *
167
+ * OpenAI format:
168
+ * {
169
+ * type: "image_url",
170
+ * image_url: {
171
+ * url: "data:image/png;base64,..."
172
+ * }
173
+ * }
174
+ */
175
+ declare function attachmentToOpenAIImage(attachment: MessageAttachment): OpenAIContentBlock | null;
176
+ /**
177
+ * Convert MessageAttachment (PDF) to Anthropic document content block
178
+ *
179
+ * Anthropic format:
180
+ * {
181
+ * type: "document",
182
+ * source: {
183
+ * type: "base64",
184
+ * media_type: "application/pdf",
185
+ * data: "base64data..."
186
+ * }
187
+ * }
188
+ */
189
+ declare function attachmentToAnthropicDocument(attachment: MessageAttachment): AnthropicContentBlock | null;
190
+ /**
191
+ * Convert a Message to Anthropic multimodal content blocks
192
+ */
193
+ declare function messageToAnthropicContent(message: Message): string | AnthropicContentBlock[];
194
+ /**
195
+ * Convert a Message to OpenAI multimodal content blocks
196
+ */
197
+ declare function messageToOpenAIContent(message: Message): string | OpenAIContentBlock[];
198
+ /**
199
+ * Anthropic content block types (extended for tools)
200
+ */
201
+ type AnthropicToolUseBlock = {
202
+ type: "tool_use";
203
+ id: string;
204
+ name: string;
205
+ input: Record<string, unknown>;
206
+ };
207
+ type AnthropicToolResultBlock = {
208
+ type: "tool_result";
209
+ tool_use_id: string;
210
+ content: string;
211
+ };
212
+ type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
213
+ /**
214
+ * Format messages for Anthropic with full tool support
215
+ * Handles: text, images, tool_use, and tool_result
216
+ *
217
+ * Key differences from OpenAI:
218
+ * - tool_calls become tool_use blocks in assistant content
219
+ * - tool results become tool_result blocks in user content
220
+ */
221
+ declare function formatMessagesForAnthropic(messages: Message[], systemPrompt?: string): {
222
+ system: string;
223
+ messages: Array<{
224
+ role: "user" | "assistant";
225
+ content: AnthropicMessageContent;
226
+ }>;
227
+ };
228
+ /**
229
+ * OpenAI message format with tool support
230
+ */
231
+ type OpenAIMessage = {
232
+ role: "system";
233
+ content: string;
234
+ } | {
235
+ role: "user";
236
+ content: string | OpenAIContentBlock[];
237
+ } | {
238
+ role: "assistant";
239
+ content: string | null;
240
+ tool_calls?: Array<{
241
+ id: string;
242
+ type: "function";
243
+ function: {
244
+ name: string;
245
+ arguments: string;
246
+ };
247
+ }>;
248
+ } | {
249
+ role: "tool";
250
+ content: string;
251
+ tool_call_id: string;
252
+ };
253
+ /**
254
+ * Format messages for OpenAI with full tool support
255
+ * Handles: text, images, tool_calls, and tool results
256
+ */
257
+ declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
258
+
259
+ 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,259 @@
1
+ import { M as Message, A as ActionDefinition, d as ToolDefinition, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, X as LLMConfig, a6 as MessageAttachment } from './types-BkQCSiIt.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
+ }
12
+ /**
13
+ * Chat completion request
14
+ */
15
+ interface ChatCompletionRequest {
16
+ /** Conversation messages */
17
+ messages: Message[];
18
+ /**
19
+ * Raw provider-formatted messages (for agent loop with tool calls)
20
+ * When provided, these are used instead of converting from Message[]
21
+ * This allows passing messages with tool_calls and tool role
22
+ */
23
+ rawMessages?: Array<Record<string, unknown>>;
24
+ /** Available actions/tools */
25
+ actions?: ActionDefinition[];
26
+ /** Full tool definitions for provider-native tool search / deferred loading paths. */
27
+ toolDefinitions?: ToolDefinition[];
28
+ /** System prompt */
29
+ systemPrompt?: string;
30
+ /** LLM configuration overrides */
31
+ config?: RequestLLMConfig;
32
+ /** Abort signal for cancellation */
33
+ signal?: AbortSignal;
34
+ /**
35
+ * Enable native web search for the provider.
36
+ * When true or configured, the provider's native search is enabled.
37
+ */
38
+ webSearch?: boolean | WebSearchConfig;
39
+ /** Optional provider-specific tool policy hints derived from runtime selection. */
40
+ providerToolOptions?: ProviderToolRuntimeOptions;
41
+ /** Enable adapter-level provider payload logging. */
42
+ debug?: boolean;
43
+ }
44
+ /**
45
+ * Non-streaming completion result
46
+ */
47
+ interface CompletionResult {
48
+ /** Text content */
49
+ content: string;
50
+ /** Tool calls */
51
+ toolCalls: Array<{
52
+ id: string;
53
+ name: string;
54
+ args: Record<string, unknown>;
55
+ /** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
56
+ extra_content?: Record<string, unknown>;
57
+ }>;
58
+ /** Thinking content (if extended thinking enabled) */
59
+ thinking?: string;
60
+ /** Token usage for billing/tracking */
61
+ usage?: TokenUsage;
62
+ /** Raw provider response for debugging */
63
+ rawResponse: Record<string, unknown>;
64
+ }
65
+ /**
66
+ * Base LLM adapter interface
67
+ */
68
+ interface LLMAdapter {
69
+ /** Provider name */
70
+ readonly provider: string;
71
+ /** Model name */
72
+ readonly model: string;
73
+ /**
74
+ * Stream a chat completion
75
+ */
76
+ stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
77
+ /**
78
+ * Non-streaming chat completion (for debugging/comparison)
79
+ */
80
+ complete?(request: ChatCompletionRequest): Promise<CompletionResult>;
81
+ }
82
+ /**
83
+ * Adapter factory function type
84
+ */
85
+ type AdapterFactory = (config: LLMConfig) => LLMAdapter;
86
+ /**
87
+ * Convert messages to provider format (simple text only)
88
+ */
89
+ declare function formatMessages(messages: Message[], systemPrompt?: string): Array<{
90
+ role: string;
91
+ content: string;
92
+ }>;
93
+ /**
94
+ * Convert actions to OpenAI tool format
95
+ */
96
+ declare function formatTools(actions: ActionDefinition[]): Array<{
97
+ type: "function";
98
+ function: {
99
+ name: string;
100
+ description: string;
101
+ parameters: object;
102
+ };
103
+ }>;
104
+ /**
105
+ * Content block types for multimodal messages
106
+ */
107
+ type AnthropicContentBlock = {
108
+ type: "text";
109
+ text: string;
110
+ } | {
111
+ type: "image";
112
+ source: {
113
+ type: "base64";
114
+ media_type: string;
115
+ data: string;
116
+ } | {
117
+ type: "url";
118
+ url: string;
119
+ };
120
+ } | {
121
+ type: "document";
122
+ source: {
123
+ type: "base64";
124
+ media_type: string;
125
+ data: string;
126
+ } | {
127
+ type: "url";
128
+ url: string;
129
+ };
130
+ };
131
+ type OpenAIContentBlock = {
132
+ type: "text";
133
+ text: string;
134
+ } | {
135
+ type: "image_url";
136
+ image_url: {
137
+ url: string;
138
+ detail?: "low" | "high" | "auto";
139
+ };
140
+ };
141
+ /**
142
+ * Check if a message has image attachments
143
+ * Supports both new format (metadata.attachments) and legacy (attachments)
144
+ */
145
+ declare function hasImageAttachments(message: Message): boolean;
146
+ /**
147
+ * Check if a message has media attachments (images or PDFs)
148
+ */
149
+ declare function hasMediaAttachments(message: Message): boolean;
150
+ /**
151
+ * Convert MessageAttachment to Anthropic image content block
152
+ *
153
+ * Anthropic format:
154
+ * {
155
+ * type: "image",
156
+ * source: {
157
+ * type: "base64",
158
+ * media_type: "image/png",
159
+ * data: "base64data..."
160
+ * }
161
+ * }
162
+ */
163
+ declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
164
+ /**
165
+ * Convert MessageAttachment to OpenAI image_url content block
166
+ *
167
+ * OpenAI format:
168
+ * {
169
+ * type: "image_url",
170
+ * image_url: {
171
+ * url: "data:image/png;base64,..."
172
+ * }
173
+ * }
174
+ */
175
+ declare function attachmentToOpenAIImage(attachment: MessageAttachment): OpenAIContentBlock | null;
176
+ /**
177
+ * Convert MessageAttachment (PDF) to Anthropic document content block
178
+ *
179
+ * Anthropic format:
180
+ * {
181
+ * type: "document",
182
+ * source: {
183
+ * type: "base64",
184
+ * media_type: "application/pdf",
185
+ * data: "base64data..."
186
+ * }
187
+ * }
188
+ */
189
+ declare function attachmentToAnthropicDocument(attachment: MessageAttachment): AnthropicContentBlock | null;
190
+ /**
191
+ * Convert a Message to Anthropic multimodal content blocks
192
+ */
193
+ declare function messageToAnthropicContent(message: Message): string | AnthropicContentBlock[];
194
+ /**
195
+ * Convert a Message to OpenAI multimodal content blocks
196
+ */
197
+ declare function messageToOpenAIContent(message: Message): string | OpenAIContentBlock[];
198
+ /**
199
+ * Anthropic content block types (extended for tools)
200
+ */
201
+ type AnthropicToolUseBlock = {
202
+ type: "tool_use";
203
+ id: string;
204
+ name: string;
205
+ input: Record<string, unknown>;
206
+ };
207
+ type AnthropicToolResultBlock = {
208
+ type: "tool_result";
209
+ tool_use_id: string;
210
+ content: string;
211
+ };
212
+ type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
213
+ /**
214
+ * Format messages for Anthropic with full tool support
215
+ * Handles: text, images, tool_use, and tool_result
216
+ *
217
+ * Key differences from OpenAI:
218
+ * - tool_calls become tool_use blocks in assistant content
219
+ * - tool results become tool_result blocks in user content
220
+ */
221
+ declare function formatMessagesForAnthropic(messages: Message[], systemPrompt?: string): {
222
+ system: string;
223
+ messages: Array<{
224
+ role: "user" | "assistant";
225
+ content: AnthropicMessageContent;
226
+ }>;
227
+ };
228
+ /**
229
+ * OpenAI message format with tool support
230
+ */
231
+ type OpenAIMessage = {
232
+ role: "system";
233
+ content: string;
234
+ } | {
235
+ role: "user";
236
+ content: string | OpenAIContentBlock[];
237
+ } | {
238
+ role: "assistant";
239
+ content: string | null;
240
+ tool_calls?: Array<{
241
+ id: string;
242
+ type: "function";
243
+ function: {
244
+ name: string;
245
+ arguments: string;
246
+ };
247
+ }>;
248
+ } | {
249
+ role: "tool";
250
+ content: string;
251
+ tool_call_id: string;
252
+ };
253
+ /**
254
+ * Format messages for OpenAI with full tool support
255
+ * Handles: text, images, tool_calls, and tool results
256
+ */
257
+ declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
258
+
259
+ 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-D-U61JaB.mjs';
2
- import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-D4YfrQJR.mjs';
3
- export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-D4YfrQJR.mjs';
4
- import '../types-CR8mi9I0.mjs';
1
+ import { L as LLMAdapter } from '../base-tNgbBaSo.mjs';
2
+ import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-B6dhnguR.mjs';
3
+ export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-B6dhnguR.mjs';
4
+ import '../types-BkQCSiIt.mjs';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter } from '../base-iGi9Va6Z.js';
2
- import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-38yolWJn.js';
3
- export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-38yolWJn.js';
4
- import '../types-CR8mi9I0.js';
1
+ import { L as LLMAdapter } from '../base-C58Dsr9p.js';
2
+ import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-CCxPmkmK.js';
3
+ export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-CCxPmkmK.js';
4
+ import '../types-BkQCSiIt.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 StorageAdapter, e as StorageMessage } from './types-CR8mi9I0.mjs';
2
- export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-CR8mi9I0.mjs';
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, D as DoneEventMessage, g as StreamEvent, h as ToolCallInfo, i as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, j as ToolResponse, k as StorageMessage } from './types-BkQCSiIt.mjs';
2
+ export { a4 as AnthropicProviderToolOptions, a1 as AnthropicToolSelectionHints, p as AssistantMessage, a5 as Citation, C as CoreMessage, V as DEFAULT_CAPABILITIES, m as DoGenerateParams, n as DoGenerateResult, H as ErrorChunk, F as FilePart, E as FinishChunk, N as FinishReason, v as GenerateStep, I as ImagePart, X as LLMConfig, L as LanguageModel, l as ModelCapabilities, a3 as OpenAIProviderToolOptions, a0 as OpenAIToolSelectionHints, O as ResponseOptions, Q as StorageFile, x as StreamChunk, w as StreamPart, o as SystemMessage, y as TextDeltaChunk, s as TextPart, J as TokenUsage, t as ToolCall, z as ToolCallChunk, $ as ToolExecution, Y as ToolLocation, q as ToolMessage, a2 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, Z as UnifiedToolCall, _ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BkQCSiIt.mjs';
3
3
  import { z } from 'zod';
4
- import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-D-U61JaB.mjs';
5
- export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-D-U61JaB.mjs';
6
- import { A as AIProvider } from './types-DRqxMIjF.mjs';
7
- 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-DRqxMIjF.mjs';
4
+ import { A as AIProvider } from './types-BSSiJW2o.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-BSSiJW2o.mjs';
6
+ import { L as LLMAdapter } from './base-tNgbBaSo.mjs';
7
+ export { A as AdapterFactory, C as ChatCompletionRequest } from './base-tNgbBaSo.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-D4YfrQJR.mjs';
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-B6dhnguR.mjs';
11
11
 
12
12
  /**
13
13
  * generateText - Generate text using a language model
@@ -388,6 +388,7 @@ interface ChatRequest {
388
388
  config?: {
389
389
  temperature?: number;
390
390
  maxTokens?: number;
391
+ responseFormat?: ResponseFormat;
391
392
  };
392
393
  /** System prompt override */
393
394
  systemPrompt?: string;
package/dist/index.d.ts 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 StorageAdapter, e as StorageMessage } from './types-CR8mi9I0.js';
2
- export { A as AssistantMessage, C as CoreMessage, w as DEFAULT_CAPABILITIES, D as DoGenerateParams, f as DoGenerateResult, E as ErrorChunk, F as FilePart, s as FinishChunk, u as FinishReason, m as GenerateStep, I as ImagePart, L as LanguageModel, M as ModelCapabilities, R as ResponseOptions, v as StorageFile, o as StreamChunk, n as StreamPart, g as SystemMessage, p as TextDeltaChunk, j as TextPart, t as TokenUsage, k as ToolCall, q as ToolCallChunk, h as ToolMessage, l as ToolResult, r as ToolResultChunk, i as UserContentPart, U as UserMessage } from './types-CR8mi9I0.js';
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, D as DoneEventMessage, g as StreamEvent, h as ToolCallInfo, i as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, j as ToolResponse, k as StorageMessage } from './types-BkQCSiIt.js';
2
+ export { a4 as AnthropicProviderToolOptions, a1 as AnthropicToolSelectionHints, p as AssistantMessage, a5 as Citation, C as CoreMessage, V as DEFAULT_CAPABILITIES, m as DoGenerateParams, n as DoGenerateResult, H as ErrorChunk, F as FilePart, E as FinishChunk, N as FinishReason, v as GenerateStep, I as ImagePart, X as LLMConfig, L as LanguageModel, l as ModelCapabilities, a3 as OpenAIProviderToolOptions, a0 as OpenAIToolSelectionHints, O as ResponseOptions, Q as StorageFile, x as StreamChunk, w as StreamPart, o as SystemMessage, y as TextDeltaChunk, s as TextPart, J as TokenUsage, t as ToolCall, z as ToolCallChunk, $ as ToolExecution, Y as ToolLocation, q as ToolMessage, a2 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, Z as UnifiedToolCall, _ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BkQCSiIt.js';
3
3
  import { z } from 'zod';
4
- import { A as ActionDefinition, T as ToolDefinition, a as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, L as LLMAdapter, D as DoneEventMessage, S as StreamEvent, b as ToolCallInfo, c as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, d as ToolResponse } from './base-iGi9Va6Z.js';
5
- export { e as AdapterFactory, m as AnthropicProviderToolOptions, j as AnthropicToolSelectionHints, C as ChatCompletionRequest, n as Citation, f as LLMConfig, l as OpenAIProviderToolOptions, O as OpenAIToolSelectionHints, i as ToolExecution, g as ToolLocation, k as ToolNativeProviderHints, U as UnifiedToolCall, h as UnifiedToolResult } from './base-iGi9Va6Z.js';
6
- import { A as AIProvider } from './types-BctsnC3g.js';
7
- 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-BctsnC3g.js';
4
+ import { A as AIProvider } from './types-BQ31QIsA.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-BQ31QIsA.js';
6
+ import { L as LLMAdapter } from './base-C58Dsr9p.js';
7
+ export { A as AdapterFactory, C as ChatCompletionRequest } from './base-C58Dsr9p.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-38yolWJn.js';
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-CCxPmkmK.js';
11
11
 
12
12
  /**
13
13
  * generateText - Generate text using a language model
@@ -388,6 +388,7 @@ interface ChatRequest {
388
388
  config?: {
389
389
  temperature?: number;
390
390
  maxTokens?: number;
391
+ responseFormat?: ResponseFormat;
391
392
  };
392
393
  /** System prompt override */
393
394
  systemPrompt?: string;
package/dist/index.js CHANGED
@@ -135,6 +135,11 @@ function formatToolsForGoogle(tools) {
135
135
  // src/core/generate-text.ts
136
136
  async function generateText(params) {
137
137
  const { model, tools, maxSteps = 1, signal } = params;
138
+ if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
139
+ console.warn(
140
+ `[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
141
+ );
142
+ }
138
143
  let messages = buildMessages(params);
139
144
  const steps = [];
140
145
  const allToolCalls = [];
@@ -149,6 +154,7 @@ async function generateText(params) {
149
154
  tools: formattedTools,
150
155
  temperature: params.temperature,
151
156
  maxTokens: params.maxTokens,
157
+ responseFormat: params.responseFormat,
152
158
  signal
153
159
  });
154
160
  const stepToolResults = [];
@@ -266,6 +272,11 @@ function sumUsage(steps) {
266
272
  // src/core/stream-text.ts
267
273
  async function streamText(params) {
268
274
  const { model, tools, maxSteps = 1, signal } = params;
275
+ if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
276
+ console.warn(
277
+ `[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
278
+ );
279
+ }
269
280
  let fullText = "";
270
281
  let finalUsage = {
271
282
  promptTokens: 0,
@@ -291,6 +302,7 @@ async function streamText(params) {
291
302
  tools: formattedTools,
292
303
  temperature: params.temperature,
293
304
  maxTokens: params.maxTokens,
305
+ responseFormat: params.responseFormat,
294
306
  signal
295
307
  })) {
296
308
  switch (chunk.type) {