@cqfe/sxin-chat-core 1.0.3 → 1.0.5
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-CCeoxjP9.d.cts → ChatCore-DkvD2GqL.d.cts} +14 -1
- package/dist/{ChatCore-CCeoxjP9.d.ts → ChatCore-DkvD2GqL.d.ts} +14 -1
- package/dist/{chunk-2AXUXZVK.mjs → chunk-N2BKXRQO.mjs} +119 -16
- package/dist/index.cjs +125 -22
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.mjs +1 -1
- package/dist/vue/index.cjs +119 -16
- 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 +1 -1
|
@@ -327,10 +327,23 @@ interface IKwargs {
|
|
|
327
327
|
human_input_response?: Record<string, unknown>;
|
|
328
328
|
attachments?: IAttachment[];
|
|
329
329
|
selection?: Record<string, unknown>;
|
|
330
|
+
/** 页面引用条目:用户在业务页面明确选中的条目(sxin-additional-kwargs 协议 §5.7) */
|
|
331
|
+
page_references?: IPageReference[];
|
|
330
332
|
context?: Record<string, unknown>;
|
|
331
333
|
capability?: string[];
|
|
332
334
|
workflow?: Record<string, any>;
|
|
333
335
|
}
|
|
336
|
+
/** 页面引用条目:contract + id 定位业务对象,display_text 提供可读快照(仅消歧用) */
|
|
337
|
+
interface IPageReference {
|
|
338
|
+
/** sxin-item 的业务语义编码,如 visit.record,不是 Skill 或工具名称 */
|
|
339
|
+
contract: string;
|
|
340
|
+
/** 业务系统原始 ID,保持原值 */
|
|
341
|
+
id: string;
|
|
342
|
+
/** 唯一定位或读取该条目所需的参数,键名/值格式由业务工具校验 */
|
|
343
|
+
params?: Record<string, unknown>;
|
|
344
|
+
/** 单行纯文本快照,推荐"业务类型 + 2~4 个区分性字段",不代替实时查询 */
|
|
345
|
+
display_text?: string;
|
|
346
|
+
}
|
|
334
347
|
interface GenerateBodyRequest {
|
|
335
348
|
templateId: string;
|
|
336
349
|
outline: OutlineChapter[];
|
|
@@ -1135,4 +1148,4 @@ interface ChatCore {
|
|
|
1135
1148
|
}
|
|
1136
1149
|
declare function createChatCore(options: ChatCoreOptions): ChatCore;
|
|
1137
1150
|
|
|
1138
|
-
export { type
|
|
1151
|
+
export { type InlineCitation as $, type AsmRow as A, type Block as B, type CitationItem as C, type FormBlock as D, type ExtractedPayload as E, type FetchMessagesPageOptions as F, type GroupMessageTool as G, type HitlResponse as H, type IKwargs as I, type FormFieldItem as J, type FormFieldType as K, type GenerateBodyRequest as L, type MessageTokenUsage as M, type GenerateBodyResult as N, type OutlineSubChapter as O, type ProjectRunsInput as P, type HitlActionRequest as Q, type RunInfo as R, type StreamSubmitInput as S, type ThreadInitialValues as T, type HitlDecision as U, type HitlDecisionType as V, type HitlInterruptPayload as W, type HitlReviewConfig as X, type IAttachment as Y, type IPageReference as Z, type IQuote as _, type RunMessage as a, type InterruptReviewBlock as a0, type ItemSegment as a1, type ListBlock as a2, type ListItem as a3, type Message as a4, type MessageMetadata as a5, type MessageRole as a6, type MessageSource as a7, type MessageStatus as a8, type PendingRun as a9, isSameArgs as aA, normalizeForCompare as aB, parseHitlPayload as aC, pickRunMessageMetadata as aD, sliceBodySegments as aE, type ReportAttachment as aa, type ReportGenerateBodyHumanKwargs as ab, type ReportSelectedArtifact as ac, type ReportSelectedTemplate as ad, type RunInputKind as ae, type RunMeta as af, type RunTokens as ag, type SearchThreadsOptions as ah, type SendMessageOptions as ai, type TextBlock as aj, ThreadDirectory as ak, type ThreadDirectoryOptions as al, type ThreadRuntime as am, type ThreadRuntimeOptions as an, type ThreadsPagination as ao, type ToolRun as ap, type XmlAttrs as aq, buildHitlDecisions as ar, buildInterruptReviewBlock as as, buildRejectDecisions as at, buildRunDirectLatencyMs as au, buildRunInfo as av, buildRunMeta as aw, createChatCore as ax, createThreadRuntime as ay, getAllowedDecisions as az, type ReportBodyPayload as b, type ReportOutlinePayload as c, type BlockBuilderOptions as d, type OutlineChapter as e, type RunItem as f, type RunStatus as g, type ChatTransport as h, type MessagesPage as i, type ThreadTokenUsage as j, type StreamSubmitOptions as k, type CreateStreamOptions as l, type AcquireResult as m, type AgentThreadState as n, type ArtifactFile as o, type Attachment as p, type BlockBase as q, type BlockSource as r, type BlockStatus as s, type BodySegment as t, type ChatCore as u, type ChatCoreOptions as v, type ChatNotify as w, type ChatStreamHandle as x, type ClarificationRecord as y, type CustomBlock as z };
|
|
@@ -327,10 +327,23 @@ interface IKwargs {
|
|
|
327
327
|
human_input_response?: Record<string, unknown>;
|
|
328
328
|
attachments?: IAttachment[];
|
|
329
329
|
selection?: Record<string, unknown>;
|
|
330
|
+
/** 页面引用条目:用户在业务页面明确选中的条目(sxin-additional-kwargs 协议 §5.7) */
|
|
331
|
+
page_references?: IPageReference[];
|
|
330
332
|
context?: Record<string, unknown>;
|
|
331
333
|
capability?: string[];
|
|
332
334
|
workflow?: Record<string, any>;
|
|
333
335
|
}
|
|
336
|
+
/** 页面引用条目:contract + id 定位业务对象,display_text 提供可读快照(仅消歧用) */
|
|
337
|
+
interface IPageReference {
|
|
338
|
+
/** sxin-item 的业务语义编码,如 visit.record,不是 Skill 或工具名称 */
|
|
339
|
+
contract: string;
|
|
340
|
+
/** 业务系统原始 ID,保持原值 */
|
|
341
|
+
id: string;
|
|
342
|
+
/** 唯一定位或读取该条目所需的参数,键名/值格式由业务工具校验 */
|
|
343
|
+
params?: Record<string, unknown>;
|
|
344
|
+
/** 单行纯文本快照,推荐"业务类型 + 2~4 个区分性字段",不代替实时查询 */
|
|
345
|
+
display_text?: string;
|
|
346
|
+
}
|
|
334
347
|
interface GenerateBodyRequest {
|
|
335
348
|
templateId: string;
|
|
336
349
|
outline: OutlineChapter[];
|
|
@@ -1135,4 +1148,4 @@ interface ChatCore {
|
|
|
1135
1148
|
}
|
|
1136
1149
|
declare function createChatCore(options: ChatCoreOptions): ChatCore;
|
|
1137
1150
|
|
|
1138
|
-
export { type
|
|
1151
|
+
export { type InlineCitation as $, type AsmRow as A, type Block as B, type CitationItem as C, type FormBlock as D, type ExtractedPayload as E, type FetchMessagesPageOptions as F, type GroupMessageTool as G, type HitlResponse as H, type IKwargs as I, type FormFieldItem as J, type FormFieldType as K, type GenerateBodyRequest as L, type MessageTokenUsage as M, type GenerateBodyResult as N, type OutlineSubChapter as O, type ProjectRunsInput as P, type HitlActionRequest as Q, type RunInfo as R, type StreamSubmitInput as S, type ThreadInitialValues as T, type HitlDecision as U, type HitlDecisionType as V, type HitlInterruptPayload as W, type HitlReviewConfig as X, type IAttachment as Y, type IPageReference as Z, type IQuote as _, type RunMessage as a, type InterruptReviewBlock as a0, type ItemSegment as a1, type ListBlock as a2, type ListItem as a3, type Message as a4, type MessageMetadata as a5, type MessageRole as a6, type MessageSource as a7, type MessageStatus as a8, type PendingRun as a9, isSameArgs as aA, normalizeForCompare as aB, parseHitlPayload as aC, pickRunMessageMetadata as aD, sliceBodySegments as aE, type ReportAttachment as aa, type ReportGenerateBodyHumanKwargs as ab, type ReportSelectedArtifact as ac, type ReportSelectedTemplate as ad, type RunInputKind as ae, type RunMeta as af, type RunTokens as ag, type SearchThreadsOptions as ah, type SendMessageOptions as ai, type TextBlock as aj, ThreadDirectory as ak, type ThreadDirectoryOptions as al, type ThreadRuntime as am, type ThreadRuntimeOptions as an, type ThreadsPagination as ao, type ToolRun as ap, type XmlAttrs as aq, buildHitlDecisions as ar, buildInterruptReviewBlock as as, buildRejectDecisions as at, buildRunDirectLatencyMs as au, buildRunInfo as av, buildRunMeta as aw, createChatCore as ax, createThreadRuntime as ay, getAllowedDecisions as az, type ReportBodyPayload as b, type ReportOutlinePayload as c, type BlockBuilderOptions as d, type OutlineChapter as e, type RunItem as f, type RunStatus as g, type ChatTransport as h, type MessagesPage as i, type ThreadTokenUsage as j, type StreamSubmitOptions as k, type CreateStreamOptions as l, type AcquireResult as m, type AgentThreadState as n, type ArtifactFile as o, type Attachment as p, type BlockBase as q, type BlockSource as r, type BlockStatus as s, type BodySegment as t, type ChatCore as u, type ChatCoreOptions as v, type ChatNotify as w, type ChatStreamHandle as x, type ClarificationRecord as y, type CustomBlock as z };
|
|
@@ -1064,7 +1064,8 @@ function sliceBodySegments(body) {
|
|
|
1064
1064
|
// src/assembler/run-grouping.ts
|
|
1065
1065
|
var LIVE_SEQ = Number.MAX_SAFE_INTEGER;
|
|
1066
1066
|
function rowMessageId(msg) {
|
|
1067
|
-
|
|
1067
|
+
const m = msg;
|
|
1068
|
+
return String(m?.id || m?.tool_call_id || "").trim();
|
|
1068
1069
|
}
|
|
1069
1070
|
function isUserEchoRow(id) {
|
|
1070
1071
|
return id.endsWith("__user");
|
|
@@ -1087,12 +1088,23 @@ function liveToAsmRow(msg, runId) {
|
|
|
1087
1088
|
if (!id || isUserEchoRow(id)) return null;
|
|
1088
1089
|
return { id, runId, seq: LIVE_SEQ, msg };
|
|
1089
1090
|
}
|
|
1091
|
+
function collectPageToolCallIds(msg, into) {
|
|
1092
|
+
const m = msg;
|
|
1093
|
+
const calls = Array.isArray(m?.tool_calls) ? m.tool_calls : m?.additional_kwargs?.tool_calls;
|
|
1094
|
+
if (!Array.isArray(calls)) return;
|
|
1095
|
+
for (const call of calls) {
|
|
1096
|
+
const callId = String(call?.id || "").trim();
|
|
1097
|
+
if (callId) into.add(callId);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1090
1100
|
function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
1091
1101
|
const byId = /* @__PURE__ */ new Map();
|
|
1092
1102
|
const buckets = /* @__PURE__ */ new Map();
|
|
1103
|
+
const pageToolCallIds = /* @__PURE__ */ new Set();
|
|
1093
1104
|
for (const row of rows) {
|
|
1094
1105
|
const asm = pageRowToAsmRow(row);
|
|
1095
1106
|
if (!asm) continue;
|
|
1107
|
+
if (String(row.content?.type || "") === "ai") collectPageToolCallIds(row.content, pageToolCallIds);
|
|
1096
1108
|
const prev = byId.get(asm.id);
|
|
1097
1109
|
if (prev) {
|
|
1098
1110
|
if (asm.seq >= prev.seq) {
|
|
@@ -1110,6 +1122,9 @@ function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
|
1110
1122
|
const asm = liveToAsmRow(msg, liveRunId);
|
|
1111
1123
|
if (!asm) continue;
|
|
1112
1124
|
if (byId.has(asm.id)) continue;
|
|
1125
|
+
if (String(msg?.type || "") === "tool" && pageToolCallIds.has(String(msg?.tool_call_id || "").trim())) {
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1113
1128
|
pushToBucket(buckets, asm);
|
|
1114
1129
|
}
|
|
1115
1130
|
}
|
|
@@ -1440,6 +1455,14 @@ function projectRuns(input) {
|
|
|
1440
1455
|
runs.push(placeholder);
|
|
1441
1456
|
}
|
|
1442
1457
|
const answers = input.answers;
|
|
1458
|
+
const answerByCallId = /* @__PURE__ */ new Map();
|
|
1459
|
+
for (const meta of input.runsList) {
|
|
1460
|
+
const response = meta.inputMessages?.map((m) => m?.additional_kwargs?.human_input_response).find((r) => r && typeof r === "object");
|
|
1461
|
+
if (!response || typeof response !== "object") continue;
|
|
1462
|
+
const requestId = normalizeRequestId(response.request_id);
|
|
1463
|
+
if (!requestId) continue;
|
|
1464
|
+
answerByCallId.set(requestId, { answer: formatAnswerText(response.value), answerRunId: String(meta.runId || "") });
|
|
1465
|
+
}
|
|
1443
1466
|
for (let i = 0; i < runs.length; i++) {
|
|
1444
1467
|
const run = runs[i];
|
|
1445
1468
|
for (const record of run.clarifications) {
|
|
@@ -1449,6 +1472,12 @@ function projectRuns(input) {
|
|
|
1449
1472
|
record.answer = optimistic;
|
|
1450
1473
|
continue;
|
|
1451
1474
|
}
|
|
1475
|
+
const fromList = answerByCallId.get(normalizeRequestId(record.callId));
|
|
1476
|
+
if (fromList) {
|
|
1477
|
+
record.answer = fromList.answer;
|
|
1478
|
+
record.answerRunId = fromList.answerRunId;
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1452
1481
|
for (let j = i + 1; j < runs.length; j++) {
|
|
1453
1482
|
const laterKwargs = runs[j].input.kwargs;
|
|
1454
1483
|
const response = laterKwargs?.human_input_response;
|
|
@@ -1764,7 +1793,8 @@ function createStreamActions(ctx) {
|
|
|
1764
1793
|
if (!handle) return;
|
|
1765
1794
|
ctx.beginStream();
|
|
1766
1795
|
const kwargs = submitOptions?.kwargs ?? void 0;
|
|
1767
|
-
|
|
1796
|
+
const kind = kwargs?.human_input_response ? "clarification" : "message";
|
|
1797
|
+
ctx.createPendingRun(text, kind, kwargs);
|
|
1768
1798
|
const humanMessage = { type: "human", content: [{ type: "text", text }] };
|
|
1769
1799
|
humanMessage.additional_kwargs = submitOptions?.kwargs;
|
|
1770
1800
|
handle.submit({ messages: [humanMessage] }, { onDisconnect: "continue", config: { recursion_limit: 1e3 } });
|
|
@@ -1806,6 +1836,10 @@ function createStreamActions(ctx) {
|
|
|
1806
1836
|
|
|
1807
1837
|
// src/runtime/rows-store.ts
|
|
1808
1838
|
import { shallowRef } from "vue";
|
|
1839
|
+
function rowKey(content) {
|
|
1840
|
+
const c = content;
|
|
1841
|
+
return String(c?.id || c?.tool_call_id || "").trim();
|
|
1842
|
+
}
|
|
1809
1843
|
function createRowsStore() {
|
|
1810
1844
|
const rows = shallowRef([]);
|
|
1811
1845
|
const sortRows = (list) => [...list].sort((a, b) => a.seq - b.seq);
|
|
@@ -1816,11 +1850,11 @@ function createRowsStore() {
|
|
|
1816
1850
|
},
|
|
1817
1851
|
prepend(older) {
|
|
1818
1852
|
if (!older.length) return;
|
|
1819
|
-
const seen = new Set(rows.value.map((r) =>
|
|
1853
|
+
const seen = new Set(rows.value.map((r) => rowKey(r.content)));
|
|
1820
1854
|
const fresh = older.filter((r) => {
|
|
1821
|
-
const
|
|
1822
|
-
if (!
|
|
1823
|
-
seen.add(
|
|
1855
|
+
const key = rowKey(r.content);
|
|
1856
|
+
if (!key || seen.has(key)) return false;
|
|
1857
|
+
seen.add(key);
|
|
1824
1858
|
return true;
|
|
1825
1859
|
});
|
|
1826
1860
|
if (!fresh.length) return;
|
|
@@ -1828,13 +1862,13 @@ function createRowsStore() {
|
|
|
1828
1862
|
},
|
|
1829
1863
|
mergeLatest(latest) {
|
|
1830
1864
|
if (!latest.length) return;
|
|
1831
|
-
const
|
|
1865
|
+
const byKey = new Map(rows.value.map((r) => [rowKey(r.content), r]));
|
|
1832
1866
|
for (const row of latest) {
|
|
1833
|
-
const
|
|
1834
|
-
if (!
|
|
1835
|
-
|
|
1867
|
+
const key = rowKey(row.content);
|
|
1868
|
+
if (!key) continue;
|
|
1869
|
+
byKey.set(key, row);
|
|
1836
1870
|
}
|
|
1837
|
-
rows.value = sortRows([...
|
|
1871
|
+
rows.value = sortRows([...byKey.values()]);
|
|
1838
1872
|
}
|
|
1839
1873
|
};
|
|
1840
1874
|
}
|
|
@@ -1849,6 +1883,61 @@ function extractLiveIncrement(snapshot, lastSeenIds) {
|
|
|
1849
1883
|
return fresh;
|
|
1850
1884
|
}
|
|
1851
1885
|
|
|
1886
|
+
// src/assembler/stable-project-runs.ts
|
|
1887
|
+
var refSeq = 0;
|
|
1888
|
+
var refIds = /* @__PURE__ */ new WeakMap();
|
|
1889
|
+
function refId(value) {
|
|
1890
|
+
if (value === null || value === void 0) return "-";
|
|
1891
|
+
if (typeof value === "object") {
|
|
1892
|
+
let id = refIds.get(value);
|
|
1893
|
+
if (id === void 0) {
|
|
1894
|
+
id = ++refSeq;
|
|
1895
|
+
refIds.set(value, id);
|
|
1896
|
+
}
|
|
1897
|
+
return String(id);
|
|
1898
|
+
}
|
|
1899
|
+
return String(value);
|
|
1900
|
+
}
|
|
1901
|
+
function runFingerprint(run) {
|
|
1902
|
+
let fp = `${run.status}|${run.input.kind}|${run.input.text}`;
|
|
1903
|
+
if (run.createdAt !== void 0) fp += `|c${run.createdAt}`;
|
|
1904
|
+
if (run.tokens !== void 0) fp += `|t${JSON.stringify(run.tokens)}`;
|
|
1905
|
+
const stopReason = run.stopReason;
|
|
1906
|
+
if (stopReason !== void 0) fp += `|s${String(stopReason)}`;
|
|
1907
|
+
for (const row of run.rawMessages) {
|
|
1908
|
+
fp += `|${row.seq}:${refId(row.msg)}:${refId(row.feedback ?? null)}`;
|
|
1909
|
+
}
|
|
1910
|
+
return fp;
|
|
1911
|
+
}
|
|
1912
|
+
function globalSignal(input, next) {
|
|
1913
|
+
const runIds = next.map((r) => r.runId).join(",");
|
|
1914
|
+
const runsListRef = input.runsList.length ? refId(input.runsList) : "empty";
|
|
1915
|
+
const answersRef = input.answers && input.answers.size ? refId(input.answers) : "empty";
|
|
1916
|
+
return `${runIds}#${runsListRef}#${answersRef}`;
|
|
1917
|
+
}
|
|
1918
|
+
function createStableRunsProjector() {
|
|
1919
|
+
let cache = /* @__PURE__ */ new Map();
|
|
1920
|
+
let lastGlobal = "";
|
|
1921
|
+
return function projectRunsStable(input) {
|
|
1922
|
+
const next = projectRuns(input);
|
|
1923
|
+
const signal = globalSignal(input, next);
|
|
1924
|
+
if (signal !== lastGlobal) {
|
|
1925
|
+
lastGlobal = signal;
|
|
1926
|
+
cache = /* @__PURE__ */ new Map();
|
|
1927
|
+
}
|
|
1928
|
+
const activeId = input.streaming ? input.activeRunId : null;
|
|
1929
|
+
const pendingId = input.pendingRun?.runId ?? null;
|
|
1930
|
+
return next.map((run) => {
|
|
1931
|
+
if (run.runId === activeId || run.runId === pendingId) return run;
|
|
1932
|
+
const fingerprint = runFingerprint(run);
|
|
1933
|
+
const hit = cache.get(run.runId);
|
|
1934
|
+
if (hit && hit.fingerprint === fingerprint) return hit.item;
|
|
1935
|
+
cache.set(run.runId, { fingerprint, item: run });
|
|
1936
|
+
return run;
|
|
1937
|
+
});
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1852
1941
|
// src/runtime/values-projection.ts
|
|
1853
1942
|
function createValuesChannel(options = {}) {
|
|
1854
1943
|
let latestStreamMessages = [];
|
|
@@ -2011,8 +2100,9 @@ function createThreadRuntime(options) {
|
|
|
2011
2100
|
const pendingRun = shallowRef3(null);
|
|
2012
2101
|
const answers = shallowRef3(/* @__PURE__ */ new Map());
|
|
2013
2102
|
const activeRunId = computed2(() => runs.currentRunId.value);
|
|
2103
|
+
const projectRunsStable = createStableRunsProjector();
|
|
2014
2104
|
const runsProjection = computed2(
|
|
2015
|
-
() =>
|
|
2105
|
+
() => projectRunsStable({
|
|
2016
2106
|
rows: rowsStore.rows.value,
|
|
2017
2107
|
liveMessages: liveMessages.value,
|
|
2018
2108
|
activeRunId: activeRunId.value,
|
|
@@ -2067,13 +2157,26 @@ function createThreadRuntime(options) {
|
|
|
2067
2157
|
};
|
|
2068
2158
|
const applyLiveSnapshot = (messages) => {
|
|
2069
2159
|
if (!streaming.value) return;
|
|
2070
|
-
const
|
|
2071
|
-
const
|
|
2160
|
+
const snapshot = messages;
|
|
2161
|
+
const latestById = /* @__PURE__ */ new Map();
|
|
2162
|
+
for (const m of snapshot) {
|
|
2163
|
+
const id = String(m?.id || "").trim();
|
|
2164
|
+
if (id) latestById.set(id, m);
|
|
2165
|
+
}
|
|
2166
|
+
let changed = false;
|
|
2167
|
+
const refreshed = liveMessages.value.map((m) => {
|
|
2168
|
+
const id = String(m?.id || "").trim();
|
|
2169
|
+
const latest = id ? latestById.get(id) : void 0;
|
|
2170
|
+
if (!latest || latest === m) return m;
|
|
2171
|
+
changed = true;
|
|
2172
|
+
return latest;
|
|
2173
|
+
});
|
|
2174
|
+
const eligible = extractLiveIncrement(snapshot, lastSeenLiveIds).filter((m) => {
|
|
2072
2175
|
const t = String(m?.type || "");
|
|
2073
2176
|
return t === "ai" || t === "tool";
|
|
2074
2177
|
});
|
|
2075
|
-
if (!eligible.length) return;
|
|
2076
|
-
liveMessages.value = [...
|
|
2178
|
+
if (!changed && !eligible.length) return;
|
|
2179
|
+
liveMessages.value = eligible.length ? [...refreshed, ...eligible] : refreshed;
|
|
2077
2180
|
};
|
|
2078
2181
|
const refreshTokenUsage = async () => {
|
|
2079
2182
|
try {
|
package/dist/index.cjs
CHANGED
|
@@ -496,7 +496,7 @@ var normalizeOne = (raw) => {
|
|
|
496
496
|
for (const [field, keys] of Object.entries(STRING_FIELD_KEYS)) {
|
|
497
497
|
str[field] = pickString(raw, meta, keys);
|
|
498
498
|
}
|
|
499
|
-
const { refId, globalRef, minioBucket, minioObject, previewUrl, docUrl, docId, title, fileType } = str;
|
|
499
|
+
const { refId: refId2, globalRef, minioBucket, minioObject, previewUrl, docUrl, docId, title, fileType } = str;
|
|
500
500
|
const arr = {};
|
|
501
501
|
for (const [field, keys] of Object.entries(ARRAY_FIELD_KEYS)) {
|
|
502
502
|
arr[field] = pickStringArray(raw, meta, keys);
|
|
@@ -508,7 +508,7 @@ var normalizeOne = (raw) => {
|
|
|
508
508
|
if (!key && !previewUrl && !docUrl) return null;
|
|
509
509
|
return {
|
|
510
510
|
key,
|
|
511
|
-
refId: orUndefined(
|
|
511
|
+
refId: orUndefined(refId2),
|
|
512
512
|
globalRef: orUndefined(globalRef),
|
|
513
513
|
title,
|
|
514
514
|
docId,
|
|
@@ -550,10 +550,10 @@ function extractCitationAnchorsFromSpec(spec) {
|
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
552
|
for (const item of candidates) {
|
|
553
|
-
const
|
|
554
|
-
if (!
|
|
555
|
-
seen.add(
|
|
556
|
-
const anchor = { refId, title: "" };
|
|
553
|
+
const refId2 = pickFirstString(item, REF_ID_KEYS);
|
|
554
|
+
if (!refId2 || seen.has(refId2)) continue;
|
|
555
|
+
seen.add(refId2);
|
|
556
|
+
const anchor = { refId: refId2, title: "" };
|
|
557
557
|
const searchText = pickFirstString(item, SEARCH_TEXT_KEYS);
|
|
558
558
|
if (searchText) anchor.searchText = searchText;
|
|
559
559
|
anchors.push(anchor);
|
|
@@ -1486,7 +1486,8 @@ function sliceBodySegments(body) {
|
|
|
1486
1486
|
// src/assembler/run-grouping.ts
|
|
1487
1487
|
var LIVE_SEQ = Number.MAX_SAFE_INTEGER;
|
|
1488
1488
|
function rowMessageId(msg) {
|
|
1489
|
-
|
|
1489
|
+
const m = msg;
|
|
1490
|
+
return String(m?.id || m?.tool_call_id || "").trim();
|
|
1490
1491
|
}
|
|
1491
1492
|
function isUserEchoRow(id) {
|
|
1492
1493
|
return id.endsWith("__user");
|
|
@@ -1509,12 +1510,23 @@ function liveToAsmRow(msg, runId) {
|
|
|
1509
1510
|
if (!id || isUserEchoRow(id)) return null;
|
|
1510
1511
|
return { id, runId, seq: LIVE_SEQ, msg };
|
|
1511
1512
|
}
|
|
1513
|
+
function collectPageToolCallIds(msg, into) {
|
|
1514
|
+
const m = msg;
|
|
1515
|
+
const calls = Array.isArray(m?.tool_calls) ? m.tool_calls : m?.additional_kwargs?.tool_calls;
|
|
1516
|
+
if (!Array.isArray(calls)) return;
|
|
1517
|
+
for (const call of calls) {
|
|
1518
|
+
const callId = String(call?.id || "").trim();
|
|
1519
|
+
if (callId) into.add(callId);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1512
1522
|
function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
1513
1523
|
const byId = /* @__PURE__ */ new Map();
|
|
1514
1524
|
const buckets = /* @__PURE__ */ new Map();
|
|
1525
|
+
const pageToolCallIds = /* @__PURE__ */ new Set();
|
|
1515
1526
|
for (const row of rows) {
|
|
1516
1527
|
const asm = pageRowToAsmRow(row);
|
|
1517
1528
|
if (!asm) continue;
|
|
1529
|
+
if (String(row.content?.type || "") === "ai") collectPageToolCallIds(row.content, pageToolCallIds);
|
|
1518
1530
|
const prev = byId.get(asm.id);
|
|
1519
1531
|
if (prev) {
|
|
1520
1532
|
if (asm.seq >= prev.seq) {
|
|
@@ -1532,6 +1544,9 @@ function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
|
1532
1544
|
const asm = liveToAsmRow(msg, liveRunId);
|
|
1533
1545
|
if (!asm) continue;
|
|
1534
1546
|
if (byId.has(asm.id)) continue;
|
|
1547
|
+
if (String(msg?.type || "") === "tool" && pageToolCallIds.has(String(msg?.tool_call_id || "").trim())) {
|
|
1548
|
+
continue;
|
|
1549
|
+
}
|
|
1535
1550
|
pushToBucket(buckets, asm);
|
|
1536
1551
|
}
|
|
1537
1552
|
}
|
|
@@ -1862,6 +1877,14 @@ function projectRuns(input) {
|
|
|
1862
1877
|
runs.push(placeholder);
|
|
1863
1878
|
}
|
|
1864
1879
|
const answers = input.answers;
|
|
1880
|
+
const answerByCallId = /* @__PURE__ */ new Map();
|
|
1881
|
+
for (const meta of input.runsList) {
|
|
1882
|
+
const response = meta.inputMessages?.map((m) => m?.additional_kwargs?.human_input_response).find((r) => r && typeof r === "object");
|
|
1883
|
+
if (!response || typeof response !== "object") continue;
|
|
1884
|
+
const requestId = normalizeRequestId(response.request_id);
|
|
1885
|
+
if (!requestId) continue;
|
|
1886
|
+
answerByCallId.set(requestId, { answer: formatAnswerText(response.value), answerRunId: String(meta.runId || "") });
|
|
1887
|
+
}
|
|
1865
1888
|
for (let i = 0; i < runs.length; i++) {
|
|
1866
1889
|
const run = runs[i];
|
|
1867
1890
|
for (const record of run.clarifications) {
|
|
@@ -1871,6 +1894,12 @@ function projectRuns(input) {
|
|
|
1871
1894
|
record.answer = optimistic;
|
|
1872
1895
|
continue;
|
|
1873
1896
|
}
|
|
1897
|
+
const fromList = answerByCallId.get(normalizeRequestId(record.callId));
|
|
1898
|
+
if (fromList) {
|
|
1899
|
+
record.answer = fromList.answer;
|
|
1900
|
+
record.answerRunId = fromList.answerRunId;
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1874
1903
|
for (let j = i + 1; j < runs.length; j++) {
|
|
1875
1904
|
const laterKwargs = runs[j].input.kwargs;
|
|
1876
1905
|
const response = laterKwargs?.human_input_response;
|
|
@@ -2186,7 +2215,8 @@ function createStreamActions(ctx) {
|
|
|
2186
2215
|
if (!handle) return;
|
|
2187
2216
|
ctx.beginStream();
|
|
2188
2217
|
const kwargs = submitOptions?.kwargs ?? void 0;
|
|
2189
|
-
|
|
2218
|
+
const kind = kwargs?.human_input_response ? "clarification" : "message";
|
|
2219
|
+
ctx.createPendingRun(text, kind, kwargs);
|
|
2190
2220
|
const humanMessage = { type: "human", content: [{ type: "text", text }] };
|
|
2191
2221
|
humanMessage.additional_kwargs = submitOptions?.kwargs;
|
|
2192
2222
|
handle.submit({ messages: [humanMessage] }, { onDisconnect: "continue", config: { recursion_limit: 1e3 } });
|
|
@@ -2228,6 +2258,10 @@ function createStreamActions(ctx) {
|
|
|
2228
2258
|
|
|
2229
2259
|
// src/runtime/rows-store.ts
|
|
2230
2260
|
var import_vue2 = require("vue");
|
|
2261
|
+
function rowKey(content) {
|
|
2262
|
+
const c = content;
|
|
2263
|
+
return String(c?.id || c?.tool_call_id || "").trim();
|
|
2264
|
+
}
|
|
2231
2265
|
function createRowsStore() {
|
|
2232
2266
|
const rows = (0, import_vue2.shallowRef)([]);
|
|
2233
2267
|
const sortRows = (list) => [...list].sort((a, b) => a.seq - b.seq);
|
|
@@ -2238,11 +2272,11 @@ function createRowsStore() {
|
|
|
2238
2272
|
},
|
|
2239
2273
|
prepend(older) {
|
|
2240
2274
|
if (!older.length) return;
|
|
2241
|
-
const seen = new Set(rows.value.map((r) =>
|
|
2275
|
+
const seen = new Set(rows.value.map((r) => rowKey(r.content)));
|
|
2242
2276
|
const fresh = older.filter((r) => {
|
|
2243
|
-
const
|
|
2244
|
-
if (!
|
|
2245
|
-
seen.add(
|
|
2277
|
+
const key = rowKey(r.content);
|
|
2278
|
+
if (!key || seen.has(key)) return false;
|
|
2279
|
+
seen.add(key);
|
|
2246
2280
|
return true;
|
|
2247
2281
|
});
|
|
2248
2282
|
if (!fresh.length) return;
|
|
@@ -2250,13 +2284,13 @@ function createRowsStore() {
|
|
|
2250
2284
|
},
|
|
2251
2285
|
mergeLatest(latest) {
|
|
2252
2286
|
if (!latest.length) return;
|
|
2253
|
-
const
|
|
2287
|
+
const byKey = new Map(rows.value.map((r) => [rowKey(r.content), r]));
|
|
2254
2288
|
for (const row of latest) {
|
|
2255
|
-
const
|
|
2256
|
-
if (!
|
|
2257
|
-
|
|
2289
|
+
const key = rowKey(row.content);
|
|
2290
|
+
if (!key) continue;
|
|
2291
|
+
byKey.set(key, row);
|
|
2258
2292
|
}
|
|
2259
|
-
rows.value = sortRows([...
|
|
2293
|
+
rows.value = sortRows([...byKey.values()]);
|
|
2260
2294
|
}
|
|
2261
2295
|
};
|
|
2262
2296
|
}
|
|
@@ -2271,6 +2305,61 @@ function extractLiveIncrement(snapshot, lastSeenIds) {
|
|
|
2271
2305
|
return fresh;
|
|
2272
2306
|
}
|
|
2273
2307
|
|
|
2308
|
+
// src/assembler/stable-project-runs.ts
|
|
2309
|
+
var refSeq = 0;
|
|
2310
|
+
var refIds = /* @__PURE__ */ new WeakMap();
|
|
2311
|
+
function refId(value) {
|
|
2312
|
+
if (value === null || value === void 0) return "-";
|
|
2313
|
+
if (typeof value === "object") {
|
|
2314
|
+
let id = refIds.get(value);
|
|
2315
|
+
if (id === void 0) {
|
|
2316
|
+
id = ++refSeq;
|
|
2317
|
+
refIds.set(value, id);
|
|
2318
|
+
}
|
|
2319
|
+
return String(id);
|
|
2320
|
+
}
|
|
2321
|
+
return String(value);
|
|
2322
|
+
}
|
|
2323
|
+
function runFingerprint(run) {
|
|
2324
|
+
let fp = `${run.status}|${run.input.kind}|${run.input.text}`;
|
|
2325
|
+
if (run.createdAt !== void 0) fp += `|c${run.createdAt}`;
|
|
2326
|
+
if (run.tokens !== void 0) fp += `|t${JSON.stringify(run.tokens)}`;
|
|
2327
|
+
const stopReason = run.stopReason;
|
|
2328
|
+
if (stopReason !== void 0) fp += `|s${String(stopReason)}`;
|
|
2329
|
+
for (const row of run.rawMessages) {
|
|
2330
|
+
fp += `|${row.seq}:${refId(row.msg)}:${refId(row.feedback ?? null)}`;
|
|
2331
|
+
}
|
|
2332
|
+
return fp;
|
|
2333
|
+
}
|
|
2334
|
+
function globalSignal(input, next) {
|
|
2335
|
+
const runIds = next.map((r) => r.runId).join(",");
|
|
2336
|
+
const runsListRef = input.runsList.length ? refId(input.runsList) : "empty";
|
|
2337
|
+
const answersRef = input.answers && input.answers.size ? refId(input.answers) : "empty";
|
|
2338
|
+
return `${runIds}#${runsListRef}#${answersRef}`;
|
|
2339
|
+
}
|
|
2340
|
+
function createStableRunsProjector() {
|
|
2341
|
+
let cache = /* @__PURE__ */ new Map();
|
|
2342
|
+
let lastGlobal = "";
|
|
2343
|
+
return function projectRunsStable(input) {
|
|
2344
|
+
const next = projectRuns(input);
|
|
2345
|
+
const signal = globalSignal(input, next);
|
|
2346
|
+
if (signal !== lastGlobal) {
|
|
2347
|
+
lastGlobal = signal;
|
|
2348
|
+
cache = /* @__PURE__ */ new Map();
|
|
2349
|
+
}
|
|
2350
|
+
const activeId = input.streaming ? input.activeRunId : null;
|
|
2351
|
+
const pendingId = input.pendingRun?.runId ?? null;
|
|
2352
|
+
return next.map((run) => {
|
|
2353
|
+
if (run.runId === activeId || run.runId === pendingId) return run;
|
|
2354
|
+
const fingerprint = runFingerprint(run);
|
|
2355
|
+
const hit = cache.get(run.runId);
|
|
2356
|
+
if (hit && hit.fingerprint === fingerprint) return hit.item;
|
|
2357
|
+
cache.set(run.runId, { fingerprint, item: run });
|
|
2358
|
+
return run;
|
|
2359
|
+
});
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2274
2363
|
// src/runtime/values-projection.ts
|
|
2275
2364
|
function createValuesChannel(options = {}) {
|
|
2276
2365
|
let latestStreamMessages = [];
|
|
@@ -2433,8 +2522,9 @@ function createThreadRuntime(options) {
|
|
|
2433
2522
|
const pendingRun = (0, import_vue4.shallowRef)(null);
|
|
2434
2523
|
const answers = (0, import_vue4.shallowRef)(/* @__PURE__ */ new Map());
|
|
2435
2524
|
const activeRunId = (0, import_vue4.computed)(() => runs.currentRunId.value);
|
|
2525
|
+
const projectRunsStable = createStableRunsProjector();
|
|
2436
2526
|
const runsProjection = (0, import_vue4.computed)(
|
|
2437
|
-
() =>
|
|
2527
|
+
() => projectRunsStable({
|
|
2438
2528
|
rows: rowsStore.rows.value,
|
|
2439
2529
|
liveMessages: liveMessages.value,
|
|
2440
2530
|
activeRunId: activeRunId.value,
|
|
@@ -2489,13 +2579,26 @@ function createThreadRuntime(options) {
|
|
|
2489
2579
|
};
|
|
2490
2580
|
const applyLiveSnapshot = (messages) => {
|
|
2491
2581
|
if (!streaming.value) return;
|
|
2492
|
-
const
|
|
2493
|
-
const
|
|
2582
|
+
const snapshot = messages;
|
|
2583
|
+
const latestById = /* @__PURE__ */ new Map();
|
|
2584
|
+
for (const m of snapshot) {
|
|
2585
|
+
const id = String(m?.id || "").trim();
|
|
2586
|
+
if (id) latestById.set(id, m);
|
|
2587
|
+
}
|
|
2588
|
+
let changed = false;
|
|
2589
|
+
const refreshed = liveMessages.value.map((m) => {
|
|
2590
|
+
const id = String(m?.id || "").trim();
|
|
2591
|
+
const latest = id ? latestById.get(id) : void 0;
|
|
2592
|
+
if (!latest || latest === m) return m;
|
|
2593
|
+
changed = true;
|
|
2594
|
+
return latest;
|
|
2595
|
+
});
|
|
2596
|
+
const eligible = extractLiveIncrement(snapshot, lastSeenLiveIds).filter((m) => {
|
|
2494
2597
|
const t = String(m?.type || "");
|
|
2495
2598
|
return t === "ai" || t === "tool";
|
|
2496
2599
|
});
|
|
2497
|
-
if (!eligible.length) return;
|
|
2498
|
-
liveMessages.value = [...
|
|
2600
|
+
if (!changed && !eligible.length) return;
|
|
2601
|
+
liveMessages.value = eligible.length ? [...refreshed, ...eligible] : refreshed;
|
|
2499
2602
|
};
|
|
2500
2603
|
const refreshTokenUsage = async () => {
|
|
2501
2604
|
try {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as Block, C as CitationItem, I as IKwargs, R as RunInfo, a as RunMessage, b as ReportBodyPayload, c as ReportOutlinePayload, d as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, e as OutlineChapter, P as ProjectRunsInput, f as RunItem, A as AsmRow, g as RunStatus, E as ExtractedPayload, h as ChatTransport, T as ThreadInitialValues, i as MessagesPage, j as ThreadTokenUsage, S as StreamSubmitInput, k as StreamSubmitOptions, H as HitlResponse, l as CreateStreamOptions } from './ChatCore-
|
|
2
|
-
export { m as AcquireResult, n as AgentThreadState, o as ArtifactFile, p as Attachment, q as BlockBase, r as BlockSource, s as BlockStatus, t as BodySegment, u as ChatCore, v as ChatCoreOptions, w as ChatNotify, x as ChatStreamHandle, y as ClarificationRecord, z as CustomBlock, F as FetchMessagesPageOptions, D as FormBlock, J as FormFieldItem, K as FormFieldType, L as GenerateBodyRequest, N as GenerateBodyResult, Q as HitlActionRequest, U as HitlDecision, V as HitlDecisionType, W as HitlInterruptPayload, X as HitlReviewConfig, Y as IAttachment, Z as
|
|
1
|
+
import { B as Block, C as CitationItem, I as IKwargs, R as RunInfo, a as RunMessage, b as ReportBodyPayload, c as ReportOutlinePayload, d as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, e as OutlineChapter, P as ProjectRunsInput, f as RunItem, A as AsmRow, g as RunStatus, E as ExtractedPayload, h as ChatTransport, T as ThreadInitialValues, i as MessagesPage, j as ThreadTokenUsage, S as StreamSubmitInput, k as StreamSubmitOptions, H as HitlResponse, l as CreateStreamOptions } from './ChatCore-DkvD2GqL.cjs';
|
|
2
|
+
export { m as AcquireResult, n as AgentThreadState, o as ArtifactFile, p as Attachment, q as BlockBase, r as BlockSource, s as BlockStatus, t as BodySegment, u as ChatCore, v as ChatCoreOptions, w as ChatNotify, x as ChatStreamHandle, y as ClarificationRecord, z as CustomBlock, F as FetchMessagesPageOptions, D as FormBlock, J as FormFieldItem, K as FormFieldType, L as GenerateBodyRequest, N as GenerateBodyResult, Q as HitlActionRequest, U as HitlDecision, V as HitlDecisionType, W as HitlInterruptPayload, X as HitlReviewConfig, Y as IAttachment, Z as IPageReference, _ as IQuote, $ as InlineCitation, a0 as InterruptReviewBlock, a1 as ItemSegment, a2 as ListBlock, a3 as ListItem, a4 as Message, a5 as MessageMetadata, a6 as MessageRole, a7 as MessageSource, a8 as MessageStatus, a9 as PendingRun, aa as ReportAttachment, ab as ReportGenerateBodyHumanKwargs, ac as ReportSelectedArtifact, ad as ReportSelectedTemplate, ae as RunInputKind, af as RunMeta, ag as RunTokens, ah as SearchThreadsOptions, ai as SendMessageOptions, aj as TextBlock, ak as ThreadDirectory, al as ThreadDirectoryOptions, am as ThreadRuntime, an as ThreadRuntimeOptions, ao as ThreadsPagination, ap as ToolRun, aq as XmlAttrs, ar as buildHitlDecisions, as as buildInterruptReviewBlock, at as buildRejectDecisions, au as buildRunDirectLatencyMs, av as buildRunInfo, aw as buildRunMeta, ax as createChatCore, ay as createThreadRuntime, az as getAllowedDecisions, aA as isSameArgs, aB as normalizeForCompare, aC as parseHitlPayload, aD as pickRunMessageMetadata, aE as sliceBodySegments } from './ChatCore-DkvD2GqL.cjs';
|
|
3
3
|
import { Message, Interrupt } from '@langchain/langgraph-sdk';
|
|
4
4
|
import 'vue';
|
|
5
5
|
|
|
@@ -544,11 +544,15 @@ declare function mapBackendStatus(raw: string): RunStatus;
|
|
|
544
544
|
* - `__user` 后缀行语义按数据源区分:**page 行是后端 run-event 投影的触发输入本体**
|
|
545
545
|
* (实测每轮窗口的 human 行均为该形态,无无后缀原行——剔除会让 input 窗口兜底全部
|
|
546
546
|
* 落空),放行参与归组;live 行仍剔除(state 侧回放镜像,原行已在 page);
|
|
547
|
+
* - live tool 行 tool_call_id 命中 page 已登记调用 → 剔除(resume 流历史回放:
|
|
548
|
+
* 后端以新 id 回放前轮 tool 结果行,进活跃桶无 ai 载体可关联,只污染 rawMessages);
|
|
547
549
|
* - live 行在 activeRunId 为空时挂到 pendingRun.runId(metadata 未到的乐观窗口),
|
|
548
550
|
* 两者都缺则丢弃(无归属的孤儿行不渲染)。
|
|
549
551
|
*/
|
|
550
552
|
|
|
551
|
-
/**
|
|
553
|
+
/** 消息定位 id 提取:顶层 id 优先;tool 行 id 可能为 null(实测 page 的
|
|
554
|
+
* llm.tool.result 行),回退 tool_call_id 作为装配行键(callId 每次调用唯一);
|
|
555
|
+
* 两者皆空的行无法参与去重,直接丢弃 */
|
|
552
556
|
declare function rowMessageId(msg: Message): string;
|
|
553
557
|
/** `__user` 后缀重放行判定(resume run 窗口回放上一轮 human 的事件信封形态) */
|
|
554
558
|
declare function isUserEchoRow(id: string): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as Block, C as CitationItem, I as IKwargs, R as RunInfo, a as RunMessage, b as ReportBodyPayload, c as ReportOutlinePayload, d as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, e as OutlineChapter, P as ProjectRunsInput, f as RunItem, A as AsmRow, g as RunStatus, E as ExtractedPayload, h as ChatTransport, T as ThreadInitialValues, i as MessagesPage, j as ThreadTokenUsage, S as StreamSubmitInput, k as StreamSubmitOptions, H as HitlResponse, l as CreateStreamOptions } from './ChatCore-
|
|
2
|
-
export { m as AcquireResult, n as AgentThreadState, o as ArtifactFile, p as Attachment, q as BlockBase, r as BlockSource, s as BlockStatus, t as BodySegment, u as ChatCore, v as ChatCoreOptions, w as ChatNotify, x as ChatStreamHandle, y as ClarificationRecord, z as CustomBlock, F as FetchMessagesPageOptions, D as FormBlock, J as FormFieldItem, K as FormFieldType, L as GenerateBodyRequest, N as GenerateBodyResult, Q as HitlActionRequest, U as HitlDecision, V as HitlDecisionType, W as HitlInterruptPayload, X as HitlReviewConfig, Y as IAttachment, Z as
|
|
1
|
+
import { B as Block, C as CitationItem, I as IKwargs, R as RunInfo, a as RunMessage, b as ReportBodyPayload, c as ReportOutlinePayload, d as BlockBuilderOptions, G as GroupMessageTool, M as MessageTokenUsage, O as OutlineSubChapter, e as OutlineChapter, P as ProjectRunsInput, f as RunItem, A as AsmRow, g as RunStatus, E as ExtractedPayload, h as ChatTransport, T as ThreadInitialValues, i as MessagesPage, j as ThreadTokenUsage, S as StreamSubmitInput, k as StreamSubmitOptions, H as HitlResponse, l as CreateStreamOptions } from './ChatCore-DkvD2GqL.js';
|
|
2
|
+
export { m as AcquireResult, n as AgentThreadState, o as ArtifactFile, p as Attachment, q as BlockBase, r as BlockSource, s as BlockStatus, t as BodySegment, u as ChatCore, v as ChatCoreOptions, w as ChatNotify, x as ChatStreamHandle, y as ClarificationRecord, z as CustomBlock, F as FetchMessagesPageOptions, D as FormBlock, J as FormFieldItem, K as FormFieldType, L as GenerateBodyRequest, N as GenerateBodyResult, Q as HitlActionRequest, U as HitlDecision, V as HitlDecisionType, W as HitlInterruptPayload, X as HitlReviewConfig, Y as IAttachment, Z as IPageReference, _ as IQuote, $ as InlineCitation, a0 as InterruptReviewBlock, a1 as ItemSegment, a2 as ListBlock, a3 as ListItem, a4 as Message, a5 as MessageMetadata, a6 as MessageRole, a7 as MessageSource, a8 as MessageStatus, a9 as PendingRun, aa as ReportAttachment, ab as ReportGenerateBodyHumanKwargs, ac as ReportSelectedArtifact, ad as ReportSelectedTemplate, ae as RunInputKind, af as RunMeta, ag as RunTokens, ah as SearchThreadsOptions, ai as SendMessageOptions, aj as TextBlock, ak as ThreadDirectory, al as ThreadDirectoryOptions, am as ThreadRuntime, an as ThreadRuntimeOptions, ao as ThreadsPagination, ap as ToolRun, aq as XmlAttrs, ar as buildHitlDecisions, as as buildInterruptReviewBlock, at as buildRejectDecisions, au as buildRunDirectLatencyMs, av as buildRunInfo, aw as buildRunMeta, ax as createChatCore, ay as createThreadRuntime, az as getAllowedDecisions, aA as isSameArgs, aB as normalizeForCompare, aC as parseHitlPayload, aD as pickRunMessageMetadata, aE as sliceBodySegments } from './ChatCore-DkvD2GqL.js';
|
|
3
3
|
import { Message, Interrupt } from '@langchain/langgraph-sdk';
|
|
4
4
|
import 'vue';
|
|
5
5
|
|
|
@@ -544,11 +544,15 @@ declare function mapBackendStatus(raw: string): RunStatus;
|
|
|
544
544
|
* - `__user` 后缀行语义按数据源区分:**page 行是后端 run-event 投影的触发输入本体**
|
|
545
545
|
* (实测每轮窗口的 human 行均为该形态,无无后缀原行——剔除会让 input 窗口兜底全部
|
|
546
546
|
* 落空),放行参与归组;live 行仍剔除(state 侧回放镜像,原行已在 page);
|
|
547
|
+
* - live tool 行 tool_call_id 命中 page 已登记调用 → 剔除(resume 流历史回放:
|
|
548
|
+
* 后端以新 id 回放前轮 tool 结果行,进活跃桶无 ai 载体可关联,只污染 rawMessages);
|
|
547
549
|
* - live 行在 activeRunId 为空时挂到 pendingRun.runId(metadata 未到的乐观窗口),
|
|
548
550
|
* 两者都缺则丢弃(无归属的孤儿行不渲染)。
|
|
549
551
|
*/
|
|
550
552
|
|
|
551
|
-
/**
|
|
553
|
+
/** 消息定位 id 提取:顶层 id 优先;tool 行 id 可能为 null(实测 page 的
|
|
554
|
+
* llm.tool.result 行),回退 tool_call_id 作为装配行键(callId 每次调用唯一);
|
|
555
|
+
* 两者皆空的行无法参与去重,直接丢弃 */
|
|
552
556
|
declare function rowMessageId(msg: Message): string;
|
|
553
557
|
/** `__user` 后缀重放行判定(resume run 窗口回放上一轮 human 的事件信封形态) */
|
|
554
558
|
declare function isUserEchoRow(id: string): boolean;
|
package/dist/index.mjs
CHANGED
package/dist/vue/index.cjs
CHANGED
|
@@ -802,7 +802,8 @@ function createStreamActions(ctx) {
|
|
|
802
802
|
if (!handle) return;
|
|
803
803
|
ctx.beginStream();
|
|
804
804
|
const kwargs = submitOptions?.kwargs ?? void 0;
|
|
805
|
-
|
|
805
|
+
const kind = kwargs?.human_input_response ? "clarification" : "message";
|
|
806
|
+
ctx.createPendingRun(text, kind, kwargs);
|
|
806
807
|
const humanMessage = { type: "human", content: [{ type: "text", text }] };
|
|
807
808
|
humanMessage.additional_kwargs = submitOptions?.kwargs;
|
|
808
809
|
handle.submit({ messages: [humanMessage] }, { onDisconnect: "continue", config: { recursion_limit: 1e3 } });
|
|
@@ -844,6 +845,10 @@ function createStreamActions(ctx) {
|
|
|
844
845
|
|
|
845
846
|
// src/runtime/rows-store.ts
|
|
846
847
|
var import_vue2 = require("vue");
|
|
848
|
+
function rowKey(content) {
|
|
849
|
+
const c = content;
|
|
850
|
+
return String(c?.id || c?.tool_call_id || "").trim();
|
|
851
|
+
}
|
|
847
852
|
function createRowsStore() {
|
|
848
853
|
const rows = (0, import_vue2.shallowRef)([]);
|
|
849
854
|
const sortRows = (list) => [...list].sort((a, b) => a.seq - b.seq);
|
|
@@ -854,11 +859,11 @@ function createRowsStore() {
|
|
|
854
859
|
},
|
|
855
860
|
prepend(older) {
|
|
856
861
|
if (!older.length) return;
|
|
857
|
-
const seen = new Set(rows.value.map((r) =>
|
|
862
|
+
const seen = new Set(rows.value.map((r) => rowKey(r.content)));
|
|
858
863
|
const fresh = older.filter((r) => {
|
|
859
|
-
const
|
|
860
|
-
if (!
|
|
861
|
-
seen.add(
|
|
864
|
+
const key = rowKey(r.content);
|
|
865
|
+
if (!key || seen.has(key)) return false;
|
|
866
|
+
seen.add(key);
|
|
862
867
|
return true;
|
|
863
868
|
});
|
|
864
869
|
if (!fresh.length) return;
|
|
@@ -866,13 +871,13 @@ function createRowsStore() {
|
|
|
866
871
|
},
|
|
867
872
|
mergeLatest(latest) {
|
|
868
873
|
if (!latest.length) return;
|
|
869
|
-
const
|
|
874
|
+
const byKey = new Map(rows.value.map((r) => [rowKey(r.content), r]));
|
|
870
875
|
for (const row of latest) {
|
|
871
|
-
const
|
|
872
|
-
if (!
|
|
873
|
-
|
|
876
|
+
const key = rowKey(row.content);
|
|
877
|
+
if (!key) continue;
|
|
878
|
+
byKey.set(key, row);
|
|
874
879
|
}
|
|
875
|
-
rows.value = sortRows([...
|
|
880
|
+
rows.value = sortRows([...byKey.values()]);
|
|
876
881
|
}
|
|
877
882
|
};
|
|
878
883
|
}
|
|
@@ -890,7 +895,8 @@ function extractLiveIncrement(snapshot, lastSeenIds) {
|
|
|
890
895
|
// src/assembler/run-grouping.ts
|
|
891
896
|
var LIVE_SEQ = Number.MAX_SAFE_INTEGER;
|
|
892
897
|
function rowMessageId(msg) {
|
|
893
|
-
|
|
898
|
+
const m = msg;
|
|
899
|
+
return String(m?.id || m?.tool_call_id || "").trim();
|
|
894
900
|
}
|
|
895
901
|
function isUserEchoRow(id) {
|
|
896
902
|
return id.endsWith("__user");
|
|
@@ -913,12 +919,23 @@ function liveToAsmRow(msg, runId) {
|
|
|
913
919
|
if (!id || isUserEchoRow(id)) return null;
|
|
914
920
|
return { id, runId, seq: LIVE_SEQ, msg };
|
|
915
921
|
}
|
|
922
|
+
function collectPageToolCallIds(msg, into) {
|
|
923
|
+
const m = msg;
|
|
924
|
+
const calls = Array.isArray(m?.tool_calls) ? m.tool_calls : m?.additional_kwargs?.tool_calls;
|
|
925
|
+
if (!Array.isArray(calls)) return;
|
|
926
|
+
for (const call of calls) {
|
|
927
|
+
const callId = String(call?.id || "").trim();
|
|
928
|
+
if (callId) into.add(callId);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
916
931
|
function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
917
932
|
const byId = /* @__PURE__ */ new Map();
|
|
918
933
|
const buckets = /* @__PURE__ */ new Map();
|
|
934
|
+
const pageToolCallIds = /* @__PURE__ */ new Set();
|
|
919
935
|
for (const row of rows) {
|
|
920
936
|
const asm = pageRowToAsmRow(row);
|
|
921
937
|
if (!asm) continue;
|
|
938
|
+
if (String(row.content?.type || "") === "ai") collectPageToolCallIds(row.content, pageToolCallIds);
|
|
922
939
|
const prev = byId.get(asm.id);
|
|
923
940
|
if (prev) {
|
|
924
941
|
if (asm.seq >= prev.seq) {
|
|
@@ -936,6 +953,9 @@ function groupRowsByRun(rows, liveMessages, activeRunId, pendingRunId) {
|
|
|
936
953
|
const asm = liveToAsmRow(msg, liveRunId);
|
|
937
954
|
if (!asm) continue;
|
|
938
955
|
if (byId.has(asm.id)) continue;
|
|
956
|
+
if (String(msg?.type || "") === "tool" && pageToolCallIds.has(String(msg?.tool_call_id || "").trim())) {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
939
959
|
pushToBucket(buckets, asm);
|
|
940
960
|
}
|
|
941
961
|
}
|
|
@@ -1374,6 +1394,14 @@ function projectRuns(input) {
|
|
|
1374
1394
|
runs.push(placeholder);
|
|
1375
1395
|
}
|
|
1376
1396
|
const answers = input.answers;
|
|
1397
|
+
const answerByCallId = /* @__PURE__ */ new Map();
|
|
1398
|
+
for (const meta of input.runsList) {
|
|
1399
|
+
const response = meta.inputMessages?.map((m) => m?.additional_kwargs?.human_input_response).find((r) => r && typeof r === "object");
|
|
1400
|
+
if (!response || typeof response !== "object") continue;
|
|
1401
|
+
const requestId = normalizeRequestId(response.request_id);
|
|
1402
|
+
if (!requestId) continue;
|
|
1403
|
+
answerByCallId.set(requestId, { answer: formatAnswerText(response.value), answerRunId: String(meta.runId || "") });
|
|
1404
|
+
}
|
|
1377
1405
|
for (let i = 0; i < runs.length; i++) {
|
|
1378
1406
|
const run = runs[i];
|
|
1379
1407
|
for (const record of run.clarifications) {
|
|
@@ -1383,6 +1411,12 @@ function projectRuns(input) {
|
|
|
1383
1411
|
record.answer = optimistic;
|
|
1384
1412
|
continue;
|
|
1385
1413
|
}
|
|
1414
|
+
const fromList = answerByCallId.get(normalizeRequestId(record.callId));
|
|
1415
|
+
if (fromList) {
|
|
1416
|
+
record.answer = fromList.answer;
|
|
1417
|
+
record.answerRunId = fromList.answerRunId;
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1386
1420
|
for (let j = i + 1; j < runs.length; j++) {
|
|
1387
1421
|
const laterKwargs = runs[j].input.kwargs;
|
|
1388
1422
|
const response = laterKwargs?.human_input_response;
|
|
@@ -1397,6 +1431,61 @@ function projectRuns(input) {
|
|
|
1397
1431
|
return runs;
|
|
1398
1432
|
}
|
|
1399
1433
|
|
|
1434
|
+
// src/assembler/stable-project-runs.ts
|
|
1435
|
+
var refSeq = 0;
|
|
1436
|
+
var refIds = /* @__PURE__ */ new WeakMap();
|
|
1437
|
+
function refId(value) {
|
|
1438
|
+
if (value === null || value === void 0) return "-";
|
|
1439
|
+
if (typeof value === "object") {
|
|
1440
|
+
let id = refIds.get(value);
|
|
1441
|
+
if (id === void 0) {
|
|
1442
|
+
id = ++refSeq;
|
|
1443
|
+
refIds.set(value, id);
|
|
1444
|
+
}
|
|
1445
|
+
return String(id);
|
|
1446
|
+
}
|
|
1447
|
+
return String(value);
|
|
1448
|
+
}
|
|
1449
|
+
function runFingerprint(run) {
|
|
1450
|
+
let fp = `${run.status}|${run.input.kind}|${run.input.text}`;
|
|
1451
|
+
if (run.createdAt !== void 0) fp += `|c${run.createdAt}`;
|
|
1452
|
+
if (run.tokens !== void 0) fp += `|t${JSON.stringify(run.tokens)}`;
|
|
1453
|
+
const stopReason = run.stopReason;
|
|
1454
|
+
if (stopReason !== void 0) fp += `|s${String(stopReason)}`;
|
|
1455
|
+
for (const row of run.rawMessages) {
|
|
1456
|
+
fp += `|${row.seq}:${refId(row.msg)}:${refId(row.feedback ?? null)}`;
|
|
1457
|
+
}
|
|
1458
|
+
return fp;
|
|
1459
|
+
}
|
|
1460
|
+
function globalSignal(input, next) {
|
|
1461
|
+
const runIds = next.map((r) => r.runId).join(",");
|
|
1462
|
+
const runsListRef = input.runsList.length ? refId(input.runsList) : "empty";
|
|
1463
|
+
const answersRef = input.answers && input.answers.size ? refId(input.answers) : "empty";
|
|
1464
|
+
return `${runIds}#${runsListRef}#${answersRef}`;
|
|
1465
|
+
}
|
|
1466
|
+
function createStableRunsProjector() {
|
|
1467
|
+
let cache = /* @__PURE__ */ new Map();
|
|
1468
|
+
let lastGlobal = "";
|
|
1469
|
+
return function projectRunsStable(input) {
|
|
1470
|
+
const next = projectRuns(input);
|
|
1471
|
+
const signal = globalSignal(input, next);
|
|
1472
|
+
if (signal !== lastGlobal) {
|
|
1473
|
+
lastGlobal = signal;
|
|
1474
|
+
cache = /* @__PURE__ */ new Map();
|
|
1475
|
+
}
|
|
1476
|
+
const activeId = input.streaming ? input.activeRunId : null;
|
|
1477
|
+
const pendingId = input.pendingRun?.runId ?? null;
|
|
1478
|
+
return next.map((run) => {
|
|
1479
|
+
if (run.runId === activeId || run.runId === pendingId) return run;
|
|
1480
|
+
const fingerprint = runFingerprint(run);
|
|
1481
|
+
const hit = cache.get(run.runId);
|
|
1482
|
+
if (hit && hit.fingerprint === fingerprint) return hit.item;
|
|
1483
|
+
cache.set(run.runId, { fingerprint, item: run });
|
|
1484
|
+
return run;
|
|
1485
|
+
});
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1400
1489
|
// src/runtime/values-projection.ts
|
|
1401
1490
|
function createValuesChannel(options = {}) {
|
|
1402
1491
|
let latestStreamMessages = [];
|
|
@@ -1559,8 +1648,9 @@ function createThreadRuntime(options) {
|
|
|
1559
1648
|
const pendingRun = (0, import_vue4.shallowRef)(null);
|
|
1560
1649
|
const answers = (0, import_vue4.shallowRef)(/* @__PURE__ */ new Map());
|
|
1561
1650
|
const activeRunId = (0, import_vue4.computed)(() => runs.currentRunId.value);
|
|
1651
|
+
const projectRunsStable = createStableRunsProjector();
|
|
1562
1652
|
const runsProjection = (0, import_vue4.computed)(
|
|
1563
|
-
() =>
|
|
1653
|
+
() => projectRunsStable({
|
|
1564
1654
|
rows: rowsStore.rows.value,
|
|
1565
1655
|
liveMessages: liveMessages.value,
|
|
1566
1656
|
activeRunId: activeRunId.value,
|
|
@@ -1615,13 +1705,26 @@ function createThreadRuntime(options) {
|
|
|
1615
1705
|
};
|
|
1616
1706
|
const applyLiveSnapshot = (messages) => {
|
|
1617
1707
|
if (!streaming.value) return;
|
|
1618
|
-
const
|
|
1619
|
-
const
|
|
1708
|
+
const snapshot = messages;
|
|
1709
|
+
const latestById = /* @__PURE__ */ new Map();
|
|
1710
|
+
for (const m of snapshot) {
|
|
1711
|
+
const id = String(m?.id || "").trim();
|
|
1712
|
+
if (id) latestById.set(id, m);
|
|
1713
|
+
}
|
|
1714
|
+
let changed = false;
|
|
1715
|
+
const refreshed = liveMessages.value.map((m) => {
|
|
1716
|
+
const id = String(m?.id || "").trim();
|
|
1717
|
+
const latest = id ? latestById.get(id) : void 0;
|
|
1718
|
+
if (!latest || latest === m) return m;
|
|
1719
|
+
changed = true;
|
|
1720
|
+
return latest;
|
|
1721
|
+
});
|
|
1722
|
+
const eligible = extractLiveIncrement(snapshot, lastSeenLiveIds).filter((m) => {
|
|
1620
1723
|
const t = String(m?.type || "");
|
|
1621
1724
|
return t === "ai" || t === "tool";
|
|
1622
1725
|
});
|
|
1623
|
-
if (!eligible.length) return;
|
|
1624
|
-
liveMessages.value = [...
|
|
1726
|
+
if (!changed && !eligible.length) return;
|
|
1727
|
+
liveMessages.value = eligible.length ? [...refreshed, ...eligible] : refreshed;
|
|
1625
1728
|
};
|
|
1626
1729
|
const refreshTokenUsage = async () => {
|
|
1627
1730
|
try {
|
package/dist/vue/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { v as ChatCoreOptions, u as ChatCore } from '../ChatCore-
|
|
2
|
-
export {
|
|
1
|
+
import { v as ChatCoreOptions, u as ChatCore } from '../ChatCore-DkvD2GqL.cjs';
|
|
2
|
+
export { ax as createChatCore } from '../ChatCore-DkvD2GqL.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 { v as ChatCoreOptions, u as ChatCore } from '../ChatCore-
|
|
2
|
-
export {
|
|
1
|
+
import { v as ChatCoreOptions, u as ChatCore } from '../ChatCore-DkvD2GqL.js';
|
|
2
|
+
export { ax as createChatCore } from '../ChatCore-DkvD2GqL.js';
|
|
3
3
|
import 'vue';
|
|
4
4
|
import '@langchain/langgraph-sdk';
|
|
5
5
|
|
package/dist/vue/index.mjs
CHANGED