@dudousxd/nestjs-agent 1.3.0 → 1.5.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.
package/dist/index.cjs CHANGED
@@ -528,6 +528,7 @@ var AgentService = class {
528
528
  */
529
529
  async answer(actor, toolCallId2, answers2 = {}) {
530
530
  await this.assertOwnsToolCall(actor, toolCallId2);
531
+ await this.assertAnswersFit(toolCallId2, answers2);
531
532
  const reply = {
532
533
  answers: answers2,
533
534
  answeredByRef: actor.id
@@ -796,6 +797,27 @@ var AgentService = class {
796
797
  }
797
798
  }
798
799
  /**
800
+ * Check a reply against the questions it answers before it is signalled: every submitted value a
801
+ * question's own rules accept (a typed input's type, bounds and pattern; a pick from the offered
802
+ * options), and every `required` question answered — by the reply, or by the defaults an omitted
803
+ * question falls back to. A reply the loop would have to drop parts of is refused here instead, so
804
+ * the person who typed it hears why. Needs the store to hand back the call's recorded questions;
805
+ * without that seam the loop's own filtering is the only check.
806
+ */
807
+ async assertAnswersFit(toolCallId2, answers2) {
808
+ if (this.store.toolCallInput === void 0) {
809
+ return;
810
+ }
811
+ const questions = (0, import_nestjs_agent_core3.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
812
+ for (const question of questions) {
813
+ const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
814
+ const problem = (0, import_nestjs_agent_core3.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
815
+ if (problem !== null) {
816
+ throw new import_common2.BadRequestException(`answers["${question.id}"] ${problem}`);
817
+ }
818
+ }
819
+ }
820
+ /**
799
821
  * Authorization seam for approve/reject. The call's recorded approver decides who may settle it:
800
822
  * the requester (the default, and every call recorded before approvers existed) is the thread's
801
823
  * own actor — the ownership check this always was; any other approver goes through the policy's
@@ -2447,6 +2469,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
2447
2469
  } : {},
2448
2470
  ...meta.presentation !== void 0 ? {
2449
2471
  presentation: meta.presentation
2472
+ } : {},
2473
+ ...meta.terminal === true ? {
2474
+ terminal: true
2450
2475
  } : {}
2451
2476
  }, {
2452
2477
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),