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 OrchestrationV2LinkedSender,
17 ScheduledTaskId,
18 ThreadId,
19} from "@t3tools/contracts";
20import type {
21 EnvironmentProject,
22 EnvironmentThreadShell,
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// Render unknown attachment contracts as inert rows so newer servers cannot crash older clients.
56export type ChatUnknownAttachment = ContractChatUnknownAttachment;
57
58export type ChatAttachment = ChatImageAttachment | ChatFileAttachment | ChatUnknownAttachment;
59
60export function isImageAttachment(attachment: ChatAttachment): attachment is ChatImageAttachment {
61 // Legacy file attachments can be images; unknown types must never be reclassified by name.
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 // Keep disjoint from isImageAttachment so independently filtered sets do not render legacy images twice.
68 return attachment.type === "file" && !isImageAttachment(attachment);
69}
70
71export function isVideoAttachment(attachment: ChatFileAttachment): boolean {
72 return videoMimeType(attachment) !== null;
73}
74
75export interface ChatMessage {
76 readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
77 readonly id: MessageId;
78 readonly role: "user" | "assistant" | "system";
79 readonly text: string;
80 readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
81 readonly runId: RunId | null;
82 readonly streaming: boolean;
83 readonly createdBy?: OrchestrationV2Actor;
84 readonly creationSource?: OrchestrationV2CreationSource;
85 readonly scheduledTaskId?: ScheduledTaskId;
86 readonly senderThreadId?: ThreadId;
87 readonly linkedSender?: OrchestrationV2LinkedSender;
88 readonly idleCompaction?: import("@t3tools/contracts").OrchestrationV2IdleCompaction;
89 readonly createdAt: string;
90 readonly updatedAt: string;
91 readonly inputIntent?: OrchestrationV2UserMessageInputIntent | undefined;
92}
93
94export interface ProposedPlan {
95 readonly id: PlanId;
96 readonly runId: RunId | null;
97 readonly planMarkdown: string;
98 readonly status: OrchestrationV2PlanArtifact["status"];
99 readonly createdAt: string;
100 readonly updatedAt: string;
101}
102export type TurnDiffFileChange = ThreadCheckpointSummary["files"][number];
103export type TurnDiffSummary = ThreadCheckpointSummary;
104
105export type Project = EnvironmentProject;
106export type Thread = EnvironmentThreadShell;
107export type ThreadShell = EnvironmentThreadShell;
108
109export type SidebarThreadSummary = EnvironmentThreadShell;
110export type ThreadSession = ThreadRuntimeSummary;