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:
authored and GitHub committed 2026-04-09 02:05:20 +00:00
1 parent 72b7f90c50
commit b96308fc5a
121 files changed
+10195 -4958

No files matched your search

@@ -1,17 +1,29 @@
import "../../index.css";
import { DEFAULT_SERVER_SETTINGS, type NativeApi, type ServerConfig } from "@t3tools/contracts";
import {
DEFAULT_SERVER_SETTINGS,
EnvironmentId,
type LocalApi,
type ServerConfig,
} from "@t3tools/contracts";
import { page } from "vitest/browser";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { render } from "vitest-browser-react";
import { __resetNativeApiForTests } from "../../nativeApi";
import { __resetLocalApiForTests } from "../../localApi";
import { AppAtomRegistryProvider } from "../../rpc/atomRegistry";
import { resetServerStateForTests, setServerConfigSnapshot } from "../../rpc/serverState";
import { GeneralSettingsPanel } from "./SettingsPanels";
function createBaseServerConfig(): ServerConfig {
return {
environment: {
environmentId: EnvironmentId.makeUnsafe("environment-local"),
label: "Local environment",
platform: { os: "darwin" as const, arch: "arm64" as const },
serverVersion: "0.0.0-test",
capabilities: { repositoryIdentity: true },
},
cwd: "/repo/project",
keybindingsConfigPath: "/repo/project/.t3code-keybindings.json",
keybindings: [],
@@ -32,14 +44,14 @@ function createBaseServerConfig(): ServerConfig {
describe("GeneralSettingsPanel observability", () => {
beforeEach(async () => {
resetServerStateForTests();
await __resetNativeApiForTests();
await __resetLocalApiForTests();
localStorage.clear();
document.body.innerHTML = "";
});
afterEach(async () => {
resetServerStateForTests();
await __resetNativeApiForTests();
await __resetLocalApiForTests();
document.body.innerHTML = "";
});
@@ -68,12 +80,12 @@ describe("GeneralSettingsPanel observability", () => {
});
it("opens the logs folder in the preferred editor", async () => {
const openInEditor = vi.fn<NativeApi["shell"]["openInEditor"]>().mockResolvedValue(undefined);
const openInEditor = vi.fn<LocalApi["shell"]["openInEditor"]>().mockResolvedValue(undefined);
window.nativeApi = {
shell: {
openInEditor,
},
} as unknown as NativeApi;
} as unknown as LocalApi;
setServerConfigSnapshot(createBaseServerConfig());
@@ -13,11 +13,12 @@ import { useQueryClient } from "@tanstack/react-query";
import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
PROVIDER_DISPLAY_NAMES,
type ScopedThreadRef,
type ProviderKind,
type ServerProvider,
type ServerProviderModel,
ThreadId,
} from "@t3tools/contracts";
import { scopeThreadRef } from "@t3tools/client-runtime";
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
import { normalizeModelSlug } from "@t3tools/shared/model";
import { Equal } from "effect";
@@ -45,8 +46,12 @@ import {
getCustomModelOptionsByProvider,
resolveAppModelSelectionState,
} from "../../modelSelection";
import { ensureNativeApi, readNativeApi } from "../../nativeApi";
import { useStore } from "../../store";
import { ensureLocalApi, readLocalApi } from "../../localApi";
import {
selectProjectsAcrossEnvironments,
selectThreadsAcrossEnvironments,
useStore,
} from "../../store";
import { formatRelativeTime, formatRelativeTimeLabel } from "../../timestampFormat";
import { cn } from "../../lib/utils";
import { Button } from "../ui/button";
@@ -496,8 +501,8 @@ export function useSettingsRestore(onRestored?: () => void) {
const restoreDefaults = useCallback(async () => {
if (changedSettingLabels.length === 0) return;
const api = readNativeApi();
const confirmed = await (api ?? ensureNativeApi()).dialogs.confirm(
const api = readLocalApi();
const confirmed = await (api ?? ensureLocalApi()).dialogs.confirm(
["Restore default settings?", `This will reset: ${changedSettingLabels.join(", ")}.`].join(
"\n",
),
@@ -554,7 +559,7 @@ export function GeneralSettingsPanel() {
if (refreshingRef.current) return;
refreshingRef.current = true;
setIsRefreshingProviders(true);
void ensureNativeApi()
void ensureLocalApi()
.server.refreshProviders()
.catch((error: unknown) => {
console.warn("Failed to refresh providers", error);
@@ -614,7 +619,7 @@ export function GeneralSettingsPanel() {
return;
}
void ensureNativeApi()
void ensureLocalApi()
.shell.openInEditor(path, editor)
.catch((error) => {
setOpenPathErrorByTarget((existing) => ({
@@ -1479,20 +1484,10 @@ export function GeneralSettingsPanel() {
}
export function ArchivedThreadsPanel() {
const projectIds = useStore((store) => store.projectIds);
const projectById = useStore((store) => store.projectById);
const threadIds = useStore((store) => store.threadIds);
const threadShellById = useStore((store) => store.threadShellById);
const projects = useStore(selectProjectsAcrossEnvironments);
const threads = useStore(selectThreadsAcrossEnvironments);
const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();
const archivedGroups = useMemo(() => {
const projects = projectIds.flatMap((projectId) => {
const project = projectById[projectId];
return project ? [project] : [];
});
const threads = threadIds.flatMap((threadId) => {
const thread = threadShellById[threadId];
return thread ? [thread] : [];
});
return projects
.map((project) => ({
project,
@@ -1505,11 +1500,11 @@ export function ArchivedThreadsPanel() {
}),
}))
.filter((group) => group.threads.length > 0);
}, [projectById, projectIds, threadIds, threadShellById]);
}, [projects, threads]);
const handleArchivedThreadContextMenu = useCallback(
async (threadId: ThreadId, position: { x: number; y: number }) => {
const api = readNativeApi();
async (threadRef: ScopedThreadRef, position: { x: number; y: number }) => {
const api = readLocalApi();
if (!api) return;
const clicked = await api.contextMenu.show(
[
@@ -1521,7 +1516,7 @@ export function ArchivedThreadsPanel() {
if (clicked === "unarchive") {
try {
await unarchiveThread(threadId);
await unarchiveThread(threadRef);
} catch (error) {
toastManager.add({
type: "error",
@@ -1533,7 +1528,7 @@ export function ArchivedThreadsPanel() {
}
if (clicked === "delete") {
await confirmAndDeleteThread(threadId);
await confirmAndDeleteThread(threadRef);
}
},
[confirmAndDeleteThread, unarchiveThread],
@@ -1566,10 +1561,13 @@ export function ArchivedThreadsPanel() {
className="flex items-center justify-between gap-3 border-t border-border px-4 py-3 first:border-t-0 sm:px-5"
onContextMenu={(event) => {
event.preventDefault();
void handleArchivedThreadContextMenu(thread.id, {
x: event.clientX,
y: event.clientY,
});
void handleArchivedThreadContextMenu(
scopeThreadRef(thread.environmentId, thread.id),
{
x: event.clientX,
y: event.clientY,
},
);
}}
>
<div className="min-w-0 flex-1">
@@ -1586,13 +1584,16 @@ export function ArchivedThreadsPanel() {
size="sm"
className="h-7 shrink-0 cursor-pointer gap-1.5 px-2.5"
onClick={() =>
void unarchiveThread(thread.id).catch((error) => {
toastManager.add({
type: "error",
title: "Failed to unarchive thread",
description: error instanceof Error ? error.message : "An error occurred.",
});
})
void unarchiveThread(scopeThreadRef(thread.environmentId, thread.id)).catch(
(error) => {
toastManager.add({
type: "error",
title: "Failed to unarchive thread",
description:
error instanceof Error ? error.message : "An error occurred.",
});
},
)
}
>
<ArchiveX className="size-3.5" />