Normalize approval request kinds and persist draft provider state
- map canonical approval request types to `requestKind` across ingestion and web pending approvals - auto-approve Cursor permission requests when approval policy is `never` - persist per-thread composer provider selection in draft store and use it in ChatView - disable Cursor traits picker while model selection is locked
This commit is contained in:
1 parent
d096cb85e1
commit
78e6125cfe
9 files changed
+412
-73
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ProviderRuntimeEvent } from "@t3tools/contracts";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
CommandId,
|
||||
EventId,
|
||||
MessageId,
|
||||
@@ -804,6 +805,64 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
expect(completionEvents).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("maps canonical request events into approval activities with requestKind", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
harness.emit({
|
||||
type: "request.opened",
|
||||
eventId: asEventId("evt-request-opened"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-open"),
|
||||
payload: {
|
||||
requestType: "command_execution_approval",
|
||||
detail: "pwd",
|
||||
},
|
||||
});
|
||||
|
||||
harness.emit({
|
||||
type: "request.resolved",
|
||||
eventId: asEventId("evt-request-resolved"),
|
||||
provider: "codex",
|
||||
sessionId: asSessionId("sess-1"),
|
||||
createdAt: now,
|
||||
requestId: ApprovalRequestId.makeUnsafe("req-open"),
|
||||
payload: {
|
||||
requestType: "command_execution_approval",
|
||||
decision: "accept",
|
||||
},
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
(entry) =>
|
||||
entry.activities.some((activity) => activity.kind === "approval.requested") &&
|
||||
entry.activities.some((activity) => activity.kind === "approval.resolved"),
|
||||
);
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.makeUnsafe("thread-1"));
|
||||
expect(thread).toBeDefined();
|
||||
|
||||
const requested = thread?.activities.find((activity) => activity.id === "evt-request-opened");
|
||||
const requestedPayload =
|
||||
requested?.payload && typeof requested.payload === "object"
|
||||
? (requested.payload as Record<string, unknown>)
|
||||
: undefined;
|
||||
expect(requestedPayload?.requestKind).toBe("command");
|
||||
expect(requestedPayload?.requestType).toBe("command_execution_approval");
|
||||
|
||||
const resolved = thread?.activities.find((activity) => activity.id === "evt-request-resolved");
|
||||
const resolvedPayload =
|
||||
resolved?.payload && typeof resolved.payload === "object"
|
||||
? (resolved.payload as Record<string, unknown>)
|
||||
: undefined;
|
||||
expect(resolvedPayload?.requestKind).toBe("command");
|
||||
expect(resolvedPayload?.requestType).toBe("command_execution_approval");
|
||||
});
|
||||
|
||||
it("maps runtime.error into errored session state", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@@ -133,6 +133,21 @@ function runtimeErrorMessageFromEvent(event: ProviderRuntimeEvent): string | und
|
||||
return payloadMessage ?? legacyMessage;
|
||||
}
|
||||
|
||||
function requestKindFromCanonicalRequestType(
|
||||
requestType: string | undefined,
|
||||
): "command" | "file-change" | undefined {
|
||||
switch (requestType) {
|
||||
case "command_execution_approval":
|
||||
case "exec_command_approval":
|
||||
return "command";
|
||||
case "file_change_approval":
|
||||
case "apply_patch_approval":
|
||||
return "file-change";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function isToolLifecycleItemType(itemType: string): boolean {
|
||||
return (
|
||||
itemType === "command_execution" ||
|
||||
@@ -151,6 +166,7 @@ function runtimeEventToActivities(
|
||||
const maybeSequence = event.sessionSequence !== undefined ? { sequence: event.sessionSequence } : {};
|
||||
switch (event.type) {
|
||||
case "request.opened": {
|
||||
const requestKind = requestKindFromCanonicalRequestType(event.payload.requestType);
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -158,13 +174,14 @@ function runtimeEventToActivities(
|
||||
tone: "approval",
|
||||
kind: "approval.requested",
|
||||
summary:
|
||||
event.payload.requestType === "command_execution_approval"
|
||||
requestKind === "command"
|
||||
? "Command approval requested"
|
||||
: event.payload.requestType === "file_change_approval"
|
||||
: requestKind === "file-change"
|
||||
? "File-change approval requested"
|
||||
: "Approval requested",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
...(requestKind ? { requestKind } : {}),
|
||||
requestType: event.payload.requestType,
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
},
|
||||
@@ -175,6 +192,7 @@ function runtimeEventToActivities(
|
||||
}
|
||||
|
||||
case "request.resolved": {
|
||||
const requestKind = requestKindFromCanonicalRequestType(event.payload.requestType);
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -184,6 +202,7 @@ function runtimeEventToActivities(
|
||||
summary: "Approval resolved",
|
||||
payload: {
|
||||
requestId: event.requestId,
|
||||
...(requestKind ? { requestKind } : {}),
|
||||
requestType: event.payload.requestType,
|
||||
...(event.payload.decision ? { decision: event.payload.decision } : {}),
|
||||
},
|
||||
|
||||
@@ -406,4 +406,39 @@ describe("CursorAdapterLive", () => {
|
||||
assert.equal(fake.lastPermissionSelection, "allow-always");
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("auto-approves cursor permission requests when approval policy is never", () => {
|
||||
const fake = new FakeCursorAcpProcess();
|
||||
const layer = makeCursorAdapterLive({
|
||||
createProcess: () => fake as never,
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
|
||||
yield* adapter.startSession({
|
||||
provider: "cursor",
|
||||
approvalPolicy: "never",
|
||||
});
|
||||
|
||||
// consume startup events
|
||||
yield* Stream.take(adapter.streamEvents, 6).pipe(Stream.runDrain);
|
||||
|
||||
fake.emitPermissionRequest();
|
||||
|
||||
const resolved = yield* Stream.runHead(adapter.streamEvents);
|
||||
assert.equal(resolved._tag, "Some");
|
||||
if (resolved._tag !== "Some") {
|
||||
return;
|
||||
}
|
||||
|
||||
assert.equal(resolved.value.type, "request.resolved");
|
||||
if (resolved.value.type !== "request.resolved") {
|
||||
return;
|
||||
}
|
||||
|
||||
assert.equal(resolved.value.payload.decision, "acceptForSession");
|
||||
assert.equal(fake.lastPermissionSelection, "allow-always");
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
EventId,
|
||||
type CanonicalItemType,
|
||||
type CanonicalRequestType,
|
||||
type ProviderApprovalPolicy,
|
||||
ProviderSessionId,
|
||||
type ProviderRuntimeEvent,
|
||||
type ProviderSession,
|
||||
@@ -73,6 +74,7 @@ interface CursorTurnState {
|
||||
|
||||
interface CursorSessionContext {
|
||||
session: ProviderSession;
|
||||
approvalPolicy: ProviderApprovalPolicy;
|
||||
readonly child: ChildProcessWithoutNullStreams;
|
||||
readonly output: readline.Interface;
|
||||
readonly pending: Map<string, PendingRequest>;
|
||||
@@ -185,6 +187,43 @@ function normalizeRequestType(toolCall: unknown): CanonicalRequestType {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
function selectCursorPermissionOption(
|
||||
options: ReadonlyArray<{ optionId: string }>,
|
||||
decision: "acceptForSession" | "accept" | "decline" | "cancel",
|
||||
): string | undefined {
|
||||
const allowAlways = options.find((option) => option.optionId === "allow-always");
|
||||
const allowOnce = options.find((option) => option.optionId === "allow-once");
|
||||
const rejectOnce = options.find((option) => option.optionId === "reject-once");
|
||||
|
||||
if (decision === "acceptForSession") {
|
||||
return allowAlways?.optionId ?? allowOnce?.optionId;
|
||||
}
|
||||
if (decision === "accept") {
|
||||
return allowOnce?.optionId ?? allowAlways?.optionId;
|
||||
}
|
||||
return rejectOnce?.optionId ?? options[0]?.optionId;
|
||||
}
|
||||
|
||||
function selectCursorAutoApprovalOption(
|
||||
options: ReadonlyArray<{ optionId: string }>,
|
||||
): { optionId: string; decision: "acceptForSession" | "accept" } | undefined {
|
||||
const allowAlways = options.find((option) => option.optionId === "allow-always");
|
||||
if (allowAlways) {
|
||||
return {
|
||||
optionId: allowAlways.optionId,
|
||||
decision: "acceptForSession",
|
||||
};
|
||||
}
|
||||
const allowOnce = options.find((option) => option.optionId === "allow-once");
|
||||
if (allowOnce) {
|
||||
return {
|
||||
optionId: allowOnce.optionId,
|
||||
decision: "accept",
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function titleForItemType(itemType: CanonicalItemType): string {
|
||||
switch (itemType) {
|
||||
case "command_execution":
|
||||
@@ -459,14 +498,79 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
return Effect.gen(function* () {
|
||||
const requestId = ApprovalRequestId.makeUnsafe(randomUUID());
|
||||
const requestType = normalizeRequestType(decoded.params.toolCall);
|
||||
const options = decoded.params.options.map((entry) => ({ optionId: entry.optionId }));
|
||||
const detail = asString(asObject(decoded.params.toolCall)?.title);
|
||||
|
||||
if (context.approvalPolicy === "never") {
|
||||
const selection =
|
||||
selectCursorAutoApprovalOption(options) ??
|
||||
(options[0]
|
||||
? {
|
||||
optionId: options[0].optionId,
|
||||
decision: "accept",
|
||||
}
|
||||
: undefined);
|
||||
if (!selection) {
|
||||
return yield* emitRuntimeWarning(
|
||||
context,
|
||||
"Cursor ACP permission request contained no selectable options.",
|
||||
decoded.params,
|
||||
);
|
||||
}
|
||||
|
||||
writeCursorMessage(context, {
|
||||
jsonrpc: "2.0",
|
||||
id: decoded.id,
|
||||
result: {
|
||||
outcome: {
|
||||
outcome: "selected",
|
||||
optionId: selection.optionId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const stamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "request.resolved",
|
||||
eventId: stamp.eventId,
|
||||
provider: PROVIDER,
|
||||
sessionId: context.session.sessionId,
|
||||
createdAt: stamp.createdAt,
|
||||
...(context.session.threadId ? { threadId: context.session.threadId } : {}),
|
||||
...(context.turnState ? { turnId: context.turnState.turnId } : {}),
|
||||
requestId,
|
||||
payload: {
|
||||
requestType,
|
||||
decision: selection.decision,
|
||||
resolution: {
|
||||
optionId: selection.optionId,
|
||||
autoApproved: true,
|
||||
},
|
||||
},
|
||||
providerRefs: {
|
||||
providerSessionId: context.session.sessionId,
|
||||
...(context.session.threadId ? { providerThreadId: context.session.threadId } : {}),
|
||||
...(context.turnState ? { providerTurnId: context.turnState.turnId } : {}),
|
||||
providerRequestId: String(decoded.id),
|
||||
},
|
||||
raw: {
|
||||
source: "cursor.acp.response",
|
||||
method: "session/request_permission",
|
||||
payload: {
|
||||
optionId: selection.optionId,
|
||||
autoApproved: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
context.pendingPermissions.set(requestId, {
|
||||
jsonRpcId: decoded.id,
|
||||
requestType,
|
||||
options: decoded.params.options.map((entry) => ({ optionId: entry.optionId })),
|
||||
options,
|
||||
});
|
||||
|
||||
const detail = asString(asObject(decoded.params.toolCall)?.title);
|
||||
const stamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "request.opened",
|
||||
@@ -891,6 +995,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
|
||||
const context: CursorSessionContext = {
|
||||
session,
|
||||
approvalPolicy: input.approvalPolicy ?? "on-request",
|
||||
child,
|
||||
output,
|
||||
pending: new Map(),
|
||||
@@ -1323,16 +1428,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
const allowAlways = pending.options.find((option) => option.optionId === "allow-always");
|
||||
const allowOnce = pending.options.find((option) => option.optionId === "allow-once");
|
||||
const rejectOnce = pending.options.find((option) => option.optionId === "reject-once");
|
||||
|
||||
const optionId =
|
||||
decision === "acceptForSession"
|
||||
? allowAlways?.optionId ?? allowOnce?.optionId
|
||||
: decision === "accept"
|
||||
? allowOnce?.optionId ?? allowAlways?.optionId
|
||||
: rejectOnce?.optionId ?? pending.options[0]?.optionId;
|
||||
const optionId = selectCursorPermissionOption(pending.options, decision);
|
||||
|
||||
if (!optionId) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
@@ -1376,7 +1472,7 @@ function makeCursorAdapter(options?: CursorAdapterLiveOptions) {
|
||||
providerSessionId: context.session.sessionId,
|
||||
...(context.session.threadId ? { providerThreadId: context.session.threadId } : {}),
|
||||
...(context.turnState ? { providerTurnId: context.turnState.turnId } : {}),
|
||||
providerRequestId: requestId,
|
||||
providerRequestId: String(pending.jsonRpcId),
|
||||
},
|
||||
raw: {
|
||||
source: "cursor.acp.response",
|
||||
|
||||
@@ -520,6 +520,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const composerImages = composerDraft.images;
|
||||
const nonPersistedComposerImageIds = composerDraft.nonPersistedImageIds;
|
||||
const setComposerDraftPrompt = useComposerDraftStore((store) => store.setPrompt);
|
||||
const setComposerDraftProvider = useComposerDraftStore((store) => store.setProvider);
|
||||
const setComposerDraftModel = useComposerDraftStore((store) => store.setModel);
|
||||
const setComposerDraftEffort = useComposerDraftStore((store) => store.setEffort);
|
||||
const addComposerDraftImage = useComposerDraftStore((store) => store.addImage);
|
||||
@@ -549,12 +550,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const [sendPhase, setSendPhase] = useState<SendPhase>("idle");
|
||||
const [isConnecting, _setIsConnecting] = useState(false);
|
||||
const [isRevertingCheckpoint, setIsRevertingCheckpoint] = useState(false);
|
||||
const [selectedProviderByThread, setSelectedProviderByThread] = useState<
|
||||
Partial<Record<ThreadId, ProviderKind>>
|
||||
>({});
|
||||
const [selectedModelByThread, setSelectedModelByThread] = useState<
|
||||
Partial<Record<ThreadId, ModelSlug>>
|
||||
>({});
|
||||
const [isSwitchingRuntimeMode, setIsSwitchingRuntimeMode] = useState(false);
|
||||
const [respondingRequestIds, setRespondingRequestIds] = useState<ApprovalRequestId[]>([]);
|
||||
const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>({});
|
||||
@@ -679,9 +674,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
]);
|
||||
|
||||
const sessionProvider = activeThread?.session?.provider ?? null;
|
||||
const selectedProviderByThreadId = activeThread?.id
|
||||
? selectedProviderByThread[activeThread.id]
|
||||
: undefined;
|
||||
const selectedProviderByThreadId = composerDraft.provider;
|
||||
const hasThreadStarted = Boolean(
|
||||
activeThread &&
|
||||
(activeThread.latestTurn !== null || activeThread.messages.length > 0 || activeThread.session !== null),
|
||||
@@ -696,11 +689,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
: null;
|
||||
const baseThreadModel = resolveModelSlugForProvider(
|
||||
selectedProvider,
|
||||
(activeThread?.id ? selectedModelByThread[activeThread.id] : undefined) ??
|
||||
activeThread?.model ??
|
||||
activeProject?.model ??
|
||||
getDefaultModel(selectedProvider) ??
|
||||
DEFAULT_MODEL,
|
||||
activeThread?.model ?? activeProject?.model ?? getDefaultModel(selectedProvider) ?? DEFAULT_MODEL,
|
||||
);
|
||||
const selectedModel = resolveModelSlugForProvider(selectedProvider, composerDraft.model ?? baseThreadModel);
|
||||
const selectedEffort = composerDraft.effort ?? getDefaultReasoningEffort(selectedProvider);
|
||||
@@ -741,29 +730,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
),
|
||||
[lockedProvider],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (!activeThread?.id || !sessionProvider) return;
|
||||
setSelectedProviderByThread((existing) => {
|
||||
if (existing[activeThread.id] === sessionProvider) return existing;
|
||||
return { ...existing, [activeThread.id]: sessionProvider };
|
||||
});
|
||||
}, [activeThread?.id, sessionProvider]);
|
||||
useEffect(() => {
|
||||
if (!activeThread?.id) return;
|
||||
setSelectedModelByThread((existing) => {
|
||||
if (existing[activeThread.id]) return existing;
|
||||
return {
|
||||
...existing,
|
||||
[activeThread.id]: resolveModelSlugForProvider(
|
||||
selectedProvider,
|
||||
activeThread.model ??
|
||||
activeProject?.model ??
|
||||
getDefaultModel(selectedProvider) ??
|
||||
DEFAULT_MODEL,
|
||||
),
|
||||
};
|
||||
});
|
||||
}, [activeProject?.model, activeThread?.id, activeThread?.model, selectedProvider]);
|
||||
const phase = derivePhase(activeThread?.session ?? null);
|
||||
const isSendBusy = sendPhase !== "idle";
|
||||
const isPreparingWorktree = sendPhase === "preparing-worktree";
|
||||
@@ -2348,14 +2314,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
provider === "cursor"
|
||||
? resolveCursorModelFromSelection(parseCursorModelSelection(model))
|
||||
: resolveModelSlugForProvider(provider, model);
|
||||
setSelectedProviderByThread((existing) => ({
|
||||
...existing,
|
||||
[activeThread.id]: provider,
|
||||
}));
|
||||
setSelectedModelByThread((existing) => ({
|
||||
...existing,
|
||||
[activeThread.id]: resolvedModel,
|
||||
}));
|
||||
setComposerDraftProvider(activeThread.id, provider);
|
||||
setComposerDraftModel(activeThread.id, resolvedModel);
|
||||
if (api && isServerThread) {
|
||||
void api.orchestration.dispatchCommand({
|
||||
type: "thread.meta.update",
|
||||
@@ -2372,6 +2332,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
isServerThread,
|
||||
lockedProvider,
|
||||
scheduleComposerFocus,
|
||||
setComposerDraftModel,
|
||||
setComposerDraftProvider,
|
||||
],
|
||||
);
|
||||
const onCursorReasoningSelect = useCallback(
|
||||
@@ -2888,13 +2850,37 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
)}
|
||||
|
||||
{selectedCursorModel && selectedCursorModelCapabilities && hasSelectedCursorTraits && (
|
||||
<CursorTraitsPicker
|
||||
selection={selectedCursorModel}
|
||||
capabilities={selectedCursorModelCapabilities}
|
||||
onReasoningChange={onCursorReasoningSelect}
|
||||
onFastModeChange={onCursorFastModeChange}
|
||||
onThinkingModeChange={onCursorThinkingModeChange}
|
||||
/>
|
||||
<>
|
||||
{cursorModelSelectionLockedReason ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span className="inline-flex">
|
||||
<CursorTraitsPicker
|
||||
selection={selectedCursorModel}
|
||||
capabilities={selectedCursorModelCapabilities}
|
||||
disabled
|
||||
onReasoningChange={onCursorReasoningSelect}
|
||||
onFastModeChange={onCursorFastModeChange}
|
||||
onThinkingModeChange={onCursorThinkingModeChange}
|
||||
/>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="top" className="max-w-72 whitespace-normal leading-tight">
|
||||
{cursorModelSelectionLockedReason}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<CursorTraitsPicker
|
||||
selection={selectedCursorModel}
|
||||
capabilities={selectedCursorModelCapabilities}
|
||||
onReasoningChange={onCursorReasoningSelect}
|
||||
onFastModeChange={onCursorFastModeChange}
|
||||
onThinkingModeChange={onCursorThinkingModeChange}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : supportsReasoningEffort ? (
|
||||
@@ -4238,10 +4224,12 @@ const ReasoningEffortPicker = memo(function ReasoningEffortPicker(props: {
|
||||
const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
selection: ReturnType<typeof parseCursorModelSelection>;
|
||||
capabilities: ReturnType<typeof getCursorModelCapabilities>;
|
||||
disabled?: boolean;
|
||||
onReasoningChange: (reasoning: CursorReasoningOption) => void;
|
||||
onFastModeChange: (enabled: boolean) => void;
|
||||
onThinkingModeChange: (enabled: boolean) => void;
|
||||
}) {
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
const reasoningLabelByOption: Record<CursorReasoningOption, string> = {
|
||||
low: "Low",
|
||||
normal: "Normal",
|
||||
@@ -4258,9 +4246,25 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
const triggerLabel = traitSummary.length > 0 ? traitSummary.join(" · ") : "Traits";
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<Menu
|
||||
open={isMenuOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (props.disabled) {
|
||||
setIsMenuOpen(false);
|
||||
return;
|
||||
}
|
||||
setIsMenuOpen(open);
|
||||
}}
|
||||
>
|
||||
<MenuTrigger
|
||||
render={<Button size="sm" variant="ghost" className="shrink-0 whitespace-nowrap px-2 sm:px-3" />}
|
||||
render={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 whitespace-nowrap px-2 sm:px-3"
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<span>{triggerLabel}</span>
|
||||
<ChevronDownIcon aria-hidden="true" className="size-3 opacity-60" />
|
||||
@@ -4272,6 +4276,7 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
<MenuRadioGroup
|
||||
value={props.selection.reasoning}
|
||||
onValueChange={(value) => {
|
||||
if (props.disabled) return;
|
||||
if (!value) return;
|
||||
const nextReasoning = CURSOR_REASONING_OPTIONS.find((option) => option === value);
|
||||
if (!nextReasoning) return;
|
||||
@@ -4294,7 +4299,10 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">Fast Mode</div>
|
||||
<MenuRadioGroup
|
||||
value={props.selection.fast ? "on" : "off"}
|
||||
onValueChange={(value) => props.onFastModeChange(value === "on")}
|
||||
onValueChange={(value) => {
|
||||
if (props.disabled) return;
|
||||
props.onFastModeChange(value === "on");
|
||||
}}
|
||||
>
|
||||
<MenuRadioItem value="off">off</MenuRadioItem>
|
||||
<MenuRadioItem value="on">on</MenuRadioItem>
|
||||
@@ -4307,7 +4315,10 @@ const CursorTraitsPicker = memo(function CursorTraitsPicker(props: {
|
||||
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">Thinking</div>
|
||||
<MenuRadioGroup
|
||||
value={props.selection.thinking ? "on" : "off"}
|
||||
onValueChange={(value) => props.onThinkingModeChange(value === "on")}
|
||||
onValueChange={(value) => {
|
||||
if (props.disabled) return;
|
||||
props.onThinkingModeChange(value === "on");
|
||||
}}
|
||||
>
|
||||
<MenuRadioItem value="off">off</MenuRadioItem>
|
||||
<MenuRadioItem value="on">on</MenuRadioItem>
|
||||
|
||||
@@ -348,3 +348,32 @@ describe("composerDraftStore setModel", () => {
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.model).toBe("gpt-5.3-codex");
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore setProvider", () => {
|
||||
const threadId = ThreadId.makeUnsafe("thread-provider");
|
||||
|
||||
beforeEach(() => {
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
});
|
||||
});
|
||||
|
||||
it("persists provider-only selection even when prompt/model are empty", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProvider(threadId, "cursor");
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]?.provider).toBe("cursor");
|
||||
});
|
||||
|
||||
it("removes empty provider-only draft when provider is reset", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProvider(threadId, "cursor");
|
||||
store.setProvider(threadId, null);
|
||||
|
||||
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ThreadId,
|
||||
normalizeModelSlug,
|
||||
type CodexReasoningEffort,
|
||||
type ProviderKind,
|
||||
} from "@t3tools/contracts";
|
||||
import type { ChatImageAttachment } from "./types";
|
||||
import { create } from "zustand";
|
||||
@@ -29,6 +30,7 @@ export interface ComposerImageAttachment extends Omit<ChatImageAttachment, "prev
|
||||
interface PersistedComposerThreadDraftState {
|
||||
prompt: string;
|
||||
attachments: PersistedComposerImageAttachment[];
|
||||
provider?: ProviderKind | null;
|
||||
model?: string | null;
|
||||
effort?: CodexReasoningEffort | null;
|
||||
}
|
||||
@@ -52,6 +54,7 @@ interface ComposerThreadDraftState {
|
||||
images: ComposerImageAttachment[];
|
||||
nonPersistedImageIds: string[];
|
||||
persistedAttachments: PersistedComposerImageAttachment[];
|
||||
provider: ProviderKind | null;
|
||||
model: string | null;
|
||||
effort: CodexReasoningEffort | null;
|
||||
}
|
||||
@@ -98,6 +101,7 @@ interface ComposerDraftStoreState {
|
||||
clearProjectDraftThreadById: (projectId: ProjectId, threadId: ThreadId) => void;
|
||||
clearDraftThread: (threadId: ThreadId) => void;
|
||||
setPrompt: (threadId: ThreadId, prompt: string) => void;
|
||||
setProvider: (threadId: ThreadId, provider: ProviderKind | null | undefined) => void;
|
||||
setModel: (threadId: ThreadId, model: string | null | undefined) => void;
|
||||
setEffort: (threadId: ThreadId, effort: CodexReasoningEffort | null | undefined) => void;
|
||||
addImage: (threadId: ThreadId, image: ComposerImageAttachment) => void;
|
||||
@@ -129,6 +133,7 @@ const EMPTY_THREAD_DRAFT = Object.freeze({
|
||||
images: EMPTY_IMAGES,
|
||||
nonPersistedImageIds: EMPTY_IDS,
|
||||
persistedAttachments: EMPTY_PERSISTED_ATTACHMENTS,
|
||||
provider: null,
|
||||
model: null,
|
||||
effort: null,
|
||||
}) as ComposerThreadDraftState;
|
||||
@@ -143,6 +148,7 @@ function createEmptyThreadDraft(): ComposerThreadDraftState {
|
||||
images: [],
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
provider: null,
|
||||
model: null,
|
||||
effort: null,
|
||||
};
|
||||
@@ -159,11 +165,16 @@ function shouldRemoveDraft(draft: ComposerThreadDraftState): boolean {
|
||||
draft.prompt.length === 0 &&
|
||||
draft.images.length === 0 &&
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.effort === null
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeProviderKind(value: unknown): ProviderKind | null {
|
||||
return value === "codex" || value === "claudeCode" || value === "cursor" ? value : null;
|
||||
}
|
||||
|
||||
function revokeObjectPreviewUrl(previewUrl: string): void {
|
||||
if (typeof URL === "undefined") {
|
||||
return;
|
||||
@@ -307,20 +318,24 @@ function normalizePersistedComposerDraftState(value: unknown): PersistedComposer
|
||||
return normalized ? [normalized] : [];
|
||||
})
|
||||
: [];
|
||||
const provider = normalizeProviderKind(draftCandidate.provider);
|
||||
const model =
|
||||
typeof draftCandidate.model === "string" ? normalizeModelSlug(draftCandidate.model) : null;
|
||||
typeof draftCandidate.model === "string"
|
||||
? normalizeModelSlug(draftCandidate.model, provider ?? "codex")
|
||||
: null;
|
||||
const effortCandidate =
|
||||
typeof draftCandidate.effort === "string" ? draftCandidate.effort : null;
|
||||
const effort =
|
||||
effortCandidate && REASONING_EFFORT_VALUES.has(effortCandidate as CodexReasoningEffort)
|
||||
? (effortCandidate as CodexReasoningEffort)
|
||||
: null;
|
||||
if (prompt.length === 0 && attachments.length === 0 && !model && !effort) {
|
||||
if (prompt.length === 0 && attachments.length === 0 && !provider && !model && !effort) {
|
||||
continue;
|
||||
}
|
||||
nextDraftsByThreadId[threadId as ThreadId] = {
|
||||
prompt,
|
||||
attachments,
|
||||
...(provider ? { provider } : {}),
|
||||
...(model ? { model } : {}),
|
||||
...(effort ? { effort } : {}),
|
||||
};
|
||||
@@ -424,6 +439,7 @@ function toHydratedThreadDraft(
|
||||
images: hydrateImagesFromPersisted(persistedDraft.attachments),
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: persistedDraft.attachments,
|
||||
provider: persistedDraft.provider ?? null,
|
||||
model: persistedDraft.model ?? null,
|
||||
effort: persistedDraft.effort ?? null,
|
||||
};
|
||||
@@ -676,6 +692,33 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setProvider: (threadId, provider) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
}
|
||||
const normalizedProvider = normalizeProviderKind(provider);
|
||||
set((state) => {
|
||||
const existing = state.draftsByThreadId[threadId];
|
||||
if (!existing && normalizedProvider === null) {
|
||||
return state;
|
||||
}
|
||||
const base = existing ?? createEmptyThreadDraft();
|
||||
if (base.provider === normalizedProvider) {
|
||||
return state;
|
||||
}
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
provider: normalizedProvider,
|
||||
};
|
||||
const nextDraftsByThreadId = { ...state.draftsByThreadId };
|
||||
if (shouldRemoveDraft(nextDraft)) {
|
||||
delete nextDraftsByThreadId[threadId];
|
||||
} else {
|
||||
nextDraftsByThreadId[threadId] = nextDraft;
|
||||
}
|
||||
return { draftsByThreadId: nextDraftsByThreadId };
|
||||
});
|
||||
},
|
||||
setModel: (threadId, model) => {
|
||||
if (threadId.length === 0) {
|
||||
return;
|
||||
@@ -967,6 +1010,7 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (
|
||||
draft.prompt.length === 0 &&
|
||||
draft.persistedAttachments.length === 0 &&
|
||||
draft.provider === null &&
|
||||
draft.model === null &&
|
||||
draft.effort === null
|
||||
) {
|
||||
@@ -979,6 +1023,9 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (draft.model) {
|
||||
persistedDraft.model = draft.model;
|
||||
}
|
||||
if (draft.provider) {
|
||||
persistedDraft.provider = draft.provider;
|
||||
}
|
||||
if (draft.effort) {
|
||||
persistedDraft.effort = draft.effort;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,32 @@ describe("derivePendingApprovals", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("maps canonical requestType payloads into pending approvals", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "approval-open-request-type",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
kind: "approval.requested",
|
||||
summary: "Command approval requested",
|
||||
tone: "approval",
|
||||
payload: {
|
||||
requestId: "req-request-type",
|
||||
requestType: "command_execution_approval",
|
||||
detail: "pwd",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
expect(derivePendingApprovals(activities)).toEqual([
|
||||
{
|
||||
requestId: "req-request-type",
|
||||
requestKind: "command",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
detail: "pwd",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveWorkLogEntries", () => {
|
||||
|
||||
@@ -88,6 +88,21 @@ export function isLatestTurnSettled(
|
||||
return true;
|
||||
}
|
||||
|
||||
function requestKindFromRequestType(
|
||||
requestType: unknown,
|
||||
): PendingApproval["requestKind"] | null {
|
||||
switch (requestType) {
|
||||
case "command_execution_approval":
|
||||
case "exec_command_approval":
|
||||
return "command";
|
||||
case "file_change_approval":
|
||||
case "apply_patch_approval":
|
||||
return "file-change";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function derivePendingApprovals(
|
||||
activities: ReadonlyArray<OrchestrationThreadActivity>,
|
||||
): PendingApproval[] {
|
||||
@@ -106,6 +121,8 @@ export function derivePendingApprovals(
|
||||
const requestKind =
|
||||
payload && (payload.requestKind === "command" || payload.requestKind === "file-change")
|
||||
? payload.requestKind
|
||||
: payload
|
||||
? requestKindFromRequestType(payload.requestType)
|
||||
: null;
|
||||
const detail = payload && typeof payload.detail === "string" ? payload.detail : undefined;
|
||||
|
||||
|
||||
Reference in new issue
Block a user