@ai21/gateway 1.3.1 → 1.4.0
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/README.md +21 -17
- package/dist/agents/claude-code/index.d.ts +7 -0
- package/dist/agents/claude-code/index.js +112 -0
- package/dist/agents/claude-code/index.js.map +1 -0
- package/dist/agents/claude-code/verify.d.ts +6 -46
- package/dist/agents/claude-code/verify.js +2 -2
- package/dist/agents/claude-code/verify.js.map +1 -1
- package/dist/agents/codex/config.d.ts +20 -0
- package/dist/agents/codex/config.js +344 -0
- package/dist/agents/codex/config.js.map +1 -0
- package/dist/agents/codex/index.d.ts +2 -0
- package/dist/agents/codex/index.js +79 -0
- package/dist/agents/codex/index.js.map +1 -0
- package/dist/agents/codex/snippets.d.ts +23 -0
- package/dist/agents/codex/snippets.js +39 -0
- package/dist/agents/codex/snippets.js.map +1 -0
- package/dist/agents/codex/status.d.ts +8 -0
- package/dist/agents/codex/status.js +36 -0
- package/dist/agents/codex/status.js.map +1 -0
- package/dist/agents/codex/toml.d.ts +57 -0
- package/dist/agents/codex/toml.js +196 -0
- package/dist/agents/codex/toml.js.map +1 -0
- package/dist/agents/codex/verify.d.ts +2 -0
- package/dist/agents/codex/verify.js +43 -0
- package/dist/agents/codex/verify.js.map +1 -0
- package/dist/agents/registry.d.ts +10 -0
- package/dist/agents/registry.js +14 -0
- package/dist/agents/registry.js.map +1 -0
- package/dist/agents/types.d.ts +10 -0
- package/dist/args.d.ts +2 -3
- package/dist/args.js +7 -9
- package/dist/args.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +18 -12
- package/dist/cli.js.map +1 -1
- package/dist/fs/safeFile.d.ts +1 -0
- package/dist/fs/safeFile.js.map +1 -1
- package/dist/fs/snapshot.d.ts +1 -1
- package/dist/fs/snapshot.js +1 -1
- package/dist/precheck.d.ts +4 -1
- package/dist/precheck.js +12 -9
- package/dist/precheck.js.map +1 -1
- package/dist/report.d.ts +16 -19
- package/dist/report.js +36 -62
- package/dist/report.js.map +1 -1
- package/dist/result.d.ts +5 -5
- package/dist/result.js +5 -5
- package/dist/result.js.map +1 -1
- package/dist/router.d.ts +5 -2
- package/dist/router.js +115 -113
- package/dist/router.js.map +1 -1
- package/dist/telemetry/events.d.ts +3 -2
- package/dist/telemetry/events.js +0 -6
- package/dist/telemetry/events.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,9 +9,13 @@ Ships as the `@ai21/gateway` package.
|
|
|
9
9
|
npx @ai21/gateway install --agent-id <AGENT_ID>
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sends one request to prove it works.
|
|
12
|
+
Configures a coding agent — Claude Code or Codex — so it routes through the
|
|
13
|
+
gateway. Writes the agent's config file (`.claude/settings.json` for Claude Code,
|
|
14
|
+
`config.toml` for Codex), then sends one request to prove it works.
|
|
15
|
+
|
|
16
|
+
Use `--client codex` for Codex (user-level only; Codex ignores `model_provider`
|
|
17
|
+
and `model_providers` in a project's `.codex/config.toml`). `--client claude-code`
|
|
18
|
+
is the default and also accepts `--repo` for a project-local setup. With no key stored it signs you in through the
|
|
15
19
|
browser first and creates an AI21 key for you, all in the one command — pass `--key`
|
|
16
20
|
only for scripting, since a key in argv stays in your shell history.
|
|
17
21
|
|
|
@@ -25,17 +29,17 @@ and a warning says the key went unchecked.
|
|
|
25
29
|
`--no-verify` turns off the _post-write_ check — the one that proves end to end that
|
|
26
30
|
Claude Code reaches the gateway. It does not affect the pre-write key check.
|
|
27
31
|
|
|
28
|
-
The gateway passes
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
The gateway passes the agent's own login through. Without one it can never answer,
|
|
33
|
+
so `install` checks before the write (with `claude auth status` or `codex login
|
|
34
|
+
status`) and, when verification proves it, undoes the write and exits 9. A timeout
|
|
35
|
+
or any other verification failure only warns and keeps the config. The no-subscription
|
|
36
|
+
check and verification are skipped under `--no-verify`. For Claude Code an Anthropic
|
|
37
|
+
key (`--anthropic-key` or `ANTHROPIC_API_KEY`) can stand in for the login.
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
Without the agent's CLI on PATH, `install` stops before signing in, writes nothing,
|
|
40
|
+
and exits 10, even under `--no-verify` (or, for Claude Code, without an Anthropic
|
|
41
|
+
key). For Codex there is no stand-in: only the Codex CLI can send the ChatGPT login
|
|
42
|
+
the gateway forwards.
|
|
39
43
|
|
|
40
44
|
The dashboard prints this command for you (Add agent, or Reconnect on an existing
|
|
41
45
|
agent) and offers the key as a separate copy.
|
|
@@ -95,10 +99,10 @@ derive, so `login` asks for `--app <url>` instead of guessing.
|
|
|
95
99
|
`--print` renders the config instead of writing it, with the key masked. `--help`
|
|
96
100
|
lists the rest.
|
|
97
101
|
|
|
98
|
-
`--client <name>` picks which agent to configure
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
`--client <name>` picks which agent to configure: `claude-code` (the default) or
|
|
103
|
+
`codex`. An unsupported name is refused rather than defaulted, so it never writes
|
|
104
|
+
the wrong agent's file by mistake. `uninstall` also takes `--client` to know whose
|
|
105
|
+
file to revert.
|
|
102
106
|
|
|
103
107
|
`install` reports onboarding events to AI21's product analytics (Amplitude), so we can
|
|
104
108
|
see where setup fails: when it started, then whether it completed or at which step it
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CodingAgent, Warning } from "../types.js";
|
|
2
|
+
/** Pure, so tests pass the shadowing file as data rather than write one. */
|
|
3
|
+
export declare function claudeWarnings(processEnv: Record<string, string | undefined>, localOverride: {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly agentId?: string;
|
|
6
|
+
} | undefined): Warning[];
|
|
7
|
+
export declare const claudeCode: CodingAgent;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Claude Code: `env` keys in `settings.json`, checked with `claude auth status`, verified with `claude -p`. */
|
|
2
|
+
import { findOnPath } from "../../process.js";
|
|
3
|
+
import { revertConfig } from "./revert.js";
|
|
4
|
+
import { resolvePaths, shadowingLocalConfig, writeConfig } from "./settings.js";
|
|
5
|
+
import { ccSettings, ccSettingsEnv } from "./snippets.js";
|
|
6
|
+
import { checkClaudeLogin } from "./status.js";
|
|
7
|
+
import { CLAUDE_COMMAND, resolveAnthropicKey, verify } from "./verify.js";
|
|
8
|
+
const text = {
|
|
9
|
+
// Predates the agent-neutral outcome; `--json` consumers already match on it.
|
|
10
|
+
noSubscriptionOutcome: "no-claude-credential",
|
|
11
|
+
noSubscription: {
|
|
12
|
+
"logged-out": {
|
|
13
|
+
headline: "No Claude subscription detected.",
|
|
14
|
+
nextStep: "If you have one, run `/login` inside `claude`, then re-run this command. Otherwise, subscribe to Claude.",
|
|
15
|
+
jsonReason: "no_claude_subscription",
|
|
16
|
+
telemetryReason: "agent not logged in",
|
|
17
|
+
},
|
|
18
|
+
"key-rejected": {
|
|
19
|
+
headline: "Anthropic rejected your API key.",
|
|
20
|
+
nextStep: "Check ANTHROPIC_API_KEY (or --anthropic-key), or unset it and run `/login` inside `claude`, then re-run this command.",
|
|
21
|
+
jsonReason: "anthropic_key_rejected",
|
|
22
|
+
telemetryReason: "upstream credential rejected",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
verifiedVia: {
|
|
26
|
+
"claude-cli": "`claude -p`",
|
|
27
|
+
"direct-ping": "a direct request",
|
|
28
|
+
},
|
|
29
|
+
skippedBecause: "no Anthropic credential was available",
|
|
30
|
+
notInstalled: {
|
|
31
|
+
message: "The Claude Code CLI was not found. The AI21 gateway currently supports only the Claude Code CLI; install it to use the gateway, then re-run this command.",
|
|
32
|
+
jsonOutcome: "no-claude-cli",
|
|
33
|
+
// Kept apart from `no_claude_subscription` so a funnel can split them.
|
|
34
|
+
jsonReason: "claude_code_cli_not_installed",
|
|
35
|
+
telemetryReason: "agent cli not installed",
|
|
36
|
+
},
|
|
37
|
+
checkingLogin: "Checking your Claude login…",
|
|
38
|
+
loginFound: "Claude login found",
|
|
39
|
+
};
|
|
40
|
+
/** Pure, so tests pass the shadowing file as data rather than write one. */
|
|
41
|
+
export function claudeWarnings(processEnv, localOverride) {
|
|
42
|
+
const found = [];
|
|
43
|
+
if (processEnv.ANTHROPIC_API_KEY !== undefined && processEnv.ANTHROPIC_API_KEY !== "") {
|
|
44
|
+
found.push({
|
|
45
|
+
code: "anthropic-api-key-set",
|
|
46
|
+
// It shadows the claude.ai login and surfaces as a 401 from the gateway,
|
|
47
|
+
// which reads as "the CLI wrote a bad config" rather than "unset this".
|
|
48
|
+
message: "ANTHROPIC_API_KEY is set in your environment. It overrides the credential Claude Code manages and can cause 401s through the gateway — unset it if requests start failing.",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (localOverride !== undefined) {
|
|
52
|
+
const { path, agentId } = localOverride;
|
|
53
|
+
found.push({
|
|
54
|
+
code: "shadowed-by-local-config",
|
|
55
|
+
message: `${path} also sets Claude Code's env, and it is read after this file — so it wins. ` +
|
|
56
|
+
(agentId === undefined
|
|
57
|
+
? "Requests will not use the agent configured here."
|
|
58
|
+
: `Requests will report as '${agentId}', not the agent configured here.`) +
|
|
59
|
+
" Remove its env block, or move your override into this file.",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return found;
|
|
63
|
+
}
|
|
64
|
+
export const claudeCode = {
|
|
65
|
+
id: "claude-code",
|
|
66
|
+
kind: "claude_code",
|
|
67
|
+
displayName: "Claude Code",
|
|
68
|
+
configLabel: "settings.json",
|
|
69
|
+
targets: ["user", "repo"],
|
|
70
|
+
verifyFlags: ["anthropic-key"],
|
|
71
|
+
checkInstalled(ctx, deps) {
|
|
72
|
+
// An Anthropic key alone is enough: it serves any other client, and the direct ping verifies with it.
|
|
73
|
+
if (findOnPath(CLAUDE_COMMAND, deps.lookup) !== undefined)
|
|
74
|
+
return { kind: "present" };
|
|
75
|
+
return resolveAnthropicKey({ anthropicKey: ctx.upstreamKey, processEnv: ctx.processEnv }) === undefined
|
|
76
|
+
? { kind: "missing" }
|
|
77
|
+
: { kind: "present" };
|
|
78
|
+
},
|
|
79
|
+
resolvePaths(target, env) {
|
|
80
|
+
// `claude` must run where the file we wrote is the one that wins: a project-local
|
|
81
|
+
// settings.json outranks the home one, so a `--user` config is verified from home.
|
|
82
|
+
return { ...resolvePaths(target, env), verifyCwd: target === "user" ? env.home : env.cwd };
|
|
83
|
+
},
|
|
84
|
+
preview(inputs) {
|
|
85
|
+
return { text: ccSettings(inputs), json: { settings: { env: ccSettingsEnv(inputs) } } };
|
|
86
|
+
},
|
|
87
|
+
write(paths, inputs, options) {
|
|
88
|
+
return writeConfig(paths, ccSettingsEnv(inputs), options);
|
|
89
|
+
},
|
|
90
|
+
revert: revertConfig,
|
|
91
|
+
redact(value) {
|
|
92
|
+
return value.replace(/(x-ai21-key:\s*)\S+/gi, "$1****");
|
|
93
|
+
},
|
|
94
|
+
warnings(paths, processEnv) {
|
|
95
|
+
return claudeWarnings(processEnv, shadowingLocalConfig(paths));
|
|
96
|
+
},
|
|
97
|
+
async checkSubscription(paths, deps) {
|
|
98
|
+
switch (await checkClaudeLogin(paths.verifyCwd, deps)) {
|
|
99
|
+
case "logged-in":
|
|
100
|
+
return { kind: "present" };
|
|
101
|
+
case "logged-out":
|
|
102
|
+
return { kind: "missing", reason: "logged-out" };
|
|
103
|
+
case "inconclusive":
|
|
104
|
+
return { kind: "inconclusive" };
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
verify(ctx, deps) {
|
|
108
|
+
return verify({ ...ctx, anthropicKey: ctx.upstreamKey }, deps);
|
|
109
|
+
},
|
|
110
|
+
text,
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agents/claude-code/index.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,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AE,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;IAED,IAAI;CACL,CAAC"}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* One real request through the gateway, to prove the written config works and flip
|
|
3
|
-
* the agent's `used` latch. Three tiers, because the CLI holds no Anthropic
|
|
4
|
-
* credential and the gateway requires one: `claude -p` if it is on PATH, else a
|
|
5
|
-
* direct ping if a key is available, else skip.
|
|
6
|
-
*
|
|
7
|
-
* Two invariants: exactly one request is fired — a winning tier means no later tier
|
|
8
|
-
* runs — and only a definite missing-credential result changes the exit code. A
|
|
9
|
-
* timeout or unrecognised failure stays a warning, so a flaky network never undoes a
|
|
10
|
-
* good write.
|
|
11
|
-
*/
|
|
12
|
-
import { type ResolvedUrls } from "../../args.js";
|
|
13
|
-
import type { AgentDeps } from "../types.js";
|
|
1
|
+
import type { AgentDeps, VerifyContext as AgentVerifyContext, VerifyOutcome } from "../types.js";
|
|
14
2
|
export declare const CLAUDE_COMMAND = "claude";
|
|
15
3
|
export declare const CLAUDE_PROMPT = "ai21-gateway CLI connectivity check \u2014 reply with OK and nothing else.";
|
|
16
4
|
export declare const PING_PATH = "/v1/messages";
|
|
@@ -31,43 +19,15 @@ export declare const PING_BODY: {
|
|
|
31
19
|
readonly content: "Hello through the gateway";
|
|
32
20
|
}];
|
|
33
21
|
};
|
|
34
|
-
export type VerifyVia = "claude-cli" | "direct-ping";
|
|
35
22
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
23
|
+
* `via` is `claude-cli` or `direct-ping`. A `no-subscription` reason is `logged-out`
|
|
24
|
+
* (`claude` has no login at all) or `key-rejected` (Anthropic itself refused the key
|
|
25
|
+
* the direct ping sent).
|
|
38
26
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export type VerifyOutcome = {
|
|
42
|
-
readonly kind: "disabled";
|
|
43
|
-
} | {
|
|
44
|
-
readonly kind: "skipped";
|
|
45
|
-
readonly hint: string;
|
|
46
|
-
} | {
|
|
47
|
-
readonly kind: "passed";
|
|
48
|
-
readonly via: VerifyVia;
|
|
49
|
-
} | {
|
|
50
|
-
readonly kind: "failed";
|
|
51
|
-
readonly via: VerifyVia;
|
|
52
|
-
readonly reason: string;
|
|
53
|
-
} | {
|
|
54
|
-
readonly kind: "no-claude-credential";
|
|
55
|
-
readonly via: VerifyVia;
|
|
56
|
-
readonly reason: MissingCredential;
|
|
57
|
-
};
|
|
58
|
-
export interface VerifyContext {
|
|
59
|
-
readonly urls: ResolvedUrls;
|
|
60
|
-
readonly agentId: string;
|
|
61
|
-
readonly ai21Key: string;
|
|
62
|
-
readonly userId?: string | undefined;
|
|
27
|
+
/** Claude Code's verification also takes `--anthropic-key`, for the direct-ping tier. */
|
|
28
|
+
export interface VerifyContext extends AgentVerifyContext {
|
|
63
29
|
/** `--anthropic-key`, which outranks the environment. */
|
|
64
30
|
readonly anthropicKey?: string | undefined;
|
|
65
|
-
readonly processEnv: Record<string, string | undefined>;
|
|
66
|
-
/**
|
|
67
|
-
* Where to run `claude`: the directory in which the file we wrote is the one that
|
|
68
|
-
* wins. Home for `--user`, since a project-local settings.json outranks it.
|
|
69
|
-
*/
|
|
70
|
-
readonly cwd: string;
|
|
71
31
|
}
|
|
72
32
|
/** What the direct ping would send: `--anthropic-key`, else a non-empty ANTHROPIC_API_KEY. */
|
|
73
33
|
export declare function resolveAnthropicKey(ctx: Pick<VerifyContext, "anthropicKey" | "processEnv">): string | undefined;
|
|
@@ -82,7 +82,7 @@ async function viaClaude(executable, ctx, deps) {
|
|
|
82
82
|
return { kind: "passed", via: "claude-cli" };
|
|
83
83
|
// Printed before any request is made, so it cannot be a gateway or network symptom.
|
|
84
84
|
if (!result.timedOut && result.code !== null && NOT_LOGGED_IN.test(result.output)) {
|
|
85
|
-
return { kind: "no-
|
|
85
|
+
return { kind: "no-subscription", via: "claude-cli", reason: "logged-out" };
|
|
86
86
|
}
|
|
87
87
|
const failed = (reason) => ({ kind: "failed", via: "claude-cli", reason });
|
|
88
88
|
if (result.timedOut) {
|
|
@@ -219,7 +219,7 @@ async function viaDirectPing(anthropicKey, ctx, deps) {
|
|
|
219
219
|
if (response.ok)
|
|
220
220
|
return { kind: "passed", via: "direct-ping" };
|
|
221
221
|
if (response.status === 401 && isAnthropicAuthError((await response.text?.()) ?? "")) {
|
|
222
|
-
return { kind: "no-
|
|
222
|
+
return { kind: "no-subscription", via: "direct-ping", reason: "key-rejected" };
|
|
223
223
|
}
|
|
224
224
|
const hint = STATUS_HINTS[response.status];
|
|
225
225
|
const note = response.status === 401 ? environmentNote(ctx) : "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/agents/claude-code/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/agents/claude-code/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AACvC;;;wDAGwD;AACxD,MAAM,CAAC,MAAM,aAAa,GAAG,uEAAuE,CAAC;AACrG,MAAM,CAAC,MAAM,SAAS,GAAG,cAAc,CAAC;AAExC,uFAAuF;AACvF,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAE3C;iFACiF;AACjF,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,SAAS,cAAc,QAAQ,aAAa,UAAU,GAAG,oBAAoB,CAAC;AACvF,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC,iFAAiF;AACjF,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C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC;IAC3G,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,MAAM,CAAC,qCAAqC,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC;QAChF,CAAC;QAED,0EAA0E;QAC1E,wEAAwE;QACxE,OAAO,MAAM,CAAC,uCAAuC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAkB,EAAE,IAAe;IAC9D,MAAM,UAAU,GAAG,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAEtE,MAAM,YAAY,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO,aAAa,CAAC,YAAY,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAE9E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ConfigPaths } from "../../fs/safeFile.js";
|
|
2
|
+
import type { ConfigOutcome, RevertOptions, RevertOutcome, SnippetInputs } from "../types.js";
|
|
3
|
+
import { type Scan } from "./toml.js";
|
|
4
|
+
/** What a conflict shows instead of an AI21 key. */
|
|
5
|
+
export declare const REDACTED = "****";
|
|
6
|
+
export declare const MARKER_BEGIN = "# >>> AI21 Gateway (managed by ai21-gateway; `ai21-gateway uninstall --client codex` removes it)";
|
|
7
|
+
export declare const MARKER_END = "# <<< AI21 Gateway";
|
|
8
|
+
/** `CODEX_HOME` wins, as it does for Codex; a relative one is resolved against the cwd, as Codex does. */
|
|
9
|
+
export declare function codexHome(env: {
|
|
10
|
+
readonly home: string;
|
|
11
|
+
readonly cwd: string;
|
|
12
|
+
readonly processEnv: Record<string, string | undefined>;
|
|
13
|
+
}): string;
|
|
14
|
+
export declare function resolveCodexPaths(dir: string): ConfigPaths;
|
|
15
|
+
/** The agent id our block names, for the uninstall guard. */
|
|
16
|
+
export declare function storedAgentId(scanned: Scan): string | undefined;
|
|
17
|
+
export declare function writeCodexConfig(paths: ConfigPaths, inputs: SnippetInputs, options: {
|
|
18
|
+
readonly force: boolean;
|
|
19
|
+
}): ConfigOutcome;
|
|
20
|
+
export declare function revertCodexConfig(paths: ConfigPaths, options: RevertOptions): RevertOutcome;
|