Open History to see the last commit
1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { useMemo } from "react";
3
4import { useAssetUrl } from "../../state/assets";
5import { resolveWorkspaceFilePath } from "./filePath";
6
7export function useWorkspaceFileAssetUrl(props: {
8 readonly cwd: string | null;
9 readonly environmentId: EnvironmentId | null;
10 readonly relativePath: string | null;
11 readonly threadId: ThreadId | null;
12}) {
13 const absolutePath = useMemo(
14 () =>
15 props.cwd !== null && props.relativePath !== null
16 ? resolveWorkspaceFilePath(props.cwd, props.relativePath)
17 : null,
18 [props.cwd, props.relativePath],
19 );
20
21 return useAssetUrl(
22 props.environmentId,
23 absolutePath !== null && props.threadId !== null
24 ? {
25 _tag: "workspace-file",
26 threadId: props.threadId,
27 path: absolutePath,
28 }
29 : null,
30 );
31}