@chatpanel/events 0.156.0 → 0.161.2
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/capability-adapters.js +1 -0
- package/capability-endpoints.js +1 -1
- package/capability-providers.js +3 -0
- package/capability-tools.js +3 -0
- package/fast-path.js +6 -4
- package/feature-map.js +1 -0
- package/index.js +1 -1
- package/loop.js +1 -1
- package/model-registry.js +1 -1
- package/model-roles.js +1 -1
- package/note-plan.js +2 -2
- package/package.json +9 -1
- package/run-details.js +1 -1
- package/settings-registry.js +1 -1
- package/titles.js +1 -1
- package/trajectory.js +1 -1
package/trajectory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{linearize as m}from"./order.js";function k(n){const o=n?.args?.action;return typeof o!="string"||!o?n?.name||"tool":o==="describe"&&n.args.tool?`${n.name}.describe(${n.args.tool})`:`${n.name}.${o}`}const x=Object.freeze(["system","user","context","route","privacy","tool","result","reasoning","assistant"]),f=(n,o=120)=>{const s=String(n??"").replace(/\s+/g," ").trim();return s.length>o?`${s.slice(0,o-1)}…`:s};function h(n){const o=m(n||[]),s=[],e=new Map;let a=null;for(const r of o){const t=r.payload||{};switch(r.type){case"turn.started":a=r.at;break;case"context.assembled":s.push({kind:"context",at:r.at,title:"Context assembled",detail:`${(t.tools||[]).length} tool${(t.tools||[]).length===1?"":"s"} · ${t.used||0} tokens`,data:{tools:t.tools||[],tokens:t.used||0,redaction:!!t.redaction,surface:t.surface}});break;case"context.retrieved":s.push({kind:"context",at:r.at,title:t.count?`Retrieved ${t.count} source${t.count===1?"":"s"}`:"Retrieved material",detail:[t.tool,t.chars?`${t.chars} chars`:""].filter(Boolean).join(" · "),data:{tool:t.tool,count:t.count,sources:t.sources||[]}});break;case"privacy.redacted":{const i=t.counts||{},l=Object.values(i).reduce((u,c)=>u+(Number(c)||0),0);if(!l)break;const d=Object.entries(i).sort((u,c)=>c[1]-u[1]).map(([u,c])=>`${c} ${u.toLowerCase().replace(/_/g," ")}`).join(" · ");s.push({kind:"privacy",at:r.at,title:`Redacted ${l} value${l===1?"":"s"} before sending`,detail:d,data:{counts:i}});break}case"assistant.prompted":s.push({kind:"system",at:r.at,title:"Prompt",detail:`${t.chars||0} chars`,ref:t.ref,expandsToMessages:!0});break;case"policy.changed":{if(!String(t.dial||"").startsWith("route."))break;const i=t.dial==="route.applied";s.push({kind:"route",at:r.at,title:i?`Routed to ${t.to}`:`Would route to ${t.to}`,detail:(t.reasons||[])[0]||"",data:{from:t.from,to:t.to,applied:i,agrees:t.agrees,strategy:t.strategy,reasons:t.reasons,eligible:t.eligible,rejected:t.rejected,graph:t.graph||null}});break}case"automation.fired":{if(t.ruleId!=="router:failover"){s.push({kind:"route",at:r.at,title:`Rule fired: ${t.ruleId}`,detail:`class ${t.classUsed}`,data:t});break}s.push({kind:"route",at:r.at,title:`Failed over to ${t.to}`,detail:`${t.from} declined (${t.reason})`,data:t});break}case"capability.invoked":{const i={kind:"tool",at:r.at,title:k({name:t.capability,args:t.args}),detail:f(JSON.stringify(t.args||{}),90),key:t.idempotencyKey||r.id,ok:null,ms:null,data:{capability:t.capability,args:t.args||{},actor:t.actor,scope:t.scope,effects:t.effects,started:new Date(r.at).toISOString()}};e.set(i.key,i),s.push(i);break}case"capability.resulted":{const i=e.get(t.idempotencyKey);i&&(i.ok=t.ok,i.ms=t.cost?.ms??null),s.push({kind:"result",at:r.at,title:`${t.capability} → ${t.ok?"ok":"failed"}`,detail:f(t.summary,120),ok:!!t.ok,ms:t.cost?.ms??null,data:{status:t.ok?"completed":"failed",durationMs:t.cost?.ms??null,classUsed:t.classUsed,finished:new Date(r.at).toISOString(),result:t.summary}});break}case"assistant.reasoning":s.push({kind:"reasoning",at:r.at,title:"Reasoning",detail:`${t.chars||0} chars`,ref:t.ref});break;case"assistant.message":s.push({kind:"assistant",at:r.at,title:"Answer",detail:[`${t.chars||0} chars`,t.citations?.length?`${t.citations.length} citation${t.citations.length===1?"":"s"}`:""].filter(Boolean).join(" · "),ref:t.ref,data:t.citations?.length?{citations:t.citations}:null});break;default:break}}for(const r of s)r.offsetMs=a==null?null:r.at-a;return s}function $(n){const o=n?.ms;if(!Number.isFinite(o)||o<=0)return null;const s=Math.max(0,Math.min(n.prepMs||0,o)),e=Math.max(0,Math.min(n.ttftMs||0,o-s)),a=Math.max(0,o-s-e),r=t=>t/o*100;return{total:o,parts:[{key:"setup",ms:s,pct:r(s),label:"Setup — tools and MCP servers"},{key:"wait",ms:e,pct:r(e),label:"Waiting for the first word"},{key:"work",ms:a,pct:r(a),label:"Tools and writing"}].filter(t=>t.ms>0)}}function M(n,o){const s=o?.ms;if(!Number.isFinite(s)||s<=0)return null;const e=r=>Math.max(0,Math.min(100,r/s*100)),a={input:[],model:[],tools:[]};for(const r of n){if(r.offsetMs==null)continue;const t=e(r.offsetMs);r.kind==="system"||r.kind==="user"||r.kind==="context"?a.input.push({left:t,width:Math.max(.6,e(200)),label:r.title}):r.kind==="tool"?a.tools.push({left:t,width:Math.max(1,e(r.ms||400)),label:r.title}):(r.kind==="assistant"||r.kind==="reasoning")&&a.model.push({left:t,width:Math.max(1,e(400)),label:r.title})}return o.ttftMs>0&&a.model.unshift({left:e(o.prepMs||0),width:e(o.ttftMs),label:"Waiting for the first word"}),o.prepMs>0&&a.input.unshift({left:0,width:e(o.prepMs),label:"Setup — tools and MCP servers"}),a}function I(n){const o=Number(n?.tokensOut)||0,s=Number.isFinite(n?.ttftMs)?n.ttftMs:null,e=Number.isFinite(n?.ms)?n.ms:null,a=e!=null&&s!=null?Math.max(0,e-s):null;return{tokensIn:Number(n?.tokensIn)||0,tokensOut:o,tokensReasoning:Number(n?.tokensReasoning)||0,tokensTotal:(Number(n?.tokensIn)||0)+o,ttftMs:s,generationMs:a,totalMs:e,throughput:a>0&&o>0?+(o/(a/1e3)).toFixed(1):null,model:n?.model||null,status:n?.status||"completed"}}function w(n){const o=[];let s=null;const e=()=>(s={index:o.length+1,entries:[],calls:[],answer:null,at:null},o.push(s),s);for(const a of n)(a.kind==="system"||!s&&a.kind!=="context")&&e(),s||e(),s.at==null&&(s.at=a.at),s.entries.push(a),a.requestIndex=s.index,a.kind==="tool"&&s.calls.push(a),a.kind==="assistant"&&(s.answer=a);return o}function A(n,o){const s=String(o||"").trim().toLowerCase();return s?n.filter(e=>`${e.title} ${e.detail||""}`.toLowerCase().includes(s)):n}function g(n=[]){const o=new Map;for(const e of n){if(!e)continue;const a=e.surface||e.turn?.surface||e.turn?.kind||e.kind||"other",r=e.sourceId||e.turn?.sourceId||null,t=r?`src:${r}`:`run:${e.turnId||e.id}`;o.has(t)||o.set(t,{key:t,surface:a,sourceId:r,runs:[],startedAt:1/0,endedAt:-1/0,ms:0,tokensIn:0,tokensOut:0,calls:0,errors:0});const i=o.get(t);i.runs.push(e);const l=e.at??e.turn?.startedAt??0;i.startedAt=Math.min(i.startedAt,l),i.endedAt=Math.max(i.endedAt,e.turn?.endedAt??l),i.ms+=e.turn?.ms||0,i.tokensIn+=e.turn?.tokensIn||0,i.tokensOut+=e.turn?.tokensOut||0,i.calls+=e.calls?.length||0,e.turn?.reason
|
|
1
|
+
import{linearize as m}from"./order.js";function k(n){const o=n?.args?.action;return typeof o!="string"||!o?n?.name||"tool":o==="describe"&&n.args.tool?`${n.name}.describe(${n.args.tool})`:`${n.name}.${o}`}const x=Object.freeze(["system","user","context","route","privacy","tool","result","reasoning","assistant"]),f=(n,o=120)=>{const s=String(n??"").replace(/\s+/g," ").trim();return s.length>o?`${s.slice(0,o-1)}…`:s};function h(n){const o=m(n||[]),s=[],e=new Map;let a=null;for(const r of o){const t=r.payload||{};switch(r.type){case"turn.started":a=r.at;break;case"context.assembled":s.push({kind:"context",at:r.at,title:"Context assembled",detail:`${(t.tools||[]).length} tool${(t.tools||[]).length===1?"":"s"} · ${t.used||0} tokens`,data:{tools:t.tools||[],tokens:t.used||0,redaction:!!t.redaction,surface:t.surface}});break;case"context.retrieved":s.push({kind:"context",at:r.at,title:t.count?`Retrieved ${t.count} source${t.count===1?"":"s"}`:"Retrieved material",detail:[t.tool,t.chars?`${t.chars} chars`:""].filter(Boolean).join(" · "),data:{tool:t.tool,count:t.count,sources:t.sources||[]}});break;case"privacy.redacted":{const i=t.counts||{},l=Object.values(i).reduce((u,c)=>u+(Number(c)||0),0);if(!l)break;const d=Object.entries(i).sort((u,c)=>c[1]-u[1]).map(([u,c])=>`${c} ${u.toLowerCase().replace(/_/g," ")}`).join(" · ");s.push({kind:"privacy",at:r.at,title:`Redacted ${l} value${l===1?"":"s"} before sending`,detail:d,data:{counts:i}});break}case"assistant.prompted":s.push({kind:"system",at:r.at,title:"Prompt",detail:`${t.chars||0} chars`,ref:t.ref,expandsToMessages:!0});break;case"policy.changed":{if(!String(t.dial||"").startsWith("route."))break;const i=t.dial==="route.applied";s.push({kind:"route",at:r.at,title:i?`Routed to ${t.to}`:`Would route to ${t.to}`,detail:(t.reasons||[])[0]||"",data:{from:t.from,to:t.to,applied:i,agrees:t.agrees,strategy:t.strategy,reasons:t.reasons,eligible:t.eligible,rejected:t.rejected,graph:t.graph||null}});break}case"automation.fired":{if(t.ruleId!=="router:failover"){s.push({kind:"route",at:r.at,title:`Rule fired: ${t.ruleId}`,detail:`class ${t.classUsed}`,data:t});break}s.push({kind:"route",at:r.at,title:`Failed over to ${t.to}`,detail:`${t.from} declined (${t.reason})`,data:t});break}case"capability.invoked":{const i={kind:"tool",at:r.at,title:k({name:t.capability,args:t.args}),detail:f(JSON.stringify(t.args||{}),90),key:t.idempotencyKey||r.id,ok:null,ms:null,data:{capability:t.capability,args:t.args||{},actor:t.actor,scope:t.scope,effects:t.effects,started:new Date(r.at).toISOString()}};e.set(i.key,i),s.push(i);break}case"capability.resulted":{const i=e.get(t.idempotencyKey);i&&(i.ok=t.ok,i.ms=t.cost?.ms??null),s.push({kind:"result",at:r.at,title:`${t.capability} → ${t.ok?"ok":"failed"}`,detail:f(t.summary,120),ok:!!t.ok,ms:t.cost?.ms??null,data:{status:t.ok?"completed":"failed",durationMs:t.cost?.ms??null,classUsed:t.classUsed,finished:new Date(r.at).toISOString(),result:t.summary}});break}case"assistant.reasoning":s.push({kind:"reasoning",at:r.at,title:"Reasoning",detail:`${t.chars||0} chars`,ref:t.ref});break;case"assistant.message":s.push({kind:"assistant",at:r.at,title:"Answer",detail:[`${t.chars||0} chars`,t.citations?.length?`${t.citations.length} citation${t.citations.length===1?"":"s"}`:""].filter(Boolean).join(" · "),ref:t.ref,data:t.citations?.length?{citations:t.citations}:null});break;default:break}}for(const r of s)r.offsetMs=a==null?null:r.at-a;return s}function $(n){const o=n?.ms;if(!Number.isFinite(o)||o<=0)return null;const s=Math.max(0,Math.min(n.prepMs||0,o)),e=Math.max(0,Math.min(n.ttftMs||0,o-s)),a=Math.max(0,o-s-e),r=t=>t/o*100;return{total:o,parts:[{key:"setup",ms:s,pct:r(s),label:"Setup — tools and MCP servers"},{key:"wait",ms:e,pct:r(e),label:"Waiting for the first word"},{key:"work",ms:a,pct:r(a),label:"Tools and writing"}].filter(t=>t.ms>0)}}function M(n,o){const s=o?.ms;if(!Number.isFinite(s)||s<=0)return null;const e=r=>Math.max(0,Math.min(100,r/s*100)),a={input:[],model:[],tools:[]};for(const r of n){if(r.offsetMs==null)continue;const t=e(r.offsetMs);r.kind==="system"||r.kind==="user"||r.kind==="context"?a.input.push({left:t,width:Math.max(.6,e(200)),label:r.title}):r.kind==="tool"?a.tools.push({left:t,width:Math.max(1,e(r.ms||400)),label:r.title}):(r.kind==="assistant"||r.kind==="reasoning")&&a.model.push({left:t,width:Math.max(1,e(400)),label:r.title})}return o.ttftMs>0&&a.model.unshift({left:e(o.prepMs||0),width:e(o.ttftMs),label:"Waiting for the first word"}),o.prepMs>0&&a.input.unshift({left:0,width:e(o.prepMs),label:"Setup — tools and MCP servers"}),a}function I(n){const o=Number(n?.tokensOut)||0,s=Number.isFinite(n?.ttftMs)?n.ttftMs:null,e=Number.isFinite(n?.ms)?n.ms:null,a=e!=null&&s!=null?Math.max(0,e-s):null;return{tokensIn:Number(n?.tokensIn)||0,tokensOut:o,tokensReasoning:Number(n?.tokensReasoning)||0,tokensTotal:(Number(n?.tokensIn)||0)+o,ttftMs:s,generationMs:a,totalMs:e,throughput:a>0&&o>0?+(o/(a/1e3)).toFixed(1):null,model:n?.model||null,status:n?.status||"completed"}}function w(n){const o=[];let s=null;const e=()=>(s={index:o.length+1,entries:[],calls:[],answer:null,at:null},o.push(s),s);for(const a of n)(a.kind==="system"||!s&&a.kind!=="context")&&e(),s||e(),s.at==null&&(s.at=a.at),s.entries.push(a),a.requestIndex=s.index,a.kind==="tool"&&s.calls.push(a),a.kind==="assistant"&&(s.answer=a);return o}function A(n,o){const s=String(o||"").trim().toLowerCase();return s?n.filter(e=>`${e.title} ${e.detail||""}`.toLowerCase().includes(s)):n}function g(n=[]){const o=new Map;for(const e of n){if(!e)continue;const a=e.surface||e.turn?.surface||e.turn?.kind||e.kind||"other",r=e.sourceId||e.turn?.sourceId||null,t=r?`src:${r}`:`run:${e.turnId||e.id}`;o.has(t)||o.set(t,{key:t,surface:a,sourceId:r,runs:[],startedAt:1/0,endedAt:-1/0,ms:0,tokensIn:0,tokensOut:0,calls:0,errors:0});const i=o.get(t);i.runs.push(e);const l=e.at??e.turn?.startedAt??0;i.startedAt=Math.min(i.startedAt,l),i.endedAt=Math.max(i.endedAt,e.turn?.endedAt??l),i.ms+=e.turn?.ms||0,i.tokensIn+=e.turn?.tokensIn||0,i.tokensOut+=e.turn?.tokensOut||0,i.calls+=e.calls?.length||0,e.turn?.reason==="error"&&(i.errors+=1)}const s=[...o.values()].map(e=>({...e,surface:e.runs.find(a=>!a.background)?.surface||e.surface,startedAt:Number.isFinite(e.startedAt)?e.startedAt:0,endedAt:Number.isFinite(e.endedAt)?e.endedAt:0,runs:[...e.runs].sort((a,r)=>(a.at??0)-(r.at??0)),turns:e.runs.length}));return s.sort((e,a)=>a.endedAt-e.endedAt),s}function S(n,o=()=>null){const s=n.sourceId?o(n.surface,n.sourceId):null;if(s)return s;const e=n.runs?.[0],a=n.sourceId?String(n.sourceId).slice(-6):String(e?.turnId||"").slice(-6),r={chat:"Chat",note:"Note",meeting:"Meeting"}[n.surface]||n.surface||"Run";return a?`${r} · ${a}`:r}function v(n,o=0){const s=[];if(!n||typeof n!="object")return s;n.system&&s.push({kind:"system",at:o,title:"System prompt",detail:`${p(n.system)} chars`,text:n.system}),n.toolSystem&&s.push({kind:"system",at:o,title:"Tool instructions",detail:`${p(n.toolSystem)} chars`,text:n.toolSystem});for(const e of n.messages||[])!e||!String(e.content||"").trim()||s.push({kind:e.role==="assistant"?"assistant":"user",at:o,title:e.role==="assistant"?"Assistant":"User",detail:"",text:String(e.content)});for(const e of n.context||[])s.push({kind:"context",at:o,title:e.title||e.kind||"Attached",detail:[e.url,e.chars?`${e.chars} chars`:"",e.deferred?"read on demand":"included"].filter(Boolean).join(" · "),data:e});return s}const p=n=>String(n||"").length;function y(n=[]){const o=new Map;for(const e of n){const a=e?.turnId||e?.payload?.turnId;a&&(o.has(a)||o.set(a,[]),o.get(a).push(e))}const s=[];for(const[e,a]of o){const r=a.find(u=>u.type==="turn.started"),t=a.find(u=>u.type==="turn.ended"),i=r?.payload||{},l=t?.payload||{},d=r?.at??a[0]?.at??0;s.push({turnId:e,at:d,sourceId:i.sourceId||null,surface:i.surface||i.kind||null,kind:i.kind||"chat",agentId:i.agentId||null,background:!!i.background,entries:h(a),turn:{startedAt:d,endedAt:t?.at??null,ms:l.ms??null,reason:l.reason||(t?"ok":"open"),cause:typeof l.cause=="string"?l.cause:null,error:l.error&&typeof l.error=="object"?{message:String(l.error.message||""),code:l.error.code??null}:null,kind:i.kind||"chat",surface:i.surface||null,sourceId:i.sourceId||null,model:l.model||null,provider:l.provider||null,tokensIn:l.tokensIn??null,tokensOut:l.tokensOut??null},calls:a.filter(u=>u.type==="capability.invoked")})}return s.sort((e,a)=>e.at-a.at),s}function O(n=[]){return g(y(n))}export{x as ENTRY_KINDS,h as buildTrajectory,k as displayName,A as filterEntries,w as groupRequests,M as lanesOf,$ as phasesOf,v as promptEntries,I as requestMetrics,S as threadTitle,O as threadTree,g as threadsOf,y as turnsOf};
|