Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: use task type and add session resume

Gusb6d40207690b
diff --git a/src/cli/daemon/client.test.ts b/src/cli/daemon/client.test.ts
index ca2f46c57..f93d737b4 100644
--- a/src/cli/daemon/client.test.ts
+++ b/src/cli/daemon/client.test.ts
@@ -26,8 +26,8 @@ describe("DaemonClient claimTask schema validation", () => {
result: null,
error: null,
created_at: "2024-01-01T00:00:00Z",
+ type: "user_dm_message",
agent: { instructions: "help", name: "bot", runtime_config: {} },
- prior_session_id: "sess-0",
},
};
@@ -69,6 +69,7 @@ function validClaimResponse() {
result: null,
error: null,
created_at: "2024-01-01T00:00:00Z",
+ type: "user_dm_message",
},
};
}
@@ -182,8 +183,8 @@ function validApiTask(): TaskApi {
result: null,
error: null,
created_at: "2024-01-01T00:00:00Z",
+ type: "user_dm_message",
agent: { instructions: "help", name: "bot", runtime_config: {} },
- prior_session_id: "sess-0",
};
}
@@ -198,9 +199,9 @@ describe("fromApiTask", () => {
expect(task.prompt).toBe("do it");
expect(task.status).toBe("dispatched");
expect(task.priority).toBe(1);
+ expect(task.type).toBe("user_dm_message");
expect(task.agent?.name).toBe("bot");
expect(task.agent?.instructions).toBe("help");
- expect(task.priorSessionId).toBe("sess-0");
expect(task.createdAt).toBe("2024-01-01T00:00:00Z");
});
diff --git a/src/cli/daemon/daemon.test.ts b/src/cli/daemon/daemon.test.ts
index dcd05241b..e7ccc3ea2 100644
--- a/src/cli/daemon/daemon.test.ts
+++ b/src/cli/daemon/daemon.test.ts
@@ -101,6 +101,7 @@ vi.mock("./execenv/timeline.js", () => ({
initEntryAsync: (...args: any[]) => mockInitEntryAsync(...args),
updateEntry: (...args: any[]) => mockUpdateEntry(...args),
createTimelineEntry: (...args: any[]) => mockCreateTimelineEntry(...args),
+ findResumableSessionId: vi.fn(() => null),
}));
// Capture signal handlers and prevent actual process.exit
@@ -163,10 +164,10 @@ describe("daemon timeline integration", () => {
started_at: null,
completed_at: null,
created_at: "2026-01-01T00:00:00Z",
+ type: "user_dm_message",
result: null,
error: null,
agent: { name: "Agent 1", instructions: "be helpful" },
- prior_session_id: null,
};
let claimed = false;
diff --git a/src/cli/daemon/daemon.ts b/src/cli/daemon/daemon.ts
index 5732c8d8e..55e778489 100644
--- a/src/cli/daemon/daemon.ts
+++ b/src/cli/daemon/daemon.ts
@@ -5,7 +5,7 @@ import { buildPrompt } from "./prompt.js";
import { createBackend, detectVersion } from "./agent/index.js";
import { type Task, type TaskResult, fromApiTask } from "./types.js";
import { prepare } from "./execenv/index.js";
-import { initEntryAsync, updateEntry, createTimelineEntry, localISOString } from "./execenv/timeline.js";
+import { initEntryAsync, updateEntry, createTimelineEntry, localISOString, findResumableSessionId } from "./execenv/timeline.js";
import { loadCLIConfigForProfile } from "../lib/config.js";
import { log } from "../lib/logger.js";
import { cmdPrefix } from "../lib/env.js";
@@ -236,11 +236,17 @@ async function runTask(
task,
);
+ const resumeSessionId = findResumableSessionId(timelineDir, task.type) ?? undefined;
+ if (resumeSessionId) {
+ log.info(`Task ${task.id} resuming session ${resumeSessionId}`);
+ }
+
const session = backend.execute(prompt, {
cwd: workDir,
model: model || undefined,
env,
timeout: config.agentTimeout,
+ resumeSessionId,
});
// Context timeline — wait for session ID, then write init entry
diff --git a/src/cli/daemon/execenv/__tests__/context.test.ts b/src/cli/daemon/execenv/__tests__/context.test.ts
index 65bd1771b..f589d67f6 100644
--- a/src/cli/daemon/execenv/__tests__/context.test.ts
+++ b/src/cli/daemon/execenv/__tests__/context.test.ts
@@ -39,49 +39,27 @@ function makeTask(overrides: Partial<Task> = {}): Task {
}
describe("buildInstructionContent", () => {
- it("assembles header + agent instructions + context timeline", () => {
+ it("appends agent instructions when present", () => {
const task = makeTask();
const content = buildInstructionContent(task);
- expect(content).toContain("# Alook Agent");
expect(content).toContain("## Agent Instructions");
expect(content).toContain("Be helpful and concise.");
- expect(content).toContain("## Context Timeline");
});
- it("with task.agent undefined — omits agent instructions section", () => {
+ it("omits agent instructions section when agent is undefined", () => {
const task = makeTask({ agent: undefined });
const content = buildInstructionContent(task);
- expect(content).toContain("# Alook Agent");
expect(content).not.toContain("## Agent Instructions");
});
- it("with empty instructions string — omits agent instructions section", () => {
+ it("omits agent instructions section when instructions is empty", () => {
const task = makeTask({ agent: { name: "test", instructions: "" } });
const content = buildInstructionContent(task);
- expect(content).toContain("# Alook Agent");
expect(content).not.toContain("## Agent Instructions");
});
-
- it("includes Context Timeline section with format explanation", () => {
- const task = makeTask();
- const content = buildInstructionContent(task);
-
- expect(content).toContain("## Context Timeline");
- expect(content).toContain(".context_timeline/YYYY-MM-DD.jsonl");
- expect(content).toContain("task_id");
- expect(content).toContain("session_id");
- expect(content).toContain("pid");
- expect(content).toContain("status");
- expect(content).toContain("datetime");
- expect(content).toContain("prompt");
- expect(content).toContain("steps");
- expect(content).toContain("response");
- expect(content).toContain("errmsg");
- expect(content).toContain("last ~20 lines");
- });
});
describe("contentHash", () => {
@@ -210,7 +188,7 @@ describe("writeInstructionFileIfChanged", () => {
expect(result).toBe(true);
expect(existsSync(join(workDir, CANONICAL_FILE))).toBe(true);
const content = readFileSync(join(workDir, CANONICAL_FILE), "utf-8");
- expect(content).toContain("# Alook Agent");
+ expect(content).toContain("## Memory Management");
expect(content).toContain("Be helpful and concise.");
});
diff --git a/src/cli/daemon/execenv/__tests__/index.test.ts b/src/cli/daemon/execenv/__tests__/index.test.ts
index b00f49fdd..30c1a0c92 100644
--- a/src/cli/daemon/execenv/__tests__/index.test.ts
+++ b/src/cli/daemon/execenv/__tests__/index.test.ts
@@ -55,7 +55,6 @@ describe("prepare", () => {
const agentsPath = join(result.workDir, CANONICAL_FILE);
expect(existsSync(agentsPath)).toBe(true);
const content = readFileSync(agentsPath, "utf-8");
- expect(content).toContain("# Alook Agent");
expect(content).toContain("Be helpful.");
const claudePath = join(result.workDir, "CLAUDE.md");
diff --git a/src/cli/daemon/execenv/__tests__/timeline.test.ts b/src/cli/daemon/execenv/__tests__/timeline.test.ts
index aca472966..387ffde51 100644
--- a/src/cli/daemon/execenv/__tests__/timeline.test.ts
+++ b/src/cli/daemon/execenv/__tests__/timeline.test.ts
@@ -12,6 +12,7 @@ import {
initEntry,
updateEntry,
createTimelineEntry,
+ findResumableSessionId,
_todayFilename,
_localISOString,
_filenameForDate,
@@ -243,4 +244,182 @@ describe("timeline", () => {
const todayEntries = JSON.parse(readFileSync(join(dir, _todayFilename()), "utf-8").trimEnd());
expect(todayEntries.steps).toEqual([]);
});
+
+ describe("findResumableSessionId", () => {
+ function writeEntry(filename: string, entry: ContextTimelineEntry) {
+ const filePath = join(dir, filename);
+ let existing = "";
+ try { existing = readFileSync(filePath, "utf-8"); } catch { /* new file */ }
+ writeFileSync(filePath, existing + JSON.stringify(entry) + "\n");
+ }
+
+ function makeEntry(overrides: Partial<ContextTimelineEntry>): ContextTimelineEntry {
+ return {
+ task_id: "t_1",
+ session_id: null,
+ pid: null,
+ status: "running",
+ datetime: new Date().toISOString(),
+ type: "user_dm_message",
+ prompt: "test",
+ steps: [],
+ response: null,
+ errmsg: null,
+ ...overrides,
+ };
+ }
+
+ it("returns session_id from a completed entry of matching type within 3h", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_1",
+ status: "completed",
+ session_id: "sess_abc",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBe("sess_abc");
+ });
+
+ it("returns null when no entries exist", () => {
+ expect(findResumableSessionId(dir, "user_dm_message")).toBeNull();
+ });
+
+ it("returns null when no timeline files exist", () => {
+ rmSync(dir, { recursive: true, force: true });
+ mkdirSync(dir, { recursive: true });
+ expect(findResumableSessionId(dir, "user_dm_message")).toBeNull();
+ });
+
+ it("returns null when the latest completed entry is older than 3h", () => {
+ const fourHoursAgo = new Date(Date.now() - 4 * 60 * 60 * 1000);
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_old",
+ status: "completed",
+ session_id: "sess_old",
+ datetime: fourHoursAgo.toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBeNull();
+ });
+
+ it("returns null when session_id is null on the entry", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_nosess",
+ status: "completed",
+ session_id: null,
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBeNull();
+ });
+
+ it("skips failed/running entries and finds the correct completed one", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_completed",
+ status: "completed",
+ session_id: "sess_good",
+ datetime: new Date().toISOString(),
+ }));
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_running",
+ status: "running",
+ session_id: null,
+ datetime: new Date().toISOString(),
+ }));
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_failed",
+ status: "failed",
+ session_id: "sess_bad",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBe("sess_good");
+ });
+
+ it("searches across midnight boundary (yesterday's file)", () => {
+ const yesterday = new Date();
+ yesterday.setDate(yesterday.getDate() - 1);
+ const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);
+
+ writeEntry(_filenameForDate(yesterday), makeEntry({
+ task_id: "t_yesterday",
+ status: "completed",
+ session_id: "sess_yesterday",
+ datetime: twoHoursAgo.toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBe("sess_yesterday");
+ });
+
+ it("returns the latest match, not the first one in file order", () => {
+ const oneHourAgo = new Date(Date.now() - 1 * 60 * 60 * 1000);
+ const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);
+
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_older",
+ status: "completed",
+ session_id: "sess_older",
+ datetime: twoHoursAgo.toISOString(),
+ }));
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_newer",
+ status: "completed",
+ session_id: "sess_newer",
+ datetime: oneHourAgo.toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBe("sess_newer");
+ });
+
+ it("respects custom maxAgeMs parameter", () => {
+ const thirtyMinAgo = new Date(Date.now() - 30 * 60 * 1000);
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_recent",
+ status: "completed",
+ session_id: "sess_recent",
+ datetime: thirtyMinAgo.toISOString(),
+ }));
+
+ // 10 minute window — entry is 30 min old, should not match
+ expect(findResumableSessionId(dir, "user_dm_message", 10 * 60 * 1000)).toBeNull();
+ // 60 minute window — entry is 30 min old, should match
+ expect(findResumableSessionId(dir, "user_dm_message", 60 * 60 * 1000)).toBe("sess_recent");
+ });
+
+ it("does not match a different task type", () => {
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_1",
+ status: "completed",
+ session_id: "sess_dm",
+ type: "user_dm_message",
+ datetime: new Date().toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "scheduled_check")).toBeNull();
+ });
+
+ it("finds the latest entry across midnight boundary correctly", () => {
+ const yesterday = new Date();
+ yesterday.setDate(yesterday.getDate() - 1);
+ const ninetyMinAgo = new Date(Date.now() - 90 * 60 * 1000);
+ const thirtyMinAgo = new Date(Date.now() - 30 * 60 * 1000);
+
+ // Yesterday's entry is older but still within 3h
+ writeEntry(_filenameForDate(yesterday), makeEntry({
+ task_id: "t_yesterday",
+ status: "completed",
+ session_id: "sess_yesterday",
+ datetime: ninetyMinAgo.toISOString(),
+ }));
+ // Today's entry is newer
+ writeEntry(_todayFilename(), makeEntry({
+ task_id: "t_today",
+ status: "completed",
+ session_id: "sess_today",
+ datetime: thirtyMinAgo.toISOString(),
+ }));
+
+ expect(findResumableSessionId(dir, "user_dm_message")).toBe("sess_today");
+ });
+ });
});
diff --git a/src/cli/daemon/execenv/index.ts b/src/cli/daemon/execenv/index.ts
index 08d93e96c..d555f754f 100644
--- a/src/cli/daemon/execenv/index.ts
+++ b/src/cli/daemon/execenv/index.ts
@@ -47,3 +47,4 @@ export function prepare(
}
export { buildInstructionContent, writeInstructionFileIfChanged, ensureSymlinks, CANONICAL_FILE } from "./context.js";
+export { findResumableSessionId } from "./timeline.js";
diff --git a/src/cli/daemon/execenv/timeline.ts b/src/cli/daemon/execenv/timeline.ts
index 184ea8470..4526b0927 100644
--- a/src/cli/daemon/execenv/timeline.ts
+++ b/src/cli/daemon/execenv/timeline.ts
@@ -3,13 +3,30 @@ import { join } from "path";
import { acquireLock, releaseLock } from "./filelock.js";
import { log } from "../../lib/logger.js";
+function readJsonl(filePath: string): ContextTimelineEntry[] {
+ let content: string;
+ try {
+ content = readFileSync(filePath, "utf-8");
+ } catch {
+ return [];
+ }
+ const entries: ContextTimelineEntry[] = [];
+ for (const line of content.trimEnd().split("\n")) {
+ if (!line) continue;
+ try {
+ entries.push(JSON.parse(line));
+ } catch { /* skip malformed */ }
+ }
+ return entries;
+}
+
export interface ContextTimelineEntry {
task_id: string;
session_id: string | null;
pid: number | null;
status: "running" | "completed" | "failed";
datetime: string;
- type: "user_dm_message";
+ type: string;
prompt: string;
steps: string[];
response: string | null;
@@ -191,6 +208,39 @@ export function createTimelineEntry(
};
}
+const DEFAULT_RESUME_MAX_AGE_MS = 3 * 60 * 60 * 1000; // 3 hours
+
+export function findResumableSessionId(
+ timelineDir: string,
+ type: string,
+ maxAgeMs: number = DEFAULT_RESUME_MAX_AGE_MS,
+): string | null {
+ const now = new Date();
+ const cutoff = new Date(now.getTime() - maxAgeMs);
+
+ const daysToScan = Math.ceil(maxAgeMs / 86_400_000) + 1;
+ const entries: ContextTimelineEntry[] = [];
+ for (const filename of recentFilenames(daysToScan)) {
+ entries.push(...readJsonl(join(timelineDir, filename)));
+ }
+
+ // Sort by datetime descending, pick the first completed match
+ entries.sort((a, b) => new Date(b.datetime).getTime() - new Date(a.datetime).getTime());
+
+ for (const entry of entries) {
+ if (
+ entry.status === "completed" &&
+ entry.type === type &&
+ entry.session_id &&
+ new Date(entry.datetime) >= cutoff
+ ) {
+ return entry.session_id;
+ }
+ }
+
+ return null;
+}
+
export { localISOString };
// Exported for testing
diff --git a/src/cli/daemon/types.ts b/src/cli/daemon/types.ts
index 3590dc657..36b208750 100644
--- a/src/cli/daemon/types.ts
+++ b/src/cli/daemon/types.ts
@@ -7,8 +7,8 @@ export interface Task {
prompt: string;
status: string;
priority: number;
+ type: string;
agent?: TaskAgentData;
- priorSessionId?: string;
repos?: RepoData[];
createdAt: string;
}
@@ -85,10 +85,10 @@ export function fromApiTask(api: import("@alook/shared").TaskApi): Task {
prompt: api.prompt,
status: api.status,
priority: api.priority,
+ type: api.type,
agent: api.agent
? { name: api.agent.name, instructions: api.agent.instructions }
: undefined,
- priorSessionId: api.prior_session_id ?? undefined,
repos: undefined,
createdAt: api.created_at,
};
diff --git a/src/shared/schemas.test.ts b/src/shared/schemas.test.ts
index 98f65c60c..e2ebb5e45 100644
--- a/src/shared/schemas.test.ts
+++ b/src/shared/schemas.test.ts
@@ -44,6 +44,7 @@ function validRow() {
workspaceId: "w1",
conversationId: "c1",
prompt: "do something",
+ type: "user_dm_message",
status: "dispatched",
priority: 5,
result: null,
@@ -104,6 +105,7 @@ function validTaskApiBase() {
result: null,
error: null,
created_at: "2024-01-01T00:00:00Z",
+ type: "user_dm_message",
};
}
@@ -126,15 +128,13 @@ describe("TaskApiBaseSchema", () => {
// ---------------------------------------------------------------------------
describe("TaskApiSchema", () => {
- it("accepts optional agent and prior_session_id", () => {
+ it("accepts optional agent", () => {
const input = {
...validTaskApiBase(),
agent: { instructions: "be helpful", name: "bot", runtime_config: {} },
- prior_session_id: "sess-0",
};
const parsed = TaskApiSchema.parse(input);
expect(parsed.agent?.name).toBe("bot");
- expect(parsed.prior_session_id).toBe("sess-0");
});
});
diff --git a/src/shared/schemas.ts b/src/shared/schemas.ts
index 869df6f95..ca2fae31d 100644
--- a/src/shared/schemas.ts
+++ b/src/shared/schemas.ts
@@ -28,6 +28,7 @@ export const ClaimedTaskRowSchema = z.object({
priority: z.coerce.number(),
result: z.unknown().nullable(),
context: z.unknown().nullable(),
+ type: z.string().default("user_dm_message"),
sessionId: z.string().nullable(),
createdAt: z.coerce.date(),
dispatchedAt: z.coerce.date().nullable(),
@@ -67,6 +68,7 @@ export const TaskApiBaseSchema = z.object({
result: z.unknown().nullable(),
error: z.string().nullable(),
created_at: z.string(),
+ type: z.string(),
});
export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
@@ -76,7 +78,6 @@ export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
export const TaskApiSchema = TaskApiBaseSchema.extend({
agent: TaskAgentDataApiSchema.nullable().optional(),
- prior_session_id: z.string().nullable().optional(),
});
export type TaskApi = z.infer<typeof TaskApiSchema>;
diff --git a/src/shared/src/db/queries/task.ts b/src/shared/src/db/queries/task.ts
index 9aa1321c5..4cd7b0b63 100644
--- a/src/shared/src/db/queries/task.ts
+++ b/src/shared/src/db/queries/task.ts
@@ -11,6 +11,7 @@ export async function createTask(
workspaceId: string;
conversationId: string;
prompt: string;
+ type?: string;
priority?: number;
}
) {
@@ -22,6 +23,7 @@ export async function createTask(
workspaceId: data.workspaceId,
conversationId: data.conversationId,
prompt: data.prompt,
+ type: data.type ?? "user_dm_message",
priority: data.priority ?? 0,
})
.returning();
diff --git a/src/shared/src/db/schema.ts b/src/shared/src/db/schema.ts
index e53e8b2a4..f9c3cdc02 100644
--- a/src/shared/src/db/schema.ts
+++ b/src/shared/src/db/schema.ts
@@ -213,6 +213,7 @@ export const agentTaskQueue = sqliteTable(
.notNull()
.references(() => conversation.id),
prompt: text("prompt").notNull(),
+ type: text("type").notNull().default("user_dm_message"),
status: text("status").notNull().default("queued"),
priority: integer("priority").notNull().default(0),
result: text("result", { mode: "json" }),
diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.ts
index 884aef78f..0303fda86 100644
--- a/src/shared/src/schemas.ts
+++ b/src/shared/src/schemas.ts
@@ -28,6 +28,7 @@ export const ClaimedTaskRowSchema = z.object({
priority: z.coerce.number(),
result: z.unknown().nullable(),
context: z.unknown().nullable(),
+ type: z.string().default("user_dm_message"),
sessionId: z.string().nullable(),
createdAt: z.coerce.date(),
dispatchedAt: z.coerce.date().nullable(),
@@ -67,6 +68,7 @@ export const TaskApiBaseSchema = z.object({
result: z.unknown().nullable(),
error: z.string().nullable(),
created_at: z.string(),
+ type: z.string(),
});
export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
@@ -76,7 +78,6 @@ export type TaskApiBase = z.infer<typeof TaskApiBaseSchema>;
export const TaskApiSchema = TaskApiBaseSchema.extend({
agent: TaskAgentDataApiSchema.nullable().optional(),
- prior_session_id: z.string().nullable().optional(),
});
export type TaskApi = z.infer<typeof TaskApiSchema>;
diff --git a/src/shared/src/types.ts b/src/shared/src/types.ts
index 574f680ac..fd8992337 100644
--- a/src/shared/src/types.ts
+++ b/src/shared/src/types.ts
@@ -80,7 +80,7 @@ export interface AgentTask {
error: string | null;
agent?: TaskAgentData;
created_at: string;
- prior_session_id?: string;
+ type: string;
}
export interface TaskAgentData {
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 2985bb36d..692a2a31e 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -79,7 +79,7 @@ export interface AgentTask {
error: string | null;
agent?: TaskAgentData;
created_at: string;
- prior_session_id?: string;
+ type: string;
}
export interface TaskAgentData {
diff --git a/src/web/migrations/0004_add_task_type.sql b/src/web/migrations/0004_add_task_type.sql
new file mode 100644
index 000000000..a58b29235
--- /dev/null
+++ b/src/web/migrations/0004_add_task_type.sql
@@ -0,0 +1 @@
+ALTER TABLE agent_task_queue ADD COLUMN type TEXT NOT NULL DEFAULT 'user_dm_message';
diff --git a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
index 1d0cfe7bd..29b960e10 100644
--- a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
+++ b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.test.ts
@@ -64,7 +64,7 @@ describe("POST /api/daemon/runtimes/[runtimeId]/tasks/claim", () => {
expect(mockClaimTaskForRuntime).toHaveBeenCalledWith("rt1");
});
- it("returns task with agent data and prior_session_id always null", async () => {
+ it("returns task with agent data and type", async () => {
const fakeTask = {
id: "t1",
agentId: "a1",
@@ -103,6 +103,7 @@ describe("POST /api/daemon/runtimes/[runtimeId]/tasks/claim", () => {
result: null,
error: null,
created_at: fakeTask.createdAt,
+ type: "user_dm_message",
});
const res = await POST(
@@ -120,7 +121,7 @@ describe("POST /api/daemon/runtimes/[runtimeId]/tasks/claim", () => {
name: "Agent 1",
runtime_config: { model: "gpt-4" },
});
- expect(body.task.prior_session_id).toBeNull();
+ expect(body.task.type).toBe("user_dm_message");
expect(mockGetAgent).toHaveBeenCalledWith({}, "a1", "w1");
});
});
diff --git a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
index 98b03d3b5..81cbfebd7 100644
--- a/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
+++ b/src/web/src/app/api/daemon/runtimes/[runtimeId]/tasks/claim/route.ts
@@ -33,7 +33,6 @@ export const POST = withAuth(async (_req, ctx) => {
runtime_config: agent.runtimeConfig || {},
}
: null,
- prior_session_id: null,
},
});
});
diff --git a/src/web/src/app/api/email/notify/route.ts b/src/web/src/app/api/email/notify/route.ts
index 39af352e1..87b889b16 100644
--- a/src/web/src/app/api/email/notify/route.ts
+++ b/src/web/src/app/api/email/notify/route.ts
@@ -33,7 +33,7 @@ export async function POST(req: NextRequest) {
title: `Email: ${body.subject}`.slice(0, 50),
})
const taskService = new TaskService(db)
- await taskService.enqueueTask(agent.id, conv.id, agent.workspaceId, `New email from ${body.from}: ${body.subject}`)
+ await taskService.enqueueTask(agent.id, conv.id, agent.workspaceId, `New email from ${body.from}: ${body.subject}`, "email_notification")
}
// Notify UI for all emails (whitelisted or not)
diff --git a/src/web/src/lib/api/responses.ts b/src/web/src/lib/api/responses.ts
index f6a6342e5..e8664f2f1 100644
--- a/src/web/src/lib/api/responses.ts
+++ b/src/web/src/lib/api/responses.ts
@@ -70,6 +70,7 @@ export function taskToResponse(t: {
conversationId: string;
workspaceId: string;
prompt: string;
+ type?: string;
status: string;
priority: number;
dispatchedAt: Date | string | null;
@@ -86,6 +87,7 @@ export function taskToResponse(t: {
conversation_id: t.conversationId,
workspace_id: t.workspaceId,
prompt: t.prompt,
+ type: t.type ?? "user_dm_message",
status: t.status,
priority: t.priority,
dispatched_at: formatTimestampNullable(t.dispatchedAt),
diff --git a/src/web/src/lib/services/task.test.ts b/src/web/src/lib/services/task.test.ts
index 8e7f0b452..37f571161 100644
--- a/src/web/src/lib/services/task.test.ts
+++ b/src/web/src/lib/services/task.test.ts
@@ -75,6 +75,7 @@ describe("TaskService", () => {
workspaceId: "w1",
conversationId: "c1",
prompt: "do stuff",
+ type: "user_dm_message",
priority: 0,
});
expect(result).toEqual({ id: "t1" });
diff --git a/src/web/src/lib/services/task.ts b/src/web/src/lib/services/task.ts
index 6f5f10ddc..37a455d72 100644
--- a/src/web/src/lib/services/task.ts
+++ b/src/web/src/lib/services/task.ts
@@ -13,7 +13,8 @@ export class TaskService {
agentId: string,
conversationId: string,
workspaceId: string,
- prompt: string
+ prompt: string,
+ type: string = "user_dm_message",
) {
const agent = await agentQueries.getAgent(this.db, agentId, workspaceId);
if (!agent) {
@@ -29,6 +30,7 @@ export class TaskService {
workspaceId,
conversationId,
prompt,
+ type,
priority: 0,
});
}