feat(runtime): establish miniapp kernel and sdk design

This commit is contained in:
2026-08-05 00:46:16 +08:00
parent d8aa087bc8
commit 9fb8cd1598
86 changed files with 4615 additions and 1364 deletions
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { TaskStateMachine } from "@/runtime/coordination/task-state";
const TIME = "2026-08-03T09:00:00.000Z";
describe("TaskStateMachine", () => {
it("projects repeated progress updates into one task record", () => {
const tasks = new TaskStateMachine();
tasks.receive({ operation_id: "task_001", title: "Generate report", percent: 20, status: "running", cancellable: true }, "conversation_001", TIME);
tasks.receive({ operation_id: "task_001", title: "Generate report", percent: 80, status: "running", cancellable: true }, "conversation_001", "2026-08-03T09:01:00.000Z");
expect(tasks.snapshot()).toEqual([expect.objectContaining({ operation_id: "task_001", percent: 80, status: "running" })]);
});
it("records one local cancellation request and lets the Agent close it as cancelled", () => {
const tasks = new TaskStateMachine();
tasks.receive({ operation_id: "task_002", title: "Export", percent: 40, status: "running", cancellable: true }, "conversation_001", TIME);
expect(tasks.requestCancel("task_002", "2026-08-03T09:01:00.000Z")).toMatchObject({ disposition: "accepted", record: { cancel_requested_at: "2026-08-03T09:01:00.000Z" } });
expect(tasks.requestCancel("task_002", "2026-08-03T09:02:00.000Z").disposition).toBe("invalid_transition");
tasks.receive({ operation_id: "task_002", title: "Export", percent: 40, status: "cancelled", cancellable: false }, "conversation_001", "2026-08-03T09:03:00.000Z");
expect(tasks.get("task_002")).toMatchObject({ status: "cancelled" });
expect(tasks.get("task_002")).not.toHaveProperty("cancel_requested_at");
});
});