@runtypelabs/persona 3.17.0 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -0
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-HPZY7oAI.d.cts → types-cwY5HaFD.d.cts} +25 -0
- package/dist/animations/{types-HPZY7oAI.d.ts → types-cwY5HaFD.d.ts} +25 -0
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/index.cjs +47 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +300 -1
- package/dist/index.d.ts +300 -1
- package/dist/index.global.js +75 -75
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/dist/theme-editor.cjs +1432 -159
- package/dist/theme-editor.d.cts +218 -0
- package/dist/theme-editor.d.ts +218 -0
- package/dist/theme-editor.js +1432 -159
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +14 -0
- package/dist/theme-reference.d.ts +14 -0
- package/dist/widget.css +432 -0
- package/package.json +1 -1
- package/src/client.test.ts +134 -0
- package/src/client.ts +71 -0
- package/src/components/ask-user-question-bubble.test.ts +583 -0
- package/src/components/ask-user-question-bubble.ts +924 -0
- package/src/components/messages.ts +33 -1
- package/src/components/panel.ts +41 -4
- package/src/defaults.ts +21 -0
- package/src/index.ts +16 -1
- package/src/plugins/types.ts +57 -0
- package/src/session.test.ts +183 -0
- package/src/session.ts +242 -3
- package/src/styles/widget.css +432 -0
- package/src/types/theme.ts +15 -0
- package/src/types.ts +150 -0
- package/src/ui.ask-user-question-plugin.test.ts +649 -0
- package/src/ui.ts +631 -5
- package/src/utils/storage.ts +10 -2
- package/src/utils/theme.test.ts +36 -0
- package/src/utils/tokens.ts +23 -0
package/dist/theme-editor.cjs
CHANGED
|
@@ -255,6 +255,13 @@ var DEFAULT_WIDGET_CONFIG = {
|
|
|
255
255
|
placeholder: "none",
|
|
256
256
|
speed: 120,
|
|
257
257
|
duration: 1800
|
|
258
|
+
},
|
|
259
|
+
askUserQuestion: {
|
|
260
|
+
enabled: true,
|
|
261
|
+
slideInMs: 180,
|
|
262
|
+
freeTextLabel: "Other\u2026",
|
|
263
|
+
freeTextPlaceholder: "Type your answer\u2026",
|
|
264
|
+
submitLabel: "Send"
|
|
258
265
|
}
|
|
259
266
|
},
|
|
260
267
|
suggestionChips: [
|
|
@@ -357,13 +364,15 @@ function mergeWithDefaults(config) {
|
|
|
357
364
|
...config.voiceRecognition
|
|
358
365
|
},
|
|
359
366
|
features: (() => {
|
|
360
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
367
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
361
368
|
const da = (_a2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _a2.artifacts;
|
|
362
369
|
const ca = (_b2 = config.features) == null ? void 0 : _b2.artifacts;
|
|
363
370
|
const dsb = (_c2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _c2.scrollToBottom;
|
|
364
371
|
const csb = (_d2 = config.features) == null ? void 0 : _d2.scrollToBottom;
|
|
365
372
|
const dsa = (_e2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _e2.streamAnimation;
|
|
366
373
|
const csa = (_f2 = config.features) == null ? void 0 : _f2.streamAnimation;
|
|
374
|
+
const dau = (_g2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _g2.askUserQuestion;
|
|
375
|
+
const cau = (_h2 = config.features) == null ? void 0 : _h2.askUserQuestion;
|
|
367
376
|
const mergedArtifacts = da === void 0 && ca === void 0 ? void 0 : {
|
|
368
377
|
...da,
|
|
369
378
|
...ca,
|
|
@@ -380,12 +389,21 @@ function mergeWithDefaults(config) {
|
|
|
380
389
|
...dsa,
|
|
381
390
|
...csa
|
|
382
391
|
};
|
|
392
|
+
const mergedAskUserQuestion = dau === void 0 && cau === void 0 ? void 0 : {
|
|
393
|
+
...dau,
|
|
394
|
+
...cau,
|
|
395
|
+
styles: {
|
|
396
|
+
...dau == null ? void 0 : dau.styles,
|
|
397
|
+
...cau == null ? void 0 : cau.styles
|
|
398
|
+
}
|
|
399
|
+
};
|
|
383
400
|
return {
|
|
384
401
|
...DEFAULT_WIDGET_CONFIG.features,
|
|
385
402
|
...config.features,
|
|
386
403
|
...mergedScrollToBottom !== void 0 ? { scrollToBottom: mergedScrollToBottom } : {},
|
|
387
404
|
...mergedArtifacts !== void 0 ? { artifacts: mergedArtifacts } : {},
|
|
388
|
-
...mergedStreamAnimation !== void 0 ? { streamAnimation: mergedStreamAnimation } : {}
|
|
405
|
+
...mergedStreamAnimation !== void 0 ? { streamAnimation: mergedStreamAnimation } : {},
|
|
406
|
+
...mergedAskUserQuestion !== void 0 ? { askUserQuestion: mergedAskUserQuestion } : {}
|
|
389
407
|
};
|
|
390
408
|
})(),
|
|
391
409
|
suggestionChips: (_e = config.suggestionChips) != null ? _e : DEFAULT_WIDGET_CONFIG.suggestionChips,
|
|
@@ -736,6 +754,14 @@ var DEFAULT_COMPONENTS = {
|
|
|
736
754
|
},
|
|
737
755
|
border: "semantic.colors.border"
|
|
738
756
|
},
|
|
757
|
+
introCard: {
|
|
758
|
+
// Defaults preserve the legacy `persona-shadow-sm` look exactly so existing
|
|
759
|
+
// pages render unchanged when no token is set.
|
|
760
|
+
background: "semantic.colors.surface",
|
|
761
|
+
borderRadius: "palette.radius.2xl",
|
|
762
|
+
padding: "semantic.spacing.lg",
|
|
763
|
+
shadow: "0 5px 15px rgba(15, 23, 42, 0.08)"
|
|
764
|
+
},
|
|
739
765
|
toolBubble: {
|
|
740
766
|
shadow: "palette.shadows.sm"
|
|
741
767
|
},
|
|
@@ -1012,7 +1038,7 @@ function createTheme(userConfig, options = {}) {
|
|
|
1012
1038
|
return theme;
|
|
1013
1039
|
}
|
|
1014
1040
|
function themeToCssVariables(theme) {
|
|
1015
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb;
|
|
1041
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb;
|
|
1016
1042
|
const resolved = resolveTokens(theme);
|
|
1017
1043
|
const cssVars = {};
|
|
1018
1044
|
for (const [path, token] of Object.entries(resolved)) {
|
|
@@ -1076,31 +1102,36 @@ function themeToCssVariables(theme) {
|
|
|
1076
1102
|
const headerTokens = (_ea = theme.components) == null ? void 0 : _ea.header;
|
|
1077
1103
|
if (headerTokens == null ? void 0 : headerTokens.shadow) cssVars["--persona-header-shadow"] = headerTokens.shadow;
|
|
1078
1104
|
if (headerTokens == null ? void 0 : headerTokens.borderBottom) cssVars["--persona-header-border-bottom"] = headerTokens.borderBottom;
|
|
1079
|
-
|
|
1080
|
-
cssVars["--persona-
|
|
1081
|
-
cssVars["--persona-
|
|
1082
|
-
cssVars["--persona-
|
|
1083
|
-
cssVars["--persona-
|
|
1084
|
-
cssVars["--persona-
|
|
1085
|
-
cssVars["--persona-
|
|
1086
|
-
cssVars["--persona-message-
|
|
1087
|
-
cssVars["--persona-message-
|
|
1088
|
-
cssVars["--persona-
|
|
1089
|
-
cssVars["--persona-
|
|
1090
|
-
cssVars["--persona-
|
|
1091
|
-
cssVars["--persona-
|
|
1092
|
-
cssVars["--persona-
|
|
1093
|
-
cssVars["--persona-scroll-to-bottom-
|
|
1094
|
-
cssVars["--persona-scroll-to-bottom-
|
|
1095
|
-
cssVars["--persona-scroll-to-bottom-
|
|
1096
|
-
cssVars["--persona-scroll-to-bottom-
|
|
1097
|
-
cssVars["--persona-scroll-to-bottom-
|
|
1098
|
-
cssVars["--persona-
|
|
1099
|
-
cssVars["--persona-
|
|
1100
|
-
cssVars["--persona-
|
|
1101
|
-
cssVars["--persona-
|
|
1102
|
-
cssVars["--persona-
|
|
1103
|
-
cssVars["--persona-
|
|
1105
|
+
const introCardTokens = (_fa = theme.components) == null ? void 0 : _fa.introCard;
|
|
1106
|
+
cssVars["--persona-intro-card-bg"] = (_ga = cssVars["--persona-components-introCard-background"]) != null ? _ga : cssVars["--persona-surface"];
|
|
1107
|
+
cssVars["--persona-intro-card-radius"] = (_ha = cssVars["--persona-components-introCard-borderRadius"]) != null ? _ha : "1rem";
|
|
1108
|
+
cssVars["--persona-intro-card-padding"] = (_ia = cssVars["--persona-components-introCard-padding"]) != null ? _ia : "1.5rem";
|
|
1109
|
+
cssVars["--persona-intro-card-shadow"] = (_ka = (_ja = introCardTokens == null ? void 0 : introCardTokens.shadow) != null ? _ja : cssVars["--persona-components-introCard-shadow"]) != null ? _ka : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1110
|
+
cssVars["--persona-input-background"] = (_la = cssVars["--persona-components-input-background"]) != null ? _la : cssVars["--persona-surface"];
|
|
1111
|
+
cssVars["--persona-input-placeholder"] = (_ma = cssVars["--persona-components-input-placeholder"]) != null ? _ma : cssVars["--persona-text-muted"];
|
|
1112
|
+
cssVars["--persona-message-user-bg"] = (_na = cssVars["--persona-components-message-user-background"]) != null ? _na : cssVars["--persona-accent"];
|
|
1113
|
+
cssVars["--persona-message-user-text"] = (_oa = cssVars["--persona-components-message-user-text"]) != null ? _oa : cssVars["--persona-text-inverse"];
|
|
1114
|
+
cssVars["--persona-message-user-shadow"] = (_pa = cssVars["--persona-components-message-user-shadow"]) != null ? _pa : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1115
|
+
cssVars["--persona-message-assistant-bg"] = (_qa = cssVars["--persona-components-message-assistant-background"]) != null ? _qa : cssVars["--persona-surface"];
|
|
1116
|
+
cssVars["--persona-message-assistant-text"] = (_ra = cssVars["--persona-components-message-assistant-text"]) != null ? _ra : cssVars["--persona-text"];
|
|
1117
|
+
cssVars["--persona-message-assistant-border"] = (_sa = cssVars["--persona-components-message-assistant-border"]) != null ? _sa : cssVars["--persona-border"];
|
|
1118
|
+
cssVars["--persona-message-assistant-shadow"] = (_ta = cssVars["--persona-components-message-assistant-shadow"]) != null ? _ta : "0 1px 2px 0 rgb(0 0 0 / 0.05)";
|
|
1119
|
+
cssVars["--persona-scroll-to-bottom-bg"] = (_va = (_ua = cssVars["--persona-components-scrollToBottom-background"]) != null ? _ua : cssVars["--persona-button-primary-bg"]) != null ? _va : cssVars["--persona-accent"];
|
|
1120
|
+
cssVars["--persona-scroll-to-bottom-fg"] = (_xa = (_wa = cssVars["--persona-components-scrollToBottom-foreground"]) != null ? _wa : cssVars["--persona-button-primary-fg"]) != null ? _xa : cssVars["--persona-text-inverse"];
|
|
1121
|
+
cssVars["--persona-scroll-to-bottom-border"] = (_ya = cssVars["--persona-components-scrollToBottom-border"]) != null ? _ya : cssVars["--persona-primary"];
|
|
1122
|
+
cssVars["--persona-scroll-to-bottom-size"] = (_za = cssVars["--persona-components-scrollToBottom-size"]) != null ? _za : "40px";
|
|
1123
|
+
cssVars["--persona-scroll-to-bottom-radius"] = (_Ca = (_Ba = (_Aa = cssVars["--persona-components-scrollToBottom-borderRadius"]) != null ? _Aa : cssVars["--persona-button-radius"]) != null ? _Ba : cssVars["--persona-radius-full"]) != null ? _Ca : "9999px";
|
|
1124
|
+
cssVars["--persona-scroll-to-bottom-shadow"] = (_Ea = (_Da = cssVars["--persona-components-scrollToBottom-shadow"]) != null ? _Da : cssVars["--persona-palette-shadows-sm"]) != null ? _Ea : "0 1px 2px 0 rgb(0 0 0 / 0.05)";
|
|
1125
|
+
cssVars["--persona-scroll-to-bottom-padding"] = (_Fa = cssVars["--persona-components-scrollToBottom-padding"]) != null ? _Fa : "0.5rem 0.875rem";
|
|
1126
|
+
cssVars["--persona-scroll-to-bottom-gap"] = (_Ga = cssVars["--persona-components-scrollToBottom-gap"]) != null ? _Ga : "0.5rem";
|
|
1127
|
+
cssVars["--persona-scroll-to-bottom-font-size"] = (_Ia = (_Ha = cssVars["--persona-components-scrollToBottom-fontSize"]) != null ? _Ha : cssVars["--persona-palette-typography-fontSize-sm"]) != null ? _Ia : "0.875rem";
|
|
1128
|
+
cssVars["--persona-scroll-to-bottom-icon-size"] = (_Ja = cssVars["--persona-components-scrollToBottom-iconSize"]) != null ? _Ja : "14px";
|
|
1129
|
+
cssVars["--persona-tool-bubble-shadow"] = (_Ka = cssVars["--persona-components-toolBubble-shadow"]) != null ? _Ka : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1130
|
+
cssVars["--persona-reasoning-bubble-shadow"] = (_La = cssVars["--persona-components-reasoningBubble-shadow"]) != null ? _La : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1131
|
+
cssVars["--persona-composer-shadow"] = (_Ma = cssVars["--persona-components-composer-shadow"]) != null ? _Ma : "none";
|
|
1132
|
+
cssVars["--persona-md-inline-code-bg"] = (_Na = cssVars["--persona-components-markdown-inlineCode-background"]) != null ? _Na : cssVars["--persona-container"];
|
|
1133
|
+
cssVars["--persona-md-inline-code-color"] = (_Oa = cssVars["--persona-components-markdown-inlineCode-foreground"]) != null ? _Oa : cssVars["--persona-text"];
|
|
1134
|
+
cssVars["--persona-md-link-color"] = (_Qa = (_Pa = cssVars["--persona-components-markdown-link-foreground"]) != null ? _Pa : cssVars["--persona-accent"]) != null ? _Qa : "#0f0f0f";
|
|
1104
1135
|
const mdH1Size = cssVars["--persona-components-markdown-heading-h1-fontSize"];
|
|
1105
1136
|
if (mdH1Size) cssVars["--persona-md-h1-size"] = mdH1Size;
|
|
1106
1137
|
const mdH1Weight = cssVars["--persona-components-markdown-heading-h1-fontWeight"];
|
|
@@ -1113,19 +1144,19 @@ function themeToCssVariables(theme) {
|
|
|
1113
1144
|
if (mdProseFont && mdProseFont !== "inherit") {
|
|
1114
1145
|
cssVars["--persona-md-prose-font-family"] = mdProseFont;
|
|
1115
1146
|
}
|
|
1116
|
-
cssVars["--persona-md-code-block-bg"] = (
|
|
1117
|
-
cssVars["--persona-md-code-block-border-color"] = (
|
|
1118
|
-
cssVars["--persona-md-code-block-text-color"] = (
|
|
1119
|
-
cssVars["--persona-md-table-header-bg"] = (
|
|
1120
|
-
cssVars["--persona-md-table-border-color"] = (
|
|
1121
|
-
cssVars["--persona-md-hr-color"] = (
|
|
1122
|
-
cssVars["--persona-md-blockquote-border-color"] = (
|
|
1123
|
-
cssVars["--persona-md-blockquote-bg"] = (
|
|
1124
|
-
cssVars["--persona-md-blockquote-text-color"] = (
|
|
1125
|
-
cssVars["--cw-container"] = (
|
|
1126
|
-
cssVars["--cw-surface"] = (
|
|
1127
|
-
cssVars["--cw-border"] = (
|
|
1128
|
-
cssVars["--persona-message-border"] = (
|
|
1147
|
+
cssVars["--persona-md-code-block-bg"] = (_Ra = cssVars["--persona-components-markdown-codeBlock-background"]) != null ? _Ra : cssVars["--persona-container"];
|
|
1148
|
+
cssVars["--persona-md-code-block-border-color"] = (_Sa = cssVars["--persona-components-markdown-codeBlock-borderColor"]) != null ? _Sa : cssVars["--persona-border"];
|
|
1149
|
+
cssVars["--persona-md-code-block-text-color"] = (_Ta = cssVars["--persona-components-markdown-codeBlock-textColor"]) != null ? _Ta : "inherit";
|
|
1150
|
+
cssVars["--persona-md-table-header-bg"] = (_Ua = cssVars["--persona-components-markdown-table-headerBackground"]) != null ? _Ua : cssVars["--persona-container"];
|
|
1151
|
+
cssVars["--persona-md-table-border-color"] = (_Va = cssVars["--persona-components-markdown-table-borderColor"]) != null ? _Va : cssVars["--persona-border"];
|
|
1152
|
+
cssVars["--persona-md-hr-color"] = (_Wa = cssVars["--persona-components-markdown-hr-color"]) != null ? _Wa : cssVars["--persona-divider"];
|
|
1153
|
+
cssVars["--persona-md-blockquote-border-color"] = (_Xa = cssVars["--persona-components-markdown-blockquote-borderColor"]) != null ? _Xa : cssVars["--persona-palette-colors-gray-900"];
|
|
1154
|
+
cssVars["--persona-md-blockquote-bg"] = (_Ya = cssVars["--persona-components-markdown-blockquote-background"]) != null ? _Ya : "transparent";
|
|
1155
|
+
cssVars["--persona-md-blockquote-text-color"] = (_Za = cssVars["--persona-components-markdown-blockquote-textColor"]) != null ? _Za : cssVars["--persona-palette-colors-gray-500"];
|
|
1156
|
+
cssVars["--cw-container"] = (__a = cssVars["--persona-components-collapsibleWidget-container"]) != null ? __a : cssVars["--persona-surface"];
|
|
1157
|
+
cssVars["--cw-surface"] = (_$a = cssVars["--persona-components-collapsibleWidget-surface"]) != null ? _$a : cssVars["--persona-surface"];
|
|
1158
|
+
cssVars["--cw-border"] = (_ab = cssVars["--persona-components-collapsibleWidget-border"]) != null ? _ab : cssVars["--persona-border"];
|
|
1159
|
+
cssVars["--persona-message-border"] = (_bb = cssVars["--persona-components-message-border"]) != null ? _bb : cssVars["--persona-border"];
|
|
1129
1160
|
const components = theme.components;
|
|
1130
1161
|
const iconBtn = components == null ? void 0 : components.iconButton;
|
|
1131
1162
|
if (iconBtn) {
|
|
@@ -1172,23 +1203,23 @@ function themeToCssVariables(theme) {
|
|
|
1172
1203
|
if (t.copyPadding) cssVars["--persona-artifact-toolbar-copy-padding"] = t.copyPadding;
|
|
1173
1204
|
if (t.copyMenuBackground) {
|
|
1174
1205
|
cssVars["--persona-artifact-toolbar-copy-menu-bg"] = t.copyMenuBackground;
|
|
1175
|
-
cssVars["--persona-dropdown-bg"] = (
|
|
1206
|
+
cssVars["--persona-dropdown-bg"] = (_cb = cssVars["--persona-dropdown-bg"]) != null ? _cb : t.copyMenuBackground;
|
|
1176
1207
|
}
|
|
1177
1208
|
if (t.copyMenuBorder) {
|
|
1178
1209
|
cssVars["--persona-artifact-toolbar-copy-menu-border"] = t.copyMenuBorder;
|
|
1179
|
-
cssVars["--persona-dropdown-border"] = (
|
|
1210
|
+
cssVars["--persona-dropdown-border"] = (_db = cssVars["--persona-dropdown-border"]) != null ? _db : t.copyMenuBorder;
|
|
1180
1211
|
}
|
|
1181
1212
|
if (t.copyMenuShadow) {
|
|
1182
1213
|
cssVars["--persona-artifact-toolbar-copy-menu-shadow"] = t.copyMenuShadow;
|
|
1183
|
-
cssVars["--persona-dropdown-shadow"] = (
|
|
1214
|
+
cssVars["--persona-dropdown-shadow"] = (_eb = cssVars["--persona-dropdown-shadow"]) != null ? _eb : t.copyMenuShadow;
|
|
1184
1215
|
}
|
|
1185
1216
|
if (t.copyMenuBorderRadius) {
|
|
1186
1217
|
cssVars["--persona-artifact-toolbar-copy-menu-radius"] = t.copyMenuBorderRadius;
|
|
1187
|
-
cssVars["--persona-dropdown-radius"] = (
|
|
1218
|
+
cssVars["--persona-dropdown-radius"] = (_fb = cssVars["--persona-dropdown-radius"]) != null ? _fb : t.copyMenuBorderRadius;
|
|
1188
1219
|
}
|
|
1189
1220
|
if (t.copyMenuItemHoverBackground) {
|
|
1190
1221
|
cssVars["--persona-artifact-toolbar-copy-menu-item-hover-bg"] = t.copyMenuItemHoverBackground;
|
|
1191
|
-
cssVars["--persona-dropdown-item-hover-bg"] = (
|
|
1222
|
+
cssVars["--persona-dropdown-item-hover-bg"] = (_gb = cssVars["--persona-dropdown-item-hover-bg"]) != null ? _gb : t.copyMenuItemHoverBackground;
|
|
1192
1223
|
}
|
|
1193
1224
|
if (t.iconBackground) cssVars["--persona-artifact-toolbar-icon-bg"] = t.iconBackground;
|
|
1194
1225
|
if (t.toolbarBorder) cssVars["--persona-artifact-toolbar-border"] = t.toolbarBorder;
|
|
@@ -1208,7 +1239,7 @@ function themeToCssVariables(theme) {
|
|
|
1208
1239
|
if (artifact == null ? void 0 : artifact.pane) {
|
|
1209
1240
|
const t = artifact.pane;
|
|
1210
1241
|
if (t.toolbarBackground) {
|
|
1211
|
-
const toolbarBg = (
|
|
1242
|
+
const toolbarBg = (_hb = resolveTokenValue(theme, t.toolbarBackground)) != null ? _hb : t.toolbarBackground;
|
|
1212
1243
|
cssVars["--persona-artifact-toolbar-bg"] = toolbarBg;
|
|
1213
1244
|
}
|
|
1214
1245
|
}
|
|
@@ -4345,6 +4376,40 @@ var AgentWidgetClient = class {
|
|
|
4345
4376
|
})
|
|
4346
4377
|
});
|
|
4347
4378
|
}
|
|
4379
|
+
/**
|
|
4380
|
+
* Resume a paused flow execution by supplying outputs for LOCAL
|
|
4381
|
+
* (client-executed) tools. Used by the built-in `ask_user_question`
|
|
4382
|
+
* answer-pill sheet, but generic enough for any LOCAL tool.
|
|
4383
|
+
*
|
|
4384
|
+
* Posts to the upstream `/resume` endpoint (the dispatch URL with
|
|
4385
|
+
* `/dispatch` replaced by `/resume` — works for both direct-to-Runtype
|
|
4386
|
+
* and the persona proxy) and returns the raw Response so the caller can
|
|
4387
|
+
* pipe its SSE body through `connectStream()`.
|
|
4388
|
+
*
|
|
4389
|
+
* @param executionId - The paused execution id carried on `step_await`.
|
|
4390
|
+
* @param toolOutputs - Map keyed by tool name → the tool's result value.
|
|
4391
|
+
*/
|
|
4392
|
+
async resumeFlow(executionId, toolOutputs, options) {
|
|
4393
|
+
var _a, _b;
|
|
4394
|
+
const trimmed = ((_a = this.config.apiUrl) == null ? void 0 : _a.replace(/\/+$/, "")) || DEFAULT_CLIENT_API_BASE;
|
|
4395
|
+
const url = `${trimmed}/resume`;
|
|
4396
|
+
let headers = {
|
|
4397
|
+
"Content-Type": "application/json",
|
|
4398
|
+
...this.headers
|
|
4399
|
+
};
|
|
4400
|
+
if (this.getHeaders) {
|
|
4401
|
+
Object.assign(headers, await this.getHeaders());
|
|
4402
|
+
}
|
|
4403
|
+
return fetch(url, {
|
|
4404
|
+
method: "POST",
|
|
4405
|
+
headers,
|
|
4406
|
+
body: JSON.stringify({
|
|
4407
|
+
executionId,
|
|
4408
|
+
toolOutputs,
|
|
4409
|
+
streamResponse: (_b = options == null ? void 0 : options.streamResponse) != null ? _b : true
|
|
4410
|
+
})
|
|
4411
|
+
});
|
|
4412
|
+
}
|
|
4348
4413
|
async buildAgentPayload(messages) {
|
|
4349
4414
|
if (!this.config.agent) {
|
|
4350
4415
|
throw new Error("Agent configuration required for agent mode");
|
|
@@ -4906,7 +4971,7 @@ var AgentWidgetClient = class {
|
|
|
4906
4971
|
const agentIterationMessages = /* @__PURE__ */ new Map();
|
|
4907
4972
|
const iterationDisplay = (_a = this.config.iterationDisplay) != null ? _a : "separate";
|
|
4908
4973
|
drainReadyQueue = () => {
|
|
4909
|
-
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb;
|
|
4974
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db;
|
|
4910
4975
|
for (let i = 0; i < seqReadyQueue.length; i++) {
|
|
4911
4976
|
const payloadType = seqReadyQueue[i].payloadType;
|
|
4912
4977
|
const payload = seqReadyQueue[i].payload;
|
|
@@ -5078,8 +5143,26 @@ var AgentWidgetClient = class {
|
|
|
5078
5143
|
if (callKey) {
|
|
5079
5144
|
toolContext.byCall.delete(callKey);
|
|
5080
5145
|
}
|
|
5146
|
+
} else if (payloadType === "step_await" && payload.awaitReason === "local_tool_required" && payload.toolName) {
|
|
5147
|
+
const toolId = (_X = payload.toolId) != null ? _X : `local-${nextSequence()}`;
|
|
5148
|
+
const toolMessage = ensureToolMessage(toolId);
|
|
5149
|
+
const tool = (_Y = toolMessage.toolCall) != null ? _Y : { id: toolId, status: "pending" };
|
|
5150
|
+
tool.name = payload.toolName;
|
|
5151
|
+
tool.args = payload.parameters;
|
|
5152
|
+
tool.status = "complete";
|
|
5153
|
+
tool.chunks = (_Z = tool.chunks) != null ? _Z : [];
|
|
5154
|
+
tool.startedAt = (_$ = tool.startedAt) != null ? _$ : resolveTimestamp((__ = payload.startedAt) != null ? __ : payload.timestamp);
|
|
5155
|
+
tool.completedAt = (_aa = tool.completedAt) != null ? _aa : tool.startedAt;
|
|
5156
|
+
toolMessage.toolCall = tool;
|
|
5157
|
+
toolMessage.streaming = false;
|
|
5158
|
+
toolMessage.agentMetadata = {
|
|
5159
|
+
...toolMessage.agentMetadata,
|
|
5160
|
+
executionId: (_ca = payload.executionId) != null ? _ca : (_ba = toolMessage.agentMetadata) == null ? void 0 : _ba.executionId,
|
|
5161
|
+
awaitingLocalTool: true
|
|
5162
|
+
};
|
|
5163
|
+
emitMessage(toolMessage);
|
|
5081
5164
|
} else if (payloadType === "text_start") {
|
|
5082
|
-
if ((
|
|
5165
|
+
if ((_da = payload.toolContext) == null ? void 0 : _da.toolId) {
|
|
5083
5166
|
continue;
|
|
5084
5167
|
}
|
|
5085
5168
|
const incomingPartId = payload.partId;
|
|
@@ -5097,7 +5180,7 @@ var AgentWidgetClient = class {
|
|
|
5097
5180
|
partIdState.current = incomingPartId;
|
|
5098
5181
|
}
|
|
5099
5182
|
} else if (payloadType === "text_end") {
|
|
5100
|
-
if ((
|
|
5183
|
+
if ((_ea = payload.toolContext) == null ? void 0 : _ea.toolId) {
|
|
5101
5184
|
continue;
|
|
5102
5185
|
}
|
|
5103
5186
|
const prev = assistantMessage;
|
|
@@ -5117,7 +5200,7 @@ var AgentWidgetClient = class {
|
|
|
5117
5200
|
const nestedToolCtx = payload.toolContext;
|
|
5118
5201
|
if (nestedToolCtx == null ? void 0 : nestedToolCtx.toolId) {
|
|
5119
5202
|
const nestedStepId = String(
|
|
5120
|
-
(
|
|
5203
|
+
(_ga = (_fa = payload.id) != null ? _fa : nestedToolCtx.stepId) != null ? _ga : `step-${nextSequence()}`
|
|
5121
5204
|
);
|
|
5122
5205
|
const incomingPartId2 = payload.partId !== void 0 && payload.partId !== null ? String(payload.partId) : "";
|
|
5123
5206
|
const stepScopeKey = `${nestedToolCtx.toolId}::${nestedStepId}`;
|
|
@@ -5144,7 +5227,7 @@ var AgentWidgetClient = class {
|
|
|
5144
5227
|
incomingPartId2,
|
|
5145
5228
|
nestedToolCtx.executionId
|
|
5146
5229
|
);
|
|
5147
|
-
const nestedChunk = (
|
|
5230
|
+
const nestedChunk = (_ka = (_ja = (_ia = (_ha = payload.text) != null ? _ha : payload.delta) != null ? _ia : payload.content) != null ? _ja : payload.chunk) != null ? _ka : "";
|
|
5148
5231
|
if (nestedChunk) {
|
|
5149
5232
|
nestedMsg.content += String(nestedChunk);
|
|
5150
5233
|
nestedMsg.streaming = true;
|
|
@@ -5170,18 +5253,18 @@ var AgentWidgetClient = class {
|
|
|
5170
5253
|
if (incomingPartId !== void 0) {
|
|
5171
5254
|
partIdState.current = incomingPartId;
|
|
5172
5255
|
}
|
|
5173
|
-
const assistant = incomingPartId !== void 0 ? (
|
|
5256
|
+
const assistant = incomingPartId !== void 0 ? (_la = assistantMessagesByPartId.get(incomingPartId)) != null ? _la : ensureAssistantMessage() : ensureAssistantMessage();
|
|
5174
5257
|
if (incomingPartId !== void 0) {
|
|
5175
5258
|
if (!assistant.partId) {
|
|
5176
5259
|
assistant.partId = incomingPartId;
|
|
5177
5260
|
}
|
|
5178
5261
|
assistantMessagesByPartId.set(incomingPartId, assistant);
|
|
5179
5262
|
}
|
|
5180
|
-
const chunk = (
|
|
5263
|
+
const chunk = (_pa = (_oa = (_na = (_ma = payload.text) != null ? _ma : payload.delta) != null ? _na : payload.content) != null ? _oa : payload.chunk) != null ? _pa : "";
|
|
5181
5264
|
if (chunk) {
|
|
5182
5265
|
const chunkSeq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
5183
5266
|
const chunkBufferKey = incomingPartId != null ? incomingPartId : assistant.id;
|
|
5184
|
-
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((
|
|
5267
|
+
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((_qa = rawContentBuffers.get(assistant.id)) != null ? _qa : "") + chunk;
|
|
5185
5268
|
assistant.rawContent = accumulatedRaw;
|
|
5186
5269
|
if (!streamParsers.has(assistant.id)) {
|
|
5187
5270
|
streamParsers.set(assistant.id, this.createStreamParser());
|
|
@@ -5227,7 +5310,7 @@ var AgentWidgetClient = class {
|
|
|
5227
5310
|
emitMessage(assistant);
|
|
5228
5311
|
});
|
|
5229
5312
|
} else {
|
|
5230
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5313
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_ra = parsedResult == null ? void 0 : parsedResult.text) != null ? _ra : null;
|
|
5231
5314
|
if (text !== null && text.trim() !== "") {
|
|
5232
5315
|
assistant.content = text;
|
|
5233
5316
|
emitMessage(assistant);
|
|
@@ -5241,7 +5324,7 @@ var AgentWidgetClient = class {
|
|
|
5241
5324
|
}
|
|
5242
5325
|
}
|
|
5243
5326
|
if (payload.isComplete) {
|
|
5244
|
-
const finalContent = (
|
|
5327
|
+
const finalContent = (_ta = (_sa = payload.result) == null ? void 0 : _sa.response) != null ? _ta : assistant.content;
|
|
5245
5328
|
if (finalContent) {
|
|
5246
5329
|
const rawBuffer = rawContentBuffers.get(assistant.id);
|
|
5247
5330
|
const contentToProcess = rawBuffer != null ? rawBuffer : ensureStringContent(finalContent);
|
|
@@ -5273,7 +5356,7 @@ var AgentWidgetClient = class {
|
|
|
5273
5356
|
}
|
|
5274
5357
|
});
|
|
5275
5358
|
} else {
|
|
5276
|
-
extractedText = typeof parsedResult === "string" ? parsedResult : (
|
|
5359
|
+
extractedText = typeof parsedResult === "string" ? parsedResult : (_ua = parsedResult == null ? void 0 : parsedResult.text) != null ? _ua : null;
|
|
5277
5360
|
}
|
|
5278
5361
|
}
|
|
5279
5362
|
}
|
|
@@ -5285,7 +5368,7 @@ var AgentWidgetClient = class {
|
|
|
5285
5368
|
}
|
|
5286
5369
|
const parserToClose = streamParsers.get(assistant.id);
|
|
5287
5370
|
if (parserToClose) {
|
|
5288
|
-
const closeResult = (
|
|
5371
|
+
const closeResult = (_va = parserToClose.close) == null ? void 0 : _va.call(parserToClose);
|
|
5289
5372
|
if (closeResult instanceof Promise) {
|
|
5290
5373
|
closeResult.catch(() => {
|
|
5291
5374
|
});
|
|
@@ -5307,7 +5390,7 @@ var AgentWidgetClient = class {
|
|
|
5307
5390
|
const nestedCompleteCtx = payload.toolContext;
|
|
5308
5391
|
if (nestedCompleteCtx == null ? void 0 : nestedCompleteCtx.toolId) {
|
|
5309
5392
|
const nestedStepId = String(
|
|
5310
|
-
(
|
|
5393
|
+
(_xa = (_wa = payload.id) != null ? _wa : nestedCompleteCtx.stepId) != null ? _xa : ""
|
|
5311
5394
|
);
|
|
5312
5395
|
if (nestedStepId) {
|
|
5313
5396
|
const prefix = getNestedStepPrefix(
|
|
@@ -5338,7 +5421,7 @@ var AgentWidgetClient = class {
|
|
|
5338
5421
|
emitMessage(msg);
|
|
5339
5422
|
}
|
|
5340
5423
|
}
|
|
5341
|
-
const splitFinalContent = (
|
|
5424
|
+
const splitFinalContent = (_ya = payload.result) == null ? void 0 : _ya.response;
|
|
5342
5425
|
const sealedForReconcile = lastSealedTextSegment;
|
|
5343
5426
|
if (sealedForReconcile) {
|
|
5344
5427
|
if (stepStopReason) sealedForReconcile.stopReason = stepStopReason;
|
|
@@ -5352,7 +5435,7 @@ var AgentWidgetClient = class {
|
|
|
5352
5435
|
lastSealedTextSegment = null;
|
|
5353
5436
|
continue;
|
|
5354
5437
|
}
|
|
5355
|
-
const finalContent = (
|
|
5438
|
+
const finalContent = (_za = payload.result) == null ? void 0 : _za.response;
|
|
5356
5439
|
const assistant = ensureAssistantMessage();
|
|
5357
5440
|
if (stepStopReason) assistant.stopReason = stepStopReason;
|
|
5358
5441
|
if (finalContent !== void 0 && finalContent !== null) {
|
|
@@ -5405,7 +5488,7 @@ var AgentWidgetClient = class {
|
|
|
5405
5488
|
}
|
|
5406
5489
|
});
|
|
5407
5490
|
} else {
|
|
5408
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5491
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_Aa = parsedResult == null ? void 0 : parsedResult.text) != null ? _Aa : null;
|
|
5409
5492
|
if (text !== null && text.trim() !== "") {
|
|
5410
5493
|
assistant.content = text;
|
|
5411
5494
|
hasExtractedText = true;
|
|
@@ -5429,7 +5512,7 @@ var AgentWidgetClient = class {
|
|
|
5429
5512
|
assistant.content = ensureStringContent(finalContent);
|
|
5430
5513
|
}
|
|
5431
5514
|
if (parser) {
|
|
5432
|
-
const closeResult = (
|
|
5515
|
+
const closeResult = (_Ba = parser.close) == null ? void 0 : _Ba.call(parser);
|
|
5433
5516
|
if (closeResult instanceof Promise) {
|
|
5434
5517
|
closeResult.catch(() => {
|
|
5435
5518
|
});
|
|
@@ -5447,7 +5530,7 @@ var AgentWidgetClient = class {
|
|
|
5447
5530
|
emitMessage(assistant);
|
|
5448
5531
|
}
|
|
5449
5532
|
} else if (payloadType === "flow_complete") {
|
|
5450
|
-
const finalContent = (
|
|
5533
|
+
const finalContent = (_Ca = payload.result) == null ? void 0 : _Ca.response;
|
|
5451
5534
|
if (didSplitByPartId) {
|
|
5452
5535
|
if (assistantMessage !== null) {
|
|
5453
5536
|
const msg = assistantMessage;
|
|
@@ -5514,11 +5597,11 @@ var AgentWidgetClient = class {
|
|
|
5514
5597
|
} else if (payloadType === "agent_start") {
|
|
5515
5598
|
agentExecution = {
|
|
5516
5599
|
executionId: payload.executionId,
|
|
5517
|
-
agentId: (
|
|
5518
|
-
agentName: (
|
|
5600
|
+
agentId: (_Da = payload.agentId) != null ? _Da : "virtual",
|
|
5601
|
+
agentName: (_Ea = payload.agentName) != null ? _Ea : "",
|
|
5519
5602
|
status: "running",
|
|
5520
5603
|
currentIteration: 0,
|
|
5521
|
-
maxTurns: (
|
|
5604
|
+
maxTurns: (_Fa = payload.maxTurns) != null ? _Fa : 1,
|
|
5522
5605
|
startedAt: resolveTimestamp(payload.startedAt)
|
|
5523
5606
|
};
|
|
5524
5607
|
} else if (payloadType === "agent_iteration_start") {
|
|
@@ -5538,7 +5621,7 @@ var AgentWidgetClient = class {
|
|
|
5538
5621
|
} else if (payloadType === "agent_turn_delta") {
|
|
5539
5622
|
if (payload.contentType === "text") {
|
|
5540
5623
|
const assistant = ensureAssistantMessage();
|
|
5541
|
-
assistant.content += (
|
|
5624
|
+
assistant.content += (_Ga = payload.delta) != null ? _Ga : "";
|
|
5542
5625
|
assistant.agentMetadata = {
|
|
5543
5626
|
executionId: payload.executionId,
|
|
5544
5627
|
iteration: payload.iteration,
|
|
@@ -5547,14 +5630,14 @@ var AgentWidgetClient = class {
|
|
|
5547
5630
|
};
|
|
5548
5631
|
emitMessage(assistant);
|
|
5549
5632
|
} else if (payload.contentType === "thinking") {
|
|
5550
|
-
const reasoningId = (
|
|
5633
|
+
const reasoningId = (_Ha = payload.turnId) != null ? _Ha : `agent-think-${payload.iteration}`;
|
|
5551
5634
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
5552
|
-
reasoningMessage.reasoning = (
|
|
5635
|
+
reasoningMessage.reasoning = (_Ia = reasoningMessage.reasoning) != null ? _Ia : {
|
|
5553
5636
|
id: reasoningId,
|
|
5554
5637
|
status: "streaming",
|
|
5555
5638
|
chunks: []
|
|
5556
5639
|
};
|
|
5557
|
-
reasoningMessage.reasoning.chunks.push((
|
|
5640
|
+
reasoningMessage.reasoning.chunks.push((_Ja = payload.delta) != null ? _Ja : "");
|
|
5558
5641
|
reasoningMessage.agentMetadata = {
|
|
5559
5642
|
executionId: payload.executionId,
|
|
5560
5643
|
iteration: payload.iteration,
|
|
@@ -5562,12 +5645,12 @@ var AgentWidgetClient = class {
|
|
|
5562
5645
|
};
|
|
5563
5646
|
emitMessage(reasoningMessage);
|
|
5564
5647
|
} else if (payload.contentType === "tool_input") {
|
|
5565
|
-
const toolId = (
|
|
5648
|
+
const toolId = (_Ka = payload.toolCallId) != null ? _Ka : toolContext.lastId;
|
|
5566
5649
|
if (toolId) {
|
|
5567
5650
|
const toolMessage = toolMessages.get(toolId);
|
|
5568
5651
|
if (toolMessage == null ? void 0 : toolMessage.toolCall) {
|
|
5569
|
-
toolMessage.toolCall.chunks = (
|
|
5570
|
-
toolMessage.toolCall.chunks.push((
|
|
5652
|
+
toolMessage.toolCall.chunks = (_La = toolMessage.toolCall.chunks) != null ? _La : [];
|
|
5653
|
+
toolMessage.toolCall.chunks.push((_Ma = payload.delta) != null ? _Ma : "");
|
|
5571
5654
|
emitMessage(toolMessage);
|
|
5572
5655
|
}
|
|
5573
5656
|
}
|
|
@@ -5579,10 +5662,10 @@ var AgentWidgetClient = class {
|
|
|
5579
5662
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
5580
5663
|
reasoningMessage.reasoning.status = "complete";
|
|
5581
5664
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(payload.completedAt);
|
|
5582
|
-
const start = (
|
|
5665
|
+
const start = (_Na = reasoningMessage.reasoning.startedAt) != null ? _Na : Date.now();
|
|
5583
5666
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
5584
5667
|
0,
|
|
5585
|
-
((
|
|
5668
|
+
((_Oa = reasoningMessage.reasoning.completedAt) != null ? _Oa : Date.now()) - start
|
|
5586
5669
|
);
|
|
5587
5670
|
reasoningMessage.streaming = false;
|
|
5588
5671
|
emitMessage(reasoningMessage);
|
|
@@ -5591,17 +5674,17 @@ var AgentWidgetClient = class {
|
|
|
5591
5674
|
const turnStopReason = payload.stopReason;
|
|
5592
5675
|
if (turnStopReason && assistantMessage !== null) {
|
|
5593
5676
|
const turnId = payload.turnId;
|
|
5594
|
-
const matchesTurn = !turnId || ((
|
|
5677
|
+
const matchesTurn = !turnId || ((_Pa = assistantMessage.agentMetadata) == null ? void 0 : _Pa.turnId) === turnId;
|
|
5595
5678
|
if (matchesTurn) {
|
|
5596
5679
|
assistantMessage.stopReason = turnStopReason;
|
|
5597
5680
|
emitMessage(assistantMessage);
|
|
5598
5681
|
}
|
|
5599
5682
|
}
|
|
5600
5683
|
} else if (payloadType === "agent_tool_start") {
|
|
5601
|
-
const toolId = (
|
|
5684
|
+
const toolId = (_Qa = payload.toolCallId) != null ? _Qa : `agent-tool-${nextSequence()}`;
|
|
5602
5685
|
trackToolId(getToolCallKey(payload), toolId);
|
|
5603
5686
|
const toolMessage = ensureToolMessage(toolId);
|
|
5604
|
-
const tool = (
|
|
5687
|
+
const tool = (_Ra = toolMessage.toolCall) != null ? _Ra : {
|
|
5605
5688
|
id: toolId,
|
|
5606
5689
|
status: "pending",
|
|
5607
5690
|
name: void 0,
|
|
@@ -5613,12 +5696,12 @@ var AgentWidgetClient = class {
|
|
|
5613
5696
|
completedAt: void 0,
|
|
5614
5697
|
durationMs: void 0
|
|
5615
5698
|
};
|
|
5616
|
-
tool.name = (
|
|
5699
|
+
tool.name = (_Ta = (_Sa = payload.toolName) != null ? _Sa : payload.name) != null ? _Ta : tool.name;
|
|
5617
5700
|
tool.status = "running";
|
|
5618
5701
|
if (payload.parameters !== void 0) {
|
|
5619
5702
|
tool.args = payload.parameters;
|
|
5620
5703
|
}
|
|
5621
|
-
tool.startedAt = resolveTimestamp((
|
|
5704
|
+
tool.startedAt = resolveTimestamp((_Ua = payload.startedAt) != null ? _Ua : payload.timestamp);
|
|
5622
5705
|
toolMessage.toolCall = tool;
|
|
5623
5706
|
toolMessage.streaming = true;
|
|
5624
5707
|
toolMessage.agentMetadata = {
|
|
@@ -5627,21 +5710,21 @@ var AgentWidgetClient = class {
|
|
|
5627
5710
|
};
|
|
5628
5711
|
emitMessage(toolMessage);
|
|
5629
5712
|
} else if (payloadType === "agent_tool_delta") {
|
|
5630
|
-
const toolId = (
|
|
5713
|
+
const toolId = (_Va = payload.toolCallId) != null ? _Va : toolContext.lastId;
|
|
5631
5714
|
if (toolId) {
|
|
5632
|
-
const toolMessage = (
|
|
5715
|
+
const toolMessage = (_Wa = toolMessages.get(toolId)) != null ? _Wa : ensureToolMessage(toolId);
|
|
5633
5716
|
if (toolMessage.toolCall) {
|
|
5634
|
-
toolMessage.toolCall.chunks = (
|
|
5635
|
-
toolMessage.toolCall.chunks.push((
|
|
5717
|
+
toolMessage.toolCall.chunks = (_Xa = toolMessage.toolCall.chunks) != null ? _Xa : [];
|
|
5718
|
+
toolMessage.toolCall.chunks.push((_Ya = payload.delta) != null ? _Ya : "");
|
|
5636
5719
|
toolMessage.toolCall.status = "running";
|
|
5637
5720
|
toolMessage.streaming = true;
|
|
5638
5721
|
emitMessage(toolMessage);
|
|
5639
5722
|
}
|
|
5640
5723
|
}
|
|
5641
5724
|
} else if (payloadType === "agent_tool_complete") {
|
|
5642
|
-
const toolId = (
|
|
5725
|
+
const toolId = (_Za = payload.toolCallId) != null ? _Za : toolContext.lastId;
|
|
5643
5726
|
if (toolId) {
|
|
5644
|
-
const toolMessage = (
|
|
5727
|
+
const toolMessage = (__a = toolMessages.get(toolId)) != null ? __a : ensureToolMessage(toolId);
|
|
5645
5728
|
if (toolMessage.toolCall) {
|
|
5646
5729
|
toolMessage.toolCall.status = "complete";
|
|
5647
5730
|
if (payload.result !== void 0) {
|
|
@@ -5650,7 +5733,7 @@ var AgentWidgetClient = class {
|
|
|
5650
5733
|
if (typeof payload.executionTime === "number") {
|
|
5651
5734
|
toolMessage.toolCall.durationMs = payload.executionTime;
|
|
5652
5735
|
}
|
|
5653
|
-
toolMessage.toolCall.completedAt = resolveTimestamp((
|
|
5736
|
+
toolMessage.toolCall.completedAt = resolveTimestamp((_$a = payload.completedAt) != null ? _$a : payload.timestamp);
|
|
5654
5737
|
toolMessage.streaming = false;
|
|
5655
5738
|
emitMessage(toolMessage);
|
|
5656
5739
|
const callKey = getToolCallKey(payload);
|
|
@@ -5665,7 +5748,7 @@ var AgentWidgetClient = class {
|
|
|
5665
5748
|
const reflectionMessage = {
|
|
5666
5749
|
id: reflectionId,
|
|
5667
5750
|
role: "assistant",
|
|
5668
|
-
content: (
|
|
5751
|
+
content: (_ab = payload.reflection) != null ? _ab : "",
|
|
5669
5752
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5670
5753
|
streaming: false,
|
|
5671
5754
|
variant: "reasoning",
|
|
@@ -5673,7 +5756,7 @@ var AgentWidgetClient = class {
|
|
|
5673
5756
|
reasoning: {
|
|
5674
5757
|
id: reflectionId,
|
|
5675
5758
|
status: "complete",
|
|
5676
|
-
chunks: [(
|
|
5759
|
+
chunks: [(_bb = payload.reflection) != null ? _bb : ""]
|
|
5677
5760
|
},
|
|
5678
5761
|
agentMetadata: {
|
|
5679
5762
|
executionId: payload.executionId,
|
|
@@ -5694,7 +5777,7 @@ var AgentWidgetClient = class {
|
|
|
5694
5777
|
}
|
|
5695
5778
|
onEvent({ type: "status", status: "idle" });
|
|
5696
5779
|
} else if (payloadType === "agent_error") {
|
|
5697
|
-
const errorMessage = typeof payload.error === "string" ? payload.error : (
|
|
5780
|
+
const errorMessage = typeof payload.error === "string" ? payload.error : (_db = (_cb = payload.error) == null ? void 0 : _cb.message) != null ? _db : "Agent execution error";
|
|
5698
5781
|
if (payload.recoverable) {
|
|
5699
5782
|
if (typeof console !== "undefined") {
|
|
5700
5783
|
console.warn("[AgentWidget] Recoverable agent error:", errorMessage);
|
|
@@ -5707,7 +5790,7 @@ var AgentWidgetClient = class {
|
|
|
5707
5790
|
}
|
|
5708
5791
|
} else if (payloadType === "agent_ping") {
|
|
5709
5792
|
} else if (payloadType === "agent_approval_start") {
|
|
5710
|
-
const approvalId = (
|
|
5793
|
+
const approvalId = (_eb = payload.approvalId) != null ? _eb : `approval-${nextSequence()}`;
|
|
5711
5794
|
const approvalMessage = {
|
|
5712
5795
|
id: `approval-${approvalId}`,
|
|
5713
5796
|
role: "assistant",
|
|
@@ -5719,17 +5802,17 @@ var AgentWidgetClient = class {
|
|
|
5719
5802
|
approval: {
|
|
5720
5803
|
id: approvalId,
|
|
5721
5804
|
status: "pending",
|
|
5722
|
-
agentId: (
|
|
5723
|
-
executionId: (
|
|
5724
|
-
toolName: (
|
|
5805
|
+
agentId: (_fb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _fb : "virtual",
|
|
5806
|
+
executionId: (_hb = (_gb = payload.executionId) != null ? _gb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _hb : "",
|
|
5807
|
+
toolName: (_ib = payload.toolName) != null ? _ib : "",
|
|
5725
5808
|
toolType: payload.toolType,
|
|
5726
|
-
description: (
|
|
5809
|
+
description: (_kb = payload.description) != null ? _kb : `Execute ${(_jb = payload.toolName) != null ? _jb : "tool"}`,
|
|
5727
5810
|
parameters: payload.parameters
|
|
5728
5811
|
}
|
|
5729
5812
|
};
|
|
5730
5813
|
emitMessage(approvalMessage);
|
|
5731
5814
|
} else if (payloadType === "step_await" && payload.awaitReason === "approval_required") {
|
|
5732
|
-
const approvalId = (
|
|
5815
|
+
const approvalId = (_lb = payload.approvalId) != null ? _lb : `approval-${nextSequence()}`;
|
|
5733
5816
|
const approvalMessage = {
|
|
5734
5817
|
id: `approval-${approvalId}`,
|
|
5735
5818
|
role: "assistant",
|
|
@@ -5741,11 +5824,11 @@ var AgentWidgetClient = class {
|
|
|
5741
5824
|
approval: {
|
|
5742
5825
|
id: approvalId,
|
|
5743
5826
|
status: "pending",
|
|
5744
|
-
agentId: (
|
|
5745
|
-
executionId: (
|
|
5746
|
-
toolName: (
|
|
5827
|
+
agentId: (_mb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _mb : "virtual",
|
|
5828
|
+
executionId: (_ob = (_nb = payload.executionId) != null ? _nb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _ob : "",
|
|
5829
|
+
toolName: (_pb = payload.toolName) != null ? _pb : "",
|
|
5747
5830
|
toolType: payload.toolType,
|
|
5748
|
-
description: (
|
|
5831
|
+
description: (_rb = payload.description) != null ? _rb : `Execute ${(_qb = payload.toolName) != null ? _qb : "tool"}`,
|
|
5749
5832
|
parameters: payload.parameters
|
|
5750
5833
|
}
|
|
5751
5834
|
};
|
|
@@ -5764,11 +5847,11 @@ var AgentWidgetClient = class {
|
|
|
5764
5847
|
sequence: nextSequence(),
|
|
5765
5848
|
approval: {
|
|
5766
5849
|
id: approvalId,
|
|
5767
|
-
status: (
|
|
5768
|
-
agentId: (
|
|
5769
|
-
executionId: (
|
|
5770
|
-
toolName: (
|
|
5771
|
-
description: (
|
|
5850
|
+
status: (_sb = payload.decision) != null ? _sb : "approved",
|
|
5851
|
+
agentId: (_tb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _tb : "virtual",
|
|
5852
|
+
executionId: (_vb = (_ub = payload.executionId) != null ? _ub : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _vb : "",
|
|
5853
|
+
toolName: (_wb = payload.toolName) != null ? _wb : "",
|
|
5854
|
+
description: (_xb = payload.description) != null ? _xb : "",
|
|
5772
5855
|
resolvedAt: Date.now()
|
|
5773
5856
|
}
|
|
5774
5857
|
};
|
|
@@ -5806,7 +5889,7 @@ var AgentWidgetClient = class {
|
|
|
5806
5889
|
}
|
|
5807
5890
|
} else if (payloadType === "artifact_delta") {
|
|
5808
5891
|
const deltaId = String(payload.id);
|
|
5809
|
-
const deltaText = typeof payload.delta === "string" ? payload.delta : String((
|
|
5892
|
+
const deltaText = typeof payload.delta === "string" ? payload.delta : String((_yb = payload.delta) != null ? _yb : "");
|
|
5810
5893
|
onEvent({
|
|
5811
5894
|
type: "artifact_delta",
|
|
5812
5895
|
id: deltaId,
|
|
@@ -5829,7 +5912,7 @@ var AgentWidgetClient = class {
|
|
|
5829
5912
|
if (refMsg) {
|
|
5830
5913
|
refMsg.streaming = false;
|
|
5831
5914
|
try {
|
|
5832
|
-
const parsed = JSON.parse((
|
|
5915
|
+
const parsed = JSON.parse((_zb = refMsg.rawContent) != null ? _zb : "{}");
|
|
5833
5916
|
if (parsed.props) {
|
|
5834
5917
|
parsed.props.status = "complete";
|
|
5835
5918
|
const acc = artifactContent.get(artCompleteId);
|
|
@@ -5850,7 +5933,7 @@ var AgentWidgetClient = class {
|
|
|
5850
5933
|
if (!m || typeof m !== "object") {
|
|
5851
5934
|
continue;
|
|
5852
5935
|
}
|
|
5853
|
-
const id = String((
|
|
5936
|
+
const id = String((_Ab = m.id) != null ? _Ab : `msg-${nextSequence()}`);
|
|
5854
5937
|
const roleRaw = m.role;
|
|
5855
5938
|
const role = roleRaw === "user" ? "user" : roleRaw === "system" ? "system" : "assistant";
|
|
5856
5939
|
const msg = {
|
|
@@ -5869,7 +5952,7 @@ var AgentWidgetClient = class {
|
|
|
5869
5952
|
if (msg.rawContent) {
|
|
5870
5953
|
try {
|
|
5871
5954
|
const parsed = JSON.parse(msg.rawContent);
|
|
5872
|
-
const refArtId = (
|
|
5955
|
+
const refArtId = (_Bb = parsed == null ? void 0 : parsed.props) == null ? void 0 : _Bb.artifactId;
|
|
5873
5956
|
if (typeof refArtId === "string") {
|
|
5874
5957
|
artifactIdsWithCards.add(refArtId);
|
|
5875
5958
|
}
|
|
@@ -5885,7 +5968,7 @@ var AgentWidgetClient = class {
|
|
|
5885
5968
|
if (payload.error instanceof Error) {
|
|
5886
5969
|
resolvedError = payload.error;
|
|
5887
5970
|
} else if (payloadType === "dispatch_error") {
|
|
5888
|
-
const msg = (
|
|
5971
|
+
const msg = (_Cb = payload.message) != null ? _Cb : payload.error;
|
|
5889
5972
|
if (msg != null && msg !== "") {
|
|
5890
5973
|
resolvedError = new Error(String(msg));
|
|
5891
5974
|
}
|
|
@@ -5894,7 +5977,7 @@ var AgentWidgetClient = class {
|
|
|
5894
5977
|
if (typeof e === "string" && e !== "") {
|
|
5895
5978
|
resolvedError = new Error(e);
|
|
5896
5979
|
} else if (e != null && typeof e === "object" && "message" in e) {
|
|
5897
|
-
resolvedError = new Error(String((
|
|
5980
|
+
resolvedError = new Error(String((_Db = e.message) != null ? _Db : e));
|
|
5898
5981
|
}
|
|
5899
5982
|
} else if (payloadType === "error" && payload.error != null && payload.error !== "") {
|
|
5900
5983
|
resolvedError = new Error(String(payload.error));
|
|
@@ -6998,7 +7081,7 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
6998
7081
|
this.applyArtifactStreamEvent(event);
|
|
6999
7082
|
}
|
|
7000
7083
|
};
|
|
7001
|
-
var _a;
|
|
7084
|
+
var _a, _b;
|
|
7002
7085
|
this.messages = [...(_a = config.initialMessages) != null ? _a : []].map((message) => {
|
|
7003
7086
|
var _a2;
|
|
7004
7087
|
return {
|
|
@@ -7008,9 +7091,18 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7008
7091
|
});
|
|
7009
7092
|
this.messages = this.sortMessages(this.messages);
|
|
7010
7093
|
this.client = new AgentWidgetClient(config);
|
|
7094
|
+
for (const rec of (_b = config.initialArtifacts) != null ? _b : []) {
|
|
7095
|
+
this.artifacts.set(rec.id, { ...rec, status: "complete" });
|
|
7096
|
+
}
|
|
7097
|
+
if (config.initialSelectedArtifactId != null) {
|
|
7098
|
+
this.selectedArtifactId = config.initialSelectedArtifactId;
|
|
7099
|
+
}
|
|
7011
7100
|
if (this.messages.length) {
|
|
7012
7101
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
7013
7102
|
}
|
|
7103
|
+
if (this.artifacts.size > 0) {
|
|
7104
|
+
this.emitArtifactsState();
|
|
7105
|
+
}
|
|
7014
7106
|
this.callbacks.onStatusChanged(this.status);
|
|
7015
7107
|
}
|
|
7016
7108
|
/**
|
|
@@ -7735,6 +7827,141 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7735
7827
|
);
|
|
7736
7828
|
}
|
|
7737
7829
|
}
|
|
7830
|
+
/**
|
|
7831
|
+
* Resolve a paused `ask_user_question` LOCAL tool call.
|
|
7832
|
+
*
|
|
7833
|
+
* When the server emits `step_await` for `ask_user_question`, the widget
|
|
7834
|
+
* renders the answer-pill sheet and calls this method once the user
|
|
7835
|
+
* picks. Steps:
|
|
7836
|
+
* 1. POST the answer to `/resume` via `client.resumeFlow`.
|
|
7837
|
+
* 2. Pipe the resulting SSE stream through `connectStream()` so the
|
|
7838
|
+
* paused agent execution continues.
|
|
7839
|
+
* 3. Append a user-visible bubble with the answer text so the
|
|
7840
|
+
* transcript reads naturally.
|
|
7841
|
+
*/
|
|
7842
|
+
/**
|
|
7843
|
+
* Persist in-progress answers and the current page index for a multi-question
|
|
7844
|
+
* `ask_user_question` payload, so a refresh resumes on the same page with
|
|
7845
|
+
* prior answers intact. Called by ui.ts on every Back/Next/pick interaction.
|
|
7846
|
+
*/
|
|
7847
|
+
persistAskUserQuestionProgress(toolMessage, progress) {
|
|
7848
|
+
const current = this.messages.find((m) => m.id === toolMessage.id);
|
|
7849
|
+
if (!current) return;
|
|
7850
|
+
this.upsertMessage({
|
|
7851
|
+
...current,
|
|
7852
|
+
agentMetadata: {
|
|
7853
|
+
...current.agentMetadata,
|
|
7854
|
+
askUserQuestionAnswers: progress.answers,
|
|
7855
|
+
askUserQuestionIndex: progress.currentIndex
|
|
7856
|
+
}
|
|
7857
|
+
});
|
|
7858
|
+
}
|
|
7859
|
+
/**
|
|
7860
|
+
* Flip an `ask_user_question` tool message from awaiting → answered so
|
|
7861
|
+
* render passes stop re-mounting its answer-pill sheet. Idempotent.
|
|
7862
|
+
* When `answers` is provided, persists the full structured answer Record
|
|
7863
|
+
* atomically with the answered flag — guarding against later events that
|
|
7864
|
+
* could re-emit the tool message and clobber the per-pick persisted
|
|
7865
|
+
* answers via top-level merge.
|
|
7866
|
+
*/
|
|
7867
|
+
markAskUserQuestionResolved(toolMessage, answers) {
|
|
7868
|
+
const current = this.messages.find((m) => m.id === toolMessage.id);
|
|
7869
|
+
if (!current) return;
|
|
7870
|
+
this.upsertMessage({
|
|
7871
|
+
...current,
|
|
7872
|
+
agentMetadata: {
|
|
7873
|
+
...current.agentMetadata,
|
|
7874
|
+
awaitingLocalTool: false,
|
|
7875
|
+
askUserQuestionAnswered: true,
|
|
7876
|
+
...answers ? { askUserQuestionAnswers: answers } : {}
|
|
7877
|
+
}
|
|
7878
|
+
});
|
|
7879
|
+
}
|
|
7880
|
+
async resolveAskUserQuestion(toolMessage, answer) {
|
|
7881
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7882
|
+
const live = this.messages.find((m) => m.id === toolMessage.id);
|
|
7883
|
+
if (((_a = live == null ? void 0 : live.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswered) === true) return;
|
|
7884
|
+
const executionId = (_b = toolMessage.agentMetadata) == null ? void 0 : _b.executionId;
|
|
7885
|
+
const toolName = (_c = toolMessage.toolCall) == null ? void 0 : _c.name;
|
|
7886
|
+
if (!executionId || !toolName) {
|
|
7887
|
+
(_e = (_d = this.callbacks).onError) == null ? void 0 : _e.call(
|
|
7888
|
+
_d,
|
|
7889
|
+
new Error(
|
|
7890
|
+
"resolveAskUserQuestion: message is missing executionId or toolCall.name"
|
|
7891
|
+
)
|
|
7892
|
+
);
|
|
7893
|
+
return;
|
|
7894
|
+
}
|
|
7895
|
+
let structuredAnswers = typeof answer === "string" ? void 0 : answer;
|
|
7896
|
+
if (structuredAnswers === void 0 && typeof answer === "string") {
|
|
7897
|
+
const args2 = (_f = toolMessage.toolCall) == null ? void 0 : _f.args;
|
|
7898
|
+
const questions2 = Array.isArray(args2 == null ? void 0 : args2.questions) ? args2.questions : [];
|
|
7899
|
+
if (questions2.length === 1) {
|
|
7900
|
+
const qText = typeof ((_g = questions2[0]) == null ? void 0 : _g.question) === "string" ? questions2[0].question : "";
|
|
7901
|
+
if (qText) structuredAnswers = { [qText]: answer };
|
|
7902
|
+
}
|
|
7903
|
+
}
|
|
7904
|
+
this.markAskUserQuestionResolved(toolMessage, structuredAnswers);
|
|
7905
|
+
const toolCallId = toolMessage.toolCall.id;
|
|
7906
|
+
const args = (_h = toolMessage.toolCall) == null ? void 0 : _h.args;
|
|
7907
|
+
const questions = Array.isArray(args == null ? void 0 : args.questions) ? args.questions : [];
|
|
7908
|
+
if (questions.length === 0) {
|
|
7909
|
+
const fallback = typeof answer === "string" ? answer : Object.entries(answer).map(
|
|
7910
|
+
([q, v]) => `${q}: ${Array.isArray(v) ? v.join(", ") : v}`
|
|
7911
|
+
).join(" | ");
|
|
7912
|
+
this.appendMessage({
|
|
7913
|
+
id: `ask-user-answer-${toolCallId}`,
|
|
7914
|
+
role: "user",
|
|
7915
|
+
content: fallback,
|
|
7916
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7917
|
+
streaming: false,
|
|
7918
|
+
sequence: this.nextSequence()
|
|
7919
|
+
});
|
|
7920
|
+
} else {
|
|
7921
|
+
const stored = structuredAnswers != null ? structuredAnswers : {};
|
|
7922
|
+
questions.forEach((p, i) => {
|
|
7923
|
+
const qText = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
7924
|
+
if (!qText) return;
|
|
7925
|
+
const ans = stored[qText];
|
|
7926
|
+
const answerStr = Array.isArray(ans) ? ans.join(", ") : typeof ans === "string" ? ans : "";
|
|
7927
|
+
this.appendMessage({
|
|
7928
|
+
id: `ask-user-q-${toolCallId}-${i}`,
|
|
7929
|
+
role: "assistant",
|
|
7930
|
+
content: qText,
|
|
7931
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7932
|
+
streaming: false,
|
|
7933
|
+
sequence: this.nextSequence()
|
|
7934
|
+
});
|
|
7935
|
+
this.appendMessage({
|
|
7936
|
+
id: `ask-user-a-${toolCallId}-${i}`,
|
|
7937
|
+
role: "user",
|
|
7938
|
+
content: answerStr || "*Skipped*",
|
|
7939
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7940
|
+
streaming: false,
|
|
7941
|
+
sequence: this.nextSequence()
|
|
7942
|
+
});
|
|
7943
|
+
});
|
|
7944
|
+
}
|
|
7945
|
+
try {
|
|
7946
|
+
const response = await this.client.resumeFlow(executionId, {
|
|
7947
|
+
[toolName]: answer
|
|
7948
|
+
});
|
|
7949
|
+
if (!response.ok) {
|
|
7950
|
+
const errorData = await response.json().catch(() => null);
|
|
7951
|
+
throw new Error(
|
|
7952
|
+
(_i = errorData == null ? void 0 : errorData.error) != null ? _i : `Resume failed: ${response.status}`
|
|
7953
|
+
);
|
|
7954
|
+
}
|
|
7955
|
+
if (response.body) {
|
|
7956
|
+
await this.connectStream(response.body);
|
|
7957
|
+
}
|
|
7958
|
+
} catch (error) {
|
|
7959
|
+
(_k = (_j = this.callbacks).onError) == null ? void 0 : _k.call(
|
|
7960
|
+
_j,
|
|
7961
|
+
error instanceof Error ? error : new Error(String(error))
|
|
7962
|
+
);
|
|
7963
|
+
}
|
|
7964
|
+
}
|
|
7738
7965
|
cancel() {
|
|
7739
7966
|
var _a;
|
|
7740
7967
|
(_a = this.abortController) == null ? void 0 : _a.abort();
|
|
@@ -7882,6 +8109,14 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7882
8109
|
this.setStatus("idle");
|
|
7883
8110
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
7884
8111
|
}
|
|
8112
|
+
hydrateArtifacts(artifacts, selectedId = null) {
|
|
8113
|
+
this.artifacts.clear();
|
|
8114
|
+
for (const rec of artifacts) {
|
|
8115
|
+
this.artifacts.set(rec.id, { ...rec, status: "complete" });
|
|
8116
|
+
}
|
|
8117
|
+
this.selectedArtifactId = selectedId;
|
|
8118
|
+
this.emitArtifactsState();
|
|
8119
|
+
}
|
|
7885
8120
|
setStatus(status) {
|
|
7886
8121
|
if (this.status === status) return;
|
|
7887
8122
|
this.status = status;
|
|
@@ -7988,9 +8223,24 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7988
8223
|
this.appendMessage(withSequence);
|
|
7989
8224
|
return;
|
|
7990
8225
|
}
|
|
7991
|
-
this.messages = this.messages.map(
|
|
7992
|
-
|
|
7993
|
-
|
|
8226
|
+
this.messages = this.messages.map((existing, idx) => {
|
|
8227
|
+
var _a;
|
|
8228
|
+
if (idx !== index) return existing;
|
|
8229
|
+
const merged = { ...existing, ...withSequence };
|
|
8230
|
+
if (((_a = existing.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswered) === true && withSequence.agentMetadata) {
|
|
8231
|
+
merged.agentMetadata = {
|
|
8232
|
+
...withSequence.agentMetadata,
|
|
8233
|
+
askUserQuestionAnswered: true,
|
|
8234
|
+
...existing.agentMetadata.askUserQuestionAnswers ? {
|
|
8235
|
+
askUserQuestionAnswers: existing.agentMetadata.askUserQuestionAnswers
|
|
8236
|
+
} : {},
|
|
8237
|
+
// Keep awaiting flag false once resolved — never let a stale
|
|
8238
|
+
// re-emit flip us back to awaiting.
|
|
8239
|
+
awaitingLocalTool: false
|
|
8240
|
+
};
|
|
8241
|
+
}
|
|
8242
|
+
return merged;
|
|
8243
|
+
});
|
|
7994
8244
|
this.messages = this.sortMessages(this.messages);
|
|
7995
8245
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
7996
8246
|
}
|
|
@@ -10276,8 +10526,11 @@ var buildPanel = (config, showClose = true) => {
|
|
|
10276
10526
|
);
|
|
10277
10527
|
body.id = "persona-scroll-container";
|
|
10278
10528
|
body.setAttribute("data-persona-theme-zone", "messages");
|
|
10279
|
-
const
|
|
10280
|
-
|
|
10529
|
+
const introCard = createElement(
|
|
10530
|
+
"div",
|
|
10531
|
+
"persona-rounded-2xl persona-bg-persona-surface persona-p-6"
|
|
10532
|
+
);
|
|
10533
|
+
introCard.style.boxShadow = isDockedMountMode(config) ? "none" : "var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))";
|
|
10281
10534
|
const introTitle = createElement(
|
|
10282
10535
|
"h2",
|
|
10283
10536
|
"persona-text-lg persona-font-semibold persona-text-persona-primary"
|
|
@@ -10317,16 +10570,28 @@ var buildPanel = (config, showClose = true) => {
|
|
|
10317
10570
|
attachHeaderToContainer(container, headerElements, config);
|
|
10318
10571
|
}
|
|
10319
10572
|
container.append(body);
|
|
10573
|
+
const composerOverlay = createElement(
|
|
10574
|
+
"div",
|
|
10575
|
+
"persona-composer-overlay persona-pointer-events-none"
|
|
10576
|
+
);
|
|
10577
|
+
composerOverlay.setAttribute("data-persona-composer-overlay", "");
|
|
10578
|
+
composerOverlay.style.position = "absolute";
|
|
10579
|
+
composerOverlay.style.left = "0";
|
|
10580
|
+
composerOverlay.style.right = "0";
|
|
10581
|
+
composerOverlay.style.bottom = "0";
|
|
10582
|
+
composerOverlay.style.zIndex = "20";
|
|
10320
10583
|
if (showFooter) {
|
|
10321
10584
|
container.append(composerElements.footer);
|
|
10322
10585
|
} else {
|
|
10323
10586
|
composerElements.footer.style.display = "none";
|
|
10324
10587
|
container.append(composerElements.footer);
|
|
10325
10588
|
}
|
|
10589
|
+
container.append(composerOverlay);
|
|
10326
10590
|
return {
|
|
10327
10591
|
container,
|
|
10328
10592
|
body,
|
|
10329
10593
|
messagesWrapper,
|
|
10594
|
+
composerOverlay,
|
|
10330
10595
|
suggestions: composerElements.suggestions,
|
|
10331
10596
|
textarea: composerElements.textarea,
|
|
10332
10597
|
sendButton: composerElements.sendButton,
|
|
@@ -11592,6 +11857,582 @@ var createToolBubble = (message, config) => {
|
|
|
11592
11857
|
return bubble;
|
|
11593
11858
|
};
|
|
11594
11859
|
|
|
11860
|
+
// src/components/ask-user-question-bubble.ts
|
|
11861
|
+
var import_partial_json2 = require("partial-json");
|
|
11862
|
+
var ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
11863
|
+
var ASK_USER_QUESTION_MAX = 8;
|
|
11864
|
+
var SHEET_SENTINEL = "data-persona-ask-sheet-for";
|
|
11865
|
+
var DEFAULT_FREE_TEXT_LABEL_ROWS = "Other";
|
|
11866
|
+
var DEFAULT_FREE_TEXT_LABEL_PILLS = "Other\u2026";
|
|
11867
|
+
var DEFAULT_FREE_TEXT_PLACEHOLDER = "Type your own answer here";
|
|
11868
|
+
var DEFAULT_SUBMIT_LABEL = "Send";
|
|
11869
|
+
var DEFAULT_NEXT_LABEL = "Next";
|
|
11870
|
+
var DEFAULT_BACK_LABEL = "Back";
|
|
11871
|
+
var DEFAULT_SUBMIT_ALL_LABEL = "Submit all";
|
|
11872
|
+
var DEFAULT_SKIP_LABEL = "Skip";
|
|
11873
|
+
var DEFAULT_SKELETON_PILLS = 3;
|
|
11874
|
+
var ATTR_CURRENT_INDEX = "data-ask-current-index";
|
|
11875
|
+
var ATTR_QUESTION_COUNT = "data-ask-question-count";
|
|
11876
|
+
var ATTR_ANSWERS = "data-ask-answers";
|
|
11877
|
+
var ATTR_GROUPED = "data-ask-grouped";
|
|
11878
|
+
var ATTR_LAYOUT = "data-ask-layout";
|
|
11879
|
+
var resolveLayout = (feature) => feature.layout === "pills" ? "pills" : "rows";
|
|
11880
|
+
var getLayout = (sheet) => sheet.getAttribute(ATTR_LAYOUT) === "pills" ? "pills" : "rows";
|
|
11881
|
+
var truncateWarned = false;
|
|
11882
|
+
var escapeAttrValue = (value) => value.replace(/["\\]/g, "\\$&");
|
|
11883
|
+
var isAskUserQuestionMessage = (message) => {
|
|
11884
|
+
return message.variant === "tool" && !!message.toolCall && message.toolCall.name === ASK_USER_QUESTION_TOOL_NAME;
|
|
11885
|
+
};
|
|
11886
|
+
var resolveFeature = (config) => {
|
|
11887
|
+
var _a, _b;
|
|
11888
|
+
return (_b = (_a = config == null ? void 0 : config.features) == null ? void 0 : _a.askUserQuestion) != null ? _b : {};
|
|
11889
|
+
};
|
|
11890
|
+
var parseAskUserQuestionPayload = (message) => {
|
|
11891
|
+
const toolCall = message.toolCall;
|
|
11892
|
+
if (!toolCall) return { payload: null, complete: false };
|
|
11893
|
+
const complete = toolCall.status === "complete";
|
|
11894
|
+
if (toolCall.args && typeof toolCall.args === "object") {
|
|
11895
|
+
return { payload: toolCall.args, complete };
|
|
11896
|
+
}
|
|
11897
|
+
const chunks = toolCall.chunks;
|
|
11898
|
+
if (!chunks || chunks.length === 0) return { payload: null, complete };
|
|
11899
|
+
try {
|
|
11900
|
+
const text = chunks.join("");
|
|
11901
|
+
const parsed = (0, import_partial_json2.parse)(text, import_partial_json2.STR | import_partial_json2.OBJ | import_partial_json2.ARR);
|
|
11902
|
+
if (parsed && typeof parsed === "object") {
|
|
11903
|
+
return { payload: parsed, complete };
|
|
11904
|
+
}
|
|
11905
|
+
} catch {
|
|
11906
|
+
}
|
|
11907
|
+
return { payload: null, complete };
|
|
11908
|
+
};
|
|
11909
|
+
var promptsFromPayload = (payload) => {
|
|
11910
|
+
const all = Array.isArray(payload == null ? void 0 : payload.questions) ? payload.questions : [];
|
|
11911
|
+
if (all.length > ASK_USER_QUESTION_MAX && !truncateWarned) {
|
|
11912
|
+
truncateWarned = true;
|
|
11913
|
+
if (typeof console !== "undefined") {
|
|
11914
|
+
console.warn(
|
|
11915
|
+
`[AgentWidget] ask_user_question received ${all.length} questions; truncating to ${ASK_USER_QUESTION_MAX}.`
|
|
11916
|
+
);
|
|
11917
|
+
}
|
|
11918
|
+
}
|
|
11919
|
+
return all.slice(0, ASK_USER_QUESTION_MAX);
|
|
11920
|
+
};
|
|
11921
|
+
var firstPrompt = (payload) => {
|
|
11922
|
+
var _a;
|
|
11923
|
+
return (_a = promptsFromPayload(payload)[0]) != null ? _a : null;
|
|
11924
|
+
};
|
|
11925
|
+
var promptAt = (payload, index) => {
|
|
11926
|
+
var _a;
|
|
11927
|
+
return (_a = promptsFromPayload(payload)[index]) != null ? _a : null;
|
|
11928
|
+
};
|
|
11929
|
+
var applyStyleVars = (root, feature) => {
|
|
11930
|
+
const s = feature.styles;
|
|
11931
|
+
if (!s) return;
|
|
11932
|
+
if (s.sheetBackground) root.style.setProperty("--persona-ask-sheet-bg", s.sheetBackground);
|
|
11933
|
+
if (s.sheetBorder) root.style.setProperty("--persona-ask-sheet-border", s.sheetBorder);
|
|
11934
|
+
if (s.sheetShadow) root.style.setProperty("--persona-ask-sheet-shadow", s.sheetShadow);
|
|
11935
|
+
if (s.pillBackground) root.style.setProperty("--persona-ask-pill-bg", s.pillBackground);
|
|
11936
|
+
if (s.pillBackgroundSelected)
|
|
11937
|
+
root.style.setProperty("--persona-ask-pill-bg-selected", s.pillBackgroundSelected);
|
|
11938
|
+
if (s.pillTextColor) root.style.setProperty("--persona-ask-pill-fg", s.pillTextColor);
|
|
11939
|
+
if (s.pillTextColorSelected)
|
|
11940
|
+
root.style.setProperty("--persona-ask-pill-fg-selected", s.pillTextColorSelected);
|
|
11941
|
+
if (s.pillBorderRadius) root.style.setProperty("--persona-ask-pill-radius", s.pillBorderRadius);
|
|
11942
|
+
if (s.customInputBackground)
|
|
11943
|
+
root.style.setProperty("--persona-ask-input-bg", s.customInputBackground);
|
|
11944
|
+
};
|
|
11945
|
+
var buildAffordance = (layout, multiSelect, index) => {
|
|
11946
|
+
if (layout !== "rows") return null;
|
|
11947
|
+
const wrap = createElement("span", "persona-ask-row-affordance");
|
|
11948
|
+
wrap.setAttribute("aria-hidden", "true");
|
|
11949
|
+
if (multiSelect) {
|
|
11950
|
+
const check = createElement("span", "persona-ask-row-check");
|
|
11951
|
+
wrap.appendChild(check);
|
|
11952
|
+
} else {
|
|
11953
|
+
const badge = createElement("span", "persona-ask-row-badge");
|
|
11954
|
+
badge.textContent = String(index + 1);
|
|
11955
|
+
wrap.appendChild(badge);
|
|
11956
|
+
}
|
|
11957
|
+
return wrap;
|
|
11958
|
+
};
|
|
11959
|
+
var buildPill = (option, index, layout, multiSelect) => {
|
|
11960
|
+
const cls = layout === "rows" ? "persona-ask-pill persona-ask-row persona-pointer-events-auto" : "persona-ask-pill persona-pointer-events-auto";
|
|
11961
|
+
const btn = createElement("button", cls);
|
|
11962
|
+
btn.type = "button";
|
|
11963
|
+
btn.setAttribute("role", multiSelect ? "checkbox" : "button");
|
|
11964
|
+
btn.setAttribute("aria-pressed", "false");
|
|
11965
|
+
btn.setAttribute("data-ask-user-action", "pick");
|
|
11966
|
+
btn.setAttribute("data-option-index", String(index));
|
|
11967
|
+
btn.setAttribute("data-option-label", option.label);
|
|
11968
|
+
if (layout === "rows") {
|
|
11969
|
+
const content = createElement("span", "persona-ask-row-content");
|
|
11970
|
+
const label = createElement("span", "persona-ask-row-label");
|
|
11971
|
+
label.textContent = option.label;
|
|
11972
|
+
content.appendChild(label);
|
|
11973
|
+
if (option.description) {
|
|
11974
|
+
const desc = createElement("span", "persona-ask-row-description");
|
|
11975
|
+
desc.textContent = option.description;
|
|
11976
|
+
content.appendChild(desc);
|
|
11977
|
+
}
|
|
11978
|
+
btn.appendChild(content);
|
|
11979
|
+
const aff = buildAffordance(layout, multiSelect, index);
|
|
11980
|
+
if (aff) btn.appendChild(aff);
|
|
11981
|
+
} else {
|
|
11982
|
+
btn.textContent = option.label;
|
|
11983
|
+
if (option.description) btn.title = option.description;
|
|
11984
|
+
}
|
|
11985
|
+
return btn;
|
|
11986
|
+
};
|
|
11987
|
+
var buildSkeletonPill = (layout) => {
|
|
11988
|
+
const cls = layout === "rows" ? "persona-ask-pill persona-ask-row persona-ask-pill-skeleton persona-pointer-events-none" : "persona-ask-pill persona-ask-pill-skeleton persona-pointer-events-none";
|
|
11989
|
+
const el = createElement("span", cls);
|
|
11990
|
+
el.setAttribute("aria-hidden", "true");
|
|
11991
|
+
return el;
|
|
11992
|
+
};
|
|
11993
|
+
var buildPillList = (prompt, feature, complete, layout) => {
|
|
11994
|
+
var _a, _b, _c;
|
|
11995
|
+
const baseClass = layout === "rows" ? "persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2" : "persona-ask-pills persona-flex persona-flex-wrap persona-gap-2";
|
|
11996
|
+
const list = createElement("div", baseClass);
|
|
11997
|
+
list.setAttribute("role", "group");
|
|
11998
|
+
list.setAttribute("data-ask-pill-list", "true");
|
|
11999
|
+
const multiSelect = !!(prompt == null ? void 0 : prompt.multiSelect);
|
|
12000
|
+
const realOptions = Array.isArray(prompt == null ? void 0 : prompt.options) ? prompt.options : [];
|
|
12001
|
+
const cleanOptions = realOptions.filter((o) => o && typeof o.label === "string" && o.label.length > 0);
|
|
12002
|
+
if (cleanOptions.length === 0 && !complete) {
|
|
12003
|
+
for (let i = 0; i < DEFAULT_SKELETON_PILLS; i++) {
|
|
12004
|
+
list.appendChild(buildSkeletonPill(layout));
|
|
12005
|
+
}
|
|
12006
|
+
return list;
|
|
12007
|
+
}
|
|
12008
|
+
cleanOptions.forEach((option, index) => {
|
|
12009
|
+
list.appendChild(buildPill(option, index, layout, multiSelect));
|
|
12010
|
+
});
|
|
12011
|
+
const allowFreeText = (prompt == null ? void 0 : prompt.allowFreeText) !== false;
|
|
12012
|
+
if (allowFreeText) {
|
|
12013
|
+
const defaultLabel = layout === "rows" ? DEFAULT_FREE_TEXT_LABEL_ROWS : DEFAULT_FREE_TEXT_LABEL_PILLS;
|
|
12014
|
+
if (layout === "rows") {
|
|
12015
|
+
const otherRow = createElement(
|
|
12016
|
+
"div",
|
|
12017
|
+
"persona-ask-pill persona-ask-row persona-ask-row--other persona-ask-pill-custom persona-pointer-events-auto"
|
|
12018
|
+
);
|
|
12019
|
+
otherRow.setAttribute("data-ask-user-action", "focus-free-text");
|
|
12020
|
+
otherRow.setAttribute("data-option-index", String(cleanOptions.length));
|
|
12021
|
+
otherRow.setAttribute("data-ask-other-row", "true");
|
|
12022
|
+
const content = createElement("span", "persona-ask-row-content");
|
|
12023
|
+
const input = document.createElement("input");
|
|
12024
|
+
input.type = "text";
|
|
12025
|
+
input.className = "persona-ask-row-input persona-flex-1 persona-pointer-events-auto";
|
|
12026
|
+
input.placeholder = (_a = feature.freeTextPlaceholder) != null ? _a : DEFAULT_FREE_TEXT_PLACEHOLDER;
|
|
12027
|
+
input.setAttribute("data-ask-free-text-input", "true");
|
|
12028
|
+
input.setAttribute(
|
|
12029
|
+
"aria-label",
|
|
12030
|
+
(_b = feature.freeTextLabel) != null ? _b : defaultLabel
|
|
12031
|
+
);
|
|
12032
|
+
content.appendChild(input);
|
|
12033
|
+
otherRow.appendChild(content);
|
|
12034
|
+
const aff = buildAffordance(layout, multiSelect, cleanOptions.length);
|
|
12035
|
+
if (aff) otherRow.appendChild(aff);
|
|
12036
|
+
list.appendChild(otherRow);
|
|
12037
|
+
} else {
|
|
12038
|
+
const freeBtn = createElement(
|
|
12039
|
+
"button",
|
|
12040
|
+
"persona-ask-pill persona-ask-pill-custom persona-pointer-events-auto"
|
|
12041
|
+
);
|
|
12042
|
+
freeBtn.type = "button";
|
|
12043
|
+
freeBtn.setAttribute("data-ask-user-action", "open-free-text");
|
|
12044
|
+
freeBtn.textContent = (_c = feature.freeTextLabel) != null ? _c : defaultLabel;
|
|
12045
|
+
list.appendChild(freeBtn);
|
|
12046
|
+
}
|
|
12047
|
+
}
|
|
12048
|
+
return list;
|
|
12049
|
+
};
|
|
12050
|
+
var buildFreeTextRow = (feature, layout) => {
|
|
12051
|
+
var _a, _b;
|
|
12052
|
+
const cls = layout === "rows" ? "persona-ask-free-text persona-ask-free-text--rows persona-flex persona-gap-2 persona-mt-2" : "persona-ask-free-text persona-hidden persona-flex persona-gap-2 persona-mt-2";
|
|
12053
|
+
const row = createElement("div", cls);
|
|
12054
|
+
row.setAttribute("data-ask-free-text-row", "true");
|
|
12055
|
+
const input = document.createElement("input");
|
|
12056
|
+
input.type = "text";
|
|
12057
|
+
input.className = "persona-ask-free-text-input persona-flex-1 persona-pointer-events-auto";
|
|
12058
|
+
input.placeholder = (_a = feature.freeTextPlaceholder) != null ? _a : DEFAULT_FREE_TEXT_PLACEHOLDER;
|
|
12059
|
+
input.setAttribute("data-ask-free-text-input", "true");
|
|
12060
|
+
row.appendChild(input);
|
|
12061
|
+
if (layout !== "rows") {
|
|
12062
|
+
const submit = createElement(
|
|
12063
|
+
"button",
|
|
12064
|
+
"persona-ask-free-text-submit persona-pointer-events-auto"
|
|
12065
|
+
);
|
|
12066
|
+
submit.type = "button";
|
|
12067
|
+
submit.textContent = (_b = feature.submitLabel) != null ? _b : DEFAULT_SUBMIT_LABEL;
|
|
12068
|
+
submit.setAttribute("data-ask-user-action", "submit-free-text");
|
|
12069
|
+
row.appendChild(submit);
|
|
12070
|
+
}
|
|
12071
|
+
return row;
|
|
12072
|
+
};
|
|
12073
|
+
var buildMultiSelectActions = (feature) => {
|
|
12074
|
+
var _a;
|
|
12075
|
+
const row = createElement(
|
|
12076
|
+
"div",
|
|
12077
|
+
"persona-ask-multi-actions persona-flex persona-justify-end persona-mt-2"
|
|
12078
|
+
);
|
|
12079
|
+
row.setAttribute("data-ask-multi-actions", "true");
|
|
12080
|
+
const submit = createElement(
|
|
12081
|
+
"button",
|
|
12082
|
+
"persona-ask-multi-submit persona-pointer-events-auto"
|
|
12083
|
+
);
|
|
12084
|
+
submit.type = "button";
|
|
12085
|
+
submit.textContent = (_a = feature.submitLabel) != null ? _a : DEFAULT_SUBMIT_LABEL;
|
|
12086
|
+
submit.setAttribute("data-ask-user-action", "submit-multi");
|
|
12087
|
+
submit.disabled = true;
|
|
12088
|
+
row.appendChild(submit);
|
|
12089
|
+
return row;
|
|
12090
|
+
};
|
|
12091
|
+
var buildNavRow = (index, count, feature) => {
|
|
12092
|
+
var _a, _b, _c, _d;
|
|
12093
|
+
const row = createElement(
|
|
12094
|
+
"div",
|
|
12095
|
+
"persona-ask-nav persona-flex persona-justify-between persona-items-center persona-gap-2 persona-mt-2"
|
|
12096
|
+
);
|
|
12097
|
+
row.setAttribute("data-ask-nav-row", "true");
|
|
12098
|
+
const back = createElement(
|
|
12099
|
+
"button",
|
|
12100
|
+
"persona-ask-nav-back persona-pointer-events-auto"
|
|
12101
|
+
);
|
|
12102
|
+
back.type = "button";
|
|
12103
|
+
back.textContent = (_a = feature.backLabel) != null ? _a : DEFAULT_BACK_LABEL;
|
|
12104
|
+
back.setAttribute("data-ask-user-action", "back");
|
|
12105
|
+
back.disabled = index === 0;
|
|
12106
|
+
row.appendChild(back);
|
|
12107
|
+
const rightGroup = createElement(
|
|
12108
|
+
"div",
|
|
12109
|
+
"persona-ask-nav-right persona-flex persona-items-center persona-gap-2"
|
|
12110
|
+
);
|
|
12111
|
+
const skip = createElement(
|
|
12112
|
+
"button",
|
|
12113
|
+
"persona-ask-nav-skip persona-pointer-events-auto"
|
|
12114
|
+
);
|
|
12115
|
+
skip.type = "button";
|
|
12116
|
+
skip.textContent = (_b = feature.skipLabel) != null ? _b : DEFAULT_SKIP_LABEL;
|
|
12117
|
+
skip.setAttribute("data-ask-user-action", "skip");
|
|
12118
|
+
rightGroup.appendChild(skip);
|
|
12119
|
+
const next = createElement(
|
|
12120
|
+
"button",
|
|
12121
|
+
"persona-ask-nav-next persona-pointer-events-auto"
|
|
12122
|
+
);
|
|
12123
|
+
next.type = "button";
|
|
12124
|
+
const isFinal = index === count - 1;
|
|
12125
|
+
next.textContent = isFinal ? (_c = feature.submitAllLabel) != null ? _c : DEFAULT_SUBMIT_ALL_LABEL : (_d = feature.nextLabel) != null ? _d : DEFAULT_NEXT_LABEL;
|
|
12126
|
+
next.setAttribute("data-ask-user-action", isFinal ? "submit-all" : "next");
|
|
12127
|
+
next.disabled = true;
|
|
12128
|
+
rightGroup.appendChild(next);
|
|
12129
|
+
row.appendChild(rightGroup);
|
|
12130
|
+
return row;
|
|
12131
|
+
};
|
|
12132
|
+
var readAnswersFromSheet = (sheet) => {
|
|
12133
|
+
const raw = sheet.getAttribute(ATTR_ANSWERS);
|
|
12134
|
+
if (!raw) return {};
|
|
12135
|
+
try {
|
|
12136
|
+
const parsed = JSON.parse(raw);
|
|
12137
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
12138
|
+
} catch {
|
|
12139
|
+
return {};
|
|
12140
|
+
}
|
|
12141
|
+
};
|
|
12142
|
+
var writeAnswersToSheet = (sheet, answers) => {
|
|
12143
|
+
sheet.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
|
|
12144
|
+
};
|
|
12145
|
+
var getCurrentIndex = (sheet) => {
|
|
12146
|
+
var _a;
|
|
12147
|
+
const raw = Number((_a = sheet.getAttribute(ATTR_CURRENT_INDEX)) != null ? _a : "0");
|
|
12148
|
+
return Number.isFinite(raw) ? Math.max(0, Math.floor(raw)) : 0;
|
|
12149
|
+
};
|
|
12150
|
+
var setCurrentIndex = (sheet, index) => {
|
|
12151
|
+
sheet.setAttribute(ATTR_CURRENT_INDEX, String(Math.max(0, Math.floor(index))));
|
|
12152
|
+
};
|
|
12153
|
+
var getQuestionCount = (sheet) => {
|
|
12154
|
+
var _a;
|
|
12155
|
+
const raw = Number((_a = sheet.getAttribute(ATTR_QUESTION_COUNT)) != null ? _a : "1");
|
|
12156
|
+
return Number.isFinite(raw) ? Math.max(1, Math.floor(raw)) : 1;
|
|
12157
|
+
};
|
|
12158
|
+
var isGroupedSheet = (sheet) => {
|
|
12159
|
+
return sheet.getAttribute(ATTR_GROUPED) === "true";
|
|
12160
|
+
};
|
|
12161
|
+
var restoreAnswersFromMessage = (message, prompts) => {
|
|
12162
|
+
var _a;
|
|
12163
|
+
const stored = (_a = message.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswers;
|
|
12164
|
+
if (!stored || typeof stored !== "object") return {};
|
|
12165
|
+
const result = {};
|
|
12166
|
+
prompts.forEach((p, i) => {
|
|
12167
|
+
const q = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
12168
|
+
if (q && Object.prototype.hasOwnProperty.call(stored, q)) {
|
|
12169
|
+
const v = stored[q];
|
|
12170
|
+
if (typeof v === "string" || Array.isArray(v)) {
|
|
12171
|
+
result[i] = v;
|
|
12172
|
+
}
|
|
12173
|
+
}
|
|
12174
|
+
});
|
|
12175
|
+
return result;
|
|
12176
|
+
};
|
|
12177
|
+
var restoreIndexFromMessage = (message, count) => {
|
|
12178
|
+
var _a;
|
|
12179
|
+
const stored = (_a = message.agentMetadata) == null ? void 0 : _a.askUserQuestionIndex;
|
|
12180
|
+
if (typeof stored !== "number" || !Number.isFinite(stored)) return 0;
|
|
12181
|
+
return Math.max(0, Math.min(count - 1, Math.floor(stored)));
|
|
12182
|
+
};
|
|
12183
|
+
var buildStructuredAnswers = (sheet, message) => {
|
|
12184
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12185
|
+
const prompts = promptsFromPayload(payload);
|
|
12186
|
+
const indexed = readAnswersFromSheet(sheet);
|
|
12187
|
+
const result = {};
|
|
12188
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12189
|
+
prompts.forEach((p, i) => {
|
|
12190
|
+
const q = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
12191
|
+
if (!q) return;
|
|
12192
|
+
if (seen.has(q) && typeof console !== "undefined") {
|
|
12193
|
+
console.warn(`[AgentWidget] ask_user_question has duplicate question text "${q}"; later answer wins.`);
|
|
12194
|
+
}
|
|
12195
|
+
seen.add(q);
|
|
12196
|
+
if (Object.prototype.hasOwnProperty.call(indexed, i)) {
|
|
12197
|
+
result[q] = indexed[i];
|
|
12198
|
+
}
|
|
12199
|
+
});
|
|
12200
|
+
return result;
|
|
12201
|
+
};
|
|
12202
|
+
var applySelectionState = (sheet) => {
|
|
12203
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12204
|
+
const currentIndex = getCurrentIndex(sheet);
|
|
12205
|
+
const stored = answers[currentIndex];
|
|
12206
|
+
const selected = /* @__PURE__ */ new Set();
|
|
12207
|
+
if (typeof stored === "string") selected.add(stored);
|
|
12208
|
+
else if (Array.isArray(stored)) stored.forEach((s) => selected.add(s));
|
|
12209
|
+
const pills = sheet.querySelectorAll('[data-ask-user-action="pick"][data-option-label]');
|
|
12210
|
+
pills.forEach((pill) => {
|
|
12211
|
+
var _a;
|
|
12212
|
+
const label = (_a = pill.getAttribute("data-option-label")) != null ? _a : "";
|
|
12213
|
+
const on = selected.has(label);
|
|
12214
|
+
pill.setAttribute("aria-pressed", on ? "true" : "false");
|
|
12215
|
+
pill.classList.toggle("persona-ask-pill-selected", on);
|
|
12216
|
+
});
|
|
12217
|
+
const realPillLabels = new Set(
|
|
12218
|
+
Array.from(pills).map((p) => {
|
|
12219
|
+
var _a;
|
|
12220
|
+
return (_a = p.getAttribute("data-option-label")) != null ? _a : "";
|
|
12221
|
+
})
|
|
12222
|
+
);
|
|
12223
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
12224
|
+
if (freeInput) {
|
|
12225
|
+
if (typeof stored === "string" && stored.length > 0 && !realPillLabels.has(stored)) {
|
|
12226
|
+
freeInput.value = stored;
|
|
12227
|
+
const freeRow = freeInput.closest('[data-ask-free-text-row="true"]');
|
|
12228
|
+
freeRow == null ? void 0 : freeRow.classList.remove("persona-hidden");
|
|
12229
|
+
} else {
|
|
12230
|
+
freeInput.value = "";
|
|
12231
|
+
}
|
|
12232
|
+
}
|
|
12233
|
+
};
|
|
12234
|
+
var syncNavState = (sheet) => {
|
|
12235
|
+
if (!isGroupedSheet(sheet)) return;
|
|
12236
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12237
|
+
const currentIndex = getCurrentIndex(sheet);
|
|
12238
|
+
const v = answers[currentIndex];
|
|
12239
|
+
const hasAnswer = typeof v === "string" && v.length > 0 || Array.isArray(v) && v.length > 0;
|
|
12240
|
+
const next = sheet.querySelector(
|
|
12241
|
+
'[data-ask-user-action="next"], [data-ask-user-action="submit-all"]'
|
|
12242
|
+
);
|
|
12243
|
+
if (next) next.disabled = !hasAnswer;
|
|
12244
|
+
const multi = sheet.querySelector('[data-ask-user-action="submit-multi"]');
|
|
12245
|
+
if (multi) {
|
|
12246
|
+
const labels = Array.from(
|
|
12247
|
+
sheet.querySelectorAll('[aria-pressed="true"][data-option-label]')
|
|
12248
|
+
);
|
|
12249
|
+
multi.disabled = labels.length === 0;
|
|
12250
|
+
}
|
|
12251
|
+
};
|
|
12252
|
+
var renderCurrentPage = (sheet, message, config) => {
|
|
12253
|
+
const feature = resolveFeature(config);
|
|
12254
|
+
const layout = getLayout(sheet);
|
|
12255
|
+
const { payload, complete } = parseAskUserQuestionPayload(message);
|
|
12256
|
+
const grouped = isGroupedSheet(sheet);
|
|
12257
|
+
const index = getCurrentIndex(sheet);
|
|
12258
|
+
const count = getQuestionCount(sheet);
|
|
12259
|
+
const prompt = grouped ? promptAt(payload, index) : firstPrompt(payload);
|
|
12260
|
+
const multiSelect = !!(prompt == null ? void 0 : prompt.multiSelect);
|
|
12261
|
+
const stepInline = sheet.querySelector('[data-ask-step-inline="true"]');
|
|
12262
|
+
if (stepInline) {
|
|
12263
|
+
stepInline.textContent = grouped ? `${index + 1}/${count}` : "";
|
|
12264
|
+
}
|
|
12265
|
+
const oldStepper = sheet.querySelector('[data-ask-stepper="true"]');
|
|
12266
|
+
if (oldStepper) oldStepper.remove();
|
|
12267
|
+
const qText = sheet.querySelector('[data-ask-question="true"]');
|
|
12268
|
+
if (qText) {
|
|
12269
|
+
const text = typeof (prompt == null ? void 0 : prompt.question) === "string" ? prompt.question : "";
|
|
12270
|
+
qText.textContent = text;
|
|
12271
|
+
qText.classList.toggle("persona-ask-question-skeleton", !text && !complete);
|
|
12272
|
+
}
|
|
12273
|
+
const pillList = sheet.querySelector('[data-ask-pill-list="true"]');
|
|
12274
|
+
if (pillList) {
|
|
12275
|
+
const fresh = buildPillList(prompt, feature, complete, layout);
|
|
12276
|
+
pillList.replaceWith(fresh);
|
|
12277
|
+
}
|
|
12278
|
+
if (layout !== "rows") {
|
|
12279
|
+
const oldFree = sheet.querySelector('[data-ask-free-text-row="true"]');
|
|
12280
|
+
if (oldFree) oldFree.replaceWith(buildFreeTextRow(feature, layout));
|
|
12281
|
+
}
|
|
12282
|
+
const oldMulti = sheet.querySelector('[data-ask-multi-actions="true"]');
|
|
12283
|
+
if (!grouped && multiSelect && !oldMulti) {
|
|
12284
|
+
sheet.appendChild(buildMultiSelectActions(feature));
|
|
12285
|
+
} else if ((!multiSelect || grouped) && oldMulti) {
|
|
12286
|
+
oldMulti.remove();
|
|
12287
|
+
}
|
|
12288
|
+
sheet.setAttribute("data-multi-select", multiSelect ? "true" : "false");
|
|
12289
|
+
const oldNav = sheet.querySelector('[data-ask-nav-row="true"]');
|
|
12290
|
+
if (grouped) {
|
|
12291
|
+
const fresh = buildNavRow(index, count, feature);
|
|
12292
|
+
if (oldNav) oldNav.replaceWith(fresh);
|
|
12293
|
+
else sheet.appendChild(fresh);
|
|
12294
|
+
} else if (oldNav) {
|
|
12295
|
+
oldNav.remove();
|
|
12296
|
+
}
|
|
12297
|
+
applySelectionState(sheet);
|
|
12298
|
+
syncNavState(sheet);
|
|
12299
|
+
};
|
|
12300
|
+
var buildSheet = (message, config, payload) => {
|
|
12301
|
+
const feature = resolveFeature(config);
|
|
12302
|
+
const layout = resolveLayout(feature);
|
|
12303
|
+
const toolCallId = message.toolCall.id;
|
|
12304
|
+
const prompts = promptsFromPayload(payload);
|
|
12305
|
+
const count = Math.max(1, prompts.length);
|
|
12306
|
+
const grouped = count > 1;
|
|
12307
|
+
const initialAnswers = restoreAnswersFromMessage(message, prompts);
|
|
12308
|
+
const initialIndex = grouped ? restoreIndexFromMessage(message, count) : 0;
|
|
12309
|
+
const sheet = createElement(
|
|
12310
|
+
"div",
|
|
12311
|
+
[
|
|
12312
|
+
"persona-ask-sheet",
|
|
12313
|
+
`persona-ask-sheet--${layout}`,
|
|
12314
|
+
"persona-pointer-events-auto",
|
|
12315
|
+
"persona-ask-sheet-enter"
|
|
12316
|
+
].join(" ")
|
|
12317
|
+
);
|
|
12318
|
+
sheet.setAttribute(SHEET_SENTINEL, toolCallId);
|
|
12319
|
+
sheet.setAttribute("data-tool-call-id", toolCallId);
|
|
12320
|
+
sheet.setAttribute("data-message-id", message.id);
|
|
12321
|
+
sheet.setAttribute(ATTR_QUESTION_COUNT, String(count));
|
|
12322
|
+
sheet.setAttribute(ATTR_CURRENT_INDEX, String(initialIndex));
|
|
12323
|
+
sheet.setAttribute(ATTR_GROUPED, grouped ? "true" : "false");
|
|
12324
|
+
sheet.setAttribute(ATTR_LAYOUT, layout);
|
|
12325
|
+
writeAnswersToSheet(sheet, initialAnswers);
|
|
12326
|
+
sheet.setAttribute("role", "group");
|
|
12327
|
+
sheet.setAttribute("aria-label", "Suggested answers");
|
|
12328
|
+
if (feature.slideInMs !== void 0) {
|
|
12329
|
+
sheet.style.setProperty("--persona-ask-sheet-duration", `${feature.slideInMs}ms`);
|
|
12330
|
+
}
|
|
12331
|
+
applyStyleVars(sheet, feature);
|
|
12332
|
+
const header = createElement(
|
|
12333
|
+
"div",
|
|
12334
|
+
"persona-ask-sheet-header persona-flex persona-items-center persona-gap-3"
|
|
12335
|
+
);
|
|
12336
|
+
const qText = createElement("div", "persona-ask-sheet-question persona-flex-1");
|
|
12337
|
+
qText.setAttribute("data-ask-question", "true");
|
|
12338
|
+
qText.textContent = "";
|
|
12339
|
+
header.appendChild(qText);
|
|
12340
|
+
const stepInline = createElement(
|
|
12341
|
+
"span",
|
|
12342
|
+
"persona-ask-sheet-step-inline"
|
|
12343
|
+
);
|
|
12344
|
+
stepInline.setAttribute("data-ask-step-inline", "true");
|
|
12345
|
+
stepInline.textContent = "";
|
|
12346
|
+
header.appendChild(stepInline);
|
|
12347
|
+
sheet.appendChild(header);
|
|
12348
|
+
const skeletonClass = layout === "rows" ? "persona-ask-pills persona-ask-pills--rows persona-flex persona-flex-col persona-gap-2" : "persona-ask-pills persona-flex persona-flex-wrap persona-gap-2";
|
|
12349
|
+
const list = createElement("div", skeletonClass);
|
|
12350
|
+
list.setAttribute("data-ask-pill-list", "true");
|
|
12351
|
+
list.setAttribute("role", "group");
|
|
12352
|
+
sheet.appendChild(list);
|
|
12353
|
+
if (layout !== "rows") {
|
|
12354
|
+
sheet.appendChild(buildFreeTextRow(feature, layout));
|
|
12355
|
+
}
|
|
12356
|
+
renderCurrentPage(sheet, message, config);
|
|
12357
|
+
requestAnimationFrame(() => {
|
|
12358
|
+
requestAnimationFrame(() => sheet.classList.remove("persona-ask-sheet-enter"));
|
|
12359
|
+
});
|
|
12360
|
+
return sheet;
|
|
12361
|
+
};
|
|
12362
|
+
var syncSheetFromMessage = (sheet, message, config) => {
|
|
12363
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12364
|
+
const newCount = Math.max(1, promptsFromPayload(payload).length);
|
|
12365
|
+
if (newCount > getQuestionCount(sheet)) {
|
|
12366
|
+
sheet.setAttribute(ATTR_QUESTION_COUNT, String(newCount));
|
|
12367
|
+
if (newCount > 1 && !isGroupedSheet(sheet)) {
|
|
12368
|
+
sheet.setAttribute(ATTR_GROUPED, "true");
|
|
12369
|
+
}
|
|
12370
|
+
}
|
|
12371
|
+
renderCurrentPage(sheet, message, config);
|
|
12372
|
+
};
|
|
12373
|
+
var ensureAskUserQuestionSheet = (message, config, overlay) => {
|
|
12374
|
+
if (!overlay) return;
|
|
12375
|
+
if (!isAskUserQuestionMessage(message)) return;
|
|
12376
|
+
const feature = resolveFeature(config);
|
|
12377
|
+
if (feature.enabled === false) return;
|
|
12378
|
+
const toolCallId = message.toolCall.id;
|
|
12379
|
+
const siblings = overlay.querySelectorAll(`[${SHEET_SENTINEL}]`);
|
|
12380
|
+
siblings.forEach((el) => {
|
|
12381
|
+
if (el.getAttribute(SHEET_SENTINEL) !== toolCallId) {
|
|
12382
|
+
el.remove();
|
|
12383
|
+
}
|
|
12384
|
+
});
|
|
12385
|
+
const existing = overlay.querySelector(
|
|
12386
|
+
`[${SHEET_SENTINEL}="${escapeAttrValue(toolCallId)}"]`
|
|
12387
|
+
);
|
|
12388
|
+
if (existing) {
|
|
12389
|
+
syncSheetFromMessage(existing, message, config);
|
|
12390
|
+
return;
|
|
12391
|
+
}
|
|
12392
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12393
|
+
const sheet = buildSheet(message, config, payload);
|
|
12394
|
+
overlay.appendChild(sheet);
|
|
12395
|
+
};
|
|
12396
|
+
var removeAskUserQuestionSheet = (overlay, toolCallId) => {
|
|
12397
|
+
if (!overlay) return;
|
|
12398
|
+
const selector = toolCallId ? `[${SHEET_SENTINEL}="${escapeAttrValue(toolCallId)}"]` : `[${SHEET_SENTINEL}]`;
|
|
12399
|
+
const sheets = overlay.querySelectorAll(selector);
|
|
12400
|
+
sheets.forEach((sheet) => {
|
|
12401
|
+
sheet.classList.add("persona-ask-sheet-leave");
|
|
12402
|
+
const duration = Number.parseInt(
|
|
12403
|
+
getComputedStyle(sheet).getPropertyValue("--persona-ask-sheet-duration") || "180",
|
|
12404
|
+
10
|
|
12405
|
+
);
|
|
12406
|
+
const remove = () => sheet.remove();
|
|
12407
|
+
setTimeout(remove, Number.isFinite(duration) ? duration : 180);
|
|
12408
|
+
});
|
|
12409
|
+
};
|
|
12410
|
+
var getSelectedLabels = (sheet) => {
|
|
12411
|
+
return Array.from(
|
|
12412
|
+
sheet.querySelectorAll('[aria-pressed="true"][data-option-label]')
|
|
12413
|
+
).map((el) => el.getAttribute("data-option-label")).filter((label) => typeof label === "string" && label.length > 0);
|
|
12414
|
+
};
|
|
12415
|
+
var setCurrentAnswer = (sheet, answer) => {
|
|
12416
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12417
|
+
const idx = getCurrentIndex(sheet);
|
|
12418
|
+
if (typeof answer === "string" && answer.length === 0) {
|
|
12419
|
+
delete answers[idx];
|
|
12420
|
+
} else if (Array.isArray(answer) && answer.length === 0) {
|
|
12421
|
+
delete answers[idx];
|
|
12422
|
+
} else {
|
|
12423
|
+
answers[idx] = answer;
|
|
12424
|
+
}
|
|
12425
|
+
writeAnswersToSheet(sheet, answers);
|
|
12426
|
+
applySelectionState(sheet);
|
|
12427
|
+
syncNavState(sheet);
|
|
12428
|
+
};
|
|
12429
|
+
var navigateToPage = (sheet, message, config, index) => {
|
|
12430
|
+
const count = getQuestionCount(sheet);
|
|
12431
|
+
const clamped = Math.max(0, Math.min(count - 1, index));
|
|
12432
|
+
setCurrentIndex(sheet, clamped);
|
|
12433
|
+
renderCurrentPage(sheet, message, config);
|
|
12434
|
+
};
|
|
12435
|
+
|
|
11595
12436
|
// src/components/approval-bubble.ts
|
|
11596
12437
|
var createApprovalBubble = (message, config) => {
|
|
11597
12438
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -14000,6 +14841,10 @@ var sanitizeMessages = (messages) => messages.map((message) => ({
|
|
|
14000
14841
|
...message,
|
|
14001
14842
|
streaming: false
|
|
14002
14843
|
}));
|
|
14844
|
+
var sanitizeArtifacts = (artifacts) => artifacts.map((artifact) => ({
|
|
14845
|
+
...artifact,
|
|
14846
|
+
status: "complete"
|
|
14847
|
+
}));
|
|
14003
14848
|
var createLocalStorageAdapter = (key = "persona-state") => {
|
|
14004
14849
|
const getStorage = () => {
|
|
14005
14850
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
@@ -14019,7 +14864,8 @@ var createLocalStorageAdapter = (key = "persona-state") => {
|
|
|
14019
14864
|
try {
|
|
14020
14865
|
const payload = {
|
|
14021
14866
|
...state,
|
|
14022
|
-
messages: state.messages ? sanitizeMessages(state.messages) : void 0
|
|
14867
|
+
messages: state.messages ? sanitizeMessages(state.messages) : void 0,
|
|
14868
|
+
artifacts: state.artifacts ? sanitizeArtifacts(state.artifacts) : void 0
|
|
14023
14869
|
};
|
|
14024
14870
|
storage.setItem(key, JSON.stringify(payload));
|
|
14025
14871
|
} catch (error) {
|
|
@@ -14043,7 +14889,7 @@ var createLocalStorageAdapter = (key = "persona-state") => {
|
|
|
14043
14889
|
};
|
|
14044
14890
|
|
|
14045
14891
|
// src/utils/component-parser.ts
|
|
14046
|
-
var
|
|
14892
|
+
var import_partial_json3 = require("partial-json");
|
|
14047
14893
|
|
|
14048
14894
|
// src/utils/component-middleware.ts
|
|
14049
14895
|
function renderComponentDirective(directive, options) {
|
|
@@ -14519,7 +15365,7 @@ function buildDropOverlay(dropCfg) {
|
|
|
14519
15365
|
return overlay;
|
|
14520
15366
|
}
|
|
14521
15367
|
var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
14522
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O;
|
|
15368
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q;
|
|
14523
15369
|
if (mount == null) {
|
|
14524
15370
|
throw new Error(
|
|
14525
15371
|
'createAgentExperience: mount must be a non-null HTMLElement (e.g. pass document.getElementById("my-root") after the node exists).'
|
|
@@ -14578,6 +15424,13 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14578
15424
|
if ((_b = processedState.messages) == null ? void 0 : _b.length) {
|
|
14579
15425
|
config = { ...config, initialMessages: processedState.messages };
|
|
14580
15426
|
}
|
|
15427
|
+
if ((_c = processedState.artifacts) == null ? void 0 : _c.length) {
|
|
15428
|
+
config = {
|
|
15429
|
+
...config,
|
|
15430
|
+
initialArtifacts: processedState.artifacts,
|
|
15431
|
+
initialSelectedArtifactId: (_d = processedState.selectedArtifactId) != null ? _d : null
|
|
15432
|
+
};
|
|
15433
|
+
}
|
|
14581
15434
|
}
|
|
14582
15435
|
} catch (error) {
|
|
14583
15436
|
if (typeof console !== "undefined") {
|
|
@@ -14587,7 +15440,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14587
15440
|
} else if (config.onStateLoaded) {
|
|
14588
15441
|
try {
|
|
14589
15442
|
const processedState = applyStateLoadedHook({ messages: [], metadata: {} });
|
|
14590
|
-
if ((
|
|
15443
|
+
if ((_e = processedState.messages) == null ? void 0 : _e.length) {
|
|
14591
15444
|
config = { ...config, initialMessages: processedState.messages };
|
|
14592
15445
|
}
|
|
14593
15446
|
} catch (error) {
|
|
@@ -14614,12 +15467,12 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14614
15467
|
documentRef: typeof document !== "undefined" ? document : null
|
|
14615
15468
|
});
|
|
14616
15469
|
actionManager.syncFromMetadata();
|
|
14617
|
-
let launcherEnabled = (
|
|
14618
|
-
let autoExpand = (
|
|
14619
|
-
const autoFocusInput = (
|
|
15470
|
+
let launcherEnabled = (_g = (_f = config.launcher) == null ? void 0 : _f.enabled) != null ? _g : true;
|
|
15471
|
+
let autoExpand = (_i = (_h = config.launcher) == null ? void 0 : _h.autoExpand) != null ? _i : false;
|
|
15472
|
+
const autoFocusInput = (_j = config.autoFocusInput) != null ? _j : false;
|
|
14620
15473
|
let prevAutoExpand = autoExpand;
|
|
14621
15474
|
let prevLauncherEnabled = launcherEnabled;
|
|
14622
|
-
let prevHeaderLayout = (
|
|
15475
|
+
let prevHeaderLayout = (_l = (_k = config.layout) == null ? void 0 : _k.header) == null ? void 0 : _l.layout;
|
|
14623
15476
|
let wasMobileFullscreen = false;
|
|
14624
15477
|
let open = launcherEnabled ? autoExpand : true;
|
|
14625
15478
|
let pendingResubmit = false;
|
|
@@ -14639,14 +15492,14 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14639
15492
|
}, 1e4);
|
|
14640
15493
|
};
|
|
14641
15494
|
let postprocess = buildPostprocessor(config, actionManager, handleResubmitRequested);
|
|
14642
|
-
let showReasoning = (
|
|
14643
|
-
let showToolCalls = (
|
|
14644
|
-
let showEventStreamToggle = (
|
|
14645
|
-
let scrollToBottomFeature = (
|
|
14646
|
-
const persistKeyPrefix = (
|
|
15495
|
+
let showReasoning = (_n = (_m = config.features) == null ? void 0 : _m.showReasoning) != null ? _n : true;
|
|
15496
|
+
let showToolCalls = (_p = (_o = config.features) == null ? void 0 : _o.showToolCalls) != null ? _p : true;
|
|
15497
|
+
let showEventStreamToggle = (_r = (_q = config.features) == null ? void 0 : _q.showEventStreamToggle) != null ? _r : false;
|
|
15498
|
+
let scrollToBottomFeature = (_t = (_s = config.features) == null ? void 0 : _s.scrollToBottom) != null ? _t : {};
|
|
15499
|
+
const persistKeyPrefix = (_v = typeof config.persistState === "object" ? (_u = config.persistState) == null ? void 0 : _u.keyPrefix : void 0) != null ? _v : "persona-";
|
|
14647
15500
|
const eventStreamDbName = `${persistKeyPrefix}event-stream`;
|
|
14648
15501
|
let eventStreamStore = showEventStreamToggle ? new EventStreamStore(eventStreamDbName) : null;
|
|
14649
|
-
const eventStreamMaxEvents = (
|
|
15502
|
+
const eventStreamMaxEvents = (_y = (_x = (_w = config.features) == null ? void 0 : _w.eventStream) == null ? void 0 : _x.maxEvents) != null ? _y : 2e3;
|
|
14650
15503
|
let eventStreamBuffer = showEventStreamToggle ? new EventStreamBuffer(eventStreamMaxEvents, eventStreamStore) : null;
|
|
14651
15504
|
let eventStreamView = null;
|
|
14652
15505
|
let eventStreamVisible = false;
|
|
@@ -14683,7 +15536,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14683
15536
|
(_b2 = (_a2 = config.messageActions) == null ? void 0 : _a2.onFeedback) == null ? void 0 : _b2.call(_a2, feedback);
|
|
14684
15537
|
}
|
|
14685
15538
|
};
|
|
14686
|
-
const statusConfig = (
|
|
15539
|
+
const statusConfig = (_z = config.statusIndicator) != null ? _z : {};
|
|
14687
15540
|
const _getStatusText = (status) => {
|
|
14688
15541
|
var _a2, _b2, _c2, _d2;
|
|
14689
15542
|
if (status === "idle") return (_a2 = statusConfig.idleText) != null ? _a2 : statusCopy.idle;
|
|
@@ -14864,7 +15717,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14864
15717
|
};
|
|
14865
15718
|
let eventStreamToggleBtn = null;
|
|
14866
15719
|
if (showEventStreamToggle) {
|
|
14867
|
-
const esClassNames = (
|
|
15720
|
+
const esClassNames = (_B = (_A = config.features) == null ? void 0 : _A.eventStream) == null ? void 0 : _B.classNames;
|
|
14868
15721
|
const toggleBtnClasses = "persona-inline-flex persona-items-center persona-justify-center persona-rounded-full hover:persona-opacity-80 persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-1" + ((esClassNames == null ? void 0 : esClassNames.toggleButton) ? " " + esClassNames.toggleButton : "");
|
|
14869
15722
|
eventStreamToggleBtn = createElement("button", toggleBtnClasses);
|
|
14870
15723
|
eventStreamToggleBtn.style.width = "28px";
|
|
@@ -14960,7 +15813,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14960
15813
|
config.agent = { ...config.agent, model: modelId };
|
|
14961
15814
|
}
|
|
14962
15815
|
},
|
|
14963
|
-
onVoiceToggle: ((
|
|
15816
|
+
onVoiceToggle: ((_C = config.voiceRecognition) == null ? void 0 : _C.enabled) === true ? () => {
|
|
14964
15817
|
composerVoiceBridge == null ? void 0 : composerVoiceBridge();
|
|
14965
15818
|
} : void 0
|
|
14966
15819
|
});
|
|
@@ -14999,7 +15852,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14999
15852
|
};
|
|
15000
15853
|
ensureComposerAttachmentSurface(footer);
|
|
15001
15854
|
bindComposerRefsFromFooter(footer);
|
|
15002
|
-
const contentMaxWidth = (
|
|
15855
|
+
const contentMaxWidth = (_D = config.layout) == null ? void 0 : _D.contentMaxWidth;
|
|
15003
15856
|
if (contentMaxWidth && composerForm) {
|
|
15004
15857
|
composerForm.style.maxWidth = contentMaxWidth;
|
|
15005
15858
|
composerForm.style.marginLeft = "auto";
|
|
@@ -15015,7 +15868,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15015
15868
|
attachmentPreviewsContainer.style.marginLeft = "auto";
|
|
15016
15869
|
attachmentPreviewsContainer.style.marginRight = "auto";
|
|
15017
15870
|
}
|
|
15018
|
-
if (((
|
|
15871
|
+
if (((_E = config.attachments) == null ? void 0 : _E.enabled) && attachmentInput && attachmentPreviewsContainer) {
|
|
15019
15872
|
attachmentManager = AttachmentManager.fromConfig(config.attachments);
|
|
15020
15873
|
attachmentManager.setPreviewsContainer(attachmentPreviewsContainer);
|
|
15021
15874
|
attachmentInput.addEventListener("change", (e) => {
|
|
@@ -15327,6 +16180,300 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15327
16180
|
event.preventDefault();
|
|
15328
16181
|
target.click();
|
|
15329
16182
|
});
|
|
16183
|
+
const askUserOverlay = panelElements.composerOverlay;
|
|
16184
|
+
const submitAskUserAnswer = (sheet, text, meta) => {
|
|
16185
|
+
var _a2, _b2, _c2, _d2;
|
|
16186
|
+
const trimmed = text.trim();
|
|
16187
|
+
if (!trimmed || !sessionRef.current) return;
|
|
16188
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16189
|
+
const isFreeText = meta.source === "free-text";
|
|
16190
|
+
mount.dispatchEvent(
|
|
16191
|
+
new CustomEvent("persona:askUserQuestion:answered", {
|
|
16192
|
+
detail: {
|
|
16193
|
+
toolUseId: toolCallId,
|
|
16194
|
+
answer: trimmed,
|
|
16195
|
+
answers: meta.structured,
|
|
16196
|
+
values: (_b2 = meta.values) != null ? _b2 : meta.source === "multi" ? trimmed.split(", ") : [trimmed],
|
|
16197
|
+
isFreeText,
|
|
16198
|
+
source: meta.source
|
|
16199
|
+
},
|
|
16200
|
+
bubbles: true,
|
|
16201
|
+
composed: true
|
|
16202
|
+
})
|
|
16203
|
+
);
|
|
16204
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16205
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16206
|
+
var _a3;
|
|
16207
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16208
|
+
});
|
|
16209
|
+
if ((_c2 = sourceMessage == null ? void 0 : sourceMessage.agentMetadata) == null ? void 0 : _c2.awaitingLocalTool) {
|
|
16210
|
+
sessionRef.current.resolveAskUserQuestion(sourceMessage, (_d2 = meta.structured) != null ? _d2 : trimmed);
|
|
16211
|
+
} else {
|
|
16212
|
+
sessionRef.current.sendMessage(trimmed);
|
|
16213
|
+
}
|
|
16214
|
+
};
|
|
16215
|
+
const persistGroupedProgress = (sheet) => {
|
|
16216
|
+
var _a2;
|
|
16217
|
+
const session2 = sessionRef.current;
|
|
16218
|
+
if (!session2) return;
|
|
16219
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16220
|
+
const sourceMessage = session2.getMessages().find((m) => {
|
|
16221
|
+
var _a3;
|
|
16222
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16223
|
+
});
|
|
16224
|
+
if (!sourceMessage) return;
|
|
16225
|
+
session2.persistAskUserQuestionProgress(sourceMessage, {
|
|
16226
|
+
answers: buildStructuredAnswers(sheet, sourceMessage),
|
|
16227
|
+
currentIndex: getCurrentIndex(sheet)
|
|
16228
|
+
});
|
|
16229
|
+
};
|
|
16230
|
+
const stringifyStructured = (answers) => {
|
|
16231
|
+
return Object.entries(answers).map(([q, v]) => `${q}: ${Array.isArray(v) ? v.join(", ") : v}`).join(" | ");
|
|
16232
|
+
};
|
|
16233
|
+
const maybeAutoAdvance = (sheet) => {
|
|
16234
|
+
var _a2, _b2, _c2;
|
|
16235
|
+
if (((_b2 = (_a2 = config.features) == null ? void 0 : _a2.askUserQuestion) == null ? void 0 : _b2.groupedAutoAdvance) === false) return;
|
|
16236
|
+
const idx = getCurrentIndex(sheet);
|
|
16237
|
+
const count = getQuestionCount(sheet);
|
|
16238
|
+
if (idx >= count - 1) return;
|
|
16239
|
+
const sourceMessage = (_c2 = sessionRef.current) == null ? void 0 : _c2.getMessages().find((m) => {
|
|
16240
|
+
var _a3;
|
|
16241
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === sheet.getAttribute("data-tool-call-id");
|
|
16242
|
+
});
|
|
16243
|
+
if (!sourceMessage) return;
|
|
16244
|
+
navigateToPage(sheet, sourceMessage, config, idx + 1);
|
|
16245
|
+
persistGroupedProgress(sheet);
|
|
16246
|
+
};
|
|
16247
|
+
askUserOverlay.addEventListener("click", (event) => {
|
|
16248
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
16249
|
+
const target = event.target;
|
|
16250
|
+
const trigger = target.closest("[data-ask-user-action]");
|
|
16251
|
+
if (!trigger) return;
|
|
16252
|
+
const sheet = trigger.closest("[data-persona-ask-sheet-for]");
|
|
16253
|
+
if (!sheet) return;
|
|
16254
|
+
const action = trigger.getAttribute("data-ask-user-action");
|
|
16255
|
+
event.preventDefault();
|
|
16256
|
+
event.stopPropagation();
|
|
16257
|
+
if (action === "dismiss") {
|
|
16258
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16259
|
+
mount.dispatchEvent(
|
|
16260
|
+
new CustomEvent("persona:askUserQuestion:dismissed", {
|
|
16261
|
+
detail: { toolUseId: toolCallId },
|
|
16262
|
+
bubbles: true,
|
|
16263
|
+
composed: true
|
|
16264
|
+
})
|
|
16265
|
+
);
|
|
16266
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16267
|
+
const sourceMessage = (_b2 = sessionRef.current) == null ? void 0 : _b2.getMessages().find((m) => {
|
|
16268
|
+
var _a3;
|
|
16269
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16270
|
+
});
|
|
16271
|
+
if ((_c2 = sourceMessage == null ? void 0 : sourceMessage.agentMetadata) == null ? void 0 : _c2.awaitingLocalTool) {
|
|
16272
|
+
(_d2 = sessionRef.current) == null ? void 0 : _d2.markAskUserQuestionResolved(sourceMessage);
|
|
16273
|
+
(_e2 = sessionRef.current) == null ? void 0 : _e2.resolveAskUserQuestion(sourceMessage, "(dismissed)");
|
|
16274
|
+
}
|
|
16275
|
+
return;
|
|
16276
|
+
}
|
|
16277
|
+
if (action === "pick") {
|
|
16278
|
+
const label = trigger.getAttribute("data-option-label");
|
|
16279
|
+
if (!label) return;
|
|
16280
|
+
const multiSelect = sheet.getAttribute("data-multi-select") === "true";
|
|
16281
|
+
const grouped = isGroupedSheet(sheet);
|
|
16282
|
+
if (grouped && multiSelect) {
|
|
16283
|
+
const stored = readAnswersFromSheet(sheet)[getCurrentIndex(sheet)];
|
|
16284
|
+
const set = new Set(Array.isArray(stored) ? stored : []);
|
|
16285
|
+
if (set.has(label)) set.delete(label);
|
|
16286
|
+
else set.add(label);
|
|
16287
|
+
setCurrentAnswer(sheet, Array.from(set));
|
|
16288
|
+
persistGroupedProgress(sheet);
|
|
16289
|
+
return;
|
|
16290
|
+
}
|
|
16291
|
+
if (grouped) {
|
|
16292
|
+
setCurrentAnswer(sheet, label);
|
|
16293
|
+
persistGroupedProgress(sheet);
|
|
16294
|
+
maybeAutoAdvance(sheet);
|
|
16295
|
+
return;
|
|
16296
|
+
}
|
|
16297
|
+
if (multiSelect) {
|
|
16298
|
+
const pressed = trigger.getAttribute("aria-pressed") === "true";
|
|
16299
|
+
trigger.setAttribute("aria-pressed", pressed ? "false" : "true");
|
|
16300
|
+
trigger.classList.toggle("persona-ask-pill-selected", !pressed);
|
|
16301
|
+
const submitBtn = sheet.querySelector(
|
|
16302
|
+
'[data-ask-user-action="submit-multi"]'
|
|
16303
|
+
);
|
|
16304
|
+
if (submitBtn) {
|
|
16305
|
+
submitBtn.disabled = getSelectedLabels(sheet).length === 0;
|
|
16306
|
+
}
|
|
16307
|
+
return;
|
|
16308
|
+
}
|
|
16309
|
+
submitAskUserAnswer(sheet, label, { source: "pick", values: [label] });
|
|
16310
|
+
return;
|
|
16311
|
+
}
|
|
16312
|
+
if (action === "submit-multi") {
|
|
16313
|
+
const labels = getSelectedLabels(sheet);
|
|
16314
|
+
if (labels.length === 0) return;
|
|
16315
|
+
submitAskUserAnswer(sheet, labels.join(", "), {
|
|
16316
|
+
source: "multi",
|
|
16317
|
+
values: labels
|
|
16318
|
+
});
|
|
16319
|
+
return;
|
|
16320
|
+
}
|
|
16321
|
+
if (action === "open-free-text") {
|
|
16322
|
+
const row = sheet.querySelector('[data-ask-free-text-row="true"]');
|
|
16323
|
+
if (row) {
|
|
16324
|
+
row.classList.remove("persona-hidden");
|
|
16325
|
+
const input = row.querySelector('[data-ask-free-text-input="true"]');
|
|
16326
|
+
input == null ? void 0 : input.focus();
|
|
16327
|
+
}
|
|
16328
|
+
return;
|
|
16329
|
+
}
|
|
16330
|
+
if (action === "focus-free-text") {
|
|
16331
|
+
const input = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16332
|
+
input == null ? void 0 : input.focus();
|
|
16333
|
+
return;
|
|
16334
|
+
}
|
|
16335
|
+
if (action === "submit-free-text") {
|
|
16336
|
+
const input = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16337
|
+
const text = (_f2 = input == null ? void 0 : input.value) != null ? _f2 : "";
|
|
16338
|
+
if (!text.trim()) return;
|
|
16339
|
+
if (isGroupedSheet(sheet)) {
|
|
16340
|
+
setCurrentAnswer(sheet, text.trim());
|
|
16341
|
+
persistGroupedProgress(sheet);
|
|
16342
|
+
maybeAutoAdvance(sheet);
|
|
16343
|
+
return;
|
|
16344
|
+
}
|
|
16345
|
+
submitAskUserAnswer(sheet, text, { source: "free-text" });
|
|
16346
|
+
return;
|
|
16347
|
+
}
|
|
16348
|
+
if (action === "next" || action === "back") {
|
|
16349
|
+
if (!sessionRef.current) return;
|
|
16350
|
+
const toolCallId = (_g2 = sheet.getAttribute("data-tool-call-id")) != null ? _g2 : "";
|
|
16351
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16352
|
+
var _a3;
|
|
16353
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16354
|
+
});
|
|
16355
|
+
if (!sourceMessage) return;
|
|
16356
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16357
|
+
const pending = (_i2 = (_h2 = freeInput == null ? void 0 : freeInput.value) == null ? void 0 : _h2.trim()) != null ? _i2 : "";
|
|
16358
|
+
if (pending) {
|
|
16359
|
+
const stored = readAnswersFromSheet(sheet)[getCurrentIndex(sheet)];
|
|
16360
|
+
if (typeof stored !== "string" || stored !== pending) {
|
|
16361
|
+
setCurrentAnswer(sheet, pending);
|
|
16362
|
+
}
|
|
16363
|
+
}
|
|
16364
|
+
const direction = action === "next" ? 1 : -1;
|
|
16365
|
+
const nextIdx = getCurrentIndex(sheet) + direction;
|
|
16366
|
+
navigateToPage(sheet, sourceMessage, config, nextIdx);
|
|
16367
|
+
persistGroupedProgress(sheet);
|
|
16368
|
+
return;
|
|
16369
|
+
}
|
|
16370
|
+
if (action === "submit-all") {
|
|
16371
|
+
if (!sessionRef.current) return;
|
|
16372
|
+
const toolCallId = (_j2 = sheet.getAttribute("data-tool-call-id")) != null ? _j2 : "";
|
|
16373
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16374
|
+
var _a3;
|
|
16375
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16376
|
+
});
|
|
16377
|
+
if (!sourceMessage) return;
|
|
16378
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16379
|
+
const pending = (_l2 = (_k2 = freeInput == null ? void 0 : freeInput.value) == null ? void 0 : _k2.trim()) != null ? _l2 : "";
|
|
16380
|
+
if (pending) setCurrentAnswer(sheet, pending);
|
|
16381
|
+
const structured = buildStructuredAnswers(sheet, sourceMessage);
|
|
16382
|
+
sessionRef.current.persistAskUserQuestionProgress(sourceMessage, {
|
|
16383
|
+
answers: structured,
|
|
16384
|
+
currentIndex: getCurrentIndex(sheet)
|
|
16385
|
+
});
|
|
16386
|
+
const summary = stringifyStructured(structured);
|
|
16387
|
+
submitAskUserAnswer(sheet, summary || "(submitted)", {
|
|
16388
|
+
source: "submit-all",
|
|
16389
|
+
structured
|
|
16390
|
+
});
|
|
16391
|
+
return;
|
|
16392
|
+
}
|
|
16393
|
+
if (action === "skip") {
|
|
16394
|
+
if (!sessionRef.current) return;
|
|
16395
|
+
const toolCallId = (_m2 = sheet.getAttribute("data-tool-call-id")) != null ? _m2 : "";
|
|
16396
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16397
|
+
var _a3;
|
|
16398
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16399
|
+
});
|
|
16400
|
+
if (!sourceMessage) return;
|
|
16401
|
+
const grouped = isGroupedSheet(sheet);
|
|
16402
|
+
const idx = getCurrentIndex(sheet);
|
|
16403
|
+
const count = getQuestionCount(sheet);
|
|
16404
|
+
const isFinal = idx >= count - 1;
|
|
16405
|
+
if (!grouped) {
|
|
16406
|
+
mount.dispatchEvent(
|
|
16407
|
+
new CustomEvent("persona:askUserQuestion:dismissed", {
|
|
16408
|
+
detail: { toolUseId: toolCallId },
|
|
16409
|
+
bubbles: true,
|
|
16410
|
+
composed: true
|
|
16411
|
+
})
|
|
16412
|
+
);
|
|
16413
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16414
|
+
if ((_n2 = sourceMessage.agentMetadata) == null ? void 0 : _n2.awaitingLocalTool) {
|
|
16415
|
+
sessionRef.current.markAskUserQuestionResolved(sourceMessage);
|
|
16416
|
+
sessionRef.current.resolveAskUserQuestion(sourceMessage, "(dismissed)");
|
|
16417
|
+
}
|
|
16418
|
+
return;
|
|
16419
|
+
}
|
|
16420
|
+
setCurrentAnswer(sheet, "");
|
|
16421
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16422
|
+
if (freeInput) freeInput.value = "";
|
|
16423
|
+
if (isFinal) {
|
|
16424
|
+
const structured = buildStructuredAnswers(sheet, sourceMessage);
|
|
16425
|
+
const summary = stringifyStructured(structured);
|
|
16426
|
+
submitAskUserAnswer(sheet, summary || "(skipped)", {
|
|
16427
|
+
source: "submit-all",
|
|
16428
|
+
structured
|
|
16429
|
+
});
|
|
16430
|
+
return;
|
|
16431
|
+
}
|
|
16432
|
+
navigateToPage(sheet, sourceMessage, config, idx + 1);
|
|
16433
|
+
persistGroupedProgress(sheet);
|
|
16434
|
+
return;
|
|
16435
|
+
}
|
|
16436
|
+
});
|
|
16437
|
+
askUserOverlay.addEventListener("keydown", (event) => {
|
|
16438
|
+
var _a2;
|
|
16439
|
+
if (event.key !== "Enter") return;
|
|
16440
|
+
const target = event.target;
|
|
16441
|
+
const input = target;
|
|
16442
|
+
if (!((_a2 = input.matches) == null ? void 0 : _a2.call(input, '[data-ask-free-text-input="true"]'))) return;
|
|
16443
|
+
const sheet = input.closest("[data-persona-ask-sheet-for]");
|
|
16444
|
+
if (!sheet) return;
|
|
16445
|
+
event.preventDefault();
|
|
16446
|
+
const text = input.value;
|
|
16447
|
+
if (!text.trim()) return;
|
|
16448
|
+
if (isGroupedSheet(sheet)) {
|
|
16449
|
+
setCurrentAnswer(sheet, text.trim());
|
|
16450
|
+
persistGroupedProgress(sheet);
|
|
16451
|
+
maybeAutoAdvance(sheet);
|
|
16452
|
+
return;
|
|
16453
|
+
}
|
|
16454
|
+
submitAskUserAnswer(sheet, text, { source: "free-text" });
|
|
16455
|
+
});
|
|
16456
|
+
const handleAskUserDigitKey = (event) => {
|
|
16457
|
+
if (!/^[1-9]$/.test(event.key)) return;
|
|
16458
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
16459
|
+
const target = event.target;
|
|
16460
|
+
if ((target == null ? void 0 : target.tagName) === "INPUT" || (target == null ? void 0 : target.tagName) === "TEXTAREA" || (target == null ? void 0 : target.isContentEditable)) {
|
|
16461
|
+
return;
|
|
16462
|
+
}
|
|
16463
|
+
const sheet = askUserOverlay.querySelector("[data-persona-ask-sheet-for]");
|
|
16464
|
+
if (!sheet) return;
|
|
16465
|
+
if (sheet.getAttribute("data-ask-layout") !== "rows") return;
|
|
16466
|
+
if (sheet.getAttribute("data-multi-select") === "true") return;
|
|
16467
|
+
const n = Number(event.key);
|
|
16468
|
+
const pills = sheet.querySelectorAll(
|
|
16469
|
+
'[data-ask-pill-list="true"] [data-ask-user-action="pick"], [data-ask-pill-list="true"] [data-ask-user-action="focus-free-text"]'
|
|
16470
|
+
);
|
|
16471
|
+
const target_pill = pills[n - 1];
|
|
16472
|
+
if (!target_pill) return;
|
|
16473
|
+
event.preventDefault();
|
|
16474
|
+
target_pill.click();
|
|
16475
|
+
};
|
|
16476
|
+
document.addEventListener("keydown", handleAskUserDigitKey);
|
|
15330
16477
|
let artifactSplitRoot = null;
|
|
15331
16478
|
let artifactResizeHandle = null;
|
|
15332
16479
|
let artifactResizeUnbind = null;
|
|
@@ -15787,6 +16934,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15787
16934
|
applyArtifactLayoutCssVars(mount, config);
|
|
15788
16935
|
applyArtifactPaneAppearance(mount, config);
|
|
15789
16936
|
const destroyCallbacks = [];
|
|
16937
|
+
destroyCallbacks.push(() => {
|
|
16938
|
+
document.removeEventListener("keydown", handleAskUserDigitKey);
|
|
16939
|
+
});
|
|
15790
16940
|
let teardownHostStacking = null;
|
|
15791
16941
|
let releaseScrollLock = null;
|
|
15792
16942
|
destroyCallbacks.push(() => {
|
|
@@ -15844,7 +16994,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15844
16994
|
cleanupThemeObserver = null;
|
|
15845
16995
|
}
|
|
15846
16996
|
});
|
|
15847
|
-
const streamAnimationConfig = (
|
|
16997
|
+
const streamAnimationConfig = (_F = config.features) == null ? void 0 : _F.streamAnimation;
|
|
15848
16998
|
if ((streamAnimationConfig == null ? void 0 : streamAnimationConfig.type) && streamAnimationConfig.type !== "none") {
|
|
15849
16999
|
const plugin = resolveStreamAnimationPlugin(
|
|
15850
17000
|
streamAnimationConfig.type,
|
|
@@ -15860,6 +17010,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15860
17010
|
let session;
|
|
15861
17011
|
let isStreaming = false;
|
|
15862
17012
|
const messageCache = createMessageCache();
|
|
17013
|
+
const lastAskBubbleFingerprint = /* @__PURE__ */ new Map();
|
|
15863
17014
|
let configVersion = 0;
|
|
15864
17015
|
const autoFollow = createFollowStateController();
|
|
15865
17016
|
let lastScrollTop = 0;
|
|
@@ -15876,7 +17027,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15876
17027
|
lastUserMessageWasVoice: false,
|
|
15877
17028
|
lastUserMessageId: null
|
|
15878
17029
|
};
|
|
15879
|
-
const voiceAutoResumeMode = (
|
|
17030
|
+
const voiceAutoResumeMode = (_H = (_G = config.voiceRecognition) == null ? void 0 : _G.autoResume) != null ? _H : false;
|
|
15880
17031
|
const emitVoiceState = (source) => {
|
|
15881
17032
|
eventBus.emit("voice:state", {
|
|
15882
17033
|
active: voiceState.active,
|
|
@@ -15925,7 +17076,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15925
17076
|
const messages = messagesOverride ? stripStreamingFromMessages(messagesOverride) : session ? getMessagesForPersistence() : [];
|
|
15926
17077
|
const payload = {
|
|
15927
17078
|
messages,
|
|
15928
|
-
metadata: persistentMetadata
|
|
17079
|
+
metadata: persistentMetadata,
|
|
17080
|
+
artifacts: lastArtifactsState.artifacts,
|
|
17081
|
+
selectedArtifactId: lastArtifactsState.selectedId
|
|
15929
17082
|
};
|
|
15930
17083
|
try {
|
|
15931
17084
|
const result = storageAdapter.save(payload);
|
|
@@ -16102,13 +17255,22 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16102
17255
|
return true;
|
|
16103
17256
|
};
|
|
16104
17257
|
const activeMessageIds = /* @__PURE__ */ new Set();
|
|
17258
|
+
const liveAskToolIds = /* @__PURE__ */ new Set();
|
|
17259
|
+
const hasAskPlugin = plugins.some((p) => p.renderAskUserQuestion);
|
|
17260
|
+
const askPluginHydrate = [];
|
|
16105
17261
|
messages.forEach((message) => {
|
|
16106
|
-
var _a3, _b3;
|
|
17262
|
+
var _a3, _b3, _c3, _d3, _e3, _f3, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
16107
17263
|
activeMessageIds.add(message.id);
|
|
16108
|
-
const
|
|
16109
|
-
const
|
|
17264
|
+
const askWithPlugin = hasAskPlugin && isAskUserQuestionMessage(message);
|
|
17265
|
+
const askMeta = isAskUserQuestionMessage(message) ? `:${((_a3 = message.agentMetadata) == null ? void 0 : _a3.askUserQuestionAnswered) ? "a" : "u"}:${((_b3 = message.agentMetadata) == null ? void 0 : _b3.askUserQuestionAnswers) ? Object.keys(message.agentMetadata.askUserQuestionAnswers).length : 0}` : "";
|
|
17266
|
+
const fingerprint = computeMessageFingerprint(message, configVersion) + askMeta;
|
|
17267
|
+
const cachedWrapper = askWithPlugin ? null : getCachedWrapper(messageCache, message.id, fingerprint);
|
|
16110
17268
|
if (cachedWrapper) {
|
|
16111
17269
|
tempContainer.appendChild(cachedWrapper.cloneNode(true));
|
|
17270
|
+
if (isAskUserQuestionMessage(message) && ((_c3 = message.toolCall) == null ? void 0 : _c3.id) && ((_d3 = message.agentMetadata) == null ? void 0 : _d3.awaitingLocalTool) === true && !((_e3 = message.agentMetadata) == null ? void 0 : _e3.askUserQuestionAnswered)) {
|
|
17271
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17272
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17273
|
+
}
|
|
16112
17274
|
return;
|
|
16113
17275
|
}
|
|
16114
17276
|
let bubble = null;
|
|
@@ -16127,8 +17289,75 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16127
17289
|
}
|
|
16128
17290
|
return false;
|
|
16129
17291
|
});
|
|
16130
|
-
const messageLayoutConfig = (
|
|
16131
|
-
if (
|
|
17292
|
+
const messageLayoutConfig = (_f3 = config.layout) == null ? void 0 : _f3.messages;
|
|
17293
|
+
if (isAskUserQuestionMessage(message) && ((_g2 = message.agentMetadata) == null ? void 0 : _g2.askUserQuestionAnswered) === true) {
|
|
17294
|
+
lastAskBubbleFingerprint.delete(message.id);
|
|
17295
|
+
const existing = container2.querySelector(`#wrapper-${message.id}`);
|
|
17296
|
+
existing == null ? void 0 : existing.removeAttribute("data-preserve-runtime");
|
|
17297
|
+
return;
|
|
17298
|
+
}
|
|
17299
|
+
if (isAskUserQuestionMessage(message) && ((_i2 = (_h2 = config.features) == null ? void 0 : _h2.askUserQuestion) == null ? void 0 : _i2.enabled) !== false) {
|
|
17300
|
+
const askPlugin = plugins.find((p) => typeof p.renderAskUserQuestion === "function");
|
|
17301
|
+
if (askPlugin && sessionRef.current) {
|
|
17302
|
+
const lastFp = lastAskBubbleFingerprint.get(message.id);
|
|
17303
|
+
const needsRebuild = lastFp !== fingerprint;
|
|
17304
|
+
let pluginBubble = null;
|
|
17305
|
+
if (needsRebuild) {
|
|
17306
|
+
const { payload, complete } = parseAskUserQuestionPayload(message);
|
|
17307
|
+
const messageId = message.id;
|
|
17308
|
+
const liveMessage = () => {
|
|
17309
|
+
var _a4;
|
|
17310
|
+
return (_a4 = sessionRef.current) == null ? void 0 : _a4.getMessages().find((m) => m.id === messageId);
|
|
17311
|
+
};
|
|
17312
|
+
pluginBubble = askPlugin.renderAskUserQuestion({
|
|
17313
|
+
message,
|
|
17314
|
+
payload,
|
|
17315
|
+
complete,
|
|
17316
|
+
resolve: (answer) => {
|
|
17317
|
+
var _a4;
|
|
17318
|
+
const live = liveMessage();
|
|
17319
|
+
if (live) (_a4 = sessionRef.current) == null ? void 0 : _a4.resolveAskUserQuestion(live, answer);
|
|
17320
|
+
},
|
|
17321
|
+
dismiss: () => {
|
|
17322
|
+
var _a4, _b4, _c4;
|
|
17323
|
+
const live = liveMessage();
|
|
17324
|
+
if ((_a4 = live == null ? void 0 : live.agentMetadata) == null ? void 0 : _a4.awaitingLocalTool) {
|
|
17325
|
+
(_b4 = sessionRef.current) == null ? void 0 : _b4.markAskUserQuestionResolved(live);
|
|
17326
|
+
(_c4 = sessionRef.current) == null ? void 0 : _c4.resolveAskUserQuestion(live, "(dismissed)");
|
|
17327
|
+
}
|
|
17328
|
+
},
|
|
17329
|
+
config
|
|
17330
|
+
});
|
|
17331
|
+
}
|
|
17332
|
+
const previouslyMounted = lastFp != null;
|
|
17333
|
+
if (needsRebuild && pluginBubble === null && !previouslyMounted) {
|
|
17334
|
+
if (((_j2 = message.agentMetadata) == null ? void 0 : _j2.awaitingLocalTool) === true && !((_k2 = message.agentMetadata) == null ? void 0 : _k2.askUserQuestionAnswered)) {
|
|
17335
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17336
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17337
|
+
}
|
|
17338
|
+
return;
|
|
17339
|
+
}
|
|
17340
|
+
const stub = document.createElement("div");
|
|
17341
|
+
stub.className = "persona-flex";
|
|
17342
|
+
stub.id = `wrapper-${message.id}`;
|
|
17343
|
+
stub.setAttribute("data-wrapper-id", message.id);
|
|
17344
|
+
stub.setAttribute("data-ask-plugin-stub", "true");
|
|
17345
|
+
stub.setAttribute("data-preserve-runtime", "true");
|
|
17346
|
+
tempContainer.appendChild(stub);
|
|
17347
|
+
askPluginHydrate.push({
|
|
17348
|
+
messageId: message.id,
|
|
17349
|
+
fingerprint,
|
|
17350
|
+
bubble: pluginBubble
|
|
17351
|
+
});
|
|
17352
|
+
return;
|
|
17353
|
+
} else {
|
|
17354
|
+
if (((_l2 = message.agentMetadata) == null ? void 0 : _l2.awaitingLocalTool) === true && !((_m2 = message.agentMetadata) == null ? void 0 : _m2.askUserQuestionAnswered)) {
|
|
17355
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17356
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17357
|
+
}
|
|
17358
|
+
return;
|
|
17359
|
+
}
|
|
17360
|
+
} else if (matchingPlugin) {
|
|
16132
17361
|
if (message.variant === "reasoning" && message.reasoning && matchingPlugin.renderReasoning) {
|
|
16133
17362
|
if (!showReasoning) return;
|
|
16134
17363
|
bubble = matchingPlugin.renderReasoning({
|
|
@@ -16247,7 +17476,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16247
17476
|
if (config.approval === false) return;
|
|
16248
17477
|
bubble = createApprovalBubble(message, config);
|
|
16249
17478
|
} else {
|
|
16250
|
-
const messageLayoutConfig2 = (
|
|
17479
|
+
const messageLayoutConfig2 = (_n2 = config.layout) == null ? void 0 : _n2.messages;
|
|
16251
17480
|
if ((messageLayoutConfig2 == null ? void 0 : messageLayoutConfig2.renderUserMessage) && message.role === "user") {
|
|
16252
17481
|
bubble = messageLayoutConfig2.renderUserMessage({
|
|
16253
17482
|
message,
|
|
@@ -16292,6 +17521,17 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16292
17521
|
setCachedWrapper(messageCache, message.id, fingerprint, wrapper2);
|
|
16293
17522
|
tempContainer.appendChild(wrapper2);
|
|
16294
17523
|
});
|
|
17524
|
+
if (panelElements.composerOverlay) {
|
|
17525
|
+
const sheets = panelElements.composerOverlay.querySelectorAll(
|
|
17526
|
+
"[data-persona-ask-sheet-for]"
|
|
17527
|
+
);
|
|
17528
|
+
sheets.forEach((sheet) => {
|
|
17529
|
+
const id = sheet.getAttribute("data-persona-ask-sheet-for");
|
|
17530
|
+
if (id && !liveAskToolIds.has(id)) {
|
|
17531
|
+
removeAskUserQuestionSheet(panelElements.composerOverlay, id);
|
|
17532
|
+
}
|
|
17533
|
+
});
|
|
17534
|
+
}
|
|
16295
17535
|
if ((_b2 = (_a2 = config.features) == null ? void 0 : _a2.toolCallDisplay) == null ? void 0 : _b2.grouped) {
|
|
16296
17536
|
const toolGroups = [];
|
|
16297
17537
|
let currentGroup = [];
|
|
@@ -16456,6 +17696,23 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16456
17696
|
}
|
|
16457
17697
|
}
|
|
16458
17698
|
morphMessages(container2, tempContainer);
|
|
17699
|
+
if (askPluginHydrate.length > 0) {
|
|
17700
|
+
for (const { messageId, fingerprint, bubble } of askPluginHydrate) {
|
|
17701
|
+
const wrapper2 = container2.querySelector(`#wrapper-${messageId}`);
|
|
17702
|
+
if (!wrapper2) continue;
|
|
17703
|
+
if (bubble === null) {
|
|
17704
|
+
continue;
|
|
17705
|
+
}
|
|
17706
|
+
wrapper2.replaceChildren(bubble);
|
|
17707
|
+
wrapper2.setAttribute("data-bubble-fp", fingerprint);
|
|
17708
|
+
lastAskBubbleFingerprint.set(messageId, fingerprint);
|
|
17709
|
+
}
|
|
17710
|
+
}
|
|
17711
|
+
if (lastAskBubbleFingerprint.size > 0) {
|
|
17712
|
+
for (const id of lastAskBubbleFingerprint.keys()) {
|
|
17713
|
+
if (!activeMessageIds.has(id)) lastAskBubbleFingerprint.delete(id);
|
|
17714
|
+
}
|
|
17715
|
+
}
|
|
16459
17716
|
};
|
|
16460
17717
|
const renderMessagesWithPlugins = renderMessagesWithPluginsImpl;
|
|
16461
17718
|
const updateOpenState = () => {
|
|
@@ -16720,10 +17977,11 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16720
17977
|
onArtifactsState(state) {
|
|
16721
17978
|
lastArtifactsState = state;
|
|
16722
17979
|
syncArtifactPane();
|
|
17980
|
+
persistState();
|
|
16723
17981
|
}
|
|
16724
17982
|
});
|
|
16725
17983
|
sessionRef.current = session;
|
|
16726
|
-
if (((
|
|
17984
|
+
if (((_J = (_I = config.voiceRecognition) == null ? void 0 : _I.provider) == null ? void 0 : _J.type) === "runtype") {
|
|
16727
17985
|
try {
|
|
16728
17986
|
session.setupVoice();
|
|
16729
17987
|
} catch (err) {
|
|
@@ -16753,7 +18011,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16753
18011
|
}
|
|
16754
18012
|
if (pendingStoredState) {
|
|
16755
18013
|
pendingStoredState.then((state) => {
|
|
16756
|
-
var _a2;
|
|
18014
|
+
var _a2, _b2, _c2;
|
|
16757
18015
|
if (!state) return;
|
|
16758
18016
|
if (state.metadata) {
|
|
16759
18017
|
persistentMetadata = ensureRecord(state.metadata);
|
|
@@ -16762,6 +18020,12 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16762
18020
|
if ((_a2 = state.messages) == null ? void 0 : _a2.length) {
|
|
16763
18021
|
session.hydrateMessages(state.messages);
|
|
16764
18022
|
}
|
|
18023
|
+
if ((_b2 = state.artifacts) == null ? void 0 : _b2.length) {
|
|
18024
|
+
session.hydrateArtifacts(
|
|
18025
|
+
state.artifacts,
|
|
18026
|
+
(_c2 = state.selectedArtifactId) != null ? _c2 : null
|
|
18027
|
+
);
|
|
18028
|
+
}
|
|
16765
18029
|
}).catch((error) => {
|
|
16766
18030
|
if (typeof console !== "undefined") {
|
|
16767
18031
|
console.error("[AgentWidget] Failed to hydrate stored state:", error);
|
|
@@ -17329,7 +18593,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17329
18593
|
}
|
|
17330
18594
|
};
|
|
17331
18595
|
recalcPanelHeight();
|
|
17332
|
-
const ownerWindow = (
|
|
18596
|
+
const ownerWindow = (_K = mount.ownerDocument.defaultView) != null ? _K : window;
|
|
17333
18597
|
ownerWindow.addEventListener("resize", recalcPanelHeight);
|
|
17334
18598
|
destroyCallbacks.push(() => ownerWindow.removeEventListener("resize", recalcPanelHeight));
|
|
17335
18599
|
if (typeof ResizeObserver !== "undefined") {
|
|
@@ -17417,6 +18681,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17417
18681
|
session.clearMessages();
|
|
17418
18682
|
messageCache.clear();
|
|
17419
18683
|
resumeAutoScroll();
|
|
18684
|
+
removeAskUserQuestionSheet(panelElements.composerOverlay);
|
|
17420
18685
|
try {
|
|
17421
18686
|
localStorage.removeItem(DEFAULT_CHAT_HISTORY_STORAGE_KEY);
|
|
17422
18687
|
if (config.debug) {
|
|
@@ -17552,7 +18817,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17552
18817
|
}
|
|
17553
18818
|
const controller = {
|
|
17554
18819
|
update(nextConfig) {
|
|
17555
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2, _q2, _r2, _s2, _t2, _u2, _v2, _w2, _x2, _y2, _z2, _A2, _B2, _C2, _D2, _E2, _F2, _G2, _H2, _I2, _J2, _K2, _L2, _M2, _N2, _O2,
|
|
18820
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2, _q2, _r2, _s2, _t2, _u2, _v2, _w2, _x2, _y2, _z2, _A2, _B2, _C2, _D2, _E2, _F2, _G2, _H2, _I2, _J2, _K2, _L2, _M2, _N2, _O2, _P2, _Q2, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab;
|
|
17556
18821
|
const previousToolCallConfig = config.toolCall;
|
|
17557
18822
|
const previousMessageActions = config.messageActions;
|
|
17558
18823
|
const previousLayoutMessages = (_a2 = config.layout) == null ? void 0 : _a2.messages;
|
|
@@ -17766,7 +19031,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17766
19031
|
const layoutShowIcon = (_O2 = (_N2 = config.layout) == null ? void 0 : _N2.header) == null ? void 0 : _O2.showIcon;
|
|
17767
19032
|
const shouldHideIcon = headerIconHidden || layoutShowIcon === false;
|
|
17768
19033
|
const headerIconName = launcher.headerIconName;
|
|
17769
|
-
const headerIconSize = (
|
|
19034
|
+
const headerIconSize = (_P2 = launcher.headerIconSize) != null ? _P2 : "48px";
|
|
17770
19035
|
if (iconHolder) {
|
|
17771
19036
|
const headerEl = container.querySelector(".persona-border-b-persona-divider");
|
|
17772
19037
|
const headerCopy = headerEl == null ? void 0 : headerEl.querySelector(".persona-flex-col");
|
|
@@ -17793,7 +19058,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17793
19058
|
if (iconSvg) {
|
|
17794
19059
|
iconHolder.replaceChildren(iconSvg);
|
|
17795
19060
|
} else {
|
|
17796
|
-
iconHolder.textContent = (
|
|
19061
|
+
iconHolder.textContent = (_Q2 = launcher.agentIconText) != null ? _Q2 : "\u{1F4AC}";
|
|
17797
19062
|
}
|
|
17798
19063
|
} else if (launcher.iconUrl) {
|
|
17799
19064
|
const img2 = iconHolder.querySelector("img");
|
|
@@ -18717,6 +19982,14 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18717
19982
|
if (!artifactsSidebarEnabled(config)) return;
|
|
18718
19983
|
session.clearArtifacts();
|
|
18719
19984
|
},
|
|
19985
|
+
getArtifacts() {
|
|
19986
|
+
var _a2;
|
|
19987
|
+
return (_a2 = session == null ? void 0 : session.getArtifacts()) != null ? _a2 : [];
|
|
19988
|
+
},
|
|
19989
|
+
getSelectedArtifactId() {
|
|
19990
|
+
var _a2;
|
|
19991
|
+
return (_a2 = session == null ? void 0 : session.getSelectedArtifactId()) != null ? _a2 : null;
|
|
19992
|
+
},
|
|
18720
19993
|
focusInput() {
|
|
18721
19994
|
if (launcherEnabled && !open) return false;
|
|
18722
19995
|
if (!textarea) return false;
|
|
@@ -18834,7 +20107,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18834
20107
|
}
|
|
18835
20108
|
}
|
|
18836
20109
|
};
|
|
18837
|
-
const shouldExposeDebugApi = ((
|
|
20110
|
+
const shouldExposeDebugApi = ((_L = runtimeOptions == null ? void 0 : runtimeOptions.debugTools) != null ? _L : false) || Boolean(config.debug);
|
|
18838
20111
|
if (shouldExposeDebugApi && typeof window !== "undefined") {
|
|
18839
20112
|
const previousDebug = window.AgentWidgetBrowser;
|
|
18840
20113
|
const debugApi = {
|
|
@@ -18937,9 +20210,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18937
20210
|
const voiceKey = `${persistConfig.keyPrefix}widget-voice`;
|
|
18938
20211
|
const voiceModeKey = `${persistConfig.keyPrefix}widget-voice-mode`;
|
|
18939
20212
|
if (storage) {
|
|
18940
|
-
const wasOpen = ((
|
|
18941
|
-
const wasVoiceActive = ((
|
|
18942
|
-
const wasInVoiceMode = ((
|
|
20213
|
+
const wasOpen = ((_M = persistConfig.persist) == null ? void 0 : _M.openState) && storage.getItem(openKey) === "true";
|
|
20214
|
+
const wasVoiceActive = ((_N = persistConfig.persist) == null ? void 0 : _N.voiceState) && storage.getItem(voiceKey) === "true";
|
|
20215
|
+
const wasInVoiceMode = ((_O = persistConfig.persist) == null ? void 0 : _O.voiceState) && storage.getItem(voiceModeKey) === "true";
|
|
18943
20216
|
if (wasOpen) {
|
|
18944
20217
|
setTimeout(() => {
|
|
18945
20218
|
controller.open();
|
|
@@ -18956,7 +20229,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18956
20229
|
}, 100);
|
|
18957
20230
|
}, 0);
|
|
18958
20231
|
}
|
|
18959
|
-
if ((
|
|
20232
|
+
if ((_P = persistConfig.persist) == null ? void 0 : _P.openState) {
|
|
18960
20233
|
eventBus.on("widget:opened", () => {
|
|
18961
20234
|
storage.setItem(openKey, "true");
|
|
18962
20235
|
});
|
|
@@ -18964,7 +20237,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18964
20237
|
storage.setItem(openKey, "false");
|
|
18965
20238
|
});
|
|
18966
20239
|
}
|
|
18967
|
-
if ((
|
|
20240
|
+
if ((_Q = persistConfig.persist) == null ? void 0 : _Q.voiceState) {
|
|
18968
20241
|
eventBus.on("voice:state", (event) => {
|
|
18969
20242
|
storage.setItem(voiceKey, event.active ? "true" : "false");
|
|
18970
20243
|
});
|