utools-api-types 6.1.0 → 7.0.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utools.api.d.ts +103 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utools-api-types",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "description": "TypeScript definitions for uTools API",
5
5
  "repository": {
6
6
  "type": "git",
package/utools.api.d.ts CHANGED
@@ -1,8 +1,44 @@
1
1
  /// <reference path="ubw.d.ts"/>
2
2
  /// <reference path="electron.d.ts"/>
3
3
 
4
+ interface UtoolsAiModel {
5
+ id: string;
6
+ label: string;
7
+ description: string;
8
+ icon: string;
9
+ cost: number;
10
+ }
11
+ interface UtoolsAiResult<T> extends Promise<T> {
12
+ abort(): void;
13
+ }
14
+
15
+ interface UtoolsAiMessage {
16
+ role: "system" | "user" | "assistant";
17
+ content?: string;
18
+ reasoning_content?: string;
19
+ }
20
+
21
+ interface UtoolsAiTool {
22
+ type: "function";
23
+ function?: {
24
+ name: string;
25
+ description: string;
26
+ parameters: {
27
+ type: "object";
28
+ properties: Record<string, any>;
29
+ };
30
+ required?: string[];
31
+ };
32
+ }
33
+
34
+ interface UtoolsAiOption {
35
+ model?: string;
36
+ messages: UtoolsAiMessage[];
37
+ tools?: UtoolsAiTool[];
38
+ }
39
+
4
40
  interface CookieFilter {
5
- url ?: string;
41
+ url?: string;
6
42
  name?: string;
7
43
  domain?: string;
8
44
  path?: string;
@@ -54,6 +90,11 @@ interface UBrowser {
54
90
  * @param savePath 截图保存路径,可以是文件夹 或 .png文件完全路径, 默认保存临时目录
55
91
  */
56
92
  screenshot(arg: string | { x: number, y: number, width: number, height: number }, savePath?: string): this;
93
+ /**
94
+ * 转为 markdown 文本
95
+ * @param selector css 选择器或者XPATH
96
+ */
97
+ markdown(selector?: string): this;
57
98
  /**
58
99
  * 保存为PDF
59
100
  * @param options 选项
@@ -190,25 +231,34 @@ interface UBrowser {
190
231
  * @param options
191
232
  */
192
233
  run<T extends any = any[]>(options: {
193
- show?: boolean,
194
- width?: number,
195
- height?: number,
196
- x?: number,
197
- y?: number,
198
- center?: boolean,
199
- minWidth?: number,
200
- minHeight?: number,
201
- maxWidth?: number,
202
- maxHeight?: number,
203
- resizable?: boolean,
204
- movable?: boolean,
205
- minimizable?: boolean,
206
- maximizable?: boolean,
207
- alwaysOnTop?: boolean,
208
- fullscreen?: boolean,
209
- fullscreenable?: boolean,
210
- enableLargerThanScreen?: boolean,
211
- opacity?: number
234
+ show?: boolean;
235
+ width?: number;
236
+ height?: number;
237
+ x?: number;
238
+ y?: number;
239
+ center?: boolean;
240
+ minWidth?: number;
241
+ minHeight?: number;
242
+ maxWidth?: number;
243
+ maxHeight?: number;
244
+ resizable?: boolean;
245
+ movable?: boolean;
246
+ minimizable?: boolean;
247
+ maximizable?: boolean;
248
+ alwaysOnTop?: boolean;
249
+ fullscreen?: boolean;
250
+ fullscreenable?: boolean;
251
+ enableLargerThanScreen?: boolean;
252
+ opacity?: number;
253
+ frame?: boolean;
254
+ closable?: boolean;
255
+ focusable?: boolean;
256
+ skipTaskbar?: boolean;
257
+ backgroundColor?: string;
258
+ hasShadow?: boolean;
259
+ transparent?: boolean;
260
+ titleBarStyle?: string;
261
+ thickFrame?: boolean;
212
262
  }): Promise<T>;
213
263
  /**
214
264
  * 运行在闲置的 ubrowser 上
@@ -283,6 +333,14 @@ interface FfmpegPromise extends Promise<void> {
283
333
  quit(): void;
284
334
  }
285
335
 
336
+ interface MainPushResult {
337
+ icon?: string,
338
+ text: string,
339
+ title?: string
340
+ }
341
+
342
+ type MainPushResultList = MainPushResult[] | Promise<MainPushResult[]>
343
+
286
344
  interface UToolsApi {
287
345
  /**
288
346
  * 插件应用进入时触发
@@ -291,7 +349,7 @@ interface UToolsApi {
291
349
  /**
292
350
  * 向搜索面板推送消息
293
351
  */
294
- onMainPush<T = any>(callback: (action: { code: string, type: string, payload: T }) => { icon?: string, text: string, title?: string }[], selectCallback: (action: { code: string, type: string, payload: any, option: { icon?: string, text: string, title?: string } }) => void): void;
352
+ onMainPush<T = any>(callback: (action: { code: string, type: string, payload: T }) => MainPushResultList, selectCallback: (action: { code: string, type: string, payload: any, option: MainPushResult }) => void): void;
295
353
  /**
296
354
  * 插件应用隐藏后台或完全退出时触发
297
355
  */
@@ -822,7 +880,30 @@ interface UToolsApi {
822
880
  * @param args ffmpeg 命令行参数
823
881
  * @param onProgress 进度回调
824
882
  */
825
- runFFmpeg(args: string[], onProgress?: () => FfmpegRunProgress): FfmpegPromise;
883
+ runFFmpeg(args: string[], onProgress?: (progress: FfmpegRunProgress) => void): FfmpegPromise;
884
+
885
+ /**
886
+ * 流式调用 AI
887
+ * @param option 选项参数
888
+ * @param option.model 模型
889
+ * @param option.messages 消息
890
+ * @param option.tools 工具集合,使用 function calling 配置
891
+ * @param streamCallback 流式回调
892
+ */
893
+ ai(
894
+ option: UtoolsAiOption,
895
+ streamCallback: (chunk: UtoolsAiMessage) => void
896
+ ): UtoolsAiResult<void>
897
+ /**
898
+ * 非流式调用 AI
899
+ * @param option 选项参数
900
+ */
901
+ ai(option: UtoolsAiOption): UtoolsAiResult<UtoolsAiMessage>
902
+
903
+ /**
904
+ * 获取所有 AI 模型
905
+ */
906
+ allAiModels(): Promise<UtoolsAiModel[]>;
826
907
  }
827
908
 
828
909
  declare var utools: UToolsApi;