@yourgpt/llm-sdk 2.6.0-beta.1 → 2.6.0-beta.3

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 (61) hide show
  1. package/README.md +146 -0
  2. package/dist/adapters/index.d.mts +5 -5
  3. package/dist/adapters/index.d.ts +5 -5
  4. package/dist/adapters/index.js +437 -39
  5. package/dist/adapters/index.mjs +437 -39
  6. package/dist/audio-BBSwnjo8.d.mts +92 -0
  7. package/dist/audio-BBSwnjo8.d.ts +92 -0
  8. package/dist/{base-CkeT7u-O.d.mts → base-BICaQaRS.d.mts} +7 -3
  9. package/dist/{base-BdTpUAWI.d.ts → base-CpRPB8u8.d.ts} +7 -3
  10. package/dist/fallback/index.d.mts +4 -4
  11. package/dist/fallback/index.d.ts +4 -4
  12. package/dist/index.d.mts +20 -36
  13. package/dist/index.d.ts +20 -36
  14. package/dist/index.js +327 -69
  15. package/dist/index.mjs +325 -70
  16. package/dist/providers/anthropic/index.d.mts +3 -3
  17. package/dist/providers/anthropic/index.d.ts +3 -3
  18. package/dist/providers/anthropic/index.js +116 -7
  19. package/dist/providers/anthropic/index.mjs +116 -7
  20. package/dist/providers/azure/index.d.mts +3 -3
  21. package/dist/providers/azure/index.d.ts +3 -3
  22. package/dist/providers/azure/index.js +101 -4
  23. package/dist/providers/azure/index.mjs +101 -4
  24. package/dist/providers/fireworks/index.d.mts +3 -3
  25. package/dist/providers/fireworks/index.d.ts +3 -3
  26. package/dist/providers/fireworks/index.js +393 -31
  27. package/dist/providers/fireworks/index.mjs +393 -31
  28. package/dist/providers/google/index.d.mts +3 -3
  29. package/dist/providers/google/index.d.ts +3 -3
  30. package/dist/providers/google/index.js +393 -31
  31. package/dist/providers/google/index.mjs +393 -31
  32. package/dist/providers/ollama/index.d.mts +4 -4
  33. package/dist/providers/ollama/index.d.ts +4 -4
  34. package/dist/providers/ollama/index.js +87 -2
  35. package/dist/providers/ollama/index.mjs +87 -2
  36. package/dist/providers/openai/index.d.mts +25 -6
  37. package/dist/providers/openai/index.d.ts +25 -6
  38. package/dist/providers/openai/index.js +822 -40
  39. package/dist/providers/openai/index.mjs +821 -41
  40. package/dist/providers/openrouter/index.d.mts +3 -3
  41. package/dist/providers/openrouter/index.d.ts +3 -3
  42. package/dist/providers/openrouter/index.js +393 -31
  43. package/dist/providers/openrouter/index.mjs +393 -31
  44. package/dist/providers/togetherai/index.d.mts +3 -3
  45. package/dist/providers/togetherai/index.d.ts +3 -3
  46. package/dist/providers/togetherai/index.js +393 -31
  47. package/dist/providers/togetherai/index.mjs +393 -31
  48. package/dist/providers/xai/index.d.mts +3 -3
  49. package/dist/providers/xai/index.d.ts +3 -3
  50. package/dist/providers/xai/index.js +393 -31
  51. package/dist/providers/xai/index.mjs +393 -31
  52. package/dist/{types-BWRYIvl_.d.mts → types-C3RgRbEC.d.mts} +1 -1
  53. package/dist/{types-CpXcT-tY.d.ts → types-DCFqkJAy.d.ts} +1 -1
  54. package/dist/{types-NOswlhm9.d.mts → types-DHQEMFHA.d.mts} +3 -3
  55. package/dist/{types-BW3csYo5.d.mts → types-Dg1Bcg1k.d.mts} +106 -3
  56. package/dist/{types-BW3csYo5.d.ts → types-Dg1Bcg1k.d.ts} +106 -3
  57. package/dist/{types-DA54bSmX.d.ts → types-Dikj3En4.d.ts} +3 -3
  58. package/dist/yourgpt/index.d.mts +1 -1
  59. package/dist/yourgpt/index.d.ts +1 -1
  60. package/docs/multimodal-and-audio.md +170 -0
  61. package/package.json +3 -2
@@ -0,0 +1,92 @@
1
+ /** Audio models are independent of chat models and chat streaming events. */
2
+ type SpeechFormat = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
3
+ interface AudioResponseMetadata {
4
+ provider: string;
5
+ modelId: string;
6
+ requestId?: string;
7
+ status?: number;
8
+ }
9
+ interface AudioWarning {
10
+ code: string;
11
+ message: string;
12
+ }
13
+ interface SpeechOptions {
14
+ text: string;
15
+ voice?: string;
16
+ outputFormat?: SpeechFormat;
17
+ speed?: number;
18
+ instructions?: string;
19
+ signal?: AbortSignal;
20
+ providerOptions?: Record<string, Record<string, unknown>>;
21
+ }
22
+ interface GeneratedSpeech {
23
+ audio: {
24
+ uint8Array: Uint8Array;
25
+ readonly base64: string;
26
+ mediaType: string;
27
+ format: SpeechFormat;
28
+ };
29
+ response: AudioResponseMetadata;
30
+ warnings: AudioWarning[];
31
+ usage?: Record<string, unknown>;
32
+ }
33
+ interface SpeechModel {
34
+ readonly provider: string;
35
+ readonly modelId: string;
36
+ doGenerate(options: SpeechOptions): Promise<GeneratedSpeech>;
37
+ }
38
+ interface TranscriptionOptions {
39
+ /** Recorded file bytes, base64, or a Blob. URLs and raw PCM are not fetched/decoded. */
40
+ audio: Uint8Array | ArrayBuffer | Blob | string;
41
+ mediaType?: string;
42
+ filename?: string;
43
+ language?: string;
44
+ prompt?: string;
45
+ signal?: AbortSignal;
46
+ providerOptions?: Record<string, Record<string, unknown>>;
47
+ }
48
+ interface TranscriptSegment {
49
+ text: string;
50
+ start: number;
51
+ end: number;
52
+ speaker?: string;
53
+ }
54
+ interface TranscriptionResult {
55
+ text: string;
56
+ language?: string;
57
+ durationSeconds?: number;
58
+ segments?: TranscriptSegment[];
59
+ words?: Array<{
60
+ word: string;
61
+ start: number;
62
+ end: number;
63
+ }>;
64
+ response: AudioResponseMetadata;
65
+ warnings: AudioWarning[];
66
+ usage?: Record<string, unknown>;
67
+ /** Provider-supplied extras, including log probabilities when requested. */
68
+ providerMetadata?: Record<string, unknown>;
69
+ }
70
+ interface TranscriptionModel {
71
+ readonly provider: string;
72
+ readonly modelId: string;
73
+ doTranscribe(options: TranscriptionOptions): Promise<TranscriptionResult>;
74
+ }
75
+ declare const audioErrorMarker: unique symbol;
76
+ declare class AudioAPIError extends Error {
77
+ readonly code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error";
78
+ readonly status?: number | undefined;
79
+ readonly requestId?: string | undefined;
80
+ readonly [audioErrorMarker] = true;
81
+ static [Symbol.hasInstance](value: unknown): boolean;
82
+ readonly name = "AudioAPIError";
83
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error", status?: number | undefined, requestId?: string | undefined);
84
+ }
85
+ declare function generateSpeech({ model, ...options }: SpeechOptions & {
86
+ model: SpeechModel;
87
+ }): Promise<GeneratedSpeech>;
88
+ declare function transcribe({ model, ...options }: TranscriptionOptions & {
89
+ model: TranscriptionModel;
90
+ }): Promise<TranscriptionResult>;
91
+
92
+ export { AudioAPIError as A, type GeneratedSpeech as G, type SpeechModel as S, type TranscriptionModel as T, type SpeechOptions as a, type TranscriptionOptions as b, type TranscriptionResult as c, type SpeechFormat as d, type TranscriptSegment as e, type AudioResponseMetadata as f, generateSpeech as g, type AudioWarning as h, transcribe as t };
@@ -0,0 +1,92 @@
1
+ /** Audio models are independent of chat models and chat streaming events. */
2
+ type SpeechFormat = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
3
+ interface AudioResponseMetadata {
4
+ provider: string;
5
+ modelId: string;
6
+ requestId?: string;
7
+ status?: number;
8
+ }
9
+ interface AudioWarning {
10
+ code: string;
11
+ message: string;
12
+ }
13
+ interface SpeechOptions {
14
+ text: string;
15
+ voice?: string;
16
+ outputFormat?: SpeechFormat;
17
+ speed?: number;
18
+ instructions?: string;
19
+ signal?: AbortSignal;
20
+ providerOptions?: Record<string, Record<string, unknown>>;
21
+ }
22
+ interface GeneratedSpeech {
23
+ audio: {
24
+ uint8Array: Uint8Array;
25
+ readonly base64: string;
26
+ mediaType: string;
27
+ format: SpeechFormat;
28
+ };
29
+ response: AudioResponseMetadata;
30
+ warnings: AudioWarning[];
31
+ usage?: Record<string, unknown>;
32
+ }
33
+ interface SpeechModel {
34
+ readonly provider: string;
35
+ readonly modelId: string;
36
+ doGenerate(options: SpeechOptions): Promise<GeneratedSpeech>;
37
+ }
38
+ interface TranscriptionOptions {
39
+ /** Recorded file bytes, base64, or a Blob. URLs and raw PCM are not fetched/decoded. */
40
+ audio: Uint8Array | ArrayBuffer | Blob | string;
41
+ mediaType?: string;
42
+ filename?: string;
43
+ language?: string;
44
+ prompt?: string;
45
+ signal?: AbortSignal;
46
+ providerOptions?: Record<string, Record<string, unknown>>;
47
+ }
48
+ interface TranscriptSegment {
49
+ text: string;
50
+ start: number;
51
+ end: number;
52
+ speaker?: string;
53
+ }
54
+ interface TranscriptionResult {
55
+ text: string;
56
+ language?: string;
57
+ durationSeconds?: number;
58
+ segments?: TranscriptSegment[];
59
+ words?: Array<{
60
+ word: string;
61
+ start: number;
62
+ end: number;
63
+ }>;
64
+ response: AudioResponseMetadata;
65
+ warnings: AudioWarning[];
66
+ usage?: Record<string, unknown>;
67
+ /** Provider-supplied extras, including log probabilities when requested. */
68
+ providerMetadata?: Record<string, unknown>;
69
+ }
70
+ interface TranscriptionModel {
71
+ readonly provider: string;
72
+ readonly modelId: string;
73
+ doTranscribe(options: TranscriptionOptions): Promise<TranscriptionResult>;
74
+ }
75
+ declare const audioErrorMarker: unique symbol;
76
+ declare class AudioAPIError extends Error {
77
+ readonly code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error";
78
+ readonly status?: number | undefined;
79
+ readonly requestId?: string | undefined;
80
+ readonly [audioErrorMarker] = true;
81
+ static [Symbol.hasInstance](value: unknown): boolean;
82
+ readonly name = "AudioAPIError";
83
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error", status?: number | undefined, requestId?: string | undefined);
84
+ }
85
+ declare function generateSpeech({ model, ...options }: SpeechOptions & {
86
+ model: SpeechModel;
87
+ }): Promise<GeneratedSpeech>;
88
+ declare function transcribe({ model, ...options }: TranscriptionOptions & {
89
+ model: TranscriptionModel;
90
+ }): Promise<TranscriptionResult>;
91
+
92
+ export { AudioAPIError as A, type GeneratedSpeech as G, type SpeechModel as S, type TranscriptionModel as T, type SpeechOptions as a, type TranscriptionOptions as b, type TranscriptionResult as c, type SpeechFormat as d, type TranscriptSegment as e, type AudioResponseMetadata as f, generateSpeech as g, type AudioWarning as h, transcribe as t };
@@ -1,9 +1,10 @@
1
- import { M as Message, A as ActionDefinition, d as ToolDefinition, O as OpenAIReasoningEffort, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, Y as LLMConfig, a8 as MessageAttachment } from './types-BW3csYo5.mjs';
1
+ import { M as Message, A as ActionDefinition, e as ToolDefinition, O as OpenAITransportOptions, h as OpenAIReasoningEffort, R as ResponseFormat, W as WebSearchConfig, l as ProviderToolRuntimeOptions, i as StreamEvent, P as ProviderMetadata, V as TokenUsage, $ as LLMConfig, c as ToolModelOutput, af as MessageAttachment } from './types-Dg1Bcg1k.mjs';
2
2
 
3
3
  /**
4
4
  * Request-level LLM configuration overrides
5
5
  */
6
6
  interface RequestLLMConfig {
7
+ openai?: OpenAITransportOptions;
7
8
  model?: string;
8
9
  reasoningEffort?: OpenAIReasoningEffort;
9
10
  temperature?: number;
@@ -46,6 +47,7 @@ interface ChatCompletionRequest {
46
47
  * Non-streaming completion result
47
48
  */
48
49
  interface CompletionResult {
50
+ providerMetadata?: ProviderMetadata;
49
51
  /** Text content */
50
52
  content: string;
51
53
  /** Tool calls */
@@ -208,7 +210,7 @@ type AnthropicToolUseBlock = {
208
210
  type AnthropicToolResultBlock = {
209
211
  type: "tool_result";
210
212
  tool_use_id: string;
211
- content: string;
213
+ content: string | Array<Record<string, unknown>>;
212
214
  };
213
215
  type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
214
216
  /**
@@ -237,6 +239,7 @@ type OpenAIMessage = {
237
239
  content: string | OpenAIContentBlock[];
238
240
  } | {
239
241
  role: "assistant";
242
+ providerMetadata?: ProviderMetadata;
240
243
  content: string | null;
241
244
  tool_calls?: Array<{
242
245
  id: string;
@@ -250,11 +253,12 @@ type OpenAIMessage = {
250
253
  role: "tool";
251
254
  content: string;
252
255
  tool_call_id: string;
256
+ modelOutput?: ToolModelOutput;
253
257
  };
254
258
  /**
255
259
  * Format messages for OpenAI with full tool support
256
260
  * Handles: text, images, tool_calls, and tool results
257
261
  */
258
- declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
262
+ declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string, preserveProviderMetadata?: boolean): OpenAIMessage[];
259
263
 
260
264
  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,9 +1,10 @@
1
- import { M as Message, A as ActionDefinition, d as ToolDefinition, O as OpenAIReasoningEffort, R as ResponseFormat, W as WebSearchConfig, P as ProviderToolRuntimeOptions, g as StreamEvent, J as TokenUsage, Y as LLMConfig, a8 as MessageAttachment } from './types-BW3csYo5.js';
1
+ import { M as Message, A as ActionDefinition, e as ToolDefinition, O as OpenAITransportOptions, h as OpenAIReasoningEffort, R as ResponseFormat, W as WebSearchConfig, l as ProviderToolRuntimeOptions, i as StreamEvent, P as ProviderMetadata, V as TokenUsage, $ as LLMConfig, c as ToolModelOutput, af as MessageAttachment } from './types-Dg1Bcg1k.js';
2
2
 
3
3
  /**
4
4
  * Request-level LLM configuration overrides
5
5
  */
6
6
  interface RequestLLMConfig {
7
+ openai?: OpenAITransportOptions;
7
8
  model?: string;
8
9
  reasoningEffort?: OpenAIReasoningEffort;
9
10
  temperature?: number;
@@ -46,6 +47,7 @@ interface ChatCompletionRequest {
46
47
  * Non-streaming completion result
47
48
  */
48
49
  interface CompletionResult {
50
+ providerMetadata?: ProviderMetadata;
49
51
  /** Text content */
50
52
  content: string;
51
53
  /** Tool calls */
@@ -208,7 +210,7 @@ type AnthropicToolUseBlock = {
208
210
  type AnthropicToolResultBlock = {
209
211
  type: "tool_result";
210
212
  tool_use_id: string;
211
- content: string;
213
+ content: string | Array<Record<string, unknown>>;
212
214
  };
213
215
  type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
214
216
  /**
@@ -237,6 +239,7 @@ type OpenAIMessage = {
237
239
  content: string | OpenAIContentBlock[];
238
240
  } | {
239
241
  role: "assistant";
242
+ providerMetadata?: ProviderMetadata;
240
243
  content: string | null;
241
244
  tool_calls?: Array<{
242
245
  id: string;
@@ -250,11 +253,12 @@ type OpenAIMessage = {
250
253
  role: "tool";
251
254
  content: string;
252
255
  tool_call_id: string;
256
+ modelOutput?: ToolModelOutput;
253
257
  };
254
258
  /**
255
259
  * Format messages for OpenAI with full tool support
256
260
  * Handles: text, images, tool_calls, and tool results
257
261
  */
258
- declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
262
+ declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string, preserveProviderMetadata?: boolean): OpenAIMessage[];
259
263
 
260
264
  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-CkeT7u-O.mjs';
2
- import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-BWRYIvl_.mjs';
3
- export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-BWRYIvl_.mjs';
4
- import '../types-BW3csYo5.mjs';
1
+ import { L as LLMAdapter } from '../base-BICaQaRS.mjs';
2
+ import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-C3RgRbEC.mjs';
3
+ export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-C3RgRbEC.mjs';
4
+ import '../types-Dg1Bcg1k.mjs';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter } from '../base-BdTpUAWI.js';
2
- import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-CpXcT-tY.js';
3
- export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-CpXcT-tY.js';
4
- import '../types-BW3csYo5.js';
1
+ import { L as LLMAdapter } from '../base-CpRPB8u8.js';
2
+ import { F as FallbackChainConfig, c as FallbackFailure, R as RoutingStore } from '../types-DCFqkJAy.js';
3
+ export { d as FallbackInfo, b as RetryBackoff, e as RetryInfo, a as RoutingStrategy } from '../types-DCFqkJAy.js';
4
+ import '../types-Dg1Bcg1k.js';
5
5
  import 'zod';
6
6
 
7
7
  /**
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, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, O as OpenAIReasoningEffort, 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-BW3csYo5.mjs';
2
- export { a5 as AnthropicProviderToolOptions, a2 as AnthropicToolSelectionHints, p as AssistantMessage, a6 as Citation, C as CoreMessage, X 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, Y as LLMConfig, L as LanguageModel, l as ModelCapabilities, a4 as OpenAIProviderToolOptions, a1 as OpenAIToolSelectionHints, Q as ResponseOptions, V 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, a0 as ToolExecution, Z as ToolLocation, q as ToolMessage, a3 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, _ as UnifiedToolCall, $ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BW3csYo5.mjs';
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-NOswlhm9.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-NOswlhm9.mjs';
6
- import { L as LLMAdapter } from './base-CkeT7u-O.mjs';
7
- export { A as AdapterFactory, C as ChatCompletionRequest } from './base-CkeT7u-O.mjs';
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-BWRYIvl_.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-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>): Array<{
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>): Array<{
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>): Array<{
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,7 @@ interface ChatRequest {
386
367
  botId?: string;
387
368
  /** LLM config overrides */
388
369
  config?: {
370
+ openai?: OpenAITransportOptions;
389
371
  reasoningEffort?: OpenAIReasoningEffort;
390
372
  temperature?: number;
391
373
  maxTokens?: number;
@@ -1184,7 +1166,9 @@ declare function formatSSEData(event: StreamEvent): string;
1184
1166
  /**
1185
1167
  * Create a ReadableStream from an async generator of events
1186
1168
  */
1187
- declare function createEventStream(generator: AsyncGenerator<StreamEvent>): ReadableStream<Uint8Array>;
1169
+ declare function createEventStream(generator: AsyncGenerator<StreamEvent>, options?: {
1170
+ includeUsage?: boolean;
1171
+ }): ReadableStream<Uint8Array>;
1188
1172
  /**
1189
1173
  * Create SSE Response object
1190
1174
  */
@@ -1538,4 +1522,4 @@ declare function generateThreadId(): string;
1538
1522
  */
1539
1523
  declare function generateToolCallId(): string;
1540
1524
 
1541
- 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 };
1525
+ 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, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, O as OpenAIReasoningEffort, 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-BW3csYo5.js';
2
- export { a5 as AnthropicProviderToolOptions, a2 as AnthropicToolSelectionHints, p as AssistantMessage, a6 as Citation, C as CoreMessage, X 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, Y as LLMConfig, L as LanguageModel, l as ModelCapabilities, a4 as OpenAIProviderToolOptions, a1 as OpenAIToolSelectionHints, Q as ResponseOptions, V 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, a0 as ToolExecution, Z as ToolLocation, q as ToolMessage, a3 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, _ as UnifiedToolCall, $ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BW3csYo5.js';
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-DA54bSmX.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-DA54bSmX.js';
6
- import { L as LLMAdapter } from './base-BdTpUAWI.js';
7
- export { A as AdapterFactory, C as ChatCompletionRequest } from './base-BdTpUAWI.js';
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-CpXcT-tY.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-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>): Array<{
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>): Array<{
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>): Array<{
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,7 @@ interface ChatRequest {
386
367
  botId?: string;
387
368
  /** LLM config overrides */
388
369
  config?: {
370
+ openai?: OpenAITransportOptions;
389
371
  reasoningEffort?: OpenAIReasoningEffort;
390
372
  temperature?: number;
391
373
  maxTokens?: number;
@@ -1184,7 +1166,9 @@ declare function formatSSEData(event: StreamEvent): string;
1184
1166
  /**
1185
1167
  * Create a ReadableStream from an async generator of events
1186
1168
  */
1187
- declare function createEventStream(generator: AsyncGenerator<StreamEvent>): ReadableStream<Uint8Array>;
1169
+ declare function createEventStream(generator: AsyncGenerator<StreamEvent>, options?: {
1170
+ includeUsage?: boolean;
1171
+ }): ReadableStream<Uint8Array>;
1188
1172
  /**
1189
1173
  * Create SSE Response object
1190
1174
  */
@@ -1538,4 +1522,4 @@ declare function generateThreadId(): string;
1538
1522
  */
1539
1523
  declare function generateToolCallId(): string;
1540
1524
 
1541
- 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 };
1525
+ 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 };