@dudousxd/nestjs-agent 0.3.2 → 0.3.3

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.
@@ -124,7 +124,9 @@ AgentRunWorkflow = _ts_decorate([
124
124
  ], AgentRunWorkflow);
125
125
 
126
126
  // src/durable/durable-agent-runner.ts
127
+ import { randomUUID } from "node:crypto";
127
128
  import { WorkflowService } from "@dudousxd/nestjs-durable";
129
+ import { WorkflowSuspended as WorkflowSuspended2 } from "@dudousxd/nestjs-durable-core";
128
130
  import { Injectable as Injectable2 } from "@nestjs/common";
129
131
  function _ts_decorate2(decorators, target, key, desc) {
130
132
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -150,9 +152,16 @@ var DurableAgentRunner = class {
150
152
  ...input,
151
153
  day: input.day ?? utcDay()
152
154
  };
153
- const result = await this.workflows.start(AgentRunWorkflow, stamped);
155
+ const runId = randomUUID();
156
+ try {
157
+ await this.workflows.start(AgentRunWorkflow, stamped, runId);
158
+ } catch (error) {
159
+ if (!(error instanceof WorkflowSuspended2)) {
160
+ throw error;
161
+ }
162
+ }
154
163
  return {
155
- runId: result.runId
164
+ runId
156
165
  };
157
166
  }
158
167
  async signal(runId, toolCallId, decision) {
@@ -427,6 +436,9 @@ var AgentService = class {
427
436
  ...params.regenerate === true ? {
428
437
  regenerate: true
429
438
  } : {},
439
+ ...params.attachments !== void 0 ? {
440
+ attachments: params.attachments
441
+ } : {},
430
442
  ...params.pageContext !== void 0 ? {
431
443
  pageContext: params.pageContext
432
444
  } : {}
@@ -681,6 +693,9 @@ var ChatController = class {
681
693
  ...body.agent !== void 0 ? {
682
694
  agentName: body.agent
683
695
  } : {},
696
+ ...body.attachments !== void 0 ? {
697
+ attachments: body.attachments
698
+ } : {},
684
699
  ...body.pageContext !== void 0 ? {
685
700
  pageContext: body.pageContext
686
701
  } : {},
@@ -719,11 +734,26 @@ data: ${JSON.stringify({
719
734
 
720
735
  `);
721
736
  const decoder = new TextDecoder();
737
+ let buffer = "";
722
738
  try {
723
739
  for await (const chunk of this.agent.subscribe(runId)) {
724
- res.write(`data: ${JSON.stringify({
725
- delta: decoder.decode(chunk)
726
- })}
740
+ buffer += decoder.decode(chunk, {
741
+ stream: true
742
+ });
743
+ let newline = buffer.indexOf("\n");
744
+ while (newline !== -1) {
745
+ const line = buffer.slice(0, newline);
746
+ buffer = buffer.slice(newline + 1);
747
+ if (line.length > 0) {
748
+ res.write(`data: ${line}
749
+
750
+ `);
751
+ }
752
+ newline = buffer.indexOf("\n");
753
+ }
754
+ }
755
+ if (buffer.length > 0) {
756
+ res.write(`data: ${buffer}
727
757
 
728
758
  `);
729
759
  }
@@ -1782,6 +1812,7 @@ var AgentModule = class _AgentModule {
1782
1812
  }
1783
1813
  static forRootAsync(options) {
1784
1814
  const path = options.path ?? DEFAULT_PATH;
1815
+ const includeStore = options.externalStore !== true;
1785
1816
  return {
1786
1817
  module: _AgentModule,
1787
1818
  global: true,
@@ -1797,11 +1828,9 @@ var AgentModule = class _AgentModule {
1797
1828
  useFactory: options.useFactory,
1798
1829
  inject: options.inject ?? []
1799
1830
  },
1800
- // The async factory resolves too late to inspect `store`, so we always bind AGENT_STORE here
1801
- // (its factory reads the resolved options). Omit-and-import-a-store-module is a `forRoot` path.
1802
- ...sharedProviders(options.durable ?? false, true)
1831
+ ...sharedProviders(options.durable ?? false, includeStore)
1803
1832
  ],
1804
- exports: exportsFor(true)
1833
+ exports: exportsFor(includeStore)
1805
1834
  };
1806
1835
  }
1807
1836
  };