@agent-inspect/studio 6.31.37 → 6.31.39
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/dist/index.cjs +2341 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.mjs +2307 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { Server, IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
|
|
4
|
+
type StudioAuthMode = "none" | "basic";
|
|
5
|
+
|
|
6
|
+
interface StudioProjectRow {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string | null;
|
|
9
|
+
path: string;
|
|
10
|
+
workspaceDir: string;
|
|
11
|
+
projectName: string | null;
|
|
12
|
+
redactionProfile: string | null;
|
|
13
|
+
traceCount: number;
|
|
14
|
+
importedAt: string;
|
|
15
|
+
}
|
|
16
|
+
type IngestFileKind = "ci" | "bundle";
|
|
17
|
+
declare function resolveStudioDbPath(options: {
|
|
18
|
+
dbPath?: string;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
declare function openStudioDb(dbPath: string): Database.Database;
|
|
22
|
+
|
|
23
|
+
declare const STUDIO_REGISTRY_SCHEMA_VERSION: "1.0";
|
|
24
|
+
interface StudioRegistryProject {
|
|
25
|
+
id: string;
|
|
26
|
+
path: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
suiteConfigs?: string[];
|
|
29
|
+
}
|
|
30
|
+
interface StudioRegistryImport {
|
|
31
|
+
ciArtifactsDir?: string;
|
|
32
|
+
bundlesDir?: string;
|
|
33
|
+
fileDropDir?: string;
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface StudioRegistryGitHubIngest {
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
tokenEnv?: string;
|
|
39
|
+
}
|
|
40
|
+
interface StudioRegistryHttpIngest {
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
path?: string;
|
|
43
|
+
tokenEnv?: string;
|
|
44
|
+
maxBytes?: number;
|
|
45
|
+
}
|
|
46
|
+
interface StudioRegistryBundleUploadIngest {
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
maxBytes?: number;
|
|
49
|
+
}
|
|
50
|
+
interface StudioRegistryFileDropIngest {
|
|
51
|
+
maxBytes?: number;
|
|
52
|
+
}
|
|
53
|
+
interface StudioRegistryIngest {
|
|
54
|
+
github?: StudioRegistryGitHubIngest;
|
|
55
|
+
http?: StudioRegistryHttpIngest;
|
|
56
|
+
bundleUpload?: StudioRegistryBundleUploadIngest;
|
|
57
|
+
fileDrop?: StudioRegistryFileDropIngest;
|
|
58
|
+
}
|
|
59
|
+
interface StudioRegistry {
|
|
60
|
+
schemaVersion: typeof STUDIO_REGISTRY_SCHEMA_VERSION;
|
|
61
|
+
name: string;
|
|
62
|
+
projects: StudioRegistryProject[];
|
|
63
|
+
import?: StudioRegistryImport;
|
|
64
|
+
ingest?: StudioRegistryIngest;
|
|
65
|
+
}
|
|
66
|
+
interface StudioRegistryParseResult {
|
|
67
|
+
ok: boolean;
|
|
68
|
+
registry?: StudioRegistry;
|
|
69
|
+
errors: string[];
|
|
70
|
+
warnings: string[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare function parseStudioRegistry(input: unknown): StudioRegistryParseResult;
|
|
74
|
+
declare function readStudioRegistryFile(filePath: string): Promise<StudioRegistryParseResult & {
|
|
75
|
+
path: string;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
interface ImportedStudioProject extends StudioProjectRow {
|
|
79
|
+
suiteConfigPaths: string[];
|
|
80
|
+
}
|
|
81
|
+
interface StudioImportResult {
|
|
82
|
+
registryName: string;
|
|
83
|
+
projects: ImportedStudioProject[];
|
|
84
|
+
warnings: string[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface FileDropImportOptions {
|
|
88
|
+
db: Database.Database;
|
|
89
|
+
registryPath: string;
|
|
90
|
+
registry: StudioRegistry;
|
|
91
|
+
/** Explicit opt-in required — ingest is disabled by default. */
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
/** Override drop directory (CLI `--dir`). */
|
|
94
|
+
dropDir?: string;
|
|
95
|
+
/** Move successfully imported files into `dropDir/.imported/` instead of leaving copies. */
|
|
96
|
+
archiveAfterImport?: boolean;
|
|
97
|
+
/** Override registry ingest.fileDrop.maxBytes for tests. */
|
|
98
|
+
maxBytes?: number;
|
|
99
|
+
}
|
|
100
|
+
interface FileDropImportedFile {
|
|
101
|
+
sourceKey: string;
|
|
102
|
+
sourceName: string;
|
|
103
|
+
destPath: string;
|
|
104
|
+
kind: IngestFileKind;
|
|
105
|
+
contentHash: string;
|
|
106
|
+
archived: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface FileDropImportResult {
|
|
109
|
+
skipped: boolean;
|
|
110
|
+
reason?: string;
|
|
111
|
+
scanned: number;
|
|
112
|
+
imported: number;
|
|
113
|
+
skippedFiles: number;
|
|
114
|
+
errors: string[];
|
|
115
|
+
warnings: string[];
|
|
116
|
+
files: FileDropImportedFile[];
|
|
117
|
+
}
|
|
118
|
+
declare function importFileDrop(options: FileDropImportOptions): Promise<FileDropImportResult>;
|
|
119
|
+
declare function importFileDropFromRegistry(options: {
|
|
120
|
+
db: Database.Database;
|
|
121
|
+
registryPath: string;
|
|
122
|
+
registry: StudioRegistry;
|
|
123
|
+
enabled: boolean;
|
|
124
|
+
dropDir?: string;
|
|
125
|
+
archiveAfterImport?: boolean;
|
|
126
|
+
maxBytes?: number;
|
|
127
|
+
}): Promise<FileDropImportResult>;
|
|
128
|
+
declare function runStudioFileDropImport(options: {
|
|
129
|
+
workspacePath?: string;
|
|
130
|
+
dbPath?: string;
|
|
131
|
+
cwd?: string;
|
|
132
|
+
dropDir?: string;
|
|
133
|
+
archiveAfterImport?: boolean;
|
|
134
|
+
}): Promise<FileDropImportResult>;
|
|
135
|
+
|
|
136
|
+
interface StudioContext {
|
|
137
|
+
db: Database.Database;
|
|
138
|
+
dbPath: string;
|
|
139
|
+
registryPath: string;
|
|
140
|
+
registry: StudioRegistry;
|
|
141
|
+
importResult: StudioImportResult;
|
|
142
|
+
fileDropResult?: FileDropImportResult;
|
|
143
|
+
projects: ImportedStudioProject[];
|
|
144
|
+
}
|
|
145
|
+
declare function createStudioContext(options?: StudioServerOptions): Promise<StudioContext>;
|
|
146
|
+
declare function summarizeProjects(projects: StudioProjectRow[]): {
|
|
147
|
+
id: string;
|
|
148
|
+
label: string;
|
|
149
|
+
projectName: string | null;
|
|
150
|
+
traceCount: number;
|
|
151
|
+
redactionProfile: string | null;
|
|
152
|
+
importedAt: string;
|
|
153
|
+
}[];
|
|
154
|
+
|
|
155
|
+
interface StudioServerOptions {
|
|
156
|
+
host?: string;
|
|
157
|
+
port?: number;
|
|
158
|
+
workspacePath?: string;
|
|
159
|
+
dbPath?: string;
|
|
160
|
+
server?: boolean;
|
|
161
|
+
cwd?: string;
|
|
162
|
+
auth?: StudioAuthMode;
|
|
163
|
+
passwordEnv?: string;
|
|
164
|
+
/** Test hook: inject a preloaded context instead of importing on startup. */
|
|
165
|
+
context?: StudioContext;
|
|
166
|
+
/** Run file-drop ingest once on startup (requires explicit opt-in). */
|
|
167
|
+
ingestFileDrop?: boolean;
|
|
168
|
+
/** Move imported drop files into `.imported/` after successful copy. */
|
|
169
|
+
archiveFileDrop?: boolean;
|
|
170
|
+
/** Enable HTTP ingest routes (requires explicit opt-in + ingest token env). */
|
|
171
|
+
ingestHttp?: boolean;
|
|
172
|
+
/** Env var name for HTTP ingest token (default STUDIO_INGEST_TOKEN). */
|
|
173
|
+
ingestTokenEnv?: string;
|
|
174
|
+
}
|
|
175
|
+
interface StudioServerInfo {
|
|
176
|
+
host: string;
|
|
177
|
+
port: number;
|
|
178
|
+
url: string;
|
|
179
|
+
mode: "studio";
|
|
180
|
+
workspacePath?: string;
|
|
181
|
+
dbPath?: string;
|
|
182
|
+
registryName?: string;
|
|
183
|
+
projectCount?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare function createStudioServer(options?: StudioServerOptions): Server;
|
|
187
|
+
declare function startStudioServer(options?: StudioServerOptions): Promise<StudioServerInfo>;
|
|
188
|
+
|
|
189
|
+
declare const studioIndexHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; style-src 'unsafe-inline'; script-src 'unsafe-inline'\" />\n <title>AgentInspect Studio</title>\n <style>\n body { font-family: system-ui, sans-serif; margin: 0; line-height: 1.4; color: #111; }\n header { padding: 1rem 1.5rem; border-bottom: 1px solid #ddd; background: #fafafa; }\n nav a { margin-right: 1rem; color: #0b57d0; text-decoration: none; }\n nav a.active { font-weight: 600; text-decoration: underline; }\n main { padding: 1.5rem; max-width: 1100px; }\n .muted { color: #666; }\n table { border-collapse: collapse; width: 100%; margin: 1rem 0; }\n th, td { border: 1px solid #ddd; padding: 0.5rem; text-align: left; vertical-align: top; }\n th { background: #f6f6f6; }\n pre { background: #f4f4f5; padding: 1rem; overflow: auto; max-height: 60vh; }\n .error { color: #b42318; }\n </style>\n</head>\n<body>\n <header>\n <h1>AgentInspect Studio</h1>\n <p class=\"muted\">Self-hosted, read-only. SQLite only. JSONL remains canonical.</p>\n <nav id=\"nav\">\n <a href=\"#projects\" data-page=\"projects\">Projects</a>\n <a href=\"#runs\" data-page=\"runs\">Runs</a>\n <a href=\"#sessions\" data-page=\"sessions\">Sessions</a>\n <a href=\"#suites\" data-page=\"suites\">Suites</a>\n <a href=\"#safety\" data-page=\"safety\">Safety</a>\n <a href=\"#imports\" data-page=\"imports\">Imports</a>\n <a href=\"#search\" data-page=\"search\">Search</a>\n </nav>\n </header>\n <main id=\"content\"><p class=\"muted\">Loading\u2026</p></main>\n <script>\n function escapeHtml(value) {\n return String(value ?? \"\")\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\");\n }\n\n let state = { projects: [], projectId: null };\n\n async function api(path) {\n const res = await fetch(path);\n const data = await res.json();\n if (!res.ok) throw new Error(data.error || res.statusText);\n return data;\n }\n\n function setPage(page) {\n document.querySelectorAll(\"#nav a\").forEach((a) => {\n a.classList.toggle(\"active\", a.dataset.page === page);\n });\n }\n\n function renderProjects() {\n setPage(\"projects\");\n const rows = state.projects.map((p) =>\n '<tr><td><a href=\"#runs\" data-select-project=\"' + escapeHtml(p.id) + '\">' +\n escapeHtml(p.label || p.id) + '</a></td><td>' + escapeHtml(p.traceCount) +\n '</td><td>' + escapeHtml(p.path) + '</td></tr>'\n ).join(\"\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Projects</h2><table><thead><tr><th>Project</th><th>Runs</th><th>Path</th></tr></thead><tbody>' +\n (rows || '<tr><td colspan=\"3\">No projects imported</td></tr>') + '</tbody></table>';\n document.querySelectorAll(\"[data-select-project]\").forEach((el) => {\n el.addEventListener(\"click\", (ev) => {\n ev.preventDefault();\n state.projectId = el.getAttribute(\"data-select-project\");\n location.hash = \"runs\";\n renderRuns();\n });\n });\n }\n\n async function renderRuns() {\n setPage(\"runs\");\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n if (!state.projectId) {\n document.getElementById(\"content\").innerHTML = '<p>Select a project first.</p>';\n return;\n }\n const data = await api(\"/api/projects/\" + encodeURIComponent(state.projectId) + \"/runs\");\n const rows = (data.runs || []).map((r) =>\n '<tr><td>' + escapeHtml(r.runId) + '</td><td>' + escapeHtml(r.status) +\n '</td><td>' + escapeHtml(r.name) + '</td><td>' + escapeHtml(r.durationMs) + '</td></tr>'\n ).join(\"\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Runs \u2014 ' + escapeHtml(state.projectId) + '</h2>' +\n '<table><thead><tr><th>Run ID</th><th>Status</th><th>Name</th><th>Duration ms</th></tr></thead><tbody>' +\n rows + '</tbody></table>';\n }\n\n async function renderSimple(title, path) {\n setPage(title.toLowerCase());\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n const data = await api(\"/api/projects/\" + encodeURIComponent(state.projectId) + \"/\" + path);\n document.getElementById(\"content\").innerHTML =\n '<h2>' + escapeHtml(title) + '</h2><pre>' + escapeHtml(JSON.stringify(data, null, 2)) + '</pre>';\n }\n\n async function renderImports() {\n setPage(\"imports\");\n const health = await api(\"/api/health\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Imports</h2><p>Registry: ' + escapeHtml(health.registryName) + '</p>' +\n '<pre>' + escapeHtml(JSON.stringify(health.warnings || [], null, 2)) + '</pre>';\n }\n\n async function renderSearch() {\n setPage(\"search\");\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n document.getElementById(\"content\").innerHTML =\n '<h2>Search</h2><p><input id=\"q\" placeholder=\"run id or name\" /> <button id=\"go\">Search</button></p><pre id=\"out\"></pre>';\n document.getElementById(\"go\").onclick = async () => {\n const q = document.getElementById(\"q\").value;\n const data = await api(\"/api/search?projectId=\" + encodeURIComponent(state.projectId) + \"&q=\" + encodeURIComponent(q));\n document.getElementById(\"out\").textContent = JSON.stringify(data, null, 2);\n };\n }\n\n async function boot() {\n const health = await api(\"/api/health\");\n const projects = await api(\"/api/projects\");\n state.projects = projects.projects || health.projects || [];\n const page = (location.hash || \"#projects\").slice(1);\n if (page === \"runs\") return renderRuns();\n if (page === \"sessions\") return renderSimple(\"Sessions\", \"sessions\");\n if (page === \"suites\") return renderSimple(\"Suites\", \"suites\");\n if (page === \"safety\") return renderSimple(\"Safety\", \"redaction\");\n if (page === \"imports\") return renderImports();\n if (page === \"search\") return renderSearch();\n return renderProjects();\n }\n\n window.addEventListener(\"hashchange\", () => boot().catch(showError));\n function showError(err) {\n document.getElementById(\"content\").innerHTML = '<p class=\"error\">' + escapeHtml(String(err)) + '</p>';\n }\n boot().catch(showError);\n </script>\n</body>\n</html>";
|
|
190
|
+
|
|
191
|
+
type StudioFetch = typeof fetch;
|
|
192
|
+
interface GitHubArtifactImportOptions {
|
|
193
|
+
db: Database.Database;
|
|
194
|
+
registryPath: string;
|
|
195
|
+
registry: StudioRegistry;
|
|
196
|
+
repo: string;
|
|
197
|
+
runId: string;
|
|
198
|
+
artifactName: string;
|
|
199
|
+
/** Explicit opt-in required — disabled by default. */
|
|
200
|
+
enabled: boolean;
|
|
201
|
+
tokenEnv?: string;
|
|
202
|
+
fetchImpl?: StudioFetch;
|
|
203
|
+
}
|
|
204
|
+
interface GitHubArtifactImportResult {
|
|
205
|
+
skipped: boolean;
|
|
206
|
+
reason?: string;
|
|
207
|
+
imported: boolean;
|
|
208
|
+
destPath?: string;
|
|
209
|
+
sourceKey?: string;
|
|
210
|
+
contentHash?: string;
|
|
211
|
+
registryImportWarnings: string[];
|
|
212
|
+
errors: string[];
|
|
213
|
+
}
|
|
214
|
+
declare function downloadGitHubArtifactArchive(options: {
|
|
215
|
+
repo: string;
|
|
216
|
+
runId: string;
|
|
217
|
+
artifactName: string;
|
|
218
|
+
token: string;
|
|
219
|
+
fetchImpl?: StudioFetch;
|
|
220
|
+
maxBytes?: number;
|
|
221
|
+
}): Promise<Buffer>;
|
|
222
|
+
declare function importGitHubArtifact(options: GitHubArtifactImportOptions): Promise<GitHubArtifactImportResult>;
|
|
223
|
+
declare function runStudioGitHubArtifactImport(options: {
|
|
224
|
+
workspacePath?: string;
|
|
225
|
+
dbPath?: string;
|
|
226
|
+
cwd?: string;
|
|
227
|
+
repo: string;
|
|
228
|
+
runId: string;
|
|
229
|
+
artifact: string;
|
|
230
|
+
tokenEnv?: string;
|
|
231
|
+
fetchImpl?: StudioFetch;
|
|
232
|
+
}): Promise<GitHubArtifactImportResult>;
|
|
233
|
+
|
|
234
|
+
interface BundleUploadImportOptions {
|
|
235
|
+
db: Database.Database;
|
|
236
|
+
registryPath: string;
|
|
237
|
+
registry: StudioRegistry;
|
|
238
|
+
bundlePath: string;
|
|
239
|
+
enabled: boolean;
|
|
240
|
+
/** Override registry ingest.bundleUpload.maxBytes for tests. */
|
|
241
|
+
maxBytes?: number;
|
|
242
|
+
}
|
|
243
|
+
interface BundleUploadImportResult {
|
|
244
|
+
skipped: boolean;
|
|
245
|
+
reason?: string;
|
|
246
|
+
imported: boolean;
|
|
247
|
+
destPath?: string;
|
|
248
|
+
sourceKey?: string;
|
|
249
|
+
errors: string[];
|
|
250
|
+
registryImportWarnings: string[];
|
|
251
|
+
}
|
|
252
|
+
declare function validateBundleDirectory(bundleDir: string): Promise<string[]>;
|
|
253
|
+
declare function importBundleUpload(options: BundleUploadImportOptions): Promise<BundleUploadImportResult>;
|
|
254
|
+
declare function runStudioBundleUploadImport(options: {
|
|
255
|
+
workspacePath?: string;
|
|
256
|
+
dbPath?: string;
|
|
257
|
+
cwd?: string;
|
|
258
|
+
bundlePath: string;
|
|
259
|
+
}): Promise<BundleUploadImportResult>;
|
|
260
|
+
|
|
261
|
+
declare const HTTP_INGEST_BUNDLE_PATH = "/api/ingest/bundle";
|
|
262
|
+
declare const HTTP_INGEST_ARTIFACT_PATH = "/api/ingest/artifact";
|
|
263
|
+
interface HttpIngestConfig {
|
|
264
|
+
enabled: boolean;
|
|
265
|
+
basePath: string;
|
|
266
|
+
tokenEnv: string;
|
|
267
|
+
maxBytes: number;
|
|
268
|
+
}
|
|
269
|
+
declare function resolveHttpIngestConfig(options: StudioServerOptions, registryHttp?: StudioRegistryHttpIngest): HttpIngestConfig;
|
|
270
|
+
declare function isHttpIngestRoute(pathname: string, config: HttpIngestConfig): boolean;
|
|
271
|
+
declare function handleHttpIngestRequest(req: IncomingMessage, res: ServerResponse, ctx: StudioContext, options: StudioServerOptions, pathname: string): Promise<boolean>;
|
|
272
|
+
|
|
273
|
+
declare function resolveIngestTokenEnv(options: {
|
|
274
|
+
tokenEnv?: string;
|
|
275
|
+
registryTokenEnv?: string;
|
|
276
|
+
}): string;
|
|
277
|
+
declare function resolveIngestToken(envName: string): string | undefined;
|
|
278
|
+
declare function extractIngestTokenFromRequest(headers: {
|
|
279
|
+
authorization?: string | string[] | undefined;
|
|
280
|
+
"x-agentinspect-token"?: string | string[] | undefined;
|
|
281
|
+
"x-agent-inspect-token"?: string | string[] | undefined;
|
|
282
|
+
}): string | undefined;
|
|
283
|
+
declare function isIngestTokenValid(provided: string | undefined, expected: string | undefined): boolean;
|
|
284
|
+
|
|
285
|
+
declare function resolveStudioRegistryPath(options: {
|
|
286
|
+
workspacePath?: string;
|
|
287
|
+
cwd?: string;
|
|
288
|
+
}): Promise<string>;
|
|
289
|
+
|
|
290
|
+
export { type BundleUploadImportResult, type FileDropImportOptions, type FileDropImportResult, type GitHubArtifactImportOptions, type GitHubArtifactImportResult, HTTP_INGEST_ARTIFACT_PATH, HTTP_INGEST_BUNDLE_PATH, type StudioFetch, type StudioRegistry, type StudioRegistryProject, type StudioServerInfo, type StudioServerOptions, createStudioContext, createStudioServer, downloadGitHubArtifactArchive, extractIngestTokenFromRequest, handleHttpIngestRequest, importBundleUpload, importFileDrop, importFileDropFromRegistry, importGitHubArtifact, isHttpIngestRoute, isIngestTokenValid, openStudioDb, parseStudioRegistry, readStudioRegistryFile, resolveHttpIngestConfig, resolveIngestToken, resolveIngestTokenEnv, resolveStudioDbPath, resolveStudioRegistryPath, runStudioBundleUploadImport, runStudioFileDropImport, runStudioGitHubArtifactImport, startStudioServer, studioIndexHtml, summarizeProjects, validateBundleDirectory };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { Server, IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
|
|
4
|
+
type StudioAuthMode = "none" | "basic";
|
|
5
|
+
|
|
6
|
+
interface StudioProjectRow {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string | null;
|
|
9
|
+
path: string;
|
|
10
|
+
workspaceDir: string;
|
|
11
|
+
projectName: string | null;
|
|
12
|
+
redactionProfile: string | null;
|
|
13
|
+
traceCount: number;
|
|
14
|
+
importedAt: string;
|
|
15
|
+
}
|
|
16
|
+
type IngestFileKind = "ci" | "bundle";
|
|
17
|
+
declare function resolveStudioDbPath(options: {
|
|
18
|
+
dbPath?: string;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
}): string;
|
|
21
|
+
declare function openStudioDb(dbPath: string): Database.Database;
|
|
22
|
+
|
|
23
|
+
declare const STUDIO_REGISTRY_SCHEMA_VERSION: "1.0";
|
|
24
|
+
interface StudioRegistryProject {
|
|
25
|
+
id: string;
|
|
26
|
+
path: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
suiteConfigs?: string[];
|
|
29
|
+
}
|
|
30
|
+
interface StudioRegistryImport {
|
|
31
|
+
ciArtifactsDir?: string;
|
|
32
|
+
bundlesDir?: string;
|
|
33
|
+
fileDropDir?: string;
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface StudioRegistryGitHubIngest {
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
tokenEnv?: string;
|
|
39
|
+
}
|
|
40
|
+
interface StudioRegistryHttpIngest {
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
path?: string;
|
|
43
|
+
tokenEnv?: string;
|
|
44
|
+
maxBytes?: number;
|
|
45
|
+
}
|
|
46
|
+
interface StudioRegistryBundleUploadIngest {
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
maxBytes?: number;
|
|
49
|
+
}
|
|
50
|
+
interface StudioRegistryFileDropIngest {
|
|
51
|
+
maxBytes?: number;
|
|
52
|
+
}
|
|
53
|
+
interface StudioRegistryIngest {
|
|
54
|
+
github?: StudioRegistryGitHubIngest;
|
|
55
|
+
http?: StudioRegistryHttpIngest;
|
|
56
|
+
bundleUpload?: StudioRegistryBundleUploadIngest;
|
|
57
|
+
fileDrop?: StudioRegistryFileDropIngest;
|
|
58
|
+
}
|
|
59
|
+
interface StudioRegistry {
|
|
60
|
+
schemaVersion: typeof STUDIO_REGISTRY_SCHEMA_VERSION;
|
|
61
|
+
name: string;
|
|
62
|
+
projects: StudioRegistryProject[];
|
|
63
|
+
import?: StudioRegistryImport;
|
|
64
|
+
ingest?: StudioRegistryIngest;
|
|
65
|
+
}
|
|
66
|
+
interface StudioRegistryParseResult {
|
|
67
|
+
ok: boolean;
|
|
68
|
+
registry?: StudioRegistry;
|
|
69
|
+
errors: string[];
|
|
70
|
+
warnings: string[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare function parseStudioRegistry(input: unknown): StudioRegistryParseResult;
|
|
74
|
+
declare function readStudioRegistryFile(filePath: string): Promise<StudioRegistryParseResult & {
|
|
75
|
+
path: string;
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
interface ImportedStudioProject extends StudioProjectRow {
|
|
79
|
+
suiteConfigPaths: string[];
|
|
80
|
+
}
|
|
81
|
+
interface StudioImportResult {
|
|
82
|
+
registryName: string;
|
|
83
|
+
projects: ImportedStudioProject[];
|
|
84
|
+
warnings: string[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface FileDropImportOptions {
|
|
88
|
+
db: Database.Database;
|
|
89
|
+
registryPath: string;
|
|
90
|
+
registry: StudioRegistry;
|
|
91
|
+
/** Explicit opt-in required — ingest is disabled by default. */
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
/** Override drop directory (CLI `--dir`). */
|
|
94
|
+
dropDir?: string;
|
|
95
|
+
/** Move successfully imported files into `dropDir/.imported/` instead of leaving copies. */
|
|
96
|
+
archiveAfterImport?: boolean;
|
|
97
|
+
/** Override registry ingest.fileDrop.maxBytes for tests. */
|
|
98
|
+
maxBytes?: number;
|
|
99
|
+
}
|
|
100
|
+
interface FileDropImportedFile {
|
|
101
|
+
sourceKey: string;
|
|
102
|
+
sourceName: string;
|
|
103
|
+
destPath: string;
|
|
104
|
+
kind: IngestFileKind;
|
|
105
|
+
contentHash: string;
|
|
106
|
+
archived: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface FileDropImportResult {
|
|
109
|
+
skipped: boolean;
|
|
110
|
+
reason?: string;
|
|
111
|
+
scanned: number;
|
|
112
|
+
imported: number;
|
|
113
|
+
skippedFiles: number;
|
|
114
|
+
errors: string[];
|
|
115
|
+
warnings: string[];
|
|
116
|
+
files: FileDropImportedFile[];
|
|
117
|
+
}
|
|
118
|
+
declare function importFileDrop(options: FileDropImportOptions): Promise<FileDropImportResult>;
|
|
119
|
+
declare function importFileDropFromRegistry(options: {
|
|
120
|
+
db: Database.Database;
|
|
121
|
+
registryPath: string;
|
|
122
|
+
registry: StudioRegistry;
|
|
123
|
+
enabled: boolean;
|
|
124
|
+
dropDir?: string;
|
|
125
|
+
archiveAfterImport?: boolean;
|
|
126
|
+
maxBytes?: number;
|
|
127
|
+
}): Promise<FileDropImportResult>;
|
|
128
|
+
declare function runStudioFileDropImport(options: {
|
|
129
|
+
workspacePath?: string;
|
|
130
|
+
dbPath?: string;
|
|
131
|
+
cwd?: string;
|
|
132
|
+
dropDir?: string;
|
|
133
|
+
archiveAfterImport?: boolean;
|
|
134
|
+
}): Promise<FileDropImportResult>;
|
|
135
|
+
|
|
136
|
+
interface StudioContext {
|
|
137
|
+
db: Database.Database;
|
|
138
|
+
dbPath: string;
|
|
139
|
+
registryPath: string;
|
|
140
|
+
registry: StudioRegistry;
|
|
141
|
+
importResult: StudioImportResult;
|
|
142
|
+
fileDropResult?: FileDropImportResult;
|
|
143
|
+
projects: ImportedStudioProject[];
|
|
144
|
+
}
|
|
145
|
+
declare function createStudioContext(options?: StudioServerOptions): Promise<StudioContext>;
|
|
146
|
+
declare function summarizeProjects(projects: StudioProjectRow[]): {
|
|
147
|
+
id: string;
|
|
148
|
+
label: string;
|
|
149
|
+
projectName: string | null;
|
|
150
|
+
traceCount: number;
|
|
151
|
+
redactionProfile: string | null;
|
|
152
|
+
importedAt: string;
|
|
153
|
+
}[];
|
|
154
|
+
|
|
155
|
+
interface StudioServerOptions {
|
|
156
|
+
host?: string;
|
|
157
|
+
port?: number;
|
|
158
|
+
workspacePath?: string;
|
|
159
|
+
dbPath?: string;
|
|
160
|
+
server?: boolean;
|
|
161
|
+
cwd?: string;
|
|
162
|
+
auth?: StudioAuthMode;
|
|
163
|
+
passwordEnv?: string;
|
|
164
|
+
/** Test hook: inject a preloaded context instead of importing on startup. */
|
|
165
|
+
context?: StudioContext;
|
|
166
|
+
/** Run file-drop ingest once on startup (requires explicit opt-in). */
|
|
167
|
+
ingestFileDrop?: boolean;
|
|
168
|
+
/** Move imported drop files into `.imported/` after successful copy. */
|
|
169
|
+
archiveFileDrop?: boolean;
|
|
170
|
+
/** Enable HTTP ingest routes (requires explicit opt-in + ingest token env). */
|
|
171
|
+
ingestHttp?: boolean;
|
|
172
|
+
/** Env var name for HTTP ingest token (default STUDIO_INGEST_TOKEN). */
|
|
173
|
+
ingestTokenEnv?: string;
|
|
174
|
+
}
|
|
175
|
+
interface StudioServerInfo {
|
|
176
|
+
host: string;
|
|
177
|
+
port: number;
|
|
178
|
+
url: string;
|
|
179
|
+
mode: "studio";
|
|
180
|
+
workspacePath?: string;
|
|
181
|
+
dbPath?: string;
|
|
182
|
+
registryName?: string;
|
|
183
|
+
projectCount?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare function createStudioServer(options?: StudioServerOptions): Server;
|
|
187
|
+
declare function startStudioServer(options?: StudioServerOptions): Promise<StudioServerInfo>;
|
|
188
|
+
|
|
189
|
+
declare const studioIndexHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; style-src 'unsafe-inline'; script-src 'unsafe-inline'\" />\n <title>AgentInspect Studio</title>\n <style>\n body { font-family: system-ui, sans-serif; margin: 0; line-height: 1.4; color: #111; }\n header { padding: 1rem 1.5rem; border-bottom: 1px solid #ddd; background: #fafafa; }\n nav a { margin-right: 1rem; color: #0b57d0; text-decoration: none; }\n nav a.active { font-weight: 600; text-decoration: underline; }\n main { padding: 1.5rem; max-width: 1100px; }\n .muted { color: #666; }\n table { border-collapse: collapse; width: 100%; margin: 1rem 0; }\n th, td { border: 1px solid #ddd; padding: 0.5rem; text-align: left; vertical-align: top; }\n th { background: #f6f6f6; }\n pre { background: #f4f4f5; padding: 1rem; overflow: auto; max-height: 60vh; }\n .error { color: #b42318; }\n </style>\n</head>\n<body>\n <header>\n <h1>AgentInspect Studio</h1>\n <p class=\"muted\">Self-hosted, read-only. SQLite only. JSONL remains canonical.</p>\n <nav id=\"nav\">\n <a href=\"#projects\" data-page=\"projects\">Projects</a>\n <a href=\"#runs\" data-page=\"runs\">Runs</a>\n <a href=\"#sessions\" data-page=\"sessions\">Sessions</a>\n <a href=\"#suites\" data-page=\"suites\">Suites</a>\n <a href=\"#safety\" data-page=\"safety\">Safety</a>\n <a href=\"#imports\" data-page=\"imports\">Imports</a>\n <a href=\"#search\" data-page=\"search\">Search</a>\n </nav>\n </header>\n <main id=\"content\"><p class=\"muted\">Loading\u2026</p></main>\n <script>\n function escapeHtml(value) {\n return String(value ?? \"\")\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\");\n }\n\n let state = { projects: [], projectId: null };\n\n async function api(path) {\n const res = await fetch(path);\n const data = await res.json();\n if (!res.ok) throw new Error(data.error || res.statusText);\n return data;\n }\n\n function setPage(page) {\n document.querySelectorAll(\"#nav a\").forEach((a) => {\n a.classList.toggle(\"active\", a.dataset.page === page);\n });\n }\n\n function renderProjects() {\n setPage(\"projects\");\n const rows = state.projects.map((p) =>\n '<tr><td><a href=\"#runs\" data-select-project=\"' + escapeHtml(p.id) + '\">' +\n escapeHtml(p.label || p.id) + '</a></td><td>' + escapeHtml(p.traceCount) +\n '</td><td>' + escapeHtml(p.path) + '</td></tr>'\n ).join(\"\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Projects</h2><table><thead><tr><th>Project</th><th>Runs</th><th>Path</th></tr></thead><tbody>' +\n (rows || '<tr><td colspan=\"3\">No projects imported</td></tr>') + '</tbody></table>';\n document.querySelectorAll(\"[data-select-project]\").forEach((el) => {\n el.addEventListener(\"click\", (ev) => {\n ev.preventDefault();\n state.projectId = el.getAttribute(\"data-select-project\");\n location.hash = \"runs\";\n renderRuns();\n });\n });\n }\n\n async function renderRuns() {\n setPage(\"runs\");\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n if (!state.projectId) {\n document.getElementById(\"content\").innerHTML = '<p>Select a project first.</p>';\n return;\n }\n const data = await api(\"/api/projects/\" + encodeURIComponent(state.projectId) + \"/runs\");\n const rows = (data.runs || []).map((r) =>\n '<tr><td>' + escapeHtml(r.runId) + '</td><td>' + escapeHtml(r.status) +\n '</td><td>' + escapeHtml(r.name) + '</td><td>' + escapeHtml(r.durationMs) + '</td></tr>'\n ).join(\"\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Runs \u2014 ' + escapeHtml(state.projectId) + '</h2>' +\n '<table><thead><tr><th>Run ID</th><th>Status</th><th>Name</th><th>Duration ms</th></tr></thead><tbody>' +\n rows + '</tbody></table>';\n }\n\n async function renderSimple(title, path) {\n setPage(title.toLowerCase());\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n const data = await api(\"/api/projects/\" + encodeURIComponent(state.projectId) + \"/\" + path);\n document.getElementById(\"content\").innerHTML =\n '<h2>' + escapeHtml(title) + '</h2><pre>' + escapeHtml(JSON.stringify(data, null, 2)) + '</pre>';\n }\n\n async function renderImports() {\n setPage(\"imports\");\n const health = await api(\"/api/health\");\n document.getElementById(\"content\").innerHTML =\n '<h2>Imports</h2><p>Registry: ' + escapeHtml(health.registryName) + '</p>' +\n '<pre>' + escapeHtml(JSON.stringify(health.warnings || [], null, 2)) + '</pre>';\n }\n\n async function renderSearch() {\n setPage(\"search\");\n if (!state.projectId && state.projects[0]) state.projectId = state.projects[0].id;\n document.getElementById(\"content\").innerHTML =\n '<h2>Search</h2><p><input id=\"q\" placeholder=\"run id or name\" /> <button id=\"go\">Search</button></p><pre id=\"out\"></pre>';\n document.getElementById(\"go\").onclick = async () => {\n const q = document.getElementById(\"q\").value;\n const data = await api(\"/api/search?projectId=\" + encodeURIComponent(state.projectId) + \"&q=\" + encodeURIComponent(q));\n document.getElementById(\"out\").textContent = JSON.stringify(data, null, 2);\n };\n }\n\n async function boot() {\n const health = await api(\"/api/health\");\n const projects = await api(\"/api/projects\");\n state.projects = projects.projects || health.projects || [];\n const page = (location.hash || \"#projects\").slice(1);\n if (page === \"runs\") return renderRuns();\n if (page === \"sessions\") return renderSimple(\"Sessions\", \"sessions\");\n if (page === \"suites\") return renderSimple(\"Suites\", \"suites\");\n if (page === \"safety\") return renderSimple(\"Safety\", \"redaction\");\n if (page === \"imports\") return renderImports();\n if (page === \"search\") return renderSearch();\n return renderProjects();\n }\n\n window.addEventListener(\"hashchange\", () => boot().catch(showError));\n function showError(err) {\n document.getElementById(\"content\").innerHTML = '<p class=\"error\">' + escapeHtml(String(err)) + '</p>';\n }\n boot().catch(showError);\n </script>\n</body>\n</html>";
|
|
190
|
+
|
|
191
|
+
type StudioFetch = typeof fetch;
|
|
192
|
+
interface GitHubArtifactImportOptions {
|
|
193
|
+
db: Database.Database;
|
|
194
|
+
registryPath: string;
|
|
195
|
+
registry: StudioRegistry;
|
|
196
|
+
repo: string;
|
|
197
|
+
runId: string;
|
|
198
|
+
artifactName: string;
|
|
199
|
+
/** Explicit opt-in required — disabled by default. */
|
|
200
|
+
enabled: boolean;
|
|
201
|
+
tokenEnv?: string;
|
|
202
|
+
fetchImpl?: StudioFetch;
|
|
203
|
+
}
|
|
204
|
+
interface GitHubArtifactImportResult {
|
|
205
|
+
skipped: boolean;
|
|
206
|
+
reason?: string;
|
|
207
|
+
imported: boolean;
|
|
208
|
+
destPath?: string;
|
|
209
|
+
sourceKey?: string;
|
|
210
|
+
contentHash?: string;
|
|
211
|
+
registryImportWarnings: string[];
|
|
212
|
+
errors: string[];
|
|
213
|
+
}
|
|
214
|
+
declare function downloadGitHubArtifactArchive(options: {
|
|
215
|
+
repo: string;
|
|
216
|
+
runId: string;
|
|
217
|
+
artifactName: string;
|
|
218
|
+
token: string;
|
|
219
|
+
fetchImpl?: StudioFetch;
|
|
220
|
+
maxBytes?: number;
|
|
221
|
+
}): Promise<Buffer>;
|
|
222
|
+
declare function importGitHubArtifact(options: GitHubArtifactImportOptions): Promise<GitHubArtifactImportResult>;
|
|
223
|
+
declare function runStudioGitHubArtifactImport(options: {
|
|
224
|
+
workspacePath?: string;
|
|
225
|
+
dbPath?: string;
|
|
226
|
+
cwd?: string;
|
|
227
|
+
repo: string;
|
|
228
|
+
runId: string;
|
|
229
|
+
artifact: string;
|
|
230
|
+
tokenEnv?: string;
|
|
231
|
+
fetchImpl?: StudioFetch;
|
|
232
|
+
}): Promise<GitHubArtifactImportResult>;
|
|
233
|
+
|
|
234
|
+
interface BundleUploadImportOptions {
|
|
235
|
+
db: Database.Database;
|
|
236
|
+
registryPath: string;
|
|
237
|
+
registry: StudioRegistry;
|
|
238
|
+
bundlePath: string;
|
|
239
|
+
enabled: boolean;
|
|
240
|
+
/** Override registry ingest.bundleUpload.maxBytes for tests. */
|
|
241
|
+
maxBytes?: number;
|
|
242
|
+
}
|
|
243
|
+
interface BundleUploadImportResult {
|
|
244
|
+
skipped: boolean;
|
|
245
|
+
reason?: string;
|
|
246
|
+
imported: boolean;
|
|
247
|
+
destPath?: string;
|
|
248
|
+
sourceKey?: string;
|
|
249
|
+
errors: string[];
|
|
250
|
+
registryImportWarnings: string[];
|
|
251
|
+
}
|
|
252
|
+
declare function validateBundleDirectory(bundleDir: string): Promise<string[]>;
|
|
253
|
+
declare function importBundleUpload(options: BundleUploadImportOptions): Promise<BundleUploadImportResult>;
|
|
254
|
+
declare function runStudioBundleUploadImport(options: {
|
|
255
|
+
workspacePath?: string;
|
|
256
|
+
dbPath?: string;
|
|
257
|
+
cwd?: string;
|
|
258
|
+
bundlePath: string;
|
|
259
|
+
}): Promise<BundleUploadImportResult>;
|
|
260
|
+
|
|
261
|
+
declare const HTTP_INGEST_BUNDLE_PATH = "/api/ingest/bundle";
|
|
262
|
+
declare const HTTP_INGEST_ARTIFACT_PATH = "/api/ingest/artifact";
|
|
263
|
+
interface HttpIngestConfig {
|
|
264
|
+
enabled: boolean;
|
|
265
|
+
basePath: string;
|
|
266
|
+
tokenEnv: string;
|
|
267
|
+
maxBytes: number;
|
|
268
|
+
}
|
|
269
|
+
declare function resolveHttpIngestConfig(options: StudioServerOptions, registryHttp?: StudioRegistryHttpIngest): HttpIngestConfig;
|
|
270
|
+
declare function isHttpIngestRoute(pathname: string, config: HttpIngestConfig): boolean;
|
|
271
|
+
declare function handleHttpIngestRequest(req: IncomingMessage, res: ServerResponse, ctx: StudioContext, options: StudioServerOptions, pathname: string): Promise<boolean>;
|
|
272
|
+
|
|
273
|
+
declare function resolveIngestTokenEnv(options: {
|
|
274
|
+
tokenEnv?: string;
|
|
275
|
+
registryTokenEnv?: string;
|
|
276
|
+
}): string;
|
|
277
|
+
declare function resolveIngestToken(envName: string): string | undefined;
|
|
278
|
+
declare function extractIngestTokenFromRequest(headers: {
|
|
279
|
+
authorization?: string | string[] | undefined;
|
|
280
|
+
"x-agentinspect-token"?: string | string[] | undefined;
|
|
281
|
+
"x-agent-inspect-token"?: string | string[] | undefined;
|
|
282
|
+
}): string | undefined;
|
|
283
|
+
declare function isIngestTokenValid(provided: string | undefined, expected: string | undefined): boolean;
|
|
284
|
+
|
|
285
|
+
declare function resolveStudioRegistryPath(options: {
|
|
286
|
+
workspacePath?: string;
|
|
287
|
+
cwd?: string;
|
|
288
|
+
}): Promise<string>;
|
|
289
|
+
|
|
290
|
+
export { type BundleUploadImportResult, type FileDropImportOptions, type FileDropImportResult, type GitHubArtifactImportOptions, type GitHubArtifactImportResult, HTTP_INGEST_ARTIFACT_PATH, HTTP_INGEST_BUNDLE_PATH, type StudioFetch, type StudioRegistry, type StudioRegistryProject, type StudioServerInfo, type StudioServerOptions, createStudioContext, createStudioServer, downloadGitHubArtifactArchive, extractIngestTokenFromRequest, handleHttpIngestRequest, importBundleUpload, importFileDrop, importFileDropFromRegistry, importGitHubArtifact, isHttpIngestRoute, isIngestTokenValid, openStudioDb, parseStudioRegistry, readStudioRegistryFile, resolveHttpIngestConfig, resolveIngestToken, resolveIngestTokenEnv, resolveStudioDbPath, resolveStudioRegistryPath, runStudioBundleUploadImport, runStudioFileDropImport, runStudioGitHubArtifactImport, startStudioServer, studioIndexHtml, summarizeProjects, validateBundleDirectory };
|