pi-msgpack-rpc 0.1.2 → 0.2.0

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.
Files changed (3) hide show
  1. package/index.ts +20 -4
  2. package/package.json +10 -2
  3. package/rpc.ts +6 -6
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
3
  import { Type } from "typebox";
4
4
 
5
5
  import { msgpackRpcCall } from "./rpc";
@@ -8,7 +8,7 @@ export default function (pi: ExtensionAPI) {
8
8
  pi.registerTool({
9
9
  name: "msgpack_rpc_call",
10
10
  label: "MessagePack RPC Call",
11
- description: "Generic MessagePack RPC call (based on your working talk.ts script)",
11
+ description: "Generic MessagePack RPC Calls Interface",
12
12
  parameters: Type.Object({
13
13
  server: Type.String({ description: "Exact socket path from :echo v:servername inside Neovim" }),
14
14
  method: Type.String({ description: "e.g. nvim_get_api_info" }),
@@ -28,9 +28,9 @@ export default function (pi: ExtensionAPI) {
28
28
  throw new Error("server and method are required");
29
29
  }
30
30
 
31
- ctx.ui.notify(`[RPC] Starting call to ${server} → ${method}`, "info");
31
+ ctx.ui.notify(`[Tool] Starting call to ${server} → ${method}`, "info");
32
32
 
33
- const result = await msgpackRpcCall(ctx, server, method, args, timeout);
33
+ const result = await msgpackRpcCall(server, method, args, timeout, ctx);
34
34
 
35
35
  return {
36
36
  content: [{ type: "text", text: result }],
@@ -38,4 +38,20 @@ export default function (pi: ExtensionAPI) {
38
38
  };
39
39
  },
40
40
  });
41
+
42
+ pi.events.on("msgpack:rpc:call", async (payload: any, ctx?: any) => {
43
+ const { server, method, params = [], timeout = 30000, correlationId } = payload || {};
44
+
45
+ if (!server || !method || !correlationId) {
46
+ pi.events.emit("msgpack:rpc:response", { correlationId, success: false, error: "Missing required fields" });
47
+ return;
48
+ }
49
+
50
+ try {
51
+ const result = await msgpackRpcCall(server, method, params, timeout, ctx);
52
+ pi.events.emit("msgpack:rpc:response", { correlationId, success: true, result });
53
+ } catch (err: any) {
54
+ pi.events.emit("msgpack:rpc:response", { correlationId, success: false, error: err.message });
55
+ }
56
+ })
41
57
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-msgpack-rpc",
3
3
  "description": "A MessagePack RPC tool for Pi",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "main": "index.ts",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,5 +11,13 @@
11
11
  "dependencies": {
12
12
  "msgpackr": "^1.11.10"
13
13
  },
14
- "pi": { "extensions": ["./index.ts"] }
14
+ "devDependencies": {
15
+ "@earendil-works/pi-coding-agent": "latest",
16
+ "@types/node": "^25.6.2"
17
+ },
18
+ "pi": {
19
+ "extensions": [
20
+ "./index.ts"
21
+ ]
22
+ }
15
23
  }
package/rpc.ts CHANGED
@@ -4,30 +4,30 @@ import { pipeline } from 'node:stream';
4
4
  import { pack, UnpackrStream } from 'msgpackr';
5
5
 
6
6
  export async function msgpackRpcCall(
7
- ctx: any,
8
7
  server: string,
9
8
  method: string,
10
9
  args : any[] = [],
11
- timeout = 5000
10
+ timeout = 30000,
11
+ ctx?: any
12
12
  ) {
13
13
  return new Promise((resolve, reject) => {
14
14
  const unpackStream = new UnpackrStream();
15
15
 
16
16
  const client = net.createConnection(server, () => {
17
- ctx.ui.notify(`[RPC] Connected to ${server}, calling ${method}`, "info");
17
+ if (ctx) ctx.ui.notify(`[RPC] Connected to ${server}, calling ${method}`, "info");
18
18
  client.write(pack([0, Date.now() % 1000000, method, args]));
19
19
  })
20
20
 
21
21
  pipeline(client, unpackStream, (err) => {
22
- if (err) ctx.ui.notify(`[RPC] Pipeline error: ${err.message}`, "error");
22
+ if (err && ctx) ctx.ui.notify(`[RPC] Pipeline error: ${err.message}`, "error");
23
23
  });
24
24
 
25
25
  unpackStream.on('data', (msg: any) => {
26
- ctx.ui.notify(`[RPC] Received response`, "success");
26
+ if (ctx) ctx.ui.notify(`[RPC] Received response`, "success");
27
27
  client.end();
28
28
 
29
29
  if (Array.isArray(msg) && msg[0] === 1) {
30
- const error = msg[2]; const result = msg[3];
30
+ const error = msg[2]; const result = msg[3] || "n/a";
31
31
  error !== null && error !== undefined ? reject(error) : resolve(result);
32
32
  } else {
33
33
  resolve(msg);