The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; |
| 2 | import { threadSupportsProviderHandoff } from "@t3tools/client-runtime/state/thread-workflows"; |
| 3 | import type { ThreadStructure } from "@t3tools/client-runtime/state/models"; |
| 4 | |
| 5 | type ThreadStartMarkers = Pick< |
| 6 | EnvironmentThreadShell, |
| 7 | "latestRun" | "latestUserMessageAt" | "runtime" |
| 8 | >; |
| 9 | |
| 10 | function threadShellHasStarted(thread: ThreadStartMarkers | null | undefined): boolean { |
| 11 | return Boolean( |
| 12 | thread && |
| 13 | (thread.latestRun !== null || thread.latestUserMessageAt !== null || thread.runtime !== null), |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | export 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); |
| 24 | } |