@gmickel/gno 2.15.0 → 2.16.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 +1 -1
- package/assets/skill/cli-reference.md +4 -2
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.16.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.16.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +1 -1
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/embed.ts +2 -2
- package/src/cli/commands/links.ts +1 -1
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/program.ts +20 -36
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +142 -60
- package/src/embed/retry.ts +39 -33
- package/src/embed/variant-backlog.ts +546 -114
- package/src/embed/variant-retry.ts +157 -48
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +7 -5
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +598 -329
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/vsearch.ts +250 -152
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +18 -4
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/index.ts +2 -0
- package/src/store/sqlite/adapter.ts +1217 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +28 -45
- package/src/store/vector/proof-cache.ts +103 -0
- package/src/store/vector/sqlite-vec.ts +230 -139
- package/src/store/vector/stats.ts +29 -73
- package/src/store/vector/status.ts +151 -52
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +10 -0
- package/src/store/vector/variant-search.ts +771 -109
- package/src/store/vector/variants.ts +495 -139
- package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
package/src/serve/server.ts
CHANGED
|
@@ -293,6 +293,111 @@ export function acceptsGzip(acceptEncoding: string | null): boolean {
|
|
|
293
293
|
return (wildcardQ ?? 0) > 0;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
const API_GZIP_MIN_BYTES = 2048;
|
|
297
|
+
const API_GZIP_EXEMPT_ROUTES = new Set(["/api/doc-asset", "/api/events"]);
|
|
298
|
+
|
|
299
|
+
function appendVaryAcceptEncoding(headers: Headers): void {
|
|
300
|
+
const existing = headers.get("vary");
|
|
301
|
+
if (!existing) {
|
|
302
|
+
headers.set("Vary", "Accept-Encoding");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const tokens = existing
|
|
306
|
+
.split(",")
|
|
307
|
+
.map((part) => part.trim().toLowerCase())
|
|
308
|
+
.filter(Boolean);
|
|
309
|
+
if (!tokens.includes("accept-encoding")) {
|
|
310
|
+
headers.set("Vary", `${existing}, Accept-Encoding`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Compress REST `/api/*` JSON responses larger than 2 KiB when the client
|
|
316
|
+
* advertises gzip support, preserving all existing headers and adding
|
|
317
|
+
* `Vary: Accept-Encoding`.
|
|
318
|
+
*/
|
|
319
|
+
export async function maybeCompressApiJsonResponse(
|
|
320
|
+
req: Request,
|
|
321
|
+
response: Response
|
|
322
|
+
): Promise<Response> {
|
|
323
|
+
if (
|
|
324
|
+
req.method === "HEAD" ||
|
|
325
|
+
response.body === null ||
|
|
326
|
+
response.headers.get("content-encoding") !== null
|
|
327
|
+
) {
|
|
328
|
+
return response;
|
|
329
|
+
}
|
|
330
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
331
|
+
if (!contentType.includes("application/json")) {
|
|
332
|
+
return response;
|
|
333
|
+
}
|
|
334
|
+
if (!acceptsGzip(req.headers.get("accept-encoding"))) {
|
|
335
|
+
return response;
|
|
336
|
+
}
|
|
337
|
+
const raw = new Uint8Array(await response.arrayBuffer());
|
|
338
|
+
const headers = new Headers(response.headers);
|
|
339
|
+
if (raw.byteLength <= API_GZIP_MIN_BYTES) {
|
|
340
|
+
headers.set("Content-Length", String(raw.byteLength));
|
|
341
|
+
return new Response(raw, {
|
|
342
|
+
status: response.status,
|
|
343
|
+
statusText: response.statusText,
|
|
344
|
+
headers,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const compressed = new Uint8Array(Bun.gzipSync(raw));
|
|
348
|
+
headers.set("Content-Encoding", "gzip");
|
|
349
|
+
headers.set("Content-Length", String(compressed.byteLength));
|
|
350
|
+
appendVaryAcceptEncoding(headers);
|
|
351
|
+
return new Response(compressed, {
|
|
352
|
+
status: response.status,
|
|
353
|
+
statusText: response.statusText,
|
|
354
|
+
headers,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function withApiJsonCompression<T extends Record<string, unknown>>(
|
|
359
|
+
routes: T
|
|
360
|
+
): T {
|
|
361
|
+
const isMethodTable = (route: unknown): route is Record<string, unknown> =>
|
|
362
|
+
route !== null &&
|
|
363
|
+
typeof route === "object" &&
|
|
364
|
+
Object.getPrototypeOf(route) === Object.prototype;
|
|
365
|
+
|
|
366
|
+
const wrap =
|
|
367
|
+
(
|
|
368
|
+
handler: (req: Request, server: unknown) => Response | Promise<Response>
|
|
369
|
+
) =>
|
|
370
|
+
async (req: Request, server: unknown): Promise<Response> =>
|
|
371
|
+
maybeCompressApiJsonResponse(req, await handler(req, server));
|
|
372
|
+
|
|
373
|
+
const wrapped: Record<string, unknown> = { ...routes };
|
|
374
|
+
for (const [path, route] of Object.entries(routes)) {
|
|
375
|
+
if (!path.startsWith("/api/") || API_GZIP_EXEMPT_ROUTES.has(path)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (typeof route === "function") {
|
|
379
|
+
wrapped[path] = wrap(
|
|
380
|
+
route as (req: Request, server: unknown) => Response | Promise<Response>
|
|
381
|
+
);
|
|
382
|
+
} else if (isMethodTable(route)) {
|
|
383
|
+
wrapped[path] = Object.fromEntries(
|
|
384
|
+
Object.entries(route).map(([method, handler]) => [
|
|
385
|
+
method,
|
|
386
|
+
typeof handler === "function"
|
|
387
|
+
? wrap(
|
|
388
|
+
handler as (
|
|
389
|
+
req: Request,
|
|
390
|
+
server: unknown
|
|
391
|
+
) => Response | Promise<Response>
|
|
392
|
+
)
|
|
393
|
+
: handler,
|
|
394
|
+
])
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return wrapped as T;
|
|
399
|
+
}
|
|
400
|
+
|
|
296
401
|
export type PublicFetchFallbackOptions = {
|
|
297
402
|
isDev: boolean;
|
|
298
403
|
spaBundleSource: SpaBundleSource | null;
|
|
@@ -311,7 +416,28 @@ export function createPublicFetchFallback(
|
|
|
311
416
|
options: PublicFetchFallbackOptions
|
|
312
417
|
): (req: Request) => Promise<Response> {
|
|
313
418
|
const { isDev, spaBundleSource } = options;
|
|
314
|
-
const gzipBodies = new Map<
|
|
419
|
+
const gzipBodies = new Map<
|
|
420
|
+
string,
|
|
421
|
+
{ body: Uint8Array<ArrayBuffer>; contentType: string | null }
|
|
422
|
+
>();
|
|
423
|
+
|
|
424
|
+
const buildCachedGzipResponse = (
|
|
425
|
+
req: Request,
|
|
426
|
+
cached: { body: Uint8Array<ArrayBuffer>; contentType: string | null }
|
|
427
|
+
): Response => {
|
|
428
|
+
const headers = new Headers();
|
|
429
|
+
if (cached.contentType) {
|
|
430
|
+
headers.set("Content-Type", cached.contentType);
|
|
431
|
+
}
|
|
432
|
+
headers.set("Cache-Control", SPA_CHUNK_CACHE_CONTROL);
|
|
433
|
+
headers.set("Vary", "Accept-Encoding");
|
|
434
|
+
headers.set("Content-Encoding", "gzip");
|
|
435
|
+
headers.set("Content-Length", String(cached.body.byteLength));
|
|
436
|
+
return new Response(req.method === "HEAD" ? null : cached.body, {
|
|
437
|
+
status: 200,
|
|
438
|
+
headers,
|
|
439
|
+
});
|
|
440
|
+
};
|
|
315
441
|
|
|
316
442
|
const gzipBodyFor = async (
|
|
317
443
|
req: Request,
|
|
@@ -321,7 +447,7 @@ export function createPublicFetchFallback(
|
|
|
321
447
|
const cached = gzipBodies.get(pathname);
|
|
322
448
|
if (cached) {
|
|
323
449
|
await asset.body?.cancel();
|
|
324
|
-
return cached;
|
|
450
|
+
return cached.body;
|
|
325
451
|
}
|
|
326
452
|
// HEAD reaches the source as HEAD, so its body is empty; fetch the bytes.
|
|
327
453
|
const identity =
|
|
@@ -332,7 +458,12 @@ export function createPublicFetchFallback(
|
|
|
332
458
|
const encoded = new Uint8Array(
|
|
333
459
|
Bun.gzipSync(new Uint8Array(await identity.arrayBuffer()))
|
|
334
460
|
);
|
|
335
|
-
gzipBodies.set(pathname,
|
|
461
|
+
gzipBodies.set(pathname, {
|
|
462
|
+
body: encoded,
|
|
463
|
+
contentType:
|
|
464
|
+
asset.headers.get("content-type") ??
|
|
465
|
+
identity.headers.get("content-type"),
|
|
466
|
+
});
|
|
336
467
|
return encoded;
|
|
337
468
|
};
|
|
338
469
|
|
|
@@ -375,6 +506,19 @@ export function createPublicFetchFallback(
|
|
|
375
506
|
});
|
|
376
507
|
}
|
|
377
508
|
if (spaBundleSource && (req.method === "GET" || req.method === "HEAD")) {
|
|
509
|
+
if (
|
|
510
|
+
!isDev &&
|
|
511
|
+
isHashedSpaChunkPath(pathname) &&
|
|
512
|
+
acceptsGzip(req.headers.get("accept-encoding"))
|
|
513
|
+
) {
|
|
514
|
+
const cached = gzipBodies.get(pathname);
|
|
515
|
+
if (cached) {
|
|
516
|
+
return withSecurityHeaders(
|
|
517
|
+
buildCachedGzipResponse(req, cached),
|
|
518
|
+
isDev
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
378
522
|
const asset = await spaBundleSource.fetch(req);
|
|
379
523
|
if (asset.status === 200 && !isDev && isHashedSpaChunkPath(pathname)) {
|
|
380
524
|
return withSecurityHeaders(
|
|
@@ -526,24 +670,56 @@ export async function startServer(
|
|
|
526
670
|
spaBundleSource?.entryPath ??
|
|
527
671
|
`/__gno_spa_${crypto.randomUUID().replaceAll("-", "")}`;
|
|
528
672
|
let spaHtmlCache: {
|
|
529
|
-
body: ArrayBuffer
|
|
673
|
+
body: Uint8Array<ArrayBuffer>;
|
|
530
674
|
contentType: string;
|
|
531
|
-
etag: string
|
|
675
|
+
etag: string;
|
|
532
676
|
} | null = null;
|
|
533
677
|
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
678
|
+
const matchesIfNoneMatch = (
|
|
679
|
+
headerValue: string | null,
|
|
680
|
+
etag: string
|
|
681
|
+
): boolean => {
|
|
682
|
+
if (!headerValue) return false;
|
|
683
|
+
const normalizeTag = (tag: string): string =>
|
|
684
|
+
tag.trim().replace(/^W\//, "");
|
|
685
|
+
const target = normalizeTag(etag);
|
|
686
|
+
for (const part of headerValue.split(",")) {
|
|
687
|
+
const trimmed = part.trim();
|
|
688
|
+
if (trimmed === "*" || normalizeTag(trimmed) === target) {
|
|
689
|
+
return true;
|
|
541
690
|
}
|
|
691
|
+
}
|
|
692
|
+
return false;
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
const buildSpaHtmlResponse = (
|
|
696
|
+
req: Request | undefined,
|
|
697
|
+
cached: {
|
|
698
|
+
body: Uint8Array<ArrayBuffer>;
|
|
699
|
+
contentType: string;
|
|
700
|
+
etag: string;
|
|
701
|
+
}
|
|
702
|
+
): Response => {
|
|
703
|
+
const headers = new Headers({
|
|
704
|
+
"Content-Type": cached.contentType,
|
|
705
|
+
ETag: cached.etag,
|
|
706
|
+
});
|
|
707
|
+
if (
|
|
708
|
+
matchesIfNoneMatch(req?.headers.get("if-none-match") ?? null, cached.etag)
|
|
709
|
+
) {
|
|
542
710
|
return withSecurityHeaders(
|
|
543
|
-
new Response(
|
|
711
|
+
new Response(null, { status: 304, headers }),
|
|
544
712
|
isDev
|
|
545
713
|
);
|
|
546
714
|
}
|
|
715
|
+
headers.set("Content-Length", String(cached.body.byteLength));
|
|
716
|
+
return withSecurityHeaders(new Response(cached.body, { headers }), isDev);
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
const serveSpaHtml = async (req?: Request): Promise<Response> => {
|
|
720
|
+
if (!isDev && spaHtmlCache) {
|
|
721
|
+
return buildSpaHtmlResponse(req, spaHtmlCache);
|
|
722
|
+
}
|
|
547
723
|
const boundPort = server.port ?? port;
|
|
548
724
|
const internalRequest = new Request(
|
|
549
725
|
`${loopbackHttpOrigin(gatewayConfig.host, boundPort)}${spaInternalPath}`
|
|
@@ -558,22 +734,16 @@ export async function startServer(
|
|
|
558
734
|
);
|
|
559
735
|
}
|
|
560
736
|
if (!isDev) {
|
|
737
|
+
const body = new Uint8Array(await raw.arrayBuffer());
|
|
738
|
+
const etag =
|
|
739
|
+
raw.headers.get("etag") ?? `W/"${Bun.hash(body).toString(16)}"`;
|
|
561
740
|
spaHtmlCache = {
|
|
562
|
-
body
|
|
741
|
+
body,
|
|
563
742
|
contentType:
|
|
564
743
|
raw.headers.get("content-type") ?? "text/html;charset=utf-8",
|
|
565
|
-
etag
|
|
744
|
+
etag,
|
|
566
745
|
};
|
|
567
|
-
|
|
568
|
-
"Content-Type": spaHtmlCache.contentType,
|
|
569
|
-
});
|
|
570
|
-
if (spaHtmlCache.etag) {
|
|
571
|
-
headers.set("ETag", spaHtmlCache.etag);
|
|
572
|
-
}
|
|
573
|
-
return withSecurityHeaders(
|
|
574
|
-
new Response(spaHtmlCache.body.slice(0), { headers }),
|
|
575
|
-
isDev
|
|
576
|
-
);
|
|
746
|
+
return buildSpaHtmlResponse(req, spaHtmlCache);
|
|
577
747
|
}
|
|
578
748
|
return withSecurityHeaders(raw, isDev);
|
|
579
749
|
};
|
|
@@ -591,1192 +761,1212 @@ export async function startServer(
|
|
|
591
761
|
development: isDev,
|
|
592
762
|
|
|
593
763
|
// Static routes - Bun handles HTML bundling and /_bun/* assets automatically
|
|
594
|
-
routes:
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
764
|
+
routes: withApiJsonCompression(
|
|
765
|
+
withRemoteHostPathRedaction({
|
|
766
|
+
"/mcp": gateway.route,
|
|
767
|
+
...clipperRoutesForBind(
|
|
768
|
+
isHttpGatewayLoopbackBind(gatewayConfig.host),
|
|
769
|
+
clipperGateway
|
|
770
|
+
),
|
|
771
|
+
// Injected-server tests only. Real runs keep the raw HTMLBundle off the
|
|
772
|
+
// public listener in createSpaBundleSource above.
|
|
773
|
+
...(spaBundleSource ? {} : { [spaInternalPath]: homepage }),
|
|
774
|
+
// SPA routes - same React app, security envelope on every document
|
|
775
|
+
"/": spaPageRoute,
|
|
776
|
+
"/search": spaPageRoute,
|
|
777
|
+
"/browse": spaPageRoute,
|
|
778
|
+
"/doc": spaPageRoute,
|
|
779
|
+
"/edit": spaPageRoute,
|
|
780
|
+
"/collections": spaPageRoute,
|
|
781
|
+
"/connectors": spaPageRoute,
|
|
782
|
+
"/traces": spaPageRoute,
|
|
783
|
+
"/sessions": spaPageRoute,
|
|
784
|
+
"/context/compiled": spaPageRoute,
|
|
785
|
+
"/ask": spaPageRoute,
|
|
786
|
+
"/graph": spaPageRoute,
|
|
787
|
+
"/clipper/pair": spaPageRoute,
|
|
617
788
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
),
|
|
633
|
-
},
|
|
634
|
-
"/api/traces/export": {
|
|
635
|
-
POST: async (req: Request) => {
|
|
636
|
-
if (!isRequestAllowed(req, port)) {
|
|
637
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
638
|
-
}
|
|
639
|
-
return withSecurityHeaders(
|
|
640
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
641
|
-
handleTraceExport(store, req, ctxHolder.config.collections)
|
|
789
|
+
// API routes with CSRF protection wrapper
|
|
790
|
+
"/api/health": {
|
|
791
|
+
GET: () => withSecurityHeaders(handleHealth(), isDev),
|
|
792
|
+
},
|
|
793
|
+
"/api/status": {
|
|
794
|
+
GET: async (req: Request) =>
|
|
795
|
+
withSecurityHeaders(
|
|
796
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
797
|
+
handleStatus(ctxHolder.current, {
|
|
798
|
+
getResidentStatus: () =>
|
|
799
|
+
(runtime as ResidentRuntime).getStatus(),
|
|
800
|
+
})
|
|
801
|
+
),
|
|
802
|
+
isDev
|
|
642
803
|
),
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
804
|
+
},
|
|
805
|
+
"/api/traces/export": {
|
|
806
|
+
POST: async (req: Request) => {
|
|
807
|
+
if (!isRequestAllowed(req, port)) {
|
|
808
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
809
|
+
}
|
|
810
|
+
return withSecurityHeaders(
|
|
811
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
812
|
+
handleTraceExport(store, req, ctxHolder.config.collections)
|
|
813
|
+
),
|
|
814
|
+
isDev
|
|
815
|
+
);
|
|
816
|
+
},
|
|
817
|
+
},
|
|
818
|
+
"/api/traces/:traceId/judgments": {
|
|
819
|
+
POST: async (req: Request) => {
|
|
820
|
+
if (!isRequestAllowed(req, port)) {
|
|
821
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
822
|
+
}
|
|
823
|
+
const traceId = decodeURIComponent(
|
|
824
|
+
new URL(req.url).pathname.split("/")[3] ?? ""
|
|
825
|
+
);
|
|
826
|
+
return withSecurityHeaders(
|
|
827
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
828
|
+
handleTraceLabel(store, traceId, req)
|
|
829
|
+
),
|
|
830
|
+
isDev
|
|
831
|
+
);
|
|
832
|
+
},
|
|
833
|
+
},
|
|
834
|
+
"/api/traces/:traceId": {
|
|
835
|
+
GET: async (req: Request) => {
|
|
836
|
+
const traceId = decodeURIComponent(
|
|
837
|
+
new URL(req.url).pathname.split("/")[3] ?? ""
|
|
838
|
+
);
|
|
839
|
+
return withSecurityHeaders(
|
|
840
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
841
|
+
handleTraceShow(store, traceId, req)
|
|
842
|
+
),
|
|
843
|
+
isDev
|
|
844
|
+
);
|
|
845
|
+
},
|
|
846
|
+
DELETE: async (req: Request) => {
|
|
847
|
+
if (!isRequestAllowed(req, port)) {
|
|
848
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
849
|
+
}
|
|
850
|
+
const traceId = decodeURIComponent(
|
|
851
|
+
new URL(req.url).pathname.split("/")[3] ?? ""
|
|
852
|
+
);
|
|
853
|
+
return withSecurityHeaders(
|
|
854
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
855
|
+
handleTraceDelete(store, traceId)
|
|
856
|
+
),
|
|
857
|
+
isDev
|
|
858
|
+
);
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
"/api/traces": {
|
|
862
|
+
GET: async (req: Request) =>
|
|
863
|
+
withSecurityHeaders(
|
|
864
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
865
|
+
handleTraceList(store, req)
|
|
866
|
+
),
|
|
867
|
+
isDev
|
|
658
868
|
),
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
869
|
+
DELETE: async (req: Request) => {
|
|
870
|
+
if (!isRequestAllowed(req, port)) {
|
|
871
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
872
|
+
}
|
|
873
|
+
return withSecurityHeaders(
|
|
874
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
875
|
+
handleTracePurge(store)
|
|
876
|
+
),
|
|
877
|
+
isDev
|
|
878
|
+
);
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
"/api/resident/status": {
|
|
882
|
+
GET: () =>
|
|
883
|
+
withSecurityHeaders(
|
|
884
|
+
handleResidentStatus(() =>
|
|
885
|
+
(runtime as ResidentRuntime).getStatus()
|
|
886
|
+
),
|
|
887
|
+
isDev
|
|
671
888
|
),
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
const traceId = decodeURIComponent(
|
|
680
|
-
new URL(req.url).pathname.split("/")[3] ?? ""
|
|
681
|
-
);
|
|
682
|
-
return withSecurityHeaders(
|
|
683
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
684
|
-
handleTraceDelete(store, traceId)
|
|
889
|
+
},
|
|
890
|
+
"/api/collections": {
|
|
891
|
+
GET: async () =>
|
|
892
|
+
withSecurityHeaders(
|
|
893
|
+
(await refreshResidentConfig(runtime as ResidentRuntime)) ??
|
|
894
|
+
(await handleCollections(ctxHolder.config)),
|
|
895
|
+
isDev
|
|
685
896
|
),
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
897
|
+
POST: async (req: Request) => {
|
|
898
|
+
if (!isRequestAllowed(req, port)) {
|
|
899
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
900
|
+
}
|
|
901
|
+
return withSecurityHeaders(
|
|
902
|
+
await handleCreateCollection(ctxHolder, store, req),
|
|
903
|
+
isDev
|
|
904
|
+
);
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
"/api/egress/check": {
|
|
908
|
+
POST: async (req: Request) =>
|
|
909
|
+
withSecurityHeaders(
|
|
910
|
+
await handleCollectionEgressCheck(ctxHolder, req),
|
|
911
|
+
isDev
|
|
695
912
|
),
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
913
|
+
},
|
|
914
|
+
"/api/egress/audits/status": {
|
|
915
|
+
GET: async () =>
|
|
916
|
+
withSecurityHeaders(await handleEgressAuditStatus(store), isDev),
|
|
917
|
+
},
|
|
918
|
+
"/api/egress/audits": {
|
|
919
|
+
GET: async (req: Request) =>
|
|
920
|
+
withSecurityHeaders(
|
|
921
|
+
await handleEgressAuditList(store, req),
|
|
922
|
+
isDev
|
|
705
923
|
),
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
924
|
+
DELETE: async (req: Request) => {
|
|
925
|
+
if (!isRequestAllowed(req, port)) {
|
|
926
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
927
|
+
}
|
|
928
|
+
return withSecurityHeaders(
|
|
929
|
+
await handleEgressAuditPurge(store),
|
|
930
|
+
isDev
|
|
931
|
+
);
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
"/api/egress/audits/:auditId": {
|
|
935
|
+
GET: async (req: Request) => {
|
|
936
|
+
const auditId = decodeURIComponent(
|
|
937
|
+
new URL(req.url).pathname.split("/").at(-1) ?? ""
|
|
938
|
+
);
|
|
939
|
+
return withSecurityHeaders(
|
|
940
|
+
await handleEgressAuditShow(store, auditId),
|
|
941
|
+
isDev
|
|
942
|
+
);
|
|
943
|
+
},
|
|
944
|
+
DELETE: async (req: Request) => {
|
|
945
|
+
if (!isRequestAllowed(req, port)) {
|
|
946
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
947
|
+
}
|
|
948
|
+
const auditId = decodeURIComponent(
|
|
949
|
+
new URL(req.url).pathname.split("/").at(-1) ?? ""
|
|
950
|
+
);
|
|
951
|
+
return withSecurityHeaders(
|
|
952
|
+
await handleEgressAuditDelete(store, auditId),
|
|
953
|
+
isDev
|
|
954
|
+
);
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
"/api/connectors": {
|
|
958
|
+
GET: async (req: Request) =>
|
|
959
|
+
withSecurityHeaders(
|
|
960
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
961
|
+
handleConnectors(ctxHolder.config)
|
|
962
|
+
),
|
|
963
|
+
isDev
|
|
715
964
|
),
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
965
|
+
},
|
|
966
|
+
"/api/connectors/install": {
|
|
967
|
+
POST: async (req: Request) => {
|
|
968
|
+
if (!isRequestAllowed(req, port)) {
|
|
969
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
970
|
+
}
|
|
971
|
+
return withSecurityHeaders(
|
|
972
|
+
await (
|
|
973
|
+
dependencies.handleInstallConnector ?? handleInstallConnector
|
|
974
|
+
)(req, {
|
|
975
|
+
indexName: options.index,
|
|
976
|
+
configPath: runtime.actualConfigPath,
|
|
977
|
+
}),
|
|
978
|
+
isDev
|
|
979
|
+
);
|
|
980
|
+
},
|
|
981
|
+
},
|
|
982
|
+
"/api/connectors/verify": {
|
|
983
|
+
POST: async (req: Request) => {
|
|
984
|
+
if (!isRequestAllowed(req, port)) {
|
|
985
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
986
|
+
}
|
|
987
|
+
return withSecurityHeaders(
|
|
988
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
989
|
+
(dependencies.handleVerifyConnector ?? handleVerifyConnector)(
|
|
990
|
+
ctxHolder.config,
|
|
991
|
+
store,
|
|
992
|
+
req
|
|
993
|
+
)
|
|
994
|
+
),
|
|
995
|
+
isDev
|
|
996
|
+
);
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
"/api/import/preview": {
|
|
1000
|
+
POST: async (req: Request) => {
|
|
1001
|
+
if (!isRequestAllowed(req, port)) {
|
|
1002
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1003
|
+
}
|
|
1004
|
+
return withSecurityHeaders(
|
|
1005
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1006
|
+
(dependencies.handleImportPreview ?? handleImportPreview)(
|
|
1007
|
+
ctxHolder,
|
|
1008
|
+
req
|
|
1009
|
+
)
|
|
1010
|
+
),
|
|
1011
|
+
isDev
|
|
1012
|
+
);
|
|
1013
|
+
},
|
|
1014
|
+
},
|
|
1015
|
+
"/api/publish/export": {
|
|
1016
|
+
POST: async (req: Request) => {
|
|
1017
|
+
if (!isRequestAllowed(req, port)) {
|
|
1018
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1019
|
+
}
|
|
1020
|
+
return withSecurityHeaders(
|
|
1021
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1022
|
+
(dependencies.handlePublishExport ?? handlePublishExport)(
|
|
1023
|
+
ctxHolder.config,
|
|
1024
|
+
store,
|
|
1025
|
+
req,
|
|
1026
|
+
runtime.actualConfigPath
|
|
1027
|
+
)
|
|
1028
|
+
),
|
|
1029
|
+
isDev
|
|
1030
|
+
);
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
"/api/sync": {
|
|
1034
|
+
POST: async (req: Request) => {
|
|
1035
|
+
if (!isRequestAllowed(req, port)) {
|
|
1036
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1037
|
+
}
|
|
1038
|
+
return withSecurityHeaders(
|
|
1039
|
+
await handleSync(ctxHolder, store, req),
|
|
1040
|
+
isDev
|
|
1041
|
+
);
|
|
1042
|
+
},
|
|
1043
|
+
},
|
|
1044
|
+
"/api/capture": {
|
|
1045
|
+
POST: async (req: Request) => {
|
|
1046
|
+
if (!isRequestAllowed(req, port)) {
|
|
1047
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1048
|
+
}
|
|
1049
|
+
return withSecurityHeaders(
|
|
1050
|
+
await handleCreateCapture(ctxHolder, store, req),
|
|
1051
|
+
isDev
|
|
1052
|
+
);
|
|
1053
|
+
},
|
|
1054
|
+
},
|
|
1055
|
+
"/api/sessions/status": {
|
|
1056
|
+
GET: async (req: Request) =>
|
|
1057
|
+
withSecurityHeaders(
|
|
1058
|
+
(await refreshSessionsConfig(ctxHolder, store)) ??
|
|
1059
|
+
(await handleResidentRead(
|
|
1060
|
+
runtime as ResidentRuntime,
|
|
1061
|
+
req,
|
|
1062
|
+
() => handleSessionsStatus(ctxHolder)
|
|
1063
|
+
)),
|
|
1064
|
+
isDev
|
|
788
1065
|
),
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
)
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
1066
|
+
},
|
|
1067
|
+
"/api/sessions/discover": {
|
|
1068
|
+
GET: async (req: Request, server: RequestPeerServer) => {
|
|
1069
|
+
// Returns host paths: a cross-origin page is refused like a write.
|
|
1070
|
+
if (!isOriginOrTokenAllowed(req, port)) {
|
|
1071
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1072
|
+
}
|
|
1073
|
+
return withSecurityHeaders(
|
|
1074
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1075
|
+
handleSessionsDiscover(ctxHolder, req, { server })
|
|
1076
|
+
),
|
|
1077
|
+
isDev
|
|
1078
|
+
);
|
|
1079
|
+
},
|
|
1080
|
+
},
|
|
1081
|
+
"/api/sessions/import": {
|
|
1082
|
+
POST: async (req: Request) => {
|
|
1083
|
+
if (!isRequestAllowed(req, port)) {
|
|
1084
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1085
|
+
}
|
|
1086
|
+
return withSecurityHeaders(
|
|
1087
|
+
await handleSessionsImport(ctxHolder, req),
|
|
1088
|
+
isDev
|
|
1089
|
+
);
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
"/api/sessions/sources": {
|
|
1093
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1094
|
+
if (!isRequestAllowed(req, port)) {
|
|
1095
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1096
|
+
}
|
|
1097
|
+
return withSecurityHeaders(
|
|
1098
|
+
await handleSessionsAddSource(ctxHolder, store, req, {
|
|
1099
|
+
server,
|
|
1100
|
+
}),
|
|
1101
|
+
isDev
|
|
1102
|
+
);
|
|
1103
|
+
},
|
|
1104
|
+
},
|
|
1105
|
+
"/api/sessions/sources/:id": {
|
|
1106
|
+
DELETE: async (req: Request, server: RequestPeerServer) => {
|
|
1107
|
+
if (!isRequestAllowed(req, port)) {
|
|
1108
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1109
|
+
}
|
|
1110
|
+
const id = decodeURIComponent(
|
|
1111
|
+
new URL(req.url).pathname.split("/")[4] ?? ""
|
|
1112
|
+
);
|
|
1113
|
+
return withSecurityHeaders(
|
|
1114
|
+
await handleSessionsRemoveSource(ctxHolder, store, id, req, {
|
|
1115
|
+
server,
|
|
1116
|
+
}),
|
|
1117
|
+
isDev
|
|
1118
|
+
);
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
"/api/sessions/automation/run": {
|
|
1122
|
+
POST: async (req: Request) => {
|
|
1123
|
+
if (!isRequestAllowed(req, port)) {
|
|
1124
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1125
|
+
}
|
|
1126
|
+
return withSecurityHeaders(
|
|
1127
|
+
await handleSessionsAutomationRun(ctxHolder, store, req),
|
|
1128
|
+
isDev
|
|
1129
|
+
);
|
|
1130
|
+
},
|
|
1131
|
+
},
|
|
1132
|
+
"/api/sessions/automation/:id": {
|
|
1133
|
+
PUT: async (req: Request, server: RequestPeerServer) => {
|
|
1134
|
+
if (!isRequestAllowed(req, port)) {
|
|
1135
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1136
|
+
}
|
|
1137
|
+
return withSecurityHeaders(
|
|
1138
|
+
await handleSessionsAutomationSet(
|
|
1139
|
+
ctxHolder,
|
|
817
1140
|
store,
|
|
818
|
-
req
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
832
|
-
(dependencies.handleImportPreview ?? handleImportPreview)(
|
|
1141
|
+
automationProfileId(req),
|
|
1142
|
+
req,
|
|
1143
|
+
{ server }
|
|
1144
|
+
),
|
|
1145
|
+
isDev
|
|
1146
|
+
);
|
|
1147
|
+
},
|
|
1148
|
+
DELETE: async (req: Request, server: RequestPeerServer) => {
|
|
1149
|
+
if (!isRequestAllowed(req, port)) {
|
|
1150
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1151
|
+
}
|
|
1152
|
+
return withSecurityHeaders(
|
|
1153
|
+
await handleSessionsAutomationRemove(
|
|
833
1154
|
ctxHolder,
|
|
834
|
-
req
|
|
835
|
-
)
|
|
836
|
-
),
|
|
837
|
-
isDev
|
|
838
|
-
);
|
|
839
|
-
},
|
|
840
|
-
},
|
|
841
|
-
"/api/publish/export": {
|
|
842
|
-
POST: async (req: Request) => {
|
|
843
|
-
if (!isRequestAllowed(req, port)) {
|
|
844
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
845
|
-
}
|
|
846
|
-
return withSecurityHeaders(
|
|
847
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
848
|
-
(dependencies.handlePublishExport ?? handlePublishExport)(
|
|
849
|
-
ctxHolder.config,
|
|
850
1155
|
store,
|
|
1156
|
+
automationProfileId(req),
|
|
851
1157
|
req,
|
|
852
|
-
|
|
853
|
-
)
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
},
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
)
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
)
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
ctxHolder,
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1158
|
+
{ server }
|
|
1159
|
+
),
|
|
1160
|
+
isDev
|
|
1161
|
+
);
|
|
1162
|
+
},
|
|
1163
|
+
},
|
|
1164
|
+
"/api/sessions/automation/:id/preview": {
|
|
1165
|
+
GET: async (req: Request, server: RequestPeerServer) =>
|
|
1166
|
+
!isOriginOrTokenAllowed(req, port)
|
|
1167
|
+
? withSecurityHeaders(forbiddenResponse(), isDev)
|
|
1168
|
+
: withSecurityHeaders(
|
|
1169
|
+
await handleResidentRead(
|
|
1170
|
+
runtime as ResidentRuntime,
|
|
1171
|
+
req,
|
|
1172
|
+
() =>
|
|
1173
|
+
handleSessionsAutomationPreview(
|
|
1174
|
+
ctxHolder,
|
|
1175
|
+
automationProfileId(req),
|
|
1176
|
+
req,
|
|
1177
|
+
{ server }
|
|
1178
|
+
)
|
|
1179
|
+
),
|
|
1180
|
+
isDev
|
|
1181
|
+
),
|
|
1182
|
+
},
|
|
1183
|
+
"/api/sessions/automation/:id/enable": {
|
|
1184
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1185
|
+
if (!isRequestAllowed(req, port)) {
|
|
1186
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1187
|
+
}
|
|
1188
|
+
return withSecurityHeaders(
|
|
1189
|
+
await handleSessionsAutomationEnable(
|
|
1190
|
+
ctxHolder,
|
|
1191
|
+
store,
|
|
1192
|
+
automationProfileId(req),
|
|
1193
|
+
req,
|
|
1194
|
+
{ server }
|
|
1195
|
+
),
|
|
1196
|
+
isDev
|
|
1197
|
+
);
|
|
1198
|
+
},
|
|
1199
|
+
},
|
|
1200
|
+
"/api/sessions/automation/:id/disable": {
|
|
1201
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1202
|
+
if (!isRequestAllowed(req, port)) {
|
|
1203
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1204
|
+
}
|
|
1205
|
+
return withSecurityHeaders(
|
|
1206
|
+
await handleSessionsAutomationDisable(
|
|
1207
|
+
ctxHolder,
|
|
1208
|
+
store,
|
|
1209
|
+
automationProfileId(req),
|
|
1210
|
+
req,
|
|
1211
|
+
{ server }
|
|
1212
|
+
),
|
|
1213
|
+
isDev
|
|
1214
|
+
);
|
|
1215
|
+
},
|
|
1216
|
+
},
|
|
1217
|
+
"/api/sessions/init": {
|
|
1218
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1219
|
+
if (!isRequestAllowed(req, port)) {
|
|
1220
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1221
|
+
}
|
|
1222
|
+
return withSecurityHeaders(
|
|
1223
|
+
await handleSessionsInit(ctxHolder, store, req, { server }),
|
|
1224
|
+
isDev
|
|
1225
|
+
);
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
"/api/memory/remember": {
|
|
1229
|
+
POST: async (req: Request) => {
|
|
1230
|
+
if (!isRequestAllowed(req, port)) {
|
|
1231
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1232
|
+
}
|
|
1233
|
+
return withSecurityHeaders(
|
|
1234
|
+
await handleMemoryRemember(ctxHolder, store, req),
|
|
1235
|
+
isDev
|
|
1236
|
+
);
|
|
1237
|
+
},
|
|
1238
|
+
},
|
|
1239
|
+
"/api/memory/recall": {
|
|
1240
|
+
POST: async (req: Request) => {
|
|
1241
|
+
if (!isRequestAllowed(req, port)) {
|
|
1242
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1243
|
+
}
|
|
1244
|
+
return withSecurityHeaders(
|
|
1245
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1246
|
+
handleMemoryRecall(ctxHolder, store, req)
|
|
1247
|
+
),
|
|
1248
|
+
isDev
|
|
1249
|
+
);
|
|
1250
|
+
},
|
|
1251
|
+
},
|
|
1252
|
+
"/api/docs": {
|
|
1253
|
+
GET: async (req: Request) => {
|
|
1254
|
+
const url = new URL(req.url);
|
|
1255
|
+
return withSecurityHeaders(
|
|
1256
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1257
|
+
(dependencies.handleDocs ?? handleDocs)(store, url)
|
|
1258
|
+
),
|
|
1259
|
+
isDev
|
|
1260
|
+
);
|
|
1261
|
+
},
|
|
1262
|
+
POST: async (req: Request) => {
|
|
1263
|
+
if (!isRequestAllowed(req, port)) {
|
|
1264
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1265
|
+
}
|
|
1266
|
+
return withSecurityHeaders(
|
|
1267
|
+
await handleCreateDoc(ctxHolder, store, req),
|
|
1268
|
+
isDev
|
|
1269
|
+
);
|
|
1270
|
+
},
|
|
1271
|
+
},
|
|
1272
|
+
"/api/docs/autocomplete": {
|
|
1273
|
+
GET: async (req: Request) => {
|
|
1274
|
+
const url = new URL(req.url);
|
|
1275
|
+
return withSecurityHeaders(
|
|
1276
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1277
|
+
handleDocsAutocomplete(store, url)
|
|
1278
|
+
),
|
|
1279
|
+
isDev
|
|
1280
|
+
);
|
|
1281
|
+
},
|
|
1282
|
+
},
|
|
1283
|
+
"/api/note-presets": {
|
|
1284
|
+
GET: async () =>
|
|
1285
|
+
withSecurityHeaders(await handleNotePresets(), isDev),
|
|
1286
|
+
},
|
|
1287
|
+
"/api/folders": {
|
|
1288
|
+
POST: async (req: Request) => {
|
|
1289
|
+
if (!isRequestAllowed(req, port)) {
|
|
1290
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1291
|
+
}
|
|
1292
|
+
return withSecurityHeaders(
|
|
1293
|
+
await handleCreateFolder(ctxHolder, req),
|
|
1294
|
+
isDev
|
|
1295
|
+
);
|
|
1296
|
+
},
|
|
1297
|
+
},
|
|
1298
|
+
"/api/browse/tree": {
|
|
1299
|
+
GET: async (req: Request) =>
|
|
1300
|
+
withSecurityHeaders(
|
|
1301
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1302
|
+
handleBrowseTree(store)
|
|
1303
|
+
),
|
|
1304
|
+
isDev
|
|
981
1305
|
),
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1306
|
+
},
|
|
1307
|
+
"/api/docs/:id/deactivate": {
|
|
1308
|
+
POST: async (req: Request) => {
|
|
1309
|
+
if (!isRequestAllowed(req, port)) {
|
|
1310
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1311
|
+
}
|
|
1312
|
+
const url = new URL(req.url);
|
|
1313
|
+
// Extract id from /api/docs/:id/deactivate
|
|
1314
|
+
const parts = url.pathname.split("/");
|
|
1315
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1316
|
+
return withSecurityHeaders(
|
|
1317
|
+
await handleDeactivateDoc(ctxHolder, store, id, req),
|
|
1318
|
+
isDev
|
|
1319
|
+
);
|
|
1320
|
+
},
|
|
1321
|
+
},
|
|
1322
|
+
"/api/docs/:id/rename": {
|
|
1323
|
+
POST: async (req: Request) => {
|
|
1324
|
+
if (!isRequestAllowed(req, port)) {
|
|
1325
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1326
|
+
}
|
|
1327
|
+
const url = new URL(req.url);
|
|
1328
|
+
const parts = url.pathname.split("/");
|
|
1329
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1330
|
+
return withSecurityHeaders(
|
|
1331
|
+
await handleRenameDoc(ctxHolder, store, id, req),
|
|
1332
|
+
isDev
|
|
1333
|
+
);
|
|
1334
|
+
},
|
|
1335
|
+
},
|
|
1336
|
+
"/api/docs/:id/move": {
|
|
1337
|
+
POST: async (req: Request) => {
|
|
1338
|
+
if (!isRequestAllowed(req, port)) {
|
|
1339
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1340
|
+
}
|
|
1341
|
+
const url = new URL(req.url);
|
|
1342
|
+
const parts = url.pathname.split("/");
|
|
1343
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1344
|
+
return withSecurityHeaders(
|
|
1345
|
+
await handleMoveDoc(ctxHolder, store, id, req),
|
|
1346
|
+
isDev
|
|
1347
|
+
);
|
|
1348
|
+
},
|
|
1349
|
+
},
|
|
1350
|
+
"/api/docs/:id/duplicate": {
|
|
1351
|
+
POST: async (req: Request) => {
|
|
1352
|
+
if (!isRequestAllowed(req, port)) {
|
|
1353
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1354
|
+
}
|
|
1355
|
+
const url = new URL(req.url);
|
|
1356
|
+
const parts = url.pathname.split("/");
|
|
1357
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1358
|
+
return withSecurityHeaders(
|
|
1359
|
+
await handleDuplicateDoc(ctxHolder, store, id, req),
|
|
1360
|
+
isDev
|
|
1361
|
+
);
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
"/api/docs/:id/refactor-plan": {
|
|
1365
|
+
POST: async (req: Request) => {
|
|
1366
|
+
if (!isRequestAllowed(req, port)) {
|
|
1367
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1368
|
+
}
|
|
1369
|
+
const url = new URL(req.url);
|
|
1370
|
+
const parts = url.pathname.split("/");
|
|
1371
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1372
|
+
return withSecurityHeaders(
|
|
1373
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1374
|
+
(dependencies.handleRefactorPlan ?? handleRefactorPlan)(
|
|
1375
|
+
ctxHolder,
|
|
1376
|
+
store,
|
|
1377
|
+
id,
|
|
1378
|
+
req
|
|
1379
|
+
)
|
|
1380
|
+
),
|
|
1381
|
+
isDev
|
|
1382
|
+
);
|
|
1383
|
+
},
|
|
1384
|
+
},
|
|
1385
|
+
"/api/docs/:id/trash": {
|
|
1386
|
+
POST: async (req: Request) => {
|
|
1387
|
+
if (!isRequestAllowed(req, port)) {
|
|
1388
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1389
|
+
}
|
|
1390
|
+
const url = new URL(req.url);
|
|
1391
|
+
const parts = url.pathname.split("/");
|
|
1392
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1393
|
+
return withSecurityHeaders(
|
|
1394
|
+
await handleTrashDoc(ctxHolder, store, id, req),
|
|
1395
|
+
isDev
|
|
1396
|
+
);
|
|
1397
|
+
},
|
|
1398
|
+
},
|
|
1399
|
+
"/api/docs/:id/reveal": {
|
|
1400
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1401
|
+
if (!isRequestAllowed(req, port)) {
|
|
1402
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1403
|
+
}
|
|
1404
|
+
const url = new URL(req.url);
|
|
1405
|
+
const parts = url.pathname.split("/");
|
|
1406
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1407
|
+
return withSecurityHeaders(
|
|
1408
|
+
await handleRevealDoc(ctxHolder, store, id, req, { server }),
|
|
1409
|
+
isDev
|
|
1410
|
+
);
|
|
1411
|
+
},
|
|
1412
|
+
},
|
|
1413
|
+
"/api/docs/:id/editable-copy": {
|
|
1414
|
+
POST: async (req: Request) => {
|
|
1415
|
+
if (!isRequestAllowed(req, port)) {
|
|
1416
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1417
|
+
}
|
|
1418
|
+
const url = new URL(req.url);
|
|
1419
|
+
const parts = url.pathname.split("/");
|
|
1420
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1421
|
+
return withSecurityHeaders(
|
|
1422
|
+
await handleCreateEditableCopy(ctxHolder, store, id, req),
|
|
1423
|
+
isDev
|
|
1424
|
+
);
|
|
1425
|
+
},
|
|
1426
|
+
},
|
|
1427
|
+
"/api/docs/:id": {
|
|
1428
|
+
PUT: async (req: Request) => {
|
|
1429
|
+
if (!isRequestAllowed(req, port)) {
|
|
1430
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1431
|
+
}
|
|
1432
|
+
const url = new URL(req.url);
|
|
1433
|
+
// Extract id from /api/docs/:id
|
|
1434
|
+
const id = decodeURIComponent(
|
|
1435
|
+
url.pathname.split("/").pop() || ""
|
|
1436
|
+
);
|
|
1437
|
+
return withSecurityHeaders(
|
|
1438
|
+
await handleUpdateDoc(ctxHolder, store, id, req),
|
|
1439
|
+
isDev
|
|
1440
|
+
);
|
|
1441
|
+
},
|
|
1442
|
+
},
|
|
1443
|
+
"/api/requests/:requestId": {
|
|
1444
|
+
GET: async (req: Request) => {
|
|
1445
|
+
const url = new URL(req.url);
|
|
1446
|
+
const requestId = decodeURIComponent(
|
|
1447
|
+
url.pathname.split("/").pop() || ""
|
|
1448
|
+
);
|
|
1449
|
+
return withSecurityHeaders(
|
|
1450
|
+
await handleRequestStatus(store, requestId),
|
|
1451
|
+
isDev
|
|
1452
|
+
);
|
|
1453
|
+
},
|
|
1454
|
+
},
|
|
1455
|
+
"/api/doc": {
|
|
1456
|
+
GET: async (req: Request) => {
|
|
1457
|
+
const url = new URL(req.url);
|
|
1458
|
+
return withSecurityHeaders(
|
|
1459
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1460
|
+
handleDoc(store, ctxHolder.config, url, req)
|
|
1461
|
+
),
|
|
1462
|
+
isDev
|
|
1463
|
+
);
|
|
1464
|
+
},
|
|
1465
|
+
},
|
|
1466
|
+
// fn-112: production factories shared with route-level tests (I1-04)
|
|
1467
|
+
"/api/doc-asset": createDocAssetRouteHandlers({
|
|
1468
|
+
store,
|
|
1469
|
+
getConfig: () => ctxHolder.config,
|
|
1470
|
+
runtime: runtime as ResidentRuntime,
|
|
1471
|
+
isDev,
|
|
1472
|
+
withSecurityHeaders,
|
|
1473
|
+
}),
|
|
1474
|
+
// Vendor assets are NOT mounted as valid-only patterns here.
|
|
1475
|
+
// ALL /vendor/pdfjs/* traffic is handled by handlePdfjsVendorRequest
|
|
1476
|
+
// in the fetch fallback below (same production dispatcher tests use).
|
|
1477
|
+
"/api/events": {
|
|
1478
|
+
GET: (req: Request) => {
|
|
1479
|
+
const residentRuntime = runtime as ResidentRuntime;
|
|
1480
|
+
const admitted = residentRuntime.admitRequest(req.signal);
|
|
1481
|
+
if (!admitted || !residentRuntime.eventBus) {
|
|
1482
|
+
admitted?.finish();
|
|
1483
|
+
return withSecurityHeaders(
|
|
1484
|
+
Response.json(
|
|
1485
|
+
{
|
|
1486
|
+
error: {
|
|
1487
|
+
code: "UNAVAILABLE",
|
|
1488
|
+
message: "Document event stream unavailable",
|
|
1489
|
+
},
|
|
1490
|
+
},
|
|
1491
|
+
{ status: 503 }
|
|
1001
1492
|
),
|
|
1002
1493
|
isDev
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
try {
|
|
1497
|
+
return withSecurityHeaders(
|
|
1498
|
+
residentRuntime.eventBus.createResponse({
|
|
1499
|
+
authorizationEpoch:
|
|
1500
|
+
admitted.authorizationEpoch ??
|
|
1501
|
+
residentRuntime.authorizationEpoch,
|
|
1502
|
+
isAuthorizationEpochCurrent: () =>
|
|
1503
|
+
admitted.isAuthorizationEpochCurrent?.() ?? true,
|
|
1504
|
+
onClose: () => admitted.finish(),
|
|
1505
|
+
signal: admitted.signal,
|
|
1506
|
+
}),
|
|
1507
|
+
isDev
|
|
1508
|
+
);
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
admitted.finish();
|
|
1511
|
+
throw error;
|
|
1512
|
+
}
|
|
1513
|
+
},
|
|
1514
|
+
},
|
|
1515
|
+
"/api/metadata": {
|
|
1516
|
+
GET: async (req: Request) => {
|
|
1517
|
+
const url = new URL(req.url);
|
|
1518
|
+
return withSecurityHeaders(
|
|
1519
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1520
|
+
handleMetadata(store, url)
|
|
1003
1521
|
),
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
)
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
return withSecurityHeaders(
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
)
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1522
|
+
isDev
|
|
1523
|
+
);
|
|
1524
|
+
},
|
|
1525
|
+
},
|
|
1526
|
+
"/api/tags": {
|
|
1527
|
+
GET: async (req: Request) => {
|
|
1528
|
+
const url = new URL(req.url);
|
|
1529
|
+
return withSecurityHeaders(
|
|
1530
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1531
|
+
handleTags(store, url)
|
|
1532
|
+
),
|
|
1533
|
+
isDev
|
|
1534
|
+
);
|
|
1535
|
+
},
|
|
1536
|
+
},
|
|
1537
|
+
"/api/search": {
|
|
1538
|
+
POST: async (req: Request) => {
|
|
1539
|
+
if (!isRequestAllowed(req, port)) {
|
|
1540
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1541
|
+
}
|
|
1542
|
+
return withSecurityHeaders(
|
|
1543
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1544
|
+
handleSearch(ctxHolder.current, req)
|
|
1545
|
+
),
|
|
1546
|
+
isDev
|
|
1547
|
+
);
|
|
1548
|
+
},
|
|
1549
|
+
},
|
|
1550
|
+
"/api/query": {
|
|
1551
|
+
POST: async (req: Request) => {
|
|
1552
|
+
if (!isRequestAllowed(req, port)) {
|
|
1553
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1554
|
+
}
|
|
1555
|
+
return withSecurityHeaders(
|
|
1556
|
+
await handleResidentRead(
|
|
1557
|
+
runtime as ResidentRuntime,
|
|
1558
|
+
req,
|
|
1559
|
+
(signal) =>
|
|
1560
|
+
handleQuery(ctxHolder.current, new Request(req, { signal }))
|
|
1561
|
+
),
|
|
1562
|
+
isDev
|
|
1563
|
+
);
|
|
1564
|
+
},
|
|
1565
|
+
},
|
|
1566
|
+
"/api/context": {
|
|
1567
|
+
POST: async (req: Request) => {
|
|
1568
|
+
if (!isRequestAllowed(req, port)) {
|
|
1569
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1570
|
+
}
|
|
1571
|
+
return withSecurityHeaders(
|
|
1572
|
+
await handleResidentRead(
|
|
1573
|
+
runtime as ResidentRuntime,
|
|
1574
|
+
req,
|
|
1575
|
+
(signal) =>
|
|
1576
|
+
handleContextBuild(
|
|
1577
|
+
ctxHolder.current,
|
|
1578
|
+
new Request(req, { signal })
|
|
1579
|
+
)
|
|
1580
|
+
),
|
|
1581
|
+
isDev
|
|
1582
|
+
);
|
|
1583
|
+
},
|
|
1584
|
+
},
|
|
1585
|
+
"/api/context/compiled/preview": {
|
|
1586
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1587
|
+
if (!isRequestAllowed(req, port))
|
|
1588
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1589
|
+
return withSecurityHeaders(
|
|
1590
|
+
await handleResidentRead(
|
|
1591
|
+
runtime as ResidentRuntime,
|
|
1592
|
+
req,
|
|
1593
|
+
(signal) =>
|
|
1594
|
+
handleCompiledContext(
|
|
1595
|
+
ctxHolder.current,
|
|
1596
|
+
new Request(req, { signal }),
|
|
1597
|
+
{ requestIP: () => server.requestIP(req) },
|
|
1598
|
+
"preview"
|
|
1599
|
+
)
|
|
1600
|
+
),
|
|
1601
|
+
isDev
|
|
1602
|
+
);
|
|
1603
|
+
},
|
|
1604
|
+
},
|
|
1605
|
+
"/api/context/compiled/check": {
|
|
1606
|
+
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1607
|
+
if (!isRequestAllowed(req, port))
|
|
1608
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1609
|
+
return withSecurityHeaders(
|
|
1610
|
+
await handleResidentRead(
|
|
1611
|
+
runtime as ResidentRuntime,
|
|
1612
|
+
req,
|
|
1613
|
+
(signal) =>
|
|
1614
|
+
handleCompiledContext(
|
|
1615
|
+
ctxHolder.current,
|
|
1616
|
+
new Request(req, { signal }),
|
|
1617
|
+
{ requestIP: () => server.requestIP(req) },
|
|
1618
|
+
"check"
|
|
1619
|
+
)
|
|
1620
|
+
),
|
|
1621
|
+
isDev
|
|
1622
|
+
);
|
|
1623
|
+
},
|
|
1624
|
+
},
|
|
1625
|
+
"/api/context/verify": {
|
|
1626
|
+
POST: async (req: Request) => {
|
|
1627
|
+
if (!isRequestAllowed(req, port)) {
|
|
1628
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1629
|
+
}
|
|
1630
|
+
return withSecurityHeaders(
|
|
1631
|
+
await handleResidentRead(
|
|
1632
|
+
runtime as ResidentRuntime,
|
|
1633
|
+
req,
|
|
1634
|
+
(signal) =>
|
|
1635
|
+
handleContextVerify(
|
|
1636
|
+
ctxHolder.current,
|
|
1637
|
+
new Request(req, { signal })
|
|
1638
|
+
)
|
|
1639
|
+
),
|
|
1640
|
+
isDev
|
|
1641
|
+
);
|
|
1642
|
+
},
|
|
1643
|
+
},
|
|
1644
|
+
"/api/query/diagnose": {
|
|
1645
|
+
POST: async (req: Request) => {
|
|
1646
|
+
if (!isRequestAllowed(req, port)) {
|
|
1647
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1648
|
+
}
|
|
1649
|
+
return withSecurityHeaders(
|
|
1650
|
+
await handleResidentRead(
|
|
1651
|
+
runtime as ResidentRuntime,
|
|
1652
|
+
req,
|
|
1653
|
+
(signal) =>
|
|
1654
|
+
handleQueryDiagnose(
|
|
1655
|
+
ctxHolder.current,
|
|
1656
|
+
new Request(req, { signal })
|
|
1657
|
+
)
|
|
1658
|
+
),
|
|
1659
|
+
isDev
|
|
1660
|
+
);
|
|
1661
|
+
},
|
|
1662
|
+
},
|
|
1663
|
+
"/api/ask": {
|
|
1664
|
+
POST: async (req: Request) => {
|
|
1665
|
+
if (!isRequestAllowed(req, port)) {
|
|
1666
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1667
|
+
}
|
|
1668
|
+
return withSecurityHeaders(
|
|
1669
|
+
await handleResidentRead(
|
|
1670
|
+
runtime as ResidentRuntime,
|
|
1671
|
+
req,
|
|
1672
|
+
(signal) =>
|
|
1673
|
+
handleAsk(ctxHolder.current, new Request(req, { signal }))
|
|
1674
|
+
),
|
|
1675
|
+
isDev
|
|
1676
|
+
);
|
|
1677
|
+
},
|
|
1678
|
+
},
|
|
1679
|
+
"/api/capabilities": {
|
|
1680
|
+
GET: (req: Request, server: RequestPeerServer) =>
|
|
1681
|
+
withSecurityHeaders(
|
|
1682
|
+
handleCapabilities(ctxHolder.current, req, server),
|
|
1683
|
+
isDev
|
|
1100
1684
|
),
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1685
|
+
},
|
|
1686
|
+
"/api/presets": {
|
|
1687
|
+
GET: () =>
|
|
1688
|
+
withSecurityHeaders(handlePresets(ctxHolder.current), isDev),
|
|
1689
|
+
POST: async (req: Request) => {
|
|
1690
|
+
if (!isRequestAllowed(req, port)) {
|
|
1691
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1692
|
+
}
|
|
1693
|
+
return withSecurityHeaders(
|
|
1694
|
+
await handleSetPreset(ctxHolder, req),
|
|
1695
|
+
isDev
|
|
1696
|
+
);
|
|
1697
|
+
},
|
|
1698
|
+
},
|
|
1699
|
+
"/api/models/status": {
|
|
1700
|
+
GET: () => withSecurityHeaders(handleModelStatus(), isDev),
|
|
1701
|
+
},
|
|
1702
|
+
"/api/models/pull": {
|
|
1703
|
+
POST: async (req: Request) => {
|
|
1704
|
+
if (!isRequestAllowed(req, port)) {
|
|
1705
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1706
|
+
}
|
|
1707
|
+
return withSecurityHeaders(
|
|
1708
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1709
|
+
handleModelPull(ctxHolder)
|
|
1710
|
+
),
|
|
1711
|
+
isDev
|
|
1712
|
+
);
|
|
1713
|
+
},
|
|
1714
|
+
},
|
|
1715
|
+
"/api/jobs/active": {
|
|
1716
|
+
GET: () =>
|
|
1717
|
+
withSecurityHeaders(handleActiveJob(ctxHolder.jobManager), isDev),
|
|
1718
|
+
},
|
|
1719
|
+
"/api/jobs/:id": {
|
|
1720
|
+
GET: (req: Request) => {
|
|
1721
|
+
const url = new URL(req.url);
|
|
1722
|
+
const id = decodeURIComponent(
|
|
1723
|
+
url.pathname.split("/").pop() || ""
|
|
1724
|
+
);
|
|
1725
|
+
return withSecurityHeaders(
|
|
1726
|
+
handleJob(id, ctxHolder.jobManager),
|
|
1727
|
+
isDev
|
|
1728
|
+
);
|
|
1729
|
+
},
|
|
1730
|
+
},
|
|
1731
|
+
"/api/embed": {
|
|
1732
|
+
POST: async (req: Request) => {
|
|
1733
|
+
if (!isRequestAllowed(req, port)) {
|
|
1734
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1735
|
+
}
|
|
1736
|
+
return withSecurityHeaders(
|
|
1737
|
+
await handleEmbed(ctxHolder.scheduler),
|
|
1738
|
+
isDev
|
|
1739
|
+
);
|
|
1740
|
+
},
|
|
1741
|
+
},
|
|
1742
|
+
"/api/embed/status": {
|
|
1743
|
+
GET: () =>
|
|
1744
|
+
withSecurityHeaders(
|
|
1745
|
+
handleEmbedStatus(ctxHolder.scheduler),
|
|
1746
|
+
isDev
|
|
1125
1747
|
),
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
)
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
"/api/docs/:id/duplicate": {
|
|
1173
|
-
POST: async (req: Request) => {
|
|
1174
|
-
if (!isRequestAllowed(req, port)) {
|
|
1175
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1176
|
-
}
|
|
1177
|
-
const url = new URL(req.url);
|
|
1178
|
-
const parts = url.pathname.split("/");
|
|
1179
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1180
|
-
return withSecurityHeaders(
|
|
1181
|
-
await handleDuplicateDoc(ctxHolder, store, id, req),
|
|
1182
|
-
isDev
|
|
1183
|
-
);
|
|
1184
|
-
},
|
|
1185
|
-
},
|
|
1186
|
-
"/api/docs/:id/refactor-plan": {
|
|
1187
|
-
POST: async (req: Request) => {
|
|
1188
|
-
if (!isRequestAllowed(req, port)) {
|
|
1189
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1190
|
-
}
|
|
1191
|
-
const url = new URL(req.url);
|
|
1192
|
-
const parts = url.pathname.split("/");
|
|
1193
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1194
|
-
return withSecurityHeaders(
|
|
1195
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1196
|
-
(dependencies.handleRefactorPlan ?? handleRefactorPlan)(
|
|
1748
|
+
},
|
|
1749
|
+
"/api/collections/:name": {
|
|
1750
|
+
PATCH: async (req: Request) => {
|
|
1751
|
+
if (!isRequestAllowed(req, port)) {
|
|
1752
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1753
|
+
}
|
|
1754
|
+
const url = new URL(req.url);
|
|
1755
|
+
const name = decodeURIComponent(
|
|
1756
|
+
url.pathname.split("/").pop() || ""
|
|
1757
|
+
);
|
|
1758
|
+
return withSecurityHeaders(
|
|
1759
|
+
await handleUpdateCollection(ctxHolder, store, name, req),
|
|
1760
|
+
isDev
|
|
1761
|
+
);
|
|
1762
|
+
},
|
|
1763
|
+
DELETE: async (req: Request) => {
|
|
1764
|
+
if (!isRequestAllowed(req, port)) {
|
|
1765
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1766
|
+
}
|
|
1767
|
+
const url = new URL(req.url);
|
|
1768
|
+
const name = decodeURIComponent(
|
|
1769
|
+
url.pathname.split("/").pop() || ""
|
|
1770
|
+
);
|
|
1771
|
+
return withSecurityHeaders(
|
|
1772
|
+
await handleDeleteCollection(ctxHolder, store, name),
|
|
1773
|
+
isDev
|
|
1774
|
+
);
|
|
1775
|
+
},
|
|
1776
|
+
},
|
|
1777
|
+
"/api/collections/:name/egress-policy": {
|
|
1778
|
+
GET: (req: Request) => {
|
|
1779
|
+
const parts = new URL(req.url).pathname.split("/");
|
|
1780
|
+
const name = decodeURIComponent(parts.at(-2) ?? "");
|
|
1781
|
+
return withSecurityHeaders(
|
|
1782
|
+
handleCollectionEgressPolicy(ctxHolder, name),
|
|
1783
|
+
isDev
|
|
1784
|
+
);
|
|
1785
|
+
},
|
|
1786
|
+
PUT: async (req: Request) => {
|
|
1787
|
+
if (!isRequestAllowed(req, port)) {
|
|
1788
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1789
|
+
}
|
|
1790
|
+
const parts = new URL(req.url).pathname.split("/");
|
|
1791
|
+
const name = decodeURIComponent(parts.at(-2) ?? "");
|
|
1792
|
+
return withSecurityHeaders(
|
|
1793
|
+
await handleUpdateCollectionEgressPolicy(
|
|
1197
1794
|
ctxHolder,
|
|
1198
1795
|
store,
|
|
1199
|
-
|
|
1796
|
+
name,
|
|
1200
1797
|
req
|
|
1201
|
-
)
|
|
1202
|
-
),
|
|
1203
|
-
isDev
|
|
1204
|
-
);
|
|
1205
|
-
},
|
|
1206
|
-
},
|
|
1207
|
-
"/api/docs/:id/trash": {
|
|
1208
|
-
POST: async (req: Request) => {
|
|
1209
|
-
if (!isRequestAllowed(req, port)) {
|
|
1210
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1211
|
-
}
|
|
1212
|
-
const url = new URL(req.url);
|
|
1213
|
-
const parts = url.pathname.split("/");
|
|
1214
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1215
|
-
return withSecurityHeaders(
|
|
1216
|
-
await handleTrashDoc(ctxHolder, store, id, req),
|
|
1217
|
-
isDev
|
|
1218
|
-
);
|
|
1219
|
-
},
|
|
1220
|
-
},
|
|
1221
|
-
"/api/docs/:id/reveal": {
|
|
1222
|
-
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1223
|
-
if (!isRequestAllowed(req, port)) {
|
|
1224
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1225
|
-
}
|
|
1226
|
-
const url = new URL(req.url);
|
|
1227
|
-
const parts = url.pathname.split("/");
|
|
1228
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1229
|
-
return withSecurityHeaders(
|
|
1230
|
-
await handleRevealDoc(ctxHolder, store, id, req, { server }),
|
|
1231
|
-
isDev
|
|
1232
|
-
);
|
|
1233
|
-
},
|
|
1234
|
-
},
|
|
1235
|
-
"/api/docs/:id/editable-copy": {
|
|
1236
|
-
POST: async (req: Request) => {
|
|
1237
|
-
if (!isRequestAllowed(req, port)) {
|
|
1238
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1239
|
-
}
|
|
1240
|
-
const url = new URL(req.url);
|
|
1241
|
-
const parts = url.pathname.split("/");
|
|
1242
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1243
|
-
return withSecurityHeaders(
|
|
1244
|
-
await handleCreateEditableCopy(ctxHolder, store, id, req),
|
|
1245
|
-
isDev
|
|
1246
|
-
);
|
|
1247
|
-
},
|
|
1248
|
-
},
|
|
1249
|
-
"/api/docs/:id": {
|
|
1250
|
-
PUT: async (req: Request) => {
|
|
1251
|
-
if (!isRequestAllowed(req, port)) {
|
|
1252
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1253
|
-
}
|
|
1254
|
-
const url = new URL(req.url);
|
|
1255
|
-
// Extract id from /api/docs/:id
|
|
1256
|
-
const id = decodeURIComponent(url.pathname.split("/").pop() || "");
|
|
1257
|
-
return withSecurityHeaders(
|
|
1258
|
-
await handleUpdateDoc(ctxHolder, store, id, req),
|
|
1259
|
-
isDev
|
|
1260
|
-
);
|
|
1261
|
-
},
|
|
1262
|
-
},
|
|
1263
|
-
"/api/requests/:requestId": {
|
|
1264
|
-
GET: async (req: Request) => {
|
|
1265
|
-
const url = new URL(req.url);
|
|
1266
|
-
const requestId = decodeURIComponent(
|
|
1267
|
-
url.pathname.split("/").pop() || ""
|
|
1268
|
-
);
|
|
1269
|
-
return withSecurityHeaders(
|
|
1270
|
-
await handleRequestStatus(store, requestId),
|
|
1271
|
-
isDev
|
|
1272
|
-
);
|
|
1273
|
-
},
|
|
1274
|
-
},
|
|
1275
|
-
"/api/doc": {
|
|
1276
|
-
GET: async (req: Request) => {
|
|
1277
|
-
const url = new URL(req.url);
|
|
1278
|
-
return withSecurityHeaders(
|
|
1279
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1280
|
-
handleDoc(store, ctxHolder.config, url, req)
|
|
1281
|
-
),
|
|
1282
|
-
isDev
|
|
1283
|
-
);
|
|
1284
|
-
},
|
|
1285
|
-
},
|
|
1286
|
-
// fn-112: production factories shared with route-level tests (I1-04)
|
|
1287
|
-
"/api/doc-asset": createDocAssetRouteHandlers({
|
|
1288
|
-
store,
|
|
1289
|
-
getConfig: () => ctxHolder.config,
|
|
1290
|
-
runtime: runtime as ResidentRuntime,
|
|
1291
|
-
isDev,
|
|
1292
|
-
withSecurityHeaders,
|
|
1293
|
-
}),
|
|
1294
|
-
// Vendor assets are NOT mounted as valid-only patterns here.
|
|
1295
|
-
// ALL /vendor/pdfjs/* traffic is handled by handlePdfjsVendorRequest
|
|
1296
|
-
// in the fetch fallback below (same production dispatcher tests use).
|
|
1297
|
-
"/api/events": {
|
|
1298
|
-
GET: (req: Request) => {
|
|
1299
|
-
const residentRuntime = runtime as ResidentRuntime;
|
|
1300
|
-
const admitted = residentRuntime.admitRequest(req.signal);
|
|
1301
|
-
if (!admitted || !residentRuntime.eventBus) {
|
|
1302
|
-
admitted?.finish();
|
|
1303
|
-
return withSecurityHeaders(
|
|
1304
|
-
Response.json(
|
|
1305
|
-
{
|
|
1306
|
-
error: {
|
|
1307
|
-
code: "UNAVAILABLE",
|
|
1308
|
-
message: "Document event stream unavailable",
|
|
1309
|
-
},
|
|
1310
|
-
},
|
|
1311
|
-
{ status: 503 }
|
|
1312
1798
|
),
|
|
1313
1799
|
isDev
|
|
1314
1800
|
);
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1801
|
+
},
|
|
1802
|
+
},
|
|
1803
|
+
"/api/collections/:name/embeddings/clear": {
|
|
1804
|
+
POST: async (req: Request) => {
|
|
1805
|
+
if (!isRequestAllowed(req, port)) {
|
|
1806
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1807
|
+
}
|
|
1808
|
+
const url = new URL(req.url);
|
|
1809
|
+
const parts = url.pathname.split("/");
|
|
1810
|
+
const name = decodeURIComponent(parts.at(-3) || "");
|
|
1317
1811
|
return withSecurityHeaders(
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1812
|
+
await handleClearCollectionEmbeddings(
|
|
1813
|
+
ctxHolder,
|
|
1814
|
+
store,
|
|
1815
|
+
name,
|
|
1816
|
+
req
|
|
1817
|
+
),
|
|
1818
|
+
isDev
|
|
1819
|
+
);
|
|
1820
|
+
},
|
|
1821
|
+
},
|
|
1822
|
+
"/api/doc/:id/links": {
|
|
1823
|
+
GET: async (req: Request) => {
|
|
1824
|
+
const url = new URL(req.url);
|
|
1825
|
+
// Extract id from /api/doc/:id/links
|
|
1826
|
+
const parts = url.pathname.split("/");
|
|
1827
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1828
|
+
return withSecurityHeaders(
|
|
1829
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1830
|
+
handleDocLinks(store, id, url)
|
|
1831
|
+
),
|
|
1327
1832
|
isDev
|
|
1328
1833
|
);
|
|
1329
|
-
}
|
|
1330
|
-
admitted.finish();
|
|
1331
|
-
throw error;
|
|
1332
|
-
}
|
|
1834
|
+
},
|
|
1333
1835
|
},
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
)
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
)
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
)
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return withSecurityHeaders(
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
handleCompiledContext(
|
|
1415
|
-
ctxHolder.current,
|
|
1416
|
-
new Request(req, { signal }),
|
|
1417
|
-
{ requestIP: () => server.requestIP(req) },
|
|
1418
|
-
"preview"
|
|
1419
|
-
)
|
|
1420
|
-
),
|
|
1421
|
-
isDev
|
|
1422
|
-
);
|
|
1423
|
-
},
|
|
1424
|
-
},
|
|
1425
|
-
"/api/context/compiled/check": {
|
|
1426
|
-
POST: async (req: Request, server: RequestPeerServer) => {
|
|
1427
|
-
if (!isRequestAllowed(req, port))
|
|
1428
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1429
|
-
return withSecurityHeaders(
|
|
1430
|
-
await handleResidentRead(
|
|
1431
|
-
runtime as ResidentRuntime,
|
|
1432
|
-
req,
|
|
1433
|
-
(signal) =>
|
|
1434
|
-
handleCompiledContext(
|
|
1435
|
-
ctxHolder.current,
|
|
1436
|
-
new Request(req, { signal }),
|
|
1437
|
-
{ requestIP: () => server.requestIP(req) },
|
|
1438
|
-
"check"
|
|
1439
|
-
)
|
|
1440
|
-
),
|
|
1441
|
-
isDev
|
|
1442
|
-
);
|
|
1443
|
-
},
|
|
1444
|
-
},
|
|
1445
|
-
"/api/context/verify": {
|
|
1446
|
-
POST: async (req: Request) => {
|
|
1447
|
-
if (!isRequestAllowed(req, port)) {
|
|
1448
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1449
|
-
}
|
|
1450
|
-
return withSecurityHeaders(
|
|
1451
|
-
await handleResidentRead(
|
|
1452
|
-
runtime as ResidentRuntime,
|
|
1453
|
-
req,
|
|
1454
|
-
(signal) =>
|
|
1455
|
-
handleContextVerify(
|
|
1456
|
-
ctxHolder.current,
|
|
1457
|
-
new Request(req, { signal })
|
|
1458
|
-
)
|
|
1459
|
-
),
|
|
1460
|
-
isDev
|
|
1461
|
-
);
|
|
1462
|
-
},
|
|
1463
|
-
},
|
|
1464
|
-
"/api/query/diagnose": {
|
|
1465
|
-
POST: async (req: Request) => {
|
|
1466
|
-
if (!isRequestAllowed(req, port)) {
|
|
1467
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1468
|
-
}
|
|
1469
|
-
return withSecurityHeaders(
|
|
1470
|
-
await handleResidentRead(
|
|
1471
|
-
runtime as ResidentRuntime,
|
|
1472
|
-
req,
|
|
1473
|
-
(signal) =>
|
|
1474
|
-
handleQueryDiagnose(
|
|
1475
|
-
ctxHolder.current,
|
|
1476
|
-
new Request(req, { signal })
|
|
1836
|
+
"/api/doc/:id/sections": {
|
|
1837
|
+
GET: async (req: Request) => {
|
|
1838
|
+
const url = new URL(req.url);
|
|
1839
|
+
const parts = url.pathname.split("/");
|
|
1840
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1841
|
+
return withSecurityHeaders(
|
|
1842
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1843
|
+
handleDocSections(store, id, req)
|
|
1844
|
+
),
|
|
1845
|
+
isDev
|
|
1846
|
+
);
|
|
1847
|
+
},
|
|
1848
|
+
},
|
|
1849
|
+
"/api/doc/:id/section-targets": {
|
|
1850
|
+
POST: async (req: Request) => {
|
|
1851
|
+
if (!isRequestAllowed(req, port)) {
|
|
1852
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1853
|
+
}
|
|
1854
|
+
const parts = new URL(req.url).pathname.split("/");
|
|
1855
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1856
|
+
return withSecurityHeaders(
|
|
1857
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1858
|
+
handleCreateSectionTarget(store, id, req)
|
|
1859
|
+
),
|
|
1860
|
+
isDev
|
|
1861
|
+
);
|
|
1862
|
+
},
|
|
1863
|
+
},
|
|
1864
|
+
"/api/doc/:id/section-targets/resolve": {
|
|
1865
|
+
POST: async (req: Request) => {
|
|
1866
|
+
if (!isRequestAllowed(req, port)) {
|
|
1867
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1868
|
+
}
|
|
1869
|
+
const parts = new URL(req.url).pathname.split("/");
|
|
1870
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1871
|
+
return withSecurityHeaders(
|
|
1872
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1873
|
+
handleResolveSectionTarget(store, id, req)
|
|
1874
|
+
),
|
|
1875
|
+
isDev
|
|
1876
|
+
);
|
|
1877
|
+
},
|
|
1878
|
+
},
|
|
1879
|
+
"/api/doc/:id/backlinks": {
|
|
1880
|
+
GET: async (req: Request) => {
|
|
1881
|
+
const url = new URL(req.url);
|
|
1882
|
+
// Extract id from /api/doc/:id/backlinks
|
|
1883
|
+
const parts = url.pathname.split("/");
|
|
1884
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1885
|
+
return withSecurityHeaders(
|
|
1886
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1887
|
+
handleDocBacklinks(store, id)
|
|
1888
|
+
),
|
|
1889
|
+
isDev
|
|
1890
|
+
);
|
|
1891
|
+
},
|
|
1892
|
+
},
|
|
1893
|
+
"/api/doc/:id/similar": {
|
|
1894
|
+
GET: async (req: Request) => {
|
|
1895
|
+
const url = new URL(req.url);
|
|
1896
|
+
// Extract id from /api/doc/:id/similar
|
|
1897
|
+
const parts = url.pathname.split("/");
|
|
1898
|
+
const id = decodeURIComponent(parts[3] || "");
|
|
1899
|
+
return withSecurityHeaders(
|
|
1900
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1901
|
+
handleDocSimilar(ctxHolder.current, id, url)
|
|
1902
|
+
),
|
|
1903
|
+
isDev
|
|
1904
|
+
);
|
|
1905
|
+
},
|
|
1906
|
+
},
|
|
1907
|
+
"/api/graph": {
|
|
1908
|
+
GET: async (req: Request) => {
|
|
1909
|
+
const url = new URL(req.url);
|
|
1910
|
+
return withSecurityHeaders(
|
|
1911
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1912
|
+
handleGraph(
|
|
1913
|
+
store,
|
|
1914
|
+
url,
|
|
1915
|
+
getActivePreset(ctxHolder.config).embed
|
|
1477
1916
|
)
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
},
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1529
|
-
handleModelPull(ctxHolder)
|
|
1530
|
-
),
|
|
1531
|
-
isDev
|
|
1532
|
-
);
|
|
1533
|
-
},
|
|
1534
|
-
},
|
|
1535
|
-
"/api/jobs/active": {
|
|
1536
|
-
GET: () =>
|
|
1537
|
-
withSecurityHeaders(handleActiveJob(ctxHolder.jobManager), isDev),
|
|
1538
|
-
},
|
|
1539
|
-
"/api/jobs/:id": {
|
|
1540
|
-
GET: (req: Request) => {
|
|
1541
|
-
const url = new URL(req.url);
|
|
1542
|
-
const id = decodeURIComponent(url.pathname.split("/").pop() || "");
|
|
1543
|
-
return withSecurityHeaders(
|
|
1544
|
-
handleJob(id, ctxHolder.jobManager),
|
|
1545
|
-
isDev
|
|
1546
|
-
);
|
|
1547
|
-
},
|
|
1548
|
-
},
|
|
1549
|
-
"/api/embed": {
|
|
1550
|
-
POST: async (req: Request) => {
|
|
1551
|
-
if (!isRequestAllowed(req, port)) {
|
|
1552
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1553
|
-
}
|
|
1554
|
-
return withSecurityHeaders(
|
|
1555
|
-
await handleEmbed(ctxHolder.scheduler),
|
|
1556
|
-
isDev
|
|
1557
|
-
);
|
|
1558
|
-
},
|
|
1559
|
-
},
|
|
1560
|
-
"/api/embed/status": {
|
|
1561
|
-
GET: () =>
|
|
1562
|
-
withSecurityHeaders(handleEmbedStatus(ctxHolder.scheduler), isDev),
|
|
1563
|
-
},
|
|
1564
|
-
"/api/collections/:name": {
|
|
1565
|
-
PATCH: async (req: Request) => {
|
|
1566
|
-
if (!isRequestAllowed(req, port)) {
|
|
1567
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1568
|
-
}
|
|
1569
|
-
const url = new URL(req.url);
|
|
1570
|
-
const name = decodeURIComponent(
|
|
1571
|
-
url.pathname.split("/").pop() || ""
|
|
1572
|
-
);
|
|
1573
|
-
return withSecurityHeaders(
|
|
1574
|
-
await handleUpdateCollection(ctxHolder, store, name, req),
|
|
1575
|
-
isDev
|
|
1576
|
-
);
|
|
1577
|
-
},
|
|
1578
|
-
DELETE: async (req: Request) => {
|
|
1579
|
-
if (!isRequestAllowed(req, port)) {
|
|
1580
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1581
|
-
}
|
|
1582
|
-
const url = new URL(req.url);
|
|
1583
|
-
const name = decodeURIComponent(
|
|
1584
|
-
url.pathname.split("/").pop() || ""
|
|
1585
|
-
);
|
|
1586
|
-
return withSecurityHeaders(
|
|
1587
|
-
await handleDeleteCollection(ctxHolder, store, name),
|
|
1588
|
-
isDev
|
|
1589
|
-
);
|
|
1590
|
-
},
|
|
1591
|
-
},
|
|
1592
|
-
"/api/collections/:name/egress-policy": {
|
|
1593
|
-
GET: (req: Request) => {
|
|
1594
|
-
const parts = new URL(req.url).pathname.split("/");
|
|
1595
|
-
const name = decodeURIComponent(parts.at(-2) ?? "");
|
|
1596
|
-
return withSecurityHeaders(
|
|
1597
|
-
handleCollectionEgressPolicy(ctxHolder, name),
|
|
1598
|
-
isDev
|
|
1599
|
-
);
|
|
1600
|
-
},
|
|
1601
|
-
PUT: async (req: Request) => {
|
|
1602
|
-
if (!isRequestAllowed(req, port)) {
|
|
1603
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1604
|
-
}
|
|
1605
|
-
const parts = new URL(req.url).pathname.split("/");
|
|
1606
|
-
const name = decodeURIComponent(parts.at(-2) ?? "");
|
|
1607
|
-
return withSecurityHeaders(
|
|
1608
|
-
await handleUpdateCollectionEgressPolicy(
|
|
1609
|
-
ctxHolder,
|
|
1610
|
-
store,
|
|
1611
|
-
name,
|
|
1612
|
-
req
|
|
1613
|
-
),
|
|
1614
|
-
isDev
|
|
1615
|
-
);
|
|
1616
|
-
},
|
|
1617
|
-
},
|
|
1618
|
-
"/api/collections/:name/embeddings/clear": {
|
|
1619
|
-
POST: async (req: Request) => {
|
|
1620
|
-
if (!isRequestAllowed(req, port)) {
|
|
1621
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1622
|
-
}
|
|
1623
|
-
const url = new URL(req.url);
|
|
1624
|
-
const parts = url.pathname.split("/");
|
|
1625
|
-
const name = decodeURIComponent(parts.at(-3) || "");
|
|
1626
|
-
return withSecurityHeaders(
|
|
1627
|
-
await handleClearCollectionEmbeddings(
|
|
1628
|
-
ctxHolder,
|
|
1629
|
-
store,
|
|
1630
|
-
name,
|
|
1631
|
-
req
|
|
1632
|
-
),
|
|
1633
|
-
isDev
|
|
1634
|
-
);
|
|
1635
|
-
},
|
|
1636
|
-
},
|
|
1637
|
-
"/api/doc/:id/links": {
|
|
1638
|
-
GET: async (req: Request) => {
|
|
1639
|
-
const url = new URL(req.url);
|
|
1640
|
-
// Extract id from /api/doc/:id/links
|
|
1641
|
-
const parts = url.pathname.split("/");
|
|
1642
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1643
|
-
return withSecurityHeaders(
|
|
1644
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1645
|
-
handleDocLinks(store, id, url)
|
|
1646
|
-
),
|
|
1647
|
-
isDev
|
|
1648
|
-
);
|
|
1649
|
-
},
|
|
1650
|
-
},
|
|
1651
|
-
"/api/doc/:id/sections": {
|
|
1652
|
-
GET: async (req: Request) => {
|
|
1653
|
-
const url = new URL(req.url);
|
|
1654
|
-
const parts = url.pathname.split("/");
|
|
1655
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1656
|
-
return withSecurityHeaders(
|
|
1657
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1658
|
-
handleDocSections(store, id, req)
|
|
1659
|
-
),
|
|
1660
|
-
isDev
|
|
1661
|
-
);
|
|
1662
|
-
},
|
|
1663
|
-
},
|
|
1664
|
-
"/api/doc/:id/section-targets": {
|
|
1665
|
-
POST: async (req: Request) => {
|
|
1666
|
-
if (!isRequestAllowed(req, port)) {
|
|
1667
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1668
|
-
}
|
|
1669
|
-
const parts = new URL(req.url).pathname.split("/");
|
|
1670
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1671
|
-
return withSecurityHeaders(
|
|
1672
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1673
|
-
handleCreateSectionTarget(store, id, req)
|
|
1674
|
-
),
|
|
1675
|
-
isDev
|
|
1676
|
-
);
|
|
1677
|
-
},
|
|
1678
|
-
},
|
|
1679
|
-
"/api/doc/:id/section-targets/resolve": {
|
|
1680
|
-
POST: async (req: Request) => {
|
|
1681
|
-
if (!isRequestAllowed(req, port)) {
|
|
1682
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1683
|
-
}
|
|
1684
|
-
const parts = new URL(req.url).pathname.split("/");
|
|
1685
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1686
|
-
return withSecurityHeaders(
|
|
1687
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1688
|
-
handleResolveSectionTarget(store, id, req)
|
|
1689
|
-
),
|
|
1690
|
-
isDev
|
|
1691
|
-
);
|
|
1692
|
-
},
|
|
1693
|
-
},
|
|
1694
|
-
"/api/doc/:id/backlinks": {
|
|
1695
|
-
GET: async (req: Request) => {
|
|
1696
|
-
const url = new URL(req.url);
|
|
1697
|
-
// Extract id from /api/doc/:id/backlinks
|
|
1698
|
-
const parts = url.pathname.split("/");
|
|
1699
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1700
|
-
return withSecurityHeaders(
|
|
1701
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1702
|
-
handleDocBacklinks(store, id)
|
|
1703
|
-
),
|
|
1704
|
-
isDev
|
|
1705
|
-
);
|
|
1706
|
-
},
|
|
1707
|
-
},
|
|
1708
|
-
"/api/doc/:id/similar": {
|
|
1709
|
-
GET: async (req: Request) => {
|
|
1710
|
-
const url = new URL(req.url);
|
|
1711
|
-
// Extract id from /api/doc/:id/similar
|
|
1712
|
-
const parts = url.pathname.split("/");
|
|
1713
|
-
const id = decodeURIComponent(parts[3] || "");
|
|
1714
|
-
return withSecurityHeaders(
|
|
1715
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1716
|
-
handleDocSimilar(ctxHolder.current, id, url)
|
|
1717
|
-
),
|
|
1718
|
-
isDev
|
|
1719
|
-
);
|
|
1720
|
-
},
|
|
1721
|
-
},
|
|
1722
|
-
"/api/graph": {
|
|
1723
|
-
GET: async (req: Request) => {
|
|
1724
|
-
const url = new URL(req.url);
|
|
1725
|
-
return withSecurityHeaders(
|
|
1726
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1727
|
-
handleGraph(store, url, getActivePreset(ctxHolder.config).embed)
|
|
1728
|
-
),
|
|
1729
|
-
isDev
|
|
1730
|
-
);
|
|
1731
|
-
},
|
|
1732
|
-
},
|
|
1733
|
-
"/api/graph/query": {
|
|
1734
|
-
POST: async (req: Request) => {
|
|
1735
|
-
if (!isRequestAllowed(req, port)) {
|
|
1736
|
-
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1737
|
-
}
|
|
1738
|
-
return withSecurityHeaders(
|
|
1739
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1740
|
-
handleGraphQuery(store, ctxHolder.config, req)
|
|
1741
|
-
),
|
|
1742
|
-
isDev
|
|
1743
|
-
);
|
|
1744
|
-
},
|
|
1745
|
-
},
|
|
1746
|
-
"/api/changes": {
|
|
1747
|
-
GET: async (req: Request) => {
|
|
1748
|
-
const url = new URL(req.url);
|
|
1749
|
-
return withSecurityHeaders(
|
|
1750
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1751
|
-
handleChanges(store, url)
|
|
1752
|
-
),
|
|
1753
|
-
isDev
|
|
1754
|
-
);
|
|
1755
|
-
},
|
|
1756
|
-
},
|
|
1757
|
-
"/api/diff": {
|
|
1758
|
-
GET: async (req: Request) => {
|
|
1759
|
-
const url = new URL(req.url);
|
|
1760
|
-
return withSecurityHeaders(
|
|
1761
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1762
|
-
handleDiff(store, url)
|
|
1763
|
-
),
|
|
1764
|
-
isDev
|
|
1765
|
-
);
|
|
1766
|
-
},
|
|
1767
|
-
},
|
|
1768
|
-
"/api/impact": {
|
|
1769
|
-
GET: async (req: Request) => {
|
|
1770
|
-
const url = new URL(req.url);
|
|
1771
|
-
return withSecurityHeaders(
|
|
1772
|
-
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1773
|
-
handleImpact(store, url)
|
|
1774
|
-
),
|
|
1775
|
-
isDev
|
|
1776
|
-
);
|
|
1917
|
+
),
|
|
1918
|
+
isDev
|
|
1919
|
+
);
|
|
1920
|
+
},
|
|
1921
|
+
},
|
|
1922
|
+
"/api/graph/query": {
|
|
1923
|
+
POST: async (req: Request) => {
|
|
1924
|
+
if (!isRequestAllowed(req, port)) {
|
|
1925
|
+
return withSecurityHeaders(forbiddenResponse(), isDev);
|
|
1926
|
+
}
|
|
1927
|
+
return withSecurityHeaders(
|
|
1928
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1929
|
+
handleGraphQuery(store, ctxHolder.config, req)
|
|
1930
|
+
),
|
|
1931
|
+
isDev
|
|
1932
|
+
);
|
|
1933
|
+
},
|
|
1934
|
+
},
|
|
1935
|
+
"/api/changes": {
|
|
1936
|
+
GET: async (req: Request) => {
|
|
1937
|
+
const url = new URL(req.url);
|
|
1938
|
+
return withSecurityHeaders(
|
|
1939
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1940
|
+
handleChanges(store, url)
|
|
1941
|
+
),
|
|
1942
|
+
isDev
|
|
1943
|
+
);
|
|
1944
|
+
},
|
|
1945
|
+
},
|
|
1946
|
+
"/api/diff": {
|
|
1947
|
+
GET: async (req: Request) => {
|
|
1948
|
+
const url = new URL(req.url);
|
|
1949
|
+
return withSecurityHeaders(
|
|
1950
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1951
|
+
handleDiff(store, url)
|
|
1952
|
+
),
|
|
1953
|
+
isDev
|
|
1954
|
+
);
|
|
1955
|
+
},
|
|
1956
|
+
},
|
|
1957
|
+
"/api/impact": {
|
|
1958
|
+
GET: async (req: Request) => {
|
|
1959
|
+
const url = new URL(req.url);
|
|
1960
|
+
return withSecurityHeaders(
|
|
1961
|
+
await handleResidentRead(runtime as ResidentRuntime, req, () =>
|
|
1962
|
+
handleImpact(store, url)
|
|
1963
|
+
),
|
|
1964
|
+
isDev
|
|
1965
|
+
);
|
|
1966
|
+
},
|
|
1777
1967
|
},
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1968
|
+
})
|
|
1969
|
+
),
|
|
1780
1970
|
// Production catch-all: /vendor/pdfjs prefix, then hashed SPA chunks
|
|
1781
1971
|
// (gzip + immutable) and the private SPA source — the same factory the
|
|
1782
1972
|
// tests mount (no test-only fallback path).
|