mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
Merge pull request #880 from andrewyng/feat/sdk-session-tracing-ui
Add session tracing to the management UI
This commit is contained in:
@@ -160,6 +160,7 @@ fn authorized_search_timeline_summaries_revocation_and_separate_database_outage(
|
||||
},
|
||||
);
|
||||
let mut exec_sql = postgres::Client::connect(&execution, postgres::NoTls).unwrap();
|
||||
exec_sql.batch_execute("SET ow.runtime_schema='6'").unwrap();
|
||||
exec_sql.batch_execute(&format!("INSERT INTO {schema}.api_session_owners VALUES('s_alice','alice'),('s_empty','alice'),('s_bob','bob');UPDATE {schema}.submissions SET created='2026-01-01 00:00:00+00'" )).unwrap();
|
||||
let recording = config
|
||||
.observability
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {renderCompliance} from "./compliance.js";
|
||||
import {mountSessionTracing, serviceTracingAdapter} from "./tracing.js";
|
||||
import { mountObservability } from "./observability.js";
|
||||
let disposeObservability = null;
|
||||
let safetyActivity = null;
|
||||
@@ -559,12 +560,30 @@ async function render() {
|
||||
main.innerHTML = empty("Loading…");
|
||||
try {
|
||||
if (page === "observability") {
|
||||
disposeObservability = mountObservability(main, {
|
||||
request: (path, signal) =>
|
||||
api(path, "GET", undefined, undefined, signal),
|
||||
isAdmin: can.admin(),
|
||||
children: true,
|
||||
});
|
||||
const request = (path, signal) =>
|
||||
api(path, "GET", undefined, undefined, signal);
|
||||
const tracing = () => {
|
||||
disposeObservability?.();
|
||||
const view = mountSessionTracing(main, {
|
||||
adapter: serviceTracingAdapter(request),
|
||||
onOverview: overview,
|
||||
});
|
||||
disposeObservability = () => view.dispose();
|
||||
};
|
||||
const overview = () => {
|
||||
disposeObservability?.();
|
||||
disposeObservability = mountObservability(main, {
|
||||
request,
|
||||
isAdmin: can.admin(),
|
||||
children: true,
|
||||
});
|
||||
const back = document.createElement("button");
|
||||
back.className = "button";
|
||||
back.textContent = "← Session tracing";
|
||||
back.addEventListener("click", tracing);
|
||||
main.prepend(back);
|
||||
};
|
||||
tracing();
|
||||
return;
|
||||
}
|
||||
let html;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<meta name="color-scheme" content="light" />
|
||||
<title>OpenWorker · Management</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<link rel="stylesheet" href="tracing.css" />
|
||||
<script type="module" src="app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -0,0 +1,522 @@
|
||||
/* Optional, scoped session tracing styles. No runtime dependencies or global reset. */
|
||||
.ow-session-tracing {
|
||||
font:
|
||||
13px/1.5 -apple-system,
|
||||
BlinkMacSystemFont,
|
||||
"Segoe UI",
|
||||
sans-serif;
|
||||
color: #29313d;
|
||||
max-width: 1760px;
|
||||
margin: auto;
|
||||
--tr-border: #e2e7ee;
|
||||
--tr-muted: #8a96a6;
|
||||
background: #fafbfd;
|
||||
padding: 24px;
|
||||
}
|
||||
.ow-session-tracing * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.ow-session-tracing [hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
.ow-session-tracing button,
|
||||
.ow-session-tracing input {
|
||||
font: inherit;
|
||||
}
|
||||
.ow-session-tracing button {
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
background: white;
|
||||
border: 1px solid var(--tr-border);
|
||||
border-radius: 6px;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
.ow-session-tracing button:hover {
|
||||
background: #f1f5fa;
|
||||
}
|
||||
.ow-session-tracing button:focus-visible,
|
||||
.ow-session-tracing input:focus-visible {
|
||||
outline: 2px solid #6a8cbb;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.ow-session-tracing svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ow-session-tracing h1 {
|
||||
font-size: 27px;
|
||||
letter-spacing: -0.9px;
|
||||
margin: 0;
|
||||
}
|
||||
.ow-session-tracing h2 {
|
||||
font-size: 20px;
|
||||
letter-spacing: -0.55px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.ow-session-tracing p {
|
||||
margin: 5px 0;
|
||||
color: #8a96a6;
|
||||
}
|
||||
.tr-heading,
|
||||
.tr-heading > div:last-child {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.tr-heading {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.tr-heading > div:first-child {
|
||||
display: block;
|
||||
}
|
||||
.tr-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.tr-toolbar input {
|
||||
background: #fff;
|
||||
border: 1px solid var(--tr-border);
|
||||
border-radius: 7px;
|
||||
padding: 10px 14px;
|
||||
flex: 1;
|
||||
min-width: 160px;
|
||||
color: inherit;
|
||||
}
|
||||
.tr-directory-state {
|
||||
font-size: 10px;
|
||||
color: var(--tr-muted);
|
||||
}
|
||||
.tr-workbench {
|
||||
display: grid;
|
||||
grid-template-columns: 230px minmax(360px, 1.15fr) minmax(300px, 1fr);
|
||||
height: calc(100vh - 240px);
|
||||
min-height: 610px;
|
||||
border: 1px solid #dde4ed;
|
||||
border-radius: 11px;
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 18px #243a5510;
|
||||
}
|
||||
.tr-workbench > aside,
|
||||
.tr-workbench > section {
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.tr-workbench > section {
|
||||
border-left: 1px solid var(--tr-border);
|
||||
}
|
||||
.tr-directory {
|
||||
background: #f8fafd;
|
||||
}
|
||||
.tr-panehead {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background: #fff;
|
||||
height: 46px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 18px;
|
||||
border-bottom: 1px solid #edf0f4;
|
||||
font-size: 9px;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
color: #8b97a7;
|
||||
}
|
||||
.tr-directory .tr-panehead {
|
||||
background: #f8fafd;
|
||||
}
|
||||
.tr-results {
|
||||
padding: 9px;
|
||||
}
|
||||
.ow-session-tracing .tr-session {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: transparent;
|
||||
padding: 13px 11px;
|
||||
margin: 0 0 4px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 7px;
|
||||
}
|
||||
.ow-session-tracing .selected {
|
||||
background: #edf3fa !important;
|
||||
outline: 1px solid #dce6f2;
|
||||
outline-offset: -1px;
|
||||
}
|
||||
.ow-session-tracing .tr-session.selected {
|
||||
background: #fff !important;
|
||||
border: 1px solid #dce5f1;
|
||||
outline: 0;
|
||||
box-shadow: 0 1px 5px #243a550a;
|
||||
}
|
||||
.tr-session strong {
|
||||
display: block;
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.tr-session > span {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
font-size: 10px;
|
||||
color: #8692a3;
|
||||
}
|
||||
.tr-status {
|
||||
font-style: normal;
|
||||
}
|
||||
.tr-session code {
|
||||
font-size: 9px;
|
||||
color: #9aa6b6;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.tr-directory-footer {
|
||||
padding: 5px 18px;
|
||||
}
|
||||
.tr-directory-footer button {
|
||||
font-size: 11px;
|
||||
}
|
||||
.tr-segment {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
padding: 3px;
|
||||
background: #f0f3f8;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.ow-session-tracing .tr-segment button {
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 4px 8px;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
.ow-session-tracing .tr-segment button[aria-pressed="true"] {
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 4px #243a5515;
|
||||
}
|
||||
.tr-breadcrumb {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px;
|
||||
padding: 16px 20px 0;
|
||||
color: #9da7b5;
|
||||
font-size: 10px;
|
||||
}
|
||||
.ow-session-tracing .tr-breadcrumb button {
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: #6f88aa;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-breadcrumb strong {
|
||||
font-weight: 500;
|
||||
color: #67758a;
|
||||
}
|
||||
.tr-context > h2 {
|
||||
padding: 0 20px;
|
||||
}
|
||||
.tr-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
padding: 0 20px 18px;
|
||||
border-bottom: 1px solid #edf0f4;
|
||||
align-items: center;
|
||||
}
|
||||
.tr-chips span {
|
||||
font-size: 10px;
|
||||
background: #f0f4f9;
|
||||
border-radius: 4px;
|
||||
padding: 4px 7px;
|
||||
color: #708197;
|
||||
}
|
||||
.tr-chips code {
|
||||
font-size: 9px;
|
||||
color: #99a4b4;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.tr-turns {
|
||||
padding: 12px 14px 24px;
|
||||
}
|
||||
.ow-session-tracing .tr-turn-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 13px 4px;
|
||||
}
|
||||
.tr-turn-heading b {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.tr-turn-heading small {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: #9aa5b4;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.tr-chevron {
|
||||
color: #98a6b8;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.tr-chevron.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.tr-calls {
|
||||
padding: 4px 0 15px 24px;
|
||||
}
|
||||
.tr-turn-metrics {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding: 0 7px 12px;
|
||||
font-size: 9px;
|
||||
color: #99a5b5;
|
||||
}
|
||||
.ow-session-tracing .tr-step {
|
||||
width: 100%;
|
||||
min-height: 35px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: none;
|
||||
padding: 7px 6px;
|
||||
font-size: 11px;
|
||||
text-align: left;
|
||||
}
|
||||
.tr-step-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding-left: calc(var(--indent) * 12px);
|
||||
}
|
||||
.tr-step-name > span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tr-step svg {
|
||||
padding: 2px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 5px;
|
||||
background: #edf2f9;
|
||||
color: #7b98bc;
|
||||
}
|
||||
.tr-model svg {
|
||||
background: #f1edf8;
|
||||
color: #9b89bc;
|
||||
}
|
||||
.tr-tool svg {
|
||||
background: #edf4ef;
|
||||
color: #7d9e8a;
|
||||
}
|
||||
.tr-duration {
|
||||
font-size: 10px;
|
||||
color: #98a4b5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.tr-outcome {
|
||||
font-size: 9px;
|
||||
color: #8ba393;
|
||||
min-width: 25px;
|
||||
text-align: right;
|
||||
}
|
||||
.tr-axis {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-left: 165px;
|
||||
font-size: 9px;
|
||||
color: #9aa6b7;
|
||||
padding: 5px 0 12px;
|
||||
}
|
||||
.tr-waterfall .tr-step-name {
|
||||
flex: 0 0 165px;
|
||||
width: 165px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-track {
|
||||
position: relative;
|
||||
height: 22px;
|
||||
flex: 1;
|
||||
background: repeating-linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
transparent calc(25% - 1px),
|
||||
#edf1f6 calc(25% - 1px),
|
||||
#edf1f6 25%
|
||||
);
|
||||
}
|
||||
.tr-track i {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
height: 12px;
|
||||
min-width: 3px;
|
||||
border-radius: 3px;
|
||||
background: #99b0cc;
|
||||
}
|
||||
.tr-model .tr-track i {
|
||||
background: #b0a1ce;
|
||||
}
|
||||
.tr-tool .tr-track i {
|
||||
background: #91ad9c;
|
||||
}
|
||||
.tr-track i.tr-failed {
|
||||
background: #c08f86;
|
||||
}
|
||||
.tr-track small {
|
||||
font-size: 8px;
|
||||
color: #99a4b5;
|
||||
}
|
||||
.tr-children {
|
||||
padding: 8px 4px;
|
||||
}
|
||||
.tr-children > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin: 7px 0;
|
||||
}
|
||||
.tr-children span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.tr-children svg {
|
||||
color: #8aa2c2;
|
||||
}
|
||||
.tr-children small {
|
||||
font-size: 9px;
|
||||
color: #99a5b4;
|
||||
}
|
||||
.tr-children button {
|
||||
font-size: 10px;
|
||||
color: #718caf;
|
||||
background: #f6f9fc;
|
||||
}
|
||||
.tr-note,
|
||||
.tr-error {
|
||||
font-size: 11px;
|
||||
line-height: 1.7;
|
||||
padding: 10px;
|
||||
}
|
||||
.ow-session-tracing .tr-error {
|
||||
color: #b47c73;
|
||||
}
|
||||
.tr-detail-title {
|
||||
padding: 23px 22px 0;
|
||||
background: linear-gradient(145deg, #fff, #f9fbff);
|
||||
}
|
||||
.tr-detail-title > small {
|
||||
font-size: 9px;
|
||||
color: #8b99ad;
|
||||
letter-spacing: 0.8px;
|
||||
}
|
||||
.tr-detail-title .tr-chips {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
border: 0;
|
||||
}
|
||||
.tr-tabs {
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
padding: 0 22px;
|
||||
border-bottom: 1px solid var(--tr-border);
|
||||
}
|
||||
.ow-session-tracing .tr-tabs button {
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
padding: 12px 0;
|
||||
font-size: 11px;
|
||||
color: #99a3b2;
|
||||
}
|
||||
.ow-session-tracing .tr-tabs button[aria-pressed="true"] {
|
||||
border-bottom: 2px solid #6b8aad;
|
||||
color: #4c6c95;
|
||||
}
|
||||
.tr-detail-body {
|
||||
padding: 22px;
|
||||
}
|
||||
.tr-detail-body h3 {
|
||||
font-size: 11px;
|
||||
margin: 0 0 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.tr-empty,
|
||||
.tr-detail-body pre {
|
||||
font-size: 11px;
|
||||
line-height: 1.8;
|
||||
background: #f8fafd;
|
||||
padding: 15px;
|
||||
border: 1px solid #e6ecf4;
|
||||
border-radius: 6px;
|
||||
margin: 0 0 24px;
|
||||
color: #8998ad;
|
||||
}
|
||||
.tr-detail-body pre {
|
||||
font:
|
||||
10px/1.9 ui-monospace,
|
||||
SFMono-Regular,
|
||||
monospace;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
color: #557394;
|
||||
}
|
||||
.tr-detail-body dl {
|
||||
display: grid;
|
||||
grid-template-columns: 90px 1fr;
|
||||
gap: 12px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-detail-body dt {
|
||||
color: #99a5b4;
|
||||
}
|
||||
.tr-detail-body dd {
|
||||
margin: 0;
|
||||
color: #72849b;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@media (max-width: 1100px) {
|
||||
.tr-workbench {
|
||||
grid-template-columns: 190px minmax(300px, 1fr);
|
||||
height: auto;
|
||||
}
|
||||
.tr-inspector {
|
||||
grid-column: 1/-1;
|
||||
min-height: 300px;
|
||||
border-top: 1px solid var(--tr-border);
|
||||
}
|
||||
.tr-execution {
|
||||
min-height: 500px;
|
||||
}
|
||||
.tr-toolbar {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tr-chevron {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
import { esc, duration, count } from "./observability-data.js";
|
||||
const id = (s) => encodeURIComponent(s);
|
||||
const path = (q) =>
|
||||
`/v1/sessions/${id(q.sessionId)}/observability/${id(q.turnId)}`;
|
||||
/** Transport stays in the trusted application; the component never stores credentials. */
|
||||
export function serviceTracingAdapter(request) {
|
||||
const get = (p, signal) => request(p, signal);
|
||||
return {
|
||||
search: async (q, signal) =>
|
||||
get(
|
||||
"/v1/observability/runs?" +
|
||||
new URLSearchParams({
|
||||
q: q.q || "",
|
||||
limit: "25",
|
||||
...(q.after ? { after: q.after } : {}),
|
||||
}),
|
||||
signal,
|
||||
),
|
||||
// The existing run directory is authorized and cursor-bound. Exact matching is
|
||||
// essential: its text search can also match another session's partial ID.
|
||||
turns: async (q, signal) => {
|
||||
const p = await get(
|
||||
"/v1/observability/runs?" +
|
||||
new URLSearchParams({
|
||||
q: q.sessionId,
|
||||
limit: "100",
|
||||
...(q.after ? { after: q.after } : {}),
|
||||
}),
|
||||
signal,
|
||||
);
|
||||
return {
|
||||
turns: p.runs.filter((r) => r.session_id === q.sessionId),
|
||||
next_cursor: p.next_cursor,
|
||||
};
|
||||
},
|
||||
timeline: (q, signal) =>
|
||||
get(
|
||||
path(q) +
|
||||
"/timeline?" +
|
||||
new URLSearchParams({
|
||||
limit: "100",
|
||||
after: String(q.after ?? 0),
|
||||
...(q.through != null ? { through: String(q.through) } : {}),
|
||||
}),
|
||||
signal,
|
||||
),
|
||||
summary: (q, signal) => get(path(q) + "/summary", signal),
|
||||
children: (q, signal) => get(path(q) + "/children", signal),
|
||||
};
|
||||
}
|
||||
const svg = (kind) => {
|
||||
const shapes = {
|
||||
model: '<path d="m12 3 3 6 6 3-6 3-3 6-3-6-6-3 6-3Z"/>',
|
||||
tool: '<path d="m8 5-5 7 5 7M16 5l5 7-5 7M14 4l-4 16"/>',
|
||||
agent:
|
||||
'<rect x="4" y="5" width="16" height="14" rx="4"/><path d="M9 10h.01M15 10h.01M9 14h6M12 2v3"/>',
|
||||
chevron: '<path d="m9 5 7 7-7 7"/>',
|
||||
};
|
||||
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${shapes[kind] || shapes.agent}</svg>`;
|
||||
};
|
||||
const kind = (s) =>
|
||||
s.operation.startsWith("model.")
|
||||
? "model"
|
||||
: s.operation.startsWith("tool.")
|
||||
? "tool"
|
||||
: "agent";
|
||||
const name = (s) =>
|
||||
(s.tool && s.tool.replaceAll("__", " · ").replaceAll("_", " ")) ||
|
||||
(s.model && s.operation === "model.attempt" && `Model · ${s.model}`) ||
|
||||
{
|
||||
"agent.execute": "Execution segment",
|
||||
"model.requested": "Request started",
|
||||
"policy.review": "Policy check",
|
||||
"approval.wait": "Approval wait",
|
||||
"question.wait": "Question wait",
|
||||
"environment.operation": "Prepare environment",
|
||||
}[s.operation] ||
|
||||
s.operation;
|
||||
const key = (s) => s.trace_id + "/" + s.span_id;
|
||||
const reason = (e) =>
|
||||
e?.status === 403
|
||||
? "You cannot read this session."
|
||||
: e?.status === 404
|
||||
? "This recording is no longer available."
|
||||
: e?.status === 503
|
||||
? "Recording is disabled or unavailable."
|
||||
: e?.status === 429
|
||||
? "Recording readers are busy. Try Refresh."
|
||||
: "Unable to load recording. Try Refresh.";
|
||||
const button = (action, text, extra = "") =>
|
||||
`<button type="button" data-tr="${action}" ${extra}>${text}</button>`;
|
||||
const scope = (r) => ({ sessionId: r.session_id, turnId: r.turn_id });
|
||||
/** Session-oriented trace browser. No evaluations or combined team view. */
|
||||
export function mountSessionTracing(
|
||||
root,
|
||||
{ adapter, initialRun = null, onOverview } = {},
|
||||
) {
|
||||
if (!adapter) throw Error("A tracing adapter is required");
|
||||
const lifetime = new AbortController(),
|
||||
signal = lifetime.signal;
|
||||
let disposed = false,
|
||||
searchGen = 0,
|
||||
sessionGen = 0,
|
||||
detailGen = 0,
|
||||
timer;
|
||||
let results = [],
|
||||
nextSearch = null,
|
||||
searchText = "",
|
||||
session = null,
|
||||
turns = [],
|
||||
nextTurns = null,
|
||||
history = [],
|
||||
cache = new Map(),
|
||||
selected = null,
|
||||
details = null,
|
||||
mode = "tree",
|
||||
tab = "preview",
|
||||
pending = false;
|
||||
root.classList.add("ow-session-tracing");
|
||||
root.innerHTML = `<div class="tr-heading"><div><h1>Tracing</h1><p>Follow a session, one turn at a time.</p></div><div>${onOverview ? button("overview", "Usage overview ↗") : ""}${button("refresh", "Refresh")}</div></div><div class="tr-toolbar"><input type="search" aria-label="Search sessions" placeholder="Search session name or ID…" maxlength="200"><span class="tr-directory-state" role="status"></span></div><div class="tr-workbench"><aside class="tr-directory"><div class="tr-panehead">Sessions</div><div class="tr-results"></div><div class="tr-directory-footer"></div></aside><section class="tr-execution"><div class="tr-panehead"><span>Execution</span><div class="tr-segment" role="group" aria-label="Execution view">${button("tree", "Tree", 'aria-pressed="true"')}${button("waterfall", "Waterfall", 'aria-pressed="false"')}</div></div><div class="tr-context"></div><div class="tr-turns"></div></section><section class="tr-inspector"><div class="tr-panehead">Step details</div><div class="tr-details"></div></section></div>`;
|
||||
const $ = (s) => root.querySelector(s);
|
||||
const query = () => $(".tr-toolbar input").value;
|
||||
function sessions() {
|
||||
const map = new Map();
|
||||
for (const r of results)
|
||||
if (!map.has(r.session_id)) map.set(r.session_id, r);
|
||||
return [...map.values()];
|
||||
}
|
||||
function directory() {
|
||||
const rs = sessions();
|
||||
$(".tr-results").innerHTML =
|
||||
rs
|
||||
.map(
|
||||
(r) =>
|
||||
`<button class="tr-session ${session?.session_id === r.session_id ? "selected" : ""}" data-tr="session" data-tr-session="${esc(r.session_id)}"><strong>${esc(r.name || r.agent || r.session_id)}</strong><span><i class="tr-status">${esc(r.status || "Unknown")}</i><small>${r.created_ms ? esc(new Date(r.created_ms).toLocaleDateString()) : ""}</small></span><code>${esc(r.session_id)}</code></button>`,
|
||||
)
|
||||
.join("") ||
|
||||
'<p class="tr-note">No matching sessions on this page.</p>';
|
||||
$(".tr-directory-footer").innerHTML = nextSearch
|
||||
? button("more-search", "More sessions")
|
||||
: "";
|
||||
}
|
||||
async function search(more = false) {
|
||||
const gen = ++searchGen,
|
||||
q = searchText;
|
||||
$(".tr-directory-state").textContent = "Searching…";
|
||||
try {
|
||||
const page = await adapter.search(
|
||||
{ q, after: more ? nextSearch : undefined },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== searchGen) return;
|
||||
results = (more ? [...results, ...page.runs] : page.runs).slice(0, 1000);
|
||||
nextSearch = results.length < 1000 ? page.next_cursor : null;
|
||||
$(".tr-directory-state").textContent =
|
||||
`${sessions().length} sessions loaded${nextSearch ? " · more available" : ""}`;
|
||||
directory();
|
||||
if (!session && results.length) await openSession(results[0]);
|
||||
} catch (e) {
|
||||
if (disposed || gen !== searchGen) return;
|
||||
results = [];
|
||||
nextSearch = null;
|
||||
directory();
|
||||
$(".tr-directory-state").textContent = reason(e);
|
||||
}
|
||||
}
|
||||
function crumb() {
|
||||
return `<div class="tr-breadcrumb">${button("home", "Sessions")}${history.length ? `<span>›</span>${button("back", esc(history.at(-1).session.name || history.at(-1).session.agent || "Parent agent"))}<span>›</span>${button("back", esc(history.at(-1).parentTurn))}` : ""}<span>›</span><strong>${esc(session?.name || session?.agent || "Session")}</strong></div>`;
|
||||
}
|
||||
function context() {
|
||||
if (!session) return;
|
||||
$(".tr-context").innerHTML =
|
||||
crumb() +
|
||||
`<h2>${esc(session.name || session.agent || session.session_id)}</h2><div class="tr-chips"><span>${esc(session.status || "Unknown")}</span><span>${turns.length} ${turns.length === 1 ? "turn" : "turns"} loaded${nextTurns ? " · more available" : ""}</span><code>${esc(session.session_id)}</code></div>`;
|
||||
}
|
||||
const visibleSteps = (c) =>
|
||||
(c.steps || []).filter((s) => s.operation !== "model.requested");
|
||||
function body(t, c) {
|
||||
if (c.error) return `<p class="tr-error" role="status">${esc(c.error)}</p>`;
|
||||
if (c.loading)
|
||||
return '<p class="tr-note" role="status">Loading recording…</p>';
|
||||
const ss = visibleSteps(c),
|
||||
known = ss.filter(
|
||||
(s) => Number.isFinite(s.started_ms) && Number.isFinite(s.duration_us),
|
||||
),
|
||||
start = known.length ? Math.min(...known.map((s) => s.started_ms)) : 0,
|
||||
end = known.length
|
||||
? Math.max(...known.map((s) => s.started_ms + s.duration_us / 1000))
|
||||
: 1,
|
||||
range = Math.max(1, end - start),
|
||||
summary = c.summary;
|
||||
const total = summary?.usage;
|
||||
const tokens =
|
||||
total?.input?.total != null && total?.output?.total != null
|
||||
? `${count(total.input.total + total.output.total)}${total.input.unknown || total.output.unknown ? " + unknown" : ""}`
|
||||
: "Not reported";
|
||||
let html = `<div class="tr-turn-metrics"><span>${esc(duration(summary?.wall_elapsed_us))} elapsed</span><span>${tokens} tokens</span><span>${ss.length} steps loaded</span></div>`;
|
||||
if (mode === "waterfall")
|
||||
html += `<div class="tr-axis">${[0, 1, 2, 3, 4].map((i) => `<span>${i ? esc(duration(((range * i) / 4) * 1000)) : "0 s"}</span>`).join("")}</div>`;
|
||||
// Indentation follows recorded parent IDs only. Missing parents are roots;
|
||||
// cycles are bounded and labelled, never silently invented.
|
||||
const map = new Map(ss.map((s) => [key(s), s]));
|
||||
const depth = (s) => {
|
||||
let n = 0,
|
||||
p = s,
|
||||
seen = new Set([key(s)]);
|
||||
while (n < 6) {
|
||||
const parent = map.get(p.parent_trace_id + "/" + p.parent_span_id);
|
||||
if (!parent || seen.has(key(parent))) break;
|
||||
seen.add(key(parent));
|
||||
n++;
|
||||
p = parent;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
for (const s of ss) {
|
||||
const d = depth(s),
|
||||
k = kind(s),
|
||||
timing =
|
||||
Number.isFinite(s.started_ms) && Number.isFinite(s.duration_us);
|
||||
html += `<button class="tr-step tr-${k} ${selected?.step && key(selected.step) === key(s) ? "selected" : ""} ${mode === "waterfall" ? "tr-waterfall" : ""}" data-tr="step" data-turn="${esc(t.turn_id)}" data-step="${esc(key(s))}" data-depth="${d}"><span class="tr-step-name">${svg(k)}<span>${esc(name(s))}</span></span>${mode === "tree" ? `<span class="tr-duration">${esc(duration(s.duration_us))}</span>` : `<span class="tr-track">${timing ? `<i data-left="${Math.min(99, Math.max(0, ((s.started_ms - start) / range) * 100))}" data-width="${Math.min(100, (s.duration_us / 1000 / range) * 100)}" class="${s.outcome === "error" ? "tr-failed" : ""}"></i>` : "<small>Unknown timing</small>"}</span>`}<span class="tr-outcome ${s.outcome === "error" ? "tr-error" : ""}">${esc(s.outcome || "Unknown")}</span></button>`;
|
||||
}
|
||||
if (c.next != null)
|
||||
html +=
|
||||
c.steps.length < 1000
|
||||
? button(
|
||||
"more-steps",
|
||||
"Load more steps",
|
||||
`data-turn="${esc(t.turn_id)}"`,
|
||||
)
|
||||
: '<p class="tr-note">Showing 1,000 steps. Narrow the query through the SDK to inspect further records.</p>';
|
||||
if (!ss.length)
|
||||
html += '<p class="tr-note">No recorded steps for this turn.</p>';
|
||||
html += `<div class="tr-children">${(c.children || []).map((child, i) => `<div><span>${svg("agent")}${esc(child.agent_id)} <small>${esc(child.phase)}</small></span>${child.child_turn_id ? button("child", `Open session ↗`, `data-turn="${esc(t.turn_id)}" data-child="${i}" aria-label="Open ${esc(child.agent_id)} session"`) : "<small>Initial turn unavailable</small>"}</div>`).join("")}</div>`;
|
||||
if (c.childError)
|
||||
html +=
|
||||
'<p class="tr-note">Child links are unavailable for this turn.</p>';
|
||||
const cov = summary?.coverage;
|
||||
if (
|
||||
cov?.scan_truncated ||
|
||||
cov?.hierarchy_incomplete ||
|
||||
cov?.unknown_outcome_steps ||
|
||||
cov?.unknown_timing_steps
|
||||
)
|
||||
html +=
|
||||
'<p class="tr-note">Partial coverage: some timing, hierarchy or outcomes are incomplete. Recording is best effort.</p>';
|
||||
return html;
|
||||
}
|
||||
function render() {
|
||||
context();
|
||||
directory();
|
||||
$(".tr-turns").innerHTML =
|
||||
turns
|
||||
.map((t) => {
|
||||
const c = cache.get(t.turn_id);
|
||||
return `<section class="tr-turn"><button data-tr="turn" data-turn="${esc(t.turn_id)}" class="tr-turn-heading" aria-expanded="${!!c?.open}"><span class="tr-chevron ${c?.open ? "open" : ""}">${svg("chevron")}</span><span><b>${esc(t.label || "Turn · " + t.turn_id.slice(0, 14) + "…")}</b><small>${esc(t.status || "Status not reported")}</small></span></button>${c?.open ? `<div class="tr-calls">${body(t, c)}</div>` : ""}</section>`;
|
||||
})
|
||||
.join("") +
|
||||
(nextTurns != null ? button("more-turns", "Load more turns") : "") +
|
||||
(pending ? '<p class="tr-note" role="status">Loading turns…</p>' : "");
|
||||
root
|
||||
.querySelectorAll(".tr-segment button")
|
||||
.forEach((b) =>
|
||||
b.setAttribute("aria-pressed", String(b.dataset.tr === mode)),
|
||||
);
|
||||
for (const el of root.querySelectorAll("[data-depth]"))
|
||||
el.style.setProperty("--indent", el.dataset.depth);
|
||||
for (const el of root.querySelectorAll("[data-left]")) {
|
||||
el.style.left = el.dataset.left + "%";
|
||||
el.style.width = el.dataset.width + "%";
|
||||
}
|
||||
}
|
||||
async function loadTurns(more = false, target) {
|
||||
if (more && pending) return;
|
||||
const gen = sessionGen,
|
||||
sid = session.session_id;
|
||||
pending = true;
|
||||
render();
|
||||
try {
|
||||
const p = await adapter.turns(
|
||||
{ sessionId: sid, after: more ? nextTurns : undefined },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
const incoming = p.turns.filter((t) => t.session_id === sid);
|
||||
if (!more && incoming[0])
|
||||
session = { ...session, status: incoming[0].status };
|
||||
const unique = new Map(
|
||||
(more ? [...turns, ...incoming] : incoming).map((t) => [t.turn_id, t]),
|
||||
);
|
||||
turns = [...unique.values()];
|
||||
turns = turns.slice(0, 1000);
|
||||
nextTurns = turns.length < 1000 ? p.next_cursor : null;
|
||||
pending = false;
|
||||
if (target && !turns.some((t) => t.turn_id === target.turn_id))
|
||||
turns.unshift({ ...target, session_id: sid });
|
||||
render();
|
||||
if (!more && turns.length) {
|
||||
const t = turns.find((t) => t.turn_id === target?.turn_id) || turns[0];
|
||||
await loadTurn(t);
|
||||
}
|
||||
} catch (e) {
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
pending = false;
|
||||
turns = [];
|
||||
nextTurns = null;
|
||||
render();
|
||||
$(".tr-turns").innerHTML =
|
||||
`<p class="tr-error" role="status">${esc(reason(e))}</p>`;
|
||||
}
|
||||
}
|
||||
async function openSession(r, target) {
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
session = r;
|
||||
turns = [];
|
||||
cache = new Map();
|
||||
selected = null;
|
||||
details = null;
|
||||
nextTurns = null;
|
||||
$(".tr-details").innerHTML =
|
||||
'<p class="tr-note">Select a model or tool call.</p>';
|
||||
await loadTurns(false, target || r);
|
||||
}
|
||||
async function loadTurn(t, more = false) {
|
||||
const gen = sessionGen,
|
||||
old = cache.get(t.turn_id) || {},
|
||||
q = scope(t);
|
||||
const c = { ...old, open: true, loading: true };
|
||||
cache.set(t.turn_id, c);
|
||||
render();
|
||||
try {
|
||||
const [page, s, child] = await Promise.all([
|
||||
adapter.timeline(
|
||||
{
|
||||
...q,
|
||||
after: more ? old.next : undefined,
|
||||
through: more ? old.through : undefined,
|
||||
limit: 100,
|
||||
},
|
||||
signal,
|
||||
),
|
||||
more
|
||||
? Promise.resolve({ summary: old.summary })
|
||||
: adapter.summary(q, signal),
|
||||
more
|
||||
? Promise.resolve({ children: old.children })
|
||||
: adapter.children
|
||||
? adapter
|
||||
.children(q, signal)
|
||||
.catch(() => ({ children: [], unavailable: true }))
|
||||
: Promise.resolve({ children: [] }),
|
||||
]);
|
||||
if (disposed || gen !== sessionGen || cache.get(t.turn_id) !== c) return;
|
||||
const steps = [
|
||||
...(more ? old.steps || [] : []),
|
||||
...page.page.steps.map((x) => x.step),
|
||||
];
|
||||
Object.assign(c, {
|
||||
steps: steps.slice(0, 1000),
|
||||
next: page.page.next,
|
||||
through: page.page.through,
|
||||
summary: s.summary,
|
||||
children: child.children,
|
||||
childError: child.unavailable,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
render();
|
||||
} catch (e) {
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
Object.assign(c, {
|
||||
loading: false,
|
||||
error: reason(e),
|
||||
steps: [],
|
||||
children: [],
|
||||
});
|
||||
if (selected?.turn.turn_id === t.turn_id) {
|
||||
selected = null;
|
||||
details = null;
|
||||
detailGen++;
|
||||
$(".tr-details").innerHTML =
|
||||
'<p class="tr-note">Selected recording is unavailable.</p>';
|
||||
}
|
||||
render();
|
||||
}
|
||||
}
|
||||
function inspector() {
|
||||
const s = selected?.step;
|
||||
if (!s) return;
|
||||
const payload = (v) =>
|
||||
v === undefined || v === null
|
||||
? '<div class="tr-empty">Content was not captured or is not available to this viewer.</div>'
|
||||
: `<pre>${esc(typeof v === "string" ? v : JSON.stringify(v, null, 2))}</pre>`;
|
||||
$(".tr-details").innerHTML =
|
||||
`<div class="tr-detail-title"><small>${esc(s.operation)}</small><h2>${esc(name(s))}</h2><div class="tr-chips"><span>${esc(s.outcome)}</span><span>${esc(duration(s.duration_us))}</span></div></div><div class="tr-tabs" role="group" aria-label="Step detail view">${["preview", "attributes", "json"].map((x) => button(x, x === "json" ? "JSON" : x[0].toUpperCase() + x.slice(1), `aria-pressed="${tab === x}"`)).join("")}</div><div class="tr-detail-body">${
|
||||
tab === "json"
|
||||
? `<pre>${esc(JSON.stringify(s, null, 2))}</pre>`
|
||||
: tab === "attributes"
|
||||
? `<dl>${Object.entries(s)
|
||||
.filter(([, v]) => v != null)
|
||||
.map(
|
||||
([k, v]) =>
|
||||
`<dt>${esc(k)}</dt><dd>${esc(typeof v === "object" ? JSON.stringify(v) : v)}</dd>`,
|
||||
)
|
||||
.join("")}</dl>`
|
||||
: `<h3>Input</h3>${payload(details?.input)}<h3>Output</h3>${payload(details?.output)}${details?.error ? `<p class="tr-note">${esc(details.error)}</p>` : ""}<h3>Execution</h3><dl><dt>Duration</dt><dd>${esc(duration(s.duration_us))}</dd><dt>First output</dt><dd>${esc(duration(s.first_output_us))}</dd><dt>Model</dt><dd>${esc(s.model || "—")}</dd><dt>Token usage</dt><dd>${s.usage ? esc(JSON.stringify(s.usage)) : "Not reported"}</dd><dt>Span</dt><dd>${esc(s.span_id)}</dd></dl>`
|
||||
}</div>`;
|
||||
}
|
||||
async function select(t, s) {
|
||||
selected = { turn: t, step: s };
|
||||
details = null;
|
||||
tab = "preview";
|
||||
const gen = ++detailGen,
|
||||
sessionVersion = sessionGen;
|
||||
render();
|
||||
inspector();
|
||||
if (adapter.stepDetails) {
|
||||
try {
|
||||
const value = await adapter.stepDetails(
|
||||
{ ...scope(t), traceId: s.trace_id, spanId: s.span_id },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== detailGen || sessionVersion !== sessionGen)
|
||||
return;
|
||||
details = value;
|
||||
inspector();
|
||||
} catch (e) {
|
||||
if (!disposed && gen === detailGen) {
|
||||
details = { error: reason(e) };
|
||||
inspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function click(e) {
|
||||
const b = e.target.closest("button[data-tr]");
|
||||
if (!b || !root.contains(b)) return;
|
||||
const action = b.dataset.tr,
|
||||
t = turns.find((t) => t.turn_id === b.dataset.turn);
|
||||
if (action === "session") {
|
||||
history = [];
|
||||
await openSession(
|
||||
results.find((r) => r.session_id === b.dataset.trSession),
|
||||
);
|
||||
} else if (action === "turn") {
|
||||
const c = cache.get(t.turn_id);
|
||||
if (c?.open) {
|
||||
c.open = false;
|
||||
render();
|
||||
} else if (c?.steps) {
|
||||
c.open = true;
|
||||
render();
|
||||
} else await loadTurn(t);
|
||||
} else if (action === "more-steps") await loadTurn(t, true);
|
||||
else if (action === "step") {
|
||||
const s = cache
|
||||
.get(t.turn_id)
|
||||
?.steps.find((s) => key(s) === b.dataset.step);
|
||||
if (s) await select(t, s);
|
||||
} else if (action === "child") {
|
||||
const c = cache.get(t.turn_id).children[Number(b.dataset.child)];
|
||||
history.push({
|
||||
session,
|
||||
turns,
|
||||
nextTurns,
|
||||
cache,
|
||||
selected,
|
||||
details,
|
||||
tab,
|
||||
mode,
|
||||
parentTurn: t.label || "Turn · " + t.turn_id.slice(0, 14) + "…",
|
||||
scroll: $(".tr-execution").scrollTop,
|
||||
});
|
||||
await openSession(
|
||||
{
|
||||
session_id: c.child_session_id,
|
||||
turn_id: c.child_turn_id,
|
||||
name: c.agent_id,
|
||||
status: c.phase,
|
||||
},
|
||||
{ session_id: c.child_session_id, turn_id: c.child_turn_id },
|
||||
);
|
||||
$(".tr-execution").scrollTop = 0;
|
||||
} else if (action === "back") {
|
||||
const h = history.pop();
|
||||
if (h) {
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
({ session, turns, nextTurns, cache, selected, details, tab, mode } =
|
||||
h);
|
||||
pending = false;
|
||||
render();
|
||||
$(".tr-execution").scrollTop = h.scroll;
|
||||
inspector();
|
||||
}
|
||||
} else if (action === "home") {
|
||||
history = [];
|
||||
if (results[0]) await openSession(results[0]);
|
||||
} else if (["tree", "waterfall"].includes(action)) {
|
||||
mode = action;
|
||||
render();
|
||||
} else if (["preview", "attributes", "json"].includes(action)) {
|
||||
tab = action;
|
||||
inspector();
|
||||
} else if (action === "more-search") await search(true);
|
||||
else if (action === "more-turns") await loadTurns(true);
|
||||
else if (action === "refresh") {
|
||||
if (session) await openSession(session, selected?.turn);
|
||||
else await search();
|
||||
} else if (action === "overview") onOverview?.();
|
||||
}
|
||||
root.addEventListener("click", click, { signal });
|
||||
$(".tr-toolbar input").addEventListener(
|
||||
"input",
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
searchText = query();
|
||||
searchGen++;
|
||||
timer = setTimeout(() => search(), 250);
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
if (initialRun) openSession(initialRun);
|
||||
if (adapter.search) search();
|
||||
else $(".tr-toolbar").hidden = true;
|
||||
return {
|
||||
refresh: () => (session ? openSession(session) : search()),
|
||||
dispose() {
|
||||
disposed = true;
|
||||
searchGen++;
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
clearTimeout(timer);
|
||||
lifetime.abort();
|
||||
root.replaceChildren();
|
||||
root.classList.remove("ow-session-tracing");
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -486,6 +486,8 @@ export async function start(config) {
|
||||
"/index.html": ["index.html", "text/html"],
|
||||
"/app.js": ["app.js", "text/javascript"],
|
||||
"/compliance.js": ["compliance.js", "text/javascript"],
|
||||
"/tracing.js": ["tracing.js", "text/javascript"],
|
||||
"/tracing.css": ["tracing.css", "text/css"],
|
||||
"/observability.js": ["observability.js", "text/javascript"],
|
||||
"/observability-data.js": ["observability-data.js", "text/javascript"],
|
||||
"/style.css": ["style.css", "text/css"],
|
||||
|
||||
@@ -103,10 +103,33 @@ async function login(page, url, token) {
|
||||
await page.goto(url + "/#observability");
|
||||
await page.locator("#token").fill(token);
|
||||
await page.getByRole("button", { name: "Sign in", exact: true }).click();
|
||||
await page.locator("#obs-run-search").waitFor();
|
||||
await page.getByRole("searchbox", { name: "Search sessions" }).waitFor();
|
||||
if (url === app.url) {
|
||||
const search = page.getByRole("searchbox", { name: "Search sessions" });
|
||||
await search.fill("s_alice");
|
||||
await page
|
||||
.locator(".tr-session")
|
||||
.filter({ hasText: "s_alice" })
|
||||
.first()
|
||||
.click();
|
||||
await page.waitForFunction(
|
||||
() => document.querySelectorAll(".tr-turn").length === 2,
|
||||
);
|
||||
await page.locator(".tr-step").first().click();
|
||||
await page.getByRole("button", { name: "Waterfall", exact: true }).click();
|
||||
await page.locator(".tr-track").first().waitFor();
|
||||
await capture(page, "session-tracing");
|
||||
checks.push(
|
||||
"actual service session search, two turns, step details and waterfall",
|
||||
);
|
||||
}
|
||||
await page
|
||||
.getByRole("button", { name: "Usage overview ↗", exact: true })
|
||||
.click();
|
||||
await page.locator("[id$='-obs-run-search']").waitFor();
|
||||
}
|
||||
async function choose(page, text) {
|
||||
const input = page.locator("#obs-run-search");
|
||||
const input = page.locator("[id$='-obs-run-search']");
|
||||
await input.fill(text);
|
||||
const option = page
|
||||
.locator(".obs-run-option")
|
||||
@@ -165,12 +188,12 @@ try {
|
||||
await login(page, app.url, process.env.OW_UI_USER);
|
||||
await page.locator(".obs-stats").waitFor();
|
||||
assert(
|
||||
(await page.locator("#obs-scope").innerText()).includes(
|
||||
(await page.locator("[id$='-obs-scope']").innerText()).includes(
|
||||
"25 recent authorized runs",
|
||||
),
|
||||
);
|
||||
assert(!(await page.locator("#main").innerText()).includes("Beta Private"));
|
||||
assert.equal(await page.locator("#obs-health").count(), 0);
|
||||
assert.equal(await page.locator("[id$='-obs-health']").count(), 0);
|
||||
checks.push(
|
||||
"real scoped recent-page summary, no foreign runs or process counters",
|
||||
);
|
||||
@@ -185,7 +208,7 @@ try {
|
||||
.getByRole("button", { name: "Next 25 runs", exact: true })
|
||||
.waitFor();
|
||||
checks.push("summary page navigation preserves bounded selected-page scope");
|
||||
const input = page.locator("#obs-run-search");
|
||||
const input = page.locator("[id$='-obs-run-search']");
|
||||
await input.fill("Alpha % Game");
|
||||
await page
|
||||
.locator(".obs-run-option")
|
||||
@@ -197,9 +220,9 @@ try {
|
||||
await input.fill("No matching run 游");
|
||||
await page.getByText("No matching runs.", { exact: true }).waitFor();
|
||||
await input.fill("");
|
||||
await page.locator("#obs-search-more:not([hidden])").waitFor();
|
||||
await page.locator("[id$='-obs-search-more']:not([hidden])").waitFor();
|
||||
const firstCount = await page.locator(".obs-run-option").count();
|
||||
await page.locator("#obs-search-more").click();
|
||||
await page.locator("[id$='-obs-search-more']").click();
|
||||
await page.waitForFunction(
|
||||
(n) => document.querySelectorAll(".obs-run-option").length > n,
|
||||
firstCount,
|
||||
@@ -346,11 +369,13 @@ try {
|
||||
() =>
|
||||
document.querySelectorAll(".obs-stats").length === 0 &&
|
||||
/busy|Unable to/.test(
|
||||
document.querySelector("#obs-content").textContent,
|
||||
document.querySelector("[id$='-obs-content']").textContent,
|
||||
),
|
||||
);
|
||||
assert(
|
||||
!(await page.locator("#obs-content").innerText()).includes("12,500"),
|
||||
!(await page.locator("[id$='-obs-content']").innerText()).includes(
|
||||
"12,500",
|
||||
),
|
||||
);
|
||||
await page.unroute("**/api/v1/sessions/s_ui/observability/*/summary?**");
|
||||
await page.getByRole("button", { name: "Refresh", exact: true }).click();
|
||||
@@ -390,6 +415,9 @@ try {
|
||||
await page.locator('[data-nav="activity"]').click();
|
||||
await page.getByRole("heading", { name: "Sessions by day" }).waitFor();
|
||||
await page.locator('[data-nav="observability"]').click();
|
||||
await page
|
||||
.getByRole("button", { name: "Usage overview ↗", exact: true })
|
||||
.click();
|
||||
await page.locator(".obs-stats").waitFor();
|
||||
checks.push("Activity charts preserved; route return resets selection");
|
||||
const emptyPage = await browser.newPage();
|
||||
@@ -400,7 +428,7 @@ try {
|
||||
{ exact: true },
|
||||
)
|
||||
.waitFor();
|
||||
await emptyPage.locator("#obs-run-search").fill("Deployment");
|
||||
await emptyPage.locator("[id$='-obs-run-search']").fill("Deployment");
|
||||
await emptyPage
|
||||
.locator(".obs-run-option")
|
||||
.filter({ hasText: "Deployment diagnosis" })
|
||||
@@ -414,7 +442,7 @@ try {
|
||||
const adminPage = await browser.newPage();
|
||||
await login(adminPage, app.url, process.env.OW_UI_ADMIN);
|
||||
await adminPage.locator(".obs-stats").waitFor();
|
||||
await adminPage.locator("#obs-health summary").click();
|
||||
await adminPage.locator("[id$='-obs-health'] summary").click();
|
||||
await adminPage
|
||||
.getByText(
|
||||
"Serving API instance only. Worker and other API counters are not aggregated here.",
|
||||
@@ -442,7 +470,7 @@ try {
|
||||
.getByRole("button", { name: "Refresh", exact: true })
|
||||
.click();
|
||||
await revokedPage.locator("#login:not([hidden])").waitFor();
|
||||
assert.equal(await revokedPage.locator("#obs-content").count(), 0);
|
||||
assert.equal(await revokedPage.locator("[id$='-obs-content']").count(), 0);
|
||||
await revokedPage.close();
|
||||
checks.push("real service revocation signs out and erases metrics");
|
||||
assert.equal(
|
||||
|
||||
@@ -111,3 +111,44 @@ test("timeline retains parallel intervals and unknown duration markers", () => {
|
||||
}).some((s) => s.includes("4,096")),
|
||||
);
|
||||
});
|
||||
|
||||
test("session tracing transport preserves authorized cursors and exact scope", async () => {
|
||||
const { serviceTracingAdapter } = await import("../public/tracing.js");
|
||||
const paths = [];
|
||||
const controller = new AbortController();
|
||||
const adapter = serviceTracingAdapter(async (path, signal) => {
|
||||
paths.push(path);
|
||||
assert.equal(signal, controller.signal);
|
||||
return {
|
||||
runs: [
|
||||
{ session_id: "s_one", turn_id: "t1" },
|
||||
{ session_id: "s_one_more", turn_id: "t2" },
|
||||
],
|
||||
next_cursor: "bound_cursor",
|
||||
};
|
||||
});
|
||||
const page = await adapter.turns(
|
||||
{ sessionId: "s_one", after: "prior" },
|
||||
controller.signal,
|
||||
);
|
||||
assert.deepEqual(page.turns, [{ session_id: "s_one", turn_id: "t1" }]);
|
||||
assert.equal(page.next_cursor, "bound_cursor");
|
||||
const q = new URL(paths[0], "https://fixture").searchParams;
|
||||
assert.equal(q.get("q"), "s_one");
|
||||
assert.equal(q.get("after"), "prior");
|
||||
await adapter.timeline(
|
||||
{ sessionId: "s_one", turnId: "t1", after: 100, through: 450 },
|
||||
controller.signal,
|
||||
);
|
||||
const timeline = new URL(paths[1], "https://fixture");
|
||||
assert.equal(
|
||||
timeline.pathname,
|
||||
"/v1/sessions/s_one/observability/t1/timeline",
|
||||
);
|
||||
assert.equal(timeline.searchParams.get("through"), "450");
|
||||
await adapter.children(
|
||||
{ sessionId: "s_one", turnId: "t1" },
|
||||
controller.signal,
|
||||
);
|
||||
assert.equal(paths[2], "/v1/sessions/s_one/observability/t1/children");
|
||||
});
|
||||
|
||||
@@ -48,3 +48,64 @@ node test/browser.mjs http://127.0.0.1:59602 /absolute/path/to/playwright/index.
|
||||
|
||||
This checks keyboard tabs, exact child navigation, independent mounted instances,
|
||||
HTML escaping, disposal, and the 1,000-record pagination limit.
|
||||
|
||||
## Session tracing
|
||||
|
||||
The optional session browser adds paged session search, expandable turn lists,
|
||||
recorded hierarchy, a per-turn waterfall and a step inspector. A child link opens
|
||||
that child's session in the same pane. The breadcrumb restores the parent view.
|
||||
The browser does not merge child tool calls into a parent's turn.
|
||||
|
||||
```js
|
||||
import {mountSessionTracing, serviceTracingAdapter} from './src/index.js';
|
||||
import './src/tracing.css';
|
||||
|
||||
const viewer = mountSessionTracing(document.querySelector('#traces'), {
|
||||
adapter: serviceTracingAdapter(async (path, signal) => {
|
||||
const response = await fetch('/api' + path, {signal});
|
||||
if (!response.ok) throw Object.assign(new Error('Trace unavailable'), {
|
||||
status: response.status,
|
||||
});
|
||||
return response.json();
|
||||
}),
|
||||
});
|
||||
// On route change or logout: viewer.dispose().
|
||||
```
|
||||
|
||||
Your backend must authorize every request. The management UI uses its existing
|
||||
session cookie and read-only proxy. Service session turns are paged through the
|
||||
existing authorized run directory and filtered by exact session ID. Search results
|
||||
are deduplicated into sessions; counts describe only loaded records. Turn headings
|
||||
use stable IDs rather than inventing chronological turn numbers for partial pages.
|
||||
|
||||
For an embedded/managed SDK application, provide `adapter.turns` with
|
||||
`harness.observability.listTurns`, and the existing `timeline`, `summary` and
|
||||
`children` methods. Supply `initialRun` when your application already knows its
|
||||
session. Search is optional. Each mounted instance has independent state.
|
||||
|
||||
Content stays unavailable unless the trusted application supplies `stepDetails`
|
||||
for an exact `(sessionId, turnId, traceId, spanId)`. That function must enforce
|
||||
ownership and capture/redaction policy before returning `{input, output}`. The
|
||||
viewer does not scrape raw journals or infer payloads by matching tool names.
|
||||
Provider-private reasoning and rejected output must not be supplied. Errors in
|
||||
this optional callback do not affect agent execution.
|
||||
|
||||
Limits: 25 run rows per search page, 100 service run rows per turn-directory page,
|
||||
100 trace records per timeline page; 1,000 loaded search rows, turns and records
|
||||
per turn. Empty filtered pages can still have a next cursor. Waterfall bars use
|
||||
recorded timestamps, unknown durations remain unknown, and hierarchy depth is
|
||||
bounded. A session summary is not synthesized by adding overlapping child work.
|
||||
Evaluations and the combined team overview are outside this view.
|
||||
|
||||
Replay selected local OpenShell qualification metadata for review:
|
||||
|
||||
```sh
|
||||
node examples/serve-session.mjs /absolute/path/to/openshell-traces.json 59605
|
||||
node test/session-browser.mjs http://127.0.0.1:59605 /absolute/path/to/playwright/index.mjs /tmp/session-trace-screenshots
|
||||
```
|
||||
|
||||
The replay server is loopback-only, GET-only, serves explicit assets and the selected
|
||||
fixture, and is not a production API. Browser tests distinguish recorded data from
|
||||
injected race/denial fixtures. The real API/browser qualification lives in
|
||||
`harness/service-ui/test/observability-live.mjs`, launched by the Rust
|
||||
`recording_queries` integration test with `OW_OBSERVABILITY_UI_BROWSER=1`.
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// Replay explicitly selected, metadata-only qualification snapshots on loopback.
|
||||
// This is a review fixture, not a replacement for authenticated application APIs.
|
||||
import { createServer } from "node:http";
|
||||
import { readFile } from "node:fs/promises";
|
||||
const [file, port = "59605"] = process.argv.slice(2);
|
||||
if (!file)
|
||||
throw Error(
|
||||
"Usage: node examples/serve-session.mjs OPENSHELL_TRACE_JSON [PORT]",
|
||||
);
|
||||
const data = JSON.parse(await readFile(file, "utf8"));
|
||||
const traces = [
|
||||
{
|
||||
timeline: data.timeline,
|
||||
summary: data.summary,
|
||||
children: data.children?.children || [],
|
||||
},
|
||||
...(data.childTraces || []),
|
||||
];
|
||||
const records = traces.map((t) => ({ ...t.timeline.run, ...t.summary.run }));
|
||||
const assets = new Map([
|
||||
["/", new URL("session.html", import.meta.url)],
|
||||
...["tracing.js", "tracing.css", "observability-data.js"].map((f) => [
|
||||
"/src/" + f,
|
||||
new URL("../src/" + f, import.meta.url),
|
||||
]),
|
||||
]);
|
||||
const types = { js: "text/javascript", css: "text/css", html: "text/html" };
|
||||
createServer(async (req, res) => {
|
||||
try {
|
||||
const u = new URL(req.url, "http://loopback");
|
||||
if (req.method !== "GET") {
|
||||
res.writeHead(405);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
res.setHeader("cache-control", "no-store");
|
||||
if (assets.has(u.pathname)) {
|
||||
res.setHeader(
|
||||
"content-type",
|
||||
types[u.pathname === "/" ? "html" : u.pathname.split(".").pop()],
|
||||
);
|
||||
res.end(await readFile(assets.get(u.pathname)));
|
||||
return;
|
||||
}
|
||||
let value;
|
||||
if (u.pathname === "/api/v1/observability/runs") {
|
||||
const q = (u.searchParams.get("q") || "").toLowerCase();
|
||||
const filtered = records.filter((r) =>
|
||||
`${r.name} ${r.session_id} ${r.turn_id}`.toLowerCase().includes(q),
|
||||
);
|
||||
const offset = Number(u.searchParams.get("after") || 0),
|
||||
limit = Number(u.searchParams.get("limit") || 25);
|
||||
if (
|
||||
!Number.isSafeInteger(offset) ||
|
||||
offset < 0 ||
|
||||
!Number.isInteger(limit) ||
|
||||
limit < 1 ||
|
||||
limit > 100
|
||||
)
|
||||
throw Error("Invalid page");
|
||||
value = {
|
||||
runs: filtered.slice(offset, offset + limit),
|
||||
next_cursor:
|
||||
offset + limit < filtered.length ? String(offset + limit) : null,
|
||||
};
|
||||
} else {
|
||||
const m =
|
||||
/^\/api\/v1\/sessions\/([^/]+)\/observability\/([^/]+)\/(timeline|summary|children)$/.exec(
|
||||
u.pathname,
|
||||
);
|
||||
const t =
|
||||
m &&
|
||||
traces.find(
|
||||
(t) =>
|
||||
t.timeline.run.session_id === m[1] &&
|
||||
t.timeline.run.turn_id === m[2],
|
||||
);
|
||||
if (!t) {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
if (m[3] === "timeline") {
|
||||
const after = Number(u.searchParams.get("after") || 0),
|
||||
through = Number(
|
||||
u.searchParams.get("through") || Number.MAX_SAFE_INTEGER,
|
||||
);
|
||||
const all = t.timeline.page.steps.filter(
|
||||
(s) => s.cursor > after && s.cursor <= through,
|
||||
);
|
||||
value = {
|
||||
...t.timeline,
|
||||
page: {
|
||||
steps: all.slice(0, 100),
|
||||
next: all.length > 100 ? all[99].cursor : null,
|
||||
through: t.timeline.page.through,
|
||||
},
|
||||
};
|
||||
} else
|
||||
value =
|
||||
m[3] === "children" ? { children: t.children || [] } : t.summary;
|
||||
}
|
||||
res.setHeader("content-type", "application/json");
|
||||
res.end(JSON.stringify(value));
|
||||
} catch {
|
||||
res.writeHead(400);
|
||||
res.end("Invalid fixture request");
|
||||
}
|
||||
}).listen(Number(port), "127.0.0.1", () =>
|
||||
console.log(`Session tracing: http://127.0.0.1:${port}/`),
|
||||
);
|
||||
@@ -3,7 +3,7 @@ import {createServer} from 'node:http';
|
||||
import {readFile} from 'node:fs/promises';
|
||||
const [evidence,port='59602']=process.argv.slice(2);
|
||||
if(!evidence)throw Error('Usage: node examples/serve.mjs EVIDENCE_JSON [PORT]');
|
||||
const files=new Map([['/',new URL('index.html',import.meta.url)],...['index.js','observability.js','observability-data.js','style.css'].map(f=>[`/src/${f}`,new URL(`../src/${f}`,import.meta.url)])]);
|
||||
const files=new Map([['/',new URL('index.html',import.meta.url)],...['index.js','observability.js','observability-data.js','style.css','tracing.js','tracing.css'].map(f=>[`/src/${f}`,new URL(`../src/${f}`,import.meta.url)])]);
|
||||
const types={js:'text/javascript',html:'text/html',css:'text/css',json:'application/json'};
|
||||
createServer(async(req,res)=>{
|
||||
try {const path=new URL(req.url,'http://local').pathname;const file=path==='/trace.json'?evidence:files.get(path);if(!file){res.writeHead(404);res.end();return;}const body=await readFile(file);res.writeHead(200,{'content-type':path==='/'?'text/html':types[path.split('.').pop()]??'text/plain','cache-control':'no-store'});res.end(body);}catch{res.writeHead(500);res.end('Unavailable');}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<meta charset="utf-8" /><meta
|
||||
name="viewport"
|
||||
content="width=device-width,initial-scale=1"
|
||||
/><title>OpenWorker · Session tracing</title
|
||||
><link rel="stylesheet" href="/src/tracing.css" /><style>
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafbfd;
|
||||
}
|
||||
header {
|
||||
padding: 20px 28px;
|
||||
border-bottom: 1px solid #e5eaf1;
|
||||
background: #fff;
|
||||
font:
|
||||
13px -apple-system,
|
||||
BlinkMacSystemFont,
|
||||
sans-serif;
|
||||
color: #8090a5;
|
||||
}
|
||||
header strong {
|
||||
color: #293544;
|
||||
font-size: 17px;
|
||||
letter-spacing: -0.5px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
#preview-note {
|
||||
font-size: 11px;
|
||||
margin-left: 16px;
|
||||
}
|
||||
</style>
|
||||
<header>
|
||||
<strong>OpenWorker</strong>Session tracing<span id="preview-note"
|
||||
>Recorded local OpenShell qualification · deterministic model</span
|
||||
>
|
||||
</header>
|
||||
<main id="trace"></main>
|
||||
<script type="module">
|
||||
import {
|
||||
mountSessionTracing,
|
||||
serviceTracingAdapter,
|
||||
} from "/src/tracing.js";
|
||||
const request = async (path, signal) => {
|
||||
const r = await fetch("/api" + path, { signal });
|
||||
if (!r.ok)
|
||||
throw Object.assign(Error("Request failed"), { status: r.status });
|
||||
return r.json();
|
||||
};
|
||||
window.traceView = mountSessionTracing(document.querySelector("#trace"), {
|
||||
adapter: serviceTracingAdapter(request),
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
@@ -9,7 +9,8 @@
|
||||
"types": "./src/index.d.ts",
|
||||
"import": "./src/index.js"
|
||||
},
|
||||
"./style.css": "./src/style.css"
|
||||
"./style.css": "./src/style.css",
|
||||
"./tracing.css": "./src/tracing.css"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
|
||||
Vendored
+107
-8
@@ -1,10 +1,109 @@
|
||||
export interface TraceAdapter {
|
||||
timeline(query: {sessionId:string;turnId:string;after?:number;through?:number;limit?:number}): Promise<unknown>;
|
||||
summary(query: {sessionId:string;turnId:string;through?:number}): Promise<unknown>;
|
||||
children?(query: {sessionId:string;turnId:string}): Promise<unknown>;
|
||||
subtreeSummary?(query: {sessionId:string;turnId:string}): Promise<unknown>;
|
||||
evaluations?(query: {sessionId:string;turnId:string;limit?:number}): Promise<unknown>;
|
||||
timeline(query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
after?: number;
|
||||
through?: number;
|
||||
limit?: number;
|
||||
}): Promise<unknown>;
|
||||
summary(query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
through?: number;
|
||||
}): Promise<unknown>;
|
||||
children?(query: { sessionId: string; turnId: string }): Promise<unknown>;
|
||||
subtreeSummary?(query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
}): Promise<unknown>;
|
||||
evaluations?(query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
limit?: number;
|
||||
}): Promise<unknown>;
|
||||
}
|
||||
export interface ChildLink {child_session_id:string;child_turn_id:string|null;agent_id:string;phase:string}
|
||||
export function mountTurnTrace(root:HTMLElement, options:{adapter:TraceAdapter;sessionId:string;turnId:string;onChild?:(child:ChildLink)=>void}): {refresh():void;dispose():void};
|
||||
export function mountObservability(root:HTMLElement, options:{request:(path:string,signal?:AbortSignal)=>Promise<any>;isAdmin?:boolean;initialRun?:{session_id:string;turn_id:string}|null;directory?:boolean;openSession?:boolean;children?:boolean}):()=>void;
|
||||
export interface ChildLink {
|
||||
child_session_id: string;
|
||||
child_turn_id: string | null;
|
||||
agent_id: string;
|
||||
phase: string;
|
||||
}
|
||||
export function mountTurnTrace(
|
||||
root: HTMLElement,
|
||||
options: {
|
||||
adapter: TraceAdapter;
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
onChild?: (child: ChildLink) => void;
|
||||
},
|
||||
): { refresh(): void; dispose(): void };
|
||||
export function mountObservability(
|
||||
root: HTMLElement,
|
||||
options: {
|
||||
request: (path: string, signal?: AbortSignal) => Promise<any>;
|
||||
isAdmin?: boolean;
|
||||
initialRun?: { session_id: string; turn_id: string } | null;
|
||||
directory?: boolean;
|
||||
openSession?: boolean;
|
||||
children?: boolean;
|
||||
},
|
||||
): () => void;
|
||||
|
||||
export interface SessionTracingAdapter {
|
||||
search?(
|
||||
query: { q?: string; after?: string },
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ runs: TraceRun[]; next_cursor: string | null }>;
|
||||
turns(
|
||||
query: { sessionId: string; after?: string | number },
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ turns: TraceRun[]; next_cursor: string | number | null }>;
|
||||
timeline(
|
||||
query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
after?: number;
|
||||
through?: number;
|
||||
limit?: number;
|
||||
},
|
||||
signal?: AbortSignal,
|
||||
): Promise<any>;
|
||||
summary(
|
||||
query: { sessionId: string; turnId: string },
|
||||
signal?: AbortSignal,
|
||||
): Promise<any>;
|
||||
children?(
|
||||
query: { sessionId: string; turnId: string },
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ children: any[] }>;
|
||||
/** Backend-authorized, explicitly captured payloads, correlated to this exact span. */
|
||||
stepDetails?(
|
||||
query: {
|
||||
sessionId: string;
|
||||
turnId: string;
|
||||
traceId: string;
|
||||
spanId: string;
|
||||
},
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ input?: unknown; output?: unknown }>;
|
||||
}
|
||||
export interface TraceRun {
|
||||
session_id: string;
|
||||
turn_id: string;
|
||||
name?: string;
|
||||
agent?: string;
|
||||
status?: string;
|
||||
created_ms?: number;
|
||||
label?: string;
|
||||
}
|
||||
export function mountSessionTracing(
|
||||
root: HTMLElement,
|
||||
options: {
|
||||
adapter: SessionTracingAdapter;
|
||||
initialRun?: TraceRun;
|
||||
onOverview?: () => void;
|
||||
},
|
||||
): { refresh(): Promise<void>; dispose(): void };
|
||||
export function serviceTracingAdapter(
|
||||
request: (path: string, signal?: AbortSignal) => Promise<any>,
|
||||
): SessionTracingAdapter;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export {mountSessionTracing, serviceTracingAdapter} from './tracing.js';
|
||||
import {mountObservability} from './observability.js';
|
||||
import {count, measurement} from './observability-data.js';
|
||||
export {mountObservability};
|
||||
|
||||
@@ -0,0 +1,522 @@
|
||||
/* Optional, scoped session tracing styles. No runtime dependencies or global reset. */
|
||||
.ow-session-tracing {
|
||||
font:
|
||||
13px/1.5 -apple-system,
|
||||
BlinkMacSystemFont,
|
||||
"Segoe UI",
|
||||
sans-serif;
|
||||
color: #29313d;
|
||||
max-width: 1760px;
|
||||
margin: auto;
|
||||
--tr-border: #e2e7ee;
|
||||
--tr-muted: #8a96a6;
|
||||
background: #fafbfd;
|
||||
padding: 24px;
|
||||
}
|
||||
.ow-session-tracing * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.ow-session-tracing [hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
.ow-session-tracing button,
|
||||
.ow-session-tracing input {
|
||||
font: inherit;
|
||||
}
|
||||
.ow-session-tracing button {
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
background: white;
|
||||
border: 1px solid var(--tr-border);
|
||||
border-radius: 6px;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
.ow-session-tracing button:hover {
|
||||
background: #f1f5fa;
|
||||
}
|
||||
.ow-session-tracing button:focus-visible,
|
||||
.ow-session-tracing input:focus-visible {
|
||||
outline: 2px solid #6a8cbb;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.ow-session-tracing svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ow-session-tracing h1 {
|
||||
font-size: 27px;
|
||||
letter-spacing: -0.9px;
|
||||
margin: 0;
|
||||
}
|
||||
.ow-session-tracing h2 {
|
||||
font-size: 20px;
|
||||
letter-spacing: -0.55px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.ow-session-tracing p {
|
||||
margin: 5px 0;
|
||||
color: #8a96a6;
|
||||
}
|
||||
.tr-heading,
|
||||
.tr-heading > div:last-child {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.tr-heading {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.tr-heading > div:first-child {
|
||||
display: block;
|
||||
}
|
||||
.tr-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.tr-toolbar input {
|
||||
background: #fff;
|
||||
border: 1px solid var(--tr-border);
|
||||
border-radius: 7px;
|
||||
padding: 10px 14px;
|
||||
flex: 1;
|
||||
min-width: 160px;
|
||||
color: inherit;
|
||||
}
|
||||
.tr-directory-state {
|
||||
font-size: 10px;
|
||||
color: var(--tr-muted);
|
||||
}
|
||||
.tr-workbench {
|
||||
display: grid;
|
||||
grid-template-columns: 230px minmax(360px, 1.15fr) minmax(300px, 1fr);
|
||||
height: calc(100vh - 240px);
|
||||
min-height: 610px;
|
||||
border: 1px solid #dde4ed;
|
||||
border-radius: 11px;
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 18px #243a5510;
|
||||
}
|
||||
.tr-workbench > aside,
|
||||
.tr-workbench > section {
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.tr-workbench > section {
|
||||
border-left: 1px solid var(--tr-border);
|
||||
}
|
||||
.tr-directory {
|
||||
background: #f8fafd;
|
||||
}
|
||||
.tr-panehead {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background: #fff;
|
||||
height: 46px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 18px;
|
||||
border-bottom: 1px solid #edf0f4;
|
||||
font-size: 9px;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
color: #8b97a7;
|
||||
}
|
||||
.tr-directory .tr-panehead {
|
||||
background: #f8fafd;
|
||||
}
|
||||
.tr-results {
|
||||
padding: 9px;
|
||||
}
|
||||
.ow-session-tracing .tr-session {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: transparent;
|
||||
padding: 13px 11px;
|
||||
margin: 0 0 4px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 7px;
|
||||
}
|
||||
.ow-session-tracing .selected {
|
||||
background: #edf3fa !important;
|
||||
outline: 1px solid #dce6f2;
|
||||
outline-offset: -1px;
|
||||
}
|
||||
.ow-session-tracing .tr-session.selected {
|
||||
background: #fff !important;
|
||||
border: 1px solid #dce5f1;
|
||||
outline: 0;
|
||||
box-shadow: 0 1px 5px #243a550a;
|
||||
}
|
||||
.tr-session strong {
|
||||
display: block;
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.tr-session > span {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
font-size: 10px;
|
||||
color: #8692a3;
|
||||
}
|
||||
.tr-status {
|
||||
font-style: normal;
|
||||
}
|
||||
.tr-session code {
|
||||
font-size: 9px;
|
||||
color: #9aa6b6;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.tr-directory-footer {
|
||||
padding: 5px 18px;
|
||||
}
|
||||
.tr-directory-footer button {
|
||||
font-size: 11px;
|
||||
}
|
||||
.tr-segment {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
padding: 3px;
|
||||
background: #f0f3f8;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.ow-session-tracing .tr-segment button {
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 4px 8px;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
.ow-session-tracing .tr-segment button[aria-pressed="true"] {
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 4px #243a5515;
|
||||
}
|
||||
.tr-breadcrumb {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px;
|
||||
padding: 16px 20px 0;
|
||||
color: #9da7b5;
|
||||
font-size: 10px;
|
||||
}
|
||||
.ow-session-tracing .tr-breadcrumb button {
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: #6f88aa;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-breadcrumb strong {
|
||||
font-weight: 500;
|
||||
color: #67758a;
|
||||
}
|
||||
.tr-context > h2 {
|
||||
padding: 0 20px;
|
||||
}
|
||||
.tr-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
padding: 0 20px 18px;
|
||||
border-bottom: 1px solid #edf0f4;
|
||||
align-items: center;
|
||||
}
|
||||
.tr-chips span {
|
||||
font-size: 10px;
|
||||
background: #f0f4f9;
|
||||
border-radius: 4px;
|
||||
padding: 4px 7px;
|
||||
color: #708197;
|
||||
}
|
||||
.tr-chips code {
|
||||
font-size: 9px;
|
||||
color: #99a4b4;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.tr-turns {
|
||||
padding: 12px 14px 24px;
|
||||
}
|
||||
.ow-session-tracing .tr-turn-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: 0;
|
||||
padding: 13px 4px;
|
||||
}
|
||||
.tr-turn-heading b {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.tr-turn-heading small {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: #9aa5b4;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.tr-chevron {
|
||||
color: #98a6b8;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.tr-chevron.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.tr-calls {
|
||||
padding: 4px 0 15px 24px;
|
||||
}
|
||||
.tr-turn-metrics {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding: 0 7px 12px;
|
||||
font-size: 9px;
|
||||
color: #99a5b5;
|
||||
}
|
||||
.ow-session-tracing .tr-step {
|
||||
width: 100%;
|
||||
min-height: 35px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: none;
|
||||
padding: 7px 6px;
|
||||
font-size: 11px;
|
||||
text-align: left;
|
||||
}
|
||||
.tr-step-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding-left: calc(var(--indent) * 12px);
|
||||
}
|
||||
.tr-step-name > span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tr-step svg {
|
||||
padding: 2px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 5px;
|
||||
background: #edf2f9;
|
||||
color: #7b98bc;
|
||||
}
|
||||
.tr-model svg {
|
||||
background: #f1edf8;
|
||||
color: #9b89bc;
|
||||
}
|
||||
.tr-tool svg {
|
||||
background: #edf4ef;
|
||||
color: #7d9e8a;
|
||||
}
|
||||
.tr-duration {
|
||||
font-size: 10px;
|
||||
color: #98a4b5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.tr-outcome {
|
||||
font-size: 9px;
|
||||
color: #8ba393;
|
||||
min-width: 25px;
|
||||
text-align: right;
|
||||
}
|
||||
.tr-axis {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-left: 165px;
|
||||
font-size: 9px;
|
||||
color: #9aa6b7;
|
||||
padding: 5px 0 12px;
|
||||
}
|
||||
.tr-waterfall .tr-step-name {
|
||||
flex: 0 0 165px;
|
||||
width: 165px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-track {
|
||||
position: relative;
|
||||
height: 22px;
|
||||
flex: 1;
|
||||
background: repeating-linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
transparent calc(25% - 1px),
|
||||
#edf1f6 calc(25% - 1px),
|
||||
#edf1f6 25%
|
||||
);
|
||||
}
|
||||
.tr-track i {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
height: 12px;
|
||||
min-width: 3px;
|
||||
border-radius: 3px;
|
||||
background: #99b0cc;
|
||||
}
|
||||
.tr-model .tr-track i {
|
||||
background: #b0a1ce;
|
||||
}
|
||||
.tr-tool .tr-track i {
|
||||
background: #91ad9c;
|
||||
}
|
||||
.tr-track i.tr-failed {
|
||||
background: #c08f86;
|
||||
}
|
||||
.tr-track small {
|
||||
font-size: 8px;
|
||||
color: #99a4b5;
|
||||
}
|
||||
.tr-children {
|
||||
padding: 8px 4px;
|
||||
}
|
||||
.tr-children > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin: 7px 0;
|
||||
}
|
||||
.tr-children span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.tr-children svg {
|
||||
color: #8aa2c2;
|
||||
}
|
||||
.tr-children small {
|
||||
font-size: 9px;
|
||||
color: #99a5b4;
|
||||
}
|
||||
.tr-children button {
|
||||
font-size: 10px;
|
||||
color: #718caf;
|
||||
background: #f6f9fc;
|
||||
}
|
||||
.tr-note,
|
||||
.tr-error {
|
||||
font-size: 11px;
|
||||
line-height: 1.7;
|
||||
padding: 10px;
|
||||
}
|
||||
.ow-session-tracing .tr-error {
|
||||
color: #b47c73;
|
||||
}
|
||||
.tr-detail-title {
|
||||
padding: 23px 22px 0;
|
||||
background: linear-gradient(145deg, #fff, #f9fbff);
|
||||
}
|
||||
.tr-detail-title > small {
|
||||
font-size: 9px;
|
||||
color: #8b99ad;
|
||||
letter-spacing: 0.8px;
|
||||
}
|
||||
.tr-detail-title .tr-chips {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
border: 0;
|
||||
}
|
||||
.tr-tabs {
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
padding: 0 22px;
|
||||
border-bottom: 1px solid var(--tr-border);
|
||||
}
|
||||
.ow-session-tracing .tr-tabs button {
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
padding: 12px 0;
|
||||
font-size: 11px;
|
||||
color: #99a3b2;
|
||||
}
|
||||
.ow-session-tracing .tr-tabs button[aria-pressed="true"] {
|
||||
border-bottom: 2px solid #6b8aad;
|
||||
color: #4c6c95;
|
||||
}
|
||||
.tr-detail-body {
|
||||
padding: 22px;
|
||||
}
|
||||
.tr-detail-body h3 {
|
||||
font-size: 11px;
|
||||
margin: 0 0 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.tr-empty,
|
||||
.tr-detail-body pre {
|
||||
font-size: 11px;
|
||||
line-height: 1.8;
|
||||
background: #f8fafd;
|
||||
padding: 15px;
|
||||
border: 1px solid #e6ecf4;
|
||||
border-radius: 6px;
|
||||
margin: 0 0 24px;
|
||||
color: #8998ad;
|
||||
}
|
||||
.tr-detail-body pre {
|
||||
font:
|
||||
10px/1.9 ui-monospace,
|
||||
SFMono-Regular,
|
||||
monospace;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
color: #557394;
|
||||
}
|
||||
.tr-detail-body dl {
|
||||
display: grid;
|
||||
grid-template-columns: 90px 1fr;
|
||||
gap: 12px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.tr-detail-body dt {
|
||||
color: #99a5b4;
|
||||
}
|
||||
.tr-detail-body dd {
|
||||
margin: 0;
|
||||
color: #72849b;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@media (max-width: 1100px) {
|
||||
.tr-workbench {
|
||||
grid-template-columns: 190px minmax(300px, 1fr);
|
||||
height: auto;
|
||||
}
|
||||
.tr-inspector {
|
||||
grid-column: 1/-1;
|
||||
min-height: 300px;
|
||||
border-top: 1px solid var(--tr-border);
|
||||
}
|
||||
.tr-execution {
|
||||
min-height: 500px;
|
||||
}
|
||||
.tr-toolbar {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.tr-chevron {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
import { esc, duration, count } from "./observability-data.js";
|
||||
const id = (s) => encodeURIComponent(s);
|
||||
const path = (q) =>
|
||||
`/v1/sessions/${id(q.sessionId)}/observability/${id(q.turnId)}`;
|
||||
/** Transport stays in the trusted application; the component never stores credentials. */
|
||||
export function serviceTracingAdapter(request) {
|
||||
const get = (p, signal) => request(p, signal);
|
||||
return {
|
||||
search: async (q, signal) =>
|
||||
get(
|
||||
"/v1/observability/runs?" +
|
||||
new URLSearchParams({
|
||||
q: q.q || "",
|
||||
limit: "25",
|
||||
...(q.after ? { after: q.after } : {}),
|
||||
}),
|
||||
signal,
|
||||
),
|
||||
// The existing run directory is authorized and cursor-bound. Exact matching is
|
||||
// essential: its text search can also match another session's partial ID.
|
||||
turns: async (q, signal) => {
|
||||
const p = await get(
|
||||
"/v1/observability/runs?" +
|
||||
new URLSearchParams({
|
||||
q: q.sessionId,
|
||||
limit: "100",
|
||||
...(q.after ? { after: q.after } : {}),
|
||||
}),
|
||||
signal,
|
||||
);
|
||||
return {
|
||||
turns: p.runs.filter((r) => r.session_id === q.sessionId),
|
||||
next_cursor: p.next_cursor,
|
||||
};
|
||||
},
|
||||
timeline: (q, signal) =>
|
||||
get(
|
||||
path(q) +
|
||||
"/timeline?" +
|
||||
new URLSearchParams({
|
||||
limit: "100",
|
||||
after: String(q.after ?? 0),
|
||||
...(q.through != null ? { through: String(q.through) } : {}),
|
||||
}),
|
||||
signal,
|
||||
),
|
||||
summary: (q, signal) => get(path(q) + "/summary", signal),
|
||||
children: (q, signal) => get(path(q) + "/children", signal),
|
||||
};
|
||||
}
|
||||
const svg = (kind) => {
|
||||
const shapes = {
|
||||
model: '<path d="m12 3 3 6 6 3-6 3-3 6-3-6-6-3 6-3Z"/>',
|
||||
tool: '<path d="m8 5-5 7 5 7M16 5l5 7-5 7M14 4l-4 16"/>',
|
||||
agent:
|
||||
'<rect x="4" y="5" width="16" height="14" rx="4"/><path d="M9 10h.01M15 10h.01M9 14h6M12 2v3"/>',
|
||||
chevron: '<path d="m9 5 7 7-7 7"/>',
|
||||
};
|
||||
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${shapes[kind] || shapes.agent}</svg>`;
|
||||
};
|
||||
const kind = (s) =>
|
||||
s.operation.startsWith("model.")
|
||||
? "model"
|
||||
: s.operation.startsWith("tool.")
|
||||
? "tool"
|
||||
: "agent";
|
||||
const name = (s) =>
|
||||
(s.tool && s.tool.replaceAll("__", " · ").replaceAll("_", " ")) ||
|
||||
(s.model && s.operation === "model.attempt" && `Model · ${s.model}`) ||
|
||||
{
|
||||
"agent.execute": "Execution segment",
|
||||
"model.requested": "Request started",
|
||||
"policy.review": "Policy check",
|
||||
"approval.wait": "Approval wait",
|
||||
"question.wait": "Question wait",
|
||||
"environment.operation": "Prepare environment",
|
||||
}[s.operation] ||
|
||||
s.operation;
|
||||
const key = (s) => s.trace_id + "/" + s.span_id;
|
||||
const reason = (e) =>
|
||||
e?.status === 403
|
||||
? "You cannot read this session."
|
||||
: e?.status === 404
|
||||
? "This recording is no longer available."
|
||||
: e?.status === 503
|
||||
? "Recording is disabled or unavailable."
|
||||
: e?.status === 429
|
||||
? "Recording readers are busy. Try Refresh."
|
||||
: "Unable to load recording. Try Refresh.";
|
||||
const button = (action, text, extra = "") =>
|
||||
`<button type="button" data-tr="${action}" ${extra}>${text}</button>`;
|
||||
const scope = (r) => ({ sessionId: r.session_id, turnId: r.turn_id });
|
||||
/** Session-oriented trace browser. No evaluations or combined team view. */
|
||||
export function mountSessionTracing(
|
||||
root,
|
||||
{ adapter, initialRun = null, onOverview } = {},
|
||||
) {
|
||||
if (!adapter) throw Error("A tracing adapter is required");
|
||||
const lifetime = new AbortController(),
|
||||
signal = lifetime.signal;
|
||||
let disposed = false,
|
||||
searchGen = 0,
|
||||
sessionGen = 0,
|
||||
detailGen = 0,
|
||||
timer;
|
||||
let results = [],
|
||||
nextSearch = null,
|
||||
searchText = "",
|
||||
session = null,
|
||||
turns = [],
|
||||
nextTurns = null,
|
||||
history = [],
|
||||
cache = new Map(),
|
||||
selected = null,
|
||||
details = null,
|
||||
mode = "tree",
|
||||
tab = "preview",
|
||||
pending = false;
|
||||
root.classList.add("ow-session-tracing");
|
||||
root.innerHTML = `<div class="tr-heading"><div><h1>Tracing</h1><p>Follow a session, one turn at a time.</p></div><div>${onOverview ? button("overview", "Usage overview ↗") : ""}${button("refresh", "Refresh")}</div></div><div class="tr-toolbar"><input type="search" aria-label="Search sessions" placeholder="Search session name or ID…" maxlength="200"><span class="tr-directory-state" role="status"></span></div><div class="tr-workbench"><aside class="tr-directory"><div class="tr-panehead">Sessions</div><div class="tr-results"></div><div class="tr-directory-footer"></div></aside><section class="tr-execution"><div class="tr-panehead"><span>Execution</span><div class="tr-segment" role="group" aria-label="Execution view">${button("tree", "Tree", 'aria-pressed="true"')}${button("waterfall", "Waterfall", 'aria-pressed="false"')}</div></div><div class="tr-context"></div><div class="tr-turns"></div></section><section class="tr-inspector"><div class="tr-panehead">Step details</div><div class="tr-details"></div></section></div>`;
|
||||
const $ = (s) => root.querySelector(s);
|
||||
const query = () => $(".tr-toolbar input").value;
|
||||
function sessions() {
|
||||
const map = new Map();
|
||||
for (const r of results)
|
||||
if (!map.has(r.session_id)) map.set(r.session_id, r);
|
||||
return [...map.values()];
|
||||
}
|
||||
function directory() {
|
||||
const rs = sessions();
|
||||
$(".tr-results").innerHTML =
|
||||
rs
|
||||
.map(
|
||||
(r) =>
|
||||
`<button class="tr-session ${session?.session_id === r.session_id ? "selected" : ""}" data-tr="session" data-tr-session="${esc(r.session_id)}"><strong>${esc(r.name || r.agent || r.session_id)}</strong><span><i class="tr-status">${esc(r.status || "Unknown")}</i><small>${r.created_ms ? esc(new Date(r.created_ms).toLocaleDateString()) : ""}</small></span><code>${esc(r.session_id)}</code></button>`,
|
||||
)
|
||||
.join("") ||
|
||||
'<p class="tr-note">No matching sessions on this page.</p>';
|
||||
$(".tr-directory-footer").innerHTML = nextSearch
|
||||
? button("more-search", "More sessions")
|
||||
: "";
|
||||
}
|
||||
async function search(more = false) {
|
||||
const gen = ++searchGen,
|
||||
q = searchText;
|
||||
$(".tr-directory-state").textContent = "Searching…";
|
||||
try {
|
||||
const page = await adapter.search(
|
||||
{ q, after: more ? nextSearch : undefined },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== searchGen) return;
|
||||
results = (more ? [...results, ...page.runs] : page.runs).slice(0, 1000);
|
||||
nextSearch = results.length < 1000 ? page.next_cursor : null;
|
||||
$(".tr-directory-state").textContent =
|
||||
`${sessions().length} sessions loaded${nextSearch ? " · more available" : ""}`;
|
||||
directory();
|
||||
if (!session && results.length) await openSession(results[0]);
|
||||
} catch (e) {
|
||||
if (disposed || gen !== searchGen) return;
|
||||
results = [];
|
||||
nextSearch = null;
|
||||
directory();
|
||||
$(".tr-directory-state").textContent = reason(e);
|
||||
}
|
||||
}
|
||||
function crumb() {
|
||||
return `<div class="tr-breadcrumb">${button("home", "Sessions")}${history.length ? `<span>›</span>${button("back", esc(history.at(-1).session.name || history.at(-1).session.agent || "Parent agent"))}<span>›</span>${button("back", esc(history.at(-1).parentTurn))}` : ""}<span>›</span><strong>${esc(session?.name || session?.agent || "Session")}</strong></div>`;
|
||||
}
|
||||
function context() {
|
||||
if (!session) return;
|
||||
$(".tr-context").innerHTML =
|
||||
crumb() +
|
||||
`<h2>${esc(session.name || session.agent || session.session_id)}</h2><div class="tr-chips"><span>${esc(session.status || "Unknown")}</span><span>${turns.length} ${turns.length === 1 ? "turn" : "turns"} loaded${nextTurns ? " · more available" : ""}</span><code>${esc(session.session_id)}</code></div>`;
|
||||
}
|
||||
const visibleSteps = (c) =>
|
||||
(c.steps || []).filter((s) => s.operation !== "model.requested");
|
||||
function body(t, c) {
|
||||
if (c.error) return `<p class="tr-error" role="status">${esc(c.error)}</p>`;
|
||||
if (c.loading)
|
||||
return '<p class="tr-note" role="status">Loading recording…</p>';
|
||||
const ss = visibleSteps(c),
|
||||
known = ss.filter(
|
||||
(s) => Number.isFinite(s.started_ms) && Number.isFinite(s.duration_us),
|
||||
),
|
||||
start = known.length ? Math.min(...known.map((s) => s.started_ms)) : 0,
|
||||
end = known.length
|
||||
? Math.max(...known.map((s) => s.started_ms + s.duration_us / 1000))
|
||||
: 1,
|
||||
range = Math.max(1, end - start),
|
||||
summary = c.summary;
|
||||
const total = summary?.usage;
|
||||
const tokens =
|
||||
total?.input?.total != null && total?.output?.total != null
|
||||
? `${count(total.input.total + total.output.total)}${total.input.unknown || total.output.unknown ? " + unknown" : ""}`
|
||||
: "Not reported";
|
||||
let html = `<div class="tr-turn-metrics"><span>${esc(duration(summary?.wall_elapsed_us))} elapsed</span><span>${tokens} tokens</span><span>${ss.length} steps loaded</span></div>`;
|
||||
if (mode === "waterfall")
|
||||
html += `<div class="tr-axis">${[0, 1, 2, 3, 4].map((i) => `<span>${i ? esc(duration(((range * i) / 4) * 1000)) : "0 s"}</span>`).join("")}</div>`;
|
||||
// Indentation follows recorded parent IDs only. Missing parents are roots;
|
||||
// cycles are bounded and labelled, never silently invented.
|
||||
const map = new Map(ss.map((s) => [key(s), s]));
|
||||
const depth = (s) => {
|
||||
let n = 0,
|
||||
p = s,
|
||||
seen = new Set([key(s)]);
|
||||
while (n < 6) {
|
||||
const parent = map.get(p.parent_trace_id + "/" + p.parent_span_id);
|
||||
if (!parent || seen.has(key(parent))) break;
|
||||
seen.add(key(parent));
|
||||
n++;
|
||||
p = parent;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
for (const s of ss) {
|
||||
const d = depth(s),
|
||||
k = kind(s),
|
||||
timing =
|
||||
Number.isFinite(s.started_ms) && Number.isFinite(s.duration_us);
|
||||
html += `<button class="tr-step tr-${k} ${selected?.step && key(selected.step) === key(s) ? "selected" : ""} ${mode === "waterfall" ? "tr-waterfall" : ""}" data-tr="step" data-turn="${esc(t.turn_id)}" data-step="${esc(key(s))}" data-depth="${d}"><span class="tr-step-name">${svg(k)}<span>${esc(name(s))}</span></span>${mode === "tree" ? `<span class="tr-duration">${esc(duration(s.duration_us))}</span>` : `<span class="tr-track">${timing ? `<i data-left="${Math.min(99, Math.max(0, ((s.started_ms - start) / range) * 100))}" data-width="${Math.min(100, (s.duration_us / 1000 / range) * 100)}" class="${s.outcome === "error" ? "tr-failed" : ""}"></i>` : "<small>Unknown timing</small>"}</span>`}<span class="tr-outcome ${s.outcome === "error" ? "tr-error" : ""}">${esc(s.outcome || "Unknown")}</span></button>`;
|
||||
}
|
||||
if (c.next != null)
|
||||
html +=
|
||||
c.steps.length < 1000
|
||||
? button(
|
||||
"more-steps",
|
||||
"Load more steps",
|
||||
`data-turn="${esc(t.turn_id)}"`,
|
||||
)
|
||||
: '<p class="tr-note">Showing 1,000 steps. Narrow the query through the SDK to inspect further records.</p>';
|
||||
if (!ss.length)
|
||||
html += '<p class="tr-note">No recorded steps for this turn.</p>';
|
||||
html += `<div class="tr-children">${(c.children || []).map((child, i) => `<div><span>${svg("agent")}${esc(child.agent_id)} <small>${esc(child.phase)}</small></span>${child.child_turn_id ? button("child", `Open session ↗`, `data-turn="${esc(t.turn_id)}" data-child="${i}" aria-label="Open ${esc(child.agent_id)} session"`) : "<small>Initial turn unavailable</small>"}</div>`).join("")}</div>`;
|
||||
if (c.childError)
|
||||
html +=
|
||||
'<p class="tr-note">Child links are unavailable for this turn.</p>';
|
||||
const cov = summary?.coverage;
|
||||
if (
|
||||
cov?.scan_truncated ||
|
||||
cov?.hierarchy_incomplete ||
|
||||
cov?.unknown_outcome_steps ||
|
||||
cov?.unknown_timing_steps
|
||||
)
|
||||
html +=
|
||||
'<p class="tr-note">Partial coverage: some timing, hierarchy or outcomes are incomplete. Recording is best effort.</p>';
|
||||
return html;
|
||||
}
|
||||
function render() {
|
||||
context();
|
||||
directory();
|
||||
$(".tr-turns").innerHTML =
|
||||
turns
|
||||
.map((t) => {
|
||||
const c = cache.get(t.turn_id);
|
||||
return `<section class="tr-turn"><button data-tr="turn" data-turn="${esc(t.turn_id)}" class="tr-turn-heading" aria-expanded="${!!c?.open}"><span class="tr-chevron ${c?.open ? "open" : ""}">${svg("chevron")}</span><span><b>${esc(t.label || "Turn · " + t.turn_id.slice(0, 14) + "…")}</b><small>${esc(t.status || "Status not reported")}</small></span></button>${c?.open ? `<div class="tr-calls">${body(t, c)}</div>` : ""}</section>`;
|
||||
})
|
||||
.join("") +
|
||||
(nextTurns != null ? button("more-turns", "Load more turns") : "") +
|
||||
(pending ? '<p class="tr-note" role="status">Loading turns…</p>' : "");
|
||||
root
|
||||
.querySelectorAll(".tr-segment button")
|
||||
.forEach((b) =>
|
||||
b.setAttribute("aria-pressed", String(b.dataset.tr === mode)),
|
||||
);
|
||||
for (const el of root.querySelectorAll("[data-depth]"))
|
||||
el.style.setProperty("--indent", el.dataset.depth);
|
||||
for (const el of root.querySelectorAll("[data-left]")) {
|
||||
el.style.left = el.dataset.left + "%";
|
||||
el.style.width = el.dataset.width + "%";
|
||||
}
|
||||
}
|
||||
async function loadTurns(more = false, target) {
|
||||
if (more && pending) return;
|
||||
const gen = sessionGen,
|
||||
sid = session.session_id;
|
||||
pending = true;
|
||||
render();
|
||||
try {
|
||||
const p = await adapter.turns(
|
||||
{ sessionId: sid, after: more ? nextTurns : undefined },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
const incoming = p.turns.filter((t) => t.session_id === sid);
|
||||
if (!more && incoming[0])
|
||||
session = { ...session, status: incoming[0].status };
|
||||
const unique = new Map(
|
||||
(more ? [...turns, ...incoming] : incoming).map((t) => [t.turn_id, t]),
|
||||
);
|
||||
turns = [...unique.values()];
|
||||
turns = turns.slice(0, 1000);
|
||||
nextTurns = turns.length < 1000 ? p.next_cursor : null;
|
||||
pending = false;
|
||||
if (target && !turns.some((t) => t.turn_id === target.turn_id))
|
||||
turns.unshift({ ...target, session_id: sid });
|
||||
render();
|
||||
if (!more && turns.length) {
|
||||
const t = turns.find((t) => t.turn_id === target?.turn_id) || turns[0];
|
||||
await loadTurn(t);
|
||||
}
|
||||
} catch (e) {
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
pending = false;
|
||||
turns = [];
|
||||
nextTurns = null;
|
||||
render();
|
||||
$(".tr-turns").innerHTML =
|
||||
`<p class="tr-error" role="status">${esc(reason(e))}</p>`;
|
||||
}
|
||||
}
|
||||
async function openSession(r, target) {
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
session = r;
|
||||
turns = [];
|
||||
cache = new Map();
|
||||
selected = null;
|
||||
details = null;
|
||||
nextTurns = null;
|
||||
$(".tr-details").innerHTML =
|
||||
'<p class="tr-note">Select a model or tool call.</p>';
|
||||
await loadTurns(false, target || r);
|
||||
}
|
||||
async function loadTurn(t, more = false) {
|
||||
const gen = sessionGen,
|
||||
old = cache.get(t.turn_id) || {},
|
||||
q = scope(t);
|
||||
const c = { ...old, open: true, loading: true };
|
||||
cache.set(t.turn_id, c);
|
||||
render();
|
||||
try {
|
||||
const [page, s, child] = await Promise.all([
|
||||
adapter.timeline(
|
||||
{
|
||||
...q,
|
||||
after: more ? old.next : undefined,
|
||||
through: more ? old.through : undefined,
|
||||
limit: 100,
|
||||
},
|
||||
signal,
|
||||
),
|
||||
more
|
||||
? Promise.resolve({ summary: old.summary })
|
||||
: adapter.summary(q, signal),
|
||||
more
|
||||
? Promise.resolve({ children: old.children })
|
||||
: adapter.children
|
||||
? adapter
|
||||
.children(q, signal)
|
||||
.catch(() => ({ children: [], unavailable: true }))
|
||||
: Promise.resolve({ children: [] }),
|
||||
]);
|
||||
if (disposed || gen !== sessionGen || cache.get(t.turn_id) !== c) return;
|
||||
const steps = [
|
||||
...(more ? old.steps || [] : []),
|
||||
...page.page.steps.map((x) => x.step),
|
||||
];
|
||||
Object.assign(c, {
|
||||
steps: steps.slice(0, 1000),
|
||||
next: page.page.next,
|
||||
through: page.page.through,
|
||||
summary: s.summary,
|
||||
children: child.children,
|
||||
childError: child.unavailable,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
render();
|
||||
} catch (e) {
|
||||
if (disposed || gen !== sessionGen) return;
|
||||
Object.assign(c, {
|
||||
loading: false,
|
||||
error: reason(e),
|
||||
steps: [],
|
||||
children: [],
|
||||
});
|
||||
if (selected?.turn.turn_id === t.turn_id) {
|
||||
selected = null;
|
||||
details = null;
|
||||
detailGen++;
|
||||
$(".tr-details").innerHTML =
|
||||
'<p class="tr-note">Selected recording is unavailable.</p>';
|
||||
}
|
||||
render();
|
||||
}
|
||||
}
|
||||
function inspector() {
|
||||
const s = selected?.step;
|
||||
if (!s) return;
|
||||
const payload = (v) =>
|
||||
v === undefined || v === null
|
||||
? '<div class="tr-empty">Content was not captured or is not available to this viewer.</div>'
|
||||
: `<pre>${esc(typeof v === "string" ? v : JSON.stringify(v, null, 2))}</pre>`;
|
||||
$(".tr-details").innerHTML =
|
||||
`<div class="tr-detail-title"><small>${esc(s.operation)}</small><h2>${esc(name(s))}</h2><div class="tr-chips"><span>${esc(s.outcome)}</span><span>${esc(duration(s.duration_us))}</span></div></div><div class="tr-tabs" role="group" aria-label="Step detail view">${["preview", "attributes", "json"].map((x) => button(x, x === "json" ? "JSON" : x[0].toUpperCase() + x.slice(1), `aria-pressed="${tab === x}"`)).join("")}</div><div class="tr-detail-body">${
|
||||
tab === "json"
|
||||
? `<pre>${esc(JSON.stringify(s, null, 2))}</pre>`
|
||||
: tab === "attributes"
|
||||
? `<dl>${Object.entries(s)
|
||||
.filter(([, v]) => v != null)
|
||||
.map(
|
||||
([k, v]) =>
|
||||
`<dt>${esc(k)}</dt><dd>${esc(typeof v === "object" ? JSON.stringify(v) : v)}</dd>`,
|
||||
)
|
||||
.join("")}</dl>`
|
||||
: `<h3>Input</h3>${payload(details?.input)}<h3>Output</h3>${payload(details?.output)}${details?.error ? `<p class="tr-note">${esc(details.error)}</p>` : ""}<h3>Execution</h3><dl><dt>Duration</dt><dd>${esc(duration(s.duration_us))}</dd><dt>First output</dt><dd>${esc(duration(s.first_output_us))}</dd><dt>Model</dt><dd>${esc(s.model || "—")}</dd><dt>Token usage</dt><dd>${s.usage ? esc(JSON.stringify(s.usage)) : "Not reported"}</dd><dt>Span</dt><dd>${esc(s.span_id)}</dd></dl>`
|
||||
}</div>`;
|
||||
}
|
||||
async function select(t, s) {
|
||||
selected = { turn: t, step: s };
|
||||
details = null;
|
||||
tab = "preview";
|
||||
const gen = ++detailGen,
|
||||
sessionVersion = sessionGen;
|
||||
render();
|
||||
inspector();
|
||||
if (adapter.stepDetails) {
|
||||
try {
|
||||
const value = await adapter.stepDetails(
|
||||
{ ...scope(t), traceId: s.trace_id, spanId: s.span_id },
|
||||
signal,
|
||||
);
|
||||
if (disposed || gen !== detailGen || sessionVersion !== sessionGen)
|
||||
return;
|
||||
details = value;
|
||||
inspector();
|
||||
} catch (e) {
|
||||
if (!disposed && gen === detailGen) {
|
||||
details = { error: reason(e) };
|
||||
inspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function click(e) {
|
||||
const b = e.target.closest("button[data-tr]");
|
||||
if (!b || !root.contains(b)) return;
|
||||
const action = b.dataset.tr,
|
||||
t = turns.find((t) => t.turn_id === b.dataset.turn);
|
||||
if (action === "session") {
|
||||
history = [];
|
||||
await openSession(
|
||||
results.find((r) => r.session_id === b.dataset.trSession),
|
||||
);
|
||||
} else if (action === "turn") {
|
||||
const c = cache.get(t.turn_id);
|
||||
if (c?.open) {
|
||||
c.open = false;
|
||||
render();
|
||||
} else if (c?.steps) {
|
||||
c.open = true;
|
||||
render();
|
||||
} else await loadTurn(t);
|
||||
} else if (action === "more-steps") await loadTurn(t, true);
|
||||
else if (action === "step") {
|
||||
const s = cache
|
||||
.get(t.turn_id)
|
||||
?.steps.find((s) => key(s) === b.dataset.step);
|
||||
if (s) await select(t, s);
|
||||
} else if (action === "child") {
|
||||
const c = cache.get(t.turn_id).children[Number(b.dataset.child)];
|
||||
history.push({
|
||||
session,
|
||||
turns,
|
||||
nextTurns,
|
||||
cache,
|
||||
selected,
|
||||
details,
|
||||
tab,
|
||||
mode,
|
||||
parentTurn: t.label || "Turn · " + t.turn_id.slice(0, 14) + "…",
|
||||
scroll: $(".tr-execution").scrollTop,
|
||||
});
|
||||
await openSession(
|
||||
{
|
||||
session_id: c.child_session_id,
|
||||
turn_id: c.child_turn_id,
|
||||
name: c.agent_id,
|
||||
status: c.phase,
|
||||
},
|
||||
{ session_id: c.child_session_id, turn_id: c.child_turn_id },
|
||||
);
|
||||
$(".tr-execution").scrollTop = 0;
|
||||
} else if (action === "back") {
|
||||
const h = history.pop();
|
||||
if (h) {
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
({ session, turns, nextTurns, cache, selected, details, tab, mode } =
|
||||
h);
|
||||
pending = false;
|
||||
render();
|
||||
$(".tr-execution").scrollTop = h.scroll;
|
||||
inspector();
|
||||
}
|
||||
} else if (action === "home") {
|
||||
history = [];
|
||||
if (results[0]) await openSession(results[0]);
|
||||
} else if (["tree", "waterfall"].includes(action)) {
|
||||
mode = action;
|
||||
render();
|
||||
} else if (["preview", "attributes", "json"].includes(action)) {
|
||||
tab = action;
|
||||
inspector();
|
||||
} else if (action === "more-search") await search(true);
|
||||
else if (action === "more-turns") await loadTurns(true);
|
||||
else if (action === "refresh") {
|
||||
if (session) await openSession(session, selected?.turn);
|
||||
else await search();
|
||||
} else if (action === "overview") onOverview?.();
|
||||
}
|
||||
root.addEventListener("click", click, { signal });
|
||||
$(".tr-toolbar input").addEventListener(
|
||||
"input",
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
searchText = query();
|
||||
searchGen++;
|
||||
timer = setTimeout(() => search(), 250);
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
if (initialRun) openSession(initialRun);
|
||||
if (adapter.search) search();
|
||||
else $(".tr-toolbar").hidden = true;
|
||||
return {
|
||||
refresh: () => (session ? openSession(session) : search()),
|
||||
dispose() {
|
||||
disposed = true;
|
||||
searchGen++;
|
||||
sessionGen++;
|
||||
detailGen++;
|
||||
clearTimeout(timer);
|
||||
lifetime.abort();
|
||||
root.replaceChildren();
|
||||
root.classList.remove("ow-session-tracing");
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// One authoritative viewer implementation, copied into the standalone UI image.
|
||||
import {readFile,writeFile} from 'node:fs/promises';
|
||||
import assert from 'node:assert/strict';
|
||||
for(const file of ['observability.js','observability-data.js']) {
|
||||
for(const file of ['observability.js','observability-data.js','tracing.js','tracing.css']) {
|
||||
const source=await readFile(new URL(`src/${file}`,import.meta.url),'utf8');
|
||||
const target=new URL(`../service-ui/public/${file}`,import.meta.url);
|
||||
if(process.argv.includes('--check'))assert.equal(await readFile(target,'utf8'),source,`${file}: run npm run sync in trace-viewer`);
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
// Real component + actual OpenShell metadata; fault injection is browser-local.
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
const [url, modulePath, output] = process.argv.slice(2);
|
||||
assert(["127.0.0.1", "localhost"].includes(new URL(url).hostname));
|
||||
const { chromium } = await import(pathToFileURL(resolve(modulePath)).href);
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
try {
|
||||
const p = await browser.newPage({ viewport: { width: 1600, height: 1060 } }),
|
||||
errors = [];
|
||||
p.on("pageerror", (e) => errors.push(e.message));
|
||||
await p.goto(url);
|
||||
await p.locator(".tr-step").first().waitFor();
|
||||
await mkdir(output, { recursive: true });
|
||||
await p.locator(".tr-session").first().click();
|
||||
await p.locator(".tr-step").first().waitFor();
|
||||
const first = await p.locator(".tr-session.selected code").innerText();
|
||||
await p.locator(".tr-step").first().click();
|
||||
await p.getByRole("button", { name: "JSON", exact: true }).click();
|
||||
assert(
|
||||
(await p.locator(".tr-detail-body pre").innerText()).includes("span_id"),
|
||||
);
|
||||
await p.screenshot({
|
||||
path: resolve(output, "session-tracing-real-tree.png"),
|
||||
});
|
||||
await p.getByRole("button", { name: "Waterfall", exact: true }).click();
|
||||
assert((await p.locator(".tr-track").count()) > 0);
|
||||
await p.screenshot({
|
||||
path: resolve(output, "session-tracing-real-waterfall.png"),
|
||||
});
|
||||
const child = p.getByRole("button", { name: /Open .* session/ }).first();
|
||||
await child.waitFor();
|
||||
await child.focus();
|
||||
await p.keyboard.press("Enter");
|
||||
await p.locator('.tr-breadcrumb [data-tr="back"]').first().waitFor();
|
||||
await p.locator(".tr-step").first().waitFor();
|
||||
assert.notEqual(
|
||||
await p.locator(".tr-session.selected code").innerText(),
|
||||
first,
|
||||
);
|
||||
await p.locator(".tr-step").first().click();
|
||||
await p.screenshot({
|
||||
path: resolve(output, "session-tracing-real-child.png"),
|
||||
});
|
||||
await p.locator('.tr-breadcrumb [data-tr="back"]').first().click();
|
||||
assert.equal(await p.locator(".tr-session.selected code").innerText(), first);
|
||||
assert.equal(
|
||||
await p
|
||||
.getByRole("button", { name: "Waterfall", exact: true })
|
||||
.getAttribute("aria-pressed"),
|
||||
"true",
|
||||
);
|
||||
// Isolated mounted instance: paging, multiple turns, escaping, exact session match,
|
||||
// delayed content, loss of permission, and teardown. No new provider call.
|
||||
await p.evaluate(async () => {
|
||||
const { mountSessionTracing } = await import("/src/tracing.js");
|
||||
const records = await fetch("/api/v1/observability/runs?limit=25").then(
|
||||
(r) => r.json(),
|
||||
);
|
||||
const r = records.runs[0];
|
||||
const base = await fetch(
|
||||
`/api/v1/sessions/${r.session_id}/observability/${r.turn_id}/timeline?limit=100`,
|
||||
).then((r) => r.json());
|
||||
window.requests = [];
|
||||
window.delayed = [];
|
||||
window.denied = false;
|
||||
window.moreReads = 0;
|
||||
const root = document.createElement("div");
|
||||
root.id = "isolated";
|
||||
document.body.prepend(root);
|
||||
const row = base.page.steps.find(
|
||||
(x) => x.step.operation === "model.attempt",
|
||||
).step;
|
||||
const adapter = {
|
||||
search: async (q) => {
|
||||
window.requests.push(q);
|
||||
return {
|
||||
runs: [
|
||||
{
|
||||
session_id: "safe",
|
||||
turn_id: "t1",
|
||||
name: "<img src=x onerror=alert(1)>",
|
||||
},
|
||||
],
|
||||
next_cursor: q.after ? null : "next",
|
||||
};
|
||||
},
|
||||
turns: async (q) => ({
|
||||
turns: q.after
|
||||
? [{ session_id: "safe", turn_id: "t2", name: "safe" }]
|
||||
: [{ session_id: "safe", turn_id: "t1", name: "safe" }],
|
||||
next_cursor: q.after ? null : "turn-next",
|
||||
}),
|
||||
timeline: async (q) => {
|
||||
if (window.denied) throw Object.assign(Error(), { status: 403 });
|
||||
if (q.after) window.moreReads++;
|
||||
return {
|
||||
page: {
|
||||
steps: [
|
||||
{
|
||||
cursor: q.after ? 2 : 1,
|
||||
step: { ...row, span_id: q.after ? "span2" : "span1" },
|
||||
},
|
||||
],
|
||||
through: 2,
|
||||
next: q.after ? null : 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
summary: async () => ({
|
||||
summary: {
|
||||
usage: { input: { total: 10 }, output: { total: 5 } },
|
||||
coverage: {},
|
||||
},
|
||||
}),
|
||||
stepDetails: () => new Promise((r) => window.delayed.push(r)),
|
||||
};
|
||||
window.testView = mountSessionTracing(root, { adapter });
|
||||
});
|
||||
const root = p.locator("#isolated");
|
||||
await root.locator(".tr-step").waitFor();
|
||||
await root.getByRole("button", { name: "Load more steps" }).click();
|
||||
await p.waitForFunction(() => window.moreReads === 1);
|
||||
assert.equal(await root.locator(".tr-step").count(), 2);
|
||||
await root.locator(".tr-step").first().click();
|
||||
await root.locator(".tr-step").last().click();
|
||||
await p.evaluate(() => {
|
||||
window.delayed[1]({ input: "new selection" });
|
||||
window.delayed[0]({ input: "stale selection" });
|
||||
});
|
||||
await root.getByText("new selection", { exact: true }).waitFor();
|
||||
assert.equal(
|
||||
await root.getByText("stale selection", { exact: true }).count(),
|
||||
0,
|
||||
);
|
||||
await root.getByRole("button", { name: "Load more turns" }).click();
|
||||
await p.waitForFunction(
|
||||
() => document.querySelectorAll("#isolated .tr-turn").length === 2,
|
||||
);
|
||||
assert.equal(await root.locator("img").count(), 0);
|
||||
await p.evaluate(() => (window.denied = true));
|
||||
await root.getByRole("button", { name: "Refresh", exact: true }).click();
|
||||
await root
|
||||
.getByText("You cannot read this session.", { exact: true })
|
||||
.waitFor();
|
||||
assert.equal(
|
||||
await root.getByText("new selection", { exact: true }).count(),
|
||||
0,
|
||||
);
|
||||
await p.evaluate(() => window.testView.dispose());
|
||||
assert.equal(await root.locator("button").count(), 0);
|
||||
// Transport must exact-filter session IDs even if authorized search matches a prefix.
|
||||
assert.equal(
|
||||
await p.evaluate(async () => {
|
||||
const { serviceTracingAdapter } = await import("/src/tracing.js");
|
||||
const a = serviceTracingAdapter(async () => ({
|
||||
runs: [{ session_id: "a" }, { session_id: "ab" }],
|
||||
next_cursor: "more",
|
||||
}));
|
||||
const result = await a.turns({ sessionId: "a" });
|
||||
return result.turns.length;
|
||||
}),
|
||||
1,
|
||||
);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
"Session browser passed: real trace/child navigation, parent restore, waterfall, paging, stale detail suppression, escaping, permission loss, exact scope and disposal.",
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user