@galileodev/meta 0.1.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/dist/builder/builder.d.ts +10 -0
- package/dist/builder/builder.d.ts.map +1 -0
- package/dist/builder/builder.js +45 -0
- package/dist/builder/builder.js.map +1 -0
- package/dist/builder/defaults.d.ts +6 -0
- package/dist/builder/defaults.d.ts.map +1 -0
- package/dist/builder/defaults.js +94 -0
- package/dist/builder/defaults.js.map +1 -0
- package/dist/builder/registry.d.ts +16 -0
- package/dist/builder/registry.d.ts.map +1 -0
- package/dist/builder/registry.js +61 -0
- package/dist/builder/registry.js.map +1 -0
- package/dist/builder/tokenizer.d.ts +2 -0
- package/dist/builder/tokenizer.d.ts.map +1 -0
- package/dist/builder/tokenizer.js +8 -0
- package/dist/builder/tokenizer.js.map +1 -0
- package/dist/builder/types.d.ts +175 -0
- package/dist/builder/types.d.ts.map +1 -0
- package/dist/builder/types.js +33 -0
- package/dist/builder/types.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/optimizer/evaluator.d.ts +4 -0
- package/dist/optimizer/evaluator.d.ts.map +1 -0
- package/dist/optimizer/evaluator.js +14 -0
- package/dist/optimizer/evaluator.js.map +1 -0
- package/dist/optimizer/experiment.d.ts +18 -0
- package/dist/optimizer/experiment.d.ts.map +1 -0
- package/dist/optimizer/experiment.js +104 -0
- package/dist/optimizer/experiment.js.map +1 -0
- package/dist/optimizer/optimizer.d.ts +13 -0
- package/dist/optimizer/optimizer.d.ts.map +1 -0
- package/dist/optimizer/optimizer.js +82 -0
- package/dist/optimizer/optimizer.js.map +1 -0
- package/dist/optimizer/types.d.ts +31 -0
- package/dist/optimizer/types.d.ts.map +1 -0
- package/dist/optimizer/types.js +16 -0
- package/dist/optimizer/types.js.map +1 -0
- package/dist/validator/rules.d.ts +4 -0
- package/dist/validator/rules.d.ts.map +1 -0
- package/dist/validator/rules.js +44 -0
- package/dist/validator/rules.js.map +1 -0
- package/dist/validator/types.d.ts +16 -0
- package/dist/validator/types.d.ts.map +1 -0
- package/dist/validator/types.js +2 -0
- package/dist/validator/types.js.map +1 -0
- package/dist/validator/validator.d.ts +11 -0
- package/dist/validator/validator.d.ts.map +1 -0
- package/dist/validator/validator.js +83 -0
- package/dist/validator/validator.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RenderedPrompt } from './types.js';
|
|
2
|
+
import type { TemplateRegistry } from './registry.js';
|
|
3
|
+
export declare class PromptBuilder {
|
|
4
|
+
private readonly registry;
|
|
5
|
+
constructor(registry: TemplateRegistry);
|
|
6
|
+
build(stage: string, slots: Record<string, unknown>): Promise<RenderedPrompt>;
|
|
7
|
+
private validateRequiredSlots;
|
|
8
|
+
private fillSlots;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/builder/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,gBAAgB;IAEjD,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAwBnF,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,SAAS;CAalB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { countTokens } from './tokenizer.js';
|
|
2
|
+
export class PromptBuilder {
|
|
3
|
+
registry;
|
|
4
|
+
constructor(registry) {
|
|
5
|
+
this.registry = registry;
|
|
6
|
+
}
|
|
7
|
+
async build(stage, slots) {
|
|
8
|
+
const template = await this.registry.getActive(stage);
|
|
9
|
+
if (!template) {
|
|
10
|
+
throw new Error(`No active template for stage '${stage}'. Register a template first.`);
|
|
11
|
+
}
|
|
12
|
+
this.validateRequiredSlots(template, slots);
|
|
13
|
+
const sortedSections = [...template.sections].sort((a, b) => a.order - b.order);
|
|
14
|
+
const renderedSections = sortedSections.map((section) => this.fillSlots(section.content, slots));
|
|
15
|
+
const text = renderedSections.join('\n\n');
|
|
16
|
+
const tokenEstimate = countTokens(text);
|
|
17
|
+
return {
|
|
18
|
+
text,
|
|
19
|
+
template,
|
|
20
|
+
constraints: template.constraints,
|
|
21
|
+
tokenEstimate,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
validateRequiredSlots(template, slots) {
|
|
25
|
+
for (const slot of template.slots) {
|
|
26
|
+
if (slot.required && !(slot.name in slots)) {
|
|
27
|
+
throw new Error(`Required slot '${slot.name}' is missing for template '${template.id}'.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
fillSlots(content, slots) {
|
|
32
|
+
return content.replace(/\{\{(\w+)\}\}/g, (_match, slotName) => {
|
|
33
|
+
const value = slots[slotName];
|
|
34
|
+
if (value === undefined || value === null)
|
|
35
|
+
return '';
|
|
36
|
+
if (typeof value === 'string')
|
|
37
|
+
return value;
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return value.map((item) => typeof item === 'string' ? item : JSON.stringify(item)).join('\n');
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/builder/builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C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B,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;IACH,CAAC;IAEO,SAAS,CAAC,OAAe,EAAE,KAA8B;QAC/D,OAAO,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,QAAgB,EAAE,EAAE;YACpE,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC9B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;gBAAE,OAAO,EAAE,CAAC;YACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAC;YAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxB,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACvD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACf,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PromptTemplate } from './types.js';
|
|
2
|
+
export declare const DEFAULT_GENERATOR_TEMPLATE: PromptTemplate;
|
|
3
|
+
export declare const DEFAULT_REFLECTOR_TEMPLATE: PromptTemplate;
|
|
4
|
+
export declare const DEFAULT_CURATOR_TEMPLATE: PromptTemplate;
|
|
5
|
+
export declare const ALL_DEFAULT_TEMPLATES: PromptTemplate[];
|
|
6
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/builder/defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,0BAA0B,EAAE,cA2BxC,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,cA8BxC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cA4BtC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAAc,EAIjD,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export const DEFAULT_GENERATOR_TEMPLATE = {
|
|
2
|
+
id: 'generator-default-v1',
|
|
3
|
+
stage: 'generator',
|
|
4
|
+
version: 1,
|
|
5
|
+
slots: [
|
|
6
|
+
{ name: 'instruction', type: 'string', required: true, description: 'Task instruction from the developer' },
|
|
7
|
+
{ name: 'playbookContext', type: 'entries', required: false, description: 'Active playbook entries' },
|
|
8
|
+
],
|
|
9
|
+
sections: [
|
|
10
|
+
{
|
|
11
|
+
id: 'role',
|
|
12
|
+
content: 'You are the Generator in an ACE (Agentic Context Engineering) pipeline.\nYour role is to produce explicit reasoning trajectories and code artifacts.',
|
|
13
|
+
order: 1,
|
|
14
|
+
},
|
|
15
|
+
{ id: 'context', content: '## Playbook Context\n{{playbookContext}}', order: 2 },
|
|
16
|
+
{ id: 'task', content: '## Task\n{{instruction}}', order: 3 },
|
|
17
|
+
{
|
|
18
|
+
id: 'format',
|
|
19
|
+
content: 'Respond with trajectories (step-by-step reasoning) and artifacts (code/config files).',
|
|
20
|
+
order: 4,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
constraints: [
|
|
24
|
+
{ id: 'gen-format', type: 'output-format', description: 'Must return JSON with trajectories and artifacts arrays', check: 'zod:GenerationResponseSchema' },
|
|
25
|
+
],
|
|
26
|
+
outputSchema: 'GenerationResponseSchema',
|
|
27
|
+
metadata: { createdAt: '2026-04-03T00:00:00.000Z', tokenEstimate: 200 },
|
|
28
|
+
};
|
|
29
|
+
export const DEFAULT_REFLECTOR_TEMPLATE = {
|
|
30
|
+
id: 'reflector-default-v1',
|
|
31
|
+
stage: 'reflector',
|
|
32
|
+
version: 1,
|
|
33
|
+
slots: [
|
|
34
|
+
{ name: 'trajectories', type: 'string', required: true, description: 'Generator reasoning traces' },
|
|
35
|
+
{ name: 'artifacts', type: 'artifacts', required: true, description: 'Generated code artifacts' },
|
|
36
|
+
{ name: 'groundTruth', type: 'string', required: false, description: 'Test results or error logs' },
|
|
37
|
+
],
|
|
38
|
+
sections: [
|
|
39
|
+
{
|
|
40
|
+
id: 'role',
|
|
41
|
+
content: 'You are the Reflector in an ACE (Agentic Context Engineering) pipeline.\nYour role is to analyze a generation result and extract factual and heuristic lessons.',
|
|
42
|
+
order: 1,
|
|
43
|
+
},
|
|
44
|
+
{ id: 'trajectories', content: '## Generation Trajectories\n{{trajectories}}', order: 2 },
|
|
45
|
+
{ id: 'artifacts', content: '## Generated Artifacts\n{{artifacts}}', order: 3 },
|
|
46
|
+
{ id: 'groundTruth', content: '## Ground Truth\n{{groundTruth}}', order: 4 },
|
|
47
|
+
{
|
|
48
|
+
id: 'format',
|
|
49
|
+
content: 'Extract lessons: what worked (success), what failed (failure), and general heuristics.\nRate your confidence in each lesson from 0 to 1.',
|
|
50
|
+
order: 5,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
constraints: [
|
|
54
|
+
{ id: 'ref-format', type: 'output-format', description: 'Must return JSON with lessons array', check: 'zod:ReflectionResponseSchema' },
|
|
55
|
+
{ id: 'ref-consistency', type: 'consistency', description: 'Lessons must not contradict each other', check: 'llm-judge' },
|
|
56
|
+
],
|
|
57
|
+
outputSchema: 'ReflectionResponseSchema',
|
|
58
|
+
metadata: { createdAt: '2026-04-03T00:00:00.000Z', tokenEstimate: 300 },
|
|
59
|
+
};
|
|
60
|
+
export const DEFAULT_CURATOR_TEMPLATE = {
|
|
61
|
+
id: 'curator-default-v1',
|
|
62
|
+
stage: 'curator',
|
|
63
|
+
version: 1,
|
|
64
|
+
slots: [
|
|
65
|
+
{ name: 'lessons', type: 'lessons', required: true, description: 'Lessons from the Reflector' },
|
|
66
|
+
{ name: 'currentEntries', type: 'entries', required: false, description: 'Current playbook entries' },
|
|
67
|
+
],
|
|
68
|
+
sections: [
|
|
69
|
+
{
|
|
70
|
+
id: 'role',
|
|
71
|
+
content: 'You are the Curator in an ACE (Agentic Context Engineering) pipeline.\nYour role is to score lessons for utility and harmfulness, then produce compact delta updates.',
|
|
72
|
+
order: 1,
|
|
73
|
+
},
|
|
74
|
+
{ id: 'lessons', content: '## Lessons from Reflector\n{{lessons}}', order: 2 },
|
|
75
|
+
{ id: 'currentEntries', content: '## Current Playbook Entries\n{{currentEntries}}', order: 3 },
|
|
76
|
+
{
|
|
77
|
+
id: 'format',
|
|
78
|
+
content: 'For each lesson, produce a concise delta entry with utility score [0,1] and harmfulness score [0,1].\nMerge similar insights. Drop low-value or harmful ones.',
|
|
79
|
+
order: 4,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
constraints: [
|
|
83
|
+
{ id: 'cur-format', type: 'output-format', description: 'Must return JSON with scoredEntries array', check: 'zod:CurationResponseSchema' },
|
|
84
|
+
{ id: 'cur-scores', type: 'content-rule', description: 'Utility and harmfulness scores must be in [0, 1]', check: 'range:0:1' },
|
|
85
|
+
],
|
|
86
|
+
outputSchema: 'CurationResponseSchema',
|
|
87
|
+
metadata: { createdAt: '2026-04-03T00:00:00.000Z', tokenEstimate: 250 },
|
|
88
|
+
};
|
|
89
|
+
export const ALL_DEFAULT_TEMPLATES = [
|
|
90
|
+
DEFAULT_GENERATOR_TEMPLATE,
|
|
91
|
+
DEFAULT_REFLECTOR_TEMPLATE,
|
|
92
|
+
DEFAULT_CURATOR_TEMPLATE,
|
|
93
|
+
];
|
|
94
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/builder/defaults.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,0BAA0B,GAAmB;IACxD,EAAE,EAAE,sBAAsB;IAC1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AE,gBAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE;KACtG;IACD,QAAQ,EAAE;QACR;YACE,EAAE,EAAE,MAAM;YACV,OAAO,EAAE,uKAAuK;YAChL,KAAK,EAAE,CAAC;SACT;QACD,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,wCAAwC,EAAE,KAAK,EAAE,CAAC,EAAE;QAC9E,EAAE,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,iDAAiD,EAAE,KAAK,EAAE,CAAC,EAAE;QAC9F;YACE,EAAE,EAAE,QAAQ;YACZ,OAAO,EAAE,+JAA+J;YACxK,KAAK,EAAE,CAAC;SACT;KACF;IACD,WAAW,EAAE;QACX,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,2CAA2C,EAAE,KAAK,EAAE,4BAA4B,EAAE;QAC1I,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,kDAAkD,EAAE,KAAK,EAAE,WAAW,EAAE;KAChI;IACD,YAAY,EAAE,wBAAwB;IACtC,QAAQ,EAAE,EAAE,SAAS,EAAE,0BAA0B,EAAE,aAAa,EAAE,GAAG,EAAE;CACxE,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAqB;IACrD,0BAA0B;IAC1B,0BAA0B;IAC1B,wBAAwB;CACzB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PromptTemplate } from './types.js';
|
|
2
|
+
export declare class TemplateRegistry {
|
|
3
|
+
private readonly dir;
|
|
4
|
+
private readonly templatesPath;
|
|
5
|
+
private readonly activePath;
|
|
6
|
+
constructor(dir: string);
|
|
7
|
+
get(id: string): Promise<PromptTemplate | null>;
|
|
8
|
+
getAll(): Promise<PromptTemplate[]>;
|
|
9
|
+
save(template: PromptTemplate): Promise<void>;
|
|
10
|
+
getActive(stage: string): Promise<PromptTemplate | null>;
|
|
11
|
+
setActive(stage: string, templateId: string): Promise<void>;
|
|
12
|
+
private readActiveMap;
|
|
13
|
+
private writeActiveMapAtomic;
|
|
14
|
+
private ensureDir;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/builder/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvE,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHhC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAEP,GAAG,EAAE,MAAM;IAKlC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAK/C,MAAM,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASnC,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAOxD,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAMnD,aAAa;YAQb,oBAAoB;YAOpB,SAAS;CAKxB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFile, writeFile, appendFile, rename, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { PromptTemplateSchema } from './types.js';
|
|
5
|
+
export class TemplateRegistry {
|
|
6
|
+
dir;
|
|
7
|
+
templatesPath;
|
|
8
|
+
activePath;
|
|
9
|
+
constructor(dir) {
|
|
10
|
+
this.dir = dir;
|
|
11
|
+
this.templatesPath = join(dir, 'templates.jsonl');
|
|
12
|
+
this.activePath = join(dir, 'templates-active.json');
|
|
13
|
+
}
|
|
14
|
+
async get(id) {
|
|
15
|
+
const all = await this.getAll();
|
|
16
|
+
return all.find((t) => t.id === id) ?? null;
|
|
17
|
+
}
|
|
18
|
+
async getAll() {
|
|
19
|
+
if (!existsSync(this.templatesPath)) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const raw = await readFile(this.templatesPath, 'utf-8');
|
|
23
|
+
const lines = raw.trim().split('\n').filter(Boolean);
|
|
24
|
+
return lines.map((line) => PromptTemplateSchema.parse(JSON.parse(line)));
|
|
25
|
+
}
|
|
26
|
+
async save(template) {
|
|
27
|
+
await this.ensureDir();
|
|
28
|
+
await appendFile(this.templatesPath, JSON.stringify(template) + '\n', 'utf-8');
|
|
29
|
+
}
|
|
30
|
+
async getActive(stage) {
|
|
31
|
+
const activeMap = await this.readActiveMap();
|
|
32
|
+
const id = activeMap[stage];
|
|
33
|
+
if (!id)
|
|
34
|
+
return null;
|
|
35
|
+
return this.get(id);
|
|
36
|
+
}
|
|
37
|
+
async setActive(stage, templateId) {
|
|
38
|
+
const activeMap = await this.readActiveMap();
|
|
39
|
+
activeMap[stage] = templateId;
|
|
40
|
+
await this.writeActiveMapAtomic(activeMap);
|
|
41
|
+
}
|
|
42
|
+
async readActiveMap() {
|
|
43
|
+
if (!existsSync(this.activePath)) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const raw = await readFile(this.activePath, 'utf-8');
|
|
47
|
+
return JSON.parse(raw);
|
|
48
|
+
}
|
|
49
|
+
async writeActiveMapAtomic(map) {
|
|
50
|
+
await this.ensureDir();
|
|
51
|
+
const tmpPath = this.activePath + '.tmp';
|
|
52
|
+
await writeFile(tmpPath, JSON.stringify(map, null, 2), 'utf-8');
|
|
53
|
+
await rename(tmpPath, this.activePath);
|
|
54
|
+
}
|
|
55
|
+
async ensureDir() {
|
|
56
|
+
if (!existsSync(this.dir)) {
|
|
57
|
+
await mkdir(this.dir, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/builder/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAuB,MAAM,YAAY,CAAC;AAEvE,MAAM,OAAO,gBAAgB;IAIE;IAHZ,aAAa,CAAS;IACtB,UAAU,CAAS;IAEpC,YAA6B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;QACtC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,uBAAuB,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACpC,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACxD,MAAM,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AAC;IACnD,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,GAA2B;QAC5D,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzC,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAChE,MAAM,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../src/builder/tokenizer.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.js","sourceRoot":"","sources":["../../src/builder/tokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAE3C,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAChC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const SlotDefinitionSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
type: z.ZodEnum<["string", "entries", "artifacts", "lessons"]>;
|
|
5
|
+
required: z.ZodBoolean;
|
|
6
|
+
description: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
name: string;
|
|
9
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
10
|
+
required: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
}, {
|
|
13
|
+
name: string;
|
|
14
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
15
|
+
required: boolean;
|
|
16
|
+
description: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type SlotDefinition = z.infer<typeof SlotDefinitionSchema>;
|
|
19
|
+
export declare const TemplateSectionSchema: z.ZodObject<{
|
|
20
|
+
id: z.ZodString;
|
|
21
|
+
content: z.ZodString;
|
|
22
|
+
order: z.ZodNumber;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
id: string;
|
|
25
|
+
content: string;
|
|
26
|
+
order: number;
|
|
27
|
+
}, {
|
|
28
|
+
id: string;
|
|
29
|
+
content: string;
|
|
30
|
+
order: number;
|
|
31
|
+
}>;
|
|
32
|
+
export type TemplateSection = z.infer<typeof TemplateSectionSchema>;
|
|
33
|
+
export declare const ConstraintSchema: z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
type: z.ZodEnum<["output-format", "content-rule", "language", "consistency"]>;
|
|
36
|
+
description: z.ZodString;
|
|
37
|
+
check: z.ZodString;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
40
|
+
description: string;
|
|
41
|
+
id: string;
|
|
42
|
+
check: string;
|
|
43
|
+
}, {
|
|
44
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
45
|
+
description: string;
|
|
46
|
+
id: string;
|
|
47
|
+
check: string;
|
|
48
|
+
}>;
|
|
49
|
+
export type Constraint = z.infer<typeof ConstraintSchema>;
|
|
50
|
+
export declare const PromptTemplateSchema: z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
stage: z.ZodEnum<["generator", "reflector", "curator"]>;
|
|
53
|
+
version: z.ZodNumber;
|
|
54
|
+
slots: z.ZodArray<z.ZodObject<{
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
type: z.ZodEnum<["string", "entries", "artifacts", "lessons"]>;
|
|
57
|
+
required: z.ZodBoolean;
|
|
58
|
+
description: z.ZodString;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
name: string;
|
|
61
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
62
|
+
required: boolean;
|
|
63
|
+
description: string;
|
|
64
|
+
}, {
|
|
65
|
+
name: string;
|
|
66
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
67
|
+
required: boolean;
|
|
68
|
+
description: string;
|
|
69
|
+
}>, "many">;
|
|
70
|
+
sections: z.ZodArray<z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
content: z.ZodString;
|
|
73
|
+
order: z.ZodNumber;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
id: string;
|
|
76
|
+
content: string;
|
|
77
|
+
order: number;
|
|
78
|
+
}, {
|
|
79
|
+
id: string;
|
|
80
|
+
content: string;
|
|
81
|
+
order: number;
|
|
82
|
+
}>, "many">;
|
|
83
|
+
constraints: z.ZodArray<z.ZodObject<{
|
|
84
|
+
id: z.ZodString;
|
|
85
|
+
type: z.ZodEnum<["output-format", "content-rule", "language", "consistency"]>;
|
|
86
|
+
description: z.ZodString;
|
|
87
|
+
check: z.ZodString;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
90
|
+
description: string;
|
|
91
|
+
id: string;
|
|
92
|
+
check: string;
|
|
93
|
+
}, {
|
|
94
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
95
|
+
description: string;
|
|
96
|
+
id: string;
|
|
97
|
+
check: string;
|
|
98
|
+
}>, "many">;
|
|
99
|
+
outputSchema: z.ZodString;
|
|
100
|
+
metadata: z.ZodObject<{
|
|
101
|
+
createdAt: z.ZodString;
|
|
102
|
+
tokenEstimate: z.ZodNumber;
|
|
103
|
+
parentId: z.ZodOptional<z.ZodString>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
createdAt: string;
|
|
106
|
+
tokenEstimate: number;
|
|
107
|
+
parentId?: string | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
createdAt: string;
|
|
110
|
+
tokenEstimate: number;
|
|
111
|
+
parentId?: string | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
id: string;
|
|
115
|
+
stage: "generator" | "reflector" | "curator";
|
|
116
|
+
version: number;
|
|
117
|
+
slots: {
|
|
118
|
+
name: string;
|
|
119
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
120
|
+
required: boolean;
|
|
121
|
+
description: string;
|
|
122
|
+
}[];
|
|
123
|
+
sections: {
|
|
124
|
+
id: string;
|
|
125
|
+
content: string;
|
|
126
|
+
order: number;
|
|
127
|
+
}[];
|
|
128
|
+
constraints: {
|
|
129
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
130
|
+
description: string;
|
|
131
|
+
id: string;
|
|
132
|
+
check: string;
|
|
133
|
+
}[];
|
|
134
|
+
outputSchema: string;
|
|
135
|
+
metadata: {
|
|
136
|
+
createdAt: string;
|
|
137
|
+
tokenEstimate: number;
|
|
138
|
+
parentId?: string | undefined;
|
|
139
|
+
};
|
|
140
|
+
}, {
|
|
141
|
+
id: string;
|
|
142
|
+
stage: "generator" | "reflector" | "curator";
|
|
143
|
+
version: number;
|
|
144
|
+
slots: {
|
|
145
|
+
name: string;
|
|
146
|
+
type: "string" | "entries" | "artifacts" | "lessons";
|
|
147
|
+
required: boolean;
|
|
148
|
+
description: string;
|
|
149
|
+
}[];
|
|
150
|
+
sections: {
|
|
151
|
+
id: string;
|
|
152
|
+
content: string;
|
|
153
|
+
order: number;
|
|
154
|
+
}[];
|
|
155
|
+
constraints: {
|
|
156
|
+
type: "output-format" | "content-rule" | "language" | "consistency";
|
|
157
|
+
description: string;
|
|
158
|
+
id: string;
|
|
159
|
+
check: string;
|
|
160
|
+
}[];
|
|
161
|
+
outputSchema: string;
|
|
162
|
+
metadata: {
|
|
163
|
+
createdAt: string;
|
|
164
|
+
tokenEstimate: number;
|
|
165
|
+
parentId?: string | undefined;
|
|
166
|
+
};
|
|
167
|
+
}>;
|
|
168
|
+
export type PromptTemplate = z.infer<typeof PromptTemplateSchema>;
|
|
169
|
+
export interface RenderedPrompt {
|
|
170
|
+
text: string;
|
|
171
|
+
template: PromptTemplate;
|
|
172
|
+
constraints: Constraint[];
|
|
173
|
+
tokenEstimate: number;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builder/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;EAK/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAIhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;EAK3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const SlotDefinitionSchema = z.object({
|
|
3
|
+
name: z.string().min(1),
|
|
4
|
+
type: z.enum(['string', 'entries', 'artifacts', 'lessons']),
|
|
5
|
+
required: z.boolean(),
|
|
6
|
+
description: z.string(),
|
|
7
|
+
});
|
|
8
|
+
export const TemplateSectionSchema = z.object({
|
|
9
|
+
id: z.string().min(1),
|
|
10
|
+
content: z.string(),
|
|
11
|
+
order: z.number(),
|
|
12
|
+
});
|
|
13
|
+
export const ConstraintSchema = z.object({
|
|
14
|
+
id: z.string().min(1),
|
|
15
|
+
type: z.enum(['output-format', 'content-rule', 'language', 'consistency']),
|
|
16
|
+
description: z.string(),
|
|
17
|
+
check: z.string(),
|
|
18
|
+
});
|
|
19
|
+
export const PromptTemplateSchema = z.object({
|
|
20
|
+
id: z.string().min(1),
|
|
21
|
+
stage: z.enum(['generator', 'reflector', 'curator']),
|
|
22
|
+
version: z.number().int().positive(),
|
|
23
|
+
slots: z.array(SlotDefinitionSchema),
|
|
24
|
+
sections: z.array(TemplateSectionSchema),
|
|
25
|
+
constraints: z.array(ConstraintSchema),
|
|
26
|
+
outputSchema: z.string(),
|
|
27
|
+
metadata: z.object({
|
|
28
|
+
createdAt: z.string().datetime(),
|
|
29
|
+
tokenEstimate: z.number().nonnegative(),
|
|
30
|
+
parentId: z.string().optional(),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/builder/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC3D,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACpC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;IACxC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACtC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC;QACjB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAChC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE;QACvC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAChC,CAAC;CACH,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { PromptBuilder } from './builder/builder.js';
|
|
2
|
+
export { TemplateRegistry } from './builder/registry.js';
|
|
3
|
+
export { countTokens } from './builder/tokenizer.js';
|
|
4
|
+
export { DEFAULT_GENERATOR_TEMPLATE, DEFAULT_REFLECTOR_TEMPLATE, DEFAULT_CURATOR_TEMPLATE, ALL_DEFAULT_TEMPLATES, } from './builder/defaults.js';
|
|
5
|
+
export type { PromptTemplate, SlotDefinition, TemplateSection, Constraint, RenderedPrompt, } from './builder/types.js';
|
|
6
|
+
export { PromptTemplateSchema, SlotDefinitionSchema, TemplateSectionSchema, ConstraintSchema, } from './builder/types.js';
|
|
7
|
+
export { ConsistencyValidator } from './validator/validator.js';
|
|
8
|
+
export { checkLanguageConstraint, checkRangeConstraint } from './validator/rules.js';
|
|
9
|
+
export type { ValidationResult, ConstraintViolation, ValidationOptions, } from './validator/types.js';
|
|
10
|
+
export { RatchetOptimizer } from './optimizer/optimizer.js';
|
|
11
|
+
export { runExperiment } from './optimizer/experiment.js';
|
|
12
|
+
export { computeScore, computeEfficiency } from './optimizer/evaluator.js';
|
|
13
|
+
export type { ExperimentConfig, ExperimentResult, MetricDefinition, } from './optimizer/types.js';
|
|
14
|
+
export { validateMetric } from './optimizer/types.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACrF,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// packages/meta/src/index.ts
|
|
2
|
+
export { PromptBuilder } from './builder/builder.js';
|
|
3
|
+
export { TemplateRegistry } from './builder/registry.js';
|
|
4
|
+
export { countTokens } from './builder/tokenizer.js';
|
|
5
|
+
export { DEFAULT_GENERATOR_TEMPLATE, DEFAULT_REFLECTOR_TEMPLATE, DEFAULT_CURATOR_TEMPLATE, ALL_DEFAULT_TEMPLATES, } from './builder/defaults.js';
|
|
6
|
+
export { PromptTemplateSchema, SlotDefinitionSchema, TemplateSectionSchema, ConstraintSchema, } from './builder/types.js';
|
|
7
|
+
export { ConsistencyValidator } from './validator/validator.js';
|
|
8
|
+
export { checkLanguageConstraint, checkRangeConstraint } from './validator/rules.js';
|
|
9
|
+
export { RatchetOptimizer } from './optimizer/optimizer.js';
|
|
10
|
+
export { runExperiment } from './optimizer/experiment.js';
|
|
11
|
+
export { computeScore, computeEfficiency } from './optimizer/evaluator.js';
|
|
12
|
+
export { validateMetric } from './optimizer/types.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAOrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAM3E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MetricDefinition } from './types.js';
|
|
2
|
+
export declare function computeScore(accuracy: number, efficiency: number, metric: MetricDefinition, accuracyThreshold: number): number;
|
|
3
|
+
export declare function computeEfficiency(tokensUsed: number, baseline: number): number;
|
|
4
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/optimizer/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,gBAAgB,EACxB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAKR;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI9E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function computeScore(accuracy, efficiency, metric, accuracyThreshold) {
|
|
2
|
+
if (accuracy < accuracyThreshold) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
return metric.accuracy.weight * accuracy + metric.efficiency.weight * efficiency;
|
|
6
|
+
}
|
|
7
|
+
export function computeEfficiency(tokensUsed, baseline) {
|
|
8
|
+
if (baseline <= 0)
|
|
9
|
+
return 0;
|
|
10
|
+
if (tokensUsed >= baseline)
|
|
11
|
+
return 0;
|
|
12
|
+
return Math.min(1, (baseline - tokensUsed) / baseline);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../src/optimizer/evaluator.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,UAAkB,EAClB,MAAwB,EACxB,iBAAyB;IAEzB,IAAI,QAAQ,GAAG,iBAAiB,EAAE,CAAC;QACjC,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,QAAgB;IACpE,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC5B,IAAI,UAAU,IAAI,QAAQ;QAAE,OAAO,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LLMProvider } from '@galileodev/core';
|
|
2
|
+
import type { PromptTemplate } from '../builder/types.js';
|
|
3
|
+
import type { MetricDefinition, ExperimentResult } from './types.js';
|
|
4
|
+
interface ExperimentInput {
|
|
5
|
+
baseTemplate: PromptTemplate;
|
|
6
|
+
testInputs: Array<Record<string, unknown>>;
|
|
7
|
+
llm: LLMProvider;
|
|
8
|
+
metric: MetricDefinition;
|
|
9
|
+
directive: string;
|
|
10
|
+
accuracyThreshold: number;
|
|
11
|
+
concurrency: number;
|
|
12
|
+
failureHistory?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function runExperiment(input: ExperimentInput): Promise<ExperimentResult & {
|
|
15
|
+
variant: PromptTemplate;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=experiment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiment.d.ts","sourceRoot":"","sources":["../../src/optimizer/experiment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAcrE,UAAU,eAAe;IACvB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,GAAG;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC,CA8CnH"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ulid } from 'ulid';
|
|
3
|
+
import { countTokens } from '../builder/tokenizer.js';
|
|
4
|
+
import { computeScore, computeEfficiency } from './evaluator.js';
|
|
5
|
+
const VariantResponseSchema = z.object({
|
|
6
|
+
sections: z.array(z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
content: z.string(),
|
|
9
|
+
order: z.number(),
|
|
10
|
+
})),
|
|
11
|
+
});
|
|
12
|
+
export async function runExperiment(input) {
|
|
13
|
+
const { baseTemplate, testInputs, llm, metric, directive, accuracyThreshold, concurrency, failureHistory } = input;
|
|
14
|
+
// 1. Generate variant
|
|
15
|
+
const variantPrompt = buildVariantPrompt(baseTemplate, directive, failureHistory);
|
|
16
|
+
const variantResponse = await llm.structured(variantPrompt, VariantResponseSchema);
|
|
17
|
+
const variantId = `${baseTemplate.stage}-v${baseTemplate.version + 1}-${ulid()}`;
|
|
18
|
+
const variant = {
|
|
19
|
+
...baseTemplate,
|
|
20
|
+
id: variantId,
|
|
21
|
+
version: baseTemplate.version + 1,
|
|
22
|
+
sections: variantResponse.sections,
|
|
23
|
+
metadata: {
|
|
24
|
+
...baseTemplate.metadata,
|
|
25
|
+
createdAt: new Date().toISOString(),
|
|
26
|
+
parentId: baseTemplate.id,
|
|
27
|
+
tokenEstimate: countTokens(variantResponse.sections.map((s) => s.content).join('\n')),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
// 2. Evaluate both templates against test inputs
|
|
31
|
+
const [baseAccuracy, variantAccuracy] = await Promise.all([
|
|
32
|
+
evaluateTemplate(baseTemplate, testInputs, llm, concurrency),
|
|
33
|
+
evaluateTemplate(variant, testInputs, llm, concurrency),
|
|
34
|
+
]);
|
|
35
|
+
// 3. Compute scores
|
|
36
|
+
const variantTokens = variant.metadata.tokenEstimate;
|
|
37
|
+
const efficiency = computeEfficiency(variantTokens, metric.efficiency.baseline);
|
|
38
|
+
const score = computeScore(variantAccuracy, efficiency, metric, accuracyThreshold);
|
|
39
|
+
const tokensUsed = countTokens(variantPrompt) + variantTokens;
|
|
40
|
+
return {
|
|
41
|
+
templateId: variantId,
|
|
42
|
+
parentId: baseTemplate.id,
|
|
43
|
+
score,
|
|
44
|
+
accuracy: variantAccuracy,
|
|
45
|
+
efficiency,
|
|
46
|
+
tokensUsed,
|
|
47
|
+
reverted: false,
|
|
48
|
+
variant,
|
|
49
|
+
// suppress unused warning for baseAccuracy — kept for future use
|
|
50
|
+
...(baseAccuracy !== undefined ? {} : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function evaluateTemplate(template, testInputs, llm, concurrency) {
|
|
54
|
+
let passed = 0;
|
|
55
|
+
const chunks = chunkArray(testInputs, concurrency);
|
|
56
|
+
for (const chunk of chunks) {
|
|
57
|
+
const results = await Promise.all(chunk.map(async (input) => {
|
|
58
|
+
try {
|
|
59
|
+
const text = template.sections
|
|
60
|
+
.sort((a, b) => a.order - b.order)
|
|
61
|
+
.map((s) => {
|
|
62
|
+
let content = s.content;
|
|
63
|
+
for (const [key, value] of Object.entries(input)) {
|
|
64
|
+
content = content.replaceAll(`{{${key}}}`, String(value));
|
|
65
|
+
}
|
|
66
|
+
return content;
|
|
67
|
+
})
|
|
68
|
+
.join('\n\n');
|
|
69
|
+
await llm.structured(text, z.any());
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
passed += results.filter(Boolean).length;
|
|
77
|
+
}
|
|
78
|
+
return testInputs.length > 0 ? passed / testInputs.length : 0;
|
|
79
|
+
}
|
|
80
|
+
function buildVariantPrompt(template, directive, failureHistory) {
|
|
81
|
+
const parts = [
|
|
82
|
+
`You are optimizing a prompt template for the "${template.stage}" stage.`,
|
|
83
|
+
'',
|
|
84
|
+
'## Current Template Sections',
|
|
85
|
+
...template.sections.map((s) => `### ${s.id} (order: ${s.order})\n${s.content}`),
|
|
86
|
+
'',
|
|
87
|
+
'## Optimization Directive',
|
|
88
|
+
directive,
|
|
89
|
+
'',
|
|
90
|
+
'Generate improved sections. Keep all {{slot}} placeholders. Respond with a JSON object containing a "sections" array.',
|
|
91
|
+
];
|
|
92
|
+
if (failureHistory && failureHistory.length > 0) {
|
|
93
|
+
parts.push('', '## Previous Failed Attempts (avoid these approaches)', ...failureHistory);
|
|
94
|
+
}
|
|
95
|
+
return parts.join('\n');
|
|
96
|
+
}
|
|
97
|
+
function chunkArray(arr, size) {
|
|
98
|
+
const chunks = [];
|
|
99
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
100
|
+
chunks.push(arr.slice(i, i + size));
|
|
101
|
+
}
|
|
102
|
+
return chunks;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=experiment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiment.js","sourceRoot":"","sources":["../../src/optimizer/experiment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEjE,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;QACP,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC,CACH;CACF,CAAC,CAAC;AAaH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAsB;IACxD,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IAEnH,sBAAsB;IACtB,MAAM,aAAa,GAAG,kBAAkB,CAAC,YAAY,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAClF,MAAM,eAAe,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;I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C;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LLMProvider } from '@galileodev/core';
|
|
2
|
+
import type { ExperimentConfig, ExperimentResult } from './types.js';
|
|
3
|
+
import type { TemplateRegistry } from '../builder/registry.js';
|
|
4
|
+
export declare class RatchetOptimizer {
|
|
5
|
+
private readonly registry;
|
|
6
|
+
private readonly llm;
|
|
7
|
+
private readonly dir;
|
|
8
|
+
private readonly experimentsPath;
|
|
9
|
+
constructor(registry: TemplateRegistry, llm: LLMProvider, dir: string);
|
|
10
|
+
run(config: ExperimentConfig, testInputs: Array<Record<string, unknown>>): Promise<ExperimentResult[]>;
|
|
11
|
+
private logExperiment;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=optimizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimizer.d.ts","sourceRoot":"","sources":["../../src/optimizer/optimizer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAGtB,QAAQ,EAAE,gBAAgB,EAC1B,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM;IAKxB,GAAG,CACP,MAAM,EAAE,gBAAgB,EACxB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACzC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAiEhB,aAAa;CAO5B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { appendFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { TokenBudget } from '@galileodev/core';
|
|
4
|
+
import { validateMetric } from './types.js';
|
|
5
|
+
import { runExperiment } from './experiment.js';
|
|
6
|
+
export class RatchetOptimizer {
|
|
7
|
+
registry;
|
|
8
|
+
llm;
|
|
9
|
+
dir;
|
|
10
|
+
experimentsPath;
|
|
11
|
+
constructor(registry, llm, dir) {
|
|
12
|
+
this.registry = registry;
|
|
13
|
+
this.llm = llm;
|
|
14
|
+
this.dir = dir;
|
|
15
|
+
this.experimentsPath = join(dir, 'experiments.jsonl');
|
|
16
|
+
}
|
|
17
|
+
async run(config, testInputs) {
|
|
18
|
+
if (testInputs.length < 3) {
|
|
19
|
+
throw new Error('Not enough historical data to optimize. Run a few pipeline cycles first (need at least 3 inputs).');
|
|
20
|
+
}
|
|
21
|
+
const baseTemplate = await this.registry.getActive(config.targetStage);
|
|
22
|
+
if (!baseTemplate) {
|
|
23
|
+
throw new Error(`No active template for stage '${config.targetStage}'.`);
|
|
24
|
+
}
|
|
25
|
+
const budget = new TokenBudget(config.tokenBudget);
|
|
26
|
+
validateMetric(config.metric);
|
|
27
|
+
if (!Number.isFinite(config.accuracyThreshold) || config.accuracyThreshold < 0 || config.accuracyThreshold > 1) {
|
|
28
|
+
throw new Error('accuracyThreshold must be a finite number in [0, 1].');
|
|
29
|
+
}
|
|
30
|
+
if (!Number.isInteger(config.concurrency) || config.concurrency < 1) {
|
|
31
|
+
throw new Error('concurrency must be an integer >= 1.');
|
|
32
|
+
}
|
|
33
|
+
const results = [];
|
|
34
|
+
let currentBest = baseTemplate;
|
|
35
|
+
let bestScore = 0;
|
|
36
|
+
const failureHistory = [];
|
|
37
|
+
for (let i = 0; i < config.maxExperiments; i++) {
|
|
38
|
+
if (budget.exhausted())
|
|
39
|
+
break;
|
|
40
|
+
const result = await runExperiment({
|
|
41
|
+
baseTemplate: currentBest,
|
|
42
|
+
testInputs,
|
|
43
|
+
llm: this.llm,
|
|
44
|
+
metric: config.metric,
|
|
45
|
+
directive: config.directive,
|
|
46
|
+
accuracyThreshold: config.accuracyThreshold,
|
|
47
|
+
concurrency: config.concurrency,
|
|
48
|
+
failureHistory: failureHistory.slice(-3),
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
budget.consume(result.tokensUsed);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Budget exceeded — stop after this experiment
|
|
55
|
+
results.push({ ...result, reverted: true });
|
|
56
|
+
await this.logExperiment(result);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
if (result.score > bestScore) {
|
|
60
|
+
bestScore = result.score;
|
|
61
|
+
await this.registry.save(result.variant);
|
|
62
|
+
await this.registry.setActive(config.targetStage, result.variant.id);
|
|
63
|
+
currentBest = result.variant;
|
|
64
|
+
results.push({ ...result, reverted: false });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
failureHistory.push(`Attempt ${i + 1}: score=${result.score}, accuracy=${result.accuracy}, efficiency=${result.efficiency}`);
|
|
68
|
+
results.push({ ...result, reverted: true });
|
|
69
|
+
}
|
|
70
|
+
await this.logExperiment(result);
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
async logExperiment(result) {
|
|
75
|
+
const line = JSON.stringify({
|
|
76
|
+
...result,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
});
|
|
79
|
+
await appendFile(this.experimentsPath, line + '\n', 'utf-8');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=optimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimizer.js","sourceRoot":"","sources":["../../src/optimizer/optimizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,IAA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IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACzC,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACrE,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,KAAK,cAAc,MAAM,CAAC,QAAQ,gBAAgB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;gBAC7H,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,CAAC;YAED,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,MAAwB;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;QACH,MAAM,UAAU,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface MetricDefinition {
|
|
2
|
+
accuracy: {
|
|
3
|
+
weight: number;
|
|
4
|
+
evaluator: 'json-parse-rate' | 'constraint-pass-rate' | 'custom';
|
|
5
|
+
};
|
|
6
|
+
efficiency: {
|
|
7
|
+
weight: number;
|
|
8
|
+
baseline: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ExperimentConfig {
|
|
12
|
+
targetStage: string;
|
|
13
|
+
tokenBudget: number;
|
|
14
|
+
maxExperiments: number;
|
|
15
|
+
metric: MetricDefinition;
|
|
16
|
+
directive: string;
|
|
17
|
+
accuracyThreshold: number;
|
|
18
|
+
concurrency: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ExperimentResult {
|
|
21
|
+
templateId: string;
|
|
22
|
+
parentId: string;
|
|
23
|
+
score: number;
|
|
24
|
+
accuracy: number;
|
|
25
|
+
efficiency: number;
|
|
26
|
+
tokensUsed: number;
|
|
27
|
+
commitSha?: string;
|
|
28
|
+
reverted: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function validateMetric(metric: MetricDefinition): void;
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/optimizer/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,iBAAiB,GAAG,sBAAsB,GAAG,QAAQ,CAAC;KAClE,CAAC;IACF,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAc7D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function validateMetric(metric) {
|
|
2
|
+
if (!Number.isFinite(metric.accuracy.weight) || metric.accuracy.weight < 0) {
|
|
3
|
+
throw new Error('accuracy.weight must be a finite non-negative number.');
|
|
4
|
+
}
|
|
5
|
+
if (!Number.isFinite(metric.efficiency.weight) || metric.efficiency.weight < 0) {
|
|
6
|
+
throw new Error('efficiency.weight must be a finite non-negative number.');
|
|
7
|
+
}
|
|
8
|
+
const sum = metric.accuracy.weight + metric.efficiency.weight;
|
|
9
|
+
if (Math.abs(sum - 1.0) > 1e-6) {
|
|
10
|
+
throw new Error(`Metric weights must sum to 1.0 (got ${sum}).`);
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isFinite(metric.efficiency.baseline) || metric.efficiency.baseline <= 0) {
|
|
13
|
+
throw new Error('efficiency.baseline must be a finite positive number.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/optimizer/types.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/E,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;IAC9D,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,uCAAuC,GAAG,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC;QACpF,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ConstraintViolation } from './types.js';
|
|
2
|
+
export declare function checkLanguageConstraint(response: unknown, check: string): ConstraintViolation | null;
|
|
3
|
+
export declare function checkRangeConstraint(response: unknown, check: string): ConstraintViolation | null;
|
|
4
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/validator/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOtD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,MAAM,GACZ,mBAAmB,GAAG,IAAI,CAmB5B;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,MAAM,GACZ,mBAAmB,GAAG,IAAI,CAwB5B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function checkLanguageConstraint(response, check) {
|
|
2
|
+
const regexStr = check.replace('regex:', '');
|
|
3
|
+
const regex = new RegExp(regexStr);
|
|
4
|
+
const resp = response;
|
|
5
|
+
const artifacts = resp?.artifacts;
|
|
6
|
+
if (!artifacts || !Array.isArray(artifacts))
|
|
7
|
+
return null;
|
|
8
|
+
for (const artifact of artifacts) {
|
|
9
|
+
if (!regex.test(artifact.path)) {
|
|
10
|
+
return {
|
|
11
|
+
constraintId: '',
|
|
12
|
+
description: `Artifact path does not match pattern ${regexStr}`,
|
|
13
|
+
severity: 'error',
|
|
14
|
+
evidence: `Path '${artifact.path}' does not match ${regexStr}`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export function checkRangeConstraint(response, check) {
|
|
21
|
+
const parts = check.replace('range:', '').split(':');
|
|
22
|
+
const min = parseFloat(parts[0]);
|
|
23
|
+
const max = parseFloat(parts[1]);
|
|
24
|
+
const resp = response;
|
|
25
|
+
const entries = resp?.scoredEntries;
|
|
26
|
+
if (!entries || !Array.isArray(entries))
|
|
27
|
+
return null;
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
30
|
+
if (typeof value === 'number' && (key === 'utility' || key === 'harmfulness')) {
|
|
31
|
+
if (value < min || value > max) {
|
|
32
|
+
return {
|
|
33
|
+
constraintId: '',
|
|
34
|
+
description: `Value out of range [${min}, ${max}]`,
|
|
35
|
+
severity: 'error',
|
|
36
|
+
evidence: `${key} = ${value} is outside [${min}, ${max}]`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/validator/rules.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,uBAA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AM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,aAAa,CAAC,EAAE,CAAC;gBAC9E,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;oBAC/B,OAAO;wBACL,YAAY,EAAE,EAAE;wBAChB,WAAW,EAAE,uBAAuB,GAAG,KAAK,GAAG,GAAG;wBAClD,QAAQ,EAAE,OAAO;wBACjB,QAAQ,EAAE,GAAG,GAAG,MAAM,KAAK,gBAAgB,GAAG,KAAK,GAAG,GAAG;qBAC1D,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
violations: ConstraintViolation[];
|
|
4
|
+
checkedConstraints: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ConstraintViolation {
|
|
7
|
+
constraintId: string;
|
|
8
|
+
description: string;
|
|
9
|
+
severity: 'error' | 'warning';
|
|
10
|
+
evidence: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidationOptions {
|
|
13
|
+
maxRetries?: number;
|
|
14
|
+
llmJudge?: boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validator/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/validator/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LLMProvider } from '@galileodev/core';
|
|
2
|
+
import type { RenderedPrompt } from '../builder/types.js';
|
|
3
|
+
import type { ValidationResult, ValidationOptions } from './types.js';
|
|
4
|
+
export declare class ConsistencyValidator {
|
|
5
|
+
private readonly llm?;
|
|
6
|
+
constructor(llm?: LLMProvider | undefined);
|
|
7
|
+
validate(response: unknown, rendered: RenderedPrompt, options?: ValidationOptions): Promise<ValidationResult>;
|
|
8
|
+
private checkConstraint;
|
|
9
|
+
private llmJudge;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAuB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQ3F,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAJ,GAAG,CAAC,EAAE,WAAW,YAAA;IAExC,QAAQ,CACZ,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;YAuBd,eAAe;YA+Bf,QAAQ;CA8BvB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { checkLanguageConstraint, checkRangeConstraint } from './rules.js';
|
|
3
|
+
const LLMJudgeResponseSchema = z.object({
|
|
4
|
+
valid: z.boolean(),
|
|
5
|
+
evidence: z.string(),
|
|
6
|
+
});
|
|
7
|
+
export class ConsistencyValidator {
|
|
8
|
+
llm;
|
|
9
|
+
constructor(llm) {
|
|
10
|
+
this.llm = llm;
|
|
11
|
+
}
|
|
12
|
+
async validate(response, rendered, options = {}) {
|
|
13
|
+
const violations = [];
|
|
14
|
+
let checked = 0;
|
|
15
|
+
for (const constraint of rendered.constraints) {
|
|
16
|
+
const violation = await this.checkConstraint(constraint, response, options);
|
|
17
|
+
if (violation) {
|
|
18
|
+
violations.push({ ...violation, constraintId: constraint.id });
|
|
19
|
+
checked++;
|
|
20
|
+
}
|
|
21
|
+
else if (violation === null) {
|
|
22
|
+
checked++;
|
|
23
|
+
}
|
|
24
|
+
// undefined means skipped (not checked)
|
|
25
|
+
}
|
|
26
|
+
const errors = violations.filter((v) => v.severity === 'error');
|
|
27
|
+
return {
|
|
28
|
+
valid: errors.length === 0,
|
|
29
|
+
violations,
|
|
30
|
+
checkedConstraints: checked,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async checkConstraint(constraint, response, options) {
|
|
34
|
+
switch (constraint.type) {
|
|
35
|
+
case 'language': {
|
|
36
|
+
const result = checkLanguageConstraint(response, constraint.check);
|
|
37
|
+
return result ? { ...result, constraintId: constraint.id, description: constraint.description } : null;
|
|
38
|
+
}
|
|
39
|
+
case 'content-rule': {
|
|
40
|
+
if (constraint.check.startsWith('range:')) {
|
|
41
|
+
const result = checkRangeConstraint(response, constraint.check);
|
|
42
|
+
return result ? { ...result, constraintId: constraint.id, description: constraint.description } : null;
|
|
43
|
+
}
|
|
44
|
+
if (constraint.check === 'llm-judge') {
|
|
45
|
+
return this.llmJudge(constraint, response, options);
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
case 'consistency': {
|
|
50
|
+
return this.llmJudge(constraint, response, options);
|
|
51
|
+
}
|
|
52
|
+
case 'output-format': {
|
|
53
|
+
return null; // Handled by Zod in structured() already
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async llmJudge(constraint, response, options) {
|
|
60
|
+
if (options.llmJudge === false || !this.llm) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const prompt = [
|
|
64
|
+
`Check if this output satisfies the constraint: "${constraint.description}"`,
|
|
65
|
+
'',
|
|
66
|
+
'## Output to check',
|
|
67
|
+
JSON.stringify(response, null, 2),
|
|
68
|
+
'',
|
|
69
|
+
'Respond with {"valid": true/false, "evidence": "explanation"}',
|
|
70
|
+
].join('\n');
|
|
71
|
+
const result = await this.llm.structured(prompt, LLMJudgeResponseSchema);
|
|
72
|
+
if (!result.valid) {
|
|
73
|
+
return {
|
|
74
|
+
constraintId: constraint.id,
|
|
75
|
+
description: constraint.description,
|
|
76
|
+
severity: 'error',
|
|
77
|
+
evidence: result.evidence,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,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UAAU,CAAC,WAAW,GAAG;YAC5E,EAAE;YACF,oBAAoB;YACpB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACjC,EAAE;YACF,+DAA+D;SAChE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;QAEzE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO;gBACL,YAAY,EAAE,UAAU,CAAC,EAAE;gBAC3B,WAAW,EAAE,UAAU,CAAC,WAAW;gBACnC,QAAQ,EAAE,OAAO;gBACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galileodev/meta",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "vitest run"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@galileodev/core": "*",
|
|
23
|
+
"zod": "^3.24.0",
|
|
24
|
+
"ulid": "^2.3.0",
|
|
25
|
+
"js-tiktoken": "^1.0.18"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^25.5.0"
|
|
29
|
+
}
|
|
30
|
+
}
|