@yeaft/webchat-agent 1.0.503 → 1.0.505

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.
Files changed (88) hide show
  1. package/local-runtime/server/db/connection.js +14 -2
  2. package/local-runtime/server/db/user-stats-db.js +7 -0
  3. package/local-runtime/server/handlers/agent-conversation.js +2 -1
  4. package/local-runtime/server/handlers/agent-output.js +4 -1
  5. package/local-runtime/server/routes/admin-routes.js +3 -3
  6. package/local-runtime/version.json +1 -1
  7. package/local-runtime/web/app.bundle.js +108 -120
  8. package/local-runtime/web/app.bundle.js.gz +0 -0
  9. package/local-runtime/web/index.html +4 -3
  10. package/local-runtime/web/style.bundle.css +1 -1
  11. package/local-runtime/web/style.bundle.css.gz +0 -0
  12. package/local-runtime/web/vendor/katex/LICENSE +21 -0
  13. package/local-runtime/web/vendor/katex/fonts/KaTeX_AMS-Regular.ttf +0 -0
  14. package/local-runtime/web/vendor/katex/fonts/KaTeX_AMS-Regular.woff +0 -0
  15. package/local-runtime/web/vendor/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  16. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  17. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  18. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  19. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  20. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  21. package/local-runtime/web/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  22. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  23. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  24. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  25. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  26. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  27. package/local-runtime/web/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  28. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Bold.ttf +0 -0
  29. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Bold.woff +0 -0
  30. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  31. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  32. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  33. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  34. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Italic.ttf +0 -0
  35. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Italic.woff +0 -0
  36. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  37. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Regular.ttf +0 -0
  38. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Regular.woff +0 -0
  39. package/local-runtime/web/vendor/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  40. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  41. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  42. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  43. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-Italic.ttf +0 -0
  44. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-Italic.woff +0 -0
  45. package/local-runtime/web/vendor/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  46. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  47. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  48. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  49. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  50. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  51. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  52. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  53. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  54. package/local-runtime/web/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  55. package/local-runtime/web/vendor/katex/fonts/KaTeX_Script-Regular.ttf +0 -0
  56. package/local-runtime/web/vendor/katex/fonts/KaTeX_Script-Regular.woff +0 -0
  57. package/local-runtime/web/vendor/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  58. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size1-Regular.ttf +0 -0
  59. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size1-Regular.woff +0 -0
  60. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  61. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size2-Regular.ttf +0 -0
  62. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size2-Regular.woff +0 -0
  63. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  64. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size3-Regular.ttf +0 -0
  65. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size3-Regular.woff +0 -0
  66. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  67. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size4-Regular.ttf +0 -0
  68. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size4-Regular.woff +0 -0
  69. package/local-runtime/web/vendor/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  70. package/local-runtime/web/vendor/katex/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  71. package/local-runtime/web/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  72. package/local-runtime/web/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  73. package/local-runtime/web/vendor/katex/katex.min.css +1 -0
  74. package/local-runtime/web/vendor.bundle.js +1 -0
  75. package/local-runtime/web/vendor.bundle.js.gz +0 -0
  76. package/package.json +1 -1
  77. package/yeaft/config-api.js +16 -5
  78. package/yeaft/config.js +11 -2
  79. package/yeaft/conversation/history-index-worker.js +151 -0
  80. package/yeaft/conversation/history-index.js +96 -1
  81. package/yeaft/conversation/persist.js +6 -1
  82. package/yeaft/conversation/recall-relevance.js +103 -0
  83. package/yeaft/debug-trace.js +15 -4
  84. package/yeaft/engine.js +89 -16
  85. package/yeaft/history-window.js +370 -0
  86. package/yeaft/vp/seed-defaults.js +169 -8
  87. package/yeaft/vp/stock-ids.js +2 -0
  88. package/yeaft/web-bridge.js +19 -12
@@ -99,6 +99,7 @@ db.exec(`
99
99
  cache_read_tokens INTEGER DEFAULT 0,
100
100
  cache_write_tokens INTEGER DEFAULT 0,
101
101
  total_tokens INTEGER DEFAULT 0,
102
+ last_turn_completed_at INTEGER,
102
103
  updated_at INTEGER NOT NULL DEFAULT 0
103
104
  );
104
105
 
@@ -375,6 +376,7 @@ const migrations = [
375
376
  `ALTER TABLE user_stats ADD COLUMN cache_read_tokens INTEGER DEFAULT 0`,
376
377
  `ALTER TABLE user_stats ADD COLUMN cache_write_tokens INTEGER DEFAULT 0`,
377
378
  `ALTER TABLE user_stats ADD COLUMN total_tokens INTEGER DEFAULT 0`,
379
+ `ALTER TABLE user_stats ADD COLUMN last_turn_completed_at INTEGER`,
378
380
  `ALTER TABLE daily_stats ADD COLUMN input_tokens INTEGER DEFAULT 0`,
379
381
  `ALTER TABLE daily_stats ADD COLUMN output_tokens INTEGER DEFAULT 0`,
380
382
  `ALTER TABLE daily_stats ADD COLUMN cache_read_tokens INTEGER DEFAULT 0`,
@@ -1235,7 +1237,8 @@ export const stmts = {
1235
1237
  `),
1236
1238
 
1237
1239
  getDailyStatsAll: db.prepare(`
1238
- SELECT ds.user_id, u.username, u.display_name, u.role, u.last_login_at,
1240
+ SELECT ds.user_id, u.username, u.display_name, u.role,
1241
+ MAX(us.last_turn_completed_at) as last_turn_completed_at,
1239
1242
  SUM(ds.message_count) as message_count, SUM(ds.session_count) as session_count,
1240
1243
  SUM(ds.request_count) as request_count, SUM(ds.bytes_sent) as bytes_sent,
1241
1244
  SUM(ds.bytes_received) as bytes_received,
@@ -1245,6 +1248,7 @@ export const stmts = {
1245
1248
  SUM(ds.total_tokens) as total_tokens
1246
1249
  FROM daily_stats ds
1247
1250
  JOIN users u ON ds.user_id = u.id
1251
+ LEFT JOIN user_stats us ON us.user_id = ds.user_id
1248
1252
  WHERE ds.date >= ?
1249
1253
  GROUP BY ds.user_id
1250
1254
  ORDER BY message_count DESC
@@ -1259,7 +1263,7 @@ export const stmts = {
1259
1263
  `),
1260
1264
 
1261
1265
  getUserStats: db.prepare(`
1262
- SELECT us.*, u.username, u.display_name, u.role, u.last_login_at
1266
+ SELECT us.*, u.username, u.display_name, u.role
1263
1267
  FROM user_stats us
1264
1268
  JOIN users u ON us.user_id = u.id
1265
1269
  ORDER BY us.message_count DESC
@@ -1269,6 +1273,14 @@ export const stmts = {
1269
1273
  SELECT * FROM user_stats WHERE user_id = ?
1270
1274
  `),
1271
1275
 
1276
+ updateLastTurnCompletedAt: db.prepare(`
1277
+ INSERT INTO user_stats (user_id, last_turn_completed_at, updated_at)
1278
+ VALUES (?, ?, ?)
1279
+ ON CONFLICT(user_id) DO UPDATE SET
1280
+ last_turn_completed_at = MAX(COALESCE(last_turn_completed_at, 0), excluded.last_turn_completed_at),
1281
+ updated_at = MAX(updated_at, excluded.updated_at)
1282
+ `),
1283
+
1272
1284
  getAgentMetricWatermark: db.prepare(`
1273
1285
  SELECT * FROM agent_metric_watermarks
1274
1286
  WHERE user_id = ? AND agent_instance_id = ? AND metric_epoch = ?
@@ -100,6 +100,13 @@ export const userStatsDb = {
100
100
  return stmts.getUserStatsById.get(userId) || null;
101
101
  },
102
102
 
103
+ recordTurnCompleted(userId, completedAt = Date.now()) {
104
+ if (!userId) return;
105
+ const timestamp = Number(completedAt);
106
+ if (!Number.isFinite(timestamp) || timestamp <= 0) return;
107
+ stmts.updateLastTurnCompletedAt.run(userId, timestamp, timestamp);
108
+ },
109
+
103
110
  /**
104
111
  * Convert one cumulative agent snapshot into an idempotent user delta.
105
112
  * A new metric epoch means the agent process restarted and counters began at
@@ -1,4 +1,4 @@
1
- import { sessionDb, messageDb, sessionUiMetadataDb } from '../database.js';
1
+ import { sessionDb, messageDb, sessionUiMetadataDb, userStatsDb } from '../database.js';
2
2
  import {
3
3
  broadcastAgentList, notifyConversationUpdate, forwardToClients
4
4
  } from '../ws-utils.js';
@@ -250,6 +250,7 @@ export async function handleAgentConversation(agentId, agent, msg) {
250
250
  console.warn(`[turn_completed] Ignoring duplicate for ${msg.conversationId}`);
251
251
  break;
252
252
  }
253
+ userStatsDb.recordTurnCompleted(turnConv?.userId || agent.ownerId, Date.now());
253
254
  if (turnConv) {
254
255
  turnConv.processing = false;
255
256
  if (msg.claudeSessionId) {
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from 'crypto';
2
- import { messageDb, sessionUiMetadataDb, yeaftProjectDb, yeaftSessionDb } from '../database.js';
2
+ import { messageDb, sessionUiMetadataDb, userStatsDb, yeaftProjectDb, yeaftSessionDb } from '../database.js';
3
3
  import { transaction } from '../db/connection.js';
4
4
  import { broadcastAgentList, broadcastSessionCatalog, forwardToClients, sendToAgent, sendToWebClient } from '../ws-utils.js';
5
5
  import { advanceYeaftDebugRequestChunk, consumeYeaftDebugRequest, webClients, previewFiles } from '../context.js';
@@ -572,6 +572,9 @@ export async function handleAgentOutput(agentId, agent, msg) {
572
572
  agent.yeaftStatus = event;
573
573
  await broadcastAgentList();
574
574
  }
575
+ if (event?.type === 'vp_turn_end') {
576
+ userStatsDb.recordTurnCompleted(agent.ownerId, event.ts || Date.now());
577
+ }
575
578
  if (event?.type === 'session_roster_changed' && agent.ownerId && event.sessionId) {
576
579
  try {
577
580
  const existing = yeaftSessionDb.getForAgent(agent.ownerId, agentId, event.sessionId);
@@ -71,7 +71,7 @@ function mergePendingUserStats(stats) {
71
71
  username: userId,
72
72
  display_name: userId,
73
73
  role: 'pro',
74
- last_login_at: null,
74
+ last_turn_completed_at: null,
75
75
  updated_at: Date.now(),
76
76
  message_count: toNumber(delta.messages),
77
77
  session_count: toNumber(delta.sessions),
@@ -159,7 +159,7 @@ export function registerAdminRoutes(app, { requireAuth, requireAdmin }) {
159
159
  cache_read_tokens: 0,
160
160
  cache_write_tokens: 0,
161
161
  total_tokens: 0,
162
- last_login_at: user.last_login_at,
162
+ last_turn_completed_at: null,
163
163
  updated_at: user.created_at,
164
164
  });
165
165
  }
@@ -181,7 +181,7 @@ export function registerAdminRoutes(app, { requireAuth, requireAdmin }) {
181
181
  cacheReadTokens: s.cache_read_tokens,
182
182
  cacheWriteTokens: s.cache_write_tokens,
183
183
  totalTokens: s.total_tokens,
184
- lastLoginAt: s.last_login_at,
184
+ lastTurnCompletedAt: s.last_turn_completed_at,
185
185
  updatedAt: s.updated_at
186
186
  })));
187
187
  } catch (e) {
@@ -1 +1 @@
1
- {"version":"1.0.503"}
1
+ {"version":"1.0.505"}