@ericnunes/frame-code-cli 0.0.1 → 0.0.3
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/agent-runtime/index.js +0 -1
- package/dist/agent-runtime/registry/AgentRegistry.js +108 -36
- package/dist/agent-runtime/registry/index.js +1 -11
- package/dist/app/cli.js +3 -5
- package/dist/cli/commands/autonomous.js +8 -6
- package/dist/cli/commands/interactive.js +63 -146
- package/dist/cli/commands/memory.js +247 -76
- package/dist/content/agents/README.md +36 -32
- package/dist/content/agents/architect.md +1 -1
- package/dist/content/agents/builder.md +11 -15
- package/dist/content/agents/code-agent.md +1 -95
- package/dist/index.js +0 -6
- package/dist/infrastructure/config/config.js +40 -0
- package/dist/tools/index.js +0 -2
- package/dist/tools/registry/ToolInitializer.js +15 -55
- package/dist/tools/registry/index.js +1 -7
- package/package.json +11 -23
- package/dist/agent-runtime/AgentFacade.js +0 -33
- package/dist/agent-runtime/context/hooks/compressionHook.js +0 -56
- package/dist/agent-runtime/context/hooks/index.js +0 -5
- package/dist/agent-runtime/context/project-rules/loader.js +0 -72
- package/dist/agent-runtime/context/system-prompts/index.js +0 -5
- package/dist/agent-runtime/context/system-prompts/loader.js +0 -88
- package/dist/agent-runtime/flows/templates/ReactAgentFlow.js +0 -49
- package/dist/agent-runtime/registry/agentParser.js +0 -515
- package/dist/agent-runtime/registry/enums/agentType.enum.js +0 -8
- package/dist/agent-runtime/registry/interfaces/agentDependencies.interface.js +0 -2
- package/dist/agent-runtime/registry/interfaces/agentRegistry.interface.js +0 -2
- package/dist/app/bootstrap.js +0 -22
- package/dist/app/index.js +0 -9
- package/dist/cli/commands/index.js +0 -11
- package/dist/cli/commands/multi-agent.js +0 -131
- package/dist/cli/index.js +0 -18
- package/dist/cli/input/images/imageInput.js +0 -77
- package/dist/cli/input/images/readImageAttachment.js +0 -56
- package/dist/cli/input/index.js +0 -14
- package/dist/infrastructure/compression/CompressionManager.js +0 -315
- package/dist/infrastructure/compression/LLMCompressionService.js +0 -211
- package/dist/infrastructure/compression/index.js +0 -11
- package/dist/infrastructure/compression/promptBuilder.js +0 -132
- package/dist/infrastructure/config/agentConfig.interface.js +0 -2
- package/dist/infrastructure/config/agentConfig.js +0 -134
- package/dist/infrastructure/logging/index.js +0 -5
- package/dist/infrastructure/logging/logger.interface.js +0 -2
- package/dist/infrastructure/logging/raw-output-logger.js +0 -35
- package/dist/infrastructure/skills/index.js +0 -5
- package/dist/infrastructure/skills/loader.js +0 -104
- package/dist/infrastructure/telemetry/index.js +0 -9
- package/dist/infrastructure/telemetry/telemetry.interface.js +0 -2
- package/dist/infrastructure/telemetry/telemetryConfig.js +0 -30
- package/dist/infrastructure/telemetry/traceEventFormatter.js +0 -90
- package/dist/infrastructure/telemetry/traceSinkConsole.js +0 -17
- package/dist/scripts/_validate/telemetry-autonomous.js +0 -23
- package/dist/scripts/_validate/telemetry-multi-agent.js +0 -50
- package/dist/scripts/_validate/test-agents-md-dynamic-dir.js +0 -104
- package/dist/scripts/_validate/test-agents-md-injection.js +0 -125
- package/dist/scripts/_validate/test-agents-md-loader.js +0 -71
- package/dist/scripts/_validate/test-agents-md-priority.js +0 -121
- package/dist/scripts/_validate/test-chrome-mcp-agent.js +0 -89
- package/dist/tools/mcp/discoverer.js +0 -95
- package/dist/tools/mcp/index.js +0 -9
- package/dist/tools/mcp/loader.js +0 -36
- package/dist/tools/mcp/mcpConfig.interface.js +0 -2
- package/dist/tools/mcp/mcpMetadata.js +0 -2
- package/dist/tools/mcp/register.js +0 -269
- package/dist/tools/native/capabilities.js +0 -155
- package/dist/tools/native/file-outline.js +0 -301
- package/dist/tools/native/index.js +0 -20
- package/dist/tools/native/list-directory.js +0 -148
- package/dist/tools/native/read-image.js +0 -140
- package/dist/tools/registry/toolFilter.js +0 -52
- package/dist/tools/registry/toolRegistry.interface.js +0 -2
|
@@ -1,11 +1,69 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.agentRegistry = exports.AgentRegistry = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const { createFrameRuntime } = require('@ericnunes/frame-agent-core');
|
|
40
|
+
const config_1 = require("../../infrastructure/config");
|
|
41
|
+
function resolveProfile() {
|
|
42
|
+
return process.env.AGENT_MODE === 'autonomous' ? 'ci_headless' : 'developer_exec';
|
|
43
|
+
}
|
|
44
|
+
function resolveAgentsDirs() {
|
|
45
|
+
let builtin = path.join(__dirname, '../../content/agents');
|
|
46
|
+
if (!fs.existsSync(builtin)) {
|
|
47
|
+
try {
|
|
48
|
+
const pkg = require.resolve('@ericnunes/frame-code-cli/package.json');
|
|
49
|
+
const pkgDir = path.dirname(pkg);
|
|
50
|
+
const dist = path.join(pkgDir, 'dist', 'content', 'agents');
|
|
51
|
+
const direct = path.join(pkgDir, 'content', 'agents');
|
|
52
|
+
builtin = fs.existsSync(dist) ? dist : direct;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const custom = path.join(process.cwd(), '.code', 'agents');
|
|
58
|
+
return [builtin, custom];
|
|
59
|
+
}
|
|
60
|
+
function resolveMcpConfigFile() {
|
|
61
|
+
return path.join(process.cwd(), '.code', 'mcp.json');
|
|
62
|
+
}
|
|
6
63
|
class AgentRegistry {
|
|
7
64
|
constructor() {
|
|
8
65
|
this.agents = new Map();
|
|
66
|
+
this.loaded = false;
|
|
9
67
|
}
|
|
10
68
|
static getInstance() {
|
|
11
69
|
if (!AgentRegistry.instance) {
|
|
@@ -13,79 +71,93 @@ class AgentRegistry {
|
|
|
13
71
|
}
|
|
14
72
|
return AgentRegistry.instance;
|
|
15
73
|
}
|
|
16
|
-
async
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
74
|
+
async ensureRuntimeLoaded() {
|
|
75
|
+
if (this.loaded)
|
|
76
|
+
return;
|
|
77
|
+
await (0, config_1.loadConfig)();
|
|
78
|
+
const profile = resolveProfile();
|
|
79
|
+
const agentsDirs = resolveAgentsDirs();
|
|
80
|
+
const mcpConfigFile = resolveMcpConfigFile();
|
|
81
|
+
this.runtime = await createFrameRuntime({
|
|
82
|
+
projectRoot: process.cwd(),
|
|
83
|
+
profile,
|
|
84
|
+
agents: { dirs: agentsDirs },
|
|
85
|
+
mcp: {
|
|
86
|
+
enabled: process.env.MCP_TOOLS_ENABLED !== 'false',
|
|
87
|
+
configFile: mcpConfigFile,
|
|
88
|
+
},
|
|
89
|
+
tools: {
|
|
90
|
+
allowAskUser: profile !== 'ci_headless',
|
|
91
|
+
excludedTools: [],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const summaries = this.runtime.listAgents();
|
|
95
|
+
for (const s of summaries) {
|
|
96
|
+
const meta = this.runtime.getAgentMetadata(s.name);
|
|
97
|
+
if (meta)
|
|
98
|
+
this.agents.set(s.name, meta);
|
|
29
99
|
}
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
100
|
+
this.loaded = true;
|
|
101
|
+
}
|
|
102
|
+
async load() {
|
|
103
|
+
await this.ensureRuntimeLoaded();
|
|
104
|
+
return this.agents.size;
|
|
105
|
+
}
|
|
106
|
+
register(_metadata, _options) {
|
|
107
|
+
return { name: _metadata.name, success: false, error: 'register() nao suportado no adaptador core' };
|
|
108
|
+
}
|
|
109
|
+
assertLoaded() {
|
|
110
|
+
if (!this.loaded)
|
|
111
|
+
throw new Error('AgentRegistry nao inicializado. Chame initializeAgents() primeiro.');
|
|
33
112
|
}
|
|
34
113
|
get(name) {
|
|
114
|
+
this.assertLoaded();
|
|
35
115
|
return this.agents.get(name);
|
|
36
116
|
}
|
|
37
117
|
getMetadata(name) {
|
|
38
118
|
return this.get(name);
|
|
39
119
|
}
|
|
40
120
|
list() {
|
|
121
|
+
this.assertLoaded();
|
|
41
122
|
return Array.from(this.agents.values());
|
|
42
123
|
}
|
|
43
124
|
listSummaries() {
|
|
125
|
+
this.assertLoaded();
|
|
44
126
|
return this.list().map((metadata) => ({
|
|
45
127
|
name: metadata.name,
|
|
46
128
|
type: metadata.type,
|
|
47
129
|
description: metadata.description,
|
|
48
130
|
keywords: metadata.keywords,
|
|
49
|
-
canBeSupervisor: metadata.canBeSupervisor
|
|
131
|
+
canBeSupervisor: metadata.canBeSupervisor,
|
|
50
132
|
}));
|
|
51
133
|
}
|
|
52
134
|
listByType(type) {
|
|
53
135
|
return this.list().filter((a) => a.type === type);
|
|
54
136
|
}
|
|
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
137
|
has(name) {
|
|
62
138
|
return this.agents.has(name);
|
|
63
139
|
}
|
|
64
140
|
count() {
|
|
65
141
|
return this.agents.size;
|
|
66
142
|
}
|
|
67
|
-
unregister(name) {
|
|
68
|
-
return this.agents.delete(name);
|
|
69
|
-
}
|
|
70
143
|
clear() {
|
|
71
144
|
this.agents.clear();
|
|
72
|
-
|
|
145
|
+
this.loaded = false;
|
|
73
146
|
}
|
|
74
147
|
async createEngine(name, telemetry) {
|
|
75
|
-
|
|
76
|
-
if (!
|
|
77
|
-
throw new Error(`Agent '${name}'
|
|
78
|
-
|
|
79
|
-
logger_1.logger.info(`[AgentRegistry] Criando engine para: ${name}`);
|
|
80
|
-
return (0, agentParser_1.createAgentFromFlow)(metadata, telemetry);
|
|
148
|
+
await this.ensureRuntimeLoaded();
|
|
149
|
+
if (!this.agents.has(name))
|
|
150
|
+
throw new Error(`Agent '${name}' nao encontrado no registro`);
|
|
151
|
+
return this.runtime.createEngine(name, telemetry);
|
|
81
152
|
}
|
|
82
153
|
getStats() {
|
|
154
|
+
this.assertLoaded();
|
|
83
155
|
const agents = this.list();
|
|
84
156
|
return {
|
|
85
157
|
total: agents.length,
|
|
86
158
|
mainAgents: agents.filter((a) => a.type === 'main-agent').length,
|
|
87
159
|
subAgents: agents.filter((a) => a.type === 'sub-agent').length,
|
|
88
|
-
supervisors: agents.filter((a) => a.canBeSupervisor).length
|
|
160
|
+
supervisors: agents.filter((a) => a.canBeSupervisor).length,
|
|
89
161
|
};
|
|
90
162
|
}
|
|
91
163
|
}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.listAgentsAvailable = exports.getDefaultAgent = exports.initializeAgents = exports.agentRegistry = exports.AgentRegistry = void 0;
|
|
4
4
|
var AgentRegistry_1 = require("./AgentRegistry");
|
|
5
5
|
Object.defineProperty(exports, "AgentRegistry", { enumerable: true, get: function () { return AgentRegistry_1.AgentRegistry; } });
|
|
6
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
7
|
var initialization_1 = require("./initialization");
|
|
14
8
|
Object.defineProperty(exports, "initializeAgents", { enumerable: true, get: function () { return initialization_1.initializeAgents; } });
|
|
15
9
|
Object.defineProperty(exports, "getDefaultAgent", { enumerable: true, get: function () { return initialization_1.getDefaultAgent; } });
|
|
16
10
|
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; } });
|
package/dist/app/cli.js
CHANGED
|
@@ -4,23 +4,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.program = void 0;
|
|
5
5
|
exports.runCli = runCli;
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
|
-
const interactive_1 = require("../cli/commands/interactive");
|
|
8
7
|
const autonomous_1 = require("../cli/commands/autonomous");
|
|
8
|
+
const interactive_1 = require("../cli/commands/interactive");
|
|
9
9
|
const memory_1 = require("../cli/commands/memory");
|
|
10
|
-
const multi_agent_1 = require("../cli/commands/multi-agent");
|
|
11
10
|
exports.program = new commander_1.Command()
|
|
12
11
|
.name('frame-code-cli')
|
|
13
12
|
.description('CLI para frame-code com agentes')
|
|
14
13
|
.version('0.0.1');
|
|
15
|
-
exports.program.addCommand(interactive_1.interactiveCommand);
|
|
16
14
|
exports.program.addCommand((0, autonomous_1.createAutonomousCommand)());
|
|
15
|
+
exports.program.addCommand((0, interactive_1.createInteractiveCommand)());
|
|
17
16
|
exports.program.addCommand(memory_1.memoryCommand);
|
|
18
|
-
exports.program.addCommand((0, multi_agent_1.createMultiAgentCommand)());
|
|
19
17
|
function runCli(argv = process.argv) {
|
|
20
18
|
try {
|
|
21
19
|
const nextArgv = [...argv];
|
|
22
20
|
if (nextArgv.length <= 2) {
|
|
23
|
-
nextArgv.push('
|
|
21
|
+
nextArgv.push('--help');
|
|
24
22
|
}
|
|
25
23
|
exports.program.parse(nextArgv);
|
|
26
24
|
}
|
|
@@ -5,20 +5,22 @@ exports.createAutonomousCommand = createAutonomousCommand;
|
|
|
5
5
|
const commander_1 = require("commander");
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const logger_1 = require("../../infrastructure/logging/logger");
|
|
8
|
-
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
9
8
|
const tools_1 = require("../../tools");
|
|
10
9
|
const config_1 = require("../../infrastructure/config");
|
|
11
10
|
const reader_1 = require("../input/reader");
|
|
12
|
-
const
|
|
11
|
+
const frame_agent_core_1 = require("@ericnunes/frame-agent-core");
|
|
13
12
|
const attachments_1 = require("../input/images/attachments");
|
|
14
13
|
const agent_runtime_1 = require("../../agent-runtime");
|
|
14
|
+
const STATUS_RUNNING = 'RUNNING';
|
|
15
|
+
const STATUS_FINISHED = 'FINISHED';
|
|
16
|
+
const STATUS_ERROR = 'ERROR';
|
|
15
17
|
async function processAutonomousInput(input, options) {
|
|
16
18
|
try {
|
|
17
19
|
logger_1.logger.info('[Autonomous] Iniciando processamento autônomo');
|
|
18
20
|
if (options.verbose) {
|
|
19
21
|
logger_1.logger.info(`[Autonomous] Input recebido: ${input.substring(0, 200)}...`);
|
|
20
22
|
}
|
|
21
|
-
const { trace, telemetry } =
|
|
23
|
+
const { trace, telemetry } = frame_agent_core_1.telemetry.createDefaultTelemetry();
|
|
22
24
|
const registry = agent_runtime_1.AgentRegistry.getInstance();
|
|
23
25
|
let agentName;
|
|
24
26
|
if (options.agent) {
|
|
@@ -57,15 +59,15 @@ async function processAutonomousInput(input, options) {
|
|
|
57
59
|
...(options._runId ? { runId: options._runId } : {}),
|
|
58
60
|
...(imagePaths.length ? { imagePaths, imageDetail } : {})
|
|
59
61
|
},
|
|
60
|
-
status:
|
|
62
|
+
status: STATUS_RUNNING
|
|
61
63
|
};
|
|
62
64
|
const result = await graph.execute(initialState);
|
|
63
65
|
logger_1.logger.debug(`[Autonomous] Status final: ${result.status}`);
|
|
64
66
|
logger_1.logger.debug(`[Autonomous] lastToolCall:`, result.state.lastToolCall);
|
|
65
|
-
if (result.status ===
|
|
67
|
+
if (result.status === STATUS_ERROR) {
|
|
66
68
|
throw new Error(`Erro durante execução: ${result.state.logs?.join('\n') || 'Erro desconhecido'}`);
|
|
67
69
|
}
|
|
68
|
-
if (result.status !==
|
|
70
|
+
if (result.status !== STATUS_FINISHED) {
|
|
69
71
|
logger_1.logger.warn(`[Autonomous] Status não finalizado: ${result.status}`);
|
|
70
72
|
return 'Processamento concluÃdo com status: ' + result.status;
|
|
71
73
|
}
|
|
@@ -1,172 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.interactiveCommand = void 0;
|
|
37
6
|
exports.createInteractiveCommand = createInteractiveCommand;
|
|
38
7
|
const commander_1 = require("commander");
|
|
39
|
-
const
|
|
8
|
+
const readline_1 = __importDefault(require("readline"));
|
|
40
9
|
const logger_1 = require("../../infrastructure/logging/logger");
|
|
41
|
-
const frame_agent_sdk_1 = require("@ericnunes/frame-agent-sdk");
|
|
42
10
|
const tools_1 = require("../../tools");
|
|
43
11
|
const config_1 = require("../../infrastructure/config");
|
|
44
|
-
const telemetry_1 = require("../../infrastructure/telemetry");
|
|
45
|
-
const attachments_1 = require("../input/images/attachments");
|
|
46
12
|
const agent_runtime_1 = require("../../agent-runtime");
|
|
47
|
-
|
|
13
|
+
const frame_agent_core_1 = require("@ericnunes/frame-agent-core");
|
|
14
|
+
function extractAnswer(result) {
|
|
15
|
+
const lastToolCall = result?.state?.lastToolCall;
|
|
16
|
+
if (lastToolCall?.toolName === 'final_answer' && typeof lastToolCall?.params?.answer === 'string') {
|
|
17
|
+
return lastToolCall.params.answer;
|
|
18
|
+
}
|
|
19
|
+
const lastAssistant = result?.state?.messages?.filter((m) => m.role === 'assistant').pop();
|
|
20
|
+
if (lastAssistant?.content)
|
|
21
|
+
return String(lastAssistant.content);
|
|
22
|
+
return '[sem resposta]';
|
|
23
|
+
}
|
|
48
24
|
function createInteractiveCommand() {
|
|
49
|
-
const command = new commander_1.Command('interactive')
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
.option('
|
|
53
|
-
.option('--image <path>', 'Caminho de imagem local (pode repetir)', (value, previous) => [...(previous ?? []), value], [])
|
|
54
|
-
.option('--image-detail <low|high|auto>', 'Nivel de detalhe para imagem (low|high|auto)', 'auto')
|
|
25
|
+
const command = new commander_1.Command('interactive')
|
|
26
|
+
.description('Executa o agente em modo interativo (loop de perguntas/respostas)')
|
|
27
|
+
.option('-a, --agent <name>', 'Agente a ser usado (default: primeiro main-agent encontrado)')
|
|
28
|
+
.option('-v, --verbose', 'Logs detalhados')
|
|
55
29
|
.action(async (options) => {
|
|
56
30
|
try {
|
|
57
|
-
if (interactiveExecuted) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
interactiveExecuted = true;
|
|
61
31
|
await (0, config_1.loadConfig)();
|
|
62
|
-
console.log('.frame-agent CLI');
|
|
63
|
-
console.log('==============================================');
|
|
64
|
-
console.log('Modo Chat Interativo');
|
|
65
|
-
console.log('Dica: Digite suas perguntas ou "sair" para encerrar');
|
|
66
|
-
console.log('');
|
|
67
|
-
let imagePaths = [];
|
|
68
|
-
let runId;
|
|
69
|
-
const imageDetail = options?.imageDetail ?? 'auto';
|
|
70
|
-
if (options?.image && options.image.length > 0) {
|
|
71
|
-
await (0, attachments_1.cleanupAttachmentsRoot)((0, attachments_1.getAttachmentsCleanupConfigFromEnv)());
|
|
72
|
-
const staged = await (0, attachments_1.stageImageAttachments)({ imagePaths: options.image });
|
|
73
|
-
runId = staged.runId;
|
|
74
|
-
imagePaths = staged.stagedPaths;
|
|
75
|
-
}
|
|
76
|
-
const imageHint = imagePaths.length > 0
|
|
77
|
-
? `Imagens disponiveis (paths locais):\n${imagePaths.map((p) => `- ${p}`).join('\n')}\n\nSe precisar enxergar, chame a tool read_image com source=\"path\" e path do arquivo.`
|
|
78
|
-
: '';
|
|
79
|
-
let currentState = {
|
|
80
|
-
messages: [...(imageHint ? [{ role: 'system', content: imageHint }] : [])],
|
|
81
|
-
data: {
|
|
82
|
-
...(runId ? { runId } : {}),
|
|
83
|
-
...(imagePaths.length ? { imagePaths, imageDetail } : {}),
|
|
84
|
-
},
|
|
85
|
-
status: frame_agent_sdk_1.GraphStatus.RUNNING
|
|
86
|
-
};
|
|
87
|
-
const rl = readline.createInterface({
|
|
88
|
-
input: process.stdin,
|
|
89
|
-
output: process.stdout,
|
|
90
|
-
});
|
|
91
|
-
console.log('Inicializando ferramentas...');
|
|
92
32
|
await (0, tools_1.initializeTools)();
|
|
93
|
-
|
|
94
|
-
const { trace, telemetry } = (0, telemetry_1.createCliTelemetry)();
|
|
33
|
+
await (0, agent_runtime_1.initializeAgents)();
|
|
95
34
|
const registry = agent_runtime_1.AgentRegistry.getInstance();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
35
|
+
let agentName = options.agent;
|
|
36
|
+
if (!agentName) {
|
|
37
|
+
agentName = (0, agent_runtime_1.getDefaultAgent)('code-agent');
|
|
38
|
+
}
|
|
39
|
+
const meta = registry.getMetadata(agentName);
|
|
40
|
+
if (!meta)
|
|
41
|
+
throw new Error(`Agente "${agentName}" nao encontrado.`);
|
|
42
|
+
if (meta.type !== 'main-agent')
|
|
43
|
+
throw new Error(`Agente "${agentName}" nao eh main-agent.`);
|
|
44
|
+
const { trace, telemetry } = frame_agent_core_1.telemetry.createDefaultTelemetry();
|
|
45
|
+
const engine = await registry.createEngine(agentName, { trace, telemetry });
|
|
46
|
+
logger_1.logger.info(`[Interactive] Agente: ${agentName}`);
|
|
47
|
+
logger_1.logger.info('[Interactive] Digite sua mensagem. Use "exit" para sair.');
|
|
48
|
+
let currentState;
|
|
49
|
+
const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
50
|
+
const ask = () => new Promise((resolve) => rl.question('> ', resolve));
|
|
51
|
+
while (true) {
|
|
52
|
+
const input = (await ask()).trim();
|
|
53
|
+
if (!input)
|
|
54
|
+
continue;
|
|
55
|
+
if (input.toLowerCase() === 'exit')
|
|
56
|
+
break;
|
|
104
57
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const result = await graph.execute(newState);
|
|
112
|
-
currentState.messages = result.state.messages;
|
|
113
|
-
currentState.data = result.state.data;
|
|
114
|
-
currentState.status = result.state.status;
|
|
115
|
-
if (result.status === frame_agent_sdk_1.GraphStatus.FINISHED) {
|
|
58
|
+
let result;
|
|
59
|
+
if (!currentState) {
|
|
60
|
+
result = await engine.execute({
|
|
61
|
+
messages: [{ role: 'user', content: input }],
|
|
62
|
+
status: 'RUNNING',
|
|
63
|
+
});
|
|
116
64
|
}
|
|
117
|
-
else
|
|
118
|
-
|
|
65
|
+
else {
|
|
66
|
+
result = await engine.resume(currentState, { role: 'user', content: input });
|
|
67
|
+
}
|
|
68
|
+
currentState = result?.state;
|
|
69
|
+
const answer = extractAnswer(result);
|
|
70
|
+
console.log('\n' + answer + '\n');
|
|
71
|
+
if (options.verbose) {
|
|
72
|
+
logger_1.logger.debug('[Interactive] status:', result?.status, 'state:', result?.state?.status);
|
|
119
73
|
}
|
|
120
74
|
}
|
|
121
|
-
catch (
|
|
122
|
-
logger_1.logger.error('Erro
|
|
123
|
-
console.log('\n⌠Ocorreu um erro ao processar sua solicitação.');
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
let promptActive = false;
|
|
127
|
-
const showPrompt = () => {
|
|
128
|
-
if (promptActive) {
|
|
129
|
-
return;
|
|
75
|
+
catch (err) {
|
|
76
|
+
logger_1.logger.error('[Interactive] Erro:', err?.message || err);
|
|
130
77
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const trimmedInput = input.trim();
|
|
135
|
-
if (trimmedInput.toLowerCase() === 'sair' ||
|
|
136
|
-
trimmedInput.toLowerCase() === 'exit' ||
|
|
137
|
-
trimmedInput.toLowerCase() === 'quit') {
|
|
138
|
-
console.log('Até mais! Obrigado por usar o frame-agent.');
|
|
139
|
-
rl.close();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (trimmedInput === '') {
|
|
143
|
-
showPrompt();
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
await processQuestion(trimmedInput);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
logger_1.logger.error('Erro em processQuestion:', error);
|
|
151
|
-
}
|
|
152
|
-
console.log('\n' + '='.repeat(50) + '\n');
|
|
153
|
-
showPrompt();
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
console.log('Bem-vindo ao Chat frame-agent! Como posso ajudar?');
|
|
157
|
-
showPrompt();
|
|
158
|
-
rl.on('close', () => {
|
|
159
|
-
console.log('\nSessão encerrada. Até a próxima!');
|
|
160
|
-
process.exit(0);
|
|
161
|
-
});
|
|
162
|
-
rl.removeAllListeners('line');
|
|
163
|
-
rl.removeAllListeners('question');
|
|
78
|
+
}
|
|
79
|
+
rl.close();
|
|
80
|
+
logger_1.logger.info('[Interactive] Encerrado.');
|
|
164
81
|
}
|
|
165
82
|
catch (error) {
|
|
166
|
-
logger_1.logger.error('
|
|
83
|
+
logger_1.logger.error('[Interactive] Falha:', error);
|
|
167
84
|
process.exit(1);
|
|
168
85
|
}
|
|
169
86
|
});
|
|
170
87
|
return command;
|
|
171
88
|
}
|
|
172
|
-
exports.
|
|
89
|
+
exports.default = createInteractiveCommand;
|