ai-world-sdk 1.3.3 → 1.3.5

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/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.3";
12
+ export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.5";
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.3";
38
- readonly sdkVersion = "1.3.3";
37
+ readonly sdkSignature = "AI_WORLD_SDK_V:1.3.5";
38
+ readonly sdkVersion = "1.3.5";
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.3";
10
+ const SDK_VERSION = "1.3.5";
11
11
  /**
12
12
  * SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
13
13
  * 格式: AI_WORLD_SDK_V:版本号
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.3.3";
15
15
  *
16
16
  * 注意: {VERSION} 占位符会在构建时被替换为实际版本号
17
17
  */
18
- exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.3";
18
+ exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.3.5";
19
19
  /**
20
20
  * 版本兼容性错误
21
21
  */
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ export { OpenAIVideoGenerationClient, type OpenAIVideoGenerationConfig, type Ope
30
30
  export { DownloadClient, type DownloadConfig, type DownloadOptions, type StreamDownloadOptions, };
31
31
  export { MinioStorageClient, type MinioStorageConfig, type UploadResponse, type ObjectInfo, type PresignedUrlResponse, type UploadOptions, type ListOptions, } from "./minio";
32
32
  export { ResourceClient, type ResourceClientConfig, type ResourceInfo, type AccessLevel, type UploadResourceOptions, type ListResourceOptions, } from "./resource";
33
- export { DatabaseRequestClient, type DatabaseRequestClientConfig, type DatabaseRequestInfo, type RequestType, type RequestStatus, type ColumnDefinition, type IndexDefinition, type ForeignKeyDefinition, type SchemaDefinition, type SubmitCreateRequestOptions, type SubmitMigrateRequestOptions, type ListRequestsOptions, } from "./database-requests";
33
+ export { VersionedResourceClient, type VersionedResourceClientConfig, type VersionedResourceInfo, type VersionedResourceSummary, type VersionedResourceListResponse, type ListVersionedResourceOptions, } from "./versioned-resource";
34
34
  export { AgentSkillClient, type AgentSkillClientConfig, type AgentSkillInfo, type AgentSkillListResponse, type ListSkillsOptions, } from "./agent-skills";
35
35
  export { AuthClient, getCurrentUserInfo, type AuthConfig, type UserInfo, };
36
36
  export { sdkConfig, VersionCompatibilityError, SDK_SIGNATURE, type AuthenticatedUser } from "./config";
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.SDK_SIGNATURE = exports.VersionCompatibilityError = exports.sdkConfig = exports.getCurrentUserInfo = exports.AuthClient = exports.AgentSkillClient = exports.DatabaseRequestClient = exports.ResourceClient = exports.MinioStorageClient = exports.DownloadClient = exports.OpenAIVideoGenerationClient = exports.VideoUnderstandingClient = exports.VideoGenerationClient = exports.GeminiImageGenerationClient = exports.DoubaoImageGenerationClient = exports.ChatAnthropic = exports.ChatGoogleGenerativeAI = exports.ChatOpenAI = exports.BaseChatModel = exports.AIMessageChunk = exports.SystemMessage = exports.AIMessage = exports.HumanMessage = void 0;
23
+ exports.SDK_SIGNATURE = exports.VersionCompatibilityError = exports.sdkConfig = exports.getCurrentUserInfo = exports.AuthClient = exports.AgentSkillClient = exports.VersionedResourceClient = exports.ResourceClient = exports.MinioStorageClient = exports.DownloadClient = exports.OpenAIVideoGenerationClient = exports.VideoUnderstandingClient = exports.VideoGenerationClient = exports.GeminiImageGenerationClient = exports.DoubaoImageGenerationClient = exports.ChatAnthropic = exports.ChatGoogleGenerativeAI = exports.ChatOpenAI = exports.BaseChatModel = exports.AIMessageChunk = exports.SystemMessage = exports.AIMessage = exports.HumanMessage = void 0;
24
24
  exports.createChatModel = createChatModel;
25
25
  const openai_1 = require("./chat_models/openai");
26
26
  const google_1 = require("./chat_models/google");
@@ -60,9 +60,9 @@ Object.defineProperty(exports, "MinioStorageClient", { enumerable: true, get: fu
60
60
  // Export resource management client
61
61
  var resource_1 = require("./resource");
62
62
  Object.defineProperty(exports, "ResourceClient", { enumerable: true, get: function () { return resource_1.ResourceClient; } });
63
- // Export database request client
64
- var database_requests_1 = require("./database-requests");
65
- Object.defineProperty(exports, "DatabaseRequestClient", { enumerable: true, get: function () { return database_requests_1.DatabaseRequestClient; } });
63
+ // Export versioned resource client
64
+ var versioned_resource_1 = require("./versioned-resource");
65
+ Object.defineProperty(exports, "VersionedResourceClient", { enumerable: true, get: function () { return versioned_resource_1.VersionedResourceClient; } });
66
66
  // Export agent skill client
67
67
  var agent_skills_1 = require("./agent-skills");
68
68
  Object.defineProperty(exports, "AgentSkillClient", { enumerable: true, get: function () { return agent_skills_1.AgentSkillClient; } });
package/dist/llm.js CHANGED
@@ -32,6 +32,10 @@ function createProvider(provider, endpointType, pluginId) {
32
32
  settings.baseURL = `${serverUrl}/api/llm/openrouter`;
33
33
  return (0, ai_sdk_provider_1.createOpenRouter)(settings);
34
34
  }
35
+ else if (provider === "kunpo") {
36
+ settings.baseURL = `${serverUrl}/api/llm/kunpo`;
37
+ return (0, ai_sdk_provider_1.createOpenRouter)(settings);
38
+ }
35
39
  switch (endpointType) {
36
40
  case "openai":
37
41
  return (0, openai_1.createOpenAI)(settings);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 模型提供商
3
3
  */
4
- export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic" | "aiping" | "openrouter";
4
+ export type AIModelProvider = "api2img" | "aihubmix" | "doubao" | "gemini" | "shubiaobiao" | "anthropic" | "aiping" | "openrouter" | "kunpo";
5
5
  /**
6
6
  * 模型端点类型
7
7
  * - openai: OpenAI 兼容 API(/v1/chat/completions 等)
@@ -11,6 +11,7 @@ exports.PROVIDER_CONFIGS = {
11
11
  gemini: { provider: "gemini", modelType: "gemini" },
12
12
  anthropic: { provider: "anthropic", modelType: "anthropic" },
13
13
  openrouter: { provider: "openrouter", modelType: "openai" },
14
+ kunpo: { provider: "kunpo", modelType: "openai" },
14
15
  };
15
16
  function getProviderConfig(provider) {
16
17
  return exports.PROVIDER_CONFIGS[provider];
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Versioned Resource Client
3
+ * 版本化资源管理客户端
4
+ * 通过后端 /api/versioned-resources 操作版本化资源系统
5
+ * 资源名称为全局唯一标识,支持语义化版本号管理
6
+ */
7
+ export interface VersionedResourceClientConfig {
8
+ baseUrl?: string;
9
+ token?: string;
10
+ headers?: Record<string, string>;
11
+ }
12
+ export interface VersionedResourceInfo {
13
+ id: number;
14
+ name: string;
15
+ version: string;
16
+ description?: string;
17
+ filename: string;
18
+ size: number;
19
+ content_type: string;
20
+ uploader_id: number;
21
+ uploader_name?: string;
22
+ created_at: string;
23
+ }
24
+ export interface VersionedResourceSummary {
25
+ name: string;
26
+ latest_version: string;
27
+ description?: string;
28
+ filename: string;
29
+ size: number;
30
+ content_type: string;
31
+ version_count: number;
32
+ latest_uploader_name?: string;
33
+ created_at: string;
34
+ }
35
+ export interface VersionedResourceListResponse {
36
+ items: VersionedResourceSummary[];
37
+ total: number;
38
+ page: number;
39
+ page_size: number;
40
+ }
41
+ export interface ListVersionedResourceOptions {
42
+ page?: number;
43
+ pageSize?: number;
44
+ search?: string;
45
+ }
46
+ /**
47
+ * Versioned Resource Client
48
+ * 版本化资源管理客户端类
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { VersionedResourceClient } from 'ai-world-sdk';
53
+ *
54
+ * const vr = new VersionedResourceClient();
55
+ *
56
+ * // 上传新版本
57
+ * const file = new File(['content'], 'config.json', { type: 'application/json' });
58
+ * const res = await vr.upload('my-config', '1.0.0', file, '初始版本');
59
+ *
60
+ * // 获取最新版本
61
+ * const latest = await vr.getLatest('my-config');
62
+ *
63
+ * // 列出所有版本
64
+ * const versions = await vr.listVersions('my-config');
65
+ *
66
+ * // 下载指定版本
67
+ * const blob = await vr.download('my-config', '1.0.0');
68
+ *
69
+ * // 下载最新版本
70
+ * const latestBlob = await vr.download('my-config', 'latest');
71
+ * ```
72
+ */
73
+ export declare class VersionedResourceClient {
74
+ private baseUrl;
75
+ private headers;
76
+ constructor(config?: VersionedResourceClientConfig);
77
+ private handleErrorResponse;
78
+ /**
79
+ * 上传新版本
80
+ * @param name 资源名称(全局唯一标识)
81
+ * @param version 语义化版本号(必须高于当前最新版本)
82
+ * @param file 文件
83
+ * @param description 可选的版本描述
84
+ */
85
+ upload(name: string, version: string, file: File | Blob, description?: string): Promise<VersionedResourceInfo>;
86
+ /**
87
+ * 分页列出所有版本化资源(聚合最新版本信息)
88
+ */
89
+ list(options?: ListVersionedResourceOptions): Promise<VersionedResourceListResponse>;
90
+ /**
91
+ * 列出指定资源的所有版本(按版本号降序)
92
+ */
93
+ listVersions(name: string): Promise<VersionedResourceInfo[]>;
94
+ /**
95
+ * 获取指定资源的最新版本信息
96
+ */
97
+ getLatest(name: string): Promise<VersionedResourceInfo>;
98
+ /**
99
+ * 获取指定版本信息
100
+ */
101
+ getVersion(name: string, version: string): Promise<VersionedResourceInfo>;
102
+ /**
103
+ * 下载指定版本文件(version 可传 "latest" 下载最新版本)
104
+ */
105
+ download(name: string, version: string): Promise<Blob>;
106
+ /**
107
+ * 删除指定版本
108
+ */
109
+ deleteVersion(name: string, version: string): Promise<{
110
+ name: string;
111
+ version: string;
112
+ deleted: boolean;
113
+ }>;
114
+ }
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ /**
3
+ * Versioned Resource Client
4
+ * 版本化资源管理客户端
5
+ * 通过后端 /api/versioned-resources 操作版本化资源系统
6
+ * 资源名称为全局唯一标识,支持语义化版本号管理
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.VersionedResourceClient = void 0;
10
+ const config_1 = require("./config");
11
+ const log_1 = require("./log");
12
+ // ==================== VersionedResourceClient ====================
13
+ /**
14
+ * Versioned Resource Client
15
+ * 版本化资源管理客户端类
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { VersionedResourceClient } from 'ai-world-sdk';
20
+ *
21
+ * const vr = new VersionedResourceClient();
22
+ *
23
+ * // 上传新版本
24
+ * const file = new File(['content'], 'config.json', { type: 'application/json' });
25
+ * const res = await vr.upload('my-config', '1.0.0', file, '初始版本');
26
+ *
27
+ * // 获取最新版本
28
+ * const latest = await vr.getLatest('my-config');
29
+ *
30
+ * // 列出所有版本
31
+ * const versions = await vr.listVersions('my-config');
32
+ *
33
+ * // 下载指定版本
34
+ * const blob = await vr.download('my-config', '1.0.0');
35
+ *
36
+ * // 下载最新版本
37
+ * const latestBlob = await vr.download('my-config', 'latest');
38
+ * ```
39
+ */
40
+ class VersionedResourceClient {
41
+ constructor(config = {}) {
42
+ this.baseUrl =
43
+ config.baseUrl ||
44
+ config_1.sdkConfig.getServerUrl() ||
45
+ (typeof window !== "undefined" ? window.location.origin : "");
46
+ const globalHeaders = config_1.sdkConfig.getHeaders();
47
+ const globalToken = config.token || config_1.sdkConfig.getToken();
48
+ this.headers = {
49
+ ...globalHeaders,
50
+ ...config.headers,
51
+ };
52
+ if (globalToken) {
53
+ this.headers["Authorization"] = `Bearer ${globalToken}`;
54
+ }
55
+ }
56
+ async handleErrorResponse(response) {
57
+ let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
58
+ try {
59
+ const errorText = await response.text();
60
+ const errorJson = JSON.parse(errorText);
61
+ errorMessage = errorJson.detail || errorMessage;
62
+ }
63
+ catch {
64
+ // ignore parse error
65
+ }
66
+ throw new Error(errorMessage);
67
+ }
68
+ /**
69
+ * 上传新版本
70
+ * @param name 资源名称(全局唯一标识)
71
+ * @param version 语义化版本号(必须高于当前最新版本)
72
+ * @param file 文件
73
+ * @param description 可选的版本描述
74
+ */
75
+ async upload(name, version, file, description) {
76
+ const params = new URLSearchParams();
77
+ params.append("name", name);
78
+ params.append("version", version);
79
+ if (description)
80
+ params.append("description", description);
81
+ const url = `${this.baseUrl}/api/versioned-resources/upload?${params.toString()}`;
82
+ const formData = new FormData();
83
+ formData.append("file", file);
84
+ (0, log_1.debugLog)("VersionedResource", `Uploading ${name}@${version}`);
85
+ (0, log_1.logRequest)("POST", url);
86
+ const response = await fetch(url, {
87
+ method: "POST",
88
+ headers: {
89
+ ...this.headers,
90
+ },
91
+ body: formData,
92
+ });
93
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
94
+ if (!response.ok) {
95
+ return this.handleErrorResponse(response);
96
+ }
97
+ return response.json();
98
+ }
99
+ /**
100
+ * 分页列出所有版本化资源(聚合最新版本信息)
101
+ */
102
+ async list(options = {}) {
103
+ const params = new URLSearchParams();
104
+ if (options.page)
105
+ params.append("page", options.page.toString());
106
+ if (options.pageSize)
107
+ params.append("page_size", options.pageSize.toString());
108
+ if (options.search)
109
+ params.append("search", options.search);
110
+ const url = `${this.baseUrl}/api/versioned-resources/?${params.toString()}`;
111
+ (0, log_1.debugLog)("VersionedResource", `Listing resources`);
112
+ (0, log_1.logRequest)("GET", url);
113
+ const response = await fetch(url, {
114
+ method: "GET",
115
+ headers: this.headers,
116
+ });
117
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
118
+ if (!response.ok) {
119
+ return this.handleErrorResponse(response);
120
+ }
121
+ return response.json();
122
+ }
123
+ /**
124
+ * 列出指定资源的所有版本(按版本号降序)
125
+ */
126
+ async listVersions(name) {
127
+ const url = `${this.baseUrl}/api/versioned-resources/${encodeURIComponent(name)}/versions`;
128
+ (0, log_1.debugLog)("VersionedResource", `Listing versions of ${name}`);
129
+ (0, log_1.logRequest)("GET", url);
130
+ const response = await fetch(url, {
131
+ method: "GET",
132
+ headers: this.headers,
133
+ });
134
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
135
+ if (!response.ok) {
136
+ return this.handleErrorResponse(response);
137
+ }
138
+ return response.json();
139
+ }
140
+ /**
141
+ * 获取指定资源的最新版本信息
142
+ */
143
+ async getLatest(name) {
144
+ const url = `${this.baseUrl}/api/versioned-resources/${encodeURIComponent(name)}/latest`;
145
+ (0, log_1.debugLog)("VersionedResource", `Getting latest version of ${name}`);
146
+ (0, log_1.logRequest)("GET", url);
147
+ const response = await fetch(url, {
148
+ method: "GET",
149
+ headers: this.headers,
150
+ });
151
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
152
+ if (!response.ok) {
153
+ return this.handleErrorResponse(response);
154
+ }
155
+ return response.json();
156
+ }
157
+ /**
158
+ * 获取指定版本信息
159
+ */
160
+ async getVersion(name, version) {
161
+ const url = `${this.baseUrl}/api/versioned-resources/${encodeURIComponent(name)}/${encodeURIComponent(version)}`;
162
+ (0, log_1.debugLog)("VersionedResource", `Getting ${name}@${version}`);
163
+ (0, log_1.logRequest)("GET", url);
164
+ const response = await fetch(url, {
165
+ method: "GET",
166
+ headers: this.headers,
167
+ });
168
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
169
+ if (!response.ok) {
170
+ return this.handleErrorResponse(response);
171
+ }
172
+ return response.json();
173
+ }
174
+ /**
175
+ * 下载指定版本文件(version 可传 "latest" 下载最新版本)
176
+ */
177
+ async download(name, version) {
178
+ const url = `${this.baseUrl}/api/versioned-resources/${encodeURIComponent(name)}/${encodeURIComponent(version)}/download`;
179
+ (0, log_1.debugLog)("VersionedResource", `Downloading ${name}@${version}`);
180
+ (0, log_1.logRequest)("GET", url);
181
+ const response = await fetch(url, {
182
+ method: "GET",
183
+ headers: this.headers,
184
+ });
185
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
186
+ if (!response.ok) {
187
+ return this.handleErrorResponse(response);
188
+ }
189
+ return response.blob();
190
+ }
191
+ /**
192
+ * 删除指定版本
193
+ */
194
+ async deleteVersion(name, version) {
195
+ const url = `${this.baseUrl}/api/versioned-resources/${encodeURIComponent(name)}/${encodeURIComponent(version)}`;
196
+ (0, log_1.debugLog)("VersionedResource", `Deleting ${name}@${version}`);
197
+ (0, log_1.logRequest)("DELETE", url);
198
+ const response = await fetch(url, {
199
+ method: "DELETE",
200
+ headers: this.headers,
201
+ });
202
+ (0, log_1.logResponse)(response.status, response.statusText, response.headers, response.body);
203
+ if (!response.ok) {
204
+ return this.handleErrorResponse(response);
205
+ }
206
+ return response.json();
207
+ }
208
+ }
209
+ exports.VersionedResourceClient = VersionedResourceClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
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",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: ai-world-sdk
3
- description: Use when initializing ai-world-sdk or calling AI models in ai-world projects. Covers sdkConfig initialization, createProvider with Vercel AI SDK (generateText, streamText, generateImage), Doubao image/video generation/understanding, MinIO object storage (MinioStorageClient), resource management with ACL (ResourceClient), database requests (DatabaseRequestClient), agent skills management (AgentSkillClient), and VSCode extension login (initAIWorld). Triggers on ai-world-sdk, createProvider, sdkConfig, generateText, streamText, generateImage, doubao, video understanding, VideoUnderstandingClient, MinioStorageClient, minio, ResourceClient, resource management, access control, file sharing, DatabaseRequestClient, database request, table creation, AgentSkillClient, agent skill, vscode extension, initAIWorld, or any AI model integration.
3
+ description: Use when initializing ai-world-sdk or calling AI models in ai-world projects. Covers sdkConfig initialization, createProvider with Vercel AI SDK (generateText, streamText, generateImage), Doubao image/video generation/understanding, MinIO object storage (MinioStorageClient), resource management with ACL (ResourceClient), versioned resource management (VersionedResourceClient), agent skills management (AgentSkillClient), and VSCode extension login (initAIWorld). Triggers on ai-world-sdk, createProvider, sdkConfig, generateText, streamText, generateImage, doubao, video understanding, VideoUnderstandingClient, MinioStorageClient, minio, ResourceClient, resource management, access control, file sharing, VersionedResourceClient, versioned resource, version management, AgentSkillClient, agent skill, vscode extension, initAIWorld, or any AI model integration.
4
4
  ---
5
5
 
6
6
  # AI World SDK
@@ -18,7 +18,7 @@ ai-world-sdk 是 AI World 平台的 TypeScript SDK,通过 `createProvider` 创
18
18
  - 使用 Doubao 豆包图像/视频生成
19
19
  - 使用 MinIO 对象存储(文件上传/下载/管理)
20
20
  - 使用资源管理系统(权限控制: private/specific_users/public)
21
- - 提交数据库建表/迁移请求
21
+ - 使用版本化资源管理(资源名称+版本号管理)
22
22
  - 管理 Agent Skills(上传/下载/删除/列表)
23
23
  - **开发 VSCode 扩展**时集成 AI World 登录和 SDK 功能
24
24
 
@@ -129,8 +129,9 @@ sdkConfig.setPluginId('my-plugin');
129
129
  ### Provider 与模型 → `docs/provider-and-models.md`
130
130
 
131
131
  - `createProvider(provider, endpointType, pluginId)` 创建 Vercel AI SDK Provider
132
- - Provider 对照表:`api2img`(推荐) / `gemini` / `aihubmix` / `shubiaobiao` / `aiping` / `openrouter`
132
+ - Provider 对照表:`api2img`(推荐) / `gemini` / `aihubmix` / `shubiaobiao` / `aiping` / `openrouter` / `kunpo`
133
133
  - **OpenRouter**:使用专用代理端点 `/api/llm/openrouter`,模型 ID 格式为 `provider/model`(如 `openai/gpt-4o-mini`、`anthropic/claude-sonnet-4-20250514`、`google/gemini-2.5-flash-preview`)
134
+ - **KUNPO API**:统一 LLM 网关(https://llm.ziy.cc),兼容 OpenAI 接口,使用专用代理端点 `/api/llm/kunpo`,一个 Key 访问 150+ 模型
134
135
  - 常用模型列表和 AI SDK 函数速查
135
136
 
136
137
  #### OpenRouter 快速示例
@@ -158,6 +159,31 @@ for await (const chunk of stream.textStream) {
158
159
  }
159
160
  ```
160
161
 
162
+ #### KUNPO API 快速示例
163
+
164
+ ```typescript
165
+ import { createProvider } from 'ai-world-sdk';
166
+ import { generateText, streamText } from 'ai';
167
+
168
+ // KUNPO API(endpointType 传 'openai',兼容 OpenAI 接口)
169
+ const provider = createProvider('kunpo', 'openai', 'my-plugin');
170
+
171
+ // 非流式
172
+ const result = await generateText({
173
+ model: provider.languageModel('google/gemini-3.1-pro-preview'),
174
+ prompt: '你好',
175
+ });
176
+
177
+ // 流式
178
+ const stream = streamText({
179
+ model: provider.languageModel('anthropic/claude-haiku-4.5'),
180
+ prompt: '请介绍人工智能',
181
+ });
182
+ for await (const chunk of stream.textStream) {
183
+ process.stdout.write(chunk);
184
+ }
185
+ ```
186
+
161
187
  ### 文本生成 → `docs/text-generation.md`
162
188
 
163
189
  - `generateText` / `streamText` / `generateObject` / `streamObject`
@@ -185,10 +211,11 @@ for await (const chunk of stream.textStream) {
185
211
  - 三级权限: `private` / `specific_users` / `public`
186
212
  - 插件隔离与跨插件访问
187
213
 
188
- ### 数据库请求 → `docs/database-requests.md`
214
+ ### 版本化资源 → `docs/versioned-resource.md`
189
215
 
190
- - `DatabaseRequestClient` — 建表/迁移请求提交、列表、审核
191
- - 表名规则: `{pluginId}_{tableName}`
216
+ - `VersionedResourceClient` — 全局版本化资源管理
217
+ - 资源名称为唯一 ID,支持语义化版本号
218
+ - 支持 `latest` 别名获取/下载最新版本
192
219
 
193
220
  ### Agent Skills → `docs/agent-skills.md`
194
221
 
@@ -15,6 +15,7 @@
15
15
  | `aiping` | `anthropic` | 平音 Claude |
16
16
  | `gemini` | `gemini` | Google 原生,仅限 Gemini 系列模型 |
17
17
  | `openrouter` | `openai` | OpenRouter 聚合服务,SDK 内部自动使用 `createOpenRouter` 和专用代理端点 `/api/llm/openrouter`。模型 ID 格式为 `provider/model`(如 `openai/gpt-4o-mini`、`anthropic/claude-sonnet-4-20250514`) |
18
+ | `kunpo` | `openai` | KUNPO API 统一 LLM 网关(https://llm.ziy.cc),兼容 OpenAI 接口,一个 Key 访问 150+ 模型。SDK 内部使用 `createOpenAI` 并路由到专用代理 `/api/llm/kunpo` |
18
19
 
19
20
  ## EndpointType 与模型对应关系
20
21
 
@@ -25,7 +26,7 @@
25
26
  | `openai` | OpenAI 兼容 | 模型兼容 OpenAI 格式,可包括 GPT、以及经聚合的 Gemini/Claude 等(视 provider 能力) |
26
27
  | `openai` | OpenRouter 兼容 | 当 provider 为 `openrouter` 时,`endpointType` 传 `openai`,SDK 内部自动切换到 `createOpenRouter` 和专用代理端点 |
27
28
 
28
- 规则:**anthropic 不是 provider**,仅 **api2img**、**shubiaobiao**、**aiping** 支持 EndpointType 为 `anthropic`(调用 Claude);`gemini` provider 用 `gemini` endpoint;`openrouter` provider 的 `endpointType` 传 `openai`,SDK 内部会自动使用 `@openrouter/ai-sdk-provider` 的 `createOpenRouter` 并路由到专用代理 `/api/llm/openrouter`,其余按上表组合。
29
+ 规则:**anthropic 不是 provider**,仅 **api2img**、**shubiaobiao**、**aiping** 支持 EndpointType 为 `anthropic`(调用 Claude);`gemini` provider 用 `gemini` endpoint;`openrouter` provider 的 `endpointType` 传 `openai`,SDK 内部会自动使用 `@openrouter/ai-sdk-provider` 的 `createOpenRouter` 并路由到专用代理 `/api/llm/openrouter`;`kunpo` provider 的 `endpointType` 传 `openai`,SDK 内部使用 `createOpenAI` 并路由到专用代理 `/api/llm/kunpo`;其余按上表组合。
29
30
 
30
31
  > `doubao` 不通过 `createProvider` 使用,豆包有专用客户端(见 image-generation.md / video-generation.md)。
31
32
 
@@ -60,6 +61,13 @@ const or = createProvider('openrouter', 'openai', 'my-plugin');
60
61
  or.languageModel('openai/gpt-4o-mini');
61
62
  or.languageModel('anthropic/claude-sonnet-4-20250514');
62
63
  or.languageModel('google/gemini-2.5-flash-preview');
64
+
65
+ // KUNPO API(endpointType 传 'openai',SDK 内部使用 createOpenAI + 专用代理 /api/llm/kunpo)
66
+ // 兼容 OpenAI Chat Completions 格式,支持 150+ 模型
67
+ const kp = createProvider('kunpo', 'openai', 'my-plugin');
68
+ kp.languageModel('google/gemini-3.1-pro-preview');
69
+ kp.languageModel('anthropic/claude-haiku-4.5');
70
+ kp.languageModel('GLM-5.1');
63
71
  ```
64
72
 
65
73
  ### 检测模型可用性
@@ -80,6 +88,11 @@ const ok = await checkModel('api2img', 'openai', 'gpt-4o-mini', 'my-plugin');
80
88
  | `openai/gpt-4o-mini` / `openai/gpt-4o` | 文本 | `openrouter` | `openai`(SDK 自动处理) |
81
89
  | `anthropic/claude-sonnet-4-20250514` | 文本 | `openrouter` | `openai`(SDK 自动处理) |
82
90
  | `google/gemini-2.5-flash-preview` | 文本 | `openrouter` | `openai`(SDK 自动处理) |
91
+ | `google/gemini-3.1-pro-preview` | 文本 | `kunpo` | `openai`(KUNPO API) |
92
+ | `anthropic/claude-haiku-4.5` | 文本 | `kunpo` | `openai`(KUNPO API) |
93
+ | `GLM-5.1` / `z-ai/glm-5v-turbo` | 文本 | `kunpo` | `openai`(KUNPO API) |
94
+ | `x-ai/grok-4.20` | 文本 | `kunpo` | `openai`(KUNPO API) |
95
+ | `google/gemma-4-26b-a4b-it` | 文本 | `kunpo` | `openai`(KUNPO API) |
83
96
  | `doubao-seedream-4-5-251128` | 图像 | — | 专用客户端 |
84
97
 
85
98
  ## AI SDK 函数速查
@@ -0,0 +1,64 @@
1
+ # 版本化资源管理
2
+
3
+ 独立于 SharedResource 的版本化资源系统。资源名称为全局唯一标识(不区分用户),支持语义化版本号管理。
4
+ 存储在 MinIO `ai-world-res` bucket 的 `resources/{name}/{version}/{filename}` 路径下。
5
+
6
+ ## 基本用法
7
+
8
+ ```typescript
9
+ import { VersionedResourceClient } from 'ai-world-sdk';
10
+
11
+ const vr = new VersionedResourceClient();
12
+
13
+ // 上传新版本(版本号必须高于当前最新版本)
14
+ const file = new File(['{"key": "value"}'], 'config.json', { type: 'application/json' });
15
+ const res = await vr.upload('my-config', '1.0.0', file, '初始版本');
16
+
17
+ // 上传更高版本
18
+ const file2 = new File(['{"key": "new"}'], 'config.json', { type: 'application/json' });
19
+ await vr.upload('my-config', '1.1.0', file2, '更新配置');
20
+
21
+ // 获取最新版本信息
22
+ const latest = await vr.getLatest('my-config');
23
+ console.log(latest.version); // "1.1.0"
24
+
25
+ // 获取指定版本信息
26
+ const v1 = await vr.getVersion('my-config', '1.0.0');
27
+
28
+ // 列出所有版本(按版本号降序)
29
+ const versions = await vr.listVersions('my-config');
30
+
31
+ // 下载指定版本
32
+ const blob = await vr.download('my-config', '1.0.0');
33
+
34
+ // 下载最新版本(使用 "latest" 别名)
35
+ const latestBlob = await vr.download('my-config', 'latest');
36
+
37
+ // 列出所有资源(分页,聚合最新版本信息)
38
+ const list = await vr.list({ page: 1, pageSize: 20, search: 'config' });
39
+
40
+ // 删除指定版本
41
+ await vr.deleteVersion('my-config', '1.0.0');
42
+ ```
43
+
44
+ ## 版本号规则
45
+
46
+ | 规则 | 说明 |
47
+ |------|------|
48
+ | 格式 | 语义化版本号(semver),如 `1.0.0`、`2.1.3` |
49
+ | 唯一性 | 同一资源名称下版本号唯一 |
50
+ | 递增约束 | 上传新版本时,版本号必须高于当前最新版本 |
51
+ | latest 别名 | 获取/下载时可使用 `latest` 代替具体版本号 |
52
+
53
+ ## 权限模型
54
+
55
+ | 操作 | 权限要求 |
56
+ |------|----------|
57
+ | 上传/删除 | `can_upload_shared_resources` 权限 |
58
+ | 查看/下载 | 所有已登录用户 |
59
+
60
+ ## 与 SharedResource / ResourceClient 的区别
61
+
62
+ - `SharedResource` — 平台级文件共享,按用户上传,无版本概念
63
+ - `ResourceClient` — 插件级资源管理,按 plugin_id 隔离,三级 ACL
64
+ - `VersionedResourceClient` — 全局版本化资源,资源名称为唯一 ID,支持多版本管理
@@ -1,151 +0,0 @@
1
- /**
2
- * Database Request Client
3
- * 数据库请求客户端
4
- * 通过后端 /api/database 提交建表/迁移请求,查看请求列表和详情
5
- * 所有登录用户可提交请求,管理员可审核
6
- */
7
- export interface DatabaseRequestClientConfig {
8
- baseUrl?: string;
9
- token?: string;
10
- headers?: Record<string, string>;
11
- }
12
- export type RequestType = "create" | "migrate";
13
- export type RequestStatus = "pending" | "approved" | "rejected";
14
- export interface ColumnDefinition {
15
- name: string;
16
- type: string;
17
- primary_key?: boolean;
18
- auto_increment?: boolean;
19
- nullable?: boolean;
20
- default?: unknown;
21
- length?: number;
22
- precision?: number;
23
- scale?: number;
24
- }
25
- export interface IndexDefinition {
26
- name: string;
27
- columns: string[];
28
- unique?: boolean;
29
- }
30
- export interface ForeignKeyDefinition {
31
- column: string;
32
- references_table: string;
33
- references_column: string;
34
- on_delete?: string;
35
- }
36
- export interface SchemaDefinition {
37
- columns: ColumnDefinition[];
38
- indexes?: IndexDefinition[];
39
- foreign_keys?: ForeignKeyDefinition[];
40
- }
41
- export interface SubmitCreateRequestOptions {
42
- tableName: string;
43
- schemaDefinition: SchemaDefinition;
44
- description?: string;
45
- }
46
- export interface SubmitMigrateRequestOptions {
47
- tableName: string;
48
- migrationSql: string;
49
- description?: string;
50
- }
51
- export interface DatabaseRequestInfo {
52
- id: number;
53
- requester_id: number;
54
- plugin_id: string;
55
- table_name: string;
56
- request_type: RequestType;
57
- schema_definition: SchemaDefinition | null;
58
- migration_sql: string | null;
59
- description: string | null;
60
- status: RequestStatus;
61
- reviewer_id: number | null;
62
- review_comment: string | null;
63
- created_at: string;
64
- reviewed_at: string | null;
65
- }
66
- export interface ListRequestsOptions {
67
- status?: RequestStatus;
68
- page?: number;
69
- pageSize?: number;
70
- }
71
- /**
72
- * Database Request Client
73
- * 数据库请求客户端类
74
- *
75
- * @example
76
- * ```typescript
77
- * import { DatabaseRequestClient, sdkConfig } from 'ai-world-sdk';
78
- *
79
- * sdkConfig.setPluginId('my-plugin');
80
- * const dbRequests = new DatabaseRequestClient();
81
- *
82
- * // 提交建表请求
83
- * const req = await dbRequests.submitCreateRequest({
84
- * tableName: 'user_scores',
85
- * schemaDefinition: {
86
- * columns: [
87
- * { name: 'id', type: 'integer', primary_key: true, auto_increment: true, nullable: false },
88
- * { name: 'user_id', type: 'integer', nullable: false },
89
- * { name: 'score', type: 'float', nullable: false },
90
- * ],
91
- * indexes: [{ name: 'idx_user_id', columns: ['user_id'] }],
92
- * },
93
- * description: '用户评分表',
94
- * });
95
- *
96
- * // 提交迁移请求
97
- * const migrateReq = await dbRequests.submitMigrateRequest({
98
- * tableName: 'user_scores',
99
- * migrationSql: 'ALTER TABLE my_plugin_user_scores ADD COLUMN level INTEGER DEFAULT 0;',
100
- * description: '添加 level 字段',
101
- * });
102
- *
103
- * // 列出我的请求
104
- * const list = await dbRequests.listRequests({ status: 'pending' });
105
- *
106
- * // 获取请求详情
107
- * const detail = await dbRequests.getRequest(req.id);
108
- *
109
- * // 获取请求总数
110
- * const total = await dbRequests.getRequestCount({ status: 'pending' });
111
- * ```
112
- */
113
- export declare class DatabaseRequestClient {
114
- private baseUrl;
115
- private headers;
116
- constructor(config?: DatabaseRequestClientConfig);
117
- private getPluginId;
118
- private handleErrorResponse;
119
- /**
120
- * Submit a table creation request
121
- * 提交建表请求
122
- */
123
- submitCreateRequest(options: SubmitCreateRequestOptions): Promise<DatabaseRequestInfo>;
124
- /**
125
- * Submit a migration request
126
- * 提交迁移请求
127
- */
128
- submitMigrateRequest(options: SubmitMigrateRequestOptions): Promise<DatabaseRequestInfo>;
129
- /**
130
- * List requests (admin sees all, regular users see own)
131
- * 列出请求列表(管理员看全部,普通用户看自己的)
132
- */
133
- listRequests(options?: ListRequestsOptions): Promise<DatabaseRequestInfo[]>;
134
- /**
135
- * Get request count
136
- * 获取请求总数
137
- */
138
- getRequestCount(options?: {
139
- status?: RequestStatus;
140
- }): Promise<number>;
141
- /**
142
- * Get request detail by ID
143
- * 获取请求详情
144
- */
145
- getRequest(requestId: number): Promise<DatabaseRequestInfo>;
146
- /**
147
- * Review a request (approve/reject) - requires can_manage_database permission
148
- * 审核请求(通过/拒绝)- 需要 can_manage_database 权限
149
- */
150
- reviewRequest(requestId: number, action: "approve" | "reject", comment?: string): Promise<DatabaseRequestInfo>;
151
- }
@@ -1,242 +0,0 @@
1
- "use strict";
2
- /**
3
- * Database Request Client
4
- * 数据库请求客户端
5
- * 通过后端 /api/database 提交建表/迁移请求,查看请求列表和详情
6
- * 所有登录用户可提交请求,管理员可审核
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.DatabaseRequestClient = void 0;
10
- const config_1 = require("./config");
11
- const log_1 = require("./log");
12
- // ==================== DatabaseRequestClient ====================
13
- /**
14
- * Database Request Client
15
- * 数据库请求客户端类
16
- *
17
- * @example
18
- * ```typescript
19
- * import { DatabaseRequestClient, sdkConfig } from 'ai-world-sdk';
20
- *
21
- * sdkConfig.setPluginId('my-plugin');
22
- * const dbRequests = new DatabaseRequestClient();
23
- *
24
- * // 提交建表请求
25
- * const req = await dbRequests.submitCreateRequest({
26
- * tableName: 'user_scores',
27
- * schemaDefinition: {
28
- * columns: [
29
- * { name: 'id', type: 'integer', primary_key: true, auto_increment: true, nullable: false },
30
- * { name: 'user_id', type: 'integer', nullable: false },
31
- * { name: 'score', type: 'float', nullable: false },
32
- * ],
33
- * indexes: [{ name: 'idx_user_id', columns: ['user_id'] }],
34
- * },
35
- * description: '用户评分表',
36
- * });
37
- *
38
- * // 提交迁移请求
39
- * const migrateReq = await dbRequests.submitMigrateRequest({
40
- * tableName: 'user_scores',
41
- * migrationSql: 'ALTER TABLE my_plugin_user_scores ADD COLUMN level INTEGER DEFAULT 0;',
42
- * description: '添加 level 字段',
43
- * });
44
- *
45
- * // 列出我的请求
46
- * const list = await dbRequests.listRequests({ status: 'pending' });
47
- *
48
- * // 获取请求详情
49
- * const detail = await dbRequests.getRequest(req.id);
50
- *
51
- * // 获取请求总数
52
- * const total = await dbRequests.getRequestCount({ status: 'pending' });
53
- * ```
54
- */
55
- class DatabaseRequestClient {
56
- constructor(config = {}) {
57
- this.baseUrl =
58
- config.baseUrl ||
59
- config_1.sdkConfig.getServerUrl() ||
60
- (typeof window !== "undefined" ? window.location.origin : "");
61
- const globalHeaders = config_1.sdkConfig.getHeaders();
62
- const globalToken = config.token || config_1.sdkConfig.getToken();
63
- this.headers = {
64
- "Content-Type": "application/json",
65
- ...globalHeaders,
66
- ...config.headers,
67
- };
68
- if (globalToken) {
69
- this.headers["Authorization"] = `Bearer ${globalToken}`;
70
- }
71
- }
72
- getPluginId() {
73
- const pluginId = this.headers["X-Plugin-Id"] || config_1.sdkConfig.getPluginId();
74
- if (!pluginId) {
75
- throw new Error("Plugin ID is required. Set it via sdkConfig.setPluginId() or pass pluginId in headers.");
76
- }
77
- return pluginId;
78
- }
79
- async handleErrorResponse(response) {
80
- let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
81
- try {
82
- const errorText = await response.text();
83
- const errorJson = JSON.parse(errorText);
84
- errorMessage = errorJson.detail || errorMessage;
85
- }
86
- catch {
87
- // ignore parse error
88
- }
89
- throw new Error(errorMessage);
90
- }
91
- /**
92
- * Submit a table creation request
93
- * 提交建表请求
94
- */
95
- async submitCreateRequest(options) {
96
- config_1.sdkConfig.ensureVersionCompatible();
97
- const pluginId = this.getPluginId();
98
- const body = {
99
- plugin_id: pluginId,
100
- table_name: options.tableName,
101
- request_type: "create",
102
- schema_definition: options.schemaDefinition,
103
- description: options.description,
104
- };
105
- const apiUrl = `${this.baseUrl}/api/database/table-requests`;
106
- (0, log_1.debugLog)("Submit create request:", body);
107
- (0, log_1.logRequest)("POST", apiUrl, this.headers, body);
108
- const response = await fetch(apiUrl, {
109
- method: "POST",
110
- headers: this.headers,
111
- body: JSON.stringify(body),
112
- });
113
- if (!response.ok) {
114
- await this.handleErrorResponse(response);
115
- }
116
- const result = (await response.json());
117
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
118
- return result;
119
- }
120
- /**
121
- * Submit a migration request
122
- * 提交迁移请求
123
- */
124
- async submitMigrateRequest(options) {
125
- config_1.sdkConfig.ensureVersionCompatible();
126
- const pluginId = this.getPluginId();
127
- const body = {
128
- plugin_id: pluginId,
129
- table_name: options.tableName,
130
- request_type: "migrate",
131
- migration_sql: options.migrationSql,
132
- description: options.description,
133
- };
134
- const apiUrl = `${this.baseUrl}/api/database/table-requests`;
135
- (0, log_1.debugLog)("Submit migrate request:", body);
136
- (0, log_1.logRequest)("POST", apiUrl, this.headers, body);
137
- const response = await fetch(apiUrl, {
138
- method: "POST",
139
- headers: this.headers,
140
- body: JSON.stringify(body),
141
- });
142
- if (!response.ok) {
143
- await this.handleErrorResponse(response);
144
- }
145
- const result = (await response.json());
146
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
147
- return result;
148
- }
149
- /**
150
- * List requests (admin sees all, regular users see own)
151
- * 列出请求列表(管理员看全部,普通用户看自己的)
152
- */
153
- async listRequests(options = {}) {
154
- config_1.sdkConfig.ensureVersionCompatible();
155
- const params = new URLSearchParams();
156
- if (options.status)
157
- params.append("status", options.status);
158
- if (options.page)
159
- params.append("page", String(options.page));
160
- if (options.pageSize)
161
- params.append("page_size", String(options.pageSize));
162
- const apiUrl = `${this.baseUrl}/api/database/table-requests?${params.toString()}`;
163
- (0, log_1.debugLog)("List requests:", options);
164
- (0, log_1.logRequest)("GET", apiUrl, this.headers);
165
- const response = await fetch(apiUrl, {
166
- method: "GET",
167
- headers: this.headers,
168
- });
169
- if (!response.ok) {
170
- await this.handleErrorResponse(response);
171
- }
172
- const result = (await response.json());
173
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
174
- return result;
175
- }
176
- /**
177
- * Get request count
178
- * 获取请求总数
179
- */
180
- async getRequestCount(options = {}) {
181
- config_1.sdkConfig.ensureVersionCompatible();
182
- const params = new URLSearchParams();
183
- if (options.status)
184
- params.append("status", options.status);
185
- const apiUrl = `${this.baseUrl}/api/database/table-requests/count?${params.toString()}`;
186
- (0, log_1.debugLog)("Get request count:", options);
187
- (0, log_1.logRequest)("GET", apiUrl, this.headers);
188
- const response = await fetch(apiUrl, {
189
- method: "GET",
190
- headers: this.headers,
191
- });
192
- if (!response.ok) {
193
- await this.handleErrorResponse(response);
194
- }
195
- const result = (await response.json());
196
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
197
- return result.total;
198
- }
199
- /**
200
- * Get request detail by ID
201
- * 获取请求详情
202
- */
203
- async getRequest(requestId) {
204
- config_1.sdkConfig.ensureVersionCompatible();
205
- const apiUrl = `${this.baseUrl}/api/database/table-requests/${requestId}`;
206
- (0, log_1.debugLog)("Get request detail:", { requestId });
207
- (0, log_1.logRequest)("GET", apiUrl, this.headers);
208
- const response = await fetch(apiUrl, {
209
- method: "GET",
210
- headers: this.headers,
211
- });
212
- if (!response.ok) {
213
- await this.handleErrorResponse(response);
214
- }
215
- const result = (await response.json());
216
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
217
- return result;
218
- }
219
- /**
220
- * Review a request (approve/reject) - requires can_manage_database permission
221
- * 审核请求(通过/拒绝)- 需要 can_manage_database 权限
222
- */
223
- async reviewRequest(requestId, action, comment) {
224
- config_1.sdkConfig.ensureVersionCompatible();
225
- const body = { action, comment };
226
- const apiUrl = `${this.baseUrl}/api/database/table-requests/${requestId}`;
227
- (0, log_1.debugLog)("Review request:", { requestId, ...body });
228
- (0, log_1.logRequest)("PATCH", apiUrl, this.headers, body);
229
- const response = await fetch(apiUrl, {
230
- method: "PATCH",
231
- headers: this.headers,
232
- body: JSON.stringify(body),
233
- });
234
- if (!response.ok) {
235
- await this.handleErrorResponse(response);
236
- }
237
- const result = (await response.json());
238
- (0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
239
- return result;
240
- }
241
- }
242
- exports.DatabaseRequestClient = DatabaseRequestClient;
@@ -1,68 +0,0 @@
1
- # 数据库请求
2
-
3
- 通过 `DatabaseRequestClient` 提交建表/迁移请求、查看请求列表和详情。所有登录用户可提交请求,管理员审核通过后自动执行。
4
-
5
- ## 基本用法
6
-
7
- ```typescript
8
- import { DatabaseRequestClient, sdkConfig } from 'ai-world-sdk';
9
-
10
- sdkConfig.setPluginId('my-plugin');
11
- const dbRequests = new DatabaseRequestClient();
12
-
13
- // 提交建表请求
14
- const req = await dbRequests.submitCreateRequest({
15
- tableName: 'user_scores',
16
- schemaDefinition: {
17
- columns: [
18
- { name: 'id', type: 'integer', primary_key: true, auto_increment: true, nullable: false },
19
- { name: 'user_id', type: 'integer', nullable: false },
20
- { name: 'score', type: 'float', nullable: false },
21
- ],
22
- indexes: [{ name: 'idx_user_id', columns: ['user_id'] }],
23
- },
24
- description: '用户评分表',
25
- });
26
-
27
- // 提交迁移请求
28
- await dbRequests.submitMigrateRequest({
29
- tableName: 'user_scores',
30
- migrationSql: 'ALTER TABLE my_plugin_user_scores ADD COLUMN level INTEGER DEFAULT 0;',
31
- description: '添加 level 字段',
32
- });
33
-
34
- // 列出请求(普通用户看自己的,管理员看全部)
35
- const list = await dbRequests.listRequests({ status: 'pending', page: 1, pageSize: 20 });
36
-
37
- // 获取请求总数
38
- const total = await dbRequests.getRequestCount({ status: 'pending' });
39
-
40
- // 获取请求详情
41
- const detail = await dbRequests.getRequest(req.id);
42
-
43
- // 审核请求(需 can_manage_database 权限)
44
- await dbRequests.reviewRequest(req.id, 'approve', '审核通过');
45
- ```
46
-
47
- ## 表名规则
48
-
49
- - 实际表名 = `{pluginId}_{tableName}`
50
- - 只允许 `[a-z0-9_]`
51
-
52
- ## 列类型白名单
53
-
54
- integer, bigint, varchar, text, boolean, float, decimal, date, datetime, timestamp, json, jsonb
55
-
56
- ## 迁移 SQL 限制
57
-
58
- 禁止: DROP DATABASE, TRUNCATE, DROP SCHEMA
59
-
60
- ## API 端点
61
-
62
- | 方法 | 路径 | 说明 |
63
- |------|------|------|
64
- | POST | `/api/database/table-requests` | 提交建表/迁移请求 |
65
- | GET | `/api/database/table-requests` | 列出请求 |
66
- | GET | `/api/database/table-requests/count` | 请求总数 |
67
- | GET | `/api/database/table-requests/{id}` | 请求详情 |
68
- | PATCH | `/api/database/table-requests/{id}` | 审核请求 |