@dudousxd/nestjs-agent-core 0.15.2 → 0.15.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.
package/dist/index.cjs CHANGED
@@ -56,6 +56,7 @@ __export(index_exports, {
56
56
  DEFAULT_MAX_FACT_CHARS: () => DEFAULT_MAX_FACT_CHARS,
57
57
  DEFAULT_MAX_MEMORIES: () => DEFAULT_MAX_MEMORIES,
58
58
  DEFAULT_MAX_SKILLS: () => DEFAULT_MAX_SKILLS,
59
+ DEFAULT_REFUSAL_REASON: () => DEFAULT_REFUSAL_REASON,
59
60
  DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION: () => DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION,
60
61
  DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS: () => DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS,
61
62
  DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS: () => DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS,
@@ -3246,15 +3247,58 @@ async function runClaimedToolCall(turn, claimed) {
3246
3247
  name: call.name,
3247
3248
  output: {
3248
3249
  rejected: true,
3249
- reason: decision.reason ?? "rejected by user"
3250
+ reason: decision.reason ?? DEFAULT_REFUSAL_REASON
3250
3251
  },
3251
- error: "rejected"
3252
+ denied: true,
3253
+ // What the MODEL is told. It used to be the bare word `rejected`, which names no actor and
3254
+ // reads exactly like a tool that blew up — so the answer that followed would speculate about
3255
+ // causes ("the key may not exist", "there may be permission restrictions") and offer to try
3256
+ // again. A person's decision is not a fault to diagnose, so this says who decided, that
3257
+ // nothing ran, and what not to do next.
3258
+ error: refusalNarrative(decision.reason)
3252
3259
  };
3253
3260
  }
3254
3261
  }
3255
3262
  return recordToolOutcome(turn, claimed, await invokeClaimedTool(turn, claimed), deciderRef);
3256
3263
  }
3257
3264
  __name(runClaimedToolCall, "runClaimedToolCall");
3265
+ function outputFrame(result) {
3266
+ if (result.denied === true) {
3267
+ const reason = refusalReason(result);
3268
+ return {
3269
+ kind: "tool-output-denied",
3270
+ id: result.id,
3271
+ ...reason !== void 0 ? {
3272
+ reason
3273
+ } : {}
3274
+ };
3275
+ }
3276
+ return result.error !== void 0 ? {
3277
+ kind: "tool-output-error",
3278
+ id: result.id,
3279
+ error: result.error
3280
+ } : {
3281
+ kind: "tool-output",
3282
+ id: result.id,
3283
+ output: result.output
3284
+ };
3285
+ }
3286
+ __name(outputFrame, "outputFrame");
3287
+ function refusalReason(result) {
3288
+ const { output } = result;
3289
+ if (output !== null && typeof output === "object" && "reason" in output) {
3290
+ const reason = output.reason;
3291
+ return typeof reason === "string" && reason !== DEFAULT_REFUSAL_REASON ? reason : void 0;
3292
+ }
3293
+ return void 0;
3294
+ }
3295
+ __name(refusalReason, "refusalReason");
3296
+ var DEFAULT_REFUSAL_REASON = "rejected by user";
3297
+ function refusalNarrative(reason) {
3298
+ const base = "The person was asked to approve this action and declined it. Nothing ran and nothing changed. This is their decision, not an error, a missing record or a permissions problem \u2014 do not explain it as one, do not guess at causes, and do not run this action again or reach for another way to do the same thing. Acknowledge the decision and ask what they would like instead.";
3299
+ return reason === void 0 ? base : `${base} They said: ${reason}`;
3300
+ }
3301
+ __name(refusalNarrative, "refusalNarrative");
3258
3302
  async function invokeClaimedToolsTogether(turn, parallel, claimed) {
3259
3303
  const settled = await parallel(claimed.map((entry) => () => invokeClaimedTool(turn, entry)));
3260
3304
  for (const outcome of settled) {
@@ -3786,15 +3830,7 @@ ${block}`;
3786
3830
  await hooks.step(`stream:tool-outputs:${i}`, async () => {
3787
3831
  await deps.store.setMessageToolResults(assistant.id, settledResults);
3788
3832
  for (const result of results) {
3789
- await writer.write(encodeStreamEvent(result.error !== void 0 ? {
3790
- kind: "tool-output-error",
3791
- id: result.id,
3792
- error: result.error
3793
- } : {
3794
- kind: "tool-output",
3795
- id: result.id,
3796
- output: result.output
3797
- }));
3833
+ await writer.write(encodeStreamEvent(outputFrame(result)));
3798
3834
  }
3799
3835
  });
3800
3836
  await hooks.step(`stream:step-finish:${i}`, async () => {
@@ -3893,6 +3929,7 @@ __name(runAgentLoop, "runAgentLoop");
3893
3929
  DEFAULT_MAX_FACT_CHARS,
3894
3930
  DEFAULT_MAX_MEMORIES,
3895
3931
  DEFAULT_MAX_SKILLS,
3932
+ DEFAULT_REFUSAL_REASON,
3896
3933
  DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION,
3897
3934
  DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS,
3898
3935
  DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS,