@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill transformer preset for markdown files with frontmatter
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import type { TransformerPreset } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Content type for skill instructions
|
|
8
|
+
*/
|
|
9
|
+
export type SkillContentType = 'md' | 'jst';
|
|
10
|
+
/**
|
|
11
|
+
* MUST be kept in sync with @vertesia/tools-sdk SkillDefinition
|
|
12
|
+
* Zod schema for skill definition
|
|
13
|
+
* This validates the structure of skill objects generated from markdown
|
|
14
|
+
* Matches the SkillDefinition interface from @vertesia/tools-sdk
|
|
15
|
+
*/
|
|
16
|
+
export declare const SkillDefinitionSchema: z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
title: z.ZodOptional<z.ZodString>;
|
|
19
|
+
description: z.ZodString;
|
|
20
|
+
instructions: z.ZodString;
|
|
21
|
+
content_type: z.ZodEnum<["md", "jst"]>;
|
|
22
|
+
input_schema: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
type: z.ZodLiteral<"object">;
|
|
24
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
25
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
type: "object";
|
|
28
|
+
properties?: Record<string, any> | undefined;
|
|
29
|
+
required?: string[] | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
type: "object";
|
|
32
|
+
properties?: Record<string, any> | undefined;
|
|
33
|
+
required?: string[] | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
context_triggers: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
37
|
+
tool_names: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
38
|
+
data_patterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
keywords?: string[] | undefined;
|
|
41
|
+
tool_names?: string[] | undefined;
|
|
42
|
+
data_patterns?: string[] | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
keywords?: string[] | undefined;
|
|
45
|
+
tool_names?: string[] | undefined;
|
|
46
|
+
data_patterns?: string[] | undefined;
|
|
47
|
+
}>>;
|
|
48
|
+
execution: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
language: z.ZodString;
|
|
50
|
+
packages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
51
|
+
system_packages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
52
|
+
template: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
language: string;
|
|
55
|
+
packages?: string[] | undefined;
|
|
56
|
+
system_packages?: string[] | undefined;
|
|
57
|
+
template?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
language: string;
|
|
60
|
+
packages?: string[] | undefined;
|
|
61
|
+
system_packages?: string[] | undefined;
|
|
62
|
+
template?: string | undefined;
|
|
63
|
+
}>>;
|
|
64
|
+
related_tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
65
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
66
|
+
widgets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
name: string;
|
|
69
|
+
description: string;
|
|
70
|
+
content_type: "md" | "jst";
|
|
71
|
+
instructions: string;
|
|
72
|
+
scripts?: string[] | undefined;
|
|
73
|
+
widgets?: string[] | undefined;
|
|
74
|
+
title?: string | undefined;
|
|
75
|
+
context_triggers?: {
|
|
76
|
+
keywords?: string[] | undefined;
|
|
77
|
+
tool_names?: string[] | undefined;
|
|
78
|
+
data_patterns?: string[] | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
execution?: {
|
|
81
|
+
language: string;
|
|
82
|
+
packages?: string[] | undefined;
|
|
83
|
+
system_packages?: string[] | undefined;
|
|
84
|
+
template?: string | undefined;
|
|
85
|
+
} | undefined;
|
|
86
|
+
related_tools?: string[] | undefined;
|
|
87
|
+
input_schema?: {
|
|
88
|
+
type: "object";
|
|
89
|
+
properties?: Record<string, any> | undefined;
|
|
90
|
+
required?: string[] | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
name: string;
|
|
94
|
+
description: string;
|
|
95
|
+
content_type: "md" | "jst";
|
|
96
|
+
instructions: string;
|
|
97
|
+
scripts?: string[] | undefined;
|
|
98
|
+
widgets?: string[] | undefined;
|
|
99
|
+
title?: string | undefined;
|
|
100
|
+
context_triggers?: {
|
|
101
|
+
keywords?: string[] | undefined;
|
|
102
|
+
tool_names?: string[] | undefined;
|
|
103
|
+
data_patterns?: string[] | undefined;
|
|
104
|
+
} | undefined;
|
|
105
|
+
execution?: {
|
|
106
|
+
language: string;
|
|
107
|
+
packages?: string[] | undefined;
|
|
108
|
+
system_packages?: string[] | undefined;
|
|
109
|
+
template?: string | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
related_tools?: string[] | undefined;
|
|
112
|
+
input_schema?: {
|
|
113
|
+
type: "object";
|
|
114
|
+
properties?: Record<string, any> | undefined;
|
|
115
|
+
required?: string[] | undefined;
|
|
116
|
+
} | undefined;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* TypeScript type inferred from the Zod schema
|
|
120
|
+
* Can also be imported from consumer packages for type safety
|
|
121
|
+
*/
|
|
122
|
+
export type SkillDefinition = z.infer<typeof SkillDefinitionSchema>;
|
|
123
|
+
/**
|
|
124
|
+
* Skill transformer preset
|
|
125
|
+
* Transforms markdown files with ?skill suffix OR SKILL.md files into skill definition objects
|
|
126
|
+
*
|
|
127
|
+
* Matches:
|
|
128
|
+
* - Files with ?skill suffix: ./my-skill.md?skill
|
|
129
|
+
* - SKILL.md files: ./my-skill/SKILL.md
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import skill1 from './my-skill.md?skill';
|
|
134
|
+
* import skill2 from './my-skill/SKILL.md';
|
|
135
|
+
* // Both are SkillDefinition objects
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare const skillTransformer: TransformerPreset;
|
|
139
|
+
//# sourceMappingURL=skill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../../src/presets/skill.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,KAAK,CAAC;AA6E5C;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBhC,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAiGpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAyC9B,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Vertesia Rollup Import Plugin
|
|
3
|
+
*/
|
|
4
|
+
import type { Plugin } from 'rollup';
|
|
5
|
+
import type { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Asset file to be copied during build
|
|
8
|
+
*/
|
|
9
|
+
export interface AssetFile {
|
|
10
|
+
/** Source file path (absolute) */
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
/** Relative destination path within assets directory */
|
|
13
|
+
destPath: string;
|
|
14
|
+
/** Asset type for categorization */
|
|
15
|
+
type: 'script';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result of a transform function
|
|
19
|
+
*/
|
|
20
|
+
export interface TransformResult {
|
|
21
|
+
/** The data to export (can be text or JSON object) */
|
|
22
|
+
data: unknown;
|
|
23
|
+
/** Optional: additional imports to inject at the top of the generated module */
|
|
24
|
+
imports?: string[];
|
|
25
|
+
/** Optional: custom code to generate instead of default JSON export */
|
|
26
|
+
code?: string;
|
|
27
|
+
/** Optional: additional asset files to copy */
|
|
28
|
+
assets?: AssetFile[];
|
|
29
|
+
/** Optional: widget metadata for compilation */
|
|
30
|
+
widgets?: Array<{
|
|
31
|
+
name: string;
|
|
32
|
+
path: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Transform function that converts file content into exportable data
|
|
37
|
+
*/
|
|
38
|
+
export type TransformFunction = (content: string, filePath: string) => TransformResult | Promise<TransformResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for a single import transformer rule
|
|
41
|
+
*/
|
|
42
|
+
export interface TransformerRule {
|
|
43
|
+
/** Pattern to match import paths (e.g., /\.md\?skill$/ or /\?raw$/) */
|
|
44
|
+
pattern: RegExp;
|
|
45
|
+
/** Transform function to convert file content */
|
|
46
|
+
transform: TransformFunction;
|
|
47
|
+
/** Optional: Zod schema for validation */
|
|
48
|
+
schema?: z.ZodType<any>;
|
|
49
|
+
/** Optional: additional options for this transformer */
|
|
50
|
+
options?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Widget compilation configuration
|
|
54
|
+
*/
|
|
55
|
+
export interface WidgetConfig {
|
|
56
|
+
/**
|
|
57
|
+
* External dependencies that should not be bundled
|
|
58
|
+
* Default: ['react', 'react-dom', 'react/jsx-runtime']
|
|
59
|
+
*/
|
|
60
|
+
external?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Path to tsconfig.json for widget compilation
|
|
63
|
+
* Default: './tsconfig.json'
|
|
64
|
+
*/
|
|
65
|
+
tsconfig?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Additional options to pass to @rollup/plugin-typescript
|
|
68
|
+
*/
|
|
69
|
+
typescript?: Record<string, unknown>;
|
|
70
|
+
/**
|
|
71
|
+
* Minify widget output
|
|
72
|
+
* Default: false
|
|
73
|
+
*/
|
|
74
|
+
minify?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Plugin configuration
|
|
78
|
+
*/
|
|
79
|
+
export interface PluginConfig {
|
|
80
|
+
/** Array of transformer rules to apply */
|
|
81
|
+
transformers: TransformerRule[];
|
|
82
|
+
/**
|
|
83
|
+
* Root directory for asset output (scripts, widgets, etc.)
|
|
84
|
+
* - If specified: assets will be copied to this directory
|
|
85
|
+
* - If false: asset copying is disabled
|
|
86
|
+
* - Default: './dist'
|
|
87
|
+
*/
|
|
88
|
+
assetsDir?: string | false;
|
|
89
|
+
/**
|
|
90
|
+
* Directory for script files relative to assetsDir
|
|
91
|
+
* Default: 'scripts'
|
|
92
|
+
*/
|
|
93
|
+
scriptsDir?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Directory for widget files relative to assetsDir
|
|
96
|
+
* Default: 'widgets'
|
|
97
|
+
*/
|
|
98
|
+
widgetsDir?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Widget compilation configuration
|
|
101
|
+
* If provided, discovered widgets will be automatically compiled
|
|
102
|
+
*/
|
|
103
|
+
widgetConfig?: WidgetConfig;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Type for transformer presets
|
|
107
|
+
*/
|
|
108
|
+
export type TransformerPreset = TransformerRule;
|
|
109
|
+
/**
|
|
110
|
+
* Plugin factory return type
|
|
111
|
+
*/
|
|
112
|
+
export type VertesiaImportPlugin = (config: PluginConfig) => Plugin;
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;IAEjB,oCAAoC;IACpC,IAAI,EAAE,QAAQ,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,sDAAsD;IACtD,IAAI,EAAE,OAAO,CAAC;IAEd,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,+CAA+C;IAC/C,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IAErB,gDAAgD;IAChD,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,KACf,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAEhB,iDAAiD;IACjD,SAAS,EAAE,iBAAiB,CAAC;IAE7B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAExB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAErC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,0CAA0C;IAC1C,YAAY,EAAE,eAAe,EAAE,CAAC;IAEhC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for copying asset files during build
|
|
3
|
+
*/
|
|
4
|
+
import type { AssetFile } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Copy an asset file to its destination
|
|
7
|
+
*
|
|
8
|
+
* @param asset - Asset file information
|
|
9
|
+
* @param assetsRoot - Root directory for assets
|
|
10
|
+
*/
|
|
11
|
+
export declare function copyAssetFile(asset: AssetFile, assetsRoot: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Copy multiple asset files
|
|
14
|
+
*
|
|
15
|
+
* @param assets - Array of asset files to copy
|
|
16
|
+
* @param assetsRoot - Root directory for assets
|
|
17
|
+
* @returns Number of files copied
|
|
18
|
+
*/
|
|
19
|
+
export declare function copyAssets(assets: AssetFile[], assetsRoot: string): number;
|
|
20
|
+
//# sourceMappingURL=asset-copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-copy.d.ts","sourceRoot":"","sources":["../../../src/utils/asset-copy.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgB7C;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAgBxE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAS1E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for discovering asset files (scripts, widgets) in skill directories
|
|
3
|
+
*/
|
|
4
|
+
import type { AssetFile } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Widget metadata for compilation
|
|
7
|
+
*/
|
|
8
|
+
export interface WidgetMetadata {
|
|
9
|
+
/** Widget name (without .tsx extension) */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Absolute path to widget file */
|
|
12
|
+
path: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Discovered assets in a skill directory
|
|
16
|
+
*/
|
|
17
|
+
export interface DiscoveredAssets {
|
|
18
|
+
/** Script file names (with extensions: .js, .py) */
|
|
19
|
+
scripts: string[];
|
|
20
|
+
/** Widget file names (without .tsx extension) */
|
|
21
|
+
widgets: string[];
|
|
22
|
+
/** Widget metadata for compilation */
|
|
23
|
+
widgetMetadata: WidgetMetadata[];
|
|
24
|
+
/** Asset files to be copied */
|
|
25
|
+
assetFiles: AssetFile[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Discover assets (scripts and widgets) in a skill directory
|
|
29
|
+
*
|
|
30
|
+
* @param skillFilePath - Absolute path to the skill.md file
|
|
31
|
+
* @param options - Asset discovery options
|
|
32
|
+
* @returns Discovered assets and metadata
|
|
33
|
+
*/
|
|
34
|
+
export declare function discoverSkillAssets(skillFilePath: string, options?: {
|
|
35
|
+
scriptsDir?: string;
|
|
36
|
+
widgetsDir?: string;
|
|
37
|
+
}): DiscoveredAssets;
|
|
38
|
+
//# sourceMappingURL=asset-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-discovery.d.ts","sourceRoot":"","sources":["../../../src/utils/asset-discovery.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,oDAAoD;IACpD,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,iDAAiD;IACjD,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,sCAAsC;IACtC,cAAc,EAAE,cAAc,EAAE,CAAC;IAEjC,+BAA+B;IAC/B,UAAU,EAAE,SAAS,EAAE,CAAC;CAC3B;AAgDD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE;IACL,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CAClB,GACP,gBAAgB,CA0ClB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget compilation utility using Rollup
|
|
3
|
+
*/
|
|
4
|
+
import type { WidgetConfig } from '../types.js';
|
|
5
|
+
import type { WidgetMetadata } from './asset-discovery.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compile widgets using Rollup
|
|
8
|
+
*
|
|
9
|
+
* @param widgets - Array of widget metadata to compile
|
|
10
|
+
* @param outputDir - Directory to write compiled widgets
|
|
11
|
+
* @param config - Widget compilation configuration
|
|
12
|
+
* @returns Number of widgets compiled
|
|
13
|
+
*/
|
|
14
|
+
export declare function compileWidgets(widgets: WidgetMetadata[], outputDir: string, config?: WidgetConfig): Promise<number>;
|
|
15
|
+
//# sourceMappingURL=widget-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-compiler.d.ts","sourceRoot":"","sources":["../../../src/utils/widget-compiler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAa3D;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAChC,OAAO,EAAE,cAAc,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,YAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAiEjB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vertesia/build-tools",
|
|
3
|
+
"version": "0.80.0",
|
|
4
|
+
"description": "Build tools for Vertesia projects - Rollup and Vite plugins for transforming imports, bundling skills, and compiling widgets",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/esm/index.js",
|
|
7
|
+
"types": "./lib/types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./lib/types/index.d.ts",
|
|
15
|
+
"import": "./lib/esm/index.js",
|
|
16
|
+
"require": "./lib/cjs/index.js"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
20
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
21
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
22
|
+
"@types/node": "^25.0.3",
|
|
23
|
+
"rollup": "^4.40.2",
|
|
24
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
25
|
+
"ts-dual-module": "^0.6.3",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"vitest": "^4.0.16"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"gray-matter": "^4.0.3",
|
|
31
|
+
"zod": "^3.24.1"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"rollup": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"ts_dual_module": {
|
|
37
|
+
"outDir": "lib"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/vertesia/composableai.git",
|
|
42
|
+
"directory": "packages/build-tools"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"vertesia",
|
|
46
|
+
"rollup",
|
|
47
|
+
"rollup-plugin",
|
|
48
|
+
"vite",
|
|
49
|
+
"vite-plugin",
|
|
50
|
+
"build-tools",
|
|
51
|
+
"imports",
|
|
52
|
+
"transform",
|
|
53
|
+
"compiler",
|
|
54
|
+
"skill",
|
|
55
|
+
"markdown",
|
|
56
|
+
"frontmatter",
|
|
57
|
+
"widget",
|
|
58
|
+
"bundler",
|
|
59
|
+
"zod",
|
|
60
|
+
"validation"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"build": "pnpm exec tsmod build && pnpm exec rollup -c",
|
|
65
|
+
"clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertesia Rollup Import Plugin
|
|
3
|
+
*
|
|
4
|
+
* A flexible Rollup plugin for transforming imports with custom compilers and validation.
|
|
5
|
+
* Supports preset transformers for common use cases (skills, raw files) and custom transformers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { vertesiaImportPlugin, skillTransformer, rawTransformer } from '@vertesia/build-tools';
|
|
10
|
+
*
|
|
11
|
+
* export default {
|
|
12
|
+
* plugins: [
|
|
13
|
+
* vertesiaImportPlugin({
|
|
14
|
+
* transformers: [skillTransformer, rawTransformer]
|
|
15
|
+
* })
|
|
16
|
+
* ]
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Core plugin
|
|
22
|
+
export { vertesiaImportPlugin } from './plugin.js';
|
|
23
|
+
|
|
24
|
+
// Types
|
|
25
|
+
export type {
|
|
26
|
+
PluginConfig,
|
|
27
|
+
TransformerRule,
|
|
28
|
+
TransformerPreset,
|
|
29
|
+
TransformFunction,
|
|
30
|
+
TransformResult,
|
|
31
|
+
AssetFile,
|
|
32
|
+
WidgetConfig
|
|
33
|
+
} from './types.js';
|
|
34
|
+
|
|
35
|
+
// Presets
|
|
36
|
+
export {
|
|
37
|
+
skillTransformer,
|
|
38
|
+
rawTransformer,
|
|
39
|
+
SkillDefinitionSchema,
|
|
40
|
+
type SkillDefinition,
|
|
41
|
+
type SkillContentType
|
|
42
|
+
} from './presets/index.js';
|
|
43
|
+
|
|
44
|
+
// Utilities
|
|
45
|
+
export { parseFrontmatter, type FrontmatterResult } from './parsers/frontmatter.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontmatter parser utility using gray-matter
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import matter from 'gray-matter';
|
|
6
|
+
|
|
7
|
+
export interface FrontmatterResult {
|
|
8
|
+
/** Parsed frontmatter data */
|
|
9
|
+
frontmatter: Record<string, any>;
|
|
10
|
+
|
|
11
|
+
/** Content without frontmatter */
|
|
12
|
+
content: string;
|
|
13
|
+
|
|
14
|
+
/** Original full content */
|
|
15
|
+
original: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse YAML frontmatter from markdown content
|
|
20
|
+
*
|
|
21
|
+
* @param content - Raw markdown content with optional frontmatter
|
|
22
|
+
* @returns Parsed frontmatter and content
|
|
23
|
+
*/
|
|
24
|
+
export function parseFrontmatter(content: string): FrontmatterResult {
|
|
25
|
+
const result = matter(content);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
frontmatter: result.data,
|
|
29
|
+
content: result.content,
|
|
30
|
+
original: content
|
|
31
|
+
};
|
|
32
|
+
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Rollup plugin implementation for transforming imports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Plugin } from 'rollup';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import type { PluginConfig, TransformerRule, AssetFile } from './types.js';
|
|
9
|
+
import { copyAssets } from './utils/asset-copy.js';
|
|
10
|
+
import { compileWidgets } from './utils/widget-compiler.js';
|
|
11
|
+
import type { WidgetMetadata } from './utils/asset-discovery.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Rollup plugin that transforms imports based on configured rules
|
|
15
|
+
*/
|
|
16
|
+
export function vertesiaImportPlugin(config: PluginConfig): Plugin {
|
|
17
|
+
const { transformers, assetsDir = './dist', widgetConfig } = config;
|
|
18
|
+
|
|
19
|
+
if (!transformers || transformers.length === 0) {
|
|
20
|
+
throw new Error('vertesiaImportPlugin: At least one transformer must be configured');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Track assets to copy and widgets to compile
|
|
24
|
+
const assetsToProcess: AssetFile[] = [];
|
|
25
|
+
const widgetsToCompile: WidgetMetadata[] = [];
|
|
26
|
+
const shouldCopyAssets = assetsDir !== false;
|
|
27
|
+
const shouldCompileWidgets = widgetConfig !== undefined && assetsDir !== false;
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: 'vertesia-import-plugin',
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Resolve import IDs to handle pattern-based imports
|
|
34
|
+
*/
|
|
35
|
+
resolveId(source: string, importer: string | undefined) {
|
|
36
|
+
// Check if any transformer pattern matches
|
|
37
|
+
for (const transformer of transformers) {
|
|
38
|
+
if (transformer.pattern.test(source)) {
|
|
39
|
+
// Handle relative imports
|
|
40
|
+
if (source.startsWith('.') && importer) {
|
|
41
|
+
const cleanSource = source.replace(transformer.pattern, '');
|
|
42
|
+
const resolved = path.resolve(path.dirname(importer), cleanSource);
|
|
43
|
+
// Return with the pattern suffix to identify it in load
|
|
44
|
+
const suffix = source.match(transformer.pattern)?.[0] || '';
|
|
45
|
+
return resolved + suffix;
|
|
46
|
+
}
|
|
47
|
+
return source;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null; // Let other plugins handle it
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Load and transform the file content
|
|
55
|
+
*/
|
|
56
|
+
async load(id: string) {
|
|
57
|
+
// Find matching transformer
|
|
58
|
+
let matchedTransformer: TransformerRule | undefined;
|
|
59
|
+
let cleanId = id;
|
|
60
|
+
|
|
61
|
+
for (const transformer of transformers) {
|
|
62
|
+
if (transformer.pattern.test(id)) {
|
|
63
|
+
matchedTransformer = transformer;
|
|
64
|
+
// Remove query parameters to get actual file path
|
|
65
|
+
// For example: '/path/file.md?skill' -> '/path/file.md'
|
|
66
|
+
// '/path/file.html?raw' -> '/path/file.html'
|
|
67
|
+
const queryIndex = id.indexOf('?');
|
|
68
|
+
cleanId = queryIndex >= 0 ? id.substring(0, queryIndex) : id;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!matchedTransformer) {
|
|
74
|
+
return null; // Not for us
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
// Read file content
|
|
79
|
+
const content = readFileSync(cleanId, 'utf-8');
|
|
80
|
+
|
|
81
|
+
// Transform the content
|
|
82
|
+
const result = await matchedTransformer.transform(content, cleanId);
|
|
83
|
+
|
|
84
|
+
// Collect assets if any
|
|
85
|
+
if (result.assets && shouldCopyAssets) {
|
|
86
|
+
assetsToProcess.push(...result.assets);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Collect widgets if any
|
|
90
|
+
if (result.widgets && shouldCompileWidgets) {
|
|
91
|
+
widgetsToCompile.push(...result.widgets);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Validate if schema provided
|
|
95
|
+
if (matchedTransformer.schema) {
|
|
96
|
+
const validation = matchedTransformer.schema.safeParse(result.data);
|
|
97
|
+
if (!validation.success) {
|
|
98
|
+
const errors = validation.error.errors
|
|
99
|
+
.map((err) => ` - ${err.path.join('.')}: ${err.message}`)
|
|
100
|
+
.join('\n');
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Validation failed for ${id}:\n${errors}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Generate code
|
|
108
|
+
if (result.code) {
|
|
109
|
+
// Custom code provided
|
|
110
|
+
return result.code;
|
|
111
|
+
} else {
|
|
112
|
+
// Default: export data (escape if string, otherwise stringify as JSON)
|
|
113
|
+
const imports = result.imports ? result.imports.join('\n') + '\n\n' : '';
|
|
114
|
+
const dataJson = JSON.stringify(result.data, null, 2);
|
|
115
|
+
return `${imports}export default ${dataJson};`;
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
+
this.error(`Failed to transform ${id}: ${message}`);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Copy assets and compile widgets after all modules are loaded
|
|
125
|
+
*/
|
|
126
|
+
async buildEnd() {
|
|
127
|
+
// Copy script assets
|
|
128
|
+
if (shouldCopyAssets && assetsToProcess.length > 0) {
|
|
129
|
+
try {
|
|
130
|
+
const copied = copyAssets(assetsToProcess, assetsDir as string);
|
|
131
|
+
console.log(`Copied ${copied} asset file(s) to ${assetsDir}`);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
134
|
+
this.warn(`Failed to copy assets: ${message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Compile widgets
|
|
139
|
+
if (shouldCompileWidgets && widgetsToCompile.length > 0) {
|
|
140
|
+
try {
|
|
141
|
+
const widgetsDir = config.widgetsDir || 'widgets';
|
|
142
|
+
const outputDir = path.join(assetsDir as string, widgetsDir);
|
|
143
|
+
|
|
144
|
+
console.log(`Compiling ${widgetsToCompile.length} widget(s)...`);
|
|
145
|
+
const compiled = await compileWidgets(
|
|
146
|
+
widgetsToCompile,
|
|
147
|
+
outputDir,
|
|
148
|
+
widgetConfig
|
|
149
|
+
);
|
|
150
|
+
console.log(`Compiled ${compiled} widget(s) to ${outputDir}`);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
153
|
+
this.error(`Failed to compile widgets: ${message}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|