@wox-launcher/wox-plugin 0.0.93 → 0.0.96

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,527 +1,568 @@
1
- import { MetadataCommand, PluginSettingDefinitionItem } from "./setting.js"
2
- import { AI } from "./ai.js"
3
-
4
- export type MapString = { [key: string]: string }
5
-
6
- export type Platform = "windows" | "darwin" | "linux"
7
-
8
- export interface Plugin {
9
- init: (ctx: Context, initParams: PluginInitParams) => Promise<void>
10
- query: (ctx: Context, query: Query) => Promise<Result[]>
11
- }
12
-
13
- export interface Selection {
14
- Type: "text" | "file"
15
- // Only available when Type is text
16
- Text: string
17
- // Only available when Type is file
18
- FilePaths: string[]
19
- }
20
-
21
- export interface QueryEnv {
22
- /**
23
- * Active window title when user query
24
- */
25
- ActiveWindowTitle: string
26
-
27
- /**
28
- * Active window pid when user query, 0 if not available
29
- */
30
- ActiveWindowPid: number
31
-
32
- /**
33
- * Active window icon when user query, may be empty
34
- */
35
- ActiveWindowIcon: WoxImage
36
-
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
39
- ActiveBrowserUrl: string
40
- }
41
-
42
- export interface Query {
43
- /**
44
- * By default, Wox will only pass input query to plugin.
45
- * plugin author need to enable MetadataFeatureQuerySelection feature to handle selection query
46
- */
47
- Type: "input" | "selection"
48
- /**
49
- * Raw query, this includes trigger keyword if it has
50
- * We didn't recommend use this property directly. You should always use Search property.
51
- *
52
- * NOTE: Only available when query type is input
53
- */
54
- RawQuery: string
55
- /**
56
- * Trigger keyword of a query. It can be empty if user is using global trigger keyword.
57
- *
58
- * NOTE: Only available when query type is input
59
- */
60
- TriggerKeyword?: string
61
- /**
62
- * Command part of a query.
63
- *
64
- * NOTE: Only available when query type is input
65
- */
66
- Command?: string
67
- /**
68
- * Search part of a query.
69
- *
70
- * NOTE: Only available when query type is input
71
- */
72
- Search: string
73
-
74
- /**
75
- * User selected or drag-drop data, can be text or file or image etc
76
- *
77
- * NOTE: Only available when query type is selection
78
- */
79
- Selection: Selection
80
-
81
- /**
82
- * Additional query environment data
83
- * expose more context env data to plugin, E.g. plugin A only show result when active window title is "Chrome"
84
- */
85
- Env: QueryEnv
86
-
87
- /**
88
- * Whether current query is global query
89
- */
90
- IsGlobalQuery(): boolean
91
- }
92
-
93
- export interface Result {
94
- Id?: string
95
- Title: string
96
- SubTitle?: string
97
- Icon: WoxImage
98
- Preview?: WoxPreview
99
- Score?: number
100
- Group?: string
101
- GroupScore?: number
102
- Tails?: ResultTail[]
103
- ContextData?: string
104
- Actions?: ResultAction[]
105
- }
106
-
107
- export interface ResultTail {
108
- Type: "text" | "image"
109
- Text?: string
110
- Image?: WoxImage
111
- /** Tail id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you */
112
- Id?: string
113
- /** Additional data associate with this tail, can be retrieved later */
114
- ContextData?: string
115
- }
116
-
117
- /**
118
- * Result that can be updated directly in the UI.
119
- *
120
- * All fields except Id are optional. Only non-undefined fields will be updated.
121
- *
122
- * Example usage:
123
- * ```typescript
124
- * // Update only the title
125
- * const success = await api.updateResult(ctx, {
126
- * Id: resultId,
127
- * Title: "Downloading... 50%"
128
- * })
129
- *
130
- * // Update title and tails
131
- * const success = await api.updateResult(ctx, {
132
- * Id: resultId,
133
- * Title: "Processing...",
134
- * Tails: [{ Type: "text", Text: "Step 1/3" }]
135
- * })
136
- * ```
137
- */
138
- export interface UpdatableResult {
139
- /** Required - identifies which result to update */
140
- Id: string
141
- /** Optional - update the title */
142
- Title?: string
143
- /** Optional - update the subtitle */
144
- SubTitle?: string
145
- /** Optional - update the tails */
146
- Tails?: ResultTail[]
147
- /** Optional - update the preview */
148
- Preview?: WoxPreview
149
- /** Optional - update the actions */
150
- Actions?: ResultAction[]
151
- }
152
-
153
- /**
154
- * Represents an action that can be updated directly in the UI.
155
- *
156
- * This allows updating a single action's UI (name, icon, action callback) without replacing the entire actions array.
157
- * All fields except ResultId and ActionId are optional. Only non-undefined fields will be updated.
158
- *
159
- * @example
160
- * ```typescript
161
- * // Update only the action name
162
- * const success = await api.UpdateResultAction(ctx, {
163
- * ResultId: actionContext.ResultId,
164
- * ActionId: actionContext.ResultActionId,
165
- * Name: "Remove from favorite"
166
- * })
167
- *
168
- * // Update name, icon and action callback
169
- * const success = await api.UpdateResultAction(ctx, {
170
- * ResultId: actionContext.ResultId,
171
- * ActionId: actionContext.ResultActionId,
172
- * Name: "Add to favorite",
173
- * Icon: { ImageType: "emoji", ImageData: "⭐" },
174
- * Action: async (actionContext) => {
175
- * // New action logic
176
- * }
177
- * })
178
- * ```
179
- */
180
- export interface UpdatableResultAction {
181
- /** Required - identifies which result contains the action */
182
- ResultId: string
183
- /** Required - identifies which action to update */
184
- ActionId: string
185
- /** Optional - update the action name */
186
- Name?: string
187
- /** Optional - update the action icon */
188
- Icon?: WoxImage
189
- /** Optional - update the action callback */
190
- Action?: (actionContext: ActionContext) => Promise<void>
191
- }
192
-
193
- export interface ResultAction {
194
- /**
195
- * Result id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you
196
- */
197
- Id?: string
198
- Name: string
199
- Icon?: WoxImage
200
- /**
201
- * If true, Wox will use this action as default action. There can be only one default action in results
202
- * This can be omitted, if you don't set it, Wox will use the first action as default action
203
- */
204
- IsDefault?: boolean
205
- /**
206
- * If true, Wox will not hide after user select this result
207
- */
208
- PreventHideAfterAction?: boolean
209
- Action: (actionContext: ActionContext) => Promise<void>
210
- /**
211
- * Hotkey to trigger this action. E.g. "ctrl+Shift+Space", "Ctrl+1", "Command+K"
212
- * Case insensitive, space insensitive
213
- *
214
- * If IsDefault is true, Hotkey will be set to enter key by default
215
- */
216
- Hotkey?: string
217
- /**
218
- * Additional data associate with this action, can be retrieved later
219
- */
220
- ContextData?: string
221
- }
222
-
223
- export interface ActionContext {
224
- /**
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
228
- */
229
- ResultId: string
230
- /**
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 UpdateResultAction API to update this action's UI
234
- */
235
- ResultActionId: string
236
- /**
237
- * Additional data associated with this result
238
- */
239
- ContextData: string
240
- }
241
-
242
- export interface MRUData {
243
- PluginID: string
244
- Title: string
245
- SubTitle: string
246
- Icon: WoxImage
247
- ContextData: string
248
- }
249
-
250
- export interface PluginInitParams {
251
- API: PublicAPI
252
- PluginDirectory: string
253
- }
254
-
255
- export interface ChangeQueryParam {
256
- QueryType: "input" | "selection"
257
- QueryText?: string
258
- QuerySelection?: Selection
259
- }
260
-
261
- export interface RefreshQueryParam {
262
- /**
263
- * Controls whether to maintain the previously selected item index after refresh.
264
- * When true, the user's current selection index in the results list is preserved.
265
- * When false, the selection resets to the first item (index 0).
266
- */
267
- PreserveSelectedIndex: boolean
268
- }
269
-
270
- export interface PublicAPI {
271
- /**
272
- * Change Wox query
273
- */
274
- ChangeQuery: (ctx: Context, query: ChangeQueryParam) => Promise<void>
275
-
276
- /**
277
- * Hide Wox
278
- */
279
- HideApp: (ctx: Context) => Promise<void>
280
-
281
- /**
282
- * Show Wox
283
- */
284
- ShowApp: (ctx: Context) => Promise<void>
285
-
286
- /**
287
- * Check if Wox window is currently visible
288
- */
289
- IsVisible: (ctx: Context) => Promise<boolean>
290
-
291
- /**
292
- * Notify message
293
- */
294
- Notify: (ctx: Context, message: string) => Promise<void>
295
-
296
- /**
297
- * Write log
298
- */
299
- Log: (ctx: Context, level: "Info" | "Error" | "Debug" | "Warning", msg: string) => Promise<void>
300
-
301
- /**
302
- * Get translation of current language
303
- */
304
- GetTranslation: (ctx: Context, key: string) => Promise<string>
305
-
306
- /**
307
- * Get customized setting
308
- *
309
- * will try to get platform specific setting first, if not found, will try to get global setting
310
- */
311
- GetSetting: (ctx: Context, key: string) => Promise<string>
312
-
313
- /**
314
- * Save customized setting
315
- *
316
- * @isPlatformSpecific If true, setting will be only saved in current platform. If false, setting will be available in all platforms
317
- */
318
- SaveSetting: (ctx: Context, key: string, value: string, isPlatformSpecific: boolean) => Promise<void>
319
-
320
- /**
321
- * Register setting changed callback
322
- */
323
- OnSettingChanged: (ctx: Context, callback: (key: string, value: string) => void) => Promise<void>
324
-
325
- /**
326
- * Get dynamic setting definition
327
- */
328
- OnGetDynamicSetting: (ctx: Context, callback: (key: string) => PluginSettingDefinitionItem) => Promise<void>
329
-
330
- /**
331
- * Register deep link callback
332
- */
333
- OnDeepLink: (ctx: Context, callback: (arguments: MapString) => void) => Promise<void>
334
-
335
- /**
336
- * Register on load event
337
- */
338
- OnUnload: (ctx: Context, callback: () => Promise<void>) => Promise<void>
339
-
340
- /**
341
- * Register query commands
342
- */
343
- RegisterQueryCommands: (ctx: Context, commands: MetadataCommand[]) => Promise<void>
344
-
345
- /**
346
- * Chat using LLM
347
- */
348
- LLMStream: (ctx: Context, conversations: AI.Conversation[], callback: AI.ChatStreamFunc) => Promise<void>
349
-
350
- /**
351
- * Register MRU restore callback
352
- * @param ctx Context
353
- * @param callback Callback function that takes MRUData and returns Result or null
354
- * Return null if the MRU data is no longer valid
355
- */
356
- OnMRURestore: (ctx: Context, callback: (mruData: MRUData) => Promise<Result | null>) => Promise<void>
357
-
358
- /**
359
- * Get the current state of a result that is displayed in the UI.
360
- *
361
- * Returns UpdatableResult with current values if the result is still visible.
362
- * Returns null if the result is no longer visible.
363
- *
364
- * Note: System actions and tails (like favorite icon) are automatically filtered out.
365
- * They will be re-added by the system when you call UpdateResult().
366
- *
367
- * Example:
368
- * ```typescript
369
- * // In an action handler
370
- * Action: async (actionContext) => {
371
- * // Get current result state
372
- * const updatableResult = await api.GetUpdatableResult(ctx, actionContext.ResultId)
373
- * if (updatableResult === null) {
374
- * return // Result no longer visible
375
- * }
376
- *
377
- * // Modify the result
378
- * updatableResult.Title = "Updated title"
379
- * updatableResult.Tails?.push({ Type: "text", Text: "New tail" })
380
- *
381
- * // Update the result
382
- * await api.UpdateResult(ctx, updatableResult)
383
- * }
384
- * ```
385
- *
386
- * @param ctx Context
387
- * @param resultId ID of the result to get
388
- * @returns Promise<UpdatableResult | null> Current result state, or null if not visible
389
- */
390
- GetUpdatableResult: (ctx: Context, resultId: string) => Promise<UpdatableResult | null>
391
-
392
- /**
393
- * Update a query result that is currently displayed in the UI.
394
- *
395
- * Returns true if the result was successfully updated (still visible in UI).
396
- * Returns false if the result is no longer visible.
397
- *
398
- * This method is designed for long-running operations within Action handlers.
399
- * Best practices:
400
- * - Set PreventHideAfterAction: true in your action
401
- * - Only use during action execution or in background tasks spawned by actions
402
- * - For periodic updates, start a timer in init() and track result IDs
403
- *
404
- * Example:
405
- * ```typescript
406
- * // In an action handler
407
- * Action: async (actionContext) => {
408
- * // Update only the title
409
- * const success = await api.UpdateResult(ctx, {
410
- * Id: actionContext.ResultId,
411
- * Title: "Downloading... 50%"
412
- * })
413
- *
414
- * // Update title and tails
415
- * const success = await api.UpdateResult(ctx, {
416
- * Id: actionContext.ResultId,
417
- * Title: "Processing...",
418
- * Tails: [{ Type: "text", Text: "Step 1/3" }]
419
- * })
420
- * }
421
- * ```
422
- *
423
- * @param ctx Context
424
- * @param result UpdatableResult with Id (required) and optional fields to update
425
- * @returns Promise<boolean> True if updated successfully, false if result no longer visible
426
- */
427
- UpdateResult: (ctx: Context, result: UpdatableResult) => Promise<boolean>
428
-
429
- /**
430
- * Update a single action within a query result that is currently displayed in the UI.
431
- *
432
- * Returns true if the action was successfully updated (result still visible in UI).
433
- * Returns false if the result is no longer visible.
434
- *
435
- * This method is designed for updating action UI after execution, such as toggling
436
- * between "Add to favorite" and "Remove from favorite" states.
437
- *
438
- * Best practices:
439
- * - Set PreventHideAfterAction: true in your action
440
- * - Use actionContext.ResultActionId to identify which action to update
441
- * - Only update fields that have changed (use undefined for fields you don't want to update)
442
- *
443
- * Example:
444
- * ```typescript
445
- * // In an action handler
446
- * Action: async (actionContext) => {
447
- * if (isFavorite) {
448
- * removeFavorite()
449
- * const success = await api.UpdateResultAction(ctx, {
450
- * ResultId: actionContext.ResultId,
451
- * ActionId: actionContext.ResultActionId,
452
- * Name: "Add to favorite",
453
- * Icon: { ImageType: "emoji", ImageData: "⭐" }
454
- * })
455
- * } else {
456
- * addFavorite()
457
- * const success = await api.UpdateResultAction(ctx, {
458
- * ResultId: actionContext.ResultId,
459
- * ActionId: actionContext.ResultActionId,
460
- * Name: "Remove from favorite",
461
- * Icon: { ImageType: "emoji", ImageData: "❌" }
462
- * })
463
- * }
464
- * }
465
- * ```
466
- *
467
- * @param ctx Context
468
- * @param action UpdatableResultAction with ResultId, ActionId (required) and optional fields to update
469
- * @returns Promise<boolean> True if updated successfully, false if result no longer visible
470
- */
471
- UpdateResultAction: (ctx: Context, action: UpdatableResultAction) => Promise<boolean>
472
-
473
- /**
474
- * Re-execute the current query with the existing query text.
475
- * This is useful when plugin data changes and you want to update the displayed results.
476
- *
477
- * Example - Refresh after marking item as favorite:
478
- * ```typescript
479
- * Action: async (actionContext) => {
480
- * markAsFavorite(item)
481
- * // Refresh query and preserve user's current selection
482
- * await api.RefreshQuery(ctx, { PreserveSelectedIndex: true })
483
- * }
484
- * ```
485
- *
486
- * Example - Refresh after deleting item:
487
- * ```typescript
488
- * Action: async (actionContext) => {
489
- * deleteItem(item)
490
- * // Refresh query and reset to first item
491
- * await api.RefreshQuery(ctx, { PreserveSelectedIndex: false })
492
- * }
493
- * ```
494
- *
495
- * @param ctx Context
496
- * @param param RefreshQueryParam to control refresh behavior
497
- */
498
- RefreshQuery: (ctx: Context, param: RefreshQueryParam) => Promise<void>
499
- }
500
-
501
- export type WoxImageType = "absolute" | "relative" | "base64" | "svg" | "url" | "emoji" | "lottie"
502
-
503
- export interface WoxImage {
504
- ImageType: WoxImageType
505
- ImageData: string
506
- }
507
-
508
- export type WoxPreviewType = "markdown" | "text" | "image" | "url" | "file"
509
-
510
- export interface WoxPreview {
511
- PreviewType: WoxPreviewType
512
- PreviewData: string
513
- PreviewProperties: Record<string, string>
514
- }
515
-
516
- export declare interface Context {
517
- Values: { [key: string]: string }
518
- Get: (key: string) => string | undefined
519
- Set: (key: string, value: string) => void
520
- Exists: (key: string) => boolean
521
- }
522
-
523
- export function NewContext(): Context
524
-
525
- export function NewContextWithValue(key: string, value: string): Context
526
-
527
- export function NewBase64WoxImage(imageData: string): WoxImage
1
+ import { MetadataCommand, PluginSettingDefinitionItem } from "./setting.js"
2
+ import { AI } from "./ai.js"
3
+
4
+ export type MapString = { [key: string]: string }
5
+
6
+ export type Platform = "windows" | "darwin" | "linux"
7
+
8
+ export interface Plugin {
9
+ init: (ctx: Context, initParams: PluginInitParams) => Promise<void>
10
+ query: (ctx: Context, query: Query) => Promise<Result[]>
11
+ }
12
+
13
+ export interface Selection {
14
+ Type: "text" | "file"
15
+ // Only available when Type is text
16
+ Text: string
17
+ // Only available when Type is file
18
+ FilePaths: string[]
19
+ }
20
+
21
+ export interface QueryEnv {
22
+ /**
23
+ * Active window title when user query
24
+ */
25
+ ActiveWindowTitle: string
26
+
27
+ /**
28
+ * Active window pid when user query, 0 if not available
29
+ */
30
+ ActiveWindowPid: number
31
+
32
+ /**
33
+ * Active window icon when user query, may be empty
34
+ */
35
+ ActiveWindowIcon: WoxImage
36
+
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
39
+ ActiveBrowserUrl: string
40
+ }
41
+
42
+ export interface Query {
43
+ /**
44
+ * By default, Wox will only pass input query to plugin.
45
+ * plugin author need to enable MetadataFeatureQuerySelection feature to handle selection query
46
+ */
47
+ Type: "input" | "selection"
48
+ /**
49
+ * Raw query, this includes trigger keyword if it has
50
+ * We didn't recommend use this property directly. You should always use Search property.
51
+ *
52
+ * NOTE: Only available when query type is input
53
+ */
54
+ RawQuery: string
55
+ /**
56
+ * Trigger keyword of a query. It can be empty if user is using global trigger keyword.
57
+ *
58
+ * NOTE: Only available when query type is input
59
+ */
60
+ TriggerKeyword?: string
61
+ /**
62
+ * Command part of a query.
63
+ *
64
+ * NOTE: Only available when query type is input
65
+ */
66
+ Command?: string
67
+ /**
68
+ * Search part of a query.
69
+ *
70
+ * NOTE: Only available when query type is input
71
+ */
72
+ Search: string
73
+
74
+ /**
75
+ * User selected or drag-drop data, can be text or file or image etc
76
+ *
77
+ * NOTE: Only available when query type is selection
78
+ */
79
+ Selection: Selection
80
+
81
+ /**
82
+ * Additional query environment data
83
+ * expose more context env data to plugin, E.g. plugin A only show result when active window title is "Chrome"
84
+ */
85
+ Env: QueryEnv
86
+
87
+ /**
88
+ * Whether current query is global query
89
+ */
90
+ IsGlobalQuery(): boolean
91
+ }
92
+
93
+ export interface Result {
94
+ Id?: string
95
+ Title: string
96
+ SubTitle?: string
97
+ Icon: WoxImage
98
+ Preview?: WoxPreview
99
+ Score?: number
100
+ Group?: string
101
+ GroupScore?: number
102
+ Tails?: ResultTail[]
103
+ ContextData?: string
104
+ Actions?: ResultAction[]
105
+ }
106
+
107
+ export interface ResultTail {
108
+ Type: "text" | "image"
109
+ Text?: string
110
+ Image?: WoxImage
111
+ /** Tail id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you */
112
+ Id?: string
113
+ /** Additional data associate with this tail, can be retrieved later */
114
+ ContextData?: string
115
+ }
116
+
117
+ /**
118
+ * Result that can be updated directly in the UI.
119
+ *
120
+ * All fields except Id are optional. Only non-undefined fields will be updated.
121
+ *
122
+ * Example usage:
123
+ * ```typescript
124
+ * // Update only the title
125
+ * const success = await api.updateResult(ctx, {
126
+ * Id: resultId,
127
+ * Title: "Downloading... 50%"
128
+ * })
129
+ *
130
+ * // Update title and tails
131
+ * const success = await api.updateResult(ctx, {
132
+ * Id: resultId,
133
+ * Title: "Processing...",
134
+ * Tails: [{ Type: "text", Text: "Step 1/3" }]
135
+ * })
136
+ * ```
137
+ */
138
+ export interface UpdatableResult {
139
+ /** Required - identifies which result to update */
140
+ Id: string
141
+ /** Optional - update the title */
142
+ Title?: string
143
+ /** Optional - update the subtitle */
144
+ SubTitle?: string
145
+ /** Optional - update the tails */
146
+ Tails?: ResultTail[]
147
+ /** Optional - update the preview */
148
+ Preview?: WoxPreview
149
+ /** Optional - update the actions */
150
+ Actions?: ResultAction[]
151
+ }
152
+
153
+ /**
154
+ * Represents an action that can be updated directly in the UI.
155
+ *
156
+ * This allows updating a single action's UI (name, icon, action callback) without replacing the entire actions array.
157
+ * All fields except ResultId and ActionId are optional. Only non-undefined fields will be updated.
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Update only the action name
162
+ * const success = await api.UpdateResultAction(ctx, {
163
+ * ResultId: actionContext.ResultId,
164
+ * ActionId: actionContext.ResultActionId,
165
+ * Name: "Remove from favorite"
166
+ * })
167
+ *
168
+ * // Update name, icon and action callback
169
+ * const success = await api.UpdateResultAction(ctx, {
170
+ * ResultId: actionContext.ResultId,
171
+ * ActionId: actionContext.ResultActionId,
172
+ * Name: "Add to favorite",
173
+ * Icon: { ImageType: "emoji", ImageData: "⭐" },
174
+ * Action: async (actionContext) => {
175
+ * // New action logic
176
+ * }
177
+ * })
178
+ * ```
179
+ */
180
+ export interface UpdatableResultAction {
181
+ /** Required - identifies which result contains the action */
182
+ ResultId: string
183
+ /** Required - identifies which action to update */
184
+ ActionId: string
185
+ /** Optional - update the action name */
186
+ Name?: string
187
+ /** Optional - update the action icon */
188
+ Icon?: WoxImage
189
+ /** Optional - update the action callback */
190
+ Action?: (actionContext: ActionContext) => Promise<void>
191
+ }
192
+
193
+ export type ResultActionType = "execute" | "form"
194
+
195
+ export type ResultAction = ExecuteResultAction | FormResultAction
196
+
197
+ export interface ExecuteResultAction {
198
+ /**
199
+ * Result id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you
200
+ */
201
+ Id?: string
202
+ Type?: "execute"
203
+ Name: string
204
+ Icon?: WoxImage
205
+ /**
206
+ * If true, Wox will use this action as default action. There can be only one default action in results
207
+ * This can be omitted, if you don't set it, Wox will use the first action as default action
208
+ */
209
+ IsDefault?: boolean
210
+ /**
211
+ * If true, Wox will not hide after user select this result
212
+ */
213
+ PreventHideAfterAction?: boolean
214
+ Action: (actionContext: ActionContext) => Promise<void>
215
+ /**
216
+ * Hotkey to trigger this action. E.g. "ctrl+Shift+Space", "Ctrl+1", "Command+K"
217
+ * Case insensitive, space insensitive
218
+ *
219
+ * If IsDefault is true, Hotkey will be set to enter key by default
220
+ */
221
+ Hotkey?: string
222
+ /**
223
+ * Additional data associate with this action, can be retrieved later
224
+ */
225
+ ContextData?: string
226
+ }
227
+
228
+ export interface FormResultAction {
229
+ /**
230
+ * Result id, should be unique. It's optional, if you don't set it, Wox will assign a random id for you
231
+ */
232
+ Id?: string
233
+ Type: "form"
234
+ Name: string
235
+ Icon?: WoxImage
236
+ /**
237
+ * If true, Wox will use this action as default action. There can be only one default action in results
238
+ * This can be omitted, if you don't set it, Wox will use the first action as default action
239
+ */
240
+ IsDefault?: boolean
241
+ /**
242
+ * If true, Wox will not hide after user select this result
243
+ */
244
+ PreventHideAfterAction?: boolean
245
+ Form: PluginSettingDefinitionItem[]
246
+ OnSubmit: (actionContext: FormActionContext) => Promise<void>
247
+ /**
248
+ * Hotkey to trigger this action. E.g. "ctrl+Shift+Space", "Ctrl+1", "Command+K"
249
+ * Case insensitive, space insensitive
250
+ *
251
+ * If IsDefault is true, Hotkey will be set to enter key by default
252
+ */
253
+ Hotkey?: string
254
+ /**
255
+ * Additional data associate with this action, can be retrieved later
256
+ */
257
+ ContextData?: string
258
+ }
259
+
260
+ export interface ActionContext {
261
+ /**
262
+ * The ID of the result that triggered this action
263
+ * This is automatically set by Wox when the action is invoked
264
+ * Useful for calling UpdateResult API to update the result's UI
265
+ */
266
+ ResultId: string
267
+ /**
268
+ * The ID of the action that was triggered
269
+ * This is automatically set by Wox when the action is invoked
270
+ * Useful for calling UpdateResultAction API to update this action's UI
271
+ */
272
+ ResultActionId: string
273
+ /**
274
+ * Additional data associated with this result
275
+ */
276
+ ContextData: string
277
+ }
278
+
279
+ export interface FormActionContext extends ActionContext {
280
+ Values: Record<string, string>
281
+ }
282
+
283
+ export interface MRUData {
284
+ PluginID: string
285
+ Title: string
286
+ SubTitle: string
287
+ Icon: WoxImage
288
+ ContextData: string
289
+ }
290
+
291
+ export interface PluginInitParams {
292
+ API: PublicAPI
293
+ PluginDirectory: string
294
+ }
295
+
296
+ export interface ChangeQueryParam {
297
+ QueryType: "input" | "selection"
298
+ QueryText?: string
299
+ QuerySelection?: Selection
300
+ }
301
+
302
+ export interface RefreshQueryParam {
303
+ /**
304
+ * Controls whether to maintain the previously selected item index after refresh.
305
+ * When true, the user's current selection index in the results list is preserved.
306
+ * When false, the selection resets to the first item (index 0).
307
+ */
308
+ PreserveSelectedIndex: boolean
309
+ }
310
+
311
+ export interface PublicAPI {
312
+ /**
313
+ * Change Wox query
314
+ */
315
+ ChangeQuery: (ctx: Context, query: ChangeQueryParam) => Promise<void>
316
+
317
+ /**
318
+ * Hide Wox
319
+ */
320
+ HideApp: (ctx: Context) => Promise<void>
321
+
322
+ /**
323
+ * Show Wox
324
+ */
325
+ ShowApp: (ctx: Context) => Promise<void>
326
+
327
+ /**
328
+ * Check if Wox window is currently visible
329
+ */
330
+ IsVisible: (ctx: Context) => Promise<boolean>
331
+
332
+ /**
333
+ * Notify message
334
+ */
335
+ Notify: (ctx: Context, message: string) => Promise<void>
336
+
337
+ /**
338
+ * Write log
339
+ */
340
+ Log: (ctx: Context, level: "Info" | "Error" | "Debug" | "Warning", msg: string) => Promise<void>
341
+
342
+ /**
343
+ * Get translation of current language
344
+ */
345
+ GetTranslation: (ctx: Context, key: string) => Promise<string>
346
+
347
+ /**
348
+ * Get customized setting
349
+ *
350
+ * will try to get platform specific setting first, if not found, will try to get global setting
351
+ */
352
+ GetSetting: (ctx: Context, key: string) => Promise<string>
353
+
354
+ /**
355
+ * Save customized setting
356
+ *
357
+ * @isPlatformSpecific If true, setting will be only saved in current platform. If false, setting will be available in all platforms
358
+ */
359
+ SaveSetting: (ctx: Context, key: string, value: string, isPlatformSpecific: boolean) => Promise<void>
360
+
361
+ /**
362
+ * Register setting changed callback
363
+ */
364
+ OnSettingChanged: (ctx: Context, callback: (key: string, value: string) => void) => Promise<void>
365
+
366
+ /**
367
+ * Get dynamic setting definition
368
+ */
369
+ OnGetDynamicSetting: (ctx: Context, callback: (key: string) => PluginSettingDefinitionItem) => Promise<void>
370
+
371
+ /**
372
+ * Register deep link callback
373
+ */
374
+ OnDeepLink: (ctx: Context, callback: (arguments: MapString) => void) => Promise<void>
375
+
376
+ /**
377
+ * Register on load event
378
+ */
379
+ OnUnload: (ctx: Context, callback: () => Promise<void>) => Promise<void>
380
+
381
+ /**
382
+ * Register query commands
383
+ */
384
+ RegisterQueryCommands: (ctx: Context, commands: MetadataCommand[]) => Promise<void>
385
+
386
+ /**
387
+ * Chat using LLM
388
+ */
389
+ LLMStream: (ctx: Context, conversations: AI.Conversation[], callback: AI.ChatStreamFunc) => Promise<void>
390
+
391
+ /**
392
+ * Register MRU restore callback
393
+ * @param ctx Context
394
+ * @param callback Callback function that takes MRUData and returns Result or null
395
+ * Return null if the MRU data is no longer valid
396
+ */
397
+ OnMRURestore: (ctx: Context, callback: (mruData: MRUData) => Promise<Result | null>) => Promise<void>
398
+
399
+ /**
400
+ * Get the current state of a result that is displayed in the UI.
401
+ *
402
+ * Returns UpdatableResult with current values if the result is still visible.
403
+ * Returns null if the result is no longer visible.
404
+ *
405
+ * Note: System actions and tails (like favorite icon) are automatically filtered out.
406
+ * They will be re-added by the system when you call UpdateResult().
407
+ *
408
+ * Example:
409
+ * ```typescript
410
+ * // In an action handler
411
+ * Action: async (actionContext) => {
412
+ * // Get current result state
413
+ * const updatableResult = await api.GetUpdatableResult(ctx, actionContext.ResultId)
414
+ * if (updatableResult === null) {
415
+ * return // Result no longer visible
416
+ * }
417
+ *
418
+ * // Modify the result
419
+ * updatableResult.Title = "Updated title"
420
+ * updatableResult.Tails?.push({ Type: "text", Text: "New tail" })
421
+ *
422
+ * // Update the result
423
+ * await api.UpdateResult(ctx, updatableResult)
424
+ * }
425
+ * ```
426
+ *
427
+ * @param ctx Context
428
+ * @param resultId ID of the result to get
429
+ * @returns Promise<UpdatableResult | null> Current result state, or null if not visible
430
+ */
431
+ GetUpdatableResult: (ctx: Context, resultId: string) => Promise<UpdatableResult | null>
432
+
433
+ /**
434
+ * Update a query result that is currently displayed in the UI.
435
+ *
436
+ * Returns true if the result was successfully updated (still visible in UI).
437
+ * Returns false if the result is no longer visible.
438
+ *
439
+ * This method is designed for long-running operations within Action handlers.
440
+ * Best practices:
441
+ * - Set PreventHideAfterAction: true in your action
442
+ * - Only use during action execution or in background tasks spawned by actions
443
+ * - For periodic updates, start a timer in init() and track result IDs
444
+ *
445
+ * Example:
446
+ * ```typescript
447
+ * // In an action handler
448
+ * Action: async (actionContext) => {
449
+ * // Update only the title
450
+ * const success = await api.UpdateResult(ctx, {
451
+ * Id: actionContext.ResultId,
452
+ * Title: "Downloading... 50%"
453
+ * })
454
+ *
455
+ * // Update title and tails
456
+ * const success = await api.UpdateResult(ctx, {
457
+ * Id: actionContext.ResultId,
458
+ * Title: "Processing...",
459
+ * Tails: [{ Type: "text", Text: "Step 1/3" }]
460
+ * })
461
+ * }
462
+ * ```
463
+ *
464
+ * @param ctx Context
465
+ * @param result UpdatableResult with Id (required) and optional fields to update
466
+ * @returns Promise<boolean> True if updated successfully, false if result no longer visible
467
+ */
468
+ UpdateResult: (ctx: Context, result: UpdatableResult) => Promise<boolean>
469
+
470
+ /**
471
+ * Update a single action within a query result that is currently displayed in the UI.
472
+ *
473
+ * Returns true if the action was successfully updated (result still visible in UI).
474
+ * Returns false if the result is no longer visible.
475
+ *
476
+ * This method is designed for updating action UI after execution, such as toggling
477
+ * between "Add to favorite" and "Remove from favorite" states.
478
+ *
479
+ * Best practices:
480
+ * - Set PreventHideAfterAction: true in your action
481
+ * - Use actionContext.ResultActionId to identify which action to update
482
+ * - Only update fields that have changed (use undefined for fields you don't want to update)
483
+ *
484
+ * Example:
485
+ * ```typescript
486
+ * // In an action handler
487
+ * Action: async (actionContext) => {
488
+ * if (isFavorite) {
489
+ * removeFavorite()
490
+ * const success = await api.UpdateResultAction(ctx, {
491
+ * ResultId: actionContext.ResultId,
492
+ * ActionId: actionContext.ResultActionId,
493
+ * Name: "Add to favorite",
494
+ * Icon: { ImageType: "emoji", ImageData: "⭐" }
495
+ * })
496
+ * } else {
497
+ * addFavorite()
498
+ * const success = await api.UpdateResultAction(ctx, {
499
+ * ResultId: actionContext.ResultId,
500
+ * ActionId: actionContext.ResultActionId,
501
+ * Name: "Remove from favorite",
502
+ * Icon: { ImageType: "emoji", ImageData: "❌" }
503
+ * })
504
+ * }
505
+ * }
506
+ * ```
507
+ *
508
+ * @param ctx Context
509
+ * @param action UpdatableResultAction with ResultId, ActionId (required) and optional fields to update
510
+ * @returns Promise<boolean> True if updated successfully, false if result no longer visible
511
+ */
512
+ UpdateResultAction: (ctx: Context, action: UpdatableResultAction) => Promise<boolean>
513
+
514
+ /**
515
+ * Re-execute the current query with the existing query text.
516
+ * This is useful when plugin data changes and you want to update the displayed results.
517
+ *
518
+ * Example - Refresh after marking item as favorite:
519
+ * ```typescript
520
+ * Action: async (actionContext) => {
521
+ * markAsFavorite(item)
522
+ * // Refresh query and preserve user's current selection
523
+ * await api.RefreshQuery(ctx, { PreserveSelectedIndex: true })
524
+ * }
525
+ * ```
526
+ *
527
+ * Example - Refresh after deleting item:
528
+ * ```typescript
529
+ * Action: async (actionContext) => {
530
+ * deleteItem(item)
531
+ * // Refresh query and reset to first item
532
+ * await api.RefreshQuery(ctx, { PreserveSelectedIndex: false })
533
+ * }
534
+ * ```
535
+ *
536
+ * @param ctx Context
537
+ * @param param RefreshQueryParam to control refresh behavior
538
+ */
539
+ RefreshQuery: (ctx: Context, param: RefreshQueryParam) => Promise<void>
540
+ }
541
+
542
+ export type WoxImageType = "absolute" | "relative" | "base64" | "svg" | "url" | "emoji" | "lottie"
543
+
544
+ export interface WoxImage {
545
+ ImageType: WoxImageType
546
+ ImageData: string
547
+ }
548
+
549
+ export type WoxPreviewType = "markdown" | "text" | "image" | "url" | "file"
550
+
551
+ export interface WoxPreview {
552
+ PreviewType: WoxPreviewType
553
+ PreviewData: string
554
+ PreviewProperties: Record<string, string>
555
+ }
556
+
557
+ export declare interface Context {
558
+ Values: { [key: string]: string }
559
+ Get: (key: string) => string | undefined
560
+ Set: (key: string, value: string) => void
561
+ Exists: (key: string) => boolean
562
+ }
563
+
564
+ export function NewContext(): Context
565
+
566
+ export function NewContextWithValue(key: string, value: string): Context
567
+
568
+ export function NewBase64WoxImage(imageData: string): WoxImage