Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Show same-conversation on automation read-back; page list_threads past 100

AdityaUmale2cde594578cc
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index f19d5c76f9..eae3424f82 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -20,7 +20,7 @@ import { dropBlankArguments } from "./agents-blank-arguments.ts";
import { callResearchTool, RESEARCH_TOOL_NAMES } from "./agents-research-tools.ts";
import { callHelperTool, HELPER_TOOL_NAMES } from "./agents-helper-tools.ts";
import { callUsageLimitsTool, USAGE_LIMITS_TOOL } from "./agents-usage-tool.ts";
-import { callThreadPostTool, THREAD_POST_TOOL } from "./agents-thread-post-tool.ts"; import { callRenameThreadTool, RENAME_THREAD_TOOL } from "./agents-thread-title-tool.ts";
+import { callThreadPostTool, THREAD_POST_TOOL } from "./agents-thread-post-tool.ts"; import { callListThreadsTool, LIST_THREADS_TOOL } from "./agents-list-threads-tool.ts"; import { callRenameThreadTool, RENAME_THREAD_TOOL } from "./agents-thread-title-tool.ts";
import { callWaitTool, WAIT_TOOL_NAMES } from "./agents-wait-tools.ts";
import { callBurstTool } from "./agents-burst-tool.ts";
import { callComputerAskTool, COMPUTER_ASK_TOOL_NAMES } from "./agents-computer-ask-tool.ts";
@@ -424,23 +424,7 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
if (!r.ok) return { text: String(r.body.error ?? `reset_cloud_computer failed (HTTP ${r.status}).`), isError: true };
return { text: String(r.body.text ?? "") };
}
- if (name === "list_threads") {
- const query = new URLSearchParams({ fromBotId: BOT_ID, fromThreadId: THREAD_ID });
- const r = await api(`/api/internal/threads?${query.toString()}`);
- if (r.error) return { text: `Couldn't list threads: ${String(r.error)}`, isError: true };
- const threads = Array.isArray(r.threads) ? r.threads.filter(jsonRecord) : [];
- if (!threads.length) return { text: "No threads yet: you have none of your own beyond this one, and you have not opened any on a teammate." };
- const stateWord: Record<string, string> = { running: "running", "waiting-on-you": "waiting on the person", queued: "queued", idle: "idle" };
- const lines = threads.map((thread) => {
- const where = thread.own === true ? "yours" : `on @${String(thread.botName)}${typeof thread.openedBy === "string" && thread.openedBy ? `, opened by @${thread.openedBy}` : ""}`;
- const state = stateWord[String(thread.state)] ?? String(thread.state);
- const unread = thread.unread === true ? ", unread for the person" : "";
- const handoff = typeof thread.delegationId === "string" && thread.delegationId ? ` [delegation id: ${thread.delegationId}]` : "";
- const waiting = typeof thread.waiting === "string" && thread.waiting ? `: ${thread.waiting}` : "";
- return `- #${String(thread.title)} (${where}, ${state}${waiting}${unread}) [thread id: ${String(thread.threadId)}]${handoff}`;
- });
- return { text: `Threads, newest first:\n${lines.join("\n")}` };
- }
+ if (name === LIST_THREADS_TOOL) return callListThreadsTool(args, context);
if (name === "close_thread") {
const threadId = String(args.thread_id ?? "").trim();
if (!threadId) return { text: "close_thread needs the thread_id from list_threads or start_thread.", isError: true };
diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json
index e28761c948..b4c88a8479 100644
--- a/server/drivers/agents-catalog-goldens/full.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json
@@ -293,7 +293,12 @@
"inputSchema": {
"type": "object",
"additionalProperties": false,
- "properties": {}
+ "properties": {
+ "page": {
+ "type": "integer",
+ "description": "100 per page; default 1."
+ }
+ }
},
"annotations": {
"readOnlyHint": true,
diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json
index 8924f4a6b2..98007c52ee 100644
--- a/server/drivers/agents-catalog-goldens/profiles.json
+++ b/server/drivers/agents-catalog-goldens/profiles.json
@@ -1,7 +1,7 @@
{
"default": {
- "bytes": 58339,
- "sha256": "0832e12432a9babeb5acaf569b48f92a53e705f1280c7f840e70597e93048092",
+ "bytes": 58405,
+ "sha256": "6d8915413af5377efa434ee143ec945b55765b8fa8764f4ef8774247e14b984b",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -57,8 +57,8 @@
]
},
"voice": {
- "bytes": 59120,
- "sha256": "a78fb7fdde66548daff71e6a4d65947d074c71b748efbc65047b6c36fca396fc",
+ "bytes": 59186,
+ "sha256": "496bb0b7d6ba56fd2f42e814c020313685dda603465d63b79c713a5c58fcd094",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -115,8 +115,8 @@
]
},
"shared": {
- "bytes": 60604,
- "sha256": "66c5c3b3a94a1811f24983b8c8178f8f165640e7c7be2a9678b4b1b01eb478c0",
+ "bytes": 60670,
+ "sha256": "b212dec7cc637f770f636f56051364a0d4f84592466e4bf61532fd9f166c4ee5",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -174,8 +174,8 @@
]
},
"shared+voice": {
- "bytes": 61385,
- "sha256": "7317c444dc3a9e4c969b3cc19bb1bf9b7330d6c1907e6f90c61ec85e2c52e9bb",
+ "bytes": 61451,
+ "sha256": "b02b32ea5835ceb640d24feffe6707bf3367333582882ce753a8c825175457e5",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -234,8 +234,8 @@
]
},
"skills": {
- "bytes": 60660,
- "sha256": "7941c94cbc18f50cfdcffca74ea3a54252ebebc9ed10788412151212bb0d0261",
+ "bytes": 60726,
+ "sha256": "f2c6b0e348ce02c055697f39d60fde40fdb24765bc56a3e05ab9d8a5e01a8110",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -293,8 +293,8 @@
]
},
"skills+voice": {
- "bytes": 61441,
- "sha256": "f2ee3d5dd96b942ca278937845fab55717986800f93ae718aef46abb33e0983a",
+ "bytes": 61507,
+ "sha256": "6f8f2e3afd9f079a28e5c1b2b468497bb54188ef51b2750a389ff360814b54a9",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -353,8 +353,8 @@
]
},
"skills+shared": {
- "bytes": 62925,
- "sha256": "58988551e01e3230e1371fbfeb7caf32488887e1fd92ec738c692c6f59d46d2d",
+ "bytes": 62991,
+ "sha256": "082ab884764ae61a9d76a29a997745b5198f3570b0698ce486f37fee5b489807",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -414,8 +414,8 @@
]
},
"skills+shared+voice": {
- "bytes": 63706,
- "sha256": "fe179802775f85fb69e2359d8d31ebd6b122e106f1b6cc40fe688abd30021ade",
+ "bytes": 63772,
+ "sha256": "0224e7c6ba2508518856db3fa3fa028443f1c314ccd43ef14eb8242adb6a58fe",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -476,8 +476,8 @@
]
},
"non-chief": {
- "bytes": 49791,
- "sha256": "674974ee50050405f4ba10e46a5b0ef03439296c0876f6e4ca2f29a4e1ca15fd",
+ "bytes": 49857,
+ "sha256": "6db9296e63bdb55b4fd03f43afbfb7cba45c14bf5c4d33d7c5453c7adf28854c",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -526,8 +526,8 @@
]
},
"voice+non-chief": {
- "bytes": 50572,
- "sha256": "0aff8c7f3e5161fcc6779bad4061c131c07b8ffa691338972a208fd136778c3f",
+ "bytes": 50638,
+ "sha256": "801fe024254bd3a2b1f46e9eb0cc78de7cad247f658d9066759e010a39c3159c",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -577,8 +577,8 @@
]
},
"shared+non-chief": {
- "bytes": 52056,
- "sha256": "7c66dbbb003e69d4365c85558ac7cb0f5a875ac340d9c4980419311ab4adc63a",
+ "bytes": 52122,
+ "sha256": "f58f44c4a3014226be300992747a5ffa393a13a7e0a3fd35a447837b7f22ab52",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -629,8 +629,8 @@
]
},
"shared+voice+non-chief": {
- "bytes": 52837,
- "sha256": "a1f3a050e3ab1d4a683702f58efb372aa06fa4728318b65a7311f5cf507a81ea",
+ "bytes": 52903,
+ "sha256": "d9ef60cf7029bc0f456d8d472ec54952c303c93d42102979eed5feef57d88fa7",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -682,8 +682,8 @@
]
},
"skills+non-chief": {
- "bytes": 52112,
- "sha256": "6b28e7e612009b74b2c071cd6d9e615650b6972036d96ca23747e7e1cd9b218b",
+ "bytes": 52178,
+ "sha256": "dc567d728c349d0690b78a4b4e751166f351eeb784f9c1342a1112f314c8e9e7",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -734,8 +734,8 @@
]
},
"skills+voice+non-chief": {
- "bytes": 52893,
- "sha256": "93ad38c1f15d69cf603e4fda3e98366444399195c66b77a3adfecf7832fb643e",
+ "bytes": 52959,
+ "sha256": "0a782765975ae2d0d06756a08cc21dc4d491bdc62f64e690ee3b58ad30159eb2",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -787,8 +787,8 @@
]
},
"skills+shared+non-chief": {
- "bytes": 54377,
- "sha256": "5c607bcc8a5e2e0be62d808154ece470630b392cc01c76d1b3191ab724378189",
+ "bytes": 54443,
+ "sha256": "47970eb36a92fb24e89132edbdc5026a6a8764c4b2e9eb43f00d258b6c55c1b8",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -841,8 +841,8 @@
]
},
"skills+shared+voice+non-chief": {
- "bytes": 55158,
- "sha256": "2e877006de5e8ad5a692236dabe0862ff2f8b0fd3d04294d260f2bca6117b5d5",
+ "bytes": 55224,
+ "sha256": "3457a894f9cc4e0ec4e28fcbe8cc337c18689b9df2086313160ab8d3b9027512",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -896,8 +896,8 @@
]
},
"skills+shared+voice+cloud-home": {
- "bytes": 63472,
- "sha256": "05d24a443288182b8cbf80a92f77ff21bc2dcf2062b77a3797235ada1e29e9ba",
+ "bytes": 63538,
+ "sha256": "ac1f3900e9d01bf11a4c0aa414afa5d336f099115e2e02773d2d8acb454503d8",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -958,8 +958,8 @@
]
},
"skills+shared+voice+non-chief+cloud-home": {
- "bytes": 54924,
- "sha256": "3af6d73ec7fb10a3120f61cd31900973d2773229fab382252c3fa1ce9703e6b6",
+ "bytes": 54990,
+ "sha256": "228a0c41148e41a590accd1cc1399a1a037f0b84b01eae7717b025581bca00c7",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1013,8 +1013,8 @@
]
},
"skills+shared+voice+x": {
- "bytes": 67545,
- "sha256": "c51c599fb9d85f55c3fc57de3400657fc783b625449be858d1b65e6679c8ae66",
+ "bytes": 67611,
+ "sha256": "2ca96495e9f1ed877d245128460dbf7b5f6ab911dad51cb9d3099b96a3b7a970",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1079,8 +1079,8 @@
]
},
"skills+shared+voice+x+team": {
- "bytes": 67545,
- "sha256": "c51c599fb9d85f55c3fc57de3400657fc783b625449be858d1b65e6679c8ae66",
+ "bytes": 67611,
+ "sha256": "2ca96495e9f1ed877d245128460dbf7b5f6ab911dad51cb9d3099b96a3b7a970",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1145,8 +1145,8 @@
]
},
"skills+shared+voice+x+team+images": {
- "bytes": 69479,
- "sha256": "fd4583b1d7dd15db2e933e72d7936ee5206ecde52a792fb192198e904bef59cc",
+ "bytes": 69545,
+ "sha256": "e880737a790d5fec2996dad8caadf9f37cd30924a311565324c4a4ad561b3387",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1213,8 +1213,8 @@
]
},
"default+legacy-switches": {
- "bytes": 58339,
- "sha256": "0832e12432a9babeb5acaf569b48f92a53e705f1280c7f840e70597e93048092",
+ "bytes": 58405,
+ "sha256": "6d8915413af5377efa434ee143ec945b55765b8fa8764f4ef8774247e14b984b",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1270,8 +1270,8 @@
]
},
"default+mausbot": {
- "bytes": 58990,
- "sha256": "41097dcf4c15de1a4bdf80638d59622fab5abdfa414582c65822eb786b8d825c",
+ "bytes": 59056,
+ "sha256": "3291a662377ad451dac22f21ffbd9d2f667947b9c2280b87ed1b222a6c52f3df",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1329,8 +1329,8 @@
]
},
"skills+shared+voice+mausbot": {
- "bytes": 64357,
- "sha256": "d9dfdb8e7fa70aa160415ca30e6502aa0069d9ab8882975a9cb7fdc1f79c52f1",
+ "bytes": 64423,
+ "sha256": "408de4e6daf058a99684519fbe86da019514af91729e052082ff030bbf6c44de",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1393,8 +1393,8 @@
]
},
"default+no-computer-pick": {
- "bytes": 57127,
- "sha256": "82938ed65e14749965fbfa56835dc5155e0bced36a8623101c85770e2d85369a",
+ "bytes": 57193,
+ "sha256": "675982cf5ba5a6909461ba7391618d092537ea043e69f1af5c390f7ebc7becba",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1449,8 +1449,8 @@
]
},
"default+room": {
- "bytes": 54123,
- "sha256": "5cf99d242d8b04394a12df56468f97b6ecfbe6d04fa3678966afe31e7216af4a",
+ "bytes": 54189,
+ "sha256": "944dbd1617015f94adef32ecd02930701eff446eca55ddef57dc016cb2975528",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1500,8 +1500,8 @@
]
},
"non-chief+room": {
- "bytes": 45575,
- "sha256": "4314e9768e67df941f8c149d17713ba920e5bfc28b7a062b0ebb311752c6b94e",
+ "bytes": 45641,
+ "sha256": "c2ee56abc9897a2ced8396b3eb49fb9c0c79da1b0f50db9fb9322924e872b2e8",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1544,8 +1544,8 @@
]
},
"default+images": {
- "bytes": 60273,
- "sha256": "f67dff463cdda6016a59a0db02fa7687ed9096e5c9873d6bcfb68ac092d7f7ea",
+ "bytes": 60339,
+ "sha256": "9a08bd783df310997efdfd0dfec1a6d757ed7ffdc5cc3e76d52f9e1bfa18c1ad",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1603,8 +1603,8 @@
]
},
"skills+shared+voice+x+team+images+hosting": {
- "bytes": 71342,
- "sha256": "ae1234729aa139f223e5e990155167f65ad3a8a06a0555adabc9264c9e63be8f",
+ "bytes": 71408,
+ "sha256": "38a383bc2cc131930319c937449981c43e2b5198ca1da56769c24ee6f0115170",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1673,8 +1673,8 @@
]
},
"default+hosting": {
- "bytes": 60202,
- "sha256": "8bded152f82c3e23e26aa324282e26f2818afeb76517747e13c924a690eb5e31",
+ "bytes": 60268,
+ "sha256": "5ea3d77ad82239fa2b1523b3385388fe6e46c9f0fe4d12834a2cf345f2964851",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -1732,8 +1732,8 @@
]
},
"default+tools-off": {
- "bytes": 54021,
- "sha256": "7a2a541229aee99b235964a9b74066d5163407c7832113ae4a00cead86f75485",
+ "bytes": 54087,
+ "sha256": "ea3074762d1e093bd8d9e9c5d8f133c3970566f4d9437175c4a4530a30cd229c",
"tools": [
"tool_result_read",
"list_room_targets",
diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts
index 7bf9164125..09da4d837b 100644
--- a/server/drivers/agents-catalog.ts
+++ b/server/drivers/agents-catalog.ts
@@ -232,7 +232,9 @@ const TOOL_DEFINITIONS = [
name: "list_threads",
description:
"See your own threads and the threads you opened on teammates, newest first: each with its bot, title, state (running, waiting on the person, queued, idle, or closed), whether the person has unread there, and the delegation id if it was a handoff. Use it to check how the threads you started are going before reporting to the person; write a thread's title as #Title when you mention it. A Chief of Staff also sees threads teammates opened on each other. This is a read: it starts nothing and changes nothing.",
- inputSchema: { type: "object", additionalProperties: false, properties: {} },
+ inputSchema: { type: "object", additionalProperties: false, properties: {
+ page: { type: "integer", minimum: 1, description: "100 per page; default 1." },
+ } },
},
{
name: "close_thread",
diff --git a/server/drivers/agents-list-threads-tool.ts b/server/drivers/agents-list-threads-tool.ts
new file mode 100644
index 0000000000..4e21559016
--- /dev/null
+++ b/server/drivers/agents-list-threads-tool.ts
@@ -0,0 +1,33 @@
+// The agents catalog's list_threads tool: this bot's own threads and the ones it opened on teammates, newest first,
+// one page of the internal route (server/routes/internal-threads.ts) at a time.
+import type { Json } from "./agents-client.ts";
+import type { ToolCallContext, ToolCallResult } from "./agents-call.ts";
+
+export const LIST_THREADS_TOOL = "list_threads";
+
+const STATE_WORD: Record<string, string> = { running: "running", "waiting-on-you": "waiting on the person", queued: "queued", idle: "idle" };
+
+function threadLine(thread: Json): string {
+ const where = thread.own === true ? "yours" : `on @${String(thread.botName)}${typeof thread.openedBy === "string" && thread.openedBy ? `, opened by @${thread.openedBy}` : ""}`;
+ const state = STATE_WORD[String(thread.state)] ?? String(thread.state);
+ const unread = thread.unread === true ? ", unread for the person" : "";
+ const handoff = typeof thread.delegationId === "string" && thread.delegationId ? ` [delegation id: ${thread.delegationId}]` : "";
+ const waiting = typeof thread.waiting === "string" && thread.waiting ? `: ${thread.waiting}` : "";
+ return `- #${String(thread.title)} (${where}, ${state}${waiting}${unread}) [thread id: ${String(thread.threadId)}]${handoff}`;
+}
+
+export async function callListThreadsTool(args: Json, context: ToolCallContext): Promise<ToolCallResult> {
+ const query = new URLSearchParams({ fromBotId: context.botId, fromThreadId: context.threadId, ...(args.page === undefined ? {} : { page: String(args.page) }) });
+ const r = await context.client.api(`/api/internal/threads?${query.toString()}`);
+ if (r.error) return { text: `Couldn't list threads: ${String(r.error)}`, isError: true };
+ const threads = Array.isArray(r.threads) ? r.threads.filter((row): row is Json => typeof row === "object" && row !== null && !Array.isArray(row)) : [];
+ const total = typeof r.total === "number" ? r.total : threads.length;
+ const page = typeof r.page === "number" ? r.page : 1;
+ const pageSize = typeof r.pageSize === "number" ? r.pageSize : threads.length;
+ if (!threads.length && total > 0) return { text: `No threads on page ${page}: there are ${total}, ${pageSize} to a page.` };
+ if (!threads.length) return { text: "No threads yet: you have none of your own beyond this one, and you have not opened any on a teammate." };
+ const first = (page - 1) * pageSize + 1;
+ const last = first + threads.length - 1;
+ const more = last < total ? `\n\nShowing ${first}-${last} of ${total}. For older ones call list_threads with page ${page + 1}.` : "";
+ return { text: `Threads, newest first:\n${threads.map(threadLine).join("\n")}${more}` };
+}
diff --git a/server/drivers/agents-proxy.test.ts b/server/drivers/agents-proxy.test.ts
index dd3ca8d380..ceed377862 100644
--- a/server/drivers/agents-proxy.test.ts
+++ b/server/drivers/agents-proxy.test.ts
@@ -49,6 +49,7 @@ let assignmentStatusCode = 200;
let lastThreadBody: any = null;
let threadCalls = 0;
let threadsList: unknown = { threads: [] };
+let lastThreadsUrl = "";
let threadResponse: unknown = { threadId: "thread-new", title: "QA: PR #1", botId: "bot-asker", botName: "Asker", self: true, state: "running", limit: 3 };
let computerRequests: { method: string; url: string; body: unknown }[] = [];
let computerResponse: unknown = { current: "local", available: ["local", "vm"] };
@@ -269,6 +270,7 @@ beforeAll(async () => {
return;
}
if (req.method === "GET" && req.url?.startsWith("/api/internal/threads?")) {
+ lastThreadsUrl = req.url;
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify(threadsList));
return;
@@ -1341,6 +1343,24 @@ describe("agents-proxy MCP surface", () => {
}
});
+ it("list_threads names the next page when more threads are left, and asks for the page it is given", async () => {
+ const row = { threadId: "t-1", botId: "bot-a", botName: "A", title: "Event 1", state: "idle", own: true, unread: false, openedAt: 1 };
+ threadsList = { threads: [row], total: 101, page: 1, pageSize: 100 };
+ try {
+ expect((await callTool("list_threads", {})).result.content[0].text).toContain("Showing 1-1 of 101. For older ones call list_threads with page 2.");
+ threadsList = { threads: [row], total: 101, page: 2, pageSize: 100 };
+ const last = (await callTool("list_threads", { page: 2 })).result.content[0].text;
+ expect(new URL(lastThreadsUrl, "http://x").searchParams.get("page")).toBe("2");
+ expect(last).toContain("#Event 1");
+ expect(last).not.toContain("Showing");
+ threadsList = { threads: [], total: 101, page: 3, pageSize: 100 };
+ expect((await callTool("list_threads", { page: 3 })).result.content[0].text).toBe("No threads on page 3: there are 101, 100 to a page.");
+ expect((await callTool("list_threads", { page: 0 })).result.content[0].text).toContain("was not run");
+ } finally {
+ threadsList = { threads: [] };
+ }
+ });
+
it("assignment_status with an id renders status, outcome, the result head and the assignment's own hand-offs", async () => {
assignmentStatusResponse = {
assignment: { id: "asg-9", botId: "bot-helper", botName: "Helper", status: "failed", outcome: "provider_error", outcomeDetail: "the engine exited early", result: "x".repeat(2_500) },
diff --git a/server/routes/internal-threads.test.ts b/server/routes/internal-threads.test.ts
index 0f4d8fd56b..9b0e4f6734 100644
--- a/server/routes/internal-threads.test.ts
+++ b/server/routes/internal-threads.test.ts
@@ -23,7 +23,7 @@ async function listThreads(from: BotRecord) {
readBody: async () => ({}),
});
let body: { threads: Array<Record<string, unknown>> } | undefined;
- await route({ res: {}, path: "/api/internal/threads", method: "GET", json: (_res: unknown, _status: number, value: never) => { body = value; } } as never);
+ await route({ res: {}, url: new URL("http://x/api/internal/threads"), path: "/api/internal/threads", method: "GET", json: (_res: unknown, _status: number, value: never) => { body = value; } } as never);
return body!.threads;
}
@@ -42,6 +42,34 @@ describe("list_threads on a queued handoff", () => {
});
});
+describe("list_threads past the first 100", () => {
+ async function page(query: string) {
+ const many = Array.from({ length: 130 }, (_, index) => task(`t-${index}`, `Event ${index}`, undefined));
+ many.forEach((row, index) => { row.createdAt = index; });
+ const route = createInternalThreadRoutes({
+ store: { bot: () => undefined, bots: [lead], tasks: (id: string) => id === lead.id ? many : [] } as never,
+ coordinator: { awaitingAnswer: () => false, parkedDirect: () => undefined, activeDirect: () => undefined, active: () => [] } as never,
+ from: lead, fromThreadId: "t-own", ownsThread: () => true, shown: () => true,
+ threadBusy: () => false, queuedThreadPosition: () => null, queuedReason: () => "", readBody: async () => ({}),
+ });
+ let body: { threads: Array<{ threadId: string }>; total: number; page: number; pageSize: number } | undefined;
+ await route({ res: {}, url: new URL(`http://x/api/internal/threads${query}`), path: "/api/internal/threads", method: "GET",
+ json: (_res: unknown, _status: number, value: never) => { body = value; } } as never);
+ return body!;
+ }
+
+ it("gives the newest 100 first and the older ones on page 2, with the total", async () => {
+ const first = await page("");
+ expect(first).toMatchObject({ total: 130, page: 1, pageSize: 100 });
+ expect(first.threads).toHaveLength(100);
+ expect(first.threads[0]!.threadId).toBe("t-129");
+ const second = await page("?page=2");
+ expect(second).toMatchObject({ total: 130, page: 2 });
+ expect(second.threads.map((thread) => thread.threadId)).toEqual(Array.from({ length: 30 }, (_, index) => `t-${29 - index}`));
+ expect((await page("?page=0")).page).toBe(1);
+ });
+});
+
describe("rename_thread on the conversation the turn speaks in", () => {
async function rename(body: unknown, opts: { own?: TaskRecord; owns?: boolean } = {}) {
const own = opts.own ?? task("t-own", "Terminei o design e a skill de carrossel pra cl…");
diff --git a/server/routes/internal-threads.ts b/server/routes/internal-threads.ts
index 11dba95c8c..87ec4561a3 100644
--- a/server/routes/internal-threads.ts
+++ b/server/routes/internal-threads.ts
@@ -5,6 +5,8 @@ import { threadTitleFrom, type BotRecord, type Store, type TaskRecord } from "..
import { PASS, type RouteHandler } from "./table.ts";
import { conversationLanguage, serverLine } from "../server-lines.ts";
+const THREADS_PAGE = 100;
+
type ThreadState = "running" | "waiting-on-you" | "queued" | "idle" | "closed";
interface ThreadRow {
@@ -33,7 +35,7 @@ export function createInternalThreadRoutes(deps: {
readBody(): Promise<unknown>;
}): RouteHandler {
const { store, coordinator, from, fromThreadId } = deps;
- return async ({ res, path, method, json }) => {
+ return async ({ res, url, path, method, json }) => {
// list_threads: the caller's own threads plus, on reachable peers, only threads it opened; a peer's other threads are its own business.
if (method === "GET" && path === "/api/internal/threads") {
if (!deps.ownsThread(from.id, fromThreadId)) {
@@ -79,7 +81,10 @@ export function createInternalThreadRoutes(deps: {
}
}
rows.sort((a, b) => b.openedAt - a.openedAt);
- return json(res, 200, { threads: rows.slice(0, 100) });
+ const asked = Number(url.searchParams.get("page"));
+ const page = Number.isSafeInteger(asked) && asked > 0 ? asked : 1;
+ const start = (page - 1) * THREADS_PAGE;
+ return json(res, 200, { threads: rows.slice(start, start + THREADS_PAGE), total: rows.length, page, pageSize: THREADS_PAGE });
}
// rename_thread names only the conversation the turn speaks in. A room's thread is the room's, and an automation's
// chat keeps the name its runs find it by.
diff --git a/server/trigger-tools.test.ts b/server/trigger-tools.test.ts
index bfd042f953..514da2249e 100644
--- a/server/trigger-tools.test.ts
+++ b/server/trigger-tools.test.ts
@@ -66,6 +66,20 @@ describe("listTriggers", () => {
expect(listed.triggers![0]).toMatchObject({ schedule: { type: "weekly", time: "09:00", weekdays: ["monday", "tuesday", "wednesday", "thursday", "friday"] } });
});
+ it("says for every kind whether its runs continue one conversation", () => {
+ const listed = listTriggers({
+ botId: "bot-a", routines: [{ ...routine("r1", "bot-a"), sameConversation: true }],
+ webhooks: [{ ...webhook("w1", "bot-a"), sameConversation: true }, webhook("w2", "bot-a")],
+ appTriggers: [
+ { id: "a1", botId: "bot-a", prompt: "Sort mail.", name: "Mail", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", delivery: "poll", sameConversation: true } as AppTrigger,
+ { id: "a2", botId: "bot-a", prompt: "Sort mail.", name: "Mail 2", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", delivery: "poll" } as AppTrigger,
+ ],
+ runs: [], timeZone: "UTC", now,
+ });
+ expect(Object.fromEntries(listed.triggers!.map((trigger) => [trigger.id, trigger.sameConversation])))
+ .toEqual({ r1: true, w1: true, w2: false, a1: true, a2: false });
+ });
+
it("gives one trigger with its recent fires, and says plainly when the id is not the bot's", () => {
const runs = Array.from({ length: 12 }, (_, index) => run(`run-${index}`, "r1", "bot-a", `report ${index}`));
const one = listTriggers({ botId: "bot-a", triggerId: "r1", routines: [routine("r1", "bot-a")], webhooks: [], runs, timeZone: "UTC", now });
diff --git a/server/trigger-tools.ts b/server/trigger-tools.ts
index ecf80576fa..6165cb3772 100644
--- a/server/trigger-tools.ts
+++ b/server/trigger-tools.ts
@@ -96,6 +96,7 @@ export function agentWebhook(webhook: WebhookTrigger, latestRun?: RoutineRun) {
runOn: webhook.runOn,
eventTypes: webhook.eventTypes ?? [],
...(webhook.payloadFilter ? { payloadFilter: webhook.payloadFilter } : {}),
+ sameConversation: webhook.sameConversation === true,
calls: webhook.deliveryCount,
lastCalledAt: timestamp(webhook.lastReceivedAt),
latestRun: latestRun ? agentRun(latestRun) : null,
@@ -118,6 +119,7 @@ export function agentAppTrigger(trigger: AppTrigger, latestRun?: RoutineRun) {
account: trigger.accountLabel ?? trigger.accountId,
filter: trigger.filter ?? {},
event_config: trigger.config,
+ sameConversation: trigger.sameConversation === true,
enabled: trigger.enabled,
runOn: trigger.runOn,
eventsReceived: trigger.received,