@opencode-ai/ai 0.0.0-beta-17492

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 (194) hide show
  1. package/README.md +392 -0
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +121 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +19 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +102 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +230 -0
  11. package/dist/llm.js +77 -0
  12. package/dist/protocols/anthropic-messages.d.ts +633 -0
  13. package/dist/protocols/anthropic-messages.js +860 -0
  14. package/dist/protocols/bedrock-converse.d.ts +533 -0
  15. package/dist/protocols/bedrock-converse.js +584 -0
  16. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  17. package/dist/protocols/bedrock-event-stream.js +73 -0
  18. package/dist/protocols/gemini.d.ts +300 -0
  19. package/dist/protocols/gemini.js +512 -0
  20. package/dist/protocols/google-images.d.ts +30 -0
  21. package/dist/protocols/google-images.js +191 -0
  22. package/dist/protocols/index.d.ts +10 -0
  23. package/dist/protocols/index.js +10 -0
  24. package/dist/protocols/open-responses-channel.d.ts +26 -0
  25. package/dist/protocols/open-responses-channel.js +120 -0
  26. package/dist/protocols/open-responses.d.ts +951 -0
  27. package/dist/protocols/open-responses.js +873 -0
  28. package/dist/protocols/openai-chat.d.ts +795 -0
  29. package/dist/protocols/openai-chat.js +718 -0
  30. package/dist/protocols/openai-compatible-chat.d.ts +107 -0
  31. package/dist/protocols/openai-compatible-chat.js +20 -0
  32. package/dist/protocols/openai-compatible-responses.d.ts +96 -0
  33. package/dist/protocols/openai-compatible-responses.js +17 -0
  34. package/dist/protocols/openai-images.d.ts +32 -0
  35. package/dist/protocols/openai-images.js +188 -0
  36. package/dist/protocols/openai-responses-channel.d.ts +12 -0
  37. package/dist/protocols/openai-responses-channel.js +142 -0
  38. package/dist/protocols/openai-responses.d.ts +596 -0
  39. package/dist/protocols/openai-responses.js +208 -0
  40. package/dist/protocols/shared.d.ts +194 -0
  41. package/dist/protocols/shared.js +238 -0
  42. package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
  43. package/dist/protocols/utils/bedrock-auth.js +43 -0
  44. package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
  45. package/dist/protocols/utils/bedrock-cache.js +29 -0
  46. package/dist/protocols/utils/bedrock-media.d.ts +49 -0
  47. package/dist/protocols/utils/bedrock-media.js +70 -0
  48. package/dist/protocols/utils/cache.d.ts +6 -0
  49. package/dist/protocols/utils/cache.js +8 -0
  50. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  51. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  52. package/dist/protocols/utils/image-input.d.ts +21 -0
  53. package/dist/protocols/utils/image-input.js +22 -0
  54. package/dist/protocols/utils/lifecycle.d.ts +20 -0
  55. package/dist/protocols/utils/lifecycle.js +68 -0
  56. package/dist/protocols/utils/open-responses-options.d.ts +21 -0
  57. package/dist/protocols/utils/open-responses-options.js +41 -0
  58. package/dist/protocols/utils/openai-image.d.ts +5 -0
  59. package/dist/protocols/utils/openai-image.js +18 -0
  60. package/dist/protocols/utils/openai-options.d.ts +14 -0
  61. package/dist/protocols/utils/openai-options.js +14 -0
  62. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  63. package/dist/protocols/utils/tool-schema.js +81 -0
  64. package/dist/protocols/utils/tool-stream.d.ts +639 -0
  65. package/dist/protocols/utils/tool-stream.js +141 -0
  66. package/dist/protocols/xai-images.d.ts +26 -0
  67. package/dist/protocols/xai-images.js +111 -0
  68. package/dist/protocols/zai-images.d.ts +22 -0
  69. package/dist/protocols/zai-images.js +84 -0
  70. package/dist/protocols.d.ts +1 -0
  71. package/dist/protocols.js +1 -0
  72. package/dist/provider-error.d.ts +14 -0
  73. package/dist/provider-error.js +130 -0
  74. package/dist/provider-package.d.ts +15 -0
  75. package/dist/provider-package.js +1 -0
  76. package/dist/provider.d.ts +23 -0
  77. package/dist/provider.js +2 -0
  78. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  79. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  80. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  81. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  82. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  83. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  84. package/dist/providers/amazon-bedrock-mantle.d.ts +247 -0
  85. package/dist/providers/amazon-bedrock-mantle.js +68 -0
  86. package/dist/providers/amazon-bedrock.d.ts +172 -0
  87. package/dist/providers/amazon-bedrock.js +41 -0
  88. package/dist/providers/anthropic-compatible.d.ts +218 -0
  89. package/dist/providers/anthropic-compatible.js +45 -0
  90. package/dist/providers/anthropic.d.ts +216 -0
  91. package/dist/providers/anthropic.js +40 -0
  92. package/dist/providers/azure/chat.d.ts +2 -0
  93. package/dist/providers/azure/chat.js +1 -0
  94. package/dist/providers/azure/responses.d.ts +2 -0
  95. package/dist/providers/azure/responses.js +1 -0
  96. package/dist/providers/azure.d.ts +248 -0
  97. package/dist/providers/azure.js +90 -0
  98. package/dist/providers/cloudflare.d.ts +338 -0
  99. package/dist/providers/cloudflare.js +87 -0
  100. package/dist/providers/google-vertex/chat.d.ts +2 -0
  101. package/dist/providers/google-vertex/chat.js +1 -0
  102. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  103. package/dist/providers/google-vertex/gemini.js +1 -0
  104. package/dist/providers/google-vertex/messages.d.ts +2 -0
  105. package/dist/providers/google-vertex/messages.js +1 -0
  106. package/dist/providers/google-vertex/responses.d.ts +2 -0
  107. package/dist/providers/google-vertex/responses.js +1 -0
  108. package/dist/providers/google-vertex-chat.d.ts +131 -0
  109. package/dist/providers/google-vertex-chat.js +50 -0
  110. package/dist/providers/google-vertex-messages.d.ts +215 -0
  111. package/dist/providers/google-vertex-messages.js +75 -0
  112. package/dist/providers/google-vertex-responses.d.ts +122 -0
  113. package/dist/providers/google-vertex-responses.js +51 -0
  114. package/dist/providers/google-vertex-shared.d.ts +22 -0
  115. package/dist/providers/google-vertex-shared.js +61 -0
  116. package/dist/providers/google-vertex.d.ts +115 -0
  117. package/dist/providers/google-vertex.js +64 -0
  118. package/dist/providers/google.d.ts +112 -0
  119. package/dist/providers/google.js +43 -0
  120. package/dist/providers/index.d.ts +18 -0
  121. package/dist/providers/index.js +18 -0
  122. package/dist/providers/open-responses-options.d.ts +16 -0
  123. package/dist/providers/open-responses-options.js +1 -0
  124. package/dist/providers/openai/chat.d.ts +2 -0
  125. package/dist/providers/openai/chat.js +1 -0
  126. package/dist/providers/openai/responses.d.ts +2 -0
  127. package/dist/providers/openai/responses.js +1 -0
  128. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  129. package/dist/providers/openai-compatible/responses.js +1 -0
  130. package/dist/providers/openai-compatible-profile.d.ts +43 -0
  131. package/dist/providers/openai-compatible-profile.js +12 -0
  132. package/dist/providers/openai-compatible-responses.d.ts +120 -0
  133. package/dist/providers/openai-compatible-responses.js +33 -0
  134. package/dist/providers/openai-compatible.d.ts +167 -0
  135. package/dist/providers/openai-compatible.js +55 -0
  136. package/dist/providers/openai-options.d.ts +21 -0
  137. package/dist/providers/openai-options.js +41 -0
  138. package/dist/providers/openai.d.ts +264 -0
  139. package/dist/providers/openai.js +83 -0
  140. package/dist/providers/openrouter.d.ts +537 -0
  141. package/dist/providers/openrouter.js +117 -0
  142. package/dist/providers/xai.d.ts +249 -0
  143. package/dist/providers/xai.js +79 -0
  144. package/dist/providers/zai.d.ts +24 -0
  145. package/dist/providers/zai.js +21 -0
  146. package/dist/providers.d.ts +1 -0
  147. package/dist/providers.js +1 -0
  148. package/dist/route/auth-options.d.ts +34 -0
  149. package/dist/route/auth-options.js +14 -0
  150. package/dist/route/auth.d.ts +51 -0
  151. package/dist/route/auth.js +89 -0
  152. package/dist/route/client.d.ts +348 -0
  153. package/dist/route/client.js +214 -0
  154. package/dist/route/endpoint.d.ts +28 -0
  155. package/dist/route/endpoint.js +21 -0
  156. package/dist/route/executor.d.ts +23 -0
  157. package/dist/route/executor.js +227 -0
  158. package/dist/route/framing.d.ts +23 -0
  159. package/dist/route/framing.js +4 -0
  160. package/dist/route/index.d.ts +16 -0
  161. package/dist/route/index.js +9 -0
  162. package/dist/route/protocol.d.ts +77 -0
  163. package/dist/route/protocol.js +17 -0
  164. package/dist/route/transport/http.d.ts +34 -0
  165. package/dist/route/transport/http.js +63 -0
  166. package/dist/route/transport/index.d.ts +39 -0
  167. package/dist/route/transport/index.js +4 -0
  168. package/dist/route/transport/websocket-channel.d.ts +56 -0
  169. package/dist/route/transport/websocket-channel.js +1 -0
  170. package/dist/route/transport/websocket.d.ts +55 -0
  171. package/dist/route/transport/websocket.js +326 -0
  172. package/dist/route.d.ts +1 -0
  173. package/dist/route.js +1 -0
  174. package/dist/schema/errors.d.ts +159 -0
  175. package/dist/schema/errors.js +155 -0
  176. package/dist/schema/events.d.ts +4587 -0
  177. package/dist/schema/events.js +492 -0
  178. package/dist/schema/ids.d.ts +30 -0
  179. package/dist/schema/ids.js +19 -0
  180. package/dist/schema/index.d.ts +5 -0
  181. package/dist/schema/index.js +5 -0
  182. package/dist/schema/messages.d.ts +402 -0
  183. package/dist/schema/messages.js +244 -0
  184. package/dist/schema/options.d.ts +159 -0
  185. package/dist/schema/options.js +202 -0
  186. package/dist/testing.d.ts +1493 -0
  187. package/dist/testing.js +88 -0
  188. package/dist/tool-runtime.d.ts +15 -0
  189. package/dist/tool-runtime.js +54 -0
  190. package/dist/tool.d.ts +135 -0
  191. package/dist/tool.js +66 -0
  192. package/dist/utils/record.d.ts +2 -0
  193. package/dist/utils/record.js +2 -0
  194. package/package.json +47 -0
@@ -0,0 +1,264 @@
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
+ import type { Route, RouteDefaultsInput } from "../route/client.js";
3
+ import type { ProviderPackage } from "../provider-package.js";
4
+ import { ToolDefinition, type ModelID } from "../schema/index.js";
5
+ import { type OpenAIProviderOptionsInput } from "./openai-options.js";
6
+ import { type OpenAIImageString } from "../protocols/openai-images.js";
7
+ export type { OpenAIOptionsInput, OpenAIResponseIncludable } from "./openai-options.js";
8
+ export type { OpenAIImageOptions } from "../protocols/openai-images.js";
9
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
10
+ export declare const routes: (Route<{
11
+ readonly model: string;
12
+ readonly messages: readonly ({
13
+ readonly role: "system";
14
+ readonly content: string | readonly ({
15
+ readonly type: "text";
16
+ readonly text: string;
17
+ readonly cache_control?: {
18
+ readonly type: "ephemeral";
19
+ readonly ttl?: string | undefined;
20
+ } | undefined;
21
+ } | {
22
+ readonly type: "image_url";
23
+ readonly image_url: {
24
+ readonly url: string;
25
+ };
26
+ })[];
27
+ } | {
28
+ readonly role: "user";
29
+ readonly content: string | readonly ({
30
+ readonly type: "text";
31
+ readonly text: string;
32
+ readonly cache_control?: {
33
+ readonly type: "ephemeral";
34
+ readonly ttl?: string | undefined;
35
+ } | undefined;
36
+ } | {
37
+ readonly type: "image_url";
38
+ readonly image_url: {
39
+ readonly url: string;
40
+ };
41
+ })[];
42
+ } | {
43
+ readonly [x: string]: unknown;
44
+ readonly content: string | null;
45
+ readonly role: "assistant";
46
+ readonly reasoning?: string | undefined;
47
+ readonly reasoning_content?: string | undefined;
48
+ readonly reasoning_text?: string | undefined;
49
+ readonly cache_control?: {
50
+ readonly type: "ephemeral";
51
+ readonly ttl?: string | undefined;
52
+ } | undefined;
53
+ readonly tool_calls?: readonly {
54
+ readonly id: string;
55
+ readonly type: "function";
56
+ readonly function: {
57
+ readonly name: string;
58
+ readonly arguments: string;
59
+ };
60
+ }[] | undefined;
61
+ readonly reasoning_details?: unknown;
62
+ } | {
63
+ readonly content: string;
64
+ readonly role: "tool";
65
+ readonly tool_call_id: string;
66
+ readonly cache_control?: {
67
+ readonly type: "ephemeral";
68
+ readonly ttl?: string | undefined;
69
+ } | undefined;
70
+ })[];
71
+ readonly stream: true;
72
+ readonly stop?: readonly string[] | undefined;
73
+ readonly max_completion_tokens?: number | undefined;
74
+ readonly max_tokens?: number | undefined;
75
+ readonly tools?: readonly {
76
+ readonly function: {
77
+ readonly name: string;
78
+ readonly description: string;
79
+ readonly parameters: {
80
+ readonly [x: string]: unknown;
81
+ };
82
+ };
83
+ readonly type: "function";
84
+ readonly cache_control?: {
85
+ readonly type: "ephemeral";
86
+ readonly ttl?: string | undefined;
87
+ } | undefined;
88
+ }[] | undefined;
89
+ readonly temperature?: number | undefined;
90
+ readonly seed?: number | undefined;
91
+ readonly tool_choice?: "required" | "none" | "auto" | {
92
+ readonly type: "function";
93
+ readonly function: {
94
+ readonly name: string;
95
+ };
96
+ } | undefined;
97
+ readonly top_p?: number | undefined;
98
+ readonly store?: boolean | undefined;
99
+ readonly stream_options?: {
100
+ readonly include_usage: boolean;
101
+ } | undefined;
102
+ readonly prompt_cache_key?: string | undefined;
103
+ readonly reasoning_effort?: string | undefined;
104
+ readonly frequency_penalty?: number | undefined;
105
+ readonly presence_penalty?: number | undefined;
106
+ }, import("../route/transport/http.js").HttpPrepared<string>> | Route<{
107
+ readonly input: readonly ({
108
+ readonly type: "reasoning";
109
+ readonly summary: readonly {
110
+ readonly type: "summary_text";
111
+ readonly text: string;
112
+ }[];
113
+ readonly id?: string | undefined;
114
+ readonly encrypted_content?: string | null | undefined;
115
+ } | {
116
+ readonly type: "item_reference";
117
+ readonly id: string;
118
+ } | {
119
+ readonly role: "system";
120
+ readonly content: string;
121
+ } | {
122
+ readonly role: "user";
123
+ readonly content: readonly ({
124
+ readonly type: "input_image";
125
+ readonly image_url: string;
126
+ } | {
127
+ readonly type: "input_file";
128
+ readonly filename: string;
129
+ readonly file_data: string;
130
+ readonly mime_type?: string | undefined;
131
+ } | {
132
+ readonly type: "input_text";
133
+ readonly text: string;
134
+ })[];
135
+ } | {
136
+ readonly content: readonly {
137
+ readonly type: "output_text";
138
+ readonly text: string;
139
+ }[];
140
+ readonly role: "assistant";
141
+ readonly phase?: "commentary" | "final_answer" | undefined;
142
+ } | {
143
+ readonly type: "function_call";
144
+ readonly call_id: string;
145
+ readonly name: string;
146
+ readonly arguments: string;
147
+ } | {
148
+ readonly type: "function_call_output";
149
+ readonly call_id: string;
150
+ readonly output: string | readonly ({
151
+ readonly type: "input_image";
152
+ readonly image_url: string;
153
+ } | {
154
+ readonly type: "input_file";
155
+ readonly filename: string;
156
+ readonly file_data: string;
157
+ readonly mime_type?: string | undefined;
158
+ } | {
159
+ readonly type: "input_text";
160
+ readonly text: string;
161
+ })[];
162
+ } | {
163
+ readonly content: readonly {
164
+ readonly type: "output_text";
165
+ readonly text: string;
166
+ }[];
167
+ readonly role: "assistant";
168
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
169
+ })[];
170
+ readonly model: string;
171
+ readonly stream: true;
172
+ readonly instructions?: string | undefined;
173
+ readonly reasoning?: {
174
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
175
+ readonly effort?: string | undefined;
176
+ } | undefined;
177
+ readonly tools?: readonly ({
178
+ readonly type: "function";
179
+ readonly description: string;
180
+ readonly name: string;
181
+ readonly parameters: {
182
+ readonly [x: string]: unknown;
183
+ };
184
+ readonly strict?: boolean | undefined;
185
+ } | {
186
+ readonly type: "image_generation";
187
+ readonly size?: string | undefined;
188
+ readonly action?: "generate" | "auto" | "edit" | undefined;
189
+ readonly output_format?: "png" | "jpeg" | "webp" | undefined;
190
+ readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
191
+ readonly background?: "auto" | "opaque" | "transparent" | undefined;
192
+ readonly output_compression?: number | undefined;
193
+ readonly input_fidelity?: "low" | "high" | undefined;
194
+ readonly partial_images?: number | undefined;
195
+ })[] | undefined;
196
+ readonly text?: {
197
+ readonly verbosity?: "low" | "medium" | "high" | undefined;
198
+ } | undefined;
199
+ readonly temperature?: number | undefined;
200
+ readonly tool_choice?: "required" | "none" | "auto" | {
201
+ readonly type: "function";
202
+ readonly name: string;
203
+ } | {
204
+ readonly type: "image_generation";
205
+ } | undefined;
206
+ readonly top_p?: number | undefined;
207
+ readonly include?: readonly ("file_search_call.results" | "web_search_call.results" | "web_search_call.action.sources" | "message.input_image.image_url" | "computer_call_output.output.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | undefined;
208
+ readonly store?: boolean | undefined;
209
+ readonly prompt_cache_key?: string | undefined;
210
+ readonly service_tier?: "default" | "auto" | "flex" | "priority" | undefined;
211
+ readonly max_output_tokens?: number | undefined;
212
+ }, import("../protocols/open-responses-channel.js").Prepared>)[];
213
+ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
214
+ readonly baseURL?: string;
215
+ readonly queryParams?: Record<string, string>;
216
+ readonly providerOptions?: OpenAIProviderOptionsInput;
217
+ };
218
+ export interface ImageGenerationOptions {
219
+ readonly action?: OpenAIImageString<"auto" | "generate" | "edit">;
220
+ readonly background?: OpenAIImageString<"auto" | "opaque" | "transparent">;
221
+ readonly inputFidelity?: OpenAIImageString<"low" | "high">;
222
+ readonly outputCompression?: number;
223
+ readonly outputFormat?: OpenAIImageString<"png" | "jpeg" | "webp">;
224
+ readonly partialImages?: number;
225
+ readonly quality?: OpenAIImageString<"auto" | "low" | "medium" | "high" | "standard" | "hd">;
226
+ readonly size?: OpenAIImageString<"auto" | "256x256" | "512x512" | "1024x1024" | "1536x1024" | "1024x1536" | "1792x1024" | "1024x1792">;
227
+ }
228
+ export declare const imageGeneration: (options?: ImageGenerationOptions) => ToolDefinition;
229
+ export interface Settings extends ProviderPackage.Settings {
230
+ readonly apiKey?: string;
231
+ readonly baseURL?: string;
232
+ readonly organization?: string;
233
+ readonly project?: string;
234
+ readonly queryParams?: Readonly<Record<string, string>>;
235
+ readonly providerOptions?: OpenAIProviderOptionsInput;
236
+ }
237
+ export declare const configure: (input?: Config) => {
238
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
239
+ model: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
240
+ responses: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
241
+ chat: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
242
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
243
+ configure: (input?: Config) => /*elided*/ any;
244
+ };
245
+ export declare const provider: {
246
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
247
+ model: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
248
+ responses: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
249
+ chat: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
250
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
251
+ configure: (input?: Config) => {
252
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
253
+ model: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
254
+ responses: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
255
+ chat: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
256
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
257
+ configure: /*elided*/ any;
258
+ };
259
+ };
260
+ export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
261
+ export declare const chatModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
262
+ export declare const responses: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
263
+ export declare const chat: (id: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
264
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
@@ -0,0 +1,83 @@
1
+ import { AuthOptions } from "../route/auth-options.js";
2
+ import { HttpOptions, ProviderID, ToolDefinition, mergeHttpOptions } from "../schema/index.js";
3
+ import * as OpenAIChat from "../protocols/openai-chat.js";
4
+ import * as OpenAIResponses from "../protocols/openai-responses.js";
5
+ import { withOpenAIOptions } from "./openai-options.js";
6
+ import { OpenAIImages } from "../protocols/openai-images.js";
7
+ export const id = ProviderID.make("openai");
8
+ export const routes = [OpenAIResponses.route, OpenAIChat.route];
9
+ export const imageGeneration = (options = {}) => ToolDefinition.make({
10
+ name: "image_generation",
11
+ description: "Generate or edit an image using OpenAI's hosted image generation tool.",
12
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
13
+ native: {
14
+ openai: {
15
+ type: "image_generation",
16
+ action: options.action,
17
+ background: options.background,
18
+ input_fidelity: options.inputFidelity,
19
+ output_compression: options.outputCompression,
20
+ output_format: options.outputFormat,
21
+ partial_images: options.partialImages,
22
+ quality: options.quality,
23
+ size: options.size,
24
+ },
25
+ },
26
+ });
27
+ const auth = (options) => AuthOptions.bearer(options, "OPENAI_API_KEY");
28
+ const defaults = (input) => {
29
+ const { apiKey: _, auth: _auth, baseURL: _baseURL, queryParams: _queryParams, ...rest } = input;
30
+ return rest;
31
+ };
32
+ const configuredRoute = (route, input) => route.with({
33
+ auth: auth(input),
34
+ endpoint: { baseURL: input.baseURL, query: input.queryParams },
35
+ });
36
+ export const configure = (input = {}) => {
37
+ const responsesRoute = configuredRoute(OpenAIResponses.route, input);
38
+ const chatRoute = configuredRoute(OpenAIChat.route, input);
39
+ const modelDefaults = defaults(input);
40
+ const responses = (id) => responsesRoute
41
+ .with(withOpenAIOptions(id, modelDefaults, { textVerbosity: true }))
42
+ .model({ id });
43
+ const chat = (id) => chatRoute.with(withOpenAIOptions(id, modelDefaults)).model({ id });
44
+ const image = (modelID) => OpenAIImages.model({
45
+ id: modelID,
46
+ auth: auth(input),
47
+ baseURL: input.baseURL,
48
+ headers: input.headers,
49
+ http: mergeHttpOptions(input.http === undefined ? undefined : HttpOptions.make(input.http), input.queryParams === undefined ? undefined : new HttpOptions({ query: input.queryParams })),
50
+ });
51
+ return {
52
+ id,
53
+ model: responses,
54
+ responses,
55
+ chat,
56
+ image,
57
+ configure,
58
+ };
59
+ };
60
+ export const provider = configure();
61
+ const config = (settings) => {
62
+ const headers = {
63
+ ...(settings.organization === undefined ? {} : { "OpenAI-Organization": settings.organization }),
64
+ ...(settings.project === undefined ? {} : { "OpenAI-Project": settings.project }),
65
+ ...settings.headers,
66
+ };
67
+ return {
68
+ apiKey: settings.apiKey,
69
+ baseURL: settings.baseURL,
70
+ headers: Object.keys(headers).length === 0 ? undefined : headers,
71
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
72
+ limits: settings.limits,
73
+ providerOptions: settings.providerOptions,
74
+ queryParams: settings.queryParams === undefined ? undefined : { ...settings.queryParams },
75
+ };
76
+ };
77
+ export const model = (modelID, settings) => {
78
+ return configure(config(settings)).responses(modelID);
79
+ };
80
+ export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
81
+ export const responses = provider.responses;
82
+ export const chat = provider.chat;
83
+ export const image = provider.image;