@aintela/chat 0.2.15
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 +161 -0
- package/dist/ClientMessage-EKgfuTp8.js +40 -0
- package/dist/ClientMessage-EKgfuTp8.js.map +1 -0
- package/dist/Memory-DjLZqgbF.js +84 -0
- package/dist/Memory-DjLZqgbF.js.map +1 -0
- package/dist/Prompt-DZb7OaPp.js +37 -0
- package/dist/Prompt-DZb7OaPp.js.map +1 -0
- package/dist/artifactHtmlHandler-CMQJf1cX.js +41 -0
- package/dist/artifactHtmlHandler-CMQJf1cX.js.map +1 -0
- package/dist/auth-CcTgInbY.js +524 -0
- package/dist/auth-CcTgInbY.js.map +1 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.js +14159 -0
- package/dist/components.js.map +1 -0
- package/dist/environmentUtils-BaKw5_VD.js +462 -0
- package/dist/environmentUtils-BaKw5_VD.js.map +1 -0
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.js +9 -0
- package/dist/hooks.js.map +1 -0
- package/dist/httpArtifactService-BAR60Gu1.js +1802 -0
- package/dist/httpArtifactService-BAR60Gu1.js.map +1 -0
- package/dist/httpSessionService-5Kr__oQL.js +279 -0
- package/dist/httpSessionService-5Kr__oQL.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +2 -0
- package/dist/interfaces.js +11 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/models.d.ts +2 -0
- package/dist/models.js +54 -0
- package/dist/models.js.map +1 -0
- package/dist/serializer-DyHZxlAG.js +1276 -0
- package/dist/serializer-DyHZxlAG.js.map +1 -0
- package/dist/services.d.ts +2 -0
- package/dist/services.js +16 -0
- package/dist/services.js.map +1 -0
- package/dist/sortable-table-DgQHxWIh.js +819 -0
- package/dist/sortable-table-DgQHxWIh.js.map +1 -0
- package/dist/src/ErrorBondary.d.ts +10 -0
- package/dist/src/components/AiChat/AiChat.d.ts +3 -0
- package/dist/src/components/AiChat/AiChatContext.d.ts +76 -0
- package/dist/src/components/AiChat/AiChatDrawer.d.ts +3 -0
- package/dist/src/components/AiChat/AiChatFloating.d.ts +3 -0
- package/dist/src/components/AiChat/AiChatProvider.d.ts +7 -0
- package/dist/src/components/AiChat/AiChatSessionStore.d.ts +1 -0
- package/dist/src/components/AiChat/AiChatTypes.d.ts +227 -0
- package/dist/src/components/AiChat/ChatPane/AlertDialog.d.ts +12 -0
- package/dist/src/components/AiChat/ChatPane/AskUserSheet.d.ts +25 -0
- package/dist/src/components/AiChat/ChatPane/ChatPane.d.ts +7 -0
- package/dist/src/components/AiChat/ChatPane/ConnectionState.d.ts +2 -0
- package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +12 -0
- package/dist/src/components/AiChat/ChatPane/Event.d.ts +6 -0
- package/dist/src/components/AiChat/ChatPane/FloatingConnectionStatus.d.ts +8 -0
- package/dist/src/components/AiChat/ChatPane/FriendlyPartDisplay.d.ts +13 -0
- package/dist/src/components/AiChat/ChatPane/LastPrompts.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/Message.d.ts +11 -0
- package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +16 -0
- package/dist/src/components/AiChat/ChatPane/MessageNonTextDisplay.d.ts +16 -0
- package/dist/src/components/AiChat/ChatPane/MessagePart.d.ts +15 -0
- package/dist/src/components/AiChat/ChatPane/MessagePersona.d.ts +13 -0
- package/dist/src/components/AiChat/ChatPane/MessageUser.d.ts +8 -0
- package/dist/src/components/AiChat/ChatPane/ModelSelector.d.ts +11 -0
- package/dist/src/components/AiChat/ChatPane/Prompt.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/SessionDataDialog.d.ts +7 -0
- package/dist/src/components/AiChat/ChatPane/StickyQuestionHeader.d.ts +7 -0
- package/dist/src/components/AiChat/ChatPane/StreamStatistics.d.ts +32 -0
- package/dist/src/components/AiChat/ChatPane/SubAgentBox.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/TaskList.d.ts +6 -0
- package/dist/src/components/AiChat/ChatPane/friendlyToolConfig.d.ts +11 -0
- package/dist/src/components/AiChat/ChatPane/parts/AskUserPart.d.ts +8 -0
- package/dist/src/components/AiChat/ChatPane/parts/BoxedPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/FunctionPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/SuspendedPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/TextPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/ThoughtPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/UiToolDispatcher.d.ts +16 -0
- package/dist/src/components/AiChat/ChatPane/parts/WaitingPart.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +20 -0
- package/dist/src/components/AiChat/ChatPane/parts/index.test.d.ts +1 -0
- package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +22 -0
- package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.d.ts +121 -0
- package/dist/src/components/AiChat/index.d.ts +13 -0
- package/dist/src/components/AiChat/sessionStateManagerService.d.ts +47 -0
- package/dist/src/components/AiChat/stateConfiguration.d.ts +80 -0
- package/dist/src/components/Library/ArtifactRender.d.ts +18 -0
- package/dist/src/components/Library/DelayTextComponent.d.ts +9 -0
- package/dist/src/components/Library/LinearBackgroundProgress.d.ts +8 -0
- package/dist/src/components/Library/LinearProgressBarWithMarkers.d.ts +14 -0
- package/dist/src/components/Library/LoadingDots.d.ts +8 -0
- package/dist/src/components/Library/MarkdowmExtended.d.ts +32 -0
- package/dist/src/components/Library/VizLibrary/Skeletons/ChartSkeleton.d.ts +3 -0
- package/dist/src/components/Library/VizLibrary/Skeletons/IFrameSkeleton.d.ts +3 -0
- package/dist/src/components/Library/VizLibrary/Skeletons/MetricGroupSkeleton.d.ts +8 -0
- package/dist/src/components/Library/VizLibrary/Skeletons/MetricSkeleton.d.ts +7 -0
- package/dist/src/components/Library/VizLibrary/Skeletons/TableSkeleton.d.ts +7 -0
- package/dist/src/components/Library/VizLibrary/index.d.ts +5 -0
- package/dist/src/components/LlmResponseRender/EnvironmentContext.d.ts +33 -0
- package/dist/src/components/LlmResponseRender/GeneratingVisualization.d.ts +13 -0
- package/dist/src/components/LlmResponseRender/LiveJsxBlock.d.ts +55 -0
- package/dist/src/components/LlmResponseRender/LlmResponseRender.d.ts +29 -0
- package/dist/src/components/LlmResponseRender/index.d.ts +6 -0
- package/dist/src/components/LlmResponseRender/jsxScope.d.ts +41 -0
- package/dist/src/components/LlmResponseRender/liveTsxConfig.d.ts +18 -0
- package/dist/src/components/LlmResponseRender/parseBlocks.d.ts +39 -0
- package/dist/src/components/Stopwatch.d.ts +12 -0
- package/dist/src/components/index.d.ts +30 -0
- package/dist/src/components/v2/AgentActivityV2.d.ts +32 -0
- package/dist/src/components/v2/AiChatFloatingV2.d.ts +3 -0
- package/dist/src/components/v2/AiChatV2Pane.d.ts +20 -0
- package/dist/src/components/v2/AppBarV2.d.ts +38 -0
- package/dist/src/components/v2/AppRailV2.d.ts +21 -0
- package/dist/src/components/v2/AppShellV2.d.ts +13 -0
- package/dist/src/components/v2/ChatsHistoryV2.d.ts +47 -0
- package/dist/src/components/v2/LastPromptsV2.d.ts +6 -0
- package/dist/src/components/v2/MobileDrawerV2.d.ts +43 -0
- package/dist/src/components/v2/PromptV2.d.ts +164 -0
- package/dist/src/components/v2/RunProgressPanelV2.d.ts +28 -0
- package/dist/src/components/v2/RunProgressStripV2.d.ts +2 -0
- package/dist/src/components/v2/Sparkline.d.ts +10 -0
- package/dist/src/components/v2/SubAgentBoxV2.d.ts +15 -0
- package/dist/src/components/v2/TaskListV2.d.ts +8 -0
- package/dist/src/components/v2/icons.d.ts +42 -0
- package/dist/src/components/v2/index.d.ts +34 -0
- package/dist/src/components/v2/styles.d.ts +6 -0
- package/dist/src/components/v2/toolCategories.d.ts +18 -0
- package/dist/src/components/v2/useResponsiveLayout.d.ts +9 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/useChatSessions.d.ts +68 -0
- package/dist/src/hooks/useContainerWidth.d.ts +2 -0
- package/dist/src/hooks/useIntervalHook.d.ts +2 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/interfaces/IHeartbeatPort.d.ts +4 -0
- package/dist/src/interfaces/INotificationPort.d.ts +4 -0
- package/dist/src/interfaces/index.d.ts +4 -0
- package/dist/src/interfaces/memoryService.d.ts +37 -0
- package/dist/src/interfaces/schedulingService.d.ts +64 -0
- package/dist/src/models/Agent.d.ts +32 -0
- package/dist/src/models/Artifact.d.ts +21 -0
- package/dist/src/models/ArtifactData.d.ts +30 -0
- package/dist/src/models/ChatSession.d.ts +57 -0
- package/dist/src/models/ClientMessage.d.ts +38 -0
- package/dist/src/models/Customer.d.ts +7 -0
- package/dist/src/models/EndMessageData.d.ts +6 -0
- package/dist/src/models/IAbiContext.d.ts +8 -0
- package/dist/src/models/IDBStorable.d.ts +14 -0
- package/dist/src/models/Interaction.d.ts +36 -0
- package/dist/src/models/InteractionPart.d.ts +69 -0
- package/dist/src/models/LlmSession.d.ts +10 -0
- package/dist/src/models/Memory.d.ts +48 -0
- package/dist/src/models/Notification.d.ts +11 -0
- package/dist/src/models/Prompt.d.ts +20 -0
- package/dist/src/models/SendMessageResponse.d.ts +21 -0
- package/dist/src/models/ServerEvent.d.ts +130 -0
- package/dist/src/models/connectionState.d.ts +9 -0
- package/dist/src/models/contexts.d.ts +33 -0
- package/dist/src/models/enums.d.ts +333 -0
- package/dist/src/models/index.d.ts +36 -0
- package/dist/src/models/semanticKernelModel/index.d.ts +2 -0
- package/dist/src/models/semanticKernelModel/init.d.ts +1 -0
- package/dist/src/models/semanticKernelModel/models.d.ts +208 -0
- package/dist/src/models/semanticKernelModel/serializer.d.ts +40 -0
- package/dist/src/models/serverReponse.d.ts +5 -0
- package/dist/src/models/subAgentModel.d.ts +48 -0
- package/dist/src/models/todoListModel.d.ts +18 -0
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +163 -0
- package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +75 -0
- package/dist/src/services/artifactHtmlHandler.d.ts +6 -0
- package/dist/src/services/eventBusService.d.ts +119 -0
- package/dist/src/services/httpArtifactService.d.ts +25 -0
- package/dist/src/services/httpSessionService.d.ts +31 -0
- package/dist/src/services/index.d.ts +16 -0
- package/dist/src/services/interactionService.d.ts +28 -0
- package/dist/src/services/interactionService.test.d.ts +1 -0
- package/dist/src/services/interfaces/artifactService.d.ts +13 -0
- package/dist/src/services/servers/AgentGatewayService.d.ts +167 -0
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +44 -0
- package/dist/src/services/servers/agentGatewayWSAsync.test.d.ts +1 -0
- package/dist/src/services/servers/sessionService/ISessionService.d.ts +20 -0
- package/dist/src/services/sessionEventDecoder.d.ts +22 -0
- package/dist/src/services/sessionEventDecoder.test.d.ts +1 -0
- package/dist/src/services/storageService.d.ts +73 -0
- package/dist/src/themes/index.d.ts +3 -0
- package/dist/src/themes/v2-chart-palette.d.ts +1 -0
- package/dist/src/themes/v2.d.ts +71 -0
- package/dist/src/utils/auth.d.ts +9 -0
- package/dist/src/utils/envOverrides.d.ts +23 -0
- package/dist/src/utils/envUtils.d.ts +13 -0
- package/dist/src/utils/environmentUtils.d.ts +43 -0
- package/dist/src/utils/fileUtils.d.ts +6 -0
- package/dist/src/utils/getAgentArtifactsBaseUrl.d.ts +1 -0
- package/dist/src/utils/getAgentBaseUrl.d.ts +1 -0
- package/dist/src/utils/getDotNetBaseUrl.d.ts +5 -0
- package/dist/src/utils/index.d.ts +17 -0
- package/dist/src/utils/interactionIdChecker.d.ts +27 -0
- package/dist/src/utils/jsonDetector.d.ts +50 -0
- package/dist/src/utils/jsonUtils.d.ts +1 -0
- package/dist/src/utils/materialIconsList.d.ts +42 -0
- package/dist/src/utils/materialIconsSvg.d.ts +51 -0
- package/dist/src/utils/objectUtils.d.ts +31 -0
- package/dist/src/utils/parseArtifact.d.ts +3 -0
- package/dist/src/utils/sessionWindowParameters.d.ts +3 -0
- package/dist/src/utils/sortable-table.d.ts +31 -0
- package/dist/src/utils/stringUtils.d.ts +8 -0
- package/dist/src/utils/uriUtils.d.ts +39 -0
- package/dist/src/utils/urlParser.d.ts +8 -0
- package/dist/style.css +94 -0
- package/dist/tests/fakes/fakeWebSocket.d.ts +32 -0
- package/dist/tests/fakes/makeGateway.d.ts +24 -0
- package/dist/tests/fixtures.d.ts +73 -0
- package/dist/useChatSessions-DttlifVk.js +107 -0
- package/dist/useChatSessions-DttlifVk.js.map +1 -0
- package/dist/useContainerWidth-Df2PmSoC.js +52 -0
- package/dist/useContainerWidth-Df2PmSoC.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +49 -0
- package/dist/utils.js.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,1802 @@
|
|
|
1
|
+
var et = Object.defineProperty;
|
|
2
|
+
var dt = (E, t, e) => t in E ? et(E, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : E[t] = e;
|
|
3
|
+
var g = (E, t) => et(E, "name", { value: t, configurable: !0 });
|
|
4
|
+
var a = (E, t, e) => dt(E, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { d as _, t as gt, E as T, k as ft, j as mt, q as pt, C as L } from "./environmentUtils-BaKw5_VD.js";
|
|
6
|
+
import { I as A, S as lt, g as St, L as wt, P as F, b as Tt, e as yt, T as It, c as Ct } from "./serializer-DyHZxlAG.js";
|
|
7
|
+
import { unified as vt } from "unified";
|
|
8
|
+
import Et from "remark-parse";
|
|
9
|
+
import { toMarkdown as Mt } from "mdast-util-to-markdown";
|
|
10
|
+
import { format as Ot } from "date-fns";
|
|
11
|
+
import Dt from "lodash";
|
|
12
|
+
import { P as At, C as P } from "./Prompt-DZb7OaPp.js";
|
|
13
|
+
const S = {
|
|
14
|
+
ARTIFACTS: "envision-artifacts",
|
|
15
|
+
SECTIONS: "envision-sections",
|
|
16
|
+
PROMPTS: "envision-prompts"
|
|
17
|
+
}, k = [
|
|
18
|
+
{
|
|
19
|
+
id: "dashboards",
|
|
20
|
+
name: "Dashboards",
|
|
21
|
+
isDefault: !0,
|
|
22
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
23
|
+
iconType: "dashboard"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "charts",
|
|
27
|
+
name: "Chart",
|
|
28
|
+
isDefault: !0,
|
|
29
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
iconType: "chart"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "data-analytics",
|
|
34
|
+
name: "Data Analytics",
|
|
35
|
+
isDefault: !0,
|
|
36
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
|
+
iconType: "folder"
|
|
38
|
+
}
|
|
39
|
+
], W = class W {
|
|
40
|
+
constructor() {
|
|
41
|
+
a(this, "onPromptCreated", /* @__PURE__ */ g(() => {
|
|
42
|
+
}, "onPromptCreated"));
|
|
43
|
+
}
|
|
44
|
+
getItem(t) {
|
|
45
|
+
return localStorage.getItem(t);
|
|
46
|
+
}
|
|
47
|
+
setItem(t, e) {
|
|
48
|
+
localStorage.setItem(t, e);
|
|
49
|
+
}
|
|
50
|
+
removeItem(t) {
|
|
51
|
+
localStorage.removeItem(t);
|
|
52
|
+
}
|
|
53
|
+
initializeStorage() {
|
|
54
|
+
try {
|
|
55
|
+
const t = localStorage.getItem(S.SECTIONS);
|
|
56
|
+
if (!t)
|
|
57
|
+
localStorage.setItem(S.SECTIONS, JSON.stringify(k));
|
|
58
|
+
else {
|
|
59
|
+
const s = JSON.parse(t);
|
|
60
|
+
if (k.some(
|
|
61
|
+
(i) => !s.find((r) => r.id === i.id)
|
|
62
|
+
)) {
|
|
63
|
+
const i = [...s];
|
|
64
|
+
k.forEach((r) => {
|
|
65
|
+
s.find((l) => l.id === r.id) || i.push(r);
|
|
66
|
+
}), localStorage.setItem(S.SECTIONS, JSON.stringify(i));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const e = localStorage.getItem(S.ARTIFACTS);
|
|
70
|
+
if (e) {
|
|
71
|
+
const s = JSON.parse(e);
|
|
72
|
+
let n = !1;
|
|
73
|
+
const i = s.map((r) => {
|
|
74
|
+
if (!r.sectionId) {
|
|
75
|
+
n = !0;
|
|
76
|
+
let l = "data-analytics";
|
|
77
|
+
return r.type === _.Dashboard ? l = "dashboards" : r.type === _.Chart && (l = "charts"), {
|
|
78
|
+
...r,
|
|
79
|
+
sectionId: l
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return r;
|
|
83
|
+
});
|
|
84
|
+
n && localStorage.setItem(S.ARTIFACTS, JSON.stringify(i));
|
|
85
|
+
}
|
|
86
|
+
} catch (t) {
|
|
87
|
+
console.error("Error initializing storage:", t);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
getSections() {
|
|
91
|
+
try {
|
|
92
|
+
const t = localStorage.getItem(S.SECTIONS);
|
|
93
|
+
return t ? JSON.parse(t) : k;
|
|
94
|
+
} catch (t) {
|
|
95
|
+
return console.error("Error loading sections:", t), k;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getArtifacts() {
|
|
99
|
+
try {
|
|
100
|
+
const t = localStorage.getItem(S.ARTIFACTS);
|
|
101
|
+
return t ? JSON.parse(t) : [];
|
|
102
|
+
} catch (t) {
|
|
103
|
+
return console.error("Error loading artifacts:", t), [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
createSection(t, e = "folder") {
|
|
107
|
+
const s = {
|
|
108
|
+
id: crypto.randomUUID(),
|
|
109
|
+
name: t,
|
|
110
|
+
isDefault: !1,
|
|
111
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
112
|
+
iconType: e
|
|
113
|
+
}, n = this.getSections();
|
|
114
|
+
return n.push(s), localStorage.setItem(S.SECTIONS, JSON.stringify(n)), s;
|
|
115
|
+
}
|
|
116
|
+
updateSection(t, e) {
|
|
117
|
+
const s = this.getSections(), n = s.findIndex((i) => i.id === t);
|
|
118
|
+
n >= 0 && (s[n] = { ...s[n], ...e }, localStorage.setItem(S.SECTIONS, JSON.stringify(s)));
|
|
119
|
+
}
|
|
120
|
+
deleteSection(t) {
|
|
121
|
+
const e = this.getSections(), s = e.find((n) => n.id === t);
|
|
122
|
+
if (s && !s.isDefault) {
|
|
123
|
+
const n = this.getArtifacts(), i = s.iconType === "dashboard" ? "dashboards" : s.iconType === "chart" ? "charts" : "data-analytics", r = n.map((c) => c.sectionId === t ? { ...c, sectionId: i } : c);
|
|
124
|
+
localStorage.setItem(S.ARTIFACTS, JSON.stringify(r));
|
|
125
|
+
const l = e.filter((c) => c.id !== t);
|
|
126
|
+
localStorage.setItem(S.SECTIONS, JSON.stringify(l));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
storeArtifact(t) {
|
|
130
|
+
try {
|
|
131
|
+
const e = this.getArtifacts(), s = e.findIndex((n) => n.id === t.id);
|
|
132
|
+
if (s >= 0)
|
|
133
|
+
e[s] = t;
|
|
134
|
+
else {
|
|
135
|
+
let n = "data-analytics";
|
|
136
|
+
t.type === _.Dashboard ? n = "dashboards" : t.type === _.Chart && (n = "charts");
|
|
137
|
+
const i = {
|
|
138
|
+
...t,
|
|
139
|
+
created: t.created || (/* @__PURE__ */ new Date()).toISOString(),
|
|
140
|
+
sectionId: t.sectionId || n
|
|
141
|
+
};
|
|
142
|
+
e.push(i);
|
|
143
|
+
}
|
|
144
|
+
localStorage.setItem(S.ARTIFACTS, JSON.stringify(e));
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error("Error storing artifact:", e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
moveArtifact(t, e) {
|
|
150
|
+
const s = this.getArtifacts(), n = s.findIndex((i) => i.id === t);
|
|
151
|
+
n >= 0 && (s[n] = { ...s[n], sectionId: e }, localStorage.setItem(S.ARTIFACTS, JSON.stringify(s)));
|
|
152
|
+
}
|
|
153
|
+
deleteArtifact(t) {
|
|
154
|
+
const s = this.getArtifacts().filter((n) => n.id !== t);
|
|
155
|
+
localStorage.setItem(S.ARTIFACTS, JSON.stringify(s));
|
|
156
|
+
}
|
|
157
|
+
updateArtifact(t, e) {
|
|
158
|
+
const s = this.getArtifacts(), n = s.findIndex((i) => i.id === t);
|
|
159
|
+
n >= 0 && (s[n] = { ...s[n], ...e }, localStorage.setItem(S.ARTIFACTS, JSON.stringify(s)));
|
|
160
|
+
}
|
|
161
|
+
getArtifactsBySection(t) {
|
|
162
|
+
return this.getArtifacts().filter((s) => s.sectionId === t);
|
|
163
|
+
}
|
|
164
|
+
// Prompt management methods
|
|
165
|
+
getPrompts() {
|
|
166
|
+
try {
|
|
167
|
+
const t = localStorage.getItem(S.PROMPTS);
|
|
168
|
+
return t ? JSON.parse(t).sort((s, n) => new Date(n.created).getTime() - new Date(s.created).getTime()) : [];
|
|
169
|
+
} catch (t) {
|
|
170
|
+
return console.error("Error loading prompts:", t), [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
storePrompt(t) {
|
|
174
|
+
try {
|
|
175
|
+
const e = this.getPrompts();
|
|
176
|
+
e.length > 0 && e[0].promptText === t.promptText && (e[0].created = t.created, e[0].id = t.id), e.unshift(t);
|
|
177
|
+
const s = e.slice(0, 50);
|
|
178
|
+
localStorage.setItem(S.PROMPTS, JSON.stringify(s));
|
|
179
|
+
} catch (e) {
|
|
180
|
+
console.error("Error storing prompt:", e);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
deletePrompt(t) {
|
|
184
|
+
try {
|
|
185
|
+
const s = this.getPrompts().filter((n) => n.id !== t);
|
|
186
|
+
localStorage.setItem(S.PROMPTS, JSON.stringify(s));
|
|
187
|
+
} catch (e) {
|
|
188
|
+
console.error("Error deleting prompt:", e);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
clearAllPrompts() {
|
|
192
|
+
try {
|
|
193
|
+
localStorage.removeItem(S.PROMPTS);
|
|
194
|
+
} catch (t) {
|
|
195
|
+
console.error("Error clearing prompts:", t);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
g(W, "LocalStorageService");
|
|
200
|
+
let st = W;
|
|
201
|
+
const Kt = /* @__PURE__ */ g((E) => {
|
|
202
|
+
const t = E.getPrompts(), e = t.length;
|
|
203
|
+
if (e > 0) {
|
|
204
|
+
const s = t[0].promptText, n = t[t.length - 1].promptText, i = t[0].created;
|
|
205
|
+
return { promptState: e + "_" + s + "_" + n + "_" + i };
|
|
206
|
+
} else
|
|
207
|
+
return { promptState: "0" };
|
|
208
|
+
}, "usePromptState"), J = class J {
|
|
209
|
+
constructor() {
|
|
210
|
+
a(this, "activityLost", "activityLost");
|
|
211
|
+
a(this, "artifactGenerated", "artifactGenerated");
|
|
212
|
+
a(this, "artifactSelected", "artifactSelected");
|
|
213
|
+
a(this, "artifactDeleted", "artifactDeleted");
|
|
214
|
+
a(this, "gatewayMessage", "gatewayMessage");
|
|
215
|
+
a(this, "gatewayTurnComplete", "gatewayTurnComplete");
|
|
216
|
+
a(this, "gatewayStreamError", "gatewayStreamError");
|
|
217
|
+
a(this, "gatewayTurnOpen", "gatewayTurnOpen");
|
|
218
|
+
a(this, "sessionCreated", "sessionCreated");
|
|
219
|
+
a(this, "sessionUpdated", "sessionUpdated");
|
|
220
|
+
a(this, "gatewayFunctionResponse", "gatewayFunctionResponse");
|
|
221
|
+
a(this, "uiUnsavedPopoverToggle", "uiUnsavedPopoverToggle");
|
|
222
|
+
a(this, "artifactsStorageUpdated", "artifactsStorageUpdated");
|
|
223
|
+
a(this, "gatewayStreamEnded", "gatewayStreamEnded");
|
|
224
|
+
a(this, "streamNewChunk", "streamNewChunk");
|
|
225
|
+
a(this, "gatewayEndMessageData", "gatewayEndMessageData");
|
|
226
|
+
a(this, "connectionStateChange", "connectionStateChange");
|
|
227
|
+
a(this, "onMessageSent", "onMessageSent");
|
|
228
|
+
a(this, "onMessageError", "onMessageError");
|
|
229
|
+
a(this, "onToolEvent", "onToolEvent");
|
|
230
|
+
a(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
g(J, "EventTypes");
|
|
234
|
+
let U = J;
|
|
235
|
+
const o = new U(), q = class q {
|
|
236
|
+
constructor() {
|
|
237
|
+
a(this, "listeners", {});
|
|
238
|
+
a(this, "listenersCount", {});
|
|
239
|
+
}
|
|
240
|
+
callListeners(t, ...e) {
|
|
241
|
+
const s = this.listeners[t];
|
|
242
|
+
if (this.listenersCount[t] = this.listenersCount[t] + 1, s) {
|
|
243
|
+
const n = s.map((i) => i(...e));
|
|
244
|
+
Promise.all(n).catch((i) => {
|
|
245
|
+
console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${i}`, s);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
addListener(t, e) {
|
|
250
|
+
this.listeners[t] || (this.listeners[t] = [], this.listenersCount[t] = 0), this.listeners[t].push(e);
|
|
251
|
+
}
|
|
252
|
+
getEventState(t) {
|
|
253
|
+
return this.listenersCount[t];
|
|
254
|
+
}
|
|
255
|
+
activityOnLost(t) {
|
|
256
|
+
const e = o.activityLost;
|
|
257
|
+
this.addListener(e, t);
|
|
258
|
+
}
|
|
259
|
+
activityEmitLost() {
|
|
260
|
+
this.callListeners(o.activityLost);
|
|
261
|
+
}
|
|
262
|
+
/* typed artifact listeners */
|
|
263
|
+
artifactOnGenerated(t) {
|
|
264
|
+
const e = o.artifactGenerated;
|
|
265
|
+
this.addListener(e, t);
|
|
266
|
+
}
|
|
267
|
+
artifactEmitGenerated(t) {
|
|
268
|
+
this.callListeners(o.artifactGenerated, t);
|
|
269
|
+
}
|
|
270
|
+
artifactOffGenerated(t) {
|
|
271
|
+
const e = o.artifactGenerated;
|
|
272
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
273
|
+
}
|
|
274
|
+
artifactOnSelected(t) {
|
|
275
|
+
const e = o.artifactSelected;
|
|
276
|
+
this.addListener(e, t);
|
|
277
|
+
}
|
|
278
|
+
artifactEmitSelected(t) {
|
|
279
|
+
this.callListeners(o.artifactSelected, t);
|
|
280
|
+
}
|
|
281
|
+
artifactOffSelected(t) {
|
|
282
|
+
const e = o.artifactSelected;
|
|
283
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
284
|
+
}
|
|
285
|
+
artifactOnDeleted(t) {
|
|
286
|
+
const e = o.artifactDeleted;
|
|
287
|
+
this.addListener(e, t);
|
|
288
|
+
}
|
|
289
|
+
artifactEmitDeleted(t) {
|
|
290
|
+
this.callListeners(o.artifactDeleted, t);
|
|
291
|
+
}
|
|
292
|
+
artifactOffDeleted(t) {
|
|
293
|
+
const e = o.artifactDeleted;
|
|
294
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
295
|
+
}
|
|
296
|
+
gatewayOnMessage(t) {
|
|
297
|
+
const e = o.gatewayMessage;
|
|
298
|
+
this.addListener(e, t);
|
|
299
|
+
}
|
|
300
|
+
gatewayOnTurnComplete(t) {
|
|
301
|
+
const e = o.gatewayTurnComplete;
|
|
302
|
+
this.addListener(e, t);
|
|
303
|
+
}
|
|
304
|
+
gatewayOnTurnOpen(t) {
|
|
305
|
+
const e = o.gatewayTurnOpen;
|
|
306
|
+
this.addListener(e, t);
|
|
307
|
+
}
|
|
308
|
+
gatewayOnStreamError(t) {
|
|
309
|
+
const e = o.gatewayStreamError;
|
|
310
|
+
this.addListener(e, t);
|
|
311
|
+
}
|
|
312
|
+
gatewayOnStreamEnded(t) {
|
|
313
|
+
const e = o.gatewayStreamEnded;
|
|
314
|
+
this.addListener(e, t);
|
|
315
|
+
}
|
|
316
|
+
gatewayOffStreamEnded(t) {
|
|
317
|
+
const e = o.gatewayStreamEnded;
|
|
318
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
319
|
+
}
|
|
320
|
+
gatewayEmitStreamEnded(t, e) {
|
|
321
|
+
this.callListeners(o.gatewayStreamEnded, t, e);
|
|
322
|
+
}
|
|
323
|
+
gatewayEmitMessage(t, e = null) {
|
|
324
|
+
this.callListeners(o.gatewayMessage, t, e);
|
|
325
|
+
}
|
|
326
|
+
gatewayEmitTurnComplete(t, e) {
|
|
327
|
+
this.callListeners(o.gatewayTurnComplete, t, e);
|
|
328
|
+
}
|
|
329
|
+
gatewayEmitStreamError(t) {
|
|
330
|
+
this.callListeners(o.gatewayStreamError, t);
|
|
331
|
+
}
|
|
332
|
+
gatewayEmitTurnOpen(t) {
|
|
333
|
+
this.callListeners(o.gatewayTurnOpen, t);
|
|
334
|
+
}
|
|
335
|
+
gatewayOffMessage(t) {
|
|
336
|
+
const e = o.gatewayMessage;
|
|
337
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
338
|
+
}
|
|
339
|
+
gatewayOffTurnComplete(t) {
|
|
340
|
+
const e = o.gatewayTurnComplete;
|
|
341
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
342
|
+
}
|
|
343
|
+
gatewayOffTurnOpen(t) {
|
|
344
|
+
const e = o.gatewayTurnOpen;
|
|
345
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
346
|
+
}
|
|
347
|
+
gatewayOffStreamError(t) {
|
|
348
|
+
const e = o.gatewayStreamError;
|
|
349
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
350
|
+
}
|
|
351
|
+
sessionOnCreated(t) {
|
|
352
|
+
const e = o.sessionCreated;
|
|
353
|
+
this.addListener(e, t);
|
|
354
|
+
}
|
|
355
|
+
chatOnMessageSent(t) {
|
|
356
|
+
const e = o.onMessageSent;
|
|
357
|
+
this.addListener(e, t);
|
|
358
|
+
}
|
|
359
|
+
chatOffMessageSent(t) {
|
|
360
|
+
const e = o.onMessageSent;
|
|
361
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
362
|
+
}
|
|
363
|
+
ChatEmitMessageSent(t, e) {
|
|
364
|
+
this.callListeners(o.onMessageSent, t, e);
|
|
365
|
+
}
|
|
366
|
+
chatOnMessageError(t) {
|
|
367
|
+
const e = o.onMessageError;
|
|
368
|
+
this.addListener(e, t);
|
|
369
|
+
}
|
|
370
|
+
chatOffMessageError(t) {
|
|
371
|
+
const e = o.onMessageError;
|
|
372
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
373
|
+
}
|
|
374
|
+
ChatEmitMessageError(t) {
|
|
375
|
+
this.callListeners(o.onMessageError, t);
|
|
376
|
+
}
|
|
377
|
+
sessionOnUpdated(t) {
|
|
378
|
+
const e = o.sessionUpdated;
|
|
379
|
+
this.addListener(e, t);
|
|
380
|
+
}
|
|
381
|
+
sessionEmitCreated(t) {
|
|
382
|
+
this.callListeners(o.sessionCreated, t);
|
|
383
|
+
}
|
|
384
|
+
sessionEmitUpdated(t) {
|
|
385
|
+
this.callListeners(o.sessionUpdated, t);
|
|
386
|
+
}
|
|
387
|
+
sessionOffCreated(t) {
|
|
388
|
+
const e = o.sessionCreated;
|
|
389
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
390
|
+
}
|
|
391
|
+
sessionOffUpdated(t) {
|
|
392
|
+
const e = o.sessionUpdated;
|
|
393
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
394
|
+
}
|
|
395
|
+
gatewayEmitFunctionResponse(t) {
|
|
396
|
+
this.callListeners(o.gatewayFunctionResponse, t);
|
|
397
|
+
}
|
|
398
|
+
gatewayOffFunctionResponse(t) {
|
|
399
|
+
const e = o.gatewayFunctionResponse;
|
|
400
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
401
|
+
}
|
|
402
|
+
gatewayOnFunctionResponse(t) {
|
|
403
|
+
const e = o.gatewayFunctionResponse;
|
|
404
|
+
this.addListener(e, t);
|
|
405
|
+
}
|
|
406
|
+
// UI events
|
|
407
|
+
uiOnUnsavedPopoverToggle(t) {
|
|
408
|
+
const e = o.uiUnsavedPopoverToggle;
|
|
409
|
+
this.addListener(e, t);
|
|
410
|
+
}
|
|
411
|
+
uiEmitUnsavedPopoverToggle(t) {
|
|
412
|
+
this.callListeners(o.uiUnsavedPopoverToggle, t);
|
|
413
|
+
}
|
|
414
|
+
uiOffUnsavedPopoverToggle(t) {
|
|
415
|
+
const e = o.uiUnsavedPopoverToggle;
|
|
416
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
417
|
+
}
|
|
418
|
+
// Artifacts storage update events
|
|
419
|
+
artifactsOnStorageUpdated(t) {
|
|
420
|
+
const e = o.artifactsStorageUpdated;
|
|
421
|
+
this.addListener(e, t);
|
|
422
|
+
}
|
|
423
|
+
artifactsEmitStorageUpdated() {
|
|
424
|
+
this.callListeners(o.artifactsStorageUpdated);
|
|
425
|
+
}
|
|
426
|
+
artifactsOffStorageUpdated(t) {
|
|
427
|
+
const e = o.artifactsStorageUpdated;
|
|
428
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
429
|
+
}
|
|
430
|
+
streamOnNewChunk(t) {
|
|
431
|
+
const e = o.streamNewChunk;
|
|
432
|
+
this.addListener(e, t);
|
|
433
|
+
}
|
|
434
|
+
streamEmitNewChunk(t) {
|
|
435
|
+
this.callListeners(o.streamNewChunk, t);
|
|
436
|
+
}
|
|
437
|
+
streamOffNewChunk(t) {
|
|
438
|
+
const e = o.streamNewChunk;
|
|
439
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
440
|
+
}
|
|
441
|
+
gatewayOnEndMessageData(t) {
|
|
442
|
+
const e = o.gatewayEndMessageData;
|
|
443
|
+
this.addListener(e, t);
|
|
444
|
+
}
|
|
445
|
+
gatewayEmitEndMessageData(t) {
|
|
446
|
+
this.callListeners(o.gatewayEndMessageData, t);
|
|
447
|
+
}
|
|
448
|
+
gatewayOffEndMessageData(t) {
|
|
449
|
+
const e = o.gatewayEndMessageData;
|
|
450
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
451
|
+
}
|
|
452
|
+
gatewayOnConnectionStateChange(t) {
|
|
453
|
+
const e = o.connectionStateChange;
|
|
454
|
+
this.addListener(e, t);
|
|
455
|
+
}
|
|
456
|
+
gatewayEmitConnectionStateChange(t) {
|
|
457
|
+
this.callListeners(o.connectionStateChange, t);
|
|
458
|
+
}
|
|
459
|
+
gatewayOffConnectionStateChange(t) {
|
|
460
|
+
const e = o.connectionStateChange;
|
|
461
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
462
|
+
}
|
|
463
|
+
gatewayOnToolEvent(t) {
|
|
464
|
+
const e = o.onToolEvent;
|
|
465
|
+
this.addListener(e, t);
|
|
466
|
+
}
|
|
467
|
+
gatewayEmitToolEvent(t, e, s) {
|
|
468
|
+
this.callListeners(o.onToolEvent, t, e, s);
|
|
469
|
+
}
|
|
470
|
+
gatewayOffToolEvent(t) {
|
|
471
|
+
const e = o.onToolEvent;
|
|
472
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
473
|
+
}
|
|
474
|
+
gatewayOnFirstToken(t) {
|
|
475
|
+
const e = o.gatewayFirstToken;
|
|
476
|
+
this.addListener(e, t);
|
|
477
|
+
}
|
|
478
|
+
gatewayEmitFirstToken(t) {
|
|
479
|
+
this.callListeners(o.gatewayFirstToken, t);
|
|
480
|
+
}
|
|
481
|
+
gatewayOffFirstToken(t) {
|
|
482
|
+
const e = o.gatewayFirstToken;
|
|
483
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
g(q, "EventBusService");
|
|
487
|
+
let x = q;
|
|
488
|
+
const G = class G extends x {
|
|
489
|
+
constructor() {
|
|
490
|
+
super();
|
|
491
|
+
}
|
|
492
|
+
gatewayEmitConnectionStateChange(t) {
|
|
493
|
+
console.log("MockEventBusService.gatewayEmitConnectionStateChange");
|
|
494
|
+
}
|
|
495
|
+
gatewayEmitMessage(t, e) {
|
|
496
|
+
gt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
|
|
497
|
+
}
|
|
498
|
+
gatewayEmitTurnComplete(t, e) {
|
|
499
|
+
console.log("MockEventBusService.gatewayEmitTurnComplete");
|
|
500
|
+
}
|
|
501
|
+
gatewayEmitTurnOpen(t) {
|
|
502
|
+
console.log("MockEventBusService.gatewayEmitTurnOpen");
|
|
503
|
+
}
|
|
504
|
+
gatewayEmitFunctionResponse(t) {
|
|
505
|
+
console.log("MockEventBusService.gatewayEmitFunctionResponse");
|
|
506
|
+
}
|
|
507
|
+
gatewayOnFunctionResponse(t) {
|
|
508
|
+
console.log("MockEventBusService.gatewayOnFunctionResponse", t);
|
|
509
|
+
}
|
|
510
|
+
gatewayOffFunctionResponse(t) {
|
|
511
|
+
console.log("MockEventBusService.gatewayOffFunctionResponse", t);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
g(G, "MockEventBusService");
|
|
515
|
+
let nt = G;
|
|
516
|
+
const ht = {
|
|
517
|
+
inline: "inline",
|
|
518
|
+
block: "block"
|
|
519
|
+
}, H = class H {
|
|
520
|
+
constructor() {
|
|
521
|
+
a(this, "parts", []);
|
|
522
|
+
a(this, "isLastGroup", !1);
|
|
523
|
+
a(this, "hasThoughts", !1);
|
|
524
|
+
a(this, "lastWithThoughts", !1);
|
|
525
|
+
a(this, "type", ht.inline);
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
g(H, "InteractionPartGroup");
|
|
529
|
+
let R = H;
|
|
530
|
+
const K = class K {
|
|
531
|
+
constructor(t, e) {
|
|
532
|
+
a(this, "interaction");
|
|
533
|
+
a(this, "eventBusService");
|
|
534
|
+
a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
|
|
535
|
+
if (!t || t.trim().length == 0) return [];
|
|
536
|
+
const e = vt().use(Et).parse(t), s = [];
|
|
537
|
+
let n = null;
|
|
538
|
+
for (const i of e.children)
|
|
539
|
+
i.type === "code" ? (n && (s.push(n), n = null), i.lang === "htmlCanvas" && s.push(`
|
|
540
|
+
\`\`\`liveTsx
|
|
541
|
+
${i.value}
|
|
542
|
+
\`\`\`
|
|
543
|
+
`)) : (n || (n = ""), n += Mt(i));
|
|
544
|
+
return n && s.push(n), s;
|
|
545
|
+
}, "parseTextIntoParts"));
|
|
546
|
+
this.interaction = t, this.eventBusService = e;
|
|
547
|
+
}
|
|
548
|
+
expandSubParts(t, e) {
|
|
549
|
+
const s = this.parseTextIntoParts(t), n = [];
|
|
550
|
+
let i = 0;
|
|
551
|
+
for (const r of s) {
|
|
552
|
+
const l = A.fromText(r);
|
|
553
|
+
l.id = i + "_" + e, n.push(l), i++;
|
|
554
|
+
}
|
|
555
|
+
return n;
|
|
556
|
+
}
|
|
557
|
+
groupPartsByDisplayType(t, e = !0, s = !1) {
|
|
558
|
+
var l;
|
|
559
|
+
const n = [];
|
|
560
|
+
let i = new R();
|
|
561
|
+
for (let c = 0; c < t.length; c++) {
|
|
562
|
+
const u = t[c];
|
|
563
|
+
let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== T.Text && u.eventType !== T.Thought && (u.eventType === T.FunctionCall || u.eventType === T.PartialFunctionCall || u.eventType === T.FunctionResponse) && c < t.length - 1;
|
|
564
|
+
!e && h && !s || (h ? (u.eventType == T.Thought && (i.hasThoughts = !0), i.parts.push(u), i.isLastGroup = c === t.length - 1) : (i.parts.length > 0 && (n.push(i), i = new R()), n.push({
|
|
565
|
+
type: ht.block,
|
|
566
|
+
parts: [u],
|
|
567
|
+
isLastGroup: c === t.length - 1,
|
|
568
|
+
hasThoughts: !1,
|
|
569
|
+
lastWithThoughts: !1
|
|
570
|
+
})));
|
|
571
|
+
}
|
|
572
|
+
i.parts.length > 0 && n.push(i);
|
|
573
|
+
const r = n.filter((c) => c.hasThoughts);
|
|
574
|
+
return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), n;
|
|
575
|
+
}
|
|
576
|
+
isFunctionCall(t) {
|
|
577
|
+
return t == T.FunctionCall || t == T.PartialFunctionCall;
|
|
578
|
+
}
|
|
579
|
+
isFunctionResponse(t) {
|
|
580
|
+
return t == T.FunctionResponse;
|
|
581
|
+
}
|
|
582
|
+
// Computes the next interaction from a server event. Pure with respect to
|
|
583
|
+
// `prev` — no part or array on the prior tree is mutated; modified entities
|
|
584
|
+
// are cloned. The service field `this.interaction` is replaced with the
|
|
585
|
+
// new tree as the last step, so snapshots already handed out to throttled
|
|
586
|
+
// subscribers can't diverge from the live state.
|
|
587
|
+
merge(t) {
|
|
588
|
+
var Q, X, Z, V;
|
|
589
|
+
const e = this.interaction, s = [], n = [], i = A.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
|
|
590
|
+
let l = !1;
|
|
591
|
+
i && (l = !r || i.mustPush || i.mustPush === !1 && (i.eventType !== (r == null ? void 0 : r.eventType) || ((Q = i == null ? void 0 : i.functionDetails) == null ? void 0 : Q.id) !== ((X = r.functionDetails) == null ? void 0 : X.id)));
|
|
592
|
+
let c = e.parts, u = e.functionMap ?? /* @__PURE__ */ new Map(), d = !e.functionMap;
|
|
593
|
+
const h = /* @__PURE__ */ g(() => {
|
|
594
|
+
d || (u = new Map(u), d = !0);
|
|
595
|
+
}, "cloneFunctionMap"), C = /* @__PURE__ */ g(() => {
|
|
596
|
+
c === e.parts && (c = e.parts.slice());
|
|
597
|
+
}, "clonePartsIfShared");
|
|
598
|
+
let m = !1;
|
|
599
|
+
if (l && i) {
|
|
600
|
+
const p = this.isFunctionCall(i.eventType) || this.isFunctionResponse(i.eventType), y = p ? (Z = i.functionDetails) == null ? void 0 : Z.id : void 0;
|
|
601
|
+
p && !y && console.error("Got isCall or isResponse without a callId", i);
|
|
602
|
+
const M = y ? u.get(y) : void 0;
|
|
603
|
+
if (M && y && i.functionDetails) {
|
|
604
|
+
const v = c.findIndex((ut) => {
|
|
605
|
+
var tt;
|
|
606
|
+
return ((tt = ut.functionDetails) == null ? void 0 : tt.id) === y;
|
|
607
|
+
}), I = v > -1 ? c[v] : M, N = {
|
|
608
|
+
...I,
|
|
609
|
+
eventType: i.eventType,
|
|
610
|
+
functionDetails: {
|
|
611
|
+
id: I.functionDetails.id,
|
|
612
|
+
name: i.functionDetails.name ?? I.functionDetails.name,
|
|
613
|
+
// Take the parsed args from the incoming event when
|
|
614
|
+
// present (the full FunctionCall carries them), fall
|
|
615
|
+
// back to what was already on the part. Previously
|
|
616
|
+
// this was `current.functionDetails!.args`
|
|
617
|
+
// unconditionally, which silently dropped the parsed
|
|
618
|
+
// args off every full FunctionCall fold because the
|
|
619
|
+
// PartialFunctionCall stream only accumulates raw
|
|
620
|
+
// JSON in `.text` — `.args` stayed undefined.
|
|
621
|
+
args: i.functionDetails.args ?? I.functionDetails.args,
|
|
622
|
+
response: i.functionDetails.response,
|
|
623
|
+
status: i.functionDetails.status ?? "Composing",
|
|
624
|
+
start: i.functionDetails.start ?? I.functionDetails.start,
|
|
625
|
+
end: i.functionDetails.end ?? I.functionDetails.end,
|
|
626
|
+
// true-wins: a UI call has multiple reps (streaming part with isUi, the
|
|
627
|
+
// persisted FunctionCall, the result) and they interleave. `??` let a later
|
|
628
|
+
// `false`/`undefined` rep clobber an earlier `true`; OR-ing keeps it sticky.
|
|
629
|
+
isUi: i.functionDetails.isUi === !0 || I.functionDetails.isUi === !0,
|
|
630
|
+
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
631
|
+
argsDescription: i.functionDetails.argsDescription ?? I.functionDetails.argsDescription,
|
|
632
|
+
// The tool's client-only payload rides the RESULT event; keep it sticky so a
|
|
633
|
+
// later rep without one can't clobber it. This is what a uiTool renderer reads.
|
|
634
|
+
clientOutput: i.functionDetails.clientOutput ?? I.functionDetails.clientOutput
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
h(), u.set(y, N), N.eventType === T.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(N.functionDetails), s.push(N), v > -1 && (C(), c[v] = N);
|
|
638
|
+
} else {
|
|
639
|
+
if (y && i.functionDetails && !M && (h(), u.set(y, i)), r && r.textAppendable) {
|
|
640
|
+
const I = {
|
|
641
|
+
...r,
|
|
642
|
+
ended: /* @__PURE__ */ new Date(),
|
|
643
|
+
isStillWriting: !1
|
|
644
|
+
};
|
|
645
|
+
C(), c[c.length - 1] = I, s.push(I);
|
|
646
|
+
}
|
|
647
|
+
const v = {
|
|
648
|
+
...i,
|
|
649
|
+
id: c.length + 1 + "-" + e.interactionId,
|
|
650
|
+
isStillWriting: i.textAppendable,
|
|
651
|
+
partial: t.partial
|
|
652
|
+
};
|
|
653
|
+
(V = v.functionDetails) != null && V.silent || s.push(v), c = [...c, v], m = !0;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
let f = c[c.length - 1] ?? null;
|
|
657
|
+
if (f && i && i.textAppendable) {
|
|
658
|
+
const p = {
|
|
659
|
+
...f,
|
|
660
|
+
partial: t.partial,
|
|
661
|
+
textDetails: f.textDetails ? { ...f.textDetails } : { version: 0 }
|
|
662
|
+
};
|
|
663
|
+
let y = !1;
|
|
664
|
+
if (t.partial) {
|
|
665
|
+
try {
|
|
666
|
+
p.textDetails.version++, m || (p.text = (f.text ?? "") + (i.text ?? ""));
|
|
667
|
+
} catch (M) {
|
|
668
|
+
console.error("Error here", M.toString());
|
|
669
|
+
}
|
|
670
|
+
p.textLastChunk = i.text ?? "", p.isStillWriting = !0, y = !0, i.thoughtDetails && p.thoughtDetails && i.thoughtDetails.text !== p.thoughtDetails.text && (p.thoughtDetails = {
|
|
671
|
+
...p.thoughtDetails,
|
|
672
|
+
text: p.thoughtDetails.text + i.thoughtDetails.text
|
|
673
|
+
}, p.thoughtLastChunk = i.thoughtDetails.text);
|
|
674
|
+
} else
|
|
675
|
+
p.isStillWriting = !1, p.text = i.text ?? "", p.textDetails.version++, i.thoughtDetails && (p.thoughtDetails = {
|
|
676
|
+
...i.thoughtDetails,
|
|
677
|
+
text: i.thoughtDetails.text.trim()
|
|
678
|
+
}), y = !l;
|
|
679
|
+
C(), c[c.length - 1] = p, f = p, y && s.push(p);
|
|
680
|
+
}
|
|
681
|
+
let w = e.artifactData ?? [];
|
|
682
|
+
if (t.llmArtifacts && t.llmArtifacts.length > 0) {
|
|
683
|
+
let p = !1;
|
|
684
|
+
for (const y of t.llmArtifacts) {
|
|
685
|
+
const M = y.toArtifact();
|
|
686
|
+
p || (w = w.slice(), p = !0);
|
|
687
|
+
const v = w.findIndex((I) => I.id === M.id);
|
|
688
|
+
v === -1 ? w.push(M) : w[v] = M;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
const O = {
|
|
692
|
+
...e,
|
|
693
|
+
version: e.version + 1,
|
|
694
|
+
parts: c,
|
|
695
|
+
artifactData: w,
|
|
696
|
+
functionMap: u,
|
|
697
|
+
turn_complete: t.turn_complete,
|
|
698
|
+
partial: t.partial,
|
|
699
|
+
asyncFinalResponse: t.asyncFinalResponse
|
|
700
|
+
};
|
|
701
|
+
return this.interaction = O, {
|
|
702
|
+
updatedInteraction: O,
|
|
703
|
+
updatedParts: s,
|
|
704
|
+
newArtifacts: n,
|
|
705
|
+
mainBranch: O,
|
|
706
|
+
analyticsBranch: null,
|
|
707
|
+
analyticsBranchPartsChanged: null,
|
|
708
|
+
mainBranchPartsChanged: s
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
g(K, "InteractionService");
|
|
713
|
+
let b = K;
|
|
714
|
+
const Nt = 1200 * 1e3, D = class D {
|
|
715
|
+
constructor(t, e, s, n, i, r, l, c, u, d = mt.Interactive) {
|
|
716
|
+
a(this, "base_production_url", ft() ?? "https://agent.tripapi.com.br");
|
|
717
|
+
a(this, "base_url_local", "http://localagent:8000");
|
|
718
|
+
a(this, "base_url");
|
|
719
|
+
a(this, "isLocal", !1);
|
|
720
|
+
a(this, "msg_order", 0);
|
|
721
|
+
a(this, "lastPing", /* @__PURE__ */ new Date());
|
|
722
|
+
a(this, "interactionsMap", /* @__PURE__ */ new Map());
|
|
723
|
+
a(this, "interactionsServiceMap", /* @__PURE__ */ new Map());
|
|
724
|
+
a(this, "user");
|
|
725
|
+
a(this, "config");
|
|
726
|
+
a(this, "currentIS", null);
|
|
727
|
+
a(this, "server_session_id");
|
|
728
|
+
a(this, "model_session_id");
|
|
729
|
+
a(this, "runMode");
|
|
730
|
+
a(this, "sessionState");
|
|
731
|
+
a(this, "storageService");
|
|
732
|
+
a(this, "notificationPort");
|
|
733
|
+
a(this, "interactionCallIds", /* @__PURE__ */ new Map());
|
|
734
|
+
a(this, "rawJwt");
|
|
735
|
+
a(this, "sessionId");
|
|
736
|
+
a(this, "isInited", !1);
|
|
737
|
+
//Define all SSEServer methods here, use from SSEServer.ts
|
|
738
|
+
a(this, "eventBusService");
|
|
739
|
+
a(this, "artifactService");
|
|
740
|
+
a(this, "onTurnOpen", /* @__PURE__ */ g((t) => {
|
|
741
|
+
this.eventBusService.gatewayOnTurnOpen(t);
|
|
742
|
+
}, "onTurnOpen"));
|
|
743
|
+
a(this, "offTurnOpen", /* @__PURE__ */ g((t) => {
|
|
744
|
+
this.eventBusService.gatewayOffTurnOpen(t);
|
|
745
|
+
}, "offTurnOpen"));
|
|
746
|
+
a(this, "onTurnComplete", /* @__PURE__ */ g((t) => {
|
|
747
|
+
this.eventBusService.gatewayOnTurnComplete(t);
|
|
748
|
+
}, "onTurnComplete"));
|
|
749
|
+
a(this, "offTurnComplete", /* @__PURE__ */ g((t) => {
|
|
750
|
+
this.eventBusService.gatewayOffTurnComplete(t);
|
|
751
|
+
}, "offTurnComplete"));
|
|
752
|
+
a(this, "onStreamError", /* @__PURE__ */ g((t) => {
|
|
753
|
+
this.eventBusService.gatewayOnStreamError(t);
|
|
754
|
+
}, "onStreamError"));
|
|
755
|
+
a(this, "offStreamError", /* @__PURE__ */ g((t) => {
|
|
756
|
+
this.eventBusService.gatewayOffStreamError(t);
|
|
757
|
+
}, "offStreamError"));
|
|
758
|
+
a(this, "onStreamEnded", /* @__PURE__ */ g((t) => {
|
|
759
|
+
this.eventBusService.gatewayOnStreamEnded(t);
|
|
760
|
+
}, "onStreamEnded"));
|
|
761
|
+
a(this, "offStreamEnded", /* @__PURE__ */ g((t) => {
|
|
762
|
+
this.eventBusService.gatewayOffStreamEnded(t);
|
|
763
|
+
}, "offStreamEnded"));
|
|
764
|
+
a(this, "onMessage", /* @__PURE__ */ g((t) => {
|
|
765
|
+
this.eventBusService.gatewayOnMessage(t);
|
|
766
|
+
}, "onMessage"));
|
|
767
|
+
a(this, "offMessage", /* @__PURE__ */ g((t) => {
|
|
768
|
+
this.eventBusService.gatewayOffMessage(t);
|
|
769
|
+
}, "offMessage"));
|
|
770
|
+
a(this, "onFirstToken", /* @__PURE__ */ g((t) => {
|
|
771
|
+
this.eventBusService.gatewayOnFirstToken(t);
|
|
772
|
+
}, "onFirstToken"));
|
|
773
|
+
a(this, "offFirstToken", /* @__PURE__ */ g((t) => {
|
|
774
|
+
this.eventBusService.gatewayOffFirstToken(t);
|
|
775
|
+
}, "offFirstToken"));
|
|
776
|
+
a(this, "onFunctionResponse", /* @__PURE__ */ g((t) => {
|
|
777
|
+
this.eventBusService.gatewayOnFunctionResponse(t);
|
|
778
|
+
}, "onFunctionResponse"));
|
|
779
|
+
a(this, "offFunctionResponse", /* @__PURE__ */ g((t) => {
|
|
780
|
+
this.eventBusService.gatewayOffFunctionResponse(t);
|
|
781
|
+
}, "offFunctionResponse"));
|
|
782
|
+
a(this, "toolSessionId", null);
|
|
783
|
+
a(this, "pendingCurrentMessage", null);
|
|
784
|
+
a(this, "lastCurrentMessageUpdate", 0);
|
|
785
|
+
a(this, "runningRequests", /* @__PURE__ */ new Map());
|
|
786
|
+
a(this, "lastToolInteraction", "");
|
|
787
|
+
a(this, "subAgentInteractions", /* @__PURE__ */ new Map());
|
|
788
|
+
a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
|
|
789
|
+
a(this, "lastThorttledTimeout", null);
|
|
790
|
+
a(this, "lastPingStatus", !1);
|
|
791
|
+
this.user = t, this.config = i, this.rawJwt = t.access_token, this.base_url = n, this.eventBusService = e, this.sessionId = u, this.runMode = d, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = c, r.subscribe((h, C) => {
|
|
792
|
+
this.sessionState = h;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
onEndMessageData(t) {
|
|
796
|
+
this.eventBusService.gatewayOnEndMessageData(t);
|
|
797
|
+
}
|
|
798
|
+
offEndMessageData(t) {
|
|
799
|
+
this.eventBusService.gatewayOffEndMessageData(t);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Send the user's answer to a parked `ask_user` tool call back to the agent.
|
|
803
|
+
* Default no-op; the WebSocket gateway (AgentGatewayWSAsync) overrides it to emit
|
|
804
|
+
* a ChatAction.AnswerHumanTool frame.
|
|
805
|
+
*/
|
|
806
|
+
answerHumanTool(t, e) {
|
|
807
|
+
console.warn("answerHumanTool: not supported by this gateway", t, e);
|
|
808
|
+
}
|
|
809
|
+
getAgentContext() {
|
|
810
|
+
return this.config;
|
|
811
|
+
}
|
|
812
|
+
getModel() {
|
|
813
|
+
return this.config.model;
|
|
814
|
+
}
|
|
815
|
+
setModel(t) {
|
|
816
|
+
this.config = { ...this.config, model: t };
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Live update for the agent / customer slice of the gateway's
|
|
820
|
+
* config. Mirrors {@link setModel}'s in-place pattern so the
|
|
821
|
+
* next outgoing message — `sendMessageInternal` reads
|
|
822
|
+
* `this.config.agentConfig?.id` directly at send time, see
|
|
823
|
+
* `AgentGatewayWSAsync.sendMessageInternal` — picks up the new
|
|
824
|
+
* id without rebuilding the gateway or tearing down the
|
|
825
|
+
* WebSocket. This is what the host calls from the agent picker
|
|
826
|
+
* so switching agents preserves the current session's
|
|
827
|
+
* connection, chat history, and any in-flight stream state
|
|
828
|
+
* instead of remounting `AiChatProvider` and losing them.
|
|
829
|
+
*
|
|
830
|
+
* Callers should pass the FULL replacement context (the same
|
|
831
|
+
* shape they originally constructed the gateway with). The
|
|
832
|
+
* gateway preserves the `model` slice from its current config
|
|
833
|
+
* if the incoming context omits it — the model is owned
|
|
834
|
+
* separately by `setModel` and shouldn't get clobbered by an
|
|
835
|
+
* agent-only change.
|
|
836
|
+
*/
|
|
837
|
+
setAgentContext(t) {
|
|
838
|
+
this.config = {
|
|
839
|
+
...t,
|
|
840
|
+
model: t.model ?? this.config.model
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
getSessionId() {
|
|
844
|
+
return this.sessionId;
|
|
845
|
+
}
|
|
846
|
+
getErrorEvent(t) {
|
|
847
|
+
return {
|
|
848
|
+
interaction_id: this.getCurrentInteractionId(),
|
|
849
|
+
model_session_id: "",
|
|
850
|
+
mime_type: "text/plain",
|
|
851
|
+
partial: !1,
|
|
852
|
+
serverError: t
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
setSession(t, e) {
|
|
856
|
+
(this.sessionId === void 0 || this.sessionId != t) && (this.sessionId = t, this.msg_order = this.sessionState.messages.length), e && (this.toolSessionId = e);
|
|
857
|
+
}
|
|
858
|
+
startInteraction(t, e, s) {
|
|
859
|
+
if (e && this.currentIS)
|
|
860
|
+
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
|
|
861
|
+
this.msg_order += 1;
|
|
862
|
+
let n = this.getNewInteractionId();
|
|
863
|
+
s && (n = s);
|
|
864
|
+
let i = {
|
|
865
|
+
created: /* @__PURE__ */ new Date(),
|
|
866
|
+
interactionId: n,
|
|
867
|
+
artifactData: [],
|
|
868
|
+
partial: !0,
|
|
869
|
+
sessionId: this.sessionId,
|
|
870
|
+
turn_complete: !1,
|
|
871
|
+
parts: [],
|
|
872
|
+
version: 0,
|
|
873
|
+
functionMap: /* @__PURE__ */ new Map(),
|
|
874
|
+
interactionQuestion: t
|
|
875
|
+
};
|
|
876
|
+
return this.interactionsMap.set(i.interactionId, i), this.currentIS = new b(i, this.eventBusService), this.interactionsServiceMap.set(i.interactionId, this.currentIS), i;
|
|
877
|
+
}
|
|
878
|
+
getInteractions() {
|
|
879
|
+
return Array.from(this.interactionsMap.values());
|
|
880
|
+
}
|
|
881
|
+
getRecentInteractions(t = 1e3 * 60) {
|
|
882
|
+
return Array.from(this.interactionsMap.values()).filter((e) => e.created.getTime() > Date.now() - t);
|
|
883
|
+
}
|
|
884
|
+
updateMap(t) {
|
|
885
|
+
let e = this.interactionsServiceMap.get(t.interactionId);
|
|
886
|
+
if (!e) {
|
|
887
|
+
var s = this.startInteraction("Unknown", !1, t.interactionId);
|
|
888
|
+
e = this.interactionsServiceMap.get(s.interactionId);
|
|
889
|
+
}
|
|
890
|
+
return e.merge(t);
|
|
891
|
+
}
|
|
892
|
+
getCurrentInteractionId() {
|
|
893
|
+
return this.currentIS ? this.currentIS.interaction.interactionId : null;
|
|
894
|
+
}
|
|
895
|
+
getCurrentInteraction() {
|
|
896
|
+
var t;
|
|
897
|
+
return ((t = this.currentIS) == null ? void 0 : t.interaction) ?? null;
|
|
898
|
+
}
|
|
899
|
+
getInteraction(t) {
|
|
900
|
+
return this.interactionsMap.get(t);
|
|
901
|
+
}
|
|
902
|
+
hasState() {
|
|
903
|
+
return this.interactionsMap.size > 0;
|
|
904
|
+
}
|
|
905
|
+
buildAgentParams() {
|
|
906
|
+
let t = `agent=${encodeURIComponent(this.config.agentConfig.name ?? "unset")}`;
|
|
907
|
+
return this.config.customer && (t += `&customer_id=${encodeURIComponent(this.config.customer.dataSetId)}`, t += `&customer_name=${encodeURIComponent(this.config.customer.name)}`), t;
|
|
908
|
+
}
|
|
909
|
+
openConnection(t) {
|
|
910
|
+
throw "Not implemented";
|
|
911
|
+
}
|
|
912
|
+
async Error(t = void 0) {
|
|
913
|
+
console.error("Stream error: ", t), await this.eventBusService.gatewayEmitStreamError(t ?? "");
|
|
914
|
+
}
|
|
915
|
+
hasServerSessionId() {
|
|
916
|
+
return this.server_session_id != null && this.server_session_id != null;
|
|
917
|
+
}
|
|
918
|
+
async asyncLoadArtifact(t) {
|
|
919
|
+
let e = null;
|
|
920
|
+
const s = this.runningRequests.get(t);
|
|
921
|
+
s ? (console.warn("GOT A running promise", t), e = s) : (e = this.artifactService.getArtifact(t), this.runningRequests.set(t, e));
|
|
922
|
+
try {
|
|
923
|
+
return await e;
|
|
924
|
+
} catch (n) {
|
|
925
|
+
return console.error("Error awating on HTML promise", n.toString()), null;
|
|
926
|
+
} finally {
|
|
927
|
+
this.runningRequests.delete(t);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
processComands(t) {
|
|
931
|
+
switch (t.command) {
|
|
932
|
+
case "open_turn":
|
|
933
|
+
console.warn("[Stack:] author:", t.author), this.localOpen(t.interactionId, t.author);
|
|
934
|
+
break;
|
|
935
|
+
case "ignore":
|
|
936
|
+
return !0;
|
|
937
|
+
}
|
|
938
|
+
return !1;
|
|
939
|
+
}
|
|
940
|
+
getOrCreateSubAgentInteraction(t, e, s) {
|
|
941
|
+
let n = this.subAgentInteractions.get(t), i = this.subAgentInteractionServices.get(t);
|
|
942
|
+
return (!n || !i) && (n = {
|
|
943
|
+
created: /* @__PURE__ */ new Date(),
|
|
944
|
+
interactionId: e,
|
|
945
|
+
artifactData: [],
|
|
946
|
+
partial: !0,
|
|
947
|
+
turn_complete: !1,
|
|
948
|
+
parts: [],
|
|
949
|
+
version: 0,
|
|
950
|
+
functionMap: /* @__PURE__ */ new Map(),
|
|
951
|
+
interactionQuestion: s ?? t
|
|
952
|
+
}, i = new b(n, this.eventBusService), this.subAgentInteractions.set(t, n), this.subAgentInteractionServices.set(t, i)), { interaction: n, service: i };
|
|
953
|
+
}
|
|
954
|
+
handleSubAgentEvent(t) {
|
|
955
|
+
const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
|
|
956
|
+
if (t.parts && t.parts.length > 0) {
|
|
957
|
+
for (const r of t.parts)
|
|
958
|
+
if (r.toolDetails) {
|
|
959
|
+
this.localEmitToolEvent({ ...r.toolDetails, subAgentId: e });
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
const n = s.merge(t);
|
|
964
|
+
if (!n) return;
|
|
965
|
+
const i = t.turn_complete ?? !1;
|
|
966
|
+
this.sessionState.setSubAgentMessage(e, n.updatedInteraction, t.subAgentName), i && this.sessionState.completeSubAgent(e);
|
|
967
|
+
}
|
|
968
|
+
async Message(t) {
|
|
969
|
+
try {
|
|
970
|
+
let e;
|
|
971
|
+
if (typeof t == "object" && Object.keys(t).includes("mimeType"))
|
|
972
|
+
e = t;
|
|
973
|
+
else {
|
|
974
|
+
console.error("Uknown message type", t);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
if (e.subAgentId) {
|
|
978
|
+
this.handleSubAgentEvent(e);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
if (e.serverError && console.error("Stream error: ", e.serverError), e.endMessageData && this.eventBusService.gatewayEmitEndMessageData(e.endMessageData), e) {
|
|
982
|
+
if (e.llmArtifacts && e.llmArtifacts.length > 0)
|
|
983
|
+
for (const i of e.llmArtifacts) {
|
|
984
|
+
const r = i.toArtifact();
|
|
985
|
+
this.artifactService.addToCache(r), this.eventBusService.artifactEmitGenerated(r);
|
|
986
|
+
}
|
|
987
|
+
if (e.parts && e.parts.length > 0) {
|
|
988
|
+
for (const i of e.parts)
|
|
989
|
+
if (i.toolDetails) {
|
|
990
|
+
this.localEmitToolEvent(i.toolDetails);
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
const s = this.updateMap(e);
|
|
995
|
+
if (!s) {
|
|
996
|
+
console.warn({
|
|
997
|
+
message: "No updated interaction",
|
|
998
|
+
type: "warning"
|
|
999
|
+
}), console.error("No updated interaction");
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
this.localEmitMessage(s.updatedInteraction, s), e.turn_complete && this.turnComplete(e.interactionId, s.updatedInteraction, e.author, e.subAgentId), e.asyncFinalResponse && (e.turn_complete = !0, s.updatedInteraction.turn_complete == !0, this.finalResponse(e.interactionId, s.updatedInteraction, e.author, e.subAgentId));
|
|
1003
|
+
const n = e.artifactsDelta;
|
|
1004
|
+
n && n.forEach((i) => {
|
|
1005
|
+
const r = s.updatedInteraction.artifactData.filter((c) => c.id == i);
|
|
1006
|
+
let l = null;
|
|
1007
|
+
r && r.length > 0 && (l = r[0], l.loadingPromise = this.asyncLoadArtifact(i).then((c) => (c === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(c), c)).catch((c) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, c.toString()), null)));
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
} catch (e) {
|
|
1011
|
+
if (this.getCurrentInteractionId()) {
|
|
1012
|
+
const s = lt.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
|
|
1013
|
+
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
|
|
1014
|
+
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
this.localEmitMessage(n.updatedInteraction);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
hasOneCompleteInteraction() {
|
|
1022
|
+
var t;
|
|
1023
|
+
return this.interactionsMap.size > 0 && ((t = this.interactionsMap.values().next().value) == null ? void 0 : t.turn_complete) === !0;
|
|
1024
|
+
}
|
|
1025
|
+
localEmitToolEvent(t) {
|
|
1026
|
+
this.sessionState.setLastToolEvent(t), this.eventBusService.gatewayEmitToolEvent(t.eventName, t.eventData, t.sessionId);
|
|
1027
|
+
}
|
|
1028
|
+
registerInteractionCallId(t, e) {
|
|
1029
|
+
e != null && e.callId && this.interactionCallIds.set(t, e.callId);
|
|
1030
|
+
}
|
|
1031
|
+
localEmitFirstToken(t) {
|
|
1032
|
+
this.eventBusService.gatewayEmitFirstToken({
|
|
1033
|
+
interactionId: t,
|
|
1034
|
+
callId: this.interactionCallIds.get(t)
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
doEmitMessage(t, e, s) {
|
|
1038
|
+
this.sessionState.setCurrentMessage(t), this.lastCurrentMessageUpdate = e, this.pendingCurrentMessage = null, this.eventBusService.gatewayEmitMessage(t, s);
|
|
1039
|
+
}
|
|
1040
|
+
localEmitMessage(t, e) {
|
|
1041
|
+
const s = (/* @__PURE__ */ new Date()).getTime(), n = s - this.lastCurrentMessageUpdate;
|
|
1042
|
+
t.partial === !1 || n >= D.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
|
|
1043
|
+
var r, l;
|
|
1044
|
+
this.pendingCurrentMessage && (((r = this.pendingCurrentMessage) == null ? void 0 : r.version) ?? 0) > (((l = this.sessionState.currentMessage) == null ? void 0 : l.version) ?? 0) && (this.doEmitMessage(this.pendingCurrentMessage, s, e), this.lastThorttledTimeout = null);
|
|
1045
|
+
}, D.CURRENT_MSG_THROTTLE_MS * 2));
|
|
1046
|
+
}
|
|
1047
|
+
localOpen(t, e) {
|
|
1048
|
+
this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Drop any throttled `currentMessage` emit still queued by
|
|
1052
|
+
* `localEmitMessage`. The throttle's trailing edge is a `setTimeout` that
|
|
1053
|
+
* calls `setCurrentMessage(...)`; if it fires *after* the turn has been
|
|
1054
|
+
* committed (`setNewMessage` moved the interaction into `messages` and
|
|
1055
|
+
* nulled `currentMessage`), it re-publishes the now-committed interaction
|
|
1056
|
+
* as the live message — so the chat renders the turn twice: once in
|
|
1057
|
+
* history (`MessageAgent` with `onGoing=false`, which drops Thought parts)
|
|
1058
|
+
* and once as the live `currentMessage` (`onGoing=true`, which keeps them).
|
|
1059
|
+
* That is the duplicated-bubble bug (the two copies even look different —
|
|
1060
|
+
* only the live one shows the "thought" strip). Call this on turn commit.
|
|
1061
|
+
*/
|
|
1062
|
+
cancelPendingCurrentMessage() {
|
|
1063
|
+
this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.pendingCurrentMessage = null;
|
|
1064
|
+
}
|
|
1065
|
+
async turnComplete(t, e, s, n) {
|
|
1066
|
+
this.cancelPendingCurrentMessage(), this.sessionState.setNewMessage(e), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
|
|
1067
|
+
eventName: "todolistUpdated",
|
|
1068
|
+
eventData: "",
|
|
1069
|
+
subAgentId: n
|
|
1070
|
+
}), this.sessionState.setTurnOpen(!1);
|
|
1071
|
+
}
|
|
1072
|
+
async handlePing() {
|
|
1073
|
+
return Date.now() - this.lastPing.getTime() > Nt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
|
|
1074
|
+
}
|
|
1075
|
+
async sendMessage(t, e) {
|
|
1076
|
+
let s = this.getInteractions().length, n = A.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1077
|
+
this.sendStatusMessage(t.data, [n], s.toString() + "1");
|
|
1078
|
+
try {
|
|
1079
|
+
const { promptAsString: i, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1080
|
+
this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = i);
|
|
1081
|
+
const l = await this.sendMessageInternal(t, e), c = At.createPrompt(i ?? "", (r == null ? void 0 : r.toString()) ?? {});
|
|
1082
|
+
this.storageService.storePrompt(c);
|
|
1083
|
+
const u = A.fromText("Planejando próximos passos");
|
|
1084
|
+
return this.sendStatusMessage(t.data, [n, u], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
|
|
1085
|
+
} catch (i) {
|
|
1086
|
+
return this.eventBusService.ChatEmitMessageError((i == null ? void 0 : i.toString()) ?? ""), {
|
|
1087
|
+
success: !1,
|
|
1088
|
+
interaction: {
|
|
1089
|
+
artifactData: [],
|
|
1090
|
+
created: /* @__PURE__ */ new Date(),
|
|
1091
|
+
interactionId: "",
|
|
1092
|
+
partial: !1,
|
|
1093
|
+
parts: [A.fromError((i == null ? void 0 : i.toString()) ?? "")],
|
|
1094
|
+
version: 0
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
} finally {
|
|
1098
|
+
this.clearStatus();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async check() {
|
|
1102
|
+
return !0;
|
|
1103
|
+
}
|
|
1104
|
+
startAndForget() {
|
|
1105
|
+
}
|
|
1106
|
+
forceReceiveMessage(t) {
|
|
1107
|
+
t.partial = !0, t.turn_complete = !1, t.asyncFinalResponse = !1, t.interactionId = t.interactionId, this.eventBusService.gatewayEmitTurnOpen(t.interactionId), this.Message(t);
|
|
1108
|
+
}
|
|
1109
|
+
sendStatusMessage(t, e, s) {
|
|
1110
|
+
var i, r;
|
|
1111
|
+
let n;
|
|
1112
|
+
((r = (i = this.currentIS) == null ? void 0 : i.interaction) == null ? void 0 : r.turn_complete) === !1 ? (n = Dt.cloneDeep(this.currentIS.interaction), n.parts.push(...e)) : n = {
|
|
1113
|
+
interactionId: "tmp" + s,
|
|
1114
|
+
created: /* @__PURE__ */ new Date(),
|
|
1115
|
+
partial: !0,
|
|
1116
|
+
turn_complete: !1,
|
|
1117
|
+
version: 0,
|
|
1118
|
+
parts: e,
|
|
1119
|
+
interactionQuestion: t,
|
|
1120
|
+
artifactData: []
|
|
1121
|
+
}, this.localEmitMessage(n);
|
|
1122
|
+
}
|
|
1123
|
+
clearStatus() {
|
|
1124
|
+
}
|
|
1125
|
+
async ping() {
|
|
1126
|
+
var t;
|
|
1127
|
+
try {
|
|
1128
|
+
const e = await fetch(this.base_url + "/ping"), s = await e.json();
|
|
1129
|
+
return e.ok == !0 && ((t = s == null ? void 0 : s.debug) == null ? void 0 : t.id) != null;
|
|
1130
|
+
} catch (e) {
|
|
1131
|
+
return console.error("Error pinging server", e), !1;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
getNewInteractionId() {
|
|
1135
|
+
const e = Ot(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
1136
|
+
return `${this.msg_order}_${e}`;
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
g(D, "AgentGatewayService"), a(D, "SUSPENSION_MSG", "SUSPEND"), a(D, "CURRENT_MSG_THROTTLE_MS", 20);
|
|
1140
|
+
let B = D;
|
|
1141
|
+
const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2, at = 2, z = class z {
|
|
1142
|
+
constructor(t = "ws://localhost:8000", e) {
|
|
1143
|
+
a(this, "ws", null);
|
|
1144
|
+
a(this, "stats");
|
|
1145
|
+
a(this, "baseUrl");
|
|
1146
|
+
/**
|
|
1147
|
+
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
1148
|
+
* so that a refreshed token is picked up automatically. Browsers can't set the Authorization
|
|
1149
|
+
* header on the WebSocket handshake, so we pass the JWT via the ?access_token= query string,
|
|
1150
|
+
* which the .NET JwtBearer events handler reads in Program.cs.
|
|
1151
|
+
*/
|
|
1152
|
+
a(this, "getToken");
|
|
1153
|
+
a(this, "onEvent");
|
|
1154
|
+
a(this, "onError");
|
|
1155
|
+
a(this, "onOpen");
|
|
1156
|
+
a(this, "onFirstToken");
|
|
1157
|
+
a(this, "onSuspended");
|
|
1158
|
+
a(this, "onPong");
|
|
1159
|
+
a(this, "onClose");
|
|
1160
|
+
/** Fired when an unexpected close triggers a reconnect attempt. */
|
|
1161
|
+
a(this, "onReconnecting");
|
|
1162
|
+
/** Fired the first time the socket reopens after an unexpected close. */
|
|
1163
|
+
a(this, "onReconnected");
|
|
1164
|
+
/**
|
|
1165
|
+
* Fired when the server signals that we lost streaming events on resume — our
|
|
1166
|
+
* `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
|
|
1167
|
+
* reset partial-streaming UI for this session and rely on persisted history.
|
|
1168
|
+
*/
|
|
1169
|
+
a(this, "onRewindLost");
|
|
1170
|
+
a(this, "sessionId");
|
|
1171
|
+
a(this, "onNewPacket");
|
|
1172
|
+
/**
|
|
1173
|
+
* Stats can fire dozens of times per second during streaming. We
|
|
1174
|
+
* coalesce to a fixed cadence so subscribers see steady,
|
|
1175
|
+
* digestible updates instead of a per-packet firehose — the
|
|
1176
|
+
* latter caused a "Maximum update depth exceeded" cascade in
|
|
1177
|
+
* heavy v2 surfaces (RunProgressPanelV2 + StreamStatistics +
|
|
1178
|
+
* ChatTranscript all subscribed to `statistics` and re-rendered
|
|
1179
|
+
* on every packet, with their useEffect-driven setStates pushing
|
|
1180
|
+
* React's nested-update counter past its threshold).
|
|
1181
|
+
*/
|
|
1182
|
+
a(this, "statsFlushTimer", null);
|
|
1183
|
+
a(this, "statsLastFlushed", 0);
|
|
1184
|
+
a(this, "STATS_FLUSH_MS", 120);
|
|
1185
|
+
a(this, "monitorInterval", null);
|
|
1186
|
+
a(this, "streamingResponseSerializer");
|
|
1187
|
+
a(this, "events");
|
|
1188
|
+
a(this, "lastActivity");
|
|
1189
|
+
a(this, "pingPongStack");
|
|
1190
|
+
a(this, "firstTokenInteractions");
|
|
1191
|
+
/** Last sessionId we successfully had — used to resume on reconnect. */
|
|
1192
|
+
a(this, "lastKnownSessionId");
|
|
1193
|
+
/** True when the consumer called `disconnect()` — suppresses auto-reconnect. */
|
|
1194
|
+
a(this, "intentionalDisconnect", !1);
|
|
1195
|
+
/** Number of reconnect attempts since the last clean open. */
|
|
1196
|
+
a(this, "reconnectAttempts", 0);
|
|
1197
|
+
a(this, "reconnectTimer", null);
|
|
1198
|
+
/** True while we are in the middle of an unexpected-close → reconnect cycle. */
|
|
1199
|
+
a(this, "isReconnecting", !1);
|
|
1200
|
+
/** Internal flag set by `scheduleReconnect` so `connect()` does not reset the backoff state. */
|
|
1201
|
+
a(this, "_internalReconnect", !1);
|
|
1202
|
+
/**
|
|
1203
|
+
* Highest server-assigned `seq` we have observed and processed. The next
|
|
1204
|
+
* reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
|
|
1205
|
+
* we missed from the InteractionRun's in-memory buffer. -1 means "haven't
|
|
1206
|
+
* seen any sequenced events yet" (fresh connection).
|
|
1207
|
+
*/
|
|
1208
|
+
a(this, "lastSeq", -1);
|
|
1209
|
+
/**
|
|
1210
|
+
* True once *any* socket on this instance has received at least one packet.
|
|
1211
|
+
* Used by `onclose` to distinguish a real mid-stream drop (we had a working
|
|
1212
|
+
* channel) from a connect attempt that never produced traffic (server down,
|
|
1213
|
+
* unreachable, etc.). The inner reconnect loop is only meant for the former
|
|
1214
|
+
* — fresh-connect failures should be handed straight to the outer
|
|
1215
|
+
* SessionStateManagerService.processRetryLoop instead of being retried
|
|
1216
|
+
* twice in here. Sticky for the lifetime of this connection instance so
|
|
1217
|
+
* that internal resume attempts keep their full inner-loop budget even
|
|
1218
|
+
* when a replacement socket fails before delivering its first message.
|
|
1219
|
+
* Cleared by `disconnect()`.
|
|
1220
|
+
*/
|
|
1221
|
+
a(this, "hasEverReceivedPacket", !1);
|
|
1222
|
+
this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = St(), console.log("SOCKET INSTACE", pt()), this.stats = {
|
|
1223
|
+
eventCount: 0,
|
|
1224
|
+
unknonwCount: 0,
|
|
1225
|
+
buffer: [],
|
|
1226
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
1227
|
+
elapsed: 0,
|
|
1228
|
+
unparsedCount: 0,
|
|
1229
|
+
totalTransfered: 0,
|
|
1230
|
+
tokensPerSecond: 0
|
|
1231
|
+
}, this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Connect to the WebSocket endpoint
|
|
1235
|
+
*/
|
|
1236
|
+
connect(t) {
|
|
1237
|
+
return new Promise(async (e, s) => {
|
|
1238
|
+
var m;
|
|
1239
|
+
this.intentionalDisconnect = !1;
|
|
1240
|
+
const n = this._internalReconnect;
|
|
1241
|
+
n || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
|
|
1242
|
+
const i = (m = this.getToken) == null ? void 0 : m.call(this), r = [];
|
|
1243
|
+
i && r.push(`access_token=${encodeURIComponent(i)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
|
|
1244
|
+
const l = r.length > 0 ? `?${r.join("&")}` : "", c = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${c}/ws/connect/${t ?? ""}${l}`, d = `${c}/ws/connect/${t ?? ""}` + (n && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
|
|
1245
|
+
if (console.log("Connecting to ", d), this.ws) {
|
|
1246
|
+
this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
|
|
1247
|
+
try {
|
|
1248
|
+
this.ws.close();
|
|
1249
|
+
} catch {
|
|
1250
|
+
}
|
|
1251
|
+
this.ws = null;
|
|
1252
|
+
}
|
|
1253
|
+
this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${c}/ws/connect/${t ?? ""}`);
|
|
1254
|
+
let h = !1;
|
|
1255
|
+
this.ws.onopen = () => {
|
|
1256
|
+
console.log("[WebSocket] Connected");
|
|
1257
|
+
const f = this.isReconnecting;
|
|
1258
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), f && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? "");
|
|
1259
|
+
}, this.ws.onmessage = (f) => {
|
|
1260
|
+
try {
|
|
1261
|
+
this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1262
|
+
const w = this.streamingResponseSerializer.parse(f.data);
|
|
1263
|
+
if (!w)
|
|
1264
|
+
throw "Error parsing event JSON";
|
|
1265
|
+
const O = this.handleMessage(w, f.data);
|
|
1266
|
+
!h && (O != null && O.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
|
|
1267
|
+
} catch (w) {
|
|
1268
|
+
console.error("[WebSocket] Error parsing message:", w);
|
|
1269
|
+
}
|
|
1270
|
+
}, this.ws.onerror = (f) => {
|
|
1271
|
+
console.error("[WebSocket] Error:", f), this.onError && this.onError("WebSocket error");
|
|
1272
|
+
}, this.ws.onclose = (f) => {
|
|
1273
|
+
console.log("[WebSocket] Closed:", f.code, f.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
|
|
1274
|
+
const w = this.sessionId ?? this.lastKnownSessionId;
|
|
1275
|
+
if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(f.code)) {
|
|
1276
|
+
this.scheduleReconnect(w, f.code, f.reason);
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(f.code, f.reason);
|
|
1280
|
+
};
|
|
1281
|
+
let C = 0;
|
|
1282
|
+
for (this.sessionId = void 0; !this.sessionId && C < 30; )
|
|
1283
|
+
console.log("Aguardando session Id"), await this.sleep(400), C++;
|
|
1284
|
+
this.sessionId ? (console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId)) : s("After 3 seconds no session id was generated");
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Returns true when the close code is something we believe a fresh connect
|
|
1289
|
+
* (with the same sessionId) can recover from. We deliberately do NOT retry
|
|
1290
|
+
* on:
|
|
1291
|
+
* - 1000 normal closure
|
|
1292
|
+
* - 1008 policy violation (auth rejected)
|
|
1293
|
+
* - 4001 our own intentional disconnect
|
|
1294
|
+
* - 4000-4099 reserved for app-level fatal codes from the server
|
|
1295
|
+
*/
|
|
1296
|
+
shouldAttemptReconnect(t) {
|
|
1297
|
+
return !(this.intentionalDisconnect || t === $ || t === Pt || t === 1e3 || t === 1008);
|
|
1298
|
+
}
|
|
1299
|
+
cancelPendingReconnect() {
|
|
1300
|
+
this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
|
|
1301
|
+
}
|
|
1302
|
+
computeBackoffDelay() {
|
|
1303
|
+
const t = _t * Math.pow(Rt, this.reconnectAttempts), e = Math.min(t, Ft), s = e * bt * (Math.random() * 2 - 1);
|
|
1304
|
+
return Math.max(0, Math.round(e + s));
|
|
1305
|
+
}
|
|
1306
|
+
scheduleReconnect(t, e, s) {
|
|
1307
|
+
var i, r;
|
|
1308
|
+
if (this.intentionalDisconnect) return;
|
|
1309
|
+
if (this.reconnectAttempts >= at) {
|
|
1310
|
+
console.warn(
|
|
1311
|
+
`[WebSocket] Reconnect exhausted after ${this.reconnectAttempts} attempts (last code=${e}, reason="${s}"). Handing off to outer state manager.`
|
|
1312
|
+
), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (i = this.onClose) == null || i.call(this, e, s);
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
this.isReconnecting = !0, this.reconnectAttempts += 1;
|
|
1316
|
+
const n = this.computeBackoffDelay();
|
|
1317
|
+
console.warn(
|
|
1318
|
+
`[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${at} in ${n}ms (resume sessionId=${t ?? "none"}).`
|
|
1319
|
+
), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, n), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
|
|
1320
|
+
if (this.reconnectTimer = null, !this.intentionalDisconnect)
|
|
1321
|
+
try {
|
|
1322
|
+
this.ws && (this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null, this.ws = null), this._internalReconnect = !0, await this.connect(t);
|
|
1323
|
+
} catch (l) {
|
|
1324
|
+
console.error("[WebSocket] Reconnect attempt failed:", l);
|
|
1325
|
+
}
|
|
1326
|
+
}, n);
|
|
1327
|
+
}
|
|
1328
|
+
async sleep(t) {
|
|
1329
|
+
return new Promise((e) => setTimeout(e, t));
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Handle incoming messages from server
|
|
1333
|
+
*/
|
|
1334
|
+
handleMessage(t, e) {
|
|
1335
|
+
var l, c, u;
|
|
1336
|
+
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1337
|
+
case "Pong":
|
|
1338
|
+
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
1339
|
+
console.error("Pong response has no SESSION ID");
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
t.accessToken && this.persistRefreshedAccessToken(t.accessToken), this.pingPongStack.pop() || console.warn("Ping pong order broke, on Pong receive"), this.onPong && this.onPong(t.sessionId);
|
|
1343
|
+
break;
|
|
1344
|
+
case "Suspended":
|
|
1345
|
+
this.onSuspended && this.onSuspended();
|
|
1346
|
+
break;
|
|
1347
|
+
case "Event":
|
|
1348
|
+
break;
|
|
1349
|
+
case "RewindLost":
|
|
1350
|
+
console.warn(
|
|
1351
|
+
`[WebSocket] RewindLost: lost events on resume, resuming from seq=${t.seq}`
|
|
1352
|
+
), typeof t.seq == "number" && (this.lastSeq = t.seq - 1), this.onRewindLost && t.sessionId && this.onRewindLost(t.sessionId, t.seq ?? -1);
|
|
1353
|
+
break;
|
|
1354
|
+
default:
|
|
1355
|
+
console.warn("[WebSocket] Unknown message type:", t.type);
|
|
1356
|
+
}
|
|
1357
|
+
if (t.partialEvent) {
|
|
1358
|
+
const d = t.partialEvent;
|
|
1359
|
+
this.emitFirstToken(d == null ? void 0 : d.iteractionId);
|
|
1360
|
+
const h = new wt();
|
|
1361
|
+
if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
|
|
1362
|
+
fullName: F.StreamingFunctionCallUpdateContent,
|
|
1363
|
+
type: T.PartialFunctionCall
|
|
1364
|
+
} : d.partialReasoning ? {
|
|
1365
|
+
fullName: F.StreamingReasoningContent,
|
|
1366
|
+
type: T.Thought
|
|
1367
|
+
} : {
|
|
1368
|
+
fullName: F.StreamingTextContent,
|
|
1369
|
+
type: T.Text
|
|
1370
|
+
}, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == T.PartialFunctionCall) {
|
|
1371
|
+
var s = new Tt();
|
|
1372
|
+
s.choiceIndex = 0, s.callId = d.functionCallId, s.arguments = d.partialText, s.name = d.functionName, h.content = {
|
|
1373
|
+
items: [s],
|
|
1374
|
+
role: {
|
|
1375
|
+
label: "Assistant"
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
} else if (h.eventType.type == T.Text)
|
|
1379
|
+
if (h.eventType.fullName == F.StreamingTextContent) {
|
|
1380
|
+
var n = new yt();
|
|
1381
|
+
n.text = d.partialText, h.content = {
|
|
1382
|
+
items: [n],
|
|
1383
|
+
role: {
|
|
1384
|
+
label: "Assistant"
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
} else {
|
|
1388
|
+
var i = new It();
|
|
1389
|
+
i.text = d.partialText, h.content = {
|
|
1390
|
+
items: [i],
|
|
1391
|
+
role: {
|
|
1392
|
+
label: "Assistant"
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
else if (h.eventType.type == T.Thought) {
|
|
1397
|
+
var r = new Ct();
|
|
1398
|
+
r.text = d.partialReasoning, h.content = {
|
|
1399
|
+
items: [r],
|
|
1400
|
+
role: {
|
|
1401
|
+
label: "Assistant"
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
} else
|
|
1405
|
+
t.event = void 0;
|
|
1406
|
+
h.role = {
|
|
1407
|
+
label: "Assistant"
|
|
1408
|
+
}, h.timestamp = (d == null ? void 0 : d.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
|
|
1409
|
+
}
|
|
1410
|
+
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((c = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : c.length) ?? 0) > 0 || (((u = t.event.streamingParts) == null ? void 0 : u.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
|
|
1411
|
+
}
|
|
1412
|
+
emitFirstToken(t) {
|
|
1413
|
+
var e;
|
|
1414
|
+
!t || this.firstTokenInteractions.has(t) || (this.stats = {
|
|
1415
|
+
eventCount: 0,
|
|
1416
|
+
unknonwCount: 0,
|
|
1417
|
+
buffer: [],
|
|
1418
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
1419
|
+
elapsed: 0,
|
|
1420
|
+
unparsedCount: 0,
|
|
1421
|
+
totalTransfered: 0,
|
|
1422
|
+
tokensPerSecond: 0
|
|
1423
|
+
}, this.firstTokenInteractions.add(t), (e = this.onFirstToken) == null || e.call(this, t));
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Mirror a server-side-refreshed JWT into the stored user record so the global
|
|
1427
|
+
* fetch interceptor (packages/dashboard-app/.../EnvisionAuthProvider.tsx) picks
|
|
1428
|
+
* it up on the next HTTP call. Idempotent — the same token is delivered on
|
|
1429
|
+
* multiple consecutive Pong frames for listener-readiness, and we only write
|
|
1430
|
+
* when it actually changed.
|
|
1431
|
+
*
|
|
1432
|
+
* Uses the same localStorage key the auth provider reads (`envision_user`).
|
|
1433
|
+
* Done here in the WS layer rather than via a callback so consumers don't need
|
|
1434
|
+
* to wire up token-handling boilerplate; React contexts that hold the user in
|
|
1435
|
+
* memory will pick up the new token on the next refresh/render or via their
|
|
1436
|
+
* own storage listeners.
|
|
1437
|
+
*/
|
|
1438
|
+
persistRefreshedAccessToken(t) {
|
|
1439
|
+
const e = "envision_user";
|
|
1440
|
+
try {
|
|
1441
|
+
const s = localStorage.getItem(e);
|
|
1442
|
+
if (!s) {
|
|
1443
|
+
console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
const n = JSON.parse(s);
|
|
1447
|
+
if ((n == null ? void 0 : n.access_token) === t) return;
|
|
1448
|
+
n.access_token = t, localStorage.setItem(e, JSON.stringify(n)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
|
|
1449
|
+
} catch (s) {
|
|
1450
|
+
console.error("[WebSocket] Failed to persist WS-refreshed token", s);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
closeStream() {
|
|
1454
|
+
this.disconnect();
|
|
1455
|
+
}
|
|
1456
|
+
suspendStream() {
|
|
1457
|
+
this.sendBaseMessage({
|
|
1458
|
+
Action: L.Suspend,
|
|
1459
|
+
AgentId: "",
|
|
1460
|
+
InteractionId: "",
|
|
1461
|
+
ModelId: ""
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
/** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
|
|
1465
|
+
answerHumanTool(t, e) {
|
|
1466
|
+
this.sendBaseMessage({
|
|
1467
|
+
Action: L.AnswerHumanTool,
|
|
1468
|
+
AgentId: "",
|
|
1469
|
+
InteractionId: "",
|
|
1470
|
+
ToolCallId: t,
|
|
1471
|
+
Answer: e
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Send a message to the agent
|
|
1476
|
+
*/
|
|
1477
|
+
sendMessage(t) {
|
|
1478
|
+
this.sendBaseMessage(t);
|
|
1479
|
+
}
|
|
1480
|
+
sendBaseMessage(t) {
|
|
1481
|
+
if (this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), !this.ws || this.ws.readyState !== WebSocket.OPEN)
|
|
1482
|
+
throw new Error("WebSocket is not connected");
|
|
1483
|
+
this.ws.send(JSON.stringify(t));
|
|
1484
|
+
}
|
|
1485
|
+
sendSuspendMessage(t) {
|
|
1486
|
+
this.sendMessage(t);
|
|
1487
|
+
}
|
|
1488
|
+
monitor() {
|
|
1489
|
+
const t = this, e = this.pingPongStack, s = 3e4;
|
|
1490
|
+
this.monitorInterval = setInterval(() => {
|
|
1491
|
+
try {
|
|
1492
|
+
const n = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
|
|
1493
|
+
t.isConnected() && n >= s - 200 && (e.length > 0 && console.warn("Ping pong stack broke here, on pinging"), e.push((/* @__PURE__ */ new Date()).getTime()), t.ping());
|
|
1494
|
+
} catch (n) {
|
|
1495
|
+
console.error("Error on monitor", n);
|
|
1496
|
+
}
|
|
1497
|
+
}, s);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Send a heartbeat ping
|
|
1501
|
+
*/
|
|
1502
|
+
ping() {
|
|
1503
|
+
this.sendBaseMessage({
|
|
1504
|
+
Action: "Ping",
|
|
1505
|
+
AgentId: "",
|
|
1506
|
+
InteractionId: "",
|
|
1507
|
+
ModelId: ""
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Disconnect the WebSocket
|
|
1512
|
+
*/
|
|
1513
|
+
disconnect() {
|
|
1514
|
+
console.warn("Chamou DISCONNECT!!!"), this.intentionalDisconnect = !0, this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [], this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.hasEverReceivedPacket = !1, this.ws && (this.ws.close($, "Intentional disconnect"), this.ws = null);
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Check if connected
|
|
1518
|
+
*/
|
|
1519
|
+
isConnected() {
|
|
1520
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Push the latest stats out to `onNewPacket`, but at most every
|
|
1524
|
+
* `STATS_FLUSH_MS` ms. Subsequent packets within the window
|
|
1525
|
+
* schedule a trailing flush so the UI eventually sees the final
|
|
1526
|
+
* value without each individual packet causing a re-render.
|
|
1527
|
+
*/
|
|
1528
|
+
flushStatsCoalesced() {
|
|
1529
|
+
if (!this.onNewPacket) return;
|
|
1530
|
+
const t = Date.now(), e = t - this.statsLastFlushed;
|
|
1531
|
+
if (e >= this.STATS_FLUSH_MS) {
|
|
1532
|
+
this.statsFlushTimer && (clearTimeout(this.statsFlushTimer), this.statsFlushTimer = null), this.statsLastFlushed = t, this.onNewPacket({ ...this.stats });
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
this.statsFlushTimer || (this.statsFlushTimer = setTimeout(() => {
|
|
1536
|
+
var s;
|
|
1537
|
+
this.statsFlushTimer = null, this.statsLastFlushed = Date.now(), (s = this.onNewPacket) == null || s.call(this, { ...this.stats });
|
|
1538
|
+
}, this.STATS_FLUSH_MS - e));
|
|
1539
|
+
}
|
|
1540
|
+
async handleEvent(t, e) {
|
|
1541
|
+
var s;
|
|
1542
|
+
try {
|
|
1543
|
+
const n = lt.parseFromTypedEvent(t);
|
|
1544
|
+
if (!n)
|
|
1545
|
+
throw "Server event was null";
|
|
1546
|
+
this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, n.session_information && !n.subAgentId && (this.stats.sessionInformation = n.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
|
|
1547
|
+
const i = Date.now() - it * 1e3, l = this.events.filter((c) => c[0] > i).reduce((c, u) => c += u[1], 0) / kt;
|
|
1548
|
+
this.stats.tokensPerSecond = l / it, this.flushStatsCoalesced(), this.onEvent && this.onEvent(n).catch((c) => {
|
|
1549
|
+
console.error("Lost error on on-event", c);
|
|
1550
|
+
});
|
|
1551
|
+
} catch (n) {
|
|
1552
|
+
console.error("handleEvent error", n);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
g(z, "WebSocketConnecionV2");
|
|
1557
|
+
let rt = z;
|
|
1558
|
+
const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
1559
|
+
constructor(e, s, n, i, r, l, c, u, d, h, C) {
|
|
1560
|
+
super(e, s, n, i, r, l, c, d, C);
|
|
1561
|
+
a(this, "suspendState", !1);
|
|
1562
|
+
a(this, "wsService");
|
|
1563
|
+
a(this, "root_url", "");
|
|
1564
|
+
a(this, "hearBeatPort");
|
|
1565
|
+
a(this, "connectionAttempts", 0);
|
|
1566
|
+
a(this, "statuses", ["CONNECTING", "OPEN", "CLOSED", "UNKNOWN"]);
|
|
1567
|
+
a(this, "lastConnectionPromise", null);
|
|
1568
|
+
a(this, "socketState", P.Disconnected);
|
|
1569
|
+
a(this, "streamOpened", !1);
|
|
1570
|
+
this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (m) => {
|
|
1571
|
+
await super.Message(m);
|
|
1572
|
+
}, this.wsService.onNewPacket = (m) => {
|
|
1573
|
+
this.sessionState.setStatistics(m), this.eventBusService.streamEmitNewChunk(m);
|
|
1574
|
+
}, this.wsService.onPong = (m) => {
|
|
1575
|
+
}, this.wsService.onError = (m) => {
|
|
1576
|
+
this.streamOpened = !1;
|
|
1577
|
+
const f = {
|
|
1578
|
+
data: this.getErrorEvent(m),
|
|
1579
|
+
lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
1580
|
+
origin: "gatewayService"
|
|
1581
|
+
};
|
|
1582
|
+
console.error("Stream error:", m), this.notificationPort.pushNotification({
|
|
1583
|
+
message: "Stream error" + m,
|
|
1584
|
+
type: "warning"
|
|
1585
|
+
}), super.Message(f);
|
|
1586
|
+
}, this.wsService.onOpen = () => {
|
|
1587
|
+
this.sessionState.setConnectionStatus(P.Connected);
|
|
1588
|
+
}, this.wsService.onReconnected = (m) => {
|
|
1589
|
+
this.sessionState.setConnectionStatus(P.Connected);
|
|
1590
|
+
}, this.wsService.onFirstToken = (m) => {
|
|
1591
|
+
this.localEmitFirstToken(m);
|
|
1592
|
+
}, this.wsService.onClose = (m, f) => {
|
|
1593
|
+
m != $ && this.sessionState.setConnectionStatus(P.Disconnected);
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
reset(e, s) {
|
|
1597
|
+
throw new Error("Method not implemented.");
|
|
1598
|
+
}
|
|
1599
|
+
startStream(e) {
|
|
1600
|
+
throw new Error("Method not implemented.");
|
|
1601
|
+
}
|
|
1602
|
+
isSuspended() {
|
|
1603
|
+
return this.suspendState;
|
|
1604
|
+
}
|
|
1605
|
+
getStoredSessionId() {
|
|
1606
|
+
const e = localStorage.getItem(Lt);
|
|
1607
|
+
if (e)
|
|
1608
|
+
return e;
|
|
1609
|
+
}
|
|
1610
|
+
isInteractionComplete(e) {
|
|
1611
|
+
const s = this.interactionsMap.get(e);
|
|
1612
|
+
return s == null ? void 0 : s.turn_complete;
|
|
1613
|
+
}
|
|
1614
|
+
isTurnCompleted(e) {
|
|
1615
|
+
const s = this.interactionsMap.get(e);
|
|
1616
|
+
return s == null ? void 0 : s.turn_complete;
|
|
1617
|
+
}
|
|
1618
|
+
async finalResponse(e, s, n) {
|
|
1619
|
+
super.turnComplete(e, s, n);
|
|
1620
|
+
}
|
|
1621
|
+
stopStream(e = !0) {
|
|
1622
|
+
e && this.sessionState.setTurnOpen(!1), this.wsService && this.wsService.closeStream();
|
|
1623
|
+
}
|
|
1624
|
+
async suspend() {
|
|
1625
|
+
const e = this.wsService;
|
|
1626
|
+
return new Promise(async (n, i) => {
|
|
1627
|
+
let r = !1;
|
|
1628
|
+
e.onSuspended = () => {
|
|
1629
|
+
r = !0;
|
|
1630
|
+
}, e.suspendStream();
|
|
1631
|
+
try {
|
|
1632
|
+
let u = 0;
|
|
1633
|
+
for (; !r && u < 5e3; )
|
|
1634
|
+
await this.sleep(100), u += 100;
|
|
1635
|
+
if (r)
|
|
1636
|
+
if (this.currentIS) {
|
|
1637
|
+
const d = this.currentIS.interaction;
|
|
1638
|
+
d.isSuspended = !0, this.sessionState.setCurrentMessage(d), this.sessionState.setTurnOpen(!1), n(!0);
|
|
1639
|
+
} else
|
|
1640
|
+
console.error("CurrentIS is null"), i("CurrentIS is null");
|
|
1641
|
+
else
|
|
1642
|
+
i("Timeout awaiting for suspension");
|
|
1643
|
+
} finally {
|
|
1644
|
+
this.suspendState = !0;
|
|
1645
|
+
}
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
answerHumanTool(e, s) {
|
|
1649
|
+
this.wsService.answerHumanTool(e, s);
|
|
1650
|
+
}
|
|
1651
|
+
async cancelSuspend() {
|
|
1652
|
+
var s;
|
|
1653
|
+
const e = (s = this.currentIS) == null ? void 0 : s.interaction;
|
|
1654
|
+
e && (e.isSuspended = !1, this.turnComplete(e.interactionId, e, "Main"));
|
|
1655
|
+
}
|
|
1656
|
+
async check() {
|
|
1657
|
+
return !0;
|
|
1658
|
+
}
|
|
1659
|
+
async openConnection(e) {
|
|
1660
|
+
return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s, n) => {
|
|
1661
|
+
this.wsService.connect(e).then((i) => {
|
|
1662
|
+
this.sessionId = i, s(i);
|
|
1663
|
+
}).catch((i) => {
|
|
1664
|
+
n(i);
|
|
1665
|
+
}).finally(() => {
|
|
1666
|
+
this.lastConnectionPromise = null;
|
|
1667
|
+
});
|
|
1668
|
+
}), this.lastConnectionPromise) : Promise.resolve(this.sessionId);
|
|
1669
|
+
}
|
|
1670
|
+
async closeConnection(e = !0) {
|
|
1671
|
+
try {
|
|
1672
|
+
return this.stopStream(e), {
|
|
1673
|
+
success: !0,
|
|
1674
|
+
interaction: this.getCurrentInteraction()
|
|
1675
|
+
};
|
|
1676
|
+
} catch {
|
|
1677
|
+
return {
|
|
1678
|
+
success: !1,
|
|
1679
|
+
interaction: this.getCurrentInteraction()
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
simulateDisconnect(e = 4500, s = "Debug simulated disconnect") {
|
|
1684
|
+
const n = this.wsService;
|
|
1685
|
+
n != null && n.ws && n.ws.close(e, s);
|
|
1686
|
+
}
|
|
1687
|
+
async sleep(e) {
|
|
1688
|
+
return new Promise((s) => setTimeout(s, e));
|
|
1689
|
+
}
|
|
1690
|
+
// Send a message to the server via HTTP POST
|
|
1691
|
+
async sendMessageInternal(e, s, n) {
|
|
1692
|
+
var l, c, u, d, h, C, m, f;
|
|
1693
|
+
const i = this.suspendState;
|
|
1694
|
+
this.suspendState = !1;
|
|
1695
|
+
const r = this.startInteraction(e.friendlyMessage ?? e.data, i);
|
|
1696
|
+
if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(A.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
|
|
1697
|
+
throw "no wsService created";
|
|
1698
|
+
if (!this.sessionId)
|
|
1699
|
+
throw "no session id set";
|
|
1700
|
+
if (!((c = this.config.agentConfig) != null && c.id))
|
|
1701
|
+
throw "Agent not selected";
|
|
1702
|
+
return this.wsService.sendMessage({
|
|
1703
|
+
Content: e.data,
|
|
1704
|
+
SessionId: this.sessionId,
|
|
1705
|
+
Action: L.SendMessage,
|
|
1706
|
+
ModelId: this.config.model,
|
|
1707
|
+
InteractionId: r.interactionId,
|
|
1708
|
+
AgentId: (u = this.config.agentConfig) == null ? void 0 : u.id,
|
|
1709
|
+
// Optional explicit C# class name on the server (e.g. "LlmAgentSessionReplay").
|
|
1710
|
+
// When set, AgentBootStrapService.GetAgent dispatches to that class directly
|
|
1711
|
+
// instead of looking up an Agent metadata row by AgentId. Plumbed through
|
|
1712
|
+
// `agentContext.agentConfig.agentImplementation` so a host can run a turn
|
|
1713
|
+
// against any registered LlmAgent variant without seeding a Mongo record.
|
|
1714
|
+
AgentImplementation: (d = this.config.agentConfig) == null ? void 0 : d.agentImplementation,
|
|
1715
|
+
Parameters: {
|
|
1716
|
+
CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
|
|
1717
|
+
DataSet: ((C = this.config.customer) == null ? void 0 : C.dataSetId) ?? ""
|
|
1718
|
+
},
|
|
1719
|
+
// Forward image attachments as a structured payload (PascalCase
|
|
1720
|
+
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1721
|
+
Images: (m = e.images) != null && m.length ? e.images.map((w) => ({ MimeType: w.mimeType, Data: w.data })) : void 0,
|
|
1722
|
+
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1723
|
+
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1724
|
+
// request; Content remains the only model-facing text.
|
|
1725
|
+
UserUi: (f = e.userUi) != null && f.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
|
|
1726
|
+
}), this.localOpen(r.interactionId, "system"), Promise.resolve({
|
|
1727
|
+
interaction: r,
|
|
1728
|
+
success: !0
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
g(j, "AgentGatewayWSAsync");
|
|
1733
|
+
let ot = j;
|
|
1734
|
+
const Y = class Y {
|
|
1735
|
+
constructor(t, e) {
|
|
1736
|
+
a(this, "cache", /* @__PURE__ */ new Map());
|
|
1737
|
+
a(this, "serverBaseUrl");
|
|
1738
|
+
a(this, "accessToken");
|
|
1739
|
+
this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
|
|
1740
|
+
}
|
|
1741
|
+
get headers() {
|
|
1742
|
+
return { Authorization: `Bearer ${this.accessToken}` };
|
|
1743
|
+
}
|
|
1744
|
+
async init() {
|
|
1745
|
+
}
|
|
1746
|
+
getArtifacts() {
|
|
1747
|
+
return Array.from(this.cache.values());
|
|
1748
|
+
}
|
|
1749
|
+
async saveArtifact(t) {
|
|
1750
|
+
this.cache.set(t.id, t);
|
|
1751
|
+
}
|
|
1752
|
+
saveArtifactToCache(t) {
|
|
1753
|
+
this.cache.set(t.id, t);
|
|
1754
|
+
}
|
|
1755
|
+
async deleteArtifact(t) {
|
|
1756
|
+
this.cache.delete(t);
|
|
1757
|
+
}
|
|
1758
|
+
addToCache(t) {
|
|
1759
|
+
this.cache.set(t.id, t);
|
|
1760
|
+
}
|
|
1761
|
+
getArtifactWithCache(t) {
|
|
1762
|
+
return this.cache.get(t) ?? null;
|
|
1763
|
+
}
|
|
1764
|
+
async getArtifact(t, e) {
|
|
1765
|
+
if (this.cache.has(t)) return this.cache.get(t) ?? null;
|
|
1766
|
+
try {
|
|
1767
|
+
const s = await fetch(`${this.serverBaseUrl}/AdminArtifact/${t}`, {
|
|
1768
|
+
headers: this.headers
|
|
1769
|
+
});
|
|
1770
|
+
if (!s.ok) return null;
|
|
1771
|
+
const n = await s.json();
|
|
1772
|
+
return this.cache.set(n.id, n), n;
|
|
1773
|
+
} catch {
|
|
1774
|
+
return null;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
async clearAllArtifacts() {
|
|
1778
|
+
this.cache.clear();
|
|
1779
|
+
}
|
|
1780
|
+
async getFileContent(t) {
|
|
1781
|
+
try {
|
|
1782
|
+
const e = await fetch(t, { headers: this.headers });
|
|
1783
|
+
return e.ok ? await e.text() : null;
|
|
1784
|
+
} catch {
|
|
1785
|
+
return null;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
g(Y, "HttpArtifactService");
|
|
1790
|
+
let ct = Y;
|
|
1791
|
+
export {
|
|
1792
|
+
B as A,
|
|
1793
|
+
x as E,
|
|
1794
|
+
ct as H,
|
|
1795
|
+
b as I,
|
|
1796
|
+
st as L,
|
|
1797
|
+
nt as M,
|
|
1798
|
+
rt as W,
|
|
1799
|
+
ot as a,
|
|
1800
|
+
Kt as u
|
|
1801
|
+
};
|
|
1802
|
+
//# sourceMappingURL=httpArtifactService-BAR60Gu1.js.map
|