@agenthippo-ai/agenthippo 0.2.3-dataplane → 1.110.9
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/out/analytics/dashboard/provider.js +13 -2
- package/out/analytics/dashboard/webview/panel.js +3 -2
- package/out/analytics/identity.js +0 -0
- package/out/analytics/service.js +23 -25
- package/out/analytics/sessionEvents.js +98 -23
- package/out/auth/authBaseUrl.js +59 -0
- package/out/auth/bootstrapApply.js +9 -10
- package/out/auth/brokerClient.js +48 -14
- package/out/auth/provider.js +8 -21
- package/out/auth/sessionStore.js +3 -40
- package/out/auth/signInFlow.js +2 -1
- package/out/auth-broker/config.js +50 -5
- package/out/auth-broker/server.js +122 -26
- package/out/auth-broker/store.js +25 -24
- package/out/authority/warrant.js +206 -0
- package/out/branding.js +27 -1
- package/out/cli/commands/conformance.js +249 -0
- package/out/cli/commands/data-plane.js +67 -0
- package/out/cli/commands/deploy.js +1 -0
- package/out/cli/commands/gateway.js +4 -0
- package/out/cli/commands/pack.js +182 -3
- package/out/cli/commands/sandbox.js +332 -0
- package/out/cli/commands/serve.js +875 -52
- package/out/cli/commands/store.js +12 -4
- package/out/cli/data-plane/gateway.js +28 -5
- package/out/cli/data-plane/index.js +17 -2
- package/out/cli/data-plane/registry.js +9 -0
- package/out/cli/data-plane/remote.js +106 -0
- package/out/cli/data-plane/sidecar.js +161 -0
- package/out/cli/deploy/layers/identity.js +85 -4
- package/out/cli/deploy-init.js +89 -24
- package/out/cli/deps.js +106 -2
- package/out/cli/idp-init.js +35 -0
- package/out/cli/index.js +155 -16
- package/out/cli/pack-install-ref.js +15 -0
- package/out/cli/pack-loader.js +8 -1
- package/out/cli/pack-runtime.js +61 -0
- package/out/cli/runtime.js +35 -1
- package/out/cli/serve-hardening.js +80 -3
- package/out/cli/utils.js +12 -1
- package/out/engines/base.js +32 -3
- package/out/engines/claude.js +33 -15
- package/out/engines/codex.js +110 -26
- package/out/engines/custom.js +8 -0
- package/out/evidence/sessionShip.js +610 -0
- package/out/extension.js +11 -2
- package/out/gateway/bridge.js +40 -2
- package/out/gateway/client.js +34 -1
- package/out/gateway/installSource.js +68 -0
- package/out/gateway/lifecycle.js +185 -51
- package/out/gateway/outboundPaths.js +4 -1
- package/out/gateway/secretsPreflight.js +90 -0
- package/out/gateway/service.js +7 -2
- package/out/headless/index.js +17 -1
- package/out/live-e2e/mcp-demo/server.mjs +32 -0
- package/out/mcp.js +30 -0
- package/out/pack/caps.js +271 -0
- package/out/pack/governor.js +309 -0
- package/out/pack/lease-schema.js +270 -0
- package/out/pack/lease.js +640 -0
- package/out/pack/reconcile.js +217 -0
- package/out/pack/signature.js +839 -0
- package/out/remote/handleRemoteChat.js +44 -3
- package/out/remote/remoteTrust.js +277 -0
- package/out/remote/serveClient.js +52 -5
- package/out/runner/host.js +131 -0
- package/out/runner/protocol.js +108 -0
- package/out/runner/remoteEngine.js +130 -0
- package/out/runtime/interfaces/edit-tracker.js +2 -0
- package/out/runtime/vscode/vscode-edit-tracker.js +2 -0
- package/out/sandbox/containerDriver.js +570 -0
- package/out/sandbox/processDriver.js +315 -0
- package/out/sandbox/sandboxRunner.js +191 -0
- package/out/sandbox/support.js +301 -0
- package/out/sandbox/types.js +55 -0
- package/out/scripts/agentide-litellm.sh +67 -5
- package/out/scripts/agentide_litellm_hooks_v1.py +182 -21
- package/out/scripts/analytics/agentide-litellm-otel.config.yaml +94 -132
- package/out/scripts/analytics/setup-analytics.ps1 +37 -13
- package/out/scripts/analytics/setup-analytics.sh +93 -13
- package/out/scripts/analytics/start-analytics.sh +86 -14
- package/out/scripts/gateway/setup-gateway.sh +72 -32
- package/out/shared/models.js +11 -110
- package/out/spotlight/install.js +7 -1
- package/out/store/index.js +41 -10
- package/out/sync.js +3 -1
- package/out/test/analytics.test.js +162 -23
- package/out/test/auth-baseurl.test.js +132 -0
- package/out/test/auth-bootstrapApply.test.js +27 -6
- package/out/test/auth-broker-hardening.test.js +227 -0
- package/out/test/auth-broker.test.js +59 -9
- package/out/test/branding.test.js +13 -0
- package/out/test/caps-governor.test.js +455 -0
- package/out/test/codex-new-file-survival.test.js +119 -0
- package/out/test/configuration-scopes.test.js +131 -0
- package/out/test/data-plane.test.js +67 -0
- package/out/test/deploy-init.test.js +40 -0
- package/out/test/gateway-client.test.js +28 -0
- package/out/test/gateway-install-source.test.js +111 -0
- package/out/test/gateway-lifecycle.test.js +1 -1
- package/out/test/gateway-outbound.test.js +7 -0
- package/out/test/gateway-secrets-preflight.test.js +127 -0
- package/out/test/gateway-session-routing.test.js +18 -0
- package/out/test/governor-hardening.test.js +217 -0
- package/out/test/headless-sync.test.js +22 -0
- package/out/test/lease-signature.test.js +357 -0
- package/out/test/lease-trust-root.test.js +273 -0
- package/out/test/lease-validation.test.js +169 -0
- package/out/test/lease.test.js +114 -0
- package/out/test/mcp.test.js +27 -1
- package/out/test/pack-admission.test.js +216 -0
- package/out/test/pack-digest-parity.test.js +140 -0
- package/out/test/pack-reconcile.test.js +183 -0
- package/out/test/pack-signature-artifact.test.js +103 -0
- package/out/test/pack-signature.test.js +176 -0
- package/out/test/pack-trust-root.test.js +202 -0
- package/out/test/remote-trust.test.js +242 -0
- package/out/test/runner-protocol.test.js +249 -0
- package/out/test/sandbox-driver.test.js +553 -0
- package/out/test/sandbox-hardening.test.js +395 -0
- package/out/test/sandbox-runner.test.js +343 -0
- package/out/test/serve-hardening.test.js +45 -6
- package/out/test/serveClient.test.js +6 -5
- package/out/test/sessionShip.test.js +560 -0
- package/out/test/spotlightPublish.test.js +28 -0
- package/out/test/store-install-safe.test.js +69 -0
- package/out/test/tls-bypass.test.js +90 -0
- package/out/test/warrant.test.js +138 -0
- package/out/utils.js +46 -9
- package/package.json +1 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DEPRECATED_SANDBOX_ENV_ALIASES = void 0;
|
|
40
|
+
exports.dockerExec = dockerExec;
|
|
41
|
+
exports.alignSandboxWorkspaceOwnership = alignSandboxWorkspaceOwnership;
|
|
42
|
+
exports.resolveSandboxImageUser = resolveSandboxImageUser;
|
|
43
|
+
exports.ensureSandboxStateDir = ensureSandboxStateDir;
|
|
44
|
+
exports.sandboxScriptArg = sandboxScriptArg;
|
|
45
|
+
exports.applyDeprecatedSandboxEnvAliases = applyDeprecatedSandboxEnvAliases;
|
|
46
|
+
exports.loadWarrantKeypair = loadWarrantKeypair;
|
|
47
|
+
exports.mintSandboxInferenceWarrant = mintSandboxInferenceWarrant;
|
|
48
|
+
/**
|
|
49
|
+
* Small pieces the sandbox layer needs at its composition root: the container-runtime shim and
|
|
50
|
+
* the per-sandbox model token (blocker C — the model key leaves the engine's reach).
|
|
51
|
+
*/
|
|
52
|
+
const node_child_process_1 = require("node:child_process");
|
|
53
|
+
const fs = __importStar(require("node:fs"));
|
|
54
|
+
const path = __importStar(require("node:path"));
|
|
55
|
+
const warrant_1 = require("../authority/warrant");
|
|
56
|
+
/** Runs `docker <args>`; never throws — the driver decides what a non-zero code means. */
|
|
57
|
+
function dockerExec(args) {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
(0, node_child_process_1.execFile)('docker', args, { maxBuffer: 8 << 20 }, (err, stdout, stderr) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
const code = typeof err.code === 'number' ? err.code : 1;
|
|
62
|
+
resolve({ stdout: `${stdout ?? ''}${stderr ?? ''}`, code });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolve({ stdout: stdout ?? '', stderr: stderr ?? '', code: 0 });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Make the shared workspace writable BY THE SANDBOX, without giving the sandbox root.
|
|
71
|
+
*
|
|
72
|
+
* A sandbox image runs non-root (the runtime image is uid 10001) while serve runs as root — it has
|
|
73
|
+
* to, it drives the container runtime. So every file serve syncs into the bind-mounted workspace
|
|
74
|
+
* lands root-owned, and the sandbox's own pack sync then dies on `EACCES: unlink …/SKILL.md`. Until
|
|
75
|
+
* now that was a manual `chown -R 10001:10001 <workspace>` AFTER serve booted, which is exactly
|
|
76
|
+
* the kind of undocumented step a deployment forgets.
|
|
77
|
+
*
|
|
78
|
+
* The uid is ASKED OF THE IMAGE rather than hardcoded — `Config.User` is often a name ("agent")
|
|
79
|
+
* that only resolves inside the image, so `id -u` in the image is the only honest source. The
|
|
80
|
+
* alternative fix, `--user <serve uid>`, would make the sandbox run as root inside the container and
|
|
81
|
+
* trade an ownership problem for a weaker boundary; this keeps the sandbox non-root.
|
|
82
|
+
*
|
|
83
|
+
* Best effort by design: a failure here is a warning with the exact command to run, never a boot
|
|
84
|
+
* failure — an operator whose workspace is already aligned must not be blocked by it.
|
|
85
|
+
*/
|
|
86
|
+
async function alignSandboxWorkspaceOwnership(opts) {
|
|
87
|
+
const hostDirs = opts.writable.map((e) => (e.includes(':') ? e.slice(0, e.indexOf(':')) : e));
|
|
88
|
+
if (hostDirs.length === 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const owner = await resolveSandboxImageUser(opts.exec, opts.image);
|
|
92
|
+
if (!owner) {
|
|
93
|
+
opts.logger?.warn(`[Sandbox] could not determine the sandbox image's uid; if turns fail with EACCES in the workspace, run: chown -R <image-uid> ${hostDirs.join(' ')}`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// A root image needs no alignment: it can already write anything serve wrote.
|
|
97
|
+
if (owner.uid === 0) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const { uid, gid } = owner;
|
|
101
|
+
for (const dir of hostDirs) {
|
|
102
|
+
try {
|
|
103
|
+
const changed = chownTree(dir, uid, gid);
|
|
104
|
+
if (changed > 0) {
|
|
105
|
+
opts.logger?.info(`[Sandbox] aligned ${changed} path(s) under ${dir} to the sandbox image's uid ${uid}:${gid}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
opts.logger?.warn(`[Sandbox] could not align ownership of ${dir} for the sandbox (uid ${uid}): ${err instanceof Error ? err.message : String(err)}. Run: chown -R ${uid}:${gid} ${dir}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The uid/gid the sandbox image actually runs as. Resolved once per boot and reused — it costs two
|
|
115
|
+
* container starts, and both the workspace alignment and every per-session state dir need it.
|
|
116
|
+
*/
|
|
117
|
+
async function resolveSandboxImageUser(exec, image) {
|
|
118
|
+
const uid = await imageId(exec, image, '-u');
|
|
119
|
+
if (uid === undefined) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return { uid, gid: (await imageId(exec, image, '-g')) ?? uid };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create this session's state directory, owned by the sandbox so it can write there.
|
|
126
|
+
*
|
|
127
|
+
* The directory outlives the sandbox on purpose — it holds `provider-sessions/` and the engines'
|
|
128
|
+
* rollout files, which is the only reason a session can resume after its sandbox is reaped.
|
|
129
|
+
*/
|
|
130
|
+
function ensureSandboxStateDir(dir, owner) {
|
|
131
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
132
|
+
if (owner && owner.uid !== 0) {
|
|
133
|
+
try {
|
|
134
|
+
chownTree(dir, owner.uid, owner.gid);
|
|
135
|
+
}
|
|
136
|
+
catch { /* best effort — warned at boot */ }
|
|
137
|
+
}
|
|
138
|
+
return dir;
|
|
139
|
+
}
|
|
140
|
+
/** `id -u` / `id -g` AS THE IMAGE'S DEFAULT USER — the only place a name like "agent" resolves. */
|
|
141
|
+
async function imageId(exec, image, flag) {
|
|
142
|
+
const res = await exec(['run', '--rm', '--network', 'none', '--entrypoint', 'id', image, flag]);
|
|
143
|
+
if (res.code !== 0) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const parsed = Number.parseInt(res.stdout.trim(), 10);
|
|
147
|
+
return Number.isInteger(parsed) ? parsed : undefined;
|
|
148
|
+
}
|
|
149
|
+
/** Recursive chown, touching only what is not already owned by the sandbox. Returns how many. */
|
|
150
|
+
function chownTree(dir, uid, gid) {
|
|
151
|
+
let changed = 0;
|
|
152
|
+
const visit = (p) => {
|
|
153
|
+
// lstat/lchown: a symlink is retargeted by chown, so follow nothing.
|
|
154
|
+
const st = fs.lstatSync(p);
|
|
155
|
+
if (st.uid !== uid || st.gid !== gid) {
|
|
156
|
+
fs.lchownSync(p, uid, gid);
|
|
157
|
+
changed++;
|
|
158
|
+
}
|
|
159
|
+
if (st.isDirectory()) {
|
|
160
|
+
for (const entry of fs.readdirSync(p)) {
|
|
161
|
+
visit(path.join(p, entry));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
if (!fs.existsSync(dir)) {
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
visit(dir);
|
|
169
|
+
return changed;
|
|
170
|
+
}
|
|
171
|
+
// REMOVED (2026-07-29): `mintSandboxModelToken` / `verifySandboxModelToken`.
|
|
172
|
+
//
|
|
173
|
+
// They HMAC'd the upstream provider key and truncated the result to 32 hex characters, and their
|
|
174
|
+
// own docstring conceded that the "spend cap" they claimed to carry was never actually encoded in
|
|
175
|
+
// the token, let alone enforced. Nothing in serve used them — the shipped path is the ES256
|
|
176
|
+
// warrant below (`mintSandboxInferenceWarrant`), which the inference proxy verifies with a public
|
|
177
|
+
// key it cannot mint with. A second, weaker credential format that looks like it does the same job
|
|
178
|
+
// is a liability: it invites a future call site to reach for the one with no signature and no
|
|
179
|
+
// audience separation. The conformance `cost-cap` check now exercises the warrant path instead.
|
|
180
|
+
// -----------------------------------------------------------------------------
|
|
181
|
+
// Warrant-based sandbox model tokens (the shape the inference proxy verifies)
|
|
182
|
+
// -----------------------------------------------------------------------------
|
|
183
|
+
/**
|
|
184
|
+
* Load the authority plane's signing key, or generate an ephemeral one.
|
|
185
|
+
*
|
|
186
|
+
* `AGENTHIPPO_WARRANT_PRIVATE_KEY` (PKCS#8 PEM) + `AGENTHIPPO_WARRANT_KID` pin a stable key so
|
|
187
|
+
* gateways can be configured with the matching public key. With neither set, serve generates a
|
|
188
|
+
* keypair at boot and logs the public key: fine for a single-node dev run, useless across a
|
|
189
|
+
* restart — which is the honest tradeoff, not a silent one.
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Virtual filesystem roots used by single-file builds. Paths under these are reported by
|
|
193
|
+
* `process.argv[1]` but are not real files a child process can be pointed at — and crucially the
|
|
194
|
+
* runtime mounts them, so `fs.existsSync` returns TRUE and cannot be used to tell them apart.
|
|
195
|
+
*/
|
|
196
|
+
const VIRTUAL_SCRIPT_ROOTS = ['/$bunfs', '/snapshot'];
|
|
197
|
+
/**
|
|
198
|
+
* Normalize a script path for the virtual-root check: Windows separators become `/`, and a drive
|
|
199
|
+
* letter is stripped. `pkg` on Windows reports `C:\snapshot\app\index.js`, which the bare
|
|
200
|
+
* `startsWith('/snapshot')` test missed. serve is effectively Linux-only so this has never bitten,
|
|
201
|
+
* but the check costs one line and the failure it prevents (`unknown command 'C:\snapshot\…'`,
|
|
202
|
+
* every sandbox dead at boot) is opaque.
|
|
203
|
+
*/
|
|
204
|
+
function normalizeScriptPath(script) {
|
|
205
|
+
return script.replace(/\\/g, '/').replace(/^[A-Za-z]:/, '');
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The script argument to pass when re-invoking ourselves to launch a sandbox.
|
|
209
|
+
*
|
|
210
|
+
* `node <script> sandbox …` needs the script path; a compiled single-file binary must be invoked as
|
|
211
|
+
* `<binary> sandbox …` with no script at all. Passing the virtual path made the child treat it as
|
|
212
|
+
* the subcommand (`unknown command '/$bunfs/root/index.js'`), so every tier-0 sandbox died at boot.
|
|
213
|
+
*/
|
|
214
|
+
function sandboxScriptArg(argv = process.argv, execPath = process.execPath) {
|
|
215
|
+
const script = argv[1];
|
|
216
|
+
if (!script || script === execPath) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
const normalized = normalizeScriptPath(script);
|
|
220
|
+
if (VIRTUAL_SCRIPT_ROOTS.some((root) => normalized.startsWith(root))) {
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
return [script];
|
|
224
|
+
}
|
|
225
|
+
// -----------------------------------------------------------------------------
|
|
226
|
+
// cell → sandbox migration: deprecated environment aliases
|
|
227
|
+
// -----------------------------------------------------------------------------
|
|
228
|
+
/**
|
|
229
|
+
* Environment variables renamed by the cell → sandbox migration, old name → new name.
|
|
230
|
+
*
|
|
231
|
+
* Only variables that actually CHANGE BEHAVIOUR are listed. An operator env file still saying
|
|
232
|
+
* `AGENTHIPPO_CELL_TIER=2` would otherwise select nothing at all — the deployment would come up
|
|
233
|
+
* one tier weaker than asked for, with no error anywhere. Silent degradation is the failure mode
|
|
234
|
+
* this migration must not have; a loud warning plus the old value continuing to work is.
|
|
235
|
+
*/
|
|
236
|
+
exports.DEPRECATED_SANDBOX_ENV_ALIASES = [
|
|
237
|
+
['AGENTHIPPO_CELL', 'AGENTHIPPO_SANDBOX'],
|
|
238
|
+
['AGENTHIPPO_CELL_TIER', 'AGENTHIPPO_SANDBOX_TIER'],
|
|
239
|
+
['AGENTHIPPO_CELL_SOCKET_DIR', 'AGENTHIPPO_SANDBOX_SOCKET_DIR'],
|
|
240
|
+
['AGENTHIPPO_CELL_STRICT_EGRESS', 'AGENTHIPPO_SANDBOX_STRICT_EGRESS'],
|
|
241
|
+
['AGENTHIPPO_CELL_ALLOW_PROVIDER_KEY', 'AGENTHIPPO_SANDBOX_ALLOW_PROVIDER_KEY'],
|
|
242
|
+
];
|
|
243
|
+
/** One warning per process per variable — a per-turn log would bury it. */
|
|
244
|
+
const warnedAliases = new Set();
|
|
245
|
+
/**
|
|
246
|
+
* Accept the pre-rename `AGENTHIPPO_CELL*` spellings, loudly.
|
|
247
|
+
*
|
|
248
|
+
* A NEW name already present always wins: an operator who has migrated is never overridden by a
|
|
249
|
+
* stale variable left in a shell profile. Returns the aliases that were applied, for tests.
|
|
250
|
+
*/
|
|
251
|
+
function applyDeprecatedSandboxEnvAliases(env = process.env, warn = (m) => console.warn(m), once = warnedAliases) {
|
|
252
|
+
const applied = [];
|
|
253
|
+
for (const [oldName, newName] of exports.DEPRECATED_SANDBOX_ENV_ALIASES) {
|
|
254
|
+
const legacy = env[oldName];
|
|
255
|
+
if (legacy === undefined || legacy === '') {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (env[newName] !== undefined && env[newName] !== '') {
|
|
259
|
+
if (!once.has(oldName)) {
|
|
260
|
+
once.add(oldName);
|
|
261
|
+
warn(`[Sandbox] DEPRECATED: ${oldName} is set but ${newName} is also set — using ${newName} ` +
|
|
262
|
+
`and IGNORING ${oldName}. Remove ${oldName}; it was renamed in the cell → sandbox migration.`);
|
|
263
|
+
}
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
env[newName] = legacy;
|
|
267
|
+
applied.push(newName);
|
|
268
|
+
if (!once.has(oldName)) {
|
|
269
|
+
once.add(oldName);
|
|
270
|
+
warn(`[Sandbox] DEPRECATED: ${oldName} was renamed to ${newName} in the cell → sandbox migration. ` +
|
|
271
|
+
`The old value is being honoured for now, but it will stop working — set ${newName}=${legacy} instead.`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return applied;
|
|
275
|
+
}
|
|
276
|
+
// Applied at import so the aliases are in place before anything reads the new names. This module is
|
|
277
|
+
// on the import path of every sandbox composition root (serve and the `sandbox` subcommand both
|
|
278
|
+
// pull `dockerExec` / `sandboxScriptArg` / `loadWarrantKeypair` from here), and the alternative —
|
|
279
|
+
// a call the composition root must remember to make — is exactly the kind of step a deployment
|
|
280
|
+
// forgets, which is the failure this exists to prevent.
|
|
281
|
+
applyDeprecatedSandboxEnvAliases();
|
|
282
|
+
function loadWarrantKeypair(logger) {
|
|
283
|
+
const pem = process.env.AGENTHIPPO_WARRANT_PRIVATE_KEY?.trim();
|
|
284
|
+
const kid = process.env.AGENTHIPPO_WARRANT_KID?.trim();
|
|
285
|
+
if (pem) {
|
|
286
|
+
const crypto = require('node:crypto');
|
|
287
|
+
const publicKeyPem = crypto.createPublicKey(pem).export({ type: 'spki', format: 'pem' }).toString();
|
|
288
|
+
return { privateKeyPem: pem, publicKeyPem, kid: kid || 'default' };
|
|
289
|
+
}
|
|
290
|
+
const generated = (0, warrant_1.generateWarrantKeypair)(kid);
|
|
291
|
+
logger?.info(`[Warrant] no AGENTHIPPO_WARRANT_PRIVATE_KEY — generated an ephemeral key (kid=${generated.kid}). Configure gateways with:\nGATEWAY_SANDBOX_WARRANT_KEYS=${JSON.stringify({ [generated.kid]: generated.publicKeyPem })}`);
|
|
292
|
+
return generated;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Mint the token a sandbox presents to the inference proxy: a signed, audience-bound warrant naming
|
|
296
|
+
* the end user (cost attribution), the sandbox (spend metering + replay defence), and the tier.
|
|
297
|
+
* The proxy verifies with a public key and can never mint one.
|
|
298
|
+
*/
|
|
299
|
+
function mintSandboxInferenceWarrant(key, claims) {
|
|
300
|
+
return (0, warrant_1.mintWarrant)({ ...claims, aud: 'inference' }, key);
|
|
301
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RevocationUnsupportedError = exports.SANDBOX_PROVIDER_KEY_ENV = exports.SANDBOX_TIER_ENV = void 0;
|
|
7
|
+
exports.sandboxHoldsProviderKey = sandboxHoldsProviderKey;
|
|
8
|
+
exports.isContainerSandbox = isContainerSandbox;
|
|
9
|
+
/**
|
|
10
|
+
* The tier the surrounding sandbox ACTUALLY delivers, declared by the driver that created it.
|
|
11
|
+
*
|
|
12
|
+
* Read by engines that sandbox themselves: an engine may only stand its own boundary down when
|
|
13
|
+
* something stronger already confines it. `AGENTHIPPO_SANDBOX=1` cannot answer that question —
|
|
14
|
+
* it says "inside a sandbox", and the tier-0 process driver is a sandbox that confines nothing.
|
|
15
|
+
* Set from the driver's own `tier`, never from the caller's spec, because the driver is the only
|
|
16
|
+
* thing that knows what boundary was really built.
|
|
17
|
+
*/
|
|
18
|
+
exports.SANDBOX_TIER_ENV = 'AGENTHIPPO_SANDBOX_TIER';
|
|
19
|
+
/**
|
|
20
|
+
* Set to `1` when this sandbox was handed a RAW PROVIDER KEY (the Cursor exception — see
|
|
21
|
+
* `processDriver.baseSandboxEnv`).
|
|
22
|
+
*
|
|
23
|
+
* The tier says how strong the surrounding boundary is; this says whether the credential invariant
|
|
24
|
+
* ("the sandbox holds no provider key") actually holds inside it. They are different claims and a
|
|
25
|
+
* deployment that discloses one while quietly violating the other is the failure this exists to
|
|
26
|
+
* prevent: an engine here can reach the provider directly, around the inference proxy's meter and
|
|
27
|
+
* around the per-sandbox warrant.
|
|
28
|
+
*/
|
|
29
|
+
exports.SANDBOX_PROVIDER_KEY_ENV = 'AGENTHIPPO_SANDBOX_PROVIDER_KEY';
|
|
30
|
+
/** True when this process was given a raw provider key despite running in a sandbox. */
|
|
31
|
+
function sandboxHoldsProviderKey(env = process.env) {
|
|
32
|
+
return env[exports.SANDBOX_PROVIDER_KEY_ENV] === '1';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* True only when a boundary stronger than the engine's own confinement surrounds this process.
|
|
36
|
+
*
|
|
37
|
+
* Absent or unparseable ⇒ false: an engine keeps its own sandbox rather than dropping it on a
|
|
38
|
+
* guess. The failure mode of guessing wrong in the other direction is an unconfined agent.
|
|
39
|
+
*/
|
|
40
|
+
function isContainerSandbox(env = process.env) {
|
|
41
|
+
return Number(env[exports.SANDBOX_TIER_ENV]) >= 2;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Thrown when a driver is asked for an enforcement it cannot actually deliver — e.g. narrowing a
|
|
45
|
+
* single route on the tier-0 `process` driver, which has no network boundary. Failing loudly
|
|
46
|
+
* beats a silent no-op: a caller that believes it revoked the inference route when nothing
|
|
47
|
+
* happened is exactly the "safe by convention" failure this architecture exists to remove.
|
|
48
|
+
*/
|
|
49
|
+
class RevocationUnsupportedError extends Error {
|
|
50
|
+
constructor(driver, what) {
|
|
51
|
+
super(`${driver} driver cannot revoke '${what}' — no enforcement boundary at this tier (use 'all', which kills the sandbox)`);
|
|
52
|
+
this.name = 'RevocationUnsupportedError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.RevocationUnsupportedError = RevocationUnsupportedError;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
#---------------------------------------------------------------------------------------------
|
|
3
|
+
# Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
|
|
5
|
+
#---------------------------------------------------------------------------------------------
|
|
2
6
|
#
|
|
3
7
|
# Starts LiteLLM via uv. By default installs litellm[proxy] from PyPI (pinned version).
|
|
4
8
|
# Use --git or LITELLM_FROM_GIT=true to install from GitHub at DEFAULT_LITELLM_VERSION instead.
|
|
@@ -49,7 +53,7 @@ augment_path_for_tools
|
|
|
49
53
|
|
|
50
54
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
51
55
|
DEFAULT_CONFIG_PATH="${SCRIPT_DIR}/analytics/agentide-litellm-otel.config.yaml"
|
|
52
|
-
DEFAULT_LITELLM_VERSION="${DEFAULT_LITELLM_VERSION:-1.
|
|
56
|
+
DEFAULT_LITELLM_VERSION="${DEFAULT_LITELLM_VERSION:-1.94.0}"
|
|
53
57
|
# Resolve branded home dir from env first, then legacy fallbacks.
|
|
54
58
|
AGENT_HOME_DIR="${AGENT_HOME_DIR:-${AGENTHIPPO_HOME:-$HOME/.agent-hippo}}"
|
|
55
59
|
DEFAULT_ENV_FILE="${AGENT_HOME_DIR}/.env"
|
|
@@ -325,8 +329,20 @@ if [[ "$TLS_ENABLED" == true ]]; then
|
|
|
325
329
|
fi
|
|
326
330
|
|
|
327
331
|
if [[ ! -f "$CONFIG_PATH" ]]; then
|
|
328
|
-
|
|
329
|
-
|
|
332
|
+
# Self-heal the managed default config: deleting ~/.agent-hippo/litellm-otel.yaml is a
|
|
333
|
+
# supported "reset to defaults" gesture, so re-seed it from the bundled template instead
|
|
334
|
+
# of dying. Any other (custom) path stays a hard error — we cannot guess intent there.
|
|
335
|
+
MANAGED_DEFAULT_CONFIG="${AGENT_HOME_DIR}/litellm-otel.yaml"
|
|
336
|
+
CONFIG_TEMPLATE="${SCRIPT_DIR}/analytics/agentide-litellm-otel.config.yaml"
|
|
337
|
+
if [[ "$CONFIG_PATH" == "$MANAGED_DEFAULT_CONFIG" && -f "$CONFIG_TEMPLATE" ]]; then
|
|
338
|
+
mkdir -p "$AGENT_HOME_DIR"
|
|
339
|
+
cp "$CONFIG_TEMPLATE" "$CONFIG_PATH"
|
|
340
|
+
echo "LiteLLM config was missing; re-created ${CONFIG_PATH} from the bundled template."
|
|
341
|
+
echo "Model routes are commented out in a fresh config — uncomment the providers you use."
|
|
342
|
+
else
|
|
343
|
+
echo "LiteLLM config not found at ${CONFIG_PATH}. Update LITELLM_CONFIG_PATH or create the file." >&2
|
|
344
|
+
exit 1
|
|
345
|
+
fi
|
|
330
346
|
fi
|
|
331
347
|
|
|
332
348
|
# LiteLLM 1.85+ resolves custom callback modules beside the config file (not only PYTHONPATH).
|
|
@@ -406,10 +422,56 @@ if command -v cygpath >/dev/null 2>&1; then
|
|
|
406
422
|
esac
|
|
407
423
|
fi
|
|
408
424
|
|
|
409
|
-
|
|
410
|
-
|
|
425
|
+
# Warn (don't die) about every env var the config references but the environment
|
|
426
|
+
# lacks — driven by the config's own os.environ/… declarations, so it covers any
|
|
427
|
+
# provider without a hardcoded list. LiteLLM resolves these per model, so routes
|
|
428
|
+
# whose credentials are present (and the OTEL pipeline) still work; only the
|
|
429
|
+
# models using a missing var fail, at request time. LITELLM_MASTER_KEY is
|
|
430
|
+
# excluded: it gates the proxy itself and fails closed below.
|
|
431
|
+
MISSING_ENV_REFS=""
|
|
432
|
+
for ref in $(grep -v '^[[:space:]]*#' "$CONFIG_PATH" | grep -oE 'os\.environ/[A-Za-z_][A-Za-z0-9_]*' | sed 's|os\.environ/||' | sort -u); do
|
|
433
|
+
[[ "$ref" == "LITELLM_MASTER_KEY" ]] && continue
|
|
434
|
+
if [[ -z "${!ref:-}" ]]; then
|
|
435
|
+
MISSING_ENV_REFS="${MISSING_ENV_REFS:+$MISSING_ENV_REFS, }$ref"
|
|
436
|
+
fi
|
|
437
|
+
done
|
|
438
|
+
if [[ -n "$MISSING_ENV_REFS" ]]; then
|
|
439
|
+
echo "⚠️ ${CONFIG_PATH} references environment variables that are not set:" >&2
|
|
440
|
+
echo " ${MISSING_ENV_REFS}" >&2
|
|
441
|
+
echo " Models using them will fail until you add them to ${ENV_FILE}, e.g.:" >&2
|
|
442
|
+
echo " echo '${MISSING_ENV_REFS%%,*}=...' >> ${ENV_FILE}" >&2
|
|
443
|
+
fi
|
|
444
|
+
|
|
445
|
+
# Fail closed on an unauthenticated proxy. Without general_settings.master_key LiteLLM serves
|
|
446
|
+
# /v1/chat/completions to anything that can reach the port, using the provider credentials this
|
|
447
|
+
# process holds. There is deliberately no default value.
|
|
448
|
+
if grep -q 'LITELLM_MASTER_KEY' "$CONFIG_PATH" && [[ -z "${LITELLM_MASTER_KEY:-}" ]]; then
|
|
449
|
+
echo "" >&2
|
|
450
|
+
echo "LITELLM_MASTER_KEY is not set but the config requires it (general_settings.master_key)." >&2
|
|
451
|
+
echo "Without it the proxy would accept unauthenticated requests on port ${PORT}." >&2
|
|
452
|
+
echo " export LITELLM_MASTER_KEY=\"sk-\$(openssl rand -hex 24)\"" >&2
|
|
453
|
+
echo "Then pass the same value as AGENTHIPPO_LITELLM_API_KEY to clients." >&2
|
|
454
|
+
echo "" >&2
|
|
411
455
|
exit 1
|
|
412
456
|
fi
|
|
457
|
+
if ! grep -q 'master_key' "$CONFIG_PATH"; then
|
|
458
|
+
echo "⚠️ ${CONFIG_PATH} has no general_settings.master_key — the proxy will accept" >&2
|
|
459
|
+
echo " unauthenticated requests from anything that can reach port ${PORT}." >&2
|
|
460
|
+
fi
|
|
461
|
+
|
|
462
|
+
# Prompt/completion capture is opt-in (PLAN/compliance-req.md §6). Say which mode is in force —
|
|
463
|
+
# an operator must never have to read a YAML file to find out whether prompts are being recorded.
|
|
464
|
+
case "$(printf '%s' "${AGENTHIPPO_EVIDENCE_CONTENT_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in
|
|
465
|
+
1|true|yes|on)
|
|
466
|
+
echo "" >&2
|
|
467
|
+
echo "!! CONTENT CAPTURE IS ON — prompts and completions will be recorded in spans." >&2
|
|
468
|
+
echo "!! AGENTHIPPO_EVIDENCE_CONTENT_CAPTURE is set. Unset it for metadata-only evidence." >&2
|
|
469
|
+
echo "" >&2
|
|
470
|
+
;;
|
|
471
|
+
*)
|
|
472
|
+
echo " privacy: content capture OFF (metadata + sha256 only); set AGENTHIPPO_EVIDENCE_CONTENT_CAPTURE=1 to record prompts/completions"
|
|
473
|
+
;;
|
|
474
|
+
esac
|
|
413
475
|
|
|
414
476
|
LANGFUSE_CALLBACK_PRESENT=false
|
|
415
477
|
LANGFUSE_SHOULD_INSTALL=false
|