diff --git a/apps/web/src/state/threads.ts b/apps/web/src/state/threads.ts index ce2f941074e78..9e164f425736e 100644 --- a/apps/web/src/state/threads.ts +++ b/apps/web/src/state/threads.ts @@ -12,7 +12,12 @@ import { createThreadEnvironmentAtoms, createThreadFamilyAtoms, } from "@t3tools/client-runtime/state/threads"; -import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts"; +import { + inboxOriginFor, + type EnvironmentId, + type OrchestrationV2ThreadShell, + type ThreadId, +} from "@t3tools/contracts"; import * as Option from "effect/Option"; import { AsyncResult, Atom } from "effect/reactivity"; @@ -33,12 +38,7 @@ export const olderSettledThreads = createOlderSettledThreadAtoms( export const threadEnvironment = createThreadEnvironmentAtoms( connectionAtomRuntime, threadFamilies.snapshotAtom, - { - getInboxOrigin: () => ({ - kind: "human", - id: getClientSettings().founderInboxOwner ?? "kameron", - }), - }, + { getInboxOrigin: () => inboxOriginFor(getClientSettings()) }, ); const environmentThreads = createEnvironmentThreadStateAtoms(connectionAtomRuntime); export const environmentThreadDetails = createEnvironmentThreadDetailAtoms( diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index bb71f853081d0..bde1cf4ca7dd8 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -7,6 +7,7 @@ import { routeThreadInbox, matchesInboxView, effectiveInboxView, + inboxOriginFor, founderInboxLane, compositeThreadKey, } from "./threadInbox.ts"; @@ -50,6 +51,21 @@ describe("shared fleet organizational inbox", () => { expect([effectiveInboxView(saved), saved.founderInboxOwner]).toEqual([picked, "jeff"]); } }); + it("attributes new work only to a chosen founder and leaves unchosen work in All", () => { + expect(inboxOriginFor({})).toBeUndefined(); + // The server creates no inbox for a human thread without an origin, like legacy history. + for (const view of ["kameron", "jeff", "agents", "shared"] as const) { + expect(matchesInboxView(undefined, view)).toBe(false); + } + expect(matchesInboxView(undefined, effectiveInboxView({}))).toBe(true); + const origin = inboxOriginFor({ founderInboxOwner: "jeff" }); + expect(origin).toEqual(jeff); + const inbox = makeThreadInbox({ actor: origin ?? null }); + expect([matchesInboxView(inbox, "jeff"), matchesInboxView(inbox, "kameron")]).toEqual([ + true, + false, + ]); + }); it("hides bot-only work by default while All and Agents retain it", () => { const inbox = makeThreadInbox({ actor: bot }); expect(matchesInboxView(inbox, "kameron")).toBe(false); diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index a4f11906e604c..d9bc3b9b7eb87 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -103,6 +103,14 @@ export const effectiveInboxView = (settings: { readonly founderInboxOwner?: Founder | undefined; }): InboxView => settings.founderInboxView ?? settings.founderInboxOwner ?? "all"; +/** New work is attributed only to a chosen founder; otherwise it stays unclassified (All). */ +export const inboxOriginFor = (settings: { + readonly founderInboxOwner?: Founder | undefined; +}): InboxActor | undefined => + settings.founderInboxOwner === undefined + ? undefined + : { kind: "human", id: settings.founderInboxOwner }; + /** All deliberately includes every thread, including unclassified history. */ export function matchesInboxView(inbox: ThreadInbox | null | undefined, view: InboxView) { if (view === "all") return true;