330db43b5f
Each turn (assistant response / tool result) is appended to a JSONL file at ~/.uncaged/workflow/sessions/<sessionId>.jsonl during the loop. On completion, the JSONL is read back, each turn is stored as a CAS node, and the detail payload references them as a flat turns[] array in chronological order. The session file is then deleted. Benefits: - Real-time observability: tail -f the JSONL to watch loop progress - Crash recovery: partial JSONL survives process death - Zero write contention: one file per session - Detail stays a flat array for easy consumption by CLI/dashboard Changes: - New session.ts: initSessionDir, appendSessionTurn, readSessionTurns, removeSession - loop.ts: append JSONL each turn instead of accumulating in-memory - detail.ts: reads session JSONL → persists turns to CAS → stores detail - agent.ts: passes storageRoot/sessionId to loop, cleans up session on completion - types.ts: remove index from TurnPayload (order is implicit in JSONL/array) - schemas.ts: sync with type changes Ref: #433
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import type { JSONSchema } from "@uncaged/json-cas";
|
|
|
|
const BUILTIN_TOOL_CALL_SCHEMA: JSONSchema = {
|
|
type: "object",
|
|
required: ["name", "args"],
|
|
properties: {
|
|
name: { type: "string" },
|
|
args: { type: "string" },
|
|
},
|
|
additionalProperties: false,
|
|
};
|
|
|
|
export const BUILTIN_TURN_SCHEMA: JSONSchema = {
|
|
title: "builtin-turn",
|
|
type: "object",
|
|
required: ["role", "content"],
|
|
properties: {
|
|
role: { type: "string", enum: ["assistant", "tool"] },
|
|
content: { type: "string" },
|
|
toolCalls: {
|
|
anyOf: [{ type: "array", items: BUILTIN_TOOL_CALL_SCHEMA }, { type: "null" }],
|
|
},
|
|
reasoning: {
|
|
anyOf: [{ type: "string" }, { type: "null" }],
|
|
},
|
|
},
|
|
additionalProperties: false,
|
|
};
|
|
|
|
export const BUILTIN_DETAIL_SCHEMA: JSONSchema = {
|
|
title: "builtin-detail",
|
|
type: "object",
|
|
required: ["sessionId", "model", "duration", "turnCount", "turns"],
|
|
properties: {
|
|
sessionId: { type: "string" },
|
|
model: { type: "string" },
|
|
duration: { type: "integer" },
|
|
turnCount: { type: "integer" },
|
|
turns: {
|
|
type: "array",
|
|
items: { type: "string", format: "cas_ref" },
|
|
},
|
|
},
|
|
additionalProperties: false,
|
|
};
|