ai-world-sdk 1.5.12 → 1.5.13

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.
@@ -72,7 +72,7 @@ function registerConfigCommands(program) {
72
72
  merged[key] = {
73
73
  value: val,
74
74
  source: key === 'token'
75
- ? (saved.token ? 'config' : (process.env.DEBUG_TOKEN ? 'env' : 'none'))
75
+ ? (saved.token ? 'config' : (process.env.AI_WORLD_TOKEN || process.env.DEBUG_TOKEN ? 'env' : 'none'))
76
76
  : (hasSaved ? 'config' : (val !== null ? 'default' : 'none')),
77
77
  };
78
78
  }
@@ -95,7 +95,7 @@ function getEffectiveConfig() {
95
95
  const result = {};
96
96
  for (const key of VALID_KEYS) {
97
97
  if (key === 'token') {
98
- result[key] = config.token || process.env.DEBUG_TOKEN || null;
98
+ result[key] = config.token || process.env.AI_WORLD_TOKEN || process.env.DEBUG_TOKEN || null;
99
99
  }
100
100
  else {
101
101
  result[key] = config[key] || DEFAULTS[key] || null;
@@ -109,7 +109,7 @@ function getConfigValue(key) {
109
109
  function getEffectiveValue(key) {
110
110
  const config = readConfig();
111
111
  if (key === 'token') {
112
- return config.token || process.env.DEBUG_TOKEN || null;
112
+ return config.token || process.env.AI_WORLD_TOKEN || process.env.DEBUG_TOKEN || null;
113
113
  }
114
114
  return config[key] || DEFAULTS[key] || null;
115
115
  }
@@ -144,6 +144,7 @@ function resolveAuth(opts) {
144
144
  config['base-url'] ||
145
145
  'https://aiworld.local:8000',
146
146
  token: opts.token ||
147
+ process.env.AI_WORLD_TOKEN ||
147
148
  process.env.DEBUG_TOKEN ||
148
149
  config.token ||
149
150
  null,
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.5.12";
12
+ export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.13";
13
13
  /**
14
14
  * 版本兼容性错误
15
15
  */
@@ -35,8 +35,8 @@ declare class SDKConfig {
35
35
  private _authCheckPromise;
36
36
  private _currentUser;
37
37
  private _cliMode;
38
- readonly sdkSignature = "AI_WORLD_SDK_V:1.5.12";
39
- readonly sdkVersion = "1.5.12";
38
+ readonly sdkSignature = "AI_WORLD_SDK_V:1.5.13";
39
+ readonly sdkVersion = "1.5.13";
40
40
  constructor();
41
41
  /**
42
42
  * 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.5.12";
10
+ const SDK_VERSION = "1.5.13";
11
11
  /**
12
12
  * SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
13
13
  * 格式: AI_WORLD_SDK_V:版本号
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.5.12";
15
15
  *
16
16
  * 注意: {VERSION} 占位符会在构建时被替换为实际版本号
17
17
  */
18
- exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.12";
18
+ exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.13";
19
19
  /**
20
20
  * 版本兼容性错误
21
21
  */
@@ -97,9 +97,15 @@ class SDKConfig {
97
97
  else {
98
98
  // 非浏览器环境(Node.js / Vite dev):从 process.env 读取
99
99
  try {
100
- const debugToken = typeof process !== 'undefined' && process.env?.DEBUG_TOKEN;
101
- if (debugToken) {
102
- this._token = debugToken;
100
+ const token = typeof process !== 'undefined' && process.env?.AI_WORLD_TOKEN;
101
+ if (token) {
102
+ this._token = token;
103
+ }
104
+ else {
105
+ const debugToken = typeof process !== 'undefined' && process.env?.DEBUG_TOKEN;
106
+ if (debugToken) {
107
+ this._token = debugToken;
108
+ }
103
109
  }
104
110
  const debugFlag = typeof process !== 'undefined' && process.env?.DEBUG;
105
111
  if (debugFlag === 'true') {
package/dist/llm.js CHANGED
@@ -7,7 +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
+ const dist_1 = require("../pacakges/ai-sdk-provider/dist");
11
11
  /**
12
12
  * 根据端点类型创建 ai-sdk ProviderV3
13
13
  * 所有请求会通过后端代理(/api/llm/{endpointType})转发到实际 API
@@ -30,11 +30,11 @@ function createProvider(provider, endpointType, pluginId) {
30
30
  };
31
31
  if (provider === "openrouter") {
32
32
  settings.baseURL = `${serverUrl}/api/llm/openrouter`;
33
- return (0, ai_sdk_provider_1.createOpenRouter)(settings);
33
+ return (0, dist_1.createOpenRouter)(settings);
34
34
  }
35
35
  else if (provider === "kunpo") {
36
36
  settings.baseURL = `${serverUrl}/api/llm/kunpo`;
37
- return (0, ai_sdk_provider_1.createOpenRouter)(settings);
37
+ return (0, dist_1.createOpenRouter)(settings);
38
38
  }
39
39
  switch (endpointType) {
40
40
  case "openai":
@@ -26,6 +26,8 @@ function aiWorldPlugin(options = {}) {
26
26
  const config = { baseUrl };
27
27
  if (env["DEBUG_TOKEN"])
28
28
  config.token = env["DEBUG_TOKEN"];
29
+ if (env["AI_WORLD_TOKEN"])
30
+ config.token = env["AI_WORLD_TOKEN"];
29
31
  if (env["PLUGIN_ID"])
30
32
  config.pluginId = env["PLUGIN_ID"];
31
33
  if (env["DEBUG"] === "true")
@@ -43,7 +45,7 @@ function aiWorldPlugin(options = {}) {
43
45
  if (hasLoggedIn)
44
46
  return;
45
47
  const env = (0, login_1.readEnvLocal)(projectRoot);
46
- const existingToken = env["DEBUG_TOKEN"] || process.env.DEBUG_TOKEN;
48
+ const existingToken = env["DEBUG_TOKEN"] || process.env.DEBUG_TOKEN || env["AI_WORLD_TOKEN"] || process.env.AI_WORLD_TOKEN;
47
49
  // 确保 PLUGIN_ID 存在,不存在则从 plugin.json 或目录名推断
48
50
  if (!env["PLUGIN_ID"] && !process.env.PLUGIN_ID) {
49
51
  const pluginId = (0, login_1.resolvePluginId)(projectRoot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
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",
@@ -123,6 +123,7 @@ sdkConfig.setPluginId('my-plugin');
123
123
  - `AI_WORLD_BASE_URL` — 服务端地址,插件 JS 后端启动时由平台自动注入
124
124
  - `PLUGIN_ID` — 插件 ID
125
125
  - `DEBUG_TOKEN` — 调试用 JWT Token
126
+ - `AI_WORLD_TOKEN` — 用户登录后获取的 JWT Token
126
127
 
127
128
  ## 功能模块
128
129
 
@@ -5,12 +5,15 @@
5
5
  ## 安装
6
6
 
7
7
  ```bash
8
- # 全局安装
8
+ # 全局安装(CLI 工具)
9
9
  npm install -g ai-world-sdk
10
10
 
11
11
  # 或临时使用(无需安装)
12
12
  npx ai-world-sdk <command>
13
13
  npx ai-world <command>
14
+
15
+ # 项目中作为依赖安装(用于打包/开发)
16
+ npm install ai-world-sdk ai
14
17
  ```
15
18
 
16
19
  ## 认证
@@ -33,14 +36,14 @@ ai-world login --token <your-jwt-token>
33
36
 
34
37
  ```bash
35
38
  export AI_WORLD_BASE_URL=https://aiworld.local:8000
36
- export DEBUG_TOKEN=your-jwt-token
39
+ export AI_WORLD_TOKEN=your-jwt-token
37
40
  export PLUGIN_ID=my-plugin
38
41
  ```
39
42
 
40
43
  ### 认证优先级(从高到低)
41
44
 
42
45
  1. 命令行参数:`--token`、`--base-url`、`--plugin-id`
43
- 2. 环境变量:`DEBUG_TOKEN`、`AI_WORLD_BASE_URL`、`PLUGIN_ID`
46
+ 2. 环境变量:`AI_WORLD_TOKEN`、`AI_WORLD_BASE_URL`、`PLUGIN_ID`
44
47
  3. 本地配置文件:`~/.ai-world/config.json`
45
48
  4. 默认值:base-url=`https://aiworld.local:8000`,plugin-id=`cli`,provider=`kunpo`,endpoint=`openai`,model=`deepseek/deepseek-v4-pro`
46
49
 
@@ -114,7 +117,7 @@ $ ai-world plugin list --format table
114
117
  "code": "AUTH_REQUIRED",
115
118
  "message": "未认证",
116
119
  "details": {
117
- "checked_sources": ["--token flag", "DEBUG_TOKEN env", "~/.ai-world/config.json"],
120
+ "checked_sources": ["--token flag", "AI_WORLD_TOKEN env", "~/.ai-world/config.json"],
118
121
  "suggestion": "运行 `ai-world auth login`"
119
122
  },
120
123
  "command": "ai-world resource list",