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

models.ts

53 lines1.4 KB

1import type {
2 EnvironmentId,
3 OrchestrationMessage,
4 OrchestrationProjectShell,
5 OrchestrationShellSnapshot,
6 OrchestrationThread,
7 OrchestrationThreadShell,
8 ThreadId,
9} from "@t3tools/contracts";
10​
11export interface EnvironmentProject extends OrchestrationProjectShell {
12 readonly environmentId: EnvironmentId;
14​
15export interface EnvironmentThreadShell extends OrchestrationThreadShell {
16 readonly environmentId: EnvironmentId;
18​
19export type EnvironmentMessage = OrchestrationMessage;
20​
21export interface EnvironmentThread extends OrchestrationThread {
22 readonly environmentId: EnvironmentId;
24​
25export function scopeProject(
26 environmentId: EnvironmentId,
27 project: OrchestrationProjectShell,
28): EnvironmentProject {
29 return { ...project, environmentId };
31​
32export function scopeThreadShell(
33 environmentId: EnvironmentId,
34 thread: OrchestrationThreadShell,
35): EnvironmentThreadShell {
36 return { ...thread, environmentId };
38​
39export function scopeThread(
40 environmentId: EnvironmentId,
41 thread: OrchestrationThread,
42): EnvironmentThread {
43 return { ...thread, environmentId };
45​
46export function selectEnvironmentThreadShell(
47 snapshot: OrchestrationShellSnapshot | null,
48 environmentId: EnvironmentId,
49 threadId: ThreadId,
50): EnvironmentThreadShell | null {
51 const thread = snapshot?.threads.find((candidate) => candidate.id === threadId) ?? null;
52 return thread ? scopeThreadShell(environmentId, thread) : null;