posipaki 0.27.0 → 0.27.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.
@@ -32,7 +32,7 @@ declare const bunConnector: (scriptPath: string) => Connector;
32
32
  /** Spawn via `node <script>`. */
33
33
  declare const nodeConnector: (scriptPath: string) => Connector;
34
34
  /**
35
- * Auto-detect: prefers `bun run` if the script is a .ts file and bun is
35
+ * Auto-detect: prefers `bun run` if bun is
36
36
  * the current runtime, otherwise falls back to `node`.
37
37
  */
38
38
  declare function defaultConnector(scriptPath: string): Connector;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts","../../src/remote/fifo.ts","../../src/remote/protocol.ts"],"mappings":";;;;iBAQgB,WACd,kBACA,2BACA;EACG;EAAkB;;iBASD,SAAS,MAAM,OAAO,cAAc,SAAS,eAAe,SAChF,IAAI,eAAe,MAAM,OAAO,OAAO,UACtC;;;UCNc,oBAAoB,OAAO;EAC1C;EACA,MAAM;EACN;;UAGe,YACf,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU;WAEhB,OAAO;EAChB,SAAS;EACT,KAAK,KAAK;EACV,QAAQ;IAAU;IAAqB,OAAO;;EAC9C,UAAU,UAAU,KAAK;;;KAIf,UACV,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU,YACtB,MAAM,wBAAwB,QAAQ,YAAY,OAAO,OAAO;iBAI/C,YACpB,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU,SACzB,OAAO,yBACP,MAAM,oBAAoB,QAAQ,QAAQ,YAAY,OAAO,OAAO;;cA0HzD,eAAY,uBAZ+D;;cAe3E,gBAAa,uBAf8D;;;;;iBAqBxE,iBAAiB,qBAAqB;cAUzC,yBAAgB;;;UC1KZ;EACf;EACA,YAAY;;UAGG,kBACf,MACA,OACA,cAAc,SACd,eAAe,SACf,0BAA0B;EAE1B,OAAO,gBAAgB,MAAM,OAAO,OAAO,QAAQ;EACnD,iBAAiB;EACjB;;iBASc,kBACd,MACA,OACA,cAAc,SACd,eAAe,SACf,gBAAgB,eAChB,iBAAiB,eAAe,QAChC,mBAAmB,mBAEnB,OAAO,gBAAgB,MAAM,OAAO,OAAO,QAAQ,aACnD,aACA,OAAM,qBACL,kBAAkB,MAAM,OAAO,OAAO,QAAQ;;;cC9CpC;UACH;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAED;iBA8Cc;iBAKA;SAKd,QAAQ,QAAQ,YAAY,SAAS,aAAa;UAMjD;;;;;;;;;SAYD,aACL,kBACA;IACG,WAAW,QAAQ;;;;;;;;;;;SAqBX,QAAQ,kBAAkB,oBAAoB,QAAQ;MAU/D;EAKJ,UAAU,UAAU;EASpB,mBAAmB;MAMf;MAIA,aAAa;EAIX,KAAK,eAAe;EAQpB,SAAS;UAMD;;;;cCrKH;iBAEG,OAAO,aAAa;iBAIpB,OAAO,eAAe;iBAMtB,QAAQ,KAAK,0BAA0B;EAAS;;iBAGhD,OAAO,KAAK,0BAA0B;EAAS,OAAO;;iBAGtD,QAAQ,KAAK,0BAA0B;EAAS,QAAQ;;iBAGxD,MAAM,KAAK,0BAA0B;EAAS;IAAQ;IAAc;IAAkB;;;iBAGtF,OAAO,KAAK,0BAA0B;EAAS;IAAS;IAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts","../../src/remote/fifo.ts","../../src/remote/protocol.ts"],"mappings":";;;;iBAQgB,WACd,kBACA,2BACA;EACG;EAAkB;;iBASD,SAAS,MAAM,OAAO,cAAc,SAAS,eAAe,SAChF,IAAI,eAAe,MAAM,OAAO,OAAO,UACtC;;;UCNc,oBAAoB,OAAO;EAC1C;EACA,MAAM;EACN;;UAGe,YACf,iBACA,cAAc,UAAU,SACxB,eAAe,UAAU;WAEhB,OAAO;EAChB,SAAS;EACT,KAAK,KAAK;EACV,QAAQ;I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AkB;;;iBAGtF,OAAO,KAAK,0BAA0B;EAAS;IAAS;IAAc"}
@@ -389,17 +389,15 @@ function scriptConnector(runner, runnerArgs) {
389
389
  };
390
390
  }
391
391
  /** Spawn via `bun run <script>`. */
392
- const bunConnector = scriptConnector("bun", ["run"]);
392
+ const bunConnector = scriptConnector("bun", []);
393
393
  /** Spawn via `node <script>`. */
394
394
  const nodeConnector = scriptConnector("node", []);
395
395
  /**
396
- * Auto-detect: prefers `bun run` if the script is a .ts file and bun is
396
+ * Auto-detect: prefers `bun run` if bun is
397
397
  * the current runtime, otherwise falls back to `node`.
398
398
  */
399
399
  function defaultConnector(scriptPath) {
400
- const isBun = typeof globalThis.Bun !== "undefined";
401
- const isTs = scriptPath.endsWith(".ts");
402
- if (isBun && isTs) return bunConnector(scriptPath);
400
+ if (typeof globalThis.Bun !== "undefined") return bunConnector(scriptPath);
403
401
  return nodeConnector(scriptPath);
404
402
  }
405
403
  const commandConnector = spawnRemote;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/remote/fifo.ts","../../src/remote/protocol.ts","../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts"],"sourcesContent":["// ── FIFO transport ─────────────────────────────────────────────────────────\n//\n// Newline-delimited UTF-8 over named fifos. Strict handler lifecycle:\n// onMessage() throws if a handler is already set; call removeHandler() first.\n\nimport { open, type FileHandle } from \"node:fs/promises\";\nimport { createReadStream, createWriteStream, type ReadStream, type WriteStream } from \"node:fs\";\nimport * as readline from \"node:readline\";\n\nexport class FifoUtf8NlineTransport {\n private readFd: FileHandle | null;\n private writeFd: FileHandle | null;\n private rl: readline.Interface | null;\n private rs: ReadStream | null;\n private ws: WriteSteeam | null;\n private pvtOnMessage: ((line: string) => void) | null = null;\n private closed = false;\n private closingPromise: Promise<void> | null;\n private pvtError: Error | null = null;\n private pvtWriter: FifoUtf8NlineTransport | null = null;\n\n private constructor(opts: { readFd?: FileHandle; writeFd?: FileHandle }) {\n this.readFd = opts.readFd ?? null;\n this.writeFd = opts.writeFd ?? null;\n\n if (this.readFd) {\n this.rs = createReadStream(\"\", {\n fd: this.readFd.fd,\n encoding: \"utf-8\",\n autoClose: false,\n });\n this.rl = readline.createInterface({ input: this.rs });\n\n this.rl.on(\"line\", (line) => {\n if (this.pvtOnMessage && !this.closed) this.pvtOnMessage(line);\n });\n\n this.rl.on(\"close\", () => {\n this.close();\n });\n\n this.rs.on(\"error\", (err: Error) => {\n this.pvtError = err;\n this.close();\n });\n } else {\n this.rs = null;\n this.rl = null;\n }\n\n if (this.writeFd) {\n this.ws = createWriteStream(\"\", {\n fd: this.writeFd.fd,\n encoding: \"utf-8\",\n autoclose: false,\n });\n this.ws.on(\"error\", (err: Error) => {\n this.pvtError = err;\n this.close();\n });\n } else {\n this.ws = null;\n }\n }\n\n // ── factories ──────────────────────────────────────────────────────────\n\n private static async openReader(path: string): Promise<FifoUtf8NlineTransport> {\n const readFd = await open(path, \"r\");\n return new FifoUtf8NlineTransport({ readFd });\n }\n\n private static async openWriter(path: string): Promise<FifoUtf8NlineTransport> {\n const writeFd = await open(path, \"w\");\n return new FifoUtf8NlineTransport({ writeFd });\n }\n\n static fromFds(readFd: FileHandle, writeFd: FileHandle): FifoUtf8NlineTransport {\n return new FifoUtf8NlineTransport({ readFd, writeFd });\n }\n\n // ── bidirectional connection ───────────────────────────────────────────\n\n private attachWriter(w: FifoUtf8NlineTransport): void {\n this.pvtWriter = w;\n }\n\n /**\n * Start opening a bidirectional connection. Opens readPath for reading\n * in the background, returns a promise. The caller should do whatever\n * setup is needed to unblock the read (e.g. spawn a process that opens\n * readPath for writing), then await the returned transport.\n *\n * Once the read completes, writePath is opened for writing automatically.\n */\n static beginConnect(\n readPath: string,\n writePath: string,\n ): { transport: Promise<FifoUtf8NlineTransport> } {\n const readerPromise = FifoUtf8NlineTransport.openReader(readPath);\n\n const transport = readerPromise.then(async (reader) => {\n const writer = await FifoUtf8NlineTransport.openWriter(writePath);\n reader.attachWriter(writer);\n return reader;\n });\n\n return { transport };\n }\n\n /**\n * Open a bidirectional connection. Opens writePath for writing first\n * (unblocking the peer's read), starts reading readPath in the\n * background, then awaits both.\n *\n * Use this when you are the side that responds to the peer's beginConnect\n * (i.e. you don't need to interleave any setup between the read and write\n * opens).\n */\n static async connect(readPath: string, writePath: string): Promise<FifoUtf8NlineTransport> {\n const readerPromise = FifoUtf8NlineTransport.openReader(readPath);\n const writer = await FifoUtf8NlineTransport.openWriter(writePath);\n const reader = await readerPromise;\n reader.attachWriter(writer);\n return reader;\n }\n\n // ── public API ─────────────────────────────────────────────────────────\n\n get canSend(): boolean {\n if (this.pvtWriter) return this.pvtWriter.canSend;\n return this.writeFd !== null && !this.closed;\n }\n\n onMessage(handler: (line: string) => void): void {\n if (this.closed) throw new Error(\"FifoUtf8NlineTransport: closed\");\n if (this.readFd === null) throw new Error(\"FifoUtf8NlineTransport: not a reader\");\n if (this.pvtOnMessage !== null) {\n throw new Error(\"FifoUtf8NlineTransport: handler already set — call removeHandler() first\");\n }\n this.pvtOnMessage = handler;\n }\n\n removeHandler(): ((line: string) => void) | null {\n const prev = this.pvtOnMessage;\n this.pvtOnMessage = null;\n return prev;\n }\n\n get hasHandler(): boolean {\n return this.pvtOnMessage !== null;\n }\n\n get lastError(): Error | null {\n return this.pvtError;\n }\n\n async send(line: string): Promise<void> {\n if (this.pvtWriter) return this.pvtWriter.send(line);\n if (this.closed) throw new Error(\"FifoUtf8NlineTransport: closed\");\n if (this.writeFd === null) throw new Error(\"FifoUtf8NlineTransport: not a writer\");\n if (!line.endsWith(\"\\n\")) line += \"\\n\";\n await this.ws.write(line);\n }\n\n async close(): Promise<void> {\n this.closingPromise = this.closingPromise || this.pvtClose();\n await this.closingPromise;\n this.closed = true;\n }\n\n private async pvtClose(): Promise<void> {\n // tranfser control back to caller\n // so they can capture the promise reference\n // and prevent reentry\n await Promise.resolve();\n\n if (this.rl) {\n this.rl.close();\n this.rl = null;\n }\n if (this.rs) {\n this.rs.destroy();\n this.rs = null;\n }\n if (this.ws) {\n await new Promise(async (resolve) => {\n try {\n await this.ws.end(\"\", resolve);\n } catch {\n resolve();\n }\n });\n this.ws = null;\n }\n\n if (this.readFd) {\n try {\n await this.readFd.close();\n } catch {}\n this.readFd = null;\n }\n if (this.writeFd) {\n try {\n await this.writeFd.close();\n } catch {}\n this.writeFd = null;\n }\n if (this.pvtWriter) {\n await this.pvtWriter.close();\n }\n }\n}\n","// ── Wire protocol ──────────────────────────────────────────────────────────\n//\n// NDJSON wire protocol: one JSON object per line.\n// child → host: $proto, $state, $msg, $exit\n// host → child: $init, $msg\n\nexport const PROTO_VERSION = \"ndjson.v1\";\n\nexport function encode(key: string, value: unknown): string {\n return JSON.stringify({ [key]: value }) + \"\\n\";\n}\n\nexport function decode(line: string): Record<string, unknown> {\n return JSON.parse(line);\n}\n\n// ── type guards ──────────────────────────────────────────────────────────\n\nexport function isProto(msg: Record<string, unknown>): msg is { $proto: string } {\n return \"$proto\" in msg;\n}\nexport function isInit(msg: Record<string, unknown>): msg is { $init: Record<string, unknown> } {\n return \"$init\" in msg;\n}\nexport function isState(msg: Record<string, unknown>): msg is { $state: Record<string, unknown> } {\n return \"$state\" in msg;\n}\nexport function isMsg(msg: Record<string, unknown>): msg is { $msg: { type: string; fromName: string; body: unknown } } {\n return \"$msg\" in msg;\n}\nexport function isExit(msg: Record<string, unknown>): msg is { $exit: { code: number; state: unknown } } {\n return \"$exit\" in msg;\n}\n","// ── Child-side adapter ─────────────────────────────────────────────────────\n//\n// Wraps a posipaki actor in a CLI process that speaks the wire protocol over\n// two unidirectional named fifos.\n\nimport type { AsyncProcessFn, Message } from \"../types.js\";\nimport { FifoUtf8NlineTransport } from \"./fifo.js\";\n\nexport function makeSender(\n fromName: string,\n parentName: string | null,\n parentId: symbol | null,\n): { fromName: string; fromId: symbol } {\n if (parentId && fromName === parentName) {\n return { fromName, fromId: parentId };\n }\n return { fromName, fromId: Symbol() };\n}\nimport { encode, decode, isInit, isMsg, PROTO_VERSION } from \"./protocol.js\";\nimport { spawnAsync } from \"../index.js\";\n\nexport async function runChild<Args, State, InMsg extends Message, OutMsg extends Message>(\n fn: AsyncProcessFn<Args, State, InMsg, OutMsg>,\n): Promise<void> {\n const fifoIn = process.argv.find((a) => a.startsWith(\"--fifo-in=\"))?.slice(\"--fifo-in=\".length);\n const fifoOut = process.argv\n .find((a) => a.startsWith(\"--fifo-out=\"))\n ?.slice(\"--fifo-out=\".length);\n\n if (!fifoIn || !fifoOut) {\n console.error(\"child: --fifo-in=<path> and --fifo-out=<path> required\");\n process.exit(1);\n }\n\n const transport = await FifoUtf8NlineTransport.connect(fifoOut, fifoIn);\n\n // 1. Send protocol version\n await transport.send(encode(\"$proto\", PROTO_VERSION));\n\n // 2. Wait for $init\n const initMsg = await new Promise<Record<string, unknown>>((resolve) => {\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isInit(msg)) resolve(msg.$init);\n });\n });\n transport.removeHandler();\n\n const parentName = (initMsg.parentName as string) ?? null;\n const parentIdName = (initMsg.parentIdName as string) ?? null;\n const parentId = parentIdName ? Symbol.for(parentIdName) : null;\n const { parentName: _pn, parentIdName: _pid, ...initArgs } = initMsg;\n\n const wrappedFn: typeof fn = async function* (ctx, args) {\n (ctx as Record<string, unknown>).parentName = parentName;\n (ctx as Record<string, unknown>).parentId = parentId;\n return yield* fn(ctx, args);\n };\n\n const proc = spawnAsync(wrappedFn, \"remote\")(initArgs as unknown as Args);\n proc.subscribe(\"message\", async (msg, sender) => {\n try {\n const encodedMsg = encode(\"$msg\", {\n fromName: sender.fromName,\n body: msg,\n });\n await transport.send(encodedMsg);\n } catch (e) {\n console.error(\"Error sending out the message\");\n }\n });\n\n proc.subscribe(\"state\", async () => {\n try {\n const encodedState = encode(\"$state\", proc.state as Record<string, unknown>);\n await transport.send(encodedState);\n } catch (e) {\n console.error(\"Error sending out the message\", e);\n }\n });\n\n await proc.ready();\n\n await transport.send(encode(\"$state\", proc.state as Record<string, unknown>));\n\n // 6. Forward incoming messages to the actor\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isMsg(msg)) {\n const { fromName, body } = msg.$msg;\n proc.send(body as InMsg, { fromName, fromId: Symbol() });\n }\n });\n\n // 7. On actor exit, send $exit\n const shutdown = async (code: number) => {\n await transport.send(encode(\"$exit\", { code, state: proc.state }));\n await transport.close();\n process.exit(code);\n };\n proc.wait().then(\n () => shutdown(0),\n (err: unknown) => {\n console.error(\"child actor error:\", err);\n shutdown(1);\n },\n );\n}\n","// ── Host-side adapter ──────────────────────────────────────────────────────\n//\n// commandConnector: spawns a child process and bridges the wire protocol.\n// Connector wrappers (bunConnector, nodeConnector, defaultConnector) produce\n// the command array from a script path.\n\nimport { spawn, execSync, type ChildProcess } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { unlink } from \"node:fs/promises\";\nimport { FifoUtf8NlineTransport } from \"./fifo.js\";\nimport { encode, decode, isProto, isState, isMsg, isExit, PROTO_VERSION } from \"./protocol.js\";\nimport type { Message } from \"../types.js\";\n\n// ── types ──────────────────────────────────────────────────────────────────\n\nexport interface CommandSpawnOptions<Args = Record<string, unknown>> {\n command: string[];\n args: Args;\n parentName?: string;\n}\n\nexport interface RemoteProxy<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n> {\n readonly state: State;\n ready(): Promise<void>;\n send(msg: InMsg): void;\n wait(): Promise<{ code: number | null; state: State }>;\n onMessage(handler: (msg: OutMsg) => void): void;\n}\n\n/** A connector takes a command and returns a RemoteProxy. */\nexport type Connector<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n> = (opts: CommandSpawnOptions) => Promise<RemoteProxy<State, InMsg, OutMsg>>;\n\n// ── commandConnector ───────────────────────────────────────────────────────\n\nexport async function spawnRemote<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n Args = Record<string, unknown>,\n>(opts: CommandSpawnOptions<Args>): Promise<RemoteProxy<State, InMsg, OutMsg>> {\n const basePath = join(tmpdir(), `posipaki-${randomUUID()}`);\n\n execSync(`mkfifo \"${basePath}.in\"`);\n execSync(`mkfifo \"${basePath}.out\"`);\n\n const setup = FifoUtf8NlineTransport.beginConnect(basePath + \".in\", basePath + \".out\");\n\n const childCmd = [\n ...opts.command,\n `--fifo-in=${basePath + \".in\"}`,\n `--fifo-out=${basePath + \".out\"}`,\n ];\n const childProc: ChildProcess = spawn(childCmd[0], childCmd.slice(1), {\n cwd: process.cwd(),\n stdio: [\"inherit\", \"inherit\", \"inherit\"],\n });\n\n const transport = await setup.transport;\n\n // ── handshake ───────────────────────────────────────────────────────\n const protoLine = await new Promise<string>((resolve) => {\n transport.onMessage((line) => resolve(line));\n });\n const protoMsg = decode(protoLine);\n if (!isProto(protoMsg) || protoMsg.$proto !== PROTO_VERSION) {\n throw new Error(`unsupported protocol: ${protoLine.slice(0, 50)}`);\n }\n transport.removeHandler();\n\n await transport.send(\n encode(\"$init\", {\n ...(opts.args as Record<string, unknown>),\n parentName: opts.parentName ?? \"host\",\n parentIdName: opts.parentName ?? \"host\",\n }),\n );\n\n let currentState: Record<string, unknown> = {};\n await new Promise<void>((resolve) => {\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isState(msg)) {\n Object.assign(currentState, msg.$state as Record<string, unknown>);\n resolve();\n }\n });\n });\n transport.removeHandler();\n\n // ── persistent handler ──────────────────────────────────────────────\n let msgHandler: ((msg: OutMsg) => void) | null = null;\n let exitResolver: ((value: { code: number | null; state: State }) => void) | null = null;\n const exitPromise = new Promise<{ code: number | null; state: State }>((resolve) => {\n exitResolver = resolve;\n });\n\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isState(msg)) {\n Object.assign(currentState, msg.$state as Record<string, unknown>);\n } else if (isMsg(msg)) {\n msgHandler?.(msg.$msg.body as OutMsg);\n } else if (isExit(msg)) {\n if (exitResolver) {\n exitResolver({ code: msg.$exit.code, state: msg.$exit.state as State });\n exitResolver = null;\n }\n cleanup();\n }\n });\n\n // ── cleanup ─────────────────────────────────────────────────────────\n let cleaned = false;\n const cleanup = () => {\n if (cleaned) return;\n cleaned = true;\n transport.close();\n unlink(basePath + \".in\").catch(() => {});\n unlink(basePath + \".out\").catch(() => {});\n };\n\n childProc.on(\"exit\", (code) => {\n if (exitResolver) {\n exitResolver({ code, state: currentState as State });\n exitResolver = null;\n }\n cleanup();\n });\n\n return {\n get state(): State {\n return currentState as State;\n },\n async ready() {},\n send(msg: InMsg) {\n const from = opts.parentName ?? \"host\";\n transport.send(encode(\"$msg\", { fromName: from, body: msg }));\n },\n async wait() {\n return exitPromise;\n },\n onMessage(handler: (msg: OutMsg) => void) {\n msgHandler = handler;\n },\n };\n}\n\n// ── connector wrappers ─────────────────────────────────────────────────────\n\nfunction scriptConnector(runner: string, runnerArgs: string[]): (scriptPath: string) => Connector {\n return (scriptPath: string) => {\n return ((opts: CommandSpawnOptions) => {\n return commandConnector({\n ...opts,\n command: [runner, ...runnerArgs, scriptPath, ...opts.command],\n });\n }) as Connector;\n };\n}\n\n/** Spawn via `bun run <script>`. */\nexport const bunConnector = scriptConnector(\"bun\", [\"run\"]);\n\n/** Spawn via `node <script>`. */\nexport const nodeConnector = scriptConnector(\"node\", []);\n\n/**\n * Auto-detect: prefers `bun run` if the script is a .ts file and bun is\n * the current runtime, otherwise falls back to `node`.\n */\nexport function defaultConnector(scriptPath: string): Connector {\n // Check if we're running under bun\n const isBun = typeof (globalThis as any).Bun !== \"undefined\";\n const isTs = scriptPath.endsWith(\".ts\");\n if (isBun && isTs) return bunConnector(scriptPath);\n return nodeConnector(scriptPath);\n}\n\n// ── alias ───────────────────────────────────────────────────────────────────\n\nexport const commandConnector = spawnRemote;\n","// ── defineRemoteActor ──────────────────────────────────────────────────────\n//\n// Wraps an ActorDefinition so that when spawned, it runs in a child process\n// over two named fifos. Returns { actor, runRemoteRoot, isRemoteRoot }.\n//\n// Uses defineActor's setup hook to spawn the remote child before the first\n// yield, so proc.ready() shows the live remote state — same as local spawn.\n\nimport { fileURLToPath } from \"node:url\";\nimport { createHash } from \"node:crypto\";\nimport type { Message } from \"../types.js\";\nimport type { HandlerOptions, MethodOptions, ReflectionOptions } from \"../actor-types.js\";\nimport { defineActor } from \"../define-actor.js\";\nimport { stopPropagation } from \"../hooks.js\";\nimport type { HookResult } from \"../hooks.js\";\nimport { runChild } from \"./child.js\";\nimport { type Connector, defaultConnector } from \"./host.js\";\nimport type { RemoteProxy } from \"./host.js\";\nimport type { ActorDefinition } from \"../actor-types.js\";\n\nexport interface RemoteActorOptions {\n manual?: boolean;\n connector?: Connector;\n}\n\nexport interface RemoteActorBundle<\n Args,\n State,\n InMsg extends Message,\n OutMsg extends Message,\n ReflectionMethods extends ReflectionOptions,\n> {\n actor: ActorDefinition<Args, State, InMsg, OutMsg, ReflectionMethods>;\n runRemoteRoot(): Promise<void>;\n isRemoteRoot: boolean;\n}\n\nfunction pathHash(path: string): string {\n return createHash(\"sha256\").update(path).digest(\"hex\").slice(0, 12);\n}\n\nconst MARKER_PREFIX = \"--remote=\";\n\nexport function defineRemoteActor<\n Args,\n State,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n Handlers extends HandlerOptions<InMsg>,\n Reflection extends ReflectionOptions,\n>(\n actor: ActorDefinition<Args, State, InMsg, OutMsg, Reflection>,\n url: string,\n opts: RemoteActorOptions = {},\n): RemoteActorBundle<Args, State, InMsg, OutMsg, Reflection> {\n const scriptPath = fileURLToPath(url);\n const marker = `${MARKER_PREFIX}${pathHash(scriptPath)}`;\n const isRemoteRoot = !opts.manual && process.argv.includes(marker);\n\n if (isRemoteRoot) {\n runChild(actor.fn);\n }\n\n const proxyDef = defineActor<\n Args,\n { public: State; private: { remote: RemoteProxy<State, InMsg, OutMsg> } },\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n Reflection\n >({\n name: actor.name ?? \"actor\",\n inMessages: actor.inMessages,\n outMessages: actor.outMessages,\n handlers: {} as unknown as Handlers,\n async setup(args: Args) {\n const connect = opts.connector ?? defaultConnector(scriptPath);\n const remote = (await connect({\n command: [marker],\n args: args as Record<string, unknown>,\n })) as RemoteProxy<State, InMsg, OutMsg>;\n remote.onMessage((msg: OutMsg) => {\n this.emit(msg);\n });\n return {\n public: remote.state,\n private: { remote },\n };\n },\n async onMessage(msg: InMsg): Promise<HookResult> {\n this.state.private.remote?.send(msg);\n return stopPropagation();\n },\n async onStopRequested() {\n if (this.state.private.remote) {\n this.state.private.remote.send({ type: \"STOP\" } as InMsg);\n await this.state.private.remote.wait();\n }\n this.agreeToStop();\n },\n });\n\n return {\n actor: proxyDef as ActorDefinition<Args, State, InMsg, OutMsg, Reflection>,\n runRemoteRoot() {\n return runChild(actor.fn);\n },\n isRemoteRoot,\n };\n}\n"],"mappings":";;;;;;;;;;;AASA,IAAa,yBAAb,MAAa,uBAAuB;CAYlC,YAAoB,MAAqD;EANjB,KAAA,eAAA;EACvC,KAAA,SAAA;EAEgB,KAAA,WAAA;EACkB,KAAA,YAAA;EAGjD,KAAK,SAAS,KAAK,UAAU;EAC7B,KAAK,UAAU,KAAK,WAAW;EAE/B,IAAI,KAAK,QAAQ;GACf,KAAK,KAAK,iBAAiB,IAAI;IAC7B,IAAI,KAAK,OAAO;IAChB,UAAU;IACV,WAAW;GACb,CAAC;GACD,KAAK,KAAK,SAAS,gBAAgB,EAAE,OAAO,KAAK,GAAG,CAAC;GAErD,KAAK,GAAG,GAAG,SAAS,SAAS;IAC3B,IAAI,KAAK,gBAAgB,CAAC,KAAK,QAAQ,KAAK,aAAa,IAAI;GAC/D,CAAC;GAED,KAAK,GAAG,GAAG,eAAe;IACxB,KAAK,MAAM;GACb,CAAC;GAED,KAAK,GAAG,GAAG,UAAU,QAAe;IAClC,KAAK,WAAW;IAChB,KAAK,MAAM;GACb,CAAC;EACH,OAAO;GACL,KAAK,KAAK;GACV,KAAK,KAAK;EACZ;EAEA,IAAI,KAAK,SAAS;GAChB,KAAK,KAAK,kBAAkB,IA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,KAAK,YAAY;GACnB;EACF,CAGgB;EACd,gBAAgB;GACd,OAAO,SAAS,MAAM,EAAE;EAC1B;EACA;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/remote/fifo.ts","../../src/remote/protocol.ts","../../src/remote/child.ts","../../src/remote/host.ts","../../src/remote/define.ts"],"sourcesContent":["// ── FIFO transport ─────────────────────────────────────────────────────────\n//\n// Newline-delimited UTF-8 over named fifos. Strict handler lifecycle:\n// onMessage() throws if a handler is already set; call removeHandler() first.\n\nimport { open, type FileHandle } from \"node:fs/promises\";\nimport { createReadStream, createWriteStream, type ReadStream, type WriteStream } from \"node:fs\";\nimport * as readline from \"node:readline\";\n\nexport class FifoUtf8NlineTransport {\n private readFd: FileHandle | null;\n private writeFd: FileHandle | null;\n private rl: readline.Interface | null;\n private rs: ReadStream | null;\n private ws: WriteSteeam | null;\n private pvtOnMessage: ((line: string) => void) | null = null;\n private closed = false;\n private closingPromise: Promise<void> | null;\n private pvtError: Error | null = null;\n private pvtWriter: FifoUtf8NlineTransport | null = null;\n\n private constructor(opts: { readFd?: FileHandle; writeFd?: FileHandle }) {\n this.readFd = opts.readFd ?? null;\n this.writeFd = opts.writeFd ?? null;\n\n if (this.readFd) {\n this.rs = createReadStream(\"\", {\n fd: this.readFd.fd,\n encoding: \"utf-8\",\n autoClose: false,\n });\n this.rl = readline.createInterface({ input: this.rs });\n\n this.rl.on(\"line\", (line) => {\n if (this.pvtOnMessage && !this.closed) this.pvtOnMessage(line);\n });\n\n this.rl.on(\"close\", () => {\n this.close();\n });\n\n this.rs.on(\"error\", (err: Error) => {\n this.pvtError = err;\n this.close();\n });\n } else {\n this.rs = null;\n this.rl = null;\n }\n\n if (this.writeFd) {\n this.ws = createWriteStream(\"\", {\n fd: this.writeFd.fd,\n encoding: \"utf-8\",\n autoclose: false,\n });\n this.ws.on(\"error\", (err: Error) => {\n this.pvtError = err;\n this.close();\n });\n } else {\n this.ws = null;\n }\n }\n\n // ── factories ──────────────────────────────────────────────────────────\n\n private static async openReader(path: string): Promise<FifoUtf8NlineTransport> {\n const readFd = await open(path, \"r\");\n return new FifoUtf8NlineTransport({ readFd });\n }\n\n private static async openWriter(path: string): Promise<FifoUtf8NlineTransport> {\n const writeFd = await open(path, \"w\");\n return new FifoUtf8NlineTransport({ writeFd });\n }\n\n static fromFds(readFd: FileHandle, writeFd: FileHandle): FifoUtf8NlineTransport {\n return new FifoUtf8NlineTransport({ readFd, writeFd });\n }\n\n // ── bidirectional connection ───────────────────────────────────────────\n\n private attachWriter(w: FifoUtf8NlineTransport): void {\n this.pvtWriter = w;\n }\n\n /**\n * Start opening a bidirectional connection. Opens readPath for reading\n * in the background, returns a promise. The caller should do whatever\n * setup is needed to unblock the read (e.g. spawn a process that opens\n * readPath for writing), then await the returned transport.\n *\n * Once the read completes, writePath is opened for writing automatically.\n */\n static beginConnect(\n readPath: string,\n writePath: string,\n ): { transport: Promise<FifoUtf8NlineTransport> } {\n const readerPromise = FifoUtf8NlineTransport.openReader(readPath);\n\n const transport = readerPromise.then(async (reader) => {\n const writer = await FifoUtf8NlineTransport.openWriter(writePath);\n reader.attachWriter(writer);\n return reader;\n });\n\n return { transport };\n }\n\n /**\n * Open a bidirectional connection. Opens writePath for writing first\n * (unblocking the peer's read), starts reading readPath in the\n * background, then awaits both.\n *\n * Use this when you are the side that responds to the peer's beginConnect\n * (i.e. you don't need to interleave any setup between the read and write\n * opens).\n */\n static async connect(readPath: string, writePath: string): Promise<FifoUtf8NlineTransport> {\n const readerPromise = FifoUtf8NlineTransport.openReader(readPath);\n const writer = await FifoUtf8NlineTransport.openWriter(writePath);\n const reader = await readerPromise;\n reader.attachWriter(writer);\n return reader;\n }\n\n // ── public API ─────────────────────────────────────────────────────────\n\n get canSend(): boolean {\n if (this.pvtWriter) return this.pvtWriter.canSend;\n return this.writeFd !== null && !this.closed;\n }\n\n onMessage(handler: (line: string) => void): void {\n if (this.closed) throw new Error(\"FifoUtf8NlineTransport: closed\");\n if (this.readFd === null) throw new Error(\"FifoUtf8NlineTransport: not a reader\");\n if (this.pvtOnMessage !== null) {\n throw new Error(\"FifoUtf8NlineTransport: handler already set — call removeHandler() first\");\n }\n this.pvtOnMessage = handler;\n }\n\n removeHandler(): ((line: string) => void) | null {\n const prev = this.pvtOnMessage;\n this.pvtOnMessage = null;\n return prev;\n }\n\n get hasHandler(): boolean {\n return this.pvtOnMessage !== null;\n }\n\n get lastError(): Error | null {\n return this.pvtError;\n }\n\n async send(line: string): Promise<void> {\n if (this.pvtWriter) return this.pvtWriter.send(line);\n if (this.closed) throw new Error(\"FifoUtf8NlineTransport: closed\");\n if (this.writeFd === null) throw new Error(\"FifoUtf8NlineTransport: not a writer\");\n if (!line.endsWith(\"\\n\")) line += \"\\n\";\n await this.ws.write(line);\n }\n\n async close(): Promise<void> {\n this.closingPromise = this.closingPromise || this.pvtClose();\n await this.closingPromise;\n this.closed = true;\n }\n\n private async pvtClose(): Promise<void> {\n // tranfser control back to caller\n // so they can capture the promise reference\n // and prevent reentry\n await Promise.resolve();\n\n if (this.rl) {\n this.rl.close();\n this.rl = null;\n }\n if (this.rs) {\n this.rs.destroy();\n this.rs = null;\n }\n if (this.ws) {\n await new Promise(async (resolve) => {\n try {\n await this.ws.end(\"\", resolve);\n } catch {\n resolve();\n }\n });\n this.ws = null;\n }\n\n if (this.readFd) {\n try {\n await this.readFd.close();\n } catch {}\n this.readFd = null;\n }\n if (this.writeFd) {\n try {\n await this.writeFd.close();\n } catch {}\n this.writeFd = null;\n }\n if (this.pvtWriter) {\n await this.pvtWriter.close();\n }\n }\n}\n","// ── Wire protocol ──────────────────────────────────────────────────────────\n//\n// NDJSON wire protocol: one JSON object per line.\n// child → host: $proto, $state, $msg, $exit\n// host → child: $init, $msg\n\nexport const PROTO_VERSION = \"ndjson.v1\";\n\nexport function encode(key: string, value: unknown): string {\n return JSON.stringify({ [key]: value }) + \"\\n\";\n}\n\nexport function decode(line: string): Record<string, unknown> {\n return JSON.parse(line);\n}\n\n// ── type guards ──────────────────────────────────────────────────────────\n\nexport function isProto(msg: Record<string, unknown>): msg is { $proto: string } {\n return \"$proto\" in msg;\n}\nexport function isInit(msg: Record<string, unknown>): msg is { $init: Record<string, unknown> } {\n return \"$init\" in msg;\n}\nexport function isState(msg: Record<string, unknown>): msg is { $state: Record<string, unknown> } {\n return \"$state\" in msg;\n}\nexport function isMsg(msg: Record<string, unknown>): msg is { $msg: { type: string; fromName: string; body: unknown } } {\n return \"$msg\" in msg;\n}\nexport function isExit(msg: Record<string, unknown>): msg is { $exit: { code: number; state: unknown } } {\n return \"$exit\" in msg;\n}\n","// ── Child-side adapter ─────────────────────────────────────────────────────\n//\n// Wraps a posipaki actor in a CLI process that speaks the wire protocol over\n// two unidirectional named fifos.\n\nimport type { AsyncProcessFn, Message } from \"../types.js\";\nimport { FifoUtf8NlineTransport } from \"./fifo.js\";\n\nexport function makeSender(\n fromName: string,\n parentName: string | null,\n parentId: symbol | null,\n): { fromName: string; fromId: symbol } {\n if (parentId && fromName === parentName) {\n return { fromName, fromId: parentId };\n }\n return { fromName, fromId: Symbol() };\n}\nimport { encode, decode, isInit, isMsg, PROTO_VERSION } from \"./protocol.js\";\nimport { spawnAsync } from \"../index.js\";\n\nexport async function runChild<Args, State, InMsg extends Message, OutMsg extends Message>(\n fn: AsyncProcessFn<Args, State, InMsg, OutMsg>,\n): Promise<void> {\n const fifoIn = process.argv.find((a) => a.startsWith(\"--fifo-in=\"))?.slice(\"--fifo-in=\".length);\n const fifoOut = process.argv\n .find((a) => a.startsWith(\"--fifo-out=\"))\n ?.slice(\"--fifo-out=\".length);\n\n if (!fifoIn || !fifoOut) {\n console.error(\"child: --fifo-in=<path> and --fifo-out=<path> required\");\n process.exit(1);\n }\n\n const transport = await FifoUtf8NlineTransport.connect(fifoOut, fifoIn);\n\n // 1. Send protocol version\n await transport.send(encode(\"$proto\", PROTO_VERSION));\n\n // 2. Wait for $init\n const initMsg = await new Promise<Record<string, unknown>>((resolve) => {\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isInit(msg)) resolve(msg.$init);\n });\n });\n transport.removeHandler();\n\n const parentName = (initMsg.parentName as string) ?? null;\n const parentIdName = (initMsg.parentIdName as string) ?? null;\n const parentId = parentIdName ? Symbol.for(parentIdName) : null;\n const { parentName: _pn, parentIdName: _pid, ...initArgs } = initMsg;\n\n const wrappedFn: typeof fn = async function* (ctx, args) {\n (ctx as Record<string, unknown>).parentName = parentName;\n (ctx as Record<string, unknown>).parentId = parentId;\n return yield* fn(ctx, args);\n };\n\n const proc = spawnAsync(wrappedFn, \"remote\")(initArgs as unknown as Args);\n proc.subscribe(\"message\", async (msg, sender) => {\n try {\n const encodedMsg = encode(\"$msg\", {\n fromName: sender.fromName,\n body: msg,\n });\n await transport.send(encodedMsg);\n } catch (e) {\n console.error(\"Error sending out the message\");\n }\n });\n\n proc.subscribe(\"state\", async () => {\n try {\n const encodedState = encode(\"$state\", proc.state as Record<string, unknown>);\n await transport.send(encodedState);\n } catch (e) {\n console.error(\"Error sending out the message\", e);\n }\n });\n\n await proc.ready();\n\n await transport.send(encode(\"$state\", proc.state as Record<string, unknown>));\n\n // 6. Forward incoming messages to the actor\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isMsg(msg)) {\n const { fromName, body } = msg.$msg;\n proc.send(body as InMsg, { fromName, fromId: Symbol() });\n }\n });\n\n // 7. On actor exit, send $exit\n const shutdown = async (code: number) => {\n await transport.send(encode(\"$exit\", { code, state: proc.state }));\n await transport.close();\n process.exit(code);\n };\n proc.wait().then(\n () => shutdown(0),\n (err: unknown) => {\n console.error(\"child actor error:\", err);\n shutdown(1);\n },\n );\n}\n","// ── Host-side adapter ──────────────────────────────────────────────────────\n//\n// commandConnector: spawns a child process and bridges the wire protocol.\n// Connector wrappers (bunConnector, nodeConnector, defaultConnector) produce\n// the command array from a script path.\n\nimport { spawn, execSync, type ChildProcess } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { unlink } from \"node:fs/promises\";\nimport { FifoUtf8NlineTransport } from \"./fifo.js\";\nimport { encode, decode, isProto, isState, isMsg, isExit, PROTO_VERSION } from \"./protocol.js\";\nimport type { Message } from \"../types.js\";\n\n// ── types ──────────────────────────────────────────────────────────────────\n\nexport interface CommandSpawnOptions<Args = Record<string, unknown>> {\n command: string[];\n args: Args;\n parentName?: string;\n}\n\nexport interface RemoteProxy<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n> {\n readonly state: State;\n ready(): Promise<void>;\n send(msg: InMsg): void;\n wait(): Promise<{ code: number | null; state: State }>;\n onMessage(handler: (msg: OutMsg) => void): void;\n}\n\n/** A connector takes a command and returns a RemoteProxy. */\nexport type Connector<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n> = (opts: CommandSpawnOptions) => Promise<RemoteProxy<State, InMsg, OutMsg>>;\n\n// ── commandConnector ───────────────────────────────────────────────────────\n\nexport async function spawnRemote<\n State = unknown,\n InMsg extends Message = Message,\n OutMsg extends Message = Message,\n Args = Record<string, unknown>,\n>(opts: CommandSpawnOptions<Args>): Promise<RemoteProxy<State, InMsg, OutMsg>> {\n const basePath = join(tmpdir(), `posipaki-${randomUUID()}`);\n\n execSync(`mkfifo \"${basePath}.in\"`);\n execSync(`mkfifo \"${basePath}.out\"`);\n\n const setup = FifoUtf8NlineTransport.beginConnect(basePath + \".in\", basePath + \".out\");\n\n const childCmd = [\n ...opts.command,\n `--fifo-in=${basePath + \".in\"}`,\n `--fifo-out=${basePath + \".out\"}`,\n ];\n const childProc: ChildProcess = spawn(childCmd[0], childCmd.slice(1), {\n cwd: process.cwd(),\n stdio: [\"inherit\", \"inherit\", \"inherit\"],\n });\n\n const transport = await setup.transport;\n\n // ── handshake ───────────────────────────────────────────────────────\n const protoLine = await new Promise<string>((resolve) => {\n transport.onMessage((line) => resolve(line));\n });\n const protoMsg = decode(protoLine);\n if (!isProto(protoMsg) || protoMsg.$proto !== PROTO_VERSION) {\n throw new Error(`unsupported protocol: ${protoLine.slice(0, 50)}`);\n }\n transport.removeHandler();\n\n await transport.send(\n encode(\"$init\", {\n ...(opts.args as Record<string, unknown>),\n parentName: opts.parentName ?? \"host\",\n parentIdName: opts.parentName ?? \"host\",\n }),\n );\n\n let currentState: Record<string, unknown> = {};\n await new Promise<void>((resolve) => {\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isState(msg)) {\n Object.assign(currentState, msg.$state as Record<string, unknown>);\n resolve();\n }\n });\n });\n transport.removeHandler();\n\n // ── persistent handler ──────────────────────────────────────────────\n let msgHandler: ((msg: OutMsg) => void) | null = null;\n let exitResolver: ((value: { code: number | null; state: State }) => void) | null = null;\n const exitPromise = new Promise<{ code: number | null; state: State }>((resolve) => {\n exitResolver = resolve;\n });\n\n transport.onMessage((line) => {\n const msg = decode(line);\n if (isState(msg)) {\n Object.assign(currentState, msg.$state as Record<string, unknown>);\n } else if (isMsg(msg)) {\n msgHandler?.(msg.$msg.body as OutMsg);\n } else if (isExit(msg)) {\n if (exitResolver) {\n exitResolver({ code: msg.$exit.code, state: msg.$exit.state as State });\n exitResolver = null;\n }\n cleanup();\n }\n });\n\n // ── cleanup ─────────────────────────────────────────────────────────\n let cleaned = false;\n const cleanup = () => {\n if (cleaned) return;\n cleaned = true;\n transport.close();\n unlink(basePath + \".in\").catch(() => {});\n unlink(basePath + \".out\").catch(() => {});\n };\n\n childProc.on(\"exit\", (code) => {\n if (exitResolver) {\n exitResolver({ code, state: currentState as State });\n exitResolver = null;\n }\n cleanup();\n });\n\n return {\n get state(): State {\n return currentState as State;\n },\n async ready() {},\n send(msg: InMsg) {\n const from = opts.parentName ?? \"host\";\n transport.send(encode(\"$msg\", { fromName: from, body: msg }));\n },\n async wait() {\n return exitPromise;\n },\n onMessage(handler: (msg: OutMsg) => void) {\n msgHandler = handler;\n },\n };\n}\n\n// ── connector wrappers ─────────────────────────────────────────────────────\n\nfunction scriptConnector(runner: string, runnerArgs: string[]): (scriptPath: string) => Connector {\n return (scriptPath: string) => {\n return ((opts: CommandSpawnOptions) => {\n return commandConnector({\n ...opts,\n command: [runner, ...runnerArgs, scriptPath, ...opts.command],\n });\n }) as Connector;\n };\n}\n\n/** Spawn via `bun run <script>`. */\nexport const bunConnector = scriptConnector(\"bun\", []);\n\n/** Spawn via `node <script>`. */\nexport const nodeConnector = scriptConnector(\"node\", []);\n\n/**\n * Auto-detect: prefers `bun run` if bun is\n * the current runtime, otherwise falls back to `node`.\n */\nexport function defaultConnector(scriptPath: string): Connector {\n // Check if we're running under bun\n const isBun = typeof (globalThis as any).Bun !== \"undefined\";\n if (isBun) return bunConnector(scriptPath);\n return nodeConnector(scriptPath);\n}\n\n// ── alias ───────────────────────────────────────────────────────────────────\n\nexport const commandConnector = spawnRemote;\n","// ── defineRemoteActor ──────────────────────────────────────────────────────\n//\n// Wraps an ActorDefinition so that when spawned, it runs in a child process\n// over two named fifos. Returns { actor, runRemoteRoot, isRemoteRoot }.\n//\n// Uses defineActor's setup hook to spawn the remote child before the first\n// yield, so proc.ready() shows the live remote state — same as local spawn.\n\nimport { fileURLToPath } from \"node:url\";\nimport { createHash } from \"node:crypto\";\nimport type { Message } from \"../types.js\";\nimport type { HandlerOptions, MethodOptions, ReflectionOptions } from \"../actor-types.js\";\nimport { defineActor } from \"../define-actor.js\";\nimport { stopPropagation } from \"../hooks.js\";\nimport type { HookResult } from \"../hooks.js\";\nimport { runChild } from \"./child.js\";\nimport { type Connector, defaultConnector } from \"./host.js\";\nimport type { RemoteProxy } from \"./host.js\";\nimport type { ActorDefinition } from \"../actor-types.js\";\n\nexport interface RemoteActorOptions {\n manual?: boolean;\n connector?: Connector;\n}\n\nexport interface RemoteActorBundle<\n Args,\n State,\n InMsg extends Message,\n OutMsg extends Message,\n ReflectionMethods extends ReflectionOptions,\n> {\n actor: ActorDefinition<Args, State, InMsg, OutMsg, ReflectionMethods>;\n runRemoteRoot(): Promise<void>;\n isRemoteRoot: boolean;\n}\n\nfunction pathHash(path: string): string {\n return createHash(\"sha256\").update(path).digest(\"hex\").slice(0, 12);\n}\n\nconst MARKER_PREFIX = \"--remote=\";\n\nexport function defineRemoteActor<\n Args,\n State,\n InMsg extends Message,\n OutMsg extends Message,\n Methods extends MethodOptions,\n Handlers extends HandlerOptions<InMsg>,\n Reflection extends ReflectionOptions,\n>(\n actor: ActorDefinition<Args, State, InMsg, OutMsg, Reflection>,\n url: string,\n opts: RemoteActorOptions = {},\n): RemoteActorBundle<Args, State, InMsg, OutMsg, Reflection> {\n const scriptPath = fileURLToPath(url);\n const marker = `${MARKER_PREFIX}${pathHash(scriptPath)}`;\n const isRemoteRoot = !opts.manual && process.argv.includes(marker);\n\n if (isRemoteRoot) {\n runChild(actor.fn);\n }\n\n const proxyDef = defineActor<\n Args,\n { public: State; private: { remote: RemoteProxy<State, InMsg, OutMsg> } },\n InMsg,\n OutMsg,\n Methods,\n Handlers,\n Reflection\n >({\n name: actor.name ?? \"actor\",\n inMessages: actor.inMessages,\n outMessages: actor.outMessages,\n handlers: {} as unknown as Handlers,\n async setup(args: Args) {\n const connect = opts.connector ?? defaultConnector(scriptPath);\n const remote = (await connect({\n command: [marker],\n args: args as Record<string, unknown>,\n })) as RemoteProxy<State, InMsg, OutMsg>;\n remote.onMessage((msg: OutMsg) => {\n this.emit(msg);\n });\n return {\n public: remote.state,\n private: { remote },\n };\n },\n async onMessage(msg: InMsg): Promise<HookResult> {\n this.state.private.remote?.send(msg);\n return stopPropagation();\n },\n async onStopRequested() {\n if (this.state.private.remote) {\n this.state.private.remote.send({ type: \"STOP\" } as InMsg);\n await this.state.private.remote.wait();\n }\n this.agreeToStop();\n },\n });\n\n return {\n actor: proxyDef as ActorDefinition<Args, State, InMsg, OutMsg, Reflection>,\n runRemoteRoot() {\n return runChild(actor.fn);\n },\n isRemoteRoot,\n };\n}\n"],"mappings":";;;;;;;;;;;AASA,IAAa,yBAAb,MAAa,uBAAuB;CAYlC,YAAoB,MAAqD;EANjB,K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ACA,MAAM,MAAM,QAAQ;GACpB,YAAY,MAAM;GAClB,aAAa,MAAM;GACnB,UAAU,CAAC;GACX,MAAM,MAAM,MAAY;IAEtB,MAAM,SAAU,OADA,KAAK,aAAa,iBAAiB,UAAU,EAAA,CAC/B;KAC5B,SAAS,CAAC,MAAM;KACV;IACR,CAAC;IACD,OAAO,WAAW,QAAgB;KAChC,KAAK,KAAK,GAAG;IACf,CAAC;IACD,OAAO;KACL,QAAQ,OAAO;KACf,SAAS,EAAE,OAAO;IACpB;GACF;GACA,MAAM,UAAU,KAAiC;IAC/C,KAAK,MAAM,QAAQ,QAAQ,KAAK,GAAG;IACnC,OAAO,gBAAgB;GACzB;GACA,MAAM,kBAAkB;IACtB,IAAI,KAAK,MAAM,QAAQ,QAAQ;KAC7B,KAAK,MAAM,QAAQ,OAAO,KAAK,EAAE,MAAM,OAAO,CAAU;KACxD,MAAM,KAAK,MAAM,QAAQ,OAAO,KAAK;IACvC;IACA,KAAK,YAAY;GACnB;EACF,CAGgB;EACd,gBAAgB;GACd,OAAO,SAAS,MAAM,EAAE;EAC1B;EACA;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "posipaki",
4
- "version": "0.27.0",
4
+ "version": "0.27.1",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "files": [