@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.
- package/dist/components.js +7213 -6950
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +1 -1
- package/dist/httpArtifactService-EEhF_mp9.js +1744 -0
- package/dist/httpArtifactService-EEhF_mp9.js.map +1 -0
- package/dist/{httpSessionService-CUujaUo6.js → httpSessionService-wBby4ggl.js} +51 -53
- package/dist/httpSessionService-wBby4ggl.js.map +1 -0
- package/dist/index.js +248 -240
- package/dist/models.js +1 -1
- package/dist/{serializer-DX-yGa_k.js → serializer-CC-nM3ig.js} +497 -498
- package/dist/serializer-CC-nM3ig.js.map +1 -0
- package/dist/services.js +12 -10
- package/dist/src/components/AiChat/AiChatContext.d.ts +4 -0
- package/dist/src/components/AiChat/AiChatTypes.d.ts +8 -0
- package/dist/src/components/AiChat/ChatPane/CrossfadeSlot.d.ts +24 -0
- package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +9 -9
- package/dist/src/components/AiChat/ChatPane/Message.d.ts +1 -3
- package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +9 -8
- package/dist/src/components/AiChat/ChatPane/MessageScope.d.ts +32 -0
- package/dist/src/components/AiChat/ChatPane/MessageUser.d.ts +0 -1
- package/dist/src/components/AiChat/ChatPane/StickyQuestionHeader.d.ts +0 -1
- package/dist/src/components/AiChat/ChatPane/groupParts.d.ts +34 -0
- package/dist/src/components/AiChat/ChatPane/messageAgentVerbosity.test.d.ts +1 -0
- package/dist/src/components/AiChat/ChatPane/parts/ActivityLine.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/parts/ConnectionOutagePart.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/parts/connectionOutagePart.test.d.ts +1 -0
- package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +4 -1
- package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +25 -5
- package/dist/src/components/AiChat/ChatPane/reasoningHeadlines.d.ts +4 -9
- package/dist/src/components/AiChat/ChatPane/verbosity.d.ts +57 -0
- package/dist/src/components/AiChat/sessionStateManagerService.d.ts +36 -35
- package/dist/src/components/AiChat/stateConfiguration.d.ts +18 -0
- package/dist/src/components/index.d.ts +10 -4
- package/dist/src/components/v2/VerbositySlider.d.ts +12 -0
- package/dist/src/interfaces/index.d.ts +0 -1
- package/dist/src/models/Interaction.d.ts +0 -9
- package/dist/src/models/InteractionPart.d.ts +4 -3
- package/dist/src/models/Notification.d.ts +7 -1
- package/dist/src/models/ServerEvent.d.ts +4 -0
- package/dist/src/models/index.d.ts +1 -1
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +28 -108
- package/dist/src/services/WebSocketConnection/closeCodes.d.ts +24 -0
- package/dist/src/services/WebSocketConnection/streamStats.d.ts +41 -0
- package/dist/src/services/WebSocketConnection/streamStats.test.d.ts +1 -0
- package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +15 -12
- package/dist/src/services/eventBusService.d.ts +28 -67
- package/dist/src/services/index.d.ts +2 -1
- package/dist/src/services/interaction/reduceInteraction.d.ts +28 -0
- package/dist/src/services/interactionService.d.ts +15 -32
- package/dist/src/services/interactionService.invariants.test.d.ts +1 -0
- package/dist/src/services/servers/AgentGatewayService.d.ts +3 -182
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +145 -46
- package/dist/src/services/servers/connectionSupervisor.d.ts +173 -0
- package/dist/src/services/servers/connectionSupervisor.test.d.ts +1 -0
- package/dist/src/services/servers/connectionSupervisor.wire.test.d.ts +0 -0
- package/dist/src/services/servers/gatewayErrorClosesTurn.test.d.ts +1 -0
- package/dist/src/services/servers/gatewayFixes.test.d.ts +1 -0
- package/dist/src/services/servers/throttledEmit.test.d.ts +1 -0
- package/dist/src/services/servers/throttledEmitter.d.ts +38 -0
- package/dist/src/services/streamPipeline.characterization.test.d.ts +1 -0
- package/dist/src/services/wire/decodeFrame.d.ts +21 -0
- package/dist/src/services/wire/decodeFrame.test.d.ts +1 -0
- package/dist/tests/bench/streamPipeline.bench.d.ts +1 -0
- package/dist/tests/fakes/fakeRawWebSocket.d.ts +2 -0
- package/dist/tests/fakes/fakeWebSocket.d.ts +4 -3
- package/dist/tests/fakes/makeGateway.d.ts +7 -0
- package/dist/tests/wire/journey.d.ts +47 -0
- package/dist/{useChatSessions-BXYvvd4S.js → useChatSessions-C6sYF4U6.js} +2 -2
- package/dist/{useChatSessions-BXYvvd4S.js.map → useChatSessions-C6sYF4U6.js.map} +1 -1
- package/package.json +2 -1
- package/dist/httpArtifactService-GdGsaFKS.js +0 -1979
- package/dist/httpArtifactService-GdGsaFKS.js.map +0 -1
- package/dist/httpSessionService-CUujaUo6.js.map +0 -1
- package/dist/serializer-DX-yGa_k.js.map +0 -1
- package/dist/src/interfaces/IHeartbeatPort.d.ts +0 -4
- /package/dist/src/components/AiChat/{sessionStateManagerService.idle.test.d.ts → ChatPane/crossfadeSlot.test.d.ts} +0 -0
- /package/dist/src/{services/interactionServiceGrouping.test.d.ts → components/AiChat/ChatPane/groupParts.test.d.ts} +0 -0
|
@@ -1,26 +1,54 @@
|
|
|
1
|
+
import { ServerEvent, ToolEventDetails } from '../../models/ServerEvent';
|
|
1
2
|
import { User, AgentContext } from '../../models/contexts';
|
|
3
|
+
import { Customer } from '../../models/Customer';
|
|
2
4
|
import { ClientMessage } from '../../models/ClientMessage';
|
|
3
|
-
import { AgentGatewayService, GatewaySendMessageOptions } from './AgentGatewayService';
|
|
4
5
|
import { Interaction } from '../../models/Interaction';
|
|
5
6
|
import { EventBusService } from '../eventBusService';
|
|
6
|
-
import {
|
|
7
|
+
import { InteractionService } from '../interactionService';
|
|
8
|
+
import { InteractionPart } from '../../models/InteractionPart';
|
|
9
|
+
import { SendMessageResponse } from '../../models/SendMessageResponse';
|
|
7
10
|
import { IArtifactService } from '../interfaces/artifactService';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
11
|
+
import { Artifact } from '../../models/Artifact';
|
|
12
|
+
import { AiChatState, AiChatStore } from '../../components/AiChat/stateConfiguration';
|
|
10
13
|
import { INotificationPort } from '../../interfaces/INotificationPort';
|
|
11
|
-
import { ConnectionState } from '../../models/connectionState';
|
|
12
|
-
import { AiChatStore } from '../../components/AiChat/stateConfiguration';
|
|
13
|
-
import { IWebSocketConnection } from '../WebSocketConnection/webSocketConnection';
|
|
14
14
|
import { IStorageService } from '../storageService';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
import { HaltReason, OpenOptions } from './connectionSupervisor';
|
|
16
|
+
import { IWebSocketConnection } from '../WebSocketConnection/webSocketConnection';
|
|
17
|
+
export interface GatewaySendMessageOptions {
|
|
18
|
+
callId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The agent gateway: owns the live session's interactions, turns server events
|
|
22
|
+
* into interaction trees (through {@link InteractionService} and the reducer),
|
|
23
|
+
* publishes the live message to the store at a bounded cadence, and sends the
|
|
24
|
+
* user's turns over the socket.
|
|
25
|
+
*
|
|
26
|
+
* One class. It was an abstract base plus this subclass for an SSE transport
|
|
27
|
+
* that no longer exists; `AgentGatewayService` still resolves to this class for
|
|
28
|
+
* hosts and the context types.
|
|
29
|
+
*/
|
|
30
|
+
export declare class AgentGatewayWSAsync {
|
|
31
|
+
base_url: string;
|
|
32
|
+
msg_order: number;
|
|
33
|
+
protected interactionsMap: Map<string, Interaction>;
|
|
34
|
+
protected interactionsServiceMap: Map<string, InteractionService>;
|
|
35
|
+
protected user: User;
|
|
36
|
+
protected config: AgentContext;
|
|
37
|
+
protected currentIS: InteractionService | null;
|
|
38
|
+
protected sessionState: AiChatState;
|
|
39
|
+
protected storageService: IStorageService;
|
|
40
|
+
protected notificationPort: INotificationPort;
|
|
41
|
+
protected interactionCallIds: Map<string, string>;
|
|
42
|
+
/** Interactions whose turn was committed (turn-complete or a server error); a second close is ignored. */
|
|
43
|
+
protected committedTurns: Set<string>;
|
|
44
|
+
protected rawJwt: string;
|
|
45
|
+
protected sessionId?: string;
|
|
46
|
+
eventBusService: EventBusService;
|
|
47
|
+
artifactService: IArtifactService;
|
|
20
48
|
protected wsService: IWebSocketConnection;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
49
|
+
/** The one owner of dial / redial / idle close / connection status. See ConnectionSupervisor. */
|
|
50
|
+
private readonly connection;
|
|
51
|
+
suspendState: boolean;
|
|
24
52
|
/**
|
|
25
53
|
* True once a WS has successfully opened at least once in this gateway's
|
|
26
54
|
* lifetime. Gates the "Reiniciando a conexão" toast: a drop of a working
|
|
@@ -28,33 +56,95 @@ export declare class AgentGatewayWSAsync extends AgentGatewayService {
|
|
|
28
56
|
* (the Connecting state already covers it).
|
|
29
57
|
*/
|
|
30
58
|
private everConnected;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
private static readonly CURRENT_MSG_THROTTLE_MS;
|
|
60
|
+
/**
|
|
61
|
+
* How long an open turn survives a connection outage. While the supervisor is redialling the
|
|
62
|
+
* turn stays open — a short blip resumes it from the replay cursor, and a server that comes back
|
|
63
|
+
* (or another instance) closes it with an error if its run is gone. Past this, nobody can tell
|
|
64
|
+
* us anything, and a turn that is still open is a composer that is still locked: the client
|
|
65
|
+
* closes it itself, with an error part, so the user can go on.
|
|
66
|
+
*/
|
|
67
|
+
static readonly OUTAGE_CLOSES_TURN_AFTER_MS = 60000;
|
|
68
|
+
static readonly OUTAGE_TURN_MESSAGE = "Sem conex\u00E3o com o servidor h\u00E1 mais de um minuto. A resposta foi interrompida.";
|
|
69
|
+
/** What a send reports when the socket could not be brought up for it. */
|
|
70
|
+
static readonly NO_CONNECTION_MESSAGE = "N\u00E3o foi poss\u00EDvel obter conex\u00E3o com o servidor";
|
|
71
|
+
static readonly HALT_TURN_MESSAGE: Record<HaltReason, string>;
|
|
72
|
+
/** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
|
|
73
|
+
private readonly liveMessage;
|
|
74
|
+
constructor(user: User, eventBusService: EventBusService, artifactService: IArtifactService, baseUrl: string, config: AgentContext, sessionStore: AiChatStore, notificationPort: INotificationPort, ws: IWebSocketConnection, storageService: IStorageService, sessionId?: string);
|
|
39
75
|
/**
|
|
40
|
-
*
|
|
76
|
+
* The turn the user is waiting on will not continue: close it from the client side with an error
|
|
77
|
+
* part, the same way a server error would. No-op when no turn is open.
|
|
78
|
+
*/
|
|
79
|
+
private closeOpenTurnWith;
|
|
80
|
+
/** The supervisor gave up on its own (another tab holds the session, the session is gone, …): tell the user. */
|
|
81
|
+
private notifyHalt;
|
|
82
|
+
/**
|
|
83
|
+
* The agent this gateway speaks to — the ONE truth for the conversation.
|
|
84
|
+
* `sendMessageInternal` stamps every outbound frame's `AgentId` from it,
|
|
85
|
+
* and the session manager binds/rebinds against it. Fixed at construction;
|
|
86
|
+
* see {@link forceAgentContext} for the single exception (issue #59).
|
|
87
|
+
*/
|
|
88
|
+
getAgentContext(): AgentContext;
|
|
89
|
+
getModel(): string | undefined;
|
|
90
|
+
setModel(modelId: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Live update for the ordinary, non-identity slice of the context — the
|
|
93
|
+
* dataset/customer the same agent works over. No "force" needed: swapping
|
|
94
|
+
* datasets mid-conversation is routine and changes nothing about who is
|
|
95
|
+
* answering.
|
|
96
|
+
*/
|
|
97
|
+
setCustomer(customer: Customer): void;
|
|
98
|
+
/**
|
|
99
|
+
* Replace the AGENT mid-conversation. The escape hatch for an agent picker,
|
|
100
|
+
* and nothing else: the session already holds another agent's history, and
|
|
101
|
+
* the server stamps `Session.AgentId` on the first turn only — so the
|
|
102
|
+
* conversation keeps reporting the agent it STARTED as, however many times
|
|
103
|
+
* this is called. Prefer a new engine (new key, see `engineKeyFor`) per
|
|
104
|
+
* agent.
|
|
41
105
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
106
|
+
* Callers pass the FULL replacement context (the same shape the gateway was
|
|
107
|
+
* constructed with). The `model` slice is preserved when the incoming
|
|
108
|
+
* context omits it — the model is owned separately by {@link setModel} and
|
|
109
|
+
* must not be clobbered by an agent-only change.
|
|
45
110
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
111
|
+
forceAgentContext(config: AgentContext): void;
|
|
112
|
+
getSessionId(): string | undefined;
|
|
113
|
+
setSession(sessionId: string, _toolSessionId?: string): void;
|
|
114
|
+
startInteraction(interactionQuestion: string, wasSuspended?: boolean | undefined, idOverrideForTests?: string): Interaction;
|
|
115
|
+
getInteractions(): Interaction[];
|
|
116
|
+
getCurrentInteractionId(): string | null;
|
|
117
|
+
getCurrentInteraction(): Interaction | null;
|
|
118
|
+
protected updateMap(serverEvent: ServerEvent): Interaction | undefined;
|
|
119
|
+
protected getNewInteractionId(): string;
|
|
120
|
+
Message(event: MessageEvent | ServerEvent): Promise<void>;
|
|
121
|
+
protected subAgentInteractions: Map<string, Interaction>;
|
|
122
|
+
protected subAgentInteractionServices: Map<string, InteractionService>;
|
|
123
|
+
protected getOrCreateSubAgentInteraction(subAgentId: string, interactionId: string, subAgentName?: string): {
|
|
124
|
+
interaction: Interaction;
|
|
125
|
+
service: InteractionService;
|
|
126
|
+
};
|
|
127
|
+
protected handleSubAgentEvent(serverEvent: ServerEvent): void;
|
|
128
|
+
protected localEmitToolEvent(toolDetails: ToolEventDetails): void;
|
|
129
|
+
protected registerInteractionCallId(interactionId: string, options?: GatewaySendMessageOptions): void;
|
|
130
|
+
protected localEmitFirstToken(interactionId: string): void;
|
|
131
|
+
protected localEmitMessage(message: Interaction): void;
|
|
132
|
+
protected localOpen(interactionId: string, _author: string): void;
|
|
133
|
+
protected turnComplete(interactionId: string, agentInteraction: Interaction, _author: string, subAgentId?: string): Promise<void>;
|
|
134
|
+
runningRequests: Map<string, Promise<Artifact | null>>;
|
|
135
|
+
asyncLoadArtifact(artifactId: string): Promise<Artifact | null>;
|
|
136
|
+
/**
|
|
137
|
+
* Be on `sessionId` (a fresh session when undefined). Resolves with the session id once the
|
|
138
|
+
* first dial succeeds and rejects when it fails; the supervisor keeps redialling in the
|
|
139
|
+
* background either way, with the replay cursor, until {@link closeConnection}. Concurrent
|
|
140
|
+
* callers for the same session share the dial in flight. See ConnectionSupervisor for the
|
|
141
|
+
* backoff, the idle close and the close-code policy — and for the rule that a requested
|
|
142
|
+
* session is never swapped for another.
|
|
143
|
+
*/
|
|
144
|
+
openConnection(sessionId?: string, options?: OpenOptions): Promise<string>;
|
|
54
145
|
closeConnection(closeTurn?: boolean): Promise<SendMessageResponse | null>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
streamOpened: boolean;
|
|
146
|
+
/** Hang up and stop supervising the connection. `closeTurn` also closes an open turn in the store. */
|
|
147
|
+
stopStream(closeTurn?: boolean): void;
|
|
58
148
|
/**
|
|
59
149
|
* Make sure the socket is OPEN before a send, redialling the SAME session when it is not.
|
|
60
150
|
*
|
|
@@ -62,14 +152,23 @@ export declare class AgentGatewayWSAsync extends AgentGatewayService {
|
|
|
62
152
|
* idle close (5 min without input), the server's (6 min without a message, code 4003), a dead
|
|
63
153
|
* peer the heartbeat just detected, or a dial still in flight. Until this existed the send
|
|
64
154
|
* threw `WebSocket is not connected` AFTER the user's turn was already on the transcript — or
|
|
65
|
-
* the composer refused it outright
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* `resume: true` keeps the replay cursor: if the socket died mid-turn the server replays what
|
|
69
|
-
* we missed. `openConnection` de-duplicates against a dial already in flight (the state
|
|
70
|
-
* manager's retry loop, a host's own bind), so concurrent callers share one socket. A
|
|
71
|
-
* transport without `isConnected` semantics (the demo's fake gateway) is treated as up.
|
|
155
|
+
* the composer refused it outright. A send IS the activity that reconnect was waiting for, so
|
|
156
|
+
* the supervisor dials now rather than at its next scheduled retry, replay cursor kept.
|
|
72
157
|
*/
|
|
73
158
|
private ensureConnected;
|
|
74
|
-
|
|
159
|
+
sendMessage(message: ClientMessage, options?: GatewaySendMessageOptions): Promise<SendMessageResponse>;
|
|
160
|
+
sendMessageInternal(message: ClientMessage, options?: GatewaySendMessageOptions): Promise<SendMessageResponse>;
|
|
161
|
+
sendStatusMessage(question: string, parts: InteractionPart[], interactionId: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Send the user's answer to a parked `ask_user` tool call back to the agent, as a
|
|
164
|
+
* ChatAction.AnswerHumanTool frame. 'sent' when it went out immediately, 'queued' when the
|
|
165
|
+
* socket was down and the answer will flush on reconnect.
|
|
166
|
+
*
|
|
167
|
+
* Feature-detected rather than cast: a host may supply any `IWebSocketConnection` (the demo's fake
|
|
168
|
+
* gateway does), and a hard cast turned "this transport doesn't deliver answers" into a TypeError
|
|
169
|
+
* thrown from a click handler — with the answer lost either way.
|
|
170
|
+
*/
|
|
171
|
+
answerHumanTool(toolCallId: string, answer: string): 'sent' | 'queued';
|
|
172
|
+
suspend(): Promise<boolean>;
|
|
173
|
+
sleep(ms: number): Promise<unknown>;
|
|
75
174
|
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { AiChatStore } from '../../components/AiChat/stateConfiguration';
|
|
2
|
+
/**
|
|
3
|
+
* The ONE owner of the live connection's lifecycle.
|
|
4
|
+
*
|
|
5
|
+
* Until 2026-10-07 two loops shared this job: the transport redialled a dropped socket twice
|
|
6
|
+
* on its own (500 ms, 1 s), then "handed off" to `SessionStateManagerService`, whose 2 s
|
|
7
|
+
* heartbeat redialled on a slower curve, closed idle sessions and wrote the store. The seam
|
|
8
|
+
* between them is where every reconnect bug lived — budgets reset by an upgrade that was not a
|
|
9
|
+
* connection, an outer redial buying two inner ones, two timers tearing down each other's
|
|
10
|
+
* sockets. Now the transport dials once and reports how it ended; this class decides what
|
|
11
|
+
* happens next.
|
|
12
|
+
*
|
|
13
|
+
* What it owns:
|
|
14
|
+
* - dialling (one in flight at a time) and the resume cursor (every redial of a known session
|
|
15
|
+
* asks the transport to keep it, so the server replays what was missed);
|
|
16
|
+
* - ONE backoff curve for every failure, server down or session dropped alike;
|
|
17
|
+
* - the close-code policy (see {@link ConnectionSupervisor.transportClosed});
|
|
18
|
+
* - the idle close: the store's `lastActivity` is fed by human input and by sends, a streaming
|
|
19
|
+
* turn refreshes it, and {@link IDLE_TIMEOUT} without it closes the socket until activity
|
|
20
|
+
* returns;
|
|
21
|
+
* - every `connectionStatus` write to the store.
|
|
22
|
+
*
|
|
23
|
+
* What it refuses to do: swap a session. A target with a session id is that session; if the
|
|
24
|
+
* server answers a dial with another id, or says the session is gone, the supervisor halts and
|
|
25
|
+
* tells the host instead of quietly starting a new conversation. Only a dial with NO id starts
|
|
26
|
+
* fresh, and from its first success on, that id is the target too.
|
|
27
|
+
*/
|
|
28
|
+
/** First retry delay. The curve is w ← min(⌊w + w²/BASE⌋, MAX): 500, 750, 1312, 3033, 12232, 20000, 20000… */
|
|
29
|
+
export declare const RETRY_INITIAL_WAIT_MS = 500;
|
|
30
|
+
export declare const RETRY_MAX_WAIT_MS = 20000;
|
|
31
|
+
export declare const RETRY_BASE_MULTIPLIER = 1000;
|
|
32
|
+
/** ±20 % on every retry delay, so a server restart does not get every tab back at the same millisecond. */
|
|
33
|
+
export declare const RETRY_JITTER = 0.2;
|
|
34
|
+
export declare const IDLE_TIMEOUT: number;
|
|
35
|
+
/** The fraction of {@link IDLE_TIMEOUT} after which the UI shows the countdown (and the console says so once). */
|
|
36
|
+
export declare const WARNING_THRESHOLD = 0.75;
|
|
37
|
+
export declare const IDLE_TICK_MS = 2000;
|
|
38
|
+
/** Why the supervisor stopped retrying on its own. An explicit `open()` clears it. */
|
|
39
|
+
export type HaltReason =
|
|
40
|
+
/** 4002 — another socket (a second tab, usually) holds this session. Retrying would only bounce. */
|
|
41
|
+
'attached-elsewhere'
|
|
42
|
+
/** The server closed with 4004, or answered a dial for session A with session B: A is gone. */
|
|
43
|
+
| 'session-gone'
|
|
44
|
+
/** 1000 / 1008 — the server ended the conversation on purpose, or rejected our credentials. */
|
|
45
|
+
| 'closed-by-server';
|
|
46
|
+
export interface ConnectionTarget {
|
|
47
|
+
/** The session to be on. Undefined only until the first fresh dial succeeds. */
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the NEXT dial keeps the transport's replay cursor. Set by the caller for the first
|
|
51
|
+
* dial (a host returning to the foreground), always true for the supervisor's own redials.
|
|
52
|
+
*/
|
|
53
|
+
resume: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Something to do before each dial attempt until one succeeds — the session manager loads the
|
|
56
|
+
* session record here, so a REST failure is retried on the same curve as a socket failure and a
|
|
57
|
+
* late success still binds the record. Dropped after the first success: later redials resume
|
|
58
|
+
* the socket, the record is already there.
|
|
59
|
+
*/
|
|
60
|
+
prepare?: () => Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export interface OpenOptions {
|
|
63
|
+
resume?: boolean;
|
|
64
|
+
prepare?: () => Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export interface ConnectionSupervisorPorts {
|
|
67
|
+
/** Dial once. Resolves with the session id the server answered with; rejects when the socket died first. */
|
|
68
|
+
dial: (sessionId: string | undefined, options: {
|
|
69
|
+
resume: boolean;
|
|
70
|
+
}) => Promise<string>;
|
|
71
|
+
/** Close the socket we hold. Idempotent; the transport reports the close as {@link APPLICATION_CLOSED_CODE}. */
|
|
72
|
+
hangUp: () => void;
|
|
73
|
+
/**
|
|
74
|
+
* The transport's own word on whether the socket is OPEN. The store says what the supervisor
|
|
75
|
+
* last wrote; a socket that died without a close event yet (an idle close the store has not
|
|
76
|
+
* caught up with, a dead peer the heartbeat is still timing) is what this catches.
|
|
77
|
+
*/
|
|
78
|
+
isConnected?: () => boolean;
|
|
79
|
+
store: AiChatStore;
|
|
80
|
+
/** The socket is up and the session proven. `reconnect` is true for every success after the first. */
|
|
81
|
+
onConnected?: (sessionId: string, info: {
|
|
82
|
+
reconnect: boolean;
|
|
83
|
+
}) => void;
|
|
84
|
+
/**
|
|
85
|
+
* A redial was scheduled `delayMs` from now — the moment the UI can say "reconnecting in N s".
|
|
86
|
+
* `attempt` counts consecutive failures since the last proven connection (1 = first redial).
|
|
87
|
+
*/
|
|
88
|
+
onRetryScheduled?: (info: {
|
|
89
|
+
sessionId?: string;
|
|
90
|
+
delayMs: number;
|
|
91
|
+
attempt: number;
|
|
92
|
+
}) => void;
|
|
93
|
+
/** The supervisor gave up on its own; the host decides what to tell the user. */
|
|
94
|
+
onHalt?: (reason: HaltReason, info: {
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
code?: number;
|
|
97
|
+
actualSessionId?: string;
|
|
98
|
+
}) => void;
|
|
99
|
+
/** For tests. Defaults to `Date.now`. */
|
|
100
|
+
now?: () => number;
|
|
101
|
+
}
|
|
102
|
+
export declare class ConnectionSupervisor {
|
|
103
|
+
private readonly ports;
|
|
104
|
+
private state;
|
|
105
|
+
private readonly now;
|
|
106
|
+
private target;
|
|
107
|
+
private inflight;
|
|
108
|
+
private retryTimer;
|
|
109
|
+
private idleTimer;
|
|
110
|
+
private wait;
|
|
111
|
+
/** Consecutive failed attempts since the last proven connection. */
|
|
112
|
+
private attempt;
|
|
113
|
+
private halted;
|
|
114
|
+
/** The code of the last close the transport reported, consumed by the next dial failure. */
|
|
115
|
+
private lastCloseCode;
|
|
116
|
+
private everConnected;
|
|
117
|
+
private idleWarningLogged;
|
|
118
|
+
constructor(ports: ConnectionSupervisorPorts);
|
|
119
|
+
get sessionId(): string | undefined;
|
|
120
|
+
get isSupervising(): boolean;
|
|
121
|
+
get haltReason(): HaltReason | null;
|
|
122
|
+
/** The delay the NEXT failure would wait. Exposed for tests and the console. */
|
|
123
|
+
get nextWaitMs(): number;
|
|
124
|
+
get retryScheduled(): boolean;
|
|
125
|
+
/** Connected by the store AND by the transport. */
|
|
126
|
+
private get isUp();
|
|
127
|
+
/**
|
|
128
|
+
* Be on `sessionId` (or on a fresh session when undefined). Resolves with the session id once
|
|
129
|
+
* the first attempt succeeds, rejects when it fails — and keeps retrying in the background
|
|
130
|
+
* either way, until {@link close} or a halt. Calling it for the session already targeted
|
|
131
|
+
* joins the dial in flight or returns the open socket's id; calling it for a different session
|
|
132
|
+
* hangs up the current one first.
|
|
133
|
+
*/
|
|
134
|
+
open(sessionId?: string, options?: OpenOptions): Promise<string>;
|
|
135
|
+
/**
|
|
136
|
+
* The send guard: make sure the socket is up before a frame goes out, dialling NOW (not at
|
|
137
|
+
* the next scheduled retry) when it is not. `fallbackSessionId` is what to dial when nothing
|
|
138
|
+
* was ever opened through here (a host that set the session on the gateway directly).
|
|
139
|
+
*/
|
|
140
|
+
ensure(fallbackSessionId?: string): Promise<string>;
|
|
141
|
+
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
142
|
+
close(): void;
|
|
143
|
+
/**
|
|
144
|
+
* The transport's socket closed. The code is the policy input:
|
|
145
|
+
* - 4001: our own hang-up, nothing to do.
|
|
146
|
+
* - 4002: attached elsewhere — halt, never bounce the other tab.
|
|
147
|
+
* - 4004: the server no longer has the session — halt, the host tells the user.
|
|
148
|
+
* - 1000 / 1008: closed on purpose / credentials rejected — halt.
|
|
149
|
+
* - anything else (1001 going away, 1006 abnormal, 1011–1013 server trouble, 4003 the server's
|
|
150
|
+
* idle close, 4100 our heartbeat's dead-peer verdict): retry on the curve, cursor kept.
|
|
151
|
+
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
152
|
+
*/
|
|
153
|
+
transportClosed(code: number, reason: string): void;
|
|
154
|
+
private dial;
|
|
155
|
+
/** Apply the close-code policy to a failure: halt, or schedule the next attempt. */
|
|
156
|
+
private judge;
|
|
157
|
+
private halt;
|
|
158
|
+
private scheduleRetry;
|
|
159
|
+
private cancelRetry;
|
|
160
|
+
private jittered;
|
|
161
|
+
private sameTarget;
|
|
162
|
+
private startIdleTick;
|
|
163
|
+
private stopIdleTick;
|
|
164
|
+
/**
|
|
165
|
+
* One idle check. Public so a test can drive it without the interval.
|
|
166
|
+
*
|
|
167
|
+
* A STREAMING TURN IS ACTIVITY: `lastActivity` is otherwise fed only by human input and sends,
|
|
168
|
+
* and surfaces without a ChatPane never register the listeners, so a long agent turn used to
|
|
169
|
+
* cross the window mid-stream and get its socket closed under it. Refreshing the clock while
|
|
170
|
+
* the turn is open mirrors the server's own live-activity exemption.
|
|
171
|
+
*/
|
|
172
|
+
tick(): void;
|
|
173
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coalesces a stream of cumulative snapshots down to a bounded cadence.
|
|
3
|
+
*
|
|
4
|
+
* Exists ONLY for the partial-streaming firehose: text and reasoning deltas
|
|
5
|
+
* reach the gateway dozens of times per second, and every publish re-renders
|
|
6
|
+
* the live message. A snapshot flagged `partial === false` — a settled tool
|
|
7
|
+
* result, the turn-complete signal — is rare and terminal-ish, so it publishes
|
|
8
|
+
* immediately and drops any trailing timer: each snapshot is cumulative, so
|
|
9
|
+
* nothing is lost by skipping the ones in between.
|
|
10
|
+
*
|
|
11
|
+
* Deferring a non-partial publish is exactly what once let a stale trailing
|
|
12
|
+
* timer land AFTER the turn was committed and draw the message twice (see
|
|
13
|
+
* {@link cancelPending}).
|
|
14
|
+
*/
|
|
15
|
+
export declare class ThrottledEmitter<T extends {
|
|
16
|
+
version: number;
|
|
17
|
+
partial: boolean;
|
|
18
|
+
}> {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private pending;
|
|
21
|
+
private lastPublishedAt;
|
|
22
|
+
private trailing;
|
|
23
|
+
constructor(options: {
|
|
24
|
+
windowMs: number;
|
|
25
|
+
publish: (snapshot: T) => void;
|
|
26
|
+
/** The version subscribers already hold; a trailing publish must be strictly newer. */
|
|
27
|
+
publishedVersion: () => number;
|
|
28
|
+
});
|
|
29
|
+
emit(snapshot: T): void;
|
|
30
|
+
/**
|
|
31
|
+
* Drop a trailing publish still queued. Call on turn commit: once the store
|
|
32
|
+
* has moved the interaction into history and nulled the live message, a late
|
|
33
|
+
* trailing publish would set it live again — the duplicated-bubble bug.
|
|
34
|
+
*/
|
|
35
|
+
cancelPending(): void;
|
|
36
|
+
private publish;
|
|
37
|
+
private clearTrailing;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LlmEvent, StreamingResponse, PartialLlmEvent } from '../../models/semanticKernelModel/models';
|
|
2
|
+
/**
|
|
3
|
+
* The server narrows a delta-only frame to `pe` (PartialEvent.cs): no envelope
|
|
4
|
+
* fields beyond the interaction id, and one of `pt` (text, or the ARGUMENTS
|
|
5
|
+
* fragment when `fn` is set), `pr` (reasoning). This widens it back to the
|
|
6
|
+
* LlmEvent shape the ServerEvent mapper reads, so one mapper serves both the
|
|
7
|
+
* narrowed and the full frame. Pure: builds a new event, mutates nothing.
|
|
8
|
+
*
|
|
9
|
+
* Kind is decided by presence, in this order: a function name → streamed
|
|
10
|
+
* arguments; reasoning → thought; otherwise text, even when `pt` is empty.
|
|
11
|
+
*/
|
|
12
|
+
export declare function llmEventFromPartial(pe: PartialLlmEvent): LlmEvent;
|
|
13
|
+
/**
|
|
14
|
+
* The LlmEvent carried by a frame, whichever form it took — the full `event`,
|
|
15
|
+
* or the narrowed `pe` widened back. Control frames (Pong, Suspended,
|
|
16
|
+
* RewindLost without a payload) yield nothing. The envelope's sub-agent identity
|
|
17
|
+
* is stamped onto the event so the gateway can route it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function llmEventFromFrame(frame: StreamingResponse): LlmEvent | undefined;
|
|
20
|
+
/** True when the event carries any content item or streaming part — what counts as a first token. */
|
|
21
|
+
export declare function carriesContent(event: LlmEvent): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,8 @@ export declare class FakeRawWebSocket {
|
|
|
5
5
|
static readonly CLOSING = 2;
|
|
6
6
|
static readonly CLOSED = 3;
|
|
7
7
|
readonly url: string;
|
|
8
|
+
/** When the code under test constructed it — the fake clock's time under fake timers. */
|
|
9
|
+
readonly createdAt: number;
|
|
8
10
|
readyState: number;
|
|
9
11
|
/** Every frame the production code sent through this socket, parsed. */
|
|
10
12
|
readonly sent: any[];
|
|
@@ -9,9 +9,6 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
|
|
|
9
9
|
onSuspended?: () => void;
|
|
10
10
|
onClose?: (code: number, reason: string) => void;
|
|
11
11
|
onNewPacket?: (stats: InteractionStatistics) => void;
|
|
12
|
-
onPong?: (sessionId: string) => void;
|
|
13
|
-
onReconnecting?: never;
|
|
14
|
-
onReconnected?: (sessionId: string) => void;
|
|
15
12
|
onRewindLost?: never;
|
|
16
13
|
readonly recordedSends: IMessage[];
|
|
17
14
|
sessionIdToReturn: string;
|
|
@@ -20,11 +17,13 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
|
|
|
20
17
|
sessionId?: string;
|
|
21
18
|
options?: {
|
|
22
19
|
resume?: boolean;
|
|
20
|
+
openInteractionId?: string;
|
|
23
21
|
};
|
|
24
22
|
}[];
|
|
25
23
|
private connected;
|
|
26
24
|
connect(sessionId?: string, options?: {
|
|
27
25
|
resume?: boolean;
|
|
26
|
+
openInteractionId?: string;
|
|
28
27
|
}): Promise<string>;
|
|
29
28
|
sendMessage(message: IMessage): void;
|
|
30
29
|
suspendStream(): void;
|
|
@@ -37,6 +36,8 @@ export declare class FakeWebSocketConnection implements IWebSocketConnection {
|
|
|
37
36
|
* consumer has (or has not) already reacted; the point is what it does at the next send.
|
|
38
37
|
*/
|
|
39
38
|
drop(): void;
|
|
39
|
+
/** The server (or the network) closed the socket: what the real transport reports through `onClose`. */
|
|
40
|
+
serverClose(code: number, reason?: string): void;
|
|
40
41
|
/**
|
|
41
42
|
* Drive an event through `onEvent` *and await it*. Use this when the
|
|
42
43
|
* next assertion depends on the merger having finished (the gateway's
|
|
@@ -8,6 +8,7 @@ import { IArtifactService } from '../../src/services/interfaces/artifactService'
|
|
|
8
8
|
import { ISessionService } from '../../src/services/servers/sessionService/ISessionService';
|
|
9
9
|
import { FakeWebSocketConnection } from './fakeWebSocket';
|
|
10
10
|
import { IStorageService } from '../../src/services/storageService';
|
|
11
|
+
import { IWebSocketConnection } from '../../src/services/WebSocketConnection/webSocketConnection';
|
|
11
12
|
declare function fakeArtifactService(): IArtifactService;
|
|
12
13
|
export interface FakeNotificationCapture extends INotificationPort {
|
|
13
14
|
/** Every notification the gateway pushed during the test. */
|
|
@@ -36,6 +37,12 @@ export interface MakeGatewayOptions {
|
|
|
36
37
|
* the test asserts on what `sendMessage` recorded.
|
|
37
38
|
*/
|
|
38
39
|
storageService?: IStorageService;
|
|
40
|
+
/**
|
|
41
|
+
* The transport under the gateway. Defaults to a `FakeWebSocketConnection`; pass a real
|
|
42
|
+
* `WebSocketConnecionV2` over `installFakeWebSocket()` to test the gateway's supervisor
|
|
43
|
+
* against the real wire code. `handle.ws` is then that object, typed as the fake.
|
|
44
|
+
*/
|
|
45
|
+
ws?: IWebSocketConnection;
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
48
|
* Build a fully-wired AgentGatewayWSAsync for tests. The `ws` field is
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AgentGatewayWSAsync } from '../../src/services/servers/AgentGatewayWSAsync';
|
|
2
|
+
export interface JourneyOptions {
|
|
3
|
+
interactionId: string;
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
/** How many reasoning deltas open the turn. */
|
|
6
|
+
reasoningDeltas?: number;
|
|
7
|
+
/** How many text deltas follow the reasoning (before the tool calls). */
|
|
8
|
+
textDeltas?: number;
|
|
9
|
+
/** How many text deltas close the turn (after the tool calls). */
|
|
10
|
+
closingTextDeltas?: number;
|
|
11
|
+
/** Characters per delta. The server coalesces into ~50ms windows (tens of chars); 1-3 is the old per-token wire. */
|
|
12
|
+
deltaChars?: number;
|
|
13
|
+
/** Include the two tool calls, the UI tool and the parked ask-user exchange. */
|
|
14
|
+
withTools?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class JourneyBuilder {
|
|
17
|
+
readonly interactionId: string;
|
|
18
|
+
readonly sessionId: string;
|
|
19
|
+
private seq;
|
|
20
|
+
readonly frames: string[];
|
|
21
|
+
private ts;
|
|
22
|
+
constructor(interactionId: string, sessionId?: string);
|
|
23
|
+
private envelope;
|
|
24
|
+
pong(): this;
|
|
25
|
+
reasoning(text: string): this;
|
|
26
|
+
text(text: string): this;
|
|
27
|
+
argsDelta(callId: string, name: string, fragment: string | null): this;
|
|
28
|
+
private fullEvent;
|
|
29
|
+
finalCall(callId: string, name: string, args: Record<string, unknown>, presentation?: Record<string, unknown>): this;
|
|
30
|
+
finalResult(callId: string, name: string, result: unknown, presentation?: Record<string, unknown>, clientOutput?: unknown): this;
|
|
31
|
+
park(callId: string, clientOutput?: unknown): this;
|
|
32
|
+
toolEvent(eventName: string, eventData: string): this;
|
|
33
|
+
turnComplete(): this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The reference journey: reasoning, an answer, a plain tool call streamed arg by
|
|
37
|
+
* arg, a UI render tool with a client-only payload, an ask-user exchange that
|
|
38
|
+
* parks and resumes, a closing paragraph, the turn-complete frame.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildJourney(opts: JourneyOptions): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Push raw frames through the REAL inbound path — typedjson parse, the `pe`
|
|
43
|
+
* expansion and ServerEvent mapping in WebSocketConnectionV2.handleMessage, then
|
|
44
|
+
* the gateway's Message → merge. Only the socket itself is absent: `handleMessage`
|
|
45
|
+
* is what `ws.onmessage` calls after `JSON.parse`, and it never touches the socket.
|
|
46
|
+
*/
|
|
47
|
+
export declare function replayFrames(gateway: AgentGatewayWSAsync, frames: Iterable<string>): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var L = Object.defineProperty;
|
|
2
2
|
var d = (e, t) => L(e, "name", { value: t, configurable: !0 });
|
|
3
3
|
import { useMemo as h, useState as v, useCallback as g, useEffect as C } from "react";
|
|
4
|
-
import { H } from "./httpSessionService-
|
|
4
|
+
import { H } from "./httpSessionService-wBby4ggl.js";
|
|
5
5
|
const w = 6e4, y = 60 * w, l = 24 * y;
|
|
6
6
|
function k(e) {
|
|
7
7
|
if (!e) return;
|
|
@@ -104,4 +104,4 @@ d(Y, "useChatSessions");
|
|
|
104
104
|
export {
|
|
105
105
|
Y as u
|
|
106
106
|
};
|
|
107
|
-
//# sourceMappingURL=useChatSessions-
|
|
107
|
+
//# sourceMappingURL=useChatSessions-C6sYF4U6.js.map
|