@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.
Files changed (218) hide show
  1. package/README.md +161 -0
  2. package/dist/ClientMessage-EKgfuTp8.js +40 -0
  3. package/dist/ClientMessage-EKgfuTp8.js.map +1 -0
  4. package/dist/Memory-DjLZqgbF.js +84 -0
  5. package/dist/Memory-DjLZqgbF.js.map +1 -0
  6. package/dist/Prompt-DZb7OaPp.js +37 -0
  7. package/dist/Prompt-DZb7OaPp.js.map +1 -0
  8. package/dist/artifactHtmlHandler-CMQJf1cX.js +41 -0
  9. package/dist/artifactHtmlHandler-CMQJf1cX.js.map +1 -0
  10. package/dist/auth-CcTgInbY.js +524 -0
  11. package/dist/auth-CcTgInbY.js.map +1 -0
  12. package/dist/components.d.ts +2 -0
  13. package/dist/components.js +14159 -0
  14. package/dist/components.js.map +1 -0
  15. package/dist/environmentUtils-BaKw5_VD.js +462 -0
  16. package/dist/environmentUtils-BaKw5_VD.js.map +1 -0
  17. package/dist/hooks.d.ts +2 -0
  18. package/dist/hooks.js +9 -0
  19. package/dist/hooks.js.map +1 -0
  20. package/dist/httpArtifactService-BAR60Gu1.js +1802 -0
  21. package/dist/httpArtifactService-BAR60Gu1.js.map +1 -0
  22. package/dist/httpSessionService-5Kr__oQL.js +279 -0
  23. package/dist/httpSessionService-5Kr__oQL.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +226 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/interfaces.d.ts +2 -0
  28. package/dist/interfaces.js +11 -0
  29. package/dist/interfaces.js.map +1 -0
  30. package/dist/models.d.ts +2 -0
  31. package/dist/models.js +54 -0
  32. package/dist/models.js.map +1 -0
  33. package/dist/serializer-DyHZxlAG.js +1276 -0
  34. package/dist/serializer-DyHZxlAG.js.map +1 -0
  35. package/dist/services.d.ts +2 -0
  36. package/dist/services.js +16 -0
  37. package/dist/services.js.map +1 -0
  38. package/dist/sortable-table-DgQHxWIh.js +819 -0
  39. package/dist/sortable-table-DgQHxWIh.js.map +1 -0
  40. package/dist/src/ErrorBondary.d.ts +10 -0
  41. package/dist/src/components/AiChat/AiChat.d.ts +3 -0
  42. package/dist/src/components/AiChat/AiChatContext.d.ts +76 -0
  43. package/dist/src/components/AiChat/AiChatDrawer.d.ts +3 -0
  44. package/dist/src/components/AiChat/AiChatFloating.d.ts +3 -0
  45. package/dist/src/components/AiChat/AiChatProvider.d.ts +7 -0
  46. package/dist/src/components/AiChat/AiChatSessionStore.d.ts +1 -0
  47. package/dist/src/components/AiChat/AiChatTypes.d.ts +227 -0
  48. package/dist/src/components/AiChat/ChatPane/AlertDialog.d.ts +12 -0
  49. package/dist/src/components/AiChat/ChatPane/AskUserSheet.d.ts +25 -0
  50. package/dist/src/components/AiChat/ChatPane/ChatPane.d.ts +7 -0
  51. package/dist/src/components/AiChat/ChatPane/ConnectionState.d.ts +2 -0
  52. package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +12 -0
  53. package/dist/src/components/AiChat/ChatPane/Event.d.ts +6 -0
  54. package/dist/src/components/AiChat/ChatPane/FloatingConnectionStatus.d.ts +8 -0
  55. package/dist/src/components/AiChat/ChatPane/FriendlyPartDisplay.d.ts +13 -0
  56. package/dist/src/components/AiChat/ChatPane/LastPrompts.d.ts +9 -0
  57. package/dist/src/components/AiChat/ChatPane/Message.d.ts +11 -0
  58. package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +16 -0
  59. package/dist/src/components/AiChat/ChatPane/MessageNonTextDisplay.d.ts +16 -0
  60. package/dist/src/components/AiChat/ChatPane/MessagePart.d.ts +15 -0
  61. package/dist/src/components/AiChat/ChatPane/MessagePersona.d.ts +13 -0
  62. package/dist/src/components/AiChat/ChatPane/MessageUser.d.ts +8 -0
  63. package/dist/src/components/AiChat/ChatPane/ModelSelector.d.ts +11 -0
  64. package/dist/src/components/AiChat/ChatPane/Prompt.d.ts +9 -0
  65. package/dist/src/components/AiChat/ChatPane/SessionDataDialog.d.ts +7 -0
  66. package/dist/src/components/AiChat/ChatPane/StickyQuestionHeader.d.ts +7 -0
  67. package/dist/src/components/AiChat/ChatPane/StreamStatistics.d.ts +32 -0
  68. package/dist/src/components/AiChat/ChatPane/SubAgentBox.d.ts +9 -0
  69. package/dist/src/components/AiChat/ChatPane/TaskList.d.ts +6 -0
  70. package/dist/src/components/AiChat/ChatPane/friendlyToolConfig.d.ts +11 -0
  71. package/dist/src/components/AiChat/ChatPane/parts/AskUserPart.d.ts +8 -0
  72. package/dist/src/components/AiChat/ChatPane/parts/BoxedPart.d.ts +4 -0
  73. package/dist/src/components/AiChat/ChatPane/parts/FunctionPart.d.ts +4 -0
  74. package/dist/src/components/AiChat/ChatPane/parts/SuspendedPart.d.ts +4 -0
  75. package/dist/src/components/AiChat/ChatPane/parts/TextPart.d.ts +4 -0
  76. package/dist/src/components/AiChat/ChatPane/parts/ThoughtPart.d.ts +4 -0
  77. package/dist/src/components/AiChat/ChatPane/parts/UiToolDispatcher.d.ts +16 -0
  78. package/dist/src/components/AiChat/ChatPane/parts/WaitingPart.d.ts +4 -0
  79. package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +20 -0
  80. package/dist/src/components/AiChat/ChatPane/parts/index.test.d.ts +1 -0
  81. package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +22 -0
  82. package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.d.ts +121 -0
  83. package/dist/src/components/AiChat/index.d.ts +13 -0
  84. package/dist/src/components/AiChat/sessionStateManagerService.d.ts +47 -0
  85. package/dist/src/components/AiChat/stateConfiguration.d.ts +80 -0
  86. package/dist/src/components/Library/ArtifactRender.d.ts +18 -0
  87. package/dist/src/components/Library/DelayTextComponent.d.ts +9 -0
  88. package/dist/src/components/Library/LinearBackgroundProgress.d.ts +8 -0
  89. package/dist/src/components/Library/LinearProgressBarWithMarkers.d.ts +14 -0
  90. package/dist/src/components/Library/LoadingDots.d.ts +8 -0
  91. package/dist/src/components/Library/MarkdowmExtended.d.ts +32 -0
  92. package/dist/src/components/Library/VizLibrary/Skeletons/ChartSkeleton.d.ts +3 -0
  93. package/dist/src/components/Library/VizLibrary/Skeletons/IFrameSkeleton.d.ts +3 -0
  94. package/dist/src/components/Library/VizLibrary/Skeletons/MetricGroupSkeleton.d.ts +8 -0
  95. package/dist/src/components/Library/VizLibrary/Skeletons/MetricSkeleton.d.ts +7 -0
  96. package/dist/src/components/Library/VizLibrary/Skeletons/TableSkeleton.d.ts +7 -0
  97. package/dist/src/components/Library/VizLibrary/index.d.ts +5 -0
  98. package/dist/src/components/LlmResponseRender/EnvironmentContext.d.ts +33 -0
  99. package/dist/src/components/LlmResponseRender/GeneratingVisualization.d.ts +13 -0
  100. package/dist/src/components/LlmResponseRender/LiveJsxBlock.d.ts +55 -0
  101. package/dist/src/components/LlmResponseRender/LlmResponseRender.d.ts +29 -0
  102. package/dist/src/components/LlmResponseRender/index.d.ts +6 -0
  103. package/dist/src/components/LlmResponseRender/jsxScope.d.ts +41 -0
  104. package/dist/src/components/LlmResponseRender/liveTsxConfig.d.ts +18 -0
  105. package/dist/src/components/LlmResponseRender/parseBlocks.d.ts +39 -0
  106. package/dist/src/components/Stopwatch.d.ts +12 -0
  107. package/dist/src/components/index.d.ts +30 -0
  108. package/dist/src/components/v2/AgentActivityV2.d.ts +32 -0
  109. package/dist/src/components/v2/AiChatFloatingV2.d.ts +3 -0
  110. package/dist/src/components/v2/AiChatV2Pane.d.ts +20 -0
  111. package/dist/src/components/v2/AppBarV2.d.ts +38 -0
  112. package/dist/src/components/v2/AppRailV2.d.ts +21 -0
  113. package/dist/src/components/v2/AppShellV2.d.ts +13 -0
  114. package/dist/src/components/v2/ChatsHistoryV2.d.ts +47 -0
  115. package/dist/src/components/v2/LastPromptsV2.d.ts +6 -0
  116. package/dist/src/components/v2/MobileDrawerV2.d.ts +43 -0
  117. package/dist/src/components/v2/PromptV2.d.ts +164 -0
  118. package/dist/src/components/v2/RunProgressPanelV2.d.ts +28 -0
  119. package/dist/src/components/v2/RunProgressStripV2.d.ts +2 -0
  120. package/dist/src/components/v2/Sparkline.d.ts +10 -0
  121. package/dist/src/components/v2/SubAgentBoxV2.d.ts +15 -0
  122. package/dist/src/components/v2/TaskListV2.d.ts +8 -0
  123. package/dist/src/components/v2/icons.d.ts +42 -0
  124. package/dist/src/components/v2/index.d.ts +34 -0
  125. package/dist/src/components/v2/styles.d.ts +6 -0
  126. package/dist/src/components/v2/toolCategories.d.ts +18 -0
  127. package/dist/src/components/v2/useResponsiveLayout.d.ts +9 -0
  128. package/dist/src/hooks/index.d.ts +4 -0
  129. package/dist/src/hooks/useChatSessions.d.ts +68 -0
  130. package/dist/src/hooks/useContainerWidth.d.ts +2 -0
  131. package/dist/src/hooks/useIntervalHook.d.ts +2 -0
  132. package/dist/src/index.d.ts +7 -0
  133. package/dist/src/interfaces/IHeartbeatPort.d.ts +4 -0
  134. package/dist/src/interfaces/INotificationPort.d.ts +4 -0
  135. package/dist/src/interfaces/index.d.ts +4 -0
  136. package/dist/src/interfaces/memoryService.d.ts +37 -0
  137. package/dist/src/interfaces/schedulingService.d.ts +64 -0
  138. package/dist/src/models/Agent.d.ts +32 -0
  139. package/dist/src/models/Artifact.d.ts +21 -0
  140. package/dist/src/models/ArtifactData.d.ts +30 -0
  141. package/dist/src/models/ChatSession.d.ts +57 -0
  142. package/dist/src/models/ClientMessage.d.ts +38 -0
  143. package/dist/src/models/Customer.d.ts +7 -0
  144. package/dist/src/models/EndMessageData.d.ts +6 -0
  145. package/dist/src/models/IAbiContext.d.ts +8 -0
  146. package/dist/src/models/IDBStorable.d.ts +14 -0
  147. package/dist/src/models/Interaction.d.ts +36 -0
  148. package/dist/src/models/InteractionPart.d.ts +69 -0
  149. package/dist/src/models/LlmSession.d.ts +10 -0
  150. package/dist/src/models/Memory.d.ts +48 -0
  151. package/dist/src/models/Notification.d.ts +11 -0
  152. package/dist/src/models/Prompt.d.ts +20 -0
  153. package/dist/src/models/SendMessageResponse.d.ts +21 -0
  154. package/dist/src/models/ServerEvent.d.ts +130 -0
  155. package/dist/src/models/connectionState.d.ts +9 -0
  156. package/dist/src/models/contexts.d.ts +33 -0
  157. package/dist/src/models/enums.d.ts +333 -0
  158. package/dist/src/models/index.d.ts +36 -0
  159. package/dist/src/models/semanticKernelModel/index.d.ts +2 -0
  160. package/dist/src/models/semanticKernelModel/init.d.ts +1 -0
  161. package/dist/src/models/semanticKernelModel/models.d.ts +208 -0
  162. package/dist/src/models/semanticKernelModel/serializer.d.ts +40 -0
  163. package/dist/src/models/serverReponse.d.ts +5 -0
  164. package/dist/src/models/subAgentModel.d.ts +48 -0
  165. package/dist/src/models/todoListModel.d.ts +18 -0
  166. package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +163 -0
  167. package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +75 -0
  168. package/dist/src/services/artifactHtmlHandler.d.ts +6 -0
  169. package/dist/src/services/eventBusService.d.ts +119 -0
  170. package/dist/src/services/httpArtifactService.d.ts +25 -0
  171. package/dist/src/services/httpSessionService.d.ts +31 -0
  172. package/dist/src/services/index.d.ts +16 -0
  173. package/dist/src/services/interactionService.d.ts +28 -0
  174. package/dist/src/services/interactionService.test.d.ts +1 -0
  175. package/dist/src/services/interfaces/artifactService.d.ts +13 -0
  176. package/dist/src/services/servers/AgentGatewayService.d.ts +167 -0
  177. package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +44 -0
  178. package/dist/src/services/servers/agentGatewayWSAsync.test.d.ts +1 -0
  179. package/dist/src/services/servers/sessionService/ISessionService.d.ts +20 -0
  180. package/dist/src/services/sessionEventDecoder.d.ts +22 -0
  181. package/dist/src/services/sessionEventDecoder.test.d.ts +1 -0
  182. package/dist/src/services/storageService.d.ts +73 -0
  183. package/dist/src/themes/index.d.ts +3 -0
  184. package/dist/src/themes/v2-chart-palette.d.ts +1 -0
  185. package/dist/src/themes/v2.d.ts +71 -0
  186. package/dist/src/utils/auth.d.ts +9 -0
  187. package/dist/src/utils/envOverrides.d.ts +23 -0
  188. package/dist/src/utils/envUtils.d.ts +13 -0
  189. package/dist/src/utils/environmentUtils.d.ts +43 -0
  190. package/dist/src/utils/fileUtils.d.ts +6 -0
  191. package/dist/src/utils/getAgentArtifactsBaseUrl.d.ts +1 -0
  192. package/dist/src/utils/getAgentBaseUrl.d.ts +1 -0
  193. package/dist/src/utils/getDotNetBaseUrl.d.ts +5 -0
  194. package/dist/src/utils/index.d.ts +17 -0
  195. package/dist/src/utils/interactionIdChecker.d.ts +27 -0
  196. package/dist/src/utils/jsonDetector.d.ts +50 -0
  197. package/dist/src/utils/jsonUtils.d.ts +1 -0
  198. package/dist/src/utils/materialIconsList.d.ts +42 -0
  199. package/dist/src/utils/materialIconsSvg.d.ts +51 -0
  200. package/dist/src/utils/objectUtils.d.ts +31 -0
  201. package/dist/src/utils/parseArtifact.d.ts +3 -0
  202. package/dist/src/utils/sessionWindowParameters.d.ts +3 -0
  203. package/dist/src/utils/sortable-table.d.ts +31 -0
  204. package/dist/src/utils/stringUtils.d.ts +8 -0
  205. package/dist/src/utils/uriUtils.d.ts +39 -0
  206. package/dist/src/utils/urlParser.d.ts +8 -0
  207. package/dist/style.css +94 -0
  208. package/dist/tests/fakes/fakeWebSocket.d.ts +32 -0
  209. package/dist/tests/fakes/makeGateway.d.ts +24 -0
  210. package/dist/tests/fixtures.d.ts +73 -0
  211. package/dist/useChatSessions-DttlifVk.js +107 -0
  212. package/dist/useChatSessions-DttlifVk.js.map +1 -0
  213. package/dist/useContainerWidth-Df2PmSoC.js +52 -0
  214. package/dist/useContainerWidth-Df2PmSoC.js.map +1 -0
  215. package/dist/utils.d.ts +2 -0
  216. package/dist/utils.js +49 -0
  217. package/dist/utils.js.map +1 -0
  218. package/package.json +127 -0
@@ -0,0 +1,48 @@
1
+ import { TodoList } from './todoListModel';
2
+ /**
3
+ * Mirrors `Envision.SemanticKernel.Core.SubAgent.SubAgentStatus` enum on the
4
+ * server. Values come back as plain strings (the controller uses `Status.ToString()`).
5
+ */
6
+ export type SubAgentStatus = 'Pending' | 'Running' | 'Completed' | 'Failed' | 'Cancelled' | 'Unknown';
7
+ /**
8
+ * Lightweight representation of a chat message embedded in the SubAgentDto.
9
+ * The server-side `Message` type carries more fields, but only the basics are
10
+ * needed for status polling on the client.
11
+ */
12
+ export interface SubAgentMessage {
13
+ id?: string;
14
+ role?: string;
15
+ content?: string;
16
+ [key: string]: unknown;
17
+ }
18
+ /**
19
+ * TypeScript counterpart of `Envision.SemanticKernel.Core.SubAgent.SubAgentDto`.
20
+ *
21
+ * This is the payload returned by `GET /SubAgent/{sessionId}/{id}`.
22
+ *
23
+ * `TodoList.percentComplete` is serialized by the server as a fraction in the
24
+ * range `[0, 1]` (i.e. `completedItems / totalItems`). It can be `NaN` when the
25
+ * todo list is empty, so consumers should guard against non-finite values.
26
+ */
27
+ export interface SubAgentDto {
28
+ id?: string;
29
+ subAgentId: string;
30
+ name: string;
31
+ sessionId?: string;
32
+ dashboardId?: string | null;
33
+ todoList?: TodoList | null;
34
+ generalInstructions?: string | null;
35
+ dashboardInstructions?: string | null;
36
+ detailedStatus?: string | null;
37
+ status: SubAgentStatus | string;
38
+ error?: string | null;
39
+ hasResult?: boolean | null;
40
+ finalSummary?: string | null;
41
+ parameters?: Record<string, string> | null;
42
+ updatedAt?: string | Date | null;
43
+ created?: string | Date | null;
44
+ message?: SubAgentMessage | null;
45
+ }
46
+ /** Status values that indicate the sub-agent is no longer making progress. */
47
+ export declare const SUB_AGENT_TERMINAL_STATUSES: ReadonlyArray<SubAgentStatus>;
48
+ export declare function isSubAgentTerminalStatus(status: string | undefined | null): boolean;
@@ -0,0 +1,18 @@
1
+ export type TodoItemStatus = 'Pending' | 'pending' | 'in_progress' | 'InProgress' | 'Completed' | 'completed' | 'Failed' | 'failed';
2
+ export interface TodoList {
3
+ id?: string;
4
+ title?: string;
5
+ items: TodoItem[];
6
+ currentWorkingItemKey?: string;
7
+ /**
8
+ * Fraction of completed items in the range `[0, 1]` (e.g. `0.4` means 40%).
9
+ * Computed and serialized by the server. Can be `NaN` when `items` is empty.
10
+ */
11
+ percentComplete?: number;
12
+ }
13
+ export interface TodoItem {
14
+ key: string;
15
+ label: string;
16
+ status: TodoItemStatus;
17
+ detail?: string;
18
+ }
@@ -0,0 +1,163 @@
1
+ import { ServerEvent } from '../../models/ServerEvent';
2
+ import { TypedJSON } from 'typedjson';
3
+ import { InteractionStatistics, LlmEvent, StreamingResponse } from '../../models/semanticKernelModel/models';
4
+ import { IWebSocketConnection, IMessage, IMessageBase } from './webSocketConnection';
5
+ export declare const APPLICATION_CLOSED_CODE = 4001;
6
+ /**
7
+ * The server uses this WS close code when rejecting a duplicate attachment for the
8
+ * same sessionId (single-attach policy in InteractionRunRegistry). The user already
9
+ * has another WS connected for this session — usually another browser tab — so
10
+ * silently auto-reconnecting would just bounce the rejection forever. Surface the
11
+ * close to the consumer instead.
12
+ */
13
+ export declare const SESSION_ALREADY_ATTACHED_CODE = 4002;
14
+ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
15
+ ws: WebSocket | null;
16
+ stats: InteractionStatistics;
17
+ baseUrl: string;
18
+ /**
19
+ * Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
20
+ * so that a refreshed token is picked up automatically. Browsers can't set the Authorization
21
+ * header on the WebSocket handshake, so we pass the JWT via the ?access_token= query string,
22
+ * which the .NET JwtBearer events handler reads in Program.cs.
23
+ */
24
+ getToken?: () => string | undefined;
25
+ onEvent?: (event: MessageEvent | ServerEvent) => Promise<void>;
26
+ onError?: (error: string) => void;
27
+ onOpen?: () => void;
28
+ onFirstToken?: (interactionId: string) => void;
29
+ onSuspended?: () => void;
30
+ onPong?: (sessionId: string) => void;
31
+ onClose?: (code: number, reason: string) => void;
32
+ /** Fired when an unexpected close triggers a reconnect attempt. */
33
+ onReconnecting?: (attempt: number, delayMs: number) => void;
34
+ /** Fired the first time the socket reopens after an unexpected close. */
35
+ onReconnected?: (sessionId: string) => void;
36
+ /**
37
+ * Fired when the server signals that we lost streaming events on resume — our
38
+ * `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
39
+ * reset partial-streaming UI for this session and rely on persisted history.
40
+ */
41
+ onRewindLost?: (sessionId: string, resumingFromSeq: number) => void;
42
+ sessionId?: string;
43
+ onNewPacket?: (stats: InteractionStatistics) => void;
44
+ /**
45
+ * Stats can fire dozens of times per second during streaming. We
46
+ * coalesce to a fixed cadence so subscribers see steady,
47
+ * digestible updates instead of a per-packet firehose — the
48
+ * latter caused a "Maximum update depth exceeded" cascade in
49
+ * heavy v2 surfaces (RunProgressPanelV2 + StreamStatistics +
50
+ * ChatTranscript all subscribed to `statistics` and re-rendered
51
+ * on every packet, with their useEffect-driven setStates pushing
52
+ * React's nested-update counter past its threshold).
53
+ */
54
+ private statsFlushTimer;
55
+ private statsLastFlushed;
56
+ private readonly STATS_FLUSH_MS;
57
+ monitorInterval: NodeJS.Timeout | null;
58
+ streamingResponseSerializer: TypedJSON<StreamingResponse>;
59
+ events: [number, number][];
60
+ lastActivity: number;
61
+ pingPongStack: number[];
62
+ firstTokenInteractions: Set<string>;
63
+ /** Last sessionId we successfully had — used to resume on reconnect. */
64
+ private lastKnownSessionId?;
65
+ /** True when the consumer called `disconnect()` — suppresses auto-reconnect. */
66
+ private intentionalDisconnect;
67
+ /** Number of reconnect attempts since the last clean open. */
68
+ private reconnectAttempts;
69
+ private reconnectTimer;
70
+ /** True while we are in the middle of an unexpected-close → reconnect cycle. */
71
+ private isReconnecting;
72
+ /** Internal flag set by `scheduleReconnect` so `connect()` does not reset the backoff state. */
73
+ private _internalReconnect;
74
+ /**
75
+ * Highest server-assigned `seq` we have observed and processed. The next
76
+ * reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
77
+ * we missed from the InteractionRun's in-memory buffer. -1 means "haven't
78
+ * seen any sequenced events yet" (fresh connection).
79
+ */
80
+ private lastSeq;
81
+ /**
82
+ * True once *any* socket on this instance has received at least one packet.
83
+ * Used by `onclose` to distinguish a real mid-stream drop (we had a working
84
+ * channel) from a connect attempt that never produced traffic (server down,
85
+ * unreachable, etc.). The inner reconnect loop is only meant for the former
86
+ * — fresh-connect failures should be handed straight to the outer
87
+ * SessionStateManagerService.processRetryLoop instead of being retried
88
+ * twice in here. Sticky for the lifetime of this connection instance so
89
+ * that internal resume attempts keep their full inner-loop budget even
90
+ * when a replacement socket fails before delivering its first message.
91
+ * Cleared by `disconnect()`.
92
+ */
93
+ private hasEverReceivedPacket;
94
+ constructor(baseUrl?: string, getToken?: () => string | undefined);
95
+ /**
96
+ * Connect to the WebSocket endpoint
97
+ */
98
+ connect(sessionId?: string): Promise<string>;
99
+ /**
100
+ * Returns true when the close code is something we believe a fresh connect
101
+ * (with the same sessionId) can recover from. We deliberately do NOT retry
102
+ * on:
103
+ * - 1000 normal closure
104
+ * - 1008 policy violation (auth rejected)
105
+ * - 4001 our own intentional disconnect
106
+ * - 4000-4099 reserved for app-level fatal codes from the server
107
+ */
108
+ private shouldAttemptReconnect;
109
+ private cancelPendingReconnect;
110
+ private computeBackoffDelay;
111
+ private scheduleReconnect;
112
+ sleep(ms: number): Promise<unknown>;
113
+ /**
114
+ * Handle incoming messages from server
115
+ */
116
+ handleMessage(streamingResponse: StreamingResponse, rawData: string): LlmEvent | null | undefined;
117
+ protected emitFirstToken(interactionId?: string): void;
118
+ /**
119
+ * Mirror a server-side-refreshed JWT into the stored user record so the global
120
+ * fetch interceptor (packages/dashboard-app/.../EnvisionAuthProvider.tsx) picks
121
+ * it up on the next HTTP call. Idempotent — the same token is delivered on
122
+ * multiple consecutive Pong frames for listener-readiness, and we only write
123
+ * when it actually changed.
124
+ *
125
+ * Uses the same localStorage key the auth provider reads (`envision_user`).
126
+ * Done here in the WS layer rather than via a callback so consumers don't need
127
+ * to wire up token-handling boilerplate; React contexts that hold the user in
128
+ * memory will pick up the new token on the next refresh/render or via their
129
+ * own storage listeners.
130
+ */
131
+ private persistRefreshedAccessToken;
132
+ closeStream(): void;
133
+ suspendStream(): void;
134
+ /** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
135
+ answerHumanTool(toolCallId: string, answer: string): void;
136
+ /**
137
+ * Send a message to the agent
138
+ */
139
+ sendMessage(message: IMessage): void;
140
+ sendBaseMessage(message: IMessageBase): void;
141
+ sendSuspendMessage(message: IMessage): void;
142
+ monitor(): void;
143
+ /**
144
+ * Send a heartbeat ping
145
+ */
146
+ ping(): void;
147
+ /**
148
+ * Disconnect the WebSocket
149
+ */
150
+ disconnect(): void;
151
+ /**
152
+ * Check if connected
153
+ */
154
+ isConnected(): boolean;
155
+ /**
156
+ * Push the latest stats out to `onNewPacket`, but at most every
157
+ * `STATS_FLUSH_MS` ms. Subsequent packets within the window
158
+ * schedule a trailing flush so the UI eventually sees the final
159
+ * value without each individual packet causing a re-render.
160
+ */
161
+ private flushStatsCoalesced;
162
+ handleEvent(llmEvent: LlmEvent, rawData: string): Promise<void>;
163
+ }
@@ -0,0 +1,75 @@
1
+ import { ServerEvent } from '../../models/ServerEvent';
2
+ import { ChatAction } from '../../models/enums';
3
+ import { InteractionStatistics } from '../../models/semanticKernelModel/models';
4
+ export interface IMessageBase {
5
+ Action: ChatAction;
6
+ ModelId?: string;
7
+ AgentId: string;
8
+ InteractionId: string;
9
+ /** ask_user answer routing (Action === 'AnswerHumanTool'): the parked tool-call id and the user's answer. */
10
+ ToolCallId?: string;
11
+ Answer?: string;
12
+ }
13
+ export interface IMessageImage {
14
+ MimeType: string;
15
+ /** Base64-encoded payload (no data-URL prefix). */
16
+ Data: string;
17
+ }
18
+ export interface IMessage extends IMessageBase {
19
+ Content: string;
20
+ SessionId?: string;
21
+ Parameters?: {
22
+ [key: string]: string;
23
+ };
24
+ CustumerId?: string;
25
+ /**
26
+ * Optional explicit C# class name to dispatch the turn to (e.g.
27
+ * `"LlmAgentSessionReplay"`). When set, `AgentBootStrapService.GetAgent`
28
+ * resolves the LlmAgent directly by type name and skips the Mongo
29
+ * Agents-collection lookup. Used by the replay demo so a host can target
30
+ * any registered LlmAgent variant without seeding a metadata row.
31
+ */
32
+ AgentImplementation?: string;
33
+ /**
34
+ * Optional image attachments. Server-side `Message.Images` mirrors this
35
+ * shape; PascalCase here is intentional so System.Text.Json deserialises
36
+ * straight onto the C# model.
37
+ */
38
+ Images?: IMessageImage[];
39
+ /**
40
+ * Optional client-only UI representation for this user turn. Server-side
41
+ * `Message.UserUi` mirrors this shape (PascalCase for System.Text.Json). The server
42
+ * persists it as a `UserUiContent` sibling and strips it from the model request, so
43
+ * `Content` stays the only model-facing text. `Args` is a serialized JSON string.
44
+ */
45
+ UserUi?: {
46
+ Name: string;
47
+ Args?: string;
48
+ };
49
+ }
50
+ export interface IWebSocketConnection {
51
+ onEvent?: (event: MessageEvent | ServerEvent) => Promise<void>;
52
+ onError?: (error: string) => void;
53
+ onOpen?: () => void;
54
+ onFirstToken?: (interactionId: string) => void;
55
+ onSuspended?: () => void;
56
+ onClose?: (code: number, reason: string) => void;
57
+ onNewPacket?: (stats: InteractionStatistics) => void;
58
+ onPong?: (sessionId: string) => void;
59
+ /** Emitted when an unexpected close kicks off the auto-reconnect loop. */
60
+ onReconnecting?: (attempt: number, delayMs: number) => void;
61
+ /** Emitted on the first successful re-open after one or more reconnect attempts. */
62
+ onReconnected?: (sessionId: string) => void;
63
+ /**
64
+ * Emitted when the server signals that some events were lost on resume —
65
+ * our `lastSeq` was older than its in-memory replay buffer. UI should
66
+ * reset partial-streaming state for the affected session.
67
+ */
68
+ onRewindLost?: (sessionId: string, resumingFromSeq: number) => void;
69
+ connect: (sessionId?: string) => Promise<string>;
70
+ sendMessage: (message: IMessage) => void;
71
+ suspendStream: () => void;
72
+ disconnect: () => void;
73
+ closeStream: () => void;
74
+ isConnected: () => boolean;
75
+ }
@@ -0,0 +1,6 @@
1
+ import { Theme } from '@mui/material/styles';
2
+ export declare class ArtifactHtmlHandler {
3
+ static defaultIframeScript: string;
4
+ static replaceVarText: (artifactHtml: string, _theme: Theme) => string;
5
+ static handleArtifactHtml(artifactHtml: string, _mode: 'full' | 'compact', _isMobile: boolean, theme: Theme): string;
6
+ }
@@ -0,0 +1,119 @@
1
+ import { EndMessageData } from '../models/EndMessageData';
2
+ import { ArtifactData } from '../models/ArtifactData';
3
+ import { ChatSession } from '../models/ChatSession';
4
+ import { Interaction, MergeResult } from '../models/Interaction';
5
+ import { FunctionDetails } from '../models/ServerEvent';
6
+ import { Artifact } from '../models/Artifact';
7
+ import { ConnectionState } from '../models/connectionState';
8
+ import { InteractionStatistics } from '../models/semanticKernelModel/models';
9
+ export interface FirstTokenEventDetails {
10
+ interactionId: string;
11
+ callId?: string;
12
+ }
13
+ export declare class EventTypes {
14
+ activityLost: string;
15
+ artifactGenerated: string;
16
+ artifactSelected: string;
17
+ artifactDeleted: string;
18
+ gatewayMessage: string;
19
+ gatewayTurnComplete: string;
20
+ gatewayStreamError: string;
21
+ gatewayTurnOpen: string;
22
+ sessionCreated: string;
23
+ sessionUpdated: string;
24
+ gatewayFunctionResponse: string;
25
+ uiUnsavedPopoverToggle: string;
26
+ artifactsStorageUpdated: string;
27
+ gatewayStreamEnded: string;
28
+ streamNewChunk: string;
29
+ gatewayEndMessageData: string;
30
+ connectionStateChange: string;
31
+ onMessageSent: string;
32
+ onMessageError: string;
33
+ onToolEvent: string;
34
+ gatewayFirstToken: string;
35
+ }
36
+ export declare const allEventTypes: EventTypes;
37
+ export declare class EventBusService {
38
+ protected listeners: {
39
+ [methodName: string]: ((...args: any) => Promise<void>)[];
40
+ };
41
+ protected listenersCount: {
42
+ [methodName: string]: number;
43
+ };
44
+ protected callListeners(eventName: string, ...args: any[]): void;
45
+ protected addListener(eventName: string, listener: (...args: any) => Promise<void>): void;
46
+ getEventState(eventName: string): number;
47
+ activityOnLost(listener: (...args: any) => Promise<void>): void;
48
+ activityEmitLost(): void;
49
+ artifactOnGenerated(listener: (artifact: Artifact) => Promise<void>): void;
50
+ artifactEmitGenerated(artifact: Artifact): void;
51
+ artifactOffGenerated(listener: (artifact: Artifact) => Promise<void>): void;
52
+ artifactOnSelected(listener: (artifact: Artifact | string) => Promise<void>): void;
53
+ artifactEmitSelected(artifact: Artifact | string): void;
54
+ artifactOffSelected(listener: (artifact: Artifact | string) => Promise<void>): void;
55
+ artifactOnDeleted(listener: (artifact: Artifact) => Promise<void>): void;
56
+ artifactEmitDeleted(artifact: ArtifactData): void;
57
+ artifactOffDeleted(listener: (artifact: ArtifactData) => Promise<void>): void;
58
+ gatewayOnMessage(listener: (interaction: Interaction, messageDetails: MergeResult | null) => Promise<void>): void;
59
+ gatewayOnTurnComplete(listener: (interactionId: string, interaction: Interaction) => Promise<void>): void;
60
+ gatewayOnTurnOpen(listener: (interactionId: string) => Promise<void>): void;
61
+ gatewayOnStreamError(listener: (...args: any[]) => Promise<void>): void;
62
+ gatewayOnStreamEnded(listener: (...args: any[]) => Promise<void>): void;
63
+ gatewayOffStreamEnded(listener: (...args: any[]) => Promise<void>): void;
64
+ gatewayEmitStreamEnded(interactionId: string, interaction: Interaction): void;
65
+ gatewayEmitMessage(agentInteraction: Interaction, messageDetails?: MergeResult | null): void;
66
+ gatewayEmitTurnComplete(interactionId: string, agentInteraction: Interaction): void;
67
+ gatewayEmitStreamError(errorMessage: string): void;
68
+ gatewayEmitTurnOpen(interactionId: string): void;
69
+ gatewayOffMessage(listener: (interaction: Interaction, messageDetails: MergeResult | null) => Promise<void>): void;
70
+ gatewayOffTurnComplete(listener: (interactionId: string, interaction: Interaction) => Promise<void>): void;
71
+ gatewayOffTurnOpen(listener: (interactionId: string) => Promise<void>): void;
72
+ gatewayOffStreamError(listener: (...args: any[]) => Promise<void>): void;
73
+ sessionOnCreated(listener: (...args: any[]) => Promise<void>): void;
74
+ chatOnMessageSent(listener: (messate: string, interaction: Interaction) => Promise<void>): void;
75
+ chatOffMessageSent(listener: (...args: any[]) => Promise<void>): void;
76
+ ChatEmitMessageSent(message: string, interaction: Interaction): void;
77
+ chatOnMessageError(listener: (error: string) => Promise<void>): void;
78
+ chatOffMessageError(listener: (...args: any[]) => Promise<void>): void;
79
+ ChatEmitMessageError(error: string): void;
80
+ sessionOnUpdated(listener: (...args: any[]) => Promise<void>): void;
81
+ sessionEmitCreated(session: ChatSession): void;
82
+ sessionEmitUpdated(session: ChatSession): void;
83
+ sessionOffCreated(listener: (...args: any[]) => Promise<void>): void;
84
+ sessionOffUpdated(listener: (...args: any[]) => Promise<void>): void;
85
+ gatewayEmitFunctionResponse(functionDetails: FunctionDetails): void;
86
+ gatewayOffFunctionResponse(listener: (...args: any[]) => Promise<void>): void;
87
+ gatewayOnFunctionResponse(listener: (...args: any[]) => Promise<void>): void;
88
+ uiOnUnsavedPopoverToggle(listener: (anchorEl: HTMLElement | null) => Promise<void>): void;
89
+ uiEmitUnsavedPopoverToggle(anchorEl: HTMLElement | null): void;
90
+ uiOffUnsavedPopoverToggle(listener: (anchorEl: HTMLElement | null) => Promise<void>): void;
91
+ artifactsOnStorageUpdated(listener: () => Promise<void>): void;
92
+ artifactsEmitStorageUpdated(): void;
93
+ artifactsOffStorageUpdated(listener: () => Promise<void>): void;
94
+ streamOnNewChunk(listener: (stats: InteractionStatistics) => Promise<void>): void;
95
+ streamEmitNewChunk(stats: InteractionStatistics): void;
96
+ streamOffNewChunk(listener: (stats: InteractionStatistics) => Promise<void>): void;
97
+ gatewayOnEndMessageData(listener: (data: EndMessageData) => Promise<void>): void;
98
+ gatewayEmitEndMessageData(data: EndMessageData): void;
99
+ gatewayOffEndMessageData(listener: (data: EndMessageData) => Promise<void>): void;
100
+ gatewayOnConnectionStateChange(listener: (state: ConnectionState) => Promise<void>): void;
101
+ gatewayEmitConnectionStateChange(state: ConnectionState): void;
102
+ gatewayOffConnectionStateChange(listener: (state: ConnectionState) => Promise<void>): void;
103
+ gatewayOnToolEvent(listener: (eventName: string, eventData: string, sessionId?: string) => Promise<void>): void;
104
+ gatewayEmitToolEvent(eventName: string, eventData: string, sessionId?: string): void;
105
+ gatewayOffToolEvent(listener: (eventName: string, eventData: string, sessionId?: string) => Promise<void>): void;
106
+ gatewayOnFirstToken(listener: (details: FirstTokenEventDetails) => Promise<void>): void;
107
+ gatewayEmitFirstToken(details: FirstTokenEventDetails): void;
108
+ gatewayOffFirstToken(listener: (details: FirstTokenEventDetails) => Promise<void>): void;
109
+ }
110
+ export declare class MockEventBusService extends EventBusService {
111
+ constructor();
112
+ gatewayEmitConnectionStateChange(_state: ConnectionState): void;
113
+ gatewayEmitMessage(agentInteraction: Interaction, _messageDetails?: MergeResult): void;
114
+ gatewayEmitTurnComplete(_interactionId: string, _agentInteraction: Interaction): void;
115
+ gatewayEmitTurnOpen(_interactionId: string): void;
116
+ gatewayEmitFunctionResponse(_functionDetails: FunctionDetails): void;
117
+ gatewayOnFunctionResponse(listener: (...args: any[]) => Promise<void>): void;
118
+ gatewayOffFunctionResponse(listener: (...args: any[]) => Promise<void>): void;
119
+ }
@@ -0,0 +1,25 @@
1
+ import { Artifact } from '../models/Artifact';
2
+ import { IArtifactService } from './interfaces/artifactService';
3
+ /**
4
+ * Minimal IArtifactService for the replay demo. The replay path doesn't
5
+ * generate artifacts — every persisted FunctionResultContent carries its
6
+ * own payload — so most operations are in-memory pass-throughs. Hosts
7
+ * that need full artifact handling supply their own implementation.
8
+ */
9
+ export declare class HttpArtifactService implements IArtifactService {
10
+ private cache;
11
+ private serverBaseUrl;
12
+ private accessToken;
13
+ constructor(serverBaseUrl: string, accessToken: string);
14
+ private get headers();
15
+ init(): Promise<void>;
16
+ getArtifacts(): Artifact[];
17
+ saveArtifact(artifact: Artifact): Promise<void>;
18
+ saveArtifactToCache(artifact: Artifact): void;
19
+ deleteArtifact(artifactId: string): Promise<void>;
20
+ addToCache(artifact: Artifact): void;
21
+ getArtifactWithCache(artifactId: string): Artifact | null;
22
+ getArtifact(artifactId: string, _useCache?: boolean): Promise<Artifact | null>;
23
+ clearAllArtifacts(): Promise<void>;
24
+ getFileContent(url: string): Promise<string | null>;
25
+ }
@@ -0,0 +1,31 @@
1
+ import { ChatSession, Customer, ISessionService } from '..';
2
+ /**
3
+ * Minimal ISessionService over the WSServer's REST `/sessions` endpoints.
4
+ *
5
+ * Reads from the unified `Sessions` collection. The list endpoint returns
6
+ * header projections; the detail endpoint returns header + the raw
7
+ * `LlmEvent[]` log which we replay through `decodeSessionEvents` to rebuild
8
+ * the chat UI's `Interaction[]`. Mutation methods are no-ops — write paths
9
+ * are exercised by the live agent turn loop and the WS connection, not by
10
+ * REST calls from the picker.
11
+ */
12
+ export declare class HttpSessionService implements ISessionService {
13
+ private serverBaseUrl;
14
+ private accessToken;
15
+ constructor(serverBaseUrl: string, accessToken: string);
16
+ private get headers();
17
+ getAllSessions(): Promise<ChatSession[]>;
18
+ retrieveSession(sessionId: string): Promise<ChatSession | null>;
19
+ getLastUsedSession(): Promise<ChatSession | null>;
20
+ removeSession(sessionId: string): Promise<void>;
21
+ createSession(_sessionId: string, _agentName: string, _customer?: Customer): Promise<ChatSession | null>;
22
+ createAgentSession(): Promise<any>;
23
+ closeSession(_sessionId: string): Promise<void>;
24
+ generateOverviewForCurrentSession(_sys: string, _model: string): Promise<string | null>;
25
+ storeSession(session: ChatSession): Promise<any>;
26
+ patchSession(sessionId: string, partial: Partial<ChatSession>): Promise<void>;
27
+ delayedPatchActiveSession(_partial: Partial<ChatSession>): void;
28
+ patchActiveSession(_partial: Partial<ChatSession>): Promise<ChatSession | null>;
29
+ getLlmSessionInformation(): Promise<any>;
30
+ transformIntoInstances(session: ChatSession): ChatSession;
31
+ }
@@ -0,0 +1,16 @@
1
+ export type { ISessionService } from './servers/sessionService/ISessionService';
2
+ export type { IArtifactService } from './interfaces/artifactService';
3
+ export type { IStorageService } from './storageService';
4
+ export { LocalStorageService } from './storageService';
5
+ export { EventBusService } from './eventBusService';
6
+ export type { FirstTokenEventDetails } from './eventBusService';
7
+ export { AgentGatewayService } from './servers/AgentGatewayService';
8
+ export type { GatewaySendMessageOptions } from './servers/AgentGatewayService';
9
+ export { AgentGatewayWSAsync } from './servers/AgentGatewayWSAsync';
10
+ export { WebSocketConnecionV2 } from './WebSocketConnection/WebSocketConnectionV2';
11
+ export type { IWebSocketConnection, IMessage } from './WebSocketConnection/webSocketConnection';
12
+ export { ArtifactHtmlHandler } from './artifactHtmlHandler';
13
+ export { InteractionService } from './interactionService';
14
+ export { decodeSessionEvents } from './sessionEventDecoder';
15
+ export { HttpSessionService } from './httpSessionService';
16
+ export { HttpArtifactService } from './httpArtifactService';
@@ -0,0 +1,28 @@
1
+ import { MergeResult, Interaction } from '../models/Interaction';
2
+ import { InteractionPart } from '../models/InteractionPart';
3
+ import { ServerEvent } from '../models/ServerEvent';
4
+ import { EventType } from '../models/enums';
5
+ import { EventBusService } from './eventBusService';
6
+ export type InteractionPartGroupType = 'inline' | 'block';
7
+ export declare const InteractionPartGroupType: {
8
+ readonly inline: "inline";
9
+ readonly block: "block";
10
+ };
11
+ export declare class InteractionPartGroup {
12
+ parts: InteractionPart[];
13
+ isLastGroup: boolean;
14
+ hasThoughts: boolean;
15
+ lastWithThoughts: boolean;
16
+ type: InteractionPartGroupType;
17
+ }
18
+ export declare class InteractionService {
19
+ interaction: Interaction;
20
+ eventBusService: EventBusService;
21
+ constructor(interaction: Interaction, eventBusService: EventBusService);
22
+ expandSubParts(text: string, parentPartId: string): InteractionPart[];
23
+ groupPartsByDisplayType(parts: InteractionPart[], partial?: boolean, showToolCalls?: boolean): InteractionPartGroup[];
24
+ isFunctionCall(eventType: EventType): boolean;
25
+ isFunctionResponse(eventType: EventType): boolean;
26
+ private parseTextIntoParts;
27
+ merge(serverEvent: ServerEvent): MergeResult;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Artifact } from '../../models/Artifact';
2
+ export interface IArtifactService {
3
+ getArtifacts(): Artifact[] | Promise<Artifact[]>;
4
+ saveArtifact(artifact: Artifact): void | Promise<void>;
5
+ saveArtifactToCache(artifact: Artifact): void;
6
+ deleteArtifact(artifactId: string): void | Promise<void>;
7
+ addToCache(artifact: Artifact): void;
8
+ getArtifactWithCache(artifactId: string): Artifact | null;
9
+ getArtifact(artifactId: string, useCache?: boolean): Promise<Artifact | null>;
10
+ clearAllArtifacts(): void | Promise<void>;
11
+ getFileContent(url: string): Promise<string | null>;
12
+ init(): Promise<void>;
13
+ }