@townco/ui 0.1.6 → 0.1.7
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/README.md +11 -11
- package/dist/core/hooks/use-chat-input.d.ts +17 -17
- package/dist/core/hooks/use-chat-input.js +55 -64
- package/dist/core/hooks/use-chat-messages.d.ts +11 -11
- package/dist/core/hooks/use-chat-messages.js +114 -121
- package/dist/core/hooks/use-chat-session.d.ts +5 -5
- package/dist/core/hooks/use-chat-session.js +80 -78
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/schemas/chat.d.ts +56 -83
- package/dist/core/schemas/chat.js +25 -27
- package/dist/core/store/chat-store.d.ts +22 -28
- package/dist/core/store/chat-store.js +50 -59
- package/dist/gui/components/Button.d.ts +7 -23
- package/dist/gui/components/Button.js +27 -40
- package/dist/gui/components/Card.d.ts +7 -26
- package/dist/gui/components/Card.js +8 -54
- package/dist/gui/components/ChatInput.d.ts +36 -58
- package/dist/gui/components/ChatInput.js +121 -191
- package/dist/gui/components/ChatSecondaryPanel.d.ts +11 -14
- package/dist/gui/components/ChatSecondaryPanel.js +38 -115
- package/dist/gui/components/ChatStatus.d.ts +2 -4
- package/dist/gui/components/ChatStatus.js +34 -45
- package/dist/gui/components/Conversation.d.ts +14 -17
- package/dist/gui/components/Conversation.js +83 -143
- package/dist/gui/components/Dialog.d.ts +11 -57
- package/dist/gui/components/Dialog.js +8 -84
- package/dist/gui/components/HeightTransition.d.ts +7 -12
- package/dist/gui/components/HeightTransition.js +77 -88
- package/dist/gui/components/Input.d.ts +6 -13
- package/dist/gui/components/Input.js +16 -27
- package/dist/gui/components/Label.d.ts +1 -7
- package/dist/gui/components/Label.js +2 -12
- package/dist/gui/components/MarkdownRenderer.d.ts +4 -6
- package/dist/gui/components/MarkdownRenderer.js +81 -178
- package/dist/gui/components/Message.d.ts +18 -25
- package/dist/gui/components/Message.js +23 -44
- package/dist/gui/components/MessageContent.d.ts +22 -29
- package/dist/gui/components/MessageContent.js +85 -157
- package/dist/gui/components/Reasoning.d.ts +24 -30
- package/dist/gui/components/Reasoning.js +60 -187
- package/dist/gui/components/Response.d.ts +9 -11
- package/dist/gui/components/Response.js +90 -229
- package/dist/gui/components/Select.d.ts +10 -69
- package/dist/gui/components/Select.js +12 -118
- package/dist/gui/components/Tabs.d.ts +4 -24
- package/dist/gui/components/Tabs.js +4 -32
- package/dist/gui/components/Task.d.ts +24 -28
- package/dist/gui/components/Task.js +31 -164
- package/dist/gui/components/Textarea.d.ts +7 -15
- package/dist/gui/components/Textarea.js +46 -63
- package/dist/gui/components/ThinkingBlock.d.ts +10 -20
- package/dist/gui/components/ThinkingBlock.js +35 -134
- package/dist/gui/components/TodoList.d.ts +10 -12
- package/dist/gui/components/TodoList.js +7 -22
- package/dist/gui/components/TodoListItem.d.ts +6 -9
- package/dist/gui/components/TodoListItem.js +4 -18
- package/dist/gui/components/index.d.ts +8 -59
- package/dist/gui/components/index.js +8 -42
- package/dist/gui/lib/utils.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.test.js +1 -0
- package/dist/sdk/client/acp-client.d.ts +76 -88
- package/dist/sdk/client/acp-client.js +217 -215
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/schemas/agent.d.ts +64 -111
- package/dist/sdk/schemas/agent.js +24 -24
- package/dist/sdk/schemas/message.d.ts +147 -245
- package/dist/sdk/schemas/message.js +40 -40
- package/dist/sdk/schemas/session.d.ts +135 -219
- package/dist/sdk/schemas/session.js +27 -27
- package/dist/sdk/transports/http.d.ts +55 -55
- package/dist/sdk/transports/http.js +469 -472
- package/dist/sdk/transports/stdio.d.ts +20 -20
- package/dist/sdk/transports/stdio.js +286 -289
- package/dist/sdk/transports/types.d.ts +42 -42
- package/dist/sdk/transports/websocket.d.ts +12 -12
- package/dist/sdk/transports/websocket.js +46 -52
- package/dist/tui/components/ChatView.d.ts +2 -4
- package/dist/tui/components/ChatView.js +18 -51
- package/dist/tui/components/GameOfLife.js +35 -64
- package/dist/tui/components/InputBox.d.ts +11 -18
- package/dist/tui/components/InputBox.js +10 -70
- package/dist/tui/components/MessageList.d.ts +2 -4
- package/dist/tui/components/MessageList.js +10 -37
- package/dist/tui/components/MultiSelect.d.ts +10 -15
- package/dist/tui/components/MultiSelect.js +73 -116
- package/dist/tui/components/ReadlineInput.d.ts +6 -12
- package/dist/tui/components/ReadlineInput.js +237 -252
- package/dist/tui/components/SingleSelect.d.ts +9 -15
- package/dist/tui/components/SingleSelect.js +43 -84
- package/dist/tui/components/StatusBar.d.ts +6 -11
- package/dist/tui/components/StatusBar.js +67 -102
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/package.json +2 -2
- package/dist/core/hooks/index.d.ts.map +0 -1
- package/dist/core/hooks/index.js.map +0 -1
- package/dist/core/hooks/use-chat-input.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-input.js.map +0 -1
- package/dist/core/hooks/use-chat-messages.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-messages.js.map +0 -1
- package/dist/core/hooks/use-chat-session.d.ts.map +0 -1
- package/dist/core/hooks/use-chat-session.js.map +0 -1
- package/dist/core/hooks/use-media-query.d.ts +0 -39
- package/dist/core/hooks/use-media-query.js +0 -80
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/schemas/chat.d.ts.map +0 -1
- package/dist/core/schemas/chat.js.map +0 -1
- package/dist/core/schemas/index.d.ts.map +0 -1
- package/dist/core/schemas/index.js.map +0 -1
- package/dist/core/store/chat-store.d.ts.map +0 -1
- package/dist/core/store/chat-store.js.map +0 -1
- package/dist/gui/components/Button.d.ts.map +0 -1
- package/dist/gui/components/Button.js.map +0 -1
- package/dist/gui/components/Card.d.ts.map +0 -1
- package/dist/gui/components/Card.js.map +0 -1
- package/dist/gui/components/ChatHeader.d.ts +0 -65
- package/dist/gui/components/ChatHeader.js +0 -189
- package/dist/gui/components/ChatInput.d.ts.map +0 -1
- package/dist/gui/components/ChatInput.js.map +0 -1
- package/dist/gui/components/ChatInterface.d.ts +0 -12
- package/dist/gui/components/ChatInterface.d.ts.map +0 -1
- package/dist/gui/components/ChatInterface.js +0 -204
- package/dist/gui/components/ChatInterface.js.map +0 -1
- package/dist/gui/components/ChatLayout.d.ts +0 -82
- package/dist/gui/components/ChatLayout.js +0 -232
- package/dist/gui/components/ChatPanelTabContent.d.ts +0 -27
- package/dist/gui/components/ChatPanelTabContent.js +0 -93
- package/dist/gui/components/ChatPreview.d.ts +0 -12
- package/dist/gui/components/ChatPreview.d.ts.map +0 -1
- package/dist/gui/components/ChatPreview.js +0 -214
- package/dist/gui/components/ChatPreview.js.map +0 -1
- package/dist/gui/components/ChatSecondaryPanel.d.ts.map +0 -1
- package/dist/gui/components/ChatSecondaryPanel.js.map +0 -1
- package/dist/gui/components/ChatSidebar.d.ts +0 -27
- package/dist/gui/components/ChatSidebar.js +0 -57
- package/dist/gui/components/ChatStatus.d.ts.map +0 -1
- package/dist/gui/components/ChatStatus.js.map +0 -1
- package/dist/gui/components/ChatView.d.ts +0 -8
- package/dist/gui/components/ChatView.d.ts.map +0 -1
- package/dist/gui/components/ChatView.js +0 -42
- package/dist/gui/components/ChatView.js.map +0 -1
- package/dist/gui/components/ConfigPanel.d.ts +0 -20
- package/dist/gui/components/ConfigPanel.d.ts.map +0 -1
- package/dist/gui/components/ConfigPanel.js +0 -225
- package/dist/gui/components/ConfigPanel.js.map +0 -1
- package/dist/gui/components/Conversation.d.ts.map +0 -1
- package/dist/gui/components/Conversation.js.map +0 -1
- package/dist/gui/components/Dialog.d.ts.map +0 -1
- package/dist/gui/components/Dialog.js.map +0 -1
- package/dist/gui/components/DropdownMenu.d.ts +0 -108
- package/dist/gui/components/DropdownMenu.js +0 -215
- package/dist/gui/components/HeightTransition.d.ts.map +0 -1
- package/dist/gui/components/HeightTransition.js.map +0 -1
- package/dist/gui/components/Input.d.ts.map +0 -1
- package/dist/gui/components/Input.js.map +0 -1
- package/dist/gui/components/InputBox.d.ts +0 -21
- package/dist/gui/components/InputBox.d.ts.map +0 -1
- package/dist/gui/components/InputBox.js +0 -90
- package/dist/gui/components/InputBox.js.map +0 -1
- package/dist/gui/components/Label.d.ts.map +0 -1
- package/dist/gui/components/Label.js.map +0 -1
- package/dist/gui/components/MarkdownRenderer.d.ts.map +0 -1
- package/dist/gui/components/MarkdownRenderer.js.map +0 -1
- package/dist/gui/components/Message.d.ts.map +0 -1
- package/dist/gui/components/Message.js.map +0 -1
- package/dist/gui/components/MessageContent.d.ts.map +0 -1
- package/dist/gui/components/MessageContent.js.map +0 -1
- package/dist/gui/components/MessageList.d.ts.map +0 -1
- package/dist/gui/components/MessageList.js.map +0 -1
- package/dist/gui/components/PlaygroundLayout.d.ts +0 -14
- package/dist/gui/components/PlaygroundLayout.d.ts.map +0 -1
- package/dist/gui/components/PlaygroundLayout.js +0 -49
- package/dist/gui/components/PlaygroundLayout.js.map +0 -1
- package/dist/gui/components/Reasoning.d.ts.map +0 -1
- package/dist/gui/components/Reasoning.js.map +0 -1
- package/dist/gui/components/Response.d.ts.map +0 -1
- package/dist/gui/components/Response.js.map +0 -1
- package/dist/gui/components/Select.d.ts.map +0 -1
- package/dist/gui/components/Select.js.map +0 -1
- package/dist/gui/components/Sonner.d.ts +0 -7
- package/dist/gui/components/Sonner.js +0 -34
- package/dist/gui/components/StatusBar.d.ts +0 -12
- package/dist/gui/components/StatusBar.d.ts.map +0 -1
- package/dist/gui/components/StatusBar.js +0 -58
- package/dist/gui/components/StatusBar.js.map +0 -1
- package/dist/gui/components/Tabs.d.ts.map +0 -1
- package/dist/gui/components/Tabs.js.map +0 -1
- package/dist/gui/components/Task.d.ts.map +0 -1
- package/dist/gui/components/Task.js.map +0 -1
- package/dist/gui/components/Textarea.d.ts.map +0 -1
- package/dist/gui/components/Textarea.js.map +0 -1
- package/dist/gui/components/ThinkingBlock.d.ts.map +0 -1
- package/dist/gui/components/ThinkingBlock.js.map +0 -1
- package/dist/gui/components/TodoList.d.ts.map +0 -1
- package/dist/gui/components/TodoList.js.map +0 -1
- package/dist/gui/components/TodoListItem.d.ts.map +0 -1
- package/dist/gui/components/TodoListItem.js.map +0 -1
- package/dist/gui/components/index.d.ts.map +0 -1
- package/dist/gui/components/index.js.map +0 -1
- package/dist/gui/index.d.ts.map +0 -1
- package/dist/gui/index.js.map +0 -1
- package/dist/gui/lib/utils.d.ts.map +0 -1
- package/dist/gui/lib/utils.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/sdk/client/acp-client.d.ts.map +0 -1
- package/dist/sdk/client/acp-client.js.map +0 -1
- package/dist/sdk/client/index.d.ts.map +0 -1
- package/dist/sdk/client/index.js.map +0 -1
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/schemas/agent.d.ts.map +0 -1
- package/dist/sdk/schemas/agent.js.map +0 -1
- package/dist/sdk/schemas/index.d.ts.map +0 -1
- package/dist/sdk/schemas/index.js.map +0 -1
- package/dist/sdk/schemas/message.d.ts.map +0 -1
- package/dist/sdk/schemas/message.js.map +0 -1
- package/dist/sdk/schemas/session.d.ts.map +0 -1
- package/dist/sdk/schemas/session.js.map +0 -1
- package/dist/sdk/transports/http.d.ts.map +0 -1
- package/dist/sdk/transports/http.js.map +0 -1
- package/dist/sdk/transports/index.d.ts.map +0 -1
- package/dist/sdk/transports/index.js.map +0 -1
- package/dist/sdk/transports/stdio.d.ts.map +0 -1
- package/dist/sdk/transports/stdio.js.map +0 -1
- package/dist/sdk/transports/types.d.ts.map +0 -1
- package/dist/sdk/transports/types.js.map +0 -1
- package/dist/sdk/transports/websocket.d.ts.map +0 -1
- package/dist/sdk/transports/websocket.js.map +0 -1
- package/dist/tui/components/ChatView.d.ts.map +0 -1
- package/dist/tui/components/ChatView.js.map +0 -1
- package/dist/tui/components/GameOfLife.d.ts.map +0 -1
- package/dist/tui/components/GameOfLife.js.map +0 -1
- package/dist/tui/components/InputBox.d.ts.map +0 -1
- package/dist/tui/components/InputBox.js.map +0 -1
- package/dist/tui/components/MessageList.d.ts.map +0 -1
- package/dist/tui/components/MessageList.js.map +0 -1
- package/dist/tui/components/ReadlineInput.d.ts.map +0 -1
- package/dist/tui/components/ReadlineInput.js.map +0 -1
- package/dist/tui/components/StatusBar.d.ts.map +0 -1
- package/dist/tui/components/StatusBar.js.map +0 -1
- package/dist/tui/components/index.d.ts.map +0 -1
- package/dist/tui/components/index.js.map +0 -1
- package/dist/tui/index.d.ts.map +0 -1
- package/dist/tui/index.js.map +0 -1
|
@@ -5,24 +5,24 @@ import type { StdioTransportOptions, Transport } from "./types.js";
|
|
|
5
5
|
* Uses JSON-RPC 2.0 over stdio to communicate with agents
|
|
6
6
|
*/
|
|
7
7
|
export declare class StdioTransport implements Transport {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
private options;
|
|
9
|
+
private agentProcess;
|
|
10
|
+
private connection;
|
|
11
|
+
private connected;
|
|
12
|
+
private sessionUpdateCallbacks;
|
|
13
|
+
private errorCallbacks;
|
|
14
|
+
private messageQueue;
|
|
15
|
+
private currentSessionId;
|
|
16
|
+
private chunkResolvers;
|
|
17
|
+
private streamComplete;
|
|
18
|
+
constructor(options: StdioTransportOptions);
|
|
19
|
+
connect(): Promise<void>;
|
|
20
|
+
disconnect(): Promise<void>;
|
|
21
|
+
send(message: Message): Promise<void>;
|
|
22
|
+
receive(): AsyncIterableIterator<MessageChunk>;
|
|
23
|
+
isConnected(): boolean;
|
|
24
|
+
onSessionUpdate(callback: (update: SessionUpdate) => void): () => void;
|
|
25
|
+
onError(callback: (error: Error) => void): () => void;
|
|
26
|
+
private notifySessionUpdate;
|
|
27
|
+
private notifyError;
|
|
28
28
|
}
|
|
@@ -1,297 +1,294 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { Readable, Writable } from "node:stream";
|
|
3
|
-
import {
|
|
4
|
-
ClientSideConnection,
|
|
5
|
-
ndJsonStream,
|
|
6
|
-
PROTOCOL_VERSION,
|
|
7
|
-
} from "@agentclientprotocol/sdk";
|
|
3
|
+
import { ClientSideConnection, ndJsonStream, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
|
|
8
4
|
/**
|
|
9
5
|
* Stdio transport implementation using Agent Client Protocol SDK
|
|
10
6
|
* Uses JSON-RPC 2.0 over stdio to communicate with agents
|
|
11
7
|
*/
|
|
12
8
|
export class StdioTransport {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
9
|
+
options;
|
|
10
|
+
agentProcess = null;
|
|
11
|
+
connection = null;
|
|
12
|
+
connected = false;
|
|
13
|
+
sessionUpdateCallbacks = new Set();
|
|
14
|
+
errorCallbacks = new Set();
|
|
15
|
+
messageQueue = [];
|
|
16
|
+
currentSessionId = null;
|
|
17
|
+
chunkResolvers = [];
|
|
18
|
+
streamComplete = false;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
async connect() {
|
|
23
|
+
if (this.connected) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
// Spawn the agent process
|
|
28
|
+
this.agentProcess = spawn(this.options.agentPath, this.options.agentArgs || [], {
|
|
29
|
+
cwd: this.options.workingDirectory || process.cwd(),
|
|
30
|
+
env: { ...process.env, ...this.options.environment },
|
|
31
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
32
|
+
});
|
|
33
|
+
if (!this.agentProcess.stdin ||
|
|
34
|
+
!this.agentProcess.stdout ||
|
|
35
|
+
!this.agentProcess.stderr) {
|
|
36
|
+
throw new Error("Failed to create stdio pipes for agent process");
|
|
37
|
+
}
|
|
38
|
+
// Convert Node.js streams to Web streams
|
|
39
|
+
const outputStream = Writable.toWeb(this.agentProcess.stdin);
|
|
40
|
+
const inputStream = Readable.toWeb(this.agentProcess.stdout);
|
|
41
|
+
// Create the bidirectional stream using ndJsonStream
|
|
42
|
+
const stream = ndJsonStream(outputStream, inputStream);
|
|
43
|
+
// Create ACP client implementation factory
|
|
44
|
+
const self = this;
|
|
45
|
+
const clientFactory = (_agent) => {
|
|
46
|
+
return {
|
|
47
|
+
async requestPermission(params) {
|
|
48
|
+
// For now, auto-approve all permissions
|
|
49
|
+
// In a real implementation, this should prompt the user
|
|
50
|
+
console.log(`Permission requested:`, params);
|
|
51
|
+
// @ts-expect-error - Type mismatch with ACP SDK v0.5.1
|
|
52
|
+
return { outcome: "approved" };
|
|
53
|
+
},
|
|
54
|
+
async sessionUpdate(params) {
|
|
55
|
+
// Handle session updates from the agent
|
|
56
|
+
const paramsExtended = params;
|
|
57
|
+
const update = paramsExtended.update;
|
|
58
|
+
const sessionUpdate = {
|
|
59
|
+
sessionId: self.currentSessionId || params.sessionId,
|
|
60
|
+
status: "active",
|
|
61
|
+
};
|
|
62
|
+
// Queue message chunks if present - content is in update.content
|
|
63
|
+
if (update?.content) {
|
|
64
|
+
const content = update.content;
|
|
65
|
+
let chunk = null;
|
|
66
|
+
if (content.type === "text" && content.text) {
|
|
67
|
+
chunk = {
|
|
68
|
+
id: params.sessionId,
|
|
69
|
+
role: "assistant",
|
|
70
|
+
contentDelta: { type: "text", text: content.text },
|
|
71
|
+
isComplete: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
else if (content.type === "tool_call") {
|
|
75
|
+
chunk = {
|
|
76
|
+
id: params.sessionId,
|
|
77
|
+
role: "assistant",
|
|
78
|
+
contentDelta: content,
|
|
79
|
+
isComplete: false,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (chunk) {
|
|
83
|
+
// Resolve any waiting receive() calls immediately
|
|
84
|
+
const resolver = self.chunkResolvers.shift();
|
|
85
|
+
if (resolver) {
|
|
86
|
+
resolver(chunk);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Only queue if no resolver is waiting
|
|
90
|
+
self.messageQueue.push(chunk);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
self.notifySessionUpdate(sessionUpdate);
|
|
95
|
+
},
|
|
96
|
+
async writeTextFile(params) {
|
|
97
|
+
const fs = await import("node:fs/promises");
|
|
98
|
+
await fs.writeFile(params.path, params.content, "utf-8");
|
|
99
|
+
return {};
|
|
100
|
+
},
|
|
101
|
+
async readTextFile(params) {
|
|
102
|
+
const fs = await import("node:fs/promises");
|
|
103
|
+
const content = await fs.readFile(params.path, "utf-8");
|
|
104
|
+
return { content };
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
// Create the client-side connection
|
|
109
|
+
this.connection = new ClientSideConnection(clientFactory, stream);
|
|
110
|
+
// Handle stderr for debugging
|
|
111
|
+
this.agentProcess.stderr.on("data", (data) => {
|
|
112
|
+
console.error(`Agent stderr: ${data}`);
|
|
113
|
+
});
|
|
114
|
+
// Handle process exit
|
|
115
|
+
this.agentProcess.on("exit", (code, signal) => {
|
|
116
|
+
this.connected = false;
|
|
117
|
+
const error = new Error(`Agent process exited with code ${code} and signal ${signal}`);
|
|
118
|
+
this.notifyError(error);
|
|
119
|
+
});
|
|
120
|
+
// Listen for connection closure
|
|
121
|
+
this.connection.closed.then(() => {
|
|
122
|
+
this.connected = false;
|
|
123
|
+
});
|
|
124
|
+
// Initialize the connection
|
|
125
|
+
const initResponse = await this.connection.initialize({
|
|
126
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
127
|
+
clientCapabilities: {
|
|
128
|
+
fs: {
|
|
129
|
+
readTextFile: true,
|
|
130
|
+
writeTextFile: true,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
console.log("ACP connection initialized:", initResponse);
|
|
135
|
+
this.connected = true;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.connected = false;
|
|
139
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
140
|
+
this.notifyError(err);
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async disconnect() {
|
|
145
|
+
if (!this.connected) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
// Terminate the agent process (this will close the connection)
|
|
150
|
+
if (this.agentProcess) {
|
|
151
|
+
this.agentProcess.kill();
|
|
152
|
+
this.agentProcess = null;
|
|
153
|
+
}
|
|
154
|
+
// Wait for connection to close
|
|
155
|
+
if (this.connection) {
|
|
156
|
+
await this.connection.closed;
|
|
157
|
+
}
|
|
158
|
+
this.connection = null;
|
|
159
|
+
this.connected = false;
|
|
160
|
+
this.currentSessionId = null;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
164
|
+
this.notifyError(err);
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async send(message) {
|
|
169
|
+
if (!this.connected || !this.connection) {
|
|
170
|
+
throw new Error("Transport not connected");
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
// Reset stream state for new message
|
|
174
|
+
this.streamComplete = false;
|
|
175
|
+
this.messageQueue = [];
|
|
176
|
+
// If no session, create one first
|
|
177
|
+
if (!this.currentSessionId) {
|
|
178
|
+
const sessionResponse = await this.connection.newSession({
|
|
179
|
+
cwd: this.options.workingDirectory || process.cwd(),
|
|
180
|
+
mcpServers: [],
|
|
181
|
+
});
|
|
182
|
+
this.currentSessionId = sessionResponse.sessionId;
|
|
183
|
+
}
|
|
184
|
+
// Convert our message format to ACP prompt format
|
|
185
|
+
const textContent = message.content
|
|
186
|
+
.filter((c) => c.type === "text")
|
|
187
|
+
.map((c) => c.text)
|
|
188
|
+
.join("\n");
|
|
189
|
+
// Send the prompt - ACP expects "prompt" field with ContentBlock[]
|
|
190
|
+
const promptResponse = await this.connection.prompt({
|
|
191
|
+
sessionId: this.currentSessionId,
|
|
192
|
+
prompt: [
|
|
193
|
+
{
|
|
194
|
+
type: "text",
|
|
195
|
+
text: textContent,
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
console.log("Prompt response:", promptResponse);
|
|
200
|
+
// Mark stream as complete after prompt finishes
|
|
201
|
+
this.streamComplete = true;
|
|
202
|
+
// Resolve any waiting receive() calls with completion
|
|
203
|
+
const resolver = this.chunkResolvers.shift();
|
|
204
|
+
if (resolver) {
|
|
205
|
+
resolver({
|
|
206
|
+
id: this.currentSessionId || "unknown",
|
|
207
|
+
role: "assistant",
|
|
208
|
+
contentDelta: { type: "text", text: "" },
|
|
209
|
+
isComplete: true,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
this.streamComplete = true;
|
|
215
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
216
|
+
this.notifyError(err);
|
|
217
|
+
throw err;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async *receive() {
|
|
221
|
+
// Keep yielding chunks until stream is complete
|
|
222
|
+
while (!this.streamComplete) {
|
|
223
|
+
// Check if there are queued messages
|
|
224
|
+
if (this.messageQueue.length > 0) {
|
|
225
|
+
const chunk = this.messageQueue.shift();
|
|
226
|
+
if (chunk) {
|
|
227
|
+
yield chunk;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
// Wait for next chunk to arrive
|
|
232
|
+
const chunk = await new Promise((resolve) => {
|
|
233
|
+
this.chunkResolvers.push(resolve);
|
|
234
|
+
});
|
|
235
|
+
if (chunk.isComplete) {
|
|
236
|
+
yield chunk;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
yield chunk;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Yield any remaining queued messages
|
|
245
|
+
while (this.messageQueue.length > 0) {
|
|
246
|
+
const chunk = this.messageQueue.shift();
|
|
247
|
+
if (chunk) {
|
|
248
|
+
yield chunk;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Mark the stream as complete
|
|
252
|
+
yield {
|
|
253
|
+
id: this.currentSessionId || "unknown",
|
|
254
|
+
role: "assistant",
|
|
255
|
+
contentDelta: { type: "text", text: "" },
|
|
256
|
+
isComplete: true,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
isConnected() {
|
|
260
|
+
return this.connected;
|
|
261
|
+
}
|
|
262
|
+
onSessionUpdate(callback) {
|
|
263
|
+
this.sessionUpdateCallbacks.add(callback);
|
|
264
|
+
return () => {
|
|
265
|
+
this.sessionUpdateCallbacks.delete(callback);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
onError(callback) {
|
|
269
|
+
this.errorCallbacks.add(callback);
|
|
270
|
+
return () => {
|
|
271
|
+
this.errorCallbacks.delete(callback);
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
notifySessionUpdate(update) {
|
|
275
|
+
for (const callback of this.sessionUpdateCallbacks) {
|
|
276
|
+
try {
|
|
277
|
+
callback(update);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
console.error("Error in session update callback:", error);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
notifyError(error) {
|
|
285
|
+
for (const callback of this.errorCallbacks) {
|
|
286
|
+
try {
|
|
287
|
+
callback(error);
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
console.error("Error in error callback:", err);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
297
294
|
}
|