@hearsay-tools/squawk 0.18.0-dev.7876 → 0.18.0-dev.7880

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.
@@ -54,7 +54,7 @@ import { runRelationships } from './run-relationships.js';
54
54
  import { delegationFailure } from '../delegation/routes.js';
55
55
  import { githubItemParamsSchema } from '../contract/index.js';
56
56
  import { workerDestroyRequestSchema, workerEmptyRequestSchema, runRelationshipsSchema } from '../contract/index.js';
57
- import { existsSync, readFileSync, statSync } from 'node:fs';
57
+ import { existsSync } from 'node:fs';
58
58
  import { randomUUID } from 'node:crypto';
59
59
  import { createAutomationService, onceCreateAnswer } from '../automations/service.js';
60
60
  import { createAutomationToolService } from '../automations/tool-adapter.js';
@@ -105,7 +105,7 @@ import { ownPullRequestNumbers } from '../runs/pull-requests.js';
105
105
  import { ColdRepoHandles } from './cold-repo-handles.js';
106
106
  import { isV2WireEventType } from '../runs/ui-event-sink.js';
107
107
  import { runEventsQuerySchema, runHistoryQuerySchema, runIdParamSchema, } from '../contract/index.js';
108
- import { resolveAttachmentPath } from '../workflows/attachment-path.js';
108
+ import { resolveAttachmentPathAsync } from '../workflows/attachment-path.js';
109
109
  import { artifactParamsSchema, fileLinkQuerySchema } from '../contract/index.js';
110
110
  import { listArtifacts, readArtifact, readArtifactMetadata } from '../artifacts/store.js';
111
111
  import { artifactPreview, loadFileLink, rasterMime } from '../artifacts/resolve.js';
@@ -153,6 +153,7 @@ import { providerForExistingRun, providersRequiredByWorkflow, } from './provider
153
153
  import { attachProjectWebhooks, createBootContext, createProviderStatus, emitProviderRow, resolveServerDeps, watchProviderRuntimeAuth, } from './server-deps.js';
154
154
  import { NO_WEBHOOK_ERROR, agentProfileRefusal, clientRequestOf, launchRun, modelLockRefusal, notifyRefusal, providerGateRefusal, replayedRun, resolveStartWorkflow, startRunInput, } from './start-run-options.js';
155
155
  import { ASSET_CACHE_CONTROL, BUILD_HINT_HTML, assetContentType, isSafeAssetFilename, resolveGetRequest, } from './static-ui.js';
156
+ import { compression, createStaticAssets, isFile } from './static-assets.js';
156
157
  import { registerBrandFileRoutes } from './brand-file-routes.js';
157
158
  /** The hosted-mode refusal, worded like the agent-config one it mirrors. */
158
159
  const HOSTED_GITHUB_CREATE_REFUSAL = 'Creating GitHub repositories is available from a local cockpit only';
@@ -481,6 +482,11 @@ export function createApp(deps) {
481
482
  };
482
483
  };
483
484
  const app = new Hono();
485
+ app.use('*', compression);
486
+ // One cache per app: immutable bundle bytes and their negotiated encodings share a cap.
487
+ // Live shell and worker files bypass it so a rebuild appears on the next request.
488
+ // Compression runs outside route families and leaves live event streams untouched.
489
+ const staticResponse = createStaticAssets();
484
490
  // Reject oversized request bodies before they reach any handler (#429). GETs
485
491
  // and SSE carry no body, so this only ever gates the mutating routes.
486
492
  app.use('*', bodyLimit({ maxSize: GLOBAL_BODY_LIMIT }));
@@ -574,7 +580,7 @@ export function createApp(deps) {
574
580
  const webDir = resolveWebDir();
575
581
  const distDir = join(webDir, 'dist');
576
582
  const HTML_TYPE = 'text/html; charset=utf-8';
577
- const staticFile = (name, type) => (c) => {
583
+ const staticFile = (name, type) => async (c) => {
578
584
  // Read per request — the files are tiny and this keeps dev iteration live.
579
585
  //
580
586
  // Served out of the Vite build: the files are `public/` assets of the web package, which the
@@ -583,24 +589,22 @@ export function createApp(deps) {
583
589
  // paths. Without a build there is nothing to serve, which is a 404 rather than a crash (the
584
590
  // shell route answers the same dev-only state with its build hint).
585
591
  const path = join(distDir, name);
586
- if (!existsSync(path))
587
- return c.json({ error: 'not found' }, 404);
588
- return new Response(readFileSync(path), { headers: { 'content-type': type } });
592
+ return staticResponse(c.req.raw, path, { 'content-type': type });
589
593
  };
590
594
  // Stable SharedWorker identity across same-origin tabs; its imported chunks stay hashed.
591
- app.get('/live-worker.js', (c) => {
592
- const response = staticFile('live-worker.js', 'text/javascript; charset=utf-8')(c);
595
+ app.get('/live-worker.js', async (c) => {
596
+ const response = await staticFile('live-worker.js', 'text/javascript; charset=utf-8')(c);
593
597
  response.headers.set('Cache-Control', 'no-cache');
594
598
  return response;
595
599
  });
596
600
  let hintLogged = false;
597
- const serveShell = (c) => {
601
+ const serveShell = async (c) => {
598
602
  const distIndex = join(distDir, 'index.html');
599
- // existsSync per request, like the reads below: `npm run build:web` in a
603
+ // Async stat per request, like the reads below: `npm run build:web` in a
600
604
  // running cockpit takes effect on the next reload, no restart.
601
605
  const target = resolveGetRequest({
602
606
  path: c.req.path,
603
- distExists: existsSync(distIndex),
607
+ distExists: await isFile(distIndex),
604
608
  });
605
609
  if (target === 'passthrough')
606
610
  return undefined;
@@ -615,28 +619,22 @@ export function createApp(deps) {
615
619
  headers: { 'content-type': HTML_TYPE },
616
620
  });
617
621
  }
618
- return new Response(readFileSync(distIndex), {
619
- headers: { 'content-type': HTML_TYPE },
620
- });
622
+ return staticResponse(c.req.raw, distIndex, { 'content-type': HTML_TYPE });
621
623
  };
622
624
  // Hashed bundles/fonts of the built app. Vite fingerprints every name, so
623
625
  // the bytes behind a URL never change — cache them hard. Only plain
624
626
  // filenames are served: `basename('..')` is `'..'` (it resolves to the
625
- // assets dir itself and readFileSync would throw EISDIR), so dot-segments
627
+ // assets dir itself and readFile would throw EISDIR), so dot-segments
626
628
  // and separator-bearing params get a 404, not a 500.
627
- app.get('/assets/:file', (c) => {
629
+ app.get('/assets/:file', async (c) => {
628
630
  const file = c.req.param('file');
629
631
  if (!isSafeAssetFilename(file))
630
632
  return c.json({ error: 'not found' }, 404);
631
633
  const path = join(distDir, 'assets', file);
632
- if (!existsSync(path) || !statSync(path).isFile())
633
- return c.json({ error: 'not found' }, 404);
634
- return new Response(readFileSync(path), {
635
- headers: {
636
- 'content-type': assetContentType(file),
637
- 'cache-control': ASSET_CACHE_CONTROL,
638
- },
639
- });
634
+ return staticResponse(c.req.raw, path, {
635
+ 'content-type': assetContentType(file),
636
+ 'cache-control': ASSET_CACHE_CONTROL,
637
+ }, true);
640
638
  });
641
639
  registerBrandFileRoutes(app, staticFile);
642
640
  // ---- meta ----------------------------------------------------------------
@@ -2872,13 +2870,13 @@ export function createApp(deps) {
2872
2870
  'content-type': 'text/markdown; charset=utf-8',
2873
2871
  });
2874
2872
  })
2875
- .get('/runs/:id/images/:file', paramZodValidator(attachmentFileParamSchema), (c) => {
2873
+ .get('/runs/:id/images/:file', paramZodValidator(attachmentFileParamSchema), async (c) => {
2876
2874
  const { store } = c.get('project');
2877
2875
  const run = store.getRun(c.req.param('id'));
2878
2876
  if (!run)
2879
2877
  return c.json({ error: 'not found' }, 404);
2880
2878
  const file = c.req.valid('param').file;
2881
- const path = resolveAttachmentPath(store.claims.sourceDataDir(run.id), run.id, file);
2879
+ const path = await resolveAttachmentPathAsync(store.claims.sourceDataDir(run.id), run.id, file);
2882
2880
  if (!path)
2883
2881
  return c.json({ error: 'not found' }, 404);
2884
2882
  const ext = file.split('.').pop() ?? '';
@@ -2886,7 +2884,7 @@ export function createApp(deps) {
2886
2884
  // An image answers exactly as it always has — the cockpit renders it in an `<img>`.
2887
2885
  // Everything else is a user-supplied file (#950) and leaves under the download headers.
2888
2886
  const type = image ?? FILE_TYPES[ext] ?? 'application/octet-stream';
2889
- return new Response(readFileSync(path), {
2887
+ return new Response(await readFile(path), {
2890
2888
  headers: {
2891
2889
  'content-type': type,
2892
2890
  'cache-control': 'private, max-age=31536000, immutable',
@@ -4156,7 +4154,7 @@ export function createApp(deps) {
4156
4154
  // an unknown API path must never answer with HTML.
4157
4155
  // Without a web/dist build this serves the built-in build-hint page (dev-only
4158
4156
  // state — the published tarball ships web/dist), never a 404.
4159
- routed.get('*', (c) => serveShell(c) ?? c.notFound());
4157
+ routed.get('*', async (c) => await serveShell(c) ?? c.notFound());
4160
4158
  return routed;
4161
4159
  }
4162
4160
  /** The host a thread link names (#589): the bound one, or loopback for a wildcard bind. */