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

types.ts

124 lines4.7 KB

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";
44​
45export interface ChatImageAttachment extends ContractChatImageAttachment {
46 readonly previewUrl?: string;
48​
49export interface ChatFileAttachment extends ContractChatFileAttachment {
50 readonly previewUrl?: string;
51 readonly downloadable?: boolean;
53​
54// Attachment types this build does not know pass through with the contract
55// shape. The UI renders them as inert rows so a newer server cannot crash an
56// older client.
57export type ChatUnknownAttachment = ContractChatUnknownAttachment;
58​
59export type ChatAttachment = ChatImageAttachment | ChatFileAttachment | ChatUnknownAttachment;
60​
61// The union has an open member (`type: string`), so a literal comparison does
62// not narrow. Use these guards wherever type-specific fields are read.
63export function isImageAttachment(attachment: ChatAttachment): attachment is ChatImageAttachment {
64 // Messages sent before pictures were typed by content carry `file`; they are still
65 // pictures, and reading them as such is what lets them render instead of listing. Only
66 // `file` is reclassified: an attachment type this client does not know yet is not a
67 // picture by default, whatever its name says.
68 if (attachment.type === "image") return true;
69 return attachment.type === "file" && imageMimeType(attachment) !== null;
71​
72export function isFileAttachment(attachment: ChatAttachment): attachment is ChatFileAttachment {
73 // Disjoint from `isImageAttachment` on purpose: a legacy `file` carrying an image reads as a
74 // picture, and callers filter both sets independently, so overlap renders it twice.
75 return attachment.type === "file" && !isImageAttachment(attachment);
77​
78export function isVideoAttachment(attachment: ChatFileAttachment): boolean {
79 return videoMimeType(attachment) !== null;
81​
82export function isBrowserPreviewAttachment(attachment: ChatFileAttachment): boolean {
83 const mimeType = attachment.mimeType.split(";", 1)[0]?.trim().toLowerCase();
84 return (
85 /\.(?:html?|pdf)$/i.test(attachment.name) ||
86 mimeType === "application/pdf" ||
87 mimeType === "text/html"
88 );
90​
91export interface ChatMessage {
92 readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
93 readonly id: MessageId;
94 readonly role: "user" | "assistant" | "system";
95 readonly text: string;
96 readonly attachments?: ReadonlyArray<ChatAttachment> | undefined;
97 readonly runId: RunId | null;
98 readonly streaming: boolean;
99 readonly createdBy?: OrchestrationV2Actor;
100 readonly creationSource?: OrchestrationV2CreationSource;
101 readonly scheduledTaskId?: ScheduledTaskId;
102 readonly senderThreadId?: ThreadId;
103 readonly createdAt: string;
104 readonly updatedAt: string;
105 readonly inputIntent?: OrchestrationV2UserMessageInputIntent | undefined;
107​
108export interface ProposedPlan {
109 readonly id: PlanId;
110 readonly runId: RunId | null;
111 readonly planMarkdown: string;
112 readonly status: OrchestrationV2PlanArtifact["status"];
113 readonly createdAt: string;
114 readonly updatedAt: string;
116export type TurnDiffFileChange = ThreadCheckpointSummary["files"][number];
117export type TurnDiffSummary = ThreadCheckpointSummary;
118​
119export type Project = EnvironmentProject;
120export type Thread = EnvironmentThreadShell;
121export type ThreadShell = EnvironmentThreadShell;
122​
123export type SidebarThreadSummary = EnvironmentThreadShell;
124export type ThreadSession = ThreadRuntimeSummary;