Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/common/state/protocol/actions.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// allow-any-unicode-comment-file
7
// DO NOT EDIT -- auto-generated by scripts/sync-agent-host-protocol.ts
8
9
import { ToolCallConfirmationReason, ToolCallCancellationReason, PendingMessageKind, type URI, type StringOrMarkdown, type AgentInfo, type ErrorInfo, type ModelSelection, type UserMessage, type ResponsePart, type ToolCallResult, type ToolResultContent, type ToolDefinition, type SessionActiveClient, type UsageInfo, type SessionCustomization, type FileEdit, type SessionInputAnswer, type SessionInputRequest, type TerminalInfo, type TerminalClaim, type SessionInputResponseKind, type ConfirmationOption } from './state.js';
10
11
12
// ─── Action Type Enum ────────────────────────────────────────────────────────
13
14
/**
15
* Discriminant values for all state actions.
16
*
17
* @category Actions
18
*/
19
export const enum ActionType {
20
RootAgentsChanged = 'root/agentsChanged',
21
RootActiveSessionsChanged = 'root/activeSessionsChanged',
22
SessionReady = 'session/ready',
23
SessionCreationFailed = 'session/creationFailed',
24
SessionTurnStarted = 'session/turnStarted',
25
SessionDelta = 'session/delta',
26
SessionResponsePart = 'session/responsePart',
27
SessionToolCallStart = 'session/toolCallStart',
28
SessionToolCallDelta = 'session/toolCallDelta',
29
SessionToolCallReady = 'session/toolCallReady',
30
SessionToolCallConfirmed = 'session/toolCallConfirmed',
31
SessionToolCallComplete = 'session/toolCallComplete',
32
SessionToolCallResultConfirmed = 'session/toolCallResultConfirmed',
33
SessionToolCallContentChanged = 'session/toolCallContentChanged',
34
SessionTurnComplete = 'session/turnComplete',
35
SessionTurnCancelled = 'session/turnCancelled',
36
SessionError = 'session/error',
37
SessionTitleChanged = 'session/titleChanged',
38
SessionUsage = 'session/usage',
39
SessionReasoning = 'session/reasoning',
40
SessionModelChanged = 'session/modelChanged',
41
SessionServerToolsChanged = 'session/serverToolsChanged',
42
SessionActiveClientChanged = 'session/activeClientChanged',
43
SessionActiveClientToolsChanged = 'session/activeClientToolsChanged',
44
SessionPendingMessageSet = 'session/pendingMessageSet',
45
SessionPendingMessageRemoved = 'session/pendingMessageRemoved',
46
SessionQueuedMessagesReordered = 'session/queuedMessagesReordered',
47
SessionInputRequested = 'session/inputRequested',
48
SessionInputAnswerChanged = 'session/inputAnswerChanged',
49
SessionInputCompleted = 'session/inputCompleted',
50
SessionCustomizationsChanged = 'session/customizationsChanged',
51
SessionCustomizationToggled = 'session/customizationToggled',
52
SessionTruncated = 'session/truncated',
53
SessionIsReadChanged = 'session/isReadChanged',
54
SessionIsArchivedChanged = 'session/isArchivedChanged',
55
SessionActivityChanged = 'session/activityChanged',
56
SessionDiffsChanged = 'session/diffsChanged',
57
SessionConfigChanged = 'session/configChanged',
58
SessionMetaChanged = 'session/metaChanged',
59
RootTerminalsChanged = 'root/terminalsChanged',
60
RootConfigChanged = 'root/configChanged',
61
TerminalData = 'terminal/data',
62
TerminalInput = 'terminal/input',
63
TerminalResized = 'terminal/resized',
64
TerminalClaimed = 'terminal/claimed',
65
TerminalTitleChanged = 'terminal/titleChanged',
66
TerminalCwdChanged = 'terminal/cwdChanged',
67
TerminalExited = 'terminal/exited',
68
TerminalCleared = 'terminal/cleared',
69
TerminalCommandDetectionAvailable = 'terminal/commandDetectionAvailable',
70
TerminalCommandExecuted = 'terminal/commandExecuted',
71
TerminalCommandFinished = 'terminal/commandFinished',
72
}
73
74
// ─── Action Envelope ─────────────────────────────────────────────────────────
75
76
/**
77
* Identifies the client that originally dispatched an action.
78
*/
79
export interface ActionOrigin {
80
clientId: string;
81
clientSeq: number;
82
}
83
84
/**
85
* Every action is wrapped in an `ActionEnvelope`.
86
*/
87
export interface ActionEnvelope {
88
readonly action: StateAction;
89
readonly serverSeq: number;
90
readonly origin: ActionOrigin | undefined;
91
readonly rejectionReason?: string;
92
}
93
94
// ─── Root Actions ────────────────────────────────────────────────────────────
95
96
/**
97
* Base interface for all tool-call-scoped actions, carrying the common
98
* session, turn, and tool call identifiers.
99
*
100
* @category Session Actions
101
*/
102
interface ToolCallActionBase {
103
/** Session URI */
104
session: URI;
105
/** Turn identifier */
106
turnId: string;
107
/** Tool call identifier */
108
toolCallId: string;
109
/**
110
* Additional provider-specific metadata for this tool call.
111
*
112
* Clients MAY look for well-known keys here to provide enhanced UI.
113
* For example, a `ptyTerminal` key with `{ input: string; output: string }`
114
* indicates the tool operated on a terminal (both `input` and `output` may
115
* contain escape sequences).
116
*/
117
_meta?: Record<string, unknown>;
118
}
119
120
/**
121
* Fired when available agent backends or their models change.
122
*
123
* @category Root Actions
124
* @version 1
125
*/
126
export interface RootAgentsChangedAction {
127
type: ActionType.RootAgentsChanged;
128
/** Updated agent list */
129
agents: AgentInfo[];
130
}
131
132
/**
133
* Fired when the number of active sessions changes.
134
*
135
* @category Root Actions
136
* @version 1
137
*/
138
export interface RootActiveSessionsChangedAction {
139
type: ActionType.RootActiveSessionsChanged;
140
/** Current count of active sessions */
141
activeSessions: number;
142
}
143
144
/**
145
* Fired when the list of known terminals changes.
146
*
147
* Full-replacement semantics: the `terminals` array replaces the previous
148
* `terminals` entirely.
149
*
150
* @category Root Actions
151
* @version 1
152
*/
153
export interface RootTerminalsChangedAction {
154
type: ActionType.RootTerminalsChanged;
155
/** Updated terminal list (full replacement) */
156
terminals: TerminalInfo[];
157
}
158
159
/**
160
* Fired when agent-host configuration values change.
161
*
162
* By default, the reducer merges the new values into `state.config.values`.
163
* Set `replace` to `true` to replace all values instead of merging.
164
*
165
* @category Root Actions
166
* @version 1
167
* @clientDispatchable
168
*/
169
export interface RootConfigChangedAction {
170
type: ActionType.RootConfigChanged;
171
/** Updated config values */
172
config: Record<string, unknown>;
173
/** When `true`, replaces all config values instead of merging */
174
replace?: boolean;
175
}
176
177
// ─── Session Actions ─────────────────────────────────────────────────────────
178
179
/**
180
* Session backend initialized successfully.
181
*
182
* @category Session Actions
183
* @version 1
184
*/
185
export interface SessionReadyAction {
186
type: ActionType.SessionReady;
187
/** Session URI */
188
session: URI;
189
}
190
191
/**
192
* Session backend failed to initialize.
193
*
194
* @category Session Actions
195
* @version 1
196
*/
197
export interface SessionCreationFailedAction {
198
type: ActionType.SessionCreationFailed;
199
/** Session URI */
200
session: URI;
201
/** Error details */
202
error: ErrorInfo;
203
}
204
205
/**
206
* User sent a message; server starts agent processing.
207
*
208
* @category Session Actions
209
* @version 1
210
* @clientDispatchable
211
*/
212
export interface SessionTurnStartedAction {
213
type: ActionType.SessionTurnStarted;
214
/** Session URI */
215
session: URI;
216
/** Turn identifier */
217
turnId: string;
218
/** User's message */
219
userMessage: UserMessage;
220
/** If this turn was auto-started from a queued message, the ID of that message */
221
queuedMessageId?: string;
222
}
223
224
/**
225
* Streaming text chunk from the assistant, appended to a specific response part.
226
*
227
* The server MUST first emit a `session/responsePart` to create the target
228
* part (markdown or reasoning), then use this action to append text to it.
229
*
230
* @category Session Actions
231
* @version 1
232
*/
233
export interface SessionDeltaAction {
234
type: ActionType.SessionDelta;
235
/** Session URI */
236
session: URI;
237
/** Turn identifier */
238
turnId: string;
239
/** Identifier of the response part to append to */
240
partId: string;
241
/** Text chunk */
242
content: string;
243
}
244
245
/**
246
* Structured content appended to the response.
247
*
248
* @category Session Actions
249
* @version 1
250
*/
251
export interface SessionResponsePartAction {
252
type: ActionType.SessionResponsePart;
253
/** Session URI */
254
session: URI;
255
/** Turn identifier */
256
turnId: string;
257
/** Response part (markdown or content ref) */
258
part: ResponsePart;
259
}
260
261
/**
262
* A tool call begins — parameters are streaming from the LM.
263
*
264
* For client-provided tools, the server sets `toolClientId` to identify the
265
* owning client. That client is responsible for executing the tool once it
266
* reaches the `running` state and dispatching `session/toolCallComplete`.
267
*
268
* @category Session Actions
269
* @version 1
270
*/
271
export interface SessionToolCallStartAction extends ToolCallActionBase {
272
type: ActionType.SessionToolCallStart;
273
/** Internal tool name (for debugging/logging) */
274
toolName: string;
275
/** Human-readable tool name */
276
displayName: string;
277
/**
278
* If this tool is provided by a client, the `clientId` of the owning client.
279
* Absent for server-side tools.
280
*/
281
toolClientId?: string;
282
}
283
284
/**
285
* Streaming partial parameters for a tool call.
286
*
287
* @category Session Actions
288
* @version 1
289
*/
290
export interface SessionToolCallDeltaAction extends ToolCallActionBase {
291
type: ActionType.SessionToolCallDelta;
292
/** Partial parameter content to append */
293
content: string;
294
/** Updated progress message */
295
invocationMessage?: StringOrMarkdown;
296
}
297
298
/**
299
* Tool call parameters are complete, or a running tool requires re-confirmation.
300
*
301
* When dispatched for a `streaming` tool call, transitions to `pending-confirmation`
302
* or directly to `running` if `confirmed` is set.
303
*
304
* When dispatched for a `running` tool call (e.g. mid-execution permission needed),
305
* transitions back to `pending-confirmation`. The `invocationMessage` and `_meta`
306
* SHOULD be updated to describe the specific confirmation needed. Clients use the
307
* standard `session/toolCallConfirmed` flow to approve or deny.
308
*
309
* For client-provided tools, the server typically sets `confirmed` to
310
* `'not-needed'` so the tool transitions directly to `running`, where the
311
* owning client can begin execution immediately.
312
*
313
* @category Session Actions
314
* @version 1
315
*/
316
export interface SessionToolCallReadyAction extends ToolCallActionBase {
317
type: ActionType.SessionToolCallReady;
318
/** Message describing what the tool will do or what confirmation is needed */
319
invocationMessage: StringOrMarkdown;
320
/** Raw tool input */
321
toolInput?: string;
322
/** Short title for the confirmation prompt (e.g. `"Run in terminal"`, `"Write file"`) */
323
confirmationTitle?: StringOrMarkdown;
324
/** File edits that this tool call will perform, for preview before confirmation */
325
edits?: { items: FileEdit[] };
326
/** Whether the agent host allows the client to edit the tool's input parameters before confirming */
327
editable?: boolean;
328
/** If set, the tool was auto-confirmed and transitions directly to `running` */
329
confirmed?: ToolCallConfirmationReason;
330
/**
331
* Options the server offers for this confirmation. When present, the client
332
* SHOULD render these instead of a plain approve/deny UI. Each option
333
* belongs to a {@link ConfirmationOptionGroup} so the client can still
334
* categorise the choices.
335
*/
336
options?: ConfirmationOption[];
337
}
338
339
/**
340
* Client approves a pending tool call. The tool transitions to `running`.
341
*
342
* @category Session Actions
343
* @version 1
344
* @clientDispatchable
345
*/
346
export interface SessionToolCallApprovedAction extends ToolCallActionBase {
347
type: ActionType.SessionToolCallConfirmed;
348
/** The tool call was approved */
349
approved: true;
350
/** How the tool was confirmed */
351
confirmed: ToolCallConfirmationReason;
352
/** Edited tool input parameters, if the client modified them before confirming */
353
editedToolInput?: string;
354
/** ID of the selected confirmation option, if the server provided options */
355
selectedOptionId?: string;
356
}
357
358
/**
359
* Client denies a pending tool call. The tool transitions to `cancelled`.
360
*
361
* For client-provided tools, the owning client MUST dispatch this if it does
362
* not recognize the tool or cannot execute it.
363
*
364
* @category Session Actions
365
* @version 1
366
* @clientDispatchable
367
*/
368
export interface SessionToolCallDeniedAction extends ToolCallActionBase {
369
type: ActionType.SessionToolCallConfirmed;
370
/** The tool call was denied */
371
approved: false;
372
/** Why the tool was cancelled */
373
reason: ToolCallCancellationReason.Denied | ToolCallCancellationReason.Skipped;
374
/** What the user suggested doing instead */
375
userSuggestion?: UserMessage;
376
/** Optional explanation for the denial */
377
reasonMessage?: StringOrMarkdown;
378
/** ID of the selected confirmation option, if the server provided options */
379
selectedOptionId?: string;
380
}
381
382
/**
383
* Client confirms or denies a pending tool call.
384
*
385
* @category Session Actions
386
* @version 1
387
* @clientDispatchable
388
*/
389
export type SessionToolCallConfirmedAction =
390
| SessionToolCallApprovedAction
391
| SessionToolCallDeniedAction;
392
393
/**
394
* Tool execution finished. Transitions to `completed` or `pending-result-confirmation`
395
* if `requiresResultConfirmation` is `true`.
396
*
397
* For client-provided tools (where `toolClientId` is set on the tool call state),
398
* the owning client dispatches this action with the execution result. The server
399
* SHOULD reject this action if the dispatching client does not match `toolClientId`.
400
*
401
* Servers waiting on a client tool call MAY time out after a reasonable duration
402
* if the implementing client disconnects or becomes unresponsive, and dispatch
403
* this action with `result.success = false` and an appropriate error.
404
*
405
* @category Session Actions
406
* @version 1
407
* @clientDispatchable
408
*/
409
export interface SessionToolCallCompleteAction extends ToolCallActionBase {
410
type: ActionType.SessionToolCallComplete;
411
/** Execution result */
412
result: ToolCallResult;
413
/** If true, the result requires client approval before finalizing */
414
requiresResultConfirmation?: boolean;
415
}
416
417
/**
418
* Client approves or denies a tool's result.
419
*
420
* If `approved` is `false`, the tool transitions to `cancelled` with reason `result-denied`.
421
*
422
* @category Session Actions
423
* @version 1
424
* @clientDispatchable
425
*/
426
export interface SessionToolCallResultConfirmedAction extends ToolCallActionBase {
427
type: ActionType.SessionToolCallResultConfirmed;
428
/** Whether the result was approved */
429
approved: boolean;
430
}
431
432
/**
433
* Partial content produced while a tool is still executing.
434
*
435
* Replaces the `content` array on the running tool call state. Clients can
436
* use this to display live feedback (e.g. a terminal reference) before the
437
* tool completes.
438
*
439
* For client-provided tools (where `toolClientId` is set on the tool call state),
440
* the owning client dispatches this action to stream intermediate content while
441
* executing. The server SHOULD reject this action if the dispatching client does
442
* not match `toolClientId`.
443
*
444
* @category Session Actions
445
* @version 1
446
* @clientDispatchable
447
*/
448
export interface SessionToolCallContentChangedAction extends ToolCallActionBase {
449
type: ActionType.SessionToolCallContentChanged;
450
/** The current partial content for the running tool call */
451
content: ToolResultContent[];
452
}
453
454
/**
455
* Turn finished — the assistant is idle.
456
*
457
* @category Session Actions
458
* @version 1
459
*/
460
export interface SessionTurnCompleteAction {
461
type: ActionType.SessionTurnComplete;
462
/** Session URI */
463
session: URI;
464
/** Turn identifier */
465
turnId: string;
466
}
467
468
/**
469
* Turn was aborted; server stops processing.
470
*
471
* @category Session Actions
472
* @version 1
473
* @clientDispatchable
474
*/
475
export interface SessionTurnCancelledAction {
476
type: ActionType.SessionTurnCancelled;
477
/** Session URI */
478
session: URI;
479
/** Turn identifier */
480
turnId: string;
481
}
482
483
/**
484
* Error during turn processing.
485
*
486
* @category Session Actions
487
* @version 1
488
*/
489
export interface SessionErrorAction {
490
type: ActionType.SessionError;
491
/** Session URI */
492
session: URI;
493
/** Turn identifier */
494
turnId: string;
495
/** Error details */
496
error: ErrorInfo;
497
}
498
499
/**
500
* Session title updated. Fired by the server when the title is auto-generated
501
* from conversation, or dispatched by a client to rename a session.
502
*
503
* @category Session Actions
504
* @clientDispatchable
505
* @version 1
506
*/
507
export interface SessionTitleChangedAction {
508
type: ActionType.SessionTitleChanged;
509
/** Session URI */
510
session: URI;
511
/** New title */
512
title: string;
513
}
514
515
/**
516
* Token usage report for a turn.
517
*
518
* @category Session Actions
519
* @version 1
520
*/
521
export interface SessionUsageAction {
522
type: ActionType.SessionUsage;
523
/** Session URI */
524
session: URI;
525
/** Turn identifier */
526
turnId: string;
527
/** Token usage data */
528
usage: UsageInfo;
529
}
530
531
/**
532
* Reasoning/thinking text from the model, appended to a specific reasoning response part.
533
*
534
* The server MUST first emit a `session/responsePart` to create the target
535
* reasoning part, then use this action to append text to it.
536
*
537
* @category Session Actions
538
* @version 1
539
*/
540
export interface SessionReasoningAction {
541
type: ActionType.SessionReasoning;
542
/** Session URI */
543
session: URI;
544
/** Turn identifier */
545
turnId: string;
546
/** Identifier of the reasoning response part to append to */
547
partId: string;
548
/** Reasoning text chunk */
549
content: string;
550
}
551
552
/**
553
* Model changed for this session.
554
*
555
* @category Session Actions
556
* @version 1
557
* @clientDispatchable
558
*/
559
export interface SessionModelChangedAction {
560
type: ActionType.SessionModelChanged;
561
/** Session URI */
562
session: URI;
563
/** New model selection */
564
model: ModelSelection;
565
}
566
567
/**
568
* The read state of the session changed.
569
*
570
* Dispatched by a client to mark a session as read (e.g. after viewing it)
571
* or unread (e.g. after new activity since the client last looked at it).
572
*
573
* @category Session Actions
574
* @version 1
575
* @clientDispatchable
576
*/
577
export interface SessionIsReadChangedAction {
578
type: ActionType.SessionIsReadChanged;
579
/** Session URI */
580
session: URI;
581
/** Whether the session has been read */
582
isRead: boolean;
583
}
584
585
/**
586
* The archived state of the session changed.
587
*
588
* Dispatched by a client to archive a session (e.g. the task is
589
* complete) or to unarchive it.
590
*
591
* @category Session Actions
592
* @version 1
593
* @clientDispatchable
594
*/
595
export interface SessionIsArchivedChangedAction {
596
type: ActionType.SessionIsArchivedChanged;
597
/** Session URI */
598
session: URI;
599
/** Whether the session is archived */
600
isArchived: boolean;
601
}
602
603
/**
604
* The activity description of the session changed.
605
*
606
* Dispatched by the server to indicate what the session is currently doing
607
* (e.g. running a tool, thinking). Clear activity by setting it to `undefined`.
608
*
609
* @category Session Actions
610
* @version 1
611
*/
612
export interface SessionActivityChangedAction {
613
type: ActionType.SessionActivityChanged;
614
/** Session URI */
615
session: URI;
616
/** Human-readable description of current activity, or `undefined` to clear */
617
activity: string | undefined;
618
}
619
620
/**
621
* The file diffs for the session changed.
622
*
623
* Full-replacement semantics: the `diffs` array replaces the previous
624
* `summary.diffs` entirely.
625
*
626
* @category Session Actions
627
* @version 1
628
*/
629
export interface SessionDiffsChangedAction {
630
type: ActionType.SessionDiffsChanged;
631
/** Session URI */
632
session: URI;
633
/** Updated file diffs for the session */
634
diffs: FileEdit[];
635
}
636
637
/**
638
* Server tools for this session have changed.
639
*
640
* Full-replacement semantics: the `tools` array replaces the previous `serverTools` entirely.
641
*
642
* @category Session Actions
643
* @version 1
644
*/
645
export interface SessionServerToolsChangedAction {
646
type: ActionType.SessionServerToolsChanged;
647
/** Session URI */
648
session: URI;
649
/** Updated server tools list (full replacement) */
650
tools: ToolDefinition[];
651
}
652
653
/**
654
* The active client for this session has changed.
655
*
656
* A client dispatches this action with its own `SessionActiveClient` to claim
657
* the active role, or with `null` to release it. The server SHOULD reject if
658
* another client is already active. The server SHOULD automatically dispatch
659
* this action with `activeClient: null` when the active client disconnects.
660
*
661
* @category Session Actions
662
* @version 1
663
* @clientDispatchable
664
*/
665
export interface SessionActiveClientChangedAction {
666
type: ActionType.SessionActiveClientChanged;
667
/** Session URI */
668
session: URI;
669
/** The new active client, or `null` to unset */
670
activeClient: SessionActiveClient | null;
671
}
672
673
/**
674
* The active client's tool list has changed.
675
*
676
* Full-replacement semantics: the `tools` array replaces the active client's
677
* previous tools entirely. The server SHOULD reject if the dispatching client
678
* is not the current active client.
679
*
680
* @category Session Actions
681
* @version 1
682
* @clientDispatchable
683
*/
684
export interface SessionActiveClientToolsChangedAction {
685
type: ActionType.SessionActiveClientToolsChanged;
686
/** Session URI */
687
session: URI;
688
/** Updated client tools list (full replacement) */
689
tools: ToolDefinition[];
690
}
691
692
// ─── Customization Actions ───────────────────────────────────────────────────
693
694
/**
695
* The session's customizations have changed.
696
*
697
* Full-replacement semantics: the `customizations` array replaces the
698
* previous `customizations` entirely.
699
*
700
* @category Session Actions
701
* @version 1
702
*/
703
export interface SessionCustomizationsChangedAction {
704
type: ActionType.SessionCustomizationsChanged;
705
/** Session URI */
706
session: URI;
707
/** Updated customization list (full replacement) */
708
customizations: SessionCustomization[];
709
}
710
711
/**
712
* A client toggled a customization on or off.
713
*
714
* The server locates the customization by `uri` in the session's
715
* customization list and sets its `enabled` flag.
716
*
717
* @category Session Actions
718
* @version 1
719
* @clientDispatchable
720
*/
721
export interface SessionCustomizationToggledAction {
722
type: ActionType.SessionCustomizationToggled;
723
/** Session URI */
724
session: URI;
725
/** The URI of the customization to toggle */
726
uri: URI;
727
/** Whether to enable or disable the customization */
728
enabled: boolean;
729
}
730
731
// ─── Config Actions ──────────────────────────────────────────────────────────
732
733
/**
734
* Client changed a mutable config value mid-session.
735
*
736
* Only properties with `sessionMutable: true` in the config schema may be
737
* changed. The server validates and broadcasts the action; the reducer merges
738
* the new values into `state.config.values`.
739
*
740
* @category Session Actions
741
* @version 1
742
* @clientDispatchable
743
*/
744
export interface SessionConfigChangedAction {
745
type: ActionType.SessionConfigChanged;
746
/** Session URI */
747
session: URI;
748
/** Updated config values */
749
config: Record<string, unknown>;
750
/** When `true`, replaces all config values instead of merging */
751
replace?: boolean;
752
}
753
754
/**
755
* The session's `_meta` side-channel changed. Replaces `state._meta`
756
* entirely (full-replacement semantics). Producers SHOULD merge any
757
* keys they wish to preserve into the new value before dispatching.
758
*
759
* @category Session Actions
760
* @version 1
761
*/
762
export interface SessionMetaChangedAction {
763
type: ActionType.SessionMetaChanged;
764
/** Session URI */
765
session: URI;
766
/** New `_meta` payload, or `undefined` to clear it */
767
_meta: Record<string, unknown> | undefined;
768
}
769
770
// ─── Truncation ──────────────────────────────────────────────────────────────
771
772
/**
773
* Truncates a session's history. If `turnId` is provided, all turns after that
774
* turn are removed and the specified turn is kept. If `turnId` is omitted, all
775
* turns are removed.
776
*
777
* If there is an active turn it is silently dropped and the session status
778
* returns to `idle`.
779
*
780
* Common use-case: truncate old data then dispatch a new
781
* `session/turnStarted` with an edited message.
782
*
783
* @category Session Actions
784
* @version 1
785
* @clientDispatchable
786
*/
787
export interface SessionTruncatedAction {
788
type: ActionType.SessionTruncated;
789
/** Session URI */
790
session: URI;
791
/** Keep turns up to and including this turn. Omit to clear all turns. */
792
turnId?: string;
793
}
794
795
// ─── Pending Message Actions ─────────────────────────────────────────────────
796
797
/**
798
* A pending message was set (upsert semantics: creates or replaces).
799
*
800
* For steering messages, this always replaces the single steering message.
801
* For queued messages, if a message with the given `id` already exists it is
802
* updated in place; otherwise it is appended to the queue. If the session is
803
* idle when a queued message is set, the server SHOULD immediately consume it
804
* and start a new turn.
805
*
806
* @category Session Actions
807
* @version 1
808
* @clientDispatchable
809
*/
810
export interface SessionPendingMessageSetAction {
811
type: ActionType.SessionPendingMessageSet;
812
/** Session URI */
813
session: URI;
814
/** Whether this is a steering or queued message */
815
kind: PendingMessageKind;
816
/** Unique identifier for this pending message */
817
id: string;
818
/** The message content */
819
userMessage: UserMessage;
820
}
821
822
/**
823
* A pending message was removed (steering or queued).
824
*
825
* Dispatched by clients to cancel a pending message, or by the server when
826
* it consumes a message (e.g. starting a turn from a queued message or
827
* injecting a steering message into the current turn).
828
*
829
* @category Session Actions
830
* @version 1
831
* @clientDispatchable
832
*/
833
export interface SessionPendingMessageRemovedAction {
834
type: ActionType.SessionPendingMessageRemoved;
835
/** Session URI */
836
session: URI;
837
/** Whether this is a steering or queued message */
838
kind: PendingMessageKind;
839
/** Identifier of the pending message to remove */
840
id: string;
841
}
842
843
/**
844
* Reorder the queued messages.
845
*
846
* The `order` array contains the IDs of queued messages in their new
847
* desired order. IDs not present in the current queue are ignored.
848
* Queued messages whose IDs are absent from `order` are appended at
849
* the end in their original relative order (so a client with a stale
850
* view of the queue never silently drops messages).
851
*
852
* @category Session Actions
853
* @version 1
854
* @clientDispatchable
855
*/
856
export interface SessionQueuedMessagesReorderedAction {
857
type: ActionType.SessionQueuedMessagesReordered;
858
/** Session URI */
859
session: URI;
860
/** Queued message IDs in the desired order */
861
order: string[];
862
}
863
864
// ─── Session Input Actions ──────────────────────────────────────────────────
865
866
/**
867
* A session requested input from the user.
868
*
869
* Full-request upsert semantics: the `request` replaces any existing request
870
* with the same `id`, or is appended if it is new. Answer drafts are preserved
871
* unless `request.answers` is provided.
872
*
873
* @category Session Actions
874
* @version 1
875
*/
876
export interface SessionInputRequestedAction {
877
type: ActionType.SessionInputRequested;
878
/** Session URI */
879
session: URI;
880
/** Input request to create or replace */
881
request: SessionInputRequest;
882
}
883
884
/**
885
* A client updated, submitted, skipped, or removed a single in-progress answer.
886
*
887
* Dispatching with `answer: undefined` removes that question's answer draft.
888
*
889
* @category Session Actions
890
* @version 1
891
* @clientDispatchable
892
*/
893
export interface SessionInputAnswerChangedAction {
894
type: ActionType.SessionInputAnswerChanged;
895
/** Session URI */
896
session: URI;
897
/** Input request identifier */
898
requestId: string;
899
/** Question identifier within the input request */
900
questionId: string;
901
/** Updated answer, or `undefined` to clear an answer draft */
902
answer?: SessionInputAnswer;
903
}
904
905
/**
906
* A client accepted, declined, or cancelled a session input request.
907
*
908
* If accepted, the server uses `answers` (when provided) plus the request's
909
* synced answer state to resume the blocked operation.
910
*
911
* @category Session Actions
912
* @version 1
913
* @clientDispatchable
914
*/
915
export interface SessionInputCompletedAction {
916
type: ActionType.SessionInputCompleted;
917
/** Session URI */
918
session: URI;
919
/** Input request identifier */
920
requestId: string;
921
/** Completion outcome */
922
response: SessionInputResponseKind;
923
/** Optional final answer replacement, keyed by question ID */
924
answers?: Record<string, SessionInputAnswer>;
925
}
926
927
// ─── Terminal Actions ────────────────────────────────────────────────────────
928
929
/**
930
* Terminal output data (pty → client direction).
931
*
932
* Appends `data` to the terminal's `content` in the reducer.
933
*
934
* `terminal/data` and `terminal/input` are intentionally separate actions
935
* because standard write-ahead reconciliation is not safe for terminal I/O.
936
* A pty is a stateful, mutable process — optimistically applying input or
937
* predicting output would produce incorrect state. Instead, `terminal/input`
938
* is a side-effect-only action (client → server → pty), and `terminal/data`
939
* is server-authoritative output (pty → server → client).
940
*
941
* @category Terminal Actions
942
* @version 1
943
*/
944
export interface TerminalDataAction {
945
type: ActionType.TerminalData;
946
/** Terminal URI */
947
terminal: URI;
948
/** Output data (may contain ANSI escape sequences) */
949
data: string;
950
}
951
952
/**
953
* Keyboard input sent to the terminal process (client → pty direction).
954
*
955
* This is a side-effect-only action: the server forwards the data to the
956
* terminal's pty. The reducer treats this as a no-op since `terminal/data`
957
* actions will reflect any resulting output.
958
*
959
* See `terminal/data` for why these two actions are kept separate.
960
*
961
* @category Terminal Actions
962
* @version 1
963
* @clientDispatchable
964
*/
965
export interface TerminalInputAction {
966
type: ActionType.TerminalInput;
967
/** Terminal URI */
968
terminal: URI;
969
/** Input data to send to the pty */
970
data: string;
971
}
972
973
/**
974
* Terminal dimensions changed.
975
*
976
* Dispatchable by clients to request a resize, or by the server to inform
977
* clients of the actual terminal dimensions.
978
*
979
* @category Terminal Actions
980
* @version 1
981
* @clientDispatchable
982
*/
983
export interface TerminalResizedAction {
984
type: ActionType.TerminalResized;
985
/** Terminal URI */
986
terminal: URI;
987
/** Terminal width in columns */
988
cols: number;
989
/** Terminal height in rows */
990
rows: number;
991
}
992
993
/**
994
* Terminal claim changed. A client or session transfers ownership of the terminal.
995
*
996
* The server SHOULD reject if the dispatching client does not currently hold
997
* the claim.
998
*
999
* @category Terminal Actions
1000
* @version 1
1001
* @clientDispatchable
1002
*/
1003
export interface TerminalClaimedAction {
1004
type: ActionType.TerminalClaimed;
1005
/** Terminal URI */
1006
terminal: URI;
1007
/** The new claim */
1008
claim: TerminalClaim;
1009
}
1010
1011
/**
1012
* Terminal title changed.
1013
*
1014
* Fired by the server when the terminal process updates its title (e.g. via
1015
* escape sequences), or dispatched by a client to rename a terminal.
1016
*
1017
* @category Terminal Actions
1018
* @version 1
1019
* @clientDispatchable
1020
*/
1021
export interface TerminalTitleChangedAction {
1022
type: ActionType.TerminalTitleChanged;
1023
/** Terminal URI */
1024
terminal: URI;
1025
/** New terminal title */
1026
title: string;
1027
}
1028
1029
/**
1030
* Terminal working directory changed.
1031
*
1032
* @category Terminal Actions
1033
* @version 1
1034
*/
1035
export interface TerminalCwdChangedAction {
1036
type: ActionType.TerminalCwdChanged;
1037
/** Terminal URI */
1038
terminal: URI;
1039
/** New working directory */
1040
cwd: URI;
1041
}
1042
1043
/**
1044
* Terminal process exited.
1045
*
1046
* @category Terminal Actions
1047
* @version 1
1048
*/
1049
export interface TerminalExitedAction {
1050
type: ActionType.TerminalExited;
1051
/** Terminal URI */
1052
terminal: URI;
1053
/** Process exit code. `undefined` if the process was killed without an exit code. */
1054
exitCode?: number;
1055
}
1056
1057
/**
1058
* Terminal scrollback buffer cleared.
1059
*
1060
* @category Terminal Actions
1061
* @version 1
1062
* @clientDispatchable
1063
*/
1064
export interface TerminalClearedAction {
1065
type: ActionType.TerminalCleared;
1066
/** Terminal URI */
1067
terminal: URI;
1068
}
1069
1070
/**
1071
* Shell integration has loaded and the terminal now supports command
1072
* detection. The server dispatches this when shell integration becomes
1073
* available (which may happen asynchronously after the terminal is created).
1074
*
1075
* Clients MUST NOT assume command detection is available until this action
1076
* (or `terminal/commandExecuted`) has been received.
1077
*
1078
* @category Terminal Actions
1079
* @version 1
1080
*/
1081
export interface TerminalCommandDetectionAvailableAction {
1082
type: ActionType.TerminalCommandDetectionAvailable;
1083
/** Terminal URI */
1084
terminal: URI;
1085
}
1086
1087
/**
1088
* A command has been submitted to the shell and is now executing.
1089
* All subsequent `terminal/data` actions (until the matching
1090
* `terminal/commandFinished`) constitute this command's output.
1091
*
1092
* @category Terminal Actions
1093
* @version 1
1094
*/
1095
export interface TerminalCommandExecutedAction {
1096
type: ActionType.TerminalCommandExecuted;
1097
/** Terminal URI */
1098
terminal: URI;
1099
/**
1100
* Stable identifier for this command, scoped to the terminal URI.
1101
* Allows correlating `commandExecuted` → `commandFinished` pairs.
1102
*/
1103
commandId: string;
1104
/** The command line text that was submitted */
1105
commandLine: string;
1106
/**
1107
* Unix timestamp (ms) of when the command started executing, as measured
1108
* on the server.
1109
*/
1110
timestamp: number;
1111
}
1112
1113
/**
1114
* A command has finished executing.
1115
*
1116
* The sequence of `terminal/data` actions between the preceding
1117
* `terminal/commandExecuted` (same `commandId`) and this action constitutes
1118
* the complete output of the command.
1119
*
1120
* @category Terminal Actions
1121
* @version 1
1122
*/
1123
export interface TerminalCommandFinishedAction {
1124
type: ActionType.TerminalCommandFinished;
1125
/** Terminal URI */
1126
terminal: URI;
1127
/** Matches the `commandId` from the corresponding `commandExecuted` */
1128
commandId: string;
1129
/** Shell exit code. `undefined` if the shell did not report one. */
1130
exitCode?: number;
1131
/**
1132
* Wall-clock duration of the command in milliseconds, as measured by the
1133
* shell integration script on the server side.
1134
*/
1135
durationMs?: number;
1136
}
1137
1138
// ─── Discriminated Union ─────────────────────────────────────────────────────
1139
1140
/**
1141
* Discriminated union of all state actions.
1142
*/
1143
export type StateAction =
1144
| RootAgentsChangedAction
1145
| RootActiveSessionsChangedAction
1146
| RootTerminalsChangedAction
1147
| RootConfigChangedAction
1148
| SessionReadyAction
1149
| SessionCreationFailedAction
1150
| SessionTurnStartedAction
1151
| SessionDeltaAction
1152
| SessionResponsePartAction
1153
| SessionToolCallStartAction
1154
| SessionToolCallDeltaAction
1155
| SessionToolCallReadyAction
1156
| SessionToolCallConfirmedAction
1157
| SessionToolCallCompleteAction
1158
| SessionToolCallResultConfirmedAction
1159
| SessionToolCallContentChangedAction
1160
| SessionTurnCompleteAction
1161
| SessionTurnCancelledAction
1162
| SessionErrorAction
1163
| SessionTitleChangedAction
1164
| SessionUsageAction
1165
| SessionReasoningAction
1166
| SessionModelChangedAction
1167
| SessionServerToolsChangedAction
1168
| SessionActiveClientChangedAction
1169
| SessionActiveClientToolsChangedAction
1170
| SessionPendingMessageSetAction
1171
| SessionPendingMessageRemovedAction
1172
| SessionQueuedMessagesReorderedAction
1173
| SessionInputRequestedAction
1174
| SessionInputAnswerChangedAction
1175
| SessionInputCompletedAction
1176
| SessionCustomizationsChangedAction
1177
| SessionCustomizationToggledAction
1178
| SessionTruncatedAction
1179
| SessionIsReadChangedAction
1180
| SessionIsArchivedChangedAction
1181
| SessionActivityChangedAction
1182
| SessionDiffsChangedAction
1183
| SessionConfigChangedAction
1184
| SessionMetaChangedAction
1185
| TerminalDataAction
1186
| TerminalInputAction
1187
| TerminalResizedAction
1188
| TerminalClaimedAction
1189
| TerminalTitleChangedAction
1190
| TerminalCwdChangedAction
1191
| TerminalExitedAction
1192
| TerminalClearedAction
1193
| TerminalCommandDetectionAvailableAction
1194
| TerminalCommandExecutedAction
1195
| TerminalCommandFinishedAction;
1196
1197