@vertesia/build-tools 0.24.0-dev.202601221707
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 +1730 -0
- package/lib/build-tools.js.map +1 -0
- package/lib/cjs/index.js +39 -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 +150 -0
- package/lib/cjs/plugin.js.map +1 -0
- package/lib/cjs/presets/index.js +19 -0
- package/lib/cjs/presets/index.js.map +1 -0
- package/lib/cjs/presets/prompt.js +185 -0
- package/lib/cjs/presets/prompt.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-collection.js +83 -0
- package/lib/cjs/presets/skill-collection.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 +144 -0
- package/lib/esm/plugin.js.map +1 -0
- package/lib/esm/presets/index.js +8 -0
- package/lib/esm/presets/index.js.map +1 -0
- package/lib/esm/presets/prompt.js +181 -0
- package/lib/esm/presets/prompt.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-collection.js +77 -0
- package/lib/esm/presets/skill-collection.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 +8 -0
- package/lib/types/presets/index.d.ts.map +1 -0
- package/lib/types/presets/prompt.d.ts +63 -0
- package/lib/types/presets/prompt.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-collection.d.ts +26 -0
- package/lib/types/presets/skill-collection.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 +115 -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 +69 -0
- package/src/index.ts +52 -0
- package/src/parsers/frontmatter.ts +32 -0
- package/src/plugin.ts +166 -0
- package/src/presets/index.ts +8 -0
- package/src/presets/prompt.ts +227 -0
- package/src/presets/raw.ts +24 -0
- package/src/presets/skill-collection.ts +86 -0
- package/src/presets/skill.ts +271 -0
- package/src/types.ts +140 -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,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core Rollup plugin implementation for transforming imports
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.vertesiaImportPlugin = vertesiaImportPlugin;
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const asset_copy_js_1 = require("./utils/asset-copy.js");
|
|
13
|
+
const widget_compiler_js_1 = require("./utils/widget-compiler.js");
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Rollup plugin that transforms imports based on configured rules
|
|
16
|
+
*/
|
|
17
|
+
function vertesiaImportPlugin(config) {
|
|
18
|
+
const { transformers, assetsDir = './dist', widgetConfig } = config;
|
|
19
|
+
if (!transformers || transformers.length === 0) {
|
|
20
|
+
throw new Error('vertesiaImportPlugin: At least one transformer must be configured');
|
|
21
|
+
}
|
|
22
|
+
// Track assets to copy and widgets to compile
|
|
23
|
+
const assetsToProcess = [];
|
|
24
|
+
const widgetsToCompile = [];
|
|
25
|
+
const shouldCopyAssets = assetsDir !== false;
|
|
26
|
+
const shouldCompileWidgets = widgetConfig !== undefined && assetsDir !== false;
|
|
27
|
+
return {
|
|
28
|
+
name: 'vertesia-import-plugin',
|
|
29
|
+
/**
|
|
30
|
+
* Resolve import IDs to handle pattern-based imports
|
|
31
|
+
*/
|
|
32
|
+
resolveId(source, importer) {
|
|
33
|
+
// Check if any transformer pattern matches
|
|
34
|
+
for (const transformer of transformers) {
|
|
35
|
+
if (transformer.pattern.test(source)) {
|
|
36
|
+
// Handle relative imports
|
|
37
|
+
if (source.startsWith('.') && importer) {
|
|
38
|
+
const cleanSource = source.replace(transformer.pattern, '');
|
|
39
|
+
// Strip query parameters from importer to get the file path
|
|
40
|
+
const cleanImporter = importer.indexOf('?') >= 0
|
|
41
|
+
? importer.substring(0, importer.indexOf('?'))
|
|
42
|
+
: importer;
|
|
43
|
+
// Always use dirname to get the directory containing the importer
|
|
44
|
+
const baseDir = node_path_1.default.dirname(cleanImporter);
|
|
45
|
+
const resolved = node_path_1.default.resolve(baseDir, cleanSource);
|
|
46
|
+
// Return with the pattern suffix to identify it in load
|
|
47
|
+
const suffix = source.match(transformer.pattern)?.[0] || '';
|
|
48
|
+
return resolved + suffix;
|
|
49
|
+
}
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null; // Let other plugins handle it
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Load and transform the file content
|
|
57
|
+
*/
|
|
58
|
+
async load(id) {
|
|
59
|
+
// Find matching transformer
|
|
60
|
+
let matchedTransformer;
|
|
61
|
+
let cleanId = id;
|
|
62
|
+
for (const transformer of transformers) {
|
|
63
|
+
if (transformer.pattern.test(id)) {
|
|
64
|
+
matchedTransformer = transformer;
|
|
65
|
+
// Remove query parameters to get actual file path
|
|
66
|
+
// For example: '/path/file.md?skill' -> '/path/file.md'
|
|
67
|
+
// '/path/file.html?raw' -> '/path/file.html'
|
|
68
|
+
const queryIndex = id.indexOf('?');
|
|
69
|
+
cleanId = queryIndex >= 0 ? id.substring(0, queryIndex) : id;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!matchedTransformer) {
|
|
74
|
+
return null; // Not for us
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
// Read file content (skip for virtual transforms)
|
|
78
|
+
const content = matchedTransformer.virtual
|
|
79
|
+
? ''
|
|
80
|
+
: (0, node_fs_1.readFileSync)(cleanId, 'utf-8');
|
|
81
|
+
// Transform the content
|
|
82
|
+
const result = await matchedTransformer.transform(content, cleanId);
|
|
83
|
+
// Collect assets if any
|
|
84
|
+
if (result.assets && shouldCopyAssets) {
|
|
85
|
+
assetsToProcess.push(...result.assets);
|
|
86
|
+
}
|
|
87
|
+
// Collect widgets if any
|
|
88
|
+
if (result.widgets && shouldCompileWidgets) {
|
|
89
|
+
widgetsToCompile.push(...result.widgets);
|
|
90
|
+
}
|
|
91
|
+
// Validate if schema provided
|
|
92
|
+
if (matchedTransformer.schema) {
|
|
93
|
+
const validation = matchedTransformer.schema.safeParse(result.data);
|
|
94
|
+
if (!validation.success) {
|
|
95
|
+
const errors = validation.error.errors
|
|
96
|
+
.map((err) => ` - ${err.path.join('.')}: ${err.message}`)
|
|
97
|
+
.join('\n');
|
|
98
|
+
throw new Error(`Validation failed for ${id}:\n${errors}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Generate code
|
|
102
|
+
const imports = result.imports ? result.imports.join('\n') + '\n\n' : '';
|
|
103
|
+
if (result.code) {
|
|
104
|
+
// Custom code provided - prepend imports
|
|
105
|
+
return imports + result.code;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Default: export data (escape if string, otherwise stringify as JSON)
|
|
109
|
+
const dataJson = JSON.stringify(result.data, null, 2);
|
|
110
|
+
return `${imports}export default ${dataJson};`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
115
|
+
this.error(`Failed to transform ${id}: ${message}`);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Copy assets and compile widgets after all modules are loaded
|
|
120
|
+
*/
|
|
121
|
+
async buildEnd() {
|
|
122
|
+
// Copy script assets
|
|
123
|
+
if (shouldCopyAssets && assetsToProcess.length > 0) {
|
|
124
|
+
try {
|
|
125
|
+
const copied = (0, asset_copy_js_1.copyAssets)(assetsToProcess, assetsDir);
|
|
126
|
+
console.log(`Copied ${copied} asset file(s) to ${assetsDir}`);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
130
|
+
this.warn(`Failed to copy assets: ${message}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Compile widgets
|
|
134
|
+
if (shouldCompileWidgets && widgetsToCompile.length > 0) {
|
|
135
|
+
try {
|
|
136
|
+
const widgetsDir = config.widgetsDir || 'widgets';
|
|
137
|
+
const outputDir = node_path_1.default.join(assetsDir, widgetsDir);
|
|
138
|
+
console.log(`Compiling ${widgetsToCompile.length} widget(s)...`);
|
|
139
|
+
const compiled = await (0, widget_compiler_js_1.compileWidgets)(widgetsToCompile, outputDir, widgetConfig);
|
|
140
|
+
console.log(`Compiled ${compiled} widget(s) to ${outputDir}`);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
144
|
+
this.error(`Failed to compile widgets: ${message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAaH,oDAsJC;AAhKD,qCAAuC;AACvC,0DAA6B;AAE7B,yDAAmD;AACnD,mEAA4D;AAG5D;;GAEG;AACH,SAAgB,oBAAoB,CAAC,MAAoB;IACrD,MAAM,EAAE,YAAY,EAAE,SAAS,GAAG,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEpE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC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AC,CAAC;gBAClE,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACvE,IAAI,CAAC,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;gBACxD,CAAC;YACL,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Preset transformers for common use cases
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TemplateType = exports.PromptRole = exports.PromptDefinitionSchema = exports.promptTransformer = exports.rawTransformer = exports.skillCollectionTransformer = exports.SkillDefinitionSchema = exports.skillTransformer = void 0;
|
|
7
|
+
var skill_js_1 = require("./skill.js");
|
|
8
|
+
Object.defineProperty(exports, "skillTransformer", { enumerable: true, get: function () { return skill_js_1.skillTransformer; } });
|
|
9
|
+
Object.defineProperty(exports, "SkillDefinitionSchema", { enumerable: true, get: function () { return skill_js_1.SkillDefinitionSchema; } });
|
|
10
|
+
var skill_collection_js_1 = require("./skill-collection.js");
|
|
11
|
+
Object.defineProperty(exports, "skillCollectionTransformer", { enumerable: true, get: function () { return skill_collection_js_1.skillCollectionTransformer; } });
|
|
12
|
+
var raw_js_1 = require("./raw.js");
|
|
13
|
+
Object.defineProperty(exports, "rawTransformer", { enumerable: true, get: function () { return raw_js_1.rawTransformer; } });
|
|
14
|
+
var prompt_js_1 = require("./prompt.js");
|
|
15
|
+
Object.defineProperty(exports, "promptTransformer", { enumerable: true, get: function () { return prompt_js_1.promptTransformer; } });
|
|
16
|
+
Object.defineProperty(exports, "PromptDefinitionSchema", { enumerable: true, get: function () { return prompt_js_1.PromptDefinitionSchema; } });
|
|
17
|
+
Object.defineProperty(exports, "PromptRole", { enumerable: true, get: function () { return prompt_js_1.PromptRole; } });
|
|
18
|
+
Object.defineProperty(exports, "TemplateType", { enumerable: true, get: function () { return prompt_js_1.TemplateType; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/presets/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uCAAkH;AAAzG,4GAAA,gBAAgB,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAChD,6DAAmE;AAA1D,iIAAA,0BAA0B,OAAA;AACnC,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,yCAAiJ;AAAxI,8GAAA,iBAAiB,OAAA;AAAE,mHAAA,sBAAsB,OAAA;AAAiD,uGAAA,UAAU,OAAA;AAAE,yGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompt transformer preset for template files with frontmatter
|
|
4
|
+
* Supports .jst, .hbs, and plain text files
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.promptTransformer = exports.PromptDefinitionSchema = exports.PromptRole = exports.TemplateType = void 0;
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const frontmatter_js_1 = require("../parsers/frontmatter.js");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const common_1 = require("@vertesia/common");
|
|
15
|
+
Object.defineProperty(exports, "TemplateType", { enumerable: true, get: function () { return common_1.TemplateType; } });
|
|
16
|
+
const common_2 = require("@llumiverse/common");
|
|
17
|
+
Object.defineProperty(exports, "PromptRole", { enumerable: true, get: function () { return common_2.PromptRole; } });
|
|
18
|
+
/**
|
|
19
|
+
* Zod schema for prompt frontmatter validation
|
|
20
|
+
*/
|
|
21
|
+
const PromptFrontmatterSchema = zod_1.z.object({
|
|
22
|
+
// Required fields
|
|
23
|
+
role: zod_1.z.nativeEnum(common_2.PromptRole, {
|
|
24
|
+
errorMap: () => ({ message: 'Role must be one of: safety, system, user, assistant, negative' })
|
|
25
|
+
}),
|
|
26
|
+
// Optional fields
|
|
27
|
+
content_type: zod_1.z.nativeEnum(common_1.TemplateType).optional(),
|
|
28
|
+
schema: zod_1.z.string().optional(),
|
|
29
|
+
name: zod_1.z.string().optional(),
|
|
30
|
+
externalId: zod_1.z.string().optional(),
|
|
31
|
+
}).strict();
|
|
32
|
+
/**
|
|
33
|
+
* MUST be kept in sync with @vertesia/common InCodePrompt
|
|
34
|
+
* Zod schema for prompt definition
|
|
35
|
+
*/
|
|
36
|
+
exports.PromptDefinitionSchema = zod_1.z.object({
|
|
37
|
+
role: zod_1.z.nativeEnum(common_2.PromptRole),
|
|
38
|
+
content: zod_1.z.string(),
|
|
39
|
+
content_type: zod_1.z.nativeEnum(common_1.TemplateType),
|
|
40
|
+
schema: zod_1.z.any().optional(),
|
|
41
|
+
name: zod_1.z.string().optional(),
|
|
42
|
+
externalId: zod_1.z.string().optional(),
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Normalize schema path for import
|
|
46
|
+
* - Adds './' prefix if not a relative path
|
|
47
|
+
* - Replaces .ts with .js
|
|
48
|
+
* - Adds .js if no extension
|
|
49
|
+
*
|
|
50
|
+
* @param schemaPath - Original schema path from frontmatter
|
|
51
|
+
* @returns Normalized path for ES module import
|
|
52
|
+
*/
|
|
53
|
+
function normalizeSchemaPath(schemaPath) {
|
|
54
|
+
let normalized = schemaPath.trim();
|
|
55
|
+
// Add './' prefix if not already a relative path
|
|
56
|
+
if (!normalized.startsWith('.')) {
|
|
57
|
+
normalized = './' + normalized;
|
|
58
|
+
}
|
|
59
|
+
// Get the extension
|
|
60
|
+
const ext = path_1.default.extname(normalized);
|
|
61
|
+
if (ext === '.ts') {
|
|
62
|
+
// Replace .ts with .js
|
|
63
|
+
normalized = normalized.slice(0, -3) + '.js';
|
|
64
|
+
}
|
|
65
|
+
else if (!ext) {
|
|
66
|
+
// No extension, add .js
|
|
67
|
+
normalized = normalized + '.js';
|
|
68
|
+
}
|
|
69
|
+
// If extension is already .js or something else, leave as is
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Infer content type from file extension
|
|
74
|
+
*
|
|
75
|
+
* @param filePath - Path to the prompt file
|
|
76
|
+
* @returns Inferred content type
|
|
77
|
+
*/
|
|
78
|
+
function inferContentType(filePath) {
|
|
79
|
+
const ext = path_1.default.extname(filePath).toLowerCase();
|
|
80
|
+
switch (ext) {
|
|
81
|
+
case '.jst':
|
|
82
|
+
return common_1.TemplateType.jst;
|
|
83
|
+
case '.hbs':
|
|
84
|
+
return common_1.TemplateType.handlebars;
|
|
85
|
+
default:
|
|
86
|
+
return common_1.TemplateType.text;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Build a PromptDefinition from frontmatter and content
|
|
91
|
+
*
|
|
92
|
+
* @param frontmatter - Parsed frontmatter object
|
|
93
|
+
* @param content - Prompt content (body of the file)
|
|
94
|
+
* @param filePath - Path to the prompt file (for content type inference)
|
|
95
|
+
* @returns Prompt definition object and optional imports
|
|
96
|
+
*/
|
|
97
|
+
function buildPromptDefinition(frontmatter, content, filePath) {
|
|
98
|
+
// Determine content type from frontmatter or file extension
|
|
99
|
+
const content_type = frontmatter.content_type || inferContentType(filePath);
|
|
100
|
+
const prompt = {
|
|
101
|
+
role: frontmatter.role,
|
|
102
|
+
content,
|
|
103
|
+
content_type,
|
|
104
|
+
};
|
|
105
|
+
// Add optional fields
|
|
106
|
+
if (frontmatter.name) {
|
|
107
|
+
prompt.name = frontmatter.name;
|
|
108
|
+
}
|
|
109
|
+
if (frontmatter.externalId) {
|
|
110
|
+
prompt.externalId = frontmatter.externalId;
|
|
111
|
+
}
|
|
112
|
+
// Handle schema import if specified
|
|
113
|
+
let imports;
|
|
114
|
+
let schemaImportName;
|
|
115
|
+
if (frontmatter.schema) {
|
|
116
|
+
const normalizedPath = normalizeSchemaPath(frontmatter.schema);
|
|
117
|
+
schemaImportName = '__promptSchema';
|
|
118
|
+
imports = [`import ${schemaImportName} from '${normalizedPath}';`];
|
|
119
|
+
}
|
|
120
|
+
return { prompt, imports, schemaImportName };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Prompt transformer preset
|
|
124
|
+
* Transforms template files with ?prompt suffix into prompt definition objects
|
|
125
|
+
*
|
|
126
|
+
* Supported file types:
|
|
127
|
+
* - .jst (JavaScript template literals) → content_type: 'jst'
|
|
128
|
+
* - .hbs (Handlebars templates) → content_type: 'handlebars'
|
|
129
|
+
* - .txt or other → content_type: 'text'
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import PROMPT from './prompt.hbs?prompt';
|
|
134
|
+
* // PROMPT is an InCodePrompt object
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
exports.promptTransformer = {
|
|
138
|
+
pattern: /\?prompt$/,
|
|
139
|
+
schema: exports.PromptDefinitionSchema,
|
|
140
|
+
transform: (content, filePath) => {
|
|
141
|
+
const { frontmatter, content: promptContent } = (0, frontmatter_js_1.parseFrontmatter)(content);
|
|
142
|
+
// Validate frontmatter
|
|
143
|
+
const frontmatterValidation = PromptFrontmatterSchema.safeParse(frontmatter);
|
|
144
|
+
if (!frontmatterValidation.success) {
|
|
145
|
+
const errors = frontmatterValidation.error.errors
|
|
146
|
+
.map((err) => {
|
|
147
|
+
const path = err.path.length > 0 ? err.path.join('.') : 'frontmatter';
|
|
148
|
+
return ` - ${path}: ${err.message}`;
|
|
149
|
+
})
|
|
150
|
+
.join('\n');
|
|
151
|
+
throw new Error(`Invalid frontmatter in ${filePath}:\n${errors}`);
|
|
152
|
+
}
|
|
153
|
+
// Build prompt definition
|
|
154
|
+
const { prompt, imports, schemaImportName } = buildPromptDefinition(frontmatter, promptContent, filePath);
|
|
155
|
+
// If schema is specified, generate custom code with schema reference
|
|
156
|
+
if (schemaImportName) {
|
|
157
|
+
// Build the code manually to avoid JSON.stringify issues with schema reference
|
|
158
|
+
const lines = [
|
|
159
|
+
'export default {',
|
|
160
|
+
` role: "${prompt.role}",`,
|
|
161
|
+
` content: ${JSON.stringify(prompt.content)},`,
|
|
162
|
+
` content_type: "${prompt.content_type}",`,
|
|
163
|
+
` schema: ${schemaImportName}`,
|
|
164
|
+
];
|
|
165
|
+
if (prompt.name) {
|
|
166
|
+
lines.splice(4, 0, ` name: ${JSON.stringify(prompt.name)},`);
|
|
167
|
+
}
|
|
168
|
+
if (prompt.externalId) {
|
|
169
|
+
lines.splice(4, 0, ` externalId: ${JSON.stringify(prompt.externalId)},`);
|
|
170
|
+
}
|
|
171
|
+
lines.push('};');
|
|
172
|
+
const code = lines.join('\n');
|
|
173
|
+
return {
|
|
174
|
+
data: prompt,
|
|
175
|
+
imports,
|
|
176
|
+
code,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// Standard case without schema
|
|
180
|
+
return {
|
|
181
|
+
data: prompt,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/presets/prompt.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,6BAAwB;AAExB,8DAA6D;AAC7D,gDAAwB;AACxB,6CAAgD;AAMvC,6FANA,qBAAY,OAMA;AALrB,+CAAgD;AAKzB,2FALd,mBAAU,OAKc;AAOjC;;GAEG;AACH,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,kBAAkB;IAClB,IAAI,EAAE,OAAC,CAAC,UAAU,CAA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AAqE;QACrE,IAAI,gBAAgB,EAAE,CAAC;YACnB,+EAA+E;YAC/E,MAAM,KAAK,GAAG;gBACV,kBAAkB;gBAClB,YAAY,MAAM,CAAC,IAAI,IAAI;gBAC3B,cAAc,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG;gBAC/C,oBAAoB,MAAM,CAAC,YAAY,IAAI;gBAC3C,aAAa,gBAAgB,EAAE;aAClC,CAAC;YAEF,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACd,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClE,CAAC;YACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACpB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,iBAAiB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC9E,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE9B,OAAO;gBACH,IAAI,EAAE,MAAM;gBACZ,OAAO;gBACP,IAAI;aACP,CAAC;QACN,CAAC;QAED,+BAA+B;QAC/B,OAAO;YACH,IAAI,EAAE,MAAM;SACf,CAAC;IACN,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Raw transformer preset for importing file content as strings
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rawTransformer = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Raw transformer preset
|
|
9
|
+
* Transforms any file with ?raw suffix into a string export
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import template from './template.html?raw';
|
|
14
|
+
* // template is a string containing the file content
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
exports.rawTransformer = {
|
|
18
|
+
pattern: /\?raw$/,
|
|
19
|
+
transform: (content) => {
|
|
20
|
+
return {
|
|
21
|
+
data: content
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=raw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw.js","sourceRoot":"","sources":["../../../src/presets/raw.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;;;;;;;;GASG;AACU,QAAA,cAAc,GAAsB;IAC7C,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE;QAC3B,OAAO;YACH,IAAI,EAAE,OAAO;SAChB,CAAC;IACN,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Skill collection transformer for directory-based skill imports
|
|
4
|
+
* Scans a directory for subdirectories containing SKILL.md files
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.skillCollectionTransformer = void 0;
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
/**
|
|
14
|
+
* Skill collection transformer preset
|
|
15
|
+
* Transforms directory imports with ?skills suffix into an array of skill imports
|
|
16
|
+
*
|
|
17
|
+
* Matches:
|
|
18
|
+
* - ./all?skills (recommended - generates all.js in the directory)
|
|
19
|
+
* - ./_skills?skills (generates _skills.js in the directory)
|
|
20
|
+
* - Any path ending with a filename and ?skills
|
|
21
|
+
*
|
|
22
|
+
* NOTE: A filename before ?skills is REQUIRED to avoid naming conflicts.
|
|
23
|
+
* The filename becomes the output module name.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import skills from './all?skills';
|
|
28
|
+
* // Scans current directory for subdirectories with SKILL.md
|
|
29
|
+
* // Generates all.js containing array of all skills
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
exports.skillCollectionTransformer = {
|
|
33
|
+
pattern: /\/[^/?]+\?skills$/,
|
|
34
|
+
virtual: true, // Indicates this doesn't transform a real file
|
|
35
|
+
transform: (_content, filePath) => {
|
|
36
|
+
// Remove ?skills suffix and the filename to get directory path
|
|
37
|
+
// Example: /path/code/all?skills -> /path/code/all -> /path/code/
|
|
38
|
+
const pathWithoutQuery = filePath.replace(/\?skills$/, '');
|
|
39
|
+
const dirPath = node_path_1.default.dirname(pathWithoutQuery);
|
|
40
|
+
if (!(0, node_fs_1.existsSync)(dirPath)) {
|
|
41
|
+
throw new Error(`Directory not found: ${dirPath}`);
|
|
42
|
+
}
|
|
43
|
+
if (!(0, node_fs_1.statSync)(dirPath).isDirectory()) {
|
|
44
|
+
throw new Error(`Not a directory: ${dirPath}`);
|
|
45
|
+
}
|
|
46
|
+
// Scan for subdirectories containing SKILL.md
|
|
47
|
+
const entries = (0, node_fs_1.readdirSync)(dirPath);
|
|
48
|
+
const imports = [];
|
|
49
|
+
const names = [];
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
const entryPath = node_path_1.default.join(dirPath, entry);
|
|
52
|
+
try {
|
|
53
|
+
if ((0, node_fs_1.statSync)(entryPath).isDirectory()) {
|
|
54
|
+
const skillFile = node_path_1.default.join(entryPath, 'SKILL.md');
|
|
55
|
+
if ((0, node_fs_1.existsSync)(skillFile)) {
|
|
56
|
+
// Generate unique identifier from directory name
|
|
57
|
+
const identifier = `Skill_${entry.replace(/[^a-zA-Z0-9_]/g, '_')}`;
|
|
58
|
+
imports.push(`import ${identifier} from './${entry}/SKILL.md';`);
|
|
59
|
+
names.push(identifier);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
// Skip entries that can't be read
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (names.length === 0) {
|
|
69
|
+
console.warn(`No SKILL.md files found in subdirectories of ${dirPath}`);
|
|
70
|
+
}
|
|
71
|
+
// Generate code that imports all skills and exports as array
|
|
72
|
+
const code = [
|
|
73
|
+
...imports,
|
|
74
|
+
'',
|
|
75
|
+
`export default [${names.join(', ')}];`
|
|
76
|
+
].join('\n');
|
|
77
|
+
return {
|
|
78
|
+
data: null, // Not used when custom code is provided
|
|
79
|
+
code
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=skill-collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-collection.js","sourceRoot":"","sources":["../../../src/presets/skill-collection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,qCAA4D;AAC5D,0DAA6B;AAG7B;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,0BAA0B,GAAsB;IACzD,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,IAAI,EAAE,+CAA+C;IAC9D,SAAS,EAAE,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAE;QAC9C,+DAA+D;QAC/D,kEAAkE;QAClE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,mBAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAA,oBAAU,EAAC,OAAO,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,CAA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