Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
latestProviderTurnForAttempt,
resolveProjectProviderInstanceEnabled,
SECRET_REQUEST_UNSAVED_NOTE,
agentLaunchInboxRouting,
} from "@t3tools/contracts";
import { getProviderOptionCurrentValue, withLegacyUltracodeEffort } from "@t3tools/shared/model";
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
Expand Down Expand Up @@ -3216,11 +3217,7 @@ const make = Effect.gen(function* () {
.dispatch({
type: "thread.create",
inboxOrigin: { kind: "agent", id: parent.thread.id },
...(request.inboxRouting !== undefined
? { inboxRouting: request.inboxRouting }
: parent.thread.inbox === undefined
? {}
: { inboxRouting: parent.thread.inbox }),
inboxRouting: agentLaunchInboxRouting(request),
createdBy: "agent",
creationSource: "mcp",
commandId,
Expand Down
33 changes: 33 additions & 0 deletions apps/server/src/mcp/toolkits/project/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,39 @@ it.effect("a launch with a model its provider does not advertise creates no thre
}),
);

it.effect("a launch is filed in Agents unless the agent picks an inbox", () =>
Effect.gen(function* () {
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
const { projectId, dependencies } = clientLaunchHarness({
runtimeModeCeiling: "auto",
launched,
});
const toolkit = yield* ProjectToolkit.pipe(
Effect.provide(
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
),
);
const launch = (inbox?: "kameron" | "shared") =>
toolkit
.handle("t3_thread_launch", {
title: "Fix",
projectId,
...(inbox === undefined ? {} : { inbox }),
})
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));

yield* launch();
yield* launch("kameron");
yield* launch("shared");
expect(launched.map((input) => input.inboxRouting?.audience)).toEqual([
"agent-only",
"kameron",
"shared",
]);
expect(launched[1]?.inboxRouting?.assignee).toEqual({ kind: "human", id: "kameron" });
}),
);

it.effect("a launch retried with the same clientRequestId replays the first one", () =>
Effect.gen(function* () {
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/mcp/toolkits/project/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
agentLaunchInboxRouting,
CommandId,
type EnvironmentId,
isProviderAvailable,
Expand Down Expand Up @@ -155,6 +156,7 @@ const launchPlacedThere = Effect.fn("mcp.launchPlacedThere")(function* (
placement: _placement,
delegatedFrom: _delegatedFrom,
workspaceStrategy: _requested,
inbox: _inbox,
...params
} = input;
const launched = yield* delegation.value.launch(scope, {
Expand All @@ -165,6 +167,8 @@ const launchPlacedThere = Effect.fn("mcp.launchPlacedThere")(function* (
// The workspace and modes it was admitted with go explicitly, so nothing there changes them.
params: {
...params,
// Resolved here: a linked environment on an older release knows only inboxRouting.
inboxRouting: agentLaunchInboxRouting(input),
modelSelection,
...(local.strategy === undefined ? {} : { workspaceStrategy: local.strategy }),
runtimeMode: local.runtimeMode,
Expand Down Expand Up @@ -404,11 +408,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
}
const result = yield* ThreadMessageIntake.launchThread({
inboxOrigin: { kind: "agent", id: caller?.id ?? "agent" },
...(input.inboxRouting !== undefined
? { inboxRouting: input.inboxRouting }
: caller?.inbox === undefined
? {}
: { inboxRouting: caller.inbox }),
inboxRouting: agentLaunchInboxRouting(input),
commandId,
threadId,
projectId,
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/mcp/toolkits/project/tools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { McpAttachmentInput } from "../attachment/input.ts";
import {
clampedPositiveInt,
InboxChoiceParameter,
ThreadInboxRoutingPatch,
NonNegativeInt,
ModelSelection,
Expand Down Expand Up @@ -141,6 +142,7 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", {
"No project: a new Scratch folder. Not with `projectId` or `workspaceStrategy`.",
}),
),
inbox: Schema.optional(InboxChoiceParameter),
inboxRouting: Schema.optional(ThreadInboxRoutingPatch),
title: TrimmedNonEmptyString,
modelSelection: Schema.optional(ModelSelection),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 5930,
"codexAdditionalContextBytes": 7324,
"mcpToolListJsonBytes": 49736
"mcpToolListJsonBytes": 52637
}
20 changes: 6 additions & 14 deletions apps/web/src/components/threadActionMenu.logic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ThreadInboxRoutingPatch } from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { InboxChoice, inboxRoutingFor, type ThreadInboxRoutingPatch } from "@t3tools/contracts";
import type { ContextMenuItem } from "@t3tools/contracts";
import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled";

Expand Down Expand Up @@ -297,20 +298,11 @@ export function buildThreadActionMenuItems(
);
}

const isInboxChoice = Schema.is(InboxChoice);

export function threadRoutingUpdateFromMenuAction(action: string): ThreadInboxRoutingPatch | null {
if (action === "inbox:kameron" || action === "inbox:jeff") {
const founder = action === "inbox:kameron" ? "kameron" : "jeff";
return {
owner: founder,
assignee: { kind: "human", id: founder },
audience: founder,
attentionKind: "action",
};
}
if (action === "inbox:shared")
return { owner: null, assignee: null, audience: "shared", attentionKind: "FYI" };
if (action === "inbox:agents")
return { owner: null, assignee: null, audience: "agent-only", attentionKind: "background" };
const inbox = action.startsWith("inbox:") ? action.slice("inbox:".length) : undefined;
if (isInboxChoice(inbox)) return inboxRoutingFor(inbox);
if (action === "attention:action") return { attentionKind: "action" };
if (action === "attention:FYI") return { attentionKind: "FYI" };
if (action === "attention:background") return { attentionKind: "background" };
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/src/orchestratorMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ export const OrchestratorMcpTaskCancelResult = Schema.Struct({
});
export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type;

import { ThreadInbox, ThreadInboxRoutingPatch } from "./threadInbox.ts";
import { InboxChoiceParameter, ThreadInbox, ThreadInboxRoutingPatch } from "./threadInbox.ts";

export const OrchestratorMcpCreateThreadRequest = Schema.Struct({
inbox: Schema.optional(InboxChoiceParameter),
inboxRouting: Schema.optional(ThreadInboxRoutingPatch),
prompt: Schema.optional(OrchestratorMcpPrompt),
title: Schema.optional(OrchestratorMcpTitle),
Expand Down
22 changes: 22 additions & 0 deletions packages/contracts/src/threadInbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
inboxOriginFor,
founderInboxLane,
compositeThreadKey,
agentLaunchInboxRouting,
} from "./threadInbox.ts";
const kameron = { kind: "human", id: "kameron" } as const;
const jeff = { kind: "human", id: "jeff" } as const;
Expand Down Expand Up @@ -66,6 +67,27 @@ describe("shared fleet organizational inbox", () => {
false,
]);
});
it("files agent launches in Agents unless the agent picks an inbox", () => {
// A launch from a thread in Kameron's inbox no longer copies that routing.
const launched = (choice: Parameters<typeof agentLaunchInboxRouting>[0]) =>
makeThreadInbox({ actor: bot, routing: agentLaunchInboxRouting(choice) });
const views = ["kameron", "jeff", "shared", "agents"] as const;
const visibleIn = (inbox: ReturnType<typeof launched>) =>
views.filter((view) => matchesInboxView(inbox, view));
expect(visibleIn(launched({}))).toEqual(["agents"]);
expect(visibleIn(launched({ inbox: "kameron" }))).toEqual(["kameron", "agents"]);
expect(visibleIn(launched({ inbox: "jeff" }))).toEqual(["jeff", "agents"]);
expect(visibleIn(launched({ inbox: "shared" }))).toEqual(["shared", "agents"]);
expect(launched({ inbox: "kameron" }).origin).toEqual(bot);
const explicit = launched({
inbox: "kameron",
inboxRouting: { assignee: { kind: "human", id: "jeff" } },
});
expect(visibleIn(explicit)).toEqual(["jeff", "agents"]);
const quieter = launched({ inbox: "kameron", inboxRouting: { attentionKind: "FYI" } });
expect(visibleIn(quieter)).toEqual(["kameron", "agents"]);
expect(quieter.attentionKind).toBe("FYI");
});
it("hides bot-only work by default while All and Agents retain it", () => {
const inbox = makeThreadInbox({ actor: bot });
expect(matchesInboxView(inbox, "kameron")).toBe(false);
Expand Down
34 changes: 34 additions & 0 deletions packages/contracts/src/threadInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ export type ThreadInbox = typeof ThreadInbox.Type;
export const INBOX_CAPABILITY = "closura-founder-inbox-v2" as const;
export const InboxView = Schema.Literals(["kameron", "jeff", "shared", "agents", "all"]);
export type InboxView = typeof InboxView.Type;
/** An inbox a thread can be filed into: every view except All. */
export const InboxChoice = Schema.Literals(["kameron", "jeff", "shared", "agents"]);
export type InboxChoice = typeof InboxChoice.Type;

/** The routing that files a thread into one inbox, shared by the thread menu and agent launches. */
export function inboxRoutingFor(inbox: InboxChoice): ThreadInboxRouting {
if (inbox === "shared")
return { owner: null, assignee: null, audience: "shared", attentionKind: "FYI" };
if (inbox === "agents")
return { owner: null, assignee: null, audience: "agent-only", attentionKind: "background" };
return {
owner: inbox,
assignee: { kind: "human", id: inbox },
audience: inbox,
attentionKind: "action",
};
}

/**
* Where an agent-launched top-level thread is filed: the chosen inbox, else Agents, so agent
* work never lands in a founder's inbox by default. `inboxRouting` adjusts the chosen inbox.
*/
export const agentLaunchInboxRouting = (input: {
readonly inbox?: InboxChoice | undefined;
readonly inboxRouting?: ThreadInboxRoutingPatch | undefined;
}): ThreadInboxRoutingPatch =>
input.inbox === undefined
? (input.inboxRouting ?? inboxRoutingFor("agents"))
: { ...inboxRoutingFor(input.inbox), ...input.inboxRouting };

export const InboxChoiceParameter = InboxChoice.annotate({
description:
"Sidebar inbox for the new thread. Default 'agents'. Pick 'kameron' or 'jeff' only when that founder asked for it or must act on it (your thread's `inbox.owner` in t3_thread_read); 'shared' for both. `inboxRouting` adjusts fields of the chosen inbox.",
});
export const compositeThreadKey = (environmentId: string, threadId: string) =>
JSON.stringify([environmentId, threadId]);
export const InboxThreadRef = Schema.Struct({ environmentId: EnvironmentId, threadId: ThreadId });
Expand Down
Loading