@yourgpt/llm-sdk 2.6.0-beta.2 → 2.6.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -17
  3. package/dist/adapters/index.d.mts +11 -13
  4. package/dist/adapters/index.d.ts +11 -13
  5. package/dist/adapters/index.js +406 -114
  6. package/dist/adapters/index.mjs +406 -114
  7. package/dist/audio-K-Z3-Bce.d.mts +191 -0
  8. package/dist/audio-K-Z3-Bce.d.ts +191 -0
  9. package/dist/{base-BICaQaRS.d.mts → base-6LzczuCg.d.ts} +8 -1
  10. package/dist/{base-CpRPB8u8.d.ts → base-DySbTP8C.d.mts} +8 -1
  11. package/dist/decisions-CJzOt87t.d.mts +137 -0
  12. package/dist/decisions-CJzOt87t.d.ts +137 -0
  13. package/dist/fallback/index.d.mts +4 -4
  14. package/dist/fallback/index.d.ts +4 -4
  15. package/dist/http-BQxUT5A9.d.mts +9 -0
  16. package/dist/http-BQxUT5A9.d.ts +9 -0
  17. package/dist/index.d.mts +17 -9
  18. package/dist/index.d.ts +17 -9
  19. package/dist/index.js +698 -205
  20. package/dist/index.mjs +695 -206
  21. package/dist/providers/anthropic/index.d.mts +7 -4
  22. package/dist/providers/anthropic/index.d.ts +7 -4
  23. package/dist/providers/anthropic/index.js +389 -115
  24. package/dist/providers/anthropic/index.mjs +389 -115
  25. package/dist/providers/azure/index.d.mts +3 -3
  26. package/dist/providers/azure/index.d.ts +3 -3
  27. package/dist/providers/cloudflare/index.d.mts +11 -0
  28. package/dist/providers/cloudflare/index.d.ts +11 -0
  29. package/dist/providers/cloudflare/index.js +743 -0
  30. package/dist/providers/cloudflare/index.mjs +741 -0
  31. package/dist/providers/fireworks/index.d.mts +3 -3
  32. package/dist/providers/fireworks/index.d.ts +3 -3
  33. package/dist/providers/fireworks/index.js +181 -60
  34. package/dist/providers/fireworks/index.mjs +181 -60
  35. package/dist/providers/google/index.d.mts +3 -3
  36. package/dist/providers/google/index.d.ts +3 -3
  37. package/dist/providers/google/index.js +181 -60
  38. package/dist/providers/google/index.mjs +181 -60
  39. package/dist/providers/ollama/index.d.mts +4 -4
  40. package/dist/providers/ollama/index.d.ts +4 -4
  41. package/dist/providers/openai/index.d.mts +38 -6
  42. package/dist/providers/openai/index.d.ts +38 -6
  43. package/dist/providers/openai/index.js +1451 -85
  44. package/dist/providers/openai/index.mjs +1449 -86
  45. package/dist/providers/openrouter/index.d.mts +21 -4
  46. package/dist/providers/openrouter/index.d.ts +21 -4
  47. package/dist/providers/openrouter/index.js +1040 -131
  48. package/dist/providers/openrouter/index.mjs +1040 -132
  49. package/dist/providers/togetherai/index.d.mts +3 -3
  50. package/dist/providers/togetherai/index.d.ts +3 -3
  51. package/dist/providers/togetherai/index.js +181 -60
  52. package/dist/providers/togetherai/index.mjs +181 -60
  53. package/dist/providers/typesafe/index.d.mts +8 -0
  54. package/dist/providers/typesafe/index.d.ts +8 -0
  55. package/dist/providers/typesafe/index.js +735 -0
  56. package/dist/providers/typesafe/index.mjs +733 -0
  57. package/dist/providers/xai/index.d.mts +3 -3
  58. package/dist/providers/xai/index.d.ts +3 -3
  59. package/dist/providers/xai/index.js +181 -60
  60. package/dist/providers/xai/index.mjs +181 -60
  61. package/dist/{types-DCFqkJAy.d.ts → types-B0y6VZSQ.d.ts} +1 -1
  62. package/dist/{types-DHQEMFHA.d.mts → types-BXQMtaCX.d.ts} +17 -3
  63. package/dist/{types-C3RgRbEC.d.mts → types-BY6BVhFg.d.mts} +1 -1
  64. package/dist/{types-Dikj3En4.d.ts → types-C7_qVSSd.d.mts} +17 -3
  65. package/dist/{types-Dg1Bcg1k.d.mts → types-D7lzMMLu.d.mts} +13 -1
  66. package/dist/{types-Dg1Bcg1k.d.ts → types-D7lzMMLu.d.ts} +13 -1
  67. package/dist/yourgpt/index.d.mts +1 -1
  68. package/dist/yourgpt/index.d.ts +1 -1
  69. package/docs/decisions.md +174 -0
  70. package/docs/media.md +201 -0
  71. package/docs/multimodal-and-audio.md +9 -2
  72. package/package.json +34 -12
  73. package/dist/audio-BBSwnjo8.d.mts +0 -92
  74. package/dist/audio-BBSwnjo8.d.ts +0 -92
@@ -0,0 +1,191 @@
1
+ interface ImageFile {
2
+ data: Uint8Array | ArrayBuffer | Blob;
3
+ mediaType: "image/png" | "image/jpeg" | "image/webp";
4
+ }
5
+ interface ImageOptions {
6
+ prompt: string;
7
+ n?: number;
8
+ size?: "auto" | `${number}x${number}`;
9
+ /** Supplying images switches to image editing. URLs are never fetched implicitly. */
10
+ images?: ImageFile[];
11
+ mask?: ImageFile;
12
+ signal?: AbortSignal;
13
+ timeoutMs?: number;
14
+ providerOptions?: Record<string, Record<string, unknown>>;
15
+ }
16
+ interface GeneratedImage {
17
+ uint8Array: Uint8Array;
18
+ readonly base64: string;
19
+ mediaType: string;
20
+ revisedPrompt?: string;
21
+ }
22
+ interface ImageResult {
23
+ image: GeneratedImage;
24
+ images: GeneratedImage[];
25
+ usage?: Record<string, unknown>;
26
+ response: {
27
+ provider: string;
28
+ modelId: string;
29
+ requestId?: string;
30
+ status: number;
31
+ };
32
+ providerMetadata?: Record<string, unknown>;
33
+ }
34
+ interface ImageModel {
35
+ readonly provider: string;
36
+ readonly modelId: string;
37
+ doGenerate(options: ImageOptions): Promise<ImageResult>;
38
+ }
39
+ declare function generateImage({ model, ...options }: ImageOptions & {
40
+ model: ImageModel;
41
+ }): Promise<ImageResult>;
42
+ declare const marker: unique symbol;
43
+ /** Errors from image and realtime setup requests. Provider bodies and credentials are not retained. */
44
+ declare class MediaAPIError extends Error {
45
+ readonly code: "invalid_input" | "unsupported_option" | "invalid_response" | "http_error" | "network_error";
46
+ readonly status?: number | undefined;
47
+ readonly requestId?: string | undefined;
48
+ readonly [marker] = true;
49
+ readonly name = "MediaAPIError";
50
+ static [Symbol.hasInstance](value: unknown): boolean;
51
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "invalid_response" | "http_error" | "network_error", status?: number | undefined, requestId?: string | undefined);
52
+ }
53
+
54
+ interface RealtimeToolDefinition {
55
+ name: string;
56
+ description?: string;
57
+ parameters: Record<string, unknown>;
58
+ }
59
+ interface RealtimeSessionOptions {
60
+ instructions?: string;
61
+ voice?: string;
62
+ transcriptionModel?: string;
63
+ language?: string;
64
+ outputModality?: "audio" | "text";
65
+ turnDetection?: {
66
+ type: "server_vad";
67
+ threshold?: number;
68
+ silenceDurationMs?: number;
69
+ prefixPaddingMs?: number;
70
+ } | {
71
+ type: "semantic_vad";
72
+ eagerness?: "auto" | "low" | "medium" | "high";
73
+ } | null;
74
+ tools?: RealtimeToolDefinition[];
75
+ maxOutputTokens?: number | "inf";
76
+ safetyIdentifier?: string;
77
+ signal?: AbortSignal;
78
+ timeoutMs?: number;
79
+ }
80
+ /** Short-lived credential, not a persisted session or a server authorization policy. */
81
+ interface RealtimeClientSecret {
82
+ value: string;
83
+ expiresAt: number;
84
+ modelId: string;
85
+ }
86
+ interface RealtimeModel {
87
+ readonly provider: string;
88
+ readonly modelId: string;
89
+ createClientSecret(options?: RealtimeSessionOptions & {
90
+ expiresAfterSeconds?: number;
91
+ }): Promise<RealtimeClientSecret>;
92
+ /** Exchange a browser SDP offer on your authenticated server. Returns no credentials. */
93
+ createCall(options: RealtimeSessionOptions & {
94
+ sdp: string;
95
+ }): Promise<{
96
+ sdp: string;
97
+ }>;
98
+ }
99
+
100
+ /** Audio models are independent of chat models and chat streaming events. */
101
+ type SpeechFormat = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
102
+ interface AudioResponseMetadata {
103
+ provider: string;
104
+ modelId: string;
105
+ requestId?: string;
106
+ status?: number;
107
+ }
108
+ interface AudioWarning {
109
+ code: string;
110
+ message: string;
111
+ }
112
+ interface SpeechOptions {
113
+ text: string;
114
+ voice?: string;
115
+ outputFormat?: SpeechFormat;
116
+ speed?: number;
117
+ instructions?: string;
118
+ signal?: AbortSignal;
119
+ providerOptions?: Record<string, Record<string, unknown>>;
120
+ }
121
+ interface GeneratedSpeech {
122
+ audio: {
123
+ uint8Array: Uint8Array;
124
+ readonly base64: string;
125
+ mediaType: string;
126
+ format: SpeechFormat;
127
+ };
128
+ response: AudioResponseMetadata;
129
+ warnings: AudioWarning[];
130
+ usage?: Record<string, unknown>;
131
+ }
132
+ interface SpeechModel {
133
+ readonly provider: string;
134
+ readonly modelId: string;
135
+ doGenerate(options: SpeechOptions): Promise<GeneratedSpeech>;
136
+ }
137
+ interface TranscriptionOptions {
138
+ /** Recorded file bytes, base64, or a Blob. URLs and raw PCM are not fetched/decoded. */
139
+ audio: Uint8Array | ArrayBuffer | Blob | string;
140
+ mediaType?: string;
141
+ filename?: string;
142
+ language?: string;
143
+ prompt?: string;
144
+ signal?: AbortSignal;
145
+ providerOptions?: Record<string, Record<string, unknown>>;
146
+ }
147
+ interface TranscriptSegment {
148
+ text: string;
149
+ start: number;
150
+ end: number;
151
+ speaker?: string;
152
+ }
153
+ interface TranscriptionResult {
154
+ text: string;
155
+ language?: string;
156
+ durationSeconds?: number;
157
+ segments?: TranscriptSegment[];
158
+ words?: Array<{
159
+ word: string;
160
+ start: number;
161
+ end: number;
162
+ }>;
163
+ response: AudioResponseMetadata;
164
+ warnings: AudioWarning[];
165
+ usage?: Record<string, unknown>;
166
+ /** Provider-supplied extras, including log probabilities when requested. */
167
+ providerMetadata?: Record<string, unknown>;
168
+ }
169
+ interface TranscriptionModel {
170
+ readonly provider: string;
171
+ readonly modelId: string;
172
+ doTranscribe(options: TranscriptionOptions): Promise<TranscriptionResult>;
173
+ }
174
+ declare const audioErrorMarker: unique symbol;
175
+ declare class AudioAPIError extends Error {
176
+ readonly code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error";
177
+ readonly status?: number | undefined;
178
+ readonly requestId?: string | undefined;
179
+ readonly [audioErrorMarker] = true;
180
+ static [Symbol.hasInstance](value: unknown): boolean;
181
+ readonly name = "AudioAPIError";
182
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error", status?: number | undefined, requestId?: string | undefined);
183
+ }
184
+ declare function generateSpeech({ model, ...options }: SpeechOptions & {
185
+ model: SpeechModel;
186
+ }): Promise<GeneratedSpeech>;
187
+ declare function transcribe({ model, ...options }: TranscriptionOptions & {
188
+ model: TranscriptionModel;
189
+ }): Promise<TranscriptionResult>;
190
+
191
+ export { AudioAPIError as A, type GeneratedImage as G, type ImageFile as I, MediaAPIError as M, type RealtimeToolDefinition as R, type SpeechModel as S, type TranscriptionModel as T, type ImageOptions as a, type ImageResult as b, type ImageModel as c, type RealtimeSessionOptions as d, type RealtimeClientSecret as e, type RealtimeModel as f, generateImage as g, generateSpeech as h, type SpeechOptions as i, type TranscriptionOptions as j, type GeneratedSpeech as k, type TranscriptionResult as l, type SpeechFormat as m, type TranscriptSegment as n, type AudioResponseMetadata as o, type AudioWarning as p, transcribe as t };
@@ -0,0 +1,191 @@
1
+ interface ImageFile {
2
+ data: Uint8Array | ArrayBuffer | Blob;
3
+ mediaType: "image/png" | "image/jpeg" | "image/webp";
4
+ }
5
+ interface ImageOptions {
6
+ prompt: string;
7
+ n?: number;
8
+ size?: "auto" | `${number}x${number}`;
9
+ /** Supplying images switches to image editing. URLs are never fetched implicitly. */
10
+ images?: ImageFile[];
11
+ mask?: ImageFile;
12
+ signal?: AbortSignal;
13
+ timeoutMs?: number;
14
+ providerOptions?: Record<string, Record<string, unknown>>;
15
+ }
16
+ interface GeneratedImage {
17
+ uint8Array: Uint8Array;
18
+ readonly base64: string;
19
+ mediaType: string;
20
+ revisedPrompt?: string;
21
+ }
22
+ interface ImageResult {
23
+ image: GeneratedImage;
24
+ images: GeneratedImage[];
25
+ usage?: Record<string, unknown>;
26
+ response: {
27
+ provider: string;
28
+ modelId: string;
29
+ requestId?: string;
30
+ status: number;
31
+ };
32
+ providerMetadata?: Record<string, unknown>;
33
+ }
34
+ interface ImageModel {
35
+ readonly provider: string;
36
+ readonly modelId: string;
37
+ doGenerate(options: ImageOptions): Promise<ImageResult>;
38
+ }
39
+ declare function generateImage({ model, ...options }: ImageOptions & {
40
+ model: ImageModel;
41
+ }): Promise<ImageResult>;
42
+ declare const marker: unique symbol;
43
+ /** Errors from image and realtime setup requests. Provider bodies and credentials are not retained. */
44
+ declare class MediaAPIError extends Error {
45
+ readonly code: "invalid_input" | "unsupported_option" | "invalid_response" | "http_error" | "network_error";
46
+ readonly status?: number | undefined;
47
+ readonly requestId?: string | undefined;
48
+ readonly [marker] = true;
49
+ readonly name = "MediaAPIError";
50
+ static [Symbol.hasInstance](value: unknown): boolean;
51
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "invalid_response" | "http_error" | "network_error", status?: number | undefined, requestId?: string | undefined);
52
+ }
53
+
54
+ interface RealtimeToolDefinition {
55
+ name: string;
56
+ description?: string;
57
+ parameters: Record<string, unknown>;
58
+ }
59
+ interface RealtimeSessionOptions {
60
+ instructions?: string;
61
+ voice?: string;
62
+ transcriptionModel?: string;
63
+ language?: string;
64
+ outputModality?: "audio" | "text";
65
+ turnDetection?: {
66
+ type: "server_vad";
67
+ threshold?: number;
68
+ silenceDurationMs?: number;
69
+ prefixPaddingMs?: number;
70
+ } | {
71
+ type: "semantic_vad";
72
+ eagerness?: "auto" | "low" | "medium" | "high";
73
+ } | null;
74
+ tools?: RealtimeToolDefinition[];
75
+ maxOutputTokens?: number | "inf";
76
+ safetyIdentifier?: string;
77
+ signal?: AbortSignal;
78
+ timeoutMs?: number;
79
+ }
80
+ /** Short-lived credential, not a persisted session or a server authorization policy. */
81
+ interface RealtimeClientSecret {
82
+ value: string;
83
+ expiresAt: number;
84
+ modelId: string;
85
+ }
86
+ interface RealtimeModel {
87
+ readonly provider: string;
88
+ readonly modelId: string;
89
+ createClientSecret(options?: RealtimeSessionOptions & {
90
+ expiresAfterSeconds?: number;
91
+ }): Promise<RealtimeClientSecret>;
92
+ /** Exchange a browser SDP offer on your authenticated server. Returns no credentials. */
93
+ createCall(options: RealtimeSessionOptions & {
94
+ sdp: string;
95
+ }): Promise<{
96
+ sdp: string;
97
+ }>;
98
+ }
99
+
100
+ /** Audio models are independent of chat models and chat streaming events. */
101
+ type SpeechFormat = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
102
+ interface AudioResponseMetadata {
103
+ provider: string;
104
+ modelId: string;
105
+ requestId?: string;
106
+ status?: number;
107
+ }
108
+ interface AudioWarning {
109
+ code: string;
110
+ message: string;
111
+ }
112
+ interface SpeechOptions {
113
+ text: string;
114
+ voice?: string;
115
+ outputFormat?: SpeechFormat;
116
+ speed?: number;
117
+ instructions?: string;
118
+ signal?: AbortSignal;
119
+ providerOptions?: Record<string, Record<string, unknown>>;
120
+ }
121
+ interface GeneratedSpeech {
122
+ audio: {
123
+ uint8Array: Uint8Array;
124
+ readonly base64: string;
125
+ mediaType: string;
126
+ format: SpeechFormat;
127
+ };
128
+ response: AudioResponseMetadata;
129
+ warnings: AudioWarning[];
130
+ usage?: Record<string, unknown>;
131
+ }
132
+ interface SpeechModel {
133
+ readonly provider: string;
134
+ readonly modelId: string;
135
+ doGenerate(options: SpeechOptions): Promise<GeneratedSpeech>;
136
+ }
137
+ interface TranscriptionOptions {
138
+ /** Recorded file bytes, base64, or a Blob. URLs and raw PCM are not fetched/decoded. */
139
+ audio: Uint8Array | ArrayBuffer | Blob | string;
140
+ mediaType?: string;
141
+ filename?: string;
142
+ language?: string;
143
+ prompt?: string;
144
+ signal?: AbortSignal;
145
+ providerOptions?: Record<string, Record<string, unknown>>;
146
+ }
147
+ interface TranscriptSegment {
148
+ text: string;
149
+ start: number;
150
+ end: number;
151
+ speaker?: string;
152
+ }
153
+ interface TranscriptionResult {
154
+ text: string;
155
+ language?: string;
156
+ durationSeconds?: number;
157
+ segments?: TranscriptSegment[];
158
+ words?: Array<{
159
+ word: string;
160
+ start: number;
161
+ end: number;
162
+ }>;
163
+ response: AudioResponseMetadata;
164
+ warnings: AudioWarning[];
165
+ usage?: Record<string, unknown>;
166
+ /** Provider-supplied extras, including log probabilities when requested. */
167
+ providerMetadata?: Record<string, unknown>;
168
+ }
169
+ interface TranscriptionModel {
170
+ readonly provider: string;
171
+ readonly modelId: string;
172
+ doTranscribe(options: TranscriptionOptions): Promise<TranscriptionResult>;
173
+ }
174
+ declare const audioErrorMarker: unique symbol;
175
+ declare class AudioAPIError extends Error {
176
+ readonly code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error";
177
+ readonly status?: number | undefined;
178
+ readonly requestId?: string | undefined;
179
+ readonly [audioErrorMarker] = true;
180
+ static [Symbol.hasInstance](value: unknown): boolean;
181
+ readonly name = "AudioAPIError";
182
+ constructor(message: string, code: "invalid_input" | "unsupported_option" | "provider_error" | "invalid_response" | "network_error", status?: number | undefined, requestId?: string | undefined);
183
+ }
184
+ declare function generateSpeech({ model, ...options }: SpeechOptions & {
185
+ model: SpeechModel;
186
+ }): Promise<GeneratedSpeech>;
187
+ declare function transcribe({ model, ...options }: TranscriptionOptions & {
188
+ model: TranscriptionModel;
189
+ }): Promise<TranscriptionResult>;
190
+
191
+ export { AudioAPIError as A, type GeneratedImage as G, type ImageFile as I, MediaAPIError as M, type RealtimeToolDefinition as R, type SpeechModel as S, type TranscriptionModel as T, type ImageOptions as a, type ImageResult as b, type ImageModel as c, type RealtimeSessionOptions as d, type RealtimeClientSecret as e, type RealtimeModel as f, generateImage as g, generateSpeech as h, type SpeechOptions as i, type TranscriptionOptions as j, type GeneratedSpeech as k, type TranscriptionResult as l, type SpeechFormat as m, type TranscriptSegment as n, type AudioResponseMetadata as o, type AudioWarning as p, transcribe as t };
@@ -1,4 +1,4 @@
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';
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-D7lzMMLu.js';
2
2
 
3
3
  /**
4
4
  * Request-level LLM configuration overrides
@@ -110,6 +110,13 @@ declare function formatTools(actions: ActionDefinition[]): Array<{
110
110
  type AnthropicContentBlock = {
111
111
  type: "text";
112
112
  text: string;
113
+ } | {
114
+ type: "thinking";
115
+ thinking: string;
116
+ signature: string;
117
+ } | {
118
+ type: "redacted_thinking";
119
+ data: string;
113
120
  } | {
114
121
  type: "image";
115
122
  source: {
@@ -1,4 +1,4 @@
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';
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-D7lzMMLu.mjs';
2
2
 
3
3
  /**
4
4
  * Request-level LLM configuration overrides
@@ -110,6 +110,13 @@ declare function formatTools(actions: ActionDefinition[]): Array<{
110
110
  type AnthropicContentBlock = {
111
111
  type: "text";
112
112
  text: string;
113
+ } | {
114
+ type: "thinking";
115
+ thinking: string;
116
+ signature: string;
117
+ } | {
118
+ type: "redacted_thinking";
119
+ data: string;
113
120
  } | {
114
121
  type: "image";
115
122
  source: {
@@ -0,0 +1,137 @@
1
+ type DecisionJSON = null | boolean | number | string | readonly DecisionJSON[] | {
2
+ readonly [key: string]: DecisionJSON;
3
+ };
4
+ /** Native structured state, not a chat message list. JSON arrays remain JSON arrays. */
5
+ type DecisionInput = string | readonly DecisionJSON[] | {
6
+ readonly [key: string]: DecisionJSON;
7
+ };
8
+ type DecisionQuestion = {
9
+ readonly type: "boolean";
10
+ readonly instructions: DecisionInput;
11
+ readonly criteria?: {
12
+ readonly true?: DecisionInput;
13
+ readonly false?: DecisionInput;
14
+ };
15
+ } | {
16
+ readonly type: "choice";
17
+ readonly instructions: DecisionInput;
18
+ readonly criteria: Readonly<Record<string, DecisionInput | null>>;
19
+ } | {
20
+ readonly type: "score";
21
+ readonly instructions: DecisionInput;
22
+ readonly criteria: readonly DecisionInput[];
23
+ };
24
+ type DecisionQuestions = Readonly<Record<string, DecisionQuestion>>;
25
+ interface DecisionImage {
26
+ /** Encoded image bytes. This SDK interface does not accept hosted URLs. */
27
+ data: Uint8Array;
28
+ mediaType?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
29
+ /** OpenAI image detail. Other providers reject this setting. */
30
+ detail?: "auto" | "low" | "high" | "original";
31
+ }
32
+ interface DecisionOptions {
33
+ state: DecisionInput;
34
+ questions: DecisionQuestions;
35
+ /** Images are supplied alongside shared state; no remote downloads are performed. */
36
+ images?: readonly DecisionImage[];
37
+ signal?: AbortSignal;
38
+ /** Whole request, including reading its response. Defaults to 60 seconds. */
39
+ timeoutMs?: number;
40
+ providerOptions?: {
41
+ openai?: {
42
+ safetyIdentifier?: string;
43
+ promptCacheKey?: string;
44
+ };
45
+ typesafe?: {
46
+ longContext?: boolean;
47
+ };
48
+ openrouter?: {
49
+ sessionId?: string;
50
+ provider?: {
51
+ order?: readonly string[];
52
+ allowFallbacks?: boolean;
53
+ };
54
+ };
55
+ };
56
+ }
57
+ type DecisionAnswer = {
58
+ type: "boolean";
59
+ probability: number;
60
+ } | {
61
+ type: "choice";
62
+ choice: string;
63
+ probabilities?: Record<string, number>;
64
+ confidence?: number;
65
+ } | {
66
+ type: "score";
67
+ score: number;
68
+ probabilities?: Record<string, number>;
69
+ confidence?: number;
70
+ } | {
71
+ type: "refusal";
72
+ };
73
+ type AnswerFor<Q extends DecisionQuestion> = Extract<DecisionAnswer, {
74
+ type: "refusal";
75
+ }> | (Q extends {
76
+ type: "choice";
77
+ criteria: infer C;
78
+ } ? {
79
+ type: "choice";
80
+ choice: Extract<keyof C, string>;
81
+ probabilities?: Record<Extract<keyof C, string>, number>;
82
+ confidence?: number;
83
+ } : Extract<DecisionAnswer, {
84
+ type: Q["type"];
85
+ }>);
86
+ interface DecisionResult<Q extends DecisionQuestions = DecisionQuestions> {
87
+ answers: {
88
+ [K in keyof Q]: AnswerFor<Q[K]>;
89
+ };
90
+ usage?: {
91
+ inputTokens?: number;
92
+ outputTokens?: number;
93
+ totalTokens?: number;
94
+ cachedInputTokens?: number;
95
+ cacheWriteTokens?: number;
96
+ costUsd?: number;
97
+ };
98
+ response: {
99
+ provider: string;
100
+ modelId: string;
101
+ requestId?: string;
102
+ status?: number;
103
+ body?: unknown;
104
+ };
105
+ /** Only supplied by adapters whose upstream is known to round its values. */
106
+ rounding?: {
107
+ probabilityDecimals: number;
108
+ scoreDecimals: number;
109
+ };
110
+ }
111
+ /** Separate from LanguageModel: native decisions do not generate text or execute tools. */
112
+ interface DecisionModel {
113
+ readonly provider: string;
114
+ readonly modelId: string;
115
+ doDecide(options: DecisionOptions): Promise<DecisionResult>;
116
+ }
117
+ type DecisionErrorCode = "invalid_input" | "unsupported_option" | "invalid_response" | "refusal" | "http_error" | "network_error";
118
+ declare const decisionErrorMarker: unique symbol;
119
+ declare class DecisionAPIError extends Error {
120
+ readonly code: DecisionErrorCode;
121
+ readonly status?: number | undefined;
122
+ readonly requestId?: string | undefined;
123
+ readonly name = "DecisionAPIError";
124
+ private readonly [decisionErrorMarker];
125
+ /** Works across CJS/ESM and separately bundled provider entry points. */
126
+ static isInstance(error: unknown): error is DecisionAPIError;
127
+ constructor(message: string, code: DecisionErrorCode, status?: number | undefined, requestId?: string | undefined);
128
+ /** Advisory only: this SDK does not retry Decisions automatically. */
129
+ get retryable(): boolean;
130
+ }
131
+ /** Experimental: native provider contracts can change during this beta. */
132
+ declare function experimental_decide<const Q extends DecisionQuestions>(options: Omit<DecisionOptions, "questions"> & {
133
+ model: DecisionModel;
134
+ questions: Q;
135
+ }): Promise<DecisionResult<Q>>;
136
+
137
+ export { DecisionAPIError as D, type DecisionJSON as a, type DecisionInput as b, type DecisionQuestion as c, type DecisionQuestions as d, experimental_decide as e, type DecisionImage as f, type DecisionOptions as g, type DecisionAnswer as h, type DecisionResult as i, type DecisionModel as j, type DecisionErrorCode as k };
@@ -0,0 +1,137 @@
1
+ type DecisionJSON = null | boolean | number | string | readonly DecisionJSON[] | {
2
+ readonly [key: string]: DecisionJSON;
3
+ };
4
+ /** Native structured state, not a chat message list. JSON arrays remain JSON arrays. */
5
+ type DecisionInput = string | readonly DecisionJSON[] | {
6
+ readonly [key: string]: DecisionJSON;
7
+ };
8
+ type DecisionQuestion = {
9
+ readonly type: "boolean";
10
+ readonly instructions: DecisionInput;
11
+ readonly criteria?: {
12
+ readonly true?: DecisionInput;
13
+ readonly false?: DecisionInput;
14
+ };
15
+ } | {
16
+ readonly type: "choice";
17
+ readonly instructions: DecisionInput;
18
+ readonly criteria: Readonly<Record<string, DecisionInput | null>>;
19
+ } | {
20
+ readonly type: "score";
21
+ readonly instructions: DecisionInput;
22
+ readonly criteria: readonly DecisionInput[];
23
+ };
24
+ type DecisionQuestions = Readonly<Record<string, DecisionQuestion>>;
25
+ interface DecisionImage {
26
+ /** Encoded image bytes. This SDK interface does not accept hosted URLs. */
27
+ data: Uint8Array;
28
+ mediaType?: "image/png" | "image/jpeg" | "image/webp" | "image/gif";
29
+ /** OpenAI image detail. Other providers reject this setting. */
30
+ detail?: "auto" | "low" | "high" | "original";
31
+ }
32
+ interface DecisionOptions {
33
+ state: DecisionInput;
34
+ questions: DecisionQuestions;
35
+ /** Images are supplied alongside shared state; no remote downloads are performed. */
36
+ images?: readonly DecisionImage[];
37
+ signal?: AbortSignal;
38
+ /** Whole request, including reading its response. Defaults to 60 seconds. */
39
+ timeoutMs?: number;
40
+ providerOptions?: {
41
+ openai?: {
42
+ safetyIdentifier?: string;
43
+ promptCacheKey?: string;
44
+ };
45
+ typesafe?: {
46
+ longContext?: boolean;
47
+ };
48
+ openrouter?: {
49
+ sessionId?: string;
50
+ provider?: {
51
+ order?: readonly string[];
52
+ allowFallbacks?: boolean;
53
+ };
54
+ };
55
+ };
56
+ }
57
+ type DecisionAnswer = {
58
+ type: "boolean";
59
+ probability: number;
60
+ } | {
61
+ type: "choice";
62
+ choice: string;
63
+ probabilities?: Record<string, number>;
64
+ confidence?: number;
65
+ } | {
66
+ type: "score";
67
+ score: number;
68
+ probabilities?: Record<string, number>;
69
+ confidence?: number;
70
+ } | {
71
+ type: "refusal";
72
+ };
73
+ type AnswerFor<Q extends DecisionQuestion> = Extract<DecisionAnswer, {
74
+ type: "refusal";
75
+ }> | (Q extends {
76
+ type: "choice";
77
+ criteria: infer C;
78
+ } ? {
79
+ type: "choice";
80
+ choice: Extract<keyof C, string>;
81
+ probabilities?: Record<Extract<keyof C, string>, number>;
82
+ confidence?: number;
83
+ } : Extract<DecisionAnswer, {
84
+ type: Q["type"];
85
+ }>);
86
+ interface DecisionResult<Q extends DecisionQuestions = DecisionQuestions> {
87
+ answers: {
88
+ [K in keyof Q]: AnswerFor<Q[K]>;
89
+ };
90
+ usage?: {
91
+ inputTokens?: number;
92
+ outputTokens?: number;
93
+ totalTokens?: number;
94
+ cachedInputTokens?: number;
95
+ cacheWriteTokens?: number;
96
+ costUsd?: number;
97
+ };
98
+ response: {
99
+ provider: string;
100
+ modelId: string;
101
+ requestId?: string;
102
+ status?: number;
103
+ body?: unknown;
104
+ };
105
+ /** Only supplied by adapters whose upstream is known to round its values. */
106
+ rounding?: {
107
+ probabilityDecimals: number;
108
+ scoreDecimals: number;
109
+ };
110
+ }
111
+ /** Separate from LanguageModel: native decisions do not generate text or execute tools. */
112
+ interface DecisionModel {
113
+ readonly provider: string;
114
+ readonly modelId: string;
115
+ doDecide(options: DecisionOptions): Promise<DecisionResult>;
116
+ }
117
+ type DecisionErrorCode = "invalid_input" | "unsupported_option" | "invalid_response" | "refusal" | "http_error" | "network_error";
118
+ declare const decisionErrorMarker: unique symbol;
119
+ declare class DecisionAPIError extends Error {
120
+ readonly code: DecisionErrorCode;
121
+ readonly status?: number | undefined;
122
+ readonly requestId?: string | undefined;
123
+ readonly name = "DecisionAPIError";
124
+ private readonly [decisionErrorMarker];
125
+ /** Works across CJS/ESM and separately bundled provider entry points. */
126
+ static isInstance(error: unknown): error is DecisionAPIError;
127
+ constructor(message: string, code: DecisionErrorCode, status?: number | undefined, requestId?: string | undefined);
128
+ /** Advisory only: this SDK does not retry Decisions automatically. */
129
+ get retryable(): boolean;
130
+ }
131
+ /** Experimental: native provider contracts can change during this beta. */
132
+ declare function experimental_decide<const Q extends DecisionQuestions>(options: Omit<DecisionOptions, "questions"> & {
133
+ model: DecisionModel;
134
+ questions: Q;
135
+ }): Promise<DecisionResult<Q>>;
136
+
137
+ export { DecisionAPIError as D, type DecisionJSON as a, type DecisionInput as b, type DecisionQuestion as c, type DecisionQuestions as d, experimental_decide as e, type DecisionImage as f, type DecisionOptions as g, type DecisionAnswer as h, type DecisionResult as i, type DecisionModel as j, type DecisionErrorCode as k };