@m4trix/trace-viewer 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/cli.js +1864 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +222 -4
- package/dist/index.js +1835 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _m4trix_tracing from '@m4trix/tracing';
|
|
2
|
-
import { TraceViewerApi } from '@m4trix/tracing';
|
|
2
|
+
import { TraceViewerApi, Trace, TraceRun, TraceRecord } from '@m4trix/tracing';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
4
|
import * as _trpc_server from '@trpc/server';
|
|
4
5
|
import { AnyRouter } from '@trpc/server';
|
|
5
6
|
import http from 'node:http';
|
|
@@ -14,7 +15,10 @@ type AwsStackTraceViewerOptions = {
|
|
|
14
15
|
declare function createAwsStackTraceViewerApi(options?: AwsStackTraceViewerOptions): TraceViewerApi;
|
|
15
16
|
|
|
16
17
|
type AdapterKind = 'fs' | 'aws-stack';
|
|
18
|
+
/** `serve` starts the HTTP viewer; `mcp` serves the trace MCP over stdio. */
|
|
19
|
+
type CliCommand = 'serve' | 'mcp';
|
|
17
20
|
type ParsedCli = {
|
|
21
|
+
command: CliCommand;
|
|
18
22
|
adapter: AdapterKind;
|
|
19
23
|
/** Resolved absolute or cwd-relative path for fs adapter */
|
|
20
24
|
path: string | undefined;
|
|
@@ -30,6 +34,220 @@ declare function cliHelpText(program: string): string;
|
|
|
30
34
|
|
|
31
35
|
declare function createFsTraceViewerApi(traceRootPath: string): TraceViewerApi;
|
|
32
36
|
|
|
37
|
+
/** A scalar leaf of a payload, addressed by a JSONPath that `evaluateWithPaths` accepts. */
|
|
38
|
+
type PayloadLeaf = {
|
|
39
|
+
path: string;
|
|
40
|
+
text: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type PayloadSide = 'input' | 'output';
|
|
44
|
+
type IndexedPayload = {
|
|
45
|
+
ref: string;
|
|
46
|
+
runId: string;
|
|
47
|
+
side: PayloadSide;
|
|
48
|
+
/** Payload with JSON-in-string values decoded (see `decodeJsonStrings`). */
|
|
49
|
+
value: unknown;
|
|
50
|
+
leaves: PayloadLeaf[];
|
|
51
|
+
size: number;
|
|
52
|
+
};
|
|
53
|
+
type IndexedTrace = {
|
|
54
|
+
trace: Trace;
|
|
55
|
+
runs: Map<string, TraceRun>;
|
|
56
|
+
payloads: Map<string, IndexedPayload>;
|
|
57
|
+
size: number;
|
|
58
|
+
failures: {
|
|
59
|
+
ref: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}[];
|
|
62
|
+
};
|
|
63
|
+
type LoadTraceResult = {
|
|
64
|
+
traceId: string;
|
|
65
|
+
traceName: string;
|
|
66
|
+
status: string;
|
|
67
|
+
loaded: number;
|
|
68
|
+
alreadyLoaded: number;
|
|
69
|
+
failed: {
|
|
70
|
+
ref: string;
|
|
71
|
+
message: string;
|
|
72
|
+
}[];
|
|
73
|
+
size: number;
|
|
74
|
+
evicted: string[];
|
|
75
|
+
};
|
|
76
|
+
type PayloadIndexOptions = {
|
|
77
|
+
/** Approximate budget (serialized JSON characters) before least-recently-used traces are evicted. */
|
|
78
|
+
maxChars?: number;
|
|
79
|
+
/** Parallel payload fetches per trace. */
|
|
80
|
+
concurrency?: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* In-memory, per-trace cache of decoded and flattened payloads that `search_payloads`,
|
|
84
|
+
* `analyze_trace` and `compare` read from. Payload blobs are immutable once written, so
|
|
85
|
+
* reloading a trace only fetches refs that appeared since the last load.
|
|
86
|
+
*/
|
|
87
|
+
declare class PayloadIndex {
|
|
88
|
+
private readonly api;
|
|
89
|
+
private readonly traces;
|
|
90
|
+
private readonly maxChars;
|
|
91
|
+
private readonly concurrency;
|
|
92
|
+
constructor(api: TraceViewerApi, options?: PayloadIndexOptions);
|
|
93
|
+
/** Loaded traces, most recently used last. */
|
|
94
|
+
loadedTraces(): IndexedTrace[];
|
|
95
|
+
get(traceId: string): IndexedTrace | undefined;
|
|
96
|
+
totalSize(): number;
|
|
97
|
+
isFullyLoaded(record: TraceRecord): boolean;
|
|
98
|
+
/** Cached payload for a ref, if its trace is loaded. */
|
|
99
|
+
getPayload(traceId: string, ref: string): IndexedPayload | undefined;
|
|
100
|
+
unload(traceId: string): boolean;
|
|
101
|
+
loadTrace(record: TraceRecord): Promise<LoadTraceResult>;
|
|
102
|
+
private evict;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type TraceMcpServerOptions = {
|
|
106
|
+
traceViewerApi: TraceViewerApi;
|
|
107
|
+
index?: PayloadIndexOptions;
|
|
108
|
+
version?: string;
|
|
109
|
+
};
|
|
110
|
+
declare function createTraceMcpServer(options: TraceMcpServerOptions): McpServer;
|
|
111
|
+
/** Serves the trace MCP over stdio. Logs go to stderr; stdout carries the protocol. */
|
|
112
|
+
declare function startTraceMcpStdioServer(options: TraceMcpServerOptions): Promise<McpServer>;
|
|
113
|
+
|
|
114
|
+
type RunFilter = {
|
|
115
|
+
type?: string[];
|
|
116
|
+
/** Case-insensitive regex against run names. */
|
|
117
|
+
name?: string;
|
|
118
|
+
status?: 'running' | 'success' | 'error';
|
|
119
|
+
/** Case-insensitive substring of the run error message. */
|
|
120
|
+
errorContains?: string;
|
|
121
|
+
minLatencyMs?: number;
|
|
122
|
+
/** Minimum input + output tokens. */
|
|
123
|
+
minTokens?: number;
|
|
124
|
+
/** Exact (stringified) equality against run metadata values. */
|
|
125
|
+
metadata?: Record<string, string | number | boolean>;
|
|
126
|
+
maxDepth?: number;
|
|
127
|
+
};
|
|
128
|
+
type TraceFilter = {
|
|
129
|
+
status?: Trace['status'];
|
|
130
|
+
projectId?: string;
|
|
131
|
+
/** Case-insensitive regex against trace names. */
|
|
132
|
+
name?: string;
|
|
133
|
+
metadata?: Record<string, string | number | boolean>;
|
|
134
|
+
minLatencyMs?: number;
|
|
135
|
+
annotated?: boolean;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type SearchQuery = {
|
|
139
|
+
query: string;
|
|
140
|
+
regex?: boolean;
|
|
141
|
+
caseSensitive?: boolean;
|
|
142
|
+
runType?: string[];
|
|
143
|
+
/** Case-insensitive regex against run names. */
|
|
144
|
+
runName?: string;
|
|
145
|
+
side?: PayloadSide | 'both';
|
|
146
|
+
/** Only leaves whose path starts with this prefix (e.g. `$.messages`). */
|
|
147
|
+
pathPrefix?: string;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
type ListTracesInput = TraceFilter & {
|
|
151
|
+
since?: string;
|
|
152
|
+
until?: string;
|
|
153
|
+
limit?: number;
|
|
154
|
+
offset?: number;
|
|
155
|
+
};
|
|
156
|
+
type GetTraceInput = {
|
|
157
|
+
traceId: string;
|
|
158
|
+
focusRunId?: string;
|
|
159
|
+
maxDepth?: number;
|
|
160
|
+
maxNodes?: number;
|
|
161
|
+
hide?: string;
|
|
162
|
+
};
|
|
163
|
+
type FindRunsInput = RunFilter & {
|
|
164
|
+
traceIds?: string[];
|
|
165
|
+
traceLimit?: number;
|
|
166
|
+
limit?: number;
|
|
167
|
+
};
|
|
168
|
+
type GetRunInput = {
|
|
169
|
+
traceId: string;
|
|
170
|
+
runId: string;
|
|
171
|
+
previewChars?: number;
|
|
172
|
+
};
|
|
173
|
+
type GetPayloadInput = {
|
|
174
|
+
ref?: string;
|
|
175
|
+
traceId?: string;
|
|
176
|
+
runId?: string;
|
|
177
|
+
side?: PayloadSide;
|
|
178
|
+
path?: string;
|
|
179
|
+
mode?: 'auto' | 'json' | 'outline';
|
|
180
|
+
offset?: number;
|
|
181
|
+
maxChars?: number;
|
|
182
|
+
outlineDepth?: number;
|
|
183
|
+
};
|
|
184
|
+
type LoadPayloadsInput = {
|
|
185
|
+
traceIds?: string[];
|
|
186
|
+
status?: Trace['status'];
|
|
187
|
+
projectId?: string;
|
|
188
|
+
limit?: number;
|
|
189
|
+
};
|
|
190
|
+
type SearchPayloadsInput = SearchQuery & {
|
|
191
|
+
traceIds?: string[];
|
|
192
|
+
maxGroups?: number;
|
|
193
|
+
offset?: number;
|
|
194
|
+
maxOccurrencesPerGroup?: number;
|
|
195
|
+
};
|
|
196
|
+
type AnalyzeTraceInput = {
|
|
197
|
+
traceId: string;
|
|
198
|
+
loadPayloads?: boolean;
|
|
199
|
+
};
|
|
200
|
+
type GetConversationInput = {
|
|
201
|
+
traceId: string;
|
|
202
|
+
runId: string;
|
|
203
|
+
side?: PayloadSide | 'both';
|
|
204
|
+
maxMessages?: number;
|
|
205
|
+
maxCharsPerMessage?: number;
|
|
206
|
+
};
|
|
207
|
+
type CompareTarget = {
|
|
208
|
+
traceId: string;
|
|
209
|
+
runId?: string;
|
|
210
|
+
};
|
|
211
|
+
type CompareInput = {
|
|
212
|
+
a: CompareTarget;
|
|
213
|
+
b: CompareTarget;
|
|
214
|
+
side?: PayloadSide | 'both';
|
|
215
|
+
maxChanges?: number;
|
|
216
|
+
};
|
|
217
|
+
type AnnotateInput = {
|
|
218
|
+
traceId: string;
|
|
219
|
+
runId?: string;
|
|
220
|
+
annotation: Record<string, unknown>;
|
|
221
|
+
merge?: boolean;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Implementation behind the MCP tools. Every method returns plain text sized for an agent's
|
|
225
|
+
* context window and throws `TraceToolError` for user-correctable problems.
|
|
226
|
+
*/
|
|
227
|
+
declare class TraceTools {
|
|
228
|
+
private readonly api;
|
|
229
|
+
readonly index: PayloadIndex;
|
|
230
|
+
constructor(api: TraceViewerApi, options?: {
|
|
231
|
+
index?: PayloadIndexOptions;
|
|
232
|
+
});
|
|
233
|
+
listTraces(input: ListTracesInput): Promise<string>;
|
|
234
|
+
getTrace(input: GetTraceInput): Promise<string>;
|
|
235
|
+
findRuns(input: FindRunsInput): Promise<string>;
|
|
236
|
+
getRun(input: GetRunInput): Promise<string>;
|
|
237
|
+
getPayload(input: GetPayloadInput): Promise<string>;
|
|
238
|
+
loadTracePayloads(input: LoadPayloadsInput): Promise<string>;
|
|
239
|
+
searchPayloads(input: SearchPayloadsInput): Promise<string>;
|
|
240
|
+
analyzeTrace(input: AnalyzeTraceInput): Promise<string>;
|
|
241
|
+
getConversation(input: GetConversationInput): Promise<string>;
|
|
242
|
+
compare(input: CompareInput): Promise<string>;
|
|
243
|
+
annotate(input: AnnotateInput): Promise<string>;
|
|
244
|
+
private compareRuns;
|
|
245
|
+
private resolveTraceScope;
|
|
246
|
+
private resolvePayloadRef;
|
|
247
|
+
/** Decoded payload from the index when loaded, otherwise fetched directly (not cached). */
|
|
248
|
+
private loadPayloadValue;
|
|
249
|
+
}
|
|
250
|
+
|
|
33
251
|
type TraceViewerContext = {
|
|
34
252
|
traceViewerApi: TraceViewerApi;
|
|
35
253
|
};
|
|
@@ -47,9 +265,9 @@ declare const appRouterImpl: _trpc_server.TRPCBuiltRouter<{
|
|
|
47
265
|
}, _trpc_server.TRPCDecorateCreateRouterOptions<{
|
|
48
266
|
list: _trpc_server.TRPCQueryProcedure<{
|
|
49
267
|
input: {
|
|
268
|
+
status?: "error" | "running" | "success" | undefined;
|
|
50
269
|
limit?: number | undefined;
|
|
51
270
|
cursor?: string | undefined;
|
|
52
|
-
status?: "running" | "success" | "error" | undefined;
|
|
53
271
|
projectId?: string | undefined;
|
|
54
272
|
} | undefined;
|
|
55
273
|
output: _m4trix_tracing.ListTracesResult;
|
|
@@ -84,8 +302,8 @@ declare const appRouterImpl: _trpc_server.TRPCBuiltRouter<{
|
|
|
84
302
|
patchRunAnnotation: _trpc_server.TRPCMutationProcedure<{
|
|
85
303
|
input: {
|
|
86
304
|
traceId: string;
|
|
87
|
-
annotation: Record<string, unknown>;
|
|
88
305
|
runId: string;
|
|
306
|
+
annotation: Record<string, unknown>;
|
|
89
307
|
merge?: boolean | undefined;
|
|
90
308
|
};
|
|
91
309
|
output: _m4trix_tracing.TraceRun | null;
|
|
@@ -104,4 +322,4 @@ type StartServerOptions = {
|
|
|
104
322
|
};
|
|
105
323
|
declare function startTraceViewerServer(options: StartServerOptions): http.Server;
|
|
106
324
|
|
|
107
|
-
export { type AdapterKind, type AppRouter, type AwsStackTraceViewerOptions, CliParseError, DEFAULT_FS_RELATIVE_PATH, DEFAULT_PORT, type ParsedCli, type TraceViewerContext, appRouter, cliHelpText, createAwsStackTraceViewerApi, createFsTraceViewerApi, parseCliArgs, startTraceViewerServer };
|
|
325
|
+
export { type AdapterKind, type AppRouter, type AwsStackTraceViewerOptions, type CliCommand, CliParseError, DEFAULT_FS_RELATIVE_PATH, DEFAULT_PORT, type ParsedCli, type TraceMcpServerOptions, TraceTools, type TraceViewerContext, appRouter, cliHelpText, createAwsStackTraceViewerApi, createFsTraceViewerApi, createTraceMcpServer, parseCliArgs, startTraceMcpStdioServer, startTraceViewerServer };
|