@chatu-ai/builder-sdk 0.5.0 → 0.6.1
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 +81 -2
- package/dist/client.js +23 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -32,10 +32,13 @@ export interface BuilderClientOptions {
|
|
|
32
32
|
export interface SandboxStatus {
|
|
33
33
|
state: SandboxState;
|
|
34
34
|
previewUrl?: string;
|
|
35
|
+
/** dev server:running 且 !ready = 首屏编译中(1c 机型冷启动可能 1–2 分钟) */
|
|
35
36
|
devServer?: {
|
|
36
37
|
running: boolean;
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
ready?: boolean;
|
|
39
|
+
startingForMs?: number | null;
|
|
40
|
+
lastError?: string | null;
|
|
41
|
+
} | null;
|
|
39
42
|
}
|
|
40
43
|
export interface VersionInfo {
|
|
41
44
|
sha: string;
|
|
@@ -207,6 +210,76 @@ export interface BuilderClient {
|
|
|
207
210
|
}>;
|
|
208
211
|
/** 本月用量:dev/prod 原始计量与折算点数估算、只读状态、单价 */
|
|
209
212
|
usage(conversationId: string): Promise<DataUsage>;
|
|
213
|
+
/** 资源面板:KV 浏览/编辑(经服务端代理,用户鉴权) */
|
|
214
|
+
kv: {
|
|
215
|
+
list(conversationId: string, opts?: {
|
|
216
|
+
env?: 'dev' | 'prod';
|
|
217
|
+
prefix?: string;
|
|
218
|
+
cursor?: string | null;
|
|
219
|
+
limit?: number;
|
|
220
|
+
}): Promise<{
|
|
221
|
+
ok: boolean;
|
|
222
|
+
keys: string[];
|
|
223
|
+
nextCursor: string | null;
|
|
224
|
+
}>;
|
|
225
|
+
get(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
226
|
+
ok: boolean;
|
|
227
|
+
key: string;
|
|
228
|
+
value: unknown;
|
|
229
|
+
exists: boolean;
|
|
230
|
+
ttl?: number | null;
|
|
231
|
+
}>;
|
|
232
|
+
set(conversationId: string, key: string, value: unknown, opts?: {
|
|
233
|
+
env?: 'dev' | 'prod';
|
|
234
|
+
ex?: number;
|
|
235
|
+
}): Promise<{
|
|
236
|
+
ok: boolean;
|
|
237
|
+
}>;
|
|
238
|
+
remove(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
239
|
+
ok: boolean;
|
|
240
|
+
removed?: boolean;
|
|
241
|
+
}>;
|
|
242
|
+
};
|
|
243
|
+
/** 资源面板:对象存储浏览 */
|
|
244
|
+
storage: {
|
|
245
|
+
list(conversationId: string, opts?: {
|
|
246
|
+
env?: 'dev' | 'prod';
|
|
247
|
+
prefix?: string;
|
|
248
|
+
cursor?: string | null;
|
|
249
|
+
limit?: number;
|
|
250
|
+
}): Promise<{
|
|
251
|
+
ok: boolean;
|
|
252
|
+
items: Array<{
|
|
253
|
+
key: string;
|
|
254
|
+
size: number;
|
|
255
|
+
lastModified?: string | null;
|
|
256
|
+
}>;
|
|
257
|
+
nextCursor: string | null;
|
|
258
|
+
}>;
|
|
259
|
+
sign(conversationId: string, key: string, opts?: {
|
|
260
|
+
env?: 'dev' | 'prod';
|
|
261
|
+
expiresIn?: number;
|
|
262
|
+
downloadName?: string;
|
|
263
|
+
}): Promise<{
|
|
264
|
+
ok: boolean;
|
|
265
|
+
url: string;
|
|
266
|
+
}>;
|
|
267
|
+
uploadUrl(conversationId: string, key: string, opts?: {
|
|
268
|
+
env?: 'dev' | 'prod';
|
|
269
|
+
contentType?: string;
|
|
270
|
+
size?: number;
|
|
271
|
+
}): Promise<{
|
|
272
|
+
ok: boolean;
|
|
273
|
+
url: string;
|
|
274
|
+
method: 'PUT';
|
|
275
|
+
headers?: {
|
|
276
|
+
contentType?: string;
|
|
277
|
+
} | null;
|
|
278
|
+
}>;
|
|
279
|
+
remove(conversationId: string, key: string, env?: 'dev' | 'prod'): Promise<{
|
|
280
|
+
ok: boolean;
|
|
281
|
+
}>;
|
|
282
|
+
};
|
|
210
283
|
/** 复制命名空间(默认 dev→prod) */
|
|
211
284
|
promote(conversationId: string, input?: {
|
|
212
285
|
from?: 'dev' | 'prod';
|
|
@@ -243,6 +316,12 @@ export interface BuilderClient {
|
|
|
243
316
|
}>;
|
|
244
317
|
}>;
|
|
245
318
|
};
|
|
319
|
+
logs: {
|
|
320
|
+
/** dev server 最近日志(沙箱未运行返回空) */
|
|
321
|
+
tail(conversationId: string, lines?: number): Promise<{
|
|
322
|
+
lines: string[];
|
|
323
|
+
}>;
|
|
324
|
+
};
|
|
246
325
|
export: {
|
|
247
326
|
/**
|
|
248
327
|
* 导出应用源码 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
|
}
|