Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-provider-switching.ts

24 lines928 Bytes

1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows";
3import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts";
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: OrchestrationV2ThreadProjection | null | undefined;
20}): boolean {
21 return input.projection != null
22 ? threadSupportsProviderHandoff(input.projection)
23 : !threadShellHasStarted(input.thread);