Files
t3code/apps/web/src/threadRoutes.ts
b96308fc5a 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>
2026-04-09 02:05:20 +00:00

60 lines
1.4 KiB
TypeScript

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<Record<"environmentId" | "threadId", string | undefined>>,
): ScopedThreadRef | null {
if (!params.environmentId || !params.threadId) {
return null;
}
return scopeThreadRef(params.environmentId as EnvironmentId, params.threadId as ThreadId);
}
export function resolveThreadRouteTarget(
params: Partial<Record<"environmentId" | "threadId" | "draftId", string | undefined>>,
): 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,
};
}