@opencode-ai/ai 0.0.0-next-16162 → 0.0.0-next-16164

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.
@@ -292,6 +292,7 @@ export declare const protocol: Protocol<{
292
292
  }, "Encoded"> | undefined;
293
293
  readonly reasoningContent?: {
294
294
  readonly text?: string | undefined;
295
+ readonly data?: string | undefined;
295
296
  readonly signature?: string | undefined;
296
297
  readonly redactedContent?: string | undefined;
297
298
  } | undefined;
@@ -304,21 +305,31 @@ export declare const protocol: Protocol<{
304
305
  readonly stopReason: string;
305
306
  readonly additionalModelResponseFields?: unknown;
306
307
  } | undefined;
307
- readonly internalServerException?: Schema.Struct.ReadonlySide<{
308
- readonly message: Schema.String;
309
- }, "Encoded"> | undefined;
310
- readonly modelStreamErrorException?: Schema.Struct.ReadonlySide<{
311
- readonly message: Schema.String;
312
- }, "Encoded"> | undefined;
313
- readonly validationException?: Schema.Struct.ReadonlySide<{
314
- readonly message: Schema.String;
315
- }, "Encoded"> | undefined;
316
- readonly throttlingException?: Schema.Struct.ReadonlySide<{
317
- readonly message: Schema.String;
318
- }, "Encoded"> | undefined;
319
- readonly serviceUnavailableException?: Schema.Struct.ReadonlySide<{
320
- readonly message: Schema.String;
321
- }, "Encoded"> | undefined;
308
+ readonly internalServerException?: {
309
+ readonly message?: string | undefined;
310
+ readonly originalMessage?: string | undefined;
311
+ readonly originalStatusCode?: number | undefined;
312
+ } | undefined;
313
+ readonly modelStreamErrorException?: {
314
+ readonly message?: string | undefined;
315
+ readonly originalMessage?: string | undefined;
316
+ readonly originalStatusCode?: number | undefined;
317
+ } | undefined;
318
+ readonly validationException?: {
319
+ readonly message?: string | undefined;
320
+ readonly originalMessage?: string | undefined;
321
+ readonly originalStatusCode?: number | undefined;
322
+ } | undefined;
323
+ readonly throttlingException?: {
324
+ readonly message?: string | undefined;
325
+ readonly originalMessage?: string | undefined;
326
+ readonly originalStatusCode?: number | undefined;
327
+ } | undefined;
328
+ readonly serviceUnavailableException?: {
329
+ readonly message?: string | undefined;
330
+ readonly originalMessage?: string | undefined;
331
+ readonly originalStatusCode?: number | undefined;
332
+ } | undefined;
322
333
  }, {
323
334
  readonly metadata?: {
324
335
  readonly usage?: {
@@ -351,6 +362,7 @@ export declare const protocol: Protocol<{
351
362
  }, "Type"> | undefined;
352
363
  readonly reasoningContent?: {
353
364
  readonly text?: string | undefined;
365
+ readonly data?: string | undefined;
354
366
  readonly signature?: string | undefined;
355
367
  readonly redactedContent?: string | undefined;
356
368
  } | undefined;
@@ -363,21 +375,31 @@ export declare const protocol: Protocol<{
363
375
  readonly stopReason: string;
364
376
  readonly additionalModelResponseFields?: unknown;
365
377
  } | undefined;
366
- readonly internalServerException?: Schema.Struct.ReadonlySide<{
367
- readonly message: Schema.String;
368
- }, "Type"> | undefined;
369
- readonly modelStreamErrorException?: Schema.Struct.ReadonlySide<{
370
- readonly message: Schema.String;
371
- }, "Type"> | undefined;
372
- readonly validationException?: Schema.Struct.ReadonlySide<{
373
- readonly message: Schema.String;
374
- }, "Type"> | undefined;
375
- readonly throttlingException?: Schema.Struct.ReadonlySide<{
376
- readonly message: Schema.String;
377
- }, "Type"> | undefined;
378
- readonly serviceUnavailableException?: Schema.Struct.ReadonlySide<{
379
- readonly message: Schema.String;
380
- }, "Type"> | undefined;
378
+ readonly internalServerException?: {
379
+ readonly message?: string | undefined;
380
+ readonly originalMessage?: string | undefined;
381
+ readonly originalStatusCode?: number | undefined;
382
+ } | undefined;
383
+ readonly modelStreamErrorException?: {
384
+ readonly message?: string | undefined;
385
+ readonly originalMessage?: string | undefined;
386
+ readonly originalStatusCode?: number | undefined;
387
+ } | undefined;
388
+ readonly validationException?: {
389
+ readonly message?: string | undefined;
390
+ readonly originalMessage?: string | undefined;
391
+ readonly originalStatusCode?: number | undefined;
392
+ } | undefined;
393
+ readonly throttlingException?: {
394
+ readonly message?: string | undefined;
395
+ readonly originalMessage?: string | undefined;
396
+ readonly originalStatusCode?: number | undefined;
397
+ } | undefined;
398
+ readonly serviceUnavailableException?: {
399
+ readonly message?: string | undefined;
400
+ readonly originalMessage?: string | undefined;
401
+ readonly originalStatusCode?: number | undefined;
402
+ } | undefined;
381
403
  }, ParserState>;
382
404
  export declare const route: Route<{
383
405
  readonly messages: readonly (Schema.Struct.ReadonlySide<{
@@ -107,6 +107,11 @@ const BedrockUsageSchema = Schema.Struct({
107
107
  cacheReadInputTokens: Schema.optional(Schema.Number),
108
108
  cacheWriteInputTokens: Schema.optional(Schema.Number),
109
109
  });
110
+ const BedrockStreamException = Schema.Struct({
111
+ message: Schema.optional(Schema.String),
112
+ originalMessage: Schema.optional(Schema.String),
113
+ originalStatusCode: Schema.optional(Schema.Number),
114
+ });
110
115
  // Streaming event shape — the AWS event stream wraps each JSON payload by its
111
116
  // `:event-type` header (e.g. `messageStart`, `contentBlockDelta`). We
112
117
  // reconstruct that wrapping in `decodeFrames` below so the event schema can
@@ -129,6 +134,9 @@ const BedrockEvent = Schema.Struct({
129
134
  signature: Schema.optional(Schema.String),
130
135
  // Blob fields in Bedrock's JSON event stream are base64 strings.
131
136
  redactedContent: Schema.optional(Schema.String),
137
+ // Vercel's Bedrock provider exposes the same delta under
138
+ // Anthropic's shorter `data` spelling.
139
+ data: Schema.optional(Schema.String),
132
140
  })),
133
141
  })),
134
142
  })),
@@ -141,11 +149,11 @@ const BedrockEvent = Schema.Struct({
141
149
  usage: Schema.optional(BedrockUsageSchema),
142
150
  metrics: Schema.optional(Schema.Unknown),
143
151
  })),
144
- internalServerException: Schema.optional(Schema.Struct({ message: Schema.String })),
145
- modelStreamErrorException: Schema.optional(Schema.Struct({ message: Schema.String })),
146
- validationException: Schema.optional(Schema.Struct({ message: Schema.String })),
147
- throttlingException: Schema.optional(Schema.Struct({ message: Schema.String })),
148
- serviceUnavailableException: Schema.optional(Schema.Struct({ message: Schema.String })),
152
+ internalServerException: Schema.optional(BedrockStreamException),
153
+ modelStreamErrorException: Schema.optional(BedrockStreamException),
154
+ validationException: Schema.optional(BedrockStreamException),
155
+ throttlingException: Schema.optional(BedrockStreamException),
156
+ serviceUnavailableException: Schema.optional(BedrockStreamException),
149
157
  });
150
158
  // =============================================================================
151
159
  // Request Lowering
@@ -412,11 +420,15 @@ const step = (state, event) => Effect.gen(function* () {
412
420
  const index = event.contentBlockDelta.contentBlockIndex;
413
421
  const reasoning = event.contentBlockDelta.delta.reasoningContent;
414
422
  const events = [];
415
- const lifecycle = reasoning.text
416
- ? Lifecycle.reasoningDelta(state.lifecycle, events, `reasoning-${index}`, reasoning.text)
417
- : reasoning.redactedContent !== undefined
418
- ? Lifecycle.reasoningStart(state.lifecycle, events, `reasoning-${index}`, bedrockMetadata({ redactedData: reasoning.redactedContent }))
419
- : state.lifecycle;
423
+ const redactedData = reasoning.redactedContent ?? reasoning.data;
424
+ const providerMetadata = reasoning.signature
425
+ ? bedrockMetadata({ signature: reasoning.signature })
426
+ : redactedData !== undefined
427
+ ? bedrockMetadata({ redactedData })
428
+ : undefined;
429
+ const lifecycle = reasoning.text !== undefined || providerMetadata !== undefined
430
+ ? Lifecycle.reasoningDelta(state.lifecycle, events, `reasoning-${index}`, reasoning.text ?? "", providerMetadata)
431
+ : state.lifecycle;
420
432
  return [
421
433
  {
422
434
  ...state,
@@ -477,7 +489,7 @@ const step = (state, event) => Effect.gen(function* () {
477
489
  ];
478
490
  }
479
491
  if (event.metadata) {
480
- const usage = mapUsage(event.metadata.usage);
492
+ const usage = mapUsage(event.metadata.usage) ?? state.pendingFinish?.usage;
481
493
  return [
482
494
  {
483
495
  ...state,
@@ -501,7 +513,7 @@ const step = (state, event) => Effect.gen(function* () {
501
513
  module: ADAPTER,
502
514
  method: "stream",
503
515
  reason: classifyProviderFailure({
504
- message: exception[1]?.message ?? "Bedrock Converse stream error",
516
+ message: exception[1]?.message ?? exception[1]?.originalMessage ?? "Bedrock Converse stream error",
505
517
  code: exception[0],
506
518
  }),
507
519
  });
@@ -33,9 +33,18 @@ const consumeFrames = (route) => (state, chunk) => Effect.gen(function* () {
33
33
  catch: (error) => ProviderShared.eventError(route, `Failed to decode Bedrock Converse event-stream frame: ${error instanceof Error ? error.message : String(error)}`),
34
34
  });
35
35
  cursor = { buffer: cursor.buffer, offset: cursor.offset + totalLength };
36
- if (decoded.headers[":message-type"]?.value !== "event")
37
- continue;
38
- const eventType = decoded.headers[":event-type"]?.value;
36
+ const messageType = decoded.headers[":message-type"]?.value;
37
+ if (messageType === "error") {
38
+ const code = decoded.headers[":error-code"]?.value;
39
+ const message = decoded.headers[":error-message"]?.value;
40
+ return yield* ProviderShared.eventError(route, [code, message].filter((value) => typeof value === "string").join(": ") ||
41
+ "Bedrock Converse event-stream error");
42
+ }
43
+ const eventType = messageType === "event"
44
+ ? decoded.headers[":event-type"]?.value
45
+ : messageType === "exception"
46
+ ? decoded.headers[":exception-type"]?.value
47
+ : undefined;
39
48
  if (typeof eventType !== "string")
40
49
  continue;
41
50
  const payload = utf8.decode(decoded.body);
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-16162",
3
+ "version": "0.0.0-next-16164",
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-16162",
29
+ "@opencode-ai/http-recorder": "0.0.0-next-16164",
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-16162",
38
+ "@opencode-ai/schema": "0.0.0-next-16164",
39
39
  "aws4fetch": "1.0.20",
40
40
  "effect": "4.0.0-beta.98",
41
41
  "google-auth-library": "10.5.0"