@valbuild/shared 0.113.0 → 0.116.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.
@@ -870,36 +870,6 @@ export declare const Api: {
870
870
  }, z.core.$strip>]>;
871
871
  };
872
872
  };
873
- "/commit-summary": {
874
- GET: {
875
- req: {
876
- query: {
877
- patch_id: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
878
- };
879
- cookies: {
880
- val_session: z.ZodOptional<z.ZodString>;
881
- };
882
- };
883
- res: z.ZodUnion<readonly [z.ZodObject<{
884
- status: z.ZodLiteral<401>;
885
- json: z.ZodObject<{
886
- message: z.ZodString;
887
- }, z.core.$strip>;
888
- }, z.core.$strip>, z.ZodObject<{
889
- status: z.ZodLiteral<400>;
890
- json: z.ZodObject<{
891
- message: z.ZodString;
892
- }, z.core.$strip>;
893
- }, z.core.$strip>, z.ZodObject<{
894
- status: z.ZodLiteral<200>;
895
- json: z.ZodObject<{
896
- patchIds: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
897
- baseSha: z.ZodString;
898
- commitSummary: z.ZodNullable<z.ZodString>;
899
- }, z.core.$strip>;
900
- }, z.core.$strip>]>;
901
- };
902
- };
903
873
  "/save": {
904
874
  POST: {
905
875
  req: {
@@ -1064,6 +1034,7 @@ export declare const Api: {
1064
1034
  json: z.ZodObject<{
1065
1035
  nonce: z.ZodString;
1066
1036
  wsUrl: z.ZodString;
1037
+ providers: z.ZodOptional<z.ZodArray<z.ZodString>>;
1067
1038
  }, z.core.$strip>;
1068
1039
  }, z.core.$strip>, z.ZodObject<{
1069
1040
  status: z.ZodLiteral<500>;
@@ -0,0 +1,60 @@
1
+ import { type ImageMetadata, type SerializedSchema, type Source } from "@valbuild/core";
2
+ import { Patch } from "../zod/Patch.js";
3
+ import type { ToolName } from "./toolNames.js";
4
+ export type CombinedImageMetadata = ImageMetadata;
5
+ type GalleryArgs = {
6
+ filePath: string;
7
+ imageKey: string;
8
+ metadata: CombinedImageMetadata;
9
+ };
10
+ type RemoveGalleryArgs = {
11
+ filePath: string;
12
+ };
13
+ export type BuildResult = {
14
+ kind: "ok";
15
+ patch: Patch;
16
+ } | {
17
+ kind: "wrong-tool";
18
+ suggestedTool: ToolName;
19
+ reason: string;
20
+ } | {
21
+ kind: "error";
22
+ message: string;
23
+ };
24
+ export declare function buildFileRefValue(filePath: string, metadata: Record<string, unknown>): Record<string, unknown>;
25
+ export declare function getSourceAt(source: Source | undefined, path: string[]): Source | undefined;
26
+ export type ResolveResult = {
27
+ kind: "leaf";
28
+ schema: SerializedSchema;
29
+ } | {
30
+ kind: "richtext";
31
+ schema: SerializedSchema;
32
+ remainingPath: string[];
33
+ } | {
34
+ kind: "gallery-traversed";
35
+ schema: SerializedSchema;
36
+ } | {
37
+ kind: "unresolved";
38
+ };
39
+ /**
40
+ * Walks `schema` along `path`, returning a structured result:
41
+ * - `leaf`: walked the full path; resolved schema at the end.
42
+ * - `richtext`: hit a richtext mid-walk; richtext is the resolved schema.
43
+ * - `gallery-traversed`: hit an `s.images()` record and walked past it (i.e. the
44
+ * path tries to address an entry inside the gallery — a clue the AI should
45
+ * have used the gallery tool instead).
46
+ * - `unresolved`: the path could not be walked.
47
+ */
48
+ export declare function resolveSerializedSchemaAtPath(schema: SerializedSchema, path: string[]): ResolveResult;
49
+ export type InlineImgInfo = {
50
+ kind: "not-allowed";
51
+ } | {
52
+ kind: "allowed";
53
+ remote: boolean;
54
+ };
55
+ export declare function getInlineImgInfo(richtextSchema: SerializedSchema): InlineImgInfo;
56
+ export declare function isRemoteSchema(schema: SerializedSchema): boolean;
57
+ export declare function safeParsePatch(patch: unknown[]): BuildResult;
58
+ export declare function buildImageGalleryPatch(args: GalleryArgs, moduleSchema: SerializedSchema): BuildResult;
59
+ export declare function buildRemoveImageGalleryEntryPatch(args: RemoveGalleryArgs, moduleSchema: SerializedSchema, moduleSource: Source | undefined): BuildResult;
60
+ export {};
@@ -0,0 +1,44 @@
1
+ import type { SerializedSchema, Source } from "@valbuild/core";
2
+ import { type BuildResult } from "./aiImageToolPatches.js";
3
+ export declare function buildDuplicatePatch(args: {
4
+ sourcePath: string[];
5
+ destinationPath: string[];
6
+ }, moduleSchema: SerializedSchema, moduleSource: Source | undefined): BuildResult;
7
+ export declare function buildEmptyAtPathPatch(args: {
8
+ destinationPath: string[];
9
+ }, moduleSchema: SerializedSchema, moduleSource: Source | undefined): BuildResult;
10
+ /**
11
+ * What kind of container a path points at.
12
+ *
13
+ * `gallery` and `richtext` are called out separately from `record`/`array`
14
+ * because the two callers disagree about them: `count_entries` can count either,
15
+ * `get_record_keys` documents that it refuses both.
16
+ */
17
+ export type ContainerKind = "array" | "record" | "object" | "gallery" | "richtext";
18
+ export type DescribeContainerResult = {
19
+ kind: "ok";
20
+ container: ContainerKind;
21
+ value: Source;
22
+ } | {
23
+ kind: "error";
24
+ /**
25
+ * Whether the path is not there at all, or is there but holds something
26
+ * that has no entries.
27
+ *
28
+ * The distinction is not cosmetic: a caller that maps these onto its own
29
+ * error codes has to tell "go and look for this path" apart from "the
30
+ * path is right, its type is not", and only the second is worth a retry
31
+ * with a different tool.
32
+ */
33
+ reason: "missing" | "not-a-container";
34
+ message: string;
35
+ };
36
+ /**
37
+ * Classifies the value at `path` using the SCHEMA, not just its runtime shape.
38
+ *
39
+ * The runtime shape is not enough: an `s.image()`/`s.file()` source, a richtext
40
+ * node and a union variant are all plain objects at runtime, so classifying by
41
+ * `typeof` alone let `get_record_keys` list a file ref's `_ref`/`_type` internals
42
+ * or a richtext node's `tag`/`children` as if they were record keys.
43
+ */
44
+ export declare function describeContainerAtPath(moduleSchema: SerializedSchema, moduleSource: Source | undefined, path: string[]): DescribeContainerResult;
@@ -0,0 +1,2 @@
1
+ export declare const toolNames: readonly ["get_all_schema", "get_source", "search_content", "validate_content", "create_patch", "add_session_image_to_gallery", "remove_image_gallery_entry", "navigate_to", "get_current_context", "get_patches", "get_source_path_from_route", "set_session_name", "show_compare_view", "ask_user_question", "duplicate_source", "empty_at_path", "count_entries", "get_record_keys"];
2
+ export type ToolName = (typeof toolNames)[number];
@@ -0,0 +1,2 @@
1
+ import { SerializedSchema, Json } from "@valbuild/core";
2
+ export declare function emptyOf(schema: SerializedSchema): Json;
@@ -16,3 +16,9 @@ export * from "./resolveSchemaSourceFixes.js";
16
16
  export * from "./getErrorMessageFromUnknownJson.js";
17
17
  export * from "./zod/SerializedSchema.js";
18
18
  export * from "./valCanvasProtocol.js";
19
+ export * from "./emptyOf.js";
20
+ export * from "./aiTools/toolNames.js";
21
+ export * from "./aiTools/aiImageToolPatches.js";
22
+ export * from "./aiTools/aiSourceToolPatches.js";
23
+ export * from "./validation/partitionValidationErrors.js";
24
+ export * from "./validation/blockingValidationErrors.js";
@@ -0,0 +1,26 @@
1
+ import { type Json, type ModuleFilePath, type SerializedSchema, type SourcePath, type ValidationError } from "@valbuild/core";
2
+ /**
3
+ * The errors a user must actually act on.
4
+ *
5
+ * Two passes stand between a schema's complaint and something worth blocking a
6
+ * publish for:
7
+ *
8
+ * - `resolveSchemaSourceFixes` resolves the CROSS-MODULE fixes —
9
+ * `keyof:check-keys` and `router:check-route` — against the live schema and
10
+ * source. Unresolved, those arrive as "This error should typically be
11
+ * processed by Val internally. Seeing this error most likely means you have a
12
+ * Val version mismatch", which is not something a user can do anything with.
13
+ * - `partitionValidationErrors` drops the fixes the SERVER applies on save:
14
+ * image and file metadata, remote files, gallery directory checks. Blocking on
15
+ * those would refuse a publish for something the publish itself repairs.
16
+ *
17
+ * ## Everything that gates on validation must use this
18
+ *
19
+ * That is the whole reason it lives in `validation/` rather than beside one of
20
+ * its callers. There are three: the errors a field shows, the AI flow's check on
21
+ * a proposed patch, and — the one that bites — `system.publish`. A publish gate
22
+ * reading raw errors refuses on `router:check-route` for every route module in
23
+ * the project, which is a Save button that does nothing and says
24
+ * "validation-errors" with no error visible anywhere on screen.
25
+ */
26
+ export declare function filterBlockingValidationErrors(validationErrors: Record<SourcePath, ValidationError[]>, schemas: Record<ModuleFilePath, SerializedSchema> | null, sources: Record<ModuleFilePath, Json> | null): Record<SourcePath, ValidationError[]>;
@@ -0,0 +1,27 @@
1
+ import type { SourcePath, ValidationError } from "@valbuild/core";
2
+ /**
3
+ * Partition validation errors by whether the UI should surface them.
4
+ *
5
+ * `skipped` errors carry only fix codes the user can't (or shouldn't) act on
6
+ * in the browser:
7
+ * - image/file metadata checks (need to read bytes from disk)
8
+ * - remote upload/download/check (need a personal access token + network)
9
+ * - gallery directory uniqueness + untracked-files checks (need fs traversal)
10
+ *
11
+ * The server (ValOps + createFixPatch) resolves all of these automatically on
12
+ * save, and the CLI's `runValidation` does the same. So the user never needs
13
+ * to see them in the studio — but we keep them in the `skipped` partition,
14
+ * not dropped, so we can later surface a "N fixes pending — saving will
15
+ * repair them" badge or wire up an explicit "fix all" affordance without
16
+ * having to plumb the data back in.
17
+ *
18
+ * `keyof:check-keys` and `router:check-route` are surfaced if they reach
19
+ * this function — they're meant to be resolved upfront by the shared
20
+ * `resolveSchemaSourceFixes`. A remnant here means resolution didn't run
21
+ * for some reason; the user-facing "Invalid key/route" message is more
22
+ * useful than silent hiding.
23
+ */
24
+ export declare function partitionValidationErrors(validationErrors: Record<SourcePath, ValidationError[]>): {
25
+ surfaced: Record<SourcePath, ValidationError[]>;
26
+ skipped: Record<SourcePath, ValidationError[]>;
27
+ };