@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.js
CHANGED
|
@@ -144,6 +144,13 @@ var DEFAULT_WIDGET_CONFIG = {
|
|
|
144
144
|
placeholder: "none",
|
|
145
145
|
speed: 120,
|
|
146
146
|
duration: 1800
|
|
147
|
+
},
|
|
148
|
+
askUserQuestion: {
|
|
149
|
+
enabled: true,
|
|
150
|
+
slideInMs: 180,
|
|
151
|
+
freeTextLabel: "Other\u2026",
|
|
152
|
+
freeTextPlaceholder: "Type your answer\u2026",
|
|
153
|
+
submitLabel: "Send"
|
|
147
154
|
}
|
|
148
155
|
},
|
|
149
156
|
suggestionChips: [
|
|
@@ -246,13 +253,15 @@ function mergeWithDefaults(config) {
|
|
|
246
253
|
...config.voiceRecognition
|
|
247
254
|
},
|
|
248
255
|
features: (() => {
|
|
249
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
256
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
250
257
|
const da = (_a2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _a2.artifacts;
|
|
251
258
|
const ca = (_b2 = config.features) == null ? void 0 : _b2.artifacts;
|
|
252
259
|
const dsb = (_c2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _c2.scrollToBottom;
|
|
253
260
|
const csb = (_d2 = config.features) == null ? void 0 : _d2.scrollToBottom;
|
|
254
261
|
const dsa = (_e2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _e2.streamAnimation;
|
|
255
262
|
const csa = (_f2 = config.features) == null ? void 0 : _f2.streamAnimation;
|
|
263
|
+
const dau = (_g2 = DEFAULT_WIDGET_CONFIG.features) == null ? void 0 : _g2.askUserQuestion;
|
|
264
|
+
const cau = (_h2 = config.features) == null ? void 0 : _h2.askUserQuestion;
|
|
256
265
|
const mergedArtifacts = da === void 0 && ca === void 0 ? void 0 : {
|
|
257
266
|
...da,
|
|
258
267
|
...ca,
|
|
@@ -269,12 +278,21 @@ function mergeWithDefaults(config) {
|
|
|
269
278
|
...dsa,
|
|
270
279
|
...csa
|
|
271
280
|
};
|
|
281
|
+
const mergedAskUserQuestion = dau === void 0 && cau === void 0 ? void 0 : {
|
|
282
|
+
...dau,
|
|
283
|
+
...cau,
|
|
284
|
+
styles: {
|
|
285
|
+
...dau == null ? void 0 : dau.styles,
|
|
286
|
+
...cau == null ? void 0 : cau.styles
|
|
287
|
+
}
|
|
288
|
+
};
|
|
272
289
|
return {
|
|
273
290
|
...DEFAULT_WIDGET_CONFIG.features,
|
|
274
291
|
...config.features,
|
|
275
292
|
...mergedScrollToBottom !== void 0 ? { scrollToBottom: mergedScrollToBottom } : {},
|
|
276
293
|
...mergedArtifacts !== void 0 ? { artifacts: mergedArtifacts } : {},
|
|
277
|
-
...mergedStreamAnimation !== void 0 ? { streamAnimation: mergedStreamAnimation } : {}
|
|
294
|
+
...mergedStreamAnimation !== void 0 ? { streamAnimation: mergedStreamAnimation } : {},
|
|
295
|
+
...mergedAskUserQuestion !== void 0 ? { askUserQuestion: mergedAskUserQuestion } : {}
|
|
278
296
|
};
|
|
279
297
|
})(),
|
|
280
298
|
suggestionChips: (_e = config.suggestionChips) != null ? _e : DEFAULT_WIDGET_CONFIG.suggestionChips,
|
|
@@ -625,6 +643,14 @@ var DEFAULT_COMPONENTS = {
|
|
|
625
643
|
},
|
|
626
644
|
border: "semantic.colors.border"
|
|
627
645
|
},
|
|
646
|
+
introCard: {
|
|
647
|
+
// Defaults preserve the legacy `persona-shadow-sm` look exactly so existing
|
|
648
|
+
// pages render unchanged when no token is set.
|
|
649
|
+
background: "semantic.colors.surface",
|
|
650
|
+
borderRadius: "palette.radius.2xl",
|
|
651
|
+
padding: "semantic.spacing.lg",
|
|
652
|
+
shadow: "0 5px 15px rgba(15, 23, 42, 0.08)"
|
|
653
|
+
},
|
|
628
654
|
toolBubble: {
|
|
629
655
|
shadow: "palette.shadows.sm"
|
|
630
656
|
},
|
|
@@ -901,7 +927,7 @@ function createTheme(userConfig, options = {}) {
|
|
|
901
927
|
return theme;
|
|
902
928
|
}
|
|
903
929
|
function themeToCssVariables(theme) {
|
|
904
|
-
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;
|
|
930
|
+
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;
|
|
905
931
|
const resolved = resolveTokens(theme);
|
|
906
932
|
const cssVars = {};
|
|
907
933
|
for (const [path, token] of Object.entries(resolved)) {
|
|
@@ -965,31 +991,36 @@ function themeToCssVariables(theme) {
|
|
|
965
991
|
const headerTokens = (_ea = theme.components) == null ? void 0 : _ea.header;
|
|
966
992
|
if (headerTokens == null ? void 0 : headerTokens.shadow) cssVars["--persona-header-shadow"] = headerTokens.shadow;
|
|
967
993
|
if (headerTokens == null ? void 0 : headerTokens.borderBottom) cssVars["--persona-header-border-bottom"] = headerTokens.borderBottom;
|
|
968
|
-
|
|
969
|
-
cssVars["--persona-
|
|
970
|
-
cssVars["--persona-
|
|
971
|
-
cssVars["--persona-
|
|
972
|
-
cssVars["--persona-
|
|
973
|
-
cssVars["--persona-
|
|
974
|
-
cssVars["--persona-
|
|
975
|
-
cssVars["--persona-message-
|
|
976
|
-
cssVars["--persona-message-
|
|
977
|
-
cssVars["--persona-
|
|
978
|
-
cssVars["--persona-
|
|
979
|
-
cssVars["--persona-
|
|
980
|
-
cssVars["--persona-
|
|
981
|
-
cssVars["--persona-
|
|
982
|
-
cssVars["--persona-scroll-to-bottom-
|
|
983
|
-
cssVars["--persona-scroll-to-bottom-
|
|
984
|
-
cssVars["--persona-scroll-to-bottom-
|
|
985
|
-
cssVars["--persona-scroll-to-bottom-
|
|
986
|
-
cssVars["--persona-scroll-to-bottom-
|
|
987
|
-
cssVars["--persona-
|
|
988
|
-
cssVars["--persona-
|
|
989
|
-
cssVars["--persona-
|
|
990
|
-
cssVars["--persona-
|
|
991
|
-
cssVars["--persona-
|
|
992
|
-
cssVars["--persona-
|
|
994
|
+
const introCardTokens = (_fa = theme.components) == null ? void 0 : _fa.introCard;
|
|
995
|
+
cssVars["--persona-intro-card-bg"] = (_ga = cssVars["--persona-components-introCard-background"]) != null ? _ga : cssVars["--persona-surface"];
|
|
996
|
+
cssVars["--persona-intro-card-radius"] = (_ha = cssVars["--persona-components-introCard-borderRadius"]) != null ? _ha : "1rem";
|
|
997
|
+
cssVars["--persona-intro-card-padding"] = (_ia = cssVars["--persona-components-introCard-padding"]) != null ? _ia : "1.5rem";
|
|
998
|
+
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)";
|
|
999
|
+
cssVars["--persona-input-background"] = (_la = cssVars["--persona-components-input-background"]) != null ? _la : cssVars["--persona-surface"];
|
|
1000
|
+
cssVars["--persona-input-placeholder"] = (_ma = cssVars["--persona-components-input-placeholder"]) != null ? _ma : cssVars["--persona-text-muted"];
|
|
1001
|
+
cssVars["--persona-message-user-bg"] = (_na = cssVars["--persona-components-message-user-background"]) != null ? _na : cssVars["--persona-accent"];
|
|
1002
|
+
cssVars["--persona-message-user-text"] = (_oa = cssVars["--persona-components-message-user-text"]) != null ? _oa : cssVars["--persona-text-inverse"];
|
|
1003
|
+
cssVars["--persona-message-user-shadow"] = (_pa = cssVars["--persona-components-message-user-shadow"]) != null ? _pa : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1004
|
+
cssVars["--persona-message-assistant-bg"] = (_qa = cssVars["--persona-components-message-assistant-background"]) != null ? _qa : cssVars["--persona-surface"];
|
|
1005
|
+
cssVars["--persona-message-assistant-text"] = (_ra = cssVars["--persona-components-message-assistant-text"]) != null ? _ra : cssVars["--persona-text"];
|
|
1006
|
+
cssVars["--persona-message-assistant-border"] = (_sa = cssVars["--persona-components-message-assistant-border"]) != null ? _sa : cssVars["--persona-border"];
|
|
1007
|
+
cssVars["--persona-message-assistant-shadow"] = (_ta = cssVars["--persona-components-message-assistant-shadow"]) != null ? _ta : "0 1px 2px 0 rgb(0 0 0 / 0.05)";
|
|
1008
|
+
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"];
|
|
1009
|
+
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"];
|
|
1010
|
+
cssVars["--persona-scroll-to-bottom-border"] = (_ya = cssVars["--persona-components-scrollToBottom-border"]) != null ? _ya : cssVars["--persona-primary"];
|
|
1011
|
+
cssVars["--persona-scroll-to-bottom-size"] = (_za = cssVars["--persona-components-scrollToBottom-size"]) != null ? _za : "40px";
|
|
1012
|
+
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";
|
|
1013
|
+
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)";
|
|
1014
|
+
cssVars["--persona-scroll-to-bottom-padding"] = (_Fa = cssVars["--persona-components-scrollToBottom-padding"]) != null ? _Fa : "0.5rem 0.875rem";
|
|
1015
|
+
cssVars["--persona-scroll-to-bottom-gap"] = (_Ga = cssVars["--persona-components-scrollToBottom-gap"]) != null ? _Ga : "0.5rem";
|
|
1016
|
+
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";
|
|
1017
|
+
cssVars["--persona-scroll-to-bottom-icon-size"] = (_Ja = cssVars["--persona-components-scrollToBottom-iconSize"]) != null ? _Ja : "14px";
|
|
1018
|
+
cssVars["--persona-tool-bubble-shadow"] = (_Ka = cssVars["--persona-components-toolBubble-shadow"]) != null ? _Ka : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1019
|
+
cssVars["--persona-reasoning-bubble-shadow"] = (_La = cssVars["--persona-components-reasoningBubble-shadow"]) != null ? _La : "0 5px 15px rgba(15, 23, 42, 0.08)";
|
|
1020
|
+
cssVars["--persona-composer-shadow"] = (_Ma = cssVars["--persona-components-composer-shadow"]) != null ? _Ma : "none";
|
|
1021
|
+
cssVars["--persona-md-inline-code-bg"] = (_Na = cssVars["--persona-components-markdown-inlineCode-background"]) != null ? _Na : cssVars["--persona-container"];
|
|
1022
|
+
cssVars["--persona-md-inline-code-color"] = (_Oa = cssVars["--persona-components-markdown-inlineCode-foreground"]) != null ? _Oa : cssVars["--persona-text"];
|
|
1023
|
+
cssVars["--persona-md-link-color"] = (_Qa = (_Pa = cssVars["--persona-components-markdown-link-foreground"]) != null ? _Pa : cssVars["--persona-accent"]) != null ? _Qa : "#0f0f0f";
|
|
993
1024
|
const mdH1Size = cssVars["--persona-components-markdown-heading-h1-fontSize"];
|
|
994
1025
|
if (mdH1Size) cssVars["--persona-md-h1-size"] = mdH1Size;
|
|
995
1026
|
const mdH1Weight = cssVars["--persona-components-markdown-heading-h1-fontWeight"];
|
|
@@ -1002,19 +1033,19 @@ function themeToCssVariables(theme) {
|
|
|
1002
1033
|
if (mdProseFont && mdProseFont !== "inherit") {
|
|
1003
1034
|
cssVars["--persona-md-prose-font-family"] = mdProseFont;
|
|
1004
1035
|
}
|
|
1005
|
-
cssVars["--persona-md-code-block-bg"] = (
|
|
1006
|
-
cssVars["--persona-md-code-block-border-color"] = (
|
|
1007
|
-
cssVars["--persona-md-code-block-text-color"] = (
|
|
1008
|
-
cssVars["--persona-md-table-header-bg"] = (
|
|
1009
|
-
cssVars["--persona-md-table-border-color"] = (
|
|
1010
|
-
cssVars["--persona-md-hr-color"] = (
|
|
1011
|
-
cssVars["--persona-md-blockquote-border-color"] = (
|
|
1012
|
-
cssVars["--persona-md-blockquote-bg"] = (
|
|
1013
|
-
cssVars["--persona-md-blockquote-text-color"] = (
|
|
1014
|
-
cssVars["--cw-container"] = (
|
|
1015
|
-
cssVars["--cw-surface"] = (
|
|
1016
|
-
cssVars["--cw-border"] = (
|
|
1017
|
-
cssVars["--persona-message-border"] = (
|
|
1036
|
+
cssVars["--persona-md-code-block-bg"] = (_Ra = cssVars["--persona-components-markdown-codeBlock-background"]) != null ? _Ra : cssVars["--persona-container"];
|
|
1037
|
+
cssVars["--persona-md-code-block-border-color"] = (_Sa = cssVars["--persona-components-markdown-codeBlock-borderColor"]) != null ? _Sa : cssVars["--persona-border"];
|
|
1038
|
+
cssVars["--persona-md-code-block-text-color"] = (_Ta = cssVars["--persona-components-markdown-codeBlock-textColor"]) != null ? _Ta : "inherit";
|
|
1039
|
+
cssVars["--persona-md-table-header-bg"] = (_Ua = cssVars["--persona-components-markdown-table-headerBackground"]) != null ? _Ua : cssVars["--persona-container"];
|
|
1040
|
+
cssVars["--persona-md-table-border-color"] = (_Va = cssVars["--persona-components-markdown-table-borderColor"]) != null ? _Va : cssVars["--persona-border"];
|
|
1041
|
+
cssVars["--persona-md-hr-color"] = (_Wa = cssVars["--persona-components-markdown-hr-color"]) != null ? _Wa : cssVars["--persona-divider"];
|
|
1042
|
+
cssVars["--persona-md-blockquote-border-color"] = (_Xa = cssVars["--persona-components-markdown-blockquote-borderColor"]) != null ? _Xa : cssVars["--persona-palette-colors-gray-900"];
|
|
1043
|
+
cssVars["--persona-md-blockquote-bg"] = (_Ya = cssVars["--persona-components-markdown-blockquote-background"]) != null ? _Ya : "transparent";
|
|
1044
|
+
cssVars["--persona-md-blockquote-text-color"] = (_Za = cssVars["--persona-components-markdown-blockquote-textColor"]) != null ? _Za : cssVars["--persona-palette-colors-gray-500"];
|
|
1045
|
+
cssVars["--cw-container"] = (__a = cssVars["--persona-components-collapsibleWidget-container"]) != null ? __a : cssVars["--persona-surface"];
|
|
1046
|
+
cssVars["--cw-surface"] = (_$a = cssVars["--persona-components-collapsibleWidget-surface"]) != null ? _$a : cssVars["--persona-surface"];
|
|
1047
|
+
cssVars["--cw-border"] = (_ab = cssVars["--persona-components-collapsibleWidget-border"]) != null ? _ab : cssVars["--persona-border"];
|
|
1048
|
+
cssVars["--persona-message-border"] = (_bb = cssVars["--persona-components-message-border"]) != null ? _bb : cssVars["--persona-border"];
|
|
1018
1049
|
const components = theme.components;
|
|
1019
1050
|
const iconBtn = components == null ? void 0 : components.iconButton;
|
|
1020
1051
|
if (iconBtn) {
|
|
@@ -1061,23 +1092,23 @@ function themeToCssVariables(theme) {
|
|
|
1061
1092
|
if (t.copyPadding) cssVars["--persona-artifact-toolbar-copy-padding"] = t.copyPadding;
|
|
1062
1093
|
if (t.copyMenuBackground) {
|
|
1063
1094
|
cssVars["--persona-artifact-toolbar-copy-menu-bg"] = t.copyMenuBackground;
|
|
1064
|
-
cssVars["--persona-dropdown-bg"] = (
|
|
1095
|
+
cssVars["--persona-dropdown-bg"] = (_cb = cssVars["--persona-dropdown-bg"]) != null ? _cb : t.copyMenuBackground;
|
|
1065
1096
|
}
|
|
1066
1097
|
if (t.copyMenuBorder) {
|
|
1067
1098
|
cssVars["--persona-artifact-toolbar-copy-menu-border"] = t.copyMenuBorder;
|
|
1068
|
-
cssVars["--persona-dropdown-border"] = (
|
|
1099
|
+
cssVars["--persona-dropdown-border"] = (_db = cssVars["--persona-dropdown-border"]) != null ? _db : t.copyMenuBorder;
|
|
1069
1100
|
}
|
|
1070
1101
|
if (t.copyMenuShadow) {
|
|
1071
1102
|
cssVars["--persona-artifact-toolbar-copy-menu-shadow"] = t.copyMenuShadow;
|
|
1072
|
-
cssVars["--persona-dropdown-shadow"] = (
|
|
1103
|
+
cssVars["--persona-dropdown-shadow"] = (_eb = cssVars["--persona-dropdown-shadow"]) != null ? _eb : t.copyMenuShadow;
|
|
1073
1104
|
}
|
|
1074
1105
|
if (t.copyMenuBorderRadius) {
|
|
1075
1106
|
cssVars["--persona-artifact-toolbar-copy-menu-radius"] = t.copyMenuBorderRadius;
|
|
1076
|
-
cssVars["--persona-dropdown-radius"] = (
|
|
1107
|
+
cssVars["--persona-dropdown-radius"] = (_fb = cssVars["--persona-dropdown-radius"]) != null ? _fb : t.copyMenuBorderRadius;
|
|
1077
1108
|
}
|
|
1078
1109
|
if (t.copyMenuItemHoverBackground) {
|
|
1079
1110
|
cssVars["--persona-artifact-toolbar-copy-menu-item-hover-bg"] = t.copyMenuItemHoverBackground;
|
|
1080
|
-
cssVars["--persona-dropdown-item-hover-bg"] = (
|
|
1111
|
+
cssVars["--persona-dropdown-item-hover-bg"] = (_gb = cssVars["--persona-dropdown-item-hover-bg"]) != null ? _gb : t.copyMenuItemHoverBackground;
|
|
1081
1112
|
}
|
|
1082
1113
|
if (t.iconBackground) cssVars["--persona-artifact-toolbar-icon-bg"] = t.iconBackground;
|
|
1083
1114
|
if (t.toolbarBorder) cssVars["--persona-artifact-toolbar-border"] = t.toolbarBorder;
|
|
@@ -1097,7 +1128,7 @@ function themeToCssVariables(theme) {
|
|
|
1097
1128
|
if (artifact == null ? void 0 : artifact.pane) {
|
|
1098
1129
|
const t = artifact.pane;
|
|
1099
1130
|
if (t.toolbarBackground) {
|
|
1100
|
-
const toolbarBg = (
|
|
1131
|
+
const toolbarBg = (_hb = resolveTokenValue(theme, t.toolbarBackground)) != null ? _hb : t.toolbarBackground;
|
|
1101
1132
|
cssVars["--persona-artifact-toolbar-bg"] = toolbarBg;
|
|
1102
1133
|
}
|
|
1103
1134
|
}
|
|
@@ -4234,6 +4265,40 @@ var AgentWidgetClient = class {
|
|
|
4234
4265
|
})
|
|
4235
4266
|
});
|
|
4236
4267
|
}
|
|
4268
|
+
/**
|
|
4269
|
+
* Resume a paused flow execution by supplying outputs for LOCAL
|
|
4270
|
+
* (client-executed) tools. Used by the built-in `ask_user_question`
|
|
4271
|
+
* answer-pill sheet, but generic enough for any LOCAL tool.
|
|
4272
|
+
*
|
|
4273
|
+
* Posts to the upstream `/resume` endpoint (the dispatch URL with
|
|
4274
|
+
* `/dispatch` replaced by `/resume` — works for both direct-to-Runtype
|
|
4275
|
+
* and the persona proxy) and returns the raw Response so the caller can
|
|
4276
|
+
* pipe its SSE body through `connectStream()`.
|
|
4277
|
+
*
|
|
4278
|
+
* @param executionId - The paused execution id carried on `step_await`.
|
|
4279
|
+
* @param toolOutputs - Map keyed by tool name → the tool's result value.
|
|
4280
|
+
*/
|
|
4281
|
+
async resumeFlow(executionId, toolOutputs, options) {
|
|
4282
|
+
var _a, _b;
|
|
4283
|
+
const trimmed = ((_a = this.config.apiUrl) == null ? void 0 : _a.replace(/\/+$/, "")) || DEFAULT_CLIENT_API_BASE;
|
|
4284
|
+
const url = `${trimmed}/resume`;
|
|
4285
|
+
let headers = {
|
|
4286
|
+
"Content-Type": "application/json",
|
|
4287
|
+
...this.headers
|
|
4288
|
+
};
|
|
4289
|
+
if (this.getHeaders) {
|
|
4290
|
+
Object.assign(headers, await this.getHeaders());
|
|
4291
|
+
}
|
|
4292
|
+
return fetch(url, {
|
|
4293
|
+
method: "POST",
|
|
4294
|
+
headers,
|
|
4295
|
+
body: JSON.stringify({
|
|
4296
|
+
executionId,
|
|
4297
|
+
toolOutputs,
|
|
4298
|
+
streamResponse: (_b = options == null ? void 0 : options.streamResponse) != null ? _b : true
|
|
4299
|
+
})
|
|
4300
|
+
});
|
|
4301
|
+
}
|
|
4237
4302
|
async buildAgentPayload(messages) {
|
|
4238
4303
|
if (!this.config.agent) {
|
|
4239
4304
|
throw new Error("Agent configuration required for agent mode");
|
|
@@ -4795,7 +4860,7 @@ var AgentWidgetClient = class {
|
|
|
4795
4860
|
const agentIterationMessages = /* @__PURE__ */ new Map();
|
|
4796
4861
|
const iterationDisplay = (_a = this.config.iterationDisplay) != null ? _a : "separate";
|
|
4797
4862
|
drainReadyQueue = () => {
|
|
4798
|
-
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;
|
|
4863
|
+
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;
|
|
4799
4864
|
for (let i = 0; i < seqReadyQueue.length; i++) {
|
|
4800
4865
|
const payloadType = seqReadyQueue[i].payloadType;
|
|
4801
4866
|
const payload = seqReadyQueue[i].payload;
|
|
@@ -4967,8 +5032,26 @@ var AgentWidgetClient = class {
|
|
|
4967
5032
|
if (callKey) {
|
|
4968
5033
|
toolContext.byCall.delete(callKey);
|
|
4969
5034
|
}
|
|
5035
|
+
} else if (payloadType === "step_await" && payload.awaitReason === "local_tool_required" && payload.toolName) {
|
|
5036
|
+
const toolId = (_X = payload.toolId) != null ? _X : `local-${nextSequence()}`;
|
|
5037
|
+
const toolMessage = ensureToolMessage(toolId);
|
|
5038
|
+
const tool = (_Y = toolMessage.toolCall) != null ? _Y : { id: toolId, status: "pending" };
|
|
5039
|
+
tool.name = payload.toolName;
|
|
5040
|
+
tool.args = payload.parameters;
|
|
5041
|
+
tool.status = "complete";
|
|
5042
|
+
tool.chunks = (_Z = tool.chunks) != null ? _Z : [];
|
|
5043
|
+
tool.startedAt = (_$ = tool.startedAt) != null ? _$ : resolveTimestamp((__ = payload.startedAt) != null ? __ : payload.timestamp);
|
|
5044
|
+
tool.completedAt = (_aa = tool.completedAt) != null ? _aa : tool.startedAt;
|
|
5045
|
+
toolMessage.toolCall = tool;
|
|
5046
|
+
toolMessage.streaming = false;
|
|
5047
|
+
toolMessage.agentMetadata = {
|
|
5048
|
+
...toolMessage.agentMetadata,
|
|
5049
|
+
executionId: (_ca = payload.executionId) != null ? _ca : (_ba = toolMessage.agentMetadata) == null ? void 0 : _ba.executionId,
|
|
5050
|
+
awaitingLocalTool: true
|
|
5051
|
+
};
|
|
5052
|
+
emitMessage(toolMessage);
|
|
4970
5053
|
} else if (payloadType === "text_start") {
|
|
4971
|
-
if ((
|
|
5054
|
+
if ((_da = payload.toolContext) == null ? void 0 : _da.toolId) {
|
|
4972
5055
|
continue;
|
|
4973
5056
|
}
|
|
4974
5057
|
const incomingPartId = payload.partId;
|
|
@@ -4986,7 +5069,7 @@ var AgentWidgetClient = class {
|
|
|
4986
5069
|
partIdState.current = incomingPartId;
|
|
4987
5070
|
}
|
|
4988
5071
|
} else if (payloadType === "text_end") {
|
|
4989
|
-
if ((
|
|
5072
|
+
if ((_ea = payload.toolContext) == null ? void 0 : _ea.toolId) {
|
|
4990
5073
|
continue;
|
|
4991
5074
|
}
|
|
4992
5075
|
const prev = assistantMessage;
|
|
@@ -5006,7 +5089,7 @@ var AgentWidgetClient = class {
|
|
|
5006
5089
|
const nestedToolCtx = payload.toolContext;
|
|
5007
5090
|
if (nestedToolCtx == null ? void 0 : nestedToolCtx.toolId) {
|
|
5008
5091
|
const nestedStepId = String(
|
|
5009
|
-
(
|
|
5092
|
+
(_ga = (_fa = payload.id) != null ? _fa : nestedToolCtx.stepId) != null ? _ga : `step-${nextSequence()}`
|
|
5010
5093
|
);
|
|
5011
5094
|
const incomingPartId2 = payload.partId !== void 0 && payload.partId !== null ? String(payload.partId) : "";
|
|
5012
5095
|
const stepScopeKey = `${nestedToolCtx.toolId}::${nestedStepId}`;
|
|
@@ -5033,7 +5116,7 @@ var AgentWidgetClient = class {
|
|
|
5033
5116
|
incomingPartId2,
|
|
5034
5117
|
nestedToolCtx.executionId
|
|
5035
5118
|
);
|
|
5036
|
-
const nestedChunk = (
|
|
5119
|
+
const nestedChunk = (_ka = (_ja = (_ia = (_ha = payload.text) != null ? _ha : payload.delta) != null ? _ia : payload.content) != null ? _ja : payload.chunk) != null ? _ka : "";
|
|
5037
5120
|
if (nestedChunk) {
|
|
5038
5121
|
nestedMsg.content += String(nestedChunk);
|
|
5039
5122
|
nestedMsg.streaming = true;
|
|
@@ -5059,18 +5142,18 @@ var AgentWidgetClient = class {
|
|
|
5059
5142
|
if (incomingPartId !== void 0) {
|
|
5060
5143
|
partIdState.current = incomingPartId;
|
|
5061
5144
|
}
|
|
5062
|
-
const assistant = incomingPartId !== void 0 ? (
|
|
5145
|
+
const assistant = incomingPartId !== void 0 ? (_la = assistantMessagesByPartId.get(incomingPartId)) != null ? _la : ensureAssistantMessage() : ensureAssistantMessage();
|
|
5063
5146
|
if (incomingPartId !== void 0) {
|
|
5064
5147
|
if (!assistant.partId) {
|
|
5065
5148
|
assistant.partId = incomingPartId;
|
|
5066
5149
|
}
|
|
5067
5150
|
assistantMessagesByPartId.set(incomingPartId, assistant);
|
|
5068
5151
|
}
|
|
5069
|
-
const chunk = (
|
|
5152
|
+
const chunk = (_pa = (_oa = (_na = (_ma = payload.text) != null ? _ma : payload.delta) != null ? _na : payload.content) != null ? _oa : payload.chunk) != null ? _pa : "";
|
|
5070
5153
|
if (chunk) {
|
|
5071
5154
|
const chunkSeq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
5072
5155
|
const chunkBufferKey = incomingPartId != null ? incomingPartId : assistant.id;
|
|
5073
|
-
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((
|
|
5156
|
+
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((_qa = rawContentBuffers.get(assistant.id)) != null ? _qa : "") + chunk;
|
|
5074
5157
|
assistant.rawContent = accumulatedRaw;
|
|
5075
5158
|
if (!streamParsers.has(assistant.id)) {
|
|
5076
5159
|
streamParsers.set(assistant.id, this.createStreamParser());
|
|
@@ -5116,7 +5199,7 @@ var AgentWidgetClient = class {
|
|
|
5116
5199
|
emitMessage(assistant);
|
|
5117
5200
|
});
|
|
5118
5201
|
} else {
|
|
5119
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5202
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_ra = parsedResult == null ? void 0 : parsedResult.text) != null ? _ra : null;
|
|
5120
5203
|
if (text !== null && text.trim() !== "") {
|
|
5121
5204
|
assistant.content = text;
|
|
5122
5205
|
emitMessage(assistant);
|
|
@@ -5130,7 +5213,7 @@ var AgentWidgetClient = class {
|
|
|
5130
5213
|
}
|
|
5131
5214
|
}
|
|
5132
5215
|
if (payload.isComplete) {
|
|
5133
|
-
const finalContent = (
|
|
5216
|
+
const finalContent = (_ta = (_sa = payload.result) == null ? void 0 : _sa.response) != null ? _ta : assistant.content;
|
|
5134
5217
|
if (finalContent) {
|
|
5135
5218
|
const rawBuffer = rawContentBuffers.get(assistant.id);
|
|
5136
5219
|
const contentToProcess = rawBuffer != null ? rawBuffer : ensureStringContent(finalContent);
|
|
@@ -5162,7 +5245,7 @@ var AgentWidgetClient = class {
|
|
|
5162
5245
|
}
|
|
5163
5246
|
});
|
|
5164
5247
|
} else {
|
|
5165
|
-
extractedText = typeof parsedResult === "string" ? parsedResult : (
|
|
5248
|
+
extractedText = typeof parsedResult === "string" ? parsedResult : (_ua = parsedResult == null ? void 0 : parsedResult.text) != null ? _ua : null;
|
|
5166
5249
|
}
|
|
5167
5250
|
}
|
|
5168
5251
|
}
|
|
@@ -5174,7 +5257,7 @@ var AgentWidgetClient = class {
|
|
|
5174
5257
|
}
|
|
5175
5258
|
const parserToClose = streamParsers.get(assistant.id);
|
|
5176
5259
|
if (parserToClose) {
|
|
5177
|
-
const closeResult = (
|
|
5260
|
+
const closeResult = (_va = parserToClose.close) == null ? void 0 : _va.call(parserToClose);
|
|
5178
5261
|
if (closeResult instanceof Promise) {
|
|
5179
5262
|
closeResult.catch(() => {
|
|
5180
5263
|
});
|
|
@@ -5196,7 +5279,7 @@ var AgentWidgetClient = class {
|
|
|
5196
5279
|
const nestedCompleteCtx = payload.toolContext;
|
|
5197
5280
|
if (nestedCompleteCtx == null ? void 0 : nestedCompleteCtx.toolId) {
|
|
5198
5281
|
const nestedStepId = String(
|
|
5199
|
-
(
|
|
5282
|
+
(_xa = (_wa = payload.id) != null ? _wa : nestedCompleteCtx.stepId) != null ? _xa : ""
|
|
5200
5283
|
);
|
|
5201
5284
|
if (nestedStepId) {
|
|
5202
5285
|
const prefix = getNestedStepPrefix(
|
|
@@ -5227,7 +5310,7 @@ var AgentWidgetClient = class {
|
|
|
5227
5310
|
emitMessage(msg);
|
|
5228
5311
|
}
|
|
5229
5312
|
}
|
|
5230
|
-
const splitFinalContent = (
|
|
5313
|
+
const splitFinalContent = (_ya = payload.result) == null ? void 0 : _ya.response;
|
|
5231
5314
|
const sealedForReconcile = lastSealedTextSegment;
|
|
5232
5315
|
if (sealedForReconcile) {
|
|
5233
5316
|
if (stepStopReason) sealedForReconcile.stopReason = stepStopReason;
|
|
@@ -5241,7 +5324,7 @@ var AgentWidgetClient = class {
|
|
|
5241
5324
|
lastSealedTextSegment = null;
|
|
5242
5325
|
continue;
|
|
5243
5326
|
}
|
|
5244
|
-
const finalContent = (
|
|
5327
|
+
const finalContent = (_za = payload.result) == null ? void 0 : _za.response;
|
|
5245
5328
|
const assistant = ensureAssistantMessage();
|
|
5246
5329
|
if (stepStopReason) assistant.stopReason = stepStopReason;
|
|
5247
5330
|
if (finalContent !== void 0 && finalContent !== null) {
|
|
@@ -5294,7 +5377,7 @@ var AgentWidgetClient = class {
|
|
|
5294
5377
|
}
|
|
5295
5378
|
});
|
|
5296
5379
|
} else {
|
|
5297
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5380
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_Aa = parsedResult == null ? void 0 : parsedResult.text) != null ? _Aa : null;
|
|
5298
5381
|
if (text !== null && text.trim() !== "") {
|
|
5299
5382
|
assistant.content = text;
|
|
5300
5383
|
hasExtractedText = true;
|
|
@@ -5318,7 +5401,7 @@ var AgentWidgetClient = class {
|
|
|
5318
5401
|
assistant.content = ensureStringContent(finalContent);
|
|
5319
5402
|
}
|
|
5320
5403
|
if (parser) {
|
|
5321
|
-
const closeResult = (
|
|
5404
|
+
const closeResult = (_Ba = parser.close) == null ? void 0 : _Ba.call(parser);
|
|
5322
5405
|
if (closeResult instanceof Promise) {
|
|
5323
5406
|
closeResult.catch(() => {
|
|
5324
5407
|
});
|
|
@@ -5336,7 +5419,7 @@ var AgentWidgetClient = class {
|
|
|
5336
5419
|
emitMessage(assistant);
|
|
5337
5420
|
}
|
|
5338
5421
|
} else if (payloadType === "flow_complete") {
|
|
5339
|
-
const finalContent = (
|
|
5422
|
+
const finalContent = (_Ca = payload.result) == null ? void 0 : _Ca.response;
|
|
5340
5423
|
if (didSplitByPartId) {
|
|
5341
5424
|
if (assistantMessage !== null) {
|
|
5342
5425
|
const msg = assistantMessage;
|
|
@@ -5403,11 +5486,11 @@ var AgentWidgetClient = class {
|
|
|
5403
5486
|
} else if (payloadType === "agent_start") {
|
|
5404
5487
|
agentExecution = {
|
|
5405
5488
|
executionId: payload.executionId,
|
|
5406
|
-
agentId: (
|
|
5407
|
-
agentName: (
|
|
5489
|
+
agentId: (_Da = payload.agentId) != null ? _Da : "virtual",
|
|
5490
|
+
agentName: (_Ea = payload.agentName) != null ? _Ea : "",
|
|
5408
5491
|
status: "running",
|
|
5409
5492
|
currentIteration: 0,
|
|
5410
|
-
maxTurns: (
|
|
5493
|
+
maxTurns: (_Fa = payload.maxTurns) != null ? _Fa : 1,
|
|
5411
5494
|
startedAt: resolveTimestamp(payload.startedAt)
|
|
5412
5495
|
};
|
|
5413
5496
|
} else if (payloadType === "agent_iteration_start") {
|
|
@@ -5427,7 +5510,7 @@ var AgentWidgetClient = class {
|
|
|
5427
5510
|
} else if (payloadType === "agent_turn_delta") {
|
|
5428
5511
|
if (payload.contentType === "text") {
|
|
5429
5512
|
const assistant = ensureAssistantMessage();
|
|
5430
|
-
assistant.content += (
|
|
5513
|
+
assistant.content += (_Ga = payload.delta) != null ? _Ga : "";
|
|
5431
5514
|
assistant.agentMetadata = {
|
|
5432
5515
|
executionId: payload.executionId,
|
|
5433
5516
|
iteration: payload.iteration,
|
|
@@ -5436,14 +5519,14 @@ var AgentWidgetClient = class {
|
|
|
5436
5519
|
};
|
|
5437
5520
|
emitMessage(assistant);
|
|
5438
5521
|
} else if (payload.contentType === "thinking") {
|
|
5439
|
-
const reasoningId = (
|
|
5522
|
+
const reasoningId = (_Ha = payload.turnId) != null ? _Ha : `agent-think-${payload.iteration}`;
|
|
5440
5523
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
5441
|
-
reasoningMessage.reasoning = (
|
|
5524
|
+
reasoningMessage.reasoning = (_Ia = reasoningMessage.reasoning) != null ? _Ia : {
|
|
5442
5525
|
id: reasoningId,
|
|
5443
5526
|
status: "streaming",
|
|
5444
5527
|
chunks: []
|
|
5445
5528
|
};
|
|
5446
|
-
reasoningMessage.reasoning.chunks.push((
|
|
5529
|
+
reasoningMessage.reasoning.chunks.push((_Ja = payload.delta) != null ? _Ja : "");
|
|
5447
5530
|
reasoningMessage.agentMetadata = {
|
|
5448
5531
|
executionId: payload.executionId,
|
|
5449
5532
|
iteration: payload.iteration,
|
|
@@ -5451,12 +5534,12 @@ var AgentWidgetClient = class {
|
|
|
5451
5534
|
};
|
|
5452
5535
|
emitMessage(reasoningMessage);
|
|
5453
5536
|
} else if (payload.contentType === "tool_input") {
|
|
5454
|
-
const toolId = (
|
|
5537
|
+
const toolId = (_Ka = payload.toolCallId) != null ? _Ka : toolContext.lastId;
|
|
5455
5538
|
if (toolId) {
|
|
5456
5539
|
const toolMessage = toolMessages.get(toolId);
|
|
5457
5540
|
if (toolMessage == null ? void 0 : toolMessage.toolCall) {
|
|
5458
|
-
toolMessage.toolCall.chunks = (
|
|
5459
|
-
toolMessage.toolCall.chunks.push((
|
|
5541
|
+
toolMessage.toolCall.chunks = (_La = toolMessage.toolCall.chunks) != null ? _La : [];
|
|
5542
|
+
toolMessage.toolCall.chunks.push((_Ma = payload.delta) != null ? _Ma : "");
|
|
5460
5543
|
emitMessage(toolMessage);
|
|
5461
5544
|
}
|
|
5462
5545
|
}
|
|
@@ -5468,10 +5551,10 @@ var AgentWidgetClient = class {
|
|
|
5468
5551
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
5469
5552
|
reasoningMessage.reasoning.status = "complete";
|
|
5470
5553
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(payload.completedAt);
|
|
5471
|
-
const start = (
|
|
5554
|
+
const start = (_Na = reasoningMessage.reasoning.startedAt) != null ? _Na : Date.now();
|
|
5472
5555
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
5473
5556
|
0,
|
|
5474
|
-
((
|
|
5557
|
+
((_Oa = reasoningMessage.reasoning.completedAt) != null ? _Oa : Date.now()) - start
|
|
5475
5558
|
);
|
|
5476
5559
|
reasoningMessage.streaming = false;
|
|
5477
5560
|
emitMessage(reasoningMessage);
|
|
@@ -5480,17 +5563,17 @@ var AgentWidgetClient = class {
|
|
|
5480
5563
|
const turnStopReason = payload.stopReason;
|
|
5481
5564
|
if (turnStopReason && assistantMessage !== null) {
|
|
5482
5565
|
const turnId = payload.turnId;
|
|
5483
|
-
const matchesTurn = !turnId || ((
|
|
5566
|
+
const matchesTurn = !turnId || ((_Pa = assistantMessage.agentMetadata) == null ? void 0 : _Pa.turnId) === turnId;
|
|
5484
5567
|
if (matchesTurn) {
|
|
5485
5568
|
assistantMessage.stopReason = turnStopReason;
|
|
5486
5569
|
emitMessage(assistantMessage);
|
|
5487
5570
|
}
|
|
5488
5571
|
}
|
|
5489
5572
|
} else if (payloadType === "agent_tool_start") {
|
|
5490
|
-
const toolId = (
|
|
5573
|
+
const toolId = (_Qa = payload.toolCallId) != null ? _Qa : `agent-tool-${nextSequence()}`;
|
|
5491
5574
|
trackToolId(getToolCallKey(payload), toolId);
|
|
5492
5575
|
const toolMessage = ensureToolMessage(toolId);
|
|
5493
|
-
const tool = (
|
|
5576
|
+
const tool = (_Ra = toolMessage.toolCall) != null ? _Ra : {
|
|
5494
5577
|
id: toolId,
|
|
5495
5578
|
status: "pending",
|
|
5496
5579
|
name: void 0,
|
|
@@ -5502,12 +5585,12 @@ var AgentWidgetClient = class {
|
|
|
5502
5585
|
completedAt: void 0,
|
|
5503
5586
|
durationMs: void 0
|
|
5504
5587
|
};
|
|
5505
|
-
tool.name = (
|
|
5588
|
+
tool.name = (_Ta = (_Sa = payload.toolName) != null ? _Sa : payload.name) != null ? _Ta : tool.name;
|
|
5506
5589
|
tool.status = "running";
|
|
5507
5590
|
if (payload.parameters !== void 0) {
|
|
5508
5591
|
tool.args = payload.parameters;
|
|
5509
5592
|
}
|
|
5510
|
-
tool.startedAt = resolveTimestamp((
|
|
5593
|
+
tool.startedAt = resolveTimestamp((_Ua = payload.startedAt) != null ? _Ua : payload.timestamp);
|
|
5511
5594
|
toolMessage.toolCall = tool;
|
|
5512
5595
|
toolMessage.streaming = true;
|
|
5513
5596
|
toolMessage.agentMetadata = {
|
|
@@ -5516,21 +5599,21 @@ var AgentWidgetClient = class {
|
|
|
5516
5599
|
};
|
|
5517
5600
|
emitMessage(toolMessage);
|
|
5518
5601
|
} else if (payloadType === "agent_tool_delta") {
|
|
5519
|
-
const toolId = (
|
|
5602
|
+
const toolId = (_Va = payload.toolCallId) != null ? _Va : toolContext.lastId;
|
|
5520
5603
|
if (toolId) {
|
|
5521
|
-
const toolMessage = (
|
|
5604
|
+
const toolMessage = (_Wa = toolMessages.get(toolId)) != null ? _Wa : ensureToolMessage(toolId);
|
|
5522
5605
|
if (toolMessage.toolCall) {
|
|
5523
|
-
toolMessage.toolCall.chunks = (
|
|
5524
|
-
toolMessage.toolCall.chunks.push((
|
|
5606
|
+
toolMessage.toolCall.chunks = (_Xa = toolMessage.toolCall.chunks) != null ? _Xa : [];
|
|
5607
|
+
toolMessage.toolCall.chunks.push((_Ya = payload.delta) != null ? _Ya : "");
|
|
5525
5608
|
toolMessage.toolCall.status = "running";
|
|
5526
5609
|
toolMessage.streaming = true;
|
|
5527
5610
|
emitMessage(toolMessage);
|
|
5528
5611
|
}
|
|
5529
5612
|
}
|
|
5530
5613
|
} else if (payloadType === "agent_tool_complete") {
|
|
5531
|
-
const toolId = (
|
|
5614
|
+
const toolId = (_Za = payload.toolCallId) != null ? _Za : toolContext.lastId;
|
|
5532
5615
|
if (toolId) {
|
|
5533
|
-
const toolMessage = (
|
|
5616
|
+
const toolMessage = (__a = toolMessages.get(toolId)) != null ? __a : ensureToolMessage(toolId);
|
|
5534
5617
|
if (toolMessage.toolCall) {
|
|
5535
5618
|
toolMessage.toolCall.status = "complete";
|
|
5536
5619
|
if (payload.result !== void 0) {
|
|
@@ -5539,7 +5622,7 @@ var AgentWidgetClient = class {
|
|
|
5539
5622
|
if (typeof payload.executionTime === "number") {
|
|
5540
5623
|
toolMessage.toolCall.durationMs = payload.executionTime;
|
|
5541
5624
|
}
|
|
5542
|
-
toolMessage.toolCall.completedAt = resolveTimestamp((
|
|
5625
|
+
toolMessage.toolCall.completedAt = resolveTimestamp((_$a = payload.completedAt) != null ? _$a : payload.timestamp);
|
|
5543
5626
|
toolMessage.streaming = false;
|
|
5544
5627
|
emitMessage(toolMessage);
|
|
5545
5628
|
const callKey = getToolCallKey(payload);
|
|
@@ -5554,7 +5637,7 @@ var AgentWidgetClient = class {
|
|
|
5554
5637
|
const reflectionMessage = {
|
|
5555
5638
|
id: reflectionId,
|
|
5556
5639
|
role: "assistant",
|
|
5557
|
-
content: (
|
|
5640
|
+
content: (_ab = payload.reflection) != null ? _ab : "",
|
|
5558
5641
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5559
5642
|
streaming: false,
|
|
5560
5643
|
variant: "reasoning",
|
|
@@ -5562,7 +5645,7 @@ var AgentWidgetClient = class {
|
|
|
5562
5645
|
reasoning: {
|
|
5563
5646
|
id: reflectionId,
|
|
5564
5647
|
status: "complete",
|
|
5565
|
-
chunks: [(
|
|
5648
|
+
chunks: [(_bb = payload.reflection) != null ? _bb : ""]
|
|
5566
5649
|
},
|
|
5567
5650
|
agentMetadata: {
|
|
5568
5651
|
executionId: payload.executionId,
|
|
@@ -5583,7 +5666,7 @@ var AgentWidgetClient = class {
|
|
|
5583
5666
|
}
|
|
5584
5667
|
onEvent({ type: "status", status: "idle" });
|
|
5585
5668
|
} else if (payloadType === "agent_error") {
|
|
5586
|
-
const errorMessage = typeof payload.error === "string" ? payload.error : (
|
|
5669
|
+
const errorMessage = typeof payload.error === "string" ? payload.error : (_db = (_cb = payload.error) == null ? void 0 : _cb.message) != null ? _db : "Agent execution error";
|
|
5587
5670
|
if (payload.recoverable) {
|
|
5588
5671
|
if (typeof console !== "undefined") {
|
|
5589
5672
|
console.warn("[AgentWidget] Recoverable agent error:", errorMessage);
|
|
@@ -5596,7 +5679,7 @@ var AgentWidgetClient = class {
|
|
|
5596
5679
|
}
|
|
5597
5680
|
} else if (payloadType === "agent_ping") {
|
|
5598
5681
|
} else if (payloadType === "agent_approval_start") {
|
|
5599
|
-
const approvalId = (
|
|
5682
|
+
const approvalId = (_eb = payload.approvalId) != null ? _eb : `approval-${nextSequence()}`;
|
|
5600
5683
|
const approvalMessage = {
|
|
5601
5684
|
id: `approval-${approvalId}`,
|
|
5602
5685
|
role: "assistant",
|
|
@@ -5608,17 +5691,17 @@ var AgentWidgetClient = class {
|
|
|
5608
5691
|
approval: {
|
|
5609
5692
|
id: approvalId,
|
|
5610
5693
|
status: "pending",
|
|
5611
|
-
agentId: (
|
|
5612
|
-
executionId: (
|
|
5613
|
-
toolName: (
|
|
5694
|
+
agentId: (_fb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _fb : "virtual",
|
|
5695
|
+
executionId: (_hb = (_gb = payload.executionId) != null ? _gb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _hb : "",
|
|
5696
|
+
toolName: (_ib = payload.toolName) != null ? _ib : "",
|
|
5614
5697
|
toolType: payload.toolType,
|
|
5615
|
-
description: (
|
|
5698
|
+
description: (_kb = payload.description) != null ? _kb : `Execute ${(_jb = payload.toolName) != null ? _jb : "tool"}`,
|
|
5616
5699
|
parameters: payload.parameters
|
|
5617
5700
|
}
|
|
5618
5701
|
};
|
|
5619
5702
|
emitMessage(approvalMessage);
|
|
5620
5703
|
} else if (payloadType === "step_await" && payload.awaitReason === "approval_required") {
|
|
5621
|
-
const approvalId = (
|
|
5704
|
+
const approvalId = (_lb = payload.approvalId) != null ? _lb : `approval-${nextSequence()}`;
|
|
5622
5705
|
const approvalMessage = {
|
|
5623
5706
|
id: `approval-${approvalId}`,
|
|
5624
5707
|
role: "assistant",
|
|
@@ -5630,11 +5713,11 @@ var AgentWidgetClient = class {
|
|
|
5630
5713
|
approval: {
|
|
5631
5714
|
id: approvalId,
|
|
5632
5715
|
status: "pending",
|
|
5633
|
-
agentId: (
|
|
5634
|
-
executionId: (
|
|
5635
|
-
toolName: (
|
|
5716
|
+
agentId: (_mb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _mb : "virtual",
|
|
5717
|
+
executionId: (_ob = (_nb = payload.executionId) != null ? _nb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _ob : "",
|
|
5718
|
+
toolName: (_pb = payload.toolName) != null ? _pb : "",
|
|
5636
5719
|
toolType: payload.toolType,
|
|
5637
|
-
description: (
|
|
5720
|
+
description: (_rb = payload.description) != null ? _rb : `Execute ${(_qb = payload.toolName) != null ? _qb : "tool"}`,
|
|
5638
5721
|
parameters: payload.parameters
|
|
5639
5722
|
}
|
|
5640
5723
|
};
|
|
@@ -5653,11 +5736,11 @@ var AgentWidgetClient = class {
|
|
|
5653
5736
|
sequence: nextSequence(),
|
|
5654
5737
|
approval: {
|
|
5655
5738
|
id: approvalId,
|
|
5656
|
-
status: (
|
|
5657
|
-
agentId: (
|
|
5658
|
-
executionId: (
|
|
5659
|
-
toolName: (
|
|
5660
|
-
description: (
|
|
5739
|
+
status: (_sb = payload.decision) != null ? _sb : "approved",
|
|
5740
|
+
agentId: (_tb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _tb : "virtual",
|
|
5741
|
+
executionId: (_vb = (_ub = payload.executionId) != null ? _ub : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _vb : "",
|
|
5742
|
+
toolName: (_wb = payload.toolName) != null ? _wb : "",
|
|
5743
|
+
description: (_xb = payload.description) != null ? _xb : "",
|
|
5661
5744
|
resolvedAt: Date.now()
|
|
5662
5745
|
}
|
|
5663
5746
|
};
|
|
@@ -5695,7 +5778,7 @@ var AgentWidgetClient = class {
|
|
|
5695
5778
|
}
|
|
5696
5779
|
} else if (payloadType === "artifact_delta") {
|
|
5697
5780
|
const deltaId = String(payload.id);
|
|
5698
|
-
const deltaText = typeof payload.delta === "string" ? payload.delta : String((
|
|
5781
|
+
const deltaText = typeof payload.delta === "string" ? payload.delta : String((_yb = payload.delta) != null ? _yb : "");
|
|
5699
5782
|
onEvent({
|
|
5700
5783
|
type: "artifact_delta",
|
|
5701
5784
|
id: deltaId,
|
|
@@ -5718,7 +5801,7 @@ var AgentWidgetClient = class {
|
|
|
5718
5801
|
if (refMsg) {
|
|
5719
5802
|
refMsg.streaming = false;
|
|
5720
5803
|
try {
|
|
5721
|
-
const parsed = JSON.parse((
|
|
5804
|
+
const parsed = JSON.parse((_zb = refMsg.rawContent) != null ? _zb : "{}");
|
|
5722
5805
|
if (parsed.props) {
|
|
5723
5806
|
parsed.props.status = "complete";
|
|
5724
5807
|
const acc = artifactContent.get(artCompleteId);
|
|
@@ -5739,7 +5822,7 @@ var AgentWidgetClient = class {
|
|
|
5739
5822
|
if (!m || typeof m !== "object") {
|
|
5740
5823
|
continue;
|
|
5741
5824
|
}
|
|
5742
|
-
const id = String((
|
|
5825
|
+
const id = String((_Ab = m.id) != null ? _Ab : `msg-${nextSequence()}`);
|
|
5743
5826
|
const roleRaw = m.role;
|
|
5744
5827
|
const role = roleRaw === "user" ? "user" : roleRaw === "system" ? "system" : "assistant";
|
|
5745
5828
|
const msg = {
|
|
@@ -5758,7 +5841,7 @@ var AgentWidgetClient = class {
|
|
|
5758
5841
|
if (msg.rawContent) {
|
|
5759
5842
|
try {
|
|
5760
5843
|
const parsed = JSON.parse(msg.rawContent);
|
|
5761
|
-
const refArtId = (
|
|
5844
|
+
const refArtId = (_Bb = parsed == null ? void 0 : parsed.props) == null ? void 0 : _Bb.artifactId;
|
|
5762
5845
|
if (typeof refArtId === "string") {
|
|
5763
5846
|
artifactIdsWithCards.add(refArtId);
|
|
5764
5847
|
}
|
|
@@ -5774,7 +5857,7 @@ var AgentWidgetClient = class {
|
|
|
5774
5857
|
if (payload.error instanceof Error) {
|
|
5775
5858
|
resolvedError = payload.error;
|
|
5776
5859
|
} else if (payloadType === "dispatch_error") {
|
|
5777
|
-
const msg = (
|
|
5860
|
+
const msg = (_Cb = payload.message) != null ? _Cb : payload.error;
|
|
5778
5861
|
if (msg != null && msg !== "") {
|
|
5779
5862
|
resolvedError = new Error(String(msg));
|
|
5780
5863
|
}
|
|
@@ -5783,7 +5866,7 @@ var AgentWidgetClient = class {
|
|
|
5783
5866
|
if (typeof e === "string" && e !== "") {
|
|
5784
5867
|
resolvedError = new Error(e);
|
|
5785
5868
|
} else if (e != null && typeof e === "object" && "message" in e) {
|
|
5786
|
-
resolvedError = new Error(String((
|
|
5869
|
+
resolvedError = new Error(String((_Db = e.message) != null ? _Db : e));
|
|
5787
5870
|
}
|
|
5788
5871
|
} else if (payloadType === "error" && payload.error != null && payload.error !== "") {
|
|
5789
5872
|
resolvedError = new Error(String(payload.error));
|
|
@@ -6887,7 +6970,7 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
6887
6970
|
this.applyArtifactStreamEvent(event);
|
|
6888
6971
|
}
|
|
6889
6972
|
};
|
|
6890
|
-
var _a;
|
|
6973
|
+
var _a, _b;
|
|
6891
6974
|
this.messages = [...(_a = config.initialMessages) != null ? _a : []].map((message) => {
|
|
6892
6975
|
var _a2;
|
|
6893
6976
|
return {
|
|
@@ -6897,9 +6980,18 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
6897
6980
|
});
|
|
6898
6981
|
this.messages = this.sortMessages(this.messages);
|
|
6899
6982
|
this.client = new AgentWidgetClient(config);
|
|
6983
|
+
for (const rec of (_b = config.initialArtifacts) != null ? _b : []) {
|
|
6984
|
+
this.artifacts.set(rec.id, { ...rec, status: "complete" });
|
|
6985
|
+
}
|
|
6986
|
+
if (config.initialSelectedArtifactId != null) {
|
|
6987
|
+
this.selectedArtifactId = config.initialSelectedArtifactId;
|
|
6988
|
+
}
|
|
6900
6989
|
if (this.messages.length) {
|
|
6901
6990
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
6902
6991
|
}
|
|
6992
|
+
if (this.artifacts.size > 0) {
|
|
6993
|
+
this.emitArtifactsState();
|
|
6994
|
+
}
|
|
6903
6995
|
this.callbacks.onStatusChanged(this.status);
|
|
6904
6996
|
}
|
|
6905
6997
|
/**
|
|
@@ -7624,6 +7716,141 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7624
7716
|
);
|
|
7625
7717
|
}
|
|
7626
7718
|
}
|
|
7719
|
+
/**
|
|
7720
|
+
* Resolve a paused `ask_user_question` LOCAL tool call.
|
|
7721
|
+
*
|
|
7722
|
+
* When the server emits `step_await` for `ask_user_question`, the widget
|
|
7723
|
+
* renders the answer-pill sheet and calls this method once the user
|
|
7724
|
+
* picks. Steps:
|
|
7725
|
+
* 1. POST the answer to `/resume` via `client.resumeFlow`.
|
|
7726
|
+
* 2. Pipe the resulting SSE stream through `connectStream()` so the
|
|
7727
|
+
* paused agent execution continues.
|
|
7728
|
+
* 3. Append a user-visible bubble with the answer text so the
|
|
7729
|
+
* transcript reads naturally.
|
|
7730
|
+
*/
|
|
7731
|
+
/**
|
|
7732
|
+
* Persist in-progress answers and the current page index for a multi-question
|
|
7733
|
+
* `ask_user_question` payload, so a refresh resumes on the same page with
|
|
7734
|
+
* prior answers intact. Called by ui.ts on every Back/Next/pick interaction.
|
|
7735
|
+
*/
|
|
7736
|
+
persistAskUserQuestionProgress(toolMessage, progress) {
|
|
7737
|
+
const current = this.messages.find((m) => m.id === toolMessage.id);
|
|
7738
|
+
if (!current) return;
|
|
7739
|
+
this.upsertMessage({
|
|
7740
|
+
...current,
|
|
7741
|
+
agentMetadata: {
|
|
7742
|
+
...current.agentMetadata,
|
|
7743
|
+
askUserQuestionAnswers: progress.answers,
|
|
7744
|
+
askUserQuestionIndex: progress.currentIndex
|
|
7745
|
+
}
|
|
7746
|
+
});
|
|
7747
|
+
}
|
|
7748
|
+
/**
|
|
7749
|
+
* Flip an `ask_user_question` tool message from awaiting → answered so
|
|
7750
|
+
* render passes stop re-mounting its answer-pill sheet. Idempotent.
|
|
7751
|
+
* When `answers` is provided, persists the full structured answer Record
|
|
7752
|
+
* atomically with the answered flag — guarding against later events that
|
|
7753
|
+
* could re-emit the tool message and clobber the per-pick persisted
|
|
7754
|
+
* answers via top-level merge.
|
|
7755
|
+
*/
|
|
7756
|
+
markAskUserQuestionResolved(toolMessage, answers) {
|
|
7757
|
+
const current = this.messages.find((m) => m.id === toolMessage.id);
|
|
7758
|
+
if (!current) return;
|
|
7759
|
+
this.upsertMessage({
|
|
7760
|
+
...current,
|
|
7761
|
+
agentMetadata: {
|
|
7762
|
+
...current.agentMetadata,
|
|
7763
|
+
awaitingLocalTool: false,
|
|
7764
|
+
askUserQuestionAnswered: true,
|
|
7765
|
+
...answers ? { askUserQuestionAnswers: answers } : {}
|
|
7766
|
+
}
|
|
7767
|
+
});
|
|
7768
|
+
}
|
|
7769
|
+
async resolveAskUserQuestion(toolMessage, answer) {
|
|
7770
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7771
|
+
const live = this.messages.find((m) => m.id === toolMessage.id);
|
|
7772
|
+
if (((_a = live == null ? void 0 : live.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswered) === true) return;
|
|
7773
|
+
const executionId = (_b = toolMessage.agentMetadata) == null ? void 0 : _b.executionId;
|
|
7774
|
+
const toolName = (_c = toolMessage.toolCall) == null ? void 0 : _c.name;
|
|
7775
|
+
if (!executionId || !toolName) {
|
|
7776
|
+
(_e = (_d = this.callbacks).onError) == null ? void 0 : _e.call(
|
|
7777
|
+
_d,
|
|
7778
|
+
new Error(
|
|
7779
|
+
"resolveAskUserQuestion: message is missing executionId or toolCall.name"
|
|
7780
|
+
)
|
|
7781
|
+
);
|
|
7782
|
+
return;
|
|
7783
|
+
}
|
|
7784
|
+
let structuredAnswers = typeof answer === "string" ? void 0 : answer;
|
|
7785
|
+
if (structuredAnswers === void 0 && typeof answer === "string") {
|
|
7786
|
+
const args2 = (_f = toolMessage.toolCall) == null ? void 0 : _f.args;
|
|
7787
|
+
const questions2 = Array.isArray(args2 == null ? void 0 : args2.questions) ? args2.questions : [];
|
|
7788
|
+
if (questions2.length === 1) {
|
|
7789
|
+
const qText = typeof ((_g = questions2[0]) == null ? void 0 : _g.question) === "string" ? questions2[0].question : "";
|
|
7790
|
+
if (qText) structuredAnswers = { [qText]: answer };
|
|
7791
|
+
}
|
|
7792
|
+
}
|
|
7793
|
+
this.markAskUserQuestionResolved(toolMessage, structuredAnswers);
|
|
7794
|
+
const toolCallId = toolMessage.toolCall.id;
|
|
7795
|
+
const args = (_h = toolMessage.toolCall) == null ? void 0 : _h.args;
|
|
7796
|
+
const questions = Array.isArray(args == null ? void 0 : args.questions) ? args.questions : [];
|
|
7797
|
+
if (questions.length === 0) {
|
|
7798
|
+
const fallback = typeof answer === "string" ? answer : Object.entries(answer).map(
|
|
7799
|
+
([q, v]) => `${q}: ${Array.isArray(v) ? v.join(", ") : v}`
|
|
7800
|
+
).join(" | ");
|
|
7801
|
+
this.appendMessage({
|
|
7802
|
+
id: `ask-user-answer-${toolCallId}`,
|
|
7803
|
+
role: "user",
|
|
7804
|
+
content: fallback,
|
|
7805
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7806
|
+
streaming: false,
|
|
7807
|
+
sequence: this.nextSequence()
|
|
7808
|
+
});
|
|
7809
|
+
} else {
|
|
7810
|
+
const stored = structuredAnswers != null ? structuredAnswers : {};
|
|
7811
|
+
questions.forEach((p, i) => {
|
|
7812
|
+
const qText = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
7813
|
+
if (!qText) return;
|
|
7814
|
+
const ans = stored[qText];
|
|
7815
|
+
const answerStr = Array.isArray(ans) ? ans.join(", ") : typeof ans === "string" ? ans : "";
|
|
7816
|
+
this.appendMessage({
|
|
7817
|
+
id: `ask-user-q-${toolCallId}-${i}`,
|
|
7818
|
+
role: "assistant",
|
|
7819
|
+
content: qText,
|
|
7820
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7821
|
+
streaming: false,
|
|
7822
|
+
sequence: this.nextSequence()
|
|
7823
|
+
});
|
|
7824
|
+
this.appendMessage({
|
|
7825
|
+
id: `ask-user-a-${toolCallId}-${i}`,
|
|
7826
|
+
role: "user",
|
|
7827
|
+
content: answerStr || "*Skipped*",
|
|
7828
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7829
|
+
streaming: false,
|
|
7830
|
+
sequence: this.nextSequence()
|
|
7831
|
+
});
|
|
7832
|
+
});
|
|
7833
|
+
}
|
|
7834
|
+
try {
|
|
7835
|
+
const response = await this.client.resumeFlow(executionId, {
|
|
7836
|
+
[toolName]: answer
|
|
7837
|
+
});
|
|
7838
|
+
if (!response.ok) {
|
|
7839
|
+
const errorData = await response.json().catch(() => null);
|
|
7840
|
+
throw new Error(
|
|
7841
|
+
(_i = errorData == null ? void 0 : errorData.error) != null ? _i : `Resume failed: ${response.status}`
|
|
7842
|
+
);
|
|
7843
|
+
}
|
|
7844
|
+
if (response.body) {
|
|
7845
|
+
await this.connectStream(response.body);
|
|
7846
|
+
}
|
|
7847
|
+
} catch (error) {
|
|
7848
|
+
(_k = (_j = this.callbacks).onError) == null ? void 0 : _k.call(
|
|
7849
|
+
_j,
|
|
7850
|
+
error instanceof Error ? error : new Error(String(error))
|
|
7851
|
+
);
|
|
7852
|
+
}
|
|
7853
|
+
}
|
|
7627
7854
|
cancel() {
|
|
7628
7855
|
var _a;
|
|
7629
7856
|
(_a = this.abortController) == null ? void 0 : _a.abort();
|
|
@@ -7771,6 +7998,14 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7771
7998
|
this.setStatus("idle");
|
|
7772
7999
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
7773
8000
|
}
|
|
8001
|
+
hydrateArtifacts(artifacts, selectedId = null) {
|
|
8002
|
+
this.artifacts.clear();
|
|
8003
|
+
for (const rec of artifacts) {
|
|
8004
|
+
this.artifacts.set(rec.id, { ...rec, status: "complete" });
|
|
8005
|
+
}
|
|
8006
|
+
this.selectedArtifactId = selectedId;
|
|
8007
|
+
this.emitArtifactsState();
|
|
8008
|
+
}
|
|
7774
8009
|
setStatus(status) {
|
|
7775
8010
|
if (this.status === status) return;
|
|
7776
8011
|
this.status = status;
|
|
@@ -7877,9 +8112,24 @@ var AgentWidgetSession = class _AgentWidgetSession {
|
|
|
7877
8112
|
this.appendMessage(withSequence);
|
|
7878
8113
|
return;
|
|
7879
8114
|
}
|
|
7880
|
-
this.messages = this.messages.map(
|
|
7881
|
-
|
|
7882
|
-
|
|
8115
|
+
this.messages = this.messages.map((existing, idx) => {
|
|
8116
|
+
var _a;
|
|
8117
|
+
if (idx !== index) return existing;
|
|
8118
|
+
const merged = { ...existing, ...withSequence };
|
|
8119
|
+
if (((_a = existing.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswered) === true && withSequence.agentMetadata) {
|
|
8120
|
+
merged.agentMetadata = {
|
|
8121
|
+
...withSequence.agentMetadata,
|
|
8122
|
+
askUserQuestionAnswered: true,
|
|
8123
|
+
...existing.agentMetadata.askUserQuestionAnswers ? {
|
|
8124
|
+
askUserQuestionAnswers: existing.agentMetadata.askUserQuestionAnswers
|
|
8125
|
+
} : {},
|
|
8126
|
+
// Keep awaiting flag false once resolved — never let a stale
|
|
8127
|
+
// re-emit flip us back to awaiting.
|
|
8128
|
+
awaitingLocalTool: false
|
|
8129
|
+
};
|
|
8130
|
+
}
|
|
8131
|
+
return merged;
|
|
8132
|
+
});
|
|
7883
8133
|
this.messages = this.sortMessages(this.messages);
|
|
7884
8134
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
7885
8135
|
}
|
|
@@ -10165,8 +10415,11 @@ var buildPanel = (config, showClose = true) => {
|
|
|
10165
10415
|
);
|
|
10166
10416
|
body.id = "persona-scroll-container";
|
|
10167
10417
|
body.setAttribute("data-persona-theme-zone", "messages");
|
|
10168
|
-
const
|
|
10169
|
-
|
|
10418
|
+
const introCard = createElement(
|
|
10419
|
+
"div",
|
|
10420
|
+
"persona-rounded-2xl persona-bg-persona-surface persona-p-6"
|
|
10421
|
+
);
|
|
10422
|
+
introCard.style.boxShadow = isDockedMountMode(config) ? "none" : "var(--persona-intro-card-shadow, 0 5px 15px rgba(15, 23, 42, 0.08))";
|
|
10170
10423
|
const introTitle = createElement(
|
|
10171
10424
|
"h2",
|
|
10172
10425
|
"persona-text-lg persona-font-semibold persona-text-persona-primary"
|
|
@@ -10206,16 +10459,28 @@ var buildPanel = (config, showClose = true) => {
|
|
|
10206
10459
|
attachHeaderToContainer(container, headerElements, config);
|
|
10207
10460
|
}
|
|
10208
10461
|
container.append(body);
|
|
10462
|
+
const composerOverlay = createElement(
|
|
10463
|
+
"div",
|
|
10464
|
+
"persona-composer-overlay persona-pointer-events-none"
|
|
10465
|
+
);
|
|
10466
|
+
composerOverlay.setAttribute("data-persona-composer-overlay", "");
|
|
10467
|
+
composerOverlay.style.position = "absolute";
|
|
10468
|
+
composerOverlay.style.left = "0";
|
|
10469
|
+
composerOverlay.style.right = "0";
|
|
10470
|
+
composerOverlay.style.bottom = "0";
|
|
10471
|
+
composerOverlay.style.zIndex = "20";
|
|
10209
10472
|
if (showFooter) {
|
|
10210
10473
|
container.append(composerElements.footer);
|
|
10211
10474
|
} else {
|
|
10212
10475
|
composerElements.footer.style.display = "none";
|
|
10213
10476
|
container.append(composerElements.footer);
|
|
10214
10477
|
}
|
|
10478
|
+
container.append(composerOverlay);
|
|
10215
10479
|
return {
|
|
10216
10480
|
container,
|
|
10217
10481
|
body,
|
|
10218
10482
|
messagesWrapper,
|
|
10483
|
+
composerOverlay,
|
|
10219
10484
|
suggestions: composerElements.suggestions,
|
|
10220
10485
|
textarea: composerElements.textarea,
|
|
10221
10486
|
sendButton: composerElements.sendButton,
|
|
@@ -11481,6 +11746,582 @@ var createToolBubble = (message, config) => {
|
|
|
11481
11746
|
return bubble;
|
|
11482
11747
|
};
|
|
11483
11748
|
|
|
11749
|
+
// src/components/ask-user-question-bubble.ts
|
|
11750
|
+
import { parse as parsePartialJson2, ARR, OBJ as OBJ2, STR as STR2 } from "partial-json";
|
|
11751
|
+
var ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
11752
|
+
var ASK_USER_QUESTION_MAX = 8;
|
|
11753
|
+
var SHEET_SENTINEL = "data-persona-ask-sheet-for";
|
|
11754
|
+
var DEFAULT_FREE_TEXT_LABEL_ROWS = "Other";
|
|
11755
|
+
var DEFAULT_FREE_TEXT_LABEL_PILLS = "Other\u2026";
|
|
11756
|
+
var DEFAULT_FREE_TEXT_PLACEHOLDER = "Type your own answer here";
|
|
11757
|
+
var DEFAULT_SUBMIT_LABEL = "Send";
|
|
11758
|
+
var DEFAULT_NEXT_LABEL = "Next";
|
|
11759
|
+
var DEFAULT_BACK_LABEL = "Back";
|
|
11760
|
+
var DEFAULT_SUBMIT_ALL_LABEL = "Submit all";
|
|
11761
|
+
var DEFAULT_SKIP_LABEL = "Skip";
|
|
11762
|
+
var DEFAULT_SKELETON_PILLS = 3;
|
|
11763
|
+
var ATTR_CURRENT_INDEX = "data-ask-current-index";
|
|
11764
|
+
var ATTR_QUESTION_COUNT = "data-ask-question-count";
|
|
11765
|
+
var ATTR_ANSWERS = "data-ask-answers";
|
|
11766
|
+
var ATTR_GROUPED = "data-ask-grouped";
|
|
11767
|
+
var ATTR_LAYOUT = "data-ask-layout";
|
|
11768
|
+
var resolveLayout = (feature) => feature.layout === "pills" ? "pills" : "rows";
|
|
11769
|
+
var getLayout = (sheet) => sheet.getAttribute(ATTR_LAYOUT) === "pills" ? "pills" : "rows";
|
|
11770
|
+
var truncateWarned = false;
|
|
11771
|
+
var escapeAttrValue = (value) => value.replace(/["\\]/g, "\\$&");
|
|
11772
|
+
var isAskUserQuestionMessage = (message) => {
|
|
11773
|
+
return message.variant === "tool" && !!message.toolCall && message.toolCall.name === ASK_USER_QUESTION_TOOL_NAME;
|
|
11774
|
+
};
|
|
11775
|
+
var resolveFeature = (config) => {
|
|
11776
|
+
var _a, _b;
|
|
11777
|
+
return (_b = (_a = config == null ? void 0 : config.features) == null ? void 0 : _a.askUserQuestion) != null ? _b : {};
|
|
11778
|
+
};
|
|
11779
|
+
var parseAskUserQuestionPayload = (message) => {
|
|
11780
|
+
const toolCall = message.toolCall;
|
|
11781
|
+
if (!toolCall) return { payload: null, complete: false };
|
|
11782
|
+
const complete = toolCall.status === "complete";
|
|
11783
|
+
if (toolCall.args && typeof toolCall.args === "object") {
|
|
11784
|
+
return { payload: toolCall.args, complete };
|
|
11785
|
+
}
|
|
11786
|
+
const chunks = toolCall.chunks;
|
|
11787
|
+
if (!chunks || chunks.length === 0) return { payload: null, complete };
|
|
11788
|
+
try {
|
|
11789
|
+
const text = chunks.join("");
|
|
11790
|
+
const parsed = parsePartialJson2(text, STR2 | OBJ2 | ARR);
|
|
11791
|
+
if (parsed && typeof parsed === "object") {
|
|
11792
|
+
return { payload: parsed, complete };
|
|
11793
|
+
}
|
|
11794
|
+
} catch {
|
|
11795
|
+
}
|
|
11796
|
+
return { payload: null, complete };
|
|
11797
|
+
};
|
|
11798
|
+
var promptsFromPayload = (payload) => {
|
|
11799
|
+
const all = Array.isArray(payload == null ? void 0 : payload.questions) ? payload.questions : [];
|
|
11800
|
+
if (all.length > ASK_USER_QUESTION_MAX && !truncateWarned) {
|
|
11801
|
+
truncateWarned = true;
|
|
11802
|
+
if (typeof console !== "undefined") {
|
|
11803
|
+
console.warn(
|
|
11804
|
+
`[AgentWidget] ask_user_question received ${all.length} questions; truncating to ${ASK_USER_QUESTION_MAX}.`
|
|
11805
|
+
);
|
|
11806
|
+
}
|
|
11807
|
+
}
|
|
11808
|
+
return all.slice(0, ASK_USER_QUESTION_MAX);
|
|
11809
|
+
};
|
|
11810
|
+
var firstPrompt = (payload) => {
|
|
11811
|
+
var _a;
|
|
11812
|
+
return (_a = promptsFromPayload(payload)[0]) != null ? _a : null;
|
|
11813
|
+
};
|
|
11814
|
+
var promptAt = (payload, index) => {
|
|
11815
|
+
var _a;
|
|
11816
|
+
return (_a = promptsFromPayload(payload)[index]) != null ? _a : null;
|
|
11817
|
+
};
|
|
11818
|
+
var applyStyleVars = (root, feature) => {
|
|
11819
|
+
const s = feature.styles;
|
|
11820
|
+
if (!s) return;
|
|
11821
|
+
if (s.sheetBackground) root.style.setProperty("--persona-ask-sheet-bg", s.sheetBackground);
|
|
11822
|
+
if (s.sheetBorder) root.style.setProperty("--persona-ask-sheet-border", s.sheetBorder);
|
|
11823
|
+
if (s.sheetShadow) root.style.setProperty("--persona-ask-sheet-shadow", s.sheetShadow);
|
|
11824
|
+
if (s.pillBackground) root.style.setProperty("--persona-ask-pill-bg", s.pillBackground);
|
|
11825
|
+
if (s.pillBackgroundSelected)
|
|
11826
|
+
root.style.setProperty("--persona-ask-pill-bg-selected", s.pillBackgroundSelected);
|
|
11827
|
+
if (s.pillTextColor) root.style.setProperty("--persona-ask-pill-fg", s.pillTextColor);
|
|
11828
|
+
if (s.pillTextColorSelected)
|
|
11829
|
+
root.style.setProperty("--persona-ask-pill-fg-selected", s.pillTextColorSelected);
|
|
11830
|
+
if (s.pillBorderRadius) root.style.setProperty("--persona-ask-pill-radius", s.pillBorderRadius);
|
|
11831
|
+
if (s.customInputBackground)
|
|
11832
|
+
root.style.setProperty("--persona-ask-input-bg", s.customInputBackground);
|
|
11833
|
+
};
|
|
11834
|
+
var buildAffordance = (layout, multiSelect, index) => {
|
|
11835
|
+
if (layout !== "rows") return null;
|
|
11836
|
+
const wrap = createElement("span", "persona-ask-row-affordance");
|
|
11837
|
+
wrap.setAttribute("aria-hidden", "true");
|
|
11838
|
+
if (multiSelect) {
|
|
11839
|
+
const check = createElement("span", "persona-ask-row-check");
|
|
11840
|
+
wrap.appendChild(check);
|
|
11841
|
+
} else {
|
|
11842
|
+
const badge = createElement("span", "persona-ask-row-badge");
|
|
11843
|
+
badge.textContent = String(index + 1);
|
|
11844
|
+
wrap.appendChild(badge);
|
|
11845
|
+
}
|
|
11846
|
+
return wrap;
|
|
11847
|
+
};
|
|
11848
|
+
var buildPill = (option, index, layout, multiSelect) => {
|
|
11849
|
+
const cls = layout === "rows" ? "persona-ask-pill persona-ask-row persona-pointer-events-auto" : "persona-ask-pill persona-pointer-events-auto";
|
|
11850
|
+
const btn = createElement("button", cls);
|
|
11851
|
+
btn.type = "button";
|
|
11852
|
+
btn.setAttribute("role", multiSelect ? "checkbox" : "button");
|
|
11853
|
+
btn.setAttribute("aria-pressed", "false");
|
|
11854
|
+
btn.setAttribute("data-ask-user-action", "pick");
|
|
11855
|
+
btn.setAttribute("data-option-index", String(index));
|
|
11856
|
+
btn.setAttribute("data-option-label", option.label);
|
|
11857
|
+
if (layout === "rows") {
|
|
11858
|
+
const content = createElement("span", "persona-ask-row-content");
|
|
11859
|
+
const label = createElement("span", "persona-ask-row-label");
|
|
11860
|
+
label.textContent = option.label;
|
|
11861
|
+
content.appendChild(label);
|
|
11862
|
+
if (option.description) {
|
|
11863
|
+
const desc = createElement("span", "persona-ask-row-description");
|
|
11864
|
+
desc.textContent = option.description;
|
|
11865
|
+
content.appendChild(desc);
|
|
11866
|
+
}
|
|
11867
|
+
btn.appendChild(content);
|
|
11868
|
+
const aff = buildAffordance(layout, multiSelect, index);
|
|
11869
|
+
if (aff) btn.appendChild(aff);
|
|
11870
|
+
} else {
|
|
11871
|
+
btn.textContent = option.label;
|
|
11872
|
+
if (option.description) btn.title = option.description;
|
|
11873
|
+
}
|
|
11874
|
+
return btn;
|
|
11875
|
+
};
|
|
11876
|
+
var buildSkeletonPill = (layout) => {
|
|
11877
|
+
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";
|
|
11878
|
+
const el = createElement("span", cls);
|
|
11879
|
+
el.setAttribute("aria-hidden", "true");
|
|
11880
|
+
return el;
|
|
11881
|
+
};
|
|
11882
|
+
var buildPillList = (prompt, feature, complete, layout) => {
|
|
11883
|
+
var _a, _b, _c;
|
|
11884
|
+
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";
|
|
11885
|
+
const list = createElement("div", baseClass);
|
|
11886
|
+
list.setAttribute("role", "group");
|
|
11887
|
+
list.setAttribute("data-ask-pill-list", "true");
|
|
11888
|
+
const multiSelect = !!(prompt == null ? void 0 : prompt.multiSelect);
|
|
11889
|
+
const realOptions = Array.isArray(prompt == null ? void 0 : prompt.options) ? prompt.options : [];
|
|
11890
|
+
const cleanOptions = realOptions.filter((o) => o && typeof o.label === "string" && o.label.length > 0);
|
|
11891
|
+
if (cleanOptions.length === 0 && !complete) {
|
|
11892
|
+
for (let i = 0; i < DEFAULT_SKELETON_PILLS; i++) {
|
|
11893
|
+
list.appendChild(buildSkeletonPill(layout));
|
|
11894
|
+
}
|
|
11895
|
+
return list;
|
|
11896
|
+
}
|
|
11897
|
+
cleanOptions.forEach((option, index) => {
|
|
11898
|
+
list.appendChild(buildPill(option, index, layout, multiSelect));
|
|
11899
|
+
});
|
|
11900
|
+
const allowFreeText = (prompt == null ? void 0 : prompt.allowFreeText) !== false;
|
|
11901
|
+
if (allowFreeText) {
|
|
11902
|
+
const defaultLabel = layout === "rows" ? DEFAULT_FREE_TEXT_LABEL_ROWS : DEFAULT_FREE_TEXT_LABEL_PILLS;
|
|
11903
|
+
if (layout === "rows") {
|
|
11904
|
+
const otherRow = createElement(
|
|
11905
|
+
"div",
|
|
11906
|
+
"persona-ask-pill persona-ask-row persona-ask-row--other persona-ask-pill-custom persona-pointer-events-auto"
|
|
11907
|
+
);
|
|
11908
|
+
otherRow.setAttribute("data-ask-user-action", "focus-free-text");
|
|
11909
|
+
otherRow.setAttribute("data-option-index", String(cleanOptions.length));
|
|
11910
|
+
otherRow.setAttribute("data-ask-other-row", "true");
|
|
11911
|
+
const content = createElement("span", "persona-ask-row-content");
|
|
11912
|
+
const input = document.createElement("input");
|
|
11913
|
+
input.type = "text";
|
|
11914
|
+
input.className = "persona-ask-row-input persona-flex-1 persona-pointer-events-auto";
|
|
11915
|
+
input.placeholder = (_a = feature.freeTextPlaceholder) != null ? _a : DEFAULT_FREE_TEXT_PLACEHOLDER;
|
|
11916
|
+
input.setAttribute("data-ask-free-text-input", "true");
|
|
11917
|
+
input.setAttribute(
|
|
11918
|
+
"aria-label",
|
|
11919
|
+
(_b = feature.freeTextLabel) != null ? _b : defaultLabel
|
|
11920
|
+
);
|
|
11921
|
+
content.appendChild(input);
|
|
11922
|
+
otherRow.appendChild(content);
|
|
11923
|
+
const aff = buildAffordance(layout, multiSelect, cleanOptions.length);
|
|
11924
|
+
if (aff) otherRow.appendChild(aff);
|
|
11925
|
+
list.appendChild(otherRow);
|
|
11926
|
+
} else {
|
|
11927
|
+
const freeBtn = createElement(
|
|
11928
|
+
"button",
|
|
11929
|
+
"persona-ask-pill persona-ask-pill-custom persona-pointer-events-auto"
|
|
11930
|
+
);
|
|
11931
|
+
freeBtn.type = "button";
|
|
11932
|
+
freeBtn.setAttribute("data-ask-user-action", "open-free-text");
|
|
11933
|
+
freeBtn.textContent = (_c = feature.freeTextLabel) != null ? _c : defaultLabel;
|
|
11934
|
+
list.appendChild(freeBtn);
|
|
11935
|
+
}
|
|
11936
|
+
}
|
|
11937
|
+
return list;
|
|
11938
|
+
};
|
|
11939
|
+
var buildFreeTextRow = (feature, layout) => {
|
|
11940
|
+
var _a, _b;
|
|
11941
|
+
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";
|
|
11942
|
+
const row = createElement("div", cls);
|
|
11943
|
+
row.setAttribute("data-ask-free-text-row", "true");
|
|
11944
|
+
const input = document.createElement("input");
|
|
11945
|
+
input.type = "text";
|
|
11946
|
+
input.className = "persona-ask-free-text-input persona-flex-1 persona-pointer-events-auto";
|
|
11947
|
+
input.placeholder = (_a = feature.freeTextPlaceholder) != null ? _a : DEFAULT_FREE_TEXT_PLACEHOLDER;
|
|
11948
|
+
input.setAttribute("data-ask-free-text-input", "true");
|
|
11949
|
+
row.appendChild(input);
|
|
11950
|
+
if (layout !== "rows") {
|
|
11951
|
+
const submit = createElement(
|
|
11952
|
+
"button",
|
|
11953
|
+
"persona-ask-free-text-submit persona-pointer-events-auto"
|
|
11954
|
+
);
|
|
11955
|
+
submit.type = "button";
|
|
11956
|
+
submit.textContent = (_b = feature.submitLabel) != null ? _b : DEFAULT_SUBMIT_LABEL;
|
|
11957
|
+
submit.setAttribute("data-ask-user-action", "submit-free-text");
|
|
11958
|
+
row.appendChild(submit);
|
|
11959
|
+
}
|
|
11960
|
+
return row;
|
|
11961
|
+
};
|
|
11962
|
+
var buildMultiSelectActions = (feature) => {
|
|
11963
|
+
var _a;
|
|
11964
|
+
const row = createElement(
|
|
11965
|
+
"div",
|
|
11966
|
+
"persona-ask-multi-actions persona-flex persona-justify-end persona-mt-2"
|
|
11967
|
+
);
|
|
11968
|
+
row.setAttribute("data-ask-multi-actions", "true");
|
|
11969
|
+
const submit = createElement(
|
|
11970
|
+
"button",
|
|
11971
|
+
"persona-ask-multi-submit persona-pointer-events-auto"
|
|
11972
|
+
);
|
|
11973
|
+
submit.type = "button";
|
|
11974
|
+
submit.textContent = (_a = feature.submitLabel) != null ? _a : DEFAULT_SUBMIT_LABEL;
|
|
11975
|
+
submit.setAttribute("data-ask-user-action", "submit-multi");
|
|
11976
|
+
submit.disabled = true;
|
|
11977
|
+
row.appendChild(submit);
|
|
11978
|
+
return row;
|
|
11979
|
+
};
|
|
11980
|
+
var buildNavRow = (index, count, feature) => {
|
|
11981
|
+
var _a, _b, _c, _d;
|
|
11982
|
+
const row = createElement(
|
|
11983
|
+
"div",
|
|
11984
|
+
"persona-ask-nav persona-flex persona-justify-between persona-items-center persona-gap-2 persona-mt-2"
|
|
11985
|
+
);
|
|
11986
|
+
row.setAttribute("data-ask-nav-row", "true");
|
|
11987
|
+
const back = createElement(
|
|
11988
|
+
"button",
|
|
11989
|
+
"persona-ask-nav-back persona-pointer-events-auto"
|
|
11990
|
+
);
|
|
11991
|
+
back.type = "button";
|
|
11992
|
+
back.textContent = (_a = feature.backLabel) != null ? _a : DEFAULT_BACK_LABEL;
|
|
11993
|
+
back.setAttribute("data-ask-user-action", "back");
|
|
11994
|
+
back.disabled = index === 0;
|
|
11995
|
+
row.appendChild(back);
|
|
11996
|
+
const rightGroup = createElement(
|
|
11997
|
+
"div",
|
|
11998
|
+
"persona-ask-nav-right persona-flex persona-items-center persona-gap-2"
|
|
11999
|
+
);
|
|
12000
|
+
const skip = createElement(
|
|
12001
|
+
"button",
|
|
12002
|
+
"persona-ask-nav-skip persona-pointer-events-auto"
|
|
12003
|
+
);
|
|
12004
|
+
skip.type = "button";
|
|
12005
|
+
skip.textContent = (_b = feature.skipLabel) != null ? _b : DEFAULT_SKIP_LABEL;
|
|
12006
|
+
skip.setAttribute("data-ask-user-action", "skip");
|
|
12007
|
+
rightGroup.appendChild(skip);
|
|
12008
|
+
const next = createElement(
|
|
12009
|
+
"button",
|
|
12010
|
+
"persona-ask-nav-next persona-pointer-events-auto"
|
|
12011
|
+
);
|
|
12012
|
+
next.type = "button";
|
|
12013
|
+
const isFinal = index === count - 1;
|
|
12014
|
+
next.textContent = isFinal ? (_c = feature.submitAllLabel) != null ? _c : DEFAULT_SUBMIT_ALL_LABEL : (_d = feature.nextLabel) != null ? _d : DEFAULT_NEXT_LABEL;
|
|
12015
|
+
next.setAttribute("data-ask-user-action", isFinal ? "submit-all" : "next");
|
|
12016
|
+
next.disabled = true;
|
|
12017
|
+
rightGroup.appendChild(next);
|
|
12018
|
+
row.appendChild(rightGroup);
|
|
12019
|
+
return row;
|
|
12020
|
+
};
|
|
12021
|
+
var readAnswersFromSheet = (sheet) => {
|
|
12022
|
+
const raw = sheet.getAttribute(ATTR_ANSWERS);
|
|
12023
|
+
if (!raw) return {};
|
|
12024
|
+
try {
|
|
12025
|
+
const parsed = JSON.parse(raw);
|
|
12026
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
12027
|
+
} catch {
|
|
12028
|
+
return {};
|
|
12029
|
+
}
|
|
12030
|
+
};
|
|
12031
|
+
var writeAnswersToSheet = (sheet, answers) => {
|
|
12032
|
+
sheet.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
|
|
12033
|
+
};
|
|
12034
|
+
var getCurrentIndex = (sheet) => {
|
|
12035
|
+
var _a;
|
|
12036
|
+
const raw = Number((_a = sheet.getAttribute(ATTR_CURRENT_INDEX)) != null ? _a : "0");
|
|
12037
|
+
return Number.isFinite(raw) ? Math.max(0, Math.floor(raw)) : 0;
|
|
12038
|
+
};
|
|
12039
|
+
var setCurrentIndex = (sheet, index) => {
|
|
12040
|
+
sheet.setAttribute(ATTR_CURRENT_INDEX, String(Math.max(0, Math.floor(index))));
|
|
12041
|
+
};
|
|
12042
|
+
var getQuestionCount = (sheet) => {
|
|
12043
|
+
var _a;
|
|
12044
|
+
const raw = Number((_a = sheet.getAttribute(ATTR_QUESTION_COUNT)) != null ? _a : "1");
|
|
12045
|
+
return Number.isFinite(raw) ? Math.max(1, Math.floor(raw)) : 1;
|
|
12046
|
+
};
|
|
12047
|
+
var isGroupedSheet = (sheet) => {
|
|
12048
|
+
return sheet.getAttribute(ATTR_GROUPED) === "true";
|
|
12049
|
+
};
|
|
12050
|
+
var restoreAnswersFromMessage = (message, prompts) => {
|
|
12051
|
+
var _a;
|
|
12052
|
+
const stored = (_a = message.agentMetadata) == null ? void 0 : _a.askUserQuestionAnswers;
|
|
12053
|
+
if (!stored || typeof stored !== "object") return {};
|
|
12054
|
+
const result = {};
|
|
12055
|
+
prompts.forEach((p, i) => {
|
|
12056
|
+
const q = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
12057
|
+
if (q && Object.prototype.hasOwnProperty.call(stored, q)) {
|
|
12058
|
+
const v = stored[q];
|
|
12059
|
+
if (typeof v === "string" || Array.isArray(v)) {
|
|
12060
|
+
result[i] = v;
|
|
12061
|
+
}
|
|
12062
|
+
}
|
|
12063
|
+
});
|
|
12064
|
+
return result;
|
|
12065
|
+
};
|
|
12066
|
+
var restoreIndexFromMessage = (message, count) => {
|
|
12067
|
+
var _a;
|
|
12068
|
+
const stored = (_a = message.agentMetadata) == null ? void 0 : _a.askUserQuestionIndex;
|
|
12069
|
+
if (typeof stored !== "number" || !Number.isFinite(stored)) return 0;
|
|
12070
|
+
return Math.max(0, Math.min(count - 1, Math.floor(stored)));
|
|
12071
|
+
};
|
|
12072
|
+
var buildStructuredAnswers = (sheet, message) => {
|
|
12073
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12074
|
+
const prompts = promptsFromPayload(payload);
|
|
12075
|
+
const indexed = readAnswersFromSheet(sheet);
|
|
12076
|
+
const result = {};
|
|
12077
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12078
|
+
prompts.forEach((p, i) => {
|
|
12079
|
+
const q = typeof (p == null ? void 0 : p.question) === "string" ? p.question : "";
|
|
12080
|
+
if (!q) return;
|
|
12081
|
+
if (seen.has(q) && typeof console !== "undefined") {
|
|
12082
|
+
console.warn(`[AgentWidget] ask_user_question has duplicate question text "${q}"; later answer wins.`);
|
|
12083
|
+
}
|
|
12084
|
+
seen.add(q);
|
|
12085
|
+
if (Object.prototype.hasOwnProperty.call(indexed, i)) {
|
|
12086
|
+
result[q] = indexed[i];
|
|
12087
|
+
}
|
|
12088
|
+
});
|
|
12089
|
+
return result;
|
|
12090
|
+
};
|
|
12091
|
+
var applySelectionState = (sheet) => {
|
|
12092
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12093
|
+
const currentIndex = getCurrentIndex(sheet);
|
|
12094
|
+
const stored = answers[currentIndex];
|
|
12095
|
+
const selected = /* @__PURE__ */ new Set();
|
|
12096
|
+
if (typeof stored === "string") selected.add(stored);
|
|
12097
|
+
else if (Array.isArray(stored)) stored.forEach((s) => selected.add(s));
|
|
12098
|
+
const pills = sheet.querySelectorAll('[data-ask-user-action="pick"][data-option-label]');
|
|
12099
|
+
pills.forEach((pill) => {
|
|
12100
|
+
var _a;
|
|
12101
|
+
const label = (_a = pill.getAttribute("data-option-label")) != null ? _a : "";
|
|
12102
|
+
const on = selected.has(label);
|
|
12103
|
+
pill.setAttribute("aria-pressed", on ? "true" : "false");
|
|
12104
|
+
pill.classList.toggle("persona-ask-pill-selected", on);
|
|
12105
|
+
});
|
|
12106
|
+
const realPillLabels = new Set(
|
|
12107
|
+
Array.from(pills).map((p) => {
|
|
12108
|
+
var _a;
|
|
12109
|
+
return (_a = p.getAttribute("data-option-label")) != null ? _a : "";
|
|
12110
|
+
})
|
|
12111
|
+
);
|
|
12112
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
12113
|
+
if (freeInput) {
|
|
12114
|
+
if (typeof stored === "string" && stored.length > 0 && !realPillLabels.has(stored)) {
|
|
12115
|
+
freeInput.value = stored;
|
|
12116
|
+
const freeRow = freeInput.closest('[data-ask-free-text-row="true"]');
|
|
12117
|
+
freeRow == null ? void 0 : freeRow.classList.remove("persona-hidden");
|
|
12118
|
+
} else {
|
|
12119
|
+
freeInput.value = "";
|
|
12120
|
+
}
|
|
12121
|
+
}
|
|
12122
|
+
};
|
|
12123
|
+
var syncNavState = (sheet) => {
|
|
12124
|
+
if (!isGroupedSheet(sheet)) return;
|
|
12125
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12126
|
+
const currentIndex = getCurrentIndex(sheet);
|
|
12127
|
+
const v = answers[currentIndex];
|
|
12128
|
+
const hasAnswer = typeof v === "string" && v.length > 0 || Array.isArray(v) && v.length > 0;
|
|
12129
|
+
const next = sheet.querySelector(
|
|
12130
|
+
'[data-ask-user-action="next"], [data-ask-user-action="submit-all"]'
|
|
12131
|
+
);
|
|
12132
|
+
if (next) next.disabled = !hasAnswer;
|
|
12133
|
+
const multi = sheet.querySelector('[data-ask-user-action="submit-multi"]');
|
|
12134
|
+
if (multi) {
|
|
12135
|
+
const labels = Array.from(
|
|
12136
|
+
sheet.querySelectorAll('[aria-pressed="true"][data-option-label]')
|
|
12137
|
+
);
|
|
12138
|
+
multi.disabled = labels.length === 0;
|
|
12139
|
+
}
|
|
12140
|
+
};
|
|
12141
|
+
var renderCurrentPage = (sheet, message, config) => {
|
|
12142
|
+
const feature = resolveFeature(config);
|
|
12143
|
+
const layout = getLayout(sheet);
|
|
12144
|
+
const { payload, complete } = parseAskUserQuestionPayload(message);
|
|
12145
|
+
const grouped = isGroupedSheet(sheet);
|
|
12146
|
+
const index = getCurrentIndex(sheet);
|
|
12147
|
+
const count = getQuestionCount(sheet);
|
|
12148
|
+
const prompt = grouped ? promptAt(payload, index) : firstPrompt(payload);
|
|
12149
|
+
const multiSelect = !!(prompt == null ? void 0 : prompt.multiSelect);
|
|
12150
|
+
const stepInline = sheet.querySelector('[data-ask-step-inline="true"]');
|
|
12151
|
+
if (stepInline) {
|
|
12152
|
+
stepInline.textContent = grouped ? `${index + 1}/${count}` : "";
|
|
12153
|
+
}
|
|
12154
|
+
const oldStepper = sheet.querySelector('[data-ask-stepper="true"]');
|
|
12155
|
+
if (oldStepper) oldStepper.remove();
|
|
12156
|
+
const qText = sheet.querySelector('[data-ask-question="true"]');
|
|
12157
|
+
if (qText) {
|
|
12158
|
+
const text = typeof (prompt == null ? void 0 : prompt.question) === "string" ? prompt.question : "";
|
|
12159
|
+
qText.textContent = text;
|
|
12160
|
+
qText.classList.toggle("persona-ask-question-skeleton", !text && !complete);
|
|
12161
|
+
}
|
|
12162
|
+
const pillList = sheet.querySelector('[data-ask-pill-list="true"]');
|
|
12163
|
+
if (pillList) {
|
|
12164
|
+
const fresh = buildPillList(prompt, feature, complete, layout);
|
|
12165
|
+
pillList.replaceWith(fresh);
|
|
12166
|
+
}
|
|
12167
|
+
if (layout !== "rows") {
|
|
12168
|
+
const oldFree = sheet.querySelector('[data-ask-free-text-row="true"]');
|
|
12169
|
+
if (oldFree) oldFree.replaceWith(buildFreeTextRow(feature, layout));
|
|
12170
|
+
}
|
|
12171
|
+
const oldMulti = sheet.querySelector('[data-ask-multi-actions="true"]');
|
|
12172
|
+
if (!grouped && multiSelect && !oldMulti) {
|
|
12173
|
+
sheet.appendChild(buildMultiSelectActions(feature));
|
|
12174
|
+
} else if ((!multiSelect || grouped) && oldMulti) {
|
|
12175
|
+
oldMulti.remove();
|
|
12176
|
+
}
|
|
12177
|
+
sheet.setAttribute("data-multi-select", multiSelect ? "true" : "false");
|
|
12178
|
+
const oldNav = sheet.querySelector('[data-ask-nav-row="true"]');
|
|
12179
|
+
if (grouped) {
|
|
12180
|
+
const fresh = buildNavRow(index, count, feature);
|
|
12181
|
+
if (oldNav) oldNav.replaceWith(fresh);
|
|
12182
|
+
else sheet.appendChild(fresh);
|
|
12183
|
+
} else if (oldNav) {
|
|
12184
|
+
oldNav.remove();
|
|
12185
|
+
}
|
|
12186
|
+
applySelectionState(sheet);
|
|
12187
|
+
syncNavState(sheet);
|
|
12188
|
+
};
|
|
12189
|
+
var buildSheet = (message, config, payload) => {
|
|
12190
|
+
const feature = resolveFeature(config);
|
|
12191
|
+
const layout = resolveLayout(feature);
|
|
12192
|
+
const toolCallId = message.toolCall.id;
|
|
12193
|
+
const prompts = promptsFromPayload(payload);
|
|
12194
|
+
const count = Math.max(1, prompts.length);
|
|
12195
|
+
const grouped = count > 1;
|
|
12196
|
+
const initialAnswers = restoreAnswersFromMessage(message, prompts);
|
|
12197
|
+
const initialIndex = grouped ? restoreIndexFromMessage(message, count) : 0;
|
|
12198
|
+
const sheet = createElement(
|
|
12199
|
+
"div",
|
|
12200
|
+
[
|
|
12201
|
+
"persona-ask-sheet",
|
|
12202
|
+
`persona-ask-sheet--${layout}`,
|
|
12203
|
+
"persona-pointer-events-auto",
|
|
12204
|
+
"persona-ask-sheet-enter"
|
|
12205
|
+
].join(" ")
|
|
12206
|
+
);
|
|
12207
|
+
sheet.setAttribute(SHEET_SENTINEL, toolCallId);
|
|
12208
|
+
sheet.setAttribute("data-tool-call-id", toolCallId);
|
|
12209
|
+
sheet.setAttribute("data-message-id", message.id);
|
|
12210
|
+
sheet.setAttribute(ATTR_QUESTION_COUNT, String(count));
|
|
12211
|
+
sheet.setAttribute(ATTR_CURRENT_INDEX, String(initialIndex));
|
|
12212
|
+
sheet.setAttribute(ATTR_GROUPED, grouped ? "true" : "false");
|
|
12213
|
+
sheet.setAttribute(ATTR_LAYOUT, layout);
|
|
12214
|
+
writeAnswersToSheet(sheet, initialAnswers);
|
|
12215
|
+
sheet.setAttribute("role", "group");
|
|
12216
|
+
sheet.setAttribute("aria-label", "Suggested answers");
|
|
12217
|
+
if (feature.slideInMs !== void 0) {
|
|
12218
|
+
sheet.style.setProperty("--persona-ask-sheet-duration", `${feature.slideInMs}ms`);
|
|
12219
|
+
}
|
|
12220
|
+
applyStyleVars(sheet, feature);
|
|
12221
|
+
const header = createElement(
|
|
12222
|
+
"div",
|
|
12223
|
+
"persona-ask-sheet-header persona-flex persona-items-center persona-gap-3"
|
|
12224
|
+
);
|
|
12225
|
+
const qText = createElement("div", "persona-ask-sheet-question persona-flex-1");
|
|
12226
|
+
qText.setAttribute("data-ask-question", "true");
|
|
12227
|
+
qText.textContent = "";
|
|
12228
|
+
header.appendChild(qText);
|
|
12229
|
+
const stepInline = createElement(
|
|
12230
|
+
"span",
|
|
12231
|
+
"persona-ask-sheet-step-inline"
|
|
12232
|
+
);
|
|
12233
|
+
stepInline.setAttribute("data-ask-step-inline", "true");
|
|
12234
|
+
stepInline.textContent = "";
|
|
12235
|
+
header.appendChild(stepInline);
|
|
12236
|
+
sheet.appendChild(header);
|
|
12237
|
+
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";
|
|
12238
|
+
const list = createElement("div", skeletonClass);
|
|
12239
|
+
list.setAttribute("data-ask-pill-list", "true");
|
|
12240
|
+
list.setAttribute("role", "group");
|
|
12241
|
+
sheet.appendChild(list);
|
|
12242
|
+
if (layout !== "rows") {
|
|
12243
|
+
sheet.appendChild(buildFreeTextRow(feature, layout));
|
|
12244
|
+
}
|
|
12245
|
+
renderCurrentPage(sheet, message, config);
|
|
12246
|
+
requestAnimationFrame(() => {
|
|
12247
|
+
requestAnimationFrame(() => sheet.classList.remove("persona-ask-sheet-enter"));
|
|
12248
|
+
});
|
|
12249
|
+
return sheet;
|
|
12250
|
+
};
|
|
12251
|
+
var syncSheetFromMessage = (sheet, message, config) => {
|
|
12252
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12253
|
+
const newCount = Math.max(1, promptsFromPayload(payload).length);
|
|
12254
|
+
if (newCount > getQuestionCount(sheet)) {
|
|
12255
|
+
sheet.setAttribute(ATTR_QUESTION_COUNT, String(newCount));
|
|
12256
|
+
if (newCount > 1 && !isGroupedSheet(sheet)) {
|
|
12257
|
+
sheet.setAttribute(ATTR_GROUPED, "true");
|
|
12258
|
+
}
|
|
12259
|
+
}
|
|
12260
|
+
renderCurrentPage(sheet, message, config);
|
|
12261
|
+
};
|
|
12262
|
+
var ensureAskUserQuestionSheet = (message, config, overlay) => {
|
|
12263
|
+
if (!overlay) return;
|
|
12264
|
+
if (!isAskUserQuestionMessage(message)) return;
|
|
12265
|
+
const feature = resolveFeature(config);
|
|
12266
|
+
if (feature.enabled === false) return;
|
|
12267
|
+
const toolCallId = message.toolCall.id;
|
|
12268
|
+
const siblings = overlay.querySelectorAll(`[${SHEET_SENTINEL}]`);
|
|
12269
|
+
siblings.forEach((el) => {
|
|
12270
|
+
if (el.getAttribute(SHEET_SENTINEL) !== toolCallId) {
|
|
12271
|
+
el.remove();
|
|
12272
|
+
}
|
|
12273
|
+
});
|
|
12274
|
+
const existing = overlay.querySelector(
|
|
12275
|
+
`[${SHEET_SENTINEL}="${escapeAttrValue(toolCallId)}"]`
|
|
12276
|
+
);
|
|
12277
|
+
if (existing) {
|
|
12278
|
+
syncSheetFromMessage(existing, message, config);
|
|
12279
|
+
return;
|
|
12280
|
+
}
|
|
12281
|
+
const { payload } = parseAskUserQuestionPayload(message);
|
|
12282
|
+
const sheet = buildSheet(message, config, payload);
|
|
12283
|
+
overlay.appendChild(sheet);
|
|
12284
|
+
};
|
|
12285
|
+
var removeAskUserQuestionSheet = (overlay, toolCallId) => {
|
|
12286
|
+
if (!overlay) return;
|
|
12287
|
+
const selector = toolCallId ? `[${SHEET_SENTINEL}="${escapeAttrValue(toolCallId)}"]` : `[${SHEET_SENTINEL}]`;
|
|
12288
|
+
const sheets = overlay.querySelectorAll(selector);
|
|
12289
|
+
sheets.forEach((sheet) => {
|
|
12290
|
+
sheet.classList.add("persona-ask-sheet-leave");
|
|
12291
|
+
const duration = Number.parseInt(
|
|
12292
|
+
getComputedStyle(sheet).getPropertyValue("--persona-ask-sheet-duration") || "180",
|
|
12293
|
+
10
|
|
12294
|
+
);
|
|
12295
|
+
const remove = () => sheet.remove();
|
|
12296
|
+
setTimeout(remove, Number.isFinite(duration) ? duration : 180);
|
|
12297
|
+
});
|
|
12298
|
+
};
|
|
12299
|
+
var getSelectedLabels = (sheet) => {
|
|
12300
|
+
return Array.from(
|
|
12301
|
+
sheet.querySelectorAll('[aria-pressed="true"][data-option-label]')
|
|
12302
|
+
).map((el) => el.getAttribute("data-option-label")).filter((label) => typeof label === "string" && label.length > 0);
|
|
12303
|
+
};
|
|
12304
|
+
var setCurrentAnswer = (sheet, answer) => {
|
|
12305
|
+
const answers = readAnswersFromSheet(sheet);
|
|
12306
|
+
const idx = getCurrentIndex(sheet);
|
|
12307
|
+
if (typeof answer === "string" && answer.length === 0) {
|
|
12308
|
+
delete answers[idx];
|
|
12309
|
+
} else if (Array.isArray(answer) && answer.length === 0) {
|
|
12310
|
+
delete answers[idx];
|
|
12311
|
+
} else {
|
|
12312
|
+
answers[idx] = answer;
|
|
12313
|
+
}
|
|
12314
|
+
writeAnswersToSheet(sheet, answers);
|
|
12315
|
+
applySelectionState(sheet);
|
|
12316
|
+
syncNavState(sheet);
|
|
12317
|
+
};
|
|
12318
|
+
var navigateToPage = (sheet, message, config, index) => {
|
|
12319
|
+
const count = getQuestionCount(sheet);
|
|
12320
|
+
const clamped = Math.max(0, Math.min(count - 1, index));
|
|
12321
|
+
setCurrentIndex(sheet, clamped);
|
|
12322
|
+
renderCurrentPage(sheet, message, config);
|
|
12323
|
+
};
|
|
12324
|
+
|
|
11484
12325
|
// src/components/approval-bubble.ts
|
|
11485
12326
|
var createApprovalBubble = (message, config) => {
|
|
11486
12327
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -13889,6 +14730,10 @@ var sanitizeMessages = (messages) => messages.map((message) => ({
|
|
|
13889
14730
|
...message,
|
|
13890
14731
|
streaming: false
|
|
13891
14732
|
}));
|
|
14733
|
+
var sanitizeArtifacts = (artifacts) => artifacts.map((artifact) => ({
|
|
14734
|
+
...artifact,
|
|
14735
|
+
status: "complete"
|
|
14736
|
+
}));
|
|
13892
14737
|
var createLocalStorageAdapter = (key = "persona-state") => {
|
|
13893
14738
|
const getStorage = () => {
|
|
13894
14739
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
@@ -13908,7 +14753,8 @@ var createLocalStorageAdapter = (key = "persona-state") => {
|
|
|
13908
14753
|
try {
|
|
13909
14754
|
const payload = {
|
|
13910
14755
|
...state,
|
|
13911
|
-
messages: state.messages ? sanitizeMessages(state.messages) : void 0
|
|
14756
|
+
messages: state.messages ? sanitizeMessages(state.messages) : void 0,
|
|
14757
|
+
artifacts: state.artifacts ? sanitizeArtifacts(state.artifacts) : void 0
|
|
13912
14758
|
};
|
|
13913
14759
|
storage.setItem(key, JSON.stringify(payload));
|
|
13914
14760
|
} catch (error) {
|
|
@@ -13932,7 +14778,7 @@ var createLocalStorageAdapter = (key = "persona-state") => {
|
|
|
13932
14778
|
};
|
|
13933
14779
|
|
|
13934
14780
|
// src/utils/component-parser.ts
|
|
13935
|
-
import { parse as
|
|
14781
|
+
import { parse as parsePartialJson3, STR as STR3, OBJ as OBJ3 } from "partial-json";
|
|
13936
14782
|
|
|
13937
14783
|
// src/utils/component-middleware.ts
|
|
13938
14784
|
function renderComponentDirective(directive, options) {
|
|
@@ -14408,7 +15254,7 @@ function buildDropOverlay(dropCfg) {
|
|
|
14408
15254
|
return overlay;
|
|
14409
15255
|
}
|
|
14410
15256
|
var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
14411
|
-
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;
|
|
15257
|
+
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;
|
|
14412
15258
|
if (mount == null) {
|
|
14413
15259
|
throw new Error(
|
|
14414
15260
|
'createAgentExperience: mount must be a non-null HTMLElement (e.g. pass document.getElementById("my-root") after the node exists).'
|
|
@@ -14467,6 +15313,13 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14467
15313
|
if ((_b = processedState.messages) == null ? void 0 : _b.length) {
|
|
14468
15314
|
config = { ...config, initialMessages: processedState.messages };
|
|
14469
15315
|
}
|
|
15316
|
+
if ((_c = processedState.artifacts) == null ? void 0 : _c.length) {
|
|
15317
|
+
config = {
|
|
15318
|
+
...config,
|
|
15319
|
+
initialArtifacts: processedState.artifacts,
|
|
15320
|
+
initialSelectedArtifactId: (_d = processedState.selectedArtifactId) != null ? _d : null
|
|
15321
|
+
};
|
|
15322
|
+
}
|
|
14470
15323
|
}
|
|
14471
15324
|
} catch (error) {
|
|
14472
15325
|
if (typeof console !== "undefined") {
|
|
@@ -14476,7 +15329,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14476
15329
|
} else if (config.onStateLoaded) {
|
|
14477
15330
|
try {
|
|
14478
15331
|
const processedState = applyStateLoadedHook({ messages: [], metadata: {} });
|
|
14479
|
-
if ((
|
|
15332
|
+
if ((_e = processedState.messages) == null ? void 0 : _e.length) {
|
|
14480
15333
|
config = { ...config, initialMessages: processedState.messages };
|
|
14481
15334
|
}
|
|
14482
15335
|
} catch (error) {
|
|
@@ -14503,12 +15356,12 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14503
15356
|
documentRef: typeof document !== "undefined" ? document : null
|
|
14504
15357
|
});
|
|
14505
15358
|
actionManager.syncFromMetadata();
|
|
14506
|
-
let launcherEnabled = (
|
|
14507
|
-
let autoExpand = (
|
|
14508
|
-
const autoFocusInput = (
|
|
15359
|
+
let launcherEnabled = (_g = (_f = config.launcher) == null ? void 0 : _f.enabled) != null ? _g : true;
|
|
15360
|
+
let autoExpand = (_i = (_h = config.launcher) == null ? void 0 : _h.autoExpand) != null ? _i : false;
|
|
15361
|
+
const autoFocusInput = (_j = config.autoFocusInput) != null ? _j : false;
|
|
14509
15362
|
let prevAutoExpand = autoExpand;
|
|
14510
15363
|
let prevLauncherEnabled = launcherEnabled;
|
|
14511
|
-
let prevHeaderLayout = (
|
|
15364
|
+
let prevHeaderLayout = (_l = (_k = config.layout) == null ? void 0 : _k.header) == null ? void 0 : _l.layout;
|
|
14512
15365
|
let wasMobileFullscreen = false;
|
|
14513
15366
|
let open = launcherEnabled ? autoExpand : true;
|
|
14514
15367
|
let pendingResubmit = false;
|
|
@@ -14528,14 +15381,14 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14528
15381
|
}, 1e4);
|
|
14529
15382
|
};
|
|
14530
15383
|
let postprocess = buildPostprocessor(config, actionManager, handleResubmitRequested);
|
|
14531
|
-
let showReasoning = (
|
|
14532
|
-
let showToolCalls = (
|
|
14533
|
-
let showEventStreamToggle = (
|
|
14534
|
-
let scrollToBottomFeature = (
|
|
14535
|
-
const persistKeyPrefix = (
|
|
15384
|
+
let showReasoning = (_n = (_m = config.features) == null ? void 0 : _m.showReasoning) != null ? _n : true;
|
|
15385
|
+
let showToolCalls = (_p = (_o = config.features) == null ? void 0 : _o.showToolCalls) != null ? _p : true;
|
|
15386
|
+
let showEventStreamToggle = (_r = (_q = config.features) == null ? void 0 : _q.showEventStreamToggle) != null ? _r : false;
|
|
15387
|
+
let scrollToBottomFeature = (_t = (_s = config.features) == null ? void 0 : _s.scrollToBottom) != null ? _t : {};
|
|
15388
|
+
const persistKeyPrefix = (_v = typeof config.persistState === "object" ? (_u = config.persistState) == null ? void 0 : _u.keyPrefix : void 0) != null ? _v : "persona-";
|
|
14536
15389
|
const eventStreamDbName = `${persistKeyPrefix}event-stream`;
|
|
14537
15390
|
let eventStreamStore = showEventStreamToggle ? new EventStreamStore(eventStreamDbName) : null;
|
|
14538
|
-
const eventStreamMaxEvents = (
|
|
15391
|
+
const eventStreamMaxEvents = (_y = (_x = (_w = config.features) == null ? void 0 : _w.eventStream) == null ? void 0 : _x.maxEvents) != null ? _y : 2e3;
|
|
14539
15392
|
let eventStreamBuffer = showEventStreamToggle ? new EventStreamBuffer(eventStreamMaxEvents, eventStreamStore) : null;
|
|
14540
15393
|
let eventStreamView = null;
|
|
14541
15394
|
let eventStreamVisible = false;
|
|
@@ -14572,7 +15425,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14572
15425
|
(_b2 = (_a2 = config.messageActions) == null ? void 0 : _a2.onFeedback) == null ? void 0 : _b2.call(_a2, feedback);
|
|
14573
15426
|
}
|
|
14574
15427
|
};
|
|
14575
|
-
const statusConfig = (
|
|
15428
|
+
const statusConfig = (_z = config.statusIndicator) != null ? _z : {};
|
|
14576
15429
|
const _getStatusText = (status) => {
|
|
14577
15430
|
var _a2, _b2, _c2, _d2;
|
|
14578
15431
|
if (status === "idle") return (_a2 = statusConfig.idleText) != null ? _a2 : statusCopy.idle;
|
|
@@ -14753,7 +15606,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14753
15606
|
};
|
|
14754
15607
|
let eventStreamToggleBtn = null;
|
|
14755
15608
|
if (showEventStreamToggle) {
|
|
14756
|
-
const esClassNames = (
|
|
15609
|
+
const esClassNames = (_B = (_A = config.features) == null ? void 0 : _A.eventStream) == null ? void 0 : _B.classNames;
|
|
14757
15610
|
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 : "");
|
|
14758
15611
|
eventStreamToggleBtn = createElement("button", toggleBtnClasses);
|
|
14759
15612
|
eventStreamToggleBtn.style.width = "28px";
|
|
@@ -14849,7 +15702,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14849
15702
|
config.agent = { ...config.agent, model: modelId };
|
|
14850
15703
|
}
|
|
14851
15704
|
},
|
|
14852
|
-
onVoiceToggle: ((
|
|
15705
|
+
onVoiceToggle: ((_C = config.voiceRecognition) == null ? void 0 : _C.enabled) === true ? () => {
|
|
14853
15706
|
composerVoiceBridge == null ? void 0 : composerVoiceBridge();
|
|
14854
15707
|
} : void 0
|
|
14855
15708
|
});
|
|
@@ -14888,7 +15741,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14888
15741
|
};
|
|
14889
15742
|
ensureComposerAttachmentSurface(footer);
|
|
14890
15743
|
bindComposerRefsFromFooter(footer);
|
|
14891
|
-
const contentMaxWidth = (
|
|
15744
|
+
const contentMaxWidth = (_D = config.layout) == null ? void 0 : _D.contentMaxWidth;
|
|
14892
15745
|
if (contentMaxWidth && composerForm) {
|
|
14893
15746
|
composerForm.style.maxWidth = contentMaxWidth;
|
|
14894
15747
|
composerForm.style.marginLeft = "auto";
|
|
@@ -14904,7 +15757,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14904
15757
|
attachmentPreviewsContainer.style.marginLeft = "auto";
|
|
14905
15758
|
attachmentPreviewsContainer.style.marginRight = "auto";
|
|
14906
15759
|
}
|
|
14907
|
-
if (((
|
|
15760
|
+
if (((_E = config.attachments) == null ? void 0 : _E.enabled) && attachmentInput && attachmentPreviewsContainer) {
|
|
14908
15761
|
attachmentManager = AttachmentManager.fromConfig(config.attachments);
|
|
14909
15762
|
attachmentManager.setPreviewsContainer(attachmentPreviewsContainer);
|
|
14910
15763
|
attachmentInput.addEventListener("change", (e) => {
|
|
@@ -15216,6 +16069,300 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15216
16069
|
event.preventDefault();
|
|
15217
16070
|
target.click();
|
|
15218
16071
|
});
|
|
16072
|
+
const askUserOverlay = panelElements.composerOverlay;
|
|
16073
|
+
const submitAskUserAnswer = (sheet, text, meta) => {
|
|
16074
|
+
var _a2, _b2, _c2, _d2;
|
|
16075
|
+
const trimmed = text.trim();
|
|
16076
|
+
if (!trimmed || !sessionRef.current) return;
|
|
16077
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16078
|
+
const isFreeText = meta.source === "free-text";
|
|
16079
|
+
mount.dispatchEvent(
|
|
16080
|
+
new CustomEvent("persona:askUserQuestion:answered", {
|
|
16081
|
+
detail: {
|
|
16082
|
+
toolUseId: toolCallId,
|
|
16083
|
+
answer: trimmed,
|
|
16084
|
+
answers: meta.structured,
|
|
16085
|
+
values: (_b2 = meta.values) != null ? _b2 : meta.source === "multi" ? trimmed.split(", ") : [trimmed],
|
|
16086
|
+
isFreeText,
|
|
16087
|
+
source: meta.source
|
|
16088
|
+
},
|
|
16089
|
+
bubbles: true,
|
|
16090
|
+
composed: true
|
|
16091
|
+
})
|
|
16092
|
+
);
|
|
16093
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16094
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16095
|
+
var _a3;
|
|
16096
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16097
|
+
});
|
|
16098
|
+
if ((_c2 = sourceMessage == null ? void 0 : sourceMessage.agentMetadata) == null ? void 0 : _c2.awaitingLocalTool) {
|
|
16099
|
+
sessionRef.current.resolveAskUserQuestion(sourceMessage, (_d2 = meta.structured) != null ? _d2 : trimmed);
|
|
16100
|
+
} else {
|
|
16101
|
+
sessionRef.current.sendMessage(trimmed);
|
|
16102
|
+
}
|
|
16103
|
+
};
|
|
16104
|
+
const persistGroupedProgress = (sheet) => {
|
|
16105
|
+
var _a2;
|
|
16106
|
+
const session2 = sessionRef.current;
|
|
16107
|
+
if (!session2) return;
|
|
16108
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16109
|
+
const sourceMessage = session2.getMessages().find((m) => {
|
|
16110
|
+
var _a3;
|
|
16111
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16112
|
+
});
|
|
16113
|
+
if (!sourceMessage) return;
|
|
16114
|
+
session2.persistAskUserQuestionProgress(sourceMessage, {
|
|
16115
|
+
answers: buildStructuredAnswers(sheet, sourceMessage),
|
|
16116
|
+
currentIndex: getCurrentIndex(sheet)
|
|
16117
|
+
});
|
|
16118
|
+
};
|
|
16119
|
+
const stringifyStructured = (answers) => {
|
|
16120
|
+
return Object.entries(answers).map(([q, v]) => `${q}: ${Array.isArray(v) ? v.join(", ") : v}`).join(" | ");
|
|
16121
|
+
};
|
|
16122
|
+
const maybeAutoAdvance = (sheet) => {
|
|
16123
|
+
var _a2, _b2, _c2;
|
|
16124
|
+
if (((_b2 = (_a2 = config.features) == null ? void 0 : _a2.askUserQuestion) == null ? void 0 : _b2.groupedAutoAdvance) === false) return;
|
|
16125
|
+
const idx = getCurrentIndex(sheet);
|
|
16126
|
+
const count = getQuestionCount(sheet);
|
|
16127
|
+
if (idx >= count - 1) return;
|
|
16128
|
+
const sourceMessage = (_c2 = sessionRef.current) == null ? void 0 : _c2.getMessages().find((m) => {
|
|
16129
|
+
var _a3;
|
|
16130
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === sheet.getAttribute("data-tool-call-id");
|
|
16131
|
+
});
|
|
16132
|
+
if (!sourceMessage) return;
|
|
16133
|
+
navigateToPage(sheet, sourceMessage, config, idx + 1);
|
|
16134
|
+
persistGroupedProgress(sheet);
|
|
16135
|
+
};
|
|
16136
|
+
askUserOverlay.addEventListener("click", (event) => {
|
|
16137
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
16138
|
+
const target = event.target;
|
|
16139
|
+
const trigger = target.closest("[data-ask-user-action]");
|
|
16140
|
+
if (!trigger) return;
|
|
16141
|
+
const sheet = trigger.closest("[data-persona-ask-sheet-for]");
|
|
16142
|
+
if (!sheet) return;
|
|
16143
|
+
const action = trigger.getAttribute("data-ask-user-action");
|
|
16144
|
+
event.preventDefault();
|
|
16145
|
+
event.stopPropagation();
|
|
16146
|
+
if (action === "dismiss") {
|
|
16147
|
+
const toolCallId = (_a2 = sheet.getAttribute("data-tool-call-id")) != null ? _a2 : "";
|
|
16148
|
+
mount.dispatchEvent(
|
|
16149
|
+
new CustomEvent("persona:askUserQuestion:dismissed", {
|
|
16150
|
+
detail: { toolUseId: toolCallId },
|
|
16151
|
+
bubbles: true,
|
|
16152
|
+
composed: true
|
|
16153
|
+
})
|
|
16154
|
+
);
|
|
16155
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16156
|
+
const sourceMessage = (_b2 = sessionRef.current) == null ? void 0 : _b2.getMessages().find((m) => {
|
|
16157
|
+
var _a3;
|
|
16158
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16159
|
+
});
|
|
16160
|
+
if ((_c2 = sourceMessage == null ? void 0 : sourceMessage.agentMetadata) == null ? void 0 : _c2.awaitingLocalTool) {
|
|
16161
|
+
(_d2 = sessionRef.current) == null ? void 0 : _d2.markAskUserQuestionResolved(sourceMessage);
|
|
16162
|
+
(_e2 = sessionRef.current) == null ? void 0 : _e2.resolveAskUserQuestion(sourceMessage, "(dismissed)");
|
|
16163
|
+
}
|
|
16164
|
+
return;
|
|
16165
|
+
}
|
|
16166
|
+
if (action === "pick") {
|
|
16167
|
+
const label = trigger.getAttribute("data-option-label");
|
|
16168
|
+
if (!label) return;
|
|
16169
|
+
const multiSelect = sheet.getAttribute("data-multi-select") === "true";
|
|
16170
|
+
const grouped = isGroupedSheet(sheet);
|
|
16171
|
+
if (grouped && multiSelect) {
|
|
16172
|
+
const stored = readAnswersFromSheet(sheet)[getCurrentIndex(sheet)];
|
|
16173
|
+
const set = new Set(Array.isArray(stored) ? stored : []);
|
|
16174
|
+
if (set.has(label)) set.delete(label);
|
|
16175
|
+
else set.add(label);
|
|
16176
|
+
setCurrentAnswer(sheet, Array.from(set));
|
|
16177
|
+
persistGroupedProgress(sheet);
|
|
16178
|
+
return;
|
|
16179
|
+
}
|
|
16180
|
+
if (grouped) {
|
|
16181
|
+
setCurrentAnswer(sheet, label);
|
|
16182
|
+
persistGroupedProgress(sheet);
|
|
16183
|
+
maybeAutoAdvance(sheet);
|
|
16184
|
+
return;
|
|
16185
|
+
}
|
|
16186
|
+
if (multiSelect) {
|
|
16187
|
+
const pressed = trigger.getAttribute("aria-pressed") === "true";
|
|
16188
|
+
trigger.setAttribute("aria-pressed", pressed ? "false" : "true");
|
|
16189
|
+
trigger.classList.toggle("persona-ask-pill-selected", !pressed);
|
|
16190
|
+
const submitBtn = sheet.querySelector(
|
|
16191
|
+
'[data-ask-user-action="submit-multi"]'
|
|
16192
|
+
);
|
|
16193
|
+
if (submitBtn) {
|
|
16194
|
+
submitBtn.disabled = getSelectedLabels(sheet).length === 0;
|
|
16195
|
+
}
|
|
16196
|
+
return;
|
|
16197
|
+
}
|
|
16198
|
+
submitAskUserAnswer(sheet, label, { source: "pick", values: [label] });
|
|
16199
|
+
return;
|
|
16200
|
+
}
|
|
16201
|
+
if (action === "submit-multi") {
|
|
16202
|
+
const labels = getSelectedLabels(sheet);
|
|
16203
|
+
if (labels.length === 0) return;
|
|
16204
|
+
submitAskUserAnswer(sheet, labels.join(", "), {
|
|
16205
|
+
source: "multi",
|
|
16206
|
+
values: labels
|
|
16207
|
+
});
|
|
16208
|
+
return;
|
|
16209
|
+
}
|
|
16210
|
+
if (action === "open-free-text") {
|
|
16211
|
+
const row = sheet.querySelector('[data-ask-free-text-row="true"]');
|
|
16212
|
+
if (row) {
|
|
16213
|
+
row.classList.remove("persona-hidden");
|
|
16214
|
+
const input = row.querySelector('[data-ask-free-text-input="true"]');
|
|
16215
|
+
input == null ? void 0 : input.focus();
|
|
16216
|
+
}
|
|
16217
|
+
return;
|
|
16218
|
+
}
|
|
16219
|
+
if (action === "focus-free-text") {
|
|
16220
|
+
const input = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16221
|
+
input == null ? void 0 : input.focus();
|
|
16222
|
+
return;
|
|
16223
|
+
}
|
|
16224
|
+
if (action === "submit-free-text") {
|
|
16225
|
+
const input = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16226
|
+
const text = (_f2 = input == null ? void 0 : input.value) != null ? _f2 : "";
|
|
16227
|
+
if (!text.trim()) return;
|
|
16228
|
+
if (isGroupedSheet(sheet)) {
|
|
16229
|
+
setCurrentAnswer(sheet, text.trim());
|
|
16230
|
+
persistGroupedProgress(sheet);
|
|
16231
|
+
maybeAutoAdvance(sheet);
|
|
16232
|
+
return;
|
|
16233
|
+
}
|
|
16234
|
+
submitAskUserAnswer(sheet, text, { source: "free-text" });
|
|
16235
|
+
return;
|
|
16236
|
+
}
|
|
16237
|
+
if (action === "next" || action === "back") {
|
|
16238
|
+
if (!sessionRef.current) return;
|
|
16239
|
+
const toolCallId = (_g2 = sheet.getAttribute("data-tool-call-id")) != null ? _g2 : "";
|
|
16240
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16241
|
+
var _a3;
|
|
16242
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16243
|
+
});
|
|
16244
|
+
if (!sourceMessage) return;
|
|
16245
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16246
|
+
const pending = (_i2 = (_h2 = freeInput == null ? void 0 : freeInput.value) == null ? void 0 : _h2.trim()) != null ? _i2 : "";
|
|
16247
|
+
if (pending) {
|
|
16248
|
+
const stored = readAnswersFromSheet(sheet)[getCurrentIndex(sheet)];
|
|
16249
|
+
if (typeof stored !== "string" || stored !== pending) {
|
|
16250
|
+
setCurrentAnswer(sheet, pending);
|
|
16251
|
+
}
|
|
16252
|
+
}
|
|
16253
|
+
const direction = action === "next" ? 1 : -1;
|
|
16254
|
+
const nextIdx = getCurrentIndex(sheet) + direction;
|
|
16255
|
+
navigateToPage(sheet, sourceMessage, config, nextIdx);
|
|
16256
|
+
persistGroupedProgress(sheet);
|
|
16257
|
+
return;
|
|
16258
|
+
}
|
|
16259
|
+
if (action === "submit-all") {
|
|
16260
|
+
if (!sessionRef.current) return;
|
|
16261
|
+
const toolCallId = (_j2 = sheet.getAttribute("data-tool-call-id")) != null ? _j2 : "";
|
|
16262
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16263
|
+
var _a3;
|
|
16264
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16265
|
+
});
|
|
16266
|
+
if (!sourceMessage) return;
|
|
16267
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16268
|
+
const pending = (_l2 = (_k2 = freeInput == null ? void 0 : freeInput.value) == null ? void 0 : _k2.trim()) != null ? _l2 : "";
|
|
16269
|
+
if (pending) setCurrentAnswer(sheet, pending);
|
|
16270
|
+
const structured = buildStructuredAnswers(sheet, sourceMessage);
|
|
16271
|
+
sessionRef.current.persistAskUserQuestionProgress(sourceMessage, {
|
|
16272
|
+
answers: structured,
|
|
16273
|
+
currentIndex: getCurrentIndex(sheet)
|
|
16274
|
+
});
|
|
16275
|
+
const summary = stringifyStructured(structured);
|
|
16276
|
+
submitAskUserAnswer(sheet, summary || "(submitted)", {
|
|
16277
|
+
source: "submit-all",
|
|
16278
|
+
structured
|
|
16279
|
+
});
|
|
16280
|
+
return;
|
|
16281
|
+
}
|
|
16282
|
+
if (action === "skip") {
|
|
16283
|
+
if (!sessionRef.current) return;
|
|
16284
|
+
const toolCallId = (_m2 = sheet.getAttribute("data-tool-call-id")) != null ? _m2 : "";
|
|
16285
|
+
const sourceMessage = sessionRef.current.getMessages().find((m) => {
|
|
16286
|
+
var _a3;
|
|
16287
|
+
return ((_a3 = m.toolCall) == null ? void 0 : _a3.id) === toolCallId;
|
|
16288
|
+
});
|
|
16289
|
+
if (!sourceMessage) return;
|
|
16290
|
+
const grouped = isGroupedSheet(sheet);
|
|
16291
|
+
const idx = getCurrentIndex(sheet);
|
|
16292
|
+
const count = getQuestionCount(sheet);
|
|
16293
|
+
const isFinal = idx >= count - 1;
|
|
16294
|
+
if (!grouped) {
|
|
16295
|
+
mount.dispatchEvent(
|
|
16296
|
+
new CustomEvent("persona:askUserQuestion:dismissed", {
|
|
16297
|
+
detail: { toolUseId: toolCallId },
|
|
16298
|
+
bubbles: true,
|
|
16299
|
+
composed: true
|
|
16300
|
+
})
|
|
16301
|
+
);
|
|
16302
|
+
removeAskUserQuestionSheet(askUserOverlay, toolCallId);
|
|
16303
|
+
if ((_n2 = sourceMessage.agentMetadata) == null ? void 0 : _n2.awaitingLocalTool) {
|
|
16304
|
+
sessionRef.current.markAskUserQuestionResolved(sourceMessage);
|
|
16305
|
+
sessionRef.current.resolveAskUserQuestion(sourceMessage, "(dismissed)");
|
|
16306
|
+
}
|
|
16307
|
+
return;
|
|
16308
|
+
}
|
|
16309
|
+
setCurrentAnswer(sheet, "");
|
|
16310
|
+
const freeInput = sheet.querySelector('[data-ask-free-text-input="true"]');
|
|
16311
|
+
if (freeInput) freeInput.value = "";
|
|
16312
|
+
if (isFinal) {
|
|
16313
|
+
const structured = buildStructuredAnswers(sheet, sourceMessage);
|
|
16314
|
+
const summary = stringifyStructured(structured);
|
|
16315
|
+
submitAskUserAnswer(sheet, summary || "(skipped)", {
|
|
16316
|
+
source: "submit-all",
|
|
16317
|
+
structured
|
|
16318
|
+
});
|
|
16319
|
+
return;
|
|
16320
|
+
}
|
|
16321
|
+
navigateToPage(sheet, sourceMessage, config, idx + 1);
|
|
16322
|
+
persistGroupedProgress(sheet);
|
|
16323
|
+
return;
|
|
16324
|
+
}
|
|
16325
|
+
});
|
|
16326
|
+
askUserOverlay.addEventListener("keydown", (event) => {
|
|
16327
|
+
var _a2;
|
|
16328
|
+
if (event.key !== "Enter") return;
|
|
16329
|
+
const target = event.target;
|
|
16330
|
+
const input = target;
|
|
16331
|
+
if (!((_a2 = input.matches) == null ? void 0 : _a2.call(input, '[data-ask-free-text-input="true"]'))) return;
|
|
16332
|
+
const sheet = input.closest("[data-persona-ask-sheet-for]");
|
|
16333
|
+
if (!sheet) return;
|
|
16334
|
+
event.preventDefault();
|
|
16335
|
+
const text = input.value;
|
|
16336
|
+
if (!text.trim()) return;
|
|
16337
|
+
if (isGroupedSheet(sheet)) {
|
|
16338
|
+
setCurrentAnswer(sheet, text.trim());
|
|
16339
|
+
persistGroupedProgress(sheet);
|
|
16340
|
+
maybeAutoAdvance(sheet);
|
|
16341
|
+
return;
|
|
16342
|
+
}
|
|
16343
|
+
submitAskUserAnswer(sheet, text, { source: "free-text" });
|
|
16344
|
+
});
|
|
16345
|
+
const handleAskUserDigitKey = (event) => {
|
|
16346
|
+
if (!/^[1-9]$/.test(event.key)) return;
|
|
16347
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
16348
|
+
const target = event.target;
|
|
16349
|
+
if ((target == null ? void 0 : target.tagName) === "INPUT" || (target == null ? void 0 : target.tagName) === "TEXTAREA" || (target == null ? void 0 : target.isContentEditable)) {
|
|
16350
|
+
return;
|
|
16351
|
+
}
|
|
16352
|
+
const sheet = askUserOverlay.querySelector("[data-persona-ask-sheet-for]");
|
|
16353
|
+
if (!sheet) return;
|
|
16354
|
+
if (sheet.getAttribute("data-ask-layout") !== "rows") return;
|
|
16355
|
+
if (sheet.getAttribute("data-multi-select") === "true") return;
|
|
16356
|
+
const n = Number(event.key);
|
|
16357
|
+
const pills = sheet.querySelectorAll(
|
|
16358
|
+
'[data-ask-pill-list="true"] [data-ask-user-action="pick"], [data-ask-pill-list="true"] [data-ask-user-action="focus-free-text"]'
|
|
16359
|
+
);
|
|
16360
|
+
const target_pill = pills[n - 1];
|
|
16361
|
+
if (!target_pill) return;
|
|
16362
|
+
event.preventDefault();
|
|
16363
|
+
target_pill.click();
|
|
16364
|
+
};
|
|
16365
|
+
document.addEventListener("keydown", handleAskUserDigitKey);
|
|
15219
16366
|
let artifactSplitRoot = null;
|
|
15220
16367
|
let artifactResizeHandle = null;
|
|
15221
16368
|
let artifactResizeUnbind = null;
|
|
@@ -15676,6 +16823,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15676
16823
|
applyArtifactLayoutCssVars(mount, config);
|
|
15677
16824
|
applyArtifactPaneAppearance(mount, config);
|
|
15678
16825
|
const destroyCallbacks = [];
|
|
16826
|
+
destroyCallbacks.push(() => {
|
|
16827
|
+
document.removeEventListener("keydown", handleAskUserDigitKey);
|
|
16828
|
+
});
|
|
15679
16829
|
let teardownHostStacking = null;
|
|
15680
16830
|
let releaseScrollLock = null;
|
|
15681
16831
|
destroyCallbacks.push(() => {
|
|
@@ -15733,7 +16883,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15733
16883
|
cleanupThemeObserver = null;
|
|
15734
16884
|
}
|
|
15735
16885
|
});
|
|
15736
|
-
const streamAnimationConfig = (
|
|
16886
|
+
const streamAnimationConfig = (_F = config.features) == null ? void 0 : _F.streamAnimation;
|
|
15737
16887
|
if ((streamAnimationConfig == null ? void 0 : streamAnimationConfig.type) && streamAnimationConfig.type !== "none") {
|
|
15738
16888
|
const plugin = resolveStreamAnimationPlugin(
|
|
15739
16889
|
streamAnimationConfig.type,
|
|
@@ -15749,6 +16899,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15749
16899
|
let session;
|
|
15750
16900
|
let isStreaming = false;
|
|
15751
16901
|
const messageCache = createMessageCache();
|
|
16902
|
+
const lastAskBubbleFingerprint = /* @__PURE__ */ new Map();
|
|
15752
16903
|
let configVersion = 0;
|
|
15753
16904
|
const autoFollow = createFollowStateController();
|
|
15754
16905
|
let lastScrollTop = 0;
|
|
@@ -15765,7 +16916,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15765
16916
|
lastUserMessageWasVoice: false,
|
|
15766
16917
|
lastUserMessageId: null
|
|
15767
16918
|
};
|
|
15768
|
-
const voiceAutoResumeMode = (
|
|
16919
|
+
const voiceAutoResumeMode = (_H = (_G = config.voiceRecognition) == null ? void 0 : _G.autoResume) != null ? _H : false;
|
|
15769
16920
|
const emitVoiceState = (source) => {
|
|
15770
16921
|
eventBus.emit("voice:state", {
|
|
15771
16922
|
active: voiceState.active,
|
|
@@ -15814,7 +16965,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15814
16965
|
const messages = messagesOverride ? stripStreamingFromMessages(messagesOverride) : session ? getMessagesForPersistence() : [];
|
|
15815
16966
|
const payload = {
|
|
15816
16967
|
messages,
|
|
15817
|
-
metadata: persistentMetadata
|
|
16968
|
+
metadata: persistentMetadata,
|
|
16969
|
+
artifacts: lastArtifactsState.artifacts,
|
|
16970
|
+
selectedArtifactId: lastArtifactsState.selectedId
|
|
15818
16971
|
};
|
|
15819
16972
|
try {
|
|
15820
16973
|
const result = storageAdapter.save(payload);
|
|
@@ -15991,13 +17144,22 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
15991
17144
|
return true;
|
|
15992
17145
|
};
|
|
15993
17146
|
const activeMessageIds = /* @__PURE__ */ new Set();
|
|
17147
|
+
const liveAskToolIds = /* @__PURE__ */ new Set();
|
|
17148
|
+
const hasAskPlugin = plugins.some((p) => p.renderAskUserQuestion);
|
|
17149
|
+
const askPluginHydrate = [];
|
|
15994
17150
|
messages.forEach((message) => {
|
|
15995
|
-
var _a3, _b3;
|
|
17151
|
+
var _a3, _b3, _c3, _d3, _e3, _f3, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
15996
17152
|
activeMessageIds.add(message.id);
|
|
15997
|
-
const
|
|
15998
|
-
const
|
|
17153
|
+
const askWithPlugin = hasAskPlugin && isAskUserQuestionMessage(message);
|
|
17154
|
+
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}` : "";
|
|
17155
|
+
const fingerprint = computeMessageFingerprint(message, configVersion) + askMeta;
|
|
17156
|
+
const cachedWrapper = askWithPlugin ? null : getCachedWrapper(messageCache, message.id, fingerprint);
|
|
15999
17157
|
if (cachedWrapper) {
|
|
16000
17158
|
tempContainer.appendChild(cachedWrapper.cloneNode(true));
|
|
17159
|
+
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)) {
|
|
17160
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17161
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17162
|
+
}
|
|
16001
17163
|
return;
|
|
16002
17164
|
}
|
|
16003
17165
|
let bubble = null;
|
|
@@ -16016,8 +17178,75 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16016
17178
|
}
|
|
16017
17179
|
return false;
|
|
16018
17180
|
});
|
|
16019
|
-
const messageLayoutConfig = (
|
|
16020
|
-
if (
|
|
17181
|
+
const messageLayoutConfig = (_f3 = config.layout) == null ? void 0 : _f3.messages;
|
|
17182
|
+
if (isAskUserQuestionMessage(message) && ((_g2 = message.agentMetadata) == null ? void 0 : _g2.askUserQuestionAnswered) === true) {
|
|
17183
|
+
lastAskBubbleFingerprint.delete(message.id);
|
|
17184
|
+
const existing = container2.querySelector(`#wrapper-${message.id}`);
|
|
17185
|
+
existing == null ? void 0 : existing.removeAttribute("data-preserve-runtime");
|
|
17186
|
+
return;
|
|
17187
|
+
}
|
|
17188
|
+
if (isAskUserQuestionMessage(message) && ((_i2 = (_h2 = config.features) == null ? void 0 : _h2.askUserQuestion) == null ? void 0 : _i2.enabled) !== false) {
|
|
17189
|
+
const askPlugin = plugins.find((p) => typeof p.renderAskUserQuestion === "function");
|
|
17190
|
+
if (askPlugin && sessionRef.current) {
|
|
17191
|
+
const lastFp = lastAskBubbleFingerprint.get(message.id);
|
|
17192
|
+
const needsRebuild = lastFp !== fingerprint;
|
|
17193
|
+
let pluginBubble = null;
|
|
17194
|
+
if (needsRebuild) {
|
|
17195
|
+
const { payload, complete } = parseAskUserQuestionPayload(message);
|
|
17196
|
+
const messageId = message.id;
|
|
17197
|
+
const liveMessage = () => {
|
|
17198
|
+
var _a4;
|
|
17199
|
+
return (_a4 = sessionRef.current) == null ? void 0 : _a4.getMessages().find((m) => m.id === messageId);
|
|
17200
|
+
};
|
|
17201
|
+
pluginBubble = askPlugin.renderAskUserQuestion({
|
|
17202
|
+
message,
|
|
17203
|
+
payload,
|
|
17204
|
+
complete,
|
|
17205
|
+
resolve: (answer) => {
|
|
17206
|
+
var _a4;
|
|
17207
|
+
const live = liveMessage();
|
|
17208
|
+
if (live) (_a4 = sessionRef.current) == null ? void 0 : _a4.resolveAskUserQuestion(live, answer);
|
|
17209
|
+
},
|
|
17210
|
+
dismiss: () => {
|
|
17211
|
+
var _a4, _b4, _c4;
|
|
17212
|
+
const live = liveMessage();
|
|
17213
|
+
if ((_a4 = live == null ? void 0 : live.agentMetadata) == null ? void 0 : _a4.awaitingLocalTool) {
|
|
17214
|
+
(_b4 = sessionRef.current) == null ? void 0 : _b4.markAskUserQuestionResolved(live);
|
|
17215
|
+
(_c4 = sessionRef.current) == null ? void 0 : _c4.resolveAskUserQuestion(live, "(dismissed)");
|
|
17216
|
+
}
|
|
17217
|
+
},
|
|
17218
|
+
config
|
|
17219
|
+
});
|
|
17220
|
+
}
|
|
17221
|
+
const previouslyMounted = lastFp != null;
|
|
17222
|
+
if (needsRebuild && pluginBubble === null && !previouslyMounted) {
|
|
17223
|
+
if (((_j2 = message.agentMetadata) == null ? void 0 : _j2.awaitingLocalTool) === true && !((_k2 = message.agentMetadata) == null ? void 0 : _k2.askUserQuestionAnswered)) {
|
|
17224
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17225
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17226
|
+
}
|
|
17227
|
+
return;
|
|
17228
|
+
}
|
|
17229
|
+
const stub = document.createElement("div");
|
|
17230
|
+
stub.className = "persona-flex";
|
|
17231
|
+
stub.id = `wrapper-${message.id}`;
|
|
17232
|
+
stub.setAttribute("data-wrapper-id", message.id);
|
|
17233
|
+
stub.setAttribute("data-ask-plugin-stub", "true");
|
|
17234
|
+
stub.setAttribute("data-preserve-runtime", "true");
|
|
17235
|
+
tempContainer.appendChild(stub);
|
|
17236
|
+
askPluginHydrate.push({
|
|
17237
|
+
messageId: message.id,
|
|
17238
|
+
fingerprint,
|
|
17239
|
+
bubble: pluginBubble
|
|
17240
|
+
});
|
|
17241
|
+
return;
|
|
17242
|
+
} else {
|
|
17243
|
+
if (((_l2 = message.agentMetadata) == null ? void 0 : _l2.awaitingLocalTool) === true && !((_m2 = message.agentMetadata) == null ? void 0 : _m2.askUserQuestionAnswered)) {
|
|
17244
|
+
liveAskToolIds.add(message.toolCall.id);
|
|
17245
|
+
ensureAskUserQuestionSheet(message, config, panelElements.composerOverlay);
|
|
17246
|
+
}
|
|
17247
|
+
return;
|
|
17248
|
+
}
|
|
17249
|
+
} else if (matchingPlugin) {
|
|
16021
17250
|
if (message.variant === "reasoning" && message.reasoning && matchingPlugin.renderReasoning) {
|
|
16022
17251
|
if (!showReasoning) return;
|
|
16023
17252
|
bubble = matchingPlugin.renderReasoning({
|
|
@@ -16136,7 +17365,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16136
17365
|
if (config.approval === false) return;
|
|
16137
17366
|
bubble = createApprovalBubble(message, config);
|
|
16138
17367
|
} else {
|
|
16139
|
-
const messageLayoutConfig2 = (
|
|
17368
|
+
const messageLayoutConfig2 = (_n2 = config.layout) == null ? void 0 : _n2.messages;
|
|
16140
17369
|
if ((messageLayoutConfig2 == null ? void 0 : messageLayoutConfig2.renderUserMessage) && message.role === "user") {
|
|
16141
17370
|
bubble = messageLayoutConfig2.renderUserMessage({
|
|
16142
17371
|
message,
|
|
@@ -16181,6 +17410,17 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16181
17410
|
setCachedWrapper(messageCache, message.id, fingerprint, wrapper2);
|
|
16182
17411
|
tempContainer.appendChild(wrapper2);
|
|
16183
17412
|
});
|
|
17413
|
+
if (panelElements.composerOverlay) {
|
|
17414
|
+
const sheets = panelElements.composerOverlay.querySelectorAll(
|
|
17415
|
+
"[data-persona-ask-sheet-for]"
|
|
17416
|
+
);
|
|
17417
|
+
sheets.forEach((sheet) => {
|
|
17418
|
+
const id = sheet.getAttribute("data-persona-ask-sheet-for");
|
|
17419
|
+
if (id && !liveAskToolIds.has(id)) {
|
|
17420
|
+
removeAskUserQuestionSheet(panelElements.composerOverlay, id);
|
|
17421
|
+
}
|
|
17422
|
+
});
|
|
17423
|
+
}
|
|
16184
17424
|
if ((_b2 = (_a2 = config.features) == null ? void 0 : _a2.toolCallDisplay) == null ? void 0 : _b2.grouped) {
|
|
16185
17425
|
const toolGroups = [];
|
|
16186
17426
|
let currentGroup = [];
|
|
@@ -16345,6 +17585,23 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16345
17585
|
}
|
|
16346
17586
|
}
|
|
16347
17587
|
morphMessages(container2, tempContainer);
|
|
17588
|
+
if (askPluginHydrate.length > 0) {
|
|
17589
|
+
for (const { messageId, fingerprint, bubble } of askPluginHydrate) {
|
|
17590
|
+
const wrapper2 = container2.querySelector(`#wrapper-${messageId}`);
|
|
17591
|
+
if (!wrapper2) continue;
|
|
17592
|
+
if (bubble === null) {
|
|
17593
|
+
continue;
|
|
17594
|
+
}
|
|
17595
|
+
wrapper2.replaceChildren(bubble);
|
|
17596
|
+
wrapper2.setAttribute("data-bubble-fp", fingerprint);
|
|
17597
|
+
lastAskBubbleFingerprint.set(messageId, fingerprint);
|
|
17598
|
+
}
|
|
17599
|
+
}
|
|
17600
|
+
if (lastAskBubbleFingerprint.size > 0) {
|
|
17601
|
+
for (const id of lastAskBubbleFingerprint.keys()) {
|
|
17602
|
+
if (!activeMessageIds.has(id)) lastAskBubbleFingerprint.delete(id);
|
|
17603
|
+
}
|
|
17604
|
+
}
|
|
16348
17605
|
};
|
|
16349
17606
|
const renderMessagesWithPlugins = renderMessagesWithPluginsImpl;
|
|
16350
17607
|
const updateOpenState = () => {
|
|
@@ -16609,10 +17866,11 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16609
17866
|
onArtifactsState(state) {
|
|
16610
17867
|
lastArtifactsState = state;
|
|
16611
17868
|
syncArtifactPane();
|
|
17869
|
+
persistState();
|
|
16612
17870
|
}
|
|
16613
17871
|
});
|
|
16614
17872
|
sessionRef.current = session;
|
|
16615
|
-
if (((
|
|
17873
|
+
if (((_J = (_I = config.voiceRecognition) == null ? void 0 : _I.provider) == null ? void 0 : _J.type) === "runtype") {
|
|
16616
17874
|
try {
|
|
16617
17875
|
session.setupVoice();
|
|
16618
17876
|
} catch (err) {
|
|
@@ -16642,7 +17900,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16642
17900
|
}
|
|
16643
17901
|
if (pendingStoredState) {
|
|
16644
17902
|
pendingStoredState.then((state) => {
|
|
16645
|
-
var _a2;
|
|
17903
|
+
var _a2, _b2, _c2;
|
|
16646
17904
|
if (!state) return;
|
|
16647
17905
|
if (state.metadata) {
|
|
16648
17906
|
persistentMetadata = ensureRecord(state.metadata);
|
|
@@ -16651,6 +17909,12 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
16651
17909
|
if ((_a2 = state.messages) == null ? void 0 : _a2.length) {
|
|
16652
17910
|
session.hydrateMessages(state.messages);
|
|
16653
17911
|
}
|
|
17912
|
+
if ((_b2 = state.artifacts) == null ? void 0 : _b2.length) {
|
|
17913
|
+
session.hydrateArtifacts(
|
|
17914
|
+
state.artifacts,
|
|
17915
|
+
(_c2 = state.selectedArtifactId) != null ? _c2 : null
|
|
17916
|
+
);
|
|
17917
|
+
}
|
|
16654
17918
|
}).catch((error) => {
|
|
16655
17919
|
if (typeof console !== "undefined") {
|
|
16656
17920
|
console.error("[AgentWidget] Failed to hydrate stored state:", error);
|
|
@@ -17218,7 +18482,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17218
18482
|
}
|
|
17219
18483
|
};
|
|
17220
18484
|
recalcPanelHeight();
|
|
17221
|
-
const ownerWindow = (
|
|
18485
|
+
const ownerWindow = (_K = mount.ownerDocument.defaultView) != null ? _K : window;
|
|
17222
18486
|
ownerWindow.addEventListener("resize", recalcPanelHeight);
|
|
17223
18487
|
destroyCallbacks.push(() => ownerWindow.removeEventListener("resize", recalcPanelHeight));
|
|
17224
18488
|
if (typeof ResizeObserver !== "undefined") {
|
|
@@ -17306,6 +18570,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17306
18570
|
session.clearMessages();
|
|
17307
18571
|
messageCache.clear();
|
|
17308
18572
|
resumeAutoScroll();
|
|
18573
|
+
removeAskUserQuestionSheet(panelElements.composerOverlay);
|
|
17309
18574
|
try {
|
|
17310
18575
|
localStorage.removeItem(DEFAULT_CHAT_HISTORY_STORAGE_KEY);
|
|
17311
18576
|
if (config.debug) {
|
|
@@ -17441,7 +18706,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17441
18706
|
}
|
|
17442
18707
|
const controller = {
|
|
17443
18708
|
update(nextConfig) {
|
|
17444
|
-
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,
|
|
18709
|
+
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;
|
|
17445
18710
|
const previousToolCallConfig = config.toolCall;
|
|
17446
18711
|
const previousMessageActions = config.messageActions;
|
|
17447
18712
|
const previousLayoutMessages = (_a2 = config.layout) == null ? void 0 : _a2.messages;
|
|
@@ -17655,7 +18920,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17655
18920
|
const layoutShowIcon = (_O2 = (_N2 = config.layout) == null ? void 0 : _N2.header) == null ? void 0 : _O2.showIcon;
|
|
17656
18921
|
const shouldHideIcon = headerIconHidden || layoutShowIcon === false;
|
|
17657
18922
|
const headerIconName = launcher.headerIconName;
|
|
17658
|
-
const headerIconSize = (
|
|
18923
|
+
const headerIconSize = (_P2 = launcher.headerIconSize) != null ? _P2 : "48px";
|
|
17659
18924
|
if (iconHolder) {
|
|
17660
18925
|
const headerEl = container.querySelector(".persona-border-b-persona-divider");
|
|
17661
18926
|
const headerCopy = headerEl == null ? void 0 : headerEl.querySelector(".persona-flex-col");
|
|
@@ -17682,7 +18947,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17682
18947
|
if (iconSvg) {
|
|
17683
18948
|
iconHolder.replaceChildren(iconSvg);
|
|
17684
18949
|
} else {
|
|
17685
|
-
iconHolder.textContent = (
|
|
18950
|
+
iconHolder.textContent = (_Q2 = launcher.agentIconText) != null ? _Q2 : "\u{1F4AC}";
|
|
17686
18951
|
}
|
|
17687
18952
|
} else if (launcher.iconUrl) {
|
|
17688
18953
|
const img2 = iconHolder.querySelector("img");
|
|
@@ -18606,6 +19871,14 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18606
19871
|
if (!artifactsSidebarEnabled(config)) return;
|
|
18607
19872
|
session.clearArtifacts();
|
|
18608
19873
|
},
|
|
19874
|
+
getArtifacts() {
|
|
19875
|
+
var _a2;
|
|
19876
|
+
return (_a2 = session == null ? void 0 : session.getArtifacts()) != null ? _a2 : [];
|
|
19877
|
+
},
|
|
19878
|
+
getSelectedArtifactId() {
|
|
19879
|
+
var _a2;
|
|
19880
|
+
return (_a2 = session == null ? void 0 : session.getSelectedArtifactId()) != null ? _a2 : null;
|
|
19881
|
+
},
|
|
18609
19882
|
focusInput() {
|
|
18610
19883
|
if (launcherEnabled && !open) return false;
|
|
18611
19884
|
if (!textarea) return false;
|
|
@@ -18723,7 +19996,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18723
19996
|
}
|
|
18724
19997
|
}
|
|
18725
19998
|
};
|
|
18726
|
-
const shouldExposeDebugApi = ((
|
|
19999
|
+
const shouldExposeDebugApi = ((_L = runtimeOptions == null ? void 0 : runtimeOptions.debugTools) != null ? _L : false) || Boolean(config.debug);
|
|
18727
20000
|
if (shouldExposeDebugApi && typeof window !== "undefined") {
|
|
18728
20001
|
const previousDebug = window.AgentWidgetBrowser;
|
|
18729
20002
|
const debugApi = {
|
|
@@ -18826,9 +20099,9 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18826
20099
|
const voiceKey = `${persistConfig.keyPrefix}widget-voice`;
|
|
18827
20100
|
const voiceModeKey = `${persistConfig.keyPrefix}widget-voice-mode`;
|
|
18828
20101
|
if (storage) {
|
|
18829
|
-
const wasOpen = ((
|
|
18830
|
-
const wasVoiceActive = ((
|
|
18831
|
-
const wasInVoiceMode = ((
|
|
20102
|
+
const wasOpen = ((_M = persistConfig.persist) == null ? void 0 : _M.openState) && storage.getItem(openKey) === "true";
|
|
20103
|
+
const wasVoiceActive = ((_N = persistConfig.persist) == null ? void 0 : _N.voiceState) && storage.getItem(voiceKey) === "true";
|
|
20104
|
+
const wasInVoiceMode = ((_O = persistConfig.persist) == null ? void 0 : _O.voiceState) && storage.getItem(voiceModeKey) === "true";
|
|
18832
20105
|
if (wasOpen) {
|
|
18833
20106
|
setTimeout(() => {
|
|
18834
20107
|
controller.open();
|
|
@@ -18845,7 +20118,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18845
20118
|
}, 100);
|
|
18846
20119
|
}, 0);
|
|
18847
20120
|
}
|
|
18848
|
-
if ((
|
|
20121
|
+
if ((_P = persistConfig.persist) == null ? void 0 : _P.openState) {
|
|
18849
20122
|
eventBus.on("widget:opened", () => {
|
|
18850
20123
|
storage.setItem(openKey, "true");
|
|
18851
20124
|
});
|
|
@@ -18853,7 +20126,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
18853
20126
|
storage.setItem(openKey, "false");
|
|
18854
20127
|
});
|
|
18855
20128
|
}
|
|
18856
|
-
if ((
|
|
20129
|
+
if ((_Q = persistConfig.persist) == null ? void 0 : _Q.voiceState) {
|
|
18857
20130
|
eventBus.on("voice:state", (event) => {
|
|
18858
20131
|
storage.setItem(voiceKey, event.active ? "true" : "false");
|
|
18859
20132
|
});
|