@skaile/transform-proxy 0.2.2 → 0.2.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.3
4
+
5
+ - omp extension: without `SKAILE_TRANSFORM_PROXY_URL`, `/anon on` starts the proxy as a child process under the system Node (`SKAILE_TRANSFORM_PROXY_NODE`, else `node` from `PATH`; Node ≥ 22) instead of inside omp. omp is a compiled Bun executable whose resolver cannot load transform modules with native or ML dependencies from `node_modules`: under omp 18.14.2, `/anon on` failed with `transform "anon": cannot load module @skaile/forge-anon/proxy: Cannot find package 'ibantools'`. The child runs this package's CLI with the found config, `--port 0 --host 127.0.0.1 --exit-with-stdin` and a random token, which every routed provider sends as `x-skaile-transform-token`. A child that exits before `listening <url>` or stays silent for 60 s fails `/anon on` with its last stderr lines (token redacted). The child exits with omp, does not keep omp's event loop alive, and is replaced on the next turn when it dies. A rotated-out proxy session is no longer dropped: the child keeps its state in memory until it exits, and no request carries that id again.
6
+ - CLI: `--exit-with-stdin` stops the proxy when its stdin closes, so a parent that spawns it with a stdin pipe takes it down on exit, SIGKILL included.
7
+
3
8
  ## 0.2.2
4
9
 
5
10
  - Fail closed on malformed request bodies: the Anthropic, OpenAI chat and OpenAI responses walkers refuse a JSON body whose shape they cannot classify (a root that is not an object; a `system`, `messages`, `input`, `instructions`, message `content`, text, thinking, tool-call `arguments` or tool-result slot of an unexpected type) with 400 `unsupported_content` instead of forwarding it untransformed. Unknown part, block and item types still pass through.
package/README.md CHANGED
@@ -60,12 +60,13 @@ Keys are exactly the option fields. An unknown top-level key is an error. Module
60
60
  ## CLI
61
61
 
62
62
  ```sh
63
- skaile-transform-proxy [--config <file>] [--port <n>] [--host <h>] [--token <t>]
63
+ skaile-transform-proxy [--config <file>] [--port <n>] [--host <h>] [--token <t>] [--exit-with-stdin]
64
64
  ```
65
65
 
66
66
  - The token comes from `--token` or `SKAILE_TRANSFORM_PROXY_TOKEN`.
67
67
  - Without `--config`, the proxy reads `./.skaile/transform-proxy.yaml`, then `~/.config/skaile/transform-proxy.yaml`.
68
68
  - On start it prints `listening <url>`. It stops on SIGINT or SIGTERM.
69
+ - `--exit-with-stdin` also stops it when its stdin closes. A parent process that spawns the proxy with a stdin pipe and never writes to it takes the proxy down when it exits, even on SIGKILL.
69
70
 
70
71
  ## Library
71
72
 
@@ -92,15 +93,16 @@ The package ships an [omp](https://omp.sh) extension (subpath `@skaile/transform
92
93
  omp plugin install @skaile/transform-proxy
93
94
  ```
94
95
 
95
- It adds the command `/anon on|off|status` and the footer status `anon on`, `anon off` or `anon error`.
96
+ It adds the command `/anon on|off|status` and the footer status `anon on`, `anon off` or `anon error`. Unless `SKAILE_TRANSFORM_PROXY_URL` names a running proxy, it needs Node ≥ 22 on `PATH` (or its path in `SKAILE_TRANSFORM_PROXY_NODE`).
96
97
 
97
98
  - `/anon on` routes every provider of omp's model registry through the proxy: the provider's `baseUrl` becomes the proxy URL, and the original base URL travels in `x-skaile-transform-upstream`, next to `x-skaile-transform-session` (the omp session id) and the token. The provider's own headers and auth stay in place and are relayed.
98
99
  - With `SKAILE_TRANSFORM_PROXY_URL` (and `SKAILE_TRANSFORM_PROXY_TOKEN`) set, it uses that running proxy, and the proxy applies its `defaultPipeline`.
99
- - Otherwise it starts one proxy inside the omp process, from the config lookup of the CLI (`./.skaile/transform-proxy.yaml`, then `~/.config/skaile/transform-proxy.yaml`). That config must set `defaultPipeline`. Without a config, `/anon on` refuses and says where to put one.
100
+ - Otherwise it starts one proxy per omp process as a child process: the system Node (`SKAILE_TRANSFORM_PROXY_NODE`, else `node` from `PATH`) runs this package's CLI with the config lookup of the CLI (`./.skaile/transform-proxy.yaml`, then `~/.config/skaile/transform-proxy.yaml`), `--port 0 --host 127.0.0.1 --exit-with-stdin` and a random token in `SKAILE_TRANSFORM_PROXY_TOKEN`, which every routed provider sends. That config must set `defaultPipeline`. Without a config, `/anon on` refuses and says where to put one. A child that exits before printing `listening <url>`, or stays silent for 60 s, fails `/anon on` with its last stderr lines.
101
+ - omp is a compiled Bun executable, and its resolver cannot load transform modules with native or ML dependencies (`onnxruntime-node`, `@huggingface/transformers`, `ibantools`) from `node_modules`; Node can. The child exits with omp: its stdin pipe closes when omp exits (SIGKILL included), and omp kills it on a normal exit. It does not keep omp's event loop alive. A child that dies later is replaced on the next turn.
100
102
  - Providers on a wire the proxy does not rewrite (Bedrock, Vertex, Gemini, agent bridges, providers without a base URL) are routed too, so the proxy refuses their requests: the setup fails closed. `/anon status` lists them as refused.
101
103
  - The session's active model is rebound to the re-routed one, so the next request already uses the new base URL. A rebind that fails is an activation failure: `/anon on` rolls the routes back, saves nothing and stays off. When anon is required, or a later turn's rebind fails while anon is on, the footer shows `anon error`.
102
104
  - While anon is on or in error, a `before_provider_request` handler checks every model request: a request whose model does not target the proxy gets its payload replaced with an empty object, so no conversation text leaves, and an error notice names the model. omp has no hook that cancels a provider request, and a throwing handler is only logged, so this replacement is the block.
103
- - The proxy session follows the root omp session: on `/new`, `/resume`, `/fork` (`session_switch`) and on a root `session_start` with a new session id, every provider is re-routed with the new `x-skaile-transform-session`, and the in-process proxy drops the old session. A `session_start` of a headless `print` session (how omp runs subagents) keeps the parent's id, so subagents share its pseudonyms.
105
+ - The proxy session follows the root omp session: on `/new`, `/resume`, `/fork` (`session_switch`) and on a root `session_start` with a new session id, every provider is re-routed with the new `x-skaile-transform-session`. The proxy keeps the old session's state in memory until it exits; no request carries that id again. A `session_start` of a headless `print` session (how omp runs subagents) keeps the parent's id, so subagents share its pseudonyms.
104
106
  - `/anon off` restores the original base URLs and headers.
105
107
  - `/anon status` shows the state, the proxy URL and its source, the pipeline, the session id, and the routed and refused providers.
106
108
  - The enabled flag is saved in `skaile-transform-proxy.json` in omp's agent dir (`~/.omp/agent`; `SKAILE_TRANSFORM_PROXY_OMP_STATE` overrides the path) and re-applied when a session starts.
package/dist/cli.d.mts CHANGED
@@ -12,6 +12,8 @@ export interface CliEnvironment {
12
12
  export interface CliRun {
13
13
  readonly code: number;
14
14
  readonly proxy?: TransformProxy;
15
+ /** `--exit-with-stdin`: the caller stops the proxy when its stdin closes (the parent process is gone). */
16
+ readonly exitWithStdin?: boolean;
15
17
  }
16
18
  /** Parses the arguments, loads the config and starts the proxy. Never installs signal handlers. */
17
19
  export declare function runCli(argv: readonly string[], io: CliEnvironment): Promise<CliRun>;
package/dist/cli.mjs CHANGED
@@ -7,7 +7,7 @@ import { parseArgs } from "node:util";
7
7
  // src/cli.ts
8
8
  /** Environment variable that supplies the client token when `--token` is absent. */
9
9
  const TOKEN_ENV = "SKAILE_TRANSFORM_PROXY_TOKEN";
10
- const USAGE = "usage: skaile-transform-proxy [--config <file>] [--port <n>] [--host <h>] [--token <t>]";
10
+ const USAGE = "usage: skaile-transform-proxy [--config <file>] [--port <n>] [--host <h>] [--token <t>] [--exit-with-stdin]";
11
11
  /** Parses the arguments, loads the config and starts the proxy. Never installs signal handlers. */
12
12
  async function runCli(argv, io) {
13
13
  let values;
@@ -23,7 +23,8 @@ async function runCli(argv, io) {
23
23
  help: {
24
24
  type: "boolean",
25
25
  short: "h"
26
- }
26
+ },
27
+ "exit-with-stdin": { type: "boolean" }
27
28
  }
28
29
  }));
29
30
  } catch (err) {
@@ -67,7 +68,8 @@ async function runCli(argv, io) {
67
68
  io.stdout(`listening ${proxy.url}`);
68
69
  return {
69
70
  code: 0,
70
- proxy
71
+ proxy,
72
+ exitWithStdin: values["exit-with-stdin"] === true
71
73
  };
72
74
  } catch (err) {
73
75
  io.stderr(errorMessage(err));
@@ -103,7 +105,10 @@ if (isEntryPoint()) {
103
105
  if (run.proxy === void 0) process.exitCode = run.code;
104
106
  else {
105
107
  const proxy = run.proxy;
108
+ let stopping = false;
106
109
  const stop = () => {
110
+ if (stopping) return;
111
+ stopping = true;
107
112
  proxy.close().then(() => process.exit(0), (err) => {
108
113
  console.error(errorMessage(err));
109
114
  process.exit(1);
@@ -111,6 +116,11 @@ if (isEntryPoint()) {
111
116
  };
112
117
  process.once("SIGINT", stop);
113
118
  process.once("SIGTERM", stop);
119
+ if (run.exitWithStdin === true) {
120
+ process.stdin.once("end", stop);
121
+ process.stdin.once("close", stop);
122
+ process.stdin.resume();
123
+ }
114
124
  }
115
125
  }
116
126
  export { TOKEN_ENV, runCli };
@@ -1,4 +1,4 @@
1
- import { a as TransformProxyOptions, i as TransformProxy } from "../server-C_eKyCTV.mjs";
1
+ import { Readable, Writable } from "node:stream";
2
2
  interface OmpModel {
3
3
  readonly provider: string;
4
4
  readonly id: string;
@@ -67,13 +67,34 @@ interface OmpExtensionApi extends OmpSessionActions {
67
67
  /** For `before_provider_request`, a non-undefined result replaces the request payload. */
68
68
  on(event: OmpEventName, handler: (event: unknown, ctx: OmpContext) => unknown): void;
69
69
  }
70
+ /** How the extension spawns its proxy child. */
71
+ interface ProxySpawnOptions {
72
+ readonly cwd: string;
73
+ readonly env: Readonly<Record<string, string | undefined>>;
74
+ readonly stdio: readonly ['pipe', 'pipe', 'pipe'];
75
+ }
76
+ /** The slice of a `node:child_process` `ChildProcess` the extension uses. */
77
+ interface ProxyChildProcess {
78
+ readonly pid?: number | undefined;
79
+ readonly stdin: Writable | null;
80
+ readonly stdout: Readable | null;
81
+ readonly stderr: Readable | null;
82
+ kill(signal?: NodeJS.Signals): boolean;
83
+ unref(): void;
84
+ on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): unknown;
85
+ on(event: 'error', listener: (err: Error) => void): unknown;
86
+ }
70
87
  interface AnonControllerDeps {
71
88
  readonly env: Readonly<Record<string, string | undefined>>;
72
89
  readonly home: string;
73
90
  /** Default: `$SKAILE_TRANSFORM_PROXY_OMP_STATE`, else `<omp agent dir>/skaile-transform-proxy.json`. */
74
91
  readonly statePath?: string;
75
- /** Default: `createTransformProxy`. */
76
- readonly startProxy?: (options: TransformProxyOptions) => Promise<TransformProxy>;
92
+ /** Spawns the proxy child. Default: `node:child_process` `spawn`. */
93
+ readonly spawnChild?: (command: string, args: readonly string[], options: ProxySpawnOptions) => ProxyChildProcess;
94
+ /** The CLI the child runs. Default: this package's `dist/cli.mjs`, next to the built extension's `dist/omp/`. */
95
+ readonly cliPath?: string;
96
+ /** How long the child may take to print `listening <url>`. Default: 60 s (transform modules may load ML models). */
97
+ readonly listenTimeoutMs?: number;
77
98
  }
78
99
  interface AnonController {
79
100
  readonly required: boolean;
@@ -112,4 +133,4 @@ export declare function defaultStatePath(env: Readonly<Record<string, string | u
112
133
  /** Registers the `/anon` command and the event handlers on one session's extension API. */
113
134
  export declare function registerAnonExtension(pi: OmpExtensionApi, controller: AnonController): void;
114
135
  export default function anonExtension(pi: OmpExtensionApi): void;
115
- export type { AnonController, AnonControllerDeps, OmpAutocompleteItem, OmpContext, OmpEventName, OmpExtensionApi, OmpModel, OmpModelRegistry, OmpNotifyType, OmpProviderOverride, OmpSessionActions, OmpUi };
136
+ export type { AnonController, AnonControllerDeps, OmpAutocompleteItem, OmpContext, OmpEventName, OmpExtensionApi, OmpModel, OmpModelRegistry, OmpNotifyType, OmpProviderOverride, OmpSessionActions, OmpUi, ProxyChildProcess, ProxySpawnOptions };
@@ -1,13 +1,17 @@
1
- import { c as SESSION_HEADER, d as createTransformProxy, i as loadProxyConfig, l as TOKEN_HEADER, n as configCandidates, r as findProxyConfig, u as UPSTREAM_HEADER, v as errorMessage, y as silentLogger } from "../config-PKHxejC8.mjs";
2
- import { randomUUID } from "node:crypto";
1
+ import { c as SESSION_HEADER, i as loadProxyConfig, l as TOKEN_HEADER, n as configCandidates, r as findProxyConfig, u as UPSTREAM_HEADER, v as errorMessage } from "../config-PKHxejC8.mjs";
2
+ import { randomBytes, randomUUID } from "node:crypto";
3
3
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
5
6
  import { homedir } from "node:os";
7
+ import { spawn } from "node:child_process";
6
8
  // src/omp/anon.ts
7
9
  /** A running proxy the extension routes to. */
8
10
  const URL_ENV = "SKAILE_TRANSFORM_PROXY_URL";
9
- /** The client token of that proxy. */
11
+ /** The client token of that proxy; also how the extension hands its own proxy child a random token. */
10
12
  const TOKEN_ENV = "SKAILE_TRANSFORM_PROXY_TOKEN";
13
+ /** The Node binary that runs the proxy child; default: `node` from `PATH`. */
14
+ const NODE_ENV = "SKAILE_TRANSFORM_PROXY_NODE";
11
15
  /** `required` (set by a skaile session in required mode): routing is forced on and `/anon off` is refused. */
12
16
  const MODE_ENV = "SKAILE_TRANSFORM_PROXY_MODE";
13
17
  /** Overrides the path of the persisted enabled flag. */
@@ -53,7 +57,8 @@ function createAnonController(deps) {
53
57
  const env = deps.env;
54
58
  const required = env[MODE_ENV] === "required";
55
59
  const statePath = deps.statePath ?? defaultStatePath(env, deps.home);
56
- const startProxy = deps.startProxy ?? createTransformProxy;
60
+ const spawnChild = deps.spawnChild ?? spawnNode;
61
+ const listenTimeoutMs = deps.listenTimeoutMs ?? 6e4;
57
62
  const registries = /* @__PURE__ */ new WeakMap();
58
63
  let wanted = required;
59
64
  let enabled = false;
@@ -72,7 +77,7 @@ function createAnonController(deps) {
72
77
  return state;
73
78
  }
74
79
  async function resolveEndpoint(ctx) {
75
- if (endpoint !== void 0) return endpoint;
80
+ if (endpoint !== void 0 && endpoint.child?.exited !== true) return endpoint;
76
81
  const url = env[URL_ENV];
77
82
  if (url !== void 0 && url !== "") {
78
83
  const token = env[TOKEN_ENV];
@@ -83,13 +88,17 @@ function createAnonController(deps) {
83
88
  };
84
89
  return endpoint;
85
90
  }
86
- starting ??= startInProcess(ctx.cwd).finally(() => {
91
+ starting ??= startChild(ctx.cwd).finally(() => {
87
92
  starting = void 0;
88
93
  });
89
94
  endpoint = await starting;
90
95
  return endpoint;
91
96
  }
92
- async function startInProcess(cwd) {
97
+ /**
98
+ * Runs the proxy CLI under the system Node: omp is a compiled Bun executable whose resolver
99
+ * cannot load transform modules with native or ML dependencies from `node_modules`.
100
+ */
101
+ async function startChild(cwd) {
93
102
  const path = findProxyConfig({
94
103
  cwd,
95
104
  home: deps.home
@@ -100,15 +109,45 @@ function createAnonController(deps) {
100
109
  }
101
110
  const options = loadProxyConfig(path);
102
111
  if (options.defaultPipeline === void 0) throw new Error(`${path} sets no defaultPipeline: the omp extension sends no pipeline header`);
103
- const proxy = await startProxy({
104
- ...options,
105
- log: silentLogger
112
+ const token = randomBytes(32).toString("base64url");
113
+ const node = env["SKAILE_TRANSFORM_PROXY_NODE"] || "node";
114
+ const cli = deps.cliPath ?? fileURLToPath(new URL("../cli.mjs", import.meta.url));
115
+ const child = spawnChild(node, [
116
+ cli,
117
+ "--config",
118
+ path,
119
+ "--port",
120
+ "0",
121
+ "--host",
122
+ "127.0.0.1",
123
+ "--exit-with-stdin"
124
+ ], {
125
+ cwd,
126
+ env: {
127
+ ...env,
128
+ [TOKEN_ENV]: token
129
+ },
130
+ stdio: [
131
+ "pipe",
132
+ "pipe",
133
+ "pipe"
134
+ ]
135
+ });
136
+ const state = { exited: false };
137
+ child.on("exit", () => {
138
+ state.exited = true;
139
+ if (endpoint?.child === state) endpoint = void 0;
106
140
  });
107
141
  return {
108
- url: proxy.url,
142
+ url: await waitForListening(child, {
143
+ node,
144
+ token,
145
+ timeoutMs: listenTimeoutMs
146
+ }),
147
+ token,
109
148
  pipeline: options.defaultPipeline,
110
- source: `in-process, config ${path}`,
111
- proxy
149
+ source: `child process ${child.pid}, config ${path}`,
150
+ child: state
112
151
  };
113
152
  }
114
153
  function currentSessionId(ctx) {
@@ -116,27 +155,13 @@ function createAnonController(deps) {
116
155
  return sessionId;
117
156
  }
118
157
  /**
119
- * Adopts the session id of a root session and returns the id it replaced, if any. The first
120
- * session of the process is the root; later `session_start`s are subagents (headless, `print`
121
- * mode) unless the session has a UI or runs in another mode.
158
+ * Adopts the session id of a root session. The first session of the process is the root;
159
+ * later `session_start`s are subagents (headless, `print` mode) unless the session has a UI
160
+ * or runs in another mode.
122
161
  */
123
162
  function enterSession(ctx, root) {
124
- const previous = sessionId;
125
- if (previous === void 0) {
126
- currentSessionId(ctx);
127
- return;
128
- }
129
- if (root) sessionId = readSessionId(ctx) ?? previous;
130
- return sessionId === previous ? void 0 : previous;
131
- }
132
- async function dropProxySession(ctx, id) {
133
- const proxy = endpoint?.proxy;
134
- if (proxy === void 0) return;
135
- try {
136
- await proxy.dropSession(id);
137
- } catch (err) {
138
- ctx.ui.notify(`anon: could not drop proxy session ${id}: ${errorMessage(err)}`, "warning");
139
- }
163
+ if (sessionId === void 0) currentSessionId(ctx);
164
+ else if (root) sessionId = readSessionId(ctx) ?? sessionId;
140
165
  }
141
166
  function route(ctx, target) {
142
167
  const registry = ctx.modelRegistry;
@@ -264,9 +289,13 @@ function createAnonController(deps) {
264
289
  if (preRouted.length > 0) lines.push(`routed by their own config (${preRouted.length}): ${preRouted.sort().join(", ")}`);
265
290
  return lines.join("\n");
266
291
  }
267
- /** Session entry: rotate the proxy session for a new root, then (re-)apply routing when wanted. */
292
+ /**
293
+ * Session entry: rotate the proxy session for a new root, then (re-)apply routing when wanted.
294
+ * Rotation only switches the session header: the proxy keeps the old session's state in memory
295
+ * until it exits, and no request carries that id again.
296
+ */
268
297
  async function start(ctx, session, root) {
269
- const previous = enterSession(ctx, root);
298
+ enterSession(ctx, root);
270
299
  if (!wanted && readEnabled(statePath)) wanted = true;
271
300
  if (wanted) {
272
301
  const failure = await activate(ctx, session);
@@ -275,7 +304,6 @@ function createAnonController(deps) {
275
304
  ctx.ui.notify(refusalHint(), "error");
276
305
  }
277
306
  }
278
- if (previous !== void 0) await dropProxySession(ctx, previous);
279
307
  showStatus(ctx);
280
308
  }
281
309
  return {
@@ -370,6 +398,101 @@ function readEnabled(path) {
370
398
  return false;
371
399
  }
372
400
  }
401
+ function spawnNode(command, args, options) {
402
+ return spawn(command, [...args], {
403
+ cwd: options.cwd,
404
+ env: options.env,
405
+ stdio: [...options.stdio]
406
+ });
407
+ }
408
+ /** The stderr lines a startup failure quotes. */
409
+ const STDERR_TAIL = 10;
410
+ /**
411
+ * Resolves with the URL of the child's `listening <url>` line. A child that exits first, fails
412
+ * to spawn or stays silent past `timeoutMs` (it is then killed) rejects, quoting its last stderr
413
+ * lines with the token redacted. omp exiting kills the child; once listening, the child and its
414
+ * pipes no longer hold omp's event loop, and stdin stays open so the child sees omp go away.
415
+ */
416
+ function waitForListening(child, how) {
417
+ const killOnExit = () => {
418
+ child.kill("SIGTERM");
419
+ };
420
+ process.on("exit", killOnExit);
421
+ const forgetExitHook = () => {
422
+ process.off("exit", killOnExit);
423
+ };
424
+ child.on("exit", forgetExitHook);
425
+ for (const stream of [
426
+ child.stdin,
427
+ child.stdout,
428
+ child.stderr
429
+ ]) stream?.on("error", () => {});
430
+ const listening = Promise.withResolvers();
431
+ const label = `the transform proxy child process (${how.node}, pid ${child.pid})`;
432
+ const tail = [];
433
+ let stderrPartial = "";
434
+ let stdout = "";
435
+ let settled = false;
436
+ function stderrTail() {
437
+ const lines = [...tail, stderrPartial].filter((line) => line.trim() !== "").slice(-10);
438
+ return lines.length === 0 ? "(none)" : lines.map((line) => line.split(how.token).join("[token]")).join("\n");
439
+ }
440
+ function fail(message) {
441
+ if (settled) return;
442
+ settled = true;
443
+ clearTimeout(timer);
444
+ listening.reject(new Error(message));
445
+ }
446
+ const timer = setTimeout(() => {
447
+ fail(`${label} did not print "listening" within ${duration(how.timeoutMs)} and was killed; last stderr lines:\n${stderrTail()}`);
448
+ child.kill("SIGKILL");
449
+ }, how.timeoutMs);
450
+ child.stderr?.on("data", (chunk) => {
451
+ if (settled) return;
452
+ const lines = (stderrPartial + String(chunk)).split("\n");
453
+ stderrPartial = lines.pop() ?? "";
454
+ tail.push(...lines.map((line) => line.replace(/\r$/, "")));
455
+ tail.splice(0, Math.max(0, tail.length - STDERR_TAIL));
456
+ });
457
+ child.stdout?.on("data", (chunk) => {
458
+ if (settled) return;
459
+ const lines = (stdout + String(chunk)).split("\n");
460
+ stdout = lines.pop() ?? "";
461
+ for (const line of lines) {
462
+ const match = /^listening (\S+)$/.exec(line.trim());
463
+ if (match === null) continue;
464
+ settled = true;
465
+ clearTimeout(timer);
466
+ stdout = "";
467
+ child.unref();
468
+ for (const stream of [
469
+ child.stdin,
470
+ child.stdout,
471
+ child.stderr
472
+ ]) stream?.unref?.();
473
+ listening.resolve(match[1]);
474
+ return;
475
+ }
476
+ });
477
+ child.on("exit", (code, signal) => {
478
+ if (settled) return;
479
+ const report = () => fail(`${label} exited with ${code === null ? `signal ${signal}` : `code ${code}`} before it was listening; last stderr lines:\n${stderrTail()}`);
480
+ const stderr = child.stderr;
481
+ if (stderr === null || stderr.readableEnded || stderr.destroyed) report();
482
+ else {
483
+ stderr.once("end", report);
484
+ stderr.once("close", report);
485
+ }
486
+ });
487
+ child.on("error", (err) => {
488
+ forgetExitHook();
489
+ fail(`could not start the transform proxy with "${how.node}": ${err.message}; it runs under Node >= 22: put node on PATH or set ${NODE_ENV}`);
490
+ });
491
+ return listening.promise;
492
+ }
493
+ function duration(ms) {
494
+ return ms % 1e3 === 0 ? `${ms / 1e3} s` : `${ms} ms`;
495
+ }
373
496
  /** Every provider of the registry with the wire APIs of its models. */
374
497
  function providerApis(registry) {
375
498
  const out = /* @__PURE__ */ new Map();
@@ -416,7 +539,7 @@ function originOf(url) {
416
539
  }
417
540
  }
418
541
  // src/omp/index.ts
419
- /** omp re-imports the extension per session; the controller (proxy, recorded originals) is process-wide. */
542
+ /** omp re-imports the extension per session; the controller (proxy child, recorded originals) is process-wide. */
420
543
  const CONTROLLER_KEY = Symbol.for("@skaile/transform-proxy/omp");
421
544
  /** Registers the `/anon` command and the event handlers on one session's extension API. */
422
545
  function registerAnonExtension(pi, controller) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skaile/transform-proxy",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "Same-protocol passthrough proxy that runs model requests and replies through a chain of text transforms (Anthropic Messages, OpenAI chat, OpenAI responses)",
6
6
  "license": "MIT",