@somecat/ai-assist-sdk 2.0.2 → 2.0.4
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/ai-assist-sdk.css +1 -1
- package/dist/chunks/{engine-Cu-2TgJb.mjs → engine-CObUibqY.mjs} +4880 -4835
- package/dist/chunks/{index-BIUOuQxJ.mjs → index-CoDHrvxN.mjs} +171 -252
- package/dist/core/services/mode.d.ts +10 -0
- package/dist/core/types/index.d.ts +42 -13
- package/dist/core/utils/index.d.ts +2 -11
- package/dist/core/utils/markdown.d.ts +15 -0
- package/dist/core/utils/streamPlayback.d.ts +9 -58
- package/dist/core/utils/structured.d.ts +0 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +109 -54
- package/dist/react/components/answer/chatStore.d.ts +2 -2
- package/dist/react/components/answer/components/MessageItem.d.ts +0 -5
- package/dist/react/components/answer/components/StepBlock.d.ts +1 -5
- package/dist/react/components/answer/components/StreamingMarkdown.d.ts +1 -8
- package/dist/react/components/answer/components/ThinkingBlock.d.ts +2 -0
- package/dist/react/components/answer/hooks/useScrollManager.d.ts +2 -0
- package/dist/react/components/page/AiChartCard.d.ts +6 -0
- package/dist/react/index.mjs +10375 -10407
- package/dist/vue/components/answer/composables/useChatSessions.d.ts +0 -2
- package/dist/vue/components/answer/composables/useMessagesBatch.d.ts +3 -1
- package/dist/vue/components/answer/composables/useSSEStream.d.ts +2 -2
- package/dist/vue/components/answer/composables/useScrollManager.d.ts +2 -0
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/index.mjs +2357 -2258
- package/package.json +1 -1
- package/dist/chunks/index-DNWBsXlO.mjs +0 -98
- package/dist/react/components/answer/hooks/useMessagePlayback.d.ts +0 -34
- package/dist/react/components/answer/hooks/useStallHint.d.ts +0 -15
- package/dist/vue/components/answer/composables/useMessagePlayback.d.ts +0 -27
- package/dist/vue/components/answer/composables/useStallHint.d.ts +0 -16
|
@@ -7,6 +7,11 @@ import { AiAssistConfig, AiAssistMode, AiAssistPageModeConfig } from '../types';
|
|
|
7
7
|
* - Vue / React 适配层通过 `subscribeAiAssistState` 订阅,读取 `getXxx` 取值。
|
|
8
8
|
*/
|
|
9
9
|
type Listener = () => void;
|
|
10
|
+
export declare const setCurrentConversationId: (id: string) => void;
|
|
11
|
+
export declare const getCurrentConversationId: () => string;
|
|
12
|
+
/** 注入当前登录用户;切换用户时应先调用 resetAiAssistState() 再注入新值 */
|
|
13
|
+
export declare const setAiAssistUserCode: (userCode?: string) => void;
|
|
14
|
+
export declare const getAiAssistUserCode: () => string;
|
|
10
15
|
/** 订阅任意状态变化(mode / visible / context) */
|
|
11
16
|
export declare const subscribeAiAssistState: (fn: Listener) => (() => void);
|
|
12
17
|
export declare const getAiAssistMode: () => AiAssistMode;
|
|
@@ -44,6 +49,11 @@ export declare const refreshAiPanelContext: () => Promise<Record<string, any>>;
|
|
|
44
49
|
export declare const getPageThreadId: (module?: string) => string;
|
|
45
50
|
export declare const setPageThreadId: (threadId: string, module?: string) => void;
|
|
46
51
|
export declare const clearPageThreadId: (module?: string) => void;
|
|
52
|
+
export declare const registerAiAssistResetHook: (fn: () => void) => (() => void);
|
|
53
|
+
/**
|
|
54
|
+
* 账号切换/登出:清掉会话与上下文,但保留形态和宿主配置(SDK 不需要重新挂载)。
|
|
55
|
+
*/
|
|
56
|
+
export declare const resetAiAssistUserData: () => void;
|
|
47
57
|
/** 卸载时重置,避免 HMR / 重新挂载残留 */
|
|
48
58
|
export declare const resetAiAssistState: () => void;
|
|
49
59
|
export {};
|
|
@@ -44,6 +44,8 @@ export interface AiToolState {
|
|
|
44
44
|
name: string;
|
|
45
45
|
status: 'idle' | 'running' | 'done' | 'failed';
|
|
46
46
|
message?: string;
|
|
47
|
+
/** phase=阶段提示(不显示 spinner);tool=工具状态 */
|
|
48
|
+
kind?: 'phase' | 'tool';
|
|
47
49
|
}
|
|
48
50
|
/** page 模式:流式过程中的结构化事件(工具/图表) */
|
|
49
51
|
export type AiStreamEvent = {
|
|
@@ -67,6 +69,16 @@ export type AiStreamEvent = {
|
|
|
67
69
|
type: 'status';
|
|
68
70
|
phase: string;
|
|
69
71
|
message?: string;
|
|
72
|
+
}
|
|
73
|
+
/** 平台原生深度思考片段 */
|
|
74
|
+
| {
|
|
75
|
+
type: 'thought';
|
|
76
|
+
text: string;
|
|
77
|
+
}
|
|
78
|
+
/** 平台工具生命周期说明 */
|
|
79
|
+
| {
|
|
80
|
+
type: 'tool_message';
|
|
81
|
+
message: string;
|
|
70
82
|
};
|
|
71
83
|
/** page 模式:会话状态(刷新后恢复) */
|
|
72
84
|
export interface AiPageStateResult {
|
|
@@ -152,7 +164,10 @@ export interface AiAssistPageModeConfig {
|
|
|
152
164
|
/** 动作执行回调,返回回执驱动卡片状态 */
|
|
153
165
|
onAction?: (action: AiPageAction) => AiPageActionResult | Promise<AiPageActionResult>;
|
|
154
166
|
/** 文件下载回调(宿主负责带鉴权取流并落盘),返回回执驱动卡片状态 */
|
|
155
|
-
onDownloadFile?: (file: AiPageFile
|
|
167
|
+
onDownloadFile?: (file: AiPageFile, context?: {
|
|
168
|
+
conversationId?: string;
|
|
169
|
+
mode?: 'page' | 'default';
|
|
170
|
+
}) => AiPageActionResult | Promise<AiPageActionResult>;
|
|
156
171
|
/** 图表渲染回调:宿主用 echarts.init(el) 渲染(SDK 不引入 echarts) */
|
|
157
172
|
onChartRender?: (chart: AiChartItem, el: HTMLElement) => void | Promise<void>;
|
|
158
173
|
/** 图表下载回调(宿主持有 echarts 实例,可导出 PNG);不提供则隐藏下载按钮 */
|
|
@@ -200,6 +215,15 @@ export interface AiAssistConfig {
|
|
|
200
215
|
onPanelActive?: (info: AiAssistPanelActiveInfo) => void;
|
|
201
216
|
/** 用户发送消息回调(点发送 / 回车 / 语音;「重新生成」不计) */
|
|
202
217
|
onMessageSend?: (info: AiAssistMessageSendInfo) => void;
|
|
218
|
+
/** 顶层图表渲染回调(默认助手与页面模式共用),未配置时回退 pageMode.onChartRender */
|
|
219
|
+
onChartRender?: (chart: AiChartItem, el: HTMLElement) => void | Promise<void>;
|
|
220
|
+
/** 顶层图表下载回调,未配置时回退 pageMode.onChartDownload */
|
|
221
|
+
onChartDownload?: (chart: AiChartItem) => void;
|
|
222
|
+
/** 顶层文件下载回调,未配置时回退 pageMode.onDownloadFile */
|
|
223
|
+
onDownloadFile?: (file: AiPageFile, context?: {
|
|
224
|
+
conversationId?: string;
|
|
225
|
+
mode?: 'page' | 'default';
|
|
226
|
+
}) => AiPageActionResult | Promise<AiPageActionResult>;
|
|
203
227
|
apis: {
|
|
204
228
|
chatQueryApi: string;
|
|
205
229
|
chatQueryStreamApi?: string;
|
|
@@ -275,6 +299,8 @@ export interface MessageSegment {
|
|
|
275
299
|
id?: string;
|
|
276
300
|
/** 是否为推理内容(对话流型 message_config.reasoning === true) */
|
|
277
301
|
reasoning?: boolean;
|
|
302
|
+
/** 该分段开始时刻(毫秒),用于按段结算耗时;内部字段,不展示 */
|
|
303
|
+
startedAt?: number;
|
|
278
304
|
}
|
|
279
305
|
/** 流程步骤展示状态 */
|
|
280
306
|
export type StepState = 'pending' | 'active' | 'done';
|
|
@@ -330,18 +356,6 @@ export interface ChatMessage {
|
|
|
330
356
|
cost?: MessageCost;
|
|
331
357
|
/** agent_error 的错误信息 */
|
|
332
358
|
errorMessage?: string;
|
|
333
|
-
/**
|
|
334
|
-
* 是否由本次会话的实时流产生(需要前端按序逐字揭示)。
|
|
335
|
-
* 后端为批量转发(多事件同一帧到达),终态可能早于渲染,
|
|
336
|
-
* 故不能仅凭 status 判断是否需要动画;历史/降级消息不带此标记,直接全量渲染。
|
|
337
|
-
*/
|
|
338
|
-
streamed?: boolean;
|
|
339
|
-
/**
|
|
340
|
-
* 最近一次收到后端 SSE 数据包的时间戳(毫秒)。
|
|
341
|
-
* 用于识别「伪流式」卡顿:前端已追平已有内容但后端长时间不再发包时,
|
|
342
|
-
* 由渲染层补一条「工具调用中」状态,避免界面呆滞。
|
|
343
|
-
*/
|
|
344
|
-
lastChunkAt?: number;
|
|
345
359
|
/** page 模式:智能体返回的结构化动作 */
|
|
346
360
|
actions?: AiPageAction[];
|
|
347
361
|
/** page 模式:动作执行状态(按动作 key 存储) */
|
|
@@ -356,6 +370,8 @@ export interface ChatMessage {
|
|
|
356
370
|
charts?: AiChartItem[];
|
|
357
371
|
/** page 模式:取数工具执行状态(查询中/完成/失败) */
|
|
358
372
|
toolState?: AiToolState;
|
|
373
|
+
/** page 模式:阶段提示(理解问题/整理结论),与工具结果分开,失败提示不被覆盖 */
|
|
374
|
+
phaseState?: AiToolState;
|
|
359
375
|
}
|
|
360
376
|
/** API 返回的会话列表项(已转 camelCase) */
|
|
361
377
|
export interface ConversationItem {
|
|
@@ -365,6 +381,9 @@ export interface ConversationItem {
|
|
|
365
381
|
createTimestamp: number;
|
|
366
382
|
lastChatTime: string;
|
|
367
383
|
lastChatTimestamp: number;
|
|
384
|
+
/** 新平台:ISO 时间或 Unix 秒(兼容字段) */
|
|
385
|
+
createdAt?: number | string;
|
|
386
|
+
updatedAt?: number | string;
|
|
368
387
|
emptyConversation: boolean;
|
|
369
388
|
isPinned: boolean;
|
|
370
389
|
conversationID: string;
|
|
@@ -400,6 +419,16 @@ export interface ConversationMessageItem {
|
|
|
400
419
|
createdTime?: number;
|
|
401
420
|
/** 兼容字段 */
|
|
402
421
|
createTime?: number;
|
|
422
|
+
/** 新平台:本轮图表 */
|
|
423
|
+
charts?: AiChartItem[];
|
|
424
|
+
/** 新平台:本轮产物文件 */
|
|
425
|
+
files?: AiPageFile[];
|
|
426
|
+
/** 新平台:平台轮次 ID(内部字段,按轮回填用) */
|
|
427
|
+
runTurnId?: string;
|
|
428
|
+
/** 新平台:平台轮次状态(completed / failed / stopped / running / unknown) */
|
|
429
|
+
turnStatus?: string;
|
|
430
|
+
/** 新平台:失败原因(内部字段) */
|
|
431
|
+
errorMessage?: string;
|
|
403
432
|
};
|
|
404
433
|
/** 提问创建时间(部分网关返回,兼容用) */
|
|
405
434
|
createdTime?: number;
|
|
@@ -35,15 +35,6 @@ export declare const looksLikeRawPayload: (text?: string) => boolean;
|
|
|
35
35
|
* 返回空串表示该标题不可用,调用方应跳过更新(保留服务端默认会话名)。
|
|
36
36
|
*/
|
|
37
37
|
export declare const sanitizeConversationTitle: (raw?: string) => string;
|
|
38
|
-
/**
|
|
39
|
-
* 将流式光标拼接到 HTML 最后一个块级元素内部末尾,保证光标跟在文字后而非换行独占一行。
|
|
40
|
-
*
|
|
41
|
-
* 表格处理:markdown-it 对表格几乎总是输出「完整闭合」的 <table>(流式行也会补空 td),
|
|
42
|
-
* 因此光标插入点常落在最后一个闭合标签 </table> 之前 —— 即表格结构内部(表头下方/表格内),
|
|
43
|
-
* 视觉上表现为光标出现在表格上方。故当最后一个块级闭合标签属于表格标签时隐藏光标;
|
|
44
|
-
* 仅当内容以段落/列表/代码块等非表格标签结尾时才正常插入光标。
|
|
45
|
-
*/
|
|
46
|
-
export declare const appendStreamingCursor: (html: string, streaming?: boolean) => string;
|
|
47
38
|
/**
|
|
48
39
|
* 将 GetConversationMessages 返回的消息项按时间**升序**重排(旧 → 新)。
|
|
49
40
|
*
|
|
@@ -59,8 +50,8 @@ export declare const orderConversationMessages: <T extends {
|
|
|
59
50
|
createdTime?: number | string;
|
|
60
51
|
createTime?: number | string;
|
|
61
52
|
}>(items: T[] | undefined | null) => T[];
|
|
62
|
-
export { renderMarkdown, preprocessStreamingMarkdown, stripChartBlocks } from './markdown';
|
|
63
|
-
export {
|
|
53
|
+
export { renderMarkdown, preprocessStreamingMarkdown, stripChartBlocks, parseAnswerBlocks, type AnswerBlock, } from './markdown';
|
|
54
|
+
export { buildMetaBlocks, segmentDuration, sumThinkingDuration } from './streamPlayback';
|
|
64
55
|
export { showToast, type ToastType } from './toast';
|
|
65
56
|
export declare const ensureViewportFit: () => void;
|
|
66
57
|
export interface HistoryGroup {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AiChartItem } from '../types';
|
|
1
2
|
export declare const renderMarkdown: (content: string) => string;
|
|
2
3
|
/**
|
|
3
4
|
* 移除平台图表工具的「正文引用」,避免把 chart_id JSON 当代码块展示。
|
|
@@ -10,6 +11,20 @@ export declare const renderMarkdown: (content: string) => string;
|
|
|
10
11
|
* - 无匹配时原样返回。
|
|
11
12
|
*/
|
|
12
13
|
export declare const stripChartBlocks: (content: string) => string;
|
|
14
|
+
/** 回答正文的有序块:文本或图表引用(按原文顺序渲染) */
|
|
15
|
+
export type AnswerBlock = {
|
|
16
|
+
kind: 'text';
|
|
17
|
+
content: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'chart';
|
|
20
|
+
chartId: string;
|
|
21
|
+
chart?: AiChartItem;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 把正文里的 echarts 引用解析为有序的文本/图卡块。
|
|
25
|
+
* 图表数据可能晚于引用到达:先出占位,数据到达后按同一 chartId 升级为卡片。
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseAnswerBlocks(content: string, charts?: AiChartItem[], fallbackCharts?: boolean): AnswerBlock[];
|
|
13
28
|
/**
|
|
14
29
|
* 预处理流式传输中的不完整 Markdown,避免渲染错乱
|
|
15
30
|
* - 闭合未关闭的代码块 (```)
|
|
@@ -1,62 +1,13 @@
|
|
|
1
1
|
import { MessageSegment, MetaBlock } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
export declare
|
|
2
|
+
/** 按分段自身开始时间结算耗时(秒,保留 1 位小数) */
|
|
3
|
+
export declare function segmentDuration(seg: MessageSegment, now?: number): number;
|
|
4
|
+
/** 思考总耗时由各 thinking 分段派生,避免多处累加重复计时 */
|
|
5
|
+
export declare function sumThinkingDuration(segments: MessageSegment[] | undefined): number;
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
* 即一阶衰减,时间常数越大整体越慢;同时保证「积压有界」——
|
|
7
|
-
* 若后端持续以 R 字/秒产出,稳态积压 ≈ R × TARGET_SEC,不会无限落后。
|
|
8
|
-
*/
|
|
9
|
-
export declare const REVEAL_TARGET_SEC = 1.4;
|
|
10
|
-
/** 速率上限(字/秒):防止超大批量一帧铺满 */
|
|
11
|
-
export declare const REVEAL_MAX_CPS = 1600;
|
|
12
|
-
/**
|
|
13
|
-
* 单个「流程步骤」的最短展示时长(秒)。
|
|
14
|
-
* 大包内往往含多个步骤,若按全局排空速率会被一起冲掉,故对步骤单独限速:
|
|
15
|
-
* 揭示该步骤全部内容至少耗时 STEP_MIN_SEC,使步骤与步骤之间保持可见节奏。
|
|
16
|
-
*/
|
|
17
|
-
export declare const REVEAL_STEP_MIN_SEC = 2;
|
|
18
|
-
/**
|
|
19
|
-
* 伪流式卡顿判定阈值(毫秒)。
|
|
20
|
-
* 前端已把已收到的内容揭示完毕,若这段时间内后端仍未下发新包,
|
|
21
|
-
* 且不处于深度思考 / 工具调用 / 步骤进行中,则补一条「工具调用中」状态占位。
|
|
22
|
-
*/
|
|
23
|
-
export declare const STALL_HINT_DELAY_MS = 2000;
|
|
24
|
-
/** 该分段是否参与逐字揭示 */
|
|
25
|
-
export declare function isRevealableSegment(seg: MessageSegment): boolean;
|
|
26
|
-
/** 按 segments 顺序统计需要揭示的总字符数 */
|
|
27
|
-
export declare function totalRevealLength(segments?: MessageSegment[]): number;
|
|
28
|
-
/**
|
|
29
|
-
* 计算每个分段当前应展示的已揭示内容(与 segments 等长)。
|
|
30
|
-
* 不可揭示的分段(agent_thought)原样返回,便于调用方统一按索引取值。
|
|
31
|
-
*/
|
|
32
|
-
export declare function revealSegmentContents(segments: MessageSegment[] | undefined, reveal: number): string[];
|
|
33
|
-
/** 揭示游标当前所处(尚未揭示完)的分段下标;全部揭示完返回 -1 */
|
|
34
|
-
export declare function findRevealFrontier(segments: MessageSegment[] | undefined, reveal: number): number;
|
|
35
|
-
/** 分段是否已完全揭示 */
|
|
36
|
-
export declare function isSegmentRevealed(segments: MessageSegment[] | undefined, segIdx: number, reveal: number): boolean;
|
|
37
|
-
/** 分段在揭示坐标系中的区间 [start, end)(不可揭示分段返回 [0,0]) */
|
|
38
|
-
export declare function segmentRevealRange(segments: MessageSegment[] | undefined, segIdx: number): {
|
|
39
|
-
start: number;
|
|
40
|
-
end: number;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* 构建「过程内容块」列表。
|
|
7
|
+
* 过程内容块分组(框架无关)。
|
|
44
8
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* tools 无正文,按揭示偏移 gate),从而保证「从上到下逐个出现」。
|
|
49
|
-
*/
|
|
50
|
-
export declare function buildMetaBlocks(segments: MessageSegment[] | undefined, reveal: number): MetaBlock[];
|
|
51
|
-
/**
|
|
52
|
-
* 揭示游标当前所在分段为「流程步骤」时的速率上限(字/秒)。
|
|
53
|
-
* 保证单个步骤的揭示耗时 ≥ REVEAL_STEP_MIN_SEC;非步骤分段返回 Infinity(不额外限速)。
|
|
9
|
+
* 新平台是真实 SSE:正文、思考、工具事件按到达顺序增量写入,
|
|
10
|
+
* 这里只负责把连续的 step / thinking / agent_thought 分段组织成块供 UI 渲染,
|
|
11
|
+
* 不再做任何「逐字揭示 / 二次限速 / 卡顿伪装」。
|
|
54
12
|
*/
|
|
55
|
-
export declare function
|
|
56
|
-
/** 推进一帧揭示进度(返回新的 reveal 与小数累加器,跨帧保留以保证低速率均匀) */
|
|
57
|
-
export declare function advanceReveal(reveal: number, total: number, frac: number, dtMs: number,
|
|
58
|
-
/** 速率上限(字/秒),用于对步骤等分段单独限速;默认不限 */
|
|
59
|
-
cpsCap?: number): {
|
|
60
|
-
reveal: number;
|
|
61
|
-
frac: number;
|
|
62
|
-
};
|
|
13
|
+
export declare function buildMetaBlocks(segments: MessageSegment[] | undefined): MetaBlock[];
|
|
@@ -13,13 +13,5 @@ export interface AiStructuredAnswer {
|
|
|
13
13
|
* 兼容代码围栏与前后噪声;解析失败时整段按纯文本返回,由渲染层走 Markdown,不白屏。
|
|
14
14
|
*/
|
|
15
15
|
export declare const parseStructuredAnswer: (raw: string) => AiStructuredAnswer;
|
|
16
|
-
/**
|
|
17
|
-
* 流式场景下从「尚未闭合的 JSON」里提取 `answer` 字段已到达的部分。
|
|
18
|
-
*
|
|
19
|
-
* - 还没出现 `"answer"`(或是纯文本回答)→ 直接返回原文;
|
|
20
|
-
* - 已出现但内容未到达 → 返回空串,避免把 JSON 骨架显示给用户;
|
|
21
|
-
* - 遇到未完成的转义序列时先不追加,等下一段数据。
|
|
22
|
-
*/
|
|
23
|
-
export declare const extractStreamingAnswer: (raw: string) => string;
|
|
24
16
|
/** 拼装 page 模式的提问内容(上下文块 + 用户原话) */
|
|
25
17
|
export declare const composePageQuery: (question: string, pageContext?: Record<string, any>) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { AiAssistConfig, AiAssistTheme, AiAssistMode, AiAssistPageModeConfig, AiPageAction, AiPageActionResult, AiPageActionState, AiPageTransport, AiPageFile, AiPageHistoryMessage, AiPageStateResult, AiChartItem, AiToolState, AiStreamEvent, ViewStatus, MessageStatus, ChatMessage, ConversationItem, ConversationMessageItem, HistoryItem, ChatSessionMeta, PersonalInfo, } from './core/types';
|
|
2
|
-
export { getAiAssistMode, setAiAssistMode, isAiAssistPageMode, isAiAssistModeLocked, openAiAssist, closeAiAssist, collapsePageAssist, toggleAiAssist, isAiAssistVisible, setAiAssistVisible, refreshAiPanelContext, getPageContextSnapshot, getPageModule, setPageModule, getPageThreadId, setPageThreadId, clearPageThreadId, subscribeAiAssistState, resetAiAssistState, } from './core/services/mode';
|
|
2
|
+
export { getAiAssistMode, setAiAssistMode, isAiAssistPageMode, isAiAssistModeLocked, openAiAssist, closeAiAssist, collapsePageAssist, setAiAssistUserCode, getAiAssistUserCode, resetAiAssistUserData, registerAiAssistResetHook, toggleAiAssist, isAiAssistVisible, setAiAssistVisible, refreshAiPanelContext, getPageContextSnapshot, getPageModule, setPageModule, getPageThreadId, setPageThreadId, clearPageThreadId, subscribeAiAssistState, resetAiAssistState, } from './core/services/mode';
|
|
3
3
|
export { parseStructuredAnswer, composePageQuery } from './core/utils/structured';
|
|
4
4
|
export type { AiStructuredAnswer } from './core/utils/structured';
|
|
5
5
|
export { setConfig, getConfig, request, http, createAuthAxios, } from './core/services/request';
|
package/dist/index.mjs
CHANGED
|
@@ -1,56 +1,111 @@
|
|
|
1
|
-
import { V as
|
|
2
|
-
|
|
1
|
+
import { V as d, I as y, a0 as h, f as S, T, U as C, m as b, h as w, D as P, w as m, n as x, a1 as v, A as M, q as E, W as O, a2 as j, g as I, z, j as N, a3 as k, H as Q, k as U, c as D, E as J, a4 as V, a5 as $, a6 as G, i as X, M as Z, X as _, a7 as F, a8 as H, v as L, F as R, r as K, a9 as W, R as Y, Y as q, O as B, x as ss, N as es, Z as ts, K as as, S as rs, _ as ns, t as is, aa as os, l as cs, G as gs, ab as ls, $ as As, y as fs, u as us, J as ps } from "./chunks/engine-CObUibqY.mjs";
|
|
2
|
+
const o = (e) => {
|
|
3
|
+
const s = e.trim(), a = /^```[a-zA-Z]*\s*\n([\s\S]*?)\n?```$/m.exec(s);
|
|
4
|
+
if (a) return a[1].trim();
|
|
5
|
+
const t = /```[a-zA-Z]*\s*\n([\s\S]*?)\n?```/.exec(s);
|
|
6
|
+
return t ? t[1].trim() : s;
|
|
7
|
+
}, c = (e) => {
|
|
8
|
+
const s = e.indexOf("{");
|
|
9
|
+
if (s < 0) return null;
|
|
10
|
+
let a = 0, t = !1, i = !1;
|
|
11
|
+
for (let r = s; r < e.length; r++) {
|
|
12
|
+
const n = e[r];
|
|
13
|
+
if (t) {
|
|
14
|
+
i ? i = !1 : n === "\\" ? i = !0 : n === '"' && (t = !1);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (n === '"') t = !0;
|
|
18
|
+
else if (n === "{") a++;
|
|
19
|
+
else if (n === "}" && (a--, a === 0))
|
|
20
|
+
return e.slice(s, r + 1);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}, g = (e) => Array.isArray(e) ? e.filter((s) => s && typeof s == "object" && typeof s.type == "string" && s.type.trim()).map((s) => ({
|
|
24
|
+
type: String(s.type).trim(),
|
|
25
|
+
label: typeof s.label == "string" ? s.label : void 0,
|
|
26
|
+
payload: s.payload && typeof s.payload == "object" && !Array.isArray(s.payload) ? s.payload : void 0
|
|
27
|
+
})) : [], l = (e) => Array.isArray(e) ? e.filter((s) => typeof s == "string" && s.trim()).map((s) => s.trim()) : [], A = (e) => {
|
|
28
|
+
const s = (e || "").trim();
|
|
29
|
+
if (!s) return { answer: "", actions: [], suggestions: [] };
|
|
30
|
+
const a = c(o(s));
|
|
31
|
+
if (!a) return { answer: s, actions: [], suggestions: [] };
|
|
32
|
+
try {
|
|
33
|
+
const t = JSON.parse(a);
|
|
34
|
+
if (!t || typeof t != "object") return { answer: s, actions: [], suggestions: [] };
|
|
35
|
+
const i = typeof t.answer == "string" ? t.answer : typeof t.content == "string" ? t.content : "", r = g(t.actions), n = l(t.suggestions);
|
|
36
|
+
return !i && !r.length ? { answer: s, actions: r, suggestions: n } : { answer: i || s, actions: r, suggestions: n };
|
|
37
|
+
} catch {
|
|
38
|
+
return { answer: s, actions: [], suggestions: [] };
|
|
39
|
+
}
|
|
40
|
+
}, f = (e, s) => {
|
|
41
|
+
if (!s || !Object.keys(s).length) return e;
|
|
42
|
+
let a = "";
|
|
43
|
+
try {
|
|
44
|
+
a = JSON.stringify(s);
|
|
45
|
+
} catch {
|
|
46
|
+
return e;
|
|
47
|
+
}
|
|
48
|
+
return `[PAGE_CONTEXT]
|
|
49
|
+
${a}
|
|
50
|
+
[/PAGE_CONTEXT]
|
|
51
|
+
[QUESTION]
|
|
52
|
+
${e}`;
|
|
53
|
+
};
|
|
3
54
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
L as
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
d as VoiceEngine,
|
|
56
|
+
y as applyTheme,
|
|
57
|
+
h as chatQuery,
|
|
58
|
+
S as clearPageThreadId,
|
|
59
|
+
T as closeAiAssist,
|
|
60
|
+
C as collapsePageAssist,
|
|
61
|
+
f as composePageQuery,
|
|
62
|
+
b as createAuthAxios,
|
|
63
|
+
w as createConversation,
|
|
64
|
+
P as deleteConversation,
|
|
65
|
+
m as ensureTitleConversation,
|
|
66
|
+
x as extractAnswerText,
|
|
67
|
+
v as extractPlainText,
|
|
68
|
+
M as formatQuestions,
|
|
69
|
+
E as getAiAssistMode,
|
|
70
|
+
O as getAiAssistUserCode,
|
|
71
|
+
j as getAppConfig,
|
|
72
|
+
I as getConfig,
|
|
73
|
+
z as getConversationList,
|
|
74
|
+
N as getConversationMessages,
|
|
75
|
+
k as getMessageInfo,
|
|
76
|
+
Q as getPageContextSnapshot,
|
|
77
|
+
U as getPageModule,
|
|
78
|
+
D as getPageThreadId,
|
|
79
|
+
J as getPersonalInfo,
|
|
80
|
+
V as getSuggestedQuestions,
|
|
81
|
+
$ as http,
|
|
82
|
+
G as isAiAssistModeLocked,
|
|
83
|
+
X as isAiAssistPageMode,
|
|
84
|
+
Z as isAiAssistVisible,
|
|
85
|
+
_ as openAiAssist,
|
|
86
|
+
F as parseSSEData,
|
|
87
|
+
A as parseStructuredAnswer,
|
|
88
|
+
H as processSSEData,
|
|
89
|
+
L as refreshAiPanelContext,
|
|
90
|
+
R as registerAiAssistResetHook,
|
|
91
|
+
K as renderMarkdown,
|
|
92
|
+
W as request,
|
|
93
|
+
Y as resetAiAssistState,
|
|
94
|
+
q as resetAiAssistUserData,
|
|
95
|
+
B as resolveTheme,
|
|
96
|
+
ss as sanitizeConversationTitle,
|
|
97
|
+
es as setAiAssistMode,
|
|
98
|
+
ts as setAiAssistUserCode,
|
|
99
|
+
as as setAiAssistVisible,
|
|
100
|
+
rs as setConfig,
|
|
101
|
+
ns as setPageModule,
|
|
102
|
+
is as setPageThreadId,
|
|
103
|
+
os as statusText,
|
|
104
|
+
cs as stopMessage,
|
|
105
|
+
gs as subscribeAiAssistState,
|
|
106
|
+
ls as textError,
|
|
107
|
+
As as toggleAiAssist,
|
|
108
|
+
fs as updateConversation,
|
|
109
|
+
us as useClipboard,
|
|
110
|
+
ps as watchSystemTheme
|
|
56
111
|
};
|
|
@@ -49,8 +49,6 @@ export declare class ChatSession {
|
|
|
49
49
|
updatedAt: number;
|
|
50
50
|
/** 是否已手动停止当前生成 */
|
|
51
51
|
stopped: boolean;
|
|
52
|
-
/** 逐字揭示进度:消息下标 → 已揭示字符数(切回会话时恢复,避免重放整段动画) */
|
|
53
|
-
readonly reveal: Map<number, number>;
|
|
54
52
|
sendMessage: () => Promise<void>;
|
|
55
53
|
regenerateResponse: () => Promise<void>;
|
|
56
54
|
toggleStop: () => Promise<void>;
|
|
@@ -88,6 +86,8 @@ export declare class ChatStore {
|
|
|
88
86
|
subscribe: (listener: () => void) => () => void;
|
|
89
87
|
getSnapshot: () => ChatStoreSnapshot;
|
|
90
88
|
get activeSession(): ChatSession | undefined;
|
|
89
|
+
/** 会话消息批量写入完成后调用:只有当前展示会话才按门闩滚底 */
|
|
90
|
+
onSessionBatchApplied(uid: string): void;
|
|
91
91
|
/** 切换展示会话 */
|
|
92
92
|
activate(uid: string): void;
|
|
93
93
|
/** 新建对话:复用一个空草稿会话,避免堆积无用会话 */
|
|
@@ -2,12 +2,7 @@ import { ChatMessage } from '../../../../core/types';
|
|
|
2
2
|
interface MessageItemProps {
|
|
3
3
|
msg: ChatMessage;
|
|
4
4
|
index: number;
|
|
5
|
-
scrollToBottom: () => void;
|
|
6
5
|
onRegenerate: () => void;
|
|
7
|
-
/** 挂载时恢复的揭示进度(会话切回时避免重放动画) */
|
|
8
|
-
initialReveal?: number;
|
|
9
|
-
/** 揭示进度变化(宿主持久化,切回会话时用 initialReveal 恢复) */
|
|
10
|
-
onRevealProgress?: (reveal: number) => void;
|
|
11
6
|
}
|
|
12
7
|
declare const MessageItem: React.FC<MessageItemProps>;
|
|
13
8
|
export default MessageItem;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { StepItem } from '../../../../core/types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* 由 buildMetaBlocks 按 SSE 事件顺序切分(连续 step 合成一块),使用户看到的顺序
|
|
6
|
-
* 与后端返回的从上到下顺序一致:步骤块可与深度思考块交替出现。
|
|
7
|
-
* 标题只在多步时展示,单步块直接作为一行,避免与思考块交错时标题重复。
|
|
3
|
+
* 流程步骤块:流式展开、结束后收起;单步可展开原文。
|
|
8
4
|
*/
|
|
9
5
|
declare const StepBlock: React.FC<{
|
|
10
6
|
steps: StepItem[];
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown 渲染器(流式光标装饰)。
|
|
3
|
-
*
|
|
4
|
-
* 逐字揭示已统一上移到 useMessagePlayback:本组件接收的 content 即为「已揭示」的内容,
|
|
5
|
-
* 只做 markdown 渲染,并在揭示未完成时补充光标,不再自行打字。
|
|
6
|
-
*/
|
|
1
|
+
/** 纯 Markdown 渲染:直接展示平台真实 SSE 已到达的增量,不自行打字、不追加光标 */
|
|
7
2
|
declare const StreamingMarkdown: React.FC<{
|
|
8
3
|
content: string;
|
|
9
|
-
/** 是否处于揭示中(显示光标) */
|
|
10
|
-
showCursor?: boolean;
|
|
11
4
|
}>;
|
|
12
5
|
export default StreamingMarkdown;
|