@ai-setting/roy-agent-cli 1.5.96 → 1.5.98
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/bin/roy-agent.js +45 -5
- package/dist/index.js +45 -5
- package/dist/roy-agent-linux-x64/bin/roy-agent +0 -0
- package/package.json +1 -1
package/dist/bin/roy-agent.js
CHANGED
|
@@ -7427,7 +7427,7 @@ var require_dist = __commonJS((exports) => {
|
|
|
7427
7427
|
var require_package = __commonJS((exports, module) => {
|
|
7428
7428
|
module.exports = {
|
|
7429
7429
|
name: "@ai-setting/roy-agent-cli",
|
|
7430
|
-
version: "1.5.
|
|
7430
|
+
version: "1.5.98",
|
|
7431
7431
|
type: "module",
|
|
7432
7432
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
7433
7433
|
main: "./dist/index.js",
|
|
@@ -7948,7 +7948,7 @@ class EnvironmentService {
|
|
|
7948
7948
|
env.registerComponent(pluginComponent);
|
|
7949
7949
|
await env.init();
|
|
7950
7950
|
await env.start();
|
|
7951
|
-
agentComponent.refreshDependencies();
|
|
7951
|
+
await agentComponent.refreshDependencies();
|
|
7952
7952
|
logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
|
|
7953
7953
|
if (options?.plugins && options.plugins.length > 0) {
|
|
7954
7954
|
await this.loadPlugins(options.plugins);
|
|
@@ -7956,6 +7956,10 @@ class EnvironmentService {
|
|
|
7956
7956
|
this.environment = env;
|
|
7957
7957
|
return env;
|
|
7958
7958
|
}
|
|
7959
|
+
static SUB_AGENT_PROMPT_NAMES = new Set([
|
|
7960
|
+
"json-extract",
|
|
7961
|
+
"workflow-extract"
|
|
7962
|
+
]);
|
|
7959
7963
|
registerCommandsPromptHook(promptComponent, commandsComponent) {
|
|
7960
7964
|
globalHookManager.register("prompt.after-render", {
|
|
7961
7965
|
name: "commands-prompt",
|
|
@@ -7963,6 +7967,8 @@ class EnvironmentService {
|
|
|
7963
7967
|
const hookCtx = ctx.data;
|
|
7964
7968
|
if (!hookCtx?.name || hookCtx.name === "anonymous")
|
|
7965
7969
|
return;
|
|
7970
|
+
if (EnvironmentService.SUB_AGENT_PROMPT_NAMES.has(hookCtx.name))
|
|
7971
|
+
return;
|
|
7966
7972
|
try {
|
|
7967
7973
|
const metaList = await commandsComponent.getCommandsMeta();
|
|
7968
7974
|
if (metaList.length === 0)
|
|
@@ -9357,6 +9363,8 @@ class EventHandler {
|
|
|
9357
9363
|
isProcessing = false;
|
|
9358
9364
|
isStopped = false;
|
|
9359
9365
|
unsubscribe = null;
|
|
9366
|
+
sessionComponent = null;
|
|
9367
|
+
activeEventSessionId = null;
|
|
9360
9368
|
constructor(options) {
|
|
9361
9369
|
this.env = options.env;
|
|
9362
9370
|
this.eventTypes = options.eventTypes;
|
|
@@ -9365,6 +9373,7 @@ class EventHandler {
|
|
|
9365
9373
|
this.formatter = options.formatter ?? new EventMessageFormatter;
|
|
9366
9374
|
this.isIdle = options.isIdle ?? (() => true);
|
|
9367
9375
|
this.idleCheckInterval = options.idleCheckInterval ?? 100;
|
|
9376
|
+
this.sessionComponent = options.sessionComponent ?? null;
|
|
9368
9377
|
}
|
|
9369
9378
|
start() {
|
|
9370
9379
|
this.isStopped = false;
|
|
@@ -9400,6 +9409,7 @@ class EventHandler {
|
|
|
9400
9409
|
}
|
|
9401
9410
|
this.queue = [];
|
|
9402
9411
|
this.isProcessing = false;
|
|
9412
|
+
this.clearActiveSession();
|
|
9403
9413
|
}
|
|
9404
9414
|
handleEvent(event) {
|
|
9405
9415
|
if (this.isStopped) {
|
|
@@ -9425,6 +9435,7 @@ class EventHandler {
|
|
|
9425
9435
|
}
|
|
9426
9436
|
async processQueue() {
|
|
9427
9437
|
this.isProcessing = true;
|
|
9438
|
+
const sessionId = await this.ensureActiveSession();
|
|
9428
9439
|
while (!this.isStopped && this.queue.length > 0) {
|
|
9429
9440
|
await this.waitForIdle();
|
|
9430
9441
|
if (this.isStopped) {
|
|
@@ -9434,6 +9445,9 @@ class EventHandler {
|
|
|
9434
9445
|
if (!item) {
|
|
9435
9446
|
break;
|
|
9436
9447
|
}
|
|
9448
|
+
if (sessionId) {
|
|
9449
|
+
item.eventSessionId = sessionId;
|
|
9450
|
+
}
|
|
9437
9451
|
try {
|
|
9438
9452
|
if (this.onEventWithEnv) {
|
|
9439
9453
|
await this.onEventWithEnv(item);
|
|
@@ -9444,8 +9458,31 @@ class EventHandler {
|
|
|
9444
9458
|
console.error(`[EventHandler] 处理事件失败:`, error);
|
|
9445
9459
|
}
|
|
9446
9460
|
}
|
|
9461
|
+
this.clearActiveSession();
|
|
9447
9462
|
this.isProcessing = false;
|
|
9448
9463
|
}
|
|
9464
|
+
async ensureActiveSession() {
|
|
9465
|
+
if (!this.sessionComponent)
|
|
9466
|
+
return null;
|
|
9467
|
+
if (this.activeEventSessionId)
|
|
9468
|
+
return this.activeEventSessionId;
|
|
9469
|
+
try {
|
|
9470
|
+
const session = await this.sessionComponent.create({
|
|
9471
|
+
title: `Event Session - ${new Date().toLocaleString("zh-CN")}`
|
|
9472
|
+
});
|
|
9473
|
+
this.activeEventSessionId = session.id;
|
|
9474
|
+
return session.id;
|
|
9475
|
+
} catch (error) {
|
|
9476
|
+
console.error(`[EventHandler] 创建事件 session 失败:`, error);
|
|
9477
|
+
return null;
|
|
9478
|
+
}
|
|
9479
|
+
}
|
|
9480
|
+
clearActiveSession() {
|
|
9481
|
+
this.activeEventSessionId = null;
|
|
9482
|
+
}
|
|
9483
|
+
getActiveEventSessionId() {
|
|
9484
|
+
return this.activeEventSessionId;
|
|
9485
|
+
}
|
|
9449
9486
|
async waitForIdle() {
|
|
9450
9487
|
while (!this.isStopped && !this.isIdle()) {
|
|
9451
9488
|
await this.sleep(this.idleCheckInterval);
|
|
@@ -10070,7 +10107,7 @@ ${COLORS.system("[通知] ❯ " + message.replace(/\n/g, `
|
|
|
10070
10107
|
await this.executeInternal(message, { showPrompt: true });
|
|
10071
10108
|
}
|
|
10072
10109
|
async handleEventMessageWithEnv(formattedEvent) {
|
|
10073
|
-
const { message, envEvent } = formattedEvent;
|
|
10110
|
+
const { message, envEvent, eventSessionId } = formattedEvent;
|
|
10074
10111
|
console.log(`
|
|
10075
10112
|
${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
10076
10113
|
` + COLORS.system("[通知2] ❯ ")))}
|
|
@@ -10090,7 +10127,8 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
10090
10127
|
agentType: agentFromEvent,
|
|
10091
10128
|
pluginEnabled,
|
|
10092
10129
|
envEvent,
|
|
10093
|
-
plugins
|
|
10130
|
+
plugins,
|
|
10131
|
+
eventSessionId
|
|
10094
10132
|
};
|
|
10095
10133
|
await this.executeInternal(message, { showPrompt: true });
|
|
10096
10134
|
}
|
|
@@ -10544,7 +10582,8 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
10544
10582
|
model: args.model,
|
|
10545
10583
|
...agentContext
|
|
10546
10584
|
};
|
|
10547
|
-
const
|
|
10585
|
+
const effectiveSessionId = mergedContext.eventSessionId ?? sessionId;
|
|
10586
|
+
const result = await queryExecutor.execute(message, effectiveSessionId, {
|
|
10548
10587
|
showReasoning: args.reasoning,
|
|
10549
10588
|
showToolCalls: args.toolCalls,
|
|
10550
10589
|
showToolResults: args.toolResults
|
|
@@ -10606,6 +10645,7 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
10606
10645
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
10607
10646
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
10608
10647
|
isIdle: () => repl.isIdle(),
|
|
10648
|
+
sessionComponent,
|
|
10609
10649
|
onEvent: async (message) => {
|
|
10610
10650
|
await repl.handleEventMessage(message);
|
|
10611
10651
|
},
|
package/dist/index.js
CHANGED
|
@@ -7426,7 +7426,7 @@ var require_dist = __commonJS((exports) => {
|
|
|
7426
7426
|
var require_package = __commonJS((exports, module) => {
|
|
7427
7427
|
module.exports = {
|
|
7428
7428
|
name: "@ai-setting/roy-agent-cli",
|
|
7429
|
-
version: "1.5.
|
|
7429
|
+
version: "1.5.98",
|
|
7430
7430
|
type: "module",
|
|
7431
7431
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
7432
7432
|
main: "./dist/index.js",
|
|
@@ -7947,7 +7947,7 @@ class EnvironmentService {
|
|
|
7947
7947
|
env.registerComponent(pluginComponent);
|
|
7948
7948
|
await env.init();
|
|
7949
7949
|
await env.start();
|
|
7950
|
-
agentComponent.refreshDependencies();
|
|
7950
|
+
await agentComponent.refreshDependencies();
|
|
7951
7951
|
logger.debug("[EnvironmentService] AgentComponent dependencies refreshed after env.start()");
|
|
7952
7952
|
if (options?.plugins && options.plugins.length > 0) {
|
|
7953
7953
|
await this.loadPlugins(options.plugins);
|
|
@@ -7955,6 +7955,10 @@ class EnvironmentService {
|
|
|
7955
7955
|
this.environment = env;
|
|
7956
7956
|
return env;
|
|
7957
7957
|
}
|
|
7958
|
+
static SUB_AGENT_PROMPT_NAMES = new Set([
|
|
7959
|
+
"json-extract",
|
|
7960
|
+
"workflow-extract"
|
|
7961
|
+
]);
|
|
7958
7962
|
registerCommandsPromptHook(promptComponent, commandsComponent) {
|
|
7959
7963
|
globalHookManager.register("prompt.after-render", {
|
|
7960
7964
|
name: "commands-prompt",
|
|
@@ -7962,6 +7966,8 @@ class EnvironmentService {
|
|
|
7962
7966
|
const hookCtx = ctx.data;
|
|
7963
7967
|
if (!hookCtx?.name || hookCtx.name === "anonymous")
|
|
7964
7968
|
return;
|
|
7969
|
+
if (EnvironmentService.SUB_AGENT_PROMPT_NAMES.has(hookCtx.name))
|
|
7970
|
+
return;
|
|
7965
7971
|
try {
|
|
7966
7972
|
const metaList = await commandsComponent.getCommandsMeta();
|
|
7967
7973
|
if (metaList.length === 0)
|
|
@@ -9356,6 +9362,8 @@ class EventHandler {
|
|
|
9356
9362
|
isProcessing = false;
|
|
9357
9363
|
isStopped = false;
|
|
9358
9364
|
unsubscribe = null;
|
|
9365
|
+
sessionComponent = null;
|
|
9366
|
+
activeEventSessionId = null;
|
|
9359
9367
|
constructor(options) {
|
|
9360
9368
|
this.env = options.env;
|
|
9361
9369
|
this.eventTypes = options.eventTypes;
|
|
@@ -9364,6 +9372,7 @@ class EventHandler {
|
|
|
9364
9372
|
this.formatter = options.formatter ?? new EventMessageFormatter;
|
|
9365
9373
|
this.isIdle = options.isIdle ?? (() => true);
|
|
9366
9374
|
this.idleCheckInterval = options.idleCheckInterval ?? 100;
|
|
9375
|
+
this.sessionComponent = options.sessionComponent ?? null;
|
|
9367
9376
|
}
|
|
9368
9377
|
start() {
|
|
9369
9378
|
this.isStopped = false;
|
|
@@ -9399,6 +9408,7 @@ class EventHandler {
|
|
|
9399
9408
|
}
|
|
9400
9409
|
this.queue = [];
|
|
9401
9410
|
this.isProcessing = false;
|
|
9411
|
+
this.clearActiveSession();
|
|
9402
9412
|
}
|
|
9403
9413
|
handleEvent(event) {
|
|
9404
9414
|
if (this.isStopped) {
|
|
@@ -9424,6 +9434,7 @@ class EventHandler {
|
|
|
9424
9434
|
}
|
|
9425
9435
|
async processQueue() {
|
|
9426
9436
|
this.isProcessing = true;
|
|
9437
|
+
const sessionId = await this.ensureActiveSession();
|
|
9427
9438
|
while (!this.isStopped && this.queue.length > 0) {
|
|
9428
9439
|
await this.waitForIdle();
|
|
9429
9440
|
if (this.isStopped) {
|
|
@@ -9433,6 +9444,9 @@ class EventHandler {
|
|
|
9433
9444
|
if (!item) {
|
|
9434
9445
|
break;
|
|
9435
9446
|
}
|
|
9447
|
+
if (sessionId) {
|
|
9448
|
+
item.eventSessionId = sessionId;
|
|
9449
|
+
}
|
|
9436
9450
|
try {
|
|
9437
9451
|
if (this.onEventWithEnv) {
|
|
9438
9452
|
await this.onEventWithEnv(item);
|
|
@@ -9443,8 +9457,31 @@ class EventHandler {
|
|
|
9443
9457
|
console.error(`[EventHandler] 处理事件失败:`, error);
|
|
9444
9458
|
}
|
|
9445
9459
|
}
|
|
9460
|
+
this.clearActiveSession();
|
|
9446
9461
|
this.isProcessing = false;
|
|
9447
9462
|
}
|
|
9463
|
+
async ensureActiveSession() {
|
|
9464
|
+
if (!this.sessionComponent)
|
|
9465
|
+
return null;
|
|
9466
|
+
if (this.activeEventSessionId)
|
|
9467
|
+
return this.activeEventSessionId;
|
|
9468
|
+
try {
|
|
9469
|
+
const session = await this.sessionComponent.create({
|
|
9470
|
+
title: `Event Session - ${new Date().toLocaleString("zh-CN")}`
|
|
9471
|
+
});
|
|
9472
|
+
this.activeEventSessionId = session.id;
|
|
9473
|
+
return session.id;
|
|
9474
|
+
} catch (error) {
|
|
9475
|
+
console.error(`[EventHandler] 创建事件 session 失败:`, error);
|
|
9476
|
+
return null;
|
|
9477
|
+
}
|
|
9478
|
+
}
|
|
9479
|
+
clearActiveSession() {
|
|
9480
|
+
this.activeEventSessionId = null;
|
|
9481
|
+
}
|
|
9482
|
+
getActiveEventSessionId() {
|
|
9483
|
+
return this.activeEventSessionId;
|
|
9484
|
+
}
|
|
9448
9485
|
async waitForIdle() {
|
|
9449
9486
|
while (!this.isStopped && !this.isIdle()) {
|
|
9450
9487
|
await this.sleep(this.idleCheckInterval);
|
|
@@ -10069,7 +10106,7 @@ ${COLORS.system("[通知] ❯ " + message.replace(/\n/g, `
|
|
|
10069
10106
|
await this.executeInternal(message, { showPrompt: true });
|
|
10070
10107
|
}
|
|
10071
10108
|
async handleEventMessageWithEnv(formattedEvent) {
|
|
10072
|
-
const { message, envEvent } = formattedEvent;
|
|
10109
|
+
const { message, envEvent, eventSessionId } = formattedEvent;
|
|
10073
10110
|
console.log(`
|
|
10074
10111
|
${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
10075
10112
|
` + COLORS.system("[通知2] ❯ ")))}
|
|
@@ -10089,7 +10126,8 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
10089
10126
|
agentType: agentFromEvent,
|
|
10090
10127
|
pluginEnabled,
|
|
10091
10128
|
envEvent,
|
|
10092
|
-
plugins
|
|
10129
|
+
plugins,
|
|
10130
|
+
eventSessionId
|
|
10093
10131
|
};
|
|
10094
10132
|
await this.executeInternal(message, { showPrompt: true });
|
|
10095
10133
|
}
|
|
@@ -10543,7 +10581,8 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
10543
10581
|
model: args.model,
|
|
10544
10582
|
...agentContext
|
|
10545
10583
|
};
|
|
10546
|
-
const
|
|
10584
|
+
const effectiveSessionId = mergedContext.eventSessionId ?? sessionId;
|
|
10585
|
+
const result = await queryExecutor.execute(message, effectiveSessionId, {
|
|
10547
10586
|
showReasoning: args.reasoning,
|
|
10548
10587
|
showToolCalls: args.toolCalls,
|
|
10549
10588
|
showToolResults: args.toolResults
|
|
@@ -10605,6 +10644,7 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
10605
10644
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
10606
10645
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
10607
10646
|
isIdle: () => repl.isIdle(),
|
|
10647
|
+
sessionComponent,
|
|
10608
10648
|
onEvent: async (message) => {
|
|
10609
10649
|
await repl.handleEventMessage(message);
|
|
10610
10650
|
},
|
|
Binary file
|