mirror of
https://github.com/saltbo/agent-kanban.git
synced 2026-09-19 09:01:47 +08:00
a2fa54a729
Replace the v1 Agent/Machine runtime and CLI architecture with the v2 Resource Server, AMA-backed projections, task lifecycle, session observation, BDD specifications, and a single-package layered codebase. BREAKING CHANGE: remove the v1 CLI, internal Agent/Machine runtime entities, workspace layout, and legacy runtime coordination APIs.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import type { D1 } from "@server/db";
|
|
import type { TaskEventRepository, TaskEventSnapshot } from "@server/usecases/tasks/waitForTaskEvents";
|
|
import type { Task } from "@shared";
|
|
import { mapTaskRow } from "./taskRow";
|
|
|
|
type TaskEventRow = Task & { event_offset: number };
|
|
|
|
export function d1TaskEventRepository(db: D1): TaskEventRepository {
|
|
return {
|
|
async readSnapshot(ownerId: string, taskIds: string[]): Promise<TaskEventSnapshot | null> {
|
|
const result = await db
|
|
.prepare(`
|
|
WITH requested(id) AS (
|
|
SELECT CAST(value AS TEXT) FROM json_each(?)
|
|
)
|
|
SELECT t.*, COALESCE((
|
|
SELECT MAX(event.sequence)
|
|
FROM task_event_offsets event
|
|
WHERE event.task_id IN (SELECT id FROM requested)
|
|
), 0) AS event_offset
|
|
FROM tasks t
|
|
JOIN boards b ON b.id = t.board_id
|
|
WHERE b.owner_id = ? AND t.id IN (SELECT id FROM requested)
|
|
`)
|
|
.bind(JSON.stringify(taskIds), ownerId)
|
|
.all<TaskEventRow>();
|
|
|
|
if (result.results.length !== taskIds.length) return null;
|
|
const byId = new Map(
|
|
result.results.map((row) => {
|
|
const { event_offset: _eventOffset, ...task } = row;
|
|
return [row.id, task as Task] as const;
|
|
}),
|
|
);
|
|
const tasks = taskIds.map((taskId) => mapTaskRow(byId.get(taskId)!));
|
|
return { tasks, offset: result.results[0]?.event_offset ?? 0 };
|
|
},
|
|
};
|
|
}
|