@valbuild/core 0.117.0 → 0.121.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/dist/declarations/src/index.d.ts +3 -0
  3. package/dist/declarations/src/initSchema.d.ts +27 -0
  4. package/dist/declarations/src/initVal.d.ts +11 -8
  5. package/dist/declarations/src/schema/array.d.ts +2 -2
  6. package/dist/declarations/src/schema/boolean.d.ts +2 -2
  7. package/dist/declarations/src/schema/code.d.ts +2 -2
  8. package/dist/declarations/src/schema/color.d.ts +2 -2
  9. package/dist/declarations/src/schema/date.d.ts +2 -2
  10. package/dist/declarations/src/schema/datetime.d.ts +2 -2
  11. package/dist/declarations/src/schema/file.d.ts +2 -2
  12. package/dist/declarations/src/schema/image.d.ts +2 -2
  13. package/dist/declarations/src/schema/index.d.ts +12 -3
  14. package/dist/declarations/src/schema/keyOf.d.ts +2 -2
  15. package/dist/declarations/src/schema/literal.d.ts +2 -2
  16. package/dist/declarations/src/schema/number.d.ts +2 -2
  17. package/dist/declarations/src/schema/object.d.ts +2 -2
  18. package/dist/declarations/src/schema/record.d.ts +2 -2
  19. package/dist/declarations/src/schema/richtext.d.ts +3 -3
  20. package/dist/declarations/src/schema/route.d.ts +2 -2
  21. package/dist/declarations/src/schema/settings.d.ts +102 -0
  22. package/dist/declarations/src/schema/string.d.ts +2 -2
  23. package/dist/declarations/src/schema/union.d.ts +2 -2
  24. package/dist/declarations/src/selector/index.d.ts +3 -2
  25. package/dist/declarations/src/settingsModule.d.ts +60 -0
  26. package/dist/declarations/src/source/index.d.ts +2 -1
  27. package/dist/declarations/src/source/richtext.d.ts +57 -67
  28. package/dist/declarations/src/source/settings.d.ts +94 -0
  29. package/dist/{index-b8004eea.esm.js → index-5fe6fb98.esm.js} +767 -266
  30. package/dist/{index-941877c6.cjs.prod.js → index-61237991.cjs.prod.js} +772 -265
  31. package/dist/{index-0ba5047e.cjs.dev.js → index-9860179f.cjs.dev.js} +772 -265
  32. package/dist/valbuild-core.cjs.dev.js +7 -1
  33. package/dist/valbuild-core.cjs.prod.js +7 -1
  34. package/dist/valbuild-core.esm.js +1 -1
  35. package/package.json +1 -1
  36. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  37. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  38. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -0,0 +1,60 @@
1
+ import { SerializedSchema } from "./schema/index.js";
2
+ import { ModuleFilePath } from "./val/index.js";
3
+ /**
4
+ * Where a settings module goes unless a project has a reason not to.
5
+ *
6
+ * A convention, not a rule: any module file path at the root of the content
7
+ * tree may hold `s.settings()` — see {@link resolveSettingsModule}.
8
+ */
9
+ export declare const SETTINGS_MODULE_CONVENTION: ModuleFilePath;
10
+ /**
11
+ * Whether a module file path is at the root of the content tree.
12
+ *
13
+ * `/settings.val.ts` is; `/content/settings.val.ts` is not. The settings module
14
+ * is the project's, not a folder's, and a project-wide setting found three
15
+ * directories down reads as one section's — so the position is part of what it
16
+ * means.
17
+ */
18
+ export declare function isRootModuleFilePath(moduleFilePath: string): boolean;
19
+ export type ResolvedSettingsModule = {
20
+ /**
21
+ * The project's settings module, if it has exactly one valid one.
22
+ *
23
+ * `null` both when there is no settings module and when what there is cannot
24
+ * be used (nested, or ambiguous). A caller that reads settings therefore does
25
+ * not have to consider the broken cases: it gets nothing, and the errors are
26
+ * reported by whoever is in a position to report them.
27
+ */
28
+ moduleFilePath: ModuleFilePath | null;
29
+ /**
30
+ * What is wrong with how settings are declared, ready to print.
31
+ *
32
+ * Empty in the ordinary cases — one settings module, or none. Reported as
33
+ * MODULE errors, each attributed to the file it is about: extraction appends
34
+ * them, which is what puts them in front of the reader in all three places at
35
+ * once — the dev server refuses to serve sources with a module error,
36
+ * `val validate` reports them against the file, and the Studio shows them.
37
+ *
38
+ * A duplicate produces one error per offending module, each naming all of
39
+ * them, so the message is there whichever of the files you happen to open.
40
+ */
41
+ errors: SettingsModuleError[];
42
+ };
43
+ /**
44
+ * Structurally an `ExtractedModuleError`, declared here rather than imported to
45
+ * keep `extractValModules` -> `settingsModule` a one-way dependency.
46
+ */
47
+ export type SettingsModuleError = {
48
+ message: string;
49
+ path: ModuleFilePath;
50
+ };
51
+ /**
52
+ * Find the project's settings module among all its schemas.
53
+ *
54
+ * One per project, at the root: a settings module in a subdirectory is an
55
+ * error, and so is a second one. Both are reported rather than resolved by
56
+ * picking a winner — a project with two settings modules has a question to
57
+ * answer, and answering it by sort order means the answer changes when a file
58
+ * is renamed.
59
+ */
60
+ export declare function resolveSettingsModule(schemas: Record<ModuleFilePath, SerializedSchema> | Record<ModuleFilePath, SerializedSchema | undefined>): ResolvedSettingsModule;
@@ -1,7 +1,8 @@
1
1
  import { JsonSource } from "./json.js";
2
2
  import { MediaSource } from "./media.js";
3
3
  import { RichTextOptions, RichTextSource } from "./richtext.js";
4
- export type Source = SourcePrimitive | SourceObject | SourceArray | MediaSource | JsonSource | RichTextSource<RichTextOptions>;
4
+ import { SettingsSource } from "./settings.js";
5
+ export type Source = SourcePrimitive | SourceObject | SourceArray | MediaSource | JsonSource | SettingsSource | RichTextSource<RichTextOptions>;
5
6
  export type SourceObject = {
6
7
  [key in string]: Source;
7
8
  } & {
@@ -3,71 +3,60 @@ import { RouteSchema, SerializedRouteSchema } from "../schema/route.js";
3
3
  import { StringSchema, SerializedStringSchema } from "../schema/string.js";
4
4
  import { ImageSource } from "./media.js";
5
5
  export type RichTextOptions = Partial<{
6
- style: Partial<{
7
- bold: boolean;
8
- italic: boolean;
9
- lineThrough: boolean;
10
- }>;
11
- block: Partial<{
12
- h1: boolean;
13
- h2: boolean;
14
- h3: boolean;
15
- h4: boolean;
16
- h5: boolean;
17
- h6: boolean;
18
- ul: boolean;
19
- ol: boolean;
20
- }>;
21
- inline: Partial<{
22
- a: boolean | RouteSchema<string> | StringSchema<string>;
23
- img: boolean | ImageSchema<ImageSource>;
24
- }>;
6
+ bold: boolean;
7
+ italic: boolean;
8
+ lineThrough: boolean;
9
+ h1: boolean;
10
+ h2: boolean;
11
+ h3: boolean;
12
+ h4: boolean;
13
+ h5: boolean;
14
+ h6: boolean;
15
+ ul: boolean;
16
+ ol: boolean;
17
+ a: boolean | RouteSchema<string> | StringSchema<string>;
18
+ img: boolean | ImageSchema<ImageSource>;
25
19
  }>;
26
20
  export type SerializedRichTextOptions = Partial<{
27
- style: Partial<{
28
- bold: boolean;
29
- italic: boolean;
30
- lineThrough: boolean;
31
- }>;
32
- block: Partial<{
33
- h1: boolean;
34
- h2: boolean;
35
- h3: boolean;
36
- h4: boolean;
37
- h5: boolean;
38
- h6: boolean;
39
- ul: boolean;
40
- ol: boolean;
41
- }>;
42
- inline: Partial<{
43
- a: boolean | SerializedRouteSchema | SerializedStringSchema;
44
- img: boolean | SerializedImageSchema;
45
- }>;
21
+ /**
22
+ * `.maxLength()` / `.minLength()` are not authored in the options argument,
23
+ * but they serialize into the same object - so the wire type has to name
24
+ * them, or a parser that strips unknown keys drops them in transit.
25
+ */
26
+ maxLength: number;
27
+ minLength: number;
28
+ bold: boolean;
29
+ italic: boolean;
30
+ lineThrough: boolean;
31
+ h1: boolean;
32
+ h2: boolean;
33
+ h3: boolean;
34
+ h4: boolean;
35
+ h5: boolean;
36
+ h6: boolean;
37
+ ul: boolean;
38
+ ol: boolean;
39
+ a: boolean | SerializedRouteSchema | SerializedStringSchema;
40
+ img: boolean | SerializedImageSchema;
46
41
  }>;
47
42
  export type AllRichTextOptions = {
48
- style: {
49
- bold: true;
50
- italic: true;
51
- lineThrough: true;
52
- };
53
- block: {
54
- h1: true;
55
- h2: true;
56
- h3: true;
57
- h4: true;
58
- h5: true;
59
- h6: true;
60
- ul: true;
61
- ol: true;
62
- };
63
- inline: {
64
- a: true;
65
- img: true;
66
- };
43
+ bold: true;
44
+ italic: true;
45
+ lineThrough: true;
46
+ h1: true;
47
+ h2: true;
48
+ h3: true;
49
+ h4: true;
50
+ h5: true;
51
+ h6: true;
52
+ ul: true;
53
+ ol: true;
54
+ a: true;
55
+ img: true;
67
56
  };
68
- export type LineThrough<O extends RichTextOptions> = NonNullable<O["style"]>["lineThrough"] extends true ? "line-through" : never;
69
- export type Italic<O extends RichTextOptions> = NonNullable<O["style"]>["italic"] extends true ? "italic" : never;
70
- export type Bold<O extends RichTextOptions> = NonNullable<O["style"]>["bold"] extends true ? "bold" : never;
57
+ export type LineThrough<O extends RichTextOptions> = O["lineThrough"] extends true ? "line-through" : never;
58
+ export type Italic<O extends RichTextOptions> = O["italic"] extends true ? "italic" : never;
59
+ export type Bold<O extends RichTextOptions> = O["bold"] extends true ? "bold" : never;
71
60
  export type Styles<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
72
61
  export type GenericRichTextSourceNode = {
73
62
  tag: string;
@@ -88,10 +77,10 @@ export type SpanNode<O extends RichTextOptions> = {
88
77
  styles: Styles<O>[];
89
78
  children: [string];
90
79
  };
91
- export type ImageNode<O extends RichTextOptions> = NonNullable<O["inline"]>["img"] extends true ? {
80
+ export type ImageNode<O extends RichTextOptions> = O["img"] extends true ? {
92
81
  tag: "img";
93
82
  src: ImageSource;
94
- } : NonNullable<O["inline"]>["img"] extends ImageSchema<infer Src> ? Src extends ImageSource ? {
83
+ } : O["img"] extends ImageSchema<infer Src> ? Src extends ImageSource ? {
95
84
  tag: "img";
96
85
  src: Src;
97
86
  } : never : never;
@@ -100,21 +89,22 @@ type LinkTagNode<O extends RichTextOptions> = {
100
89
  href: string;
101
90
  children: (string | SpanNode<O> | ImageNode<O> | CustomInlineNode<O>)[];
102
91
  };
103
- export type LinkNode<O extends RichTextOptions> = NonNullable<O["inline"]>["a"] extends true ? LinkTagNode<O> : NonNullable<O["inline"]>["a"] extends RouteSchema<string> | StringSchema<string> ? LinkTagNode<O> : never;
92
+ export type LinkNode<O extends RichTextOptions> = O["a"] extends true ? LinkTagNode<O> : O["a"] extends RouteSchema<string> | StringSchema<string> ? LinkTagNode<O> : never;
104
93
  type ListItemTagNode<O extends RichTextOptions> = {
105
94
  tag: "li";
106
95
  children: (ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O>)[];
107
96
  };
108
- export type ListItemNode<O extends RichTextOptions> = NonNullable<O["block"]>["ul"] extends true ? ListItemTagNode<O> : never | NonNullable<O["block"]>["ol"] extends true ? ListItemTagNode<O> : never;
109
- export type UnorderedListNode<O extends RichTextOptions> = NonNullable<O["block"]>["ul"] extends true ? {
97
+ export type ListItemNode<O extends RichTextOptions> = O["ul"] extends true ? ListItemTagNode<O> : O["ol"] extends true ? ListItemTagNode<O> : never;
98
+ export type UnorderedListNode<O extends RichTextOptions> = O["ul"] extends true ? {
110
99
  tag: "ul";
111
100
  children: ListItemNode<O>[];
112
101
  } : never;
113
- export type OrderedListNode<O extends RichTextOptions> = NonNullable<O["block"]>["ol"] extends true ? {
102
+ export type OrderedListNode<O extends RichTextOptions> = O["ol"] extends true ? {
114
103
  tag: "ol";
115
104
  children: ListItemNode<O>[];
116
105
  } : never;
117
- export type HeadingTagOf<S extends keyof NonNullable<NonNullable<O["block"]>>, O extends RichTextOptions> = NonNullable<NonNullable<O["block"]>>[S] extends true ? {
106
+ export type HeadingTag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
107
+ export type HeadingTagOf<S extends HeadingTag, O extends RichTextOptions> = O[S] extends true ? {
118
108
  tag: S;
119
109
  children: (string | SpanNode<O> | CustomInlineNode<O> | LinkNode<O> | BrNode | ImageNode<O>)[];
120
110
  } : never;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The source of the project's settings module — `s.settings()`.
3
+ *
4
+ * **Every key is optional, at every level, and that is the whole point.** A
5
+ * settings module is written as
6
+ *
7
+ * ```typescript
8
+ * export default c.define("/settings.val.ts", s.settings(), {});
9
+ * ```
10
+ *
11
+ * and `{}` has to keep validating as sections are added to it. A project that
12
+ * never touched the assistant's settings should not have to edit its settings
13
+ * file the day `locales` or `permissions` land.
14
+ *
15
+ * That is why settings is not sugar over `s.object()`: an object schema errors
16
+ * with `Expected key 'assistant' not found in object` for any absent key (see
17
+ * `ObjectSchema.executeAssert`), and `.nullable()` permits `null`, not absence.
18
+ * `SettingsSchema` gives absent keys the meaning "unset" instead.
19
+ *
20
+ * `null` means unset too, so the editor can clear a field it has already
21
+ * written without removing the key.
22
+ */
23
+ export type SettingsSource = {
24
+ assistant?: AssistantSettingsSource;
25
+ };
26
+ /**
27
+ * The assistant: whether editors have one, and what it is told about the
28
+ * project on every message.
29
+ *
30
+ * `context` and `tone` are prose the model reads, not instructions Val
31
+ * interprets, and both are capped (see {@link ASSISTANT_SETTINGS_MAX_LENGTH}):
32
+ * they are prepended to every request the chat makes, so an unbounded field
33
+ * here is an unbounded cost on every turn.
34
+ */
35
+ export type AssistantSettingsSource = {
36
+ /**
37
+ * Whether editors have an assistant in this project.
38
+ *
39
+ * Three states, not two — see {@link assistantAvailability}, which is the one
40
+ * place that reads them. Unset is NOT "on": it is "nobody has decided", and
41
+ * the Studio treats that as an offer rather than as an answer.
42
+ */
43
+ enabled?: boolean | null;
44
+ /**
45
+ * Background the model would otherwise have to guess: what this site is, who
46
+ * runs it, what the product does, names and spellings that matter.
47
+ */
48
+ context?: string | null;
49
+ /**
50
+ * How the model should write when it writes content — formal or playful,
51
+ * British or American, sentence case in headings, no exclamation marks.
52
+ *
53
+ * Named `tone` rather than `toneOfVoice` so it reads as one hint among
54
+ * several inside `assistant`, leaving room for siblings (`audience`,
55
+ * `glossary`) rather than a field that looks like it should absorb them.
56
+ */
57
+ tone?: string | null;
58
+ };
59
+ /**
60
+ * The cap on each of the assistant's prose fields, in characters.
61
+ *
62
+ * Roughly a thousand tokens each. Generous enough for a paragraph of
63
+ * background and a house style, small enough that the two of them together do
64
+ * not dominate the system prompt they are appended to.
65
+ */
66
+ export declare const ASSISTANT_SETTINGS_MAX_LENGTH = 4000;
67
+ /**
68
+ * Whether a project has an assistant — and the answer is not a boolean.
69
+ *
70
+ * - `"on"`: use it.
71
+ * - `"off"`: every trace of it goes. No button in the top bar, no row in the
72
+ * quick actions, no panel, nothing sent. A project that says `false` has
73
+ * decided, and the Studio does not keep offering.
74
+ * - `"unconfigured"`: nobody has said. The affordances are SHOWN, and asking to
75
+ * use the assistant asks to turn it on first. That is the difference between
76
+ * this and `"off"`, and the reason `enabled` is a tri-state: hiding an
77
+ * unconfigured assistant means nobody discovers it, and quietly enabling one
78
+ * means a project starts sending its content to a model because it did not
79
+ * know to say no.
80
+ *
81
+ * A project with NO settings module is `"on"`. There is nowhere to record a
82
+ * decision, so there is nothing to prompt for and nothing to prompt INTO — the
83
+ * prompt writes to a settings module, and that project has none.
84
+ *
85
+ * This is the only answer to "does this project have an assistant":
86
+ * `config.ai.chat` is gone, and with it the chat's title, description and
87
+ * suggestions, which nothing replaces. The AI commit-message summariser is
88
+ * deliberately not part of this — `config.ai.commitMessages` stays where it is,
89
+ * and gets settings of its own later.
90
+ */
91
+ export type AssistantAvailability = "on" | "off" | "unconfigured";
92
+ export declare function assistantAvailability(
93
+ /** The settings module's source, or `undefined` where the project has none. */
94
+ settings: SettingsSource | undefined): AssistantAvailability;