@tanzerfe/page-use 0.0.2
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/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/index-DtJ3mvL2.d.mts +583 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/src-C8EWDZVz.mjs +2693 -0
- package/dist/vue.d.mts +53 -0
- package/dist/vue.mjs +86 -0
- package/package.json +72 -0
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
import { AgentStatus, PageAgentConfig } from "page-agent";
|
|
2
|
+
import { LitElement, PropertyValues } from "lit";
|
|
3
|
+
//#region src/core/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Page Use 对外类型:菜单结构、能力 API、进度事件、任务结果。
|
|
6
|
+
* 对接方(其它智能体)只需依赖本文件与 capability/ 下的导出。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 宿主导航菜单节点:用于生成站点地图写入系统提示,并据此生成「打开 XX」快捷指令。
|
|
10
|
+
* path 为路由路径(不含 hash 前缀 `#`,前导 `/` 可有可无);有子节点的分组节点可不填 path。
|
|
11
|
+
*/
|
|
12
|
+
interface PageUseMenuNode {
|
|
13
|
+
label: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
/** 保留路由但不在导航中展示:模型无法点击到达,不列入站点地图 */
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
children?: PageUseMenuNode[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 任务来源标识,用于面板展示、历史记录与日志排查。
|
|
21
|
+
* 约定值:'launcher' 调试面板;其它智能体自行命名(如 'assistant')。
|
|
22
|
+
*/
|
|
23
|
+
type PageUseTaskSource = string;
|
|
24
|
+
/** 调用失败原因(任务未真正开始执行时) */
|
|
25
|
+
type PageUseErrorCode =
|
|
26
|
+
/** 未调用 createPageUse,或未配置 LLM 端点 baseURL */
|
|
27
|
+
'NOT_CONFIGURED' |
|
|
28
|
+
/** 已配置但宿主已销毁(destroy 之后、例如登出) */
|
|
29
|
+
'NOT_READY' |
|
|
30
|
+
/** 已有任务执行中;同一时刻只允许一个任务操作页面 */
|
|
31
|
+
'BUSY' |
|
|
32
|
+
/** 指令为空 */
|
|
33
|
+
'EMPTY_TASK' |
|
|
34
|
+
/** agent 构造或钩子抛出的外部错误 */
|
|
35
|
+
'AGENT_ERROR';
|
|
36
|
+
/**
|
|
37
|
+
* 任务最终状态:
|
|
38
|
+
* - completed:模型调用 done 且声明成功
|
|
39
|
+
* - failed:模型调用 done 但声明未达成
|
|
40
|
+
* - stopped:被终止(调用方 abort、stop() 或面板「终止」)
|
|
41
|
+
* - error:执行出错(模型异常、超出最大步数等)或未能开始(见 errorCode)
|
|
42
|
+
*/
|
|
43
|
+
type PageUseTaskStatus = 'completed' | 'failed' | 'stopped' | 'error';
|
|
44
|
+
interface PageUseStepLog {
|
|
45
|
+
index: number;
|
|
46
|
+
/** 工具名,用于图标与颜色区分;另有 'error' / 'retry' 两个伪工具名表示执行出错与重试 */
|
|
47
|
+
tool: string;
|
|
48
|
+
/** 模型对上一步的评估 */
|
|
49
|
+
evaluation: string;
|
|
50
|
+
/** 模型对下一步的目标描述 */
|
|
51
|
+
goal: string;
|
|
52
|
+
/** 工具名 + 关键入参摘要 */
|
|
53
|
+
action: string;
|
|
54
|
+
output: string;
|
|
55
|
+
/** 该步是否失败(工具返回以 ❌ 开头或出现"失败"字样) */
|
|
56
|
+
failed: boolean;
|
|
57
|
+
}
|
|
58
|
+
interface PageUseTaskResult {
|
|
59
|
+
/** 本次任务 ID;未能开始时为空串 */
|
|
60
|
+
taskId: string;
|
|
61
|
+
task: string;
|
|
62
|
+
source: PageUseTaskSource;
|
|
63
|
+
status: PageUseTaskStatus;
|
|
64
|
+
/** 等价于 status === 'completed' */
|
|
65
|
+
success: boolean;
|
|
66
|
+
/** 模型给出的结论,或失败原因 */
|
|
67
|
+
summary: string;
|
|
68
|
+
/** 仅在任务未能开始或外部错误时有值 */
|
|
69
|
+
errorCode?: PageUseErrorCode;
|
|
70
|
+
steps: PageUseStepLog[];
|
|
71
|
+
tokens: number;
|
|
72
|
+
durationMs: number;
|
|
73
|
+
}
|
|
74
|
+
/** 进度事件:run() 的 onProgress 只收到本任务事件;subscribe() 收到全部任务事件 */
|
|
75
|
+
type PageUseProgressEvent = {
|
|
76
|
+
type: 'started';
|
|
77
|
+
taskId: string;
|
|
78
|
+
task: string;
|
|
79
|
+
source: PageUseTaskSource;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'activity';
|
|
82
|
+
taskId: string;
|
|
83
|
+
text: string;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'step';
|
|
86
|
+
taskId: string;
|
|
87
|
+
step: PageUseStepLog;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'question';
|
|
90
|
+
taskId: string;
|
|
91
|
+
question: string;
|
|
92
|
+
} | {
|
|
93
|
+
type: 'finished';
|
|
94
|
+
taskId: string;
|
|
95
|
+
result: PageUseTaskResult;
|
|
96
|
+
};
|
|
97
|
+
interface PageUseRunOptions {
|
|
98
|
+
/** 任务来源,默认 'unknown' */
|
|
99
|
+
source?: PageUseTaskSource;
|
|
100
|
+
/** 中断信号:abort 后任务以 stopped 结束 */
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
onProgress?: (event: PageUseProgressEvent) => void;
|
|
103
|
+
/**
|
|
104
|
+
* 模型向用户提问(ask_user 工具)时的回答方式。
|
|
105
|
+
* 不传时:调试面板已挂载则由面板作答;否则自动回复「无法补充信息」让模型自行决策或结束。
|
|
106
|
+
*/
|
|
107
|
+
onAskUser?: (question: string) => Promise<string>;
|
|
108
|
+
}
|
|
109
|
+
/** 能力状态快照(非响应式) */
|
|
110
|
+
interface PageUseSnapshot {
|
|
111
|
+
/** 已配置端点且宿主未销毁,可立即接收任务 */
|
|
112
|
+
ready: boolean;
|
|
113
|
+
running: boolean;
|
|
114
|
+
taskId: string;
|
|
115
|
+
task: string;
|
|
116
|
+
source: PageUseTaskSource;
|
|
117
|
+
activity: string;
|
|
118
|
+
steps: number;
|
|
119
|
+
}
|
|
120
|
+
/** 快捷指令:label 为按钮文字,task 为下达的完整指令 */
|
|
121
|
+
interface PageUsePreset {
|
|
122
|
+
label: string;
|
|
123
|
+
task: string;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/capability/api.d.ts
|
|
127
|
+
interface PageUseCapability {
|
|
128
|
+
/** 协议版本;不兼容变更时递增,调用方可据此判断 */
|
|
129
|
+
readonly version: 1;
|
|
130
|
+
/** 已调用 createPageUse 且配置了端点、未销毁,可立即接收任务 */
|
|
131
|
+
isReady(): boolean;
|
|
132
|
+
/** 下达指令并等待结束;不会 reject,失败信息见结果的 status / errorCode */
|
|
133
|
+
run(task: string, options?: PageUseRunOptions): Promise<PageUseTaskResult>;
|
|
134
|
+
/** 终止当前任务(无论由谁下达);当前任务将以 stopped 结束 */
|
|
135
|
+
stop(): Promise<void>;
|
|
136
|
+
getSnapshot(): PageUseSnapshot;
|
|
137
|
+
/** 订阅全部任务的进度事件;返回取消订阅函数 */
|
|
138
|
+
subscribe(listener: (event: PageUseProgressEvent) => void): () => void;
|
|
139
|
+
}
|
|
140
|
+
declare const pageUseCapability: PageUseCapability;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/core/options.d.ts
|
|
143
|
+
/** 默认模型,仅为示例取值;接入其它端点时应通过 llm.model 显式指定支持 function calling 的模型 */
|
|
144
|
+
declare const DEFAULT_MODEL = "deepseek-chat";
|
|
145
|
+
/** 单次任务最大步数;每步一次 LLM 调用,防止死循环消耗 token */
|
|
146
|
+
declare const DEFAULT_MAX_STEPS = 20;
|
|
147
|
+
/** 默认会话头:OpenCode Go 要求每个会话带稳定的 x-opencode-session 用于路由与提示缓存 */
|
|
148
|
+
declare const DEFAULT_SESSION_HEADER = "x-opencode-session";
|
|
149
|
+
/** localStorage / sessionStorage 键前缀,可通过 storageKeyPrefix 覆盖 */
|
|
150
|
+
declare const DEFAULT_STORAGE_KEY_PREFIX = "tz-page-use";
|
|
151
|
+
interface PageUseLLMOptions {
|
|
152
|
+
/**
|
|
153
|
+
* OpenAI 兼容端点(到版本前缀为止,如 https://api.deepseek.com/v1)。
|
|
154
|
+
* 可传相对路径(如本地代理 /__page-use-llm),会按当前 origin 补为绝对地址。
|
|
155
|
+
*/
|
|
156
|
+
baseURL: string;
|
|
157
|
+
/**
|
|
158
|
+
* 前端直连时的 Key。生产环境建议留空,由网关/代理注入,避免 Key 出现在前端产物中。
|
|
159
|
+
*/
|
|
160
|
+
apiKey?: string;
|
|
161
|
+
model?: string;
|
|
162
|
+
maxSteps?: number;
|
|
163
|
+
/** 部分模型拒绝对象形式 tool_choice("Invalid tool_choice type")时打开 */
|
|
164
|
+
disableNamedToolChoice?: boolean;
|
|
165
|
+
/** 额外合并进请求体的字段,例:DeepSeek 关闭思考模式 { thinking: { type: 'disabled' } } */
|
|
166
|
+
extraBody?: Record<string, unknown>;
|
|
167
|
+
/**
|
|
168
|
+
* 会话 ID 请求头名,每个任务生成一个新 ID;false 表示不发送
|
|
169
|
+
* (直连不需要该头的端点时关闭,避免 CORS 预检拒绝自定义头)。默认 x-opencode-session。
|
|
170
|
+
*/
|
|
171
|
+
sessionHeader?: string | false;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 路由模式,决定站点地图中路径的写法与默认的当前路径读取方式:
|
|
175
|
+
* - hash:页面 URL 形如 `/#/a/b`
|
|
176
|
+
* - history:页面 URL 形如 `/a/b`
|
|
177
|
+
*/
|
|
178
|
+
type PageUseRouterMode = 'hash' | 'history';
|
|
179
|
+
interface PageUseOptions {
|
|
180
|
+
llm: PageUseLLMOptions;
|
|
181
|
+
/** 系统名称,写入系统提示「你正在「xxx」内替用户操作页面」 */
|
|
182
|
+
appName: string;
|
|
183
|
+
/** 每次任务开始(及每一步)时读取最新的可见菜单;返回空时站点地图为空 */
|
|
184
|
+
getMenus?: () => PageUseMenuNode[] | undefined;
|
|
185
|
+
/** 默认 'hash' */
|
|
186
|
+
routerMode?: PageUseRouterMode;
|
|
187
|
+
/** 读取当前路由路径(不含 `#`);默认按 routerMode 从 location 读取 */
|
|
188
|
+
getCurrentPath?: () => string;
|
|
189
|
+
/** 由路径解析路由名,用于匹配 routeHints;不传时 routeHints 仅按路径匹配 */
|
|
190
|
+
resolveRouteName?: (path: string) => string | undefined;
|
|
191
|
+
/** 按页操作提示:key 为路由名或路径(不含前导 `/`),value 为提示文本 */
|
|
192
|
+
routeHints?: Record<string, string>;
|
|
193
|
+
/** 页面布局描述,替换系统提示中的「页面结构」段落;不传时使用通用描述 */
|
|
194
|
+
layoutHint?: string;
|
|
195
|
+
/** 任务开始前的宿主预处理,例如展开折叠的侧栏,使菜单文字对模型可见 */
|
|
196
|
+
beforeTask?: () => void | Promise<void>;
|
|
197
|
+
/** 调试面板设置中 beforeTask 开关的显示名,默认「任务开始前执行宿主预处理」 */
|
|
198
|
+
beforeTaskLabel?: string;
|
|
199
|
+
/** 存储键前缀,默认 'tz-page-use';同源多应用共存时用于隔离 */
|
|
200
|
+
storageKeyPrefix?: string;
|
|
201
|
+
/** 透传给 page-agent 的配置,覆盖包内默认值(stepDelay、language 等) */
|
|
202
|
+
pageAgentOptions?: Partial<PageAgentConfig>;
|
|
203
|
+
/** 是否安装 window.__TZ_PAGE_USE__ 全局桥接,默认 true */
|
|
204
|
+
exposeGlobal?: boolean;
|
|
205
|
+
}
|
|
206
|
+
interface NormalizedLLMOptions {
|
|
207
|
+
/** 绝对地址;page-agent 内部 `new URL(baseURL)` 解析,相对路径会抛错 */
|
|
208
|
+
baseURL: string;
|
|
209
|
+
apiKey: string;
|
|
210
|
+
model: string;
|
|
211
|
+
maxSteps: number;
|
|
212
|
+
disableNamedToolChoice: boolean;
|
|
213
|
+
extraBody: Record<string, unknown>;
|
|
214
|
+
/** 空串表示不发送会话头 */
|
|
215
|
+
sessionHeader: string;
|
|
216
|
+
}
|
|
217
|
+
interface NormalizedPageUseOptions {
|
|
218
|
+
llm: NormalizedLLMOptions;
|
|
219
|
+
appName: string;
|
|
220
|
+
getMenus: () => PageUseMenuNode[] | undefined;
|
|
221
|
+
routerMode: PageUseRouterMode;
|
|
222
|
+
getCurrentPath: () => string;
|
|
223
|
+
resolveRouteName?: (path: string) => string | undefined;
|
|
224
|
+
routeHints: Record<string, string>;
|
|
225
|
+
layoutHint?: string;
|
|
226
|
+
beforeTask?: () => void | Promise<void>;
|
|
227
|
+
beforeTaskLabel: string;
|
|
228
|
+
storageKeyPrefix: string;
|
|
229
|
+
pageAgentOptions: Partial<PageAgentConfig>;
|
|
230
|
+
exposeGlobal: boolean;
|
|
231
|
+
}
|
|
232
|
+
declare function normalizeOptions(options: PageUseOptions): NormalizedPageUseOptions;
|
|
233
|
+
/**
|
|
234
|
+
* 调试面板是否显示。优先级:URL 参数(并记入本会话)> 会话记录 > fallback。
|
|
235
|
+
* fallback 由宿主决定(例如「开发环境显示,生产环境隐藏」)。
|
|
236
|
+
*/
|
|
237
|
+
declare function readLauncherSwitch(fallback: boolean, storageKeyPrefix?: string): boolean;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/create.d.ts
|
|
240
|
+
interface PageUseHandle {
|
|
241
|
+
capability: PageUseCapability;
|
|
242
|
+
/** 清除配置、释放 agent(清掉高亮与蒙层)、移除全局桥接;宿主登出或卸载时调用 */
|
|
243
|
+
destroy(): void;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* 初始化 Page Use。全局只有一份配置:重复调用会以新配置替换旧配置,
|
|
247
|
+
* 旧 handle 的 destroy 随之失效(不会误清新配置)。
|
|
248
|
+
*/
|
|
249
|
+
declare function createPageUse(options: PageUseOptions): PageUseHandle;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/ui/launcher.d.ts
|
|
252
|
+
declare const PAGE_USE_LAUNCHER_TAG = "tz-page-use-launcher";
|
|
253
|
+
interface PageUseLauncherConfig {
|
|
254
|
+
/** 入口与面板标题,默认 'Page Use' */
|
|
255
|
+
title?: string;
|
|
256
|
+
/** 追加到「常用」分组的快捷指令(排在菜单生成的「打开 XX」与通用示例之后) */
|
|
257
|
+
presets?: PageUsePreset[];
|
|
258
|
+
/** 「复杂场景」分组的快捷指令;为空时不显示该分组 */
|
|
259
|
+
scenarios?: PageUsePreset[];
|
|
260
|
+
/** 由菜单生成「打开 XX」快捷指令的数量上限,默认 6;0 表示不生成 */
|
|
261
|
+
menuPresetLimit?: number;
|
|
262
|
+
/** 任务来源 → 展示名;未登记的来源直接显示原值 */
|
|
263
|
+
sourceLabels?: Record<string, string>;
|
|
264
|
+
}
|
|
265
|
+
declare class PageUseLauncherElement extends LitElement {
|
|
266
|
+
static styles: import("lit").CSSResult;
|
|
267
|
+
private _config;
|
|
268
|
+
/** 面板配置;赋值后立即重新渲染 */
|
|
269
|
+
get config(): PageUseLauncherConfig;
|
|
270
|
+
set config(value: PageUseLauncherConfig | undefined);
|
|
271
|
+
private open;
|
|
272
|
+
private showSettings;
|
|
273
|
+
private task;
|
|
274
|
+
private answer;
|
|
275
|
+
private tray;
|
|
276
|
+
/**
|
|
277
|
+
* 日志区跟随滚动:默认贴底跟随新内容;用户上翻后停止跟随,
|
|
278
|
+
* 回到底部附近(阈值内)或点击「最新」后恢复。
|
|
279
|
+
*/
|
|
280
|
+
private stickToBottom;
|
|
281
|
+
/** 上次渲染时日志内容的摘要;仅内容变化时才贴底,避免每秒的耗时刷新把用户拉回底部 */
|
|
282
|
+
private logSignature;
|
|
283
|
+
/** 下次渲染强制滚到底部(点击「最新」、任务开始) */
|
|
284
|
+
private forceScroll;
|
|
285
|
+
/**
|
|
286
|
+
* 入口尺寸缓存:入口在面板展开时被隐藏,offsetWidth 为 0,
|
|
287
|
+
* 因此在可见时测量并保留最近一次结果;初值为「Page Use」文案下的近似尺寸。
|
|
288
|
+
*/
|
|
289
|
+
private fabSize;
|
|
290
|
+
private viewport;
|
|
291
|
+
/**
|
|
292
|
+
* 面板相对入口的对齐方式:入口在视口右半边则面板右边缘对齐入口右边缘,否则左对齐;
|
|
293
|
+
* 下半边则底边对齐(面板向上展开),否则顶边对齐。
|
|
294
|
+
* 仅在展开时计算一次并在展开期间保持,避免拖动面板越过中线时锚点切换导致跳动。
|
|
295
|
+
*/
|
|
296
|
+
private panelAnchor;
|
|
297
|
+
private wasRunning;
|
|
298
|
+
private cleanups;
|
|
299
|
+
private get fabEl();
|
|
300
|
+
private get panelEl();
|
|
301
|
+
private get logEl();
|
|
302
|
+
private get textareaEl();
|
|
303
|
+
private fabDrag;
|
|
304
|
+
/** 拖动面板时反推入口位置:面板锚定角即入口所在角,收起后入口停在面板原位置 */
|
|
305
|
+
private panelDrag;
|
|
306
|
+
connectedCallback(): void;
|
|
307
|
+
disconnectedCallback(): void;
|
|
308
|
+
protected firstUpdated(): void;
|
|
309
|
+
protected updated(_changed: PropertyValues): void;
|
|
310
|
+
private onStateChange;
|
|
311
|
+
private onResize;
|
|
312
|
+
private measureFab;
|
|
313
|
+
/** 入口在视口中的矩形;未拖动过时按默认 right/bottom 推算 */
|
|
314
|
+
private fabRect;
|
|
315
|
+
private resolvePanelAnchor;
|
|
316
|
+
/** 未拖动过时用默认角落定位,拖动后切换为 left/top */
|
|
317
|
+
private fabStyle;
|
|
318
|
+
/** 面板位置完全由入口位置推导,展开时与入口重合于同一角 */
|
|
319
|
+
private panelStyle;
|
|
320
|
+
private collapse;
|
|
321
|
+
private submit;
|
|
322
|
+
private applyPreset;
|
|
323
|
+
private lastTaskText;
|
|
324
|
+
/** 回车执行、Shift+回车换行;输入法组词中的回车不触发执行 */
|
|
325
|
+
private onTaskKeydown;
|
|
326
|
+
private onTaskInput;
|
|
327
|
+
/** 按内容在 2~6 行之间调整输入框高度,超出后内部滚动 */
|
|
328
|
+
private autosizeTextarea;
|
|
329
|
+
private submitAnswer;
|
|
330
|
+
private onLogScroll;
|
|
331
|
+
/**
|
|
332
|
+
* 滚轮上翻立即停止跟随:平滑滚动的首个 scroll 事件位移可能小于阈值,
|
|
333
|
+
* 若此时仍判定为贴底,内容刷新会把视图拉回底部,表现为上翻时抖动。
|
|
334
|
+
*/
|
|
335
|
+
private onLogWheel;
|
|
336
|
+
private scrollLogToBottom;
|
|
337
|
+
private toggleTray;
|
|
338
|
+
private onClearLog;
|
|
339
|
+
private sourceLabel;
|
|
340
|
+
private presets;
|
|
341
|
+
private endpointLabel;
|
|
342
|
+
private renderChips;
|
|
343
|
+
private renderPresetGroups;
|
|
344
|
+
private renderCheckbox;
|
|
345
|
+
private renderSettings;
|
|
346
|
+
private renderLog;
|
|
347
|
+
private renderTray;
|
|
348
|
+
private renderComposer;
|
|
349
|
+
render(): import("lit").TemplateResult<1>;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/ui/mount.d.ts
|
|
353
|
+
/** 注册 <tz-page-use-glow> 与 <tz-page-use-launcher>;重复调用安全(已注册则跳过) */
|
|
354
|
+
declare function definePageUseElements(): void;
|
|
355
|
+
interface MountPageUseUIOptions {
|
|
356
|
+
/** 运行期定制光晕,默认 true(仍受设置 customMaskEffect 控制) */
|
|
357
|
+
glow?: boolean;
|
|
358
|
+
/** 调试面板:false 不挂载(默认);true 或配置对象挂载 */
|
|
359
|
+
launcher?: boolean | PageUseLauncherConfig;
|
|
360
|
+
/** 挂载容器,默认 document.body */
|
|
361
|
+
container?: HTMLElement;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 挂载 UI,返回卸载函数。
|
|
365
|
+
* 外层容器带 data-page-agent-ignore="true"(值必须为字符串 "true"):
|
|
366
|
+
* page-controller 按 dataset 值精确判断后跳过整棵子树,面板与光晕不会被模型当作页面元素。
|
|
367
|
+
*/
|
|
368
|
+
declare function mountPageUseUI(options?: MountPageUseUIOptions): () => void;
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/capability/tool.d.ts
|
|
371
|
+
/** 工具名;对接方在 system 提示中引用时保持一致 */
|
|
372
|
+
declare const PAGE_USE_TOOL_NAME = "operate_current_page";
|
|
373
|
+
declare const PAGE_USE_TOOL: {
|
|
374
|
+
readonly type: "function";
|
|
375
|
+
readonly function: {
|
|
376
|
+
readonly name: "operate_current_page";
|
|
377
|
+
readonly description: string;
|
|
378
|
+
readonly parameters: {
|
|
379
|
+
readonly type: "object";
|
|
380
|
+
readonly properties: {
|
|
381
|
+
readonly instruction: {
|
|
382
|
+
readonly type: "string";
|
|
383
|
+
readonly description: "可独立执行的完整中文指令,写明目标页面与具体操作,例如「打开订单管理下的订单列表,筛选状态为待发货并查询,告诉我第一条订单的收货地址」。";
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
readonly required: readonly ["instruction"];
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
/** 把任务结果整理为给模型阅读的纯文本 */
|
|
391
|
+
declare function formatPageUseResultForModel(result: PageUseTaskResult): string;
|
|
392
|
+
/**
|
|
393
|
+
* 执行一次 operate_current_page 工具调用。
|
|
394
|
+
* 返回 { result, content }:content 直接作为 tool 消息回给模型,result 供对接方自行展示。
|
|
395
|
+
*/
|
|
396
|
+
declare function runPageUseTool(args: unknown, options?: PageUseRunOptions): Promise<{
|
|
397
|
+
result: PageUseTaskResult;
|
|
398
|
+
content: string;
|
|
399
|
+
}>;
|
|
400
|
+
/** 指令块类型名:模型在 shell / JSON 块中输出 {"type":"pageAction","instruction":"..."} */
|
|
401
|
+
declare const PAGE_USE_COMMAND_TYPE = "pageAction";
|
|
402
|
+
interface PageUseCommand {
|
|
403
|
+
type: typeof PAGE_USE_COMMAND_TYPE;
|
|
404
|
+
instruction: string;
|
|
405
|
+
}
|
|
406
|
+
declare function isPageUseCommand(value: unknown): value is PageUseCommand;
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/capability/bridge.d.ts
|
|
409
|
+
/** window 上的挂载名 */
|
|
410
|
+
declare const PAGE_USE_GLOBAL_KEY = "__TZ_PAGE_USE__";
|
|
411
|
+
interface PageUseGlobal extends PageUseCapability {
|
|
412
|
+
tool: typeof PAGE_USE_TOOL;
|
|
413
|
+
runTool: typeof runPageUseTool;
|
|
414
|
+
}
|
|
415
|
+
declare global {
|
|
416
|
+
interface Window {
|
|
417
|
+
[PAGE_USE_GLOBAL_KEY]?: PageUseGlobal;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/core/store.d.ts
|
|
422
|
+
/**
|
|
423
|
+
* 极简可订阅状态容器(框架无关)。
|
|
424
|
+
* 状态按不可变对象整体替换,订阅方通过引用比较即可判断变化;
|
|
425
|
+
* Vue / React / Lit 等 UI 层各自把 subscribe 接到自身的响应式机制上。
|
|
426
|
+
*/
|
|
427
|
+
interface ReadonlyStore<T> {
|
|
428
|
+
get(): T;
|
|
429
|
+
/** 状态变化后同步通知;返回取消订阅函数 */
|
|
430
|
+
subscribe(listener: (state: T) => void): () => void;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/core/service.d.ts
|
|
434
|
+
interface PageUseQuestion {
|
|
435
|
+
question: string;
|
|
436
|
+
resolve: (answer: string) => void;
|
|
437
|
+
}
|
|
438
|
+
/** 供 UI 读取的执行状态(不可变对象,每次变化整体替换) */
|
|
439
|
+
interface PageUseState {
|
|
440
|
+
/** page-agent 状态:idle / running / completed / error / stopped */
|
|
441
|
+
status: AgentStatus;
|
|
442
|
+
activityText: string;
|
|
443
|
+
currentTask: string;
|
|
444
|
+
currentTaskId: string;
|
|
445
|
+
currentSource: PageUseTaskSource;
|
|
446
|
+
steps: PageUseStepLog[];
|
|
447
|
+
lastResult: PageUseTaskResult | null;
|
|
448
|
+
errorMessage: string;
|
|
449
|
+
/** 等待调试面板作答的问题;仅当调用方未提供 onAskUser 且面板已挂载时出现 */
|
|
450
|
+
pendingQuestion: PageUseQuestion | null;
|
|
451
|
+
totalTokens: number;
|
|
452
|
+
startedAt: number;
|
|
453
|
+
finishedAt: number;
|
|
454
|
+
/** 运行期每秒推进一次,驱动耗时显示刷新 */
|
|
455
|
+
nowTick: number;
|
|
456
|
+
/** 当前 agent 实例是否带蒙层(构造期确定);供光晕层判断,蒙层节点为异步创建,不能靠查 DOM */
|
|
457
|
+
maskEnabled: boolean;
|
|
458
|
+
/** 已配置端点且宿主未销毁 */
|
|
459
|
+
ready: boolean;
|
|
460
|
+
}
|
|
461
|
+
/** 只读状态容器:UI 层订阅后自行接入响应式 */
|
|
462
|
+
declare const pageUseStore: ReadonlyStore<PageUseState>;
|
|
463
|
+
declare function isRunning(state?: PageUseState): boolean;
|
|
464
|
+
/** 任务耗时(秒):运行中随 nowTick 每秒刷新,结束后固定 */
|
|
465
|
+
declare function getElapsedSeconds(state?: PageUseState): number;
|
|
466
|
+
/** 已调用 createPageUse 且配置了端点 */
|
|
467
|
+
declare function isPageUseConfigured(): boolean;
|
|
468
|
+
/** 当前生效的规范化配置;未配置时为 null */
|
|
469
|
+
declare function getPageUseConfig(): NormalizedPageUseOptions | null;
|
|
470
|
+
/**
|
|
471
|
+
* 清屏:清空面板展示的本次执行记录(指令、步骤、结果、计数),不影响历史指令与 agent 实例。
|
|
472
|
+
* 执行中不允许清空,否则后续步骤回写会与已清空的状态错位。
|
|
473
|
+
*/
|
|
474
|
+
declare function clearPageUseLog(): void;
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/core/settings.d.ts
|
|
477
|
+
interface PageUsePoint {
|
|
478
|
+
x: number;
|
|
479
|
+
y: number;
|
|
480
|
+
}
|
|
481
|
+
interface PageUseSettings {
|
|
482
|
+
/** 是否显示 page-agent 自带的底部面板;默认隐藏,由调试面板承担交互 */
|
|
483
|
+
showBuiltinPanel: boolean;
|
|
484
|
+
/** 是否显示运行中的元素编号高亮框(browser-use 风格数字标签) */
|
|
485
|
+
showHighlights: boolean;
|
|
486
|
+
/** 步骤列表是否展示模型思考与工具输出细节 */
|
|
487
|
+
showStepDetails: boolean;
|
|
488
|
+
/** 任务开始前是否执行宿主提供的 beforeTask(如展开折叠侧栏) */
|
|
489
|
+
enableBeforeTask: boolean;
|
|
490
|
+
/** 运行期是否用蒙层阻断用户误点 */
|
|
491
|
+
enableMask: boolean;
|
|
492
|
+
/** 蒙层使用定制光晕与光标配色(false = page-agent 默认 ai-motion 效果) */
|
|
493
|
+
customMaskEffect: boolean;
|
|
494
|
+
/** 浮动入口位置(null = 默认右下角);面板展开时以入口为锚点定位,不单独存位置 */
|
|
495
|
+
fabPos: PageUsePoint | null;
|
|
496
|
+
}
|
|
497
|
+
declare const DEFAULT_PAGE_USE_SETTINGS: Readonly<PageUseSettings>;
|
|
498
|
+
declare const pageUseSettings: {
|
|
499
|
+
store: ReadonlyStore<PageUseSettings>;
|
|
500
|
+
get(): PageUseSettings;
|
|
501
|
+
update(patch: Partial<PageUseSettings>): void;
|
|
502
|
+
/** 把浮动入口(及随之定位的面板)恢复到默认角落位置 */
|
|
503
|
+
resetPositions(): void;
|
|
504
|
+
};
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/core/history.d.ts
|
|
507
|
+
interface PageUseHistoryEntry {
|
|
508
|
+
id: string;
|
|
509
|
+
task: string;
|
|
510
|
+
/** 任务来源('launcher' 等);旧记录无此字段 */
|
|
511
|
+
source?: string;
|
|
512
|
+
/** null:被终止或无结论 */
|
|
513
|
+
success: boolean | null;
|
|
514
|
+
/** 结束时间戳 */
|
|
515
|
+
at: number;
|
|
516
|
+
/** 执行步数 */
|
|
517
|
+
steps: number;
|
|
518
|
+
/** 模型 done 时给出的结论 */
|
|
519
|
+
summary: string;
|
|
520
|
+
}
|
|
521
|
+
declare const pageUseHistory: {
|
|
522
|
+
store: ReadonlyStore<{
|
|
523
|
+
entries: PageUseHistoryEntry[];
|
|
524
|
+
}>;
|
|
525
|
+
entries(): PageUseHistoryEntry[];
|
|
526
|
+
add(entry: Omit<PageUseHistoryEntry, "id">): void;
|
|
527
|
+
remove(id: string): void;
|
|
528
|
+
clear(): void;
|
|
529
|
+
};
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/ui/presets.d.ts
|
|
532
|
+
/** 通用示例:不依赖具体站点,覆盖详情、标签、返回等典型操作 */
|
|
533
|
+
declare const PAGE_USE_STATIC_PRESETS: readonly PageUsePreset[];
|
|
534
|
+
/** 取前 N 个可见叶子菜单,生成「打开 XX」快捷指令 */
|
|
535
|
+
declare function buildMenuPresets(menus: PageUseMenuNode[] | undefined, limit?: number): PageUsePreset[];
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/ui/glow.d.ts
|
|
538
|
+
declare const PAGE_USE_GLOW_TAG = "tz-page-use-glow";
|
|
539
|
+
declare class PageUseGlowElement extends LitElement {
|
|
540
|
+
static styles: import("lit").CSSResult;
|
|
541
|
+
private blocked;
|
|
542
|
+
/** 每次误触自增,作为提示条 key 重建节点以重播抖动动画 */
|
|
543
|
+
private blockCount;
|
|
544
|
+
private blockedTimer;
|
|
545
|
+
private active;
|
|
546
|
+
private unsubscribers;
|
|
547
|
+
connectedCallback(): void;
|
|
548
|
+
disconnectedCallback(): void;
|
|
549
|
+
private syncActive;
|
|
550
|
+
/**
|
|
551
|
+
* 捕获阶段监听:SimulatorMask 在自身节点上 stopPropagation,
|
|
552
|
+
* 冒泡阶段收不到,必须在 window 捕获阶段判断点击目标是否落在蒙层内。
|
|
553
|
+
*/
|
|
554
|
+
private onPointerDownCapture;
|
|
555
|
+
private setListening;
|
|
556
|
+
private resetBlocked;
|
|
557
|
+
render(): import("lit").TemplateResult<1>;
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/core/maskTheme.d.ts
|
|
561
|
+
/**
|
|
562
|
+
* 运行期蒙层与模拟光标的定制主题(覆盖 page-agent SimulatorMask 的默认视觉)。
|
|
563
|
+
*
|
|
564
|
+
* page-agent 的 CSS Module 类名带哈希(如 `_cursor_1dgwb_2`),随版本变化,
|
|
565
|
+
* 因此这里只依赖稳定的结构:
|
|
566
|
+
* - 蒙层根节点 id:`page-agent-runtime_simulator-mask`
|
|
567
|
+
* - 子节点顺序:ai-motion 光晕层在前(初始化失败时不存在),光标节点恒为最后一个子节点
|
|
568
|
+
* - 光标子节点顺序:1 点击波纹 / 2 箭头填充 / 3 箭头描边
|
|
569
|
+
* - 点击态类名包含 `clicking` 子串
|
|
570
|
+
* 升级 page-agent 后若光标样式失效,先核对 SimulatorMask 的 #createCursor 结构。
|
|
571
|
+
*/
|
|
572
|
+
/** 蒙层根节点 id(@page-agent/page-controller 内部常量) */
|
|
573
|
+
declare const SIMULATOR_MASK_ID = "page-agent-runtime_simulator-mask";
|
|
574
|
+
/** 主题色:主色 #0879ff 同系的蓝 → 青 → 靛渐变 */
|
|
575
|
+
declare const PAGE_USE_MASK_COLORS: {
|
|
576
|
+
readonly primary: "#0879ff";
|
|
577
|
+
readonly cyan: "#36cfc9";
|
|
578
|
+
readonly indigo: "#597ef7";
|
|
579
|
+
/** 误触拦截时的警示色 */
|
|
580
|
+
readonly warning: "#fa8c16";
|
|
581
|
+
};
|
|
582
|
+
//#endregion
|
|
583
|
+
export { PageUsePreset as $, runPageUseTool as A, DEFAULT_MODEL as B, PageUseGlobal as C, PageUseCommand as D, PAGE_USE_TOOL_NAME as E, PageUseLauncherConfig as F, PageUseOptions as G, DEFAULT_STORAGE_KEY_PREFIX as H, PageUseLauncherElement as I, readLauncherSwitch as J, PageUseRouterMode as K, PageUseHandle as L, definePageUseElements as M, mountPageUseUI as N, formatPageUseResultForModel as O, PAGE_USE_LAUNCHER_TAG as P, PageUseMenuNode as Q, createPageUse as R, PAGE_USE_GLOBAL_KEY as S, PAGE_USE_TOOL as T, NormalizedPageUseOptions as U, DEFAULT_SESSION_HEADER as V, PageUseLLMOptions as W, pageUseCapability as X, PageUseCapability as Y, PageUseErrorCode as Z, getPageUseConfig as _, PAGE_USE_STATIC_PRESETS as a, PageUseTaskSource as at, pageUseStore as b, pageUseHistory as c, PageUseSettings as d, PageUseProgressEvent as et, pageUseSettings as f, getElapsedSeconds as g, clearPageUseLog as h, PageUseGlowElement as i, PageUseTaskResult as it, MountPageUseUIOptions as j, isPageUseCommand as k, DEFAULT_PAGE_USE_SETTINGS as l, PageUseState as m, SIMULATOR_MASK_ID as n, PageUseSnapshot as nt, buildMenuPresets as o, PageUseTaskStatus as ot, PageUseQuestion as p, normalizeOptions as q, PAGE_USE_GLOW_TAG as r, PageUseStepLog as rt, PageUseHistoryEntry as s, PAGE_USE_MASK_COLORS as t, PageUseRunOptions as tt, PageUsePoint as u, isPageUseConfigured as v, PAGE_USE_COMMAND_TYPE as w, ReadonlyStore as x, isRunning as y, DEFAULT_MAX_STEPS as z };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as PageUsePreset, A as runPageUseTool, B as DEFAULT_MODEL, C as PageUseGlobal, D as PageUseCommand, E as PAGE_USE_TOOL_NAME, F as PageUseLauncherConfig, G as PageUseOptions, H as DEFAULT_STORAGE_KEY_PREFIX, I as PageUseLauncherElement, J as readLauncherSwitch, K as PageUseRouterMode, L as PageUseHandle, M as definePageUseElements, N as mountPageUseUI, O as formatPageUseResultForModel, P as PAGE_USE_LAUNCHER_TAG, Q as PageUseMenuNode, R as createPageUse, S as PAGE_USE_GLOBAL_KEY, T as PAGE_USE_TOOL, U as NormalizedPageUseOptions, V as DEFAULT_SESSION_HEADER, W as PageUseLLMOptions, X as pageUseCapability, Y as PageUseCapability, Z as PageUseErrorCode, _ as getPageUseConfig, a as PAGE_USE_STATIC_PRESETS, at as PageUseTaskSource, b as pageUseStore, c as pageUseHistory, d as PageUseSettings, et as PageUseProgressEvent, f as pageUseSettings, g as getElapsedSeconds, h as clearPageUseLog, i as PageUseGlowElement, it as PageUseTaskResult, j as MountPageUseUIOptions, k as isPageUseCommand, l as DEFAULT_PAGE_USE_SETTINGS, m as PageUseState, n as SIMULATOR_MASK_ID, nt as PageUseSnapshot, o as buildMenuPresets, ot as PageUseTaskStatus, p as PageUseQuestion, q as normalizeOptions, r as PAGE_USE_GLOW_TAG, rt as PageUseStepLog, s as PageUseHistoryEntry, t as PAGE_USE_MASK_COLORS, tt as PageUseRunOptions, u as PageUsePoint, v as isPageUseConfigured, w as PAGE_USE_COMMAND_TYPE, x as ReadonlyStore, y as isRunning, z as DEFAULT_MAX_STEPS } from "./index-DtJ3mvL2.mjs";
|
|
2
|
+
export { DEFAULT_MAX_STEPS, DEFAULT_MODEL, DEFAULT_PAGE_USE_SETTINGS, DEFAULT_SESSION_HEADER, DEFAULT_STORAGE_KEY_PREFIX, type MountPageUseUIOptions, type NormalizedPageUseOptions, PAGE_USE_COMMAND_TYPE, PAGE_USE_GLOBAL_KEY, PAGE_USE_GLOW_TAG, PAGE_USE_LAUNCHER_TAG, PAGE_USE_MASK_COLORS, PAGE_USE_STATIC_PRESETS, PAGE_USE_TOOL, PAGE_USE_TOOL_NAME, type PageUseCapability, type PageUseCommand, type PageUseErrorCode, type PageUseGlobal, PageUseGlowElement, type PageUseHandle, type PageUseHistoryEntry, type PageUseLLMOptions, type PageUseLauncherConfig, PageUseLauncherElement, type PageUseMenuNode, type PageUseOptions, type PageUsePoint, type PageUsePreset, type PageUseProgressEvent, type PageUseQuestion, type PageUseRouterMode, type PageUseRunOptions, type PageUseSettings, type PageUseSnapshot, type PageUseState, type PageUseStepLog, type PageUseTaskResult, type PageUseTaskSource, type PageUseTaskStatus, type ReadonlyStore, SIMULATOR_MASK_ID, buildMenuPresets, clearPageUseLog, createPageUse, definePageUseElements, formatPageUseResultForModel, getElapsedSeconds, getPageUseConfig, isPageUseCommand, isPageUseConfigured, isRunning, mountPageUseUI, normalizeOptions, pageUseCapability, pageUseHistory, pageUseSettings, pageUseStore, readLauncherSwitch, runPageUseTool };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as DEFAULT_MODEL, C as pageUseStore, D as SIMULATOR_MASK_ID, E as PAGE_USE_MASK_COLORS, M as DEFAULT_STORAGE_KEY_PREFIX, N as normalizeOptions, O as pageUseHistory, P as readLauncherSwitch, S as isRunning, T as pageUseSettings, _ as pageUseCapability, a as PAGE_USE_STATIC_PRESETS, b as getPageUseConfig, c as PageUseGlowElement, d as PAGE_USE_COMMAND_TYPE, f as PAGE_USE_TOOL, g as runPageUseTool, h as isPageUseCommand, i as PageUseLauncherElement, j as DEFAULT_SESSION_HEADER, k as DEFAULT_MAX_STEPS, l as createPageUse, m as formatPageUseResultForModel, n as mountPageUseUI, o as buildMenuPresets, p as PAGE_USE_TOOL_NAME, r as PAGE_USE_LAUNCHER_TAG, s as PAGE_USE_GLOW_TAG, t as definePageUseElements, u as PAGE_USE_GLOBAL_KEY, v as clearPageUseLog, w as DEFAULT_PAGE_USE_SETTINGS, x as isPageUseConfigured, y as getElapsedSeconds } from "./src-C8EWDZVz.mjs";
|
|
2
|
+
|
|
3
|
+
export { DEFAULT_MAX_STEPS, DEFAULT_MODEL, DEFAULT_PAGE_USE_SETTINGS, DEFAULT_SESSION_HEADER, DEFAULT_STORAGE_KEY_PREFIX, PAGE_USE_COMMAND_TYPE, PAGE_USE_GLOBAL_KEY, PAGE_USE_GLOW_TAG, PAGE_USE_LAUNCHER_TAG, PAGE_USE_MASK_COLORS, PAGE_USE_STATIC_PRESETS, PAGE_USE_TOOL, PAGE_USE_TOOL_NAME, PageUseGlowElement, PageUseLauncherElement, SIMULATOR_MASK_ID, buildMenuPresets, clearPageUseLog, createPageUse, definePageUseElements, formatPageUseResultForModel, getElapsedSeconds, getPageUseConfig, isPageUseCommand, isPageUseConfigured, isRunning, mountPageUseUI, normalizeOptions, pageUseCapability, pageUseHistory, pageUseSettings, pageUseStore, readLauncherSwitch, runPageUseTool };
|