@opencode/ai 0.0.0-dev-19364 → 0.0.0-dev-19366

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.
@@ -0,0 +1,86 @@
1
+ import { AlibabaChat } from "../protocols/alibaba-chat.js";
2
+ import { AlibabaMessages } from "../protocols/alibaba-messages.js";
3
+ import { AlibabaResponses } from "../protocols/alibaba-responses.js";
4
+ import { AuthOptions } from "../route/auth-options.js";
5
+ import { Route } from "../route/client.js";
6
+ import { Endpoint } from "../route/endpoint.js";
7
+ import { Framing } from "../route/framing.js";
8
+ import { ProviderID, ToolDefinition } from "../schema/index.js";
9
+ export const id = ProviderID.make("alibaba");
10
+ const hosts = new Map([
11
+ ["ap-southeast-1", "dashscope-intl.aliyuncs.com"],
12
+ ["cn-beijing", "dashscope.aliyuncs.com"],
13
+ ["cn-hongkong", "cn-hongkong.dashscope.aliyuncs.com"],
14
+ ["us-east-1", "dashscope-us.aliyuncs.com"],
15
+ ]);
16
+ const chatRoute = Route.make({
17
+ id: "alibaba-chat",
18
+ provider: id,
19
+ providerMetadataKey: "alibaba",
20
+ protocol: AlibabaChat.protocol,
21
+ endpoint: Endpoint.path("/chat/completions"),
22
+ framing: Framing.sse,
23
+ });
24
+ const messagesRoute = Route.make({
25
+ id: "alibaba-messages",
26
+ provider: id,
27
+ providerMetadataKey: "alibaba",
28
+ protocol: AlibabaMessages.protocol,
29
+ endpoint: Endpoint.path("/messages"),
30
+ framing: Framing.sse,
31
+ headers: () => ({ "anthropic-version": "2023-06-01" }),
32
+ });
33
+ const responsesRoute = Route.make({
34
+ id: "alibaba-responses",
35
+ provider: id,
36
+ providerMetadataKey: "alibaba",
37
+ protocol: AlibabaResponses.protocol,
38
+ endpoint: Endpoint.path("/responses"),
39
+ framing: Framing.sse,
40
+ });
41
+ export const routes = [chatRoute, messagesRoute, responsesRoute];
42
+ export const configure = (input) => {
43
+ const { apiKey: _key, auth: _auth, region, workspaceID, baseURL, ...rest } = input;
44
+ const host = region === undefined
45
+ ? undefined
46
+ : workspaceID === undefined
47
+ ? hosts.get(region)
48
+ : `${workspaceID}.${region}.maas.aliyuncs.com`;
49
+ if (baseURL === undefined) {
50
+ if (region === undefined)
51
+ throw new Error("Alibaba requires region or baseURL");
52
+ if (host === undefined)
53
+ throw new Error(`Alibaba region ${region} requires workspaceID or baseURL`);
54
+ }
55
+ const opts = { ...rest, auth: AuthOptions.bearer(input, ["DASHSCOPE_API_KEY", "ALIBABA_API_KEY"]) };
56
+ const common = { ...opts, endpoint: { baseURL: baseURL ?? `https://${host}/compatible-mode/v1` } };
57
+ const chat = (id) => chatRoute.with(common).model({ id, compatibility: AlibabaChat.compatibility });
58
+ const messages = (id) => messagesRoute
59
+ .with({
60
+ ...opts,
61
+ endpoint: { baseURL: baseURL ?? `https://${host}/apps/anthropic/v1` },
62
+ })
63
+ .model({ id, compatibility: { requireSignature: false } });
64
+ const responses = (id) => responsesRoute.with(common).model({ id });
65
+ return { id, model: chat, chat, messages, responses, configure };
66
+ };
67
+ export const provider = { id, configure };
68
+ export const model = (id, input) => fromSettings(input).chat(id);
69
+ export const messagesModel = (id, input) => fromSettings(input).messages(id);
70
+ export const responsesModel = (id, input) => fromSettings(input).responses(id);
71
+ function fromSettings(input) {
72
+ const { body, ...rest } = input;
73
+ return configure({ ...rest, http: body === undefined ? undefined : { body } });
74
+ }
75
+ export const webSearch = () => hostedTool("web_search", "Search the web with Alibaba's hosted search tool.");
76
+ export const webExtractor = () => hostedTool("web_extractor", "Extract web page content with Alibaba's hosted tool.");
77
+ export const codeInterpreter = () => hostedTool("code_interpreter", "Execute code with Alibaba's hosted interpreter.");
78
+ function hostedTool(type, description) {
79
+ return ToolDefinition.make({
80
+ name: type,
81
+ description,
82
+ inputSchema: { type: "object", properties: {} },
83
+ native: { alibaba: { type } },
84
+ });
85
+ }
86
+ export * as Alibaba from "./alibaba.js";
@@ -1,3 +1,4 @@
1
+ export * as Alibaba from "./alibaba.js";
1
2
  export * as Anthropic from "./anthropic.js";
2
3
  export * as AnthropicCompatible from "./anthropic-compatible.js";
3
4
  export * as AmazonBedrock from "./amazon-bedrock.js";
@@ -1,3 +1,4 @@
1
+ export * as Alibaba from "./alibaba.js";
1
2
  export * as Anthropic from "./anthropic.js";
2
3
  export * as AnthropicCompatible from "./anthropic-compatible.js";
3
4
  export * as AmazonBedrock from "./amazon-bedrock.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-19364",
3
+ "version": "0.0.0-dev-19366",
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-19364",
33
+ "@opencode/http-recorder": "0.0.0-dev-19366",
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-19364",
43
+ "@opencode/schema": "0.0.0-dev-19366",
44
44
  "aws4fetch": "1.0.20",
45
45
  "effect": "4.0.0-rc.112",
46
46
  "google-auth-library": "10.5.0"