ai-world-sdk 1.5.6 → 1.5.7

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.
@@ -185,10 +185,16 @@ function registerPluginCommands(program) {
185
185
  });
186
186
  plugin
187
187
  .command('create')
188
- .argument('<zip-file>')
189
- .requiredOption('--plugin-id <id>')
190
- .option('--name <name>')
191
- .option('--description <text>')
188
+ .argument('[zip-file]', '静态文件 zip 包路径(可选)')
189
+ .requiredOption('--plugin-id <id>', '插件 ID')
190
+ .option('--name <name>', '插件名称')
191
+ .option('--description <text>', '插件描述')
192
+ .option('--author <author>', '插件作者')
193
+ .option('--version <ver>', '插件版本')
194
+ .option('--server-zip <path>', 'JS 后端 zip 包路径')
195
+ .option('--backend-entry <entry>', 'JS 后端入口文件(默认 index.js)')
196
+ .option('--backend-websocket', '启用 WebSocket 代理')
197
+ .option('--disable-sdk-update-notice', '禁用 SDK 更新提示')
192
198
  .action(async (zipFile, options, cmd) => {
193
199
  const commandName = 'plugin create';
194
200
  try {
@@ -200,12 +206,58 @@ function registerPluginCommands(program) {
200
206
  });
201
207
  (0, utils_1.initSDK)(auth);
202
208
  const client = new plugin_management_1.PluginManagementClient();
203
- const staticZip = (0, utils_1.readFileAsFile)(zipFile);
204
209
  const res = await client.create({
205
210
  pluginId: options.pluginId,
206
211
  name: options.name,
207
212
  description: options.description,
208
- staticZip,
213
+ author: options.author,
214
+ version: options.version,
215
+ staticZip: zipFile ? (0, utils_1.readFileAsFile)(zipFile) : undefined,
216
+ serverZip: options.serverZip ? (0, utils_1.readFileAsFile)(options.serverZip) : undefined,
217
+ backendEntry: options.backendEntry,
218
+ backendWebsocket: options.backendWebsocket === true ? true : undefined,
219
+ disableSdkUpdateNotice: options.disableSdkUpdateNotice === true ? true : undefined,
220
+ });
221
+ (0, output_1.output)(res, (0, utils_1.getFormat)(program));
222
+ }
223
+ catch (err) {
224
+ (0, utils_1.handleError)(err, commandName);
225
+ }
226
+ });
227
+ plugin
228
+ .command('update')
229
+ .argument('[zip-file]', '静态文件 zip 包路径(可选)')
230
+ .requiredOption('--plugin-id <id>', '要更新的插件 ID')
231
+ .option('--name <name>', '插件名称')
232
+ .option('--description <text>', '插件描述')
233
+ .option('--author <author>', '插件作者')
234
+ .option('--version <ver>', '插件版本')
235
+ .option('--server-zip <path>', 'JS 后端 zip 包路径')
236
+ .option('--backend-entry <entry>', 'JS 后端入口文件(默认 index.js)')
237
+ .option('--backend-websocket', '启用 WebSocket 代理')
238
+ .option('--disable-sdk-update-notice', '禁用 SDK 更新提示')
239
+ .action(async (zipFile, options, cmd) => {
240
+ const commandName = 'plugin update';
241
+ try {
242
+ const o = collectOpts(cmd);
243
+ const auth = (0, config_1.resolveAuth)({
244
+ baseUrl: o.baseUrl,
245
+ token: o.token,
246
+ pluginId: o.pluginId,
247
+ });
248
+ (0, utils_1.initSDK)(auth);
249
+ const client = new plugin_management_1.PluginManagementClient();
250
+ const res = await client.update({
251
+ pluginId: options.pluginId,
252
+ name: options.name,
253
+ description: options.description,
254
+ author: options.author,
255
+ version: options.version,
256
+ staticZip: zipFile ? (0, utils_1.readFileAsFile)(zipFile) : undefined,
257
+ serverZip: options.serverZip ? (0, utils_1.readFileAsFile)(options.serverZip) : undefined,
258
+ backendEntry: options.backendEntry,
259
+ backendWebsocket: options.backendWebsocket === true ? true : undefined,
260
+ disableSdkUpdateNotice: options.disableSdkUpdateNotice === true ? true : undefined,
209
261
  });
210
262
  (0, output_1.output)(res, (0, utils_1.getFormat)(program));
211
263
  }
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.6";
12
+ export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.7";
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.6";
39
- readonly sdkVersion = "1.5.6";
38
+ readonly sdkSignature = "AI_WORLD_SDK_V:1.5.7";
39
+ readonly sdkVersion = "1.5.7";
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.6";
10
+ const SDK_VERSION = "1.5.7";
11
11
  /**
12
12
  * SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
13
13
  * 格式: AI_WORLD_SDK_V:版本号
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.5.6";
15
15
  *
16
16
  * 注意: {VERSION} 占位符会在构建时被替换为实际版本号
17
17
  */
18
- exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.6";
18
+ exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.7";
19
19
  /**
20
20
  * 版本兼容性错误
21
21
  */
@@ -49,6 +49,18 @@ export interface CreatePluginData {
49
49
  backendWebsocket?: boolean;
50
50
  disableSdkUpdateNotice?: boolean;
51
51
  }
52
+ export interface UpdatePluginData {
53
+ pluginId: string;
54
+ name?: string;
55
+ description?: string;
56
+ author?: string;
57
+ version?: string;
58
+ staticZip?: File | Blob;
59
+ serverZip?: File | Blob;
60
+ backendEntry?: string;
61
+ backendWebsocket?: boolean;
62
+ disableSdkUpdateNotice?: boolean;
63
+ }
52
64
  export interface PluginStatus {
53
65
  plugin_id: string;
54
66
  enabled: boolean;
@@ -110,6 +122,7 @@ export declare class PluginManagementClient {
110
122
  get(pluginId: string): Promise<PluginInfo>;
111
123
  getStatus(pluginId: string): Promise<PluginStatus>;
112
124
  create(data: CreatePluginData): Promise<PluginInfo>;
125
+ update(data: UpdatePluginData): Promise<PluginInfo>;
113
126
  delete(pluginId: string): Promise<{
114
127
  message: string;
115
128
  }>;
@@ -136,6 +136,41 @@ class PluginManagementClient {
136
136
  await this.handleErrorResponse(response);
137
137
  return (await response.json());
138
138
  }
139
+ async update(data) {
140
+ config_1.sdkConfig.ensureVersionCompatible();
141
+ const url = `${this.baseUrl}/api/plugins/update`;
142
+ const formData = new FormData();
143
+ formData.append("plugin_id", data.pluginId);
144
+ if (data.name)
145
+ formData.append("name", data.name);
146
+ if (data.description)
147
+ formData.append("description", data.description);
148
+ if (data.author)
149
+ formData.append("author", data.author);
150
+ if (data.version)
151
+ formData.append("version", data.version);
152
+ if (data.staticZip)
153
+ formData.append("static_zip", data.staticZip);
154
+ if (data.serverZip)
155
+ formData.append("server_zip", data.serverZip);
156
+ if (data.backendEntry)
157
+ formData.append("backend_entry", data.backendEntry);
158
+ if (data.backendWebsocket !== undefined)
159
+ formData.append("backend_websocket", String(data.backendWebsocket));
160
+ if (data.disableSdkUpdateNotice !== undefined)
161
+ formData.append("disable_sdk_update_notice", String(data.disableSdkUpdateNotice));
162
+ const uploadHeaders = { ...this.headers };
163
+ delete uploadHeaders["Content-Type"];
164
+ (0, log_1.logRequest)("POST", url, uploadHeaders);
165
+ const response = await fetch(url, {
166
+ method: "POST",
167
+ headers: uploadHeaders,
168
+ body: formData,
169
+ });
170
+ if (!response.ok)
171
+ await this.handleErrorResponse(response);
172
+ return (await response.json());
173
+ }
139
174
  async delete(pluginId) {
140
175
  config_1.sdkConfig.ensureVersionCompatible();
141
176
  const url = `${this.baseUrl}/api/plugins/${pluginId}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
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",
@@ -133,6 +133,7 @@ sdkConfig.setPluginId('my-plugin');
133
133
  - `createProvider(provider, endpointType, pluginId)` 创建 Vercel AI SDK Provider
134
134
  - Provider 对照表:`api2img`(推荐) / `gemini` / `aihubmix` / `shubiaobiao` / `aiping` / `openrouter` / `kunpo`
135
135
  - **OpenRouter**:使用专用代理端点 `/api/llm/openrouter`,模型 ID 格式为 `provider/model`(如 `openai/gpt-4o-mini`、`anthropic/claude-sonnet-4-20250514`、`google/gemini-2.5-flash-preview`)
136
+ - **OpenRouter Reasoning**:通过 `providerOptions.openrouter.reasoning` 启用模型思考,支持 `effort`(`xhigh`/`high`/`medium`/`low`/`minimal`)和 `max_tokens` 参数,适用于 Claude / DeepSeek-R1 / o1 / o3 / Gemini 等支持思考的模型
136
137
  - **KUNPO API**:统一 LLM 网关(https://llm.ziy.cc),兼容 OpenAI 接口,使用专用代理端点 `/api/llm/kunpo`,一个 Key 访问 150+ 模型
137
138
  - 常用模型列表和 AI SDK 函数速查
138
139
 
@@ -159,6 +160,22 @@ const stream = streamText({
159
160
  for await (const chunk of stream.textStream) {
160
161
  process.stdout.write(chunk);
161
162
  }
163
+
164
+ // 启用思考/推理(OpenRouter / KUNPO 均支持)
165
+ const thinkResult = await generateText({
166
+ model: provider.languageModel('anthropic/claude-sonnet-4-20250514'),
167
+ prompt: '证明根号2是无理数',
168
+ providerOptions: {
169
+ openrouter: {
170
+ reasoning: {
171
+ effort: 'high', // 思考深度: xhigh / high / medium / low / minimal
172
+ // max_tokens: 10000, // 可选:限制思考 token 数量
173
+ },
174
+ },
175
+ },
176
+ });
177
+ console.log('思考过程:', thinkResult.reasoning);
178
+ console.log('最终回答:', thinkResult.text);
162
179
  ```
163
180
 
164
181
  #### KUNPO API 快速示例
@@ -247,7 +264,10 @@ for await (const chunk of stream.textStream) {
247
264
 
248
265
  ### 平台通用 API → `docs/platform-api.md`
249
266
 
250
- - `PluginManagementClient` — 插件 CRUD、启用/禁用/重载/重启、模板管理
267
+ - `PluginManagementClient` — 插件 CRUD(`create` / `update` 分离)、启用/禁用/重载/重启、模板管理
268
+ - `create(data)` — 创建新插件(POST `/api/plugins/create`),插件不存在时使用
269
+ - `update(data)` — 更新已有插件(POST `/api/plugins/update`),插件必须已存在,未传入的字段保留原值
270
+ - 两者均支持: pluginId / name / description / author / version / staticZip / serverZip / backendEntry / backendWebsocket / disableSdkUpdateNotice
251
271
  - `StatsClient` — AI 接口调用统计/趋势、插件访问统计(管理员)
252
272
  - `DashboardClient` — 当前用户统计(无需管理员权限)
253
273
  - `SharedResourceClient` — 平台级文件共享(与 `ResourceClient` 的插件级 ACL 不同)
@@ -285,6 +305,12 @@ ai-world text stream --prompt "请介绍人工智能"
285
305
  # 查看插件列表
286
306
  ai-world plugin list --format table
287
307
 
308
+ # 创建插件
309
+ ai-world plugin create ./dist.zip --plugin-id my-plugin --name "My Plugin" --version 1.0.0
310
+
311
+ # 更新插件(插件必须已存在,未传入的字段保留原值)
312
+ ai-world plugin update ./dist.zip --plugin-id my-plugin --version 1.1.0
313
+
288
314
  # 版本检查
289
315
  ai-world version
290
316
  ```