@dudousxd/nestjs-agent 0.6.0 → 0.8.0

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.
@@ -92,12 +92,12 @@ var AgentRunSteps = class {
92
92
  const tools = await deps.registry.definitionsFor(input.actor, deps.rolesPolicy, deps.toolAllowList);
93
93
  const opened = await deps.sink.open(input.sinkRunId);
94
94
  const writer = input.childSink ? childSinkWriter(opened) : opened;
95
- return deps.model.runTurn({
95
+ return (0, import_nestjs_agent_core.traceLlmTurn)(input.runId, input.step, () => deps.model.runTurn({
96
96
  system: input.system,
97
97
  messages: input.messages,
98
98
  tools,
99
99
  sink: writer
100
- });
100
+ }));
101
101
  }
102
102
  /**
103
103
  * No retries — a tool may not be idempotent (a bare `@Step()` carries none, unlike `llm` above).
@@ -109,8 +109,14 @@ var AgentRunSteps = class {
109
109
  const ctx = {
110
110
  ...input.ctx
111
111
  };
112
- const invocation = deps.registry.invoke(input.toolName, input.input, ctx, deps.rolesPolicy);
113
- return input.timeoutMs !== void 0 ? (0, import_nestjs_agent_core.withToolTimeout)(invocation, input.timeoutMs, input.toolName) : invocation;
112
+ return (0, import_nestjs_agent_core.traceToolExecution)(input.ctx.runId, {
113
+ toolCallId: input.toolCallId,
114
+ toolName: input.toolName,
115
+ toolType: input.toolType
116
+ }, () => {
117
+ const invocation = deps.registry.invoke(input.toolName, input.input, ctx, deps.rolesPolicy);
118
+ return input.timeoutMs !== void 0 ? (0, import_nestjs_agent_core.withToolTimeout)(invocation, input.timeoutMs, input.toolName) : invocation;
119
+ });
114
120
  }
115
121
  };
116
122
  _ts_decorate([
@@ -127,7 +133,7 @@ _ts_decorate([
127
133
  (0, import_nestjs_durable.Step)(),
128
134
  _ts_metadata("design:type", Function),
129
135
  _ts_metadata("design:paramtypes", [
130
- typeof ToolStepEnvelope === "undefined" ? Object : ToolStepEnvelope
136
+ typeof DispatchedToolInput === "undefined" ? Object : DispatchedToolInput
131
137
  ]),
132
138
  _ts_metadata("design:returntype", Promise)
133
139
  ], AgentRunSteps.prototype, "tool", null);
@@ -188,8 +194,11 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
188
194
  openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
189
195
  awaitApproval: /* @__PURE__ */ __name((call) => ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`), "awaitApproval"),
190
196
  step: /* @__PURE__ */ __name((name, fn) => ctx.localStep(name, fn), "step"),
191
- // Dispatched-step suspends must escape the loop's tool catch — control flow, not a tool failure.
192
- isControlFlowError: /* @__PURE__ */ __name((error) => error instanceof import_nestjs_durable_core.WorkflowSuspended || error instanceof import_nestjs_durable_core.ContinueAsNew, "isControlFlowError"),
197
+ // Dispatched-step suspends must escape the loop's tool catch — control flow, not a tool
198
+ // failure. Marker-based predicate, NOT instanceof: the signal's CLASS differs by runtime
199
+ // (engine in-process throws durable-core's WorkflowSuspended/ContinueAsNew; the BullMQ thin
200
+ // worker throws durable-worker's own Suspend), so only the Symbol.for marker is reliable.
201
+ isControlFlowError: /* @__PURE__ */ __name((error) => (0, import_nestjs_durable_core.isWorkflowControlFlowSignal)(error), "isControlFlowError"),
193
202
  runAgent: /* @__PURE__ */ __name(async (agentName, task) => {
194
203
  const subThreadId = await ctx.localStep(`subthread:${agentName}`, async () => {
195
204
  const thread = await this.store.createThread({
@@ -213,13 +222,23 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
213
222
  // execution. `sinkRunId`/`childSink` are sink routing this workflow already resolved above —
214
223
  // core's dispatchLlm signature stays sink-topology-agnostic, so we add them here, not in core.
215
224
  ...this.dispatchedSteps ? {
216
- dispatchLlm: /* @__PURE__ */ __name((_index, envelope) => ctx.step(this.steps.llm, {
225
+ dispatchLlm: /* @__PURE__ */ __name((index, envelope) => ctx.step(this.steps.llm, {
217
226
  ...envelope,
218
227
  runId: ctx.runId,
228
+ step: index,
219
229
  sinkRunId,
220
230
  childSink: input.sinkRunId !== void 0
221
231
  }), "dispatchLlm"),
222
- dispatchTool: /* @__PURE__ */ __name((_call, envelope) => ctx.step(this.steps.tool, envelope), "dispatchTool")
232
+ // Fold the call identity (`toolCallId`/`toolType`) into the wire payload — the handler
233
+ // emits the `tool.execution` span with it. Only read/action calls reach dispatchTool
234
+ // ('agent'-kind delegations branch to runAgent earlier in the loop), so anything that
235
+ // isn't 'action' is defensively 'read' — the same posture core takes for an
236
+ // unresolvable `kind`.
237
+ dispatchTool: /* @__PURE__ */ __name((call, envelope) => ctx.step(this.steps.tool, {
238
+ ...envelope,
239
+ toolCallId: call.id,
240
+ toolType: call.kind === "action" ? "action" : "read"
241
+ }), "dispatchTool")
223
242
  } : {}
224
243
  };
225
244
  try {
@@ -230,7 +249,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
230
249
  await ctx.localStep("deactivate", () => this.store.setActiveStream(input.threadId, null));
231
250
  return result;
232
251
  } catch (error) {
233
- if (error instanceof import_nestjs_durable_core.WorkflowSuspended || error instanceof import_nestjs_durable_core.ContinueAsNew) {
252
+ if ((0, import_nestjs_durable_core.isWorkflowControlFlowSignal)(error)) {
234
253
  throw error;
235
254
  }
236
255
  const message = error instanceof Error ? error.message : String(error);
@@ -307,7 +326,7 @@ var DurableAgentRunner = class {
307
326
  try {
308
327
  await this.workflows.start(AgentRunWorkflow, stamped, runId);
309
328
  } catch (error) {
310
- if (!(error instanceof import_nestjs_durable_core2.WorkflowSuspended)) {
329
+ if (!(0, import_nestjs_durable_core2.isWorkflowControlFlowSignal)(error)) {
311
330
  throw error;
312
331
  }
313
332
  }