Queue controls, resume, secret requests and subagent stop, as in T3 Code

Queued messages show above the composer (Q to go through them: send now,
edit in the composer, remove; alt+up edits the last). An empty enter after
an interrupt continues where the run left off and releases held messages.
Secret requests get a masked field that never touches the message box.
Running subagents the web can stop get a palette command. Adds the
diagnostics:read and providers:manage scopes for usage limits.
This commit is contained in:
Callum Alpass committed 2026-11-02 20:36:39 +11:00
1 parent 43347d1d58
commit a8e35ee83a
12 files changed
+518 -9

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import type { OrchestrationV2ThreadProjection, RunId } from "@t3tools/contracts";
import { secretRequestDisplay, type SecretRequestItem } from "@t3tools/client-runtime/secret-request";
import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows";
import { deriveThreadStructureRuntime } from "@t3tools/client-runtime/state/thread-execution";
import { latestExecutedRun, latestRootProviderFailure } from "@t3tools/shared/orchestrationV2ThreadError";
export interface QueuedMessage {
readonly runId: RunId;
readonly text: string;
/** A guest's message keeps the guest's words: it can be removed, not rewritten. */
readonly editable: boolean;
}
/** What the composer's queue controls need, derived as the web's chat view derives it. */
export interface QueueState {
readonly queued: readonly QueuedMessage[];
readonly activeRunId: RunId | null;
/** "Send now" starts a turn with the message when idle, or steers it into the running one. */
readonly canSendNow: boolean;
readonly canPromoteToSteer: boolean;
/** An interrupted run (or one stopped by a usage limit) the web offers to continue. */
readonly resumableRunId: RunId | null;
/** Queued turns held back by an interrupt, released by resuming. */
readonly held: boolean;
}
export function queueState(projection: OrchestrationV2ThreadProjection): QueueState {
const workflow = deriveThreadQueueWorkflowState(projection);
return {
queued: workflow.queuedRuns.map(({ run, text, context }) => ({ runId: run.id, text, editable: context?.guest === undefined })),
activeRunId: workflow.activeRun?.id ?? null,
canSendNow: workflow.canSendNow,
canPromoteToSteer: workflow.canPromoteToSteer,
resumableRunId: resumableRunId(projection),
held: workflow.isHeld,
};
}
function resumableRunId(projection: OrchestrationV2ThreadProjection): RunId | null {
const run = latestExecutedRun(projection.runs);
if (run?.status === "interrupted") return run.id;
return run?.status === "failed" &&
deriveThreadStructureRuntime(projection)?.lastErrorClass === "usage_limit" &&
latestRootProviderFailure(run, projection.turnItems)?.class === "usage_limit"
? run.id
: null;
}
/** The oldest secret request this thread can answer: one asked here, not inherited from a fork. */
export function pendingSecretRequest(projection: OrchestrationV2ThreadProjection): SecretRequestItem | null {
for (const projected of projection.visibleTurnItems) {
const item = projected.item;
if (item.type === "secret_request" && secretRequestDisplay(item, projected.visibility).kind === "pending") return item;
}
return null;
}
+14
View File
@@ -0,0 +1,14 @@
import type { OrchestrationV2Subagent } from "@t3tools/contracts";
const LIVE = ["pending", "running", "waiting"];
/**
* Whether a subagent can be stopped from its parent, as the web's lineage panel decides: app-owned
* tasks always, Claude's native ones only with a strong task reference to aim the stop at.
*/
export function canStopSubagent(agent: OrchestrationV2Subagent): boolean {
const reachable =
agent.origin === "app_owned" ||
(agent.origin === "provider_native" && agent.driver === "claudeAgent" && agent.runId != null && agent.nativeTaskRef?.strength === "strong" && agent.nativeTaskRef.nativeId !== null);
return reachable && agent.startedAt != null && LIVE.includes(agent.status);
}
+5
View File
@@ -1,4 +1,5 @@
import type { OrchestrationV2TurnItem, RuntimeRequestId } from "@t3tools/contracts";
import { secretRequestDisplay } from "@t3tools/client-runtime/secret-request";
/** A turn item as one line or card: the fallback for timeline event rows the web app renders specially. */
export type Block =
@@ -76,6 +77,10 @@ export function blockFor(item: OrchestrationV2TurnItem, pending: ReadonlySet<str
return { kind: "notice", id, text: item.summary, tone: item.outcome === "failed" ? "bad" : item.outcome === "completed" ? "good" : "muted" };
case "compaction":
return { kind: "notice", id, text: "context compacted", tone: "muted" };
case "secret_request": {
const display = secretRequestDisplay(item, "local");
return { kind: "notice", id, text: `🔒 ${item.label} · ${display.kind === "answered" ? display.label : "waiting for your answer"}`, tone: display.kind === "answered" ? "muted" : "warn" };
}
case "handoff":
return { kind: "notice", id, text: `handed off${item.toModel ? ` to ${item.toModel}` : ""}`, tone: "muted" };
case "checkpoint":