ai-world-sdk 1.3.5 → 1.3.6
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/admin.d.ts +121 -0
- package/dist/admin.js +297 -0
- package/dist/chrome-extension.d.ts +54 -0
- package/dist/chrome-extension.js +124 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -1
- package/dist/plugin-management.d.ts +144 -0
- package/dist/plugin-management.js +333 -0
- package/dist/shared-resource.d.ts +61 -0
- package/dist/shared-resource.js +133 -0
- package/dist/stats.d.ts +60 -0
- package/dist/stats.js +172 -0
- package/package.json +1 -1
- package/skills/ai-world-sdk/SKILL.md +22 -1
- package/skills/ai-world-sdk/docs/admin-api.md +133 -0
- package/skills/ai-world-sdk/docs/auth-and-download.md +87 -0
- package/skills/ai-world-sdk/docs/common-mistakes.md +23 -2
- package/skills/ai-world-sdk/docs/platform-api.md +186 -0
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Client
|
|
3
|
+
* 管理员客户端:用户管理、角色管理、数据库表管理
|
|
4
|
+
* 所有接口需管理员权限
|
|
5
|
+
*/
|
|
6
|
+
export interface AdminClientConfig {
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export interface AdminUserInfo {
|
|
12
|
+
id: number;
|
|
13
|
+
email?: string;
|
|
14
|
+
full_name?: string;
|
|
15
|
+
avatar_url?: string;
|
|
16
|
+
feishu_user_id?: string;
|
|
17
|
+
is_active: boolean;
|
|
18
|
+
is_superuser: boolean;
|
|
19
|
+
role_id?: number;
|
|
20
|
+
role_name?: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AdminUserListResponse {
|
|
24
|
+
items: AdminUserInfo[];
|
|
25
|
+
total: number;
|
|
26
|
+
page: number;
|
|
27
|
+
page_size: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ListUsersOptions {
|
|
30
|
+
page?: number;
|
|
31
|
+
pageSize?: number;
|
|
32
|
+
search?: string;
|
|
33
|
+
roleId?: number;
|
|
34
|
+
noRole?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface RoleInfo {
|
|
37
|
+
id: number;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
permissions: Record<string, boolean>;
|
|
41
|
+
created_at?: string;
|
|
42
|
+
updated_at?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface CreateRoleData {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
permissions?: Record<string, boolean>;
|
|
48
|
+
}
|
|
49
|
+
export interface UpdateRoleData {
|
|
50
|
+
name?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
permissions?: Record<string, boolean>;
|
|
53
|
+
}
|
|
54
|
+
export interface RoleUserCount {
|
|
55
|
+
role_id: number;
|
|
56
|
+
role_name: string;
|
|
57
|
+
user_count: number;
|
|
58
|
+
}
|
|
59
|
+
export interface TableColumn {
|
|
60
|
+
name: string;
|
|
61
|
+
type: string;
|
|
62
|
+
nullable?: boolean;
|
|
63
|
+
default?: string;
|
|
64
|
+
primary_key?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface TableDataResponse {
|
|
67
|
+
data: Record<string, any>[];
|
|
68
|
+
total: number;
|
|
69
|
+
page: number;
|
|
70
|
+
page_size: number;
|
|
71
|
+
}
|
|
72
|
+
export interface ListTableDataOptions {
|
|
73
|
+
page?: number;
|
|
74
|
+
pageSize?: number;
|
|
75
|
+
search?: string;
|
|
76
|
+
sortBy?: string;
|
|
77
|
+
sortOrder?: "asc" | "desc";
|
|
78
|
+
}
|
|
79
|
+
export declare class AdminClient {
|
|
80
|
+
private baseUrl;
|
|
81
|
+
private headers;
|
|
82
|
+
constructor(config?: AdminClientConfig);
|
|
83
|
+
private handleErrorResponse;
|
|
84
|
+
private buildUrl;
|
|
85
|
+
listUsers(options?: ListUsersOptions): Promise<AdminUserListResponse>;
|
|
86
|
+
getUser(userId: number): Promise<AdminUserInfo>;
|
|
87
|
+
activateUser(userId: number): Promise<{
|
|
88
|
+
message: string;
|
|
89
|
+
}>;
|
|
90
|
+
deactivateUser(userId: number): Promise<{
|
|
91
|
+
message: string;
|
|
92
|
+
}>;
|
|
93
|
+
makeAdmin(userId: number): Promise<{
|
|
94
|
+
message: string;
|
|
95
|
+
}>;
|
|
96
|
+
removeAdmin(userId: number): Promise<{
|
|
97
|
+
message: string;
|
|
98
|
+
}>;
|
|
99
|
+
setUserRole(userId: number, roleId?: number): Promise<{
|
|
100
|
+
message: string;
|
|
101
|
+
}>;
|
|
102
|
+
batchSetRole(userIds: number[], roleId?: number | null): Promise<{
|
|
103
|
+
message: string;
|
|
104
|
+
}>;
|
|
105
|
+
listRoles(): Promise<RoleInfo[]>;
|
|
106
|
+
getRole(roleId: number): Promise<RoleInfo>;
|
|
107
|
+
getRoleUserCounts(): Promise<RoleUserCount[]>;
|
|
108
|
+
createRole(data: CreateRoleData): Promise<RoleInfo>;
|
|
109
|
+
updateRole(roleId: number, data: UpdateRoleData): Promise<RoleInfo>;
|
|
110
|
+
deleteRole(roleId: number): Promise<{
|
|
111
|
+
message: string;
|
|
112
|
+
}>;
|
|
113
|
+
listTables(): Promise<string[]>;
|
|
114
|
+
getTableSchema(tableName: string): Promise<TableColumn[]>;
|
|
115
|
+
getTableData(tableName: string, options?: ListTableDataOptions): Promise<TableDataResponse>;
|
|
116
|
+
insertRow(tableName: string, data: Record<string, any>): Promise<Record<string, any>>;
|
|
117
|
+
updateRow(tableName: string, primaryKey: Record<string, any>, data: Record<string, any>): Promise<Record<string, any>>;
|
|
118
|
+
deleteRow(tableName: string, primaryKey: Record<string, any>): Promise<{
|
|
119
|
+
message: string;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
package/dist/admin.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Admin Client
|
|
4
|
+
* 管理员客户端:用户管理、角色管理、数据库表管理
|
|
5
|
+
* 所有接口需管理员权限
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AdminClient = void 0;
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const log_1 = require("./log");
|
|
11
|
+
class AdminClient {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
this.baseUrl =
|
|
14
|
+
config.baseUrl ||
|
|
15
|
+
config_1.sdkConfig.getServerUrl() ||
|
|
16
|
+
(typeof window !== "undefined" ? window.location.origin : "");
|
|
17
|
+
const globalHeaders = config_1.sdkConfig.getHeaders();
|
|
18
|
+
const globalToken = config.token || config_1.sdkConfig.getToken();
|
|
19
|
+
this.headers = {
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
...globalHeaders,
|
|
22
|
+
...config.headers,
|
|
23
|
+
};
|
|
24
|
+
if (globalToken) {
|
|
25
|
+
this.headers["Authorization"] = `Bearer ${globalToken}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async handleErrorResponse(response) {
|
|
29
|
+
let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
|
|
30
|
+
try {
|
|
31
|
+
const errorText = await response.text();
|
|
32
|
+
const errorJson = JSON.parse(errorText);
|
|
33
|
+
errorMessage = errorJson.detail || errorMessage;
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
throw new Error(errorMessage);
|
|
37
|
+
}
|
|
38
|
+
buildUrl(path, params) {
|
|
39
|
+
const url = `${this.baseUrl}${path}`;
|
|
40
|
+
if (!params)
|
|
41
|
+
return url;
|
|
42
|
+
const sp = new URLSearchParams();
|
|
43
|
+
for (const [k, v] of Object.entries(params)) {
|
|
44
|
+
if (v !== undefined && v !== null)
|
|
45
|
+
sp.append(k, String(v));
|
|
46
|
+
}
|
|
47
|
+
const qs = sp.toString();
|
|
48
|
+
return qs ? `${url}?${qs}` : url;
|
|
49
|
+
}
|
|
50
|
+
// ==================== 用户管理 ====================
|
|
51
|
+
async listUsers(options = {}) {
|
|
52
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
53
|
+
const url = this.buildUrl("/api/admin/users", {
|
|
54
|
+
page: options.page,
|
|
55
|
+
page_size: options.pageSize,
|
|
56
|
+
search: options.search,
|
|
57
|
+
role_id: options.roleId,
|
|
58
|
+
no_role: options.noRole,
|
|
59
|
+
});
|
|
60
|
+
(0, log_1.debugLog)("Admin list users:", options);
|
|
61
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
62
|
+
const response = await fetch(url, { headers: this.headers });
|
|
63
|
+
if (!response.ok)
|
|
64
|
+
await this.handleErrorResponse(response);
|
|
65
|
+
const result = (await response.json());
|
|
66
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
async getUser(userId) {
|
|
70
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
71
|
+
const url = `${this.baseUrl}/api/admin/users/${userId}`;
|
|
72
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
73
|
+
const response = await fetch(url, { headers: this.headers });
|
|
74
|
+
if (!response.ok)
|
|
75
|
+
await this.handleErrorResponse(response);
|
|
76
|
+
const result = (await response.json());
|
|
77
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
async activateUser(userId) {
|
|
81
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
82
|
+
const url = `${this.baseUrl}/api/admin/users/${userId}/activate`;
|
|
83
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
84
|
+
const response = await fetch(url, {
|
|
85
|
+
method: "PATCH",
|
|
86
|
+
headers: this.headers,
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok)
|
|
89
|
+
await this.handleErrorResponse(response);
|
|
90
|
+
return (await response.json());
|
|
91
|
+
}
|
|
92
|
+
async deactivateUser(userId) {
|
|
93
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
94
|
+
const url = `${this.baseUrl}/api/admin/users/${userId}/deactivate`;
|
|
95
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
96
|
+
const response = await fetch(url, {
|
|
97
|
+
method: "PATCH",
|
|
98
|
+
headers: this.headers,
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok)
|
|
101
|
+
await this.handleErrorResponse(response);
|
|
102
|
+
return (await response.json());
|
|
103
|
+
}
|
|
104
|
+
async makeAdmin(userId) {
|
|
105
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
106
|
+
const url = `${this.baseUrl}/api/admin/users/${userId}/make-admin`;
|
|
107
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
108
|
+
const response = await fetch(url, {
|
|
109
|
+
method: "PATCH",
|
|
110
|
+
headers: this.headers,
|
|
111
|
+
});
|
|
112
|
+
if (!response.ok)
|
|
113
|
+
await this.handleErrorResponse(response);
|
|
114
|
+
return (await response.json());
|
|
115
|
+
}
|
|
116
|
+
async removeAdmin(userId) {
|
|
117
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
118
|
+
const url = `${this.baseUrl}/api/admin/users/${userId}/remove-admin`;
|
|
119
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
120
|
+
const response = await fetch(url, {
|
|
121
|
+
method: "PATCH",
|
|
122
|
+
headers: this.headers,
|
|
123
|
+
});
|
|
124
|
+
if (!response.ok)
|
|
125
|
+
await this.handleErrorResponse(response);
|
|
126
|
+
return (await response.json());
|
|
127
|
+
}
|
|
128
|
+
async setUserRole(userId, roleId) {
|
|
129
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
130
|
+
const url = this.buildUrl(`/api/admin/users/${userId}/role`, roleId !== undefined ? { role_id: roleId } : undefined);
|
|
131
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
132
|
+
const response = await fetch(url, {
|
|
133
|
+
method: "PATCH",
|
|
134
|
+
headers: this.headers,
|
|
135
|
+
});
|
|
136
|
+
if (!response.ok)
|
|
137
|
+
await this.handleErrorResponse(response);
|
|
138
|
+
return (await response.json());
|
|
139
|
+
}
|
|
140
|
+
async batchSetRole(userIds, roleId) {
|
|
141
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
142
|
+
const url = `${this.baseUrl}/api/admin/users/batch-role`;
|
|
143
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
144
|
+
const response = await fetch(url, {
|
|
145
|
+
method: "PATCH",
|
|
146
|
+
headers: this.headers,
|
|
147
|
+
body: JSON.stringify({ user_ids: userIds, role_id: roleId ?? null }),
|
|
148
|
+
});
|
|
149
|
+
if (!response.ok)
|
|
150
|
+
await this.handleErrorResponse(response);
|
|
151
|
+
return (await response.json());
|
|
152
|
+
}
|
|
153
|
+
// ==================== 角色管理 ====================
|
|
154
|
+
async listRoles() {
|
|
155
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
156
|
+
const url = `${this.baseUrl}/api/admin/roles`;
|
|
157
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
158
|
+
const response = await fetch(url, { headers: this.headers });
|
|
159
|
+
if (!response.ok)
|
|
160
|
+
await this.handleErrorResponse(response);
|
|
161
|
+
const result = (await response.json());
|
|
162
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
async getRole(roleId) {
|
|
166
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
167
|
+
const url = `${this.baseUrl}/api/admin/roles/${roleId}`;
|
|
168
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
169
|
+
const response = await fetch(url, { headers: this.headers });
|
|
170
|
+
if (!response.ok)
|
|
171
|
+
await this.handleErrorResponse(response);
|
|
172
|
+
const result = (await response.json());
|
|
173
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
async getRoleUserCounts() {
|
|
177
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
178
|
+
const url = `${this.baseUrl}/api/admin/roles/user-counts`;
|
|
179
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
180
|
+
const response = await fetch(url, { headers: this.headers });
|
|
181
|
+
if (!response.ok)
|
|
182
|
+
await this.handleErrorResponse(response);
|
|
183
|
+
return (await response.json());
|
|
184
|
+
}
|
|
185
|
+
async createRole(data) {
|
|
186
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
187
|
+
const url = `${this.baseUrl}/api/admin/roles`;
|
|
188
|
+
(0, log_1.logRequest)("POST", url, this.headers);
|
|
189
|
+
const response = await fetch(url, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: this.headers,
|
|
192
|
+
body: JSON.stringify(data),
|
|
193
|
+
});
|
|
194
|
+
if (!response.ok)
|
|
195
|
+
await this.handleErrorResponse(response);
|
|
196
|
+
return (await response.json());
|
|
197
|
+
}
|
|
198
|
+
async updateRole(roleId, data) {
|
|
199
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
200
|
+
const url = `${this.baseUrl}/api/admin/roles/${roleId}`;
|
|
201
|
+
(0, log_1.logRequest)("PATCH", url, this.headers);
|
|
202
|
+
const response = await fetch(url, {
|
|
203
|
+
method: "PATCH",
|
|
204
|
+
headers: this.headers,
|
|
205
|
+
body: JSON.stringify(data),
|
|
206
|
+
});
|
|
207
|
+
if (!response.ok)
|
|
208
|
+
await this.handleErrorResponse(response);
|
|
209
|
+
return (await response.json());
|
|
210
|
+
}
|
|
211
|
+
async deleteRole(roleId) {
|
|
212
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
213
|
+
const url = `${this.baseUrl}/api/admin/roles/${roleId}`;
|
|
214
|
+
(0, log_1.logRequest)("DELETE", url, this.headers);
|
|
215
|
+
const response = await fetch(url, {
|
|
216
|
+
method: "DELETE",
|
|
217
|
+
headers: this.headers,
|
|
218
|
+
});
|
|
219
|
+
if (!response.ok)
|
|
220
|
+
await this.handleErrorResponse(response);
|
|
221
|
+
return (await response.json());
|
|
222
|
+
}
|
|
223
|
+
// ==================== 数据库表管理 ====================
|
|
224
|
+
async listTables() {
|
|
225
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
226
|
+
const url = `${this.baseUrl}/api/admin/database/tables`;
|
|
227
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
228
|
+
const response = await fetch(url, { headers: this.headers });
|
|
229
|
+
if (!response.ok)
|
|
230
|
+
await this.handleErrorResponse(response);
|
|
231
|
+
return (await response.json());
|
|
232
|
+
}
|
|
233
|
+
async getTableSchema(tableName) {
|
|
234
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
235
|
+
const url = `${this.baseUrl}/api/admin/database/tables/${tableName}/schema`;
|
|
236
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
237
|
+
const response = await fetch(url, { headers: this.headers });
|
|
238
|
+
if (!response.ok)
|
|
239
|
+
await this.handleErrorResponse(response);
|
|
240
|
+
return (await response.json());
|
|
241
|
+
}
|
|
242
|
+
async getTableData(tableName, options = {}) {
|
|
243
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
244
|
+
const url = this.buildUrl(`/api/admin/database/tables/${tableName}/data`, {
|
|
245
|
+
page: options.page,
|
|
246
|
+
page_size: options.pageSize,
|
|
247
|
+
search: options.search,
|
|
248
|
+
sort_by: options.sortBy,
|
|
249
|
+
sort_order: options.sortOrder,
|
|
250
|
+
});
|
|
251
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
252
|
+
const response = await fetch(url, { headers: this.headers });
|
|
253
|
+
if (!response.ok)
|
|
254
|
+
await this.handleErrorResponse(response);
|
|
255
|
+
return (await response.json());
|
|
256
|
+
}
|
|
257
|
+
async insertRow(tableName, data) {
|
|
258
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
259
|
+
const url = `${this.baseUrl}/api/admin/database/tables/${tableName}/data`;
|
|
260
|
+
(0, log_1.logRequest)("POST", url, this.headers);
|
|
261
|
+
const response = await fetch(url, {
|
|
262
|
+
method: "POST",
|
|
263
|
+
headers: this.headers,
|
|
264
|
+
body: JSON.stringify(data),
|
|
265
|
+
});
|
|
266
|
+
if (!response.ok)
|
|
267
|
+
await this.handleErrorResponse(response);
|
|
268
|
+
return (await response.json());
|
|
269
|
+
}
|
|
270
|
+
async updateRow(tableName, primaryKey, data) {
|
|
271
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
272
|
+
const url = `${this.baseUrl}/api/admin/database/tables/${tableName}/data`;
|
|
273
|
+
(0, log_1.logRequest)("PUT", url, this.headers);
|
|
274
|
+
const response = await fetch(url, {
|
|
275
|
+
method: "PUT",
|
|
276
|
+
headers: this.headers,
|
|
277
|
+
body: JSON.stringify({ primary_key: primaryKey, data }),
|
|
278
|
+
});
|
|
279
|
+
if (!response.ok)
|
|
280
|
+
await this.handleErrorResponse(response);
|
|
281
|
+
return (await response.json());
|
|
282
|
+
}
|
|
283
|
+
async deleteRow(tableName, primaryKey) {
|
|
284
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
285
|
+
const url = `${this.baseUrl}/api/admin/database/tables/${tableName}/data`;
|
|
286
|
+
(0, log_1.logRequest)("DELETE", url, this.headers);
|
|
287
|
+
const response = await fetch(url, {
|
|
288
|
+
method: "DELETE",
|
|
289
|
+
headers: this.headers,
|
|
290
|
+
body: JSON.stringify({ primary_key: primaryKey }),
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok)
|
|
293
|
+
await this.handleErrorResponse(response);
|
|
294
|
+
return (await response.json());
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.AdminClient = AdminClient;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome Extension Client
|
|
3
|
+
* Chrome 插件管理客户端
|
|
4
|
+
*/
|
|
5
|
+
export interface ChromeExtensionClientConfig {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface ChromeExtensionInfo {
|
|
11
|
+
extension_id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
author?: string;
|
|
15
|
+
version: string;
|
|
16
|
+
user_id?: number;
|
|
17
|
+
created_at?: string;
|
|
18
|
+
updated_at?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ChromeExtensionListResponse {
|
|
21
|
+
items: ChromeExtensionInfo[];
|
|
22
|
+
total: number;
|
|
23
|
+
page: number;
|
|
24
|
+
page_size: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ListChromeExtensionsOptions {
|
|
27
|
+
page?: number;
|
|
28
|
+
pageSize?: number;
|
|
29
|
+
name?: string;
|
|
30
|
+
extensionId?: string;
|
|
31
|
+
author?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CreateChromeExtensionData {
|
|
34
|
+
extensionId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
author?: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
extensionZip?: File | Blob;
|
|
40
|
+
}
|
|
41
|
+
export declare class ChromeExtensionClient {
|
|
42
|
+
private baseUrl;
|
|
43
|
+
private headers;
|
|
44
|
+
constructor(config?: ChromeExtensionClientConfig);
|
|
45
|
+
private handleErrorResponse;
|
|
46
|
+
private buildUrl;
|
|
47
|
+
list(options?: ListChromeExtensionsOptions): Promise<ChromeExtensionListResponse>;
|
|
48
|
+
get(extensionId: string): Promise<ChromeExtensionInfo>;
|
|
49
|
+
create(data: CreateChromeExtensionData): Promise<ChromeExtensionInfo>;
|
|
50
|
+
delete(extensionId: string): Promise<{
|
|
51
|
+
message: string;
|
|
52
|
+
}>;
|
|
53
|
+
download(extensionId: string): Promise<Blob>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chrome Extension Client
|
|
4
|
+
* Chrome 插件管理客户端
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ChromeExtensionClient = void 0;
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const log_1 = require("./log");
|
|
10
|
+
class ChromeExtensionClient {
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
this.baseUrl =
|
|
13
|
+
config.baseUrl ||
|
|
14
|
+
config_1.sdkConfig.getServerUrl() ||
|
|
15
|
+
(typeof window !== "undefined" ? window.location.origin : "");
|
|
16
|
+
const globalHeaders = config_1.sdkConfig.getHeaders();
|
|
17
|
+
const globalToken = config.token || config_1.sdkConfig.getToken();
|
|
18
|
+
this.headers = {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
...globalHeaders,
|
|
21
|
+
...config.headers,
|
|
22
|
+
};
|
|
23
|
+
if (globalToken) {
|
|
24
|
+
this.headers["Authorization"] = `Bearer ${globalToken}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async handleErrorResponse(response) {
|
|
28
|
+
let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
|
|
29
|
+
try {
|
|
30
|
+
const errorText = await response.text();
|
|
31
|
+
const errorJson = JSON.parse(errorText);
|
|
32
|
+
errorMessage = errorJson.detail || errorMessage;
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
throw new Error(errorMessage);
|
|
36
|
+
}
|
|
37
|
+
buildUrl(path, params) {
|
|
38
|
+
const url = `${this.baseUrl}${path}`;
|
|
39
|
+
if (!params)
|
|
40
|
+
return url;
|
|
41
|
+
const sp = new URLSearchParams();
|
|
42
|
+
for (const [k, v] of Object.entries(params)) {
|
|
43
|
+
if (v !== undefined && v !== null)
|
|
44
|
+
sp.append(k, String(v));
|
|
45
|
+
}
|
|
46
|
+
const qs = sp.toString();
|
|
47
|
+
return qs ? `${url}?${qs}` : url;
|
|
48
|
+
}
|
|
49
|
+
async list(options = {}) {
|
|
50
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
51
|
+
const url = this.buildUrl("/api/chrome-extensions/", {
|
|
52
|
+
page: options.page,
|
|
53
|
+
page_size: options.pageSize,
|
|
54
|
+
name: options.name,
|
|
55
|
+
extension_id: options.extensionId,
|
|
56
|
+
author: options.author,
|
|
57
|
+
});
|
|
58
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
59
|
+
const response = await fetch(url, { headers: this.headers });
|
|
60
|
+
if (!response.ok)
|
|
61
|
+
await this.handleErrorResponse(response);
|
|
62
|
+
const result = (await response.json());
|
|
63
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
async get(extensionId) {
|
|
67
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
68
|
+
const url = `${this.baseUrl}/api/chrome-extensions/${extensionId}`;
|
|
69
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
70
|
+
const response = await fetch(url, { headers: this.headers });
|
|
71
|
+
if (!response.ok)
|
|
72
|
+
await this.handleErrorResponse(response);
|
|
73
|
+
const result = (await response.json());
|
|
74
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
async create(data) {
|
|
78
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
79
|
+
const url = `${this.baseUrl}/api/chrome-extensions/create`;
|
|
80
|
+
const formData = new FormData();
|
|
81
|
+
formData.append("extension_id", data.extensionId);
|
|
82
|
+
formData.append("name", data.name);
|
|
83
|
+
formData.append("description", data.description);
|
|
84
|
+
if (data.author)
|
|
85
|
+
formData.append("author", data.author);
|
|
86
|
+
if (data.version)
|
|
87
|
+
formData.append("version", data.version);
|
|
88
|
+
if (data.extensionZip)
|
|
89
|
+
formData.append("extension_zip", data.extensionZip);
|
|
90
|
+
const uploadHeaders = { ...this.headers };
|
|
91
|
+
delete uploadHeaders["Content-Type"];
|
|
92
|
+
(0, log_1.logRequest)("POST", url, uploadHeaders);
|
|
93
|
+
const response = await fetch(url, {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: uploadHeaders,
|
|
96
|
+
body: formData,
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok)
|
|
99
|
+
await this.handleErrorResponse(response);
|
|
100
|
+
return (await response.json());
|
|
101
|
+
}
|
|
102
|
+
async delete(extensionId) {
|
|
103
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
104
|
+
const url = `${this.baseUrl}/api/chrome-extensions/${extensionId}`;
|
|
105
|
+
(0, log_1.logRequest)("DELETE", url, this.headers);
|
|
106
|
+
const response = await fetch(url, {
|
|
107
|
+
method: "DELETE",
|
|
108
|
+
headers: this.headers,
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok)
|
|
111
|
+
await this.handleErrorResponse(response);
|
|
112
|
+
return (await response.json());
|
|
113
|
+
}
|
|
114
|
+
async download(extensionId) {
|
|
115
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
116
|
+
const url = `${this.baseUrl}/api/chrome-extensions/${extensionId}/download`;
|
|
117
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
118
|
+
const response = await fetch(url, { headers: this.headers });
|
|
119
|
+
if (!response.ok)
|
|
120
|
+
await this.handleErrorResponse(response);
|
|
121
|
+
return await response.blob();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.ChromeExtensionClient = ChromeExtensionClient;
|
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.6";
|
|
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.6";
|
|
38
|
+
readonly sdkVersion = "1.3.6";
|
|
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.6";
|
|
11
11
|
/**
|
|
12
12
|
* SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
|
|
13
13
|
* 格式: AI_WORLD_SDK_V:版本号
|
|
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.3.5";
|
|
|
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.6";
|
|
19
19
|
/**
|
|
20
20
|
* 版本兼容性错误
|
|
21
21
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export { ResourceClient, type ResourceClientConfig, type ResourceInfo, type Acce
|
|
|
33
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
|
+
export { AdminClient, type AdminClientConfig, type AdminUserInfo, type AdminUserListResponse, type ListUsersOptions, type RoleInfo, type CreateRoleData, type UpdateRoleData, type RoleUserCount, type TableColumn, type TableDataResponse, type ListTableDataOptions, } from "./admin";
|
|
37
|
+
export { PluginManagementClient, type PluginManagementClientConfig, type PluginInfo, type PluginListResponse, type ListPluginsOptions, type CreatePluginData, type PluginStatus, type PluginTemplateInfo, type PluginTemplateListResponse, type ListPluginTemplatesOptions, type CreatePluginTemplateData, type UpdatePluginTemplateData, } from "./plugin-management";
|
|
38
|
+
export { StatsClient, DashboardClient, type StatsClientConfig, type AiApiCallsOptions, type AiApiCallsTrendOptions, type AiApiCallsTrendByUserOptions, type PluginAccessOptions, } from "./stats";
|
|
39
|
+
export { SharedResourceClient, type SharedResourceClientConfig, type SharedResourceInfo, type SharedResourceListResponse, type ListSharedResourceOptions, type UpdateSharedResourceData, } from "./shared-resource";
|
|
40
|
+
export { ChromeExtensionClient, type ChromeExtensionClientConfig, type ChromeExtensionInfo, type ChromeExtensionListResponse, type ListChromeExtensionsOptions, type CreateChromeExtensionData, } from "./chrome-extension";
|
|
36
41
|
export { sdkConfig, VersionCompatibilityError, SDK_SIGNATURE, type AuthenticatedUser } from "./config";
|
|
37
42
|
/**
|
|
38
43
|
* Create a chat model instance based on model name
|
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.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;
|
|
23
|
+
exports.SDK_SIGNATURE = exports.VersionCompatibilityError = exports.sdkConfig = exports.ChromeExtensionClient = exports.SharedResourceClient = exports.DashboardClient = exports.StatsClient = exports.PluginManagementClient = exports.AdminClient = 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");
|
|
@@ -66,6 +66,22 @@ Object.defineProperty(exports, "VersionedResourceClient", { enumerable: true, ge
|
|
|
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; } });
|
|
69
|
+
// Export admin client
|
|
70
|
+
var admin_1 = require("./admin");
|
|
71
|
+
Object.defineProperty(exports, "AdminClient", { enumerable: true, get: function () { return admin_1.AdminClient; } });
|
|
72
|
+
// Export plugin management client
|
|
73
|
+
var plugin_management_1 = require("./plugin-management");
|
|
74
|
+
Object.defineProperty(exports, "PluginManagementClient", { enumerable: true, get: function () { return plugin_management_1.PluginManagementClient; } });
|
|
75
|
+
// Export stats & dashboard clients
|
|
76
|
+
var stats_1 = require("./stats");
|
|
77
|
+
Object.defineProperty(exports, "StatsClient", { enumerable: true, get: function () { return stats_1.StatsClient; } });
|
|
78
|
+
Object.defineProperty(exports, "DashboardClient", { enumerable: true, get: function () { return stats_1.DashboardClient; } });
|
|
79
|
+
// Export shared resource client
|
|
80
|
+
var shared_resource_1 = require("./shared-resource");
|
|
81
|
+
Object.defineProperty(exports, "SharedResourceClient", { enumerable: true, get: function () { return shared_resource_1.SharedResourceClient; } });
|
|
82
|
+
// Export chrome extension client
|
|
83
|
+
var chrome_extension_1 = require("./chrome-extension");
|
|
84
|
+
Object.defineProperty(exports, "ChromeExtensionClient", { enumerable: true, get: function () { return chrome_extension_1.ChromeExtensionClient; } });
|
|
69
85
|
// Export global configuration
|
|
70
86
|
var config_2 = require("./config");
|
|
71
87
|
Object.defineProperty(exports, "sdkConfig", { enumerable: true, get: function () { return config_2.sdkConfig; } });
|