@talex-touch/utils 1.0.14 → 1.0.16
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/base/index.ts +181 -181
- package/channel/index.ts +108 -99
- package/common/index.ts +2 -39
- package/common/storage/constants.ts +3 -0
- package/common/storage/entity/app-settings.ts +47 -0
- package/common/storage/entity/index.ts +1 -0
- package/common/storage/index.ts +3 -0
- package/common/utils.ts +160 -0
- package/core-box/README.md +218 -0
- package/core-box/index.ts +7 -0
- package/core-box/search.ts +536 -0
- package/core-box/types.ts +384 -0
- package/electron/download-manager.ts +118 -0
- package/{common → electron}/env-tool.ts +56 -56
- package/electron/touch-core.ts +167 -0
- package/electron/window.ts +71 -0
- package/eventbus/index.ts +86 -87
- package/index.ts +5 -0
- package/package.json +55 -30
- package/permission/index.ts +48 -48
- package/plugin/channel.ts +203 -193
- package/plugin/index.ts +216 -121
- package/plugin/log/logger-manager.ts +60 -0
- package/plugin/log/logger.ts +75 -0
- package/plugin/log/types.ts +27 -0
- package/plugin/preload.ts +39 -39
- package/plugin/sdk/common.ts +27 -27
- package/plugin/sdk/hooks/life-cycle.ts +95 -95
- package/plugin/sdk/index.ts +18 -13
- package/plugin/sdk/service/index.ts +29 -29
- package/plugin/sdk/types.ts +578 -0
- package/plugin/sdk/window/index.ts +40 -40
- package/renderer/index.ts +2 -0
- package/renderer/ref.ts +54 -54
- package/renderer/slots.ts +124 -0
- package/renderer/storage/app-settings.ts +34 -0
- package/renderer/storage/base-storage.ts +335 -0
- package/renderer/storage/index.ts +1 -0
- package/search/types.ts +726 -0
- package/service/index.ts +67 -67
- package/service/protocol/index.ts +77 -77
package/search/types.ts
ADDED
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Search Types and Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive type definitions and utility functions
|
|
5
|
+
* for search result items across the Talex Touch application. It defines
|
|
6
|
+
* the core interfaces and factory functions used by the search system,
|
|
7
|
+
* plugins, and UI components.
|
|
8
|
+
*
|
|
9
|
+
* Key exports:
|
|
10
|
+
* - {@link ISearchItem} - Core search result item interface
|
|
11
|
+
* - {@link IDataItem} - Extended interface for data processing results
|
|
12
|
+
* - {@link createDataItem} - Factory function for creating data items
|
|
13
|
+
*
|
|
14
|
+
* @author Talex Touch Team
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
* @version 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { IPluginIcon, IFeatureCommand } from '../plugin';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Search Result Item Interface
|
|
23
|
+
*
|
|
24
|
+
* Unified data structure definition for search results, maintaining consistency
|
|
25
|
+
* with SearchItem in app/core/src/views/box/search-box.ts
|
|
26
|
+
*
|
|
27
|
+
* This interface serves as the foundation for all search result items across
|
|
28
|
+
* the application, ensuring type safety and consistent data handling.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
* @since 2.0.0
|
|
32
|
+
*/
|
|
33
|
+
export interface ISearchItem {
|
|
34
|
+
/**
|
|
35
|
+
* Display name of the search result item
|
|
36
|
+
*
|
|
37
|
+
* This is the primary text shown to users in search results.
|
|
38
|
+
* Should be concise and descriptive.
|
|
39
|
+
*
|
|
40
|
+
* @example "Calculator" for an application
|
|
41
|
+
* @example "Translate Text" for a plugin feature
|
|
42
|
+
*/
|
|
43
|
+
name: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Description or subtitle of the search result item
|
|
47
|
+
*
|
|
48
|
+
* Provides additional context about the item, such as file paths,
|
|
49
|
+
* feature descriptions, or application details.
|
|
50
|
+
*
|
|
51
|
+
* @example "/Applications/Calculator.app" for an application
|
|
52
|
+
* @example "Translate text using Google Translate" for a feature
|
|
53
|
+
*/
|
|
54
|
+
desc: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Icon configuration for visual representation
|
|
58
|
+
*
|
|
59
|
+
* Defines how the item's icon should be displayed in the UI.
|
|
60
|
+
* Supports various icon types including files, remix icons, and data URLs.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link IPluginIcon} for icon configuration options
|
|
63
|
+
*/
|
|
64
|
+
icon: IPluginIcon;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether this item supports push mode functionality
|
|
68
|
+
*
|
|
69
|
+
* Push mode allows items to dynamically update their content or
|
|
70
|
+
* provide interactive features beyond simple execution.
|
|
71
|
+
*
|
|
72
|
+
* @defaultValue false
|
|
73
|
+
* @example true for plugin features that accept user input
|
|
74
|
+
* @example false for simple applications or static items
|
|
75
|
+
*/
|
|
76
|
+
push: boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* List of feature commands associated with this item
|
|
80
|
+
*
|
|
81
|
+
* Commands provide additional actions that can be performed on this item.
|
|
82
|
+
* Only applicable for plugin features that support multiple operations.
|
|
83
|
+
*
|
|
84
|
+
* @optional
|
|
85
|
+
* @see {@link IFeatureCommand} for command structure
|
|
86
|
+
*/
|
|
87
|
+
commands?: IFeatureCommand[];
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Array of searchable names for this item
|
|
91
|
+
*
|
|
92
|
+
* Alternative names that can be used to find this item in search.
|
|
93
|
+
* Typically includes the primary name and common variations.
|
|
94
|
+
*
|
|
95
|
+
* @example ["Calculator", "Calc", "Math"] for a calculator app
|
|
96
|
+
*/
|
|
97
|
+
names: string[];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Array of keywords for search matching
|
|
101
|
+
*
|
|
102
|
+
* Additional terms that should match this item in search results.
|
|
103
|
+
* Includes synonyms, categories, and related terms.
|
|
104
|
+
*
|
|
105
|
+
* @example ["math", "arithmetic", "numbers"] for a calculator
|
|
106
|
+
*/
|
|
107
|
+
keyWords: string[];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Type of plugin this item belongs to
|
|
111
|
+
*
|
|
112
|
+
* Categorizes the item by its plugin type for filtering and sorting.
|
|
113
|
+
* Common values include "app", "feature", "file", "cmd".
|
|
114
|
+
*
|
|
115
|
+
* @example "app" for applications
|
|
116
|
+
* @example "feature" for plugin features
|
|
117
|
+
* @example "file" for file system items
|
|
118
|
+
*/
|
|
119
|
+
pluginType: string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* General type classification of the item
|
|
123
|
+
*
|
|
124
|
+
* Broader categorization used for grouping and display logic.
|
|
125
|
+
* Often matches pluginType but can be more generic.
|
|
126
|
+
*
|
|
127
|
+
* @example "plugin" for plugin-based items
|
|
128
|
+
* @example "app" for applications
|
|
129
|
+
*/
|
|
130
|
+
type: string;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Associated value, typically the plugin name or identifier
|
|
134
|
+
*
|
|
135
|
+
* Links this item to its source plugin or system component.
|
|
136
|
+
* Used for routing actions and maintaining relationships.
|
|
137
|
+
*
|
|
138
|
+
* @example "calculator-plugin" for a plugin feature
|
|
139
|
+
* @example "system" for built-in functionality
|
|
140
|
+
*/
|
|
141
|
+
value: string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Usage frequency counter for ranking and sorting
|
|
145
|
+
*
|
|
146
|
+
* Tracks how often this item has been selected or used.
|
|
147
|
+
* Higher values indicate more frequently used items.
|
|
148
|
+
*
|
|
149
|
+
* @optional
|
|
150
|
+
* @defaultValue 0
|
|
151
|
+
* @minimum 0
|
|
152
|
+
*/
|
|
153
|
+
amo?: number;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Matching information from search algorithms
|
|
157
|
+
*
|
|
158
|
+
* Contains details about how this item matched the search query.
|
|
159
|
+
* Used for highlighting and relevance scoring.
|
|
160
|
+
*
|
|
161
|
+
* @optional
|
|
162
|
+
* @internal Used by search algorithms
|
|
163
|
+
*/
|
|
164
|
+
matched?: any;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Whether this item was matched by its name
|
|
168
|
+
*
|
|
169
|
+
* Indicates if the search match occurred against the item's name field.
|
|
170
|
+
* Used for determining match quality and highlighting.
|
|
171
|
+
*
|
|
172
|
+
* @optional
|
|
173
|
+
* @defaultValue false
|
|
174
|
+
*/
|
|
175
|
+
matchedByName?: boolean;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Whether this item was matched by its description
|
|
179
|
+
*
|
|
180
|
+
* Indicates if the search match occurred against the item's description.
|
|
181
|
+
* Typically has lower priority than name matches.
|
|
182
|
+
*
|
|
183
|
+
* @optional
|
|
184
|
+
* @defaultValue false
|
|
185
|
+
*/
|
|
186
|
+
descMatched?: boolean;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Whether this item was matched by abbreviation
|
|
190
|
+
*
|
|
191
|
+
* Indicates if the search match occurred against abbreviated forms
|
|
192
|
+
* of the item's name or keywords.
|
|
193
|
+
*
|
|
194
|
+
* @optional
|
|
195
|
+
* @defaultValue false
|
|
196
|
+
*/
|
|
197
|
+
abridgeMatched?: boolean;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Unique identifier for this search item
|
|
201
|
+
*
|
|
202
|
+
* Optional unique ID that can be used to distinguish items
|
|
203
|
+
* with similar names or for caching purposes.
|
|
204
|
+
*
|
|
205
|
+
* @optional
|
|
206
|
+
* @example "app-calculator-v1.0"
|
|
207
|
+
* @example "feature-translate-google"
|
|
208
|
+
*/
|
|
209
|
+
id?: string;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Action to execute when this item is selected
|
|
213
|
+
*
|
|
214
|
+
* Command or action string that defines what happens when
|
|
215
|
+
* the user selects this item. Format varies by item type.
|
|
216
|
+
*
|
|
217
|
+
* @optional
|
|
218
|
+
* @example "open /Applications/Calculator.app" for applications
|
|
219
|
+
* @example "translate:google" for plugin features
|
|
220
|
+
*/
|
|
221
|
+
action?: string;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Reference to original feature object for command matching
|
|
225
|
+
*
|
|
226
|
+
* Used internally for items that are derived from plugin features.
|
|
227
|
+
* Maintains a link to the original feature for command resolution.
|
|
228
|
+
*
|
|
229
|
+
* @optional
|
|
230
|
+
* @internal Used by plugin system
|
|
231
|
+
*/
|
|
232
|
+
originFeature?: ISearchItem;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Additional properties for extensibility
|
|
236
|
+
*
|
|
237
|
+
* Allows for custom properties to be added to search items
|
|
238
|
+
* without breaking the interface contract. Use sparingly
|
|
239
|
+
* and prefer explicit properties when possible.
|
|
240
|
+
*
|
|
241
|
+
* @example { customData: "value", metadata: { source: "api" } }
|
|
242
|
+
*/
|
|
243
|
+
[key: string]: any;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Generic Data Item Interface
|
|
248
|
+
*
|
|
249
|
+
* Extended search item interface for various types of data processing results.
|
|
250
|
+
* Inherits all properties from ISearchItem and adds data-specific fields
|
|
251
|
+
* for tracking processing metadata, quality metrics, and source information.
|
|
252
|
+
*
|
|
253
|
+
* Commonly used for:
|
|
254
|
+
* - Translation results
|
|
255
|
+
* - Text analysis outputs
|
|
256
|
+
* - Format conversion results
|
|
257
|
+
* - API response data
|
|
258
|
+
* - Computed values
|
|
259
|
+
*
|
|
260
|
+
* @public
|
|
261
|
+
* @extends ISearchItem
|
|
262
|
+
* @since 1.0.0
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const translationResult: IDataItem = {
|
|
267
|
+
* name: "Hello World",
|
|
268
|
+
* desc: "English to Chinese translation",
|
|
269
|
+
* // ... other ISearchItem properties
|
|
270
|
+
* source: "google-translate",
|
|
271
|
+
* dataType: "translation",
|
|
272
|
+
* originalData: "Hello World",
|
|
273
|
+
* processedData: "你好世界",
|
|
274
|
+
* confidence: 95,
|
|
275
|
+
* duration: 120,
|
|
276
|
+
* cached: false
|
|
277
|
+
* };
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export interface IDataItem extends ISearchItem {
|
|
281
|
+
/**
|
|
282
|
+
* Source service or system that generated this data
|
|
283
|
+
*
|
|
284
|
+
* Identifies the origin of the processed data, such as an API service,
|
|
285
|
+
* local processor, or external tool. Useful for debugging and analytics.
|
|
286
|
+
*
|
|
287
|
+
* @optional
|
|
288
|
+
* @example "google-translate"
|
|
289
|
+
* @example "local-analyzer"
|
|
290
|
+
* @example "openai-api"
|
|
291
|
+
*/
|
|
292
|
+
source?: string;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Type of data processing performed
|
|
296
|
+
*
|
|
297
|
+
* Categorizes the kind of data transformation or analysis that was applied.
|
|
298
|
+
* Used for filtering, grouping, and applying type-specific logic.
|
|
299
|
+
*
|
|
300
|
+
* @optional
|
|
301
|
+
* @example "translation"
|
|
302
|
+
* @example "analysis"
|
|
303
|
+
* @example "conversion"
|
|
304
|
+
* @example "summarization"
|
|
305
|
+
*/
|
|
306
|
+
dataType?: string;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Original input data before processing
|
|
310
|
+
*
|
|
311
|
+
* Preserves the raw input that was provided to the processing system.
|
|
312
|
+
* Can be any type depending on the processing context.
|
|
313
|
+
*
|
|
314
|
+
* @optional
|
|
315
|
+
* @example "Hello World" for translation input
|
|
316
|
+
* @example { text: "...", options: {...} } for complex inputs
|
|
317
|
+
*/
|
|
318
|
+
originalData?: any;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Processed output data
|
|
322
|
+
*
|
|
323
|
+
* Contains the result of the data processing operation.
|
|
324
|
+
* Type varies based on the processing performed.
|
|
325
|
+
*
|
|
326
|
+
* @optional
|
|
327
|
+
* @example "你好世界" for translation output
|
|
328
|
+
* @example { summary: "...", keywords: [...] } for analysis results
|
|
329
|
+
*/
|
|
330
|
+
processedData?: any;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Quality score of the processing result (0-100)
|
|
334
|
+
*
|
|
335
|
+
* Numerical assessment of the processing quality or accuracy.
|
|
336
|
+
* Higher values indicate better quality results.
|
|
337
|
+
*
|
|
338
|
+
* @optional
|
|
339
|
+
* @minimum 0
|
|
340
|
+
* @maximum 100
|
|
341
|
+
* @example 95 for high-quality translation
|
|
342
|
+
* @example 78 for moderate-quality analysis
|
|
343
|
+
*/
|
|
344
|
+
quality?: number;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Whether this result was retrieved from cache
|
|
348
|
+
*
|
|
349
|
+
* Indicates if the result came from a cached previous computation
|
|
350
|
+
* rather than fresh processing. Useful for performance tracking.
|
|
351
|
+
*
|
|
352
|
+
* @optional
|
|
353
|
+
* @defaultValue false
|
|
354
|
+
*/
|
|
355
|
+
cached?: boolean;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Processing time in milliseconds
|
|
359
|
+
*
|
|
360
|
+
* Time taken to generate this result, excluding any caching.
|
|
361
|
+
* Used for performance monitoring and user feedback.
|
|
362
|
+
*
|
|
363
|
+
* @optional
|
|
364
|
+
* @minimum 0
|
|
365
|
+
* @example 120 for a 120ms processing time
|
|
366
|
+
* @example 1500 for a 1.5 second operation
|
|
367
|
+
*/
|
|
368
|
+
duration?: number;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Confidence level of the result (0-100)
|
|
372
|
+
*
|
|
373
|
+
* Statistical confidence or certainty in the processing result.
|
|
374
|
+
* Different from quality - indicates algorithmic confidence.
|
|
375
|
+
*
|
|
376
|
+
* @optional
|
|
377
|
+
* @minimum 0
|
|
378
|
+
* @maximum 100
|
|
379
|
+
* @example 92 for high-confidence translation
|
|
380
|
+
* @example 67 for moderate-confidence analysis
|
|
381
|
+
*/
|
|
382
|
+
confidence?: number;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Additional metadata about the processing
|
|
386
|
+
*
|
|
387
|
+
* Flexible container for any additional information about
|
|
388
|
+
* the processing operation, source, or result context.
|
|
389
|
+
*
|
|
390
|
+
* @optional
|
|
391
|
+
* @example { apiVersion: "v2", model: "gpt-4", tokens: 150 }
|
|
392
|
+
* @example { processingNode: "server-1", retryCount: 0 }
|
|
393
|
+
*/
|
|
394
|
+
metadata?: Record<string, any>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 搜索模式枚举
|
|
399
|
+
*/
|
|
400
|
+
export enum SearchMode {
|
|
401
|
+
INPUT = 'INPUT',
|
|
402
|
+
COMMAND = 'COMMAND',
|
|
403
|
+
IMAGE = 'IMAGE',
|
|
404
|
+
FILE = 'FILE',
|
|
405
|
+
FEATURE = 'FEATURE'
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 搜索选项接口
|
|
410
|
+
*/
|
|
411
|
+
export interface ISearchOptions {
|
|
412
|
+
/** 搜索模式 */
|
|
413
|
+
mode: SearchMode;
|
|
414
|
+
|
|
415
|
+
/** 最大结果数量 */
|
|
416
|
+
maxResults?: number;
|
|
417
|
+
|
|
418
|
+
/** 是否启用模糊匹配 */
|
|
419
|
+
fuzzyMatch?: boolean;
|
|
420
|
+
|
|
421
|
+
/** 搜索超时时间(毫秒) */
|
|
422
|
+
timeout?: number;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 插件搜索结果推送接口
|
|
427
|
+
*/
|
|
428
|
+
export interface IPluginSearchResult {
|
|
429
|
+
/** 插件名称 */
|
|
430
|
+
pluginName: string;
|
|
431
|
+
|
|
432
|
+
/** 搜索结果列表 */
|
|
433
|
+
items: ISearchItem[];
|
|
434
|
+
|
|
435
|
+
/** 推送时间戳 */
|
|
436
|
+
timestamp: number;
|
|
437
|
+
|
|
438
|
+
/** 查询关键词 */
|
|
439
|
+
query: string;
|
|
440
|
+
|
|
441
|
+
/** 结果总数 */
|
|
442
|
+
total: number;
|
|
443
|
+
|
|
444
|
+
/** 是否有更多结果 */
|
|
445
|
+
hasMore?: boolean;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* 搜索结果管理器接口
|
|
450
|
+
*/
|
|
451
|
+
export interface ISearchResultManager {
|
|
452
|
+
/** 推送搜索结果 */
|
|
453
|
+
pushItems(items: ISearchItem[]): void;
|
|
454
|
+
|
|
455
|
+
/** 清空搜索结果 */
|
|
456
|
+
clearItems(): void;
|
|
457
|
+
|
|
458
|
+
/** 获取当前搜索结果 */
|
|
459
|
+
getItems(): ISearchItem[];
|
|
460
|
+
|
|
461
|
+
/** 更新单个搜索结果 */
|
|
462
|
+
updateItem(id: string, item: Partial<ISearchItem>): boolean;
|
|
463
|
+
|
|
464
|
+
/** 删除单个搜索结果 */
|
|
465
|
+
removeItem(id: string): boolean;
|
|
466
|
+
|
|
467
|
+
/** 获取结果数量 */
|
|
468
|
+
getCount(): number;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Creates a data processing result item
|
|
473
|
+
*
|
|
474
|
+
* Factory function for creating IDataItem instances with proper defaults
|
|
475
|
+
* and validation. Handles the common pattern of converting processed data
|
|
476
|
+
* into searchable items with metadata tracking.
|
|
477
|
+
*
|
|
478
|
+
* This function is particularly useful for plugins that perform data
|
|
479
|
+
* transformations, API calls, or analysis operations and need to present
|
|
480
|
+
* their results in the search interface.
|
|
481
|
+
*
|
|
482
|
+
* @param options - Configuration object for the data item
|
|
483
|
+
* @param options.name - Display name for the processed result
|
|
484
|
+
* @param options.desc - Description of the processing or result
|
|
485
|
+
* @param options.pluginName - Name of the plugin that created this item
|
|
486
|
+
* @param options.source - Optional source identifier (e.g., "google-api")
|
|
487
|
+
* @param options.dataType - Optional type of processing (e.g., "translation")
|
|
488
|
+
* @param options.originalData - Optional input data before processing
|
|
489
|
+
* @param options.processedData - Optional output data after processing
|
|
490
|
+
* @param options.quality - Optional quality score (0-100)
|
|
491
|
+
* @param options.cached - Optional flag indicating cached result
|
|
492
|
+
* @param options.duration - Optional processing time in milliseconds
|
|
493
|
+
* @param options.confidence - Optional confidence score (0-100)
|
|
494
|
+
* @param options.metadata - Optional additional metadata
|
|
495
|
+
* @param options.iconType - Optional icon type (defaults to "remix")
|
|
496
|
+
* @param options.iconValue - Optional icon value (defaults to "function")
|
|
497
|
+
* @param options.keyWords - Optional additional search keywords
|
|
498
|
+
* @param options.pluginType - Optional plugin type (defaults to "data")
|
|
499
|
+
*
|
|
500
|
+
* @returns A properly configured IDataItem instance
|
|
501
|
+
*
|
|
502
|
+
* @public
|
|
503
|
+
* @since 1.0.0
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```typescript
|
|
507
|
+
* const translationItem = createDataItem({
|
|
508
|
+
* name: "你好世界",
|
|
509
|
+
* desc: "English to Chinese translation",
|
|
510
|
+
* pluginName: "translator",
|
|
511
|
+
* source: "google-translate",
|
|
512
|
+
* dataType: "translation",
|
|
513
|
+
* originalData: "Hello World",
|
|
514
|
+
* processedData: "你好世界",
|
|
515
|
+
* confidence: 95,
|
|
516
|
+
* duration: 120,
|
|
517
|
+
* cached: false
|
|
518
|
+
* });
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```typescript
|
|
523
|
+
* const analysisItem = createDataItem({
|
|
524
|
+
* name: "Text Analysis Complete",
|
|
525
|
+
* desc: "Analyzed 150 words, 3 sentences",
|
|
526
|
+
* pluginName: "text-analyzer",
|
|
527
|
+
* dataType: "analysis",
|
|
528
|
+
* quality: 88,
|
|
529
|
+
* metadata: { wordCount: 150, sentenceCount: 3 }
|
|
530
|
+
* });
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
export function createDataItem(options: {
|
|
534
|
+
/** Display name for the processed result */
|
|
535
|
+
name: string;
|
|
536
|
+
/** Description of the processing or result */
|
|
537
|
+
desc: string;
|
|
538
|
+
/** Name of the plugin that created this item */
|
|
539
|
+
pluginName: string;
|
|
540
|
+
/** Source identifier (e.g., "google-api") */
|
|
541
|
+
source?: string;
|
|
542
|
+
/** Type of processing performed (e.g., "translation") */
|
|
543
|
+
dataType?: string;
|
|
544
|
+
/** Input data before processing */
|
|
545
|
+
originalData?: any;
|
|
546
|
+
/** Output data after processing */
|
|
547
|
+
processedData?: any;
|
|
548
|
+
/** Quality score (0-100) */
|
|
549
|
+
quality?: number;
|
|
550
|
+
/** Whether result is from cache */
|
|
551
|
+
cached?: boolean;
|
|
552
|
+
/** Processing time in milliseconds */
|
|
553
|
+
duration?: number;
|
|
554
|
+
/** Confidence score (0-100) */
|
|
555
|
+
confidence?: number;
|
|
556
|
+
/** Additional metadata */
|
|
557
|
+
metadata?: Record<string, any>;
|
|
558
|
+
/** Icon type (defaults to "remix") */
|
|
559
|
+
iconType?: string;
|
|
560
|
+
/** Icon value (defaults to "function") */
|
|
561
|
+
iconValue?: string;
|
|
562
|
+
/** Additional search keywords */
|
|
563
|
+
keyWords?: string[];
|
|
564
|
+
/** Plugin type (defaults to "data") */
|
|
565
|
+
pluginType?: string;
|
|
566
|
+
}): IDataItem {
|
|
567
|
+
// Extract options with defaults for optional parameters
|
|
568
|
+
const {
|
|
569
|
+
name,
|
|
570
|
+
desc,
|
|
571
|
+
pluginName,
|
|
572
|
+
source,
|
|
573
|
+
dataType,
|
|
574
|
+
originalData,
|
|
575
|
+
processedData,
|
|
576
|
+
quality,
|
|
577
|
+
cached,
|
|
578
|
+
duration,
|
|
579
|
+
confidence,
|
|
580
|
+
metadata,
|
|
581
|
+
iconType = 'remix', // Default to remix icon type
|
|
582
|
+
iconValue = 'function', // Default to function icon
|
|
583
|
+
keyWords = [], // Default to empty keywords array
|
|
584
|
+
pluginType = 'data' // Default to data plugin type
|
|
585
|
+
} = options;
|
|
586
|
+
|
|
587
|
+
// Create and return the data item with all required and optional properties
|
|
588
|
+
return {
|
|
589
|
+
// Core search item properties
|
|
590
|
+
name,
|
|
591
|
+
desc,
|
|
592
|
+
icon: {
|
|
593
|
+
type: iconType,
|
|
594
|
+
value: iconValue,
|
|
595
|
+
init: async () => {} // Required by IPluginIcon interface
|
|
596
|
+
},
|
|
597
|
+
push: false, // Data items don't support push mode
|
|
598
|
+
names: [name], // Include name in searchable names
|
|
599
|
+
keyWords: [name, ...keyWords], // Combine name with additional keywords
|
|
600
|
+
pluginType,
|
|
601
|
+
type: 'plugin', // All plugin-generated items have type 'plugin'
|
|
602
|
+
value: pluginName, // Link to source plugin
|
|
603
|
+
amo: 0, // Initialize usage counter
|
|
604
|
+
|
|
605
|
+
// Data-specific properties
|
|
606
|
+
source,
|
|
607
|
+
dataType,
|
|
608
|
+
originalData,
|
|
609
|
+
processedData,
|
|
610
|
+
quality,
|
|
611
|
+
cached,
|
|
612
|
+
duration,
|
|
613
|
+
confidence,
|
|
614
|
+
metadata
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Creates a basic search result item
|
|
620
|
+
*
|
|
621
|
+
* Factory function for creating standard ISearchItem instances with
|
|
622
|
+
* sensible defaults. This is the most commonly used function for
|
|
623
|
+
* creating search results from plugins and system components.
|
|
624
|
+
*
|
|
625
|
+
* Unlike createDataItem, this function is for general-purpose search
|
|
626
|
+
* items that don't require data processing metadata. It's ideal for
|
|
627
|
+
* applications, features, files, and other standard search results.
|
|
628
|
+
*
|
|
629
|
+
* @param options - Configuration object for the search item
|
|
630
|
+
* @param options.name - Display name of the search result
|
|
631
|
+
* @param options.desc - Description or subtitle text
|
|
632
|
+
* @param options.icon - Icon configuration object
|
|
633
|
+
* @param options.pluginName - Name of the plugin creating this item
|
|
634
|
+
* @param options.pluginType - Optional plugin type (defaults to "feature")
|
|
635
|
+
* @param options.type - Optional general type (defaults to "plugin")
|
|
636
|
+
* @param options.push - Optional push mode support (defaults to false)
|
|
637
|
+
* @param options.commands - Optional list of available commands
|
|
638
|
+
* @param options.keyWords - Optional additional search keywords
|
|
639
|
+
* @param options.[key] - Any additional properties to include
|
|
640
|
+
*
|
|
641
|
+
* @returns A properly configured ISearchItem instance
|
|
642
|
+
*
|
|
643
|
+
* @public
|
|
644
|
+
* @since 1.0.0
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* const appItem = createSearchItem({
|
|
649
|
+
* name: "Calculator",
|
|
650
|
+
* desc: "Built-in calculator application",
|
|
651
|
+
* icon: { type: 'file', value: '/path/to/icon.png', init: async () => {} },
|
|
652
|
+
* pluginName: "system-apps",
|
|
653
|
+
* pluginType: "app",
|
|
654
|
+
* keyWords: ["math", "arithmetic", "calc"]
|
|
655
|
+
* });
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* const featureItem = createSearchItem({
|
|
661
|
+
* name: "Search Files",
|
|
662
|
+
* desc: "Search for files on your system",
|
|
663
|
+
* icon: { type: 'remix', value: 'search', init: async () => {} },
|
|
664
|
+
* pluginName: "file-search",
|
|
665
|
+
* push: true,
|
|
666
|
+
* commands: [
|
|
667
|
+
* { name: "Search in Documents", action: "search:documents" }
|
|
668
|
+
* ]
|
|
669
|
+
* });
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
export function createSearchItem(options: {
|
|
673
|
+
/** Display name of the search result */
|
|
674
|
+
name: string;
|
|
675
|
+
/** Description or subtitle text */
|
|
676
|
+
desc: string;
|
|
677
|
+
/** Icon configuration object */
|
|
678
|
+
icon: IPluginIcon;
|
|
679
|
+
/** Name of the plugin creating this item */
|
|
680
|
+
pluginName: string;
|
|
681
|
+
/** Plugin type (defaults to "feature") */
|
|
682
|
+
pluginType?: string;
|
|
683
|
+
/** General type (defaults to "plugin") */
|
|
684
|
+
type?: string;
|
|
685
|
+
/** Push mode support (defaults to false) */
|
|
686
|
+
push?: boolean;
|
|
687
|
+
/** List of available commands */
|
|
688
|
+
commands?: IFeatureCommand[];
|
|
689
|
+
/** Additional search keywords */
|
|
690
|
+
keyWords?: string[];
|
|
691
|
+
/** Any additional properties to include */
|
|
692
|
+
[key: string]: any;
|
|
693
|
+
}): ISearchItem {
|
|
694
|
+
// Extract options with defaults for optional parameters
|
|
695
|
+
const {
|
|
696
|
+
name,
|
|
697
|
+
desc,
|
|
698
|
+
icon,
|
|
699
|
+
pluginName,
|
|
700
|
+
pluginType = 'feature', // Default to feature type
|
|
701
|
+
type = 'plugin', // Default to plugin type
|
|
702
|
+
push = false, // Default to no push mode
|
|
703
|
+
commands = [], // Default to empty commands array
|
|
704
|
+
keyWords = [], // Default to empty keywords array
|
|
705
|
+
...extra // Capture any additional properties
|
|
706
|
+
} = options;
|
|
707
|
+
|
|
708
|
+
// Create and return the search item with all properties
|
|
709
|
+
return {
|
|
710
|
+
// Core required properties
|
|
711
|
+
name,
|
|
712
|
+
desc,
|
|
713
|
+
icon,
|
|
714
|
+
push,
|
|
715
|
+
commands,
|
|
716
|
+
names: [name], // Include name in searchable names
|
|
717
|
+
keyWords: [name, ...keyWords], // Combine name with additional keywords
|
|
718
|
+
pluginType,
|
|
719
|
+
type,
|
|
720
|
+
value: pluginName, // Link to source plugin
|
|
721
|
+
amo: 0, // Initialize usage counter
|
|
722
|
+
|
|
723
|
+
// Spread any additional properties provided
|
|
724
|
+
...extra
|
|
725
|
+
};
|
|
726
|
+
}
|