@cqfe/sxin-chat-core 1.0.1 → 1.0.3
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-C-G9isDM.d.cts → ChatCore-CCeoxjP9.d.cts} +437 -342
- package/dist/{ChatCore-C-G9isDM.d.ts → ChatCore-CCeoxjP9.d.ts} +437 -342
- package/dist/chunk-2AXUXZVK.mjs +2661 -0
- package/dist/index.cjs +1042 -1550
- package/dist/index.d.cts +228 -220
- package/dist/index.d.ts +228 -220
- package/dist/index.mjs +356 -141
- package/dist/vue/index.cjs +1068 -2055
- 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 +3 -3
- package/dist/chunk-K2ZOZPBB.mjs +0 -3391
package/dist/index.mjs
CHANGED
|
@@ -2,197 +2,392 @@ import {
|
|
|
2
2
|
DEFAULT_ASSISTANT_ID,
|
|
3
3
|
DEFAULT_MAX_CACHED_SESSIONS,
|
|
4
4
|
DEFAULT_MAX_CONCURRENT_STREAMS,
|
|
5
|
-
DEFAULT_TWIN_TOOL_PREFIX,
|
|
6
5
|
INJECTED_TAGS,
|
|
7
6
|
MESSAGE_TYPE_NORMALIZE,
|
|
8
7
|
OUTLINE_MAX_LEVEL,
|
|
9
8
|
ThreadDirectory,
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
applySemanticPatches,
|
|
10
|
+
asArgsObject,
|
|
11
|
+
assembleRun,
|
|
12
|
+
backfillRunMessageFeedback,
|
|
12
13
|
buildHitlDecisions,
|
|
13
|
-
buildHumanGroup,
|
|
14
14
|
buildHumanInputResponse,
|
|
15
15
|
buildInterruptReviewBlock,
|
|
16
|
-
buildInterruptReviewGroup,
|
|
17
16
|
buildRejectDecisions,
|
|
18
|
-
buildReportBodyPayload,
|
|
19
|
-
buildReportOutlinePayload,
|
|
20
17
|
buildRunDirectLatencyMs,
|
|
21
18
|
buildRunInfo,
|
|
19
|
+
buildRunMeta,
|
|
22
20
|
collectTextKeepSxin,
|
|
23
21
|
collectVisibleText,
|
|
24
|
-
createBlockBuilderLite,
|
|
25
22
|
createChatCore,
|
|
26
23
|
createEmptySubChapter,
|
|
27
|
-
|
|
28
|
-
createOptimisticHuman,
|
|
24
|
+
createSemanticOverlay,
|
|
29
25
|
createThreadRuntime,
|
|
30
|
-
createViewModelState,
|
|
31
26
|
deriveToolsFromMessages,
|
|
27
|
+
emptyRunItem,
|
|
32
28
|
ensureOutlineContentThemes,
|
|
33
29
|
ensureRunningRun,
|
|
34
30
|
extractAiContentFromMessage,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
extractCitationAnchors,
|
|
38
|
-
extractCitationAnchorsFromSpec,
|
|
31
|
+
extractFromToolResult,
|
|
32
|
+
extractInputFromRows,
|
|
39
33
|
extractReportTitleFromBody,
|
|
40
34
|
extractRunEnrichment,
|
|
35
|
+
extractSemanticPatchesFromMessages,
|
|
41
36
|
extractStateMessages,
|
|
42
37
|
extractTextFromMessage,
|
|
43
38
|
extractThreadInfo,
|
|
44
39
|
extractTitleFromArtifactPath,
|
|
45
40
|
extractUserMessageTexts,
|
|
46
|
-
|
|
41
|
+
formatAnswerText,
|
|
47
42
|
formatStr,
|
|
48
43
|
genBlockId,
|
|
49
44
|
genMessageId,
|
|
50
45
|
getAllowedDecisions,
|
|
51
46
|
getHumanMessageBaseId,
|
|
52
47
|
getToolCallArtifactMeta,
|
|
48
|
+
groupRowsByRun,
|
|
53
49
|
isAiMessage,
|
|
54
|
-
isClarificationAnswered,
|
|
55
|
-
isClarificationBlock,
|
|
56
50
|
isHiddenUserMessage,
|
|
57
51
|
isHumanMessage,
|
|
58
52
|
isInjectedElement,
|
|
59
53
|
isReportBodyHtml,
|
|
60
54
|
isSameArgs,
|
|
61
55
|
isToolMessage,
|
|
56
|
+
isUserEchoRow,
|
|
62
57
|
isVisibleUserMessage,
|
|
63
58
|
isWriteFileToolName,
|
|
59
|
+
mapBackendStatus,
|
|
60
|
+
mergeStateWithPageMessages,
|
|
64
61
|
normalizeForCompare,
|
|
65
62
|
normalizeMessageType,
|
|
66
63
|
normalizeOutline,
|
|
67
64
|
normalizeUsage,
|
|
68
65
|
parseHitlPayload,
|
|
69
66
|
parseHumanMessageId,
|
|
70
|
-
parseKnowledgeItemsFromValue,
|
|
71
67
|
parseMarkdownToOutline,
|
|
68
|
+
pickRicherArgs,
|
|
72
69
|
pickRunMessageMetadata,
|
|
70
|
+
projectRuns,
|
|
73
71
|
readMessageContentText,
|
|
74
72
|
resolveReportArtifactKind,
|
|
73
|
+
rowMessageId,
|
|
75
74
|
runMessagesToMessages,
|
|
76
75
|
simpleHash,
|
|
76
|
+
sliceBodySegments,
|
|
77
77
|
stateMessagesToRunMessages,
|
|
78
78
|
toRunMessage,
|
|
79
79
|
tokenizeSxin,
|
|
80
80
|
validateOutline
|
|
81
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-2AXUXZVK.mjs";
|
|
82
82
|
|
|
83
|
-
// src/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
83
|
+
// src/parser/citation.ts
|
|
84
|
+
var toStringArray = (v) => {
|
|
85
|
+
if (!v) return [];
|
|
86
|
+
if (Array.isArray(v))
|
|
87
|
+
return v.map((x) => String(x)).map((x) => x.trim()).filter(Boolean);
|
|
88
|
+
return [String(v).trim()].filter(Boolean);
|
|
89
|
+
};
|
|
90
|
+
var pick = (obj, keys) => {
|
|
91
|
+
for (const k of keys) {
|
|
92
|
+
const v = obj?.[k];
|
|
93
|
+
if (v !== void 0 && v !== null && String(v).trim() !== "") return v;
|
|
94
|
+
}
|
|
95
|
+
return void 0;
|
|
96
|
+
};
|
|
97
|
+
var STRING_FIELD_KEYS = {
|
|
98
|
+
rawKey: ["key", "refId", "ref_id", "citationId", "citation_id"],
|
|
99
|
+
refId: ["refId", "ref_id", "citationId", "citation_id"],
|
|
100
|
+
globalRef: ["globalRef", "global_ref"],
|
|
101
|
+
minioBucket: ["minioBucket", "minio_bucket", "bucket", "minioBucketName"],
|
|
102
|
+
minioObject: ["minioObject", "minio_object", "object", "object_name", "objectName", "minioObjectName"],
|
|
103
|
+
previewUrl: ["previewUrl", "preview_url", "url", "preview"],
|
|
104
|
+
docUrl: ["docUrl", "doc_url"],
|
|
105
|
+
docId: ["docId", "doc_id", "document_id", "docid", "id"],
|
|
106
|
+
title: ["title", "docName", "doc_name", "docOriginalName", "doc_original_name", "file_name", "filename", "name"],
|
|
107
|
+
fileType: ["fileType", "file_type", "ext", "extension"]
|
|
108
|
+
};
|
|
109
|
+
var ARRAY_FIELD_KEYS = {
|
|
110
|
+
sourcePages: ["sourcePages", "source_pages", "pages", "page_idxs", "page_idx"],
|
|
111
|
+
highlightText: ["highlightText", "highlight_text"]
|
|
112
|
+
};
|
|
113
|
+
var pickString = (raw, meta, keys) => String(pick(raw, keys) ?? pick(meta, keys) ?? "").trim();
|
|
114
|
+
var pickStringArray = (raw, meta, keys) => toStringArray(pick(raw, keys) ?? pick(meta, keys));
|
|
115
|
+
var orUndefined = (s) => s || void 0;
|
|
116
|
+
var nonEmpty = (a) => a.length ? a : void 0;
|
|
117
|
+
var resolveCitationKey = (s) => {
|
|
118
|
+
if (s.rawKey) return s.rawKey;
|
|
119
|
+
if (s.minioBucket && s.minioObject) return `${s.minioBucket}:${s.minioObject}`;
|
|
120
|
+
if (s.docId) return `doc:${s.docId}`;
|
|
121
|
+
if (s.title) return `title:${s.title}`;
|
|
122
|
+
return "";
|
|
123
|
+
};
|
|
124
|
+
var parseBboxEntry = (entry) => {
|
|
125
|
+
const b = entry?.bbox;
|
|
126
|
+
const pageIdx = Number(entry?.page_idx);
|
|
127
|
+
const left = Number(b?.left);
|
|
128
|
+
const top = Number(b?.top);
|
|
129
|
+
const right = Number(b?.right);
|
|
130
|
+
const bottom = Number(b?.bottom);
|
|
131
|
+
if (![left, top, right, bottom].every(Number.isFinite)) return null;
|
|
132
|
+
return {
|
|
133
|
+
page: Number.isFinite(pageIdx) ? Math.max(1, pageIdx + 1) : 1,
|
|
134
|
+
bbox: [left, top, right, bottom]
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
var parseCitationLocations = (raw, meta) => {
|
|
138
|
+
const rawBboxes = Array.isArray(raw?.source_bboxes) ? raw.source_bboxes : Array.isArray(meta?.source_bboxes) ? meta.source_bboxes : [];
|
|
139
|
+
return rawBboxes.map(parseBboxEntry).filter(Boolean);
|
|
140
|
+
};
|
|
141
|
+
var normalizeOne = (raw) => {
|
|
142
|
+
if (!raw || typeof raw !== "object") return null;
|
|
143
|
+
const meta = raw.metadata && typeof raw.metadata === "object" ? raw.metadata : {};
|
|
144
|
+
const str = {};
|
|
145
|
+
for (const [field, keys] of Object.entries(STRING_FIELD_KEYS)) {
|
|
146
|
+
str[field] = pickString(raw, meta, keys);
|
|
147
|
+
}
|
|
148
|
+
const { refId, globalRef, minioBucket, minioObject, previewUrl, docUrl, docId, title, fileType } = str;
|
|
149
|
+
const arr = {};
|
|
150
|
+
for (const [field, keys] of Object.entries(ARRAY_FIELD_KEYS)) {
|
|
151
|
+
arr[field] = pickStringArray(raw, meta, keys);
|
|
152
|
+
}
|
|
153
|
+
const { sourcePages, highlightText } = arr;
|
|
154
|
+
const searchText = highlightText[0] || "";
|
|
155
|
+
const citationLocations = parseCitationLocations(raw, meta);
|
|
156
|
+
const key = resolveCitationKey(str);
|
|
157
|
+
if (!key && !previewUrl && !docUrl) return null;
|
|
158
|
+
return {
|
|
159
|
+
key,
|
|
160
|
+
refId: orUndefined(refId),
|
|
161
|
+
globalRef: orUndefined(globalRef),
|
|
162
|
+
title,
|
|
163
|
+
docId,
|
|
164
|
+
minioBucket: orUndefined(minioBucket),
|
|
165
|
+
minioObject: orUndefined(minioObject),
|
|
166
|
+
previewUrl: orUndefined(previewUrl),
|
|
167
|
+
docUrl: orUndefined(docUrl),
|
|
168
|
+
fileType: orUndefined(fileType),
|
|
169
|
+
sourcePages: nonEmpty(sourcePages),
|
|
170
|
+
citationLocations: nonEmpty(citationLocations),
|
|
171
|
+
highlightText: nonEmpty(highlightText),
|
|
172
|
+
searchText: orUndefined(searchText)
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
var KB_CITATION_CONTRACT = "support.kbCitation";
|
|
176
|
+
var REF_ID_KEYS = ["ref-id", "refId", "ref_id", "citation-id", "citationId", "citation_id", "id"];
|
|
177
|
+
var SEARCH_TEXT_KEYS = ["search-text", "searchText", "search_text", "keyword"];
|
|
178
|
+
var REF_ID_LIST_KEY_RE = /^(ref|citation)[-_]?ids?$/i;
|
|
179
|
+
var isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
180
|
+
var pickFirstString = (obj, keys) => {
|
|
181
|
+
for (const k of keys) {
|
|
182
|
+
const v = obj?.[k];
|
|
183
|
+
if (v === void 0 || v === null) continue;
|
|
184
|
+
const s = String(v).trim();
|
|
185
|
+
if (s) return s;
|
|
186
|
+
}
|
|
187
|
+
return void 0;
|
|
188
|
+
};
|
|
189
|
+
function extractCitationAnchorsFromSpec(spec) {
|
|
190
|
+
const anchors = [];
|
|
191
|
+
const seen = /* @__PURE__ */ new Set();
|
|
192
|
+
const candidates = [];
|
|
193
|
+
if (isPlainObject(spec)) candidates.push(spec);
|
|
194
|
+
for (const [key, value] of Object.entries(spec || {})) {
|
|
195
|
+
if (Array.isArray(value)) {
|
|
196
|
+
for (const item of value) if (isPlainObject(item)) candidates.push(item);
|
|
197
|
+
} else if (typeof value === "string" && /,/.test(value) && REF_ID_LIST_KEY_RE.test(key)) {
|
|
198
|
+
for (const id of value.split(",")) candidates.push({ "ref-id": id });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const item of candidates) {
|
|
202
|
+
const refId = pickFirstString(item, REF_ID_KEYS);
|
|
203
|
+
if (!refId || seen.has(refId)) continue;
|
|
204
|
+
seen.add(refId);
|
|
205
|
+
const anchor = { refId, title: "" };
|
|
206
|
+
const searchText = pickFirstString(item, SEARCH_TEXT_KEYS);
|
|
207
|
+
if (searchText) anchor.searchText = searchText;
|
|
208
|
+
anchors.push(anchor);
|
|
209
|
+
}
|
|
210
|
+
return anchors;
|
|
89
211
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (event === "error") throw new StreamError(data);
|
|
104
|
-
if (event === "metadata") {
|
|
105
|
-
options.onMetadataEvent?.(data);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (event === "values" || event.startsWith("values|")) {
|
|
109
|
-
if (event.includes("|")) continue;
|
|
110
|
-
options.onValuesEvent?.(data);
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (event === "messages" || event === "messages-tuple" || event.startsWith("messages|")) {
|
|
114
|
-
if (event.includes("|")) continue;
|
|
115
|
-
const [serialized, metadata] = Array.isArray(data) ? data : [];
|
|
116
|
-
options.onMessageTupleEvent?.(serialized, metadata);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} catch (e) {
|
|
121
|
-
if (!isSilentStreamError(e)) {
|
|
122
|
-
error.value = e;
|
|
123
|
-
try {
|
|
124
|
-
await options.onError?.(e);
|
|
125
|
-
} catch {
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} finally {
|
|
129
|
-
try {
|
|
130
|
-
await options.onStreamEnd?.();
|
|
131
|
-
} catch {
|
|
132
|
-
}
|
|
133
|
-
isLoading.value = false;
|
|
134
|
-
if (currentController === controller) currentController = null;
|
|
135
|
-
try {
|
|
136
|
-
await options.onFinish?.();
|
|
137
|
-
} catch {
|
|
138
|
-
}
|
|
212
|
+
function extractCitationAnchors(blocks) {
|
|
213
|
+
const anchors = [];
|
|
214
|
+
const seen = /* @__PURE__ */ new Set();
|
|
215
|
+
for (const block of blocks) {
|
|
216
|
+
if (block.type !== "custom") continue;
|
|
217
|
+
const custom = block;
|
|
218
|
+
if (custom.tagName !== "sxin-item") continue;
|
|
219
|
+
const spec = custom.spec || {};
|
|
220
|
+
if (String(spec.contract || "").trim() !== KB_CITATION_CONTRACT) continue;
|
|
221
|
+
for (const anchor of extractCitationAnchorsFromSpec(spec)) {
|
|
222
|
+
if (seen.has(anchor.refId)) continue;
|
|
223
|
+
seen.add(anchor.refId);
|
|
224
|
+
anchors.push(anchor);
|
|
139
225
|
}
|
|
226
|
+
}
|
|
227
|
+
return anchors;
|
|
228
|
+
}
|
|
229
|
+
function parseKnowledgeItemsFromValue(value) {
|
|
230
|
+
if (!value) return [];
|
|
231
|
+
const rawList = Array.isArray(value) ? value : typeof value === "object" ? [value] : [];
|
|
232
|
+
const result = [];
|
|
233
|
+
for (const raw of rawList) {
|
|
234
|
+
const it = normalizeOne(raw);
|
|
235
|
+
if (it) result.push(it);
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/parser/block-build-helper.ts
|
|
241
|
+
function buildArtifactFiles(paths) {
|
|
242
|
+
return paths.map((path) => {
|
|
243
|
+
const name = path.split("/").pop() || path;
|
|
244
|
+
const fileType = name.split(".").pop() || void 0;
|
|
245
|
+
return { path, name, fileType };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function toCreatedAtIso(createdAt) {
|
|
249
|
+
const ms = Number(createdAt);
|
|
250
|
+
if (!Number.isFinite(ms)) return (/* @__PURE__ */ new Date()).toISOString();
|
|
251
|
+
const date = new Date(ms);
|
|
252
|
+
return Number.isNaN(date.getTime()) ? (/* @__PURE__ */ new Date()).toISOString() : date.toISOString();
|
|
253
|
+
}
|
|
254
|
+
function buildReportOutlinePayload(input) {
|
|
255
|
+
const { templateId, fallbackName, sourcePath, content, contentRef, createdAt } = input;
|
|
256
|
+
const createdIso = toCreatedAtIso(createdAt);
|
|
257
|
+
if (!content) {
|
|
258
|
+
return {
|
|
259
|
+
templateId,
|
|
260
|
+
templateName: fallbackName,
|
|
261
|
+
outline: [],
|
|
262
|
+
createdAt: createdIso,
|
|
263
|
+
sourcePath: sourcePath || void 0,
|
|
264
|
+
contentRef
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const parsed = parseMarkdownToOutline(content);
|
|
268
|
+
return {
|
|
269
|
+
templateId,
|
|
270
|
+
templateName: parsed.templateName || fallbackName,
|
|
271
|
+
outline: parsed.outline,
|
|
272
|
+
createdAt: createdIso,
|
|
273
|
+
sourcePath: sourcePath || void 0,
|
|
274
|
+
outlineMarkdown: content,
|
|
275
|
+
contentRef
|
|
140
276
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
277
|
+
}
|
|
278
|
+
function buildReportBodyPayload(input) {
|
|
279
|
+
const { templateId, fallbackName, sourcePath, content, contentRef, createdAt } = input;
|
|
280
|
+
const createdIso = toCreatedAtIso(createdAt);
|
|
281
|
+
if (!content) {
|
|
282
|
+
return {
|
|
283
|
+
templateId,
|
|
284
|
+
templateName: fallbackName,
|
|
285
|
+
reportTitle: "",
|
|
286
|
+
createdAt: createdIso,
|
|
287
|
+
sourcePath: sourcePath || void 0,
|
|
288
|
+
contentRef
|
|
289
|
+
};
|
|
290
|
+
}
|
|
147
291
|
return {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
-
},
|
|
166
|
-
/** 加入既有 run 的 SSE 流(断线重连);await 至流结束 */
|
|
167
|
-
joinStream(runId, lastEventId) {
|
|
168
|
-
return start((signal) => source.openJoinStream(runId, lastEventId ?? "-1", signal), { abortPrevious: true });
|
|
169
|
-
},
|
|
170
|
-
/** 停止当前流(本地 abort,不取消服务端 run) */
|
|
171
|
-
stop() {
|
|
172
|
-
currentController?.abort();
|
|
173
|
-
},
|
|
174
|
-
/** 恢复 pending interrupt:发送 HITL 决策(Command(resume)),与 joinStream 的 SSE 重连语义不同;await 至流结束 */
|
|
175
|
-
resumeInterrupt(decisions) {
|
|
176
|
-
return start(
|
|
177
|
-
(signal) => source.openRunStream(
|
|
178
|
-
{
|
|
179
|
-
input: null,
|
|
180
|
-
command: { resume: decisions },
|
|
181
|
-
onDisconnect: "continue",
|
|
182
|
-
config: { recursion_limit: 1e3 },
|
|
183
|
-
streamMode: STREAM_MODE,
|
|
184
|
-
onRunCreated: (params) => options.onCreated?.(params)
|
|
185
|
-
},
|
|
186
|
-
signal
|
|
187
|
-
),
|
|
188
|
-
{ abortPrevious: true }
|
|
189
|
-
);
|
|
292
|
+
templateId,
|
|
293
|
+
templateName: fallbackName,
|
|
294
|
+
reportTitle: extractReportTitleFromBody(content, fallbackName),
|
|
295
|
+
createdAt: createdIso,
|
|
296
|
+
sourcePath: sourcePath || void 0,
|
|
297
|
+
bodyMarkdown: content,
|
|
298
|
+
contentRef
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function collectListSpecs(listEls, spec, source) {
|
|
302
|
+
for (const listEl of listEls) {
|
|
303
|
+
const itemType = formatStr(listEl.attrs["item-type"] || "");
|
|
304
|
+
if (!itemType) continue;
|
|
305
|
+
if (!spec[itemType]) spec[itemType] = [];
|
|
306
|
+
for (const item of listEl.children) {
|
|
307
|
+
if (item.type !== "element" || item.tagName !== "sxin-list-item") continue;
|
|
308
|
+
spec[itemType].push(buildItemSpec(item, source));
|
|
190
309
|
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function collectChildSpecs(children, spec, source) {
|
|
313
|
+
for (const child of children) {
|
|
314
|
+
if (child.type !== "element") continue;
|
|
315
|
+
const key = formatStr(child.tagName);
|
|
316
|
+
if (!spec[key]) spec[key] = [];
|
|
317
|
+
spec[key].push(buildItemSpec(child, source));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function buildCustomBlockFromNode(el, source, status) {
|
|
321
|
+
const spec = { ...el.attrs };
|
|
322
|
+
const listEls = el.children.filter((c) => c.type === "element" && c.tagName === "sxin-list");
|
|
323
|
+
if (listEls.length > 0) {
|
|
324
|
+
collectListSpecs(listEls, spec, source);
|
|
325
|
+
} else {
|
|
326
|
+
collectChildSpecs(el.children, spec, source);
|
|
327
|
+
}
|
|
328
|
+
return { id: genBlockId(), type: "custom", tagName: el.tagName, spec, status };
|
|
329
|
+
}
|
|
330
|
+
function buildItemSpec(el, source) {
|
|
331
|
+
const attrs = { ...el.attrs };
|
|
332
|
+
const inner = el.children.map((c) => source.slice(c.start, c.end)).join("").trim();
|
|
333
|
+
if (inner) attrs.text = inner;
|
|
334
|
+
return attrs;
|
|
335
|
+
}
|
|
336
|
+
function flushTextBuf(ctx) {
|
|
337
|
+
const content = ctx.textBuf.value.replace(/\n{3,}/g, "\n\n").trim();
|
|
338
|
+
ctx.textBuf.value = "";
|
|
339
|
+
if (content) {
|
|
340
|
+
ctx.blocks.push({ id: genBlockId(), type: "text", content, status: ctx.status });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function handleSxinElement(ctx, node) {
|
|
344
|
+
if (!node.closed && !ctx.isHistory) {
|
|
345
|
+
flushTextBuf(ctx);
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
flushTextBuf(ctx);
|
|
349
|
+
ctx.blocks.push(buildCustomBlockFromNode(node, ctx.rawText, ctx.status));
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
function walkNodes(ctx, nodes) {
|
|
353
|
+
for (const node of nodes) {
|
|
354
|
+
if (node.type === "text") {
|
|
355
|
+
ctx.textBuf.value += node.value;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (node.type === "comment") {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (isInjectedElement(node)) {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (node.tagName.startsWith("sxin-")) {
|
|
365
|
+
if (!handleSxinElement(ctx, node)) return false;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
ctx.textBuf.value += ctx.rawText.slice(node.start, node.end);
|
|
369
|
+
}
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
function extractBlocksFromNodes(nodes, rawText, source) {
|
|
373
|
+
const isHistory = source === "history";
|
|
374
|
+
const ctx = {
|
|
375
|
+
rawText,
|
|
376
|
+
isHistory,
|
|
377
|
+
status: isHistory ? "completed" : "streaming",
|
|
378
|
+
blocks: [],
|
|
379
|
+
textBuf: { value: "" }
|
|
191
380
|
};
|
|
381
|
+
const completed = walkNodes(ctx, nodes);
|
|
382
|
+
if (completed) flushTextBuf(ctx);
|
|
383
|
+
return { blocks: ctx.blocks };
|
|
384
|
+
}
|
|
385
|
+
function extractBlocksFromContent(rawText, source) {
|
|
386
|
+
return extractBlocksFromNodes(tokenizeSxin(rawText), rawText, source);
|
|
192
387
|
}
|
|
193
388
|
|
|
194
389
|
// src/test-utils/mockTransport.ts
|
|
195
|
-
import { ref
|
|
390
|
+
import { ref } from "vue";
|
|
196
391
|
var mockThreadSeq = 0;
|
|
197
392
|
function createMockTransport() {
|
|
198
393
|
const threads = [];
|
|
@@ -200,6 +395,7 @@ function createMockTransport() {
|
|
|
200
395
|
const messagesPagesMap = /* @__PURE__ */ new Map();
|
|
201
396
|
const tokenUsageMap = /* @__PURE__ */ new Map();
|
|
202
397
|
const artifactContentMap = /* @__PURE__ */ new Map();
|
|
398
|
+
const resumeErrorMap = /* @__PURE__ */ new Map();
|
|
203
399
|
const handles = /* @__PURE__ */ new Map();
|
|
204
400
|
const optionsMap = /* @__PURE__ */ new Map();
|
|
205
401
|
const calls = { submit: [], resumeInterrupt: [], stop: [], joinStream: [], cancel: [] };
|
|
@@ -283,13 +479,15 @@ function createMockTransport() {
|
|
|
283
479
|
return content;
|
|
284
480
|
},
|
|
285
481
|
createStream(options) {
|
|
286
|
-
const isLoading =
|
|
287
|
-
const error =
|
|
482
|
+
const isLoading = ref(false);
|
|
483
|
+
const error = ref(null);
|
|
484
|
+
const interrupt = ref(void 0);
|
|
288
485
|
const threadId = options.threadId;
|
|
289
486
|
optionsMap.set(threadId, options);
|
|
290
487
|
const handle = {
|
|
291
488
|
isLoading,
|
|
292
489
|
error,
|
|
490
|
+
interrupt,
|
|
293
491
|
submit(input, submitOptions) {
|
|
294
492
|
calls.submit.push({ threadId, input, options: submitOptions });
|
|
295
493
|
},
|
|
@@ -302,6 +500,8 @@ function createMockTransport() {
|
|
|
302
500
|
},
|
|
303
501
|
async resumeInterrupt(decisions) {
|
|
304
502
|
calls.resumeInterrupt.push({ threadId, decisions });
|
|
503
|
+
const err = resumeErrorMap.get(threadId)?.shift();
|
|
504
|
+
if (err) throw err;
|
|
305
505
|
}
|
|
306
506
|
};
|
|
307
507
|
handles.set(threadId, {
|
|
@@ -312,12 +512,12 @@ function createMockTransport() {
|
|
|
312
512
|
isLoading.value = snapshot.isLoading;
|
|
313
513
|
if (!snapshot.isLoading) ended = true;
|
|
314
514
|
}
|
|
315
|
-
if (snapshot.values !== void 0 || snapshot.messages !== void 0
|
|
515
|
+
if (snapshot.values !== void 0 || snapshot.messages !== void 0) {
|
|
316
516
|
const data = { ...snapshot.values ?? {} };
|
|
317
517
|
if (snapshot.messages !== void 0) data.messages = snapshot.messages;
|
|
318
|
-
if ("interrupt" in snapshot) data.__interrupt__ = snapshot.interrupt ? [snapshot.interrupt] : [];
|
|
319
518
|
options.onValuesEvent?.(data);
|
|
320
519
|
}
|
|
520
|
+
if ("interrupt" in snapshot) interrupt.value = snapshot.interrupt;
|
|
321
521
|
if (ended) options.onStreamEnd?.();
|
|
322
522
|
}
|
|
323
523
|
});
|
|
@@ -350,6 +550,14 @@ function createMockTransport() {
|
|
|
350
550
|
;
|
|
351
551
|
entry.handle.error.value = err;
|
|
352
552
|
},
|
|
553
|
+
__setResumeError(threadId, err) {
|
|
554
|
+
let queue = resumeErrorMap.get(threadId);
|
|
555
|
+
if (!queue) {
|
|
556
|
+
queue = [];
|
|
557
|
+
resumeErrorMap.set(threadId, queue);
|
|
558
|
+
}
|
|
559
|
+
queue.push(err);
|
|
560
|
+
},
|
|
353
561
|
__setInitialValues(threadId, values) {
|
|
354
562
|
initialValuesMap.set(threadId, values);
|
|
355
563
|
},
|
|
@@ -372,41 +580,39 @@ function createMockTransport() {
|
|
|
372
580
|
}
|
|
373
581
|
|
|
374
582
|
// src/index.ts
|
|
375
|
-
var CORE_VERSION = "2.
|
|
583
|
+
var CORE_VERSION = "2.1.0";
|
|
376
584
|
export {
|
|
377
585
|
CORE_VERSION,
|
|
378
586
|
DEFAULT_ASSISTANT_ID,
|
|
379
587
|
DEFAULT_MAX_CACHED_SESSIONS,
|
|
380
588
|
DEFAULT_MAX_CONCURRENT_STREAMS,
|
|
381
|
-
DEFAULT_TWIN_TOOL_PREFIX,
|
|
382
589
|
INJECTED_TAGS,
|
|
383
590
|
MESSAGE_TYPE_NORMALIZE,
|
|
384
591
|
OUTLINE_MAX_LEVEL,
|
|
385
592
|
ThreadDirectory,
|
|
386
|
-
|
|
593
|
+
applySemanticPatches,
|
|
594
|
+
asArgsObject,
|
|
595
|
+
assembleRun,
|
|
596
|
+
backfillRunMessageFeedback,
|
|
387
597
|
buildArtifactFiles,
|
|
388
598
|
buildHitlDecisions,
|
|
389
|
-
buildHumanGroup,
|
|
390
599
|
buildHumanInputResponse,
|
|
391
600
|
buildInterruptReviewBlock,
|
|
392
|
-
buildInterruptReviewGroup,
|
|
393
601
|
buildRejectDecisions,
|
|
394
602
|
buildReportBodyPayload,
|
|
395
603
|
buildReportOutlinePayload,
|
|
396
604
|
buildRunDirectLatencyMs,
|
|
397
605
|
buildRunInfo,
|
|
606
|
+
buildRunMeta,
|
|
398
607
|
collectTextKeepSxin,
|
|
399
608
|
collectVisibleText,
|
|
400
|
-
createBlockBuilderLite,
|
|
401
609
|
createChatCore,
|
|
402
610
|
createEmptySubChapter,
|
|
403
|
-
createGroupDeriver,
|
|
404
611
|
createMockTransport,
|
|
405
|
-
|
|
406
|
-
createStreamPump,
|
|
612
|
+
createSemanticOverlay,
|
|
407
613
|
createThreadRuntime,
|
|
408
|
-
createViewModelState,
|
|
409
614
|
deriveToolsFromMessages,
|
|
615
|
+
emptyRunItem,
|
|
410
616
|
ensureOutlineContentThemes,
|
|
411
617
|
ensureRunningRun,
|
|
412
618
|
extractAiContentFromMessage,
|
|
@@ -414,31 +620,36 @@ export {
|
|
|
414
620
|
extractBlocksFromNodes,
|
|
415
621
|
extractCitationAnchors,
|
|
416
622
|
extractCitationAnchorsFromSpec,
|
|
623
|
+
extractFromToolResult,
|
|
624
|
+
extractInputFromRows,
|
|
417
625
|
extractReportTitleFromBody,
|
|
418
626
|
extractRunEnrichment,
|
|
627
|
+
extractSemanticPatchesFromMessages,
|
|
419
628
|
extractStateMessages,
|
|
420
629
|
extractTextFromMessage,
|
|
421
630
|
extractThreadInfo,
|
|
422
631
|
extractTitleFromArtifactPath,
|
|
423
632
|
extractUserMessageTexts,
|
|
424
|
-
|
|
633
|
+
formatAnswerText,
|
|
425
634
|
formatStr,
|
|
426
635
|
genBlockId,
|
|
427
636
|
genMessageId,
|
|
428
637
|
getAllowedDecisions,
|
|
429
638
|
getHumanMessageBaseId,
|
|
430
639
|
getToolCallArtifactMeta,
|
|
640
|
+
groupRowsByRun,
|
|
431
641
|
isAiMessage,
|
|
432
|
-
isClarificationAnswered,
|
|
433
|
-
isClarificationBlock,
|
|
434
642
|
isHiddenUserMessage,
|
|
435
643
|
isHumanMessage,
|
|
436
644
|
isInjectedElement,
|
|
437
645
|
isReportBodyHtml,
|
|
438
646
|
isSameArgs,
|
|
439
647
|
isToolMessage,
|
|
648
|
+
isUserEchoRow,
|
|
440
649
|
isVisibleUserMessage,
|
|
441
650
|
isWriteFileToolName,
|
|
651
|
+
mapBackendStatus,
|
|
652
|
+
mergeStateWithPageMessages,
|
|
442
653
|
normalizeForCompare,
|
|
443
654
|
normalizeMessageType,
|
|
444
655
|
normalizeOutline,
|
|
@@ -447,11 +658,15 @@ export {
|
|
|
447
658
|
parseHumanMessageId,
|
|
448
659
|
parseKnowledgeItemsFromValue,
|
|
449
660
|
parseMarkdownToOutline,
|
|
661
|
+
pickRicherArgs,
|
|
450
662
|
pickRunMessageMetadata,
|
|
663
|
+
projectRuns,
|
|
451
664
|
readMessageContentText,
|
|
452
665
|
resolveReportArtifactKind,
|
|
666
|
+
rowMessageId,
|
|
453
667
|
runMessagesToMessages,
|
|
454
668
|
simpleHash,
|
|
669
|
+
sliceBodySegments,
|
|
455
670
|
stateMessagesToRunMessages,
|
|
456
671
|
toRunMessage,
|
|
457
672
|
tokenizeSxin,
|