@vertesia/build-tools 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +334 -0
- package/lib/build-tools.js +616 -0
- package/lib/build-tools.js.map +1 -0
- package/lib/cjs/index.js +34 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/parsers/frontmatter.js +25 -0
- package/lib/cjs/parsers/frontmatter.js.map +1 -0
- package/lib/cjs/plugin.js +142 -0
- package/lib/cjs/plugin.js.map +1 -0
- package/lib/cjs/presets/index.js +12 -0
- package/lib/cjs/presets/index.js.map +1 -0
- package/lib/cjs/presets/raw.js +25 -0
- package/lib/cjs/presets/raw.js.map +1 -0
- package/lib/cjs/presets/skill.js +224 -0
- package/lib/cjs/presets/skill.js.map +1 -0
- package/lib/cjs/types.js +6 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/utils/asset-copy.js +61 -0
- package/lib/cjs/utils/asset-copy.js.map +1 -0
- package/lib/cjs/utils/asset-discovery.js +100 -0
- package/lib/cjs/utils/asset-discovery.js.map +1 -0
- package/lib/cjs/utils/widget-compiler.js +115 -0
- package/lib/cjs/utils/widget-compiler.js.map +1 -0
- package/lib/esm/index.js +26 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/parsers/frontmatter.js +19 -0
- package/lib/esm/parsers/frontmatter.js.map +1 -0
- package/lib/esm/plugin.js +136 -0
- package/lib/esm/plugin.js.map +1 -0
- package/lib/esm/presets/index.js +6 -0
- package/lib/esm/presets/index.js.map +1 -0
- package/lib/esm/presets/raw.js +22 -0
- package/lib/esm/presets/raw.js.map +1 -0
- package/lib/esm/presets/skill.js +221 -0
- package/lib/esm/presets/skill.js.map +1 -0
- package/lib/esm/types.js +5 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils/asset-copy.js +54 -0
- package/lib/esm/utils/asset-copy.js.map +1 -0
- package/lib/esm/utils/asset-discovery.js +94 -0
- package/lib/esm/utils/asset-discovery.js.map +1 -0
- package/lib/esm/utils/widget-compiler.js +76 -0
- package/lib/esm/utils/widget-compiler.js.map +1 -0
- package/lib/types/index.d.ts +24 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/parsers/frontmatter.d.ts +19 -0
- package/lib/types/parsers/frontmatter.d.ts.map +1 -0
- package/lib/types/plugin.d.ts +10 -0
- package/lib/types/plugin.d.ts.map +1 -0
- package/lib/types/presets/index.d.ts +6 -0
- package/lib/types/presets/index.d.ts.map +1 -0
- package/lib/types/presets/raw.d.ts +16 -0
- package/lib/types/presets/raw.d.ts.map +1 -0
- package/lib/types/presets/skill.d.ts +139 -0
- package/lib/types/presets/skill.d.ts.map +1 -0
- package/lib/types/types.d.ts +113 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/utils/asset-copy.d.ts +20 -0
- package/lib/types/utils/asset-copy.d.ts.map +1 -0
- package/lib/types/utils/asset-discovery.d.ts +38 -0
- package/lib/types/utils/asset-discovery.d.ts.map +1 -0
- package/lib/types/utils/widget-compiler.d.ts +15 -0
- package/lib/types/utils/widget-compiler.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/index.ts +45 -0
- package/src/parsers/frontmatter.ts +32 -0
- package/src/plugin.ts +158 -0
- package/src/presets/index.ts +6 -0
- package/src/presets/raw.ts +24 -0
- package/src/presets/skill.ts +271 -0
- package/src/types.ts +137 -0
- package/src/utils/asset-copy.ts +63 -0
- package/src/utils/asset-discovery.ts +138 -0
- package/src/utils/widget-compiler.ts +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2024 Composable
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# @vertesia/build-tools
|
|
2
|
+
|
|
3
|
+
A flexible Rollup plugin for transforming imports with custom compilers and validation. Built for Vertesia but usable in any project.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Pattern-based import transformation** - Match imports by path patterns
|
|
8
|
+
- ✅ **Built-in Zod validation** - Validate transformed data at build time
|
|
9
|
+
- 🔧 **Preset transformers** - Ready-to-use transformers for common cases
|
|
10
|
+
- 🎨 **Custom transformers** - Easy to create custom transformation logic
|
|
11
|
+
- 📦 **TypeScript-first** - Full type safety with TypeScript
|
|
12
|
+
- ⚡ **Fast** - Efficient transformation with minimal overhead
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add -D @vertesia/build-tools
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Using Preset Transformers
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// rollup.config.js
|
|
26
|
+
import { vertesiaImportPlugin, skillTransformer, rawTransformer } from '@vertesia/build-tools';
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
input: 'src/index.ts',
|
|
30
|
+
output: {
|
|
31
|
+
dir: 'dist',
|
|
32
|
+
format: 'es'
|
|
33
|
+
},
|
|
34
|
+
plugins: [
|
|
35
|
+
vertesiaImportPlugin({
|
|
36
|
+
transformers: [
|
|
37
|
+
skillTransformer, // Handles .md?skill imports
|
|
38
|
+
rawTransformer // Handles ?raw imports
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Using in Your Code
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Import a skill definition from markdown
|
|
49
|
+
import codeReview from './skills/code-review.md?skill';
|
|
50
|
+
|
|
51
|
+
console.log(codeReview.name); // 'code-review'
|
|
52
|
+
console.log(codeReview.title); // 'Code Review Assistant'
|
|
53
|
+
console.log(codeReview.description); // 'Skill for reviewing...'
|
|
54
|
+
console.log(codeReview.instructions); // Full markdown content
|
|
55
|
+
console.log(codeReview.content_type); // 'md' or 'jst'
|
|
56
|
+
|
|
57
|
+
// Import raw file content
|
|
58
|
+
import template from './template.html?raw';
|
|
59
|
+
console.log(template); // Raw HTML string
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Preset Transformers
|
|
63
|
+
|
|
64
|
+
### Skill Transformer
|
|
65
|
+
|
|
66
|
+
Transforms markdown files with frontmatter into skill definition objects.
|
|
67
|
+
|
|
68
|
+
**Pattern:** `.md?skill`
|
|
69
|
+
|
|
70
|
+
**Input:** `my-skill.md`
|
|
71
|
+
```markdown
|
|
72
|
+
---
|
|
73
|
+
name: my-skill
|
|
74
|
+
title: My Skill
|
|
75
|
+
description: A helpful skill
|
|
76
|
+
content_type: md
|
|
77
|
+
context_triggers:
|
|
78
|
+
keywords: [skill, helper]
|
|
79
|
+
related_tools: [tool1, tool2]
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
# My Skill
|
|
83
|
+
|
|
84
|
+
This is the skill content in markdown.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Output:**
|
|
88
|
+
```typescript
|
|
89
|
+
{
|
|
90
|
+
name: 'my-skill',
|
|
91
|
+
title: 'My Skill',
|
|
92
|
+
description: 'A helpful skill',
|
|
93
|
+
instructions: '# My Skill\n\nThis is the skill content...',
|
|
94
|
+
content_type: 'md',
|
|
95
|
+
context_triggers: {
|
|
96
|
+
keywords: ['skill', 'helper']
|
|
97
|
+
},
|
|
98
|
+
related_tools: ['tool1', 'tool2'],
|
|
99
|
+
scripts: ['helper.js', 'script.py'], // If .js/.py files exist in skill dir
|
|
100
|
+
widgets: ['chart', 'user-select'] // If .tsx files exist in skill dir
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Type:** `SkillDefinition` (exported from package)
|
|
105
|
+
|
|
106
|
+
**Asset Discovery:** The skill transformer automatically discovers:
|
|
107
|
+
- Script files (`.js`, `.py`) in the skill directory → added to `scripts` array
|
|
108
|
+
- Widget files (`.tsx`) in the skill directory → added to `widgets` array (without extension)
|
|
109
|
+
|
|
110
|
+
**Asset Copying:** Script files are automatically copied to `{assetsDir}/scripts/` during build. Widget files are automatically compiled to `{assetsDir}/widgets/` during build.
|
|
111
|
+
|
|
112
|
+
**SkillDefinition Schema:**
|
|
113
|
+
```typescript
|
|
114
|
+
{
|
|
115
|
+
name: string; // Required: Unique skill name (kebab-case)
|
|
116
|
+
title?: string; // Optional: Display title
|
|
117
|
+
description: string; // Required: Short description
|
|
118
|
+
instructions: string; // Required: Skill instructions (markdown)
|
|
119
|
+
content_type: 'md' | 'jst'; // Required: Content type
|
|
120
|
+
input_schema?: { // Optional: JSON Schema for parameters
|
|
121
|
+
type: 'object';
|
|
122
|
+
properties?: Record<string, any>;
|
|
123
|
+
required?: string[];
|
|
124
|
+
};
|
|
125
|
+
context_triggers?: { // Optional: Auto-injection triggers
|
|
126
|
+
keywords?: string[]; // Keywords to trigger this skill
|
|
127
|
+
tool_names?: string[]; // Tools that suggest this skill
|
|
128
|
+
data_patterns?: string[]; // Regex patterns for data matching
|
|
129
|
+
};
|
|
130
|
+
execution?: { // Optional: Code execution config
|
|
131
|
+
language: string; // Programming language
|
|
132
|
+
packages?: string[]; // Required packages
|
|
133
|
+
system_packages?: string[]; // System-level packages
|
|
134
|
+
template?: string; // Code template
|
|
135
|
+
};
|
|
136
|
+
related_tools?: string[]; // Optional: Related tool names
|
|
137
|
+
scripts?: string[]; // Optional: Script files in skill dir
|
|
138
|
+
widgets?: string[]; // Optional: Widget names in skill dir
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Raw Transformer
|
|
143
|
+
|
|
144
|
+
Imports any file as a raw string.
|
|
145
|
+
|
|
146
|
+
**Pattern:** `?raw`
|
|
147
|
+
|
|
148
|
+
**Usage:**
|
|
149
|
+
```typescript
|
|
150
|
+
import html from './template.html?raw';
|
|
151
|
+
import css from './styles.css?raw';
|
|
152
|
+
import txt from './data.txt?raw';
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Custom Transformers
|
|
156
|
+
|
|
157
|
+
Create your own transformers for specific use cases:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { vertesiaImportPlugin } from '@vertesia/build-tools';
|
|
161
|
+
import { z } from 'zod';
|
|
162
|
+
|
|
163
|
+
// Define your schema
|
|
164
|
+
const InteractionSchema = z.object({
|
|
165
|
+
name: z.string(),
|
|
166
|
+
type: z.enum(['form', 'modal', 'dialog']),
|
|
167
|
+
fields: z.array(z.object({
|
|
168
|
+
name: z.string(),
|
|
169
|
+
type: z.string()
|
|
170
|
+
}))
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export default {
|
|
174
|
+
plugins: [
|
|
175
|
+
vertesiaImportPlugin({
|
|
176
|
+
transformers: [
|
|
177
|
+
{
|
|
178
|
+
// Match pattern
|
|
179
|
+
pattern: /\.interaction\.json$/,
|
|
180
|
+
|
|
181
|
+
// Optional validation schema
|
|
182
|
+
schema: InteractionSchema,
|
|
183
|
+
|
|
184
|
+
// Transform function
|
|
185
|
+
transform: (content, filePath) => {
|
|
186
|
+
const json = JSON.parse(content);
|
|
187
|
+
|
|
188
|
+
// Add computed fields
|
|
189
|
+
json.timestamp = Date.now();
|
|
190
|
+
json.source = filePath;
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
data: json
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## API
|
|
204
|
+
|
|
205
|
+
### `vertesiaImportPlugin(config)`
|
|
206
|
+
|
|
207
|
+
Main plugin factory.
|
|
208
|
+
|
|
209
|
+
**Parameters:**
|
|
210
|
+
- `config.transformers` - Array of transformer rules
|
|
211
|
+
- `config.assetsDir` - Root directory for asset output (default: `'./dist'`, use `false` to disable)
|
|
212
|
+
- `config.scriptsDir` - Directory for script files relative to assetsDir (default: `'scripts'`)
|
|
213
|
+
- `config.widgetsDir` - Directory for widget files relative to assetsDir (default: `'widgets'`)
|
|
214
|
+
|
|
215
|
+
**Returns:** Rollup Plugin
|
|
216
|
+
|
|
217
|
+
**Asset Management:**
|
|
218
|
+
- When `assetsDir` is configured, script files (`.js`, `.py`) discovered in skill directories are automatically copied to `{assetsDir}/{scriptsDir}/`
|
|
219
|
+
- Widget files (`.tsx`) are tracked in the skill definition but not copied (compile them separately)
|
|
220
|
+
- Set `assetsDir: false` to disable asset copying
|
|
221
|
+
|
|
222
|
+
### `TransformerRule`
|
|
223
|
+
|
|
224
|
+
Configuration for a single transformer.
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
interface TransformerRule {
|
|
228
|
+
pattern: RegExp; // Pattern to match imports
|
|
229
|
+
transform: TransformFunction; // Transform function
|
|
230
|
+
schema?: z.ZodType<any>; // Optional Zod schema
|
|
231
|
+
options?: Record<string, unknown>; // Optional custom options
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### `TransformFunction`
|
|
236
|
+
|
|
237
|
+
Function that transforms file content.
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
type TransformFunction = (
|
|
241
|
+
content: string,
|
|
242
|
+
filePath: string
|
|
243
|
+
) => TransformResult | Promise<TransformResult>;
|
|
244
|
+
|
|
245
|
+
interface TransformResult {
|
|
246
|
+
data: unknown; // Data to export (serialized to JSON)
|
|
247
|
+
imports?: string[]; // Optional imports to inject
|
|
248
|
+
code?: string; // Optional custom code generation
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Advanced Usage
|
|
253
|
+
|
|
254
|
+
### Custom Code Generation
|
|
255
|
+
|
|
256
|
+
Instead of JSON export, generate custom code:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
{
|
|
260
|
+
pattern: /\.template\.ts$/,
|
|
261
|
+
transform: (content, filePath) => {
|
|
262
|
+
return {
|
|
263
|
+
data: null,
|
|
264
|
+
code: `
|
|
265
|
+
export function render() {
|
|
266
|
+
return ${JSON.stringify(content)};
|
|
267
|
+
}
|
|
268
|
+
export const filePath = ${JSON.stringify(filePath)};
|
|
269
|
+
`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Adding Imports
|
|
276
|
+
|
|
277
|
+
Inject imports into the generated module:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
{
|
|
281
|
+
pattern: /\.config\.yaml$/,
|
|
282
|
+
transform: (content) => {
|
|
283
|
+
const config = parseYaml(content);
|
|
284
|
+
return {
|
|
285
|
+
data: config,
|
|
286
|
+
imports: [
|
|
287
|
+
"import { validateConfig } from './validator.js';",
|
|
288
|
+
"validateConfig(config);"
|
|
289
|
+
]
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Type Safety
|
|
296
|
+
|
|
297
|
+
The plugin exports TypeScript types for use in your code:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import type { SkillDefinition } from '@vertesia/build-tools';
|
|
301
|
+
|
|
302
|
+
function processSkill(skill: SkillDefinition) {
|
|
303
|
+
console.log(skill.name);
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## How It Works
|
|
308
|
+
|
|
309
|
+
1. **Pattern Matching:** Plugin intercepts imports matching configured patterns
|
|
310
|
+
2. **File Loading:** Reads the actual file from disk
|
|
311
|
+
3. **Transformation:** Runs the transform function on file content
|
|
312
|
+
4. **Validation:** If schema provided, validates the result with Zod
|
|
313
|
+
5. **Code Generation:** Generates JavaScript module with the data
|
|
314
|
+
6. **Build Fails:** If validation fails, build stops with clear error messages
|
|
315
|
+
|
|
316
|
+
## Error Handling
|
|
317
|
+
|
|
318
|
+
The plugin provides detailed error messages when validation fails:
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
Error: Validation failed for ./skills/bad-skill.md?skill:
|
|
322
|
+
- name: Required
|
|
323
|
+
- description: String must contain at least 1 character(s)
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
Apache-2.0
|
|
329
|
+
|
|
330
|
+
## Repository
|
|
331
|
+
|
|
332
|
+
https://github.com/vertesia/composableai
|
|
333
|
+
|
|
334
|
+
Part of the Vertesia LLM Studio monorepo.
|