Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/probe-worker.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DEFAULT_BASE_URL = "https://technocore.chat";
const DEFAULT_WORKERS_AI_MODEL = "@cf/meta/llama-3.2-3b-instruct";
const DEFAULT_PROBE_DID = "did:key:z6MktJffXSF9X98YQ29Ug36A1dkc26RqULaeRHyZj6rpZQV5";
const EXPECTED_AGENT_DID = "did:key:z6MkfRm7VkjC52pff11L12dbFkChhVkiZqv5Wwd7VMo3fCsG";
const PROBE_PATTERN = /^probe v1 \| ([a-z0-9.-]+) \| (ask|addressed|statement|question|offer|null) \| (.+)$/i;
const REPLY_PATTERN = /^probe v1 reply \| ([a-z0-9.-]+) \|/i;

Expand Down Expand Up @@ -274,6 +275,7 @@ export async function scanOnce(env, now = Date.now()) {
for (const required of ["TECHNOCORE_AGENT_DID", "TECHNOCORE_AGENT_PRIVATE_KEY"]) {
if (!env[required]) throw new Error(`${required} is required`);
}
if (env.TECHNOCORE_AGENT_DID !== EXPECTED_AGENT_DID) throw new Error("TECHNOCORE_AGENT_DID does not match the Task Relay identity");
const { rooms } = await resolveRooms(env, now);
const state = { cursors: new Map(), replied: new Map() };
const results = await scanRooms(env, rooms, state, now);
Expand All @@ -284,6 +286,7 @@ export async function listenForProbeWindow(env, options = {}) {
for (const required of ["TECHNOCORE_AGENT_DID", "TECHNOCORE_AGENT_PRIVATE_KEY"]) {
if (!env[required]) throw new Error(`${required} is required`);
}
if (env.TECHNOCORE_AGENT_DID !== EXPECTED_AGENT_DID) throw new Error("TECHNOCORE_AGENT_DID does not match the Task Relay identity");
const sleep = options.sleep || ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
const pollMilliseconds = Math.min(20_000, Math.max(5_000, Number(env.PROBE_POLL_SECONDS || 15) * 1000));
const followupPasses = Math.min(3, Math.max(1, Number(env.PROBE_FOLLOWUP_PASSES || 3)));
Expand Down
10 changes: 10 additions & 0 deletions tests/probe-worker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ test("hot-polls configured probe rooms with a sequence cursor", async () => {
}
});

test("refuses to run under a DID other than the Task Relay identity", async () => {
await assert.rejects(
listenForProbeWindow({
TECHNOCORE_AGENT_DID: "did:key:z6MkuEZEahZu1VeAD6eton6sC5gv2u6picq3vj8zTd8iY6oW",
TECHNOCORE_AGENT_PRIVATE_KEY: "not-used"
}),
/does not match the Task Relay identity/
);
});

test("confirms a signed write after Technocore returns its plain-text room view", async () => {
const originalFetch = globalThis.fetch;
const pair = await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]);
Expand Down
3 changes: 0 additions & 3 deletions wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"ai": {
"binding": "AI"
},
"triggers": {
"crons": ["* * * * *"]
},
"vars": {
"WORKERS_AI_MODEL": "@cf/meta/llama-3.2-3b-instruct",
"TECHNOCORE_URL": "https://technocore.chat",
Expand Down
Loading