forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscenario-13-kernel.mjs
More file actions
152 lines (144 loc) · 5.66 KB
/
Copy pathscenario-13-kernel.mjs
File metadata and controls
152 lines (144 loc) · 5.66 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { rmSync } from "node:fs";
import { resolve } from "node:path";
import { AdapterRegistry } from "../dist/runtime/adapter-registry.js";
import { handleAgentControlToolCall } from "../dist/runtime/control-tools.js";
import { AgentRuntimeKernel } from "../dist/runtime/kernel.js";
import { SqliteAgentStore } from "../dist/runtime/sqlite-store.js";
const databasePath = resolve(process.argv[2] ?? "/tmp/omi-scenario-13-kernel.sqlite");
rmSync(databasePath, { force: true });
function openKernel() {
const store = new SqliteAgentStore({ databasePath, reconcileOnOpen: false });
const kernel = new AgentRuntimeKernel({
store,
registry: new AdapterRegistry(),
runtimeNodeId: "scenario-13-runtime",
});
return { store, kernel, context: { kernel, getOwnerId: () => "scenario-13-owner" } };
}
function parse(raw) {
const result = JSON.parse(raw);
if (result.ok !== true) throw new Error(JSON.stringify(result.error));
return result;
}
const evidence = [{ kind: "conversation", id: "conversation-friday", scope: "canonical" }];
const productContext = (latestEventSequence) => ({
canonicalSummary: "The Friday date is incorporated; approval is still pending.",
redactedCanonicalSummary: "The Friday date is incorporated; approval is still pending.",
summarySensitivityTier: "low",
latestEventSequence,
currentTask: { taskId: "scenario-13-task-review", title: "Review launch email", status: "active" },
selectedEvents: [{
eventId: "event-friday",
type: "conversation",
summary: "Launch date changed to Friday",
occurredAtMs: 1_783_676_400_000,
evidenceRefs: evidence,
sensitivityTier: "low",
}],
artifactHeads: [],
provenance: {
snapshotVersion: `workstream:${latestEventSequence}`,
fetchedAtMs: Date.now(),
source: "canonical_backend",
},
});
const first = openKernel();
const legacySurface = {
surfaceKind: "task_chat",
externalRefKind: "task",
externalRefId: "scenario-13-task-draft",
};
first.kernel.resolveSurfaceSession({ ownerId: "scenario-13-owner", surfaceRef: legacySurface });
first.kernel.importConversationTurns({
ownerId: "scenario-13-owner",
surfaceRef: legacySurface,
turns: [{ role: "user", content: "Draft the launch email", createdAtMs: 1_783_669_600_000 }],
});
const prepared = parse(await handleAgentControlToolCall(first.context, "prepare_workstream_continuity", {
workstreamId: "scenario-13-workstream",
taskIds: ["scenario-13-task-draft", "scenario-13-task-review"],
}));
const v1 = parse(await handleAgentControlToolCall(first.context, "persist_workstream_continuity", {
workstreamId: "scenario-13-workstream",
context: productContext(1),
artifacts: [{
logicalKey: "launch-email",
evidenceRefs: evidence,
kind: "email_draft",
role: "result",
uri: "file:///tmp/omi-scenario-13-email-v1.md",
contentHash: "sha256:scenario13-email-v1",
sourceArtifactId: "scenario-13-source-v1",
}],
}));
const v2 = parse(await handleAgentControlToolCall(first.context, "persist_workstream_continuity", {
workstreamId: "scenario-13-workstream",
context: productContext(3),
artifacts: [{
logicalKey: "launch-email",
evidenceRefs: evidence,
kind: "email_draft",
role: "result",
uri: "file:///tmp/omi-scenario-13-email-v2.md",
contentHash: "sha256:scenario13-email-v2",
sourceArtifactId: "scenario-13-source-v2",
}],
}));
const checkpoint = v2.checkpoint;
first.store.close();
const restarted = openKernel();
const resumed = parse(await handleAgentControlToolCall(restarted.context, "prepare_workstream_continuity", {
workstreamId: "scenario-13-workstream",
taskIds: ["scenario-13-task-draft", "scenario-13-task-review"],
checkpoint: {
checkpointId: checkpoint.checkpointId,
runtimeId: checkpoint.sourceRuntimeId,
lastEventSequence: checkpoint.lastEventSequence,
contextSummary: checkpoint.canonicalSummary,
evidenceRefs: checkpoint.evidenceRefs,
updatedAtMs: checkpoint.createdAtMs,
},
}));
const replay = parse(await handleAgentControlToolCall(restarted.context, "persist_workstream_continuity", {
workstreamId: "scenario-13-workstream",
context: productContext(3),
artifacts: [{
logicalKey: "launch-email",
evidenceRefs: evidence,
kind: "email_draft",
role: "result",
uri: "file:///tmp/omi-scenario-13-email-v2.md",
contentHash: "sha256:scenario13-email-v2",
sourceArtifactId: "scenario-13-source-v2",
}],
}));
const policy = parse(await handleAgentControlToolCall(restarted.context, "evaluate_desktop_tool_policy", {
requestedBundles: ["external.write_send"],
selectedBundles: ["external.write_send"],
externalSend: true,
operation: "send_email",
resourceRef: "workstream:scenario-13-workstream",
}));
const versions = restarted.store.allRows(
"SELECT logical_key, version, evidence_refs_json FROM workstream_artifact_versions ORDER BY version ASC",
);
const turns = restarted.store.getRow("SELECT COUNT(*) AS count FROM conversation_turns");
restarted.store.close();
process.stdout.write(JSON.stringify({
ok: true,
workstreamId: "scenario-13-workstream",
migratedTaskMappings: prepared.migration.migratedTaskMappings,
copiedTurns: prepared.migration.copiedTurns,
conversationTurnsAfterRestart: Number(turns.count),
versions: versions.map((row) => ({
logicalKey: String(row.logical_key),
version: Number(row.version),
cited: JSON.parse(String(row.evidence_refs_json)).length > 0,
})),
firstVersion: v1.artifactVersions[0]?.version,
secondVersion: v2.artifactVersions[0]?.version,
replayVersion: replay.artifactVersions[0]?.version,
resumedSessionId: resumed.session.agentSessionId,
queuedDeliveriesAfterRestart: resumed.deliveries.length,
externalSendDecision: policy.policy.decision,
}, null, 2));