@vuagent/ui 0.3.0 → 0.6.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/README.md +22 -3
- package/dist/index.js +7326 -6442
- package/dist/types/components/agent-plan/VaAgentPlan.vue.d.ts +4 -0
- package/dist/types/components/agent-plan/types.d.ts +18 -0
- package/dist/types/components/assistant-turn/VaAssistantTurn.vue.d.ts +3 -3
- package/dist/types/components/capability-card/VaCapabilityCard.vue.d.ts +1 -1
- package/dist/types/components/change-summary/VaChangeSummary.vue.d.ts +1 -1
- package/dist/types/components/decision-inbox/types.d.ts +5 -4
- package/dist/types/components/empty-hero/VaEmptyHero.vue.d.ts +2 -2
- package/dist/types/components/form/VaForm.vue.d.ts +32 -0
- package/dist/types/components/form/index.d.ts +2 -0
- package/dist/types/components/form/types.d.ts +45 -0
- package/dist/types/components/gradient-border/VaGradientBorder.vue.d.ts +21 -0
- package/dist/types/components/gradient-border/index.d.ts +2 -0
- package/dist/types/components/gradient-border/types.d.ts +13 -0
- package/dist/types/components/message-actions/useMessageActions.d.ts +2 -0
- package/dist/types/components/otp-input/VaOtpInput.vue.d.ts +3 -1
- package/dist/types/components/queue-dock/VaQueueDock.vue.d.ts +1 -1
- package/dist/types/components/scrim-edge/VaScrimEdge.vue.d.ts +6 -0
- package/dist/types/components/scrim-edge/index.d.ts +2 -0
- package/dist/types/components/scrim-edge/types.d.ts +13 -0
- package/dist/types/components/smart-recommendation/VaSmartRecommendation.vue.d.ts +1 -1
- package/dist/types/components/spotlight-card/VaSpotlightCard.vue.d.ts +22 -0
- package/dist/types/components/spotlight-card/index.d.ts +3 -0
- package/dist/types/components/spotlight-card/types.d.ts +9 -0
- package/dist/types/components/spotlight-card/useSpotlightCard.d.ts +18 -0
- package/dist/types/components/stepper-form/VaStepperForm.vue.d.ts +9 -3
- package/dist/types/components/trajectory/VaTrajectory.vue.d.ts +3 -1
- package/dist/types/components/trajectory/useTrajectoryReveal.d.ts +18 -0
- package/dist/types/components/turn-list/VaTurnList.vue.d.ts +2 -2
- package/dist/types/components/user-bubble/VaUserBubble.vue.d.ts +2 -2
- package/dist/types/composables/useShake.d.ts +4 -0
- package/dist/types/composables/useSpotlight.d.ts +43 -0
- package/dist/types/composables/useStagger.d.ts +25 -0
- package/dist/types/index.d.ts +19 -1
- package/dist/types/runtime/actionClient.d.ts +5 -0
- package/dist/types/runtime/form-errors.d.ts +18 -0
- package/dist/types/runtime/form-result-schema.d.ts +49 -0
- package/dist/types/runtime/interaction-validation.d.ts +16 -0
- package/dist/types/runtime/plan-steps-mirror.d.ts +15 -0
- package/dist/types/runtime/protocol-types.d.ts +88 -2
- package/dist/types/runtime/sse.d.ts +79 -0
- package/dist/types/runtime/types.d.ts +8 -2
- package/dist/types/runtime/useAgentChat.d.ts +4 -2
- package/dist/types/runtime/useDeltaBuffer.d.ts +63 -0
- package/dist/vuagent-ui.css +1 -1
- package/package.json +1 -1
- package/src/styles/button.css +8 -1
- package/src/styles/motion.css +211 -0
- package/src/styles/surface.css +55 -0
- package/src/styles/tokens.css +66 -4
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vuagent/ui - form resultSchema 派生器(vendored 副本,TASK-092)
|
|
3
|
+
*
|
|
4
|
+
* 逐字同步自 @vuagent/protocol/src/form.ts 的 `FormFieldSpec` 与
|
|
5
|
+
* `deriveFormResultSchema`(见该文件头注释「单一事实来源;ui 侧为文本同步的
|
|
6
|
+
* vendored 副本」)。为什么 vendored:@vuagent/ui 以 npm 包分发且必须零
|
|
7
|
+
* workspace 依赖(peer 仅 vue,见 ./protocol-types.ts 头注释),不能引入
|
|
8
|
+
* protocol/typebox 运行时——派生器刻意不依赖 TypeBox(输出普通 JSON Schema
|
|
9
|
+
* 对象字面量),得以文本级分发到 ui 侧。
|
|
10
|
+
*
|
|
11
|
+
* 同步保障:两侧函数文本由 scripts/check-protocol-sync.mjs 的函数级比对
|
|
12
|
+
* (FUNCTION_CORPUS)机械锁死——任何一侧改动(哪怕一行)都会让卡口失败,
|
|
13
|
+
* 杜绝双事实来源漂移。本文件不得新增 protocol 侧没有的声明。
|
|
14
|
+
*/
|
|
15
|
+
/** 结构别名占位(npm 自包含:不引入 @sinclair/typebox) */
|
|
16
|
+
type TSchema = Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* 派生器的结构输入(两侧文件各自本地声明同名结构,函数文本保持逐字一致)。
|
|
19
|
+
* 与 FormFieldSchema 的 Static 类型结构化兼容(key 之外全部可选读取)。
|
|
20
|
+
*/
|
|
21
|
+
interface FormFieldSpec {
|
|
22
|
+
key: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
type: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
default?: unknown;
|
|
28
|
+
options?: ReadonlyArray<{
|
|
29
|
+
value: string;
|
|
30
|
+
label: string;
|
|
31
|
+
}>;
|
|
32
|
+
unit?: string;
|
|
33
|
+
secret?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 从 fields 派生回传值校验 Schema(resultSchema 一身三任:边界校验规则 /
|
|
37
|
+
* 模型词汇表 / 摘要生成模板)。
|
|
38
|
+
*
|
|
39
|
+
* 映射规则(设计文档 §7 + §4.1 摘要规则表):
|
|
40
|
+
* - text/textarea/date → string;number → number;boolean → boolean;
|
|
41
|
+
* - select → string + anyOf[{const, label, description}](枚举约束与 label 回映
|
|
42
|
+
* 同体:result-digest 的 enumLabelOf 读 anyOf 分支的 label/description);
|
|
43
|
+
* - required:true → 顶层 required 数组;
|
|
44
|
+
* - description(缺省回退 label)/ unit / secret / default 作为自定义关键字
|
|
45
|
+
* 透传——TypeBox Value.Check 忽略未知关键字(不影响校验),result-digest
|
|
46
|
+
* 与 ui 本地预校验读取它们驱动摘要打码与本地提示。
|
|
47
|
+
*/
|
|
48
|
+
export declare function deriveFormResultSchema(fields: ReadonlyArray<FormFieldSpec>): TSchema;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UIComponentInteraction } from './protocol-types';
|
|
2
|
+
/** 本地校验失败错误:携带逐字段错误信息,供组件回显(不发请求、不落乐观更新) */
|
|
3
|
+
export declare class UIActionLocalValidationError extends Error {
|
|
4
|
+
readonly fieldErrors: Record<string, string>;
|
|
5
|
+
constructor(fieldErrors: Record<string, string>);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 按 resultSchema 校验 submit/patch 信封的 values。
|
|
9
|
+
* 返回逐字段错误(空对象 = 通过)。schema 缺失/非对象时视为无本地校验能力,直接放行。
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateValuesLocally(values: Record<string, unknown>, resultSchema: unknown): Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* 取组件声明的本地校验 Schema:仅 submit/patch 这类携带 values 的信封可校验;
|
|
14
|
+
* 组件未声明 interaction.resultSchema 时返回 null(调用方跳过本地校验)。
|
|
15
|
+
*/
|
|
16
|
+
export declare function localValidationSchemaOf(interaction: UIComponentInteraction | undefined, kind: "submit" | "cancel" | "patch"): unknown | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vuagent/ui - 协作计划 steps 镜像(评审 R1 修复)
|
|
3
|
+
*
|
|
4
|
+
* VaAgentPlan 是纯 props 驱动组件:用户编辑 emit update:steps 后,若不把
|
|
5
|
+
* 编辑结果回写到 props,下一次编辑仍从**原始 args.steps** 计算——前一次
|
|
6
|
+
* patch 的增量被静默覆盖(连续编辑丢失数据,server 侧 PatchStash 同样只
|
|
7
|
+
* 收到最后一次)。本模块按 toolCallId 保存「最近一次已发送的 steps」,
|
|
8
|
+
* propAdapter 读取镜像作为渲染输入(在 activeProps computed 内读取即注册
|
|
9
|
+
* 响应依赖,写入自动驱动回显);终态/消息换血时清理。
|
|
10
|
+
*/
|
|
11
|
+
export declare const planStepsMirror: import('vue').Reactive<Map<string, unknown[]>>;
|
|
12
|
+
export declare function getPlanStepsMirror(toolCallId: string): unknown[] | undefined;
|
|
13
|
+
export declare function setPlanStepsMirror(toolCallId: string, steps: readonly unknown[]): void;
|
|
14
|
+
export declare function clearPlanStepsMirror(toolCallId: string): void;
|
|
15
|
+
export declare function clearAllPlanStepsMirrors(): void;
|
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 为什么内联:@vuagent/ui 以 npm 包分发(dist 产物),运行时 JS 已将这些
|
|
5
5
|
* 契约仅作类型使用(bundle 自包含,仅外部依赖 vue);若保留对
|
|
6
|
-
* @
|
|
6
|
+
* @sinclair/typebox 的依赖声明,发布后宿主会解析到一个 npm 上不存在的
|
|
7
7
|
* workspace 包,导致 `npm i @vuagent/ui` 直接失败。内联类型让发布包
|
|
8
8
|
* 零外部依赖(peer 仅 vue),契约语义与 @vuagent/protocol 保持一致,
|
|
9
|
-
* 两端类型演进时需人工同步(见 packages/protocol/src/lifecycle.ts / events.ts
|
|
9
|
+
* 两端类型演进时需人工同步(见 packages/protocol/src/lifecycle.ts / events.ts /
|
|
10
|
+
* interaction.ts),同步由 scripts/check-protocol-sync.mjs 卡口机械把关。
|
|
11
|
+
*
|
|
12
|
+
* TASK-090:追加 vendor 交互契约类型(protocol/src/interaction.ts)——
|
|
13
|
+
* 信封(UIActionEnvelope)与交互能力声明(UIComponentInteraction)。
|
|
14
|
+
* 协议侧 ActionMeta/UIActionEnvelope 是 Static<typeof Schema> 计算类型,
|
|
15
|
+
* 此处按 Schema 语义展开为字面声明(卡口对计算类型做名集合比对,
|
|
16
|
+
* 形状保真由 protocol 侧 Schema 测试与本包信封快照测试双侧兜底)。
|
|
10
17
|
*/
|
|
11
18
|
/**
|
|
12
19
|
* Agent 组件的四态生命周期:
|
|
@@ -116,3 +123,82 @@ export type UIStreamEvent =
|
|
|
116
123
|
code?: string;
|
|
117
124
|
message: string;
|
|
118
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* 协议侧为 @sinclair/typebox 的 TSchema(运行时校验只在 server 做)。
|
|
128
|
+
* ui 侧不引入 typebox 运行时,仅以 JSON Schema 结构视角只读消费
|
|
129
|
+
* (本地预校验见 runtime/interaction-validation.ts)——刻意保持宽松结构:
|
|
130
|
+
* 回传值校验的权威永远在 server 边界(设计文档 §8「UI 回传不可信」)。
|
|
131
|
+
* 非导出:仅为下方 vendored 声明提供同名标识符,不进发布类型面。
|
|
132
|
+
*/
|
|
133
|
+
type TSchema = Record<string, unknown>;
|
|
134
|
+
/** 交互元信息(对应 protocol ActionMetaSchema 的 Static 展开) */
|
|
135
|
+
export interface ActionMeta {
|
|
136
|
+
/** 用户实际修改过的字段 key(区别于组件预填默认值) */
|
|
137
|
+
editedFields?: string[];
|
|
138
|
+
/** 用户交互耗时(毫秒) */
|
|
139
|
+
durationMs?: number;
|
|
140
|
+
/** 前端是否已过本地校验(服务端仍必须复核) */
|
|
141
|
+
clientValidated?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/** submit 信封:用户提交结构化值(values 形状由组件 resultSchema 约束) */
|
|
144
|
+
export interface UIActionSubmitEnvelope {
|
|
145
|
+
kind: "submit";
|
|
146
|
+
values: Record<string, unknown>;
|
|
147
|
+
meta?: ActionMeta;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* cancel 信封:用户主动取消——一等公民而非错误
|
|
151
|
+
* (设计文档 §3:混为 error 会诱导模型重试轰炸)
|
|
152
|
+
*/
|
|
153
|
+
export interface UIActionCancelEnvelope {
|
|
154
|
+
kind: "cancel";
|
|
155
|
+
reason?: string;
|
|
156
|
+
meta?: ActionMeta;
|
|
157
|
+
}
|
|
158
|
+
/** patch 信封:L3 预留的增量编辑,不终结挂起(运行时本阶段不实现) */
|
|
159
|
+
export interface UIActionPatchEnvelope {
|
|
160
|
+
kind: "patch";
|
|
161
|
+
values: Record<string, unknown>;
|
|
162
|
+
meta?: ActionMeta;
|
|
163
|
+
}
|
|
164
|
+
/** 回传信封判别联合(对应 protocol UIActionEnvelopeSchema 的 Static 展开) */
|
|
165
|
+
export type UIActionEnvelope = UIActionSubmitEnvelope | UIActionCancelEnvelope | UIActionPatchEnvelope;
|
|
166
|
+
export type UIActionKind = UIActionEnvelope["kind"];
|
|
167
|
+
/**
|
|
168
|
+
* 交互能力分级(设计文档 §2):
|
|
169
|
+
* - L0 presentational:纯展示,无回传通道(缺省等级);
|
|
170
|
+
* - L1 decision:有限决策集(approve/deny),枚举型 payload;
|
|
171
|
+
* - L2 form:结构化值采集——必须声明 resultSchema;
|
|
172
|
+
* - L3 collaborative:多次增量 patch,终态由显式 submit/cancel 触发——必须声明 resultSchema。
|
|
173
|
+
*/
|
|
174
|
+
export type UIInteractionLevel = "L0" | "L1" | "L2" | "L3";
|
|
175
|
+
/**
|
|
176
|
+
* 组件交互声明(挂在 RegisteredComponentEntry.interaction)。
|
|
177
|
+
*
|
|
178
|
+
* 刻意用 TS interface 而非 TypeBox Schema:resultSchema 本身是 TSchema
|
|
179
|
+
* (schema 的 schema 在 TypeBox 里只能退化为 Unknown,失去校验意义),
|
|
180
|
+
* 且该声明是定义期契约,不是线格式。
|
|
181
|
+
*/
|
|
182
|
+
export interface UIComponentInteraction {
|
|
183
|
+
level: UIInteractionLevel;
|
|
184
|
+
/**
|
|
185
|
+
* UI → LLM 方向的回传值 Schema(L2/L3 必填,或与 deriveResultSchema 二选一):
|
|
186
|
+
* 一身三任——服务端边界校验规则 / 模型词汇表(字段 description)/ 摘要生成模板。
|
|
187
|
+
*/
|
|
188
|
+
resultSchema?: TSchema;
|
|
189
|
+
/**
|
|
190
|
+
* args 驱动的 resultSchema 派生器(TASK-092,与 resultSchema 二选一):
|
|
191
|
+
* resultSchema 不允许模型自行声明(设计文档 §7——模型给的 fields 是输入,
|
|
192
|
+
* resultSchema 是推导结果,防止模型通过自定义 resultSchema 放宽校验),
|
|
193
|
+
* ui_form 这类「Schema 由模型入参决定」的组件通过本回调在服务端/前端
|
|
194
|
+
* 按同一份 fields 推导(派生逻辑本体见 form.ts deriveFormResultSchema)。
|
|
195
|
+
* 定义期合法性由 assertValidInteraction() 把关(L2/L3 两者至少其一)。
|
|
196
|
+
*/
|
|
197
|
+
deriveResultSchema?: (args: Record<string, unknown>) => TSchema;
|
|
198
|
+
/**
|
|
199
|
+
* 挂起超时的语义归属:deny(L1 缺省,视为拒绝)/ cancel(L2 缺省,视为放弃)。
|
|
200
|
+
* 超时不允许映射为 submit(半成品值不得当作用户意图,设计文档 §6)。
|
|
201
|
+
*/
|
|
202
|
+
timeoutMeaning?: "cancel" | "deny";
|
|
203
|
+
}
|
|
204
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 共享 SSE 消费件(TASK-114 双轨归一):
|
|
3
|
+
* useAgentChat(库)与 console useChatStream(宿主)此前各有一套内联
|
|
4
|
+
* reader 循环 + 块解析——本模块收口为单一实现,双方消费同一份代码。
|
|
5
|
+
*
|
|
6
|
+
* 两部分:
|
|
7
|
+
* - parseSSEChunk:纯函数块解析(跨 chunk 半包 / CRLF / 多行 data 合并,SSE 规范);
|
|
8
|
+
* - consumeSSEStream:fetch Response → 事件流消费循环(泛型事件类型、
|
|
9
|
+
* AbortError 分类、解析失败钩子)。
|
|
10
|
+
*
|
|
11
|
+
* 纯 TypeScript(无 Vue 依赖):可单测、可被非组件数据域复用。
|
|
12
|
+
*
|
|
13
|
+
* @example 基本用法(类型化事件流)
|
|
14
|
+
* ```ts
|
|
15
|
+
* const { aborted } = await consumeSSEStream<UIStreamEvent>({
|
|
16
|
+
* open: () => fetch("/api/chat", { method: "POST", body }),
|
|
17
|
+
* onEvent: (event) => reduce(event), // event: UIStreamEvent(无类型断言)
|
|
18
|
+
* onDone: () => finalize(),
|
|
19
|
+
* signal: controller.signal,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example 自定义解析失败处理(默认 console.warn 跳过)
|
|
24
|
+
* ```ts
|
|
25
|
+
* consumeSSEStream({
|
|
26
|
+
* open,
|
|
27
|
+
* onEvent,
|
|
28
|
+
* onParseError: (payload, err) => telemetry.warn("sse-parse", { payload, err }),
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface SSEParseResult {
|
|
33
|
+
/** 本次完整取出的 data 载荷(JSON 字符串或 "[DONE]") */
|
|
34
|
+
payloads: string[];
|
|
35
|
+
/** 未凑齐事件的残余 buffer,需带回下一次调用 */
|
|
36
|
+
buffer: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* SSE 文本流块解析(纯函数):
|
|
40
|
+
* 输入增量 chunk + 上一次残余 buffer,输出本次完整取出的 data 载荷与新的残余 buffer。
|
|
41
|
+
* 规范增强(相比朴素的 split("\n") 逐行实现):
|
|
42
|
+
* 1. 兼容 \r\n / \r 换行;
|
|
43
|
+
* 2. 按 SSE 规范合并同一事件块内的多行 data 字段;
|
|
44
|
+
* 3. 忽略注释行(`:` 前缀,如心跳 `: keepalive`)与非 data 字段行。
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseSSEChunk(chunk: string, buffer: string): SSEParseResult;
|
|
47
|
+
export interface SSEConsumeOptions<T = unknown> {
|
|
48
|
+
/**
|
|
49
|
+
* 打开流:唯一的传输扩展点(调用方完全掌控 fetch/headers/URL/重连策略——
|
|
50
|
+
* POST 发起、GET 重连、代理转发、自定义鉴权都在这里做)。
|
|
51
|
+
* 非 2xx 应在本函数内抛错(错误原样透传给调用方)。
|
|
52
|
+
*/
|
|
53
|
+
open: () => Promise<Response>;
|
|
54
|
+
/**
|
|
55
|
+
* 已解析的事件对象([DONE] 不经过此回调,走 onDone)。
|
|
56
|
+
* 泛型 T 指定事件类型,免去调用方断言。
|
|
57
|
+
*/
|
|
58
|
+
onEvent: (event: T) => void;
|
|
59
|
+
/** 服务端收尾标记(data: [DONE]);流自然读完但未发 [DONE] 时不会触发 */
|
|
60
|
+
onDone?: () => void;
|
|
61
|
+
/** 本地中止信号(兜底断开手段;中止 → 结果 aborted:true 而非抛错) */
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
/**
|
|
64
|
+
* 解析失败钩子(扩展点):data 块 JSON 解析失败时调用(缺省 console.warn 后
|
|
65
|
+
* 跳过该块——单块损坏不拖垮整条流)。宿主可接告警/采样/降级渲染。
|
|
66
|
+
*/
|
|
67
|
+
onParseError?: (payload: string, err: unknown) => void;
|
|
68
|
+
}
|
|
69
|
+
export interface SSEConsumeResult {
|
|
70
|
+
/** true = 因本地 abort 断开(非服务端正常收尾) */
|
|
71
|
+
aborted: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 消费 SSE 流至收尾/断开。
|
|
75
|
+
* - 正常收尾([DONE] 后流结束,或流自然读完)→ { aborted: false };
|
|
76
|
+
* - signal 中止 → { aborted: true }(调用方据此做中止徽标等本地语义);
|
|
77
|
+
* - 其他错误(网络/服务端非 2xx 的 open 抛错/流中断)→ 原样抛出,由调用方呈现。
|
|
78
|
+
*/
|
|
79
|
+
export declare function consumeSSEStream<T = unknown>(options: SSEConsumeOptions<T>): Promise<SSEConsumeResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from 'vue';
|
|
2
|
-
import { AgentComponentBaseProps, AgentComponentStatus, MessageBlock, UIStreamEvent } from './protocol-types';
|
|
3
|
-
export type { AgentComponentBaseProps, AgentComponentStatus, MessageBlock, UIStreamEvent, };
|
|
2
|
+
import { ActionMeta, AgentComponentBaseProps, AgentComponentStatus, MessageBlock, UIActionCancelEnvelope, UIActionEnvelope, UIActionKind, UIActionPatchEnvelope, UIActionSubmitEnvelope, UIComponentInteraction, UIInteractionLevel, UIStreamEvent } from './protocol-types';
|
|
3
|
+
export type { ActionMeta, AgentComponentBaseProps, AgentComponentStatus, MessageBlock, UIActionCancelEnvelope, UIActionEnvelope, UIActionKind, UIActionPatchEnvelope, UIActionSubmitEnvelope, UIComponentInteraction, UIInteractionLevel, UIStreamEvent, };
|
|
4
4
|
export interface CustomProviderConfig {
|
|
5
5
|
provider?: string;
|
|
6
6
|
baseUrl?: string;
|
|
@@ -19,6 +19,12 @@ export interface RegisteredComponentEntry<TArgs extends Record<string, any> = Re
|
|
|
19
19
|
* false: 流式阶段优先展示 skeleton,待参数完整 (executing/done) 时再渲染实体组件
|
|
20
20
|
*/
|
|
21
21
|
progressive?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 交互能力声明(TASK-090,设计文档 §2 分级):缺省视为 L0 纯展示。
|
|
24
|
+
* 声明 L1/L2/L3 的组件才会在 executing 态获得可用的 onSubmitAction 通道;
|
|
25
|
+
* L2/L3 的 resultSchema 驱动提交前本地预校验(server 边界复核仍是权威)。
|
|
26
|
+
*/
|
|
27
|
+
interaction?: UIComponentInteraction;
|
|
22
28
|
/**
|
|
23
29
|
* 自定义适配器:将大模型生成的 args 转换为该组件特有的 props。
|
|
24
30
|
* 注意:args 来自模型输出,必须视为不可信输入——各字段需做空值/类型兜底。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageBlock, UIStreamEvent, CustomProviderConfig } from './types.js';
|
|
1
|
+
import { MessageBlock, UIActionEnvelope, UIStreamEvent, CustomProviderConfig } from './types.js';
|
|
2
2
|
export interface ChatMessage {
|
|
3
3
|
id: string;
|
|
4
4
|
role: "user" | "assistant" | "system";
|
|
@@ -68,8 +68,10 @@ export declare function useAgentChat(options?: UseAgentChatOptions): {
|
|
|
68
68
|
}[]>;
|
|
69
69
|
isStreaming: import('vue').Ref<boolean, boolean>;
|
|
70
70
|
error: import('vue').Ref<string | null, string | null>;
|
|
71
|
+
/** 即时提交合帧缓冲(复制/截图等需要立刻取全文的场景;测试亦经此手动 flush) */
|
|
72
|
+
flushNow: () => void;
|
|
71
73
|
sendMessage: (prompt: string, extraOptions?: SendMessageOptions | Record<string, string>) => Promise<void>;
|
|
72
|
-
submitAction:
|
|
74
|
+
submitAction: (toolCallId: string, envelope: UIActionEnvelope) => Promise<any>;
|
|
73
75
|
handleStreamEvent: (event: UIStreamEvent) => void;
|
|
74
76
|
playMockEvents: (events: UIStreamEvent[], delayMs?: number) => Promise<void>;
|
|
75
77
|
clearMessages: () => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 流式文本 rAF 合帧缓冲(TASK-104 引入于 useAgentChat,TASK-114 抽离为共享件):
|
|
3
|
+
* delta 只进缓冲,每帧一次 commit——markdown 重解析随 commit 同帧节流
|
|
4
|
+
* (同帧多次 delta 只触发一次重渲染)。
|
|
5
|
+
*
|
|
6
|
+
* 职责边界:本件只负责「累积 + 帧调度 + flush/drop 纪律」;
|
|
7
|
+
* 提交目标(写哪块文本)由调用方的 commit 回调决定——
|
|
8
|
+
* 块寻址、响应式代理、跨块防御都是调用方状态机的职责。
|
|
9
|
+
*
|
|
10
|
+
* @example 基本用法
|
|
11
|
+
* ```ts
|
|
12
|
+
* const buffer = createDeltaBuffer({
|
|
13
|
+
* commit: (text) => { targetBlock.content += text; },
|
|
14
|
+
* });
|
|
15
|
+
* buffer.push(delta); // 累积并调度一帧
|
|
16
|
+
* buffer.flush(); // 流结束/错误/块边界切换:同步提交(幂等)
|
|
17
|
+
* buffer.drop(); // 消息整体换血:丢弃不提交
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example 自定义帧调度器(worker / 节流 / 测试手动跑帧)
|
|
21
|
+
* ```ts
|
|
22
|
+
* const buffer = createDeltaBuffer({
|
|
23
|
+
* commit,
|
|
24
|
+
* scheduler: {
|
|
25
|
+
* schedule: (cb) => setTimeout(cb, 16), // 返回句柄
|
|
26
|
+
* cancel: (handle) => clearTimeout(handle as number),
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* 降级:注入缺省调度器且环境无 rAF 时(Node SSR / 未注入 rAF 的测试环境)
|
|
32
|
+
* push 直接同步 commit——每 delta 即时可见,与合帧前的对外行为契约一致。
|
|
33
|
+
* 陈旧帧防御:flush 后迟到的帧回调不再二次提交。
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* 帧调度器抽象(扩展点):缺省 rAF;测试手动跑帧 / worker / 自定义节流可注入。
|
|
37
|
+
* **契约:schedule 应异步调度 callback(不得同步调用)**——缓冲的陈旧帧防御
|
|
38
|
+
* 依赖「schedule 返回句柄 → 句柄赋值 → 帧回调」的时序;同步调用回调会破坏
|
|
39
|
+
* 防御语义。同步提交诉求走「无 rAF 缺省调度器」的自动降级路径。
|
|
40
|
+
*/
|
|
41
|
+
export interface DeltaBufferScheduler {
|
|
42
|
+
/** 调度一帧,返回句柄(供 cancel 使用) */
|
|
43
|
+
schedule(callback: () => void): unknown;
|
|
44
|
+
/** 取消一帧(handle 为 schedule 的返回值) */
|
|
45
|
+
cancel(handle: unknown): void;
|
|
46
|
+
}
|
|
47
|
+
export interface DeltaBufferOptions {
|
|
48
|
+
/** 提交回调:缓冲 flush 时以累积文本调用(幂等:空缓冲不调用) */
|
|
49
|
+
commit: (accumulated: string) => void;
|
|
50
|
+
/** 帧调度器;缺省 rAF(无 rAF 环境同步降级) */
|
|
51
|
+
scheduler?: DeltaBufferScheduler;
|
|
52
|
+
}
|
|
53
|
+
export interface DeltaBuffer {
|
|
54
|
+
/** 累积一条 delta 并调度帧提交 */
|
|
55
|
+
push(delta: string): void;
|
|
56
|
+
/** 即时提交缓冲(幂等:空缓冲时 commit 不被调用) */
|
|
57
|
+
flush(): void;
|
|
58
|
+
/** 丢弃缓冲(不 commit) */
|
|
59
|
+
drop(): void;
|
|
60
|
+
/** 是否有未提交的累积文本(测试/防御断言用) */
|
|
61
|
+
readonly pendingText: string;
|
|
62
|
+
}
|
|
63
|
+
export declare function createDeltaBuffer(options: DeltaBufferOptions): DeltaBuffer;
|