wi-chat 0.4.0 → 0.5.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/dist/core/index.cjs +1 -1
- package/dist/core/index.js +129 -123
- package/dist/core/useChat.d.ts +11 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +102 -74
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +3 -3
- package/dist/mobile-ui/index.cjs +1 -1
- package/dist/mobile-ui/index.d.ts +1 -1
- package/dist/mobile-ui/index.js +26 -25
- package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +1 -1
- package/dist/page-context/extArgs.d.ts +46 -0
- package/dist/page-context/index.cjs +2 -0
- package/dist/page-context/index.d.ts +18 -0
- package/dist/page-context/index.js +48 -0
- package/dist/page-context/state.d.ts +10 -0
- package/dist/page-context/types.d.ts +218 -0
- package/dist/parser/answerCom/actionExecute/actionProtocol.d.ts +38 -0
- package/dist/parser/answerCom/actionExecute/clarification.d.ts +67 -0
- package/dist/parser/answerCom/actionExecute/parseActionExecute.d.ts +28 -0
- package/dist/parser/answerCom/actionExecute/types.d.ts +153 -0
- package/dist/parser/index.cjs +2 -2
- package/dist/parser/index.d.ts +9 -0
- package/dist/parser/index.js +537 -251
- package/dist/parser/registry.d.ts +8 -1
- package/dist/parser/title.d.ts +27 -0
- package/dist/renderers/clarification/ClarificationCard.vue.d.ts +19 -0
- package/dist/renderers/index.cjs +1 -1
- package/dist/renderers/index.d.ts +1 -0
- package/dist/renderers/index.js +641 -354
- package/dist/renderers/style.css +1 -1
- package/dist/right-panel/RightPanel.vue.d.ts +43 -0
- package/dist/right-panel/RightPanelIcon.vue.d.ts +38 -0
- package/dist/right-panel/RightPanelTabs.vue.d.ts +39 -0
- package/dist/right-panel/icons.d.ts +48 -0
- package/dist/right-panel/index.cjs +2 -0
- package/dist/right-panel/index.d.ts +43 -0
- package/dist/right-panel/index.js +1004 -0
- package/dist/right-panel/panels/index.d.ts +7 -0
- package/dist/right-panel/panels/newtab/NewTabPanel.vue.d.ts +27 -0
- package/dist/right-panel/panels/newtab/defaults.d.ts +6 -0
- package/dist/right-panel/panels/newtab/index.d.ts +4 -0
- package/dist/right-panel/panels/web/WebPanel.vue.d.ts +28 -0
- package/dist/right-panel/panels/web/index.d.ts +4 -0
- package/dist/right-panel/panels/web/useWebview.d.ts +59 -0
- package/dist/right-panel/registry.d.ts +24 -0
- package/dist/right-panel/runtime.d.ts +45 -0
- package/dist/right-panel/scope.d.ts +34 -0
- package/dist/right-panel/shared/BrowserToolbar.vue.d.ts +23 -0
- package/dist/right-panel/shared/RightPanelToolList.vue.d.ts +48 -0
- package/dist/right-panel/style.css +1 -0
- package/dist/right-panel/types.d.ts +363 -0
- package/dist/right-panel/useRightPanel.d.ts +39 -0
- package/dist/right-panel/useRightPanelTabs.d.ts +14 -0
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +182 -162
- package/dist/tools/markdown/index.d.ts +1 -1
- package/dist/tools/markdown/renderMarkdown.d.ts +25 -0
- package/dist/web-ui/attach/AttachmentList.vue.d.ts +1 -1
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +3 -3
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +2 -2
- package/dist/web-ui/index.cjs +1 -1
- package/dist/web-ui/index.d.ts +1 -1
- package/dist/web-ui/index.js +301 -295
- package/dist/web-ui/inputbox/Inputbox.vue.d.ts +4 -7
- package/dist/web-ui/style.css +1 -1
- package/package.json +13 -6
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 页面上下文协议类型(schemaVersion 2.0)
|
|
3
|
+
*
|
|
4
|
+
* 纯类型定义,不依赖任何运行时 / 业务模块:宿主页面按本协议把自己的
|
|
5
|
+
* 导航上下文、可读状态与可执行 Action 声明给大模型,随提问经
|
|
6
|
+
* `ext_args.pageContext` 下发(外层再序列化一次,见 `./extArgs`)。
|
|
7
|
+
*
|
|
8
|
+
* 与 `docs/agent-workflow-host-protocol.md` 第 2 章一一对应,
|
|
9
|
+
* 修改字段前先同步协议文档。
|
|
10
|
+
*/
|
|
11
|
+
/** JSON Schema 字段的公共描述信息。 */
|
|
12
|
+
export interface AgentSchemaBase {
|
|
13
|
+
/** 字段用途说明,供大模型理解参数语义。 */
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
/** 字符串参数的单个候选项。 */
|
|
17
|
+
export interface AgentStringSchemaOption extends AgentSchemaBase {
|
|
18
|
+
/** 模型最终必须输出的字符串值。 */
|
|
19
|
+
const: string;
|
|
20
|
+
/** 该字符串值对应的中文名称或展示标题。 */
|
|
21
|
+
title: string;
|
|
22
|
+
}
|
|
23
|
+
/** 字符串参数 Schema。 */
|
|
24
|
+
export interface AgentStringSchema extends AgentSchemaBase {
|
|
25
|
+
/** JSON Schema 字符串类型。 */
|
|
26
|
+
type: 'string';
|
|
27
|
+
/** 参数允许使用的字符串枚举值。 */
|
|
28
|
+
enum?: string[];
|
|
29
|
+
/** 带中文语义说明的字符串候选值。 */
|
|
30
|
+
oneOf?: AgentStringSchemaOption[];
|
|
31
|
+
/** 参数默认值;模型未输出该参数时使用此值。 */
|
|
32
|
+
default?: string;
|
|
33
|
+
}
|
|
34
|
+
/** 数值参数 Schema。 */
|
|
35
|
+
export interface AgentNumberSchema extends AgentSchemaBase {
|
|
36
|
+
/** JSON Schema 数值类型;integer 表示仅允许整数。 */
|
|
37
|
+
type: 'number' | 'integer';
|
|
38
|
+
/** 参数允许使用的数值枚举值。 */
|
|
39
|
+
enum?: number[];
|
|
40
|
+
/** 参数默认值;模型未输出该参数时使用此值。 */
|
|
41
|
+
default?: number;
|
|
42
|
+
}
|
|
43
|
+
/** 布尔参数 Schema。 */
|
|
44
|
+
export interface AgentBooleanSchema extends AgentSchemaBase {
|
|
45
|
+
/** JSON Schema 布尔类型。 */
|
|
46
|
+
type: 'boolean';
|
|
47
|
+
/** 参数默认值;模型未输出该参数时使用此值。 */
|
|
48
|
+
default?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** Action 参数支持的 JSON Schema 联合类型。 */
|
|
51
|
+
export type AgentParameterSchema = AgentObjectSchema | AgentArraySchema | AgentStringSchema | AgentNumberSchema | AgentBooleanSchema;
|
|
52
|
+
/** 对象参数 properties 中的字段映射。 */
|
|
53
|
+
export interface AgentSchemaProperties {
|
|
54
|
+
/** 参数名称及其对应的 JSON Schema。 */
|
|
55
|
+
[propertyName: string]: AgentParameterSchema;
|
|
56
|
+
}
|
|
57
|
+
/** 对象参数 Schema。 */
|
|
58
|
+
export interface AgentObjectSchema extends AgentSchemaBase {
|
|
59
|
+
/** JSON Schema 对象类型。 */
|
|
60
|
+
type: 'object';
|
|
61
|
+
/** 必须提供的参数名称列表。 */
|
|
62
|
+
required?: string[];
|
|
63
|
+
/** 是否允许 properties 之外的字段。 */
|
|
64
|
+
additionalProperties?: boolean;
|
|
65
|
+
/** 对象内所有可用参数及其 Schema。 */
|
|
66
|
+
properties: AgentSchemaProperties;
|
|
67
|
+
/** 参数默认值;模型未输出该参数时使用此值。 */
|
|
68
|
+
default?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/** 数组参数 Schema。 */
|
|
71
|
+
export interface AgentArraySchema extends AgentSchemaBase {
|
|
72
|
+
/** JSON Schema 数组类型。 */
|
|
73
|
+
type: 'array';
|
|
74
|
+
/** 数组中每个元素必须符合的 Schema。 */
|
|
75
|
+
items: AgentParameterSchema;
|
|
76
|
+
/** 参数默认值;模型未输出该参数时使用此值。 */
|
|
77
|
+
default?: unknown[];
|
|
78
|
+
}
|
|
79
|
+
/** Action 的执行顺序约束。 */
|
|
80
|
+
export interface AgentActionExecution {
|
|
81
|
+
/** 当前 Action 执行前必须完成的 Action 名称列表。 */
|
|
82
|
+
requires: string[];
|
|
83
|
+
}
|
|
84
|
+
/** 页面向大模型声明的单个可执行 Action。 */
|
|
85
|
+
export interface AgentAction {
|
|
86
|
+
/** Action 唯一名称,也是模型输出指令时使用的名称。 */
|
|
87
|
+
name: string;
|
|
88
|
+
/** Action 的展示标题。 */
|
|
89
|
+
title: string;
|
|
90
|
+
/** Action 的能力和执行效果说明。 */
|
|
91
|
+
description: string;
|
|
92
|
+
/** Action arguments 必须遵守的对象参数 Schema。 */
|
|
93
|
+
parameters: AgentObjectSchema;
|
|
94
|
+
/** Action 的前置依赖及执行约束。 */
|
|
95
|
+
execution: AgentActionExecution;
|
|
96
|
+
}
|
|
97
|
+
/** URL 导航参数支持的标量 Schema。 */
|
|
98
|
+
export type AgentNavigationScalarSchema = AgentStringSchema | AgentNumberSchema | AgentBooleanSchema;
|
|
99
|
+
/** URL 导航参数支持的数组 Schema。 */
|
|
100
|
+
export interface AgentNavigationArraySchema extends AgentSchemaBase {
|
|
101
|
+
/** JSON Schema 数组类型。 */
|
|
102
|
+
type: 'array';
|
|
103
|
+
/** URL 数组中每个元素必须是可序列化的标量。 */
|
|
104
|
+
items: AgentNavigationScalarSchema;
|
|
105
|
+
}
|
|
106
|
+
/** 单个 URL 导航参数支持的 Schema。 */
|
|
107
|
+
export type AgentNavigationValueSchema = AgentNavigationScalarSchema | AgentNavigationArraySchema;
|
|
108
|
+
/** URL 参数对象中的字段映射。 */
|
|
109
|
+
export interface AgentNavigationSchemaProperties {
|
|
110
|
+
/** 参数名称及其对应的 JSON Schema。 */
|
|
111
|
+
[propertyName: string]: AgentNavigationValueSchema;
|
|
112
|
+
}
|
|
113
|
+
/** 单个参数位置的对象 Schema。 */
|
|
114
|
+
export interface AgentNavigationObjectSchema extends AgentSchemaBase {
|
|
115
|
+
/** JSON Schema 对象类型。 */
|
|
116
|
+
type: 'object';
|
|
117
|
+
/** 必须提供的参数名称列表。 */
|
|
118
|
+
required?: string[];
|
|
119
|
+
/** 导航参数不允许使用未声明字段。 */
|
|
120
|
+
additionalProperties: false;
|
|
121
|
+
/** 当前参数位置允许使用的字段。 */
|
|
122
|
+
properties: AgentNavigationSchemaProperties;
|
|
123
|
+
}
|
|
124
|
+
/** 菜单支持的三类 URL 参数定义。 */
|
|
125
|
+
export interface AgentNavigationParameterSchemas {
|
|
126
|
+
/** Vue Router 动态路径参数。 */
|
|
127
|
+
path?: AgentNavigationObjectSchema;
|
|
128
|
+
/** Hash 路由内的 query 参数。 */
|
|
129
|
+
query?: AgentNavigationObjectSchema;
|
|
130
|
+
/** Hash 外层 window.location.search 参数。 */
|
|
131
|
+
search?: AgentNavigationObjectSchema;
|
|
132
|
+
}
|
|
133
|
+
/** 路由配置中供 Agent 使用的导航元数据。 */
|
|
134
|
+
export interface AgentRouteNavigationMeta {
|
|
135
|
+
/** 菜单的业务用途说明。 */
|
|
136
|
+
description: string;
|
|
137
|
+
/** 菜单支持的 URL 参数定义;无参数时省略。 */
|
|
138
|
+
parameters?: AgentNavigationParameterSchemas;
|
|
139
|
+
}
|
|
140
|
+
/** 导航指令或当前路由中的参数值。 */
|
|
141
|
+
export interface AgentNavigationParameterValues {
|
|
142
|
+
/** Vue Router 动态路径参数值。 */
|
|
143
|
+
path?: Record<string, unknown>;
|
|
144
|
+
/** Hash 路由内的 query 参数值。 */
|
|
145
|
+
query?: Record<string, unknown>;
|
|
146
|
+
/** Hash 外层 window.location.search 参数值。 */
|
|
147
|
+
search?: Record<string, unknown>;
|
|
148
|
+
}
|
|
149
|
+
/** 当前用户可访问的菜单信息。 */
|
|
150
|
+
export interface AgentMenu {
|
|
151
|
+
/** 菜单对应的路由唯一标识。 */
|
|
152
|
+
id: string;
|
|
153
|
+
/** 菜单展示名称。 */
|
|
154
|
+
name: string;
|
|
155
|
+
/** 菜单对应的路由路径。 */
|
|
156
|
+
route: string;
|
|
157
|
+
/** 菜单的业务用途说明。 */
|
|
158
|
+
description: string;
|
|
159
|
+
/** 菜单支持的 URL 参数定义;无参数时省略。 */
|
|
160
|
+
parameters?: AgentNavigationParameterSchemas;
|
|
161
|
+
}
|
|
162
|
+
/** 当前页面的导航上下文。 */
|
|
163
|
+
export interface AgentNavigationContext {
|
|
164
|
+
/** 当前菜单 ID,必须引用 menus 中的一个菜单。 */
|
|
165
|
+
currentMenuId: string;
|
|
166
|
+
/** 当前菜单已声明参数的实际值;无值时省略。 */
|
|
167
|
+
currentParameters?: AgentNavigationParameterValues;
|
|
168
|
+
/** 当前用户可以访问的菜单列表。 */
|
|
169
|
+
menus: AgentMenu[];
|
|
170
|
+
}
|
|
171
|
+
/** 表格列的数据类型,仅用于帮助大模型理解列语义。 */
|
|
172
|
+
export type AgentTableColumnType = 'string' | 'number' | 'boolean' | 'date' | 'datetime';
|
|
173
|
+
/** 页面状态中单个表格列的描述。 */
|
|
174
|
+
export interface AgentTableColumn {
|
|
175
|
+
/** data 对象中与该列对应的字段名。 */
|
|
176
|
+
key: string;
|
|
177
|
+
/** 表格列的展示标题。 */
|
|
178
|
+
title: string;
|
|
179
|
+
/** 表格列的数据类型,不用于运行时校验。 */
|
|
180
|
+
type: AgentTableColumnType;
|
|
181
|
+
/** 表格列的业务含义说明。 */
|
|
182
|
+
description?: string;
|
|
183
|
+
}
|
|
184
|
+
/** 调用方向页面上下文提供的表格状态。 */
|
|
185
|
+
export interface AgentTableStateInput {
|
|
186
|
+
/** 当前上下文中的表格唯一标识。 */
|
|
187
|
+
id: string;
|
|
188
|
+
/** 页面状态类型。 */
|
|
189
|
+
type: 'table';
|
|
190
|
+
/** 表格名称。 */
|
|
191
|
+
name: string;
|
|
192
|
+
/** 表格的业务用途说明。 */
|
|
193
|
+
description?: string;
|
|
194
|
+
/** 表格列及其语义描述。 */
|
|
195
|
+
columns: AgentTableColumn[];
|
|
196
|
+
/** 表格对象行数据。 */
|
|
197
|
+
data: Array<Record<string, unknown>>;
|
|
198
|
+
}
|
|
199
|
+
/** 发送给大模型的表格状态。 */
|
|
200
|
+
export interface AgentTableState extends AgentTableStateInput {
|
|
201
|
+
/** 截断前的表格总行数。 */
|
|
202
|
+
total: number;
|
|
203
|
+
/** data 是否因上下文行数限制而被截断。 */
|
|
204
|
+
truncated: boolean;
|
|
205
|
+
}
|
|
206
|
+
/** 页面提供给大模型读取的状态。 */
|
|
207
|
+
export type AgentPageState = AgentTableState;
|
|
208
|
+
/** 发送给大模型的完整页面上下文协议。 */
|
|
209
|
+
export interface AgentPageContext {
|
|
210
|
+
/** 页面上下文协议版本。 */
|
|
211
|
+
schemaVersion: '2.0';
|
|
212
|
+
/** 当前页面及可访问菜单的导航上下文。 */
|
|
213
|
+
navigation: AgentNavigationContext;
|
|
214
|
+
/** 当前页面显式提供给大模型读取的状态。 */
|
|
215
|
+
state: AgentPageState[];
|
|
216
|
+
/** 当前页面允许大模型规划的 Action 列表。 */
|
|
217
|
+
actions: AgentAction[];
|
|
218
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ActionExecuteCommand, ActionResult, ActionDefinition } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 创建失败结果
|
|
5
|
+
* @param message 失败原因(会作为 wait_reply 的 message 回传后端)
|
|
6
|
+
* @returns 统一失败结果(data 固定为 null)
|
|
7
|
+
*/
|
|
8
|
+
export declare const createFailureResult: (message: string) => ActionResult;
|
|
9
|
+
/**
|
|
10
|
+
* 解析 action_execute 指令
|
|
11
|
+
* @param value front_reply 的 `values`(对象或 JSON 字符串)
|
|
12
|
+
* @returns 归一化后的指令(只保留 type / executor / action.name / action.arguments)
|
|
13
|
+
*/
|
|
14
|
+
export declare const parseActionExecuteCommand: (value: unknown) => ActionExecuteCommand;
|
|
15
|
+
/**
|
|
16
|
+
* 把宿主返回的任意值规整成统一 ActionResult
|
|
17
|
+
* @param value 宿主返回值
|
|
18
|
+
* @param invalidMessage 非 ActionResult 形态时的失败文案
|
|
19
|
+
* @returns 统一执行结果
|
|
20
|
+
*/
|
|
21
|
+
export declare const normalizeActionResult: (value: unknown, invalidMessage?: string) => ActionResult;
|
|
22
|
+
/**
|
|
23
|
+
* 统一包裹:把业务报文帧规整为 ActionResult(发往 wait_reply 的所有帧都应经过它)。
|
|
24
|
+
* 规则:
|
|
25
|
+
* - 已是 ActionResult 形状(success 为布尔)→ 幂等原样返回;
|
|
26
|
+
* - json_ok === true → { success: true, message: '操作成功', data: 报文帧 };
|
|
27
|
+
* - json_ok === false → { success: false, message: error 文案, data: 报文帧 };
|
|
28
|
+
* - 其余/非法输入 → failure。
|
|
29
|
+
* @param frame 业务报文帧
|
|
30
|
+
* @returns 统一执行结果
|
|
31
|
+
*/
|
|
32
|
+
export declare const wrapActionFrame: (frame: unknown) => ActionResult;
|
|
33
|
+
/**
|
|
34
|
+
* 归一化 Action 定义(外部可能传入任意对象,这里只保留 name / arguments)
|
|
35
|
+
* @param action 原始 Action
|
|
36
|
+
* @returns 仅含 name / arguments 的 Action
|
|
37
|
+
*/
|
|
38
|
+
export declare const normalizeActionDefinition: (action: ActionDefinition) => ActionDefinition;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AiAnswerReport } from '../../answer';
|
|
2
|
+
import { ClarificationAnswer, ClarificationItem, WaitReplyPayload } from './types';
|
|
3
|
+
|
|
4
|
+
/** 解析后的澄清参数(不含运行时状态字段) */
|
|
5
|
+
export interface ParsedClarificationArguments {
|
|
6
|
+
/** 卡片标题 */
|
|
7
|
+
title: string;
|
|
8
|
+
/** 卡片说明 */
|
|
9
|
+
description: string;
|
|
10
|
+
/** 待确认项列表 */
|
|
11
|
+
items: ClarificationItem[];
|
|
12
|
+
}
|
|
13
|
+
/** 一条等待用户回答的确认请求 */
|
|
14
|
+
interface PendingClarification {
|
|
15
|
+
/** 报告 id(与 viewModel.requestId 一致) */
|
|
16
|
+
reportId: string;
|
|
17
|
+
/** 后端 front_reply 的 reply_id(回包必须原样带回) */
|
|
18
|
+
replyId?: string | number;
|
|
19
|
+
/** 回答 reports 数组(registry 预取的同一引用,用于就地更新卡片状态) */
|
|
20
|
+
reports: AiAnswerReport<any>[];
|
|
21
|
+
/** wait_reply 回传通道(useChat 注入 sendWsMessage) */
|
|
22
|
+
reply?: (payload: WaitReplyPayload) => boolean | void;
|
|
23
|
+
/** 非致命错误回调 */
|
|
24
|
+
onError?: (error: unknown) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 解析 collect_clarifications 的 arguments
|
|
28
|
+
* @param value action.arguments
|
|
29
|
+
* @returns 卡片标题、说明与确认项列表
|
|
30
|
+
*/
|
|
31
|
+
export declare const parseClarificationArguments: (value: Record<string, unknown>) => ParsedClarificationArguments;
|
|
32
|
+
/**
|
|
33
|
+
* 生成本次确认请求的 report id:优先用后端 reply_id,缺省时本地生成。
|
|
34
|
+
* @param replyId 后端 front_reply 的 reply_id
|
|
35
|
+
* @returns 字符串形式的唯一 id
|
|
36
|
+
*/
|
|
37
|
+
export declare const nextClarificationRequestId: (replyId?: string | number) => string;
|
|
38
|
+
/**
|
|
39
|
+
* 登记一条在途确认请求(解析器在生成卡片时调用)
|
|
40
|
+
* @param pending 待结算请求
|
|
41
|
+
*/
|
|
42
|
+
export declare const registerClarification: (pending: PendingClarification) => void;
|
|
43
|
+
/**
|
|
44
|
+
* 判断某条确认请求是否仍在等待用户回答(卡片据此决定能否交互)
|
|
45
|
+
* @param requestId 确认请求 id
|
|
46
|
+
* @returns 在途时 true
|
|
47
|
+
*/
|
|
48
|
+
export declare const hasPendingClarification: (requestId: string) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 用户提交补充信息:结算在途请求、回传 wait_reply 并更新卡片状态。
|
|
51
|
+
* @param requestId 确认请求 id
|
|
52
|
+
* @param answers 用户回答列表
|
|
53
|
+
* @returns 是否结算成功(false = 该请求已结算或已失效)
|
|
54
|
+
*/
|
|
55
|
+
export declare const submitClarification: (requestId: string, answers: ClarificationAnswer[]) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 用户取消补充信息:结算在途请求、回传失败帧并更新卡片状态。
|
|
58
|
+
* @param requestId 确认请求 id
|
|
59
|
+
* @returns 是否结算成功(false = 该请求已结算或已失效)
|
|
60
|
+
*/
|
|
61
|
+
export declare const cancelClarification: (requestId: string) => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 清空全部在途请求(切换分组 / 停止回答时调用):
|
|
64
|
+
* 先把仍在等待回答的卡片标为已失效,再清理登记表,避免卡片停留在「等待回答」却无法提交。
|
|
65
|
+
*/
|
|
66
|
+
export declare const clearPendingClarifications: () => void;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AiAnswerReport } from '../../answer';
|
|
2
|
+
import { AnswerParser, AnswerParseOptions } from '../../registry';
|
|
3
|
+
import { StreamChunk } from '../../sse';
|
|
4
|
+
import { ClarificationViewModel } from './types';
|
|
5
|
+
|
|
6
|
+
/** 确认卡片的回答类型(也是历史 report 的分发键) */
|
|
7
|
+
export declare const ACTION_EXECUTE_ANSWER_TYPE = "collect_clarifications";
|
|
8
|
+
/**
|
|
9
|
+
* 处理实时流的 front_reply 帧
|
|
10
|
+
* @param chunk 流式数据块
|
|
11
|
+
* @param reports 回答 reports 数组(registry 预取的同一引用,push 即累积)
|
|
12
|
+
* @param answerValues 回答整体结构(本 parser 不使用)
|
|
13
|
+
* @param options 解析配置(frontReply 提供回包通道与 host 执行器)
|
|
14
|
+
* @returns 是否消费了该 chunk(仅 front_reply 返回 true)
|
|
15
|
+
*/
|
|
16
|
+
export declare const applyActionExecuteChunk: (chunk: StreamChunk, reports: AiAnswerReport<any>[], _answerValues?: unknown, options?: AnswerParseOptions) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 历史归一化:历史里的确认卡片没有在途请求,统一标为已失效(只读展示)。
|
|
19
|
+
* 实时链路产出的 pending 报告若仍有在途请求则保持原状。
|
|
20
|
+
* @param report 历史 reports 中的确认卡片报告(就地修改)
|
|
21
|
+
*/
|
|
22
|
+
export declare const normalizeActionExecuteReport: (report: AiAnswerReport<ClarificationViewModel>) => void;
|
|
23
|
+
/**
|
|
24
|
+
* action_execute 答案类型的注册表条目(registry 内置):
|
|
25
|
+
* - 实时链路:`applyChunk` 只消费 `front_reply` 帧(确认卡片产出报告,host 指令只回包);
|
|
26
|
+
* - 历史链路:`answerType` 命中 `collect_clarifications` 时把 pending 标为已失效。
|
|
27
|
+
*/
|
|
28
|
+
export declare const actionExecuteParser: AnswerParser<ClarificationViewModel>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* action_execute / collect_clarifications 协议类型
|
|
3
|
+
*
|
|
4
|
+
* 对应后端流式回答中的 `mode === 'front_reply'` 帧:
|
|
5
|
+
* `{ mode: 'front_reply', reply_id, values: { type: 'action_execute', executor, action } }`。
|
|
6
|
+
* 宿主执行完(或用户提交确认项)后,统一以
|
|
7
|
+
* `{ type: 'wait_reply', reply_id, values }` 经同一条 WebSocket 回传。
|
|
8
|
+
*
|
|
9
|
+
* 与 `docs/agent-workflow-host-protocol.md` 第 4~12 章一一对应。
|
|
10
|
+
*/
|
|
11
|
+
/** Action 的执行端:host = 宿主页面执行,agent = 智能助手执行 */
|
|
12
|
+
export type ActionExecutor = 'host' | 'agent';
|
|
13
|
+
/** 单个待执行的 Action(模型规划结果 / 下发给宿主的指令体) */
|
|
14
|
+
export interface ActionDefinition {
|
|
15
|
+
/** Action 名称(宿主按此查表分发) */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Action 参数(对象形态) */
|
|
18
|
+
arguments: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/** 后端下发的执行指令 */
|
|
21
|
+
export interface ActionExecuteCommand {
|
|
22
|
+
/** 固定为 action_execute */
|
|
23
|
+
type: 'action_execute';
|
|
24
|
+
/** 执行端 */
|
|
25
|
+
executor: ActionExecutor;
|
|
26
|
+
/** 待执行的 Action */
|
|
27
|
+
action: ActionDefinition;
|
|
28
|
+
}
|
|
29
|
+
/** 统一的执行结果(回传后端固定三字段) */
|
|
30
|
+
export interface ActionResult<T = unknown> {
|
|
31
|
+
/** 是否执行成功 */
|
|
32
|
+
success: boolean;
|
|
33
|
+
/** 结果说明(成功/失败都必填) */
|
|
34
|
+
message: string;
|
|
35
|
+
/** 业务数据;没有时固定为 null */
|
|
36
|
+
data: T | null;
|
|
37
|
+
}
|
|
38
|
+
/** 回传后端的 wait_reply 载荷 */
|
|
39
|
+
export interface WaitReplyPayload {
|
|
40
|
+
/** 固定为 wait_reply */
|
|
41
|
+
type: 'wait_reply';
|
|
42
|
+
/** 对应 front_reply 的 reply_id(保持后端下发的原始类型) */
|
|
43
|
+
reply_id?: string | number;
|
|
44
|
+
/** 执行结果(ActionResult)或其它业务载荷 */
|
|
45
|
+
values: unknown;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* front_reply 处理配置(经 AnswerParseOptions.frontReply 注入;
|
|
49
|
+
* useChat 会自动补上 reply = sendWsMessage,宿主通常只需提供 execute)。
|
|
50
|
+
*/
|
|
51
|
+
export interface FrontReplyOptions {
|
|
52
|
+
/**
|
|
53
|
+
* host 执行器:executor === 'host' 时由宿主执行该 Action。
|
|
54
|
+
* 未提供时 host 指令一律回失败帧(避免后端一直等待 wait_reply)。
|
|
55
|
+
* @param action 待执行的 Action(name + arguments)
|
|
56
|
+
* @returns 统一执行结果(同步或异步均可)
|
|
57
|
+
*/
|
|
58
|
+
execute?: (action: ActionDefinition) => ActionResult | Promise<ActionResult>;
|
|
59
|
+
/**
|
|
60
|
+
* wait_reply 回传通道(useChat 内部注入 sendWsMessage,宿主一般不用传)。
|
|
61
|
+
* @param payload wait_reply 载荷
|
|
62
|
+
* @returns false 表示当前无在途连接(连接已关闭),回包失败
|
|
63
|
+
*/
|
|
64
|
+
reply?: (payload: WaitReplyPayload) => boolean | void;
|
|
65
|
+
/**
|
|
66
|
+
* 非致命错误回调(指令解析失败 / 执行异常 / 回包失败)。
|
|
67
|
+
* @param error 原始错误
|
|
68
|
+
*/
|
|
69
|
+
onError?: (error: unknown) => void;
|
|
70
|
+
}
|
|
71
|
+
/** 确认项输入类型 */
|
|
72
|
+
export type ClarificationInputType = 'single_select' | 'multi_select' | 'date' | 'text';
|
|
73
|
+
/** 确认项回答方式:结构化选项 / 自然语言 */
|
|
74
|
+
export type ClarificationAnswerMode = 'structured' | 'text';
|
|
75
|
+
/** 确认项的一个候选项 */
|
|
76
|
+
export interface ClarificationOption {
|
|
77
|
+
/** 展示文案 */
|
|
78
|
+
label: string;
|
|
79
|
+
/** 结构化值(原样回传后端) */
|
|
80
|
+
value: unknown;
|
|
81
|
+
}
|
|
82
|
+
/** 确认项与某个 Action 参数的绑定关系 */
|
|
83
|
+
export interface ClarificationBinding {
|
|
84
|
+
/** 对应候选 actions 中的下标 */
|
|
85
|
+
actionIndex?: number;
|
|
86
|
+
/** 对应 Action 名称 */
|
|
87
|
+
actionName?: string;
|
|
88
|
+
/** 对应参数路径(如 arguments.layerId) */
|
|
89
|
+
parameterPath?: string;
|
|
90
|
+
}
|
|
91
|
+
/** 确认项的输入控件定义 */
|
|
92
|
+
export interface ClarificationInput {
|
|
93
|
+
/** 控件类型 */
|
|
94
|
+
type: ClarificationInputType;
|
|
95
|
+
/** 单选 / 多选的候选项(这两种类型必填) */
|
|
96
|
+
options?: ClarificationOption[];
|
|
97
|
+
/** 日期格式;当前仅支持 YYYY-MM-DD */
|
|
98
|
+
format?: 'YYYY-MM-DD';
|
|
99
|
+
/** 输入占位提示 */
|
|
100
|
+
placeholder?: string;
|
|
101
|
+
/** 自然语言输入框配置(选择 / 日期类型会与结构化值并列展示) */
|
|
102
|
+
textInput?: {
|
|
103
|
+
/** 自然语言输入框占位提示 */
|
|
104
|
+
placeholder?: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** 单个确认项 */
|
|
108
|
+
export interface ClarificationItem {
|
|
109
|
+
/** 本次确认请求内的唯一标识 */
|
|
110
|
+
id: string;
|
|
111
|
+
/** 展示给用户的问题 */
|
|
112
|
+
question: string;
|
|
113
|
+
/** 问题补充说明 */
|
|
114
|
+
description?: string;
|
|
115
|
+
/** 是否必须回答(后端未显式给 false 时按必填处理) */
|
|
116
|
+
required: boolean;
|
|
117
|
+
/** 默认值(回显用) */
|
|
118
|
+
default?: unknown;
|
|
119
|
+
/** 与 Action 参数的绑定关系 */
|
|
120
|
+
binding?: ClarificationBinding;
|
|
121
|
+
/** 输入控件定义 */
|
|
122
|
+
input: ClarificationInput;
|
|
123
|
+
}
|
|
124
|
+
/** 用户对单个确认项的回答 */
|
|
125
|
+
export interface ClarificationAnswer {
|
|
126
|
+
/** 对应原确认项的 id */
|
|
127
|
+
id: string;
|
|
128
|
+
/** 回答方式 */
|
|
129
|
+
mode: ClarificationAnswerMode;
|
|
130
|
+
/** 结构化值或自然语言原文 */
|
|
131
|
+
value: unknown;
|
|
132
|
+
/** 界面上展示的答案文本 */
|
|
133
|
+
displayText: string;
|
|
134
|
+
}
|
|
135
|
+
/** 确认卡片状态:等待回答 / 已提交 / 已取消 / 已失效(历史回放无在途请求) */
|
|
136
|
+
export type ClarificationStatus = 'pending' | 'submitted' | 'cancelled' | 'expired';
|
|
137
|
+
/** 确认卡片视图模型(`answer_type = 'collect_clarifications'` 的 values) */
|
|
138
|
+
export interface ClarificationViewModel {
|
|
139
|
+
/** 本次确认请求 id(取自后端 reply_id,缺省时本地生成) */
|
|
140
|
+
requestId: string;
|
|
141
|
+
/** 卡片标题 */
|
|
142
|
+
title: string;
|
|
143
|
+
/** 卡片说明 */
|
|
144
|
+
description: string;
|
|
145
|
+
/** 待确认项列表 */
|
|
146
|
+
items: ClarificationItem[];
|
|
147
|
+
/** 当前状态 */
|
|
148
|
+
status: ClarificationStatus;
|
|
149
|
+
/** 状态说明文案(提交/取消/失效后展示) */
|
|
150
|
+
resultMessage: string;
|
|
151
|
+
/** 用户提交的回答(仅 submitted 状态有值) */
|
|
152
|
+
answers?: ClarificationAnswer[];
|
|
153
|
+
}
|