chat.ts


Overview

The chat.ts file defines TypeScript interfaces and types that model the core data structures used in a chat or conversational AI system. These interfaces represent configurations, dialog metadata, conversations, messages, references, answers, tokens, and statistics, enabling strong typing and clear contracts for components interacting with chat-related data. The file mainly serves as a type definitions module to standardize data shapes across the application, facilitating maintainability and reducing runtime errors.

The file does not contain executable logic or algorithms but provides critical schema definitions that underpin chat functionality such as message handling, dialog settings, LLM (Large Language Model) configurations, conversation referencing, and token management.


Detailed Interface Descriptions


PromptConfig

Defines the configuration for a prompt used in generating or refining chat responses.

Property

Type

Description

empty_response

string

The response to use when no content is generated or found.

parameters

Parameter[]

Array of parameters required or optional for prompt generation.

prologue

string

Introductory text to prepend to generated prompts.

system

string

System-level instructions or context for the prompt.

tts?

boolean

Optional flag to enable text-to-speech features.

quote

boolean

Whether quoting is enabled in the prompt.

keyword

boolean

Whether keyword extraction or usage is enabled.

refine_multiturn

boolean

Enables refinement across multiple turns in a conversation.

use_kg

boolean

Whether to use a knowledge graph in prompt generation.

reasoning?

boolean

Optional flag to enable reasoning capabilities.

cross_languages?

string[]

Optional list of supported cross-languages for multilingual prompts.

Usage example:

const examplePromptConfig: PromptConfig = {
  empty_response: "Sorry, I don't have an answer.",
  parameters: [{ key: 'topic', optional: false }],
  prologue: "Let's discuss the topic:",
  system: "You are an expert assistant.",
  quote: true,
  keyword: false,
  refine_multiturn: true,
  use_kg: false,
};

Parameter

Defines an individual prompt parameter specifying its key and whether it is optional.

Property

Type

Description

key

string

The name/key of the parameter.

optional

boolean

Whether the parameter is optional.


LlmSetting

Describes multiple LLM configuration profiles, each represented as a Variable.

Property

Type

Description

Creative

Variable

Settings for a creative LLM style.

Custom

Variable

Custom LLM settings.

Evenly

Variable

Balanced LLM settings.

Precise

Variable

Settings favoring precision.


Variable

Models the configurable parameters for an LLM instance.

Property

Type

Description

frequency_penalty?

number

Controls repetition penalty.

max_tokens?

number

Maximum tokens allowed in a generation.

presence_penalty?

number

Penalty for presence of new tokens.

temperature?

number

Sampling temperature for randomness.

top_p?

number

Top-p nucleus sampling parameter.

llm_id?

string

Identifier for the LLM instance.


IDialog

Represents metadata and configuration of a dialog session or template.

Property

Type

Description

create_date

string

Creation date of the dialog.

create_time

number

Timestamp of creation.

description

string

Description or summary of the dialog.

icon

string

Icon identifier or URL associated with the dialog.

id

string

Unique identifier of the dialog.

dialog_id

string

Another dialog ID, possibly for external referencing.

kb_ids

string[]

Knowledge base IDs linked to this dialog.

kb_names

string[]

Names of linked knowledge bases.

language

string

Language code of the dialog.

llm_id

string

Identifier of the LLM used in the dialog.

llm_setting

Variable

LLM parameters associated with the dialog.

llm_setting_type

string

Type or profile name of the LLM setting (e.g., "Creative").

name

string

Human-readable name for the dialog.

prompt_config

PromptConfig

Configuration for prompts used in this dialog.

prompt_type

string

Type/category of prompt (e.g., "question_answering").

status

string

Current status of the dialog (e.g., "active").

tenant_id

string

Tenant or customer identifier owning this dialog.

update_date

string

Last update date.

update_time

number

Last update timestamp.

vector_similarity_weight

number

Weighting factor for vector similarity in retrieval.

similarity_threshold

number

Threshold for similarity filtering.

top_k

number

Number of top results to consider.

top_n

number

Number of top candidates to retrieve.

meta_data_filter

MetaDataFilter

Filter criteria for metadata during retrieval or processing.


MetaDataFilter

Defines filtering method and manual filters applied to metadata.

Property

Type

Description

manual

Manual[]

Array of manual filter conditions.

method

string

Filtering method used (e.g., "and").


Manual

Specifies a single manual filter condition.

Property

Type

Description

key

string

Metadata key to filter by.

op

string

Operation to apply (e.g., "=").

value

string

Value to match for the key.


IConversation

Represents a conversation thread or chat session.

Property

Type

Description

create_date

string

Creation date of the conversation.

create_time

number

Creation timestamp.

dialog_id

string

Associated dialog ID.

id

string

Unique ID for the conversation.

avatar

string

Avatar image or icon for UI display.

message

Message[]

List of messages in the conversation.

reference

IReference[]

List of references related to the conversation.

name

string

Name or title of the conversation.

update_date

string

Last update date.

update_time

number

Last update timestamp.

is_new

true

Flag indicating if the conversation is new.


Message

Represents an individual message within a conversation.

Property

Type

Description

content

string

Text content of the message.

role

MessageType

Role of the sender (e.g., user, system).

doc_ids?

string[]

Optional list of document IDs referenced.

prompt?

string

Optional prompt text associated.

id?

string

Optional unique message identifier.

audio_binary?

string

Optional audio binary data for TTS.

data?

any

Optional additional data payload.

files?

File[]

Optional attached files.

chatBoxId?

string

Optional ID of the chat box UI element.


IReferenceChunk

Represents a chunk of referenced data from a document.

Property

Type

Description

id

string

Unique chunk identifier.

content

null

Content is currently null (placeholder).

document_id

string

ID of the document this chunk belongs to.

document_name

string

Name of the document.

dataset_id

string

Dataset identifier.

image_id

string

Associated image identifier.

similarity

number

Overall similarity score.

vector_similarity

number

Similarity based on vector embedding.

term_similarity

number

Similarity based on term matching.

positions

number[]

Positions or offsets in the document.

doc_type?

string

Optional document type (e.g., "pdf").


IReference

Represents aggregated referencing information for documents related to a conversation or answer.

Property

Type

Description

chunks

IReferenceChunk[]

Array of referenced chunks.

doc_aggs

Docagg[]

Aggregated document metadata.

total

number

Total number of references.


IReferenceObject

Alternative representation with mapped chunk and document aggregations keyed by IDs.

Property

Type

Description

chunks

Record<string, IReferenceChunk>

Map of chunk IDs to chunks.

doc_aggs

Record<string, Docagg>

Map of document IDs to aggregates.


IAnswer

Represents an answer generated by the system, potentially with references and audio.

Property

Type

Description

answer

string

The textual answer content.

reference?

IReference

Optional references supporting the answer.

conversationId?

string

Optional ID of the conversation.

prompt?

string

Optional prompt used to generate the answer.

id?

string

Optional unique answer ID.

audio_binary?

string

Optional audio data for TTS playback.

data?

any

Optional additional data payload.

chatBoxId?

string

Optional UI chat box identifier.


Docagg

Aggregated metadata for a document referenced in conversations or answers.

Property

Type

Description

count

number

Number of references or hits.

doc_id

string

Document ID.

doc_name

string

Document name.

url?

string

Optional URL to access the document.


IToken

Represents an authentication or access token entity.

Property

Type

Description

create_date

string

Token creation date.

create_time

number

Creation timestamp.

tenant_id

string

Tenant or customer owning the token.

token

string

The token string itself.

update_date?

any

Optional last update date.

update_time?

any

Optional last update timestamp.

beta

string

Beta feature flag or related info.


IStats

Holds various usage and performance statistics as arrays of timestamp-value tuples.

Property

Type

Description

pv

[string, number][]

Page views over time.

uv

[string, number][]

Unique visitors over time.

speed

[string, number][]

Processing speed metrics.

tokens

[string, number][]

Token usage counts.

round

[string, number][]

Conversation rounds count.

thumb_up

[string, number][]

Positive feedback counts.


IExternalChatInfo

Metadata for external chat integrations or imports.

Property

Type

Description

avatar?

string

Optional avatar image URL or ID.

title

string

Title or name of the external chat.

prologue?

string

Optional introductory text.


Important Implementation Notes


Interaction with Other System Components


Visual Diagram: Class Diagram of Interfaces in chat.ts

classDiagram
    class PromptConfig {
        +empty_response: string
        +parameters: Parameter[]
        +prologue: string
        +system: string
        +tts?: boolean
        +quote: boolean
        +keyword: boolean
        +refine_multiturn: boolean
        +use_kg: boolean
        +reasoning?: boolean
        +cross_languages?: string[]
    }
    class Parameter {
        +key: string
        +optional: boolean
    }
    class LlmSetting {
        +Creative: Variable
        +Custom: Variable
        +Evenly: Variable
        +Precise: Variable
    }
    class Variable {
        +frequency_penalty?: number
        +max_tokens?: number
        +presence_penalty?: number
        +temperature?: number
        +top_p?: number
        +llm_id?: string
    }
    class IDialog {
        +create_date: string
        +create_time: number
        +description: string
        +icon: string
        +id: string
        +dialog_id: string
        +kb_ids: string[]
        +kb_names: string[]
        +language: string
        +llm_id: string
        +llm_setting: Variable
        +llm_setting_type: string
        +name: string
        +prompt_config: PromptConfig
        +prompt_type: string
        +status: string
        +tenant_id: string
        +update_date: string
        +update_time: number
        +vector_similarity_weight: number
        +similarity_threshold: number
        +top_k: number
        +top_n: number
        +meta_data_filter: MetaDataFilter
    }
    class MetaDataFilter {
        +manual: Manual[]
        +method: string
    }
    class Manual {
        +key: string
        +op: string
        +value: string
    }
    class IConversation {
        +create_date: string
        +create