UNPKG

@unified-llm/core

Version:

Unified LLM interface (in-memory).

101 lines (100 loc) 3.35 kB
import { type Thread, type ThreadParticipant, type Message, type StoredLLMClient } from './schema'; import type { ConversationThread } from '../types/unified-api'; export interface ThreadConfig { dbPath?: string; autoSave?: boolean; threadId?: string; title?: string; description?: string; createdBy?: string; tags?: string[]; metadata?: Record<string, any>; } export interface JoinThreadOptions { role?: 'moderator' | 'participant' | 'observer'; nickname?: string; metadata?: Record<string, any>; } export interface ThreadSummary { id: string; title?: string; description?: string; messageCount: number; participantCount: number; lastActivity: Date; activeParticipants: string[]; tags?: string[]; } export declare class ThreadRepository { /** 非同期 DB 取得プロミス */ private dbPromise; constructor(dbPath?: string); private getDb; private isDisabled; /** 新規作成 */ createThread(config?: ThreadConfig): Promise<Thread>; /** 取得 */ getThread(threadId: string): Promise<Thread | null>; /** 更新 */ updateThread(threadId: string, updates: Partial<Pick<Thread, 'title' | 'description' | 'tags' | 'metadata'>>): Promise<Thread | null>; /** 論理削除 */ deleteThread(threadId: string): Promise<boolean>; /** スレッド一覧 */ listThreads(options?: { limit?: number; offset?: number; tags?: string[]; createdBy?: string; }): Promise<ThreadSummary[]>; /** 参加 */ joinThread(threadId: string, clientId: string, options?: JoinThreadOptions): Promise<ThreadParticipant>; /** 離脱 */ leaveThread(threadId: string, clientId: string): Promise<boolean>; /** アクティブ参加者 */ getActiveParticipants(threadId: string): Promise<Array<ThreadParticipant & { client: StoredLLMClient; }>>; /** ある時点以降の参加者 */ getParticipantsSince(threadId: string, since: Date): Promise<Array<ThreadParticipant & { client: StoredLLMClient; }>>; /** 追加 */ addMessage(data: { threadId: string; clientId?: string; role: string; content: any; toolCalls?: any; toolResults?: any; parentMessageId?: string; metadata?: Record<string, any>; tokens?: number; cost?: number; }): Promise<Message>; /** スレッドのメッセージ取得 */ getThreadMessages(threadId: string, options?: { limit?: number; offset?: number; since?: Date; }): Promise<Message[]>; /** 参加以降に見えるメッセージ */ getVisibleMessages(threadId: string, clientId: string, options?: { includeContext?: boolean; contextLimit?: number; }): Promise<Message[]>; getConversationThread(threadId: string): Promise<ConversationThread | null>; private convertToUnifiedMessage; /** 統計 */ getThreadStats(threadId: string): Promise<{ messageCount: number; participantCount: number; totalTokens: number; totalCost: number; participants: Array<{ clientId: string; messageCount: number; joinedAt: Date; }>; }>; } export declare const threadRepository: ThreadRepository;