@paperclipai/plugin-sdk 2026.3.17-canary.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +888 -0
  3. package/dist/bundlers.d.ts +57 -0
  4. package/dist/bundlers.d.ts.map +1 -0
  5. package/dist/bundlers.js +105 -0
  6. package/dist/bundlers.js.map +1 -0
  7. package/dist/define-plugin.d.ts +218 -0
  8. package/dist/define-plugin.d.ts.map +1 -0
  9. package/dist/define-plugin.js +85 -0
  10. package/dist/define-plugin.js.map +1 -0
  11. package/dist/dev-cli.d.ts +3 -0
  12. package/dist/dev-cli.d.ts.map +1 -0
  13. package/dist/dev-cli.js +49 -0
  14. package/dist/dev-cli.js.map +1 -0
  15. package/dist/dev-server.d.ts +34 -0
  16. package/dist/dev-server.d.ts.map +1 -0
  17. package/dist/dev-server.js +194 -0
  18. package/dist/dev-server.js.map +1 -0
  19. package/dist/host-client-factory.d.ts +229 -0
  20. package/dist/host-client-factory.d.ts.map +1 -0
  21. package/dist/host-client-factory.js +353 -0
  22. package/dist/host-client-factory.js.map +1 -0
  23. package/dist/index.d.ts +84 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +84 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/protocol.d.ts +881 -0
  28. package/dist/protocol.d.ts.map +1 -0
  29. package/dist/protocol.js +297 -0
  30. package/dist/protocol.js.map +1 -0
  31. package/dist/testing.d.ts +63 -0
  32. package/dist/testing.d.ts.map +1 -0
  33. package/dist/testing.js +700 -0
  34. package/dist/testing.js.map +1 -0
  35. package/dist/types.d.ts +982 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +12 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/ui/components.d.ts +257 -0
  40. package/dist/ui/components.d.ts.map +1 -0
  41. package/dist/ui/components.js +97 -0
  42. package/dist/ui/components.js.map +1 -0
  43. package/dist/ui/hooks.d.ts +120 -0
  44. package/dist/ui/hooks.d.ts.map +1 -0
  45. package/dist/ui/hooks.js +148 -0
  46. package/dist/ui/hooks.js.map +1 -0
  47. package/dist/ui/index.d.ts +50 -0
  48. package/dist/ui/index.d.ts.map +1 -0
  49. package/dist/ui/index.js +48 -0
  50. package/dist/ui/index.js.map +1 -0
  51. package/dist/ui/runtime.d.ts +3 -0
  52. package/dist/ui/runtime.d.ts.map +1 -0
  53. package/dist/ui/runtime.js +30 -0
  54. package/dist/ui/runtime.js.map +1 -0
  55. package/dist/ui/types.d.ts +308 -0
  56. package/dist/ui/types.d.ts.map +1 -0
  57. package/dist/ui/types.js +17 -0
  58. package/dist/ui/types.js.map +1 -0
  59. package/dist/worker-rpc-host.d.ts +127 -0
  60. package/dist/worker-rpc-host.d.ts.map +1 -0
  61. package/dist/worker-rpc-host.js +941 -0
  62. package/dist/worker-rpc-host.js.map +1 -0
  63. package/package.json +88 -0
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Worker-side RPC host — runs inside the child process spawned by the host.
3
+ *
4
+ * This module is the worker-side counterpart to the server's
5
+ * `PluginWorkerManager`. It:
6
+ *
7
+ * 1. Reads newline-delimited JSON-RPC 2.0 requests from **stdin**
8
+ * 2. Dispatches them to the appropriate plugin handler (events, jobs, tools, …)
9
+ * 3. Writes JSON-RPC 2.0 responses back on **stdout**
10
+ * 4. Provides a concrete `PluginContext` whose SDK client methods (e.g.
11
+ * `ctx.state.get()`, `ctx.events.emit()`) send JSON-RPC requests to the
12
+ * host on stdout and await responses on stdin.
13
+ *
14
+ * ## Message flow
15
+ *
16
+ * ```
17
+ * Host (parent) Worker (this module)
18
+ * | |
19
+ * |--- request(initialize) -------------> | → calls plugin.setup(ctx)
20
+ * |<-- response(ok:true) ---------------- |
21
+ * | |
22
+ * |--- notification(onEvent) -----------> | → dispatches to registered handler
23
+ * | |
24
+ * |<-- request(state.get) --------------- | ← SDK client call from plugin code
25
+ * |--- response(result) ----------------> |
26
+ * | |
27
+ * |--- request(shutdown) ---------------> | → calls plugin.onShutdown()
28
+ * |<-- response(void) ------------------ |
29
+ * | (process exits)
30
+ * ```
31
+ *
32
+ * @see PLUGIN_SPEC.md §12 — Process Model
33
+ * @see PLUGIN_SPEC.md §13 — Host-Worker Protocol
34
+ * @see PLUGIN_SPEC.md §14 — SDK Surface
35
+ */
36
+ import type { PaperclipPlugin } from "./define-plugin.js";
37
+ /**
38
+ * Options for starting the worker-side RPC host.
39
+ */
40
+ export interface WorkerRpcHostOptions {
41
+ /**
42
+ * The plugin definition returned by `definePlugin()`.
43
+ *
44
+ * The worker entrypoint should import its plugin and pass it here.
45
+ */
46
+ plugin: PaperclipPlugin;
47
+ /**
48
+ * Input stream to read JSON-RPC messages from.
49
+ * Defaults to `process.stdin`.
50
+ */
51
+ stdin?: NodeJS.ReadableStream;
52
+ /**
53
+ * Output stream to write JSON-RPC messages to.
54
+ * Defaults to `process.stdout`.
55
+ */
56
+ stdout?: NodeJS.WritableStream;
57
+ /**
58
+ * Default timeout (ms) for worker→host RPC calls.
59
+ * Defaults to 30 000 ms.
60
+ */
61
+ rpcTimeoutMs?: number;
62
+ }
63
+ /**
64
+ * A running worker RPC host instance.
65
+ *
66
+ * Returned by `startWorkerRpcHost()`. Callers (usually just the worker
67
+ * bootstrap) hold a reference so they can inspect status or force-stop.
68
+ */
69
+ export interface WorkerRpcHost {
70
+ /** Whether the host is currently running and listening for messages. */
71
+ readonly running: boolean;
72
+ /**
73
+ * Stop the RPC host immediately. Closes readline, rejects pending
74
+ * outbound calls, and does NOT call the plugin's shutdown hook (that
75
+ * should have already been called via the `shutdown` RPC method).
76
+ */
77
+ stop(): void;
78
+ }
79
+ /**
80
+ * Options for runWorker when testing (optional stdio to avoid using process streams).
81
+ * When both stdin and stdout are provided, the "is main module" check is skipped
82
+ * and the host is started with these streams. Used by tests.
83
+ */
84
+ export interface RunWorkerOptions {
85
+ stdin?: NodeJS.ReadableStream;
86
+ stdout?: NodeJS.WritableStream;
87
+ }
88
+ /**
89
+ * Start the worker when this module is the process entrypoint.
90
+ *
91
+ * Call this at the bottom of your worker file so that when the host runs
92
+ * `node dist/worker.js`, the RPC host starts and the process stays alive.
93
+ * When the module is imported (e.g. for re-exports or tests), nothing runs.
94
+ *
95
+ * When `options.stdin` and `options.stdout` are provided (e.g. in tests),
96
+ * the main-module check is skipped and the host is started with those streams.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const plugin = definePlugin({ ... });
101
+ * export default plugin;
102
+ * runWorker(plugin, import.meta.url);
103
+ * ```
104
+ */
105
+ export declare function runWorker(plugin: PaperclipPlugin, moduleUrl: string, options?: RunWorkerOptions): WorkerRpcHost | void;
106
+ /**
107
+ * Start the worker-side RPC host.
108
+ *
109
+ * This function is typically called from a thin bootstrap script that is the
110
+ * actual entrypoint of the child process:
111
+ *
112
+ * ```ts
113
+ * // worker-bootstrap.ts
114
+ * import plugin from "./worker.js";
115
+ * import { startWorkerRpcHost } from "@paperclipai/plugin-sdk";
116
+ *
117
+ * startWorkerRpcHost({ plugin });
118
+ * ```
119
+ *
120
+ * The host begins listening on stdin immediately. It does NOT call
121
+ * `plugin.definition.setup()` yet — that happens when the host sends the
122
+ * `initialize` RPC.
123
+ *
124
+ * @returns A handle for inspecting or stopping the RPC host
125
+ */
126
+ export declare function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost;
127
+ //# sourceMappingURL=worker-rpc-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-rpc-host.d.ts","sourceRoot":"","sources":["../src/worker-rpc-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAQH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAwD1D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,MAAM,EAAE,eAAe,CAAC;IAExB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAE9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAE/B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;OAIG;IACH,IAAI,IAAI,IAAI,CAAC;CACd;AAuBD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,eAAe,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,aAAa,GAAG,IAAI,CAkBtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CA0+B/E"}