@valbuild/server 0.150.5 → 0.150.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @valbuild/server
2
2
 
3
+ ## 0.150.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`fdb0280`](https://github.com/valbuild/val/commit/fdb02809830355e595127814c8e8676fdb0d5279)]:
8
+ - @valbuild/ui@0.150.9
9
+ - @valbuild/shared@0.150.8
10
+
11
+ ## 0.150.8
12
+
13
+ ### Patch Changes
14
+
15
+ - [#968](https://github.com/valbuild/val/pull/968) [`2a16ffa`](https://github.com/valbuild/val/commit/2a16ffacd1c77bccaa6ccf5f8754b1f9c574d4f2) Thanks [@freekh](https://github.com/freekh)! - The assistant can search, format and typecheck a proposal's code, and change content in the design tab.
16
+
17
+ - **`search_code`** finds every line of the project that matches some text or a regular expression, with its file and line number, so the assistant finds where something is rendered before reading whole files.
18
+ - **`format_files`** formats the proposal's files with Prettier and the project's own config (`.prettierrc`, `.prettierrc.json` or `package.json`'s `prettier`), and stages the ones that change. It runs in the browser, loaded the first time it is used, because the platform's server cannot run Prettier. A config it cannot read — JavaScript, YAML, plugins or per-file overrides — is reported rather than guessed at.
19
+ - **`typecheck`** checks the proposal's code with TypeScript and answers the type errors the proposal adds — not the ones the site already has. The assistant runs it after changing code and before building. In the design tab its result is the Types check.
20
+ - **`create_patch` in the design tab** writes content into the module's file in the proposal and stages it with the code, so a field the assistant adds to a schema is filled in the same change and built with it.
21
+
22
+ - [#963](https://github.com/valbuild/val/pull/963) [`f7d56ec`](https://github.com/valbuild/val/commit/f7d56ecaed8567c0ea2889bbf1ba64844356cb1a) Thanks [@freekh](https://github.com/freekh)! - The assistant's chats in a proposal are shared with everyone on the project. A chat started while you are in a proposal belongs to it: anyone on the project who opens the proposal sees it in the chat list, with who is in it, and can read it and keep asking. Messages are named once more than one person has written, and the chat header has a link to the chat. One question runs at a time: if someone else's question is running, what you write is sent when its answer is done. Chats started on the site stay your own.
23
+
24
+ It needs the content server that knows about proposal chats; with an older one, chats work as before.
25
+
26
+ - Updated dependencies [[`5960071`](https://github.com/valbuild/val/commit/59600711af792f489b050ab47bcdc103d7d8c028), [`2a16ffa`](https://github.com/valbuild/val/commit/2a16ffacd1c77bccaa6ccf5f8754b1f9c574d4f2), [`f7d56ec`](https://github.com/valbuild/val/commit/f7d56ecaed8567c0ea2889bbf1ba64844356cb1a)]:
27
+ - @valbuild/shared@0.150.8
28
+ - @valbuild/ui@0.150.8
29
+
3
30
  ## 0.150.5
4
31
 
5
32
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-f9016ae0.cjs.dev.js');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-946e45df.cjs.dev.js');
7
7
  require('@valbuild/shared/internal');
8
8
  require('zod');
9
9
  require('zod-validation-error');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@valbuild/core');
6
- var ValRouterCore = require('../../dist/ValRouterCore-2e82ae18.cjs.prod.js');
6
+ var ValRouterCore = require('../../dist/ValRouterCore-97c47cec.cjs.prod.js');
7
7
  require('@valbuild/shared/internal');
8
8
  require('zod');
9
9
  require('zod-validation-error');
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
- import { j as ValOpsMemory, E as bytesToBase64, y as ValServer, z as createValRequestHandler } from '../../dist/ValRouterCore-b3c6a562.esm.js';
2
+ import { j as ValOpsMemory, E as bytesToBase64, y as ValServer, z as createValRequestHandler } from '../../dist/ValRouterCore-2f7ad9b9.esm.js';
3
3
  import '@valbuild/shared/internal';
4
4
  import 'zod';
5
5
  import 'zod-validation-error';
@@ -8439,7 +8439,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8439
8439
  id: z.string(),
8440
8440
  name: z.string().nullable(),
8441
8441
  createdAt: z.string(),
8442
- updatedAt: z.string()
8442
+ updatedAt: z.string(),
8443
+ // A proposal's chats say who is in each (Flow H).
8444
+ authorIds: z.array(z.string()).optional()
8443
8445
  })),
8444
8446
  nextCursor: z.object({
8445
8447
  updatedAt: z.string(),
@@ -8448,6 +8450,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
8448
8450
  });
8449
8451
  const params = new URLSearchParams();
8450
8452
  if (req.query.limit) params.set("limit", req.query.limit);
8453
+ // In a proposal, its chats, everyone's (Flow H).
8454
+ if (req.query.proposal) params.set("proposal", req.query.proposal);
8451
8455
  if (req.query.cursor_updatedAt) {
8452
8456
  params.set("cursor_updatedAt", req.query.cursor_updatedAt);
8453
8457
  }
@@ -8637,7 +8641,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8637
8641
  const SessionMessagesResponse = z.object({
8638
8642
  messages: z.array(z.object({
8639
8643
  role: z.string(),
8640
- content: AIMessageContent
8644
+ content: AIMessageContent,
8645
+ // Who asked, on a user message (Flow H).
8646
+ authorId: z.string().nullable().optional()
8641
8647
  })),
8642
8648
  nextCursor: z.object({
8643
8649
  updatedAt: z.string(),
@@ -9110,7 +9116,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9110
9116
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9111
9117
  const {
9112
9118
  getJsonEntryAtCommit
9113
- } = await import('./getJsonEntryAtCommit-ad6deabd.esm.js');
9119
+ } = await import('./getJsonEntryAtCommit-8a6adc22.esm.js');
9114
9120
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9115
9121
  if (result.isErr(res)) {
9116
9122
  return historyErrorResponse(res.error);
@@ -8445,7 +8445,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8445
8445
  id: z.z.string(),
8446
8446
  name: z.z.string().nullable(),
8447
8447
  createdAt: z.z.string(),
8448
- updatedAt: z.z.string()
8448
+ updatedAt: z.z.string(),
8449
+ // A proposal's chats say who is in each (Flow H).
8450
+ authorIds: z.z.array(z.z.string()).optional()
8449
8451
  })),
8450
8452
  nextCursor: z.z.object({
8451
8453
  updatedAt: z.z.string(),
@@ -8454,6 +8456,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
8454
8456
  });
8455
8457
  const params = new URLSearchParams();
8456
8458
  if (req.query.limit) params.set("limit", req.query.limit);
8459
+ // In a proposal, its chats, everyone's (Flow H).
8460
+ if (req.query.proposal) params.set("proposal", req.query.proposal);
8457
8461
  if (req.query.cursor_updatedAt) {
8458
8462
  params.set("cursor_updatedAt", req.query.cursor_updatedAt);
8459
8463
  }
@@ -8643,7 +8647,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8643
8647
  const SessionMessagesResponse = z.z.object({
8644
8648
  messages: z.z.array(z.z.object({
8645
8649
  role: z.z.string(),
8646
- content: AIMessageContent
8650
+ content: AIMessageContent,
8651
+ // Who asked, on a user message (Flow H).
8652
+ authorId: z.z.string().nullable().optional()
8647
8653
  })),
8648
8654
  nextCursor: z.z.object({
8649
8655
  updatedAt: z.z.string(),
@@ -9116,7 +9122,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9116
9122
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9117
9123
  const {
9118
9124
  getJsonEntryAtCommit
9119
- } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-b8469ec5.cjs.dev.js'); });
9125
+ } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-757fec21.cjs.dev.js'); });
9120
9126
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9121
9127
  if (fp.result.isErr(res)) {
9122
9128
  return historyErrorResponse(res.error);
@@ -8445,7 +8445,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8445
8445
  id: z.z.string(),
8446
8446
  name: z.z.string().nullable(),
8447
8447
  createdAt: z.z.string(),
8448
- updatedAt: z.z.string()
8448
+ updatedAt: z.z.string(),
8449
+ // A proposal's chats say who is in each (Flow H).
8450
+ authorIds: z.z.array(z.z.string()).optional()
8449
8451
  })),
8450
8452
  nextCursor: z.z.object({
8451
8453
  updatedAt: z.z.string(),
@@ -8454,6 +8456,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
8454
8456
  });
8455
8457
  const params = new URLSearchParams();
8456
8458
  if (req.query.limit) params.set("limit", req.query.limit);
8459
+ // In a proposal, its chats, everyone's (Flow H).
8460
+ if (req.query.proposal) params.set("proposal", req.query.proposal);
8457
8461
  if (req.query.cursor_updatedAt) {
8458
8462
  params.set("cursor_updatedAt", req.query.cursor_updatedAt);
8459
8463
  }
@@ -8643,7 +8647,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
8643
8647
  const SessionMessagesResponse = z.z.object({
8644
8648
  messages: z.z.array(z.z.object({
8645
8649
  role: z.z.string(),
8646
- content: AIMessageContent
8650
+ content: AIMessageContent,
8651
+ // Who asked, on a user message (Flow H).
8652
+ authorId: z.z.string().nullable().optional()
8647
8653
  })),
8648
8654
  nextCursor: z.z.object({
8649
8655
  updatedAt: z.z.string(),
@@ -9116,7 +9122,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
9116
9122
  // TypeScript compiler. See `patch/ts/publishKit.ts`.
9117
9123
  const {
9118
9124
  getJsonEntryAtCommit
9119
- } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-5552ac46.cjs.prod.js'); });
9125
+ } = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-e519549a.cjs.prod.js'); });
9120
9126
  const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
9121
9127
  if (fp.result.isErr(res)) {
9122
9128
  return historyErrorResponse(res.error);
@@ -311,15 +311,20 @@ export declare class ValOpsHttp extends ValOps {
311
311
  /**
312
312
  * The writes the SITE's server may make to a proposal's files: what the
313
313
  * design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
314
- * code and build it. The tab is served by the site's
314
+ * code, build it, and report its typecheck. The tab is served by the site's
315
315
  * build so that a build the assistant breaks in the proposal cannot take
316
316
  * down the tools it would fix it with; at the proposal's address those
317
317
  * tools run on the proposal's own code.
318
318
  *
319
+ * The typecheck too, though it blocks the proposal's Publish (adept.md,
320
+ * decision 20): it is the proposal's staged files checked against the
321
+ * site's, the same program from either address, and the content service
322
+ * keeps it only for the inputs it was made from. Without it the tab's
323
+ * Types check, and the assistant's `typecheck`, had nothing to show.
324
+ *
319
325
  * The rest stay the proposal's own: Update from the site and the lockfile
320
- * are answered from the proposal's build and schemas, bringing back a
321
- * point's code is the Studio at its address finishing a restore, and the
322
- * typecheck it reports is what blocks its Publish (adept.md, decision 20).
326
+ * are answered from the proposal's build and schemas, and bringing back a
327
+ * point's code is the Studio at its address finishing a restore.
323
328
  */
324
329
  private static readonly SITE_MAY_WRITE;
325
330
  /**
@@ -346,6 +351,20 @@ export declare class ValOpsHttp extends ValOps {
346
351
  body: string;
347
352
  contentType: string;
348
353
  }>;
354
+ /**
355
+ * A patch written into a module's FILE in a proposal, and staged there as
356
+ * code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
357
+ * The assistant there changes the proposal's code, so content it writes goes
358
+ * with that code -- a field it just added is filled in the same change, and
359
+ * built and rendered with it -- rather than into the proposal's saves, which
360
+ * the site's server does not write.
361
+ *
362
+ * Answered here, at `POST /<name>/patch-file`: the file is the proposal's
363
+ * copy if it has one, otherwise the one this build was made from, and the
364
+ * patch is written into it as a save writes one (`patchModuleText`). Who may
365
+ * is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
366
+ */
367
+ private patchFileInProposal;
349
368
  /**
350
369
  * Update from the site, for a proposal that changes only content
351
370
  * (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var ts = require('typescript');
4
- var ValRouterCore = require('./ValRouterCore-f9016ae0.cjs.dev.js');
4
+ var ValRouterCore = require('./ValRouterCore-946e45df.cjs.dev.js');
5
5
  var fp = require('@valbuild/core/fp');
6
6
  var jsonValuesModule = require('./jsonValuesModule-8ae503a8.cjs.dev.js');
7
7
  require('@valbuild/core');
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { F as bytesToUtf8, G as posixPath } from './ValRouterCore-b3c6a562.esm.js';
2
+ import { F as bytesToUtf8, G as posixPath } from './ValRouterCore-2f7ad9b9.esm.js';
3
3
  import { result } from '@valbuild/core/fp';
4
4
  import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-427d68c8.esm.js';
5
5
  import '@valbuild/core';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var ts = require('typescript');
4
- var ValRouterCore = require('./ValRouterCore-2e82ae18.cjs.prod.js');
4
+ var ValRouterCore = require('./ValRouterCore-97c47cec.cjs.prod.js');
5
5
  var fp = require('@valbuild/core/fp');
6
6
  var jsonValuesModule = require('./jsonValuesModule-d1bb8d8f.cjs.prod.js');
7
7
  require('@valbuild/core');
@@ -12,7 +12,7 @@ var path = require('path');
12
12
  var fs = require('fs');
13
13
  var vm = require('node:vm');
14
14
  var node_module = require('node:module');
15
- var ValRouterCore = require('./ValRouterCore-f9016ae0.cjs.dev.js');
15
+ var ValRouterCore = require('./ValRouterCore-946e45df.cjs.dev.js');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var z = require('zod');
18
18
  var zodValidationError = require('zod-validation-error');
@@ -4978,6 +4978,46 @@ function sameJson(a, b) {
4978
4978
  return JSON.stringify(a) === JSON.stringify(b);
4979
4979
  }
4980
4980
 
4981
+ /**
4982
+ * A module's file with a patch written into it: what a save does to a
4983
+ * `.val.ts`, for one file and one patch, with nothing pending around it.
4984
+ *
4985
+ * The design tab's `create_patch` (valbuild/home `docs/design-tab.md`): there
4986
+ * the assistant changes a proposal's code, and content it writes goes into the
4987
+ * module's file and is staged with the code -- so a field it just added can
4988
+ * be filled in the same change, and is built and rendered with it.
4989
+ *
4990
+ * Only the module's own file. A `.jsonValues()` entry lives in a `*.val.json`
4991
+ * of its own, which a save routes to op by op (`ValOps.prepare`); a patch that
4992
+ * reaches into one fails here, and the message says to write that file.
4993
+ */
4994
+ async function patchModuleText(text, patch$1) {
4995
+ // The TypeScript compiler, loaded when a patch asks for it, as a save loads
4996
+ // it: see `publishKit.ts`.
4997
+ const {
4998
+ tsOps,
4999
+ parseValFile
5000
+ } = await Promise.resolve().then(function () { return require('./publishKit-5865095c.cjs.dev.js'); });
5001
+ const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
5002
+ if (fp.result.isErr(applied)) {
5003
+ const reason = messagesOf(applied.error).join(" ");
5004
+ return fp.result.err(text.includes(".jsonValues(") ? `${reason} This module keeps entries in .val.json files of their own: change an entry by writing its file with write_files.` : reason);
5005
+ }
5006
+ const sourceFile = applied.value;
5007
+ // As a save writes it: https://github.com/microsoft/TypeScript/issues/36174
5008
+ return fp.result.ok(unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u")));
5009
+ }
5010
+
5011
+ /**
5012
+ * A patch error, or a tree of syntax errors, as sentences. Walked here rather
5013
+ * than with `syntax.ts`'s `flattenErrors`, which would bring the compiler in
5014
+ * with this module.
5015
+ */
5016
+
5017
+ function messagesOf(error) {
5018
+ return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
5019
+ }
5020
+
4981
5021
  /**
4982
5022
  * Which of the site's pending changes a merge of a proposal moves into
4983
5023
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5083,6 +5123,18 @@ const textEncoder$2 = new TextEncoder();
5083
5123
  const PlanRefusedBody = z.z.object({
5084
5124
  error: internal.PlanRefusalError
5085
5125
  });
5126
+
5127
+ /** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
5128
+ const PatchFileBody = z.z.object({
5129
+ moduleFilePath: z.z.string().regex(/^\/.+\.val\.(ts|js)$/),
5130
+ patch: internal.Patch,
5131
+ message: z.z.string().max(500).optional()
5132
+ });
5133
+
5134
+ /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5135
+ const ProposalFilesRead = z.z.object({
5136
+ files: z.z.record(z.z.string(), z.z.string().nullable())
5137
+ });
5086
5138
  const PatchId = z.z.string().refine(s => !!s); // TODO: validate
5087
5139
  const CommitSha = z.z.string().refine(s => !!s); // TODO: validate
5088
5140
  z.z.string().refine(s => !!s); // TODO: validate
@@ -5859,17 +5911,22 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5859
5911
  /**
5860
5912
  * The writes the SITE's server may make to a proposal's files: what the
5861
5913
  * design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
5862
- * code and build it. The tab is served by the site's
5914
+ * code, build it, and report its typecheck. The tab is served by the site's
5863
5915
  * build so that a build the assistant breaks in the proposal cannot take
5864
5916
  * down the tools it would fix it with; at the proposal's address those
5865
5917
  * tools run on the proposal's own code.
5866
5918
  *
5919
+ * The typecheck too, though it blocks the proposal's Publish (adept.md,
5920
+ * decision 20): it is the proposal's staged files checked against the
5921
+ * site's, the same program from either address, and the content service
5922
+ * keeps it only for the inputs it was made from. Without it the tab's
5923
+ * Types check, and the assistant's `typecheck`, had nothing to show.
5924
+ *
5867
5925
  * The rest stay the proposal's own: Update from the site and the lockfile
5868
- * are answered from the proposal's build and schemas, bringing back a
5869
- * point's code is the Studio at its address finishing a restore, and the
5870
- * typecheck it reports is what blocks its Publish (adept.md, decision 20).
5926
+ * are answered from the proposal's build and schemas, and bringing back a
5927
+ * point's code is the Studio at its address finishing a restore.
5871
5928
  */
5872
- static SITE_MAY_WRITE = new Set(["files", "build"]);
5929
+ static SITE_MAY_WRITE = new Set(["files", "build", "typecheck"]);
5873
5930
 
5874
5931
  /**
5875
5932
  * Whether this server may make a write to a proposal's files: the
@@ -5906,13 +5963,17 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5906
5963
  return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
5907
5964
  }
5908
5965
  async proposalsApi(path, init, profileId) {
5909
- var _exec, _exec2, _exec3, _exec4;
5966
+ var _exec, _exec2, _exec3, _exec4, _exec5;
5910
5967
  const json = "application/json";
5911
5968
  const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
5912
5969
  if (updating !== undefined && init.method === "POST") {
5913
5970
  return this.updateContentFromSite(updating, init.body, profileId);
5914
5971
  }
5915
- const withCode = (_exec2 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5972
+ const patching = (_exec2 = /^\/([0-9a-f]{20})\/patch-file$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5973
+ if (patching !== undefined && init.method === "POST") {
5974
+ return this.patchFileInProposal(patching, init.body, profileId);
5975
+ }
5976
+ const withCode = (_exec3 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5916
5977
  if (withCode !== undefined && init.method === "POST") {
5917
5978
  return this.updateCodeFromSite(withCode, init.body, profileId);
5918
5979
  }
@@ -5922,11 +5983,11 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5922
5983
  * build's schemas (step 8.2). Anywhere else they go to content as they
5923
5984
  * are, and the site's pending changes block as they always did.
5924
5985
  */
5925
- const checking = (_exec3 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5986
+ const checking = (_exec4 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5926
5987
  if (checking !== undefined && init.method === "GET" && (await this.answersMovesFor(checking, profileId))) {
5927
5988
  return this.mergeChecksWithMoves(checking, profileId);
5928
5989
  }
5929
- const pressing = (_exec4 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5990
+ const pressing = (_exec5 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec5 === void 0 ? void 0 : _exec5[1];
5930
5991
  if (pressing !== undefined && init.method === "POST" && (await this.answersMovesFor(pressing, profileId))) {
5931
5992
  return this.pressMergeWithMoves(pressing, init.body, profileId);
5932
5993
  }
@@ -5976,6 +6037,121 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5976
6037
  };
5977
6038
  }
5978
6039
 
6040
+ /**
6041
+ * A patch written into a module's FILE in a proposal, and staged there as
6042
+ * code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
6043
+ * The assistant there changes the proposal's code, so content it writes goes
6044
+ * with that code -- a field it just added is filled in the same change, and
6045
+ * built and rendered with it -- rather than into the proposal's saves, which
6046
+ * the site's server does not write.
6047
+ *
6048
+ * Answered here, at `POST /<name>/patch-file`: the file is the proposal's
6049
+ * copy if it has one, otherwise the one this build was made from, and the
6050
+ * patch is written into it as a save writes one (`patchModuleText`). Who may
6051
+ * is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
6052
+ */
6053
+ async patchFileInProposal(name, body, profileId) {
6054
+ var _this$projectSource, _this$options;
6055
+ const json = "application/json";
6056
+ const answer = (status, value) => ({
6057
+ status,
6058
+ contentType: json,
6059
+ body: JSON.stringify(value)
6060
+ });
6061
+ if (!this.mayWriteFiles({
6062
+ name,
6063
+ write: "files"
6064
+ })) {
6065
+ return answer(403, {
6066
+ message: "Files are changed in the proposal this Studio is open in, not in another."
6067
+ });
6068
+ }
6069
+ let parsedBody;
6070
+ try {
6071
+ parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
6072
+ } catch {
6073
+ return answer(400, {
6074
+ message: "The patch's body is not JSON."
6075
+ });
6076
+ }
6077
+ const request = PatchFileBody.safeParse(parsedBody);
6078
+ if (!request.success) {
6079
+ return answer(400, {
6080
+ message: `Invalid patch: ${zodValidationError.fromError(request.error).toString()}`
6081
+ });
6082
+ }
6083
+ const {
6084
+ moduleFilePath,
6085
+ patch,
6086
+ message
6087
+ } = request.data;
6088
+ const content = this.proposalContent(name, profileId);
6089
+ const read = await content("/files");
6090
+ if (!read.ok) {
6091
+ return {
6092
+ status: read.status,
6093
+ contentType: json,
6094
+ body: await read.text()
6095
+ };
6096
+ }
6097
+ const files = ProposalFilesRead.safeParse(await read.json());
6098
+ if (!files.success) {
6099
+ return answer(502, {
6100
+ message: `Content answered the proposal's files in a shape this Val does not read: ${zodValidationError.fromError(files.error).toString()}`
6101
+ });
6102
+ }
6103
+ const filePath = moduleFilePath.replace(/^\/+/, "");
6104
+ const own = files.data.files[filePath];
6105
+ if (own === null) {
6106
+ return answer(409, {
6107
+ message: `${moduleFilePath} is deleted in this proposal.`
6108
+ });
6109
+ }
6110
+ if (own === undefined && this.projectSource === null) {
6111
+ return answer(409, {
6112
+ message: `This build does not carry its source, so ${moduleFilePath} can only be patched once the proposal has its own copy: write it with write_files.`
6113
+ });
6114
+ }
6115
+ const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
6116
+ if (text === undefined) {
6117
+ return answer(404, {
6118
+ message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
6119
+ });
6120
+ }
6121
+ const patched = await patchModuleText(text, patch);
6122
+ if (fp.result.isErr(patched)) {
6123
+ return answer(422, {
6124
+ message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
6125
+ });
6126
+ }
6127
+ let formatted = patched.value;
6128
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
6129
+ try {
6130
+ formatted = await this.options.formatter(patched.value, moduleFilePath);
6131
+ } catch (error) {
6132
+ return answer(422, {
6133
+ message: `The patched ${moduleFilePath} could not be formatted: ${error instanceof Error ? error.message : String(error)}`
6134
+ });
6135
+ }
6136
+ }
6137
+ const staged = await content("/files", {
6138
+ method: "POST",
6139
+ body: JSON.stringify({
6140
+ files: {
6141
+ [filePath]: formatted
6142
+ },
6143
+ ...(message !== undefined ? {
6144
+ message
6145
+ } : {})
6146
+ })
6147
+ });
6148
+ return {
6149
+ status: staged.status,
6150
+ contentType: staged.headers.get("Content-Type") ?? json,
6151
+ body: await staged.text()
6152
+ };
6153
+ }
6154
+
5979
6155
  /**
5980
6156
  * Update from the site, for a proposal that changes only content
5981
6157
  * (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
@@ -12,7 +12,7 @@ var path = require('path');
12
12
  var fs = require('fs');
13
13
  var vm = require('node:vm');
14
14
  var node_module = require('node:module');
15
- var ValRouterCore = require('./ValRouterCore-2e82ae18.cjs.prod.js');
15
+ var ValRouterCore = require('./ValRouterCore-97c47cec.cjs.prod.js');
16
16
  var server = require('@valbuild/ui/server');
17
17
  var z = require('zod');
18
18
  var zodValidationError = require('zod-validation-error');
@@ -4978,6 +4978,46 @@ function sameJson(a, b) {
4978
4978
  return JSON.stringify(a) === JSON.stringify(b);
4979
4979
  }
4980
4980
 
4981
+ /**
4982
+ * A module's file with a patch written into it: what a save does to a
4983
+ * `.val.ts`, for one file and one patch, with nothing pending around it.
4984
+ *
4985
+ * The design tab's `create_patch` (valbuild/home `docs/design-tab.md`): there
4986
+ * the assistant changes a proposal's code, and content it writes goes into the
4987
+ * module's file and is staged with the code -- so a field it just added can
4988
+ * be filled in the same change, and is built and rendered with it.
4989
+ *
4990
+ * Only the module's own file. A `.jsonValues()` entry lives in a `*.val.json`
4991
+ * of its own, which a save routes to op by op (`ValOps.prepare`); a patch that
4992
+ * reaches into one fails here, and the message says to write that file.
4993
+ */
4994
+ async function patchModuleText(text, patch$1) {
4995
+ // The TypeScript compiler, loaded when a patch asks for it, as a save loads
4996
+ // it: see `publishKit.ts`.
4997
+ const {
4998
+ tsOps,
4999
+ parseValFile
5000
+ } = await Promise.resolve().then(function () { return require('./publishKit-580f558a.cjs.prod.js'); });
5001
+ const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
5002
+ if (fp.result.isErr(applied)) {
5003
+ const reason = messagesOf(applied.error).join(" ");
5004
+ return fp.result.err(text.includes(".jsonValues(") ? `${reason} This module keeps entries in .val.json files of their own: change an entry by writing its file with write_files.` : reason);
5005
+ }
5006
+ const sourceFile = applied.value;
5007
+ // As a save writes it: https://github.com/microsoft/TypeScript/issues/36174
5008
+ return fp.result.ok(unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u")));
5009
+ }
5010
+
5011
+ /**
5012
+ * A patch error, or a tree of syntax errors, as sentences. Walked here rather
5013
+ * than with `syntax.ts`'s `flattenErrors`, which would bring the compiler in
5014
+ * with this module.
5015
+ */
5016
+
5017
+ function messagesOf(error) {
5018
+ return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
5019
+ }
5020
+
4981
5021
  /**
4982
5022
  * Which of the site's pending changes a merge of a proposal moves into
4983
5023
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5083,6 +5123,18 @@ const textEncoder$2 = new TextEncoder();
5083
5123
  const PlanRefusedBody = z.z.object({
5084
5124
  error: internal.PlanRefusalError
5085
5125
  });
5126
+
5127
+ /** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
5128
+ const PatchFileBody = z.z.object({
5129
+ moduleFilePath: z.z.string().regex(/^\/.+\.val\.(ts|js)$/),
5130
+ patch: internal.Patch,
5131
+ message: z.z.string().max(500).optional()
5132
+ });
5133
+
5134
+ /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5135
+ const ProposalFilesRead = z.z.object({
5136
+ files: z.z.record(z.z.string(), z.z.string().nullable())
5137
+ });
5086
5138
  const PatchId = z.z.string().refine(s => !!s); // TODO: validate
5087
5139
  const CommitSha = z.z.string().refine(s => !!s); // TODO: validate
5088
5140
  z.z.string().refine(s => !!s); // TODO: validate
@@ -5859,17 +5911,22 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5859
5911
  /**
5860
5912
  * The writes the SITE's server may make to a proposal's files: what the
5861
5913
  * design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
5862
- * code and build it. The tab is served by the site's
5914
+ * code, build it, and report its typecheck. The tab is served by the site's
5863
5915
  * build so that a build the assistant breaks in the proposal cannot take
5864
5916
  * down the tools it would fix it with; at the proposal's address those
5865
5917
  * tools run on the proposal's own code.
5866
5918
  *
5919
+ * The typecheck too, though it blocks the proposal's Publish (adept.md,
5920
+ * decision 20): it is the proposal's staged files checked against the
5921
+ * site's, the same program from either address, and the content service
5922
+ * keeps it only for the inputs it was made from. Without it the tab's
5923
+ * Types check, and the assistant's `typecheck`, had nothing to show.
5924
+ *
5867
5925
  * The rest stay the proposal's own: Update from the site and the lockfile
5868
- * are answered from the proposal's build and schemas, bringing back a
5869
- * point's code is the Studio at its address finishing a restore, and the
5870
- * typecheck it reports is what blocks its Publish (adept.md, decision 20).
5926
+ * are answered from the proposal's build and schemas, and bringing back a
5927
+ * point's code is the Studio at its address finishing a restore.
5871
5928
  */
5872
- static SITE_MAY_WRITE = new Set(["files", "build"]);
5929
+ static SITE_MAY_WRITE = new Set(["files", "build", "typecheck"]);
5873
5930
 
5874
5931
  /**
5875
5932
  * Whether this server may make a write to a proposal's files: the
@@ -5906,13 +5963,17 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5906
5963
  return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
5907
5964
  }
5908
5965
  async proposalsApi(path, init, profileId) {
5909
- var _exec, _exec2, _exec3, _exec4;
5966
+ var _exec, _exec2, _exec3, _exec4, _exec5;
5910
5967
  const json = "application/json";
5911
5968
  const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
5912
5969
  if (updating !== undefined && init.method === "POST") {
5913
5970
  return this.updateContentFromSite(updating, init.body, profileId);
5914
5971
  }
5915
- const withCode = (_exec2 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5972
+ const patching = (_exec2 = /^\/([0-9a-f]{20})\/patch-file$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5973
+ if (patching !== undefined && init.method === "POST") {
5974
+ return this.patchFileInProposal(patching, init.body, profileId);
5975
+ }
5976
+ const withCode = (_exec3 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5916
5977
  if (withCode !== undefined && init.method === "POST") {
5917
5978
  return this.updateCodeFromSite(withCode, init.body, profileId);
5918
5979
  }
@@ -5922,11 +5983,11 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5922
5983
  * build's schemas (step 8.2). Anywhere else they go to content as they
5923
5984
  * are, and the site's pending changes block as they always did.
5924
5985
  */
5925
- const checking = (_exec3 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5986
+ const checking = (_exec4 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5926
5987
  if (checking !== undefined && init.method === "GET" && (await this.answersMovesFor(checking, profileId))) {
5927
5988
  return this.mergeChecksWithMoves(checking, profileId);
5928
5989
  }
5929
- const pressing = (_exec4 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5990
+ const pressing = (_exec5 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec5 === void 0 ? void 0 : _exec5[1];
5930
5991
  if (pressing !== undefined && init.method === "POST" && (await this.answersMovesFor(pressing, profileId))) {
5931
5992
  return this.pressMergeWithMoves(pressing, init.body, profileId);
5932
5993
  }
@@ -5976,6 +6037,121 @@ class ValOpsHttp extends ValRouterCore.ValOps {
5976
6037
  };
5977
6038
  }
5978
6039
 
6040
+ /**
6041
+ * A patch written into a module's FILE in a proposal, and staged there as
6042
+ * code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
6043
+ * The assistant there changes the proposal's code, so content it writes goes
6044
+ * with that code -- a field it just added is filled in the same change, and
6045
+ * built and rendered with it -- rather than into the proposal's saves, which
6046
+ * the site's server does not write.
6047
+ *
6048
+ * Answered here, at `POST /<name>/patch-file`: the file is the proposal's
6049
+ * copy if it has one, otherwise the one this build was made from, and the
6050
+ * patch is written into it as a save writes one (`patchModuleText`). Who may
6051
+ * is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
6052
+ */
6053
+ async patchFileInProposal(name, body, profileId) {
6054
+ var _this$projectSource, _this$options;
6055
+ const json = "application/json";
6056
+ const answer = (status, value) => ({
6057
+ status,
6058
+ contentType: json,
6059
+ body: JSON.stringify(value)
6060
+ });
6061
+ if (!this.mayWriteFiles({
6062
+ name,
6063
+ write: "files"
6064
+ })) {
6065
+ return answer(403, {
6066
+ message: "Files are changed in the proposal this Studio is open in, not in another."
6067
+ });
6068
+ }
6069
+ let parsedBody;
6070
+ try {
6071
+ parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
6072
+ } catch {
6073
+ return answer(400, {
6074
+ message: "The patch's body is not JSON."
6075
+ });
6076
+ }
6077
+ const request = PatchFileBody.safeParse(parsedBody);
6078
+ if (!request.success) {
6079
+ return answer(400, {
6080
+ message: `Invalid patch: ${zodValidationError.fromError(request.error).toString()}`
6081
+ });
6082
+ }
6083
+ const {
6084
+ moduleFilePath,
6085
+ patch,
6086
+ message
6087
+ } = request.data;
6088
+ const content = this.proposalContent(name, profileId);
6089
+ const read = await content("/files");
6090
+ if (!read.ok) {
6091
+ return {
6092
+ status: read.status,
6093
+ contentType: json,
6094
+ body: await read.text()
6095
+ };
6096
+ }
6097
+ const files = ProposalFilesRead.safeParse(await read.json());
6098
+ if (!files.success) {
6099
+ return answer(502, {
6100
+ message: `Content answered the proposal's files in a shape this Val does not read: ${zodValidationError.fromError(files.error).toString()}`
6101
+ });
6102
+ }
6103
+ const filePath = moduleFilePath.replace(/^\/+/, "");
6104
+ const own = files.data.files[filePath];
6105
+ if (own === null) {
6106
+ return answer(409, {
6107
+ message: `${moduleFilePath} is deleted in this proposal.`
6108
+ });
6109
+ }
6110
+ if (own === undefined && this.projectSource === null) {
6111
+ return answer(409, {
6112
+ message: `This build does not carry its source, so ${moduleFilePath} can only be patched once the proposal has its own copy: write it with write_files.`
6113
+ });
6114
+ }
6115
+ const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
6116
+ if (text === undefined) {
6117
+ return answer(404, {
6118
+ message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
6119
+ });
6120
+ }
6121
+ const patched = await patchModuleText(text, patch);
6122
+ if (fp.result.isErr(patched)) {
6123
+ return answer(422, {
6124
+ message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
6125
+ });
6126
+ }
6127
+ let formatted = patched.value;
6128
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
6129
+ try {
6130
+ formatted = await this.options.formatter(patched.value, moduleFilePath);
6131
+ } catch (error) {
6132
+ return answer(422, {
6133
+ message: `The patched ${moduleFilePath} could not be formatted: ${error instanceof Error ? error.message : String(error)}`
6134
+ });
6135
+ }
6136
+ }
6137
+ const staged = await content("/files", {
6138
+ method: "POST",
6139
+ body: JSON.stringify({
6140
+ files: {
6141
+ [filePath]: formatted
6142
+ },
6143
+ ...(message !== undefined ? {
6144
+ message
6145
+ } : {})
6146
+ })
6147
+ });
6148
+ return {
6149
+ status: staged.status,
6150
+ contentType: staged.headers.get("Content-Type") ?? json,
6151
+ body: await staged.text()
6152
+ };
6153
+ }
6154
+
5979
6155
  /**
5980
6156
  * Update from the site, for a proposal that changes only content
5981
6157
  * (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
@@ -10,8 +10,8 @@ import path from 'path';
10
10
  import fs from 'fs';
11
11
  import vm from 'node:vm';
12
12
  import { Module } from 'node:module';
13
- import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, V as ValOps, b as bufferFromDataUrl, g as getFieldsForType, u as uploadRemoteFile, d as getFileExt, e as guessMimeTypeFromPath, h as createMetadataFromBuffer, j as ValOpsMemory, k as isHlsMasterPlaylist, s as sumHlsSegmentDurations, p as parseHlsMasterVariants, l as largestHlsVariant, m as fallbackRefOf, n as mapHlsUris, o as movedRemoteHost, q as needsHostCheck, t as rewriteRefHost, w as fallbackRemoteHost, x as checkRemoteFiles, y as ValServer, z as createValRequestHandler, A as getNewJsonEntryPaths, B as formatPatchSourceError } from './ValRouterCore-b3c6a562.esm.js';
14
- export { I as InMemoryPatchStore, j as ValOpsMemory, C as askOncePerHost, c as classifyJsonValuesOp, B as formatPatchSourceError, d as getFileExt, D as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-b3c6a562.esm.js';
13
+ import { r as resolveExistingJsonPath, f as findNestedJsonValuesRecords, v as validateJsonValuesEntries, i as isJsonValuesRootOp, a as rebaseContentOp, c as classifyJsonValuesOp, V as ValOps, b as bufferFromDataUrl, g as getFieldsForType, u as uploadRemoteFile, d as getFileExt, e as guessMimeTypeFromPath, h as createMetadataFromBuffer, j as ValOpsMemory, k as isHlsMasterPlaylist, s as sumHlsSegmentDurations, p as parseHlsMasterVariants, l as largestHlsVariant, m as fallbackRefOf, n as mapHlsUris, o as movedRemoteHost, q as needsHostCheck, t as rewriteRefHost, w as fallbackRemoteHost, x as checkRemoteFiles, y as ValServer, z as createValRequestHandler, A as getNewJsonEntryPaths, B as formatPatchSourceError } from './ValRouterCore-2f7ad9b9.esm.js';
14
+ export { I as InMemoryPatchStore, j as ValOpsMemory, C as askOncePerHost, c as classifyJsonValuesOp, B as formatPatchSourceError, d as getFileExt, D as getSettings, a as rebaseContentOp, u as uploadRemoteFile } from './ValRouterCore-2f7ad9b9.esm.js';
15
15
  import { createUIRequestHandler } from '@valbuild/ui/server';
16
16
  import z$1, { z } from 'zod';
17
17
  import { fromError } from 'zod-validation-error';
@@ -4942,6 +4942,46 @@ function sameJson(a, b) {
4942
4942
  return JSON.stringify(a) === JSON.stringify(b);
4943
4943
  }
4944
4944
 
4945
+ /**
4946
+ * A module's file with a patch written into it: what a save does to a
4947
+ * `.val.ts`, for one file and one patch, with nothing pending around it.
4948
+ *
4949
+ * The design tab's `create_patch` (valbuild/home `docs/design-tab.md`): there
4950
+ * the assistant changes a proposal's code, and content it writes goes into the
4951
+ * module's file and is staged with the code -- so a field it just added can
4952
+ * be filled in the same change, and is built and rendered with it.
4953
+ *
4954
+ * Only the module's own file. A `.jsonValues()` entry lives in a `*.val.json`
4955
+ * of its own, which a save routes to op by op (`ValOps.prepare`); a patch that
4956
+ * reaches into one fails here, and the message says to write that file.
4957
+ */
4958
+ async function patchModuleText(text, patch) {
4959
+ // The TypeScript compiler, loaded when a patch asks for it, as a save loads
4960
+ // it: see `publishKit.ts`.
4961
+ const {
4962
+ tsOps,
4963
+ parseValFile
4964
+ } = await import('./publishKit-bc8df53d.esm.js');
4965
+ const applied = applyPatch(parseValFile(text), tsOps, patch);
4966
+ if (result.isErr(applied)) {
4967
+ const reason = messagesOf(applied.error).join(" ");
4968
+ return result.err(text.includes(".jsonValues(") ? `${reason} This module keeps entries in .val.json files of their own: change an entry by writing its file with write_files.` : reason);
4969
+ }
4970
+ const sourceFile = applied.value;
4971
+ // As a save writes it: https://github.com/microsoft/TypeScript/issues/36174
4972
+ return result.ok(unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u")));
4973
+ }
4974
+
4975
+ /**
4976
+ * A patch error, or a tree of syntax errors, as sentences. Walked here rather
4977
+ * than with `syntax.ts`'s `flattenErrors`, which would bring the compiler in
4978
+ * with this module.
4979
+ */
4980
+
4981
+ function messagesOf(error) {
4982
+ return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
4983
+ }
4984
+
4945
4985
  /**
4946
4986
  * Which of the site's pending changes a merge of a proposal moves into
4947
4987
  * proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
@@ -5047,6 +5087,18 @@ const textEncoder$2 = new TextEncoder();
5047
5087
  const PlanRefusedBody = z.object({
5048
5088
  error: PlanRefusalError
5049
5089
  });
5090
+
5091
+ /** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
5092
+ const PatchFileBody = z.object({
5093
+ moduleFilePath: z.string().regex(/^\/.+\.val\.(ts|js)$/),
5094
+ patch: Patch,
5095
+ message: z.string().max(500).optional()
5096
+ });
5097
+
5098
+ /** What `patchFileInProposal` reads of content's answer for a proposal's files. */
5099
+ const ProposalFilesRead = z.object({
5100
+ files: z.record(z.string(), z.string().nullable())
5101
+ });
5050
5102
  const PatchId = z.string().refine(s => !!s); // TODO: validate
5051
5103
  const CommitSha = z.string().refine(s => !!s); // TODO: validate
5052
5104
  z.string().refine(s => !!s); // TODO: validate
@@ -5823,17 +5875,22 @@ class ValOpsHttp extends ValOps {
5823
5875
  /**
5824
5876
  * The writes the SITE's server may make to a proposal's files: what the
5825
5877
  * design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
5826
- * code and build it. The tab is served by the site's
5878
+ * code, build it, and report its typecheck. The tab is served by the site's
5827
5879
  * build so that a build the assistant breaks in the proposal cannot take
5828
5880
  * down the tools it would fix it with; at the proposal's address those
5829
5881
  * tools run on the proposal's own code.
5830
5882
  *
5883
+ * The typecheck too, though it blocks the proposal's Publish (adept.md,
5884
+ * decision 20): it is the proposal's staged files checked against the
5885
+ * site's, the same program from either address, and the content service
5886
+ * keeps it only for the inputs it was made from. Without it the tab's
5887
+ * Types check, and the assistant's `typecheck`, had nothing to show.
5888
+ *
5831
5889
  * The rest stay the proposal's own: Update from the site and the lockfile
5832
- * are answered from the proposal's build and schemas, bringing back a
5833
- * point's code is the Studio at its address finishing a restore, and the
5834
- * typecheck it reports is what blocks its Publish (adept.md, decision 20).
5890
+ * are answered from the proposal's build and schemas, and bringing back a
5891
+ * point's code is the Studio at its address finishing a restore.
5835
5892
  */
5836
- static SITE_MAY_WRITE = new Set(["files", "build"]);
5893
+ static SITE_MAY_WRITE = new Set(["files", "build", "typecheck"]);
5837
5894
 
5838
5895
  /**
5839
5896
  * Whether this server may make a write to a proposal's files: the
@@ -5870,13 +5927,17 @@ class ValOpsHttp extends ValOps {
5870
5927
  return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
5871
5928
  }
5872
5929
  async proposalsApi(path, init, profileId) {
5873
- var _exec, _exec2, _exec3, _exec4;
5930
+ var _exec, _exec2, _exec3, _exec4, _exec5;
5874
5931
  const json = "application/json";
5875
5932
  const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
5876
5933
  if (updating !== undefined && init.method === "POST") {
5877
5934
  return this.updateContentFromSite(updating, init.body, profileId);
5878
5935
  }
5879
- const withCode = (_exec2 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5936
+ const patching = (_exec2 = /^\/([0-9a-f]{20})\/patch-file$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
5937
+ if (patching !== undefined && init.method === "POST") {
5938
+ return this.patchFileInProposal(patching, init.body, profileId);
5939
+ }
5940
+ const withCode = (_exec3 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5880
5941
  if (withCode !== undefined && init.method === "POST") {
5881
5942
  return this.updateCodeFromSite(withCode, init.body, profileId);
5882
5943
  }
@@ -5886,11 +5947,11 @@ class ValOpsHttp extends ValOps {
5886
5947
  * build's schemas (step 8.2). Anywhere else they go to content as they
5887
5948
  * are, and the site's pending changes block as they always did.
5888
5949
  */
5889
- const checking = (_exec3 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
5950
+ const checking = (_exec4 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5890
5951
  if (checking !== undefined && init.method === "GET" && (await this.answersMovesFor(checking, profileId))) {
5891
5952
  return this.mergeChecksWithMoves(checking, profileId);
5892
5953
  }
5893
- const pressing = (_exec4 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
5954
+ const pressing = (_exec5 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec5 === void 0 ? void 0 : _exec5[1];
5894
5955
  if (pressing !== undefined && init.method === "POST" && (await this.answersMovesFor(pressing, profileId))) {
5895
5956
  return this.pressMergeWithMoves(pressing, init.body, profileId);
5896
5957
  }
@@ -5940,6 +6001,121 @@ class ValOpsHttp extends ValOps {
5940
6001
  };
5941
6002
  }
5942
6003
 
6004
+ /**
6005
+ * A patch written into a module's FILE in a proposal, and staged there as
6006
+ * code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
6007
+ * The assistant there changes the proposal's code, so content it writes goes
6008
+ * with that code -- a field it just added is filled in the same change, and
6009
+ * built and rendered with it -- rather than into the proposal's saves, which
6010
+ * the site's server does not write.
6011
+ *
6012
+ * Answered here, at `POST /<name>/patch-file`: the file is the proposal's
6013
+ * copy if it has one, otherwise the one this build was made from, and the
6014
+ * patch is written into it as a save writes one (`patchModuleText`). Who may
6015
+ * is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
6016
+ */
6017
+ async patchFileInProposal(name, body, profileId) {
6018
+ var _this$projectSource, _this$options;
6019
+ const json = "application/json";
6020
+ const answer = (status, value) => ({
6021
+ status,
6022
+ contentType: json,
6023
+ body: JSON.stringify(value)
6024
+ });
6025
+ if (!this.mayWriteFiles({
6026
+ name,
6027
+ write: "files"
6028
+ })) {
6029
+ return answer(403, {
6030
+ message: "Files are changed in the proposal this Studio is open in, not in another."
6031
+ });
6032
+ }
6033
+ let parsedBody;
6034
+ try {
6035
+ parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
6036
+ } catch {
6037
+ return answer(400, {
6038
+ message: "The patch's body is not JSON."
6039
+ });
6040
+ }
6041
+ const request = PatchFileBody.safeParse(parsedBody);
6042
+ if (!request.success) {
6043
+ return answer(400, {
6044
+ message: `Invalid patch: ${fromError(request.error).toString()}`
6045
+ });
6046
+ }
6047
+ const {
6048
+ moduleFilePath,
6049
+ patch,
6050
+ message
6051
+ } = request.data;
6052
+ const content = this.proposalContent(name, profileId);
6053
+ const read = await content("/files");
6054
+ if (!read.ok) {
6055
+ return {
6056
+ status: read.status,
6057
+ contentType: json,
6058
+ body: await read.text()
6059
+ };
6060
+ }
6061
+ const files = ProposalFilesRead.safeParse(await read.json());
6062
+ if (!files.success) {
6063
+ return answer(502, {
6064
+ message: `Content answered the proposal's files in a shape this Val does not read: ${fromError(files.error).toString()}`
6065
+ });
6066
+ }
6067
+ const filePath = moduleFilePath.replace(/^\/+/, "");
6068
+ const own = files.data.files[filePath];
6069
+ if (own === null) {
6070
+ return answer(409, {
6071
+ message: `${moduleFilePath} is deleted in this proposal.`
6072
+ });
6073
+ }
6074
+ if (own === undefined && this.projectSource === null) {
6075
+ return answer(409, {
6076
+ message: `This build does not carry its source, so ${moduleFilePath} can only be patched once the proposal has its own copy: write it with write_files.`
6077
+ });
6078
+ }
6079
+ const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
6080
+ if (text === undefined) {
6081
+ return answer(404, {
6082
+ message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
6083
+ });
6084
+ }
6085
+ const patched = await patchModuleText(text, patch);
6086
+ if (result.isErr(patched)) {
6087
+ return answer(422, {
6088
+ message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
6089
+ });
6090
+ }
6091
+ let formatted = patched.value;
6092
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
6093
+ try {
6094
+ formatted = await this.options.formatter(patched.value, moduleFilePath);
6095
+ } catch (error) {
6096
+ return answer(422, {
6097
+ message: `The patched ${moduleFilePath} could not be formatted: ${error instanceof Error ? error.message : String(error)}`
6098
+ });
6099
+ }
6100
+ }
6101
+ const staged = await content("/files", {
6102
+ method: "POST",
6103
+ body: JSON.stringify({
6104
+ files: {
6105
+ [filePath]: formatted
6106
+ },
6107
+ ...(message !== undefined ? {
6108
+ message
6109
+ } : {})
6110
+ })
6111
+ });
6112
+ return {
6113
+ status: staged.status,
6114
+ contentType: staged.headers.get("Content-Type") ?? json,
6115
+ body: await staged.text()
6116
+ };
6117
+ }
6118
+
5943
6119
  /**
5944
6120
  * Update from the site, for a proposal that changes only content
5945
6121
  * (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
package/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "exports": true
29
29
  },
30
- "version": "0.150.5",
30
+ "version": "0.150.9",
31
31
  "devDependencies": {
32
32
  "@prettier/sync": "^0.6.1",
33
33
  "@types/jest": "^30.0.0",
@@ -42,8 +42,8 @@
42
42
  "zod": "^4.4.3",
43
43
  "zod-validation-error": "^5.0.0",
44
44
  "@valbuild/core": "0.150.3",
45
- "@valbuild/shared": "0.150.3",
46
- "@valbuild/ui": "0.150.5"
45
+ "@valbuild/shared": "0.150.8",
46
+ "@valbuild/ui": "0.150.9"
47
47
  },
48
48
  "engines": {
49
49
  "node": "^20.19.0 || >=22"