@axiom-lattice/gateway 2.1.70 → 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.70",
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,34 +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
- // addMessage 会触发 streaming 执行,但不会等待完整 workflow 完成
433
- try {
434
- await agent.addMessage({
435
- input: { message: "Clarification answers submitted" },
436
- command: {
437
- resume: {
438
- action: "submit",
439
- data: { answers },
440
- message: "Clarification answers submitted",
441
- },
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",
442
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");
443
458
  });
444
- } catch (error) {
445
- // resume 提交失败(如 thread 不在 interrupted 状态)
446
- return reply.status(400).send({
447
- success: false,
448
- message: "Failed to resume workflow",
449
- error: error instanceof Error ? error.message : String(error),
450
- });
451
- }
459
+ }).catch((error) => {
460
+ request.log.error(error, "Background resume failed");
461
+ });
452
462
 
453
463
  // 4. 立即返回成功(不等待 agent 执行完成)
454
464
  return reply.status(200).send({