@amodalai/react 0.1.0 → 0.1.1

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.
Files changed (97) hide show
  1. package/dist/client/ChatClient.d.ts +76 -0
  2. package/dist/client/ChatClient.d.ts.map +1 -0
  3. package/dist/client/ChatStream.d.ts +63 -0
  4. package/dist/client/ChatStream.d.ts.map +1 -0
  5. package/dist/client/EventEmitter.d.ts +16 -0
  6. package/dist/client/EventEmitter.d.ts.map +1 -0
  7. package/dist/client/chat-api.d.ts +80 -0
  8. package/dist/client/chat-api.d.ts.map +1 -0
  9. package/dist/client/index.d.ts +7 -0
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client.js +437 -123
  12. package/dist/client.js.map +1 -1
  13. package/dist/event-bus-h26clqbZ.js +297 -0
  14. package/dist/event-bus-h26clqbZ.js.map +1 -0
  15. package/dist/events/entity-extractor.d.ts +7 -0
  16. package/dist/events/entity-extractor.d.ts.map +1 -0
  17. package/dist/events/event-bus.d.ts +27 -0
  18. package/dist/events/event-bus.d.ts.map +1 -0
  19. package/dist/events/index.d.ts +9 -0
  20. package/dist/events/index.d.ts.map +1 -0
  21. package/dist/events/types.d.ts +72 -0
  22. package/dist/events/types.d.ts.map +1 -0
  23. package/dist/hooks/useAmodalChat.d.ts.map +1 -1
  24. package/dist/hooks/useChat.d.ts +52 -0
  25. package/dist/hooks/useChat.d.ts.map +1 -0
  26. package/dist/hooks/useSessionHistory.d.ts +17 -0
  27. package/dist/hooks/useSessionHistory.d.ts.map +1 -0
  28. package/dist/hooks/useWidgetEvents.d.ts +17 -0
  29. package/dist/hooks/useWidgetEvents.d.ts.map +1 -0
  30. package/dist/index.d.ts +17 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/react.css +5 -0
  33. package/dist/react.js +245 -222
  34. package/dist/react.js.map +1 -1
  35. package/dist/theme-BaBR_tym.js +691 -0
  36. package/dist/theme-BaBR_tym.js.map +1 -0
  37. package/dist/theme.d.ts +11 -0
  38. package/dist/theme.d.ts.map +1 -0
  39. package/dist/types.d.ts +106 -8
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/umd-entry.d.ts +21 -0
  42. package/dist/umd-entry.d.ts.map +1 -0
  43. package/dist/widget/AskUserCard.d.ts +8 -0
  44. package/dist/widget/AskUserCard.d.ts.map +1 -0
  45. package/dist/widget/ChatWidget.d.ts +9 -0
  46. package/dist/widget/ChatWidget.d.ts.map +1 -0
  47. package/dist/widget/FormattedText.d.ts +12 -0
  48. package/dist/widget/FormattedText.d.ts.map +1 -0
  49. package/dist/widget/InputBar.d.ts +15 -0
  50. package/dist/widget/InputBar.d.ts.map +1 -0
  51. package/dist/widget/KBProposalCard.d.ts +7 -0
  52. package/dist/widget/KBProposalCard.d.ts.map +1 -0
  53. package/dist/widget/MessageList.d.ts +15 -0
  54. package/dist/widget/MessageList.d.ts.map +1 -0
  55. package/dist/widget/SessionHistory.d.ts +12 -0
  56. package/dist/widget/SessionHistory.d.ts.map +1 -0
  57. package/dist/widget/SkillPill.d.ts +11 -0
  58. package/dist/widget/SkillPill.d.ts.map +1 -0
  59. package/dist/widget/StreamingIndicator.d.ts +7 -0
  60. package/dist/widget/StreamingIndicator.d.ts.map +1 -0
  61. package/dist/widget/TagEditor.d.ts +11 -0
  62. package/dist/widget/TagEditor.d.ts.map +1 -0
  63. package/dist/widget/ToolCallCard.d.ts +7 -0
  64. package/dist/widget/ToolCallCard.d.ts.map +1 -0
  65. package/dist/widget/index.d.ts +33 -0
  66. package/dist/widget/index.d.ts.map +1 -0
  67. package/dist/widget/widgets/AlertCard.d.ts +3 -0
  68. package/dist/widget/widgets/AlertCard.d.ts.map +1 -0
  69. package/dist/widget/widgets/Comparison.d.ts +3 -0
  70. package/dist/widget/widgets/Comparison.d.ts.map +1 -0
  71. package/dist/widget/widgets/CredentialInput.d.ts +3 -0
  72. package/dist/widget/widgets/CredentialInput.d.ts.map +1 -0
  73. package/dist/widget/widgets/DataTable.d.ts +3 -0
  74. package/dist/widget/widgets/DataTable.d.ts.map +1 -0
  75. package/dist/widget/widgets/DocumentPreview.d.ts +3 -0
  76. package/dist/widget/widgets/DocumentPreview.d.ts.map +1 -0
  77. package/dist/widget/widgets/EntityCard.d.ts +3 -0
  78. package/dist/widget/widgets/EntityCard.d.ts.map +1 -0
  79. package/dist/widget/widgets/EntityList.d.ts +3 -0
  80. package/dist/widget/widgets/EntityList.d.ts.map +1 -0
  81. package/dist/widget/widgets/InfoCard.d.ts +3 -0
  82. package/dist/widget/widgets/InfoCard.d.ts.map +1 -0
  83. package/dist/widget/widgets/Metric.d.ts +3 -0
  84. package/dist/widget/widgets/Metric.d.ts.map +1 -0
  85. package/dist/widget/widgets/ScopeMap.d.ts +3 -0
  86. package/dist/widget/widgets/ScopeMap.d.ts.map +1 -0
  87. package/dist/widget/widgets/ScoreBreakdown.d.ts +3 -0
  88. package/dist/widget/widgets/ScoreBreakdown.d.ts.map +1 -0
  89. package/dist/widget/widgets/StatusBoard.d.ts +3 -0
  90. package/dist/widget/widgets/StatusBoard.d.ts.map +1 -0
  91. package/dist/widget/widgets/Timeline.d.ts +3 -0
  92. package/dist/widget/widgets/Timeline.d.ts.map +1 -0
  93. package/dist/widget/widgets/WidgetRenderer.d.ts +28 -0
  94. package/dist/widget/widgets/WidgetRenderer.d.ts.map +1 -0
  95. package/dist/widget.js +1668 -0
  96. package/dist/widget.js.map +1 -0
  97. package/package.json +8 -1
package/dist/widget.js ADDED
@@ -0,0 +1,1668 @@
1
+ import { jsx as e, jsxs as n, Fragment as ne } from "react/jsx-runtime";
2
+ import { useState as w, useCallback as b, Component as re, useRef as A, useEffect as M } from "react";
3
+ import { m as ie, u as le, b as de, a as oe } from "./theme-BaBR_tym.js";
4
+ import { d as tt, c as st } from "./theme-BaBR_tym.js";
5
+ import { W as at, a as nt, d as rt, g as it, l as lt } from "./event-bus-h26clqbZ.js";
6
+ /**
7
+ * @license
8
+ * Copyright 2025 Amodal Labs, Inc.
9
+ * SPDX-License-Identifier: MIT
10
+ */
11
+ function O(s) {
12
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13
+ }
14
+ function D(s) {
15
+ let c = O(s);
16
+ return c = c.replace(/`([^`]+)`/g, '<code class="pcw-md-code">$1</code>'), c = c.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>"), c = c.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), c = c.replace(/__(.+?)__/g, "<strong>$1</strong>"), c = c.replace(/\*(.+?)\*/g, "<em>$1</em>"), c = c.replace(new RegExp("(?<!\\w)_(.+?)_(?!\\w)", "g"), "<em>$1</em>"), c = c.replace(
17
+ /\[([^\]]+)\]\(([^)]+)\)/g,
18
+ '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
19
+ ), c;
20
+ }
21
+ function pe(s) {
22
+ const c = s.split(`
23
+ `), t = [];
24
+ let a = !1, i = [], l = !1;
25
+ for (let d = 0; d < c.length; d++) {
26
+ const r = c[d];
27
+ if (r.startsWith("```")) {
28
+ a ? (t.push(`<pre class="pcw-md-codeblock"><code>${O(i.join(`
29
+ `))}</code></pre>`), i = [], a = !1) : (l && (t.push("</ul>"), l = !1), a = !0);
30
+ continue;
31
+ }
32
+ if (a) {
33
+ i.push(r);
34
+ continue;
35
+ }
36
+ if (r.trim() === "") {
37
+ l && (t.push("</ul>"), l = !1);
38
+ continue;
39
+ }
40
+ const p = /^(#{1,4})\s+(.+)$/.exec(r);
41
+ if (p) {
42
+ l && (t.push("</ul>"), l = !1);
43
+ const u = p[1].length;
44
+ t.push(`<h${String(u)} class="pcw-md-h${String(u)}">${D(p[2])}</h${String(u)}>`);
45
+ continue;
46
+ }
47
+ const o = /^(\s*)[-*]\s+(.+)$/.exec(r) ?? /^(\s*)\d+\.\s+(.+)$/.exec(r);
48
+ if (o) {
49
+ l || (t.push('<ul class="pcw-md-list">'), l = !0), t.push(`<li>${D(o[2])}</li>`);
50
+ continue;
51
+ }
52
+ l && (t.push("</ul>"), l = !1), t.push(`<p>${D(r)}</p>`);
53
+ }
54
+ return a && t.push(`<pre class="pcw-md-codeblock"><code>${O(i.join(`
55
+ `))}</code></pre>`), l && t.push("</ul>"), t.join(`
56
+ `);
57
+ }
58
+ function x({ text: s, className: c }) {
59
+ const t = pe(s);
60
+ return /* @__PURE__ */ e(
61
+ "div",
62
+ {
63
+ className: `pcw-formatted-text${c ? ` ${c}` : ""}`,
64
+ dangerouslySetInnerHTML: { __html: t }
65
+ }
66
+ );
67
+ }
68
+ function he({ event: s }) {
69
+ const [c, t] = w(!1), a = !!(s.result || s.error || s.toolArgs);
70
+ return /* @__PURE__ */ n("div", { className: "pcw-subagent-row", children: [
71
+ /* @__PURE__ */ n(
72
+ "button",
73
+ {
74
+ type: "button",
75
+ className: `pcw-subagent-row__header${a ? "" : " pcw-subagent-row__header--static"}`,
76
+ onClick: () => {
77
+ a && t(!c);
78
+ },
79
+ children: [
80
+ a && /* @__PURE__ */ e("span", { className: "pcw-subagent-row__chevron", children: c ? "▼" : "▶" }),
81
+ /* @__PURE__ */ e("span", { className: `pcw-subagent-row__icon${s.error ? " pcw-subagent-row__icon--error" : ""}`, children: s.error ? "✗" : "✓" }),
82
+ /* @__PURE__ */ e("span", { className: "pcw-subagent-row__name", children: s.toolName ?? "unknown" })
83
+ ]
84
+ }
85
+ ),
86
+ c && /* @__PURE__ */ n("div", { className: "pcw-subagent-row__detail", children: [
87
+ s.error && /* @__PURE__ */ e("pre", { className: "pcw-subagent-row__error", children: s.error }),
88
+ s.result && /* @__PURE__ */ e("pre", { className: "pcw-subagent-row__result", children: s.result }),
89
+ s.toolArgs && /* @__PURE__ */ e("pre", { className: "pcw-subagent-row__args", children: JSON.stringify(s.toolArgs, null, 2) })
90
+ ] })
91
+ ] });
92
+ }
93
+ function ue({ params: s }) {
94
+ const c = s.subagent, t = s.task, a = s.instruction, i = s.kb_tags, l = s.tools;
95
+ return /* @__PURE__ */ n("div", { className: "pcw-dispatch-args", children: [
96
+ c && /* @__PURE__ */ n("div", { className: "pcw-dispatch-args__row", children: [
97
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__label", children: "agent" }),
98
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__value pcw-dispatch-args__value--mono", children: c })
99
+ ] }),
100
+ t && /* @__PURE__ */ n("div", { className: "pcw-dispatch-args__row", children: [
101
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__label", children: "task" }),
102
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__value", children: t })
103
+ ] }),
104
+ a && !t && /* @__PURE__ */ n("div", { className: "pcw-dispatch-args__row", children: [
105
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__label", children: "instruction" }),
106
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__value", children: a })
107
+ ] }),
108
+ i && i.length > 0 && /* @__PURE__ */ n("div", { className: "pcw-dispatch-args__row", children: [
109
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__label", children: "kb" }),
110
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__value pcw-dispatch-args__tags", children: i.map((d) => /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__tag", children: d }, d)) })
111
+ ] }),
112
+ l && l.length > 0 && /* @__PURE__ */ n("div", { className: "pcw-dispatch-args__row", children: [
113
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__label", children: "tools" }),
114
+ /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__value pcw-dispatch-args__tags", children: l.map((d) => /* @__PURE__ */ e("span", { className: "pcw-dispatch-args__tag", children: d }, d)) })
115
+ ] })
116
+ ] });
117
+ }
118
+ function me(s) {
119
+ if (!s || s.length === 0) return [];
120
+ const c = [];
121
+ let t = "";
122
+ for (const a of s)
123
+ a.eventType === "thought" && a.text ? t += a.text : (a.eventType === "tool_call_start" || a.eventType === "tool_call_end") && (t && (c.push({ kind: "text", text: t }), t = ""), c.push({ kind: "tool", event: a }));
124
+ return t && c.push({ kind: "text", text: t }), c;
125
+ }
126
+ function _e({ event: s }) {
127
+ const c = s.eventType === "tool_call_end", t = s.error ? "✗" : c ? "✓" : "⦿", a = s.error ? "pcw-subagent-row__icon--error" : c ? "" : "pcw-subagent-row__icon--running";
128
+ return /* @__PURE__ */ n("div", { className: "pcw-subagent-inline-tool", children: [
129
+ /* @__PURE__ */ e("span", { className: `pcw-subagent-row__icon ${a}`, children: t }),
130
+ /* @__PURE__ */ e("span", { className: "pcw-subagent-row__name", children: s.toolName ?? "unknown" })
131
+ ] });
132
+ }
133
+ function we({ toolCall: s }) {
134
+ var u;
135
+ const [c, t] = w(!1), a = `pcw-tool-call__status pcw-tool-call__status--${s.status}`, i = s.duration_ms ? `dispatch (${String(s.duration_ms)}ms)` : "dispatch", l = (u = s.subagentEvents) == null ? void 0 : u.find(
136
+ (h) => h.eventType === "complete"
137
+ ), d = me(s.subagentEvents), r = d.length > 0, p = d.filter((h) => h.kind === "tool" && h.event.eventType === "tool_call_end").length, o = r || !!(l != null && l.text);
138
+ return /* @__PURE__ */ n("div", { className: "pcw-tool-call", children: [
139
+ /* @__PURE__ */ n("div", { className: "pcw-tool-call__header pcw-tool-call__header--static", children: [
140
+ /* @__PURE__ */ e("span", { className: "pcw-tool-call__name", children: i }),
141
+ /* @__PURE__ */ e("span", { className: a, children: s.status })
142
+ ] }),
143
+ s.parameters && /* @__PURE__ */ e(ue, { params: s.parameters }),
144
+ s.status === "running" && r && /* @__PURE__ */ e("div", { className: "pcw-dispatch-streaming", children: d.map(
145
+ (h, _) => h.kind === "text" ? /* @__PURE__ */ e(x, { text: h.text }, _) : /* @__PURE__ */ e(_e, { event: h.event }, _)
146
+ ) }),
147
+ s.status !== "running" && o && /* @__PURE__ */ n("div", { className: "pcw-dispatch-details", children: [
148
+ /* @__PURE__ */ n(
149
+ "button",
150
+ {
151
+ type: "button",
152
+ className: "pcw-dispatch-details__toggle",
153
+ onClick: () => t(!c),
154
+ children: [
155
+ /* @__PURE__ */ e("span", { className: "pcw-tool-call__chevron", children: c ? "▼" : "▶" }),
156
+ /* @__PURE__ */ e("span", { children: "details" }),
157
+ p > 0 && /* @__PURE__ */ n("span", { className: "pcw-dispatch-details__count", children: [
158
+ String(p),
159
+ " tool calls"
160
+ ] })
161
+ ]
162
+ }
163
+ ),
164
+ c && /* @__PURE__ */ n("div", { className: "pcw-dispatch-details__body", children: [
165
+ (l == null ? void 0 : l.text) && /* @__PURE__ */ e(x, { text: l.text, className: "pcw-tool-call__subagent-summary" }),
166
+ d.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-tool-call__subagent", children: d.map(
167
+ (h, _) => h.kind === "text" ? /* @__PURE__ */ e(x, { text: h.text, className: "pcw-dispatch-inline-text" }, _) : /* @__PURE__ */ e(he, { event: h.event }, _)
168
+ ) })
169
+ ] })
170
+ ] }),
171
+ s.error && /* @__PURE__ */ e("p", { className: "pcw-tool-call__error", children: s.error })
172
+ ] });
173
+ }
174
+ function K({ toolCall: s }) {
175
+ const [c, t] = w(!1);
176
+ if (s.toolName === "dispatch")
177
+ return /* @__PURE__ */ e(we, { toolCall: s });
178
+ const a = `pcw-tool-call__status pcw-tool-call__status--${s.status}`, i = s.duration_ms ? `${s.toolName} (${String(s.duration_ms)}ms)` : s.toolName;
179
+ return /* @__PURE__ */ n("div", { className: "pcw-tool-call", children: [
180
+ /* @__PURE__ */ n(
181
+ "button",
182
+ {
183
+ type: "button",
184
+ className: "pcw-tool-call__header",
185
+ onClick: () => t(!c),
186
+ children: [
187
+ /* @__PURE__ */ e("span", { className: "pcw-tool-call__chevron", children: c ? "▼" : "▶" }),
188
+ /* @__PURE__ */ e("span", { className: "pcw-tool-call__name", children: i }),
189
+ /* @__PURE__ */ e("span", { className: a, children: s.status })
190
+ ]
191
+ }
192
+ ),
193
+ c && s.parameters && /* @__PURE__ */ e("pre", { className: "pcw-tool-call__details", children: JSON.stringify(s.parameters, null, 2) }),
194
+ s.error && /* @__PURE__ */ e("p", { className: "pcw-tool-call__error", children: s.error })
195
+ ] });
196
+ }
197
+ /**
198
+ * @license
199
+ * Copyright 2025 Amodal Labs, Inc.
200
+ * SPDX-License-Identifier: MIT
201
+ */
202
+ function Z({ proposal: s }) {
203
+ return /* @__PURE__ */ n("div", { className: "pcw-kb-proposal", children: [
204
+ /* @__PURE__ */ n("div", { className: "pcw-kb-proposal__header", children: [
205
+ /* @__PURE__ */ e("span", { className: "pcw-kb-proposal__icon", children: "💡" }),
206
+ /* @__PURE__ */ e("span", { className: "pcw-kb-proposal__title", children: s.title }),
207
+ /* @__PURE__ */ e("span", { className: "pcw-kb-proposal__scope", children: s.scope })
208
+ ] }),
209
+ /* @__PURE__ */ e("p", { className: "pcw-kb-proposal__reasoning", children: s.reasoning })
210
+ ] });
211
+ }
212
+ /**
213
+ * @license
214
+ * Copyright 2025 Amodal Labs, Inc.
215
+ * SPDX-License-Identifier: MIT
216
+ */
217
+ function J({ skill: s }) {
218
+ return /* @__PURE__ */ n("span", { className: "pcw-skill-pill", children: [
219
+ "Using: ",
220
+ s
221
+ ] });
222
+ }
223
+ /**
224
+ * @license
225
+ * Copyright 2025 Amodal Labs, Inc.
226
+ * SPDX-License-Identifier: MIT
227
+ */
228
+ function ge() {
229
+ return /* @__PURE__ */ n("div", { className: "pcw-streaming", "aria-label": "Streaming", children: [
230
+ /* @__PURE__ */ e("span", { className: "pcw-streaming__dot" }),
231
+ /* @__PURE__ */ e("span", { className: "pcw-streaming__dot" }),
232
+ /* @__PURE__ */ e("span", { className: "pcw-streaming__dot" })
233
+ ] });
234
+ }
235
+ function be({
236
+ question: s,
237
+ index: c,
238
+ value: t,
239
+ onChange: a,
240
+ disabled: i
241
+ }) {
242
+ const l = `ask-user-q-${String(c)}`;
243
+ switch (s.type) {
244
+ case "text":
245
+ return /* @__PURE__ */ n("div", { className: "pcw-ask-user__field", children: [
246
+ /* @__PURE__ */ n("label", { htmlFor: l, className: "pcw-ask-user__label", children: [
247
+ s.header && /* @__PURE__ */ e("span", { className: "pcw-ask-user__header", children: s.header }),
248
+ s.question
249
+ ] }),
250
+ /* @__PURE__ */ e(
251
+ "textarea",
252
+ {
253
+ id: l,
254
+ className: "pcw-ask-user__textarea",
255
+ value: t,
256
+ onChange: (d) => a(d.target.value),
257
+ placeholder: s.placeholder ?? "",
258
+ disabled: i,
259
+ rows: 3
260
+ }
261
+ )
262
+ ] });
263
+ case "yesno":
264
+ return /* @__PURE__ */ n("div", { className: "pcw-ask-user__field", children: [
265
+ /* @__PURE__ */ n("span", { className: "pcw-ask-user__label", children: [
266
+ s.header && /* @__PURE__ */ e("span", { className: "pcw-ask-user__header", children: s.header }),
267
+ s.question
268
+ ] }),
269
+ /* @__PURE__ */ n("div", { className: "pcw-ask-user__yesno", children: [
270
+ /* @__PURE__ */ e(
271
+ "button",
272
+ {
273
+ type: "button",
274
+ className: `pcw-ask-user__yesno-btn ${t === "yes" ? "pcw-ask-user__yesno-btn--active" : ""}`,
275
+ onClick: () => a("yes"),
276
+ disabled: i,
277
+ children: "Yes"
278
+ }
279
+ ),
280
+ /* @__PURE__ */ e(
281
+ "button",
282
+ {
283
+ type: "button",
284
+ className: `pcw-ask-user__yesno-btn ${t === "no" ? "pcw-ask-user__yesno-btn--active" : ""}`,
285
+ onClick: () => a("no"),
286
+ disabled: i,
287
+ children: "No"
288
+ }
289
+ )
290
+ ] })
291
+ ] });
292
+ case "choice": {
293
+ const d = s.options ?? [];
294
+ if (s.multiSelect) {
295
+ const r = t ? t.split(",").filter(Boolean) : [], p = (o) => {
296
+ const u = r.includes(o) ? r.filter((h) => h !== o) : [...r, o];
297
+ a(u.join(","));
298
+ };
299
+ return /* @__PURE__ */ n("div", { className: "pcw-ask-user__field", children: [
300
+ /* @__PURE__ */ n("span", { className: "pcw-ask-user__label", children: [
301
+ s.header && /* @__PURE__ */ e("span", { className: "pcw-ask-user__header", children: s.header }),
302
+ s.question
303
+ ] }),
304
+ /* @__PURE__ */ e("div", { className: "pcw-ask-user__choices", children: d.map((o) => /* @__PURE__ */ n("label", { className: "pcw-ask-user__choice", children: [
305
+ /* @__PURE__ */ e(
306
+ "input",
307
+ {
308
+ type: "checkbox",
309
+ checked: r.includes(o.label),
310
+ onChange: () => p(o.label),
311
+ disabled: i
312
+ }
313
+ ),
314
+ /* @__PURE__ */ e("span", { className: "pcw-ask-user__choice-label", children: o.label }),
315
+ o.description && /* @__PURE__ */ e("span", { className: "pcw-ask-user__choice-desc", children: o.description })
316
+ ] }, o.label)) })
317
+ ] });
318
+ }
319
+ return /* @__PURE__ */ n("div", { className: "pcw-ask-user__field", children: [
320
+ /* @__PURE__ */ n("span", { className: "pcw-ask-user__label", children: [
321
+ s.header && /* @__PURE__ */ e("span", { className: "pcw-ask-user__header", children: s.header }),
322
+ s.question
323
+ ] }),
324
+ /* @__PURE__ */ e("div", { className: "pcw-ask-user__choices", children: d.map((r) => /* @__PURE__ */ n("label", { className: "pcw-ask-user__choice", children: [
325
+ /* @__PURE__ */ e(
326
+ "input",
327
+ {
328
+ type: "radio",
329
+ name: l,
330
+ checked: t === r.label,
331
+ onChange: () => a(r.label),
332
+ disabled: i
333
+ }
334
+ ),
335
+ /* @__PURE__ */ e("span", { className: "pcw-ask-user__choice-label", children: r.label }),
336
+ r.description && /* @__PURE__ */ e("span", { className: "pcw-ask-user__choice-desc", children: r.description })
337
+ ] }, r.label)) })
338
+ ] });
339
+ }
340
+ default:
341
+ return null;
342
+ }
343
+ }
344
+ function ve({ block: s, onSubmit: c }) {
345
+ const [t, a] = w({}), [i, l] = w(!1), d = s.status === "submitted", r = d || i, p = () => {
346
+ l(!0), c(s.askId, t);
347
+ };
348
+ return d && s.answers ? /* @__PURE__ */ e("div", { className: "pcw-ask-user pcw-ask-user--submitted", children: s.questions.map((o, u) => {
349
+ var h;
350
+ return /* @__PURE__ */ n("div", { className: "pcw-ask-user__summary", children: [
351
+ /* @__PURE__ */ e("span", { className: "pcw-ask-user__summary-q", children: o.question }),
352
+ /* @__PURE__ */ e("span", { className: "pcw-ask-user__summary-a", children: ((h = s.answers) == null ? void 0 : h[String(u)]) ?? "" })
353
+ ] }, `${o.header}-${String(u)}`);
354
+ }) }) : /* @__PURE__ */ n("div", { className: "pcw-ask-user", children: [
355
+ s.questions.map((o, u) => /* @__PURE__ */ e(
356
+ be,
357
+ {
358
+ question: o,
359
+ index: u,
360
+ value: t[String(u)] ?? "",
361
+ onChange: (h) => a((_) => ({ ..._, [String(u)]: h })),
362
+ disabled: r
363
+ },
364
+ `${o.header}-${String(u)}`
365
+ )),
366
+ /* @__PURE__ */ e(
367
+ "button",
368
+ {
369
+ type: "button",
370
+ className: "pcw-ask-user__submit",
371
+ onClick: p,
372
+ disabled: r,
373
+ children: i ? "Submitting..." : "Submit"
374
+ }
375
+ )
376
+ ] });
377
+ }
378
+ function Ne({ data: s, sendMessage: c, onInteraction: t }) {
379
+ const a = s, i = Math.min(100, Math.max(0, a.suspicion_score)), l = b(() => {
380
+ const p = {
381
+ type: "entity_hovered",
382
+ entity: { entityType: "device", entityId: a.mac, source: "widget:entity-card" },
383
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
384
+ };
385
+ t == null || t(p);
386
+ }, [a.mac, t]), d = b(() => {
387
+ const p = {
388
+ type: "entity_unhovered",
389
+ entity: { entityType: "device", entityId: a.mac, source: "widget:entity-card" },
390
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
391
+ };
392
+ t == null || t(p);
393
+ }, [a.mac, t]), r = b(() => {
394
+ const p = {
395
+ type: "entity_clicked",
396
+ entity: { entityType: "device", entityId: a.mac, source: "widget:entity-card" },
397
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
398
+ };
399
+ t == null || t(p);
400
+ }, [a.mac, t]);
401
+ return /* @__PURE__ */ n(
402
+ "div",
403
+ {
404
+ className: "pcw-widget-card pcw-entity-card",
405
+ onMouseEnter: l,
406
+ onMouseLeave: d,
407
+ onClick: r,
408
+ "data-testid": "entity-card",
409
+ children: [
410
+ /* @__PURE__ */ n("div", { className: "pcw-entity-card__header", children: [
411
+ /* @__PURE__ */ e("span", { className: "pcw-entity-card__mac", children: a.mac }),
412
+ /* @__PURE__ */ e("span", { className: "pcw-entity-card__mfr", children: a.manufacturer })
413
+ ] }),
414
+ Array.isArray(a.protocols) && a.protocols.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-entity-card__protocols", children: a.protocols.map((p) => /* @__PURE__ */ e("span", { className: "pcw-entity-card__protocol-badge", children: p }, p)) }),
415
+ /* @__PURE__ */ n("div", { className: "pcw-entity-card__zone", children: [
416
+ "Zone ",
417
+ a.zone,
418
+ a.zone_name ? ` (${a.zone_name})` : ""
419
+ ] }),
420
+ /* @__PURE__ */ n("div", { className: "pcw-score-bar", children: [
421
+ /* @__PURE__ */ n("div", { className: "pcw-score-bar__label", children: [
422
+ "Score: ",
423
+ a.suspicion_score
424
+ ] }),
425
+ /* @__PURE__ */ e("div", { className: "pcw-score-bar__track", children: /* @__PURE__ */ e(
426
+ "div",
427
+ {
428
+ className: "pcw-score-bar__fill",
429
+ style: { width: `${String(i)}%` }
430
+ }
431
+ ) })
432
+ ] }),
433
+ a.score_factors && Object.keys(a.score_factors).length > 0 && /* @__PURE__ */ e("div", { className: "pcw-entity-card__factors", children: Object.entries(a.score_factors).map(([p, o]) => /* @__PURE__ */ n("div", { className: "pcw-entity-card__factor", children: [
434
+ /* @__PURE__ */ e("span", { children: p.replace(/_/g, " ") }),
435
+ /* @__PURE__ */ n("span", { children: [
436
+ "+",
437
+ o
438
+ ] })
439
+ ] }, p)) }),
440
+ /* @__PURE__ */ n("div", { className: "pcw-entity-card__meta", children: [
441
+ /* @__PURE__ */ n("span", { children: [
442
+ "Tag: ",
443
+ a.tag_status
444
+ ] }),
445
+ a.dwell_time_minutes != null && /* @__PURE__ */ n("span", { children: [
446
+ "Dwell: ",
447
+ a.dwell_time_minutes,
448
+ "min"
449
+ ] })
450
+ ] }),
451
+ /* @__PURE__ */ n("div", { className: "pcw-entity-card__actions", children: [
452
+ /* @__PURE__ */ e(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: "pcw-entity-card__btn",
457
+ onClick: () => c(`Investigate device ${a.mac} in Zone ${a.zone}`),
458
+ children: "Investigate"
459
+ }
460
+ ),
461
+ /* @__PURE__ */ e(
462
+ "button",
463
+ {
464
+ type: "button",
465
+ className: "pcw-entity-card__btn pcw-entity-card__btn--secondary",
466
+ onClick: () => c(`Tag device ${a.mac} as suspicious`),
467
+ children: "Tag"
468
+ }
469
+ )
470
+ ] })
471
+ ]
472
+ }
473
+ );
474
+ }
475
+ function ye({ data: s, sendMessage: c }) {
476
+ const t = s, [a, i] = w(null), [l, d] = w(t.sort ?? "suspicion_score"), r = [...t.devices].sort((u, h) => l === "suspicion_score" ? h.suspicion_score - u.suspicion_score : l === "mac" ? u.mac.localeCompare(h.mac) : l === "zone" ? u.zone.localeCompare(h.zone) : 0), p = t.max_display ?? r.length, o = r.slice(0, p);
477
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-entity-list", children: [
478
+ t.title && /* @__PURE__ */ e("div", { className: "pcw-entity-list__title", children: t.title }),
479
+ /* @__PURE__ */ n("div", { className: "pcw-entity-list__sort", children: [
480
+ "Sort:",
481
+ ["suspicion_score", "mac", "zone"].map((u) => /* @__PURE__ */ e(
482
+ "button",
483
+ {
484
+ type: "button",
485
+ className: `pcw-entity-list__sort-btn ${l === u ? "pcw-entity-list__sort-btn--active" : ""}`,
486
+ onClick: () => d(u),
487
+ children: u.replace(/_/g, " ")
488
+ },
489
+ u
490
+ ))
491
+ ] }),
492
+ /* @__PURE__ */ n("table", { className: "pcw-data-table__table", children: [
493
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ n("tr", { children: [
494
+ /* @__PURE__ */ e("th", { children: "MAC" }),
495
+ /* @__PURE__ */ e("th", { children: "Mfr" }),
496
+ /* @__PURE__ */ e("th", { children: "Zone" }),
497
+ /* @__PURE__ */ e("th", { children: "Score" }),
498
+ /* @__PURE__ */ e("th", { children: "Tag" })
499
+ ] }) }),
500
+ /* @__PURE__ */ e("tbody", { children: o.map((u) => /* @__PURE__ */ n(
501
+ "tr",
502
+ {
503
+ className: `pcw-entity-list__row ${a === u.mac ? "pcw-entity-list__row--expanded" : ""}`,
504
+ onClick: () => i(a === u.mac ? null : u.mac),
505
+ children: [
506
+ /* @__PURE__ */ e("td", { className: "pcw-entity-list__mac", children: u.mac }),
507
+ /* @__PURE__ */ e("td", { children: u.manufacturer }),
508
+ /* @__PURE__ */ e("td", { children: u.zone }),
509
+ /* @__PURE__ */ e("td", { children: u.suspicion_score }),
510
+ /* @__PURE__ */ e("td", { children: u.tag_status })
511
+ ]
512
+ },
513
+ u.mac
514
+ )) })
515
+ ] }),
516
+ a && /* @__PURE__ */ e("div", { className: "pcw-entity-list__detail", children: /* @__PURE__ */ n(
517
+ "button",
518
+ {
519
+ type: "button",
520
+ className: "pcw-entity-card__btn",
521
+ onClick: () => c(`Tell me more about device ${a}`),
522
+ children: [
523
+ "Investigate ",
524
+ a
525
+ ]
526
+ }
527
+ ) }),
528
+ r.length > p && /* @__PURE__ */ n("div", { className: "pcw-entity-list__more", children: [
529
+ "+",
530
+ r.length - p,
531
+ " more devices"
532
+ ] })
533
+ ] });
534
+ }
535
+ const fe = {
536
+ A: { x: 10, y: 10, w: 80, h: 60 },
537
+ B: { x: 100, y: 10, w: 80, h: 60 },
538
+ C: { x: 190, y: 10, w: 80, h: 60 },
539
+ D: { x: 10, y: 80, w: 125, h: 60 },
540
+ E: { x: 145, y: 80, w: 125, h: 60 }
541
+ }, ke = {
542
+ A: "Lobby",
543
+ B: "Offices",
544
+ C: "Server Room",
545
+ D: "Warehouse",
546
+ E: "Parking"
547
+ };
548
+ function Se({ data: s, onInteraction: c }) {
549
+ const t = s, a = new Set(t.highlight_zones ?? []), i = b(
550
+ (d, r) => {
551
+ const p = {
552
+ type: d,
553
+ entity: { entityType: "zone", entityId: r, source: "widget:scope-map" },
554
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
555
+ };
556
+ c == null || c(p);
557
+ },
558
+ [c]
559
+ ), l = b(
560
+ (d, r) => {
561
+ const p = {
562
+ type: d,
563
+ entity: { entityType: "device", entityId: r, source: "widget:scope-map" },
564
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
565
+ };
566
+ c == null || c(p);
567
+ },
568
+ [c]
569
+ );
570
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-scope-map", children: [
571
+ t.label && /* @__PURE__ */ e("div", { className: "pcw-scope-map__label", children: t.label }),
572
+ /* @__PURE__ */ e("svg", { viewBox: "0 0 280 150", className: "pcw-scope-map__svg", children: Object.entries(fe).map(([d, r]) => /* @__PURE__ */ n("g", { children: [
573
+ /* @__PURE__ */ e(
574
+ "rect",
575
+ {
576
+ x: r.x,
577
+ y: r.y,
578
+ width: r.w,
579
+ height: r.h,
580
+ rx: 4,
581
+ className: a.has(d) ? "pcw-scope-map__zone pcw-scope-map__zone--highlight" : "pcw-scope-map__zone",
582
+ "data-testid": `zone-${d}`,
583
+ onMouseEnter: () => i("entity_hovered", d),
584
+ onMouseLeave: () => i("entity_unhovered", d),
585
+ onClick: () => i("entity_clicked", d),
586
+ style: { cursor: "pointer" }
587
+ }
588
+ ),
589
+ /* @__PURE__ */ n(
590
+ "text",
591
+ {
592
+ x: r.x + r.w / 2,
593
+ y: r.y + r.h / 2 - 6,
594
+ textAnchor: "middle",
595
+ className: "pcw-scope-map__zone-label",
596
+ style: { pointerEvents: "none" },
597
+ children: [
598
+ "Zone ",
599
+ d
600
+ ]
601
+ }
602
+ ),
603
+ /* @__PURE__ */ e(
604
+ "text",
605
+ {
606
+ x: r.x + r.w / 2,
607
+ y: r.y + r.h / 2 + 8,
608
+ textAnchor: "middle",
609
+ className: "pcw-scope-map__zone-name",
610
+ style: { pointerEvents: "none" },
611
+ children: ke[d] ?? ""
612
+ }
613
+ )
614
+ ] }, d)) }),
615
+ t.highlight_devices && t.highlight_devices.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-scope-map__devices", children: t.highlight_devices.map((d) => /* @__PURE__ */ e(
616
+ "span",
617
+ {
618
+ className: "pcw-scope-map__device-badge",
619
+ "data-testid": `device-badge-${d}`,
620
+ onMouseEnter: () => l("entity_hovered", d),
621
+ onMouseLeave: () => l("entity_unhovered", d),
622
+ onClick: () => l("entity_clicked", d),
623
+ style: { cursor: "pointer" },
624
+ children: d
625
+ },
626
+ d
627
+ )) })
628
+ ] });
629
+ }
630
+ /**
631
+ * @license
632
+ * Copyright 2025 Amodal Labs, Inc.
633
+ * SPDX-License-Identifier: MIT
634
+ */
635
+ const xe = {
636
+ low: "pcw-alert-card__severity--low",
637
+ medium: "pcw-alert-card__severity--medium",
638
+ high: "pcw-alert-card__severity--high",
639
+ critical: "pcw-alert-card__severity--critical"
640
+ };
641
+ function Ce({ data: s, sendMessage: c }) {
642
+ const t = s;
643
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-alert-card", children: [
644
+ /* @__PURE__ */ n("div", { className: "pcw-alert-card__header", children: [
645
+ /* @__PURE__ */ e("span", { className: `pcw-alert-card__severity ${xe[t.severity] ?? ""}`, children: t.severity.toUpperCase() }),
646
+ /* @__PURE__ */ e("span", { className: "pcw-alert-card__type", children: t.type.replace(/_/g, " ") }),
647
+ /* @__PURE__ */ n("span", { className: "pcw-alert-card__zone", children: [
648
+ "Zone ",
649
+ t.zone
650
+ ] })
651
+ ] }),
652
+ /* @__PURE__ */ e("p", { className: "pcw-alert-card__description", children: t.description }),
653
+ /* @__PURE__ */ e("div", { className: "pcw-alert-card__devices", children: t.involved_devices.map((a) => /* @__PURE__ */ e(
654
+ "button",
655
+ {
656
+ type: "button",
657
+ className: "pcw-alert-card__device-link",
658
+ onClick: () => c(`Tell me about device ${a}`),
659
+ children: a
660
+ },
661
+ a
662
+ )) }),
663
+ t.protocols_involved && t.protocols_involved.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-alert-card__protocols", children: t.protocols_involved.map((a) => /* @__PURE__ */ e("span", { className: "pcw-entity-card__protocol-badge", children: a }, a)) }),
664
+ /* @__PURE__ */ e("div", { className: "pcw-alert-card__time", children: new Date(t.detected_at).toLocaleString() })
665
+ ] });
666
+ }
667
+ /**
668
+ * @license
669
+ * Copyright 2025 Amodal Labs, Inc.
670
+ * SPDX-License-Identifier: MIT
671
+ */
672
+ const Y = {
673
+ device_seen: "#3b82f6",
674
+ zone_change: "#8b5cf6",
675
+ alert: "#ef4444",
676
+ tag_change: "#10b981",
677
+ custom: "#6b7280"
678
+ };
679
+ function $e({ data: s, sendMessage: c }) {
680
+ const t = s;
681
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-timeline", children: [
682
+ t.label && /* @__PURE__ */ e("div", { className: "pcw-timeline__label", children: t.label }),
683
+ /* @__PURE__ */ e("div", { className: "pcw-timeline__events", children: t.events.map((a, i) => {
684
+ const l = Y[a.type ?? "custom"] ?? Y.custom;
685
+ return /* @__PURE__ */ n("div", { className: "pcw-timeline__event", children: [
686
+ /* @__PURE__ */ e("div", { className: "pcw-timeline__marker", style: { backgroundColor: l } }),
687
+ /* @__PURE__ */ n("div", { className: "pcw-timeline__content", children: [
688
+ /* @__PURE__ */ e("span", { className: "pcw-timeline__time", children: new Date(a.timestamp).toLocaleTimeString(void 0, {
689
+ hour: "2-digit",
690
+ minute: "2-digit"
691
+ }) }),
692
+ /* @__PURE__ */ e("span", { className: "pcw-timeline__event-label", children: a.label }),
693
+ a.device && /* @__PURE__ */ e(
694
+ "button",
695
+ {
696
+ type: "button",
697
+ className: "pcw-alert-card__device-link",
698
+ onClick: () => c(`Tell me about device ${a.device}`),
699
+ children: a.device
700
+ }
701
+ )
702
+ ] })
703
+ ] }, `${a.timestamp}-${String(i)}`);
704
+ }) })
705
+ ] });
706
+ }
707
+ /**
708
+ * @license
709
+ * Copyright 2025 Amodal Labs, Inc.
710
+ * SPDX-License-Identifier: MIT
711
+ */
712
+ function Te({ data: s, sendMessage: c }) {
713
+ const t = s;
714
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-comparison", children: [
715
+ t.title && /* @__PURE__ */ e("div", { className: "pcw-comparison__title", children: t.title }),
716
+ /* @__PURE__ */ e("div", { className: "pcw-comparison__grid", children: t.items.map((a) => /* @__PURE__ */ n("div", { className: "pcw-comparison__item", children: [
717
+ /* @__PURE__ */ e("div", { className: "pcw-comparison__mac", children: a.mac }),
718
+ /* @__PURE__ */ e("div", { className: "pcw-comparison__detail", children: a.manufacturer }),
719
+ /* @__PURE__ */ e("div", { className: "pcw-comparison__detail", children: a.protocols.join(", ") }),
720
+ /* @__PURE__ */ n("div", { className: "pcw-comparison__detail", children: [
721
+ "Zone ",
722
+ a.zone
723
+ ] }),
724
+ /* @__PURE__ */ n("div", { className: "pcw-comparison__score", children: [
725
+ "Score: ",
726
+ a.suspicion_score
727
+ ] }),
728
+ /* @__PURE__ */ n("div", { className: "pcw-comparison__detail", children: [
729
+ "Tag: ",
730
+ a.tag_status
731
+ ] }),
732
+ /* @__PURE__ */ e(
733
+ "button",
734
+ {
735
+ type: "button",
736
+ className: "pcw-entity-card__btn",
737
+ onClick: () => c(`Investigate device ${a.mac}`),
738
+ children: "Investigate"
739
+ }
740
+ )
741
+ ] }, a.mac)) })
742
+ ] });
743
+ }
744
+ function Ee({ data: s }) {
745
+ const c = s, t = c.columns ?? [], a = c.rows ?? [], [i, l] = w(null), [d, r] = w("asc"), p = b(
746
+ (u) => {
747
+ c.sortable && (i === u ? r((h) => h === "asc" ? "desc" : "asc") : (l(u), r("asc")));
748
+ },
749
+ [c.sortable, i]
750
+ ), o = i ? [...a].sort((u, h) => {
751
+ const _ = u[i], m = h[i];
752
+ if (typeof _ == "number" && typeof m == "number")
753
+ return d === "asc" ? _ - m : m - _;
754
+ const g = String(_ ?? ""), v = String(m ?? "");
755
+ return d === "asc" ? g.localeCompare(v) : v.localeCompare(g);
756
+ }) : a;
757
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-data-table", children: [
758
+ c.title && /* @__PURE__ */ e("div", { className: "pcw-data-table__title", children: c.title }),
759
+ /* @__PURE__ */ e("div", { className: "pcw-data-table__scroll", children: /* @__PURE__ */ n("table", { className: "pcw-data-table__table", children: [
760
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { children: t.map((u) => /* @__PURE__ */ n(
761
+ "th",
762
+ {
763
+ onClick: () => p(u.key),
764
+ className: c.sortable ? "pcw-data-table__sortable" : "",
765
+ children: [
766
+ u.label,
767
+ i === u.key && (d === "asc" ? " ▲" : " ▼")
768
+ ]
769
+ },
770
+ u.key
771
+ )) }) }),
772
+ /* @__PURE__ */ e("tbody", { children: o.map((u, h) => /* @__PURE__ */ e("tr", { children: t.map((_) => /* @__PURE__ */ e("td", { children: String(u[_.key] ?? "") }, _.key)) }, String(h))) })
773
+ ] }) })
774
+ ] });
775
+ }
776
+ /**
777
+ * @license
778
+ * Copyright 2025 Amodal Labs, Inc.
779
+ * SPDX-License-Identifier: MIT
780
+ */
781
+ function Ae({ data: s }) {
782
+ const c = s, t = c.max_score ?? 100, a = Math.min(100, Math.max(0, c.total_score / t * 100));
783
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-score-breakdown", children: [
784
+ c.label && /* @__PURE__ */ e("div", { className: "pcw-score-breakdown__label", children: c.label }),
785
+ /* @__PURE__ */ n("div", { className: "pcw-score-bar", children: [
786
+ /* @__PURE__ */ n("div", { className: "pcw-score-bar__label", children: [
787
+ "Score: ",
788
+ c.total_score,
789
+ t !== 100 ? ` / ${t}` : ""
790
+ ] }),
791
+ /* @__PURE__ */ e("div", { className: "pcw-score-bar__track", children: /* @__PURE__ */ e(
792
+ "div",
793
+ {
794
+ className: "pcw-score-bar__fill",
795
+ style: { width: `${String(a)}%` }
796
+ }
797
+ ) })
798
+ ] }),
799
+ /* @__PURE__ */ e("div", { className: "pcw-score-breakdown__factors", children: c.factors.map((i) => {
800
+ const l = i.max ?? t, d = Math.min(100, Math.max(0, i.value / l * 100));
801
+ return /* @__PURE__ */ n("div", { className: "pcw-score-breakdown__factor", children: [
802
+ /* @__PURE__ */ n("div", { className: "pcw-score-breakdown__factor-header", children: [
803
+ /* @__PURE__ */ e("span", { className: "pcw-score-breakdown__factor-name", children: i.name.replace(/_/g, " ") }),
804
+ /* @__PURE__ */ n("span", { className: "pcw-score-breakdown__factor-value", children: [
805
+ "+",
806
+ i.value
807
+ ] })
808
+ ] }),
809
+ /* @__PURE__ */ e("div", { className: "pcw-score-breakdown__factor-bar", children: /* @__PURE__ */ e(
810
+ "div",
811
+ {
812
+ className: "pcw-score-breakdown__factor-fill",
813
+ style: { width: `${String(d)}%` }
814
+ }
815
+ ) }),
816
+ i.description && /* @__PURE__ */ e("div", { className: "pcw-score-breakdown__factor-desc", children: i.description })
817
+ ] }, i.name);
818
+ }) })
819
+ ] });
820
+ }
821
+ /**
822
+ * @license
823
+ * Copyright 2025 Amodal Labs, Inc.
824
+ * SPDX-License-Identifier: MIT
825
+ */
826
+ const Q = {
827
+ critical: 0,
828
+ high: 1,
829
+ medium: 2,
830
+ low: 3
831
+ };
832
+ function Le({ data: s, sendMessage: c }) {
833
+ const t = s, a = [...t.items].sort(
834
+ (i, l) => (Q[i.severity] ?? 4) - (Q[l.severity] ?? 4)
835
+ );
836
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-status-board", children: [
837
+ t.title && /* @__PURE__ */ e("div", { className: "pcw-status-board__title", children: t.title }),
838
+ /* @__PURE__ */ e("div", { className: "pcw-status-board__items", children: a.map((i) => /* @__PURE__ */ n(
839
+ "div",
840
+ {
841
+ className: `pcw-status-board__item pcw-status-board__item--${i.severity}`,
842
+ onClick: () => c(`Tell me more about ${i.label}`),
843
+ style: { cursor: "pointer" },
844
+ children: [
845
+ /* @__PURE__ */ n("div", { className: "pcw-status-board__item-header", children: [
846
+ /* @__PURE__ */ e("span", { className: `pcw-status-board__severity pcw-status-board__severity--${i.severity}`, children: i.severity.toUpperCase() }),
847
+ /* @__PURE__ */ e("span", { className: "pcw-status-board__item-label", children: i.label }),
848
+ /* @__PURE__ */ e("span", { className: "pcw-status-board__item-status", children: i.status })
849
+ ] }),
850
+ i.description && /* @__PURE__ */ e("div", { className: "pcw-status-board__item-desc", children: i.description })
851
+ ]
852
+ },
853
+ i.id
854
+ )) })
855
+ ] });
856
+ }
857
+ function Be({ data: s, sendMessage: c }) {
858
+ const t = s, [a, i] = w({}), [l, d] = w("idle"), [r, p] = w(""), o = b((h, _) => {
859
+ i((m) => ({ ...m, [h]: _ }));
860
+ }, []), u = b(
861
+ async (h) => {
862
+ h.preventDefault(), d("submitting"), p("");
863
+ try {
864
+ const m = `${window.location.origin}/api/tenants/${t.tenant_id}/secrets`;
865
+ for (const g of t.fields) {
866
+ const v = await fetch(m, {
867
+ method: "POST",
868
+ headers: { "Content-Type": "application/json" },
869
+ body: JSON.stringify({
870
+ name: g.name,
871
+ value: a[g.name] ?? "",
872
+ connection_name: t.connection_name
873
+ })
874
+ });
875
+ if (!v.ok)
876
+ throw new Error(`Failed to save ${g.label}: ${String(v.status)}`);
877
+ }
878
+ d("success"), i({}), c(`Credentials for ${t.connection_name} have been saved.`);
879
+ } catch (_) {
880
+ d("error"), p(_ instanceof Error ? _.message : "Failed to save credentials");
881
+ }
882
+ },
883
+ [t.tenant_id, t.connection_name, t.fields, a, c]
884
+ );
885
+ return l === "success" ? /* @__PURE__ */ e("div", { className: "pcw-widget-card pcw-widget-card--credential-input", children: /* @__PURE__ */ n("div", { className: "pcw-credential-input__status pcw-credential-input__status--success", children: [
886
+ "Credentials for ",
887
+ t.connection_name,
888
+ " saved successfully."
889
+ ] }) }) : /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-widget-card--credential-input", children: [
890
+ /* @__PURE__ */ n("div", { className: "pcw-credential-input__title", children: [
891
+ "Configure ",
892
+ t.connection_name
893
+ ] }),
894
+ /* @__PURE__ */ n(
895
+ "form",
896
+ {
897
+ onSubmit: (h) => {
898
+ u(h);
899
+ },
900
+ children: [
901
+ t.fields.map((h) => /* @__PURE__ */ n("div", { className: "pcw-credential-input__field", children: [
902
+ /* @__PURE__ */ n("label", { className: "pcw-credential-input__label", htmlFor: `pcw-cred-${h.name}`, children: [
903
+ h.label,
904
+ h.required && /* @__PURE__ */ e("span", { "aria-hidden": "true", children: " *" })
905
+ ] }),
906
+ /* @__PURE__ */ e(
907
+ "input",
908
+ {
909
+ id: `pcw-cred-${h.name}`,
910
+ className: "pcw-credential-input__input",
911
+ type: h.type,
912
+ required: h.required,
913
+ autoComplete: h.type === "password" ? "new-password" : "off",
914
+ value: a[h.name] ?? "",
915
+ disabled: l === "submitting",
916
+ onChange: (_) => o(h.name, _.target.value)
917
+ }
918
+ )
919
+ ] }, h.name)),
920
+ l === "error" && /* @__PURE__ */ e("div", { className: "pcw-credential-input__status pcw-credential-input__status--error", children: r }),
921
+ /* @__PURE__ */ e(
922
+ "button",
923
+ {
924
+ type: "submit",
925
+ className: "pcw-credential-input__submit",
926
+ disabled: l === "submitting",
927
+ children: l === "submitting" ? "Saving..." : "Save Credentials"
928
+ }
929
+ )
930
+ ]
931
+ }
932
+ )
933
+ ] });
934
+ }
935
+ const De = {
936
+ create: "New",
937
+ update: "Update"
938
+ };
939
+ function Me({ data: s, sendMessage: c }) {
940
+ const t = s, [a, i] = w(!1), [l, d] = w(t.body), [r, p] = w(!1), o = b(() => {
941
+ p(!0), c(`I've approved the ${t.resource_type} '${t.preview_id}'.`);
942
+ }, [t.resource_type, t.preview_id, c]), u = b(() => {
943
+ i(!0);
944
+ }, []), h = b(() => {
945
+ p(!0), i(!1), c(
946
+ `I've approved the ${t.resource_type} '${t.preview_id}' with edits:
947
+
948
+ ${l}`
949
+ );
950
+ }, [t.resource_type, t.preview_id, l, c]);
951
+ return r ? /* @__PURE__ */ e("div", { className: "pcw-widget-card pcw-widget-card--document-preview", children: /* @__PURE__ */ n("div", { className: "pcw-document-preview__header", children: [
952
+ /* @__PURE__ */ e("span", { className: "pcw-document-preview__title", children: t.title }),
953
+ /* @__PURE__ */ e("span", { className: "pcw-document-preview__badge pcw-document-preview__badge--approved", children: "Approved" })
954
+ ] }) }) : /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-widget-card--document-preview", children: [
955
+ /* @__PURE__ */ n("div", { className: "pcw-document-preview__header", children: [
956
+ /* @__PURE__ */ e("span", { className: "pcw-document-preview__title", children: t.title }),
957
+ t.category && /* @__PURE__ */ e("span", { className: "pcw-document-preview__badge pcw-document-preview__badge--category", children: t.category }),
958
+ /* @__PURE__ */ e("span", { className: "pcw-document-preview__badge pcw-document-preview__badge--action", children: De[t.action] ?? t.action })
959
+ ] }),
960
+ a ? /* @__PURE__ */ n("div", { className: "pcw-document-preview__editor-container", children: [
961
+ /* @__PURE__ */ e(
962
+ "textarea",
963
+ {
964
+ className: "pcw-document-preview__editor",
965
+ value: l,
966
+ onChange: (_) => d(_.target.value),
967
+ rows: 12
968
+ }
969
+ ),
970
+ /* @__PURE__ */ n("div", { className: "pcw-document-preview__actions", children: [
971
+ /* @__PURE__ */ e(
972
+ "button",
973
+ {
974
+ type: "button",
975
+ className: "pcw-document-preview__btn pcw-document-preview__btn--primary",
976
+ onClick: h,
977
+ children: "Approve with edits"
978
+ }
979
+ ),
980
+ /* @__PURE__ */ e(
981
+ "button",
982
+ {
983
+ type: "button",
984
+ className: "pcw-document-preview__btn pcw-document-preview__btn--secondary",
985
+ onClick: () => {
986
+ i(!1), d(t.body);
987
+ },
988
+ children: "Cancel"
989
+ }
990
+ )
991
+ ] })
992
+ ] }) : /* @__PURE__ */ n(ne, { children: [
993
+ /* @__PURE__ */ e("pre", { className: "pcw-document-preview__body", children: /* @__PURE__ */ e("code", { children: t.body }) }),
994
+ /* @__PURE__ */ n("div", { className: "pcw-document-preview__actions", children: [
995
+ /* @__PURE__ */ e(
996
+ "button",
997
+ {
998
+ type: "button",
999
+ className: "pcw-document-preview__btn pcw-document-preview__btn--primary",
1000
+ onClick: o,
1001
+ children: "Approve"
1002
+ }
1003
+ ),
1004
+ /* @__PURE__ */ e(
1005
+ "button",
1006
+ {
1007
+ type: "button",
1008
+ className: "pcw-document-preview__btn pcw-document-preview__btn--secondary",
1009
+ onClick: u,
1010
+ children: "Edit First"
1011
+ }
1012
+ )
1013
+ ] })
1014
+ ] })
1015
+ ] });
1016
+ }
1017
+ /**
1018
+ * @license
1019
+ * Copyright 2025 Amodal Labs, Inc.
1020
+ * SPDX-License-Identifier: MIT
1021
+ */
1022
+ function Oe({ data: s, sendMessage: c }) {
1023
+ const t = s, a = t.title ?? "Untitled", i = Array.isArray(t.fields) ? t.fields : [], l = Array.isArray(t.tags) ? t.tags : [], d = Array.isArray(t.actions) ? t.actions : [];
1024
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-info-card", "data-testid": "info-card", children: [
1025
+ /* @__PURE__ */ n("div", { className: "pcw-info-card__header", children: [
1026
+ /* @__PURE__ */ e("span", { className: "pcw-info-card__title", children: a }),
1027
+ t.status && /* @__PURE__ */ e("span", { className: `pcw-info-card__status pcw-info-card__status--${t.status}`, children: t.status })
1028
+ ] }),
1029
+ t.subtitle && /* @__PURE__ */ e("div", { className: "pcw-info-card__subtitle", children: t.subtitle }),
1030
+ t.description && /* @__PURE__ */ e("p", { className: "pcw-info-card__description", children: t.description }),
1031
+ i.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-info-card__fields", children: i.map((r) => /* @__PURE__ */ n("div", { className: "pcw-info-card__field", children: [
1032
+ /* @__PURE__ */ e("span", { className: "pcw-info-card__field-label", children: r.label }),
1033
+ /* @__PURE__ */ e("span", { className: "pcw-info-card__field-value", children: String(r.value) })
1034
+ ] }, r.label)) }),
1035
+ l.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-info-card__tags", children: l.map((r) => /* @__PURE__ */ e("span", { className: "pcw-info-card__tag", children: r }, r)) }),
1036
+ d.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-info-card__actions", children: d.map((r) => /* @__PURE__ */ e(
1037
+ "button",
1038
+ {
1039
+ type: "button",
1040
+ className: "pcw-info-card__btn",
1041
+ onClick: () => c(r.message),
1042
+ children: r.label
1043
+ },
1044
+ r.label
1045
+ )) })
1046
+ ] });
1047
+ }
1048
+ /**
1049
+ * @license
1050
+ * Copyright 2025 Amodal Labs, Inc.
1051
+ * SPDX-License-Identifier: MIT
1052
+ */
1053
+ const Re = {
1054
+ up: "↑",
1055
+ down: "↓",
1056
+ flat: "→"
1057
+ };
1058
+ function He({ data: s }) {
1059
+ const c = s, t = c.label ?? "Metric", a = c.value ?? "—";
1060
+ return /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-metric", "data-testid": "metric", children: [
1061
+ /* @__PURE__ */ e("div", { className: "pcw-metric__label", children: t }),
1062
+ /* @__PURE__ */ n("div", { className: "pcw-metric__value-row", children: [
1063
+ /* @__PURE__ */ e("span", { className: "pcw-metric__value", children: String(a) }),
1064
+ c.unit && /* @__PURE__ */ e("span", { className: "pcw-metric__unit", children: c.unit }),
1065
+ c.trend && /* @__PURE__ */ e("span", { className: `pcw-metric__trend pcw-metric__trend--${c.trend}`, children: Re[c.trend] ?? "" })
1066
+ ] }),
1067
+ c.description && /* @__PURE__ */ e("div", { className: "pcw-metric__description", children: c.description }),
1068
+ c.previous_value != null && /* @__PURE__ */ n("div", { className: "pcw-metric__previous", children: [
1069
+ "Previous: ",
1070
+ String(c.previous_value),
1071
+ c.unit ? ` ${c.unit}` : ""
1072
+ ] })
1073
+ ] });
1074
+ }
1075
+ const je = {
1076
+ "entity-card": Ne,
1077
+ "entity-list": ye,
1078
+ "scope-map": Se,
1079
+ "alert-card": Ce,
1080
+ timeline: $e,
1081
+ comparison: Te,
1082
+ "data-table": Ee,
1083
+ "score-breakdown": Ae,
1084
+ "status-board": Le,
1085
+ "credential-input": Be,
1086
+ "document-preview": Me,
1087
+ "info-card": Oe,
1088
+ metric: He
1089
+ };
1090
+ class ze extends re {
1091
+ constructor(c) {
1092
+ super(c), this.state = { error: null };
1093
+ }
1094
+ static getDerivedStateFromError(c) {
1095
+ return { error: c };
1096
+ }
1097
+ render() {
1098
+ return this.state.error ? /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-widget-card--generic", children: [
1099
+ /* @__PURE__ */ n("div", { className: "pcw-widget-card__header", children: [
1100
+ /* @__PURE__ */ e("span", { className: "pcw-widget-card__type", children: this.props.widgetType }),
1101
+ /* @__PURE__ */ e("span", { style: { color: "var(--pcw-error, #ef4444)", fontSize: "12px", marginLeft: "8px" }, children: "render error" })
1102
+ ] }),
1103
+ /* @__PURE__ */ e("pre", { className: "pcw-widget-card__json", children: JSON.stringify(this.props.data, null, 2) })
1104
+ ] }) : this.props.children;
1105
+ }
1106
+ }
1107
+ function Ie({
1108
+ widgetType: s,
1109
+ data: c,
1110
+ sendMessage: t,
1111
+ customWidgets: a,
1112
+ onInteraction: i
1113
+ }) {
1114
+ const l = (a == null ? void 0 : a[s]) ?? je[s];
1115
+ return l ? /* @__PURE__ */ e(ze, { widgetType: s, data: c, children: /* @__PURE__ */ e(l, { data: c, sendMessage: t, onInteraction: i }) }) : /* @__PURE__ */ n("div", { className: "pcw-widget-card pcw-widget-card--generic", children: [
1116
+ /* @__PURE__ */ e("div", { className: "pcw-widget-card__header", children: /* @__PURE__ */ e("span", { className: "pcw-widget-card__type", children: s }) }),
1117
+ /* @__PURE__ */ e("pre", { className: "pcw-widget-card__json", children: JSON.stringify(c, null, 2) })
1118
+ ] });
1119
+ }
1120
+ function Pe({
1121
+ message: s,
1122
+ sendMessage: c,
1123
+ customWidgets: t,
1124
+ onInteraction: a,
1125
+ onAskUserSubmit: i
1126
+ }) {
1127
+ const l = s.contentBlocks && s.contentBlocks.length > 0, d = s.toolCalls.length > 0 || s.skillActivations.length > 0 || s.kbProposals.length > 0;
1128
+ if (l) {
1129
+ const r = s.kbProposals.length > 0;
1130
+ return /* @__PURE__ */ n("div", { className: "pcw-bubble pcw-bubble--assistant", children: [
1131
+ s.skillActivations.map((p) => /* @__PURE__ */ e(J, { skill: p }, p)),
1132
+ s.contentBlocks.map((p, o) => {
1133
+ switch (p.type) {
1134
+ case "text":
1135
+ return p.text.length > 0 ? /* @__PURE__ */ e(x, { text: p.text, className: "pcw-bubble__text" }, `text-${String(o)}`) : null;
1136
+ case "widget":
1137
+ return /* @__PURE__ */ e(
1138
+ Ie,
1139
+ {
1140
+ widgetType: p.widgetType,
1141
+ data: p.data,
1142
+ sendMessage: c ?? (() => {
1143
+ }),
1144
+ customWidgets: t,
1145
+ onInteraction: a
1146
+ },
1147
+ `widget-${String(o)}`
1148
+ );
1149
+ case "tool_calls":
1150
+ return /* @__PURE__ */ e("div", { className: "pcw-bubble__extras", children: p.calls.map((u) => /* @__PURE__ */ e(K, { toolCall: u }, u.toolId)) }, `tools-${String(o)}`);
1151
+ case "ask_user":
1152
+ return /* @__PURE__ */ e(
1153
+ ve,
1154
+ {
1155
+ block: p,
1156
+ onSubmit: i ?? (() => {
1157
+ })
1158
+ },
1159
+ `ask-${p.askId}`
1160
+ );
1161
+ default:
1162
+ return null;
1163
+ }
1164
+ }),
1165
+ r && /* @__PURE__ */ e("div", { className: "pcw-bubble__extras", children: s.kbProposals.map((p, o) => /* @__PURE__ */ e(Z, { proposal: p }, `${p.title}-${String(o)}`)) })
1166
+ ] });
1167
+ }
1168
+ return /* @__PURE__ */ n("div", { className: "pcw-bubble pcw-bubble--assistant", children: [
1169
+ s.skillActivations.map((r) => /* @__PURE__ */ e(J, { skill: r }, r)),
1170
+ s.text.length > 0 && /* @__PURE__ */ e(x, { className: "pcw-bubble__text", text: s.text }),
1171
+ d && /* @__PURE__ */ n("div", { className: "pcw-bubble__extras", children: [
1172
+ s.toolCalls.map((r) => /* @__PURE__ */ e(K, { toolCall: r }, r.toolId)),
1173
+ s.kbProposals.map((r, p) => /* @__PURE__ */ e(Z, { proposal: r }, `${r.title}-${String(p)}`))
1174
+ ] })
1175
+ ] });
1176
+ }
1177
+ function G({ messages: s, isStreaming: c, sendMessage: t, customWidgets: a, onInteraction: i, onAskUserSubmit: l, emptyStateText: d }) {
1178
+ const r = A(null), p = A(!0);
1179
+ return M(() => {
1180
+ const o = r.current;
1181
+ if (!o) return;
1182
+ const u = () => {
1183
+ p.current = o.scrollHeight - o.scrollTop - o.clientHeight < 100;
1184
+ };
1185
+ return o.addEventListener("scroll", u), () => o.removeEventListener("scroll", u);
1186
+ }, []), M(() => {
1187
+ p.current && r.current && (r.current.scrollTop = r.current.scrollHeight);
1188
+ }, [s, c]), s.length === 0 ? /* @__PURE__ */ e("div", { className: "pcw-messages--empty", children: /* @__PURE__ */ e("p", { children: d ?? "Send a message to start a conversation." }) }) : /* @__PURE__ */ n("div", { ref: r, className: "pcw-messages", children: [
1189
+ s.map((o) => {
1190
+ switch (o.type) {
1191
+ case "user":
1192
+ return /* @__PURE__ */ e("div", { className: "pcw-bubble pcw-bubble--user", children: /* @__PURE__ */ e("p", { className: "pcw-bubble__text", children: o.text }) }, o.id);
1193
+ case "assistant_text":
1194
+ return /* @__PURE__ */ e(
1195
+ Pe,
1196
+ {
1197
+ message: o,
1198
+ sendMessage: t,
1199
+ customWidgets: a,
1200
+ onInteraction: i,
1201
+ onAskUserSubmit: l
1202
+ },
1203
+ o.id
1204
+ );
1205
+ case "error":
1206
+ return /* @__PURE__ */ e("div", { className: "pcw-error", children: o.message }, o.id);
1207
+ default:
1208
+ return null;
1209
+ }
1210
+ }),
1211
+ c && /* @__PURE__ */ e(ge, {})
1212
+ ] });
1213
+ }
1214
+ function We() {
1215
+ return /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", children: [
1216
+ /* @__PURE__ */ e("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
1217
+ /* @__PURE__ */ e("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
1218
+ ] });
1219
+ }
1220
+ function Fe() {
1221
+ return /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ e("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) });
1222
+ }
1223
+ function X({ onSend: s, onStop: c, disabled: t, isStreaming: a, placeholder: i }) {
1224
+ const [l, d] = w(""), r = A(null), p = b(() => {
1225
+ const h = l.trim();
1226
+ h.length !== 0 && (s(h), d(""), r.current && (r.current.style.height = "auto"));
1227
+ }, [l, s]), o = b(
1228
+ (h) => {
1229
+ h.key === "Enter" && !h.shiftKey && (h.preventDefault(), p());
1230
+ },
1231
+ [p]
1232
+ ), u = b(() => {
1233
+ const h = r.current;
1234
+ h && (h.style.height = "auto", h.style.height = `${String(Math.min(h.scrollHeight, 120))}px`);
1235
+ }, []);
1236
+ return /* @__PURE__ */ n("div", { className: "pcw-input", children: [
1237
+ /* @__PURE__ */ e(
1238
+ "textarea",
1239
+ {
1240
+ ref: r,
1241
+ className: "pcw-input__textarea",
1242
+ value: l,
1243
+ onChange: (h) => d(h.target.value),
1244
+ onKeyDown: o,
1245
+ onInput: u,
1246
+ placeholder: i,
1247
+ disabled: t && !a,
1248
+ rows: 1
1249
+ }
1250
+ ),
1251
+ a ? /* @__PURE__ */ e(
1252
+ "button",
1253
+ {
1254
+ type: "button",
1255
+ className: "pcw-input__send pcw-input__stop",
1256
+ onClick: c,
1257
+ "aria-label": "Stop generating",
1258
+ children: /* @__PURE__ */ e(Fe, {})
1259
+ }
1260
+ ) : /* @__PURE__ */ e(
1261
+ "button",
1262
+ {
1263
+ type: "button",
1264
+ className: "pcw-input__send",
1265
+ onClick: p,
1266
+ disabled: t || l.trim().length === 0,
1267
+ "aria-label": "Send message",
1268
+ children: /* @__PURE__ */ e(We, {})
1269
+ }
1270
+ )
1271
+ ] });
1272
+ }
1273
+ function Ve({ tags: s, onSave: c }) {
1274
+ const [t, a] = w(!1), [i, l] = w(""), d = b(
1275
+ (o) => {
1276
+ c(s.filter((u) => u !== o));
1277
+ },
1278
+ [s, c]
1279
+ ), r = b(() => {
1280
+ const o = i.trim();
1281
+ o && !s.includes(o) && c([...s, o]), l(""), a(!1);
1282
+ }, [i, s, c]), p = b(
1283
+ (o) => {
1284
+ o.key === "Enter" ? (o.preventDefault(), r()) : o.key === "Escape" && (l(""), a(!1));
1285
+ },
1286
+ [r]
1287
+ );
1288
+ return /* @__PURE__ */ n("div", { className: "pcw-tag-editor", children: [
1289
+ s.map((o) => /* @__PURE__ */ n("span", { className: "pcw-tag-badge", children: [
1290
+ o,
1291
+ /* @__PURE__ */ e(
1292
+ "button",
1293
+ {
1294
+ type: "button",
1295
+ className: "pcw-tag-remove",
1296
+ onClick: () => d(o),
1297
+ "aria-label": `Remove tag ${o}`,
1298
+ children: "x"
1299
+ }
1300
+ )
1301
+ ] }, o)),
1302
+ t ? /* @__PURE__ */ e(
1303
+ "input",
1304
+ {
1305
+ className: "pcw-tag-input",
1306
+ type: "text",
1307
+ value: i,
1308
+ onChange: (o) => l(o.target.value),
1309
+ onKeyDown: p,
1310
+ onBlur: r,
1311
+ placeholder: "Add tag...",
1312
+ autoFocus: !0
1313
+ }
1314
+ ) : /* @__PURE__ */ e(
1315
+ "button",
1316
+ {
1317
+ type: "button",
1318
+ className: "pcw-tag-add-btn",
1319
+ onClick: () => a(!0),
1320
+ "aria-label": "Add tag",
1321
+ children: "+"
1322
+ }
1323
+ )
1324
+ ] });
1325
+ }
1326
+ function Ue(s) {
1327
+ const c = Date.now(), t = new Date(s).getTime(), a = c - t, i = Math.floor(a / 6e4);
1328
+ if (i < 1) return "just now";
1329
+ if (i < 60) return `${String(i)}m ago`;
1330
+ const l = Math.floor(i / 60);
1331
+ if (l < 24) return `${String(l)}h ago`;
1332
+ const d = Math.floor(l / 24);
1333
+ return `${String(d)}d ago`;
1334
+ }
1335
+ function q({
1336
+ sessions: s,
1337
+ isLoading: c,
1338
+ allTags: t,
1339
+ onSelectSession: a,
1340
+ onNewChat: i,
1341
+ onClose: l,
1342
+ onUpdateTags: d
1343
+ }) {
1344
+ const [r, p] = w([]), [o, u] = w(null), h = b((m) => {
1345
+ p(
1346
+ (g) => g.includes(m) ? g.filter((v) => v !== m) : [...g, m]
1347
+ );
1348
+ }, []), _ = r.length > 0 ? s.filter((m) => r.some((g) => m.tags.includes(g))) : s;
1349
+ return /* @__PURE__ */ n("div", { className: "pcw-history-drawer", "data-testid": "session-history", children: [
1350
+ /* @__PURE__ */ n("div", { className: "pcw-history-header", children: [
1351
+ /* @__PURE__ */ e("h3", { className: "pcw-history-title", children: "Session History" }),
1352
+ /* @__PURE__ */ e(
1353
+ "button",
1354
+ {
1355
+ type: "button",
1356
+ className: "pcw-history-close",
1357
+ onClick: l,
1358
+ "aria-label": "Close history",
1359
+ children: /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, width: 16, height: 16, children: [
1360
+ /* @__PURE__ */ e("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1361
+ /* @__PURE__ */ e("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1362
+ ] })
1363
+ }
1364
+ )
1365
+ ] }),
1366
+ /* @__PURE__ */ e(
1367
+ "button",
1368
+ {
1369
+ type: "button",
1370
+ className: "pcw-history-new-chat",
1371
+ onClick: i,
1372
+ children: "+ New Chat"
1373
+ }
1374
+ ),
1375
+ t.length > 0 && /* @__PURE__ */ e("div", { className: "pcw-history-filters", children: t.map((m) => /* @__PURE__ */ e(
1376
+ "button",
1377
+ {
1378
+ type: "button",
1379
+ className: `pcw-filter-chip ${r.includes(m) ? "pcw-filter-chip--active" : ""}`,
1380
+ onClick: () => h(m),
1381
+ children: m
1382
+ },
1383
+ m
1384
+ )) }),
1385
+ /* @__PURE__ */ n("div", { className: "pcw-history-list", children: [
1386
+ c && /* @__PURE__ */ e("div", { className: "pcw-history-loading", children: "Loading sessions..." }),
1387
+ !c && _.length === 0 && /* @__PURE__ */ e("div", { className: "pcw-history-empty", children: "No past sessions" }),
1388
+ _.map((m) => /* @__PURE__ */ n(
1389
+ "div",
1390
+ {
1391
+ className: "pcw-history-item",
1392
+ children: [
1393
+ /* @__PURE__ */ n(
1394
+ "button",
1395
+ {
1396
+ type: "button",
1397
+ className: "pcw-history-item-content",
1398
+ onClick: () => a(m.id),
1399
+ children: [
1400
+ /* @__PURE__ */ e("div", { className: "pcw-history-item-title", children: m.title ?? `Session ${m.id.slice(0, 8)}` }),
1401
+ /* @__PURE__ */ n("div", { className: "pcw-history-item-meta", children: [
1402
+ /* @__PURE__ */ e("span", { className: "pcw-history-item-time", children: Ue(m.created_at) }),
1403
+ /* @__PURE__ */ n("span", { className: "pcw-history-item-count", children: [
1404
+ String(m.message_count),
1405
+ " msg",
1406
+ m.message_count !== 1 ? "s" : ""
1407
+ ] })
1408
+ ] })
1409
+ ]
1410
+ }
1411
+ ),
1412
+ /* @__PURE__ */ e("div", { className: "pcw-history-item-tags", children: o === m.id ? /* @__PURE__ */ e(
1413
+ Ve,
1414
+ {
1415
+ tags: m.tags,
1416
+ onSave: (g) => {
1417
+ d(m.id, g), u(null);
1418
+ }
1419
+ }
1420
+ ) : /* @__PURE__ */ n("div", { className: "pcw-history-item-tag-list", children: [
1421
+ m.tags.map((g) => /* @__PURE__ */ e("span", { className: "pcw-tag-badge pcw-tag-badge--small", children: g }, g)),
1422
+ /* @__PURE__ */ e(
1423
+ "button",
1424
+ {
1425
+ type: "button",
1426
+ className: "pcw-tag-edit-btn",
1427
+ onClick: (g) => {
1428
+ g.stopPropagation(), u(m.id);
1429
+ },
1430
+ "aria-label": "Edit tags",
1431
+ children: /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, width: 12, height: 12, children: [
1432
+ /* @__PURE__ */ e("path", { d: "M20.59 13.41l-7.17 7.17a2 2 0 01-2.83 0L2 12V2h10l8.59 8.59a2 2 0 010 2.82z" }),
1433
+ /* @__PURE__ */ e("line", { x1: "7", y1: "7", x2: "7.01", y2: "7" })
1434
+ ] })
1435
+ }
1436
+ )
1437
+ ] }) })
1438
+ ]
1439
+ },
1440
+ m.id
1441
+ ))
1442
+ ] })
1443
+ ] });
1444
+ }
1445
+ function Ke() {
1446
+ return /* @__PURE__ */ e("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ e("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
1447
+ }
1448
+ function Ze() {
1449
+ return /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", children: [
1450
+ /* @__PURE__ */ e("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1451
+ /* @__PURE__ */ e("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1452
+ ] });
1453
+ }
1454
+ function Xe({
1455
+ serverUrl: s,
1456
+ user: c,
1457
+ getToken: t,
1458
+ theme: a,
1459
+ position: i = "floating",
1460
+ defaultOpen: l = !1,
1461
+ onToolCall: d,
1462
+ onKBProposal: r,
1463
+ onEvent: p,
1464
+ entityExtractors: o,
1465
+ widgets: u,
1466
+ historyEnabled: h = !1,
1467
+ showInput: _ = !0,
1468
+ sessionType: m,
1469
+ deployId: g,
1470
+ initialMessage: v,
1471
+ resumeSessionId: te,
1472
+ onStreamEnd: se,
1473
+ onSessionCreated: ce
1474
+ }) {
1475
+ const [ae, R] = w(l), [L, f] = w(!1), C = A(null), k = ie(a), { messages: H, send: B, stop: j, isStreaming: S, error: $, reset: T, eventBus: z, submitAskUserResponse: I, loadSession: P, isHistorical: E } = le({
1476
+ serverUrl: s,
1477
+ user: c,
1478
+ getToken: t,
1479
+ onToolCall: d,
1480
+ onKBProposal: r,
1481
+ onEvent: p,
1482
+ entityExtractors: o,
1483
+ sessionType: m,
1484
+ deployId: g,
1485
+ initialMessage: v,
1486
+ resumeSessionId: te,
1487
+ onStreamEnd: se,
1488
+ onSessionCreated: ce
1489
+ }), N = de({
1490
+ serverUrl: s,
1491
+ getToken: t,
1492
+ enabled: h && L
1493
+ }), W = b(
1494
+ (y) => {
1495
+ z.emitInteraction(y), p == null || p(y);
1496
+ },
1497
+ [z, p]
1498
+ ), F = b(
1499
+ (y) => {
1500
+ P(y), f(!1);
1501
+ },
1502
+ [P]
1503
+ ), V = b(() => {
1504
+ T(), f(!1);
1505
+ }, [T]);
1506
+ M(() => {
1507
+ C.current && a && oe(C.current, a);
1508
+ }, [a]);
1509
+ const U = `pcw-widget pcw-widget--${i}`;
1510
+ return i === "inline" ? /* @__PURE__ */ n("div", { ref: C, className: U, "data-testid": "chat-widget", children: [
1511
+ /* @__PURE__ */ e(
1512
+ ee,
1513
+ {
1514
+ title: k.headerText,
1515
+ onReset: T,
1516
+ historyEnabled: h,
1517
+ onToggleHistory: () => f((y) => !y),
1518
+ isHistorical: E
1519
+ }
1520
+ ),
1521
+ L && /* @__PURE__ */ e(
1522
+ q,
1523
+ {
1524
+ sessions: N.sessions,
1525
+ isLoading: N.isLoading,
1526
+ allTags: N.allTags,
1527
+ onSelectSession: F,
1528
+ onNewChat: V,
1529
+ onClose: () => f(!1),
1530
+ onUpdateTags: N.updateTags
1531
+ }
1532
+ ),
1533
+ /* @__PURE__ */ e(G, { messages: H, isStreaming: S, sendMessage: B, customWidgets: u, onInteraction: W, onAskUserSubmit: I, emptyStateText: k.emptyStateText }),
1534
+ $ && /* @__PURE__ */ e("div", { className: "pcw-error", children: $ }),
1535
+ _ && /* @__PURE__ */ e(
1536
+ X,
1537
+ {
1538
+ onSend: B,
1539
+ onStop: j,
1540
+ disabled: S,
1541
+ isStreaming: S,
1542
+ placeholder: E ? "Send a message to start a new chat..." : k.placeholder
1543
+ }
1544
+ )
1545
+ ] }) : ae ? /* @__PURE__ */ n("div", { ref: C, className: U, "data-testid": "chat-widget", children: [
1546
+ /* @__PURE__ */ e(
1547
+ ee,
1548
+ {
1549
+ title: k.headerText,
1550
+ onClose: () => R(!1),
1551
+ onReset: T,
1552
+ showClose: !0,
1553
+ historyEnabled: h,
1554
+ onToggleHistory: () => f((y) => !y),
1555
+ isHistorical: E
1556
+ }
1557
+ ),
1558
+ L && /* @__PURE__ */ e(
1559
+ q,
1560
+ {
1561
+ sessions: N.sessions,
1562
+ isLoading: N.isLoading,
1563
+ allTags: N.allTags,
1564
+ onSelectSession: F,
1565
+ onNewChat: V,
1566
+ onClose: () => f(!1),
1567
+ onUpdateTags: N.updateTags
1568
+ }
1569
+ ),
1570
+ /* @__PURE__ */ e(G, { messages: H, isStreaming: S, onInteraction: W, onAskUserSubmit: I, emptyStateText: k.emptyStateText }),
1571
+ $ && /* @__PURE__ */ e("div", { className: "pcw-error", children: $ }),
1572
+ _ && /* @__PURE__ */ e(
1573
+ X,
1574
+ {
1575
+ onSend: B,
1576
+ onStop: j,
1577
+ disabled: S,
1578
+ isStreaming: S,
1579
+ placeholder: E ? "Send a message to start a new chat..." : k.placeholder
1580
+ }
1581
+ )
1582
+ ] }) : i === "floating" ? /* @__PURE__ */ e(
1583
+ "button",
1584
+ {
1585
+ type: "button",
1586
+ className: "pcw-toggle",
1587
+ onClick: () => R(!0),
1588
+ "aria-label": "Open chat",
1589
+ children: /* @__PURE__ */ e(Ke, {})
1590
+ }
1591
+ ) : null;
1592
+ }
1593
+ function Je() {
1594
+ return /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", width: 16, height: 16, children: [
1595
+ /* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "10" }),
1596
+ /* @__PURE__ */ e("polyline", { points: "12 6 12 12 16 14" })
1597
+ ] });
1598
+ }
1599
+ function ee({ title: s, onClose: c, onReset: t, showClose: a = !1, historyEnabled: i, onToggleHistory: l, isHistorical: d }) {
1600
+ return /* @__PURE__ */ n("div", { className: "pcw-header", children: [
1601
+ /* @__PURE__ */ n("div", { style: { display: "flex", gap: "4px", alignItems: "center" }, children: [
1602
+ i && l && /* @__PURE__ */ e(
1603
+ "button",
1604
+ {
1605
+ type: "button",
1606
+ className: "pcw-header__close",
1607
+ onClick: l,
1608
+ "aria-label": "Session history",
1609
+ title: "Session history",
1610
+ children: /* @__PURE__ */ e(Je, {})
1611
+ }
1612
+ ),
1613
+ /* @__PURE__ */ n("h3", { className: "pcw-header__title", children: [
1614
+ s,
1615
+ d && /* @__PURE__ */ e("span", { className: "pcw-header__badge", children: "History" })
1616
+ ] })
1617
+ ] }),
1618
+ /* @__PURE__ */ n("div", { style: { display: "flex", gap: "4px", alignItems: "center" }, children: [
1619
+ t && /* @__PURE__ */ e(
1620
+ "button",
1621
+ {
1622
+ type: "button",
1623
+ className: "pcw-header__close",
1624
+ onClick: t,
1625
+ "aria-label": "New conversation",
1626
+ title: "New conversation",
1627
+ children: "↻"
1628
+ }
1629
+ ),
1630
+ a && c && /* @__PURE__ */ e(
1631
+ "button",
1632
+ {
1633
+ type: "button",
1634
+ className: "pcw-header__close",
1635
+ onClick: c,
1636
+ "aria-label": "Close chat",
1637
+ children: /* @__PURE__ */ e(Ze, {})
1638
+ }
1639
+ )
1640
+ ] })
1641
+ ] });
1642
+ }
1643
+ export {
1644
+ ve as AskUserCard,
1645
+ Xe as ChatWidget,
1646
+ x as FormattedText,
1647
+ X as InputBar,
1648
+ Z as KBProposalCard,
1649
+ G as MessageList,
1650
+ q as SessionHistory,
1651
+ J as SkillPill,
1652
+ ge as StreamingIndicator,
1653
+ Ve as TagEditor,
1654
+ K as ToolCallCard,
1655
+ at as WidgetEventBus,
1656
+ Ie as WidgetRenderer,
1657
+ oe as applyTheme,
1658
+ nt as createSession,
1659
+ rt as defaultEntityExtractor,
1660
+ tt as defaultTheme,
1661
+ it as getSessionHistory,
1662
+ lt as listSessions,
1663
+ ie as mergeTheme,
1664
+ le as useChat,
1665
+ de as useSessionHistory,
1666
+ st as useWidgetEvents
1667
+ };
1668
+ //# sourceMappingURL=widget.js.map