53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
/**
|
||
* dsh-better-chat 客户端入口(合并后)。
|
||
*
|
||
* 两个半场共用一个 client 产物:
|
||
* - 阅读视图(原 dsh-better-display):reader-plugin.tsx 及其整棵 React 源码树;
|
||
* - 聊天增强(原 dsh-better-chat):审批键盘/提示、权限 UI、商店更新按钮。
|
||
*
|
||
* 入口必须导出一个静态字符串 inject 数组(宿主 Cordis 服务注入),
|
||
* 并在这里统一 apply。审批快捷键的配置存在 dsh.better-chat.v1,由设置页写入。
|
||
*/
|
||
import type { Context } from '@deepseek-ai/cordis'
|
||
import { install as installApprovalKeys } from './chat/approval-keys.js'
|
||
import { createChatStore, currentBindings } from './chat/bindings-store.js'
|
||
import { installKeyHints } from './chat/key-hint.js'
|
||
import { installPermissionPolicy } from './chat/permission-policy.js'
|
||
import { storeUpdatePlugin } from './chat/store-update.js'
|
||
import { apply as applyReader, name as readerName } from './reader-plugin.js'
|
||
|
||
export const name = 'dsh-better-chat'
|
||
|
||
/** 阅读视图所需的宿主客户端服务;聊天增强不额外依赖服务。 */
|
||
export const inject = [
|
||
'slots',
|
||
'sessions',
|
||
'conversation',
|
||
'uiConversation',
|
||
'remote',
|
||
'remote.session',
|
||
]
|
||
|
||
export function apply(ctx: Context): void {
|
||
// 审批快捷键:持久化实例在 apply 里创建,避免模块级单例跨插件重载残留。
|
||
const chatPrefs = createChatStore().create()
|
||
const getBindings = () => currentBindings(chatPrefs)
|
||
|
||
// 聊天增强:纯 DOM 观察,不依赖任何宿主服务。
|
||
ctx.effect(() => installApprovalKeys(document, getBindings), 'dsh-better-chat: approval key routing')
|
||
ctx.effect(() => installKeyHints(document, { getBindings }), 'dsh-better-chat: approval key hints')
|
||
ctx.effect(
|
||
() => installPermissionPolicy(document, () => (ctx as { sessions?: unknown }).sessions),
|
||
'dsh-better-chat: permission policy (no full access, auto review by default)',
|
||
)
|
||
try {
|
||
ctx.plugin(storeUpdatePlugin as any)
|
||
} catch {
|
||
// 子插件挂不上(旧宿主等)不影响主功能。
|
||
}
|
||
|
||
// 阅读视图:注册 slots、设置页(含快捷键配置)与文本变换服务。
|
||
applyReader(ctx, { chatPrefs })
|
||
void readerName
|
||
}
|