@unified-llm/core
Version:
Unified LLM interface.
147 lines (146 loc) • 4.72 kB
TypeScript
import { LLMClient } from './llm-client';
import { ConversationThread, Message as UnifiedMessage, UnifiedChatResponse } from './types/unified-api';
import type { ThreadConfig, JoinThreadOptions } from './database/thread-repository';
/**
* スレッドベースのチャットセッション
* 複数のLLMクライアントが途中から参加可能な永続化された会話スレッド
*/
export declare class Thread {
id: string;
title?: string;
description?: string;
clients: Map<string, LLMClient>;
messages: UnifiedMessage[];
autoSave: boolean;
private repository;
private _isLoaded;
private _createdBy?;
private _tags?;
private _runtimeClientIds;
constructor(config?: ThreadConfig);
/**
* 既存のスレッドをロード
*/
load(): Promise<boolean>;
/**
* スレッドを保存
*/
save(): Promise<boolean>;
/**
* 保存されたLLMクライアントをスレッドに参加させる
*/
addAssistantById(clientId: string, nickname?: string, options?: JoinThreadOptions & {
includeContext?: boolean;
contextLimit?: number;
}): Promise<void>;
/**
* 実行時LLMクライアントをスレッドに参加させる(実行時作成対応)
*/
addAssistant(assistant: LLMClient, name: string, options?: JoinThreadOptions & {
clientId?: string;
provider?: 'openai' | 'anthropic' | 'google';
model?: string;
includeContext?: boolean;
contextLimit?: number;
}): Promise<void>;
/**
* LLMクライアントをスレッドから離脱させる
*/
removeAssistant(nameOrId: string): Promise<boolean>;
/**
* スレッドに参加しているLLMクライアントの一覧を取得
*/
getParticipants(): Promise<({
id: string;
role: string | null;
metadata: unknown;
threadId: string;
clientId: string;
joinedAt: Date;
leftAt: Date | null;
nickname: string | null;
} & {
client: import(".").StoredLLMClient;
})[]>;
/**
* 特定の時点以降に参加したLLMクライアントを取得
*/
getNewParticipantsSince(since: Date): Promise<({
id: string;
role: string | null;
metadata: unknown;
threadId: string;
clientId: string;
joinedAt: Date;
leftAt: Date | null;
nickname: string | null;
} & {
client: import(".").StoredLLMClient;
})[]>;
/**
* メッセージを送信(指定したLLMクライアントまたは全LLMクライアントが応答)
*/
sendMessage(content: string | UnifiedMessage['content'], targetAssistant?: string): Promise<UnifiedChatResponse[]>;
/**
* LLMクライアントのニックネームから参加者情報を取得
*/
private getParticipantByName;
/**
* LLMクライアントインスタンスからニックネームを取得
*/
private getAssistantName;
/**
* 統一形式のスレッドとして取得
*/
toConversationThread(): ConversationThread;
/**
* メッセージをクリア
*/
clearMessages(): void;
/**
* スレッドの統計情報を取得
*/
getStats(): Promise<{
messageCount: number;
participantCount: number;
totalTokens: number;
totalCost: number;
participants: Array<{
clientId: string;
messageCount: number;
joinedAt: Date;
}>;
}>;
/**
* セッション終了時のクリーンアップ(実行時LLMクライアントをDBから削除)
*/
cleanup(): Promise<void>;
/**
* 新しいスレッドを作成
*/
static createThread(config?: ThreadConfig): Promise<Thread>;
/**
* 既存のスレッドをロード
*/
static loadThread(threadId: string, config?: Omit<ThreadConfig, 'threadId'>): Promise<Thread | null>;
/**
* アクティブなスレッドの一覧を取得
*/
static listThreads(options?: {
limit?: number;
offset?: number;
tags?: string[];
createdBy?: string;
dbPath?: string;
}): Promise<import("./database/thread-repository").ThreadSummary[]>;
/**
* スレッドを削除
*/
static deleteThread(threadId: string, dbPath?: string): Promise<boolean>;
/**
* 既存のチャットをロード(loadThreadのエイリアス)
* テストの互換性のために追加
*/
static loadChat(threadId: string, config?: Omit<ThreadConfig, 'threadId'>): Promise<Thread | null>;
}
export default Thread;