@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
@@ -4,7 +4,7 @@ import { Media } from "../media.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
6
6
  import { mergeJsonRecords } from "../schema/index.js";
7
- import { ProviderShared, optionalNull } from "./shared.js";
7
+ import { JsonObject, ProviderShared, lenient, optionalNull } from "./shared.js";
8
8
  import { MediaInput } from "./utils/media-input.js";
9
9
  const route = MediaProtocol.identity({ id: "xai-images", name: "xAI Images", provider: "xai" });
10
10
  export const DEFAULT_BASE_URL = "https://api.x.ai/v1";
@@ -20,7 +20,7 @@ const XAIImageResponse = Schema.Struct({
20
20
  revised_prompt: optionalNull(Schema.String),
21
21
  mime_type: optionalNull(Schema.String),
22
22
  })),
23
- usage: Schema.optional(Schema.Unknown),
23
+ usage: lenient(JsonObject),
24
24
  });
25
25
  // ---------------------------------------------------------------------------
26
26
  // 5. Request body construction
@@ -59,12 +59,11 @@ const decodeResponse = Effect.fn("XAIImages.decodeResponse")(function* (response
59
59
  }));
60
60
  if (images.length === 0)
61
61
  return yield* output.invalid(`${route.name} returned no images`);
62
- const usage = ProviderShared.isRecord(decoded.usage) ? decoded.usage : undefined;
63
62
  // xAI reports a USD cost (`cost_in_usd_ticks`) rather than tokens, seconds, or credits; the raw record stays in
64
63
  // provider metadata.
65
64
  return new ImageResponse({
66
65
  images,
67
- providerMetadata: usage === undefined ? undefined : { xai: { usage } },
66
+ providerMetadata: decoded.usage === undefined ? undefined : { xai: { usage: decoded.usage } },
68
67
  });
69
68
  });
70
69
  // ---------------------------------------------------------------------------
@@ -3,55 +3,10 @@ import { OpenResponses } from "./open-responses.js";
3
3
  export declare const protocol: Protocol<{
4
4
  readonly model: string;
5
5
  readonly input: readonly ({
6
- readonly [x: string]: unknown;
7
- readonly type: "web_search_call";
8
- readonly id: string;
9
- readonly status?: string | undefined;
10
- readonly action?: {
11
- readonly [x: string]: unknown;
12
- } | null | undefined;
13
- } | {
14
- readonly [x: string]: unknown;
15
- readonly type: "file_search_call";
16
- readonly id: string;
17
- readonly status?: string | undefined;
18
- readonly queries?: readonly string[] | undefined;
19
- readonly results?: readonly {
20
- readonly [x: string]: unknown;
21
- }[] | null | undefined;
22
- } | {
23
- readonly [x: string]: unknown;
24
- readonly type: "code_interpreter_call";
25
- readonly id: string;
26
- readonly status?: string | undefined;
27
- readonly code?: string | null | undefined;
28
- readonly container_id?: string | null | undefined;
29
- readonly outputs?: readonly {
30
- readonly [x: string]: unknown;
31
- }[] | null | undefined;
32
- } | {
33
- readonly [x: string]: unknown;
34
- readonly type: "mcp_call";
35
- readonly id: string;
36
- readonly status?: string | undefined;
37
- readonly server_label?: string | undefined;
38
- readonly name?: string | undefined;
39
- readonly arguments?: string | undefined;
40
- readonly output?: string | null | undefined;
41
- readonly error?: unknown;
42
- } | {
43
6
  readonly type: "configuration_update";
44
7
  readonly reasoning: {
45
8
  readonly effort: import("../schema/options.js").ReasoningEffort;
46
9
  };
47
- } | {
48
- readonly [x: string]: unknown;
49
- readonly type: string;
50
- readonly id: string;
51
- } | {
52
- readonly type: "compaction";
53
- readonly id?: string | null | undefined;
54
- readonly encrypted_content: string;
55
10
  } | {
56
11
  readonly type: "message";
57
12
  readonly role: "system";
@@ -60,10 +15,45 @@ export declare const protocol: Protocol<{
60
15
  readonly type: "message";
61
16
  readonly role: "developer";
62
17
  readonly content: string;
18
+ } | {
19
+ readonly type: "function_call_output";
20
+ readonly call_id: string;
21
+ readonly output: string | readonly ({
22
+ readonly type: "input_text";
23
+ readonly text: string;
24
+ } | {
25
+ readonly type: "input_video";
26
+ readonly video_url: string;
27
+ } | {
28
+ readonly type: "input_image";
29
+ readonly image_url: string;
30
+ readonly detail?: string | undefined;
31
+ } | {
32
+ readonly type: "input_file";
33
+ readonly filename: string;
34
+ readonly detail?: string | undefined;
35
+ readonly file_data?: string | undefined;
36
+ readonly file_url?: string | undefined;
37
+ })[];
38
+ } | {
39
+ readonly type: "reasoning";
40
+ readonly id?: string | undefined;
41
+ readonly summary: readonly {
42
+ readonly type: "summary_text";
43
+ readonly text: string;
44
+ }[];
45
+ readonly encrypted_content?: string | null | undefined;
46
+ } | {
47
+ readonly type: "compaction";
48
+ readonly id?: string | null | undefined;
49
+ readonly encrypted_content: string;
63
50
  } | {
64
51
  readonly type: "message";
65
52
  readonly role: "user";
66
53
  readonly content: readonly ({
54
+ readonly type: "input_text";
55
+ readonly text: string;
56
+ } | {
67
57
  readonly type: "input_image";
68
58
  readonly image_url: string;
69
59
  readonly detail?: string | undefined;
@@ -73,9 +63,6 @@ export declare const protocol: Protocol<{
73
63
  readonly detail?: string | undefined;
74
64
  readonly file_data?: string | undefined;
75
65
  readonly file_url?: string | undefined;
76
- } | {
77
- readonly type: "input_text";
78
- readonly text: string;
79
66
  })[];
80
67
  readonly id?: string | undefined;
81
68
  readonly status?: string | undefined;
@@ -89,14 +76,6 @@ export declare const protocol: Protocol<{
89
76
  }[];
90
77
  readonly phase?: "commentary" | "final_answer" | null | undefined;
91
78
  readonly status?: string | undefined;
92
- } | {
93
- readonly type: "reasoning";
94
- readonly id?: string | undefined;
95
- readonly summary: readonly {
96
- readonly type: "summary_text";
97
- readonly text: string;
98
- }[];
99
- readonly encrypted_content?: string | null | undefined;
100
79
  } | {
101
80
  readonly type: "function_call";
102
81
  readonly id?: string | undefined;
@@ -105,31 +84,49 @@ export declare const protocol: Protocol<{
105
84
  readonly namespace?: string | undefined;
106
85
  readonly arguments: string;
107
86
  } | {
108
- readonly type: "function_call_output";
109
- readonly call_id: string;
110
- readonly output: string | readonly ({
111
- readonly type: "input_image";
112
- readonly image_url: string;
113
- readonly detail?: string | undefined;
114
- } | {
115
- readonly type: "input_file";
116
- readonly filename: string;
117
- readonly detail?: string | undefined;
118
- readonly file_data?: string | undefined;
119
- readonly file_url?: string | undefined;
120
- } | {
121
- readonly type: "input_text";
122
- readonly text: string;
123
- } | {
124
- readonly type: "input_video";
125
- readonly video_url: string;
126
- })[];
87
+ readonly [x: string]: unknown;
88
+ readonly type: "web_search_call";
89
+ readonly id: string;
90
+ readonly status?: string | undefined;
91
+ readonly action?: {
92
+ readonly [x: string]: unknown;
93
+ } | null | undefined;
94
+ } | {
95
+ readonly [x: string]: unknown;
96
+ readonly type: "file_search_call";
97
+ readonly id: string;
98
+ readonly status?: string | undefined;
99
+ readonly queries?: readonly string[] | undefined;
100
+ readonly results?: readonly {
101
+ readonly [x: string]: unknown;
102
+ }[] | null | undefined;
103
+ } | {
104
+ readonly [x: string]: unknown;
105
+ readonly type: "code_interpreter_call";
106
+ readonly id: string;
107
+ readonly status?: string | undefined;
108
+ readonly code?: string | null | undefined;
109
+ readonly container_id?: string | null | undefined;
110
+ readonly outputs?: readonly {
111
+ readonly [x: string]: unknown;
112
+ }[] | null | undefined;
113
+ } | {
114
+ readonly [x: string]: unknown;
115
+ readonly type: "mcp_call";
116
+ readonly id: string;
117
+ readonly status?: string | undefined;
118
+ readonly server_label?: string | undefined;
119
+ readonly name?: string | undefined;
120
+ readonly arguments?: string | undefined;
121
+ readonly output?: string | null | undefined;
122
+ readonly error?: unknown;
123
+ } | {
124
+ readonly [x: string]: unknown;
125
+ readonly type: string;
126
+ readonly id: string;
127
127
  })[];
128
128
  readonly instructions?: string | undefined;
129
129
  readonly tools?: readonly ({
130
- readonly [x: string]: unknown;
131
- readonly type: string;
132
- } | {
133
130
  readonly type: "function";
134
131
  readonly name: string;
135
132
  readonly description: string;
@@ -137,6 +134,9 @@ export declare const protocol: Protocol<{
137
134
  readonly [x: string]: unknown;
138
135
  };
139
136
  readonly strict?: boolean | undefined;
137
+ } | {
138
+ readonly [x: string]: unknown;
139
+ readonly type: string;
140
140
  })[] | undefined;
141
141
  readonly tool_choice?: "auto" | "none" | "required" | {
142
142
  readonly type: "function";
@@ -159,15 +159,15 @@ export declare const protocol: Protocol<{
159
159
  } | undefined;
160
160
  readonly top_logprobs?: number | undefined;
161
161
  readonly truncation?: "auto" | "disabled" | undefined;
162
- readonly service_tier?: import("./utils/open-responses-options.js").ServiceTier | undefined;
162
+ readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
163
163
  readonly prompt_cache_key?: string | undefined;
164
- readonly include?: readonly import("./utils/open-responses-options.js").ResponseIncludable[] | undefined;
164
+ readonly include?: readonly import("../schema/options.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;
165
165
  readonly reasoning?: {
166
166
  readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
167
167
  readonly summary?: "auto" | "concise" | "detailed" | undefined;
168
168
  } | undefined;
169
169
  readonly text?: {
170
- readonly verbosity?: import("./utils/open-responses-options.js").TextVerbosity | undefined;
170
+ readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
171
171
  } | undefined;
172
172
  readonly max_output_tokens?: number | undefined;
173
173
  readonly max_tool_calls?: number | undefined;
@@ -1,21 +1,24 @@
1
+ import { Schema } from "effect";
1
2
  import { Protocol } from "../route/protocol.js";
2
3
  import { OpenAIChat } from "./openai-chat.js";
3
- export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {});
4
- export type OptionsInput = {
5
- readonly reasoningEffort?: ReasoningEffort;
6
- readonly thinking?: {
7
- readonly type?: "enabled" | "disabled" | (string & {});
4
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
5
+ export type ReasoningEffort = OpenResponsesOptions.ReasoningEffort;
6
+ declare const Options: Schema.Struct<{
7
+ readonly reasoningEffort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
8
+ readonly thinking: Schema.optional<Schema.Struct<{
9
+ readonly type: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"disabled" | "enabled">, import("../schema/options.js").OpenString<"disabled" | "enabled">>>;
8
10
  /** False retains historical reasoning; omission preserves the endpoint's default. */
9
- readonly clear_thinking?: boolean;
10
- };
11
- readonly toolStream?: boolean;
12
- readonly doSample?: boolean;
13
- readonly responseFormat?: {
14
- readonly type: "text" | "json_object" | (string & {});
15
- };
16
- readonly requestID?: string;
17
- readonly userID?: string;
18
- };
11
+ readonly clear_thinking: Schema.optional<Schema.Boolean>;
12
+ }>>;
13
+ readonly toolStream: Schema.optional<Schema.Boolean>;
14
+ readonly doSample: Schema.optional<Schema.Boolean>;
15
+ readonly responseFormat: Schema.optional<Schema.Struct<{
16
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"json_object" | "text">, import("../schema/options.js").OpenString<"json_object" | "text">>;
17
+ }>>;
18
+ readonly requestID: Schema.optional<Schema.String>;
19
+ readonly userID: Schema.optional<Schema.String>;
20
+ }>;
21
+ export type OptionsInput = typeof Options.Type;
19
22
  export declare const compatibility: {
20
23
  maxTokensField: "max_tokens";
21
24
  supportsStrictMode: false;
@@ -27,13 +30,6 @@ export declare const protocol: Protocol<{
27
30
  readonly messages: readonly ({
28
31
  readonly role: "system";
29
32
  readonly content: string | readonly ({
30
- readonly type: "text";
31
- readonly text: string;
32
- readonly cache_control?: {
33
- readonly type: "ephemeral";
34
- readonly ttl?: string | undefined;
35
- } | undefined;
36
- } | {
37
33
  readonly type: "image_url";
38
34
  readonly image_url: {
39
35
  readonly url: string;
@@ -44,17 +40,17 @@ export declare const protocol: Protocol<{
44
40
  readonly filename: string;
45
41
  readonly file_data: string;
46
42
  };
47
- })[];
48
- } | {
49
- readonly role: "user";
50
- readonly content: string | readonly ({
43
+ } | {
51
44
  readonly type: "text";
52
45
  readonly text: string;
53
46
  readonly cache_control?: {
54
47
  readonly type: "ephemeral";
55
48
  readonly ttl?: string | undefined;
56
49
  } | undefined;
57
- } | {
50
+ })[];
51
+ } | {
52
+ readonly role: "user";
53
+ readonly content: string | readonly ({
58
54
  readonly type: "image_url";
59
55
  readonly image_url: {
60
56
  readonly url: string;
@@ -65,6 +61,13 @@ export declare const protocol: Protocol<{
65
61
  readonly filename: string;
66
62
  readonly file_data: string;
67
63
  };
64
+ } | {
65
+ readonly type: "text";
66
+ readonly text: string;
67
+ readonly cache_control?: {
68
+ readonly type: "ephemeral";
69
+ readonly ttl?: string | undefined;
70
+ } | undefined;
68
71
  })[];
69
72
  } | {
70
73
  readonly role: "tool";
@@ -133,7 +136,7 @@ export declare const protocol: Protocol<{
133
136
  } | undefined;
134
137
  readonly store?: boolean | undefined;
135
138
  readonly prompt_cache_key?: string | undefined;
136
- readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
139
+ readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
137
140
  readonly tool_stream?: boolean | undefined;
138
141
  readonly max_completion_tokens?: number | undefined;
139
142
  readonly max_tokens?: number | undefined;
@@ -144,12 +147,12 @@ export declare const protocol: Protocol<{
144
147
  readonly seed?: number | undefined;
145
148
  readonly stop?: readonly string[] | undefined;
146
149
  readonly thinking?: {
147
- readonly type?: string | undefined;
150
+ readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
148
151
  readonly clear_thinking?: boolean | undefined;
149
152
  } | undefined;
150
153
  readonly do_sample?: boolean | undefined;
151
154
  readonly response_format?: {
152
- readonly type: string;
155
+ readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
153
156
  } | undefined;
154
157
  readonly request_id?: string | undefined;
155
158
  readonly user_id?: string | undefined;
@@ -2,12 +2,17 @@ import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
3
  import { OpenAIChat } from "./openai-chat.js";
4
4
  import { ProviderShared } from "./shared.js";
5
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
5
6
  const Options = Schema.Struct({
6
- reasoningEffort: Schema.optional(Schema.String),
7
- thinking: Schema.optional(Schema.Struct({ type: Schema.optional(Schema.String), clear_thinking: Schema.optional(Schema.Boolean) })),
7
+ reasoningEffort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
8
+ thinking: Schema.optional(Schema.Struct({
9
+ type: Schema.optional(ProviderShared.knownString()),
10
+ /** False retains historical reasoning; omission preserves the endpoint's default. */
11
+ clear_thinking: Schema.optional(Schema.Boolean),
12
+ })),
8
13
  toolStream: Schema.optional(Schema.Boolean),
9
14
  doSample: Schema.optional(Schema.Boolean),
10
- responseFormat: Schema.optional(Schema.Struct({ type: Schema.String })),
15
+ responseFormat: Schema.optional(Schema.Struct({ type: ProviderShared.knownString() })),
11
16
  requestID: Schema.optional(Schema.String),
12
17
  userID: Schema.optional(Schema.String),
13
18
  });
@@ -1,11 +1,13 @@
1
+ import { Schema } from "effect";
1
2
  import { Protocol } from "../route/protocol.js";
2
- import type { ZAIChat } from "./zai-chat.js";
3
- export type OptionsInput = {
4
- readonly effort?: ZAIChat.ReasoningEffort;
5
- readonly thinking?: {
6
- readonly type: "enabled" | "adaptive" | "disabled" | (string & {});
7
- };
8
- };
3
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
4
+ declare const Options: Schema.Struct<{
5
+ readonly effort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
6
+ readonly thinking: Schema.optional<Schema.Struct<{
7
+ readonly type: Schema.declare<import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">, import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">>;
8
+ }>>;
9
+ }>;
10
+ export type OptionsInput = typeof Options.Type;
9
11
  export declare const protocol: Protocol<{
10
12
  readonly context_management?: {
11
13
  readonly edits: readonly {
@@ -148,23 +150,15 @@ export declare const protocol: Protocol<{
148
150
  } | {
149
151
  readonly role: "assistant";
150
152
  readonly content: readonly ({
153
+ readonly type: "compaction";
154
+ readonly content: string | null;
155
+ } | {
151
156
  readonly type: "text";
152
157
  readonly text: string;
153
158
  readonly cache_control?: {
154
159
  readonly type: "ephemeral";
155
160
  readonly ttl?: "1h" | "5m" | undefined;
156
161
  } | undefined;
157
- } | {
158
- readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
159
- readonly tool_use_id: string;
160
- readonly content: unknown;
161
- readonly cache_control?: {
162
- readonly type: "ephemeral";
163
- readonly ttl?: "1h" | "5m" | undefined;
164
- } | undefined;
165
- } | {
166
- readonly type: "compaction";
167
- readonly content: string | null;
168
162
  } | {
169
163
  readonly type: "thinking";
170
164
  readonly thinking: string;
@@ -198,6 +192,14 @@ export declare const protocol: Protocol<{
198
192
  readonly type: "ephemeral";
199
193
  readonly ttl?: "1h" | "5m" | undefined;
200
194
  } | undefined;
195
+ } | {
196
+ readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
197
+ readonly tool_use_id: string;
198
+ readonly content: unknown;
199
+ readonly cache_control?: {
200
+ readonly type: "ephemeral";
201
+ readonly ttl?: "1h" | "5m" | undefined;
202
+ } | undefined;
201
203
  })[];
202
204
  } | {
203
205
  readonly role: "system";
@@ -263,7 +265,7 @@ export declare const protocol: Protocol<{
263
265
  } | undefined;
264
266
  readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
265
267
  readonly thinking?: {
266
- readonly type: string;
268
+ readonly type: import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">;
267
269
  } | undefined;
268
270
  }, string, {
269
271
  readonly [x: string]: unknown;
@@ -3,9 +3,10 @@ import { Protocol } from "../route/protocol.js";
3
3
  import { LLMRequest } from "../schema/index.js";
4
4
  import { AnthropicMessages } from "./anthropic-messages.js";
5
5
  import { ProviderShared } from "./shared.js";
6
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
6
7
  const Options = Schema.Struct({
7
- effort: Schema.optional(Schema.String),
8
- thinking: Schema.optional(Schema.Struct({ type: Schema.String })),
8
+ effort: Schema.optional(OpenResponsesOptions.ReasoningEffort),
9
+ thinking: Schema.optional(Schema.Struct({ type: ProviderShared.knownString() })),
9
10
  });
10
11
  const Body = Schema.Struct({
11
12
  ...AnthropicMessages.AnthropicMessagesBody.fields,
@@ -1,8 +1,12 @@
1
1
  import { Option, Schema, SchemaGetter } from "effect";
2
2
  import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
+ import { Json } from "./utils/json.js";
4
+ import { isRecord } from "./utils/record.js";
3
5
  const patterns = [
4
6
  /prompt is too long/i,
5
- /input is too long for requested model/i,
7
+ /input is too long for (?:the )?(?:requested|selected) model/i,
8
+ // OpenCode Go
9
+ /too large for the model'?s configured input limit/i,
6
10
  // Cloudflare Workers AI reports this as HTTP 413.
7
11
  /exceeded this model context window limit/i,
8
12
  /exceeds the context window/i,
@@ -29,8 +33,8 @@ const patterns = [
29
33
  /context[_ ]length[_ ]exceeded/i,
30
34
  /context length is only \d+ tokens/i,
31
35
  /input length.*exceeds.*context length/i,
32
- // Z.ai code 1261 arrives as `Prompt too long` or `Prompt 超长`.
33
- /prompt (?:too long|超长)/i,
36
+ // Z.ai code 1261 arrives as `Prompt too long`, `Prompt exceeds max length` or `Prompt 超长`.
37
+ /prompt (?:too long|exceeds max length|超长)/i,
34
38
  /too large for model with \d+ maximum context length/i,
35
39
  /prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,
36
40
  /model_context_window_exceeded/i,
@@ -93,7 +97,7 @@ export const isRetryable = (error) => {
93
97
  }
94
98
  }
95
99
  };
96
- const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
100
+ const decodeJson = Schema.decodeUnknownOption(Json);
97
101
  // OpenCode Zen reports account caps as typed 429/402 errors that are not throttles.
98
102
  const QUOTA_CODES = new Set([
99
103
  "insufficient_quota",
@@ -265,6 +269,3 @@ function providerCodes(value) {
265
269
  exception?.type,
266
270
  ].filter((value) => typeof value === "string");
267
271
  }
268
- function isRecord(value) {
269
- return typeof value === "object" && value !== null;
270
- }