@opencode/ai 2.0.22 → 2.0.23

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 (92) hide show
  1. package/README.md +61 -1
  2. package/dist/cache-policy.js +1 -0
  3. package/dist/protocols/alibaba-chat.d.ts +3 -3
  4. package/dist/protocols/alibaba-responses.d.ts +16 -12
  5. package/dist/protocols/alibaba-responses.js +3 -5
  6. package/dist/protocols/anthropic-messages.js +44 -39
  7. package/dist/protocols/bedrock-converse.js +3 -3
  8. package/dist/protocols/cartesia-speech.js +3 -3
  9. package/dist/protocols/cohere-chat.d.ts +178 -0
  10. package/dist/protocols/cohere-chat.js +299 -0
  11. package/dist/protocols/elevenlabs-speech.js +3 -3
  12. package/dist/protocols/gemini.d.ts +2 -2
  13. package/dist/protocols/gemini.js +3 -3
  14. package/dist/protocols/google-interactions.d.ts +236 -0
  15. package/dist/protocols/google-interactions.js +478 -0
  16. package/dist/protocols/google-speech.js +1 -1
  17. package/dist/protocols/google-transcription.js +1 -1
  18. package/dist/protocols/index.d.ts +2 -0
  19. package/dist/protocols/index.js +2 -0
  20. package/dist/protocols/meta-responses.d.ts +31 -58
  21. package/dist/protocols/meta-responses.js +8 -27
  22. package/dist/protocols/mistral-chat.d.ts +24 -9
  23. package/dist/protocols/mistral-chat.js +22 -10
  24. package/dist/protocols/open-responses.d.ts +406 -91
  25. package/dist/protocols/open-responses.js +25 -15
  26. package/dist/protocols/openai-chat.d.ts +401 -5
  27. package/dist/protocols/openai-chat.js +18 -21
  28. package/dist/protocols/openai-compatible-chat.d.ts +1 -1
  29. package/dist/protocols/openai-compatible-responses.d.ts +16 -4
  30. package/dist/protocols/openai-images.js +2 -2
  31. package/dist/protocols/openai-responses.d.ts +87 -223
  32. package/dist/protocols/openai-responses.js +6 -13
  33. package/dist/protocols/openai-speech.js +1 -1
  34. package/dist/protocols/openai-transcription.js +1 -1
  35. package/dist/protocols/shared.js +2 -2
  36. package/dist/protocols/stability-images.js +1 -1
  37. package/dist/protocols/utils/bedrock-media.js +2 -2
  38. package/dist/protocols/utils/responses-checkpoint.js +2 -2
  39. package/dist/protocols/utils/responses-hosted-tools.js +1 -1
  40. package/dist/protocols/utils/tool-stream.js +15 -7
  41. package/dist/protocols/venice-chat.d.ts +280 -0
  42. package/dist/protocols/venice-chat.js +283 -0
  43. package/dist/protocols/xai-responses.d.ts +18 -21
  44. package/dist/protocols/xai-responses.js +2 -8
  45. package/dist/protocols/zai-chat.d.ts +3 -3
  46. package/dist/provider-error.js +7 -1
  47. package/dist/providers/alibaba.d.ts +17 -13
  48. package/dist/providers/amazon-bedrock/mantle/messages.d.ts +2 -0
  49. package/dist/providers/amazon-bedrock/mantle/messages.js +1 -0
  50. package/dist/providers/amazon-bedrock-mantle.d.ts +301 -9
  51. package/dist/providers/amazon-bedrock-mantle.js +28 -3
  52. package/dist/providers/azure.d.ts +13 -61
  53. package/dist/providers/baseten.d.ts +2 -2
  54. package/dist/providers/cerebras.d.ts +2 -2
  55. package/dist/providers/cloudflare-ai-gateway.d.ts +14 -62
  56. package/dist/providers/cloudflare-workers-ai.d.ts +2 -2
  57. package/dist/providers/cohere/chat.d.ts +4 -0
  58. package/dist/providers/cohere/chat.js +8 -0
  59. package/dist/providers/cohere.d.ts +395 -0
  60. package/dist/providers/cohere.js +48 -0
  61. package/dist/providers/deepinfra.d.ts +2 -2
  62. package/dist/providers/deepseek.d.ts +2 -2
  63. package/dist/providers/digitalocean.d.ts +5 -5
  64. package/dist/providers/fireworks.d.ts +2 -2
  65. package/dist/providers/google/interactions.d.ts +7 -0
  66. package/dist/providers/google/interactions.js +8 -0
  67. package/dist/providers/google-vertex-chat.d.ts +1 -1
  68. package/dist/providers/google-vertex-responses.d.ts +16 -4
  69. package/dist/providers/google-vertex.d.ts +1 -1
  70. package/dist/providers/google.d.ts +95 -4
  71. package/dist/providers/google.js +8 -1
  72. package/dist/providers/groq.d.ts +4 -4
  73. package/dist/providers/index.d.ts +2 -0
  74. package/dist/providers/index.js +2 -0
  75. package/dist/providers/meta.d.ts +15 -28
  76. package/dist/providers/minimax.d.ts +17 -5
  77. package/dist/providers/mistral.d.ts +10 -4
  78. package/dist/providers/moonshot.d.ts +17 -5
  79. package/dist/providers/openai-compatible-responses.d.ts +16 -4
  80. package/dist/providers/openai-compatible.d.ts +1 -1
  81. package/dist/providers/openai-options.d.ts +1 -1
  82. package/dist/providers/openai.d.ts +7 -31
  83. package/dist/providers/openrouter.d.ts +5 -5
  84. package/dist/providers/togetherai.d.ts +2 -2
  85. package/dist/providers/venice.d.ts +183 -0
  86. package/dist/providers/venice.js +38 -0
  87. package/dist/providers/xai.d.ts +1 -1
  88. package/dist/providers/zai-coding-plan.d.ts +17 -5
  89. package/dist/providers/zai.d.ts +1 -1
  90. package/dist/route/client.js +2 -5
  91. package/dist/route/framing.js +23 -23
  92. package/package.json +3 -3
@@ -121,8 +121,13 @@ export const ConfigurationUpdate = Schema.Struct({
121
121
  type: Schema.Literal("configuration_update"),
122
122
  reasoning: Schema.Struct({ effort: OpenResponsesOptions.ReasoningEffort }),
123
123
  });
124
+ export const HostedToolReplay = Schema.StructWithRest(Schema.Struct({
125
+ type: Schema.String,
126
+ id: Schema.String,
127
+ }), [JsonObject]);
124
128
  export const InputItem = Schema.Union([
125
129
  CompactionItem,
130
+ ConfigurationUpdate,
126
131
  Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("system"), content: Schema.String }),
127
132
  Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("developer"), content: Schema.String }),
128
133
  Schema.Struct({
@@ -155,6 +160,7 @@ export const InputItem = Schema.Union([
155
160
  output: OpenResponsesFunctionCallOutput,
156
161
  }),
157
162
  HostedToolItem,
163
+ HostedToolReplay,
158
164
  ]);
159
165
  export const Tool = Schema.Struct({
160
166
  type: Schema.tag("function"),
@@ -163,6 +169,9 @@ export const Tool = Schema.Struct({
163
169
  parameters: JsonObject,
164
170
  strict: Schema.optional(Schema.Boolean),
165
171
  });
172
+ export const HostedTool = Schema.StructWithRest(Schema.Struct({
173
+ type: Schema.String,
174
+ }), [JsonObject]);
166
175
  export const ToolChoice = Schema.Union([
167
176
  Schema.Literals(["auto", "none", "required"]),
168
177
  Schema.Struct({ type: Schema.tag("function"), name: Schema.String }),
@@ -180,7 +189,7 @@ export const coreFields = {
180
189
  model: Schema.String,
181
190
  input: Schema.Array(InputItem),
182
191
  instructions: Schema.optional(Schema.String),
183
- tools: optionalArray(Tool),
192
+ tools: optionalArray(Schema.Union([Tool, HostedTool])),
184
193
  tool_choice: Schema.optional(ToolChoice),
185
194
  store: Schema.optional(Schema.Boolean),
186
195
  metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
@@ -208,7 +217,7 @@ export const coreFields = {
208
217
  presence_penalty: Schema.optional(Schema.Number),
209
218
  frequency_penalty: Schema.optional(Schema.Number),
210
219
  };
211
- const OpenResponsesBody = Schema.Struct({
220
+ export const OpenResponsesBody = Schema.Struct({
212
221
  ...coreFields,
213
222
  stream: Schema.Literal(true),
214
223
  });
@@ -280,7 +289,7 @@ const BASE_ADAPTER = { id: ADAPTER, name: NAME };
280
289
  // =============================================================================
281
290
  // Request Lowering
282
291
  // =============================================================================
283
- export const lowerTool = Effect.fn("OpenResponses.lowerTool")(function* (protocolName, tool) {
292
+ export const lowerTool = Effect.fnUntraced(function* (protocolName, tool) {
284
293
  if (tool.native !== undefined)
285
294
  return yield* ProviderShared.invalidRequest(`${protocolName} does not support provider-native tool ${tool.name}`);
286
295
  return {
@@ -334,12 +343,15 @@ const lowerReasoning = (part, providerMetadataKey) => {
334
343
  encrypted_content: encryptedContent,
335
344
  };
336
345
  };
337
- const lowerMedia = Effect.fn("OpenResponses.lowerMedia")(function* (part, request, adapter, target) {
346
+ const decodeImageDetail = ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesInputImage.fields.detail));
347
+ const decodeMessageMetadata = ProviderShared.validateWith(Schema.decodeUnknownEffect(MessageMetadata));
348
+ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter, target) {
338
349
  const media = part.media.inline();
339
350
  const providerMedia = adapter.lowerMedia?.({ part, media, request });
340
351
  if (providerMedia)
341
352
  return providerMedia;
342
- const detail = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesInputImage.fields.detail))(part.providerMetadata?.[metadataKey(request.model)]?.detail);
353
+ const rawDetail = part.providerMetadata?.[metadataKey(request.model)]?.detail;
354
+ const detail = rawDetail === undefined ? undefined : yield* decodeImageDetail(rawDetail);
343
355
  const mime = part.media.mediaType.toLowerCase();
344
356
  const url = ProviderShared.mediaUrl(part.media);
345
357
  const location = url ?? (yield* ProviderShared.requireInlineMedia(adapter.name, part.media)).dataUrl;
@@ -394,11 +406,12 @@ const lowerToolResultOutput = Effect.fnUntraced(function* (part, request, adapte
394
406
  return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, adapter));
395
407
  });
396
408
  const DEFAULT_EFFORT = "medium";
397
- const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (request, adapter) {
409
+ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
398
410
  const input = [];
399
411
  const providerMetadataKey = metadataKey(request.model);
400
412
  for (const message of request.messages) {
401
- const metadata = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Schema.UndefinedOr(MessageMetadata)))(message.providerMetadata?.[providerMetadataKey]);
413
+ const rawMetadata = message.providerMetadata?.[providerMetadataKey];
414
+ const metadata = rawMetadata === undefined ? undefined : yield* decodeMessageMetadata(rawMetadata);
402
415
  if (message.role === "system") {
403
416
  const update = effortUpdate(message);
404
417
  if (update) {
@@ -546,7 +559,7 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
546
559
  }
547
560
  return input;
548
561
  });
549
- export const lowerConversation = Effect.fn("OpenResponses.lowerConversation")(function* (request, adapter) {
562
+ export const lowerConversation = Effect.fnUntraced(function* (request, adapter) {
550
563
  const instructions = ProviderShared.joinText(request.system);
551
564
  return {
552
565
  model: request.model.id,
@@ -611,10 +624,7 @@ export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAd
611
624
  (request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
612
625
  };
613
626
  });
614
- const decodeBody = ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesBody));
615
- export const fromRequest = Effect.fn("OpenResponses.fromRequest")(function* (request) {
616
- return yield* decodeBody(yield* fromRequestWithAdapter(request, BASE_ADAPTER));
617
- });
627
+ export const fromRequest = (request) => fromRequestWithAdapter(request, BASE_ADAPTER);
618
628
  // =============================================================================
619
629
  // Stream Parsing
620
630
  // =============================================================================
@@ -892,7 +902,7 @@ const onReasoningSummaryPartDone = (state, event) => {
892
902
  NO_EVENTS,
893
903
  ];
894
904
  };
895
- const onFunctionCallArgumentsDelta = Effect.fn("OpenResponses.onFunctionCallArgumentsDelta")(function* (state, event) {
905
+ const onFunctionCallArgumentsDelta = Effect.fnUntraced(function* (state, event) {
896
906
  if (event.item_id === undefined)
897
907
  return [state, NO_EVENTS];
898
908
  const tool = state.tools[event.item_id];
@@ -917,7 +927,7 @@ const onFunctionCallArgumentsDelta = Effect.fn("OpenResponses.onFunctionCallArgu
917
927
  events.push(...result.events);
918
928
  return [{ ...state, lifecycle, tools: result.tools }, events];
919
929
  });
920
- const onOutputItemDone = Effect.fn("OpenResponses.onOutputItemDone")(function* (state, item) {
930
+ const onOutputItemDone = Effect.fnUntraced(function* (state, item) {
921
931
  if (!item)
922
932
  return [state, NO_EVENTS];
923
933
  if (item.type === "compaction") {
@@ -1045,7 +1055,7 @@ const onOutputItemDone = Effect.fn("OpenResponses.onOutputItemDone")(function* (
1045
1055
  }
1046
1056
  return [state, NO_EVENTS];
1047
1057
  });
1048
- const onResponseFinish = Effect.fn("OpenResponses.onResponseFinish")(function* (state, event) {
1058
+ const onResponseFinish = Effect.fnUntraced(function* (state, event) {
1049
1059
  let current = state;
1050
1060
  const events = [];
1051
1061
  if (event.type === "response.completed") {
@@ -18,6 +18,19 @@ declare const ExtraContent: Schema.Struct<{
18
18
  readonly thought_signature: Schema.String;
19
19
  }>;
20
20
  }>;
21
+ export declare const OpenAIChatAssistantToolCall: Schema.Struct<{
22
+ readonly id: Schema.String;
23
+ readonly type: Schema.tag<"function">;
24
+ readonly function: Schema.Struct<{
25
+ readonly name: Schema.String;
26
+ readonly arguments: Schema.String;
27
+ }>;
28
+ readonly extra_content: Schema.optional<Schema.Struct<{
29
+ readonly google: Schema.Struct<{
30
+ readonly thought_signature: Schema.String;
31
+ }>;
32
+ }>>;
33
+ }>;
21
34
  declare const ReasoningDetail: Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
22
35
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
23
36
  readonly format: Schema.optional<Schema.String>;
@@ -49,6 +62,88 @@ declare const ReasoningDetail: Schema.Union<readonly [Schema.StructWithRest<Sche
49
62
  readonly index: Schema.optional<Schema.Number>;
50
63
  }>]>;
51
64
  type ReasoningDetail = Schema.Schema.Type<typeof ReasoningDetail>;
65
+ export declare const OpenAIChatMessage: Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
66
+ readonly role: Schema.Literal<"system">;
67
+ readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
68
+ readonly type: Schema.Literal<"text">;
69
+ readonly text: Schema.String;
70
+ readonly cache_control: Schema.optional<Schema.Struct<{
71
+ readonly type: Schema.Literal<"ephemeral">;
72
+ readonly ttl: Schema.optional<Schema.String>;
73
+ }>>;
74
+ }>, Schema.Struct<{
75
+ readonly type: Schema.Literal<"image_url">;
76
+ readonly image_url: Schema.Struct<{
77
+ readonly url: Schema.String;
78
+ }>;
79
+ }>, Schema.Struct<{
80
+ readonly type: Schema.Literal<"file">;
81
+ readonly file: Schema.Struct<{
82
+ readonly filename: Schema.String;
83
+ readonly file_data: Schema.String;
84
+ }>;
85
+ }>]>>]>;
86
+ }>, Schema.Struct<{
87
+ readonly role: Schema.Literal<"user">;
88
+ readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
89
+ readonly type: Schema.Literal<"text">;
90
+ readonly text: Schema.String;
91
+ readonly cache_control: Schema.optional<Schema.Struct<{
92
+ readonly type: Schema.Literal<"ephemeral">;
93
+ readonly ttl: Schema.optional<Schema.String>;
94
+ }>>;
95
+ }>, Schema.Struct<{
96
+ readonly type: Schema.Literal<"image_url">;
97
+ readonly image_url: Schema.Struct<{
98
+ readonly url: Schema.String;
99
+ }>;
100
+ }>, Schema.Struct<{
101
+ readonly type: Schema.Literal<"file">;
102
+ readonly file: Schema.Struct<{
103
+ readonly filename: Schema.String;
104
+ readonly file_data: Schema.String;
105
+ }>;
106
+ }>]>>]>;
107
+ }>, Schema.StructWithRest<Schema.Struct<{
108
+ readonly role: Schema.Literal<"assistant">;
109
+ readonly content: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Struct<{
110
+ readonly type: Schema.Literal<"text">;
111
+ readonly text: Schema.String;
112
+ readonly cache_control: Schema.optional<Schema.Struct<{
113
+ readonly type: Schema.Literal<"ephemeral">;
114
+ readonly ttl: Schema.optional<Schema.String>;
115
+ }>>;
116
+ }>>]>>;
117
+ readonly tool_calls: Schema.optional<Schema.$Array<Schema.Struct<{
118
+ readonly id: Schema.String;
119
+ readonly type: Schema.tag<"function">;
120
+ readonly function: Schema.Struct<{
121
+ readonly name: Schema.String;
122
+ readonly arguments: Schema.String;
123
+ }>;
124
+ readonly extra_content: Schema.optional<Schema.Struct<{
125
+ readonly google: Schema.Struct<{
126
+ readonly thought_signature: Schema.String;
127
+ }>;
128
+ }>>;
129
+ }>>>;
130
+ readonly reasoning_content: Schema.optional<Schema.String>;
131
+ readonly reasoning: Schema.optional<Schema.String>;
132
+ readonly reasoning_text: Schema.optional<Schema.String>;
133
+ readonly reasoning_details: Schema.optional<Schema.Unknown>;
134
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
135
+ readonly role: Schema.Literal<"tool">;
136
+ readonly tool_call_id: Schema.String;
137
+ readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Struct<{
138
+ readonly type: Schema.Literal<"text">;
139
+ readonly text: Schema.String;
140
+ readonly cache_control: Schema.optional<Schema.Struct<{
141
+ readonly type: Schema.Literal<"ephemeral">;
142
+ readonly ttl: Schema.optional<Schema.String>;
143
+ }>>;
144
+ }>>]>;
145
+ }>]>;
146
+ type OpenAIChatMessage = Schema.Schema.Type<typeof OpenAIChatMessage>;
52
147
  export declare const bodyFields: {
53
148
  model: Schema.String;
54
149
  messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
@@ -288,6 +383,89 @@ declare const OpenAIChatBody: Schema.Struct<{
288
383
  stop: Schema.optional<Schema.$Array<Schema.String>>;
289
384
  }>;
290
385
  export type OpenAIChatBody = Schema.Schema.Type<typeof OpenAIChatBody>;
386
+ export declare const OpenAIChatUsage: Schema.StructWithRest<Schema.Struct<{
387
+ readonly prompt_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
388
+ readonly completion_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
389
+ readonly total_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
390
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
391
+ readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
392
+ readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
393
+ readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
394
+ readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
395
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
396
+ readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
397
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
398
+ readonly completion_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
399
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
400
+ readonly accepted_prediction_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
401
+ readonly rejected_prediction_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
402
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
403
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
404
+ export declare const OpenAIChatToolCallDelta: Schema.Struct<{
405
+ readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
406
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
407
+ readonly function: Schema.optional<Schema.NullOr<Schema.Struct<{
408
+ readonly name: Schema.optional<Schema.NullOr<Schema.String>>;
409
+ readonly arguments: Schema.optional<Schema.NullOr<Schema.String>>;
410
+ }>>>;
411
+ readonly extra_content: Schema.optional<Schema.NullOr<Schema.Unknown>>;
412
+ }>;
413
+ export declare const OpenAIChatDelta: Schema.StructWithRest<Schema.Struct<{
414
+ readonly content: Schema.optional<Schema.NullOr<Schema.String>>;
415
+ readonly refusal: Schema.optional<Schema.NullOr<Schema.String>>;
416
+ readonly reasoning_content: Schema.optional<Schema.NullOr<Schema.String>>;
417
+ readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
418
+ readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
419
+ readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
420
+ readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
421
+ readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
422
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
423
+ readonly function: Schema.optional<Schema.NullOr<Schema.Struct<{
424
+ readonly name: Schema.optional<Schema.NullOr<Schema.String>>;
425
+ readonly arguments: Schema.optional<Schema.NullOr<Schema.String>>;
426
+ }>>>;
427
+ readonly extra_content: Schema.optional<Schema.NullOr<Schema.Unknown>>;
428
+ }>>>>;
429
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
430
+ export declare const OpenAIChatChoice: Schema.StructWithRest<Schema.Struct<{
431
+ readonly delta: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
432
+ readonly content: Schema.optional<Schema.NullOr<Schema.String>>;
433
+ readonly refusal: Schema.optional<Schema.NullOr<Schema.String>>;
434
+ readonly reasoning_content: Schema.optional<Schema.NullOr<Schema.String>>;
435
+ readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
436
+ readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
437
+ readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
438
+ readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
439
+ readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
440
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
441
+ readonly function: Schema.optional<Schema.NullOr<Schema.Struct<{
442
+ readonly name: Schema.optional<Schema.NullOr<Schema.String>>;
443
+ readonly arguments: Schema.optional<Schema.NullOr<Schema.String>>;
444
+ }>>>;
445
+ readonly extra_content: Schema.optional<Schema.NullOr<Schema.Unknown>>;
446
+ }>>>>;
447
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
448
+ readonly finish_reason: Schema.optional<Schema.NullOr<Schema.String>>;
449
+ readonly native_finish_reason: Schema.optional<Schema.NullOr<Schema.String>>;
450
+ readonly usage: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
451
+ readonly prompt_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
452
+ readonly completion_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
453
+ readonly total_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
454
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
455
+ readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
456
+ readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
457
+ readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
458
+ readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
459
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
460
+ readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
461
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
462
+ readonly completion_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
463
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
464
+ readonly accepted_prediction_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
465
+ readonly rejected_prediction_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
466
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
467
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
468
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
291
469
  export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
292
470
  readonly choices: Schema.optional<Schema.NullOr<Schema.$Array<Schema.StructWithRest<Schema.Struct<{
293
471
  readonly delta: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
@@ -379,6 +557,8 @@ export interface ParserState {
379
557
  interface LoweringOptions {
380
558
  readonly cacheControl?: (cache: CacheHint | undefined) => OpenAIChatCacheControl | undefined;
381
559
  readonly toolCallID?: (id: string) => string;
560
+ /** Project provider-specific fields from the exact source, even when other messages are dropped during lowering. */
561
+ readonly assistant?: (source: LLMRequest["messages"][number], message: OpenAIChatMessage) => OpenAIChatMessage;
382
562
  }
383
563
  export declare const fromRequest: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
384
564
  readonly [x: string]: unknown;
@@ -623,6 +803,222 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
623
803
  } | undefined;
624
804
  stream: true;
625
805
  }, AIError, never>;
806
+ export declare const finishEvents: (state: ParserState) => Effect.Effect<(({
807
+ readonly type: "compaction";
808
+ readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
809
+ readonly id?: string | undefined;
810
+ readonly text?: string | null | undefined;
811
+ readonly encrypted?: string | undefined;
812
+ } & ({
813
+ readonly encrypted: string;
814
+ readonly text?: never;
815
+ } | {
816
+ readonly text: string | null;
817
+ readonly encrypted?: never;
818
+ })) | {
819
+ readonly type: "step-start";
820
+ readonly index: number;
821
+ } | {
822
+ readonly id: string;
823
+ readonly type: "text-start";
824
+ readonly providerMetadata?: {
825
+ readonly [x: string]: {
826
+ readonly [x: string]: unknown;
827
+ };
828
+ } | undefined;
829
+ } | {
830
+ readonly id: string;
831
+ readonly type: "text-delta";
832
+ readonly text: string;
833
+ readonly providerMetadata?: {
834
+ readonly [x: string]: {
835
+ readonly [x: string]: unknown;
836
+ };
837
+ } | undefined;
838
+ } | {
839
+ readonly id: string;
840
+ readonly type: "text-end";
841
+ readonly text?: string | undefined;
842
+ readonly providerMetadata?: {
843
+ readonly [x: string]: {
844
+ readonly [x: string]: unknown;
845
+ };
846
+ } | undefined;
847
+ } | {
848
+ readonly id: string;
849
+ readonly type: "reasoning-start";
850
+ readonly providerMetadata?: {
851
+ readonly [x: string]: {
852
+ readonly [x: string]: unknown;
853
+ };
854
+ } | undefined;
855
+ } | {
856
+ readonly id: string;
857
+ readonly type: "reasoning-delta";
858
+ readonly text: string;
859
+ readonly providerMetadata?: {
860
+ readonly [x: string]: {
861
+ readonly [x: string]: unknown;
862
+ };
863
+ } | undefined;
864
+ } | {
865
+ readonly id: string;
866
+ readonly type: "reasoning-end";
867
+ readonly text?: string | undefined;
868
+ readonly providerMetadata?: {
869
+ readonly [x: string]: {
870
+ readonly [x: string]: unknown;
871
+ };
872
+ } | undefined;
873
+ } | {
874
+ readonly id: string;
875
+ readonly type: "tool-input-start";
876
+ readonly name: string;
877
+ readonly providerMetadata?: {
878
+ readonly [x: string]: {
879
+ readonly [x: string]: unknown;
880
+ };
881
+ } | undefined;
882
+ readonly namespace?: string | undefined;
883
+ readonly providerExecuted?: boolean | undefined;
884
+ } | {
885
+ readonly id: string;
886
+ readonly type: "tool-input-delta";
887
+ readonly name: string;
888
+ readonly text: string;
889
+ readonly input?: unknown;
890
+ readonly namespace?: string | undefined;
891
+ } | {
892
+ readonly id: string;
893
+ readonly type: "tool-input-end";
894
+ readonly name: string;
895
+ readonly providerMetadata?: {
896
+ readonly [x: string]: {
897
+ readonly [x: string]: unknown;
898
+ };
899
+ } | undefined;
900
+ readonly namespace?: string | undefined;
901
+ } | {
902
+ readonly id: string;
903
+ readonly type: "tool-input-error";
904
+ readonly name: string;
905
+ readonly raw: string;
906
+ readonly namespace?: string | undefined;
907
+ } | {
908
+ readonly id: string;
909
+ readonly type: "tool-call";
910
+ readonly name: string;
911
+ readonly input: unknown;
912
+ readonly providerMetadata?: {
913
+ readonly [x: string]: {
914
+ readonly [x: string]: unknown;
915
+ };
916
+ } | undefined;
917
+ readonly namespace?: string | undefined;
918
+ readonly providerExecuted?: boolean | undefined;
919
+ } | {
920
+ readonly id: string;
921
+ readonly type: "tool-result";
922
+ readonly name: string;
923
+ readonly result: {
924
+ readonly type: "json";
925
+ readonly value: unknown;
926
+ } | {
927
+ readonly type: "text";
928
+ readonly value: unknown;
929
+ } | {
930
+ readonly type: "error";
931
+ readonly value: unknown;
932
+ } | {
933
+ readonly type: "content";
934
+ readonly value: readonly ({
935
+ readonly type: "text";
936
+ readonly text: string;
937
+ } | {
938
+ readonly type: "file";
939
+ readonly uri: string;
940
+ readonly mime: string;
941
+ readonly name?: string | undefined;
942
+ })[];
943
+ };
944
+ readonly output?: {
945
+ readonly structured: unknown;
946
+ readonly content: readonly ({
947
+ readonly type: "text";
948
+ readonly text: string;
949
+ } | {
950
+ readonly type: "file";
951
+ readonly uri: string;
952
+ readonly mime: string;
953
+ readonly name?: string | undefined;
954
+ })[];
955
+ } | undefined;
956
+ readonly providerMetadata?: {
957
+ readonly [x: string]: {
958
+ readonly [x: string]: unknown;
959
+ };
960
+ } | undefined;
961
+ readonly namespace?: string | undefined;
962
+ readonly providerExecuted?: boolean | undefined;
963
+ } | {
964
+ readonly id: string;
965
+ readonly type: "tool-error";
966
+ readonly message: string;
967
+ readonly name: string;
968
+ readonly error?: unknown;
969
+ readonly providerMetadata?: {
970
+ readonly [x: string]: {
971
+ readonly [x: string]: unknown;
972
+ };
973
+ } | undefined;
974
+ readonly namespace?: string | undefined;
975
+ } | {
976
+ readonly type: "media";
977
+ readonly media: import("../media.js").Asset;
978
+ readonly providerMetadata?: {
979
+ readonly [x: string]: {
980
+ readonly [x: string]: unknown;
981
+ };
982
+ } | undefined;
983
+ } | {
984
+ readonly type: "step-finish";
985
+ readonly reason: {
986
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
987
+ readonly raw?: string | undefined;
988
+ readonly category?: string | undefined;
989
+ readonly explanation?: string | undefined;
990
+ };
991
+ readonly index: number;
992
+ readonly providerMetadata?: {
993
+ readonly [x: string]: {
994
+ readonly [x: string]: unknown;
995
+ };
996
+ } | undefined;
997
+ readonly usage?: Usage | undefined;
998
+ } | {
999
+ readonly type: "finish";
1000
+ readonly reason: {
1001
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1002
+ readonly raw?: string | undefined;
1003
+ readonly category?: string | undefined;
1004
+ readonly explanation?: string | undefined;
1005
+ };
1006
+ readonly providerMetadata?: {
1007
+ readonly [x: string]: {
1008
+ readonly [x: string]: unknown;
1009
+ };
1010
+ } | undefined;
1011
+ readonly usage?: Usage | undefined;
1012
+ } | {
1013
+ readonly type: "provider-error";
1014
+ readonly message: string;
1015
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
1016
+ readonly providerMetadata?: {
1017
+ readonly [x: string]: {
1018
+ readonly [x: string]: unknown;
1019
+ };
1020
+ } | undefined;
1021
+ })[], AIError, never>;
626
1022
  /**
627
1023
  * The OpenAI Chat protocol — request body construction, body schema, and the
628
1024
  * streaming-event state machine. Reused by every route that speaks OpenAI Chat
@@ -743,9 +1139,9 @@ export declare const protocol: Protocol<{
743
1139
  readonly top_p?: number | undefined;
744
1140
  readonly frequency_penalty?: number | undefined;
745
1141
  readonly presence_penalty?: number | undefined;
1142
+ readonly store?: boolean | undefined;
746
1143
  readonly prompt_cache_key?: string | undefined;
747
1144
  readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
748
- readonly store?: boolean | undefined;
749
1145
  readonly stream_options?: {
750
1146
  readonly include_usage: boolean;
751
1147
  } | undefined;
@@ -761,9 +1157,9 @@ export declare const protocol: Protocol<{
761
1157
  readonly [x: string]: unknown;
762
1158
  readonly cache_read_input_tokens?: number | null | undefined;
763
1159
  readonly cached_tokens?: number | null | undefined;
1160
+ readonly total_tokens?: number | null | undefined;
764
1161
  readonly prompt_tokens?: number | null | undefined;
765
1162
  readonly completion_tokens?: number | null | undefined;
766
- readonly total_tokens?: number | null | undefined;
767
1163
  readonly prompt_tokens_details?: {
768
1164
  readonly [x: string]: unknown;
769
1165
  readonly cached_tokens?: number | null | undefined;
@@ -802,9 +1198,9 @@ export declare const protocol: Protocol<{
802
1198
  readonly [x: string]: unknown;
803
1199
  readonly cache_read_input_tokens?: number | null | undefined;
804
1200
  readonly cached_tokens?: number | null | undefined;
1201
+ readonly total_tokens?: number | null | undefined;
805
1202
  readonly prompt_tokens?: number | null | undefined;
806
1203
  readonly completion_tokens?: number | null | undefined;
807
- readonly total_tokens?: number | null | undefined;
808
1204
  readonly prompt_tokens_details?: {
809
1205
  readonly [x: string]: unknown;
810
1206
  readonly cached_tokens?: number | null | undefined;
@@ -938,9 +1334,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
938
1334
  readonly top_p?: number | undefined;
939
1335
  readonly frequency_penalty?: number | undefined;
940
1336
  readonly presence_penalty?: number | undefined;
1337
+ readonly store?: boolean | undefined;
941
1338
  readonly prompt_cache_key?: string | undefined;
942
1339
  readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
943
- readonly store?: boolean | undefined;
944
1340
  readonly stream_options?: {
945
1341
  readonly include_usage: boolean;
946
1342
  } | undefined;
@@ -1060,9 +1456,9 @@ export declare const route: Route<{
1060
1456
  readonly top_p?: number | undefined;
1061
1457
  readonly frequency_penalty?: number | undefined;
1062
1458
  readonly presence_penalty?: number | undefined;
1459
+ readonly store?: boolean | undefined;
1063
1460
  readonly prompt_cache_key?: string | undefined;
1064
1461
  readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
1065
- readonly store?: boolean | undefined;
1066
1462
  readonly stream_options?: {
1067
1463
  readonly include_usage: boolean;
1068
1464
  } | undefined;