@certalis/agent-smith 0.3.0 → 0.3.3
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 +8 -3
- package/dist/bin.js +792 -177
- package/dist/claude-companion/hooks/provider-choice.js +6 -1
- package/dist/client-launcher.js +689 -66
- package/dist/edge.js +15 -3
- package/dist/https.js +17 -4
- package/dist/pool.js +217 -86
- package/dist/post-processor.worker.js +92 -42
- package/dist/server.js +217 -86
- package/package.json +2 -1
package/dist/edge.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
request
|
|
4
4
|
} from "node:http";
|
|
5
5
|
import { isAbsolute } from "node:path";
|
|
6
|
+
import { createGunzip } from "node:zlib";
|
|
6
7
|
|
|
7
8
|
// ../../packages/runtime-server/src/inference-routes.ts
|
|
8
9
|
var INFERENCE_ROUTES = new Set([
|
|
@@ -79,6 +80,7 @@ function isEnrollmentRoute(method, path) {
|
|
|
79
80
|
function selectHeaders(headers, names) {
|
|
80
81
|
return Object.fromEntries(names.flatMap((name) => typeof headers[name] === "string" ? [[name, headers[name]]] : []));
|
|
81
82
|
}
|
|
83
|
+
var isGzip = (encoding) => encoding.trim().toLowerCase() === "gzip";
|
|
82
84
|
function requestFailure(req, origin, maxBodyBytes, enrollment) {
|
|
83
85
|
const health = req.method === "GET" && req.url === "/pool-health";
|
|
84
86
|
if (!enrollment && !health && !isInferenceRoute(req.method ?? "", req.url ?? ""))
|
|
@@ -89,6 +91,9 @@ function requestFailure(req, origin, maxBodyBytes, enrollment) {
|
|
|
89
91
|
return 400;
|
|
90
92
|
if (req.headers["content-length"] !== undefined && (!/^\d+$/.test(req.headers["content-length"]) || Number(req.headers["content-length"]) > maxBodyBytes))
|
|
91
93
|
return 413;
|
|
94
|
+
const encoding = req.headers["content-encoding"];
|
|
95
|
+
if (encoding !== undefined && (enrollment || !isGzip(encoding)))
|
|
96
|
+
return 415;
|
|
92
97
|
if (enrollment) {
|
|
93
98
|
if (req.method === "POST" && req.headers.origin !== origin)
|
|
94
99
|
return 403;
|
|
@@ -180,17 +185,24 @@ function createProxyEdgeHandler({
|
|
|
180
185
|
});
|
|
181
186
|
req.once("aborted", () => upstream.destroy());
|
|
182
187
|
req.once("error", () => upstream.destroy());
|
|
188
|
+
const gunzip = req.headers["content-encoding"] ? req.pipe(createGunzip()) : undefined;
|
|
189
|
+
gunzip?.on("error", () => {
|
|
190
|
+
upstream.destroy();
|
|
191
|
+
finish(400);
|
|
192
|
+
});
|
|
193
|
+
const body = gunzip ?? req;
|
|
183
194
|
let bytes = 0;
|
|
184
|
-
|
|
195
|
+
body.on("data", (chunk) => {
|
|
185
196
|
bytes += chunk.length;
|
|
186
197
|
if (bytes > bodyLimit) {
|
|
187
|
-
|
|
198
|
+
body.unpipe(upstream);
|
|
199
|
+
gunzip?.destroy();
|
|
188
200
|
upstream.destroy();
|
|
189
201
|
finish(413);
|
|
190
202
|
}
|
|
191
203
|
});
|
|
192
204
|
upstream.flushHeaders();
|
|
193
|
-
|
|
205
|
+
body.pipe(upstream);
|
|
194
206
|
};
|
|
195
207
|
}
|
|
196
208
|
export {
|
package/dist/https.js
CHANGED
|
@@ -99,6 +99,7 @@ import {
|
|
|
99
99
|
request
|
|
100
100
|
} from "node:http";
|
|
101
101
|
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
102
|
+
import { createGunzip } from "node:zlib";
|
|
102
103
|
|
|
103
104
|
// ../../packages/runtime-server/src/inference-routes.ts
|
|
104
105
|
var INFERENCE_ROUTES = new Set([
|
|
@@ -175,6 +176,7 @@ function isEnrollmentRoute(method, path) {
|
|
|
175
176
|
function selectHeaders(headers, names) {
|
|
176
177
|
return Object.fromEntries(names.flatMap((name) => typeof headers[name] === "string" ? [[name, headers[name]]] : []));
|
|
177
178
|
}
|
|
179
|
+
var isGzip = (encoding) => encoding.trim().toLowerCase() === "gzip";
|
|
178
180
|
function requestFailure(req, origin, maxBodyBytes, enrollment) {
|
|
179
181
|
const health = req.method === "GET" && req.url === "/pool-health";
|
|
180
182
|
if (!enrollment && !health && !isInferenceRoute(req.method ?? "", req.url ?? ""))
|
|
@@ -185,6 +187,9 @@ function requestFailure(req, origin, maxBodyBytes, enrollment) {
|
|
|
185
187
|
return 400;
|
|
186
188
|
if (req.headers["content-length"] !== undefined && (!/^\d+$/.test(req.headers["content-length"]) || Number(req.headers["content-length"]) > maxBodyBytes))
|
|
187
189
|
return 413;
|
|
190
|
+
const encoding = req.headers["content-encoding"];
|
|
191
|
+
if (encoding !== undefined && (enrollment || !isGzip(encoding)))
|
|
192
|
+
return 415;
|
|
188
193
|
if (enrollment) {
|
|
189
194
|
if (req.method === "POST" && req.headers.origin !== origin)
|
|
190
195
|
return 403;
|
|
@@ -276,21 +281,29 @@ function createProxyEdgeHandler({
|
|
|
276
281
|
});
|
|
277
282
|
req.once("aborted", () => upstream.destroy());
|
|
278
283
|
req.once("error", () => upstream.destroy());
|
|
284
|
+
const gunzip = req.headers["content-encoding"] ? req.pipe(createGunzip()) : undefined;
|
|
285
|
+
gunzip?.on("error", () => {
|
|
286
|
+
upstream.destroy();
|
|
287
|
+
finish(400);
|
|
288
|
+
});
|
|
289
|
+
const body = gunzip ?? req;
|
|
279
290
|
let bytes = 0;
|
|
280
|
-
|
|
291
|
+
body.on("data", (chunk) => {
|
|
281
292
|
bytes += chunk.length;
|
|
282
293
|
if (bytes > bodyLimit) {
|
|
283
|
-
|
|
294
|
+
body.unpipe(upstream);
|
|
295
|
+
gunzip?.destroy();
|
|
284
296
|
upstream.destroy();
|
|
285
297
|
finish(413);
|
|
286
298
|
}
|
|
287
299
|
});
|
|
288
300
|
upstream.flushHeaders();
|
|
289
|
-
|
|
301
|
+
body.pipe(upstream);
|
|
290
302
|
};
|
|
291
303
|
}
|
|
292
304
|
|
|
293
305
|
// ../../packages/runtime-server/src/standalone.ts
|
|
306
|
+
var POOL_READY_DEADLINE_MS = 10 * 60000;
|
|
294
307
|
async function bounded(promise, ms) {
|
|
295
308
|
let timer;
|
|
296
309
|
try {
|
|
@@ -424,7 +437,7 @@ async function startStandalone(options, poolEntry, env = process.env) {
|
|
|
424
437
|
child.on("message", ready);
|
|
425
438
|
child.once("error", failed);
|
|
426
439
|
child.once("close", failed);
|
|
427
|
-
}),
|
|
440
|
+
}), POOL_READY_DEADLINE_MS);
|
|
428
441
|
server.listen(options.port, "0.0.0.0");
|
|
429
442
|
await once(server, "listening");
|
|
430
443
|
if (exited)
|