@revojs/ai 0.2.13 → 0.2.15

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 ADDED
@@ -0,0 +1,67 @@
1
+ # @revojs/ai
2
+
3
+ ## Model Context Protocol
4
+
5
+ Connect to a Model Context Protocol server using Streamable HTTP. Headers,
6
+ an SDK OAuth provider, a custom fetch implementation,
7
+ and custom SDK transports are supported. Keep credentials on the server and only
8
+ connect to trusted endpoints.
9
+
10
+ ```ts
11
+ import { useAi, useModelContextProtocol } from "@revojs/ai";
12
+
13
+ const modelContextProtocol = await useModelContextProtocol({ endpoint: "https://example.com/mcp" });
14
+
15
+ try {
16
+ const { openai } = useAi(scope);
17
+ const result = await openai.textGenerate({
18
+ model,
19
+ prompt,
20
+ tools: await modelContextProtocol.listTools(),
21
+ });
22
+
23
+ for (const call of result.content) {
24
+ if (call.type === "tool-call" && !call.providerExecuted) {
25
+ const output = await modelContextProtocol.executeTool(call);
26
+ }
27
+ }
28
+ } finally {
29
+ await modelContextProtocol.close();
30
+ }
31
+ ```
32
+
33
+ `listTools()` follows pagination and returns AI function-tool definitions.
34
+ `executeTool()` parses a normalized model tool call and returns a tool-result part
35
+ for the next prompt. It preserves the entire Model Context Protocol result, including structured and
36
+ multimodal content, as JSON. Model Context Protocol tool errors become `error-json`; invalid input and
37
+ transport/protocol errors throw. Tool execution is explicit: apply authorization
38
+ or approval checks before calling it. The application controls the conversation
39
+ loop, stream consumption, and tool namespacing/routing when combining multiple servers.
40
+
41
+ Use `modelContextProtocol.client.callTool({ name, arguments })` for the original SDK result.
42
+ Use `modelContextProtocol.client` for SDK
43
+ operations such as `listResources()`, `readResource({ uri })`, `listPrompts()`, and
44
+ `getPrompt({ name, arguments })`. SDK request options support cancellation and
45
+ timeouts; `useModelContextProtocol` accepts them as `requestOptions`, and the tool methods take
46
+ them as their last argument.
47
+
48
+ For local stdio servers, create a `StdioClientTransport` from the Model Context Protocol SDK in
49
+ Node/Bun application code and pass it as `transport`. The runtime entry itself
50
+ does not import Node process APIs. Always close the connection when finished;
51
+ HTTP sessions are terminated before disconnecting.
52
+
53
+ ## OpenCode Go
54
+
55
+ `useAi(scope)["opencode-go"]` supports generation and streaming using the existing
56
+ Chat Completions, Responses, and Anthropic Messages protocols, including function tools. Configure the
57
+ server-side `opencodeApiKey` variable. Supply a stable `x-opencode-session` header
58
+ for every request, normally the conversation ID. Caller headers cannot override
59
+ authorization, and Responses requests always use `store: false`.
60
+
61
+ The provider includes all 45 IDs returned by the
62
+ [Go model catalog](https://opencode.ai/zen/go/v1/models) on October 10, 2026,
63
+ including legacy IDs. Protocol mappings use the [models.dev catalog](https://models.dev/api.json):
64
+ Grok, GPT Luna, and Muse Spark use Responses; Claude Haiku 5.5, MiniMax M3/M2.7,
65
+ and Qwen3.8 Max/Flash and Qwen3.7 Plus use Anthropic Messages. The remaining IDs
66
+ use Chat Completions. Live availability and subscription limits are controlled
67
+ by OpenCode Go; the model catalog may change.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3
+ import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
+ import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
1
5
  import { type Scope, type Source, type SourceScope, type SourceValue } from "revojs";
2
6
  import type { JSONObject, JSONValue, JsonSchema } from "revojs/shared";
7
+ export type ModelContextProtocolConnectOptions = ModelContextProtocolHttpConnectOptions | ModelContextProtocolTransportConnectOptions;
3
8
  export type SharedWarning = {
4
9
  type: "unsupported" | "compatibility";
5
10
  feature: string;
@@ -29,6 +34,25 @@ export type LanguageModelMessage = ({
29
34
  providerOptions?: Record<string, JSONObject>;
30
35
  };
31
36
  export type LanguageModelContent = LanguageModelText | LanguageModelReasoning | LanguageModelCustomContent | LanguageModelReasoningFile | LanguageModelFile | LanguageModelToolApprovalRequest | LanguageModelSource | LanguageModelToolCall | LanguageModelToolResult;
37
+ export interface ModelContextProtocolClientInfo {
38
+ name: string;
39
+ version: string;
40
+ }
41
+ export interface ModelContextProtocolConnectionOptions {
42
+ clientInfo?: ModelContextProtocolClientInfo;
43
+ requestOptions?: RequestOptions;
44
+ }
45
+ export interface ModelContextProtocolHttpConnectOptions extends ModelContextProtocolConnectionOptions {
46
+ endpoint: string | URL;
47
+ transport?: "http";
48
+ headers?: Record<string, string>;
49
+ authProvider?: StreamableHTTPClientTransportOptions["authProvider"];
50
+ fetch?: StreamableHTTPClientTransportOptions["fetch"];
51
+ }
52
+ export interface ModelContextProtocolTransportConnectOptions extends ModelContextProtocolConnectionOptions {
53
+ transport: Transport;
54
+ endpoint?: never;
55
+ }
32
56
  export interface LanguageModelText {
33
57
  type: "text";
34
58
  text: string;
@@ -610,6 +634,15 @@ export interface SkillsUploadSkillResult {
610
634
  export interface Provider {
611
635
  setup: (scope: Scope) => ProviderConnection;
612
636
  }
637
+ export declare class ModelContextProtocolConnection {
638
+ readonly client: Client;
639
+ private readonly transport;
640
+ constructor(client: Client, transport: Transport);
641
+ listTools(options?: RequestOptions): Promise<Array<LanguageModelFunctionTool>>;
642
+ executeTool(call: LanguageModelToolCall, options?: RequestOptions): Promise<LanguageModelToolResultPart>;
643
+ close(): Promise<void>;
644
+ }
645
+ export declare function useModelContextProtocol(options: ModelContextProtocolConnectOptions): Promise<ModelContextProtocolConnection>;
613
646
  export declare function defineProvider<TProvider extends Provider>(provider: TProvider): TProvider;
614
647
  export declare function useAi<TSource extends Source<Provider> = typeof import("#providers").default>(scope: Scope): AiConnections<TSource>;
615
648
  export declare function mergeHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string>;
package/dist/index.js CHANGED
@@ -1,6 +1,80 @@
1
1
  import providers from "#providers";
2
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
4
  import "revojs";
3
5
  //#region src/index.ts
6
+ var ModelContextProtocolConnection = class {
7
+ client;
8
+ transport;
9
+ constructor(client, transport) {
10
+ this.client = client;
11
+ this.transport = transport;
12
+ }
13
+ async listTools(options) {
14
+ const tools = new Array();
15
+ const cursors = /* @__PURE__ */ new Set();
16
+ let cursor;
17
+ do {
18
+ const result = await this.client.listTools({ cursor }, options);
19
+ for (const tool of result.tools) tools.push({
20
+ type: "function",
21
+ name: tool.name,
22
+ description: tool.description,
23
+ inputSchema: tool.inputSchema
24
+ });
25
+ cursor = result.nextCursor;
26
+ if (cursor !== void 0 && cursors.has(cursor)) throw new Error("Model Context Protocol server returned a repeated tools pagination cursor.");
27
+ if (cursor !== void 0) cursors.add(cursor);
28
+ } while (cursor !== void 0);
29
+ return tools;
30
+ }
31
+ async executeTool(call, options) {
32
+ const input = JSON.parse(call.input);
33
+ if (input === null || typeof input !== "object" || Array.isArray(input)) throw new Error(`Model Context Protocol tool "${call.toolName}" requires a JSON object as input.`);
34
+ const result = await this.client.callTool({
35
+ name: call.toolName,
36
+ arguments: input
37
+ }, void 0, options);
38
+ return {
39
+ type: "tool-result",
40
+ toolCallId: call.toolCallId,
41
+ toolName: call.toolName,
42
+ output: {
43
+ type: result.isError ? "error-json" : "json",
44
+ value: result
45
+ }
46
+ };
47
+ }
48
+ async close() {
49
+ try {
50
+ if (this.transport instanceof StreamableHTTPClientTransport && this.transport.sessionId !== void 0) await this.transport.terminateSession();
51
+ } finally {
52
+ await this.client.close();
53
+ }
54
+ }
55
+ };
56
+ async function useModelContextProtocol(options) {
57
+ const client = new Client(options.clientInfo ?? {
58
+ name: "revojs",
59
+ version: "1.0.0"
60
+ });
61
+ let transport = options.transport;
62
+ if (typeof transport !== "object") {
63
+ if (options.endpoint === void 0) throw new Error("Model Context Protocol requires an endpoint or a custom transport.");
64
+ transport = new StreamableHTTPClientTransport(new URL(options.endpoint), {
65
+ authProvider: options.authProvider,
66
+ fetch: options.fetch,
67
+ requestInit: { headers: options.headers }
68
+ });
69
+ }
70
+ try {
71
+ await client.connect(transport, options.requestOptions);
72
+ return new ModelContextProtocolConnection(client, transport);
73
+ } catch (error) {
74
+ await client.close().catch(() => {});
75
+ throw error;
76
+ }
77
+ }
4
78
  function defineProvider(provider) {
5
79
  return provider;
6
80
  }
@@ -83,4 +157,4 @@ function toStream(read) {
83
157
  });
84
158
  }
85
159
  //#endregion
86
- export { defineProvider, mergeHeaders, postJson, readDataFrames, toStream, useAi };
160
+ export { ModelContextProtocolConnection, defineProvider, mergeHeaders, postJson, readDataFrames, toStream, useAi, useModelContextProtocol };
@@ -144,7 +144,7 @@ function toFinishReason(raw) {
144
144
  raw
145
145
  };
146
146
  return {
147
- unified: "stop",
147
+ unified: raw === "stop" ? "stop" : "other",
148
148
  raw: raw ?? void 0
149
149
  };
150
150
  }
@@ -216,14 +216,14 @@ async function* readParts(response, warnings) {
216
216
  accumulator = {
217
217
  streamId: `openai-tool-${index}`,
218
218
  callId: partial.id ?? "",
219
- name: partial.function?.name ?? "",
219
+ name: "",
220
220
  arguments: ""
221
221
  };
222
222
  tools.set(index, accumulator);
223
223
  yield {
224
224
  type: "tool-input-start",
225
225
  id: accumulator.streamId,
226
- toolName: accumulator.name
226
+ toolName: partial.function?.name ?? ""
227
227
  };
228
228
  }
229
229
  if (partial.id !== void 0 && partial.id !== accumulator.callId) accumulator.callId = partial.id;
@@ -238,6 +238,7 @@ async function* readParts(response, warnings) {
238
238
  }
239
239
  }
240
240
  }
241
+ if (finishRaw === void 0) throw new Error("Incomplete chat completions stream.");
241
242
  if (reasoningStarted) yield {
242
243
  type: "reasoning-end",
243
244
  id: "openai-reasoning-0"
@@ -23,7 +23,7 @@ function toUsage(usage) {
23
23
  }
24
24
  function toFinishReason(status, toolCalls, incomplete) {
25
25
  return {
26
- unified: toolCalls ? "tool-calls" : incomplete === "max_output_tokens" ? "length" : status === "failed" ? "error" : "stop",
26
+ unified: incomplete === "max_output_tokens" ? "length" : status === "failed" ? "error" : status === "incomplete" ? "other" : toolCalls ? "tool-calls" : "stop",
27
27
  raw: incomplete ?? status ?? void 0
28
28
  };
29
29
  }
@@ -167,6 +167,7 @@ async function* readParts(response, warnings) {
167
167
  const tools = /* @__PURE__ */ new Map();
168
168
  let metadataSent = false;
169
169
  let hasToolCall = false;
170
+ let finished = false;
170
171
  let status;
171
172
  let incomplete;
172
173
  let usage;
@@ -289,7 +290,8 @@ async function* readParts(response, warnings) {
289
290
  continue;
290
291
  }
291
292
  if (event.type === "response.completed" || event.type === "response.incomplete") {
292
- status = event.response?.status;
293
+ finished = true;
294
+ status = event.response?.status ?? (event.type === "response.completed" ? "completed" : "incomplete");
293
295
  incomplete = event.response?.incomplete_details?.reason;
294
296
  usage = toUsage(event.response?.usage);
295
297
  continue;
@@ -297,6 +299,7 @@ async function* readParts(response, warnings) {
297
299
  if (event.type === "response.failed") throw new Error(event.response?.error?.message ?? "Unknown AI provider error");
298
300
  if (event.type === "error") throw new Error(event.message ?? "Unknown AI provider error");
299
301
  }
302
+ if (!finished) throw new Error("Incomplete responses stream.");
300
303
  for (const id of text) yield {
301
304
  type: "text-end",
302
305
  id
@@ -0,0 +1,100 @@
1
+ import { type LanguageModelCallOptions } from "../index";
2
+ declare const _default: {
3
+ setup(scope: import("revojs").Scope): {
4
+ textGenerate: {
5
+ "kimi-k3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
6
+ "kimi-k2.7-code": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
7
+ "kimi-k2.6": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
8
+ "kimi-k2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
9
+ "glm-5.3-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
10
+ "glm-5.3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
11
+ "glm-5.2": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
12
+ "glm-5.1": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
13
+ "glm-5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
14
+ "deepseek-v4.1-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
15
+ "deepseek-v4-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
16
+ "deepseek-v4-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
17
+ "deepseek-v4-flash-vision-exp": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
18
+ "deepseek-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
19
+ "longcat-2.0": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
20
+ "longcat-2.5-preview-free": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
21
+ "step-5-preview-free": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
22
+ "mimo-v2.6-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
23
+ "mimo-v2.6-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
24
+ "mimo-v2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
25
+ "mimo-v2.5-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
26
+ "mimo-v2-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
27
+ "mimo-v2-omni": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
28
+ "minimax-m2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
29
+ "qwen3.7-max": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
30
+ "qwen3.6-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
31
+ "qwen3.5-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
32
+ "hy4-preview": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
33
+ hy3: (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
34
+ "hy3-preview": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
35
+ "omen-alpha": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
36
+ "space-bunny": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
37
+ "grok-4.7": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
38
+ "grok-4.6": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
39
+ "grok-4.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
40
+ "gpt-6-luna": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
41
+ "gpt-5.6-luna": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
42
+ "muse-spark-1.3-contributor": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
43
+ "muse-spark-1.2-contributor": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
44
+ "claude-haiku-5-5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
45
+ "minimax-m3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
46
+ "minimax-m2.7": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
47
+ "qwen3.8-max": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
48
+ "qwen3.8-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
49
+ "qwen3.7-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelGenerateResult>;
50
+ };
51
+ textStream: {
52
+ "kimi-k3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
53
+ "kimi-k2.7-code": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
54
+ "kimi-k2.6": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
55
+ "kimi-k2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
56
+ "glm-5.3-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
57
+ "glm-5.3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
58
+ "glm-5.2": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
59
+ "glm-5.1": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
60
+ "glm-5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
61
+ "deepseek-v4.1-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
62
+ "deepseek-v4-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
63
+ "deepseek-v4-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
64
+ "deepseek-v4-flash-vision-exp": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
65
+ "deepseek-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
66
+ "longcat-2.0": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
67
+ "longcat-2.5-preview-free": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
68
+ "step-5-preview-free": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
69
+ "mimo-v2.6-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
70
+ "mimo-v2.6-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
71
+ "mimo-v2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
72
+ "mimo-v2.5-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
73
+ "mimo-v2-pro": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
74
+ "mimo-v2-omni": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
75
+ "minimax-m2.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
76
+ "qwen3.7-max": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
77
+ "qwen3.6-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
78
+ "qwen3.5-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
79
+ "hy4-preview": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
80
+ hy3: (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
81
+ "hy3-preview": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
82
+ "omen-alpha": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
83
+ "space-bunny": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
84
+ "grok-4.7": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
85
+ "grok-4.6": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
86
+ "grok-4.5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
87
+ "gpt-6-luna": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
88
+ "gpt-5.6-luna": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
89
+ "muse-spark-1.3-contributor": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
90
+ "muse-spark-1.2-contributor": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
91
+ "claude-haiku-5-5": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
92
+ "minimax-m3": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
93
+ "minimax-m2.7": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
94
+ "qwen3.8-max": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
95
+ "qwen3.8-flash": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
96
+ "qwen3.7-plus": (options: LanguageModelCallOptions) => PromiseLike<import("../index").LanguageModelStreamResult>;
97
+ };
98
+ };
99
+ };
100
+ export default _default;
@@ -0,0 +1,138 @@
1
+ import { defineProvider } from "../index.js";
2
+ import { messagesGenerateProtocol, messagesStreamProtocol } from "../protocols/anthropic-messages.js";
3
+ import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
4
+ import { responsesGenerateProtocol, responsesStreamProtocol } from "../protocols/openai-responses.js";
5
+ import { useVariables } from "revojs";
6
+ //#region src/providers/opencode-go.ts
7
+ var opencode_go_default = defineProvider({ setup(scope) {
8
+ function withSession(protocol) {
9
+ return (options) => {
10
+ if (!variables.opencodeApiKey) throw new Error("OpenCode Go requires opencodeApiKey.");
11
+ const headers = new Headers();
12
+ for (const [name, value] of Object.entries(options.headers ?? {})) if (value !== void 0) headers.set(name, value);
13
+ if (!headers.get("x-opencode-session")?.trim()) throw new Error("OpenCode Go requires a stable x-opencode-session header.");
14
+ headers.delete("Authorization");
15
+ headers.delete("x-api-key");
16
+ return protocol({
17
+ ...options,
18
+ headers: Object.fromEntries(headers.entries()),
19
+ providerOptions: {
20
+ ...options.providerOptions,
21
+ responses: {
22
+ ...options.providerOptions?.responses,
23
+ store: false
24
+ }
25
+ }
26
+ });
27
+ };
28
+ }
29
+ const variables = useVariables(scope);
30
+ const config = {
31
+ baseURL: "https://opencode.ai/zen/go/v1",
32
+ apiKey: variables.opencodeApiKey
33
+ };
34
+ const chatCompletionsGenerate = withSession(chatCompletionsGenerateProtocol(config));
35
+ const chatCompletionsStream = withSession(chatCompletionsStreamProtocol(config));
36
+ const responsesGenerate = withSession(responsesGenerateProtocol(config));
37
+ const responsesStream = withSession(responsesStreamProtocol(config));
38
+ const messagesGenerate = withSession(messagesGenerateProtocol(config));
39
+ const messagesStream = withSession(messagesStreamProtocol(config));
40
+ return {
41
+ textGenerate: {
42
+ "kimi-k3": chatCompletionsGenerate,
43
+ "kimi-k2.7-code": chatCompletionsGenerate,
44
+ "kimi-k2.6": chatCompletionsGenerate,
45
+ "kimi-k2.5": chatCompletionsGenerate,
46
+ "glm-5.3-flash": chatCompletionsGenerate,
47
+ "glm-5.3": chatCompletionsGenerate,
48
+ "glm-5.2": chatCompletionsGenerate,
49
+ "glm-5.1": chatCompletionsGenerate,
50
+ "glm-5": chatCompletionsGenerate,
51
+ "deepseek-v4.1-flash": chatCompletionsGenerate,
52
+ "deepseek-v4-pro": chatCompletionsGenerate,
53
+ "deepseek-v4-flash": chatCompletionsGenerate,
54
+ "deepseek-v4-flash-vision-exp": chatCompletionsGenerate,
55
+ "deepseek-flash": chatCompletionsGenerate,
56
+ "longcat-2.0": chatCompletionsGenerate,
57
+ "longcat-2.5-preview-free": chatCompletionsGenerate,
58
+ "step-5-preview-free": chatCompletionsGenerate,
59
+ "mimo-v2.6-flash": chatCompletionsGenerate,
60
+ "mimo-v2.6-pro": chatCompletionsGenerate,
61
+ "mimo-v2.5": chatCompletionsGenerate,
62
+ "mimo-v2.5-pro": chatCompletionsGenerate,
63
+ "mimo-v2-pro": chatCompletionsGenerate,
64
+ "mimo-v2-omni": chatCompletionsGenerate,
65
+ "minimax-m2.5": chatCompletionsGenerate,
66
+ "qwen3.7-max": chatCompletionsGenerate,
67
+ "qwen3.6-plus": chatCompletionsGenerate,
68
+ "qwen3.5-plus": chatCompletionsGenerate,
69
+ "hy4-preview": chatCompletionsGenerate,
70
+ hy3: chatCompletionsGenerate,
71
+ "hy3-preview": chatCompletionsGenerate,
72
+ "omen-alpha": chatCompletionsGenerate,
73
+ "space-bunny": chatCompletionsGenerate,
74
+ "grok-4.7": responsesGenerate,
75
+ "grok-4.6": responsesGenerate,
76
+ "grok-4.5": responsesGenerate,
77
+ "gpt-6-luna": responsesGenerate,
78
+ "gpt-5.6-luna": responsesGenerate,
79
+ "muse-spark-1.3-contributor": responsesGenerate,
80
+ "muse-spark-1.2-contributor": responsesGenerate,
81
+ "claude-haiku-5-5": messagesGenerate,
82
+ "minimax-m3": messagesGenerate,
83
+ "minimax-m2.7": messagesGenerate,
84
+ "qwen3.8-max": messagesGenerate,
85
+ "qwen3.8-flash": messagesGenerate,
86
+ "qwen3.7-plus": messagesGenerate
87
+ },
88
+ textStream: {
89
+ "kimi-k3": chatCompletionsStream,
90
+ "kimi-k2.7-code": chatCompletionsStream,
91
+ "kimi-k2.6": chatCompletionsStream,
92
+ "kimi-k2.5": chatCompletionsStream,
93
+ "glm-5.3-flash": chatCompletionsStream,
94
+ "glm-5.3": chatCompletionsStream,
95
+ "glm-5.2": chatCompletionsStream,
96
+ "glm-5.1": chatCompletionsStream,
97
+ "glm-5": chatCompletionsStream,
98
+ "deepseek-v4.1-flash": chatCompletionsStream,
99
+ "deepseek-v4-pro": chatCompletionsStream,
100
+ "deepseek-v4-flash": chatCompletionsStream,
101
+ "deepseek-v4-flash-vision-exp": chatCompletionsStream,
102
+ "deepseek-flash": chatCompletionsStream,
103
+ "longcat-2.0": chatCompletionsStream,
104
+ "longcat-2.5-preview-free": chatCompletionsStream,
105
+ "step-5-preview-free": chatCompletionsStream,
106
+ "mimo-v2.6-flash": chatCompletionsStream,
107
+ "mimo-v2.6-pro": chatCompletionsStream,
108
+ "mimo-v2.5": chatCompletionsStream,
109
+ "mimo-v2.5-pro": chatCompletionsStream,
110
+ "mimo-v2-pro": chatCompletionsStream,
111
+ "mimo-v2-omni": chatCompletionsStream,
112
+ "minimax-m2.5": chatCompletionsStream,
113
+ "qwen3.7-max": chatCompletionsStream,
114
+ "qwen3.6-plus": chatCompletionsStream,
115
+ "qwen3.5-plus": chatCompletionsStream,
116
+ "hy4-preview": chatCompletionsStream,
117
+ hy3: chatCompletionsStream,
118
+ "hy3-preview": chatCompletionsStream,
119
+ "omen-alpha": chatCompletionsStream,
120
+ "space-bunny": chatCompletionsStream,
121
+ "grok-4.7": responsesStream,
122
+ "grok-4.6": responsesStream,
123
+ "grok-4.5": responsesStream,
124
+ "gpt-6-luna": responsesStream,
125
+ "gpt-5.6-luna": responsesStream,
126
+ "muse-spark-1.3-contributor": responsesStream,
127
+ "muse-spark-1.2-contributor": responsesStream,
128
+ "claude-haiku-5-5": messagesStream,
129
+ "minimax-m3": messagesStream,
130
+ "minimax-m2.7": messagesStream,
131
+ "qwen3.8-max": messagesStream,
132
+ "qwen3.8-flash": messagesStream,
133
+ "qwen3.7-plus": messagesStream
134
+ }
135
+ };
136
+ } });
137
+ //#endregion
138
+ export { opencode_go_default as default };
@@ -1,8 +1,8 @@
1
1
  import { defineProvider } from "../index.js";
2
2
  import { messagesGenerateProtocol, messagesStreamProtocol } from "../protocols/anthropic-messages.js";
3
3
  import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
4
- import { geminiGenerateProtocol, geminiStreamProtocol } from "../protocols/google-models.js";
5
4
  import { responsesGenerateProtocol, responsesStreamProtocol } from "../protocols/openai-responses.js";
5
+ import { geminiGenerateProtocol, geminiStreamProtocol } from "../protocols/google-models.js";
6
6
  import { useVariables } from "revojs";
7
7
  //#region src/providers/opencode.ts
8
8
  var opencode_default = defineProvider({ setup: (scope) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/ai",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,7 @@
29
29
  "watch": "vite build --watch"
30
30
  },
31
31
  "dependencies": {
32
+ "@modelcontextprotocol/sdk": "^1.32.1",
32
33
  "revojs": "*"
33
34
  },
34
35
  "devDependencies": {