src/vs/workbench/contrib/chat/common/chatDebugEvents.ts
165 LOC · 163 covered · 2 uncovered · 53 ranges · 40 concepts · 29 introducers · 38 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
chatDebugEvents.ts ×5
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IChatDebugEvent } from './chatDebugService.js';
/**
* Checks whether a debug event matches a single text search term.
* Used by both the debug panel filter and the listDebugEvents tool.
*/
export function debugEventMatchesText(event: IChatDebugEvent, term: string): boolean {
}
case 'toolCall':
|| (event.input?.toLowerCase().includes(term) ?? false)
|| (event.output?.toLowerCase().includes(term) ?? false);
|| (event.requestName?.toLowerCase().includes(term) ?? false);
|| (event.details?.toLowerCase().includes(term) ?? false)
|| (event.category?.toLowerCase().includes(term) ?? false);
|| (event.description?.toLowerCase().includes(term) ?? false);
case 'agentResponse':
|| event.sections.some(s => s.name.toLowerCase().includes(term) || s.content.toLowerCase().includes(term));
}
/**
* Regex used to match `before:` and `after:` timestamp tokens inside filter text.
*/
const timestampTokenPattern = /\b(?:before|after):\d{4}(?:-\d{2}(?:-\d{2}(?:t\d{1,2}(?::\d{2}(?::\d{2})?)?)?)?)?(\b|$)/g;
/**
* Parse a `before:YYYY[-MM[-DD[THH[:MM[:SS]]]]]` or `after:…` token from
* free-form filter text. Each component after the year is optional.
*
* For `before:`, the timestamp is rounded **up** to the end of the most
* specific unit given (e.g. `before:2026-03` → end-of-March).
* For `after:`, the timestamp is the **start** of the most specific unit.
*/
export function parseTimeToken(text: string, prefix: string): number | undefined {
const regex = new RegExp(`${prefix}:(\\d{4})(?:-(\\d{2})(?:-(\\d{2})(?:t(\\d{1,2})(?::(\\d{2})(?::(\\d{2}))?)?)?)?)?(?!\\w)`);
chatDebugEvents.ts ×3
const m = regex.exec(text);
if (!m) {
}
const year = parseInt(m[1], 10);
const day = m[3] !== undefined ? parseInt(m[3], 10) : undefined;
const hour = m[4] !== undefined ? parseInt(m[4], 10) : undefined;
const minute = m[5] !== undefined ? parseInt(m[5], 10) : undefined;
const second = m[6] !== undefined ? parseInt(m[6], 10) : undefined;
if (prefix === 'before') {
return new Date(year, month!, day!, hour!, minute!, second, 999).getTime();
return new Date(year, month!, day!, hour!, minute, 59, 999).getTime();
}
year,
month ?? 0,
day ?? 1,
hour ?? 0,
minute ?? 0,
second ?? 0,
0,
).getTime();
}
/**
* Strips `before:…` and `after:…` timestamp tokens from filter text,
* returning only the plain text search portion.
*/
export function stripTimestampTokens(text: string): string {
}
/**
* Filters debug events by comma-separated text terms and optional
* `before:`/`after:` timestamp tokens.
*
* Terms prefixed with `!` are exclusions; all others are inclusions.
* At least one inclusion term must match (if any are present).
* Timestamp tokens are parsed and applied as date-range bounds, then
* stripped before text matching.
*/
export function filterDebugEventsByText(events: readonly IChatDebugEvent[], filterText: string): readonly IChatDebugEvent[] {
const afterTimestamp = parseTimeToken(filterText, 'after');
// Strip timestamp tokens before splitting into text search terms
const textOnly = stripTimestampTokens(filterText);
const terms = textOnly.split(/\s*,\s*/).filter(t => t.length > 0);
const includeTerms = terms.filter(t => !t.startsWith('!')).map(t => t.trim());
const excludeTerms = terms.filter(t => t.startsWith('!')).map(t => t.slice(1).trim()).filter(t => t.length > 0);
return events.filter(e => {
// Timestamp bounds
const time = e.created.getTime();
if (beforeTimestamp !== undefined && time > beforeTimestamp) {
}
}
if (excludeTerms.some(term => debugEventMatchesText(e, term))) {
}
}
}
export interface DebugEventFilterOptions {
readonly kind?: string;
readonly filter?: string;
readonly limit?: number;
}
/**
* Applies kind, text, and limit filters to debug events.
* Used by the listDebugEvents tool to consolidate all filtering in one place.
*/
export function filterDebugEvents(events: readonly IChatDebugEvent[], options: DebugEventFilterOptions): readonly IChatDebugEvent[] {
if (options.kind) {
}
if (options.filter) {
}
if (options.limit !== undefined && options.limit > 0 && result.length > options.limit) {
}
return result;
}