@opencode/ai 2.1.2 → 2.1.4

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 (140) hide show
  1. package/dist/cache-policy.js +6 -5
  2. package/dist/experimental/evaluation.d.ts +7 -6
  3. package/dist/experimental/evaluation.js +3 -11
  4. package/dist/experimental/realtime.d.ts +59 -0
  5. package/dist/experimental/realtime.js +21 -13
  6. package/dist/experimental.d.ts +1 -1
  7. package/dist/generation.js +1 -1
  8. package/dist/image-client.d.ts +11 -9
  9. package/dist/image.d.ts +158 -150
  10. package/dist/image.js +2 -2
  11. package/dist/llm.d.ts +2 -4
  12. package/dist/llm.js +2 -2
  13. package/dist/media-model.d.ts +2 -2
  14. package/dist/media-model.js +1 -1
  15. package/dist/promise.d.ts +121 -121
  16. package/dist/promise.js +3 -5
  17. package/dist/protocols/alibaba-chat.d.ts +18 -18
  18. package/dist/protocols/alibaba-chat.js +3 -3
  19. package/dist/protocols/alibaba-messages.d.ts +12 -12
  20. package/dist/protocols/alibaba-messages.js +1 -1
  21. package/dist/protocols/alibaba-responses.d.ts +38 -38
  22. package/dist/protocols/anthropic-messages.d.ts +40 -44
  23. package/dist/protocols/anthropic-messages.js +13 -15
  24. package/dist/protocols/bedrock-converse.d.ts +36 -85
  25. package/dist/protocols/bedrock-converse.js +6 -6
  26. package/dist/protocols/bedrock-event-stream.d.ts +6 -1
  27. package/dist/protocols/bedrock-event-stream.js +9 -8
  28. package/dist/protocols/cartesia-speech.d.ts +32 -32
  29. package/dist/protocols/cohere-chat.d.ts +13 -10
  30. package/dist/protocols/cohere-chat.js +2 -2
  31. package/dist/protocols/deepgram-speech.d.ts +32 -32
  32. package/dist/protocols/elevenlabs-speech.d.ts +32 -32
  33. package/dist/protocols/gemini.d.ts +46 -36
  34. package/dist/protocols/gemini.js +12 -15
  35. package/dist/protocols/google-interactions.d.ts +14 -13
  36. package/dist/protocols/google-interactions.js +16 -11
  37. package/dist/protocols/google-speech.d.ts +32 -32
  38. package/dist/protocols/google-transcription.d.ts +32 -32
  39. package/dist/protocols/meta-messages.d.ts +23 -23
  40. package/dist/protocols/meta-responses.d.ts +84 -84
  41. package/dist/protocols/mistral-chat.d.ts +81 -78
  42. package/dist/protocols/mistral-chat.js +3 -5
  43. package/dist/protocols/open-responses-channel.js +47 -46
  44. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  45. package/dist/protocols/open-responses-continuation.js +3 -1
  46. package/dist/protocols/open-responses.d.ts +419 -419
  47. package/dist/protocols/open-responses.js +11 -10
  48. package/dist/protocols/openai-chat.d.ts +68 -67
  49. package/dist/protocols/openai-chat.js +7 -8
  50. package/dist/protocols/openai-compatible-chat.d.ts +13 -14
  51. package/dist/protocols/openai-compatible-responses.d.ts +39 -40
  52. package/dist/protocols/openai-images.d.ts +32 -32
  53. package/dist/protocols/openai-responses.d.ts +253 -253
  54. package/dist/protocols/openai-responses.js +1 -1
  55. package/dist/protocols/openai-speech.d.ts +32 -32
  56. package/dist/protocols/openai-transcription.d.ts +32 -32
  57. package/dist/protocols/openai-transcription.js +12 -7
  58. package/dist/protocols/utils/open-responses-options.d.ts +8 -8
  59. package/dist/protocols/utils/open-responses-options.js +4 -6
  60. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  61. package/dist/protocols/utils/partial-json-options.js +0 -1
  62. package/dist/protocols/utils/partial-json.js +5 -4
  63. package/dist/protocols/utils/tool-schema.d.ts +0 -3
  64. package/dist/protocols/utils/tool-schema.js +0 -4
  65. package/dist/protocols/utils/tool-stream.d.ts +1 -1
  66. package/dist/protocols/venice-chat.d.ts +52 -53
  67. package/dist/protocols/venice-chat.js +6 -5
  68. package/dist/protocols/xai-images.js +3 -4
  69. package/dist/protocols/xai-responses.d.ts +81 -81
  70. package/dist/protocols/zai-chat.d.ts +33 -30
  71. package/dist/protocols/zai-chat.js +8 -3
  72. package/dist/protocols/zai-messages.d.ts +21 -19
  73. package/dist/protocols/zai-messages.js +3 -2
  74. package/dist/provider-error.js +8 -7
  75. package/dist/providers/alibaba.d.ts +74 -74
  76. package/dist/providers/amazon-bedrock-mantle.d.ts +202 -202
  77. package/dist/providers/amazon-bedrock.d.ts +16 -13
  78. package/dist/providers/anthropic-compatible.d.ts +13 -13
  79. package/dist/providers/anthropic.d.ts +13 -13
  80. package/dist/providers/azure.d.ts +112 -112
  81. package/dist/providers/baseten.d.ts +24 -24
  82. package/dist/providers/cerebras.d.ts +24 -24
  83. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -234
  84. package/dist/providers/cloudflare-ai-gateway.js +3 -6
  85. package/dist/providers/cloudflare-workers-ai.d.ts +24 -24
  86. package/dist/providers/cohere.d.ts +78 -74
  87. package/dist/providers/deepinfra.d.ts +24 -24
  88. package/dist/providers/deepseek.d.ts +24 -24
  89. package/dist/providers/digitalocean.d.ts +36 -36
  90. package/dist/providers/fireworks.d.ts +24 -24
  91. package/dist/providers/google-vertex-chat.d.ts +12 -12
  92. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  93. package/dist/providers/google-vertex-messages.d.ts +20 -20
  94. package/dist/providers/google-vertex-mistral.d.ts +14 -14
  95. package/dist/providers/google-vertex-responses.d.ts +38 -38
  96. package/dist/providers/google-vertex.d.ts +17 -17
  97. package/dist/providers/google-vertex.js +2 -2
  98. package/dist/providers/google.d.ts +79 -79
  99. package/dist/providers/groq.d.ts +24 -24
  100. package/dist/providers/meta.d.ts +189 -189
  101. package/dist/providers/minimax.d.ts +202 -202
  102. package/dist/providers/mistral.d.ts +28 -28
  103. package/dist/providers/moonshot.d.ts +202 -202
  104. package/dist/providers/open-responses-options.d.ts +0 -1
  105. package/dist/providers/open-responses-options.js +1 -1
  106. package/dist/providers/openai-compatible-responses.d.ts +38 -38
  107. package/dist/providers/openai-compatible.d.ts +12 -12
  108. package/dist/providers/openai-compatible.js +1 -1
  109. package/dist/providers/openai-options.d.ts +3 -4
  110. package/dist/providers/openai-options.js +0 -1
  111. package/dist/providers/openai.d.ts +103 -103
  112. package/dist/providers/openrouter.d.ts +171 -112
  113. package/dist/providers/openrouter.js +40 -33
  114. package/dist/providers/togetherai.d.ts +24 -24
  115. package/dist/providers/venice.d.ts +195 -20
  116. package/dist/providers/xai.d.ts +12 -12
  117. package/dist/providers/zai-coding-plan.d.ts +152 -72
  118. package/dist/providers/zai.d.ts +84 -19
  119. package/dist/route/auth-options.d.ts +0 -3
  120. package/dist/route/auth.d.ts +0 -2
  121. package/dist/route/auth.js +0 -2
  122. package/dist/route/client.d.ts +0 -218
  123. package/dist/route/client.js +3 -7
  124. package/dist/route/executor-service.js +1 -1
  125. package/dist/route/transport/http.js +5 -8
  126. package/dist/schema/errors.d.ts +1 -1
  127. package/dist/schema/errors.js +1 -1
  128. package/dist/schema/messages.js +4 -7
  129. package/dist/speech-client.d.ts +11 -9
  130. package/dist/speech.d.ts +158 -150
  131. package/dist/speech.js +2 -2
  132. package/dist/transcription-client.d.ts +11 -9
  133. package/dist/transcription.d.ts +158 -150
  134. package/dist/transcription.js +2 -2
  135. package/dist/video-client.d.ts +11 -9
  136. package/dist/video.d.ts +124 -116
  137. package/dist/video.js +2 -2
  138. package/package.json +7 -6
  139. package/dist/protocols/utils/openai-options.d.ts +0 -16
  140. package/dist/protocols/utils/openai-options.js +0 -15
@@ -13,10 +13,6 @@ export type OptionsInput = typeof Options.Type;
13
13
  export declare const protocol: Protocol<{
14
14
  readonly model: string;
15
15
  readonly input: readonly ({
16
- readonly type: "compaction";
17
- readonly id?: string | null | undefined;
18
- readonly encrypted_content: string;
19
- } | {
20
16
  readonly type: "configuration_update";
21
17
  readonly reasoning: {
22
18
  readonly effort: OpenResponsesOptions.ReasoningEffort;
@@ -29,10 +25,45 @@ export declare const protocol: Protocol<{
29
25
  readonly type: "message";
30
26
  readonly role: "developer";
31
27
  readonly content: string;
28
+ } | {
29
+ readonly type: "function_call_output";
30
+ readonly call_id: string;
31
+ readonly output: string | readonly ({
32
+ readonly type: "input_text";
33
+ readonly text: string;
34
+ } | {
35
+ readonly type: "input_video";
36
+ readonly video_url: string;
37
+ } | {
38
+ readonly type: "input_image";
39
+ readonly image_url: string;
40
+ readonly detail?: string | undefined;
41
+ } | {
42
+ readonly type: "input_file";
43
+ readonly filename: string;
44
+ readonly detail?: string | undefined;
45
+ readonly file_data?: string | undefined;
46
+ readonly file_url?: string | undefined;
47
+ })[];
48
+ } | {
49
+ readonly type: "reasoning";
50
+ readonly id?: string | undefined;
51
+ readonly summary: readonly {
52
+ readonly type: "summary_text";
53
+ readonly text: string;
54
+ }[];
55
+ readonly encrypted_content?: string | null | undefined;
56
+ } | {
57
+ readonly type: "compaction";
58
+ readonly id?: string | null | undefined;
59
+ readonly encrypted_content: string;
32
60
  } | {
33
61
  readonly type: "message";
34
62
  readonly role: "user";
35
63
  readonly content: readonly ({
64
+ readonly type: "input_text";
65
+ readonly text: string;
66
+ } | {
36
67
  readonly type: "input_image";
37
68
  readonly image_url: string;
38
69
  readonly detail?: string | undefined;
@@ -42,9 +73,6 @@ export declare const protocol: Protocol<{
42
73
  readonly detail?: string | undefined;
43
74
  readonly file_data?: string | undefined;
44
75
  readonly file_url?: string | undefined;
45
- } | {
46
- readonly type: "input_text";
47
- readonly text: string;
48
76
  })[];
49
77
  readonly id?: string | undefined;
50
78
  readonly status?: string | undefined;
@@ -58,14 +86,6 @@ export declare const protocol: Protocol<{
58
86
  }[];
59
87
  readonly phase?: "commentary" | "final_answer" | null | undefined;
60
88
  readonly status?: string | undefined;
61
- } | {
62
- readonly type: "reasoning";
63
- readonly id?: string | undefined;
64
- readonly summary: readonly {
65
- readonly type: "summary_text";
66
- readonly text: string;
67
- }[];
68
- readonly encrypted_content?: string | null | undefined;
69
89
  } | {
70
90
  readonly type: "function_call";
71
91
  readonly id?: string | undefined;
@@ -73,26 +93,6 @@ export declare const protocol: Protocol<{
73
93
  readonly name: string;
74
94
  readonly namespace?: string | undefined;
75
95
  readonly arguments: string;
76
- } | {
77
- readonly type: "function_call_output";
78
- readonly call_id: string;
79
- readonly output: string | readonly ({
80
- readonly type: "input_image";
81
- readonly image_url: string;
82
- readonly detail?: string | undefined;
83
- } | {
84
- readonly type: "input_file";
85
- readonly filename: string;
86
- readonly detail?: string | undefined;
87
- readonly file_data?: string | undefined;
88
- readonly file_url?: string | undefined;
89
- } | {
90
- readonly type: "input_text";
91
- readonly text: string;
92
- } | {
93
- readonly type: "input_video";
94
- readonly video_url: string;
95
- })[];
96
96
  } | {
97
97
  readonly [x: string]: unknown;
98
98
  readonly type: "web_search_call";
@@ -169,15 +169,15 @@ export declare const protocol: Protocol<{
169
169
  } | undefined;
170
170
  readonly top_logprobs?: number | undefined;
171
171
  readonly truncation?: "auto" | "disabled" | undefined;
172
- readonly service_tier?: OpenResponsesOptions.ServiceTier | undefined;
172
+ readonly service_tier?: import("../index.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
173
173
  readonly prompt_cache_key?: string | undefined;
174
- readonly include?: readonly OpenResponsesOptions.ResponseIncludable[] | undefined;
174
+ readonly include?: readonly import("../index.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
175
175
  readonly reasoning?: {
176
176
  readonly effort?: OpenResponsesOptions.ReasoningEffort | undefined;
177
177
  readonly summary?: "auto" | "concise" | "detailed" | undefined;
178
178
  } | undefined;
179
179
  readonly text?: {
180
- readonly verbosity?: OpenResponsesOptions.TextVerbosity | undefined;
180
+ readonly verbosity?: import("../index.js").OpenString<"high" | "low" | "medium"> | undefined;
181
181
  } | undefined;
182
182
  readonly max_output_tokens?: number | undefined;
183
183
  readonly max_tool_calls?: number | undefined;
@@ -10,7 +10,6 @@ export declare const DEFAULT_BASE_URL = "https://api.anthropic.com/v1";
10
10
  export declare const PATH = "/messages";
11
11
  export declare const DEFAULT_MAX_TOKENS = 32000;
12
12
  export declare const framing: Framing.Definition<string>;
13
- export type ThinkingBlockBinding = typeof AnthropicThinkingBlockBinding.Type;
14
13
  export type ThinkingInput = typeof Thinking.Encoded;
15
14
  /** Caller-facing provider options; unknown keys are accepted and ignored. `Options.Type` is the wire-ready form. */
16
15
  export type OptionsInput = ProviderOptions & typeof Options.Encoded;
@@ -27,9 +26,6 @@ export declare const ContextManagement: Schema.Struct<{
27
26
  }>>;
28
27
  }>;
29
28
  export type ContextManagement = typeof ContextManagement.Type;
30
- declare const AnthropicThinkingBlockBinding: Schema.Struct<{
31
- readonly prefix_mismatch_behavior: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"drop_block" | "error">, import("../schema/options.js").OpenString<"drop_block" | "error">>>;
32
- }>;
33
29
  declare const Thinking: Schema.Union<readonly [Schema.decodeTo<Schema.Struct<{
34
30
  readonly display: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"omitted" | "summarized">, import("../schema/options.js").OpenString<"omitted" | "summarized">>>;
35
31
  readonly block_binding: Schema.optional<Schema.Struct<{
@@ -553,12 +549,30 @@ export declare const protocol: Protocol<{
553
549
  } | {
554
550
  readonly role: "assistant";
555
551
  readonly content: readonly ({
552
+ readonly type: "compaction";
553
+ readonly content: string | null;
554
+ } | {
556
555
  readonly type: "text";
557
556
  readonly text: string;
558
557
  readonly cache_control?: {
559
558
  readonly type: "ephemeral";
560
559
  readonly ttl?: "1h" | "5m" | undefined;
561
560
  } | undefined;
561
+ } | {
562
+ readonly type: "thinking";
563
+ readonly thinking: string;
564
+ readonly signature: string;
565
+ readonly cache_control?: {
566
+ readonly type: "ephemeral";
567
+ readonly ttl?: "1h" | "5m" | undefined;
568
+ } | undefined;
569
+ } | {
570
+ readonly type: "redacted_thinking";
571
+ readonly data: string;
572
+ readonly cache_control?: {
573
+ readonly type: "ephemeral";
574
+ readonly ttl?: "1h" | "5m" | undefined;
575
+ } | undefined;
562
576
  } | {
563
577
  readonly type: "tool_use";
564
578
  readonly id: string;
@@ -585,24 +599,6 @@ export declare const protocol: Protocol<{
585
599
  readonly type: "ephemeral";
586
600
  readonly ttl?: "1h" | "5m" | undefined;
587
601
  } | undefined;
588
- } | {
589
- readonly type: "compaction";
590
- readonly content: string | null;
591
- } | {
592
- readonly type: "thinking";
593
- readonly thinking: string;
594
- readonly signature: string;
595
- readonly cache_control?: {
596
- readonly type: "ephemeral";
597
- readonly ttl?: "1h" | "5m" | undefined;
598
- } | undefined;
599
- } | {
600
- readonly type: "redacted_thinking";
601
- readonly data: string;
602
- readonly cache_control?: {
603
- readonly type: "ephemeral";
604
- readonly ttl?: "1h" | "5m" | undefined;
605
- } | undefined;
606
602
  })[];
607
603
  } | {
608
604
  readonly role: "system";
@@ -644,6 +640,8 @@ export declare const protocol: Protocol<{
644
640
  readonly top_k?: number | undefined;
645
641
  readonly stop_sequences?: readonly string[] | undefined;
646
642
  readonly thinking?: {
643
+ readonly type: "between_tools" | "disabled";
644
+ } | {
647
645
  readonly display?: import("../schema/options.js").OpenString<"omitted" | "summarized"> | undefined;
648
646
  readonly block_binding?: {
649
647
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
@@ -656,8 +654,6 @@ export declare const protocol: Protocol<{
656
654
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
657
655
  } | undefined;
658
656
  readonly type: "adaptive";
659
- } | {
660
- readonly type: "between_tools" | "disabled";
661
657
  } | undefined;
662
658
  readonly output_config?: {
663
659
  readonly effort?: string | undefined;
@@ -913,12 +909,30 @@ export declare const route: Route<{
913
909
  } | {
914
910
  readonly role: "assistant";
915
911
  readonly content: readonly ({
912
+ readonly type: "compaction";
913
+ readonly content: string | null;
914
+ } | {
916
915
  readonly type: "text";
917
916
  readonly text: string;
918
917
  readonly cache_control?: {
919
918
  readonly type: "ephemeral";
920
919
  readonly ttl?: "1h" | "5m" | undefined;
921
920
  } | undefined;
921
+ } | {
922
+ readonly type: "thinking";
923
+ readonly thinking: string;
924
+ readonly signature: string;
925
+ readonly cache_control?: {
926
+ readonly type: "ephemeral";
927
+ readonly ttl?: "1h" | "5m" | undefined;
928
+ } | undefined;
929
+ } | {
930
+ readonly type: "redacted_thinking";
931
+ readonly data: string;
932
+ readonly cache_control?: {
933
+ readonly type: "ephemeral";
934
+ readonly ttl?: "1h" | "5m" | undefined;
935
+ } | undefined;
922
936
  } | {
923
937
  readonly type: "tool_use";
924
938
  readonly id: string;
@@ -945,24 +959,6 @@ export declare const route: Route<{
945
959
  readonly type: "ephemeral";
946
960
  readonly ttl?: "1h" | "5m" | undefined;
947
961
  } | undefined;
948
- } | {
949
- readonly type: "compaction";
950
- readonly content: string | null;
951
- } | {
952
- readonly type: "thinking";
953
- readonly thinking: string;
954
- readonly signature: string;
955
- readonly cache_control?: {
956
- readonly type: "ephemeral";
957
- readonly ttl?: "1h" | "5m" | undefined;
958
- } | undefined;
959
- } | {
960
- readonly type: "redacted_thinking";
961
- readonly data: string;
962
- readonly cache_control?: {
963
- readonly type: "ephemeral";
964
- readonly ttl?: "1h" | "5m" | undefined;
965
- } | undefined;
966
962
  })[];
967
963
  } | {
968
964
  readonly role: "system";
@@ -1004,6 +1000,8 @@ export declare const route: Route<{
1004
1000
  readonly top_k?: number | undefined;
1005
1001
  readonly stop_sequences?: readonly string[] | undefined;
1006
1002
  readonly thinking?: {
1003
+ readonly type: "between_tools" | "disabled";
1004
+ } | {
1007
1005
  readonly display?: import("../schema/options.js").OpenString<"omitted" | "summarized"> | undefined;
1008
1006
  readonly block_binding?: {
1009
1007
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
@@ -1016,8 +1014,6 @@ export declare const route: Route<{
1016
1014
  readonly prefix_mismatch_behavior?: import("../schema/options.js").OpenString<"drop_block" | "error"> | undefined;
1017
1015
  } | undefined;
1018
1016
  readonly type: "adaptive";
1019
- } | {
1020
- readonly type: "between_tools" | "disabled";
1021
1017
  } | undefined;
1022
1018
  readonly output_config?: {
1023
1019
  readonly effort?: string | undefined;
@@ -400,13 +400,13 @@ const cacheControl = (breakpoints, cache) => {
400
400
  const providerMetadata = (key, metadata) => ({ [key]: metadata });
401
401
  const signatureFromMetadata = (metadata, key) => {
402
402
  const provider = metadata?.[key];
403
- if (!ProviderShared.isRecord(provider))
403
+ if (!provider)
404
404
  return undefined;
405
405
  return typeof provider.signature === "string" ? provider.signature : undefined;
406
406
  };
407
407
  const redactedDataFromMetadata = (metadata, key) => {
408
408
  const provider = metadata?.[key];
409
- if (!ProviderShared.isRecord(provider))
409
+ if (!provider)
410
410
  return undefined;
411
411
  return typeof provider.redactedData === "string" ? provider.redactedData : undefined;
412
412
  };
@@ -477,7 +477,7 @@ const lowerServerToolResult = Effect.fnUntraced(function* (part, providerMetadat
477
477
  };
478
478
  });
479
479
  const fileIdFromMetadata = (metadata) => {
480
- if (!ProviderShared.isRecord(metadata))
480
+ if (!metadata)
481
481
  return undefined;
482
482
  const anthropic = metadata.anthropic;
483
483
  if (ProviderShared.isRecord(anthropic)) {
@@ -493,7 +493,7 @@ const fileIdFromMetadata = (metadata) => {
493
493
  return undefined;
494
494
  };
495
495
  const transformationsFromMetadata = (metadata) => {
496
- if (!ProviderShared.isRecord(metadata))
496
+ if (!metadata)
497
497
  return undefined;
498
498
  const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
499
499
  const raw = anthropic?.transformations ?? metadata.transformations;
@@ -507,19 +507,19 @@ const transformationsFromMetadata = (metadata) => {
507
507
  return undefined;
508
508
  };
509
509
  const documentTitleFromPart = (part) => {
510
- if (ProviderShared.isRecord(part.metadata)) {
510
+ if (part.metadata !== undefined) {
511
511
  const anthropic = part.metadata.anthropic;
512
512
  if (ProviderShared.isRecord(anthropic) && typeof anthropic.title === "string")
513
513
  return anthropic.title;
514
514
  if (typeof part.metadata.title === "string")
515
515
  return part.metadata.title;
516
516
  }
517
- if (typeof part.filename === "string" && part.filename.length > 0)
517
+ if (part.filename && part.filename.length > 0)
518
518
  return part.filename;
519
519
  return undefined;
520
520
  };
521
521
  const documentContextFromMetadata = (metadata) => {
522
- if (!ProviderShared.isRecord(metadata))
522
+ if (!metadata)
523
523
  return undefined;
524
524
  const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
525
525
  if (anthropic && typeof anthropic.context === "string")
@@ -529,7 +529,7 @@ const documentContextFromMetadata = (metadata) => {
529
529
  return undefined;
530
530
  };
531
531
  const citationsFromMetadata = (metadata) => {
532
- if (!ProviderShared.isRecord(metadata))
532
+ if (!metadata)
533
533
  return undefined;
534
534
  const raw = ProviderShared.isRecord(metadata.anthropic)
535
535
  ? (metadata.anthropic.citations ?? metadata.citations)
@@ -678,7 +678,7 @@ const requireThinkingSignature = (request) => {
678
678
  };
679
679
  // Opus 4.8 and every Claude 5 model accept mid-conversation system messages; later versions inherit support.
680
680
  const supportsNativeSystemUpdates = (request) => {
681
- const version = claudeVersion(String(request.model.id));
681
+ const version = claudeVersion(request.model.id);
682
682
  if (version === undefined)
683
683
  return false;
684
684
  if (version.family === "opus" && version.major === 4)
@@ -723,7 +723,7 @@ const appendToUserTurn = (messages, block) => {
723
723
  };
724
724
  const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
725
725
  const messages = [];
726
- const providerMetadataKey = request.model.route.providerMetadataKey ?? String(request.model.provider);
726
+ const providerMetadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
727
727
  // Text updates stay where they are unless a user turn follows them; then they move after the latest
728
728
  // user turn, the nearest spot where Anthropic accepts a native system message.
729
729
  const holdUpdates = supportsNativeSystemUpdates(request);
@@ -796,7 +796,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
796
796
  content.push({ type: "redacted_thinking", data: redactedData });
797
797
  continue;
798
798
  }
799
- if (typeof signature !== "string" || signature.trim().length === 0) {
799
+ if (!signature || signature.trim().length === 0) {
800
800
  if (part.text.trim().length === 0)
801
801
  continue;
802
802
  if (!requireThinkingSignature(request)) {
@@ -1044,9 +1044,7 @@ const isServerToolResultType = (type) => type in SERVER_TOOL_RESULT_NAMES;
1044
1044
  const serverToolResultEvent = (block, providerMetadataKey) => {
1045
1045
  if (!block.type || !isServerToolResultType(block.type))
1046
1046
  return undefined;
1047
- const errorPayload = typeof block.content === "object" && block.content !== null && "type" in block.content
1048
- ? String(block.content.type)
1049
- : "";
1047
+ const errorPayload = ProviderShared.isRecord(block.content) && "type" in block.content ? String(block.content.type) : "";
1050
1048
  const isError = errorPayload.endsWith("_tool_result_error");
1051
1049
  return LLMEvent.toolResult({
1052
1050
  id: block.tool_use_id ?? "",
@@ -1387,7 +1385,7 @@ export const protocol = Protocol.make({
1387
1385
  initial: (request) => ({
1388
1386
  provider: request.model.provider,
1389
1387
  compactions: {},
1390
- providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
1388
+ providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
1391
1389
  tools: ToolStream.empty(),
1392
1390
  reasoningSignatures: {},
1393
1391
  lifecycle: Lifecycle.initial(),
@@ -2,7 +2,6 @@ import { Schema } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
4
  import { Usage, type FinishReasonDetails } from "../schema/index.js";
5
- import { BedrockAuth } from "./utils/bedrock-auth.js";
6
5
  import { Lifecycle } from "./utils/lifecycle.js";
7
6
  import { ToolStream } from "./utils/tool-stream.js";
8
7
  export type { Credentials as BedrockCredentials } from "./utils/bedrock-auth.js";
@@ -146,6 +145,21 @@ export declare const protocol: Protocol<{
146
145
  readonly type: "default";
147
146
  readonly ttl?: "1h" | "5m" | undefined;
148
147
  };
148
+ } | {
149
+ readonly image: {
150
+ readonly format: "gif" | "jpeg" | "png" | "webp";
151
+ readonly source: {
152
+ readonly bytes: string;
153
+ };
154
+ };
155
+ } | {
156
+ readonly document: {
157
+ readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
158
+ readonly name: string;
159
+ readonly source: {
160
+ readonly bytes: string;
161
+ };
162
+ };
149
163
  } | {
150
164
  readonly text: string;
151
165
  } | {
@@ -173,21 +187,6 @@ export declare const protocol: Protocol<{
173
187
  })[];
174
188
  readonly status?: "error" | "success" | undefined;
175
189
  };
176
- } | {
177
- readonly image: {
178
- readonly format: "gif" | "jpeg" | "png" | "webp";
179
- readonly source: {
180
- readonly bytes: string;
181
- };
182
- };
183
- } | {
184
- readonly document: {
185
- readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
186
- readonly name: string;
187
- readonly source: {
188
- readonly bytes: string;
189
- };
190
- };
191
190
  })[];
192
191
  } | {
193
192
  readonly role: "assistant";
@@ -260,58 +259,8 @@ export declare const protocol: Protocol<{
260
259
  readonly [x: string]: unknown;
261
260
  } | undefined;
262
261
  }, {
263
- readonly messageStart?: {
264
- readonly role: string;
265
- } | undefined;
266
- readonly contentBlockStart?: {
267
- readonly contentBlockIndex: number;
268
- readonly start?: {
269
- readonly toolUse?: {
270
- readonly toolUseId: string;
271
- readonly name: string;
272
- } | undefined;
273
- } | undefined;
274
- } | undefined;
275
- readonly contentBlockDelta?: {
276
- readonly contentBlockIndex: number;
277
- readonly delta?: {
278
- readonly text?: string | undefined;
279
- readonly toolUse?: {
280
- readonly input: string;
281
- } | undefined;
282
- readonly reasoningContent?: {
283
- readonly text?: string | undefined;
284
- readonly signature?: string | undefined;
285
- readonly redactedContent?: string | undefined;
286
- readonly data?: string | undefined;
287
- } | undefined;
288
- } | undefined;
289
- } | undefined;
290
- readonly contentBlockStop?: {
291
- readonly contentBlockIndex: number;
292
- } | undefined;
293
- readonly messageStop?: {
294
- readonly stopReason: string;
295
- readonly additionalModelResponseFields?: unknown;
296
- } | undefined;
297
- readonly metadata?: {
298
- readonly usage?: {
299
- readonly inputTokens?: number | undefined;
300
- readonly outputTokens?: number | undefined;
301
- readonly totalTokens?: number | undefined;
302
- readonly cacheReadInputTokens?: number | undefined;
303
- readonly cacheWriteInputTokens?: number | undefined;
304
- } | undefined;
305
- readonly metrics?: unknown;
306
- } | undefined;
307
- readonly exception?: {
308
- readonly type: string;
309
- readonly details: {
310
- readonly message?: string | undefined;
311
- readonly originalMessage?: string | undefined;
312
- readonly originalStatusCode?: number | undefined;
313
- };
314
- } | undefined;
262
+ readonly [x: string]: unknown;
263
+ readonly rawBody: string;
315
264
  }, {
316
265
  readonly messageStart?: {
317
266
  readonly role: string;
@@ -384,6 +333,21 @@ export declare const route: Route<{
384
333
  readonly type: "default";
385
334
  readonly ttl?: "1h" | "5m" | undefined;
386
335
  };
336
+ } | {
337
+ readonly image: {
338
+ readonly format: "gif" | "jpeg" | "png" | "webp";
339
+ readonly source: {
340
+ readonly bytes: string;
341
+ };
342
+ };
343
+ } | {
344
+ readonly document: {
345
+ readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
346
+ readonly name: string;
347
+ readonly source: {
348
+ readonly bytes: string;
349
+ };
350
+ };
387
351
  } | {
388
352
  readonly text: string;
389
353
  } | {
@@ -411,21 +375,6 @@ export declare const route: Route<{
411
375
  })[];
412
376
  readonly status?: "error" | "success" | undefined;
413
377
  };
414
- } | {
415
- readonly image: {
416
- readonly format: "gif" | "jpeg" | "png" | "webp";
417
- readonly source: {
418
- readonly bytes: string;
419
- };
420
- };
421
- } | {
422
- readonly document: {
423
- readonly format: "csv" | "doc" | "docx" | "html" | "md" | "pdf" | "txt" | "xls" | "xlsx";
424
- readonly name: string;
425
- readonly source: {
426
- readonly bytes: string;
427
- };
428
- };
429
378
  })[];
430
379
  } | {
431
380
  readonly role: "assistant";
@@ -497,6 +446,8 @@ export declare const route: Route<{
497
446
  readonly additionalModelRequestFields?: {
498
447
  readonly [x: string]: unknown;
499
448
  } | undefined;
500
- }, import("../route/transport/http.js").HttpPrepared<object>, import("../route/client.js").CompactionOperations | undefined>;
501
- export declare const sigV4Auth: typeof BedrockAuth.sigV4;
449
+ }, import("../route/transport/http.js").HttpPrepared<{
450
+ readonly [x: string]: unknown;
451
+ readonly rawBody: string;
452
+ }>, import("../route/client.js").CompactionOperations | undefined>;
502
453
  export * as BedrockConverse from "./bedrock-converse.js";
@@ -189,12 +189,12 @@ const reasoningSignature = (part, providerMetadataKey) => {
189
189
  const metadata = part.providerMetadata?.[providerMetadataKey];
190
190
  if (part.encrypted !== undefined)
191
191
  return part.encrypted;
192
- if (ProviderShared.isRecord(metadata) && typeof metadata.signature === "string")
192
+ if (typeof metadata?.signature === "string")
193
193
  return metadata.signature;
194
194
  };
195
195
  const reasoningRedactedData = (part, providerMetadataKey) => {
196
196
  const metadata = part.providerMetadata?.[providerMetadataKey];
197
- if (ProviderShared.isRecord(metadata) && typeof metadata.redactedData === "string")
197
+ if (typeof metadata?.redactedData === "string")
198
198
  return metadata.redactedData;
199
199
  };
200
200
  const removeEmptyToolInputKeys = (input) => {
@@ -244,7 +244,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
244
244
  const documentNames = new Set();
245
245
  // Mistral can reject replay IDs even when they satisfy Converse's broader ID syntax.
246
246
  const normalizeID = request.model.id.includes("mistral.") ? MistralToolID.normalizer(request) : (id) => id;
247
- const providerMetadataKey = request.model.route.providerMetadataKey ?? String(request.model.provider);
247
+ const providerMetadataKey = request.model.route.providerMetadataKey ?? request.model.provider;
248
248
  const hoistImages = !keepToolImagesInline(request.model.id);
249
249
  // Bedrock expects parallel tool results before any images hoisted beside them.
250
250
  const pendingImages = [];
@@ -647,6 +647,7 @@ const step = (state, event) => Effect.gen(function* () {
647
647
  return yield* new AIError({
648
648
  reason: classifyProviderFailure({
649
649
  message,
650
+ status: event.exception.details.originalStatusCode,
650
651
  rawBody: body,
651
652
  }),
652
653
  });
@@ -690,9 +691,9 @@ export const protocol = Protocol.make({
690
691
  from: fromRequest,
691
692
  },
692
693
  stream: {
693
- event: BedrockEvent,
694
+ event: BedrockEventStream.Frame.pipe(Schema.decodeTo(BedrockEvent)),
694
695
  initial: (request) => ({
695
- providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
696
+ providerMetadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
696
697
  tools: ToolStream.empty(),
697
698
  finishReason: undefined,
698
699
  usage: undefined,
@@ -717,5 +718,4 @@ export const route = Route.make({
717
718
  auth: BedrockAuth.auth,
718
719
  framing,
719
720
  });
720
- export const sigV4Auth = BedrockAuth.sigV4;
721
721
  export * as BedrockConverse from "./bedrock-converse.js";
@@ -1,9 +1,14 @@
1
+ import { Schema } from "effect";
1
2
  import { Framing } from "../route/framing.js";
3
+ export declare const Frame: Schema.StructWithRest<Schema.Struct<{
4
+ readonly rawBody: Schema.String;
5
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
6
+ export type Frame = typeof Frame.Type;
2
7
  /**
3
8
  * AWS event-stream framing for Bedrock Converse. Each frame is decoded by
4
9
  * `@smithy/eventstream-codec` (length + header + payload + CRC) and rewrapped
5
10
  * under its `:event-type` header so the chunk schema can match the JSON
6
11
  * payload directly.
7
12
  */
8
- export declare const framing: (route: string) => Framing.Definition<object>;
13
+ export declare const framing: (route: string) => Framing.Definition<Frame>;
9
14
  export * as BedrockEventStream from "./bedrock-event-stream.js";