/** * A chunk where the value contains actual data stored * inside `data_value`. */ type Data = 'data'; /** * A chunk where the value contains response from LLM * stored as a string inside `data_value`. */ type Response = 'response'; /** * A dummy chunk that indicates the DPO is still processing * user documents. */ type ProcessingDocument = 'processing_document'; /** * A dummy chunk that indicates cache hit, which will make the * API to response from cache. */ type Cached = 'cached'; /** * Available variants for chunks from API. Each type should * be handled separately. */ export type GLChatMessageStatus = Data | Response | ProcessingDocument | Cached; /** * Streamed data sent from GLChat API during message manipulation process. */ export type GLChatMessageChunk = GLChatMessageDataChunk | GLChatMessageResponseChunk | GLChatMessageBaseChunk; /** * Step is currently in progress. */ type Running = 'running'; /** * Step has been completed successfully. */ type Finished = 'finished'; /** * Step was stopped either prematurely or by user demand. */ type Stopped = 'stopped'; /** * Available statuses for a step indicator. Each status corresponds * to a specific visual state in the UI. * */ export type StepIndicatorStatus = Running | Finished | Stopped; interface GLChatMessageBaseChunk { /** * Conversation identifier where the message belongs to. */ conversation_id: string | null; /** * Identifier of the user message. * * If the current message is an assistant message, this value * will be the ID of the user message that triggers the response. */ user_message_id: string | null; /** * Identifier of the assistant message. * * If the current message is a user message, this value * will be the ID of the assistant message that complements the request. */ assistant_message_id: string | null; /** * Unix timestamp when the chunk is created. */ created_date: number; /** * An enum that denotes the type of the chunk. */ status: T; message: unknown; } /** * A chunk that represents data related to the message manipulation process * that isn't the response itself. */ interface GLChatMessageDataChunk extends GLChatMessageBaseChunk { /** * Actual data content of the chunk. */ message: | GLChatReferenceChunk | GLChatAttachmentChunk | GLChatRelatedQuestionChunk | GLChatDeanonymizationChunk | GLChatMediaChunk | GLChatProcessChunk | GLChatThinkingChunk | GLChatThinkingStartChunk | GLChatThinkingEndChunk | GLChatActivityChunk; } /** * Chunk that represents actual LLM or agent response. */ interface GLChatMessageResponseChunk extends GLChatMessageBaseChunk { /** * Response of LLM or agent. */ message: string; } /** * Chunk that represents references that may exist in the actual response string. */ export interface GLChatReferenceChunk { data_type: 'reference'; /** * List of references mentioned in the response string. */ data_value: string[]; } /** * Chunk that represents attachment binary of the message. */ export interface GLChatAttachmentChunk { data_type: 'attachments'; /** * List of attachments of the message. */ data_value: GLChatAttachment[]; } /** * Chunk that represents questions related with the query * that triggers the chunk. */ export interface GLChatRelatedQuestionChunk { data_type: 'related'; /** * List of related questions. */ data_value: string[]; } /** * Chunk that represents anonymization data of the message. */ export interface GLChatDeanonymizationChunk { data_type: 'deanonymized_data'; /** * Anonymization result of the message. */ data_value: DeanomymizedData; } /** * Chunk that represents key-value of media inside actual contents * represented by `[_]` string. */ export interface GLChatMediaChunk { data_type: 'media_mapping'; /** * Key-value mapping of media that may exist inside actual contents * of the message. */ data_value: Record; } /** * Chunk that represents process of the message-manipulation request. */ export interface GLChatProcessChunk { data_type: 'process'; /** * Current process of the request. */ data_value: GLChatProcess; } /** * Chunk that represents process of activity for deep research */ export interface GLChatActivityChunk { data_type: 'activity'; /** * Label of the activity */ data_value: { message: string }; } /** * Chunk that represents the start of thinking process for deep research */ export interface GLChatThinkingStartChunk { data_type: 'thinking_start'; /** * Thinking identifier, which will be used to accumulate thinking step */ id: string; } /** * Chunk that represents the end of thinking process for deep research */ export interface GLChatThinkingEndChunk { data_type: 'thinking_end'; /** * Thinking identifier, which will be used to accumulate thinking step */ id: string; } /** * Chunk that represents process of thinking for deep research */ export interface GLChatThinkingChunk { data_type: 'thinking'; /** * Current process of thinking or browser use */ data_value: string | GLChatIframeThinkingChunk; /** * Thinking identifier, which will be used to accumulate thinking step */ id: string; } /** * Chunk that represents the activity of URL visit during browser use */ export interface GLChatIframeThinkingChunk { /** * URL that is visited by the browser use agent */ url?: string; /** * Label for display use */ value: string; } /** * Data wrapper for deanonymized_message chunk. * * Stores both user and assistant plus their actual content mapped * in key-value objects. */ interface DeanomymizedData { /** * Deanonymization data for user message that triggers the request */ user_message: DeanonymizedMessage; /** * Deanonymization data for assistant message */ ai_message: DeanonymizedMessage; /** * Key-value mapping of anonymization for both user and assistant message */ deanonymized_mapping: Record; } /** * Actual message content of the deanonymized_message chunk. */ interface DeanonymizedMessage { /** * Message content that has been anonymized. */ content: string; /** * Raw message content without anonymization. If the message * isn't going through anonymization step, this value will be `undefined`. */ deanonymized_content?: string; } /** * Progress report of current message stream */ interface GLChatProcess { /** * Unique identifier of the process */ id: string; /** * Human-readable message to be associated with the process */ message?: string; /** * Status of the current progress */ status: StepIndicatorStatus; /** * Unix timestamp that denotes when this process is created */ time?: number; } /** * Attached binary data in form of File inside a message. */ interface GLChatAttachment { /** * Identifier of the attachment. * * Mainly used to interact with the attachment during edit / refresh flow. */ id: string; /** * MIME type of the attachment. */ type: string; /** * Name of the attachment. */ name: string; /** * A public URL of the attachment. */ url: string; }