@pluno/product-agent-web 0.1.15 → 0.1.17
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/index.d.ts +1 -0
- package/dist/product-agent-sdk.js +37 -36
- package/dist/product-agent-widget.js +686 -455
- package/dist/widget.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type ProductAgentAppearance = {
|
|
|
22
22
|
accentColor?: string;
|
|
23
23
|
colorScheme?: "light" | "dark";
|
|
24
24
|
fontFamily?: string;
|
|
25
|
+
scribbleStyle?: boolean;
|
|
25
26
|
};
|
|
26
27
|
export type ProductAgentState = {
|
|
27
28
|
status: "idle" | "connecting" | "connected" | "reconnecting" | "closed" | "error";
|
|
@@ -129,7 +129,7 @@ class q {
|
|
|
129
129
|
isThinking: !0,
|
|
130
130
|
lastError: null
|
|
131
131
|
}), this.emit("message", i);
|
|
132
|
-
const
|
|
132
|
+
const a = {
|
|
133
133
|
type: "chat.user_message",
|
|
134
134
|
sessionId: this.state.sessionId ?? void 0,
|
|
135
135
|
clientMessageId: r,
|
|
@@ -138,7 +138,7 @@ class q {
|
|
|
138
138
|
model: this.options.model,
|
|
139
139
|
metadata: F(this.options.metadata)
|
|
140
140
|
};
|
|
141
|
-
this.activeClientMessageId = r, this.activeUserMessageEvent =
|
|
141
|
+
this.activeClientMessageId = r, this.activeUserMessageEvent = a, this.markThinkingProgress(), this.send(a);
|
|
142
142
|
}
|
|
143
143
|
stop() {
|
|
144
144
|
this.state.sessionId && (this.send({ type: "run.stop", sessionId: this.state.sessionId }), this.setState({ isThinking: !1 }), this.clearThinkingWatchdog());
|
|
@@ -196,11 +196,11 @@ class q {
|
|
|
196
196
|
rawAppearance: t.appearance,
|
|
197
197
|
normalizedAppearance: s
|
|
198
198
|
}), this.runtimeHelperJavascript = et(t.runtimeHelpers)?.javascript ?? null;
|
|
199
|
-
const r = Z(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"),
|
|
199
|
+
const r = Z(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
|
|
200
200
|
user: at(t.user),
|
|
201
201
|
status: "connected"
|
|
202
202
|
};
|
|
203
|
-
(i || this.state.starterPrompts.length === 0) && (
|
|
203
|
+
(i || this.state.starterPrompts.length === 0) && (a.starterPrompts = r), (n || s) && (a.appearance = s), this.setState(a), this.state.sessionId && this.send({
|
|
204
204
|
type: "page.upsert",
|
|
205
205
|
sessionId: this.state.sessionId,
|
|
206
206
|
page: g(),
|
|
@@ -259,14 +259,14 @@ class q {
|
|
|
259
259
|
if (i >= 1)
|
|
260
260
|
return !1;
|
|
261
261
|
this.retryAttemptsByClientMessageId[n] = i + 1;
|
|
262
|
-
const
|
|
262
|
+
const a = typeof t.retryAfterMs == "number" ? t.retryAfterMs : 2e3;
|
|
263
263
|
return this.setState({ status: "reconnecting", isThinking: !0, lastError: null }), this.retryTimersByClientMessageId[n] = window.setTimeout(() => {
|
|
264
264
|
delete this.retryTimersByClientMessageId[n], this.setState({ status: "connected", isThinking: !0, lastError: null }), this.markThinkingProgress(), this.send({
|
|
265
265
|
type: "chat.retry_last_user_message",
|
|
266
266
|
sessionId: s,
|
|
267
267
|
clientMessageId: n
|
|
268
268
|
});
|
|
269
|
-
},
|
|
269
|
+
}, a), !0;
|
|
270
270
|
}
|
|
271
271
|
clearRetryTimers() {
|
|
272
272
|
for (const t of Object.values(this.retryTimersByClientMessageId))
|
|
@@ -337,10 +337,10 @@ class q {
|
|
|
337
337
|
const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
|
|
338
338
|
if (!s || !n || !_t(r))
|
|
339
339
|
return;
|
|
340
|
-
const i = await this.executeRuntimeHelper(),
|
|
340
|
+
const i = await this.executeRuntimeHelper(), a = await M(r).catch((o) => ({
|
|
341
341
|
ok: !1,
|
|
342
342
|
exception: {
|
|
343
|
-
message:
|
|
343
|
+
message: o instanceof Error ? o.message : String(o)
|
|
344
344
|
}
|
|
345
345
|
}));
|
|
346
346
|
this.send({
|
|
@@ -350,7 +350,7 @@ class q {
|
|
|
350
350
|
toolName: "execute_code",
|
|
351
351
|
summary: r.summary,
|
|
352
352
|
rawInput: f(r),
|
|
353
|
-
rawOutput: f(st(
|
|
353
|
+
rawOutput: f(st(a, i))
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
async executeRuntimeHelper() {
|
|
@@ -365,10 +365,10 @@ class q {
|
|
|
365
365
|
if (this.networkCaptureCleanup)
|
|
366
366
|
return;
|
|
367
367
|
const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
|
|
368
|
-
window.fetch = async (i,
|
|
369
|
-
const
|
|
368
|
+
window.fetch = async (i, a) => {
|
|
369
|
+
const o = Date.now(), c = new Date(o).toISOString(), u = i instanceof Request ? i : null, y = typeof i == "string" ? i : i instanceof URL ? i.toString() : u?.url ?? "", w = (a?.method ?? u?.method ?? "GET").toUpperCase(), A = H(new Headers(a?.headers ?? u?.headers ?? void 0)), C = await Et(u, a);
|
|
370
370
|
try {
|
|
371
|
-
const d = await t(i,
|
|
371
|
+
const d = await t(i, a);
|
|
372
372
|
return this.enqueueNetworkEvent({
|
|
373
373
|
requestId: T("fetch"),
|
|
374
374
|
url: y,
|
|
@@ -380,7 +380,7 @@ class q {
|
|
|
380
380
|
responseHeaders: H(d.headers),
|
|
381
381
|
responseBody: await wt(d),
|
|
382
382
|
startedAt: c,
|
|
383
|
-
durationMs: Date.now() -
|
|
383
|
+
durationMs: Date.now() - o
|
|
384
384
|
}), d;
|
|
385
385
|
} catch (d) {
|
|
386
386
|
throw this.enqueueNetworkEvent({
|
|
@@ -392,27 +392,27 @@ class q {
|
|
|
392
392
|
resourceType: "fetch",
|
|
393
393
|
errorText: d instanceof Error ? d.message : String(d),
|
|
394
394
|
startedAt: c,
|
|
395
|
-
durationMs: Date.now() -
|
|
395
|
+
durationMs: Date.now() - o
|
|
396
396
|
}), d;
|
|
397
397
|
}
|
|
398
|
-
}, XMLHttpRequest.prototype.open = function(
|
|
398
|
+
}, XMLHttpRequest.prototype.open = function(a, o, c, u, y) {
|
|
399
399
|
return this.__plunoMeta = {
|
|
400
400
|
requestId: T("xhr"),
|
|
401
|
-
method: String(
|
|
402
|
-
url: typeof
|
|
401
|
+
method: String(a ?? "GET").toUpperCase(),
|
|
402
|
+
url: typeof o == "string" ? o : o.toString(),
|
|
403
403
|
requestHeaders: {},
|
|
404
404
|
startedAtMs: Date.now(),
|
|
405
405
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
406
|
-
}, s.call(this,
|
|
407
|
-
}, XMLHttpRequest.prototype.setRequestHeader = function(
|
|
406
|
+
}, s.call(this, a, o, c ?? !0, u ?? void 0, y ?? void 0);
|
|
407
|
+
}, XMLHttpRequest.prototype.setRequestHeader = function(a, o) {
|
|
408
408
|
const c = this.__plunoMeta;
|
|
409
409
|
if (c) {
|
|
410
410
|
const u = c.requestHeaders ?? {};
|
|
411
|
-
u[
|
|
411
|
+
u[a] = o, c.requestHeaders = u;
|
|
412
412
|
}
|
|
413
|
-
return n.call(this,
|
|
414
|
-
}, XMLHttpRequest.prototype.send = function(
|
|
415
|
-
const
|
|
413
|
+
return n.call(this, a, o);
|
|
414
|
+
}, XMLHttpRequest.prototype.send = function(a) {
|
|
415
|
+
const o = window.__plunoProductAgentInstance, c = this.__plunoMeta ?? {
|
|
416
416
|
requestId: T("xhr"),
|
|
417
417
|
method: "GET",
|
|
418
418
|
url: "",
|
|
@@ -420,10 +420,10 @@ class q {
|
|
|
420
420
|
startedAtMs: Date.now(),
|
|
421
421
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
422
422
|
};
|
|
423
|
-
return c.requestBody = B(
|
|
423
|
+
return c.requestBody = B(a), this.__plunoMeta = c, this.addEventListener(
|
|
424
424
|
"loadend",
|
|
425
425
|
function() {
|
|
426
|
-
!
|
|
426
|
+
!o || !this.__plunoMeta || o.enqueueNetworkEvent({
|
|
427
427
|
requestId: String(this.__plunoMeta.requestId),
|
|
428
428
|
url: String(this.__plunoMeta.url ?? ""),
|
|
429
429
|
method: String(this.__plunoMeta.method ?? "GET"),
|
|
@@ -439,7 +439,7 @@ class q {
|
|
|
439
439
|
});
|
|
440
440
|
},
|
|
441
441
|
{ once: !0 }
|
|
442
|
-
), r.call(this,
|
|
442
|
+
), r.call(this, a ?? null);
|
|
443
443
|
}, window.__plunoProductAgentInstance = this, this.networkCaptureCleanup = () => {
|
|
444
444
|
window.fetch = t, XMLHttpRequest.prototype.open = s, XMLHttpRequest.prototype.setRequestHeader = n, XMLHttpRequest.prototype.send = r, window.__plunoProductAgentInstance === this && delete window.__plunoProductAgentInstance;
|
|
445
445
|
};
|
|
@@ -508,10 +508,10 @@ async function M(e) {
|
|
|
508
508
|
info: console.info,
|
|
509
509
|
warn: console.warn,
|
|
510
510
|
error: console.error
|
|
511
|
-
},
|
|
512
|
-
r.push({ level:
|
|
511
|
+
}, a = (o) => (...c) => {
|
|
512
|
+
r.push({ level: o, args: c }), i[o](...c);
|
|
513
513
|
};
|
|
514
|
-
console.log =
|
|
514
|
+
console.log = a("log"), console.info = a("info"), console.warn = a("warn"), console.error = a("error");
|
|
515
515
|
try {
|
|
516
516
|
return {
|
|
517
517
|
ok: !0,
|
|
@@ -528,14 +528,14 @@ async function M(e) {
|
|
|
528
528
|
origin: location.origin
|
|
529
529
|
}
|
|
530
530
|
};
|
|
531
|
-
} catch (
|
|
531
|
+
} catch (o) {
|
|
532
532
|
return {
|
|
533
533
|
ok: !1,
|
|
534
534
|
console: r,
|
|
535
535
|
exception: {
|
|
536
|
-
name:
|
|
537
|
-
message:
|
|
538
|
-
stack:
|
|
536
|
+
name: o instanceof Error ? o.name : "Error",
|
|
537
|
+
message: o instanceof Error ? o.message : String(o),
|
|
538
|
+
stack: o instanceof Error ? o.stack : void 0
|
|
539
539
|
},
|
|
540
540
|
metadata: {
|
|
541
541
|
durationMs: Date.now() - n,
|
|
@@ -581,11 +581,12 @@ function Q(e) {
|
|
|
581
581
|
function tt(e) {
|
|
582
582
|
if (!e || typeof e != "object")
|
|
583
583
|
return null;
|
|
584
|
-
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,
|
|
585
|
-
return !r && !i && !o ? null : {
|
|
584
|
+
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, a = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, o = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
|
|
585
|
+
return !r && !i && !a && o === null ? null : {
|
|
586
586
|
...r ? { accentColor: r } : {},
|
|
587
587
|
...i ? { colorScheme: i } : {},
|
|
588
|
-
...
|
|
588
|
+
...a ? { fontFamily: a } : {},
|
|
589
|
+
...o !== null ? { scribbleStyle: o } : {}
|
|
589
590
|
};
|
|
590
591
|
}
|
|
591
592
|
function et(e) {
|