import type { ParsedApp } from "@next-tsx/parser"; export interface Conversation { id: string; title: string; projectId?: string; state: ConversationState; tasks: Task[]; serviceFlows: ServiceFlowRun[]; mode: "new" | "resume"; startTime: number; endTime?: number; finished?: boolean; } export interface Task { id: string; upstream?: string[]; parent?: string; state: TaskState; jobs: Job[]; startTime: number; endTime?: number; aiEmployeeId?: string; plan?: PlanStep[]; } export interface PlanStep { name: string; jobId?: string; } export type ConversationState = "working" | "completed" | "failed" | "input-required" | "terminated"; export type TaskState = "working" | "input-required" | "completed" | "failed"; export type JobState = "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "skipped" | "unknown"; export interface Job { id: string; type?: "default" | "subTask" | "serviceFlow" | "reasoning" | "askUser"; upstream?: string[]; parent?: string; instruction?: string; state: JobState; toolCall?: ToolCall; messages?: Message[]; isError?: boolean; hidden?: boolean; startTime: number; endTime?: number; generatedView?: GeneratedView; requestHumanAction?: HumanAction; humanAction?: string; hil?: { userInstanceId: string; username: string; }; aiEmployeeId?: string; username?: string; cmd?: CommandPayload; mentionedAiEmployeeId?: string; ignoreDetails?: boolean; summary?: string; } export type HumanAction = HumanActionConfirm | HumanActionSelect; export interface HumanActionConfirm { type: "confirm"; confirmText: string; } export interface HumanActionSelect { type: "select"; options: string[]; } export interface Message { role: string; parts: Part[]; } export type Part = TextPart | FilePart | DataPart; export interface TextPart { type: "text"; text: string; } export interface FilePart { type: "file"; file: FileInfo; } export interface FileInfo { name?: string; mimeType?: string; size?: number; bytes?: string; uri?: string; } export interface DataPart { type: "data"; data: Record; } export interface ToolCall { name: string; arguments?: Record; argumentsParseFailed?: boolean; argumentsParseError?: unknown; originalArguments?: string; annotations?: { title?: string; }; } export type ConversationBaseDetail = Omit; export interface ConversationPatch extends Omit, "tasks" | "serviceFlows"> { tasks?: TaskPatch[]; error?: string; time?: number; serviceFlows?: ServiceFlowPatch[]; } export interface TaskPatch extends Omit, "jobs"> { id: string; jobs?: JobPatch[]; } export interface JobPatch extends Partial { id: string; } export interface RequestStore extends ChatPayload { conversationId: string; } export interface UploadFileInfo { fileId: string; } export interface UploadOptions { enabled?: boolean; dragDisabled?: boolean; dragTips?: string; accept?: string; maxFiles?: number; /** In bytes */ maxSize?: number; readableAccept?: string; readableMaxSize?: string; } export interface ChatPayload extends ExtraChatPayload { content: string; } export interface ExtraChatPayload { files?: UploadFileInfo[]; cmd?: CommandPayload | null; aiEmployeeId?: string | null; agentId?: string; spaceId?: string; } export interface GeneratedView { viewId: string; code: string; isStaticData?: boolean; from?: "generate" | "config"; withContexts?: Record; asyncConstructedView?: Promise; } export interface ParsedView extends ParsedApp { viewId: string; withContexts?: Record; } export interface ShowCaseType { conversationId: string; title: string; summary: string; scenario: string; url?: string; } export interface ExampleProject { instanceId: string; name: string; url?: string; } export interface ConversationError { taskId?: string; error?: string; } export type CommandPayload = CommandPayloadServiceFlowStart | CommandPayloadServiceFlowCreate | CommandPayloadServiceFlowEdit | CommandPayloadGoalPlan | CommandPayloadBusinessObjectManagement | CommandPayloadBusinessInstanceManagement | CommandPayloadSpaceConfig | LegacyCommandPayloadServiceFlowStarting; export interface BaseCommandPayload { type: string; payload?: unknown; } export interface CommandPayloadServiceFlowStart extends BaseCommandPayload { type: "serviceflow-start"; payload: { spaceInstanceId: string; spaceName?: string; flowInstanceId?: string; flowName?: string; }; } export interface CommandPayloadSpaceConfig extends BaseCommandPayload { type: "space-config"; payload: { spaceInstanceId: string; ServiceObjectId?: string; InstanceId?: string; }; } export interface CommandPayloadServiceFlowCreate extends BaseCommandPayload { type: "serviceflow-create"; payload: { spaceInstanceId: string; spaceName?: string; }; } export interface CommandPayloadServiceFlowEdit extends BaseCommandPayload { type: "serviceflow-edit"; payload: { spaceInstanceId: string; spaceName?: string; flowInstanceId: string; flowName?: string; }; } export interface CommandPayloadGoalPlan extends BaseCommandPayload { type: "goal-plan"; payload: { goalId: string; goalName?: string; description?: string; }; } export interface CommandPayloadBusinessObjectManagement extends BaseCommandPayload { type: "serviceObject-createOrEdit"; payload: { spaceInstanceId: string; serviceObjectId?: string; }; } export interface CommandPayloadBusinessInstanceManagement extends BaseCommandPayload { type: "serviceObjectInstance-createOrEdit"; payload: { spaceInstanceId: string; serviceObjectId: string; instanceId?: string; }; } /** @deprecated Use `payload` instead */ export interface LegacyCommandPayloadServiceFlowStarting { type: "serviceFlowStarting"; serviceFlowStarting: { spaceInstanceId?: string; spaceName?: string; flowInstanceId?: string; flowName?: string; }; } export interface ServiceFlowRun { taskId: string; flowInstanceId: string; name: string; spec: StageRun[]; space: CollaborationSpace; } export interface StageRun { name: string; serviceFlowActivities: ActivityRun[]; } export interface ActivityRun { taskId?: string; name: string; } export interface CollaborationSpace { instanceId: string; name: string; } export interface ServiceFlowPatch extends Partial> { taskId: string; spec?: StagePatch[]; fullSpec?: StageRun[]; space?: CollaborationSpace; } export interface StagePatch { name: string; serviceFlowActivities?: ActivityRun[]; } export interface ActivityWithFlow { flow: ServiceFlowRun; activity: ActivityRun; } export interface ActiveDetail { type: "job" | "flow" | "activity" | "task"; id: string; } export type FulfilledActiveDetail = ActiveDetailOfJob | ActiveDetailOfTask | ActiveDetailOfFlow | ActiveDetailOfActivity; export interface ActiveDetailOfJob { type: "job"; job: Job; } export interface ActiveDetailOfTask { type: "task"; task: Task; } export interface ActiveDetailOfFlow { type: "flow"; flow: ServiceFlowRun; } export interface ActiveDetailOfActivity { type: "activity"; activity: ActivityRun; flow: ServiceFlowRun; } export interface PlanProgressStep { name: string; taskId?: string; state?: TaskState; } export interface ActiveImages { files: FileInfo[]; file: FileInfo; }