@chatu-ai/builder-sdk 0.7.0 → 0.7.2

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 CHANGED
@@ -110,9 +110,18 @@ export interface DataUsage {
110
110
  rates?: Record<string, number>;
111
111
  error?: string;
112
112
  }
113
+ export type DeployStreamEvent = {
114
+ type: 'log';
115
+ line: string;
116
+ } | {
117
+ type: 'result';
118
+ result: DeployResult;
119
+ };
113
120
  export interface DeployInput {
114
121
  provider: 'edgeone';
115
122
  projectName: string;
123
+ /** EdgeOne 部署区域:global(默认,含中国大陆可用)| overseas */
124
+ area?: 'global' | 'overseas';
116
125
  credentialId?: string;
117
126
  token?: string;
118
127
  save?: boolean;
@@ -128,6 +137,7 @@ export interface DeployResult {
128
137
  projectName?: string;
129
138
  env?: string;
130
139
  url?: string;
140
+ consoleUrl?: string;
131
141
  output?: string;
132
142
  envVarsApplied?: number;
133
143
  envVarsFailed?: string[];
@@ -157,6 +167,15 @@ export interface BuilderClient {
157
167
  }>;
158
168
  /** 唤醒/确保沙箱(休眠 → 恢复快照 → 起 dev server;不发起 agent 会话) */
159
169
  wake(conversationId: string): Promise<SandboxStatus>;
170
+ /** 生成预览分享链接(非所有者可看;沙箱需在运行);默认 24h,最长 7 天 */
171
+ share(conversationId: string, ttlHours?: number): Promise<{
172
+ url: string;
173
+ token: string;
174
+ expiresAt: string;
175
+ }>;
176
+ revokeShare(conversationId: string, token: string): Promise<{
177
+ ok: boolean;
178
+ }>;
160
179
  };
161
180
  versions: {
162
181
  list(conversationId: string, opts?: {
@@ -206,6 +225,10 @@ export interface BuilderClient {
206
225
  pushGit(conversationId: string, input: GitPushInput): Promise<GitPushResult>;
207
226
  /** 一键部署(P1:EdgeOne Pages);沙箱未运行时 ok=false, error='SANDBOX_NOT_RUNNING' */
208
227
  deploy(conversationId: string, input: DeployInput): Promise<DeployResult>;
228
+ /** 一键部署(流式进度):逐条产出 log 行,最后一条为 result */
229
+ deployStream(conversationId: string, input: DeployInput, opts?: {
230
+ signal?: AbortSignal;
231
+ }): AsyncIterable<DeployStreamEvent>;
209
232
  };
210
233
  /** 平台数据能力接入信息(技术方案 15):线上部署所需环境变量;apiKey 为服务端密钥 */
211
234
  data: {
package/dist/client.js CHANGED
@@ -58,6 +58,8 @@ export function createBuilderClient(options) {
58
58
  }),
59
59
  previewToken: id => req(`/${id}/preview-token`),
60
60
  wake: id => req(`/sandbox/${id}/wake`, { method: 'POST' }),
61
+ share: (id, ttlHours) => req(`/${id}/preview-share`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ ttlHours }) }),
62
+ revokeShare: (id, token) => req(`/${id}/preview-share/revoke`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ token }) }),
61
63
  },
62
64
  versions: {
63
65
  // 服务端形状:{ versions: VersionInfo[] }(runtime 透传)
@@ -92,6 +94,7 @@ export function createBuilderClient(options) {
92
94
  saveSetting: (id, input) => req(`/${id}/deploy-settings`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }),
93
95
  pushGit: (id, input) => req(`/${id}/export/git`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }),
94
96
  deploy: (id, input) => req(`/${id}/export/deploy`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }),
97
+ deployStream: (id, input, o) => readNamedSse(`${restBase}/${id}/export/deploy/stream`, auth.apply({ method: 'POST', headers: { 'content-type': 'application/json', accept: 'text/event-stream' }, body: JSON.stringify(input), signal: o?.signal }), doFetch),
95
98
  },
96
99
  data: {
97
100
  access: id => req(`/${id}/data-access`),
@@ -150,6 +153,54 @@ export class BuilderApiError extends Error {
150
153
  this.status = status;
151
154
  }
152
155
  }
156
+ /** 读取带 event: 名的 SSE(log / result) */
157
+ async function* readNamedSse(url, init, doFetch) {
158
+ const res = await doFetch(url, init);
159
+ if (!res.ok || !res.body)
160
+ throw new BuilderApiError(res.status, await res.text().catch(() => ''));
161
+ const reader = res.body.getReader();
162
+ const decoder = new TextDecoder();
163
+ let buffer = '';
164
+ let eventName = '';
165
+ try {
166
+ for (;;) {
167
+ const { value, done } = await reader.read();
168
+ if (done)
169
+ break;
170
+ buffer += decoder.decode(value, { stream: true });
171
+ let nl;
172
+ while ((nl = buffer.indexOf('\n')) >= 0) {
173
+ const line = buffer.slice(0, nl).replace(/\r$/, '');
174
+ buffer = buffer.slice(nl + 1);
175
+ if (line.startsWith('event:')) {
176
+ eventName = line.slice(6).trim();
177
+ continue;
178
+ }
179
+ if (!line.startsWith('data:')) {
180
+ if (line === '')
181
+ eventName = eventName;
182
+ continue;
183
+ }
184
+ const data = line.slice(5).trim();
185
+ if (!data)
186
+ continue;
187
+ let payload = data;
188
+ try {
189
+ payload = JSON.parse(data);
190
+ }
191
+ catch { /* raw */ }
192
+ if (eventName === 'log')
193
+ yield { type: 'log', line: String(payload?.line ?? payload) };
194
+ else if (eventName === 'result')
195
+ yield { type: 'result', result: payload };
196
+ eventName = '';
197
+ }
198
+ }
199
+ }
200
+ finally {
201
+ reader.releaseLock();
202
+ }
203
+ }
153
204
  function encPath(key) {
154
205
  return key.split('/').map(encodeURIComponent).join('/');
155
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatu-ai/builder-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "ChatU Builder client SDK core: REST + streaming client, zod event schemas, seq resume",
5
5
  "license": "MIT",
6
6
  "type": "module",