ms-types 0.9.43 → 0.10.1
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 +2 -2
- package/types/ai.d.ts +177 -0
- package/types/index.d.ts +1 -0
- package/types/lua/ai.lua +103 -0
- package/types/zh/AI/346/250/241/345/235/227.d.ts +177 -0
- package/types/zh/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ms-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
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.
|
|
21
|
+
"wrangler": "^4.129.1"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/types/ai.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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.deepseek.com */
|
|
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
|
+
/**
|
|
30
|
+
* 思考级别,只对 openai 协议生效(请求字段 reasoning_effort)。
|
|
31
|
+
* 不传则不发,用服务商默认。
|
|
32
|
+
*/
|
|
33
|
+
reasoningEffort?: "none" | "low" | "medium" | "high" | "xhigh";
|
|
34
|
+
/** 是否支持图片输入,默认 true;为 false 时带图调用直接报错 */
|
|
35
|
+
supportsVision: boolean;
|
|
36
|
+
/** 是否为默认供应商 */
|
|
37
|
+
isDefault: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* ask / judge / extract / chat 的可选参数
|
|
42
|
+
*/
|
|
43
|
+
interface AiOptions {
|
|
44
|
+
/** 用哪个供应商:id 或 name;不传用默认 */
|
|
45
|
+
provider?: string;
|
|
46
|
+
/** 临时换模型,覆盖供应商默认模型 */
|
|
47
|
+
model?: string;
|
|
48
|
+
/** 覆盖默认温度 */
|
|
49
|
+
temperature?: number;
|
|
50
|
+
/** 覆盖默认最大输出 token */
|
|
51
|
+
maxTokens?: number;
|
|
52
|
+
/** 超时毫秒,默认 90000 */
|
|
53
|
+
timeout?: number;
|
|
54
|
+
/** 要求模型输出 JSON(extract 自动开启) */
|
|
55
|
+
json?: boolean;
|
|
56
|
+
/** 系统提示(chat 不用这个,写在 messages 里) */
|
|
57
|
+
system?: string;
|
|
58
|
+
/** imageId,与 image 模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径 */
|
|
59
|
+
image?: string;
|
|
60
|
+
/** 对 image 裁剪,同 image.clip:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen" */
|
|
61
|
+
x?: number;
|
|
62
|
+
/** 裁剪区域左上角 Y */
|
|
63
|
+
y?: number;
|
|
64
|
+
/** 裁剪区域右下角 X */
|
|
65
|
+
ex?: number;
|
|
66
|
+
/** 裁剪区域右下角 Y */
|
|
67
|
+
ey?: number;
|
|
68
|
+
/** 多张图,元素同 image,不裁剪 */
|
|
69
|
+
images?: string[];
|
|
70
|
+
/** 仅 extract:期望的 JSON 结构说明,字符串或对象 */
|
|
71
|
+
schema?: string | object;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* chat 的消息项,图片参数与 AiOptions 相同
|
|
76
|
+
*/
|
|
77
|
+
interface AiMessage {
|
|
78
|
+
/** 角色 */
|
|
79
|
+
role: "system" | "user" | "assistant";
|
|
80
|
+
/** 文本内容 */
|
|
81
|
+
content: string;
|
|
82
|
+
/** imageId,同 AiOptions.image */
|
|
83
|
+
image?: string;
|
|
84
|
+
/** 裁剪区域,同 AiOptions */
|
|
85
|
+
x?: number;
|
|
86
|
+
y?: number;
|
|
87
|
+
ex?: number;
|
|
88
|
+
ey?: number;
|
|
89
|
+
/** 多张图,同 AiOptions.images */
|
|
90
|
+
images?: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
|
|
95
|
+
* 可登记多个:便宜的文本模型做默认,视觉模型单独一个,调用时用 options.provider 选
|
|
96
|
+
* @param config 新建至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
|
|
97
|
+
* @returns 保存后的完整配置;protocol 不合法或缺 baseUrl / model 时返回 null
|
|
98
|
+
* @example
|
|
99
|
+
* ai.setProvider({ name: "DeepSeek", protocol: "openai", baseUrl: "https://api.deepseek.com", apiKey: "sk-...", model: "deepseek-v4-flash" })
|
|
100
|
+
*/
|
|
101
|
+
function setProvider(config: Partial<AiProvider>): AiProvider | null;
|
|
102
|
+
/**
|
|
103
|
+
* 列出已登记的供应商,默认项排在最前
|
|
104
|
+
* @example ai.getProviders().forEach(p => logi(p.name))
|
|
105
|
+
*/
|
|
106
|
+
function getProviders(): AiProvider[];
|
|
107
|
+
/**
|
|
108
|
+
* 获取默认供应商
|
|
109
|
+
* @returns 一个都没登记时返回 null
|
|
110
|
+
* @example const p = ai.getDefaultProvider()
|
|
111
|
+
*/
|
|
112
|
+
function getDefaultProvider(): AiProvider | null;
|
|
113
|
+
/**
|
|
114
|
+
* 切换默认供应商
|
|
115
|
+
* @param id 供应商 id 或 name
|
|
116
|
+
* @returns id 或 name 存在返回 true
|
|
117
|
+
* @example ai.setDefaultProvider("cheap")
|
|
118
|
+
*/
|
|
119
|
+
function setDefaultProvider(id: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* 删除供应商;删掉的是默认项时默认转给剩下的第一个
|
|
122
|
+
* @param id 供应商 id 或 name
|
|
123
|
+
* @returns 存在并删除返回 true
|
|
124
|
+
* @example ai.removeProvider("cheap")
|
|
125
|
+
*/
|
|
126
|
+
function removeProvider(id: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* 单轮提问,可附带图片
|
|
129
|
+
* @param prompt 问题
|
|
130
|
+
* @param options 可选参数,图片参数与 image 模块一致:image 为 imageId,x/y/ex/ey 同 image.clip 裁剪
|
|
131
|
+
* @returns 回复文本;失败返回 null
|
|
132
|
+
* @example
|
|
133
|
+
* ai.ask("屏幕上有几个按钮?", { image: "screen" })
|
|
134
|
+
* ai.ask("这个区域的价格是多少?", { image: "screen", x: 0, y: 300, ex: 750, ey: 500 })
|
|
135
|
+
*/
|
|
136
|
+
function ask(prompt: string, options?: AiOptions): string | null;
|
|
137
|
+
/**
|
|
138
|
+
* 是非判断:让模型只回答 yes / no
|
|
139
|
+
* @param question 要判断的问题
|
|
140
|
+
* @param options 同 ask
|
|
141
|
+
* @returns 肯定为 true;否定或请求失败为 false(失败时 lastError() 有内容)
|
|
142
|
+
* @example if (ai.judge("是否出现了「领取成功」?", { image: "screen" })) { ... }
|
|
143
|
+
*/
|
|
144
|
+
function judge(question: string, options?: AiOptions): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 结构化提取:要求模型输出 JSON 并解析成对象或数组
|
|
147
|
+
* @param prompt 提取要求
|
|
148
|
+
* @param options 同 ask,另支持 schema
|
|
149
|
+
* @returns 解析后的对象或数组;没有合法 JSON 或请求失败返回 null
|
|
150
|
+
* @example
|
|
151
|
+
* const d = ai.extract("提取验证码", { image: "screen", x: 100, y: 800, ex: 600, ey: 900, schema: { code: "string" } })
|
|
152
|
+
* if (d) logi(d.code)
|
|
153
|
+
*/
|
|
154
|
+
function extract(prompt: string, options?: AiOptions): any | null;
|
|
155
|
+
/**
|
|
156
|
+
* 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 null,不要把空回复推进历史。
|
|
157
|
+
* @param messages 消息数组;直接写字符串等于 user 消息;图片写在该条消息上
|
|
158
|
+
* @param options provider / model / temperature / maxTokens / json / timeout(不用 system / image)
|
|
159
|
+
* @returns 回复文本;失败返回 null
|
|
160
|
+
* @example
|
|
161
|
+
* ai.chat([{ role: "system", content: "你是助手" }, { role: "user", content: "看下这是哪个页面", image: "screen" }])
|
|
162
|
+
*/
|
|
163
|
+
function chat(messages: (AiMessage | string)[], options?: AiOptions): string | null;
|
|
164
|
+
/**
|
|
165
|
+
* 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
|
|
166
|
+
* @param text 模型输出
|
|
167
|
+
* @returns 解析结果;失败返回 null
|
|
168
|
+
* @example ai.parseJson("```json\n{\"a\":1}\n```")
|
|
169
|
+
*/
|
|
170
|
+
function parseJson(text: string): any | null;
|
|
171
|
+
/**
|
|
172
|
+
* 最近一次调用失败的原因
|
|
173
|
+
* @returns 错误文案;上一次调用成功时返回 null
|
|
174
|
+
* @example if (ai.ask("你好") === null) loge(ai.lastError())
|
|
175
|
+
*/
|
|
176
|
+
function lastError(): string | null;
|
|
177
|
+
}
|
package/types/index.d.ts
CHANGED
package/types/lua/ai.lua
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
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.deepseek.com
|
|
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 reasoningEffort "none"|"low"|"medium"|"high"|"xhigh"|nil 思考级别,仅 openai 协议;不传不发,用服务商默认
|
|
16
|
+
---@field supportsVision boolean 是否支持图片输入,默认 true
|
|
17
|
+
---@field isDefault boolean 是否为默认供应商
|
|
18
|
+
|
|
19
|
+
---@class AiOptions
|
|
20
|
+
---@field provider string|nil 用哪个供应商:id 或 name;不传用默认
|
|
21
|
+
---@field model string|nil 临时换模型,覆盖供应商默认模型
|
|
22
|
+
---@field temperature number|nil 覆盖默认温度
|
|
23
|
+
---@field maxTokens integer|nil 覆盖默认最大输出 token
|
|
24
|
+
---@field timeout integer|nil 超时毫秒,默认 90000
|
|
25
|
+
---@field json boolean|nil 要求模型输出 JSON(extract 自动开启)
|
|
26
|
+
---@field system string|nil 系统提示(chat 不用这个,写在 messages 里)
|
|
27
|
+
---@field image string|nil imageId,与 image 模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径
|
|
28
|
+
---@field x integer|nil 对 image 裁剪,同 image.clip:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen"
|
|
29
|
+
---@field y integer|nil 裁剪区域左上角 Y
|
|
30
|
+
---@field ex integer|nil 裁剪区域右下角 X
|
|
31
|
+
---@field ey integer|nil 裁剪区域右下角 Y
|
|
32
|
+
---@field images string[]|nil 多张图,元素同 image,不裁剪
|
|
33
|
+
---@field schema string|table|nil 仅 extract:期望的 JSON 结构说明
|
|
34
|
+
|
|
35
|
+
---@class AiMessage 图片参数与 AiOptions 相同
|
|
36
|
+
---@field role "system"|"user"|"assistant"
|
|
37
|
+
---@field content string
|
|
38
|
+
---@field image string|nil
|
|
39
|
+
---@field x integer|nil
|
|
40
|
+
---@field y integer|nil
|
|
41
|
+
---@field ex integer|nil
|
|
42
|
+
---@field ey integer|nil
|
|
43
|
+
---@field images string[]|nil
|
|
44
|
+
|
|
45
|
+
--- 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
|
|
46
|
+
--- 至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
|
|
47
|
+
---@param config table
|
|
48
|
+
---@return AiProvider|nil 保存后的完整配置;参数不合法返回 nil
|
|
49
|
+
function _Ai.setProvider(config) return nil end
|
|
50
|
+
|
|
51
|
+
--- 列出已登记的供应商,默认项排在最前
|
|
52
|
+
---@return AiProvider[]
|
|
53
|
+
function _Ai.getProviders() return {} end
|
|
54
|
+
|
|
55
|
+
--- 获取默认供应商;一个都没登记时返回 nil
|
|
56
|
+
---@return AiProvider|nil
|
|
57
|
+
function _Ai.getDefaultProvider() return nil end
|
|
58
|
+
|
|
59
|
+
--- 切换默认供应商
|
|
60
|
+
---@param id string 供应商 id 或 name
|
|
61
|
+
---@return boolean id 或 name 存在返回 true
|
|
62
|
+
function _Ai.setDefaultProvider(id) return true end
|
|
63
|
+
|
|
64
|
+
--- 删除供应商;删掉的是默认项时默认转给剩下的第一个
|
|
65
|
+
---@param id string 供应商 id 或 name
|
|
66
|
+
---@return boolean 存在并删除返回 true
|
|
67
|
+
function _Ai.removeProvider(id) return true end
|
|
68
|
+
|
|
69
|
+
--- 单轮提问,可附带图片;图片参数与 image 模块一致(image + x/y/ex/ey,或 images)
|
|
70
|
+
---@param prompt string
|
|
71
|
+
---@param options AiOptions|nil
|
|
72
|
+
---@return string|nil 回复文本;失败返回 nil,原因看 lastError()
|
|
73
|
+
function _Ai.ask(prompt, options) return nil end
|
|
74
|
+
|
|
75
|
+
--- 是非判断:让模型只回答 yes / no
|
|
76
|
+
---@param question string
|
|
77
|
+
---@param options AiOptions|nil
|
|
78
|
+
---@return boolean 肯定为 true;否定或请求失败为 false(失败时 lastError() 有内容)
|
|
79
|
+
function _Ai.judge(question, options) return false end
|
|
80
|
+
|
|
81
|
+
--- 结构化提取:要求模型输出 JSON 并解析成表
|
|
82
|
+
---@param prompt string
|
|
83
|
+
---@param options AiOptions|nil 另支持 schema
|
|
84
|
+
---@return table|nil 解析后的表;没有合法 JSON 或请求失败返回 nil
|
|
85
|
+
function _Ai.extract(prompt, options) return nil end
|
|
86
|
+
|
|
87
|
+
--- 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 nil,不要把空回复推进历史。
|
|
88
|
+
---@param messages (AiMessage|string)[] 直接写字符串等于 user 消息;图片写在该条消息上
|
|
89
|
+
---@param options AiOptions|nil provider / model / temperature / maxTokens / json / timeout(不用 system / image)
|
|
90
|
+
---@return string|nil 回复文本;失败返回 nil
|
|
91
|
+
function _Ai.chat(messages, options) return nil end
|
|
92
|
+
|
|
93
|
+
--- 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
|
|
94
|
+
---@param text string
|
|
95
|
+
---@return table|nil
|
|
96
|
+
function _Ai.parseJson(text) return nil end
|
|
97
|
+
|
|
98
|
+
--- 最近一次调用失败的原因;上一次调用成功时返回 nil
|
|
99
|
+
---@return string|nil
|
|
100
|
+
function _Ai.lastError() return nil end
|
|
101
|
+
|
|
102
|
+
---@type Ai
|
|
103
|
+
ai = _Ai
|
|
@@ -0,0 +1,177 @@
|
|
|
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.deepseek.com */
|
|
20
|
+
baseUrl: 字符串;
|
|
21
|
+
/** API Key;openai 协议连本机模型时可为空 */
|
|
22
|
+
apiKey: 字符串;
|
|
23
|
+
/** 默认模型名 */
|
|
24
|
+
model: 字符串;
|
|
25
|
+
/** 额外请求头,某些网关需要 */
|
|
26
|
+
headers: 字典<字符串>;
|
|
27
|
+
/** 默认温度;不传则不发该字段,用模型自己的默认值 */
|
|
28
|
+
temperature?: 数字;
|
|
29
|
+
/** 默认最大输出 token;不传则不发该字段,用模型自己的默认值(Anthropic 因接口必填仍默认 2048) */
|
|
30
|
+
maxTokens?: 数字;
|
|
31
|
+
/**
|
|
32
|
+
* 思考级别,只对 openai 协议生效(请求字段 reasoning_effort)。
|
|
33
|
+
* 不传则不发,用服务商默认。
|
|
34
|
+
*/
|
|
35
|
+
reasoningEffort?: "none" | "low" | "medium" | "high" | "xhigh";
|
|
36
|
+
/** 是否支持图片输入,默认 true */
|
|
37
|
+
supportsVision: 布尔值;
|
|
38
|
+
/** 是否为默认供应商 */
|
|
39
|
+
isDefault: 布尔值;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 提问 / 判断 / 提取 / 对话 的可选参数
|
|
44
|
+
*/
|
|
45
|
+
interface 调用选项 {
|
|
46
|
+
/** 用哪个供应商:id 或 name;不传用默认 */
|
|
47
|
+
provider?: 字符串;
|
|
48
|
+
/** 临时换模型 */
|
|
49
|
+
model?: 字符串;
|
|
50
|
+
/** 覆盖默认温度 */
|
|
51
|
+
temperature?: 数字;
|
|
52
|
+
/** 覆盖默认最大输出 token */
|
|
53
|
+
maxTokens?: 数字;
|
|
54
|
+
/** 超时毫秒,默认 90000 */
|
|
55
|
+
timeout?: 数字;
|
|
56
|
+
/** 要求模型输出 JSON(提取 自动开启) */
|
|
57
|
+
json?: 布尔值;
|
|
58
|
+
/** 系统提示 */
|
|
59
|
+
system?: 字符串;
|
|
60
|
+
/** imageId,与图片模块所有函数的 imageId 参数一致:图片 ID / "screen" / 图片路径 */
|
|
61
|
+
image?: 字符串;
|
|
62
|
+
/** 对 image 裁剪,同 $图片.裁剪图片:左上角 X;全 0 不裁剪。只写区域不写 image 时按 "screen" */
|
|
63
|
+
x?: 数字;
|
|
64
|
+
/** 裁剪区域左上角 Y */
|
|
65
|
+
y?: 数字;
|
|
66
|
+
/** 裁剪区域右下角 X */
|
|
67
|
+
ex?: 数字;
|
|
68
|
+
/** 裁剪区域右下角 Y */
|
|
69
|
+
ey?: 数字;
|
|
70
|
+
/** 多张图,元素同 image,不裁剪 */
|
|
71
|
+
images?: 数组<字符串>;
|
|
72
|
+
/** 仅 提取:期望的 JSON 结构说明 */
|
|
73
|
+
schema?: 字符串 | object;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 对话 的消息项,图片参数与 调用选项 相同
|
|
78
|
+
*/
|
|
79
|
+
interface 对话消息 {
|
|
80
|
+
/** 角色 */
|
|
81
|
+
role: "system" | "user" | "assistant";
|
|
82
|
+
/** 文本内容 */
|
|
83
|
+
content: 字符串;
|
|
84
|
+
/** imageId,同 调用选项.image */
|
|
85
|
+
image?: 字符串;
|
|
86
|
+
/** 裁剪区域,同 调用选项 */
|
|
87
|
+
x?: 数字;
|
|
88
|
+
y?: 数字;
|
|
89
|
+
ex?: 数字;
|
|
90
|
+
ey?: 数字;
|
|
91
|
+
/** 多张图,同 调用选项.images */
|
|
92
|
+
images?: 数组<字符串>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
|
|
97
|
+
* @param 配置 新建至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新
|
|
98
|
+
* @returns 保存后的完整配置;参数不合法返回 null
|
|
99
|
+
* @example
|
|
100
|
+
* $AI.设置模型({ name: "DeepSeek", protocol: "openai", baseUrl: "https://api.deepseek.com", apiKey: "sk-...", model: "deepseek-v4-flash" })
|
|
101
|
+
*/
|
|
102
|
+
function 设置模型(配置: Partial<模型供应商>): 模型供应商 | null;
|
|
103
|
+
/**
|
|
104
|
+
* 列出已登记的供应商,默认项排在最前
|
|
105
|
+
* @example $AI.获取模型列表()
|
|
106
|
+
*/
|
|
107
|
+
function 获取模型列表(): 数组<模型供应商>;
|
|
108
|
+
/**
|
|
109
|
+
* 获取默认供应商
|
|
110
|
+
* @returns 一个都没登记时返回 null
|
|
111
|
+
* @example $AI.获取默认模型()
|
|
112
|
+
*/
|
|
113
|
+
function 获取默认模型(): 模型供应商 | null;
|
|
114
|
+
/**
|
|
115
|
+
* 切换默认供应商
|
|
116
|
+
* @param id 供应商 id 或 name
|
|
117
|
+
* @returns id 或 name 存在返回 true
|
|
118
|
+
* @example $AI.设置默认模型("cheap")
|
|
119
|
+
*/
|
|
120
|
+
function 设置默认模型(id: 字符串): 布尔值;
|
|
121
|
+
/**
|
|
122
|
+
* 删除供应商
|
|
123
|
+
* @param id 供应商 id 或 name
|
|
124
|
+
* @returns 存在并删除返回 true
|
|
125
|
+
* @example $AI.删除模型("cheap")
|
|
126
|
+
*/
|
|
127
|
+
function 删除模型(id: 字符串): 布尔值;
|
|
128
|
+
/**
|
|
129
|
+
* 单轮提问,可附带图片
|
|
130
|
+
* @param 问题 问题
|
|
131
|
+
* @param 选项 可选参数,图片参数与图片模块一致:image 为 imageId,x/y/ex/ey 同 $图片.裁剪图片
|
|
132
|
+
* @returns 回复文本;失败返回 null
|
|
133
|
+
* @example
|
|
134
|
+
* $AI.提问("屏幕上有几个按钮?", { image: "screen" })
|
|
135
|
+
* $AI.提问("这个区域的价格是多少?", { image: "screen", x: 0, y: 300, ex: 750, ey: 500 })
|
|
136
|
+
*/
|
|
137
|
+
function 提问(问题: 字符串, 选项?: 调用选项): 字符串 | null;
|
|
138
|
+
/**
|
|
139
|
+
* 是非判断:让模型只回答 yes / no
|
|
140
|
+
* @param 问题 要判断的问题
|
|
141
|
+
* @param 选项 同 提问
|
|
142
|
+
* @returns 肯定为 true;否定或请求失败为 false
|
|
143
|
+
* @example if ($AI.判断("是否出现了「领取成功」?", { image: "screen" })) { ... }
|
|
144
|
+
*/
|
|
145
|
+
function 判断(问题: 字符串, 选项?: 调用选项): 布尔值;
|
|
146
|
+
/**
|
|
147
|
+
* 结构化提取:要求模型输出 JSON 并解析成对象或数组
|
|
148
|
+
* @param 要求 提取要求
|
|
149
|
+
* @param 选项 同 提问,另支持 schema
|
|
150
|
+
* @returns 解析后的对象或数组;失败返回 null
|
|
151
|
+
* @example
|
|
152
|
+
* const d = $AI.提取("提取验证码", { image: "screen", x: 100, y: 800, ex: 600, ey: 900, schema: { code: "string" } })
|
|
153
|
+
*/
|
|
154
|
+
function 提取(要求: 字符串, 选项?: 调用选项): 任意类型 | null;
|
|
155
|
+
/**
|
|
156
|
+
* 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 null,不要把空回复推进历史。
|
|
157
|
+
* @param 消息列表 消息数组;直接写字符串等于 user 消息;图片写在该条消息上
|
|
158
|
+
* @param 选项 provider / model / temperature / maxTokens / json / timeout(不用 system / image)
|
|
159
|
+
* @returns 回复文本;失败返回 null
|
|
160
|
+
* @example
|
|
161
|
+
* $AI.对话([{ role: "system", content: "你是助手" }, { role: "user", content: "看下这是哪个页面", image: "screen" }])
|
|
162
|
+
*/
|
|
163
|
+
function 对话(消息列表: 数组<对话消息 | 字符串>, 选项?: 调用选项): 字符串 | null;
|
|
164
|
+
/**
|
|
165
|
+
* 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
|
|
166
|
+
* @param 文本 模型输出
|
|
167
|
+
* @returns 解析结果;失败返回 null
|
|
168
|
+
* @example $AI.解析JSON("```json\n{\"a\":1}\n```")
|
|
169
|
+
*/
|
|
170
|
+
function 解析JSON(文本: 字符串): 任意类型 | null;
|
|
171
|
+
/**
|
|
172
|
+
* 最近一次调用失败的原因
|
|
173
|
+
* @returns 错误文案;上一次调用成功时返回 null
|
|
174
|
+
* @example if ($AI.提问("你好") === null) $打印错误日志($AI.获取错误())
|
|
175
|
+
*/
|
|
176
|
+
function 获取错误(): 字符串 | null;
|
|
177
|
+
}
|