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

types.ts

104 lines3.5 KB

1import type {
2 ChatFileAttachment as ContractChatFileAttachment,
3 ChatImageAttachment as ContractChatImageAttachment,
4 ChatUnknownAttachment as ContractChatUnknownAttachment,
5 OrchestrationCheckpointFile,
6 OrchestrationCheckpointSummary,
7 OrchestrationLatestTurn,
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";
20​
21export type SessionPhase = "disconnected" | "connecting" | "ready" | "running";
22export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
23​
24export const DEFAULT_INTERACTION_MODE: ProviderInteractionMode = "default";
25export const DEFAULT_THREAD_TERMINAL_HEIGHT = 280;
26export const DEFAULT_THREAD_TERMINAL_ID = "term-1";
27export const MAX_TERMINALS_PER_GROUP = 4;
28export type ProjectScript = ContractProjectScript;
29​
30export interface ThreadTerminalGroup {
31 id: string;
32 terminalIds: string[];
33 splitDirection?: "horizontal" | "vertical";
35​
36export interface ChatImageAttachment extends ContractChatImageAttachment {
37 readonly previewUrl?: string;
39​
40export interface ChatFileAttachment extends ContractChatFileAttachment {
41 readonly previewUrl?: string;
42 readonly downloadable?: boolean;
44​
45// Attachment types this build does not know pass through with the contract
46// shape. The UI renders them as inert rows so a newer server cannot crash an
47// older client.
48export type ChatUnknownAttachment = ContractChatUnknownAttachment;
49​
50export type ChatAttachment = ChatImageAttachment | ChatFileAttachment | ChatUnknownAttachment;
51​
52// The union has an open member (`type: string`), so a literal comparison does
53// not narrow. Use these guards wherever type-specific fields are read.
54export function isImageAttachment(attachment: ChatAttachment): attachment is ChatImageAttachment {
55 return attachment.type === "image";
57​
58export function isFileAttachment(attachment: ChatAttachment): attachment is ChatFileAttachment {
59 return attachment.type === "file";
61​
62const VIDEO_MIME_TYPE_BY_EXTENSION: Readonly<Record<string, string>> = {
63 avi: "video/x-msvideo",
64 m4v: "video/mp4",
65 mkv: "video/x-matroska",
66 mov: "video/quicktime",
67 mp4: "video/mp4",
68 ogv: "video/ogg",
69 webm: "video/webm",
70};
71​
72export function videoMimeType(
73 attachment: Pick<ChatFileAttachment, "name" | "mimeType">,
74): string | null {
75 const mimeType = attachment.mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
76 if (mimeType.startsWith("video/")) return mimeType;
77 const dotIndex = attachment.name.lastIndexOf(".");
78 return dotIndex < 0
79 ? null
80 : (VIDEO_MIME_TYPE_BY_EXTENSION[attachment.name.slice(dotIndex + 1).toLowerCase()] ?? null);
82​
83export function isVideoAttachment(attachment: ChatFileAttachment): boolean {
84 return videoMimeType(attachment) !== null;
86​
87export interface ChatMessage extends Omit<OrchestrationMessage, "attachments"> {
88 readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
90​
91export type ProposedPlan = OrchestrationProposedPlan;
92export type TurnDiffFileChange = OrchestrationCheckpointFile;
93export type TurnDiffSummary = OrchestrationCheckpointSummary;
94​
95export type Project = EnvironmentProject;
96export type Thread = EnvironmentThread;
97export type ThreadShell = EnvironmentThreadShell;
98​
99export interface ThreadTurnState {
100 latestTurn: OrchestrationLatestTurn | null;
102​
103export type SidebarThreadSummary = EnvironmentThreadShell;
104export type ThreadSession = OrchestrationSession;