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>
60 lines
1.4 KiB
TypeScript
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,
|
|
};
|
|
}
|