ai-world-sdk 1.3.0 → 1.3.2
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/dist/__tests__/example.test.js +27 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/dist/llm.js +5 -0
- package/dist/openai_video_generation.d.ts +5 -4
- package/dist/provider_config.d.ts +1 -1
- package/dist/provider_config.js +2 -0
- package/package.json +2 -1
- package/skills/ai-world-sdk/SKILL.md +1 -1
- package/skills/ai-world-sdk/docs/provider-and-models.md +10 -5
- package/skills/ai-world-sdk/docs/vscode-login.md +1 -1
|
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
40
40
|
const dotenv = __importStar(require("dotenv"));
|
|
41
41
|
const index_1 = require("../index");
|
|
42
42
|
const fs_1 = require("fs");
|
|
43
|
+
const ai_1 = require("ai");
|
|
43
44
|
// Load environment variables from .env file
|
|
44
45
|
dotenv.config();
|
|
45
46
|
index_1.sdkConfig.setBaseUrl("http://localhost:8000");
|
|
@@ -1187,6 +1188,32 @@ describe("Langchain SDK Tests", () => {
|
|
|
1187
1188
|
console.log("响应内容:", content);
|
|
1188
1189
|
}
|
|
1189
1190
|
}, 30000);
|
|
1191
|
+
// ========== OpenRouter 测试 ==========
|
|
1192
|
+
test("ChatOpenAI - OpenRouter 基础测试", async () => {
|
|
1193
|
+
const provider = (0, index_1.createProvider)("openrouter", "openai", "test");
|
|
1194
|
+
const result = await (0, ai_1.generateText)({
|
|
1195
|
+
model: provider.languageModel('openai/gpt-4o-mini'),
|
|
1196
|
+
prompt: '你好',
|
|
1197
|
+
});
|
|
1198
|
+
console.log("result:", result);
|
|
1199
|
+
}, 30000);
|
|
1200
|
+
test("ChatOpenAI - OpenRouter 流式调用", async () => {
|
|
1201
|
+
const provider = (0, index_1.createProvider)("openrouter", "openai", "test");
|
|
1202
|
+
const stream = (0, ai_1.streamText)({
|
|
1203
|
+
model: provider.languageModel('openai/gpt-4o-mini'),
|
|
1204
|
+
prompt: '你好',
|
|
1205
|
+
});
|
|
1206
|
+
let fullText = "";
|
|
1207
|
+
for await (const part of stream.fullStream) {
|
|
1208
|
+
switch (part.type) {
|
|
1209
|
+
case 'text-delta':
|
|
1210
|
+
fullText += part.text;
|
|
1211
|
+
break;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
expect(fullText.length).toBeGreaterThan(0);
|
|
1215
|
+
console.log("fullText:", fullText);
|
|
1216
|
+
}, 30000);
|
|
1190
1217
|
// ========== OpenAI 视频生成测试 ==========
|
|
1191
1218
|
test("OpenAIVideoGenerationClient - 创建视频生成任务(文本)", async () => {
|
|
1192
1219
|
const openaiVideoClient = new index_1.OpenAIVideoGenerationClient({});
|
package/dist/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
11
11
|
*/
|
|
12
|
-
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.
|
|
12
|
+
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.2";
|
|
13
13
|
/**
|
|
14
14
|
* 版本兼容性错误
|
|
15
15
|
*/
|
|
@@ -34,8 +34,8 @@ declare class SDKConfig {
|
|
|
34
34
|
private _authenticated;
|
|
35
35
|
private _authCheckPromise;
|
|
36
36
|
private _currentUser;
|
|
37
|
-
readonly sdkSignature = "AI_WORLD_SDK_V:1.3.
|
|
38
|
-
readonly sdkVersion = "1.3.
|
|
37
|
+
readonly sdkSignature = "AI_WORLD_SDK_V:1.3.2";
|
|
38
|
+
readonly sdkVersion = "1.3.2";
|
|
39
39
|
constructor();
|
|
40
40
|
/**
|
|
41
41
|
* Set global base URL
|
package/dist/config.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.sdkConfig = exports.VersionCompatibilityError = exports.SDK_SIGNATURE = void 0;
|
|
8
8
|
// SDK 版本号(构建时自动从 package.json 更新)
|
|
9
9
|
// 此版本号会在运行 npm run build 时自动从 package.json 读取并更新
|
|
10
|
-
const SDK_VERSION = "1.3.
|
|
10
|
+
const SDK_VERSION = "1.3.2";
|
|
11
11
|
/**
|
|
12
12
|
* SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
|
|
13
13
|
* 格式: AI_WORLD_SDK_V:版本号
|
|
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.3.0";
|
|
|
15
15
|
*
|
|
16
16
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
17
17
|
*/
|
|
18
|
-
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.
|
|
18
|
+
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.2";
|
|
19
19
|
/**
|
|
20
20
|
* 版本兼容性错误
|
|
21
21
|
*/
|
package/dist/llm.js
CHANGED
|
@@ -7,6 +7,7 @@ const google_1 = require("@ai-sdk/google");
|
|
|
7
7
|
const openai_1 = require("@ai-sdk/openai");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const ai_1 = require("ai");
|
|
10
|
+
const ai_sdk_provider_1 = require("@openrouter/ai-sdk-provider");
|
|
10
11
|
/**
|
|
11
12
|
* 根据端点类型创建 ai-sdk ProviderV3
|
|
12
13
|
* 所有请求会通过后端代理(/api/llm/{endpointType})转发到实际 API
|
|
@@ -27,6 +28,10 @@ function createProvider(provider, endpointType, pluginId) {
|
|
|
27
28
|
Authorization: `Bearer ${config_1.sdkConfig.getToken()}`,
|
|
28
29
|
},
|
|
29
30
|
};
|
|
31
|
+
if (provider === "openrouter") {
|
|
32
|
+
settings.baseURL = `${serverUrl}/api/llm/openrouter`;
|
|
33
|
+
return (0, ai_sdk_provider_1.createOpenRouter)(settings);
|
|
34
|
+
}
|
|
30
35
|
switch (endpointType) {
|
|
31
36
|
case "openai":
|
|
32
37
|
return (0, openai_1.createOpenAI)(settings);
|
|
@@ -7,10 +7,11 @@ export interface OpenAIVideoGenerationConfig {
|
|
|
7
7
|
token?: string;
|
|
8
8
|
headers?: Record<string, string>;
|
|
9
9
|
}
|
|
10
|
+
export type OpenAIVideoGenerationProvider = "shubiaobiao" | "api2img" | "aiping";
|
|
10
11
|
export interface OpenAIVideoGenerationRequest {
|
|
11
12
|
prompt: string;
|
|
12
13
|
model?: string;
|
|
13
|
-
provider?:
|
|
14
|
+
provider?: OpenAIVideoGenerationProvider;
|
|
14
15
|
seconds?: "4" | "8" | "12";
|
|
15
16
|
size?: "720x1280" | "1280x720" | "1024x1792" | "1792x1024";
|
|
16
17
|
input_reference?: string;
|
|
@@ -107,7 +108,7 @@ export declare class OpenAIVideoGenerationClient {
|
|
|
107
108
|
* }
|
|
108
109
|
* ```
|
|
109
110
|
*/
|
|
110
|
-
getTask(taskId: string, provider:
|
|
111
|
+
getTask(taskId: string, provider: OpenAIVideoGenerationProvider): Promise<OpenAIVideoTaskResponse>;
|
|
111
112
|
/**
|
|
112
113
|
* 轮询等待任务完成
|
|
113
114
|
* Poll and wait for task completion
|
|
@@ -125,7 +126,7 @@ export declare class OpenAIVideoGenerationClient {
|
|
|
125
126
|
* console.log('Video URL:', result.url);
|
|
126
127
|
* ```
|
|
127
128
|
*/
|
|
128
|
-
waitForCompletion(taskId: string, provider?:
|
|
129
|
+
waitForCompletion(taskId: string, provider?: OpenAIVideoGenerationProvider, options?: {
|
|
129
130
|
maxAttempts?: number;
|
|
130
131
|
interval?: number;
|
|
131
132
|
onProgress?: (status: OpenAIVideoTaskResponse) => void;
|
|
@@ -184,5 +185,5 @@ export declare class OpenAIVideoGenerationClient {
|
|
|
184
185
|
* const thumbnail = await client.downloadVideo('vid_abc123', 'api2img', 'thumbnail');
|
|
185
186
|
* ```
|
|
186
187
|
*/
|
|
187
|
-
downloadVideo(taskId: string, provider?:
|
|
188
|
+
downloadVideo(taskId: string, provider?: OpenAIVideoGenerationProvider, variant?: "video" | "thumbnail"): Promise<Blob>;
|
|
188
189
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 模型提供商
|
|
3
3
|
*/
|
|
4
|
-
export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic";
|
|
4
|
+
export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic" | "aiping" | "openrouter";
|
|
5
5
|
/**
|
|
6
6
|
* 模型端点类型
|
|
7
7
|
* - openai: OpenAI 兼容 API(/v1/chat/completions 等)
|
package/dist/provider_config.js
CHANGED
|
@@ -5,10 +5,12 @@ exports.getProviderConfig = getProviderConfig;
|
|
|
5
5
|
exports.PROVIDER_CONFIGS = {
|
|
6
6
|
shubiaobiao: { provider: "shubiaobiao", modelType: "openai" },
|
|
7
7
|
api2img: { provider: "api2img", modelType: "openai" },
|
|
8
|
+
aiping: { provider: "aiping", modelType: "openai" },
|
|
8
9
|
aihubmix: { provider: "aihubmix", modelType: "openai" },
|
|
9
10
|
doubao: { provider: "doubao", modelType: "openai" },
|
|
10
11
|
gemini: { provider: "gemini", modelType: "gemini" },
|
|
11
12
|
anthropic: { provider: "anthropic", modelType: "anthropic" },
|
|
13
|
+
openrouter: { provider: "openrouter", modelType: "openai" },
|
|
12
14
|
};
|
|
13
15
|
function getProviderConfig(provider) {
|
|
14
16
|
return exports.PROVIDER_CONFIGS[provider];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-world-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "TypeScript SDK for AI World Platform - Chat Models, Image Generation, and Video Generation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"@ai-sdk/anthropic": "^3.0.43",
|
|
79
79
|
"@ai-sdk/google": "^3.0.29",
|
|
80
80
|
"@ai-sdk/openai": "^3.0.28",
|
|
81
|
+
"@openrouter/ai-sdk-provider": "^2.3.1",
|
|
81
82
|
"ai": "^6.0.85"
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -126,7 +126,7 @@ sdkConfig.setPluginId('my-plugin');
|
|
|
126
126
|
### Provider 与模型 → `docs/provider-and-models.md`
|
|
127
127
|
|
|
128
128
|
- `createProvider(provider, endpointType, pluginId)` 创建 Vercel AI SDK Provider
|
|
129
|
-
- Provider 对照表:`api2img`(推荐) / `gemini` / `aihubmix` / `shubiaobiao`
|
|
129
|
+
- Provider 对照表:`api2img`(推荐) / `gemini` / `aihubmix` / `shubiaobiao` / `aiping`
|
|
130
130
|
- 常用模型列表和 AI SDK 函数速查
|
|
131
131
|
|
|
132
132
|
### 文本生成 → `docs/text-generation.md`
|
|
@@ -10,17 +10,22 @@
|
|
|
10
10
|
| `shubiaobiao` | `openai` | 数标标 |
|
|
11
11
|
| `shubiaobiao` | `gemini` | 数标标 Gemini |
|
|
12
12
|
| `shubiaobiao` | `anthropic` | 数标标 Claude |
|
|
13
|
+
| `aiping` | `openai` | 平音 |
|
|
14
|
+
| `aiping` | `gemini` | 平音 Gemini |
|
|
15
|
+
| `aiping` | `anthropic` | 平音 Claude |
|
|
13
16
|
| `gemini` | `gemini` | Google 原生,仅限 Gemini 系列模型 |
|
|
17
|
+
| `openrouter` | `openrouter` | OpenRouter 兼容,模型兼容 OpenRouter 格式,可包括 GPT、以及经聚合的 Gemini/Claude 等(视 provider 能力),模型ID必须以gateway方式设置,如openai/gpt-4o-mini |
|
|
14
18
|
|
|
15
19
|
## EndpointType 与模型对应关系
|
|
16
20
|
|
|
17
21
|
| EndpointType | 适用模型 | 说明 |
|
|
18
22
|
|--------------|----------|------|
|
|
19
23
|
| `gemini` | Google Gemini | 必须使用 Google 的 Gemini 模型(如 `gemini-2.5-flash`、`gemini-2.5-pro`) |
|
|
20
|
-
| `anthropic` | Claude | 必须使用 Anthropic 的 Claude 模型(如 `claude-sonnet-4-5`、`claude-3-5-sonnet`);**仅 api2img、shubiaobiao 支持此 endpoint** |
|
|
24
|
+
| `anthropic` | Claude | 必须使用 Anthropic 的 Claude 模型(如 `claude-sonnet-4-5`、`claude-3-5-sonnet`);**仅 api2img、shubiaobiao、aiping 支持此 endpoint** |
|
|
21
25
|
| `openai` | OpenAI 兼容 | 模型兼容 OpenAI 格式,可包括 GPT、以及经聚合的 Gemini/Claude 等(视 provider 能力) |
|
|
26
|
+
| `openrouter` | OpenRouter 兼容 | OpenRouter 兼容,模型兼容 OpenRouter 格式,可包括 GPT、以及经聚合的 Gemini/Claude 等(视 provider 能力),模型ID必须以gateway方式设置,如openai/gpt-4o-mini |
|
|
22
27
|
|
|
23
|
-
规则:**anthropic 不是 provider**,仅 **api2img**、**shubiaobiao** 支持 EndpointType 为 `anthropic`(调用 Claude);`gemini` provider 用 `gemini` endpoint,其余按上表组合。
|
|
28
|
+
规则:**anthropic 不是 provider**,仅 **api2img**、**shubiaobiao**、**aiping** 支持 EndpointType 为 `anthropic`(调用 Claude);`gemini` provider 用 `gemini` endpoint,其余按上表组合。
|
|
24
29
|
|
|
25
30
|
> `doubao` 不通过 `createProvider` 使用,豆包有专用客户端(见 image-generation.md / video-generation.md)。
|
|
26
31
|
|
|
@@ -40,7 +45,7 @@ const model = provider.languageModel('gpt-4o-mini');
|
|
|
40
45
|
// Google Gemini(EndpointType = gemini,仅 Google 模型)
|
|
41
46
|
createProvider('gemini', 'gemini', 'my-plugin').languageModel('gemini-2.5-flash');
|
|
42
47
|
|
|
43
|
-
// Anthropic Claude(仅 api2img / shubiaobiao 支持 endpointType = anthropic,仅 Claude 模型)
|
|
48
|
+
// Anthropic Claude(仅 api2img / shubiaobiao / aiping 支持 endpointType = anthropic,仅 Claude 模型)
|
|
44
49
|
createProvider('api2img', 'anthropic', 'my-plugin').languageModel('claude-sonnet-4-5');
|
|
45
50
|
|
|
46
51
|
// OpenAI 兼容(EndpointType = openai,模型兼容 OpenAI 格式;api2img 可聚合多模型)
|
|
@@ -63,8 +68,8 @@ const ok = await checkModel('api2img', 'openai', 'gpt-4o-mini', 'my-plugin');
|
|
|
63
68
|
|------|------|----------|-------------|
|
|
64
69
|
| `gpt-4o-mini` / `gpt-4o` / `gpt-5.1` | 文本 | `api2img` | `openai`(OpenAI 兼容) |
|
|
65
70
|
| `gemini-2.5-flash` / `gemini-2.5-pro` | 文本 | `gemini` | `gemini`(仅 Google) |
|
|
66
|
-
| `claude-sonnet-4-
|
|
67
|
-
| `dall-e-3` / `gpt-image-1` | 图像 | `api2img` | `openai` |
|
|
71
|
+
| `claude-sonnet-4-6` / `claude-opus-4-6` | 文本 | `api2img`、`shubiaobiao` 或 `aiping` | `anthropic`(仅 Claude) |
|
|
72
|
+
| `dall-e-3` / `gpt-image-1` | 图像 | `api2img`、`shubiaobiao` 或 `aiping` | `openai` |
|
|
68
73
|
| `doubao-seedream-4-5-251128` | 图像 | — | 专用客户端 |
|
|
69
74
|
|
|
70
75
|
## AI SDK 函数速查
|