palmier 0.1.4 → 0.1.5

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.
@@ -41,24 +41,34 @@ export async function serveCommand() {
41
41
  }
42
42
  console.log("Agent serving. Waiting for RPC messages...");
43
43
  for await (const msg of sub) {
44
- let request;
45
- try {
46
- request = JSON.parse(sc.decode(msg.data));
47
- }
48
- catch {
49
- console.error("Failed to parse RPC message");
50
- if (msg.reply) {
51
- msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
44
+ // Derive RPC method from subject: ...rpc.<method parts>
45
+ const subjectTokens = msg.subject.split(".");
46
+ const rpcIdx = subjectTokens.indexOf("rpc");
47
+ const method = rpcIdx >= 0 ? subjectTokens.slice(rpcIdx + 1).join(".") : "";
48
+ // Parse params from message body (the PWA sends params directly, no wrapper)
49
+ let params = {};
50
+ if (msg.data && msg.data.length > 0) {
51
+ const raw = sc.decode(msg.data).trim();
52
+ if (raw.length > 0) {
53
+ try {
54
+ params = JSON.parse(raw);
55
+ }
56
+ catch {
57
+ console.error(`Failed to parse RPC params for ${method}`);
58
+ if (msg.reply) {
59
+ msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
60
+ }
61
+ continue;
62
+ }
52
63
  }
53
- continue;
54
64
  }
55
- console.log(`RPC: ${request.method}`);
65
+ console.log(`RPC: ${method}`);
56
66
  let response;
57
67
  try {
58
- response = await handleRpc(request);
68
+ response = await handleRpc({ method, params });
59
69
  }
60
70
  catch (err) {
61
- console.error(`RPC error (${request.method}):`, err);
71
+ console.error(`RPC error (${method}):`, err);
62
72
  response = { error: String(err) };
63
73
  }
64
74
  if (msg.reply) {
@@ -137,7 +147,7 @@ export async function serveCommand() {
137
147
  cwd: config.projectRoot,
138
148
  timeout: 120_000,
139
149
  });
140
- return { ok: true, output };
150
+ return { ok: true, body: output };
141
151
  }
142
152
  catch (err) {
143
153
  const error = err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palmier",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Palmier agent CLI - provisions, executes tasks, and serves NATS RPC",
5
5
  "license": "ISC",
6
6
  "author": "Hongxu Cai",
@@ -49,24 +49,35 @@ export async function serveCommand(): Promise<void> {
49
49
  console.log("Agent serving. Waiting for RPC messages...");
50
50
 
51
51
  for await (const msg of sub) {
52
- let request: RpcMessage;
53
- try {
54
- request = JSON.parse(sc.decode(msg.data)) as RpcMessage;
55
- } catch {
56
- console.error("Failed to parse RPC message");
57
- if (msg.reply) {
58
- msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
52
+ // Derive RPC method from subject: ...rpc.<method parts>
53
+ const subjectTokens = msg.subject.split(".");
54
+ const rpcIdx = subjectTokens.indexOf("rpc");
55
+ const method = rpcIdx >= 0 ? subjectTokens.slice(rpcIdx + 1).join(".") : "";
56
+
57
+ // Parse params from message body (the PWA sends params directly, no wrapper)
58
+ let params: Record<string, unknown> = {};
59
+ if (msg.data && msg.data.length > 0) {
60
+ const raw = sc.decode(msg.data).trim();
61
+ if (raw.length > 0) {
62
+ try {
63
+ params = JSON.parse(raw);
64
+ } catch {
65
+ console.error(`Failed to parse RPC params for ${method}`);
66
+ if (msg.reply) {
67
+ msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
68
+ }
69
+ continue;
70
+ }
59
71
  }
60
- continue;
61
72
  }
62
73
 
63
- console.log(`RPC: ${request.method}`);
74
+ console.log(`RPC: ${method}`);
64
75
 
65
76
  let response: unknown;
66
77
  try {
67
- response = await handleRpc(request);
78
+ response = await handleRpc({ method, params });
68
79
  } catch (err) {
69
- console.error(`RPC error (${request.method}):`, err);
80
+ console.error(`RPC error (${method}):`, err);
70
81
  response = { error: String(err) };
71
82
  }
72
83
 
@@ -176,7 +187,7 @@ export async function serveCommand(): Promise<void> {
176
187
  cwd: config.projectRoot,
177
188
  timeout: 120_000,
178
189
  });
179
- return { ok: true, output };
190
+ return { ok: true, body: output };
180
191
  } catch (err: unknown) {
181
192
  const error = err as { stdout?: string; stderr?: string };
182
193
  return { error: "claude command failed", stdout: error.stdout, stderr: error.stderr };