@cogitator-ai/self-modifying 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/LICENSE +21 -0
- package/README.md +714 -0
- package/dist/architecture-evolution/capability-analyzer.d.ts +32 -0
- package/dist/architecture-evolution/capability-analyzer.d.ts.map +1 -0
- package/dist/architecture-evolution/capability-analyzer.js +264 -0
- package/dist/architecture-evolution/capability-analyzer.js.map +1 -0
- package/dist/architecture-evolution/evolution-strategy.d.ts +29 -0
- package/dist/architecture-evolution/evolution-strategy.d.ts.map +1 -0
- package/dist/architecture-evolution/evolution-strategy.js +176 -0
- package/dist/architecture-evolution/evolution-strategy.js.map +1 -0
- package/dist/architecture-evolution/index.d.ts +5 -0
- package/dist/architecture-evolution/index.d.ts.map +1 -0
- package/dist/architecture-evolution/index.js +5 -0
- package/dist/architecture-evolution/index.js.map +1 -0
- package/dist/architecture-evolution/parameter-optimizer.d.ts +67 -0
- package/dist/architecture-evolution/parameter-optimizer.d.ts.map +1 -0
- package/dist/architecture-evolution/parameter-optimizer.js +341 -0
- package/dist/architecture-evolution/parameter-optimizer.js.map +1 -0
- package/dist/architecture-evolution/prompts.d.ts +33 -0
- package/dist/architecture-evolution/prompts.d.ts.map +1 -0
- package/dist/architecture-evolution/prompts.js +169 -0
- package/dist/architecture-evolution/prompts.js.map +1 -0
- package/dist/constraints/index.d.ts +4 -0
- package/dist/constraints/index.d.ts.map +1 -0
- package/dist/constraints/index.js +4 -0
- package/dist/constraints/index.js.map +1 -0
- package/dist/constraints/modification-validator.d.ts +26 -0
- package/dist/constraints/modification-validator.d.ts.map +1 -0
- package/dist/constraints/modification-validator.js +313 -0
- package/dist/constraints/modification-validator.js.map +1 -0
- package/dist/constraints/rollback-manager.d.ts +52 -0
- package/dist/constraints/rollback-manager.d.ts.map +1 -0
- package/dist/constraints/rollback-manager.js +113 -0
- package/dist/constraints/rollback-manager.js.map +1 -0
- package/dist/constraints/safety-constraints.d.ts +11 -0
- package/dist/constraints/safety-constraints.d.ts.map +1 -0
- package/dist/constraints/safety-constraints.js +78 -0
- package/dist/constraints/safety-constraints.js.map +1 -0
- package/dist/events/event-emitter.d.ts +12 -0
- package/dist/events/event-emitter.d.ts.map +1 -0
- package/dist/events/event-emitter.js +43 -0
- package/dist/events/event-emitter.js.map +1 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/meta-reasoning/index.d.ts +5 -0
- package/dist/meta-reasoning/index.d.ts.map +1 -0
- package/dist/meta-reasoning/index.js +5 -0
- package/dist/meta-reasoning/index.js.map +1 -0
- package/dist/meta-reasoning/meta-reasoner.d.ts +53 -0
- package/dist/meta-reasoning/meta-reasoner.d.ts.map +1 -0
- package/dist/meta-reasoning/meta-reasoner.js +261 -0
- package/dist/meta-reasoning/meta-reasoner.js.map +1 -0
- package/dist/meta-reasoning/observation-collector.d.ts +37 -0
- package/dist/meta-reasoning/observation-collector.d.ts.map +1 -0
- package/dist/meta-reasoning/observation-collector.js +123 -0
- package/dist/meta-reasoning/observation-collector.js.map +1 -0
- package/dist/meta-reasoning/prompts.d.ts +31 -0
- package/dist/meta-reasoning/prompts.d.ts.map +1 -0
- package/dist/meta-reasoning/prompts.js +96 -0
- package/dist/meta-reasoning/prompts.js.map +1 -0
- package/dist/meta-reasoning/strategy-selector.d.ts +27 -0
- package/dist/meta-reasoning/strategy-selector.d.ts.map +1 -0
- package/dist/meta-reasoning/strategy-selector.js +138 -0
- package/dist/meta-reasoning/strategy-selector.js.map +1 -0
- package/dist/self-modifying-agent.d.ts +61 -0
- package/dist/self-modifying-agent.d.ts.map +1 -0
- package/dist/self-modifying-agent.js +449 -0
- package/dist/self-modifying-agent.js.map +1 -0
- package/dist/tool-generation/gap-analyzer.d.ts +25 -0
- package/dist/tool-generation/gap-analyzer.d.ts.map +1 -0
- package/dist/tool-generation/gap-analyzer.js +153 -0
- package/dist/tool-generation/gap-analyzer.js.map +1 -0
- package/dist/tool-generation/generated-tool-store.d.ts +51 -0
- package/dist/tool-generation/generated-tool-store.d.ts.map +1 -0
- package/dist/tool-generation/generated-tool-store.js +195 -0
- package/dist/tool-generation/generated-tool-store.js.map +1 -0
- package/dist/tool-generation/index.d.ts +7 -0
- package/dist/tool-generation/index.d.ts.map +1 -0
- package/dist/tool-generation/index.js +7 -0
- package/dist/tool-generation/index.js.map +1 -0
- package/dist/tool-generation/prompts.d.ts +28 -0
- package/dist/tool-generation/prompts.d.ts.map +1 -0
- package/dist/tool-generation/prompts.js +269 -0
- package/dist/tool-generation/prompts.js.map +1 -0
- package/dist/tool-generation/tool-generator.d.ts +29 -0
- package/dist/tool-generation/tool-generator.d.ts.map +1 -0
- package/dist/tool-generation/tool-generator.js +169 -0
- package/dist/tool-generation/tool-generator.js.map +1 -0
- package/dist/tool-generation/tool-sandbox.d.ts +31 -0
- package/dist/tool-generation/tool-sandbox.d.ts.map +1 -0
- package/dist/tool-generation/tool-sandbox.js +240 -0
- package/dist/tool-generation/tool-sandbox.js.map +1 -0
- package/dist/tool-generation/tool-validator.d.ts +32 -0
- package/dist/tool-generation/tool-validator.d.ts.map +1 -0
- package/dist/tool-generation/tool-validator.js +304 -0
- package/dist/tool-generation/tool-validator.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/llm-helper.d.ts +6 -0
- package/dist/utils/llm-helper.d.ts.map +1 -0
- package/dist/utils/llm-helper.js +18 -0
- package/dist/utils/llm-helper.js.map +1 -0
- package/package.json +61 -0
- package/src/__tests__/architecture-evolution.test.ts +368 -0
- package/src/__tests__/constraints.test.ts +266 -0
- package/src/__tests__/index.test.ts +99 -0
- package/src/__tests__/meta-reasoning.test.ts +343 -0
- package/src/__tests__/tool-generation.test.ts +455 -0
- package/src/architecture-evolution/capability-analyzer.ts +337 -0
- package/src/architecture-evolution/evolution-strategy.ts +224 -0
- package/src/architecture-evolution/index.ts +26 -0
- package/src/architecture-evolution/parameter-optimizer.ts +489 -0
- package/src/architecture-evolution/prompts.ts +216 -0
- package/src/constraints/index.ts +23 -0
- package/src/constraints/modification-validator.ts +402 -0
- package/src/constraints/rollback-manager.ts +173 -0
- package/src/constraints/safety-constraints.ts +103 -0
- package/src/events/event-emitter.ts +62 -0
- package/src/events/index.ts +1 -0
- package/src/index.ts +112 -0
- package/src/meta-reasoning/index.ts +24 -0
- package/src/meta-reasoning/meta-reasoner.ts +381 -0
- package/src/meta-reasoning/observation-collector.ts +161 -0
- package/src/meta-reasoning/prompts.ts +131 -0
- package/src/meta-reasoning/strategy-selector.ts +179 -0
- package/src/self-modifying-agent.ts +585 -0
- package/src/tool-generation/gap-analyzer.ts +234 -0
- package/src/tool-generation/generated-tool-store.ts +268 -0
- package/src/tool-generation/index.ts +19 -0
- package/src/tool-generation/prompts.ts +308 -0
- package/src/tool-generation/tool-generator.ts +243 -0
- package/src/tool-generation/tool-sandbox.ts +332 -0
- package/src/tool-generation/tool-validator.ts +365 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/llm-helper.ts +24 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { GeneratedTool, GeneratedToolStore as IGeneratedToolStore } from '@cogitator-ai/types';
|
|
2
|
+
export interface ToolUsageRecord {
|
|
3
|
+
toolId: string;
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
success: boolean;
|
|
6
|
+
executionTime: number;
|
|
7
|
+
inputSummary?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ToolMetrics {
|
|
11
|
+
totalUsage: number;
|
|
12
|
+
successCount: number;
|
|
13
|
+
failureCount: number;
|
|
14
|
+
averageExecutionTime: number;
|
|
15
|
+
lastUsed: Date | null;
|
|
16
|
+
successRate: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class InMemoryGeneratedToolStore implements IGeneratedToolStore {
|
|
19
|
+
private readonly tools;
|
|
20
|
+
private readonly usageRecords;
|
|
21
|
+
private readonly maxUsageRecordsPerTool;
|
|
22
|
+
save(tool: GeneratedTool): Promise<void>;
|
|
23
|
+
get(id: string): Promise<GeneratedTool | null>;
|
|
24
|
+
getByName(name: string): Promise<GeneratedTool | null>;
|
|
25
|
+
list(filter?: {
|
|
26
|
+
status?: GeneratedTool['status'];
|
|
27
|
+
minScore?: number;
|
|
28
|
+
}): Promise<GeneratedTool[]>;
|
|
29
|
+
delete(id: string): Promise<boolean>;
|
|
30
|
+
updateStatus(id: string, status: GeneratedTool['status']): Promise<boolean>;
|
|
31
|
+
recordUsage(record: ToolUsageRecord): Promise<void>;
|
|
32
|
+
getMetrics(toolId: string): Promise<ToolMetrics | null>;
|
|
33
|
+
getTopTools(limit?: number): Promise<Array<{
|
|
34
|
+
tool: GeneratedTool;
|
|
35
|
+
metrics: ToolMetrics;
|
|
36
|
+
}>>;
|
|
37
|
+
findSimilar(description: string, limit?: number): Promise<GeneratedTool[]>;
|
|
38
|
+
promoteToActive(toolId: string): Promise<boolean>;
|
|
39
|
+
deprecate(toolId: string, reason?: string): Promise<boolean>;
|
|
40
|
+
cleanup(options: {
|
|
41
|
+
maxAge?: number;
|
|
42
|
+
minUsage?: number;
|
|
43
|
+
maxDeprecated?: number;
|
|
44
|
+
}): Promise<number>;
|
|
45
|
+
getStats(): {
|
|
46
|
+
total: number;
|
|
47
|
+
byStatus: Record<string, number>;
|
|
48
|
+
totalUsage: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=generated-tool-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-tool-store.d.ts","sourceRoot":"","sources":["../../src/tool-generation/generated-tool-store.ts"],"names":[],"mappings":"AAAA,OAAO,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Q,CAAC,GAC9B,OAAO,CAAC,OAAO,CAAC;IASb,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAmBvD,WAAW,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;IAqB9F,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAgC7E,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAajD,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAc5D,OAAO,CAAC,OAAO,EAAE;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,MAAM,CAAC;IAyCnB,QAAQ,IAAI;QACV,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,UAAU,EAAE,MAAM,CAAC;KACpB;CAeF"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export class InMemoryGeneratedToolStore {
|
|
2
|
+
tools = new Map();
|
|
3
|
+
usageRecords = new Map();
|
|
4
|
+
maxUsageRecordsPerTool = 1000;
|
|
5
|
+
async save(tool) {
|
|
6
|
+
const existing = this.tools.get(tool.id);
|
|
7
|
+
if (existing) {
|
|
8
|
+
tool.version = existing.version + 1;
|
|
9
|
+
}
|
|
10
|
+
this.tools.set(tool.id, { ...tool, updatedAt: new Date() });
|
|
11
|
+
}
|
|
12
|
+
async get(id) {
|
|
13
|
+
return this.tools.get(id) || null;
|
|
14
|
+
}
|
|
15
|
+
async getByName(name) {
|
|
16
|
+
for (const tool of this.tools.values()) {
|
|
17
|
+
if (tool.name === name && tool.status !== 'deprecated') {
|
|
18
|
+
return tool;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
async list(filter) {
|
|
24
|
+
let tools = Array.from(this.tools.values());
|
|
25
|
+
if (filter?.status) {
|
|
26
|
+
tools = tools.filter((t) => t.status === filter.status);
|
|
27
|
+
}
|
|
28
|
+
if (filter?.minScore !== undefined) {
|
|
29
|
+
tools = tools.filter((t) => t.validationScore !== undefined && t.validationScore >= filter.minScore);
|
|
30
|
+
}
|
|
31
|
+
return tools.sort((a, b) => {
|
|
32
|
+
const scoreA = a.validationScore ?? 0;
|
|
33
|
+
const scoreB = b.validationScore ?? 0;
|
|
34
|
+
return scoreB - scoreA;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async delete(id) {
|
|
38
|
+
const deleted = this.tools.delete(id);
|
|
39
|
+
this.usageRecords.delete(id);
|
|
40
|
+
return deleted;
|
|
41
|
+
}
|
|
42
|
+
async updateStatus(id, status) {
|
|
43
|
+
const tool = this.tools.get(id);
|
|
44
|
+
if (!tool)
|
|
45
|
+
return false;
|
|
46
|
+
tool.status = status;
|
|
47
|
+
tool.updatedAt = new Date();
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
async recordUsage(record) {
|
|
51
|
+
const records = this.usageRecords.get(record.toolId) || [];
|
|
52
|
+
records.push(record);
|
|
53
|
+
if (records.length > this.maxUsageRecordsPerTool) {
|
|
54
|
+
records.splice(0, records.length - this.maxUsageRecordsPerTool);
|
|
55
|
+
}
|
|
56
|
+
this.usageRecords.set(record.toolId, records);
|
|
57
|
+
const tool = this.tools.get(record.toolId);
|
|
58
|
+
if (tool) {
|
|
59
|
+
tool.usageCount = (tool.usageCount || 0) + 1;
|
|
60
|
+
tool.lastUsed = record.timestamp;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async getMetrics(toolId) {
|
|
64
|
+
const records = this.usageRecords.get(toolId);
|
|
65
|
+
if (!records || records.length === 0) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const successCount = records.filter((r) => r.success).length;
|
|
69
|
+
const totalTime = records.reduce((sum, r) => sum + r.executionTime, 0);
|
|
70
|
+
return {
|
|
71
|
+
totalUsage: records.length,
|
|
72
|
+
successCount,
|
|
73
|
+
failureCount: records.length - successCount,
|
|
74
|
+
averageExecutionTime: totalTime / records.length,
|
|
75
|
+
lastUsed: records.length > 0 ? records[records.length - 1].timestamp : null,
|
|
76
|
+
successRate: successCount / records.length,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async getTopTools(limit = 10) {
|
|
80
|
+
const result = [];
|
|
81
|
+
for (const tool of this.tools.values()) {
|
|
82
|
+
if (tool.status !== 'active')
|
|
83
|
+
continue;
|
|
84
|
+
const metrics = await this.getMetrics(tool.id);
|
|
85
|
+
if (metrics && metrics.totalUsage > 0) {
|
|
86
|
+
result.push({ tool, metrics });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return result
|
|
90
|
+
.sort((a, b) => {
|
|
91
|
+
const scoreA = a.metrics.successRate * Math.log(a.metrics.totalUsage + 1);
|
|
92
|
+
const scoreB = b.metrics.successRate * Math.log(b.metrics.totalUsage + 1);
|
|
93
|
+
return scoreB - scoreA;
|
|
94
|
+
})
|
|
95
|
+
.slice(0, limit);
|
|
96
|
+
}
|
|
97
|
+
async findSimilar(description, limit = 5) {
|
|
98
|
+
const descWords = new Set(description.toLowerCase().split(/\s+/));
|
|
99
|
+
const scored = [];
|
|
100
|
+
for (const tool of this.tools.values()) {
|
|
101
|
+
if (tool.status === 'deprecated')
|
|
102
|
+
continue;
|
|
103
|
+
const toolWords = new Set(`${tool.name} ${tool.description}`.toLowerCase().split(/\s+/));
|
|
104
|
+
let matchCount = 0;
|
|
105
|
+
for (const word of descWords) {
|
|
106
|
+
if (word.length >= 3 && toolWords.has(word)) {
|
|
107
|
+
matchCount++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (matchCount > 0) {
|
|
111
|
+
scored.push({
|
|
112
|
+
tool,
|
|
113
|
+
score: matchCount / Math.max(descWords.size, toolWords.size),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return scored
|
|
118
|
+
.sort((a, b) => b.score - a.score)
|
|
119
|
+
.slice(0, limit)
|
|
120
|
+
.map((s) => s.tool);
|
|
121
|
+
}
|
|
122
|
+
async promoteToActive(toolId) {
|
|
123
|
+
const tool = this.tools.get(toolId);
|
|
124
|
+
if (!tool)
|
|
125
|
+
return false;
|
|
126
|
+
if (tool.status !== 'validated') {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
tool.status = 'active';
|
|
130
|
+
tool.updatedAt = new Date();
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
async deprecate(toolId, reason) {
|
|
134
|
+
const tool = this.tools.get(toolId);
|
|
135
|
+
if (!tool)
|
|
136
|
+
return false;
|
|
137
|
+
tool.status = 'deprecated';
|
|
138
|
+
tool.metadata = {
|
|
139
|
+
...tool.metadata,
|
|
140
|
+
deprecationReason: reason,
|
|
141
|
+
deprecatedAt: new Date().toISOString(),
|
|
142
|
+
};
|
|
143
|
+
tool.updatedAt = new Date();
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
async cleanup(options) {
|
|
147
|
+
let removed = 0;
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
for (const [id, tool] of this.tools) {
|
|
150
|
+
if (options.maxAge && tool.createdAt) {
|
|
151
|
+
const age = now - tool.createdAt.getTime();
|
|
152
|
+
if (age > options.maxAge && tool.status !== 'active') {
|
|
153
|
+
this.tools.delete(id);
|
|
154
|
+
this.usageRecords.delete(id);
|
|
155
|
+
removed++;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (options.minUsage !== undefined) {
|
|
160
|
+
const usage = tool.usageCount || 0;
|
|
161
|
+
if (usage < options.minUsage && tool.status === 'deprecated') {
|
|
162
|
+
this.tools.delete(id);
|
|
163
|
+
this.usageRecords.delete(id);
|
|
164
|
+
removed++;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (options.maxDeprecated !== undefined) {
|
|
169
|
+
const deprecated = Array.from(this.tools.values())
|
|
170
|
+
.filter((t) => t.status === 'deprecated')
|
|
171
|
+
.sort((a, b) => (a.usageCount || 0) - (b.usageCount || 0));
|
|
172
|
+
while (deprecated.length > options.maxDeprecated) {
|
|
173
|
+
const toRemove = deprecated.shift();
|
|
174
|
+
this.tools.delete(toRemove.id);
|
|
175
|
+
this.usageRecords.delete(toRemove.id);
|
|
176
|
+
removed++;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return removed;
|
|
180
|
+
}
|
|
181
|
+
getStats() {
|
|
182
|
+
const byStatus = {};
|
|
183
|
+
let totalUsage = 0;
|
|
184
|
+
for (const tool of this.tools.values()) {
|
|
185
|
+
byStatus[tool.status] = (byStatus[tool.status] || 0) + 1;
|
|
186
|
+
totalUsage += tool.usageCount || 0;
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
total: this.tools.size,
|
|
190
|
+
byStatus,
|
|
191
|
+
totalUsage,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=generated-tool-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-tool-store.js","sourceRoot":"","sources":["../../src/tool-generation/generated-tool-store.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,0BAA0B;IACpB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACzC,YAAY,GAAG,IAAI,GAAG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AAC;QAEnB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACzD,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;QACrC,CAAC;QAED,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;YACtB,QAAQ;YACR,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { GapAnalyzer, type GapAnalyzerOptions } from './gap-analyzer';
|
|
2
|
+
export { ToolGenerator, type ToolGeneratorOptions, type GenerationResult } from './tool-generator';
|
|
3
|
+
export { ToolValidator, type ToolValidatorOptions } from './tool-validator';
|
|
4
|
+
export { ToolSandbox, DEFAULT_SANDBOX_CONFIG } from './tool-sandbox';
|
|
5
|
+
export { InMemoryGeneratedToolStore, type ToolUsageRecord, type ToolMetrics, } from './generated-tool-store';
|
|
6
|
+
export { buildGapAnalysisPrompt, buildToolGenerationPrompt, buildToolValidationPrompt, buildToolImprovementPrompt, parseGapAnalysisResponse, parseToolGenerationResponse, parseValidationResponse, TOOL_GENERATION_SYSTEM_PROMPT, } from './prompts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-generation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,0BAA0B,EAC1B,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { GapAnalyzer } from './gap-analyzer';
|
|
2
|
+
export { ToolGenerator } from './tool-generator';
|
|
3
|
+
export { ToolValidator } from './tool-validator';
|
|
4
|
+
export { ToolSandbox, DEFAULT_SANDBOX_CONFIG } from './tool-sandbox';
|
|
5
|
+
export { InMemoryGeneratedToolStore, } from './generated-tool-store';
|
|
6
|
+
export { buildGapAnalysisPrompt, buildToolGenerationPrompt, buildToolValidationPrompt, buildToolImprovementPrompt, parseGapAnalysisResponse, parseToolGenerationResponse, parseValidationResponse, TOOL_GENERATION_SYSTEM_PROMPT, } from './prompts';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-generation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2B,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAoD,MAAM,kBAAkB,CAAC;AACnG,OAAO,EAAE,aAAa,EAA6B,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,0BAA0B,GAG3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CapabilityGap, GeneratedTool, ToolValidationResult } from '@cogitator-ai/types';
|
|
2
|
+
export declare const TOOL_GENERATION_SYSTEM_PROMPT = "You are an expert TypeScript developer specializing in creating tools for AI agents.\nYour task is to generate safe, efficient, and well-typed tool implementations.\n\nCRITICAL CONSTRAINTS:\n1. Generate ONLY pure TypeScript functions - no external dependencies beyond built-in modules\n2. All generated code must be self-contained and synchronous where possible\n3. Never generate code that accesses file system, network, or system resources unless explicitly requested\n4. Always include proper error handling\n5. Use Zod for parameter validation when schemas are provided\n6. Follow the exact Tool interface structure\n\nOUTPUT FORMAT:\nReturn a JSON object with:\n{\n \"name\": \"tool_name\",\n \"description\": \"Clear description of what the tool does\",\n \"implementation\": \"// TypeScript code as a string\",\n \"parameters\": { \"type\": \"object\", \"properties\": {...}, \"required\": [...] },\n \"reasoning\": \"Why this implementation was chosen\"\n}";
|
|
3
|
+
export declare function buildGapAnalysisPrompt(userIntent: string, availableTools: Array<{
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
}>, failedAttempts?: string[]): string;
|
|
7
|
+
export declare function buildToolGenerationPrompt(gap: CapabilityGap, existingTools: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}>, constraints?: {
|
|
11
|
+
maxLines?: number;
|
|
12
|
+
allowedModules?: string[];
|
|
13
|
+
securityLevel?: 'strict' | 'moderate' | 'permissive';
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function buildToolValidationPrompt(tool: GeneratedTool, testCases: Array<{
|
|
16
|
+
input: unknown;
|
|
17
|
+
expectedBehavior: string;
|
|
18
|
+
}>): string;
|
|
19
|
+
export declare function buildToolImprovementPrompt(tool: GeneratedTool, validationResult: ToolValidationResult, iteration: number): string;
|
|
20
|
+
export declare function parseGapAnalysisResponse(response: string): {
|
|
21
|
+
hasGap: boolean;
|
|
22
|
+
gaps: CapabilityGap[];
|
|
23
|
+
canProceed: boolean;
|
|
24
|
+
alternativeApproach?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function parseToolGenerationResponse(response: string): GeneratedTool | null;
|
|
27
|
+
export declare function parseValidationResponse(response: string): ToolValidationResult | null;
|
|
28
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/tool-generation/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE9F,eAAO,MAAM,6BAA6B,88BAmBxC,CAAC;AAEH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,EAC5D,cAAc,CAAC,EAAE,MAAM,EAAE,GACxB,MAAM,CAmCR;AAED,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,aAAa,EAClB,aAAa,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,EAC3D,WAAW,CAAC,EAAE;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;CACtD,GACA,MAAM,CAoDR;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7D,MAAM,CA+BR;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,aAAa,EACnB,gBAAgB,EAAE,oBAAoB,EACtC,SAAS,EAAE,MAAM,GAChB,MAAM,CAmCR;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC1D,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CA+BA;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CA4BlF;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAoCrF"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
export const TOOL_GENERATION_SYSTEM_PROMPT = `You are an expert TypeScript developer specializing in creating tools for AI agents.
|
|
2
|
+
Your task is to generate safe, efficient, and well-typed tool implementations.
|
|
3
|
+
|
|
4
|
+
CRITICAL CONSTRAINTS:
|
|
5
|
+
1. Generate ONLY pure TypeScript functions - no external dependencies beyond built-in modules
|
|
6
|
+
2. All generated code must be self-contained and synchronous where possible
|
|
7
|
+
3. Never generate code that accesses file system, network, or system resources unless explicitly requested
|
|
8
|
+
4. Always include proper error handling
|
|
9
|
+
5. Use Zod for parameter validation when schemas are provided
|
|
10
|
+
6. Follow the exact Tool interface structure
|
|
11
|
+
|
|
12
|
+
OUTPUT FORMAT:
|
|
13
|
+
Return a JSON object with:
|
|
14
|
+
{
|
|
15
|
+
"name": "tool_name",
|
|
16
|
+
"description": "Clear description of what the tool does",
|
|
17
|
+
"implementation": "// TypeScript code as a string",
|
|
18
|
+
"parameters": { "type": "object", "properties": {...}, "required": [...] },
|
|
19
|
+
"reasoning": "Why this implementation was chosen"
|
|
20
|
+
}`;
|
|
21
|
+
export function buildGapAnalysisPrompt(userIntent, availableTools, failedAttempts) {
|
|
22
|
+
const toolList = availableTools
|
|
23
|
+
.map((t) => `- ${t.name}: ${t.description}`)
|
|
24
|
+
.join('\n');
|
|
25
|
+
const failureContext = failedAttempts?.length
|
|
26
|
+
? `\n\nPrevious failed attempts:\n${failedAttempts.map((f) => `- ${f}`).join('\n')}`
|
|
27
|
+
: '';
|
|
28
|
+
return `Analyze the following user intent and determine if any capabilities are missing from the available tools.
|
|
29
|
+
|
|
30
|
+
USER INTENT:
|
|
31
|
+
${userIntent}
|
|
32
|
+
|
|
33
|
+
AVAILABLE TOOLS:
|
|
34
|
+
${toolList}
|
|
35
|
+
${failureContext}
|
|
36
|
+
|
|
37
|
+
Respond with a JSON object:
|
|
38
|
+
{
|
|
39
|
+
"hasGap": boolean,
|
|
40
|
+
"gaps": [
|
|
41
|
+
{
|
|
42
|
+
"id": "unique_gap_id",
|
|
43
|
+
"description": "What capability is missing",
|
|
44
|
+
"requiredCapability": "Specific capability needed",
|
|
45
|
+
"suggestedToolName": "proposed_tool_name",
|
|
46
|
+
"complexity": "simple" | "moderate" | "complex",
|
|
47
|
+
"confidence": 0.0-1.0,
|
|
48
|
+
"reasoning": "Why this gap exists"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"canProceed": boolean,
|
|
52
|
+
"alternativeApproach": "If gaps exist but can still proceed, explain how"
|
|
53
|
+
}`;
|
|
54
|
+
}
|
|
55
|
+
export function buildToolGenerationPrompt(gap, existingTools, constraints) {
|
|
56
|
+
const securityRules = {
|
|
57
|
+
strict: `
|
|
58
|
+
- NO file system access
|
|
59
|
+
- NO network requests
|
|
60
|
+
- NO eval() or Function constructor
|
|
61
|
+
- NO dynamic imports
|
|
62
|
+
- NO process or child_process access
|
|
63
|
+
- ONLY pure computation`,
|
|
64
|
+
moderate: `
|
|
65
|
+
- File system access ONLY if explicitly requested
|
|
66
|
+
- Network requests ONLY to whitelisted domains
|
|
67
|
+
- NO eval() or Function constructor
|
|
68
|
+
- NO dynamic imports`,
|
|
69
|
+
permissive: `
|
|
70
|
+
- File system access allowed with path validation
|
|
71
|
+
- Network requests allowed
|
|
72
|
+
- NO eval() or Function constructor`,
|
|
73
|
+
};
|
|
74
|
+
const security = constraints?.securityLevel || 'strict';
|
|
75
|
+
const maxLines = constraints?.maxLines || 100;
|
|
76
|
+
return `Generate a TypeScript tool implementation for the following capability gap.
|
|
77
|
+
|
|
78
|
+
CAPABILITY GAP:
|
|
79
|
+
- Description: ${gap.description}
|
|
80
|
+
- Required: ${gap.requiredCapability}
|
|
81
|
+
- Suggested name: ${gap.suggestedToolName}
|
|
82
|
+
- Complexity: ${gap.complexity}
|
|
83
|
+
|
|
84
|
+
EXISTING TOOLS (avoid duplication):
|
|
85
|
+
${existingTools.map((t) => `- ${t.name}: ${t.description}`).join('\n')}
|
|
86
|
+
|
|
87
|
+
CONSTRAINTS:
|
|
88
|
+
- Maximum ${maxLines} lines of code
|
|
89
|
+
- Security level: ${security}
|
|
90
|
+
${securityRules[security]}
|
|
91
|
+
${constraints?.allowedModules ? `- Allowed modules: ${constraints.allowedModules.join(', ')}` : ''}
|
|
92
|
+
|
|
93
|
+
Generate a complete, self-contained tool following this exact structure:
|
|
94
|
+
{
|
|
95
|
+
"name": "${gap.suggestedToolName}",
|
|
96
|
+
"description": "Clear description",
|
|
97
|
+
"implementation": "async function execute(params: Params): Promise<Result> { ... }",
|
|
98
|
+
"parameters": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"properties": { ... },
|
|
101
|
+
"required": [ ... ]
|
|
102
|
+
},
|
|
103
|
+
"reasoning": "Implementation rationale"
|
|
104
|
+
}`;
|
|
105
|
+
}
|
|
106
|
+
export function buildToolValidationPrompt(tool, testCases) {
|
|
107
|
+
return `Validate the following generated tool for correctness, safety, and edge cases.
|
|
108
|
+
|
|
109
|
+
TOOL:
|
|
110
|
+
Name: ${tool.name}
|
|
111
|
+
Description: ${tool.description}
|
|
112
|
+
|
|
113
|
+
IMPLEMENTATION:
|
|
114
|
+
\`\`\`typescript
|
|
115
|
+
${tool.implementation}
|
|
116
|
+
\`\`\`
|
|
117
|
+
|
|
118
|
+
PARAMETERS:
|
|
119
|
+
${JSON.stringify(tool.parameters, null, 2)}
|
|
120
|
+
|
|
121
|
+
TEST CASES TO CONSIDER:
|
|
122
|
+
${testCases.map((tc, i) => `${i + 1}. Input: ${JSON.stringify(tc.input)} - Expected: ${tc.expectedBehavior}`).join('\n')}
|
|
123
|
+
|
|
124
|
+
Analyze and respond with:
|
|
125
|
+
{
|
|
126
|
+
"isValid": boolean,
|
|
127
|
+
"securityIssues": ["list of security concerns"],
|
|
128
|
+
"logicIssues": ["list of logic/correctness issues"],
|
|
129
|
+
"edgeCases": ["unhandled edge cases"],
|
|
130
|
+
"suggestions": ["improvement suggestions"],
|
|
131
|
+
"testResults": [
|
|
132
|
+
{ "testCase": 1, "wouldPass": boolean, "reason": "explanation" }
|
|
133
|
+
],
|
|
134
|
+
"overallScore": 0.0-1.0,
|
|
135
|
+
"recommendation": "approve" | "revise" | "reject"
|
|
136
|
+
}`;
|
|
137
|
+
}
|
|
138
|
+
export function buildToolImprovementPrompt(tool, validationResult, iteration) {
|
|
139
|
+
const issues = [
|
|
140
|
+
...validationResult.securityIssues.map((i) => `[SECURITY] ${i}`),
|
|
141
|
+
...validationResult.logicIssues.map((i) => `[LOGIC] ${i}`),
|
|
142
|
+
...validationResult.edgeCases.map((i) => `[EDGE CASE] ${i}`),
|
|
143
|
+
];
|
|
144
|
+
return `Improve the following tool based on validation feedback.
|
|
145
|
+
|
|
146
|
+
ITERATION: ${iteration}
|
|
147
|
+
|
|
148
|
+
CURRENT TOOL:
|
|
149
|
+
Name: ${tool.name}
|
|
150
|
+
Description: ${tool.description}
|
|
151
|
+
|
|
152
|
+
CURRENT IMPLEMENTATION:
|
|
153
|
+
\`\`\`typescript
|
|
154
|
+
${tool.implementation}
|
|
155
|
+
\`\`\`
|
|
156
|
+
|
|
157
|
+
ISSUES TO FIX:
|
|
158
|
+
${issues.map((i, idx) => `${idx + 1}. ${i}`).join('\n')}
|
|
159
|
+
|
|
160
|
+
SUGGESTIONS:
|
|
161
|
+
${validationResult.suggestions.map((s, idx) => `${idx + 1}. ${s}`).join('\n')}
|
|
162
|
+
|
|
163
|
+
Generate an improved implementation that addresses ALL issues.
|
|
164
|
+
Respond with the same JSON format as before:
|
|
165
|
+
{
|
|
166
|
+
"name": "${tool.name}",
|
|
167
|
+
"description": "Updated description if needed",
|
|
168
|
+
"implementation": "// Improved TypeScript code",
|
|
169
|
+
"parameters": { ... },
|
|
170
|
+
"reasoning": "What was changed and why"
|
|
171
|
+
}`;
|
|
172
|
+
}
|
|
173
|
+
export function parseGapAnalysisResponse(response) {
|
|
174
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
175
|
+
if (!jsonMatch) {
|
|
176
|
+
return { hasGap: false, gaps: [], canProceed: true };
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
180
|
+
return {
|
|
181
|
+
hasGap: Boolean(parsed.hasGap),
|
|
182
|
+
gaps: Array.isArray(parsed.gaps)
|
|
183
|
+
? parsed.gaps.map((g, idx) => ({
|
|
184
|
+
id: String(g.id || `gap_${idx}`),
|
|
185
|
+
description: String(g.description || ''),
|
|
186
|
+
requiredCapability: String(g.requiredCapability || ''),
|
|
187
|
+
suggestedToolName: String(g.suggestedToolName || `generated_tool_${idx}`),
|
|
188
|
+
complexity: (['simple', 'moderate', 'complex'].includes(String(g.complexity))
|
|
189
|
+
? g.complexity
|
|
190
|
+
: 'moderate'),
|
|
191
|
+
confidence: typeof g.confidence === 'number' ? g.confidence : 0.5,
|
|
192
|
+
reasoning: String(g.reasoning || ''),
|
|
193
|
+
}))
|
|
194
|
+
: [],
|
|
195
|
+
canProceed: Boolean(parsed.canProceed),
|
|
196
|
+
alternativeApproach: parsed.alternativeApproach
|
|
197
|
+
? String(parsed.alternativeApproach)
|
|
198
|
+
: undefined,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return { hasGap: false, gaps: [], canProceed: true };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export function parseToolGenerationResponse(response) {
|
|
206
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
207
|
+
if (!jsonMatch) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
212
|
+
if (!parsed.name || !parsed.implementation) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
id: `gen_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
217
|
+
name: String(parsed.name),
|
|
218
|
+
description: String(parsed.description || ''),
|
|
219
|
+
implementation: String(parsed.implementation),
|
|
220
|
+
parameters: parsed.parameters || { type: 'object', properties: {} },
|
|
221
|
+
createdAt: new Date(),
|
|
222
|
+
version: 1,
|
|
223
|
+
status: 'pending_validation',
|
|
224
|
+
metadata: {
|
|
225
|
+
reasoning: parsed.reasoning ? String(parsed.reasoning) : undefined,
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export function parseValidationResponse(response) {
|
|
234
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
235
|
+
if (!jsonMatch) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
240
|
+
return {
|
|
241
|
+
isValid: Boolean(parsed.isValid),
|
|
242
|
+
securityIssues: Array.isArray(parsed.securityIssues)
|
|
243
|
+
? parsed.securityIssues.map(String)
|
|
244
|
+
: [],
|
|
245
|
+
logicIssues: Array.isArray(parsed.logicIssues)
|
|
246
|
+
? parsed.logicIssues.map(String)
|
|
247
|
+
: [],
|
|
248
|
+
edgeCases: Array.isArray(parsed.edgeCases)
|
|
249
|
+
? parsed.edgeCases.map(String)
|
|
250
|
+
: [],
|
|
251
|
+
suggestions: Array.isArray(parsed.suggestions)
|
|
252
|
+
? parsed.suggestions.map(String)
|
|
253
|
+
: [],
|
|
254
|
+
testResults: Array.isArray(parsed.testResults)
|
|
255
|
+
? parsed.testResults.map((tr) => ({
|
|
256
|
+
input: tr.input,
|
|
257
|
+
output: tr.output,
|
|
258
|
+
passed: Boolean(tr.wouldPass ?? tr.passed),
|
|
259
|
+
error: tr.error ? String(tr.error) : undefined,
|
|
260
|
+
}))
|
|
261
|
+
: [],
|
|
262
|
+
overallScore: typeof parsed.overallScore === 'number' ? parsed.overallScore : 0,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/tool-generation/prompts.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,6BAA6B,GAAG;;;;;;;;;;;;;;;;;;;EAmB3C,CAAC;AAEH,MAAM,UAAU,sBAAsB,CACpC,UAAkB,EAClB,cAA4D,EAC5D,cAAyB;IAEzB,MAAM,QAAQ,GAAG,cAAc;SAC5B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;SAC3C,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,cAAc,GAAG,cAAc,EAAE,MAAM;QAC3C,CAAC,CAAC,kCAAkC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACpF,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;;EAGP,UAAU;;;EAGV,QAAQ;EACR,cAAc;;;;;;;;;;;;;;;;;;EAkBd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,EAA2B,EAAE,EAAE,CAAC,CAAC;oBACvD,KAAK,EAAE,EAAE,CAAC,KAAK;oBACf,MAAM,EAAE,EAAE,CAAC,MAAM;oBACjB,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC;oBAC1C,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;iBAC/C,CAAC,CAAC;gBACL,CAAC,CAAC,EAAE;YACN,YAAY,EAAE,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;SAChF,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Tool, LLMBackend, CapabilityGap, GeneratedTool, ToolValidationResult, ToolSelfGenerationConfig } from '@cogitator-ai/types';
|
|
2
|
+
export interface ToolGeneratorOptions {
|
|
3
|
+
llm: LLMBackend;
|
|
4
|
+
config: ToolSelfGenerationConfig;
|
|
5
|
+
}
|
|
6
|
+
export interface GenerationResult {
|
|
7
|
+
tool: GeneratedTool | null;
|
|
8
|
+
validationResult: ToolValidationResult | null;
|
|
9
|
+
iterations: number;
|
|
10
|
+
success: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class ToolGenerator {
|
|
14
|
+
private readonly llm;
|
|
15
|
+
private readonly config;
|
|
16
|
+
private readonly validator;
|
|
17
|
+
constructor(options: ToolGeneratorOptions);
|
|
18
|
+
generate(gap: CapabilityGap, existingTools: Tool[], testCases?: Array<{
|
|
19
|
+
input: unknown;
|
|
20
|
+
expectedOutput?: unknown;
|
|
21
|
+
}>): Promise<GenerationResult>;
|
|
22
|
+
generateQuick(description: string, name: string, parameters: Record<string, unknown>): Promise<GeneratedTool | null>;
|
|
23
|
+
private generateInitial;
|
|
24
|
+
private improve;
|
|
25
|
+
createExecutableTool(generated: GeneratedTool): Tool;
|
|
26
|
+
private compileImplementation;
|
|
27
|
+
private callLLM;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=tool-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-generator.d.ts","sourceRoot":"","sources":["../../src/tool-generation/tool-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAU7B,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,wBAAwB,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IAC3B,gBAAgB,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;gBAE9B,OAAO,EAAE,oBAAoB;IASnC,QAAQ,CACZ,GAAG,EAAE,aAAa,EAClB,aAAa,EAAE,IAAI,EAAE,EACrB,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,GAC9D,OAAO,CAAC,gBAAgB,CAAC;IAsEtB,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM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