pi-roundtable-sandbox 0.7.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/examples/roundtable.config.ts +36 -0
- package/package.json +47 -0
- package/src/broker.ts +387 -0
- package/src/channel-store.ts +81 -0
- package/src/claim.ts +77 -0
- package/src/commands.ts +63 -0
- package/src/container-driver.ts +193 -0
- package/src/index.ts +29 -0
- package/src/model-input.ts +177 -0
- package/src/plugin.ts +85 -0
- package/src/protocol.ts +108 -0
- package/src/runtime.ts +240 -0
- package/worker/Dockerfile +6 -0
- package/worker/agent.ts +271 -0
- package/worker/main.ts +16 -0
- package/worker/memory.ts +138 -0
- package/worker/transport.ts +61 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { request } from "node:http";
|
|
2
|
+
import { BROKER_PATH, DUMMY_KEY } from "../src/protocol.ts";
|
|
3
|
+
|
|
4
|
+
/** Bun fetch adds Connection automatically; this client sends only the explicit safe headers. */
|
|
5
|
+
export function unixBrokerRequest(
|
|
6
|
+
route: string,
|
|
7
|
+
body: Record<string, unknown>,
|
|
8
|
+
socketPath = BROKER_PATH,
|
|
9
|
+
): Promise<{ status: number; body: unknown }> {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const encoded = JSON.stringify(body);
|
|
12
|
+
const outgoing = request(
|
|
13
|
+
{
|
|
14
|
+
socketPath,
|
|
15
|
+
path: route,
|
|
16
|
+
method: "POST",
|
|
17
|
+
setDefaultHeaders: false,
|
|
18
|
+
headers: {
|
|
19
|
+
host: "broker",
|
|
20
|
+
"content-type": "application/json",
|
|
21
|
+
"content-length": Buffer.byteLength(encoded),
|
|
22
|
+
authorization: `Bearer ${DUMMY_KEY}`,
|
|
23
|
+
},
|
|
24
|
+
signal: AbortSignal.timeout(65_000),
|
|
25
|
+
},
|
|
26
|
+
(incoming) => {
|
|
27
|
+
let size = 0;
|
|
28
|
+
const chunks: Buffer[] = [];
|
|
29
|
+
incoming.on("data", (chunk: Buffer) => {
|
|
30
|
+
size += chunk.length;
|
|
31
|
+
if (size > 1024 * 1024) {
|
|
32
|
+
outgoing.destroy(new Error("broker response too large"));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
chunks.push(chunk);
|
|
36
|
+
});
|
|
37
|
+
incoming.on("error", reject);
|
|
38
|
+
incoming.on("end", () => {
|
|
39
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
40
|
+
if (incoming.statusCode !== 200) {
|
|
41
|
+
resolve({
|
|
42
|
+
status: incoming.statusCode ?? 502,
|
|
43
|
+
body: { error: "broker refused" },
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
resolve({
|
|
49
|
+
status: incoming.statusCode ?? 502,
|
|
50
|
+
body: JSON.parse(text),
|
|
51
|
+
});
|
|
52
|
+
} catch {
|
|
53
|
+
reject(new Error("broker returned no JSON"));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
outgoing.on("error", reject);
|
|
59
|
+
outgoing.end(encoded);
|
|
60
|
+
});
|
|
61
|
+
}
|