@cqfe/sxin-chat-core 1.0.0 → 1.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/{ChatCore-DyjH-HBV.d.cts → ChatCore-C-G9isDM.d.cts} +11 -8
- package/dist/{ChatCore-DyjH-HBV.d.ts → ChatCore-C-G9isDM.d.ts} +11 -8
- package/dist/{chunk-NLL3XGEI.mjs → chunk-K2ZOZPBB.mjs} +63 -50
- package/dist/index.cjs +65 -51
- package/dist/index.d.cts +26 -31
- package/dist/index.d.ts +26 -31
- package/dist/index.mjs +5 -3
- package/dist/vue/index.cjs +65 -53
- package/dist/vue/index.d.cts +2 -2
- package/dist/vue/index.d.ts +2 -2
- package/dist/vue/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -353,7 +353,7 @@ interface AskClarificationBlock extends BlockBase {
|
|
|
353
353
|
/** thread 级回答状态(跨 run 不回写 block,渲染层据此自行判断是否已回答) */
|
|
354
354
|
isAnswered?: boolean;
|
|
355
355
|
}
|
|
356
|
-
/**
|
|
356
|
+
/** 引用文件项(GroupMessage.citations 元素类型:refId 锚点 + 详情字段,详情由渲染层拉取后写回) */
|
|
357
357
|
interface CitationItem {
|
|
358
358
|
/** 引用唯一标识 */
|
|
359
359
|
refId: string;
|
|
@@ -376,11 +376,8 @@ interface CitationItem {
|
|
|
376
376
|
/** 搜索关键词列表,用于一次高亮多段命中文本 */
|
|
377
377
|
searchTexts?: string[];
|
|
378
378
|
}
|
|
379
|
-
/** 引用 Block
|
|
380
|
-
|
|
381
|
-
type: 'citation';
|
|
382
|
-
items: CitationItem[];
|
|
383
|
-
}
|
|
379
|
+
/** 引用 Block 已下线:citation 走 sxin-item contract="support.kbCitation" 自定义渲染链,
|
|
380
|
+
* 解析层仅产出锚点挂到 GroupMessage.citations(见 types/groupMessage.ts)。 */
|
|
384
381
|
interface TwinBlock extends BlockBase {
|
|
385
382
|
type: 'twin';
|
|
386
383
|
toolName: string;
|
|
@@ -399,7 +396,7 @@ interface InterruptReviewBlock extends BlockBase {
|
|
|
399
396
|
isResponded?: boolean;
|
|
400
397
|
}
|
|
401
398
|
/** Block 联合类型 */
|
|
402
|
-
type Block = TextBlock | ArtifactBlock |
|
|
399
|
+
type Block = TextBlock | ArtifactBlock | CustomBlock | ReportOutlineBlock | ReportBodyBlock | FormBlock | ListBlock | AskClarificationBlock | TwinBlock | InterruptReviewBlock;
|
|
403
400
|
|
|
404
401
|
/**
|
|
405
402
|
* 前端 Message 结构类型(blockBuilder.ts re-export 保持 import 路径不变)。
|
|
@@ -521,6 +518,12 @@ interface GroupMessage {
|
|
|
521
518
|
checkpointId?: string;
|
|
522
519
|
/** 渲染 block 列表 */
|
|
523
520
|
blocks: Block[];
|
|
521
|
+
/**
|
|
522
|
+
* 消息级引用锚点:由 sxin-item contract="support.kbCitation" 块提取(refId + searchText),
|
|
523
|
+
* 顺序即正文 [n] 角标序号;docUrl/docId 等详情由渲染层按 refId 拉 artifact 后写回。
|
|
524
|
+
* 仅 AI 组可能有值;无引用块时为 undefined。
|
|
525
|
+
*/
|
|
526
|
+
citations?: CitationItem[];
|
|
524
527
|
/** 该组内提取到的 tool_call_id 列表(按出现顺序去重) */
|
|
525
528
|
toolIds: string[];
|
|
526
529
|
/** 与 toolIds 对应的完整 tool 对象 */
|
|
@@ -1037,4 +1040,4 @@ interface ChatCore {
|
|
|
1037
1040
|
}
|
|
1038
1041
|
declare function createChatCore(options: ChatCoreOptions): ChatCore;
|
|
1039
1042
|
|
|
1040
|
-
export { type
|
|
1043
|
+
export { type HitlDecisionType as $, type AcquireResult as A, type Block as B, type CreateStreamOptions as C, type ChatCoreOptions as D, type ElementNode as E, type ChatNotify as F, type GroupMessageTool as G, type HitlResponse as H, type IKwargs as I, type CommentNode as J, type CustomBlock as K, DEFAULT_TWIN_TOOL_PREFIX as L, type MessageTokenUsage as M, type FetchMessagesPageOptions as N, type OutlineSubChapter as O, type FormBlock as P, type FormFieldItem as Q, type RunInfo as R, type SxinNode as S, type ThreadInitialValues as T, type FormFieldType as U, type GenerateBodyRequest as V, type GenerateBodyResult as W, type GroupMessageSource as X, type GroupMessageStatus as Y, type HitlActionRequest as Z, type HitlDecision as _, type ChatStreamHandle as a, type HitlInterruptPayload as a0, type HitlReviewConfig as a1, type IAttachment as a2, type IQuote as a3, type InlineCitation as a4, type InterruptReviewBlock as a5, type ListBlock as a6, type ListItem as a7, type Message as a8, type MessageMetadata as a9, getAllowedDecisions as aA, isSameArgs as aB, normalizeForCompare as aC, parseHitlPayload as aD, pickRunMessageMetadata as aE, type MessageRole as aa, type MessageSource as ab, type MessageStatus as ac, type ReportBodyBlock as ad, type ReportGenerateBodyHumanKwargs as ae, type ReportOutlineBlock as af, type ReportSelectedArtifact as ag, type ReportSelectedTemplate as ah, type SearchThreadsOptions as ai, type TextBlock as aj, type TextNode as ak, ThreadDirectory as al, type ThreadDirectoryOptions as am, type ThreadRuntime as an, type ThreadRuntimeOptions as ao, type ThreadsPagination as ap, type TwinBlock as aq, buildHitlDecisions as ar, buildInterruptReviewBlock as as, buildInterruptReviewGroup as at, buildRejectDecisions as au, buildRunDirectLatencyMs as av, buildRunInfo as aw, createBlockBuilderLite as ax, createChatCore as ay, createThreadRuntime as az, type CitationItem as b, type RunMessage as c, type ReportBodyPayload as d, type ReportOutlinePayload as e, type BlockBuilderOptions as f, type OutlineChapter as g, type GroupMessageType as h, type BlockBuilderLiteOptions as i, type GroupMessage as j, type SendMessageOptions as k, type ChatTransport as l, type MessagesPage as m, type ThreadTokenUsage as n, type StreamSubmitInput as o, type StreamSubmitOptions as p, type AgentThreadState as q, type ArtifactBlock as r, type ArtifactFile as s, type AskClarificationBlock as t, type BlockBase as u, type BlockBuilderLite as v, type BlockSource as w, type BlockStatus as x, type BuildAllOptions as y, type ChatCore as z };
|
|
@@ -353,7 +353,7 @@ interface AskClarificationBlock extends BlockBase {
|
|
|
353
353
|
/** thread 级回答状态(跨 run 不回写 block,渲染层据此自行判断是否已回答) */
|
|
354
354
|
isAnswered?: boolean;
|
|
355
355
|
}
|
|
356
|
-
/**
|
|
356
|
+
/** 引用文件项(GroupMessage.citations 元素类型:refId 锚点 + 详情字段,详情由渲染层拉取后写回) */
|
|
357
357
|
interface CitationItem {
|
|
358
358
|
/** 引用唯一标识 */
|
|
359
359
|
refId: string;
|
|
@@ -376,11 +376,8 @@ interface CitationItem {
|
|
|
376
376
|
/** 搜索关键词列表,用于一次高亮多段命中文本 */
|
|
377
377
|
searchTexts?: string[];
|
|
378
378
|
}
|
|
379
|
-
/** 引用 Block
|
|
380
|
-
|
|
381
|
-
type: 'citation';
|
|
382
|
-
items: CitationItem[];
|
|
383
|
-
}
|
|
379
|
+
/** 引用 Block 已下线:citation 走 sxin-item contract="support.kbCitation" 自定义渲染链,
|
|
380
|
+
* 解析层仅产出锚点挂到 GroupMessage.citations(见 types/groupMessage.ts)。 */
|
|
384
381
|
interface TwinBlock extends BlockBase {
|
|
385
382
|
type: 'twin';
|
|
386
383
|
toolName: string;
|
|
@@ -399,7 +396,7 @@ interface InterruptReviewBlock extends BlockBase {
|
|
|
399
396
|
isResponded?: boolean;
|
|
400
397
|
}
|
|
401
398
|
/** Block 联合类型 */
|
|
402
|
-
type Block = TextBlock | ArtifactBlock |
|
|
399
|
+
type Block = TextBlock | ArtifactBlock | CustomBlock | ReportOutlineBlock | ReportBodyBlock | FormBlock | ListBlock | AskClarificationBlock | TwinBlock | InterruptReviewBlock;
|
|
403
400
|
|
|
404
401
|
/**
|
|
405
402
|
* 前端 Message 结构类型(blockBuilder.ts re-export 保持 import 路径不变)。
|
|
@@ -521,6 +518,12 @@ interface GroupMessage {
|
|
|
521
518
|
checkpointId?: string;
|
|
522
519
|
/** 渲染 block 列表 */
|
|
523
520
|
blocks: Block[];
|
|
521
|
+
/**
|
|
522
|
+
* 消息级引用锚点:由 sxin-item contract="support.kbCitation" 块提取(refId + searchText),
|
|
523
|
+
* 顺序即正文 [n] 角标序号;docUrl/docId 等详情由渲染层按 refId 拉 artifact 后写回。
|
|
524
|
+
* 仅 AI 组可能有值;无引用块时为 undefined。
|
|
525
|
+
*/
|
|
526
|
+
citations?: CitationItem[];
|
|
524
527
|
/** 该组内提取到的 tool_call_id 列表(按出现顺序去重) */
|
|
525
528
|
toolIds: string[];
|
|
526
529
|
/** 与 toolIds 对应的完整 tool 对象 */
|
|
@@ -1037,4 +1040,4 @@ interface ChatCore {
|
|
|
1037
1040
|
}
|
|
1038
1041
|
declare function createChatCore(options: ChatCoreOptions): ChatCore;
|
|
1039
1042
|
|
|
1040
|
-
export { type
|
|
1043
|
+
export { type HitlDecisionType as $, type AcquireResult as A, type Block as B, type CreateStreamOptions as C, type ChatCoreOptions as D, type ElementNode as E, type ChatNotify as F, type GroupMessageTool as G, type HitlResponse as H, type IKwargs as I, type CommentNode as J, type CustomBlock as K, DEFAULT_TWIN_TOOL_PREFIX as L, type MessageTokenUsage as M, type FetchMessagesPageOptions as N, type OutlineSubChapter as O, type FormBlock as P, type FormFieldItem as Q, type RunInfo as R, type SxinNode as S, type ThreadInitialValues as T, type FormFieldType as U, type GenerateBodyRequest as V, type GenerateBodyResult as W, type GroupMessageSource as X, type GroupMessageStatus as Y, type HitlActionRequest as Z, type HitlDecision as _, type ChatStreamHandle as a, type HitlInterruptPayload as a0, type HitlReviewConfig as a1, type IAttachment as a2, type IQuote as a3, type InlineCitation as a4, type InterruptReviewBlock as a5, type ListBlock as a6, type ListItem as a7, type Message as a8, type MessageMetadata as a9, getAllowedDecisions as aA, isSameArgs as aB, normalizeForCompare as aC, parseHitlPayload as aD, pickRunMessageMetadata as aE, type MessageRole as aa, type MessageSource as ab, type MessageStatus as ac, type ReportBodyBlock as ad, type ReportGenerateBodyHumanKwargs as ae, type ReportOutlineBlock as af, type ReportSelectedArtifact as ag, type ReportSelectedTemplate as ah, type SearchThreadsOptions as ai, type TextBlock as aj, type TextNode as ak, ThreadDirectory as al, type ThreadDirectoryOptions as am, type ThreadRuntime as an, type ThreadRuntimeOptions as ao, type ThreadsPagination as ap, type TwinBlock as aq, buildHitlDecisions as ar, buildInterruptReviewBlock as as, buildInterruptReviewGroup as at, buildRejectDecisions as au, buildRunDirectLatencyMs as av, buildRunInfo as aw, createBlockBuilderLite as ax, createChatCore as ay, createThreadRuntime as az, type CitationItem as b, type RunMessage as c, type ReportBodyPayload as d, type ReportOutlinePayload as e, type BlockBuilderOptions as f, type OutlineChapter as g, type GroupMessageType as h, type BlockBuilderLiteOptions as i, type GroupMessage as j, type SendMessageOptions as k, type ChatTransport as l, type MessagesPage as m, type ThreadTokenUsage as n, type StreamSubmitInput as o, type StreamSubmitOptions as p, type AgentThreadState as q, type ArtifactBlock as r, type ArtifactFile as s, type AskClarificationBlock as t, type BlockBase as u, type BlockBuilderLite as v, type BlockSource as w, type BlockStatus as x, type BuildAllOptions as y, type ChatCore as z };
|
|
@@ -409,18 +409,59 @@ var normalizeOne = (raw) => {
|
|
|
409
409
|
searchText: orUndefined(searchText)
|
|
410
410
|
};
|
|
411
411
|
};
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
412
|
+
var KB_CITATION_CONTRACT = "support.kbCitation";
|
|
413
|
+
var REF_ID_KEYS = ["ref-id", "refId", "ref_id", "citation-id", "citationId", "citation_id", "id"];
|
|
414
|
+
var SEARCH_TEXT_KEYS = ["search-text", "searchText", "search_text", "keyword"];
|
|
415
|
+
var REF_ID_LIST_KEY_RE = /^(ref|citation)[-_]?ids?$/i;
|
|
416
|
+
var isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
417
|
+
var pickFirstString = (obj, keys) => {
|
|
418
|
+
for (const k of keys) {
|
|
419
|
+
const v = obj?.[k];
|
|
420
|
+
if (v === void 0 || v === null) continue;
|
|
421
|
+
const s = String(v).trim();
|
|
422
|
+
if (s) return s;
|
|
423
423
|
}
|
|
424
|
+
return void 0;
|
|
425
|
+
};
|
|
426
|
+
function extractCitationAnchorsFromSpec(spec) {
|
|
427
|
+
const anchors = [];
|
|
428
|
+
const seen = /* @__PURE__ */ new Set();
|
|
429
|
+
const candidates = [];
|
|
430
|
+
if (isPlainObject(spec)) candidates.push(spec);
|
|
431
|
+
for (const [key, value] of Object.entries(spec || {})) {
|
|
432
|
+
if (Array.isArray(value)) {
|
|
433
|
+
for (const item of value) if (isPlainObject(item)) candidates.push(item);
|
|
434
|
+
} else if (typeof value === "string" && /,/.test(value) && REF_ID_LIST_KEY_RE.test(key)) {
|
|
435
|
+
for (const id of value.split(",")) candidates.push({ "ref-id": id });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (const item of candidates) {
|
|
439
|
+
const refId = pickFirstString(item, REF_ID_KEYS);
|
|
440
|
+
if (!refId || seen.has(refId)) continue;
|
|
441
|
+
seen.add(refId);
|
|
442
|
+
const anchor = { refId, title: "" };
|
|
443
|
+
const searchText = pickFirstString(item, SEARCH_TEXT_KEYS);
|
|
444
|
+
if (searchText) anchor.searchText = searchText;
|
|
445
|
+
anchors.push(anchor);
|
|
446
|
+
}
|
|
447
|
+
return anchors;
|
|
448
|
+
}
|
|
449
|
+
function extractCitationAnchors(blocks) {
|
|
450
|
+
const anchors = [];
|
|
451
|
+
const seen = /* @__PURE__ */ new Set();
|
|
452
|
+
for (const block of blocks) {
|
|
453
|
+
if (block.type !== "custom") continue;
|
|
454
|
+
const custom = block;
|
|
455
|
+
if (custom.tagName !== "sxin-item") continue;
|
|
456
|
+
const spec = custom.spec || {};
|
|
457
|
+
if (String(spec.contract || "").trim() !== KB_CITATION_CONTRACT) continue;
|
|
458
|
+
for (const anchor of extractCitationAnchorsFromSpec(spec)) {
|
|
459
|
+
if (seen.has(anchor.refId)) continue;
|
|
460
|
+
seen.add(anchor.refId);
|
|
461
|
+
anchors.push(anchor);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return anchors;
|
|
424
465
|
}
|
|
425
466
|
function parseKnowledgeItemsFromValue(value) {
|
|
426
467
|
if (!value) return [];
|
|
@@ -1083,11 +1124,6 @@ function walkNodes(ctx, nodes) {
|
|
|
1083
1124
|
if (isInjectedElement(node)) {
|
|
1084
1125
|
continue;
|
|
1085
1126
|
}
|
|
1086
|
-
if (node.tagName === "sxin-kb-citation" && node.closed) {
|
|
1087
|
-
flushTextBuf(ctx);
|
|
1088
|
-
collectCitation(node, ctx.citations);
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
1127
|
if (node.tagName.startsWith("sxin-")) {
|
|
1092
1128
|
if (!handleSxinElement(ctx, node)) return false;
|
|
1093
1129
|
continue;
|
|
@@ -1103,12 +1139,11 @@ function extractBlocksFromNodes(nodes, rawText, source) {
|
|
|
1103
1139
|
isHistory,
|
|
1104
1140
|
status: isHistory ? "completed" : "streaming",
|
|
1105
1141
|
blocks: [],
|
|
1106
|
-
citations: [],
|
|
1107
1142
|
textBuf: { value: "" }
|
|
1108
1143
|
};
|
|
1109
1144
|
const completed = walkNodes(ctx, nodes);
|
|
1110
1145
|
if (completed) flushTextBuf(ctx);
|
|
1111
|
-
return { blocks: ctx.blocks
|
|
1146
|
+
return { blocks: ctx.blocks };
|
|
1112
1147
|
}
|
|
1113
1148
|
function extractBlocksFromContent(rawText, source) {
|
|
1114
1149
|
return extractBlocksFromNodes(tokenizeSxin(rawText), rawText, source);
|
|
@@ -1428,20 +1463,12 @@ function createBlockBuilderLite(options) {
|
|
|
1428
1463
|
const blocks = [];
|
|
1429
1464
|
const status = isStreaming ? "streaming" : "completed";
|
|
1430
1465
|
const contentSource = source === "state" ? "history" : source;
|
|
1431
|
-
const { blocks: contentBlocks
|
|
1466
|
+
const { blocks: contentBlocks } = extractBlocksFromNodes(nodes, rawText, contentSource);
|
|
1432
1467
|
blocks.push(...contentBlocks);
|
|
1433
1468
|
for (const tool of tools) {
|
|
1434
1469
|
const toolBlocks = parseBlockTool(tool, status);
|
|
1435
1470
|
blocks.push(...toolBlocks);
|
|
1436
1471
|
}
|
|
1437
|
-
if (citations.length > 0) {
|
|
1438
|
-
blocks.push({
|
|
1439
|
-
id: genBlockId(),
|
|
1440
|
-
type: "citation",
|
|
1441
|
-
items: citations.map((c) => ({ ...c, title: c.title || "" })),
|
|
1442
|
-
status
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
1472
|
if (twinEnabled) {
|
|
1446
1473
|
const twinTool = tools.reverse().find((_) => _.call?.name.includes(twinToolPrefix));
|
|
1447
1474
|
if (twinTool) {
|
|
@@ -1530,6 +1557,8 @@ function buildAiGroup(messages, options, twin) {
|
|
|
1530
1557
|
content,
|
|
1531
1558
|
groupTools
|
|
1532
1559
|
);
|
|
1560
|
+
const anchors = extractCitationAnchors(blocks);
|
|
1561
|
+
const citations = anchors.length ? anchors : void 0;
|
|
1533
1562
|
return {
|
|
1534
1563
|
id: firstId,
|
|
1535
1564
|
type: "ai",
|
|
@@ -1538,6 +1567,7 @@ function buildAiGroup(messages, options, twin) {
|
|
|
1538
1567
|
runId: messageRunId(lastAi) || options.runId,
|
|
1539
1568
|
rawMessages: messages,
|
|
1540
1569
|
blocks,
|
|
1570
|
+
citations,
|
|
1541
1571
|
toolIds: groupTools.map((t) => t.id),
|
|
1542
1572
|
tools: groupTools,
|
|
1543
1573
|
createdAt
|
|
@@ -1708,15 +1738,8 @@ function createGroupDeriver(state) {
|
|
|
1708
1738
|
const streaming = store.streamStatus === "streaming";
|
|
1709
1739
|
const patched = store.getMessages().map((m) => {
|
|
1710
1740
|
const patch = enrichments.resolveCitation(String(asSxin(m).id || ""));
|
|
1711
|
-
if (!patch) return m;
|
|
1712
|
-
return {
|
|
1713
|
-
...asSxin(m),
|
|
1714
|
-
...patch.content !== void 0 ? { content: patch.content } : {},
|
|
1715
|
-
additional_kwargs: {
|
|
1716
|
-
...asSxin(m).additional_kwargs ?? {},
|
|
1717
|
-
...patch.citationInfo !== void 0 ? { citation_info: patch.citationInfo } : {}
|
|
1718
|
-
}
|
|
1719
|
-
};
|
|
1741
|
+
if (!patch || patch.content === void 0) return m;
|
|
1742
|
+
return { ...asSxin(m), content: patch.content };
|
|
1720
1743
|
});
|
|
1721
1744
|
const sourceOf = (id) => id ? store.getEntity(id)?.source ?? "stream" : "stream";
|
|
1722
1745
|
const epochOf = (id) => id ? store.getEntity(id)?.epoch : void 0;
|
|
@@ -2544,12 +2567,6 @@ function createThreadStore(_options = {}) {
|
|
|
2544
2567
|
streamStatusRef
|
|
2545
2568
|
};
|
|
2546
2569
|
}
|
|
2547
|
-
function hasCitationInfo(v) {
|
|
2548
|
-
if (!v) return false;
|
|
2549
|
-
if (Array.isArray(v)) return v.length > 0;
|
|
2550
|
-
if (typeof v === "object") return Object.keys(v).length > 0;
|
|
2551
|
-
return Boolean(v);
|
|
2552
|
-
}
|
|
2553
2570
|
function readContentText(content) {
|
|
2554
2571
|
if (typeof content === "string") return content;
|
|
2555
2572
|
if (Array.isArray(content)) {
|
|
@@ -2558,10 +2575,8 @@ function readContentText(content) {
|
|
|
2558
2575
|
return "";
|
|
2559
2576
|
}
|
|
2560
2577
|
function isCitationCarrier(msg) {
|
|
2561
|
-
const m = asSxin(msg);
|
|
2562
2578
|
if (!isAiMessage(msg)) return false;
|
|
2563
|
-
|
|
2564
|
-
return hasCitationInfo(m.additional_kwargs?.citation_info);
|
|
2579
|
+
return readContentText(asSxin(msg).content).includes("support.kbCitation");
|
|
2565
2580
|
}
|
|
2566
2581
|
function createEnrichments() {
|
|
2567
2582
|
const citationPatches = shallowReactive2(/* @__PURE__ */ new Map());
|
|
@@ -2576,10 +2591,7 @@ function createEnrichments() {
|
|
|
2576
2591
|
const m = asSxin(msg);
|
|
2577
2592
|
const id = String(m.id || "").trim();
|
|
2578
2593
|
if (!id || !isCitationCarrier(msg)) continue;
|
|
2579
|
-
citationPatches.set(id, {
|
|
2580
|
-
content: m.content,
|
|
2581
|
-
citationInfo: m.additional_kwargs?.citation_info
|
|
2582
|
-
});
|
|
2594
|
+
citationPatches.set(id, { content: m.content });
|
|
2583
2595
|
citationVersion++;
|
|
2584
2596
|
}
|
|
2585
2597
|
const extracted = extractThreadInfo(messages).clarificationAnswers;
|
|
@@ -3306,7 +3318,8 @@ export {
|
|
|
3306
3318
|
collectVisibleText,
|
|
3307
3319
|
collectTextKeepSxin,
|
|
3308
3320
|
tokenizeSxin,
|
|
3309
|
-
|
|
3321
|
+
extractCitationAnchorsFromSpec,
|
|
3322
|
+
extractCitationAnchors,
|
|
3310
3323
|
parseKnowledgeItemsFromValue,
|
|
3311
3324
|
genMessageId,
|
|
3312
3325
|
genBlockId,
|
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,6 @@ __export(src_exports, {
|
|
|
41
41
|
buildReportOutlinePayload: () => buildReportOutlinePayload,
|
|
42
42
|
buildRunDirectLatencyMs: () => buildRunDirectLatencyMs,
|
|
43
43
|
buildRunInfo: () => buildRunInfo,
|
|
44
|
-
collectCitation: () => collectCitation,
|
|
45
44
|
collectTextKeepSxin: () => collectTextKeepSxin,
|
|
46
45
|
collectVisibleText: () => collectVisibleText,
|
|
47
46
|
createBlockBuilderLite: () => createBlockBuilderLite,
|
|
@@ -59,6 +58,8 @@ __export(src_exports, {
|
|
|
59
58
|
extractAiContentFromMessage: () => extractAiContentFromMessage,
|
|
60
59
|
extractBlocksFromContent: () => extractBlocksFromContent,
|
|
61
60
|
extractBlocksFromNodes: () => extractBlocksFromNodes,
|
|
61
|
+
extractCitationAnchors: () => extractCitationAnchors,
|
|
62
|
+
extractCitationAnchorsFromSpec: () => extractCitationAnchorsFromSpec,
|
|
62
63
|
extractReportTitleFromBody: () => extractReportTitleFromBody,
|
|
63
64
|
extractRunEnrichment: () => extractRunEnrichment,
|
|
64
65
|
extractStateMessages: () => extractStateMessages,
|
|
@@ -626,18 +627,59 @@ var normalizeOne = (raw) => {
|
|
|
626
627
|
searchText: orUndefined(searchText)
|
|
627
628
|
};
|
|
628
629
|
};
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
630
|
+
var KB_CITATION_CONTRACT = "support.kbCitation";
|
|
631
|
+
var REF_ID_KEYS = ["ref-id", "refId", "ref_id", "citation-id", "citationId", "citation_id", "id"];
|
|
632
|
+
var SEARCH_TEXT_KEYS = ["search-text", "searchText", "search_text", "keyword"];
|
|
633
|
+
var REF_ID_LIST_KEY_RE = /^(ref|citation)[-_]?ids?$/i;
|
|
634
|
+
var isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
635
|
+
var pickFirstString = (obj, keys) => {
|
|
636
|
+
for (const k of keys) {
|
|
637
|
+
const v = obj?.[k];
|
|
638
|
+
if (v === void 0 || v === null) continue;
|
|
639
|
+
const s = String(v).trim();
|
|
640
|
+
if (s) return s;
|
|
640
641
|
}
|
|
642
|
+
return void 0;
|
|
643
|
+
};
|
|
644
|
+
function extractCitationAnchorsFromSpec(spec) {
|
|
645
|
+
const anchors = [];
|
|
646
|
+
const seen = /* @__PURE__ */ new Set();
|
|
647
|
+
const candidates = [];
|
|
648
|
+
if (isPlainObject(spec)) candidates.push(spec);
|
|
649
|
+
for (const [key, value] of Object.entries(spec || {})) {
|
|
650
|
+
if (Array.isArray(value)) {
|
|
651
|
+
for (const item of value) if (isPlainObject(item)) candidates.push(item);
|
|
652
|
+
} else if (typeof value === "string" && /,/.test(value) && REF_ID_LIST_KEY_RE.test(key)) {
|
|
653
|
+
for (const id of value.split(",")) candidates.push({ "ref-id": id });
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
for (const item of candidates) {
|
|
657
|
+
const refId = pickFirstString(item, REF_ID_KEYS);
|
|
658
|
+
if (!refId || seen.has(refId)) continue;
|
|
659
|
+
seen.add(refId);
|
|
660
|
+
const anchor = { refId, title: "" };
|
|
661
|
+
const searchText = pickFirstString(item, SEARCH_TEXT_KEYS);
|
|
662
|
+
if (searchText) anchor.searchText = searchText;
|
|
663
|
+
anchors.push(anchor);
|
|
664
|
+
}
|
|
665
|
+
return anchors;
|
|
666
|
+
}
|
|
667
|
+
function extractCitationAnchors(blocks) {
|
|
668
|
+
const anchors = [];
|
|
669
|
+
const seen = /* @__PURE__ */ new Set();
|
|
670
|
+
for (const block of blocks) {
|
|
671
|
+
if (block.type !== "custom") continue;
|
|
672
|
+
const custom = block;
|
|
673
|
+
if (custom.tagName !== "sxin-item") continue;
|
|
674
|
+
const spec = custom.spec || {};
|
|
675
|
+
if (String(spec.contract || "").trim() !== KB_CITATION_CONTRACT) continue;
|
|
676
|
+
for (const anchor of extractCitationAnchorsFromSpec(spec)) {
|
|
677
|
+
if (seen.has(anchor.refId)) continue;
|
|
678
|
+
seen.add(anchor.refId);
|
|
679
|
+
anchors.push(anchor);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return anchors;
|
|
641
683
|
}
|
|
642
684
|
function parseKnowledgeItemsFromValue(value) {
|
|
643
685
|
if (!value) return [];
|
|
@@ -1302,11 +1344,6 @@ function walkNodes(ctx, nodes) {
|
|
|
1302
1344
|
if (isInjectedElement(node)) {
|
|
1303
1345
|
continue;
|
|
1304
1346
|
}
|
|
1305
|
-
if (node.tagName === "sxin-kb-citation" && node.closed) {
|
|
1306
|
-
flushTextBuf(ctx);
|
|
1307
|
-
collectCitation(node, ctx.citations);
|
|
1308
|
-
continue;
|
|
1309
|
-
}
|
|
1310
1347
|
if (node.tagName.startsWith("sxin-")) {
|
|
1311
1348
|
if (!handleSxinElement(ctx, node)) return false;
|
|
1312
1349
|
continue;
|
|
@@ -1322,12 +1359,11 @@ function extractBlocksFromNodes(nodes, rawText, source) {
|
|
|
1322
1359
|
isHistory,
|
|
1323
1360
|
status: isHistory ? "completed" : "streaming",
|
|
1324
1361
|
blocks: [],
|
|
1325
|
-
citations: [],
|
|
1326
1362
|
textBuf: { value: "" }
|
|
1327
1363
|
};
|
|
1328
1364
|
const completed = walkNodes(ctx, nodes);
|
|
1329
1365
|
if (completed) flushTextBuf(ctx);
|
|
1330
|
-
return { blocks: ctx.blocks
|
|
1366
|
+
return { blocks: ctx.blocks };
|
|
1331
1367
|
}
|
|
1332
1368
|
function extractBlocksFromContent(rawText, source) {
|
|
1333
1369
|
return extractBlocksFromNodes(tokenizeSxin(rawText), rawText, source);
|
|
@@ -1647,20 +1683,12 @@ function createBlockBuilderLite(options) {
|
|
|
1647
1683
|
const blocks = [];
|
|
1648
1684
|
const status = isStreaming ? "streaming" : "completed";
|
|
1649
1685
|
const contentSource = source === "state" ? "history" : source;
|
|
1650
|
-
const { blocks: contentBlocks
|
|
1686
|
+
const { blocks: contentBlocks } = extractBlocksFromNodes(nodes, rawText, contentSource);
|
|
1651
1687
|
blocks.push(...contentBlocks);
|
|
1652
1688
|
for (const tool of tools) {
|
|
1653
1689
|
const toolBlocks = parseBlockTool(tool, status);
|
|
1654
1690
|
blocks.push(...toolBlocks);
|
|
1655
1691
|
}
|
|
1656
|
-
if (citations.length > 0) {
|
|
1657
|
-
blocks.push({
|
|
1658
|
-
id: genBlockId(),
|
|
1659
|
-
type: "citation",
|
|
1660
|
-
items: citations.map((c) => ({ ...c, title: c.title || "" })),
|
|
1661
|
-
status
|
|
1662
|
-
});
|
|
1663
|
-
}
|
|
1664
1692
|
if (twinEnabled) {
|
|
1665
1693
|
const twinTool = tools.reverse().find((_) => _.call?.name.includes(twinToolPrefix));
|
|
1666
1694
|
if (twinTool) {
|
|
@@ -1749,6 +1777,8 @@ function buildAiGroup(messages, options, twin) {
|
|
|
1749
1777
|
content,
|
|
1750
1778
|
groupTools
|
|
1751
1779
|
);
|
|
1780
|
+
const anchors = extractCitationAnchors(blocks);
|
|
1781
|
+
const citations = anchors.length ? anchors : void 0;
|
|
1752
1782
|
return {
|
|
1753
1783
|
id: firstId,
|
|
1754
1784
|
type: "ai",
|
|
@@ -1757,6 +1787,7 @@ function buildAiGroup(messages, options, twin) {
|
|
|
1757
1787
|
runId: messageRunId(lastAi) || options.runId,
|
|
1758
1788
|
rawMessages: messages,
|
|
1759
1789
|
blocks,
|
|
1790
|
+
citations,
|
|
1760
1791
|
toolIds: groupTools.map((t) => t.id),
|
|
1761
1792
|
tools: groupTools,
|
|
1762
1793
|
createdAt
|
|
@@ -1927,15 +1958,8 @@ function createGroupDeriver(state) {
|
|
|
1927
1958
|
const streaming = store.streamStatus === "streaming";
|
|
1928
1959
|
const patched = store.getMessages().map((m) => {
|
|
1929
1960
|
const patch = enrichments.resolveCitation(String(asSxin(m).id || ""));
|
|
1930
|
-
if (!patch) return m;
|
|
1931
|
-
return {
|
|
1932
|
-
...asSxin(m),
|
|
1933
|
-
...patch.content !== void 0 ? { content: patch.content } : {},
|
|
1934
|
-
additional_kwargs: {
|
|
1935
|
-
...asSxin(m).additional_kwargs ?? {},
|
|
1936
|
-
...patch.citationInfo !== void 0 ? { citation_info: patch.citationInfo } : {}
|
|
1937
|
-
}
|
|
1938
|
-
};
|
|
1961
|
+
if (!patch || patch.content === void 0) return m;
|
|
1962
|
+
return { ...asSxin(m), content: patch.content };
|
|
1939
1963
|
});
|
|
1940
1964
|
const sourceOf = (id) => id ? store.getEntity(id)?.source ?? "stream" : "stream";
|
|
1941
1965
|
const epochOf = (id) => id ? store.getEntity(id)?.epoch : void 0;
|
|
@@ -2763,12 +2787,6 @@ function createThreadStore(_options = {}) {
|
|
|
2763
2787
|
streamStatusRef
|
|
2764
2788
|
};
|
|
2765
2789
|
}
|
|
2766
|
-
function hasCitationInfo(v) {
|
|
2767
|
-
if (!v) return false;
|
|
2768
|
-
if (Array.isArray(v)) return v.length > 0;
|
|
2769
|
-
if (typeof v === "object") return Object.keys(v).length > 0;
|
|
2770
|
-
return Boolean(v);
|
|
2771
|
-
}
|
|
2772
2790
|
function readContentText(content) {
|
|
2773
2791
|
if (typeof content === "string") return content;
|
|
2774
2792
|
if (Array.isArray(content)) {
|
|
@@ -2777,10 +2795,8 @@ function readContentText(content) {
|
|
|
2777
2795
|
return "";
|
|
2778
2796
|
}
|
|
2779
2797
|
function isCitationCarrier(msg) {
|
|
2780
|
-
const m = asSxin(msg);
|
|
2781
2798
|
if (!isAiMessage(msg)) return false;
|
|
2782
|
-
|
|
2783
|
-
return hasCitationInfo(m.additional_kwargs?.citation_info);
|
|
2799
|
+
return readContentText(asSxin(msg).content).includes("support.kbCitation");
|
|
2784
2800
|
}
|
|
2785
2801
|
function createEnrichments() {
|
|
2786
2802
|
const citationPatches = (0, import_vue5.shallowReactive)(/* @__PURE__ */ new Map());
|
|
@@ -2795,10 +2811,7 @@ function createEnrichments() {
|
|
|
2795
2811
|
const m = asSxin(msg);
|
|
2796
2812
|
const id = String(m.id || "").trim();
|
|
2797
2813
|
if (!id || !isCitationCarrier(msg)) continue;
|
|
2798
|
-
citationPatches.set(id, {
|
|
2799
|
-
content: m.content,
|
|
2800
|
-
citationInfo: m.additional_kwargs?.citation_info
|
|
2801
|
-
});
|
|
2814
|
+
citationPatches.set(id, { content: m.content });
|
|
2802
2815
|
citationVersion++;
|
|
2803
2816
|
}
|
|
2804
2817
|
const extracted = extractThreadInfo(messages).clarificationAnswers;
|
|
@@ -3720,7 +3733,6 @@ var CORE_VERSION = "2.0.0";
|
|
|
3720
3733
|
buildReportOutlinePayload,
|
|
3721
3734
|
buildRunDirectLatencyMs,
|
|
3722
3735
|
buildRunInfo,
|
|
3723
|
-
collectCitation,
|
|
3724
3736
|
collectTextKeepSxin,
|
|
3725
3737
|
collectVisibleText,
|
|
3726
3738
|
createBlockBuilderLite,
|
|
@@ -3738,6 +3750,8 @@ var CORE_VERSION = "2.0.0";
|
|
|
3738
3750
|
extractAiContentFromMessage,
|
|
3739
3751
|
extractBlocksFromContent,
|
|
3740
3752
|
extractBlocksFromNodes,
|
|
3753
|
+
extractCitationAnchors,
|
|
3754
|
+
extractCitationAnchorsFromSpec,
|
|
3741
3755
|
extractReportTitleFromBody,
|
|
3742
3756
|
extractRunEnrichment,
|
|
3743
3757
|
extractStateMessages,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CreateStreamOptions, a as ChatStreamHandle, S as SxinNode, E as ElementNode, b as CitationItem, I as IKwargs, R as RunInfo, c as RunMessage, d as ReportBodyPayload, e as ReportOutlinePayload,
|
|
2
|
-
export { A as AcquireResult, q as AgentThreadState, r as ArtifactBlock, s as ArtifactFile, t as AskClarificationBlock, u as BlockBase, v as BlockBuilderLite, w as BlockSource, x as BlockStatus, y as BuildAllOptions, z as ChatCore, D as ChatCoreOptions, F as ChatNotify, J as
|
|
1
|
+
import { C as CreateStreamOptions, a as ChatStreamHandle, S as SxinNode, E as ElementNode, B as Block, b as CitationItem, I as IKwargs, R as RunInfo, c as RunMessage, d as ReportBodyPayload, e as ReportOutlinePayload, f as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, g as OutlineChapter, h as GroupMessageType, i as BlockBuilderLiteOptions, j as GroupMessage, k as SendMessageOptions, l as ChatTransport, T as ThreadInitialValues, m as MessagesPage, n as ThreadTokenUsage, o as StreamSubmitInput, p as StreamSubmitOptions, H as HitlResponse } from './ChatCore-C-G9isDM.cjs';
|
|
2
|
+
export { A as AcquireResult, q as AgentThreadState, r as ArtifactBlock, s as ArtifactFile, t as AskClarificationBlock, u as BlockBase, v as BlockBuilderLite, w as BlockSource, x as BlockStatus, y as BuildAllOptions, z as ChatCore, D as ChatCoreOptions, F as ChatNotify, J as CommentNode, K as CustomBlock, L as DEFAULT_TWIN_TOOL_PREFIX, N as FetchMessagesPageOptions, P as FormBlock, Q as FormFieldItem, U as FormFieldType, V as GenerateBodyRequest, W as GenerateBodyResult, X as GroupMessageSource, Y as GroupMessageStatus, Z as HitlActionRequest, _ as HitlDecision, $ as HitlDecisionType, a0 as HitlInterruptPayload, a1 as HitlReviewConfig, a2 as IAttachment, a3 as IQuote, a4 as InlineCitation, a5 as InterruptReviewBlock, a6 as ListBlock, a7 as ListItem, a8 as Message, a9 as MessageMetadata, aa as MessageRole, ab as MessageSource, ac as MessageStatus, ad as ReportBodyBlock, ae as ReportGenerateBodyHumanKwargs, af as ReportOutlineBlock, ag as ReportSelectedArtifact, ah as ReportSelectedTemplate, ai as SearchThreadsOptions, aj as TextBlock, ak as TextNode, al as ThreadDirectory, am as ThreadDirectoryOptions, an as ThreadRuntime, ao as ThreadRuntimeOptions, ap as ThreadsPagination, aq as TwinBlock, ar as buildHitlDecisions, as as buildInterruptReviewBlock, at as buildInterruptReviewGroup, au as buildRejectDecisions, av as buildRunDirectLatencyMs, aw as buildRunInfo, ax as createBlockBuilderLite, ay as createChatCore, az as createThreadRuntime, aA as getAllowedDecisions, aB as isSameArgs, aC as normalizeForCompare, aD as parseHitlPayload, aE as pickRunMessageMetadata } from './ChatCore-C-G9isDM.cjs';
|
|
3
3
|
import { Message, Interrupt } from '@langchain/langgraph-sdk';
|
|
4
4
|
import { Ref, ShallowRef } from 'vue';
|
|
5
5
|
|
|
@@ -137,7 +137,7 @@ declare function collectVisibleText(source: string, nodes: SxinNode[]): string;
|
|
|
137
137
|
* 提取文本但保留 sxin 协议标签原文(AI 内容管线专用)。
|
|
138
138
|
* 剔除 think / 系统注入等注入标签(见 INJECTED_TAGS,未闭合同样剔除),
|
|
139
139
|
* 其余(文本 / 注释 / sxin 标签 / 正文 HTML / 未闭合非注入元素)按原文保留,
|
|
140
|
-
* 供 extractBlocksFromContent 二次解析为 custom
|
|
140
|
+
* 供 extractBlocksFromContent 二次解析为 custom block。
|
|
141
141
|
*/
|
|
142
142
|
declare function collectTextKeepSxin(source: string, nodes: SxinNode[]): string;
|
|
143
143
|
|
|
@@ -163,20 +163,16 @@ declare function collectTextKeepSxin(source: string, nodes: SxinNode[]): string;
|
|
|
163
163
|
declare function tokenizeSxin(source: string): SxinNode[];
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
* 知识引用(citation
|
|
167
|
-
*
|
|
166
|
+
* 知识引用(citation)解析工具(协议切换后的两通道分工):
|
|
167
|
+
* 将后端下发的引用数据归一化为 KnowledgeItem / CitationItem。
|
|
168
168
|
*
|
|
169
|
-
*
|
|
170
|
-
* 1. state
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* 3. web 消费通道(本包的输出侧):UI 按 CitationItem.refId 从 KnowledgeItem(本文件
|
|
177
|
-
* 归一 payload 通道的完整详情:minio/docUrl/页码/高亮)拉取展示数据。
|
|
178
|
-
* KnowledgeItem(详情,payload 通道)与 CitationItem(锚点,标签通道)服务不同阶段,
|
|
179
|
-
* 双类型是刻意设计,不是冗余。
|
|
169
|
+
* 【通道分工】:
|
|
170
|
+
* 1. state 通道(重开恢复):page 接口不含 sxin-item citation 标签,store/enrichments 在
|
|
171
|
+
* ingestion 时按消息 id 采集 content 补丁(citationPatches Map),构建期注入消息副本。
|
|
172
|
+
* 2. 锚点通道(消息级数据):buildAiGroup 完成 blocks 构建后,经 extractCitationAnchors
|
|
173
|
+
* 从 sxin-item contract="support.kbCitation" 块提取 refId 锚点挂到 GroupMessage.citations,
|
|
174
|
+
* 供行内 [n] 角标映射与渲染层合并;渲染本身走 sxin-item 自定义渲染链(被动,无特判)。
|
|
175
|
+
* KnowledgeItem(详情,payload 通道)与 CitationItem(锚点)服务不同阶段,双类型是刻意设计。
|
|
180
176
|
*/
|
|
181
177
|
|
|
182
178
|
/** 知识引用项接口 */
|
|
@@ -200,14 +196,16 @@ interface KnowledgeItem {
|
|
|
200
196
|
searchText?: string;
|
|
201
197
|
}
|
|
202
198
|
/**
|
|
203
|
-
* 从 sxin-
|
|
204
|
-
*
|
|
205
|
-
* 此处产出的 CitationItem 是轻量锚点,web 按 refId 再拉 KnowledgeItem 详情,
|
|
206
|
-
* 与 store/enrichments 的 CitationPatch(state 通道补丁)服务对象不同,勿混)。
|
|
207
|
-
* citation 双归一器同文件两出口:
|
|
208
|
-
* KnowledgeItem(payload 通道,parseKnowledgeItemsFromValue)与 CitationItem(标签通道,本函数)。
|
|
199
|
+
* 从 sxin-item spec 中提取 citation 锚点(contract 已判定的单块入口)。
|
|
200
|
+
* 兼容 refId 来源:spec 自身属性 / ref-ids 列表属性(数组或逗号串)/ 任意子项数组的 refId 系字段。
|
|
209
201
|
*/
|
|
210
|
-
declare function
|
|
202
|
+
declare function extractCitationAnchorsFromSpec(spec: Record<string, any>): CitationItem[];
|
|
203
|
+
/**
|
|
204
|
+
* 从 blocks 中提取 citation 锚点(sxin-item contract="support.kbCitation" 块 → CitationItem)。
|
|
205
|
+
* 顺序即正文 [n] 角标序号;跨块同 refId 去重保留首个(含其 searchText)。
|
|
206
|
+
* 供 buildAiGroup 装饰 GroupMessage.citations 使用。
|
|
207
|
+
*/
|
|
208
|
+
declare function extractCitationAnchors(blocks: Block[]): CitationItem[];
|
|
211
209
|
/** 从任意数据(数组/单对象)中解析知识引用项列表,逐项归一化并过滤无效项 */
|
|
212
210
|
declare function parseKnowledgeItemsFromValue(value: any): KnowledgeItem[];
|
|
213
211
|
|
|
@@ -305,7 +303,7 @@ declare function extractTextFromMessage(msg: any): string;
|
|
|
305
303
|
/**
|
|
306
304
|
* 提取 AI 正文(block 构建 / 流式渲染管线专用,如 group-builder 喂给 block builder)。
|
|
307
305
|
* 剔除 think / 系统注入标签,保留 sxin-* 协议标签与注释原文,
|
|
308
|
-
* 供 extractBlocksFromContent 二次解析为 custom
|
|
306
|
+
* 供 extractBlocksFromContent 二次解析为 custom block。
|
|
309
307
|
*/
|
|
310
308
|
declare function extractAiContentFromMessage(msg: any): string;
|
|
311
309
|
/**
|
|
@@ -373,7 +371,7 @@ declare function buildReportBodyPayload(input: {
|
|
|
373
371
|
createdAt?: number;
|
|
374
372
|
}): ReportBodyPayload;
|
|
375
373
|
/**
|
|
376
|
-
* 把 AST 节点序列拆分为 text / chart / custom
|
|
374
|
+
* 把 AST 节点序列拆分为 text / chart / custom block。
|
|
377
375
|
* 供已 tokenize 的调用方直接使用(如 group-builder → BlockBuilderLite.buildFromNodes),
|
|
378
376
|
* 避免 content 被二次解析;未闭合 sxin 标签的收尾策略按 source 区分(见 walkNodes 内注释)。
|
|
379
377
|
*
|
|
@@ -382,16 +380,14 @@ declare function buildReportBodyPayload(input: {
|
|
|
382
380
|
*/
|
|
383
381
|
declare function extractBlocksFromNodes(nodes: SxinNode[], rawText: string, source: BlockBuilderOptions['source']): {
|
|
384
382
|
blocks: Block[];
|
|
385
|
-
citations: CitationItem[];
|
|
386
383
|
};
|
|
387
384
|
/**
|
|
388
|
-
* 把 assistant 正文拆分为 text / chart / custom
|
|
385
|
+
* 把 assistant 正文拆分为 text / chart / custom block 序列。
|
|
389
386
|
* tokenize + 遍历的便捷封装,适合未提前 tokenize 的调用方;
|
|
390
387
|
* 已持有节点树的调用方请直接用 extractBlocksFromNodes,避免重复解析。
|
|
391
388
|
*/
|
|
392
389
|
declare function extractBlocksFromContent(rawText: string, source: BlockBuilderOptions['source']): {
|
|
393
390
|
blocks: Block[];
|
|
394
|
-
citations: CitationItem[];
|
|
395
391
|
};
|
|
396
392
|
|
|
397
393
|
/** 判断是否为 human 消息 */
|
|
@@ -545,10 +541,9 @@ interface ThreadStore {
|
|
|
545
541
|
/** 流状态响应式镜像(与 streamStatus 同步) */
|
|
546
542
|
readonly streamStatusRef: ShallowRef<StreamStatus>;
|
|
547
543
|
}
|
|
548
|
-
/** citation 补丁:viewmodel 构建 blocks 时注入到 AI 消息(content
|
|
544
|
+
/** citation 补丁:viewmodel 构建 blocks 时注入到 AI 消息(content 回补 state 侧标签) */
|
|
549
545
|
interface CitationPatch {
|
|
550
546
|
content?: unknown;
|
|
551
|
-
citationInfo?: unknown;
|
|
552
547
|
}
|
|
553
548
|
interface Enrichments {
|
|
554
549
|
/** init 装配:从 state 侧消息一次提取 citation + 澄清回答(可多次调用,合并语义) */
|
|
@@ -726,4 +721,4 @@ declare function createMockTransport(): MockTransport;
|
|
|
726
721
|
/** 包版本常量,发布时由人工随 package.json 同步(changesets 只改 package.json,此处发版时核对) */
|
|
727
722
|
declare const CORE_VERSION = "2.0.0";
|
|
728
723
|
|
|
729
|
-
export { Block, BlockBuilderLiteOptions, BlockBuilderOptions, type BuildGroupsResult, CORE_VERSION, ChatStreamHandle, ChatTransport, CitationItem, CreateStreamOptions, DEFAULT_ASSISTANT_ID, DEFAULT_MAX_CACHED_SESSIONS, DEFAULT_MAX_CONCURRENT_STREAMS, type DeriveGroupsDeps, ElementNode, type GroupDeriver, GroupMessage, GroupMessageTool, GroupMessageType, HitlResponse, type HumanInputResponseOptions, IKwargs, INJECTED_TAGS, type InstructionSink, type KnowledgeItem, MESSAGE_TYPE_NORMALIZE, MessageTokenUsage, MessagesPage, type MockStreamSnapshot, type MockTransport, type MockTransportCalls, OUTLINE_MAX_LEVEL, OutlineChapter, OutlineSubChapter, ReportBodyPayload, ReportOutlinePayload, RunInfo, RunMessage, type RunStreamPayload, SendMessageOptions, type StreamEvent, type StreamEventSource, StreamSubmitInput, StreamSubmitOptions, type SxinMessage, SxinNode, type ThreadInfo, ThreadInitialValues, type ThreadInstruction, ThreadTokenUsage, type ViewModelState, buildAiGroup, buildArtifactFiles, buildHumanGroup, buildHumanInputResponse, buildReportBodyPayload, buildReportOutlinePayload,
|
|
724
|
+
export { Block, BlockBuilderLiteOptions, BlockBuilderOptions, type BuildGroupsResult, CORE_VERSION, ChatStreamHandle, ChatTransport, CitationItem, CreateStreamOptions, DEFAULT_ASSISTANT_ID, DEFAULT_MAX_CACHED_SESSIONS, DEFAULT_MAX_CONCURRENT_STREAMS, type DeriveGroupsDeps, ElementNode, type GroupDeriver, GroupMessage, GroupMessageTool, GroupMessageType, HitlResponse, type HumanInputResponseOptions, IKwargs, INJECTED_TAGS, type InstructionSink, type KnowledgeItem, MESSAGE_TYPE_NORMALIZE, MessageTokenUsage, MessagesPage, type MockStreamSnapshot, type MockTransport, type MockTransportCalls, OUTLINE_MAX_LEVEL, OutlineChapter, OutlineSubChapter, ReportBodyPayload, ReportOutlinePayload, RunInfo, RunMessage, type RunStreamPayload, SendMessageOptions, type StreamEvent, type StreamEventSource, StreamSubmitInput, StreamSubmitOptions, type SxinMessage, SxinNode, type ThreadInfo, ThreadInitialValues, type ThreadInstruction, ThreadTokenUsage, type ViewModelState, buildAiGroup, buildArtifactFiles, buildHumanGroup, buildHumanInputResponse, buildReportBodyPayload, buildReportOutlinePayload, collectTextKeepSxin, collectVisibleText, createEmptySubChapter, createGroupDeriver, createMockTransport, createOptimisticHuman, createStreamPump, createViewModelState, deriveToolsFromMessages, ensureOutlineContentThemes, ensureRunningRun, extractAiContentFromMessage, extractBlocksFromContent, extractBlocksFromNodes, extractCitationAnchors, extractCitationAnchorsFromSpec, extractReportTitleFromBody, extractRunEnrichment, extractStateMessages, extractTextFromMessage, extractThreadInfo, extractTitleFromArtifactPath, extractUserMessageTexts, foldMessages, formatStr, genBlockId, genMessageId, getHumanMessageBaseId, getToolCallArtifactMeta, isAiMessage, isClarificationAnswered, isClarificationBlock, isHiddenUserMessage, isHumanMessage, isInjectedElement, isReportBodyHtml, isToolMessage, isVisibleUserMessage, isWriteFileToolName, normalizeMessageType, normalizeOutline, normalizeUsage, parseHumanMessageId, parseKnowledgeItemsFromValue, parseMarkdownToOutline, readMessageContentText, resolveReportArtifactKind, runMessagesToMessages, simpleHash, stateMessagesToRunMessages, toRunMessage, tokenizeSxin, validateOutline };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CreateStreamOptions, a as ChatStreamHandle, S as SxinNode, E as ElementNode, b as CitationItem, I as IKwargs, R as RunInfo, c as RunMessage, d as ReportBodyPayload, e as ReportOutlinePayload,
|
|
2
|
-
export { A as AcquireResult, q as AgentThreadState, r as ArtifactBlock, s as ArtifactFile, t as AskClarificationBlock, u as BlockBase, v as BlockBuilderLite, w as BlockSource, x as BlockStatus, y as BuildAllOptions, z as ChatCore, D as ChatCoreOptions, F as ChatNotify, J as
|
|
1
|
+
import { C as CreateStreamOptions, a as ChatStreamHandle, S as SxinNode, E as ElementNode, B as Block, b as CitationItem, I as IKwargs, R as RunInfo, c as RunMessage, d as ReportBodyPayload, e as ReportOutlinePayload, f as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, g as OutlineChapter, h as GroupMessageType, i as BlockBuilderLiteOptions, j as GroupMessage, k as SendMessageOptions, l as ChatTransport, T as ThreadInitialValues, m as MessagesPage, n as ThreadTokenUsage, o as StreamSubmitInput, p as StreamSubmitOptions, H as HitlResponse } from './ChatCore-C-G9isDM.js';
|
|
2
|
+
export { A as AcquireResult, q as AgentThreadState, r as ArtifactBlock, s as ArtifactFile, t as AskClarificationBlock, u as BlockBase, v as BlockBuilderLite, w as BlockSource, x as BlockStatus, y as BuildAllOptions, z as ChatCore, D as ChatCoreOptions, F as ChatNotify, J as CommentNode, K as CustomBlock, L as DEFAULT_TWIN_TOOL_PREFIX, N as FetchMessagesPageOptions, P as FormBlock, Q as FormFieldItem, U as FormFieldType, V as GenerateBodyRequest, W as GenerateBodyResult, X as GroupMessageSource, Y as GroupMessageStatus, Z as HitlActionRequest, _ as HitlDecision, $ as HitlDecisionType, a0 as HitlInterruptPayload, a1 as HitlReviewConfig, a2 as IAttachment, a3 as IQuote, a4 as InlineCitation, a5 as InterruptReviewBlock, a6 as ListBlock, a7 as ListItem, a8 as Message, a9 as MessageMetadata, aa as MessageRole, ab as MessageSource, ac as MessageStatus, ad as ReportBodyBlock, ae as ReportGenerateBodyHumanKwargs, af as ReportOutlineBlock, ag as ReportSelectedArtifact, ah as ReportSelectedTemplate, ai as SearchThreadsOptions, aj as TextBlock, ak as TextNode, al as ThreadDirectory, am as ThreadDirectoryOptions, an as ThreadRuntime, ao as ThreadRuntimeOptions, ap as ThreadsPagination, aq as TwinBlock, ar as buildHitlDecisions, as as buildInterruptReviewBlock, at as buildInterruptReviewGroup, au as buildRejectDecisions, av as buildRunDirectLatencyMs, aw as buildRunInfo, ax as createBlockBuilderLite, ay as createChatCore, az as createThreadRuntime, aA as getAllowedDecisions, aB as isSameArgs, aC as normalizeForCompare, aD as parseHitlPayload, aE as pickRunMessageMetadata } from './ChatCore-C-G9isDM.js';
|
|
3
3
|
import { Message, Interrupt } from '@langchain/langgraph-sdk';
|
|
4
4
|
import { Ref, ShallowRef } from 'vue';
|
|
5
5
|
|
|
@@ -137,7 +137,7 @@ declare function collectVisibleText(source: string, nodes: SxinNode[]): string;
|
|
|
137
137
|
* 提取文本但保留 sxin 协议标签原文(AI 内容管线专用)。
|
|
138
138
|
* 剔除 think / 系统注入等注入标签(见 INJECTED_TAGS,未闭合同样剔除),
|
|
139
139
|
* 其余(文本 / 注释 / sxin 标签 / 正文 HTML / 未闭合非注入元素)按原文保留,
|
|
140
|
-
* 供 extractBlocksFromContent 二次解析为 custom
|
|
140
|
+
* 供 extractBlocksFromContent 二次解析为 custom block。
|
|
141
141
|
*/
|
|
142
142
|
declare function collectTextKeepSxin(source: string, nodes: SxinNode[]): string;
|
|
143
143
|
|
|
@@ -163,20 +163,16 @@ declare function collectTextKeepSxin(source: string, nodes: SxinNode[]): string;
|
|
|
163
163
|
declare function tokenizeSxin(source: string): SxinNode[];
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
* 知识引用(citation
|
|
167
|
-
*
|
|
166
|
+
* 知识引用(citation)解析工具(协议切换后的两通道分工):
|
|
167
|
+
* 将后端下发的引用数据归一化为 KnowledgeItem / CitationItem。
|
|
168
168
|
*
|
|
169
|
-
*
|
|
170
|
-
* 1. state
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* 3. web 消费通道(本包的输出侧):UI 按 CitationItem.refId 从 KnowledgeItem(本文件
|
|
177
|
-
* 归一 payload 通道的完整详情:minio/docUrl/页码/高亮)拉取展示数据。
|
|
178
|
-
* KnowledgeItem(详情,payload 通道)与 CitationItem(锚点,标签通道)服务不同阶段,
|
|
179
|
-
* 双类型是刻意设计,不是冗余。
|
|
169
|
+
* 【通道分工】:
|
|
170
|
+
* 1. state 通道(重开恢复):page 接口不含 sxin-item citation 标签,store/enrichments 在
|
|
171
|
+
* ingestion 时按消息 id 采集 content 补丁(citationPatches Map),构建期注入消息副本。
|
|
172
|
+
* 2. 锚点通道(消息级数据):buildAiGroup 完成 blocks 构建后,经 extractCitationAnchors
|
|
173
|
+
* 从 sxin-item contract="support.kbCitation" 块提取 refId 锚点挂到 GroupMessage.citations,
|
|
174
|
+
* 供行内 [n] 角标映射与渲染层合并;渲染本身走 sxin-item 自定义渲染链(被动,无特判)。
|
|
175
|
+
* KnowledgeItem(详情,payload 通道)与 CitationItem(锚点)服务不同阶段,双类型是刻意设计。
|
|
180
176
|
*/
|
|
181
177
|
|
|
182
178
|
/** 知识引用项接口 */
|
|
@@ -200,14 +196,16 @@ interface KnowledgeItem {
|
|
|
200
196
|
searchText?: string;
|
|
201
197
|
}
|
|
202
198
|
/**
|
|
203
|
-
* 从 sxin-
|
|
204
|
-
*
|
|
205
|
-
* 此处产出的 CitationItem 是轻量锚点,web 按 refId 再拉 KnowledgeItem 详情,
|
|
206
|
-
* 与 store/enrichments 的 CitationPatch(state 通道补丁)服务对象不同,勿混)。
|
|
207
|
-
* citation 双归一器同文件两出口:
|
|
208
|
-
* KnowledgeItem(payload 通道,parseKnowledgeItemsFromValue)与 CitationItem(标签通道,本函数)。
|
|
199
|
+
* 从 sxin-item spec 中提取 citation 锚点(contract 已判定的单块入口)。
|
|
200
|
+
* 兼容 refId 来源:spec 自身属性 / ref-ids 列表属性(数组或逗号串)/ 任意子项数组的 refId 系字段。
|
|
209
201
|
*/
|
|
210
|
-
declare function
|
|
202
|
+
declare function extractCitationAnchorsFromSpec(spec: Record<string, any>): CitationItem[];
|
|
203
|
+
/**
|
|
204
|
+
* 从 blocks 中提取 citation 锚点(sxin-item contract="support.kbCitation" 块 → CitationItem)。
|
|
205
|
+
* 顺序即正文 [n] 角标序号;跨块同 refId 去重保留首个(含其 searchText)。
|
|
206
|
+
* 供 buildAiGroup 装饰 GroupMessage.citations 使用。
|
|
207
|
+
*/
|
|
208
|
+
declare function extractCitationAnchors(blocks: Block[]): CitationItem[];
|
|
211
209
|
/** 从任意数据(数组/单对象)中解析知识引用项列表,逐项归一化并过滤无效项 */
|
|
212
210
|
declare function parseKnowledgeItemsFromValue(value: any): KnowledgeItem[];
|
|
213
211
|
|
|
@@ -305,7 +303,7 @@ declare function extractTextFromMessage(msg: any): string;
|
|
|
305
303
|
/**
|
|
306
304
|
* 提取 AI 正文(block 构建 / 流式渲染管线专用,如 group-builder 喂给 block builder)。
|
|
307
305
|
* 剔除 think / 系统注入标签,保留 sxin-* 协议标签与注释原文,
|
|
308
|
-
* 供 extractBlocksFromContent 二次解析为 custom
|
|
306
|
+
* 供 extractBlocksFromContent 二次解析为 custom block。
|
|
309
307
|
*/
|
|
310
308
|
declare function extractAiContentFromMessage(msg: any): string;
|
|
311
309
|
/**
|
|
@@ -373,7 +371,7 @@ declare function buildReportBodyPayload(input: {
|
|
|
373
371
|
createdAt?: number;
|
|
374
372
|
}): ReportBodyPayload;
|
|
375
373
|
/**
|
|
376
|
-
* 把 AST 节点序列拆分为 text / chart / custom
|
|
374
|
+
* 把 AST 节点序列拆分为 text / chart / custom block。
|
|
377
375
|
* 供已 tokenize 的调用方直接使用(如 group-builder → BlockBuilderLite.buildFromNodes),
|
|
378
376
|
* 避免 content 被二次解析;未闭合 sxin 标签的收尾策略按 source 区分(见 walkNodes 内注释)。
|
|
379
377
|
*
|
|
@@ -382,16 +380,14 @@ declare function buildReportBodyPayload(input: {
|
|
|
382
380
|
*/
|
|
383
381
|
declare function extractBlocksFromNodes(nodes: SxinNode[], rawText: string, source: BlockBuilderOptions['source']): {
|
|
384
382
|
blocks: Block[];
|
|
385
|
-
citations: CitationItem[];
|
|
386
383
|
};
|
|
387
384
|
/**
|
|
388
|
-
* 把 assistant 正文拆分为 text / chart / custom
|
|
385
|
+
* 把 assistant 正文拆分为 text / chart / custom block 序列。
|
|
389
386
|
* tokenize + 遍历的便捷封装,适合未提前 tokenize 的调用方;
|
|
390
387
|
* 已持有节点树的调用方请直接用 extractBlocksFromNodes,避免重复解析。
|
|
391
388
|
*/
|
|
392
389
|
declare function extractBlocksFromContent(rawText: string, source: BlockBuilderOptions['source']): {
|
|
393
390
|
blocks: Block[];
|
|
394
|
-
citations: CitationItem[];
|
|
395
391
|
};
|
|
396
392
|
|
|
397
393
|
/** 判断是否为 human 消息 */
|
|
@@ -545,10 +541,9 @@ interface ThreadStore {
|
|
|
545
541
|
/** 流状态响应式镜像(与 streamStatus 同步) */
|
|
546
542
|
readonly streamStatusRef: ShallowRef<StreamStatus>;
|
|
547
543
|
}
|
|
548
|
-
/** citation 补丁:viewmodel 构建 blocks 时注入到 AI 消息(content
|
|
544
|
+
/** citation 补丁:viewmodel 构建 blocks 时注入到 AI 消息(content 回补 state 侧标签) */
|
|
549
545
|
interface CitationPatch {
|
|
550
546
|
content?: unknown;
|
|
551
|
-
citationInfo?: unknown;
|
|
552
547
|
}
|
|
553
548
|
interface Enrichments {
|
|
554
549
|
/** init 装配:从 state 侧消息一次提取 citation + 澄清回答(可多次调用,合并语义) */
|
|
@@ -726,4 +721,4 @@ declare function createMockTransport(): MockTransport;
|
|
|
726
721
|
/** 包版本常量,发布时由人工随 package.json 同步(changesets 只改 package.json,此处发版时核对) */
|
|
727
722
|
declare const CORE_VERSION = "2.0.0";
|
|
728
723
|
|
|
729
|
-
export { Block, BlockBuilderLiteOptions, BlockBuilderOptions, type BuildGroupsResult, CORE_VERSION, ChatStreamHandle, ChatTransport, CitationItem, CreateStreamOptions, DEFAULT_ASSISTANT_ID, DEFAULT_MAX_CACHED_SESSIONS, DEFAULT_MAX_CONCURRENT_STREAMS, type DeriveGroupsDeps, ElementNode, type GroupDeriver, GroupMessage, GroupMessageTool, GroupMessageType, HitlResponse, type HumanInputResponseOptions, IKwargs, INJECTED_TAGS, type InstructionSink, type KnowledgeItem, MESSAGE_TYPE_NORMALIZE, MessageTokenUsage, MessagesPage, type MockStreamSnapshot, type MockTransport, type MockTransportCalls, OUTLINE_MAX_LEVEL, OutlineChapter, OutlineSubChapter, ReportBodyPayload, ReportOutlinePayload, RunInfo, RunMessage, type RunStreamPayload, SendMessageOptions, type StreamEvent, type StreamEventSource, StreamSubmitInput, StreamSubmitOptions, type SxinMessage, SxinNode, type ThreadInfo, ThreadInitialValues, type ThreadInstruction, ThreadTokenUsage, type ViewModelState, buildAiGroup, buildArtifactFiles, buildHumanGroup, buildHumanInputResponse, buildReportBodyPayload, buildReportOutlinePayload,
|
|
724
|
+
export { Block, BlockBuilderLiteOptions, BlockBuilderOptions, type BuildGroupsResult, CORE_VERSION, ChatStreamHandle, ChatTransport, CitationItem, CreateStreamOptions, DEFAULT_ASSISTANT_ID, DEFAULT_MAX_CACHED_SESSIONS, DEFAULT_MAX_CONCURRENT_STREAMS, type DeriveGroupsDeps, ElementNode, type GroupDeriver, GroupMessage, GroupMessageTool, GroupMessageType, HitlResponse, type HumanInputResponseOptions, IKwargs, INJECTED_TAGS, type InstructionSink, type KnowledgeItem, MESSAGE_TYPE_NORMALIZE, MessageTokenUsage, MessagesPage, type MockStreamSnapshot, type MockTransport, type MockTransportCalls, OUTLINE_MAX_LEVEL, OutlineChapter, OutlineSubChapter, ReportBodyPayload, ReportOutlinePayload, RunInfo, RunMessage, type RunStreamPayload, SendMessageOptions, type StreamEvent, type StreamEventSource, StreamSubmitInput, StreamSubmitOptions, type SxinMessage, SxinNode, type ThreadInfo, ThreadInitialValues, type ThreadInstruction, ThreadTokenUsage, type ViewModelState, buildAiGroup, buildArtifactFiles, buildHumanGroup, buildHumanInputResponse, buildReportBodyPayload, buildReportOutlinePayload, collectTextKeepSxin, collectVisibleText, createEmptySubChapter, createGroupDeriver, createMockTransport, createOptimisticHuman, createStreamPump, createViewModelState, deriveToolsFromMessages, ensureOutlineContentThemes, ensureRunningRun, extractAiContentFromMessage, extractBlocksFromContent, extractBlocksFromNodes, extractCitationAnchors, extractCitationAnchorsFromSpec, extractReportTitleFromBody, extractRunEnrichment, extractStateMessages, extractTextFromMessage, extractThreadInfo, extractTitleFromArtifactPath, extractUserMessageTexts, foldMessages, formatStr, genBlockId, genMessageId, getHumanMessageBaseId, getToolCallArtifactMeta, isAiMessage, isClarificationAnswered, isClarificationBlock, isHiddenUserMessage, isHumanMessage, isInjectedElement, isReportBodyHtml, isToolMessage, isVisibleUserMessage, isWriteFileToolName, normalizeMessageType, normalizeOutline, normalizeUsage, parseHumanMessageId, parseKnowledgeItemsFromValue, parseMarkdownToOutline, readMessageContentText, resolveReportArtifactKind, runMessagesToMessages, simpleHash, stateMessagesToRunMessages, toRunMessage, tokenizeSxin, validateOutline };
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
buildReportOutlinePayload,
|
|
20
20
|
buildRunDirectLatencyMs,
|
|
21
21
|
buildRunInfo,
|
|
22
|
-
collectCitation,
|
|
23
22
|
collectTextKeepSxin,
|
|
24
23
|
collectVisibleText,
|
|
25
24
|
createBlockBuilderLite,
|
|
@@ -35,6 +34,8 @@ import {
|
|
|
35
34
|
extractAiContentFromMessage,
|
|
36
35
|
extractBlocksFromContent,
|
|
37
36
|
extractBlocksFromNodes,
|
|
37
|
+
extractCitationAnchors,
|
|
38
|
+
extractCitationAnchorsFromSpec,
|
|
38
39
|
extractReportTitleFromBody,
|
|
39
40
|
extractRunEnrichment,
|
|
40
41
|
extractStateMessages,
|
|
@@ -77,7 +78,7 @@ import {
|
|
|
77
78
|
toRunMessage,
|
|
78
79
|
tokenizeSxin,
|
|
79
80
|
validateOutline
|
|
80
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-K2ZOZPBB.mjs";
|
|
81
82
|
|
|
82
83
|
// src/protocol/stream-pump.ts
|
|
83
84
|
import { ref } from "vue";
|
|
@@ -394,7 +395,6 @@ export {
|
|
|
394
395
|
buildReportOutlinePayload,
|
|
395
396
|
buildRunDirectLatencyMs,
|
|
396
397
|
buildRunInfo,
|
|
397
|
-
collectCitation,
|
|
398
398
|
collectTextKeepSxin,
|
|
399
399
|
collectVisibleText,
|
|
400
400
|
createBlockBuilderLite,
|
|
@@ -412,6 +412,8 @@ export {
|
|
|
412
412
|
extractAiContentFromMessage,
|
|
413
413
|
extractBlocksFromContent,
|
|
414
414
|
extractBlocksFromNodes,
|
|
415
|
+
extractCitationAnchors,
|
|
416
|
+
extractCitationAnchorsFromSpec,
|
|
415
417
|
extractReportTitleFromBody,
|
|
416
418
|
extractRunEnrichment,
|
|
417
419
|
extractStateMessages,
|
package/dist/vue/index.cjs
CHANGED
|
@@ -966,12 +966,6 @@ function createThreadStore(_options = {}) {
|
|
|
966
966
|
streamStatusRef
|
|
967
967
|
};
|
|
968
968
|
}
|
|
969
|
-
function hasCitationInfo(v) {
|
|
970
|
-
if (!v) return false;
|
|
971
|
-
if (Array.isArray(v)) return v.length > 0;
|
|
972
|
-
if (typeof v === "object") return Object.keys(v).length > 0;
|
|
973
|
-
return Boolean(v);
|
|
974
|
-
}
|
|
975
969
|
function readContentText(content) {
|
|
976
970
|
if (typeof content === "string") return content;
|
|
977
971
|
if (Array.isArray(content)) {
|
|
@@ -980,10 +974,8 @@ function readContentText(content) {
|
|
|
980
974
|
return "";
|
|
981
975
|
}
|
|
982
976
|
function isCitationCarrier(msg) {
|
|
983
|
-
const m = asSxin(msg);
|
|
984
977
|
if (!isAiMessage(msg)) return false;
|
|
985
|
-
|
|
986
|
-
return hasCitationInfo(m.additional_kwargs?.citation_info);
|
|
978
|
+
return readContentText(asSxin(msg).content).includes("support.kbCitation");
|
|
987
979
|
}
|
|
988
980
|
function createEnrichments() {
|
|
989
981
|
const citationPatches = (0, import_vue3.shallowReactive)(/* @__PURE__ */ new Map());
|
|
@@ -998,10 +990,7 @@ function createEnrichments() {
|
|
|
998
990
|
const m = asSxin(msg);
|
|
999
991
|
const id = String(m.id || "").trim();
|
|
1000
992
|
if (!id || !isCitationCarrier(msg)) continue;
|
|
1001
|
-
citationPatches.set(id, {
|
|
1002
|
-
content: m.content,
|
|
1003
|
-
citationInfo: m.additional_kwargs?.citation_info
|
|
1004
|
-
});
|
|
993
|
+
citationPatches.set(id, { content: m.content });
|
|
1005
994
|
citationVersion++;
|
|
1006
995
|
}
|
|
1007
996
|
const extracted = extractThreadInfo(messages).clarificationAnswers;
|
|
@@ -1531,6 +1520,62 @@ function foldMessages(target, flush) {
|
|
|
1531
1520
|
doFlush();
|
|
1532
1521
|
}
|
|
1533
1522
|
|
|
1523
|
+
// src/parser/citation.ts
|
|
1524
|
+
var KB_CITATION_CONTRACT = "support.kbCitation";
|
|
1525
|
+
var REF_ID_KEYS = ["ref-id", "refId", "ref_id", "citation-id", "citationId", "citation_id", "id"];
|
|
1526
|
+
var SEARCH_TEXT_KEYS = ["search-text", "searchText", "search_text", "keyword"];
|
|
1527
|
+
var REF_ID_LIST_KEY_RE = /^(ref|citation)[-_]?ids?$/i;
|
|
1528
|
+
var isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
1529
|
+
var pickFirstString = (obj, keys) => {
|
|
1530
|
+
for (const k of keys) {
|
|
1531
|
+
const v = obj?.[k];
|
|
1532
|
+
if (v === void 0 || v === null) continue;
|
|
1533
|
+
const s = String(v).trim();
|
|
1534
|
+
if (s) return s;
|
|
1535
|
+
}
|
|
1536
|
+
return void 0;
|
|
1537
|
+
};
|
|
1538
|
+
function extractCitationAnchorsFromSpec(spec) {
|
|
1539
|
+
const anchors = [];
|
|
1540
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1541
|
+
const candidates = [];
|
|
1542
|
+
if (isPlainObject(spec)) candidates.push(spec);
|
|
1543
|
+
for (const [key, value] of Object.entries(spec || {})) {
|
|
1544
|
+
if (Array.isArray(value)) {
|
|
1545
|
+
for (const item of value) if (isPlainObject(item)) candidates.push(item);
|
|
1546
|
+
} else if (typeof value === "string" && /,/.test(value) && REF_ID_LIST_KEY_RE.test(key)) {
|
|
1547
|
+
for (const id of value.split(",")) candidates.push({ "ref-id": id });
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
for (const item of candidates) {
|
|
1551
|
+
const refId = pickFirstString(item, REF_ID_KEYS);
|
|
1552
|
+
if (!refId || seen.has(refId)) continue;
|
|
1553
|
+
seen.add(refId);
|
|
1554
|
+
const anchor = { refId, title: "" };
|
|
1555
|
+
const searchText = pickFirstString(item, SEARCH_TEXT_KEYS);
|
|
1556
|
+
if (searchText) anchor.searchText = searchText;
|
|
1557
|
+
anchors.push(anchor);
|
|
1558
|
+
}
|
|
1559
|
+
return anchors;
|
|
1560
|
+
}
|
|
1561
|
+
function extractCitationAnchors(blocks) {
|
|
1562
|
+
const anchors = [];
|
|
1563
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1564
|
+
for (const block of blocks) {
|
|
1565
|
+
if (block.type !== "custom") continue;
|
|
1566
|
+
const custom = block;
|
|
1567
|
+
if (custom.tagName !== "sxin-item") continue;
|
|
1568
|
+
const spec = custom.spec || {};
|
|
1569
|
+
if (String(spec.contract || "").trim() !== KB_CITATION_CONTRACT) continue;
|
|
1570
|
+
for (const anchor of extractCitationAnchorsFromSpec(spec)) {
|
|
1571
|
+
if (seen.has(anchor.refId)) continue;
|
|
1572
|
+
seen.add(anchor.refId);
|
|
1573
|
+
anchors.push(anchor);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return anchors;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1534
1579
|
// src/parser/report-artifact.ts
|
|
1535
1580
|
var genId = () => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `id-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
1536
1581
|
function isWriteFileToolName(name) {
|
|
@@ -1754,21 +1799,6 @@ function extractReportTitleFromBody(content, fallback = "") {
|
|
|
1754
1799
|
return fallback;
|
|
1755
1800
|
}
|
|
1756
1801
|
|
|
1757
|
-
// src/parser/citation.ts
|
|
1758
|
-
function collectCitation(el, citations) {
|
|
1759
|
-
const citationId = String(el.attrs["citation-id"] || "").trim();
|
|
1760
|
-
const searchText = String(el.attrs["search-text"] || el.attrs["keyword"] || "").trim() || void 0;
|
|
1761
|
-
if (!citationId) return;
|
|
1762
|
-
const existing = citations.find((c) => c.refId === citationId);
|
|
1763
|
-
if (!existing) {
|
|
1764
|
-
const item = { refId: citationId, title: "" };
|
|
1765
|
-
if (searchText) item.searchText = searchText;
|
|
1766
|
-
citations.push(item);
|
|
1767
|
-
} else if (searchText && !existing.searchText) {
|
|
1768
|
-
existing.searchText = searchText;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
1802
|
// src/parser/block-build-helper.ts
|
|
1773
1803
|
function buildArtifactFiles(paths) {
|
|
1774
1804
|
return paths.map((path) => {
|
|
@@ -1893,11 +1923,6 @@ function walkNodes(ctx, nodes) {
|
|
|
1893
1923
|
if (isInjectedElement(node)) {
|
|
1894
1924
|
continue;
|
|
1895
1925
|
}
|
|
1896
|
-
if (node.tagName === "sxin-kb-citation" && node.closed) {
|
|
1897
|
-
flushTextBuf(ctx);
|
|
1898
|
-
collectCitation(node, ctx.citations);
|
|
1899
|
-
continue;
|
|
1900
|
-
}
|
|
1901
1926
|
if (node.tagName.startsWith("sxin-")) {
|
|
1902
1927
|
if (!handleSxinElement(ctx, node)) return false;
|
|
1903
1928
|
continue;
|
|
@@ -1913,12 +1938,11 @@ function extractBlocksFromNodes(nodes, rawText, source) {
|
|
|
1913
1938
|
isHistory,
|
|
1914
1939
|
status: isHistory ? "completed" : "streaming",
|
|
1915
1940
|
blocks: [],
|
|
1916
|
-
citations: [],
|
|
1917
1941
|
textBuf: { value: "" }
|
|
1918
1942
|
};
|
|
1919
1943
|
const completed = walkNodes(ctx, nodes);
|
|
1920
1944
|
if (completed) flushTextBuf(ctx);
|
|
1921
|
-
return { blocks: ctx.blocks
|
|
1945
|
+
return { blocks: ctx.blocks };
|
|
1922
1946
|
}
|
|
1923
1947
|
|
|
1924
1948
|
// src/domain/block-builder.ts
|
|
@@ -2079,20 +2103,12 @@ function createBlockBuilderLite(options) {
|
|
|
2079
2103
|
const blocks = [];
|
|
2080
2104
|
const status = isStreaming ? "streaming" : "completed";
|
|
2081
2105
|
const contentSource = source === "state" ? "history" : source;
|
|
2082
|
-
const { blocks: contentBlocks
|
|
2106
|
+
const { blocks: contentBlocks } = extractBlocksFromNodes(nodes, rawText, contentSource);
|
|
2083
2107
|
blocks.push(...contentBlocks);
|
|
2084
2108
|
for (const tool of tools) {
|
|
2085
2109
|
const toolBlocks = parseBlockTool(tool, status);
|
|
2086
2110
|
blocks.push(...toolBlocks);
|
|
2087
2111
|
}
|
|
2088
|
-
if (citations.length > 0) {
|
|
2089
|
-
blocks.push({
|
|
2090
|
-
id: genBlockId(),
|
|
2091
|
-
type: "citation",
|
|
2092
|
-
items: citations.map((c) => ({ ...c, title: c.title || "" })),
|
|
2093
|
-
status
|
|
2094
|
-
});
|
|
2095
|
-
}
|
|
2096
2112
|
if (twinEnabled) {
|
|
2097
2113
|
const twinTool = tools.reverse().find((_) => _.call?.name.includes(twinToolPrefix));
|
|
2098
2114
|
if (twinTool) {
|
|
@@ -2149,6 +2165,8 @@ function buildAiGroup(messages, options, twin) {
|
|
|
2149
2165
|
content,
|
|
2150
2166
|
groupTools
|
|
2151
2167
|
);
|
|
2168
|
+
const anchors = extractCitationAnchors(blocks);
|
|
2169
|
+
const citations = anchors.length ? anchors : void 0;
|
|
2152
2170
|
return {
|
|
2153
2171
|
id: firstId,
|
|
2154
2172
|
type: "ai",
|
|
@@ -2157,6 +2175,7 @@ function buildAiGroup(messages, options, twin) {
|
|
|
2157
2175
|
runId: messageRunId(lastAi) || options.runId,
|
|
2158
2176
|
rawMessages: messages,
|
|
2159
2177
|
blocks,
|
|
2178
|
+
citations,
|
|
2160
2179
|
toolIds: groupTools.map((t) => t.id),
|
|
2161
2180
|
tools: groupTools,
|
|
2162
2181
|
createdAt
|
|
@@ -2354,15 +2373,8 @@ function createGroupDeriver(state) {
|
|
|
2354
2373
|
const streaming = store.streamStatus === "streaming";
|
|
2355
2374
|
const patched = store.getMessages().map((m) => {
|
|
2356
2375
|
const patch = enrichments.resolveCitation(String(asSxin(m).id || ""));
|
|
2357
|
-
if (!patch) return m;
|
|
2358
|
-
return {
|
|
2359
|
-
...asSxin(m),
|
|
2360
|
-
...patch.content !== void 0 ? { content: patch.content } : {},
|
|
2361
|
-
additional_kwargs: {
|
|
2362
|
-
...asSxin(m).additional_kwargs ?? {},
|
|
2363
|
-
...patch.citationInfo !== void 0 ? { citation_info: patch.citationInfo } : {}
|
|
2364
|
-
}
|
|
2365
|
-
};
|
|
2376
|
+
if (!patch || patch.content === void 0) return m;
|
|
2377
|
+
return { ...asSxin(m), content: patch.content };
|
|
2366
2378
|
});
|
|
2367
2379
|
const sourceOf = (id) => id ? store.getEntity(id)?.source ?? "stream" : "stream";
|
|
2368
2380
|
const epochOf = (id) => id ? store.getEntity(id)?.epoch : void 0;
|
package/dist/vue/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as ChatCoreOptions, z as ChatCore } from '../ChatCore-
|
|
2
|
-
export {
|
|
1
|
+
import { D as ChatCoreOptions, z as ChatCore } from '../ChatCore-C-G9isDM.cjs';
|
|
2
|
+
export { ay as createChatCore } from '../ChatCore-C-G9isDM.cjs';
|
|
3
3
|
import 'vue';
|
|
4
4
|
import '@langchain/langgraph-sdk';
|
|
5
5
|
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as ChatCoreOptions, z as ChatCore } from '../ChatCore-
|
|
2
|
-
export {
|
|
1
|
+
import { D as ChatCoreOptions, z as ChatCore } from '../ChatCore-C-G9isDM.js';
|
|
2
|
+
export { ay as createChatCore } from '../ChatCore-C-G9isDM.js';
|
|
3
3
|
import 'vue';
|
|
4
4
|
import '@langchain/langgraph-sdk';
|
|
5
5
|
|
package/dist/vue/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqfe/sxin-chat-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "SXin 对话数据层核心:thread/session 管理、消息分组、block 解析(平台无关)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"lodash": "^4.18.1"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|