Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
2.9 kB · 63 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import path from "node:path";import { createHash } from "node:crypto";import { loadAgentDeclarations } from "../src/agents/declarations.js";import { buildSubscribedTelegramConversationContextPacket } from "../src/agents/context.js";import { PiAgentRunner } from "../src/agents/pi.js";import { AgentRunFailure } from "../src/agents/types.js";import { JazzThoughtStore } from "../src/jazz/store.js";
if (process.env.THOUGHTSTREAM_RUN_TINKER_LIVE_EVENT_CANARY !== "1") { throw new Error("Set THOUGHTSTREAM_RUN_TINKER_LIVE_EVENT_CANARY=1 to run the credentialed event canary");}if (!process.env.TINKER_API_KEY) throw new Error("TINKER_API_KEY is required for the Tinker event canary");const eventId = process.env.THOUGHTSTREAM_TINKER_CANARY_EVENT_ID;if (!eventId || !/^evt_[a-f0-9]{48}$/.test(eventId)) throw new Error("THOUGHTSTREAM_TINKER_CANARY_EVENT_ID must be one exact event id");
const projectRoot = process.env.THOUGHTSTREAM_ROOT;if (!projectRoot) throw new Error("THOUGHTSTREAM_ROOT is required for the Tinker event canary");const store = await JazzThoughtStore.open({ projectRoot });try { const declaration = (await loadAgentDeclarations(path.resolve(import.meta.dirname, "..", "agents"))) .find((candidate) => candidate.id === "telegram-conversation"); if (!declaration) throw new Error("Telegram conversation declaration is missing"); const event = await store.getEvent(eventId); if (!event || event.type !== "stream.thought.source.telegram.message") { throw new Error("Requested event is not an available Telegram message"); } const context = await buildSubscribedTelegramConversationContextPacket(declaration, event, store); const traces: Array<{ kind: string; data: unknown }> = []; try { const output = await new PiAgentRunner({ artifactRoot: store.getArtifactRoot() }).run({ runId: `canary_${eventId}`, declaration, event, context, }, async (trace) => { traces.push(trace); }); process.stdout.write(`${JSON.stringify({ status: "passed", eventId, outputSha256: sha256(output.summary), outputChars: output.summary.length, proposalKinds: (output.proposals ?? []).map((proposal) => proposal.kind), traceKinds: traces.map((trace) => trace.kind), usage: output.usage, })}\n`); } catch (error) { const failure = error instanceof AgentRunFailure ? error : undefined; process.stdout.write(`${JSON.stringify({ status: "failed", eventId, errorClass: error instanceof Error ? error.name : typeof error, message: error instanceof Error ? error.message : "unknown error", diagnostic: failure?.diagnostic, traceKinds: traces.map((trace) => trace.kind), })}\n`); process.exitCode = 1; }} finally { await store.close();}
function sha256(value: string): string { return createHash("sha256").update(value).digest("hex");}