@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 32 lines 1.36 KB
Raw
1 import type { DiscoveredLocalServer, ScopedThreadRef } from "@t3tools/contracts";
2 import {
3 mapAtomCommandResult,
4 type AtomCommandResult,
5 } from "@t3tools/client-runtime/state/runtime";
6
7 import { resolveDiscoveredServerUrl } from "~/browser/browserTargetResolver";
8 import type { BrowserSettingsReadError, OpenPreviewMutation } from "~/browser/openFileInPreview";
9 import { recordVisitForThread } from "~/browserHistoryStore";
10 import { useRightPanelStore } from "~/rightPanelStore";
11 import { openPreviewSession } from "./openPreviewSession";
12 import { previewRuntimeFor } from "~/browser/previewRuntime";
13
14 export async function openDiscoveredPort<E>(input: {
15 readonly threadRef: ScopedThreadRef;
16 readonly port: DiscoveredLocalServer;
17 readonly openPreview: OpenPreviewMutation<E>;
18 }): Promise<AtomCommandResult<void, E | BrowserSettingsReadError>> {
19 const resolvedUrl =
20 previewRuntimeFor(input.threadRef.environmentId) === "server"
21 ? input.port.url
22 : resolveDiscoveredServerUrl(input.threadRef.environmentId, input.port.url);
23 const result = await openPreviewSession({
24 openPreview: input.openPreview,
25 threadRef: input.threadRef,
26 url: resolvedUrl,
27 });
28 return mapAtomCommandResult(result, (snapshot) => {
29 recordVisitForThread(input.threadRef, input.port.url);
30 useRightPanelStore.getState().openBrowser(input.threadRef, snapshot.tabId);
31 });
32 }