@opencode/ai 0.0.0-dev-19287 → 0.0.0-dev-19291

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,6 +29,67 @@ await Effect.runPromise(program.pipe(Effect.provide(llmLayer)))
29
29
 
30
30
  Run `LLMClient.stream(request)` instead of `generate` when you want incremental `LLMEvent`s. The event stream is provider-neutral — same shape across OpenAI Chat, OpenAI Responses, Anthropic Messages, Gemini, Bedrock Converse, and any OpenAI-compatible deployment.
31
31
 
32
+ ## Moonshot
33
+
34
+ Moonshot defaults to Chat Completions, with Messages and Responses selectors for Kimi K3:
35
+
36
+ ```ts
37
+ import { LLM } from "@opencode/ai"
38
+ import { Moonshot } from "@opencode/ai/providers"
39
+
40
+ const moonshot = Moonshot.configure({ apiKey: process.env.MOONSHOT_API_KEY })
41
+
42
+ const request = LLM.request({
43
+ model: moonshot.model("kimi-k3"), // also moonshot.chat("kimi-k3")
44
+ prompt: "Explain the tradeoffs in this design.",
45
+ providerOptions: { reasoningEffort: "high" },
46
+ })
47
+
48
+ const messages = LLM.request({
49
+ model: moonshot.messages("kimi-k3"),
50
+ prompt: "Explain the tradeoffs in this design.",
51
+ providerOptions: { effort: "high" },
52
+ })
53
+
54
+ const responses = LLM.request({
55
+ model: moonshot.responses("kimi-k3"),
56
+ prompt: "Explain the tradeoffs in this design.",
57
+ providerOptions: { reasoningEffort: "high" },
58
+ })
59
+ ```
60
+
61
+ When `apiKey` is omitted, authentication reads `MOONSHOT_API_KEY`, then `MOONSHOTAI_API_KEY`.
62
+ Chat and Responses use `https://api.moonshot.ai/v1`; Messages uses
63
+ `https://api.moonshot.ai/anthropic/v1`. `baseURL` overrides the selected API's complete base,
64
+ including the version prefix, for regional endpoints or gateways. Each endpoint requires its own valid credentials.
65
+ All three routes use HTTP/SSE.
66
+
67
+ Reasoning options stay native to the selected API and model:
68
+
69
+ | Model/API | Provider options |
70
+ | --------------------------- | --------------------------------------------------------------------------------------- |
71
+ | K3 Chat / Responses | `reasoningEffort: "low" \| "high" \| "max"`; default is `max` |
72
+ | K3 Messages | `effort: "low" \| "high" \| "max"`; default is `max` |
73
+ | K2.6 Chat | `thinking: { type: "enabled" \| "disabled", keep?: "all" \| null }`; default is enabled |
74
+ | K2.7 Code / high-speed Chat | Omit `thinking` to use always-on, preserved reasoning |
75
+
76
+ Omitting options preserves the model's defaults. K3 uses effort rather than the K2.x `thinking`
77
+ parameter. Known effort values have autocomplete while future strings remain accepted.
78
+ For K2.6, `thinking.keep: "all"` enables preservation of reasoning across user messages.
79
+ K3 and both K2.7 Code variants always preserve reasoning. Continue with the returned
80
+ `response.message` and matching tool results so reasoning content and any Messages signatures are retained.
81
+ Leave sampling options such as `temperature` unset to use these models' fixed defaults.
82
+
83
+ The recorded suite covers all three K3 APIs, default and explicit efforts, K2.6 thinking modes,
84
+ both K2.7 Code variants, generated tool loops with a subsequent user follow-up, required/disabled
85
+ tool choice, image-byte input, and native structured output through `http.body` overlays.
86
+ K3 Chat and Messages accept required and disabled tool choice. Responses supports automatic tool
87
+ choice only; explicit `required` and `none` produce a provider `InvalidRequest` error, also covered by recordings.
88
+ The provider targets the Moonshot Open Platform; Kimi Code is a separate product and endpoint.
89
+
90
+ Package entrypoints are `@opencode/ai/providers/moonshot`, `moonshot/chat`, `moonshot/messages`,
91
+ and `moonshot/responses`; each exports `model(modelID, settings)`.
92
+
32
93
  ## MiniMax
33
94
 
34
95
  MiniMax defaults to its Messages API and reads `MINIMAX_API_KEY` when `apiKey` is omitted:
@@ -19,6 +19,7 @@ export * as Groq from "./groq.js";
19
19
  export * as Meta from "./meta.js";
20
20
  export * as MiniMax from "./minimax.js";
21
21
  export * as Mistral from "./mistral.js";
22
+ export * as Moonshot from "./moonshot.js";
22
23
  export * as OpenAI from "./openai.js";
23
24
  export * as OpenAICompatible from "./openai-compatible.js";
24
25
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -19,6 +19,7 @@ export * as Groq from "./groq.js";
19
19
  export * as Meta from "./meta.js";
20
20
  export * as MiniMax from "./minimax.js";
21
21
  export * as Mistral from "./mistral.js";
22
+ export * as Moonshot from "./moonshot.js";
22
23
  export * as OpenAI from "./openai.js";
23
24
  export * as OpenAICompatible from "./openai-compatible.js";
24
25
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -0,0 +1 @@
1
+ export { model, type Settings } from "../moonshot.js";
@@ -0,0 +1 @@
1
+ export { model } from "../moonshot.js";
@@ -0,0 +1,4 @@
1
+ import type { ProviderPackage } from "../../provider-package.js";
2
+ import { Moonshot } from "../moonshot.js";
3
+ export type Settings = Moonshot.Settings<Moonshot.MessagesOptionsInput>;
4
+ export declare const model: ProviderPackage.Definition<Settings, Moonshot.MessagesOptionsInput>["model"];
@@ -0,0 +1,8 @@
1
+ import { Moonshot } from "../moonshot.js";
2
+ export const model = (modelID, settings) => Moonshot.configure({
3
+ apiKey: settings.apiKey,
4
+ baseURL: settings.baseURL,
5
+ headers: settings.headers,
6
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
7
+ providerOptions: settings.providerOptions,
8
+ }).messages(modelID);
@@ -0,0 +1,4 @@
1
+ import type { ProviderPackage } from "../../provider-package.js";
2
+ import { Moonshot } from "../moonshot.js";
3
+ export type Settings = Moonshot.Settings<Moonshot.ResponsesOptionsInput>;
4
+ export declare const model: ProviderPackage.Definition<Settings, Moonshot.ResponsesOptionsInput>["model"];
@@ -0,0 +1,8 @@
1
+ import { Moonshot } from "../moonshot.js";
2
+ export const model = (modelID, settings) => Moonshot.configure({
3
+ apiKey: settings.apiKey,
4
+ baseURL: settings.baseURL,
5
+ headers: settings.headers,
6
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
7
+ providerOptions: settings.providerOptions,
8
+ }).responses(modelID);
@@ -0,0 +1,591 @@
1
+ import type { ProviderPackage } from "../provider-package.js";
2
+ import { AnthropicMessages } from "../protocols/anthropic-messages.js";
3
+ import { type ProviderAuthOption } from "../route/auth-options.js";
4
+ import { Route, type RouteDefaultsInput } from "../route/client.js";
5
+ import { type ModelID } from "../schema/index.js";
6
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
+ export type ReasoningEffort = "low" | "high" | "max" | (string & {});
8
+ export type ChatOptionsInput = {
9
+ /** K3 always reasons; omitted effort uses the model's default. */
10
+ readonly reasoningEffort?: ReasoningEffort;
11
+ /** K2.6 supports disabling thinking; K2.7 Code always thinks and preserves reasoning. */
12
+ readonly thinking?: {
13
+ readonly type: "enabled" | "disabled" | (string & {});
14
+ readonly keep?: "all" | (string & {}) | null;
15
+ };
16
+ };
17
+ export type MessagesOptionsInput = {
18
+ readonly effort?: ReasoningEffort;
19
+ readonly metadata?: AnthropicMessages.OptionsInput["metadata"];
20
+ };
21
+ export type ResponsesOptionsInput = {
22
+ readonly reasoningEffort?: ReasoningEffort;
23
+ readonly safetyIdentifier?: string;
24
+ };
25
+ export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
26
+ /** Overrides the selected API's base URL, including its version prefix. */
27
+ readonly baseURL?: string;
28
+ readonly providerOptions?: ChatOptionsInput | MessagesOptionsInput | ResponsesOptionsInput;
29
+ };
30
+ export interface Settings<Options = ChatOptionsInput> extends ProviderPackage.Settings {
31
+ readonly apiKey?: string;
32
+ readonly baseURL?: string;
33
+ readonly providerOptions?: Options;
34
+ }
35
+ export declare const routes: (Route<{
36
+ readonly max_tokens: number;
37
+ readonly model: string;
38
+ readonly messages: readonly ({
39
+ readonly role: "user";
40
+ readonly content: readonly ({
41
+ readonly type: "text";
42
+ readonly text: string;
43
+ readonly cache_control?: {
44
+ readonly type: "ephemeral";
45
+ readonly ttl?: "1h" | "5m" | undefined;
46
+ } | undefined;
47
+ } | {
48
+ readonly type: "image";
49
+ readonly source: {
50
+ readonly type: "base64";
51
+ readonly media_type: string;
52
+ readonly data: string;
53
+ } | {
54
+ readonly type: "url";
55
+ readonly url: string;
56
+ } | {
57
+ readonly type: "file";
58
+ readonly file_id: string;
59
+ };
60
+ readonly cache_control?: {
61
+ readonly type: "ephemeral";
62
+ readonly ttl?: "1h" | "5m" | undefined;
63
+ } | undefined;
64
+ readonly transformations?: {
65
+ readonly oversized_image?: "error" | "downsize" | undefined;
66
+ } | undefined;
67
+ } | {
68
+ readonly type: "document";
69
+ readonly source: {
70
+ readonly type: "base64";
71
+ readonly media_type: "application/pdf";
72
+ readonly data: string;
73
+ } | {
74
+ readonly type: "text";
75
+ readonly media_type: "text/plain";
76
+ readonly data: string;
77
+ } | {
78
+ readonly type: "url";
79
+ readonly url: string;
80
+ } | {
81
+ readonly type: "file";
82
+ readonly file_id: string;
83
+ };
84
+ readonly title?: string | undefined;
85
+ readonly context?: string | undefined;
86
+ readonly cache_control?: {
87
+ readonly type: "ephemeral";
88
+ readonly ttl?: "1h" | "5m" | undefined;
89
+ } | undefined;
90
+ readonly citations?: {
91
+ readonly enabled: boolean;
92
+ } | undefined;
93
+ } | {
94
+ readonly type: "tool_result";
95
+ readonly content: string | readonly ({
96
+ readonly type: "text";
97
+ readonly text: string;
98
+ readonly cache_control?: {
99
+ readonly type: "ephemeral";
100
+ readonly ttl?: "1h" | "5m" | undefined;
101
+ } | undefined;
102
+ } | {
103
+ readonly type: "image";
104
+ readonly source: {
105
+ readonly type: "base64";
106
+ readonly media_type: string;
107
+ readonly data: string;
108
+ } | {
109
+ readonly type: "url";
110
+ readonly url: string;
111
+ } | {
112
+ readonly type: "file";
113
+ readonly file_id: string;
114
+ };
115
+ readonly cache_control?: {
116
+ readonly type: "ephemeral";
117
+ readonly ttl?: "1h" | "5m" | undefined;
118
+ } | undefined;
119
+ readonly transformations?: {
120
+ readonly oversized_image?: "error" | "downsize" | undefined;
121
+ } | undefined;
122
+ } | {
123
+ readonly type: "document";
124
+ readonly source: {
125
+ readonly type: "base64";
126
+ readonly media_type: "application/pdf";
127
+ readonly data: string;
128
+ } | {
129
+ readonly type: "text";
130
+ readonly media_type: "text/plain";
131
+ readonly data: string;
132
+ } | {
133
+ readonly type: "url";
134
+ readonly url: string;
135
+ } | {
136
+ readonly type: "file";
137
+ readonly file_id: string;
138
+ };
139
+ readonly title?: string | undefined;
140
+ readonly context?: string | undefined;
141
+ readonly cache_control?: {
142
+ readonly type: "ephemeral";
143
+ readonly ttl?: "1h" | "5m" | undefined;
144
+ } | undefined;
145
+ readonly citations?: {
146
+ readonly enabled: boolean;
147
+ } | undefined;
148
+ })[];
149
+ readonly tool_use_id: string;
150
+ readonly cache_control?: {
151
+ readonly type: "ephemeral";
152
+ readonly ttl?: "1h" | "5m" | undefined;
153
+ } | undefined;
154
+ readonly is_error?: boolean | undefined;
155
+ })[];
156
+ } | {
157
+ readonly role: "assistant";
158
+ readonly content: readonly ({
159
+ readonly type: "text";
160
+ readonly text: string;
161
+ readonly cache_control?: {
162
+ readonly type: "ephemeral";
163
+ readonly ttl?: "1h" | "5m" | undefined;
164
+ } | undefined;
165
+ } | {
166
+ readonly id: string;
167
+ readonly type: "tool_use";
168
+ readonly name: string;
169
+ readonly input: unknown;
170
+ readonly cache_control?: {
171
+ readonly type: "ephemeral";
172
+ readonly ttl?: "1h" | "5m" | undefined;
173
+ } | undefined;
174
+ } | {
175
+ readonly id: string;
176
+ readonly type: "server_tool_use";
177
+ readonly name: string;
178
+ readonly input: unknown;
179
+ readonly cache_control?: {
180
+ readonly type: "ephemeral";
181
+ readonly ttl?: "1h" | "5m" | undefined;
182
+ } | undefined;
183
+ } | {
184
+ readonly type: "web_search_tool_result" | "code_execution_tool_result" | "web_fetch_tool_result";
185
+ readonly content: unknown;
186
+ readonly tool_use_id: string;
187
+ readonly cache_control?: {
188
+ readonly type: "ephemeral";
189
+ readonly ttl?: "1h" | "5m" | undefined;
190
+ } | undefined;
191
+ } | {
192
+ readonly type: "thinking";
193
+ readonly thinking: string;
194
+ readonly signature: string;
195
+ readonly cache_control?: {
196
+ readonly type: "ephemeral";
197
+ readonly ttl?: "1h" | "5m" | undefined;
198
+ } | undefined;
199
+ } | {
200
+ readonly data: string;
201
+ readonly type: "redacted_thinking";
202
+ readonly cache_control?: {
203
+ readonly type: "ephemeral";
204
+ readonly ttl?: "1h" | "5m" | undefined;
205
+ } | undefined;
206
+ } | {
207
+ readonly type: "compaction";
208
+ readonly content: string | null;
209
+ })[];
210
+ } | {
211
+ readonly role: "system";
212
+ readonly content: readonly {
213
+ readonly type: "text";
214
+ readonly text: string;
215
+ readonly cache_control?: {
216
+ readonly type: "ephemeral";
217
+ readonly ttl?: "1h" | "5m" | undefined;
218
+ } | undefined;
219
+ }[];
220
+ })[];
221
+ readonly stream: true;
222
+ readonly metadata?: {
223
+ readonly user_id?: string | null | undefined;
224
+ } | undefined;
225
+ readonly tools?: readonly {
226
+ readonly description: string;
227
+ readonly name: string;
228
+ readonly input_schema: {
229
+ readonly [x: string]: unknown;
230
+ };
231
+ readonly cache_control?: {
232
+ readonly type: "ephemeral";
233
+ readonly ttl?: "1h" | "5m" | undefined;
234
+ } | undefined;
235
+ }[] | undefined;
236
+ readonly system?: readonly {
237
+ readonly type: "text";
238
+ readonly text: string;
239
+ readonly cache_control?: {
240
+ readonly type: "ephemeral";
241
+ readonly ttl?: "1h" | "5m" | undefined;
242
+ } | undefined;
243
+ }[] | undefined;
244
+ readonly temperature?: number | undefined;
245
+ readonly thinking?: {
246
+ readonly type: "enabled";
247
+ readonly budget_tokens: number;
248
+ readonly display?: "summarized" | "omitted" | undefined;
249
+ } | {
250
+ readonly type: "adaptive";
251
+ readonly display?: "summarized" | "omitted" | undefined;
252
+ } | {
253
+ readonly type: "disabled";
254
+ } | undefined;
255
+ readonly service_tier?: "auto" | "standard_only" | undefined;
256
+ readonly container?: string | {
257
+ readonly id?: string | null | undefined;
258
+ readonly skills?: readonly {
259
+ readonly [x: string]: unknown;
260
+ }[] | null | undefined;
261
+ } | null | undefined;
262
+ readonly inference_geo?: string | null | undefined;
263
+ readonly cache_control?: {
264
+ readonly type: "ephemeral";
265
+ readonly ttl?: "1h" | "5m" | undefined;
266
+ } | undefined;
267
+ readonly output_config?: {
268
+ readonly format?: {
269
+ readonly type: "json_schema";
270
+ readonly schema: {
271
+ readonly [x: string]: unknown;
272
+ };
273
+ } | null | undefined;
274
+ readonly effort?: string | undefined;
275
+ } | undefined;
276
+ readonly context_management?: {
277
+ readonly edits: readonly {
278
+ readonly type: "compact_20260112";
279
+ readonly instructions?: string | undefined;
280
+ readonly trigger?: {
281
+ readonly type: "input_tokens";
282
+ readonly value: number;
283
+ } | undefined;
284
+ readonly pause_after_compaction?: boolean | undefined;
285
+ }[];
286
+ } | undefined;
287
+ readonly tool_choice?: {
288
+ readonly type: "auto" | "none" | "any";
289
+ readonly disable_parallel_tool_use?: boolean | undefined;
290
+ } | {
291
+ readonly type: "tool";
292
+ readonly name: string;
293
+ readonly disable_parallel_tool_use?: boolean | undefined;
294
+ } | undefined;
295
+ readonly top_p?: number | undefined;
296
+ readonly top_k?: number | undefined;
297
+ readonly stop_sequences?: readonly string[] | undefined;
298
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
299
+ readonly input: readonly ({
300
+ readonly [x: string]: unknown;
301
+ readonly id: string;
302
+ readonly type: "web_search_call";
303
+ readonly status?: string | undefined;
304
+ readonly action?: {
305
+ readonly [x: string]: unknown;
306
+ } | null | undefined;
307
+ } | {
308
+ readonly [x: string]: unknown;
309
+ readonly id: string;
310
+ readonly type: "file_search_call";
311
+ readonly status?: string | undefined;
312
+ readonly queries?: readonly string[] | undefined;
313
+ readonly results?: readonly {
314
+ readonly [x: string]: unknown;
315
+ }[] | null | undefined;
316
+ } | {
317
+ readonly [x: string]: unknown;
318
+ readonly id: string;
319
+ readonly type: "code_interpreter_call";
320
+ readonly status?: string | undefined;
321
+ readonly code?: string | null | undefined;
322
+ readonly container_id?: string | null | undefined;
323
+ readonly outputs?: readonly {
324
+ readonly [x: string]: unknown;
325
+ }[] | null | undefined;
326
+ } | {
327
+ readonly [x: string]: unknown;
328
+ readonly id: string;
329
+ readonly type: "mcp_call";
330
+ readonly status?: string | undefined;
331
+ readonly name?: string | undefined;
332
+ readonly output?: string | null | undefined;
333
+ readonly error?: unknown;
334
+ readonly arguments?: string | undefined;
335
+ readonly server_label?: string | undefined;
336
+ } | {
337
+ readonly type: "reasoning";
338
+ readonly summary: readonly {
339
+ readonly type: "summary_text";
340
+ readonly text: string;
341
+ }[];
342
+ readonly id?: string | undefined;
343
+ readonly encrypted_content?: string | null | undefined;
344
+ } | {
345
+ readonly type: "compaction";
346
+ readonly encrypted_content: string;
347
+ readonly id?: string | null | undefined;
348
+ } | {
349
+ readonly role: "system";
350
+ readonly content: string;
351
+ } | {
352
+ readonly role: "developer";
353
+ readonly content: string;
354
+ } | {
355
+ readonly content: readonly ({
356
+ readonly type: "input_image";
357
+ readonly image_url: string;
358
+ readonly detail?: string | undefined;
359
+ } | {
360
+ readonly type: "input_file";
361
+ readonly filename: string;
362
+ readonly detail?: string | undefined;
363
+ readonly file_data?: string | undefined;
364
+ readonly file_url?: string | undefined;
365
+ } | {
366
+ readonly type: "input_text";
367
+ readonly text: string;
368
+ })[];
369
+ readonly role: "user";
370
+ readonly id?: string | undefined;
371
+ readonly type?: "message" | undefined;
372
+ readonly status?: string | undefined;
373
+ } | {
374
+ readonly type: "message";
375
+ readonly content: readonly {
376
+ readonly type: "output_text";
377
+ readonly text: string;
378
+ }[];
379
+ readonly role: "assistant";
380
+ readonly id?: string | undefined;
381
+ readonly status?: string | undefined;
382
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
383
+ } | {
384
+ readonly type: "function_call";
385
+ readonly name: string;
386
+ readonly arguments: string;
387
+ readonly call_id: string;
388
+ readonly id?: string | undefined;
389
+ readonly namespace?: string | undefined;
390
+ } | {
391
+ readonly type: "function_call_output";
392
+ readonly call_id: string;
393
+ readonly output: string | readonly ({
394
+ readonly type: "input_image";
395
+ readonly image_url: string;
396
+ readonly detail?: string | undefined;
397
+ } | {
398
+ readonly type: "input_file";
399
+ readonly filename: string;
400
+ readonly detail?: string | undefined;
401
+ readonly file_data?: string | undefined;
402
+ readonly file_url?: string | undefined;
403
+ } | {
404
+ readonly type: "input_text";
405
+ readonly text: string;
406
+ } | {
407
+ readonly type: "input_video";
408
+ readonly video_url: string;
409
+ })[];
410
+ })[];
411
+ readonly model: string;
412
+ readonly stream: true;
413
+ readonly metadata?: {
414
+ readonly [x: string]: string;
415
+ } | undefined;
416
+ readonly instructions?: string | undefined;
417
+ readonly reasoning?: {
418
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
419
+ readonly effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
420
+ } | undefined;
421
+ readonly tools?: readonly {
422
+ readonly type: "function";
423
+ readonly description: string;
424
+ readonly name: string;
425
+ readonly parameters: {
426
+ readonly [x: string]: unknown;
427
+ };
428
+ readonly strict?: boolean | undefined;
429
+ }[] | undefined;
430
+ readonly text?: {
431
+ readonly verbosity?: import("../protocols/utils/open-responses-options.js").TextVerbosity | undefined;
432
+ } | undefined;
433
+ readonly temperature?: number | undefined;
434
+ readonly service_tier?: import("../protocols/utils/open-responses-options.js").ServiceTier | undefined;
435
+ readonly tool_choice?: "required" | "auto" | "none" | {
436
+ readonly type: "function";
437
+ readonly name: string;
438
+ } | {
439
+ readonly type: "allowed_tools";
440
+ readonly mode: "required" | "auto" | "none";
441
+ readonly tools: readonly {
442
+ readonly type: "function";
443
+ readonly name: string;
444
+ }[];
445
+ } | undefined;
446
+ readonly top_p?: number | undefined;
447
+ readonly frequency_penalty?: number | undefined;
448
+ readonly presence_penalty?: number | undefined;
449
+ readonly prompt_cache_key?: string | undefined;
450
+ readonly parallel_tool_calls?: boolean | undefined;
451
+ readonly store?: boolean | undefined;
452
+ readonly include?: readonly import("../protocols/utils/open-responses-options.js").ResponseIncludable[] | undefined;
453
+ readonly truncation?: "auto" | "disabled" | undefined;
454
+ readonly stream_options?: {
455
+ readonly include_obfuscation?: boolean | undefined;
456
+ } | undefined;
457
+ readonly safety_identifier?: string | undefined;
458
+ readonly top_logprobs?: number | undefined;
459
+ readonly max_output_tokens?: number | undefined;
460
+ readonly max_tool_calls?: number | undefined;
461
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
462
+ readonly model: string;
463
+ readonly messages: readonly ({
464
+ readonly role: "system";
465
+ readonly content: string | readonly ({
466
+ readonly type: "text";
467
+ readonly text: string;
468
+ readonly cache_control?: {
469
+ readonly type: "ephemeral";
470
+ readonly ttl?: string | undefined;
471
+ } | undefined;
472
+ } | {
473
+ readonly type: "image_url";
474
+ readonly image_url: {
475
+ readonly url: string;
476
+ };
477
+ })[];
478
+ } | {
479
+ readonly role: "user";
480
+ readonly content: string | readonly ({
481
+ readonly type: "text";
482
+ readonly text: string;
483
+ readonly cache_control?: {
484
+ readonly type: "ephemeral";
485
+ readonly ttl?: string | undefined;
486
+ } | undefined;
487
+ } | {
488
+ readonly type: "image_url";
489
+ readonly image_url: {
490
+ readonly url: string;
491
+ };
492
+ })[];
493
+ } | {
494
+ readonly [x: string]: unknown;
495
+ readonly content: string | null;
496
+ readonly role: "assistant";
497
+ readonly reasoning?: string | undefined;
498
+ readonly reasoning_content?: string | undefined;
499
+ readonly reasoning_text?: string | undefined;
500
+ readonly cache_control?: {
501
+ readonly type: "ephemeral";
502
+ readonly ttl?: string | undefined;
503
+ } | undefined;
504
+ readonly tool_calls?: readonly {
505
+ readonly id: string;
506
+ readonly type: "function";
507
+ readonly function: {
508
+ readonly name: string;
509
+ readonly arguments: string;
510
+ };
511
+ }[] | undefined;
512
+ readonly reasoning_details?: unknown;
513
+ } | {
514
+ readonly content: string;
515
+ readonly role: "tool";
516
+ readonly tool_call_id: string;
517
+ readonly cache_control?: {
518
+ readonly type: "ephemeral";
519
+ readonly ttl?: string | undefined;
520
+ } | undefined;
521
+ })[];
522
+ readonly stream: true;
523
+ readonly max_completion_tokens?: number | undefined;
524
+ readonly max_tokens?: number | undefined;
525
+ readonly tools?: readonly {
526
+ readonly function: {
527
+ readonly description: string;
528
+ readonly name: string;
529
+ readonly parameters: {
530
+ readonly [x: string]: unknown;
531
+ };
532
+ readonly strict?: boolean | undefined;
533
+ };
534
+ readonly type: "function";
535
+ readonly cache_control?: {
536
+ readonly type: "ephemeral";
537
+ readonly ttl?: string | undefined;
538
+ } | undefined;
539
+ }[] | undefined;
540
+ readonly stop?: readonly string[] | undefined;
541
+ readonly temperature?: number | undefined;
542
+ readonly seed?: number | undefined;
543
+ readonly thinking?: {
544
+ readonly type: string;
545
+ readonly keep?: string | null | undefined;
546
+ } | undefined;
547
+ readonly tool_choice?: "required" | "auto" | "none" | {
548
+ readonly type: "function";
549
+ readonly function: {
550
+ readonly name: string;
551
+ };
552
+ } | undefined;
553
+ readonly top_p?: number | undefined;
554
+ readonly frequency_penalty?: number | undefined;
555
+ readonly presence_penalty?: number | undefined;
556
+ readonly prompt_cache_key?: string | undefined;
557
+ readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
558
+ readonly store?: boolean | undefined;
559
+ readonly stream_options?: {
560
+ readonly include_usage: boolean;
561
+ } | undefined;
562
+ readonly tool_stream?: boolean | undefined;
563
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
564
+ export declare const configure: (input?: Config) => {
565
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
566
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
567
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
568
+ messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<MessagesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
569
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
570
+ configure: (input?: Config) => /*elided*/ any;
571
+ };
572
+ export declare const provider: {
573
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
574
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
575
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
576
+ messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<MessagesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
577
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
578
+ configure: (input?: Config) => {
579
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
580
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
581
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
582
+ messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<MessagesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
583
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
584
+ configure: /*elided*/ any;
585
+ };
586
+ };
587
+ export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
588
+ export declare const messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<MessagesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
589
+ export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ResponsesOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
590
+ export declare const model: ProviderPackage.Definition<Settings, ChatOptionsInput>["model"];
591
+ export * as Moonshot from "./moonshot.js";
@@ -0,0 +1,90 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { AnthropicMessages } from "../protocols/anthropic-messages.js";
3
+ import { OpenAIChat } from "../protocols/openai-chat.js";
4
+ import { OpenResponses } from "../protocols/open-responses.js";
5
+ import { ProviderShared } from "../protocols/shared.js";
6
+ import { AuthOptions } from "../route/auth-options.js";
7
+ import { Route } from "../route/client.js";
8
+ import { Endpoint } from "../route/endpoint.js";
9
+ import { Framing } from "../route/framing.js";
10
+ import { Protocol } from "../route/protocol.js";
11
+ import { ProviderID } from "../schema/index.js";
12
+ export const id = ProviderID.make("moonshotai");
13
+ const ChatOptions = Schema.Struct({
14
+ reasoningEffort: Schema.optional(Schema.String),
15
+ thinking: Schema.optional(Schema.Struct({ type: Schema.String, keep: Schema.optional(Schema.NullOr(Schema.String)) })),
16
+ });
17
+ const chatProtocol = Protocol.make({
18
+ id: "moonshot-chat",
19
+ body: {
20
+ schema: Schema.Struct({ ...OpenAIChat.bodyFields, thinking: ChatOptions.fields.thinking }),
21
+ from: Effect.fn("Moonshot.chatFromRequest")(function* (request) {
22
+ const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(ChatOptions))(request.providerOptions ?? {});
23
+ return { ...(yield* OpenAIChat.protocol.body.from(request)), thinking: options.thinking };
24
+ }),
25
+ },
26
+ stream: OpenAIChat.protocol.stream,
27
+ });
28
+ const chatRoute = Route.make({
29
+ id: "moonshot-chat",
30
+ provider: id,
31
+ providerMetadataKey: "moonshot",
32
+ protocol: chatProtocol,
33
+ endpoint: Endpoint.path("/chat/completions", { baseURL: "https://api.moonshot.ai/v1" }),
34
+ framing: OpenAIChat.framing,
35
+ });
36
+ const messagesRoute = Route.make({
37
+ id: "moonshot-messages",
38
+ provider: id,
39
+ providerMetadataKey: "moonshot",
40
+ protocol: AnthropicMessages.protocol,
41
+ endpoint: Endpoint.path("/messages", { baseURL: "https://api.moonshot.ai/anthropic/v1" }),
42
+ framing: AnthropicMessages.framing,
43
+ });
44
+ const responsesRoute = Route.make({
45
+ id: "moonshot-responses",
46
+ provider: id,
47
+ providerMetadataKey: "moonshot",
48
+ protocol: OpenResponses.protocol,
49
+ endpoint: Endpoint.path("/responses", { baseURL: "https://api.moonshot.ai/v1" }),
50
+ framing: Framing.sse,
51
+ });
52
+ export const routes = [chatRoute, messagesRoute, responsesRoute];
53
+ export const configure = (input = {}) => {
54
+ const { apiKey: _apiKey, auth: _auth, baseURL, ...rest } = input;
55
+ const defaults = {
56
+ ...rest,
57
+ endpoint: baseURL === undefined ? undefined : { baseURL },
58
+ auth: AuthOptions.bearer(input, ["MOONSHOT_API_KEY", "MOONSHOTAI_API_KEY"]),
59
+ };
60
+ const chat = (modelID) => chatRoute.with(defaults).model({
61
+ id: modelID,
62
+ compatibility: {
63
+ maxTokensField: "max_tokens",
64
+ supportsStore: false,
65
+ supportsStrictMode: false,
66
+ toolSchema: "moonshot",
67
+ reasoningField: "reasoning_content",
68
+ },
69
+ });
70
+ const messages = (modelID) => messagesRoute.with(defaults).model({
71
+ id: modelID,
72
+ compatibility: { requireSignature: false, toolSchema: "moonshot" },
73
+ });
74
+ const responses = (modelID) => responsesRoute
75
+ .with(defaults)
76
+ .model({ id: modelID, compatibility: { toolSchema: "moonshot" } });
77
+ return { id, model: chat, chat, messages, responses, configure };
78
+ };
79
+ export const provider = configure();
80
+ export const chat = provider.chat;
81
+ export const messages = provider.messages;
82
+ export const responses = provider.responses;
83
+ export const model = (modelID, settings) => configure({
84
+ apiKey: settings.apiKey,
85
+ baseURL: settings.baseURL,
86
+ headers: settings.headers,
87
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
88
+ providerOptions: settings.providerOptions,
89
+ }).model(modelID);
90
+ export * as Moonshot from "./moonshot.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-19287",
3
+ "version": "0.0.0-dev-19291",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0-alpha.1",
32
32
  "@effect/platform-node": "4.0.0-rc.112",
33
- "@opencode/http-recorder": "0.0.0-dev-19287",
33
+ "@opencode/http-recorder": "0.0.0-dev-19291",
34
34
  "@tsconfig/bun": "1.0.9",
35
35
  "@types/bun": "1.4.0",
36
36
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -40,7 +40,7 @@
40
40
  "@aws-sdk/credential-providers": "3.1057.0",
41
41
  "@smithy/eventstream-codec": "4.2.14",
42
42
  "@smithy/util-utf8": "4.2.2",
43
- "@opencode/schema": "0.0.0-dev-19287",
43
+ "@opencode/schema": "0.0.0-dev-19291",
44
44
  "aws4fetch": "1.0.20",
45
45
  "effect": "4.0.0-rc.112",
46
46
  "google-auth-library": "10.5.0"