@ai-setting/roy-agent-cli 1.5.97 → 1.5.99

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.
@@ -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.97",
7430
+ version: "1.5.99",
7431
7431
  type: "module",
7432
7432
  description: "CLI for roy-agent - Non-interactive command execution",
7433
7433
  main: "./dist/index.js",
@@ -9363,6 +9363,8 @@ class EventHandler {
9363
9363
  isProcessing = false;
9364
9364
  isStopped = false;
9365
9365
  unsubscribe = null;
9366
+ sessionComponent = null;
9367
+ activeEventSessionId = null;
9366
9368
  constructor(options) {
9367
9369
  this.env = options.env;
9368
9370
  this.eventTypes = options.eventTypes;
@@ -9371,6 +9373,7 @@ class EventHandler {
9371
9373
  this.formatter = options.formatter ?? new EventMessageFormatter;
9372
9374
  this.isIdle = options.isIdle ?? (() => true);
9373
9375
  this.idleCheckInterval = options.idleCheckInterval ?? 100;
9376
+ this.sessionComponent = options.sessionComponent ?? null;
9374
9377
  }
9375
9378
  start() {
9376
9379
  this.isStopped = false;
@@ -9406,6 +9409,7 @@ class EventHandler {
9406
9409
  }
9407
9410
  this.queue = [];
9408
9411
  this.isProcessing = false;
9412
+ this.clearActiveSession();
9409
9413
  }
9410
9414
  handleEvent(event) {
9411
9415
  if (this.isStopped) {
@@ -9431,6 +9435,12 @@ class EventHandler {
9431
9435
  }
9432
9436
  async processQueue() {
9433
9437
  this.isProcessing = true;
9438
+ const sessionId = await this.ensureActiveSession();
9439
+ if (this.isStopped) {
9440
+ this.clearActiveSession();
9441
+ this.isProcessing = false;
9442
+ return;
9443
+ }
9434
9444
  while (!this.isStopped && this.queue.length > 0) {
9435
9445
  await this.waitForIdle();
9436
9446
  if (this.isStopped) {
@@ -9440,6 +9450,9 @@ class EventHandler {
9440
9450
  if (!item) {
9441
9451
  break;
9442
9452
  }
9453
+ if (sessionId) {
9454
+ item.eventSessionId = sessionId;
9455
+ }
9443
9456
  try {
9444
9457
  if (this.onEventWithEnv) {
9445
9458
  await this.onEventWithEnv(item);
@@ -9450,8 +9463,35 @@ class EventHandler {
9450
9463
  console.error(`[EventHandler] 处理事件失败:`, error);
9451
9464
  }
9452
9465
  }
9466
+ this.clearActiveSession();
9453
9467
  this.isProcessing = false;
9454
9468
  }
9469
+ async ensureActiveSession() {
9470
+ if (!this.sessionComponent)
9471
+ return null;
9472
+ if (this.activeEventSessionId)
9473
+ return this.activeEventSessionId;
9474
+ try {
9475
+ const session = await this.sessionComponent.create({
9476
+ title: `Event Session - ${new Date().toLocaleString()}`
9477
+ });
9478
+ if (this.isStopped) {
9479
+ this.activeEventSessionId = null;
9480
+ return null;
9481
+ }
9482
+ this.activeEventSessionId = session.id;
9483
+ return session.id;
9484
+ } catch (error) {
9485
+ console.error(`[EventHandler] 创建事件 session 失败:`, error);
9486
+ return null;
9487
+ }
9488
+ }
9489
+ clearActiveSession() {
9490
+ this.activeEventSessionId = null;
9491
+ }
9492
+ getActiveEventSessionId() {
9493
+ return this.activeEventSessionId;
9494
+ }
9455
9495
  async waitForIdle() {
9456
9496
  while (!this.isStopped && !this.isIdle()) {
9457
9497
  await this.sleep(this.idleCheckInterval);
@@ -10076,7 +10116,7 @@ ${COLORS.system("[通知] ❯ " + message.replace(/\n/g, `
10076
10116
  await this.executeInternal(message, { showPrompt: true });
10077
10117
  }
10078
10118
  async handleEventMessageWithEnv(formattedEvent) {
10079
- const { message, envEvent } = formattedEvent;
10119
+ const { message, envEvent, eventSessionId } = formattedEvent;
10080
10120
  console.log(`
10081
10121
  ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
10082
10122
  ` + COLORS.system("[通知2] ❯ ")))}
@@ -10096,7 +10136,8 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
10096
10136
  agentType: agentFromEvent,
10097
10137
  pluginEnabled,
10098
10138
  envEvent,
10099
- plugins
10139
+ plugins,
10140
+ eventSessionId
10100
10141
  };
10101
10142
  await this.executeInternal(message, { showPrompt: true });
10102
10143
  }
@@ -10550,7 +10591,8 @@ function createInteractiveCommand(externalEnvService) {
10550
10591
  model: args.model,
10551
10592
  ...agentContext
10552
10593
  };
10553
- const result = await queryExecutor.execute(message, sessionId, {
10594
+ const effectiveSessionId = mergedContext.eventSessionId ?? sessionId;
10595
+ const result = await queryExecutor.execute(message, effectiveSessionId, {
10554
10596
  showReasoning: args.reasoning,
10555
10597
  showToolCalls: args.toolCalls,
10556
10598
  showToolResults: args.toolResults
@@ -10612,9 +10654,7 @@ function createInteractiveCommand(externalEnvService) {
10612
10654
  eventTypes: ["task.background.*", "event-source.event.*"],
10613
10655
  formatter: new EventMessageFormatter({ prefix: "[通知]" }),
10614
10656
  isIdle: () => repl.isIdle(),
10615
- onEvent: async (message) => {
10616
- await repl.handleEventMessage(message);
10617
- },
10657
+ sessionComponent,
10618
10658
  onEventWithEnv: async (formattedEvent) => {
10619
10659
  await repl.handleEventMessageWithEnv(formattedEvent);
10620
10660
  }
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.97",
7429
+ version: "1.5.99",
7430
7430
  type: "module",
7431
7431
  description: "CLI for roy-agent - Non-interactive command execution",
7432
7432
  main: "./dist/index.js",
@@ -9362,6 +9362,8 @@ class EventHandler {
9362
9362
  isProcessing = false;
9363
9363
  isStopped = false;
9364
9364
  unsubscribe = null;
9365
+ sessionComponent = null;
9366
+ activeEventSessionId = null;
9365
9367
  constructor(options) {
9366
9368
  this.env = options.env;
9367
9369
  this.eventTypes = options.eventTypes;
@@ -9370,6 +9372,7 @@ class EventHandler {
9370
9372
  this.formatter = options.formatter ?? new EventMessageFormatter;
9371
9373
  this.isIdle = options.isIdle ?? (() => true);
9372
9374
  this.idleCheckInterval = options.idleCheckInterval ?? 100;
9375
+ this.sessionComponent = options.sessionComponent ?? null;
9373
9376
  }
9374
9377
  start() {
9375
9378
  this.isStopped = false;
@@ -9405,6 +9408,7 @@ class EventHandler {
9405
9408
  }
9406
9409
  this.queue = [];
9407
9410
  this.isProcessing = false;
9411
+ this.clearActiveSession();
9408
9412
  }
9409
9413
  handleEvent(event) {
9410
9414
  if (this.isStopped) {
@@ -9430,6 +9434,12 @@ class EventHandler {
9430
9434
  }
9431
9435
  async processQueue() {
9432
9436
  this.isProcessing = true;
9437
+ const sessionId = await this.ensureActiveSession();
9438
+ if (this.isStopped) {
9439
+ this.clearActiveSession();
9440
+ this.isProcessing = false;
9441
+ return;
9442
+ }
9433
9443
  while (!this.isStopped && this.queue.length > 0) {
9434
9444
  await this.waitForIdle();
9435
9445
  if (this.isStopped) {
@@ -9439,6 +9449,9 @@ class EventHandler {
9439
9449
  if (!item) {
9440
9450
  break;
9441
9451
  }
9452
+ if (sessionId) {
9453
+ item.eventSessionId = sessionId;
9454
+ }
9442
9455
  try {
9443
9456
  if (this.onEventWithEnv) {
9444
9457
  await this.onEventWithEnv(item);
@@ -9449,8 +9462,35 @@ class EventHandler {
9449
9462
  console.error(`[EventHandler] 处理事件失败:`, error);
9450
9463
  }
9451
9464
  }
9465
+ this.clearActiveSession();
9452
9466
  this.isProcessing = false;
9453
9467
  }
9468
+ async ensureActiveSession() {
9469
+ if (!this.sessionComponent)
9470
+ return null;
9471
+ if (this.activeEventSessionId)
9472
+ return this.activeEventSessionId;
9473
+ try {
9474
+ const session = await this.sessionComponent.create({
9475
+ title: `Event Session - ${new Date().toLocaleString()}`
9476
+ });
9477
+ if (this.isStopped) {
9478
+ this.activeEventSessionId = null;
9479
+ return null;
9480
+ }
9481
+ this.activeEventSessionId = session.id;
9482
+ return session.id;
9483
+ } catch (error) {
9484
+ console.error(`[EventHandler] 创建事件 session 失败:`, error);
9485
+ return null;
9486
+ }
9487
+ }
9488
+ clearActiveSession() {
9489
+ this.activeEventSessionId = null;
9490
+ }
9491
+ getActiveEventSessionId() {
9492
+ return this.activeEventSessionId;
9493
+ }
9454
9494
  async waitForIdle() {
9455
9495
  while (!this.isStopped && !this.isIdle()) {
9456
9496
  await this.sleep(this.idleCheckInterval);
@@ -10075,7 +10115,7 @@ ${COLORS.system("[通知] ❯ " + message.replace(/\n/g, `
10075
10115
  await this.executeInternal(message, { showPrompt: true });
10076
10116
  }
10077
10117
  async handleEventMessageWithEnv(formattedEvent) {
10078
- const { message, envEvent } = formattedEvent;
10118
+ const { message, envEvent, eventSessionId } = formattedEvent;
10079
10119
  console.log(`
10080
10120
  ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
10081
10121
  ` + COLORS.system("[通知2] ❯ ")))}
@@ -10095,7 +10135,8 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
10095
10135
  agentType: agentFromEvent,
10096
10136
  pluginEnabled,
10097
10137
  envEvent,
10098
- plugins
10138
+ plugins,
10139
+ eventSessionId
10099
10140
  };
10100
10141
  await this.executeInternal(message, { showPrompt: true });
10101
10142
  }
@@ -10549,7 +10590,8 @@ function createInteractiveCommand(externalEnvService) {
10549
10590
  model: args.model,
10550
10591
  ...agentContext
10551
10592
  };
10552
- const result = await queryExecutor.execute(message, sessionId, {
10593
+ const effectiveSessionId = mergedContext.eventSessionId ?? sessionId;
10594
+ const result = await queryExecutor.execute(message, effectiveSessionId, {
10553
10595
  showReasoning: args.reasoning,
10554
10596
  showToolCalls: args.toolCalls,
10555
10597
  showToolResults: args.toolResults
@@ -10611,9 +10653,7 @@ function createInteractiveCommand(externalEnvService) {
10611
10653
  eventTypes: ["task.background.*", "event-source.event.*"],
10612
10654
  formatter: new EventMessageFormatter({ prefix: "[通知]" }),
10613
10655
  isIdle: () => repl.isIdle(),
10614
- onEvent: async (message) => {
10615
- await repl.handleEventMessage(message);
10616
- },
10656
+ sessionComponent,
10617
10657
  onEventWithEnv: async (formattedEvent) => {
10618
10658
  await repl.handleEventMessageWithEnv(formattedEvent);
10619
10659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-cli",
3
- "version": "1.5.97",
3
+ "version": "1.5.99",
4
4
  "type": "module",
5
5
  "description": "CLI for roy-agent - Non-interactive command execution",
6
6
  "main": "./dist/index.js",