plugin-agent-orchestrator 1.0.35 → 1.0.37

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.
@@ -241,15 +241,36 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
241
241
  });
242
242
  this.app.resourceManager.use(
243
243
  async (ctx, next) => {
244
+ var _a2, _b2;
244
245
  const { resourceName, actionName } = ctx.action || {};
245
246
  if (resourceName === "aiConversations" && actionName === "sendMessages") {
246
247
  const values = ctx.action.params.values || {};
247
248
  const messages = values.messages;
248
249
  if (Array.isArray(messages)) {
249
- planningPrompt.applyPlanningContext(messages);
250
+ const runtimeContext2 = {
251
+ ctx,
252
+ source: "chat-ui",
253
+ employee: void 0,
254
+ sessionId: String(((_a2 = ctx.state) == null ? void 0 : _a2.sessionId) || ""),
255
+ userId: (0, import_ctx_utils.currentUserId)(ctx),
256
+ messages,
257
+ metadata: {}
258
+ };
259
+ await this.agentRuntimeLifecycle.runBeforeHooks(runtimeContext2);
260
+ ctx.state.agentRuntimeContext = runtimeContext2;
261
+ }
262
+ }
263
+ const runtimeContext = (_b2 = ctx.state) == null ? void 0 : _b2.agentRuntimeContext;
264
+ try {
265
+ await next();
266
+ } finally {
267
+ if (runtimeContext) {
268
+ await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
269
+ succeeded: ctx.status < 400,
270
+ value: ctx.body
271
+ });
250
272
  }
251
273
  }
252
- await next();
253
274
  },
254
275
  { tag: "orchestrator-planning-prompt", after: "acl" }
255
276
  );
@@ -421,7 +421,7 @@ class SkillHubSubFeature {
421
421
  * Includes rate limiting and graceful abort propagation.
422
422
  */
423
423
  async executeSkill(skill, inputArgs, ctx) {
424
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
424
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
425
425
  const userId = (_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
426
426
  if (userId) {
427
427
  if (!this.rateLimiter.check(String(userId))) {
@@ -475,19 +475,40 @@ class SkillHubSubFeature {
475
475
  });
476
476
  const timeoutMs = ((skill.timeoutSeconds || ((_f = skill.get) == null ? void 0 : _f.call(skill, "timeoutSeconds")) || 60) + 15) * 1e3;
477
477
  const timeout = setTimeout(() => {
478
+ clearInterval(poll);
478
479
  rejectPromise(new Error(`Skill execution timeout after ${skill.timeoutSeconds || 60}s`));
479
480
  }, timeoutMs);
481
+ const poll = setInterval(async () => {
482
+ var _a2, _b2, _c2, _d2, _e2;
483
+ try {
484
+ const current = await this.db.getRepository("skillExecutions").findOne({ filterByTk: execId });
485
+ const status = ((_a2 = current == null ? void 0 : current.get) == null ? void 0 : _a2.call(current, "status")) || (current == null ? void 0 : current.status);
486
+ if (!["succeeded", "failed", "timeout", "canceled"].includes(status)) return;
487
+ clearTimeout(timeout);
488
+ clearInterval(poll);
489
+ resolvePromise({
490
+ status,
491
+ stdout: ((_b2 = current == null ? void 0 : current.get) == null ? void 0 : _b2.call(current, "stdout")) || (current == null ? void 0 : current.stdout) || "",
492
+ stderr: ((_c2 = current == null ? void 0 : current.get) == null ? void 0 : _c2.call(current, "stderr")) || (current == null ? void 0 : current.stderr) || "",
493
+ files: (0, import_json_fields.parseJsonText)(((_d2 = current == null ? void 0 : current.get) == null ? void 0 : _d2.call(current, "outputFiles")) || (current == null ? void 0 : current.outputFiles), []),
494
+ durationMs: ((_e2 = current == null ? void 0 : current.get) == null ? void 0 : _e2.call(current, "durationMs")) || (current == null ? void 0 : current.durationMs) || 0
495
+ });
496
+ } catch {
497
+ }
498
+ }, 2e3);
499
+ (_g = poll.unref) == null ? void 0 : _g.call(poll);
480
500
  const doneCallback = async (data) => {
481
501
  clearTimeout(timeout);
502
+ clearInterval(poll);
482
503
  resolvePromise(data);
483
504
  };
484
505
  await this.app.pubSubManager.subscribe(progressChannel, progressCallback);
485
506
  cleanups.push({ channel: progressChannel, callback: progressCallback });
486
507
  await this.app.pubSubManager.subscribe(doneChannel, doneCallback);
487
508
  cleanups.push({ channel: doneChannel, callback: doneCallback });
488
- if (((_g = ctx == null ? void 0 : ctx.req) == null ? void 0 : _g.signal) || (ctx == null ? void 0 : ctx.signal)) {
489
- const signal = ((_h = ctx.req) == null ? void 0 : _h.signal) || ctx.signal;
490
- (_i = signal.addEventListener) == null ? void 0 : _i.call(signal, "abort", () => {
509
+ if (((_h = ctx == null ? void 0 : ctx.req) == null ? void 0 : _h.signal) || (ctx == null ? void 0 : ctx.signal)) {
510
+ const signal = ((_i = ctx.req) == null ? void 0 : _i.signal) || ctx.signal;
511
+ (_j = signal.addEventListener) == null ? void 0 : _j.call(signal, "abort", () => {
491
512
  clearTimeout(timeout);
492
513
  this.app.pubSubManager.publish(abortChannel, { reason: "user_cancel" }).catch(() => {
493
514
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "代理协调器",
5
5
  "displayName.vi-VN": "Điều phối Agent",
6
6
  "description": "Native AI Employee sub-agent monitoring, policy, and memory context layer for NocoBase plugin-ai.",
7
- "version": "1.0.35",
7
+ "version": "1.0.37",
8
8
  "license": "Apache-2.0",
9
9
  "main": "dist/server/index.js",
10
10
  "keywords": [
@@ -245,10 +245,37 @@ export class PluginAgentOrchestratorServer extends Plugin {
245
245
  const values = ctx.action.params.values || {};
246
246
  const messages = values.messages;
247
247
  if (Array.isArray(messages)) {
248
- planningPrompt.applyPlanningContext(messages);
248
+ const runtimeContext = {
249
+ ctx,
250
+ source: 'chat-ui' as const,
251
+ employee: undefined,
252
+ sessionId: String(ctx.state?.sessionId || ''),
253
+ userId: currentUserId(ctx),
254
+ messages,
255
+ metadata: {},
256
+ };
257
+ await this.agentRuntimeLifecycle.runBeforeHooks(runtimeContext);
258
+ ctx.state.agentRuntimeContext = runtimeContext;
249
259
  }
250
260
  }
251
- await next();
261
+ const runtimeContext = ctx.state?.agentRuntimeContext;
262
+ try {
263
+ await next();
264
+ if (runtimeContext) {
265
+ await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
266
+ succeeded: ctx.status < 400,
267
+ value: ctx.body,
268
+ });
269
+ }
270
+ } catch (error) {
271
+ if (runtimeContext) {
272
+ await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
273
+ succeeded: false,
274
+ error: error instanceof Error ? error : new Error(String(error)),
275
+ });
276
+ }
277
+ throw error;
278
+ }
252
279
  },
253
280
  { tag: 'orchestrator-planning-prompt', after: 'acl' },
254
281
  );
@@ -501,11 +501,32 @@ export class SkillHubSubFeature {
501
501
 
502
502
  const timeoutMs = ((skill.timeoutSeconds || skill.get?.('timeoutSeconds') || 60) + 15) * 1000;
503
503
  const timeout = setTimeout(() => {
504
+ clearInterval(poll);
504
505
  rejectPromise(new Error(`Skill execution timeout after ${skill.timeoutSeconds || 60}s`));
505
506
  }, timeoutMs);
507
+ const poll = setInterval(async () => {
508
+ try {
509
+ const current = await (this as any).db.getRepository('skillExecutions').findOne({ filterByTk: execId });
510
+ const status = current?.get?.('status') || current?.status;
511
+ if (!['succeeded', 'failed', 'timeout', 'canceled'].includes(status)) return;
512
+ clearTimeout(timeout);
513
+ clearInterval(poll);
514
+ resolvePromise({
515
+ status,
516
+ stdout: current?.get?.('stdout') || current?.stdout || '',
517
+ stderr: current?.get?.('stderr') || current?.stderr || '',
518
+ files: parseJsonText(current?.get?.('outputFiles') || current?.outputFiles, []),
519
+ durationMs: current?.get?.('durationMs') || current?.durationMs || 0,
520
+ });
521
+ } catch {
522
+ // Pub/Sub remains the primary completion path; polling is a recovery fallback.
523
+ }
524
+ }, 2000);
525
+ poll.unref?.();
506
526
 
507
527
  const doneCallback = async (data: any) => {
508
528
  clearTimeout(timeout);
529
+ clearInterval(poll);
509
530
  resolvePromise(data);
510
531
  };
511
532