@ericnunes/frame-code-cli 0.0.3 → 0.0.5
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.
|
@@ -8,19 +8,19 @@ const logger_1 = require("../../infrastructure/logging/logger");
|
|
|
8
8
|
const tools_1 = require("../../tools");
|
|
9
9
|
const config_1 = require("../../infrastructure/config");
|
|
10
10
|
const reader_1 = require("../input/reader");
|
|
11
|
-
const frame_agent_core_1 = require("@ericnunes/frame-agent-core");
|
|
12
11
|
const attachments_1 = require("../input/images/attachments");
|
|
13
12
|
const agent_runtime_1 = require("../../agent-runtime");
|
|
13
|
+
const cliTelemetry_1 = require("../../infrastructure/telemetry/cliTelemetry");
|
|
14
14
|
const STATUS_RUNNING = 'RUNNING';
|
|
15
15
|
const STATUS_FINISHED = 'FINISHED';
|
|
16
16
|
const STATUS_ERROR = 'ERROR';
|
|
17
17
|
async function processAutonomousInput(input, options) {
|
|
18
|
+
const runtimeTelemetry = (0, cliTelemetry_1.createCliTelemetry)();
|
|
18
19
|
try {
|
|
19
20
|
logger_1.logger.info('[Autonomous] Iniciando processamento autônomo');
|
|
20
21
|
if (options.verbose) {
|
|
21
22
|
logger_1.logger.info(`[Autonomous] Input recebido: ${input.substring(0, 200)}...`);
|
|
22
23
|
}
|
|
23
|
-
const { trace, telemetry } = frame_agent_core_1.telemetry.createDefaultTelemetry();
|
|
24
24
|
const registry = agent_runtime_1.AgentRegistry.getInstance();
|
|
25
25
|
let agentName;
|
|
26
26
|
if (options.agent) {
|
|
@@ -38,10 +38,7 @@ async function processAutonomousInput(input, options) {
|
|
|
38
38
|
agentName = (0, agent_runtime_1.getDefaultAgent)('code-agent');
|
|
39
39
|
logger_1.logger.info(`[Autonomous] Usando agente padrão: ${agentName}`);
|
|
40
40
|
}
|
|
41
|
-
const graph = await registry.createEngine(agentName,
|
|
42
|
-
trace,
|
|
43
|
-
telemetry
|
|
44
|
-
});
|
|
41
|
+
const graph = await registry.createEngine(agentName, runtimeTelemetry);
|
|
45
42
|
const imagePaths = options._imagePaths ?? [];
|
|
46
43
|
const imageDetail = options.imageDetail ?? 'auto';
|
|
47
44
|
const imageHint = imagePaths.length > 0
|
|
@@ -87,6 +84,9 @@ async function processAutonomousInput(input, options) {
|
|
|
87
84
|
logger_1.logger.error('[Autonomous] Erro no processamento:', error);
|
|
88
85
|
throw error;
|
|
89
86
|
}
|
|
87
|
+
finally {
|
|
88
|
+
await runtimeTelemetry.trace.flush?.();
|
|
89
|
+
}
|
|
90
90
|
}
|
|
91
91
|
function createAutonomousCommand() {
|
|
92
92
|
const command = new commander_1.Command('autonomous');
|
|
@@ -163,7 +163,7 @@ function createAutonomousCommand() {
|
|
|
163
163
|
(0, fs_1.writeFileSync)(options.logFile, logContent, 'utf-8');
|
|
164
164
|
}
|
|
165
165
|
logger_1.logger.info('[Autonomous] Processamento autônomo concluÃdo com sucesso');
|
|
166
|
-
|
|
166
|
+
return;
|
|
167
167
|
}
|
|
168
168
|
catch (error) {
|
|
169
169
|
logger_1.logger.error('[Autonomous] Erro fatal:', error);
|
|
@@ -176,7 +176,8 @@ function createAutonomousCommand() {
|
|
|
176
176
|
logger_1.logger.debug('[Autonomous] Imprimindo erro no console');
|
|
177
177
|
console.error('Erro:', errorMessage);
|
|
178
178
|
}
|
|
179
|
-
process.
|
|
179
|
+
process.exitCode = 1;
|
|
180
|
+
return;
|
|
180
181
|
}
|
|
181
182
|
});
|
|
182
183
|
return command;
|
|
@@ -10,7 +10,7 @@ const logger_1 = require("../../infrastructure/logging/logger");
|
|
|
10
10
|
const tools_1 = require("../../tools");
|
|
11
11
|
const config_1 = require("../../infrastructure/config");
|
|
12
12
|
const agent_runtime_1 = require("../../agent-runtime");
|
|
13
|
-
const
|
|
13
|
+
const cliTelemetry_1 = require("../../infrastructure/telemetry/cliTelemetry");
|
|
14
14
|
function extractAnswer(result) {
|
|
15
15
|
const lastToolCall = result?.state?.lastToolCall;
|
|
16
16
|
if (lastToolCall?.toolName === 'final_answer' && typeof lastToolCall?.params?.answer === 'string') {
|
|
@@ -41,47 +41,52 @@ function createInteractiveCommand() {
|
|
|
41
41
|
throw new Error(`Agente "${agentName}" nao encontrado.`);
|
|
42
42
|
if (meta.type !== 'main-agent')
|
|
43
43
|
throw new Error(`Agente "${agentName}" nao eh main-agent.`);
|
|
44
|
-
const
|
|
45
|
-
const engine = await registry.createEngine(agentName,
|
|
44
|
+
const runtimeTelemetry = (0, cliTelemetry_1.createCliTelemetry)();
|
|
45
|
+
const engine = await registry.createEngine(agentName, runtimeTelemetry);
|
|
46
46
|
logger_1.logger.info(`[Interactive] Agente: ${agentName}`);
|
|
47
47
|
logger_1.logger.info('[Interactive] Digite sua mensagem. Use "exit" para sair.');
|
|
48
48
|
let currentState;
|
|
49
49
|
const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
try {
|
|
51
|
+
const ask = () => new Promise((resolve) => rl.question('> ', resolve));
|
|
52
|
+
while (true) {
|
|
53
|
+
const input = (await ask()).trim();
|
|
54
|
+
if (!input)
|
|
55
|
+
continue;
|
|
56
|
+
if (input.toLowerCase() === 'exit')
|
|
57
|
+
break;
|
|
58
|
+
try {
|
|
59
|
+
let result;
|
|
60
|
+
if (!currentState) {
|
|
61
|
+
result = await engine.execute({
|
|
62
|
+
messages: [{ role: 'user', content: input }],
|
|
63
|
+
status: 'RUNNING',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
result = await engine.resume(currentState, { role: 'user', content: input });
|
|
68
|
+
}
|
|
69
|
+
currentState = result?.state;
|
|
70
|
+
const answer = extractAnswer(result);
|
|
71
|
+
console.log('\n' + answer + '\n');
|
|
72
|
+
if (options.verbose) {
|
|
73
|
+
logger_1.logger.debug('[Interactive] status:', result?.status, 'state:', result?.state?.status);
|
|
74
|
+
}
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
catch (err) {
|
|
77
|
+
logger_1.logger.error('[Interactive] Erro:', err?.message || err);
|
|
67
78
|
}
|
|
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);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
logger_1.logger.error('[Interactive] Erro:', err?.message || err);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
finally {
|
|
82
|
+
rl.close();
|
|
83
|
+
await runtimeTelemetry.trace.flush?.();
|
|
84
|
+
}
|
|
80
85
|
logger_1.logger.info('[Interactive] Encerrado.');
|
|
81
86
|
}
|
|
82
87
|
catch (error) {
|
|
83
88
|
logger_1.logger.error('[Interactive] Falha:', error);
|
|
84
|
-
process.
|
|
89
|
+
process.exitCode = 1;
|
|
85
90
|
}
|
|
86
91
|
});
|
|
87
92
|
return command;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCliTelemetry = createCliTelemetry;
|
|
4
|
+
const frame_agent_core_1 = require("@ericnunes/frame-agent-core");
|
|
5
|
+
function readBool(value, defaultValue) {
|
|
6
|
+
if (value == null)
|
|
7
|
+
return defaultValue;
|
|
8
|
+
if (value === '1')
|
|
9
|
+
return true;
|
|
10
|
+
if (value === '0')
|
|
11
|
+
return false;
|
|
12
|
+
return value.toLowerCase() === 'true';
|
|
13
|
+
}
|
|
14
|
+
function readInt(value, defaultValue) {
|
|
15
|
+
if (value == null || value.trim().length === 0)
|
|
16
|
+
return defaultValue;
|
|
17
|
+
const parsed = Number.parseInt(value, 10);
|
|
18
|
+
return Number.isFinite(parsed) ? parsed : defaultValue;
|
|
19
|
+
}
|
|
20
|
+
function createCliTelemetry() {
|
|
21
|
+
const includePrompts = readBool(process.env.TELEMETRY_INCLUDE_PROMPTS, false);
|
|
22
|
+
const nativeOpenAIEnabled = readBool(process.env.LANGFUSE_OPENAI_NATIVE_ENABLED ?? process.env.LANGFUSE_NATIVE_OPENAI_ENABLED, true);
|
|
23
|
+
const maxPayloadChars = process.env.TELEMETRY_MAX_PAYLOAD_CHARS != null
|
|
24
|
+
? readInt(process.env.TELEMETRY_MAX_PAYLOAD_CHARS, 4000)
|
|
25
|
+
: includePrompts
|
|
26
|
+
? 200000
|
|
27
|
+
: 4000;
|
|
28
|
+
const maxEvents = process.env.TELEMETRY_MAX_EVENTS != null
|
|
29
|
+
? readInt(process.env.TELEMETRY_MAX_EVENTS, 200)
|
|
30
|
+
: undefined;
|
|
31
|
+
return frame_agent_core_1.telemetry.createDefaultTelemetry({
|
|
32
|
+
includePrompts,
|
|
33
|
+
maxPayloadChars,
|
|
34
|
+
...(maxEvents != null ? { maxEvents } : {}),
|
|
35
|
+
langfuse: {
|
|
36
|
+
nativeOpenAIEnabled,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ericnunes/frame-code-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "CLI para interagir com agentes (runtime via frame-agent-core)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"author": "Eric Nunes",
|
|
45
45
|
"license": "SEE LICENSE IN LICENSE",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ericnunes/frame-agent-core": "
|
|
47
|
+
"@ericnunes/frame-agent-core": ">=0.0.5 <0.1.0",
|
|
48
48
|
"commander": "^14.0.1",
|
|
49
49
|
"dotenv": "^17.2.3"
|
|
50
50
|
},
|