mirror of
https://github.com/block/buzz.git
synced 2026-10-30 22:11:36 +00:00
Signed-off-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Matt Toohey <contact@matttoohey.com> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Tyler <109685178+tlongwell-block@users.noreply.github.com> Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Dawn <c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: npub1hwqy0rnujtl25dzmlhn8qwux4kr8sjhas3ugltx9j5dm5dwkp2dsqjhytw <bb80478e7c92feaa345bfde6703b86ad86784afd84788facc5951bba35d60a9b@buzz.block.builderlab.xyz>
105 lines
3.0 KiB
JavaScript
Executable File
105 lines
3.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/** Deterministic ACP fixture for agents-everywhere live tests. */
|
|
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import { createInterface } from "node:readline";
|
|
|
|
const exec = promisify(execFile);
|
|
|
|
const wakeDelayMs = Number.parseInt(
|
|
process.env.BUZZ_E2E_FAKE_ACP_WAKE_MS ?? "0",
|
|
10,
|
|
);
|
|
if (!Number.isFinite(wakeDelayMs) || wakeDelayMs < 0) {
|
|
throw new Error("BUZZ_E2E_FAKE_ACP_WAKE_MS must be a non-negative integer");
|
|
}
|
|
|
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
const write = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
const textFromPrompt = (params) =>
|
|
(params?.prompt ?? [])
|
|
.filter((part) => part?.type === "text" && typeof part.text === "string")
|
|
.map((part) => part.text)
|
|
.join("\n");
|
|
|
|
let sessionCounter = 0;
|
|
const input = createInterface({
|
|
input: process.stdin,
|
|
crlfDelay: Number.POSITIVE_INFINITY,
|
|
});
|
|
for await (const line of input) {
|
|
if (!line.trim()) continue;
|
|
const request = JSON.parse(line);
|
|
if (request.id === undefined || typeof request.method !== "string") continue;
|
|
|
|
switch (request.method) {
|
|
case "initialize":
|
|
if (wakeDelayMs > 0) await sleep(wakeDelayMs);
|
|
write({
|
|
jsonrpc: "2.0",
|
|
id: request.id,
|
|
result: { protocolVersion: 2, agentCapabilities: {} },
|
|
});
|
|
break;
|
|
case "session/new":
|
|
sessionCounter += 1;
|
|
write({
|
|
jsonrpc: "2.0",
|
|
id: request.id,
|
|
result: { sessionId: `fake-session-${sessionCounter}` },
|
|
});
|
|
break;
|
|
case "session/prompt": {
|
|
const prompt = textFromPrompt(request.params);
|
|
const ids = [...prompt.matchAll(/\bAE-ID:([A-Za-z0-9._:-]+)\b/g)].map(
|
|
(match) => match[1],
|
|
);
|
|
const ack = `AE-ACK:${ids.join(",")}`;
|
|
write({
|
|
jsonrpc: "2.0",
|
|
method: "session/update",
|
|
params: {
|
|
sessionId: request.params?.sessionId,
|
|
update: {
|
|
sessionUpdate: "agent_message_chunk",
|
|
content: { type: "text", text: ack },
|
|
},
|
|
},
|
|
});
|
|
const channel = prompt.match(/^Channel: .+ \(#([^)]+)\)$/m)?.[1];
|
|
const replyTo = prompt.match(/--reply-to ([0-9a-f]{64})/)?.[1];
|
|
const cli = process.env.BUZZ_E2E_CLI_BIN;
|
|
if (cli && channel) {
|
|
const args = [
|
|
"messages",
|
|
"send",
|
|
"--channel",
|
|
channel,
|
|
"--content",
|
|
ack,
|
|
];
|
|
if (replyTo) args.push("--reply-to", replyTo);
|
|
await exec(cli, args, { env: process.env });
|
|
}
|
|
write({
|
|
jsonrpc: "2.0",
|
|
id: request.id,
|
|
result: { stopReason: "end_turn" },
|
|
});
|
|
break;
|
|
}
|
|
case "session/cancel":
|
|
write({ jsonrpc: "2.0", id: request.id, result: {} });
|
|
break;
|
|
default:
|
|
write({
|
|
jsonrpc: "2.0",
|
|
id: request.id,
|
|
error: {
|
|
code: -32601,
|
|
message: `Unsupported fixture method: ${request.method}`,
|
|
},
|
|
});
|
|
}
|
|
}
|