UNPKG

@mencraft/lore-headless

Version:
253 lines (252 loc) 6.14 kB
/** * Event types for the chat stream */ export declare enum EventType { BatchDataIntermediate = "batch_data_intermediate", TextBatchIntermediate = "text_batch_intermediate", TextStreamIntermediate = "text_stream_intermediate", ToolCallIntermediate = "tool_call_intermediate", BatchDataOutput = "batch_data_output", TextBatchOutput = "text_batch_output", TextStreamOutput = "text_stream_output", ToolCallOutput = "tool_call_output", End = "end", Error = "error" } /** * Node output types */ export declare enum LoreNodeOutputTypes { HYDE_PROMPT = "HydePromptNode", PROMPT = "PromptNode", BOOL_PROMPT = "BoolPromptNode", DEFAULT_RESPONSE = "DefaultResponseNode", QUERY = "QueryNode", ROUTER = "RouterNode", REACT = "ReactNode", CONDITIONAL = "ConditionalNode", SEARCH = "SearchNode" } /** * Metadata for stream events */ export interface EventMetadata { timestamp: string; } /** * Stream event interface */ export interface StreamEvent<T = any> { event_type: EventType; event_data: T | null; metadata: EventMetadata; } /** * Chat request interface */ export interface ChatRequest { user: string; session: string; query: string; testNodeId?: string | undefined; } export interface GraphChatRequest { user: string; session: string; query: string; testNodeId: string | undefined; flow: { nodes: any[]; edges: any[]; viewport: any; }; } /** * Callbacks for chat stream */ export interface ChatStreamCallbacks { graphId?: string; onTextStream?: (text: string) => void; onBatchData?: (data: NodeResult) => void; onTextBatch?: (data: NodeResult) => void; onToolCall?: (toolCall: any) => void; onBatchDataIntermediate?: (data: NodeResult) => void; onTextBatchIntermediate?: (data: NodeResult) => void; onTextStreamIntermediate?: (text: string) => void; onToolCallIntermediate?: (toolCall: any) => void; onEnd?: () => void; onError?: (error: Error) => void; onSystemMessage?: (text: string) => void; onEvent?: (event: StreamEvent) => void; } /** * Base node interface */ export interface BaseNode { node_type: string; [key: string]: any; } /** * Query node interface */ export interface QueryNode extends BaseNode { node_type: LoreNodeOutputTypes.QUERY; query_result: Record<string, any[]>; } /** * Image data interface */ export interface ImageData { [key: string]: { image_name: string; storage_type: string; url: string; uuid: string; }; } /** * Graph structure error response */ export interface GraphStructureErrorResponse { validation_errors?: Array<{ node_id: string; message: string; error_type: string; }>; test_failure?: boolean; too_many_graphs?: boolean; tests?: Array<{ error?: boolean; error_text?: string; events?: StreamEvent[]; }>; } /** * Feedback request interface */ export interface FeedbackRequest { user: string; session: string; query: string; response: string; feedback: string; feedback_value: number; } /** * API response interface */ export interface ApiResponse<T> { data?: T; status: number; statusText: string; headers: Headers; } export interface NodeResult { identity?: Identity; node_type: LoreNodeTypes; node_id: string; node_results?: string | ConditionalNodeResult | ModelResult | ModelResultBool | HydeResult | Record<string, unknown> | RouterResult; } export declare enum LoreNodeTypes { HYDE_PROMPT = "HydePromptNode", PROMPT = "PromptNode", BOOL_PROMPT = "BoolPromptNode", DEFAULT_RESPONSE = "DefaultResponseNode", QUERY = "QueryNode", ROUTER = "RouterNode", REACT = "ReactNode", CONDITIONAL = "ConditionalNode", SEARCH = "SearchNode" } export type ConditionType = "equals" | "contains" | "greater_than" | "less_than" | "regex" | "llm" | "has_memory"; export interface ConditionalNodeResult { condition_result: string; matched_condition: Condition; next_node_id: string; } export interface ModelResult { input_prompt: Prompt; input_token_count?: number; llm_output?: string; llm_token_count?: number; model?: string; memory_prompt?: Prompt; system_prompt?: Prompt; } export interface Condition { type: ConditionType; value?: string; prompt?: Prompt; target_node_id: string; } export interface ModelResultBool extends ModelResult { bool_returned: boolean; } export interface RouterResult extends ModelResult { next_node_id: string; } export interface QueryNodeResult extends NodeResult { query_result: { [key: string]: string[]; }; } export interface HydeResult { model_output: ModelResult; hyde_model_output: ModelResult; } export type LoreOutput = { result: string; experiment_logs: NodeResult[]; experiment_node_ids: string[]; }; export interface Prompt { messages: Message[]; } export declare enum LLMRole { ASSISTANT = "assistant", USER = "user", SYSTEM = "system", DEVELOPER = "developer" } export interface Message { role: LLMRole; content: string; } export interface Identity { user_id: string; session_id: string; experiment: string; graph_id: string; client_id: string; } export declare enum ToolParameterType { STRING = "string", NUMBER = "number", INTEGER = "integer", BOOLEAN = "boolean", OBJECT = "object", ARRAY = "array" } export interface ToolParameter { name: string; type: ToolParameterType; description: string; required?: boolean; enum?: any[]; } export interface ToolConfig { name: string; description: string; parameters: ToolParameter[]; } export interface ToolCall { tool_name: string; str_ai_parameters?: string; error?: boolean; tool_id?: string; ai_parameters?: Record<string, any>; } export interface ToolCallResult extends ToolCall { result?: Record<string, any> | any[]; str_result?: string; }