@skaile/transform-proxy 0.2.5 → 0.2.6
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 +4 -0
- package/README.md +2 -1
- package/dist/omp/index.d.mts +17 -1
- package/dist/omp/index.mjs +54 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.6
|
|
4
|
+
|
|
5
|
+
- omp extension: while anon is on, in error or required, images are not sent. The extension sets omp's `images.blockImages` as a runtime override (never persisted), so omp replaces every image in the request, history included, with `Image reading is disabled.`; `/anon off` drops the override. Before, a screenshot from a browser tool made the proxy refuse every later request of the session with 400 `unsupported_content` ("Anthropic image content cannot be transformed"). `/anon status` lists `images: not sent`. An omp without the settings registry gets one warning, and the proxy keeps refusing images.
|
|
6
|
+
|
|
3
7
|
## 0.2.5
|
|
4
8
|
|
|
5
9
|
- omp extension: the status is `🟢A` (on), `🔴A` (off), `🟠A` (error) instead of `A`, `Ⱥ`, `A!`. The crossed A was not legible in common terminal fonts, and omp strips ANSI colour from extension statuses, so the colour comes from an emoji.
|
package/README.md
CHANGED
|
@@ -112,9 +112,10 @@ statusLine:
|
|
|
112
112
|
- 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.
|
|
113
113
|
- 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 status shows `🟠A`.
|
|
114
114
|
- 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.
|
|
115
|
+
- While anon is on or in error, images are not sent: the extension sets omp's `images.blockImages` in omp's in-memory runtime settings layer, and omp replaces every image in the request, history included, with the note `Image reading is disabled.`. The proxy cannot anonymize images and refuses every request that carries one (400 `unsupported_content`), and omp resends the whole history each turn, so a single screenshot would otherwise block the session. `/anon off` drops the override, so your own `images.blockImages` setting applies again; the override is never written to `config.yml`. An omp without this settings API gets a warning instead, and the proxy keeps refusing images.
|
|
115
116
|
- 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.
|
|
116
117
|
- `/anon off` restores the original base URLs and headers.
|
|
117
|
-
- `/anon status` shows the state, the proxy URL and its source, the pipeline, the session id, and the routed and refused providers.
|
|
118
|
+
- `/anon status` shows the state, the proxy URL and its source, the pipeline, the session id, whether images are blocked, and the routed and refused providers.
|
|
118
119
|
- 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.
|
|
119
120
|
- `SKAILE_TRANSFORM_PROXY_MODE=required` (set by a skaile session in required mode) turns routing on at session start and refuses `/anon off`.
|
|
120
121
|
|
package/dist/omp/index.d.mts
CHANGED
|
@@ -59,6 +59,10 @@ interface OmpSessionActions {
|
|
|
59
59
|
setModel(model: OmpModel): Promise<boolean>;
|
|
60
60
|
}
|
|
61
61
|
interface OmpExtensionApi extends OmpSessionActions {
|
|
62
|
+
/** omp's package exports; `settings` is the scope its setting handles read and override. */
|
|
63
|
+
readonly pi?: {
|
|
64
|
+
readonly settings?: unknown;
|
|
65
|
+
};
|
|
62
66
|
registerCommand(name: string, options: {
|
|
63
67
|
description?: string;
|
|
64
68
|
getArgumentCompletions?: (argumentPrefix: string) => OmpAutocompleteItem[] | null;
|
|
@@ -84,6 +88,14 @@ interface ProxyChildProcess {
|
|
|
84
88
|
on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): unknown;
|
|
85
89
|
on(event: 'error', listener: (err: Error) => void): unknown;
|
|
86
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Image sending of the host. The proxy cannot anonymize images and refuses every request that
|
|
93
|
+
* carries one; omp resends the whole history each turn, so one screenshot would block the session.
|
|
94
|
+
*/
|
|
95
|
+
interface ImageSending {
|
|
96
|
+
/** `true` stops images from reaching the provider, `false` restores the user's setting. Resolves `false` when the host offers no way to do it; that answer is final. */
|
|
97
|
+
setBlocked(blocked: boolean): Promise<boolean>;
|
|
98
|
+
}
|
|
87
99
|
interface AnonControllerDeps {
|
|
88
100
|
readonly env: Readonly<Record<string, string | undefined>>;
|
|
89
101
|
readonly home: string;
|
|
@@ -95,6 +107,8 @@ interface AnonControllerDeps {
|
|
|
95
107
|
readonly cliPath?: string;
|
|
96
108
|
/** How long the child may take to print `listening <url>`. Default: 60 s (transform modules may load ML models). */
|
|
97
109
|
readonly listenTimeoutMs?: number;
|
|
110
|
+
/** Blocked while anon is wanted (on, error or required), released by `/anon off`. Default: none. */
|
|
111
|
+
readonly images?: ImageSending;
|
|
98
112
|
}
|
|
99
113
|
interface AnonController {
|
|
100
114
|
readonly required: boolean;
|
|
@@ -133,4 +147,6 @@ export declare function defaultStatePath(env: Readonly<Record<string, string | u
|
|
|
133
147
|
/** Registers the `/anon` command and the event handlers on one session's extension API. */
|
|
134
148
|
export declare function registerAnonExtension(pi: OmpExtensionApi, controller: AnonController): void;
|
|
135
149
|
export default function anonExtension(pi: OmpExtensionApi): void;
|
|
136
|
-
|
|
150
|
+
/** Blocks images through a runtime override of omp's `images.blockImages`, which strips them from every request, history included. */
|
|
151
|
+
export declare function ompImageSending(pi: OmpExtensionApi, load?: () => Promise<unknown>): ImageSending;
|
|
152
|
+
export type { AnonController, AnonControllerDeps, ImageSending, OmpAutocompleteItem, OmpContext, OmpEventName, OmpExtensionApi, OmpModel, OmpModelRegistry, OmpNotifyType, OmpProviderOverride, OmpSessionActions, OmpUi, ProxyChildProcess, ProxySpawnOptions };
|
package/dist/omp/index.mjs
CHANGED
|
@@ -62,6 +62,10 @@ function createAnonController(deps) {
|
|
|
62
62
|
const registries = /* @__PURE__ */ new WeakMap();
|
|
63
63
|
let wanted = required;
|
|
64
64
|
let enabled = false;
|
|
65
|
+
/** Whether this controller holds the image block; only then does it release it. */
|
|
66
|
+
let imagesBlocked = false;
|
|
67
|
+
/** The host answered that it cannot block images; asked once, warned once. */
|
|
68
|
+
let imagesUnsupported = false;
|
|
65
69
|
let endpoint;
|
|
66
70
|
let starting;
|
|
67
71
|
let sessionId;
|
|
@@ -265,6 +269,24 @@ function createAnonController(deps) {
|
|
|
265
269
|
function stateLabel() {
|
|
266
270
|
return enabled ? "on" : wanted ? "error" : "off";
|
|
267
271
|
}
|
|
272
|
+
/** Follows `wanted`: images are blocked while model requests must go through the proxy. */
|
|
273
|
+
async function syncImages(ctx) {
|
|
274
|
+
const images = deps.images;
|
|
275
|
+
if (images === void 0 || imagesUnsupported || imagesBlocked === wanted) return;
|
|
276
|
+
let done;
|
|
277
|
+
try {
|
|
278
|
+
done = await images.setBlocked(wanted);
|
|
279
|
+
} catch (err) {
|
|
280
|
+
ctx.ui.notify(`anon: could not ${wanted ? "stop" : "restore"} image sending: ${errorMessage(err)}`, "warning");
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (done) {
|
|
284
|
+
imagesBlocked = wanted;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
imagesUnsupported = true;
|
|
288
|
+
if (wanted) ctx.ui.notify("anon: this omp cannot stop image sending; the proxy refuses every request that carries an image", "warning");
|
|
289
|
+
}
|
|
268
290
|
/**
|
|
269
291
|
* Compact status for omp's main status line. omp strips ANSI colour from extension statuses and
|
|
270
292
|
* paints them in its accent colour, so the colour comes from an emoji: green on, red off, orange error.
|
|
@@ -282,6 +304,7 @@ function createAnonController(deps) {
|
|
|
282
304
|
lines.push(`pipeline: ${endpoint.pipeline ?? "the proxy default"}`);
|
|
283
305
|
}
|
|
284
306
|
if (sessionId !== void 0) lines.push(`session: ${sessionId}`);
|
|
307
|
+
if (imagesBlocked) lines.push("images: not sent (omp images.blockImages)");
|
|
285
308
|
const routed = [...state.routed.keys()].sort();
|
|
286
309
|
const refused = routed.flatMap((provider) => {
|
|
287
310
|
const reason = refusalReason(apis.get(provider), state.originals.get(provider));
|
|
@@ -308,6 +331,7 @@ function createAnonController(deps) {
|
|
|
308
331
|
ctx.ui.notify(refusalHint(), "error");
|
|
309
332
|
}
|
|
310
333
|
}
|
|
334
|
+
await syncImages(ctx);
|
|
311
335
|
showStatus(ctx);
|
|
312
336
|
}
|
|
313
337
|
return {
|
|
@@ -350,6 +374,7 @@ function createAnonController(deps) {
|
|
|
350
374
|
break;
|
|
351
375
|
default: ctx.ui.notify(USAGE, "error");
|
|
352
376
|
}
|
|
377
|
+
await syncImages(ctx);
|
|
353
378
|
showStatus(ctx);
|
|
354
379
|
},
|
|
355
380
|
completions(prefix) {
|
|
@@ -545,6 +570,7 @@ function originOf(url) {
|
|
|
545
570
|
// src/omp/index.ts
|
|
546
571
|
/** omp re-imports the extension per session; the controller (proxy child, recorded originals) is process-wide. */
|
|
547
572
|
const CONTROLLER_KEY = Symbol.for("@skaile/transform-proxy/omp");
|
|
573
|
+
const BLOCK_IMAGES = "images.blockImages";
|
|
548
574
|
/** Registers the `/anon` command and the event handlers on one session's extension API. */
|
|
549
575
|
function registerAnonExtension(pi, controller) {
|
|
550
576
|
pi.registerCommand("anon", {
|
|
@@ -562,9 +588,35 @@ function anonExtension(pi) {
|
|
|
562
588
|
const scope = globalThis;
|
|
563
589
|
registerAnonExtension(pi, scope[CONTROLLER_KEY] ??= createAnonController({
|
|
564
590
|
env: process.env,
|
|
565
|
-
home: homedir()
|
|
591
|
+
home: homedir(),
|
|
592
|
+
images: ompImageSending(pi)
|
|
566
593
|
}));
|
|
567
594
|
}
|
|
595
|
+
/** Blocks images through a runtime override of omp's `images.blockImages`, which strips them from every request, history included. */
|
|
596
|
+
function ompImageSending(pi, load = loadOmpSettingsRegistry) {
|
|
597
|
+
let handle;
|
|
598
|
+
return { async setBlocked(blocked) {
|
|
599
|
+
const settings = pi.pi?.settings;
|
|
600
|
+
if (settings === void 0) return false;
|
|
601
|
+
handle ??= load().then(blockImagesHandle, () => void 0);
|
|
602
|
+
const resolved = await handle;
|
|
603
|
+
if (resolved === void 0) return false;
|
|
604
|
+
if (blocked) resolved.override(settings, true);
|
|
605
|
+
else resolved.clearOverride(settings);
|
|
606
|
+
return true;
|
|
607
|
+
} };
|
|
608
|
+
}
|
|
609
|
+
function loadOmpSettingsRegistry() {
|
|
610
|
+
return import("@oh-my-pi/pi-coding-agent/config/registry");
|
|
611
|
+
}
|
|
612
|
+
function blockImagesHandle(registry) {
|
|
613
|
+
if (typeof registry !== "object" || registry === null || !("lookup" in registry) || typeof registry.lookup !== "function") return void 0;
|
|
614
|
+
const handle = registry.lookup(BLOCK_IMAGES);
|
|
615
|
+
if (typeof handle !== "object" || handle === null) return void 0;
|
|
616
|
+
if (!("override" in handle) || typeof handle.override !== "function") return void 0;
|
|
617
|
+
if (!("clearOverride" in handle) || typeof handle.clearOverride !== "function") return void 0;
|
|
618
|
+
return handle;
|
|
619
|
+
}
|
|
568
620
|
function on(pi, event, run) {
|
|
569
621
|
pi.on(event, (_event, ctx) => guarded(ctx, () => run(ctx)));
|
|
570
622
|
}
|
|
@@ -575,4 +627,4 @@ async function guarded(ctx, run) {
|
|
|
575
627
|
ctx.ui.notify(`anon: ${errorMessage(err)}`, "error");
|
|
576
628
|
}
|
|
577
629
|
}
|
|
578
|
-
export { createAnonController, anonExtension as default, defaultStatePath, registerAnonExtension };
|
|
630
|
+
export { createAnonController, anonExtension as default, defaultStatePath, ompImageSending, registerAnonExtension };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skaile/transform-proxy",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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",
|