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
1 change: 1 addition & 0 deletions apps/server/src/environment/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const make = Effect.gen(function* () {
...(desktopAppUpdate ? { desktopAppUpdate: true, desktopAppChannelSwitch: true } : {}),
serverBrowser: true,
peerLinks: true,
threadInbox: true,
mcpModeLimitHeader: true,
linkFence: true,
mcpApprovalCodes: true,
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ function listItemFromShell(
nowMs: number,
): OrchestratorMcpThreadListItem {
return {
...(shell.inbox === undefined ? {} : { inbox: shell.inbox }),
threadId: shell.id,
projectId: shell.projectId,
title: shell.title,
Expand Down Expand Up @@ -913,6 +914,7 @@ function threadDetail(
const latest = ThreadManagementService.latestRun(projection);
const active = ThreadManagementService.latestActiveRun(projection);
return {
...(projection.thread.inbox === undefined ? {} : { inbox: projection.thread.inbox }),
threadId: projection.thread.id,
projectId: projection.thread.projectId,
title: projection.thread.title,
Expand Down Expand Up @@ -2985,6 +2987,12 @@ const make = Effect.gen(function* () {
yield* threadManagement
.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 }),
createdBy: "agent",
creationSource: "mcp",
commandId,
Expand Down
10 changes: 9 additions & 1 deletion apps/server/src/mcp/ThreadMetadataMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ function metadataCommand(input: {
readonly update: ThreadMetadataMcpUpdateInput;
}): Extract<OrchestrationV2Command, { readonly type: "thread.metadata.update" }> {
switch (input.update.action) {
case "route":
return {
type: "thread.metadata.update",
commandId: input.commandId,
threadId: input.threadId,
inboxRouting: input.update.inboxRouting!,
};
case "rename":
return {
type: "thread.metadata.update",
Expand All @@ -88,10 +95,11 @@ function resultFromThread(input: {
readonly sequence: number;
readonly thread: Pick<
OrchestrationV2AppThread,
"id" | "title" | "titleRegeneration" | "linkedPullRequest" | "updatedAt"
"id" | "title" | "titleRegeneration" | "linkedPullRequest" | "updatedAt" | "inbox"
>;
}): ThreadMetadataMcpUpdateResult {
return {
...(input.thread.inbox === undefined ? {} : { inbox: input.thread.inbox }),
threadId: input.thread.id,
action: input.action,
commandId: input.commandId,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/toolkits/orchestrator/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const ThreadReadTool = Tool.make("t3_thread_read", {

const ThreadUpdateTool = Tool.make("t3_thread_update", {
description:
"Rename a thread (`action:'rename'` with `title`) or regenerate its title. Omit `threadId` for this thread. Workspace and branch cannot change here.",
"Route a thread with action:'route' and inboxRouting (owner, assignee, audience, attentionKind), or rename a thread (`action:'rename'` with `title`) or regenerate its title. Omit `threadId` for this thread. Workspace and branch cannot change here.",
// Keeps the input's action/field check, which rebuilding the struct would drop.
parameters: ThreadMetadataMcpUpdateInput.mapFields(
Struct.assign({ environmentId: OrchestratorMcpEnvironmentTarget }),
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/mcp/toolkits/project/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ 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 }),
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,5 +1,6 @@
import { McpAttachmentInput } from "../attachment/input.ts";
import {
ThreadInboxRoutingPatch,
NonNegativeInt,
ModelSelection,
TrimmedNonEmptyString,
Expand Down Expand Up @@ -134,6 +135,7 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", {
"No project: a new Scratch folder. Not with `projectId` or `workspaceStrategy`.",
}),
),
inboxRouting: Schema.optional(ThreadInboxRoutingPatch),
title: TrimmedNonEmptyString,
modelSelection: Schema.optional(ModelSelection),
runtimeMode: Schema.optional(RuntimeMode),
Expand Down
27 changes: 27 additions & 0 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type {
OrchestrationV2SearchThreadResult,
OrchestrationV2ThreadHistoryPage,
} from "@t3tools/contracts";
import { makeThreadInbox, routeThreadInbox } from "@t3tools/contracts";
import { ServerEnvironmentIdentity } from "../environment/ServerEnvironment.ts";
import {
latestExecutedRun,
latestRootProviderFailure,
Expand Down Expand Up @@ -3644,6 +3646,23 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
const now = yield* DateTime.now;
const emitEvent = emit(events, command);
const thread: OrchestrationV2AppThread = {
...(command.inboxOrigin === undefined &&
command.inboxRouting === undefined &&
command.createdBy !== "agent"
? {}
: {
inbox: makeThreadInbox({
actor:
command.inboxOrigin ??
(command.createdBy === "agent" ? { kind: "agent", id: "agent" } : null),
...(command.inboxRouting === undefined ? {} : { routing: command.inboxRouting }),
executorEnvironmentId: yield* Effect.serviceOption(ServerEnvironmentIdentity).pipe(
Effect.flatMap((identity) =>
Option.isSome(identity) ? identity.value.getEnvironmentId : Effect.succeed(null),
),
),
}),
}),
createdBy: command.createdBy,
creationSource: command.creationSource,
id: command.threadId,
Expand Down Expand Up @@ -4672,6 +4691,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
};
return {
...thread,
...(command.inboxRouting === undefined
? {}
: {
inbox: routeThreadInbox(
thread.inbox ?? makeThreadInbox({ actor: null }),
command.inboxRouting,
),
}),
...(command.title === undefined ? {} : { title: command.title }),
...(command.limitRecovery === undefined ? {} : { limitRecovery }),
...(command.limitRecovery !== undefined &&
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ export function threadShellFromProjection(
});
return {
createdBy: projection.thread.createdBy,
...(projection.thread.inbox === undefined ? {} : { inbox: projection.thread.inbox }),
creationSource: projection.thread.creationSource,
id: projection.thread.id,
projectId: projection.thread.projectId,
Expand Down Expand Up @@ -2066,6 +2067,7 @@ function shellFromState(input: {
...(input.state.thread.historyOrigin === undefined
? {}
: { historyOrigin: input.state.thread.historyOrigin }),
...(input.state.thread.inbox === undefined ? {} : { inbox: input.state.thread.inbox }),
...(input.state.thread.linkOrigin === undefined
? {}
: { linkOrigin: input.state.thread.linkOrigin }),
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/orchestration-v2/SubagentProjection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { assert, it } from "@effect/vitest";
import {
makeThreadInbox,
matchesInboxView,
CommandId,
type ModelSelection,
NodeId,
Expand Down Expand Up @@ -85,6 +87,7 @@ function makeParentThread(): OrchestrationV2AppThread {
it("keeps a subagent child awake when its parent thread is snoozed", () => {
const parentThread: OrchestrationV2AppThread = {
...makeParentThread(),
inbox: makeThreadInbox({ actor: { kind: "human", id: "jeff" } }),
titleRegeneration: { requestId: CommandId.make("command:parent-title"), startedAt: snoozedAt },
};
const childProviderThreadId = ProviderThreadId.make("provider-thread:subagent-awake-child");
Expand All @@ -102,6 +105,12 @@ it("keeps a subagent child awake when its parent thread is snoozed", () => {
creationSource: "provider",
});

assert.equal(childThread.inbox?.owner, "jeff");
assert.deepEqual(childThread.inbox?.requestedBy, parentThread.inbox?.requestedBy);
assert.isFalse(matchesInboxView(childThread.inbox, "jeff"));
assert.isFalse(matchesInboxView(childThread.inbox, "kameron"));
assert.isTrue(matchesInboxView(childThread.inbox, "agents"));
assert.isTrue(matchesInboxView(childThread.inbox, "all"));
assert.isNull(childThread.snoozedUntil);
assert.isNull(childThread.snoozedAt);
assert.isNull(childThread.titleRegeneration);
Expand Down
32 changes: 32 additions & 0 deletions apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2903,3 +2903,35 @@ it.effect("replays an accepted send after the project disables the instance", ()
}
}).pipe(Effect.provide(Layer.mergeAll(harness.layer, layerFiles)));
});

it.effect(
"persists founder routing in projections and shells and retains it on launch replay",
() => {
const harness = makeHarness();
return Effect.gen(function* () {
const launches = yield* ThreadLaunch.ThreadLaunchService;
const threads = yield* ThreadManagement.ThreadManagementService;
const input = {
...launchInput({ command: "inbox-launch", thread: "inbox-thread" }),
inboxOrigin: { kind: "human" as const, id: "jeff" as const },
};
const launched = yield* launches.launch(input);
const original = (yield* threads.getThreadProjection(launched.threadId)).thread.inbox;
assert.equal(original?.owner, "jeff");
assert.deepEqual((yield* threads.getThreadShell(launched.threadId))?.inbox, original);
yield* threads.dispatch({
type: "thread.metadata.update",
commandId: CommandId.make("route-inbox"),
threadId: launched.threadId,
inboxRouting: { assignee: { kind: "human", id: "kameron" }, attentionKind: "FYI" },
});
yield* launches.launch(input);
const routed = (yield* threads.getThreadProjection(launched.threadId)).thread.inbox;
assert.equal(routed?.owner, "kameron");
assert.equal(routed?.attentionKind, "FYI");
assert.deepEqual(routed?.origin, original?.origin);
assert.deepEqual(routed?.requestedBy, original?.requestedBy);
assert.deepEqual((yield* threads.getThreadShell(launched.threadId))?.inbox, routed);
}).pipe(Effect.provide(harness.layer));
},
);
6 changes: 6 additions & 0 deletions apps/server/src/orchestration-v2/ThreadLaunchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as TerminalManager from "../terminal/Manager.ts";
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
import {
CommandId,
type InboxActor,
type ThreadInboxRoutingPatch,
type ChatAttachment,
type MessageId,
type ModelSelection,
Expand Down Expand Up @@ -83,6 +85,8 @@ export interface ThreadLaunchInitialMessage {

export interface ThreadLaunchInput {
readonly commandId: CommandId;
readonly inboxOrigin?: InboxActor;
readonly inboxRouting?: ThreadInboxRoutingPatch;
readonly threadId?: ThreadId;
readonly reuseExistingThread?: boolean;
readonly projectId: ProjectId;
Expand Down Expand Up @@ -1142,6 +1146,8 @@ const make = Effect.gen(function* () {
: { delegatedFrom: input.delegatedFrom }),
createdBy: input.createdBy,
creationSource: input.creationSource,
...(input.inboxOrigin === undefined ? {} : { inboxOrigin: input.inboxOrigin }),
...(input.inboxRouting === undefined ? {} : { inboxRouting: input.inboxRouting }),
});
const claimed = yield* claimDispatch.pipe(
Effect.mapError(
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,12 @@ export const layerWsRpc = (
Effect.andThen(
ThreadMessageIntake.launchThread({
commandId: input.commandId,
...(input.inboxOrigin === undefined
? {}
: { inboxOrigin: input.inboxOrigin }),
...(input.inboxRouting === undefined
? {}
: { inboxRouting: input.inboxRouting }),
...(input.threadId === undefined ? {} : { threadId: input.threadId }),
...(input.reuseExistingThread === undefined
? {}
Expand Down
26 changes: 24 additions & 2 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { matchesInboxView } from "@t3tools/contracts";
import { SidebarInboxBar } from "./sidebar/SidebarInboxBar";
import { threadRoutingUpdateFromMenuAction } from "./threadActionMenu.logic";
import { attachSidebarTree } from "../lib/sidebarTree";
import { type EnvironmentId, type ScopedProjectRef } from "@t3tools/contracts";
import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";
Expand Down Expand Up @@ -1118,10 +1121,17 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
);
const threads = useQuietThreadShells();
const promotingDraftThreadKeys = usePromotingDraftThreadKeys();
const inboxView = useClientSettings((settings) => settings.founderInboxView);
const inboxThreads = threads.filter(
(thread) =>
threadSearchQuery.trim().length > 0 ||
matchesInboxView(thread.source.inbox, inboxView) ||
(inboxView === "agents" && thread.source.createdBy === "agent"),
);
const listedThreads =
promotingDraftThreadKeys.length === 0
? threads
: threads.map((thread) =>
? inboxThreads
: inboxThreads.map((thread) =>
promotingDraftThreadKeys.includes(threadShellKey(thread))
? asLaunchingThread(thread)
: thread,
Expand Down Expand Up @@ -2671,6 +2681,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
),
canTurnIntoProject: canTurnThreadIntoProject(threadRef),
supports: {
inboxRouting:
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadInbox ===
true,
settlement: configLoaded,
autoSettleOptOut: supportsAutoSettleOptOut,
snooze: configLoaded,
Expand All @@ -2684,6 +2697,14 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
);
if (clicked._tag === "Failure" || clicked.value === null) return;
if (threadActionRequiresOperate(clicked.value) && !checkThreadOperations([thread])) return;
const inboxRouting = threadRoutingUpdateFromMenuAction(clicked.value);
if (inboxRouting) {
await updateThreadMetadata({
environmentId: thread.environmentId,
input: { threadId: thread.id, inboxRouting },
});
return;
}
if (clicked.value?.startsWith("snooze:")) {
const preset =
clicked.value === "snooze:custom"
Expand Down Expand Up @@ -3208,6 +3229,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
activeSearchResultIndex={activeSearchResultIndex}
onClearSearch={clearThreadSearch}
/>
<SidebarInboxBar />
</SidebarGroup>
}
>
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/components/ThreadNotificationCoordinator.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { matchesInboxView } from "@t3tools/contracts";
import {
type EnvironmentThreadShell,
type PendingSubagentRequest,
Expand Down Expand Up @@ -111,7 +112,15 @@ export function startThreadNotifications(
const live = registry.get(environmentThreadShells.anyEnvironmentHidingAtom)
? new Set(registry.get(environmentThreadShells.threadRefsAtom).map(threadKey))
: null;
const shouldClose = (key: string) => hidden.has(key) || (live !== null && !live.has(key));
const outsideInbox = new Set<string>();
for (const [environmentId, state] of watched) {
for (const [threadId, entry] of state.previous) {
if (!matchesInboxView(entry.thread.source.inbox, getClientSettings().founderInboxView))
outsideInbox.add(threadKey({ environmentId, threadId }));
}
}
const shouldClose = (key: string) =>
outsideInbox.has(key) || hidden.has(key) || (live !== null && !live.has(key));
closeToasts(shouldClose);
const count = pending.size;
for (const [tag, entry] of pending) {
Expand All @@ -133,6 +142,7 @@ export function startThreadNotifications(
kind: ThreadNotificationKind,
) => {
const { thread, status } = state;
if (!matchesInboxView(thread.source.inbox, getClientSettings().founderInboxView)) return;
if (
registry
.get(environmentThreadShells.hiddenThreadKeysAtom)
Expand Down Expand Up @@ -415,6 +425,7 @@ export function startThreadNotifications(
};

const onSettings = () => {
closeHiddenPending();
applyMode();
syncEnvironments();
};
Expand Down
Loading