llmz 0.0.5 → 0.0.7
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/package.json +5 -3
- package/dist/chat.d.ts +0 -17
- package/dist/chunk-3U57H7GT.js +0 -608
- package/dist/chunk-4EWY34YA.js +0 -3079
- package/dist/chunk-4I7UPBLN.cjs +0 -104
- package/dist/chunk-4QTK5ALH.cjs +0 -211
- package/dist/chunk-5NVNEEYW.cjs +0 -3079
- package/dist/chunk-5TRUJES5.js +0 -220
- package/dist/chunk-6WT5VZBG.cjs +0 -755
- package/dist/chunk-7WRN4E42.js +0 -3087
- package/dist/chunk-EJRCDWBA.cjs +0 -153
- package/dist/chunk-FIVFS4HG.cjs +0 -152
- package/dist/chunk-HP7RKM25.js +0 -153
- package/dist/chunk-HYVKY3W6.cjs +0 -283
- package/dist/chunk-IKSIOIIP.cjs +0 -28
- package/dist/chunk-JDABP4SD.cjs +0 -161
- package/dist/chunk-JKVVQN2P.js +0 -161
- package/dist/chunk-JQBT7UWN.js +0 -28
- package/dist/chunk-KMZDFWYZ.cjs +0 -33
- package/dist/chunk-MU4LFVY7.cjs +0 -608
- package/dist/chunk-ORQP26SZ.js +0 -33
- package/dist/chunk-P7J2WCBB.cjs +0 -220
- package/dist/chunk-QBXIE6EY.js +0 -211
- package/dist/chunk-QT4QF3YA.js +0 -152
- package/dist/chunk-S6FOL2HY.js +0 -104
- package/dist/chunk-UNMKB2DA.js +0 -283
- package/dist/chunk-UQOBUJIQ.cjs +0 -3087
- package/dist/chunk-WLUVY5QU.js +0 -755
- package/dist/citations.d.ts +0 -63
- package/dist/compiler/compiler.d.ts +0 -28
- package/dist/compiler/index.d.ts +0 -2
- package/dist/compiler/plugins/async-iterator.d.ts +0 -4
- package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
- package/dist/compiler/plugins/line-tracking.d.ts +0 -5
- package/dist/compiler/plugins/replace-comment.d.ts +0 -5
- package/dist/compiler/plugins/return-async.d.ts +0 -4
- package/dist/compiler/plugins/track-tool-calls.d.ts +0 -16
- package/dist/compiler/plugins/variable-extraction.d.ts +0 -5
- package/dist/component-R2Y74VUI.js +0 -16
- package/dist/component-TSNW3SC7.cjs +0 -16
- package/dist/component.d.ts +0 -60
- package/dist/component.default.d.ts +0 -316
- package/dist/context.d.ts +0 -170
- package/dist/dual-modes-UHNDHNIF.cjs +0 -12
- package/dist/dual-modes-ZUQKPJFH.js +0 -12
- package/dist/errors.d.ts +0 -64
- package/dist/exit-KJ4COC5N.cjs +0 -8
- package/dist/exit-OIYZLBVJ.js +0 -8
- package/dist/exit.d.ts +0 -26
- package/dist/formatting.d.ts +0 -5
- package/dist/getter.d.ts +0 -2
- package/dist/handlers.d.ts +0 -10
- package/dist/hoist.d.ts +0 -2
- package/dist/index.cjs +0 -907
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -907
- package/dist/inspect.d.ts +0 -6
- package/dist/jsx-AEHVFB3L.js +0 -13
- package/dist/jsx-AJAXBWFE.cjs +0 -13
- package/dist/jsx.d.ts +0 -11
- package/dist/llmz-VDA4M42R.cjs +0 -604
- package/dist/llmz-YE5N54IU.js +0 -604
- package/dist/llmz.d.ts +0 -39
- package/dist/objects.d.ts +0 -24
- package/dist/openai.d.ts +0 -8
- package/dist/prompts/chat-mode/system.md.d.ts +0 -2
- package/dist/prompts/chat-mode/user.md.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -6
- package/dist/prompts/dual-modes.d.ts +0 -2
- package/dist/prompts/prompt.d.ts +0 -50
- package/dist/prompts/worker-mode/system.md.d.ts +0 -2
- package/dist/prompts/worker-mode/user.md.d.ts +0 -2
- package/dist/snapshots.d.ts +0 -69
- package/dist/stack-traces.d.ts +0 -1
- package/dist/tool-LY77IWV2.js +0 -11
- package/dist/tool-SWJYOR2Z.cjs +0 -11
- package/dist/tool.d.ts +0 -55
- package/dist/transcript.d.ts +0 -9
- package/dist/truncator-NYN7BGKJ.cjs +0 -10
- package/dist/truncator-WAL2GCUY.js +0 -10
- package/dist/truncator.d.ts +0 -21
- package/dist/types.d.ts +0 -139
- package/dist/typings-AIV2OASX.js +0 -10
- package/dist/typings-XR6CYHW4.cjs +0 -10
- package/dist/typings.d.ts +0 -5
- package/dist/utils-L5GLCS3C.js +0 -37
- package/dist/utils-QC4I2L6R.cjs +0 -37
- package/dist/utils.d.ts +0 -21
- package/dist/vm-GJ5R72AP.cjs +0 -12
- package/dist/vm-ZUQOSRRM.js +0 -12
- package/dist/vm.d.ts +0 -3
package/dist/chunk-EJRCDWBA.cjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
exports.assertValidComponent = assertValidComponent; exports.getComponentReference = getComponentReference; exports.Component = Component; exports.isComponent = isComponent; exports.isAnyComponent = isAnyComponent;
|
package/dist/chunk-FIVFS4HG.cjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
|
|
4
|
-
|
|
5
|
-
// src/truncator.ts
|
|
6
|
-
var DEFAULT_REMOVE_CHUNK = 250;
|
|
7
|
-
var WRAP_OPEN_TAG_1 = "\u3010TRUNCATE";
|
|
8
|
-
var WRAP_OPEN_TAG_2 = "\u3011";
|
|
9
|
-
var WRAP_CLOSE_TAG = "\u3010/TRUNCATE\u3011";
|
|
10
|
-
var getRegex = () => new RegExp(`(${WRAP_OPEN_TAG_1}(?:\\s+[\\w:]+)*\\s*${WRAP_OPEN_TAG_2})([\\s\\S]*?)(${WRAP_CLOSE_TAG})`, "g");
|
|
11
|
-
var DEFAULT_TRUNCATE_OPTIONS = {
|
|
12
|
-
preserve: "top",
|
|
13
|
-
flex: 1,
|
|
14
|
-
minTokens: 0
|
|
15
|
-
};
|
|
16
|
-
function wrapContent(content, options) {
|
|
17
|
-
const preserve = _nullishCoalesce((options == null ? void 0 : options.preserve), () => ( DEFAULT_TRUNCATE_OPTIONS.preserve));
|
|
18
|
-
const flex = _nullishCoalesce((options == null ? void 0 : options.flex), () => ( DEFAULT_TRUNCATE_OPTIONS.flex));
|
|
19
|
-
const minTokens = _nullishCoalesce((options == null ? void 0 : options.minTokens), () => ( DEFAULT_TRUNCATE_OPTIONS.minTokens));
|
|
20
|
-
return `${WRAP_OPEN_TAG_1} preserve:${preserve} flex:${flex} min:${minTokens} ${WRAP_OPEN_TAG_2}${content}${WRAP_CLOSE_TAG}`;
|
|
21
|
-
}
|
|
22
|
-
function truncateWrappedContent({
|
|
23
|
-
messages,
|
|
24
|
-
tokenLimit,
|
|
25
|
-
throwOnFailure = true
|
|
26
|
-
}) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
const tokenizer = _chunkP7J2WCBBcjs.getTokenizer.call(void 0, );
|
|
29
|
-
const parts = [];
|
|
30
|
-
for (const msg of messages) {
|
|
31
|
-
const current = [];
|
|
32
|
-
const content = msg.content;
|
|
33
|
-
let match;
|
|
34
|
-
const regex = getRegex();
|
|
35
|
-
let lastIndex = 0;
|
|
36
|
-
while ((match = regex.exec(content)) !== null) {
|
|
37
|
-
const attributes = match[1].split(/\s+/).slice(1).filter((x) => x !== WRAP_OPEN_TAG_2).map((x) => x.split(":")).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
38
|
-
if (match.index > lastIndex) {
|
|
39
|
-
const nonTruncatableContent = content.slice(lastIndex, match.index);
|
|
40
|
-
current.push({
|
|
41
|
-
content: nonTruncatableContent,
|
|
42
|
-
tokens: tokenizer.count(nonTruncatableContent),
|
|
43
|
-
truncatable: false
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const wrappedContent = match[2];
|
|
47
|
-
current.push({
|
|
48
|
-
content: wrappedContent,
|
|
49
|
-
tokens: tokenizer.count(wrappedContent),
|
|
50
|
-
truncatable: true,
|
|
51
|
-
attributes: {
|
|
52
|
-
preserve: attributes.preserve,
|
|
53
|
-
flex: Number(attributes.flex) || DEFAULT_TRUNCATE_OPTIONS.flex,
|
|
54
|
-
minTokens: Number(attributes.min) || DEFAULT_TRUNCATE_OPTIONS.minTokens
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
lastIndex = regex.lastIndex;
|
|
58
|
-
}
|
|
59
|
-
if (lastIndex < content.length) {
|
|
60
|
-
const remainingContent = content.slice(lastIndex);
|
|
61
|
-
current.push({
|
|
62
|
-
content: remainingContent,
|
|
63
|
-
tokens: tokenizer.count(remainingContent),
|
|
64
|
-
truncatable: false
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
parts.push(current);
|
|
68
|
-
}
|
|
69
|
-
const getCount = () => parts.reduce((acc, x) => acc + x.reduce((acc2, y) => acc2 + y.tokens, 0), 0);
|
|
70
|
-
const getTwoBiggestTruncatables = () => {
|
|
71
|
-
var _a2, _b2;
|
|
72
|
-
let biggest = null;
|
|
73
|
-
let secondBiggest = null;
|
|
74
|
-
for (const part of parts.flat()) {
|
|
75
|
-
if (part.truncatable) {
|
|
76
|
-
const flex = _nullishCoalesce(((_a2 = part.attributes) == null ? void 0 : _a2.flex), () => ( DEFAULT_TRUNCATE_OPTIONS.flex));
|
|
77
|
-
const tokens = part.tokens * flex;
|
|
78
|
-
if (part.tokens <= (_nullishCoalesce(((_b2 = part.attributes) == null ? void 0 : _b2.minTokens), () => ( 0)))) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if (!biggest || tokens > biggest.tokens) {
|
|
82
|
-
secondBiggest = biggest;
|
|
83
|
-
biggest = part;
|
|
84
|
-
} else if (!secondBiggest || tokens > secondBiggest.tokens) {
|
|
85
|
-
secondBiggest = part;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return { biggest, secondBiggest };
|
|
90
|
-
};
|
|
91
|
-
let currentCount = getCount();
|
|
92
|
-
while (currentCount > tokenLimit) {
|
|
93
|
-
const { biggest, secondBiggest } = getTwoBiggestTruncatables();
|
|
94
|
-
if (!biggest || !biggest.truncatable || biggest.tokens <= 0) {
|
|
95
|
-
if (throwOnFailure) {
|
|
96
|
-
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
97
|
-
} else {
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const delta = Math.max(biggest.tokens - (_nullishCoalesce((secondBiggest == null ? void 0 : secondBiggest.tokens), () => ( 0))), DEFAULT_REMOVE_CHUNK);
|
|
102
|
-
const room = Math.min(delta, biggest.tokens);
|
|
103
|
-
let toRemove = Math.min(room, currentCount - tokenLimit);
|
|
104
|
-
if (toRemove <= 0) {
|
|
105
|
-
if (throwOnFailure) {
|
|
106
|
-
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
107
|
-
} else {
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (biggest.tokens - toRemove < (_nullishCoalesce(((_a = biggest.attributes) == null ? void 0 : _a.minTokens), () => ( 0)))) {
|
|
112
|
-
toRemove = biggest.tokens - (_nullishCoalesce(((_b = biggest.attributes) == null ? void 0 : _b.minTokens), () => ( 0)));
|
|
113
|
-
}
|
|
114
|
-
const preserve = _nullishCoalesce(((_c = biggest.attributes) == null ? void 0 : _c.preserve), () => ( DEFAULT_TRUNCATE_OPTIONS.preserve));
|
|
115
|
-
const split = tokenizer.split(biggest.content);
|
|
116
|
-
if (preserve === "bottom") {
|
|
117
|
-
biggest.content = split.slice(toRemove).join("");
|
|
118
|
-
} else if (preserve === "top") {
|
|
119
|
-
biggest.content = split.slice(0, -toRemove).join("");
|
|
120
|
-
} else {
|
|
121
|
-
const anchor = Math.ceil(split.length / 2);
|
|
122
|
-
const radius = Math.ceil(toRemove / 2);
|
|
123
|
-
const left = anchor - radius;
|
|
124
|
-
const right = anchor + radius;
|
|
125
|
-
biggest.content = split.slice(0, left).join("") + split.slice(right).join("");
|
|
126
|
-
}
|
|
127
|
-
biggest.tokens -= toRemove;
|
|
128
|
-
currentCount -= toRemove;
|
|
129
|
-
}
|
|
130
|
-
const removeRedundantWrappers = (content) => {
|
|
131
|
-
return content.replace(getRegex(), "$2");
|
|
132
|
-
};
|
|
133
|
-
return messages.map((msg, i) => {
|
|
134
|
-
const p = parts[i];
|
|
135
|
-
return {
|
|
136
|
-
...msg,
|
|
137
|
-
content: removeRedundantWrappers(
|
|
138
|
-
p.map((part) => {
|
|
139
|
-
if (part.truncatable) {
|
|
140
|
-
return part.content;
|
|
141
|
-
}
|
|
142
|
-
return part.content;
|
|
143
|
-
}).join("")
|
|
144
|
-
)
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
exports.wrapContent = wrapContent; exports.truncateWrappedContent = truncateWrappedContent;
|
package/dist/chunk-HP7RKM25.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isAnyJsxComponent,
|
|
3
|
-
isJsxComponent
|
|
4
|
-
} from "./chunk-ORQP26SZ.js";
|
|
5
|
-
|
|
6
|
-
// src/component.ts
|
|
7
|
-
import { z } from "@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 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
|
-
definition;
|
|
133
|
-
propsType;
|
|
134
|
-
// phantom type for inference
|
|
135
|
-
constructor(definition) {
|
|
136
|
-
assertValidComponent(definition);
|
|
137
|
-
this.definition = definition;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
function isComponent(rendered, component) {
|
|
141
|
-
return isJsxComponent(component.definition.name, rendered);
|
|
142
|
-
}
|
|
143
|
-
function isAnyComponent(message) {
|
|
144
|
-
return isAnyJsxComponent(message);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export {
|
|
148
|
-
assertValidComponent,
|
|
149
|
-
getComponentReference,
|
|
150
|
-
Component,
|
|
151
|
-
isComponent,
|
|
152
|
-
isAnyComponent
|
|
153
|
-
};
|