@opencode-ai/ai 0.0.0-next-16093 → 0.0.0-next-16094

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.
package/dist/llm.d.ts CHANGED
@@ -176,7 +176,10 @@ export declare class GenerateObjectResponse<T> {
176
176
  } | undefined;
177
177
  } | {
178
178
  readonly type: "step-finish";
179
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
179
+ readonly reason: {
180
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
181
+ readonly raw?: string | undefined;
182
+ };
180
183
  readonly index: number;
181
184
  readonly providerMetadata?: {
182
185
  readonly [x: string]: {
@@ -186,7 +189,10 @@ export declare class GenerateObjectResponse<T> {
186
189
  readonly usage?: import("./schema").Usage | undefined;
187
190
  } | {
188
191
  readonly type: "finish";
189
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
192
+ readonly reason: {
193
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
194
+ readonly raw?: string | undefined;
195
+ };
190
196
  readonly providerMetadata?: {
191
197
  readonly [x: string]: {
192
198
  readonly [x: string]: unknown;
@@ -498,7 +498,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
498
498
  const mapFinishReason = (reason) => {
499
499
  if (reason === "end_turn" || reason === "stop_sequence" || reason === "pause_turn")
500
500
  return "stop";
501
- if (reason === "max_tokens")
501
+ if (reason === "max_tokens" || reason === "model_context_window_exceeded")
502
502
  return "length";
503
503
  if (reason === "tool_use")
504
504
  return "tool-calls";
@@ -701,7 +701,10 @@ const onMessageDelta = (state, event) => {
701
701
  const usage = mergeUsage(state.usage, mapUsage(event.usage));
702
702
  const events = [];
703
703
  const lifecycle = Lifecycle.finish(state.lifecycle, events, {
704
- reason: mapFinishReason(event.delta?.stop_reason),
704
+ reason: {
705
+ normalized: mapFinishReason(event.delta?.stop_reason),
706
+ raw: event.delta?.stop_reason ?? undefined,
707
+ },
705
708
  usage,
706
709
  providerMetadata: event.delta?.stop_sequence
707
710
  ? anthropicMetadata({ stopSequence: event.delta.stop_sequence })
@@ -1,7 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { Route } from "../route/client";
3
3
  import { Protocol } from "../route/protocol";
4
- import { Usage, type FinishReason } from "../schema";
4
+ import { Usage, type FinishReasonDetails } from "../schema";
5
5
  import { BedrockAuth } from "./utils/bedrock-auth";
6
6
  import { Lifecycle } from "./utils/lifecycle";
7
7
  import { ToolStream } from "./utils/tool-stream";
@@ -127,7 +127,7 @@ export type BedrockConverseBody = Schema.Schema.Type<typeof BedrockConverseBody>
127
127
  interface ParserState {
128
128
  readonly tools: ToolStream.State<number>;
129
129
  readonly pendingFinish: {
130
- readonly reason: FinishReason;
130
+ readonly reason: FinishReasonDetails;
131
131
  readonly usage?: Usage;
132
132
  } | undefined;
133
133
  readonly hasToolCalls: boolean;
@@ -336,12 +336,14 @@ const fromRequest = Effect.fn("BedrockConverse.fromRequest")(function* (request)
336
336
  const mapFinishReason = (reason) => {
337
337
  if (reason === "end_turn" || reason === "stop_sequence")
338
338
  return "stop";
339
- if (reason === "max_tokens")
339
+ if (reason === "max_tokens" || reason === "model_context_window_exceeded")
340
340
  return "length";
341
341
  if (reason === "tool_use")
342
342
  return "tool-calls";
343
343
  if (reason === "content_filtered" || reason === "guardrail_intervened")
344
344
  return "content-filter";
345
+ if (reason === "malformed_model_output" || reason === "malformed_tool_use")
346
+ return "error";
345
347
  return "unknown";
346
348
  };
347
349
  // AWS reports inputTokens separately from cache reads and writes.
@@ -447,14 +449,29 @@ const step = (state, event) => Effect.gen(function* () {
447
449
  return [
448
450
  {
449
451
  ...state,
450
- pendingFinish: { reason: mapFinishReason(event.messageStop.stopReason), usage: state.pendingFinish?.usage },
452
+ pendingFinish: {
453
+ reason: {
454
+ normalized: mapFinishReason(event.messageStop.stopReason),
455
+ raw: event.messageStop.stopReason,
456
+ },
457
+ usage: state.pendingFinish?.usage,
458
+ },
451
459
  },
452
460
  [],
453
461
  ];
454
462
  }
455
463
  if (event.metadata) {
456
464
  const usage = mapUsage(event.metadata.usage);
457
- return [{ ...state, pendingFinish: { reason: state.pendingFinish?.reason ?? "stop", usage } }, []];
465
+ return [
466
+ {
467
+ ...state,
468
+ pendingFinish: {
469
+ reason: state.pendingFinish?.reason ?? { normalized: "stop" },
470
+ usage,
471
+ },
472
+ },
473
+ [],
474
+ ];
458
475
  }
459
476
  const exception = [
460
477
  ["internalServerException", event.internalServerException],
@@ -480,7 +497,12 @@ const onHalt = (state) => state.pendingFinish
480
497
  ? (() => {
481
498
  const events = [];
482
499
  Lifecycle.finish(state.lifecycle, events, {
483
- reason: state.pendingFinish.reason === "stop" && state.hasToolCalls ? "tool-calls" : state.pendingFinish.reason,
500
+ reason: {
501
+ ...state.pendingFinish.reason,
502
+ normalized: state.pendingFinish.reason.normalized === "stop" && state.hasToolCalls
503
+ ? "tool-calls"
504
+ : state.pendingFinish.reason.normalized,
505
+ },
484
506
  usage: state.pendingFinish.usage,
485
507
  });
486
508
  return events;
@@ -320,9 +320,18 @@ const mapFinishReason = (finishReason, hasToolCalls) => {
320
320
  finishReason === "SAFETY" ||
321
321
  finishReason === "BLOCKLIST" ||
322
322
  finishReason === "PROHIBITED_CONTENT" ||
323
- finishReason === "SPII")
323
+ finishReason === "SPII" ||
324
+ finishReason === "MODEL_ARMOR" ||
325
+ finishReason === "IMAGE_PROHIBITED_CONTENT" ||
326
+ finishReason === "IMAGE_RECITATION" ||
327
+ finishReason === "LANGUAGE")
324
328
  return "content-filter";
325
- if (finishReason === "MALFORMED_FUNCTION_CALL")
329
+ if (finishReason === "MALFORMED_FUNCTION_CALL" ||
330
+ finishReason === "UNEXPECTED_TOOL_CALL" ||
331
+ finishReason === "NO_IMAGE" ||
332
+ finishReason === "TOO_MANY_TOOL_CALLS" ||
333
+ finishReason === "MISSING_THOUGHT_SIGNATURE" ||
334
+ finishReason === "MALFORMED_RESPONSE")
326
335
  return "error";
327
336
  return "unknown";
328
337
  };
@@ -333,7 +342,10 @@ const finish = (state) => state.finishReason || state.usage
333
342
  ? Lifecycle.reasoningEnd(state.lifecycle, events, "reasoning-0", googleMetadata({ thoughtSignature: state.reasoningSignature }))
334
343
  : state.lifecycle;
335
344
  Lifecycle.finish(lifecycle, events, {
336
- reason: mapFinishReason(state.finishReason, state.hasToolCalls),
345
+ reason: {
346
+ normalized: mapFinishReason(state.finishReason, state.hasToolCalls),
347
+ raw: state.finishReason,
348
+ },
337
349
  usage: state.usage,
338
350
  });
339
351
  return events;
@@ -2,7 +2,7 @@ import { Schema } from "effect";
2
2
  import { Route } from "../route/client";
3
3
  import { HttpTransport } from "../route/transport";
4
4
  import { Protocol } from "../route/protocol";
5
- import { LLMEvent, Usage, type FinishReason } from "../schema";
5
+ import { LLMEvent, Usage, type FinishReasonDetails } from "../schema";
6
6
  import { Lifecycle } from "./utils/lifecycle";
7
7
  import { ToolStream } from "./utils/tool-stream";
8
8
  export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
@@ -137,7 +137,7 @@ declare const OpenAIChatBody: Schema.Struct<{
137
137
  }>;
138
138
  export type OpenAIChatBody = Schema.Schema.Type<typeof OpenAIChatBody>;
139
139
  export declare const OpenAIChatEvent: Schema.Struct<{
140
- readonly choices: Schema.$Array<Schema.Struct<{
140
+ readonly choices: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
141
141
  readonly delta: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
142
142
  readonly content: Schema.optional<Schema.NullOr<Schema.String>>;
143
143
  readonly reasoning_content: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -154,7 +154,8 @@ export declare const OpenAIChatEvent: Schema.Struct<{
154
154
  }>>>>;
155
155
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
156
156
  readonly finish_reason: Schema.optional<Schema.NullOr<Schema.String>>;
157
- }>>;
157
+ readonly native_finish_reason: Schema.optional<Schema.NullOr<Schema.String>>;
158
+ }>>>>;
158
159
  readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
159
160
  readonly prompt_tokens: Schema.optional<Schema.Number>;
160
161
  readonly completion_tokens: Schema.optional<Schema.Number>;
@@ -166,6 +167,10 @@ export declare const OpenAIChatEvent: Schema.Struct<{
166
167
  readonly reasoning_tokens: Schema.optional<Schema.Number>;
167
168
  }>>>;
168
169
  }>>>;
170
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
171
+ readonly code: Schema.optional<Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.Number]>>>;
172
+ readonly message: Schema.String;
173
+ }>>>;
169
174
  }>;
170
175
  export type OpenAIChatEvent = Schema.Schema.Type<typeof OpenAIChatEvent>;
171
176
  interface PendingToolDelta {
@@ -178,7 +183,7 @@ export interface ParserState {
178
183
  readonly pendingTools: Partial<Record<number, PendingToolDelta>>;
179
184
  readonly toolCallEvents: ReadonlyArray<LLMEvent>;
180
185
  readonly usage?: Usage;
181
- readonly finishReason?: FinishReason;
186
+ readonly finishReason?: FinishReasonDetails;
182
187
  readonly lifecycle: Lifecycle.State;
183
188
  readonly reasoningField?: string;
184
189
  readonly reasoningDetails: Array<unknown>;
@@ -256,7 +261,22 @@ export declare const protocol: Protocol<{
256
261
  readonly store?: boolean | undefined;
257
262
  readonly reasoning_effort?: string | undefined;
258
263
  }, string, {
259
- readonly choices: readonly {
264
+ readonly error?: {
265
+ readonly message: string;
266
+ readonly code?: string | number | null | undefined;
267
+ } | null | undefined;
268
+ readonly usage?: {
269
+ readonly prompt_tokens?: number | undefined;
270
+ readonly completion_tokens?: number | undefined;
271
+ readonly total_tokens?: number | undefined;
272
+ readonly prompt_tokens_details?: {
273
+ readonly cached_tokens?: number | undefined;
274
+ } | null | undefined;
275
+ readonly completion_tokens_details?: {
276
+ readonly reasoning_tokens?: number | undefined;
277
+ } | null | undefined;
278
+ } | null | undefined;
279
+ readonly choices?: readonly {
260
280
  readonly delta?: {
261
281
  readonly [x: string]: unknown;
262
282
  readonly content?: string | null | undefined;
@@ -274,18 +294,8 @@ export declare const protocol: Protocol<{
274
294
  readonly reasoning_details?: unknown;
275
295
  } | null | undefined;
276
296
  readonly finish_reason?: string | null | undefined;
277
- }[];
278
- readonly usage?: {
279
- readonly prompt_tokens?: number | undefined;
280
- readonly completion_tokens?: number | undefined;
281
- readonly total_tokens?: number | undefined;
282
- readonly prompt_tokens_details?: {
283
- readonly cached_tokens?: number | undefined;
284
- } | null | undefined;
285
- readonly completion_tokens_details?: {
286
- readonly reasoning_tokens?: number | undefined;
287
- } | null | undefined;
288
- } | null | undefined;
297
+ readonly native_finish_reason?: string | null | undefined;
298
+ }[] | null | undefined;
289
299
  }, ParserState>;
290
300
  export declare const httpTransport: HttpTransport.HttpJsonTransport<{
291
301
  readonly messages: readonly (Schema.Struct.ReadonlySide<{
@@ -4,7 +4,8 @@ import { Auth } from "../route/auth";
4
4
  import { Endpoint } from "../route/endpoint";
5
5
  import { HttpTransport } from "../route/transport";
6
6
  import { Protocol } from "../route/protocol";
7
- import { LLMEvent, Usage, } from "../schema";
7
+ import { LLMError, LLMEvent, Usage, } from "../schema";
8
+ import { classifyProviderFailure } from "../provider-error";
8
9
  import { isRecord, JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared";
9
10
  import { OpenAIOptions } from "./utils/openai-options";
10
11
  import { Lifecycle } from "./utils/lifecycle";
@@ -124,10 +125,16 @@ const OpenAIChatDelta = Schema.StructWithRest(Schema.Struct({
124
125
  const OpenAIChatChoice = Schema.Struct({
125
126
  delta: optionalNull(OpenAIChatDelta),
126
127
  finish_reason: optionalNull(Schema.String),
128
+ native_finish_reason: optionalNull(Schema.String),
129
+ });
130
+ const OpenAIChatError = Schema.Struct({
131
+ code: optionalNull(Schema.Union([Schema.String, Schema.Number])),
132
+ message: Schema.String,
127
133
  });
128
134
  export const OpenAIChatEvent = Schema.Struct({
129
- choices: Schema.Array(OpenAIChatChoice),
135
+ choices: optionalNull(Schema.Array(OpenAIChatChoice)),
130
136
  usage: optionalNull(OpenAIChatUsage),
137
+ error: optionalNull(OpenAIChatError),
131
138
  });
132
139
  // =============================================================================
133
140
  // Request Lowering
@@ -362,6 +369,8 @@ const mapFinishReason = (reason) => {
362
369
  return "content-filter";
363
370
  if (reason === "function_call" || reason === "tool_calls")
364
371
  return "tool-calls";
372
+ if (reason === "error")
373
+ return "error";
365
374
  return "unknown";
366
375
  };
367
376
  // OpenAI Chat reports `prompt_tokens` (inclusive total) with a
@@ -444,10 +453,22 @@ const reasoningMetadata = (field, details) => ({
444
453
  },
445
454
  });
446
455
  const step = (state, event) => Effect.gen(function* () {
456
+ if (event.error)
457
+ return yield* new LLMError({
458
+ module: ADAPTER,
459
+ method: "stream",
460
+ reason: classifyProviderFailure({
461
+ message: event.error.message,
462
+ code: event.error.code === undefined || event.error.code === null ? undefined : String(event.error.code),
463
+ status: typeof event.error.code === "number" ? event.error.code : undefined,
464
+ }),
465
+ });
447
466
  const events = [];
448
467
  const usage = mapUsage(event.usage) ?? state.usage;
449
- const choice = event.choices[0];
450
- const finishReason = choice?.finish_reason ? mapFinishReason(choice.finish_reason) : state.finishReason;
468
+ const choice = event.choices?.[0];
469
+ const finishReason = choice?.finish_reason
470
+ ? { normalized: mapFinishReason(choice.finish_reason), raw: choice.native_finish_reason ?? choice.finish_reason }
471
+ : state.finishReason;
451
472
  const delta = choice?.delta;
452
473
  const toolDeltas = delta?.tool_calls ?? [];
453
474
  let tools = state.tools;
@@ -520,7 +541,12 @@ const step = (state, event) => Effect.gen(function* () {
520
541
  const finishEvents = (state) => {
521
542
  const events = [];
522
543
  const hasToolCalls = state.toolCallEvents.length > 0;
523
- const reason = state.finishReason === "stop" && hasToolCalls ? "tool-calls" : state.finishReason;
544
+ const reason = state.finishReason
545
+ ? {
546
+ ...state.finishReason,
547
+ normalized: state.finishReason.normalized === "stop" && hasToolCalls ? "tool-calls" : state.finishReason.normalized,
548
+ }
549
+ : undefined;
524
550
  const metadata = reasoningMetadata(state.reasoningField, state.reasoningDetailsObserved ? state.reasoningDetails : undefined);
525
551
  const started = state.reasoningDetailsObserved && !state.reasoningEmitted
526
552
  ? Lifecycle.reasoningStart(state.lifecycle, events, "reasoning-0", reasoningMetadata(state.reasoningField))
@@ -789,7 +789,10 @@ const onOutputItemDone = Effect.fn("OpenAIResponses.onOutputItemDone")(function*
789
789
  const onResponseFinish = (state, event) => {
790
790
  const events = [];
791
791
  const lifecycle = Lifecycle.finish(state.lifecycle, events, {
792
- reason: mapFinishReason(event, state.hasFunctionCall),
792
+ reason: {
793
+ normalized: mapFinishReason(event, state.hasFunctionCall),
794
+ raw: event.response?.incomplete_details?.reason,
795
+ },
793
796
  usage: mapUsage(event.response?.usage),
794
797
  providerMetadata: event.response?.id || event.response?.service_tier
795
798
  ? openaiMetadata({
@@ -1,4 +1,4 @@
1
- import { LLMEvent, type FinishReason, type ProviderMetadata, type Usage } from "../../schema";
1
+ import { LLMEvent, type FinishReasonDetails, type ProviderMetadata, type Usage } from "../../schema";
2
2
  export interface State {
3
3
  readonly stepStarted: boolean;
4
4
  readonly text: ReadonlySet<string>;
@@ -12,7 +12,7 @@ export declare const reasoningDelta: (state: State, events: LLMEvent[], id: stri
12
12
  export declare const reasoningEnd: (state: State, events: LLMEvent[], id: string, providerMetadata?: ProviderMetadata) => State;
13
13
  export declare const textEnd: (state: State, events: LLMEvent[], id: string, providerMetadata?: ProviderMetadata) => State;
14
14
  export declare const finish: (state: State, events: LLMEvent[], input: {
15
- readonly reason: FinishReason;
15
+ readonly reason: FinishReasonDetails;
16
16
  readonly usage?: Usage;
17
17
  readonly providerMetadata?: ProviderMetadata;
18
18
  }) => State;
@@ -219,7 +219,10 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
219
219
  } | undefined;
220
220
  } | {
221
221
  readonly type: "step-finish";
222
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
222
+ readonly reason: {
223
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
224
+ readonly raw?: string | undefined;
225
+ };
223
226
  readonly index: number;
224
227
  readonly providerMetadata?: {
225
228
  readonly [x: string]: {
@@ -229,7 +232,10 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
229
232
  readonly usage?: import("../..").Usage | undefined;
230
233
  } | {
231
234
  readonly type: "finish";
232
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
235
+ readonly reason: {
236
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
237
+ readonly raw?: string | undefined;
238
+ };
233
239
  readonly providerMetadata?: {
234
240
  readonly [x: string]: {
235
241
  readonly [x: string]: unknown;
@@ -406,7 +412,10 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
406
412
  } | undefined;
407
413
  } | {
408
414
  readonly type: "step-finish";
409
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
415
+ readonly reason: {
416
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
417
+ readonly raw?: string | undefined;
418
+ };
410
419
  readonly index: number;
411
420
  readonly providerMetadata?: {
412
421
  readonly [x: string]: {
@@ -416,7 +425,10 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
416
425
  readonly usage?: import("../..").Usage | undefined;
417
426
  } | {
418
427
  readonly type: "finish";
419
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
428
+ readonly reason: {
429
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
430
+ readonly raw?: string | undefined;
431
+ };
420
432
  readonly providerMetadata?: {
421
433
  readonly [x: string]: {
422
434
  readonly [x: string]: unknown;
@@ -590,7 +602,10 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
590
602
  } | undefined;
591
603
  } | {
592
604
  readonly type: "step-finish";
593
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
605
+ readonly reason: {
606
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
607
+ readonly raw?: string | undefined;
608
+ };
594
609
  readonly index: number;
595
610
  readonly providerMetadata?: {
596
611
  readonly [x: string]: {
@@ -600,7 +615,10 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
600
615
  readonly usage?: import("../..").Usage | undefined;
601
616
  } | {
602
617
  readonly type: "finish";
603
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
618
+ readonly reason: {
619
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
620
+ readonly raw?: string | undefined;
621
+ };
604
622
  readonly providerMetadata?: {
605
623
  readonly [x: string]: {
606
624
  readonly [x: string]: unknown;
@@ -153,7 +153,22 @@ export declare const protocol: Protocol<{
153
153
  readonly store?: boolean | undefined;
154
154
  readonly reasoning_effort?: string | undefined;
155
155
  }, string, {
156
- readonly choices: readonly {
156
+ readonly error?: {
157
+ readonly message: string;
158
+ readonly code?: string | number | null | undefined;
159
+ } | null | undefined;
160
+ readonly usage?: {
161
+ readonly prompt_tokens?: number | undefined;
162
+ readonly completion_tokens?: number | undefined;
163
+ readonly total_tokens?: number | undefined;
164
+ readonly prompt_tokens_details?: {
165
+ readonly cached_tokens?: number | undefined;
166
+ } | null | undefined;
167
+ readonly completion_tokens_details?: {
168
+ readonly reasoning_tokens?: number | undefined;
169
+ } | null | undefined;
170
+ } | null | undefined;
171
+ readonly choices?: readonly {
157
172
  readonly delta?: {
158
173
  readonly [x: string]: unknown;
159
174
  readonly content?: string | null | undefined;
@@ -171,18 +186,8 @@ export declare const protocol: Protocol<{
171
186
  readonly reasoning_details?: unknown;
172
187
  } | null | undefined;
173
188
  readonly finish_reason?: string | null | undefined;
174
- }[];
175
- readonly usage?: {
176
- readonly prompt_tokens?: number | undefined;
177
- readonly completion_tokens?: number | undefined;
178
- readonly total_tokens?: number | undefined;
179
- readonly prompt_tokens_details?: {
180
- readonly cached_tokens?: number | undefined;
181
- } | null | undefined;
182
- readonly completion_tokens_details?: {
183
- readonly reasoning_tokens?: number | undefined;
184
- } | null | undefined;
185
- } | null | undefined;
189
+ readonly native_finish_reason?: string | null | undefined;
190
+ }[] | null | undefined;
186
191
  }, OpenAIChat.ParserState>;
187
192
  export declare const route: Route<{
188
193
  readonly [x: string]: any;
@@ -295,7 +295,10 @@ export declare const streamRequest: (request: LLMRequest) => Stream.Stream<Schem
295
295
  } | undefined;
296
296
  } | {
297
297
  readonly type: "step-finish";
298
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
298
+ readonly reason: {
299
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
300
+ readonly raw?: string | undefined;
301
+ };
299
302
  readonly index: number;
300
303
  readonly providerMetadata?: {
301
304
  readonly [x: string]: {
@@ -305,7 +308,10 @@ export declare const streamRequest: (request: LLMRequest) => Stream.Stream<Schem
305
308
  readonly usage?: import("..").Usage | undefined;
306
309
  } | {
307
310
  readonly type: "finish";
308
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
311
+ readonly reason: {
312
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
313
+ readonly raw?: string | undefined;
314
+ };
309
315
  readonly providerMetadata?: {
310
316
  readonly [x: string]: {
311
317
  readonly [x: string]: unknown;
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "effect";
2
- import { ContentBlockID, FinishReason, ProviderMetadata, ToolCallID } from "./ids";
2
+ import { ContentBlockID, ProviderMetadata, ToolCallID } from "./ids";
3
3
  import { Message, ToolOutput, ToolResultValue } from "./messages";
4
4
  declare const Usage_base: Schema.Class<Usage, Schema.Struct<{
5
5
  readonly inputTokens: Schema.optional<Schema.Number>;
@@ -206,17 +206,28 @@ export declare const ToolError: Schema.Struct<{
206
206
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
207
207
  }>;
208
208
  export type ToolError = Schema.Schema.Type<typeof ToolError>;
209
+ export declare const FinishReasonDetails: Schema.Struct<{
210
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
211
+ readonly raw: Schema.optional<Schema.String>;
212
+ }>;
213
+ export type FinishReasonDetails = Schema.Schema.Type<typeof FinishReasonDetails>;
209
214
  export declare const StepFinish: Schema.Struct<{
210
215
  readonly type: Schema.tag<"step-finish">;
211
216
  readonly index: Schema.Number;
212
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
217
+ readonly reason: Schema.Struct<{
218
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
219
+ readonly raw: Schema.optional<Schema.String>;
220
+ }>;
213
221
  readonly usage: Schema.optional<typeof Usage>;
214
222
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
215
223
  }>;
216
224
  export type StepFinish = Schema.Schema.Type<typeof StepFinish>;
217
225
  export declare const Finish: Schema.Struct<{
218
226
  readonly type: Schema.tag<"finish">;
219
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
227
+ readonly reason: Schema.Struct<{
228
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
229
+ readonly raw: Schema.optional<Schema.String>;
230
+ }>;
220
231
  readonly usage: Schema.optional<typeof Usage>;
221
232
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
222
233
  }>;
@@ -341,12 +352,18 @@ declare const llmEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Stru
341
352
  }>, Schema.Struct<{
342
353
  readonly type: Schema.tag<"step-finish">;
343
354
  readonly index: Schema.Number;
344
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
355
+ readonly reason: Schema.Struct<{
356
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
357
+ readonly raw: Schema.optional<Schema.String>;
358
+ }>;
345
359
  readonly usage: Schema.optional<typeof Usage>;
346
360
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
347
361
  }>, Schema.Struct<{
348
362
  readonly type: Schema.tag<"finish">;
349
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
363
+ readonly reason: Schema.Struct<{
364
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
365
+ readonly raw: Schema.optional<Schema.String>;
366
+ }>;
350
367
  readonly usage: Schema.optional<typeof Usage>;
351
368
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
352
369
  }>, Schema.Struct<{
@@ -483,12 +500,18 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
483
500
  }>, Schema.Struct<{
484
501
  readonly type: Schema.tag<"step-finish">;
485
502
  readonly index: Schema.Number;
486
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
503
+ readonly reason: Schema.Struct<{
504
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
505
+ readonly raw: Schema.optional<Schema.String>;
506
+ }>;
487
507
  readonly usage: Schema.optional<typeof Usage>;
488
508
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
489
509
  }>, Schema.Struct<{
490
510
  readonly type: Schema.tag<"finish">;
491
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
511
+ readonly reason: Schema.Struct<{
512
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
513
+ readonly raw: Schema.optional<Schema.String>;
514
+ }>;
492
515
  readonly usage: Schema.optional<typeof Usage>;
493
516
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
494
517
  }>, Schema.Struct<{
@@ -625,13 +648,19 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
625
648
  "step-finish": Schema.Struct<{
626
649
  readonly type: Schema.tag<"step-finish">;
627
650
  readonly index: Schema.Number;
628
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
651
+ readonly reason: Schema.Struct<{
652
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
653
+ readonly raw: Schema.optional<Schema.String>;
654
+ }>;
629
655
  readonly usage: Schema.optional<typeof Usage>;
630
656
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
631
657
  }>;
632
658
  finish: Schema.Struct<{
633
659
  readonly type: Schema.tag<"finish">;
634
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
660
+ readonly reason: Schema.Struct<{
661
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
662
+ readonly raw: Schema.optional<Schema.String>;
663
+ }>;
635
664
  readonly usage: Schema.optional<typeof Usage>;
636
665
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
637
666
  }>;
@@ -791,7 +820,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
791
820
  } | undefined;
792
821
  } | {
793
822
  readonly type: "step-finish";
794
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
823
+ readonly reason: {
824
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
825
+ readonly raw?: string | undefined;
826
+ };
795
827
  readonly index: number;
796
828
  readonly providerMetadata?: {
797
829
  readonly [x: string]: {
@@ -801,7 +833,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
801
833
  readonly usage?: Usage | undefined;
802
834
  } | {
803
835
  readonly type: "finish";
804
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
836
+ readonly reason: {
837
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
838
+ readonly raw?: string | undefined;
839
+ };
805
840
  readonly providerMetadata?: {
806
841
  readonly [x: string]: {
807
842
  readonly [x: string]: unknown;
@@ -994,7 +1029,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
994
1029
  readonly type: Keys;
995
1030
  }> | Extract<{
996
1031
  readonly type: "step-finish";
997
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1032
+ readonly reason: {
1033
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1034
+ readonly raw?: string | undefined;
1035
+ };
998
1036
  readonly index: number;
999
1037
  readonly providerMetadata?: {
1000
1038
  readonly [x: string]: {
@@ -1006,7 +1044,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1006
1044
  readonly type: Keys;
1007
1045
  }> | Extract<{
1008
1046
  readonly type: "finish";
1009
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1047
+ readonly reason: {
1048
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1049
+ readonly raw?: string | undefined;
1050
+ };
1010
1051
  readonly providerMetadata?: {
1011
1052
  readonly [x: string]: {
1012
1053
  readonly [x: string]: unknown;
@@ -1191,7 +1232,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1191
1232
  };
1192
1233
  "step-finish": (u: unknown) => u is {
1193
1234
  readonly type: "step-finish";
1194
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1235
+ readonly reason: {
1236
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1237
+ readonly raw?: string | undefined;
1238
+ };
1195
1239
  readonly index: number;
1196
1240
  readonly providerMetadata?: {
1197
1241
  readonly [x: string]: {
@@ -1202,7 +1246,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1202
1246
  };
1203
1247
  finish: (u: unknown) => u is {
1204
1248
  readonly type: "finish";
1205
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1249
+ readonly reason: {
1250
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1251
+ readonly raw?: string | undefined;
1252
+ };
1206
1253
  readonly providerMetadata?: {
1207
1254
  readonly [x: string]: {
1208
1255
  readonly [x: string]: unknown;
@@ -1386,7 +1433,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1386
1433
  }) => any;
1387
1434
  "step-finish": (value: {
1388
1435
  readonly type: "step-finish";
1389
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1436
+ readonly reason: {
1437
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1438
+ readonly raw?: string | undefined;
1439
+ };
1390
1440
  readonly index: number;
1391
1441
  readonly providerMetadata?: {
1392
1442
  readonly [x: string]: {
@@ -1397,7 +1447,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1397
1447
  }) => any;
1398
1448
  finish: (value: {
1399
1449
  readonly type: "finish";
1400
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1450
+ readonly reason: {
1451
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1452
+ readonly raw?: string | undefined;
1453
+ };
1401
1454
  readonly providerMetadata?: {
1402
1455
  readonly [x: string]: {
1403
1456
  readonly [x: string]: unknown;
@@ -1564,7 +1617,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1564
1617
  } | undefined;
1565
1618
  } | {
1566
1619
  readonly type: "step-finish";
1567
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1620
+ readonly reason: {
1621
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1622
+ readonly raw?: string | undefined;
1623
+ };
1568
1624
  readonly index: number;
1569
1625
  readonly providerMetadata?: {
1570
1626
  readonly [x: string]: {
@@ -1574,7 +1630,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1574
1630
  readonly usage?: Usage | undefined;
1575
1631
  } | {
1576
1632
  readonly type: "finish";
1577
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1633
+ readonly reason: {
1634
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1635
+ readonly raw?: string | undefined;
1636
+ };
1578
1637
  readonly providerMetadata?: {
1579
1638
  readonly [x: string]: {
1580
1639
  readonly [x: string]: unknown;
@@ -1755,7 +1814,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1755
1814
  }) => any;
1756
1815
  "step-finish": (value: {
1757
1816
  readonly type: "step-finish";
1758
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1817
+ readonly reason: {
1818
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1819
+ readonly raw?: string | undefined;
1820
+ };
1759
1821
  readonly index: number;
1760
1822
  readonly providerMetadata?: {
1761
1823
  readonly [x: string]: {
@@ -1766,7 +1828,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1766
1828
  }) => any;
1767
1829
  finish: (value: {
1768
1830
  readonly type: "finish";
1769
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1831
+ readonly reason: {
1832
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
1833
+ readonly raw?: string | undefined;
1834
+ };
1770
1835
  readonly providerMetadata?: {
1771
1836
  readonly [x: string]: {
1772
1837
  readonly [x: string]: unknown;
@@ -1933,7 +1998,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1933
1998
  } | undefined;
1934
1999
  } | {
1935
2000
  readonly type: "step-finish";
1936
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2001
+ readonly reason: {
2002
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2003
+ readonly raw?: string | undefined;
2004
+ };
1937
2005
  readonly index: number;
1938
2006
  readonly providerMetadata?: {
1939
2007
  readonly [x: string]: {
@@ -1943,7 +2011,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
1943
2011
  readonly usage?: Usage | undefined;
1944
2012
  } | {
1945
2013
  readonly type: "finish";
1946
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2014
+ readonly reason: {
2015
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2016
+ readonly raw?: string | undefined;
2017
+ };
1947
2018
  readonly providerMetadata?: {
1948
2019
  readonly [x: string]: {
1949
2020
  readonly [x: string]: unknown;
@@ -2128,7 +2199,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
2128
2199
  };
2129
2200
  stepFinish: (input: WithUsage<StepFinish>) => {
2130
2201
  readonly type: "step-finish";
2131
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2202
+ readonly reason: {
2203
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2204
+ readonly raw?: string | undefined;
2205
+ };
2132
2206
  readonly index: number;
2133
2207
  readonly providerMetadata?: {
2134
2208
  readonly [x: string]: {
@@ -2139,7 +2213,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
2139
2213
  };
2140
2214
  finish: (input: WithUsage<Finish>) => {
2141
2215
  readonly type: "finish";
2142
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2216
+ readonly reason: {
2217
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2218
+ readonly raw?: string | undefined;
2219
+ };
2143
2220
  readonly providerMetadata?: {
2144
2221
  readonly [x: string]: {
2145
2222
  readonly [x: string]: unknown;
@@ -2330,7 +2407,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
2330
2407
  };
2331
2408
  stepFinish: (u: unknown) => u is {
2332
2409
  readonly type: "step-finish";
2333
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2410
+ readonly reason: {
2411
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2412
+ readonly raw?: string | undefined;
2413
+ };
2334
2414
  readonly index: number;
2335
2415
  readonly providerMetadata?: {
2336
2416
  readonly [x: string]: {
@@ -2341,7 +2421,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.Struct<{
2341
2421
  };
2342
2422
  finish: (u: unknown) => u is {
2343
2423
  readonly type: "finish";
2344
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2424
+ readonly reason: {
2425
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2426
+ readonly raw?: string | undefined;
2427
+ };
2345
2428
  readonly providerMetadata?: {
2346
2429
  readonly [x: string]: {
2347
2430
  readonly [x: string]: unknown;
@@ -2399,7 +2482,7 @@ interface ResponseState {
2399
2482
  readonly events: ReadonlyArray<LLMEvent>;
2400
2483
  readonly message: Message;
2401
2484
  readonly usage?: Usage;
2402
- readonly finishReason?: FinishReason;
2485
+ readonly finishReason?: FinishReasonDetails;
2403
2486
  readonly textParts: Readonly<Record<string, ContentAssembly>>;
2404
2487
  readonly reasoningParts: Readonly<Record<string, ContentAssembly>>;
2405
2488
  readonly toolInputs: Readonly<Record<string, ToolInputAssembly>>;
@@ -2519,12 +2602,18 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
2519
2602
  }>, Schema.Struct<{
2520
2603
  readonly type: Schema.tag<"step-finish">;
2521
2604
  readonly index: Schema.Number;
2522
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2605
+ readonly reason: Schema.Struct<{
2606
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2607
+ readonly raw: Schema.optional<Schema.String>;
2608
+ }>;
2523
2609
  readonly usage: Schema.optional<typeof Usage>;
2524
2610
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2525
2611
  }>, Schema.Struct<{
2526
2612
  readonly type: Schema.tag<"finish">;
2527
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2613
+ readonly reason: Schema.Struct<{
2614
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2615
+ readonly raw: Schema.optional<Schema.String>;
2616
+ }>;
2528
2617
  readonly usage: Schema.optional<typeof Usage>;
2529
2618
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2530
2619
  }>, Schema.Struct<{
@@ -2661,13 +2750,19 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
2661
2750
  "step-finish": Schema.Struct<{
2662
2751
  readonly type: Schema.tag<"step-finish">;
2663
2752
  readonly index: Schema.Number;
2664
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2753
+ readonly reason: Schema.Struct<{
2754
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2755
+ readonly raw: Schema.optional<Schema.String>;
2756
+ }>;
2665
2757
  readonly usage: Schema.optional<typeof Usage>;
2666
2758
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2667
2759
  }>;
2668
2760
  finish: Schema.Struct<{
2669
2761
  readonly type: Schema.tag<"finish">;
2670
- readonly reason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2762
+ readonly reason: Schema.Struct<{
2763
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
2764
+ readonly raw: Schema.optional<Schema.String>;
2765
+ }>;
2671
2766
  readonly usage: Schema.optional<typeof Usage>;
2672
2767
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2673
2768
  }>;
@@ -2827,7 +2922,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
2827
2922
  } | undefined;
2828
2923
  } | {
2829
2924
  readonly type: "step-finish";
2830
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2925
+ readonly reason: {
2926
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2927
+ readonly raw?: string | undefined;
2928
+ };
2831
2929
  readonly index: number;
2832
2930
  readonly providerMetadata?: {
2833
2931
  readonly [x: string]: {
@@ -2837,7 +2935,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
2837
2935
  readonly usage?: Usage | undefined;
2838
2936
  } | {
2839
2937
  readonly type: "finish";
2840
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2938
+ readonly reason: {
2939
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
2940
+ readonly raw?: string | undefined;
2941
+ };
2841
2942
  readonly providerMetadata?: {
2842
2943
  readonly [x: string]: {
2843
2944
  readonly [x: string]: unknown;
@@ -3030,7 +3131,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3030
3131
  readonly type: Keys;
3031
3132
  }> | Extract<{
3032
3133
  readonly type: "step-finish";
3033
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3134
+ readonly reason: {
3135
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3136
+ readonly raw?: string | undefined;
3137
+ };
3034
3138
  readonly index: number;
3035
3139
  readonly providerMetadata?: {
3036
3140
  readonly [x: string]: {
@@ -3042,7 +3146,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3042
3146
  readonly type: Keys;
3043
3147
  }> | Extract<{
3044
3148
  readonly type: "finish";
3045
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3149
+ readonly reason: {
3150
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3151
+ readonly raw?: string | undefined;
3152
+ };
3046
3153
  readonly providerMetadata?: {
3047
3154
  readonly [x: string]: {
3048
3155
  readonly [x: string]: unknown;
@@ -3227,7 +3334,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3227
3334
  };
3228
3335
  "step-finish": (u: unknown) => u is {
3229
3336
  readonly type: "step-finish";
3230
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3337
+ readonly reason: {
3338
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3339
+ readonly raw?: string | undefined;
3340
+ };
3231
3341
  readonly index: number;
3232
3342
  readonly providerMetadata?: {
3233
3343
  readonly [x: string]: {
@@ -3238,7 +3348,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3238
3348
  };
3239
3349
  finish: (u: unknown) => u is {
3240
3350
  readonly type: "finish";
3241
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3351
+ readonly reason: {
3352
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3353
+ readonly raw?: string | undefined;
3354
+ };
3242
3355
  readonly providerMetadata?: {
3243
3356
  readonly [x: string]: {
3244
3357
  readonly [x: string]: unknown;
@@ -3422,7 +3535,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3422
3535
  }) => any;
3423
3536
  "step-finish": (value: {
3424
3537
  readonly type: "step-finish";
3425
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3538
+ readonly reason: {
3539
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3540
+ readonly raw?: string | undefined;
3541
+ };
3426
3542
  readonly index: number;
3427
3543
  readonly providerMetadata?: {
3428
3544
  readonly [x: string]: {
@@ -3433,7 +3549,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3433
3549
  }) => any;
3434
3550
  finish: (value: {
3435
3551
  readonly type: "finish";
3436
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3552
+ readonly reason: {
3553
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3554
+ readonly raw?: string | undefined;
3555
+ };
3437
3556
  readonly providerMetadata?: {
3438
3557
  readonly [x: string]: {
3439
3558
  readonly [x: string]: unknown;
@@ -3600,7 +3719,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3600
3719
  } | undefined;
3601
3720
  } | {
3602
3721
  readonly type: "step-finish";
3603
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3722
+ readonly reason: {
3723
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3724
+ readonly raw?: string | undefined;
3725
+ };
3604
3726
  readonly index: number;
3605
3727
  readonly providerMetadata?: {
3606
3728
  readonly [x: string]: {
@@ -3610,7 +3732,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3610
3732
  readonly usage?: Usage | undefined;
3611
3733
  } | {
3612
3734
  readonly type: "finish";
3613
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3735
+ readonly reason: {
3736
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3737
+ readonly raw?: string | undefined;
3738
+ };
3614
3739
  readonly providerMetadata?: {
3615
3740
  readonly [x: string]: {
3616
3741
  readonly [x: string]: unknown;
@@ -3791,7 +3916,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3791
3916
  }) => any;
3792
3917
  "step-finish": (value: {
3793
3918
  readonly type: "step-finish";
3794
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3919
+ readonly reason: {
3920
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3921
+ readonly raw?: string | undefined;
3922
+ };
3795
3923
  readonly index: number;
3796
3924
  readonly providerMetadata?: {
3797
3925
  readonly [x: string]: {
@@ -3802,7 +3930,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3802
3930
  }) => any;
3803
3931
  finish: (value: {
3804
3932
  readonly type: "finish";
3805
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3933
+ readonly reason: {
3934
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
3935
+ readonly raw?: string | undefined;
3936
+ };
3806
3937
  readonly providerMetadata?: {
3807
3938
  readonly [x: string]: {
3808
3939
  readonly [x: string]: unknown;
@@ -3969,7 +4100,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3969
4100
  } | undefined;
3970
4101
  } | {
3971
4102
  readonly type: "step-finish";
3972
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4103
+ readonly reason: {
4104
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4105
+ readonly raw?: string | undefined;
4106
+ };
3973
4107
  readonly index: number;
3974
4108
  readonly providerMetadata?: {
3975
4109
  readonly [x: string]: {
@@ -3979,7 +4113,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
3979
4113
  readonly usage?: Usage | undefined;
3980
4114
  } | {
3981
4115
  readonly type: "finish";
3982
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4116
+ readonly reason: {
4117
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4118
+ readonly raw?: string | undefined;
4119
+ };
3983
4120
  readonly providerMetadata?: {
3984
4121
  readonly [x: string]: {
3985
4122
  readonly [x: string]: unknown;
@@ -4164,7 +4301,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4164
4301
  };
4165
4302
  stepFinish: (input: WithUsage<StepFinish>) => {
4166
4303
  readonly type: "step-finish";
4167
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4304
+ readonly reason: {
4305
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4306
+ readonly raw?: string | undefined;
4307
+ };
4168
4308
  readonly index: number;
4169
4309
  readonly providerMetadata?: {
4170
4310
  readonly [x: string]: {
@@ -4175,7 +4315,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4175
4315
  };
4176
4316
  finish: (input: WithUsage<Finish>) => {
4177
4317
  readonly type: "finish";
4178
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4318
+ readonly reason: {
4319
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4320
+ readonly raw?: string | undefined;
4321
+ };
4179
4322
  readonly providerMetadata?: {
4180
4323
  readonly [x: string]: {
4181
4324
  readonly [x: string]: unknown;
@@ -4366,7 +4509,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4366
4509
  };
4367
4510
  stepFinish: (u: unknown) => u is {
4368
4511
  readonly type: "step-finish";
4369
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4512
+ readonly reason: {
4513
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4514
+ readonly raw?: string | undefined;
4515
+ };
4370
4516
  readonly index: number;
4371
4517
  readonly providerMetadata?: {
4372
4518
  readonly [x: string]: {
@@ -4377,7 +4523,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4377
4523
  };
4378
4524
  finish: (u: unknown) => u is {
4379
4525
  readonly type: "finish";
4380
- readonly reason: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4526
+ readonly reason: {
4527
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
4528
+ readonly raw?: string | undefined;
4529
+ };
4381
4530
  readonly providerMetadata?: {
4382
4531
  readonly [x: string]: {
4383
4532
  readonly [x: string]: unknown;
@@ -4398,7 +4547,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4398
4547
  };
4399
4548
  }>;
4400
4549
  readonly usage: Schema.optional<typeof Usage>;
4401
- readonly finishReason: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
4550
+ readonly finishReason: Schema.Struct<{
4551
+ readonly normalized: Schema.Literals<readonly ["stop", "length", "tool-calls", "content-filter", "error", "unknown"]>;
4552
+ readonly raw: Schema.optional<Schema.String>;
4553
+ }>;
4402
4554
  }>, {}>;
4403
4555
  export declare class LLMResponse extends LLMResponse_base {
4404
4556
  /** Concatenated assistant text assembled from streamed `text-delta` events. */
@@ -158,16 +158,20 @@ export const ToolError = Schema.Struct({
158
158
  error: Schema.optional(Schema.Defect()),
159
159
  providerMetadata: Schema.optional(ProviderMetadata),
160
160
  }).annotate({ identifier: "LLM.Event.ToolError" });
161
+ export const FinishReasonDetails = Schema.Struct({
162
+ normalized: FinishReason,
163
+ raw: Schema.optional(Schema.String),
164
+ }).annotate({ identifier: "LLM.FinishReasonDetails" });
161
165
  export const StepFinish = Schema.Struct({
162
166
  type: Schema.tag("step-finish"),
163
167
  index: Schema.Number,
164
- reason: FinishReason,
168
+ reason: FinishReasonDetails,
165
169
  usage: Schema.optional(Usage),
166
170
  providerMetadata: Schema.optional(ProviderMetadata),
167
171
  }).annotate({ identifier: "LLM.Event.StepFinish" });
168
172
  export const Finish = Schema.Struct({
169
173
  type: Schema.tag("finish"),
170
- reason: FinishReason,
174
+ reason: FinishReasonDetails,
171
175
  usage: Schema.optional(Usage),
172
176
  providerMetadata: Schema.optional(ProviderMetadata),
173
177
  }).annotate({ identifier: "LLM.Event.Finish" });
@@ -290,7 +294,7 @@ const appendEvent = (state, event) => {
290
294
  return {
291
295
  ...state,
292
296
  events,
293
- finishReason: state.finishReason ?? "error",
297
+ finishReason: state.finishReason ?? { normalized: "error" },
294
298
  };
295
299
  }
296
300
  return {
@@ -456,7 +460,7 @@ export class LLMResponse extends Schema.Class("LLM.Response")({
456
460
  message: Message,
457
461
  events: Schema.Array(LLMEvent),
458
462
  usage: Schema.optional(Usage),
459
- finishReason: FinishReason,
463
+ finishReason: FinishReasonDetails,
460
464
  }) {
461
465
  /** Concatenated assistant text assembled from streamed `text-delta` events. */
462
466
  get text() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-next-16093",
3
+ "version": "0.0.0-next-16094",
4
4
  "name": "@opencode-ai/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "@clack/prompts": "1.0.0-alpha.1",
28
28
  "@effect/platform-node": "4.0.0-beta.98",
29
- "@opencode-ai/http-recorder": "0.0.0-next-16093",
29
+ "@opencode-ai/http-recorder": "0.0.0-next-16094",
30
30
  "@tsconfig/bun": "1.0.9",
31
31
  "@types/bun": "1.3.13",
32
32
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@smithy/eventstream-codec": "4.2.14",
37
37
  "@smithy/util-utf8": "4.2.2",
38
- "@opencode-ai/schema": "0.0.0-next-16093",
38
+ "@opencode-ai/schema": "0.0.0-next-16094",
39
39
  "aws4fetch": "1.0.20",
40
40
  "effect": "4.0.0-beta.98",
41
41
  "google-auth-library": "10.5.0"