Add agent task sessions table, session types, and programmatic DB backup

Add agent_task_sessions table for per-task session state keyed by
(agent, adapter, taskKey). Add AgentTaskSession type, resetAgentSessionSchema
validator, and sessionDisplayId/sessionParamsJson to AgentRuntimeState.

Rework migration hash-resolution fallback ordering to prefer hash-based
matching over timestamp-based journal matching. Move backup-db.sh logic
into packages/db/src/backup.ts for programmatic use and simplify the shell
script to call the TypeScript implementation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten
2026-02-19 14:01:40 -06:00
parent 61db74d525
commit 4e3da49116
13 changed files with 3720 additions and 91 deletions

View File

@@ -51,6 +51,7 @@ export type {
HeartbeatRun,
HeartbeatRunEvent,
AgentRuntimeState,
AgentTaskSession,
AgentWakeupRequest,
LiveEvent,
DashboardSummary,
@@ -68,6 +69,7 @@ export {
updateAgentSchema,
createAgentKeySchema,
wakeAgentSchema,
resetAgentSessionSchema,
agentPermissionsSchema,
updateAgentPermissionsSchema,
type CreateAgent,
@@ -75,6 +77,7 @@ export {
type UpdateAgent,
type CreateAgentKey,
type WakeAgent,
type ResetAgentSession,
type UpdateAgentPermissions,
createProjectSchema,
updateProjectSchema,

View File

@@ -56,6 +56,8 @@ export interface AgentRuntimeState {
companyId: string;
adapterType: string;
sessionId: string | null;
sessionDisplayId?: string | null;
sessionParamsJson?: Record<string, unknown> | null;
stateJson: Record<string, unknown>;
lastRunId: string | null;
lastRunStatus: string | null;
@@ -68,6 +70,20 @@ export interface AgentRuntimeState {
updatedAt: Date;
}
export interface AgentTaskSession {
id: string;
companyId: string;
agentId: string;
adapterType: string;
taskKey: string;
sessionParamsJson: Record<string, unknown> | null;
sessionDisplayId: string | null;
lastRunId: string | null;
lastError: string | null;
createdAt: Date;
updatedAt: Date;
}
export interface AgentWakeupRequest {
id: string;
companyId: string;

View File

@@ -9,6 +9,7 @@ export type {
HeartbeatRun,
HeartbeatRunEvent,
AgentRuntimeState,
AgentTaskSession,
AgentWakeupRequest,
} from "./heartbeat.js";
export type { LiveEvent } from "./live.js";

View File

@@ -59,6 +59,12 @@ export const wakeAgentSchema = z.object({
export type WakeAgent = z.infer<typeof wakeAgentSchema>;
export const resetAgentSessionSchema = z.object({
taskKey: z.string().min(1).optional().nullable(),
});
export type ResetAgentSession = z.infer<typeof resetAgentSessionSchema>;
export const updateAgentPermissionsSchema = z.object({
canCreateAgents: z.boolean(),
});

View File

@@ -11,6 +11,7 @@ export {
updateAgentSchema,
createAgentKeySchema,
wakeAgentSchema,
resetAgentSessionSchema,
agentPermissionsSchema,
updateAgentPermissionsSchema,
type CreateAgent,
@@ -18,6 +19,7 @@ export {
type UpdateAgent,
type CreateAgentKey,
type WakeAgent,
type ResetAgentSession,
type UpdateAgentPermissions,
} from "./agent.js";