Open History to see the last commit
1import { imageMimeType } from "@t3tools/shared/image";
2import type {
3 ChatFileAttachment as ContractChatFileAttachment,
4 ChatImageAttachment as ContractChatImageAttachment,
5 ChatUnknownAttachment as ContractChatUnknownAttachment,
6 MessageId,
7 OrchestrationV2Actor,
8 OrchestrationV2CreationSource,
9 OrchestrationV2PlanArtifact,
10 OrchestrationV2UserMessageInputIntent,
11 PlanId,
12 ProjectScript as ContractProjectScript,
13 ProviderInteractionMode,
14 RunId,
15 RuntimeMode,
16 ScheduledTaskId,
17 ThreadId,
18} from "@t3tools/contracts";
19import type {
20 EnvironmentProject,
21 EnvironmentThreadShell,
22 ThreadRunSummary,
23 ThreadRuntimeSummary,
24} from "@t3tools/client-runtime/state/shell";
25import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
26import { videoMimeType } from "@t3tools/shared/video";
27
28export { videoMimeType } from "@t3tools/shared/video";
29
30export type SessionPhase = "disconnected" | "connecting" | "ready" | "running";
31export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
32
33export const DEFAULT_INTERACTION_MODE: ProviderInteractionMode = "default";
34export const DEFAULT_THREAD_TERMINAL_HEIGHT = 280;
35export const DEFAULT_THREAD_TERMINAL_ID = "term-1";
36export const MAX_TERMINALS_PER_GROUP = 4;
37export type ProjectScript = ContractProjectScript;
38
39export interface ThreadTerminalGroup {
40 id: string;
41 terminalIds: string[];
42 splitDirection?: "horizontal" | "vertical";
43}
44
45export interface ChatImageAttachment extends ContractChatImageAttachment {
46 readonly previewUrl?: string;
47}
48
49export interface ChatFileAttachment extends ContractChatFileAttachment {
50 readonly previewUrl?: string;
51 readonly downloadable?: boolean;
52 readonly htmlRender?: boolean;
53}
54
55// Attachment types this build does not know pass through with the contract
56// shape. The UI renders them as inert rows so a newer server cannot crash an
57// older client.
58export type ChatUnknownAttachment = ContractChatUnknownAttachment;
59
60export type ChatAttachment = ChatImageAttachment | ChatFileAttachment | ChatUnknownAttachment;
61
62// The union has an open member (`type: string`), so a literal comparison does
63// not narrow. Use these guards wherever type-specific fields are read.
64export function isImageAttachment(attachment: ChatAttachment): attachment is ChatImageAttachment {
65 // Messages sent before pictures were typed by content carry `file`; they are still
66 // pictures, and reading them as such is what lets them render instead of listing. Only
67 // `file` is reclassified: an attachment type this client does not know yet is not a
68 // picture by default, whatever its name says.
69 if (attachment.type === "image") return true;
70 return attachment.type === "file" && imageMimeType(attachment) !== null;
71}
72
73export function isFileAttachment(attachment: ChatAttachment): attachment is ChatFileAttachment {
74 // Disjoint from `isImageAttachment` on purpose: a legacy `file` carrying an image reads as a
75 // picture, and callers filter both sets independently, so overlap renders it twice.
76 return attachment.type === "file" && !isImageAttachment(attachment);
77}
78
79export function isVideoAttachment(attachment: ChatFileAttachment): boolean {
80 return videoMimeType(attachment) !== null;
81}
82
83export interface ChatMessage {
84 readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
85 readonly id: MessageId;
86 readonly role: "user" | "assistant" | "system";
87 readonly text: string;
88 readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
89 readonly runId: RunId | null;
90 readonly streaming: boolean;
91 readonly createdBy?: OrchestrationV2Actor;
92 readonly creationSource?: OrchestrationV2CreationSource;
93 readonly scheduledTaskId?: ScheduledTaskId;
94 readonly senderThreadId?: ThreadId;
95 readonly createdAt: string;
96 readonly updatedAt: string;
97 readonly inputIntent?: OrchestrationV2UserMessageInputIntent | undefined;
98}
99
100export interface ProposedPlan {
101 readonly id: PlanId;
102 readonly runId: RunId | null;
103 readonly planMarkdown: string;
104 readonly status: OrchestrationV2PlanArtifact["status"];
105 readonly createdAt: string;
106 readonly updatedAt: string;
107}
108export type TurnDiffFileChange = ThreadCheckpointSummary["files"][number];
109export type TurnDiffSummary = ThreadCheckpointSummary;
110
111export type Project = EnvironmentProject;
112export type Thread = EnvironmentThreadShell;
113export type ThreadShell = EnvironmentThreadShell;
114
115export type SidebarThreadSummary = EnvironmentThreadShell;
116export type ThreadSession = ThreadRuntimeSummary;