@agentvault/openai-bridge 0.1.22 → 0.1.23

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.
@@ -0,0 +1,100 @@
1
+ /** X-4: the raw base64 string is refused above this many characters, before anything else. */
2
+ export declare const MAX_BASE64_RAW_CHARS: number;
3
+ /** X-4: `ceil(5,242,864 / 3) × 4` — the longest canonical base64 of a file that fits. */
4
+ export declare const MAX_BASE64_STRIPPED_CHARS: number;
5
+ /** §2.3: a filename is at most this many UTF-8 bytes. */
6
+ export declare const MAX_FILENAME_BYTES = 200;
7
+ /** A caption is ordinary text; bounded so a tool call cannot carry a huge one. */
8
+ export declare const MAX_CAPTION_BYTES = 4096;
9
+ /** X-5: kept files per destination folder: the last 50, or 100 MB, whichever is smaller. */
10
+ export declare const KEEP_FILES = 50;
11
+ export declare const KEEP_BYTES: number;
12
+ /**
13
+ * Review #1788 item 5: strict base64 by one linear pass, no regex (a backtracking regex over a
14
+ * multi-MB string overflowed V8's regex stack above ~3.2 MiB). Length a multiple of 4; only
15
+ * A-Z a-z 0-9 + / ; "=" only as the last one or two characters.
16
+ */
17
+ export declare function strictBase64(s: string): boolean;
18
+ export type ContentTarget = {
19
+ kind: "owner";
20
+ conversationId?: string;
21
+ } | {
22
+ kind: "room";
23
+ roomId: string;
24
+ };
25
+ export type Validated = {
26
+ ok: true;
27
+ filename: string;
28
+ bytes: Buffer;
29
+ caption: string;
30
+ } | {
31
+ ok: false;
32
+ reason: string;
33
+ };
34
+ /** Test seam: count decodes, so "refused before decode" is measured, not assumed. */
35
+ export declare const decodeSpy: {
36
+ base64: number;
37
+ };
38
+ /**
39
+ * §2.3 / X-4 — validate the model's arguments. Order matters: the cheap size
40
+ * checks run before any decode, and the name before any content work.
41
+ */
42
+ export declare function validateSendFileArgs(args: unknown): Validated;
43
+ /** What `ContentStager.stage` returns. */
44
+ export type Staged = {
45
+ ok: true;
46
+ path: string;
47
+ dir: string;
48
+ root: string;
49
+ size: number;
50
+ } | {
51
+ ok: false;
52
+ reason: string;
53
+ };
54
+ export interface ContentStagerOptions {
55
+ /**
56
+ * The absolute staging folder for a target, or null. Production: the
57
+ * channel's `stagingPathFor` (a `~/`-relative path for this bridge) expanded
58
+ * against the home folder the policy itself uses (`os.homedir()`).
59
+ */
60
+ rootFor(target: ContentTarget): string | null;
61
+ log?: (line: string) => void;
62
+ /** Test seam: the per-folder caps (defaults KEEP_FILES / KEEP_BYTES). */
63
+ keepFiles?: number;
64
+ keepBytes?: number;
65
+ /** Test seam: runs after the per-call folder is made, before the file is opened (a planted leaf). */
66
+ afterMkdir?: (dir: string, path: string) => void;
67
+ }
68
+ /** Production `rootFor`: SecureChannel's staging path for the target, `~/` expanded. */
69
+ export declare function channelRootFor(channel: {
70
+ stagingPathFor?(t: ContentTarget): string | null;
71
+ }): (t: ContentTarget) => string | null;
72
+ /**
73
+ * X-5 — writes each file at `<root>/<uuid>/<filename>` (so the receiver sees
74
+ * the clean name), keeps sent files (an owner-visible record) capped per
75
+ * folder, and removes a file whose send failed.
76
+ */
77
+ export declare class ContentStager {
78
+ private readonly opts;
79
+ constructor(opts: ContentStagerOptions);
80
+ stage(target: ContentTarget, filename: string, bytes: Buffer): Promise<Staged>;
81
+ /** The send failed: remove what this call wrote (the file, then its own uuid folder). Never follows a link. */
82
+ discard(staged: Staged): void;
83
+ /**
84
+ * X-5 — after a successful send: if the folder holds more than 50 kept
85
+ * files or 100 MB, the oldest move to `<outbox>/left/kept-<uuid>` (outside
86
+ * every root), and this bridge's own `kept-*` entries there are trimmed to
87
+ * the newest three. Only uuid folders holding one regular file are counted
88
+ * or moved; nothing is followed or recursed into.
89
+ */
90
+ enforceCap(target: ContentTarget): void;
91
+ /** The target's folder, only if it is a real directory we own (realpath, lstat, uid, 0700). */
92
+ private safeRoot;
93
+ private realDir;
94
+ /** A uuid folder holding exactly one regular file: its size and age. Anything else: null. */
95
+ private keptEntry;
96
+ /** Keep this bridge's newest three `kept-*` entries in left/; remove older ones without following links. */
97
+ private trimLeft;
98
+ private log;
99
+ }
100
+ //# sourceMappingURL=content-send.d.ts.map
package/dist/driver.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type TurnFailureCode } from "@agentvault/agentvault";
2
- export declare const SUPPORTED_CODEX_VERSION = "0.154.0";
2
+ export { SUPPORTED_CODEX_VERSION } from "./codex-version.js";
3
3
  export declare const CODE_MODE_WARNING = "Code Mode is unavailable because code-mode host is disabled. Code mode will fail closed; enable `features.code_mode_host` and install `codex-code-mode-host`.";
4
4
  /** #1560 — observed on 0.154.0 as an `item.completed` error item when the
5
5
  * model name has no local metadata. Codex carries on and answers, so it is a
@@ -16,7 +16,91 @@ export interface Layout {
16
16
  export declare function createLayout(root: string): Promise<Layout>;
17
17
  export declare function atomicPrivateWrite(path: string, value: string): Promise<void>;
18
18
  export declare function childEnvironment(layout: Layout): NodeJS.ProcessEnv;
19
- export declare function buildInvocation(layout: Layout, sessionId?: string): {
19
+ /**
20
+ * The features this bridge ALWAYS disables (the boundary measured on
21
+ * 0.154.0). X-3: each must appear in `codex features list`; a missing one
22
+ * means Codex renamed it, so the bridge refuses to run (`ai_tool_unsupported`).
23
+ */
24
+ export declare const HARD_DENY_FEATURES: readonly string[];
25
+ /**
26
+ * X-3: the default-on features left ON, each with its reviewed reason.
27
+ * Every other feature that is on gets `--disable`d.
28
+ */
29
+ export declare const FEATURE_ALLOWLIST: Readonly<Record<string, string>>;
30
+ /**
31
+ * X-3: parse `codex features list` (`<name> <stage words> <true|false>` per
32
+ * line). Throws on anything it cannot read, so the caller fails closed.
33
+ */
34
+ export declare function parseFeatureList(text: string): Map<string, boolean>;
35
+ /**
36
+ * X-3 default-deny: the hard list, plus every feature that is ON and not on
37
+ * the reviewed allowlist. Throws when a hard-deny name is missing (a rename).
38
+ */
39
+ export declare function featureDisableList(features: Map<string, boolean>): string[];
40
+ /** X-3: run `codex features list`; fail closed (`ai_tool_unsupported`) on anything it cannot read. */
41
+ export declare function listDisabledFeatures(binary: string, layout: Layout, timeoutMs?: number): Promise<string[]>;
42
+ /**
43
+ * #1762 PR-X — the model's TOOL CATALOG, pinned by this bridge.
44
+ *
45
+ * Measured on 0.162.1 (and 0.154.0): Codex's bundled catalog gives
46
+ * gpt-5.6-terra `tool_mode: "code_mode_only"`, `multi_agent_version: "v2"` and
47
+ * `supports_search_tool: true`. With that, the model sees only `exec` (Code
48
+ * Mode, whose host this bridge disables, so it fails closed), `wait`,
49
+ * `request_user_input` and the multi-agent `collaboration` tools — and NO MCP
50
+ * tool at all (MCP tools would be nested inside `exec`, or deferred behind
51
+ * tool search). So `send_file` could never be called by the real model.
52
+ *
53
+ * The bridge therefore runs with its OWN one-model catalog, built from the
54
+ * binary's BUNDLED entry for CODEX_MODEL (`codex debug models --bundled`:
55
+ * without `--bundled` Codex refreshes the list from the provider when logged
56
+ * in, so the entry could change under us). The entry is ALLOWLISTED key by
57
+ * key (review #1788 item 2):
58
+ * - CATALOG_COPY: non-tool keys copied after a type check;
59
+ * - CATALOG_PIN: every tool-shaping key, forced to a fixed value whatever the
60
+ * bundled entry says (direct tools, no tool search, no multi-agent, no
61
+ * apply_patch, no shell, no node REPL, no experimental tools, no parallel
62
+ * calls, no usage-instruction blocks, no upgrade nudge);
63
+ * - any OTHER key in the bundled entry → `ai_tool_unsupported` (a new key is
64
+ * a new behaviour nobody has measured).
65
+ * Measured with this catalog (live gate): the model's tools are EXACTLY the
66
+ * three MCP resource tools (the shim answers them "method not found"),
67
+ * `request_user_input` and `mcp__avroom.send_file`.
68
+ */
69
+ type Check = (v: unknown) => boolean;
70
+ /** Non-tool keys: copied verbatim after a type check. */
71
+ export declare const CATALOG_COPY: Readonly<Record<string, Check>>;
72
+ /** Every tool-shaping key, forced to this value (present in the entry or not). */
73
+ export declare const CATALOG_PIN: Readonly<Record<string, unknown>>;
74
+ /** The bridge's entry from the bundled one: allowlisted, pinned, or refused. Throws on anything else. */
75
+ export declare function pinnedCatalogEntry(bundled: unknown): Record<string, unknown>;
76
+ export declare function writeModelCatalog(binary: string, layout: Layout, timeoutMs?: number): Promise<string>;
77
+ /**
78
+ * #1762 PR-X — the per-turn `avroom` MCP server (§2.3). Codex starts the
79
+ * bridge's stdio shim with node's ABSOLUTE path (the child PATH is
80
+ * /usr/bin:/bin), and the shim relays to THIS turn's Unix socket. No secret
81
+ * is in argv or env: the socket's 0700 directory and 0600 mode are the gate.
82
+ */
83
+ export interface McpWiring {
84
+ /** Absolute node executable (process.execPath). */
85
+ command: string;
86
+ /** Absolute path of dist/avroom-stdio.js. */
87
+ shim: string;
88
+ /** Absolute path of this turn's socket. */
89
+ socket: string;
90
+ }
91
+ /** The `send_file` call must cover a 60 s upload (§2.3: at least 120 s). */
92
+ export declare const MCP_TOOL_TIMEOUT_SEC = 150;
93
+ /**
94
+ * #1762 PR-X (review #1788 item 3): the generation budget of a turn that has send_file (default
95
+ * turns keep 120 s). Writing a sizable file takes the model minutes; each running call then also
96
+ * holds the turn for MCP_TOOL_TIMEOUT_SEC + 10 s, all under the 600 s ceiling.
97
+ */
98
+ export declare const FILE_TURN_BUDGET_MS = 300000;
99
+ export declare function buildInvocation(layout: Layout, sessionId?: string, opts?: {
100
+ disable?: readonly string[];
101
+ mcp?: McpWiring;
102
+ catalog?: string;
103
+ }): {
20
104
  args: string[];
21
105
  env: NodeJS.ProcessEnv;
22
106
  cwd: string;
@@ -57,6 +141,12 @@ export interface TurnUsage {
57
141
  export interface TurnResult {
58
142
  text: string;
59
143
  sessionId: string;
144
+ /**
145
+ * #1762 PR-X: true when this turn ran in a NEW Codex session (no stored
146
+ * session, a recovery, or `startFresh`), false for a resume. The owner-lane
147
+ * taint clears only on a new session. Absent from older fixtures.
148
+ */
149
+ fresh?: boolean;
60
150
  /** Absent when Codex reported none or the shape was not understood. */
61
151
  usage?: TurnUsage;
62
152
  }
@@ -66,7 +156,10 @@ export declare function parseTurnUsage(raw: unknown): TurnUsage | undefined;
66
156
  export interface DriverOptions {
67
157
  binary: string;
68
158
  layout: Layout;
159
+ /** The turn's generation budget (default 120 s). A held tool call extends it (RunOptions.hold). */
69
160
  timeoutMs?: number;
161
+ /** #1762 PR-X: the hard ceiling no hold can pass (default 600 s, under the 15-minute turn-token TTL). */
162
+ maxTurnMs?: number;
70
163
  killGraceMs?: number;
71
164
  maxLineBytes?: number;
72
165
  maxOutputBytes?: number;
@@ -78,13 +171,44 @@ export interface DriverOptions {
78
171
  export interface RunOptions {
79
172
  /** Recent messages of this conversation, sent only when a session starts fresh. */
80
173
  freshContext?: string;
174
+ /** #1762 PR-X: this turn's `avroom` MCP server (absent: Codex gets no MCP server). */
175
+ mcp?: McpWiring;
176
+ /**
177
+ * #1762 PR-X: start a NEW session even though one is stored (the owner
178
+ * lane rotates a session it cannot show to be clean). The stored id is
179
+ * replaced only after the new reply verifies; the first replaced id is kept
180
+ * in `<file>.prev`, as for a recovery.
181
+ */
182
+ startFresh?: boolean;
183
+ /**
184
+ * #1762 PR-X (review #1788 item 3): while a `send_file` call runs, the
185
+ * bridge sets `until` to the latest moment that call may need (Codex's own
186
+ * tool timeout plus a margin). The turn is never killed before it, so a file
187
+ * send always gets its full time and ends with its own "File sent" or "File
188
+ * NOT sent" — up to `maxTurnMs`.
189
+ */
190
+ hold?: {
191
+ until: number;
192
+ };
193
+ /** #1762 PR-X (review #1788 item 3): this turn's generation budget instead of `timeoutMs` (a turn that can write a file gets longer), capped by `maxTurnMs`. */
194
+ budgetMs?: number;
81
195
  }
82
196
  /** One caller at a time. The bridge serializes delivery as well as inference. */
83
197
  export declare class CodexDriver {
84
198
  private readonly options;
85
199
  private busy;
86
200
  private poisoned;
201
+ /** X-3: the default-deny `--disable` list, read once from `codex features list`. */
202
+ private disabled?;
203
+ /** #1762 PR-X: the path of the bridge's own model catalog, written once. */
204
+ private catalog?;
87
205
  constructor(options: DriverOptions);
206
+ /**
207
+ * #1762 PR-X: the Codex session id stored for `key` (undefined when none:
208
+ * the next run starts a new session). Throws on a corrupt record, which the
209
+ * run would refuse too.
210
+ */
211
+ storedSession(key: string): Promise<string | undefined>;
88
212
  run(key: string, prompt: string, signal?: AbortSignal, opts?: RunOptions): Promise<TurnResult>;
89
213
  /**
90
214
  * #1560 — the stored session is gone: run exactly one fresh, seeded session.
@@ -0,0 +1,95 @@
1
+ import type { FileSendResult, FileSendTarget, MessageMetadata, TurnToken } from "@agentvault/agentvault";
2
+ /** The capability SecureChannel hands only to `onMessage`. */
3
+ export type TurnLease = NonNullable<MessageMetadata["turnLease"]>;
4
+ /** The SecureChannel surface a file turn uses. */
5
+ export interface FileTurnChannel {
6
+ sendFile(target: FileSendTarget, path: string, caption: string, turn: TurnToken | null, opts?: {
7
+ signal?: AbortSignal;
8
+ }): Promise<FileSendResult>;
9
+ stagingPathFor(target: FileSendTarget): string | null;
10
+ attestCleanTurn(lease: TurnLease): boolean;
11
+ parkTurn(lease: TurnLease): boolean;
12
+ foldTurn(folded: TurnLease, into: TurnLease): boolean;
13
+ endTurn(lease: TurnLease, opts?: {
14
+ replies?: readonly string[];
15
+ }): Promise<void>;
16
+ }
17
+ /** Does `ch` implement the file-turn surface (a SecureChannel with file send)? */
18
+ export declare function isFileTurnChannel(ch: unknown): ch is FileTurnChannel;
19
+ /** What a `send_file` call returns to the model. */
20
+ export interface SendFileOutcome {
21
+ ok: boolean;
22
+ /** "File sent: …" or "File NOT sent: …" (never a host path, R3-9). */
23
+ text: string;
24
+ }
25
+ export declare class FileTurn {
26
+ private readonly channel;
27
+ readonly lease: TurnLease;
28
+ readonly target: FileSendTarget;
29
+ private state;
30
+ private attested;
31
+ /** A held message's content entered this turn without a fold the registry accepted. */
32
+ private foreignInput;
33
+ private readonly replies;
34
+ private ending?;
35
+ private constructor();
36
+ /**
37
+ * Take the lease from `onMessage` metadata. Call it FIRST, synchronously,
38
+ * before anything that can throw or await. `null` when there is no lease
39
+ * (file send not opted into) or the channel has no file surface.
40
+ */
41
+ static take(channel: unknown, metadata: MessageMetadata | undefined, target: FileSendTarget): FileTurn | null;
42
+ /** The router's lane decision attested this room turn (and nothing has since cost it that). */
43
+ get isAttested(): boolean;
44
+ /** Not yet ended, dropped or folded. */
45
+ get open(): boolean;
46
+ /**
47
+ * The lane decision attests a clean room turn (§1.4, R3-5): call it ONLY
48
+ * when the lane that will run this turn receives no held context, and
49
+ * before the turn can run a tool. 1:1 turns need no attestation.
50
+ */
51
+ attest(): boolean;
52
+ /** The content is HELD (room context), in no turn's input yet. Later: absorb() or drop(). */
53
+ park(): void;
54
+ /**
55
+ * `held`'s content is delivered into THIS turn (§11 R3-4: content enters a
56
+ * turn only through `foldTurn`). `held` then ends with this turn, and a
57
+ * foreign one downgrades it. A fold the registry refuses still marks this
58
+ * turn as carrying foreign input, so it can never send a room file.
59
+ */
60
+ absorb(held: FileTurn | null | undefined): void;
61
+ /** Something the agent said in this turn (say, or the #416 fallback): read by the §4.4 prose check. */
62
+ noteReply(text: string): void;
63
+ /** The turn is over. Once; never throws. Ends whatever was folded into it. */
64
+ end(): Promise<void>;
65
+ /** A TRUE drop: this message's content never enters any turn. */
66
+ drop(): Promise<void>;
67
+ private endNow;
68
+ /** The `[AgentVault: …]` line that tells the model where this conversation's files go (§2, R3-9). */
69
+ stagingNote(): string;
70
+ /** `send_file`: the turn's own conversation, the turn's own token. Never throws. */
71
+ send(path: unknown, caption: unknown, opts?: {
72
+ folderHint?: boolean;
73
+ signal?: AbortSignal;
74
+ }): Promise<SendFileOutcome>;
75
+ }
76
+ /**
77
+ * What `SecureChannelConfig.onMessage` points at. SecureChannel is built
78
+ * before `wireBridge` runs, so the consumer is attached late; until it is, a
79
+ * message is a true drop and its lease is ended (never leaked).
80
+ */
81
+ export declare class TurnInbox {
82
+ private consumer?;
83
+ private channel?;
84
+ /** Pass as `onMessage`. Reads the lease synchronously; never queues. */
85
+ readonly onMessage: (text: string, metadata: MessageMetadata) => void;
86
+ /** The channel, so an unconsumed message's lease can be ended. */
87
+ bindChannel(channel: {
88
+ endTurn(lease: TurnLease, opts?: {
89
+ replies?: readonly string[];
90
+ }): Promise<void>;
91
+ }): void;
92
+ /** wireBridge's one consumer. A second attach replaces the first (there is one claimant). */
93
+ attach(consumer: (text: string, metadata: MessageMetadata) => void): void;
94
+ }
95
+ //# sourceMappingURL=file-turn.d.ts.map
package/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@
2
2
  export { runCli } from "./cli.js";
3
3
  export { CodexDriver, buildInvocation, createLayout } from "./driver.js";
4
4
  export { OpenAIBridge } from "./bridge.js";
5
+ export { AvroomEndpoint } from "./avroom-mcp.js";
5
6
  export declare function main(args?: string[]): Promise<number>;
6
7
  //# sourceMappingURL=index.d.ts.map