@townco/ui 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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.js +114 -121
- package/dist/core/hooks/use-chat-session.d.ts +1 -1
- package/dist/core/hooks/use-chat-session.js +80 -78
- 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/ChatEmptyState.d.ts +18 -0
- package/dist/gui/components/ChatEmptyState.js +22 -0
- package/dist/gui/components/ChatInput.js +29 -1
- package/dist/gui/components/ChatLayout.js +2 -2
- package/dist/gui/components/ChatSecondaryPanel.d.ts +25 -14
- package/dist/gui/components/ChatSecondaryPanel.js +60 -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/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/MarkdownRenderer.d.ts +4 -6
- package/dist/gui/components/MarkdownRenderer.js +81 -178
- package/dist/gui/components/Message.d.ts +1 -1
- package/dist/gui/components/MessageContent.d.ts +22 -29
- package/dist/gui/components/PanelTabsHeader.d.ts +17 -0
- package/dist/gui/components/PanelTabsHeader.js +31 -0
- 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/Tabs.d.ts +4 -24
- 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 +2 -0
- package/dist/gui/components/index.js +2 -0
- package/dist/gui/lib/utils.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/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 +6 -6
- package/dist/sdk/transports/http.d.ts +55 -55
- package/dist/sdk/transports/http.js +3 -3
- package/dist/sdk/transports/stdio.d.ts +20 -20
- 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/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/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/package.json +2 -2
- package/src/styles/global.css +64 -0
- 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/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/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/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/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/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/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,219 +5,221 @@ import { WebSocketTransport } from "../transports/websocket.js";
|
|
|
5
5
|
* Simplified ACP client with explicit transport selection
|
|
6
6
|
*/
|
|
7
7
|
export class AcpClient {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
8
|
+
config;
|
|
9
|
+
transport;
|
|
10
|
+
sessions = new Map();
|
|
11
|
+
currentSessionId = null;
|
|
12
|
+
sessionUpdateHandlers = new Set();
|
|
13
|
+
errorHandlers = new Set();
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.transport = this.createTransport();
|
|
17
|
+
this.setupTransportListeners();
|
|
18
|
+
if (config.autoConnect) {
|
|
19
|
+
this.connect().catch((error) => {
|
|
20
|
+
console.error("Failed to auto-connect:", error);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Connect to the agent
|
|
26
|
+
*/
|
|
27
|
+
async connect() {
|
|
28
|
+
await this.transport.connect();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Disconnect from the agent
|
|
32
|
+
*/
|
|
33
|
+
async disconnect() {
|
|
34
|
+
await this.transport.disconnect();
|
|
35
|
+
this.currentSessionId = null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if connected
|
|
39
|
+
*/
|
|
40
|
+
isConnected() {
|
|
41
|
+
return this.transport.isConnected();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Start a new chat session
|
|
45
|
+
*/
|
|
46
|
+
async startSession(config) {
|
|
47
|
+
const sessionId = this.generateSessionId();
|
|
48
|
+
const now = new Date().toISOString();
|
|
49
|
+
const session = {
|
|
50
|
+
id: sessionId,
|
|
51
|
+
status: "connecting",
|
|
52
|
+
config: config
|
|
53
|
+
? { ...config, agentPath: config.agentPath || "" }
|
|
54
|
+
: { agentPath: "" },
|
|
55
|
+
messages: [],
|
|
56
|
+
metadata: {
|
|
57
|
+
startedAt: now,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
this.sessions.set(sessionId, session);
|
|
61
|
+
this.currentSessionId = sessionId;
|
|
62
|
+
// Update session status
|
|
63
|
+
this.updateSessionStatus(sessionId, "connected");
|
|
64
|
+
return sessionId;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Send a message in the current session
|
|
68
|
+
*/
|
|
69
|
+
async sendMessage(content, sessionId) {
|
|
70
|
+
const targetSessionId = sessionId || this.currentSessionId;
|
|
71
|
+
if (!targetSessionId) {
|
|
72
|
+
throw new Error("No active session. Start a session first.");
|
|
73
|
+
}
|
|
74
|
+
if (!this.transport.isConnected()) {
|
|
75
|
+
throw new Error("Transport not connected");
|
|
76
|
+
}
|
|
77
|
+
const session = this.sessions.get(targetSessionId);
|
|
78
|
+
if (!session) {
|
|
79
|
+
throw new Error(`Session ${targetSessionId} not found`);
|
|
80
|
+
}
|
|
81
|
+
// Create message
|
|
82
|
+
const message = {
|
|
83
|
+
id: this.generateMessageId(),
|
|
84
|
+
role: "user",
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: content,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
};
|
|
93
|
+
// Add to session
|
|
94
|
+
session.messages.push(message);
|
|
95
|
+
this.updateSessionStatus(targetSessionId, "active");
|
|
96
|
+
// Send through transport
|
|
97
|
+
await this.transport.send(message);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Receive messages from the agent (streaming)
|
|
101
|
+
*/
|
|
102
|
+
async *receiveMessages() {
|
|
103
|
+
if (!this.transport.isConnected()) {
|
|
104
|
+
throw new Error("Transport not connected");
|
|
105
|
+
}
|
|
106
|
+
yield* this.transport.receive();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get a session by ID
|
|
110
|
+
*/
|
|
111
|
+
getSession(sessionId) {
|
|
112
|
+
return this.sessions.get(sessionId);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get current session
|
|
116
|
+
*/
|
|
117
|
+
getCurrentSession() {
|
|
118
|
+
return this.currentSessionId
|
|
119
|
+
? this.sessions.get(this.currentSessionId)
|
|
120
|
+
: undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get all sessions
|
|
124
|
+
*/
|
|
125
|
+
getAllSessions() {
|
|
126
|
+
return Array.from(this.sessions.values());
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Subscribe to session updates
|
|
130
|
+
*/
|
|
131
|
+
onSessionUpdate(handler) {
|
|
132
|
+
this.sessionUpdateHandlers.add(handler);
|
|
133
|
+
return () => {
|
|
134
|
+
this.sessionUpdateHandlers.delete(handler);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Subscribe to errors
|
|
139
|
+
*/
|
|
140
|
+
onError(handler) {
|
|
141
|
+
this.errorHandlers.add(handler);
|
|
142
|
+
return () => {
|
|
143
|
+
this.errorHandlers.delete(handler);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create transport based on explicit configuration
|
|
148
|
+
*/
|
|
149
|
+
createTransport() {
|
|
150
|
+
switch (this.config.type) {
|
|
151
|
+
case "stdio":
|
|
152
|
+
return new StdioTransport(this.config.options);
|
|
153
|
+
case "http":
|
|
154
|
+
return new HttpTransport(this.config.options);
|
|
155
|
+
case "websocket":
|
|
156
|
+
return new WebSocketTransport(this.config.options);
|
|
157
|
+
default:
|
|
158
|
+
// biome-ignore lint/suspicious/noExplicitAny: .
|
|
159
|
+
throw new Error(`Unknown transport type: ${this.config.type}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
setupTransportListeners() {
|
|
163
|
+
// Listen to transport session updates
|
|
164
|
+
this.transport.onSessionUpdate((update) => {
|
|
165
|
+
this.handleSessionUpdate(update);
|
|
166
|
+
});
|
|
167
|
+
// Listen to transport errors
|
|
168
|
+
this.transport.onError((error) => {
|
|
169
|
+
this.handleError(error);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
handleSessionUpdate(update) {
|
|
173
|
+
// Update local session state
|
|
174
|
+
if (update.sessionId) {
|
|
175
|
+
const session = this.sessions.get(update.sessionId);
|
|
176
|
+
if (session) {
|
|
177
|
+
if (update.status) {
|
|
178
|
+
session.status = update.status;
|
|
179
|
+
}
|
|
180
|
+
if (update.message) {
|
|
181
|
+
session.messages.push(update.message);
|
|
182
|
+
}
|
|
183
|
+
if (update.error) {
|
|
184
|
+
session.error = update.error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Notify handlers
|
|
189
|
+
for (const handler of this.sessionUpdateHandlers) {
|
|
190
|
+
try {
|
|
191
|
+
handler(update);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
console.error("Error in session update handler:", error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
handleError(error) {
|
|
199
|
+
// Notify error handlers
|
|
200
|
+
for (const handler of this.errorHandlers) {
|
|
201
|
+
try {
|
|
202
|
+
handler(error);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.error("Error in error handler:", err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
updateSessionStatus(sessionId, status) {
|
|
210
|
+
const session = this.sessions.get(sessionId);
|
|
211
|
+
if (session) {
|
|
212
|
+
session.status = status;
|
|
213
|
+
this.handleSessionUpdate({
|
|
214
|
+
sessionId,
|
|
215
|
+
status,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
generateSessionId() {
|
|
220
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
221
|
+
}
|
|
222
|
+
generateMessageId() {
|
|
223
|
+
return `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
224
|
+
}
|
|
223
225
|
}
|
|
@@ -2,133 +2,86 @@ import { z } from "zod";
|
|
|
2
2
|
/**
|
|
3
3
|
* Agent capability schema
|
|
4
4
|
*/
|
|
5
|
-
export declare const AgentCapability: z.ZodObject<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
z.core.$strip
|
|
12
|
-
>;
|
|
5
|
+
export declare const AgentCapability: z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
description: z.ZodOptional<z.ZodString>;
|
|
8
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
13
10
|
export type AgentCapability = z.infer<typeof AgentCapability>;
|
|
14
11
|
/**
|
|
15
12
|
* Agent tool schema
|
|
16
13
|
*/
|
|
17
|
-
export declare const AgentTool: z.ZodObject<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
z.core.$strip
|
|
25
|
-
>;
|
|
14
|
+
export declare const AgentTool: z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
description: z.ZodString;
|
|
17
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
18
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
26
20
|
export type AgentTool = z.infer<typeof AgentTool>;
|
|
27
21
|
/**
|
|
28
22
|
* Agent information schema
|
|
29
23
|
*/
|
|
30
|
-
export declare const AgentInfo: z.ZodObject<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
tools: z.ZodOptional<
|
|
49
|
-
z.ZodArray<
|
|
50
|
-
z.ZodObject<
|
|
51
|
-
{
|
|
52
|
-
name: z.ZodString;
|
|
53
|
-
description: z.ZodString;
|
|
54
|
-
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
55
|
-
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
|
-
},
|
|
57
|
-
z.core.$strip
|
|
58
|
-
>
|
|
59
|
-
>
|
|
60
|
-
>;
|
|
61
|
-
supportedFormats: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
-
},
|
|
63
|
-
z.core.$strip
|
|
64
|
-
>;
|
|
24
|
+
export declare const AgentInfo: z.ZodObject<{
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
version: z.ZodOptional<z.ZodString>;
|
|
27
|
+
description: z.ZodOptional<z.ZodString>;
|
|
28
|
+
author: z.ZodOptional<z.ZodString>;
|
|
29
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
30
|
+
name: z.ZodString;
|
|
31
|
+
description: z.ZodOptional<z.ZodString>;
|
|
32
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
33
|
+
}, z.core.$strip>>>;
|
|
34
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
description: z.ZodString;
|
|
37
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
38
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
39
|
+
}, z.core.$strip>>>;
|
|
40
|
+
supportedFormats: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
|
+
}, z.core.$strip>;
|
|
65
42
|
export type AgentInfo = z.infer<typeof AgentInfo>;
|
|
66
43
|
/**
|
|
67
44
|
* Agent status schema
|
|
68
45
|
*/
|
|
69
46
|
export declare const AgentStatus: z.ZodEnum<{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
initializing: "initializing";
|
|
48
|
+
ready: "ready";
|
|
49
|
+
busy: "busy";
|
|
50
|
+
error: "error";
|
|
51
|
+
terminated: "terminated";
|
|
75
52
|
}>;
|
|
76
53
|
export type AgentStatus = z.infer<typeof AgentStatus>;
|
|
77
54
|
/**
|
|
78
55
|
* Agent state schema
|
|
79
56
|
*/
|
|
80
|
-
export declare const AgentState: z.ZodObject<
|
|
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
|
-
tools: z.ZodOptional<
|
|
111
|
-
z.ZodArray<
|
|
112
|
-
z.ZodObject<
|
|
113
|
-
{
|
|
114
|
-
name: z.ZodString;
|
|
115
|
-
description: z.ZodString;
|
|
116
|
-
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
117
|
-
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
118
|
-
},
|
|
119
|
-
z.core.$strip
|
|
120
|
-
>
|
|
121
|
-
>
|
|
122
|
-
>;
|
|
123
|
-
supportedFormats: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
-
},
|
|
125
|
-
z.core.$strip
|
|
126
|
-
>
|
|
127
|
-
>;
|
|
128
|
-
pid: z.ZodOptional<z.ZodNumber>;
|
|
129
|
-
error: z.ZodOptional<z.ZodString>;
|
|
130
|
-
uptime: z.ZodOptional<z.ZodNumber>;
|
|
131
|
-
},
|
|
132
|
-
z.core.$strip
|
|
133
|
-
>;
|
|
57
|
+
export declare const AgentState: z.ZodObject<{
|
|
58
|
+
status: z.ZodEnum<{
|
|
59
|
+
initializing: "initializing";
|
|
60
|
+
ready: "ready";
|
|
61
|
+
busy: "busy";
|
|
62
|
+
error: "error";
|
|
63
|
+
terminated: "terminated";
|
|
64
|
+
}>;
|
|
65
|
+
info: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
name: z.ZodString;
|
|
67
|
+
version: z.ZodOptional<z.ZodString>;
|
|
68
|
+
description: z.ZodOptional<z.ZodString>;
|
|
69
|
+
author: z.ZodOptional<z.ZodString>;
|
|
70
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
description: z.ZodOptional<z.ZodString>;
|
|
73
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
74
|
+
}, z.core.$strip>>>;
|
|
75
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
description: z.ZodString;
|
|
78
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
79
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
80
|
+
}, z.core.$strip>>>;
|
|
81
|
+
supportedFormats: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
+
}, z.core.$strip>>;
|
|
83
|
+
pid: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
error: z.ZodOptional<z.ZodString>;
|
|
85
|
+
uptime: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
}, z.core.$strip>;
|
|
134
87
|
export type AgentState = z.infer<typeof AgentState>;
|