@done-coding/forge-kit-agent 0.0.0-stage → 0.100.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/LICENSE +21 -0
- package/README.md +53 -2
- package/es/_virtual/_plugin-vue_export-helper.mjs +10 -0
- package/es/components/bubble/AiBubbleContent.vue.mjs +7 -0
- package/es/components/bubble/AiBubbleContent.vue2.mjs +209 -0
- package/es/components/bubble/AiBubbleFooter.vue.mjs +7 -0
- package/es/components/bubble/AiBubbleFooter.vue2.mjs +91 -0
- package/es/components/bubble/AiCodeHeaderControl.vue.mjs +7 -0
- package/es/components/bubble/AiCodeHeaderControl.vue2.mjs +97 -0
- package/es/components/bubble/AiContentSplit.vue.mjs +70 -0
- package/es/components/bubble/AiContentSplit.vue2.mjs +4 -0
- package/es/components/bubble/AiPartRenderer.vue.mjs +7 -0
- package/es/components/bubble/AiPartRenderer.vue2.mjs +184 -0
- package/es/components/bubble/AiThinkBox.vue.mjs +7 -0
- package/es/components/bubble/AiThinkBox.vue2.mjs +155 -0
- package/es/components/bubble/AiTypewriter.vue.mjs +81 -0
- package/es/components/bubble/AiTypewriter.vue2.mjs +4 -0
- package/es/components/config/AiConfigProvider.vue.mjs +31 -0
- package/es/components/config/AiConfigProvider.vue2.mjs +4 -0
- package/es/components/dialogue/AiDialogue.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogue.vue2.mjs +242 -0
- package/es/components/dialogue/AiDialogueGroup.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogueGroup.vue2.mjs +133 -0
- package/es/components/dialogue/AiDialogueWrap.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogueWrap.vue2.mjs +73 -0
- package/es/components/dialogue/AiMessageList.vue.mjs +7 -0
- package/es/components/dialogue/AiMessageList.vue2.mjs +111 -0
- package/es/components/json-trigger/LlmJsonTrigger.vue.mjs +7 -0
- package/es/components/json-trigger/LlmJsonTrigger.vue2.mjs +130 -0
- package/es/components/operation/AiOperationBar.vue.mjs +7 -0
- package/es/components/operation/AiOperationBar.vue2.mjs +174 -0
- package/es/components/operation/AiOperationBtns.vue.mjs +7 -0
- package/es/components/operation/AiOperationBtns.vue2.mjs +140 -0
- package/es/components/sender/AiSender.vue.mjs +7 -0
- package/es/components/sender/AiSender.vue2.mjs +74 -0
- package/es/components/sender/AiSenderHeader.vue.mjs +7 -0
- package/es/components/sender/AiSenderHeader.vue2.mjs +78 -0
- package/es/hooks/CodeXSlot.mjs +20 -0
- package/es/hooks/SessionExpose.mjs +81 -0
- package/es/hooks/agent-tools.mjs +95 -0
- package/es/hooks/agent.mjs +143 -0
- package/es/hooks/bubble-list.mjs +64 -0
- package/es/hooks/expose.mjs +133 -0
- package/es/hooks/fix-bubble-list-bug.mjs +65 -0
- package/es/hooks/sender-history.mjs +28 -0
- package/es/hooks/sender.mjs +197 -0
- package/es/hooks/session-list.mjs +154 -0
- package/es/hooks/sse.mjs +401 -0
- package/es/hooks/storage.mjs +217 -0
- package/es/hooks/theme.mjs +253 -0
- package/es/hooks/use-density.mjs +100 -0
- package/es/hooks/use-empty-state-center.mjs +40 -0
- package/es/hooks/use-keyboard-inset.mjs +87 -0
- package/es/index.mjs +68 -0
- package/es/style.css +836 -0
- package/es/types/index.mjs +54 -0
- package/es/utils/index.mjs +34 -0
- package/es/utils/json-from-llm.mjs +26 -0
- package/es/utils/request-llm.mjs +60 -0
- package/package.json +83 -4
- package/types/bridge/config-hook.d.ts +21 -0
- package/types/bridge/index.d.ts +69 -0
- package/types/bridge/plugin.d.ts +39 -0
- package/types/bridge/state.d.ts +26 -0
- package/types/bridge/storage.d.ts +10 -0
- package/types/components/bubble/AiBubbleContent.vue.d.ts +57 -0
- package/types/components/bubble/AiBubbleFooter.vue.d.ts +6 -0
- package/types/components/bubble/AiCodeHeaderControl.vue.d.ts +7 -0
- package/types/components/bubble/AiContentSplit.vue.d.ts +36 -0
- package/types/components/bubble/AiPartRenderer.vue.d.ts +9 -0
- package/types/components/bubble/AiThinkBox.vue.d.ts +31 -0
- package/types/components/bubble/AiTypewriter.vue.d.ts +28 -0
- package/types/components/config/AiConfigProvider.vue.d.ts +28 -0
- package/types/components/dialogue/AiDialogue.vue.d.ts +546 -0
- package/types/components/dialogue/AiDialogueGroup.vue.d.ts +49 -0
- package/types/components/dialogue/AiDialogueWrap.vue.d.ts +38 -0
- package/types/components/dialogue/AiMessageList.vue.d.ts +65 -0
- package/types/components/json-trigger/LlmJsonTrigger.vue.d.ts +43 -0
- package/types/components/json-trigger/types.d.ts +12 -0
- package/types/components/operation/AiOperationBar.vue.d.ts +36 -0
- package/types/components/operation/AiOperationBtns.vue.d.ts +27 -0
- package/types/components/sender/AiSender.vue.d.ts +38 -0
- package/types/components/sender/AiSenderHeader.vue.d.ts +28 -0
- package/types/hooks/CodeXSlot.d.ts +7 -0
- package/types/hooks/SessionExpose.d.ts +20 -0
- package/types/hooks/agent-tools.d.ts +67 -0
- package/types/hooks/agent.d.ts +43 -0
- package/types/hooks/bubble-list.d.ts +22 -0
- package/types/hooks/expose.d.ts +111 -0
- package/types/hooks/fix-bubble-list-bug.d.ts +8 -0
- package/types/hooks/sender-history.d.ts +41 -0
- package/types/hooks/sender.d.ts +101 -0
- package/types/hooks/session-list.d.ts +36 -0
- package/types/hooks/sse.d.ts +239 -0
- package/types/hooks/storage.d.ts +70 -0
- package/types/hooks/theme.d.ts +37 -0
- package/types/hooks/use-density.d.ts +66 -0
- package/types/hooks/use-empty-state-center.d.ts +23 -0
- package/types/hooks/use-keyboard-inset.d.ts +37 -0
- package/types/index.d.ts +26 -0
- package/types/inject/key.d.ts +20 -0
- package/types/types/index.d.ts +612 -0
- package/types/utils/index.d.ts +29 -0
- package/types/utils/json-from-llm.d.ts +35 -0
- package/types/utils/request-llm.d.ts +44 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Reactive } from 'vue';
|
|
2
|
+
import { AiSSEOptions } from './sse';
|
|
3
|
+
import { AiMessagePart, AiTool, AiToolExecutor, XBubbleListItemProps } from '../types';
|
|
4
|
+
import { SenderHistorySerializer } from './sender-history';
|
|
5
|
+
/**
|
|
6
|
+
* 程序化发送的附加项(`handleSubmit` 第二参)。
|
|
7
|
+
* ----
|
|
8
|
+
* 输入框路径(`@submit`)只给正文、不传本参;`ask({ parts })` 经它把「以用户名义发出的
|
|
9
|
+
* 结构化卡片」带进同一条发送主干——[MUST NOT] 为卡片另开一条发送路径(两条路径会各自
|
|
10
|
+
* 漏掉滚动 / 中止 / 历史快照 / 打字机的某几步)。
|
|
11
|
+
*/
|
|
12
|
+
export interface AiSenderSubmitOptions {
|
|
13
|
+
/** 随本条用户消息发出的 parts(数据卡 / 引用卡 / 附件) */
|
|
14
|
+
parts?: readonly AiMessagePart[];
|
|
15
|
+
}
|
|
16
|
+
/** 应用 输入框 作用域 选项 */
|
|
17
|
+
export interface AiSenderScopedOptions<T extends XBubbleListItemProps = XBubbleListItemProps> extends Pick<AiSSEOptions, "converter"> {
|
|
18
|
+
/** 添加聊天气泡 */
|
|
19
|
+
addBubble: (item: T) => Reactive<T>;
|
|
20
|
+
/**
|
|
21
|
+
* 获取当前会话气泡列表(多轮上下文来源)。
|
|
22
|
+
* ----
|
|
23
|
+
* 惰性 getter;发送时在 addBubble **之前**取快照(见 `senderBuildMessages`)。
|
|
24
|
+
* 不传 = 无历史可取,退化为单轮。
|
|
25
|
+
*/
|
|
26
|
+
getBubbleList?: () => readonly T[];
|
|
27
|
+
/**
|
|
28
|
+
* 获取附加 / 覆盖的 SSE 请求头。
|
|
29
|
+
* ----
|
|
30
|
+
* 走 getter 而非直值:消费方可能按运行期状态改鉴权头(换租户 / 刷新 token),
|
|
31
|
+
* 直值会在 setup 期定格。每轮发送时求值。
|
|
32
|
+
*/
|
|
33
|
+
getHeaders?: () => AiSSEOptions["headers"];
|
|
34
|
+
/**
|
|
35
|
+
* 获取附加 / 覆盖的 SSE 请求 body 字段。
|
|
36
|
+
* ----
|
|
37
|
+
* 走 getter 而非直值:`tools` 等字段常随页面上下文动态变化,直值会在 setup 期定格。
|
|
38
|
+
* 每轮发送时求值。
|
|
39
|
+
*/
|
|
40
|
+
getBody?: () => Record<string, unknown> | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 获取携带的历史消息**条数**上限(不含本轮)。
|
|
43
|
+
* ----
|
|
44
|
+
* 返回 `undefined` = 全量历史(默认);`<= 0` = 不带历史(单轮);`n > 0` = 最近 n 条。
|
|
45
|
+
*/
|
|
46
|
+
getHistoryLimit?: () => number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* 获取前端工具注册表(webAgent)。
|
|
49
|
+
* ----
|
|
50
|
+
* 走 getter 而非直值:可用工具常随页面上下文变化(当前实体 / 权限 / 已开面板),
|
|
51
|
+
* 直值会在 setup 期定格。每轮发送时求值。不传 = 不开工具循环。
|
|
52
|
+
*/
|
|
53
|
+
getTools?: () => readonly AiTool[] | undefined;
|
|
54
|
+
/** 获取工具兜底执行体(注册表无 `execute` 时接管) */
|
|
55
|
+
getOnToolCall?: () => AiToolExecutor | undefined;
|
|
56
|
+
/** 获取工具循环轮数上限(不传 = 库默认 10) */
|
|
57
|
+
getMaxSteps?: () => number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* 获取 wire 序列化器(`AiMessage[]` → `body.messages[]`),不传 = `toOpenAIMessages`。
|
|
60
|
+
* ----
|
|
61
|
+
* 走 getter 与其余入参同口径(直值会在 setup 期定格)。
|
|
62
|
+
*/
|
|
63
|
+
getMessagesSerializer?: () => SenderHistorySerializer | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* 获取 sse url(OpenAI Chat Completions 端点)——可选(消费方可能未配);
|
|
66
|
+
* 缺失时 handleSubmit 提示「未配置 SSE 端点」且不发起请求。
|
|
67
|
+
* ----
|
|
68
|
+
* 走 getter 而非直值:直值会在 setup 期定格,消费方运行期切端点(多环境 / 灰度 /
|
|
69
|
+
* mock 与真实后端切换)会**静默失效**——请求仍打向旧地址。与 `getHeaders` /
|
|
70
|
+
* `getBody` / `getHistoryLimit` 同口径。
|
|
71
|
+
*/
|
|
72
|
+
getSseUrl?: () => string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* 获取「是否按 `</think>` 切分正文为思考段」(默认 `false`)。
|
|
75
|
+
* ----
|
|
76
|
+
* 0.3.0 前此值硬编码为 `true`、无开关;它与结构化 `reasoning` part 是同一件事的
|
|
77
|
+
* 两条路,默认开会与后者双轨。走 getter 与其余入参同口径。
|
|
78
|
+
*/
|
|
79
|
+
getShowThink?: () => boolean | undefined;
|
|
80
|
+
/** 更新消息 */
|
|
81
|
+
changeMessage: (item: Required<Pick<T, "uuid">> & Partial<Omit<T, "uuid">>) => void;
|
|
82
|
+
}
|
|
83
|
+
/** 应用 输入框 作用域 */
|
|
84
|
+
export declare const useSenderScoped: <T extends XBubbleListItemProps = XBubbleListItemProps>({ addBubble, getSseUrl, getBubbleList, getHeaders, getBody, getHistoryLimit, getTools, getOnToolCall, getMaxSteps, getMessagesSerializer, getShowThink, converter, changeMessage, }: AiSenderScopedOptions<T>) => {
|
|
85
|
+
senderValue: import('vue').Ref<string, string>;
|
|
86
|
+
placeholder: string;
|
|
87
|
+
autoSizeOptions: import('vue').ComputedRef<{
|
|
88
|
+
minRows: number;
|
|
89
|
+
maxRows: number;
|
|
90
|
+
}>;
|
|
91
|
+
submitBtnDisabled: import('vue').ComputedRef<boolean>;
|
|
92
|
+
isResponding: import('vue').ComputedRef<boolean>;
|
|
93
|
+
message: import('element-plus/es/utils/index.mjs').SFCInstallWithContext<import('element-plus').Message>;
|
|
94
|
+
typingMsgCtrl: import('vue').ComputedRef<Pick<XBubbleListItemProps, "uuid"> | undefined>;
|
|
95
|
+
fixBugCls: string;
|
|
96
|
+
noScrollAnimation: import('vue').ComputedRef<boolean>;
|
|
97
|
+
historyRenderScrollShield: () => void;
|
|
98
|
+
setTypingMsgCtrl: (item?: T) => void;
|
|
99
|
+
handleSubmit: (valueInit: string, options?: AiSenderSubmitOptions) => void;
|
|
100
|
+
handleCancel: () => void;
|
|
101
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { XConversationItem } from '../types';
|
|
3
|
+
import { AiDb } from './storage';
|
|
4
|
+
/** 创建新会话信息 */
|
|
5
|
+
export declare const createNewSessionInfo: () => XConversationItem;
|
|
6
|
+
/**
|
|
7
|
+
* `useSessionListScoped` 的返回面(**[MUST] 显式声明,[MUST NOT] 交给类型推断**)。
|
|
8
|
+
* ----
|
|
9
|
+
* 推断出的返回类型会把 `XConversationItem` 结构展开,展开后的嵌套 element-plus 类型
|
|
10
|
+
* 需要 `vue-router` 才能命名——而本包不依赖 vue-router,于是 `vite-plugin-dts` 抛
|
|
11
|
+
* TS2742 并**静默跳过** `session-list.d.ts`:`pnpm build` 仍然打印 ✓(假绿),
|
|
12
|
+
* 下游 import 该 hook 时才炸 TS2305。显式类型让 d.ts 只引用可命名的别名,永久免疫。
|
|
13
|
+
*/
|
|
14
|
+
export interface AiSessionListScoped {
|
|
15
|
+
/** 历史会话加载中 */
|
|
16
|
+
isLoadMoreLoading: ComputedRef<boolean>;
|
|
17
|
+
/** 历史会话已加载完 */
|
|
18
|
+
isLoadMoreFinished: ComputedRef<boolean>;
|
|
19
|
+
/** 加载下一页历史会话 */
|
|
20
|
+
loadMore: () => Promise<XConversationItem[]>;
|
|
21
|
+
/** 激活的会话 id */
|
|
22
|
+
activeSessionId: Ref<string | undefined>;
|
|
23
|
+
/** 展示的会话列表(内存 + 历史,按最后消息时间倒序) */
|
|
24
|
+
sessionList: ComputedRef<Readonly<XConversationItem[]>>;
|
|
25
|
+
/** 已渲染的会话列表 */
|
|
26
|
+
renderSessionList: ComputedRef<XConversationItem[]>;
|
|
27
|
+
/** 含预留虚拟会话的完整列表 */
|
|
28
|
+
fullSessionList: ComputedRef<XConversationItem[]>;
|
|
29
|
+
/** 新增会话(已存在则忽略) */
|
|
30
|
+
unshiftSession: (session: XConversationItem) => void;
|
|
31
|
+
/** 更新会话 */
|
|
32
|
+
changeSession: (session: XConversationItem) => void;
|
|
33
|
+
/** 预留的虚拟会话信息 */
|
|
34
|
+
virtualSessionInfo: Ref<XConversationItem>;
|
|
35
|
+
}
|
|
36
|
+
export declare const useSessionListScoped: (db?: AiDb) => AiSessionListScoped;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { AiChatCompletionMessage, AiSSEHeaders, AiMessagePart, AiOpenAIDeltaToolCall, AiSSEConverter, AiSSEFrame, XBubbleListItemProps } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* ai 对话的 SSE 通信(OpenAI Chat Completions 传输层 + 业务转换层 · C 阶段去耦)
|
|
4
|
+
* ============================================================================
|
|
5
|
+
* 分两块(spec REQ-3):
|
|
6
|
+
* ① 传输协议层(通用 · 业务无关):POST body 构造(内置 `{ model, messages, stream:true }`
|
|
7
|
+
* 可经 `body` 浅合并覆盖;`messages` 未传则回落单轮)+ 请求头(内置 Content-Type 可经
|
|
8
|
+
* `headers` 覆盖,函数形态支持异步求值)+ SSE 帧解析(`data: JSON` + `[DONE]`)+
|
|
9
|
+
* `choices[0].delta.content` 累积 + `finish_reason`;`delta.tool_calls` 增量解析进
|
|
10
|
+
* 归一化帧(立结构,不做调用逻辑)。
|
|
11
|
+
* ② 业务转换层(业务方注入):`converter(frame: AiSSEFrame) => AiMessagePart[]`——
|
|
12
|
+
* 逐帧增量调用;缺省恒等(content → AiTextPart)。
|
|
13
|
+
* 业务数据通道:content 混 markdown / 自定义 SSE 事件(raw)/ delta 扩展字段。
|
|
14
|
+
* ============================================================================
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 解析 SSE 数据行 → 归一化帧。
|
|
18
|
+
* ----
|
|
19
|
+
* 兼容两种输入:ⓐ 原始行 `data: <payload>`;ⓑ 已剥前缀的纯 payload
|
|
20
|
+
* (vue-element-plus-x `useXStream` 的 splitPart 已把 `data: xxx` 解析为 `{ data: xxx }`)。
|
|
21
|
+
* `[DONE]` → done 帧;空行/注释行/非法 JSON → null(忽略)。
|
|
22
|
+
*/
|
|
23
|
+
export declare const parseSSEEventLine: (line: string) => AiSSEFrame | null;
|
|
24
|
+
/**
|
|
25
|
+
* 解析 OpenAI Chat Completions chunk → 归一化帧。
|
|
26
|
+
* ----
|
|
27
|
+
* `{ choices: [{ delta: { content?, tool_calls? }, finish_reason? }] }`——
|
|
28
|
+
* delta.content 增量、delta.tool_calls 增量(REQ-4)、finish_reason;raw 保留原文(业务自定义字段通道)。
|
|
29
|
+
*/
|
|
30
|
+
export declare const parseOpenAIChunk: (json: unknown) => AiSSEFrame;
|
|
31
|
+
/** 合并后的工具调用(delta.tool_calls 增量按 index 锚合并)。 */
|
|
32
|
+
export interface AiMergedToolCall {
|
|
33
|
+
/** 增量锚 index */
|
|
34
|
+
index: number;
|
|
35
|
+
/** 工具调用 id(首个非空帧;续轮 tool 消息的 tool_call_id) */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** 函数名(首个非空帧) */
|
|
38
|
+
name?: string;
|
|
39
|
+
/** 参数片段拼接(流式完整后为 JSON 字符串) */
|
|
40
|
+
arguments?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 合并 `delta.tool_calls` 增量(REQ-4 铺路)。
|
|
44
|
+
* ----
|
|
45
|
+
* 同一 index 的增量合并为单条(id / name 取首个非空、arguments 逐帧拼接);
|
|
46
|
+
* 状态机推进(input-streaming → input-available)与渲染由业务转换器/消费方负责,
|
|
47
|
+
* 本函数只做纯合并(不做调用逻辑、不接线)。
|
|
48
|
+
*
|
|
49
|
+
* `name` / `arguments` 从 wire 的 `delta.function` 下读取([MUST NOT] 读顶层同名字段
|
|
50
|
+
* ——真实端点不存在,2026-08-25 修正的历史 bug)。
|
|
51
|
+
*
|
|
52
|
+
* @param seed 已累积结果(跨帧续接用):新增量在其之上继续合并,`arguments` 接着拼。
|
|
53
|
+
* [MUST NOT] 修改入参(seed 逐条浅拷贝)。
|
|
54
|
+
*/
|
|
55
|
+
export declare const mergeToolCallsDeltas: (deltas: AiOpenAIDeltaToolCall[], seed?: AiMergedToolCall[]) => AiMergedToolCall[];
|
|
56
|
+
/**
|
|
57
|
+
* 解析工具调用参数(wire 上是 JSON 字符串,流式期间可能是半截)。
|
|
58
|
+
* ----
|
|
59
|
+
* 空串 → `{}`(无参工具);非法 JSON → **原样返回该字符串**([MUST NOT] 抛错吞掉
|
|
60
|
+
* 现场:解析失败要让上层落进 `output-error` 并把原文回发给模型自纠,而不是静默变 `{}`)。
|
|
61
|
+
*/
|
|
62
|
+
export declare const parseAiToolArguments: (raw?: string) => unknown;
|
|
63
|
+
/**
|
|
64
|
+
* 默认转换器:content → AiTextPart + reasoningContent → AiReasoningPart(streaming 态);
|
|
65
|
+
* toolCalls 不消费(业务转换器按需映射)。
|
|
66
|
+
* ----
|
|
67
|
+
* reasoning 先于 text(DeepSeek wire:思维链段先行、正文段接续),增量合并见
|
|
68
|
+
* `applyParts` 的 D9 口径(streaming 态 reasoning 并进同一 part)。
|
|
69
|
+
*/
|
|
70
|
+
export declare const defaultSSEConverter: AiSSEConverter;
|
|
71
|
+
/**
|
|
72
|
+
* 按 `id` upsert 消息 parts(纯函数)。
|
|
73
|
+
* ----
|
|
74
|
+
* 流式下转换器会逐帧吐出**同一个** tool-call part(`AiToolPart.id` 为锚)。若一律追加会
|
|
75
|
+
* 堆出 N 条重复 part,且五态状态机(input-streaming → input-available → output-*)
|
|
76
|
+
* 无法推进。故:
|
|
77
|
+
* - part 带非空 `id` 且命中已有同 id → **浅合并覆盖**(后到字段覆盖先到,未带的字段保留);
|
|
78
|
+
* - 无 `id` 或未命中 → 追加。
|
|
79
|
+
*
|
|
80
|
+
* 现仅 `AiToolPart` 带 `id`,其余 part(text / reasoning / file / data-*)行为不变。
|
|
81
|
+
* [MUST NOT] 修改入参(返回新数组)。
|
|
82
|
+
*/
|
|
83
|
+
export declare const upsertAiMessageParts: (parts: AiMessagePart[], incoming: AiMessagePart[]) => AiMessagePart[];
|
|
84
|
+
/** ai 对话的 SSE 通信选项 */
|
|
85
|
+
export interface AiSSEOptions<T extends XBubbleListItemProps = XBubbleListItemProps> {
|
|
86
|
+
/** 当前聊天气泡项(只读;经 changeMessage 增量更新) */
|
|
87
|
+
message: Readonly<T>;
|
|
88
|
+
/** 输入内容(未传 `messages` 时用作 OpenAI body.messages 的单条 user content) */
|
|
89
|
+
input: string;
|
|
90
|
+
/** sse url(OpenAI Chat Completions 端点) */
|
|
91
|
+
sseUrl: string;
|
|
92
|
+
/**
|
|
93
|
+
* 模型标识(OpenAI `body.model`)——**可选**。
|
|
94
|
+
* ----
|
|
95
|
+
* 0.3.0 起放宽为可选:此前必填是因为组件持有一份模型清单(「智能体 → 执行目标」
|
|
96
|
+
* 分类学)并把选中项灌进来;该分类学已移除,模型改由消费方经 `body`/`sseBody` 提供。
|
|
97
|
+
*
|
|
98
|
+
* 不传时**无需特殊处理**:请求体构造为 `{ model: undefined, …, ...body }`,
|
|
99
|
+
* `body.model` 会覆盖它;两边都没有时 `JSON.stringify` 直接省略该键(实测
|
|
100
|
+
* `{"messages":[],"stream":true}`)。注意多数网关要求 `model`,缺失会 400。
|
|
101
|
+
*/
|
|
102
|
+
model?: string;
|
|
103
|
+
/**
|
|
104
|
+
* 附加 / 覆盖请求头。
|
|
105
|
+
* ----
|
|
106
|
+
* 与内置 `{ "Content-Type": "application/json" }` 浅合并,**同名键由本项覆盖**。
|
|
107
|
+
* 函数形态(可异步)在每轮发起前求值一次——鉴权 token 需刷新时用它。
|
|
108
|
+
* 不传 = 只发内置头(**不带 `Authorization`**)。
|
|
109
|
+
*/
|
|
110
|
+
headers?: AiSSEHeaders | (() => AiSSEHeaders | Promise<AiSSEHeaders>);
|
|
111
|
+
/**
|
|
112
|
+
* 完整 messages(OpenAI wire 形状,**含本轮**)。
|
|
113
|
+
* ----
|
|
114
|
+
* 不传 = 回落 `[{ role: "user", content: input }]`(单轮)。
|
|
115
|
+
* 本层是传输协议层(业务无关)故收 wire 形状;`AiMessage[]` → wire 走公开纯函数
|
|
116
|
+
* `toOpenAIMessages`。
|
|
117
|
+
*/
|
|
118
|
+
messages?: AiChatCompletionMessage[];
|
|
119
|
+
/**
|
|
120
|
+
* 附加 / 覆盖请求 body 字段。
|
|
121
|
+
* ----
|
|
122
|
+
* 与内置 `{ model, messages, stream: true }` 浅合并,**同名键由本项覆盖**。
|
|
123
|
+
* `tools` / `tool_choice` / `temperature` / `response_format` 等一律走此口,
|
|
124
|
+
* [MUST NOT] 为它们逐字段开一等参数(`tools` 之名留给后续工具注册表)。
|
|
125
|
+
*/
|
|
126
|
+
body?: Record<string, unknown>;
|
|
127
|
+
/** 业务转换器(缺省恒等:content → AiTextPart) */
|
|
128
|
+
converter?: AiSSEConverter;
|
|
129
|
+
/**
|
|
130
|
+
* 正文种子(续轮用)。
|
|
131
|
+
* ----
|
|
132
|
+
* `content` 是**全量覆盖**语义(`changeMessage({content})`),而每个 `useAiSSE` 实例的
|
|
133
|
+
* 累积器从 `""` 起——工具循环第二轮若不给种子会把第一轮正文冲掉。单轮调用无需传。
|
|
134
|
+
*/
|
|
135
|
+
initialContent?: string;
|
|
136
|
+
/** 非文本 parts 种子(续轮用;同 `initialContent` 之理,按 id upsert 续接) */
|
|
137
|
+
initialParts?: AiMessagePart[];
|
|
138
|
+
/**
|
|
139
|
+
* parts 正文偏移种子(续轮用,与 `initialParts` 平行;q21yfk 方案 B)。
|
|
140
|
+
* ----
|
|
141
|
+
* 工具循环跨步续接时 [MUST] 与 `initialParts` 成对传——只传 parts 不传偏移会让
|
|
142
|
+
* 第二轮起的偏移数组与 parts 长度错位、时序渲染整体退回旧序。
|
|
143
|
+
*/
|
|
144
|
+
initialPartOffsets?: number[];
|
|
145
|
+
/**
|
|
146
|
+
* 是否由本层直接把 `delta.tool_calls` 投影成 `tool-call` part(默认 `false`)。
|
|
147
|
+
* ----
|
|
148
|
+
* 开 = 本层持**跨帧累加器**(id / name 只在首帧出现),逐帧吐 `input-streaming`、
|
|
149
|
+
* 流结束翻 `input-available`;业务转换器不必再自持 `index → {id,name}` 种子。
|
|
150
|
+
* 关 = 维持既有行为(转换器全权负责),[MUST] 保持默认关以免与消费方自造 part id 撞条。
|
|
151
|
+
*/
|
|
152
|
+
projectToolCallParts?: boolean;
|
|
153
|
+
/** 完成回调 */
|
|
154
|
+
finish: (symbol: Symbol) => void;
|
|
155
|
+
/** 更新消息内容(content 字段高频走防抖) */
|
|
156
|
+
changeMessage: (patch: Partial<Omit<XBubbleListItemProps, "uuid">>,
|
|
157
|
+
/**
|
|
158
|
+
* 是否是改变 content 字段
|
|
159
|
+
* ---
|
|
160
|
+
* 高频走防抖
|
|
161
|
+
*/
|
|
162
|
+
isChangeContent?: boolean) => void;
|
|
163
|
+
}
|
|
164
|
+
/** ai对话中的SSE(OpenAI 协议) */
|
|
165
|
+
export declare const useAiSSE: <T extends XBubbleListItemProps = XBubbleListItemProps>({ message, input, sseUrl, model, headers, messages, body, converter, initialContent, initialParts, initialPartOffsets, projectToolCallParts, finish, changeMessage, }: AiSSEOptions<T>) => {
|
|
166
|
+
startSSE: () => Promise<void>;
|
|
167
|
+
symbol: symbol;
|
|
168
|
+
input: string;
|
|
169
|
+
isResponding: import('vue').WritableComputedRef<boolean, boolean>;
|
|
170
|
+
cancel: () => void;
|
|
171
|
+
/** 累积正文(含 `initialContent` 种子)——工具循环续轮取它做下一实例的种子 */
|
|
172
|
+
content: import('vue').Ref<string, string>;
|
|
173
|
+
/** 累积非文本 parts(含 `initialParts` 种子) */
|
|
174
|
+
parts: import('vue').Ref<({
|
|
175
|
+
type: "text";
|
|
176
|
+
text: string;
|
|
177
|
+
} | {
|
|
178
|
+
type: "reasoning";
|
|
179
|
+
text: string;
|
|
180
|
+
state?: "streaming" | "done" | undefined;
|
|
181
|
+
thinkTime?: number | undefined;
|
|
182
|
+
} | {
|
|
183
|
+
type: "tool-call";
|
|
184
|
+
id: string;
|
|
185
|
+
name: string;
|
|
186
|
+
state: import('..').AiToolCallState;
|
|
187
|
+
input?: unknown;
|
|
188
|
+
output?: unknown;
|
|
189
|
+
errorText?: string | undefined;
|
|
190
|
+
} | {
|
|
191
|
+
type: "file";
|
|
192
|
+
mediaType: string;
|
|
193
|
+
filename?: string | undefined;
|
|
194
|
+
url?: string | undefined;
|
|
195
|
+
} | {
|
|
196
|
+
type: `data-${string}`;
|
|
197
|
+
data: unknown;
|
|
198
|
+
})[], AiMessagePart[] | ({
|
|
199
|
+
type: "text";
|
|
200
|
+
text: string;
|
|
201
|
+
} | {
|
|
202
|
+
type: "reasoning";
|
|
203
|
+
text: string;
|
|
204
|
+
state?: "streaming" | "done" | undefined;
|
|
205
|
+
thinkTime?: number | undefined;
|
|
206
|
+
} | {
|
|
207
|
+
type: "tool-call";
|
|
208
|
+
id: string;
|
|
209
|
+
name: string;
|
|
210
|
+
state: import('..').AiToolCallState;
|
|
211
|
+
input?: unknown;
|
|
212
|
+
output?: unknown;
|
|
213
|
+
errorText?: string | undefined;
|
|
214
|
+
} | {
|
|
215
|
+
type: "file";
|
|
216
|
+
mediaType: string;
|
|
217
|
+
filename?: string | undefined;
|
|
218
|
+
url?: string | undefined;
|
|
219
|
+
} | {
|
|
220
|
+
type: `data-${string}`;
|
|
221
|
+
data: unknown;
|
|
222
|
+
})[]>;
|
|
223
|
+
/** parts 正文偏移(与 parts 平行;工具循环续轮取它做下一实例的种子) */
|
|
224
|
+
partOffsets: import('vue').Ref<number[], number[]>;
|
|
225
|
+
/** 跨帧累积的工具调用(`finish_reason:"tool_calls"` 时即待执行清单) */
|
|
226
|
+
toolCalls: import('vue').Ref<{
|
|
227
|
+
index: number;
|
|
228
|
+
id?: string | undefined;
|
|
229
|
+
name?: string | undefined;
|
|
230
|
+
arguments?: string | undefined;
|
|
231
|
+
}[], AiMergedToolCall[] | {
|
|
232
|
+
index: number;
|
|
233
|
+
id?: string | undefined;
|
|
234
|
+
name?: string | undefined;
|
|
235
|
+
arguments?: string | undefined;
|
|
236
|
+
}[]>;
|
|
237
|
+
/** 本轮 `finish_reason` */
|
|
238
|
+
finishReason: import('vue').Ref<string | null | undefined, string | null | undefined>;
|
|
239
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { default as Dexie, EntityTable } from 'dexie';
|
|
2
|
+
import { ComputedRef } from 'vue';
|
|
3
|
+
import { XBubbleListItemProps, XConversationItem } from '../types';
|
|
4
|
+
export type ISessionInfo = Pick<XConversationItem, "id" | "createdAt" | "label" | "lastMsgCreatedAt" | "group" | "msgCount"> & {
|
|
5
|
+
/** 是否删除 */
|
|
6
|
+
isDel: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 存储的消息行。
|
|
10
|
+
* ----
|
|
11
|
+
* ⚠️ 本 `Pick` 只是**类型面**的声明,不是存储面的过滤器:`addMessage` 存的是整条气泡
|
|
12
|
+
* 对象(Dexie 照单全收非索引字段)。`stores()` 串里列的才是索引,改它要升 `.version()`。
|
|
13
|
+
* 故给这里补字段是**纯类型订正**、零 schema 影响——`content` / `parts` 本就一直在库里。
|
|
14
|
+
*/
|
|
15
|
+
export type IMessageInfo = Pick<XBubbleListItemProps, "uuid" | "sessionId" | "role" | "createdAt" | "errorMsg" | "isAborted" | "isFinished" | "thinkTime" | "talkGoalLabel" | "talkGoalValue" | "askInput" | "askUuid" | "showThink" | "replyUuid" | "content" | "parts"> & {
|
|
16
|
+
/** 是否删除 */
|
|
17
|
+
isDel: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** 分页参数 */
|
|
20
|
+
export interface PageParams {
|
|
21
|
+
/** 在某个创建时间之间 */
|
|
22
|
+
beforeCreatedAt: number;
|
|
23
|
+
/** 每页多少条 */
|
|
24
|
+
pageSize: number;
|
|
25
|
+
}
|
|
26
|
+
/** 数据表 */
|
|
27
|
+
declare enum DbTableEnum {
|
|
28
|
+
/** 会话列表 */
|
|
29
|
+
SESSIONS = "sessions",
|
|
30
|
+
/** 信息列表 */
|
|
31
|
+
MESSAGES = "messages"
|
|
32
|
+
}
|
|
33
|
+
export declare class AiDb extends Dexie {
|
|
34
|
+
/** 会话表 */
|
|
35
|
+
[DbTableEnum.SESSIONS]: EntityTable<ISessionInfo, "id">;
|
|
36
|
+
/** 消息表 */
|
|
37
|
+
[DbTableEnum.MESSAGES]: EntityTable<IMessageInfo, "uuid">;
|
|
38
|
+
/**
|
|
39
|
+
* @param key 库标识(通常 = userName,用户数据隔离)
|
|
40
|
+
* @param namespace 命名空间(对齐 bridge 的 namespace 机制,库名 = `${namespace}/ai-db/${key}`)——
|
|
41
|
+
* 组件库不区分环境(无 DEV 后缀),多应用/多环境隔离由消费方传 namespace 实现
|
|
42
|
+
*/
|
|
43
|
+
constructor(key: string, namespace?: string);
|
|
44
|
+
init: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare const createAiDb: (key: string, namespace?: string) => AiDb;
|
|
47
|
+
/** 会话列表存储 */
|
|
48
|
+
export declare const useSessionListStorage: <T extends XConversationItem>(db?: AiDb) => {
|
|
49
|
+
isLoadMoreLoading: ComputedRef<boolean>;
|
|
50
|
+
isLoadMoreFinished: ComputedRef<boolean>;
|
|
51
|
+
list: ComputedRef<T[]>;
|
|
52
|
+
addSession: (session: T) => Promise<string>;
|
|
53
|
+
updateSession: ({ id, ...rest }: Required<Pick<T, "id">> & Partial<Omit<T, "id">>) => Promise<number>;
|
|
54
|
+
deleteSession: ({ id }: Pick<T, "id">) => Promise<void>;
|
|
55
|
+
loadMore: () => Promise<T[]>;
|
|
56
|
+
};
|
|
57
|
+
/** 会话信息列表存储 */
|
|
58
|
+
export declare const useMessageListStorage: <T extends XBubbleListItemProps>({ db, sessionId, }: {
|
|
59
|
+
db?: AiDb;
|
|
60
|
+
sessionId: string;
|
|
61
|
+
}) => {
|
|
62
|
+
isLoadMoreLoading: ComputedRef<boolean>;
|
|
63
|
+
isLoadMoreFinished: ComputedRef<boolean>;
|
|
64
|
+
list: ComputedRef<T[]>;
|
|
65
|
+
addMessage: (message: T) => Promise<string>;
|
|
66
|
+
updateMessage: ({ uuid, ...rest }: Required<Pick<T, "uuid">> & Partial<Omit<T, "uuid">>) => Promise<number>;
|
|
67
|
+
deleteMessage: ({ uuid }: Pick<T, "uuid">) => Promise<void>;
|
|
68
|
+
loadMore: () => Promise<T[]>;
|
|
69
|
+
};
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 移动端密度 token registry(移动端适配单一真相源 · T1)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 规则 6 框定:所有 `--dc-agent-*` 默认值仍在本文件(theme 模块)定义。registry 把
|
|
5
|
+
* 「随密度可缩放 / 保物理像素 / 视口量」三类 token 的 PC 默认值 + 移动档派生规则集中声明,
|
|
6
|
+
* 供 `useAgentUiDensity()`(hooks/use-density.ts)**只消费不再手写常量表**——避免定义源
|
|
7
|
+
* 分裂到 hook(design §3.2 / §4.1)。
|
|
8
|
+
*
|
|
9
|
+
* 单位策略(design §4.1 像素分界):
|
|
10
|
+
* - `scale`:随密度等比缩放。`useAgentUiDensity` 按单一 `scale = agentRemPx / REFERENCE_REM_PX`
|
|
11
|
+
* 把移动档值算成**绝对 px** = `basePx * scale`,由 scope 上的 hook(父级)统一写入。
|
|
12
|
+
* **[MUST NOT] 用 `em`**:`em` 在非 font-size 属性上相对**消费元素自身 font-size** 解析、
|
|
13
|
+
* 父级 scope 管不到、且逐层级联不可控(曾用 em → height/touch-target 渲染错位)。
|
|
14
|
+
* - `keep-px`:保物理像素(1px hairline 等比缩放会亚像素发虚;focus-ring 宽度),hook **不缩放**。
|
|
15
|
+
* - `viewport`:视口量(panel-width/height/radius),移动档直给字面值 `mobileValue`。
|
|
16
|
+
*
|
|
17
|
+
* unmount 复位:hook 采「记录-恢复」(记录写前的 scope 内联旧值并还原,避免误删外部 inline
|
|
18
|
+
* style);`pcDefault` 同时是「无移动覆盖时」的回退目标(来自 :root body 默认声明)。
|
|
19
|
+
*/
|
|
20
|
+
export type AgentUiTokenUnit = "scale" | "keep-px" | "viewport";
|
|
21
|
+
export interface AgentUiDensityToken {
|
|
22
|
+
/** CSS 自定义属性名(含 `--` 前缀;规则 6:仅 `--dc-agent-*`) */
|
|
23
|
+
cssVar: string;
|
|
24
|
+
/** PC 默认档值(写入 `:root body` 默认声明;亦为复位回退目标) */
|
|
25
|
+
pcDefault: string;
|
|
26
|
+
/** 单位策略:scale 等比(→绝对 px)/ keep-px 保 px / viewport 视口字面值 */
|
|
27
|
+
unit: AgentUiTokenUnit;
|
|
28
|
+
/** scale 专用:设计基准像素 → 移动档绝对 px = `basePx * (agentRemPx / REFERENCE_REM_PX)` */
|
|
29
|
+
basePx?: number;
|
|
30
|
+
/** viewport 专用:移动档字面值(如 `100vw` / `100svh` / `0` / `100%`) */
|
|
31
|
+
mobileValue?: string;
|
|
32
|
+
}
|
|
33
|
+
/** 等比设计基准(= 390 设计宽 / 10):缩放因子 `scale = agentRemPx / REFERENCE_REM_PX`(390 竖屏 scale=1)。 */
|
|
34
|
+
export declare const REFERENCE_REM_PX = 39;
|
|
35
|
+
export declare const AGENT_UI_DENSITY_TOKENS: readonly AgentUiDensityToken[];
|
|
36
|
+
/** ai模块主题 */
|
|
37
|
+
export declare const useAiModuleTheme: (getIsDark: () => boolean) => void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { REFERENCE_REM_PX } from './theme';
|
|
3
|
+
/**
|
|
4
|
+
* agent-ui 移动端密度驱动 hook(scoped-rem · 移动端适配 T2)
|
|
5
|
+
* ============================================================================
|
|
6
|
+
* design §3.2 / §4.1 / §5.1:JS 判设备(iPad/iPhone/Android/HarmonyOS)→ 移动端时把
|
|
7
|
+
* `AGENT_UI_DENSITY_TOKENS` registry 的移动档应用到 **agent-ui 根 scope 节点**:
|
|
8
|
+
* ① 算 `agentRemPx`(clamp + 设备 cap 矩阵)→ 单一缩放因子 `scale = agentRemPx / REFERENCE_REM_PX`;
|
|
9
|
+
* ② 设 scope **局部 `font-size`** = 缩放后基准正文 px(让无显式 token 的继承文本随档缩放,
|
|
10
|
+
* **不碰 documentElement、不污染宿主**);
|
|
11
|
+
* ③ `scale` token 写**绝对 px** = `basePx * scale`(由父级 scope hook 统一掌控,**不用 `em`**——
|
|
12
|
+
* em 在非 font-size 属性上相对消费元素自身 font-size 解析、父级管不到且级联不可控)、
|
|
13
|
+
* viewport token 写字面值、keep-px 不改写。
|
|
14
|
+
* 监听 resize / orientationchange 重设;unmount **记录-恢复**(还原 hook 写过的旧值,
|
|
15
|
+
* 不清空 scope.style,避免误删外部 inline style)。
|
|
16
|
+
*
|
|
17
|
+
* 规则 6:hook **只消费 registry**(design §3.2),不手写 token 常量表——定义源单一在 theme 模块。
|
|
18
|
+
*/
|
|
19
|
+
export { REFERENCE_REM_PX };
|
|
20
|
+
/** 设备档:phone / ipad 走移动 scoped-rem;pc 不适配(保 PC 默认档)。 */
|
|
21
|
+
export type DeviceKind = "phone" | "ipad" | "pc";
|
|
22
|
+
/** 设备判定 override:auto = UA 判定;mobile/desktop 强制。 */
|
|
23
|
+
export type DensityMode = "auto" | "mobile" | "desktop";
|
|
24
|
+
/** 设备探针(依赖注入,便于纯函数判定 + 单测,不直接耦合 navigator)。 */
|
|
25
|
+
export interface DeviceProbe {
|
|
26
|
+
/** navigator.userAgent */
|
|
27
|
+
userAgent: string;
|
|
28
|
+
/** navigator.userAgentData?.mobile(UA-CH,可能 undefined) */
|
|
29
|
+
uaDataMobile?: boolean;
|
|
30
|
+
/** navigator.maxTouchPoints(iPadOS 13+ 伪装辨识) */
|
|
31
|
+
maxTouchPoints: number;
|
|
32
|
+
}
|
|
33
|
+
/** rem 基准下限(过窄视口兜底)。 */
|
|
34
|
+
export declare const REM_MIN_PX = 16;
|
|
35
|
+
/**
|
|
36
|
+
* 设备 cap 矩阵(design §5.1:横屏/iPad 独立上限防过大)
|
|
37
|
+
* - phone:≈430/10,cap 住超宽手机与横屏放大;
|
|
38
|
+
* - ipad:独立上限(width/10 在平板上达 ~77,会让 UI 巨大)→ 收口为平板合理上限。
|
|
39
|
+
* 注:cap 为可调设计矩阵值,T11 真机 e2e 按设备矩阵校验后定稿。
|
|
40
|
+
*/
|
|
41
|
+
export declare const REM_CAP: {
|
|
42
|
+
readonly phone: 43;
|
|
43
|
+
readonly ipad: 52;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 设备判定(优先级写死、可预测 · design §5.1)
|
|
47
|
+
* ① override → ② UA-CH mobile=true → ③ UA 正则 → ④ iPadOS13 伪装 Macintosh → ⑤ PC 兜底。
|
|
48
|
+
* UA-CH mobile=false 不据此判 PC(iPad 亦为 false)→ 继续 UA/iPad 链。
|
|
49
|
+
*/
|
|
50
|
+
export declare function detectDeviceKind(override: DensityMode, probe: DeviceProbe): DeviceKind;
|
|
51
|
+
/** phone / ipad 走移动 scoped-rem 适配;pc 不适配(类型谓词,便于收窄 cap 计算入参)。 */
|
|
52
|
+
export declare function isMobileKind(kind: DeviceKind): kind is Exclude<DeviceKind, "pc">;
|
|
53
|
+
/**
|
|
54
|
+
* 算 scope 局部 font-size(= em 基准):`clamp(REM_MIN_PX, viewportWidth/10, 设备 cap)`。
|
|
55
|
+
* 仅对移动档(phone/ipad)有意义;pc 不调用。
|
|
56
|
+
*/
|
|
57
|
+
export declare function computeAgentRemPx(kind: Exclude<DeviceKind, "pc">, viewportWidth: number): number;
|
|
58
|
+
export interface UseAgentUiDensityOptions {
|
|
59
|
+
/** 设备判定 override,默认 `auto`(UA 判定)。支持响应式(ref/getter)→ 切换即重设。 */
|
|
60
|
+
mode?: MaybeRefOrGetter<DensityMode>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 把移动档密度应用到 agent-ui 根 scope(见模块头说明)。
|
|
64
|
+
* @param scope agent-ui 根节点 ref(`.ai-dialogue-wrap` / `.ai-message-list` wrapper)
|
|
65
|
+
*/
|
|
66
|
+
export declare function useAgentUiDensity(scope: Ref<HTMLElement | null | undefined>, options?: UseAgentUiDensityOptions): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* 空态「欢迎语 + 输入框」整体垂直居中的几何补偿
|
|
4
|
+
* ============================================================================
|
|
5
|
+
* 空会话时 sender 绝对定位在 `bottom: 50%`,而 `AiSenderHeader`(欢迎语 + 建议卡)
|
|
6
|
+
* 用 `bottom: 100%` 悬在 sender **之上、不占位**。于是「header + sender」这个视觉
|
|
7
|
+
* 整体的重心落在中线以上——要让整体居中,sender 需再向下移 header 高度的一半。
|
|
8
|
+
*
|
|
9
|
+
* header 高度随**快捷问题条数**与**容器宽度**(卡片换行 / 降列)变化,纯 CSS 读不到,
|
|
10
|
+
* 故用 ResizeObserver 实测。
|
|
11
|
+
*
|
|
12
|
+
* 原实现写死 `--dc-agent-space-8 * 2`(64px) 估一个常数:实测 300px 容器 + 3 条建议卡
|
|
13
|
+
* 单列时 header 高约 217px、需补 ~108px,**欠补 44px**(空态整团偏上、下方留大片
|
|
14
|
+
* 空白即此)。条数越多 / 容器越窄,偏得越厉害。
|
|
15
|
+
*
|
|
16
|
+
* 规则 21:ResizeObserver 属过程性资源句柄,[MUST NOT] 铺在组件顶级 setup。
|
|
17
|
+
*/
|
|
18
|
+
export declare const useEmptyStateCenter: (getEl: () => HTMLElement | null | undefined,
|
|
19
|
+
/** 仅空会话态需要补偿;非空态返回 0,观测也随之停掉 */
|
|
20
|
+
enabled: Ref<boolean>) => {
|
|
21
|
+
offsetPx: import('vue').ComputedRef<string>;
|
|
22
|
+
headerHeight: Ref<number, number>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { DensityMode } from './use-density';
|
|
3
|
+
/**
|
|
4
|
+
* agent-ui 移动端键盘避让 inset hook(移动端适配 T5 · design §4.2 / §6)
|
|
5
|
+
* ============================================================================
|
|
6
|
+
* 监听 `visualViewport` → 算键盘占高 → 写 agent-ui 根 scope 的 `--dc-agent-keyboard-inset`
|
|
7
|
+
* (**runtime 更新**,非新定义;token 默认 0px 在 theme.ts 已声明)。sender 布局公式
|
|
8
|
+
* (AiDialogue §6:`bottom = safe-bottom + keyboard-inset`)据此把输入栏顶到键盘之上。
|
|
9
|
+
* 键盘弹起(inset>0)时额外在 scope 打 `data-agent-ui-keyboard-open` 标记,供「空会话态
|
|
10
|
+
* sender 居中」等布局据此切回底部公式(否则 `bottom:50%` 居中会被键盘遮住)。
|
|
11
|
+
*
|
|
12
|
+
* **互斥矩阵(§6.1)**:聚焦后比较 `Δlayout(innerHeight)` vs `Δvisual(visualViewport.height)`:
|
|
13
|
+
* - resizes-content(layout viewport 随键盘 resize,Δlayout≈Δvisual)→ 键盘已被 layout 吸收 →
|
|
14
|
+
* inset 置 0(避免双重避让)。
|
|
15
|
+
* - visual-only(Δlayout≈0、Δvisual>0)→ 需 JS inset 避让。
|
|
16
|
+
*
|
|
17
|
+
* **设备档**:与 `useAgentUiDensity` 同源——按 `mode`(auto/mobile/desktop)+ UA 判设备,仅移动档
|
|
18
|
+
* 启用;`mode` 响应式切换即 attach/detach 复位(保 density override 语义两 hook 一致)。
|
|
19
|
+
* 无 visualViewport(PC/老浏览器)不监听。`scope` 上 inset/标记采「记录-恢复」,卸载/禁用还原
|
|
20
|
+
* 旧值、不误删宿主预置 inline。
|
|
21
|
+
*/
|
|
22
|
+
/** design §6 公式:键盘占高 = layout 视口高 - visualViewport 高 - 其 offsetTop,下限 0。 */
|
|
23
|
+
export declare function computeKeyboardInset(layoutHeight: number, visualViewportHeight: number, visualViewportOffsetTop: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* §6.1 启发式:layout 也随键盘收缩(Δlayout≈Δvisual 且 Δvisual 显著)→ resizes-content 模式
|
|
26
|
+
* → 键盘已被 layout viewport 吸收,JS inset 应置 0。容差默认 12px(地址栏/系统 UI 抖动)。
|
|
27
|
+
*/
|
|
28
|
+
export declare function shouldZeroInsetForResizesContent(deltaLayout: number, deltaVisual: number, tolerance?: number): boolean;
|
|
29
|
+
export interface UseKeyboardInsetOptions {
|
|
30
|
+
/** 设备档 override(与 useAgentUiDensity 同源,默认 auto)。支持响应式。 */
|
|
31
|
+
mode?: MaybeRefOrGetter<DensityMode>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 监听键盘弹起 → 写 scope 的 `--dc-agent-keyboard-inset`(见模块头说明)。
|
|
35
|
+
* @param scope agent-ui 根 scope(与 useAgentUiDensity 同节点)
|
|
36
|
+
*/
|
|
37
|
+
export declare function useKeyboardInset(scope: Ref<HTMLElement | null | undefined>, options?: UseKeyboardInsetOptions): void;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { default as AiDialogue } from './components/dialogue/AiDialogue.vue';
|
|
2
|
+
import { default as AiDialogueWrap } from './components/dialogue/AiDialogueWrap.vue';
|
|
3
|
+
import { default as AiDialogueGroup } from './components/dialogue/AiDialogueGroup.vue';
|
|
4
|
+
import { default as AiConfigProvider } from './components/config/AiConfigProvider.vue';
|
|
5
|
+
import { default as AiMessageList } from './components/dialogue/AiMessageList.vue';
|
|
6
|
+
import { default as AiSender } from './components/sender/AiSender.vue';
|
|
7
|
+
import { default as AiPartRenderer } from './components/bubble/AiPartRenderer.vue';
|
|
8
|
+
export { AiDialogueWrap, AiDialogue, AiDialogueGroup, AiConfigProvider, AiMessageList, AiSender, AiPartRenderer, };
|
|
9
|
+
export type { AiMessage, AiMessageRole, AiMessagePart, AiTextPart, AiReasoningPart, AiToolPart, AiToolCallState, AiFilePart, AiDataPart, AiSenderProps, AiSenderSubmitType, AiSSEFrame, AiSSEConverter, AiOpenAIDeltaToolCall, AiOpenAIToolCall, AiChatCompletionMessage, AiSSEHeaders, AiTool, AiToolCtx, AiToolExecutor, AiAgentStopReason, XConversationItem, AiSessionBaseSimpleInfo, } from './types';
|
|
10
|
+
export { AiToolDeniedError } from './types';
|
|
11
|
+
export { toOpenAIMessages, aiIsDataPart, aiDataPartToWireText } from './types';
|
|
12
|
+
export * from './hooks/sse';
|
|
13
|
+
export * from './hooks/agent';
|
|
14
|
+
export * from './hooks/sender';
|
|
15
|
+
export * from './hooks/bubble-list';
|
|
16
|
+
export * from './hooks/fix-bubble-list-bug';
|
|
17
|
+
export * from './hooks/theme';
|
|
18
|
+
export * from './hooks/CodeXSlot';
|
|
19
|
+
export * from './hooks/session-list';
|
|
20
|
+
export * from './hooks/expose';
|
|
21
|
+
export * from './hooks/SessionExpose';
|
|
22
|
+
export * from './hooks/storage';
|
|
23
|
+
export { default as LlmJsonTrigger } from './components/json-trigger/LlmJsonTrigger.vue';
|
|
24
|
+
export * from './components/json-trigger/types';
|
|
25
|
+
export * from './utils/json-from-llm';
|
|
26
|
+
export * from './utils/request-llm';
|