@chatu-ai/builder-sdk 0.7.1 → 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 +14 -0
- package/dist/client.js +49 -0
- package/package.json +1 -1
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[];
|
|
@@ -215,6 +225,10 @@ export interface BuilderClient {
|
|
|
215
225
|
pushGit(conversationId: string, input: GitPushInput): Promise<GitPushResult>;
|
|
216
226
|
/** 一键部署(P1:EdgeOne Pages);沙箱未运行时 ok=false, error='SANDBOX_NOT_RUNNING' */
|
|
217
227
|
deploy(conversationId: string, input: DeployInput): Promise<DeployResult>;
|
|
228
|
+
/** 一键部署(流式进度):逐条产出 log 行,最后一条为 result */
|
|
229
|
+
deployStream(conversationId: string, input: DeployInput, opts?: {
|
|
230
|
+
signal?: AbortSignal;
|
|
231
|
+
}): AsyncIterable<DeployStreamEvent>;
|
|
218
232
|
};
|
|
219
233
|
/** 平台数据能力接入信息(技术方案 15):线上部署所需环境变量;apiKey 为服务端密钥 */
|
|
220
234
|
data: {
|
package/dist/client.js
CHANGED
|
@@ -94,6 +94,7 @@ export function createBuilderClient(options) {
|
|
|
94
94
|
saveSetting: (id, input) => req(`/${id}/deploy-settings`, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }),
|
|
95
95
|
pushGit: (id, input) => req(`/${id}/export/git`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(input) }),
|
|
96
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),
|
|
97
98
|
},
|
|
98
99
|
data: {
|
|
99
100
|
access: id => req(`/${id}/data-access`),
|
|
@@ -152,6 +153,54 @@ export class BuilderApiError extends Error {
|
|
|
152
153
|
this.status = status;
|
|
153
154
|
}
|
|
154
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
|
+
}
|
|
155
204
|
function encPath(key) {
|
|
156
205
|
return key.split('/').map(encodeURIComponent).join('/');
|
|
157
206
|
}
|