@gencode/shared 0.0.13 → 0.0.15
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/run-events.d.ts +3 -3
- package/dist/run-events.d.ts.map +1 -1
- package/dist/ui-tool.d.ts +43 -77
- package/dist/ui-tool.d.ts.map +1 -1
- package/dist/ui-tool.js +35 -96
- package/dist/ui-tool.js.map +1 -1
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export type { CollapseSpan, CompressionLayer, ContextCompactionState, ReadStateR
|
|
|
8
8
|
export { isHitlPending, isHitlResolved, isHitlExpired, isHitlTool, HITL_TOOL_NAMES, parseTextToResolution } from "./hitl.js";
|
|
9
9
|
export type { HitlKind, HitlChoice, HitlChoiceInput, HitlTextInput, HitlFormInput, HitlInputSchema, HitlPreview, HitlPolicy, HitlRequest, HitlResolution, HitlCheckpointPhase, HitlCheckpoint, HitlToolContext, HitlStatus, PausedRunState, HitlHistoryEntry, } from "./hitl.js";
|
|
10
10
|
export { validateUiToolResult } from "./ui-tool.js";
|
|
11
|
-
export type {
|
|
11
|
+
export type { UiToolExtra, UiToolJsonSchemaProperty, UiToolJsonSchemaType, UiToolOutputSchema, UiToolSchema, UiToolRequest, UiToolResult, UiToolPendingStatus, UiToolPausedState, UiToolValidationError, UiToolValidationResult, } from "./ui-tool.js";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,YAAY,EACV,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,oBAAoB,EACpB,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC7H,YAAY,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,YAAY,EACV,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,oBAAoB,EACpB,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC7H,YAAY,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,EACd,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EACV,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
|
package/dist/run-events.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentProgressEvent } from "./agent-progress.js";
|
|
2
2
|
import type { HitlKind, HitlRequest } from "./hitl.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { UiToolExtra, UiToolOutputSchema } from "./ui-tool.js";
|
|
4
4
|
export type Channel = "H5" | "WEB" | "KLPA" | "TASK" | "CRON" | "EIP_ASSISTANT" | (string & {});
|
|
5
5
|
type EventEnvelopeBase = {
|
|
6
6
|
sessionId: string;
|
|
@@ -26,8 +26,8 @@ export type RunResultPayload = {
|
|
|
26
26
|
requestId: string;
|
|
27
27
|
toolName: string;
|
|
28
28
|
toolCallId: string;
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
outputSchema: UiToolOutputSchema;
|
|
30
|
+
extra?: UiToolExtra;
|
|
31
31
|
};
|
|
32
32
|
context?: {
|
|
33
33
|
snapshotPath: string;
|
package/dist/run-events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-events.d.ts","sourceRoot":"","sources":["../src/run-events.ts"],"names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IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;CACtB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
package/dist/ui-tool.d.ts
CHANGED
|
@@ -3,126 +3,92 @@
|
|
|
3
3
|
*
|
|
4
4
|
* UI Tools are a special category of agent tools that, when invoked by the LLM,
|
|
5
5
|
* immediately pause the agent loop and request structured user input through
|
|
6
|
-
* a front-end rendered form.
|
|
7
|
-
* persist pause state to disk — the interrupt is transient and resolved within
|
|
8
|
-
* the same CLI invocation when the user submits data.
|
|
9
|
-
*
|
|
10
|
-
* Design:
|
|
11
|
-
* 1. The agent calls a registered UI tool.
|
|
12
|
-
* 2. The tool execution returns a UiToolPauseSignal (thrown as an error).
|
|
13
|
-
* 3. The runner catches the signal, emits `ui_tool_request` progress event,
|
|
14
|
-
* and ends the current run with a `uiToolPending` marker.
|
|
15
|
-
* 4. The front-end renders the form described by `UiToolSchema`.
|
|
16
|
-
* 5. On user submit, the CLI is re-invoked with the UI tool result.
|
|
17
|
-
* 6. The result is validated against the schema (or custom validator),
|
|
18
|
-
* written as a `tool_result` entry in the transcript, and the agent
|
|
19
|
-
* loop resumes.
|
|
6
|
+
* a front-end rendered form.
|
|
20
7
|
*/
|
|
21
|
-
|
|
22
|
-
export type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
export type UiToolJsonSchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
9
|
+
export type UiToolPrimitiveSchema = {
|
|
10
|
+
type?: "string" | "number" | "integer" | "boolean";
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
default?: unknown;
|
|
14
|
+
enum?: unknown[];
|
|
15
|
+
format?: string;
|
|
16
|
+
minLength?: number;
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
minimum?: number;
|
|
19
|
+
maximum?: number;
|
|
20
|
+
pattern?: string;
|
|
21
|
+
};
|
|
22
|
+
export type UiToolArraySchema = {
|
|
23
|
+
type: "array";
|
|
24
|
+
title?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
default?: unknown;
|
|
27
|
+
items?: UiToolJsonSchemaProperty;
|
|
28
|
+
minItems?: number;
|
|
29
|
+
maxItems?: number;
|
|
30
|
+
uniqueItems?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type UiToolObjectSchema = {
|
|
33
|
+
type: "object";
|
|
34
|
+
title?: string;
|
|
36
35
|
description?: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
options?: Array<{
|
|
41
|
-
value: string;
|
|
42
|
-
label: string;
|
|
43
|
-
}>;
|
|
44
|
-
/** JSON-Schema-style validation hints (e.g. minLength, pattern). */
|
|
45
|
-
validation?: Record<string, unknown>;
|
|
36
|
+
properties?: Record<string, UiToolJsonSchemaProperty>;
|
|
37
|
+
required?: string[];
|
|
38
|
+
additionalProperties?: boolean;
|
|
46
39
|
};
|
|
40
|
+
export type UiToolJsonSchemaProperty = UiToolPrimitiveSchema | UiToolArraySchema | UiToolObjectSchema;
|
|
47
41
|
/** Describes the full form that the front-end should render. */
|
|
48
|
-
export type
|
|
49
|
-
|
|
42
|
+
export type UiToolOutputSchema = {
|
|
43
|
+
type: "object";
|
|
50
44
|
title: string;
|
|
51
|
-
/** Optional longer description / instructions. */
|
|
52
45
|
description?: string;
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
properties: Record<string, UiToolJsonSchemaProperty>;
|
|
47
|
+
required?: string[];
|
|
48
|
+
additionalProperties?: boolean;
|
|
55
49
|
};
|
|
56
|
-
/**
|
|
57
|
-
export type
|
|
50
|
+
/** Backward-compatible alias for the UI form schema shape. */
|
|
51
|
+
export type UiToolSchema = UiToolOutputSchema;
|
|
52
|
+
/** Optional JSON-safe payload for custom front-end rendering hints. */
|
|
53
|
+
export type UiToolExtra = Record<string, unknown>;
|
|
58
54
|
/** Emitted as a progress event when a UI tool is invoked. */
|
|
59
55
|
export type UiToolRequest = {
|
|
60
|
-
/** Unique request identifier (UUID). */
|
|
61
56
|
requestId: string;
|
|
62
|
-
/** Session that produced this request. */
|
|
63
57
|
sessionId: string;
|
|
64
|
-
/** The tool name that triggered the UI. */
|
|
65
58
|
toolName: string;
|
|
66
|
-
/** The tool call ID from the LLM. */
|
|
67
59
|
toolCallId: string;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** Optional custom rendering payload for front-end integrations. */
|
|
71
|
-
uiExtension?: UiToolUiExtension;
|
|
72
|
-
/** ISO-8601 creation timestamp. */
|
|
60
|
+
outputSchema: UiToolOutputSchema;
|
|
61
|
+
extra?: UiToolExtra;
|
|
73
62
|
createdAt: string;
|
|
74
63
|
};
|
|
75
64
|
/** User-submitted result for a UI tool request. */
|
|
76
65
|
export type UiToolResult = {
|
|
77
|
-
/** Must match the original `UiToolRequest.requestId`. */
|
|
78
66
|
requestId: string;
|
|
79
|
-
/** Must match the original session. */
|
|
80
67
|
sessionId: string;
|
|
81
|
-
/** The tool call ID to which this result corresponds. */
|
|
82
68
|
toolCallId: string;
|
|
83
|
-
/** The tool name. */
|
|
84
69
|
toolName: string;
|
|
85
|
-
/** Submitted field values keyed by field name. */
|
|
86
70
|
values: Record<string, unknown>;
|
|
87
|
-
/** ISO-8601 submission timestamp. */
|
|
88
71
|
submittedAt: string;
|
|
89
72
|
};
|
|
90
|
-
/** Persisted status for a pending UI tool request. */
|
|
91
73
|
export type UiToolPendingStatus = "pending" | "resolved";
|
|
92
|
-
/** Persisted UI tool pause state written into the session directory. */
|
|
93
74
|
export type UiToolPausedState = {
|
|
94
|
-
/** Schema version for forward-compatibility. */
|
|
95
75
|
version: 1;
|
|
96
|
-
/** Session identifier. */
|
|
97
76
|
sessionId: string;
|
|
98
|
-
/** Original UI tool request metadata. */
|
|
99
77
|
request: UiToolRequest;
|
|
100
|
-
/** Current lifecycle status. */
|
|
101
78
|
status: UiToolPendingStatus;
|
|
102
|
-
/** Present once the user has submitted the form. */
|
|
103
79
|
result?: UiToolResult;
|
|
104
|
-
/** ISO-8601 creation timestamp. */
|
|
105
80
|
createdAt: string;
|
|
106
|
-
/** ISO-8601 last-update timestamp. */
|
|
107
81
|
updatedAt: string;
|
|
108
82
|
};
|
|
109
|
-
/** A single validation error for a specific field. */
|
|
110
83
|
export type UiToolValidationError = {
|
|
111
84
|
field: string;
|
|
112
85
|
message: string;
|
|
113
86
|
};
|
|
114
|
-
/** Result of validating a UI tool submission. */
|
|
115
87
|
export type UiToolValidationResult = {
|
|
116
88
|
valid: true;
|
|
117
89
|
} | {
|
|
118
90
|
valid: false;
|
|
119
91
|
errors: UiToolValidationError[];
|
|
120
92
|
};
|
|
121
|
-
/**
|
|
122
|
-
* Validates submitted values against a UiToolSchema using built-in rules.
|
|
123
|
-
*
|
|
124
|
-
* This performs structural validation: required-field checks, type checks,
|
|
125
|
-
* and select-option membership. Callers can layer custom validators on top.
|
|
126
|
-
*/
|
|
127
93
|
export declare function validateUiToolResult(schema: UiToolSchema, values: Record<string, unknown>): UiToolValidationResult;
|
|
128
94
|
//# sourceMappingURL=ui-tool.d.ts.map
|
package/dist/ui-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-tool.d.ts","sourceRoot":"","sources":["../src/ui-tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui-tool.d.ts","sourceRoot":"","sources":["../src/ui-tool.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,MAAM,MAAM,oBAAoB,GAC5B,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,QAAQ,CAAC;AAEb,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,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;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEzD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GACf;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,qBAAqB,EAAE,CAAA;CAAE,CAAC;AAqCtD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,sBAAsB,CAsBxB"}
|
package/dist/ui-tool.js
CHANGED
|
@@ -1,100 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Validates submitted values against a UiToolSchema using built-in rules.
|
|
23
|
-
*
|
|
24
|
-
* This performs structural validation: required-field checks, type checks,
|
|
25
|
-
* and select-option membership. Callers can layer custom validators on top.
|
|
26
|
-
*/
|
|
1
|
+
import * as Ajv from "ajv";
|
|
2
|
+
const AjvConstructor = Ajv.default;
|
|
3
|
+
const ajv = new AjvConstructor({ allErrors: true, strict: false });
|
|
4
|
+
const schemaCache = new Map();
|
|
5
|
+
function compileSchema(schema, cacheKey) {
|
|
6
|
+
const cached = schemaCache.get(cacheKey);
|
|
7
|
+
if (cached) {
|
|
8
|
+
return cached;
|
|
9
|
+
}
|
|
10
|
+
const compiled = ajv.compile(schema);
|
|
11
|
+
schemaCache.set(cacheKey, compiled);
|
|
12
|
+
return compiled;
|
|
13
|
+
}
|
|
14
|
+
function toFieldName(instancePath) {
|
|
15
|
+
if (!instancePath) {
|
|
16
|
+
return "/";
|
|
17
|
+
}
|
|
18
|
+
const segments = instancePath.split("/").filter(Boolean);
|
|
19
|
+
return segments.length === 0 ? "/" : segments[segments.length - 1] ?? "/";
|
|
20
|
+
}
|
|
27
21
|
export function validateUiToolResult(schema, values) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const isStringLike = field.type === "string" || field.type === "textarea" || field.type === "date" || field.type === "select" || field.type === "file";
|
|
34
|
-
const isMissing = value === undefined || value === null || (isStringLike && value === "");
|
|
35
|
-
if (isMissing) {
|
|
36
|
-
errors.push({ field: field.name, message: `Field "${field.label}" is required.` });
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// Skip further checks if the value is absent and not required
|
|
41
|
-
if (value === undefined || value === null) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
// Type checks
|
|
45
|
-
switch (field.type) {
|
|
46
|
-
case "string":
|
|
47
|
-
case "textarea":
|
|
48
|
-
case "date":
|
|
49
|
-
if (typeof value !== "string") {
|
|
50
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be a string.` });
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
case "number":
|
|
54
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
55
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be a number.` });
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
case "boolean":
|
|
59
|
-
if (typeof value !== "boolean") {
|
|
60
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be a boolean.` });
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case "select":
|
|
64
|
-
if (typeof value !== "string") {
|
|
65
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be a string.` });
|
|
66
|
-
}
|
|
67
|
-
else if (field.options && !field.options.some((opt) => opt.value === value)) {
|
|
68
|
-
errors.push({
|
|
69
|
-
field: field.name,
|
|
70
|
-
message: `Field "${field.label}" has an invalid option "${value}".`,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
case "multiselect":
|
|
75
|
-
if (!Array.isArray(value)) {
|
|
76
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be an array.` });
|
|
77
|
-
}
|
|
78
|
-
else if (field.options) {
|
|
79
|
-
const validValues = new Set(field.options.map((opt) => opt.value));
|
|
80
|
-
for (const item of value) {
|
|
81
|
-
if (typeof item !== "string" || !validValues.has(item)) {
|
|
82
|
-
errors.push({
|
|
83
|
-
field: field.name,
|
|
84
|
-
message: `Field "${field.label}" contains invalid option "${String(item)}".`,
|
|
85
|
-
});
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
case "file":
|
|
92
|
-
if (typeof value !== "string") {
|
|
93
|
-
errors.push({ field: field.name, message: `Field "${field.label}" must be a string (file path or data URI).` });
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
22
|
+
const cacheKey = JSON.stringify(schema);
|
|
23
|
+
const validate = compileSchema(schema, cacheKey);
|
|
24
|
+
const valid = validate(values);
|
|
25
|
+
if (valid) {
|
|
26
|
+
return { valid: true };
|
|
97
27
|
}
|
|
98
|
-
|
|
28
|
+
const errors = (validate.errors ?? []).map((error) => {
|
|
29
|
+
const field = error.keyword === "required"
|
|
30
|
+
? String(error.params.missingProperty ?? "/")
|
|
31
|
+
: toFieldName(error.instancePath);
|
|
32
|
+
return {
|
|
33
|
+
field,
|
|
34
|
+
message: error.message ?? "invalid",
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
return { valid: false, errors };
|
|
99
38
|
}
|
|
100
39
|
//# sourceMappingURL=ui-tool.js.map
|
package/dist/ui-tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-tool.js","sourceRoot":"","sources":["../src/ui-tool.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ui-tool.js","sourceRoot":"","sources":["../src/ui-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAyH3B,MAAM,cAAc,GAAG,GAAG,CAAC,OAK1B,CAAC;AAEF,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACnE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAC;AAE5D,SAAS,aAAa,CAAC,MAAoB,EAAE,QAAgB;IAC3D,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,WAAW,CAAC,YAAoB;IACvC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,GA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18,6 +18,9 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"ajv": "^8.17.1"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@types/node": "^22.0.0",
|
|
23
26
|
"@vitest/coverage-v8": "^4.0.18",
|