Prepare datamodel for multi-environment (#1765)
Co-authored-by: justsomelegs <[email protected]> Co-authored-by: codex <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
121 files changed
+10195
-4958
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
type EnvironmentId,
|
||||
type EditorId,
|
||||
type ProjectScript,
|
||||
type ResolvedKeybindingsConfig,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import { memo } from "react";
|
||||
import GitActionsControl from "../GitActionsControl";
|
||||
import { DiffIcon, TerminalSquareIcon } from "lucide-react";
|
||||
@@ -15,6 +17,7 @@ import { SidebarTrigger } from "../ui/sidebar";
|
||||
import { OpenInPicker } from "./OpenInPicker";
|
||||
|
||||
interface ChatHeaderProps {
|
||||
activeThreadEnvironmentId: EnvironmentId;
|
||||
activeThreadId: ThreadId;
|
||||
activeThreadTitle: string;
|
||||
activeProjectName: string | undefined;
|
||||
@@ -39,6 +42,7 @@ interface ChatHeaderProps {
|
||||
}
|
||||
|
||||
export const ChatHeader = memo(function ChatHeader({
|
||||
activeThreadEnvironmentId,
|
||||
activeThreadId,
|
||||
activeThreadTitle,
|
||||
activeProjectName,
|
||||
@@ -101,7 +105,12 @@ export const ChatHeader = memo(function ChatHeader({
|
||||
openInCwd={openInCwd}
|
||||
/>
|
||||
)}
|
||||
{activeProjectName && <GitActionsControl gitCwd={gitCwd} activeThreadId={activeThreadId} />}
|
||||
{activeProjectName && (
|
||||
<GitActionsControl
|
||||
gitCwd={gitCwd}
|
||||
activeThreadRef={scopeThreadRef(activeThreadEnvironmentId, activeThreadId)}
|
||||
/>
|
||||
)}
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { DEFAULT_MODEL_BY_PROVIDER, ModelSelection, ThreadId } from "@t3tools/contracts";
|
||||
import {
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
EnvironmentId,
|
||||
ModelSelection,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import "../../index.css";
|
||||
|
||||
import { page } from "vitest/browser";
|
||||
@@ -9,35 +15,37 @@ import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu";
|
||||
import { TraitsMenuContent } from "./TraitsPicker";
|
||||
import { useComposerDraftStore } from "../../composerDraftStore";
|
||||
|
||||
const LOCAL_ENVIRONMENT_ID = EnvironmentId.makeUnsafe("environment-local");
|
||||
|
||||
async function mountMenu(props?: { modelSelection?: ModelSelection; prompt?: string }) {
|
||||
const threadId = ThreadId.makeUnsafe("thread-compact-menu");
|
||||
const threadRef = scopeThreadRef(LOCAL_ENVIRONMENT_ID, threadId);
|
||||
const threadKey = scopedThreadKey(threadRef);
|
||||
const provider = props?.modelSelection?.provider ?? "claudeAgent";
|
||||
const draftsByThreadId = {} as ReturnType<
|
||||
typeof useComposerDraftStore.getState
|
||||
>["draftsByThreadId"];
|
||||
const model = props?.modelSelection?.model ?? DEFAULT_MODEL_BY_PROVIDER[provider];
|
||||
|
||||
draftsByThreadId[threadId] = {
|
||||
prompt: props?.prompt ?? "",
|
||||
images: [],
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
modelSelectionByProvider: {
|
||||
[provider]: {
|
||||
provider,
|
||||
model,
|
||||
...(props?.modelSelection?.options ? { options: props.modelSelection.options } : {}),
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadKey: {
|
||||
[threadKey]: {
|
||||
prompt: props?.prompt ?? "",
|
||||
images: [],
|
||||
nonPersistedImageIds: [],
|
||||
persistedAttachments: [],
|
||||
terminalContexts: [],
|
||||
modelSelectionByProvider: {
|
||||
[provider]: {
|
||||
provider,
|
||||
model,
|
||||
...(props?.modelSelection?.options ? { options: props.modelSelection.options } : {}),
|
||||
},
|
||||
},
|
||||
activeProvider: provider,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
},
|
||||
},
|
||||
activeProvider: provider,
|
||||
runtimeMode: null,
|
||||
interactionMode: null,
|
||||
};
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId,
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {},
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
@@ -121,7 +129,7 @@ async function mountMenu(props?: { modelSelection?: ModelSelection; prompt?: str
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
models={models}
|
||||
threadId={threadId}
|
||||
threadRef={threadRef}
|
||||
model={model}
|
||||
prompt={props?.prompt ?? ""}
|
||||
modelOptions={providerOptions}
|
||||
@@ -150,9 +158,9 @@ describe("CompactComposerControlsMenu", () => {
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
draftsByThreadKey: {},
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {},
|
||||
stickyModelSelectionByProvider: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type ApprovalRequestId } from "@t3tools/contracts";
|
||||
import { memo, useCallback, useEffect, useRef } from "react";
|
||||
import { memo, useEffect, useEffectEvent, useRef } from "react";
|
||||
import { type PendingUserInput } from "../../session-logic";
|
||||
import {
|
||||
derivePendingUserInputProgress,
|
||||
@@ -60,6 +60,11 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex);
|
||||
const activeQuestion = progress.activeQuestion;
|
||||
const autoAdvanceTimerRef = useRef<number | null>(null);
|
||||
const onAdvanceRef = useRef(onAdvance);
|
||||
|
||||
useEffect(() => {
|
||||
onAdvanceRef.current = onAdvance;
|
||||
}, [onAdvance]);
|
||||
|
||||
// Clear auto-advance timer on unmount
|
||||
useEffect(() => {
|
||||
@@ -70,22 +75,19 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleOptionSelection = useCallback(
|
||||
(questionId: string, optionLabel: string) => {
|
||||
onToggleOption(questionId, optionLabel);
|
||||
if (activeQuestion?.multiSelect) {
|
||||
return;
|
||||
}
|
||||
if (autoAdvanceTimerRef.current !== null) {
|
||||
window.clearTimeout(autoAdvanceTimerRef.current);
|
||||
}
|
||||
autoAdvanceTimerRef.current = window.setTimeout(() => {
|
||||
autoAdvanceTimerRef.current = null;
|
||||
onAdvance();
|
||||
}, 200);
|
||||
},
|
||||
[activeQuestion?.multiSelect, onAdvance, onToggleOption],
|
||||
);
|
||||
const handleOptionSelection = useEffectEvent((questionId: string, optionLabel: string) => {
|
||||
onToggleOption(questionId, optionLabel);
|
||||
if (activeQuestion?.multiSelect) {
|
||||
return;
|
||||
}
|
||||
if (autoAdvanceTimerRef.current !== null) {
|
||||
window.clearTimeout(autoAdvanceTimerRef.current);
|
||||
}
|
||||
autoAdvanceTimerRef.current = window.setTimeout(() => {
|
||||
autoAdvanceTimerRef.current = null;
|
||||
onAdvanceRef.current();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
// Keyboard shortcut: number keys 1-9 select corresponding options when focus is
|
||||
// outside editable fields. Multi-select prompts toggle options in place; single-
|
||||
@@ -112,7 +114,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
};
|
||||
document.addEventListener("keydown", handler);
|
||||
return () => document.removeEventListener("keydown", handler);
|
||||
}, [activeQuestion, handleOptionSelection, isResponding]);
|
||||
}, [activeQuestion, isResponding]);
|
||||
|
||||
if (!activeQuestion) {
|
||||
return null;
|
||||
|
||||
@@ -42,6 +42,8 @@ beforeAll(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const ACTIVE_THREAD_ENVIRONMENT_ID = "environment-local" as never;
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
it("renders inline terminal labels with the composer chip UI", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
@@ -85,6 +87,7 @@ describe("MessagesTimeline", () => {
|
||||
onRevertUserMessage={() => {}}
|
||||
isRevertingCheckpoint={false}
|
||||
onImageExpand={() => {}}
|
||||
activeThreadEnvironmentId={ACTIVE_THREAD_ENVIRONMENT_ID}
|
||||
markdownCwd={undefined}
|
||||
resolvedTheme="light"
|
||||
timestampFormat="locale"
|
||||
@@ -130,6 +133,7 @@ describe("MessagesTimeline", () => {
|
||||
onRevertUserMessage={() => {}}
|
||||
isRevertingCheckpoint={false}
|
||||
onImageExpand={() => {}}
|
||||
activeThreadEnvironmentId={ACTIVE_THREAD_ENVIRONMENT_ID}
|
||||
markdownCwd={undefined}
|
||||
resolvedTheme="light"
|
||||
timestampFormat="locale"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type MessageId, type TurnId } from "@t3tools/contracts";
|
||||
import { type EnvironmentId, type MessageId, type TurnId } from "@t3tools/contracts";
|
||||
import {
|
||||
memo,
|
||||
useCallback,
|
||||
@@ -82,6 +82,7 @@ interface MessagesTimelineProps {
|
||||
onRevertUserMessage: (messageId: MessageId) => void;
|
||||
isRevertingCheckpoint: boolean;
|
||||
onImageExpand: (preview: ExpandedImagePreview) => void;
|
||||
activeThreadEnvironmentId: EnvironmentId;
|
||||
markdownCwd: string | undefined;
|
||||
resolvedTheme: "light" | "dark";
|
||||
timestampFormat: TimestampFormat;
|
||||
@@ -117,6 +118,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
onRevertUserMessage,
|
||||
isRevertingCheckpoint,
|
||||
onImageExpand,
|
||||
activeThreadEnvironmentId,
|
||||
markdownCwd,
|
||||
resolvedTheme,
|
||||
timestampFormat,
|
||||
@@ -531,6 +533,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
<div className="min-w-0 px-1 py-0.5">
|
||||
<ProposedPlanCard
|
||||
planMarkdown={row.proposedPlan.planMarkdown}
|
||||
environmentId={activeThreadEnvironmentId}
|
||||
cwd={markdownCwd}
|
||||
workspaceRoot={workspaceRoot}
|
||||
/>
|
||||
|
||||
@@ -19,6 +19,7 @@ const DEFAULT_VIEWPORT = {
|
||||
height: 1_100,
|
||||
};
|
||||
const MARKDOWN_CWD = "/repo/project";
|
||||
const ACTIVE_THREAD_ENVIRONMENT_ID = "environment-local" as never;
|
||||
|
||||
interface RowMeasurement {
|
||||
actualHeightPx: number;
|
||||
@@ -31,7 +32,10 @@ interface RowMeasurement {
|
||||
interface VirtualizationScenario {
|
||||
name: string;
|
||||
targetRowId: string;
|
||||
props: Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer">;
|
||||
props: Omit<
|
||||
ComponentProps<typeof MessagesTimeline>,
|
||||
"scrollContainer" | "activeThreadEnvironmentId"
|
||||
>;
|
||||
maxEstimateDeltaPx: number;
|
||||
}
|
||||
|
||||
@@ -48,7 +52,10 @@ interface VirtualizerSnapshot {
|
||||
}
|
||||
|
||||
function MessagesTimelineBrowserHarness(
|
||||
props: Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer">,
|
||||
props: Omit<
|
||||
ComponentProps<typeof MessagesTimeline>,
|
||||
"scrollContainer" | "activeThreadEnvironmentId"
|
||||
>,
|
||||
) {
|
||||
const [scrollContainer, setScrollContainer] = useState<HTMLDivElement | null>(null);
|
||||
const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>(
|
||||
@@ -73,6 +80,7 @@ function MessagesTimelineBrowserHarness(
|
||||
>
|
||||
<MessagesTimeline
|
||||
{...props}
|
||||
activeThreadEnvironmentId={ACTIVE_THREAD_ENVIRONMENT_ID}
|
||||
scrollContainer={scrollContainer}
|
||||
expandedWorkGroups={expandedWorkGroups}
|
||||
onToggleWorkGroup={handleToggleWorkGroup}
|
||||
@@ -143,7 +151,7 @@ function createBaseTimelineProps(input: {
|
||||
completionDividerBeforeEntryId?: string | null;
|
||||
turnDiffSummaryByAssistantMessageId?: Map<MessageId, TurnDiffSummary>;
|
||||
onVirtualizerSnapshot?: ComponentProps<typeof MessagesTimeline>["onVirtualizerSnapshot"];
|
||||
}): Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer"> {
|
||||
}): Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer" | "activeThreadEnvironmentId"> {
|
||||
return {
|
||||
hasMessages: true,
|
||||
isWorking: false,
|
||||
@@ -481,7 +489,10 @@ async function waitForElement<T extends Element>(
|
||||
|
||||
async function measureTimelineRow(input: {
|
||||
host: HTMLElement;
|
||||
props: Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer">;
|
||||
props: Omit<
|
||||
ComponentProps<typeof MessagesTimeline>,
|
||||
"scrollContainer" | "activeThreadEnvironmentId"
|
||||
>;
|
||||
targetRowId: string;
|
||||
}): Promise<RowMeasurement> {
|
||||
const scrollContainer = await waitForElement(
|
||||
@@ -550,7 +561,10 @@ async function measureTimelineRow(input: {
|
||||
}
|
||||
|
||||
async function mountMessagesTimeline(input: {
|
||||
props: Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer">;
|
||||
props: Omit<
|
||||
ComponentProps<typeof MessagesTimeline>,
|
||||
"scrollContainer" | "activeThreadEnvironmentId"
|
||||
>;
|
||||
viewport?: { width: number; height: number };
|
||||
}) {
|
||||
const viewport = input.viewport ?? DEFAULT_VIEWPORT;
|
||||
@@ -576,7 +590,10 @@ async function mountMessagesTimeline(input: {
|
||||
return {
|
||||
host,
|
||||
rerender: async (
|
||||
nextProps: Omit<ComponentProps<typeof MessagesTimeline>, "scrollContainer">,
|
||||
nextProps: Omit<
|
||||
ComponentProps<typeof MessagesTimeline>,
|
||||
"scrollContainer" | "activeThreadEnvironmentId"
|
||||
>,
|
||||
) => {
|
||||
await screen.rerender(<MessagesTimelineBrowserHarness {...nextProps} />);
|
||||
await waitForLayout();
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
Zed,
|
||||
} from "../Icons";
|
||||
import { isMacPlatform, isWindowsPlatform } from "~/lib/utils";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
import { readLocalApi } from "~/localApi";
|
||||
|
||||
const resolveOptions = (platform: string, availableEditors: ReadonlyArray<EditorId>) => {
|
||||
const baseOptions: ReadonlyArray<{ label: string; Icon: Icon; value: EditorId }> = [
|
||||
@@ -93,7 +93,7 @@ export const OpenInPicker = memo(function OpenInPicker({
|
||||
|
||||
const openInEditor = useCallback(
|
||||
(editorId: EditorId | null) => {
|
||||
const api = readNativeApi();
|
||||
const api = readLocalApi();
|
||||
if (!api || !openInCwd) return;
|
||||
const editor = editorId ?? preferredEditor;
|
||||
if (!editor) return;
|
||||
@@ -110,7 +110,7 @@ export const OpenInPicker = memo(function OpenInPicker({
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (e: globalThis.KeyboardEvent) => {
|
||||
const api = readNativeApi();
|
||||
const api = readLocalApi();
|
||||
if (!isOpenFavoriteEditorShortcut(e, keybindings)) return;
|
||||
if (!api || !openInCwd) return;
|
||||
if (!preferredEditor) return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { memo, useState, useId } from "react";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import {
|
||||
buildCollapsedProposedPlanPreviewMarkdown,
|
||||
buildProposedPlanMarkdownFilename,
|
||||
@@ -24,15 +25,17 @@ import {
|
||||
DialogTitle,
|
||||
} from "../ui/dialog";
|
||||
import { toastManager } from "../ui/toast";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
import { readEnvironmentApi } from "~/environmentApi";
|
||||
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
|
||||
|
||||
export const ProposedPlanCard = memo(function ProposedPlanCard({
|
||||
planMarkdown,
|
||||
environmentId,
|
||||
cwd,
|
||||
workspaceRoot,
|
||||
}: {
|
||||
planMarkdown: string;
|
||||
environmentId: EnvironmentId;
|
||||
cwd: string | undefined;
|
||||
workspaceRoot: string | undefined;
|
||||
}) {
|
||||
@@ -82,7 +85,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
|
||||
};
|
||||
|
||||
const handleSaveToWorkspace = () => {
|
||||
const api = readNativeApi();
|
||||
const api = readEnvironmentApi(environmentId);
|
||||
const relativePath = savePath.trim();
|
||||
if (!api || !workspaceRoot) {
|
||||
return;
|
||||
|
||||
@@ -6,10 +6,11 @@ import {
|
||||
CodexModelOptions,
|
||||
DEFAULT_MODEL_BY_PROVIDER,
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
ProjectId,
|
||||
EnvironmentId,
|
||||
type ServerProvider,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import { page } from "vitest/browser";
|
||||
import { useCallback } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -27,7 +28,13 @@ import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
|
||||
|
||||
// ── Claude TraitsPicker tests ─────────────────────────────────────────
|
||||
|
||||
const LOCAL_ENVIRONMENT_ID = EnvironmentId.makeUnsafe("environment-local");
|
||||
const CLAUDE_THREAD_ID = ThreadId.makeUnsafe("thread-claude-traits");
|
||||
const CLAUDE_THREAD_REF = scopeThreadRef(LOCAL_ENVIRONMENT_ID, CLAUDE_THREAD_ID);
|
||||
const CLAUDE_THREAD_KEY = scopedThreadKey(CLAUDE_THREAD_REF);
|
||||
const CODEX_THREAD_ID = ThreadId.makeUnsafe("thread-codex-traits");
|
||||
const CODEX_THREAD_REF = scopeThreadRef(LOCAL_ENVIRONMENT_ID, CODEX_THREAD_ID);
|
||||
const CODEX_THREAD_KEY = scopedThreadKey(CODEX_THREAD_REF);
|
||||
const TEST_PROVIDERS: ReadonlyArray<ServerProvider> = [
|
||||
{
|
||||
provider: "codex",
|
||||
@@ -120,10 +127,10 @@ function ClaudeTraitsPickerHarness(props: {
|
||||
fallbackModelSelection: ModelSelection | null;
|
||||
triggerVariant?: "ghost" | "outline";
|
||||
}) {
|
||||
const prompt = useComposerThreadDraft(CLAUDE_THREAD_ID).prompt;
|
||||
const prompt = useComposerThreadDraft(CLAUDE_THREAD_REF).prompt;
|
||||
const setPrompt = useComposerDraftStore((store) => store.setPrompt);
|
||||
const { modelOptions, selectedModel } = useEffectiveComposerModelState({
|
||||
threadId: CLAUDE_THREAD_ID,
|
||||
threadRef: CLAUDE_THREAD_REF,
|
||||
providers: TEST_PROVIDERS,
|
||||
selectedProvider: "claudeAgent",
|
||||
threadModelSelection: props.fallbackModelSelection,
|
||||
@@ -135,7 +142,7 @@ function ClaudeTraitsPickerHarness(props: {
|
||||
});
|
||||
const handlePromptChange = useCallback(
|
||||
(nextPrompt: string) => {
|
||||
setPrompt(CLAUDE_THREAD_ID, nextPrompt);
|
||||
setPrompt(CLAUDE_THREAD_REF, nextPrompt);
|
||||
},
|
||||
[setPrompt],
|
||||
);
|
||||
@@ -144,7 +151,7 @@ function ClaudeTraitsPickerHarness(props: {
|
||||
<TraitsPicker
|
||||
provider="claudeAgent"
|
||||
models={TEST_PROVIDERS[1]!.models}
|
||||
threadId={CLAUDE_THREAD_ID}
|
||||
threadRef={CLAUDE_THREAD_REF}
|
||||
model={selectedModel ?? props.model}
|
||||
prompt={prompt}
|
||||
modelOptions={modelOptions?.claudeAgent}
|
||||
@@ -168,8 +175,8 @@ async function mountClaudePicker(props?: {
|
||||
}) {
|
||||
const model = props?.model ?? "claude-opus-4-6";
|
||||
const claudeOptions = !props?.skipDraftModelOptions ? props?.options : undefined;
|
||||
const draftsByThreadId: Record<ThreadId, ComposerThreadDraftState> = {
|
||||
[CLAUDE_THREAD_ID]: {
|
||||
const draftsByThreadKey: Record<string, ComposerThreadDraftState> = {
|
||||
[CLAUDE_THREAD_KEY]: {
|
||||
prompt: props?.prompt ?? "",
|
||||
images: [],
|
||||
nonPersistedImageIds: [],
|
||||
@@ -192,9 +199,9 @@ async function mountClaudePicker(props?: {
|
||||
},
|
||||
};
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId,
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
draftsByThreadKey,
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {},
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
@@ -230,9 +237,9 @@ describe("TraitsPicker (Claude)", () => {
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
draftsByThreadKey: {},
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {},
|
||||
stickyModelSelectionByProvider: {},
|
||||
});
|
||||
});
|
||||
@@ -369,10 +376,9 @@ describe("TraitsPicker (Claude)", () => {
|
||||
// ── Codex TraitsPicker tests ──────────────────────────────────────────
|
||||
|
||||
async function mountCodexPicker(props: { model?: string; options?: CodexModelOptions }) {
|
||||
const threadId = ThreadId.makeUnsafe("thread-codex-traits");
|
||||
const model = props.model ?? DEFAULT_MODEL_BY_PROVIDER.codex;
|
||||
const draftsByThreadId: Record<ThreadId, ComposerThreadDraftState> = {
|
||||
[threadId]: {
|
||||
const draftsByThreadKey: Record<string, ComposerThreadDraftState> = {
|
||||
[CODEX_THREAD_KEY]: {
|
||||
prompt: "",
|
||||
images: [],
|
||||
nonPersistedImageIds: [],
|
||||
@@ -392,10 +398,10 @@ async function mountCodexPicker(props: { model?: string; options?: CodexModelOpt
|
||||
};
|
||||
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId,
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {
|
||||
[ProjectId.makeUnsafe("project-codex-traits")]: threadId,
|
||||
draftsByThreadKey,
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {
|
||||
"environment-local:project-codex-traits": CODEX_THREAD_KEY,
|
||||
},
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
@@ -404,7 +410,7 @@ async function mountCodexPicker(props: { model?: string; options?: CodexModelOpt
|
||||
<TraitsPicker
|
||||
provider="codex"
|
||||
models={TEST_PROVIDERS[0]!.models}
|
||||
threadId={threadId}
|
||||
threadRef={CODEX_THREAD_REF}
|
||||
model={props.model ?? DEFAULT_MODEL_BY_PROVIDER.codex}
|
||||
prompt=""
|
||||
modelOptions={props.options}
|
||||
@@ -429,9 +435,9 @@ describe("TraitsPicker (Codex)", () => {
|
||||
document.body.innerHTML = "";
|
||||
localStorage.removeItem(COMPOSER_DRAFT_STORAGE_KEY);
|
||||
useComposerDraftStore.setState({
|
||||
draftsByThreadId: {},
|
||||
draftThreadsByThreadId: {},
|
||||
projectDraftThreadIdByProjectId: {},
|
||||
draftsByThreadKey: {},
|
||||
draftThreadsByThreadKey: {},
|
||||
logicalProjectDraftThreadKeyByLogicalProjectKey: {},
|
||||
stickyModelSelectionByProvider: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,8 +3,8 @@ import {
|
||||
type CodexModelOptions,
|
||||
type ProviderKind,
|
||||
type ProviderModelOptions,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
applyClaudePromptEffortPrefix,
|
||||
@@ -28,18 +28,19 @@ import {
|
||||
MenuSeparator as MenuDivider,
|
||||
MenuTrigger,
|
||||
} from "../ui/menu";
|
||||
import { useComposerDraftStore } from "../../composerDraftStore";
|
||||
import { useComposerDraftStore, DraftId } from "../../composerDraftStore";
|
||||
import { getProviderModelCapabilities } from "../../providerModels";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
type ProviderOptions = ProviderModelOptions[ProviderKind];
|
||||
type TraitsPersistence =
|
||||
| {
|
||||
threadId: ThreadId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
onModelOptionsChange?: never;
|
||||
}
|
||||
| {
|
||||
threadId?: undefined;
|
||||
threadRef?: undefined;
|
||||
onModelOptionsChange: (nextOptions: ProviderOptions | undefined) => void;
|
||||
};
|
||||
|
||||
@@ -167,7 +168,13 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
persistence.onModelOptionsChange(nextOptions);
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(persistence.threadId, provider, nextOptions, { persistSticky: true });
|
||||
const threadTarget = persistence.threadRef ?? persistence.draftId;
|
||||
if (!threadTarget) {
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ServerProviderModel } from "@t3tools/contracts";
|
||||
import { getComposerProviderState } from "./composerProviderRegistry";
|
||||
import {
|
||||
getComposerProviderState,
|
||||
renderProviderTraitsMenuContent,
|
||||
renderProviderTraitsPicker,
|
||||
} from "./composerProviderRegistry";
|
||||
|
||||
const CODEX_MODELS: ReadonlyArray<ServerProviderModel> = [
|
||||
{
|
||||
@@ -417,3 +421,31 @@ describe("getComposerProviderState", () => {
|
||||
expect(state.modelOptionsForDispatch).not.toHaveProperty("fastMode");
|
||||
});
|
||||
});
|
||||
|
||||
describe("provider traits render guards", () => {
|
||||
it("returns null for codex traits picker when no thread target is provided", () => {
|
||||
const content = renderProviderTraitsPicker({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
models: CODEX_MODELS,
|
||||
modelOptions: undefined,
|
||||
prompt: "",
|
||||
onPromptChange: () => {},
|
||||
});
|
||||
|
||||
expect(content).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for claude traits menu content when no thread target is provided", () => {
|
||||
const content = renderProviderTraitsMenuContent({
|
||||
provider: "claudeAgent",
|
||||
model: "claude-sonnet-4-6",
|
||||
models: CLAUDE_MODELS,
|
||||
modelOptions: undefined,
|
||||
prompt: "",
|
||||
onPromptChange: () => {},
|
||||
});
|
||||
|
||||
expect(content).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
type ProviderKind,
|
||||
type ProviderModelOptions,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { isClaudeUltrathinkPrompt, resolveEffort } from "@t3tools/shared/model";
|
||||
import type { ReactNode } from "react";
|
||||
import type { DraftId } from "../../composerDraftStore";
|
||||
import { getProviderModelCapabilities } from "../../providerModels";
|
||||
import { TraitsMenuContent, TraitsPicker } from "./TraitsPicker";
|
||||
import {
|
||||
@@ -33,7 +34,8 @@ export type ComposerProviderState = {
|
||||
type ProviderRegistryEntry = {
|
||||
getState: (input: ComposerProviderStateInput) => ComposerProviderState;
|
||||
renderTraitsMenuContent: (input: {
|
||||
threadId: ThreadId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
modelOptions: ProviderModelOptions[ProviderKind] | undefined;
|
||||
@@ -41,7 +43,8 @@ type ProviderRegistryEntry = {
|
||||
onPromptChange: (prompt: string) => void;
|
||||
}) => ReactNode;
|
||||
renderTraitsPicker: (input: {
|
||||
threadId: ThreadId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
modelOptions: ProviderModelOptions[ProviderKind] | undefined;
|
||||
@@ -50,6 +53,13 @@ type ProviderRegistryEntry = {
|
||||
}) => ReactNode;
|
||||
};
|
||||
|
||||
function hasComposerTraitsTarget(input: {
|
||||
threadRef: ScopedThreadRef | undefined;
|
||||
draftId: DraftId | undefined;
|
||||
}): boolean {
|
||||
return input.threadRef !== undefined || input.draftId !== undefined;
|
||||
}
|
||||
|
||||
function getProviderStateFromCapabilities(
|
||||
input: ComposerProviderStateInput,
|
||||
): ComposerProviderState {
|
||||
@@ -94,66 +104,92 @@ const composerProviderRegistry: Record<ProviderKind, ProviderRegistryEntry> = {
|
||||
codex: {
|
||||
getState: (input) => getProviderStateFromCapabilities(input),
|
||||
renderTraitsMenuContent: ({
|
||||
threadId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
}) => (
|
||||
<TraitsMenuContent
|
||||
provider="codex"
|
||||
models={models}
|
||||
threadId={threadId}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
renderTraitsPicker: ({ threadId, model, models, modelOptions, prompt, onPromptChange }) => (
|
||||
<TraitsPicker
|
||||
provider="codex"
|
||||
models={models}
|
||||
threadId={threadId}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
}) =>
|
||||
!hasComposerTraitsTarget({ threadRef, draftId }) ? null : (
|
||||
<TraitsMenuContent
|
||||
provider="codex"
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
renderTraitsPicker: ({
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
}) =>
|
||||
!hasComposerTraitsTarget({ threadRef, draftId }) ? null : (
|
||||
<TraitsPicker
|
||||
provider="codex"
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
},
|
||||
claudeAgent: {
|
||||
getState: (input) => getProviderStateFromCapabilities(input),
|
||||
renderTraitsMenuContent: ({
|
||||
threadId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
}) => (
|
||||
<TraitsMenuContent
|
||||
provider="claudeAgent"
|
||||
models={models}
|
||||
threadId={threadId}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
renderTraitsPicker: ({ threadId, model, models, modelOptions, prompt, onPromptChange }) => (
|
||||
<TraitsPicker
|
||||
provider="claudeAgent"
|
||||
models={models}
|
||||
threadId={threadId}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
}) =>
|
||||
!hasComposerTraitsTarget({ threadRef, draftId }) ? null : (
|
||||
<TraitsMenuContent
|
||||
provider="claudeAgent"
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
renderTraitsPicker: ({
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
}) =>
|
||||
!hasComposerTraitsTarget({ threadRef, draftId }) ? null : (
|
||||
<TraitsPicker
|
||||
provider="claudeAgent"
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
model={model}
|
||||
modelOptions={modelOptions}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
/>
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -163,7 +199,8 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
|
||||
|
||||
export function renderProviderTraitsMenuContent(input: {
|
||||
provider: ProviderKind;
|
||||
threadId: ThreadId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
modelOptions: ProviderModelOptions[ProviderKind] | undefined;
|
||||
@@ -171,7 +208,8 @@ export function renderProviderTraitsMenuContent(input: {
|
||||
onPromptChange: (prompt: string) => void;
|
||||
}): ReactNode {
|
||||
return composerProviderRegistry[input.provider].renderTraitsMenuContent({
|
||||
threadId: input.threadId,
|
||||
...(input.threadRef ? { threadRef: input.threadRef } : {}),
|
||||
...(input.draftId ? { draftId: input.draftId } : {}),
|
||||
model: input.model,
|
||||
models: input.models,
|
||||
modelOptions: input.modelOptions,
|
||||
@@ -182,7 +220,8 @@ export function renderProviderTraitsMenuContent(input: {
|
||||
|
||||
export function renderProviderTraitsPicker(input: {
|
||||
provider: ProviderKind;
|
||||
threadId: ThreadId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
modelOptions: ProviderModelOptions[ProviderKind] | undefined;
|
||||
@@ -190,7 +229,8 @@ export function renderProviderTraitsPicker(input: {
|
||||
onPromptChange: (prompt: string) => void;
|
||||
}): ReactNode {
|
||||
return composerProviderRegistry[input.provider].renderTraitsPicker({
|
||||
threadId: input.threadId,
|
||||
...(input.threadRef ? { threadRef: input.threadRef } : {}),
|
||||
...(input.draftId ? { draftId: input.draftId } : {}),
|
||||
model: input.model,
|
||||
models: input.models,
|
||||
modelOptions: input.modelOptions,
|
||||
|
||||
Reference in new issue
Block a user