@axiom-lattice/gateway 2.1.71 → 2.1.72

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/gateway",
3
- "version": "2.1.71",
3
+ "version": "2.1.72",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,7 @@
1
1
  import { FastifyRequest, FastifyReply } from "fastify";
2
2
  import { getStoreLattice, agentInstanceManager } from "@axiom-lattice/core";
3
3
  import type { WorkflowTrackingStore, WorkflowRun, RunStep } from "@axiom-lattice/protocols";
4
+ import { MessageChunkTypes } from "@axiom-lattice/protocols";
4
5
 
5
6
  function getTenantId(request: FastifyRequest): string {
6
7
  const userTenantId = (request as any).user?.tenantId;
@@ -421,43 +422,43 @@ export async function replyInboxTask(
421
422
  });
422
423
  }
423
424
 
424
- // 2. 获取 Agent 实例
425
+ // 2. 获取 Agent 实例(补齐参数,与 createRun 一致)
426
+ const workspace_id = request.headers["x-workspace-id"] as string;
427
+ const project_id = request.headers["x-project-id"] as string;
425
428
  const agent = agentInstanceManager.getAgent({
426
429
  assistant_id: run.assistantId,
427
430
  thread_id: run.threadId,
428
431
  tenant_id: tenantId,
432
+ workspace_id,
433
+ project_id,
429
434
  });
430
435
 
431
- // 3. 提交 resume 请求并强制启动执行
432
- // 注意:interrupted 状态下 processing message 会阻止自动启动,需要先重置
433
- try {
434
- // 先重置被中断的 processing message,使其可以被重新处理
435
- const queueStore = (agent as any).getQueueStore?.() || (agent as any).queueStore;
436
- if (queueStore?.resetProcessingToPending) {
437
- await queueStore.resetProcessingToPending(run.threadId);
438
- }
439
-
440
- // 添加 resume 消息到队列
441
- await agent.addMessage({
442
- input: { message: "Clarification answers submitted" },
443
- command: {
444
- resume: {
445
- action: "submit",
446
- data: { answers },
447
- message: "Clarification answers submitted",
448
- },
436
+ // 3. 直接在后台触发 resume 执行(不等待,不阻塞 HTTP 响应)
437
+ agent.addMessage({
438
+ input: { message: "Clarification answers submitted" },
439
+ command: {
440
+ resume: {
441
+ action: "submit",
442
+ data: { answers },
443
+ message: "Clarification answers submitted",
449
444
  },
445
+ },
446
+ }).then((result) => {
447
+ // addMessage 成功后,触发 chunkStream 消费(驱动执行)
448
+ // 不 await stream,让它在后台运行
449
+ const stream = agent.chunkStream(
450
+ result.messageId,
451
+ [MessageChunkTypes.MESSAGE_COMPLETED]
452
+ );
453
+ // 消费 stream 但不阻塞(后台驱动 agent 执行)
454
+ (async () => {
455
+ for await (const _ of stream) { /* 丢弃 chunks */ }
456
+ })().catch((error) => {
457
+ request.log.error(error, "Background chunk stream error");
450
458
  });
451
-
452
- // 强制启动 queue processor
453
- await agent.startQueueProcessorIfNeeded();
454
- } catch (error) {
455
- return reply.status(400).send({
456
- success: false,
457
- message: "Failed to resume workflow",
458
- error: error instanceof Error ? error.message : String(error),
459
- });
460
- }
459
+ }).catch((error) => {
460
+ request.log.error(error, "Background resume failed");
461
+ });
461
462
 
462
463
  // 4. 立即返回成功(不等待 agent 执行完成)
463
464
  return reply.status(200).send({