import { scopeThreadRef } from "@t3tools/client-runtime"; import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts"; import type { DraftId } from "./composerDraftStore"; export type ThreadRouteTarget = | { kind: "server"; threadRef: ScopedThreadRef; } | { kind: "draft"; draftId: DraftId; }; export function buildThreadRouteParams(ref: ScopedThreadRef): { environmentId: EnvironmentId; threadId: ThreadId; } { return { environmentId: ref.environmentId, threadId: ref.threadId, }; } export function buildDraftThreadRouteParams(draftId: DraftId): { draftId: DraftId; } { return { draftId }; } export function resolveThreadRouteRef( params: Partial>, ): ScopedThreadRef | null { if (!params.environmentId || !params.threadId) { return null; } return scopeThreadRef(params.environmentId as EnvironmentId, params.threadId as ThreadId); } export function resolveThreadRouteTarget( params: Partial>, ): ThreadRouteTarget | null { if (params.environmentId && params.threadId) { return { kind: "server", threadRef: scopeThreadRef(params.environmentId as EnvironmentId, params.threadId as ThreadId), }; } if (!params.draftId) { return null; } return { kind: "draft", draftId: params.draftId as DraftId, }; }