Skip to content
Source
Sign inSign up

thread-provider-switching.ts

24 lines914 Bytes

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows";
3import type { ThreadStructure } from "@t3tools/client-runtime/state/models";
4​
5type ThreadStartMarkers = Pick<
6 EnvironmentThreadShell,
7 "latestRun" | "latestUserMessageAt" | "runtime"
8>;
9​
10function threadShellHasStarted(thread: ThreadStartMarkers | null | undefined): boolean {
11 return Boolean(
12 thread &&
13 (thread.latestRun !== null || thread.latestUserMessageAt !== null || thread.runtime !== null),
14 );
16​
17export function threadAllowsProviderSwitch(input: {
18 readonly thread: ThreadStartMarkers | null | undefined;
19 readonly projection: ThreadStructure | null | undefined;
20}): boolean {
21 return input.projection != null
22 ? threadSupportsProviderHandoff(input.projection)
23 : !threadShellHasStarted(input.thread);