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 OrchestrationCheckpointFile,
7 OrchestrationCheckpointSummary,
8 OrchestrationMessage,
9 OrchestrationProposedPlan,
10 OrchestrationSession,
11 ProjectScript as ContractProjectScript,
12 ProviderInteractionMode,
13 RuntimeMode,
14} from "@t3tools/contracts";
15import type {
16 EnvironmentProject,
17 EnvironmentThread,
18 EnvironmentThreadShell,
19} from "@t3tools/client-runtime/state/shell";
20import { videoMimeType } from "@t3tools/shared/video";
21
22export { videoMimeType } from "@t3tools/shared/video";
23
24export type SessionPhase = "disconnected" | "connecting" | "ready" | "running";
25export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
26
27export const DEFAULT_INTERACTION_MODE: ProviderInteractionMode = "default";
28export const DEFAULT_THREAD_TERMINAL_HEIGHT = 280;
29export const DEFAULT_THREAD_TERMINAL_ID = "term-1";
30export const MAX_TERMINALS_PER_GROUP = 4;
31export type ProjectScript = ContractProjectScript;
32
33export interface ThreadTerminalGroup {
34 id: string;
35 terminalIds: string[];
36 splitDirection?: "horizontal" | "vertical";
37}
38
39export interface ChatImageAttachment extends ContractChatImageAttachment {
40 readonly previewUrl?: string;
41}
42
43export interface ChatFileAttachment extends ContractChatFileAttachment {
44 readonly previewUrl?: string;
45 readonly downloadable?: boolean;
46}
47
48// Attachment types this build does not know pass through with the contract
49// shape. The UI renders them as inert rows so a newer server cannot crash an
50// older client.
51export type ChatUnknownAttachment = ContractChatUnknownAttachment;
52
53export type ChatAttachment = ChatImageAttachment | ChatFileAttachment | ChatUnknownAttachment;
54
55// The union has an open member (`type: string`), so a literal comparison does
56// not narrow. Use these guards wherever type-specific fields are read.
57export function isImageAttachment(attachment: ChatAttachment): attachment is ChatImageAttachment {
58 // Messages sent before pictures were typed by content carry `file`; they are still
59 // pictures, and reading them as such is what lets them render instead of listing. Only
60 // `file` is reclassified: an attachment type this client does not know yet is not a
61 // picture by default, whatever its name says.
62 if (attachment.type === "image") return true;
63 return attachment.type === "file" && imageMimeType(attachment) !== null;
64}
65
66export function isFileAttachment(attachment: ChatAttachment): attachment is ChatFileAttachment {
67 // Disjoint from `isImageAttachment` on purpose: a legacy `file` carrying an image reads as a
68 // picture, and callers filter both sets independently, so overlap renders it twice.
69 return attachment.type === "file" && !isImageAttachment(attachment);
70}
71
72export function isVideoAttachment(attachment: ChatFileAttachment): boolean {
73 return videoMimeType(attachment) !== null;
74}
75
76export interface ChatMessage extends Omit<OrchestrationMessage, "attachments"> {
77 readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
78}
79
80export type ProposedPlan = OrchestrationProposedPlan;
81export type TurnDiffFileChange = OrchestrationCheckpointFile;
82export type TurnDiffSummary = OrchestrationCheckpointSummary;
83
84export type Project = EnvironmentProject;
85export type Thread = EnvironmentThread;
86export type ThreadShell = EnvironmentThreadShell;
87
88export type SidebarThreadSummary = EnvironmentThreadShell;
89export type ThreadSession = OrchestrationSession;