@ericnunes/frame-code-cli 0.0.1
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 +139 -0
- package/README.md +196 -0
- package/dist/agent-runtime/AgentFacade.js +33 -0
- package/dist/agent-runtime/context/hooks/compressionHook.js +56 -0
- package/dist/agent-runtime/context/hooks/index.js +5 -0
- package/dist/agent-runtime/context/project-rules/loader.js +72 -0
- package/dist/agent-runtime/context/system-prompts/index.js +5 -0
- package/dist/agent-runtime/context/system-prompts/loader.js +88 -0
- package/dist/agent-runtime/flows/templates/ReactAgentFlow.js +49 -0
- package/dist/agent-runtime/index.js +18 -0
- package/dist/agent-runtime/registry/AgentRegistry.js +93 -0
- package/dist/agent-runtime/registry/agentParser.js +515 -0
- package/dist/agent-runtime/registry/enums/agentType.enum.js +8 -0
- package/dist/agent-runtime/registry/index.js +20 -0
- package/dist/agent-runtime/registry/initialization.js +53 -0
- package/dist/agent-runtime/registry/interfaces/agentDependencies.interface.js +2 -0
- package/dist/agent-runtime/registry/interfaces/agentMetadata.interface.js +2 -0
- package/dist/agent-runtime/registry/interfaces/agentRegistry.interface.js +2 -0
- package/dist/app/bootstrap.js +22 -0
- package/dist/app/cli.js +31 -0
- package/dist/app/index.js +9 -0
- package/dist/cli/commands/autonomous.js +181 -0
- package/dist/cli/commands/index.js +11 -0
- package/dist/cli/commands/interactive.js +172 -0
- package/dist/cli/commands/memory.js +149 -0
- package/dist/cli/commands/multi-agent.js +131 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/input/images/attachments.js +173 -0
- package/dist/cli/input/images/imageInput.js +77 -0
- package/dist/cli/input/images/readImageAttachment.js +56 -0
- package/dist/cli/input/index.js +14 -0
- package/dist/cli/input/reader.js +26 -0
- package/dist/content/agents/README.md +324 -0
- package/dist/content/agents/architect.md +95 -0
- package/dist/content/agents/builder.md +85 -0
- package/dist/content/agents/code-agent.md +123 -0
- package/dist/content/agents/supervisor.md +63 -0
- package/dist/index.js +25 -0
- package/dist/infrastructure/compression/CompressionManager.js +315 -0
- package/dist/infrastructure/compression/LLMCompressionService.js +211 -0
- package/dist/infrastructure/compression/index.js +11 -0
- package/dist/infrastructure/compression/promptBuilder.js +132 -0
- package/dist/infrastructure/config/agentConfig.interface.js +2 -0
- package/dist/infrastructure/config/agentConfig.js +134 -0
- package/dist/infrastructure/config/config.interface.js +2 -0
- package/dist/infrastructure/config/config.js +112 -0
- package/dist/infrastructure/config/index.js +6 -0
- package/dist/infrastructure/logging/index.js +5 -0
- package/dist/infrastructure/logging/logger.interface.js +2 -0
- package/dist/infrastructure/logging/logger.js +33 -0
- package/dist/infrastructure/logging/raw-output-logger.js +35 -0
- package/dist/infrastructure/skills/index.js +5 -0
- package/dist/infrastructure/skills/loader.js +104 -0
- package/dist/infrastructure/telemetry/index.js +9 -0
- package/dist/infrastructure/telemetry/telemetry.interface.js +2 -0
- package/dist/infrastructure/telemetry/telemetryConfig.js +30 -0
- package/dist/infrastructure/telemetry/traceEventFormatter.js +90 -0
- package/dist/infrastructure/telemetry/traceSinkConsole.js +17 -0
- package/dist/scripts/_validate/telemetry-autonomous.js +23 -0
- package/dist/scripts/_validate/telemetry-multi-agent.js +50 -0
- package/dist/scripts/_validate/test-agents-md-dynamic-dir.js +104 -0
- package/dist/scripts/_validate/test-agents-md-injection.js +125 -0
- package/dist/scripts/_validate/test-agents-md-loader.js +71 -0
- package/dist/scripts/_validate/test-agents-md-priority.js +121 -0
- package/dist/scripts/_validate/test-chrome-mcp-agent.js +89 -0
- package/dist/tools/index.js +19 -0
- package/dist/tools/mcp/discoverer.js +95 -0
- package/dist/tools/mcp/index.js +9 -0
- package/dist/tools/mcp/loader.js +36 -0
- package/dist/tools/mcp/mcpConfig.interface.js +2 -0
- package/dist/tools/mcp/mcpMetadata.js +2 -0
- package/dist/tools/mcp/register.js +269 -0
- package/dist/tools/native/capabilities.js +155 -0
- package/dist/tools/native/file-outline.js +301 -0
- package/dist/tools/native/index.js +20 -0
- package/dist/tools/native/list-directory.js +148 -0
- package/dist/tools/native/read-image.js +140 -0
- package/dist/tools/registry/ToolInitializer.js +62 -0
- package/dist/tools/registry/index.js +11 -0
- package/dist/tools/registry/toolFilter.js +52 -0
- package/dist/tools/registry/toolRegistry.interface.js +2 -0
- package/package.json +81 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentRegistry = exports.AgentRegistry = void 0;
|
|
4
|
+
const agentParser_1 = require("./agentParser");
|
|
5
|
+
const logger_1 = require("../../infrastructure/logging/logger");
|
|
6
|
+
class AgentRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.agents = new Map();
|
|
9
|
+
}
|
|
10
|
+
static getInstance() {
|
|
11
|
+
if (!AgentRegistry.instance) {
|
|
12
|
+
AgentRegistry.instance = new AgentRegistry();
|
|
13
|
+
}
|
|
14
|
+
return AgentRegistry.instance;
|
|
15
|
+
}
|
|
16
|
+
async load() {
|
|
17
|
+
const agents = (0, agentParser_1.discoverAgents)();
|
|
18
|
+
for (const agent of agents) {
|
|
19
|
+
this.register(agent);
|
|
20
|
+
}
|
|
21
|
+
logger_1.logger.info(`[AgentRegistry] Carregados ${agents.length} agentes de .code/agents/`);
|
|
22
|
+
return agents.length;
|
|
23
|
+
}
|
|
24
|
+
register(metadata) {
|
|
25
|
+
if (this.agents.has(metadata.name)) {
|
|
26
|
+
const error = `Agent '${metadata.name}' já registrado`;
|
|
27
|
+
logger_1.logger.warn(`[AgentRegistry] ${error}`);
|
|
28
|
+
return { name: metadata.name, success: false, error };
|
|
29
|
+
}
|
|
30
|
+
this.agents.set(metadata.name, metadata);
|
|
31
|
+
logger_1.logger.debug(`[AgentRegistry] Agente registrado: ${metadata.name}`);
|
|
32
|
+
return { name: metadata.name, success: true };
|
|
33
|
+
}
|
|
34
|
+
get(name) {
|
|
35
|
+
return this.agents.get(name);
|
|
36
|
+
}
|
|
37
|
+
getMetadata(name) {
|
|
38
|
+
return this.get(name);
|
|
39
|
+
}
|
|
40
|
+
list() {
|
|
41
|
+
return Array.from(this.agents.values());
|
|
42
|
+
}
|
|
43
|
+
listSummaries() {
|
|
44
|
+
return this.list().map((metadata) => ({
|
|
45
|
+
name: metadata.name,
|
|
46
|
+
type: metadata.type,
|
|
47
|
+
description: metadata.description,
|
|
48
|
+
keywords: metadata.keywords,
|
|
49
|
+
canBeSupervisor: metadata.canBeSupervisor
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
listByType(type) {
|
|
53
|
+
return this.list().filter((a) => a.type === type);
|
|
54
|
+
}
|
|
55
|
+
listSupervisors() {
|
|
56
|
+
return this.list().filter((a) => a.canBeSupervisor);
|
|
57
|
+
}
|
|
58
|
+
searchByKeywords(keywords) {
|
|
59
|
+
return this.list().filter((agent) => keywords.some((kw) => agent.keywords.some((akw) => akw.toLowerCase().includes(kw.toLowerCase()))));
|
|
60
|
+
}
|
|
61
|
+
has(name) {
|
|
62
|
+
return this.agents.has(name);
|
|
63
|
+
}
|
|
64
|
+
count() {
|
|
65
|
+
return this.agents.size;
|
|
66
|
+
}
|
|
67
|
+
unregister(name) {
|
|
68
|
+
return this.agents.delete(name);
|
|
69
|
+
}
|
|
70
|
+
clear() {
|
|
71
|
+
this.agents.clear();
|
|
72
|
+
logger_1.logger.info('[AgentRegistry] Registro limpo');
|
|
73
|
+
}
|
|
74
|
+
async createEngine(name, telemetry) {
|
|
75
|
+
const metadata = this.get(name);
|
|
76
|
+
if (!metadata) {
|
|
77
|
+
throw new Error(`Agent '${name}' não encontrado no registro`);
|
|
78
|
+
}
|
|
79
|
+
logger_1.logger.info(`[AgentRegistry] Criando engine para: ${name}`);
|
|
80
|
+
return (0, agentParser_1.createAgentFromFlow)(metadata, telemetry);
|
|
81
|
+
}
|
|
82
|
+
getStats() {
|
|
83
|
+
const agents = this.list();
|
|
84
|
+
return {
|
|
85
|
+
total: agents.length,
|
|
86
|
+
mainAgents: agents.filter((a) => a.type === 'main-agent').length,
|
|
87
|
+
subAgents: agents.filter((a) => a.type === 'sub-agent').length,
|
|
88
|
+
supervisors: agents.filter((a) => a.canBeSupervisor).length
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.AgentRegistry = AgentRegistry;
|
|
93
|
+
exports.agentRegistry = AgentRegistry.getInstance();
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.parseAgentFile = parseAgentFile;
|
|
37
|
+
exports.discoverAgents = discoverAgents;
|
|
38
|
+
exports.createAgentFromFlow = createAgentFromFlow;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
42
|
+
const ReactAgentFlow_1 = require("../flows/templates/ReactAgentFlow");
|
|
43
|
+
const AgentRegistry_1 = require("./AgentRegistry");
|
|
44
|
+
const tools_1 = require("../../tools");
|
|
45
|
+
const config_1 = require("../../infrastructure/config");
|
|
46
|
+
const agentConfig_1 = require("../../infrastructure/config/agentConfig");
|
|
47
|
+
const compression_1 = require("../../infrastructure/compression");
|
|
48
|
+
const compressionHook_1 = require("../context/hooks/compressionHook");
|
|
49
|
+
const loader_1 = require("../context/system-prompts/loader");
|
|
50
|
+
const loader_2 = require("../context/project-rules/loader");
|
|
51
|
+
const logger_1 = require("../../infrastructure/logging/logger");
|
|
52
|
+
const loader_3 = require("../../tools/mcp/loader");
|
|
53
|
+
function parseAgentFile(filePath) {
|
|
54
|
+
try {
|
|
55
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
56
|
+
const lines = content.split('\n');
|
|
57
|
+
if (lines[0].trim() !== '---') {
|
|
58
|
+
logger_1.logger.warn('[agentFormatter] Arquivo sem frontmatter: ' + filePath);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const frontmatter = {};
|
|
62
|
+
let i = 1;
|
|
63
|
+
for (; i < lines.length; i++) {
|
|
64
|
+
if (lines[i].trim() === '---')
|
|
65
|
+
break;
|
|
66
|
+
const colonIndex = lines[i].indexOf(':');
|
|
67
|
+
if (colonIndex === -1)
|
|
68
|
+
continue;
|
|
69
|
+
const key = lines[i].substring(0, colonIndex).trim();
|
|
70
|
+
const valuePart = lines[i].substring(colonIndex + 1).trim();
|
|
71
|
+
if (valuePart === '|' || valuePart.startsWith('| ')) {
|
|
72
|
+
const multilineLines = [];
|
|
73
|
+
i++;
|
|
74
|
+
let baseIndent = 0;
|
|
75
|
+
while (i < lines.length && lines[i].trim() !== '---') {
|
|
76
|
+
const line = lines[i];
|
|
77
|
+
if (line.match(/^\s*[a-zA-Z_]+:/)) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
if (line.trim() === '') {
|
|
81
|
+
multilineLines.push('');
|
|
82
|
+
i++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (baseIndent === 0 && line.trim() !== '') {
|
|
86
|
+
const match = line.match(/^(\s+)/);
|
|
87
|
+
baseIndent = match ? match[1].length : 0;
|
|
88
|
+
}
|
|
89
|
+
if (line.length >= baseIndent) {
|
|
90
|
+
multilineLines.push(line.substring(baseIndent));
|
|
91
|
+
}
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
i--;
|
|
95
|
+
frontmatter[key] = multilineLines.join('\n');
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (key && valuePart.length > 0) {
|
|
99
|
+
const value = valuePart;
|
|
100
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
101
|
+
const arrayValue = value
|
|
102
|
+
.slice(1, -1)
|
|
103
|
+
.split(',')
|
|
104
|
+
.map((s) => s.trim().replace(/^['"]|['"]$/g, ''));
|
|
105
|
+
if (key === 'subAgents' && arrayValue.length === 1 && arrayValue[0] === 'all') {
|
|
106
|
+
frontmatter[key] = 'all';
|
|
107
|
+
}
|
|
108
|
+
else if (key === 'availableFor' && arrayValue.length === 1 && arrayValue[0] === 'all') {
|
|
109
|
+
frontmatter[key] = 'all';
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
frontmatter[key] = arrayValue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (value === 'true') {
|
|
117
|
+
frontmatter[key] = true;
|
|
118
|
+
}
|
|
119
|
+
else if (value === 'false') {
|
|
120
|
+
frontmatter[key] = false;
|
|
121
|
+
}
|
|
122
|
+
else if (value === 'all' && key === 'subAgents') {
|
|
123
|
+
frontmatter[key] = 'all';
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
frontmatter[key] = value.replace(/^['"]|['"]$/g, '');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const body = lines.slice(i + 1).join('\n').trim();
|
|
132
|
+
if (!frontmatter.name || !frontmatter.type || !frontmatter.description) {
|
|
133
|
+
logger_1.logger.error('[agentFormatter] Campos obrigatórios faltando em ' + filePath);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
let agentType = frontmatter.type;
|
|
137
|
+
if (agentType !== 'main-agent' && agentType !== 'sub-agent') {
|
|
138
|
+
logger_1.logger.warn('[agentFormatter] Type inválido em ' + filePath + ': ' + frontmatter.type);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const category = 'agents';
|
|
142
|
+
const metadata = {
|
|
143
|
+
name: frontmatter.name,
|
|
144
|
+
type: agentType,
|
|
145
|
+
canBeSupervisor: frontmatter.canBeSupervisor === true || frontmatter.canBeSupervisor === 'true',
|
|
146
|
+
description: frontmatter.description,
|
|
147
|
+
keywords: frontmatter.keywords || [],
|
|
148
|
+
tools: frontmatter.tools || [],
|
|
149
|
+
toolPolicy: frontmatter.toolPolicy,
|
|
150
|
+
subAgents: frontmatter.subAgents,
|
|
151
|
+
availableFor: frontmatter.availableFor,
|
|
152
|
+
model: frontmatter.model,
|
|
153
|
+
temperature: frontmatter.temperature ? parseFloat(frontmatter.temperature) : undefined,
|
|
154
|
+
maxTokens: frontmatter.maxTokens ? parseInt(frontmatter.maxTokens, 10) : undefined,
|
|
155
|
+
systemPromptPath: frontmatter.systemPrompt,
|
|
156
|
+
systemPrompt: body,
|
|
157
|
+
backstory: frontmatter.backstory,
|
|
158
|
+
additionalInstructions: frontmatter.additionalInstructions,
|
|
159
|
+
path: filePath,
|
|
160
|
+
category,
|
|
161
|
+
compressionEnabled: frontmatter.compressionEnabled !== undefined
|
|
162
|
+
? frontmatter.compressionEnabled === true || frontmatter.compressionEnabled === 'true'
|
|
163
|
+
: undefined,
|
|
164
|
+
customErrorHandling: frontmatter.customErrorHandling === true || frontmatter.customErrorHandling === 'true',
|
|
165
|
+
flowMode: frontmatter.flowMode,
|
|
166
|
+
useProjectRules: frontmatter.useProjectRules !== false
|
|
167
|
+
};
|
|
168
|
+
return metadata;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
logger_1.logger.error('[agentFormatter] Erro ao parsear ' + filePath + ':', error);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function discoverAgentsInDir(agentsDir) {
|
|
176
|
+
const agents = [];
|
|
177
|
+
if (!fs.existsSync(agentsDir)) {
|
|
178
|
+
return agents;
|
|
179
|
+
}
|
|
180
|
+
const entries = fs.readdirSync(agentsDir, { withFileTypes: true });
|
|
181
|
+
for (const entry of entries) {
|
|
182
|
+
if (entry.isFile() && entry.name.endsWith('.md') && entry.name !== 'README.md') {
|
|
183
|
+
const agentFile = path.join(agentsDir, entry.name);
|
|
184
|
+
const metadata = parseAgentFile(agentFile);
|
|
185
|
+
if (metadata) {
|
|
186
|
+
agents.push(metadata);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return agents;
|
|
191
|
+
}
|
|
192
|
+
function discoverAgents(agentsDir) {
|
|
193
|
+
const agents = [];
|
|
194
|
+
let builtinAgentsDir = path.join(__dirname, '../../content/agents');
|
|
195
|
+
if (!fs.existsSync(builtinAgentsDir)) {
|
|
196
|
+
try {
|
|
197
|
+
const packagePath = require.resolve('frame-code-cli/package.json');
|
|
198
|
+
const packageDir = path.dirname(packagePath);
|
|
199
|
+
builtinAgentsDir = path.join(packageDir, 'dist', 'content', 'agents');
|
|
200
|
+
if (!fs.existsSync(builtinAgentsDir)) {
|
|
201
|
+
builtinAgentsDir = path.join(packageDir, 'content', 'agents');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
builtinAgentsDir = path.join(__dirname, '../../content/agents');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
agents.push(...discoverAgentsInDir(builtinAgentsDir));
|
|
209
|
+
const customAgentsDir = path.join(agentsDir || path.join(process.cwd(), '.code'), 'agents');
|
|
210
|
+
agents.push(...discoverAgentsInDir(customAgentsDir));
|
|
211
|
+
return agents;
|
|
212
|
+
}
|
|
213
|
+
function filterToolsByPolicy(allTools, policy) {
|
|
214
|
+
if (!policy)
|
|
215
|
+
return allTools;
|
|
216
|
+
let filtered = allTools;
|
|
217
|
+
if (policy.allow && policy.allow.length > 0) {
|
|
218
|
+
filtered = filtered.filter((t) => policy.allow.includes(t.name));
|
|
219
|
+
}
|
|
220
|
+
if (policy.deny && policy.deny.length > 0) {
|
|
221
|
+
filtered = filtered.filter((t) => !policy.deny.includes(t.name));
|
|
222
|
+
}
|
|
223
|
+
return filtered;
|
|
224
|
+
}
|
|
225
|
+
function filterSubAgents(allSubAgents, subAgentsConfig, supervisorName) {
|
|
226
|
+
if (supervisorName) {
|
|
227
|
+
return allSubAgents.filter(agent => {
|
|
228
|
+
if (!agent.availableFor)
|
|
229
|
+
return true;
|
|
230
|
+
if (agent.availableFor === 'all')
|
|
231
|
+
return true;
|
|
232
|
+
return agent.availableFor.includes(supervisorName);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (!subAgentsConfig || (Array.isArray(subAgentsConfig) && subAgentsConfig.length === 0)) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
if (subAgentsConfig === 'all') {
|
|
239
|
+
return allSubAgents;
|
|
240
|
+
}
|
|
241
|
+
const allowedSet = new Set(subAgentsConfig);
|
|
242
|
+
return allSubAgents.filter(agent => allowedSet.has(agent.name));
|
|
243
|
+
}
|
|
244
|
+
function expandMcpTools(toolNames, mcpLoader, allTools) {
|
|
245
|
+
const expanded = [];
|
|
246
|
+
const mcpNamespaces = new Set();
|
|
247
|
+
for (const name of toolNames) {
|
|
248
|
+
const mcpById = mcpLoader.getMcpById(name);
|
|
249
|
+
if (mcpById) {
|
|
250
|
+
mcpNamespaces.add(mcpById.namespace);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const mcpByNs = mcpLoader.getMcpByNamespace(name);
|
|
254
|
+
if (mcpByNs.length > 0) {
|
|
255
|
+
mcpNamespaces.add(mcpByNs[0].namespace);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
expanded.push(name);
|
|
259
|
+
}
|
|
260
|
+
if (mcpNamespaces.size > 0) {
|
|
261
|
+
for (const tool of allTools) {
|
|
262
|
+
const meta = tool;
|
|
263
|
+
if (meta._mcpNamespace && mcpNamespaces.has(meta._mcpNamespace)) {
|
|
264
|
+
expanded.push(tool.name);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return [...new Set(expanded)];
|
|
269
|
+
}
|
|
270
|
+
function loadSystemPromptWithExternal(systemPromptPath, basePrompt) {
|
|
271
|
+
if (!systemPromptPath)
|
|
272
|
+
return basePrompt;
|
|
273
|
+
try {
|
|
274
|
+
const externalPrompt = loader_1.loadSystemPrompt.loadFileContent(systemPromptPath);
|
|
275
|
+
return externalPrompt + '\n\n' + basePrompt;
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
logger_1.logger.warn('[agentFormatter] Não foi possível carregar ' + systemPromptPath);
|
|
279
|
+
return basePrompt;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async function createAgentWithDefinition(metadata, telemetry) {
|
|
283
|
+
const config = await (0, config_1.loadConfig)();
|
|
284
|
+
let compressionManager;
|
|
285
|
+
if (metadata.compressionEnabled !== false && config.compression?.enabled !== false) {
|
|
286
|
+
compressionManager = new compression_1.CompressionManager({
|
|
287
|
+
...config.compression,
|
|
288
|
+
persistKey: 'agent-' + metadata.name
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
let systemPrompt = loadSystemPromptWithExternal(metadata.systemPromptPath, metadata.systemPrompt);
|
|
292
|
+
if (compressionManager) {
|
|
293
|
+
const compressionPrompt = compressionManager.getCompressionPrompt();
|
|
294
|
+
if (compressionPrompt) {
|
|
295
|
+
systemPrompt = compressionPrompt + '\n\n' + systemPrompt;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const projectRules = loader_2.loadProjectRules.load();
|
|
299
|
+
if (metadata.useProjectRules !== false && projectRules.content && projectRules.source !== 'none') {
|
|
300
|
+
const rulesSection = `## Rules Project\n\n${projectRules.content}\n\n---\n\n`;
|
|
301
|
+
systemPrompt = systemPrompt + rulesSection;
|
|
302
|
+
}
|
|
303
|
+
if (metadata.useProjectRules !== false) {
|
|
304
|
+
const directoryInstruction = `### Instrução Adicional\n\n` +
|
|
305
|
+
`Arquivo AGENTS.md ou CLAUDE.md são arquivos que contêm regras e contexto do projeto. ` +
|
|
306
|
+
`Cada diretório que você acessar, verifique se possui AGENTS.md ou CLAUDE.md para colher contexto.\n\n`;
|
|
307
|
+
systemPrompt = systemPrompt + directoryInstruction;
|
|
308
|
+
}
|
|
309
|
+
const agentConfig = (0, agentConfig_1.loadAgentConfig)(metadata.name);
|
|
310
|
+
const supportsVision = agentConfig.capabilities?.supportsVision
|
|
311
|
+
?? config.vision?.supportsVision
|
|
312
|
+
?? false;
|
|
313
|
+
const llmConfig = {
|
|
314
|
+
model: metadata.model || agentConfig.model || config.defaults?.model || 'gpt-4o-mini',
|
|
315
|
+
provider: agentConfig.provider || config.provider,
|
|
316
|
+
apiKey: agentConfig.apiKey || config.apiKey,
|
|
317
|
+
baseUrl: agentConfig.baseUrl || config.baseURL,
|
|
318
|
+
capabilities: { supportsVision },
|
|
319
|
+
defaults: {
|
|
320
|
+
maxTokens: metadata.maxTokens || agentConfig.maxTokens || config.defaults?.maxTokens,
|
|
321
|
+
maxContextTokens: agentConfig.maxContextTokens || config.defaults?.maxContextTokens,
|
|
322
|
+
temperature: metadata.temperature ?? agentConfig.temperature ?? config.defaults?.temperature,
|
|
323
|
+
topP: agentConfig.topP ?? config.defaults?.topP
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const allTools = tools_1.toolRegistry.listTools();
|
|
327
|
+
const allowedTools = filterToolsByPolicy(allTools, metadata.toolPolicy);
|
|
328
|
+
const mcpLoader = new loader_3.McpLoader();
|
|
329
|
+
const expandedToolNames = expandMcpTools(metadata.tools, mcpLoader, allTools);
|
|
330
|
+
let finalTools = expandedToolNames.length > 0
|
|
331
|
+
? allowedTools.filter((t) => expandedToolNames.includes(t.name))
|
|
332
|
+
: allowedTools;
|
|
333
|
+
if (metadata.type === 'sub-agent' && finalTools.some((t) => t.name === 'ask_user')) {
|
|
334
|
+
finalTools = finalTools.filter((t) => t.name !== 'ask_user');
|
|
335
|
+
}
|
|
336
|
+
if (!supportsVision) {
|
|
337
|
+
finalTools = finalTools.filter((t) => t.name !== 'read_image');
|
|
338
|
+
}
|
|
339
|
+
const graphDefinition = {
|
|
340
|
+
...ReactAgentFlow_1.REACT_AGENT_FLOW,
|
|
341
|
+
nodes: { ...ReactAgentFlow_1.REACT_AGENT_FLOW.nodes }
|
|
342
|
+
};
|
|
343
|
+
graphDefinition.nodes.agent = (0, frame_agent_sdk_1.createAgentNode)({
|
|
344
|
+
llm: llmConfig,
|
|
345
|
+
promptConfig: {
|
|
346
|
+
mode: 'react',
|
|
347
|
+
agentInfo: {
|
|
348
|
+
name: metadata.name,
|
|
349
|
+
goal: metadata.description,
|
|
350
|
+
backstory: metadata.backstory || systemPrompt.substring(0, 500)
|
|
351
|
+
},
|
|
352
|
+
additionalInstructions: metadata.additionalInstructions || systemPrompt,
|
|
353
|
+
tools: finalTools,
|
|
354
|
+
toolPolicy: metadata.toolPolicy
|
|
355
|
+
},
|
|
356
|
+
contextHooks: (0, compressionHook_1.createCliContextHooks)(compressionManager),
|
|
357
|
+
autoExecuteTools: false,
|
|
358
|
+
temperature: metadata.temperature ?? config.defaults?.temperature,
|
|
359
|
+
maxTokens: metadata.maxTokens || config.defaults?.maxTokens
|
|
360
|
+
});
|
|
361
|
+
if (metadata.customErrorHandling) {
|
|
362
|
+
const originalExecuteNode = graphDefinition.nodes.execute;
|
|
363
|
+
graphDefinition.nodes.execute = async (state, engine) => {
|
|
364
|
+
if (state.status === 'ERROR') {
|
|
365
|
+
logger_1.logger.warn('[' + metadata.name + '] Erro detectado, aplicando tratamento customizado');
|
|
366
|
+
}
|
|
367
|
+
return originalExecuteNode(state, engine);
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const engine = new frame_agent_sdk_1.GraphEngine(graphDefinition, telemetry ? {
|
|
371
|
+
trace: telemetry.trace,
|
|
372
|
+
telemetry: telemetry.telemetry,
|
|
373
|
+
traceContext: { agent: { id: metadata.name, label: metadata.name } }
|
|
374
|
+
} : undefined, llmConfig);
|
|
375
|
+
return { graphDefinition, engine, llmConfig };
|
|
376
|
+
}
|
|
377
|
+
async function createAgentFromFlow(metadata, telemetry, _skipSubAgents) {
|
|
378
|
+
const config = await (0, config_1.loadConfig)();
|
|
379
|
+
let compressionManager;
|
|
380
|
+
if (metadata.compressionEnabled !== false && config.compression?.enabled !== false) {
|
|
381
|
+
compressionManager = new compression_1.CompressionManager({
|
|
382
|
+
...config.compression,
|
|
383
|
+
persistKey: 'agent-' + metadata.name
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
let systemPrompt = loadSystemPromptWithExternal(metadata.systemPromptPath, metadata.systemPrompt);
|
|
387
|
+
if (compressionManager) {
|
|
388
|
+
const compressionPrompt = compressionManager.getCompressionPrompt();
|
|
389
|
+
if (compressionPrompt) {
|
|
390
|
+
systemPrompt = compressionPrompt + '\n\n' + systemPrompt;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const projectRules = loader_2.loadProjectRules.load();
|
|
394
|
+
if (metadata.useProjectRules !== false && projectRules.content && projectRules.source !== 'none') {
|
|
395
|
+
const rulesSection = `## Rules Project\n\n${projectRules.content}\n\n---\n\n`;
|
|
396
|
+
systemPrompt = systemPrompt + rulesSection;
|
|
397
|
+
}
|
|
398
|
+
if (metadata.useProjectRules !== false) {
|
|
399
|
+
const directoryInstruction = `### Instrução Adicional\n\n` +
|
|
400
|
+
`Arquivo AGENTS.md ou CLAUDE.md são arquivos que contêm regras e contexto do projeto. ` +
|
|
401
|
+
`Cada diretório que você acessar, verifique se possui AGENTS.md ou CLAUDE.md para colher contexto.\n\n`;
|
|
402
|
+
systemPrompt = systemPrompt + directoryInstruction;
|
|
403
|
+
}
|
|
404
|
+
if (metadata.type === 'main-agent' && metadata.canBeSupervisor) {
|
|
405
|
+
const registry = AgentRegistry_1.AgentRegistry.getInstance();
|
|
406
|
+
const allSubAgents = registry.listByType('sub-agent');
|
|
407
|
+
const allowedSubAgents = filterSubAgents(allSubAgents, metadata.subAgents, metadata.name);
|
|
408
|
+
if (allowedSubAgents.length > 0) {
|
|
409
|
+
const subAgentList = allowedSubAgents.map(agent => `- **${agent.name}**: ${agent.description}`).join('\n');
|
|
410
|
+
systemPrompt = systemPrompt + '\n\n## Sub-agentes Disponíveis\n\n' +
|
|
411
|
+
'Você pode chamar os seguintes sub-agentes via `call_flow`:\n\n' +
|
|
412
|
+
subAgentList + '\n\n' +
|
|
413
|
+
'Use `call_flow` com o `flowId` correspondente ao nome do sub-agente.';
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const agentConfig = (0, agentConfig_1.loadAgentConfig)(metadata.name);
|
|
417
|
+
const supportsVision = agentConfig.capabilities?.supportsVision
|
|
418
|
+
?? config.vision?.supportsVision
|
|
419
|
+
?? false;
|
|
420
|
+
const llmConfig = {
|
|
421
|
+
model: metadata.model || agentConfig.model || config.defaults?.model || 'gpt-4o-mini',
|
|
422
|
+
provider: agentConfig.provider || config.provider,
|
|
423
|
+
apiKey: agentConfig.apiKey || config.apiKey,
|
|
424
|
+
baseUrl: agentConfig.baseUrl || config.baseURL,
|
|
425
|
+
capabilities: { supportsVision },
|
|
426
|
+
defaults: {
|
|
427
|
+
maxTokens: metadata.maxTokens || agentConfig.maxTokens || config.defaults?.maxTokens,
|
|
428
|
+
maxContextTokens: agentConfig.maxContextTokens || config.defaults?.maxContextTokens,
|
|
429
|
+
temperature: metadata.temperature ?? agentConfig.temperature ?? config.defaults?.temperature,
|
|
430
|
+
topP: agentConfig.topP ?? config.defaults?.topP
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const allTools = tools_1.toolRegistry.listTools();
|
|
434
|
+
const allowedTools = filterToolsByPolicy(allTools, metadata.toolPolicy);
|
|
435
|
+
const mcpLoader = new loader_3.McpLoader();
|
|
436
|
+
const expandedToolNames = expandMcpTools(metadata.tools, mcpLoader, allTools);
|
|
437
|
+
const selectedTools = expandedToolNames.length > 0
|
|
438
|
+
? allowedTools.filter((t) => expandedToolNames.includes(t.name))
|
|
439
|
+
: allowedTools;
|
|
440
|
+
let finalTools = [...selectedTools];
|
|
441
|
+
if (metadata.type === 'sub-agent' && finalTools.some((t) => t.name === 'ask_user')) {
|
|
442
|
+
finalTools = finalTools.filter((t) => t.name !== 'ask_user');
|
|
443
|
+
}
|
|
444
|
+
if (!_skipSubAgents && metadata.type === 'main-agent') {
|
|
445
|
+
const registry = AgentRegistry_1.AgentRegistry.getInstance();
|
|
446
|
+
const allSubAgents = registry.listByType('sub-agent');
|
|
447
|
+
const allowedSubAgents = filterSubAgents(allSubAgents, metadata.subAgents, metadata.name);
|
|
448
|
+
if (allowedSubAgents.length === 0 && metadata.tools.includes('call_flow')) {
|
|
449
|
+
finalTools = selectedTools.filter((t) => t.name !== 'call_flow');
|
|
450
|
+
}
|
|
451
|
+
else if (allowedSubAgents.length > 0 && metadata.tools.includes('call_flow')) {
|
|
452
|
+
const flowRegistry = new frame_agent_sdk_1.FlowRegistryImpl();
|
|
453
|
+
for (const subAgent of allowedSubAgents) {
|
|
454
|
+
try {
|
|
455
|
+
const result = await createAgentWithDefinition(subAgent, telemetry);
|
|
456
|
+
flowRegistry.register(subAgent.name, {
|
|
457
|
+
id: subAgent.name,
|
|
458
|
+
version: '1',
|
|
459
|
+
kind: 'agentFlow',
|
|
460
|
+
graph: result.graphDefinition
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
logger_1.logger.error('[' + metadata.name + '] ✗ Erro ao criar sub-agente ' + subAgent.name + ':', error);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const flowRunner = new frame_agent_sdk_1.FlowRunnerImpl(flowRegistry, { llmConfig });
|
|
468
|
+
const callFlowTool = new frame_agent_sdk_1.CallFlowTool(flowRunner);
|
|
469
|
+
try {
|
|
470
|
+
tools_1.toolRegistry.unregister('call_flow');
|
|
471
|
+
}
|
|
472
|
+
catch (e) { }
|
|
473
|
+
tools_1.toolRegistry.register(callFlowTool);
|
|
474
|
+
finalTools = finalTools.filter((t) => t.name !== 'call_flow');
|
|
475
|
+
finalTools.push(callFlowTool);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const graphDefinition = {
|
|
479
|
+
...ReactAgentFlow_1.REACT_AGENT_FLOW,
|
|
480
|
+
nodes: { ...ReactAgentFlow_1.REACT_AGENT_FLOW.nodes }
|
|
481
|
+
};
|
|
482
|
+
graphDefinition.nodes.agent = (0, frame_agent_sdk_1.createAgentNode)({
|
|
483
|
+
llm: llmConfig,
|
|
484
|
+
promptConfig: {
|
|
485
|
+
mode: 'react',
|
|
486
|
+
agentInfo: {
|
|
487
|
+
name: metadata.name,
|
|
488
|
+
goal: metadata.description,
|
|
489
|
+
backstory: metadata.backstory || systemPrompt.substring(0, 500)
|
|
490
|
+
},
|
|
491
|
+
additionalInstructions: metadata.additionalInstructions || systemPrompt,
|
|
492
|
+
tools: finalTools,
|
|
493
|
+
toolPolicy: metadata.toolPolicy
|
|
494
|
+
},
|
|
495
|
+
contextHooks: (0, compressionHook_1.createCliContextHooks)(compressionManager),
|
|
496
|
+
autoExecuteTools: false,
|
|
497
|
+
temperature: metadata.temperature ?? config.defaults?.temperature,
|
|
498
|
+
maxTokens: metadata.maxTokens || config.defaults?.maxTokens
|
|
499
|
+
});
|
|
500
|
+
if (metadata.customErrorHandling) {
|
|
501
|
+
const originalExecuteNode = graphDefinition.nodes.execute;
|
|
502
|
+
graphDefinition.nodes.execute = async (state, engine) => {
|
|
503
|
+
if (state.status === 'ERROR') {
|
|
504
|
+
logger_1.logger.warn('[' + metadata.name + '] Erro detectado, aplicando tratamento customizado');
|
|
505
|
+
}
|
|
506
|
+
return originalExecuteNode(state, engine);
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const engine = new frame_agent_sdk_1.GraphEngine(graphDefinition, telemetry ? {
|
|
510
|
+
trace: telemetry.trace,
|
|
511
|
+
telemetry: telemetry.telemetry,
|
|
512
|
+
traceContext: { agent: { id: metadata.name, label: metadata.name } }
|
|
513
|
+
} : undefined, llmConfig);
|
|
514
|
+
return engine;
|
|
515
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentType = void 0;
|
|
4
|
+
var AgentType;
|
|
5
|
+
(function (AgentType) {
|
|
6
|
+
AgentType["MAIN_AGENT"] = "main-agent";
|
|
7
|
+
AgentType["SUB_AGENT"] = "sub-agent";
|
|
8
|
+
})(AgentType || (exports.AgentType = AgentType = {}));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentFacade = exports.AgentType = exports.listAgentsAvailable = exports.getDefaultAgent = exports.initializeAgents = exports.REACT_AGENT_FLOW = exports.createAgentFromFlow = exports.discoverAgents = exports.parseAgentFile = exports.agentRegistry = exports.AgentRegistry = void 0;
|
|
4
|
+
var AgentRegistry_1 = require("./AgentRegistry");
|
|
5
|
+
Object.defineProperty(exports, "AgentRegistry", { enumerable: true, get: function () { return AgentRegistry_1.AgentRegistry; } });
|
|
6
|
+
Object.defineProperty(exports, "agentRegistry", { enumerable: true, get: function () { return AgentRegistry_1.agentRegistry; } });
|
|
7
|
+
var agentParser_1 = require("./agentParser");
|
|
8
|
+
Object.defineProperty(exports, "parseAgentFile", { enumerable: true, get: function () { return agentParser_1.parseAgentFile; } });
|
|
9
|
+
Object.defineProperty(exports, "discoverAgents", { enumerable: true, get: function () { return agentParser_1.discoverAgents; } });
|
|
10
|
+
Object.defineProperty(exports, "createAgentFromFlow", { enumerable: true, get: function () { return agentParser_1.createAgentFromFlow; } });
|
|
11
|
+
var ReactAgentFlow_1 = require("../flows/templates/ReactAgentFlow");
|
|
12
|
+
Object.defineProperty(exports, "REACT_AGENT_FLOW", { enumerable: true, get: function () { return ReactAgentFlow_1.REACT_AGENT_FLOW; } });
|
|
13
|
+
var initialization_1 = require("./initialization");
|
|
14
|
+
Object.defineProperty(exports, "initializeAgents", { enumerable: true, get: function () { return initialization_1.initializeAgents; } });
|
|
15
|
+
Object.defineProperty(exports, "getDefaultAgent", { enumerable: true, get: function () { return initialization_1.getDefaultAgent; } });
|
|
16
|
+
Object.defineProperty(exports, "listAgentsAvailable", { enumerable: true, get: function () { return initialization_1.listAgentsAvailable; } });
|
|
17
|
+
var agentType_enum_1 = require("./enums/agentType.enum");
|
|
18
|
+
Object.defineProperty(exports, "AgentType", { enumerable: true, get: function () { return agentType_enum_1.AgentType; } });
|
|
19
|
+
var AgentFacade_1 = require("../AgentFacade");
|
|
20
|
+
Object.defineProperty(exports, "AgentFacade", { enumerable: true, get: function () { return AgentFacade_1.AgentFacade; } });
|