@pluno/product-agent-web 0.1.16 → 0.1.19

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.
@@ -1,12 +1,12 @@
1
- const X = "https://app.pluno.ai";
2
- const O = "pluno.productAgent.state.", k = "pluno.productAgent.pendingEvents.", R = "pluno.productAgent.transportId";
1
+ const z = "https://app.pluno.ai", F = "gpt-5.4";
2
+ const H = "pluno.productAgent.state.", k = "pluno.productAgent.pendingEvents.", R = "pluno.productAgent.transportId";
3
3
  class q {
4
4
  constructor(t) {
5
- this.options = t, this.transportId = it(), this.state = {
5
+ this.options = t, this.transportId = at(), this.state = {
6
6
  ...this.state,
7
- starterPrompts: Q(t.initialStarterPrompts)
7
+ starterPrompts: et(t.initialStarterPrompts)
8
8
  };
9
- const s = Tt(t.clientId);
9
+ const s = kt(t.clientId);
10
10
  s && (this.state = {
11
11
  ...this.state,
12
12
  ...s,
@@ -15,7 +15,7 @@ class q {
15
15
  assistantDraft: "",
16
16
  isThinking: !1,
17
17
  lastError: null
18
- }), this.queuedClientEvents = kt(t.clientId);
18
+ }), this.queuedClientEvents = _t(t.clientId);
19
19
  }
20
20
  options;
21
21
  listeners = {};
@@ -50,8 +50,9 @@ class q {
50
50
  static async init(t) {
51
51
  const s = new q({
52
52
  ...t,
53
- backendUrl: J(t.backendUrl ?? X),
54
- clientId: t.clientId ?? rt()
53
+ backendUrl: V(t.backendUrl ?? z),
54
+ clientId: t.clientId ?? ot(),
55
+ model: t.model ?? F
55
56
  });
56
57
  try {
57
58
  s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
@@ -76,10 +77,10 @@ class q {
76
77
  if (this.socket?.readyState === WebSocket.OPEN || this.socket?.readyState === WebSocket.CONNECTING)
77
78
  return;
78
79
  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)
79
- throw new Error("Product Agent requires a token or tokenProvider");
80
- const t = Y(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
80
+ throw new Error("Pluno requires a token or tokenProvider");
81
+ const t = Z(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
81
82
  this.socket = s, s.addEventListener("open", () => {
82
- this.socket === s && (l("web-sdk.agent", "Product Agent socket opened", {
83
+ this.socket === s && (l("web-sdk.agent", "Pluno socket opened", {
83
84
  queuedClientEventCount: this.queuedClientEvents.length,
84
85
  isThinking: this.state.isThinking
85
86
  }), this.token && this.sendNow({
@@ -89,9 +90,9 @@ class q {
89
90
  transportId: this.transportId
90
91
  }), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null }));
91
92
  }), s.addEventListener("message", (n) => {
92
- this.socket === s && this.handleServerEvent(V(n.data));
93
+ this.socket === s && this.handleServerEvent(Q(n.data));
93
94
  }), s.addEventListener("close", (n) => {
94
- this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (l("web-sdk.agent", "Product Agent socket closed; scheduling reconnect", {
95
+ this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (l("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
95
96
  code: typeof n?.code == "number" ? n.code : null,
96
97
  reason: typeof n?.reason == "string" ? n.reason : "",
97
98
  wasClean: typeof n?.wasClean == "boolean" ? n.wasClean : null,
@@ -99,7 +100,7 @@ class q {
99
100
  isThinking: this.state.isThinking
100
101
  }), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect()));
101
102
  }), s.addEventListener("error", () => {
102
- this.socket !== s || this.state.status === "closed" || (l("web-sdk.agent", "Product Agent socket error; scheduling reconnect", {
103
+ this.socket !== s || this.state.status === "closed" || (l("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
103
104
  queuedClientEventCount: this.queuedClientEvents.length,
104
105
  isThinking: this.state.isThinking
105
106
  }), this.stopHeartbeat(), this.socket = null, this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect(), s.readyState !== WebSocket.CLOSED && s.readyState !== WebSocket.CLOSING && s.close());
@@ -113,32 +114,34 @@ class q {
113
114
  for (const t of Object.values(this.listeners))
114
115
  t?.clear();
115
116
  }
116
- sendMessage(t) {
117
- const s = t.trim();
118
- if (!s)
117
+ sendMessage(t, s = {}) {
118
+ const n = t.trim(), r = s.attachments ?? [];
119
+ if (!n && r.length === 0)
119
120
  return;
120
- const n = g(), r = ot(), i = {
121
- id: `local-${r}`,
121
+ const i = g(), a = ct(), o = {
122
+ id: `local-${a}`,
122
123
  role: "user",
123
- content: s,
124
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
124
+ content: n,
125
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
126
+ ...r.length > 0 ? { attachments: r } : {}
125
127
  };
126
128
  this.setState({
127
- messages: [...this.state.messages, i],
129
+ messages: [...this.state.messages, o],
128
130
  assistantDraft: "",
129
131
  isThinking: !0,
130
132
  lastError: null
131
- }), this.emit("message", i);
132
- const a = {
133
+ }), this.emit("message", o);
134
+ const c = {
133
135
  type: "chat.user_message",
134
136
  sessionId: this.state.sessionId ?? void 0,
135
- clientMessageId: r,
136
- content: s,
137
- page: n,
137
+ clientMessageId: a,
138
+ content: n,
139
+ attachments: r.length > 0 ? r : void 0,
140
+ page: i,
138
141
  model: this.options.model,
139
- metadata: F(this.options.metadata)
142
+ metadata: K(this.options.metadata)
140
143
  };
141
- this.activeClientMessageId = r, this.activeUserMessageEvent = a, this.markThinkingProgress(), this.send(a);
144
+ this.activeClientMessageId = a, this.activeUserMessageEvent = c, this.markThinkingProgress(), this.send(c);
142
145
  }
143
146
  stop() {
144
147
  this.state.sessionId && (this.send({ type: "run.stop", sessionId: this.state.sessionId }), this.setState({ isThinking: !1 }), this.clearThinkingWatchdog());
@@ -167,7 +170,7 @@ class q {
167
170
  try {
168
171
  return s.send(JSON.stringify(t)), !0;
169
172
  } catch (n) {
170
- return l("web-sdk.agent", "Product Agent socket send failed; scheduling reconnect", {
173
+ return l("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
171
174
  message: n instanceof Error ? n.message : String(n),
172
175
  queuedClientEventCount: this.queuedClientEvents.length,
173
176
  isThinking: this.state.isThinking
@@ -189,15 +192,15 @@ class q {
189
192
  }
190
193
  }
191
194
  handleServerEvent(t) {
192
- if (z(t) && this.markThinkingProgress(), t.type === "auth.ok") {
193
- const s = tt(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
195
+ if (J(t) && this.markThinkingProgress(), t.type === "auth.ok") {
196
+ const s = st(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
194
197
  l("web-sdk.agent", "Received auth.ok appearance", {
195
198
  hasAppearance: n,
196
199
  rawAppearance: t.appearance,
197
200
  normalizedAppearance: s
198
- }), this.runtimeHelperJavascript = et(t.runtimeHelpers)?.javascript ?? null;
199
- const r = Z(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
200
- user: at(t.user),
201
+ }), this.runtimeHelperJavascript = nt(t.runtimeHelpers)?.javascript ?? null;
202
+ const r = tt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
203
+ user: ut(t.user),
201
204
  status: "connected"
202
205
  };
203
206
  (i || this.state.starterPrompts.length === 0) && (a.starterPrompts = r), (n || s) && (a.appearance = s), this.setState(a), this.state.sessionId && this.send({
@@ -210,9 +213,9 @@ class q {
210
213
  }
211
214
  if (t.type === "conversation.state") {
212
215
  const s = Array.isArray(t.items) ? t.items : [];
213
- ft(s) && this.clearRetryTimers(), this.setState({
216
+ mt(s) && this.clearRetryTimers(), this.setState({
214
217
  sessionId: P(t.session, "id") ?? this.state.sessionId,
215
- messages: ct(s),
218
+ messages: lt(s),
216
219
  ...b(s) ? { assistantDraft: "", isThinking: !1 } : {}
217
220
  }), b(s) && this.clearThinkingWatchdog();
218
221
  return;
@@ -224,7 +227,7 @@ class q {
224
227
  if (t.type === "session.item") {
225
228
  const s = U(t.item);
226
229
  s && (s.role === "assistant" && this.clearRetryTimers(), this.setState({
227
- messages: pt(this.state.messages, s),
230
+ messages: ft(this.state.messages, s),
228
231
  assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
229
232
  ...I(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
230
233
  }), I(t.item.data) && this.clearThinkingWatchdog(), this.emit("message", s));
@@ -247,7 +250,7 @@ class q {
247
250
  if (t.type === "error") {
248
251
  if (this.retryAfterRetryableError(t))
249
252
  return;
250
- const s = new Error(typeof t.message == "string" ? t.message : "Product Agent error");
253
+ const s = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error");
251
254
  this.setState({ status: "error", isThinking: !1, lastError: s.message }), this.clearThinkingWatchdog(), this.emit("error", s);
252
255
  }
253
256
  }
@@ -289,14 +292,14 @@ class q {
289
292
  return;
290
293
  const t = this.activeClientMessageId;
291
294
  if (!t) {
292
- l("web-sdk.agent", "Product Agent thinking watchdog resyncing without active message id", {
295
+ l("web-sdk.agent", "Pluno thinking watchdog resyncing without active message id", {
293
296
  sessionId: this.state.sessionId
294
297
  }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(6e4);
295
298
  return;
296
299
  }
297
300
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[t] ?? 0, n = this.thinkingWatchdogRetryAttemptsByClientMessageId[t] ?? 0;
298
301
  if (s <= n) {
299
- this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, l("web-sdk.agent", "Product Agent thinking watchdog resyncing session", {
302
+ this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, l("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
300
303
  sessionId: this.state.sessionId,
301
304
  clientMessageId: t,
302
305
  resyncAttempts: s + 1
@@ -304,7 +307,7 @@ class q {
304
307
  return;
305
308
  }
306
309
  if (n >= 2) {
307
- l("web-sdk.agent", "Product Agent thinking watchdog retry limit reached; continuing resync", {
310
+ l("web-sdk.agent", "Pluno thinking watchdog retry limit reached; continuing resync", {
308
311
  sessionId: this.state.sessionId,
309
312
  clientMessageId: t,
310
313
  retryAttempts: n
@@ -315,7 +318,7 @@ class q {
315
318
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
316
319
  isThinking: !0,
317
320
  lastError: null
318
- }), l("web-sdk.agent", "Product Agent thinking watchdog retrying last user message", {
321
+ }), l("web-sdk.agent", "Pluno thinking watchdog retrying last user message", {
319
322
  sessionId: this.state.sessionId,
320
323
  clientMessageId: t,
321
324
  retryAttempts: n + 1
@@ -335,7 +338,7 @@ class q {
335
338
  }
336
339
  async executeToolCall(t) {
337
340
  const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
338
- if (!s || !n || !_t(r))
341
+ if (!s || !n || !At(r))
339
342
  return;
340
343
  const i = await this.executeRuntimeHelper(), a = await M(r).catch((o) => ({
341
344
  ok: !1,
@@ -350,7 +353,7 @@ class q {
350
353
  toolName: "execute_code",
351
354
  summary: r.summary,
352
355
  rawInput: f(r),
353
- rawOutput: f(st(a, i))
356
+ rawOutput: f(rt(a, i))
354
357
  });
355
358
  }
356
359
  async executeRuntimeHelper() {
@@ -359,14 +362,14 @@ class q {
359
362
  const t = await M({
360
363
  javascript: this.runtimeHelperJavascript
361
364
  });
362
- return t.ok === !1 ? nt(t) : null;
365
+ return t.ok === !1 ? it(t) : null;
363
366
  }
364
367
  enableNetworkCapture() {
365
368
  if (this.networkCaptureCleanup)
366
369
  return;
367
370
  const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
368
371
  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);
372
+ 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 = O(new Headers(a?.headers ?? u?.headers ?? void 0)), C = await Ct(u, a);
370
373
  try {
371
374
  const d = await t(i, a);
372
375
  return this.enqueueNetworkEvent({
@@ -377,8 +380,8 @@ class q {
377
380
  requestBody: C,
378
381
  resourceType: "fetch",
379
382
  responseStatus: d.status,
380
- responseHeaders: H(d.headers),
381
- responseBody: await wt(d),
383
+ responseHeaders: O(d.headers),
384
+ responseBody: await Rt(d),
382
385
  startedAt: c,
383
386
  durationMs: Date.now() - o
384
387
  }), d;
@@ -420,7 +423,7 @@ class q {
420
423
  startedAtMs: Date.now(),
421
424
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
422
425
  };
423
- return c.requestBody = B(a), this.__plunoMeta = c, this.addEventListener(
426
+ return c.requestBody = L(a), this.__plunoMeta = c, this.addEventListener(
424
427
  "loadend",
425
428
  function() {
426
429
  !o || !this.__plunoMeta || o.enqueueNetworkEvent({
@@ -431,8 +434,8 @@ class q {
431
434
  requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
432
435
  resourceType: "xhr",
433
436
  responseStatus: this.status,
434
- responseHeaders: Ct(this.getAllResponseHeaders()),
435
- responseBody: At(this),
437
+ responseHeaders: bt(this.getAllResponseHeaders()),
438
+ responseBody: Mt(this),
436
439
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
437
440
  startedAt: String(this.__plunoMeta.startedAt),
438
441
  durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
@@ -459,7 +462,7 @@ class q {
459
462
  scheduleReconnect() {
460
463
  this.reconnectTimer !== null || this.state.status === "closed" || (this.reconnectTimer = window.setTimeout(() => {
461
464
  this.reconnectTimer = null, this.connect().catch((t) => {
462
- l("web-sdk.agent", "Product Agent reconnect failed; retrying", {
465
+ l("web-sdk.agent", "Pluno reconnect failed; retrying", {
463
466
  message: t instanceof Error ? t.message : String(t),
464
467
  queuedClientEventCount: this.queuedClientEvents.length,
465
468
  isThinking: this.state.isThinking
@@ -476,7 +479,7 @@ class q {
476
479
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
477
480
  }
478
481
  setState(t) {
479
- this.state = { ...this.state, ...t }, St(this.options.clientId, this.state), this.emit("state", this.getState());
482
+ this.state = { ...this.state, ...t }, It(this.options.clientId, this.state), this.emit("state", this.getState());
480
483
  }
481
484
  emit(t, s) {
482
485
  this.listeners[t]?.forEach((r) => r(s));
@@ -493,17 +496,17 @@ function l(e, t, s) {
493
496
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
494
497
  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 }));
495
498
  }
496
- function F(e) {
499
+ function K(e) {
497
500
  const t = typeof e == "function" ? e() : e;
498
501
  return t && Object.keys(t).length > 0 ? t : void 0;
499
502
  }
500
- function z(e) {
503
+ function J(e) {
501
504
  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";
502
505
  }
503
- const K = 5e3;
506
+ const Y = 5e3;
504
507
  async function M(e) {
505
508
  const t = Object.getPrototypeOf(async function() {
506
- }).constructor, s = K, n = Date.now(), r = [], i = {
509
+ }).constructor, s = Y, n = Date.now(), r = [], i = {
507
510
  log: console.log,
508
511
  info: console.info,
509
512
  warn: console.warn,
@@ -547,10 +550,10 @@ async function M(e) {
547
550
  console.log = i.log, console.info = i.info, console.warn = i.warn, console.error = i.error;
548
551
  }
549
552
  }
550
- function J(e) {
553
+ function V(e) {
551
554
  return e.replace(/\/+$/, "");
552
555
  }
553
- function Y(e) {
556
+ function Z(e) {
554
557
  const t = new URL("/api/product-agent/embed/ws", e);
555
558
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
556
559
  }
@@ -561,7 +564,7 @@ function g() {
561
564
  origin: location.origin
562
565
  };
563
566
  }
564
- function V(e) {
567
+ function Q(e) {
565
568
  try {
566
569
  const t = JSON.parse(e);
567
570
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -569,16 +572,16 @@ function V(e) {
569
572
  return { type: "error", message: "Invalid server event" };
570
573
  }
571
574
  }
572
- function Z(e, t) {
575
+ function tt(e, t) {
573
576
  if (!e || typeof e != "object")
574
577
  return [];
575
578
  const s = e[t];
576
579
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
577
580
  }
578
- function Q(e) {
581
+ function et(e) {
579
582
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
580
583
  }
581
- function tt(e) {
584
+ function st(e) {
582
585
  if (!e || typeof e != "object")
583
586
  return null;
584
587
  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;
@@ -589,13 +592,13 @@ function tt(e) {
589
592
  ...o !== null ? { scribbleStyle: o } : {}
590
593
  };
591
594
  }
592
- function et(e) {
595
+ function nt(e) {
593
596
  if (!e || typeof e != "object")
594
597
  return null;
595
598
  const t = e.javascript;
596
599
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
597
600
  }
598
- function st(e, t) {
601
+ function rt(e, t) {
599
602
  return t ? e && typeof e == "object" ? {
600
603
  ...e,
601
604
  helperError: t
@@ -605,30 +608,30 @@ function st(e, t) {
605
608
  helperError: t
606
609
  } : e;
607
610
  }
608
- function nt(e) {
611
+ function it(e) {
609
612
  if (!e || typeof e != "object")
610
613
  return e;
611
614
  const t = e;
612
615
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
613
616
  }
614
- function rt() {
617
+ function ot() {
615
618
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
616
619
  if (t)
617
620
  return t;
618
621
  const s = crypto.randomUUID();
619
622
  return window.localStorage.setItem(e, s), s;
620
623
  }
621
- function it() {
624
+ function at() {
622
625
  const e = window.sessionStorage.getItem(R);
623
626
  if (e)
624
627
  return e;
625
628
  const t = crypto.randomUUID();
626
629
  return window.sessionStorage.setItem(R, t), t;
627
630
  }
628
- function ot() {
631
+ function ct() {
629
632
  return crypto.randomUUID();
630
633
  }
631
- function at(e) {
634
+ function ut(e) {
632
635
  if (!e || typeof e != "object")
633
636
  return null;
634
637
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -639,7 +642,7 @@ function at(e) {
639
642
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
640
643
  } : null;
641
644
  }
642
- function ct(e) {
645
+ function lt(e) {
643
646
  return Array.isArray(e) ? _(
644
647
  e.map(U).filter((t) => t !== null)
645
648
  ) : [];
@@ -656,29 +659,30 @@ function U(e) {
656
659
  return {
657
660
  id: String(t.id ?? crypto.randomUUID()),
658
661
  role: r,
659
- content: ht(n.content),
660
- createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString()
662
+ content: gt(n.content),
663
+ createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
664
+ attachments: B(n.attachments)
661
665
  };
662
666
  }
663
667
  return n.type === "function_call" || n.type === "tool_call" || n.type === "web_search_call" ? {
664
668
  id: String(t.id ?? crypto.randomUUID()),
665
669
  role: "tool",
666
- content: lt(n),
670
+ content: ht(n),
667
671
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
668
672
  dataType: String(n.type),
669
673
  loading: n.localExecutionStatus === "running"
670
674
  } : n.type === "run_status" || n.type === "run_error" ? n.type === "run_status" && (n.status === "running" || n.status === "retrying") || n.type === "run_error" && n.stage === "tool_execution" ? null : {
671
675
  id: String(t.id ?? crypto.randomUUID()),
672
676
  role: "system",
673
- content: ut(n),
677
+ content: dt(n),
674
678
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
675
679
  dataType: String(n.type)
676
680
  } : null;
677
681
  }
678
- function ut(e) {
679
- return typeof e.message == "string" && e.message.trim().length > 0 ? e.message : e.type === "run_status" && e.status === "interrupted" ? "Product Agent was interrupted before it could finish this message." : e.type === "run_status" && e.status === "stopped" ? "Product Agent stopped." : "Product Agent run status changed.";
682
+ function dt(e) {
683
+ 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.";
680
684
  }
681
- function lt(e) {
685
+ function ht(e) {
682
686
  if (e.type === "web_search_call") {
683
687
  const t = e.action;
684
688
  if (t && typeof t == "object") {
@@ -690,9 +694,9 @@ function lt(e) {
690
694
  }
691
695
  return "Searching the web";
692
696
  }
693
- return dt(e);
697
+ return pt(e);
694
698
  }
695
- function dt(e) {
699
+ function pt(e) {
696
700
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
697
701
  return e.summary;
698
702
  if (typeof e.arguments == "string")
@@ -705,7 +709,7 @@ function dt(e) {
705
709
  }
706
710
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
707
711
  }
708
- function ht(e) {
712
+ function gt(e) {
709
713
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
710
714
  if (!t || typeof t != "object")
711
715
  return "";
@@ -713,14 +717,14 @@ function ht(e) {
713
717
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
714
718
  }).filter(Boolean).join("") : "";
715
719
  }
716
- function pt(e, t) {
717
- const s = gt(e, t), n = s.findIndex((i) => i.id === t.id);
720
+ function ft(e, t) {
721
+ const s = yt(e, t), n = s.findIndex((i) => i.id === t.id);
718
722
  if (n === -1)
719
723
  return _([...s, t]);
720
724
  const r = [...s];
721
725
  return r[n] = t, _(r);
722
726
  }
723
- function gt(e, t) {
727
+ function yt(e, t) {
724
728
  if (t.role !== "user")
725
729
  return e;
726
730
  const s = e.findIndex(
@@ -735,7 +739,7 @@ function b(e) {
735
739
  const t = W(e);
736
740
  return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : I(s.data));
737
741
  }
738
- function ft(e) {
742
+ function mt(e) {
739
743
  const t = W(e);
740
744
  return t === null ? e.some((s) => !s || typeof s != "object" ? !1 : N(s.data)) : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : N(s.data));
741
745
  }
@@ -766,12 +770,12 @@ function I(e) {
766
770
  return t.type === "message" && t.role === "assistant" ? !0 : t.type === "run_error" ? t.stage !== "tool_execution" : t.type === "run_status" && (t.status === "stopped" || t.status === "interrupted");
767
771
  }
768
772
  function _(e) {
769
- return e.filter((t, s) => yt(t) ? !mt(e, s) : !0);
773
+ return e.filter((t, s) => Tt(t) ? !St(e, s) : !0);
770
774
  }
771
- function yt(e) {
775
+ function Tt(e) {
772
776
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
773
777
  }
774
- function mt(e, t) {
778
+ function St(e, t) {
775
779
  for (let s = t + 1; s < e.length; s += 1) {
776
780
  const n = e[s];
777
781
  if (n.role === "user")
@@ -784,12 +788,12 @@ function mt(e, t) {
784
788
  function P(e, t) {
785
789
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
786
790
  }
787
- function Tt(e) {
791
+ function kt(e) {
788
792
  try {
789
- const t = window.localStorage.getItem(`${O}${e}`);
793
+ const t = window.localStorage.getItem(`${H}${e}`);
790
794
  if (!t)
791
795
  return null;
792
- const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(It).filter((r) => !!r) : [];
796
+ const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(wt).filter((r) => !!r) : [];
793
797
  return {
794
798
  sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
795
799
  messages: n
@@ -798,10 +802,10 @@ function Tt(e) {
798
802
  return null;
799
803
  }
800
804
  }
801
- function St(e, t) {
805
+ function It(e, t) {
802
806
  try {
803
807
  window.localStorage.setItem(
804
- `${O}${e}`,
808
+ `${H}${e}`,
805
809
  JSON.stringify({
806
810
  sessionId: t.sessionId,
807
811
  messages: t.messages.slice(-100)
@@ -811,7 +815,7 @@ function St(e, t) {
811
815
  return;
812
816
  }
813
817
  }
814
- function kt(e) {
818
+ function _t(e) {
815
819
  try {
816
820
  const t = window.localStorage.getItem(`${k}${e}`);
817
821
  if (!t)
@@ -849,7 +853,21 @@ function D(e) {
849
853
  const t = e;
850
854
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
851
855
  }
852
- function It(e) {
856
+ function B(e) {
857
+ if (!Array.isArray(e))
858
+ return;
859
+ const t = e.filter((s) => {
860
+ if (!s || typeof s != "object")
861
+ return !1;
862
+ const n = s;
863
+ return typeof n.name == "string" && Et(n.mimeType) && typeof n.sizeBytes == "number" && typeof n.dataUrl == "string";
864
+ });
865
+ return t.length > 0 ? t : void 0;
866
+ }
867
+ function Et(e) {
868
+ return e === "image/png" || e === "image/jpeg" || e === "image/webp" || e === "image/gif" || e === "application/pdf";
869
+ }
870
+ function wt(e) {
853
871
  if (!e || typeof e != "object")
854
872
  return null;
855
873
  const t = e;
@@ -859,21 +877,22 @@ function It(e) {
859
877
  content: t.content,
860
878
  createdAt: t.createdAt,
861
879
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
880
+ attachments: B(t.attachments),
862
881
  loading: typeof t.loading == "boolean" ? t.loading : void 0
863
882
  };
864
883
  }
865
- function _t(e) {
884
+ function At(e) {
866
885
  return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
867
886
  }
868
- function H(e) {
887
+ function O(e) {
869
888
  const t = {};
870
889
  return e?.forEach((s, n) => {
871
890
  t[n] = s;
872
891
  }), t;
873
892
  }
874
- async function Et(e, t) {
893
+ async function Ct(e, t) {
875
894
  if (typeof t?.body < "u")
876
- return B(t.body);
895
+ return L(t.body);
877
896
  if (e)
878
897
  try {
879
898
  return p(await e.clone().text());
@@ -881,21 +900,21 @@ async function Et(e, t) {
881
900
  return;
882
901
  }
883
902
  }
884
- async function wt(e) {
903
+ async function Rt(e) {
885
904
  try {
886
905
  return p(await e.clone().text());
887
906
  } catch (t) {
888
907
  return { error: t instanceof Error ? t.message : "unavailable" };
889
908
  }
890
909
  }
891
- function At(e) {
910
+ function Mt(e) {
892
911
  try {
893
912
  return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
894
913
  } catch (t) {
895
914
  return { error: t instanceof Error ? t.message : "unavailable" };
896
915
  }
897
916
  }
898
- function B(e) {
917
+ function L(e) {
899
918
  if (!(e === null || typeof e > "u")) {
900
919
  if (typeof e == "string")
901
920
  return p(e);
@@ -914,7 +933,7 @@ function B(e) {
914
933
  }
915
934
  }
916
935
  }
917
- function Ct(e) {
936
+ function bt(e) {
918
937
  const t = {};
919
938
  for (const s of e.trim().split(/[\r\n]+/)) {
920
939
  const n = s.indexOf(":");
@@ -928,16 +947,16 @@ function p(e) {
928
947
  function T(e) {
929
948
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
930
949
  }
931
- const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Rt = "[REDACTED_SIGNED_URL]", Mt = 20, bt = /^(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, L = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, j = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, v = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, G = /\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, Nt = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Pt = /\bhttps?:\/\/[^\s"'<>]+/gi, Dt = /[),.;\]]+$/;
950
+ const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Nt = "[REDACTED_SIGNED_URL]", Pt = 20, Dt = /^(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, j = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, G = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, v = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, $ = /\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, Ot = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Ht = /\bhttps?:\/\/[^\s"'<>]+/gi, qt = /[),.;\]]+$/;
932
951
  function f(e) {
933
952
  return S(e, 0, /* @__PURE__ */ new WeakSet());
934
953
  }
935
954
  function S(e, t, s) {
936
955
  if (typeof e == "string")
937
- return qt(e);
956
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : xt(e);
938
957
  if (e === null || typeof e != "object")
939
958
  return e;
940
- if (t >= Mt)
959
+ if (t >= Pt)
941
960
  return "[REDACTED_MAX_DEPTH]";
942
961
  if (s.has(e))
943
962
  return "[REDACTED_CIRCULAR]";
@@ -945,35 +964,35 @@ function S(e, t, s) {
945
964
  return e.map((r) => S(r, t + 1, s));
946
965
  const n = {};
947
966
  for (const [r, i] of Object.entries(e))
948
- Ht(r) ? n[r] = E : n[r] = r.toLowerCase() === "url" ? Ot(i) : S(i, t + 1, s);
967
+ Ut(r) ? n[r] = E : n[r] = r.toLowerCase() === "url" ? Wt(i) : S(i, t + 1, s);
949
968
  return n;
950
969
  }
951
- function Ht(e) {
970
+ function Ut(e) {
952
971
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
953
972
  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");
954
973
  }
955
- function Ot(e) {
956
- return typeof e == "string" ? $(e) : S(e, 0, /* @__PURE__ */ new WeakSet());
974
+ function Wt(e) {
975
+ return typeof e == "string" ? X(e) : S(e, 0, /* @__PURE__ */ new WeakSet());
957
976
  }
958
- function $(e) {
977
+ function X(e) {
959
978
  try {
960
979
  const t = new URL(e, location.href);
961
980
  for (const s of Array.from(t.searchParams.keys()))
962
- bt.test(s) && t.searchParams.set(s, h);
981
+ Dt.test(s) && t.searchParams.set(s, h);
963
982
  return t.username && (t.username = h), t.password && (t.password = h), t.toString();
964
983
  } catch {
965
- return Ut(e);
984
+ return Bt(e);
966
985
  }
967
986
  }
968
- function qt(e) {
969
- return e.replace(Nt, Rt).replace(Pt, Wt).replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(v, h).replace(G, (t, s) => `${s}: ${E}`);
987
+ function xt(e) {
988
+ return e.replace(Ot, Nt).replace(Ht, Lt).replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
970
989
  }
971
- function Ut(e) {
972
- return e.replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(v, h).replace(G, (t, s) => `${s}: ${E}`);
990
+ function Bt(e) {
991
+ return e.replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
973
992
  }
974
- function Wt(e) {
975
- const t = e.match(Dt)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
976
- return `${$(s)}${t}`;
993
+ function Lt(e) {
994
+ const t = e.match(qt)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
995
+ return `${X(s)}${t}`;
977
996
  }
978
997
  export {
979
998
  q as PlunoProductAgent,