@opencode/ai 0.0.0-reserved → 2.0.0

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 (288) hide show
  1. package/README.md +879 -2
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +129 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +28 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +103 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +252 -0
  11. package/dist/llm.js +74 -0
  12. package/dist/protocols/alibaba-chat.d.ts +225 -0
  13. package/dist/protocols/alibaba-chat.js +75 -0
  14. package/dist/protocols/alibaba-messages.d.ts +350 -0
  15. package/dist/protocols/alibaba-messages.js +40 -0
  16. package/dist/protocols/alibaba-responses.d.ts +255 -0
  17. package/dist/protocols/alibaba-responses.js +80 -0
  18. package/dist/protocols/anthropic-messages.d.ts +980 -0
  19. package/dist/protocols/anthropic-messages.js +1460 -0
  20. package/dist/protocols/bedrock-converse.d.ts +499 -0
  21. package/dist/protocols/bedrock-converse.js +643 -0
  22. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  23. package/dist/protocols/bedrock-event-stream.js +97 -0
  24. package/dist/protocols/gemini.d.ts +285 -0
  25. package/dist/protocols/gemini.js +671 -0
  26. package/dist/protocols/google-images.d.ts +30 -0
  27. package/dist/protocols/google-images.js +181 -0
  28. package/dist/protocols/index.d.ts +12 -0
  29. package/dist/protocols/index.js +12 -0
  30. package/dist/protocols/meta-images.d.ts +26 -0
  31. package/dist/protocols/meta-images.js +89 -0
  32. package/dist/protocols/meta-messages.d.ts +356 -0
  33. package/dist/protocols/meta-messages.js +41 -0
  34. package/dist/protocols/meta-responses.d.ts +473 -0
  35. package/dist/protocols/meta-responses.js +173 -0
  36. package/dist/protocols/mistral-chat.d.ts +540 -0
  37. package/dist/protocols/mistral-chat.js +624 -0
  38. package/dist/protocols/open-responses-channel.d.ts +25 -0
  39. package/dist/protocols/open-responses-channel.js +141 -0
  40. package/dist/protocols/open-responses-continuation.d.ts +16 -0
  41. package/dist/protocols/open-responses-continuation.js +170 -0
  42. package/dist/protocols/open-responses.d.ts +1715 -0
  43. package/dist/protocols/open-responses.js +1228 -0
  44. package/dist/protocols/openai-chat.d.ts +860 -0
  45. package/dist/protocols/openai-chat.js +966 -0
  46. package/dist/protocols/openai-compatible-chat.d.ts +109 -0
  47. package/dist/protocols/openai-compatible-chat.js +19 -0
  48. package/dist/protocols/openai-compatible-responses.d.ts +172 -0
  49. package/dist/protocols/openai-compatible-responses.js +18 -0
  50. package/dist/protocols/openai-images.d.ts +32 -0
  51. package/dist/protocols/openai-images.js +183 -0
  52. package/dist/protocols/openai-responses.d.ts +1389 -0
  53. package/dist/protocols/openai-responses.js +260 -0
  54. package/dist/protocols/shared.d.ts +193 -0
  55. package/dist/protocols/shared.js +290 -0
  56. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  57. package/dist/protocols/utils/bedrock-auth.js +85 -0
  58. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  59. package/dist/protocols/utils/bedrock-cache.js +49 -0
  60. package/dist/protocols/utils/bedrock-media.d.ts +55 -0
  61. package/dist/protocols/utils/bedrock-media.js +73 -0
  62. package/dist/protocols/utils/cache.d.ts +6 -0
  63. package/dist/protocols/utils/cache.js +5 -0
  64. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  65. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  66. package/dist/protocols/utils/image-input.d.ts +21 -0
  67. package/dist/protocols/utils/image-input.js +20 -0
  68. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  69. package/dist/protocols/utils/lifecycle.js +72 -0
  70. package/dist/protocols/utils/meta-image.d.ts +2 -0
  71. package/dist/protocols/utils/meta-image.js +13 -0
  72. package/dist/protocols/utils/open-responses-options.d.ts +56 -0
  73. package/dist/protocols/utils/open-responses-options.js +61 -0
  74. package/dist/protocols/utils/openai-image.d.ts +5 -0
  75. package/dist/protocols/utils/openai-image.js +18 -0
  76. package/dist/protocols/utils/openai-options.d.ts +16 -0
  77. package/dist/protocols/utils/openai-options.js +14 -0
  78. package/dist/protocols/utils/partial-json-options.d.ts +62 -0
  79. package/dist/protocols/utils/partial-json-options.js +52 -0
  80. package/dist/protocols/utils/partial-json.d.ts +8 -0
  81. package/dist/protocols/utils/partial-json.js +279 -0
  82. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  83. package/dist/protocols/utils/responses-checkpoint.js +107 -0
  84. package/dist/protocols/utils/responses-compaction.d.ts +4 -0
  85. package/dist/protocols/utils/responses-compaction.js +129 -0
  86. package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
  87. package/dist/protocols/utils/responses-hosted-tools.js +32 -0
  88. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  89. package/dist/protocols/utils/tool-schema.js +54 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +710 -0
  91. package/dist/protocols/utils/tool-stream.js +155 -0
  92. package/dist/protocols/xai-images.d.ts +26 -0
  93. package/dist/protocols/xai-images.js +106 -0
  94. package/dist/protocols/xai-responses.d.ts +250 -0
  95. package/dist/protocols/xai-responses.js +81 -0
  96. package/dist/protocols/zai-chat.d.ts +202 -0
  97. package/dist/protocols/zai-chat.js +49 -0
  98. package/dist/protocols/zai-images.d.ts +22 -0
  99. package/dist/protocols/zai-images.js +79 -0
  100. package/dist/protocols/zai-messages.d.ts +344 -0
  101. package/dist/protocols/zai-messages.js +27 -0
  102. package/dist/protocols.d.ts +1 -0
  103. package/dist/protocols.js +1 -0
  104. package/dist/provider-error.d.ts +15 -0
  105. package/dist/provider-error.js +125 -0
  106. package/dist/provider-package.d.ts +15 -0
  107. package/dist/provider-package.js +1 -0
  108. package/dist/provider.d.ts +23 -0
  109. package/dist/provider.js +2 -0
  110. package/dist/providers/alibaba/chat.d.ts +1 -0
  111. package/dist/providers/alibaba/chat.js +1 -0
  112. package/dist/providers/alibaba/messages.d.ts +3 -0
  113. package/dist/providers/alibaba/messages.js +1 -0
  114. package/dist/providers/alibaba/responses.d.ts +3 -0
  115. package/dist/providers/alibaba/responses.js +1 -0
  116. package/dist/providers/alibaba.d.ts +711 -0
  117. package/dist/providers/alibaba.js +94 -0
  118. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  119. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  120. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  121. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  122. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  123. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  124. package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
  125. package/dist/providers/amazon-bedrock-mantle.js +79 -0
  126. package/dist/providers/amazon-bedrock.d.ts +173 -0
  127. package/dist/providers/amazon-bedrock.js +41 -0
  128. package/dist/providers/anthropic-compatible.d.ts +309 -0
  129. package/dist/providers/anthropic-compatible.js +50 -0
  130. package/dist/providers/anthropic.d.ts +307 -0
  131. package/dist/providers/anthropic.js +42 -0
  132. package/dist/providers/azure/chat.d.ts +2 -0
  133. package/dist/providers/azure/chat.js +1 -0
  134. package/dist/providers/azure/responses.d.ts +2 -0
  135. package/dist/providers/azure/responses.js +1 -0
  136. package/dist/providers/azure.d.ts +598 -0
  137. package/dist/providers/azure.js +115 -0
  138. package/dist/providers/baseten.d.ts +228 -0
  139. package/dist/providers/baseten.js +38 -0
  140. package/dist/providers/cerebras.d.ts +227 -0
  141. package/dist/providers/cerebras.js +40 -0
  142. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
  143. package/dist/providers/cloudflare-ai-gateway.js +65 -0
  144. package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
  145. package/dist/providers/cloudflare-workers-ai.js +51 -0
  146. package/dist/providers/deepinfra.d.ts +227 -0
  147. package/dist/providers/deepinfra.js +43 -0
  148. package/dist/providers/deepseek.d.ts +228 -0
  149. package/dist/providers/deepseek.js +41 -0
  150. package/dist/providers/fireworks.d.ts +228 -0
  151. package/dist/providers/fireworks.js +38 -0
  152. package/dist/providers/google-vertex/chat.d.ts +2 -0
  153. package/dist/providers/google-vertex/chat.js +1 -0
  154. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  155. package/dist/providers/google-vertex/gemini.js +1 -0
  156. package/dist/providers/google-vertex/messages.d.ts +2 -0
  157. package/dist/providers/google-vertex/messages.js +1 -0
  158. package/dist/providers/google-vertex/responses.d.ts +2 -0
  159. package/dist/providers/google-vertex/responses.js +1 -0
  160. package/dist/providers/google-vertex-chat.d.ts +132 -0
  161. package/dist/providers/google-vertex-chat.js +55 -0
  162. package/dist/providers/google-vertex-messages.d.ts +306 -0
  163. package/dist/providers/google-vertex-messages.js +75 -0
  164. package/dist/providers/google-vertex-responses.d.ts +197 -0
  165. package/dist/providers/google-vertex-responses.js +56 -0
  166. package/dist/providers/google-vertex-shared.d.ts +22 -0
  167. package/dist/providers/google-vertex-shared.js +72 -0
  168. package/dist/providers/google-vertex.d.ts +119 -0
  169. package/dist/providers/google-vertex.js +98 -0
  170. package/dist/providers/google.d.ts +114 -0
  171. package/dist/providers/google.js +42 -0
  172. package/dist/providers/groq.d.ts +314 -0
  173. package/dist/providers/groq.js +81 -0
  174. package/dist/providers/index.d.ts +31 -0
  175. package/dist/providers/index.js +31 -0
  176. package/dist/providers/meta/chat.d.ts +2 -0
  177. package/dist/providers/meta/chat.js +1 -0
  178. package/dist/providers/meta/messages.d.ts +2 -0
  179. package/dist/providers/meta/messages.js +1 -0
  180. package/dist/providers/meta/responses.d.ts +2 -0
  181. package/dist/providers/meta/responses.js +1 -0
  182. package/dist/providers/meta.d.ts +636 -0
  183. package/dist/providers/meta.js +113 -0
  184. package/dist/providers/minimax/chat.d.ts +4 -0
  185. package/dist/providers/minimax/chat.js +8 -0
  186. package/dist/providers/minimax/messages.d.ts +1 -0
  187. package/dist/providers/minimax/messages.js +1 -0
  188. package/dist/providers/minimax/responses.d.ts +4 -0
  189. package/dist/providers/minimax/responses.js +8 -0
  190. package/dist/providers/minimax.d.ts +598 -0
  191. package/dist/providers/minimax.js +89 -0
  192. package/dist/providers/mistral.d.ts +207 -0
  193. package/dist/providers/mistral.js +28 -0
  194. package/dist/providers/moonshot/chat.d.ts +1 -0
  195. package/dist/providers/moonshot/chat.js +1 -0
  196. package/dist/providers/moonshot/messages.d.ts +4 -0
  197. package/dist/providers/moonshot/messages.js +8 -0
  198. package/dist/providers/moonshot/responses.d.ts +4 -0
  199. package/dist/providers/moonshot/responses.js +8 -0
  200. package/dist/providers/moonshot.d.ts +596 -0
  201. package/dist/providers/moonshot.js +90 -0
  202. package/dist/providers/open-responses-options.d.ts +6 -0
  203. package/dist/providers/open-responses-options.js +1 -0
  204. package/dist/providers/openai/chat.d.ts +2 -0
  205. package/dist/providers/openai/chat.js +1 -0
  206. package/dist/providers/openai/responses.d.ts +2 -0
  207. package/dist/providers/openai/responses.js +1 -0
  208. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  209. package/dist/providers/openai-compatible/responses.js +1 -0
  210. package/dist/providers/openai-compatible-responses.d.ts +195 -0
  211. package/dist/providers/openai-compatible-responses.js +32 -0
  212. package/dist/providers/openai-compatible.d.ts +130 -0
  213. package/dist/providers/openai-compatible.js +33 -0
  214. package/dist/providers/openai-options.d.ts +26 -0
  215. package/dist/providers/openai-options.js +41 -0
  216. package/dist/providers/openai.d.ts +404 -0
  217. package/dist/providers/openai.js +82 -0
  218. package/dist/providers/openrouter.d.ts +563 -0
  219. package/dist/providers/openrouter.js +114 -0
  220. package/dist/providers/togetherai.d.ts +227 -0
  221. package/dist/providers/togetherai.js +40 -0
  222. package/dist/providers/xai.d.ts +163 -0
  223. package/dist/providers/xai.js +88 -0
  224. package/dist/providers/zai/chat.d.ts +1 -0
  225. package/dist/providers/zai/chat.js +1 -0
  226. package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
  227. package/dist/providers/zai-coding-plan/chat.js +1 -0
  228. package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
  229. package/dist/providers/zai-coding-plan/messages.js +8 -0
  230. package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
  231. package/dist/providers/zai-coding-plan/responses.js +8 -0
  232. package/dist/providers/zai-coding-plan.d.ts +577 -0
  233. package/dist/providers/zai-coding-plan.js +63 -0
  234. package/dist/providers/zai.d.ts +149 -0
  235. package/dist/providers/zai.js +53 -0
  236. package/dist/providers.d.ts +1 -0
  237. package/dist/providers.js +1 -0
  238. package/dist/route/auth-options.d.ts +34 -0
  239. package/dist/route/auth-options.js +14 -0
  240. package/dist/route/auth.d.ts +51 -0
  241. package/dist/route/auth.js +87 -0
  242. package/dist/route/client.d.ts +430 -0
  243. package/dist/route/client.js +307 -0
  244. package/dist/route/endpoint.d.ts +28 -0
  245. package/dist/route/endpoint.js +21 -0
  246. package/dist/route/executor.d.ts +27 -0
  247. package/dist/route/executor.js +183 -0
  248. package/dist/route/framing.d.ts +29 -0
  249. package/dist/route/framing.js +14 -0
  250. package/dist/route/index.d.ts +16 -0
  251. package/dist/route/index.js +9 -0
  252. package/dist/route/protocol.d.ts +76 -0
  253. package/dist/route/protocol.js +16 -0
  254. package/dist/route/transport/http.d.ts +34 -0
  255. package/dist/route/transport/http.js +68 -0
  256. package/dist/route/transport/index.d.ts +41 -0
  257. package/dist/route/transport/index.js +4 -0
  258. package/dist/route/transport/websocket-channel.d.ts +57 -0
  259. package/dist/route/transport/websocket-channel.js +1 -0
  260. package/dist/route/transport/websocket.d.ts +56 -0
  261. package/dist/route/transport/websocket.js +370 -0
  262. package/dist/route.d.ts +1 -0
  263. package/dist/route.js +1 -0
  264. package/dist/schema/errors.d.ts +170 -0
  265. package/dist/schema/errors.js +131 -0
  266. package/dist/schema/events.d.ts +8123 -0
  267. package/dist/schema/events.js +550 -0
  268. package/dist/schema/ids.d.ts +17 -0
  269. package/dist/schema/ids.js +10 -0
  270. package/dist/schema/index.d.ts +5 -0
  271. package/dist/schema/index.js +5 -0
  272. package/dist/schema/messages.d.ts +646 -0
  273. package/dist/schema/messages.js +301 -0
  274. package/dist/schema/options.d.ts +159 -0
  275. package/dist/schema/options.js +189 -0
  276. package/dist/testing.d.ts +1693 -0
  277. package/dist/testing.js +129 -0
  278. package/dist/tool-history.d.ts +2 -0
  279. package/dist/tool-history.js +84 -0
  280. package/dist/tool-runtime.d.ts +15 -0
  281. package/dist/tool-runtime.js +62 -0
  282. package/dist/tool.d.ts +136 -0
  283. package/dist/tool.js +66 -0
  284. package/dist/utils/record.d.ts +2 -0
  285. package/dist/utils/record.js +2 -0
  286. package/dist/utils/sanitize.d.ts +1 -0
  287. package/dist/utils/sanitize.js +12 -0
  288. package/package.json +43 -10
@@ -0,0 +1,473 @@
1
+ import { Schema } from "effect";
2
+ import { Protocol } from "../route/protocol.js";
3
+ import { HttpTransport } from "../route/transport/index.js";
4
+ import { OpenResponses } from "./open-responses.js";
5
+ export declare const WebSearch: Schema.Struct<{
6
+ readonly type: Schema.Literal<"web_search">;
7
+ readonly search_context_size: Schema.optional<Schema.String>;
8
+ readonly user_location: Schema.optional<Schema.Struct<{
9
+ readonly type: Schema.Literal<"approximate">;
10
+ readonly city: Schema.optional<Schema.String>;
11
+ readonly region: Schema.optional<Schema.String>;
12
+ readonly country: Schema.optional<Schema.String>;
13
+ readonly timezone: Schema.optional<Schema.String>;
14
+ }>>;
15
+ }>;
16
+ export declare const ImageGeneration: Schema.Struct<{
17
+ readonly type: Schema.Literal<"image_generation">;
18
+ readonly size: Schema.optional<Schema.String>;
19
+ readonly output_format: Schema.optional<Schema.String>;
20
+ readonly reasoning_strength: Schema.optional<Schema.String>;
21
+ readonly enable_image_search: Schema.optional<Schema.Boolean>;
22
+ readonly enable_web_search: Schema.optional<Schema.Boolean>;
23
+ readonly enable_shell: Schema.optional<Schema.Boolean>;
24
+ }>;
25
+ interface ParserState extends OpenResponses.ParserState {
26
+ readonly completedItems: ReadonlySet<string>;
27
+ }
28
+ export declare const protocol: Protocol<{
29
+ readonly input: readonly ({
30
+ readonly [x: string]: unknown;
31
+ readonly id: string;
32
+ readonly type: "web_search_call";
33
+ readonly status?: string | undefined;
34
+ readonly action?: {
35
+ readonly [x: string]: unknown;
36
+ } | null | undefined;
37
+ } | {
38
+ readonly [x: string]: unknown;
39
+ readonly id: string;
40
+ readonly type: "file_search_call";
41
+ readonly status?: string | undefined;
42
+ readonly queries?: readonly string[] | undefined;
43
+ readonly results?: readonly {
44
+ readonly [x: string]: unknown;
45
+ }[] | null | undefined;
46
+ } | {
47
+ readonly [x: string]: unknown;
48
+ readonly id: string;
49
+ readonly type: "code_interpreter_call";
50
+ readonly status?: string | undefined;
51
+ readonly code?: string | null | undefined;
52
+ readonly container_id?: string | null | undefined;
53
+ readonly outputs?: readonly {
54
+ readonly [x: string]: unknown;
55
+ }[] | null | undefined;
56
+ } | {
57
+ readonly [x: string]: unknown;
58
+ readonly id: string;
59
+ readonly type: "mcp_call";
60
+ readonly status?: string | undefined;
61
+ readonly name?: string | undefined;
62
+ readonly output?: string | null | undefined;
63
+ readonly error?: unknown;
64
+ readonly arguments?: string | undefined;
65
+ readonly server_label?: string | undefined;
66
+ } | {
67
+ readonly type: "reasoning";
68
+ readonly summary: readonly {
69
+ readonly type: "summary_text";
70
+ readonly text: string;
71
+ }[];
72
+ readonly id?: string | undefined;
73
+ readonly encrypted_content?: string | null | undefined;
74
+ } | {
75
+ readonly type: "compaction";
76
+ readonly encrypted_content: string;
77
+ readonly id?: string | null | undefined;
78
+ } | {
79
+ readonly role: "system";
80
+ readonly content: string;
81
+ } | {
82
+ readonly role: "developer";
83
+ readonly content: string;
84
+ } | {
85
+ readonly content: readonly ({
86
+ readonly type: "input_image";
87
+ readonly image_url: string;
88
+ readonly detail?: string | undefined;
89
+ } | {
90
+ readonly type: "input_file";
91
+ readonly filename: string;
92
+ readonly detail?: string | undefined;
93
+ readonly file_data?: string | undefined;
94
+ readonly file_url?: string | undefined;
95
+ } | {
96
+ readonly type: "input_text";
97
+ readonly text: string;
98
+ })[];
99
+ readonly role: "user";
100
+ readonly id?: string | undefined;
101
+ readonly type?: "message" | undefined;
102
+ readonly status?: string | undefined;
103
+ } | {
104
+ readonly type: "message";
105
+ readonly content: readonly {
106
+ readonly type: "output_text";
107
+ readonly text: string;
108
+ }[];
109
+ readonly role: "assistant";
110
+ readonly id?: string | undefined;
111
+ readonly status?: string | undefined;
112
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
113
+ } | {
114
+ readonly type: "function_call";
115
+ readonly name: string;
116
+ readonly arguments: string;
117
+ readonly call_id: string;
118
+ readonly id?: string | undefined;
119
+ readonly namespace?: string | undefined;
120
+ } | {
121
+ readonly type: "function_call_output";
122
+ readonly call_id: string;
123
+ readonly output: string | readonly ({
124
+ readonly type: "input_image";
125
+ readonly image_url: string;
126
+ readonly detail?: string | undefined;
127
+ } | {
128
+ readonly type: "input_file";
129
+ readonly filename: string;
130
+ readonly detail?: string | undefined;
131
+ readonly file_data?: string | undefined;
132
+ readonly file_url?: string | undefined;
133
+ } | {
134
+ readonly type: "input_text";
135
+ readonly text: string;
136
+ } | {
137
+ readonly type: "input_video";
138
+ readonly video_url: string;
139
+ })[];
140
+ } | {
141
+ readonly id: string;
142
+ readonly type: "image_generation_call";
143
+ readonly status?: string | undefined;
144
+ readonly error?: unknown;
145
+ readonly result?: string | null | undefined;
146
+ readonly output_format?: string | undefined;
147
+ })[];
148
+ readonly model: string;
149
+ readonly stream: true;
150
+ readonly metadata?: {
151
+ readonly [x: string]: string;
152
+ } | undefined;
153
+ readonly instructions?: string | undefined;
154
+ readonly reasoning?: {
155
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
156
+ readonly effort?: import("./utils/open-responses-options.js").ReasoningEffort | undefined;
157
+ } | undefined;
158
+ readonly tools?: readonly ({
159
+ readonly type: "function";
160
+ readonly description: string;
161
+ readonly name: string;
162
+ readonly parameters: {
163
+ readonly [x: string]: unknown;
164
+ };
165
+ readonly strict?: boolean | undefined;
166
+ } | {
167
+ readonly type: "web_search";
168
+ readonly search_context_size?: string | undefined;
169
+ readonly user_location?: {
170
+ readonly type: "approximate";
171
+ readonly region?: string | undefined;
172
+ readonly city?: string | undefined;
173
+ readonly country?: string | undefined;
174
+ readonly timezone?: string | undefined;
175
+ } | undefined;
176
+ } | {
177
+ readonly type: "image_generation";
178
+ readonly size?: string | undefined;
179
+ readonly output_format?: string | undefined;
180
+ readonly reasoning_strength?: string | undefined;
181
+ readonly enable_image_search?: boolean | undefined;
182
+ readonly enable_web_search?: boolean | undefined;
183
+ readonly enable_shell?: boolean | undefined;
184
+ })[] | undefined;
185
+ readonly text?: {
186
+ readonly verbosity?: import("./utils/open-responses-options.js").TextVerbosity | undefined;
187
+ } | undefined;
188
+ readonly temperature?: number | undefined;
189
+ readonly service_tier?: import("./utils/open-responses-options.js").ServiceTier | undefined;
190
+ readonly tool_choice?: "required" | "auto" | "none" | {
191
+ readonly type: "function";
192
+ readonly name: string;
193
+ } | {
194
+ readonly type: "allowed_tools";
195
+ readonly mode: "required" | "auto" | "none";
196
+ readonly tools: readonly {
197
+ readonly type: "function";
198
+ readonly name: string;
199
+ }[];
200
+ } | undefined;
201
+ readonly top_p?: number | undefined;
202
+ readonly frequency_penalty?: number | undefined;
203
+ readonly presence_penalty?: number | undefined;
204
+ readonly prompt_cache_key?: string | undefined;
205
+ readonly parallel_tool_calls?: boolean | undefined;
206
+ readonly store?: boolean | undefined;
207
+ readonly include?: readonly import("./utils/open-responses-options.js").ResponseIncludable[] | undefined;
208
+ readonly truncation?: "auto" | "disabled" | undefined;
209
+ readonly stream_options?: {
210
+ readonly include_obfuscation?: boolean | undefined;
211
+ } | undefined;
212
+ readonly safety_identifier?: string | undefined;
213
+ readonly top_logprobs?: number | undefined;
214
+ readonly max_output_tokens?: number | undefined;
215
+ readonly max_tool_calls?: number | undefined;
216
+ }, string, {
217
+ readonly [x: string]: unknown;
218
+ readonly type: string;
219
+ readonly status?: unknown;
220
+ readonly code?: string | null | undefined;
221
+ readonly message?: string | undefined;
222
+ readonly headers?: unknown;
223
+ readonly text?: string | undefined;
224
+ readonly error?: {
225
+ readonly type?: string | null | undefined;
226
+ readonly code?: string | null | undefined;
227
+ readonly message?: string | null | undefined;
228
+ readonly param?: string | null | undefined;
229
+ } | null | undefined;
230
+ readonly item?: {
231
+ readonly [x: string]: unknown;
232
+ readonly type: string;
233
+ readonly id?: string | undefined;
234
+ readonly name?: string | undefined;
235
+ readonly namespace?: string | undefined;
236
+ readonly arguments?: string | undefined;
237
+ readonly encrypted_content?: string | null | undefined;
238
+ readonly call_id?: string | undefined;
239
+ } | null | undefined;
240
+ readonly delta?: string | undefined;
241
+ readonly response?: {
242
+ readonly [x: string]: unknown;
243
+ readonly id?: string | undefined;
244
+ readonly output?: readonly {
245
+ readonly [x: string]: unknown;
246
+ readonly type: string;
247
+ readonly id?: string | undefined;
248
+ readonly name?: string | undefined;
249
+ readonly namespace?: string | undefined;
250
+ readonly arguments?: string | undefined;
251
+ readonly encrypted_content?: string | null | undefined;
252
+ readonly call_id?: string | undefined;
253
+ }[] | undefined;
254
+ readonly error?: {
255
+ readonly type?: string | null | undefined;
256
+ readonly code?: string | null | undefined;
257
+ readonly message?: string | null | undefined;
258
+ readonly param?: string | null | undefined;
259
+ } | null | undefined;
260
+ readonly usage?: {
261
+ readonly input_tokens?: number | undefined;
262
+ readonly output_tokens?: number | undefined;
263
+ readonly output_tokens_details?: {
264
+ readonly reasoning_tokens?: number | undefined;
265
+ } | null | undefined;
266
+ readonly total_tokens?: number | undefined;
267
+ readonly input_tokens_details?: {
268
+ readonly cached_tokens?: number | undefined;
269
+ readonly cache_write_tokens?: number | undefined;
270
+ } | null | undefined;
271
+ } | null | undefined;
272
+ readonly service_tier?: string | null | undefined;
273
+ readonly incomplete_details?: {
274
+ readonly reason?: string | undefined;
275
+ } | null | undefined;
276
+ } | undefined;
277
+ readonly arguments?: string | undefined;
278
+ readonly param?: string | null | undefined;
279
+ readonly status_code?: unknown;
280
+ readonly item_id?: string | undefined;
281
+ readonly output_index?: number | undefined;
282
+ readonly summary_index?: number | undefined;
283
+ }, ParserState>;
284
+ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
285
+ readonly input: readonly ({
286
+ readonly [x: string]: unknown;
287
+ readonly id: string;
288
+ readonly type: "web_search_call";
289
+ readonly status?: string | undefined;
290
+ readonly action?: {
291
+ readonly [x: string]: unknown;
292
+ } | null | undefined;
293
+ } | {
294
+ readonly [x: string]: unknown;
295
+ readonly id: string;
296
+ readonly type: "file_search_call";
297
+ readonly status?: string | undefined;
298
+ readonly queries?: readonly string[] | undefined;
299
+ readonly results?: readonly {
300
+ readonly [x: string]: unknown;
301
+ }[] | null | undefined;
302
+ } | {
303
+ readonly [x: string]: unknown;
304
+ readonly id: string;
305
+ readonly type: "code_interpreter_call";
306
+ readonly status?: string | undefined;
307
+ readonly code?: string | null | undefined;
308
+ readonly container_id?: string | null | undefined;
309
+ readonly outputs?: readonly {
310
+ readonly [x: string]: unknown;
311
+ }[] | null | undefined;
312
+ } | {
313
+ readonly [x: string]: unknown;
314
+ readonly id: string;
315
+ readonly type: "mcp_call";
316
+ readonly status?: string | undefined;
317
+ readonly name?: string | undefined;
318
+ readonly output?: string | null | undefined;
319
+ readonly error?: unknown;
320
+ readonly arguments?: string | undefined;
321
+ readonly server_label?: string | undefined;
322
+ } | {
323
+ readonly type: "reasoning";
324
+ readonly summary: readonly {
325
+ readonly type: "summary_text";
326
+ readonly text: string;
327
+ }[];
328
+ readonly id?: string | undefined;
329
+ readonly encrypted_content?: string | null | undefined;
330
+ } | {
331
+ readonly type: "compaction";
332
+ readonly encrypted_content: string;
333
+ readonly id?: string | null | undefined;
334
+ } | {
335
+ readonly role: "system";
336
+ readonly content: string;
337
+ } | {
338
+ readonly role: "developer";
339
+ readonly content: string;
340
+ } | {
341
+ readonly content: readonly ({
342
+ readonly type: "input_image";
343
+ readonly image_url: string;
344
+ readonly detail?: string | undefined;
345
+ } | {
346
+ readonly type: "input_file";
347
+ readonly filename: string;
348
+ readonly detail?: string | undefined;
349
+ readonly file_data?: string | undefined;
350
+ readonly file_url?: string | undefined;
351
+ } | {
352
+ readonly type: "input_text";
353
+ readonly text: string;
354
+ })[];
355
+ readonly role: "user";
356
+ readonly id?: string | undefined;
357
+ readonly type?: "message" | undefined;
358
+ readonly status?: string | undefined;
359
+ } | {
360
+ readonly type: "message";
361
+ readonly content: readonly {
362
+ readonly type: "output_text";
363
+ readonly text: string;
364
+ }[];
365
+ readonly role: "assistant";
366
+ readonly id?: string | undefined;
367
+ readonly status?: string | undefined;
368
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
369
+ } | {
370
+ readonly type: "function_call";
371
+ readonly name: string;
372
+ readonly arguments: string;
373
+ readonly call_id: string;
374
+ readonly id?: string | undefined;
375
+ readonly namespace?: string | undefined;
376
+ } | {
377
+ readonly type: "function_call_output";
378
+ readonly call_id: string;
379
+ readonly output: string | readonly ({
380
+ readonly type: "input_image";
381
+ readonly image_url: string;
382
+ readonly detail?: string | undefined;
383
+ } | {
384
+ readonly type: "input_file";
385
+ readonly filename: string;
386
+ readonly detail?: string | undefined;
387
+ readonly file_data?: string | undefined;
388
+ readonly file_url?: string | undefined;
389
+ } | {
390
+ readonly type: "input_text";
391
+ readonly text: string;
392
+ } | {
393
+ readonly type: "input_video";
394
+ readonly video_url: string;
395
+ })[];
396
+ } | {
397
+ readonly id: string;
398
+ readonly type: "image_generation_call";
399
+ readonly status?: string | undefined;
400
+ readonly error?: unknown;
401
+ readonly result?: string | null | undefined;
402
+ readonly output_format?: string | undefined;
403
+ })[];
404
+ readonly model: string;
405
+ readonly stream: true;
406
+ readonly metadata?: {
407
+ readonly [x: string]: string;
408
+ } | undefined;
409
+ readonly instructions?: string | undefined;
410
+ readonly reasoning?: {
411
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
412
+ readonly effort?: import("./utils/open-responses-options.js").ReasoningEffort | undefined;
413
+ } | undefined;
414
+ readonly tools?: readonly ({
415
+ readonly type: "function";
416
+ readonly description: string;
417
+ readonly name: string;
418
+ readonly parameters: {
419
+ readonly [x: string]: unknown;
420
+ };
421
+ readonly strict?: boolean | undefined;
422
+ } | {
423
+ readonly type: "web_search";
424
+ readonly search_context_size?: string | undefined;
425
+ readonly user_location?: {
426
+ readonly type: "approximate";
427
+ readonly region?: string | undefined;
428
+ readonly city?: string | undefined;
429
+ readonly country?: string | undefined;
430
+ readonly timezone?: string | undefined;
431
+ } | undefined;
432
+ } | {
433
+ readonly type: "image_generation";
434
+ readonly size?: string | undefined;
435
+ readonly output_format?: string | undefined;
436
+ readonly reasoning_strength?: string | undefined;
437
+ readonly enable_image_search?: boolean | undefined;
438
+ readonly enable_web_search?: boolean | undefined;
439
+ readonly enable_shell?: boolean | undefined;
440
+ })[] | undefined;
441
+ readonly text?: {
442
+ readonly verbosity?: import("./utils/open-responses-options.js").TextVerbosity | undefined;
443
+ } | undefined;
444
+ readonly temperature?: number | undefined;
445
+ readonly service_tier?: import("./utils/open-responses-options.js").ServiceTier | undefined;
446
+ readonly tool_choice?: "required" | "auto" | "none" | {
447
+ readonly type: "function";
448
+ readonly name: string;
449
+ } | {
450
+ readonly type: "allowed_tools";
451
+ readonly mode: "required" | "auto" | "none";
452
+ readonly tools: readonly {
453
+ readonly type: "function";
454
+ readonly name: string;
455
+ }[];
456
+ } | undefined;
457
+ readonly top_p?: number | undefined;
458
+ readonly frequency_penalty?: number | undefined;
459
+ readonly presence_penalty?: number | undefined;
460
+ readonly prompt_cache_key?: string | undefined;
461
+ readonly parallel_tool_calls?: boolean | undefined;
462
+ readonly store?: boolean | undefined;
463
+ readonly include?: readonly import("./utils/open-responses-options.js").ResponseIncludable[] | undefined;
464
+ readonly truncation?: "auto" | "disabled" | undefined;
465
+ readonly stream_options?: {
466
+ readonly include_obfuscation?: boolean | undefined;
467
+ } | undefined;
468
+ readonly safety_identifier?: string | undefined;
469
+ readonly top_logprobs?: number | undefined;
470
+ readonly max_output_tokens?: number | undefined;
471
+ readonly max_tool_calls?: number | undefined;
472
+ }, string>;
473
+ export * as MetaResponses from "./meta-responses.js";
@@ -0,0 +1,173 @@
1
+ import { Effect, Encoding, Schema } from "effect";
2
+ import { Protocol } from "../route/protocol.js";
3
+ import { HttpTransport } from "../route/transport/index.js";
4
+ import { LLMEvent, LLMRequest, Message, ToolResultPart } from "../schema/index.js";
5
+ import { OpenResponses } from "./open-responses.js";
6
+ import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
7
+ import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
8
+ import { ToolSchemaProjection } from "./utils/tool-schema.js";
9
+ import { MetaImage } from "./utils/meta-image.js";
10
+ const ADAPTER = "meta-responses";
11
+ const NAME = "Meta Responses";
12
+ export const WebSearch = Schema.Struct({
13
+ type: Schema.Literal("web_search"),
14
+ search_context_size: Schema.optional(Schema.String),
15
+ user_location: Schema.optional(Schema.Struct({
16
+ type: Schema.Literal("approximate"),
17
+ city: Schema.optional(Schema.String),
18
+ region: Schema.optional(Schema.String),
19
+ country: Schema.optional(Schema.String),
20
+ timezone: Schema.optional(Schema.String),
21
+ })),
22
+ });
23
+ export const ImageGeneration = Schema.Struct({
24
+ type: Schema.Literal("image_generation"),
25
+ size: Schema.optional(Schema.String),
26
+ output_format: Schema.optional(Schema.String),
27
+ reasoning_strength: Schema.optional(Schema.String),
28
+ enable_image_search: Schema.optional(Schema.Boolean),
29
+ enable_web_search: Schema.optional(Schema.Boolean),
30
+ enable_shell: Schema.optional(Schema.Boolean),
31
+ });
32
+ const NativeTool = Schema.Union([WebSearch, ImageGeneration]);
33
+ const ImageItem = Schema.Struct({
34
+ type: Schema.Literal("image_generation_call"),
35
+ id: Schema.String,
36
+ status: Schema.optional(Schema.String),
37
+ result: optionalNull(Schema.String),
38
+ output_format: Schema.optional(Schema.String),
39
+ error: Schema.optional(Schema.Unknown),
40
+ });
41
+ const Body = Schema.Struct({
42
+ ...OpenResponses.coreFields,
43
+ input: Schema.Array(Schema.Union([OpenResponses.InputItem, ImageItem])),
44
+ tools: optionalArray(Schema.Union([OpenResponses.Tool, NativeTool])),
45
+ stream: Schema.Literal(true),
46
+ });
47
+ const MessageAnnotations = Schema.Struct({
48
+ content: Schema.Array(Schema.Struct({ annotations: optionalArray(JsonObject) })),
49
+ });
50
+ const adapter = {
51
+ id: ADAPTER,
52
+ name: NAME,
53
+ restoreHostedToolItem: (item) => (Schema.is(ImageItem)(item) ? item : undefined),
54
+ };
55
+ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
56
+ const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
57
+ const projected = ProviderShared.flattenToolRequest(LLMRequest.update(request, {
58
+ messages: request.messages.map((message) => Message.make({
59
+ ...message,
60
+ content: message.content.map((part) => {
61
+ if (part.type !== "tool-result" ||
62
+ !part.providerExecuted ||
63
+ part.name !== "image_generation" ||
64
+ part.result.type !== "content" ||
65
+ part.providerMetadata?.[key]?.itemId !== part.id)
66
+ return part;
67
+ // Meta's signed image ID carries edit state; replay the handle, not the image bytes as a user message.
68
+ return ToolResultPart.make({
69
+ ...part,
70
+ result: {
71
+ type: "json",
72
+ value: { type: "image_generation_call", id: part.id, status: "completed", result: null },
73
+ },
74
+ });
75
+ }),
76
+ })),
77
+ }));
78
+ return yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))({
79
+ ...(yield* OpenResponses.lowerConversation(projected.request, adapter)),
80
+ ...OpenResponses.lowerGeneration(request),
81
+ tools: projected.tools.length === 0
82
+ ? undefined
83
+ : yield* Effect.forEach(projected.tools, (tool) => Effect.gen(function* () {
84
+ if (tool.native === undefined)
85
+ return yield* OpenResponses.lowerTool(NAME, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, request.model.compatibility?.toolSchema));
86
+ return yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(NativeTool))(tool.native.meta);
87
+ })),
88
+ tool_choice: OpenResponses.allowedToolChoice(request) ??
89
+ (request.toolChoice ? yield* OpenResponses.lowerToolChoice(NAME, request.toolChoice) : undefined),
90
+ });
91
+ });
92
+ const HOSTED_TOOLS = {
93
+ web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
94
+ image_generation_call: {
95
+ name: "image_generation",
96
+ input: () => ({}),
97
+ result: Effect.fn("MetaResponses.imageResult")(function* (raw) {
98
+ const item = yield* Schema.decodeUnknownEffect(ImageItem)(raw).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned an invalid image item", ProviderShared.encodeJson(raw), cause)));
99
+ if (item.error !== undefined && item.error !== null)
100
+ return { type: "error", value: item.error };
101
+ if (!item.result)
102
+ return yield* ProviderShared.eventError(ADAPTER, "Meta returned an image without data", ProviderShared.encodeJson(raw));
103
+ const data = yield* Effect.fromResult(Encoding.decodeBase64(item.result)).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned invalid image base64", ProviderShared.encodeJson(raw), cause)));
104
+ const mime = MetaImage.mediaType(data, item.output_format);
105
+ return {
106
+ type: "content",
107
+ value: [{ type: "file", uri: `data:${mime};base64,${item.result}`, mime }],
108
+ };
109
+ }),
110
+ },
111
+ };
112
+ const onEvent = Effect.fn("MetaResponses.onEvent")(function* (state, input) {
113
+ const event = OpenResponses.normalize(state, input);
114
+ if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
115
+ return yield* ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
116
+ const result = yield* OpenResponses.step(state, event);
117
+ if (event.type !== "response.output_item.done" || event.item?.type !== "message")
118
+ return result;
119
+ const message = yield* Schema.decodeUnknownEffect(MessageAnnotations)(event.item).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned invalid message annotations", ProviderShared.encodeJson(event), cause)));
120
+ const annotations = message.content.flatMap((part) => part.annotations ?? []);
121
+ if (annotations.length === 0)
122
+ return result;
123
+ return [
124
+ result[0],
125
+ result[1].map((item) => LLMEvent.is.textEnd(item)
126
+ ? LLMEvent.textEnd({
127
+ ...item,
128
+ providerMetadata: {
129
+ ...item.providerMetadata,
130
+ [state.providerMetadataKey]: { ...item.providerMetadata?.[state.providerMetadataKey], annotations },
131
+ },
132
+ })
133
+ : item),
134
+ ];
135
+ });
136
+ const step = Effect.fn("MetaResponses.step")(function* (state, input) {
137
+ const completedItems = new Set(state.completedItems);
138
+ const event = OpenResponses.normalize(state, input);
139
+ if (event.type === "response.output_item.done" && event.item && completedItems.has(event.item.id))
140
+ return [state, []];
141
+ const events = [];
142
+ let current = state;
143
+ // Muse Image delivers its image and optional summary only in response.completed.
144
+ // Recover terminal-only items in order, without duplicating Spark's streamed items.
145
+ if (event.type === "response.completed") {
146
+ for (const [index, item] of (event.response?.output ?? []).entries()) {
147
+ const done = OpenResponses.normalize(current, { type: "response.output_item.done", item, output_index: index });
148
+ // Spark changes reasoning IDs in the terminal snapshot; output indices still identify the streamed items.
149
+ if (!done.item || completedItems.has(done.item.id) || completedItems.has(state.outputItems[index] ?? ""))
150
+ continue;
151
+ const result = yield* onEvent(current, done);
152
+ current = result[0];
153
+ events.push(...result[1]);
154
+ completedItems.add(done.item.id);
155
+ }
156
+ }
157
+ const result = yield* onEvent(current, event);
158
+ if (event.type === "response.output_item.done" && event.item)
159
+ completedItems.add(event.item.id);
160
+ return [{ ...result[0], completedItems }, [...events, ...result[1]]];
161
+ });
162
+ export const protocol = Protocol.make({
163
+ id: ADAPTER,
164
+ body: { schema: Body, from: fromRequest },
165
+ stream: {
166
+ event: OpenResponses.protocol.stream.event,
167
+ initial: (request) => ({ ...OpenResponses.initial(request, adapter), completedItems: new Set() }),
168
+ step,
169
+ terminal: OpenResponses.terminal,
170
+ },
171
+ });
172
+ export const httpTransport = HttpTransport.sseJson.with();
173
+ export * as MetaResponses from "./meta-responses.js";