|
|
|
|
@ -8,7 +8,7 @@
@@ -8,7 +8,7 @@
|
|
|
|
|
var seen = Object.create(null) |
|
|
|
|
var cfg = null |
|
|
|
|
var lastAccum = null |
|
|
|
|
var SEP = String.fromCharCode(10) + String.fromCharCode(10) |
|
|
|
|
var SEP = String.fromCharCode(10) + String.fromCharCode(10); try { window.addEventListener('dshmem:chat-change', function () { charsAccum = 0; lastAccum = null; seen = Object.create(null); }) } catch (e) {} |
|
|
|
|
|
|
|
|
|
function hash(s) { |
|
|
|
|
var h1 = 5381 |
|
|
|
|
@ -159,9 +159,9 @@
@@ -159,9 +159,9 @@
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (!cfg.enabled) return |
|
|
|
|
var messages = [] |
|
|
|
|
var messages = []; var chatId = ''; var reqKeys = '' |
|
|
|
|
try { |
|
|
|
|
var req = JSON.parse(entry.body) |
|
|
|
|
var req = JSON.parse(entry.body); if (req) reqKeys = Object.keys(req).join(','); var ck = 'chat' + '_session' + '_id'; if (req) chatId = String(req[ck] || '') |
|
|
|
|
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 @@
@@ -204,7 +204,7 @@
|
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
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) { } |
|
|
|
|
} |
|
|
|
|
@ -233,5 +233,5 @@
@@ -233,5 +233,5 @@
|
|
|
|
|
return origSend.apply(this, arguments) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
requestConfig() |
|
|
|
|
requestConfig(); try { var __boot = Date.now(); var __nav = ''; try { var __ne = performance.getEntriesByType('navigation'); __nav = (__ne && __ne[0] && __ne[0].type) || 'unknown' } catch (e1) { __nav = 'err' } var __path = String(location.pathname || ''); var __cid = ''; var __parts = __path.split('/'); var __si = __parts.indexOf('s'); __cid = __si !== -1 && __parts[__si + 1] ? __parts[__si + 1] : ''; var __init = { mid: 'init-' + __boot, part: 0, total: 1, role: 'init', ts: __boot, inj: false, text: 'init', boot: __boot, nav: __nav, ready: document.readyState, path: __path, chat_id: __cid }; var __cfgReady = requestConfig(); __cfgReady.then(function (c) { if (!c || !c.token) return; var __h = { 'Content-Type': 'application/json' }; __h.Authorization = 'Bearer ' + c.token; fetch(BASE + '/log/append', { method: 'POST', headers: __h, body: JSON.stringify({ file: today() + '.jsonl', lines: [JSON.stringify(__init)] }) }).catch(function () { }) }); } catch (e2) { } |
|
|
|
|
})() |
|
|
|
|
|