svamp-cli 0.1.75 → 0.1.78

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.
@@ -144,6 +144,113 @@ async function sessionBroadcast(action, args) {
144
144
  });
145
145
  console.log(`Broadcast sent: ${action}`);
146
146
  }
147
+ async function connectToMachineService() {
148
+ const { connectAndGetMachine } = await import('./commands-B6FEeZeP.mjs');
149
+ return connectAndGetMachine();
150
+ }
151
+ async function inboxSend(targetSessionId, opts) {
152
+ const sessionId = process.env.SVAMP_SESSION_ID;
153
+ if (!sessionId) {
154
+ console.error("SVAMP_SESSION_ID not set. This command must be run inside a Svamp session.");
155
+ process.exit(1);
156
+ }
157
+ const body = opts?.body || "";
158
+ if (!body) {
159
+ console.error("Message body is required.");
160
+ process.exit(1);
161
+ }
162
+ const { server, machine } = await connectToMachineService();
163
+ try {
164
+ const { resolveSessionId } = await import('./commands-B6FEeZeP.mjs');
165
+ const sessions = await machine.listSessions();
166
+ const match = resolveSessionId(sessions, targetSessionId);
167
+ const fullTargetId = match.sessionId;
168
+ const { randomUUID } = await import('node:crypto');
169
+ const message = {
170
+ messageId: randomUUID(),
171
+ body,
172
+ timestamp: Date.now(),
173
+ read: false,
174
+ from: `agent:${sessionId}`,
175
+ fromSession: sessionId,
176
+ to: fullTargetId,
177
+ subject: opts?.subject,
178
+ urgency: opts?.urgency || "normal"
179
+ };
180
+ const result = await machine.sessionRPC(fullTargetId, "sendInboxMessage", [message]);
181
+ console.log(`Inbox message sent to ${fullTargetId.slice(0, 8)} (id: ${result.messageId.slice(0, 8)})`);
182
+ } finally {
183
+ await server.disconnect();
184
+ }
185
+ }
186
+ async function inboxList(opts) {
187
+ const sessionId = process.env.SVAMP_SESSION_ID;
188
+ if (!sessionId) {
189
+ console.error("SVAMP_SESSION_ID not set. This command must be run inside a Svamp session.");
190
+ process.exit(1);
191
+ }
192
+ const { server, machine } = await connectToMachineService();
193
+ try {
194
+ const result = await machine.sessionRPC(sessionId, "getInbox", [{ unread: opts?.unread, limit: opts?.limit }]);
195
+ const messages = result.messages;
196
+ if (opts?.json) {
197
+ console.log(JSON.stringify({ messages }, null, 2));
198
+ return;
199
+ }
200
+ if (messages.length === 0) {
201
+ console.log("Inbox is empty.");
202
+ return;
203
+ }
204
+ for (const msg of messages) {
205
+ const status = msg.read ? " " : "\u25CF";
206
+ const from = msg.from ? ` from ${msg.from}` : "";
207
+ const subject = msg.subject ? ` \u2014 ${msg.subject}` : "";
208
+ const urgencyTag = msg.urgency === "urgent" ? " [URGENT]" : "";
209
+ const preview = msg.body.length > 100 ? msg.body.slice(0, 97) + "..." : msg.body;
210
+ console.log(`${status} ${msg.messageId.slice(0, 8)}${urgencyTag}${from}${subject}: ${preview}`);
211
+ }
212
+ } finally {
213
+ await server.disconnect();
214
+ }
215
+ }
216
+ async function inboxReply(messageId, body) {
217
+ const sessionId = process.env.SVAMP_SESSION_ID;
218
+ if (!sessionId) {
219
+ console.error("SVAMP_SESSION_ID not set. This command must be run inside a Svamp session.");
220
+ process.exit(1);
221
+ }
222
+ const { server, machine } = await connectToMachineService();
223
+ try {
224
+ const result = await machine.sessionRPC(sessionId, "getInbox", []);
225
+ const original = result.messages.find((m) => m.messageId === messageId || m.messageId.startsWith(messageId));
226
+ if (!original) {
227
+ console.error(`Message ${messageId} not found in inbox.`);
228
+ process.exit(1);
229
+ }
230
+ if (!original.fromSession) {
231
+ console.error("Cannot reply: original message has no fromSession.");
232
+ process.exit(1);
233
+ }
234
+ const { randomUUID } = await import('node:crypto');
235
+ const reply = {
236
+ messageId: randomUUID(),
237
+ body,
238
+ timestamp: Date.now(),
239
+ read: false,
240
+ from: `agent:${sessionId}`,
241
+ fromSession: sessionId,
242
+ to: original.fromSession,
243
+ subject: original.subject ? `Re: ${original.subject}` : void 0,
244
+ urgency: "normal",
245
+ replyTo: original.messageId,
246
+ threadId: original.threadId || original.messageId
247
+ };
248
+ const sendResult = await machine.sessionRPC(original.fromSession, "sendInboxMessage", [reply]);
249
+ console.log(`Reply sent to ${original.fromSession.slice(0, 8)} (id: ${sendResult.messageId.slice(0, 8)})`);
250
+ } finally {
251
+ await server.disconnect();
252
+ }
253
+ }
147
254
  async function machineNotify(message, level = "info") {
148
255
  const machineId = process.env.SVAMP_MACHINE_ID;
149
256
  await connectAndEmit({
@@ -153,4 +260,4 @@ async function machineNotify(message, level = "info") {
153
260
  console.log(`Machine notification sent [${level}]: ${message}`);
154
261
  }
155
262
 
156
- export { machineNotify, sessionBroadcast, sessionNotify, sessionSetLink, sessionSetTitle };
263
+ export { inboxList, inboxReply, inboxSend, machineNotify, sessionBroadcast, sessionNotify, sessionSetLink, sessionSetTitle };