@wox-launcher/wox-plugin 0.0.106 → 0.0.109

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/types/index.d.ts CHANGED
@@ -1,120 +1,533 @@
1
1
  import { MetadataCommand, PluginSettingDefinitionItem } from "./setting.js"
2
2
  import { AI } from "./ai.js"
3
3
 
4
+ /**
5
+ * A dictionary type for string key-value pairs.
6
+ *
7
+ * Used throughout the plugin API for passing arbitrary string data,
8
+ * such as context data, settings, and metadata.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const data: MapString = {
13
+ * "userId": "12345",
14
+ * "category": "documents",
15
+ * "tag": "favorite"
16
+ * }
17
+ * ```
18
+ */
4
19
  export type MapString = { [key: string]: string }
5
20
 
21
+ /**
22
+ * Operating system platform identifier.
23
+ *
24
+ * Used for platform-specific functionality and conditional behavior.
25
+ *
26
+ * - `windows`: Windows operating system
27
+ * - `darwin`: macOS operating system
28
+ * - `linux`: Linux operating system
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * if (platform === "darwin") {
33
+ * // macOS-specific code
34
+ * }
35
+ * ```
36
+ */
6
37
  export type Platform = "windows" | "darwin" | "linux"
7
38
 
39
+ /**
40
+ * Main plugin interface that all Wox plugins must implement.
41
+ *
42
+ * A plugin is a class or object that provides search functionality to Wox.
43
+ * It must implement the `init` and `query` methods.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * class MyPlugin implements Plugin {
48
+ * private api: PublicAPI
49
+ *
50
+ * async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
51
+ * this.api = initParams.API
52
+ * await this.api.Log(ctx, "Info", "Plugin initialized")
53
+ * }
54
+ *
55
+ * async query(ctx: Context, query: Query): Promise<Result[]> {
56
+ * return [{
57
+ * Title: "Hello World",
58
+ * SubTitle: "My first result",
59
+ * Icon: { ImageType: "emoji", ImageData: "👋" },
60
+ * Score: 100
61
+ * }]
62
+ * }
63
+ * }
64
+ * ```
65
+ */
8
66
  export interface Plugin {
67
+ /**
68
+ * Initialize the plugin with the provided context and parameters.
69
+ *
70
+ * Called once when the plugin is first loaded. Use this to:
71
+ * - Store the API for later use
72
+ * - Load initial data
73
+ * - Register callbacks
74
+ * - Set up any required resources
75
+ *
76
+ * @param ctx - Request context with trace ID for logging
77
+ * @param initParams - Initialization parameters including API and plugin directory
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
82
+ * this.api = initParams.API
83
+ * this.pluginDir = initParams.PluginDirectory
84
+ *
85
+ * // Load settings
86
+ * const apiKey = await this.api.GetSetting(ctx, "apiKey")
87
+ *
88
+ * // Register callbacks
89
+ * await this.api.OnSettingChanged(ctx, (ctx, key, value) => {
90
+ * console.log(`Setting changed: ${key} = ${value}`)
91
+ * })
92
+ * }
93
+ * ```
94
+ */
9
95
  init: (ctx: Context, initParams: PluginInitParams) => Promise<void>
96
+
97
+ /**
98
+ * Query handler that returns results based on user input.
99
+ *
100
+ * Called whenever the user types a query that triggers this plugin.
101
+ * The plugin should return a list of matching results sorted by relevance.
102
+ *
103
+ * @param ctx - Request context with trace ID for logging
104
+ * @param query - The query object containing search text, type, environment
105
+ * @returns Array of results to display to the user
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * async query(ctx: Context, query: Query): Promise<Result[]> {
110
+ * if (query.Type === "selection") {
111
+ * return this.handleSelection(query.Selection)
112
+ * }
113
+ *
114
+ * const searchTerm = query.Search.toLowerCase()
115
+ * return this.items
116
+ * .filter(item => item.name.toLowerCase().includes(searchTerm))
117
+ * .map(item => ({
118
+ * Title: item.name,
119
+ * SubTitle: item.description,
120
+ * Icon: this.getIcon(item),
121
+ * Score: this.calculateScore(item, searchTerm),
122
+ * Actions: [
123
+ * {
124
+ * Name: "Open",
125
+ * Icon: { ImageType: "emoji", ImageData: "🔗" },
126
+ * Action: async (ctx, actionCtx) => {
127
+ * await this.openItem(item)
128
+ * }
129
+ * }
130
+ * ]
131
+ * }))
132
+ * }
133
+ * ```
134
+ */
10
135
  query: (ctx: Context, query: Query) => Promise<Result[]>
11
136
  }
12
137
 
138
+ /**
139
+ * User-selected or drag-dropped data.
140
+ *
141
+ * When a plugin has the `MetadataFeatureQuerySelection` feature enabled,
142
+ * it can receive selection queries in addition to input queries.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * async query(ctx: Context, query: Query): Promise<Result[]> {
147
+ * if (query.Type === "selection") {
148
+ * const selection = query.Selection
149
+ * if (selection.Type === "text") {
150
+ * console.log("Selected text:", selection.Text)
151
+ * } else if (selection.Type === "file") {
152
+ * console.log("Selected files:", selection.FilePaths)
153
+ * }
154
+ * }
155
+ * return []
156
+ * }
157
+ * ```
158
+ */
13
159
  export interface Selection {
160
+ /**
161
+ * The type of selection data.
162
+ *
163
+ * - `text`: User has selected text content
164
+ * - `file`: User has selected or drag-dropped files
165
+ */
14
166
  Type: "text" | "file"
15
- // Only available when Type is text
167
+ /**
168
+ * The selected text content.
169
+ *
170
+ * Only available when Type is "text".
171
+ */
16
172
  Text: string
17
- // Only available when Type is file
173
+ /**
174
+ * Array of selected file paths.
175
+ *
176
+ * Only available when Type is "file".
177
+ * Contains full paths to all selected/dropped files.
178
+ */
18
179
  FilePaths: string[]
19
180
  }
20
181
 
182
+ /**
183
+ * Environment context for a query.
184
+ *
185
+ * Provides information about the user's current environment when the
186
+ * query was made, such as the active window, browser URL, etc.
187
+ *
188
+ * This allows plugins to provide context-aware results.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Show different results based on active window
193
+ * async query(ctx: Context, query: Query): Promise<Result[]> {
194
+ * if (query.Env.ActiveWindowTitle.includes("Visual Studio")) {
195
+ * return this.getVSCodeActions()
196
+ * }
197
+ * return []
198
+ * }
199
+ * ```
200
+ */
21
201
  export interface QueryEnv {
22
202
  /**
23
- * Active window title when user query
203
+ * Title of the active window when the query was made.
204
+ *
205
+ * Useful for context-aware results based on what application
206
+ * the user is currently using.
24
207
  */
25
208
  ActiveWindowTitle: string
26
209
 
27
210
  /**
28
- * Active window pid when user query, 0 if not available
211
+ * Process ID of the active window.
212
+ *
213
+ * Zero if the information is not available.
29
214
  */
30
215
  ActiveWindowPid: number
31
216
 
32
217
  /**
33
- * Active window icon when user query, may be empty
218
+ * Icon of the active window.
219
+ *
220
+ * May be empty if no icon is available.
34
221
  */
35
222
  ActiveWindowIcon: WoxImage
36
223
 
37
- // active browser url when user query
38
- // Only available when active window is browser and https://github.com/Wox-launcher/Wox.Chrome.Extension is installed
224
+ /**
225
+ * URL of the active browser tab.
226
+ *
227
+ * Only available when:
228
+ * - The active window is a supported browser
229
+ * - The Wox browser extension is installed
230
+ *
231
+ * @see https://github.com/Wox-launcher/Wox.Chrome.Extension
232
+ */
39
233
  ActiveBrowserUrl: string
40
234
  }
41
235
 
236
+ /**
237
+ * Query object containing user input and context.
238
+ *
239
+ * Passed to the plugin's `query()` method, contains all information
240
+ * about the user's search query including the search text, type,
241
+ * trigger keyword, and environment context.
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * async query(ctx: Context, query: Query): Promise<Result[]> {
246
+ * // Handle input query
247
+ * if (query.Type === "input") {
248
+ * console.log("Search:", query.Search)
249
+ * console.log("Trigger:", query.TriggerKeyword)
250
+ * }
251
+ *
252
+ * // Handle selection query
253
+ * if (query.Type === "selection") {
254
+ * console.log("Selection:", query.Selection)
255
+ * }
256
+ *
257
+ * // Check environment
258
+ * if (query.Env.ActiveBrowserUrl) {
259
+ * console.log("Browser:", query.Env.ActiveBrowserUrl)
260
+ * }
261
+ * }
262
+ * ```
263
+ */
42
264
  export interface Query {
43
265
  /**
44
- * Query id passed from UI to correlate async updates.
266
+ * Unique query identifier.
267
+ *
268
+ * Used to correlate async updates with the original query.
269
+ * Pass this ID when calling UpdateResult or PushResults.
45
270
  */
46
271
  Id: string
272
+
47
273
  /**
48
- * By default, Wox will only pass input query to plugin.
49
- * plugin author need to enable MetadataFeatureQuerySelection feature to handle selection query
274
+ * Query type.
275
+ *
276
+ * - `input`: User typed a query
277
+ * - `selection`: User selected text or drag-dropped files
278
+ *
279
+ * Note: Selection queries require the `MetadataFeatureQuerySelection` feature.
50
280
  */
51
281
  Type: "input" | "selection"
282
+
52
283
  /**
53
- * Raw query, this includes trigger keyword if it has
54
- * We didn't recommend use this property directly. You should always use Search property.
284
+ * Raw query string including trigger keyword.
55
285
  *
56
- * NOTE: Only available when query type is input
286
+ * Not recommended for direct use. Use `Search` instead for the
287
+ * actual search term without the trigger keyword.
288
+ *
289
+ * Only available when Type is "input".
57
290
  */
58
291
  RawQuery: string
292
+
59
293
  /**
60
- * Trigger keyword of a query. It can be empty if user is using global trigger keyword.
294
+ * Trigger keyword that activated this plugin.
295
+ *
296
+ * Empty if using global trigger keyword.
61
297
  *
62
- * NOTE: Only available when query type is input
298
+ * Only available when Type is "input".
299
+ *
300
+ * @example
301
+ * If user types "git status", TriggerKeyword is "git" and Search is "status"
63
302
  */
64
303
  TriggerKeyword?: string
304
+
65
305
  /**
66
- * Command part of a query.
306
+ * Command part of the query (between trigger and search).
307
+ *
308
+ * Only available when Type is "input".
67
309
  *
68
- * NOTE: Only available when query type is input
310
+ * @example
311
+ * If user types "myplugin cmd search", Command is "cmd" and Search is "search"
69
312
  */
70
313
  Command?: string
314
+
71
315
  /**
72
- * Search part of a query.
316
+ * The actual search term.
317
+ *
318
+ * This is the text the user wants to search for, without
319
+ * trigger keyword or command. Use this for your search logic.
73
320
  *
74
- * NOTE: Only available when query type is input
321
+ * Only available when Type is "input".
75
322
  */
76
323
  Search: string
77
324
 
78
325
  /**
79
- * User selected or drag-drop data, can be text or file or image etc
326
+ * User selected or drag-dropped data.
80
327
  *
81
- * NOTE: Only available when query type is selection
328
+ * Only available when Type is "selection".
82
329
  */
83
330
  Selection: Selection
84
331
 
85
332
  /**
86
- * Additional query environment data
87
- * expose more context env data to plugin, E.g. plugin A only show result when active window title is "Chrome"
333
+ * Environment context when the query was made.
334
+ *
335
+ * Includes information about the active window, browser URL, etc.
336
+ * Use this to provide context-aware results.
88
337
  */
89
338
  Env: QueryEnv
90
339
 
91
340
  /**
92
- * Whether current query is global query
341
+ * Check if this is a global query (no trigger keyword).
342
+ *
343
+ * @returns true if triggered globally, false if triggered by keyword
93
344
  */
94
345
  IsGlobalQuery(): boolean
95
346
  }
96
347
 
348
+ /**
349
+ * A search result displayed to the user.
350
+ *
351
+ * Results are displayed in the Wox UI and can include icons, previews,
352
+ * actions, and tail elements for additional information.
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const result: Result = {
357
+ * Id: "result-1",
358
+ * Title: "Open Calculator",
359
+ * SubTitle: "Launch the system calculator app",
360
+ * Icon: { ImageType: "emoji", ImageData: "🔢" },
361
+ * Score: 100,
362
+ * Preview: {
363
+ * PreviewType: "markdown",
364
+ * PreviewData: "# Calculator\n\nA simple calculator app",
365
+ * PreviewProperties: {}
366
+ * },
367
+ * Tails: [
368
+ * { Type: "text", Text: "⌘⏎ Quick Action" }
369
+ * ],
370
+ * Actions: [
371
+ * {
372
+ * Name: "Open",
373
+ * Icon: { ImageType: "emoji", ImageData: "🚀" },
374
+ * Action: async (ctx, actionCtx) => {
375
+ * // Open calculator
376
+ * }
377
+ * }
378
+ * ]
379
+ * }
380
+ * ```
381
+ */
97
382
  export interface Result {
383
+ /**
384
+ * Unique identifier for this result.
385
+ *
386
+ * Optional. If not provided, Wox will generate a random ID.
387
+ * Use this ID with UpdateResult to update the result later.
388
+ */
98
389
  Id?: string
390
+
391
+ /**
392
+ * Main title displayed to the user.
393
+ *
394
+ * This is the primary text shown in the result list.
395
+ * Should be concise but descriptive.
396
+ */
99
397
  Title: string
398
+
399
+ /**
400
+ * Secondary text shown below the title.
401
+ *
402
+ * Use for additional context like description, path, or metadata.
403
+ */
100
404
  SubTitle?: string
405
+
406
+ /**
407
+ * Icon displayed next to the result.
408
+ *
409
+ * Can be emoji, image path, base64, etc.
410
+ */
101
411
  Icon: WoxImage
412
+
413
+ /**
414
+ * Preview panel content.
415
+ *
416
+ * When selected, this content is shown in the preview panel.
417
+ * Supports markdown, text, images, URLs, and files.
418
+ */
102
419
  Preview?: WoxPreview
420
+
421
+ /**
422
+ * Relevance score for sorting.
423
+ *
424
+ * Higher values appear first in the result list.
425
+ * Default is 0.
426
+ */
103
427
  Score?: number
428
+
429
+ /**
430
+ * Group name for organizing results.
431
+ *
432
+ * Results with the same group name are displayed together
433
+ * with a group header.
434
+ */
104
435
  Group?: string
436
+
437
+ /**
438
+ * Score for group sorting.
439
+ *
440
+ * Determines the order of groups in the result list.
441
+ */
105
442
  GroupScore?: number
443
+
444
+ /**
445
+ * Additional visual elements displayed after the result.
446
+ *
447
+ * Tails are small UI elements like text labels or icons
448
+ * shown to the right of the result.
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * Tails: [
453
+ * { Type: "text", Text: "⭐ Favorite" },
454
+ * { Type: "image", Image: { ImageType: "emoji", ImageData: "🔥" } }
455
+ * ]
456
+ * ```
457
+ */
106
458
  Tails?: ResultTail[]
459
+
460
+ /**
461
+ * User actions available for this result.
462
+ *
463
+ * Actions are shown when the result is selected and can be
464
+ * triggered via keyboard shortcuts or clicking.
465
+ */
107
466
  Actions?: ResultAction[]
108
467
  }
109
468
 
469
+ /**
470
+ * A visual element displayed after a result.
471
+ *
472
+ * Tails are small UI elements that provide additional information
473
+ * or quick actions. They appear to the right of the result in
474
+ * the list view.
475
+ *
476
+ * @example
477
+ * ```typescript
478
+ * // Text tail for status
479
+ * { Type: "text", Text: "✓ Verified", Id: "status-tail" }
480
+ *
481
+ * // Image tail for icon
482
+ * { Type: "image", Image: { ImageType: "emoji", ImageData: "🔥" } }
483
+ * ```
484
+ */
110
485
  export interface ResultTail {
486
+ /**
487
+ * The type of tail content.
488
+ *
489
+ * - `text`: Display text content
490
+ * - `image`: Display an icon or image
491
+ */
111
492
  Type: "text" | "image"
493
+
494
+ /**
495
+ * Text content for text tails.
496
+ *
497
+ * Only used when Type is "text".
498
+ */
112
499
  Text?: string
500
+
501
+ /**
502
+ * Image content for image tails.
503
+ *
504
+ * Only used when Type is "image".
505
+ */
113
506
  Image?: WoxImage
114
- /** Tail id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you */
507
+
508
+ /**
509
+ * Unique identifier for this tail.
510
+ *
511
+ * Optional. If not provided, Wox generates a random ID.
512
+ * Use this to identify specific tails for updates.
513
+ */
115
514
  Id?: string
116
- /** Additional data associate with this tail, can be retrieved later */
117
- ContextData?: string
515
+
516
+ /**
517
+ * Additional data associated with this tail.
518
+ *
519
+ * Store arbitrary key-value pairs for identification and metadata.
520
+ *
521
+ * Note: This data is NOT passed to action callbacks.
522
+ * Use ResultAction.ContextData for data that needs to be available
523
+ * in action handlers.
524
+ *
525
+ * Tail context data is primarily used for:
526
+ * - Identifying specific tails (e.g., custom IDs, tags)
527
+ * - Storing tail metadata for UI updates
528
+ * - System-level tail identification (e.g., "system:favorite")
529
+ */
530
+ ContextData?: MapString
118
531
  }
119
532
 
120
533
  /**
@@ -153,112 +566,424 @@ export interface UpdatableResult {
153
566
  Actions?: ResultAction[]
154
567
  }
155
568
 
569
+ /**
570
+ * Type of result action.
571
+ *
572
+ * - `execute`: Immediately execute the action's callback function
573
+ * - `form`: Display a form to the user before executing
574
+ */
156
575
  export type ResultActionType = "execute" | "form"
157
576
 
577
+ /**
578
+ * A user action that can be performed on a result.
579
+ *
580
+ * Actions are displayed when a result is selected and can be triggered
581
+ * via keyboard shortcuts or by clicking. There are two types:
582
+ * execute actions (run immediately) and form actions (show form first).
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * const action: ExecuteResultAction = {
587
+ * Name: "Copy to Clipboard",
588
+ * Icon: { ImageType: "emoji", ImageData: "📋" },
589
+ * IsDefault: true,
590
+ * Hotkey: "Ctrl+C",
591
+ * Action: async (ctx, actionCtx) => {
592
+ * await api.Copy(ctx, { type: "text", text: "Hello" })
593
+ * }
594
+ * }
595
+ * ```
596
+ */
158
597
  export type ResultAction = ExecuteResultAction | FormResultAction
159
598
 
599
+ /**
600
+ * An action that executes immediately when triggered.
601
+ *
602
+ * Execute actions run their callback function as soon as the user
603
+ * activates them (via keyboard shortcut or click).
604
+ *
605
+ * @example
606
+ * ```typescript
607
+ * const action: ExecuteResultAction = {
608
+ * Id: "action-copy",
609
+ * Name: "Copy",
610
+ * Icon: { ImageType: "emoji", ImageData: "📋" },
611
+ * IsDefault: true,
612
+ * PreventHideAfterAction: false,
613
+ * Hotkey: "Ctrl+C",
614
+ * ContextData: { "copyType": "text" },
615
+ * Action: async (ctx, actionCtx) => {
616
+ * console.log("ResultId:", actionCtx.ResultId)
617
+ * await this.copyItem(ctx, actionCtx)
618
+ * }
619
+ * }
620
+ * ```
621
+ */
160
622
  export interface ExecuteResultAction {
161
623
  /**
162
- * Result id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you
624
+ * Unique identifier for this action.
625
+ *
626
+ * Optional. If not provided, Wox generates a random ID.
627
+ * Use this to identify the action for updates or logging.
163
628
  */
164
629
  Id?: string
630
+
631
+ /**
632
+ * Action type discriminator.
633
+ *
634
+ * Set to "execute" for immediate execution actions.
635
+ */
165
636
  Type?: "execute"
637
+
638
+ /**
639
+ * Display name for the action.
640
+ *
641
+ * This is shown to the user in the UI.
642
+ */
166
643
  Name: string
644
+
645
+ /**
646
+ * Icon displayed next to the action name.
647
+ */
167
648
  Icon?: WoxImage
649
+
168
650
  /**
169
- * If true, Wox will use this action as default action. There can be only one default action in results
170
- * This can be omitted, if you don't set it, Wox will use the first action as default action
651
+ * Whether this is the default action.
652
+ *
653
+ * If true, this action is triggered when the user presses Enter.
654
+ * Only one action per result can be the default.
655
+ * If not set, the first action becomes the default.
171
656
  */
172
657
  IsDefault?: boolean
658
+
173
659
  /**
174
- * If true, Wox will not hide after user select this result
660
+ * Whether to keep Wox visible after executing this action.
661
+ *
662
+ * If true, Wox remains open after the action completes.
663
+ * Useful for actions that update the result rather than navigate away.
175
664
  */
176
665
  PreventHideAfterAction?: boolean
666
+
667
+ /**
668
+ * The callback function to execute when the action is triggered.
669
+ *
670
+ * @param ctx - Request context
671
+ * @param actionContext - Action context with result ID and context data
672
+ */
177
673
  Action: (ctx: Context, actionContext: ActionContext) => Promise<void>
674
+
178
675
  /**
179
- * Hotkey to trigger this action. E.g. "ctrl+Shift+Space", "Ctrl+1", "Command+K"
180
- * Case insensitive, space insensitive
676
+ * Keyboard shortcut to trigger this action.
677
+ *
678
+ * Examples: "Ctrl+Shift+Space", "Ctrl+1", "Command+K"
679
+ * Case and space insensitive.
181
680
  *
182
- * If IsDefault is true, Hotkey will be set to enter key by default
681
+ * If IsDefault is true, the hotkey defaults to Enter.
183
682
  */
184
683
  Hotkey?: string
684
+
185
685
  /**
186
- * Additional data associate with this action, can be retrieved later
686
+ * Additional data associated with this action.
687
+ *
688
+ * This data is passed to ActionContext.ContextData when
689
+ * the action is executed. Use it to identify which action
690
+ * was triggered or pass custom parameters.
187
691
  */
188
- ContextData?: string
692
+ ContextData?: MapString
189
693
  }
190
694
 
695
+ /**
696
+ * An action that shows a form before executing.
697
+ *
698
+ * Form actions display a form to the user, collect input,
699
+ * and then execute the OnSubmit callback with the form values.
700
+ *
701
+ * @example
702
+ * ```typescript
703
+ * const action: FormResultAction = {
704
+ * Name: "Create New Item",
705
+ * Icon: { ImageType: "emoji", ImageData: "➕" },
706
+ * Form: [
707
+ * createTextboxSetting({
708
+ * key: "name",
709
+ * label: "Name",
710
+ * defaultValue: ""
711
+ * }),
712
+ * createCheckboxSetting({
713
+ * key: "enabled",
714
+ * label: "Enable",
715
+ * defaultValue: "true"
716
+ * })
717
+ * ],
718
+ * OnSubmit: async (ctx, formCtx) => {
719
+ * console.log("Name:", formCtx.Values["name"])
720
+ * console.log("Enabled:", formCtx.Values["enabled"])
721
+ * await this.createItem(ctx, formCtx.Values)
722
+ * }
723
+ * }
724
+ * ```
725
+ */
191
726
  export interface FormResultAction {
192
727
  /**
193
- * Result id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you
728
+ * Unique identifier for this action.
729
+ *
730
+ * Optional. If not provided, Wox generates a random ID.
194
731
  */
195
732
  Id?: string
733
+
734
+ /**
735
+ * Action type discriminator.
736
+ *
737
+ * Must be "form" for form-based actions.
738
+ */
196
739
  Type: "form"
740
+
741
+ /**
742
+ * Display name for the action.
743
+ */
197
744
  Name: string
745
+
746
+ /**
747
+ * Icon displayed next to the action name.
748
+ */
198
749
  Icon?: WoxImage
750
+
199
751
  /**
200
- * If true, Wox will use this action as default action. There can be only one default action in results
201
- * This can be omitted, if you don't set it, Wox will use the first action as default action
752
+ * Whether this is the default action.
753
+ *
754
+ * If true, this action is triggered when the user presses Enter.
755
+ * Only one action per result can be the default.
202
756
  */
203
757
  IsDefault?: boolean
758
+
204
759
  /**
205
- * If true, Wox will not hide after user select this result
760
+ * Whether to keep Wox visible after executing this action.
206
761
  */
207
762
  PreventHideAfterAction?: boolean
763
+
764
+ /**
765
+ * Form definition to display.
766
+ *
767
+ * Array of setting items that define the form fields.
768
+ */
208
769
  Form: PluginSettingDefinitionItem[]
770
+
771
+ /**
772
+ * Callback executed when the form is submitted.
773
+ *
774
+ * @param ctx - Request context
775
+ * @param actionContext - Form action context with submitted values
776
+ */
209
777
  OnSubmit: (ctx: Context, actionContext: FormActionContext) => Promise<void>
778
+
210
779
  /**
211
- * Hotkey to trigger this action. E.g. "ctrl+Shift+Space", "Ctrl+1", "Command+K"
212
- * Case insensitive, space insensitive
780
+ * Keyboard shortcut to trigger this action.
213
781
  *
214
- * If IsDefault is true, Hotkey will be set to enter key by default
782
+ * Examples: "Ctrl+Shift+Space", "Ctrl+1", "Command+K"
215
783
  */
216
784
  Hotkey?: string
785
+
217
786
  /**
218
- * Additional data associate with this action, can be retrieved later
787
+ * Additional data associated with this action.
219
788
  */
220
- ContextData?: string
789
+ ContextData?: MapString
221
790
  }
222
791
 
792
+ /**
793
+ * Context passed to action callback functions.
794
+ *
795
+ * When a user triggers an action, Wox creates an ActionContext
796
+ * containing information about which result and action were triggered,
797
+ * along with any custom context data.
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * Action: async (ctx: Context, actionContext: ActionContext) => {
802
+ * console.log("Result ID:", actionContext.ResultId)
803
+ * console.log("Action ID:", actionContext.ResultActionId)
804
+ * console.log("Custom data:", actionContext.ContextData)
805
+ *
806
+ * // Update the result
807
+ * await api.UpdateResult(ctx, {
808
+ * Id: actionContext.ResultId,
809
+ * Title: "Updated!"
810
+ * })
811
+ * }
812
+ * ```
813
+ */
223
814
  export interface ActionContext {
224
815
  /**
225
- * The ID of the result that triggered this action
226
- * This is automatically set by Wox when the action is invoked
227
- * Useful for calling UpdateResult API to update the result's UI
816
+ * The ID of the result that triggered this action.
817
+ *
818
+ * Automatically set by Wox when the action is invoked.
819
+ * Use this with UpdateResult to modify the result's UI.
228
820
  */
229
821
  ResultId: string
230
822
  /**
231
- * The ID of the action that was triggered
232
- * This is automatically set by Wox when the action is invoked
233
- * Useful for calling UpdateResult API to update this action's UI
823
+ * The ID of the action that was triggered.
824
+ *
825
+ * Automatically set by Wox when the action is invoked.
826
+ * Useful for identifying which action was executed.
234
827
  */
235
828
  ResultActionId: string
236
829
  /**
237
- * Additional data associated with this action
830
+ * Additional data associated with this action.
831
+ *
832
+ * Contains the ContextData from the ResultAction that was triggered.
833
+ * Use this to pass custom parameters to your action handler.
238
834
  */
239
- ContextData: string
835
+ ContextData: MapString
240
836
  }
241
837
 
838
+ /**
839
+ * Extended action context for form submissions.
840
+ *
841
+ * In addition to the standard ActionContext fields, this includes
842
+ * the form values submitted by the user.
843
+ *
844
+ * @example
845
+ * ```typescript
846
+ * OnSubmit: async (ctx: Context, formContext: FormActionContext) => {
847
+ * const name = formContext.Values["name"]
848
+ * const email = formContext.Values["email"]
849
+ * console.log("User submitted:", name, email)
850
+ * }
851
+ * ```
852
+ */
242
853
  export interface FormActionContext extends ActionContext {
854
+ /**
855
+ * Form field values submitted by the user.
856
+ *
857
+ * Keys are the setting keys, values are the user-submitted strings.
858
+ */
243
859
  Values: Record<string, string>
244
860
  }
245
861
 
862
+ /**
863
+ * Most Recently Used (MRU) item data.
864
+ *
865
+ * Wox keeps track of recently selected items and can restore them
866
+ * via the OnMRURestore callback.
867
+ *
868
+ * @example
869
+ * ```typescript
870
+ * await api.OnMRURestore(ctx, async (ctx, mruData) => {
871
+ * // Find the item in our data
872
+ * const item = this.findById(mruData.ContextData["id"])
873
+ * if (!item) {
874
+ * return null // Item no longer exists
875
+ * }
876
+ *
877
+ * // Return a result for the MRU item
878
+ * return {
879
+ * Title: item.name,
880
+ * SubTitle: item.description,
881
+ * Icon: mruData.Icon
882
+ * }
883
+ * })
884
+ * ```
885
+ */
246
886
  export interface MRUData {
887
+ /**
888
+ * Plugin ID that owns this MRU item.
889
+ */
247
890
  PluginID: string
891
+ /**
892
+ * Title of the MRU item.
893
+ */
248
894
  Title: string
895
+ /**
896
+ * Subtitle of the MRU item.
897
+ */
249
898
  SubTitle: string
899
+ /**
900
+ * Icon of the MRU item.
901
+ */
250
902
  Icon: WoxImage
251
- ContextData: string
903
+ /**
904
+ * Custom data associated with this MRU item.
905
+ *
906
+ * Use this to store identifiers or metadata needed to
907
+ * reconstruct the item when restoring from MRU.
908
+ */
909
+ ContextData: MapString
252
910
  }
253
911
 
912
+ /**
913
+ * Parameters passed to the plugin's init method.
914
+ *
915
+ * Contains the API instance and plugin directory path.
916
+ *
917
+ * @example
918
+ * ```typescript
919
+ * async init(ctx: Context, initParams: PluginInitParams): Promise<void> {
920
+ * this.api = initParams.API
921
+ * this.pluginDir = initParams.PluginDirectory
922
+ *
923
+ * // Load data from plugin directory
924
+ * const dataPath = `${this.pluginDir}/data.json`
925
+ * this.data = JSON.parse(await fs.readFile(dataPath, 'utf-8'))
926
+ * }
927
+ * ```
928
+ */
254
929
  export interface PluginInitParams {
930
+ /**
931
+ * The public API for interacting with Wox.
932
+ *
933
+ * Store this for later use in your plugin methods.
934
+ */
255
935
  API: PublicAPI
936
+ /**
937
+ * Absolute path to the plugin directory.
938
+ *
939
+ * Use this to load plugin-specific data files, configs, etc.
940
+ */
256
941
  PluginDirectory: string
257
942
  }
258
943
 
944
+ /**
945
+ * Parameters for changing the current Wox query.
946
+ *
947
+ * Used with the ChangeQuery API to programmatically change
948
+ * what the user is searching for.
949
+ *
950
+ * @example
951
+ * ```typescript
952
+ * // Change to input query
953
+ * await api.ChangeQuery(ctx, {
954
+ * QueryType: "input",
955
+ * QueryText: "github wox"
956
+ * })
957
+ *
958
+ * // Change to selection query
959
+ * await api.ChangeQuery(ctx, {
960
+ * QueryType: "selection",
961
+ * QuerySelection: {
962
+ * Type: "text",
963
+ * Text: "selected text"
964
+ * }
965
+ * })
966
+ * ```
967
+ */
259
968
  export interface ChangeQueryParam {
969
+ /**
970
+ * The type of query to change to.
971
+ *
972
+ * - `input`: Change to a text input query
973
+ * - `selection`: Change to a selection-based query
974
+ */
260
975
  QueryType: "input" | "selection"
976
+ /**
977
+ * New query text (for input queries).
978
+ *
979
+ * Only used when QueryType is "input".
980
+ */
261
981
  QueryText?: string
982
+ /**
983
+ * New selection data (for selection queries).
984
+ *
985
+ * Only used when QueryType is "selection".
986
+ */
262
987
  QuerySelection?: Selection
263
988
  }
264
989
 
@@ -271,11 +996,51 @@ export interface RefreshQueryParam {
271
996
  PreserveSelectedIndex: boolean
272
997
  }
273
998
 
999
+ /**
1000
+ * Type of data to copy to clipboard.
1001
+ *
1002
+ * - `text`: Copy plain text
1003
+ * - `image`: Copy image data
1004
+ */
274
1005
  export type CopyType = "text" | "image"
275
1006
 
1007
+ /**
1008
+ * Parameters for copying data to clipboard.
1009
+ *
1010
+ * Used with the Copy API to copy text or images.
1011
+ *
1012
+ * @example
1013
+ * ```typescript
1014
+ * // Copy text
1015
+ * await api.Copy(ctx, {
1016
+ * type: "text",
1017
+ * text: "Hello, World!"
1018
+ * })
1019
+ *
1020
+ * // Copy image
1021
+ * await api.Copy(ctx, {
1022
+ * type: "image",
1023
+ * text: "",
1024
+ * woxImage: { ImageType: "base64", ImageData: "data:image/png;base64,..." }
1025
+ * })
1026
+ * ```
1027
+ */
276
1028
  export interface CopyParams {
1029
+ /**
1030
+ * Type of content to copy.
1031
+ */
277
1032
  type: CopyType
1033
+ /**
1034
+ * Text content to copy.
1035
+ *
1036
+ * Used when type is "text".
1037
+ */
278
1038
  text: string
1039
+ /**
1040
+ * Image data to copy.
1041
+ *
1042
+ * Used when type is "image".
1043
+ */
279
1044
  woxImage?: WoxImage
280
1045
  }
281
1046
 
@@ -485,30 +1250,251 @@ export interface PublicAPI {
485
1250
  Copy: (ctx: Context, params: CopyParams) => Promise<void>
486
1251
  }
487
1252
 
1253
+ /**
1254
+ * Type of image data.
1255
+ *
1256
+ * - `absolute`: Absolute file path to an image
1257
+ * - `relative`: Path relative to the plugin directory
1258
+ * - `base64`: Base64 encoded image with data URI prefix (e.g., "data:image/png;base64,...")
1259
+ * - `svg`: SVG string content
1260
+ * - `url`: HTTP/HTTPS URL to an image
1261
+ * - `emoji`: Emoji character
1262
+ * - `lottie`: Lottie animation JSON URL or data
1263
+ *
1264
+ * @example
1265
+ * ```typescript
1266
+ * // Absolute path
1267
+ * { ImageType: "absolute", ImageData: "/usr/share/icons/app.png" }
1268
+ *
1269
+ * // Relative path (from plugin directory)
1270
+ * { ImageType: "relative", ImageData: "./icons/icon.png" }
1271
+ *
1272
+ * // Base64 with data URI prefix
1273
+ * { ImageType: "base64", ImageData: "data:image/png;base64,iVBORw0KGgo..." }
1274
+ *
1275
+ * // Emoji
1276
+ * { ImageType: "emoji", ImageData: "🔍" }
1277
+ *
1278
+ * // URL
1279
+ * { ImageType: "url", ImageData: "https://example.com/icon.png" }
1280
+ * ```
1281
+ */
488
1282
  export type WoxImageType = "absolute" | "relative" | "base64" | "svg" | "url" | "emoji" | "lottie"
489
1283
 
1284
+ /**
1285
+ * Image representation in Wox.
1286
+ *
1287
+ * Used throughout the plugin API for icons, previews, and UI elements.
1288
+ * The ImageData format depends on the ImageType.
1289
+ *
1290
+ * @example
1291
+ * ```typescript
1292
+ * const emojiIcon: WoxImage = {
1293
+ * ImageType: "emoji",
1294
+ * ImageData: "🔍"
1295
+ * }
1296
+ *
1297
+ * const base64Icon: WoxImage = {
1298
+ * ImageType: "base64",
1299
+ * ImageData: "data:image/png;base64,iVBORw0KGgoAAAA..."
1300
+ * }
1301
+ *
1302
+ * const relativeIcon: WoxImage = {
1303
+ * ImageType: "relative",
1304
+ * ImageData: "./icons/my-icon.png"
1305
+ * }
1306
+ * ```
1307
+ */
490
1308
  export interface WoxImage {
1309
+ /**
1310
+ * The type of image data.
1311
+ *
1312
+ * Determines how ImageData should be interpreted.
1313
+ */
491
1314
  ImageType: WoxImageType
1315
+ /**
1316
+ * The image data.
1317
+ *
1318
+ * Format depends on ImageType:
1319
+ * - `absolute`: Absolute file path
1320
+ * - `relative`: Path relative to plugin directory
1321
+ * - `base64`: Data URI with base64 content (e.g., "data:image/png;base64,...")
1322
+ * - `svg`: SVG string content
1323
+ * - `url`: HTTP/HTTPS URL
1324
+ * - `emoji`: Single emoji character
1325
+ * - `lottie`: Lottie JSON URL or data
1326
+ */
492
1327
  ImageData: string
493
1328
  }
494
1329
 
1330
+ /**
1331
+ * Type of preview content.
1332
+ *
1333
+ * - `markdown`: Rendered markdown content
1334
+ * - `text`: Plain text content
1335
+ * - `image`: Image preview
1336
+ * - `url`: Website URL preview
1337
+ * - `file`: File preview
1338
+ */
495
1339
  export type WoxPreviewType = "markdown" | "text" | "image" | "url" | "file"
496
1340
 
1341
+ /**
1342
+ * Preview panel content for a result.
1343
+ *
1344
+ * When a result is selected, the preview panel displays additional
1345
+ * information using the specified preview type.
1346
+ *
1347
+ * @example
1348
+ * ```typescript
1349
+ * // Markdown preview
1350
+ * {
1351
+ * PreviewType: "markdown",
1352
+ * PreviewData: "# Title\n\nDescription with **formatting**",
1353
+ * PreviewProperties: {}
1354
+ * }
1355
+ *
1356
+ * // Image preview
1357
+ * {
1358
+ * PreviewType: "image",
1359
+ * PreviewData: "https://example.com/image.png",
1360
+ * PreviewProperties: { "height": "300" }
1361
+ * }
1362
+ *
1363
+ * // URL preview
1364
+ * {
1365
+ * PreviewType: "url",
1366
+ * PreviewData: "https://github.com/Wox-launcher/Wox",
1367
+ * PreviewProperties: {}
1368
+ * }
1369
+ * ```
1370
+ */
497
1371
  export interface WoxPreview {
1372
+ /**
1373
+ * The type of preview content.
1374
+ *
1375
+ * Determines how PreviewData is rendered.
1376
+ */
498
1377
  PreviewType: WoxPreviewType
1378
+ /**
1379
+ * The preview content data.
1380
+ *
1381
+ * Format depends on PreviewType:
1382
+ * - `markdown`: Markdown string to render
1383
+ * - `text`: Plain text string
1384
+ * - `image`: Image URL, path, or base64 data
1385
+ * - `url`: Website URL to preview
1386
+ * - `file`: File path to preview
1387
+ */
499
1388
  PreviewData: string
1389
+ /**
1390
+ * Additional properties for the preview.
1391
+ *
1392
+ * Type-specific options like height, width, scroll position, etc.
1393
+ *
1394
+ * @example
1395
+ * ```typescript
1396
+ * { "height": "400", "width": "600" }
1397
+ * { "scrollPosition": "top" }
1398
+ * ```
1399
+ */
500
1400
  PreviewProperties: Record<string, string>
501
1401
  }
502
1402
 
1403
+ /**
1404
+ * Request context for tracking and passing data.
1405
+ *
1406
+ * Context is passed to all plugin API calls and contains a trace ID
1407
+ * for logging and debugging. Plugins can also store custom values
1408
+ * in the context for passing between function calls.
1409
+ *
1410
+ * @example
1411
+ * ```typescript
1412
+ * // Create a new context
1413
+ * const ctx = NewContext()
1414
+ * const traceId = ctx.Get("traceId") // Auto-generated UUID
1415
+ *
1416
+ * // Store custom data
1417
+ * ctx.Set("userId", "12345")
1418
+ * ctx.Set("requestId", "req-abc")
1419
+ *
1420
+ * // Check if key exists
1421
+ * if (ctx.Exists("userId")) {
1422
+ * console.log("User ID:", ctx.Get("userId"))
1423
+ * }
1424
+ *
1425
+ * // Create with initial value
1426
+ * const ctxWithValue = NewContextWithValue("userId", "12345")
1427
+ * ```
1428
+ */
503
1429
  export declare interface Context {
1430
+ /**
1431
+ * Key-value storage for context data.
1432
+ *
1433
+ * Contains auto-generated trace ID and any custom values.
1434
+ */
504
1435
  Values: { [key: string]: string }
1436
+ /**
1437
+ * Get a value from the context.
1438
+ *
1439
+ * @param key - The key to retrieve
1440
+ * @returns The value, or undefined if not found
1441
+ */
505
1442
  Get: (key: string) => string | undefined
1443
+ /**
1444
+ * Set a value in the context.
1445
+ *
1446
+ * @param key - The key to set
1447
+ * @param value - The value to store
1448
+ */
506
1449
  Set: (key: string, value: string) => void
1450
+ /**
1451
+ * Check if a key exists in the context.
1452
+ *
1453
+ * @param key - The key to check
1454
+ * @returns true if the key exists, false otherwise
1455
+ */
507
1456
  Exists: (key: string) => boolean
508
1457
  }
509
1458
 
1459
+ /**
1460
+ * Create a new context with auto-generated trace ID.
1461
+ *
1462
+ * @returns A new Context instance with a UUID in the "traceId" key
1463
+ *
1464
+ * @example
1465
+ * ```typescript
1466
+ * const ctx = NewContext()
1467
+ * console.log(ctx.Get("traceId")) // e.g., "550e8400-e29b-41d4-a716-446655440000"
1468
+ * ```
1469
+ */
510
1470
  export function NewContext(): Context
511
1471
 
1472
+ /**
1473
+ * Create a new context with an initial key-value pair.
1474
+ *
1475
+ * @param key - The key to set
1476
+ * @param value - The value to store
1477
+ * @returns A new Context instance with the trace ID and custom value
1478
+ *
1479
+ * @example
1480
+ * ```typescript
1481
+ * const ctx = NewContextWithValue("userId", "12345")
1482
+ * console.log(ctx.Get("userId")) // "12345"
1483
+ * console.log(ctx.Get("traceId")) // auto-generated UUID
1484
+ * ```
1485
+ */
512
1486
  export function NewContextWithValue(key: string, value: string): Context
513
1487
 
1488
+ /**
1489
+ * Create a base64 WoxImage from image data.
1490
+ *
1491
+ * @param imageData - Base64 image data with data URI prefix (e.g., "data:image/png;base64,...")
1492
+ * @returns A WoxImage with type "base64"
1493
+ *
1494
+ * @example
1495
+ * ```typescript
1496
+ * const pngData = "data:image/png;base64,iVBORw0KGgoAAAA..."
1497
+ * const icon = NewBase64WoxImage(pngData)
1498
+ * ```
1499
+ */
514
1500
  export function NewBase64WoxImage(imageData: string): WoxImage