@mseep/obsidian-agent-client 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/hooks/gh-setup.sh +49 -0
- package/.claude/settings.json +15 -0
- package/.claude/skills/release-notes/SKILL.md +331 -0
- package/.editorconfig +10 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +90 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +59 -0
- package/.github/copilot-instructions.md +45 -0
- package/.github/pull_request_template.md +32 -0
- package/.github/workflows/ci.yaml +25 -0
- package/.github/workflows/docs.yml +58 -0
- package/.github/workflows/relay_to_openclaw.yml +59 -0
- package/.github/workflows/release.yaml +45 -0
- package/.prettierignore +10 -0
- package/.prettierrc +13 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +37 -0
- package/.zed/settings.json +42 -0
- package/AGENTS.md +330 -0
- package/ARCHITECTURE.md +390 -0
- package/CONTRIBUTING.md +216 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.ja.md +121 -0
- package/README.md +125 -0
- package/docs/.vitepress/config.mts +124 -0
- package/docs/.vitepress/theme/custom.css +111 -0
- package/docs/.vitepress/theme/index.ts +4 -0
- package/docs/agent-setup/claude-code.md +84 -0
- package/docs/agent-setup/codex.md +76 -0
- package/docs/agent-setup/custom-agents.md +67 -0
- package/docs/agent-setup/gemini-cli.md +99 -0
- package/docs/agent-setup/index.md +34 -0
- package/docs/announcements/gemini-cli-deprecation.md +73 -0
- package/docs/getting-started/index.md +78 -0
- package/docs/getting-started/quick-start.md +38 -0
- package/docs/help/faq.md +181 -0
- package/docs/help/troubleshooting.md +221 -0
- package/docs/index.md +63 -0
- package/docs/public/apple-touch-icon.png +0 -0
- package/docs/public/demo.mp4 +0 -0
- package/docs/public/favicon-16x16.png +0 -0
- package/docs/public/favicon-32x32.png +0 -0
- package/docs/public/favicon.ico +0 -0
- package/docs/public/images/editing.webp +0 -0
- package/docs/public/images/export.webp +0 -0
- package/docs/public/images/floating-chat-button.webp +0 -0
- package/docs/public/images/floating-chat-instance-menu.webp +0 -0
- package/docs/public/images/floating-chat-view.webp +0 -0
- package/docs/public/images/mode-selection.webp +0 -0
- package/docs/public/images/model-selection.webp +0 -0
- package/docs/public/images/multi-session.webp +0 -0
- package/docs/public/images/remove-image.webp +0 -0
- package/docs/public/images/ribbon-icon.webp +0 -0
- package/docs/public/images/selection-context.gif +0 -0
- package/docs/public/images/sending-images.webp +0 -0
- package/docs/public/images/sending-messages.webp +0 -0
- package/docs/public/images/session-history-button.webp +0 -0
- package/docs/public/images/slash-commands-1.webp +0 -0
- package/docs/public/images/slash-commands-2.webp +0 -0
- package/docs/public/images/switch-agent.webp +0 -0
- package/docs/public/images/switch-default-agent.webp +0 -0
- package/docs/public/images/temporary-disable.gif +0 -0
- package/docs/reference/acp-support.md +110 -0
- package/docs/usage/chat-export.md +80 -0
- package/docs/usage/commands.md +51 -0
- package/docs/usage/context-files.md +57 -0
- package/docs/usage/editing.md +69 -0
- package/docs/usage/floating-chat.md +84 -0
- package/docs/usage/index.md +97 -0
- package/docs/usage/mcp-tools.md +33 -0
- package/docs/usage/mentions.md +70 -0
- package/docs/usage/mode-selection.md +28 -0
- package/docs/usage/model-selection.md +32 -0
- package/docs/usage/multi-session.md +68 -0
- package/docs/usage/sending-images.md +64 -0
- package/docs/usage/session-history.md +91 -0
- package/docs/usage/slash-commands.md +44 -0
- package/esbuild.config.mjs +49 -0
- package/eslint.config.mjs +25 -0
- package/main.js +228 -0
- package/manifest.json +11 -0
- package/package.json +52 -0
- package/src/acp/acp-client.ts +921 -0
- package/src/acp/acp-handler.ts +252 -0
- package/src/acp/permission-handler.ts +282 -0
- package/src/acp/terminal-handler.ts +264 -0
- package/src/acp/type-converter.ts +272 -0
- package/src/hooks/useAgent.ts +250 -0
- package/src/hooks/useAgentMessages.ts +470 -0
- package/src/hooks/useAgentSession.ts +544 -0
- package/src/hooks/useChatActions.ts +400 -0
- package/src/hooks/useHistoryModal.ts +219 -0
- package/src/hooks/useSessionHistory.ts +863 -0
- package/src/hooks/useSettings.ts +19 -0
- package/src/hooks/useSuggestions.ts +342 -0
- package/src/main.ts +9 -0
- package/src/plugin.ts +1126 -0
- package/src/services/chat-exporter.ts +552 -0
- package/src/services/message-sender.ts +755 -0
- package/src/services/message-state.ts +375 -0
- package/src/services/session-helpers.ts +211 -0
- package/src/services/session-state.ts +130 -0
- package/src/services/session-storage.ts +267 -0
- package/src/services/settings-normalizer.ts +255 -0
- package/src/services/settings-service.ts +285 -0
- package/src/services/update-checker.ts +128 -0
- package/src/services/vault-service.ts +558 -0
- package/src/services/view-registry.ts +345 -0
- package/src/types/agent.ts +92 -0
- package/src/types/chat.ts +351 -0
- package/src/types/errors.ts +136 -0
- package/src/types/obsidian-internals.d.ts +14 -0
- package/src/types/session.ts +731 -0
- package/src/ui/ChangeDirectoryModal.ts +137 -0
- package/src/ui/ChatContext.ts +25 -0
- package/src/ui/ChatHeader.tsx +295 -0
- package/src/ui/ChatPanel.tsx +1162 -0
- package/src/ui/ChatView.tsx +348 -0
- package/src/ui/ErrorBanner.tsx +104 -0
- package/src/ui/FloatingButton.tsx +351 -0
- package/src/ui/FloatingChatView.tsx +531 -0
- package/src/ui/InputArea.tsx +1107 -0
- package/src/ui/InputToolbar.tsx +371 -0
- package/src/ui/MessageBubble.tsx +442 -0
- package/src/ui/MessageList.tsx +265 -0
- package/src/ui/PermissionBanner.tsx +61 -0
- package/src/ui/SessionHistoryModal.tsx +821 -0
- package/src/ui/SettingsTab.ts +1337 -0
- package/src/ui/SuggestionPopup.tsx +138 -0
- package/src/ui/TerminalBlock.tsx +107 -0
- package/src/ui/ToolCallBlock.tsx +456 -0
- package/src/ui/shared/AttachmentStrip.tsx +57 -0
- package/src/ui/shared/IconButton.tsx +55 -0
- package/src/ui/shared/MarkdownRenderer.tsx +103 -0
- package/src/ui/view-host.ts +56 -0
- package/src/utils/error-utils.ts +274 -0
- package/src/utils/logger.ts +44 -0
- package/src/utils/mention-parser.ts +129 -0
- package/src/utils/paths.ts +246 -0
- package/src/utils/platform.ts +425 -0
- package/styles.css +2322 -0
- package/tsconfig.json +18 -0
- package/version-bump.mjs +18 -0
- package/versions.json +3 -0
|
@@ -0,0 +1,731 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain Models for Chat Sessions
|
|
3
|
+
*
|
|
4
|
+
* These types represent the state and lifecycle of an agent chat session,
|
|
5
|
+
* independent of the ACP protocol implementation. They encapsulate connection
|
|
6
|
+
* state, authentication, and session metadata.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Session State
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents the current state of a chat session.
|
|
15
|
+
*
|
|
16
|
+
* State transitions:
|
|
17
|
+
* - initializing: Connection is being established
|
|
18
|
+
* - authenticating: User authentication in progress
|
|
19
|
+
* - ready: Session is ready to send/receive messages
|
|
20
|
+
* - busy: Agent is processing a request
|
|
21
|
+
* - error: An error occurred (connection failed, etc.)
|
|
22
|
+
* - disconnected: Session has been closed
|
|
23
|
+
*/
|
|
24
|
+
export type SessionState =
|
|
25
|
+
| "initializing" // Connection is being established
|
|
26
|
+
| "authenticating" // User authentication in progress
|
|
27
|
+
| "ready" // Ready to send/receive messages
|
|
28
|
+
| "busy" // Agent is processing a request
|
|
29
|
+
| "error" // An error occurred
|
|
30
|
+
| "disconnected"; // Session has been closed
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Authentication
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Authentication method available for the session.
|
|
38
|
+
*
|
|
39
|
+
* Simplified from ACP's AuthMethod to domain concept.
|
|
40
|
+
* Represents a way the user can authenticate with the agent
|
|
41
|
+
* (e.g., API key, OAuth, etc.)
|
|
42
|
+
*/
|
|
43
|
+
export interface AuthenticationMethod {
|
|
44
|
+
/** Unique identifier for this authentication method */
|
|
45
|
+
id: string;
|
|
46
|
+
|
|
47
|
+
/** Human-readable name (e.g., "API Key", "OAuth") */
|
|
48
|
+
name: string;
|
|
49
|
+
|
|
50
|
+
/** Optional description of the authentication method */
|
|
51
|
+
description?: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Slash Commands
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Represents a slash command available in the current session.
|
|
60
|
+
*
|
|
61
|
+
* Slash commands provide quick access to specific agent capabilities
|
|
62
|
+
* and workflows (e.g., /web, /test, /plan). They are advertised by
|
|
63
|
+
* the agent via the ACP protocol's `available_commands_update` notification.
|
|
64
|
+
*
|
|
65
|
+
* Commands can be invoked by users by typing `/` followed by the command
|
|
66
|
+
* name and optional input in the chat input field.
|
|
67
|
+
*/
|
|
68
|
+
export interface SlashCommand {
|
|
69
|
+
/** Command name (e.g., "web", "test", "plan") */
|
|
70
|
+
name: string;
|
|
71
|
+
|
|
72
|
+
/** Human-readable description of what the command does */
|
|
73
|
+
description: string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Hint text to display when the command expects additional input.
|
|
77
|
+
* If null or undefined, the command does not require additional input.
|
|
78
|
+
*
|
|
79
|
+
* Example: "query to search for" for the /web command
|
|
80
|
+
*/
|
|
81
|
+
hint?: string | null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Session Mode
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Represents a mode available in the current session.
|
|
90
|
+
*
|
|
91
|
+
* Modes define how the agent behaves and processes requests.
|
|
92
|
+
* For example, "build" mode for implementation tasks, "plan" mode for
|
|
93
|
+
* architecture and design discussions.
|
|
94
|
+
*
|
|
95
|
+
* Modes are advertised by the agent in the NewSessionResponse and can
|
|
96
|
+
* be changed during the session via the ACP protocol.
|
|
97
|
+
*/
|
|
98
|
+
/** DEPRECATED: Use SessionConfigOption instead. Kept for backward compatibility. */
|
|
99
|
+
export interface SessionMode {
|
|
100
|
+
/** Unique identifier for this mode (e.g., "build", "plan") */
|
|
101
|
+
id: string;
|
|
102
|
+
|
|
103
|
+
/** Human-readable name for display */
|
|
104
|
+
name: string;
|
|
105
|
+
|
|
106
|
+
/** Optional description of what this mode does */
|
|
107
|
+
description?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* State of available modes in a session.
|
|
112
|
+
*
|
|
113
|
+
* Contains both the list of available modes and the currently active mode.
|
|
114
|
+
* Updated via NewSessionResponse initially and current_mode_update notifications.
|
|
115
|
+
*/
|
|
116
|
+
/** DEPRECATED: Use SessionConfigOption instead. Kept for backward compatibility. */
|
|
117
|
+
export interface SessionModeState {
|
|
118
|
+
/** List of modes available in this session */
|
|
119
|
+
availableModes: SessionMode[];
|
|
120
|
+
|
|
121
|
+
/** ID of the currently active mode */
|
|
122
|
+
currentModeId: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ============================================================================
|
|
126
|
+
// Model (Experimental)
|
|
127
|
+
// ============================================================================
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Represents an AI model available in a session.
|
|
131
|
+
*
|
|
132
|
+
* Models determine which AI model is used for responses.
|
|
133
|
+
* This is an experimental feature and may change.
|
|
134
|
+
*/
|
|
135
|
+
/** DEPRECATED: Use SessionConfigOption instead. Kept for backward compatibility. */
|
|
136
|
+
export interface SessionModel {
|
|
137
|
+
/** Unique identifier for this model (e.g., "claude-sonnet-4") */
|
|
138
|
+
modelId: string;
|
|
139
|
+
|
|
140
|
+
/** Human-readable name for display */
|
|
141
|
+
name: string;
|
|
142
|
+
|
|
143
|
+
/** Optional description of this model */
|
|
144
|
+
description?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* State of available models in a session.
|
|
149
|
+
*
|
|
150
|
+
* Contains both the list of available models and the currently active model.
|
|
151
|
+
* Updated via NewSessionResponse initially.
|
|
152
|
+
* Note: Unlike modes, there is no dedicated notification for model changes.
|
|
153
|
+
*/
|
|
154
|
+
/** DEPRECATED: Use SessionConfigOption instead. Kept for backward compatibility. */
|
|
155
|
+
export interface SessionModelState {
|
|
156
|
+
/** List of models available in this session */
|
|
157
|
+
availableModels: SessionModel[];
|
|
158
|
+
|
|
159
|
+
/** ID of the currently active model */
|
|
160
|
+
currentModelId: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Context window usage and cost information for a session.
|
|
165
|
+
* Reported by the agent via `usage_update` session notifications.
|
|
166
|
+
*/
|
|
167
|
+
export interface SessionUsage {
|
|
168
|
+
/** Tokens currently in context */
|
|
169
|
+
used: number;
|
|
170
|
+
/** Total context window size in tokens */
|
|
171
|
+
size: number;
|
|
172
|
+
/** Cumulative session cost (optional — not all agents track this) */
|
|
173
|
+
cost?: { amount: number; currency: string };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ============================================================================
|
|
177
|
+
// Chat Session
|
|
178
|
+
// ============================================================================
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Represents a chat session with an AI agent.
|
|
182
|
+
*
|
|
183
|
+
* A session encapsulates:
|
|
184
|
+
* - Connection state and readiness
|
|
185
|
+
* - Authentication status and available methods
|
|
186
|
+
* - Current agent configuration
|
|
187
|
+
* - Session lifecycle metadata (creation time, last activity)
|
|
188
|
+
* - Working directory for file operations
|
|
189
|
+
*
|
|
190
|
+
* Sessions are created when connecting to an agent and persist until
|
|
191
|
+
* the user creates a new session or disconnects.
|
|
192
|
+
*/
|
|
193
|
+
export interface ChatSession {
|
|
194
|
+
/** Unique identifier for this session (null if not yet created) */
|
|
195
|
+
sessionId: string | null;
|
|
196
|
+
|
|
197
|
+
/** Current state of the session */
|
|
198
|
+
state: SessionState;
|
|
199
|
+
|
|
200
|
+
/** ID of the active agent (claude, gemini, or custom agent ID) */
|
|
201
|
+
agentId: string;
|
|
202
|
+
|
|
203
|
+
/** Display name of the agent at session creation time */
|
|
204
|
+
agentDisplayName: string;
|
|
205
|
+
|
|
206
|
+
/** Available authentication methods for this session */
|
|
207
|
+
authMethods: AuthenticationMethod[];
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Slash commands available in this session.
|
|
211
|
+
* Updated dynamically via ACP's `available_commands_update` notification.
|
|
212
|
+
*/
|
|
213
|
+
availableCommands?: SlashCommand[];
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* DEPRECATED: Use configOptions instead. Kept for backward compatibility
|
|
217
|
+
* with agents that don't support configOptions.
|
|
218
|
+
*/
|
|
219
|
+
modes?: SessionModeState;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* DEPRECATED: Use configOptions instead. Kept for backward compatibility
|
|
223
|
+
* with agents that don't support configOptions.
|
|
224
|
+
*/
|
|
225
|
+
models?: SessionModelState;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Session configuration options (mode, model, thought_level, etc.).
|
|
229
|
+
* Supersedes legacy modes/models fields.
|
|
230
|
+
* When present, UI should use this instead of modes/models.
|
|
231
|
+
*/
|
|
232
|
+
configOptions?: SessionConfigOption[];
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Context window usage and cost information.
|
|
236
|
+
* Updated dynamically via ACP's `usage_update` notification.
|
|
237
|
+
* Agent sends this after each prompt response and on session load/resume.
|
|
238
|
+
*/
|
|
239
|
+
usage?: SessionUsage;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Prompt capabilities supported by the agent.
|
|
243
|
+
* Indicates which content types (image, audio, etc.) can be included in prompts.
|
|
244
|
+
* Set during initialization and persists for the session lifetime.
|
|
245
|
+
* (Convenience accessor - same as agentCapabilities.promptCapabilities)
|
|
246
|
+
*/
|
|
247
|
+
promptCapabilities?: PromptCapabilities;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Full agent capabilities from initialization.
|
|
251
|
+
* Contains loadSession, sessionCapabilities, mcpCapabilities, and promptCapabilities.
|
|
252
|
+
* Set during initialization and persists for the session lifetime.
|
|
253
|
+
*/
|
|
254
|
+
agentCapabilities?: AgentCapabilities;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Information about the connected agent.
|
|
258
|
+
* Contains agent name, title, and version.
|
|
259
|
+
* Set during initialization and persists for the session lifetime.
|
|
260
|
+
*/
|
|
261
|
+
agentInfo?: AgentInfo;
|
|
262
|
+
|
|
263
|
+
/** Timestamp when the session was created */
|
|
264
|
+
createdAt: Date;
|
|
265
|
+
|
|
266
|
+
/** Timestamp of the last activity in this session */
|
|
267
|
+
lastActivityAt: Date;
|
|
268
|
+
|
|
269
|
+
/** Working directory for agent file operations */
|
|
270
|
+
workingDirectory: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Domain Models for Session Updates
|
|
274
|
+
*
|
|
275
|
+
* These types represent session update events from the agent,
|
|
276
|
+
* independent of the ACP protocol implementation. They use the same
|
|
277
|
+
* type names as ACP's sessionUpdate values for consistency.
|
|
278
|
+
*
|
|
279
|
+
* The Adapter layer receives ACP notifications and converts them to
|
|
280
|
+
* these domain types, which are then handled by the application layer.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
import type {
|
|
284
|
+
PlanEntry,
|
|
285
|
+
ToolCallContent,
|
|
286
|
+
ToolCallLocation,
|
|
287
|
+
ToolKind,
|
|
288
|
+
ToolCallStatus,
|
|
289
|
+
PermissionOption,
|
|
290
|
+
} from "./chat";
|
|
291
|
+
import type { ProcessError } from "./errors";
|
|
292
|
+
|
|
293
|
+
// ============================================================================
|
|
294
|
+
// Base Type
|
|
295
|
+
// ============================================================================
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Base interface for all session updates.
|
|
299
|
+
* Contains the session ID that the update belongs to.
|
|
300
|
+
*/
|
|
301
|
+
interface SessionUpdateBase {
|
|
302
|
+
/** The session ID this update belongs to */
|
|
303
|
+
sessionId: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ============================================================================
|
|
307
|
+
// Session Update Types
|
|
308
|
+
// ============================================================================
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Text chunk from agent's message stream.
|
|
312
|
+
* Used for streaming text responses.
|
|
313
|
+
*/
|
|
314
|
+
export interface AgentMessageChunk extends SessionUpdateBase {
|
|
315
|
+
type: "agent_message_chunk";
|
|
316
|
+
text: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Text chunk from agent's internal reasoning.
|
|
321
|
+
* Used for streaming thought/reasoning content.
|
|
322
|
+
*/
|
|
323
|
+
export interface AgentThoughtChunk extends SessionUpdateBase {
|
|
324
|
+
type: "agent_thought_chunk";
|
|
325
|
+
text: string;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Text chunk from user's message during session/load.
|
|
330
|
+
* Used for reconstructing user messages when loading a saved session.
|
|
331
|
+
*/
|
|
332
|
+
export interface UserMessageChunk extends SessionUpdateBase {
|
|
333
|
+
type: "user_message_chunk";
|
|
334
|
+
text: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* New tool call event.
|
|
339
|
+
* Creates a new tool call in the message history.
|
|
340
|
+
*/
|
|
341
|
+
export interface ToolCall extends SessionUpdateBase {
|
|
342
|
+
type: "tool_call";
|
|
343
|
+
toolCallId: string;
|
|
344
|
+
title?: string;
|
|
345
|
+
status: ToolCallStatus;
|
|
346
|
+
kind?: ToolKind;
|
|
347
|
+
content?: ToolCallContent[];
|
|
348
|
+
locations?: ToolCallLocation[];
|
|
349
|
+
rawInput?: { [k: string]: unknown };
|
|
350
|
+
permissionRequest?: {
|
|
351
|
+
requestId: string;
|
|
352
|
+
options: PermissionOption[];
|
|
353
|
+
selectedOptionId?: string;
|
|
354
|
+
isCancelled?: boolean;
|
|
355
|
+
isActive?: boolean;
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Tool call update event.
|
|
361
|
+
* Updates an existing tool call with new information.
|
|
362
|
+
* Semantically identical to ToolCall for processing purposes.
|
|
363
|
+
*/
|
|
364
|
+
export interface ToolCallUpdate extends SessionUpdateBase {
|
|
365
|
+
type: "tool_call_update";
|
|
366
|
+
toolCallId: string;
|
|
367
|
+
title?: string;
|
|
368
|
+
status?: ToolCallStatus;
|
|
369
|
+
kind?: ToolKind;
|
|
370
|
+
content?: ToolCallContent[];
|
|
371
|
+
locations?: ToolCallLocation[];
|
|
372
|
+
rawInput?: { [k: string]: unknown };
|
|
373
|
+
permissionRequest?: {
|
|
374
|
+
requestId: string;
|
|
375
|
+
options: PermissionOption[];
|
|
376
|
+
selectedOptionId?: string;
|
|
377
|
+
isCancelled?: boolean;
|
|
378
|
+
isActive?: boolean;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Agent's execution plan.
|
|
384
|
+
* Contains a list of tasks the agent intends to accomplish.
|
|
385
|
+
*/
|
|
386
|
+
export interface Plan extends SessionUpdateBase {
|
|
387
|
+
type: "plan";
|
|
388
|
+
entries: PlanEntry[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Update to available slash commands.
|
|
393
|
+
* Sent when the agent's available commands change.
|
|
394
|
+
*/
|
|
395
|
+
export interface AvailableCommandsUpdate extends SessionUpdateBase {
|
|
396
|
+
type: "available_commands_update";
|
|
397
|
+
commands: SlashCommand[];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Update to current session mode.
|
|
402
|
+
* Sent when the agent switches to a different mode.
|
|
403
|
+
*/
|
|
404
|
+
export interface CurrentModeUpdate extends SessionUpdateBase {
|
|
405
|
+
type: "current_mode_update";
|
|
406
|
+
currentModeId: string;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Session info update (title, timestamp).
|
|
411
|
+
* Sent when the agent updates session metadata.
|
|
412
|
+
*/
|
|
413
|
+
export interface SessionInfoUpdate extends SessionUpdateBase {
|
|
414
|
+
type: "session_info_update";
|
|
415
|
+
title?: string | null;
|
|
416
|
+
updatedAt?: string | null;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Context window and cost update for a session.
|
|
421
|
+
* Sent periodically to report token usage and cost.
|
|
422
|
+
*/
|
|
423
|
+
export interface UsageUpdate extends SessionUpdateBase {
|
|
424
|
+
type: "usage_update";
|
|
425
|
+
/** Total context window size in tokens */
|
|
426
|
+
size: number;
|
|
427
|
+
/** Tokens currently in context */
|
|
428
|
+
used: number;
|
|
429
|
+
/** Cumulative session cost */
|
|
430
|
+
cost?: { amount: number; currency: string } | null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Session configuration options have been updated.
|
|
435
|
+
* Sent when the agent changes config options (mode, model, thought_level, etc.).
|
|
436
|
+
* Supersedes legacy modes/models API.
|
|
437
|
+
*/
|
|
438
|
+
export interface ConfigOptionUpdate extends SessionUpdateBase {
|
|
439
|
+
type: "config_option_update";
|
|
440
|
+
configOptions: SessionConfigOption[];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Process-level error event.
|
|
445
|
+
* Emitted when the agent process encounters a system error
|
|
446
|
+
* (spawn failure, command not found, etc.).
|
|
447
|
+
*/
|
|
448
|
+
export interface ProcessErrorUpdate extends SessionUpdateBase {
|
|
449
|
+
type: "process_error";
|
|
450
|
+
error: ProcessError;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ============================================================================
|
|
454
|
+
// Config Option Types
|
|
455
|
+
// ============================================================================
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* A session configuration option (e.g. mode, model, thought_level).
|
|
459
|
+
* Part of the ACP configOptions API that supersedes legacy modes/models.
|
|
460
|
+
*/
|
|
461
|
+
export interface SessionConfigOption {
|
|
462
|
+
id: string;
|
|
463
|
+
name: string;
|
|
464
|
+
description?: string | null;
|
|
465
|
+
category?: string | null;
|
|
466
|
+
type: "select";
|
|
467
|
+
currentValue: string;
|
|
468
|
+
options: SessionConfigSelectOption[] | SessionConfigSelectGroup[];
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface SessionConfigSelectOption {
|
|
472
|
+
value: string;
|
|
473
|
+
name: string;
|
|
474
|
+
description?: string | null;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export interface SessionConfigSelectGroup {
|
|
478
|
+
group: string;
|
|
479
|
+
name: string;
|
|
480
|
+
options: SessionConfigSelectOption[];
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Flatten grouped or flat config select options into a single array.
|
|
485
|
+
*/
|
|
486
|
+
export function flattenConfigSelectOptions(
|
|
487
|
+
options: SessionConfigSelectOption[] | SessionConfigSelectGroup[],
|
|
488
|
+
): SessionConfigSelectOption[] {
|
|
489
|
+
if (options.length === 0) return [];
|
|
490
|
+
if ("value" in options[0]) return options as SessionConfigSelectOption[];
|
|
491
|
+
return (options as SessionConfigSelectGroup[]).flatMap((g) => g.options);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ============================================================================
|
|
495
|
+
// Union Type
|
|
496
|
+
// ============================================================================
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Union of all session update types.
|
|
500
|
+
*
|
|
501
|
+
* These types correspond to ACP's SessionNotification.update.sessionUpdate values:
|
|
502
|
+
* - agent_message_chunk: Text chunk from agent's response
|
|
503
|
+
* - agent_thought_chunk: Text chunk from agent's reasoning
|
|
504
|
+
* - user_message_chunk: Text chunk from user's message (session/load)
|
|
505
|
+
* - tool_call: New tool call event
|
|
506
|
+
* - tool_call_update: Update to existing tool call
|
|
507
|
+
* - plan: Agent's task plan
|
|
508
|
+
* - available_commands_update: Slash commands changed
|
|
509
|
+
* - current_mode_update: Mode changed
|
|
510
|
+
* - session_info_update: Session metadata changed
|
|
511
|
+
* - usage_update: Context window and cost update
|
|
512
|
+
* - config_option_update: Session config options changed
|
|
513
|
+
*
|
|
514
|
+
* All session update types include a sessionId field to identify which
|
|
515
|
+
* session the update belongs to. This enables filtering/routing of updates
|
|
516
|
+
* in multi-session scenarios.
|
|
517
|
+
*/
|
|
518
|
+
export type SessionUpdate =
|
|
519
|
+
| AgentMessageChunk
|
|
520
|
+
| AgentThoughtChunk
|
|
521
|
+
| UserMessageChunk
|
|
522
|
+
| ToolCall
|
|
523
|
+
| ToolCallUpdate
|
|
524
|
+
| Plan
|
|
525
|
+
| AvailableCommandsUpdate
|
|
526
|
+
| CurrentModeUpdate
|
|
527
|
+
| SessionInfoUpdate
|
|
528
|
+
| UsageUpdate
|
|
529
|
+
| ConfigOptionUpdate
|
|
530
|
+
| ProcessErrorUpdate;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Session metadata from session/list response.
|
|
534
|
+
* Matches ACP SessionInfo type.
|
|
535
|
+
*/
|
|
536
|
+
export interface SessionInfo {
|
|
537
|
+
/** Unique session identifier */
|
|
538
|
+
sessionId: string;
|
|
539
|
+
/** Working directory for the session */
|
|
540
|
+
cwd: string;
|
|
541
|
+
/** Human-readable session title */
|
|
542
|
+
title?: string;
|
|
543
|
+
/** ISO 8601 timestamp of last update */
|
|
544
|
+
updatedAt?: string;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Result of session/list (unstable).
|
|
549
|
+
*/
|
|
550
|
+
export interface ListSessionsResult {
|
|
551
|
+
/** Array of session metadata */
|
|
552
|
+
sessions: SessionInfo[];
|
|
553
|
+
/** Cursor for pagination (load more sessions) */
|
|
554
|
+
nextCursor?: string;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Result of session operations (new, load, resume, fork).
|
|
559
|
+
*
|
|
560
|
+
* All session creation/restoration operations return the same structure:
|
|
561
|
+
* a session ID with optional mode/model/config state.
|
|
562
|
+
*
|
|
563
|
+
* Note: modes and models are DEPRECATED in favor of configOptions.
|
|
564
|
+
* They are kept for backward compatibility with agents that don't
|
|
565
|
+
* support configOptions yet.
|
|
566
|
+
*/
|
|
567
|
+
export interface SessionResult {
|
|
568
|
+
/** Unique session identifier */
|
|
569
|
+
sessionId: string;
|
|
570
|
+
|
|
571
|
+
/** DEPRECATED: Use configOptions instead. Kept for backward compatibility. */
|
|
572
|
+
modes?: SessionModeState;
|
|
573
|
+
|
|
574
|
+
/** DEPRECATED: Use configOptions instead. Kept for backward compatibility. */
|
|
575
|
+
models?: SessionModelState;
|
|
576
|
+
|
|
577
|
+
/** Session config options (supersedes modes/models) */
|
|
578
|
+
configOptions?: SessionConfigOption[];
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Locally saved session metadata.
|
|
583
|
+
*
|
|
584
|
+
* Used when agent doesn't support session/list but supports load/resume/fork.
|
|
585
|
+
* Saved to plugin settings via plugin.saveData().
|
|
586
|
+
*/
|
|
587
|
+
export interface SavedSessionInfo {
|
|
588
|
+
/** Unique session identifier */
|
|
589
|
+
sessionId: string;
|
|
590
|
+
/** Agent ID that created this session */
|
|
591
|
+
agentId: string;
|
|
592
|
+
/** Working directory for the session */
|
|
593
|
+
cwd: string;
|
|
594
|
+
/** Human-readable session title (first 50 chars of first user message) */
|
|
595
|
+
title?: string;
|
|
596
|
+
/** ISO 8601 timestamp of session creation */
|
|
597
|
+
createdAt: string;
|
|
598
|
+
/** ISO 8601 timestamp of last activity */
|
|
599
|
+
updatedAt: string;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Domain Models for Agent Initialization Results
|
|
603
|
+
*
|
|
604
|
+
* These types represent the result of agent initialization,
|
|
605
|
+
* including capabilities, agent info, and authentication methods.
|
|
606
|
+
* They are returned by AcpClient.initialize() and stored
|
|
607
|
+
* in ChatSession for the session lifetime.
|
|
608
|
+
*/
|
|
609
|
+
|
|
610
|
+
// ============================================================================
|
|
611
|
+
// Agent Capabilities
|
|
612
|
+
// ============================================================================
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Capabilities for prompt content types.
|
|
616
|
+
*
|
|
617
|
+
* Describes which content types the agent supports in prompts.
|
|
618
|
+
* All capabilities default to false if not specified.
|
|
619
|
+
*/
|
|
620
|
+
export interface PromptCapabilities {
|
|
621
|
+
/** Agent supports image content in prompts */
|
|
622
|
+
image?: boolean;
|
|
623
|
+
|
|
624
|
+
/** Agent supports audio content in prompts */
|
|
625
|
+
audio?: boolean;
|
|
626
|
+
|
|
627
|
+
/** Agent supports embedded context (Resource) in prompts */
|
|
628
|
+
embeddedContext?: boolean;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* MCP (Model Context Protocol) capabilities supported by the agent.
|
|
633
|
+
*/
|
|
634
|
+
export interface McpCapabilities {
|
|
635
|
+
/** Agent supports connecting to MCP servers over HTTP */
|
|
636
|
+
http?: boolean;
|
|
637
|
+
|
|
638
|
+
/** Agent supports connecting to MCP servers over SSE (deprecated) */
|
|
639
|
+
sse?: boolean;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Session-related capabilities (unstable features).
|
|
644
|
+
* From agentCapabilities.sessionCapabilities in initialize response.
|
|
645
|
+
*/
|
|
646
|
+
export interface SessionCapabilities {
|
|
647
|
+
/** session/resume support (unstable) */
|
|
648
|
+
resume?: Record<string, unknown>;
|
|
649
|
+
/** session/fork support (unstable) */
|
|
650
|
+
fork?: Record<string, unknown>;
|
|
651
|
+
/** session/list support (unstable) */
|
|
652
|
+
list?: Record<string, unknown>;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Full agent capabilities from ACP initialization.
|
|
657
|
+
*
|
|
658
|
+
* Contains all capability information returned by the agent,
|
|
659
|
+
* including session features, MCP support, and prompt capabilities.
|
|
660
|
+
*/
|
|
661
|
+
export interface AgentCapabilities {
|
|
662
|
+
/** Whether the agent supports session/load for resuming sessions (stable) */
|
|
663
|
+
loadSession?: boolean;
|
|
664
|
+
|
|
665
|
+
/** Session management capabilities (unstable features) */
|
|
666
|
+
sessionCapabilities?: SessionCapabilities;
|
|
667
|
+
|
|
668
|
+
/** MCP connection capabilities */
|
|
669
|
+
mcpCapabilities?: McpCapabilities;
|
|
670
|
+
|
|
671
|
+
/** Prompt content type capabilities */
|
|
672
|
+
promptCapabilities?: PromptCapabilities;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ============================================================================
|
|
676
|
+
// Agent Info
|
|
677
|
+
// ============================================================================
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Information about the agent implementation.
|
|
681
|
+
*
|
|
682
|
+
* Provided by the agent during initialization for identification
|
|
683
|
+
* and debugging purposes.
|
|
684
|
+
*
|
|
685
|
+
* Note: This is distinct from the UI-level AgentDisplayInfo { id, displayName }
|
|
686
|
+
* used in hooks/components for agent switching UI.
|
|
687
|
+
*/
|
|
688
|
+
export interface AgentInfo {
|
|
689
|
+
/** Programmatic identifier for the agent */
|
|
690
|
+
name: string;
|
|
691
|
+
|
|
692
|
+
/** Human-readable display name */
|
|
693
|
+
title?: string;
|
|
694
|
+
|
|
695
|
+
/** Version string (e.g., "1.0.0") */
|
|
696
|
+
version?: string;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// ============================================================================
|
|
700
|
+
// Initialize Result
|
|
701
|
+
// ============================================================================
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Result of initializing a connection to an agent.
|
|
705
|
+
*/
|
|
706
|
+
export interface InitializeResult {
|
|
707
|
+
/** Available authentication methods */
|
|
708
|
+
authMethods: AuthenticationMethod[];
|
|
709
|
+
|
|
710
|
+
/** Protocol version supported by the agent (ACP uses number) */
|
|
711
|
+
protocolVersion: number;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Prompt capabilities supported by the agent.
|
|
715
|
+
* Indicates which content types can be included in prompts.
|
|
716
|
+
* (Convenience accessor - same as agentCapabilities.promptCapabilities)
|
|
717
|
+
*/
|
|
718
|
+
promptCapabilities?: PromptCapabilities;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Full agent capabilities from initialization.
|
|
722
|
+
* Contains loadSession, sessionCapabilities, mcpCapabilities, and promptCapabilities.
|
|
723
|
+
*/
|
|
724
|
+
agentCapabilities?: AgentCapabilities;
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Information about the agent implementation.
|
|
728
|
+
* Contains name, title, and version.
|
|
729
|
+
*/
|
|
730
|
+
agentInfo?: AgentInfo;
|
|
731
|
+
}
|