Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b89ba0651b | ||
|
|
406d486e06 | ||
|
|
100a978bc5 | ||
|
|
926042276d | ||
|
|
5a5afe7f8f |
No files matched your search
@@ -14,32 +14,23 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
const TraceRecordLine = Schema.Struct({
|
||||
name: Schema.optional(Schema.Unknown),
|
||||
traceId: Schema.optional(Schema.Unknown),
|
||||
spanId: Schema.optional(Schema.Unknown),
|
||||
startTimeUnixNano: Schema.optional(Schema.Unknown),
|
||||
endTimeUnixNano: Schema.optional(Schema.Unknown),
|
||||
durationMs: Schema.optional(Schema.Unknown),
|
||||
exit: Schema.optional(Schema.Unknown),
|
||||
events: Schema.optional(Schema.Array(Schema.Unknown)),
|
||||
});
|
||||
interface TraceRecordLike {
|
||||
readonly name?: unknown;
|
||||
readonly traceId?: unknown;
|
||||
readonly spanId?: unknown;
|
||||
readonly startTimeUnixNano?: unknown;
|
||||
readonly endTimeUnixNano?: unknown;
|
||||
readonly durationMs?: unknown;
|
||||
readonly exit?: unknown;
|
||||
readonly events?: unknown;
|
||||
}
|
||||
|
||||
const TraceEvent = Schema.Struct({
|
||||
name: Schema.optional(Schema.Unknown),
|
||||
timeUnixNano: Schema.optional(Schema.Unknown),
|
||||
attributes: Schema.optional(Schema.Unknown),
|
||||
});
|
||||
|
||||
const TraceEventAttributes = Schema.Record(Schema.String, Schema.Unknown);
|
||||
|
||||
type TraceEventLike = typeof TraceEvent.Type;
|
||||
|
||||
const decodeTraceRecordLine = Schema.decodeUnknownOption(Schema.fromJsonString(TraceRecordLine));
|
||||
const decodeTraceEvent = Schema.decodeUnknownOption(TraceEvent);
|
||||
const decodeTraceEventAttributes = Schema.decodeUnknownOption(TraceEventAttributes);
|
||||
interface TraceEventLike {
|
||||
readonly name?: unknown;
|
||||
readonly timeUnixNano?: unknown;
|
||||
readonly attributes?: unknown;
|
||||
}
|
||||
|
||||
export interface TraceDiagnosticsOptions {
|
||||
readonly traceFilePath: string;
|
||||
@@ -83,42 +74,47 @@ function toRotatedTracePaths(traceFilePath: string, maxFiles: number): ReadonlyA
|
||||
return [...backups, traceFilePath];
|
||||
}
|
||||
|
||||
function isRecordObject(value: unknown): value is Readonly<Record<string, unknown>> {
|
||||
function isRecordObject(value: unknown): value is TraceRecordLike {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function toStringValue(value: unknown): Option.Option<string> {
|
||||
return typeof value === "string" && value.trim().length > 0 ? Option.some(value) : Option.none();
|
||||
function toStringValue(value: unknown): string | null {
|
||||
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
||||
}
|
||||
|
||||
function toNumberValue(value: unknown): Option.Option<number> {
|
||||
return typeof value === "number" && Number.isFinite(value) ? Option.some(value) : Option.none();
|
||||
function toNumberValue(value: unknown): number | null {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
function unixNanoToDateTime(value: unknown): Option.Option<DateTime.Utc> {
|
||||
function unixNanoToDateTime(value: unknown): DateTime.Utc | null {
|
||||
const text = toStringValue(value);
|
||||
if (Option.isNone(text)) return Option.none();
|
||||
if (!text) return null;
|
||||
try {
|
||||
const millis = Number(BigInt(text.value) / 1_000_000n);
|
||||
return DateTime.make(millis);
|
||||
const millis = Number(BigInt(text) / 1_000_000n);
|
||||
return Option.getOrNull(DateTime.make(millis));
|
||||
} catch {
|
||||
return Option.none();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function readExitTag(exit: unknown): Option.Option<string> {
|
||||
if (!isRecordObject(exit) || !("_tag" in exit)) return Option.none();
|
||||
function readExitTag(exit: unknown): string | null {
|
||||
if (!isRecordObject(exit) || !("_tag" in exit)) return null;
|
||||
return toStringValue(exit._tag);
|
||||
}
|
||||
|
||||
function readExitCause(exit: unknown): string {
|
||||
if (!isRecordObject(exit) || !("cause" in exit)) return "Failure";
|
||||
const cause = toStringValue(exit.cause);
|
||||
return Option.isSome(cause) ? cause.value.trim() : "Failure";
|
||||
return toStringValue(exit.cause)?.trim() ?? "Failure";
|
||||
}
|
||||
|
||||
function isTraceEvent(value: unknown): value is TraceEventLike {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function readEventAttributes(event: TraceEventLike): Readonly<Record<string, unknown>> {
|
||||
return Option.getOrElse(decodeTraceEventAttributes(event.attributes), () => ({}));
|
||||
return typeof event.attributes === "object" && event.attributes !== null
|
||||
? (event.attributes as Readonly<Record<string, unknown>>)
|
||||
: {};
|
||||
}
|
||||
|
||||
function makeEmptyDiagnostics(input: {
|
||||
@@ -203,8 +199,8 @@ export function aggregateTraceDiagnostics(
|
||||
let failureCount = 0;
|
||||
let interruptionCount = 0;
|
||||
let slowSpanCount = 0;
|
||||
let firstSpanAt = Option.none<DateTime.Utc>();
|
||||
let lastSpanAt = Option.none<DateTime.Utc>();
|
||||
let firstSpanAt: DateTime.Utc | null = null;
|
||||
let lastSpanAt: DateTime.Utc | null = null;
|
||||
|
||||
const spansByName = new Map<
|
||||
string,
|
||||
@@ -221,50 +217,42 @@ export function aggregateTraceDiagnostics(
|
||||
for (const line of lines) {
|
||||
if (line.trim().length === 0) continue;
|
||||
|
||||
const parsedOption = decodeTraceRecordLine(line);
|
||||
if (Option.isNone(parsedOption)) {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(line);
|
||||
} catch {
|
||||
parseErrorCount += 1;
|
||||
continue;
|
||||
}
|
||||
const parsed = parsedOption.value;
|
||||
|
||||
const nameOption = toStringValue(parsed.name);
|
||||
const traceIdOption = toStringValue(parsed.traceId);
|
||||
const spanIdOption = toStringValue(parsed.spanId);
|
||||
const durationMsOption = toNumberValue(parsed.durationMs);
|
||||
const endedAtOption = unixNanoToDateTime(parsed.endTimeUnixNano);
|
||||
if (!isRecordObject(parsed)) {
|
||||
parseErrorCount += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
const name = toStringValue(parsed.name);
|
||||
const traceId = toStringValue(parsed.traceId);
|
||||
const spanId = toStringValue(parsed.spanId);
|
||||
const durationMs = toNumberValue(parsed.durationMs);
|
||||
const endedAt = unixNanoToDateTime(parsed.endTimeUnixNano);
|
||||
const startedAt = unixNanoToDateTime(parsed.startTimeUnixNano);
|
||||
|
||||
if (
|
||||
Option.isNone(nameOption) ||
|
||||
Option.isNone(traceIdOption) ||
|
||||
Option.isNone(spanIdOption) ||
|
||||
Option.isNone(durationMsOption) ||
|
||||
Option.isNone(endedAtOption)
|
||||
) {
|
||||
if (!name || !traceId || !spanId || durationMs === null || !endedAt) {
|
||||
parseErrorCount += 1;
|
||||
continue;
|
||||
}
|
||||
const name = nameOption.value;
|
||||
const traceId = traceIdOption.value;
|
||||
const spanId = spanIdOption.value;
|
||||
const durationMs = durationMsOption.value;
|
||||
const endedAt = endedAtOption.value;
|
||||
|
||||
recordCount += 1;
|
||||
if (
|
||||
Option.isSome(startedAt) &&
|
||||
(Option.isNone(firstSpanAt) || DateTime.isLessThan(startedAt.value, firstSpanAt.value))
|
||||
) {
|
||||
firstSpanAt = startedAt;
|
||||
}
|
||||
if (Option.isNone(lastSpanAt) || DateTime.isGreaterThan(endedAt, lastSpanAt.value)) {
|
||||
lastSpanAt = Option.some(endedAt);
|
||||
}
|
||||
firstSpanAt =
|
||||
startedAt && (firstSpanAt === null || DateTime.isLessThan(startedAt, firstSpanAt))
|
||||
? startedAt
|
||||
: firstSpanAt;
|
||||
lastSpanAt =
|
||||
lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt;
|
||||
|
||||
const exitTag = readExitTag(parsed.exit);
|
||||
const isFailure = Option.isSome(exitTag) && exitTag.value === "Failure";
|
||||
const isInterrupted = Option.isSome(exitTag) && exitTag.value === "Interrupted";
|
||||
const isFailure = exitTag === "Failure";
|
||||
const isInterrupted = exitTag === "Interrupted";
|
||||
if (isFailure) failureCount += 1;
|
||||
if (isInterrupted) interruptionCount += 1;
|
||||
|
||||
@@ -304,14 +292,11 @@ export function aggregateTraceDiagnostics(
|
||||
}
|
||||
|
||||
if (Array.isArray(parsed.events)) {
|
||||
for (const rawTraceEvent of parsed.events) {
|
||||
const eventOption = decodeTraceEvent(rawTraceEvent);
|
||||
if (Option.isNone(eventOption)) continue;
|
||||
const event = eventOption.value;
|
||||
const attributes = readEventAttributes(event);
|
||||
const levelOption = toStringValue(attributes["effect.logLevel"]);
|
||||
if (Option.isNone(levelOption)) continue;
|
||||
const level = levelOption.value;
|
||||
for (const rawEvent of parsed.events) {
|
||||
if (!isTraceEvent(rawEvent)) continue;
|
||||
const attributes = readEventAttributes(rawEvent);
|
||||
const level = toStringValue(attributes["effect.logLevel"]);
|
||||
if (!level) continue;
|
||||
|
||||
logLevelCounts[level] = (logLevelCounts[level] ?? 0) + 1;
|
||||
const normalizedLevel = level.toLowerCase();
|
||||
@@ -324,11 +309,8 @@ export function aggregateTraceDiagnostics(
|
||||
continue;
|
||||
}
|
||||
|
||||
const seenAt = Option.getOrElse(unixNanoToDateTime(event.timeUnixNano), () => endedAt);
|
||||
const message = Option.getOrElse(
|
||||
Option.map(toStringValue(event.name), (value) => value.trim()),
|
||||
() => "Log event",
|
||||
);
|
||||
const seenAt = unixNanoToDateTime(rawEvent.timeUnixNano) ?? endedAt;
|
||||
const message = toStringValue(rawEvent.name)?.trim() ?? "Log event";
|
||||
latestWarningAndErrorLogs.push({
|
||||
spanName: name,
|
||||
level,
|
||||
@@ -360,8 +342,8 @@ export function aggregateTraceDiagnostics(
|
||||
readAt,
|
||||
recordCount,
|
||||
parseErrorCount,
|
||||
firstSpanAt,
|
||||
lastSpanAt,
|
||||
firstSpanAt: Option.fromNullishOr(firstSpanAt),
|
||||
lastSpanAt: Option.fromNullishOr(lastSpanAt),
|
||||
failureCount,
|
||||
interruptionCount,
|
||||
slowSpanThresholdMs,
|
||||
|
||||
@@ -4,12 +4,11 @@ import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Random from "effect/Random";
|
||||
import * as Scope from "effect/Scope";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { expect } from "vitest";
|
||||
@@ -189,22 +188,6 @@ function runGitSyncForFakeGh(cwd: string, args: readonly string[]): void {
|
||||
});
|
||||
}
|
||||
|
||||
function makeDeterministicRandomService(seed = 0x1234_5678): {
|
||||
nextIntUnsafe: () => number;
|
||||
nextDoubleUnsafe: () => number;
|
||||
} {
|
||||
let state = seed >>> 0;
|
||||
const nextIntUnsafe = (): number => {
|
||||
state = (Math.imul(1_664_525, state) + 1_013_904_223) >>> 0;
|
||||
return state;
|
||||
};
|
||||
|
||||
return {
|
||||
nextIntUnsafe,
|
||||
nextDoubleUnsafe: () => nextIntUnsafe() / 0x1_0000_0000,
|
||||
};
|
||||
}
|
||||
|
||||
function isGitHubCliError(error: unknown): error is GitHubCliError {
|
||||
return (
|
||||
typeof error === "object" &&
|
||||
@@ -3230,41 +3213,6 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("uses Effect Random for implicit progress action ids", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
yield* initRepo(repoDir);
|
||||
fs.writeFileSync(path.join(repoDir, "random-action-id.txt"), "random action id\n");
|
||||
|
||||
const { manager } = yield* makeManager();
|
||||
const events: GitActionProgressEvent[] = [];
|
||||
const seed = 0x5eed_c0de;
|
||||
const expectedActionId = yield* Random.nextUUIDv4.pipe(
|
||||
Effect.provideService(Random.Random, makeDeterministicRandomService(seed)),
|
||||
);
|
||||
|
||||
const result = yield* runStackedAction(
|
||||
manager,
|
||||
{
|
||||
cwd: repoDir,
|
||||
action: "commit",
|
||||
},
|
||||
{
|
||||
progressReporter: {
|
||||
publish: (event) =>
|
||||
Effect.sync(() => {
|
||||
events.push(event);
|
||||
}),
|
||||
},
|
||||
},
|
||||
).pipe(Effect.provideService(Random.Random, makeDeterministicRandomService(seed)));
|
||||
|
||||
assert.equal(result.commit.status, "created");
|
||||
assert.isAbove(events.length, 0);
|
||||
assert.isTrue(events.every((event) => event.actionId === expectedActionId));
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("emits ordered progress events for commit hooks", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Context from "effect/Context";
|
||||
@@ -10,7 +12,6 @@ import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Order from "effect/Order";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Random from "effect/Random";
|
||||
import * as Ref from "effect/Ref";
|
||||
import {
|
||||
GitActionProgressEvent,
|
||||
@@ -535,11 +536,11 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
const sourceControlProvider = (cwd: string) => sourceControlProviders.resolve({ cwd });
|
||||
const serverSettingsService = yield* ServerSettingsService;
|
||||
|
||||
const createProgressEmitter = Effect.fn("GitManager.createProgressEmitter")(function* (
|
||||
const createProgressEmitter = (
|
||||
input: { cwd: string; action: GitStackedAction },
|
||||
options?: GitRunStackedActionOptions,
|
||||
) {
|
||||
const actionId = options?.actionId ?? (yield* Random.nextUUIDv4);
|
||||
) => {
|
||||
const actionId = options?.actionId ?? randomUUID();
|
||||
const reporter = options?.progressReporter;
|
||||
|
||||
const emit = (event: GitActionProgressPayload) =>
|
||||
@@ -556,7 +557,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
actionId,
|
||||
emit,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const configurePullRequestHeadUpstreamBase = Effect.fn("configurePullRequestHeadUpstream")(
|
||||
function* (
|
||||
@@ -1300,8 +1301,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
modelSelection,
|
||||
});
|
||||
|
||||
const bodyFileId = yield* Random.nextUUIDv4;
|
||||
const bodyFile = path.join(tempDir, `t3code-pr-body-${process.pid}-${bodyFileId}.md`);
|
||||
const bodyFile = path.join(tempDir, `t3code-pr-body-${process.pid}-${randomUUID()}.md`);
|
||||
yield* fileSystem
|
||||
.writeFileString(bodyFile, generated.body)
|
||||
.pipe(
|
||||
@@ -1591,7 +1591,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
|
||||
const runStackedAction: GitManagerShape["runStackedAction"] = Effect.fn("runStackedAction")(
|
||||
function* (input, options) {
|
||||
const progress = yield* createProgressEmitter(input, options);
|
||||
const progress = createProgressEmitter(input, options);
|
||||
const currentPhase = yield* Ref.make<Option.Option<GitActionProgressPhase>>(Option.none());
|
||||
|
||||
const runAction = Effect.fn("runStackedAction.runAction")(function* (): Effect.fn.Return<
|
||||
|
||||
@@ -147,7 +147,10 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
|
||||
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
|
||||
import { MessagesTimeline } from "./chat/MessagesTimeline";
|
||||
import { ChatHeader } from "./chat/ChatHeader";
|
||||
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import {
|
||||
getExpandedImagePreviewIdentityKey,
|
||||
type ExpandedImagePreview,
|
||||
} from "./chat/ExpandedImagePreview";
|
||||
import { NoActiveThreadState } from "./NoActiveThreadState";
|
||||
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { ProviderStatusBanner } from "./chat/ProviderStatusBanner";
|
||||
@@ -3773,7 +3776,11 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null}
|
||||
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
|
||||
<ExpandedImageDialog
|
||||
key={getExpandedImagePreviewIdentityKey(expandedImage)}
|
||||
preview={expandedImage}
|
||||
onClose={closeExpandedImage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -727,16 +727,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
prompt,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
}),
|
||||
[
|
||||
composerModelOptions,
|
||||
prompt,
|
||||
selectedInstanceId,
|
||||
selectedModel,
|
||||
selectedProvider,
|
||||
selectedProviderModels,
|
||||
],
|
||||
[composerModelOptions, prompt, selectedModel, selectedProvider, selectedProviderModels],
|
||||
);
|
||||
|
||||
const selectedPromptEffort = composerProviderState.promptEffort;
|
||||
@@ -1025,23 +1018,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
|
||||
const providerTraitsMenuContent = renderProviderTraitsMenuContent({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
const providerTraitsPicker = renderProviderTraitsPicker({
|
||||
provider: selectedProvider,
|
||||
instanceId: selectedInstanceId,
|
||||
...(routeKind === "server" ? { threadRef: routeThreadRef } : {}),
|
||||
...(routeKind === "draft" && draftId ? { draftId } : {}),
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
modelOptions: composerModelOptions?.[selectedProvider],
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { memo, useCallback, useEffect, useEffectEvent, useState } from "react";
|
||||
import { ChevronLeftIcon, ChevronRightIcon, XIcon } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
|
||||
@@ -8,52 +8,65 @@ interface ExpandedImageDialogProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview: initialPreview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [preview, setPreview] = useState(initialPreview);
|
||||
|
||||
// Sync when the parent hands us a new preview reference.
|
||||
useEffect(() => {
|
||||
setPreview(initialPreview);
|
||||
}, [initialPreview]);
|
||||
|
||||
const navigateImage = useCallback((direction: -1 | 1) => {
|
||||
setPreview((existing) => {
|
||||
if (existing.images.length <= 1) return existing;
|
||||
const nextIndex =
|
||||
(existing.index + direction + existing.images.length) % existing.images.length;
|
||||
if (nextIndex === existing.index) return existing;
|
||||
return { ...existing, index: nextIndex };
|
||||
});
|
||||
}, []);
|
||||
function useExpandedImageDialogKeyboardShortcuts(input: {
|
||||
readonly imageCount: number;
|
||||
readonly onClose: () => void;
|
||||
readonly onNavigate: (direction: -1 | 1) => void;
|
||||
}) {
|
||||
const close = useEffectEvent(input.onClose);
|
||||
const navigate = useEffectEvent(input.onNavigate);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onClose();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (preview.images.length <= 1) return;
|
||||
if (input.imageCount <= 1) return;
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigateImage(-1);
|
||||
navigate(-1);
|
||||
return;
|
||||
}
|
||||
if (event.key !== "ArrowRight") return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigateImage(1);
|
||||
navigate(1);
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [navigateImage, onClose, preview.images.length]);
|
||||
}, [close, input.imageCount, navigate]);
|
||||
}
|
||||
|
||||
const item = preview.images[preview.index];
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [navigationOffset, setNavigationOffset] = useState(0);
|
||||
const imageCount = preview.images.length;
|
||||
const activeIndex =
|
||||
imageCount > 0 ? (preview.index + navigationOffset + imageCount) % imageCount : preview.index;
|
||||
|
||||
const navigateImage = useCallback(
|
||||
(direction: -1 | 1) => {
|
||||
setNavigationOffset((offset) => {
|
||||
if (imageCount <= 1) return offset;
|
||||
return offset + direction;
|
||||
});
|
||||
},
|
||||
[imageCount],
|
||||
);
|
||||
|
||||
useExpandedImageDialogKeyboardShortcuts({
|
||||
imageCount,
|
||||
onClose,
|
||||
onNavigate: navigateImage,
|
||||
});
|
||||
|
||||
const item = preview.images[activeIndex];
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
@@ -69,7 +82,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
aria-label="Close image preview"
|
||||
onClick={onClose}
|
||||
/>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
@@ -100,10 +113,10 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
/>
|
||||
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-muted-foreground/80">
|
||||
{item.name}
|
||||
{preview.images.length > 1 ? ` (${preview.index + 1}/${preview.images.length})` : ""}
|
||||
{imageCount > 1 ? ` (${activeIndex + 1}/${imageCount})` : ""}
|
||||
</p>
|
||||
</div>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
|
||||
@@ -8,6 +8,14 @@ export interface ExpandedImagePreview {
|
||||
index: number;
|
||||
}
|
||||
|
||||
export function getExpandedImagePreviewIdentityKey(preview: ExpandedImagePreview): string {
|
||||
const selectedImage = preview.images[preview.index];
|
||||
const selectedImageKey = selectedImage
|
||||
? `${selectedImage.name.length}:${selectedImage.name}:${selectedImage.src.length}:${selectedImage.src}`
|
||||
: "missing";
|
||||
return `${preview.images.length}:${preview.index}:${selectedImageKey}`;
|
||||
}
|
||||
|
||||
export function buildExpandedImagePreview(
|
||||
images: ReadonlyArray<{ id: string; name: string; previewUrl?: string }>,
|
||||
selectedImageId: string,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
@@ -197,7 +196,6 @@ export function shouldRenderTraitsControls(input: {
|
||||
|
||||
export interface TraitsMenuContentProps {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
model: string | null | undefined;
|
||||
prompt: string;
|
||||
@@ -210,7 +208,6 @@ export interface TraitsMenuContentProps {
|
||||
|
||||
export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -231,12 +228,11 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return;
|
||||
}
|
||||
setProviderModelOptions(threadTarget, provider, nextOptions, {
|
||||
...(instanceId ? { instanceId } : {}),
|
||||
model,
|
||||
persistSticky: true,
|
||||
});
|
||||
},
|
||||
[instanceId, model, persistence, provider, setProviderModelOptions],
|
||||
[model, persistence, provider, setProviderModelOptions],
|
||||
);
|
||||
const {
|
||||
descriptors,
|
||||
@@ -347,7 +343,6 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
|
||||
export const TraitsPicker = memo(function TraitsPicker({
|
||||
provider,
|
||||
instanceId,
|
||||
models,
|
||||
model,
|
||||
prompt,
|
||||
@@ -436,7 +431,6 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
<MenuPopup align="start">
|
||||
<TraitsMenuContent
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
model={model}
|
||||
prompt={prompt}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
type ScopedThreadRef,
|
||||
type ServerProviderModel,
|
||||
@@ -36,7 +35,6 @@ export type ComposerProviderState = {
|
||||
|
||||
type TraitsRenderInput = {
|
||||
provider: ProviderDriverKind;
|
||||
instanceId?: ProviderInstanceId;
|
||||
threadRef?: ScopedThreadRef;
|
||||
draftId?: DraftId;
|
||||
model: string;
|
||||
@@ -78,17 +76,8 @@ function renderTraitsControl(
|
||||
Component: typeof TraitsMenuContent | typeof TraitsPicker,
|
||||
input: TraitsRenderInput,
|
||||
): ReactNode {
|
||||
const {
|
||||
provider,
|
||||
instanceId,
|
||||
threadRef,
|
||||
draftId,
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
} = input;
|
||||
const { provider, threadRef, draftId, model, models, modelOptions, prompt, onPromptChange } =
|
||||
input;
|
||||
const hasTarget = threadRef !== undefined || draftId !== undefined;
|
||||
if (
|
||||
!hasTarget ||
|
||||
@@ -99,7 +88,6 @@ function renderTraitsControl(
|
||||
return (
|
||||
<Component
|
||||
provider={provider}
|
||||
{...(instanceId ? { instanceId } : {})}
|
||||
models={models}
|
||||
{...(threadRef ? { threadRef } : {})}
|
||||
{...(draftId ? { draftId } : {})}
|
||||
|
||||
@@ -21,7 +21,6 @@ import { createModelSelection } from "@t3tools/shared/model";
|
||||
// `stickyModelSelectionByProvider` maps are keyed by `ProviderInstanceId`
|
||||
// in production; these aliases keep the legacy-key migration tests concise.
|
||||
const CODEX_INSTANCE = ProviderInstanceId.make("codex");
|
||||
const CODEX_SECONDARY_INSTANCE = ProviderInstanceId.make("codex_secondary");
|
||||
const CLAUDE_AGENT_INSTANCE = ProviderInstanceId.make("claudeAgent");
|
||||
const CURSOR_INSTANCE = ProviderInstanceId.make("cursor");
|
||||
const CODEX_DRIVER = ProviderDriverKind.make("codex");
|
||||
@@ -1202,43 +1201,6 @@ describe("composerDraftStore modelSelection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("stores provider option changes on a selected custom instance", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
store.setProviderModelOptions(
|
||||
threadRef,
|
||||
CODEX_DRIVER,
|
||||
toSelections({ reasoningEffort: "low" }),
|
||||
{
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
model: "gpt-5-codex",
|
||||
persistSticky: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
draftFor(threadId, TEST_ENVIRONMENT_ID)?.modelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.activeProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyActiveProvider).toBe(CODEX_SECONDARY_INSTANCE);
|
||||
expect(useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_INSTANCE]).toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(
|
||||
useComposerDraftStore.getState().stickyModelSelectionByProvider[CODEX_SECONDARY_INSTANCE],
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
instanceId: CODEX_SECONDARY_INSTANCE,
|
||||
options: [{ id: "reasoningEffort", value: "low" }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates only the draft when sticky persistence is disabled", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
|
||||
|
||||
@@ -371,7 +371,6 @@ interface ComposerDraftStoreState {
|
||||
provider: ProviderDriverKind,
|
||||
nextProviderOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
|
||||
options?: {
|
||||
instanceId?: ProviderInstanceId | null | undefined;
|
||||
model?: string | null | undefined;
|
||||
persistSticky?: boolean;
|
||||
},
|
||||
@@ -2457,7 +2456,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
if (normalizedProvider === null) {
|
||||
return;
|
||||
}
|
||||
const instanceKey = options?.instanceId ?? defaultInstanceIdForDriver(normalizedProvider);
|
||||
const instanceKey = defaultInstanceIdForDriver(normalizedProvider);
|
||||
const fallbackModel =
|
||||
normalizeModelSlug(options?.model, normalizedProvider) ??
|
||||
DEFAULT_MODEL_BY_PROVIDER[normalizedProvider] ??
|
||||
@@ -2502,9 +2501,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
const { options: _, ...rest } = stickyBase;
|
||||
nextStickyMap[instanceKey] = rest as ModelSelection;
|
||||
}
|
||||
nextStickyActiveProvider = options.instanceId
|
||||
? instanceKey
|
||||
: (base.activeProvider ?? instanceKey);
|
||||
nextStickyActiveProvider = base.activeProvider ?? instanceKey;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -2517,7 +2514,6 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
|
||||
const nextDraft: ComposerThreadDraftState = {
|
||||
...base,
|
||||
...(options?.instanceId ? { activeProvider: instanceKey } : {}),
|
||||
modelSelectionByProvider: nextMap,
|
||||
};
|
||||
const nextDraftsByThreadKey = { ...state.draftsByThreadKey };
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user