@pluno/product-agent-web 0.1.53 → 0.1.55
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/attachmentStorage.d.ts +18 -0
- package/dist/index.d.ts +39 -3
- package/dist/product-agent-sdk.js +838 -391
- package/dist/product-agent-widget.js +1254 -1298
- package/dist/widget.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,11 +1,86 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const Et = "pluno-product-agent-attachments";
|
|
2
|
+
const F = "files";
|
|
3
|
+
async function it(e) {
|
|
4
|
+
const t = await U();
|
|
5
|
+
await at(t, "readwrite", (s) => s.put(e));
|
|
6
|
+
}
|
|
7
|
+
async function Rt(e) {
|
|
8
|
+
const t = await U(), s = await at(
|
|
9
|
+
t,
|
|
10
|
+
"readonly",
|
|
11
|
+
(r) => r.get(e)
|
|
12
|
+
);
|
|
13
|
+
if (!s)
|
|
14
|
+
return null;
|
|
15
|
+
const n = Date.now();
|
|
16
|
+
return await ot(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
|
|
17
|
+
}
|
|
18
|
+
async function ot(e, t) {
|
|
19
|
+
const s = await U();
|
|
20
|
+
await L(s, "readwrite", async (n) => {
|
|
21
|
+
const r = await v(
|
|
22
|
+
n.get(e)
|
|
23
|
+
);
|
|
24
|
+
r && n.put({
|
|
25
|
+
...r,
|
|
26
|
+
...t
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function _t(e = 864e5) {
|
|
31
|
+
const t = await U(), s = Date.now() - e;
|
|
32
|
+
await L(t, "readwrite", async (n) => {
|
|
33
|
+
const r = n.index("lastUsedAt");
|
|
34
|
+
(await v(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function U() {
|
|
38
|
+
return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((e, t) => {
|
|
39
|
+
const s = indexedDB.open(Et, 1);
|
|
40
|
+
s.onupgradeneeded = () => {
|
|
41
|
+
const r = s.result.createObjectStore(F, { keyPath: "attachmentId" });
|
|
42
|
+
r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
|
|
43
|
+
}, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error ?? new Error("Failed to open Product Agent attachment storage"));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async function at(e, t, s) {
|
|
47
|
+
return await L(e, t, async (n) => await v(s(n)));
|
|
48
|
+
}
|
|
49
|
+
function L(e, t, s) {
|
|
50
|
+
return new Promise((n, r) => {
|
|
51
|
+
const i = e.transaction(F, t), o = i.objectStore(F);
|
|
52
|
+
let c, a = !1;
|
|
53
|
+
s(o).then((d) => {
|
|
54
|
+
c = d;
|
|
55
|
+
}).catch((d) => {
|
|
56
|
+
a = !0;
|
|
57
|
+
try {
|
|
58
|
+
i.abort();
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
r(d);
|
|
62
|
+
}), i.oncomplete = () => {
|
|
63
|
+
a || n(c);
|
|
64
|
+
}, i.onerror = () => {
|
|
65
|
+
a || (a = !0, r(i.error ?? new Error("Product Agent attachment storage transaction failed")));
|
|
66
|
+
}, i.onabort = () => {
|
|
67
|
+
a || (a = !0, r(i.error ?? new Error("Product Agent attachment storage transaction aborted")));
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function v(e) {
|
|
72
|
+
return new Promise((t, s) => {
|
|
73
|
+
e.onsuccess = () => t(e.result), e.onerror = () => s(e.error ?? new Error("Product Agent attachment storage request failed"));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const H = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', Pt = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Mt = ".pluno-pa-widget__panel", bt = ".pluno-pa-widget__timeline", X = `${H}[data-pluno-sdk-preview-channel]`, Ut = "https://app.pluno.ai", Ct = "gpt-5.4", Dt = 2e4, Nt = 2e3, E = 6e4, qt = 15e3, K = 2, Ot = 15e3, Ft = 5e3, Ht = 1e3, Bt = 8e3, Wt = 15e3, J = 3, xt = [300, 1e3], N = 1e5, Lt = 100, ct = "pluno.productAgent.state.", B = "pluno.productAgent.pendingEvents.", V = "pluno.productAgent.transportId";
|
|
77
|
+
class ut {
|
|
3
78
|
constructor(t) {
|
|
4
|
-
this.options = t, this.transportId =
|
|
79
|
+
this.options = t, this.transportId = oe(), this.state = {
|
|
5
80
|
...this.state,
|
|
6
|
-
starterPrompts:
|
|
81
|
+
starterPrompts: te(t.initialStarterPrompts)
|
|
7
82
|
};
|
|
8
|
-
const s = t.restorePersistedState === !1 ? null :
|
|
83
|
+
const s = t.restorePersistedState === !1 ? null : Ue(t.clientId, t.expectedPersistedSessionId);
|
|
9
84
|
s && (this.state = {
|
|
10
85
|
...this.state,
|
|
11
86
|
...s,
|
|
@@ -16,7 +91,7 @@ class $ {
|
|
|
16
91
|
assistantDraftRunId: null,
|
|
17
92
|
isThinking: !1,
|
|
18
93
|
lastError: null
|
|
19
|
-
}), this.queuedClientEvents =
|
|
94
|
+
}), this.queuedClientEvents = De(t.clientId);
|
|
20
95
|
}
|
|
21
96
|
options;
|
|
22
97
|
listeners = {};
|
|
@@ -42,6 +117,9 @@ class $ {
|
|
|
42
117
|
thinkingWatchdogResyncAttemptsByClientMessageId = {};
|
|
43
118
|
thinkingWatchdogRetryAttemptsByClientMessageId = {};
|
|
44
119
|
runtimeHelperJavascript = null;
|
|
120
|
+
attachmentFiles = /* @__PURE__ */ new Map();
|
|
121
|
+
attachmentBlobCache = /* @__PURE__ */ new Map();
|
|
122
|
+
sessionUserFilesApiCleanup = null;
|
|
45
123
|
transientStarterPromptsRequestInFlight = !1;
|
|
46
124
|
transientStarterPromptsRequestAttempted = !1;
|
|
47
125
|
state = {
|
|
@@ -60,14 +138,18 @@ class $ {
|
|
|
60
138
|
lastErrorCode: null
|
|
61
139
|
};
|
|
62
140
|
static async init(t) {
|
|
63
|
-
const s = new
|
|
141
|
+
const s = new ut({
|
|
64
142
|
...t,
|
|
65
|
-
backendUrl:
|
|
66
|
-
clientId: t.clientId ??
|
|
67
|
-
model: t.model ??
|
|
143
|
+
backendUrl: Kt(t.backendUrl ?? Ut),
|
|
144
|
+
clientId: t.clientId ?? ie(),
|
|
145
|
+
model: t.model ?? Ct
|
|
68
146
|
});
|
|
69
147
|
try {
|
|
70
|
-
|
|
148
|
+
_t().catch((n) => {
|
|
149
|
+
p("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
|
|
150
|
+
message: n instanceof Error ? n.message : String(n)
|
|
151
|
+
});
|
|
152
|
+
}), s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
|
|
71
153
|
} catch (n) {
|
|
72
154
|
throw s.destroy(), n;
|
|
73
155
|
}
|
|
@@ -90,9 +172,9 @@ class $ {
|
|
|
90
172
|
return;
|
|
91
173
|
if (this.setState({ status: (this.state.status === "closed", "connecting"), lastError: null }), this.token = this.options.token ?? await this.options.tokenProvider?.() ?? null, !this.token && !this.options.webSocketFactory)
|
|
92
174
|
throw new Error("Pluno requires a token or tokenProvider");
|
|
93
|
-
const t =
|
|
175
|
+
const t = Jt(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
|
|
94
176
|
this.socket = s, s.addEventListener("open", () => {
|
|
95
|
-
this.socket === s && (
|
|
177
|
+
this.socket === s && (p("web-sdk.agent", "Pluno socket opened", {
|
|
96
178
|
queuedClientEventCount: this.queuedClientEvents.length,
|
|
97
179
|
isThinking: this.state.isThinking
|
|
98
180
|
}), this.token && this.sendNow({
|
|
@@ -102,9 +184,9 @@ class $ {
|
|
|
102
184
|
transportId: this.transportId
|
|
103
185
|
}), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null }));
|
|
104
186
|
}), s.addEventListener("message", (n) => {
|
|
105
|
-
this.socket === s && this.handleServerEvent(
|
|
187
|
+
this.socket === s && this.handleServerEvent(Qt(n.data));
|
|
106
188
|
}), s.addEventListener("close", (n) => {
|
|
107
|
-
this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (
|
|
189
|
+
this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (p("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
|
|
108
190
|
code: typeof n?.code == "number" ? n.code : null,
|
|
109
191
|
reason: typeof n?.reason == "string" ? n.reason : "",
|
|
110
192
|
wasClean: typeof n?.wasClean == "boolean" ? n.wasClean : null,
|
|
@@ -112,7 +194,7 @@ class $ {
|
|
|
112
194
|
isThinking: this.state.isThinking
|
|
113
195
|
}), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect()));
|
|
114
196
|
}), s.addEventListener("error", () => {
|
|
115
|
-
this.socket !== s || this.state.status === "closed" || (
|
|
197
|
+
this.socket !== s || this.state.status === "closed" || (p("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
|
|
116
198
|
queuedClientEventCount: this.queuedClientEvents.length,
|
|
117
199
|
isThinking: this.state.isThinking
|
|
118
200
|
}), this.stopHeartbeat(), this.socket = null, this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect(), s.readyState !== WebSocket.CLOSED && s.readyState !== WebSocket.CLOSING && s.close());
|
|
@@ -122,16 +204,16 @@ class $ {
|
|
|
122
204
|
this.setState({ status: "closed", isThinking: !1 }), this.stopHeartbeat(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
|
|
123
205
|
}
|
|
124
206
|
destroy() {
|
|
125
|
-
this.disconnect(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null;
|
|
207
|
+
this.disconnect(), this.cleanupSessionUserFilesApi(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null;
|
|
126
208
|
for (const t of Object.values(this.listeners))
|
|
127
209
|
t?.clear();
|
|
128
210
|
}
|
|
129
211
|
sendMessage(t, s = {}) {
|
|
130
|
-
const n = t.trim(), r = s.attachments ?? [];
|
|
131
|
-
if (!n &&
|
|
132
|
-
return;
|
|
133
|
-
const
|
|
134
|
-
id: `local-${
|
|
212
|
+
const n = t.trim(), r = s.attachments ?? [], i = r.map(j);
|
|
213
|
+
if (!n && i.length === 0)
|
|
214
|
+
return null;
|
|
215
|
+
const o = y(), c = R(), a = {
|
|
216
|
+
id: `local-${c}`,
|
|
135
217
|
role: "user",
|
|
136
218
|
content: n,
|
|
137
219
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -139,32 +221,189 @@ class $ {
|
|
|
139
221
|
};
|
|
140
222
|
this.setState({
|
|
141
223
|
messages: [...this.state.messages, a],
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
224
|
+
...this.state.isThinking ? {} : {
|
|
225
|
+
assistantDraft: "",
|
|
226
|
+
assistantDraftRespondsToUserMessageId: null,
|
|
227
|
+
assistantDraftRunId: null
|
|
228
|
+
},
|
|
145
229
|
isThinking: !0,
|
|
146
230
|
lastError: null
|
|
147
231
|
}), this.emit("message", a);
|
|
148
|
-
const
|
|
232
|
+
const d = {
|
|
149
233
|
type: "chat.user_message",
|
|
150
234
|
sessionId: this.state.sessionId ?? void 0,
|
|
151
|
-
clientMessageId:
|
|
235
|
+
clientMessageId: c,
|
|
152
236
|
content: n,
|
|
153
|
-
attachments:
|
|
154
|
-
page:
|
|
237
|
+
attachments: i.length > 0 ? i : void 0,
|
|
238
|
+
page: o,
|
|
155
239
|
model: this.options.model,
|
|
156
|
-
metadata:
|
|
240
|
+
metadata: Y(this.options.metadata)
|
|
241
|
+
};
|
|
242
|
+
return this.activeClientMessageId = c, this.activeUserMessageEvent = d, this.markThinkingProgress(), this.send(d), this.startBackgroundAttachmentUploads(c, i), c;
|
|
243
|
+
}
|
|
244
|
+
createLocalAttachment(t) {
|
|
245
|
+
const s = R(), n = {
|
|
246
|
+
id: s,
|
|
247
|
+
name: t.name || "attachment",
|
|
248
|
+
mimeType: nt(t),
|
|
249
|
+
sizeBytes: t.size
|
|
157
250
|
};
|
|
158
|
-
this.
|
|
251
|
+
this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
|
|
252
|
+
const r = Date.now();
|
|
253
|
+
return it({
|
|
254
|
+
attachmentId: s,
|
|
255
|
+
name: n.name,
|
|
256
|
+
mimeType: n.mimeType,
|
|
257
|
+
sizeBytes: n.sizeBytes,
|
|
258
|
+
blob: t,
|
|
259
|
+
origin: y().origin,
|
|
260
|
+
sessionId: this.state.sessionId ?? void 0,
|
|
261
|
+
createdAt: r,
|
|
262
|
+
lastUsedAt: r
|
|
263
|
+
}).catch((i) => {
|
|
264
|
+
p("web-sdk.attachments", "Failed to store Product Agent attachment", {
|
|
265
|
+
attachmentId: s,
|
|
266
|
+
name: n.name,
|
|
267
|
+
message: i instanceof Error ? i.message : String(i)
|
|
268
|
+
});
|
|
269
|
+
}), n;
|
|
270
|
+
}
|
|
271
|
+
async uploadAttachment(t) {
|
|
272
|
+
const s = this.createLocalAttachment(t);
|
|
273
|
+
return await this.uploadAttachmentForMessage({
|
|
274
|
+
file: t,
|
|
275
|
+
attachment: s,
|
|
276
|
+
clientMessageId: R(),
|
|
277
|
+
waitForSession: !1,
|
|
278
|
+
notifyCompletion: !1
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
startBackgroundAttachmentUploads(t, s) {
|
|
282
|
+
for (const n of s) {
|
|
283
|
+
if (!n.id || n.gcsPath || !this.attachmentFiles.has(n.id))
|
|
284
|
+
continue;
|
|
285
|
+
const r = this.attachmentFiles.get(n.id);
|
|
286
|
+
r && this.uploadAttachmentForMessage({
|
|
287
|
+
file: r,
|
|
288
|
+
attachment: n,
|
|
289
|
+
clientMessageId: t,
|
|
290
|
+
waitForSession: !0,
|
|
291
|
+
notifyCompletion: !0
|
|
292
|
+
}).catch((i) => {
|
|
293
|
+
p("web-sdk.agent", "Attachment background upload failed", {
|
|
294
|
+
attachmentId: n.id,
|
|
295
|
+
name: n.name,
|
|
296
|
+
message: i instanceof Error ? i.message : String(i)
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
async uploadAttachmentForMessage({
|
|
302
|
+
file: t,
|
|
303
|
+
attachment: s,
|
|
304
|
+
clientMessageId: n,
|
|
305
|
+
waitForSession: r,
|
|
306
|
+
notifyCompletion: i
|
|
307
|
+
}) {
|
|
308
|
+
const o = r ? await this.waitForSessionId() : this.state.sessionId, c = nt(t), a = {
|
|
309
|
+
sessionId: o ?? void 0,
|
|
310
|
+
attachmentId: s.id,
|
|
311
|
+
clientId: this.options.clientId,
|
|
312
|
+
transportId: this.transportId,
|
|
313
|
+
name: t.name || "attachment",
|
|
314
|
+
mimeType: c,
|
|
315
|
+
sizeBytes: t.size,
|
|
316
|
+
page: y(),
|
|
317
|
+
model: this.options.model,
|
|
318
|
+
metadata: Y(this.options.metadata)
|
|
319
|
+
}, d = this.options.prepareAttachmentUpload ? await O(
|
|
320
|
+
() => this.options.prepareAttachmentUpload(a),
|
|
321
|
+
"Failed to prepare attachment upload"
|
|
322
|
+
) : await this.prepareEmbedAttachmentUpload(a);
|
|
323
|
+
await O(async () => {
|
|
324
|
+
const u = await fetch(d.uploadUrl, {
|
|
325
|
+
method: d.uploadMethod,
|
|
326
|
+
headers: d.uploadHeaders,
|
|
327
|
+
body: t
|
|
328
|
+
});
|
|
329
|
+
if (!u.ok)
|
|
330
|
+
throw new M("Failed to upload attachment", u.status);
|
|
331
|
+
return u;
|
|
332
|
+
}, "Failed to upload attachment"), this.setState({ sessionId: d.sessionId });
|
|
333
|
+
const h = yt(d.attachment, this.options.backendUrl);
|
|
334
|
+
return this.updateAttachmentInState(s.id, h), s.id && ot(s.id, {
|
|
335
|
+
sessionId: d.sessionId,
|
|
336
|
+
fileUrl: h.fileUrl,
|
|
337
|
+
gcsPath: h.gcsPath,
|
|
338
|
+
lastUsedAt: Date.now()
|
|
339
|
+
}).catch((u) => {
|
|
340
|
+
p("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
|
|
341
|
+
attachmentId: s.id,
|
|
342
|
+
name: h.name,
|
|
343
|
+
message: u instanceof Error ? u.message : String(u)
|
|
344
|
+
});
|
|
345
|
+
}), i && h.gcsPath && this.send({
|
|
346
|
+
type: "attachment.upload_completed",
|
|
347
|
+
sessionId: d.sessionId,
|
|
348
|
+
clientMessageId: n,
|
|
349
|
+
attachment: h
|
|
350
|
+
}), h;
|
|
351
|
+
}
|
|
352
|
+
waitForSessionId() {
|
|
353
|
+
return this.state.sessionId ? Promise.resolve(this.state.sessionId) : new Promise((t, s) => {
|
|
354
|
+
const n = window.setTimeout(() => {
|
|
355
|
+
r(), s(new Error("Timed out waiting for Pluno session before persisting attachment"));
|
|
356
|
+
}, Wt), r = this.on("state", (i) => {
|
|
357
|
+
i.sessionId && (window.clearTimeout(n), r(), t(i.sessionId));
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
updateAttachmentInState(t, s) {
|
|
362
|
+
if (!t)
|
|
363
|
+
return;
|
|
364
|
+
const n = this.state.messages.map((r) => r.attachments?.some((i) => i.id === t) ? {
|
|
365
|
+
...r,
|
|
366
|
+
attachments: r.attachments.map(
|
|
367
|
+
(i) => i.id === t ? { ...i, ...s } : i
|
|
368
|
+
)
|
|
369
|
+
} : r);
|
|
370
|
+
this.setState({ messages: n });
|
|
371
|
+
}
|
|
372
|
+
async prepareEmbedAttachmentUpload(t) {
|
|
373
|
+
let s = !1;
|
|
374
|
+
return await O(async () => {
|
|
375
|
+
const n = await this.fetchEmbedAttachmentUpload(t);
|
|
376
|
+
if (n.ok)
|
|
377
|
+
return await n.json();
|
|
378
|
+
if (Ge(n.status) && this.options.tokenProvider && !s) {
|
|
379
|
+
s = !0;
|
|
380
|
+
const r = await this.fetchEmbedAttachmentUpload(t);
|
|
381
|
+
if (r.ok)
|
|
382
|
+
return await r.json();
|
|
383
|
+
throw new M("Failed to prepare attachment upload", r.status);
|
|
384
|
+
}
|
|
385
|
+
throw new M("Failed to prepare attachment upload", n.status);
|
|
386
|
+
}, "Failed to prepare attachment upload");
|
|
387
|
+
}
|
|
388
|
+
async fetchEmbedAttachmentUpload(t) {
|
|
389
|
+
const s = await this.getUploadToken();
|
|
390
|
+
return await fetch(new URL("/api/product-agent/embed/attachments/upload", this.options.backendUrl), {
|
|
391
|
+
method: "POST",
|
|
392
|
+
headers: {
|
|
393
|
+
authorization: `Bearer ${s}`,
|
|
394
|
+
"content-type": "application/json"
|
|
395
|
+
},
|
|
396
|
+
body: JSON.stringify(t)
|
|
397
|
+
});
|
|
159
398
|
}
|
|
160
399
|
stop() {
|
|
161
|
-
this.state.sessionId && (this.send({ type: "run.stop", sessionId: this.state.sessionId }), this.setState({
|
|
400
|
+
this.state.sessionId && (this.send({ type: "run.stop", sessionId: this.state.sessionId }), this.setState({ isThinking: !1 }), this.clearThinkingWatchdog());
|
|
162
401
|
}
|
|
163
402
|
startNewSession() {
|
|
164
|
-
this.state.sessionId && this.state.isThinking && this.sendNow({ type: "run.stop", sessionId: this.state.sessionId }), this.queuedClientEvents = this.queuedClientEvents.filter((t) => t.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.send({
|
|
403
|
+
this.state.sessionId && this.state.isThinking && this.sendNow({ type: "run.stop", sessionId: this.state.sessionId }), this.cleanupSessionUserFilesApi(), this.queuedClientEvents = this.queuedClientEvents.filter((t) => t.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.send({
|
|
165
404
|
type: "session.reset",
|
|
166
405
|
sessionId: this.state.sessionId ?? void 0,
|
|
167
|
-
page:
|
|
406
|
+
page: y()
|
|
168
407
|
}), this.setState({
|
|
169
408
|
sessionId: null,
|
|
170
409
|
starterPrompts: [...this.state.starterPrompts],
|
|
@@ -177,15 +416,15 @@ class $ {
|
|
|
177
416
|
});
|
|
178
417
|
}
|
|
179
418
|
listSessions(t = {}) {
|
|
180
|
-
const s =
|
|
181
|
-
const
|
|
419
|
+
const s = R(), n = new Promise((i, o) => {
|
|
420
|
+
const c = window.setTimeout(() => {
|
|
182
421
|
this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
|
|
183
|
-
},
|
|
184
|
-
this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout:
|
|
422
|
+
}, Bt);
|
|
423
|
+
this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: c });
|
|
185
424
|
}), r = {
|
|
186
425
|
type: "sessions.list",
|
|
187
426
|
requestId: s,
|
|
188
|
-
page:
|
|
427
|
+
page: y(),
|
|
189
428
|
...t.cursor ? { cursor: t.cursor } : {},
|
|
190
429
|
...t.limit ? { limit: t.limit } : {}
|
|
191
430
|
};
|
|
@@ -207,11 +446,17 @@ class $ {
|
|
|
207
446
|
}), this.send({
|
|
208
447
|
type: "session.load",
|
|
209
448
|
sessionId: t,
|
|
210
|
-
page:
|
|
449
|
+
page: y()
|
|
211
450
|
});
|
|
212
451
|
}
|
|
213
452
|
send(t) {
|
|
214
|
-
this.sendNow(
|
|
453
|
+
this.sendNow(w(t)) || (this.queuedClientEvents.push(t), _(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
|
|
454
|
+
}
|
|
455
|
+
async getUploadToken() {
|
|
456
|
+
const t = this.options.token ?? await this.options.tokenProvider?.() ?? this.token ?? null;
|
|
457
|
+
if (!t)
|
|
458
|
+
throw new Error("Pluno attachment upload requires a token or tokenProvider");
|
|
459
|
+
return this.token = t, t;
|
|
215
460
|
}
|
|
216
461
|
sendNow(t) {
|
|
217
462
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
|
|
@@ -220,7 +465,7 @@ class $ {
|
|
|
220
465
|
try {
|
|
221
466
|
return s.send(JSON.stringify(t)), !0;
|
|
222
467
|
} catch (n) {
|
|
223
|
-
return
|
|
468
|
+
return p("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
|
|
224
469
|
message: n instanceof Error ? n.message : String(n),
|
|
225
470
|
queuedClientEventCount: this.queuedClientEvents.length,
|
|
226
471
|
isThinking: this.state.isThinking
|
|
@@ -231,9 +476,9 @@ class $ {
|
|
|
231
476
|
if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
|
|
232
477
|
return;
|
|
233
478
|
this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
|
|
234
|
-
const t =
|
|
479
|
+
const t = Vt();
|
|
235
480
|
this.sendNow(
|
|
236
|
-
|
|
481
|
+
w({
|
|
237
482
|
type: "starter_prompts.page_context",
|
|
238
483
|
pageUrl: t.pageUrl,
|
|
239
484
|
pageTitle: t.pageTitle,
|
|
@@ -245,14 +490,14 @@ class $ {
|
|
|
245
490
|
if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
|
|
246
491
|
return;
|
|
247
492
|
const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
|
|
248
|
-
|
|
493
|
+
_(this.options.clientId, this.queuedClientEvents);
|
|
249
494
|
for (let s = 0; s < t.length; s += 1) {
|
|
250
495
|
const n = t[s];
|
|
251
|
-
if (!this.sendNow(
|
|
252
|
-
this.queuedClientEvents.unshift(n, ...t.slice(s + 1)),
|
|
496
|
+
if (!this.sendNow(w(n))) {
|
|
497
|
+
this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), _(this.options.clientId, this.queuedClientEvents);
|
|
253
498
|
return;
|
|
254
499
|
}
|
|
255
|
-
|
|
500
|
+
_(this.options.clientId, this.queuedClientEvents);
|
|
256
501
|
}
|
|
257
502
|
}
|
|
258
503
|
handleServerEvent(t) {
|
|
@@ -260,36 +505,39 @@ class $ {
|
|
|
260
505
|
this.handleRunAck(t);
|
|
261
506
|
return;
|
|
262
507
|
}
|
|
263
|
-
if (
|
|
264
|
-
const s =
|
|
265
|
-
|
|
508
|
+
if (vt(t) && this.markThinkingProgress(), t.type === "auth.ok") {
|
|
509
|
+
const s = ee(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
|
|
510
|
+
p("web-sdk.agent", "Received auth.ok appearance", {
|
|
266
511
|
hasAppearance: n,
|
|
267
512
|
rawAppearance: t.appearance,
|
|
268
513
|
normalizedAppearance: s
|
|
269
|
-
}), this.runtimeHelperJavascript =
|
|
270
|
-
const r =
|
|
271
|
-
user:
|
|
514
|
+
}), this.runtimeHelperJavascript = se(t.runtimeHelpers)?.javascript ?? null;
|
|
515
|
+
const r = tt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, c = {
|
|
516
|
+
user: ae(t.user),
|
|
272
517
|
status: "connected"
|
|
273
518
|
};
|
|
274
|
-
(i || this.state.starterPrompts.length === 0) && (
|
|
519
|
+
(i || this.state.starterPrompts.length === 0) && (c.starterPrompts = r, c.starterPromptsLoading = r.length > 0 ? !1 : o), i && r.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (n || s) && (c.appearance = s), this.setState(c), i && r.length === 0 && !o && !Yt() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
|
|
275
520
|
type: "page.upsert",
|
|
276
521
|
sessionId: this.state.sessionId,
|
|
277
|
-
page:
|
|
522
|
+
page: y(),
|
|
278
523
|
model: this.options.model
|
|
279
524
|
});
|
|
280
525
|
return;
|
|
281
526
|
}
|
|
282
527
|
if (t.type === "starterPrompts.updated") {
|
|
283
528
|
this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
|
|
284
|
-
starterPrompts:
|
|
529
|
+
starterPrompts: tt(t, "starterPrompts"),
|
|
285
530
|
starterPromptsLoading: !1
|
|
286
531
|
});
|
|
287
532
|
return;
|
|
288
533
|
}
|
|
289
534
|
if (t.type === "conversation.state") {
|
|
290
|
-
const s = Array.isArray(t.items) ? t.items : [], n =
|
|
291
|
-
|
|
292
|
-
|
|
535
|
+
const s = Array.isArray(t.items) ? t.items : [], n = me(
|
|
536
|
+
this.state.messages,
|
|
537
|
+
ce(s, this.options.backendUrl)
|
|
538
|
+
), r = et(n), i = r ? null : Se(s);
|
|
539
|
+
this.latestRecoverableClientMessageId = i, Ie(n) && this.clearRetryTimers(), this.setState({
|
|
540
|
+
sessionId: I(t.session, "id") ?? this.state.sessionId,
|
|
293
541
|
messages: n,
|
|
294
542
|
...r ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : i ? {
|
|
295
543
|
assistantDraft: "",
|
|
@@ -304,22 +552,22 @@ class $ {
|
|
|
304
552
|
if (t.type === "sessions.page") {
|
|
305
553
|
const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
|
|
306
554
|
s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
|
|
307
|
-
sessions:
|
|
555
|
+
sessions: ue(t.sessions),
|
|
308
556
|
nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
|
|
309
557
|
}));
|
|
310
558
|
return;
|
|
311
559
|
}
|
|
312
560
|
if (t.type === "session.updated") {
|
|
313
|
-
this.clearRunAckResyncRetryTimer(), this.setState({ sessionId:
|
|
561
|
+
this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: I(t.session, "id") ?? this.state.sessionId });
|
|
314
562
|
return;
|
|
315
563
|
}
|
|
316
564
|
if (t.type === "session.item") {
|
|
317
|
-
const s =
|
|
565
|
+
const s = dt(t.item, this.options.backendUrl);
|
|
318
566
|
if (s) {
|
|
319
567
|
s.role === "assistant" && (this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
|
|
320
568
|
const n = t.item.data;
|
|
321
|
-
|
|
322
|
-
const r =
|
|
569
|
+
Ee(n) && this.clearRunAckResyncRetryTimer();
|
|
570
|
+
const r = fe(this.state.messages, s), i = et(r);
|
|
323
571
|
this.setState({
|
|
324
572
|
messages: r,
|
|
325
573
|
assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
|
|
@@ -401,7 +649,7 @@ class $ {
|
|
|
401
649
|
this.pendingSessionHistoryRequests.clear();
|
|
402
650
|
}
|
|
403
651
|
markThinkingProgress() {
|
|
404
|
-
!this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(
|
|
652
|
+
!this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(E), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
|
|
405
653
|
}
|
|
406
654
|
scheduleThinkingWatchdog(t) {
|
|
407
655
|
this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
|
|
@@ -418,29 +666,29 @@ class $ {
|
|
|
418
666
|
scheduleRunAckWatchdog(t) {
|
|
419
667
|
this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
|
|
420
668
|
this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
|
|
421
|
-
},
|
|
669
|
+
}, Ot);
|
|
422
670
|
}
|
|
423
671
|
recoverMissedRunAck(t) {
|
|
424
|
-
!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (
|
|
672
|
+
!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (p("web-sdk.agent", "Pluno run ack missed; resyncing session", {
|
|
425
673
|
sessionId: this.state.sessionId,
|
|
426
674
|
clientMessageId: t
|
|
427
675
|
}), this.resyncThinkingSession(), this.scheduleRunAckResyncRetry(t));
|
|
428
676
|
}
|
|
429
677
|
scheduleRunAckResyncRetry(t) {
|
|
430
678
|
this.clearRunAckResyncRetryTimer(), this.runAckResyncRetryTimer = window.setTimeout(() => {
|
|
431
|
-
this.runAckResyncRetryTimer = null, !((this.runAckRecoveryRetryAttemptsByClientMessageId[t] ?? 0) >= 1) && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || this.latestRecoverableClientMessageId !== t || (this.runAckRecoveryRetryAttemptsByClientMessageId[t] = 1, this.thinkingWatchdogRetryAttemptsByClientMessageId[t] =
|
|
679
|
+
this.runAckResyncRetryTimer = null, !((this.runAckRecoveryRetryAttemptsByClientMessageId[t] ?? 0) >= 1) && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || this.latestRecoverableClientMessageId !== t || (this.runAckRecoveryRetryAttemptsByClientMessageId[t] = 1, this.thinkingWatchdogRetryAttemptsByClientMessageId[t] = K, this.setState({
|
|
432
680
|
status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
|
|
433
681
|
isThinking: !0,
|
|
434
682
|
lastError: null
|
|
435
|
-
}),
|
|
683
|
+
}), p("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
|
|
436
684
|
sessionId: this.state.sessionId,
|
|
437
685
|
clientMessageId: t
|
|
438
686
|
}), this.state.sessionId ? this.send({
|
|
439
687
|
type: "chat.retry_last_user_message",
|
|
440
688
|
sessionId: this.state.sessionId,
|
|
441
689
|
clientMessageId: t
|
|
442
|
-
}) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(
|
|
443
|
-
},
|
|
690
|
+
}) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(E)));
|
|
691
|
+
}, Ft);
|
|
444
692
|
}
|
|
445
693
|
clearRunAckResyncRetryTimer() {
|
|
446
694
|
this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
|
|
@@ -453,33 +701,33 @@ class $ {
|
|
|
453
701
|
return;
|
|
454
702
|
const t = this.activeClientMessageId;
|
|
455
703
|
if (!t) {
|
|
456
|
-
|
|
704
|
+
p("web-sdk.agent", "Pluno thinking watchdog resyncing without active message id", {
|
|
457
705
|
sessionId: this.state.sessionId
|
|
458
|
-
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(
|
|
706
|
+
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(E);
|
|
459
707
|
return;
|
|
460
708
|
}
|
|
461
709
|
const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[t] ?? 0, n = this.thinkingWatchdogRetryAttemptsByClientMessageId[t] ?? 0;
|
|
462
710
|
if (s <= n) {
|
|
463
|
-
this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1,
|
|
711
|
+
this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, p("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
|
|
464
712
|
sessionId: this.state.sessionId,
|
|
465
713
|
clientMessageId: t,
|
|
466
714
|
resyncAttempts: s + 1
|
|
467
|
-
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(
|
|
715
|
+
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(qt);
|
|
468
716
|
return;
|
|
469
717
|
}
|
|
470
|
-
if (n >=
|
|
471
|
-
|
|
718
|
+
if (n >= K) {
|
|
719
|
+
p("web-sdk.agent", "Pluno thinking watchdog retry limit reached; continuing resync", {
|
|
472
720
|
sessionId: this.state.sessionId,
|
|
473
721
|
clientMessageId: t,
|
|
474
722
|
retryAttempts: n
|
|
475
|
-
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(
|
|
723
|
+
}), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(E);
|
|
476
724
|
return;
|
|
477
725
|
}
|
|
478
726
|
this.thinkingWatchdogRetryAttemptsByClientMessageId[t] = n + 1, this.setState({
|
|
479
727
|
status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
|
|
480
728
|
isThinking: !0,
|
|
481
729
|
lastError: null
|
|
482
|
-
}),
|
|
730
|
+
}), p("web-sdk.agent", "Pluno thinking watchdog retrying last user message", {
|
|
483
731
|
sessionId: this.state.sessionId,
|
|
484
732
|
clientMessageId: t,
|
|
485
733
|
retryAttempts: n + 1
|
|
@@ -487,113 +735,131 @@ class $ {
|
|
|
487
735
|
type: "chat.retry_last_user_message",
|
|
488
736
|
sessionId: this.state.sessionId,
|
|
489
737
|
clientMessageId: t
|
|
490
|
-
}) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(
|
|
738
|
+
}) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(E);
|
|
491
739
|
}
|
|
492
740
|
resyncThinkingSession() {
|
|
493
741
|
this.state.sessionId ? this.send({
|
|
494
742
|
type: "page.upsert",
|
|
495
743
|
sessionId: this.state.sessionId,
|
|
496
|
-
page:
|
|
744
|
+
page: y(),
|
|
497
745
|
model: this.options.model
|
|
498
746
|
}) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect());
|
|
499
747
|
}
|
|
500
748
|
async executeToolCall(t) {
|
|
501
|
-
const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
|
|
502
|
-
if (!s || !n || !
|
|
749
|
+
const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = typeof t.toolName == "string" ? t.toolName : null, i = typeof t.summary == "string" ? t.summary : "Running browser tool", o = t.rawInput;
|
|
750
|
+
if (!s || !n || !r)
|
|
751
|
+
return;
|
|
752
|
+
if (r !== "execute_code" || !Be(o)) {
|
|
753
|
+
this.send({
|
|
754
|
+
type: "tool.result",
|
|
755
|
+
sessionId: s,
|
|
756
|
+
callId: n,
|
|
757
|
+
toolName: r,
|
|
758
|
+
summary: i,
|
|
759
|
+
rawInput: w(o),
|
|
760
|
+
rawOutput: w({
|
|
761
|
+
ok: !1,
|
|
762
|
+
toolName: r,
|
|
763
|
+
error: `Unsupported browser tool: ${r}`
|
|
764
|
+
})
|
|
765
|
+
});
|
|
503
766
|
return;
|
|
504
|
-
const i = It(this.state.messages), o = kt(i);
|
|
505
|
-
let a = null, c;
|
|
506
|
-
try {
|
|
507
|
-
a = await this.executeRuntimeHelper(), c = await W(r).catch((u) => ({
|
|
508
|
-
ok: !1,
|
|
509
|
-
exception: {
|
|
510
|
-
message: u instanceof Error ? u.message : String(u)
|
|
511
|
-
}
|
|
512
|
-
}));
|
|
513
|
-
} finally {
|
|
514
|
-
o();
|
|
515
767
|
}
|
|
516
|
-
this.
|
|
768
|
+
const c = $t(this.state.messages);
|
|
769
|
+
this.installSessionUserFilesApi(c);
|
|
770
|
+
let a = null, d;
|
|
771
|
+
a = await this.executeRuntimeHelper(), d = await Q(o).catch((h) => ({
|
|
772
|
+
ok: !1,
|
|
773
|
+
exception: {
|
|
774
|
+
message: h instanceof Error ? h.message : String(h)
|
|
775
|
+
}
|
|
776
|
+
})), this.send({
|
|
517
777
|
type: "tool.result",
|
|
518
778
|
sessionId: s,
|
|
519
779
|
callId: n,
|
|
520
|
-
toolName:
|
|
521
|
-
summary:
|
|
522
|
-
rawInput:
|
|
523
|
-
rawOutput:
|
|
780
|
+
toolName: r,
|
|
781
|
+
summary: o.summary,
|
|
782
|
+
rawInput: w(o),
|
|
783
|
+
rawOutput: w(ne(d, a))
|
|
524
784
|
});
|
|
525
785
|
}
|
|
786
|
+
installSessionUserFilesApi(t) {
|
|
787
|
+
this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = zt(t, this.attachmentFiles, this.attachmentBlobCache);
|
|
788
|
+
}
|
|
789
|
+
cleanupSessionUserFilesApi() {
|
|
790
|
+
this.sessionUserFilesApiCleanup && (Gt(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
|
|
791
|
+
}
|
|
526
792
|
async executeRuntimeHelper() {
|
|
527
793
|
if (!this.runtimeHelperJavascript?.trim())
|
|
528
794
|
return null;
|
|
529
|
-
const t = await
|
|
795
|
+
const t = await Q({
|
|
530
796
|
javascript: this.runtimeHelperJavascript
|
|
531
797
|
});
|
|
532
|
-
return t.ok === !1 ?
|
|
798
|
+
return t.ok === !1 ? re(t) : null;
|
|
533
799
|
}
|
|
534
800
|
enableNetworkCapture() {
|
|
535
801
|
if (this.networkCaptureCleanup)
|
|
536
802
|
return;
|
|
537
803
|
const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
|
|
538
804
|
window.fetch = async (i, o) => {
|
|
539
|
-
const
|
|
805
|
+
const c = Date.now(), a = new Date(c).toISOString(), d = i instanceof Request ? i : null, h = typeof i == "string" ? i : i instanceof URL ? i.toString() : d?.url ?? "", u = (o?.method ?? d?.method ?? "GET").toUpperCase(), l = rt(new Headers(o?.headers ?? d?.headers ?? void 0)), f = await We(d, o);
|
|
540
806
|
try {
|
|
541
|
-
const
|
|
807
|
+
const g = await t(i, o);
|
|
542
808
|
return this.enqueueNetworkEvent({
|
|
543
|
-
requestId:
|
|
544
|
-
url:
|
|
545
|
-
method:
|
|
546
|
-
requestHeaders:
|
|
547
|
-
requestBody:
|
|
809
|
+
requestId: P("fetch"),
|
|
810
|
+
url: h,
|
|
811
|
+
method: u,
|
|
812
|
+
requestHeaders: l,
|
|
813
|
+
requestBody: f,
|
|
548
814
|
resourceType: "fetch",
|
|
549
|
-
responseStatus:
|
|
550
|
-
responseHeaders:
|
|
551
|
-
responseBody: await
|
|
552
|
-
startedAt:
|
|
553
|
-
durationMs: Date.now() -
|
|
554
|
-
}),
|
|
555
|
-
} catch (
|
|
815
|
+
responseStatus: g.status,
|
|
816
|
+
responseHeaders: rt(g.headers),
|
|
817
|
+
responseBody: await xe(g),
|
|
818
|
+
startedAt: a,
|
|
819
|
+
durationMs: Date.now() - c
|
|
820
|
+
}), g;
|
|
821
|
+
} catch (g) {
|
|
556
822
|
throw this.enqueueNetworkEvent({
|
|
557
|
-
requestId:
|
|
558
|
-
url:
|
|
559
|
-
method:
|
|
560
|
-
requestHeaders:
|
|
561
|
-
requestBody:
|
|
823
|
+
requestId: P("fetch"),
|
|
824
|
+
url: h,
|
|
825
|
+
method: u,
|
|
826
|
+
requestHeaders: l,
|
|
827
|
+
requestBody: f,
|
|
562
828
|
resourceType: "fetch",
|
|
563
|
-
errorText:
|
|
564
|
-
startedAt:
|
|
565
|
-
durationMs: Date.now() -
|
|
566
|
-
}),
|
|
829
|
+
errorText: g instanceof Error ? g.message : String(g),
|
|
830
|
+
startedAt: a,
|
|
831
|
+
durationMs: Date.now() - c
|
|
832
|
+
}), g;
|
|
567
833
|
}
|
|
568
|
-
}, XMLHttpRequest.prototype.open = function(o,
|
|
834
|
+
}, XMLHttpRequest.prototype.open = function(o, c, a, d, h) {
|
|
569
835
|
return this.__plunoMeta = {
|
|
570
|
-
requestId:
|
|
836
|
+
requestId: P("xhr"),
|
|
571
837
|
method: String(o ?? "GET").toUpperCase(),
|
|
572
|
-
url: typeof
|
|
838
|
+
url: typeof c == "string" ? c : c.toString(),
|
|
573
839
|
requestHeaders: {},
|
|
574
840
|
startedAtMs: Date.now(),
|
|
575
841
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
576
|
-
}, s.call(this, o,
|
|
577
|
-
}, XMLHttpRequest.prototype.setRequestHeader = function(o,
|
|
578
|
-
const
|
|
579
|
-
if (
|
|
580
|
-
const
|
|
581
|
-
|
|
842
|
+
}, s.call(this, o, c, a ?? !0, d ?? void 0, h ?? void 0);
|
|
843
|
+
}, XMLHttpRequest.prototype.setRequestHeader = function(o, c) {
|
|
844
|
+
const a = this.__plunoMeta;
|
|
845
|
+
if (a) {
|
|
846
|
+
const d = a.requestHeaders ?? {};
|
|
847
|
+
d[o] = c, a.requestHeaders = d;
|
|
582
848
|
}
|
|
583
|
-
return n.call(this, o,
|
|
849
|
+
return n.call(this, o, c);
|
|
584
850
|
}, XMLHttpRequest.prototype.send = function(o) {
|
|
585
|
-
const
|
|
586
|
-
requestId:
|
|
851
|
+
const c = window.__plunoProductAgentInstance, a = this.__plunoMeta ?? {
|
|
852
|
+
requestId: P("xhr"),
|
|
587
853
|
method: "GET",
|
|
588
854
|
url: "",
|
|
589
855
|
requestHeaders: {},
|
|
590
856
|
startedAtMs: Date.now(),
|
|
591
857
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
592
858
|
};
|
|
593
|
-
return
|
|
859
|
+
return a.requestBody = Tt(o), this.__plunoMeta = a, this.addEventListener(
|
|
594
860
|
"loadend",
|
|
595
861
|
function() {
|
|
596
|
-
!
|
|
862
|
+
!c || !this.__plunoMeta || c.enqueueNetworkEvent({
|
|
597
863
|
requestId: String(this.__plunoMeta.requestId),
|
|
598
864
|
url: String(this.__plunoMeta.url ?? ""),
|
|
599
865
|
method: String(this.__plunoMeta.method ?? "GET"),
|
|
@@ -601,8 +867,8 @@ class $ {
|
|
|
601
867
|
requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
|
|
602
868
|
resourceType: "xhr",
|
|
603
869
|
responseStatus: this.status,
|
|
604
|
-
responseHeaders:
|
|
605
|
-
responseBody:
|
|
870
|
+
responseHeaders: ve(this.getAllResponseHeaders()),
|
|
871
|
+
responseBody: Le(this),
|
|
606
872
|
errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
|
|
607
873
|
startedAt: String(this.__plunoMeta.startedAt),
|
|
608
874
|
durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
|
|
@@ -615,32 +881,32 @@ class $ {
|
|
|
615
881
|
};
|
|
616
882
|
}
|
|
617
883
|
enqueueNetworkEvent(t) {
|
|
618
|
-
this.queuedNetworkEvents.push(
|
|
884
|
+
this.queuedNetworkEvents.push(w(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
|
|
619
885
|
this.networkBatchTimer = null;
|
|
620
886
|
const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
|
|
621
887
|
s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
|
|
622
888
|
type: "network.batch",
|
|
623
889
|
sessionId: this.state.sessionId ?? void 0,
|
|
624
|
-
page:
|
|
890
|
+
page: y(),
|
|
625
891
|
events: s
|
|
626
892
|
});
|
|
627
|
-
},
|
|
893
|
+
}, Ht));
|
|
628
894
|
}
|
|
629
895
|
scheduleReconnect() {
|
|
630
896
|
this.reconnectTimer !== null || this.state.status === "closed" || (this.reconnectTimer = window.setTimeout(() => {
|
|
631
897
|
this.reconnectTimer = null, this.connect().catch((t) => {
|
|
632
|
-
|
|
898
|
+
p("web-sdk.agent", "Pluno reconnect failed; retrying", {
|
|
633
899
|
message: t instanceof Error ? t.message : String(t),
|
|
634
900
|
queuedClientEventCount: this.queuedClientEvents.length,
|
|
635
901
|
isThinking: this.state.isThinking
|
|
636
902
|
}), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect();
|
|
637
903
|
});
|
|
638
|
-
},
|
|
904
|
+
}, Nt));
|
|
639
905
|
}
|
|
640
906
|
startHeartbeat() {
|
|
641
907
|
this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
|
|
642
908
|
this.sendNow({ type: "runtime.ping" });
|
|
643
|
-
},
|
|
909
|
+
}, Dt);
|
|
644
910
|
}
|
|
645
911
|
stopHeartbeat() {
|
|
646
912
|
this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
@@ -650,13 +916,13 @@ class $ {
|
|
|
650
916
|
...this.state,
|
|
651
917
|
...t,
|
|
652
918
|
...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {}
|
|
653
|
-
},
|
|
919
|
+
}, Ce(this.options.clientId, this.state), this.emit("state", this.getState());
|
|
654
920
|
}
|
|
655
921
|
emit(t, s) {
|
|
656
922
|
this.listeners[t]?.forEach((r) => r(s));
|
|
657
923
|
}
|
|
658
924
|
}
|
|
659
|
-
function
|
|
925
|
+
function p(e, t, s) {
|
|
660
926
|
if (typeof window > "u")
|
|
661
927
|
return;
|
|
662
928
|
const n = window, r = {
|
|
@@ -667,15 +933,15 @@ function l(e, t, s) {
|
|
|
667
933
|
}, i = n.__plunoProductAgentDiagnostics__ ?? [];
|
|
668
934
|
i.push(r), i.length > 120 && i.splice(0, i.length - 120), n.__plunoProductAgentDiagnostics__ = i, n.__PLUNO_PRODUCT_AGENT_DIAGNOSTICS__ = () => [...i], window.dispatchEvent(new CustomEvent("product-agent:preview-diagnostic", { detail: r }));
|
|
669
935
|
}
|
|
670
|
-
function
|
|
936
|
+
function Y(e) {
|
|
671
937
|
const t = typeof e == "function" ? e() : e;
|
|
672
938
|
return t && Object.keys(t).length > 0 ? t : void 0;
|
|
673
939
|
}
|
|
674
|
-
function
|
|
940
|
+
function vt(e) {
|
|
675
941
|
return e.type === "conversation.state" || e.type === "session.updated" || e.type === "session.item" || e.type === "chat.assistant_delta" || e.type === "chat.assistant_done" || e.type === "tool.call";
|
|
676
942
|
}
|
|
677
|
-
const
|
|
678
|
-
function
|
|
943
|
+
const jt = 5e3;
|
|
944
|
+
function $t(e) {
|
|
679
945
|
const t = [];
|
|
680
946
|
for (const s of e)
|
|
681
947
|
s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
|
|
@@ -686,76 +952,144 @@ function It(e) {
|
|
|
686
952
|
});
|
|
687
953
|
return t;
|
|
688
954
|
}
|
|
689
|
-
function
|
|
690
|
-
const
|
|
691
|
-
id:
|
|
692
|
-
name:
|
|
693
|
-
mimeType:
|
|
694
|
-
sizeBytes:
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
955
|
+
function zt(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
|
|
956
|
+
const n = new Map(e.map((u) => [u.id, u])), r = (u) => ({
|
|
957
|
+
id: u.id,
|
|
958
|
+
name: u.name,
|
|
959
|
+
mimeType: u.mimeType,
|
|
960
|
+
sizeBytes: u.sizeBytes,
|
|
961
|
+
type: u.mimeType,
|
|
962
|
+
size: u.sizeBytes
|
|
963
|
+
}), i = (u) => {
|
|
964
|
+
const l = n.get(u);
|
|
965
|
+
if (!l)
|
|
966
|
+
throw new Error(`Unknown Pluno user file: ${u}`);
|
|
967
|
+
return l;
|
|
968
|
+
}, o = async (u) => {
|
|
969
|
+
const l = i(u), f = t.get(l.id);
|
|
970
|
+
if (f)
|
|
971
|
+
return f;
|
|
972
|
+
const g = s.get(l.id);
|
|
973
|
+
if (g)
|
|
974
|
+
return g;
|
|
975
|
+
const S = await Rt(l.id).then((m) => m?.blob ?? null).catch((m) => (p("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
|
|
976
|
+
attachmentId: l.id,
|
|
977
|
+
name: l.name,
|
|
978
|
+
message: m instanceof Error ? m.message : String(m)
|
|
979
|
+
}), null));
|
|
980
|
+
if (S)
|
|
981
|
+
return s.set(l.id, S), S;
|
|
982
|
+
if (!l.fileUrl)
|
|
983
|
+
throw new Error(`Pluno user file is missing content: ${u}`);
|
|
984
|
+
const z = await fetch(l.fileUrl, Ne(l.fileUrl));
|
|
985
|
+
if (!z.ok)
|
|
986
|
+
throw new Error(`Failed to load Pluno user file: ${u}`);
|
|
987
|
+
const D = await z.blob();
|
|
988
|
+
s.set(l.id, D);
|
|
989
|
+
const G = Date.now();
|
|
990
|
+
return it({
|
|
991
|
+
attachmentId: l.id,
|
|
992
|
+
name: l.name,
|
|
993
|
+
mimeType: l.mimeType,
|
|
994
|
+
sizeBytes: l.sizeBytes,
|
|
995
|
+
blob: D,
|
|
996
|
+
fileUrl: l.fileUrl,
|
|
997
|
+
gcsPath: l.gcsPath,
|
|
998
|
+
createdAt: G,
|
|
999
|
+
lastUsedAt: G
|
|
1000
|
+
}).catch((m) => {
|
|
1001
|
+
p("web-sdk.attachments", "Failed to cache Product Agent attachment from fileUrl", {
|
|
1002
|
+
attachmentId: l.id,
|
|
1003
|
+
name: l.name,
|
|
1004
|
+
message: m instanceof Error ? m.message : String(m)
|
|
1005
|
+
});
|
|
1006
|
+
}), D;
|
|
1007
|
+
}, c = async (u) => {
|
|
1008
|
+
const l = i(u), f = await o(u), g = l.mimeType.startsWith("image/") ? l.mimeType : f.type || l.mimeType;
|
|
1009
|
+
if (!g.startsWith("image/"))
|
|
1010
|
+
throw new Error(`Pluno user file is not an image: ${u}`);
|
|
1011
|
+
const S = f.type === g ? f : new Blob([f], { type: g });
|
|
1012
|
+
return {
|
|
1013
|
+
type: "pluno.userFiles.inspectImage",
|
|
1014
|
+
id: l.id,
|
|
1015
|
+
name: l.name,
|
|
1016
|
+
mimeType: g,
|
|
1017
|
+
sizeBytes: l.sizeBytes,
|
|
1018
|
+
imageAttached: !0,
|
|
1019
|
+
dataUrl: await Z(S)
|
|
1020
|
+
};
|
|
1021
|
+
}, a = globalThis, d = a.pluno?.userFiles, h = Object.prototype.hasOwnProperty.call(a.pluno ?? {}, "userFiles");
|
|
1022
|
+
return a.pluno = {
|
|
1023
|
+
...a.pluno ?? {},
|
|
706
1024
|
userFiles: {
|
|
707
|
-
list: () => e.map(
|
|
708
|
-
get: (
|
|
709
|
-
const
|
|
710
|
-
return
|
|
1025
|
+
list: () => e.map(r),
|
|
1026
|
+
get: (u) => {
|
|
1027
|
+
const l = n.get(u);
|
|
1028
|
+
return l ? r(l) : null;
|
|
711
1029
|
},
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
1030
|
+
inspectImage: c,
|
|
1031
|
+
getDataUrl: async (u) => (i(u), await Z(await o(u))),
|
|
1032
|
+
getBlob: o,
|
|
1033
|
+
getArrayBuffer: async (u) => await (await o(u)).arrayBuffer(),
|
|
1034
|
+
getFile: async (u) => {
|
|
1035
|
+
const l = i(u);
|
|
1036
|
+
return new File([await o(u)], l.name, { type: l.mimeType });
|
|
718
1037
|
}
|
|
719
1038
|
}
|
|
720
1039
|
}, () => {
|
|
721
|
-
const
|
|
722
|
-
if (
|
|
723
|
-
|
|
724
|
-
...
|
|
725
|
-
userFiles:
|
|
1040
|
+
const u = a.pluno ?? {};
|
|
1041
|
+
if (h) {
|
|
1042
|
+
a.pluno = {
|
|
1043
|
+
...u,
|
|
1044
|
+
userFiles: d
|
|
726
1045
|
};
|
|
727
1046
|
return;
|
|
728
1047
|
}
|
|
729
|
-
const { userFiles:
|
|
730
|
-
|
|
1048
|
+
const { userFiles: l, ...f } = u;
|
|
1049
|
+
a.pluno = f;
|
|
731
1050
|
};
|
|
732
1051
|
}
|
|
733
|
-
function
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
1052
|
+
function Gt(e) {
|
|
1053
|
+
try {
|
|
1054
|
+
e();
|
|
1055
|
+
} catch {
|
|
1056
|
+
}
|
|
738
1057
|
}
|
|
739
|
-
|
|
1058
|
+
function Z(e) {
|
|
1059
|
+
return new Promise((t, s) => {
|
|
1060
|
+
const n = new FileReader();
|
|
1061
|
+
n.onload = () => {
|
|
1062
|
+
if (typeof n.result == "string") {
|
|
1063
|
+
t(n.result);
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
s(new Error("Failed to read Pluno user file"));
|
|
1067
|
+
}, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
async function Q(e) {
|
|
740
1071
|
const t = Object.getPrototypeOf(async function() {
|
|
741
|
-
}).constructor, s =
|
|
1072
|
+
}).constructor, s = e.timeoutMs ?? jt, n = Date.now(), r = [];
|
|
1073
|
+
let i;
|
|
1074
|
+
const o = {
|
|
742
1075
|
log: console.log,
|
|
743
1076
|
info: console.info,
|
|
744
1077
|
warn: console.warn,
|
|
745
1078
|
error: console.error
|
|
746
|
-
},
|
|
747
|
-
r.push({ level: a, args:
|
|
1079
|
+
}, c = (a) => (...d) => {
|
|
1080
|
+
r.push({ level: a, args: d }), o[a](...d);
|
|
748
1081
|
};
|
|
749
|
-
console.log =
|
|
1082
|
+
console.log = c("log"), console.info = c("info"), console.warn = c("warn"), console.error = c("error");
|
|
750
1083
|
try {
|
|
751
|
-
|
|
1084
|
+
const a = /* @__PURE__ */ Symbol("execute_code_timeout"), d = await Promise.race([
|
|
1085
|
+
new t(e.javascript)(),
|
|
1086
|
+
new Promise((h) => {
|
|
1087
|
+
i = window.setTimeout(() => h(a), s);
|
|
1088
|
+
})
|
|
1089
|
+
]);
|
|
1090
|
+
return d === a ? Xt(s) : {
|
|
752
1091
|
ok: !0,
|
|
753
|
-
result:
|
|
754
|
-
new t(e.javascript)(),
|
|
755
|
-
new Promise(
|
|
756
|
-
(c, u) => window.setTimeout(() => u(new Error(`execute_code timed out after ${s}ms`)), s)
|
|
757
|
-
)
|
|
758
|
-
]),
|
|
1092
|
+
result: d,
|
|
759
1093
|
console: r,
|
|
760
1094
|
metadata: {
|
|
761
1095
|
durationMs: Date.now() - n,
|
|
@@ -779,18 +1113,32 @@ async function W(e) {
|
|
|
779
1113
|
}
|
|
780
1114
|
};
|
|
781
1115
|
} finally {
|
|
782
|
-
console.log =
|
|
1116
|
+
i !== void 0 && window.clearTimeout(i), console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
|
|
783
1117
|
}
|
|
784
1118
|
}
|
|
785
|
-
function
|
|
1119
|
+
function Xt(e) {
|
|
1120
|
+
return {
|
|
1121
|
+
ok: !1,
|
|
1122
|
+
exception: {
|
|
1123
|
+
name: "Error",
|
|
1124
|
+
message: `execute_code timed out after ${e}ms`
|
|
1125
|
+
},
|
|
1126
|
+
metadata: {
|
|
1127
|
+
durationMs: e,
|
|
1128
|
+
url: location.href,
|
|
1129
|
+
origin: location.origin
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function Kt(e) {
|
|
786
1134
|
return e.replace(/\/+$/, "");
|
|
787
1135
|
}
|
|
788
|
-
function
|
|
1136
|
+
function Jt(e) {
|
|
789
1137
|
const t = new URL("/api/product-agent/embed/ws", e);
|
|
790
1138
|
return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
|
|
791
1139
|
}
|
|
792
|
-
function
|
|
793
|
-
const e =
|
|
1140
|
+
function y() {
|
|
1141
|
+
const e = lt();
|
|
794
1142
|
return {
|
|
795
1143
|
url: location.href,
|
|
796
1144
|
title: document.title,
|
|
@@ -798,17 +1146,17 @@ function f() {
|
|
|
798
1146
|
...e ? { plunoProductAgentUi: e } : {}
|
|
799
1147
|
};
|
|
800
1148
|
}
|
|
801
|
-
function
|
|
1149
|
+
function Vt() {
|
|
802
1150
|
return {
|
|
803
1151
|
pageUrl: location.href,
|
|
804
1152
|
pageTitle: document.title,
|
|
805
|
-
htmlContent:
|
|
1153
|
+
htmlContent: Zt()
|
|
806
1154
|
};
|
|
807
1155
|
}
|
|
808
|
-
function
|
|
809
|
-
return
|
|
1156
|
+
function Yt() {
|
|
1157
|
+
return lt()?.surface === "browser_extension_sdk_preview";
|
|
810
1158
|
}
|
|
811
|
-
function
|
|
1159
|
+
function Zt() {
|
|
812
1160
|
const e = document.body?.cloneNode(!0);
|
|
813
1161
|
return e instanceof HTMLElement ? (e.querySelectorAll(
|
|
814
1162
|
[
|
|
@@ -832,9 +1180,9 @@ function At() {
|
|
|
832
1180
|
s.name === "href" || s.name === "aria-label" || s.name === "role" || t.removeAttribute(s.name);
|
|
833
1181
|
}), e.textContent?.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[email]").replace(/\b(?:\d[ -]*?){13,19}\b/g, "[number]").replace(/\b(?:sk|pk|tok|key|secret|token)_[A-Za-z0-9_-]{8,}\b/gi, "[secret]").replace(/\s+/g, " ").trim().slice(0, 12e3) ?? "") : "";
|
|
834
1182
|
}
|
|
835
|
-
function
|
|
836
|
-
const e = document.querySelector(
|
|
837
|
-
if (!(e ?? document.querySelector(
|
|
1183
|
+
function lt() {
|
|
1184
|
+
const e = document.querySelector(X);
|
|
1185
|
+
if (!(e ?? document.querySelector(H)))
|
|
838
1186
|
return;
|
|
839
1187
|
const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
|
|
840
1188
|
return {
|
|
@@ -843,28 +1191,28 @@ function G() {
|
|
|
843
1191
|
selectors: [
|
|
844
1192
|
{
|
|
845
1193
|
name: "widget_host",
|
|
846
|
-
selector: s === "browser_extension_sdk_preview" ?
|
|
1194
|
+
selector: s === "browser_extension_sdk_preview" ? X : H,
|
|
847
1195
|
description: "Finds Pluno's shadow-host element in the host page DOM."
|
|
848
1196
|
},
|
|
849
1197
|
{
|
|
850
1198
|
name: "widget_root",
|
|
851
|
-
selector:
|
|
1199
|
+
selector: Pt,
|
|
852
1200
|
description: "Finds Pluno's widget root inside the widget host shadow root."
|
|
853
1201
|
},
|
|
854
1202
|
{
|
|
855
1203
|
name: "widget_panel",
|
|
856
|
-
selector:
|
|
1204
|
+
selector: Mt,
|
|
857
1205
|
description: "Finds Pluno's open chat panel inside the widget host shadow root."
|
|
858
1206
|
},
|
|
859
1207
|
{
|
|
860
1208
|
name: "widget_timeline",
|
|
861
|
-
selector:
|
|
1209
|
+
selector: bt,
|
|
862
1210
|
description: "Finds Pluno's chat timeline inside the widget host shadow root."
|
|
863
1211
|
}
|
|
864
1212
|
]
|
|
865
1213
|
};
|
|
866
1214
|
}
|
|
867
|
-
function
|
|
1215
|
+
function Qt(e) {
|
|
868
1216
|
try {
|
|
869
1217
|
const t = JSON.parse(e);
|
|
870
1218
|
return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
|
|
@@ -872,33 +1220,33 @@ function Mt(e) {
|
|
|
872
1220
|
return { type: "error", message: "Invalid server event" };
|
|
873
1221
|
}
|
|
874
1222
|
}
|
|
875
|
-
function
|
|
1223
|
+
function tt(e, t) {
|
|
876
1224
|
if (!e || typeof e != "object")
|
|
877
1225
|
return [];
|
|
878
1226
|
const s = e[t];
|
|
879
1227
|
return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
|
|
880
1228
|
}
|
|
881
|
-
function
|
|
1229
|
+
function te(e) {
|
|
882
1230
|
return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
|
|
883
1231
|
}
|
|
884
|
-
function
|
|
1232
|
+
function ee(e) {
|
|
885
1233
|
if (!e || typeof e != "object")
|
|
886
1234
|
return null;
|
|
887
|
-
const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, o = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null,
|
|
888
|
-
return !r && !i && !o &&
|
|
1235
|
+
const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, o = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, c = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
|
|
1236
|
+
return !r && !i && !o && c === null ? null : {
|
|
889
1237
|
...r ? { accentColor: r } : {},
|
|
890
1238
|
...i ? { colorScheme: i } : {},
|
|
891
1239
|
...o ? { fontFamily: o } : {},
|
|
892
|
-
...
|
|
1240
|
+
...c !== null ? { scribbleStyle: c } : {}
|
|
893
1241
|
};
|
|
894
1242
|
}
|
|
895
|
-
function
|
|
1243
|
+
function se(e) {
|
|
896
1244
|
if (!e || typeof e != "object")
|
|
897
1245
|
return null;
|
|
898
1246
|
const t = e.javascript;
|
|
899
1247
|
return typeof t != "string" || !t.trim() ? null : { javascript: t };
|
|
900
1248
|
}
|
|
901
|
-
function
|
|
1249
|
+
function ne(e, t) {
|
|
902
1250
|
return t ? e && typeof e == "object" ? {
|
|
903
1251
|
...e,
|
|
904
1252
|
helperError: t
|
|
@@ -908,30 +1256,30 @@ function Ut(e, t) {
|
|
|
908
1256
|
helperError: t
|
|
909
1257
|
} : e;
|
|
910
1258
|
}
|
|
911
|
-
function
|
|
1259
|
+
function re(e) {
|
|
912
1260
|
if (!e || typeof e != "object")
|
|
913
1261
|
return e;
|
|
914
1262
|
const t = e;
|
|
915
1263
|
return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
|
|
916
1264
|
}
|
|
917
|
-
function
|
|
1265
|
+
function ie() {
|
|
918
1266
|
const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
|
|
919
1267
|
if (t)
|
|
920
1268
|
return t;
|
|
921
1269
|
const s = crypto.randomUUID();
|
|
922
1270
|
return window.localStorage.setItem(e, s), s;
|
|
923
1271
|
}
|
|
924
|
-
function
|
|
925
|
-
const e = window.sessionStorage.getItem(
|
|
1272
|
+
function oe() {
|
|
1273
|
+
const e = window.sessionStorage.getItem(V);
|
|
926
1274
|
if (e)
|
|
927
1275
|
return e;
|
|
928
1276
|
const t = crypto.randomUUID();
|
|
929
|
-
return window.sessionStorage.setItem(
|
|
1277
|
+
return window.sessionStorage.setItem(V, t), t;
|
|
930
1278
|
}
|
|
931
|
-
function
|
|
1279
|
+
function R() {
|
|
932
1280
|
return crypto.randomUUID();
|
|
933
1281
|
}
|
|
934
|
-
function
|
|
1282
|
+
function ae(e) {
|
|
935
1283
|
if (!e || typeof e != "object")
|
|
936
1284
|
return null;
|
|
937
1285
|
const t = e, s = typeof t.id == "string" ? t.id : null;
|
|
@@ -942,23 +1290,23 @@ function Ot(e) {
|
|
|
942
1290
|
avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
|
|
943
1291
|
} : null;
|
|
944
1292
|
}
|
|
945
|
-
function
|
|
946
|
-
return Array.isArray(e) ?
|
|
947
|
-
|
|
948
|
-
e.map(
|
|
1293
|
+
function ce(e, t) {
|
|
1294
|
+
return Array.isArray(e) ? W(
|
|
1295
|
+
x(
|
|
1296
|
+
e.map((s) => dt(s, t)).filter((s) => s !== null)
|
|
949
1297
|
)
|
|
950
1298
|
) : [];
|
|
951
1299
|
}
|
|
952
|
-
function
|
|
1300
|
+
function ue(e) {
|
|
953
1301
|
return Array.isArray(e) ? e.flatMap((t) => {
|
|
954
1302
|
if (!t || typeof t != "object")
|
|
955
1303
|
return [];
|
|
956
|
-
const s = t, n =
|
|
1304
|
+
const s = t, n = I(s, "id"), r = I(s, "createdAt"), i = I(s, "updatedAt"), o = I(s, "lastActiveAt");
|
|
957
1305
|
return !n || !r || !i || !o ? [] : [
|
|
958
1306
|
{
|
|
959
1307
|
id: n,
|
|
960
|
-
title:
|
|
961
|
-
firstUserMessage:
|
|
1308
|
+
title: I(s, "title"),
|
|
1309
|
+
firstUserMessage: I(s, "firstUserMessage"),
|
|
962
1310
|
currentPage: s.currentPage ?? null,
|
|
963
1311
|
createdAt: r,
|
|
964
1312
|
updatedAt: i,
|
|
@@ -967,51 +1315,51 @@ function Wt(e) {
|
|
|
967
1315
|
];
|
|
968
1316
|
}) : [];
|
|
969
1317
|
}
|
|
970
|
-
function
|
|
1318
|
+
function dt(e, t) {
|
|
971
1319
|
if (!e || typeof e != "object")
|
|
972
1320
|
return null;
|
|
973
|
-
const
|
|
974
|
-
if (!
|
|
1321
|
+
const s = e, n = s.data;
|
|
1322
|
+
if (!n || typeof n != "object")
|
|
975
1323
|
return null;
|
|
976
|
-
const
|
|
977
|
-
if (
|
|
978
|
-
const
|
|
1324
|
+
const r = n;
|
|
1325
|
+
if (r.type === "message") {
|
|
1326
|
+
const i = r.role === "assistant" ? "assistant" : r.role === "user" ? "user" : "system";
|
|
979
1327
|
return {
|
|
980
|
-
id: String(
|
|
981
|
-
role:
|
|
982
|
-
content:
|
|
983
|
-
createdAt: typeof
|
|
984
|
-
respondsToUserMessageId:
|
|
985
|
-
...
|
|
986
|
-
attachments:
|
|
1328
|
+
id: String(s.id ?? crypto.randomUUID()),
|
|
1329
|
+
role: i,
|
|
1330
|
+
content: ge(r.content),
|
|
1331
|
+
createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1332
|
+
respondsToUserMessageId: q(r) ?? void 0,
|
|
1333
|
+
...k(r) ? { runId: k(r) } : {},
|
|
1334
|
+
attachments: mt(r.attachments, t)
|
|
987
1335
|
};
|
|
988
1336
|
}
|
|
989
|
-
return
|
|
990
|
-
id: String(
|
|
1337
|
+
return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" ? {
|
|
1338
|
+
id: String(s.id ?? crypto.randomUUID()),
|
|
991
1339
|
role: "tool",
|
|
992
|
-
content:
|
|
993
|
-
createdAt: typeof
|
|
994
|
-
respondsToUserMessageId:
|
|
995
|
-
...
|
|
996
|
-
dataType: String(
|
|
997
|
-
toolName: typeof
|
|
998
|
-
callId:
|
|
999
|
-
loading:
|
|
1000
|
-
} :
|
|
1001
|
-
id: String(
|
|
1340
|
+
content: de(r),
|
|
1341
|
+
createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1342
|
+
respondsToUserMessageId: q(r) ?? void 0,
|
|
1343
|
+
...k(r) ? { runId: k(r) } : {},
|
|
1344
|
+
dataType: String(r.type),
|
|
1345
|
+
toolName: typeof r.name == "string" ? r.name : void 0,
|
|
1346
|
+
callId: pe(r) ?? void 0,
|
|
1347
|
+
loading: r.localExecutionStatus === "running"
|
|
1348
|
+
} : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
|
|
1349
|
+
id: String(s.id ?? crypto.randomUUID()),
|
|
1002
1350
|
role: "system",
|
|
1003
|
-
content:
|
|
1004
|
-
createdAt: typeof
|
|
1005
|
-
respondsToUserMessageId:
|
|
1006
|
-
...
|
|
1007
|
-
dataType: String(
|
|
1008
|
-
loading:
|
|
1351
|
+
content: le(r),
|
|
1352
|
+
createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1353
|
+
respondsToUserMessageId: q(r) ?? void 0,
|
|
1354
|
+
...k(r) ? { runId: k(r) } : {},
|
|
1355
|
+
dataType: String(r.type),
|
|
1356
|
+
loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying")
|
|
1009
1357
|
} : null;
|
|
1010
1358
|
}
|
|
1011
|
-
function
|
|
1359
|
+
function le(e) {
|
|
1012
1360
|
return typeof e.message == "string" && e.message.trim().length > 0 ? e.message.replace(/Product Agent/g, "Pluno") : e.type === "run_status" && e.status === "interrupted" ? "Pluno was interrupted before it could finish this message." : e.type === "run_status" && e.status === "stopped" ? "Pluno stopped." : "Pluno run status changed.";
|
|
1013
1361
|
}
|
|
1014
|
-
function
|
|
1362
|
+
function de(e) {
|
|
1015
1363
|
if (e.type === "web_search_call") {
|
|
1016
1364
|
const t = e.action;
|
|
1017
1365
|
if (t && typeof t == "object") {
|
|
@@ -1023,9 +1371,9 @@ function Lt(e) {
|
|
|
1023
1371
|
}
|
|
1024
1372
|
return "Searching the web";
|
|
1025
1373
|
}
|
|
1026
|
-
return
|
|
1374
|
+
return he(e);
|
|
1027
1375
|
}
|
|
1028
|
-
function
|
|
1376
|
+
function he(e) {
|
|
1029
1377
|
if (typeof e.summary == "string" && e.summary.trim().length > 0)
|
|
1030
1378
|
return e.summary;
|
|
1031
1379
|
if (typeof e.arguments == "string")
|
|
@@ -1038,11 +1386,11 @@ function vt(e) {
|
|
|
1038
1386
|
}
|
|
1039
1387
|
return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
|
|
1040
1388
|
}
|
|
1041
|
-
function
|
|
1389
|
+
function pe(e) {
|
|
1042
1390
|
const t = e.callId ?? e.call_id;
|
|
1043
1391
|
return typeof t == "string" && t ? t : null;
|
|
1044
1392
|
}
|
|
1045
|
-
function
|
|
1393
|
+
function ge(e) {
|
|
1046
1394
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
|
|
1047
1395
|
if (!t || typeof t != "object")
|
|
1048
1396
|
return "";
|
|
@@ -1050,14 +1398,40 @@ function jt(e) {
|
|
|
1050
1398
|
return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
|
|
1051
1399
|
}).filter(Boolean).join("") : "";
|
|
1052
1400
|
}
|
|
1053
|
-
function
|
|
1054
|
-
const s =
|
|
1055
|
-
if (
|
|
1056
|
-
return
|
|
1057
|
-
|
|
1058
|
-
|
|
1401
|
+
function fe(e, t) {
|
|
1402
|
+
const s = ht(e, t), n = we(e, t), r = n.findIndex((o) => o.id === s.id);
|
|
1403
|
+
if (r === -1)
|
|
1404
|
+
return W(
|
|
1405
|
+
x([...n, s])
|
|
1406
|
+
);
|
|
1407
|
+
const i = [...n];
|
|
1408
|
+
return i[r] = s, W(x(i));
|
|
1409
|
+
}
|
|
1410
|
+
function me(e, t) {
|
|
1411
|
+
return t.map((s) => ht(e, s));
|
|
1412
|
+
}
|
|
1413
|
+
function ht(e, t) {
|
|
1414
|
+
if (t.role !== "user" || !t.attachments?.length)
|
|
1415
|
+
return t;
|
|
1416
|
+
const s = e.find(
|
|
1417
|
+
(r) => r.role === "user" && (r.id === t.id || r.id.startsWith("local-") && r.content === t.content)
|
|
1418
|
+
);
|
|
1419
|
+
if (!s?.attachments?.length)
|
|
1420
|
+
return t;
|
|
1421
|
+
const n = t.attachments.map((r) => {
|
|
1422
|
+
const i = ye(s.attachments ?? [], r);
|
|
1423
|
+
return i ? Te(r, i) : r;
|
|
1424
|
+
});
|
|
1425
|
+
return { ...t, attachments: n };
|
|
1426
|
+
}
|
|
1427
|
+
function ye(e, t) {
|
|
1428
|
+
return t.id ? e.find((s) => s.id === t.id) ?? null : null;
|
|
1429
|
+
}
|
|
1430
|
+
function Te(e, t) {
|
|
1431
|
+
const { previewUrl: s } = t;
|
|
1432
|
+
return s ? { ...e, previewUrl: s } : e;
|
|
1059
1433
|
}
|
|
1060
|
-
function
|
|
1434
|
+
function we(e, t) {
|
|
1061
1435
|
if (t.role !== "user")
|
|
1062
1436
|
return e;
|
|
1063
1437
|
const s = e.findIndex(
|
|
@@ -1068,24 +1442,24 @@ function $t(e, t) {
|
|
|
1068
1442
|
const n = [...e];
|
|
1069
1443
|
return n.splice(s, 1), n;
|
|
1070
1444
|
}
|
|
1071
|
-
function
|
|
1072
|
-
const t =
|
|
1073
|
-
return t === null ? !1 : e.slice(t + 1).some(
|
|
1445
|
+
function et(e) {
|
|
1446
|
+
const t = pt(e);
|
|
1447
|
+
return t === null ? !1 : e.slice(t + 1).some(Ae);
|
|
1074
1448
|
}
|
|
1075
|
-
function
|
|
1076
|
-
const t =
|
|
1449
|
+
function Ie(e) {
|
|
1450
|
+
const t = pt(e);
|
|
1077
1451
|
return t === null ? e.some((s) => s.role === "assistant") : e.slice(t + 1).some((s) => s.role === "assistant");
|
|
1078
1452
|
}
|
|
1079
|
-
function
|
|
1453
|
+
function pt(e) {
|
|
1080
1454
|
for (let t = e.length - 1; t >= 0; t -= 1)
|
|
1081
1455
|
if (e[t].role === "user")
|
|
1082
1456
|
return t;
|
|
1083
1457
|
return null;
|
|
1084
1458
|
}
|
|
1085
|
-
function
|
|
1459
|
+
function Ae(e) {
|
|
1086
1460
|
return e.role === "assistant" ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
|
|
1087
1461
|
}
|
|
1088
|
-
function
|
|
1462
|
+
function ke(e) {
|
|
1089
1463
|
for (let t = e.length - 1; t >= 0; t -= 1) {
|
|
1090
1464
|
const s = e[t];
|
|
1091
1465
|
if (!s || typeof s != "object")
|
|
@@ -1099,8 +1473,8 @@ function Xt(e) {
|
|
|
1099
1473
|
}
|
|
1100
1474
|
return null;
|
|
1101
1475
|
}
|
|
1102
|
-
function
|
|
1103
|
-
const t =
|
|
1476
|
+
function Se(e) {
|
|
1477
|
+
const t = ke(e);
|
|
1104
1478
|
if (t === null)
|
|
1105
1479
|
return null;
|
|
1106
1480
|
const s = e[t];
|
|
@@ -1112,22 +1486,22 @@ function Jt(e) {
|
|
|
1112
1486
|
const r = n.clientMessageId;
|
|
1113
1487
|
return typeof r == "string" ? r : null;
|
|
1114
1488
|
}
|
|
1115
|
-
function
|
|
1489
|
+
function Ee(e) {
|
|
1116
1490
|
if (!e || typeof e != "object")
|
|
1117
1491
|
return !1;
|
|
1118
1492
|
const t = e;
|
|
1119
1493
|
return t.type === "message" && t.role === "user" ? !1 : t.type === "message" || t.type === "function_call" || t.type === "function_call_output" || t.type === "run_error" || t.type === "run_status";
|
|
1120
1494
|
}
|
|
1121
|
-
function
|
|
1122
|
-
return e.filter((t, s) =>
|
|
1495
|
+
function W(e) {
|
|
1496
|
+
return e.filter((t, s) => gt(t) ? !be(e, s) && !Pe(e, s) && !Me(e, s) : Re(t) ? !_e(e, s) : !0);
|
|
1123
1497
|
}
|
|
1124
|
-
function
|
|
1498
|
+
function Re(e) {
|
|
1125
1499
|
return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
|
|
1126
1500
|
}
|
|
1127
|
-
function
|
|
1501
|
+
function gt(e) {
|
|
1128
1502
|
return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
|
|
1129
1503
|
}
|
|
1130
|
-
function
|
|
1504
|
+
function x(e) {
|
|
1131
1505
|
const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
1132
1506
|
for (const i of e) {
|
|
1133
1507
|
if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
|
|
@@ -1143,53 +1517,53 @@ function P(e) {
|
|
|
1143
1517
|
n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
|
|
1144
1518
|
return r;
|
|
1145
1519
|
}
|
|
1146
|
-
function
|
|
1520
|
+
function _e(e, t) {
|
|
1147
1521
|
const s = e[t];
|
|
1148
1522
|
for (let n = t + 1; n < e.length; n += 1) {
|
|
1149
1523
|
const r = e[n];
|
|
1150
1524
|
if (r.role === "user")
|
|
1151
1525
|
return !1;
|
|
1152
|
-
if (r.role === "assistant" &&
|
|
1526
|
+
if (r.role === "assistant" && C(s, r))
|
|
1153
1527
|
return !0;
|
|
1154
1528
|
}
|
|
1155
1529
|
return !1;
|
|
1156
1530
|
}
|
|
1157
|
-
function
|
|
1531
|
+
function Pe(e, t) {
|
|
1158
1532
|
const s = e[t];
|
|
1159
1533
|
for (let n = t + 1; n < e.length; n += 1)
|
|
1160
|
-
if (e[n].role === "assistant" &&
|
|
1534
|
+
if (e[n].role === "assistant" && C(s, e[n]))
|
|
1161
1535
|
return !0;
|
|
1162
1536
|
return !1;
|
|
1163
1537
|
}
|
|
1164
|
-
function
|
|
1538
|
+
function Me(e, t) {
|
|
1165
1539
|
const s = e[t];
|
|
1166
1540
|
for (let n = t + 1; n < e.length; n += 1)
|
|
1167
|
-
if (e[n].role === "tool" &&
|
|
1541
|
+
if (e[n].role === "tool" && C(s, e[n]))
|
|
1168
1542
|
return !0;
|
|
1169
1543
|
return !1;
|
|
1170
1544
|
}
|
|
1171
|
-
function
|
|
1545
|
+
function be(e, t) {
|
|
1172
1546
|
const s = e[t];
|
|
1173
1547
|
for (let n = t + 1; n < e.length; n += 1)
|
|
1174
|
-
if (
|
|
1548
|
+
if (gt(e[n]) && C(s, e[n]))
|
|
1175
1549
|
return !0;
|
|
1176
1550
|
return !1;
|
|
1177
1551
|
}
|
|
1178
|
-
function
|
|
1552
|
+
function C(e, t) {
|
|
1179
1553
|
return !e.runId || !t.runId ? !0 : e.runId === t.runId;
|
|
1180
1554
|
}
|
|
1181
|
-
function
|
|
1555
|
+
function I(e, t) {
|
|
1182
1556
|
return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
|
|
1183
1557
|
}
|
|
1184
|
-
function
|
|
1558
|
+
function Ue(e, t) {
|
|
1185
1559
|
try {
|
|
1186
|
-
const s = window.localStorage.getItem(`${
|
|
1560
|
+
const s = window.localStorage.getItem(`${ct}${e}`);
|
|
1187
1561
|
if (!s)
|
|
1188
1562
|
return null;
|
|
1189
1563
|
const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
|
|
1190
1564
|
if (t !== void 0 && r !== t)
|
|
1191
1565
|
return null;
|
|
1192
|
-
const i = Array.isArray(n.messages) ? n.messages.map(
|
|
1566
|
+
const i = Array.isArray(n.messages) ? n.messages.map(Fe).filter((o) => !!o) : [];
|
|
1193
1567
|
return {
|
|
1194
1568
|
sessionId: r,
|
|
1195
1569
|
messages: i
|
|
@@ -1198,72 +1572,98 @@ function ee(e, t) {
|
|
|
1198
1572
|
return null;
|
|
1199
1573
|
}
|
|
1200
1574
|
}
|
|
1201
|
-
function
|
|
1575
|
+
function Ce(e, t) {
|
|
1202
1576
|
try {
|
|
1203
1577
|
window.localStorage.setItem(
|
|
1204
|
-
`${
|
|
1578
|
+
`${ct}${e}`,
|
|
1205
1579
|
JSON.stringify({
|
|
1206
1580
|
sessionId: t.sessionId,
|
|
1207
|
-
messages: t.messages.slice(-
|
|
1581
|
+
messages: t.messages.slice(-Lt).map(He)
|
|
1208
1582
|
})
|
|
1209
1583
|
);
|
|
1210
1584
|
} catch {
|
|
1211
1585
|
return;
|
|
1212
1586
|
}
|
|
1213
1587
|
}
|
|
1214
|
-
function
|
|
1588
|
+
function De(e) {
|
|
1215
1589
|
try {
|
|
1216
|
-
const t = window.localStorage.getItem(`${
|
|
1590
|
+
const t = window.localStorage.getItem(`${B}${e}`);
|
|
1217
1591
|
if (!t)
|
|
1218
1592
|
return [];
|
|
1219
1593
|
const s = JSON.parse(t);
|
|
1220
|
-
return Array.isArray(s) ? s.filter(
|
|
1594
|
+
return Array.isArray(s) ? s.filter(ft) : [];
|
|
1221
1595
|
} catch {
|
|
1222
1596
|
return [];
|
|
1223
1597
|
}
|
|
1224
1598
|
}
|
|
1225
|
-
function
|
|
1599
|
+
function _(e, t) {
|
|
1226
1600
|
try {
|
|
1227
|
-
const s = t.filter(
|
|
1601
|
+
const s = t.filter(ft);
|
|
1228
1602
|
if (s.length === 0) {
|
|
1229
|
-
window.localStorage.removeItem(`${
|
|
1603
|
+
window.localStorage.removeItem(`${B}${e}`);
|
|
1230
1604
|
return;
|
|
1231
1605
|
}
|
|
1232
1606
|
window.localStorage.setItem(
|
|
1233
|
-
`${
|
|
1607
|
+
`${B}${e}`,
|
|
1234
1608
|
JSON.stringify(s.slice(-25))
|
|
1235
1609
|
);
|
|
1236
1610
|
} catch {
|
|
1237
1611
|
return;
|
|
1238
1612
|
}
|
|
1239
1613
|
}
|
|
1240
|
-
function
|
|
1614
|
+
function ft(e) {
|
|
1241
1615
|
if (!e || typeof e != "object")
|
|
1242
1616
|
return !1;
|
|
1243
1617
|
const t = e;
|
|
1244
|
-
return t.type === "chat.user_message" ? typeof t.content == "string" &&
|
|
1618
|
+
return t.type === "chat.user_message" ? typeof t.content == "string" && st(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? st(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && t.toolName === "execute_code" : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" : !1;
|
|
1245
1619
|
}
|
|
1246
|
-
function
|
|
1620
|
+
function st(e) {
|
|
1247
1621
|
if (!e || typeof e != "object")
|
|
1248
1622
|
return !1;
|
|
1249
1623
|
const t = e;
|
|
1250
1624
|
return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
|
|
1251
1625
|
}
|
|
1252
|
-
function
|
|
1626
|
+
function mt(e, t) {
|
|
1253
1627
|
if (!Array.isArray(e))
|
|
1254
1628
|
return;
|
|
1255
|
-
const
|
|
1256
|
-
if (!
|
|
1629
|
+
const s = e.filter((r) => {
|
|
1630
|
+
if (!r || typeof r != "object")
|
|
1257
1631
|
return !1;
|
|
1258
|
-
const
|
|
1259
|
-
return typeof
|
|
1260
|
-
});
|
|
1261
|
-
return
|
|
1632
|
+
const i = r;
|
|
1633
|
+
return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
|
|
1634
|
+
}), n = t ? s.map((r) => yt(r, t)) : s;
|
|
1635
|
+
return n.length > 0 ? n : void 0;
|
|
1262
1636
|
}
|
|
1263
|
-
function
|
|
1264
|
-
return e
|
|
1637
|
+
function yt(e, t) {
|
|
1638
|
+
return e.fileUrl?.startsWith("/") ? {
|
|
1639
|
+
...e,
|
|
1640
|
+
fileUrl: new URL(e.fileUrl, t).toString()
|
|
1641
|
+
} : e;
|
|
1642
|
+
}
|
|
1643
|
+
function Ne(e) {
|
|
1644
|
+
if (qe(e))
|
|
1645
|
+
return {
|
|
1646
|
+
headers: {
|
|
1647
|
+
"ngrok-skip-browser-warning": "true"
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
function qe(e) {
|
|
1652
|
+
try {
|
|
1653
|
+
const t = new URL(e).hostname;
|
|
1654
|
+
return t.endsWith(".ngrok-free.dev") || t.endsWith(".ngrok-free.app") || t.endsWith(".ngrok.app") || t.endsWith(".ngrok.io");
|
|
1655
|
+
} catch {
|
|
1656
|
+
return !1;
|
|
1657
|
+
}
|
|
1265
1658
|
}
|
|
1266
|
-
function
|
|
1659
|
+
function nt(e) {
|
|
1660
|
+
return e.type || Oe(e.name) || "application/octet-stream";
|
|
1661
|
+
}
|
|
1662
|
+
function Oe(e) {
|
|
1663
|
+
const t = e.toLowerCase();
|
|
1664
|
+
return t.endsWith(".png") ? "image/png" : t.endsWith(".jpg") || t.endsWith(".jpeg") ? "image/jpeg" : t.endsWith(".webp") ? "image/webp" : t.endsWith(".gif") ? "image/gif" : t.endsWith(".pdf") ? "application/pdf" : null;
|
|
1665
|
+
}
|
|
1666
|
+
function Fe(e) {
|
|
1267
1667
|
if (!e || typeof e != "object")
|
|
1268
1668
|
return null;
|
|
1269
1669
|
const t = e;
|
|
@@ -1275,71 +1675,86 @@ function ie(e) {
|
|
|
1275
1675
|
respondsToUserMessageId: typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : void 0,
|
|
1276
1676
|
...typeof t.runId == "string" ? { runId: t.runId } : {},
|
|
1277
1677
|
dataType: typeof t.dataType == "string" ? t.dataType : void 0,
|
|
1278
|
-
attachments:
|
|
1678
|
+
attachments: mt(t.attachments)?.map(j),
|
|
1279
1679
|
loading: typeof t.loading == "boolean" ? t.loading : void 0
|
|
1280
1680
|
};
|
|
1281
1681
|
}
|
|
1282
|
-
function
|
|
1682
|
+
function He(e) {
|
|
1683
|
+
return e.attachments?.length ? {
|
|
1684
|
+
...e,
|
|
1685
|
+
attachments: e.attachments.map(j)
|
|
1686
|
+
} : e;
|
|
1687
|
+
}
|
|
1688
|
+
function j(e) {
|
|
1689
|
+
const {
|
|
1690
|
+
dataUrl: t,
|
|
1691
|
+
objectUrl: s,
|
|
1692
|
+
previewUrl: n,
|
|
1693
|
+
...r
|
|
1694
|
+
} = e;
|
|
1695
|
+
return r;
|
|
1696
|
+
}
|
|
1697
|
+
function q(e) {
|
|
1283
1698
|
const t = e.respondsToUserMessageId;
|
|
1284
1699
|
return typeof t == "string" && t ? t : null;
|
|
1285
1700
|
}
|
|
1286
|
-
function
|
|
1701
|
+
function k(e) {
|
|
1287
1702
|
const t = e.runId;
|
|
1288
1703
|
return typeof t == "string" && t ? t : null;
|
|
1289
1704
|
}
|
|
1290
|
-
function
|
|
1705
|
+
function Be(e) {
|
|
1291
1706
|
return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
|
|
1292
1707
|
}
|
|
1293
|
-
function
|
|
1708
|
+
function rt(e) {
|
|
1294
1709
|
const t = {};
|
|
1295
1710
|
return e?.forEach((s, n) => {
|
|
1296
1711
|
t[n] = s;
|
|
1297
1712
|
}), t;
|
|
1298
1713
|
}
|
|
1299
|
-
async function
|
|
1714
|
+
async function We(e, t) {
|
|
1300
1715
|
if (typeof t?.body < "u")
|
|
1301
|
-
return
|
|
1716
|
+
return Tt(t.body);
|
|
1302
1717
|
if (e)
|
|
1303
1718
|
try {
|
|
1304
|
-
return
|
|
1719
|
+
return A(await e.clone().text());
|
|
1305
1720
|
} catch {
|
|
1306
1721
|
return;
|
|
1307
1722
|
}
|
|
1308
1723
|
}
|
|
1309
|
-
async function
|
|
1724
|
+
async function xe(e) {
|
|
1310
1725
|
try {
|
|
1311
|
-
return
|
|
1726
|
+
return A(await e.clone().text());
|
|
1312
1727
|
} catch (t) {
|
|
1313
1728
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
1314
1729
|
}
|
|
1315
1730
|
}
|
|
1316
|
-
function
|
|
1731
|
+
function Le(e) {
|
|
1317
1732
|
try {
|
|
1318
|
-
return e.responseType === "" || e.responseType === "text" ?
|
|
1733
|
+
return e.responseType === "" || e.responseType === "text" ? A(e.responseText ?? "") : e.responseType === "json" ? A(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
|
|
1319
1734
|
} catch (t) {
|
|
1320
1735
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
1321
1736
|
}
|
|
1322
1737
|
}
|
|
1323
|
-
function
|
|
1738
|
+
function Tt(e) {
|
|
1324
1739
|
if (!(e === null || typeof e > "u")) {
|
|
1325
1740
|
if (typeof e == "string")
|
|
1326
|
-
return
|
|
1741
|
+
return A(e);
|
|
1327
1742
|
if (e instanceof URLSearchParams)
|
|
1328
|
-
return
|
|
1743
|
+
return A(e.toString());
|
|
1329
1744
|
if (e instanceof FormData) {
|
|
1330
1745
|
const t = [];
|
|
1331
|
-
return e.forEach((s, n) => t.push([n, s instanceof File ? `[file:${s.name}]` : String(s)])),
|
|
1746
|
+
return e.forEach((s, n) => t.push([n, s instanceof File ? `[file:${s.name}]` : String(s)])), A(JSON.stringify(t));
|
|
1332
1747
|
}
|
|
1333
1748
|
if (e instanceof Blob)
|
|
1334
1749
|
return `[blob:${e.type || "application/octet-stream"}:${e.size}]`;
|
|
1335
1750
|
try {
|
|
1336
|
-
return
|
|
1751
|
+
return A(JSON.stringify(e));
|
|
1337
1752
|
} catch {
|
|
1338
1753
|
return `[unserializable body: ${Object.prototype.toString.call(e)}]`;
|
|
1339
1754
|
}
|
|
1340
1755
|
}
|
|
1341
1756
|
}
|
|
1342
|
-
function
|
|
1757
|
+
function ve(e) {
|
|
1343
1758
|
const t = {};
|
|
1344
1759
|
for (const s of e.trim().split(/[\r\n]+/)) {
|
|
1345
1760
|
const n = s.indexOf(":");
|
|
@@ -1347,65 +1762,97 @@ function le(e) {
|
|
|
1347
1762
|
}
|
|
1348
1763
|
return t;
|
|
1349
1764
|
}
|
|
1350
|
-
function
|
|
1351
|
-
return e.length <=
|
|
1765
|
+
function A(e) {
|
|
1766
|
+
return e.length <= N ? e : `${e.slice(0, N)}... [truncated ${e.length - N} chars]`;
|
|
1352
1767
|
}
|
|
1353
|
-
function
|
|
1768
|
+
function P(e) {
|
|
1354
1769
|
return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
1355
1770
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1771
|
+
class M extends Error {
|
|
1772
|
+
constructor(t, s) {
|
|
1773
|
+
super(`${t} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
|
|
1774
|
+
}
|
|
1775
|
+
status;
|
|
1776
|
+
}
|
|
1777
|
+
async function O(e, t) {
|
|
1778
|
+
let s = null;
|
|
1779
|
+
for (let n = 0; n < J; n += 1)
|
|
1780
|
+
try {
|
|
1781
|
+
return await e();
|
|
1782
|
+
} catch (r) {
|
|
1783
|
+
if (s = r, n >= J - 1 || !$e(r))
|
|
1784
|
+
throw r;
|
|
1785
|
+
await je(n);
|
|
1786
|
+
}
|
|
1787
|
+
throw s instanceof Error ? s : new Error(t);
|
|
1788
|
+
}
|
|
1789
|
+
function je(e) {
|
|
1790
|
+
return new Promise((t) => {
|
|
1791
|
+
window.setTimeout(t, xt[e] ?? 0);
|
|
1792
|
+
});
|
|
1359
1793
|
}
|
|
1360
|
-
function
|
|
1794
|
+
function $e(e) {
|
|
1795
|
+
return e instanceof M ? ze(e.status) : e instanceof TypeError;
|
|
1796
|
+
}
|
|
1797
|
+
function ze(e) {
|
|
1798
|
+
return e === 408 || e === 409 || e === 429 || e >= 500;
|
|
1799
|
+
}
|
|
1800
|
+
function Ge(e) {
|
|
1801
|
+
return e === 401 || e === 403;
|
|
1802
|
+
}
|
|
1803
|
+
const $ = "[REDACTED_SECRET]", T = "[REDACTED_TOKEN]", Xe = "[REDACTED_SIGNED_URL]", Ke = 20, Je = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, wt = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, It = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, At = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, kt = /\b(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|api_key|apiKey|apikey|client_secret|clientSecret|password|secret|token|jwt|csrf|csrfToken|xsrf|xsrfToken)\b\s*[:=]\s*["']?[^"',&\s}]+/gi, Ve = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Ye = /\bhttps?:\/\/[^\s"'<>]+/gi, Ze = /[),.;\]]+$/;
|
|
1804
|
+
function w(e) {
|
|
1805
|
+
return b(e, 0, /* @__PURE__ */ new WeakSet());
|
|
1806
|
+
}
|
|
1807
|
+
function b(e, t, s) {
|
|
1361
1808
|
if (typeof e == "string")
|
|
1362
|
-
return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e :
|
|
1809
|
+
return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : es(e);
|
|
1363
1810
|
if (e === null || typeof e != "object")
|
|
1364
1811
|
return e;
|
|
1365
|
-
if (t >=
|
|
1812
|
+
if (t >= Ke)
|
|
1366
1813
|
return "[REDACTED_MAX_DEPTH]";
|
|
1367
1814
|
if (s.has(e))
|
|
1368
1815
|
return "[REDACTED_CIRCULAR]";
|
|
1369
1816
|
if (s.add(e), Array.isArray(e))
|
|
1370
|
-
return e.map((r) =>
|
|
1817
|
+
return e.map((r) => b(r, t + 1, s));
|
|
1371
1818
|
const n = {};
|
|
1372
1819
|
for (const [r, i] of Object.entries(e))
|
|
1373
|
-
|
|
1820
|
+
Qe(r) ? n[r] = $ : n[r] = r.toLowerCase() === "url" ? ts(i) : b(i, t + 1, s);
|
|
1374
1821
|
return n;
|
|
1375
1822
|
}
|
|
1376
|
-
function
|
|
1823
|
+
function Qe(e) {
|
|
1377
1824
|
const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
1378
1825
|
return t.includes("authorization") || t.includes("cookie") || t.includes("password") || t.includes("passwd") || t === "pwd" || t.includes("secret") || t === "token" || t.endsWith("token") || t.includes("apikey") || t.includes("csrf") || t.includes("xsrf") || t === "jwt" || t === "session" || t === "signature" || t.includes("privatekey");
|
|
1379
1826
|
}
|
|
1380
|
-
function
|
|
1381
|
-
return typeof e == "string" ?
|
|
1827
|
+
function ts(e) {
|
|
1828
|
+
return typeof e == "string" ? St(e) : b(e, 0, /* @__PURE__ */ new WeakSet());
|
|
1382
1829
|
}
|
|
1383
|
-
function
|
|
1830
|
+
function St(e) {
|
|
1384
1831
|
try {
|
|
1385
1832
|
const t = new URL(e, location.href);
|
|
1386
1833
|
for (const s of Array.from(t.searchParams.keys()))
|
|
1387
|
-
|
|
1388
|
-
return t.username && (t.username =
|
|
1834
|
+
Je.test(s) && t.searchParams.set(s, T);
|
|
1835
|
+
return t.username && (t.username = T), t.password && (t.password = T), t.toString();
|
|
1389
1836
|
} catch {
|
|
1390
|
-
return
|
|
1837
|
+
return ss(e);
|
|
1391
1838
|
}
|
|
1392
1839
|
}
|
|
1393
|
-
function
|
|
1394
|
-
return e.replace(
|
|
1840
|
+
function es(e) {
|
|
1841
|
+
return e.replace(Ve, Xe).replace(Ye, ns).replace(wt, `Bearer ${T}`).replace(It, `Basic ${T}`).replace(At, T).replace(kt, (t, s) => `${s}: ${$}`);
|
|
1395
1842
|
}
|
|
1396
|
-
function
|
|
1397
|
-
return e.replace(
|
|
1843
|
+
function ss(e) {
|
|
1844
|
+
return e.replace(wt, `Bearer ${T}`).replace(It, `Basic ${T}`).replace(At, T).replace(kt, (t, s) => `${s}: ${$}`);
|
|
1398
1845
|
}
|
|
1399
|
-
function
|
|
1400
|
-
const t = e.match(
|
|
1401
|
-
return `${
|
|
1846
|
+
function ns(e) {
|
|
1847
|
+
const t = e.match(Ze)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
|
|
1848
|
+
return `${St(s)}${t}`;
|
|
1402
1849
|
}
|
|
1403
1850
|
export {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1851
|
+
X as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
|
|
1852
|
+
H as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
|
|
1853
|
+
Mt as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
|
|
1854
|
+
Pt as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
|
|
1855
|
+
bt as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
|
|
1856
|
+
ut as PlunoProductAgent,
|
|
1857
|
+
ut as default
|
|
1411
1858
|
};
|