@bangdao-ai/acw-tools 1.3.8 → 1.3.9

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.
@@ -391,10 +391,14 @@ function extractAdditionalInfo(composerData, bubbles, markdownContent = '') {
391
391
  }
392
392
 
393
393
  let executionTime = 0;
394
+ let isEstimated = false; // 标记是否为估算值
395
+
394
396
  if (aiTimingInfo.clientRpcSendTime && aiTimingInfo.clientSettleTime) {
397
+ // 有 timingInfo,使用精确计算
395
398
  executionTime = aiTimingInfo.clientSettleTime - aiTimingInfo.clientRpcSendTime;
396
399
  additionalInfo.performance.totalExecutionTime += executionTime;
397
400
  }
401
+ // 注意:兜底计算将在第二遍遍历中进行
398
402
 
399
403
  // 构建execution对象(timestamp已在上面统一处理)
400
404
  const execution = {
@@ -411,9 +415,10 @@ function extractAdditionalInfo(composerData, bubbles, markdownContent = '') {
411
415
  }
412
416
  };
413
417
 
414
- // 如果有timingInfo,添加原始时间戳
418
+ // 如果有timingInfo,添加原始时间戳,并标记为精确值
415
419
  if (Object.keys(aiTimingInfo).length > 0) {
416
420
  execution.timingInfo = {
421
+ isEstimated: false, // 标记为精确值(来自 Cursor 原生 timingInfo)
417
422
  clientStartTime: aiTimingInfo.clientStartTime || null,
418
423
  clientRpcSendTime: aiTimingInfo.clientRpcSendTime || null,
419
424
  clientSettleTime: aiTimingInfo.clientSettleTime || null,
@@ -437,6 +442,134 @@ function extractAdditionalInfo(composerData, bubbles, markdownContent = '') {
437
442
  }
438
443
  }
439
444
 
445
+ // ==================== 兜底方案:使用 createdAt 时间差估算执行时间 ====================
446
+ // 核心逻辑:
447
+ // 1. 一个会话包含多轮对话,每轮对话 = 1个User bubble + N个连续AI bubble
448
+ // 2. 正常情况下,第一个AI bubble有timingInfo,其executionTime包含整轮对话的执行时间
449
+ // 3. 兜底:如果第一个AI bubble没有timingInfo,用「下一个User bubble的createdAt - 第一个AI bubble的createdAt」估算
450
+ // 4. 对于最后一轮对话,用「composerData.lastUpdatedAt - 第一个AI bubble的createdAt」估算
451
+
452
+ const executions = additionalInfo.performance.executions;
453
+ let estimatedCount = 0;
454
+
455
+ // 辅助函数:解析时间戳为毫秒
456
+ const parseTimestamp = (ts) => {
457
+ if (!ts) return null;
458
+ if (typeof ts === 'number') return ts;
459
+ const parsed = new Date(ts).getTime();
460
+ return isNaN(parsed) ? null : parsed;
461
+ };
462
+
463
+ // 获取 composerData.lastUpdatedAt 作为最后一轮的结束时间
464
+ const lastUpdatedAt = parseTimestamp(composerData?.lastUpdatedAt);
465
+
466
+ // 遍历 executions,识别每一轮对话并处理兜底
467
+ let i = 0;
468
+ while (i < executions.length) {
469
+ const current = executions[i];
470
+
471
+ // 跳过非 User bubble
472
+ if (current.type !== 'user') {
473
+ i++;
474
+ continue;
475
+ }
476
+
477
+ // 找到 User bubble,开始处理这一轮对话
478
+ const userBubbleIndex = i;
479
+ i++; // 移动到下一个 bubble
480
+
481
+ // 找到这一轮的第一个 AI bubble
482
+ if (i >= executions.length || executions[i].type !== 'ai') {
483
+ continue; // 没有 AI bubble,跳过
484
+ }
485
+
486
+ const firstAiBubbleIndex = i;
487
+ const firstAiBubble = executions[firstAiBubbleIndex];
488
+
489
+ // 找到这一轮的最后一个 AI bubble(连续的 AI bubble)
490
+ let lastAiBubbleIndex = firstAiBubbleIndex;
491
+ while (lastAiBubbleIndex + 1 < executions.length && executions[lastAiBubbleIndex + 1].type === 'ai') {
492
+ lastAiBubbleIndex++;
493
+ }
494
+
495
+ // 移动索引到下一轮
496
+ i = lastAiBubbleIndex + 1;
497
+
498
+ // 检查第一个 AI bubble 是否需要兜底
499
+ // 条件:没有 timingInfo 且 executionTime 为 0
500
+ if (firstAiBubble.timingInfo || firstAiBubble.executionTime > 0) {
501
+ continue; // 已有执行时间,不需要兜底
502
+ }
503
+
504
+ // 计算估算执行时间
505
+ const firstAiCreatedAt = parseTimestamp(firstAiBubble.timestamp);
506
+ if (!firstAiCreatedAt) {
507
+ continue; // 没有时间戳,无法估算
508
+ }
509
+
510
+ let endTime = null;
511
+ let endTimeSource = '';
512
+
513
+ // 优先使用下一个 User bubble 的 createdAt
514
+ if (i < executions.length && executions[i].type === 'user') {
515
+ endTime = parseTimestamp(executions[i].timestamp);
516
+ endTimeSource = 'nextUserBubble';
517
+ }
518
+
519
+ // 如果是最后一轮对话,使用 lastUpdatedAt
520
+ if (!endTime && lastUpdatedAt) {
521
+ endTime = lastUpdatedAt;
522
+ endTimeSource = 'lastUpdatedAt';
523
+ }
524
+
525
+ if (!endTime) {
526
+ continue; // 无法确定结束时间
527
+ }
528
+
529
+ // 计算时间差
530
+ const estimatedTime = endTime - firstAiCreatedAt;
531
+
532
+ // 验证估算值的合理性(正数且小于30分钟)
533
+ if (estimatedTime <= 0 || estimatedTime > 30 * 60 * 1000) {
534
+ if (DEBUG_MODE) {
535
+ debugLog(`[兜底跳过] 估算值不合理`, {
536
+ bubbleId: firstAiBubble.bubbleId,
537
+ firstAiCreatedAt,
538
+ endTime,
539
+ endTimeSource,
540
+ estimatedTime: `${estimatedTime}ms`
541
+ });
542
+ }
543
+ continue;
544
+ }
545
+
546
+ // 应用估算值
547
+ firstAiBubble.executionTime = estimatedTime;
548
+ firstAiBubble.timingInfo = {
549
+ isEstimated: true, // 标记为估算值
550
+ estimatedFrom: endTimeSource,
551
+ firstAiCreatedAt: firstAiCreatedAt,
552
+ endTime: endTime
553
+ };
554
+ additionalInfo.performance.totalExecutionTime += estimatedTime;
555
+ estimatedCount++;
556
+
557
+ if (DEBUG_MODE) {
558
+ debugLog(`[兜底估算成功]`, {
559
+ bubbleId: firstAiBubble.bubbleId,
560
+ 轮次AI_bubble数: lastAiBubbleIndex - firstAiBubbleIndex + 1,
561
+ firstAiCreatedAt: new Date(firstAiCreatedAt).toISOString(),
562
+ endTime: new Date(endTime).toISOString(),
563
+ endTimeSource,
564
+ estimatedExecutionTime: `${estimatedTime}ms (${(estimatedTime / 1000).toFixed(1)}s)`
565
+ });
566
+ }
567
+ }
568
+
569
+ if (DEBUG_MODE && estimatedCount > 0) {
570
+ debugLog(`[兜底估算汇总] 共估算了 ${estimatedCount} 轮对话的执行时间`);
571
+ }
572
+
440
573
  // 计算平均执行时间、最大执行时间和最小执行时间(只统计type='ai'且executionTime>0的)
441
574
  let validAiExecutionCount = 0;
442
575
  let validTotalExecutionTime = 0;
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ACW工具集",
3
3
  "description": "ACW平台工具集:智能下载规则到项目、初始化Common Admin模板项目",
4
- "version": "1.3.8",
4
+ "version": "1.3.9",
5
5
  "author": "邦道科技 - 产品技术中心",
6
6
  "homepage": "https://www.npmjs.com/package/@bangdao-ai/acw-tools",
7
7
  "repository": "https://www.npmjs.com/package/@bangdao-ai/acw-tools?activeTab=readme",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bangdao-ai/acw-tools",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "type": "module",
5
5
  "description": "MCP (Model Context Protocol) tools for ACW - download rules and initialize Common Admin projects",
6
6
  "main": "index.js",