@chatu-ai/builder-sdk 0.4.1 → 0.6.0
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/client.d.ts +76 -0
- package/dist/client.js +23 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -207,6 +207,76 @@ export interface BuilderClient {
|
|
|
207
207
|
}>;
|
|
208
208
|
/** 本月用量:dev/prod 原始计量与折算点数估算、只读状态、单价 */
|
|
209
209
|
usage(conversationId: string): Promise<DataUsage>;
|
|
210
|
+
/** 资源面板:KV 浏览/编辑(经服务端代理,用户鉴权) */
|
|
211
|
+
kv: {
|
|
212
|
+
list(conversationId: string, opts?: {
|
|
213
|
+
env?: 'dev' | 'prod';
|
|
214
|
+
prefix?: string;
|
|
215
|
+
cursor?: string | null;
|
|
216
|
+
limit?: number;
|
|
217
|
+
}): Promise<{
|
|
218
|
+
ok: boolean;
|
|
219
|
+
keys: string[];
|
|
220
|
+
nextCursor: string | null;
|
|
221
|
+
}>;
|
|
222
|
+
get(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
223
|
+
ok: boolean;
|
|
224
|
+
key: string;
|
|
225
|
+
value: unknown;
|
|
226
|
+
exists: boolean;
|
|
227
|
+
ttl?: number | null;
|
|
228
|
+
}>;
|
|
229
|
+
set(conversationId: string, key: string, value: unknown, opts?: {
|
|
230
|
+
env?: 'dev' | 'prod';
|
|
231
|
+
ex?: number;
|
|
232
|
+
}): Promise<{
|
|
233
|
+
ok: boolean;
|
|
234
|
+
}>;
|
|
235
|
+
remove(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
236
|
+
ok: boolean;
|
|
237
|
+
removed?: boolean;
|
|
238
|
+
}>;
|
|
239
|
+
};
|
|
240
|
+
/** 资源面板:对象存储浏览 */
|
|
241
|
+
storage: {
|
|
242
|
+
list(conversationId: string, opts?: {
|
|
243
|
+
env?: 'dev' | 'prod';
|
|
244
|
+
prefix?: string;
|
|
245
|
+
cursor?: string | null;
|
|
246
|
+
limit?: number;
|
|
247
|
+
}): Promise<{
|
|
248
|
+
ok: boolean;
|
|
249
|
+
items: Array<{
|
|
250
|
+
key: string;
|
|
251
|
+
size: number;
|
|
252
|
+
lastModified?: string | null;
|
|
253
|
+
}>;
|
|
254
|
+
nextCursor: string | null;
|
|
255
|
+
}>;
|
|
256
|
+
sign(conversationId: string, key: string, opts?: {
|
|
257
|
+
env?: 'dev' | 'prod';
|
|
258
|
+
expiresIn?: number;
|
|
259
|
+
downloadName?: string;
|
|
260
|
+
}): Promise<{
|
|
261
|
+
ok: boolean;
|
|
262
|
+
url: string;
|
|
263
|
+
}>;
|
|
264
|
+
uploadUrl(conversationId: string, key: string, opts?: {
|
|
265
|
+
env?: 'dev' | 'prod';
|
|
266
|
+
contentType?: string;
|
|
267
|
+
size?: number;
|
|
268
|
+
}): Promise<{
|
|
269
|
+
ok: boolean;
|
|
270
|
+
url: string;
|
|
271
|
+
method: 'PUT';
|
|
272
|
+
headers?: {
|
|
273
|
+
contentType?: string;
|
|
274
|
+
} | null;
|
|
275
|
+
}>;
|
|
276
|
+
remove(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
277
|
+
ok: boolean;
|
|
278
|
+
}>;
|
|
279
|
+
};
|
|
210
280
|
/** 复制命名空间(默认 dev→prod) */
|
|
211
281
|
promote(conversationId: string, input?: {
|
|
212
282
|
from?: 'dev' | 'prod';
|
|
@@ -243,6 +313,12 @@ export interface BuilderClient {
|
|
|
243
313
|
}>;
|
|
244
314
|
}>;
|
|
245
315
|
};
|
|
316
|
+
logs: {
|
|
317
|
+
/** dev server 最近日志(沙箱未运行返回空) */
|
|
318
|
+
tail(conversationId: string, lines?: number): Promise<{
|
|
319
|
+
lines: string[];
|
|
320
|
+
}>;
|
|
321
|
+
};
|
|
246
322
|
export: {
|
|
247
323
|
/**
|
|
248
324
|
* 导出应用源码 ZIP(含 Dockerfile/DEPLOY.md)。沙箱未运行时服务端返回 409 SANDBOX_NOT_RUNNING —— 调用方先 sandbox.wake()。
|
package/dist/client.js
CHANGED
|
@@ -90,9 +90,27 @@ export function createBuilderClient(options) {
|
|
|
90
90
|
data: {
|
|
91
91
|
access: id => req(`/${id}/data-access`),
|
|
92
92
|
usage: id => req(`/${id}/data-usage`),
|
|
93
|
+
kv: {
|
|
94
|
+
list: (id, o) => req(`/${id}/data/kv?${qs({ env: o?.env, prefix: o?.prefix, cursor: o?.cursor ?? undefined, limit: o?.limit })}`),
|
|
95
|
+
get: (id, key, env) => req(`/${id}/data/kv/${encPath(key)}?${qs({ env })}`),
|
|
96
|
+
set: (id, key, value, o) => req(`/${id}/data/kv/${encPath(key)}?${qs({ env: o?.env })}`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ value, ex: o?.ex }) }),
|
|
97
|
+
remove: (id, key, env) => req(`/${id}/data/kv/${encPath(key)}?${qs({ env })}`, { method: 'DELETE' }),
|
|
98
|
+
},
|
|
99
|
+
storage: {
|
|
100
|
+
list: (id, o) => req(`/${id}/data/storage?${qs({ env: o?.env, prefix: o?.prefix, cursor: o?.cursor ?? undefined, limit: o?.limit })}`),
|
|
101
|
+
sign: (id, key, o) => req(`/${id}/data/storage/sign?${qs({ env: o?.env })}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ key, expiresIn: o?.expiresIn, downloadName: o?.downloadName }) }),
|
|
102
|
+
uploadUrl: (id, key, o) => req(`/${id}/data/storage/upload-url?${qs({ env: o?.env })}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ key, contentType: o?.contentType, size: o?.size }) }),
|
|
103
|
+
remove: (id, key, env) => req(`/${id}/data/storage/${encPath(key)}?${qs({ env })}`, { method: 'DELETE' }),
|
|
104
|
+
},
|
|
93
105
|
promote: (id, input) => req(`/${id}/data/promote`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input ?? {}) }),
|
|
94
106
|
export: (id, env) => req(`/${id}/data/export?env=${env ?? 'prod'}`),
|
|
95
107
|
},
|
|
108
|
+
logs: {
|
|
109
|
+
tail: async (id, lines) => {
|
|
110
|
+
const r = await req(`/${id}/logs?tail=${lines ?? 200}`);
|
|
111
|
+
return { lines: Array.isArray(r) ? r : (r.lines ?? []) };
|
|
112
|
+
},
|
|
113
|
+
},
|
|
96
114
|
export: {
|
|
97
115
|
zip: async (id) => {
|
|
98
116
|
const res = await doFetch(`${restBase}/${id}/export/zip`, auth.apply({}));
|
|
@@ -126,10 +144,13 @@ export class BuilderApiError extends Error {
|
|
|
126
144
|
this.status = status;
|
|
127
145
|
}
|
|
128
146
|
}
|
|
147
|
+
function encPath(key) {
|
|
148
|
+
return key.split('/').map(encodeURIComponent).join('/');
|
|
149
|
+
}
|
|
129
150
|
function qs(obj) {
|
|
130
151
|
const p = new URLSearchParams();
|
|
131
152
|
for (const [k, v] of Object.entries(obj ?? {}))
|
|
132
|
-
if (v !== undefined)
|
|
133
|
-
p.set(k, v);
|
|
153
|
+
if (v !== undefined && v !== null)
|
|
154
|
+
p.set(k, String(v));
|
|
134
155
|
return p.toString();
|
|
135
156
|
}
|