@opencode/ai 0.0.0-dev-482 → 0.0.0-dev-513

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 (96) hide show
  1. package/dist/effect.d.ts +1 -12
  2. package/dist/effect.js +1 -5
  3. package/dist/effort-updates.d.ts +2 -2
  4. package/dist/image-client.d.ts +4 -4
  5. package/dist/index.d.ts +1 -12
  6. package/dist/index.js +1 -5
  7. package/dist/protocols/alibaba-responses.js +8 -20
  8. package/dist/protocols/anthropic-messages.js +35 -89
  9. package/dist/protocols/bedrock-converse.js +2 -3
  10. package/dist/protocols/gemini.js +26 -40
  11. package/dist/protocols/meta-responses.js +1 -1
  12. package/dist/protocols/open-responses-channel.js +6 -19
  13. package/dist/protocols/open-responses-continuation.d.ts +1 -5
  14. package/dist/protocols/open-responses-continuation.js +1 -3
  15. package/dist/protocols/open-responses.js +1 -3
  16. package/dist/protocols/openai-compatible-chat.d.ts +1 -1
  17. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  18. package/dist/protocols/openai-responses.js +8 -26
  19. package/dist/protocols/utils/bedrock-cache.js +2 -5
  20. package/dist/protocols/utils/cache.d.ts +3 -0
  21. package/dist/protocols/utils/cache.js +15 -2
  22. package/dist/protocols/utils/image-sizing.d.ts +1 -1
  23. package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
  24. package/dist/protocols/utils/responses-hosted-tools.js +31 -0
  25. package/dist/protocols/utils/tool-stream.d.ts +3 -209
  26. package/dist/protocols/utils/tool-stream.js +3 -13
  27. package/dist/protocols/xai-responses.js +4 -24
  28. package/dist/providers/baseten.d.ts +1 -1
  29. package/dist/providers/baseten.js +7 -21
  30. package/dist/providers/cerebras.d.ts +1 -1
  31. package/dist/providers/cerebras.js +3 -14
  32. package/dist/providers/cloudflare-ai-gateway.js +5 -25
  33. package/dist/providers/cloudflare-shared.d.ts +9 -0
  34. package/dist/providers/cloudflare-shared.js +25 -0
  35. package/dist/providers/cloudflare-workers-ai.js +4 -20
  36. package/dist/providers/cohere/chat.js +2 -7
  37. package/dist/providers/cohere.d.ts +1 -1
  38. package/dist/providers/cohere.js +5 -12
  39. package/dist/providers/deepinfra.d.ts +1 -1
  40. package/dist/providers/deepinfra.js +4 -12
  41. package/dist/providers/deepseek.d.ts +1 -1
  42. package/dist/providers/deepseek.js +3 -14
  43. package/dist/providers/digitalocean.d.ts +1 -1
  44. package/dist/providers/digitalocean.js +5 -7
  45. package/dist/providers/fireworks.d.ts +1 -1
  46. package/dist/providers/fireworks.js +3 -14
  47. package/dist/providers/google/interactions.js +2 -7
  48. package/dist/providers/google-vertex-chat.js +3 -29
  49. package/dist/providers/google-vertex-messages.js +3 -29
  50. package/dist/providers/google-vertex-mistral.js +3 -29
  51. package/dist/providers/google-vertex-responses.js +3 -29
  52. package/dist/providers/google-vertex-shared.d.ts +30 -0
  53. package/dist/providers/google-vertex-shared.js +25 -0
  54. package/dist/providers/google.js +3 -11
  55. package/dist/providers/groq.d.ts +1 -1
  56. package/dist/providers/groq.js +3 -14
  57. package/dist/providers/meta.d.ts +1 -1
  58. package/dist/providers/meta.js +6 -20
  59. package/dist/providers/minimax/chat.js +2 -7
  60. package/dist/providers/minimax/responses.js +2 -7
  61. package/dist/providers/minimax.d.ts +1 -1
  62. package/dist/providers/minimax.js +5 -20
  63. package/dist/providers/mistral.d.ts +1 -1
  64. package/dist/providers/mistral.js +3 -14
  65. package/dist/providers/moonshot/messages.js +2 -7
  66. package/dist/providers/moonshot/responses.js +2 -7
  67. package/dist/providers/moonshot.d.ts +1 -1
  68. package/dist/providers/moonshot.js +3 -14
  69. package/dist/providers/openai-compatible-responses.js +2 -8
  70. package/dist/providers/openai-compatible.js +3 -9
  71. package/dist/providers/opencode.d.ts +1 -1
  72. package/dist/providers/opencode.js +5 -1
  73. package/dist/providers/openrouter.d.ts +1 -1
  74. package/dist/providers/openrouter.js +9 -20
  75. package/dist/providers/settings.d.ts +40 -0
  76. package/dist/providers/settings.js +19 -0
  77. package/dist/providers/togetherai.d.ts +1 -1
  78. package/dist/providers/togetherai.js +3 -14
  79. package/dist/providers/typesafe-ai.d.ts +1 -1
  80. package/dist/providers/typesafe-ai.js +5 -1
  81. package/dist/providers/vercel-ai-gateway.d.ts +1 -1
  82. package/dist/providers/vercel-ai-gateway.js +8 -22
  83. package/dist/providers/xai.js +3 -11
  84. package/dist/providers/zai-coding-plan/messages.js +2 -7
  85. package/dist/providers/zai-coding-plan/responses.js +2 -7
  86. package/dist/providers/zai-coding-plan.d.ts +1 -1
  87. package/dist/providers/zai-coding-plan.js +3 -14
  88. package/dist/providers/zai.d.ts +1 -1
  89. package/dist/providers/zai.js +6 -22
  90. package/dist/public.d.ts +12 -0
  91. package/dist/public.js +5 -0
  92. package/dist/schema/events.js +31 -64
  93. package/dist/speech-client.d.ts +4 -4
  94. package/dist/transcription-client.d.ts +4 -4
  95. package/dist/video-client.d.ts +4 -4
  96. package/package.json +3 -3
@@ -249,29 +249,10 @@ const hostedToolResult = Effect.fnUntraced(function* (item) {
249
249
  return isError ? { type: "error", value: item.error } : { type: "json", value: item };
250
250
  });
251
251
  const HOSTED_TOOLS = {
252
- web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
252
+ ...ResponsesHostedTools.common,
253
253
  web_search_preview_call: { name: "web_search_preview", input: (item) => item.action ?? {} },
254
- file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
255
- code_interpreter_call: {
256
- name: "code_interpreter",
257
- input: (item) => ({ code: item.code, container_id: item.container_id }),
258
- },
259
254
  computer_call: { name: "computer_use", input: (item) => item.action ?? {} },
260
255
  image_generation_call: { name: "image_generation", input: () => ({}), result: hostedToolResult },
261
- mcp_call: {
262
- name: "mcp",
263
- input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
264
- },
265
- };
266
- const step = (state, input) => {
267
- const event = OpenResponses.normalize(state, input);
268
- if (event.type === "response.reasoning_text.delta")
269
- return event.item_id !== undefined
270
- ? Effect.succeed(OpenResponses.onReasoningDelta(state, event, event.item_id))
271
- : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
272
- if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
273
- return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
274
- return OpenResponses.step(state, event);
275
256
  };
276
257
  export const protocol = Protocol.make({
277
258
  id: ADAPTER,
@@ -279,12 +260,13 @@ export const protocol = Protocol.make({
279
260
  schema: OpenAIResponsesBody,
280
261
  from: fromRequest,
281
262
  },
282
- stream: {
283
- event: OpenResponses.protocol.stream.event,
284
- initial: (request) => OpenResponses.initial(request, adapter),
285
- step,
286
- terminal: OpenResponses.terminal,
287
- },
263
+ stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS, (state, event) => {
264
+ if (event.type !== "response.reasoning_text.delta")
265
+ return undefined;
266
+ return event.item_id !== undefined
267
+ ? Effect.succeed(OpenResponses.onReasoningDelta(state, event, event.item_id))
268
+ : ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
269
+ }),
288
270
  supportsEffortUpdates,
289
271
  });
290
272
  const endpoint = Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL });
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { CacheTTL } from "../../schema/index.js";
3
- import { newBreakpoints } from "./cache.js";
3
+ import { newBreakpoints, take } from "./cache.js";
4
4
  // Bedrock cache markers are positional: emit a `cachePoint` block immediately
5
5
  // after the content the caller wants treated as a cacheable prefix. Bedrock
6
6
  // accepts an optional `ttl` such as "5m" or "1h" on cachePoint.
@@ -40,11 +40,8 @@ export const block = (breakpoints, cache) => {
40
40
  return undefined;
41
41
  if (cache?.type !== "ephemeral" && cache?.type !== "persistent")
42
42
  return undefined;
43
- if (breakpoints.remaining <= 0) {
44
- breakpoints.dropped += 1;
43
+ if (!take(breakpoints))
45
44
  return undefined;
46
- }
47
- breakpoints.remaining -= 1;
48
45
  // Older Claude releases cache for five minutes only, so a one-hour request falls back to the default.
49
46
  const ttl = cache.ttl === "1h" && !breakpoints.ttl1h ? undefined : cache.ttl;
50
47
  return { cachePoint: { type: "default", ...(ttl === undefined ? {} : { ttl }) } };
@@ -1,9 +1,12 @@
1
+ import { Effect } from "effect";
1
2
  import type { CacheHint, CacheTTL } from "../../schema/index.js";
2
3
  export interface Breakpoints {
3
4
  remaining: number;
4
5
  dropped: number;
5
6
  }
6
7
  export declare const newBreakpoints: (cap: number) => Breakpoints;
8
+ export declare const take: (breakpoints: Breakpoints) => boolean;
9
+ export declare const warnDropped: (breakpoints: Breakpoints, protocol: string, cap: number) => Effect.Effect<void, never, never>;
7
10
  export declare const cacheControl: () => (cache: CacheHint | undefined) => {
8
11
  type: "ephemeral";
9
12
  ttl: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
@@ -1,10 +1,23 @@
1
+ // Shared counter and lifetime mapping for provider cache lowering.
2
+ import { Effect } from "effect";
1
3
  export const newBreakpoints = (cap) => ({ remaining: cap, dropped: 0 });
4
+ // Spends one breakpoint, or records it as dropped once the budget is gone.
5
+ export const take = (breakpoints) => {
6
+ if (breakpoints.remaining <= 0) {
7
+ breakpoints.dropped += 1;
8
+ return false;
9
+ }
10
+ breakpoints.remaining -= 1;
11
+ return true;
12
+ };
13
+ export const warnDropped = (breakpoints, protocol, cap) => breakpoints.dropped === 0
14
+ ? Effect.void
15
+ : Effect.logWarning(`${protocol}: dropped ${breakpoints.dropped} cache breakpoint(s); the API allows at most ${cap} per request.`);
2
16
  export const cacheControl = () => {
3
17
  const breakpoints = newBreakpoints(4);
4
18
  return (cache) => {
5
- if (cache === undefined || breakpoints.remaining === 0)
19
+ if (cache === undefined || !take(breakpoints))
6
20
  return undefined;
7
- breakpoints.remaining -= 1;
8
21
  return { type: "ephemeral", ttl: cache.ttl };
9
22
  };
10
23
  };
@@ -27,5 +27,5 @@ export declare const fit: (shape: Shape, limits: Limits) => Size;
27
27
  /** The listed size closest to the shape: nearest aspect ratio first, then nearest pixel count. */
28
28
  export declare const nearest: (shape: Shape, sizes: ReadonlyArray<Size>) => Size;
29
29
  /** Free width and height that must honor the shape; a size that misses it fails. */
30
- export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../effect.js").AIError, never> | Effect.Effect<Size, never, never>;
30
+ export declare const exact: (route: MediaProtocol.Identity, shape: Shape, limits: Limits) => Effect.Effect<undefined, never, never> | Effect.Effect<never, import("../../public.js").AIError, never> | Effect.Effect<Size, never, never>;
31
31
  export * as ImageSizing from "./image-sizing.js";
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { type AIError, type ToolResultPart } from "../../schema/index.js";
2
+ import { type AIError, type LLMRequest, type ToolResultPart } from "../../schema/index.js";
3
3
  import { OpenResponses } from "../open-responses.js";
4
4
  export type Item = OpenResponses.OutputItem & {
5
5
  readonly status?: string;
@@ -21,6 +21,102 @@ export interface Definition {
21
21
  readonly result?: (item: Item) => Effect.Effect<ToolResultPart["result"], AIError>;
22
22
  }
23
23
  export type Definitions = Readonly<Record<string, Definition>>;
24
+ /** Hosted tools that several Responses providers report with the same item shape. */
25
+ export declare const common: {
26
+ readonly web_search_call: {
27
+ readonly name: "web_search";
28
+ readonly input: (item: Item) => {};
29
+ };
30
+ readonly file_search_call: {
31
+ readonly name: "file_search";
32
+ readonly input: (item: Item) => {
33
+ queries: {};
34
+ };
35
+ };
36
+ readonly code_interpreter_call: {
37
+ readonly name: "code_interpreter";
38
+ readonly input: (item: Item) => {
39
+ code: string | undefined;
40
+ container_id: string | undefined;
41
+ };
42
+ };
43
+ readonly mcp_call: {
44
+ readonly name: "mcp";
45
+ readonly input: (item: Item) => {
46
+ server_label: string | undefined;
47
+ name: string | undefined;
48
+ arguments: string | undefined;
49
+ };
50
+ };
51
+ };
24
52
  export declare const isItem: <Tools extends Definitions>(item: OpenResponses.OutputItem, tools: Tools) => item is Item;
53
+ /**
54
+ * Responses stream that turns completed hosted tool items into a provider-executed
55
+ * tool call and result. `override` sees each normalized event first and may handle it.
56
+ */
57
+ export declare const stream: (adapter: OpenResponses.ProviderAdapter, tools: Definitions, override?: (state: OpenResponses.ParserState, event: OpenResponses.NormalizedEvent) => Effect.Effect<OpenResponses.StepResult, AIError> | undefined) => {
58
+ event: import("effect/Schema").Codec<{
59
+ readonly [x: string]: unknown;
60
+ readonly type: string;
61
+ readonly delta?: string | undefined;
62
+ readonly arguments?: string | undefined;
63
+ readonly text?: string | undefined;
64
+ readonly item_id?: string | undefined;
65
+ readonly output_index?: number | undefined;
66
+ readonly summary_index?: number | undefined;
67
+ readonly item?: {
68
+ readonly [x: string]: unknown;
69
+ readonly type: string;
70
+ readonly id?: string | undefined;
71
+ readonly call_id?: string | undefined;
72
+ readonly name?: string | undefined;
73
+ readonly namespace?: string | undefined;
74
+ readonly arguments?: string | undefined;
75
+ readonly encrypted_content?: string | null | undefined;
76
+ } | null | undefined;
77
+ readonly response?: {
78
+ readonly [x: string]: unknown;
79
+ readonly id?: string | undefined;
80
+ readonly service_tier?: string | null | undefined;
81
+ readonly incomplete_details?: {
82
+ readonly reason?: string | undefined;
83
+ } | null | undefined;
84
+ readonly output?: readonly {
85
+ readonly [x: string]: unknown;
86
+ readonly type: string;
87
+ readonly id?: string | undefined;
88
+ readonly call_id?: string | undefined;
89
+ readonly name?: string | undefined;
90
+ readonly namespace?: string | undefined;
91
+ readonly arguments?: string | undefined;
92
+ readonly encrypted_content?: string | null | undefined;
93
+ }[] | undefined;
94
+ readonly usage?: {
95
+ readonly [x: string]: unknown;
96
+ readonly input_tokens?: number | undefined;
97
+ readonly input_tokens_details?: {
98
+ readonly [x: string]: unknown;
99
+ readonly cached_tokens?: number | undefined;
100
+ readonly cache_write_tokens?: number | undefined;
101
+ } | null | undefined;
102
+ readonly output_tokens?: number | undefined;
103
+ readonly output_tokens_details?: {
104
+ readonly [x: string]: unknown;
105
+ readonly reasoning_tokens?: number | undefined;
106
+ } | null | undefined;
107
+ readonly total_tokens?: number | undefined;
108
+ } | null | undefined;
109
+ readonly error?: unknown;
110
+ } | undefined;
111
+ readonly code?: unknown;
112
+ readonly message?: unknown;
113
+ readonly error?: unknown;
114
+ readonly status?: unknown;
115
+ readonly status_code?: unknown;
116
+ }, string, never, never>;
117
+ initial: (request: LLMRequest) => OpenResponses.ParserState;
118
+ step: (state: OpenResponses.ParserState, input: OpenResponses.Event) => AIError | Effect.Effect<OpenResponses.StepResult, AIError, never>;
119
+ terminal: typeof OpenResponses.terminal;
120
+ };
25
121
  export declare const onDone: (state: OpenResponses.ParserState, item: Item, tools: Definitions) => Effect.Effect<OpenResponses.StepResult, AIError>;
26
122
  export * as ResponsesHostedTools from "./responses-hosted-tools.js";
@@ -2,7 +2,38 @@ import { Effect } from "effect";
2
2
  import { LLMEvent } from "../../schema/index.js";
3
3
  import { OpenResponses } from "../open-responses.js";
4
4
  import { Lifecycle } from "./lifecycle.js";
5
+ /** Hosted tools that several Responses providers report with the same item shape. */
6
+ export const common = {
7
+ web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
8
+ file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
9
+ code_interpreter_call: {
10
+ name: "code_interpreter",
11
+ input: (item) => ({ code: item.code, container_id: item.container_id }),
12
+ },
13
+ mcp_call: {
14
+ name: "mcp",
15
+ input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
16
+ },
17
+ };
5
18
  export const isItem = (item, tools) => item.type in tools;
19
+ /**
20
+ * Responses stream that turns completed hosted tool items into a provider-executed
21
+ * tool call and result. `override` sees each normalized event first and may handle it.
22
+ */
23
+ export const stream = (adapter, tools, override) => ({
24
+ event: OpenResponses.protocol.stream.event,
25
+ initial: (request) => OpenResponses.initial(request, adapter),
26
+ step: (state, input) => {
27
+ const event = OpenResponses.normalize(state, input);
28
+ const handled = override?.(state, event);
29
+ if (handled)
30
+ return handled;
31
+ if (event.type === "response.output_item.done" && event.item && isItem(event.item, tools))
32
+ return onDone(state, event.item, tools);
33
+ return OpenResponses.step(state, event);
34
+ },
35
+ terminal: OpenResponses.terminal,
36
+ });
6
37
  export const onDone = Effect.fnUntraced(function* (state, item, tools) {
7
38
  const tool = tools[item.type];
8
39
  if (!tool)
@@ -70,218 +70,12 @@ export declare const appendExisting: <K extends StreamKey>(route: string, tools:
70
70
  * from state, and reject malformed local arguments without repairing them.
71
71
  * Missing keys are a no-op because some providers emit stop events for
72
72
  * non-tool content blocks.
73
- */
74
- export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K) => Effect.Effect<{
75
- tools: Partial<Record<K, PendingTool>>;
76
- events?: undefined;
77
- } | {
78
- tools: Partial<Record<K, PendingTool>>;
79
- events: readonly ({
80
- readonly type: "step-start";
81
- readonly index: number;
82
- } | {
83
- readonly type: "raw";
84
- readonly data: unknown;
85
- } | {
86
- readonly type: "text-start";
87
- readonly id: string;
88
- readonly providerMetadata?: {
89
- readonly [x: string]: {
90
- readonly [x: string]: unknown;
91
- };
92
- } | undefined;
93
- } | {
94
- readonly type: "text-delta";
95
- readonly id: string;
96
- readonly text: string;
97
- readonly providerMetadata?: {
98
- readonly [x: string]: {
99
- readonly [x: string]: unknown;
100
- };
101
- } | undefined;
102
- } | {
103
- readonly type: "text-end";
104
- readonly id: string;
105
- readonly text?: string | undefined;
106
- readonly providerMetadata?: {
107
- readonly [x: string]: {
108
- readonly [x: string]: unknown;
109
- };
110
- } | undefined;
111
- } | {
112
- readonly type: "reasoning-start";
113
- readonly id: string;
114
- readonly providerMetadata?: {
115
- readonly [x: string]: {
116
- readonly [x: string]: unknown;
117
- };
118
- } | undefined;
119
- } | {
120
- readonly type: "reasoning-delta";
121
- readonly id: string;
122
- readonly text: string;
123
- readonly providerMetadata?: {
124
- readonly [x: string]: {
125
- readonly [x: string]: unknown;
126
- };
127
- } | undefined;
128
- } | {
129
- readonly type: "reasoning-end";
130
- readonly id: string;
131
- readonly text?: string | undefined;
132
- readonly providerMetadata?: {
133
- readonly [x: string]: {
134
- readonly [x: string]: unknown;
135
- };
136
- } | undefined;
137
- } | {
138
- readonly type: "tool-input-start";
139
- readonly id: string;
140
- readonly name: string;
141
- readonly namespace?: string | undefined;
142
- readonly providerExecuted?: boolean | undefined;
143
- readonly providerMetadata?: {
144
- readonly [x: string]: {
145
- readonly [x: string]: unknown;
146
- };
147
- } | undefined;
148
- } | {
149
- readonly type: "tool-input-delta";
150
- readonly id: string;
151
- readonly name: string;
152
- readonly namespace?: string | undefined;
153
- readonly text: string;
154
- readonly input?: unknown;
155
- } | {
156
- readonly type: "tool-input-end";
157
- readonly id: string;
158
- readonly name: string;
159
- readonly namespace?: string | undefined;
160
- readonly providerMetadata?: {
161
- readonly [x: string]: {
162
- readonly [x: string]: unknown;
163
- };
164
- } | undefined;
165
- } | {
166
- readonly type: "tool-input-error";
167
- readonly id: string;
168
- readonly name: string;
169
- readonly namespace?: string | undefined;
170
- readonly raw: string;
171
- } | {
172
- readonly type: "tool-call";
173
- readonly id: string;
174
- readonly name: string;
175
- readonly namespace?: string | undefined;
176
- readonly input: unknown;
177
- readonly providerExecuted?: boolean | undefined;
178
- readonly providerMetadata?: {
179
- readonly [x: string]: {
180
- readonly [x: string]: unknown;
181
- };
182
- } | undefined;
183
- } | {
184
- readonly type: "tool-result";
185
- readonly id: string;
186
- readonly name: string;
187
- readonly namespace?: string | undefined;
188
- readonly result: {
189
- readonly type: "json";
190
- readonly value: unknown;
191
- } | {
192
- readonly type: "text";
193
- readonly value: unknown;
194
- } | {
195
- readonly type: "error";
196
- readonly value: unknown;
197
- } | {
198
- readonly type: "content";
199
- readonly value: readonly ({
200
- readonly type: "text";
201
- readonly text: string;
202
- } | {
203
- readonly type: "file";
204
- readonly uri: string;
205
- readonly mime: string;
206
- readonly name?: string | undefined;
207
- })[];
208
- };
209
- readonly output?: {
210
- readonly structured: unknown;
211
- readonly content: readonly ({
212
- readonly type: "text";
213
- readonly text: string;
214
- } | {
215
- readonly type: "file";
216
- readonly uri: string;
217
- readonly mime: string;
218
- readonly name?: string | undefined;
219
- })[];
220
- } | undefined;
221
- readonly providerExecuted?: boolean | undefined;
222
- readonly providerMetadata?: {
223
- readonly [x: string]: {
224
- readonly [x: string]: unknown;
225
- };
226
- } | undefined;
227
- } | {
228
- readonly type: "step-finish";
229
- readonly index: number;
230
- readonly reason: {
231
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
232
- readonly raw?: string | undefined;
233
- readonly category?: string | undefined;
234
- readonly explanation?: string | undefined;
235
- };
236
- readonly usage?: import("../../schema/events.js").Usage | undefined;
237
- readonly providerMetadata?: {
238
- readonly [x: string]: {
239
- readonly [x: string]: unknown;
240
- };
241
- } | undefined;
242
- } | {
243
- readonly type: "finish";
244
- readonly reason: {
245
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
246
- readonly raw?: string | undefined;
247
- readonly category?: string | undefined;
248
- readonly explanation?: string | undefined;
249
- };
250
- readonly usage?: import("../../schema/events.js").Usage | undefined;
251
- readonly message?: import("../../schema/messages.js").Message | undefined;
252
- readonly providerMetadata?: {
253
- readonly [x: string]: {
254
- readonly [x: string]: unknown;
255
- };
256
- } | undefined;
257
- } | {
258
- readonly type: "media";
259
- readonly media: import("../../media.js").Asset;
260
- readonly providerMetadata?: {
261
- readonly [x: string]: {
262
- readonly [x: string]: unknown;
263
- };
264
- } | undefined;
265
- } | ({
266
- readonly type: "compaction";
267
- readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
268
- readonly id?: string | undefined;
269
- readonly encrypted?: string | undefined;
270
- readonly text?: string | null | undefined;
271
- } & ({
272
- readonly encrypted: string;
273
- readonly text?: never;
274
- } | {
275
- readonly text: string | null;
276
- readonly encrypted?: never;
277
- })))[];
278
- }, AIError, never>;
279
- /**
280
- * Finalize one pending tool call with an authoritative final input string.
73
+ *
74
+ * Pass `input` when the provider sends an authoritative final input string.
281
75
  * OpenAI Responses can send accumulated deltas and then repeat the completed
282
76
  * arguments on `response.output_item.done`; the final value wins.
283
77
  */
284
- export declare const finishWithInput: <K extends StreamKey>(route: string, tools: State<K>, key: K, input: string) => Effect.Effect<{
78
+ export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K, input?: string) => Effect.Effect<{
285
79
  tools: Partial<Record<K, PendingTool>>;
286
80
  events?: undefined;
287
81
  } | {
@@ -124,22 +124,12 @@ export const appendExisting = (route, tools, key, text, missingToolMessage) => a
124
124
  * from state, and reject malformed local arguments without repairing them.
125
125
  * Missing keys are a no-op because some providers emit stop events for
126
126
  * non-tool content blocks.
127
- */
128
- export const finish = (route, tools, key) => Effect.gen(function* () {
129
- const tool = tools[key];
130
- if (!tool)
131
- return { tools };
132
- return {
133
- tools: withoutTool(tools, key),
134
- events: finishEvents(tool, yield* toolCall(route, tool)),
135
- };
136
- });
137
- /**
138
- * Finalize one pending tool call with an authoritative final input string.
127
+ *
128
+ * Pass `input` when the provider sends an authoritative final input string.
139
129
  * OpenAI Responses can send accumulated deltas and then repeat the completed
140
130
  * arguments on `response.output_item.done`; the final value wins.
141
131
  */
142
- export const finishWithInput = (route, tools, key, input) => Effect.gen(function* () {
132
+ export const finish = (route, tools, key, input) => Effect.gen(function* () {
143
133
  const tool = tools[key];
144
134
  if (!tool)
145
135
  return { tools };
@@ -63,27 +63,12 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
63
63
  min_p: options.minP,
64
64
  };
65
65
  });
66
+ // Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
67
+ // handled by the baseline); only its hosted tool vocabulary differs.
66
68
  const HOSTED_TOOLS = {
67
- web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
69
+ ...ResponsesHostedTools.common,
68
70
  x_search_call: { name: "x_search", input: (item) => item.action ?? {} },
69
- file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
70
- code_interpreter_call: {
71
- name: "code_interpreter",
72
- input: (item) => ({ code: item.code, container_id: item.container_id }),
73
- },
74
71
  image_generation_call: { name: "image_generation", input: () => ({}) },
75
- mcp_call: {
76
- name: "mcp",
77
- input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
78
- },
79
- };
80
- // Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
81
- // handled by the baseline); only its hosted tool vocabulary differs.
82
- const step = (state, input) => {
83
- const event = OpenResponses.normalize(state, input);
84
- if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
85
- return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
86
- return OpenResponses.step(state, event);
87
72
  };
88
73
  export const protocol = Protocol.make({
89
74
  id: ADAPTER,
@@ -91,12 +76,7 @@ export const protocol = Protocol.make({
91
76
  schema: Body,
92
77
  from: fromRequest,
93
78
  },
94
- stream: {
95
- event: OpenResponses.protocol.stream.event,
96
- initial: (request) => OpenResponses.initial(request, adapter),
97
- step,
98
- terminal: OpenResponses.terminal,
99
- },
79
+ stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS),
100
80
  });
101
81
  export const compact = ResponsesCompaction.make(adapter, (request) => OpenResponses.lowerTools(ProviderShared.flattenTools(request.tools), adapter, OpenAIFreeform.tools(request)));
102
82
  export * as XAIResponses from "./xai-responses.js";
@@ -1,5 +1,5 @@
1
1
  import type { ProviderPackage } from "../provider-package.js";
2
- import { type ProviderAuthOption } from "../route/auth-options.js";
2
+ import type { ProviderAuthOption } from "../route/auth-options.js";
3
3
  import { Route, type RouteDefaultsInput } from "../route/client.js";
4
4
  import { type ModelID, type ProviderOptions } from "../schema/index.js";
5
5
  import type { OpenAIProviderOptionsInput } from "./openai-options.js";
@@ -1,11 +1,11 @@
1
1
  import { Effect } from "effect";
2
2
  import { OpenAIChat } from "../protocols/openai-chat.js";
3
3
  import { SystemOne } from "../protocols/system-one.js";
4
- import { AuthOptions } from "../route/auth-options.js";
5
4
  import { Route } from "../route/client.js";
6
5
  import { DecisionRoute } from "../route/decision.js";
7
6
  import { Endpoint } from "../route/endpoint.js";
8
7
  import { ProviderID } from "../schema/index.js";
8
+ import { bearerRouteDefaults, toConfig } from "./settings.js";
9
9
  export const id = ProviderID.make("baseten");
10
10
  const baseURL = "https://inference.baseten.co/v1";
11
11
  export const route = Route.make({
@@ -27,20 +27,15 @@ const decisionProtocol = DecisionRoute.protocol({
27
27
  },
28
28
  });
29
29
  export const configure = (input = {}) => {
30
- const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input;
31
- const auth = AuthOptions.bearer(input, "BASETEN_API_KEY");
32
- const configured = route.with({
33
- ...defaults,
34
- endpoint: { baseURL: endpoint ?? baseURL },
35
- auth,
36
- });
30
+ const options = bearerRouteDefaults(input, "BASETEN_API_KEY", baseURL);
31
+ const configured = route.with(options);
37
32
  const decisionRoute = DecisionRoute.make({
38
33
  id: decisionProtocol.id,
39
34
  provider: id,
40
35
  providerMetadataKey: "baseten",
41
36
  protocol: decisionProtocol,
42
- endpoint: Endpoint.path("/systemone", { baseURL: endpoint ?? baseURL }),
43
- auth,
37
+ endpoint: Endpoint.path("/systemone", { baseURL: options.endpoint.baseURL }),
38
+ auth: options.auth,
44
39
  headers: input.headers,
45
40
  http: input.http,
46
41
  });
@@ -54,18 +49,9 @@ export const configure = (input = {}) => {
54
49
  };
55
50
  export const provider = configure();
56
51
  export const decision = provider.decision;
57
- export const model = (modelID, settings) => configure(config(settings)).model(modelID);
52
+ export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
58
53
  export const decisionModel = (modelID, settings) => {
59
- const input = config(settings);
54
+ const input = toConfig(settings);
60
55
  return configure(input).decision(modelID, input.providerOptions);
61
56
  };
62
- function config({ apiKey, baseURL, body, headers, ...providerOptions } = {}) {
63
- return {
64
- apiKey,
65
- baseURL,
66
- headers,
67
- http: body === undefined ? undefined : { body },
68
- providerOptions,
69
- };
70
- }
71
57
  export * as Baseten from "./baseten.js";
@@ -1,5 +1,5 @@
1
1
  import type { ProviderPackage } from "../provider-package.js";
2
- import { type ProviderAuthOption } from "../route/auth-options.js";
2
+ import type { ProviderAuthOption } from "../route/auth-options.js";
3
3
  import { Route, type RouteDefaultsInput } from "../route/client.js";
4
4
  import { type ModelID } from "../schema/index.js";
5
5
  import type { OpenAIProviderOptionsInput } from "./openai-options.js";