@opencode-ai/ai 0.0.0-bootstrap.0 → 0.0.0-next-15618

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 (151) hide show
  1. package/README.md +176 -1
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +108 -0
  4. package/dist/index.d.ts +14 -0
  5. package/dist/index.js +9 -0
  6. package/dist/llm.d.ts +223 -0
  7. package/dist/llm.js +81 -0
  8. package/dist/protocols/anthropic-messages.d.ts +503 -0
  9. package/dist/protocols/anthropic-messages.js +745 -0
  10. package/dist/protocols/bedrock-converse.d.ts +476 -0
  11. package/dist/protocols/bedrock-converse.js +526 -0
  12. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  13. package/dist/protocols/bedrock-event-stream.js +64 -0
  14. package/dist/protocols/gemini.d.ts +220 -0
  15. package/dist/protocols/gemini.js +420 -0
  16. package/dist/protocols/google-vertex-anthropic.d.ts +494 -0
  17. package/dist/protocols/google-vertex-anthropic.js +33 -0
  18. package/dist/protocols/google-vertex-gemini.d.ts +59 -0
  19. package/dist/protocols/google-vertex-gemini.js +18 -0
  20. package/dist/protocols/index.d.ts +9 -0
  21. package/dist/protocols/index.js +9 -0
  22. package/dist/protocols/openai-chat.d.ts +391 -0
  23. package/dist/protocols/openai-chat.js +423 -0
  24. package/dist/protocols/openai-compatible-chat.d.ts +73 -0
  25. package/dist/protocols/openai-compatible-chat.js +20 -0
  26. package/dist/protocols/openai-compatible-responses.d.ts +85 -0
  27. package/dist/protocols/openai-compatible-responses.js +18 -0
  28. package/dist/protocols/openai-responses.d.ts +613 -0
  29. package/dist/protocols/openai-responses.js +828 -0
  30. package/dist/protocols/shared.d.ts +192 -0
  31. package/dist/protocols/shared.js +236 -0
  32. package/dist/protocols/utils/bedrock-auth.d.ts +18 -0
  33. package/dist/protocols/utils/bedrock-auth.js +41 -0
  34. package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
  35. package/dist/protocols/utils/bedrock-cache.js +29 -0
  36. package/dist/protocols/utils/bedrock-media.d.ts +49 -0
  37. package/dist/protocols/utils/bedrock-media.js +68 -0
  38. package/dist/protocols/utils/cache.d.ts +6 -0
  39. package/dist/protocols/utils/cache.js +8 -0
  40. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  41. package/dist/protocols/utils/gemini-tool-schema.js +83 -0
  42. package/dist/protocols/utils/lifecycle.d.ts +19 -0
  43. package/dist/protocols/utils/lifecycle.js +65 -0
  44. package/dist/protocols/utils/openai-options.d.ts +22 -0
  45. package/dist/protocols/utils/openai-options.js +64 -0
  46. package/dist/protocols/utils/tool-schema.d.ts +7 -0
  47. package/dist/protocols/utils/tool-schema.js +79 -0
  48. package/dist/protocols/utils/tool-stream.d.ts +155 -0
  49. package/dist/protocols/utils/tool-stream.js +136 -0
  50. package/dist/protocols.d.ts +1 -0
  51. package/dist/protocols.js +1 -0
  52. package/dist/provider-error.d.ts +13 -0
  53. package/dist/provider-error.js +122 -0
  54. package/dist/provider-package.d.ts +13 -0
  55. package/dist/provider-package.js +1 -0
  56. package/dist/provider.d.ts +23 -0
  57. package/dist/provider.js +2 -0
  58. package/dist/providers/amazon-bedrock.d.ts +150 -0
  59. package/dist/providers/amazon-bedrock.js +41 -0
  60. package/dist/providers/anthropic-compatible.d.ts +183 -0
  61. package/dist/providers/anthropic-compatible.js +44 -0
  62. package/dist/providers/anthropic.d.ts +181 -0
  63. package/dist/providers/anthropic.js +39 -0
  64. package/dist/providers/azure/chat.d.ts +2 -0
  65. package/dist/providers/azure/chat.js +1 -0
  66. package/dist/providers/azure/responses.d.ts +2 -0
  67. package/dist/providers/azure/responses.js +1 -0
  68. package/dist/providers/azure.d.ts +183 -0
  69. package/dist/providers/azure.js +89 -0
  70. package/dist/providers/cloudflare.d.ts +232 -0
  71. package/dist/providers/cloudflare.js +87 -0
  72. package/dist/providers/github-copilot.d.ts +167 -0
  73. package/dist/providers/github-copilot.js +47 -0
  74. package/dist/providers/google-vertex/anthropic.d.ts +2 -0
  75. package/dist/providers/google-vertex/anthropic.js +1 -0
  76. package/dist/providers/google-vertex-anthropic.d.ts +181 -0
  77. package/dist/providers/google-vertex-anthropic.js +46 -0
  78. package/dist/providers/google-vertex-shared.d.ts +22 -0
  79. package/dist/providers/google-vertex-shared.js +61 -0
  80. package/dist/providers/google-vertex.d.ts +93 -0
  81. package/dist/providers/google-vertex.js +49 -0
  82. package/dist/providers/google.d.ts +85 -0
  83. package/dist/providers/google.js +33 -0
  84. package/dist/providers/index.d.ts +15 -0
  85. package/dist/providers/index.js +15 -0
  86. package/dist/providers/openai/chat.d.ts +2 -0
  87. package/dist/providers/openai/chat.js +1 -0
  88. package/dist/providers/openai/responses.d.ts +2 -0
  89. package/dist/providers/openai/responses.js +1 -0
  90. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  91. package/dist/providers/openai-compatible/responses.js +1 -0
  92. package/dist/providers/openai-compatible-profile.d.ts +43 -0
  93. package/dist/providers/openai-compatible-profile.js +12 -0
  94. package/dist/providers/openai-compatible-responses.d.ts +107 -0
  95. package/dist/providers/openai-compatible-responses.js +33 -0
  96. package/dist/providers/openai-compatible.d.ts +130 -0
  97. package/dist/providers/openai-compatible.js +55 -0
  98. package/dist/providers/openai-options.d.ts +30 -0
  99. package/dist/providers/openai-options.js +42 -0
  100. package/dist/providers/openai.d.ts +264 -0
  101. package/dist/providers/openai.js +62 -0
  102. package/dist/providers/openrouter.d.ts +321 -0
  103. package/dist/providers/openrouter.js +65 -0
  104. package/dist/providers/xai.d.ts +169 -0
  105. package/dist/providers/xai.js +43 -0
  106. package/dist/providers.d.ts +1 -0
  107. package/dist/providers.js +1 -0
  108. package/dist/route/auth-options.d.ts +34 -0
  109. package/dist/route/auth-options.js +14 -0
  110. package/dist/route/auth.d.ts +49 -0
  111. package/dist/route/auth.js +89 -0
  112. package/dist/route/client.d.ts +330 -0
  113. package/dist/route/client.js +211 -0
  114. package/dist/route/endpoint.d.ts +28 -0
  115. package/dist/route/endpoint.js +21 -0
  116. package/dist/route/executor.d.ts +12 -0
  117. package/dist/route/executor.js +229 -0
  118. package/dist/route/framing.d.ts +23 -0
  119. package/dist/route/framing.js +4 -0
  120. package/dist/route/index.d.ts +16 -0
  121. package/dist/route/index.js +9 -0
  122. package/dist/route/protocol.d.ts +76 -0
  123. package/dist/route/protocol.js +17 -0
  124. package/dist/route/transport/http.d.ts +33 -0
  125. package/dist/route/transport/http.js +98 -0
  126. package/dist/route/transport/index.d.ts +27 -0
  127. package/dist/route/transport/index.js +4 -0
  128. package/dist/route/transport/websocket.d.ts +56 -0
  129. package/dist/route/transport/websocket.js +181 -0
  130. package/dist/route.d.ts +1 -0
  131. package/dist/route.js +1 -0
  132. package/dist/schema/errors.d.ts +153 -0
  133. package/dist/schema/errors.js +150 -0
  134. package/dist/schema/events.d.ts +4292 -0
  135. package/dist/schema/events.js +482 -0
  136. package/dist/schema/ids.d.ts +30 -0
  137. package/dist/schema/ids.js +18 -0
  138. package/dist/schema/index.d.ts +5 -0
  139. package/dist/schema/index.js +5 -0
  140. package/dist/schema/messages.d.ts +385 -0
  141. package/dist/schema/messages.js +246 -0
  142. package/dist/schema/options.d.ts +143 -0
  143. package/dist/schema/options.js +195 -0
  144. package/dist/tool-runtime.d.ts +15 -0
  145. package/dist/tool-runtime.js +35 -0
  146. package/dist/tool.d.ts +134 -0
  147. package/dist/tool.js +66 -0
  148. package/dist/utils/record.d.ts +2 -0
  149. package/dist/utils/record.js +2 -0
  150. package/package.json +36 -9
  151. package/index.js +0 -1
@@ -0,0 +1,181 @@
1
+ import type { RouteDefaultsInput } from "../route/client";
2
+ import type { ProviderAuthOption } from "../route/auth-options";
3
+ import type { ProviderPackage } from "../provider-package";
4
+ import { type ModelID } from "../schema";
5
+ export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
6
+ export declare const routes: import("../route").Route<{
7
+ readonly model: string;
8
+ readonly messages: readonly ({
9
+ readonly role: "user";
10
+ readonly content: readonly ({
11
+ readonly type: "text";
12
+ readonly text: string;
13
+ readonly cache_control?: {
14
+ readonly type: "ephemeral";
15
+ readonly ttl?: "1h" | "5m" | undefined;
16
+ } | undefined;
17
+ } | {
18
+ readonly type: "image";
19
+ readonly source: {
20
+ readonly type: "base64";
21
+ readonly media_type: string;
22
+ readonly data: string;
23
+ };
24
+ readonly cache_control?: {
25
+ readonly type: "ephemeral";
26
+ readonly ttl?: "1h" | "5m" | undefined;
27
+ } | undefined;
28
+ } | {
29
+ readonly type: "tool_result";
30
+ readonly tool_use_id: string;
31
+ readonly content: string | readonly ({
32
+ readonly type: "text";
33
+ readonly text: string;
34
+ readonly cache_control?: {
35
+ readonly type: "ephemeral";
36
+ readonly ttl?: "1h" | "5m" | undefined;
37
+ } | undefined;
38
+ } | {
39
+ readonly type: "image";
40
+ readonly source: {
41
+ readonly type: "base64";
42
+ readonly media_type: string;
43
+ readonly data: string;
44
+ };
45
+ readonly cache_control?: {
46
+ readonly type: "ephemeral";
47
+ readonly ttl?: "1h" | "5m" | undefined;
48
+ } | undefined;
49
+ })[];
50
+ readonly is_error?: boolean | undefined;
51
+ readonly cache_control?: {
52
+ readonly type: "ephemeral";
53
+ readonly ttl?: "1h" | "5m" | undefined;
54
+ } | undefined;
55
+ })[];
56
+ } | {
57
+ readonly role: "assistant";
58
+ readonly content: readonly ({
59
+ readonly type: "text";
60
+ readonly text: string;
61
+ readonly cache_control?: {
62
+ readonly type: "ephemeral";
63
+ readonly ttl?: "1h" | "5m" | undefined;
64
+ } | undefined;
65
+ } | {
66
+ readonly type: "tool_use";
67
+ readonly id: string;
68
+ readonly name: string;
69
+ readonly input: unknown;
70
+ readonly cache_control?: {
71
+ readonly type: "ephemeral";
72
+ readonly ttl?: "1h" | "5m" | undefined;
73
+ } | undefined;
74
+ } | {
75
+ readonly type: "server_tool_use";
76
+ readonly id: string;
77
+ readonly name: string;
78
+ readonly input: unknown;
79
+ readonly cache_control?: {
80
+ readonly type: "ephemeral";
81
+ readonly ttl?: "1h" | "5m" | undefined;
82
+ } | undefined;
83
+ } | {
84
+ readonly type: "web_search_tool_result" | "code_execution_tool_result" | "web_fetch_tool_result";
85
+ readonly tool_use_id: string;
86
+ readonly content: unknown;
87
+ readonly cache_control?: {
88
+ readonly type: "ephemeral";
89
+ readonly ttl?: "1h" | "5m" | undefined;
90
+ } | undefined;
91
+ } | {
92
+ readonly type: "thinking";
93
+ readonly thinking: string;
94
+ readonly signature?: string | undefined;
95
+ readonly cache_control?: {
96
+ readonly type: "ephemeral";
97
+ readonly ttl?: "1h" | "5m" | undefined;
98
+ } | undefined;
99
+ })[];
100
+ } | {
101
+ readonly role: "system";
102
+ readonly content: readonly {
103
+ readonly type: "text";
104
+ readonly text: string;
105
+ readonly cache_control?: {
106
+ readonly type: "ephemeral";
107
+ readonly ttl?: "1h" | "5m" | undefined;
108
+ } | undefined;
109
+ }[];
110
+ })[];
111
+ readonly stream: true;
112
+ readonly max_tokens: number;
113
+ readonly system?: readonly {
114
+ readonly type: "text";
115
+ readonly text: string;
116
+ readonly cache_control?: {
117
+ readonly type: "ephemeral";
118
+ readonly ttl?: "1h" | "5m" | undefined;
119
+ } | undefined;
120
+ }[] | undefined;
121
+ readonly tools?: readonly {
122
+ readonly name: string;
123
+ readonly description: string;
124
+ readonly input_schema: {
125
+ readonly [x: string]: unknown;
126
+ };
127
+ readonly cache_control?: {
128
+ readonly type: "ephemeral";
129
+ readonly ttl?: "1h" | "5m" | undefined;
130
+ } | undefined;
131
+ }[] | undefined;
132
+ readonly tool_choice?: {
133
+ readonly type: "auto" | "any";
134
+ } | {
135
+ readonly type: "tool";
136
+ readonly name: string;
137
+ } | undefined;
138
+ readonly temperature?: number | undefined;
139
+ readonly top_p?: number | undefined;
140
+ readonly top_k?: number | undefined;
141
+ readonly stop_sequences?: readonly string[] | undefined;
142
+ readonly thinking?: {
143
+ readonly type: "enabled";
144
+ readonly budget_tokens: number;
145
+ } | {
146
+ readonly type: "adaptive";
147
+ readonly display?: "summarized" | "omitted" | undefined;
148
+ } | {
149
+ readonly type: "disabled";
150
+ } | undefined;
151
+ readonly output_config?: {
152
+ readonly effort?: string | undefined;
153
+ } | undefined;
154
+ }, import("../route/transport/http").HttpPrepared<string>>[];
155
+ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
156
+ readonly baseURL?: string;
157
+ };
158
+ export type Settings = ProviderPackage.Settings & ({
159
+ readonly apiKey?: string;
160
+ readonly authToken?: never;
161
+ } | {
162
+ readonly apiKey?: never;
163
+ readonly authToken?: string;
164
+ }) & {
165
+ readonly baseURL?: string;
166
+ };
167
+ export declare const configure: (input?: Config) => {
168
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
169
+ model: (modelID: string | ModelID) => import("..").Model;
170
+ configure: (input?: Config) => /*elided*/ any;
171
+ };
172
+ export declare const provider: {
173
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
174
+ model: (modelID: string | ModelID) => import("..").Model;
175
+ configure: (input?: Config) => {
176
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
177
+ model: (modelID: string | ModelID) => import("..").Model;
178
+ configure: /*elided*/ any;
179
+ };
180
+ };
181
+ export declare const model: ProviderPackage.Definition<Settings>["model"];
@@ -0,0 +1,39 @@
1
+ import { Auth } from "../route/auth";
2
+ import { ProviderID } from "../schema";
3
+ import { AnthropicMessages } from "../protocols/anthropic-messages";
4
+ import { AnthropicCompatible } from "./anthropic-compatible";
5
+ export const id = ProviderID.make("anthropic");
6
+ export const routes = [AnthropicMessages.route];
7
+ const auth = (options) => {
8
+ if ("auth" in options && options.auth)
9
+ return options.auth;
10
+ return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
+ .orElse(Auth.config("ANTHROPIC_API_KEY"))
12
+ .pipe(Auth.header("x-api-key"));
13
+ };
14
+ export const configure = (input = {}) => {
15
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
16
+ const compatible = AnthropicCompatible.configure({
17
+ ...rest,
18
+ auth: auth(input),
19
+ baseURL: baseURL ?? AnthropicMessages.DEFAULT_BASE_URL,
20
+ provider: id,
21
+ });
22
+ return {
23
+ id,
24
+ model: (modelID) => compatible.model(modelID),
25
+ configure,
26
+ };
27
+ };
28
+ export const provider = configure();
29
+ export const model = (modelID, settings) => {
30
+ if (settings.apiKey !== undefined && settings.authToken !== undefined)
31
+ throw new Error("Anthropic apiKey cannot be combined with authToken");
32
+ return configure({
33
+ ...(settings.authToken === undefined ? { apiKey: settings.apiKey } : { auth: Auth.bearer(settings.authToken) }),
34
+ baseURL: settings.baseURL,
35
+ headers: settings.headers === undefined ? undefined : { ...settings.headers },
36
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
37
+ limits: settings.limits,
38
+ }).model(modelID);
39
+ };
@@ -0,0 +1,2 @@
1
+ export { chatModel as model } from "../azure";
2
+ export type { Settings } from "../azure";
@@ -0,0 +1 @@
1
+ export { chatModel as model } from "../azure";
@@ -0,0 +1,2 @@
1
+ export { responsesModel as model } from "../azure";
2
+ export type { Settings } from "../azure";
@@ -0,0 +1 @@
1
+ export { responsesModel as model } from "../azure";
@@ -0,0 +1,183 @@
1
+ import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options";
2
+ import type { Route as RouteDef, RouteDefaultsInput } from "../route/client";
3
+ import type { ProviderPackage } from "../provider-package";
4
+ import { type ModelID } from "../schema";
5
+ import { type OpenAIProviderOptionsInput } from "./openai-options";
6
+ export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
7
+ type AzureURL = AtLeastOne<{
8
+ readonly resourceName: string;
9
+ readonly baseURL: string;
10
+ }>;
11
+ export type ModelOptions = AzureURL & RouteDefaultsInput & ProviderAuthOption<"optional"> & {
12
+ readonly apiVersion?: string;
13
+ readonly queryParams?: Record<string, string>;
14
+ readonly useCompletionUrls?: boolean;
15
+ readonly providerOptions?: OpenAIProviderOptionsInput;
16
+ };
17
+ export type Config = ModelOptions;
18
+ export type Settings = ProviderPackage.Settings & AzureURL & {
19
+ readonly apiKey?: string;
20
+ readonly apiVersion?: string;
21
+ readonly queryParams?: Readonly<Record<string, string>>;
22
+ readonly providerOptions?: OpenAIProviderOptionsInput;
23
+ };
24
+ export declare const routes: (RouteDef<{
25
+ readonly model: string;
26
+ readonly messages: readonly ({
27
+ readonly role: "system";
28
+ readonly content: string;
29
+ } | {
30
+ readonly role: "user";
31
+ readonly content: string | readonly ({
32
+ readonly type: "text";
33
+ readonly text: string;
34
+ } | {
35
+ readonly type: "image_url";
36
+ readonly image_url: {
37
+ readonly url: string;
38
+ };
39
+ })[];
40
+ } | {
41
+ readonly role: "assistant";
42
+ readonly content: string | null;
43
+ readonly tool_calls?: readonly {
44
+ readonly id: string;
45
+ readonly type: "function";
46
+ readonly function: {
47
+ readonly name: string;
48
+ readonly arguments: string;
49
+ };
50
+ }[] | undefined;
51
+ readonly reasoning_content?: string | undefined;
52
+ } | {
53
+ readonly role: "tool";
54
+ readonly tool_call_id: string;
55
+ readonly content: string;
56
+ })[];
57
+ readonly stream: true;
58
+ readonly tools?: readonly {
59
+ readonly type: "function";
60
+ readonly function: {
61
+ readonly name: string;
62
+ readonly description: string;
63
+ readonly parameters: {
64
+ readonly [x: string]: unknown;
65
+ };
66
+ };
67
+ }[] | undefined;
68
+ readonly tool_choice?: "required" | "none" | "auto" | {
69
+ readonly type: "function";
70
+ readonly function: {
71
+ readonly name: string;
72
+ };
73
+ } | undefined;
74
+ readonly stream_options?: {
75
+ readonly include_usage: boolean;
76
+ } | undefined;
77
+ readonly store?: boolean | undefined;
78
+ readonly reasoning_effort?: string | undefined;
79
+ readonly max_tokens?: number | undefined;
80
+ readonly temperature?: number | undefined;
81
+ readonly top_p?: number | undefined;
82
+ readonly frequency_penalty?: number | undefined;
83
+ readonly presence_penalty?: number | undefined;
84
+ readonly seed?: number | undefined;
85
+ readonly stop?: readonly string[] | undefined;
86
+ }, import("../route/transport/http").HttpPrepared<string>> | RouteDef<{
87
+ readonly stream: true;
88
+ readonly model: string;
89
+ readonly input: readonly ({
90
+ readonly role: "system";
91
+ readonly content: string;
92
+ } | {
93
+ readonly role: "user";
94
+ readonly content: readonly ({
95
+ readonly type: "input_text";
96
+ readonly text: string;
97
+ } | {
98
+ readonly type: "input_image";
99
+ readonly image_url: string;
100
+ })[];
101
+ } | {
102
+ readonly role: "assistant";
103
+ readonly content: readonly {
104
+ readonly type: "output_text";
105
+ readonly text: string;
106
+ }[];
107
+ } | {
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 type: "function_call";
120
+ readonly call_id: string;
121
+ readonly name: string;
122
+ readonly arguments: string;
123
+ } | {
124
+ readonly type: "function_call_output";
125
+ readonly call_id: string;
126
+ readonly output: string | readonly ({
127
+ readonly type: "input_text";
128
+ readonly text: string;
129
+ } | {
130
+ readonly type: "input_image";
131
+ readonly image_url: string;
132
+ })[];
133
+ })[];
134
+ readonly instructions?: string | undefined;
135
+ readonly tools?: readonly {
136
+ readonly type: "function";
137
+ readonly name: string;
138
+ readonly description: string;
139
+ readonly parameters: {
140
+ readonly [x: string]: unknown;
141
+ };
142
+ readonly strict?: boolean | undefined;
143
+ }[] | undefined;
144
+ readonly tool_choice?: "required" | "none" | "auto" | {
145
+ readonly type: "function";
146
+ readonly name: string;
147
+ } | undefined;
148
+ readonly store?: boolean | undefined;
149
+ readonly service_tier?: "auto" | "default" | "flex" | "priority" | undefined;
150
+ readonly prompt_cache_key?: string | undefined;
151
+ 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;
152
+ readonly reasoning?: {
153
+ readonly effort?: string | undefined;
154
+ readonly summary?: "auto" | undefined;
155
+ } | undefined;
156
+ readonly text?: {
157
+ readonly verbosity?: "low" | "medium" | "high" | undefined;
158
+ } | undefined;
159
+ readonly max_output_tokens?: number | undefined;
160
+ readonly temperature?: number | undefined;
161
+ readonly top_p?: number | undefined;
162
+ }, import("../route/transport/http").HttpPrepared<string>>)[];
163
+ export declare const configure: (input: Config) => {
164
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
165
+ model: (modelID: string | ModelID) => import("..").Model;
166
+ responses: (modelID: string | ModelID) => import("..").Model;
167
+ chat: (modelID: string | ModelID) => import("..").Model;
168
+ configure: (input: Config) => /*elided*/ any;
169
+ };
170
+ export declare const provider: {
171
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
172
+ configure: (input: Config) => {
173
+ id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
174
+ model: (modelID: string | ModelID) => import("..").Model;
175
+ responses: (modelID: string | ModelID) => import("..").Model;
176
+ chat: (modelID: string | ModelID) => import("..").Model;
177
+ configure: /*elided*/ any;
178
+ };
179
+ };
180
+ export declare const responsesModel: ProviderPackage.Definition<Settings>["model"];
181
+ export declare const chatModel: ProviderPackage.Definition<Settings>["model"];
182
+ export declare const model: (modelID: string, settings: Settings) => import("..").Model;
183
+ export {};
@@ -0,0 +1,89 @@
1
+ import { Auth } from "../route/auth";
2
+ import {} from "../route/auth-options";
3
+ import { ProviderID } from "../schema";
4
+ import * as OpenAIChat from "../protocols/openai-chat";
5
+ import * as OpenAIResponses from "../protocols/openai-responses";
6
+ import { withOpenAIOptions } from "./openai-options";
7
+ export const id = ProviderID.make("azure");
8
+ const routeAuth = Auth.remove("authorization");
9
+ const resourceBaseURL = (resourceName) => `https://${resourceName.trim()}.openai.azure.com/openai/v1`;
10
+ const responsesRoute = OpenAIResponses.route.with({
11
+ id: "azure-openai-responses",
12
+ provider: id,
13
+ auth: routeAuth,
14
+ endpoint: {
15
+ query: { "api-version": "v1" },
16
+ },
17
+ });
18
+ const chatRoute = OpenAIChat.route.with({
19
+ id: "azure-openai-chat",
20
+ provider: id,
21
+ auth: routeAuth,
22
+ endpoint: {
23
+ query: { "api-version": "v1" },
24
+ },
25
+ });
26
+ export const routes = [responsesRoute, chatRoute];
27
+ const defaults = (input) => {
28
+ const { apiKey: _, apiVersion: _apiVersion, resourceName: _resourceName, useCompletionUrls: _useCompletionUrls, baseURL: _baseURL, queryParams: _queryParams, ...rest } = input;
29
+ if ("auth" in rest) {
30
+ const { auth: _, ...withoutAuth } = rest;
31
+ return withoutAuth;
32
+ }
33
+ return rest;
34
+ };
35
+ const auth = (input) => {
36
+ if ("auth" in input && input.auth)
37
+ return input.auth;
38
+ return Auth.remove("authorization").andThen(Auth.optional("apiKey" in input ? input.apiKey : undefined, "apiKey")
39
+ .orElse(Auth.config("AZURE_OPENAI_API_KEY"))
40
+ .pipe(Auth.header("api-key")));
41
+ };
42
+ const configuredRoute = (route, input) => route.with({
43
+ auth: auth(input),
44
+ endpoint: {
45
+ // AtLeastOne guarantees at least one is set; baseURL wins if both are.
46
+ baseURL: input.baseURL ?? resourceBaseURL(input.resourceName),
47
+ query: {
48
+ ...(input.apiVersion ? { "api-version": input.apiVersion } : {}),
49
+ ...input.queryParams,
50
+ },
51
+ },
52
+ });
53
+ export const configure = (input) => {
54
+ const configuredResponsesRoute = configuredRoute(responsesRoute, input);
55
+ const configuredChatRoute = configuredRoute(chatRoute, input);
56
+ const modelDefaults = defaults(input);
57
+ const responses = (modelID) => configuredResponsesRoute.with(withOpenAIOptions(modelID, modelDefaults)).model({ id: modelID });
58
+ const chat = (modelID) => configuredChatRoute.with(withOpenAIOptions(modelID, modelDefaults)).model({ id: modelID });
59
+ return {
60
+ id,
61
+ model: (modelID) => (input.useCompletionUrls === true ? chat(modelID) : responses(modelID)),
62
+ responses,
63
+ chat,
64
+ configure,
65
+ };
66
+ };
67
+ export const provider = {
68
+ id,
69
+ configure,
70
+ };
71
+ const config = (settings) => {
72
+ const common = {
73
+ apiKey: settings.apiKey,
74
+ apiVersion: settings.apiVersion,
75
+ headers: settings.headers === undefined ? undefined : { ...settings.headers },
76
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
77
+ limits: settings.limits,
78
+ providerOptions: settings.providerOptions,
79
+ queryParams: settings.queryParams === undefined ? undefined : { ...settings.queryParams },
80
+ };
81
+ if (settings.baseURL !== undefined)
82
+ return { ...common, baseURL: settings.baseURL };
83
+ if (settings.resourceName !== undefined)
84
+ return { ...common, resourceName: settings.resourceName };
85
+ throw new Error("Azure requires resourceName or baseURL");
86
+ };
87
+ export const responsesModel = (modelID, settings) => configure(config(settings)).responses(modelID);
88
+ export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
89
+ export const model = responsesModel;