feat(threads): add agent-requested handoffs #7487
Closedmrmg(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/7487/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -0,0 +20,21 @@20+ <p className="truncate text-xs text-muted-foreground">21+ {handoff.artifactReferences.join(" · ")}22+ </p>23+ ) : null}24+ </div>25+ <button26+ type="button"27+ disabled={busy}28+ onClick={onOpen}29+ className="rounded-md bg-primary px-2.5 py-1.5 font-medium text-primary-foreground disabled:opacity-50"30+ >31+ Open {handoff.title} thread32+ </button>33+ <button34+ type="button"35+ disabled={busy}36+ onClick={onDismiss}37+ className="rounded-md px-2.5 py-1.5 text-muted-foreground hover:bg-muted disabled:opacity-50"38+ >39+ Dismiss40+ </button>
- @@ -0,0 +1,20 @@1+import { ThreadHandoffId, TrimmedNonEmptyString } from "@t3tools/contracts";2+import * as Crypto from "effect/Crypto";3+import * as Effect from "effect/Effect";4+import * as Schema from "effect/Schema";5+import { Tool, Toolkit } from "effect/unstable/ai";6+7+import * as McpInvocationContext from "../../McpInvocationContext.ts";8+import { OrchestrationEngineService } from "../../../orchestration/Services/OrchestrationEngine.ts";9+10+export const RequestThreadHandoffInput = Schema.Struct({11+ title: TrimmedNonEmptyString,12+ prompt: TrimmedNonEmptyString,13+ artifactReferences: Schema.Array(TrimmedNonEmptyString).pipe(14+ Schema.withDecodingDefault(Effect.succeed([])),15+ ),16+});17+18+export const ThreadHandoffToolFailure = Schema.Struct({19+ message: Schema.String,20+});@@ -0,0 +1,8 @@1+import { ThreadHandoffId, TrimmedNonEmptyString } from "@t3tools/contracts";2+import * as Crypto from "effect/Crypto";3+import * as Effect from "effect/Effect";4+import * as Schema from "effect/Schema";5+import { Tool, Toolkit } from "effect/unstable/ai";6+7+import * as McpInvocationContext from "../../McpInvocationContext.ts";8+import { OrchestrationEngineService } from "../../../orchestration/Services/OrchestrationEngine.ts";@@ -0,0 +18,21 @@18+ const createdAt = yield* DateTime.now.pipe(Effect.map(DateTime.formatIso));19+ yield* orchestrationEngine.dispatch({20+ type: "thread.handoff.request",21+ commandId: CommandId.make(requestId),22+ threadId: invocation.threadId,23+ handoffId: ThreadHandoffId.make(handoffId),24+ title: input.title,25+ prompt: input.prompt,26+ artifactReferences: input.artifactReferences,27+ createdAt,28+ });29+ return { handoffId: ThreadHandoffId.make(handoffId) };30+ },31+);32+33+export const ThreadHandoffToolkitHandlersLive = ThreadHandoffToolkit.toLayer({34+ request_thread_handoff: (input) =>35+ requestThreadHandoff(input).pipe(36+ Effect.mapError((error) => ({37+ message: error instanceof Error ? error.message : "Unable to request a thread handoff.",38+ })),
- @@ -5740,16 +5763,10 @@5740- titleSeed: nextThreadTitle,5741- runtimeMode,5742- interactionMode: "default",5743- sourceProposedPlan: {5744- threadId: activeThread.id,5745- planId: activeProposedPlan.id,5746- },5747- createdAt,5763+ threadId: activeThread.id,5764+ handoffId,5765+ targetThreadId: nextThreadId,57485766 },57495767 });5750- failure = startResult._tag === "Failure" ? startResult : null;5768+ failure = acceptResult._tag === "Failure" ? acceptResult : null;57515769 }5752577057535771 if (failure === null) {5754- const startedResult = await settlePromise(() =>5755- waitForStartedServerThread(scopeThreadRef(activeThread.environmentId, nextThreadId)),5772+ seedHandoffPrompt(@@ -5716,14 +5748,13 @@57165748 title: nextThreadTitle,5717- modelSelection: nextThreadModelSelection,5718- runtimeMode,5719- interactionMode: "default",5720- branch: activeThreadBranch,5721- worktreePath: activeThread.worktreePath,5722- createdAt,5749+ prompt: outgoingImplementationPrompt,5750+ artifactReferences: [],5751+ ...(activeProposedPlan.turnId5752+ ? { requestingTurnId: activeProposedPlan.turnId, availableImmediately: true as const }5753+ : {}),57235754 },57245755 });57255756 let failure: AtomCommandResult<unknown, unknown> | null =5726- createResult._tag === "Failure" ? createResult : null;5757+ requestResult._tag === "Failure" ? requestResult : null;5727575857285759 if (failure === null) {5729- const startResult = await startThreadTurn({5760+ const acceptResult = await acceptThreadHandoff({@@ -5716,14 +5748,13 @@57165748 title: nextThreadTitle,5717- modelSelection: nextThreadModelSelection,5718- runtimeMode,5719- interactionMode: "default",5720- branch: activeThreadBranch,5721- worktreePath: activeThread.worktreePath,5722- createdAt,5749+ prompt: outgoingImplementationPrompt,5750+ artifactReferences: [],5751+ ...(activeProposedPlan.turnId5752+ ? { requestingTurnId: activeProposedPlan.turnId, availableImmediately: true as const }5753+ : {}),57235754 },57245755 });57255756 let failure: AtomCommandResult<unknown, unknown> | null =5726- createResult._tag === "Failure" ? createResult : null;5757+ requestResult._tag === "Failure" ? requestResult : null;5727575857285759 if (failure === null) {5729- const startResult = await startThreadTurn({5760+ const acceptResult = await acceptThreadHandoff({@@ -0,0 +1,18 @@1+import type { ThreadHandoff } from "@t3tools/contracts";2+import { Pressable, View } from "react-native";3+4+import { AppText as Text } from "../../components/AppText";5+import { presentThreadHandoff } from "./thread-handoff-presentation";6+7+export function ThreadHandoffCard(props: {8+ readonly handoff: ThreadHandoff;9+ readonly busy?: boolean;10+ readonly onOpen: () => void;11+ readonly onDismiss: () => void;12+}) {13+ const { handoff, busy = false, onOpen, onDismiss } = props;14+ const presentation = presentThreadHandoff(handoff);15+ return (16+ <View17+ accessibilityLabel={presentation.accessibilityLabel}18+ className="absolute left-3 right-3 top-2 z-20 rounded-2xl border border-border bg-surface px-3 py-2 shadow-sm"@@ -1162,3 +1231,10 @@11621231 };11631232 }116412331234+ case "thread.handoff.request": {1235+ const thread = yield* requireThreadNotArchived({1236+ readModel,1237+ command,1238+ threadId: command.threadId,1239+ });1240+ const requestingTurnId = command.requestingTurnId ?? thread.session?.activeTurnId;@@ -496,3 +519,6 @@496519 },497520 });498521 }, [interruptThreadTurn, selectedThread]);522+ const handleOpenHandoff = useCallback(523+ async (handoff: ReturnType<typeof findThreadHandoffs>[number]) => {524+ if (!selectedThread || handoffActionId !== null) {
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
88d6270c-7c6d-449c-9fd7-cedc140b0160You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share