diff --git a/injected/chat-logger.js b/injected/chat-logger.js index ed9b03f..a6e8ed3 100644 --- a/injected/chat-logger.js +++ b/injected/chat-logger.js @@ -161,7 +161,7 @@ if (!cfg.enabled) return var messages = []; var chatId = ''; var reqKeys = '' try { - var req = JSON.parse(entry.body); if (req) reqKeys = Object.keys(req).join(','); var ck = 'chat' + '_session' + '_id'; if (req) chatId = String(req[ck] || '') + var req = JSON.parse(entry.body); if (req) reqKeys = Object.keys(req).join(','); var ck = 'chat' + '_session' + '_id'; if (req) chatId = String(req[ck] || ''); var pk = 'parent' + '_message' + '_id'; var pid = (req && req[pk] !== undefined) ? String(req[pk]) : 'absent' if (req && Array.isArray(req.messages)) messages = req.messages else if (req && typeof req.prompt === 'string' && req.prompt) messages = [{ role: 'user', content: req.prompt }] } catch (e) { return } @@ -204,7 +204,7 @@ accum: accum, delta: delta, chars: ctxChars, - chat_id: chatId, req_keys: reqKeys, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10 + chat_id: chatId, parent_id: pid, req_keys: reqKeys, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10 } lines.push(JSON.stringify(meta)); try { window.dispatchEvent(new CustomEvent('dshmem:metrics', { detail: JSON.stringify({ accum: accum, delta: delta, chars: ctxChars, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10 }) })) } catch (e) { } }