ms-types 0.9.42 → 0.10.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-types",
3
- "version": "0.9.42",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -18,6 +18,6 @@
18
18
  "devDependencies": {
19
19
  "vitepress": "^1.6.4",
20
20
  "vitepress-theme-teek": "^1.6.2",
21
- "wrangler": "^4.128.0"
21
+ "wrangler": "^4.129.0"
22
22
  }
23
23
  }
package/types/ai.d.ts ADDED
@@ -0,0 +1,172 @@
1
+ /**
2
+ * AI 模块 让脚本直接在手机上调用大模型:看图回答、是非判断、提取结构化数据、多轮对话。
3
+ * 支持 openai 兼容 / anthropic / gemini 三种协议;模型配置写在脚本里,脚本开头 ai.setProvider 一次即可。
4
+ * 所有方法同步阻塞,失败返回 null / false,原因用 ai.lastError() 查看。
5
+ */
6
+ declare namespace ai {
7
+ /**
8
+ * 模型供应商配置
9
+ */
10
+ interface AiProvider {
11
+ /** 供应商 id,不传时自动生成 */
12
+ id: string;
13
+ /** 展示名,例如 "DeepSeek",调用时可用它选模型 */
14
+ name: string;
15
+ /** 接口协议 */
16
+ protocol: "openai" | "anthropic" | "gemini";
17
+ /** 接口根地址,例如 https://api.openai.com/v1 */
18
+ baseUrl: string;
19
+ /** API Key;openai 协议连本机模型时可为空 */
20
+ apiKey: string;
21
+ /** 默认模型名 */
22
+ model: string;
23
+ /** 额外请求头,某些网关需要 */
24
+ headers: Record<string, string>;
25
+ /** 默认温度;不传则不发该字段,用模型自己的默认值 */
26
+ temperature?: number;
27
+ /** 默认最大输出 token;不传则不发该字段,用模型自己的默认值(Anthropic 因接口必填仍默认 2048) */
28
+ maxTokens?: number;
29
+ /** 是否支持图片输入,默认 true;为 false 时带图调用直接报错 */
30
+ supportsVision: boolean;
31
+ /** 是否为默认供应商 */
32
+ isDefault: boolean;
33
+ }
34
+
35
+ /**
36
+ * ask / judge / extract / chat 的可选参数
37
+ */
38
+ interface AiOptions {
39
+ /** 用哪个供应商:id 或 name;不传用默认 */
40
+ provider?: string;
41
+ /** 临时换模型,覆盖供应商默认模型 */
42
+ model?: string;
43
+ /** 覆盖默认温度 */
44
+ temperature?: number;
45
+ /** 覆盖默认最大输出 token */
46
+ maxTokens?: number;
47
+ /** 超时毫秒,默认 90000 */
48
+ timeout?: number;
49
+ /** 要求模型输出 JSON(extract 自动开启) */
50
+ json?: boolean;
51
+ /** 系统提示(chat 不用这个,写在 messages 里) */
52
+ system?: string;
53
+ /** imageId,与 image 模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径 */
54
+ image?: string;
55
+ /** 对 image 裁剪,同 image.clip:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen" */
56
+ x?: number;
57
+ /** 裁剪区域左上角 Y */
58
+ y?: number;
59
+ /** 裁剪区域右下角 X */
60
+ ex?: number;
61
+ /** 裁剪区域右下角 Y */
62
+ ey?: number;
63
+ /** 多张图,元素同 image,不裁剪 */
64
+ images?: string[];
65
+ /** 仅 extract:期望的 JSON 结构说明,字符串或对象 */
66
+ schema?: string | object;
67
+ }
68
+
69
+ /**
70
+ * chat 的消息项,图片参数与 AiOptions 相同
71
+ */
72
+ interface AiMessage {
73
+ /** 角色 */
74
+ role: "system" | "user" | "assistant";
75
+ /** 文本内容 */
76
+ content: string;
77
+ /** imageId,同 AiOptions.image */
78
+ image?: string;
79
+ /** 裁剪区域,同 AiOptions */
80
+ x?: number;
81
+ y?: number;
82
+ ex?: number;
83
+ ey?: number;
84
+ /** 多张图,同 AiOptions.images */
85
+ images?: string[];
86
+ }
87
+
88
+ /**
89
+ * 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
90
+ * 可登记多个:便宜的文本模型做默认,视觉模型单独一个,调用时用 options.provider 选
91
+ * @param config 新建至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
92
+ * @returns 保存后的完整配置;protocol 不合法或缺 baseUrl / model 时返回 null
93
+ * @example
94
+ * ai.setProvider({ name: "DeepSeek", protocol: "openai", baseUrl: "https://api.deepseek.com", apiKey: "sk-...", model: "deepseek-v4-flash" })
95
+ */
96
+ function setProvider(config: Partial<AiProvider>): AiProvider | null;
97
+ /**
98
+ * 列出已登记的供应商,默认项排在最前
99
+ * @example ai.getProviders().forEach(p => logi(p.name))
100
+ */
101
+ function getProviders(): AiProvider[];
102
+ /**
103
+ * 获取默认供应商
104
+ * @returns 一个都没登记时返回 null
105
+ * @example const p = ai.getDefaultProvider()
106
+ */
107
+ function getDefaultProvider(): AiProvider | null;
108
+ /**
109
+ * 切换默认供应商
110
+ * @param id 供应商 id 或 name
111
+ * @returns id 或 name 存在返回 true
112
+ * @example ai.setDefaultProvider("cheap")
113
+ */
114
+ function setDefaultProvider(id: string): boolean;
115
+ /**
116
+ * 删除供应商;删掉的是默认项时默认转给剩下的第一个
117
+ * @param id 供应商 id 或 name
118
+ * @returns 存在并删除返回 true
119
+ * @example ai.removeProvider("cheap")
120
+ */
121
+ function removeProvider(id: string): boolean;
122
+ /**
123
+ * 单轮提问,可附带图片
124
+ * @param prompt 问题
125
+ * @param options 可选参数,图片参数与 image 模块一致:image 为 imageId,x/y/ex/ey 同 image.clip 裁剪
126
+ * @returns 回复文本;失败返回 null
127
+ * @example
128
+ * ai.ask("屏幕上有几个按钮?", { image: "screen" })
129
+ * ai.ask("这个区域的价格是多少?", { image: "screen", x: 0, y: 300, ex: 750, ey: 500 })
130
+ */
131
+ function ask(prompt: string, options?: AiOptions): string | null;
132
+ /**
133
+ * 是非判断:让模型只回答 yes / no
134
+ * @param question 要判断的问题
135
+ * @param options 同 ask
136
+ * @returns 肯定为 true;否定或请求失败为 false(失败时 lastError() 有内容)
137
+ * @example if (ai.judge("是否出现了「领取成功」?", { image: "screen" })) { ... }
138
+ */
139
+ function judge(question: string, options?: AiOptions): boolean;
140
+ /**
141
+ * 结构化提取:要求模型输出 JSON 并解析成对象或数组
142
+ * @param prompt 提取要求
143
+ * @param options 同 ask,另支持 schema
144
+ * @returns 解析后的对象或数组;没有合法 JSON 或请求失败返回 null
145
+ * @example
146
+ * const d = ai.extract("提取验证码", { image: "screen", x: 100, y: 800, ex: 600, ey: 900, schema: { code: "string" } })
147
+ * if (d) logi(d.code)
148
+ */
149
+ function extract(prompt: string, options?: AiOptions): any | null;
150
+ /**
151
+ * 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 null,不要把空回复推进历史。
152
+ * @param messages 消息数组;直接写字符串等于 user 消息;图片写在该条消息上
153
+ * @param options provider / model / temperature / maxTokens / json / timeout(不用 system / image)
154
+ * @returns 回复文本;失败返回 null
155
+ * @example
156
+ * ai.chat([{ role: "system", content: "你是助手" }, { role: "user", content: "看下这是哪个页面", image: "screen" }])
157
+ */
158
+ function chat(messages: (AiMessage | string)[], options?: AiOptions): string | null;
159
+ /**
160
+ * 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
161
+ * @param text 模型输出
162
+ * @returns 解析结果;失败返回 null
163
+ * @example ai.parseJson("```json\n{\"a\":1}\n```")
164
+ */
165
+ function parseJson(text: string): any | null;
166
+ /**
167
+ * 最近一次调用失败的原因
168
+ * @returns 错误文案;上一次调用成功时返回 null
169
+ * @example if (ai.ask("你好") === null) loge(ai.lastError())
170
+ */
171
+ function lastError(): string | null;
172
+ }
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="action.d.ts" />
2
+ /// <reference path="ai.d.ts" />
2
3
  /// <reference path="appleocr.d.ts" />
3
4
  /// <reference path="cloud.d.ts" />
4
5
  /// <reference path="config.d.ts" />
@@ -0,0 +1,102 @@
1
+ ---@meta
2
+ ---@class Ai
3
+ local _Ai = {}
4
+
5
+ ---@class AiProvider
6
+ ---@field id string 供应商 id,不传时自动生成
7
+ ---@field name string 展示名,例如 "DeepSeek",调用时可用它选模型
8
+ ---@field protocol "openai"|"anthropic"|"gemini" 接口协议
9
+ ---@field baseUrl string 接口根地址,例如 https://api.openai.com/v1
10
+ ---@field apiKey string API Key;openai 协议连本机模型时可为空
11
+ ---@field model string 默认模型名
12
+ ---@field headers table<string, string> 额外请求头,某些网关需要
13
+ ---@field temperature number|nil 默认温度;不传则不发该字段,用模型自己的默认值
14
+ ---@field maxTokens integer|nil 默认最大输出 token;不传则不发该字段,用模型自己的默认值(Anthropic 因接口必填仍默认 2048)
15
+ ---@field supportsVision boolean 是否支持图片输入,默认 true
16
+ ---@field isDefault boolean 是否为默认供应商
17
+
18
+ ---@class AiOptions
19
+ ---@field provider string|nil 用哪个供应商:id 或 name;不传用默认
20
+ ---@field model string|nil 临时换模型,覆盖供应商默认模型
21
+ ---@field temperature number|nil 覆盖默认温度
22
+ ---@field maxTokens integer|nil 覆盖默认最大输出 token
23
+ ---@field timeout integer|nil 超时毫秒,默认 90000
24
+ ---@field json boolean|nil 要求模型输出 JSON(extract 自动开启)
25
+ ---@field system string|nil 系统提示(chat 不用这个,写在 messages 里)
26
+ ---@field image string|nil imageId,与 image 模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径
27
+ ---@field x integer|nil 对 image 裁剪,同 image.clip:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen"
28
+ ---@field y integer|nil 裁剪区域左上角 Y
29
+ ---@field ex integer|nil 裁剪区域右下角 X
30
+ ---@field ey integer|nil 裁剪区域右下角 Y
31
+ ---@field images string[]|nil 多张图,元素同 image,不裁剪
32
+ ---@field schema string|table|nil 仅 extract:期望的 JSON 结构说明
33
+
34
+ ---@class AiMessage 图片参数与 AiOptions 相同
35
+ ---@field role "system"|"user"|"assistant"
36
+ ---@field content string
37
+ ---@field image string|nil
38
+ ---@field x integer|nil
39
+ ---@field y integer|nil
40
+ ---@field ex integer|nil
41
+ ---@field ey integer|nil
42
+ ---@field images string[]|nil
43
+
44
+ --- 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
45
+ --- 至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
46
+ ---@param config table
47
+ ---@return AiProvider|nil 保存后的完整配置;参数不合法返回 nil
48
+ function _Ai.setProvider(config) return nil end
49
+
50
+ --- 列出已登记的供应商,默认项排在最前
51
+ ---@return AiProvider[]
52
+ function _Ai.getProviders() return {} end
53
+
54
+ --- 获取默认供应商;一个都没登记时返回 nil
55
+ ---@return AiProvider|nil
56
+ function _Ai.getDefaultProvider() return nil end
57
+
58
+ --- 切换默认供应商
59
+ ---@param id string 供应商 id 或 name
60
+ ---@return boolean id 或 name 存在返回 true
61
+ function _Ai.setDefaultProvider(id) return true end
62
+
63
+ --- 删除供应商;删掉的是默认项时默认转给剩下的第一个
64
+ ---@param id string 供应商 id 或 name
65
+ ---@return boolean 存在并删除返回 true
66
+ function _Ai.removeProvider(id) return true end
67
+
68
+ --- 单轮提问,可附带图片;图片参数与 image 模块一致(image + x/y/ex/ey,或 images)
69
+ ---@param prompt string
70
+ ---@param options AiOptions|nil
71
+ ---@return string|nil 回复文本;失败返回 nil,原因看 lastError()
72
+ function _Ai.ask(prompt, options) return nil end
73
+
74
+ --- 是非判断:让模型只回答 yes / no
75
+ ---@param question string
76
+ ---@param options AiOptions|nil
77
+ ---@return boolean 肯定为 true;否定或请求失败为 false(失败时 lastError() 有内容)
78
+ function _Ai.judge(question, options) return false end
79
+
80
+ --- 结构化提取:要求模型输出 JSON 并解析成表
81
+ ---@param prompt string
82
+ ---@param options AiOptions|nil 另支持 schema
83
+ ---@return table|nil 解析后的表;没有合法 JSON 或请求失败返回 nil
84
+ function _Ai.extract(prompt, options) return nil end
85
+
86
+ --- 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 nil,不要把空回复推进历史。
87
+ ---@param messages (AiMessage|string)[] 直接写字符串等于 user 消息;图片写在该条消息上
88
+ ---@param options AiOptions|nil provider / model / temperature / maxTokens / json / timeout(不用 system / image)
89
+ ---@return string|nil 回复文本;失败返回 nil
90
+ function _Ai.chat(messages, options) return nil end
91
+
92
+ --- 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
93
+ ---@param text string
94
+ ---@return table|nil
95
+ function _Ai.parseJson(text) return nil end
96
+
97
+ --- 最近一次调用失败的原因;上一次调用成功时返回 nil
98
+ ---@return string|nil
99
+ function _Ai.lastError() return nil end
100
+
101
+ ---@type Ai
102
+ ai = _Ai
package/types/lua/cv.lua CHANGED
@@ -741,12 +741,15 @@ function _OpenCV.imread(path) return nil end
741
741
  function _OpenCV.imdecode(data) return nil end
742
742
 
743
743
  --- imwrite
744
+ --- 格式由扩展名决定,可用 png/apng/jpg/jpeg/jpe/bmp/dib/webp/ppm/pgm/pbm/pnm/pam/sr/ras;
745
+ --- 其它扩展名或通道数不是 1/3/4 的 Mat 返回 false。
744
746
  ---@param path string
745
747
  ---@param mat OpenCV.Mat
746
748
  ---@return boolean
747
749
  function _OpenCV.imwrite(path, mat) return false end
748
750
 
749
751
  --- imencode
752
+ --- 扩展名与通道限制同 imwrite;quality 取值 1-100,仅 jpg 有效。
750
753
  ---@param ext string
751
754
  ---@param mat OpenCV.Mat
752
755
  ---@param quality number|nil
package/types/opencv.d.ts CHANGED
@@ -256,7 +256,14 @@ declare namespace cv {
256
256
  function imread(path: string): Mat | null;
257
257
  /** 仅解码 base64 / data URI;路径与 imageId 请用 `imread` */
258
258
  function imdecode(data: string): Mat | null;
259
+ /**
260
+ * 保存 Mat 到本地文件,格式由扩展名决定。
261
+ * 可用 `png` / `apng` / `jpg` / `jpeg` / `jpe` / `bmp` / `dib` / `webp` /
262
+ * `ppm` / `pgm` / `pbm` / `pnm` / `pam` / `sr` / `ras`;
263
+ * 其它扩展名或通道数不是 1 / 3 / 4 的 Mat 返回 `false`。
264
+ */
259
265
  function imwrite(path: string, mat: Mat): boolean;
266
+ /** 编码为纯 base64;扩展名与通道限制同 `imwrite`,`quality` 取值 1–100(仅 jpg 有效) */
260
267
  function imencode(ext: string, mat: Mat, quality?: number): string | null;
261
268
  function fromImageId(imageId: string): Mat | null;
262
269
  function toImageId(mat: Mat): string | null;
@@ -0,0 +1,172 @@
1
+ /// <reference path="全局模块.d.ts" />
2
+
3
+ /**
4
+ * AI 模块 让脚本直接在手机上调用大模型:看图回答、是非判断、提取结构化数据、多轮对话。
5
+ * 支持 openai 兼容 / anthropic / gemini 三种协议;模型配置写在脚本里,脚本开头 $AI.设置模型 一次即可。
6
+ * 所有方法同步阻塞,失败返回 null / false,原因用 $AI.获取错误() 查看。
7
+ */
8
+ declare namespace $AI {
9
+ /**
10
+ * 模型供应商配置
11
+ */
12
+ interface 模型供应商 {
13
+ /** 供应商 id,不传时自动生成 */
14
+ id: 字符串;
15
+ /** 展示名,例如 "DeepSeek",调用时可用它选模型 */
16
+ name: 字符串;
17
+ /** 接口协议 */
18
+ protocol: "openai" | "anthropic" | "gemini";
19
+ /** 接口根地址,例如 https://api.openai.com/v1 */
20
+ baseUrl: 字符串;
21
+ /** API Key;openai 协议连本机模型时可为空 */
22
+ apiKey: 字符串;
23
+ /** 默认模型名 */
24
+ model: 字符串;
25
+ /** 额外请求头,某些网关需要 */
26
+ headers: 字典<字符串>;
27
+ /** 默认温度;不传则不发该字段,用模型自己的默认值 */
28
+ temperature?: 数字;
29
+ /** 默认最大输出 token;不传则不发该字段,用模型自己的默认值(Anthropic 因接口必填仍默认 2048) */
30
+ maxTokens?: 数字;
31
+ /** 是否支持图片输入,默认 true */
32
+ supportsVision: 布尔值;
33
+ /** 是否为默认供应商 */
34
+ isDefault: 布尔值;
35
+ }
36
+
37
+ /**
38
+ * 提问 / 判断 / 提取 / 对话 的可选参数
39
+ */
40
+ interface 调用选项 {
41
+ /** 用哪个供应商:id 或 name;不传用默认 */
42
+ provider?: 字符串;
43
+ /** 临时换模型 */
44
+ model?: 字符串;
45
+ /** 覆盖默认温度 */
46
+ temperature?: 数字;
47
+ /** 覆盖默认最大输出 token */
48
+ maxTokens?: 数字;
49
+ /** 超时毫秒,默认 90000 */
50
+ timeout?: 数字;
51
+ /** 要求模型输出 JSON(提取 自动开启) */
52
+ json?: 布尔值;
53
+ /** 系统提示 */
54
+ system?: 字符串;
55
+ /** imageId,与图片模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径 */
56
+ image?: 字符串;
57
+ /** 对 image 裁剪,同 $图片.裁剪图片:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen" */
58
+ x?: 数字;
59
+ /** 裁剪区域左上角 Y */
60
+ y?: 数字;
61
+ /** 裁剪区域右下角 X */
62
+ ex?: 数字;
63
+ /** 裁剪区域右下角 Y */
64
+ ey?: 数字;
65
+ /** 多张图,元素同 image,不裁剪 */
66
+ images?: 数组<字符串>;
67
+ /** 仅 提取:期望的 JSON 结构说明 */
68
+ schema?: 字符串 | object;
69
+ }
70
+
71
+ /**
72
+ * 对话 的消息项,图片参数与 调用选项 相同
73
+ */
74
+ interface 对话消息 {
75
+ /** 角色 */
76
+ role: "system" | "user" | "assistant";
77
+ /** 文本内容 */
78
+ content: 字符串;
79
+ /** imageId,同 调用选项.image */
80
+ image?: 字符串;
81
+ /** 裁剪区域,同 调用选项 */
82
+ x?: 数字;
83
+ y?: 数字;
84
+ ex?: 数字;
85
+ ey?: 数字;
86
+ /** 多张图,同 调用选项.images */
87
+ images?: 数组<字符串>;
88
+ }
89
+
90
+ /**
91
+ * 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
92
+ * @param 配置 新建至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新
93
+ * @returns 保存后的完整配置;参数不合法返回 null
94
+ * @example
95
+ * $AI.设置模型({ name: "DeepSeek", protocol: "openai", baseUrl: "https://api.deepseek.com", apiKey: "sk-...", model: "deepseek-v4-flash" })
96
+ */
97
+ function 设置模型(配置: Partial<模型供应商>): 模型供应商 | null;
98
+ /**
99
+ * 列出已登记的供应商,默认项排在最前
100
+ * @example $AI.获取模型列表()
101
+ */
102
+ function 获取模型列表(): 数组<模型供应商>;
103
+ /**
104
+ * 获取默认供应商
105
+ * @returns 一个都没登记时返回 null
106
+ * @example $AI.获取默认模型()
107
+ */
108
+ function 获取默认模型(): 模型供应商 | null;
109
+ /**
110
+ * 切换默认供应商
111
+ * @param id 供应商 id 或 name
112
+ * @returns id 或 name 存在返回 true
113
+ * @example $AI.设置默认模型("cheap")
114
+ */
115
+ function 设置默认模型(id: 字符串): 布尔值;
116
+ /**
117
+ * 删除供应商
118
+ * @param id 供应商 id 或 name
119
+ * @returns 存在并删除返回 true
120
+ * @example $AI.删除模型("cheap")
121
+ */
122
+ function 删除模型(id: 字符串): 布尔值;
123
+ /**
124
+ * 单轮提问,可附带图片
125
+ * @param 问题 问题
126
+ * @param 选项 可选参数,图片参数与图片模块一致:image 为 imageId,x/y/ex/ey 同 $图片.裁剪图片
127
+ * @returns 回复文本;失败返回 null
128
+ * @example
129
+ * $AI.提问("屏幕上有几个按钮?", { image: "screen" })
130
+ * $AI.提问("这个区域的价格是多少?", { image: "screen", x: 0, y: 300, ex: 750, ey: 500 })
131
+ */
132
+ function 提问(问题: 字符串, 选项?: 调用选项): 字符串 | null;
133
+ /**
134
+ * 是非判断:让模型只回答 yes / no
135
+ * @param 问题 要判断的问题
136
+ * @param 选项 同 提问
137
+ * @returns 肯定为 true;否定或请求失败为 false
138
+ * @example if ($AI.判断("是否出现了「领取成功」?", { image: "screen" })) { ... }
139
+ */
140
+ function 判断(问题: 字符串, 选项?: 调用选项): 布尔值;
141
+ /**
142
+ * 结构化提取:要求模型输出 JSON 并解析成对象或数组
143
+ * @param 要求 提取要求
144
+ * @param 选项 同 提问,另支持 schema
145
+ * @returns 解析后的对象或数组;失败返回 null
146
+ * @example
147
+ * const d = $AI.提取("提取验证码", { image: "screen", x: 100, y: 800, ex: 600, ey: 900, schema: { code: "string" } })
148
+ */
149
+ function 提取(要求: 字符串, 选项?: 调用选项): 任意类型 | null;
150
+ /**
151
+ * 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 null,不要把空回复推进历史。
152
+ * @param 消息列表 消息数组;直接写字符串等于 user 消息;图片写在该条消息上
153
+ * @param 选项 provider / model / temperature / maxTokens / json / timeout(不用 system / image)
154
+ * @returns 回复文本;失败返回 null
155
+ * @example
156
+ * $AI.对话([{ role: "system", content: "你是助手" }, { role: "user", content: "看下这是哪个页面", image: "screen" }])
157
+ */
158
+ function 对话(消息列表: 数组<对话消息 | 字符串>, 选项?: 调用选项): 字符串 | null;
159
+ /**
160
+ * 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
161
+ * @param 文本 模型输出
162
+ * @returns 解析结果;失败返回 null
163
+ * @example $AI.解析JSON("```json\n{\"a\":1}\n```")
164
+ */
165
+ function 解析JSON(文本: 字符串): 任意类型 | null;
166
+ /**
167
+ * 最近一次调用失败的原因
168
+ * @returns 错误文案;上一次调用成功时返回 null
169
+ * @example if ($AI.提问("你好") === null) $打印错误日志($AI.获取错误())
170
+ */
171
+ function 获取错误(): 字符串 | null;
172
+ }
@@ -1,4 +1,5 @@
1
1
  /// <reference path="动作模块.d.ts" />
2
+ /// <reference path="AI模块.d.ts" />
2
3
  /// <reference path="工具模块.d.ts" />
3
4
  /// <reference path="节点模块.d.ts" />
4
5
  /// <reference path="卡密模块.d.ts" />