@talex-touch/utils 1.0.17 → 1.0.20
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.
- package/animation/window.ts +191 -0
- package/channel/index.ts +49 -1
- package/common/index.ts +2 -0
- package/common/search/gather.ts +45 -0
- package/common/search/index.ts +67 -0
- package/common/storage/constants.ts +16 -2
- package/common/storage/entity/index.ts +2 -1
- package/common/storage/entity/openers.ts +32 -0
- package/common/storage/entity/shortcut-settings.ts +22 -0
- package/common/storage/shortcut-storage.ts +58 -0
- package/common/utils/file.ts +62 -0
- package/common/{utils.ts → utils/index.ts} +14 -2
- package/common/utils/polling.ts +184 -0
- package/common/utils/task-queue.ts +108 -0
- package/common/utils/time.ts +374 -0
- package/core-box/README.md +8 -8
- package/core-box/builder/index.ts +6 -0
- package/core-box/builder/tuff-builder.example.ts.bak +258 -0
- package/core-box/builder/tuff-builder.ts +1162 -0
- package/core-box/index.ts +5 -2
- package/core-box/run-tests.sh +7 -0
- package/core-box/search.ts +1 -536
- package/core-box/tuff/index.ts +6 -0
- package/core-box/tuff/tuff-dsl.ts +1412 -0
- package/electron/clipboard-helper.ts +199 -0
- package/electron/env-tool.ts +36 -2
- package/electron/file-parsers/index.ts +8 -0
- package/electron/file-parsers/parsers/text-parser.ts +109 -0
- package/electron/file-parsers/registry.ts +92 -0
- package/electron/file-parsers/types.ts +58 -0
- package/electron/index.ts +3 -0
- package/eventbus/index.ts +0 -7
- package/index.ts +3 -1
- package/package.json +4 -28
- package/plugin/channel.ts +48 -16
- package/plugin/index.ts +194 -30
- package/plugin/log/types.ts +11 -0
- package/plugin/node/index.ts +4 -0
- package/plugin/node/logger-manager.ts +113 -0
- package/plugin/{log → node}/logger.ts +41 -7
- package/plugin/plugin-source.ts +74 -0
- package/plugin/preload.ts +5 -15
- package/plugin/providers/index.ts +2 -0
- package/plugin/providers/registry.ts +47 -0
- package/plugin/providers/types.ts +54 -0
- package/plugin/risk/index.ts +1 -0
- package/plugin/risk/types.ts +20 -0
- package/plugin/sdk/enum/bridge-event.ts +4 -0
- package/plugin/sdk/enum/index.ts +1 -0
- package/plugin/sdk/hooks/bridge.ts +68 -0
- package/plugin/sdk/hooks/index.ts +2 -1
- package/plugin/sdk/hooks/life-cycle.ts +2 -4
- package/plugin/sdk/index.ts +2 -0
- package/plugin/sdk/storage.ts +84 -0
- package/plugin/sdk/types.ts +2 -2
- package/plugin/sdk/window/index.ts +5 -3
- package/preload/index.ts +2 -0
- package/preload/loading.ts +15 -0
- package/preload/renderer.ts +41 -0
- package/renderer/hooks/arg-mapper.ts +79 -0
- package/renderer/hooks/index.ts +2 -0
- package/renderer/hooks/initialize.ts +198 -0
- package/renderer/index.ts +3 -0
- package/renderer/storage/app-settings.ts +2 -0
- package/renderer/storage/base-storage.ts +1 -0
- package/renderer/storage/openers.ts +11 -0
- package/renderer/touch-sdk/env.ts +106 -0
- package/renderer/touch-sdk/index.ts +108 -0
- package/renderer/touch-sdk/terminal.ts +85 -0
- package/renderer/touch-sdk/utils.ts +61 -0
- package/search/levenshtein-utils.ts +39 -0
- package/search/types.ts +16 -16
- package/types/index.ts +2 -1
- package/types/modules/base.ts +146 -0
- package/types/modules/index.ts +4 -0
- package/types/modules/module-lifecycle.ts +148 -0
- package/types/modules/module-manager.ts +99 -0
- package/types/modules/module.ts +112 -0
- package/types/touch-app-core.ts +16 -93
- package/core-box/types.ts +0 -384
- package/electron/window.ts +0 -71
- package/plugin/log/logger-manager.ts +0 -60
|
@@ -0,0 +1,1412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TUFF DSL: Typed Unified Flex Format
|
|
3
|
+
* 智能启动器核心数据结构定义
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* TUFF 是一种类型安全的统一灵活格式,用于定义智能启动器的数据结构。
|
|
7
|
+
* 它提供了一套完整的类型系统,用于描述搜索结果、推荐项、操作项等。
|
|
8
|
+
*
|
|
9
|
+
* @design 设计理念:
|
|
10
|
+
* - 极简易用:默认只需 title 即可渲染,降低使用门槛
|
|
11
|
+
* - 高度可扩展:支持从简单到复杂的多层次自定义渲染
|
|
12
|
+
* - 类型安全:完整的 TypeScript 类型支持,提供编译时检查
|
|
13
|
+
* - 插件友好:标准化接口设计,便于第三方扩展
|
|
14
|
+
*
|
|
15
|
+
* @version 1.0.0
|
|
16
|
+
* @module core-box/tuff-dsl
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { TalexTouch } from "packages/utils/types";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 定义高亮范围
|
|
23
|
+
* @description 右开区间 [start, end)
|
|
24
|
+
*/
|
|
25
|
+
// ==================== 核心数据结构 ====================
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* TuffItem - 系统核心数据单元
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* 所有搜索结果、推荐项、操作项的统一结构。这是整个 TUFF 系统的基础数据单元,
|
|
32
|
+
* 通过不同的配置可以表达各种类型的内容和交互方式。
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const simpleItem: TuffItem = {
|
|
37
|
+
* source: { type: 'system', id: 'core' },
|
|
38
|
+
* render: {
|
|
39
|
+
* mode: 'default',
|
|
40
|
+
* basic: { title: '示例项目' }
|
|
41
|
+
* }
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface TuffItem {
|
|
46
|
+
/**
|
|
47
|
+
* 唯一标识符
|
|
48
|
+
* @description 唯一标识符,必须由创建者提供
|
|
49
|
+
* @required
|
|
50
|
+
*/
|
|
51
|
+
id: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 数据来源信息
|
|
55
|
+
* @description 定义项目的来源,用于权限控制、缓存策略和安全隔离
|
|
56
|
+
* @required
|
|
57
|
+
*/
|
|
58
|
+
source: TuffSource;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 项目类型分类
|
|
62
|
+
* @description 影响展示方式和处理逻辑,系统会根据类型提供默认图标和行为
|
|
63
|
+
*/
|
|
64
|
+
kind?: TuffItemKind;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 渲染配置
|
|
68
|
+
* @description 控制项目的视觉展示方式
|
|
69
|
+
* @required
|
|
70
|
+
*/
|
|
71
|
+
render: TuffRender;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 图标定义
|
|
75
|
+
* @description 项目的视觉标识,会覆盖 render.basic.icon
|
|
76
|
+
*/
|
|
77
|
+
icon?: TuffIcon;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 交互行为定义
|
|
81
|
+
* @description 定义项目支持的操作和交互方式
|
|
82
|
+
*/
|
|
83
|
+
actions?: TuffAction[];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 匹配与评分信息
|
|
87
|
+
* @description 用于搜索结果排序和推荐算法
|
|
88
|
+
*/
|
|
89
|
+
scoring?: TuffScoring;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 扩展元数据
|
|
93
|
+
* @description 携带额外的项目相关信息
|
|
94
|
+
*/
|
|
95
|
+
meta?: TuffMeta;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 上下文信息
|
|
99
|
+
* @description 用于 AI 推荐和关联分析的上下文数据
|
|
100
|
+
*/
|
|
101
|
+
context?: TuffContext;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ==================== 数据来源定义 ====================
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 数据来源标识
|
|
108
|
+
*
|
|
109
|
+
* @description
|
|
110
|
+
* 定义项目的来源信息,用于权限控制、缓存策略和安全隔离。
|
|
111
|
+
* 每个项目必须明确其来源,系统据此决定信任级别和处理方式。
|
|
112
|
+
*/
|
|
113
|
+
export interface TuffSource {
|
|
114
|
+
/**
|
|
115
|
+
* 来源类型
|
|
116
|
+
* @description 定义数据的基本来源类别
|
|
117
|
+
* @required
|
|
118
|
+
*/
|
|
119
|
+
type: TuffSourceType;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 来源标识符
|
|
123
|
+
* @description 如插件ID、模块名等,用于唯一标识来源
|
|
124
|
+
* @required
|
|
125
|
+
*/
|
|
126
|
+
id: string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 来源名称
|
|
130
|
+
* @description 用于用户界面展示的友好名称
|
|
131
|
+
*/
|
|
132
|
+
name?: string;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 来源版本
|
|
136
|
+
* @description 数据提供者的版本信息,用于兼容性检查
|
|
137
|
+
*/
|
|
138
|
+
version?: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 权限级别
|
|
142
|
+
* @description 定义该来源的信任级别和权限范围
|
|
143
|
+
*/
|
|
144
|
+
permission?: TuffPermissionLevel;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 数据来源类型
|
|
149
|
+
*
|
|
150
|
+
* @description
|
|
151
|
+
* 定义数据的基本来源类别,系统据此应用不同的安全策略和处理逻辑
|
|
152
|
+
*/
|
|
153
|
+
export type TuffSourceType =
|
|
154
|
+
| 'system' // 系统内置,最高信任级别
|
|
155
|
+
| 'plugin' // 本地插件,受插件权限控制
|
|
156
|
+
| 'remote' // 远程服务,需网络访问权限
|
|
157
|
+
| 'ai' // AI 推荐,基于机器学习生成
|
|
158
|
+
| 'history' // 历史记录,基于用户过往行为
|
|
159
|
+
| 'notification' // 系统通知,来自系统事件
|
|
160
|
+
| 'workflow' // 工作流,用户自定义流程
|
|
161
|
+
| 'file' // 文件系统,本地文件
|
|
162
|
+
| 'application' // 应用程序,可启动的软件
|
|
163
|
+
| 'service'; // 系统服务,后台运行的程序
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 权限级别
|
|
167
|
+
*
|
|
168
|
+
* @description
|
|
169
|
+
* 定义数据来源的信任级别和权限范围,影响允许执行的操作
|
|
170
|
+
*/
|
|
171
|
+
export type TuffPermissionLevel =
|
|
172
|
+
| 'safe' // 安全级别,仅允许基本展示和无害操作
|
|
173
|
+
| 'trusted' // 信任级别,允许访问用户数据但有限制
|
|
174
|
+
| 'elevated' // 提升级别,允许更广泛的系统访问
|
|
175
|
+
| 'system'; // 系统级别,完全访问权限
|
|
176
|
+
|
|
177
|
+
// ==================== 项目类型分类 ====================
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 项目语义分类
|
|
181
|
+
*
|
|
182
|
+
* @description
|
|
183
|
+
* 定义项目的语义类型,系统据此决定默认图标、行为、分组等。
|
|
184
|
+
* 支持自定义扩展,可通过字符串字面量类型添加新的类型。
|
|
185
|
+
*/
|
|
186
|
+
export type TuffItemKind =
|
|
187
|
+
// 应用与程序
|
|
188
|
+
| 'app' // 应用程序,可启动的软件
|
|
189
|
+
| 'command' // 系统命令,终端或系统级指令
|
|
190
|
+
| 'script' // 脚本文件,可执行的代码文件
|
|
191
|
+
| 'workflow' // 工作流,一系列自动化步骤
|
|
192
|
+
|
|
193
|
+
// 文件与资源
|
|
194
|
+
| 'file' // 普通文件,未指定具体类型的文件
|
|
195
|
+
| 'folder' // 文件夹,包含其他文件的目录
|
|
196
|
+
| 'document' // 文档类文件,如文本、表格、演示文稿等
|
|
197
|
+
| 'image' // 图片文件,各种图像格式
|
|
198
|
+
| 'video' // 视频文件,影片和动态图像
|
|
199
|
+
| 'audio' // 音频文件,声音和音乐
|
|
200
|
+
|
|
201
|
+
// 网络与链接
|
|
202
|
+
| 'url' // 网页链接,可访问的网络地址
|
|
203
|
+
| 'bookmark' // 书签,保存的网页引用
|
|
204
|
+
| 'search-result' // 搜索结果,来自搜索引擎
|
|
205
|
+
|
|
206
|
+
// 交互与功能
|
|
207
|
+
| 'action' // 功能操作,触发特定行为
|
|
208
|
+
| 'setting' // 设置项,配置选项
|
|
209
|
+
| 'feature' // 系统功能,内置能力
|
|
210
|
+
|
|
211
|
+
// 通信与人员
|
|
212
|
+
| 'contact' // 联系人,人员信息
|
|
213
|
+
| 'notification' // 通知消息,系统或应用通知
|
|
214
|
+
|
|
215
|
+
// 扩展支持
|
|
216
|
+
| (string & {}); // 允许自定义扩展类型
|
|
217
|
+
|
|
218
|
+
// ==================== 渲染系统 ====================
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 渲染配置
|
|
222
|
+
*
|
|
223
|
+
* @description
|
|
224
|
+
* 控制项目的视觉呈现方式,支持从简单到复杂的多种渲染模式。
|
|
225
|
+
* 可以使用默认的标题+描述+图标模式,也可以完全自定义渲染内容。
|
|
226
|
+
*/
|
|
227
|
+
export interface TuffRender {
|
|
228
|
+
/**
|
|
229
|
+
* 渲染模式
|
|
230
|
+
* @description 决定使用哪种渲染策略
|
|
231
|
+
* @required
|
|
232
|
+
*/
|
|
233
|
+
mode: TuffRenderMode;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 基础渲染信息
|
|
237
|
+
* @description mode='default' 时使用的基本渲染数据
|
|
238
|
+
*/
|
|
239
|
+
basic?: TuffBasicRender;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 自定义渲染内容
|
|
243
|
+
* @description mode='custom' 时使用的自定义渲染配置
|
|
244
|
+
*/
|
|
245
|
+
custom?: TuffCustomRender;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 布局配置
|
|
249
|
+
* @description 控制项目的布局方式和尺寸
|
|
250
|
+
*/
|
|
251
|
+
layout?: TuffLayout;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 预览配置
|
|
255
|
+
* @description 定义悬停或点击时的预览内容
|
|
256
|
+
*/
|
|
257
|
+
preview?: TuffPreview;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 样式类名
|
|
261
|
+
* @description 应用于渲染容器的 CSS 类名
|
|
262
|
+
*/
|
|
263
|
+
className?: string;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 内联样式
|
|
267
|
+
* @description 应用于渲染容器的内联样式对象
|
|
268
|
+
*/
|
|
269
|
+
style?: Record<string, string>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 补全
|
|
273
|
+
* @description 用于补全的文本
|
|
274
|
+
*/
|
|
275
|
+
completion?: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 渲染模式
|
|
280
|
+
*
|
|
281
|
+
* @description
|
|
282
|
+
* 定义项目的基本渲染策略,从简单到复杂
|
|
283
|
+
*/
|
|
284
|
+
export type TuffRenderMode =
|
|
285
|
+
| 'default' // 默认渲染(title + desc + icon)
|
|
286
|
+
| 'rich' // 富文本渲染,支持格式化文本
|
|
287
|
+
| 'card' // 卡片式渲染,适合图文混排
|
|
288
|
+
| 'custom'; // 完全自定义,最大灵活性
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 基础渲染信息
|
|
292
|
+
*
|
|
293
|
+
* @description
|
|
294
|
+
* 提供基本的标题、描述和图标等信息,用于默认渲染模式。
|
|
295
|
+
* 这是最常用的渲染方式,适合大多数简单场景。
|
|
296
|
+
*/
|
|
297
|
+
export interface TuffBasicRender {
|
|
298
|
+
/**
|
|
299
|
+
* 主标题
|
|
300
|
+
* @description 项目的主要标识文本
|
|
301
|
+
* @required
|
|
302
|
+
*/
|
|
303
|
+
title: string;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 副标题/描述
|
|
307
|
+
* @description 对主标题的补充说明,通常显示在主标题下方
|
|
308
|
+
*/
|
|
309
|
+
subtitle?: string;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 详细描述
|
|
313
|
+
* @description 更详细的项目说明,可能在悬停或展开时显示
|
|
314
|
+
*/
|
|
315
|
+
description?: string;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 图标定义
|
|
319
|
+
* @description 项目的视觉标识
|
|
320
|
+
*/
|
|
321
|
+
icon?: TuffIcon;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* 标签列表
|
|
325
|
+
* @description 附加在项目上的标签,用于分类和筛选
|
|
326
|
+
*/
|
|
327
|
+
tags?: TuffTag[];
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 右侧信息
|
|
331
|
+
* @description 显示在项目右侧的辅助信息,如快捷键、时间等
|
|
332
|
+
*/
|
|
333
|
+
accessory?: string;
|
|
334
|
+
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 自定义渲染配置
|
|
339
|
+
*
|
|
340
|
+
* @description
|
|
341
|
+
* 提供完全自定义的渲染能力,支持多种前端技术。
|
|
342
|
+
* 适用于需要复杂交互或特殊展示效果的场景。
|
|
343
|
+
*/
|
|
344
|
+
export interface TuffCustomRender {
|
|
345
|
+
/**
|
|
346
|
+
* 渲染类型
|
|
347
|
+
* @description 指定使用哪种技术进行渲染
|
|
348
|
+
* @required
|
|
349
|
+
*/
|
|
350
|
+
type: 'html' | 'vue' | 'react' | 'markdown';
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* 渲染内容
|
|
354
|
+
* @description 根据type不同,可能是HTML字符串、组件名或Markdown文本
|
|
355
|
+
* @required
|
|
356
|
+
*/
|
|
357
|
+
content: string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* 渲染数据
|
|
361
|
+
* @description 传递给渲染器的数据对象
|
|
362
|
+
*/
|
|
363
|
+
data?: Record<string, any>;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* 样式资源
|
|
367
|
+
* @description 需要加载的CSS资源URL列表
|
|
368
|
+
*/
|
|
369
|
+
styles?: string[];
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 脚本资源
|
|
373
|
+
* @description 需要加载的JavaScript资源URL列表
|
|
374
|
+
*/
|
|
375
|
+
scripts?: string[];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 图标定义
|
|
380
|
+
*
|
|
381
|
+
* @description
|
|
382
|
+
* 支持多种图标类型,从简单的emoji到复杂的组件。
|
|
383
|
+
* 可以是简单字符串或包含详细配置的对象。
|
|
384
|
+
*/
|
|
385
|
+
export type TuffIcon =
|
|
386
|
+
| string // 简单字符串:emoji、URL、组件名
|
|
387
|
+
| {
|
|
388
|
+
/**
|
|
389
|
+
* 图标类型
|
|
390
|
+
* @description 指定图标的数据格式和来源
|
|
391
|
+
* @required
|
|
392
|
+
*/
|
|
393
|
+
type: 'emoji' | 'url' | 'base64' | 'fluent' | 'component';
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* 图标值
|
|
397
|
+
* @description 根据type不同,可能是emoji字符、URL地址、Base64编码或组件名
|
|
398
|
+
* @required
|
|
399
|
+
*/
|
|
400
|
+
value: string;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* 备用图标
|
|
404
|
+
* @description 当主图标无法加载时显示的替代图标
|
|
405
|
+
*/
|
|
406
|
+
fallback?: string;
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 动态加载函数
|
|
410
|
+
* @description 用于异步加载图标资源的函数
|
|
411
|
+
*/
|
|
412
|
+
loader?: () => Promise<string>;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 样式配置
|
|
416
|
+
* @description 控制图标的视觉效果
|
|
417
|
+
*/
|
|
418
|
+
style?: {
|
|
419
|
+
/** 图标尺寸 */
|
|
420
|
+
size?: number;
|
|
421
|
+
/** 图标颜色 */
|
|
422
|
+
color?: string;
|
|
423
|
+
/** 动画效果 */
|
|
424
|
+
animation?: 'spin' | 'pulse' | 'bounce';
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 标签定义
|
|
430
|
+
*
|
|
431
|
+
* @description
|
|
432
|
+
* 用于分类和标记项目的小型标签,可自定义颜色和样式。
|
|
433
|
+
*/
|
|
434
|
+
export interface TuffTag {
|
|
435
|
+
/**
|
|
436
|
+
* 标签文本
|
|
437
|
+
* @description 标签显示的文本内容
|
|
438
|
+
* @required
|
|
439
|
+
*/
|
|
440
|
+
text: string;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 标签颜色
|
|
444
|
+
* @description 标签的背景或边框颜色,可使用预设值或自定义色值
|
|
445
|
+
*/
|
|
446
|
+
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | string;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* 标签样式
|
|
450
|
+
* @description 标签的视觉风格
|
|
451
|
+
*/
|
|
452
|
+
variant?: 'filled' | 'outlined' | 'ghost';
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* 布局配置
|
|
457
|
+
*
|
|
458
|
+
* @description
|
|
459
|
+
* 控制项目的布局方式、尺寸和对齐方式等。
|
|
460
|
+
*/
|
|
461
|
+
export interface TuffLayout {
|
|
462
|
+
/**
|
|
463
|
+
* 展示方式
|
|
464
|
+
* @description 决定项目的基本布局模式
|
|
465
|
+
* @required
|
|
466
|
+
*/
|
|
467
|
+
display: 'list' | 'card' | 'grid' | 'compact' | 'detailed';
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* 网格配置
|
|
471
|
+
* @description display='grid' 时使用的网格布局参数
|
|
472
|
+
*/
|
|
473
|
+
grid?: {
|
|
474
|
+
/** 列数 */
|
|
475
|
+
columns?: number;
|
|
476
|
+
/** 间距 */
|
|
477
|
+
gap?: number;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* 尺寸配置
|
|
482
|
+
* @description 控制项目的整体大小
|
|
483
|
+
*/
|
|
484
|
+
size?: 'small' | 'medium' | 'large';
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 对齐方式
|
|
488
|
+
* @description 控制内容的水平对齐方式
|
|
489
|
+
*/
|
|
490
|
+
align?: 'left' | 'center' | 'right';
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 预览配置
|
|
495
|
+
*
|
|
496
|
+
* @description
|
|
497
|
+
* 用于悬停展示或详情面板的预览内容配置。
|
|
498
|
+
* 可以是简单的提示框,也可以是复杂的详情面板。
|
|
499
|
+
*/
|
|
500
|
+
export interface TuffPreview {
|
|
501
|
+
/**
|
|
502
|
+
* 预览类型
|
|
503
|
+
* @description 决定预览的展示方式
|
|
504
|
+
* @required
|
|
505
|
+
*/
|
|
506
|
+
type: 'tooltip' | 'panel' | 'modal';
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* 预览标题
|
|
510
|
+
* @description 预览内容的标题
|
|
511
|
+
*/
|
|
512
|
+
title?: string;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* 预览内容
|
|
516
|
+
* @description 预览的主体内容,通常是文本
|
|
517
|
+
*/
|
|
518
|
+
content?: string;
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* 预览图片
|
|
522
|
+
* @description 预览中显示的图片URL
|
|
523
|
+
*/
|
|
524
|
+
image?: string;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* 自定义预览组件
|
|
528
|
+
* @description 用于复杂预览内容的自定义渲染配置
|
|
529
|
+
*/
|
|
530
|
+
component?: TuffCustomRender;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 懒加载配置
|
|
534
|
+
* @description 是否延迟加载预览内容,直到需要显示时
|
|
535
|
+
*/
|
|
536
|
+
lazy?: boolean;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* 加载函数
|
|
540
|
+
* @description 用于异步加载预览内容的函数
|
|
541
|
+
*/
|
|
542
|
+
loader?: () => Promise<TuffPreview>;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// ==================== 交互行为系统 ====================
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* 交互行为定义
|
|
549
|
+
*
|
|
550
|
+
* @description
|
|
551
|
+
* 定义项目支持的操作和交互方式,如点击、右键菜单等。
|
|
552
|
+
* 每个项目可以有多个行为,系统会根据配置展示对应的操作选项。
|
|
553
|
+
*/
|
|
554
|
+
export interface TuffAction {
|
|
555
|
+
/**
|
|
556
|
+
* 行为唯一标识
|
|
557
|
+
* @description 用于识别和调用特定行为
|
|
558
|
+
* @required
|
|
559
|
+
*/
|
|
560
|
+
id: string;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* 行为类型
|
|
564
|
+
* @description 指定行为的基本类别,影响默认图标和处理逻辑
|
|
565
|
+
* @required
|
|
566
|
+
*/
|
|
567
|
+
type: TuffActionType;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* 行为标签
|
|
571
|
+
* @description 用于在界面中展示的行为名称
|
|
572
|
+
*/
|
|
573
|
+
label?: string;
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* 行为描述
|
|
577
|
+
* @description 对行为的详细说明,可能在悬停时显示
|
|
578
|
+
*/
|
|
579
|
+
description?: string;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* 行为图标
|
|
583
|
+
* @description 表示该行为的图标
|
|
584
|
+
*/
|
|
585
|
+
icon?: TuffIcon;
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* 快捷键
|
|
589
|
+
* @description 触发该行为的键盘快捷键
|
|
590
|
+
*/
|
|
591
|
+
shortcut?: string;
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* 行为参数
|
|
595
|
+
* @description 执行行为时需要的附加数据
|
|
596
|
+
*/
|
|
597
|
+
payload?: any;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* 是否为主要行为
|
|
601
|
+
* @description 标记为主要行为时,可能会获得视觉强调或作为默认操作
|
|
602
|
+
*/
|
|
603
|
+
primary?: boolean;
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* 行为条件
|
|
607
|
+
* @description 定义该行为何时可用的条件
|
|
608
|
+
*/
|
|
609
|
+
condition?: TuffCondition;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* 确认配置
|
|
613
|
+
* @description 执行前是否需要用户确认,以及确认的提示信息
|
|
614
|
+
*/
|
|
615
|
+
confirm?: {
|
|
616
|
+
/** 确认对话框标题 */
|
|
617
|
+
title: string;
|
|
618
|
+
/** 确认对话框内容 */
|
|
619
|
+
message: string;
|
|
620
|
+
/** 是否为危险操作,可能会有特殊样式 */
|
|
621
|
+
danger?: boolean;
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* 行为类型
|
|
627
|
+
*
|
|
628
|
+
* @description
|
|
629
|
+
* 定义行为的基本类别,系统会根据类型提供默认图标和处理逻辑
|
|
630
|
+
*/
|
|
631
|
+
export type TuffActionType =
|
|
632
|
+
| 'execute' // 执行命令/程序,运行应用或脚本
|
|
633
|
+
| 'open' // 打开文件/链接,访问资源
|
|
634
|
+
| 'navigate' // 导航跳转,切换视图或页面
|
|
635
|
+
| 'copy' // 复制内容,将信息复制到剪贴板
|
|
636
|
+
| 'preview' // 预览内容,查看详情但不完全打开
|
|
637
|
+
| 'edit' // 编辑,修改内容
|
|
638
|
+
| 'delete' // 删除,移除项目
|
|
639
|
+
| 'share' // 分享,发送给他人
|
|
640
|
+
| 'custom'; // 自定义行为,需要特殊处理
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* 行为执行条件
|
|
644
|
+
*
|
|
645
|
+
* @description
|
|
646
|
+
* 定义行为何时可用的条件,可以基于平台、权限、依赖等因素。
|
|
647
|
+
* 系统会根据这些条件决定是否显示和启用特定行为。
|
|
648
|
+
*/
|
|
649
|
+
export interface TuffCondition {
|
|
650
|
+
/**
|
|
651
|
+
* 平台限制
|
|
652
|
+
* @description 指定行为支持的操作系统平台
|
|
653
|
+
*/
|
|
654
|
+
platform?: ('win32' | 'darwin' | 'linux')[];
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* 权限要求
|
|
658
|
+
* @description 执行行为所需的最低权限级别
|
|
659
|
+
*/
|
|
660
|
+
permission?: TuffPermissionLevel;
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* 依赖检查
|
|
664
|
+
* @description 行为依赖的外部组件或服务
|
|
665
|
+
*/
|
|
666
|
+
dependencies?: string[];
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* 自定义条件函数
|
|
670
|
+
* @description 用于复杂条件判断的自定义函数
|
|
671
|
+
*/
|
|
672
|
+
check?: () => boolean | Promise<boolean>;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ==================== 评分与排序系统 ====================
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* 评分信息
|
|
679
|
+
*
|
|
680
|
+
* @description
|
|
681
|
+
* 用于搜索排序和推荐算法的评分数据。
|
|
682
|
+
* 系统会根据这些分数决定项目在结果中的排序和展示优先级。
|
|
683
|
+
*/
|
|
684
|
+
export interface TuffScoring {
|
|
685
|
+
/**
|
|
686
|
+
* 基础得分 (0-1)
|
|
687
|
+
* @description 项目的基础重要性分数
|
|
688
|
+
*/
|
|
689
|
+
base?: number;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* 匹配得分 (0-1)
|
|
693
|
+
* @description 与搜索查询的匹配程度
|
|
694
|
+
*/
|
|
695
|
+
match?: number;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* 使用频率得分 (0-1)
|
|
699
|
+
* @description 基于用户使用频率的分数
|
|
700
|
+
*/
|
|
701
|
+
frequency?: number;
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* 时间相关性得分 (0-1)
|
|
705
|
+
* @description 基于时间因素的相关性分数
|
|
706
|
+
*/
|
|
707
|
+
recency?: number;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* AI 推荐得分 (0-1)
|
|
711
|
+
* @description 基于AI分析的推荐强度
|
|
712
|
+
*/
|
|
713
|
+
ai?: number;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* 最终综合得分
|
|
717
|
+
* @description 综合各项因素计算的最终分数
|
|
718
|
+
*/
|
|
719
|
+
final?: number;
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* 排序权重
|
|
723
|
+
* @description 直接影响排序的权重值,越小越靠前
|
|
724
|
+
*/
|
|
725
|
+
priority?: number;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* 匹配详情
|
|
729
|
+
* @description 提供关于匹配过程的详细信息
|
|
730
|
+
*/
|
|
731
|
+
match_details?: {
|
|
732
|
+
/** 匹配类型 */
|
|
733
|
+
type: 'exact' | 'fuzzy' | 'semantic' | 'ai';
|
|
734
|
+
/** 匹配的查询文本 */
|
|
735
|
+
query: string;
|
|
736
|
+
/** 高亮显示的文本片段 */
|
|
737
|
+
highlights?: string[];
|
|
738
|
+
/** 匹配置信度 */
|
|
739
|
+
confidence?: number;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* 使用统计
|
|
744
|
+
* @description 记录用户对该项目的使用情况
|
|
745
|
+
*/
|
|
746
|
+
usage_stats?: {
|
|
747
|
+
/** 使用次数 */
|
|
748
|
+
count: number;
|
|
749
|
+
/** 最后使用时间 */
|
|
750
|
+
last_used?: Date;
|
|
751
|
+
/** 平均评分 */
|
|
752
|
+
avg_rating?: number;
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// ==================== 上下文信息 ====================
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* 上下文信息
|
|
760
|
+
*
|
|
761
|
+
* @description
|
|
762
|
+
* 用于AI推荐和关联分析的上下文数据。
|
|
763
|
+
* 包含用户状态、时间、位置等信息,帮助系统提供更智能的推荐。
|
|
764
|
+
*/
|
|
765
|
+
export interface TuffContext {
|
|
766
|
+
/**
|
|
767
|
+
* 会话ID
|
|
768
|
+
* @description 标识当前用户会话
|
|
769
|
+
*/
|
|
770
|
+
session?: string;
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* 用户当前状态
|
|
774
|
+
* @description 记录用户当前的工作环境和状态
|
|
775
|
+
*/
|
|
776
|
+
user_state?: {
|
|
777
|
+
/** 当前活动的应用 */
|
|
778
|
+
active_app?: string;
|
|
779
|
+
/** 当前打开的文件夹 */
|
|
780
|
+
current_folder?: string;
|
|
781
|
+
/** 最近访问的文件列表 */
|
|
782
|
+
recent_files?: string[];
|
|
783
|
+
/** 当前工作的项目 */
|
|
784
|
+
current_project?: string;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* 时间上下文
|
|
789
|
+
* @description 与时间相关的上下文信息
|
|
790
|
+
*/
|
|
791
|
+
temporal?: {
|
|
792
|
+
/** 创建时间 */
|
|
793
|
+
created_at?: Date;
|
|
794
|
+
/** 修改时间 */
|
|
795
|
+
modified_at?: Date;
|
|
796
|
+
/** 访问时间 */
|
|
797
|
+
accessed_at?: Date;
|
|
798
|
+
/** 一天中的时段 */
|
|
799
|
+
time_of_day?: 'morning' | 'afternoon' | 'evening' | 'night';
|
|
800
|
+
/** 星期几 */
|
|
801
|
+
day_of_week?: string;
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* 地理位置上下文
|
|
806
|
+
* @description 与位置相关的上下文信息
|
|
807
|
+
*/
|
|
808
|
+
location?: {
|
|
809
|
+
/** 国家 */
|
|
810
|
+
country?: string;
|
|
811
|
+
/** 城市 */
|
|
812
|
+
city?: string;
|
|
813
|
+
/** 时区 */
|
|
814
|
+
timezone?: string;
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* 工作上下文
|
|
819
|
+
* @description 与用户工作相关的上下文信息
|
|
820
|
+
*/
|
|
821
|
+
work_context?: {
|
|
822
|
+
/** 当前任务 */
|
|
823
|
+
current_task?: string;
|
|
824
|
+
/** 所属项目 */
|
|
825
|
+
project?: string;
|
|
826
|
+
/** 所属团队 */
|
|
827
|
+
team?: string;
|
|
828
|
+
/** 截止日期 */
|
|
829
|
+
deadline?: Date;
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* 关联项目
|
|
834
|
+
* @description 与当前项目相关的其他项目ID列表
|
|
835
|
+
*/
|
|
836
|
+
related_items?: string[];
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* 标签
|
|
840
|
+
* @description 用于分类和组织的标签列表
|
|
841
|
+
*/
|
|
842
|
+
tags?: string[];
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// ==================== 扩展元数据 ====================
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* 扩展元数据
|
|
849
|
+
*
|
|
850
|
+
* @description
|
|
851
|
+
* 携带额外的项目相关信息,根据项目类型提供不同的元数据。
|
|
852
|
+
* 可以包含文件信息、网络信息、应用信息等。
|
|
853
|
+
*/
|
|
854
|
+
export interface TuffMeta {
|
|
855
|
+
/**
|
|
856
|
+
* For plugin items, this holds the name of the plugin that generated the item.
|
|
857
|
+
* @description The name of the plugin.
|
|
858
|
+
*/
|
|
859
|
+
pluginName?: string
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* For plugin items, this holds the ID of the feature that generated the item.
|
|
863
|
+
* @description The ID of the feature.
|
|
864
|
+
*/
|
|
865
|
+
featureId?: string
|
|
866
|
+
/**
|
|
867
|
+
* Defines the default action to be taken when the item is executed (e.g., by pressing Enter).
|
|
868
|
+
* This is used to distinguish simple actions (like 'copy') from feature activations.
|
|
869
|
+
* @description The default action type.
|
|
870
|
+
*/
|
|
871
|
+
defaultAction?: string;
|
|
872
|
+
/**
|
|
873
|
+
* 原始数据
|
|
874
|
+
* @description 项目的原始数据对象,用于特殊处理
|
|
875
|
+
*/
|
|
876
|
+
raw?: any;
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* 文件信息
|
|
880
|
+
* @description 适用于文件类型的元数据
|
|
881
|
+
*/
|
|
882
|
+
file?: {
|
|
883
|
+
/** 文件路径 */
|
|
884
|
+
path: string;
|
|
885
|
+
/** 文件大小(字节) */
|
|
886
|
+
size?: number;
|
|
887
|
+
/** MIME类型 */
|
|
888
|
+
mime_type?: string;
|
|
889
|
+
/** 文件权限 */
|
|
890
|
+
permissions?: string;
|
|
891
|
+
/** 创建时间 */
|
|
892
|
+
created_at?: string;
|
|
893
|
+
/** 修改时间 */
|
|
894
|
+
modified_at?: string;
|
|
895
|
+
/** 文件扩展名(不带点) */
|
|
896
|
+
extension?: string;
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* 网络信息
|
|
901
|
+
* @description 适用于链接类型的元数据
|
|
902
|
+
*/
|
|
903
|
+
web?: {
|
|
904
|
+
/** 完整URL */
|
|
905
|
+
url: string;
|
|
906
|
+
/** 域名 */
|
|
907
|
+
domain?: string;
|
|
908
|
+
/** 页面标题 */
|
|
909
|
+
title?: string;
|
|
910
|
+
/** 页面描述 */
|
|
911
|
+
description?: string;
|
|
912
|
+
/** 网站图标 */
|
|
913
|
+
favicon?: string;
|
|
914
|
+
/** 页面截图 */
|
|
915
|
+
screenshot?: string;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* 应用信息
|
|
920
|
+
* @description 适用于应用类型的元数据
|
|
921
|
+
*/
|
|
922
|
+
app?: {
|
|
923
|
+
/** 应用包标识符 */
|
|
924
|
+
bundle_id?: string;
|
|
925
|
+
/** 应用版本 */
|
|
926
|
+
version?: string;
|
|
927
|
+
/** 应用路径 */
|
|
928
|
+
path?: string;
|
|
929
|
+
/** 应用图标 */
|
|
930
|
+
icon?: string;
|
|
931
|
+
/** 应用类别 */
|
|
932
|
+
category?: string;
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* 使用统计信息
|
|
937
|
+
* @description 用于在界面上展示触发次数等数据
|
|
938
|
+
*/
|
|
939
|
+
usage?: {
|
|
940
|
+
/** 被触发的次数 */
|
|
941
|
+
clickCount?: number;
|
|
942
|
+
/** 最近一次使用时间(ISO 字符串) */
|
|
943
|
+
lastUsed?: string;
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* 插件扩展字段
|
|
948
|
+
* @description 供插件存储自定义数据的字段
|
|
949
|
+
*/
|
|
950
|
+
extension?: Record<string, any>;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* 缓存配置
|
|
954
|
+
* @description 控制项目的缓存策略
|
|
955
|
+
*/
|
|
956
|
+
cache?: {
|
|
957
|
+
/** 缓存生存时间(秒) */
|
|
958
|
+
ttl?: number;
|
|
959
|
+
/** 缓存键 */
|
|
960
|
+
key?: string;
|
|
961
|
+
/** 缓存策略 */
|
|
962
|
+
strategy?: 'memory' | 'disk' | 'remote';
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* 安全信息
|
|
967
|
+
* @description 项目的安全相关元数据
|
|
968
|
+
*/
|
|
969
|
+
security?: {
|
|
970
|
+
/** 是否可信 */
|
|
971
|
+
trusted?: boolean;
|
|
972
|
+
/** 数字签名 */
|
|
973
|
+
signature?: string;
|
|
974
|
+
/** 所需权限列表 */
|
|
975
|
+
permissions?: string[];
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// ==================== 前端展示结构 ====================
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* 前端展示项
|
|
983
|
+
*
|
|
984
|
+
* @description
|
|
985
|
+
* 经过处理后供UI使用的结构,包含了渲染和交互所需的全部信息。
|
|
986
|
+
* 这是TuffItem在前端实际使用时的形态,添加了执行方法等能力。
|
|
987
|
+
*/
|
|
988
|
+
export interface TuffDisplayItem {
|
|
989
|
+
/**
|
|
990
|
+
* 唯一标识
|
|
991
|
+
* @description 项目的唯一标识符
|
|
992
|
+
* @required
|
|
993
|
+
*/
|
|
994
|
+
id: string;
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* 渲染信息
|
|
998
|
+
* @description 控制项目的视觉呈现
|
|
999
|
+
* @required
|
|
1000
|
+
*/
|
|
1001
|
+
render: TuffRender;
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* 可用操作
|
|
1005
|
+
* @description 项目支持的交互操作列表
|
|
1006
|
+
* @required
|
|
1007
|
+
*/
|
|
1008
|
+
actions: TuffDisplayAction[];
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* 评分信息
|
|
1012
|
+
* @description 用于排序和推荐的评分数据
|
|
1013
|
+
*/
|
|
1014
|
+
scoring?: TuffScoring;
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* 原始数据引用
|
|
1018
|
+
* @description 对原始TuffItem的引用
|
|
1019
|
+
* @required
|
|
1020
|
+
*/
|
|
1021
|
+
raw: TuffItem;
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* 执行主要操作
|
|
1025
|
+
* @description 执行项目的默认主要操作
|
|
1026
|
+
* @returns 操作执行的Promise
|
|
1027
|
+
* @required
|
|
1028
|
+
*/
|
|
1029
|
+
execute(): Promise<void>;
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* 获取预览内容
|
|
1033
|
+
* @description 获取项目的预览内容
|
|
1034
|
+
* @returns 预览内容的Promise
|
|
1035
|
+
*/
|
|
1036
|
+
getPreview?(): Promise<TuffPreview>;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* 前端展示操作
|
|
1041
|
+
*
|
|
1042
|
+
* @description
|
|
1043
|
+
* 包含调用能力的操作定义,扩展了TuffAction添加了执行方法。
|
|
1044
|
+
* 这是TuffAction在前端实际使用时的形态。
|
|
1045
|
+
*/
|
|
1046
|
+
export interface TuffDisplayAction extends Omit<TuffAction, 'payload'> {
|
|
1047
|
+
/**
|
|
1048
|
+
* 执行操作
|
|
1049
|
+
* @description 执行该操作的方法
|
|
1050
|
+
* @param context 执行上下文
|
|
1051
|
+
* @returns 操作执行结果
|
|
1052
|
+
* @required
|
|
1053
|
+
*/
|
|
1054
|
+
execute(context?: any): Promise<any>;
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* 检查是否可用
|
|
1058
|
+
* @description 检查当前环境下该操作是否可用
|
|
1059
|
+
* @returns 是否可用的Promise
|
|
1060
|
+
* @required
|
|
1061
|
+
*/
|
|
1062
|
+
isAvailable(): Promise<boolean>;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// ==================== 工具类型 ====================
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* 搜索查询结构
|
|
1069
|
+
*
|
|
1070
|
+
* @description
|
|
1071
|
+
* 定义搜索请求的参数和过滤条件。
|
|
1072
|
+
* 系统根据这些参数执行搜索并返回匹配结果。
|
|
1073
|
+
*/
|
|
1074
|
+
export interface TuffQuery {
|
|
1075
|
+
/**
|
|
1076
|
+
* 查询文本
|
|
1077
|
+
* @description 用户输入的搜索文本
|
|
1078
|
+
* @required
|
|
1079
|
+
*/
|
|
1080
|
+
text: string;
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* 查询类型
|
|
1084
|
+
* @description 指定查询的输入方式
|
|
1085
|
+
*/
|
|
1086
|
+
type?: 'text' | 'voice' | 'image';
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* 过滤条件
|
|
1090
|
+
* @description 限制搜索范围的过滤器
|
|
1091
|
+
*/
|
|
1092
|
+
filters?: {
|
|
1093
|
+
/** 限制结果类型 */
|
|
1094
|
+
kinds?: TuffItemKind[];
|
|
1095
|
+
/** 限制结果来源 */
|
|
1096
|
+
sources?: string[];
|
|
1097
|
+
/** 限制结果时间范围 */
|
|
1098
|
+
date_range?: [Date, Date];
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* 排序方式
|
|
1103
|
+
* @description 结果的排序策略
|
|
1104
|
+
*/
|
|
1105
|
+
sort?: 'relevance' | 'date' | 'frequency' | 'name';
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* 分页信息
|
|
1109
|
+
* @description 控制结果的分页
|
|
1110
|
+
*/
|
|
1111
|
+
pagination?: {
|
|
1112
|
+
/** 起始偏移量 */
|
|
1113
|
+
offset: number;
|
|
1114
|
+
/** 每页数量限制 */
|
|
1115
|
+
limit: number;
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* 上下文信息
|
|
1120
|
+
* @description 提供搜索的上下文数据
|
|
1121
|
+
*/
|
|
1122
|
+
context?: TuffContext;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* Represents the statistics for a single sort middleware.
|
|
1127
|
+
*/
|
|
1128
|
+
export interface SortStat {
|
|
1129
|
+
/** The name of the sorting middleware. */
|
|
1130
|
+
name: string
|
|
1131
|
+
/** The time taken by the middleware in milliseconds. */
|
|
1132
|
+
duration: number
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* 搜索结果结构
|
|
1137
|
+
*
|
|
1138
|
+
* @description
|
|
1139
|
+
* 定义搜索返回的结果集合和元数据。
|
|
1140
|
+
* 包含匹配项、统计信息和分页数据等。
|
|
1141
|
+
*/
|
|
1142
|
+
export interface TuffSearchResult {
|
|
1143
|
+
/**
|
|
1144
|
+
* A unique identifier for this specific search operation.
|
|
1145
|
+
* This is crucial for the streaming model to associate updates with the correct search instance.
|
|
1146
|
+
*/
|
|
1147
|
+
sessionId?: string;
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* 结果项目
|
|
1151
|
+
* @description 匹配的TuffItem列表
|
|
1152
|
+
* @required
|
|
1153
|
+
*/
|
|
1154
|
+
items: TuffItem[];
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* 查询信息
|
|
1158
|
+
* @description 原始查询参数
|
|
1159
|
+
* @required
|
|
1160
|
+
*/
|
|
1161
|
+
query: TuffQuery;
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* 搜索耗时
|
|
1165
|
+
* @description 搜索执行的毫秒数
|
|
1166
|
+
* @required
|
|
1167
|
+
*/
|
|
1168
|
+
duration: number;
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* 来源统计
|
|
1172
|
+
* @description 各数据来源的结果统计
|
|
1173
|
+
* @required
|
|
1174
|
+
*/
|
|
1175
|
+
sources: Array<{
|
|
1176
|
+
/** Provider's unique ID. */
|
|
1177
|
+
providerId: string;
|
|
1178
|
+
/** Provider's display name. */
|
|
1179
|
+
providerName: string;
|
|
1180
|
+
/** Search duration in milliseconds. */
|
|
1181
|
+
duration: number;
|
|
1182
|
+
/** Number of results returned. */
|
|
1183
|
+
resultCount: number;
|
|
1184
|
+
/** Status of the search operation. */
|
|
1185
|
+
status: 'success' | 'timeout' | 'error';
|
|
1186
|
+
}>;
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* AI 推荐
|
|
1190
|
+
* @description AI生成的搜索建议
|
|
1191
|
+
*/
|
|
1192
|
+
suggestions?: string[];
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* The provider(s) to activate after this search result.
|
|
1196
|
+
*/
|
|
1197
|
+
activate?: IProviderActivate[];
|
|
1198
|
+
|
|
1199
|
+
/** Optional statistics about the sorting process. */
|
|
1200
|
+
sort_stats?: SortStat[]
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
export interface IProviderActivate {
|
|
1204
|
+
id: string
|
|
1205
|
+
name?: string
|
|
1206
|
+
icon?: TuffIcon
|
|
1207
|
+
time?: number
|
|
1208
|
+
meta?: Record<string, any>
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Defines the interface for a sort middleware.
|
|
1214
|
+
* Each middleware receives an array of items and should return a sorted array.
|
|
1215
|
+
*/
|
|
1216
|
+
export interface ISortMiddleware {
|
|
1217
|
+
/** A unique name for the middleware, used for logging and stats. */
|
|
1218
|
+
readonly name: string
|
|
1219
|
+
/**
|
|
1220
|
+
* The sort function that processes the items.
|
|
1221
|
+
* @param items - The array of TuffItems to be sorted.
|
|
1222
|
+
* @param query - The original search query for context.
|
|
1223
|
+
* @param signal - An AbortSignal to cancel the sorting operation.
|
|
1224
|
+
* @returns A sorted array of TuffItems.
|
|
1225
|
+
*/
|
|
1226
|
+
sort(items: TuffItem[], query: TuffQuery, signal: AbortSignal): TuffItem[]
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Search Provider Interface (formerly ISearchSource)
|
|
1231
|
+
*
|
|
1232
|
+
* Defines the contract for any module that provides search results to the engine.
|
|
1233
|
+
* It's a simplified, stateless interface focused solely on providing results for a given query.
|
|
1234
|
+
*/
|
|
1235
|
+
export interface IExecuteArgs {
|
|
1236
|
+
item: TuffItem
|
|
1237
|
+
searchResult?: TuffSearchResult
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
export interface ISearchProvider<C> {
|
|
1241
|
+
/**
|
|
1242
|
+
* Unique identifier for the provider, e.g., "mac-applications", "file-system", "clipboard-history"
|
|
1243
|
+
* @required
|
|
1244
|
+
*/
|
|
1245
|
+
readonly id: string
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* The type of the source, used for categorization and filtering.
|
|
1249
|
+
* @required
|
|
1250
|
+
*/
|
|
1251
|
+
readonly type: TuffSourceType
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* User-friendly name for the provider, displayed in settings or logs.
|
|
1255
|
+
*/
|
|
1256
|
+
readonly name?: string
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Icon for the provider.
|
|
1260
|
+
*/
|
|
1261
|
+
readonly icon?: any
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* Core search method (PULL mode).
|
|
1265
|
+
* The engine calls this method to get results from the provider.
|
|
1266
|
+
*
|
|
1267
|
+
* @param query - The search query object, containing text and other context.
|
|
1268
|
+
* @param signal - An AbortSignal to cancel the search operation.
|
|
1269
|
+
* @returns A promise that resolves to a full TuffSearchResult object, allowing the provider
|
|
1270
|
+
* to influence the final result, including the next activation state.
|
|
1271
|
+
*/
|
|
1272
|
+
onSearch(query: TuffQuery, signal: AbortSignal): Promise<TuffSearchResult>
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Optional method to handle activation.
|
|
1276
|
+
* Called when the provider is prioritized, e.g., via an activation keyword.
|
|
1277
|
+
*/
|
|
1278
|
+
onActivate?(): void
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* Optional method to handle deactivation.
|
|
1282
|
+
*/
|
|
1283
|
+
onDeactivate?(): void
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Optional method to execute an item.
|
|
1287
|
+
* @param args The arguments for execution, including the item and search context.
|
|
1288
|
+
* @returns A promise that resolves to an activation object if the provider should be
|
|
1289
|
+
* activated, or `null` otherwise.
|
|
1290
|
+
*/
|
|
1291
|
+
onExecute?(args: IExecuteArgs): Promise<IProviderActivate | null>
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Optional method to load provider.
|
|
1295
|
+
* @param context The context of the provider.
|
|
1296
|
+
*/
|
|
1297
|
+
onLoad?(context: C): Promise<void>
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// ==================== 插件接口预览 ====================
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* 插件搜索接口
|
|
1304
|
+
*
|
|
1305
|
+
* @description
|
|
1306
|
+
* 定义插件实现搜索功能的标准接口。
|
|
1307
|
+
* 这是一个简化版预览,实际插件系统可能更复杂。
|
|
1308
|
+
*/
|
|
1309
|
+
export interface TuffSearchProvider {
|
|
1310
|
+
/**
|
|
1311
|
+
* 插件信息
|
|
1312
|
+
* @description 插件的基本信息
|
|
1313
|
+
* @required
|
|
1314
|
+
*/
|
|
1315
|
+
info: {
|
|
1316
|
+
/** 插件唯一标识 */
|
|
1317
|
+
id: string;
|
|
1318
|
+
/** 插件名称 */
|
|
1319
|
+
name: string;
|
|
1320
|
+
/** 插件版本 */
|
|
1321
|
+
version: string;
|
|
1322
|
+
/** 插件描述 */
|
|
1323
|
+
description: string;
|
|
1324
|
+
/** 插件作者 */
|
|
1325
|
+
author: string;
|
|
1326
|
+
/** 插件图标 */
|
|
1327
|
+
icon?: TuffIcon;
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* 搜索能力配置
|
|
1332
|
+
* @description 定义插件支持的搜索能力
|
|
1333
|
+
* @required
|
|
1334
|
+
*/
|
|
1335
|
+
capabilities: {
|
|
1336
|
+
/**
|
|
1337
|
+
* 支持的查询类型
|
|
1338
|
+
* @description 插件能处理的输入类型
|
|
1339
|
+
* @required
|
|
1340
|
+
*/
|
|
1341
|
+
query_types: ('text' | 'voice' | 'image')[];
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* 支持的项目类型
|
|
1345
|
+
* @description 插件能提供的结果类型
|
|
1346
|
+
* @required
|
|
1347
|
+
*/
|
|
1348
|
+
item_kinds: TuffItemKind[];
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* 是否支持实时搜索
|
|
1352
|
+
* @description 是否支持输入时实时返回结果
|
|
1353
|
+
* @required
|
|
1354
|
+
*/
|
|
1355
|
+
realtime: boolean;
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* 是否支持 AI 增强
|
|
1359
|
+
* @description 是否使用AI技术增强搜索结果
|
|
1360
|
+
* @required
|
|
1361
|
+
*/
|
|
1362
|
+
ai_enhanced: boolean;
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* 权限要求
|
|
1366
|
+
* @description 插件需要的权限级别
|
|
1367
|
+
* @required
|
|
1368
|
+
*/
|
|
1369
|
+
permissions: TuffPermissionLevel;
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* 搜索方法
|
|
1374
|
+
* @description 执行搜索并返回结果
|
|
1375
|
+
* @param query 搜索查询参数
|
|
1376
|
+
* @returns 搜索结果Promise
|
|
1377
|
+
* @required
|
|
1378
|
+
*/
|
|
1379
|
+
search(query: TuffQuery): Promise<TuffItem[]>;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* 获取推荐项
|
|
1383
|
+
* @description 根据上下文提供推荐项目
|
|
1384
|
+
* @param context 上下文信息
|
|
1385
|
+
* @returns 推荐项目Promise
|
|
1386
|
+
*/
|
|
1387
|
+
getRecommendations?(context: TuffContext): Promise<TuffItem[]>;
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* 执行操作
|
|
1391
|
+
* @description 执行特定操作
|
|
1392
|
+
* @param action_id 操作ID
|
|
1393
|
+
* @param payload 操作参数
|
|
1394
|
+
* @returns 操作结果Promise
|
|
1395
|
+
* @required
|
|
1396
|
+
*/
|
|
1397
|
+
executeAction(action_id: string, payload: any): Promise<any>;
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* 激活钩子
|
|
1401
|
+
* @description 插件被激活时调用
|
|
1402
|
+
* @returns 完成Promise
|
|
1403
|
+
*/
|
|
1404
|
+
onActivate?(): Promise<void>;
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* 停用钩子
|
|
1408
|
+
* @description 插件被停用时调用
|
|
1409
|
+
* @returns 完成Promise
|
|
1410
|
+
*/
|
|
1411
|
+
onDeactivate?(): Promise<void>;
|
|
1412
|
+
}
|