@dmsdc-ai/aigentry-telepty 0.1.0 → 0.1.1
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/daemon.js +19 -0
- package/mcp.js +21 -0
- package/package.json +1 -1
package/daemon.js
CHANGED
|
@@ -178,6 +178,25 @@ app.delete('/api/sessions/:id', (req, res) => {
|
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
+
app.post('/api/bus/publish', (req, res) => {
|
|
182
|
+
const payload = req.body;
|
|
183
|
+
|
|
184
|
+
if (!payload || typeof payload !== 'object') {
|
|
185
|
+
return res.status(400).json({ error: 'Payload must be a JSON object' });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let deliveredCount = 0;
|
|
189
|
+
|
|
190
|
+
busClients.forEach(client => {
|
|
191
|
+
if (client.readyState === 1) { // WebSocket.OPEN
|
|
192
|
+
client.send(JSON.stringify(payload));
|
|
193
|
+
deliveredCount++;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
res.json({ success: true, delivered: deliveredCount });
|
|
198
|
+
});
|
|
199
|
+
|
|
181
200
|
const server = app.listen(PORT, HOST, () => {
|
|
182
201
|
console.log(`🚀 aigentry-telepty daemon listening on http://${HOST}:${PORT}`);
|
|
183
202
|
});
|
package/mcp.js
CHANGED
|
@@ -26,6 +26,14 @@ const tools = [
|
|
|
26
26
|
broadcast: z.boolean().optional().describe('If true, injects the prompt into ALL active sessions on the remote daemon. Overrides session_ids.'),
|
|
27
27
|
prompt: z.string().describe('Text to inject into stdin.')
|
|
28
28
|
})
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'telepty_publish_bus_event',
|
|
32
|
+
description: 'Publish a structured JSON event to the telepty in-memory event bus. This is a fire-and-forget broadcast to any AI agents currently listening. If no agents are listening, the message is dropped.',
|
|
33
|
+
schema: z.object({
|
|
34
|
+
remote_url: z.string().describe('Tailscale IP/Host and port (e.g., 100.100.100.5:3848) of the remote daemon.'),
|
|
35
|
+
payload: z.record(z.any()).describe('The structured JSON payload to broadcast to the event bus. Must be an object.')
|
|
36
|
+
})
|
|
29
37
|
}
|
|
30
38
|
];
|
|
31
39
|
|
|
@@ -83,6 +91,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
83
91
|
|
|
84
92
|
return { content: [{ type: 'text', text: msg }] };
|
|
85
93
|
}
|
|
94
|
+
|
|
95
|
+
if (name === 'telepty_publish_bus_event') {
|
|
96
|
+
const baseUrl = args.remote_url.startsWith('http') ? args.remote_url : `http://${args.remote_url}`;
|
|
97
|
+
|
|
98
|
+
const res = await fetch(`${baseUrl}/api/bus/publish`, {
|
|
99
|
+
method: 'POST', headers: { 'Content-Type': 'application/json', 'x-telepty-token': TOKEN }, body: JSON.stringify(args.payload)
|
|
100
|
+
});
|
|
101
|
+
const data = await res.json();
|
|
102
|
+
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
103
|
+
|
|
104
|
+
return { content: [{ type: 'text', text: `✅ Successfully published event to the bus. Delivered to ${data.delivered} active listeners.` }] };
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
throw new Error(`Unknown tool: ${name}`);
|
|
87
108
|
} catch (err) {
|
|
88
109
|
return { content: [{ type: 'text', text: `❌ Error: ${err.message}` }], isError: true };
|