llm-cli-gateway 1.4.0 → 1.5.13
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 +135 -1
- package/README.md +358 -15
- package/dist/approval-manager.d.ts +1 -1
- package/dist/async-job-manager.d.ts +32 -2
- package/dist/async-job-manager.js +101 -16
- package/dist/auth.d.ts +15 -0
- package/dist/auth.js +46 -0
- package/dist/cli-updater.d.ts +19 -2
- package/dist/cli-updater.js +110 -7
- package/dist/codex-json-parser.d.ts +34 -0
- package/dist/codex-json-parser.js +105 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +167 -0
- package/dist/doctor.d.ts +110 -0
- package/dist/doctor.js +280 -0
- package/dist/endpoint-exposure.d.ts +22 -0
- package/dist/endpoint-exposure.js +231 -0
- package/dist/entrypoint-url.d.ts +1 -0
- package/dist/entrypoint-url.js +5 -0
- package/dist/executor.d.ts +9 -1
- package/dist/executor.js +52 -17
- package/dist/flight-recorder.d.ts +3 -1
- package/dist/flight-recorder.js +31 -2
- package/dist/gateway-server.d.ts +2 -0
- package/dist/gateway-server.js +1 -0
- package/dist/gemini-json-parser.d.ts +21 -0
- package/dist/gemini-json-parser.js +47 -0
- package/dist/health.d.ts +7 -0
- package/dist/health.js +22 -0
- package/dist/http-transport.d.ts +22 -0
- package/dist/http-transport.js +164 -0
- package/dist/index.d.ts +186 -2
- package/dist/index.js +2761 -1454
- package/dist/job-store.d.ts +118 -2
- package/dist/job-store.js +176 -5
- package/dist/logger.d.ts +9 -0
- package/dist/logger.js +14 -0
- package/dist/model-registry.js +40 -6
- package/dist/provider-login-guidance.d.ts +21 -0
- package/dist/provider-login-guidance.js +98 -0
- package/dist/provider-status.d.ts +41 -0
- package/dist/provider-status.js +203 -0
- package/dist/request-helpers.d.ts +484 -4
- package/dist/request-helpers.js +613 -0
- package/dist/resources.js +44 -0
- package/dist/session-manager-pg.js +1 -0
- package/dist/session-manager.d.ts +1 -1
- package/dist/session-manager.js +2 -1
- package/dist/upstream-contracts.d.ts +62 -0
- package/dist/upstream-contracts.js +620 -0
- package/dist/validation-normalizer.d.ts +23 -0
- package/dist/validation-normalizer.js +79 -0
- package/dist/validation-orchestrator.d.ts +47 -0
- package/dist/validation-orchestrator.js +145 -0
- package/dist/validation-prompts.d.ts +15 -0
- package/dist/validation-prompts.js +52 -0
- package/dist/validation-report.d.ts +57 -0
- package/dist/validation-report.js +129 -0
- package/dist/validation-tools.d.ts +7 -0
- package/dist/validation-tools.js +198 -0
- package/package.json +25 -10
- package/setup/status.schema.json +271 -0
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Pure, side-effect-free helpers for request argument planning.
|
|
3
|
-
* Zero I/O, zero dependencies on index-scoped collaborators.
|
|
4
|
-
*/
|
|
1
|
+
import { z } from "zod";
|
|
5
2
|
/** Prefix for gateway-generated session IDs. Enforces provenance structurally. */
|
|
6
3
|
export declare const GATEWAY_SESSION_PREFIX = "gw-";
|
|
7
4
|
export interface SessionResumeResult {
|
|
@@ -71,3 +68,486 @@ export declare function resolveGrokSessionArgs(opts: {
|
|
|
71
68
|
resumeLatest?: boolean;
|
|
72
69
|
createNewSession?: boolean;
|
|
73
70
|
}): SessionResumeResult;
|
|
71
|
+
/**
|
|
72
|
+
* Mistral Vibe-specific resume args.
|
|
73
|
+
*
|
|
74
|
+
* Vibe persists sessions only when `[session_logging] enabled = true` is set in
|
|
75
|
+
* `~/.vibe/config.toml`. The doctor checks for that toggle and surfaces an
|
|
76
|
+
* actionable error when it is missing; this pure helper just emits the args.
|
|
77
|
+
*
|
|
78
|
+
* The args shape mirrors Grok (`--continue` for latest, `--resume <id>` for a
|
|
79
|
+
* specific session) because Vibe exposes the same surface for its session log.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveMistralSessionArgs(opts: {
|
|
82
|
+
sessionId?: string;
|
|
83
|
+
resumeLatest?: boolean;
|
|
84
|
+
createNewSession?: boolean;
|
|
85
|
+
}): SessionResumeResult;
|
|
86
|
+
/**
|
|
87
|
+
* Vibe-specific permission mode mapping. Vibe replaces Grok's `--always-approve`
|
|
88
|
+
* with an `--agent <mode>` enum. When the caller does not set a permissionMode,
|
|
89
|
+
* the gateway emits `--agent auto-approve` explicitly: omitting the flag would
|
|
90
|
+
* let Vibe pick its own default which may not be auto-approve, surprising
|
|
91
|
+
* programmatic callers.
|
|
92
|
+
*/
|
|
93
|
+
export declare const MISTRAL_AGENT_MODES: readonly ["default", "plan", "accept-edits", "auto-approve", "chat", "explore", "lean"];
|
|
94
|
+
export type MistralAgentMode = (typeof MISTRAL_AGENT_MODES)[number];
|
|
95
|
+
export declare const MISTRAL_DEFAULT_AGENT_MODE: MistralAgentMode;
|
|
96
|
+
export interface PrepareMistralRequestInput {
|
|
97
|
+
prompt: string;
|
|
98
|
+
resolvedModel?: string;
|
|
99
|
+
outputFormat?: string;
|
|
100
|
+
permissionMode?: MistralAgentMode;
|
|
101
|
+
effort?: string;
|
|
102
|
+
reasoningEffort?: string;
|
|
103
|
+
allowedTools?: string[];
|
|
104
|
+
/**
|
|
105
|
+
* Vibe has no flag to deny tools; this is accepted in the schema for caller
|
|
106
|
+
* parity with Grok/Claude but produces no CLI flag. The caller is expected to
|
|
107
|
+
* emit a `logger.warn` when this is non-empty.
|
|
108
|
+
*/
|
|
109
|
+
disallowedTools?: string[];
|
|
110
|
+
}
|
|
111
|
+
export interface PrepareMistralRequestResult {
|
|
112
|
+
args: string[];
|
|
113
|
+
env: Record<string, string>;
|
|
114
|
+
ignoredDisallowedTools: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Pure helper that builds Vibe's argv and env.
|
|
118
|
+
*
|
|
119
|
+
* - Model is selected via `VIBE_ACTIVE_MODEL` env var (NOT a `--model` flag).
|
|
120
|
+
* - Permission mode emits `--agent <mode>` (defaults to `auto-approve` when unset).
|
|
121
|
+
* - Allowed tools emit `--enabled-tools <tool>` once per tool (allowlist only).
|
|
122
|
+
* - Disallowed tools are accepted but ignored at the CLI boundary.
|
|
123
|
+
*/
|
|
124
|
+
export declare function prepareMistralRequest(input: PrepareMistralRequestInput): PrepareMistralRequestResult;
|
|
125
|
+
/**
|
|
126
|
+
* Claude `--permission-mode` values. `default` is a no-op (no flag emitted) —
|
|
127
|
+
* matches the CLI's behavior when the flag is absent, and avoids hard-coding an
|
|
128
|
+
* undocumented literal.
|
|
129
|
+
*/
|
|
130
|
+
export declare const CLAUDE_PERMISSION_MODES: readonly ["default", "acceptEdits", "plan", "auto", "dontAsk", "bypassPermissions"];
|
|
131
|
+
export type ClaudePermissionMode = (typeof CLAUDE_PERMISSION_MODES)[number];
|
|
132
|
+
export interface ClaudePermissionFlagsInput {
|
|
133
|
+
permissionMode?: ClaudePermissionMode;
|
|
134
|
+
/** Legacy parameter retained for one minor release. Maps to bypassPermissions. */
|
|
135
|
+
dangerouslySkipPermissions?: boolean;
|
|
136
|
+
}
|
|
137
|
+
export interface ClaudePermissionFlagsResult {
|
|
138
|
+
args: string[];
|
|
139
|
+
/** Set when both legacy + new flag are passed; caller should logger.warn. */
|
|
140
|
+
warning?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Resolve Claude's `--permission-mode` args.
|
|
144
|
+
*
|
|
145
|
+
* Precedence:
|
|
146
|
+
* 1. If `permissionMode` is set, it wins. A warning is returned when
|
|
147
|
+
* `dangerouslySkipPermissions: true` is also set (legacy + new conflict).
|
|
148
|
+
* 2. Else if `dangerouslySkipPermissions: true`, emit `--permission-mode
|
|
149
|
+
* bypassPermissions`.
|
|
150
|
+
* 3. Else (or `permissionMode === "default"`) emit nothing.
|
|
151
|
+
*/
|
|
152
|
+
export declare function resolveClaudePermissionFlags(input: ClaudePermissionFlagsInput): ClaudePermissionFlagsResult;
|
|
153
|
+
/**
|
|
154
|
+
* Gemini `--approval-mode` values. Preserves existing values (`default`,
|
|
155
|
+
* `auto_edit`, `yolo`) and adds `plan` for parity with Claude's plan mode.
|
|
156
|
+
*/
|
|
157
|
+
export declare const GEMINI_APPROVAL_MODES: readonly ["default", "auto_edit", "yolo", "plan"];
|
|
158
|
+
export type GeminiApprovalMode = (typeof GEMINI_APPROVAL_MODES)[number];
|
|
159
|
+
/**
|
|
160
|
+
* Codex sandbox modes (for `--sandbox <mode>`).
|
|
161
|
+
*/
|
|
162
|
+
export declare const CODEX_SANDBOX_MODES: readonly ["read-only", "workspace-write", "danger-full-access"];
|
|
163
|
+
export type CodexSandboxMode = (typeof CODEX_SANDBOX_MODES)[number];
|
|
164
|
+
/**
|
|
165
|
+
* Codex approval modes (for `--ask-for-approval <mode>`).
|
|
166
|
+
*/
|
|
167
|
+
export declare const CODEX_ASK_FOR_APPROVAL_MODES: readonly ["untrusted", "on-request", "never"];
|
|
168
|
+
export type CodexAskForApproval = (typeof CODEX_ASK_FOR_APPROVAL_MODES)[number];
|
|
169
|
+
export interface CodexSandboxFlagsInput {
|
|
170
|
+
/** Modern: explicit sandbox mode. */
|
|
171
|
+
sandboxMode?: CodexSandboxMode;
|
|
172
|
+
/** Modern: explicit approval mode. */
|
|
173
|
+
askForApproval?: CodexAskForApproval;
|
|
174
|
+
/** Legacy: shorthand for sandbox=workspace-write + askForApproval=never. */
|
|
175
|
+
fullAuto?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Escape hatch: when true + `fullAuto: true`, emit `--full-auto` directly
|
|
178
|
+
* instead of expanding. Off by default. Deprecated and removed after
|
|
179
|
+
* Mistral GA.
|
|
180
|
+
*/
|
|
181
|
+
useLegacyFullAutoFlag?: boolean;
|
|
182
|
+
}
|
|
183
|
+
export interface CodexSandboxFlagsResult {
|
|
184
|
+
args: string[];
|
|
185
|
+
/** Set when fullAuto + explicit sandbox/approval are both supplied. */
|
|
186
|
+
warning?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Resolve Codex `--sandbox` / `--ask-for-approval` args from the modern
|
|
190
|
+
* params + legacy `fullAuto` shorthand.
|
|
191
|
+
*
|
|
192
|
+
* Precedence:
|
|
193
|
+
* 1. If `useLegacyFullAutoFlag && fullAuto`, emit `--full-auto` directly
|
|
194
|
+
* (escape hatch; deprecated).
|
|
195
|
+
* 2. Else explicit `sandboxMode` / `askForApproval` always emit their
|
|
196
|
+
* flags. If `fullAuto: true` is set alongside, a warning is attached
|
|
197
|
+
* and the explicit values win.
|
|
198
|
+
* 3. Else if `fullAuto: true`, expand to
|
|
199
|
+
* `--sandbox workspace-write --ask-for-approval never`.
|
|
200
|
+
* 4. Else emit nothing.
|
|
201
|
+
*/
|
|
202
|
+
export declare function resolveCodexSandboxFlags(input: CodexSandboxFlagsInput): CodexSandboxFlagsResult;
|
|
203
|
+
/**
|
|
204
|
+
* Flags that `codex exec resume` rejects (the original session's policy is
|
|
205
|
+
* inherited). Callers must drop these when building resume argv.
|
|
206
|
+
*
|
|
207
|
+
* U26 expands this list with `--add-dir`, `-C`, `--output-schema`, and
|
|
208
|
+
* `--search`, all of which `codex exec resume --help` rejects at the audit
|
|
209
|
+
* date.
|
|
210
|
+
*/
|
|
211
|
+
export declare const CODEX_RESUME_FILTERED_FLAGS: ReadonlySet<string>;
|
|
212
|
+
/**
|
|
213
|
+
* Strip resume-incompatible flag/value pairs from a Codex argv segment.
|
|
214
|
+
*
|
|
215
|
+
* Bare flags (`--full-auto`, `--search`) drop without consuming a value.
|
|
216
|
+
* Value-taking flags (`--sandbox`, `--ask-for-approval`, `--add-dir`, `-C`,
|
|
217
|
+
* `--output-schema`) drop together with their immediately-following value.
|
|
218
|
+
*/
|
|
219
|
+
export declare function filterCodexResumeFlags(args: string[]): string[];
|
|
220
|
+
/**
|
|
221
|
+
* Claude `--effort` enum values. Mirrors the model-side effort axis.
|
|
222
|
+
*/
|
|
223
|
+
export declare const CLAUDE_EFFORT_LEVELS: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
224
|
+
export type ClaudeEffortLevel = (typeof CLAUDE_EFFORT_LEVELS)[number];
|
|
225
|
+
/**
|
|
226
|
+
* Standalone Zod object for U25's high-impact param subset. Enforces the
|
|
227
|
+
* `systemPrompt` / `appendSystemPrompt` mutual-exclusion via `.refine(...)`.
|
|
228
|
+
*
|
|
229
|
+
* The MCP SDK's `server.tool` takes a raw shape (no top-level refine), so the
|
|
230
|
+
* tool callback re-checks the constraint and returns an error response. This
|
|
231
|
+
* exported schema is what tests use to verify Zod-level enforcement.
|
|
232
|
+
*/
|
|
233
|
+
export declare const CLAUDE_HIGH_IMPACT_PARAMS_SCHEMA: z.ZodEffects<z.ZodObject<{
|
|
234
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
235
|
+
agents: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
236
|
+
forkSession: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
238
|
+
appendSystemPrompt: z.ZodOptional<z.ZodString>;
|
|
239
|
+
maxBudgetUsd: z.ZodOptional<z.ZodNumber>;
|
|
240
|
+
maxTurns: z.ZodOptional<z.ZodNumber>;
|
|
241
|
+
effort: z.ZodOptional<z.ZodEnum<["low", "medium", "high", "xhigh", "max"]>>;
|
|
242
|
+
excludeDynamicSystemPromptSections: z.ZodOptional<z.ZodBoolean>;
|
|
243
|
+
}, "strip", z.ZodTypeAny, {
|
|
244
|
+
agent?: string | undefined;
|
|
245
|
+
agents?: Record<string, Record<string, unknown>> | undefined;
|
|
246
|
+
forkSession?: boolean | undefined;
|
|
247
|
+
systemPrompt?: string | undefined;
|
|
248
|
+
appendSystemPrompt?: string | undefined;
|
|
249
|
+
maxBudgetUsd?: number | undefined;
|
|
250
|
+
maxTurns?: number | undefined;
|
|
251
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
|
|
252
|
+
excludeDynamicSystemPromptSections?: boolean | undefined;
|
|
253
|
+
}, {
|
|
254
|
+
agent?: string | undefined;
|
|
255
|
+
agents?: Record<string, Record<string, unknown>> | undefined;
|
|
256
|
+
forkSession?: boolean | undefined;
|
|
257
|
+
systemPrompt?: string | undefined;
|
|
258
|
+
appendSystemPrompt?: string | undefined;
|
|
259
|
+
maxBudgetUsd?: number | undefined;
|
|
260
|
+
maxTurns?: number | undefined;
|
|
261
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
|
|
262
|
+
excludeDynamicSystemPromptSections?: boolean | undefined;
|
|
263
|
+
}>, {
|
|
264
|
+
agent?: string | undefined;
|
|
265
|
+
agents?: Record<string, Record<string, unknown>> | undefined;
|
|
266
|
+
forkSession?: boolean | undefined;
|
|
267
|
+
systemPrompt?: string | undefined;
|
|
268
|
+
appendSystemPrompt?: string | undefined;
|
|
269
|
+
maxBudgetUsd?: number | undefined;
|
|
270
|
+
maxTurns?: number | undefined;
|
|
271
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
|
|
272
|
+
excludeDynamicSystemPromptSections?: boolean | undefined;
|
|
273
|
+
}, {
|
|
274
|
+
agent?: string | undefined;
|
|
275
|
+
agents?: Record<string, Record<string, unknown>> | undefined;
|
|
276
|
+
forkSession?: boolean | undefined;
|
|
277
|
+
systemPrompt?: string | undefined;
|
|
278
|
+
appendSystemPrompt?: string | undefined;
|
|
279
|
+
maxBudgetUsd?: number | undefined;
|
|
280
|
+
maxTurns?: number | undefined;
|
|
281
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
|
|
282
|
+
excludeDynamicSystemPromptSections?: boolean | undefined;
|
|
283
|
+
}>;
|
|
284
|
+
/**
|
|
285
|
+
* Minimal Anthropic agent-definition schema. Mirrors the shape expected by
|
|
286
|
+
* Claude CLI's `--agents` inline JSON argument. We validate the *required*
|
|
287
|
+
* keys (`description`, `prompt`) up-front so a malformed payload fails fast
|
|
288
|
+
* with an actionable error instead of producing an opaque CLI exit.
|
|
289
|
+
*/
|
|
290
|
+
export declare const CLAUDE_AGENT_DEFINITION_SCHEMA: z.ZodObject<{
|
|
291
|
+
description: z.ZodString;
|
|
292
|
+
prompt: z.ZodString;
|
|
293
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
294
|
+
model: z.ZodOptional<z.ZodString>;
|
|
295
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
296
|
+
description: z.ZodString;
|
|
297
|
+
prompt: z.ZodString;
|
|
298
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
299
|
+
model: z.ZodOptional<z.ZodString>;
|
|
300
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
301
|
+
description: z.ZodString;
|
|
302
|
+
prompt: z.ZodString;
|
|
303
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
304
|
+
model: z.ZodOptional<z.ZodString>;
|
|
305
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
306
|
+
export type ClaudeAgentDefinition = z.infer<typeof CLAUDE_AGENT_DEFINITION_SCHEMA>;
|
|
307
|
+
/**
|
|
308
|
+
* Validate an `agents` map against {@link CLAUDE_AGENT_DEFINITION_SCHEMA}.
|
|
309
|
+
*
|
|
310
|
+
* Returns `{ ok: true, value }` on success and `{ ok: false, agentKey, message }`
|
|
311
|
+
* on the first failing entry. The caller is responsible for turning the failure
|
|
312
|
+
* into a tool-level error response (e.g. via `createErrorResponse`).
|
|
313
|
+
*/
|
|
314
|
+
export declare function validateClaudeAgentsMap(agents: Record<string, unknown>): {
|
|
315
|
+
ok: true;
|
|
316
|
+
value: Record<string, ClaudeAgentDefinition>;
|
|
317
|
+
} | {
|
|
318
|
+
ok: false;
|
|
319
|
+
agentKey: string;
|
|
320
|
+
message: string;
|
|
321
|
+
};
|
|
322
|
+
export interface ClaudeHighImpactFlagsInput {
|
|
323
|
+
agent?: string;
|
|
324
|
+
/** Pre-validated agents map (call {@link validateClaudeAgentsMap} first). */
|
|
325
|
+
agents?: Record<string, ClaudeAgentDefinition>;
|
|
326
|
+
forkSession?: boolean;
|
|
327
|
+
systemPrompt?: string;
|
|
328
|
+
appendSystemPrompt?: string;
|
|
329
|
+
maxBudgetUsd?: number;
|
|
330
|
+
maxTurns?: number;
|
|
331
|
+
effort?: ClaudeEffortLevel;
|
|
332
|
+
excludeDynamicSystemPromptSections?: boolean;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Emit Claude high-impact feature flags (U25) as a flat argv segment.
|
|
336
|
+
*
|
|
337
|
+
* Mutual-exclusion of `systemPrompt`/`appendSystemPrompt` is enforced upstream
|
|
338
|
+
* at the Zod schema (`.refine(...)`); this helper does *not* re-check it, so
|
|
339
|
+
* tests can exercise either flag in isolation.
|
|
340
|
+
*/
|
|
341
|
+
export declare function prepareClaudeHighImpactFlags(input: ClaudeHighImpactFlagsInput): string[];
|
|
342
|
+
/**
|
|
343
|
+
* Zod schema for Codex `configOverrides` map.
|
|
344
|
+
*
|
|
345
|
+
* Hard requirements (argv-injection prevention):
|
|
346
|
+
* - Keys MUST match /^[a-zA-Z0-9._]+$/ (no whitespace, no equals, no flag-like prefixes).
|
|
347
|
+
* - Values MUST NOT contain CR or LF — newlines could be re-interpreted by the
|
|
348
|
+
* CLI's TOML parser as new keys.
|
|
349
|
+
*
|
|
350
|
+
* The CLI consumes overrides as `-c key=value`. We rely on `spawn(..., args)`
|
|
351
|
+
* passing argv directly without a shell, so we forbid shape-breaking
|
|
352
|
+
* characters rather than shell-escaping values.
|
|
353
|
+
*/
|
|
354
|
+
export declare const CODEX_CONFIG_OVERRIDES_SCHEMA: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, string, string>>>;
|
|
355
|
+
export type CodexConfigOverrides = z.infer<typeof CODEX_CONFIG_OVERRIDES_SCHEMA>;
|
|
356
|
+
/**
|
|
357
|
+
* Emit `-c key=value` pairs for each override. Caller MUST have validated the
|
|
358
|
+
* map with {@link CODEX_CONFIG_OVERRIDES_SCHEMA} first.
|
|
359
|
+
*/
|
|
360
|
+
export declare function emitCodexConfigOverrideArgs(overrides: Record<string, string> | undefined): string[];
|
|
361
|
+
/**
|
|
362
|
+
* Materialize `outputSchema` into a CLI path.
|
|
363
|
+
*
|
|
364
|
+
* If `outputSchema` is a string, treat it as a pre-existing path and pass it
|
|
365
|
+
* through verbatim (no temp file, no cleanup needed).
|
|
366
|
+
*
|
|
367
|
+
* If it is an object, JSON-serialize it into a 0o600-mode temp file under
|
|
368
|
+
* `os.tmpdir()` and return both the path and a cleanup function. The caller
|
|
369
|
+
* MUST invoke `cleanup()` in a `finally` block (no matter the exit path) so
|
|
370
|
+
* the temp file does not leak.
|
|
371
|
+
*
|
|
372
|
+
* Returns `null` when `outputSchema` is undefined.
|
|
373
|
+
*/
|
|
374
|
+
export interface CodexOutputSchemaResult {
|
|
375
|
+
path: string;
|
|
376
|
+
/** No-op when schema came in as a string. Idempotent. */
|
|
377
|
+
cleanup: () => void;
|
|
378
|
+
}
|
|
379
|
+
export declare function prepareCodexOutputSchema(outputSchema: string | Record<string, unknown> | undefined): CodexOutputSchemaResult | null;
|
|
380
|
+
/**
|
|
381
|
+
* Validate that every image path exists on disk. Returns the first missing
|
|
382
|
+
* path on failure; `null` on success.
|
|
383
|
+
*/
|
|
384
|
+
export declare function findMissingImagePath(images: string[] | undefined): string | null;
|
|
385
|
+
/**
|
|
386
|
+
* Zod schema for the U26 Codex high-impact feature subset. Used by the
|
|
387
|
+
* `codex_request` / `codex_request_async` tool schemas to validate the new
|
|
388
|
+
* params before they reach `prepareCodexRequest`.
|
|
389
|
+
*/
|
|
390
|
+
export declare const CODEX_HIGH_IMPACT_PARAMS_SCHEMA: z.ZodObject<{
|
|
391
|
+
outputSchema: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
392
|
+
search: z.ZodOptional<z.ZodBoolean>;
|
|
393
|
+
profile: z.ZodOptional<z.ZodString>;
|
|
394
|
+
configOverrides: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodString, string, string>>>;
|
|
395
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
396
|
+
images: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
397
|
+
ignoreUserConfig: z.ZodOptional<z.ZodBoolean>;
|
|
398
|
+
ignoreRules: z.ZodOptional<z.ZodBoolean>;
|
|
399
|
+
}, "strip", z.ZodTypeAny, {
|
|
400
|
+
search?: boolean | undefined;
|
|
401
|
+
profile?: string | undefined;
|
|
402
|
+
outputSchema?: string | Record<string, unknown> | undefined;
|
|
403
|
+
configOverrides?: Record<string, string> | undefined;
|
|
404
|
+
ephemeral?: boolean | undefined;
|
|
405
|
+
images?: string[] | undefined;
|
|
406
|
+
ignoreUserConfig?: boolean | undefined;
|
|
407
|
+
ignoreRules?: boolean | undefined;
|
|
408
|
+
}, {
|
|
409
|
+
search?: boolean | undefined;
|
|
410
|
+
profile?: string | undefined;
|
|
411
|
+
outputSchema?: string | Record<string, unknown> | undefined;
|
|
412
|
+
configOverrides?: Record<string, string> | undefined;
|
|
413
|
+
ephemeral?: boolean | undefined;
|
|
414
|
+
images?: string[] | undefined;
|
|
415
|
+
ignoreUserConfig?: boolean | undefined;
|
|
416
|
+
ignoreRules?: boolean | undefined;
|
|
417
|
+
}>;
|
|
418
|
+
export interface CodexHighImpactFlagsInput {
|
|
419
|
+
outputSchema?: string | Record<string, unknown>;
|
|
420
|
+
search?: boolean;
|
|
421
|
+
profile?: string;
|
|
422
|
+
configOverrides?: Record<string, string>;
|
|
423
|
+
ephemeral?: boolean;
|
|
424
|
+
images?: string[];
|
|
425
|
+
ignoreUserConfig?: boolean;
|
|
426
|
+
ignoreRules?: boolean;
|
|
427
|
+
}
|
|
428
|
+
export interface CodexHighImpactFlagsResult {
|
|
429
|
+
args: string[];
|
|
430
|
+
/** Cleanup hook for the `outputSchema` temp file. Caller MUST invoke in `finally`. */
|
|
431
|
+
cleanup: () => void;
|
|
432
|
+
/** First missing image path, if any. When set, the caller should bail before spawning. */
|
|
433
|
+
missingImagePath: string | null;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Build the U26 argv segment AND any required side-effect handles.
|
|
437
|
+
*
|
|
438
|
+
* IMPORTANT: When this function writes a temp file for `outputSchema`, the
|
|
439
|
+
* returned `cleanup` function MUST be invoked by the caller (typically in a
|
|
440
|
+
* `finally` block around the spawn). Failing to do so leaks `0o600` temp
|
|
441
|
+
* files into `os.tmpdir()`.
|
|
442
|
+
*/
|
|
443
|
+
export declare function prepareCodexHighImpactFlags(input: CodexHighImpactFlagsInput): CodexHighImpactFlagsResult;
|
|
444
|
+
/**
|
|
445
|
+
* Pure helper for `codex_fork_session`. Builds `codex fork ...` argv from a
|
|
446
|
+
* mutually-exclusive (sessionId | forkLast) selector and a prompt.
|
|
447
|
+
*
|
|
448
|
+
* Mutual exclusion is also enforced at the Zod schema in `index.ts`; this
|
|
449
|
+
* helper re-checks defensively so callers exercising it in isolation get the
|
|
450
|
+
* same guarantees.
|
|
451
|
+
*/
|
|
452
|
+
export interface CodexForkRequestInput {
|
|
453
|
+
prompt: string;
|
|
454
|
+
sessionId?: string;
|
|
455
|
+
forkLast?: boolean;
|
|
456
|
+
}
|
|
457
|
+
export declare function prepareCodexForkRequest(input: CodexForkRequestInput): {
|
|
458
|
+
args: string[];
|
|
459
|
+
};
|
|
460
|
+
/**
|
|
461
|
+
* Strict UUID v4 regex. Gemini's CLI is reportedly stricter about session id
|
|
462
|
+
* shape than the gateway's internal handles, so caller-supplied IDs (and IDs
|
|
463
|
+
* generated by `crypto.randomUUID()`) are validated against this regex before
|
|
464
|
+
* being emitted as `--session-id <uuid>`.
|
|
465
|
+
*/
|
|
466
|
+
export declare const GEMINI_SESSION_ID_REGEX: RegExp;
|
|
467
|
+
export declare function isValidGeminiSessionId(id: string): boolean;
|
|
468
|
+
/**
|
|
469
|
+
* Prepend `@<abs-path>` tokens to a Gemini prompt so the CLI's attachment
|
|
470
|
+
* resolver picks them up. Each path MUST be absolute and exist on disk.
|
|
471
|
+
*
|
|
472
|
+
* Returns the mutated prompt. Throws on validation failure so the caller can
|
|
473
|
+
* convert to a `createErrorResponse`.
|
|
474
|
+
*/
|
|
475
|
+
export declare function prependGeminiAttachments(prompt: string, attachments: string[]): string;
|
|
476
|
+
/**
|
|
477
|
+
* Zod schema for the U27 Gemini high-impact feature subset. Used by the
|
|
478
|
+
* `gemini_request` / `gemini_request_async` tool schemas to validate the new
|
|
479
|
+
* params before they reach `prepareGeminiRequest`.
|
|
480
|
+
*
|
|
481
|
+
* `attachments` paths are validated to be absolute at the Zod layer; existence
|
|
482
|
+
* is enforced at execution time via `prependGeminiAttachments`.
|
|
483
|
+
*/
|
|
484
|
+
export declare const GEMINI_HIGH_IMPACT_PARAMS_SCHEMA: z.ZodObject<{
|
|
485
|
+
sandbox: z.ZodOptional<z.ZodBoolean>;
|
|
486
|
+
policyFiles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
487
|
+
adminPolicyFiles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
488
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
|
|
489
|
+
}, "strip", z.ZodTypeAny, {
|
|
490
|
+
sandbox?: boolean | undefined;
|
|
491
|
+
policyFiles?: string[] | undefined;
|
|
492
|
+
adminPolicyFiles?: string[] | undefined;
|
|
493
|
+
attachments?: string[] | undefined;
|
|
494
|
+
}, {
|
|
495
|
+
sandbox?: boolean | undefined;
|
|
496
|
+
policyFiles?: string[] | undefined;
|
|
497
|
+
adminPolicyFiles?: string[] | undefined;
|
|
498
|
+
attachments?: string[] | undefined;
|
|
499
|
+
}>;
|
|
500
|
+
export interface GeminiHighImpactFlagsInput {
|
|
501
|
+
sandbox?: boolean;
|
|
502
|
+
policyFiles?: string[];
|
|
503
|
+
adminPolicyFiles?: string[];
|
|
504
|
+
}
|
|
505
|
+
export interface GeminiHighImpactFlagsResult {
|
|
506
|
+
args: string[];
|
|
507
|
+
/** First missing policy path, if any. When set, the caller should bail. */
|
|
508
|
+
missingPolicyPath: string | null;
|
|
509
|
+
/** Which field the missing path came from (for actionable error messages). */
|
|
510
|
+
missingPolicyField: "policyFiles" | "adminPolicyFiles" | null;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Emit Gemini U27 high-impact flags. Policy paths are existence-checked here
|
|
514
|
+
* so a missing file fails fast with an actionable error rather than producing
|
|
515
|
+
* an opaque CLI exit.
|
|
516
|
+
*
|
|
517
|
+
* Does NOT handle `attachments` — those are mutated into the prompt string
|
|
518
|
+
* via {@link prependGeminiAttachments} BEFORE the `-p <prompt>` pair is
|
|
519
|
+
* emitted, preserving the U21 `-p` ordering invariant.
|
|
520
|
+
*/
|
|
521
|
+
export declare function prepareGeminiHighImpactFlags(input: GeminiHighImpactFlagsInput): GeminiHighImpactFlagsResult;
|
|
522
|
+
/**
|
|
523
|
+
* Result of resolving Gemini's session-id emission strategy.
|
|
524
|
+
*
|
|
525
|
+
* U27 introduces deterministic `--session-id <uuid>` emission for fresh
|
|
526
|
+
* sessions, mapping the gateway-side session ID 1:1 to Gemini's authoritative
|
|
527
|
+
* store. The existing `--resume <id>` flow is preserved for user-supplied
|
|
528
|
+
* session IDs.
|
|
529
|
+
*/
|
|
530
|
+
export interface GeminiSessionPlan {
|
|
531
|
+
/** Flag pair to inject into argv (one of `["--session-id", uuid]`, `["--resume", id]`, `["--resume", "latest"]`, or `[]`). */
|
|
532
|
+
args: string[];
|
|
533
|
+
/** The UUID emitted via `--session-id`, if any. Gateway should persist this. */
|
|
534
|
+
emittedSessionId?: string;
|
|
535
|
+
/** True iff `--resume <id>` was emitted with a user-supplied id. */
|
|
536
|
+
resumed: boolean;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Resolve Gemini session-id args. When a fresh session is being established
|
|
540
|
+
* (either `createNewSession: true`, or no sessionId/resumeLatest set), emit
|
|
541
|
+
* `--session-id <uuid>` so the gateway and Gemini agree on the session
|
|
542
|
+
* identifier from the first turn.
|
|
543
|
+
*
|
|
544
|
+
* Falls back to `--resume <id>` when the caller supplies a sessionId, and
|
|
545
|
+
* `--resume latest` for `resumeLatest` (existing behavior preserved).
|
|
546
|
+
*/
|
|
547
|
+
export declare function resolveGeminiSessionPlan(opts: {
|
|
548
|
+
sessionId?: string;
|
|
549
|
+
resumeLatest?: boolean;
|
|
550
|
+
createNewSession?: boolean;
|
|
551
|
+
/** Override generator for deterministic tests. Must produce a v4 UUID. */
|
|
552
|
+
generateId?: () => string;
|
|
553
|
+
}): GeminiSessionPlan;
|