Q15: show which messages each agent actually read
Runs record a context manifest once a model turn succeeds; the chat marks each human message with the agents that read its current version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
592ce69219
commit
469f2f2c35
14 files changed
+144
-10
No files matched your search
@@ -24,7 +24,7 @@ describe("domain services", () => {
|
||||
const connection = createConnection();
|
||||
|
||||
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
|
||||
expect(rows.map((row) => row.version)).toEqual([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]);
|
||||
expect(rows.map((row) => row.version)).toEqual([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]);
|
||||
connection.close();
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { messageReaders } from "../../src/renderer/src/pages/chat/chat-helpers";
|
||||
import type { AgentRecord, ChatMessageRecord, TaskRunRecord } from "../../src/shared/domain";
|
||||
|
||||
function run(agentId: string | null, contextJson: string | null): TaskRunRecord {
|
||||
return {
|
||||
id: `run_${Math.random()}`, orgId: "org", taskId: "tsk", agentId, providerId: null, providerRequestId: null,
|
||||
executionContextId: null, serviceIdentityId: null, workspaceMountJson: "[]", secretScopeJson: "{}",
|
||||
trigger: "chat_mention", state: "completed", createdAt: "", startedAt: null, completedAt: null, errorMessage: null, contextJson,
|
||||
};
|
||||
}
|
||||
|
||||
function message(id: string, createdAt: string, editedAt: string | null = null): ChatMessageRecord {
|
||||
return { id, createdAt, editedAt } as ChatMessageRecord;
|
||||
}
|
||||
|
||||
const agents = [{ id: "a1", name: "CEO" }, { id: "a2", name: "Dana" }] as AgentRecord[];
|
||||
const entry = (id: string, version: string) => ({ id, version });
|
||||
const manifest = (history: object[], fresh: object[], midRun: object[]) =>
|
||||
JSON.stringify({ threadId: "t", history, fresh, omittedCount: 0, midRun });
|
||||
|
||||
describe("message readers", () => {
|
||||
test("collects each agent once per message across history, fresh, and mid-run entries", () => {
|
||||
const messages = [message("m1", "t1"), message("m2", "t2"), message("m3", "t3")];
|
||||
const readers = messageReaders([
|
||||
run("a1", manifest([entry("m1", "t1")], [entry("m2", "t2")], [entry("m3", "t3")])),
|
||||
run("a1", manifest([entry("m2", "t2")], [], [])),
|
||||
run("a2", manifest([], [entry("m2", "t2")], [])),
|
||||
run("a2", null),
|
||||
run(null, manifest([entry("m1", "t1")], [], [])),
|
||||
], agents, messages);
|
||||
expect(Object.fromEntries(readers)).toEqual({ m1: ["CEO"], m2: ["CEO", "Dana"], m3: ["CEO"] });
|
||||
});
|
||||
|
||||
test("a message edited after it was read is unread until a run sees the new version", () => {
|
||||
const messages = [message("m1", "t1", "t9")];
|
||||
expect(messageReaders([run("a1", manifest([], [entry("m1", "t1")], []))], agents, messages).size).toBe(0);
|
||||
expect(Object.fromEntries(messageReaders([run("a1", manifest([], [entry("m1", "t9")], []))], agents, messages))).toEqual({ m1: ["CEO"] });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user