@somecat/ai-assist-sdk 1.3.7 → 2.0.1
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/{index-BND0wsLs.mjs → engine-Cu-2TgJb.mjs} +2329 -2243
- package/dist/chunks/index-DNWBsXlO.mjs +98 -0
- package/dist/core/services/mode.d.ts +49 -0
- package/dist/core/types/index.d.ts +184 -0
- package/dist/core/utils/index.d.ts +1 -1
- package/dist/core/utils/markdown.d.ts +11 -0
- package/dist/core/utils/structured.d.ts +25 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +51 -29
- package/dist/react/index.d.ts +6 -1
- package/dist/react/index.mjs +708 -692
- package/dist/vue/components/answer/composables/useChatActions.d.ts +1 -0
- package/dist/vue/components/answer/composables/useChatSessions.d.ts +5 -0
- package/dist/vue/components/generated/icons.d.ts +76 -0
- package/dist/vue/index.d.ts +3 -1
- package/dist/vue/index.mjs +2445 -1685
- package/package.json +116 -113
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import "./engine-Cu-2TgJb.mjs";
|
|
2
|
+
const a = (e) => {
|
|
3
|
+
const t = e.trim(), r = /^```[a-zA-Z]*\s*\n([\s\S]*?)\n?```$/m.exec(t);
|
|
4
|
+
if (r) return r[1].trim();
|
|
5
|
+
const n = /```[a-zA-Z]*\s*\n([\s\S]*?)\n?```/.exec(t);
|
|
6
|
+
return n ? n[1].trim() : t;
|
|
7
|
+
}, i = (e) => {
|
|
8
|
+
const t = e.indexOf("{");
|
|
9
|
+
if (t < 0) return null;
|
|
10
|
+
let r = 0, n = !1, c = !1;
|
|
11
|
+
for (let s = t; s < e.length; s++) {
|
|
12
|
+
const o = e[s];
|
|
13
|
+
if (n) {
|
|
14
|
+
c ? c = !1 : o === "\\" ? c = !0 : o === '"' && (n = !1);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (o === '"') n = !0;
|
|
18
|
+
else if (o === "{") r++;
|
|
19
|
+
else if (o === "}" && (r--, r === 0))
|
|
20
|
+
return e.slice(t, s + 1);
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}, f = (e) => Array.isArray(e) ? e.filter((t) => t && typeof t == "object" && typeof t.type == "string" && t.type.trim()).map((t) => ({
|
|
24
|
+
type: String(t.type).trim(),
|
|
25
|
+
label: typeof t.label == "string" ? t.label : void 0,
|
|
26
|
+
payload: t.payload && typeof t.payload == "object" && !Array.isArray(t.payload) ? t.payload : void 0
|
|
27
|
+
})) : [], u = (e) => Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim()).map((t) => t.trim()) : [], g = (e) => {
|
|
28
|
+
const t = (e || "").trim();
|
|
29
|
+
if (!t) return { answer: "", actions: [], suggestions: [] };
|
|
30
|
+
const r = i(a(t));
|
|
31
|
+
if (!r) return { answer: t, actions: [], suggestions: [] };
|
|
32
|
+
try {
|
|
33
|
+
const n = JSON.parse(r);
|
|
34
|
+
if (!n || typeof n != "object") return { answer: t, actions: [], suggestions: [] };
|
|
35
|
+
const c = typeof n.answer == "string" ? n.answer : typeof n.content == "string" ? n.content : "", s = f(n.actions), o = u(n.suggestions);
|
|
36
|
+
return !c && !s.length ? { answer: t, actions: s, suggestions: o } : { answer: c || t, actions: s, suggestions: o };
|
|
37
|
+
} catch {
|
|
38
|
+
return { answer: t, actions: [], suggestions: [] };
|
|
39
|
+
}
|
|
40
|
+
}, l = (e, t) => {
|
|
41
|
+
const r = e[t];
|
|
42
|
+
switch (r) {
|
|
43
|
+
case "n":
|
|
44
|
+
return { text: `
|
|
45
|
+
`, next: t + 1 };
|
|
46
|
+
case "t":
|
|
47
|
+
return { text: " ", next: t + 1 };
|
|
48
|
+
case "r":
|
|
49
|
+
return { text: "\r", next: t + 1 };
|
|
50
|
+
case "b":
|
|
51
|
+
return { text: "\b", next: t + 1 };
|
|
52
|
+
case "f":
|
|
53
|
+
return { text: "\f", next: t + 1 };
|
|
54
|
+
case "u": {
|
|
55
|
+
const n = e.slice(t + 1, t + 5);
|
|
56
|
+
return n.length < 4 || !/^[0-9a-fA-F]{4}$/.test(n) ? { text: "", next: t + 1 } : { text: String.fromCharCode(parseInt(n, 16)), next: t + 5 };
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return { text: r ?? "", next: t + 1 };
|
|
60
|
+
}
|
|
61
|
+
}, p = (e) => {
|
|
62
|
+
if (!e) return "";
|
|
63
|
+
const t = e.indexOf('"answer"');
|
|
64
|
+
if (t < 0) return e;
|
|
65
|
+
let r = e.indexOf(":", t + 8);
|
|
66
|
+
if (r < 0 || (r = e.indexOf('"', r), r < 0)) return "";
|
|
67
|
+
r += 1;
|
|
68
|
+
let n = "";
|
|
69
|
+
for (; r < e.length; ) {
|
|
70
|
+
const c = e[r];
|
|
71
|
+
if (c === "\\") {
|
|
72
|
+
const s = l(e, r + 1);
|
|
73
|
+
n += s.text, r = s.next;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (c === '"') break;
|
|
77
|
+
n += c, r += 1;
|
|
78
|
+
}
|
|
79
|
+
return n;
|
|
80
|
+
}, h = (e, t) => {
|
|
81
|
+
if (!t || !Object.keys(t).length) return e;
|
|
82
|
+
let r = "";
|
|
83
|
+
try {
|
|
84
|
+
r = JSON.stringify(t);
|
|
85
|
+
} catch {
|
|
86
|
+
return e;
|
|
87
|
+
}
|
|
88
|
+
return `[PAGE_CONTEXT]
|
|
89
|
+
${r}
|
|
90
|
+
[/PAGE_CONTEXT]
|
|
91
|
+
[QUESTION]
|
|
92
|
+
${e}`;
|
|
93
|
+
};
|
|
94
|
+
export {
|
|
95
|
+
h as c,
|
|
96
|
+
p as e,
|
|
97
|
+
g as p
|
|
98
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AiAssistConfig, AiAssistMode, AiAssistPageModeConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 助手形态与面板状态(框架无关的单例 store)。
|
|
4
|
+
*
|
|
5
|
+
* - 不依赖 `getConfig()`:允许宿主在 `initAiAssist` / `mountAiAssist` 之前调用运行时 API。
|
|
6
|
+
* - 不使用 Pinia:SDK 是独立包,不能假设宿主有状态库。
|
|
7
|
+
* - Vue / React 适配层通过 `subscribeAiAssistState` 订阅,读取 `getXxx` 取值。
|
|
8
|
+
*/
|
|
9
|
+
type Listener = () => void;
|
|
10
|
+
/** 订阅任意状态变化(mode / visible / context) */
|
|
11
|
+
export declare const subscribeAiAssistState: (fn: Listener) => (() => void);
|
|
12
|
+
export declare const getAiAssistMode: () => AiAssistMode;
|
|
13
|
+
export declare const isAiAssistPageMode: () => boolean;
|
|
14
|
+
export declare const isAiAssistModeLocked: () => boolean;
|
|
15
|
+
export declare const getPageModeConfig: () => AiAssistPageModeConfig | null;
|
|
16
|
+
/** 挂载时把 config 里的形态/页面配置灌进 store(显式设置过形态时不覆盖) */
|
|
17
|
+
export declare const applyAiAssistConfig: (cfg: AiAssistConfig) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 切换形态。`lockMode` 只约束「界面是否给用户切换入口」,
|
|
20
|
+
* 宿主代码始终可以调用(本项目即通过它按页面切换)。
|
|
21
|
+
*/
|
|
22
|
+
export declare const setAiAssistMode: (next: AiAssistMode) => void;
|
|
23
|
+
export declare const isAiAssistVisible: () => boolean;
|
|
24
|
+
export declare const setAiAssistVisible: (next: boolean) => void;
|
|
25
|
+
export declare const openAiAssist: () => void;
|
|
26
|
+
export declare const closeAiAssist: () => void;
|
|
27
|
+
export declare const toggleAiAssist: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* 立即收起页面侧栏并重置上下文(不做收起动画)。
|
|
30
|
+
* 路由切换时由宿主调用,保证「切走收起、切回仍是收起」。
|
|
31
|
+
*/
|
|
32
|
+
export declare const collapsePageAssist: () => void;
|
|
33
|
+
/** 由 AiAssist 消费一次「跳过动画」标记 */
|
|
34
|
+
export declare const consumeCollapseInstant: () => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 运行时切换 page 模式的业务模块(多页面复用同一个侧栏实例)。
|
|
37
|
+
* 切换后会重新拉取上下文,并按新模块恢复各自的会话。
|
|
38
|
+
*/
|
|
39
|
+
export declare const setPageModule: (module: string) => void;
|
|
40
|
+
export declare const getPageModule: () => string;
|
|
41
|
+
export declare const getPageContextSnapshot: () => Record<string, any>;
|
|
42
|
+
/** 重新拉取页面上下文(侧栏打开、筛选变化、动作执行后调用) */
|
|
43
|
+
export declare const refreshAiPanelContext: () => Promise<Record<string, any>>;
|
|
44
|
+
export declare const getPageThreadId: (module?: string) => string;
|
|
45
|
+
export declare const setPageThreadId: (threadId: string, module?: string) => void;
|
|
46
|
+
export declare const clearPageThreadId: (module?: string) => void;
|
|
47
|
+
/** 卸载时重置,避免 HMR / 重新挂载残留 */
|
|
48
|
+
export declare const resetAiAssistState: () => void;
|
|
49
|
+
export {};
|
|
@@ -1,4 +1,165 @@
|
|
|
1
1
|
export type AiAssistTheme = 'light' | 'dark' | 'auto';
|
|
2
|
+
/** 助手形态:default=悬浮球助手,page=页面常驻侧栏 */
|
|
3
|
+
export type AiAssistMode = 'default' | 'page';
|
|
4
|
+
/** page 模式下的动作(由智能体返回,宿主决定是否放行) */
|
|
5
|
+
export interface AiPageAction {
|
|
6
|
+
type: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
payload?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
/** 宿主执行动作后的回执 */
|
|
11
|
+
export interface AiPageActionResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
/** 动作 / 文件卡片状态(idle=待执行,pending=执行中,applied=已完成,failed=失败可重试) */
|
|
16
|
+
export interface AiPageActionState {
|
|
17
|
+
status: 'idle' | 'pending' | 'applied' | 'failed';
|
|
18
|
+
message?: string;
|
|
19
|
+
}
|
|
20
|
+
/** page 模式:智能体生成的交付文件 */
|
|
21
|
+
export interface AiPageFile {
|
|
22
|
+
/** 下载时使用的相对路径(含 output/ 前缀) */
|
|
23
|
+
relPath: string;
|
|
24
|
+
name: string;
|
|
25
|
+
size?: number;
|
|
26
|
+
/** 内容指纹:同一路径被后续轮次覆盖时用于标注「文件已更新」 */
|
|
27
|
+
fingerprint?: string;
|
|
28
|
+
mtime?: number;
|
|
29
|
+
}
|
|
30
|
+
/** page 模式:会话状态中的一条历史消息 */
|
|
31
|
+
export interface AiPageHistoryMessage {
|
|
32
|
+
role: 'user' | 'assistant';
|
|
33
|
+
content: string;
|
|
34
|
+
files?: AiPageFile[];
|
|
35
|
+
charts?: AiChartItem[];
|
|
36
|
+
}
|
|
37
|
+
/** page 模式:平台内置图表工具产出的 ECharts 配置 */
|
|
38
|
+
export interface AiChartItem {
|
|
39
|
+
chartId: string;
|
|
40
|
+
option: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
/** page 模式:取数工具执行状态 */
|
|
43
|
+
export interface AiToolState {
|
|
44
|
+
name: string;
|
|
45
|
+
status: 'idle' | 'running' | 'done' | 'failed';
|
|
46
|
+
message?: string;
|
|
47
|
+
}
|
|
48
|
+
/** page 模式:流式过程中的结构化事件(工具/图表) */
|
|
49
|
+
export type AiStreamEvent = {
|
|
50
|
+
type: 'tool';
|
|
51
|
+
name: string;
|
|
52
|
+
args?: Record<string, any>;
|
|
53
|
+
message?: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'tool_result';
|
|
56
|
+
ok: boolean;
|
|
57
|
+
summary?: string;
|
|
58
|
+
months?: number;
|
|
59
|
+
series?: number;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'chart';
|
|
62
|
+
chartId: string;
|
|
63
|
+
option: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
/** 阶段提示:thinking=正在理解问题,answering=正在组织答案 */
|
|
66
|
+
| {
|
|
67
|
+
type: 'status';
|
|
68
|
+
phase: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
};
|
|
71
|
+
/** page 模式:会话状态(刷新后恢复) */
|
|
72
|
+
export interface AiPageStateResult {
|
|
73
|
+
threadId?: string;
|
|
74
|
+
messages: AiPageHistoryMessage[];
|
|
75
|
+
producedFiles?: AiPageFile[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* page 模式传输适配器。
|
|
79
|
+
*
|
|
80
|
+
* page 模式不复用 hi-agent 的 `apis.*` 报文(`{Query, AppConversationID}`),
|
|
81
|
+
* 由宿主把自家 BFF 包装成这几个方法,SDK 不感知后端协议。
|
|
82
|
+
*/
|
|
83
|
+
export interface AiPageTransport {
|
|
84
|
+
createThread: (p: {
|
|
85
|
+
module: string;
|
|
86
|
+
}) => Promise<string>;
|
|
87
|
+
chat: (p: {
|
|
88
|
+
module: string;
|
|
89
|
+
threadId?: string;
|
|
90
|
+
question: string;
|
|
91
|
+
pageContext?: Record<string, any>;
|
|
92
|
+
}) => Promise<{
|
|
93
|
+
threadId: string;
|
|
94
|
+
content: string;
|
|
95
|
+
files?: AiPageFile[];
|
|
96
|
+
charts?: AiChartItem[];
|
|
97
|
+
runTurnId?: string;
|
|
98
|
+
}>;
|
|
99
|
+
stop?: (p: {
|
|
100
|
+
module: string;
|
|
101
|
+
threadId: string;
|
|
102
|
+
}) => Promise<void>;
|
|
103
|
+
/** 会话状态:刷新后恢复对话与文件卡片(可选,未提供则刷新后从空会话开始) */
|
|
104
|
+
state?: (p: {
|
|
105
|
+
module: string;
|
|
106
|
+
threadId: string;
|
|
107
|
+
}) => Promise<AiPageStateResult>;
|
|
108
|
+
/**
|
|
109
|
+
* 流式对话(可选)。提供时优先于 `chat`:
|
|
110
|
+
* - `onDelta` 传增量文本(SDK 内部做 JSON answer 字段的渐进提取);
|
|
111
|
+
* - `onMeta` 可在建会话后立刻回传 threadId,供中途「停止」使用;
|
|
112
|
+
* - 返回最终完整结果(与 `chat` 同结构),由 SDK 做结构化解析与文件挂载。
|
|
113
|
+
*/
|
|
114
|
+
chatStream?: (p: {
|
|
115
|
+
module: string;
|
|
116
|
+
threadId?: string;
|
|
117
|
+
question: string;
|
|
118
|
+
pageContext?: Record<string, any>;
|
|
119
|
+
signal?: AbortSignal;
|
|
120
|
+
onMeta?: (info: {
|
|
121
|
+
threadId?: string;
|
|
122
|
+
}) => void;
|
|
123
|
+
onDelta: (text: string) => void;
|
|
124
|
+
/** 结构化事件:取数工具开始/结束、图表产出 */
|
|
125
|
+
onEvent?: (event: AiStreamEvent) => void;
|
|
126
|
+
}) => Promise<{
|
|
127
|
+
threadId: string;
|
|
128
|
+
content: string;
|
|
129
|
+
files?: AiPageFile[];
|
|
130
|
+
charts?: AiChartItem[];
|
|
131
|
+
runTurnId?: string;
|
|
132
|
+
}>;
|
|
133
|
+
}
|
|
134
|
+
/** page 模式配置 */
|
|
135
|
+
export interface AiAssistPageModeConfig {
|
|
136
|
+
/** 模块标识(会话按模块隔离),默认从宿主注册的上下文取 */
|
|
137
|
+
module?: string;
|
|
138
|
+
/** 侧栏宽度,默认取 dock.width 或 440 */
|
|
139
|
+
width?: number;
|
|
140
|
+
/** 头部标题,默认取 name */
|
|
141
|
+
title?: string;
|
|
142
|
+
/** 按业务模块覆盖标题(module → 标题),未命中回退 title / name */
|
|
143
|
+
titles?: Record<string, string>;
|
|
144
|
+
/** 按业务模块提供初始推荐问题(module → 问题列表),未命中回退 defaultRecommend */
|
|
145
|
+
recommend?: Record<string, string[]>;
|
|
146
|
+
/** 传输适配器(page 模式必填,缺失时退化为通用助手行为) */
|
|
147
|
+
api?: AiPageTransport;
|
|
148
|
+
/** 页面上下文提供者,仅在提问/刷新胶囊时调用 */
|
|
149
|
+
getPageContext?: (p: {
|
|
150
|
+
module: string;
|
|
151
|
+
}) => Record<string, any> | Promise<Record<string, any>>;
|
|
152
|
+
/** 动作执行回调,返回回执驱动卡片状态 */
|
|
153
|
+
onAction?: (action: AiPageAction) => AiPageActionResult | Promise<AiPageActionResult>;
|
|
154
|
+
/** 文件下载回调(宿主负责带鉴权取流并落盘),返回回执驱动卡片状态 */
|
|
155
|
+
onDownloadFile?: (file: AiPageFile) => AiPageActionResult | Promise<AiPageActionResult>;
|
|
156
|
+
/** 图表渲染回调:宿主用 echarts.init(el) 渲染(SDK 不引入 echarts) */
|
|
157
|
+
onChartRender?: (chart: AiChartItem, el: HTMLElement) => void | Promise<void>;
|
|
158
|
+
/** 图表下载回调(宿主持有 echarts 实例,可导出 PNG);不提供则隐藏下载按钮 */
|
|
159
|
+
onChartDownload?: (chart: AiChartItem) => void;
|
|
160
|
+
/** 面板显隐回调(宿主据此同步自身按钮态) */
|
|
161
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
162
|
+
}
|
|
2
163
|
export interface AiAssistConfig {
|
|
3
164
|
name?: string;
|
|
4
165
|
baseUrl: string;
|
|
@@ -18,6 +179,15 @@ export interface AiAssistConfig {
|
|
|
18
179
|
theme?: AiAssistTheme;
|
|
19
180
|
/** 是否允许拖拽移动面板(浮窗模式),默认 true */
|
|
20
181
|
panelDraggable?: boolean;
|
|
182
|
+
/** 初始形态,默认 'default';宿主可用 setAiAssistMode 在运行时切换 */
|
|
183
|
+
mode?: AiAssistMode;
|
|
184
|
+
/** page 模式配置(mode='page' 时生效) */
|
|
185
|
+
pageMode?: AiAssistPageModeConfig;
|
|
186
|
+
/**
|
|
187
|
+
* 是否锁定形态切换入口,默认 true。
|
|
188
|
+
* 仅约束「界面是否给用户切换入口」,宿主代码始终可调用 setAiAssistMode。
|
|
189
|
+
*/
|
|
190
|
+
lockMode?: boolean;
|
|
21
191
|
/** 面板停靠(嵌入宿主布局)配置 */
|
|
22
192
|
dock?: AiAssistDockConfig;
|
|
23
193
|
/** 面板活跃心跳间隔(毫秒),默认 30000;用于「不丢尾段」地上报活跃时长增量 */
|
|
@@ -172,6 +342,20 @@ export interface ChatMessage {
|
|
|
172
342
|
* 由渲染层补一条「工具调用中」状态,避免界面呆滞。
|
|
173
343
|
*/
|
|
174
344
|
lastChunkAt?: number;
|
|
345
|
+
/** page 模式:智能体返回的结构化动作 */
|
|
346
|
+
actions?: AiPageAction[];
|
|
347
|
+
/** page 模式:动作执行状态(按动作 key 存储) */
|
|
348
|
+
actionStates?: Record<string, AiPageActionState>;
|
|
349
|
+
/** page 模式:智能体给出的追问建议 */
|
|
350
|
+
suggestions?: string[];
|
|
351
|
+
/** page 模式:本轮生成的交付文件 */
|
|
352
|
+
files?: AiPageFile[];
|
|
353
|
+
/** page 模式:文件下载状态(按 relPath 存储) */
|
|
354
|
+
fileStates?: Record<string, AiPageActionState>;
|
|
355
|
+
/** page 模式:平台图表工具产出的图表 */
|
|
356
|
+
charts?: AiChartItem[];
|
|
357
|
+
/** page 模式:取数工具执行状态(查询中/完成/失败) */
|
|
358
|
+
toolState?: AiToolState;
|
|
175
359
|
}
|
|
176
360
|
/** API 返回的会话列表项(已转 camelCase) */
|
|
177
361
|
export interface ConversationItem {
|
|
@@ -59,7 +59,7 @@ export declare const orderConversationMessages: <T extends {
|
|
|
59
59
|
createdTime?: number | string;
|
|
60
60
|
createTime?: number | string;
|
|
61
61
|
}>(items: T[] | undefined | null) => T[];
|
|
62
|
-
export { renderMarkdown, preprocessStreamingMarkdown } from './markdown';
|
|
62
|
+
export { renderMarkdown, preprocessStreamingMarkdown, stripChartBlocks } from './markdown';
|
|
63
63
|
export { isRevealableSegment, totalRevealLength, revealSegmentContents, findRevealFrontier, isSegmentRevealed, segmentRevealRange, buildMetaBlocks, advanceReveal, stepRevealCap, REVEAL_BASE_CPS, REVEAL_TARGET_SEC, REVEAL_MAX_CPS, REVEAL_STEP_MIN_SEC, STALL_HINT_DELAY_MS, } from './streamPlayback';
|
|
64
64
|
export { showToast, type ToastType } from './toast';
|
|
65
65
|
export declare const ensureViewportFit: () => void;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export declare const renderMarkdown: (content: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* 移除平台图表工具的「正文引用」,避免把 chart_id JSON 当代码块展示。
|
|
4
|
+
*
|
|
5
|
+
* 官方约定:正文用 ```echarts 代码块引用,内容为 {"chart_id":"chart_xxx"};
|
|
6
|
+
* 图表本身由 tool.result 的 echarts_chart.option 另行提供并渲染成卡片。
|
|
7
|
+
*
|
|
8
|
+
* - 完整围栏与「流式未闭合」围栏都会移除;
|
|
9
|
+
* - 同时清理裸的 {"chart_id":"..."} 行;
|
|
10
|
+
* - 无匹配时原样返回。
|
|
11
|
+
*/
|
|
12
|
+
export declare const stripChartBlocks: (content: string) => string;
|
|
2
13
|
/**
|
|
3
14
|
* 预处理流式传输中的不完整 Markdown,避免渲染错乱
|
|
4
15
|
* - 闭合未关闭的代码块 (```)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AiPageAction } from '../types';
|
|
2
|
+
/** page 模式的结构化回答 */
|
|
3
|
+
export interface AiStructuredAnswer {
|
|
4
|
+
/** 正文(解析失败时为原始文本) */
|
|
5
|
+
answer: string;
|
|
6
|
+
actions: AiPageAction[];
|
|
7
|
+
suggestions: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 解析智能体返回的结构化回答。
|
|
11
|
+
*
|
|
12
|
+
* 约定格式:`{"answer":string,"actions":[],"suggestions":[]}`;
|
|
13
|
+
* 兼容代码围栏与前后噪声;解析失败时整段按纯文本返回,由渲染层走 Markdown,不白屏。
|
|
14
|
+
*/
|
|
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
|
+
/** 拼装 page 模式的提问内容(上下文块 + 用户原话) */
|
|
25
|
+
export declare const composePageQuery: (question: string, pageContext?: Record<string, any>) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export type { AiAssistConfig, AiAssistTheme, ViewStatus, MessageStatus, ChatMessage, ConversationItem, ConversationMessageItem, HistoryItem, ChatSessionMeta, PersonalInfo, } from './core/types';
|
|
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';
|
|
3
|
+
export { parseStructuredAnswer, composePageQuery } from './core/utils/structured';
|
|
4
|
+
export type { AiStructuredAnswer } from './core/utils/structured';
|
|
2
5
|
export { setConfig, getConfig, request, http, createAuthAxios, } from './core/services/request';
|
|
3
6
|
export { createConversation, ensureTitleConversation, getConversationList, deleteConversation, updateConversation, getConversationMessages, chatQuery, stopMessage, getSuggestedQuestions, getMessageInfo, getAppConfig, getPersonalInfo, } from './core/services/api';
|
|
4
7
|
export { useClipboard, extractPlainText, statusText, formatQuestions, textError, processSSEData, parseSSEData, extractAnswerText, sanitizeConversationTitle, renderMarkdown, } from './core/utils';
|
package/dist/index.mjs
CHANGED
|
@@ -1,34 +1,56 @@
|
|
|
1
|
-
import { V as a, t,
|
|
1
|
+
import { V as a, F as t, W as i, c as o, Q as r, R as n, j as g, b as A, B as d, q as l, k as p, X as c, x as u, l as C, Y as h, w as P, A as x, d as T, Z as S, E as f, e as M, f as m, C as v, _ as b, $ as w, a0 as E, i as I, J as Q, S as y, a1 as V, a2 as k, n as D, r as L, a3 as q, O as j, L as z, t as B, K as F, H as G, P as H, T as J, m as K, a4 as O, h as R, D as U, a5 as W, U as X, v as Y, u as Z, G as _ } from "./chunks/engine-Cu-2TgJb.mjs";
|
|
2
|
+
import { c as N, p as ss } from "./chunks/index-DNWBsXlO.mjs";
|
|
2
3
|
export {
|
|
3
4
|
a as VoiceEngine,
|
|
4
5
|
t as applyTheme,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
r as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
i as chatQuery,
|
|
7
|
+
o as clearPageThreadId,
|
|
8
|
+
r as closeAiAssist,
|
|
9
|
+
n as collapsePageAssist,
|
|
10
|
+
N as composePageQuery,
|
|
11
|
+
g as createAuthAxios,
|
|
12
|
+
A as createConversation,
|
|
13
|
+
d as deleteConversation,
|
|
14
|
+
l as ensureTitleConversation,
|
|
15
|
+
p as extractAnswerText,
|
|
16
|
+
c as extractPlainText,
|
|
12
17
|
u as formatQuestions,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
m as
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
C as getAiAssistMode,
|
|
19
|
+
h as getAppConfig,
|
|
20
|
+
P as getConfig,
|
|
21
|
+
x as getConversationList,
|
|
22
|
+
T as getConversationMessages,
|
|
23
|
+
S as getMessageInfo,
|
|
24
|
+
f as getPageContextSnapshot,
|
|
25
|
+
M as getPageModule,
|
|
26
|
+
m as getPageThreadId,
|
|
27
|
+
v as getPersonalInfo,
|
|
28
|
+
b as getSuggestedQuestions,
|
|
29
|
+
w as http,
|
|
30
|
+
E as isAiAssistModeLocked,
|
|
31
|
+
I as isAiAssistPageMode,
|
|
32
|
+
Q as isAiAssistVisible,
|
|
33
|
+
y as openAiAssist,
|
|
34
|
+
V as parseSSEData,
|
|
35
|
+
ss as parseStructuredAnswer,
|
|
36
|
+
k as processSSEData,
|
|
37
|
+
D as refreshAiPanelContext,
|
|
38
|
+
L as renderMarkdown,
|
|
39
|
+
q as request,
|
|
40
|
+
j as resetAiAssistState,
|
|
41
|
+
z as resolveTheme,
|
|
42
|
+
B as sanitizeConversationTitle,
|
|
43
|
+
F as setAiAssistMode,
|
|
44
|
+
G as setAiAssistVisible,
|
|
45
|
+
H as setConfig,
|
|
46
|
+
J as setPageModule,
|
|
47
|
+
K as setPageThreadId,
|
|
48
|
+
O as statusText,
|
|
49
|
+
R as stopMessage,
|
|
50
|
+
U as subscribeAiAssistState,
|
|
51
|
+
W as textError,
|
|
52
|
+
X as toggleAiAssist,
|
|
53
|
+
Y as updateConversation,
|
|
54
|
+
Z as useClipboard,
|
|
55
|
+
_ as watchSystemTheme
|
|
34
56
|
};
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import { default as React } from 'react';
|
|
|
2
2
|
import { default as AiAssist } from './components/AiAssist';
|
|
3
3
|
import { default as VoiceInput } from './components/VoiceInput';
|
|
4
4
|
import { AiAssistConfig } from '../core/types';
|
|
5
|
-
export type { AiAssistConfig, AiAssistTheme } from '../core/types';
|
|
5
|
+
export type { AiAssistConfig, AiAssistTheme, AiAssistMode, AiAssistPageModeConfig, AiPageAction, AiPageActionResult, AiPageActionState, AiPageTransport, } from '../core/types';
|
|
6
|
+
/**
|
|
7
|
+
* 形态与面板运行时 API。
|
|
8
|
+
* 注意:page 模式的侧栏 UI 目前仅 Vue 适配层实现,React 侧仅保证 API 一致可编译。
|
|
9
|
+
*/
|
|
10
|
+
export { getAiAssistMode, setAiAssistMode, isAiAssistPageMode, openAiAssist, closeAiAssist, toggleAiAssist, isAiAssistVisible, setAiAssistVisible, refreshAiPanelContext, getPageContextSnapshot, getPageModule, getPageThreadId, setPageThreadId, clearPageThreadId, subscribeAiAssistState, } from '../core/services/mode';
|
|
6
11
|
export declare const initAiAssist: (config: AiAssistConfig) => void;
|
|
7
12
|
export declare const mountAiAssist: (container?: HTMLElement) => void;
|
|
8
13
|
export declare const unmountAiAssist: () => void;
|