lastlight-core 0.40.5 → 0.41.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/dist/config/config.js +36 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/provider-registry.d.ts +2 -1
- package/dist/config/provider-registry.js +1 -0
- package/dist/config/provider-registry.js.map +1 -1
- package/dist/engine/agent-executor.js +8 -1
- package/dist/engine/agent-executor.js.map +1 -1
- package/dist/engine/chat/chat-runner.js +9 -2
- package/dist/engine/chat/chat-runner.js.map +1 -1
- package/dist/engine/llm.js +1 -0
- package/dist/engine/llm.js.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox/docker.js +5 -0
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/egress-allowlist.d.ts +20 -0
- package/dist/sandbox/egress-allowlist.js +46 -0
- package/dist/sandbox/egress-allowlist.js.map +1 -1
- package/dist/sandbox/egress-firewall-config.d.ts +6 -0
- package/dist/sandbox/egress-firewall-config.js +9 -3
- package/dist/sandbox/egress-firewall-config.js.map +1 -1
- package/dist/sandbox/model-gateway.d.ts +40 -0
- package/dist/sandbox/model-gateway.js +235 -0
- package/dist/sandbox/model-gateway.js.map +1 -0
- package/docker-compose.yml +35 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"egress-firewall-config.js","sourceRoot":"","sources":["../../src/sandbox/egress-firewall-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"egress-firewall-config.js","sourceRoot":"","sources":["../../src/sandbox/egress-firewall-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EA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,GAAG,CAAC,CAAC;IAChI,CAAC;IAED,IAAI,UAAU;QAAE,cAAc,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;IAEvE,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM;QAC/B,CAAC,CAAC;;;4BAGsB;QACxB,CAAC,CAAC;;;;;0DAKoD,CAAC;IAEzD,OAAO;;;EAGP,aAAa;;;;;4BAKa,6BAA6B;;4BAE7B,6BAA6B;;;;;;EAMvD,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;;;;EAIzB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;CAC1B,CAAC;AACF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB,EAAE,IAAkD;IAC3G,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACpC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAC9C,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,0EAA0E;IAC1E,aAAa,CAAC,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProviderEndpoint } from "lastlight-shared/providers";
|
|
2
|
+
import type { SandboxBackend } from "../config/config.js";
|
|
3
|
+
import { type WireEndpoint } from "../config/provider-registry.js";
|
|
4
|
+
/** The gateway's fixed address on `SANDBOX_EGRESS_SUBNET` (172.30.0.0/24). */
|
|
5
|
+
export declare const MODEL_GATEWAY_IP = "172.30.0.40";
|
|
6
|
+
export declare const MODEL_GATEWAY_PORT = 80;
|
|
7
|
+
/** What the sandbox holds instead of the key. The gateway overwrites it. */
|
|
8
|
+
export declare const MODEL_GATEWAY_KEY_PLACEHOLDER = "lastlight-model-gateway";
|
|
9
|
+
/** The in-sandbox base URL for a gateway provider: one path prefix per provider. */
|
|
10
|
+
export declare function modelGatewayBaseUrl(prefix: string): string;
|
|
11
|
+
/** The providers this deployment routes through the gateway. */
|
|
12
|
+
export declare function gatewayEndpoints(): readonly ProviderEndpoint[];
|
|
13
|
+
/**
|
|
14
|
+
* Swap a gateway provider's key and base URL for the placeholder and the
|
|
15
|
+
* gateway URL, for docker runs. Pure: returns new objects. Every other backend
|
|
16
|
+
* gets its inputs back, since gondolin and none make the model call host-side
|
|
17
|
+
* and smol/kubernetes refuse `sandboxGateway` at config load.
|
|
18
|
+
*
|
|
19
|
+
* The placeholder is set even when the key is absent from `env`, so pi always
|
|
20
|
+
* has a key to send and the gateway always has one to replace.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyModelGateway(env: Record<string, string>, wire: Record<string, WireEndpoint> | undefined, backend: SandboxBackend): {
|
|
23
|
+
env: Record<string, string>;
|
|
24
|
+
wire: Record<string, WireEndpoint> | undefined;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The gateway's nginx config, or `undefined` when no provider uses the gateway.
|
|
28
|
+
* Throws (naming the env var or header, never echoing a value) when a gateway
|
|
29
|
+
* provider's key is missing or a key/header value can't be written safely,
|
|
30
|
+
* which fails the boot instead of starting a gateway that can't authenticate.
|
|
31
|
+
*/
|
|
32
|
+
export declare function renderModelGatewayConf(env?: NodeJS.ProcessEnv): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Write `<stateDir>/proxy/model-gateway.conf` (mode 0600: it holds keys) and
|
|
35
|
+
* return its path; or, when no provider uses the gateway, remove a stale file
|
|
36
|
+
* so a key from an earlier config does not linger on disk, and return
|
|
37
|
+
* `undefined` — also on every backend but docker. Called at harness boot and
|
|
38
|
+
* by the compose `egress-init`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function writeModelGatewayConfig(stateDir: string, env?: NodeJS.ProcessEnv, backend?: SandboxBackend): string | undefined;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model gateway (docker backend only).
|
|
3
|
+
*
|
|
4
|
+
* A custom provider with `sandboxGateway: true` never hands its key to a docker
|
|
5
|
+
* sandbox. The sandbox gets a placeholder key and a base URL on the gateway
|
|
6
|
+
* sidecar (`model-gateway`, on the sandbox egress network); the gateway strips
|
|
7
|
+
* whatever credential the client sent, adds the real key and the provider's
|
|
8
|
+
* literal headers, and forwards over HTTPS. The real key lives only in the
|
|
9
|
+
* server's env and in the gateway's mode-0600 config.
|
|
10
|
+
*
|
|
11
|
+
* Kept free of imports from `egress-firewall-config.ts`: that module imports the
|
|
12
|
+
* allowlist, which imports this one.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, mkdirSync, rmSync, chmodSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { providerRegistry } from "../config/provider-registry.js";
|
|
17
|
+
/** The gateway's fixed address on `SANDBOX_EGRESS_SUBNET` (172.30.0.0/24). */
|
|
18
|
+
export const MODEL_GATEWAY_IP = "172.30.0.40";
|
|
19
|
+
export const MODEL_GATEWAY_PORT = 80;
|
|
20
|
+
/** What the sandbox holds instead of the key. The gateway overwrites it. */
|
|
21
|
+
export const MODEL_GATEWAY_KEY_PLACEHOLDER = "lastlight-model-gateway";
|
|
22
|
+
/** The in-sandbox base URL for a gateway provider: one path prefix per provider. */
|
|
23
|
+
export function modelGatewayBaseUrl(prefix) {
|
|
24
|
+
return `http://${MODEL_GATEWAY_IP}/${prefix}`;
|
|
25
|
+
}
|
|
26
|
+
/** The providers this deployment routes through the gateway. */
|
|
27
|
+
export function gatewayEndpoints() {
|
|
28
|
+
return providerRegistry().endpoints.filter((e) => e.sandboxGateway === true);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Swap a gateway provider's key and base URL for the placeholder and the
|
|
32
|
+
* gateway URL, for docker runs. Pure: returns new objects. Every other backend
|
|
33
|
+
* gets its inputs back, since gondolin and none make the model call host-side
|
|
34
|
+
* and smol/kubernetes refuse `sandboxGateway` at config load.
|
|
35
|
+
*
|
|
36
|
+
* The placeholder is set even when the key is absent from `env`, so pi always
|
|
37
|
+
* has a key to send and the gateway always has one to replace.
|
|
38
|
+
*/
|
|
39
|
+
export function applyModelGateway(env, wire, backend) {
|
|
40
|
+
const gated = backend === "docker" ? gatewayEndpoints() : [];
|
|
41
|
+
if (gated.length === 0)
|
|
42
|
+
return { env, wire };
|
|
43
|
+
const outEnv = { ...env };
|
|
44
|
+
const outWire = { ...(wire ?? {}) };
|
|
45
|
+
for (const e of gated) {
|
|
46
|
+
outEnv[e.envKey] = MODEL_GATEWAY_KEY_PLACEHOLDER;
|
|
47
|
+
const current = outWire[e.prefix];
|
|
48
|
+
if (current)
|
|
49
|
+
outWire[e.prefix] = { ...current, baseUrl: modelGatewayBaseUrl(e.prefix) };
|
|
50
|
+
}
|
|
51
|
+
return { env: outEnv, wire: outWire };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The paths each request family appends to its `baseUrl`, and so the only ones
|
|
55
|
+
* the gateway forwards. The OpenAI client posts `chat/completions`; the
|
|
56
|
+
* Anthropic SDK posts `/v1/messages` onto a bare base URL (it adds the `/v1`
|
|
57
|
+
* itself). `models` is the cheap listing the deploy health check reads.
|
|
58
|
+
*/
|
|
59
|
+
const GATEWAY_PATHS = {
|
|
60
|
+
"openai-completions": ["chat/completions", "models"],
|
|
61
|
+
"anthropic-messages": ["v1/messages", "v1/models"],
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* What a value inside a double-quoted nginx string may contain: printable
|
|
65
|
+
* ASCII without whitespace, minus the characters nginx would read as syntax
|
|
66
|
+
* or as a variable (`"`, `\`, `$`, `;`, `{`, `}`).
|
|
67
|
+
*/
|
|
68
|
+
const NGINX_SAFE_VALUE = /^[\x21-\x7e]+$/;
|
|
69
|
+
const NGINX_SPECIAL = /["\\$;{}]/;
|
|
70
|
+
/**
|
|
71
|
+
* What a literal header value may contain: printable ASCII plus space and tab,
|
|
72
|
+
* without `$` (nginx would expand it as a variable). `"` and `\` are escaped by
|
|
73
|
+
* {@link nginxHeaderValue}; `;`, `{` and `}` are plain characters inside quotes.
|
|
74
|
+
*/
|
|
75
|
+
const HEADER_VALUE_SAFE = /^[\t\x20-\x7e]*$/;
|
|
76
|
+
const URL_PATH_SAFE = /^[A-Za-z0-9._~/%-]*$/;
|
|
77
|
+
const PREFIX_SAFE = /^[A-Za-z0-9._-]+$/;
|
|
78
|
+
/** A header name nginx reads as one plain token (no `#` comment, no quote). */
|
|
79
|
+
const HEADER_NAME_SAFE = /^[A-Za-z0-9][A-Za-z0-9-]*$/;
|
|
80
|
+
/** Headers the gateway itself owns: overriding them corrupts every request. */
|
|
81
|
+
const RESERVED_HEADERS = new Set([
|
|
82
|
+
"host", "content-length", "transfer-encoding", "connection", "keep-alive", "upgrade",
|
|
83
|
+
"te", "trailer", "proxy-connection", "proxy-authorization", "authorization", "x-api-key",
|
|
84
|
+
]);
|
|
85
|
+
/** A header value as the body of a double-quoted nginx string. */
|
|
86
|
+
function nginxHeaderValue(value, what) {
|
|
87
|
+
if (!HEADER_VALUE_SAFE.test(value) || value.includes("$")) {
|
|
88
|
+
throw new Error(`${what}: the model gateway can't carry this value — it must be printable ASCII (spaces and tabs ` +
|
|
89
|
+
`allowed) without "$"`);
|
|
90
|
+
}
|
|
91
|
+
return value.replace(/[\\"]/g, (c) => `\\${c}`);
|
|
92
|
+
}
|
|
93
|
+
/** Never echoes `value`: the key must not reach a log or an error. */
|
|
94
|
+
function assertNginxSafe(value, what) {
|
|
95
|
+
if (!NGINX_SAFE_VALUE.test(value) || NGINX_SPECIAL.test(value)) {
|
|
96
|
+
throw new Error(`${what}: the model gateway can't carry this value — it must be printable ASCII without ` +
|
|
97
|
+
`whitespace, quotes, backslashes, "$", ";", "{" or "}"`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The gateway's nginx config, or `undefined` when no provider uses the gateway.
|
|
102
|
+
* Throws (naming the env var or header, never echoing a value) when a gateway
|
|
103
|
+
* provider's key is missing or a key/header value can't be written safely,
|
|
104
|
+
* which fails the boot instead of starting a gateway that can't authenticate.
|
|
105
|
+
*/
|
|
106
|
+
export function renderModelGatewayConf(env = process.env) {
|
|
107
|
+
const gated = gatewayEndpoints();
|
|
108
|
+
if (gated.length === 0)
|
|
109
|
+
return undefined;
|
|
110
|
+
const servers = gated.map((e) => renderProviderLocations(e, env)).join("\n");
|
|
111
|
+
return `# Generated by lastlight at harness boot. DO NOT EDIT BY HAND.
|
|
112
|
+
# Model gateway: holds provider keys so docker sandboxes never do.
|
|
113
|
+
# Source of truth: src/sandbox/model-gateway.ts. Mode 0600 — contains keys.
|
|
114
|
+
|
|
115
|
+
error_log /dev/stderr warn;
|
|
116
|
+
pid /tmp/nginx.pid;
|
|
117
|
+
|
|
118
|
+
events { worker_connections 256; }
|
|
119
|
+
|
|
120
|
+
http {
|
|
121
|
+
access_log off;
|
|
122
|
+
server_tokens off;
|
|
123
|
+
client_body_temp_path /tmp/nginx-client-body;
|
|
124
|
+
proxy_temp_path /tmp/nginx-proxy;
|
|
125
|
+
|
|
126
|
+
# Runtime resolver (docker's embedded DNS): the upstream is a variable, so
|
|
127
|
+
# nginx resolves it per request instead of pinning one IP at startup.
|
|
128
|
+
resolver 127.0.0.11 valid=30s ipv6=off;
|
|
129
|
+
|
|
130
|
+
server {
|
|
131
|
+
listen 80;
|
|
132
|
+
|
|
133
|
+
# Agent runs send big contexts and stream long generations.
|
|
134
|
+
client_max_body_size 64m;
|
|
135
|
+
proxy_request_buffering off;
|
|
136
|
+
proxy_buffering off;
|
|
137
|
+
proxy_read_timeout 600s;
|
|
138
|
+
proxy_send_timeout 600s;
|
|
139
|
+
proxy_connect_timeout 10s;
|
|
140
|
+
proxy_http_version 1.1;
|
|
141
|
+
|
|
142
|
+
proxy_ssl_server_name on;
|
|
143
|
+
proxy_ssl_verify on;
|
|
144
|
+
proxy_ssl_verify_depth 3;
|
|
145
|
+
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
|
|
146
|
+
|
|
147
|
+
${servers}
|
|
148
|
+
# Anything else: not a model call.
|
|
149
|
+
location / {
|
|
150
|
+
return 404;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
function renderProviderLocations(e, env) {
|
|
157
|
+
if (!PREFIX_SAFE.test(e.prefix)) {
|
|
158
|
+
throw new Error(`providers.${e.prefix}: the model gateway needs a prefix of letters, digits, ".", "_" or "-"`);
|
|
159
|
+
}
|
|
160
|
+
const key = env[e.envKey];
|
|
161
|
+
if (!key) {
|
|
162
|
+
throw new Error(`${e.envKey} is not set: providers.${e.prefix} uses the model gateway, which needs the key to add it`);
|
|
163
|
+
}
|
|
164
|
+
assertNginxSafe(key, e.envKey);
|
|
165
|
+
const url = new URL(e.baseUrl);
|
|
166
|
+
// The real key goes on every forwarded request: never over plain http. The
|
|
167
|
+
// registry refuses this at config load; this guards the renderer itself.
|
|
168
|
+
if (url.protocol !== "https:") {
|
|
169
|
+
throw new Error(`providers.${e.prefix}.baseUrl: the model gateway only forwards to https:// upstreams`);
|
|
170
|
+
}
|
|
171
|
+
// The gateway forwards to origin + path only; refuse what it would drop.
|
|
172
|
+
// Never echo the URL: userinfo or a query may hold a credential.
|
|
173
|
+
if (url.search || url.hash || url.username || url.password) {
|
|
174
|
+
throw new Error(`providers.${e.prefix}.baseUrl: the model gateway can't forward a query string, fragment or ` +
|
|
175
|
+
`user:password; put credentials in the key env var or in headers`);
|
|
176
|
+
}
|
|
177
|
+
const basePath = url.pathname.replace(/\/+$/, "");
|
|
178
|
+
if (!URL_PATH_SAFE.test(basePath)) {
|
|
179
|
+
throw new Error(`providers.${e.prefix}.baseUrl: the model gateway can't forward this path`);
|
|
180
|
+
}
|
|
181
|
+
const auth = e.api === "anthropic-messages"
|
|
182
|
+
? [`proxy_set_header x-api-key "${key}";`, `proxy_set_header Authorization "";`]
|
|
183
|
+
: [`proxy_set_header Authorization "Bearer ${key}";`, `proxy_set_header x-api-key "";`];
|
|
184
|
+
const headers = Object.entries(e.headers ?? {}).map(([name, value]) => {
|
|
185
|
+
if (!HEADER_NAME_SAFE.test(name) || RESERVED_HEADERS.has(name.toLowerCase())) {
|
|
186
|
+
throw new Error(`providers.${e.prefix}.headers.${name}: the model gateway only sends header names of letters, ` +
|
|
187
|
+
`digits and "-", and sets Host, Content-Length, Connection and the credential headers itself`);
|
|
188
|
+
}
|
|
189
|
+
return `proxy_set_header ${name} "${nginxHeaderValue(value, `providers.${e.prefix}.headers.${name}`)}";`;
|
|
190
|
+
});
|
|
191
|
+
const directives = [
|
|
192
|
+
`set $upstream "https://${url.host}";`,
|
|
193
|
+
`proxy_set_header Host "${url.host}";`,
|
|
194
|
+
// Here, not at server level: any proxy_set_header in a location replaces
|
|
195
|
+
// every inherited one.
|
|
196
|
+
`proxy_set_header Connection "";`,
|
|
197
|
+
`proxy_ssl_name "${url.hostname}";`,
|
|
198
|
+
...auth,
|
|
199
|
+
...headers,
|
|
200
|
+
];
|
|
201
|
+
return GATEWAY_PATHS[e.api]
|
|
202
|
+
.map((path) => ` location = /${e.prefix}/${path} {
|
|
203
|
+
${directives.map((d) => ` ${d}`).join("\n")}
|
|
204
|
+
proxy_pass $upstream${basePath}/${path}$is_args$args;
|
|
205
|
+
}
|
|
206
|
+
`)
|
|
207
|
+
.join("\n");
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Write `<stateDir>/proxy/model-gateway.conf` (mode 0600: it holds keys) and
|
|
211
|
+
* return its path; or, when no provider uses the gateway, remove a stale file
|
|
212
|
+
* so a key from an earlier config does not linger on disk, and return
|
|
213
|
+
* `undefined` — also on every backend but docker. Called at harness boot and
|
|
214
|
+
* by the compose `egress-init`.
|
|
215
|
+
*/
|
|
216
|
+
export function writeModelGatewayConfig(stateDir, env = process.env, backend = "docker") {
|
|
217
|
+
const dir = join(stateDir, "proxy");
|
|
218
|
+
const path = join(dir, "model-gateway.conf");
|
|
219
|
+
// Only docker runs use the gateway; elsewhere a key file would be a needless
|
|
220
|
+
// second copy of the key.
|
|
221
|
+
const conf = backend === "docker" ? renderModelGatewayConf(env) : undefined;
|
|
222
|
+
if (conf === undefined) {
|
|
223
|
+
if (existsSync(path))
|
|
224
|
+
rmSync(path, { force: true });
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
mkdirSync(dir, { recursive: true });
|
|
228
|
+
// `mode` only applies when the file is created, so tighten an existing file
|
|
229
|
+
// BEFORE the key goes into it.
|
|
230
|
+
if (existsSync(path))
|
|
231
|
+
chmodSync(path, 0o600);
|
|
232
|
+
writeFileSync(path, conf, { mode: 0o600 });
|
|
233
|
+
return path;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=model-gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-gateway.js","sourceRoot":"","sources":["../../src/sandbox/model-gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,gCAAgC,CAAC;AAErF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,6BAA6B,GAAG,yBAAyB,CAAC;AAEvE,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,OAAO,UAAU,gBAAgB,IAAI,MAAM,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,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/docker-compose.yml
CHANGED
|
@@ -127,7 +127,7 @@ services:
|
|
|
127
127
|
- agent-data:/app/data
|
|
128
128
|
command:
|
|
129
129
|
["node", "-e",
|
|
130
|
-
"const c=require('/app/dist/config/config.js').loadConfig();const m=require('/app/dist/sandbox/egress-firewall-config.js');const d=c.stateDir;m.writeEgressFirewallConfigs(d);m.writeOtelCollectorConfig(d,{active:c.otel.enabled&&c.otel.forwardToSandbox})"]
|
|
130
|
+
"const c=require('/app/dist/config/config.js').loadConfig();const m=require('/app/dist/sandbox/egress-firewall-config.js');const d=c.stateDir;m.writeEgressFirewallConfigs(d);m.writeOtelCollectorConfig(d,{active:c.otel.enabled&&c.otel.forwardToSandbox});require('/app/dist/sandbox/model-gateway.js').writeModelGatewayConfig(d,process.env,c.sandbox)"]
|
|
131
131
|
depends_on:
|
|
132
132
|
- agent # ensures the image has been built when init runs
|
|
133
133
|
|
|
@@ -192,6 +192,37 @@ services:
|
|
|
192
192
|
ipv4_address: 172.30.0.21
|
|
193
193
|
proxy-egress: {}
|
|
194
194
|
|
|
195
|
+
# Model gateway: holds the keys of `sandboxGateway` providers so docker
|
|
196
|
+
# sandboxes never do. Sandboxes call it by IP on sandbox-egress with a
|
|
197
|
+
# placeholder key; it swaps in the real key and forwards over HTTPS on
|
|
198
|
+
# proxy-egress. Its config (mode 0600, written by the harness/egress-init)
|
|
199
|
+
# holds the keys, so it mounts ONLY the proxy config directory — not the
|
|
200
|
+
# rest of agent-data. Not on `internal`, like the firewalls. Opt-in
|
|
201
|
+
# (`COMPOSE_PROFILES=model-gateway`): without a `sandboxGateway` provider
|
|
202
|
+
# there is no config for it to load. nginx reads the config (and so the
|
|
203
|
+
# keys) only at start: after rotating a key, restart the agent (it rewrites
|
|
204
|
+
# the config), then `docker compose restart model-gateway`.
|
|
205
|
+
model-gateway:
|
|
206
|
+
image: nginx:1.31-alpine
|
|
207
|
+
profiles: ["model-gateway"]
|
|
208
|
+
restart: unless-stopped
|
|
209
|
+
command:
|
|
210
|
+
["nginx", "-c", "/app/data/proxy/model-gateway.conf", "-g", "daemon off;"]
|
|
211
|
+
volumes:
|
|
212
|
+
- type: volume
|
|
213
|
+
source: agent-data
|
|
214
|
+
target: /app/data/proxy
|
|
215
|
+
read_only: true
|
|
216
|
+
volume:
|
|
217
|
+
subpath: proxy
|
|
218
|
+
depends_on:
|
|
219
|
+
egress-init:
|
|
220
|
+
condition: service_completed_successfully
|
|
221
|
+
networks:
|
|
222
|
+
sandbox-egress:
|
|
223
|
+
ipv4_address: 172.30.0.40
|
|
224
|
+
proxy-egress: {}
|
|
225
|
+
|
|
195
226
|
# In-network OTEL collector. Sandboxes export telemetry here (by IP, on
|
|
196
227
|
# sandbox-egress) and it re-exports to the configured backend over
|
|
197
228
|
# proxy-egress. This is why the strict SNI firewall doesn't need to know
|
|
@@ -314,12 +345,14 @@ networks:
|
|
|
314
345
|
# `internal: true` disables direct host egress, so the only path to the
|
|
315
346
|
# public internet is through the nginx firewalls, which receive sandbox
|
|
316
347
|
# traffic on this network. Static subnet so the coredns + nginx IPs
|
|
317
|
-
# baked into the generated configs are stable.
|
|
348
|
+
# baked into the generated configs are stable. Sandboxes get addresses only
|
|
349
|
+
# from ip_range (.128–.254), so none can take a sidecar's static IP (.10–.40).
|
|
318
350
|
sandbox-egress:
|
|
319
351
|
internal: true
|
|
320
352
|
ipam:
|
|
321
353
|
config:
|
|
322
354
|
- subnet: 172.30.0.0/24
|
|
355
|
+
ip_range: 172.30.0.128/25
|
|
323
356
|
# Egress-only network for the nginx firewalls. Regular bridge (has a
|
|
324
357
|
# default route to the host's network, so nginx can reach the public
|
|
325
358
|
# internet). Critically: NO other compose services attach here. That way
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lastlight-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "GitHub repository maintenance agent — Agent SDK harness",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"pino-pretty": "13.2.0",
|
|
76
76
|
"yaml": "^2.9.1",
|
|
77
77
|
"zod": "^4.6.7",
|
|
78
|
+
"agentic-pi": "0.9.0",
|
|
78
79
|
"lastlight-workflow-engine": "0.11.1",
|
|
79
|
-
"lastlight-shared": "0.
|
|
80
|
-
"agentic-pi": "0.8.2"
|
|
80
|
+
"lastlight-shared": "0.14.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@electric-sql/pglite": "^0.5.13",
|