@yeaft/webchat-agent 0.0.65 → 0.0.66
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/claude.js +3 -2
- package/package.json +1 -1
package/claude.js
CHANGED
|
@@ -358,8 +358,9 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
|
|
|
358
358
|
// 计算上下文使用百分比并注入到消息中
|
|
359
359
|
const inputTokens = message.usage?.input_tokens || 0;
|
|
360
360
|
const maxContextTokens = 200000; // Claude 模型 context window
|
|
361
|
+
let contextUsage = null;
|
|
361
362
|
if (inputTokens > 0) {
|
|
362
|
-
|
|
363
|
+
contextUsage = {
|
|
363
364
|
inputTokens,
|
|
364
365
|
maxTokens: maxContextTokens,
|
|
365
366
|
percentage: Math.min(100, Math.round((inputTokens / maxContextTokens) * 100))
|
|
@@ -384,7 +385,7 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
|
|
|
384
385
|
|
|
385
386
|
// ★ await 确保 result 和 turn_completed 消息确实发送成功
|
|
386
387
|
// 不 await 会导致 encrypt 失败时消息静默丢失,前端卡在"思考中"
|
|
387
|
-
await sendOutput(conversationId, message);
|
|
388
|
+
await sendOutput(conversationId, contextUsage ? { ...message, _contextUsage: contextUsage } : message);
|
|
388
389
|
await ctx.sendToServer({
|
|
389
390
|
type: 'turn_completed',
|
|
390
391
|
conversationId,
|