koishi-plugin-chatluna 1.3.34 → 1.3.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ export declare class ChainMiddleware {
46
46
  constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
47
47
  before<T extends keyof ChainMiddlewareName>(name: T): this;
48
48
  after<T extends keyof ChainMiddlewareName>(name: T): this;
49
- run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | h[][] | ChainMiddlewareRunStatus>;
49
+ run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | ChainMiddlewareRunStatus | h[][]>;
50
50
  }
51
51
  export interface ChainMiddlewareContext {
52
52
  config: Config;
@@ -0,0 +1,33 @@
1
+ import { Context } from 'koishi';
2
+ import { Config } from '../config';
3
+ import { ChatChain } from '../chains/chain';
4
+ export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
5
+ declare module '../chains/chain' {
6
+ interface ChainMiddlewareContextOptions {
7
+ conversation_create?: {
8
+ title?: string;
9
+ preset?: string;
10
+ model?: string;
11
+ chatMode?: string;
12
+ };
13
+ conversation_manage?: {
14
+ targetConversation?: string;
15
+ presetLane?: string;
16
+ includeArchived?: boolean;
17
+ title?: string;
18
+ };
19
+ conversation_use?: {
20
+ model?: string;
21
+ preset?: string;
22
+ chatMode?: string;
23
+ };
24
+ conversation_rule?: {
25
+ model?: string;
26
+ preset?: string;
27
+ chatMode?: string;
28
+ share?: string;
29
+ lock?: string;
30
+ };
31
+ i18n_base?: string;
32
+ }
33
+ }
@@ -0,0 +1,29 @@
1
+ export interface ConversationRoom {
2
+ visibility: 'public' | 'private' | 'template_clone';
3
+ roomMasterId: string;
4
+ roomName: string;
5
+ roomId: number;
6
+ conversationId?: string;
7
+ preset: string;
8
+ model: string;
9
+ chatMode: string;
10
+ password?: string;
11
+ autoUpdate?: boolean;
12
+ updatedTime: Date;
13
+ }
14
+ export interface ConversationRoomMemberInfo {
15
+ userId: string;
16
+ roomId: number;
17
+ mute?: boolean;
18
+ roomPermission: 'owner' | 'admin' | 'member';
19
+ }
20
+ export interface ConversationRoomGroupInfo {
21
+ groupId: string;
22
+ roomId: number;
23
+ roomVisibility: 'public' | 'private' | 'template_clone';
24
+ }
25
+ export interface ConversationRoomUserInfo {
26
+ groupId?: string;
27
+ defaultRoomId: number;
28
+ userId: string;
29
+ }
@@ -25,6 +25,7 @@ export interface CreateAgentExecutorOptions {
25
25
  tools: ComputedRef<StructuredTool[]>;
26
26
  prompt: ChatLunaChatPrompt;
27
27
  agentMode: 'react' | 'tool-calling';
28
+ maxIterations?: number;
28
29
  returnIntermediateSteps?: boolean;
29
30
  handleParsingErrors?: boolean;
30
31
  instructions?: ComputedRef<string>;
@@ -1089,6 +1089,7 @@ function createAgentExecutor(options) {
1089
1089
  () => AgentExecutor.fromAgentAndTools({
1090
1090
  agent: cfg.value.agent,
1091
1091
  tools: cfg.value.tools,
1092
+ maxIterations: options.maxIterations,
1092
1093
  returnIntermediateSteps: options.returnIntermediateSteps,
1093
1094
  handleParsingErrors: options.handleParsingErrors
1094
1095
  })
@@ -1089,6 +1089,7 @@ function createAgentExecutor(options) {
1089
1089
  () => AgentExecutor.fromAgentAndTools({
1090
1090
  agent: cfg.value.agent,
1091
1091
  tools: cfg.value.tools,
1092
+ maxIterations: options.maxIterations,
1092
1093
  returnIntermediateSteps: options.returnIntermediateSteps,
1093
1094
  handleParsingErrors: options.handleParsingErrors
1094
1095
  })
@@ -23,4 +23,4 @@ export type CreateOpenAIAgentParams = {
23
23
  export declare function createOpenAIAgent({ llm, tools, prompt }: CreateOpenAIAgentParams): RunnableSequence<{
24
24
  steps: AgentStep[];
25
25
  scratchpadEntries?: ScratchpadEntry[];
26
- }, AgentAction | AgentFinish | AgentAction[]>;
26
+ }, AgentAction | AgentAction[] | AgentFinish>;
@@ -1,4 +1,3 @@
1
- import { Embeddings } from '@langchain/core/embeddings';
2
1
  import { AIMessage } from '@langchain/core/messages';
3
2
  import { ComputedRef } from '@vue/reactivity';
4
3
  import { Context } from 'koishi';
@@ -6,7 +5,7 @@ import { ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/mode
6
5
  import { PlatformService } from 'koishi-plugin-chatluna/llm-core/platform/service';
7
6
  import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
8
7
  export declare function createDisplayResponse(responseMessage: AIMessage): AIMessage;
9
- export declare function initEmbeddings(service: PlatformService, model: string | undefined): Promise<ComputedRef<Embeddings<number[]>>>;
8
+ export declare function initEmbeddings(service: PlatformService, model: string | undefined): Promise<ComputedRef<import("koishi-plugin-chatluna/llm-core/model/in_memory").EmptyEmbeddings>>;
10
9
  export declare function initModel(ctx: Context, service: PlatformService, llmPlatform: string, llmModelName: string): Promise<[
11
10
  ComputedRef<ChatLunaChatModel>,
12
11
  ComputedRef<ModelInfo | undefined>
@@ -0,0 +1,15 @@
1
+ import { Context } from 'koishi';
2
+ import { ChatChain } from 'koishi-plugin-chatluna/chains';
3
+ import { Config } from '../../config';
4
+ import { Message } from '../../types';
5
+ export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
6
+ declare module '../../chains/chain' {
7
+ interface ChainMiddlewareName {
8
+ request_conversation: never;
9
+ }
10
+ interface ChainMiddlewareContextOptions {
11
+ responseMessage?: Message;
12
+ inputMessage?: Message;
13
+ queueCount?: number;
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ import { Context } from 'koishi';
2
+ import { ChatChain } from '../../chains/chain';
3
+ import { Config } from '../../config';
4
+ import type { ConversationRecord, ResolvedConversationContext } from '../../services/conversation_types';
5
+ export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
6
+ declare module '../../chains/chain' {
7
+ interface ChainMiddlewareName {
8
+ resolve_conversation: never;
9
+ }
10
+ interface ChainMiddlewareContextOptions {
11
+ resolvedConversation?: ConversationRecord | null;
12
+ resolvedConversationContext?: ResolvedConversationContext;
13
+ }
14
+ }
@@ -0,0 +1,15 @@
1
+ import { Context } from 'koishi';
2
+ import { ChatChain } from 'koishi-plugin-chatluna/chains';
3
+ import { Config } from '../../config';
4
+ import { Message } from '../../types';
5
+ export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
6
+ declare module '../../chains/chain' {
7
+ interface ChainMiddlewareName {
8
+ request_conversation: never;
9
+ }
10
+ interface ChainMiddlewareContextOptions {
11
+ responseMessage?: Message;
12
+ inputMessage?: Message;
13
+ queueCount?: number;
14
+ }
15
+ }
@@ -0,0 +1,27 @@
1
+ import { Context } from 'koishi';
2
+ import { ChatChain } from '../../chains/chain';
3
+ import { Config } from '../../config';
4
+ export declare function apply(ctx: Context, config: Config, chain: ChatChain): void;
5
+ declare module '../../chains/chain' {
6
+ interface ChainMiddlewareName {
7
+ conversation_new: never;
8
+ conversation_switch: never;
9
+ conversation_list: never;
10
+ conversation_current: never;
11
+ conversation_rename: never;
12
+ conversation_delete: never;
13
+ conversation_use_model: never;
14
+ conversation_use_preset: never;
15
+ conversation_use_mode: never;
16
+ conversation_archive: never;
17
+ conversation_restore: never;
18
+ conversation_export: never;
19
+ conversation_compress: never;
20
+ conversation_rule_model: never;
21
+ conversation_rule_preset: never;
22
+ conversation_rule_mode: never;
23
+ conversation_rule_share: never;
24
+ conversation_rule_lock: never;
25
+ conversation_rule_show: never;
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ export declare const LEGACY_SCHEMA_SENTINEL = "data/chatluna/temp/legacy-schema-disabled.json";
2
+ export declare const LEGACY_MIGRATION_TABLES: readonly ["chathub_room_member", "chathub_room_group_member", "chathub_user", "chathub_room", "chathub_message", "chathub_conversation"];
3
+ export declare const LEGACY_RUNTIME_TABLES: readonly ["chathub_auth_group", "chathub_auth_joined_user", "chathub_auth_user"];
4
+ export declare const LEGACY_RETENTION_META_KEY = "legacy_table_retention";
5
+ export interface LegacyTableRetention {
6
+ state: 'migration-visible' | 'purged';
7
+ migrationTables: readonly string[];
8
+ runtimeTables: readonly string[];
9
+ }
10
+ export declare function createLegacyTableRetention(state: LegacyTableRetention['state']): {
11
+ state: "migration-visible" | "purged";
12
+ migrationTables: ("chathub_conversation" | "chathub_message" | "chathub_room" | "chathub_room_member" | "chathub_room_group_member" | "chathub_user")[];
13
+ runtimeTables: ("chathub_auth_group" | "chathub_auth_user" | "chathub_auth_joined_user")[];
14
+ };
15
+ export declare function getLegacySchemaSentinel(baseDir: string): string;
16
+ export declare function getLegacySchemaSentinelDir(baseDir: string): string;
@@ -0,0 +1,5 @@
1
+ import type { Context } from 'koishi';
2
+ import type { Config } from '../config';
3
+ export declare const BUILTIN_SCHEMA_VERSION = 1;
4
+ export declare function runRoomToConversationMigration(ctx: Context, config: Config): any;
5
+ export declare function ensureMigrationValidated(ctx: Context, config: Config): any;
@@ -0,0 +1,75 @@
1
+ import type { Context } from 'koishi';
2
+ import type { Config } from '../config';
3
+ export { getLegacySchemaSentinelDir, getLegacySchemaSentinel, LEGACY_MIGRATION_TABLES, LEGACY_RETENTION_META_KEY, LEGACY_RUNTIME_TABLES, LEGACY_SCHEMA_SENTINEL, createLegacyTableRetention } from './legacy_tables';
4
+ import type { LegacyRoomGroupRecord, LegacyRoomMemberRecord, LegacyRoomRecord, LegacyUserRecord } from '../services/types';
5
+ export interface MigrationValidationResult {
6
+ passed: boolean;
7
+ checkedAt: string;
8
+ conversation: {
9
+ legacy: number;
10
+ migrated: number;
11
+ matched: boolean;
12
+ };
13
+ message: {
14
+ legacy: number;
15
+ migrated: number;
16
+ matched: boolean;
17
+ };
18
+ latestMessageId: {
19
+ missingConversationIds: string[];
20
+ matched: boolean;
21
+ };
22
+ bindingKey: {
23
+ inconsistentConversationIds: string[];
24
+ matched: boolean;
25
+ };
26
+ binding: {
27
+ missingBindingKeys: string[];
28
+ missingConversationIds: string[];
29
+ matched: boolean;
30
+ };
31
+ acl: {
32
+ expected: number;
33
+ migrated: number;
34
+ missing: string[];
35
+ matched: boolean;
36
+ };
37
+ }
38
+ export declare function validateRoomMigration(ctx: Context, config: Config): Promise<{
39
+ passed: boolean;
40
+ checkedAt: string;
41
+ conversation: {
42
+ legacy: number;
43
+ migrated: number;
44
+ matched: boolean;
45
+ };
46
+ message: {
47
+ legacy: number;
48
+ migrated: number;
49
+ matched: boolean;
50
+ };
51
+ latestMessageId: {
52
+ missingConversationIds: string[];
53
+ matched: boolean;
54
+ };
55
+ bindingKey: {
56
+ inconsistentConversationIds: string[];
57
+ matched: boolean;
58
+ };
59
+ binding: {
60
+ missingBindingKeys: string[];
61
+ missingConversationIds: string[];
62
+ matched: boolean;
63
+ };
64
+ acl: {
65
+ expected: number;
66
+ migrated: number;
67
+ missing: string[];
68
+ matched: boolean;
69
+ };
70
+ }>;
71
+ export declare function readMetaValue<T>(ctx: Context, key: string): Promise<T>;
72
+ export declare function writeMetaValue(ctx: Context, key: string, value: unknown): Promise<void>;
73
+ export declare function createLegacyBindingKey(user: LegacyUserRecord, routeModes: 'shared' | 'personal' | Map<string, 'shared' | 'personal'>): string;
74
+ export declare function isComplexRoom(room: LegacyRoomRecord, members: LegacyRoomMemberRecord[], groups: LegacyRoomGroupRecord[]): boolean;
75
+ export declare function inferLegacyGroupRouteModes(users: LegacyUserRecord[], rooms: LegacyRoomRecord[], groups: LegacyRoomGroupRecord[]): Map<string, "shared" | "personal">;
@@ -0,0 +1,101 @@
1
+ import type { Session } from 'koishi';
2
+ import type { Config } from '../config';
3
+ import { ACLRecord, ArchiveRecord, BindingRecord, ConstraintRecord, ConversationRecord, MessageRecord, ConstraintPermission, ResolveConversationContextOptions, ResolvedConstraint, ResolvedConversationContext } from './conversation_types';
4
+ interface ListConversationsOptions extends ResolveConversationContextOptions {
5
+ includeArchived?: boolean;
6
+ }
7
+ interface ResolveTargetConversationOptions extends ResolveConversationContextOptions {
8
+ targetConversation?: string;
9
+ includeArchived?: boolean;
10
+ permission?: ConstraintPermission;
11
+ }
12
+ export declare class ConversationService {
13
+ private readonly ctx;
14
+ private readonly config;
15
+ constructor(ctx: import('koishi').Context, config: Config);
16
+ getConversation(id: string): Promise<ConversationRecord>;
17
+ getBinding(bindingKey: string): Promise<BindingRecord>;
18
+ getArchive(id: string): Promise<ArchiveRecord>;
19
+ getArchiveByConversationId(conversationId: string): Promise<ArchiveRecord>;
20
+ listConstraints(): Promise<ConstraintRecord[]>;
21
+ matchConstraints(session: Session): Promise<ConstraintRecord[]>;
22
+ isConstraintMatched(constraint: ConstraintRecord, session: Session): boolean;
23
+ resolveConstraint(session: Session, options?: ResolveConversationContextOptions): Promise<ResolvedConstraint>;
24
+ resolveContext(session: Session, options?: ResolveConversationContextOptions): Promise<ResolvedConversationContext>;
25
+ private resolveBindingForKey;
26
+ ensureActiveConversation(session: Session, options?: ResolveConversationContextOptions): Promise<ResolvedConversationContext & {
27
+ conversation: ConversationRecord;
28
+ }>;
29
+ createConversation(session: Session, options: {
30
+ bindingKey: string;
31
+ title: string;
32
+ model: string;
33
+ preset: string;
34
+ chatMode: string;
35
+ }): Promise<ConversationRecord>;
36
+ setActiveConversation(bindingKey: string, conversationId: string): Promise<BindingRecord>;
37
+ touchConversation(conversationId: string, patch?: Partial<ConversationRecord>): Promise<ConversationRecord>;
38
+ listConversations(session: Session, options?: ListConversationsOptions): Promise<ConversationRecord[]>;
39
+ switchConversation(session: Session, options: ResolveTargetConversationOptions): Promise<ConversationRecord>;
40
+ getCurrentConversation(session: Session, options?: ResolveConversationContextOptions): Promise<ResolvedConversationContext>;
41
+ reopenConversation(session: Session, options: ResolveTargetConversationOptions): Promise<ConversationRecord>;
42
+ listMessages(conversationId: string): Promise<MessageRecord[]>;
43
+ listAcl(conversationId: string): Promise<ACLRecord[]>;
44
+ upsertAcl(conversationId: string, records: Omit<ACLRecord, 'conversationId'>[]): Promise<ACLRecord[]>;
45
+ replaceAcl(conversationId: string, records: Omit<ACLRecord, 'conversationId'>[]): Promise<ACLRecord[]>;
46
+ removeAcl(conversationId: string, records?: Partial<Omit<ACLRecord, 'conversationId'>>[]): Promise<ACLRecord[]>;
47
+ exportConversation(session: Session, options?: ResolveTargetConversationOptions & {
48
+ outputPath?: string;
49
+ }): Promise<{
50
+ conversation: ConversationRecord;
51
+ path: string;
52
+ size: number;
53
+ checksum: string;
54
+ }>;
55
+ archiveConversation(session: Session, options?: ResolveTargetConversationOptions): Promise<{
56
+ conversation: ConversationRecord;
57
+ archive: ArchiveRecord;
58
+ path: string;
59
+ }>;
60
+ archiveConversationById(conversationId: string): Promise<{
61
+ conversation: ConversationRecord;
62
+ archive: ArchiveRecord;
63
+ path: string;
64
+ }>;
65
+ restoreConversation(session: Session, options?: ResolveConversationContextOptions & {
66
+ archiveId?: string;
67
+ }): Promise<ConversationRecord>;
68
+ private buildArchivePayload;
69
+ exportMarkdown(conversation: ConversationRecord): Promise<string>;
70
+ renameConversation(session: Session, options: ResolveTargetConversationOptions & {
71
+ title: string;
72
+ }): Promise<ConversationRecord>;
73
+ deleteConversation(session: Session, options?: ResolveTargetConversationOptions): Promise<ConversationRecord>;
74
+ updateConversationUsage(session: Session, options: ResolveConversationContextOptions & {
75
+ model?: string;
76
+ preset?: string;
77
+ chatMode?: string;
78
+ }): Promise<ConversationRecord>;
79
+ recordCompression(conversationId: string, result: {
80
+ compressed: boolean;
81
+ inputTokens: number;
82
+ outputTokens: number;
83
+ reducedTokens: number;
84
+ reducedPercent: number;
85
+ originalMessageCount: number;
86
+ remainingMessageCount: number;
87
+ }): Promise<ConversationRecord>;
88
+ getManagedConstraint(session: Session): Promise<ConstraintRecord>;
89
+ updateManagedConstraint(session: Session, patch: Partial<ConstraintRecord>): Promise<ConstraintRecord>;
90
+ private getDefaultRouteMode;
91
+ private allocateConversationSeq;
92
+ resolveTargetConversation(session: Session, options?: ResolveTargetConversationOptions): Promise<ConversationRecord>;
93
+ private findAccessibleConversations;
94
+ resolveCommandConversation(session: Session, options?: ResolveTargetConversationOptions): Promise<ConversationRecord>;
95
+ private readArchivePayload;
96
+ private ensureDataDir;
97
+ private unbindConversation;
98
+ private assertManageAllowed;
99
+ private hasConversationPermission;
100
+ }
101
+ export {};
@@ -0,0 +1,61 @@
1
+ import { BaseMessageChunk, HumanMessage } from '@langchain/core/messages';
2
+ import type { Session } from 'koishi';
3
+ import { LRUCache } from 'lru-cache';
4
+ import type { ChatInterface } from '../llm-core/chat/app';
5
+ import { type AgentAction, MessageQueue, type ToolMask } from '../llm-core/agent/types';
6
+ import { RequestIdQueue } from '../utils/queue';
7
+ import type { ChatLunaService } from './chat';
8
+ import { ConversationRecord } from './conversation_types';
9
+ import { Message } from '../types';
10
+ import type { PostHandler } from '../utils/types';
11
+ export interface ChatEvents {
12
+ 'llm-new-token'?: (token: string) => Promise<void>;
13
+ 'llm-queue-waiting'?: (size: number) => Promise<void>;
14
+ 'llm-used-token-count'?: (token: number) => Promise<void>;
15
+ 'llm-call-tool'?: (tool: string, args: any, content: AgentAction['content'], log: string) => Promise<void>;
16
+ 'llm-new-chunk'?: (chunk: BaseMessageChunk) => Promise<void>;
17
+ }
18
+ export interface RuntimeConversationEntry {
19
+ conversation: ConversationRecord;
20
+ chatInterface: ChatInterface;
21
+ }
22
+ export interface ActiveRequest {
23
+ requestId: string;
24
+ conversationId: string;
25
+ sessionId?: string;
26
+ abortController: AbortController;
27
+ chatMode: string;
28
+ messageQueue: MessageQueue;
29
+ roundDecisionResolvers: ((canContinue: boolean) => void)[];
30
+ lastDecision?: boolean;
31
+ }
32
+ export declare class ConversationRuntime {
33
+ private readonly service;
34
+ readonly interfaces: LRUCache<string, RuntimeConversationEntry, unknown>;
35
+ readonly modelQueue: RequestIdQueue;
36
+ readonly conversationQueue: RequestIdQueue;
37
+ readonly requestsById: Map<string, AbortController>;
38
+ readonly activeByConversation: Map<string, ActiveRequest>;
39
+ readonly requestBySession: Map<string, string>;
40
+ readonly platformIndex: Map<string, Set<string>>;
41
+ constructor(service: ChatLunaService);
42
+ private get platformService();
43
+ ensureChatInterface(conversation: ConversationRecord): Promise<ChatInterface>;
44
+ chat(session: Session, conversation: ConversationRecord, message: Message, event: ChatEvents, stream?: boolean, variables?: Record<string, any>, postHandler?: PostHandler, requestId?: string, toolMask?: ToolMask): Promise<Message>;
45
+ updateConversationRecord(conversation: ConversationRecord): void;
46
+ getCachedConversations(): [string, RuntimeConversationEntry][];
47
+ withConversationLock<T>(conversationId: string, callback: () => Promise<T>): Promise<T>;
48
+ withConversationAndPlatformLock<T>(conversation: ConversationRecord, callback: () => Promise<T>): Promise<T>;
49
+ registerPlatformConversation(platform: string, conversationId: string): void;
50
+ unregisterPlatformConversation(platform: string, conversationId: string): void;
51
+ registerRequest(conversationId: string, requestId: string, chatMode: string, abortController: AbortController, session?: Session): ActiveRequest;
52
+ completeRequest(conversationId: string, requestId: string, session?: Session): void;
53
+ stopRequest(requestId: string): boolean;
54
+ getRequestIdBySession(session: Session): string;
55
+ appendPendingMessage(conversationId: string, message: HumanMessage, chatMode?: string): Promise<boolean>;
56
+ clearConversationCache(conversationId: string): Promise<boolean>;
57
+ clearConversationHistory(conversation: ConversationRecord): Promise<void>;
58
+ compressConversation(conversation: ConversationRecord, force?: boolean): Promise<import("../llm-core/chat/infinite_context").CompressContextResult>;
59
+ clearConversationInterface(conversation: ConversationRecord): Promise<boolean>;
60
+ dispose(platform?: string): void;
61
+ }
@@ -0,0 +1,149 @@
1
+ import type { Session } from 'koishi';
2
+ export type ConversationStatus = 'active' | 'archived' | 'deleted' | 'broken';
3
+ export type RouteMode = 'personal' | 'shared' | 'custom';
4
+ export type ConstraintManageMode = 'anyone' | 'admin';
5
+ export type ConstraintPrincipalType = 'user' | 'guild';
6
+ export type ConstraintPermission = 'view' | 'manage';
7
+ export type ArchiveState = 'ready' | 'restoring' | 'broken';
8
+ export interface ConversationCompressionRecord {
9
+ count?: number;
10
+ summary?: string;
11
+ compressedAt?: Date | string | null;
12
+ originalMessageCount?: number;
13
+ remainingMessageCount?: number;
14
+ tokenUsage?: number;
15
+ inputTokens?: number;
16
+ outputTokens?: number;
17
+ reducedTokens?: number;
18
+ reducedPercent?: number;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface ConversationRecord {
22
+ id: string;
23
+ seq?: number;
24
+ bindingKey: string;
25
+ title: string;
26
+ model: string;
27
+ preset: string;
28
+ chatMode: string;
29
+ createdBy: string;
30
+ createdAt: Date;
31
+ updatedAt: Date;
32
+ lastChatAt?: Date | null;
33
+ status: ConversationStatus;
34
+ latestMessageId?: string | null;
35
+ additional_kwargs?: string | null;
36
+ compression?: string | null;
37
+ archivedAt?: Date | null;
38
+ archiveId?: string | null;
39
+ legacyRoomId?: number | null;
40
+ legacyMeta?: string | null;
41
+ }
42
+ export interface MessageRecord {
43
+ id: string;
44
+ conversationId: string;
45
+ parentId?: string | null;
46
+ role: string;
47
+ text?: string | null;
48
+ content?: ArrayBuffer | null;
49
+ name?: string | null;
50
+ tool_call_id?: string | null;
51
+ tool_calls?: unknown;
52
+ additional_kwargs?: string | null;
53
+ additional_kwargs_binary?: ArrayBuffer | null;
54
+ rawId?: string | null;
55
+ createdAt?: Date | null;
56
+ }
57
+ export interface BindingRecord {
58
+ bindingKey: string;
59
+ activeConversationId?: string | null;
60
+ lastConversationId?: string | null;
61
+ updatedAt: Date;
62
+ }
63
+ export interface ConstraintRecord {
64
+ id?: number;
65
+ name: string;
66
+ enabled: boolean;
67
+ priority: number;
68
+ createdBy: string;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ platform?: string | null;
72
+ selfId?: string | null;
73
+ guildId?: string | null;
74
+ channelId?: string | null;
75
+ direct?: boolean | null;
76
+ users?: string | null;
77
+ excludeUsers?: string | null;
78
+ routeMode?: RouteMode | null;
79
+ routeKey?: string | null;
80
+ defaultModel?: string | null;
81
+ defaultPreset?: string | null;
82
+ defaultChatMode?: string | null;
83
+ fixedModel?: string | null;
84
+ fixedPreset?: string | null;
85
+ fixedChatMode?: string | null;
86
+ lockConversation?: boolean | null;
87
+ allowNew?: boolean | null;
88
+ allowSwitch?: boolean | null;
89
+ allowArchive?: boolean | null;
90
+ allowExport?: boolean | null;
91
+ manageMode?: ConstraintManageMode | null;
92
+ }
93
+ export interface ArchiveRecord {
94
+ id: string;
95
+ conversationId: string;
96
+ path: string;
97
+ formatVersion: number;
98
+ messageCount: number;
99
+ checksum?: string | null;
100
+ size: number;
101
+ state: ArchiveState;
102
+ createdAt: Date;
103
+ restoredAt?: Date | null;
104
+ }
105
+ export interface ACLRecord {
106
+ conversationId: string;
107
+ principalType: ConstraintPrincipalType;
108
+ principalId: string;
109
+ permission: ConstraintPermission;
110
+ }
111
+ export interface MetaRecord {
112
+ key: string;
113
+ value?: string | null;
114
+ updatedAt: Date;
115
+ }
116
+ export interface ResolvedConstraint {
117
+ routeMode: RouteMode;
118
+ bindingKey: string;
119
+ baseKey: string;
120
+ constraints: ConstraintRecord[];
121
+ defaultModel?: string | null;
122
+ defaultPreset?: string | null;
123
+ defaultChatMode?: string | null;
124
+ fixedModel?: string | null;
125
+ fixedPreset?: string | null;
126
+ fixedChatMode?: string | null;
127
+ lockConversation: boolean;
128
+ allowNew: boolean;
129
+ allowSwitch: boolean;
130
+ allowArchive: boolean;
131
+ allowExport: boolean;
132
+ manageMode: ConstraintManageMode;
133
+ }
134
+ export interface ResolvedConversationContext {
135
+ bindingKey: string;
136
+ presetLane?: string;
137
+ conversation?: ConversationRecord | null;
138
+ binding?: BindingRecord | null;
139
+ effectiveModel?: string | null;
140
+ effectivePreset?: string | null;
141
+ effectiveChatMode?: string | null;
142
+ constraint: ResolvedConstraint;
143
+ }
144
+ export interface ResolveConversationContextOptions {
145
+ presetLane?: string;
146
+ conversationId?: string;
147
+ }
148
+ export declare function computeBaseBindingKey(session: Session, routeMode: RouteMode, routeKey?: string | null): string;
149
+ export declare function applyPresetLane(bindingKey: string, presetLane?: string): string;
@@ -0,0 +1,5 @@
1
+ import type { Context } from 'koishi';
2
+ export declare function purgeArchivedConversation(ctx: Context, conversation: {
3
+ id: string;
4
+ archiveId?: string | null;
5
+ }): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import type { Session } from 'koishi';
2
+ export declare function getRequestId(session: Session, conversationId: string): string;
3
+ export declare function createRequestId(session: Session, conversationId: string, requestId?: string): string;
4
+ export declare function deleteRequestId(session: Session, conversationId: string): void;
@@ -0,0 +1,6 @@
1
+ type Encoding = 'buffer' | 'base64' | 'hex';
2
+ type BufferType<T extends Encoding> = T extends 'buffer' ? Buffer : T extends 'base64' ? string : T extends 'hex' ? string : never;
3
+ export declare function gzipEncode<T extends Encoding = 'buffer'>(data: string, encoding?: T): Promise<BufferType<T>>;
4
+ export declare function gzipDecode(data: ArrayBuffer | ArrayBufferView): Promise<string>;
5
+ export declare function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer;
6
+ export {};
@@ -0,0 +1,8 @@
1
+ import { type BaseMessage } from '@langchain/core/messages';
2
+ export interface PresetLaneParseResult {
3
+ preset?: string;
4
+ content?: string;
5
+ queryOnly: boolean;
6
+ }
7
+ export declare function getMessageContent(message: BaseMessage['content']): string;
8
+ export declare function parsePresetLaneInput(text: string, aliases: string[]): PresetLaneParseResult | null;
@@ -0,0 +1 @@
1
+ export declare function parseRawModelName(modelName: string): [string, string];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna",
3
3
  "description": "chatluna for koishi",
4
- "version": "1.3.34",
4
+ "version": "1.3.35",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",