39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { T3_PROJECT_FILE_NAME, type EnvironmentId, type ThreadEnvMode } from "@t3tools/contracts";
|
|
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
|
|
import { executeAtomQuery } from "@t3tools/client-runtime/state/runtime";
|
|
|
|
import {
|
|
getProjectFileQueryAtom,
|
|
resolveProjectFileQueryData,
|
|
} from "~/components/files/projectFilesQueryState";
|
|
import { appAtomRegistry } from "~/rpc/atomRegistry";
|
|
|
|
/**
|
|
* Read `defaultThreadEnvMode` from the project's checked-in `t3.json`.
|
|
*
|
|
* Imperative counterpart to `useT3ProjectFileScripts` for the new-thread
|
|
* path, which resolves defaults at call time rather than render time. The
|
|
* file query atom caches per (environment, cwd), so repeat calls don't
|
|
* re-fetch. Optimistic in-app writes overlay the query result, matching what
|
|
* `useProjectFileQuery` renders. Missing, truncated, or invalid files
|
|
* resolve to null.
|
|
*/
|
|
export async function readT3ProjectFileDefaultThreadEnvMode(
|
|
environmentId: EnvironmentId,
|
|
workspaceRoot: string,
|
|
): Promise<ThreadEnvMode | null> {
|
|
const result = await executeAtomQuery(
|
|
appAtomRegistry,
|
|
getProjectFileQueryAtom(environmentId, workspaceRoot, T3_PROJECT_FILE_NAME),
|
|
{ reportDefect: false, reportFailure: false },
|
|
);
|
|
const data = resolveProjectFileQueryData(
|
|
environmentId,
|
|
workspaceRoot,
|
|
T3_PROJECT_FILE_NAME,
|
|
result._tag === "Success" ? result.value : null,
|
|
);
|
|
if (data === null || data.truncated) return null;
|
|
return parseT3ProjectFile(data.contents)?.defaultThreadEnvMode ?? null;
|
|
}
|