@agentvault/agentvault 0.23.3 → 0.23.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.
@@ -18,9 +18,24 @@ declare function _parseMentions(text: string): string[];
18
18
  * with 2min cooldown), so we no longer gate on senderIsAgent. All messages
19
19
  * are processed unless they @mention a *different* agent specifically.
20
20
  */
21
- declare function _shouldProcessRoomMessage(plaintext: string, agentName: string, accountId: string, senderIsAgent?: boolean, roomDisplayName?: string): boolean;
21
+ declare function _shouldProcessRoomMessage(plaintext: string, agentName: string, accountId: string, senderIsAgent?: boolean, roomDisplayName?: string, ownDisplayName?: string, selfResolved?: boolean): boolean;
22
22
  /** Strip the matching @mention prefix from plaintext so the agent sees clean text. */
23
- declare function _stripMentions(text: string, agentName: string, accountId: string, roomDisplayName?: string): string;
23
+ declare function _stripMentions(text: string, agentName: string, accountId: string, roomDisplayName?: string, ownDisplayName?: string): string;
24
+ /** Strip <think>…</think> reasoning blocks (and bare "think" lines) from model
25
+ * output, returning the trimmed remainder. Used to RECOVER a real answer from a
26
+ * turn whose blocks were all filtered as reasoning (regression 2026-07-08): a
27
+ * reasoning-heavy model (deepseek) can emit `<think>…</think>answer` as one block
28
+ * that the reply filter drops wholesale because it STARTS with `<think`, so the
29
+ * room got silence. Returns "" when nothing substantive remains (genuinely no
30
+ * answer — surface a warning rather than post noise). */
31
+ declare function _stripThinkBlocks(text: string): string;
32
+ /** True when a block looks like leaked chain-of-thought or an OpenClaw directive
33
+ * rather than a real reply: a "Reasoning:/Thinking:/Let me…/I need to/Let me
34
+ * check:" preamble, a <think> XML block or bare "think" line, or a [[directive]]
35
+ * tag. Single source of truth used BOTH to filter reply blocks AND to gate the
36
+ * Fix-B recovery stash — so a recovered fallback can never itself be raw reasoning
37
+ * noise, and the two checks can never drift (code-review 2026-07-08). */
38
+ declare function _looksLikeReasoningLeak(text: string): boolean;
24
39
  /** Resolve this agent's AgentVault room display_name (its own roster entry) +
25
40
  * build the compact identity+roster preamble surfaced to the LLM, so the agent
26
41
  * knows who it is in the room and who else is present (BUG-20260604-002).
@@ -92,6 +107,8 @@ declare function _buildRoomSenderId(roomId: string, senderDeviceId?: string, sen
92
107
  * `accountId` is intentionally unused for the room form; kept in the signature
93
108
  * for symmetry with the direct/A2A `To` shapes. */
94
109
  declare function _buildRoomTo(roomId: string, _accountId: string): string;
110
+ declare function _withSessionSerial<T>(key: string, fn: () => Promise<T>): Promise<T>;
111
+ declare function _withTurnTimeout<T>(ms: number, fn: () => Promise<T>): Promise<T>;
95
112
  /** Emit the full hierarchical span tree for a message lifecycle. */
96
113
  declare function _emitHierarchicalSpans(channel: any, opts: {
97
114
  traceId: string;
@@ -113,7 +130,7 @@ declare function _emitHierarchicalSpans(channel: any, opts: {
113
130
  status: "ok" | "error";
114
131
  statusMessage?: string;
115
132
  }): void;
116
- export { _parseMentions, _shouldProcessRoomMessage, _stripMentions, _emitHierarchicalSpans, _resolveRoomIdentity, _buildRoomSenderId, _buildRoomTo };
133
+ export { _parseMentions, _shouldProcessRoomMessage, _stripMentions, _stripThinkBlocks, _looksLikeReasoningLeak, _emitHierarchicalSpans, _resolveRoomIdentity, _buildRoomSenderId, _buildRoomTo, _withSessionSerial, _withTurnTimeout };
117
134
  declare const _default: {
118
135
  id: string;
119
136
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"openclaw-entry.d.ts","sourceRoot":"","sources":["../src/openclaw-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,KAAK,EACV,iBAAiB,EASlB,MAAM,qBAAqB,CAAC;AA4D7B,gFAAgF;AAChF,eAAO,IAAI,oBAAoB,SAAQ,CAAC;AA0FxC,uEAAuE;AACvE,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAS9C;AAED;;;;;GAKG;AACH,iBAAS,yBAAyB,CAChC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,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,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAY5E;AAUD,iBAAS,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAezE;AAuqBD,oEAAoE;AACpE,iBAAS,sBAAsB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxF,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,IAAI,CA8DP;AAogBD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,cAAc,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;;;;;kBAQvN,iBAAiB;;AAJjC,wBA0ZE"}
@@ -49616,15 +49616,16 @@ function _parseMentions(text) {
49616
49616
  }
49617
49617
  return mentions;
49618
49618
  }
49619
- function _shouldProcessRoomMessage(plaintext, agentName, accountId, senderIsAgent, roomDisplayName) {
49619
+ function _shouldProcessRoomMessage(plaintext, agentName, accountId, senderIsAgent, roomDisplayName, ownDisplayName, selfResolved = true) {
49620
49620
  const mentions = _parseMentions(plaintext);
49621
49621
  if (mentions.length === 0) return true;
49622
49622
  if (mentions.includes("all") || mentions.includes("everyone")) return true;
49623
- const ownNames = _ownRoomNames(agentName, accountId, roomDisplayName);
49623
+ const ownNames = _ownRoomNames(agentName, accountId, roomDisplayName, ownDisplayName);
49624
49624
  if (mentions.some((m2) => ownNames.has(m2))) return true;
49625
+ if (!selfResolved) return true;
49625
49626
  return false;
49626
49627
  }
49627
- function _ownRoomNames(agentName, accountId, roomDisplayName) {
49628
+ function _ownRoomNames(agentName, accountId, roomDisplayName, ownDisplayName) {
49628
49629
  const names = /* @__PURE__ */ new Set();
49629
49630
  const add2 = (n2) => {
49630
49631
  if (!n2) return;
@@ -49635,10 +49636,11 @@ function _ownRoomNames(agentName, accountId, roomDisplayName) {
49635
49636
  add2(agentName);
49636
49637
  add2(accountId);
49637
49638
  add2(roomDisplayName);
49639
+ add2(ownDisplayName);
49638
49640
  return names;
49639
49641
  }
49640
- function _stripMentions(text, agentName, accountId, roomDisplayName) {
49641
- const ownNames = _ownRoomNames(agentName, accountId, roomDisplayName);
49642
+ function _stripMentions(text, agentName, accountId, roomDisplayName, ownDisplayName) {
49643
+ const ownNames = _ownRoomNames(agentName, accountId, roomDisplayName, ownDisplayName);
49642
49644
  return text.replace(/@(\w[\w]*)/gi, (full, name) => {
49643
49645
  const lower = name.toLowerCase();
49644
49646
  if (ownNames.has(lower)) {
@@ -49648,6 +49650,12 @@ function _stripMentions(text, agentName, accountId, roomDisplayName) {
49648
49650
  return full;
49649
49651
  }).replace(/^\s+/, "").trim();
49650
49652
  }
49653
+ function _stripThinkBlocks(text) {
49654
+ return (text ?? "").replace(/<think>[\s\S]*?<\/think>/gi, " ").replace(/^\s*think\s*$/gim, " ").trim();
49655
+ }
49656
+ function _looksLikeReasoningLeak(text) {
49657
+ return /^(Reasoning|Thinking|Let me think|I need to|Let me check):/i.test(text) || /^<think[\s>]/i.test(text) || /^think$/im.test(text) || /^\[\[[\w_]+\]\]/.test(text) || /^<think>[\s\S]*<\/think>$/i.test(text);
49658
+ }
49651
49659
  function _resolveRoomIdentity(channel, roomId, fallbackName) {
49652
49660
  const fallback = { selfName: fallbackName, preamble: "" };
49653
49661
  if (!roomId) return fallback;
@@ -49740,17 +49748,61 @@ async function _recallTeamMemory(query, limit = 5) {
49740
49748
  return "";
49741
49749
  }
49742
49750
  }
49751
+ var _sessionQueues = /* @__PURE__ */ new Map();
49752
+ function _withSessionSerial(key, fn) {
49753
+ const prev = _sessionQueues.get(key) ?? Promise.resolve();
49754
+ const run = prev.then(fn, fn);
49755
+ const tail = run.catch(() => {
49756
+ });
49757
+ _sessionQueues.set(key, tail);
49758
+ void tail.then(() => {
49759
+ if (_sessionQueues.get(key) === tail) _sessionQueues.delete(key);
49760
+ });
49761
+ return run;
49762
+ }
49763
+ var TURN_BUDGET_MS = 12e4;
49764
+ function _withTurnTimeout(ms, fn) {
49765
+ return new Promise((resolve2, reject) => {
49766
+ let settled = false;
49767
+ const timer = setTimeout(() => {
49768
+ if (settled) return;
49769
+ settled = true;
49770
+ reject(new Error(`turn exceeded ${ms}ms budget \u2014 releasing session lock`));
49771
+ }, ms);
49772
+ fn().then(
49773
+ (v2) => {
49774
+ if (!settled) {
49775
+ settled = true;
49776
+ clearTimeout(timer);
49777
+ resolve2(v2);
49778
+ }
49779
+ },
49780
+ // If we already timed out, swallow the late rejection here so the orphaned
49781
+ // turn never becomes an unhandled rejection.
49782
+ (e) => {
49783
+ if (!settled) {
49784
+ settled = true;
49785
+ clearTimeout(timer);
49786
+ reject(e);
49787
+ }
49788
+ }
49789
+ );
49790
+ });
49791
+ }
49743
49792
  async function handleInbound(params) {
49744
49793
  const { plaintext: rawPlaintext, metadata, channel, account, cfg } = params;
49745
49794
  const isRoomMessage = Boolean(metadata.roomId);
49746
49795
  const isA2AMessage = Boolean(metadata.a2aChannelId);
49747
49796
  const roomIdentity = isRoomMessage ? _resolveRoomIdentity(channel, metadata.roomId, account.agentName ?? "") : { selfName: account.agentName ?? "", preamble: "" };
49797
+ const ownDisplayName = channel.ownDisplayName ?? "";
49798
+ const genericAgentName = !account.agentName || account.agentName.toLowerCase() === "default";
49799
+ const selfResolved = !!ownDisplayName || !!roomIdentity.selfName && roomIdentity.selfName !== (account.agentName ?? "") || !genericAgentName;
49748
49800
  if (isRoomMessage) {
49749
- if (!_shouldProcessRoomMessage(rawPlaintext, account.agentName ?? "", account.accountId ?? "", metadata.senderIsAgent, roomIdentity.selfName)) {
49801
+ if (!_shouldProcessRoomMessage(rawPlaintext, account.agentName ?? "", account.accountId ?? "", metadata.senderIsAgent, roomIdentity.selfName, ownDisplayName, selfResolved)) {
49750
49802
  return;
49751
49803
  }
49752
49804
  }
49753
- let plaintext = isRoomMessage ? _stripMentions(rawPlaintext, account.agentName ?? "", account.accountId ?? "", roomIdentity.selfName) : rawPlaintext;
49805
+ let plaintext = isRoomMessage ? _stripMentions(rawPlaintext, account.agentName ?? "", account.accountId ?? "", roomIdentity.selfName, ownDisplayName) : rawPlaintext;
49754
49806
  if (isRoomMessage || isA2AMessage) {
49755
49807
  try {
49756
49808
  const woke = await requestHeartbeatNow({ reason: `AgentVault ${isRoomMessage ? "room" : "A2A"} message received` });
@@ -49915,6 +49967,7 @@ async function handleInbound(params) {
49915
49967
  let totalReplyChars = 0;
49916
49968
  let firstReplyTime = null;
49917
49969
  const replySpans = [];
49970
+ let lastFilteredText = "";
49918
49971
  _emitChildSpan(channel, {
49919
49972
  traceId,
49920
49973
  parentSpanId: rootSpanId,
@@ -50080,118 +50133,146 @@ ${contextBody}`;
50080
50133
  ...attachmentFields,
50081
50134
  ...credentialFields
50082
50135
  });
50083
- await core.channel.session.recordInboundSession({
50084
- storePath,
50085
- sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
50086
- ctx: ctxPayload,
50087
- onRecordError: (err) => {
50088
- core.error?.(`[AgentVault] session record failed: ${String(err)}`);
50089
- }
50090
- });
50091
- try {
50092
- await runWithTraceContext(
50093
- { traceId, parentSpanId: inferenceSpanId },
50094
- () => core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
50095
- ctx: ctxPayload,
50096
- cfg,
50097
- dispatcherOptions: {
50098
- deliver: async (payload) => {
50099
- if (payload.kind === "thinking" || payload.kind === "reasoning") return;
50100
- const text = (payload.text ?? "").trim();
50101
- if (!text) return;
50102
- if (/^(Reasoning|Thinking|Let me think|I need to|Let me check):/i.test(text)) return;
50103
- if (/^<think[\s>]/i.test(text) || /^think$/im.test(text)) return;
50104
- if (/^\[\[[\w_]+\]\]/.test(text)) return;
50105
- if (/^<think>[\s\S]*<\/think>$/i.test(text)) return;
50106
- const replyStart = Date.now();
50107
- replyCount++;
50108
- totalReplyChars += text.length;
50109
- if (!firstReplyTime) firstReplyTime = replyStart;
50110
- let replyTarget;
50111
- if (isA2AMessage) {
50112
- if (!_a2aCanReply(metadata.a2aChannelId)) {
50113
- console.warn(`[AgentVault] A2A reply suppressed (rate limit) for channel ${metadata.a2aChannelId?.slice(0, 8)}...`);
50114
- return;
50136
+ const _turnSessionKey = typeof route.sessionKey === "string" && route.sessionKey ? route.sessionKey : `__unkeyed__:${traceId}`;
50137
+ await _withSessionSerial(_turnSessionKey, () => _withTurnTimeout(TURN_BUDGET_MS, async () => {
50138
+ await core.channel.session.recordInboundSession({
50139
+ storePath,
50140
+ sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
50141
+ ctx: ctxPayload,
50142
+ onRecordError: (err) => {
50143
+ core.error?.(`[AgentVault] session record failed: ${String(err)}`);
50144
+ }
50145
+ });
50146
+ try {
50147
+ await runWithTraceContext(
50148
+ { traceId, parentSpanId: inferenceSpanId },
50149
+ () => core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
50150
+ ctx: ctxPayload,
50151
+ cfg,
50152
+ dispatcherOptions: {
50153
+ deliver: async (payload) => {
50154
+ if (payload.kind === "thinking" || payload.kind === "reasoning") return;
50155
+ const text = (payload.text ?? "").trim();
50156
+ if (!text) return;
50157
+ {
50158
+ const recoverable = _stripThinkBlocks(text);
50159
+ if (recoverable && !_looksLikeReasoningLeak(recoverable)) lastFilteredText = recoverable;
50115
50160
  }
50116
- replyTarget = { kind: "a2a", hubAddress: metadata.fromHubAddress };
50117
- } else if (isRoomMessage) {
50118
- if (!_roomCanReply(metadata.roomId)) {
50119
- console.warn(`[AgentVault] Room reply suppressed (rate limit) for room ${metadata.roomId?.slice(0, 8)}...`);
50120
- return;
50161
+ if (_looksLikeReasoningLeak(text)) return;
50162
+ const replyStart = Date.now();
50163
+ replyCount++;
50164
+ totalReplyChars += text.length;
50165
+ if (!firstReplyTime) firstReplyTime = replyStart;
50166
+ let replyTarget;
50167
+ if (isA2AMessage) {
50168
+ if (!_a2aCanReply(metadata.a2aChannelId)) {
50169
+ console.warn(`[AgentVault] A2A reply suppressed (rate limit) for channel ${metadata.a2aChannelId?.slice(0, 8)}...`);
50170
+ return;
50171
+ }
50172
+ replyTarget = { kind: "a2a", hubAddress: metadata.fromHubAddress };
50173
+ } else if (isRoomMessage) {
50174
+ if (!_roomCanReply(metadata.roomId)) {
50175
+ console.warn(`[AgentVault] Room reply suppressed (rate limit) for room ${metadata.roomId?.slice(0, 8)}...`);
50176
+ return;
50177
+ }
50178
+ replyTarget = { kind: "room", roomId: metadata.roomId };
50179
+ } else {
50180
+ replyTarget = { kind: "owner" };
50121
50181
  }
50122
- replyTarget = { kind: "room", roomId: metadata.roomId };
50123
- } else {
50124
- replyTarget = { kind: "owner" };
50125
- }
50126
- await channel.deliver(replyTarget, { type: "text", text }, {
50127
- conversationId: metadata.conversationId,
50128
- topicId: metadata.topicId,
50129
- parentSpanId: inferenceSpanId,
50130
- metadata: isRoomMessage ? { content_length: text.length } : void 0
50131
- });
50132
- if (isA2AMessage) {
50133
- _a2aRecordReply(metadata.a2aChannelId);
50134
- }
50135
- if (isRoomMessage) {
50136
- _roomRecordReply(metadata.roomId);
50182
+ await channel.deliver(replyTarget, { type: "text", text }, {
50183
+ conversationId: metadata.conversationId,
50184
+ topicId: metadata.topicId,
50185
+ parentSpanId: inferenceSpanId,
50186
+ metadata: isRoomMessage ? { content_length: text.length } : void 0
50187
+ });
50188
+ if (isA2AMessage) {
50189
+ _a2aRecordReply(metadata.a2aChannelId);
50190
+ }
50191
+ if (isRoomMessage) {
50192
+ _roomRecordReply(metadata.roomId);
50193
+ }
50194
+ const replyEnd = Date.now();
50195
+ replySpans.push({ startTime: replyStart, endTime: replyEnd, chars: text.length, index: replyCount });
50196
+ },
50197
+ onError: (err, info) => {
50198
+ core.error?.(`[AgentVault] ${info?.kind ?? "reply"} error: ${String(err)}`);
50137
50199
  }
50138
- const replyEnd = Date.now();
50139
- replySpans.push({ startTime: replyStart, endTime: replyEnd, chars: text.length, index: replyCount });
50140
50200
  },
50141
- onError: (err, info) => {
50142
- core.error?.(`[AgentVault] ${info?.kind ?? "reply"} error: ${String(err)}`);
50143
- }
50201
+ replyOptions: {}
50202
+ })
50203
+ );
50204
+ if (replyCount === 0 && lastFilteredText) {
50205
+ const canReply = isA2AMessage ? _a2aCanReply(metadata.a2aChannelId) : isRoomMessage ? _roomCanReply(metadata.roomId) : true;
50206
+ if (canReply) {
50207
+ const replyTarget = isA2AMessage ? { kind: "a2a", hubAddress: metadata.fromHubAddress } : isRoomMessage ? { kind: "room", roomId: metadata.roomId } : { kind: "owner" };
50208
+ console.warn(
50209
+ `[AgentVault] all reply blocks filtered as reasoning \u2014 delivering recovered fallback (${lastFilteredText.length} chars)`
50210
+ );
50211
+ await channel.deliver(replyTarget, { type: "text", text: lastFilteredText }, {
50212
+ conversationId: metadata.conversationId,
50213
+ topicId: metadata.topicId,
50214
+ parentSpanId: inferenceSpanId,
50215
+ metadata: isRoomMessage ? { content_length: lastFilteredText.length } : void 0
50216
+ });
50217
+ replyCount++;
50218
+ totalReplyChars += lastFilteredText.length;
50219
+ if (!firstReplyTime) firstReplyTime = Date.now();
50220
+ if (isA2AMessage) _a2aRecordReply(metadata.a2aChannelId);
50221
+ else if (isRoomMessage) _roomRecordReply(metadata.roomId);
50222
+ } else {
50223
+ console.warn("[AgentVault] reply blocks all filtered AND rate-limited \u2014 no fallback delivered");
50224
+ }
50225
+ } else if (replyCount === 0) {
50226
+ console.warn("[AgentVault] turn produced no deliverable reply (all blocks empty/filtered, nothing recoverable)");
50227
+ }
50228
+ const endTime = Date.now();
50229
+ _emitHierarchicalSpans(channel, {
50230
+ traceId,
50231
+ rootSpanId,
50232
+ inferenceSpanId,
50233
+ startTime,
50234
+ endTime,
50235
+ firstReplyTime,
50236
+ replySpans,
50237
+ inputChars: plaintext.length,
50238
+ replyCount,
50239
+ totalReplyChars,
50240
+ isRoom: isRoomMessage,
50241
+ status: "ok"
50242
+ });
50243
+ } catch (err) {
50244
+ const endTime = Date.now();
50245
+ _emitHierarchicalSpans(channel, {
50246
+ traceId,
50247
+ rootSpanId,
50248
+ inferenceSpanId,
50249
+ startTime,
50250
+ endTime,
50251
+ firstReplyTime,
50252
+ replySpans,
50253
+ inputChars: plaintext.length,
50254
+ replyCount,
50255
+ totalReplyChars,
50256
+ isRoom: isRoomMessage,
50257
+ status: "error",
50258
+ statusMessage: String(err)
50259
+ });
50260
+ _emitChildSpan(channel, {
50261
+ traceId,
50262
+ parentSpanId: rootSpanId,
50263
+ name: "error",
50264
+ startTime: endTime,
50265
+ endTime,
50266
+ attributes: {
50267
+ "ai.agent.error.type": err?.constructor?.name ?? "Error",
50268
+ "ai.agent.error.message": String(err)
50144
50269
  },
50145
- replyOptions: {}
50146
- })
50147
- );
50148
- const endTime = Date.now();
50149
- _emitHierarchicalSpans(channel, {
50150
- traceId,
50151
- rootSpanId,
50152
- inferenceSpanId,
50153
- startTime,
50154
- endTime,
50155
- firstReplyTime,
50156
- replySpans,
50157
- inputChars: plaintext.length,
50158
- replyCount,
50159
- totalReplyChars,
50160
- isRoom: isRoomMessage,
50161
- status: "ok"
50162
- });
50163
- } catch (err) {
50164
- const endTime = Date.now();
50165
- _emitHierarchicalSpans(channel, {
50166
- traceId,
50167
- rootSpanId,
50168
- inferenceSpanId,
50169
- startTime,
50170
- endTime,
50171
- firstReplyTime,
50172
- replySpans,
50173
- inputChars: plaintext.length,
50174
- replyCount,
50175
- totalReplyChars,
50176
- isRoom: isRoomMessage,
50177
- status: "error",
50178
- statusMessage: String(err)
50179
- });
50180
- _emitChildSpan(channel, {
50181
- traceId,
50182
- parentSpanId: rootSpanId,
50183
- name: "error",
50184
- startTime: endTime,
50185
- endTime,
50186
- attributes: {
50187
- "ai.agent.error.type": err?.constructor?.name ?? "Error",
50188
- "ai.agent.error.message": String(err)
50189
- },
50190
- status: "error",
50191
- statusMessage: String(err)
50192
- });
50193
- throw err;
50194
- }
50270
+ status: "error",
50271
+ statusMessage: String(err)
50272
+ });
50273
+ throw err;
50274
+ }
50275
+ }));
50195
50276
  }
50196
50277
  function _inferSpanType(name) {
50197
50278
  if (name === "error" || name.includes("error")) return "error";
@@ -51107,11 +51188,15 @@ export {
51107
51188
  _buildRoomSenderId,
51108
51189
  _buildRoomTo,
51109
51190
  _emitHierarchicalSpans,
51191
+ _looksLikeReasoningLeak,
51110
51192
  _parseMentions,
51111
51193
  _resolveRoomIdentity,
51112
51194
  _selectInboundPreamble,
51113
51195
  _shouldProcessRoomMessage,
51114
51196
  _stripMentions,
51197
+ _stripThinkBlocks,
51198
+ _withSessionSerial,
51199
+ _withTurnTimeout,
51115
51200
  openclaw_entry_default as default,
51116
51201
  isUsingManagedRoutes
51117
51202
  };