@skaile/transform-proxy 0.4.0 → 0.5.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.
- package/CHANGELOG.md +21 -0
- package/README.md +74 -5
- package/dist/cli.d.mts +8 -1
- package/dist/cli.mjs +41 -28
- package/dist/index.d.mts +34 -10
- package/dist/index.mjs +1 -1
- package/dist/omp/index.mjs +81 -8
- package/dist/{config-Ceb5AF_a.mjs → server-BR1dDA8S.mjs} +580 -117
- package/dist/{server-CicvlQ7q.d.mts → server-gwJGHF82.d.mts} +57 -2
- package/package.json +9 -8
|
@@ -27,6 +27,14 @@ interface Transform {
|
|
|
27
27
|
dispose?(): void | Promise<void>;
|
|
28
28
|
/** Host-only state of this instance (e.g. the anon mapping), read through TransformProxy.inspect. Never called by the walkers, never sent anywhere. */
|
|
29
29
|
inspect?(): unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Originals this instance has already replaced in this session (forge-anon: its mapping), each with its kind.
|
|
32
|
+
* Used only by the proxy's leak check, which reports kind and JSON path, never the value; never sent anywhere.
|
|
33
|
+
*/
|
|
34
|
+
knownOriginals?(): Iterable<{
|
|
35
|
+
readonly kind: string;
|
|
36
|
+
readonly value: string;
|
|
37
|
+
}>;
|
|
30
38
|
}
|
|
31
39
|
interface SessionFact {
|
|
32
40
|
readonly kind: string;
|
|
@@ -58,6 +66,51 @@ interface TransformModule {
|
|
|
58
66
|
readonly log: Logger;
|
|
59
67
|
}): Promise<TransformFactory>;
|
|
60
68
|
}
|
|
69
|
+
/** One leak-check finding. Never carries the value itself. */
|
|
70
|
+
interface TraceLeak {
|
|
71
|
+
/** Fact/original kind, e.g. 'person'. */
|
|
72
|
+
readonly kind: string;
|
|
73
|
+
/** Fact source (publisher id), or 'pipeline' for `Transform.knownOriginals`. */
|
|
74
|
+
readonly source: string;
|
|
75
|
+
/** JSON path in the rewritten request body, e.g. 'tools[0].description'. */
|
|
76
|
+
readonly at: string;
|
|
77
|
+
}
|
|
78
|
+
/** One line of the anon trace: what left for the provider (request) or what it answered before restore (response/error). */
|
|
79
|
+
interface TraceEvent {
|
|
80
|
+
/** ISO timestamp. */
|
|
81
|
+
readonly at: string;
|
|
82
|
+
/** Per proxied request; links its request/response/error lines. */
|
|
83
|
+
readonly requestId: string;
|
|
84
|
+
readonly sessionId: string;
|
|
85
|
+
readonly pipeline: string;
|
|
86
|
+
/** `WireRoute.name`, e.g. 'anthropic.messages'. */
|
|
87
|
+
readonly route: string;
|
|
88
|
+
/** Forward target origin + path, no query string. */
|
|
89
|
+
readonly upstream: string;
|
|
90
|
+
/** Request body `model` when a string. */
|
|
91
|
+
readonly model?: string;
|
|
92
|
+
readonly phase: 'request' | 'response' | 'error';
|
|
93
|
+
/** response/error: HTTP status (502 when the upstream was unreachable). */
|
|
94
|
+
readonly status?: number;
|
|
95
|
+
/** response/error: ms since the request event. */
|
|
96
|
+
readonly durationMs?: number;
|
|
97
|
+
/**
|
|
98
|
+
* request: the delta, keyed by JSON path (`{ 'messages[4]': {...}, system: [...] }`), only entries not yet traced in
|
|
99
|
+
* this session; `{}` when nothing is new.
|
|
100
|
+
* response: the model reply before restore (streamed: assembled in the protocol's non-streamed shape; `undefined` when
|
|
101
|
+
* the stream ended before a complete reply).
|
|
102
|
+
* error: the upstream error body as text, cut to 4096 chars, or the fetch error message.
|
|
103
|
+
*/
|
|
104
|
+
readonly content?: unknown;
|
|
105
|
+
/** Set only by `serializeTraceEvent`. */
|
|
106
|
+
readonly truncated?: boolean;
|
|
107
|
+
/** request: leak-check findings; response/error: []. */
|
|
108
|
+
readonly leaks: readonly TraceLeak[];
|
|
109
|
+
}
|
|
110
|
+
/** Synchronous. The proxy catches a throw, logs it, and never lets it reach the client. */
|
|
111
|
+
interface TraceSink {
|
|
112
|
+
record(event: TraceEvent): void;
|
|
113
|
+
}
|
|
61
114
|
/** A configured transform: a module (object, npm specifier or relative path) and its config. */
|
|
62
115
|
interface TransformSpec {
|
|
63
116
|
readonly module: string | TransformModule;
|
|
@@ -79,6 +132,8 @@ interface TransformProxyOptions {
|
|
|
79
132
|
/** Origins. Absent = any https origin plus loopback http. */
|
|
80
133
|
allowUpstreams?: readonly string[];
|
|
81
134
|
log?: Logger;
|
|
135
|
+
/** Records what goes upstream after the pipeline and what comes back before restore. Absent = no trace. */
|
|
136
|
+
trace?: TraceSink;
|
|
82
137
|
}
|
|
83
138
|
interface TransformProxy {
|
|
84
139
|
readonly url: string;
|
|
@@ -91,7 +146,7 @@ interface TransformProxy {
|
|
|
91
146
|
/**
|
|
92
147
|
* Host-only, in-process: each stage's `inspect()` result of the session's pipeline instance, keyed by transform id.
|
|
93
148
|
* `{}` when the session or pipeline is unknown, the instance is not built, or its build failed.
|
|
94
|
-
* Never builds an instance or creates session state; there is no HTTP route for it.
|
|
149
|
+
* Never builds an instance or creates session state; there is no HTTP route for it. Rejects when a stage's `inspect()` throws.
|
|
95
150
|
*/
|
|
96
151
|
inspect(sessionId: string, pipelineId?: string): Promise<Record<string, unknown>>;
|
|
97
152
|
close(): Promise<void>;
|
|
@@ -101,4 +156,4 @@ declare const SESSION_HEADER = "x-skaile-transform-session";
|
|
|
101
156
|
declare const PIPELINE_HEADER = "x-skaile-transform-pipeline";
|
|
102
157
|
declare const TOKEN_HEADER = "x-skaile-transform-token";
|
|
103
158
|
declare function createTransformProxy(options: TransformProxyOptions): Promise<TransformProxy>;
|
|
104
|
-
export {
|
|
159
|
+
export { TraceSink as _, TransformProxyOptions as a, TransformModule as b, TransformSpec as c, SessionFactPublisher as d, SessionFacts as f, TraceLeak as g, TraceEvent as h, TransformProxy as i, Logger as l, TextLeafKind as m, SESSION_HEADER as n, UPSTREAM_HEADER as o, TextLeaf as p, TOKEN_HEADER as r, createTransformProxy as s, PIPELINE_HEADER as t, SessionFact as u, Transform as v, TransformSessionContext as x, TransformFactory as y };
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skaile/transform-proxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/skaile-ai/
|
|
9
|
+
"url": "git+https://github.com/skaile-ai/forge.git",
|
|
10
|
+
"directory": "packages/transform-proxy"
|
|
10
11
|
},
|
|
11
|
-
"homepage": "https://github.com/skaile-ai/
|
|
12
|
+
"homepage": "https://github.com/skaile-ai/forge/tree/main/packages/transform-proxy#readme",
|
|
12
13
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/skaile-ai/
|
|
14
|
+
"url": "https://github.com/skaile-ai/forge/issues"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
16
17
|
"llm",
|
|
@@ -54,9 +55,10 @@
|
|
|
54
55
|
"scripts": {
|
|
55
56
|
"prebuild": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
56
57
|
"build": "tsdown",
|
|
57
|
-
"
|
|
58
|
-
"test": "bun
|
|
59
|
-
"typecheck": "tsc --noEmit"
|
|
58
|
+
"prepublishOnly": "npm run build",
|
|
59
|
+
"test": "bun --bun vitest run",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"check": "bun ../../scripts/check-package.ts"
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
64
|
"yaml": "^2.9.0"
|
|
@@ -64,7 +66,6 @@
|
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"@types/bun": "^1.3.0",
|
|
66
68
|
"@types/node": "^22.0.0",
|
|
67
|
-
"tsdown": "^0.23.1",
|
|
68
69
|
"typescript": "^5.9.3"
|
|
69
70
|
}
|
|
70
71
|
}
|