import { sha256 } from "../src/core/json.js"; import { PiAgentRunner } from "../src/agents/pi.js"; import type { ThoughtAgentDeclaration } from "../src/agents/types.js"; import type { ThoughtEvent } from "../src/events/types.js"; if (process.env.THOUGHTSTREAM_RUN_TINKER_CANARY !== "1") { throw new Error("Set THOUGHTSTREAM_RUN_TINKER_CANARY=1 to run the credentialed Tinker canary"); } if (!process.env.TINKER_API_KEY) throw new Error("TINKER_API_KEY is required for the Tinker canary"); const model = process.env.THOUGHTSTREAM_TINKER_CANARY_MODEL ?? "thinkingmachines/Inkling-Small"; const expected = "THOUGHTSTREAM_INKLING_CANARY_OK"; const declaration: ThoughtAgentDeclaration = { id: "tinker-conversation-canary", version: 1, name: "Tinker conversation canary", description: "One credentialed inference-only Tinker canary", mode: "pi", provider: "tinker", providerProfile: "tinker-default", model, outputMode: "conversation-text", eventTypes: ["stream.thought.source.telegram.message"], compiledEventTypes: ["stream.thought.source.telegram.message"], sourcePatterns: ["telegram:tinker-canary"], acceptedPrivacy: ["sensitive"], outputEventType: "stream.thought.derived.message.observation", emit: ["stream.thought.derived.message.observation"], promptRef: "scripts/tinker-conversation-canary.ts", systemPrompt: `Return exactly ${expected} and no other text.`, enabled: true, maxEvents: 1, maxInputChars: 2_000, contextStrategy: "telegram-conversation", maxOutputTokens: 128, timeoutMs: 120_000, tools: [], externalActions: false, }; const event: ThoughtEvent = { id: "evt_tinker_conversation_canary", sourceSequence: 1, type: "stream.thought.source.telegram.message", schemaVersion: 1, source: "telegram:tinker-canary", sourceKind: "telegram", externalId: "tinker-conversation-canary", idempotencyKey: "tinker-conversation-canary", occurredAt: new Date().toISOString(), observedAt: new Date().toISOString(), actor: "canary", rootEventId: "evt_tinker_conversation_canary", correlationId: "tinker-conversation-canary", privacy: "sensitive", payload: { chatId: "canary", senderId: "canary", text: `Reply with exactly ${expected}.` }, payloadHash: sha256(expected), createdByRuntime: "tinker-conversation-canary", }; const output = await new PiAgentRunner().run({ runId: "run_tinker_conversation_canary", declaration, event, context: { text: [ '', JSON.stringify([{ role: "user", content: `Reply with exactly ${expected}.` }]), "", ].join("\n"), manifest: {}, }, }, async () => undefined); if (output.summary.trim() !== expected) { throw new Error(`Tinker canary returned an unexpected response hash ${sha256(output.summary)}`); } process.stdout.write(`${JSON.stringify({ status: "passed", provider: output.model?.provider, model: output.model?.id, outputSha256: sha256(output.summary), usage: output.usage, })}\n`);