Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/common/state/protocol/state.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
// ─── Type Aliases ────────────────────────────────────────────────────────────
10
11
/** A URI string (e.g. `agenthost:/root` or `copilot:/<uuid>`). */
12
export type URI = string;
13
14
/**
15
* A string that may optionally be rendered as Markdown.
16
*
17
* - A plain `string` is rendered as-is (no Markdown processing).
18
* - An object with `{ markdown: string }` is rendered with Markdown formatting.
19
*/
20
export type StringOrMarkdown = string | { markdown: string };
21
22
// ─── Icon ────────────────────────────────────────────────────────────────────
23
24
/**
25
* An optionally-sized icon that can be displayed in a user interface.
26
*
27
* @category Common Types
28
*/
29
export interface Icon {
30
/**
31
* A standard URI pointing to an icon resource. May be an HTTP/HTTPS URL or a
32
* `data:` URI with Base64-encoded image data.
33
*
34
* Consumers SHOULD take steps to ensure URLs serving icons are from the
35
* same domain as the client/server or a trusted domain.
36
*
37
* Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain
38
* executable JavaScript.
39
*/
40
src: URI;
41
42
/**
43
* Optional MIME type override if the source MIME type is missing or generic.
44
* For example: `"image/png"`, `"image/jpeg"`, or `"image/svg+xml"`.
45
*/
46
contentType?: string;
47
48
/**
49
* Optional array of strings that specify sizes at which the icon can be used.
50
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
51
*
52
* If not provided, the client should assume that the icon can be used at any size.
53
*/
54
sizes?: string[];
55
56
/**
57
* Optional specifier for the theme this icon is designed for. `"light"` indicates
58
* the icon is designed to be used with a light background, and `"dark"` indicates
59
* the icon is designed to be used with a dark background.
60
*
61
* If not provided, the client should assume the icon can be used with any theme.
62
*/
63
theme?: 'light' | 'dark';
64
}
65
66
// ─── Protected Resource Metadata (RFC 9728) ─────────────────────────────────
67
68
/**
69
* Describes a protected resource's authentication requirements using
70
* [RFC 9728](https://datatracker.ietf.org/doc/html/rfc9728) (OAuth 2.0
71
* Protected Resource Metadata) semantics.
72
*
73
* Field names use snake_case to match the RFC 9728 JSON format.
74
*
75
* @category Authentication
76
* @see {@link https://datatracker.ietf.org/doc/html/rfc9728 | RFC 9728}
77
*/
78
export interface ProtectedResourceMetadata {
79
/**
80
* REQUIRED. The protected resource's resource identifier, a URL using the
81
* `https` scheme with no fragment component (e.g. `"https://api.github.com"`).
82
*/
83
resource: string;
84
85
/** OPTIONAL. Human-readable name of the protected resource. */
86
resource_name?: string;
87
88
/** OPTIONAL. JSON array of OAuth authorization server identifier URLs. */
89
authorization_servers?: string[];
90
91
/** OPTIONAL. URL of the protected resource's JWK Set document. */
92
jwks_uri?: string;
93
94
/** RECOMMENDED. JSON array of OAuth 2.0 scope values used in authorization requests. */
95
scopes_supported?: string[];
96
97
/** OPTIONAL. JSON array of Bearer Token presentation methods supported. */
98
bearer_methods_supported?: string[];
99
100
/** OPTIONAL. JSON array of JWS signing algorithms supported. */
101
resource_signing_alg_values_supported?: string[];
102
103
/** OPTIONAL. JSON array of JWE encryption algorithms (alg) supported. */
104
resource_encryption_alg_values_supported?: string[];
105
106
/** OPTIONAL. JSON array of JWE encryption algorithms (enc) supported. */
107
resource_encryption_enc_values_supported?: string[];
108
109
/** OPTIONAL. URL of human-readable documentation for the resource. */
110
resource_documentation?: string;
111
112
/** OPTIONAL. URL of the resource's data-usage policy. */
113
resource_policy_uri?: string;
114
115
/** OPTIONAL. URL of the resource's terms of service. */
116
resource_tos_uri?: string;
117
118
/**
119
* AHP extension. Whether authentication is required for this resource.
120
*
121
* - `true` (default) — the agent cannot be used without a valid token.
122
* The server SHOULD return `AuthRequired` (`-32007`) if the client
123
* attempts to use the agent without authenticating.
124
* - `false` — the agent works without authentication but MAY offer
125
* enhanced capabilities when a token is provided.
126
*
127
* Clients SHOULD treat an absent field the same as `true`.
128
*/
129
required?: boolean;
130
}
131
132
// ─── Root State ──────────────────────────────────────────────────────────────
133
134
/**
135
* Policy configuration state for a model.
136
*
137
* @category Root State
138
*/
139
export const enum PolicyState {
140
Enabled = 'enabled',
141
Disabled = 'disabled',
142
Unconfigured = 'unconfigured',
143
}
144
145
/**
146
* Global state shared with every client subscribed to `agenthost:/root`.
147
*
148
* @category Root State
149
*/
150
export interface RootState {
151
/** Available agent backends and their models */
152
agents: AgentInfo[];
153
/** Number of active (non-disposed) sessions on the server */
154
activeSessions?: number;
155
/** Known terminals on the server. Subscribe to individual terminal URIs for full state. */
156
terminals?: TerminalInfo[];
157
/** Agent host configuration schema and current values */
158
config?: RootConfigState;
159
}
160
161
/**
162
* @category Root State
163
*/
164
export interface AgentInfo {
165
/** Agent provider ID (e.g. `'copilot'`) */
166
provider: string;
167
/** Human-readable name */
168
displayName: string;
169
/** Description string */
170
description: string;
171
/** Available models for this agent */
172
models: SessionModelInfo[];
173
/**
174
* Protected resources this agent requires authentication for.
175
*
176
* Each entry describes an OAuth 2.0 protected resource using
177
* [RFC 9728](https://datatracker.ietf.org/doc/html/rfc9728) semantics.
178
* Clients should obtain tokens from the declared `authorization_servers`
179
* and push them via the `authenticate` command before creating sessions
180
* with this agent.
181
*
182
* @see {@link /specification/authentication | Authentication}
183
*/
184
protectedResources?: ProtectedResourceMetadata[];
185
/**
186
* Customizations (Open Plugins) associated with this agent.
187
*
188
* Each entry is a reference to an [Open Plugins](https://open-plugins.com/)
189
* plugin that the agent host can activate for sessions using this agent.
190
*/
191
customizations?: CustomizationRef[];
192
}
193
194
/**
195
* @category Root State
196
*/
197
export interface SessionModelInfo {
198
/** Model identifier */
199
id: string;
200
/** Provider this model belongs to */
201
provider: string;
202
/** Human-readable model name */
203
name: string;
204
/** Maximum context window size */
205
maxContextWindow?: number;
206
/** Whether the model supports vision */
207
supportsVision?: boolean;
208
/** Policy configuration state */
209
policyState?: PolicyState;
210
/**
211
* Configuration schema describing model-specific options (e.g. thinking
212
* level). Clients present this as a form and pass the resolved values in
213
* {@link ModelSelection.config} when creating or changing sessions.
214
*/
215
configSchema?: ConfigSchema;
216
}
217
218
/**
219
* A model selection: the chosen model ID together with any model-specific
220
* configuration values whose keys correspond to the model's
221
* {@link SessionModelInfo.configSchema}.
222
*
223
* @category Root State
224
*/
225
export interface ModelSelection {
226
/** Model identifier */
227
id: string;
228
/** Model-specific configuration values */
229
config?: Record<string, string>;
230
}
231
232
// ─── Pending Message Types ───────────────────────────────────────────────────
233
234
/**
235
* Discriminant for pending message kinds.
236
*
237
* @category Pending Message Types
238
*/
239
export const enum PendingMessageKind {
240
/** Injected into the current turn at a convenient point */
241
Steering = 'steering',
242
/** Sent automatically as a new turn after the current turn finishes */
243
Queued = 'queued',
244
}
245
246
/**
247
* A message queued for future delivery to the agent.
248
*
249
* Steering messages are injected into the current turn mid-flight.
250
* Queued messages are automatically started as new turns after the
251
* current turn naturally finishes.
252
*
253
* @category Pending Message Types
254
*/
255
export interface PendingMessage {
256
/** Unique identifier for this pending message */
257
id: string;
258
/** The message content */
259
userMessage: UserMessage;
260
}
261
262
// ─── Session State ───────────────────────────────────────────────────────────
263
264
/**
265
* Session initialization state.
266
*
267
* @category Session State
268
*/
269
export const enum SessionLifecycle {
270
Creating = 'creating',
271
Ready = 'ready',
272
CreationFailed = 'creationFailed',
273
}
274
275
/**
276
* Bitset of summary-level session status flags.
277
*
278
* Use bitwise checks instead of equality for non-terminal activity. For example,
279
* `status & SessionStatus.InProgress` matches both ordinary in-progress turns
280
* and turns that are paused waiting for input.
281
*
282
* @category Session State
283
*/
284
export const enum SessionStatus {
285
/** Session is idle — no turn is active. */
286
Idle = 1,
287
/** Session ended with an error. */
288
Error = 1 << 1,
289
/** A turn is actively streaming. */
290
InProgress = 1 << 3,
291
/** A turn is in progress but blocked waiting for user input or tool confirmation. */
292
InputNeeded = (1 << 3) | (1 << 4),
293
/** The client has viewed this session since its last modification. */
294
IsRead = 1 << 5,
295
/** The session has been archived by the client. */
296
IsArchived = 1 << 6,
297
}
298
299
/**
300
* Full state for a single session, loaded when a client subscribes to the session's URI.
301
*
302
* @category Session State
303
*/
304
export interface SessionState {
305
/** Lightweight session metadata */
306
summary: SessionSummary;
307
/** Session initialization state */
308
lifecycle: SessionLifecycle;
309
/** Error details if creation failed */
310
creationError?: ErrorInfo;
311
/** Tools provided by the server (agent host) for this session */
312
serverTools?: ToolDefinition[];
313
/** The client currently providing tools and interactive capabilities to this session */
314
activeClient?: SessionActiveClient;
315
/** Completed turns */
316
turns: Turn[];
317
/** Currently in-progress turn */
318
activeTurn?: ActiveTurn;
319
/** Message to inject into the current turn at a convenient point */
320
steeringMessage?: PendingMessage;
321
/** Messages to send automatically as new turns after the current turn finishes */
322
queuedMessages?: PendingMessage[];
323
/** Requests for user input that are currently blocking or informing session progress */
324
inputRequests?: SessionInputRequest[];
325
/** Session configuration schema and current values */
326
config?: SessionConfigState;
327
/**
328
* Server-provided customizations active in this session.
329
*
330
* Client-provided customizations are available on
331
* {@link SessionActiveClient.customizations | activeClient.customizations}.
332
*/
333
customizations?: SessionCustomization[];
334
/**
335
* Additional provider-specific metadata for this session.
336
*
337
* Clients MAY look for well-known keys here to provide enhanced UI.
338
* For example, a `git` key may provide extra git metadata about the session's
339
* workingDirectory.
340
*/
341
_meta?: Record<string, unknown>;
342
}
343
344
/**
345
* The client currently providing tools and interactive capabilities to a session.
346
*
347
* Only one client may be active per session at a time. The server SHOULD
348
* automatically unset the active client if that client disconnects.
349
*
350
* @category Session State
351
*/
352
export interface SessionActiveClient {
353
/** Client identifier (matches `clientId` from `initialize`) */
354
clientId: string;
355
/** Human-readable client name (e.g. `"VS Code"`) */
356
displayName?: string;
357
/** Tools this client provides to the session */
358
tools: ToolDefinition[];
359
/** Customizations this client contributes to the session */
360
customizations?: CustomizationRef[];
361
}
362
363
/**
364
* Server-owned project metadata for a session.
365
*
366
* @category Session State
367
*/
368
export interface ProjectInfo {
369
/** Project URI */
370
uri: URI;
371
/** Human-readable project name */
372
displayName: string;
373
}
374
375
/**
376
* @category Session State
377
*/
378
export interface SessionSummary {
379
/** Session URI */
380
resource: URI;
381
/** Agent provider ID */
382
provider: string;
383
/** Session title */
384
title: string;
385
/** Current session status */
386
status: SessionStatus;
387
/** Human-readable description of what the session is currently doing */
388
activity?: string;
389
/** Creation timestamp */
390
createdAt: number;
391
/** Last modification timestamp */
392
modifiedAt: number;
393
/** Server-owned project for this session */
394
project?: ProjectInfo;
395
/** Currently selected model */
396
model?: ModelSelection;
397
/** The working directory URI for this session */
398
workingDirectory?: URI;
399
/** Files changed during this session with diff statistics */
400
diffs?: FileEdit[];
401
}
402
403
// ─── Config Schema Types ─────────────────────────────────────────────────────
404
405
/**
406
* A JSON Schema-compatible property descriptor with display extensions.
407
*
408
* Standard JSON Schema fields (`type`, `title`, `description`, `default`,
409
* `enum`) allow validators to process the schema. Display extensions
410
* (`enumLabels`, `enumDescriptions`) are parallel arrays that provide UI
411
* metadata for each `enum` value.
412
*
413
* This is the generic base type. See {@link SessionConfigPropertySchema} for
414
* session-specific extensions.
415
*
416
* @category Config Schema Types
417
*/
418
export interface ConfigPropertySchema {
419
/** JSON Schema: property type */
420
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
421
/** JSON Schema: human-readable label for the property */
422
title: string;
423
/** JSON Schema: description / tooltip */
424
description?: string;
425
/** JSON Schema: default value */
426
default?: unknown;
427
/** JSON Schema: allowed values (typically used with `string` type) */
428
enum?: string[];
429
/** Display extension: human-readable label per enum value (parallel array) */
430
enumLabels?: string[];
431
/** Display extension: description per enum value (parallel array) */
432
enumDescriptions?: string[];
433
/** JSON Schema: when `true`, the property is displayed but cannot be modified by the user */
434
readOnly?: boolean;
435
/** JSON Schema: schema for array items (used when `type` is `'array'`) */
436
items?: ConfigPropertySchema;
437
/** JSON Schema: property descriptors for object properties (used when `type` is `'object'`) */
438
properties?: Record<string, ConfigPropertySchema>;
439
/** JSON Schema: list of required property ids (used when `type` is `'object'`) */
440
required?: string[];
441
}
442
443
/**
444
* A JSON Schema object describing available configuration properties.
445
*
446
* This is the generic base type. See {@link SessionConfigSchema} for
447
* session-specific usage.
448
*
449
* @category Config Schema Types
450
*/
451
export interface ConfigSchema {
452
/** JSON Schema: always `'object'` */
453
type: 'object';
454
/** JSON Schema: property descriptors keyed by property id */
455
properties: Record<string, ConfigPropertySchema>;
456
/** JSON Schema: list of required property ids */
457
required?: string[];
458
}
459
460
// ─── Root Config Types ───────────────────────────────────────────────────────
461
462
/**
463
* Live agent-host configuration metadata.
464
*
465
* The schema describes the available configuration properties and the values
466
* contain the current value for each resolved property.
467
*
468
* @category Root State
469
*/
470
export interface RootConfigState {
471
/** JSON Schema describing available configuration properties */
472
schema: ConfigSchema;
473
/** Current configuration values */
474
values: Record<string, unknown>;
475
}
476
477
// ─── Session Config Types ────────────────────────────────────────────────────
478
479
/**
480
* A session configuration property descriptor.
481
*
482
* Extends the generic {@link ConfigPropertySchema} with session-specific
483
* display extensions.
484
*
485
* @category Session Config Types
486
*/
487
export interface SessionConfigPropertySchema extends ConfigPropertySchema {
488
/**
489
* Display extension: when `true`, the full set of allowed values is too large
490
* to enumerate statically. The client SHOULD use `sessionConfigCompletions`
491
* to fetch matching values based on user input. Any values in `enum` are
492
* seed/recent values for initial display.
493
*/
494
enumDynamic?: boolean;
495
/** When `true`, the user may change this property after session creation */
496
sessionMutable?: boolean;
497
}
498
499
/**
500
* A JSON Schema object describing available session configuration metadata.
501
*
502
* @category Session Config Types
503
*/
504
export interface SessionConfigSchema {
505
/** JSON Schema: always `'object'` */
506
type: 'object';
507
/** JSON Schema: property descriptors keyed by property id */
508
properties: Record<string, SessionConfigPropertySchema>;
509
/** JSON Schema: list of required property ids */
510
required?: string[];
511
}
512
513
/**
514
* Live session configuration metadata.
515
*
516
* The schema describes the available configuration properties and the values
517
* contain the current value for each resolved property.
518
*
519
* @category Session Config Types
520
*/
521
export interface SessionConfigState {
522
/** JSON Schema describing available configuration properties */
523
schema: SessionConfigSchema;
524
/** Current configuration values */
525
values: Record<string, unknown>;
526
}
527
528
// ─── Session Input Types ────────────────────────────────────────────────────
529
530
/**
531
* How a client completed an input request.
532
*
533
* @category Session Input Types
534
*/
535
export const enum SessionInputResponseKind {
536
Accept = 'accept',
537
Decline = 'decline',
538
Cancel = 'cancel',
539
}
540
541
/**
542
* Question/input control kind.
543
*
544
* @category Session Input Types
545
*/
546
export const enum SessionInputQuestionKind {
547
Text = 'text',
548
Number = 'number',
549
Integer = 'integer',
550
Boolean = 'boolean',
551
SingleSelect = 'single-select',
552
MultiSelect = 'multi-select',
553
}
554
555
/**
556
* A choice in a select-style question.
557
*
558
* @category Session Input Types
559
*/
560
export interface SessionInputOption {
561
/** Stable option identifier; for MCP enum values this is the enum string */
562
id: string;
563
/** Display label */
564
label: string;
565
/** Optional secondary text */
566
description?: string;
567
/** Whether this option is the recommended/default choice */
568
recommended?: boolean;
569
}
570
571
interface SessionInputQuestionBase {
572
/** Stable question identifier used as the key in `answers` */
573
id: string;
574
/** Short display title */
575
title?: string;
576
/** Prompt shown to the user */
577
message: string;
578
/** Whether the user must answer this question to accept the request */
579
required?: boolean;
580
}
581
582
/** Text question within a session input request. */
583
export interface SessionInputTextQuestion extends SessionInputQuestionBase {
584
kind: SessionInputQuestionKind.Text;
585
/** Format hint for text questions, such as `email`, `uri`, `date`, or `date-time` */
586
format?: string;
587
/** Minimum string length */
588
min?: number;
589
/** Maximum string length */
590
max?: number;
591
/** Default text */
592
defaultValue?: string;
593
}
594
595
/** Numeric question within a session input request. */
596
export interface SessionInputNumberQuestion extends SessionInputQuestionBase {
597
kind: SessionInputQuestionKind.Number | SessionInputQuestionKind.Integer;
598
/**
599
* Minimum value
600
* @format float
601
*/
602
min?: number;
603
/**
604
* Maximum value
605
* @format float
606
*/
607
max?: number;
608
/**
609
* Default numeric value
610
* @format float
611
*/
612
defaultValue?: number;
613
}
614
615
/** Boolean question within a session input request. */
616
export interface SessionInputBooleanQuestion extends SessionInputQuestionBase {
617
kind: SessionInputQuestionKind.Boolean;
618
/** Default boolean value */
619
defaultValue?: boolean;
620
}
621
622
/** Single-select question within a session input request. */
623
export interface SessionInputSingleSelectQuestion extends SessionInputQuestionBase {
624
kind: SessionInputQuestionKind.SingleSelect;
625
/** Options the user may select from */
626
options: SessionInputOption[];
627
/** Whether the user may enter text instead of selecting an option */
628
allowFreeformInput?: boolean;
629
}
630
631
/** Multi-select question within a session input request. */
632
export interface SessionInputMultiSelectQuestion extends SessionInputQuestionBase {
633
kind: SessionInputQuestionKind.MultiSelect;
634
/** Options the user may select from */
635
options: SessionInputOption[];
636
/** Whether the user may enter text in addition to selecting options */
637
allowFreeformInput?: boolean;
638
/** Minimum selected item count */
639
min?: number;
640
/** Maximum selected item count */
641
max?: number;
642
}
643
644
/**
645
* One question within a session input request.
646
*
647
* @category Session Input Types
648
*/
649
export type SessionInputQuestion = SessionInputTextQuestion
650
| SessionInputNumberQuestion
651
| SessionInputBooleanQuestion
652
| SessionInputSingleSelectQuestion
653
| SessionInputMultiSelectQuestion;
654
655
/**
656
* A live request for user input.
657
*
658
* The server creates or replaces requests with `session/inputRequested`.
659
* Clients sync drafts with `session/inputAnswerChanged` and complete requests
660
* with `session/inputCompleted`.
661
*
662
* @category Session Input Types
663
*/
664
export interface SessionInputRequest {
665
/** Stable request identifier */
666
id: string;
667
/** Display message for the request as a whole */
668
message?: string;
669
/** URL the user should review or open, for URL-style elicitations */
670
url?: URI;
671
/** Ordered questions to ask the user */
672
questions?: SessionInputQuestion[];
673
/** Current draft or submitted answers, keyed by question ID */
674
answers?: Record<string, SessionInputAnswer>;
675
}
676
677
/**
678
* Answer value kind.
679
*
680
* @category Session Input Types
681
*/
682
export const enum SessionInputAnswerValueKind {
683
Text = 'text',
684
Number = 'number',
685
Boolean = 'boolean',
686
Selected = 'selected',
687
SelectedMany = 'selected-many',
688
}
689
690
/**
691
* Value captured for one answer.
692
*
693
* @category Session Input Types
694
*/
695
export interface SessionInputTextAnswerValue {
696
kind: SessionInputAnswerValueKind.Text;
697
value: string;
698
}
699
700
export interface SessionInputNumberAnswerValue {
701
kind: SessionInputAnswerValueKind.Number;
702
/** @format float */
703
value: number;
704
}
705
706
export interface SessionInputBooleanAnswerValue {
707
kind: SessionInputAnswerValueKind.Boolean;
708
value: boolean;
709
}
710
711
export interface SessionInputSelectedAnswerValue {
712
kind: SessionInputAnswerValueKind.Selected;
713
value: string;
714
/** Free-form text entered instead of selecting an option */
715
freeformValues?: string[];
716
}
717
718
export interface SessionInputSelectedManyAnswerValue {
719
kind: SessionInputAnswerValueKind.SelectedMany;
720
value: string[];
721
/** Free-form text entered in addition to selected options */
722
freeformValues?: string[];
723
}
724
725
export type SessionInputAnswerValue = SessionInputTextAnswerValue
726
| SessionInputNumberAnswerValue
727
| SessionInputBooleanAnswerValue
728
| SessionInputSelectedAnswerValue
729
| SessionInputSelectedManyAnswerValue;
730
731
export interface SessionInputAnswered {
732
/** Answer state */
733
state: SessionInputAnswerState.Draft | SessionInputAnswerState.Submitted;
734
/** Answer value */
735
value: SessionInputAnswerValue;
736
}
737
738
export interface SessionInputSkipped {
739
/** Answer state */
740
state: SessionInputAnswerState.Skipped;
741
/** Free-form reason or value captured while skipping, if any */
742
freeformValues?: string[];
743
}
744
745
/**
746
* Answer lifecycle state.
747
*
748
* @category Session Input Types
749
*/
750
export const enum SessionInputAnswerState {
751
Draft = 'draft',
752
Submitted = 'submitted',
753
Skipped = 'skipped',
754
}
755
756
/**
757
* Draft, submitted, or skipped answer for one question.
758
*
759
* @category Session Input Types
760
*/
761
export type SessionInputAnswer = SessionInputAnswered | SessionInputSkipped;
762
763
// ─── Turn Types ──────────────────────────────────────────────────────────────
764
765
/**
766
* How a turn ended.
767
*
768
* @category Turn Types
769
*/
770
export const enum TurnState {
771
Complete = 'complete',
772
Cancelled = 'cancelled',
773
Error = 'error',
774
}
775
776
/**
777
* Type of a message attachment.
778
*
779
* @category Turn Types
780
*/
781
export const enum AttachmentType {
782
File = 'file',
783
Directory = 'directory',
784
Selection = 'selection',
785
}
786
787
/**
788
* A completed request/response cycle.
789
*
790
* @category Turn Types
791
*/
792
export interface Turn {
793
/** Turn identifier */
794
id: string;
795
/** The user's input */
796
userMessage: UserMessage;
797
/**
798
* All response content in stream order: text, tool calls, reasoning, and content refs.
799
*
800
* Consumers should derive display text by concatenating markdown parts,
801
* and find tool calls by filtering for `ToolCall` parts.
802
*/
803
responseParts: ResponsePart[];
804
/** Token usage info */
805
usage: UsageInfo | undefined;
806
/** How the turn ended */
807
state: TurnState;
808
/** Error details if state is `'error'` */
809
error?: ErrorInfo;
810
}
811
812
/**
813
* An in-progress turn — the assistant is actively streaming.
814
*
815
* @category Turn Types
816
*/
817
export interface ActiveTurn {
818
/** Turn identifier */
819
id: string;
820
/** The user's input */
821
userMessage: UserMessage;
822
/**
823
* All response content in stream order: text, tool calls, reasoning, and content refs.
824
*
825
* Tool call parts include `pendingPermissions` when permissions are awaiting user approval.
826
*/
827
responseParts: ResponsePart[];
828
/** Token usage info */
829
usage: UsageInfo | undefined;
830
}
831
832
/**
833
* @category Turn Types
834
*/
835
export interface UserMessage {
836
/** Message text */
837
text: string;
838
/** File/selection attachments */
839
attachments?: MessageAttachment[];
840
}
841
842
/**
843
* @category Turn Types
844
*/
845
export interface MessageAttachment {
846
/** Attachment type */
847
type: AttachmentType;
848
/** File/directory URI */
849
uri: URI;
850
/** Display name */
851
displayName?: string;
852
}
853
854
// ─── Response Parts ──────────────────────────────────────────────────────────
855
856
/**
857
* Discriminant for response part types.
858
*
859
* @category Response Parts
860
*/
861
export const enum ResponsePartKind {
862
Markdown = 'markdown',
863
ContentRef = 'contentRef',
864
ToolCall = 'toolCall',
865
Reasoning = 'reasoning',
866
}
867
868
/**
869
* @category Response Parts
870
*/
871
export interface MarkdownResponsePart {
872
/** Discriminant */
873
kind: ResponsePartKind.Markdown;
874
/** Part identifier, used by `session/delta` to target this part for content appends */
875
id: string;
876
/** Markdown content */
877
content: string;
878
}
879
880
/**
881
* A reference to large content stored outside the state tree.
882
*/
883
export interface ContentRef {
884
/** Content URI */
885
uri: URI;
886
/** Approximate size in bytes */
887
sizeHint?: number;
888
/** Content MIME type */
889
contentType?: string;
890
}
891
892
/**
893
* A content part that's a reference to large content stored outside the state tree.
894
*
895
* @category Response Parts
896
*/
897
export interface ResourceReponsePart extends ContentRef {
898
/** Discriminant */
899
kind: ResponsePartKind.ContentRef;
900
}
901
902
/**
903
* A tool call represented as a response part.
904
*
905
* Tool calls are part of the response stream, interleaved with text and
906
* reasoning. The `toolCall.toolCallId` serves as the part identifier for
907
* actions that target this part.
908
*
909
* @category Response Parts
910
*/
911
export interface ToolCallResponsePart {
912
/** Discriminant */
913
kind: ResponsePartKind.ToolCall;
914
/** Full tool call lifecycle state */
915
toolCall: ToolCallState;
916
}
917
918
/**
919
* Reasoning/thinking content from the model.
920
*
921
* @category Response Parts
922
*/
923
export interface ReasoningResponsePart {
924
/** Discriminant */
925
kind: ResponsePartKind.Reasoning;
926
/** Part identifier, used by `session/reasoning` to target this part for content appends */
927
id: string;
928
/** Accumulated reasoning text */
929
content: string;
930
}
931
932
/**
933
* @category Response Parts
934
*/
935
export type ResponsePart = MarkdownResponsePart | ResourceReponsePart | ToolCallResponsePart | ReasoningResponsePart;
936
937
// ─── Tool Call Types ─────────────────────────────────────────────────────────
938
939
/**
940
* Status of a tool call in the lifecycle state machine.
941
*
942
* @category Tool Call Types
943
*/
944
export const enum ToolCallStatus {
945
Streaming = 'streaming',
946
PendingConfirmation = 'pending-confirmation',
947
Running = 'running',
948
PendingResultConfirmation = 'pending-result-confirmation',
949
Completed = 'completed',
950
Cancelled = 'cancelled',
951
}
952
953
/**
954
* How a tool call was confirmed for execution.
955
*
956
* - `NotNeeded` — No confirmation required (auto-approved)
957
* - `UserAction` — User explicitly approved
958
* - `Setting` — Approved by a persistent user setting
959
*
960
* @category Tool Call Types
961
*/
962
export const enum ToolCallConfirmationReason {
963
NotNeeded = 'not-needed',
964
UserAction = 'user-action',
965
Setting = 'setting',
966
}
967
968
/**
969
* Why a tool call was cancelled.
970
*
971
* @category Tool Call Types
972
*/
973
export const enum ToolCallCancellationReason {
974
Denied = 'denied',
975
Skipped = 'skipped',
976
ResultDenied = 'result-denied',
977
}
978
979
/**
980
* Whether a confirmation option represents an approval or denial action.
981
*
982
* @category Tool Call Types
983
*/
984
export const enum ConfirmationOptionKind {
985
Approve = 'approve',
986
Deny = 'deny',
987
}
988
989
/**
990
* A confirmation option that the server offers for a tool call awaiting
991
* approval. Allows richer choices beyond simple approve/deny — for example,
992
* "Approve in this Session" or "Deny with reason."
993
*
994
* @category Tool Call Types
995
*/
996
export interface ConfirmationOption {
997
/** Unique identifier for the option, returned in the confirmed action */
998
id: string;
999
/** Human-readable label displayed to the user */
1000
label: string;
1001
/** Whether this option represents an approval or denial */
1002
kind: ConfirmationOptionKind;
1003
/**
1004
* Logical group number for visual categorisation.
1005
*
1006
* Clients SHOULD display options in the order they are defined and MAY
1007
* use differing group numbers to insert dividers between logical clusters
1008
* of options.
1009
*/
1010
group?: number;
1011
}
1012
1013
/**
1014
* Metadata common to all tool call states.
1015
*
1016
* @category Tool Call Types
1017
* @remarks
1018
* Fields like `toolName` carry agent-specific identifiers on the wire despite the
1019
* agent-agnostic design principle. These exist for debugging and logging purposes.
1020
* A future version may move these to a separate diagnostic channel or namespace them
1021
* more clearly.
1022
*/
1023
interface ToolCallBase {
1024
/** Unique tool call identifier */
1025
toolCallId: string;
1026
/** Internal tool name (for debugging/logging) */
1027
toolName: string;
1028
/** Human-readable tool name */
1029
displayName: string;
1030
/**
1031
* If this tool is provided by a client, the `clientId` of the owning client.
1032
* Absent for server-side tools.
1033
*
1034
* When set, the identified client is responsible for executing the tool and
1035
* dispatching `session/toolCallComplete` with the result.
1036
*/
1037
toolClientId?: string;
1038
/**
1039
* Additional provider-specific metadata for this tool call.
1040
*
1041
* Clients MAY look for well-known keys here to provide enhanced UI.
1042
* For example, a `ptyTerminal` key with `{ input: string; output: string }`
1043
* indicates the tool operated on a terminal (both `input` and `output` may
1044
* contain escape sequences).
1045
*/
1046
_meta?: Record<string, unknown>;
1047
}
1048
1049
/**
1050
* Properties available once tool call parameters are fully received.
1051
*
1052
* @category Tool Call Types
1053
*/
1054
interface ToolCallParameterFields {
1055
/** Message describing what the tool will do */
1056
invocationMessage: StringOrMarkdown;
1057
/** Raw tool input */
1058
toolInput?: string;
1059
}
1060
1061
/**
1062
* Tool execution result details, available after execution completes.
1063
*
1064
* @category Tool Call Types
1065
*/
1066
export interface ToolCallResult {
1067
/** Whether the tool succeeded */
1068
success: boolean;
1069
/** Past-tense description of what the tool did */
1070
pastTenseMessage: StringOrMarkdown;
1071
/**
1072
* Unstructured result content blocks.
1073
*
1074
* This mirrors the `content` field of MCP `CallToolResult`.
1075
*/
1076
content?: ToolResultContent[];
1077
/**
1078
* Optional structured result object.
1079
*
1080
* This mirrors the `structuredContent` field of MCP `CallToolResult`.
1081
*/
1082
structuredContent?: Record<string, unknown>;
1083
/** Error details if the tool failed */
1084
error?: { message: string; code?: string };
1085
}
1086
1087
/**
1088
* LM is streaming the tool call parameters.
1089
*
1090
* @category Tool Call Types
1091
*/
1092
export interface ToolCallStreamingState extends ToolCallBase {
1093
status: ToolCallStatus.Streaming;
1094
/** Partial parameters accumulated so far */
1095
partialInput?: string;
1096
/** Progress message shown while parameters are streaming */
1097
invocationMessage?: StringOrMarkdown;
1098
}
1099
1100
/**
1101
* Parameters are complete, or a running tool requires re-confirmation
1102
* (e.g. a mid-execution permission check).
1103
*
1104
* @category Tool Call Types
1105
*/
1106
export interface ToolCallPendingConfirmationState extends ToolCallBase, ToolCallParameterFields {
1107
status: ToolCallStatus.PendingConfirmation;
1108
/** Short title for the confirmation prompt (e.g. `"Run in terminal"`, `"Write file"`) */
1109
confirmationTitle?: StringOrMarkdown;
1110
/** File edits that this tool call will perform, for preview before confirmation */
1111
edits?: { items: FileEdit[] };
1112
/** Whether the agent host allows the client to edit the tool's input parameters before confirming */
1113
editable?: boolean;
1114
/**
1115
* Options the server offers for this confirmation. When present, the client
1116
* SHOULD render these instead of a plain approve/deny UI. Each option
1117
* belongs to a {@link ConfirmationOptionGroup} so the client can still
1118
* categorise the choices.
1119
*/
1120
options?: ConfirmationOption[];
1121
}
1122
1123
/**
1124
* Tool is actively executing.
1125
*
1126
* @category Tool Call Types
1127
*/
1128
export interface ToolCallRunningState extends ToolCallBase, ToolCallParameterFields {
1129
status: ToolCallStatus.Running;
1130
/** How the tool was confirmed for execution */
1131
confirmed: ToolCallConfirmationReason;
1132
/** The confirmation option the user selected, if confirmation options were provided */
1133
selectedOption?: ConfirmationOption;
1134
/**
1135
* Partial content produced while the tool is still executing.
1136
*
1137
* For example, a terminal content block lets clients subscribe to live
1138
* output before the tool completes.
1139
*/
1140
content?: ToolResultContent[];
1141
}
1142
1143
/**
1144
* Tool finished executing, waiting for client to approve the result.
1145
*
1146
* @category Tool Call Types
1147
*/
1148
export interface ToolCallPendingResultConfirmationState extends ToolCallBase, ToolCallParameterFields, ToolCallResult {
1149
status: ToolCallStatus.PendingResultConfirmation;
1150
/** How the tool was confirmed for execution */
1151
confirmed: ToolCallConfirmationReason;
1152
/** The confirmation option the user selected, if confirmation options were provided */
1153
selectedOption?: ConfirmationOption;
1154
}
1155
1156
/**
1157
* Tool completed successfully or with an error.
1158
*
1159
* @category Tool Call Types
1160
*/
1161
export interface ToolCallCompletedState extends ToolCallBase, ToolCallParameterFields, ToolCallResult {
1162
status: ToolCallStatus.Completed;
1163
/** How the tool was confirmed for execution */
1164
confirmed: ToolCallConfirmationReason;
1165
/** The confirmation option the user selected, if confirmation options were provided */
1166
selectedOption?: ConfirmationOption;
1167
}
1168
1169
/**
1170
* Tool call was cancelled before execution.
1171
*
1172
* @category Tool Call Types
1173
*/
1174
export interface ToolCallCancelledState extends ToolCallBase, ToolCallParameterFields {
1175
status: ToolCallStatus.Cancelled;
1176
/** Why the tool was cancelled */
1177
reason: ToolCallCancellationReason;
1178
/** Optional message explaining the cancellation */
1179
reasonMessage?: StringOrMarkdown;
1180
/** What the user suggested doing instead */
1181
userSuggestion?: UserMessage;
1182
/** The confirmation option the user selected, if confirmation options were provided */
1183
selectedOption?: ConfirmationOption;
1184
}
1185
1186
/**
1187
* Discriminated union of all tool call lifecycle states.
1188
*
1189
* See the [state model guide](/guide/state-model.html#tool-call-lifecycle)
1190
* for the full state machine diagram.
1191
*
1192
* @category Tool Call Types
1193
*/
1194
export type ToolCallState =
1195
| ToolCallStreamingState
1196
| ToolCallPendingConfirmationState
1197
| ToolCallRunningState
1198
| ToolCallPendingResultConfirmationState
1199
| ToolCallCompletedState
1200
| ToolCallCancelledState;
1201
1202
// ─── Tool Definition Types ───────────────────────────────────────────────────
1203
1204
/**
1205
* Describes a tool available in a session, provided by either the server or the active client.
1206
*
1207
* @category Tool Definition Types
1208
*/
1209
export interface ToolDefinition {
1210
/** Unique tool identifier */
1211
name: string;
1212
/** Human-readable display name */
1213
title?: string;
1214
/** Description of what the tool does */
1215
description?: string;
1216
/**
1217
* JSON Schema defining the expected input parameters.
1218
*
1219
* Optional because client-provided tools may not have formal schemas.
1220
* Mirrors MCP `Tool.inputSchema`.
1221
*/
1222
inputSchema?: {
1223
type: 'object';
1224
properties?: Record<string, object>;
1225
required?: string[];
1226
};
1227
/**
1228
* JSON Schema defining the structure of the tool's output.
1229
*
1230
* Mirrors MCP `Tool.outputSchema`.
1231
*/
1232
outputSchema?: {
1233
type: 'object';
1234
properties?: Record<string, object>;
1235
required?: string[];
1236
};
1237
/** Behavioral hints about the tool. All properties are advisory. */
1238
annotations?: ToolAnnotations;
1239
/**
1240
* Additional provider-specific metadata.
1241
*
1242
* Mirrors the MCP `_meta` convention.
1243
*/
1244
_meta?: Record<string, unknown>;
1245
}
1246
1247
/**
1248
* Behavioral hints about a tool. All properties are advisory and not
1249
* guaranteed to faithfully describe tool behavior.
1250
*
1251
* Mirrors MCP `ToolAnnotations` from the Model Context Protocol specification.
1252
*
1253
* @category Tool Definition Types
1254
*/
1255
export interface ToolAnnotations {
1256
/** Alternate human-readable title */
1257
title?: string;
1258
/** Tool does not modify its environment (default: false) */
1259
readOnlyHint?: boolean;
1260
/** Tool may perform destructive updates (default: true) */
1261
destructiveHint?: boolean;
1262
/** Repeated calls with the same arguments have no additional effect (default: false) */
1263
idempotentHint?: boolean;
1264
/** Tool may interact with external entities (default: true) */
1265
openWorldHint?: boolean;
1266
}
1267
1268
// ─── Tool Result Content ─────────────────────────────────────────────────────
1269
1270
/**
1271
* Discriminant for tool result content types.
1272
*
1273
* @category Tool Result Content
1274
*/
1275
export const enum ToolResultContentType {
1276
Text = 'text',
1277
EmbeddedResource = 'embeddedResource',
1278
Resource = 'resource',
1279
FileEdit = 'fileEdit',
1280
Terminal = 'terminal',
1281
Subagent = 'subagent',
1282
}
1283
1284
/**
1285
* Text content in a tool result.
1286
*
1287
* Mirrors MCP `TextContent`.
1288
*
1289
* @category Tool Result Content
1290
*/
1291
export interface ToolResultTextContent {
1292
type: ToolResultContentType.Text;
1293
/** The text content */
1294
text: string;
1295
}
1296
1297
/**
1298
* Base64-encoded binary content embedded in a tool result.
1299
*
1300
* Mirrors MCP `EmbeddedResource` for inline binary data.
1301
*
1302
* @category Tool Result Content
1303
*/
1304
export interface ToolResultEmbeddedResourceContent {
1305
type: ToolResultContentType.EmbeddedResource;
1306
/** Base64-encoded data */
1307
data: string;
1308
/** Content type (e.g. `"image/png"`, `"application/pdf"`) */
1309
contentType: string;
1310
}
1311
1312
/**
1313
* A reference to a resource stored outside the tool result.
1314
*
1315
* Wraps {@link ContentRef} for lazy-loading large results.
1316
*
1317
* @category Tool Result Content
1318
*/
1319
export interface ToolResultResourceContent extends ContentRef {
1320
type: ToolResultContentType.Resource;
1321
}
1322
1323
/**
1324
* Describes a file modification with before/after state and diff metadata.
1325
*
1326
* Supports creates (only `after`), deletes (only `before`), renames/moves
1327
* (different `uri` in `before` and `after`), and edits (same `uri`, different content).
1328
*
1329
* @category Tool Result Content
1330
*/
1331
export interface FileEdit {
1332
/** The file state before the edit. Absent for file creations or for in-place file edits. */
1333
before?: {
1334
/** URI of the file before the edit */
1335
uri: URI;
1336
/** Reference to the file content before the edit */
1337
content: ContentRef;
1338
};
1339
/** The file state after the edit. Absent for file deletions. */
1340
after?: {
1341
/** URI of the file after the edit */
1342
uri: URI;
1343
/** Reference to the file content after the edit */
1344
content: ContentRef;
1345
};
1346
/** Optional diff display metadata */
1347
diff?: {
1348
/** Number of items added (e.g., lines for text files, cells for notebooks) */
1349
added?: number;
1350
/** Number of items removed (e.g., lines for text files, cells for notebooks) */
1351
removed?: number;
1352
};
1353
}
1354
1355
/**
1356
* Describes a file modification performed by a tool.
1357
*
1358
* @category Tool Result Content
1359
*/
1360
export interface ToolResultFileEditContent extends FileEdit {
1361
type: ToolResultContentType.FileEdit;
1362
}
1363
1364
/**
1365
* A reference to a terminal whose output is relevant to this tool result.
1366
*
1367
* Clients can subscribe to the terminal's URI to stream its output in real
1368
* time, providing live feedback while a tool is executing.
1369
*
1370
* @category Tool Result Content
1371
*/
1372
export interface ToolResultTerminalContent {
1373
type: ToolResultContentType.Terminal;
1374
/** Terminal URI (subscribable for full terminal state) */
1375
resource: URI;
1376
/** Display title for the terminal content */
1377
title: string;
1378
}
1379
1380
/**
1381
* A reference to a subagent session spawned by a tool.
1382
*
1383
* Clients can subscribe to the subagent's session URI to stream its
1384
* progress in real time, including inner tool calls and responses.
1385
*
1386
* @category Tool Result Content
1387
*/
1388
export interface ToolResultSubagentContent {
1389
type: ToolResultContentType.Subagent;
1390
/** Subagent session URI (subscribable for full session state) */
1391
resource: URI;
1392
/** Display title for the subagent */
1393
title: string;
1394
/** Internal agent name */
1395
agentName?: string;
1396
/** Human-readable description of the subagent's task */
1397
description?: string;
1398
}
1399
1400
/**
1401
* Content block in a tool result.
1402
*
1403
* Mirrors the content blocks in MCP `CallToolResult.content`, plus
1404
* `ToolResultResourceContent` for lazy-loading large results,
1405
* `ToolResultFileEditContent` for file edit diffs,
1406
* `ToolResultTerminalContent` for live terminal output, and
1407
* `ToolResultSubagentContent` for subagent sessions (AHP extensions).
1408
*
1409
* @category Tool Result Content
1410
*/
1411
export type ToolResultContent =
1412
| ToolResultTextContent
1413
| ToolResultEmbeddedResourceContent
1414
| ToolResultResourceContent
1415
| ToolResultFileEditContent
1416
| ToolResultTerminalContent
1417
| ToolResultSubagentContent;
1418
1419
// ─── Customization Types ─────────────────────────────────────────────────────
1420
1421
/**
1422
* A reference to an [Open Plugins](https://open-plugins.com/) plugin.
1423
*
1424
* This is intentionally thin — AHP specifies plugin identity and metadata
1425
* but not implementation details, which are defined by the Open Plugins spec.
1426
*
1427
* @category Customization Types
1428
*/
1429
export interface CustomizationRef {
1430
/** Plugin URI (e.g. an HTTPS URL or marketplace identifier) */
1431
uri: URI;
1432
/** Human-readable name */
1433
displayName: string;
1434
/** Description of what the plugin provides */
1435
description?: string;
1436
/** Icons for the plugin */
1437
icons?: Icon[];
1438
/**
1439
* Opaque version token for this customization.
1440
*
1441
* Clients SHOULD include a nonce with every customization they provide.
1442
* Consumers can compare nonces to detect whether a customization has
1443
* changed since it was last seen, avoiding redundant reloads or copies.
1444
*/
1445
nonce?: string;
1446
}
1447
1448
/**
1449
* Loading status for a server-managed customization.
1450
*
1451
* @category Customization Types
1452
*/
1453
export const enum CustomizationStatus {
1454
/** Plugin is being loaded */
1455
Loading = 'loading',
1456
/** Plugin is fully operational */
1457
Loaded = 'loaded',
1458
/** Plugin partially loaded but has warnings */
1459
Degraded = 'degraded',
1460
/** Plugin was unable to load */
1461
Error = 'error',
1462
}
1463
1464
/**
1465
* A customization active in a session.
1466
*
1467
* @category Customization Types
1468
*/
1469
export interface SessionCustomization {
1470
/** The plugin this customization refers to */
1471
customization: CustomizationRef;
1472
/** Whether this customization is currently enabled */
1473
enabled: boolean;
1474
/**
1475
* The `clientId` of the client that contributed this customization.
1476
* Absent for host-provided customizations.
1477
*/
1478
clientId?: string;
1479
/** Server-reported loading status */
1480
status?: CustomizationStatus;
1481
/**
1482
* Human-readable status detail (e.g. error message or degradation warning).
1483
*/
1484
statusMessage?: string;
1485
}
1486
1487
// ─── Terminal Types ──────────────────────────────────────────────────────────
1488
1489
/**
1490
* Lightweight terminal metadata exposed on the root state.
1491
*
1492
* @category Terminal Types
1493
*/
1494
export interface TerminalInfo {
1495
/** Terminal URI (subscribable for full terminal state) */
1496
resource: URI;
1497
/** Human-readable terminal title */
1498
title: string;
1499
/** Who currently holds this terminal */
1500
claim: TerminalClaim;
1501
/** Process exit code, if the terminal process has exited */
1502
exitCode?: number;
1503
}
1504
1505
/**
1506
* Discriminant for terminal claim kinds.
1507
*
1508
* @category Terminal Types
1509
*/
1510
export const enum TerminalClaimKind {
1511
Client = 'client',
1512
Session = 'session',
1513
}
1514
1515
/**
1516
* A terminal claimed by a connected client.
1517
*
1518
* @category Terminal Types
1519
*/
1520
export interface TerminalClientClaim {
1521
/** Discriminant */
1522
kind: TerminalClaimKind.Client;
1523
/** The `clientId` of the claiming client */
1524
clientId: string;
1525
}
1526
1527
/**
1528
* A terminal claimed by a session, optionally scoped to a specific turn or tool call.
1529
*
1530
* @category Terminal Types
1531
*/
1532
export interface TerminalSessionClaim {
1533
/** Discriminant */
1534
kind: TerminalClaimKind.Session;
1535
/** Session URI that claimed the terminal */
1536
session: URI;
1537
/** Optional turn identifier within the session */
1538
turnId?: string;
1539
/** Optional tool call identifier within the turn */
1540
toolCallId?: string;
1541
}
1542
1543
/**
1544
* Describes who currently holds a terminal. A terminal may be claimed by
1545
* either a connected client or a session (e.g. during a tool call).
1546
*
1547
* @category Terminal Types
1548
*/
1549
export type TerminalClaim = TerminalClientClaim | TerminalSessionClaim;
1550
1551
/**
1552
* Full state for a single terminal, loaded when a client subscribes to the terminal's URI.
1553
*
1554
* @category Terminal Types
1555
*/
1556
export interface TerminalState {
1557
/** Human-readable terminal title */
1558
title: string;
1559
/** Current working directory of the terminal process */
1560
cwd?: URI;
1561
/** Terminal width in columns */
1562
cols?: number;
1563
/** Terminal height in rows */
1564
rows?: number;
1565
/**
1566
* Typed content parts, replacing the flat `content: string`.
1567
*
1568
* Naive consumers that only need the raw VT stream can reconstruct it with:
1569
* `content.map(p => p.type === 'command' ? p.output : p.value).join('')`
1570
*
1571
* Consumers that need command boundaries can filter by part type.
1572
*/
1573
content: TerminalContentPart[];
1574
/** Process exit code, set when the terminal process exits */
1575
exitCode?: number;
1576
/** Who currently holds this terminal */
1577
claim: TerminalClaim;
1578
/**
1579
* Whether this terminal emits `terminal/commandExecuted` and
1580
* `terminal/commandFinished` actions and populates `command`-typed parts.
1581
*
1582
* Clients MUST check this flag before relying on command detection.
1583
* Do NOT use the presence of a `command` part as a feature flag — parts
1584
* are absent in the normal idle state.
1585
*/
1586
supportsCommandDetection?: boolean;
1587
}
1588
1589
// ─── Terminal Content Parts ──────────────────────────────────────────────────
1590
1591
/**
1592
* A content part within terminal output.
1593
*
1594
* @category Terminal Types
1595
*/
1596
export type TerminalContentPart =
1597
| TerminalUnclassifiedPart
1598
| TerminalCommandPart;
1599
1600
/**
1601
* Unstructured terminal output — content before, between, or after commands,
1602
* or from terminals that do not support command detection.
1603
*
1604
* @category Terminal Types
1605
*/
1606
export interface TerminalUnclassifiedPart {
1607
type: 'unclassified';
1608
/** Accumulated VT output. Appended to by `terminal/data` when no command is executing. */
1609
value: string;
1610
}
1611
1612
/**
1613
* A single command: its command line and the output it produced.
1614
*
1615
* While `isComplete` is false the command is still executing; `output` grows
1616
* as `terminal/data` actions arrive. At `terminal/commandFinished` the part
1617
* is mutated in-place with `isComplete: true` and the completion metadata.
1618
*
1619
* @category Terminal Types
1620
*/
1621
export interface TerminalCommandPart {
1622
type: 'command';
1623
/**
1624
* Stable id matching the `commandId` on the corresponding
1625
* `terminal/commandExecuted` and `terminal/commandFinished` actions.
1626
*/
1627
commandId: string;
1628
/** The command line submitted to the shell. */
1629
commandLine: string;
1630
/**
1631
* Accumulated VT output. Appended to by `terminal/data` while `isComplete`
1632
* is false. Shell integration escape sequences are stripped by the server.
1633
*/
1634
output: string;
1635
/** Unix timestamp (ms) when execution started, as reported by the server. */
1636
timestamp: number;
1637
/** Whether the command has finished. */
1638
isComplete: boolean;
1639
/** Shell exit code. Set at completion. `undefined` if unknown. */
1640
exitCode?: number;
1641
/** Wall-clock duration in milliseconds. Set at completion. */
1642
durationMs?: number;
1643
}
1644
1645
// ─── Common Types ────────────────────────────────────────────────────────────
1646
1647
/**
1648
* @category Common Types
1649
*/
1650
export interface UsageInfo {
1651
/** Input tokens consumed */
1652
inputTokens?: number;
1653
/** Output tokens generated */
1654
outputTokens?: number;
1655
/** Model used */
1656
model?: string;
1657
/** Tokens read from cache */
1658
cacheReadTokens?: number;
1659
}
1660
1661
/**
1662
* @category Common Types
1663
*/
1664
export interface ErrorInfo {
1665
/** Error type identifier */
1666
errorType: string;
1667
/** Human-readable error message */
1668
message: string;
1669
/** Stack trace */
1670
stack?: string;
1671
}
1672
1673
/**
1674
* A point-in-time snapshot of a subscribed resource's state, returned by
1675
* `initialize`, `reconnect`, and `subscribe`.
1676
*
1677
* @category Common Types
1678
*/
1679
export interface Snapshot {
1680
/** The subscribed resource URI (e.g. `agenthost:/root` or `copilot:/<uuid>`) */
1681
resource: URI;
1682
/** The current state of the resource */
1683
state: RootState | SessionState | TerminalState;
1684
/** The `serverSeq` at which this snapshot was taken. Subsequent actions will have `serverSeq > fromSeq`. */
1685
fromSeq: number;
1686
}
1687
1688