@yeaft/webchat-agent 1.0.527 → 1.0.528

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.
@@ -24,7 +24,7 @@
24
24
  * from every text_delta).
25
25
  *
26
26
  * Every envelope includes `outputFile` (durable per-agent JSONL log) and
27
- * `liveness` (toolUseCount, tokenCount, msSinceLastEvent, recentTools,
27
+ * `liveness` (toolUseCount, usageTokens, outputChars, msSinceLastEvent, recentTools,
28
28
  * lastEventType) so the model can distinguish "stuck" from "still
29
29
  * working" and can Read the log directly when it needs the full
30
30
  * timeline.
@@ -57,10 +57,10 @@ function nextStepsFor(status, opts = {}) {
57
57
  }
58
58
  if (opts.timedOut && opts.stale) {
59
59
  return (
60
- 'Sub-agent still has a running record but appears stalled. Do NOT keep ' +
61
- 'calling WaitAgent in a loop. Use ListAgents/outputFile to inspect it, ' +
62
- 'CloseAgent if you want to stop it, or report the stalled background ' +
63
- 'task and start a fresh agent if needed.'
60
+ 'No observable event arrived within the diagnostic threshold. This does ' +
61
+ 'not prove the provider or tool is dead. Do NOT keep calling WaitAgent ' +
62
+ 'in a blind loop; inspect outputFile, then use CloseAgent only if you ' +
63
+ 'actually intend to cancel, or report that the background task is quiet.'
64
64
  );
65
65
  }
66
66
  if (opts.timedOut && opts.mustCollectReply) {
@@ -197,7 +197,7 @@ export default defineTool({
197
197
  en: `Wait for a sub-agent's next state change (turn end, terminal, or wait-timeout) and retrieve a status envelope.
198
198
 
199
199
  Returns JSON with explicit \`status\`, latest \`result\` text, \`liveness\`
200
- counters (toolUseCount, tokenCount, msSinceLastEvent, recentTools), the
200
+ counters (actual toolUseCount, provider usageTokens, outputChars, msSinceLastEvent, recentTools), the
201
201
  durable \`outputFile\` path you can Read at any time, and a status-specific
202
202
  \`next_steps\` directive telling you what to call next.
203
203
 
@@ -214,16 +214,16 @@ Status semantics:
214
214
 
215
215
  After WaitAgent returns, act on the status. A non-stale timeout after PromptAgent
216
216
  has 'mustCollectReply=true': call WaitAgent again with a larger bounded timeout in
217
- the same parent turn until idle/terminal. A stale/stalled agent breaks that loop:
218
- inspect/report/close it instead. For ordinary SpawnAgent background work, use
219
- ListAgents or later completion notifications instead of repeatedly re-waiting.
217
+ the same parent turn until idle/terminal. A stale diagnostic breaks that blind
218
+ wait loop but does not cancel or prove failure: inspect outputFile before deciding.
219
+ For ordinary SpawnAgent background work, use ListAgents or later completion
220
+ notifications instead of repeatedly re-waiting.
220
221
 
221
222
  The default wait is a bounded 5000ms poll; callers may request up to 300000ms
222
- (5 minutes). Never use an unbounded blind loop: every wait is capped, liveness is
223
- checked after each timeout, and stale/stalled is the explicit stop condition.`,
223
+ (5 minutes). This caps one WaitAgent call only, not the sub-agent lifetime.`,
224
224
  zh: `等待子 Agent 的下一次状态变更(turn 结束、终止或等待超时)并获取状态信封。
225
225
 
226
- 返回 JSON,含明确的 status、最新的 result 文本、liveness 计数器(toolUseCount、tokenCount、
226
+ 返回 JSON,含明确的 status、最新的 result 文本、liveness 计数器(实际 toolUseCount、provider usageTokens、outputChars、
227
227
  msSinceLastEvent、recentTools)、可随时 Read 的持久化 outputFile 路径,以及状态相关的 next_steps
228
228
  指令告诉你下一步该调用什么。
229
229
 
@@ -237,11 +237,11 @@ msSinceLastEvent、recentTools)、可随时 Read 的持久化 outputFile 路
237
237
 
238
238
  PromptAgent 后若非 stale/stalled 的有界等待超时,必须在同一父级 turn 使用更大的有界 timeout
239
239
  再次调用 WaitAgent,直到 idle/terminal;不要改用 ListAgents/notification 丢下未收集的回复。
240
- 关键——如果信封显示 stale/stalled,子 Agent 可能卡死或空转。不要反复调用 WaitAgent——向用户
241
- 报告情况,决定是 CloseAgent(带 close_reason)还是重试。
240
+ 若信封显示 stale/stalled,应停止盲目等待并检查 outputFile;它只是诊断,不会取消任务,也不能证明
241
+ provider 或工具已经卡死。仅在确实要取消时使用 CloseAgent。
242
242
 
243
243
  普通 SpawnAgent 异步流程仍用 ListAgents 做非阻塞状态检查,并依赖后续 completion
244
- notification;不要对普通后台任务盲目循环等待。每次等待都有上限,stale/stalled 是停止条件。`
244
+ notification;默认 5000ms、最大 300000ms 仅限制单次 WaitAgent 调用,不限制子 Agent 生命周期。`
245
245
  },
246
246
  parameters: {
247
247
  type: 'object',
@@ -258,8 +258,8 @@ notification;不要对普通后台任务盲目循环等待。每次等待都
258
258
  minimum: 0,
259
259
  maximum: 300000,
260
260
  description: {
261
- en: 'Maximum time to wait in milliseconds (default: 5000 short poll, max: 300000 / 5 minutes)',
262
- zh: '最长等待时间,单位毫秒(默认 5000 短轮询,最大 300000 / 5 分钟)',
261
+ en: 'Maximum duration of this wait call, not the sub-agent lifetime (default: 5000, max: 300000)',
262
+ zh: '本次等待调用的最长时间,不是子 Agent 生命周期(默认 5000,最大 300000)',
263
263
  },
264
264
  },
265
265
  },
@@ -9,7 +9,12 @@ import { defineTool } from './types.js';
9
9
 
10
10
  /** Strip HTML tags and normalize whitespace for readability. */
11
11
  function htmlToText(html) {
12
- return html
12
+ // Remove common site chrome before applying the caller's length budget.
13
+ // Fall back for pages whose only content is navigation; raw/API is untouched.
14
+ const cleaned = html.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, '');
15
+ const withoutChrome = cleaned.replace(/<(nav|footer)\b[^>]*>[\s\S]*?<\/\1>/gi, '');
16
+ const source = withoutChrome.replace(/<[^>]+>/g, '').trim() ? withoutChrome : cleaned;
17
+ return source
13
18
  // Remove script/style blocks
14
19
  .replace(/<script[\s\S]*?<\/script>/gi, '')
15
20
  .replace(/<style[\s\S]*?<\/style>/gi, '')