@suzuke/agend 0.0.1 → 1.0.2
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 +78 -0
- package/README.zh-TW.md +79 -0
- package/dist/access-path.d.ts +7 -0
- package/dist/access-path.js +12 -0
- package/dist/access-path.js.map +1 -0
- package/dist/backend/claude-code.d.ts +13 -0
- package/dist/backend/claude-code.js +114 -0
- package/dist/backend/claude-code.js.map +1 -0
- package/dist/backend/codex.d.ts +10 -0
- package/dist/backend/codex.js +58 -0
- package/dist/backend/codex.js.map +1 -0
- package/dist/backend/factory.d.ts +2 -0
- package/dist/backend/factory.js +19 -0
- package/dist/backend/factory.js.map +1 -0
- package/dist/backend/gemini-cli.d.ts +10 -0
- package/dist/backend/gemini-cli.js +68 -0
- package/dist/backend/gemini-cli.js.map +1 -0
- package/dist/backend/index.d.ts +6 -0
- package/dist/backend/index.js +6 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/opencode.d.ts +10 -0
- package/dist/backend/opencode.js +63 -0
- package/dist/backend/opencode.js.map +1 -0
- package/dist/backend/types.d.ts +26 -0
- package/dist/backend/types.js +2 -0
- package/dist/backend/types.js.map +1 -0
- package/dist/channel/access-manager.d.ts +18 -0
- package/dist/channel/access-manager.js +149 -0
- package/dist/channel/access-manager.js.map +1 -0
- package/dist/channel/adapters/discord.d.ts +45 -0
- package/dist/channel/adapters/discord.js +366 -0
- package/dist/channel/adapters/discord.js.map +1 -0
- package/dist/channel/adapters/telegram.d.ts +58 -0
- package/dist/channel/adapters/telegram.js +569 -0
- package/dist/channel/adapters/telegram.js.map +1 -0
- package/dist/channel/attachment-handler.d.ts +15 -0
- package/dist/channel/attachment-handler.js +55 -0
- package/dist/channel/attachment-handler.js.map +1 -0
- package/dist/channel/factory.d.ts +12 -0
- package/dist/channel/factory.js +38 -0
- package/dist/channel/factory.js.map +1 -0
- package/dist/channel/ipc-bridge.d.ts +26 -0
- package/dist/channel/ipc-bridge.js +170 -0
- package/dist/channel/ipc-bridge.js.map +1 -0
- package/dist/channel/mcp-server.d.ts +10 -0
- package/dist/channel/mcp-server.js +196 -0
- package/dist/channel/mcp-server.js.map +1 -0
- package/dist/channel/mcp-tools.d.ts +909 -0
- package/dist/channel/mcp-tools.js +346 -0
- package/dist/channel/mcp-tools.js.map +1 -0
- package/dist/channel/message-bus.d.ts +17 -0
- package/dist/channel/message-bus.js +86 -0
- package/dist/channel/message-bus.js.map +1 -0
- package/dist/channel/message-queue.d.ts +39 -0
- package/dist/channel/message-queue.js +248 -0
- package/dist/channel/message-queue.js.map +1 -0
- package/dist/channel/tool-router.d.ts +6 -0
- package/dist/channel/tool-router.js +69 -0
- package/dist/channel/tool-router.js.map +1 -0
- package/dist/channel/tool-tracker.d.ts +13 -0
- package/dist/channel/tool-tracker.js +58 -0
- package/dist/channel/tool-tracker.js.map +1 -0
- package/dist/channel/types.d.ts +116 -0
- package/dist/channel/types.js +2 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +782 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +85 -0
- package/dist/config.js.map +1 -0
- package/dist/context-guardian.d.ts +29 -0
- package/dist/context-guardian.js +123 -0
- package/dist/context-guardian.js.map +1 -0
- package/dist/cost-guard.d.ts +21 -0
- package/dist/cost-guard.js +113 -0
- package/dist/cost-guard.js.map +1 -0
- package/dist/daemon-entry.d.ts +1 -0
- package/dist/daemon-entry.js +29 -0
- package/dist/daemon-entry.js.map +1 -0
- package/dist/daemon.d.ts +88 -0
- package/dist/daemon.js +821 -0
- package/dist/daemon.js.map +1 -0
- package/dist/daily-summary.d.ts +13 -0
- package/dist/daily-summary.js +55 -0
- package/dist/daily-summary.js.map +1 -0
- package/dist/event-log.d.ts +22 -0
- package/dist/event-log.js +66 -0
- package/dist/event-log.js.map +1 -0
- package/dist/export-import.d.ts +2 -0
- package/dist/export-import.js +110 -0
- package/dist/export-import.js.map +1 -0
- package/dist/fleet-context.d.ts +36 -0
- package/dist/fleet-context.js +4 -0
- package/dist/fleet-context.js.map +1 -0
- package/dist/fleet-manager.d.ts +115 -0
- package/dist/fleet-manager.js +1739 -0
- package/dist/fleet-manager.js.map +1 -0
- package/dist/fleet-system-prompt.d.ts +11 -0
- package/dist/fleet-system-prompt.js +60 -0
- package/dist/fleet-system-prompt.js.map +1 -0
- package/dist/hang-detector.d.ts +16 -0
- package/dist/hang-detector.js +53 -0
- package/dist/hang-detector.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +63 -0
- package/dist/logger.js.map +1 -0
- package/dist/plugin/agend/.claude-plugin/plugin.json +5 -0
- package/dist/scheduler/db.d.ts +16 -0
- package/dist/scheduler/db.js +132 -0
- package/dist/scheduler/db.js.map +1 -0
- package/dist/scheduler/db.test.d.ts +1 -0
- package/dist/scheduler/db.test.js +92 -0
- package/dist/scheduler/db.test.js.map +1 -0
- package/dist/scheduler/index.d.ts +4 -0
- package/dist/scheduler/index.js +4 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +25 -0
- package/dist/scheduler/scheduler.js +119 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/scheduler/scheduler.test.d.ts +1 -0
- package/dist/scheduler/scheduler.test.js +119 -0
- package/dist/scheduler/scheduler.test.js.map +1 -0
- package/dist/scheduler/types.d.ts +47 -0
- package/dist/scheduler/types.js +7 -0
- package/dist/scheduler/types.js.map +1 -0
- package/dist/service-installer.d.ts +14 -0
- package/dist/service-installer.js +91 -0
- package/dist/service-installer.js.map +1 -0
- package/dist/setup-wizard.d.ts +14 -0
- package/dist/setup-wizard.js +517 -0
- package/dist/setup-wizard.js.map +1 -0
- package/dist/stt.d.ts +10 -0
- package/dist/stt.js +33 -0
- package/dist/stt.js.map +1 -0
- package/dist/tmux-manager.d.ts +22 -0
- package/dist/tmux-manager.js +132 -0
- package/dist/tmux-manager.js.map +1 -0
- package/dist/topic-commands.d.ts +22 -0
- package/dist/topic-commands.js +176 -0
- package/dist/topic-commands.js.map +1 -0
- package/dist/transcript-monitor.d.ts +21 -0
- package/dist/transcript-monitor.js +149 -0
- package/dist/transcript-monitor.js.map +1 -0
- package/dist/types.d.ts +153 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook-emitter.d.ts +15 -0
- package/dist/webhook-emitter.js +41 -0
- package/dist/webhook-emitter.js.map +1 -0
- package/package.json +58 -4
- package/templates/launchd.plist.ejs +29 -0
- package/templates/systemd.service.ejs +15 -0
- package/index.js +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/** Pure tool schema definitions — no runtime dependencies, safe to import in tests. */
|
|
2
|
+
export const TOOLS = [
|
|
3
|
+
{
|
|
4
|
+
name: "reply",
|
|
5
|
+
description: "Reply on the channel. Pass chat_id from the inbound message. Optionally pass reply_to (message_id) for threading, and files (absolute paths) to attach. IMPORTANT: chat_id and thread_id must come from the inbound <channel> message — never infer them from instance names or topic_ids.",
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
chat_id: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "chat_id from the inbound <channel> block. Do NOT use an instance's topic_id here.",
|
|
12
|
+
},
|
|
13
|
+
text: { type: "string" },
|
|
14
|
+
reply_to: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "Message ID to thread under. Use message_id from the inbound <channel> block.",
|
|
17
|
+
},
|
|
18
|
+
thread_id: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Telegram topic thread ID. Use thread_id from the inbound <channel> block only. Never set this to an instance's topic_id from list_instances.",
|
|
21
|
+
},
|
|
22
|
+
files: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: { type: "string" },
|
|
25
|
+
description: "Absolute file paths to attach.",
|
|
26
|
+
},
|
|
27
|
+
format: {
|
|
28
|
+
type: "string",
|
|
29
|
+
enum: ["text", "markdown"],
|
|
30
|
+
description: "Rendering mode. Default: 'text'.",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
required: ["chat_id", "text"],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "react",
|
|
38
|
+
description: "Add an emoji reaction to a channel message.",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
chat_id: { type: "string" },
|
|
43
|
+
message_id: { type: "string" },
|
|
44
|
+
emoji: { type: "string" },
|
|
45
|
+
},
|
|
46
|
+
required: ["chat_id", "message_id", "emoji"],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "edit_message",
|
|
51
|
+
description: "Edit a message the bot previously sent. Useful for interim progress updates.",
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
chat_id: { type: "string" },
|
|
56
|
+
message_id: { type: "string" },
|
|
57
|
+
text: { type: "string" },
|
|
58
|
+
format: {
|
|
59
|
+
type: "string",
|
|
60
|
+
enum: ["text", "markdown"],
|
|
61
|
+
description: "Rendering mode. Default: 'text'.",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
required: ["chat_id", "message_id", "text"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "download_attachment",
|
|
69
|
+
description: "Download a file attachment from a channel message. Returns the local file path ready to Read.",
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
file_id: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "The attachment_file_id from inbound meta",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
required: ["file_id"],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "create_schedule",
|
|
83
|
+
description: "Create a cron-based schedule. When triggered, sends a message to the target instance.",
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
cron: { type: "string", description: "Cron expression, e.g. '0 7 * * *' (every day at 7 AM)" },
|
|
88
|
+
message: { type: "string", description: "Message to inject when triggered" },
|
|
89
|
+
target: { type: "string", description: "Target instance name. Defaults to this instance if omitted." },
|
|
90
|
+
label: { type: "string", description: "Human-readable name for this schedule" },
|
|
91
|
+
timezone: { type: "string", description: "IANA timezone, e.g. 'Asia/Taipei'. Defaults to Asia/Taipei." },
|
|
92
|
+
},
|
|
93
|
+
required: ["cron", "message"],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "list_schedules",
|
|
98
|
+
description: "List all schedules. Optionally filter by target instance.",
|
|
99
|
+
inputSchema: {
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: {
|
|
102
|
+
target: { type: "string", description: "Filter by target instance name" },
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "update_schedule",
|
|
108
|
+
description: "Update an existing schedule. Only include fields you want to change.",
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: "object",
|
|
111
|
+
properties: {
|
|
112
|
+
id: { type: "string", description: "Schedule ID" },
|
|
113
|
+
cron: { type: "string", description: "New cron expression" },
|
|
114
|
+
message: { type: "string", description: "New message" },
|
|
115
|
+
target: { type: "string", description: "New target instance" },
|
|
116
|
+
label: { type: "string", description: "New label" },
|
|
117
|
+
timezone: { type: "string", description: "New timezone" },
|
|
118
|
+
enabled: { type: "boolean", description: "Enable/disable the schedule" },
|
|
119
|
+
},
|
|
120
|
+
required: ["id"],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "delete_schedule",
|
|
125
|
+
description: "Delete a schedule by ID.",
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
id: { type: "string", description: "Schedule ID to delete" },
|
|
130
|
+
},
|
|
131
|
+
required: ["id"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "send_to_instance",
|
|
136
|
+
description: "Send a message to another Claude instance. The message appears in their channel as a passive notification — they decide whether to respond. Use this to share information, request reviews, or coordinate work across instances.",
|
|
137
|
+
inputSchema: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
instance_name: {
|
|
141
|
+
type: "string",
|
|
142
|
+
description: "Name of the target instance (e.g., 'ccplugin', 'blog-t1385'). Use list_instances to see available instances.",
|
|
143
|
+
},
|
|
144
|
+
message: {
|
|
145
|
+
type: "string",
|
|
146
|
+
description: "The message to send to the target instance.",
|
|
147
|
+
},
|
|
148
|
+
request_kind: {
|
|
149
|
+
type: "string",
|
|
150
|
+
enum: ["query", "task", "report", "update"],
|
|
151
|
+
description: "Categorizes the message intent. 'query' = asking a question, 'task' = delegating work, 'report' = returning results, 'update' = status notification.",
|
|
152
|
+
},
|
|
153
|
+
requires_reply: {
|
|
154
|
+
type: "boolean",
|
|
155
|
+
description: "Whether you expect the recipient to respond. Default: false.",
|
|
156
|
+
},
|
|
157
|
+
correlation_id: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Echo this from a previous message to link request-response pairs.",
|
|
160
|
+
},
|
|
161
|
+
task_summary: {
|
|
162
|
+
type: "string",
|
|
163
|
+
description: "Brief summary of the task or request (shown in logs and Telegram visibility posts).",
|
|
164
|
+
},
|
|
165
|
+
working_directory: {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: "Working directory context to pass along (e.g. the repo path you are working in).",
|
|
168
|
+
},
|
|
169
|
+
branch: {
|
|
170
|
+
type: "string",
|
|
171
|
+
description: "Git branch context to pass along.",
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
required: ["instance_name", "message"],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "request_information",
|
|
179
|
+
description: "Ask another instance a question and expect a reply. Wrapper around send_to_instance with request_kind=query and requires_reply=true.",
|
|
180
|
+
inputSchema: {
|
|
181
|
+
type: "object",
|
|
182
|
+
properties: {
|
|
183
|
+
target_instance: {
|
|
184
|
+
type: "string",
|
|
185
|
+
description: "Name of the instance to ask.",
|
|
186
|
+
},
|
|
187
|
+
question: {
|
|
188
|
+
type: "string",
|
|
189
|
+
description: "The question to ask.",
|
|
190
|
+
},
|
|
191
|
+
context: {
|
|
192
|
+
type: "string",
|
|
193
|
+
description: "Optional context to help the recipient answer.",
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
required: ["target_instance", "question"],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "delegate_task",
|
|
201
|
+
description: "Delegate a task to another instance and expect a result report back. Wrapper around send_to_instance with request_kind=task and requires_reply=true.",
|
|
202
|
+
inputSchema: {
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: {
|
|
205
|
+
target_instance: {
|
|
206
|
+
type: "string",
|
|
207
|
+
description: "Name of the instance to delegate to.",
|
|
208
|
+
},
|
|
209
|
+
task: {
|
|
210
|
+
type: "string",
|
|
211
|
+
description: "Description of the task to perform.",
|
|
212
|
+
},
|
|
213
|
+
success_criteria: {
|
|
214
|
+
type: "string",
|
|
215
|
+
description: "How the recipient should judge if the task is complete.",
|
|
216
|
+
},
|
|
217
|
+
context: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "Optional background context for the task.",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
required: ["target_instance", "task"],
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "report_result",
|
|
227
|
+
description: "Report results back to an instance that delegated a task or asked a question. Wrapper around send_to_instance with request_kind=report.",
|
|
228
|
+
inputSchema: {
|
|
229
|
+
type: "object",
|
|
230
|
+
properties: {
|
|
231
|
+
target_instance: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Name of the instance to report to.",
|
|
234
|
+
},
|
|
235
|
+
correlation_id: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "The correlation_id from the original request.",
|
|
238
|
+
},
|
|
239
|
+
summary: {
|
|
240
|
+
type: "string",
|
|
241
|
+
description: "Summary of the result.",
|
|
242
|
+
},
|
|
243
|
+
artifacts: {
|
|
244
|
+
type: "string",
|
|
245
|
+
description: "Optional details: file paths, commit hashes, URLs, etc.",
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
required: ["target_instance", "summary"],
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "describe_instance",
|
|
253
|
+
description: "Get detailed information about a specific instance: description, working directory, status, tags, and recent activity.",
|
|
254
|
+
inputSchema: {
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: {
|
|
257
|
+
name: {
|
|
258
|
+
type: "string",
|
|
259
|
+
description: "Instance name to describe.",
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
required: ["name"],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "list_instances",
|
|
267
|
+
description: "List all currently running instances that you can send messages to.",
|
|
268
|
+
inputSchema: {
|
|
269
|
+
type: "object",
|
|
270
|
+
properties: {},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "start_instance",
|
|
275
|
+
description: "Start a stopped AgEnD instance. Use list_instances() first to check available instances and their status. " +
|
|
276
|
+
"Only needed when the target instance status is 'stopped'.",
|
|
277
|
+
inputSchema: {
|
|
278
|
+
type: "object",
|
|
279
|
+
properties: {
|
|
280
|
+
name: {
|
|
281
|
+
type: "string",
|
|
282
|
+
description: "The instance name to start (from list_instances)",
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
required: ["name"],
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "create_instance",
|
|
290
|
+
description: "Create a new AgEnD instance bound to a project directory, with a new Telegram topic. " +
|
|
291
|
+
"Use this when the user wants to add a new project to the fleet. " +
|
|
292
|
+
"The directory must exist. Returns the instance name and topic ID.",
|
|
293
|
+
inputSchema: {
|
|
294
|
+
type: "object",
|
|
295
|
+
properties: {
|
|
296
|
+
directory: {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "Absolute path or ~-prefixed path to the project directory",
|
|
299
|
+
},
|
|
300
|
+
topic_name: {
|
|
301
|
+
type: "string",
|
|
302
|
+
description: "Name for the Telegram topic. Defaults to directory basename.",
|
|
303
|
+
},
|
|
304
|
+
description: {
|
|
305
|
+
type: "string",
|
|
306
|
+
description: "Human-readable description of what this instance does (e.g., 'Daily secretary for scheduling and reminders').",
|
|
307
|
+
},
|
|
308
|
+
model: {
|
|
309
|
+
type: "string",
|
|
310
|
+
description: "Claude model to use for this instance. Omit to use the default (usually opus).",
|
|
311
|
+
enum: ["sonnet", "opus", "haiku"],
|
|
312
|
+
},
|
|
313
|
+
backend: {
|
|
314
|
+
type: "string",
|
|
315
|
+
description: "CLI backend to use. Defaults to claude-code.",
|
|
316
|
+
enum: ["claude-code", "gemini-cli", "codex", "opencode"],
|
|
317
|
+
},
|
|
318
|
+
branch: {
|
|
319
|
+
type: "string",
|
|
320
|
+
description: "Git branch name. When specified, creates a git worktree from the directory's repo and uses it as the working directory. If the branch doesn't exist, it will be created.",
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
required: ["directory"],
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: "delete_instance",
|
|
328
|
+
description: "Delete a AgEnD instance: stop daemon, remove from fleet config, clean up worktree if applicable, and optionally delete the Telegram topic. " +
|
|
329
|
+
"Use this when an instance is no longer needed (e.g., feature branch work is done).",
|
|
330
|
+
inputSchema: {
|
|
331
|
+
type: "object",
|
|
332
|
+
properties: {
|
|
333
|
+
name: {
|
|
334
|
+
type: "string",
|
|
335
|
+
description: "The instance name to delete (from list_instances)",
|
|
336
|
+
},
|
|
337
|
+
delete_topic: {
|
|
338
|
+
type: "boolean",
|
|
339
|
+
description: "Whether to also delete the Telegram topic. Defaults to false.",
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
required: ["name"],
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
];
|
|
346
|
+
//# sourceMappingURL=mcp-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.js","sourceRoot":"","sources":["../../src/channel/mcp-tools.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB;QACE,IAAI,EAAE,OAAO;QACb,WAAW,EACT,4RAA4R;QAC9R,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,mFAAmF;iBACjG;gBACD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACxB,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,8EAA8E;iBACjF;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,8IAA8I;iBACjJ;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACzB,WAAW,EAAE,gCAAgC;iBAC9C;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;oBAC1B,WAAW,EAAE,kCAAkC;iBAChD;aACF;YACD,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC;SAC9B;KACF;IACD;QACE,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,6CAA6C;QAC1D,WAAW,EAAE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AAC;iBAClC;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,8CAA8C;oBAC3D,IAAI,EAAE,CAAC,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC;iBACzD;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,0KAA0K;iBACxL;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;SACxB;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EACT,6IAA6I;YAC7I,oFAAoF;QACtF,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,mDAAmD;iBACjE;gBACD,YAAY,EAAE;oBACZ,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,+DAA+D;iBAC7E;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB;KACF;CACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { ChannelAdapter, OutboundMessage, Target, ApprovalResponse, PermissionPrompt } from "./types.js";
|
|
3
|
+
export declare class MessageBus extends EventEmitter {
|
|
4
|
+
private adapters;
|
|
5
|
+
private logger?;
|
|
6
|
+
setLogger(logger: {
|
|
7
|
+
warn(obj: unknown, msg?: string): void;
|
|
8
|
+
error(msg: string): void;
|
|
9
|
+
}): void;
|
|
10
|
+
register(adapter: ChannelAdapter): void;
|
|
11
|
+
unregister(adapterId: string): void;
|
|
12
|
+
getAdapter(id: string): ChannelAdapter | undefined;
|
|
13
|
+
getAllAdapters(): ChannelAdapter[];
|
|
14
|
+
send(target: Target, msg: OutboundMessage): Promise<void>;
|
|
15
|
+
private sendVia;
|
|
16
|
+
requestApproval(prompt: PermissionPrompt): Promise<ApprovalResponse>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
const APPROVAL_TIMEOUT_MS = 120_000;
|
|
3
|
+
export class MessageBus extends EventEmitter {
|
|
4
|
+
adapters = new Map();
|
|
5
|
+
logger;
|
|
6
|
+
setLogger(logger) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
register(adapter) {
|
|
10
|
+
this.adapters.set(adapter.id, adapter);
|
|
11
|
+
adapter.on("message", (msg) => this.emit("message", msg));
|
|
12
|
+
}
|
|
13
|
+
unregister(adapterId) { this.adapters.delete(adapterId); }
|
|
14
|
+
getAdapter(id) { return this.adapters.get(id); }
|
|
15
|
+
getAllAdapters() { return [...this.adapters.values()]; }
|
|
16
|
+
async send(target, msg) {
|
|
17
|
+
if (target.adapterId) {
|
|
18
|
+
const adapter = this.adapters.get(target.adapterId);
|
|
19
|
+
if (!adapter)
|
|
20
|
+
throw new Error(`Adapter ${target.adapterId} not found`);
|
|
21
|
+
await this.sendVia(adapter, target, msg);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const results = await Promise.allSettled([...this.adapters.values()].map(a => this.sendVia(a, target, msg)));
|
|
25
|
+
for (const r of results) {
|
|
26
|
+
if (r.status === "rejected") {
|
|
27
|
+
this.logger?.warn({ err: r.reason }, "Adapter send failed");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async sendVia(adapter, target, msg) {
|
|
33
|
+
if (msg.filePath) {
|
|
34
|
+
await adapter.sendFile(target.chatId, msg.filePath, { threadId: target.threadId });
|
|
35
|
+
}
|
|
36
|
+
else if (msg.text) {
|
|
37
|
+
await adapter.sendText(target.chatId, msg.text, {
|
|
38
|
+
threadId: target.threadId, replyTo: msg.replyTo, format: msg.format,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
requestApproval(prompt) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const handles = [];
|
|
46
|
+
let resolved = false;
|
|
47
|
+
const timeout = setTimeout(() => {
|
|
48
|
+
if (resolved)
|
|
49
|
+
return;
|
|
50
|
+
resolved = true;
|
|
51
|
+
controller.abort();
|
|
52
|
+
handles.forEach(h => h.cancel());
|
|
53
|
+
resolve({ decision: "deny", respondedBy: { channelType: "timeout", userId: "" } });
|
|
54
|
+
}, APPROVAL_TIMEOUT_MS);
|
|
55
|
+
if (this.adapters.size === 0) {
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
resolve({ decision: "deny", respondedBy: { channelType: "none", userId: "" } });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let adapterFailures = 0;
|
|
61
|
+
for (const adapter of this.adapters.values()) {
|
|
62
|
+
adapter.sendApproval(prompt, (decision) => {
|
|
63
|
+
if (resolved)
|
|
64
|
+
return;
|
|
65
|
+
resolved = true;
|
|
66
|
+
clearTimeout(timeout);
|
|
67
|
+
controller.abort();
|
|
68
|
+
handles.forEach(h => h.cancel());
|
|
69
|
+
resolve({ decision, respondedBy: { channelType: adapter.type, userId: adapter.id } });
|
|
70
|
+
}, controller.signal).then(handle => handles.push(handle)).catch(err => {
|
|
71
|
+
this.logger?.warn({ err }, "Failed to send approval prompt via adapter");
|
|
72
|
+
adapterFailures++;
|
|
73
|
+
if (adapterFailures === this.adapters.size) {
|
|
74
|
+
if (resolved)
|
|
75
|
+
return;
|
|
76
|
+
resolved = true;
|
|
77
|
+
clearTimeout(timeout);
|
|
78
|
+
this.logger?.error("All adapters failed to send approval prompt, auto-denying");
|
|
79
|
+
resolve({ decision: "deny", reason: "All channel adapters failed to send approval prompt" });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=message-bus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-bus.js","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AAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBACxF,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACrE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,4CAA4C,CAAC,CAAC;oBACzE,eAAe,EAAE,CAAC;oBAClB,IAAI,eAAe,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;wBAC3C,IAAI,QAAQ;4BAAE,OAAO;wBACrB,QAAQ,GAAG,IAAI,CAAC;wBAChB,YAAY,CAAC,OAAO,CAAC,CAAC;wBACtB,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,2DAA2D,CAAC,CAAC;wBAChF,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,qDAAqD,EAAE,CAAC,CAAC;oBAC/F,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { QueuedMessage } from "./types.js";
|
|
2
|
+
interface QueueSender {
|
|
3
|
+
send(chatId: string, threadId: string | undefined, text: string): Promise<{
|
|
4
|
+
messageId: string;
|
|
5
|
+
}>;
|
|
6
|
+
edit(chatId: string, messageId: string, text: string): Promise<void>;
|
|
7
|
+
sendFile(chatId: string, threadId: string | undefined, filePath: string): Promise<{
|
|
8
|
+
messageId: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export declare class MessageQueue {
|
|
12
|
+
private sender;
|
|
13
|
+
private queues;
|
|
14
|
+
private stopped;
|
|
15
|
+
private logger?;
|
|
16
|
+
constructor(sender: QueueSender, logger?: {
|
|
17
|
+
warn(obj: unknown, msg?: string): void;
|
|
18
|
+
});
|
|
19
|
+
private queueKey;
|
|
20
|
+
private getOrCreateQueue;
|
|
21
|
+
enqueue(chatId: string, threadId: string | undefined, msg: QueuedMessage): void;
|
|
22
|
+
start(): void;
|
|
23
|
+
stop(): void;
|
|
24
|
+
private runWorker;
|
|
25
|
+
/**
|
|
26
|
+
* Synchronously extracts items from the queue and returns the extracted items
|
|
27
|
+
* plus an async work function. The work function does the actual sending.
|
|
28
|
+
* This split allows us to know which items to re-queue if the work fails.
|
|
29
|
+
*/
|
|
30
|
+
private prepareNext;
|
|
31
|
+
/**
|
|
32
|
+
* Merges all adjacent content messages at the front of the queue.
|
|
33
|
+
* Respects the 4096 char limit per chunk.
|
|
34
|
+
* Returns merged chunks plus the original consumed items (for re-queuing on error).
|
|
35
|
+
*/
|
|
36
|
+
private mergeContentMessages;
|
|
37
|
+
private sleep;
|
|
38
|
+
}
|
|
39
|
+
export {};
|