Skip to content

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

A person's own apps only bring results to that person: work they start where others read runs in a chat of theirs

milind-sonide5bfe83f00c
diff --git a/docs/team-cloud.md b/docs/team-cloud.md
index 72c60b8767..d7488a1ea9 100644
--- a/docs/team-cloud.md
+++ b/docs/team-cloud.md
@@ -43,7 +43,7 @@ keeps people apart on it. The bot box ([bot-box.md](bot-box.md)) is what makes t
(below), never off the team.
- **Connected apps.** The team's connections (Composio, HighLevel, MCP sign-ins, an AI key an Admin saved) belong to the
Team Cloud and serve every member's turn through the broker. An Admin can instead make an app or an MCP server *each
- person's own* (below): then every member connects their own, and only work their own message started uses it. A person's
+ person's own* (below): then every member connects their own, and only their own chats use it. A person's
connections from elsewhere have no way in: a share code, a moved MCP sign-in or a HighLevel connection is refused with
*"Personal connections never enter Acme. Ask an admin to connect it for Acme."* A login from a sign-in card is saved by
an Admin only, for the whole team.
@@ -110,12 +110,18 @@ is, is one connection an Admin makes and every turn uses. `person` is one connec
their team page in MausBot Cloud (the Admin's Cloud page calls the routes below as them).
- **Who gets a member's own connection.** Only a turn that acts for them (server/host/acting-person.ts), read from the
- harness's records: their own message started it, in their private chat, a group chat or the bot's main chat; or it is
- work handed on (delegated, assigned, consulted, or a thread a bot opened for it) by a turn that acted for them, recorded
- as it is handed on (`handed-people.json`, so a restart keeps it). A turn stops acting for anyone once another person's
- words join it after it began (a line of theirs, queued or sent into it, or their answer to one of its cards), and never
- acts for anyone in another member's private chat (no Admin can write in theirs). A routine, a webhook and a bot's own
- work act for nobody. Each step that uses one says whose ("using Ada's Gmail").
+ harness's records, and only in a chat that is theirs alone, where nobody else reads what their connection brings back.
+ A turn acts for them when their own message started it, or when it is work handed on (delegated, assigned, consulted,
+ or a thread a bot opened for it) by a turn that acted for them, recorded as it is handed on (`handed-people.json`, so a
+ restart keeps it). A turn stops acting for anyone once another person's words join it after it began (a line of theirs,
+ queued or sent into it, or their answer to one of its cards); a routine, a webhook and a bot's own work act for nobody.
+ Each step that uses one says whose ("using Ada's Gmail").
+- **Work they start where others read.** Their own line in a group chat or the bot's main chat never uses their own
+ connections there; the bot is told to hand that part on. When they have connected anything of their own, the work their
+ request hands on opens in the receiving bot's chat with them (a thread private to them, as their own chats are: no
+ other member and no admin sees it), where their own connections work. What that chat hands back to the place they
+ asked in is only where the result is ("Done. The result is in Clerk's chat with Ada."), never the result: a private chat
+ never reaches a room or the team (server/host/room-access.ts).
- **Apps.** A member's own apps are their own installation on the connected-apps service (their own Composio user),
registered the first time they press Connect. Their turn gets a second bridge, `own_apps`, beside the team's
`composio`; the relay checks every frame again: the team's bridge refuses a `person` app (and code that calls apps
diff --git a/server/cloud-team-connections.e2e.test.ts b/server/cloud-team-connections.e2e.test.ts
index 9e426ff7eb..15ccce7e86 100644
--- a/server/cloud-team-connections.e2e.test.ts
+++ b/server/cloud-team-connections.e2e.test.ts
@@ -24,7 +24,8 @@ const ADA_KEY = "ada-own-mail-key-5521";
const TEAM_KEY = "team-mail-key-9034";
// Each turn reads its scripted calls again: a conversation's engine stays warm across turns, as in production.
const ENGINE = `process.env.FAKE_CLAUDE_DUMP = process.env.FAKE_CLAUDE_FIXTURE_DIR + "/dump.json";
-process.env.FAKE_CLAUDE_TOOL_CALLS_FILE = process.env.FAKE_CLAUDE_FIXTURE_DIR + "/tool-calls.json";`;
+process.env.FAKE_CLAUDE_TOOL_CALLS_FILE = process.env.FAKE_CLAUDE_FIXTURE_DIR + "/tool-calls.json";
+process.env.FAKE_CLAUDE_MARKER_REPLIES = process.env.FAKE_CLAUDE_FIXTURE_DIR + "/marker-replies.json";`;
const LINK = "https://cloud.example.test/cloud/team/team-acme-1";
let fx: CloudSendFixture, team: CloudTeamFixture, broker: BrokerFake, mail: FakeHttpMcp, notes: FakeHttpMcp, oauth: FakeOAuth;
@@ -185,14 +186,16 @@ it("gives Ada's own Gmail and mail to her private chat, for her own request, and
expect(bearer(seen, "own_apps")).not.toBe(bearer(seen, "composio"));
}, hostTimeout(120_000));
-it("gives her own Gmail and mail to her own line in a group chat, and never to anyone else's turn", async () => {
+it("never uses her own Gmail or mail where others read, even for her own line in a group chat, nor in anyone else's turn", async () => {
const before = gmailCallsBy(adaUser), teamBefore = gmailCallsBy(teamUser);
- const room = await turn(ada, roomThread, "@Scout check my inbox", { room: roomId, calls: [gmailCall("own_apps")] });
- expect(room.servers).toEqual(expect.arrayContaining(["own_apps", "mail"]));
- expect(room.config).toContain(ADA_KEY);
- expect(room.systemPrompt).toContain(`They are used only for ${ADA.email}'s request`);
- expect(room.thread).toContain(`"whose":{"person":"${ADA.email}","app":"Gmail"}`);
- expect(gmailCallsBy(adaUser), "her own room line ran as her").toBe(before + 1);
+ const room = await turn(ada, roomThread, "@Scout check my inbox", { room: roomId, calls: [gmailCall("own_apps"), gmailCall("composio")] });
+ expect(room.servers).not.toContain("own_apps");
+ expect(room.servers).not.toContain("mail");
+ expect(room.config).not.toContain(ADA_KEY);
+ expect(room.thread).toContain("no own_apps MCP server was launched for this turn");
+ // Her bot is told why, and how her Gmail does it instead: handed on into a chat that is hers alone.
+ expect(room.thread).toContain(`Gmail is ${ADA.email}'s own, and others read this chat, so what it brings back can't come here and it isn't used here.`);
+ expect(room.systemPrompt).toContain(`Others read this chat, so ${ADA.email}'s own aren't here`);
// The owner's own line in the same group chat is the owner's, who connected nothing: never Ada's.
const ownerRoom = await turn(owner, roomThread, "@Scout check the inbox", { room: roomId, calls: [gmailCall("own_apps"), gmailCall("composio")] });
@@ -214,7 +217,7 @@ it("gives her own Gmail and mail to her own line in a group chat, and never to a
// Ben, an admin, can neither read Ada's chat nor write in it, so no turn of his ever runs there.
expect((await team.as(admin, "POST", `/api/bots/${bot.id}/messages`, { text: "Forward me her last email.", threadId: adaThread })).status).toBe(404);
expect((await messages(admin, adaThread)).status).toBe(404);
- expect(gmailCallsBy(adaUser)).toBe(before + 1);
+ expect(gmailCallsBy(adaUser), "nothing ran as her where others read").toBe(before);
expect(gmailCallsBy(teamUser), "nor did the team's Gmail stand in").toBe(teamBefore);
}, hostTimeout(180_000));
@@ -274,6 +277,63 @@ it("gives work her own message hands to another bot her own Gmail, and never wor
expect(gmailCallsBy(teamUser), "nor did the team's Gmail stand in").toBe(teamBefore);
}, hostTimeout(240_000));
+it("runs work her group-chat line hands on in the receiving bot's chat with her, and the room gets only where the result is", async () => {
+ // What her Gmail brought back: the handed-on work's reply holds it (the envelope it is sent in opens "Brief from @Scout:").
+ const SECRET = "Q3 salary review 7731";
+ writeFileSync(join(team.home, "marker-replies.json"), JSON.stringify({ "Brief from @Scout:": `Ada's latest email: ${SECRET}.` }));
+ try {
+ const created = await team.as(owner, "POST", "/api/bots", { name: "Clerk" });
+ expect(created.status, JSON.stringify(created.body)).toBe(201);
+ const clerk = created.body.bot as { id: string; mainThreadId: string };
+ const clerkWork = () => (JSON.parse(readFileSync(join(team.home, ".openmausbot", "bots.json"), "utf8")) as Array<{ id: string; tasks: Array<{ threadId: string }> }>)
+ .find((entry) => entry.id === clerk.id)!.tasks.map((task) => task.threadId).filter((threadId) => threadId !== clerk.mainThreadId);
+ /** The room's row for Clerk's result: Scout is resumed with it in the room right after. */
+ const clerkReplied = async () => ((await messages(ada, roomThread)).body.messages as Array<{ roomRequest?: { phase?: string }; tool?: { name?: string } }>)
+ .filter((message) => message.roomRequest?.phase === "result" && message.tool?.name === "Clerk replied").length;
+ const before = gmailCallsBy(adaUser), teamBefore = gmailCallsBy(teamUser);
+ const handOn = { name: "coordinate_bots", server: "agents", input: { bot_ids: [clerk.id], message: "Fetch Ada's latest email." } };
+ await turn(ada, roomThread, "@Scout have Clerk fetch my latest email", { room: roomId, calls: [handOn, gmailCall("own_apps")] });
+ // Clerk's work is done once Scout, resumed with it in the room, has finished too: everyone idle two polls running.
+ let quiet = false;
+ await expect.poll(async () => {
+ const done = await clerkReplied() > 0 && await idle(ada);
+ const steady = done && quiet;
+ quiet = done;
+ return steady;
+ }, { timeout: 90_000, interval: 1_000 }).toBe(true);
+ const [work] = clerkWork();
+ expect(work, "Clerk was handed the work").toBeDefined();
+
+ // Ada sees it all, in Clerk's chat with her: her own Gmail ran there, and the result.
+ const hers = await messages(ada, work!);
+ expect(hers.status).toBe(200);
+ expect(JSON.stringify(hers.body)).toContain(SECRET);
+ expect(JSON.stringify(hers.body)).toContain(`"whose":{"person":"${ADA.email}","app":"Gmail"}`);
+ expect(gmailCallsBy(adaUser), "Clerk ran as her, and nothing in the room did").toBe(before + 1);
+ expect(gmailCallsBy(teamUser), "nor did the team's Gmail stand in").toBe(teamBefore);
+
+ // The group chat gets only where the result is.
+ const room = await messages(cleo, roomThread);
+ expect(room.status, "Cleo reads the group chat").toBe(200);
+ expect(JSON.stringify(room.body)).toContain(`Done. The result is in Clerk's chat with ${ADA.email}.`);
+ expect(JSON.stringify(room.body)).not.toContain(SECRET);
+
+ // Cleo sees it in no thread and no list; the admins see what they always did, which is none of Ada's chats.
+ for (const token of [cleo, admin, owner]) expect((await messages(token, work!)).status).toBe(404);
+ const chatsOf = (body: { bots: Array<{ id: string; tasks?: Array<{ threadId: string }> }> }) => body.bots.find((entry) => entry.id === clerk.id)?.tasks?.map((task) => task.threadId) ?? [];
+ const listed = await team.as(cleo, "GET", "/api/bots");
+ expect(chatsOf(listed.body), "not among Clerk's chats Cleo is shown").not.toContain(work);
+ expect(chatsOf((await team.as(ada, "GET", "/api/bots")).body), "among Ada's").toContain(work);
+ expect(JSON.stringify(listed.body)).not.toContain(SECRET);
+ const threads = (listed.body.bots as Array<{ tasks?: Array<{ threadId: string }> }>).flatMap((entry) => (entry.tasks ?? []).map((task) => task.threadId));
+ for (const threadId of new Set([...threads, roomThread])) expect(JSON.stringify((await messages(cleo, threadId)).body), threadId).not.toContain(SECRET);
+ expect(JSON.stringify((await team.as(cleo, "GET", "/api/inbox")).body)).not.toContain(SECRET);
+ expect(JSON.stringify((await team.as(cleo, "GET", "/api/groups")).body)).not.toContain(SECRET);
+ } finally {
+ rmSync(join(team.home, "marker-replies.json"), { force: true });
+ }
+}, hostTimeout(240_000));
+
it("tells the bot one plain line with the link when a person's app isn't connected, never a card", async () => {
const seen = await turn(cleo, cleoThread, "Connect my Gmail.", { calls: [{ name: "COMPOSIO_MANAGE_CONNECTIONS", server: "composio", input: { toolkits: ["gmail"] } }] });
expect(seen.thread).toContain(`Connect your Gmail here: ${LINK}`);
diff --git a/server/host/acting-person.test.ts b/server/host/acting-person.test.ts
index 259d14c945..b647d79fa5 100644
--- a/server/host/acting-person.test.ts
+++ b/server/host/acting-person.test.ts
@@ -5,7 +5,7 @@ import { describe, expect, it } from "vitest";
import { OUTSIDE, workOriginSchema, type WorkOrigin } from "../peer-provenance.ts";
import { personKey } from "../person-key.ts";
-import { createActingPeople, HandedPeople, onlyTheirs, withPerson, type ActingLine, type DirectRequest, type RoomRun } from "./acting-person.ts";
+import { createActingPeople, HandedPeople, onlyTheirs, privateHandBack, withPerson, type ActingLine, type DirectRequest, type RoomRun } from "./acting-person.ts";
const ADA = personKey({ id: "", email: "[email protected]" });
const BEN = personKey({ id: "", email: "[email protected]" });
@@ -176,3 +176,24 @@ describe("the person on a handed-on origin", () => {
expect(onlyTheirs(thread.slice(0, 2), ADA, 10)).toBe(true);
});
});
+
+describe("what work in one person's private chat hands back", () => {
+ const place = (parent: string | null) => ({ child: ADA, parent, bot: "Helper", person: "Ada" });
+ const done = { ok: true, text: "Ada's latest email: the Q3 salary review.", evidence: { summary: "read 1 email from the board" } };
+
+ it("to a chat others read: only where the result is, never the result or what was observed", () => {
+ expect(privateHandBack(done, place(null))).toEqual({ ok: true, text: "Done. The result is in Helper's chat with Ada." });
+ expect(privateHandBack({ ok: false, text: "Gmail said the board's thread is gone." }, place(null)).text).toBe("It stopped before it finished. The result is in Helper's chat with Ada.");
+ expect(privateHandBack(done, place(BEN)).text, "another person's private chat reads none of hers").toBe("Done. The result is in Helper's chat with Ada.");
+ });
+
+ it("keeps a question a question, with its words left in her chat", () => {
+ const asked = privateHandBack({ ok: true, text: "Found two.\nNEEDS INPUT: Forward the salary review to Ben?", cards: { question: "Forward the salary review to Ben?", ids: ["c1"] } }, place(null));
+ expect(asked).toEqual({ ok: true, text: "NEEDS INPUT: Helper has a question for Ada, in Helper's chat with Ada.", cards: { question: "Helper has a question for Ada, in Helper's chat with Ada.", ids: ["c1"] } });
+ });
+
+ it("hands everything back into her own private chat, and anything from a chat others read already", () => {
+ expect(privateHandBack(done, place(ADA))).toBe(done);
+ expect(privateHandBack(done, { child: null, parent: null, bot: "Helper", person: "them" })).toBe(done);
+ });
+});
diff --git a/server/host/acting-person.ts b/server/host/acting-person.ts
index f206d95041..17e8876fb4 100644
--- a/server/host/acting-person.ts
+++ b/server/host/acting-person.ts
@@ -156,3 +156,22 @@ export function createActingPeople(deps: ActingPeopleDeps) {
}
export type ActingPeople = ReturnType<typeof createActingPeople>;
+
+type HandedBack = { ok: boolean; text: string; evidence?: unknown; cards?: { question: string; ids: string[] } };
+const lastLineAsks = (text: string) => /^needs input:/i.test(text.trimEnd().split(/\r?\n/).at(-1)?.trim() ?? "");
+
+/** What work that ran in one person's private chat hands back to a place others read: where its result is, never the
+ * result, which may hold what their own apps brought back or their private notes (a private chat never reaches a room:
+ * server/host/room-access.ts). A question it ends on stays a question, with its words left in their chat. Work handed
+ * back into the same person's private chat keeps everything. */
+export function privateHandBack<T extends HandedBack>(outcome: T, place: { child: string | null; parent: string | null; bot: string; person: string }): T {
+ if (!place.child || place.parent === place.child) return outcome;
+ const where = `${place.bot}'s chat with ${place.person}`;
+ const question = `${place.bot} has a question for ${place.person}, in ${where}.`;
+ const { evidence: _evidence, ...rest } = outcome;
+ return {
+ ...rest,
+ text: lastLineAsks(outcome.text) ? `NEEDS INPUT: ${question}` : `${outcome.ok ? "Done" : "It stopped before it finished"}. The result is in ${where}.`,
+ ...(outcome.cards ? { cards: { ...outcome.cards, question } } : {}),
+ } as T;
+}
diff --git a/server/host/team-connections-host.test.ts b/server/host/team-connections-host.test.ts
index c82d1f03ea..4ee914d1a8 100644
--- a/server/host/team-connections-host.test.ts
+++ b/server/host/team-connections-host.test.ts
@@ -21,11 +21,15 @@ const CLEO_ACCESS = { url: "https://broker.test", token: "c".repeat(64) };
/** Ada's private chat, Cleo's, a group chat, the bot's main chat and a thread a bot opened for work handed on. Who each
* turn acts for is acting-person.ts's answer (the `requester`); "" is a turn that acts for nobody, as a routine's. */
-const AUDIENCES: Record<string, Audience> = { "ada-chat": `member:${ADA}`, "cleo-chat": `member:${CLEO}`, "room-chat": "room:launch", "main-chat": "team", "work-chat": "team" };
+const AUDIENCES: Record<string, Audience> = {
+ "ada-chat": `member:${ADA}`, "cleo-chat": `member:${CLEO}`, "room-chat": "room:launch", "main-chat": "team", "work-chat": "team",
+ // Work her own request handed on, opened in the receiving bot's chat with her (handOnFor); Cleo's likewise.
+ "ada-work": `member:${ADA}`, "cleo-work": `member:${CLEO}`,
+};
function setup(options: { team?: boolean; requester?: Record<string, string>; servers?: Record<string, unknown> } = {}) {
const dataDir = mkdtempSync(join(tmpdir(), "omb-team-connections-"));
- const requester = { "ada-chat": ADA, "cleo-chat": CLEO, "room-chat": ADA, "main-chat": ADA, "work-chat": ADA, ...options.requester };
+ const requester = { "ada-chat": ADA, "cleo-chat": CLEO, "room-chat": ADA, "main-chat": ADA, "work-chat": ADA, "ada-work": ADA, "cleo-work": CLEO, ...options.requester };
const cfg = { mcpServers: options.servers ?? {
mail: { type: "http", url: "https://mail.example/mcp", headers: { Authorization: "Bearer team-mail-key" }, enabled: true },
console: { type: "http", url: "https://console.example/mcp", headers: { Authorization: "Bearer team-console-key" }, enabled: true },
@@ -82,64 +86,80 @@ describe("whose connection a turn may use", () => {
expect(host.personApps()).toEqual([]);
});
- it("is the person the turn acts for, wherever their own request began it, never in another member's private chat", () => {
+ it("is the person the turn acts for, only in a chat that is theirs alone, where nobody else reads what their apps bring back", () => {
const { host } = setup({ requester: { "room-chat": ADA, "main-chat": BEN, "work-chat": CLEO } });
expect(host.turnPerson("ada-chat")).toBe(ADA);
- expect(host.turnPerson("room-chat"), "her own line in a group chat").toBe(ADA);
- expect(host.turnPerson("main-chat"), "his own line in the bot's main chat").toBe(BEN);
- expect(host.turnPerson("work-chat"), "work handed on from her request").toBe(CLEO);
+ expect(host.turnPerson("ada-work"), "work her request handed on, in the receiving bot's chat with her").toBe(ADA);
expect(host.turnPerson("cleo-chat")).toBe(CLEO);
- const admin = setup({ requester: { "ada-chat": BEN } }).host;
- expect(admin.turnPerson("ada-chat"), "Ben's request never acts for anyone in Ada's private chat").toBeNull();
- const routine = setup({ requester: { "ada-chat": "", "room-chat": "", "work-chat": "" } }).host;
- for (const thread of ["ada-chat", "room-chat", "work-chat"]) expect(routine.turnPerson(thread), `a routine or a webhook acts for nobody (${thread})`).toBeNull();
+ expect(host.turnPerson("room-chat"), "her own line in a group chat: others read it").toBeNull();
+ expect(host.turnPerson("main-chat"), "his own line in the bot's main chat: others read it").toBeNull();
+ expect(host.turnPerson("work-chat"), "work handed on into a thread others read").toBeNull();
+ const admin = setup({ requester: { "ada-chat": BEN, "ada-work": BEN } }).host;
+ for (const thread of ["ada-chat", "ada-work"]) expect(admin.turnPerson(thread), `Ben's request never acts for anyone in Ada's chat (${thread})`).toBeNull();
+ const routine = setup({ requester: { "ada-chat": "", "ada-work": "" } }).host;
+ for (const thread of ["ada-chat", "ada-work"]) expect(routine.turnPerson(thread), `a routine or a webhook acts for nobody (${thread})`).toBeNull();
expect(setup({ team: false }).host.turnPerson("ada-chat"), "off a team nothing is anyone's").toBeNull();
});
+
+ it("opens work a person's request hands on in the receiving bot's chat with them, when they connected anything of their own", () => {
+ const { host, dataDir } = setup({ requester: { "main-chat": CLEO, "work-chat": "" } });
+ expect(host.handOnFor("room-chat", "g"), "nothing of hers connected: the work opens where it always did").toBeNull();
+ adaConnected(host, dataDir);
+ for (const thread of ["room-chat", "ada-chat"]) expect(host.handOnFor(thread, "g"), thread).toBe(ADA);
+ expect(host.handOnFor("main-chat", "g"), "Cleo connected nothing of hers").toBeNull();
+ expect(host.handOnFor("work-chat", "g"), "work nobody's request started").toBeNull();
+ const keyOnly = setup();
+ keyOnly.host.scopes.set("mcp", "mail", "person");
+ keyOnly.host.people.putKey(ADA, "[email protected]", "mail", { url: "https://mail.example/mcp", header: "Authorization", value: "Bearer ada-own-mail-key" });
+ expect(keyOnly.host.handOnFor("room-chat", "g"), "her own key for a server is hers too").toBe(ADA);
+ expect(setup({ team: false }).host.handOnFor("room-chat", "g")).toBeNull();
+ });
});
describe("apps each person connects", () => {
- it("mounts a member's own bridge in every turn that acts for her, minted for her, and in no other", async () => {
+ it("mounts a member's own bridge only in her own chats, minted for her, and in no other", async () => {
const { host, dataDir, minted } = setup({ requester: { "main-chat": CLEO } });
adaConnected(host, dataDir);
const own = await host.appsIntegrations({ id: "scout", name: "Scout" }, "ada-chat", "gen-1");
expect(own.composio?.env.AS).toBe("team");
expect(own.composioOwn?.env.AS).toBe("own");
expect(minted.map((entry) => entry.connectorsFor)).toEqual([undefined, ADA]);
- for (const thread of ["room-chat", "work-chat"]) {
- minted.length = 0;
- const hers = await host.appsIntegrations({ id: "scout", name: "Scout" }, thread, "gen-1");
- expect(hers.composioOwn?.env.AS, `${thread}: her own request`).toBe("own");
- expect(minted.map((entry) => entry.connectorsFor), thread).toEqual([undefined, ADA]);
- }
- for (const thread of ["main-chat", "cleo-chat"]) {
+ minted.length = 0;
+ expect((await host.appsIntegrations({ id: "helper", name: "Helper" }, "ada-work", "gen-1")).composioOwn?.env.AS, "work her request handed on, in its chat with her").toBe("own");
+ expect(minted.map((entry) => entry.connectorsFor)).toEqual([undefined, ADA]);
+ for (const thread of ["room-chat", "work-chat", "main-chat", "cleo-chat"]) {
const elsewhere = await host.appsIntegrations({ id: "scout", name: "Scout" }, thread, "gen-1");
expect(elsewhere.composio, thread).toBeDefined();
- expect(elsewhere.composioOwn, `${thread}: Cleo's request, and Cleo connected nothing`).toBeUndefined();
+ expect(elsewhere.composioOwn, `${thread}: others read it, or it is someone else's`).toBeUndefined();
}
const admin = setup({ requester: { "ada-chat": BEN } });
adaConnected(admin.host, admin.dataDir);
expect((await admin.host.appsIntegrations({ id: "scout", name: "Scout" }, "ada-chat", "gen-1")).composioOwn).toBeUndefined();
});
- it("never gives one person's work another's: Ada's room line and the work it hands on get only Ada's, Cleo's only Cleo's", async () => {
- const { host, dataDir, minted, composio } = setup({ requester: { "room-chat": ADA, "work-chat": CLEO } });
+ it("never gives one person's work another's: work Ada's request handed on gets only Ada's, Cleo's only Cleo's", async () => {
+ const { host, dataDir, minted, composio } = setup();
adaConnected(host, dataDir, { cleo: true });
+ await host.appsIntegrations({ id: "helper", name: "Helper" }, "ada-work", "gen-ada");
+ await host.appsIntegrations({ id: "helper", name: "Helper" }, "cleo-work", "gen-cleo");
await host.appsIntegrations({ id: "scout", name: "Scout" }, "room-chat", "gen-room");
- await host.appsIntegrations({ id: "helper", name: "Helper" }, "work-chat", "gen-work");
- expect(minted.filter((entry) => entry.connectorsFor).map((entry) => [entry.threadId, entry.connectorsFor])).toEqual([["room-chat", ADA], ["work-chat", CLEO]]);
+ expect(minted.filter((entry) => entry.connectorsFor).map((entry) => [entry.threadId, entry.connectorsFor])).toEqual([["ada-work", ADA], ["cleo-work", CLEO]]);
const owns = composio.mcpIntegration.mock.calls.map(([, context]) => context as typeof context & { threadId: string }).filter((context) => context.as);
- expect(owns.map((context) => [context.threadId, context.as])).toEqual([["room-chat", ADA_ACCESS], ["work-chat", CLEO_ACCESS]]);
- // A bridge minted for one person is refused in a turn that acts for the other, on every call.
- expect(host.relayActor({ threadId: "room-chat", generation: "gen-room", connectorsFor: ADA })).toEqual({ access: ADA_ACCESS });
- expect(host.relayActor({ threadId: "room-chat", generation: "gen-room", connectorsFor: CLEO }).refusal).toMatch(/[email protected]'s own apps, and this turn no longer acts for [email protected]/);
- expect(host.relayActor({ threadId: "work-chat", generation: "gen-work", connectorsFor: ADA }).refusal).toMatch(/[email protected]'s own apps/);
+ expect(owns.map((context) => [context.threadId, context.as])).toEqual([["ada-work", ADA_ACCESS], ["cleo-work", CLEO_ACCESS]]);
+ // A bridge minted for one person is refused in a turn that acts for the other, and anywhere others read, on every call.
+ expect(host.relayActor({ threadId: "ada-work", generation: "gen-ada", connectorsFor: ADA })).toEqual({ access: ADA_ACCESS });
+ expect(host.relayActor({ threadId: "ada-work", generation: "gen-ada", connectorsFor: CLEO }).refusal).toMatch(/[email protected]'s own apps, and this turn no longer acts for [email protected]/);
+ expect(host.relayActor({ threadId: "cleo-work", generation: "gen-cleo", connectorsFor: ADA }).refusal).toMatch(/[email protected]'s own apps/);
+ expect(host.relayActor({ threadId: "room-chat", generation: "gen-room", connectorsFor: ADA }).refusal, "her own room line: the room reads it").toMatch(/[email protected]'s own apps/);
expect(host.relayActor({ threadId: "cleo-chat", generation: "g", connectorsFor: ADA }).refusal, "her bridge in Cleo's private chat").toMatch(/[email protected]'s own apps/);
- // Each turn's MCP servers carry only its own person's key.
- const room = JSON.stringify(await host.turnMcp(BOT, "room-chat", "gen-room")), work = JSON.stringify(await host.turnMcp(BOT, "work-chat", "gen-work"));
- expect(room).toContain("ada-own-mail-key");
- expect(room).not.toContain("cleo-own-mail-key");
- expect(work).toContain("cleo-own-mail-key");
- expect(work).not.toContain("ada-own-mail-key");
+ // Each turn's MCP servers carry only its own person's key, and a chat others read carries none.
+ const ada = JSON.stringify(await host.turnMcp(BOT, "ada-work", "gen-ada")), cleo = JSON.stringify(await host.turnMcp(BOT, "cleo-work", "gen-cleo"));
+ const room = JSON.stringify(await host.turnMcp(BOT, "room-chat", "gen-room"));
+ expect(ada).toContain("ada-own-mail-key");
+ expect(ada).not.toContain("cleo-own-mail-key");
+ expect(cleo).toContain("cleo-own-mail-key");
+ expect(cleo).not.toContain("ada-own-mail-key");
+ expect(room).not.toMatch(/own-mail-key/);
});
it("relays a member's own bridge to her installation, and refuses it once the turn doesn't act for her", () => {
@@ -181,7 +201,11 @@ describe("apps each person connects", () => {
expect(nobody, "the fix, in one line, never \"open a private chat\"").toContain("\"Gmail is each person's own, so I can't use it here. Ask me yourself and I'll use yours, or an admin can connect Gmail for the whole team: https://cloud.example.test/cloud/team/team-acme-1/apps.\"");
expect(nobody).toContain("Don't try it another way (the browser or another tool).");
expect(nobody).not.toMatch(/private chat/);
- expect(await host.callRefusal({ threadId: "room-chat", generation: "g" }, [{ slug: "GMAIL_FETCH_EMAILS" }]), "her own room line: hers, through her bridge").toMatch(/Gmail here is [email protected]'s own: use it through the own_apps tools/);
+ const shared = await host.callRefusal({ threadId: "room-chat", generation: "g" }, [{ slug: "GMAIL_FETCH_EMAILS" }]);
+ expect(shared, "her own room line: the room reads what it brings back").toMatch(/^Gmail is [email protected]'s own, and others read this chat, so what it brings back can't come here and it isn't used here\./);
+ expect(shared, "and how it gets done instead").toContain("To use it, hand that part on: to yourself with start_thread, or to a teammate with coordinate_bots. It runs in that bot's chat with [email protected], with [email protected]'s own apps, and only a line saying where the result is comes back here: say only that here.");
+ expect(shared).toContain("Don't try it another way (the browser or another tool).");
+ expect(await host.callRefusal({ threadId: "ada-work", generation: "g" }, [{ slug: "GMAIL_FETCH_EMAILS" }]), "work handed on into her chat: hers, through her bridge").toMatch(/Gmail here is [email protected]'s own: use it through the own_apps tools/);
expect(await host.callRefusal(team, [{ slug: "SLACK_SEND_MESSAGE" }]), "a team app passes").toBeNull();
expect(await host.callRefusal({ threadId: "ada-chat", generation: "g" }, [{ slug: "GMAIL_SEND_EMAIL" }])).toMatch(/through the own_apps tools/);
expect(await host.callRefusal({ threadId: "ada-chat", generation: "g", connectorsFor: ADA }, [{ slug: "GMAIL_SEND_EMAIL" }])).toBeNull();
@@ -218,9 +242,8 @@ describe("MCP servers each person connects", () => {
const own = await host.turnMcp(BOT, "ada-chat", "g");
expect(own.mail).toEqual({ type: "http", url: "https://mail.example/mcp", headers: { Authorization: "Bearer ada-own-mail-key" } });
expect(own.console, "the team's server is the team's, with its key").toEqual({ type: "http", url: "https://console.example/mcp", headers: { Authorization: "Bearer team-console-key" } });
- expect((await host.turnMcp(BOT, "room-chat", "g")).mail, "her own room line").toEqual(own.mail);
- expect((await host.turnMcp(BOT, "work-chat", "g")).mail, "work handed on from her request").toEqual(own.mail);
- for (const thread of ["main-chat", "cleo-chat"]) {
+ expect((await host.turnMcp(BOT, "ada-work", "g")).mail, "work her request handed on, in its chat with her").toEqual(own.mail);
+ for (const thread of ["room-chat", "work-chat", "main-chat", "cleo-chat"]) {
const elsewhere = await host.turnMcp(BOT, thread, "g");
expect(elsewhere.mail, thread).toBeUndefined();
expect(JSON.stringify(elsewhere), thread).not.toContain("ada-own-mail-key");
@@ -259,10 +282,16 @@ describe("what the bot and the admins are told", () => {
const { host, dataDir } = setup({ requester: { "main-chat": "" } });
adaConnected(host, dataDir);
host.scopes.set("app", "outlook", "person");
- const own = host.prompt("room-chat", "g", { composioOwn: {}, custom: { mail: {} } });
+ const own = host.prompt("ada-work", "g", { composioOwn: {}, custom: { mail: {} } });
expect(own).toContain("Gmail and Outlook are [email protected]'s own: use them through the own_apps tools");
expect(own).toContain("The MCP server mail acts as [email protected]'s own account.");
- expect(own, "in a group chat, never for anyone else's request").toContain("They are used only for [email protected]'s request: if someone else asks for something from them, say they are [email protected]'s.");
+ expect(own, "never for anyone else's request").toContain("They are used only for [email protected]'s request: if someone else asks for something from them, say they are [email protected]'s.");
+ const shared = host.prompt("room-chat", "g", {});
+ expect(shared, "her own room line: others read it").toContain("Gmail, Outlook and mail are each person's own in Acme, used only in a chat that is theirs alone. Others read this chat, so [email protected]'s own aren't here");
+ expect(shared).toContain("hand that part on: to yourself with start_thread, or to a teammate with coordinate_bots. It runs in that bot's chat with [email protected]");
+ const cleos = setup({ requester: { "room-chat": CLEO } }).host;
+ cleos.scopes.set("app", "gmail", "person");
+ expect(cleos.prompt("room-chat", "g", {}), "Cleo connected nothing yet").toMatch(/and this person hasn't connected any yet\. .*"Connect your <name> here: https:\/\/cloud\.example\.test\/cloud\/team\/team-acme-1"\./);
const missing = host.prompt("ada-chat", "g", { custom: {} });
expect(missing).toContain("Each person connects these for themselves, and [email protected] hasn't connected them yet, or their sign-in ended: Gmail, Outlook and mail.");
expect(missing).toContain("\"Connect your <name> here: https://cloud.example.test/cloud/team/team-acme-1\"");
@@ -277,7 +306,7 @@ describe("what the bot and the admins are told", () => {
it("says whose own account a step used: a person's app through her bridge, or a person's server, in a turn that acts for her", () => {
const { host, dataDir } = setup({ requester: { "main-chat": "" } });
adaConnected(host, dataDir);
- const named = (tool: string, input?: unknown, thread = "room-chat") => host.toolWhose(thread, "g", tool, input);
+ const named = (tool: string, input?: unknown, thread = "ada-work") => host.toolWhose(thread, "g", tool, input);
expect(named("mcp__own_apps__GMAIL_FETCH_EMAILS")).toEqual({ whose: { person: "[email protected]", app: "Gmail" } });
expect(named("mcp__own_apps__COMPOSIO_MULTI_EXECUTE_TOOL", JSON.stringify({ tools: [{ tool_slug: "GMAIL_SEND_EMAIL" }] })), "a meta-tool names its app tools").toEqual({ whose: { person: "[email protected]", app: "Gmail" } });
expect(named("GMAIL_FETCH_EMAILS"), "an engine that names the tool alone").toEqual({ whose: { person: "[email protected]", app: "Gmail" } });
@@ -286,14 +315,15 @@ describe("what the bot and the admins are told", () => {
expect(named("mcp__console__query"), "the team's server").toEqual({});
expect(named("mcp__composio__SLACK_SEND_MESSAGE"), "a team app").toEqual({});
expect(named("mcp__own_apps__GMAIL_FETCH_EMAILS", undefined, "main-chat"), "a turn that acts for nobody").toEqual({});
- expect(host.toolWhose("room-chat", undefined, "mcp__own_apps__GMAIL_FETCH_EMAILS"), "no turn running").toEqual({});
- const cleos = setup({ requester: { "work-chat": CLEO } });
+ expect(host.toolWhose("ada-work", undefined, "mcp__own_apps__GMAIL_FETCH_EMAILS"), "no turn running").toEqual({});
+ expect(named("mcp__own_apps__GMAIL_FETCH_EMAILS", undefined, "room-chat"), "a chat others read uses none of hers").toEqual({});
+ const cleos = setup();
adaConnected(cleos.host, cleos.dataDir);
- expect(cleos.host.toolWhose("work-chat", "g", "mcp__own_apps__GMAIL_FETCH_EMAILS"), "Cleo connected nothing of hers").toEqual({});
- expect(cleos.host.toolWhose("work-chat", "g", "mcp__mail__read_inbox")).toEqual({});
- const named2 = setup({ requester: { "room-chat": ADA } });
+ expect(cleos.host.toolWhose("cleo-work", "g", "mcp__own_apps__GMAIL_FETCH_EMAILS"), "Cleo connected nothing of hers").toEqual({});
+ expect(cleos.host.toolWhose("cleo-work", "g", "mcp__mail__read_inbox")).toEqual({});
+ const named2 = setup();
adaConnected(named2.host, named2.dataDir);
- expect(named2.host.toolWhose("room-chat", "g", "mcp__own_apps__GMAIL_FETCH_EMAILS")).toEqual({ whose: { person: "[email protected]", app: "Gmail" } });
+ expect(named2.host.toolWhose("ada-chat", "g", "mcp__own_apps__GMAIL_FETCH_EMAILS")).toEqual({ whose: { person: "[email protected]", app: "Gmail" } });
});
it("says who connected what for the admin read, by address, never a secret", async () => {
diff --git a/server/host/team-connections-host.ts b/server/host/team-connections-host.ts
index a3bc2f4777..9561ea56a6 100644
--- a/server/host/team-connections-host.ts
+++ b/server/host/team-connections-host.ts
@@ -1,9 +1,11 @@
// Whose connection a turn on a Team Cloud may use. The team's connections serve every turn; a `person` app or MCP server
-// is offered to a turn only for the person it acts for (server/host/acting-person.ts): their own message started its work,
-// in their private chat, a group chat or the bot's main chat, or the work was handed on from a turn that acted for them.
+// is offered to a turn only for the person it acts for (server/host/acting-person.ts), and only in that person's own
+// private chat, where nobody else reads what it brings back. Work their own message started in a group chat or the bot's
+// main chat reaches their own connections by being handed on (handOnFor): it opens in the receiving bot's chat with them,
+// and the shared place gets only a line saying where the result is (acting-person.ts privateHandBack).
// Security: nothing else ever gets a member's connection: not another person's request or the work it hands on, not a
-// turn someone else wrote into, not another member's private chat, a routine or a webhook. The relay checks it again on
-// every call. Off a team nothing changes.
+// turn someone else wrote into, not a chat anyone else reads, a routine or a webhook. The relay checks it again on every
+// call. Off a team nothing changes.
import { createHash } from "node:crypto";
import { join } from "node:path";
@@ -96,18 +98,20 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
const without = <T,>(servers: Record<string, T>, names: readonly string[]) =>
Object.fromEntries(Object.entries(servers).filter(([name]) => !names.includes(name)));
- /** The member a turn acts for, so it may use their own connections: never in another member's private chat. */
+ /** The member a turn acts for, in a chat nobody else reads: theirs. */
+ const actingFor = (threadId: string, generation?: string): string | null => (team ? deps.requester(threadId, generation) : null);
+ /** The member a turn may use the own connections of: the one it acts for, in their own private chat only. */
const turnPerson = (threadId: string, generation?: string): string | null => {
- if (!team) return null;
- const person = deps.requester(threadId, generation);
- const member = audienceMember(deps.audienceOf(threadId));
- return person && (member === null || member === person) ? person : null;
+ const member = team ? audienceMember(deps.audienceOf(threadId)) : null;
+ return member && actingFor(threadId, generation) === member ? member : null;
};
const nameOf = (person: string): string => deps.personName?.(person) || people.emailOf(person) || "this person";
const teamName = () => team?.name ?? "the team";
/** An admin's page for who connects each app, where one can be connected for the whole team. */
const appsPage = () => { const where = link(); return where ? `${where}/apps` : null; };
const noWorkaround = "Nothing was run. Don't try it another way (the browser or another tool).";
+ /** How work a person started where others read reaches their own apps: handed on into a chat that is theirs alone. */
+ const handOnHow = (who: string) => `To use it, hand that part on: to yourself with start_thread, or to a teammate with coordinate_bots. It runs in that bot's chat with ${who}, with ${who}'s own apps, and only a line saying where the result is comes back here: say only that here.`;
const lines = {
connect: (name: string, who: string) => {
@@ -121,6 +125,8 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
return `${name} is each person's own in ${teamName()}, and this work doesn't act for one person (a routine, an outside app or a bot started it, or more than one person wrote in it), so no one's ${name} can be used. ${noWorkaround} Reply with this one line and nothing more about it: `
+ `"${name} is each person's own, so I can't use it here. Ask me yourself and I'll use yours${where ? `, or an admin can connect ${name} for the whole team: ${where}` : ""}."`;
},
+ /** The person's own app, asked for where others read: never here, and how it gets done instead. */
+ shared: (name: string, who: string) => `${name} is ${who}'s own, and others read this chat, so what it brings back can't come here and it isn't used here. ${noWorkaround} ${handOnHow(who)}`,
ownOnly: (who: string) => `These are ${who}'s own apps, and this turn no longer acts for ${who}: it was stopped, or someone else wrote in it since. ${noWorkaround} Say so in one plain line: ${who} can ask again.`,
ownGone: (who: string) => {
const where = link();
@@ -135,8 +141,18 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
/** What a `person` app the team's bridge was asked for says: in a turn that acts for someone, where theirs is; else no. */
const personAppLine = (app: string, threadId: string, generation?: string): string => {
const person = turnPerson(threadId, generation);
- if (!person) return lines.nobody(appLabel(app));
- return people.appsAccess(person) ? `${appLabel(app)} here is ${nameOf(person)}'s own: use it through the ${OWN_APPS_SERVER} tools. Nothing was run.` : lines.connect(appLabel(app), nameOf(person));
+ if (person) return people.appsAccess(person) ? `${appLabel(app)} here is ${nameOf(person)}'s own: use it through the ${OWN_APPS_SERVER} tools. Nothing was run.` : lines.connect(appLabel(app), nameOf(person));
+ const acting = actingFor(threadId, generation);
+ if (!acting) return lines.nobody(appLabel(app));
+ return people.appsAccess(acting) ? lines.shared(appLabel(app), nameOf(acting)) : lines.connect(appLabel(app), nameOf(acting));
+ };
+ /** Whether a person connected anything of their own here: an app installation, or a key or sign-in for a server. */
+ const hasOwn = (person: string): boolean => {
+ if (personApps().length && people.appsAccess(person)) return true;
+ return personMcp().some((name) => {
+ const server = teamServer(name);
+ return Boolean(server && isRemoteMcpServer(server) && (people.key(person, name, server.url) || people.oauth(person).authState(name, server.url) === "signed-in"));
+ });
};
const personSpec = async (person: string, name: string, spec: Extract<McpServerSpec, { url: string }>): Promise<McpServerSpec | null> => {
@@ -158,6 +174,12 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
personMcp,
link,
turnPerson,
+ /** The person whose private chat work this turn hands on opens in, so it can use their own connections there: the
+ * person the turn acts for, when they connected anything of their own. Null: it opens where it always did. */
+ handOnFor(threadId: string, generation: string): string | null {
+ const person = actingFor(threadId, generation);
+ return person && hasOwn(person) ? person : null;
+ },
/** At start: the team's installation's apps are read now, so the first turn need not wait for them. */
primeApps(): void {
if (deps.composio.configured(deps.cfg())) void appsConnected();
@@ -221,7 +243,7 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
const app = apps.includes(slug) ? slug : null;
if (capability.connectorsFor) return app ? lines.connect(appLabel(app), nameOf(capability.connectorsFor)) : lines.teamCard(appLabel(slug));
if (app) {
- const person = turnPerson(capability.threadId, capability.generation);
+ const person = turnPerson(capability.threadId, capability.generation) ?? actingFor(capability.threadId, capability.generation);
return person ? lines.connect(appLabel(app), nameOf(person)) : lines.nobody(appLabel(app));
}
}
@@ -257,6 +279,14 @@ export function createTeamConnectionsHost(deps: TeamConnectionsHostDeps) {
if (!team || (!apps.length && !servers.length)) return "";
const names = [...apps.map(appLabel), ...servers];
const person = turnPerson(threadId, generation);
+ const acting = person ? null : actingFor(threadId, generation);
+ if (acting) {
+ const who = nameOf(acting);
+ const these = `${list(names)} ${names.length === 1 ? "is" : "are"} each person's own in ${team.name}`;
+ return hasOwn(acting)
+ ? ` ${these}, used only in a chat that is theirs alone. Others read this chat, so ${who}'s own aren't here: what they bring back would be read here. If the task needs one, don't try it another way (the browser or another tool). ${handOnHow(who)}`
+ : ` ${these}, and ${who} hasn't connected any yet. If the task needs one, don't try it another way (the browser or another tool): reply with one plain line and nothing more about it: "Connect your <name> here: ${link() ?? "your team's page in MausBot Cloud"}".`;
+ }
if (!person) {
const where = appsPage();
return ` ${list(names)} ${names.length === 1 ? "is" : "are"} each person's own in ${team.name}: ${names.length === 1 ? "it works" : "they work"} for the person whose own message started the work, and this work doesn't act for one person (a routine, an outside app or a bot started it, or more than one person wrote in it). `
diff --git a/server/index.ts b/server/index.ts
index 7bbf5cedc6..416ac8f1d4 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -628,7 +628,7 @@ import { createPersonReplies } from "./person-replies.ts";
import { personKey, relayedPersonKey } from "./person-key.ts";
import { createTeamOwners, type AskViewer } from "./host/team-owners.ts"; import { createTeamMessages } from "./host/team-messages.ts"; import { relayedTurn } from "./host/relayed-turn.ts"; import { createPersonCalendar } from "./host/person-calendar.ts";
import { createDevsReports } from "./host/devs-reports.ts"; import { bugReportEndpoint, devsReportSender } from "./devs-report-send.ts"; import { captureRecentLog } from "./recent-log.ts";
-import { createCardRequester, linePersonKey } from "./host/thread-person.ts"; import { createActingPeople, HANDED_PEOPLE_FILE, HandedPeople, type HandedRun, withPerson } from "./host/acting-person.ts";
+import { createCardRequester, linePersonKey } from "./host/thread-person.ts"; import { createActingPeople, HANDED_PEOPLE_FILE, HandedPeople, type HandedRun, privateHandBack, withPerson } from "./host/acting-person.ts";
import { createThreadRoutes } from "./routes/threads.ts";
import { createWebhookRoutes } from "./routes/webhooks.ts";
import { withScopeHint } from "./connector-scope-hint.ts";
@@ -4102,7 +4102,9 @@ const coordinator: Coordinator = createCoordinator({
let done = false;
const finish = (outcome: HostTurnResult) => {
if (done) return;
- done = true; signal.removeEventListener("abort", abort); resolve(outcome);
+ // Work that ran in one person's private chat hands back to a chat others read only where its result is.
+ const person = teamHost.privateTo(node.threadId);
+ done = true; signal.removeEventListener("abort", abort); resolve(privateHandBack(outcome, { child: person, parent: parent ? teamHost.privateTo(parent.threadId) : null, bot: bot.name, person: (person && teamHost.personName(person)) || "them" }));
};
const abort = () => {
void interruptDirectThread(bot.id, node.threadId).catch(() => {});
@@ -13922,7 +13924,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
{ approvals: blocked });
approvalGranted = true;
}
- const requestBatchKey = destination ? randomUUID() : undefined;
+ const requestBatchKey = destination ? randomUUID() : undefined, handOnFor = CLOUD_TEAM ? teamConnections.handOnFor(internalCapability.threadId, internalCapability.generation) : null;
const generation = EXTERNAL ? randomUUID() : internalCapability.generation;
if (EXTERNAL) {
const opener = handoffOpener(internalCapability, address.threadId);
@@ -13942,7 +13944,9 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
requireActiveInternalCapability();
const recipient = store.bot(target.botId);
if (!recipient) throw new Error("The recipient no longer exists");
- const continued = room || fresh ? undefined : store.workThread(target.botId, internalSender.id, address.threadId);
+ // Work a person's request hands on opens in the receiving bot's chat with them when it may use their own apps.
+ const opener = (room ? null : handOnFor) ?? openerFrom(address.threadId);
+ const continued = room || fresh ? undefined : store.workThread(target.botId, internalSender.id, address.threadId, false, CLOUD_TEAM ? (task) => threadStarters.get(task.threadId) === opener : undefined);
const lane = room && lanes ? roomJobs.openLane(room, target.threadId, target.botId, internalSender, call.message) : undefined;
const via = lane ? "lane" : room ? "room" : "direct";
if (lane?.created) createdThread = lane.threadId;
@@ -13965,7 +13969,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
usageTrace.link(node.id, node.parentId, { threadId: internalCapability.threadId, turnId: liveTurnByThread.get(internalCapability.threadId) ?? "" }); if (!duplicate) actingPeople.handOn(internalCapability, node);
if (duplicate && createdThread) store.deleteTask(target.botId, createdThread);
else if (createdThread) {
- threadStarters.set(createdThread, openerFrom(address.threadId));
+ threadStarters.set(createdThread, opener);
if (fresh && !EXTERNAL) internalCapability.openedThreads += 1;
}
createdThread = undefined;
@@ -14300,7 +14304,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
const task = store.createTask(from.id, title, false, projectId, { botId: from.id, name: from.name, at: Date.now() },
inherited.approvalMode, inherited.modelSelection);
if (!task) return json(res, 500, { error: "couldn't create that thread" });
- threadStarters.set(task.threadId, openerFrom(fromThreadId));
+ threadStarters.set(task.threadId, (CLOUD_TEAM ? teamConnections.handOnFor(internalCapability.threadId, internalCapability.generation) : null) ?? openerFrom(fromThreadId));
internalCapability.openedThreads += 1;
const chip: Omit<Message, "id" | "at"> = {
role: "bot",
diff --git a/server/store.ts b/server/store.ts
index 022a0dd2d3..e07fe6e74e 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -2045,9 +2045,9 @@ export class Store {
return this.bot(botId)?.tasks?.find((t) => t.threadId === threadId);
}
- workThread(botId: string, fromBotId: string, fromThreadId: string, roomLane = false): TaskRecord | undefined {
+ workThread(botId: string, fromBotId: string, fromThreadId: string, roomLane = false, also: (task: TaskRecord) => boolean = () => true): TaskRecord | undefined {
return this.tasks(botId).find((t) => t.openedBy?.kind === "work" && t.openedBy.botId === fromBotId &&
- t.openedBy.threadId === fromThreadId && Boolean(t.openedBy.roomLane) === roomLane && t.archivedAt === undefined);
+ t.openedBy.threadId === fromThreadId && Boolean(t.openedBy.roomLane) === roomLane && t.archivedAt === undefined && also(t));
}
projectBotForTask(botId: string, threadId: string): BotRecord | null {