@positronic/core 0.0.52 → 0.0.53
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/src/dsl/{loop-messages.js → agent-messages.js} +21 -21
- package/dist/src/dsl/brain-runner.js +6 -6
- package/dist/src/dsl/brain-state-machine.js +2 -2
- package/dist/src/dsl/brain.js +5 -1912
- package/dist/src/dsl/builder/brain.js +944 -0
- package/dist/src/dsl/builder/step.js +75 -0
- package/dist/src/dsl/constants.js +9 -10
- package/dist/src/dsl/create-brain.js +63 -0
- package/dist/src/dsl/definitions/blocks.js +1 -0
- package/dist/src/dsl/definitions/brain-types.js +4 -0
- package/dist/src/dsl/definitions/events.js +2 -0
- package/dist/src/dsl/definitions/run-params.js +1 -0
- package/dist/src/dsl/definitions/steps.js +2 -0
- package/dist/src/dsl/execution/constants.js +14 -0
- package/dist/src/dsl/execution/event-stream.js +1638 -0
- package/dist/src/dsl/execution/retry.js +298 -0
- package/dist/src/dsl/types.js +2 -2
- package/dist/src/index.js +5 -3
- package/dist/src/tools/index.js +181 -0
- package/dist/src/ui/component-utils.js +107 -0
- package/dist/src/ui/generate-page-html.js +36 -0
- package/dist/src/ui/generate-ui.js +601 -0
- package/dist/src/ui/types.js +165 -0
- package/dist/src/ui/validate-form.js +428 -0
- package/dist/src/yaml/data-validator.js +302 -0
- package/dist/src/yaml/index.js +9 -0
- package/dist/src/yaml/parser.js +224 -0
- package/dist/src/yaml/schema-extractor.js +330 -0
- package/dist/src/yaml/type-inference.js +210 -0
- package/dist/src/yaml/types.js +12 -0
- package/dist/types/clients/types.d.ts +42 -0
- package/dist/types/clients/types.d.ts.map +1 -1
- package/dist/types/dsl/agent-messages.d.ts +18 -0
- package/dist/types/dsl/agent-messages.d.ts.map +1 -0
- package/dist/types/dsl/brain-runner.d.ts +2 -2
- package/dist/types/dsl/brain-runner.d.ts.map +1 -1
- package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
- package/dist/types/dsl/brain.d.ts +7 -273
- package/dist/types/dsl/brain.d.ts.map +1 -1
- package/dist/types/dsl/builder/brain.d.ts +200 -0
- package/dist/types/dsl/builder/brain.d.ts.map +1 -0
- package/dist/types/dsl/builder/step.d.ts +15 -0
- package/dist/types/dsl/builder/step.d.ts.map +1 -0
- package/dist/types/dsl/constants.d.ts +8 -9
- package/dist/types/dsl/constants.d.ts.map +1 -1
- package/dist/types/dsl/create-brain.d.ts +80 -0
- package/dist/types/dsl/create-brain.d.ts.map +1 -0
- package/dist/types/dsl/definitions/blocks.d.ts +62 -0
- package/dist/types/dsl/definitions/blocks.d.ts.map +1 -0
- package/dist/types/dsl/definitions/brain-types.d.ts +33 -0
- package/dist/types/dsl/definitions/brain-types.d.ts.map +1 -0
- package/dist/types/dsl/definitions/events.d.ts +129 -0
- package/dist/types/dsl/definitions/events.d.ts.map +1 -0
- package/dist/types/dsl/definitions/run-params.d.ts +26 -0
- package/dist/types/dsl/definitions/run-params.d.ts.map +1 -0
- package/dist/types/dsl/definitions/steps.d.ts +20 -0
- package/dist/types/dsl/definitions/steps.d.ts.map +1 -0
- package/dist/types/dsl/example-webhook.d.ts +1 -1
- package/dist/types/dsl/example-webhook.d.ts.map +1 -1
- package/dist/types/dsl/execution/constants.d.ts +16 -0
- package/dist/types/dsl/execution/constants.d.ts.map +1 -0
- package/dist/types/dsl/execution/event-stream.d.ts +44 -0
- package/dist/types/dsl/execution/event-stream.d.ts.map +1 -0
- package/dist/types/dsl/execution/retry.d.ts +30 -0
- package/dist/types/dsl/execution/retry.d.ts.map +1 -0
- package/dist/types/dsl/types.d.ts +35 -14
- package/dist/types/dsl/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tools/index.d.ts +33 -0
- package/dist/types/tools/index.d.ts.map +1 -0
- package/dist/types/ui/component-utils.d.ts +19 -0
- package/dist/types/ui/component-utils.d.ts.map +1 -0
- package/dist/types/ui/generate-page-html.d.ts +39 -0
- package/dist/types/ui/generate-page-html.d.ts.map +1 -0
- package/dist/types/ui/generate-ui.d.ts +47 -0
- package/dist/types/ui/generate-ui.d.ts.map +1 -0
- package/dist/types/ui/types.d.ts +138 -0
- package/dist/types/ui/types.d.ts.map +1 -0
- package/dist/types/ui/validate-form.d.ts +45 -0
- package/dist/types/ui/validate-form.d.ts.map +1 -0
- package/dist/types/yaml/data-validator.d.ts +35 -0
- package/dist/types/yaml/data-validator.d.ts.map +1 -0
- package/dist/types/yaml/index.d.ts +11 -0
- package/dist/types/yaml/index.d.ts.map +1 -0
- package/dist/types/yaml/parser.d.ts +20 -0
- package/dist/types/yaml/parser.d.ts.map +1 -0
- package/dist/types/yaml/schema-extractor.d.ts +29 -0
- package/dist/types/yaml/schema-extractor.d.ts.map +1 -0
- package/dist/types/yaml/type-inference.d.ts +50 -0
- package/dist/types/yaml/type-inference.d.ts.map +1 -0
- package/dist/types/yaml/types.d.ts +89 -0
- package/dist/types/yaml/types.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/types/dsl/loop-messages.d.ts +0 -18
- package/dist/types/dsl/loop-messages.d.ts.map +0 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
export { Brain, brain
|
|
1
|
+
export { Brain, brain } from './dsl/brain.js';
|
|
2
2
|
export { BrainRunner } from './dsl/brain-runner.js';
|
|
3
|
+
export { createBrain } from './dsl/create-brain.js';
|
|
4
|
+
export type { CreateBrainConfig } from './dsl/create-brain.js';
|
|
3
5
|
export { STATUS, BRAIN_EVENTS } from './dsl/constants.js';
|
|
4
6
|
export type { Adapter } from './adapters/types.js';
|
|
5
|
-
export type { BrainEvent, SerializedStep, InitialRunParams, RerunParams, BrainStartEvent, BrainCompleteEvent, BrainErrorEvent, StepStatusEvent, StepStartedEvent, StepCompletedEvent, StepRetryEvent, BrainStructure,
|
|
7
|
+
export type { BrainEvent, SerializedStep, InitialRunParams, RerunParams, BrainStartEvent, BrainCompleteEvent, BrainErrorEvent, StepStatusEvent, StepStartedEvent, StepCompletedEvent, StepRetryEvent, BrainStructure, BrainConfig, GeneratedPage, } from './dsl/brain.js';
|
|
6
8
|
export type { ObjectGenerator, Message, ToolMessage } from './clients/types.js';
|
|
7
|
-
export type { State, RuntimeEnv, Secrets,
|
|
8
|
-
export {
|
|
9
|
+
export type { State, RuntimeEnv, Secrets, AgentTool, AgentConfig, AgentMessage, AgentToolWaitFor, ExtractTerminalInput, RetryConfig, } from './dsl/types.js';
|
|
10
|
+
export { applyPatches } from './dsl/json-patch.js';
|
|
9
11
|
export { z } from 'zod';
|
|
10
12
|
export type { ResourceLoader } from './resources/resource-loader.js';
|
|
11
13
|
export { createResources, type Resources } from './resources/resources.js';
|
|
@@ -14,9 +16,9 @@ export type { WebhookFunction, WebhookRegistration } from './dsl/webhook.js';
|
|
|
14
16
|
export type { PagesService, Page, PageCreateOptions } from './dsl/pages.js';
|
|
15
17
|
export type { Manifest as ResourceManifest, Entry as ResourceEntry, ResourceType, } from './resources/resources.js';
|
|
16
18
|
export { RESOURCE_TYPES } from './resources/resources.js';
|
|
17
|
-
export type {
|
|
18
|
-
export
|
|
19
|
-
export {
|
|
19
|
+
export type { AgentStartEvent, AgentIterationEvent, AgentToolCallEvent, AgentToolResultEvent, AgentAssistantMessageEvent, AgentCompleteEvent, AgentTokenLimitEvent, AgentWebhookEvent, WebhookResponseEvent, } from './dsl/definitions/events.js';
|
|
20
|
+
export { defaultTools, generateUI } from './tools/index.js';
|
|
21
|
+
export type { UIComponent } from './ui/types.js';
|
|
20
22
|
export { createBrainExecutionMachine, createBrainMachine, sendEvent, getDepth, isTopLevel, getCurrentStep, getBrainStack, getBrainRunId, getExecutionState, getPendingWebhooks, getError, getCompletedSteps, } from './dsl/brain-state-machine.js';
|
|
21
23
|
export type { BrainStateMachine, BrainExecutionContext, BrainStackEntry, RunningBrain, StepInfo, ExecutionState, CreateMachineOptions, } from './dsl/brain-state-machine.js';
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1D,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChF,YAAY,EACV,KAAK,EACL,UAAU,EACV,OAAO,EACP,SAAS,EACT,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAMnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,YAAY,EACV,QAAQ,IAAI,gBAAgB,EAC5B,KAAK,IAAI,aAAa,EACtB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG5D,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,oBAAoB,GACrB,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { AgentTool } from '../dsl/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default generateUI tool - gets enriched with component metadata at runtime.
|
|
5
|
+
*
|
|
6
|
+
* This tool allows the LLM to generate a UI and wait for user response.
|
|
7
|
+
* The actual component list and descriptions are injected at runtime
|
|
8
|
+
* based on the components registered with .withComponents().
|
|
9
|
+
*/
|
|
10
|
+
export declare const generateUI: AgentTool;
|
|
11
|
+
/**
|
|
12
|
+
* Default tools bundle.
|
|
13
|
+
*
|
|
14
|
+
* Use with .withTools(defaultTools) to include standard tools in your brain.
|
|
15
|
+
* Tools can be extended or overridden in individual agent steps.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { brain, defaultTools } from '@positronic/core';
|
|
20
|
+
*
|
|
21
|
+
* const myBrain = brain('my-brain')
|
|
22
|
+
* .withTools(defaultTools)
|
|
23
|
+
* .brain('agent', ({ tools }) => ({
|
|
24
|
+
* system: 'You are helpful',
|
|
25
|
+
* prompt: 'Help the user',
|
|
26
|
+
* tools // uses defaultTools
|
|
27
|
+
* }));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const defaultTools: {
|
|
31
|
+
generateUI: AgentTool<z.ZodType<any, z.ZodTypeDef, any>>;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAGnE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,SAwBxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY;;CAExB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UIComponent } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge multiple component objects into one.
|
|
4
|
+
* Later objects override earlier ones for component definitions.
|
|
5
|
+
*
|
|
6
|
+
* @param componentSets - Component objects to merge
|
|
7
|
+
* @returns A merged component object
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { components } from '@positronic/gen-ui-components';
|
|
12
|
+
* import { myComponents } from './my-components';
|
|
13
|
+
*
|
|
14
|
+
* const merged = mergeComponents(components, myComponents);
|
|
15
|
+
* brain.withComponents(merged);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeComponents(...componentSets: Record<string, UIComponent<any>>[]): Record<string, UIComponent<any>>;
|
|
19
|
+
//# sourceMappingURL=component-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-utils.d.ts","sourceRoot":"","sources":["../../../src/ui/component-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,GAAG,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GACnD,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAQlC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Placement } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for generating the page HTML.
|
|
4
|
+
*/
|
|
5
|
+
export interface GeneratePageHtmlOptions {
|
|
6
|
+
/** The placements array representing the component tree */
|
|
7
|
+
placements: Placement[];
|
|
8
|
+
/** The ID of the root placement */
|
|
9
|
+
rootId: string;
|
|
10
|
+
/** Data to be passed to components for data binding resolution */
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
/** Page title */
|
|
13
|
+
title?: string;
|
|
14
|
+
/** Form action URL for form submission */
|
|
15
|
+
formAction?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a complete HTML page from placements.
|
|
19
|
+
*
|
|
20
|
+
* The generated page includes:
|
|
21
|
+
* - React and ReactDOM from CDN
|
|
22
|
+
* - Tailwind CSS from CDN
|
|
23
|
+
* - Reference to component bundle at /bundle/components.js
|
|
24
|
+
* - Data and placements embedded as JSON
|
|
25
|
+
* - Bootstrap runtime that builds and renders the React tree
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const html = generatePageHtml({
|
|
30
|
+
* placements: result.placements,
|
|
31
|
+
* rootId: result.rootId,
|
|
32
|
+
* data: brainState,
|
|
33
|
+
* title: 'My Generated Page',
|
|
34
|
+
* formAction: '/api/submit',
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function generatePageHtml(options: GeneratePageHtmlOptions): string;
|
|
39
|
+
//# sourceMappingURL=generate-page-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-page-html.d.ts","sourceRoot":"","sources":["../../../src/ui/generate-page-html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,2DAA2D;IAC3D,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA8HD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAsDzE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ObjectGenerator } from '../clients/types.js';
|
|
2
|
+
import type { UIComponent, Placement, FormSchema } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Result of generateUI - contains all component placements from the agent loop.
|
|
5
|
+
*/
|
|
6
|
+
export interface GenerateUIResult {
|
|
7
|
+
placements: Placement[];
|
|
8
|
+
rootId: string | undefined;
|
|
9
|
+
yaml?: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
usage: {
|
|
12
|
+
totalTokens: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate a UI page using an LLM agent loop with YAML templates.
|
|
17
|
+
*
|
|
18
|
+
* The agent receives the user's prompt and generates a YAML template describing
|
|
19
|
+
* the component tree. The template is validated and converted to placements.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { components } from '@positronic/gen-ui-components';
|
|
24
|
+
*
|
|
25
|
+
* const result = await generateUI({
|
|
26
|
+
* client,
|
|
27
|
+
* prompt: 'Create a form to collect user name and email',
|
|
28
|
+
* components,
|
|
29
|
+
* schema: z.object({ name: z.string(), email: z.string() }),
|
|
30
|
+
* data: { user: { name: 'John' } },
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // result.placements contains the component tree as a flat array
|
|
34
|
+
* // result.rootId is the ID of the root component
|
|
35
|
+
* // result.yaml is the generated YAML template
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateUI(params: {
|
|
39
|
+
client: ObjectGenerator;
|
|
40
|
+
prompt: string;
|
|
41
|
+
components: Record<string, UIComponent<any>>;
|
|
42
|
+
schema?: FormSchema;
|
|
43
|
+
data?: Record<string, unknown>;
|
|
44
|
+
system?: string;
|
|
45
|
+
maxSteps?: number;
|
|
46
|
+
}): Promise<GenerateUIResult>;
|
|
47
|
+
//# sourceMappingURL=generate-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-ui.d.ts","sourceRoot":"","sources":["../../../src/ui/generate-ui.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0DrE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC;AAgUD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE;IACvC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqD5B"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* A placed component in the UI tree.
|
|
5
|
+
* Components are stored in a flat array with parentId references to form a tree.
|
|
6
|
+
*/
|
|
7
|
+
export interface Placement {
|
|
8
|
+
/** Unique identifier for this placement */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Component name, e.g., "Form", "Input", "Checkbox" */
|
|
11
|
+
component: string;
|
|
12
|
+
/** Props for the component, may contain binding expressions like "{{path}}" */
|
|
13
|
+
props: Record<string, unknown>;
|
|
14
|
+
/** Parent placement ID, null for root components */
|
|
15
|
+
parentId: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Represents the inferred type of a data value.
|
|
19
|
+
* Used for validating data bindings against the provided data.
|
|
20
|
+
*/
|
|
21
|
+
export type DataType = {
|
|
22
|
+
kind: 'primitive';
|
|
23
|
+
type: 'string' | 'number' | 'boolean' | 'null';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'array';
|
|
26
|
+
elementType: DataType;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'object';
|
|
29
|
+
properties: Record<string, DataType>;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'unknown';
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Infer the DataType from a sample value.
|
|
35
|
+
*/
|
|
36
|
+
export declare function inferDataType(value: unknown): DataType;
|
|
37
|
+
/**
|
|
38
|
+
* A validation error from ValidateForm.
|
|
39
|
+
*/
|
|
40
|
+
export interface ValidationError {
|
|
41
|
+
type: 'form-schema-mismatch' | 'invalid-binding' | 'unknown-component' | 'missing-prop';
|
|
42
|
+
message: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Result of validation.
|
|
47
|
+
*/
|
|
48
|
+
export interface ValidationResult {
|
|
49
|
+
valid: boolean;
|
|
50
|
+
errors: ValidationError[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extracted form field info.
|
|
54
|
+
*/
|
|
55
|
+
export interface ExtractedFormField {
|
|
56
|
+
name: string;
|
|
57
|
+
type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]';
|
|
58
|
+
insideLoop: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The extracted form schema from placements.
|
|
62
|
+
*/
|
|
63
|
+
export interface ExtractedFormSchema {
|
|
64
|
+
fields: ExtractedFormField[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A UI component that can be used by the LLM to build pages.
|
|
68
|
+
* Combines a React component with metadata for the LLM.
|
|
69
|
+
*
|
|
70
|
+
* Use the schema-first approach: define props as a Zod schema,
|
|
71
|
+
* then derive the TypeScript type with `z.infer<typeof schema>`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const InputPropsSchema = z.object({
|
|
76
|
+
* name: z.string().describe('Form field name'),
|
|
77
|
+
* label: z.string().describe('Label displayed above input'),
|
|
78
|
+
* required: z.boolean().optional().describe('Whether field is required'),
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* type InputProps = z.infer<typeof InputPropsSchema>;
|
|
82
|
+
*
|
|
83
|
+
* export const Input: UIComponent<InputProps> = {
|
|
84
|
+
* component: InputComponent,
|
|
85
|
+
* description: 'A single-line text input field.',
|
|
86
|
+
* propsSchema: InputPropsSchema,
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export interface UIComponent<TProps = unknown> {
|
|
91
|
+
/**
|
|
92
|
+
* React component for rendering this UI element.
|
|
93
|
+
*/
|
|
94
|
+
component: ComponentType<TProps>;
|
|
95
|
+
/**
|
|
96
|
+
* Description of what this component does and when to use it.
|
|
97
|
+
* This is shown to the LLM to help it choose appropriate components.
|
|
98
|
+
*/
|
|
99
|
+
description: string;
|
|
100
|
+
/**
|
|
101
|
+
* Zod schema defining the props for this component.
|
|
102
|
+
* Used to generate documentation for the LLM about available props.
|
|
103
|
+
* Use `.describe()` on each field to provide helpful descriptions.
|
|
104
|
+
*/
|
|
105
|
+
propsSchema?: z.ZodObject<z.ZodRawShape>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Form-compatible primitive types that can be collected via HTML forms.
|
|
109
|
+
* These types map directly to form inputs without LLM coercion.
|
|
110
|
+
*/
|
|
111
|
+
export type FormPrimitive = z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodEnum<[string, ...string[]]>;
|
|
112
|
+
/**
|
|
113
|
+
* A form field is either a primitive or an optional/array wrapper around a primitive.
|
|
114
|
+
*/
|
|
115
|
+
export type FormField = FormPrimitive | z.ZodOptional<FormPrimitive> | z.ZodArray<FormPrimitive>;
|
|
116
|
+
/**
|
|
117
|
+
* A form schema is a Zod object where all fields are form-compatible.
|
|
118
|
+
* This constraint ensures forms can be mechanically converted to JSON
|
|
119
|
+
* without requiring LLM interpretation of the submitted data.
|
|
120
|
+
*
|
|
121
|
+
* Supported field types:
|
|
122
|
+
* - z.string() → Input / TextArea
|
|
123
|
+
* - z.number() → Input (type="number")
|
|
124
|
+
* - z.boolean() → Checkbox
|
|
125
|
+
* - z.enum([...]) → Select / radio buttons
|
|
126
|
+
* - z.array(z.string()) → MultiTextInput
|
|
127
|
+
* - z.array(z.enum([...])) → Multi-select / checkbox group
|
|
128
|
+
* - z.optional(...) → Optional version of any above
|
|
129
|
+
*/
|
|
130
|
+
export type FormSchema = z.ZodObject<{
|
|
131
|
+
[key: string]: FormField;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Type guard to check if a schema is form-compatible at runtime.
|
|
135
|
+
* Used as a backup validation when TypeScript inference isn't sufficient.
|
|
136
|
+
*/
|
|
137
|
+
export declare function isFormSchema(schema: z.ZodSchema): schema is FormSchema;
|
|
138
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ui/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,2CAA2C;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,oDAAoD;IACpD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAMD;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,QAAQ,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAkCtD;AAMD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,sBAAsB,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,cAAc,CAAC;IACxF,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;IAChE,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,WAAW,CAAC,MAAM,GAAG,OAAO;IAC3C;;OAEG;IACH,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB,CAAC,CAAC,SAAS,GACX,CAAC,CAAC,SAAS,GACX,CAAC,CAAC,UAAU,GACZ,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,GAC5B,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,SAAS,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC,CAAC;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,MAAM,IAAI,UAAU,CAatE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Placement, ValidationResult, ExtractedFormSchema } from './types.js';
|
|
3
|
+
import type { FormSchema } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check if a value is a binding expression like "{{path}}".
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBinding(value: unknown): value is string;
|
|
8
|
+
/**
|
|
9
|
+
* Extract the path from a binding expression.
|
|
10
|
+
* "{{email.subject}}" -> "email.subject"
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractBindingPath(binding: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Validate all data bindings in placements against the provided data type.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateDataBindings(placements: Placement[], data: Record<string, unknown>): ValidationResult;
|
|
17
|
+
/**
|
|
18
|
+
* Extract form schema from placements.
|
|
19
|
+
* Finds all form input components and extracts their field info.
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractFormSchema(placements: Placement[]): ExtractedFormSchema;
|
|
22
|
+
/**
|
|
23
|
+
* Validate extracted form schema against a Zod schema.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateAgainstZod(extracted: ExtractedFormSchema, zodSchema: FormSchema): ValidationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Create the ValidateForm tool for the UI generation agent.
|
|
28
|
+
* Validates both form schema and data bindings.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createValidateFormTool(placements: Placement[], schema: FormSchema | undefined, data: Record<string, unknown>): {
|
|
31
|
+
description: string;
|
|
32
|
+
inputSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
33
|
+
execute: () => {
|
|
34
|
+
valid: boolean;
|
|
35
|
+
errors: Array<{
|
|
36
|
+
type: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}>;
|
|
39
|
+
extractedFields: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=validate-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-form.d.ts","sourceRoot":"","sources":["../../../src/ui/validate-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,SAAS,EAGT,gBAAgB,EAEhB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7C;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1D;AAwHD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,CA2BlB;AAmBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,mBAAmB,CA2C9E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,mBAAmB,EAC9B,SAAS,EAAE,UAAU,GACpB,gBAAgB,CAwBlB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;mBAQd;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,eAAe,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;EAuB5I"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data validator for YAML templates.
|
|
3
|
+
*
|
|
4
|
+
* Validates that template bindings (like {{email.subject}}) reference
|
|
5
|
+
* valid paths in the provided data structure.
|
|
6
|
+
*/
|
|
7
|
+
import type { ComponentNode, DataType, ValidationResult } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Loop context tracks variables introduced by List/Each components.
|
|
10
|
+
* Maps variable name to the element type of the array being iterated.
|
|
11
|
+
*/
|
|
12
|
+
type LoopContext = Map<string, DataType>;
|
|
13
|
+
/**
|
|
14
|
+
* Infer a DataType from a sample JavaScript value.
|
|
15
|
+
*/
|
|
16
|
+
export declare function inferDataType(value: unknown): DataType;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a binding path against a data type, considering loop context.
|
|
19
|
+
*
|
|
20
|
+
* @param path - The binding path like "email.subject" or "emails"
|
|
21
|
+
* @param rootType - The root data type
|
|
22
|
+
* @param loopContext - Map of loop variable names to their types
|
|
23
|
+
* @returns The resolved DataType or null if path is invalid
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolvePathType(path: string, rootType: DataType, loopContext: LoopContext): DataType | null;
|
|
26
|
+
/**
|
|
27
|
+
* Validate all data bindings in a component tree.
|
|
28
|
+
*
|
|
29
|
+
* @param root - The root ComponentNode
|
|
30
|
+
* @param dataType - The inferred type of the available data
|
|
31
|
+
* @returns ValidationResult with any errors found
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateDataBindings(root: ComponentNode, dataType: DataType): ValidationResult;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=data-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-validator.d.ts","sourceRoot":"","sources":["../../../src/yaml/data-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EAER,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,KAAK,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEzC;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAkCtD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,GACvB,QAAQ,GAAG,IAAI,CA+BjB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,QAAQ,GACjB,gBAAgB,CAyDlB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML-based UI generation module.
|
|
3
|
+
*
|
|
4
|
+
* Provides parsing, validation, and type inference for YAML UI templates.
|
|
5
|
+
*/
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
export { parseTemplate, stringifyTemplate } from './parser.js';
|
|
8
|
+
export { inferDataType, resolvePathType, validateDataBindings, } from './data-validator.js';
|
|
9
|
+
export { extractFormSchema, fieldsToShape, validateAgainstZod, } from './schema-extractor.js';
|
|
10
|
+
export { describeDataShape, inferTypeWithExamples } from './type-inference.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/yaml/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,aAAa,EACb,eAAe,EACf,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML parser for UI templates.
|
|
3
|
+
*
|
|
4
|
+
* Parses YAML strings into a ComponentNode AST. Uses the {{path}} syntax
|
|
5
|
+
* to detect binding expressions that will be resolved at render time.
|
|
6
|
+
*/
|
|
7
|
+
import type { Template } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Parse a YAML template string into a Template AST.
|
|
10
|
+
*
|
|
11
|
+
* @param yamlString - The YAML template to parse
|
|
12
|
+
* @returns The parsed Template with root ComponentNode
|
|
13
|
+
* @throws Error if YAML is invalid or doesn't match expected structure
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseTemplate(yamlString: string): Template;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a Template back to YAML string (for debugging).
|
|
18
|
+
*/
|
|
19
|
+
export declare function stringifyTemplate(template: Template): string;
|
|
20
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/yaml/parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAA4B,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6FrE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAS1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAoB5D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema extractor for YAML templates.
|
|
3
|
+
*
|
|
4
|
+
* Extracts the form schema that will be produced by the template's form fields.
|
|
5
|
+
* Also validates extracted schema against expected Zod schemas.
|
|
6
|
+
*/
|
|
7
|
+
import { type ZodType, type ZodTypeDef } from 'zod';
|
|
8
|
+
import type { ComponentNode, ExtractedFormSchema, FormField, FormFieldType, ValidationError } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Extract form fields from a component tree.
|
|
11
|
+
*
|
|
12
|
+
* @param root - The root ComponentNode
|
|
13
|
+
* @returns ExtractedFormSchema with all form fields found
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractFormSchema(root: ComponentNode): ExtractedFormSchema;
|
|
16
|
+
/**
|
|
17
|
+
* Convert extracted fields to a nested object shape.
|
|
18
|
+
* Handles dot notation like "user.email" -> { user: { email: ... } }
|
|
19
|
+
*/
|
|
20
|
+
export declare function fieldsToShape(fields: FormField[]): Record<string, FormFieldType | Record<string, unknown>>;
|
|
21
|
+
/**
|
|
22
|
+
* Validate an extracted schema against an expected Zod schema.
|
|
23
|
+
*
|
|
24
|
+
* @param extracted - The ExtractedFormSchema from the template
|
|
25
|
+
* @param zodSchema - The expected Zod schema (must be ZodObject)
|
|
26
|
+
* @returns Array of validation errors
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateAgainstZod(extracted: ExtractedFormSchema, zodSchema: ZodType<unknown, ZodTypeDef, unknown>): ValidationError[];
|
|
29
|
+
//# sourceMappingURL=schema-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-extractor.d.ts","sourceRoot":"","sources":["../../../src/yaml/schema-extractor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAK,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,eAAe,EAChB,MAAM,YAAY,CAAC;AAiBpB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,mBAAmB,CA4C1E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,EAAE,GAClB,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAoBzD;AAmGD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,mBAAmB,EAC9B,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,GAC/C,eAAe,EAAE,CAoDnB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type inference for generating readable data shape descriptions.
|
|
3
|
+
*
|
|
4
|
+
* Used to describe available data to the LLM in a TypeScript-like format
|
|
5
|
+
* with inline examples for better template generation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Infer a type description for a value.
|
|
9
|
+
* Returns a simple type string like "string", "number", etc.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inferTypeDescription(value: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
* Infer a type description with inline examples.
|
|
14
|
+
* Makes it easier for the LLM to understand the data shape.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The sample value to describe
|
|
17
|
+
* @param indent - Current indentation level
|
|
18
|
+
* @returns Multi-line string describing the type with examples
|
|
19
|
+
*/
|
|
20
|
+
export declare function inferTypeWithExamples(value: unknown, indent?: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Describe the shape of data in a readable TypeScript-like format.
|
|
23
|
+
* This is the main entry point for generating data descriptions for the LLM.
|
|
24
|
+
*
|
|
25
|
+
* @param data - The data object to describe
|
|
26
|
+
* @returns A multi-line string describing the data shape with examples
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const data = {
|
|
31
|
+
* emails: [
|
|
32
|
+
* { id: "1", subject: "Hello", from: "alice@example.com" }
|
|
33
|
+
* ],
|
|
34
|
+
* sessionId: "abc123"
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
* console.log(describeDataShape(data));
|
|
38
|
+
* // Output:
|
|
39
|
+
* // {
|
|
40
|
+
* // emails: Array<{
|
|
41
|
+
* // id: string // e.g., "1"
|
|
42
|
+
* // subject: string // e.g., "Hello"
|
|
43
|
+
* // from: string // e.g., "alice@example.com"
|
|
44
|
+
* // }> // 1 items
|
|
45
|
+
* // sessionId: string // e.g., "abc123"
|
|
46
|
+
* // }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function describeDataShape(data: Record<string, unknown>): string;
|
|
50
|
+
//# sourceMappingURL=type-inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-inference.d.ts","sourceRoot":"","sources":["../../../src/yaml/type-inference.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkC3D;AA+BD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAI,GAAG,MAAM,CA4DxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAEvE"}
|