@qfei-design/make-ai-assistant 0.2.10 → 0.2.12
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/PUBLIC_API.md +2 -2
- package/README.md +5 -6
- package/dist/make-app.cjs +1 -1
- package/dist/make-app.d.ts +1 -1
- package/dist/make-app.mjs +418 -416
- package/dist/react/conversation-controls.d.ts +6 -1
- package/dist/react/use-attachments.d.ts +8 -1
- package/dist/react.cjs +4 -4
- package/dist/react.mjs +1437 -1399
- package/dist/styles.css +363 -113
- package/docs/make-app-integration.md +4 -4
- package/examples/make-app/README.md +1 -1
- package/package.json +1 -1
package/dist/make-app.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { p as w, a as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
import { p as w, a as B, b as g, d as b, e as v, f as R, g as H, h as j, i as P, j as $, k as K, l as O, m as J } from "./conversation-CZfbgCXd.js";
|
|
2
|
+
const M = (s) => {
|
|
3
|
+
const n = g(s, 36);
|
|
4
4
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
5
|
-
|
|
5
|
+
n
|
|
6
6
|
))
|
|
7
7
|
throw new Error("Invalid Make App request: UUID");
|
|
8
|
-
return
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
if (new TextEncoder().encode(
|
|
8
|
+
return n;
|
|
9
|
+
}, D = (s) => {
|
|
10
|
+
const n = g(s, 512, !0);
|
|
11
|
+
if (new TextEncoder().encode(n).length > 512 || /[\r\n/\\]/.test(n))
|
|
12
12
|
throw new Error("Invalid Make App request: filename");
|
|
13
|
-
return
|
|
14
|
-
},
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
13
|
+
return n;
|
|
14
|
+
}, C = (s, n, a) => {
|
|
15
|
+
const i = b(s);
|
|
16
|
+
if (j(i, [
|
|
17
17
|
"chatId",
|
|
18
18
|
"appKey",
|
|
19
19
|
"agentId",
|
|
@@ -24,177 +24,177 @@ const b = (t) => {
|
|
|
24
24
|
"pinnedAt",
|
|
25
25
|
"createdAt",
|
|
26
26
|
"lastActivityAt"
|
|
27
|
-
]),
|
|
27
|
+
]), i.appKey !== n.appKey || i.agentId !== n.agentId || a && i.chatId !== a || !["active", "deleted"].includes(String(i.status)))
|
|
28
28
|
throw new Error("Invalid Make App response: chat scope");
|
|
29
29
|
return {
|
|
30
|
-
chatId: w(
|
|
31
|
-
appKey:
|
|
32
|
-
agentId:
|
|
33
|
-
title: g(
|
|
34
|
-
status:
|
|
35
|
-
revision:
|
|
36
|
-
pinned:
|
|
37
|
-
pinnedAt:
|
|
38
|
-
createdAt: g(
|
|
39
|
-
lastActivityAt: g(
|
|
30
|
+
chatId: w(i.chatId),
|
|
31
|
+
appKey: n.appKey,
|
|
32
|
+
agentId: n.agentId,
|
|
33
|
+
title: g(i.title, 255, !0),
|
|
34
|
+
status: i.status,
|
|
35
|
+
revision: v(i.revision, 1),
|
|
36
|
+
pinned: P(i.pinned),
|
|
37
|
+
pinnedAt: i.pinnedAt == null ? null : g(i.pinnedAt, 64),
|
|
38
|
+
createdAt: g(i.createdAt, 64),
|
|
39
|
+
lastActivityAt: g(i.lastActivityAt, 64)
|
|
40
40
|
};
|
|
41
|
-
},
|
|
42
|
-
const a =
|
|
43
|
-
(
|
|
41
|
+
}, Q = (s, n) => {
|
|
42
|
+
const a = b(s), i = R(a.chats, 100).map(
|
|
43
|
+
(f) => C(f, n)
|
|
44
44
|
);
|
|
45
|
-
if (new Set(
|
|
45
|
+
if (new Set(i.map((f) => f.chatId)).size !== i.length)
|
|
46
46
|
throw new Error("Invalid Make App response: duplicate chat");
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
47
|
+
const d = g(a.nextCursor, 8192, !0), l = P(a.hasMore);
|
|
48
|
+
if (l !== !!d)
|
|
49
49
|
throw new Error("Invalid Make App response: chat cursor");
|
|
50
|
-
return { chats:
|
|
51
|
-
},
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
50
|
+
return { chats: i, nextCursor: d, hasMore: l };
|
|
51
|
+
}, W = (s, n, a) => {
|
|
52
|
+
const i = b(s), d = v(i.nextCursor, -1), l = P(i.hasMore);
|
|
53
|
+
if (d < a || l && d <= a)
|
|
54
54
|
throw new Error(
|
|
55
55
|
"Invalid Make App response: history cursor did not advance"
|
|
56
56
|
);
|
|
57
|
-
let
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
57
|
+
let f = 0, c = a;
|
|
58
|
+
const h = /* @__PURE__ */ new Set(), u = R(i.messages, 200).map((A) => {
|
|
59
|
+
const p = b(A);
|
|
60
|
+
if (p.role !== "user" && p.role !== "assistant")
|
|
61
61
|
throw new Error("Invalid Make App response: history role");
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
62
|
+
const I = v(p.cursor);
|
|
63
|
+
if (I <= c || I > d)
|
|
64
64
|
throw new Error("Invalid Make App response: history order");
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
65
|
+
c = I;
|
|
66
|
+
const k = p.messageId !== void 0, E = k ? w(p.messageId) : `history-${n}-${I}`;
|
|
67
|
+
if (h.has(E))
|
|
68
68
|
throw new Error("Invalid Make App response: duplicate message");
|
|
69
|
-
|
|
70
|
-
const r = g(
|
|
71
|
-
if (
|
|
69
|
+
h.add(E);
|
|
70
|
+
const r = g(p.text, 1e5, !0);
|
|
71
|
+
if (f += [...r].length, f > 1e6)
|
|
72
72
|
throw new Error("Invalid Make App response: history budget");
|
|
73
73
|
return {
|
|
74
|
-
id:
|
|
75
|
-
role:
|
|
74
|
+
id: E,
|
|
75
|
+
role: p.role,
|
|
76
76
|
content: r,
|
|
77
|
-
persistent:
|
|
78
|
-
cursor:
|
|
79
|
-
createdAt: g(
|
|
80
|
-
...
|
|
81
|
-
...
|
|
82
|
-
...
|
|
77
|
+
persistent: k,
|
|
78
|
+
cursor: I,
|
|
79
|
+
createdAt: g(p.createdAt, 64),
|
|
80
|
+
...p.responseId === void 0 ? {} : { responseId: w(p.responseId) },
|
|
81
|
+
...p.parts === void 0 ? {} : { parts: B(p.parts) },
|
|
82
|
+
...p.feedback === void 0 ? {} : { feedback: $(p.feedback) }
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
|
-
return { threadId:
|
|
86
|
-
},
|
|
87
|
-
const a =
|
|
88
|
-
if (a.chatId !==
|
|
85
|
+
return { threadId: n, messages: u, nextCursor: d, hasMore: l };
|
|
86
|
+
}, U = (s, n) => {
|
|
87
|
+
const a = H(s);
|
|
88
|
+
if (a.chatId !== n.chatId || a.responseId !== n.responseId)
|
|
89
89
|
throw new Error("Invalid Make App response: response scope");
|
|
90
90
|
return a;
|
|
91
|
-
},
|
|
92
|
-
const a =
|
|
93
|
-
if (!["uploading", "ready", "cancelled"].includes(String(a.status)) ||
|
|
91
|
+
}, _ = (s, n) => {
|
|
92
|
+
const a = b(s);
|
|
93
|
+
if (!["uploading", "ready", "cancelled"].includes(String(a.status)) || n && a.id !== n)
|
|
94
94
|
throw new Error("Invalid Make App response: upload");
|
|
95
|
-
const
|
|
96
|
-
(
|
|
95
|
+
const i = v(a.sizeBytes, 0, 64 << 20), d = v(a.partSize, 1 << 20, 1 << 20), l = R(a.completedParts, 64).map(
|
|
96
|
+
(c) => v(c, 0, Math.max(0, Math.ceil(i / d) - 1))
|
|
97
97
|
);
|
|
98
|
-
if (new Set(
|
|
98
|
+
if (new Set(l).size !== l.length)
|
|
99
99
|
throw new Error("Invalid Make App response: repeated upload part");
|
|
100
|
-
const
|
|
100
|
+
const f = {
|
|
101
101
|
id: w(a.id),
|
|
102
102
|
status: a.status,
|
|
103
|
-
name:
|
|
103
|
+
name: D(a.name),
|
|
104
104
|
contentType: g(a.contentType, 256),
|
|
105
|
-
sizeBytes:
|
|
106
|
-
partSize:
|
|
107
|
-
completedParts:
|
|
105
|
+
sizeBytes: i,
|
|
106
|
+
partSize: d,
|
|
107
|
+
completedParts: l
|
|
108
108
|
};
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
109
|
+
if (f.status === "ready") {
|
|
110
|
+
const c = b(a.content);
|
|
111
|
+
if (c.kind !== "reference" || c.sizeBytes !== i || !/^[0-9a-f]{64}$/.test(String(c.digestSha256)))
|
|
112
112
|
throw new Error("Invalid Make App response: content receipt");
|
|
113
|
-
|
|
113
|
+
f.content = {
|
|
114
114
|
kind: "reference",
|
|
115
|
-
contentRef: w(
|
|
116
|
-
sizeBytes:
|
|
117
|
-
digestSha256: String(
|
|
115
|
+
contentRef: w(c.contentRef),
|
|
116
|
+
sizeBytes: i,
|
|
117
|
+
digestSha256: String(c.digestSha256)
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
return
|
|
121
|
-
},
|
|
122
|
-
const
|
|
123
|
-
let
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
127
|
-
const
|
|
128
|
-
for (const
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
120
|
+
return f;
|
|
121
|
+
}, X = (s) => {
|
|
122
|
+
const n = w(s.threadId), a = M(s.message.id);
|
|
123
|
+
let i, d;
|
|
124
|
+
if (s.message.parts !== void 0) {
|
|
125
|
+
const l = B(s.message.parts);
|
|
126
|
+
if (!l.length) throw new Error("Invalid Make App request: empty parts");
|
|
127
|
+
const f = /* @__PURE__ */ new Set();
|
|
128
|
+
for (const c of l) {
|
|
129
|
+
const h = M(c.id);
|
|
130
|
+
if (f.has(h))
|
|
131
131
|
throw new Error("Invalid Make App request: duplicate part");
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
if (!/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(
|
|
132
|
+
if (f.add(h), c.kind !== "text") {
|
|
133
|
+
c.name !== void 0 && D(c.name);
|
|
134
|
+
const u = c.media.contentType;
|
|
135
|
+
if (!/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(u) || c.kind !== "file" && (!u.startsWith(`${c.kind}/`) || u === "image/svg+xml"))
|
|
136
136
|
throw new Error("Invalid Make App request: media type");
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
if (
|
|
139
|
+
if (d = l.filter((c) => c.kind === "text").map((c) => c.text).join(""), !d.trim() && l.every((c) => c.kind === "text"))
|
|
140
140
|
throw new Error("Invalid Make App request: empty input");
|
|
141
|
-
|
|
141
|
+
i = { chatId: n, messageId: a, parts: l };
|
|
142
142
|
} else
|
|
143
|
-
|
|
144
|
-
if (new TextEncoder().encode(
|
|
143
|
+
d = g(s.message.content, 8192), i = { chatId: n, messageId: a, text: d };
|
|
144
|
+
if (new TextEncoder().encode(d).length > 8192 || new TextEncoder().encode(JSON.stringify(i)).length > 65536)
|
|
145
145
|
throw new Error(
|
|
146
146
|
"输入内容过长,请控制在 8 KiB 文本和 32 个附件/文本片段以内"
|
|
147
147
|
);
|
|
148
|
-
return
|
|
149
|
-
},
|
|
150
|
-
const
|
|
151
|
-
let
|
|
148
|
+
return i;
|
|
149
|
+
}, G = () => {
|
|
150
|
+
const s = [];
|
|
151
|
+
let n, a = !1, i;
|
|
152
152
|
return {
|
|
153
|
-
push(
|
|
153
|
+
push(d) {
|
|
154
154
|
if (!a)
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
} else
|
|
155
|
+
if (n) {
|
|
156
|
+
const l = n;
|
|
157
|
+
n = void 0, l.resolve({ done: !1, value: d });
|
|
158
|
+
} else s.length >= 4096 ? this.fail(new Error("响应事件积压超过限制,请恢复对话")) : s.push(d);
|
|
159
159
|
},
|
|
160
|
-
fail(
|
|
161
|
-
|
|
160
|
+
fail(d) {
|
|
161
|
+
i = d, a = !0, s.length = 0, n?.reject(d), n = void 0;
|
|
162
162
|
},
|
|
163
163
|
close() {
|
|
164
|
-
a = !0,
|
|
164
|
+
a = !0, s.length = 0, n?.resolve({ done: !0, value: void 0 }), n = void 0;
|
|
165
165
|
},
|
|
166
166
|
next() {
|
|
167
|
-
return
|
|
168
|
-
|
|
167
|
+
return i ? Promise.reject(i) : s.length ? Promise.resolve({ done: !1, value: s.shift() }) : a ? Promise.resolve({ done: !0, value: void 0 }) : new Promise((d, l) => {
|
|
168
|
+
n = { resolve: d, reject: l };
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
},
|
|
173
|
-
if (
|
|
172
|
+
}, F = (s, n) => new Promise((a) => {
|
|
173
|
+
if (n?.aborted) {
|
|
174
174
|
a();
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
|
-
const
|
|
178
|
-
clearTimeout(
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
}),
|
|
182
|
-
if (!/^\d{1,20}-\d{1,20}$/.test(
|
|
177
|
+
const i = () => {
|
|
178
|
+
clearTimeout(d), n?.removeEventListener("abort", i), a();
|
|
179
|
+
}, d = setTimeout(i, s);
|
|
180
|
+
n?.addEventListener("abort", i, { once: !0 });
|
|
181
|
+
}), T = (s) => {
|
|
182
|
+
if (!/^\d{1,20}-\d{1,20}$/.test(s))
|
|
183
183
|
throw new Error("Invalid Make App response: stream cursor");
|
|
184
|
-
return
|
|
185
|
-
},
|
|
186
|
-
const [a,
|
|
187
|
-
return a >
|
|
188
|
-
},
|
|
189
|
-
const
|
|
190
|
-
return [400, 401, 403, 404].includes(
|
|
184
|
+
return s.split("-").map(BigInt);
|
|
185
|
+
}, V = (s, n) => {
|
|
186
|
+
const [a, i] = T(s), [d, l] = T(n);
|
|
187
|
+
return a > d || a === d && i > l;
|
|
188
|
+
}, q = (s) => {
|
|
189
|
+
const n = s;
|
|
190
|
+
return [400, 401, 403, 404].includes(n?.status ?? n?.response?.status ?? 0) || [
|
|
191
191
|
"AI_FORBIDDEN",
|
|
192
192
|
"AI_AUTH_REQUIRED",
|
|
193
193
|
"AI_AUTH_EXPIRED",
|
|
194
194
|
"AI_NOT_FOUND",
|
|
195
195
|
"AI_RESPONSE_NOT_FOUND"
|
|
196
|
-
].includes(
|
|
197
|
-
},
|
|
196
|
+
].includes(n?.code ?? "") || s instanceof Error && s.message.startsWith("Invalid ");
|
|
197
|
+
}, Y = [
|
|
198
198
|
"response.subscribed",
|
|
199
199
|
"response.state",
|
|
200
200
|
"response.output_item.added",
|
|
@@ -206,267 +206,267 @@ const b = (t) => {
|
|
|
206
206
|
"response.failed",
|
|
207
207
|
"response.cancelled"
|
|
208
208
|
];
|
|
209
|
-
async function*
|
|
209
|
+
async function* Z(s, n, a) {
|
|
210
210
|
if (a?.aborted) return;
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
const
|
|
211
|
+
let i = s.cursor ?? "0-0";
|
|
212
|
+
T(i);
|
|
213
|
+
let d = 0, l = !1, f = 0;
|
|
214
|
+
const c = /* @__PURE__ */ new Map();
|
|
215
215
|
yield {
|
|
216
216
|
type: "response.state",
|
|
217
|
-
chatId:
|
|
218
|
-
responseId:
|
|
217
|
+
chatId: s.chatId,
|
|
218
|
+
responseId: s.responseId,
|
|
219
219
|
status: "queued"
|
|
220
220
|
};
|
|
221
|
-
async function*
|
|
222
|
-
if (
|
|
223
|
-
let
|
|
224
|
-
const
|
|
225
|
-
let
|
|
226
|
-
for (;
|
|
227
|
-
if (++
|
|
221
|
+
async function* h(u, A) {
|
|
222
|
+
if (u === "completed") {
|
|
223
|
+
let p = s.historyCursor ?? -1, I = 0;
|
|
224
|
+
const k = [];
|
|
225
|
+
let E = !0;
|
|
226
|
+
for (; E && !a?.aborted; ) {
|
|
227
|
+
if (++I > 200)
|
|
228
228
|
throw new Error("历史恢复超过单次预算,请继续加载历史");
|
|
229
|
-
const r = await
|
|
230
|
-
for (const
|
|
231
|
-
if (
|
|
232
|
-
const { artifacts:
|
|
233
|
-
|
|
229
|
+
const r = await n.loadHistory(s, p, a);
|
|
230
|
+
for (const e of r.messages)
|
|
231
|
+
if (e.responseId === s.responseId && e.role === "assistant" && e.persistent) {
|
|
232
|
+
const { artifacts: t, ...o } = e;
|
|
233
|
+
k.push(J(o));
|
|
234
234
|
}
|
|
235
|
-
if (
|
|
235
|
+
if (E = r.hasMore ?? !1, E && (r.nextCursor ?? -1) <= p)
|
|
236
236
|
throw new Error("Invalid Make App response: history cursor");
|
|
237
|
-
|
|
237
|
+
p = r.nextCursor ?? p;
|
|
238
238
|
}
|
|
239
239
|
if (a?.aborted) return;
|
|
240
|
-
if (!
|
|
240
|
+
if (!k.length)
|
|
241
241
|
throw new Error("回答已完成,历史尚未同步,请恢复对话");
|
|
242
242
|
yield {
|
|
243
243
|
type: "response.reconciled",
|
|
244
|
-
chatId:
|
|
245
|
-
responseId:
|
|
246
|
-
messages:
|
|
244
|
+
chatId: s.chatId,
|
|
245
|
+
responseId: s.responseId,
|
|
246
|
+
messages: k
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
249
|
yield {
|
|
250
250
|
type: "response.terminal",
|
|
251
|
-
chatId:
|
|
252
|
-
responseId:
|
|
253
|
-
status:
|
|
254
|
-
...
|
|
251
|
+
chatId: s.chatId,
|
|
252
|
+
responseId: s.responseId,
|
|
253
|
+
status: u,
|
|
254
|
+
...A ? { code: A } : {}
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
257
|
for (; !a?.aborted; ) {
|
|
258
|
-
if (
|
|
259
|
-
if (++
|
|
260
|
-
let
|
|
258
|
+
if (d > 3) {
|
|
259
|
+
if (++f > 600) throw new Error("响应连接中断,请恢复对话");
|
|
260
|
+
let e;
|
|
261
261
|
try {
|
|
262
|
-
|
|
263
|
-
} catch (
|
|
262
|
+
e = await n.getResponse(s, a);
|
|
263
|
+
} catch (t) {
|
|
264
264
|
if (a?.aborted) return;
|
|
265
|
-
if (
|
|
265
|
+
if (q(t)) throw t;
|
|
266
266
|
}
|
|
267
|
-
if (
|
|
268
|
-
yield*
|
|
269
|
-
|
|
267
|
+
if (e && (yield { type: "response.snapshot", snapshot: e }, K(e.status))) {
|
|
268
|
+
yield* h(
|
|
269
|
+
e.status
|
|
270
270
|
);
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
|
-
await
|
|
273
|
+
await F(Math.max(1e3, n.reconnectDelayMs), a);
|
|
274
274
|
continue;
|
|
275
275
|
}
|
|
276
|
-
const
|
|
277
|
-
let
|
|
278
|
-
const
|
|
279
|
-
{ chatId:
|
|
276
|
+
const u = G();
|
|
277
|
+
let A = 0, p = !1;
|
|
278
|
+
const I = n.eventSourceFactory(
|
|
279
|
+
{ chatId: s.chatId, responseId: s.responseId, cursor: i },
|
|
280
280
|
{ withCredentials: !0 }
|
|
281
|
-
),
|
|
282
|
-
const
|
|
283
|
-
if (!(
|
|
284
|
-
if (
|
|
285
|
-
|
|
281
|
+
), k = Y.map((e) => {
|
|
282
|
+
const t = (o) => {
|
|
283
|
+
if (!(p || a?.aborted)) {
|
|
284
|
+
if (o.data.length > n.maxEventCharacters * 2 || [...o.data].length > n.maxEventCharacters || A + o.data.length > 4e6) {
|
|
285
|
+
p = !0, I.close(), u.fail(
|
|
286
286
|
new Error(
|
|
287
287
|
"Make App assistant SSE event exceeds maxEventCharacters"
|
|
288
288
|
)
|
|
289
289
|
);
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
|
-
|
|
292
|
+
A += o.data.length, u.push({ name: e, raw: o.data, id: o.lastEventId });
|
|
293
293
|
}
|
|
294
294
|
};
|
|
295
|
-
return
|
|
295
|
+
return I.addEventListener(e, t), { name: e, listener: t };
|
|
296
296
|
});
|
|
297
|
-
|
|
298
|
-
!
|
|
297
|
+
I.onerror = () => {
|
|
298
|
+
!p && !a?.aborted && (p = !0, I.close(), u.push({ reconnect: !0 }));
|
|
299
299
|
};
|
|
300
|
-
const
|
|
301
|
-
|
|
300
|
+
const E = () => {
|
|
301
|
+
p = !0, I.close(), u.close();
|
|
302
302
|
};
|
|
303
|
-
a?.addEventListener("abort",
|
|
303
|
+
a?.addEventListener("abort", E, { once: !0 }), a?.aborted && E();
|
|
304
304
|
try {
|
|
305
305
|
for (; !a?.aborted; ) {
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
if ("reconnect" in
|
|
310
|
-
if (
|
|
311
|
-
if (
|
|
306
|
+
const e = await u.next();
|
|
307
|
+
if (e.done) return;
|
|
308
|
+
const t = e.value;
|
|
309
|
+
if ("reconnect" in t) break;
|
|
310
|
+
if (A -= t.raw.length, t.id && !V(t.id, i)) {
|
|
311
|
+
if (c.has(t.id) && c.get(t.id) !== t.raw)
|
|
312
312
|
throw new Error(
|
|
313
313
|
"Invalid Make App response: conflicting stream replay"
|
|
314
314
|
);
|
|
315
315
|
continue;
|
|
316
316
|
}
|
|
317
|
-
const
|
|
318
|
-
if (w(
|
|
317
|
+
const o = b(JSON.parse(t.raw));
|
|
318
|
+
if (w(o.responseId) !== s.responseId)
|
|
319
319
|
throw new Error("Invalid Make App response: stream scope");
|
|
320
|
-
if (
|
|
321
|
-
if (
|
|
322
|
-
|
|
320
|
+
if (t.name !== "response.subscribed") {
|
|
321
|
+
if (t.name === "response.reset") {
|
|
322
|
+
l = !0;
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
|
-
if (
|
|
326
|
-
const
|
|
327
|
-
if (yield { type: "response.snapshot", snapshot:
|
|
328
|
-
yield*
|
|
329
|
-
|
|
325
|
+
if (t.name === "response.snapshot") {
|
|
326
|
+
const y = U(o, s);
|
|
327
|
+
if (yield { type: "response.snapshot", snapshot: y }, K(y.status)) {
|
|
328
|
+
yield* h(
|
|
329
|
+
y.status
|
|
330
330
|
);
|
|
331
331
|
return;
|
|
332
332
|
}
|
|
333
|
-
} else if (
|
|
334
|
-
yield*
|
|
335
|
-
|
|
333
|
+
} else if (t.name === "response.completed" || t.name === "response.cancelled") {
|
|
334
|
+
yield* h(
|
|
335
|
+
t.name === "response.completed" ? "completed" : "cancelled"
|
|
336
336
|
);
|
|
337
337
|
return;
|
|
338
|
-
} else if (
|
|
339
|
-
if (
|
|
340
|
-
|
|
338
|
+
} else if (t.name === "response.failed") {
|
|
339
|
+
if (o.code === "AI_UPSTREAM_ERROR") {
|
|
340
|
+
p = !0, I.close();
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
if (
|
|
343
|
+
if (o.code === "AI_FORBIDDEN" || o.code === "AI_AUTH_EXPIRED")
|
|
344
344
|
throw Object.assign(new Error("当前身份无法继续读取响应"), {
|
|
345
|
-
code:
|
|
346
|
-
status:
|
|
345
|
+
code: o.code,
|
|
346
|
+
status: o.code === "AI_FORBIDDEN" ? 403 : 401
|
|
347
347
|
});
|
|
348
|
-
yield*
|
|
348
|
+
yield* h(
|
|
349
349
|
"failed",
|
|
350
|
-
typeof
|
|
350
|
+
typeof o.code == "string" ? o.code : void 0
|
|
351
351
|
);
|
|
352
352
|
return;
|
|
353
|
-
} else
|
|
354
|
-
type:
|
|
355
|
-
chatId:
|
|
356
|
-
...
|
|
357
|
-
}) :
|
|
358
|
-
|
|
353
|
+
} else t.name === "response.state" ? yield O({
|
|
354
|
+
type: t.name,
|
|
355
|
+
chatId: s.chatId,
|
|
356
|
+
...o
|
|
357
|
+
}) : l || (yield O({ type: t.name, ...o }));
|
|
358
|
+
t.id && (i = t.id, c.set(t.id, t.raw), c.size > 512 && c.delete(c.keys().next().value));
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
} finally {
|
|
362
|
-
|
|
363
|
-
for (const { name:
|
|
364
|
-
|
|
365
|
-
a?.removeEventListener("abort",
|
|
362
|
+
I.onerror = null, I.close(), u.close();
|
|
363
|
+
for (const { name: e, listener: t } of k)
|
|
364
|
+
I.removeEventListener(e, t);
|
|
365
|
+
a?.removeEventListener("abort", E);
|
|
366
366
|
}
|
|
367
|
-
if (a?.aborted || (
|
|
368
|
-
attempt:
|
|
369
|
-
}), await
|
|
370
|
-
Math.min(
|
|
367
|
+
if (a?.aborted || (d += 1, console.info("[make-ai-assistant] response reconnect", {
|
|
368
|
+
attempt: d
|
|
369
|
+
}), await F(
|
|
370
|
+
Math.min(n.reconnectDelayMs * 2 ** (d - 1), 5e3),
|
|
371
371
|
a
|
|
372
372
|
), a?.aborted)) return;
|
|
373
373
|
let r;
|
|
374
374
|
try {
|
|
375
|
-
r = await
|
|
376
|
-
} catch (
|
|
375
|
+
r = await n.getResponse(s, a);
|
|
376
|
+
} catch (e) {
|
|
377
377
|
if (a?.aborted) return;
|
|
378
|
-
if (
|
|
378
|
+
if (q(e)) throw e;
|
|
379
379
|
}
|
|
380
|
-
if (r &&
|
|
381
|
-
yield { type: "response.snapshot", snapshot: r }, yield*
|
|
380
|
+
if (r && K(r.status)) {
|
|
381
|
+
yield { type: "response.snapshot", snapshot: r }, yield* h(r.status);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
|
|
384
|
+
l && (d = 4);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
389
|
-
},
|
|
390
|
-
const
|
|
391
|
-
|
|
387
|
+
const L = () => Object.assign(new Error("Operation aborted"), { name: "AbortError" }), z = (s) => {
|
|
388
|
+
if (s?.aborted) throw L();
|
|
389
|
+
}, te = (s) => {
|
|
390
|
+
const n = v(s.historyLimit ?? 100, 1, 200), a = v(
|
|
391
|
+
s.maxEventCharacters ?? 1e6,
|
|
392
392
|
1,
|
|
393
393
|
4e6
|
|
394
|
-
),
|
|
395
|
-
|
|
394
|
+
), i = v(
|
|
395
|
+
s.reconnectDelayMs ?? 500,
|
|
396
396
|
1,
|
|
397
397
|
3e4
|
|
398
|
-
),
|
|
399
|
-
const e =
|
|
398
|
+
), d = s.modelInputKinds ?? ["text"], l = s.readContent, f = (r) => {
|
|
399
|
+
const e = s.resolveScope(r);
|
|
400
400
|
return {
|
|
401
401
|
appKey: w(e.appKey),
|
|
402
402
|
agentId: w(e.agentId),
|
|
403
403
|
identityKey: w(e.identityKey)
|
|
404
404
|
};
|
|
405
|
-
},
|
|
406
|
-
const e =
|
|
405
|
+
}, c = (r) => {
|
|
406
|
+
const e = f(r);
|
|
407
407
|
return `${e.identityKey}\0${e.appKey}\0${e.agentId}`;
|
|
408
|
-
}, h = async (
|
|
409
|
-
|
|
410
|
-
const
|
|
408
|
+
}, h = async (r, e, t, o) => {
|
|
409
|
+
z(o);
|
|
410
|
+
const y = c(r);
|
|
411
411
|
console.info("[make-ai-assistant] Make App operation start", { operation: e });
|
|
412
412
|
try {
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
return
|
|
416
|
-
} catch (
|
|
413
|
+
const m = await t();
|
|
414
|
+
if (z(o), y !== c(r)) throw L();
|
|
415
|
+
return m;
|
|
416
|
+
} catch (m) {
|
|
417
417
|
throw console.warn("[make-ai-assistant] Make App operation failed", {
|
|
418
418
|
operation: e,
|
|
419
|
-
errorType:
|
|
420
|
-
}),
|
|
419
|
+
errorType: m instanceof Error ? m.name : typeof m
|
|
420
|
+
}), m;
|
|
421
421
|
}
|
|
422
|
-
},
|
|
423
|
-
chatId: w(
|
|
424
|
-
}),
|
|
425
|
-
...
|
|
426
|
-
responseId: w(
|
|
427
|
-
}),
|
|
428
|
-
...
|
|
429
|
-
uploadId: w(
|
|
430
|
-
}),
|
|
431
|
-
|
|
422
|
+
}, u = (r) => ({
|
|
423
|
+
chatId: w(r.chatId)
|
|
424
|
+
}), A = (r) => ({
|
|
425
|
+
...u(r),
|
|
426
|
+
responseId: w(r.responseId)
|
|
427
|
+
}), p = (r) => ({
|
|
428
|
+
...u(r),
|
|
429
|
+
uploadId: w(r.uploadId)
|
|
430
|
+
}), I = async (r, e, t, o) => h(
|
|
431
|
+
r,
|
|
432
432
|
"loadHistory",
|
|
433
|
-
async () =>
|
|
434
|
-
await
|
|
433
|
+
async () => W(
|
|
434
|
+
await s.loadHistory(
|
|
435
435
|
{
|
|
436
436
|
chatId: w(e),
|
|
437
|
-
cursor:
|
|
438
|
-
limit:
|
|
437
|
+
cursor: v(t, -1),
|
|
438
|
+
limit: n
|
|
439
439
|
},
|
|
440
|
-
{ signal:
|
|
440
|
+
{ signal: o }
|
|
441
441
|
),
|
|
442
442
|
e,
|
|
443
|
-
|
|
443
|
+
t
|
|
444
444
|
),
|
|
445
|
-
|
|
446
|
-
),
|
|
447
|
-
|
|
445
|
+
o
|
|
446
|
+
), k = async (r, e, t) => h(
|
|
447
|
+
r,
|
|
448
448
|
"getResponse",
|
|
449
|
-
async () =>
|
|
450
|
-
await
|
|
449
|
+
async () => U(
|
|
450
|
+
await s.getResponse(A(e), { signal: t }),
|
|
451
451
|
e
|
|
452
452
|
),
|
|
453
|
-
|
|
454
|
-
),
|
|
455
|
-
const
|
|
453
|
+
t
|
|
454
|
+
), E = (r, e, t) => {
|
|
455
|
+
const o = c(r), y = t?.signal;
|
|
456
456
|
return (async function* () {
|
|
457
|
-
for await (const
|
|
457
|
+
for await (const m of Z(
|
|
458
458
|
e,
|
|
459
459
|
{
|
|
460
|
-
eventSourceFactory:
|
|
461
|
-
getResponse: (
|
|
462
|
-
loadHistory: (
|
|
460
|
+
eventSourceFactory: s.eventSourceFactory,
|
|
461
|
+
getResponse: (x, S) => k(r, x, S),
|
|
462
|
+
loadHistory: (x, S, N) => I(r, x.chatId, S, N),
|
|
463
463
|
maxEventCharacters: a,
|
|
464
|
-
reconnectDelayMs:
|
|
464
|
+
reconnectDelayMs: i
|
|
465
465
|
},
|
|
466
|
-
|
|
466
|
+
y
|
|
467
467
|
)) {
|
|
468
|
-
if (
|
|
469
|
-
yield
|
|
468
|
+
if (y?.aborted || o !== c(r)) return;
|
|
469
|
+
yield m;
|
|
470
470
|
}
|
|
471
471
|
})();
|
|
472
472
|
};
|
|
@@ -479,249 +479,251 @@ const B = () => Object.assign(new Error("Operation aborted"), { name: "AbortErro
|
|
|
479
479
|
conversationManagement: !0,
|
|
480
480
|
feedback: !0,
|
|
481
481
|
attachments: !0,
|
|
482
|
-
modelInputKinds:
|
|
482
|
+
modelInputKinds: d
|
|
483
483
|
},
|
|
484
|
-
scopeKey:
|
|
485
|
-
listAgents: (
|
|
486
|
-
|
|
484
|
+
scopeKey: c,
|
|
485
|
+
listAgents: (r, e) => h(
|
|
486
|
+
r,
|
|
487
487
|
"listAgents",
|
|
488
488
|
async () => {
|
|
489
|
-
const
|
|
490
|
-
await
|
|
491
|
-
{ appKey:
|
|
489
|
+
const t = f(r), o = b(
|
|
490
|
+
await s.listAgents(
|
|
491
|
+
{ appKey: t.appKey },
|
|
492
492
|
{ signal: e?.signal }
|
|
493
493
|
)
|
|
494
494
|
);
|
|
495
|
-
return
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
495
|
+
return R(o.agents, 1e3).map((y) => {
|
|
496
|
+
const m = b(y);
|
|
497
|
+
if (m.appKey !== t.appKey)
|
|
498
498
|
throw new Error("Invalid Make App response: agent scope");
|
|
499
499
|
return {
|
|
500
|
-
agentId: w(
|
|
501
|
-
appKey:
|
|
502
|
-
name: g(
|
|
500
|
+
agentId: w(m.agentId),
|
|
501
|
+
appKey: t.appKey,
|
|
502
|
+
name: g(m.name)
|
|
503
503
|
};
|
|
504
504
|
});
|
|
505
505
|
},
|
|
506
506
|
e?.signal
|
|
507
507
|
),
|
|
508
|
-
listConversations: (
|
|
509
|
-
|
|
508
|
+
listConversations: (r, e, t) => h(
|
|
509
|
+
r,
|
|
510
510
|
"listChats",
|
|
511
511
|
async () => {
|
|
512
|
-
const { appKey:
|
|
513
|
-
return
|
|
514
|
-
await
|
|
512
|
+
const { appKey: o, agentId: y } = f(r);
|
|
513
|
+
return Q(
|
|
514
|
+
await s.listChats(
|
|
515
515
|
{
|
|
516
|
-
appKey:
|
|
517
|
-
agentId:
|
|
516
|
+
appKey: o,
|
|
517
|
+
agentId: y,
|
|
518
518
|
...e?.cursor ? { cursor: g(e.cursor, 8192) } : {},
|
|
519
|
-
limit:
|
|
519
|
+
limit: v(e?.limit ?? 50, 1, 100)
|
|
520
520
|
},
|
|
521
|
-
{ signal:
|
|
521
|
+
{ signal: t?.signal }
|
|
522
522
|
),
|
|
523
|
-
{ appKey:
|
|
523
|
+
{ appKey: o, agentId: y }
|
|
524
524
|
);
|
|
525
525
|
},
|
|
526
|
-
|
|
526
|
+
t?.signal
|
|
527
527
|
),
|
|
528
|
-
createConversation: (
|
|
529
|
-
|
|
528
|
+
createConversation: (r, e, t) => h(
|
|
529
|
+
r,
|
|
530
530
|
"createChat",
|
|
531
531
|
async () => {
|
|
532
|
-
const { appKey:
|
|
533
|
-
appKey:
|
|
534
|
-
agentId:
|
|
535
|
-
requestId:
|
|
532
|
+
const { appKey: o, agentId: y } = f(r), m = {
|
|
533
|
+
appKey: o,
|
|
534
|
+
agentId: y,
|
|
535
|
+
requestId: M(e.requestId),
|
|
536
536
|
...e.title === void 0 ? {} : { title: g(e.title.trim(), 255) }
|
|
537
537
|
};
|
|
538
|
-
return
|
|
539
|
-
await
|
|
540
|
-
{ appKey:
|
|
538
|
+
return C(
|
|
539
|
+
await s.createChat(m, { signal: t?.signal }),
|
|
540
|
+
{ appKey: o, agentId: y }
|
|
541
541
|
);
|
|
542
542
|
},
|
|
543
|
-
|
|
543
|
+
t?.signal
|
|
544
544
|
),
|
|
545
|
-
getConversation: (
|
|
546
|
-
|
|
545
|
+
getConversation: (r, e, t) => h(
|
|
546
|
+
r,
|
|
547
547
|
"getChat",
|
|
548
|
-
async () =>
|
|
549
|
-
await
|
|
550
|
-
|
|
548
|
+
async () => C(
|
|
549
|
+
await s.getChat(u(e), { signal: t?.signal }),
|
|
550
|
+
f(r),
|
|
551
551
|
e.chatId
|
|
552
552
|
),
|
|
553
|
-
|
|
553
|
+
t?.signal
|
|
554
554
|
),
|
|
555
|
-
updateConversation: (
|
|
556
|
-
|
|
555
|
+
updateConversation: (r, e, t) => h(
|
|
556
|
+
r,
|
|
557
557
|
"updateChat",
|
|
558
558
|
async () => {
|
|
559
|
-
const
|
|
560
|
-
...
|
|
561
|
-
expectedRevision:
|
|
559
|
+
const o = {
|
|
560
|
+
...u(e),
|
|
561
|
+
expectedRevision: v(e.expectedRevision, 1)
|
|
562
562
|
};
|
|
563
|
-
if (e.title !== void 0 && (
|
|
563
|
+
if (e.title !== void 0 && (o.title = g(e.title.trim(), 255)), e.pinned !== void 0) {
|
|
564
564
|
if (typeof e.pinned != "boolean")
|
|
565
565
|
throw new Error("Invalid Make App request: pinned");
|
|
566
|
-
|
|
566
|
+
o.pinned = e.pinned;
|
|
567
567
|
}
|
|
568
|
-
if (
|
|
568
|
+
if (o.title === void 0 && o.pinned === void 0)
|
|
569
569
|
throw new Error("Invalid Make App request: empty patch");
|
|
570
|
-
return
|
|
571
|
-
await
|
|
572
|
-
|
|
570
|
+
return C(
|
|
571
|
+
await s.updateChat(o, { signal: t?.signal }),
|
|
572
|
+
f(r),
|
|
573
573
|
e.chatId
|
|
574
574
|
);
|
|
575
575
|
},
|
|
576
|
-
|
|
576
|
+
t?.signal
|
|
577
577
|
),
|
|
578
|
-
deleteConversation: (
|
|
579
|
-
|
|
578
|
+
deleteConversation: (r, e, t) => h(
|
|
579
|
+
r,
|
|
580
580
|
"deleteChat",
|
|
581
|
-
() =>
|
|
581
|
+
() => s.deleteChat(
|
|
582
582
|
{
|
|
583
|
-
...
|
|
584
|
-
expectedRevision:
|
|
583
|
+
...u(e),
|
|
584
|
+
expectedRevision: v(e.expectedRevision, 1)
|
|
585
585
|
},
|
|
586
|
-
{ signal:
|
|
586
|
+
{ signal: t?.signal }
|
|
587
587
|
),
|
|
588
|
-
|
|
588
|
+
t?.signal
|
|
589
589
|
),
|
|
590
|
-
loadConversation: async (
|
|
591
|
-
getResponse: (
|
|
592
|
-
cancelResponse: (
|
|
593
|
-
|
|
590
|
+
loadConversation: async (r, e) => e?.threadId ? I(r, e.threadId, e.cursor ?? -1, e.signal) : { messages: [] },
|
|
591
|
+
getResponse: (r, e, t) => k(r, e, t?.signal),
|
|
592
|
+
cancelResponse: (r, e, t) => h(
|
|
593
|
+
r,
|
|
594
594
|
"cancelResponse",
|
|
595
|
-
async () =>
|
|
596
|
-
await
|
|
597
|
-
signal:
|
|
595
|
+
async () => U(
|
|
596
|
+
await s.cancelResponse(A(e), {
|
|
597
|
+
signal: t?.signal
|
|
598
598
|
}),
|
|
599
599
|
e
|
|
600
600
|
),
|
|
601
|
-
|
|
601
|
+
t?.signal
|
|
602
602
|
),
|
|
603
|
-
setFeedback: (
|
|
604
|
-
|
|
603
|
+
setFeedback: (r, e, t) => h(
|
|
604
|
+
r,
|
|
605
605
|
"setFeedback",
|
|
606
606
|
async () => {
|
|
607
607
|
if (!["like", "dislike", "none"].includes(e.rating))
|
|
608
608
|
throw new Error("Invalid Make App request: rating");
|
|
609
|
-
const
|
|
610
|
-
if (e.rating !== "dislike" && (
|
|
609
|
+
const o = g(e.reason ?? "", 128, !0).trim(), y = g(e.comment ?? "", 4e3, !0).trim();
|
|
610
|
+
if (e.rating !== "dislike" && (o || y))
|
|
611
611
|
throw new Error("Invalid Make App request: feedback detail");
|
|
612
|
-
return
|
|
613
|
-
await
|
|
612
|
+
return $(
|
|
613
|
+
await s.setFeedback(
|
|
614
614
|
{
|
|
615
|
-
...
|
|
615
|
+
...u(e),
|
|
616
616
|
messageId: w(e.messageId),
|
|
617
|
-
requestId:
|
|
617
|
+
requestId: M(e.requestId),
|
|
618
618
|
rating: e.rating,
|
|
619
|
-
...
|
|
620
|
-
...
|
|
619
|
+
...o ? { reason: o } : {},
|
|
620
|
+
...y ? { comment: y } : {}
|
|
621
621
|
},
|
|
622
|
-
{ signal:
|
|
622
|
+
{ signal: t?.signal }
|
|
623
623
|
)
|
|
624
624
|
);
|
|
625
625
|
},
|
|
626
|
-
|
|
626
|
+
t?.signal
|
|
627
627
|
),
|
|
628
|
-
startUpload: (
|
|
629
|
-
|
|
628
|
+
startUpload: (r, e, t) => h(
|
|
629
|
+
r,
|
|
630
630
|
"startUpload",
|
|
631
|
-
async () =>
|
|
632
|
-
await
|
|
631
|
+
async () => _(
|
|
632
|
+
await s.startUpload(
|
|
633
633
|
{
|
|
634
|
-
...
|
|
635
|
-
fileId:
|
|
636
|
-
name:
|
|
634
|
+
...u(e),
|
|
635
|
+
fileId: M(e.fileId),
|
|
636
|
+
name: D(e.name),
|
|
637
637
|
contentType: g(e.contentType, 256),
|
|
638
|
-
sizeBytes:
|
|
638
|
+
sizeBytes: v(e.sizeBytes, 0, 64 << 20),
|
|
639
639
|
...e.digestSha256 ? { digestSha256: g(e.digestSha256, 64) } : {}
|
|
640
640
|
},
|
|
641
|
-
{ signal:
|
|
641
|
+
{ signal: t?.signal }
|
|
642
642
|
)
|
|
643
643
|
),
|
|
644
|
-
|
|
644
|
+
t?.signal
|
|
645
645
|
),
|
|
646
|
-
getUpload: (
|
|
647
|
-
|
|
646
|
+
getUpload: (r, e, t) => h(
|
|
647
|
+
r,
|
|
648
648
|
"getUpload",
|
|
649
|
-
async () =>
|
|
650
|
-
await
|
|
649
|
+
async () => _(
|
|
650
|
+
await s.getUpload(p(e), { signal: t?.signal }),
|
|
651
651
|
e.uploadId
|
|
652
652
|
),
|
|
653
|
-
|
|
653
|
+
t?.signal
|
|
654
654
|
),
|
|
655
|
-
uploadPart: (
|
|
656
|
-
|
|
655
|
+
uploadPart: (r, e, t) => h(
|
|
656
|
+
r,
|
|
657
657
|
"uploadPart",
|
|
658
658
|
() => {
|
|
659
659
|
if (!(e.bytes instanceof Uint8Array) || e.bytes.byteLength > 1 << 20)
|
|
660
660
|
throw new Error("Invalid Make App request: upload bytes");
|
|
661
|
-
return
|
|
661
|
+
return s.uploadPart(
|
|
662
662
|
{
|
|
663
|
-
...
|
|
664
|
-
part:
|
|
663
|
+
...p(e),
|
|
664
|
+
part: v(e.part, 0, 63),
|
|
665
665
|
bytes: e.bytes
|
|
666
666
|
},
|
|
667
|
-
{ signal:
|
|
667
|
+
{ signal: t?.signal }
|
|
668
668
|
);
|
|
669
669
|
},
|
|
670
|
-
|
|
670
|
+
t?.signal
|
|
671
671
|
),
|
|
672
|
-
completeUpload: (
|
|
673
|
-
|
|
672
|
+
completeUpload: (r, e, t) => h(
|
|
673
|
+
r,
|
|
674
674
|
"completeUpload",
|
|
675
|
-
async () =>
|
|
676
|
-
await
|
|
677
|
-
signal:
|
|
675
|
+
async () => _(
|
|
676
|
+
await s.completeUpload(p(e), {
|
|
677
|
+
signal: t?.signal
|
|
678
678
|
}),
|
|
679
679
|
e.uploadId
|
|
680
680
|
),
|
|
681
|
-
|
|
681
|
+
t?.signal
|
|
682
682
|
),
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
683
|
+
...l ? {
|
|
684
|
+
readContent: (r, e, t) => h(
|
|
685
|
+
r,
|
|
686
|
+
"readContent",
|
|
687
|
+
async () => {
|
|
688
|
+
const o = await l(
|
|
689
|
+
{ ...u(e), contentRef: w(e.contentRef) },
|
|
690
|
+
{ signal: t?.signal }
|
|
691
|
+
);
|
|
692
|
+
if (!(o instanceof Uint8Array) || o.byteLength > 64 << 20)
|
|
693
|
+
throw new Error("Invalid Make App response: content bytes");
|
|
694
|
+
return o;
|
|
695
|
+
},
|
|
696
|
+
t?.signal
|
|
697
|
+
)
|
|
698
|
+
} : {},
|
|
699
|
+
watchResponse: E,
|
|
700
|
+
async *run(r, e) {
|
|
699
701
|
if (e?.signal?.aborted) return;
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
+
const t = X(r), o = await h(
|
|
703
|
+
r.context,
|
|
702
704
|
"sendMessage",
|
|
703
|
-
async () =>
|
|
704
|
-
await
|
|
705
|
+
async () => b(
|
|
706
|
+
await s.sendMessage(t, { signal: e?.signal })
|
|
705
707
|
),
|
|
706
708
|
e?.signal
|
|
707
709
|
);
|
|
708
|
-
if (
|
|
710
|
+
if (o.chatId !== t.chatId)
|
|
709
711
|
throw new Error("Invalid Make App response: accepted chat");
|
|
710
|
-
const
|
|
712
|
+
const y = w(o.responseId), m = v(o.acceptedCursor);
|
|
711
713
|
yield {
|
|
712
714
|
type: "response.accepted",
|
|
713
|
-
chatId:
|
|
714
|
-
responseId:
|
|
715
|
-
messageId:
|
|
716
|
-
acceptedCursor:
|
|
717
|
-
}, yield*
|
|
718
|
-
|
|
719
|
-
{ chatId:
|
|
715
|
+
chatId: t.chatId,
|
|
716
|
+
responseId: y,
|
|
717
|
+
messageId: t.messageId,
|
|
718
|
+
acceptedCursor: m
|
|
719
|
+
}, yield* E(
|
|
720
|
+
r.context,
|
|
721
|
+
{ chatId: t.chatId, responseId: y, historyCursor: m },
|
|
720
722
|
e
|
|
721
723
|
);
|
|
722
724
|
}
|
|
723
725
|
};
|
|
724
726
|
};
|
|
725
727
|
export {
|
|
726
|
-
|
|
728
|
+
te as createMakeAppAssistantTransport
|
|
727
729
|
};
|