-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimal-harness.mjs
More file actions
70 lines (61 loc) · 2.56 KB
/
Copy pathminimal-harness.mjs
File metadata and controls
70 lines (61 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { createThreadMeshClient } from "@fyaic/threadmesh";
function required(name) {
const value = process.env[name];
if (!value) throw new Error(`Missing ${name}`);
return value;
}
const endpoint = required("THREADMESH_URL");
function client(token, idPrefix) {
return createThreadMeshClient({
authorization: `Bearer ${token}`,
idPrefix,
send: async (request, { authorization }) => {
const response = await fetch(endpoint, {
method: "POST",
headers: { authorization, "content-type": "application/json" },
body: JSON.stringify(request),
});
if (!response.ok) throw new Error(`ThreadMesh transport failed: ${response.status}`);
return response.json();
},
});
}
const owner = client(required("THREADMESH_OWNER_TOKEN"), "owner");
const sender = client(required("THREADMESH_SENDER_TOKEN"), "sender");
const receiver = client(required("THREADMESH_RECEIVER_TOKEN"), "receiver");
const source = {
taskId: required("THREADMESH_SOURCE_TASK_ID"),
incarnationId: required("THREADMESH_SOURCE_INCARNATION_ID"),
harness: "example-harness",
};
const target = {
taskId: required("THREADMESH_TARGET_TASK_ID"),
incarnationId: required("THREADMESH_TARGET_INCARNATION_ID"),
harness: "example-harness",
};
const relationshipId = required("THREADMESH_RELATIONSHIP_ID");
// An owner or policy principal registers task incarnations. Relationship grants
// are intentionally provisioned outside the harness integration path.
await owner.registerTask({ ...source, state: "running" });
await owner.registerTask({ ...target, state: "waiting" });
// A sender sees only the target summary already published for this exact grant.
const related = await sender.discoverRelated({ task: target, relationshipId });
if (related.coordination.intents.includes("suggest")) {
await sender.sendSuggestion({
messageId: `msg_example_${Date.now()}`,
from: source,
to: target,
relationshipId,
content: "The upstream artifact checksum is sha256:example.",
reason: "The receiver declared this upstream artifact as a dependency.",
ttlMs: 5 * 60 * 1000,
});
}
// Poll at a harness checkpoint. Content is not model-visible until the receiver
// accepts it and applies its own provenance-preserving rendering policy.
const page = await receiver.pollMailbox({ receiver: target });
for (const message of page.messages) {
const decision = message.envelope.intent === "suggest" ? "accepted" : "rejected";
await receiver.decide({ message, decision });
}
console.log(JSON.stringify({ handled: page.messages.length, nextCursor: page.nextCursor }));