@aintela/chat 0.4.37 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/components.js +7213 -6950
  2. package/dist/components.js.map +1 -1
  3. package/dist/hooks.js +1 -1
  4. package/dist/httpArtifactService-EEhF_mp9.js +1744 -0
  5. package/dist/httpArtifactService-EEhF_mp9.js.map +1 -0
  6. package/dist/{httpSessionService-CUujaUo6.js → httpSessionService-wBby4ggl.js} +51 -53
  7. package/dist/httpSessionService-wBby4ggl.js.map +1 -0
  8. package/dist/index.js +248 -240
  9. package/dist/models.js +1 -1
  10. package/dist/{serializer-DX-yGa_k.js → serializer-CC-nM3ig.js} +497 -498
  11. package/dist/serializer-CC-nM3ig.js.map +1 -0
  12. package/dist/services.js +12 -10
  13. package/dist/src/components/AiChat/AiChatContext.d.ts +4 -0
  14. package/dist/src/components/AiChat/AiChatTypes.d.ts +8 -0
  15. package/dist/src/components/AiChat/ChatPane/CrossfadeSlot.d.ts +24 -0
  16. package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +9 -9
  17. package/dist/src/components/AiChat/ChatPane/Message.d.ts +1 -3
  18. package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +9 -8
  19. package/dist/src/components/AiChat/ChatPane/MessageScope.d.ts +32 -0
  20. package/dist/src/components/AiChat/ChatPane/MessageUser.d.ts +0 -1
  21. package/dist/src/components/AiChat/ChatPane/StickyQuestionHeader.d.ts +0 -1
  22. package/dist/src/components/AiChat/ChatPane/groupParts.d.ts +34 -0
  23. package/dist/src/components/AiChat/ChatPane/messageAgentVerbosity.test.d.ts +1 -0
  24. package/dist/src/components/AiChat/ChatPane/parts/ActivityLine.d.ts +9 -0
  25. package/dist/src/components/AiChat/ChatPane/parts/ConnectionOutagePart.d.ts +9 -0
  26. package/dist/src/components/AiChat/ChatPane/parts/connectionOutagePart.test.d.ts +1 -0
  27. package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +4 -1
  28. package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +25 -5
  29. package/dist/src/components/AiChat/ChatPane/reasoningHeadlines.d.ts +4 -9
  30. package/dist/src/components/AiChat/ChatPane/verbosity.d.ts +57 -0
  31. package/dist/src/components/AiChat/sessionStateManagerService.d.ts +36 -35
  32. package/dist/src/components/AiChat/stateConfiguration.d.ts +18 -0
  33. package/dist/src/components/index.d.ts +10 -4
  34. package/dist/src/components/v2/VerbositySlider.d.ts +12 -0
  35. package/dist/src/interfaces/index.d.ts +0 -1
  36. package/dist/src/models/Interaction.d.ts +0 -9
  37. package/dist/src/models/InteractionPart.d.ts +4 -3
  38. package/dist/src/models/Notification.d.ts +7 -1
  39. package/dist/src/models/ServerEvent.d.ts +4 -0
  40. package/dist/src/models/index.d.ts +1 -1
  41. package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +28 -108
  42. package/dist/src/services/WebSocketConnection/closeCodes.d.ts +24 -0
  43. package/dist/src/services/WebSocketConnection/streamStats.d.ts +41 -0
  44. package/dist/src/services/WebSocketConnection/streamStats.test.d.ts +1 -0
  45. package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +15 -12
  46. package/dist/src/services/eventBusService.d.ts +28 -67
  47. package/dist/src/services/index.d.ts +2 -1
  48. package/dist/src/services/interaction/reduceInteraction.d.ts +28 -0
  49. package/dist/src/services/interactionService.d.ts +15 -32
  50. package/dist/src/services/interactionService.invariants.test.d.ts +1 -0
  51. package/dist/src/services/servers/AgentGatewayService.d.ts +3 -182
  52. package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +145 -46
  53. package/dist/src/services/servers/connectionSupervisor.d.ts +173 -0
  54. package/dist/src/services/servers/connectionSupervisor.test.d.ts +1 -0
  55. package/dist/src/services/servers/connectionSupervisor.wire.test.d.ts +0 -0
  56. package/dist/src/services/servers/gatewayErrorClosesTurn.test.d.ts +1 -0
  57. package/dist/src/services/servers/gatewayFixes.test.d.ts +1 -0
  58. package/dist/src/services/servers/throttledEmit.test.d.ts +1 -0
  59. package/dist/src/services/servers/throttledEmitter.d.ts +38 -0
  60. package/dist/src/services/streamPipeline.characterization.test.d.ts +1 -0
  61. package/dist/src/services/wire/decodeFrame.d.ts +21 -0
  62. package/dist/src/services/wire/decodeFrame.test.d.ts +1 -0
  63. package/dist/tests/bench/streamPipeline.bench.d.ts +1 -0
  64. package/dist/tests/fakes/fakeRawWebSocket.d.ts +2 -0
  65. package/dist/tests/fakes/fakeWebSocket.d.ts +4 -3
  66. package/dist/tests/fakes/makeGateway.d.ts +7 -0
  67. package/dist/tests/wire/journey.d.ts +47 -0
  68. package/dist/{useChatSessions-BXYvvd4S.js → useChatSessions-C6sYF4U6.js} +2 -2
  69. package/dist/{useChatSessions-BXYvvd4S.js.map → useChatSessions-C6sYF4U6.js.map} +1 -1
  70. package/package.json +2 -1
  71. package/dist/httpArtifactService-GdGsaFKS.js +0 -1979
  72. package/dist/httpArtifactService-GdGsaFKS.js.map +0 -1
  73. package/dist/httpSessionService-CUujaUo6.js.map +0 -1
  74. package/dist/serializer-DX-yGa_k.js.map +0 -1
  75. package/dist/src/interfaces/IHeartbeatPort.d.ts +0 -4
  76. /package/dist/src/components/AiChat/{sessionStateManagerService.idle.test.d.ts → ChatPane/crossfadeSlot.test.d.ts} +0 -0
  77. /package/dist/src/{services/interactionServiceGrouping.test.d.ts → components/AiChat/ChatPane/groupParts.test.d.ts} +0 -0
@@ -8,6 +8,7 @@ import { default as WaitingPart } from './WaitingPart';
8
8
  import { default as SuspendedPart } from './SuspendedPart';
9
9
  import { default as BoxedPart } from './BoxedPart';
10
10
  import { default as ServerErrorPart } from './ServerErrorPart';
11
+ import { default as ActivityLine } from './ActivityLine';
11
12
  export declare const DEFAULT_PART_RENDERERS: Record<PartKind, PartRenderer>;
12
13
  /**
13
14
  * Maps an `InteractionPart` to the kind of renderer that should handle it.
@@ -22,7 +23,9 @@ export declare const DEFAULT_PART_RENDERERS: Record<PartKind, PartRenderer>;
22
23
  export declare function classifyPart(part: InteractionPart): PartKind | null;
23
24
  export * from './types';
24
25
  export * from './uiToolRegistry';
25
- export { TextPart, ThoughtPart, ThoughtRun, FunctionPart, WaitingPart, SuspendedPart, BoxedPart, ServerErrorPart };
26
+ export { TextPart, ThoughtPart, ThoughtRun, FunctionPart, WaitingPart, SuspendedPart, BoxedPart, ServerErrorPart, ActivityLine };
27
+ /** The built-in `activity` renderer (the `minimum` verbosity's slim line); a host overrides it with `partRenderers.activity`. */
28
+ export declare const DEFAULT_ACTIVITY_RENDERER: import('react').FC<import('./types').ActivityRendererProps>;
26
29
  export type { ThoughtRunProps } from './ThoughtRun';
27
30
  export { ThoughtRunContext, useThoughtRun } from './ThoughtRunContext';
28
31
  export type { ThoughtRunState } from './ThoughtRunContext';
@@ -2,18 +2,38 @@ import { default as React } from 'react';
2
2
  import { InteractionPart } from '../../../../models/InteractionPart';
3
3
  import { Interaction } from '../../../../models/Interaction';
4
4
  import { FunctionDetails } from '../../../../models/ServerEvent';
5
+ import { VerbosityActivity } from '../verbosity';
5
6
  export type PartKind = 'text' | 'thought' | 'function' | 'waiting' | 'suspended' | 'boxed' | 'serverError' | 'uiTool' | 'askUser' | 'askAuth';
7
+ /**
8
+ * What a part renderer is handed: the part, the message it belongs to, and its
9
+ * place in its group. Whether the turn is live, whether the host is in friendly
10
+ * mode and where links go are the same for every part of a message, so they come
11
+ * from the enclosing {@link MessageScope} (`useMessageScope()`) instead.
12
+ */
6
13
  export interface PartRendererProps {
7
14
  part: InteractionPart;
8
15
  message: Interaction;
9
- onGoing: boolean;
10
- preview: boolean;
11
16
  isLastInlineInGroup?: boolean;
12
- friendlyMode?: boolean;
13
- onLinkClicked: (link: string, content: string | null) => void;
14
17
  }
15
18
  export type PartRenderer = React.ComponentType<PartRendererProps>;
16
- export type PartRendererMap = Partial<Record<PartKind, PartRenderer>>;
19
+ /**
20
+ * What the `activity` renderer is handed: the `minimum` verbosity's one-line view of a live turn — the running
21
+ * tool calls, or the thought the agent is in with its latest highlight — and the message it belongs to. Friendly
22
+ * mode comes from {@link MessageScope}, as for the part renderers.
23
+ */
24
+ export interface ActivityRendererProps {
25
+ activity: VerbosityActivity;
26
+ message: Interaction;
27
+ }
28
+ export type ActivityRenderer = React.ComponentType<ActivityRendererProps>;
29
+ /**
30
+ * Per-kind renderer overrides (`<AiChat partRenderers={...} />`). `activity` is not a part kind — no single part
31
+ * classifies to it — but the slim line it draws stands in for the tool-call and thought parts under the `minimum`
32
+ * verbosity, so a host customizes it the same way, in the same map.
33
+ */
34
+ export type PartRendererMap = Partial<Record<PartKind, PartRenderer>> & {
35
+ activity?: ActivityRenderer;
36
+ };
17
37
  /**
18
38
  * Match the ask_user tool by function name across connectors. The programmed
19
39
  * path emits the bare `ask_user`; live LLM connectors qualify it as
@@ -1,16 +1,11 @@
1
1
  import { InteractionPart } from '../../../models/InteractionPart';
2
2
  /**
3
- * The tool event an agents server before the StreamingThoughtHighlightContent part emitted for each highlight. Still
4
- * read so a session recorded by such a server, or a server not yet upgraded, keeps its trail.
5
- */
6
- export declare const REASONING_HEADLINE_EVENT = "reasoningHeadline";
7
- /**
8
- * The reasoning headlines of each thought, in order of the thoughts. A thought is the run of Thought, ThoughtHighlight
9
- * (and legacy ToolEvent) parts between two parts of any other kind (text, a function call…); its trail is the
10
- * highlights inside it, each once. Pure, so it is testable without a DOM.
3
+ * The reasoning headlines of each thought, in order of the thoughts. A thought is the run of Thought and
4
+ * ThoughtHighlight parts between two parts of any other kind (text, a function call…); its trail is the highlights
5
+ * inside it, each once. Tool events are transparent — they never render as parts, so they split nothing here
6
+ * either. Pure, so it is testable without a DOM.
11
7
  */
12
8
  export declare function reasoningHeadlineTrails(parts: InteractionPart[]): string[][];
13
- export declare function headlineText(raw: string): string | undefined;
14
9
  /** The prefix every action headline is written with ("Vou precisar buscar os voos"). */
15
10
  export declare const ACTION_PREFIX = "Vou precisar ";
16
11
  /**
@@ -0,0 +1,57 @@
1
+ import { InteractionPart } from '../../../models/InteractionPart';
2
+ /**
3
+ * How much of the agent's internals (reasoning and tool calls) the transcript shows (issue #1524).
4
+ *
5
+ * - `naked` — none of it, live or closed. The answer and the UI tools only.
6
+ * - `minimum` — while the turn is open, ONE italic line: the current reasoning highlight or the running
7
+ * tool(s). Nothing once the turn closes.
8
+ * - `information` — reasoning as in `detailed`; tool calls only while they run (a finished call disappears),
9
+ * the running ones side by side on one line.
10
+ * - `detailed` — everything, the behaviour before the setting existed.
11
+ *
12
+ * UI tools (`isUi`, ask-user) are content, not internals: every level shows them.
13
+ */
14
+ export type ChatVerbosity = 'naked' | 'minimum' | 'information' | 'detailed';
15
+ /** The levels in order, least to most — the menu's bar draws one step per entry. */
16
+ export declare const CHAT_VERBOSITY_LEVELS: readonly {
17
+ value: ChatVerbosity;
18
+ label: string;
19
+ description: string;
20
+ }[];
21
+ /** A tool call that is run internals — a function part that is NOT a UI tool (a cancelled UI render counts as one). */
22
+ export declare function isToolTracePart(p: InteractionPart): boolean;
23
+ /** The call has not returned yet. The runtime turns a finished call's part into a FunctionResponse marked Done. */
24
+ export declare function isRunningCall(p: InteractionPart): boolean;
25
+ /**
26
+ * The `information` level's held call: when the message ENDS in tool calls and none of them is running any more,
27
+ * the last one stays on screen until something else (the next call, a thought, the answer) arrives.
28
+ *
29
+ * Dropping a call the moment it returned left a gap before the next one started: the chip vanished and came
30
+ * back, and the reasoning above it briefly became the message's last group — so it turned live again (open,
31
+ * "Pensando…") and folded on the next call. The run looked like it was blinking. Holding the last call closes
32
+ * the gap: the slot under the reasoning is never empty while the agent is between two calls.
33
+ */
34
+ export declare function heldTraceCall(parts: InteractionPart[]): InteractionPart | undefined;
35
+ /**
36
+ * The verbosity's cut, before the host's other visibility rules. Returns `undefined` when the level has no
37
+ * opinion about the part (the existing rules decide), `false` to drop it. `held` is {@link heldTraceCall}'s
38
+ * answer for the same parts.
39
+ */
40
+ export declare function verbosityKeeps(p: InteractionPart, verbosity: ChatVerbosity, live: boolean, held?: InteractionPart): boolean | undefined;
41
+ /** What the `minimum` line says: the running tools, or the thought the agent is in. */
42
+ export type VerbosityActivity = {
43
+ kind: 'tools';
44
+ calls: InteractionPart[];
45
+ } | {
46
+ kind: 'thought';
47
+ headline?: string;
48
+ };
49
+ /**
50
+ * The current activity of a live turn, for the `minimum` line. Running tool calls win (they are what the agent
51
+ * waits on); a message that ends in finished calls keeps the last one ({@link heldTraceCall}) until something
52
+ * follows; otherwise the agent is thinking when the latest part is reasoning, and the line carries that thought's
53
+ * latest highlight. Anything else (the answer streaming) has no line. Pure.
54
+ */
55
+ export declare function currentActivity(parts: InteractionPart[]): VerbosityActivity | null;
56
+ /** The slot key of an activity: a new key is a new item, crossfaded; the same key re-renders in place. */
57
+ export declare function activityKey(activity: VerbosityActivity): string;
@@ -4,39 +4,26 @@ import { SendMessageResponse } from '../../models/SendMessageResponse';
4
4
  import { IArtifactService } from '../../services/interfaces/artifactService';
5
5
  import { AgentGatewayService } from '../../services/servers/AgentGatewayService';
6
6
  import { ISessionService } from '../../services/servers/sessionService/ISessionService';
7
- export declare const WARNING_THRESHOLD = 0.75;
8
- export declare const BASE_MULTIPLIER = 1000;
9
- export declare const IDLE_TIMEOUT: number;
10
- export declare const DEFAULT_WAIT_TIME = 500;
11
- export declare const MAX_RETRY_WAIT = 20000;
12
7
  export interface SessionStateManagerOptions {
13
8
  onSessionEstablished?: (sessionId: string) => void;
14
9
  }
10
+ /**
11
+ * The SESSION side of going live: load the session record over REST, keep the store's session
12
+ * in step with the socket's session, and tell the gateway (and the host) which session it is on.
13
+ *
14
+ * It no longer owns the connection. Until 2026-10-07 this class also ran a 2 s heartbeat that
15
+ * redialled a dropped socket on its own backoff curve and closed idle sessions — the second of
16
+ * two reconnect loops (the transport had the other), and the seam between them is where every
17
+ * reconnect bug lived. The gateway's ConnectionSupervisor is now the one owner of dial, redial,
18
+ * idle close and every `connectionStatus` write; this class binds the record whenever the
19
+ * supervisor reports a connected session, so a session that only came up on the third retry
20
+ * still gets its history and its `onSessionEstablished`.
21
+ */
15
22
  export declare class SessionStateManagerService {
16
- private idleTime;
17
- internalHearBeat: ReturnType<typeof setInterval> | null;
18
- lastConCheck: number;
19
23
  sessionState: AiChatState;
20
24
  agentGatewayService: AgentGatewayService;
21
- paused: boolean;
22
- waitTimeForRetry: number;
23
25
  sessionService: ISessionService;
24
26
  artifactService: IArtifactService;
25
- workingSessionId?: string;
26
- /**
27
- * Set by the first {@link bindAndOpenLiveSession}. The retry loop used to
28
- * gate on `workingContext` being present — i.e. "has anyone armed this
29
- * manager yet?" — so removing that field (issue #59) needs the same latch
30
- * kept explicitly, or a heartbeat could dial a session no host ever asked for.
31
- */
32
- private armed;
33
- /**
34
- * Latch for the "about to idle out" warning: the beat runs every 2s, so an unlatched
35
- * warning would print ~35 times across the last quarter of the window. Reset whenever
36
- * activity brings the session back.
37
- */
38
- private idleWarningLogged;
39
- pendingClosePromise?: Promise<SendMessageResponse | null>;
40
27
  private onSessionEstablished?;
41
28
  constructor(agentGatewayService: AgentGatewayService, sessionService: ISessionService, artifactService: IArtifactService, sessionStore: AiChatStore, options?: SessionStateManagerOptions);
42
29
  /**
@@ -46,18 +33,20 @@ export declare class SessionStateManagerService {
46
33
  * different agent than the one the socket had been sending as.
47
34
  */
48
35
  private get agentContext();
49
- pause(): void;
50
- start(): void;
51
- beat(): void;
52
36
  /** Create a server-side session for the gateway's agent. The agent is NOT a parameter — see {@link agentContext}. */
53
37
  createSession(sessionId: string): Promise<ChatSession>;
54
38
  retrieveSession(sessionId: string): Promise<ChatSession | null>;
39
+ private cacheArtifacts;
55
40
  /**
56
- * Open the socket and bind a session FOR THE GATEWAY'S AGENT. There is
57
- * deliberately no context parameter (issue #59): a caller that could pass
58
- * one could open a conversation as an agent the gateway will never send as,
59
- * which is precisely how a page bound to `expense-agent` ended up talking to
60
- * `booking-flow-agent`.
41
+ * Load the session record and open the socket on it, FOR THE GATEWAY'S AGENT. There is
42
+ * deliberately no context parameter (issue #59): a caller that could pass one could open a
43
+ * conversation as an agent the gateway will never send as, which is precisely how a page
44
+ * bound to `expense-agent` ended up talking to `booking-flow-agent`.
45
+ *
46
+ * Resolves once the first dial succeeds and rejects when it fails; the supervisor keeps
47
+ * redialling in the background either way (see ConnectionSupervisor). The REST load runs as
48
+ * the dial's `prepare` step, so a server that is down for both is retried for both, on one
49
+ * curve, and the record is bound whenever the session finally comes up.
61
50
  *
62
51
  * @param options.resume keep the socket's replay cursor, so the server replays what was
63
52
  * emitted while we were away. Use it when redialling a session the client already holds
@@ -66,7 +55,19 @@ export declare class SessionStateManagerService {
66
55
  bindAndOpenLiveSession(sessionId?: string, options?: {
67
56
  resume?: boolean;
68
57
  }): Promise<void>;
69
- closeLiveConnection(stoneCold?: boolean, closeTurn?: boolean): Promise<void>;
58
+ /** The REST load of an existing session, shown as `loading` in the store while it runs. */
59
+ private loadSessionRecord;
60
+ /**
61
+ * Make the store's session the one the socket is on. A record already bound to this id is left
62
+ * alone; anything else (a fresh session, a record the REST load did not find) gets a
63
+ * placeholder the stream fills in.
64
+ */
65
+ bindSessionRecord(socketSessionId: string): void;
66
+ /**
67
+ * Hang up and stop supervising. `closeTurn` also closes an open turn in the store (the
68
+ * connection toggle in the composer passes false: pausing the socket is not ending the turn).
69
+ */
70
+ closeLiveConnection(closeTurn?: boolean): Promise<SendMessageResponse | null>;
71
+ /** Tear down: the host unmounted or the engine is being disposed. Never throws. */
70
72
  stop(): Promise<void>;
71
- processRetryLoop(_identification?: string): void;
72
73
  }
@@ -36,6 +36,17 @@ export interface SubAgentState {
36
36
  * stuck on "Continuar" between turns.
37
37
  */
38
38
  export type SuspendState = 'idle' | 'suspending' | 'suspended';
39
+ /** See `AiChatState.connectionOutage`. Times are epoch ms. */
40
+ export interface ConnectionOutage {
41
+ /** When the drop was noticed. */
42
+ since: number;
43
+ /** When the next redial fires; null once the supervisor halted. In the past while a dial is in flight. */
44
+ retryAt: number | null;
45
+ /** Consecutive failed attempts so far (1 while waiting for the first redial). */
46
+ attempt: number;
47
+ /** Set when the supervisor gave up: 'attached-elsewhere' | 'session-gone' | 'closed-by-server'. */
48
+ halted: string | null;
49
+ }
39
50
  export interface AiChatState {
40
51
  session: ChatSession | null;
41
52
  sendingMessage: boolean;
@@ -46,6 +57,12 @@ export interface AiChatState {
46
57
  skillLevel: SkillLevel;
47
58
  turnOpen: boolean;
48
59
  suspendState: SuspendState;
60
+ /**
61
+ * A working connection dropped and the supervisor is redialling (or gave up). Null while the
62
+ * socket is up. The live message draws it as a part while a turn is open — the stream is what
63
+ * the outage interrupts — and a host can draw its own affordance from it anywhere.
64
+ */
65
+ connectionOutage: ConnectionOutage | null;
49
66
  statistics?: InteractionStatistics;
50
67
  connectionStatus: ConnectionState;
51
68
  lastToolEvent?: ToolEventDetails;
@@ -66,6 +83,7 @@ export interface AiChatState {
66
83
  setNewMessage: (message: Interaction) => void;
67
84
  setTurnOpen: (status: boolean) => void;
68
85
  setSuspendState: (status: SuspendState) => void;
86
+ setConnectionOutage: (outage: ConnectionOutage | null) => void;
69
87
  setConnectionStatus: (status: ConnectionState) => void;
70
88
  setSubAgentMessage: (subAgentId: string, interaction: Interaction, name?: string) => void;
71
89
  completeSubAgent: (subAgentId: string) => void;
@@ -7,10 +7,12 @@ export { AiChatServiceContext, useAiChatServices, useAiChatSessionStore, } from
7
7
  export { useTurnOpen } from './AiChat/useTurnOpen';
8
8
  export type { AiChatContextState as AiChatServices } from './AiChat/AiChatContext';
9
9
  export type { AiChatProps, AiChatBaseProps, AiChatEngineProps, AiChatHandle, AiChatStyleProps, AiChatDrawerProps, AiChatFloatingProps, ConnectionInformation, AuthPromptContext, } from './AiChat/AiChatTypes';
10
- export type { AiChatState, AiChatStore, SubAgentState } from './AiChat/stateConfiguration';
10
+ export type { AiChatState, AiChatStore, SubAgentState, ConnectionOutage } from './AiChat/stateConfiguration';
11
11
  export { createAiChatStore } from './AiChat/stateConfiguration';
12
12
  export { createAiChatSessionStore } from './AiChat/AiChatSessionStore';
13
- export { SessionStateManagerService, IDLE_TIMEOUT, WARNING_THRESHOLD, } from './AiChat/sessionStateManagerService';
13
+ export { SessionStateManagerService } from './AiChat/sessionStateManagerService';
14
+ export { IDLE_TIMEOUT, WARNING_THRESHOLD, ConnectionSupervisor } from '../services/servers/connectionSupervisor';
15
+ export type { HaltReason } from '../services/servers/connectionSupervisor';
14
16
  export { createAiChatEngine } from './AiChat/aiChatEngine';
15
17
  export type { AiChatEngine, AiChatEngineConfig } from './AiChat/aiChatEngine';
16
18
  export { useAgentEngine, engineKeyFor, getSharedAiChatEngine, disposeSharedAiChatEngine, } from './AiChat/useAgentEngine';
@@ -24,8 +26,10 @@ export { useParkedAskUser, ASK_USER_CANCELLED } from './AiChat/ChatPane/useParke
24
26
  export type { ParkedAskUser } from './AiChat/ChatPane/useParkedAskUser';
25
27
  export { configureFriendlyMapping, getFriendlyLabel } from './AiChat/ChatPane/friendlyToolConfig';
26
28
  export type { FriendlyState, FriendlyToolEntry } from './AiChat/ChatPane/friendlyToolConfig';
27
- export { classifyPart, DEFAULT_PART_RENDERERS, TextPart, ThoughtPart, FunctionPart, WaitingPart, SuspendedPart, BoxedPart, UiToolDispatcher, } from './AiChat/ChatPane/parts';
28
- export type { PartKind, PartRendererProps, PartRenderer, PartRendererMap, } from './AiChat/ChatPane/parts';
29
+ export { CHAT_VERBOSITY_LEVELS } from './AiChat/ChatPane/verbosity';
30
+ export type { ChatVerbosity, VerbosityActivity } from './AiChat/ChatPane/verbosity';
31
+ export { classifyPart, DEFAULT_PART_RENDERERS, TextPart, ThoughtPart, FunctionPart, WaitingPart, SuspendedPart, BoxedPart, UiToolDispatcher, ActivityLine, DEFAULT_ACTIVITY_RENDERER, } from './AiChat/ChatPane/parts';
32
+ export type { PartKind, PartRendererProps, PartRenderer, PartRendererMap, ActivityRendererProps, ActivityRenderer, } from './AiChat/ChatPane/parts';
29
33
  export { createUiToolRegistry, parseUiArgs, parseClientOutput } from './AiChat/ChatPane/parts';
30
34
  export type { UiToolRegistry, UiToolRegistryBuilder, UiToolContext, UiToolActionContext, UiToolArgs, UiToolRenderFn, UiToolActionFn, UiToolRenderOptions, UiToolActionOptions, UiToolEntry, UiToolRenderEntry, UiToolActionEntry, UiToolAskUserRenderers, UiToolAskUserQuestionFn, UiToolAskUserResponseFn, UiToolAskUserEntry, } from './AiChat/ChatPane/parts';
31
35
  export { useContainerRectangle } from '../hooks/useContainerWidth';
@@ -43,3 +47,5 @@ export type { TurnAwarePhase } from './Library/turnAwareButtonState';
43
47
  export { LlmResponseRender, LiveJsxBlock, JsxErrorBoundary, EnvironmentProvider, InertEnvironmentProvider, useEnvironment, useEnvironmentOptional, LiveTsxConfigProvider, useLiveTsxMaxCharsForFull, LIVE_TSX_DEFAULT_MAX_CHARS_FOR_FULL, extendModuleRegistry, extendDefaultScope, getDefaultJsxScope, parseContentBlocks, } from './LlmResponseRender';
44
48
  export type { ContentBlock } from './LlmResponseRender';
45
49
  export * from './v2';
50
+ export { MessageScopeProvider, useMessageScope } from './AiChat/ChatPane/MessageScope';
51
+ export type { MessageScope } from './AiChat/ChatPane/MessageScope';
@@ -0,0 +1,12 @@
1
+ import { default as React } from 'react';
2
+ import { ChatVerbosity } from '../AiChat/ChatPane/verbosity';
3
+ interface VerbositySliderProps {
4
+ value: ChatVerbosity;
5
+ onChange: (value: ChatVerbosity) => void;
6
+ }
7
+ /**
8
+ * The verbosity setting as a line with a draggable icon that snaps to the four levels, least (left) to most
9
+ * (right). Clicking a point on the line jumps there; arrow keys step (issue #1524).
10
+ */
11
+ export declare const VerbositySlider: React.FC<VerbositySliderProps>;
12
+ export {};
@@ -1,4 +1,3 @@
1
- export type { IHeartbeatPort } from './IHeartbeatPort';
2
1
  export type { INotificationPort } from './INotificationPort';
3
2
  export * from './memoryService';
4
3
  export * from './schedulingService';
@@ -1,15 +1,6 @@
1
1
  import { TodoList } from './todoListModel';
2
2
  import { Artifact } from './Artifact';
3
3
  import { InteractionPart } from './InteractionPart';
4
- export interface MergeResult {
5
- updatedInteraction: Interaction;
6
- updatedParts: InteractionPart[];
7
- newArtifacts: Partial<Artifact>[] | null;
8
- mainBranch: Interaction | null;
9
- analyticsBranch: Interaction | null;
10
- mainBranchPartsChanged: InteractionPart[] | null;
11
- analyticsBranchPartsChanged: InteractionPart[] | null;
12
- }
13
4
  export interface TurnOpenCloseDetails {
14
5
  stack: string[];
15
6
  turnClosed: boolean;
@@ -17,10 +17,11 @@ export interface InteractionPart {
17
17
  text?: string;
18
18
  hasTask?: boolean;
19
19
  rawDetails?: any;
20
- textLastChunk?: string;
21
- thoughtLastChunk?: string;
22
20
  partial: boolean;
23
- isStillWriting: boolean;
21
+ /** @deprecated Write-only; nothing reads it. Kept optional so hosts' fixtures still compile. Goes in 0.5. */
22
+ textLastChunk?: string;
23
+ /** @deprecated Write-only; nothing reads it. Kept optional so hosts' fixtures still compile. Goes in 0.5. */
24
+ isStillWriting?: boolean;
24
25
  mustPush: boolean;
25
26
  textAppendable: boolean;
26
27
  waitingDetails?: {
@@ -7,7 +7,13 @@ export type NotificationType = 'info' | 'warning' | 'error';
7
7
  * their own connection affordance suppress this one; see `AgentGatewayWSAsync`'s `everConnected`
8
8
  * gate for why it is not raised on the initial dial.
9
9
  */
10
- export type NotificationKind = 'connection-restarting';
10
+ export type NotificationKind = 'connection-restarting'
11
+ /** 4002 — another socket (another tab, usually) holds this session; the supervisor stopped redialling. */
12
+ | 'session-attached-elsewhere'
13
+ /** The server no longer has the session (4004, or it answered a dial with a different id); no redial. */
14
+ | 'session-gone'
15
+ /** The server closed on purpose (1000) or rejected the credentials (1008); no redial. */
16
+ | 'connection-closed';
11
17
  export interface BasicNotification {
12
18
  type: NotificationType;
13
19
  message: string;
@@ -97,6 +97,8 @@ export interface CodeExecutionResultDetails {
97
97
  output?: string;
98
98
  }
99
99
  export declare class ServerEvent {
100
+ /** The call id the SDK puts on its error sentinel (`Event.ServerErrorIdentification`). */
101
+ static readonly SERVER_ERROR_CALL_ID = "Server Error";
100
102
  uniqueId: string;
101
103
  mimeType: string;
102
104
  created: Date;
@@ -132,6 +134,8 @@ export declare class ServerEvent {
132
134
  static createErrorEvent(errorMessage: string, interactionId: string): ServerEvent;
133
135
  static parseFlatPropertiesTypedEvent(event: LlmEvent): ServerEvent;
134
136
  static getPartType(part: KernelContent | StreamingKernelContent): PartType;
137
+ /** True when the event holds the SDK's "Server Error" sentinel call (`Event.GetErrorEvent`). */
138
+ static carriesServerError(event: LlmEvent): boolean;
135
139
  static parseFromTypedEvent(event: LlmEvent): ServerEvent;
136
140
  static createFromThought(interactionId: string, thinkingText: string): ServerEvent;
137
141
  static createFromFunctionName(functionName: string, interactionId: string, callData?: any): ServerEvent;
@@ -1,4 +1,4 @@
1
- export type { Interaction, MergeResult, TurnOpenCloseDetails } from './Interaction';
1
+ export type { Interaction, TurnOpenCloseDetails } from './Interaction';
2
2
  export type { InteractionPart } from './InteractionPart';
3
3
  export { InteractionPartUtils } from './InteractionPart';
4
4
  export type { ChatSession } from './ChatSession';
@@ -1,35 +1,14 @@
1
1
  import { ServerEvent } from '../../models/ServerEvent';
2
2
  import { TypedJSON } from 'typedjson';
3
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
- /**
15
- * Client-local close code used when the heartbeat declares the peer dead. It never
16
- * goes on the wire (there is nobody left to receive it); it reaches `onClose` so a
17
- * consumer can tell a detected dead peer from a server-initiated close. Retryable:
18
- * the inner loop resumes the session with its replay cursor when the channel was
19
- * proven, otherwise the outer state manager takes over as for any other drop.
20
- */
21
- export declare const HEARTBEAT_TIMEOUT_CODE = 4100;
4
+ import { ConnectOptions, IWebSocketConnection, IMessage, IMessageBase } from './webSocketConnection';
5
+ import { APPLICATION_CLOSED_CODE, HEARTBEAT_TIMEOUT_CODE, SESSION_ALREADY_ATTACHED_CODE } from './closeCodes';
6
+ export { APPLICATION_CLOSED_CODE, HEARTBEAT_TIMEOUT_CODE, SESSION_ALREADY_ATTACHED_CODE };
22
7
  export declare class WebSocketConnecionV2 implements IWebSocketConnection {
23
8
  ws: WebSocket | null;
24
- stats: InteractionStatistics;
25
- /**
26
- * Compaction history for the whole CONNECTION, and the previous size reading it
27
- * is derived from. Deliberately not inside `stats`: those are rebuilt on every
28
- * interaction (see emitFirstToken), and a session's compaction history outlives
29
- * any one turn — it is the thing the usage panel plots.
30
- */
31
- private readonly sessionCompactions;
32
- private previousSessionInformation?;
9
+ /** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
10
+ private readonly statsTracker;
11
+ get stats(): InteractionStatistics;
33
12
  baseUrl: string;
34
13
  /**
35
14
  * Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
@@ -43,12 +22,7 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
43
22
  onOpen?: () => void;
44
23
  onFirstToken?: (interactionId: string) => void;
45
24
  onSuspended?: () => void;
46
- onPong?: (sessionId: string) => void;
47
25
  onClose?: (code: number, reason: string) => void;
48
- /** Fired when an unexpected close triggers a reconnect attempt. */
49
- onReconnecting?: (attempt: number, delayMs: number) => void;
50
- /** Fired the first time the socket reopens after an unexpected close. */
51
- onReconnected?: (sessionId: string) => void;
52
26
  /**
53
27
  * Fired when the server signals that we lost streaming events on resume — our
54
28
  * `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
@@ -56,38 +30,17 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
56
30
  */
57
31
  onRewindLost?: (sessionId: string, resumingFromSeq: number) => void;
58
32
  sessionId?: string;
59
- onNewPacket?: (stats: InteractionStatistics) => void;
60
- /**
61
- * Stats can fire dozens of times per second during streaming. We
62
- * coalesce to a fixed cadence so subscribers see steady,
63
- * digestible updates instead of a per-packet firehose — the
64
- * latter caused a "Maximum update depth exceeded" cascade in
65
- * heavy v2 surfaces (RunProgressPanelV2 + StreamStatistics +
66
- * ChatTranscript all subscribed to `statistics` and re-rendered
67
- * on every packet, with their useEffect-driven setStates pushing
68
- * React's nested-update counter past its threshold).
69
- */
70
- private statsFlushTimer;
71
- private statsLastFlushed;
72
- private readonly STATS_FLUSH_MS;
33
+ /** Coalesced stats updates (see StreamStatsTracker.STATS_FLUSH_MS). */
34
+ set onNewPacket(listener: ((stats: InteractionStatistics) => void) | undefined);
35
+ get onNewPacket(): ((stats: InteractionStatistics) => void) | undefined;
73
36
  monitorInterval: NodeJS.Timeout | null;
74
37
  streamingResponseSerializer: TypedJSON<StreamingResponse>;
75
- events: [number, number][];
76
38
  lastActivity: number;
77
39
  /** When the outstanding heartbeat Ping went out; null while no reply is pending. */
78
40
  private pingSentAt;
79
41
  firstTokenInteractions: Set<string>;
80
- /** Last sessionId we successfully had — used to resume on reconnect. */
42
+ /** Last sessionId we successfully had — stamps parked answers, labels log lines. */
81
43
  private lastKnownSessionId?;
82
- /** True when the consumer called `disconnect()` — suppresses auto-reconnect. */
83
- private intentionalDisconnect;
84
- /** Number of reconnect attempts since the last clean open. */
85
- private reconnectAttempts;
86
- private reconnectTimer;
87
- /** True while we are in the middle of an unexpected-close → reconnect cycle. */
88
- private isReconnecting;
89
- /** Internal flag set by `scheduleReconnect` so `connect()` does not reset the backoff state. */
90
- private _internalReconnect;
91
44
  /**
92
45
  * Highest server-assigned `seq` we have observed and processed. The next
93
46
  * reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
@@ -104,51 +57,19 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
104
57
  * the single-attach policy makes it undeliverable from here anyway.
105
58
  */
106
59
  private pendingAnswers;
107
- /**
108
- * True once *any* socket on this instance has received at least one packet.
109
- * Used by `onclose` to distinguish a real mid-stream drop (we had a working
110
- * channel) from a connect attempt that never produced traffic (server down,
111
- * unreachable, etc.). The inner reconnect loop is only meant for the former
112
- * — fresh-connect failures should be handed straight to the outer
113
- * SessionStateManagerService.processRetryLoop instead of being retried
114
- * twice in here. Sticky for the lifetime of this connection instance so
115
- * that internal resume attempts keep their full inner-loop budget even
116
- * when a replacement socket fails before delivering its first message.
117
- * Cleared by `disconnect()`.
118
- */
119
- private hasEverReceivedPacket;
120
60
  constructor(baseUrl?: string, getToken?: () => string | undefined);
121
61
  /**
122
- * Connect to the WebSocket endpoint.
62
+ * Dial the endpoint once. Resolves with the session id the server's first Pong carries;
63
+ * rejects when the socket closes, or times out, before that. A close AFTER the Pong is
64
+ * reported through `onClose` only.
123
65
  *
124
66
  * `options.resume` keeps the replay cursor so the server can send back everything emitted
125
- * while we were away (`?lastSeq=N`). Until it existed, only the socket's OWN
126
- * `scheduleReconnect` could resume: every other caller landed in the "fresh connect" branch
127
- * below, which discards `lastSeq`. A host that redials deliberately — a mobile app coming
128
- * back to the foreground, say — therefore lost every frame emitted while it was suspended,
129
- * silently, because the transcript looked intact right up to the gap.
67
+ * while we were away (`?lastSeq=N`). Without it the dial is fresh and the cursor is dropped:
68
+ * a cursor from one conversation must never be presented to another.
130
69
  */
131
- connect(sessionId?: string, options?: {
132
- resume?: boolean;
133
- }): Promise<string>;
134
- /**
135
- * Returns true when the close code is something we believe a fresh connect
136
- * (with the same sessionId) can recover from. We deliberately do NOT retry
137
- * on:
138
- * - 1000 normal closure
139
- * - 1008 policy violation (auth rejected)
140
- * - 4001 our own intentional disconnect
141
- * - 4002 the session is attached elsewhere (another tab) — retrying just bounces
142
- * Retried, on purpose:
143
- * - 4003 the server's idle close ("reconnect on next interaction"): resuming is
144
- * cheap and lossless, and while the user is present the outer loop would redial
145
- * anyway; when they are gone the client's own idle timer closes first.
146
- * - 4100 HEARTBEAT_TIMEOUT_CODE, our own dead-peer verdict.
147
- */
148
- private shouldAttemptReconnect;
149
- private cancelPendingReconnect;
150
- private computeBackoffDelay;
151
- private scheduleReconnect;
70
+ connect(sessionId?: string, options?: ConnectOptions): Promise<string>;
71
+ /** Drop the current socket without reporting it: handlers off, then close. */
72
+ private detachSocket;
152
73
  sleep(ms: number): Promise<unknown>;
153
74
  /** The session this instance believes it is on — for log lines, never for logic. */
154
75
  private get sessionLabel();
@@ -192,7 +113,6 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
192
113
  */
193
114
  sendMessage(message: IMessage): void;
194
115
  sendBaseMessage(message: IMessageBase): void;
195
- sendSuspendMessage(message: IMessage): void;
196
116
  /**
197
117
  * Heartbeat: keep a quiet socket alive with a Ping every PING_INTERVAL_MS, and
198
118
  * declare it dead when a Ping goes PONG_TIMEOUT_MS without ANY inbound frame.
@@ -203,13 +123,20 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
203
123
  * Send a heartbeat ping and start the reply clock (unless one is already running).
204
124
  */
205
125
  ping(): void;
126
+ /**
127
+ * Behave as if the peer vanished: the socket is closed and reported as an abnormal close (1006),
128
+ * exactly the path the heartbeat's dead-peer verdict takes. For demos and tests of the resume —
129
+ * the supervisor redials with the replay cursor and the server replays what it buffered — on a
130
+ * server that is still running; a real drop needs a cable pulled.
131
+ */
132
+ simulateDrop(): void;
206
133
  /**
207
134
  * Declare the current socket dead and run the close path NOW, without waiting
208
135
  * for the browser: for a half-open peer `onclose` can lag by minutes or never
209
136
  * come, and the decision has already been made. The dead socket's own onclose
210
- * handler is invoked with a client-local code, so the reconnect-vs-handoff
211
- * logic that runs is exactly the one a server close would run. Handlers are
212
- * detached first so a late real close event cannot run it a second time.
137
+ * handler is invoked with a client-local code, so the consumer sees exactly
138
+ * what a server close would have produced. Handlers are detached first so a
139
+ * late real close event cannot run it a second time.
213
140
  */
214
141
  private failSocket;
215
142
  /**
@@ -220,12 +147,5 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
220
147
  * Check if connected
221
148
  */
222
149
  isConnected(): boolean;
223
- /**
224
- * Push the latest stats out to `onNewPacket`, but at most every
225
- * `STATS_FLUSH_MS` ms. Subsequent packets within the window
226
- * schedule a trailing flush so the UI eventually sees the final
227
- * value without each individual packet causing a re-render.
228
- */
229
- private flushStatsCoalesced;
230
150
  handleEvent(llmEvent: LlmEvent, rawData: string): Promise<void>;
231
151
  }