@terreno/blocks 57.10.1
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/LICENSE +21 -0
- package/README.md +62 -0
- package/biome.jsonc +18 -0
- package/bunfig.toml +6 -0
- package/dist/asks/errors.d.ts +77 -0
- package/dist/asks/errors.js +364 -0
- package/dist/asks/files.d.ts +53 -0
- package/dist/asks/files.js +171 -0
- package/dist/asks/formValues.d.ts +32 -0
- package/dist/asks/formValues.js +229 -0
- package/dist/asks/headless.d.ts +227 -0
- package/dist/asks/headless.js +94 -0
- package/dist/asks/jsonSchema.d.ts +6 -0
- package/dist/asks/jsonSchema.js +62 -0
- package/dist/asks/limits.d.ts +58 -0
- package/dist/asks/limits.js +61 -0
- package/dist/asks/prompt.d.ts +10 -0
- package/dist/asks/prompt.js +144 -0
- package/dist/asks/schema.d.ts +826 -0
- package/dist/asks/schema.js +864 -0
- package/dist/asks/simpleCard.d.ts +85 -0
- package/dist/asks/simpleCard.js +279 -0
- package/dist/asks/validateInput.d.ts +13 -0
- package/dist/asks/validateInput.js +19 -0
- package/dist/asks/validateResponse.d.ts +13 -0
- package/dist/asks/validateResponse.js +278 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +58 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.js +106 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +111 -0
- package/dist/jsonSchema.d.ts +5 -0
- package/dist/jsonSchema.js +12 -0
- package/dist/limits.d.ts +27 -0
- package/dist/limits.js +30 -0
- package/dist/lint.d.ts +21 -0
- package/dist/lint.js +388 -0
- package/dist/parse.d.ts +16 -0
- package/dist/parse.js +95 -0
- package/dist/parsePartial.d.ts +12 -0
- package/dist/parsePartial.js +105 -0
- package/dist/prompt.d.ts +9 -0
- package/dist/prompt.js +95 -0
- package/dist/schema.d.ts +199 -0
- package/dist/schema.js +277 -0
- package/dist/validate.d.ts +17 -0
- package/dist/validate.js +331 -0
- package/package.json +60 -0
- package/schemas/pendingAsksResponse.schema.json +195 -0
- package/schemas/simpleCard.schema.json +135 -0
- package/schemas/turnRequest.schema.json +108 -0
- package/schemas/turnResponse.schema.json +204 -0
- package/scripts/writeJsonSchemas.ts +11 -0
- package/src/asks/docParity.test.ts +65 -0
- package/src/asks/errors.test.ts +250 -0
- package/src/asks/errors.ts +449 -0
- package/src/asks/files.test.ts +294 -0
- package/src/asks/files.ts +216 -0
- package/src/asks/fixtures/invalid/choice-blank-text.json +20 -0
- package/src/asks/fixtures/invalid/choice-default-not-in-options.json +13 -0
- package/src/asks/fixtures/invalid/choice-default-selects-two.json +16 -0
- package/src/asks/fixtures/invalid/choice-description-too-long.json +24 -0
- package/src/asks/fixtures/invalid/choice-duplicate-ids.json +17 -0
- package/src/asks/fixtures/invalid/choice-label-too-long.json +23 -0
- package/src/asks/fixtures/invalid/choice-many-bounds-not-whole.json +17 -0
- package/src/asks/fixtures/invalid/choice-many-bounds-out-of-range.json +17 -0
- package/src/asks/fixtures/invalid/choice-many-default-duplicate.json +17 -0
- package/src/asks/fixtures/invalid/choice-many-default-too-many.json +15 -0
- package/src/asks/fixtures/invalid/choice-many-max-above-options.json +14 -0
- package/src/asks/fixtures/invalid/choice-many-min-above-choices.json +13 -0
- package/src/asks/fixtures/invalid/choice-many-min-above-max.json +15 -0
- package/src/asks/fixtures/invalid/choice-missing-required.json +14 -0
- package/src/asks/fixtures/invalid/choice-mixed-errors.json +19 -0
- package/src/asks/fixtures/invalid/choice-not-an-object.json +5 -0
- package/src/asks/fixtures/invalid/choice-one-with-many-fields.json +19 -0
- package/src/asks/fixtures/invalid/choice-option-id-format.json +35 -0
- package/src/asks/fixtures/invalid/choice-options-not-objects.json +12 -0
- package/src/asks/fixtures/invalid/choice-other-label-too-long.json +25 -0
- package/src/asks/fixtures/invalid/choice-other-label-without-allow-other.json +14 -0
- package/src/asks/fixtures/invalid/choice-prompt-empty.json +12 -0
- package/src/asks/fixtures/invalid/choice-prompt-too-long.json +23 -0
- package/src/asks/fixtures/invalid/choice-select-unknown.json +12 -0
- package/src/asks/fixtures/invalid/choice-submit-label-too-long.json +13 -0
- package/src/asks/fixtures/invalid/choice-title-too-long.json +24 -0
- package/src/asks/fixtures/invalid/choice-too-few-options.json +9 -0
- package/src/asks/fixtures/invalid/choice-too-many-options.json +219 -0
- package/src/asks/fixtures/invalid/choice-unknown-key-option.json +15 -0
- package/src/asks/fixtures/invalid/choice-unknown-key-root.json +13 -0
- package/src/asks/fixtures/invalid/choice-wrong-types.json +16 -0
- package/src/asks/fixtures/invalid/confirm-emoji-label-too-long.json +13 -0
- package/src/asks/fixtures/invalid/confirm-label-too-long.json +14 -0
- package/src/asks/fixtures/invalid/confirm-labels-alike-after-trim.json +14 -0
- package/src/asks/fixtures/invalid/confirm-labels-alike.json +13 -0
- package/src/asks/fixtures/invalid/confirm-missing-prompt-blank-label.json +16 -0
- package/src/asks/fixtures/invalid/confirm-unknown-keys.json +23 -0
- package/src/asks/fixtures/invalid/confirm-wrong-types.json +18 -0
- package/src/asks/fixtures/invalid/files-accept-duplicate.json +13 -0
- package/src/asks/fixtures/invalid/files-accept-empty.json +13 -0
- package/src/asks/fixtures/invalid/files-accept-unknown.json +13 -0
- package/src/asks/fixtures/invalid/files-counts-out-of-range.json +19 -0
- package/src/asks/fixtures/invalid/files-min-above-max.json +15 -0
- package/src/asks/fixtures/invalid/files-missing-accept-unknown-key.json +17 -0
- package/src/asks/fixtures/invalid/form-default-bad-format.json +40 -0
- package/src/asks/fixtures/invalid/form-default-invalid-date.json +40 -0
- package/src/asks/fixtures/invalid/form-default-not-in-options.json +58 -0
- package/src/asks/fixtures/invalid/form-default-out-of-range.json +33 -0
- package/src/asks/fixtures/invalid/form-default-text-bounds.json +42 -0
- package/src/asks/fixtures/invalid/form-default-wrong-type.json +30 -0
- package/src/asks/fixtures/invalid/form-duplicate-field-ids.json +24 -0
- package/src/asks/fixtures/invalid/form-field-id-format.json +19 -0
- package/src/asks/fixtures/invalid/form-field-text-limits.json +33 -0
- package/src/asks/fixtures/invalid/form-keys-of-another-type.json +39 -0
- package/src/asks/fixtures/invalid/form-length-above-cap.json +30 -0
- package/src/asks/fixtures/invalid/form-min-above-max.json +32 -0
- package/src/asks/fixtures/invalid/form-no-fields.json +13 -0
- package/src/asks/fixtures/invalid/form-select-options.json +44 -0
- package/src/asks/fixtures/invalid/form-too-many-fields.json +59 -0
- package/src/asks/fixtures/invalid/form-unknown-field-type.json +27 -0
- package/src/asks/fixtures/invalid/markdown-bounds-out-of-range.json +18 -0
- package/src/asks/fixtures/invalid/markdown-initial-above-cap.json +13 -0
- package/src/asks/fixtures/invalid/markdown-max-above-cap.json +13 -0
- package/src/asks/fixtures/invalid/markdown-min-above-cap.json +13 -0
- package/src/asks/fixtures/invalid/markdown-min-above-max.json +14 -0
- package/src/asks/fixtures/invalid/markdown-placeholder-too-long.json +13 -0
- package/src/asks/fixtures/invalid/markdown-wrong-types-unknown-key.json +27 -0
- package/src/asks/fixtures/valid/choice-emoji-label-cut.json +32 -0
- package/src/asks/fixtures/valid/choice-labels-collide-after-cut.json +21 -0
- package/src/asks/fixtures/valid/choice-long-text-cut.json +41 -0
- package/src/asks/fixtures/valid/choice-many-default-below-min.json +24 -0
- package/src/asks/fixtures/valid/choice-many-every-choice-with-other.json +24 -0
- package/src/asks/fixtures/valid/choice-many-no-default.json +21 -0
- package/src/asks/fixtures/valid/choice-many-optional-no-buttons.json +20 -0
- package/src/asks/fixtures/valid/choice-many-options-default-label-collides.json +23 -0
- package/src/asks/fixtures/valid/choice-many-options-no-buttons.json +21 -0
- package/src/asks/fixtures/valid/choice-many-options-no-default.json +22 -0
- package/src/asks/fixtures/valid/choice-many-options-with-default.json +30 -0
- package/src/asks/fixtures/valid/choice-many-required-with-default.json +29 -0
- package/src/asks/fixtures/valid/choice-many-single-pick-or-other.json +29 -0
- package/src/asks/fixtures/valid/choice-many-toppings-with-default.json +36 -0
- package/src/asks/fixtures/valid/choice-max-limits.json +245 -0
- package/src/asks/fixtures/valid/choice-plan-with-default.json +42 -0
- package/src/asks/fixtures/valid/choice-two-options-no-decline.json +32 -0
- package/src/asks/fixtures/valid/choice-two-options.json +32 -0
- package/src/asks/fixtures/valid/confirm-allow-decline.json +40 -0
- package/src/asks/fixtures/valid/confirm-default-labels.json +36 -0
- package/src/asks/fixtures/valid/confirm-destructive-delete.json +41 -0
- package/src/asks/fixtures/valid/confirm-emoji-labels.json +38 -0
- package/src/asks/fixtures/valid/confirm-long-text-cut.json +40 -0
- package/src/asks/fixtures/valid/files-every-type.json +28 -0
- package/src/asks/fixtures/valid/files-one-csv-no-decline.json +16 -0
- package/src/asks/fixtures/valid/files-receipt-photos.json +24 -0
- package/src/asks/fixtures/valid/form-boolean-newsletter.json +30 -0
- package/src/asks/fixtures/valid/form-date-due.json +44 -0
- package/src/asks/fixtures/valid/form-datetime-meeting.json +44 -0
- package/src/asks/fixtures/valid/form-datetime-minutes-offset.json +44 -0
- package/src/asks/fixtures/valid/form-eight-fields.json +71 -0
- package/src/asks/fixtures/valid/form-email-contact.json +44 -0
- package/src/asks/fixtures/valid/form-invoice-details.json +68 -0
- package/src/asks/fixtures/valid/form-multiselect-channels.json +64 -0
- package/src/asks/fixtures/valid/form-number-budget.json +45 -0
- package/src/asks/fixtures/valid/form-phone-callback.json +44 -0
- package/src/asks/fixtures/valid/form-select-shipping.json +58 -0
- package/src/asks/fixtures/valid/form-text-required-default.json +47 -0
- package/src/asks/fixtures/valid/form-textarea-notes.json +23 -0
- package/src/asks/fixtures/valid/form-time-reminder.json +44 -0
- package/src/asks/fixtures/valid/form-url-website.json +30 -0
- package/src/asks/fixtures/valid/markdown-announcement-draft.json +39 -0
- package/src/asks/fixtures/valid/markdown-empty-draft.json +34 -0
- package/src/asks/fixtures/valid/markdown-initial-blank-below-min.json +24 -0
- package/src/asks/fixtures/valid/markdown-initial-over-max.json +24 -0
- package/src/asks/fixtures/valid/markdown-long-text-cut.json +37 -0
- package/src/asks/fixtures/valid/markdown-no-decline.json +28 -0
- package/src/asks/fixtures/valid/markdown-no-initial-with-min.json +25 -0
- package/src/asks/formValues.ts +320 -0
- package/src/asks/headless.test.ts +146 -0
- package/src/asks/headless.ts +130 -0
- package/src/asks/jsonSchema.test.ts +171 -0
- package/src/asks/jsonSchema.ts +89 -0
- package/src/asks/limits.ts +58 -0
- package/src/asks/prompt.test.ts +200 -0
- package/src/asks/prompt.ts +173 -0
- package/src/asks/schema.test.ts +198 -0
- package/src/asks/schema.ts +1203 -0
- package/src/asks/simpleCard.test.ts +998 -0
- package/src/asks/simpleCard.ts +341 -0
- package/src/asks/validateInput.test.ts +875 -0
- package/src/asks/validateInput.ts +24 -0
- package/src/asks/validateResponse.test.ts +740 -0
- package/src/asks/validateResponse.ts +341 -0
- package/src/blocksDocParity.test.ts +21 -0
- package/src/cli.test.ts +134 -0
- package/src/cli.ts +65 -0
- package/src/display.test.ts +68 -0
- package/src/errors.test.ts +29 -0
- package/src/errors.ts +125 -0
- package/src/fixtures/invalid/column-not-found.yaml +14 -0
- package/src/fixtures/invalid/column-type.yaml +14 -0
- package/src/fixtures/invalid/dataset-not-found.yaml +7 -0
- package/src/fixtures/invalid/dataset-too-large.yaml +20 -0
- package/src/fixtures/invalid/depth-exceeded.yaml +10 -0
- package/src/fixtures/invalid/duplicate-id.yaml +6 -0
- package/src/fixtures/invalid/invalid-enum.yaml +5 -0
- package/src/fixtures/invalid/key-order.yaml +4 -0
- package/src/fixtures/invalid/missing-required.yaml +3 -0
- package/src/fixtures/invalid/not-a-document.txt +1 -0
- package/src/fixtures/invalid/row-arity.yaml +11 -0
- package/src/fixtures/invalid/select-target.yaml +12 -0
- package/src/fixtures/invalid/table-too-wide.yaml +9 -0
- package/src/fixtures/invalid/too-many-points.yaml +8 -0
- package/src/fixtures/invalid/unknown-key.yaml +5 -0
- package/src/fixtures/invalid/unsupported-version.yaml +4 -0
- package/src/fixtures/invalid/yaml-anchor.yaml +6 -0
- package/src/fixtures/partial/cut-after-divider.yaml +5 -0
- package/src/fixtures/valid/actions.yaml +32 -0
- package/src/fixtures/valid/chart.yaml +20 -0
- package/src/fixtures/valid/layout.yaml +26 -0
- package/src/fixtures/valid/prose.yaml +4 -0
- package/src/html.test.ts +52 -0
- package/src/index.test.ts +114 -0
- package/src/index.ts +175 -0
- package/src/jsonSchema.test.ts +33 -0
- package/src/jsonSchema.ts +11 -0
- package/src/limits.ts +27 -0
- package/src/lint.test.ts +289 -0
- package/src/lint.ts +484 -0
- package/src/parse.test.ts +281 -0
- package/src/parse.ts +104 -0
- package/src/parsePartial.test.ts +53 -0
- package/src/parsePartial.ts +116 -0
- package/src/prompt.test.ts +24 -0
- package/src/prompt.ts +104 -0
- package/src/schema.ts +509 -0
- package/src/tests/askFixtures.ts +40 -0
- package/src/validate.perf.test.ts +43 -0
- package/src/validate.ts +369 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {readFileSync} from "node:fs";
|
|
3
|
+
import {join} from "node:path";
|
|
4
|
+
import {ASK_ERROR_CODES} from "./errors";
|
|
5
|
+
import {ASK_LIMITS} from "./limits";
|
|
6
|
+
|
|
7
|
+
const REFERENCE_PATH = join(
|
|
8
|
+
import.meta.dir,
|
|
9
|
+
"..",
|
|
10
|
+
"..",
|
|
11
|
+
"..",
|
|
12
|
+
"docs",
|
|
13
|
+
"reference",
|
|
14
|
+
"agent-ui-asks.md"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const reference = readFileSync(REFERENCE_PATH, "utf8");
|
|
18
|
+
|
|
19
|
+
const section = (heading: string): string => {
|
|
20
|
+
const start = reference.indexOf(`\n## ${heading}\n`);
|
|
21
|
+
if (start < 0) {
|
|
22
|
+
throw new Error(`docs/reference/agent-ui-asks.md has no "## ${heading}" section.`);
|
|
23
|
+
}
|
|
24
|
+
const end = reference.indexOf("\n## ", start + 1);
|
|
25
|
+
return reference.slice(start, end < 0 ? undefined : end);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tableRows = (text: string): string[][] =>
|
|
29
|
+
text
|
|
30
|
+
.split("\n")
|
|
31
|
+
.filter((line) => line.startsWith("| `"))
|
|
32
|
+
.map((line) =>
|
|
33
|
+
line
|
|
34
|
+
.slice(1, -1)
|
|
35
|
+
.split(" | ")
|
|
36
|
+
.map((cell) => cell.trim().replace(/^`|`$/g, ""))
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const flattenLimits = (value: object, prefix = ""): [string, string][] =>
|
|
40
|
+
Object.entries(value).flatMap(([key, child]): [string, string][] => {
|
|
41
|
+
const path = prefix === "" ? key : `${prefix}.${key}`;
|
|
42
|
+
if (child instanceof RegExp) {
|
|
43
|
+
return [[path, child.source]];
|
|
44
|
+
}
|
|
45
|
+
if (typeof child === "object" && child !== null) {
|
|
46
|
+
return flattenLimits(child, path);
|
|
47
|
+
}
|
|
48
|
+
return [[path, String(child)]];
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("docs/reference/agent-ui-asks.md", () => {
|
|
52
|
+
it("documents every error code with the meaning from ASK_ERROR_CODES", () => {
|
|
53
|
+
const documented = Object.fromEntries(
|
|
54
|
+
tableRows(section("Error codes")).map(([code, meaning]) => [code, meaning])
|
|
55
|
+
);
|
|
56
|
+
expect(documented).toEqual({...ASK_ERROR_CODES});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("documents every ASK_LIMITS value", () => {
|
|
60
|
+
const documented = Object.fromEntries(
|
|
61
|
+
tableRows(section("Limits")).map(([key, value]) => [key, value])
|
|
62
|
+
);
|
|
63
|
+
expect(documented).toEqual(Object.fromEntries(flattenLimits(ASK_LIMITS)));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {z} from "zod";
|
|
3
|
+
import {ASK_ERROR_CODES, type AskErrorCode, finalizeAskErrors, issuesToAskErrors} from "./errors";
|
|
4
|
+
import {checkAskFileBytes, fileNotOwnedError} from "./files";
|
|
5
|
+
import type {ChoiceAskInput, FilesAskInput, FormAskInput} from "./schema";
|
|
6
|
+
import {resolveButtonAnswer, toSimpleCard} from "./simpleCard";
|
|
7
|
+
import {validateAskInput} from "./validateInput";
|
|
8
|
+
import {validateAskResponse} from "./validateResponse";
|
|
9
|
+
|
|
10
|
+
const INPUT: ChoiceAskInput = {
|
|
11
|
+
options: [
|
|
12
|
+
{id: "red", label: "Red"},
|
|
13
|
+
{id: "blue", label: "Blue"},
|
|
14
|
+
],
|
|
15
|
+
prompt: "Pick a color.",
|
|
16
|
+
select: "one",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const inputCodes = (input: unknown): AskErrorCode[] =>
|
|
20
|
+
validateAskInput({input, kind: "choice"}).map((error) => error.code);
|
|
21
|
+
|
|
22
|
+
const responseCodes = (response: unknown, input: ChoiceAskInput = INPUT): AskErrorCode[] =>
|
|
23
|
+
validateAskResponse({input, kind: "choice", response}).map((error) => error.code);
|
|
24
|
+
|
|
25
|
+
const FORM_INPUT: FormAskInput = {
|
|
26
|
+
fields: [
|
|
27
|
+
{id: "company", label: "Company", required: true, type: "text"},
|
|
28
|
+
{id: "seats", label: "Seats", max: 500, min: 1, type: "number"},
|
|
29
|
+
{id: "start", label: "Start date", type: "date"},
|
|
30
|
+
],
|
|
31
|
+
prompt: "A few details.",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const formCodes = (values: unknown): AskErrorCode[] =>
|
|
35
|
+
validateAskResponse({
|
|
36
|
+
input: FORM_INPUT,
|
|
37
|
+
kind: "form",
|
|
38
|
+
response: {action: "accept", content: {values}},
|
|
39
|
+
}).map((error) => error.code);
|
|
40
|
+
|
|
41
|
+
const FILES_INPUT: FilesAskInput = {accept: ["image"], maxFiles: 2, prompt: "Upload the receipt."};
|
|
42
|
+
|
|
43
|
+
const PNG_BYTES = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13]);
|
|
44
|
+
|
|
45
|
+
const filesCodes = (files: unknown[]): AskErrorCode[] =>
|
|
46
|
+
validateAskResponse({
|
|
47
|
+
input: FILES_INPUT,
|
|
48
|
+
kind: "files",
|
|
49
|
+
response: {action: "accept", content: {files}},
|
|
50
|
+
}).map((error) => error.code);
|
|
51
|
+
|
|
52
|
+
const PHOTO = {fileId: "file_1", filename: "receipt.png", mimeType: "image/png", size: 12};
|
|
53
|
+
|
|
54
|
+
const mapIssues = (schema: z.ZodType, root: unknown) => {
|
|
55
|
+
const result = schema.safeParse(root);
|
|
56
|
+
if (result.success) {
|
|
57
|
+
throw new Error("Expected the schema to reject the value.");
|
|
58
|
+
}
|
|
59
|
+
return finalizeAskErrors(issuesToAskErrors({issues: result.error.issues, root}));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
describe("ASK_ERROR_CODES", () => {
|
|
63
|
+
const producers: Record<AskErrorCode, () => AskErrorCode[]> = {
|
|
64
|
+
CHANGED_MISMATCH: () =>
|
|
65
|
+
validateAskResponse({
|
|
66
|
+
input: {initial: "Draft", prompt: "Edit it."},
|
|
67
|
+
kind: "markdown",
|
|
68
|
+
response: {action: "accept", content: {changed: true, markdown: "Draft"}},
|
|
69
|
+
}).map((error) => error.code),
|
|
70
|
+
DECLINE_NOT_ALLOWED: () => responseCodes({action: "decline"}, {...INPUT, allowDecline: false}),
|
|
71
|
+
DEFAULT_NOT_IN_OPTIONS: () => inputCodes({...INPUT, default: ["green"]}),
|
|
72
|
+
DUPLICATE_ID: () =>
|
|
73
|
+
inputCodes({
|
|
74
|
+
...INPUT,
|
|
75
|
+
options: [
|
|
76
|
+
{id: "red", label: "Red"},
|
|
77
|
+
{id: "red", label: "Crimson"},
|
|
78
|
+
],
|
|
79
|
+
}),
|
|
80
|
+
DUPLICATE_LABEL: () =>
|
|
81
|
+
validateAskInput({
|
|
82
|
+
input: {
|
|
83
|
+
...INPUT,
|
|
84
|
+
options: [
|
|
85
|
+
{id: "red", label: "Red"},
|
|
86
|
+
{id: "crimson", label: "Red"},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
kind: "choice",
|
|
90
|
+
surface: "compact",
|
|
91
|
+
}).map((error) => error.code),
|
|
92
|
+
FIELD_TYPE_MISMATCH: () => formCodes({company: "Acme", seats: "12"}),
|
|
93
|
+
FILE_COUNT: () => filesCodes([PHOTO, PHOTO, PHOTO]),
|
|
94
|
+
FILE_NOT_OWNED: () => [fileNotOwnedError({index: 0}).code],
|
|
95
|
+
FILE_TOO_LARGE: () => filesCodes([{...PHOTO, size: 11 * 1024 * 1024}]),
|
|
96
|
+
FILE_TYPE_NOT_ACCEPTED: () =>
|
|
97
|
+
filesCodes([{...PHOTO, filename: "notes.txt", mimeType: "text/plain"}]),
|
|
98
|
+
INVALID_DATE: () => formCodes({company: "Acme", start: "2026-02-30"}),
|
|
99
|
+
INVALID_ENUM: () => inputCodes({...INPUT, select: "all"}),
|
|
100
|
+
INVALID_FORMAT: () =>
|
|
101
|
+
inputCodes({
|
|
102
|
+
...INPUT,
|
|
103
|
+
options: [
|
|
104
|
+
{id: "Red", label: "Red"},
|
|
105
|
+
{id: "blue", label: "Blue"},
|
|
106
|
+
],
|
|
107
|
+
}),
|
|
108
|
+
INVALID_TYPE: () => inputCodes({...INPUT, prompt: 7}),
|
|
109
|
+
MIME_MISMATCH: () =>
|
|
110
|
+
checkAskFileBytes({
|
|
111
|
+
bytes: PNG_BYTES,
|
|
112
|
+
index: 0,
|
|
113
|
+
maxFileSizeBytes: 1024,
|
|
114
|
+
mimeType: "image/jpeg",
|
|
115
|
+
}).map((error) => error.code),
|
|
116
|
+
MISSING_REQUIRED: () => inputCodes({options: INPUT.options, select: "one"}),
|
|
117
|
+
OPTION_NOT_OFFERED: () => responseCodes({action: "accept", content: {selected: ["green"]}}),
|
|
118
|
+
OTHER_NOT_ALLOWED: () =>
|
|
119
|
+
responseCodes({action: "accept", content: {other: "Green", selected: ["red"]}}),
|
|
120
|
+
OUT_OF_RANGE: () => formCodes({company: "Acme", seats: 0}),
|
|
121
|
+
RANGE_INVALID: () => inputCodes({...INPUT, maxSelected: 2, minSelected: 3, select: "many"}),
|
|
122
|
+
REQUIRED_FIELD: () => formCodes({seats: 12}),
|
|
123
|
+
SELECTION_COUNT: () => responseCodes({action: "accept", content: {selected: ["red", "blue"]}}),
|
|
124
|
+
TOO_FEW: () => inputCodes({...INPUT, options: [{id: "red", label: "Red"}]}),
|
|
125
|
+
TOO_LONG: () => inputCodes({...INPUT, title: "t".repeat(81)}),
|
|
126
|
+
TOO_MANY: () =>
|
|
127
|
+
inputCodes({
|
|
128
|
+
...INPUT,
|
|
129
|
+
options: Array.from({length: 51}, (_, index) => ({
|
|
130
|
+
id: `c${index}`,
|
|
131
|
+
label: `Color ${index}`,
|
|
132
|
+
})),
|
|
133
|
+
}),
|
|
134
|
+
TOO_SHORT: () => inputCodes({...INPUT, prompt: ""}),
|
|
135
|
+
UNKNOWN_BUTTON: () =>
|
|
136
|
+
resolveButtonAnswer({
|
|
137
|
+
buttonId: "option:green",
|
|
138
|
+
card: toSimpleCard({input: INPUT, kind: "choice", toolCallId: "call_1"}),
|
|
139
|
+
}).errors.map((error) => error.code),
|
|
140
|
+
UNKNOWN_KEY: () => inputCodes({...INPUT, color: "red"}),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
for (const code of Object.keys(ASK_ERROR_CODES) as AskErrorCode[]) {
|
|
144
|
+
it(`${code} is returned by a check`, () => {
|
|
145
|
+
expect(producers[code]()).toEqual([code]);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
it("has a producer for every code and no others", () => {
|
|
150
|
+
expect(Object.keys(producers).sort()).toEqual(Object.keys(ASK_ERROR_CODES).sort());
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("issuesToAskErrors fallbacks", () => {
|
|
155
|
+
it("reports a missing root value", () => {
|
|
156
|
+
expect(validateAskInput({input: undefined, kind: "choice"})).toEqual([
|
|
157
|
+
{
|
|
158
|
+
code: "MISSING_REQUIRED",
|
|
159
|
+
fix: "Send the value.",
|
|
160
|
+
message: "The value is required.",
|
|
161
|
+
path: "",
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("reports a missing list item by its index", () => {
|
|
167
|
+
expect(mapIssues(z.array(z.string()), [undefined])).toEqual([
|
|
168
|
+
{code: "MISSING_REQUIRED", fix: "Send [0].", message: "[0] is required.", path: "[0]"},
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("names other string formats", () => {
|
|
173
|
+
expect(mapIssues(z.object({contact: z.email()}), {contact: "not an email"})).toEqual([
|
|
174
|
+
{
|
|
175
|
+
code: "INVALID_FORMAT",
|
|
176
|
+
fix: "Change contact to match the email format.",
|
|
177
|
+
message: "contact does not match the email format.",
|
|
178
|
+
path: "contact",
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("keeps the message of a custom issue without an ask code", () => {
|
|
184
|
+
expect(
|
|
185
|
+
mapIssues(
|
|
186
|
+
z.string().refine(() => false, {message: "Nope."}),
|
|
187
|
+
"x"
|
|
188
|
+
)
|
|
189
|
+
).toEqual([{code: "INVALID_FORMAT", fix: "Check the value.", message: "Nope.", path: ""}]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("treats a union without a discriminator as a type error", () => {
|
|
193
|
+
expect(mapIssues(z.object({value: z.union([z.string(), z.number()])}), {value: true})).toEqual([
|
|
194
|
+
{
|
|
195
|
+
code: "INVALID_TYPE",
|
|
196
|
+
fix: "Check value.",
|
|
197
|
+
message: "Invalid input",
|
|
198
|
+
path: "value",
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("falls back to INVALID_TYPE for issue codes asks never produce", () => {
|
|
204
|
+
expect(mapIssues(z.object({seats: z.number().multipleOf(5)}), {seats: 7})).toEqual([
|
|
205
|
+
{
|
|
206
|
+
code: "INVALID_TYPE",
|
|
207
|
+
fix: "Check seats.",
|
|
208
|
+
message: "Invalid number: must be a multiple of 5",
|
|
209
|
+
path: "seats",
|
|
210
|
+
},
|
|
211
|
+
]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("describes other expected and received types", () => {
|
|
215
|
+
expect(
|
|
216
|
+
mapIssues(z.object({count: z.number(), day: z.date(), tags: z.string()}), {
|
|
217
|
+
count: {},
|
|
218
|
+
day: "2026-09-27",
|
|
219
|
+
tags: 10n,
|
|
220
|
+
})
|
|
221
|
+
).toEqual([
|
|
222
|
+
{
|
|
223
|
+
code: "INVALID_TYPE",
|
|
224
|
+
fix: "Make count a number.",
|
|
225
|
+
message: "count must be a number, not an object.",
|
|
226
|
+
path: "count",
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
code: "INVALID_TYPE",
|
|
230
|
+
fix: "Make day date.",
|
|
231
|
+
message: "day must be date, not a string.",
|
|
232
|
+
path: "day",
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
code: "INVALID_TYPE",
|
|
236
|
+
fix: "Make tags a string.",
|
|
237
|
+
message: "tags must be a string, not bigint.",
|
|
238
|
+
path: "tags",
|
|
239
|
+
},
|
|
240
|
+
]);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("describes booleans and null as received values", () => {
|
|
244
|
+
expect(
|
|
245
|
+
mapIssues(z.object({a: z.string(), b: z.string()}), {a: true, b: null}).map(
|
|
246
|
+
(error) => error.message
|
|
247
|
+
)
|
|
248
|
+
).toEqual(["a must be a string, not a boolean.", "b must be a string, not null."]);
|
|
249
|
+
});
|
|
250
|
+
});
|