Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** Debounce for live re-reads of the currently-shown wire log. */
const
LIVE_REFRESH_DELAY
=
400
;
/** Debounce for re-rendering the list as the user types in the filter box. */
const
FILTER_DEBOUNCE_DELAY
=
150
;
/** Number of frames rendered per page; grows via the "Load more" button. */
const
PAGE_SIZE
=
1000
;
/** Cap the pretty-printed JSON shown per frame to keep the DOM light. */
const
MAX_DETAIL_JSON
=
20000
;
/**
* Navigation events fired by the Wire Log breadcrumb.
*/
export
const
enum
{
=
'home'
,
=
'overview'
,
}
type
WireLogDirection
=
'c2s'
|
's2c'
;
/**
* A single parsed JSON-RPC frame from the AHP wire log, together with its
* `_ahpLog` transport metadata.
*/
interface
IWireFrame
{
readonly
:
number
;
readonly
:
;
readonly
:
boolean
;
readonly
:
number
|
undefined
;
readonly
:
string
|
undefined
;
readonly
:
string
|
undefined
;
/**
* A short identifying label surfaced inline in the row: the dispatched
* action's `type` (for `action` / `dispatchAction` / `notification` frames)
* or the target session (for `createSession` frames).
*/
readonly
:
string
|
undefined
;
readonly
:
unknown
;
readonly
:
{
readonly
?
:
number
;
readonly
?
:
string
;
readonly
?
:
unknown
}
|
undefined
;
readonly
:
'request'
|
'notification'
|
'response'
;
}
/**
* A request (or notification) frame, paired with its matching response frame
* when one is present in the loaded window.
*/
interface
IWireEntry
{
readonly
:
;
:
|
undefined
;
}
/**
* AHP Log view — a user-friendly rendering of the client↔host AHP JSON-RPC
* protocol frames. Instead of raw JSONL, it pairs requests with their
* responses, surfaces direction, latency, errors and unanswered ("pending")
* calls, and lets each frame's payload be expanded. Backed by the raw AHP log
* file; full fidelity is a click away via "Open Full File".
*/
export
class
ChatDebugWireLogView
extends
Disposable
{
private
readonly
=
this
.
_register
(
new
Emitter<WireLogNavigation>
(
)
)
;
readonly
=
this
.
.
;
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
:
;
private
readonly
=
this
.
_register
(
new
DisposableStore
(
)
)
;
private
readonly
=
this
.
_register
(
new
DisposableStore
(
)
)
;
/** Watches the currently-shown wire log for live updates. */
private
readonly
=
this
.
_register
(
new
MutableDisposable<DisposableStore>
(
)
)
;
private
readonly
:
;
/** Debounces list re-renders while the user types in the filter box. */
private
readonly
:
;
private
:
|
undefined
;
private
:
URI
|
undefined
;
private
:
[
]
=
[
]
;
private
:
string
|
undefined
;
private
:
URI
|
undefined
;
private
:
[
]
=
[
]
;
/** The filtered entries currently rendered in the list, in order. */
private
:
[
]
=
[
]
;
/** Row DOM nodes parallel to {@link renderedVisible}. */
private
:
[
]
=
[
]
;
/** Per-row disposables parallel to {@link renderedVisible}. */
private
:
[
]
=
[
]
;
/** True while the list is showing a status message instead of rows. */
private
=
false
;
private
=
''
;
/** Monotonic token guarding against out-of-order async loads. */
private
=
0
;
/** Max number of (filtered) frames rendered at once; grows via "Load more". */
private
=
PAGE_SIZE
;
private
readonly
:
;
private
readonly
=
this
.
_register
(
new
DisposableStore
(
)
)
;
private
:
|
undefined
;
private
:
|
undefined
;
private
=
false
;
constructor
(
:
,
@IChatService
private
readonly
:
,
@IContextViewService
private
readonly
:
,
@IEditorService
private
readonly
:
,
@IConfigurationService
private
readonly
:
,
@IPathService
private
readonly
:
,
@IAgentHostService
private
readonly
:
,
@IRemoteAgentHostService
private
readonly
:
,
@IOutputService
private
readonly
:
,
@IFileService
private
readonly
:
,
@ITextModelService
private
readonly
:
,
@IEnvironmentService
private
readonly
:
,
@IProductService
private
readonly
:
,
@ILogService
private
readonly
:
,
)
{
super
(
)
;
this
.
=
DOM
.
append
(
,
$
(
'.chat-debug-wirelog'
)
)
;
DOM
.
hide
(
this
.
)
;
this
.
=
this
.
_register
(
new
RunOnceScheduler
(
(
)
=>
this
.
liveRefresh
(
)
,
LIVE_REFRESH_DELAY
)
)
;
this
.
=
this
.
_register
(
new
RunOnceScheduler
(
(
)
=>
this
.
applyFilter
(
)
,
FILTER_DEBOUNCE_DELAY
)
)
;
// Breadcrumb
const
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-breadcrumb'
)
)
;
this
.
=
this
.
_register
(
new
BreadcrumbsWidget
(
,
3
,
undefined
,
.
,
)
)
;
this
.
_register
(
setupBreadcrumbKeyboardNavigation
(
,
this
.
)
)
;
this
.
_register
(
this
.
.
onDidSelectItem
(
=>
{
if
(
.
===
'select'
&&
.
instanceof
TextBreadcrumbItem
)
{
this
.
.
setSelection
(
undefined
)
;
const
=
this
.
.
getItems
(
)
.
indexOf
(
.
)
;
if
(
===
0
)
{
this
.
.
fire
(
.
)
;
}
else
if
(
===
1
)
{
this
.
.
fire
(
.
)
;
}
}
}
)
)
;
// Hint shown when wire logging is disabled.
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-hint'
)
)
;
DOM
.
hide
(
this
.
)
;
// Toolbar: source picker + filter + actions.
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-toolbar'
)
)
;
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-select'
)
)
;
this
.
=
DOM
.
append
(
this
.
,
$
(
'input.chat-debug-wirelog-filter'
)
)
as
;
this
.
.
=
'text'
;
this
.
.
=
localize
(
'chatDebug.wireLog.filterPlaceholder'
,
"Filter by method, type, or id"
)
;
this
.
.
setAttribute
(
'aria-label'
,
localize
(
'chatDebug.wireLog.filterAria'
,
"Filter AHP log frames"
)
)
;
this
.
_register
(
DOM
.
addDisposableListener
(
this
.
,
DOM
.
.
INPUT
,
(
)
=>
{
// Debounce so each keystroke does not trigger a full synchronous
// rebuild of the list, which keeps typing responsive.
this
.
.
schedule
(
)
;
}
)
)
;
// Summary chips.
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-summary'
)
)
;
DOM
.
hide
(
this
.
)
;
// Body: scrollable list of frames.
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-body'
)
)
;
this
.
=
$
(
'.chat-debug-wirelog-list'
)
;
this
.
=
this
.
_register
(
new
DomScrollableElement
(
this
.
,
{
:
.
,
:
.
,
}
)
)
;
DOM
.
append
(
this
.
,
this
.
.
getDomNode
(
)
)
;
// "Load more" affordance shown when frames are paginated.
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-loadmore'
)
)
;
DOM
.
hide
(
this
.
)
;
this
.
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-footer'
)
)
;
}
setSession
(
:
URI
)
:
void
{
this
.
=
;
this
.
=
undefined
;
this
.
=
PAGE_SIZE
;
}
show
(
)
:
void
{
DOM
.
show
(
this
.
)
;
this
.
load
(
)
;
}
hide
(
)
:
void
{
DOM
.
hide
(
this
.
)
;
this
.
.
cancel
(
)
;
this
.
.
cancel
(
)
;
this
.
.
clear
(
)
;
}
refresh
(
)
:
void
{
if
(
this
.
.
.
!==
'none'
&&
!
this
.
.
isScheduled
(
)
)
{
this
.
.
schedule
(
)
;
}
}
updateBreadcrumb
(
)
:
void
{
if
(
!
this
.
)
{
return
;
}
const
=
this
.
.
getSessionTitle
(
this
.
)
||
.
parseLocalSessionId
(
this
.
)
||
this
.
.
toString
(
)
;
this
.
.
setItems
(
[
new
TextBreadcrumbItem
(
localize
(
'chatDebug.title'
,
"Agent Debug Logs"
)
,
true
)
,
new
TextBreadcrumbItem
(
,
true
)
,
new
TextBreadcrumbItem
(
localize
(
'chatDebug.ahpLog'
,
"AHP Log"
)
)
,
]
)
;
}
focus
(
)
:
void
{
this
.
?.
focus
(
)
;
}
layout
(
)
:
void
{
// Give the scrollable content an explicit height so the list can
// overflow (and thus scroll) instead of growing the whole view. The
// body is the flex-sized region between the toolbar/summary and the
// footer.
const
=
this
.
.
;
if
(
>
0
)
{
this
.
.
.
=
`${height}px`
;
}
this
.
.
scanDomNode
(
)
;
}
private
get
logSourceServices
(
)
:
{
return
{
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
:
this
.
,
}
;
}
private
async
load
(
)
:
Promise
<
void
>
{
this
.
updateBreadcrumb
(
)
;
this
.
.
clear
(
)
;
this
.
.
clear
(
)
;
DOM
.
clearNode
(
this
.
)
;
this
.
=
undefined
;
const
=
this
.
.
getValue<boolean>
(
)
;
DOM
.
clearNode
(
this
.
)
;
if
(
!
)
{
DOM
.
show
(
this
.
)
;
DOM
.
append
(
this
.
,
$
(
`span${ThemeIcon.asCSSSelector(Codicon.info)}`
)
)
;
DOM
.
append
(
this
.
,
$
(
'span'
,
undefined
,
localize
(
'chatDebug.wireLog.disabledHint'
,
"AHP logging is disabled — enable {0} and reproduce to capture client↔host protocol frames."
,
)
)
)
;
}
else
{
DOM
.
hide
(
this
.
)
;
}
if
(
!
isAgentHostSession
(
this
.
)
)
{
this
.
renderMessage
(
localize
(
'chatDebug.wireLog.notAgentHost'
,
"The AHP Log is available for Agent Host sessions."
)
)
;
return
;
}
const
=
await
enumerateAgentHostLogSources
(
this
.
,
this
.
)
;
this
.
=
.
filter
(
=>
.
===
.
)
;
if
(
this
.
.
===
0
)
{
this
.
renderMessage
(
?
localize
(
'chatDebug.wireLog.noFrames'
,
"No AHP log was found yet for this session. Interact with the agent to capture protocol frames."
)
:
localize
(
'chatDebug.wireLog.enableToCapture'
,
"No AHP log is available. Enable {0} and reproduce the issue to capture protocol frames."
,
)
)
;
return
;
}
// Source picker (only when more than one rotated wire log exists).
if
(
this
.
.
>
1
)
{
DOM
.
show
(
this
.
)
;
const
:
[
]
=
this
.
.
map
(
=>
(
{
:
.
}
)
)
;
let
=
this
.
.
findIndex
(
=>
.
===
this
.
)
;
if
(
<
0
)
{
=
0
;
}
const
=
this
.
.
add
(
new
SelectBox
(
,
,
this
.
,
,
{
:
localize
(
'chatDebug.wireLog.sourceLabel'
,
"AHP log file"
)
,
}
)
)
;
.
render
(
this
.
)
;
this
.
.
add
(
.
onDidSelect
(
=>
this
.
loadSource
(
.
)
)
)
;
this
.
=
;
}
else
{
DOM
.
hide
(
this
.
)
;
}
// Actions.
const
=
this
.
.
add
(
new
Button
(
this
.
,
{
...
,
:
true
,
:
true
,
:
localize
(
'chatDebug.wireLog.openFile'
,
"Open Full File"
)
}
)
)
;
.
.
.
add
(
'chat-debug-wirelog-action'
)
;
.
=
`$(go-to-file) ${localize('chatDebug.wireLog.openFile',"Open Full File")}`
/**
* Applies the current filter box value and re-renders the list. Invoked
* (debounced) from the filter input's INPUT handler; skips work when the
* effective filter text has not changed.
*/
private
applyFilter
(
)
:
void
{
const
=
this
.
.
.
trim
(
)
.
toLowerCase
(
)
;
if
(
===
this
.
)
{
return
;
}
this
.
=
;
this
.
=
PAGE_SIZE
;
this
.
renderList
(
)
;
}
private
renderList
(
)
:
void
{
// Dispose the previous rows' stores (click listeners etc.) before
// clearing and rebuilding; otherwise they accumulate on every filter
// change, "Load more", or full live refresh.
this
.
.
clear
(
)
;
DOM
.
clearNode
(
this
.
)
;
this
.
=
[
]
;
this
.
=
[
]
;
this
.
=
[
]
;
this
.
=
false
;
if
(
this
.
.
===
0
)
{
this
.
renderMessage
(
localize
(
'chatDebug.wireLog.empty'
,
"The AHP log is empty."
)
)
;
return
;
}
this
.
renderSummary
(
)
;
const
{
,
}
=
this
.
computeVisible
(
this
.
)
;
if
(
.
===
0
)
{
const
=
DOM
.
append
(
this
.
,
$
(
'.chat-debug-wirelog-noresults'
)
)
;
.
=
localize
(
'chatDebug.wireLog.noMatches'
,
"No frames match '{0}'."
,
this
.
)
;
this
.
updateLoadMore
(
0
)
;
this
.
.
scanDomNode
(
)
;
return
;
}
for
(
const
of
)
{
this
.
appendRow
(
)
;
}
this
.
=
;
this
.
updateLoadMore
(
.
)
;
this
.
.
scanDomNode
(
)
;
}
/**
* Re-reads the current wire log and updates the list in place — appending
* newly-captured frames and refreshing rows whose state changed (e.g. a
* response arriving for a pending request) — instead of rebuilding the
* whole view. Used for live refreshes so the panel does not flash back to
* "Loading…" and lose scroll position on every turn.
*/
private
async
liveRefresh
(
)
:
Promise
<
void
>
{
const
=
this
.
.
findIndex
(
=>
.
===
this
.
)
;
const
=
this
.
[
]
;
if
(
!
)
{
return
;
}
const
=
++
this
.
;
let
;
try
{
=
await
readAgentHostLogSourceContent
(
,
this
.
)
;
}
catch
{
return
;
// keep showing the current content on a transient read error
}
if
(
!==
this
.
||
!
)
{
return
;
}
this
.
=
.
;
this
.
applyEntries
(
buildWireEntries
(
parseWireFrames
(
.
)
)
)
;
this
.
renderFooter
(
,
.
)
;
}
/**
* Applies a freshly-parsed set of entries to the list. When the previously
* rendered rows are still a prefix of the new (filtered) set, only the
* changed and newly-appended rows are touched; otherwise a full render is
* performed (e.g. after a filter change or log rotation).
*/
private
applyEntries
(
:
[
]
)
:
void
{
const
{
,
}
=
this
.
computeVisible
(
)
;
const
=
!
this
.
&&
this
.
.
>
0
&&
.
>=
this
.
.
&&
this
.
.
every
(
(
,
)
=>
baseEntryKey
(
)
===
baseEntryKey
(
[
]
)
)
;
this
.
=
;
if
(
!
)
{
this
.
renderList
(
)
;
return
;
}
const
=
this
.
isScrolledToBottom
(
)
;
// Summary chips live outside the scroll list; cheap to rebuild.
this
.
renderSummary
(
)
;
// Refresh rows whose state changed (e.g. a response arrived).
for
(
let
=
0
;
<
this
.
.
;
++
)
{
if
(
entryStateKey
(
this
.
[
]
)
!==
entryStateKey
(
[
]
)
)
{
this
.
replaceRow
(
,
[
]
)
;
}
}
// Append rows for newly-captured frames (up to the current page limit).
for
(
let
=
this
.
.
;
<
.
;
++
)
{
this
.
appendRow
(
[
]
)
;
}
this
.
=
;
this
.
updateLoadMore
(
.
)
;
this
.
.
scanDomNode
(
)
;
if
(
)
{
this
.
scrollToBottom
(
)
;
}
}
/**
* Computes the filtered entries and the (paginated) subset currently
* displayed. Only the first {@link visibleLimit} matching frames are shown;
* the rest are revealed via the "Load more" button.
*/
private
computeVisible
(
:
[
]
)
:
{
:
[
]
;
:
[
]
}
{
const
=
this
.
;
const
=
?
.
filter
(
=>
matchesFilter
(
,
)
)
:
;
const
=
.
>
this
.
?
.
slice
(
0
,
this
.
)
:
;
return
{
,
}
;
}
/**
* Shows or hides the "Load more" affordance and updates its status label.
*/
private
updateLoadMore
(
:
number
)
:
void
{
if
(
<=
this
.
)
{
if
(
this
.
)
{
DOM
.
hide
(
this
.
)
;
this
.
=
false
;
this
.
layout
(
)
;
}
return
;
}
if
(
!
this
.
)
{
this
.
=
DOM
.
append
(
this
.
,
$
(
'span.chat-debug-wirelog-loadmore-status'
)
)
;
}
if
(
!
this
.
)
{
this
.
=
this
.
.
add
(
new
Button
(
this
.
,
{
...
,
:
true
,
:
localize
(
'chatDebug.wireLog.loadMoreTitle'
,
"Load more frames"
)
}
)
)
;
this
.
.
add
(
this
.
.
onDidClick
(
(
)
=>
{
this
.
+=
PAGE_SIZE
;
this
.
renderList
(
)
;
}
)
)
;
}
const
=
.
min
(
this
.
,
)
;
const
=
-
;
this
.
.
=
localize
(
'chatDebug.wireLog.showingCount'
,
"Showing {0} of {1} frames"
,
,
)
;
this
.
.
=
localize
(
'chatDebug.wireLog.loadMore'
,
"Load More ({0})"
,
)
;
if
(
!
this
.
)
{
DOM
.
show
(
this
.
)
;
this
.
=
true
;
this
.
layout
(
)
;
}
}
private
appendRow
(
:
)
:
void
{
const
{
,
}
=
this
.
buildRow
(
)
;
this
.
.
add
(
)
;
this
.
.
push
(
)
;
this
.
.
push
(
)
;
this
.
.
appendChild
(
)
;
}
private
replaceRow
(
:
number
,
:
)
:
void
{
const
{
,
}
=
this
.
buildRow
(
)
;
this
.
.
add
(
)
;
const
=
this
.
[
]
;
this
.
.
replaceChild
(
,
)
;
this
.
[
]
.
dispose
(
)
;
this
.
[
]
=
;
this
.
[
]
=
;
}
private
isScrolledToBottom
(
)
:
boolean
{
const
=
this
.
.
getScrollDimensions
(
)
;
const
=
this
.
.
getScrollPosition
(
)
;
return
.
+
.
>=
.
-
4
;
}
private
scrollToBottom
(
)
:
void
{
this
.
.
setScrollPosition
(
{
:
this
.
.
getScrollDimensions
(
)
.
}
)
;
}
private
buildRow
(
:
)
:
{
:
;
:
}
{
const
=
new
DisposableStore
(
)
;
const
=
.
;
const
=
isErrorEntry
(
)
;
const
=
.
===
'request'
&&
!
.
;
const
=
$
(
'.chat-debug-wirelog-row'
)
;
if
(
)
{
.
.
add
(
'chat-debug-wirelog-row-error'
)
;
}
const
=
DOM
.
append
(
,
$
(
'.chat-debug-wirelog-row-header'
)
)
;
// Accessibility: the header is an expand/collapse toggle. Make it
// keyboard-focusable, expose button semantics + expanded state, and
// hide the purely-decorative chevron from assistive technology.
// Details are rendered lazily on first expand: pretty-printing every
// frame's JSON up-front dominates render time, so collapsed rows (the
// common case) never pay that cost.
const
=
DOM
.
append
(
,
$
(
'.chat-debug-wirelog-row-details'
)
)
;
let
=
false
;
let
=
false
;
const
setExpanded
=
(
:
boolean
,
:
boolean
)
=>
{
=
;
if
(
&&
!
)
{
this
.
renderDetails
(
,
)
;
=
true
;
}
.
.
toggle
(
'chat-debug-wirelog-row-expanded'
,
)
;
.
.
toggle
(
'codicon-chevron-down'
,
)
;
.
.
toggle
(
'codicon-chevron-right'
,
!
)
;
.
setAttribute
(
'aria-expanded'
,
String
(
)
)
;
if
(
)
{
this
.
.
scanDomNode
(
)
;
}
}
;
// Apply the initial (auto-expanded for errors) state without scanning:
// renderList scans once after all rows are appended, so scanning per
// row here would thrash layout during the build.
setExpanded
(
,
false
)
;
.
add
(
DOM
.
addDisposableListener
(
,
DOM
.
.
CLICK
,
(
)
=>
setExpanded
(
!
,
true
)
)
)
;
.
add
(
DOM
.
addDisposableListener
(
,
DOM
.
.
KEY_DOWN
,
(
:
)
=>
{
if
(
.
===
'Enter'
||
.
===
' '
)
{
.
preventDefault
(
)
;
setExpanded
(
!
,
true
)
;
}
}
)
)
;
return
{
,
}
;
}
private
renderDetails
(
:
,
:
)
:
void
{
const
=
.
;
// Request / notification payload.
if
(
.
!==
undefined
)
{
this
.
appendJsonSection
(
,
.
===
'response'
?
localize
(
'chatDebug.wireLog.section.result'
,
"Result"
)
:
localize
(
'chatDebug.wireLog.section.params'
,
"Params"
)
,
.
)
;
}
if
(
.
)
{
this
.
appendJsonSection
(
,
localize
(
'chatDebug.wireLog.section.error'
,
"Error"
)
,
.
,
true
)
;
}
// Matched response payload / error.
if
(
.
)
{
if
(
.
.
)
{
this
.
appendJsonSection
(
,
localize
(
'chatDebug.wireLog.section.responseError'
,
"Response Error"
)
,
.
.
,
true
)
;
}
else
if
(
.
.
!==
undefined
)
{
this
.
appendJsonSection
(
,
localize
(
'chatDebug.wireLog.section.result'
,
"Result"
)
,
.
.
)
;
}
}
if
(
.
||
.
?.
)
{
DOM
.
append
(
,
$
(
'.chat-debug-wirelog-detail-note'
,
undefined
,
localize
(
'chatDebug.wireLog.truncatedFrame'
,
"Large payload values were elided in the log. Open the full file for complete data."
)
)
)
;
}
}
private
appendJsonSection
(
:
,
:
string
,
:
unknown
,
=
false
)
:
void
{
const
=
DOM
.
append
(
,
$
(
'.chat-debug-wirelog-detail-section'
)
)
;
DOM
.
append
(
,
$
(
'.chat-debug-wirelog-detail-title'
,
undefined
,
)
)
;
const
=
DOM
.
append
(
,
$
(
'pre.chat-debug-wirelog-detail-json'
)
)
;
if
(
)
{
.
.
add
(
'chat-debug-wirelog-detail-json-error'
)
;
}
.
=
stringifyBounded
(
)
;
}
private
renderFooter
(
:
,
:
boolean
)
:
void
{
DOM
.
clearNode
(
this
.
)
;
const
:
string
[
]
=
[
]
;
if
(
)
{
.
push
(
localize
(
'chatDebug.wireLog.footerTail'
,
"Showing the most recent frames"
)
)
;
}
if
(
.
)
{
.
push
(
localize
(
'chatDebug.wireLog.footerRemote'
,
"remote"
)
)
;
}
this
.
.
=
.
join
(
' · '
)
;
}
}
/**
* Extracts a short identifying label for a frame from its payload, surfaced
* inline in the row next to the method:
* - `action` frames carry the dispatched action under `params.action`;
* - `notification` frames carry it under `params.notification`;
* - `dispatchAction` frames pass positional args `[channel, action, …]`, so the
* action is the second argument;
* - `createSession` frames pass `[config]`, whose `session` field (a URI)
* identifies the session being resumed or forked.
*/
function
extractActionType
(
:
string
|
undefined
,
:
unknown
)
:
string
|
undefined
{
switch
(
)
{
case
'notification'
:
return
typeStringOf
(
getProp
(
,
'notification'
)
)
;
case
'dispatchAction'
:
return
typeStringOf
(
Array
.
isArray
(
)
?
[
1
]
:
undefined
)
;
case
'createSession'
:
return
uriStringOf
(
getProp
(
Array
.
isArray
(
)
?
[
0
]
:
undefined
,
'session'
)
)
;
default
:
return
typeStringOf
(
getProp
(
,
'action'
)
)
;
}
}
/** Reads a property off a value only when it is a non-null object. */
function
getProp
(
:
unknown
,
:
string
)
:
unknown
{
return
&&
typeof
===
'object'
?
(
as
<
string
,
unknown
>
)
[
]
:
undefined
;
}
/** Returns the `type` string of an action-like value, when present. */
function
typeStringOf
(
:
unknown
)
:
string
|
undefined
{
const
=
getProp
(
,
'type'
)
;
return
typeof
===
'string'
?
:
undefined
;
}
/** Renders a logged URI value (string or serialized components) as text. */
function
uriStringOf
(
:
unknown
)
:
string
|
undefined
{
if
(
typeof
===
'string'
)
{
return
;
}
if
(
&&
typeof
===
'object'
)
{
const
=
(
as
<
string
,
unknown
>
)
.
;
if
(
typeof
===
'string'
)
{
return
;
}
if
(
typeof
(
as
<
string
,
unknown
>
)
.
===
'string'
)
{
try
{
return
URI
.
revive
(
as
)
.
toString
(
true
)
;
}
catch
{
return
undefined
;
}
}
}
return
undefined
;
}
/** Parses newline-delimited AHP frames, skipping any unparseable lines. */
function
parseWireFrames
(
:
string
)
:
[
]
{
const
:
[
]
=
[
]
;
for
(
const
of
.
split
(
'\n'
)
)
{
const
=
.
trim
(
)
;
if
(
!
)
{
continue
;
}
let
:
<
string
,
unknown
>
;
try
{
=
JSON
.
parse
(
)
;
}
catch
{
// A truncated tail can leave a partial first line; skip it.
continue
;
}
const
=
.
as
<
string
,
unknown
>
|
undefined
;
if
(
!
)
{
continue
;
}
const
:
=
.
===
's2c'
?
's2c'
:
'c2s'
;
const
=
typeof
.
===
'string'
?
.
parse
(
.
)
:
NaN
;
const
=
.
!==
undefined
&&
.
!==
null
?
String
(
.
)
:
undefined
;
const
=
typeof
.
===
'string'
?
.
:
undefined
;
const
=
.
.
hasOwnProperty
.
call
(
,
'result'
)
;
const
=
.
as
{
?
:
number
;
?
:
string
;
?
:
unknown
}
|
undefined
;
const
:
[
'kind'
]
=
?
(
!==
undefined
?
'request'
:
'notification'
)
:
'response'
;
const
=
?
.
:
(
?
.
:
undefined
)
;
.
push
(
{
:
.
isNaN
(
)
?
0
:
,
,
:
.
===
true
,
:
typeof
.
===
'number'
?
.
:
undefined
,
,
,
:
extractActionType
(
,
)
,
,
:
&&
typeof
===
'object'
?
:
undefined
,
,
}
)
;
}
return
;
}
/**
* Folds response frames into the request they answer (matched by id in
* chronological order), leaving notifications and unmatched frames as
* standalone entries.
*
* AHP is bidirectional: both client and host can originate requests, and their
* id namespaces are independent. A response therefore answers a request from
* the opposite direction (a c2s request is answered by an s2c response and vice
* versa), so pending requests are keyed by direction + id to avoid pairing a
* response with a same-id request from the other direction.
*/
function
buildWireEntries
(
:
[
]
)
:
[
]
{
const
:
[
]
=
[
]
;
const
=
new
Map<string, IWireEntry>
(
)
;
const
pendingKey
=
(
:
,
:
string
)
=>
`${dir}|${id}`
;
for
(
const
of
)
{
if
(
.
===
'response'
&&
.
!==
undefined
)
{
// A response answers a request travelling in the opposite direction.
const
:
=
.
===
'c2s'
?
's2c'
:
'c2s'
;
const
=
pendingKey
(
,
.
)
;
const
=
.
get
(
)
;
if
(
)
{
.
=
;
.
delete
(
)
;
continue
;
}
}
const
:
=
{
,
:
undefined
}
;
.
push
(
)
;
if
(
.
===
'request'
&&
.
!==
undefined
)
{
.
set
(
pendingKey
(
.
,
.
)
,
)
;
}
}
return
;
}
/**
* True when an entry represents a protocol error, whether it is a JSON-RPC
* error response or an agent-emitted `chat/error` action/notification frame.
* Used to color the row and count errors in the summary.
*/
function
isErrorEntry
(
:
)
:
boolean
{
const
=
.
;
return
!
!
.
?.
||
(
.
===
'response'
&&
!
!
.
)
||
.
===
.
;
}
/** True when an entry's method, action type, id, or response error matches the filter. */
function
matchesFilter
(
:
,
:
string
)
:
boolean
{
const
=
.
;
if
(
.
?.
toLowerCase
(
)
.
includes
(
)
)
{
return
true
;
}
if
(
.
?.
toLowerCase
(
)
.
includes
(
)
)
{
return
true
;
}
if
(
.
!==
undefined
&&
.
.
toLowerCase
(
)
.
includes
(
)
)
{
return
true
;
}
const
=
.
?.
?.
??
.
?.
;
return
!
!
&&
.
toLowerCase
(
)
.
includes
(
)
;
}
/**
* A stable key for an entry's request/notification frame (ignoring its
* response). Used to test whether previously-rendered rows still line up with a
* freshly-parsed set so a live refresh can reconcile in place.
*/
/**
* A key capturing an entry's full render-relevant state, including whether (and
* how) its response has arrived, so a row can be re-rendered only when needed.
*/
function
entryStateKey
(
:
)
:
string
{
const
=
.
;
const
=
?
`R${response.ts}${response.error ?'E':''}`
:
'P'
;
return
`${baseEntryKey(entry)}|${responseKey}`
;
}
/** Pretty-prints a JSON value, bounded to keep the DOM light. */
function
stringifyBounded
(
:
unknown
)
:
string
{
let
:
string
;
try
{
=
JSON
.
stringify
(
,
undefined
,
2
)
??
String
(
)
;
}
catch
{
=
String
(
)
;
}
if
(
.
>
MAX_DETAIL_JSON
)
{
return
`${text.slice(0,MAX_DETAIL_JSON)}…`
;
}
return
;
}
/** Formats a millisecond duration into a compact human string. */
function
formatDuration
(
:
number
)
:
string
{
if
(
<
1000
)
{
return
localize
(
'chatDebug.wireLog.ms'
,
"{0} ms"
,
.
round
(
)
)
;
}
return
localize
(
'chatDebug.wireLog.s'
,
"{0} s"
,
(
/
1000
)
.
toFixed
(
<
10000
?
1
:
0
)
)
;
}
/** Formats a timestamp into an HH:MM:SS.mmm clock label. */