/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: 64060926ed56 */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AgentConfig, AgentConfig$inboundSchema, AgentConfig$Outbound, AgentConfig$outboundSchema, } from "./agentconfig.js"; import { ChatMessageCitation, ChatMessageCitation$inboundSchema, ChatMessageCitation$Outbound, ChatMessageCitation$outboundSchema, } from "./chatmessagecitation.js"; import { ChatMessageFragment, ChatMessageFragment$inboundSchema, ChatMessageFragment$Outbound, ChatMessageFragment$outboundSchema, } from "./chatmessagefragment.js"; export const Author = { User: "USER", GleanAi: "GLEAN_AI", } as const; export type Author = OpenEnum; /** * Semantically groups content of a certain type. It can be used for purposes such as differential UI treatment. USER authored messages should be of type CONTENT and do not need `messageType` specified. */ export const MessageType = { /** * An intermediate state message for progress updates. */ Update: "UPDATE", /** * A user query or response message. */ Content: "CONTENT", /** * A message providing context in addition to the user query. */ Context: "CONTEXT", /** * Control signal for message streaming. */ Control: "CONTROL", /** * Control signal indicating the start of a message stream. */ ControlStart: "CONTROL_START", /** * Control signal indicating the end of a message stream. */ ControlFinish: "CONTROL_FINISH", /** * Control signal indicating the message stream was cancelled. */ ControlCancel: "CONTROL_CANCEL", /** * Indicates the message streaming needed to be retried. */ ControlRetry: "CONTROL_RETRY", /** * Fallback control signal for unrecognized control types. */ ControlUnknown: "CONTROL_UNKNOWN", /** * A debug message. Strictly used internally. */ Debug: "DEBUG", /** * A debug message to be used while debugging Action creation. */ DebugExternal: "DEBUG_EXTERNAL", /** * A message that describes an error while processing the request. */ Error: "ERROR", /** * A heading message used to distinguish different sections of the holistic response. */ Heading: "HEADING", /** * A warning message to be shown to the user. */ Warning: "WARNING", /** * A message used to for server-side tool auth/use, for request and response. */ ServerTool: "SERVER_TOOL", } as const; /** * Semantically groups content of a certain type. It can be used for purposes such as differential UI treatment. USER authored messages should be of type CONTENT and do not need `messageType` specified. */ export type MessageType = OpenEnum; /** * A message that is rendered as one coherent unit with one given sender. */ export type ChatMessage = { /** * Describes the agent that executes the request. */ agentConfig?: AgentConfig | undefined; author?: Author | undefined; /** * Deprecated: Use inline citations via ChatMessageFragment.citation instead. For detailed reference information, use ChatMessageCitation.referenceRanges. This field is still populated for backward compatibility. * * @deprecated field: Deprecated on 2026-02-06, removal scheduled for 2026-10-15: Use inline citations via ChatMessageFragment.citation and ChatMessageCitation.referenceRanges instead. This field is still populated for backward compatibility.. */ citations?: Array | undefined; /** * IDs of files uploaded in the message that are referenced to generate the answer. */ uploadedFileIds?: Array | undefined; /** * A list of rich data used to represent the response or formulate a request. These are linearly stitched together to support richer data formats beyond simple text. */ fragments?: Array | undefined; /** * Response timestamp of the message. */ ts?: string | undefined; /** * A unique server-side generated ID used to identify a message, automatically populated for any USER authored messages. */ messageId?: string | undefined; /** * Opaque tracking token generated server-side. */ messageTrackingToken?: string | undefined; /** * Semantically groups content of a certain type. It can be used for purposes such as differential UI treatment. USER authored messages should be of type CONTENT and do not need `messageType` specified. */ messageType?: MessageType | undefined; /** * Signals there are additional response fragments incoming. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ hasMoreFragments?: boolean | undefined; }; /** @internal */ export const Author$inboundSchema: z.ZodType = openEnums.inboundSchema(Author); /** @internal */ export const Author$outboundSchema: z.ZodType = openEnums.outboundSchema(Author); /** @internal */ export const MessageType$inboundSchema: z.ZodType< MessageType, z.ZodTypeDef, unknown > = openEnums.inboundSchema(MessageType); /** @internal */ export const MessageType$outboundSchema: z.ZodType< string, z.ZodTypeDef, MessageType > = openEnums.outboundSchema(MessageType); /** @internal */ export const ChatMessage$inboundSchema: z.ZodType< ChatMessage, z.ZodTypeDef, unknown > = z.object({ agentConfig: AgentConfig$inboundSchema.optional(), author: Author$inboundSchema.default("USER"), citations: z.array(ChatMessageCitation$inboundSchema).optional(), uploadedFileIds: z.array(z.string()).optional(), fragments: z.array(ChatMessageFragment$inboundSchema).optional(), ts: z.string().optional(), messageId: z.string().optional(), messageTrackingToken: z.string().optional(), messageType: MessageType$inboundSchema.default("CONTENT"), hasMoreFragments: z.boolean().optional(), }); /** @internal */ export type ChatMessage$Outbound = { agentConfig?: AgentConfig$Outbound | undefined; author: string; citations?: Array | undefined; uploadedFileIds?: Array | undefined; fragments?: Array | undefined; ts?: string | undefined; messageId?: string | undefined; messageTrackingToken?: string | undefined; messageType: string; hasMoreFragments?: boolean | undefined; }; /** @internal */ export const ChatMessage$outboundSchema: z.ZodType< ChatMessage$Outbound, z.ZodTypeDef, ChatMessage > = z.object({ agentConfig: AgentConfig$outboundSchema.optional(), author: Author$outboundSchema.default("USER"), citations: z.array(ChatMessageCitation$outboundSchema).optional(), uploadedFileIds: z.array(z.string()).optional(), fragments: z.array(ChatMessageFragment$outboundSchema).optional(), ts: z.string().optional(), messageId: z.string().optional(), messageTrackingToken: z.string().optional(), messageType: MessageType$outboundSchema.default("CONTENT"), hasMoreFragments: z.boolean().optional(), }); export function chatMessageToJSON(chatMessage: ChatMessage): string { return JSON.stringify(ChatMessage$outboundSchema.parse(chatMessage)); } export function chatMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ChatMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ChatMessage' from JSON`, ); }