llmz 0.0.10 → 0.0.12
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/chat.d.ts +17 -0
- package/dist/chunk-276Q6EWP.cjs +224 -0
- package/dist/chunk-4L6D2A6O.cjs +283 -0
- package/dist/chunk-4MNIJGK6.js +224 -0
- package/dist/chunk-7WRN4E42.js +3087 -0
- package/dist/chunk-BEPRLBPK.cjs +3123 -0
- package/dist/chunk-C6WNNTEV.cjs +212 -0
- package/dist/chunk-D3ESDRLH.js +3123 -0
- package/dist/chunk-GGWM6X2K.js +184 -0
- package/dist/chunk-GWFYZDUR.cjs +105 -0
- package/dist/chunk-HJKOSEH2.cjs +722 -0
- package/dist/chunk-IH2WQFO5.js +283 -0
- package/dist/chunk-IKSIOIIP.cjs +28 -0
- package/dist/chunk-JAGB2AOU.js +212 -0
- package/dist/chunk-JDABP4SD.cjs +161 -0
- package/dist/chunk-JGVAZO4X.cjs +152 -0
- package/dist/chunk-JKVVQN2P.js +161 -0
- package/dist/chunk-JMSZKB4T.js +105 -0
- package/dist/chunk-JQBT7UWN.js +28 -0
- package/dist/chunk-KH6JQYQA.js +796 -0
- package/dist/chunk-KMZDFWYZ.cjs +33 -0
- package/dist/chunk-ORQP26SZ.js +33 -0
- package/dist/chunk-PRVFVXT4.js +722 -0
- package/dist/chunk-SHJDRZF5.cjs +796 -0
- package/dist/chunk-SNDVQU5A.js +152 -0
- package/dist/chunk-UQOBUJIQ.cjs +3087 -0
- package/dist/chunk-ZRCU35UV.cjs +184 -0
- package/dist/citations.d.ts +63 -0
- package/dist/compiler/compiler.d.ts +28 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/plugins/async-iterator.d.ts +4 -0
- package/dist/compiler/plugins/braces-tsx.d.ts +3 -0
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +5 -0
- package/dist/compiler/plugins/line-tracking.d.ts +5 -0
- package/dist/compiler/plugins/replace-comment.d.ts +5 -0
- package/dist/compiler/plugins/return-async.d.ts +4 -0
- package/dist/compiler/plugins/track-tool-calls.d.ts +16 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +5 -0
- package/dist/component-R4WTW6DZ.cjs +18 -0
- package/dist/component-WFVDVSDK.js +18 -0
- package/dist/component.d.ts +66 -0
- package/dist/component.default.d.ts +316 -0
- package/dist/context.d.ts +176 -0
- package/dist/dual-modes-T53P72CH.js +12 -0
- package/dist/dual-modes-VLIGPIHX.cjs +12 -0
- package/dist/errors.d.ts +64 -0
- package/dist/exit-TRXEU4OU.cjs +8 -0
- package/dist/exit-YORW76T3.js +8 -0
- package/dist/exit.d.ts +26 -0
- package/dist/formatting.d.ts +5 -0
- package/dist/getter.d.ts +2 -0
- package/dist/handlers.d.ts +10 -0
- package/dist/hoist.d.ts +2 -0
- package/dist/index.cjs +921 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +921 -0
- package/dist/inspect.d.ts +6 -0
- package/dist/jsx-AEHVFB3L.js +13 -0
- package/dist/jsx-AJAXBWFE.cjs +13 -0
- package/dist/jsx.d.ts +11 -0
- package/dist/llmz-QLZBDG2Z.cjs +576 -0
- package/dist/llmz-ROOX7RYI.js +576 -0
- package/dist/llmz.d.ts +40 -0
- package/dist/objects.d.ts +24 -0
- package/dist/prompts/chat-mode/system.md.d.ts +2 -0
- package/dist/prompts/chat-mode/user.md.d.ts +2 -0
- package/dist/prompts/common.d.ts +6 -0
- package/dist/prompts/dual-modes.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +55 -0
- package/dist/prompts/worker-mode/system.md.d.ts +2 -0
- package/dist/prompts/worker-mode/user.md.d.ts +2 -0
- package/dist/result.d.ts +33 -0
- package/dist/snapshots.d.ts +69 -0
- package/dist/stack-traces.d.ts +1 -0
- package/dist/tool-N6ODRRGH.js +11 -0
- package/dist/tool-QP4MVRWI.cjs +11 -0
- package/dist/tool.d.ts +56 -0
- package/dist/transcript.d.ts +36 -0
- package/dist/truncator-DUMWEGQO.cjs +10 -0
- package/dist/truncator-IY2MXOMC.js +10 -0
- package/dist/truncator.d.ts +20 -0
- package/dist/types.d.ts +105 -0
- package/dist/typings-2CPHOFDN.cjs +10 -0
- package/dist/typings-GDMY6VY2.js +10 -0
- package/dist/typings.d.ts +5 -0
- package/dist/utils-A7WNEFTA.cjs +39 -0
- package/dist/utils-N24IHDFA.js +39 -0
- package/dist/utils.d.ts +23 -0
- package/dist/vm-2DLG7V4G.cjs +12 -0
- package/dist/vm-FLBMZUA2.js +12 -0
- package/dist/vm.d.ts +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkKMZDFWYZcjs = require('./chunk-KMZDFWYZ.cjs');
|
|
5
|
+
|
|
6
|
+
// src/component.ts
|
|
7
|
+
var _zui = require('@bpinternal/zui');
|
|
8
|
+
function assertValidComponent(component) {
|
|
9
|
+
if (!component.name) {
|
|
10
|
+
throw new Error("Component must have a name");
|
|
11
|
+
}
|
|
12
|
+
const nameRegex = /^[A-Z]{3,50}$/i;
|
|
13
|
+
if (!nameRegex.test(component.name)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Component name "${component.name}" must be 3-50 characters long and start with an uppercase letter`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (component.aliases) {
|
|
19
|
+
for (const alias of component.aliases) {
|
|
20
|
+
if (!nameRegex.test(alias)) {
|
|
21
|
+
throw new Error(`Alias "${alias}" must be 3-50 characters long and start with an uppercase letter`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!component.description) {
|
|
26
|
+
throw new Error("Component must have a description");
|
|
27
|
+
}
|
|
28
|
+
if (!component.examples || component.examples.length === 0) {
|
|
29
|
+
throw new Error("Component must have at least one example");
|
|
30
|
+
}
|
|
31
|
+
if (component.type === "default" && !component.default) {
|
|
32
|
+
throw new Error("Default component must have default props and children");
|
|
33
|
+
}
|
|
34
|
+
if (component.type === "leaf" && !component.leaf) {
|
|
35
|
+
throw new Error("Leaf component must have leaf props");
|
|
36
|
+
}
|
|
37
|
+
if (component.type === "container" && !component.container) {
|
|
38
|
+
throw new Error("Container component must have container props and children");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var getDefaultValue = (schema) => {
|
|
42
|
+
if (schema._def.defaultValue !== void 0) {
|
|
43
|
+
if (typeof schema._def.defaultValue === "function") {
|
|
44
|
+
return String(schema._def.defaultValue()).toString();
|
|
45
|
+
} else {
|
|
46
|
+
return String(schema._def.defaultValue);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "";
|
|
50
|
+
};
|
|
51
|
+
function getComponentReference(component) {
|
|
52
|
+
let doc = `### <${component.name}>
|
|
53
|
+
|
|
54
|
+
`;
|
|
55
|
+
doc += `${component.description}
|
|
56
|
+
|
|
57
|
+
`;
|
|
58
|
+
const getPropsDoc = (props) => {
|
|
59
|
+
const shape = props.shape;
|
|
60
|
+
if (Object.keys(shape).length === 0)
|
|
61
|
+
return "_No props._\n\n";
|
|
62
|
+
const zodTypeToTsType = {
|
|
63
|
+
ZodString: "string",
|
|
64
|
+
ZodNumber: "number",
|
|
65
|
+
ZodBoolean: "boolean",
|
|
66
|
+
ZodEnum: "enum",
|
|
67
|
+
ZodArray: "array",
|
|
68
|
+
ZodObject: "object",
|
|
69
|
+
ZodDate: "date",
|
|
70
|
+
ZodBigInt: "bigint",
|
|
71
|
+
ZodSymbol: "symbol",
|
|
72
|
+
ZodUndefined: "undefined",
|
|
73
|
+
ZodNull: "null",
|
|
74
|
+
ZodVoid: "void",
|
|
75
|
+
ZodNever: "never",
|
|
76
|
+
ZodUnknown: "unknown",
|
|
77
|
+
ZodAny: "any"
|
|
78
|
+
};
|
|
79
|
+
return Object.entries(shape).map(([name, schema]) => {
|
|
80
|
+
const naked = schema.naked();
|
|
81
|
+
const zodType = naked._def.typeName;
|
|
82
|
+
const defValue = getDefaultValue(schema);
|
|
83
|
+
const typings = naked instanceof _zui.z.ZodEnum ? naked._def.values.map((x) => `"${x}"`).join(" | ") : zodTypeToTsType[zodType] || zodType;
|
|
84
|
+
const required = !schema.isOptional() ? "**(required)**" : "(optional)";
|
|
85
|
+
const def = defValue ? ` _Default: \`${defValue}\`_` : "";
|
|
86
|
+
const description = schema.description || schema.naked().description || (schema == null ? void 0 : schema._def.description) || "";
|
|
87
|
+
return `- \`${name}: ${typings}\` ${required} \u2014 ${description}${def}`;
|
|
88
|
+
}).join("\n") + "\n\n";
|
|
89
|
+
};
|
|
90
|
+
const getChildrenDoc = (children) => {
|
|
91
|
+
if (children.length === 0)
|
|
92
|
+
return "_None allowed._\n\n";
|
|
93
|
+
return "Can contain:\n" + children.map((child) => `- ${child.description} \u2014 \`<${child.component.name}>\``).join("\n") + "\n\n";
|
|
94
|
+
};
|
|
95
|
+
const getExamplesDoc = (examples) => {
|
|
96
|
+
if (!examples.length)
|
|
97
|
+
return "";
|
|
98
|
+
return "**Examples:**\n\n" + examples.map((example) => `**${example.name}** \u2014 ${example.description}
|
|
99
|
+
|
|
100
|
+
\`\`\`tsx
|
|
101
|
+
${example.code.trim()}
|
|
102
|
+
\`\`\`
|
|
103
|
+
`).join("\n");
|
|
104
|
+
};
|
|
105
|
+
switch (component.type) {
|
|
106
|
+
case "leaf":
|
|
107
|
+
doc += "**Props:**\n\n";
|
|
108
|
+
doc += getPropsDoc(component.leaf.props);
|
|
109
|
+
doc += "**Children:**\n\n";
|
|
110
|
+
doc += getChildrenDoc([]);
|
|
111
|
+
doc += getExamplesDoc(component.examples);
|
|
112
|
+
break;
|
|
113
|
+
case "container":
|
|
114
|
+
doc += "**Props:**\n\n";
|
|
115
|
+
doc += getPropsDoc(component.container.props);
|
|
116
|
+
doc += "**Children:**\n\n";
|
|
117
|
+
doc += getChildrenDoc(component.container.children);
|
|
118
|
+
doc += getExamplesDoc(component.examples);
|
|
119
|
+
break;
|
|
120
|
+
case "default":
|
|
121
|
+
default:
|
|
122
|
+
doc += "**Props:**\n\n";
|
|
123
|
+
doc += getPropsDoc(component.default.props);
|
|
124
|
+
doc += "**Children:**\n\n";
|
|
125
|
+
doc += getChildrenDoc(component.default.children);
|
|
126
|
+
doc += getExamplesDoc(component.examples);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
return doc.trim();
|
|
130
|
+
}
|
|
131
|
+
var Component = class {
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
// phantom type for inference
|
|
135
|
+
constructor(definition) {
|
|
136
|
+
assertValidComponent(definition);
|
|
137
|
+
this.definition = definition;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function isComponent(rendered, component) {
|
|
141
|
+
return _chunkKMZDFWYZcjs.isJsxComponent.call(void 0, component.definition.name, rendered);
|
|
142
|
+
}
|
|
143
|
+
function isAnyComponent(message) {
|
|
144
|
+
return _chunkKMZDFWYZcjs.isAnyJsxComponent.call(void 0, message);
|
|
145
|
+
}
|
|
146
|
+
function renderToTsx(component) {
|
|
147
|
+
const props = Object.entries(component.props).map(([key, value]) => {
|
|
148
|
+
if (typeof value === "string") {
|
|
149
|
+
return `${key}="${value}"`;
|
|
150
|
+
}
|
|
151
|
+
if (typeof value === "boolean") {
|
|
152
|
+
return value ? key : "";
|
|
153
|
+
}
|
|
154
|
+
if (typeof value === "number") {
|
|
155
|
+
return `${key}={${value}}`;
|
|
156
|
+
}
|
|
157
|
+
if (value === null || value === void 0) {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
if (typeof value === "object") {
|
|
161
|
+
return `${key}={${JSON.stringify(value)}}`;
|
|
162
|
+
}
|
|
163
|
+
return `${key}={${String(value)}}`;
|
|
164
|
+
}).filter(Boolean).join(" ");
|
|
165
|
+
const children = component.children.map((child) => {
|
|
166
|
+
if (typeof child === "string") {
|
|
167
|
+
return child;
|
|
168
|
+
}
|
|
169
|
+
if (isAnyComponent(child)) {
|
|
170
|
+
return renderToTsx(child);
|
|
171
|
+
}
|
|
172
|
+
return String(child);
|
|
173
|
+
}).join("");
|
|
174
|
+
return `<${component.type}${props ? " " + props : ""}>${children}</${component.type}>`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
exports.assertValidComponent = assertValidComponent; exports.getComponentReference = getComponentReference; exports.Component = Component; exports.isComponent = isComponent; exports.isAnyComponent = isAnyComponent; exports.renderToTsx = renderToTsx;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type Citation = {
|
|
2
|
+
id: number;
|
|
3
|
+
source: any;
|
|
4
|
+
tag: string;
|
|
5
|
+
offset?: number;
|
|
6
|
+
};
|
|
7
|
+
export type CitationReplaceFn = (citation: Citation) => string;
|
|
8
|
+
/** These are all single-token symbols that are very rare in natural texts, making them suitable for usage within GPT Prompts. */
|
|
9
|
+
export declare const RARE_SYMBOLS: {
|
|
10
|
+
readonly ARROW_UP: "↑";
|
|
11
|
+
readonly CIRCLE_BULLET: "・";
|
|
12
|
+
readonly STAR_BULLET_FULL: "★";
|
|
13
|
+
readonly STAR_BULLET_EMPTY: "☆";
|
|
14
|
+
readonly ARROW_BULLET: "→";
|
|
15
|
+
readonly SQUARE_BULLET: "■";
|
|
16
|
+
readonly TRIANGLE_BULLET: "►";
|
|
17
|
+
readonly OPENING_TAG: "【";
|
|
18
|
+
readonly CLOSING_TAG: "】";
|
|
19
|
+
readonly SS: "§";
|
|
20
|
+
readonly CROSS: "†";
|
|
21
|
+
};
|
|
22
|
+
export declare class CitationsManager {
|
|
23
|
+
private _citations;
|
|
24
|
+
private _nextId;
|
|
25
|
+
/**
|
|
26
|
+
* Registers a new source and returns the created Citation.
|
|
27
|
+
* @param source An object representing the source of the citation.
|
|
28
|
+
* @returns The created Citation.
|
|
29
|
+
*/
|
|
30
|
+
registerSource(source: any): Citation;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts citations from the provided content and cleans the content of citation tags.
|
|
33
|
+
* Non-found citations are replaced with a special "Not Found" citation.
|
|
34
|
+
* @param content The string content containing citation tags.
|
|
35
|
+
* @returns An object containing the cleaned content and an array of found citations.
|
|
36
|
+
*/
|
|
37
|
+
extractCitations(content: string, replace?: CitationReplaceFn): {
|
|
38
|
+
cleaned: string;
|
|
39
|
+
citations: Citation[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Strips citation tags from the provided content.
|
|
43
|
+
* @param content The string content containing citation tags.
|
|
44
|
+
* @returns The cleaned content without citation tags.
|
|
45
|
+
*/
|
|
46
|
+
static stripCitationTags(content: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Removes citations from a deeply nested plain object and returns a new object with citations removed.
|
|
49
|
+
* @param obj The plain object to process.
|
|
50
|
+
* @returns A tuple containing the new object and an array of extracted citations with paths.
|
|
51
|
+
*/
|
|
52
|
+
removeCitationsFromObject<T>(obj: T): [T, {
|
|
53
|
+
path: string;
|
|
54
|
+
citation: Citation;
|
|
55
|
+
}[]];
|
|
56
|
+
/**
|
|
57
|
+
* Re-adds citations to the cleaned content based on their offsets.
|
|
58
|
+
* @param cleaned The cleaned string without citation tags.
|
|
59
|
+
* @param citations The array of citations with offsets.
|
|
60
|
+
* @returns The string with citation tags re-added.
|
|
61
|
+
*/
|
|
62
|
+
reAddCitations(cleaned: string, citations: Citation[]): string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type TransformOptions } from '@babel/core';
|
|
2
|
+
import { ToolCallEntry } from './plugins/track-tool-calls.js';
|
|
3
|
+
export declare const DEFAULT_TRANSFORM_OPTIONS: TransformOptions;
|
|
4
|
+
export declare const Identifiers: {
|
|
5
|
+
JSXFnIdentifier: string;
|
|
6
|
+
AsyncIterYieldFnIdentifier: string;
|
|
7
|
+
ConsoleObjIdentifier: string;
|
|
8
|
+
LineTrackingFnIdentifier: string;
|
|
9
|
+
VariableTrackingFnIdentifier: string;
|
|
10
|
+
ToolCallTrackerFnIdentifier: string;
|
|
11
|
+
ToolTrackerRetIdentifier: string;
|
|
12
|
+
CommentFnIdentifier: string;
|
|
13
|
+
};
|
|
14
|
+
export type CompiledCode = ReturnType<typeof compile>;
|
|
15
|
+
export declare function compile(code: string): {
|
|
16
|
+
code: string;
|
|
17
|
+
map: {
|
|
18
|
+
version: number;
|
|
19
|
+
sources: string[];
|
|
20
|
+
names: string[];
|
|
21
|
+
sourceRoot?: string | undefined;
|
|
22
|
+
sourcesContent?: string[] | undefined;
|
|
23
|
+
mappings: string;
|
|
24
|
+
file: string;
|
|
25
|
+
} | null | undefined;
|
|
26
|
+
variables: Set<string>;
|
|
27
|
+
toolCalls: Map<number, ToolCallEntry>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as BabelCore from '@babel/core';
|
|
2
|
+
export declare const ToolCallTrackerFnIdentifier = "__toolc__";
|
|
3
|
+
export declare const ToolTrackerRetIdentifier = "__ret__";
|
|
4
|
+
export type Assignment = {
|
|
5
|
+
type: 'single' | 'object' | 'array' | 'unsupported';
|
|
6
|
+
left: string;
|
|
7
|
+
evalFn: string;
|
|
8
|
+
};
|
|
9
|
+
export type ToolCallEntry = {
|
|
10
|
+
object: string;
|
|
11
|
+
tool: string;
|
|
12
|
+
assignment: Assignment;
|
|
13
|
+
};
|
|
14
|
+
export declare const toolCallTrackingPlugin: (calls?: Map<number, ToolCallEntry>) => ({}: {
|
|
15
|
+
types: typeof BabelCore.types;
|
|
16
|
+
}) => BabelCore.PluginObj;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkZRCU35UVcjs = require('./chunk-ZRCU35UV.cjs');
|
|
9
|
+
require('./chunk-KMZDFWYZ.cjs');
|
|
10
|
+
require('./chunk-UQOBUJIQ.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.Component = _chunkZRCU35UVcjs.Component; exports.assertValidComponent = _chunkZRCU35UVcjs.assertValidComponent; exports.getComponentReference = _chunkZRCU35UVcjs.getComponentReference; exports.isAnyComponent = _chunkZRCU35UVcjs.isAnyComponent; exports.isComponent = _chunkZRCU35UVcjs.isComponent; exports.renderToTsx = _chunkZRCU35UVcjs.renderToTsx;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
assertValidComponent,
|
|
4
|
+
getComponentReference,
|
|
5
|
+
isAnyComponent,
|
|
6
|
+
isComponent,
|
|
7
|
+
renderToTsx
|
|
8
|
+
} from "./chunk-GGWM6X2K.js";
|
|
9
|
+
import "./chunk-ORQP26SZ.js";
|
|
10
|
+
import "./chunk-7WRN4E42.js";
|
|
11
|
+
export {
|
|
12
|
+
Component,
|
|
13
|
+
assertValidComponent,
|
|
14
|
+
getComponentReference,
|
|
15
|
+
isAnyComponent,
|
|
16
|
+
isComponent,
|
|
17
|
+
renderToTsx
|
|
18
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from '@bpinternal/zui';
|
|
2
|
+
export type ExampleUsage = {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
code: string;
|
|
6
|
+
};
|
|
7
|
+
export type ComponentChild = {
|
|
8
|
+
description: string;
|
|
9
|
+
component: ComponentDefinition;
|
|
10
|
+
};
|
|
11
|
+
export declare function assertValidComponent(component: ComponentDefinition): asserts component is ComponentDefinition;
|
|
12
|
+
export declare function getComponentReference(component: ComponentDefinition): string;
|
|
13
|
+
export type DefaultComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
14
|
+
type: 'default';
|
|
15
|
+
name: string;
|
|
16
|
+
aliases: string[];
|
|
17
|
+
description: string;
|
|
18
|
+
examples: ExampleUsage[];
|
|
19
|
+
default: {
|
|
20
|
+
props: T;
|
|
21
|
+
children: Array<ComponentChild>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type LeafComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
25
|
+
type: 'leaf';
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
aliases?: string[];
|
|
29
|
+
examples: ExampleUsage[];
|
|
30
|
+
leaf: {
|
|
31
|
+
props: T;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type ContainerComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
35
|
+
type: 'container';
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
aliases?: string[];
|
|
39
|
+
examples: ExampleUsage[];
|
|
40
|
+
container: {
|
|
41
|
+
props: T;
|
|
42
|
+
children: Array<ComponentChild>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type ComponentDefinition = DefaultComponentDefinition | LeafComponentDefinition | ContainerComponentDefinition;
|
|
46
|
+
type ExtractComponentProps<T extends ComponentDefinition> = T extends LeafComponentDefinition<infer P> ? z.infer<P> : T extends ContainerComponentDefinition<infer P> ? z.infer<P> : T extends DefaultComponentDefinition<infer P> ? z.infer<P> : never;
|
|
47
|
+
export type RenderedComponent<TProps = Record<string, any>> = {
|
|
48
|
+
__jsx: true;
|
|
49
|
+
type: string;
|
|
50
|
+
children: any[];
|
|
51
|
+
props: TProps;
|
|
52
|
+
};
|
|
53
|
+
export declare class Component<T extends ComponentDefinition = ComponentDefinition> {
|
|
54
|
+
readonly definition: T;
|
|
55
|
+
readonly propsType: ExtractComponentProps<T>;
|
|
56
|
+
constructor(definition: T);
|
|
57
|
+
}
|
|
58
|
+
export declare function isComponent<T extends ComponentDefinition>(rendered: RenderedComponent<any>, component: Component<T>): rendered is RenderedComponent<ExtractComponentProps<T>>;
|
|
59
|
+
export declare function isAnyComponent(message: unknown): message is RenderedComponent;
|
|
60
|
+
/**
|
|
61
|
+
* Converts a RenderedComponent back to TSX code
|
|
62
|
+
* @param component The rendered component to convert
|
|
63
|
+
* @returns A string containing the TSX representation of the component
|
|
64
|
+
*/
|
|
65
|
+
export declare function renderToTsx(component: RenderedComponent): string;
|
|
66
|
+
export {};
|