@carlonicora/nestjs-neo4jsonapi 2.4.2 → 2.5.1

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.
Files changed (76) hide show
  1. package/dist/agents/community.summariser/community.summariser.module.d.ts +7 -0
  2. package/dist/agents/community.summariser/community.summariser.module.d.ts.map +1 -1
  3. package/dist/agents/community.summariser/community.summariser.module.js +8 -6
  4. package/dist/agents/community.summariser/community.summariser.module.js.map +1 -1
  5. package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts +10 -1
  6. package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts.map +1 -1
  7. package/dist/agents/community.summariser/processors/community.summariser.processor.js +29 -2
  8. package/dist/agents/community.summariser/processors/community.summariser.processor.js.map +1 -1
  9. package/dist/common/decorators/conditional-service.decorator.d.ts.map +1 -1
  10. package/dist/common/decorators/conditional-service.decorator.js +11 -1
  11. package/dist/common/decorators/conditional-service.decorator.js.map +1 -1
  12. package/dist/common/enums/ai.status.d.ts +29 -1
  13. package/dist/common/enums/ai.status.d.ts.map +1 -1
  14. package/dist/common/enums/ai.status.js +28 -1
  15. package/dist/common/enums/ai.status.js.map +1 -1
  16. package/dist/common/helpers/credit-gate.d.ts +30 -0
  17. package/dist/common/helpers/credit-gate.d.ts.map +1 -0
  18. package/dist/common/helpers/credit-gate.js +43 -0
  19. package/dist/common/helpers/credit-gate.js.map +1 -0
  20. package/dist/common/helpers/index.d.ts +1 -0
  21. package/dist/common/helpers/index.d.ts.map +1 -1
  22. package/dist/common/helpers/index.js +1 -0
  23. package/dist/common/helpers/index.js.map +1 -1
  24. package/dist/common/tokens.d.ts +51 -0
  25. package/dist/common/tokens.d.ts.map +1 -1
  26. package/dist/common/tokens.js +44 -1
  27. package/dist/common/tokens.js.map +1 -1
  28. package/dist/core/llm/index.d.ts +1 -0
  29. package/dist/core/llm/index.d.ts.map +1 -1
  30. package/dist/core/llm/index.js +1 -0
  31. package/dist/core/llm/index.js.map +1 -1
  32. package/dist/core/llm/services/model.service.d.ts.map +1 -1
  33. package/dist/core/llm/services/model.service.js +7 -0
  34. package/dist/core/llm/services/model.service.js.map +1 -1
  35. package/dist/core/llm/utils/vertex.utils.d.ts +58 -0
  36. package/dist/core/llm/utils/vertex.utils.d.ts.map +1 -0
  37. package/dist/core/llm/utils/vertex.utils.js +69 -0
  38. package/dist/core/llm/utils/vertex.utils.js.map +1 -0
  39. package/dist/foundations/assistant/controllers/assistant.controller.d.ts +3 -1
  40. package/dist/foundations/assistant/controllers/assistant.controller.d.ts.map +1 -1
  41. package/dist/foundations/assistant/controllers/assistant.controller.js +10 -2
  42. package/dist/foundations/assistant/controllers/assistant.controller.js.map +1 -1
  43. package/dist/foundations/chunk/chunk.module.d.ts +8 -0
  44. package/dist/foundations/chunk/chunk.module.d.ts.map +1 -1
  45. package/dist/foundations/chunk/chunk.module.js +8 -0
  46. package/dist/foundations/chunk/chunk.module.js.map +1 -1
  47. package/dist/foundations/chunk/processors/chunk.embedding.processor.d.ts +6 -1
  48. package/dist/foundations/chunk/processors/chunk.embedding.processor.d.ts.map +1 -1
  49. package/dist/foundations/chunk/processors/chunk.embedding.processor.js +14 -2
  50. package/dist/foundations/chunk/processors/chunk.embedding.processor.js.map +1 -1
  51. package/dist/foundations/chunk/processors/chunk.processor.d.ts +34 -1
  52. package/dist/foundations/chunk/processors/chunk.processor.d.ts.map +1 -1
  53. package/dist/foundations/chunk/processors/chunk.processor.js +51 -2
  54. package/dist/foundations/chunk/processors/chunk.processor.js.map +1 -1
  55. package/dist/foundations/community/entities/community.entity.d.ts +2 -0
  56. package/dist/foundations/community/entities/community.entity.d.ts.map +1 -1
  57. package/dist/foundations/community/entities/community.map.d.ts.map +1 -1
  58. package/dist/foundations/community/entities/community.map.js +1 -0
  59. package/dist/foundations/community/entities/community.map.js.map +1 -1
  60. package/dist/foundations/community/index.d.ts +7 -0
  61. package/dist/foundations/community/index.d.ts.map +1 -0
  62. package/dist/foundations/community/index.js +14 -0
  63. package/dist/foundations/community/index.js.map +1 -0
  64. package/dist/foundations/community/repositories/community.repository.d.ts +15 -0
  65. package/dist/foundations/community/repositories/community.repository.d.ts.map +1 -1
  66. package/dist/foundations/community/repositories/community.repository.js +58 -0
  67. package/dist/foundations/community/repositories/community.repository.js.map +1 -1
  68. package/dist/foundations/company/services/company.service.d.ts +6 -1
  69. package/dist/foundations/company/services/company.service.d.ts.map +1 -1
  70. package/dist/foundations/company/services/company.service.js +18 -6
  71. package/dist/foundations/company/services/company.service.js.map +1 -1
  72. package/dist/foundations/index.d.ts +1 -0
  73. package/dist/foundations/index.d.ts.map +1 -1
  74. package/dist/foundations/index.js +1 -0
  75. package/dist/foundations/index.js.map +1 -1
  76. package/package.json +1 -1
@@ -1,3 +1,10 @@
1
+ /**
2
+ * `CompanyModule` is deliberately NOT imported (same rule as
3
+ * `agents/drift/drift.module.ts`): it declares `CompanyController`, so importing
4
+ * it mounts `companies/*` into every consumer and crashes any app that replaces
5
+ * the company foundation with its own controller. The processor's credit gate
6
+ * uses the optional `CREDIT_VALIDATOR` seam — see `common/helpers/credit-gate.ts`.
7
+ */
1
8
  export declare class CommunitySummariserModule {
2
9
  }
3
10
  //# sourceMappingURL=community.summariser.module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"community.summariser.module.d.ts","sourceRoot":"","sources":["../../../src/agents/community.summariser/community.summariser.module.ts"],"names":[],"mappings":"AAWA,qBAUa,yBAAyB;CAAG"}
1
+ {"version":3,"file":"community.summariser.module.d.ts","sourceRoot":"","sources":["../../../src/agents/community.summariser/community.summariser.module.ts"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,qBAKa,yBAAyB;CAAG"}
@@ -17,17 +17,19 @@ const conditional_service_decorator_1 = require("../../common/decorators/conditi
17
17
  const community_summariser_processor_1 = require("./processors/community.summariser.processor");
18
18
  const community_summariser_service_1 = require("./services/community.summariser.service");
19
19
  const community_summariser_cron_1 = require("./cron/community.summariser.cron");
20
+ /**
21
+ * `CompanyModule` is deliberately NOT imported (same rule as
22
+ * `agents/drift/drift.module.ts`): it declares `CompanyController`, so importing
23
+ * it mounts `companies/*` into every consumer and crashes any app that replaces
24
+ * the company foundation with its own controller. The processor's credit gate
25
+ * uses the optional `CREDIT_VALIDATOR` seam — see `common/helpers/credit-gate.ts`.
26
+ */
20
27
  let CommunitySummariserModule = class CommunitySummariserModule {
21
28
  };
22
29
  exports.CommunitySummariserModule = CommunitySummariserModule;
23
30
  exports.CommunitySummariserModule = CommunitySummariserModule = __decorate([
24
31
  (0, common_1.Module)({
25
- imports: [
26
- llm_module_1.LLMModule,
27
- logging_module_1.LoggingModule,
28
- community_module_1.CommunityModule,
29
- bullmq_1.BullModule.registerQueue({ name: config_1.QueueId.COMMUNITY_SUMMARISER }),
30
- ],
32
+ imports: [llm_module_1.LLMModule, logging_module_1.LoggingModule, community_module_1.CommunityModule, bullmq_1.BullModule.registerQueue({ name: config_1.QueueId.COMMUNITY_SUMMARISER })],
31
33
  providers: [community_summariser_service_1.CommunitySummariserService, community_summariser_processor_1.CommunitySummariserProcessor, (0, conditional_service_decorator_1.createWorkerProvider)(community_summariser_cron_1.CommunitySummariserCron)],
32
34
  exports: [community_summariser_service_1.CommunitySummariserService],
33
35
  })
@@ -1 +1 @@
1
- {"version":3,"file":"community.summariser.module.js","sourceRoot":"","sources":["../../../src/agents/community.summariser/community.summariser.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,yCAAuC;AACvC,0DAAsD;AACtD,sEAAkE;AAClE,mFAA+E;AAC/E,yGAA6F;AAC7F,gGAA2F;AAC3F,0FAAqF;AACrF,gFAA2E;AAYpE,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;CAAG,CAAA;AAA5B,8DAAyB;oCAAzB,yBAAyB;IAVrC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,sBAAS;YACT,8BAAa;YACb,kCAAe;YACf,mBAAU,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,gBAAO,CAAC,oBAAoB,EAAE,CAAC;SACjE;QACD,SAAS,EAAE,CAAC,yDAA0B,EAAE,6DAA4B,EAAE,IAAA,oDAAoB,EAAC,mDAAuB,CAAC,CAAC;QACpH,OAAO,EAAE,CAAC,yDAA0B,CAAC;KACtC,CAAC;GACW,yBAAyB,CAAG"}
1
+ {"version":3,"file":"community.summariser.module.js","sourceRoot":"","sources":["../../../src/agents/community.summariser/community.summariser.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,yCAAuC;AACvC,0DAAsD;AACtD,sEAAkE;AAClE,mFAA+E;AAC/E,yGAA6F;AAC7F,gGAA2F;AAC3F,0FAAqF;AACrF,gFAA2E;AAE3E;;;;;;GAMG;AAMI,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;CAAG,CAAA;AAA5B,8DAAyB;oCAAzB,yBAAyB;IALrC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAS,EAAE,8BAAa,EAAE,kCAAe,EAAE,mBAAU,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,gBAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;QACtH,SAAS,EAAE,CAAC,yDAA0B,EAAE,6DAA4B,EAAE,IAAA,oDAAoB,EAAC,mDAAuB,CAAC,CAAC;QACpH,OAAO,EAAE,CAAC,yDAA0B,CAAC;KACtC,CAAC;GACW,yBAAyB,CAAG"}
@@ -1,7 +1,10 @@
1
1
  import { WorkerHost } from "@nestjs/bullmq";
2
2
  import { Job } from "bullmq";
3
3
  import { ClsService } from "nestjs-cls";
4
+ import { CreditValidatorInterface } from "../../../common/tokens";
4
5
  import { AppLoggingService } from "../../../core/logging/services/logging.service";
6
+ import { WebSocketService } from "../../../core/websocket/services/websocket.service";
7
+ import { CommunityRepository } from "../../../foundations/community/repositories/community.repository";
5
8
  import { CommunitySummariserService } from "../services/community.summariser.service";
6
9
  interface CommunitySummariserJobData {
7
10
  communityId: string;
@@ -11,7 +14,13 @@ export declare class CommunitySummariserProcessor extends WorkerHost {
11
14
  private readonly summariserService;
12
15
  private readonly cls;
13
16
  private readonly logger;
14
- constructor(summariserService: CommunitySummariserService, cls: ClsService, logger: AppLoggingService);
17
+ private readonly communityRepository;
18
+ private readonly webSocketService;
19
+ /** See ChunkProcessor: seam, not CompanyService — CompanyModule would mount `companies/*` here. */
20
+ private readonly creditValidator?;
21
+ constructor(summariserService: CommunitySummariserService, cls: ClsService, logger: AppLoggingService, communityRepository: CommunityRepository, webSocketService: WebSocketService,
22
+ /** See ChunkProcessor: seam, not CompanyService — CompanyModule would mount `companies/*` here. */
23
+ creditValidator?: CreditValidatorInterface);
15
24
  onActive(job: Job): void;
16
25
  onError(job: Job): void;
17
26
  onCompleted(job: Job): void;
@@ -1 +1 @@
1
- {"version":3,"file":"community.summariser.processor.d.ts","sourceRoot":"","sources":["../../../../src/agents/community.summariser/processors/community.summariser.processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAEtF,UAAU,0BAA0B;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBACa,4BAA6B,SAAQ,UAAU;IAExD,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,iBAAiB,EAAE,0BAA0B,EAC7C,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,iBAAiB;IAM5C,QAAQ,CAAC,GAAG,EAAE,GAAG;IAKjB,OAAO,CAAC,GAAG,EAAE,GAAG;IAOhB,WAAW,CAAC,GAAG,EAAE,GAAG;IAId,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBnE"}
1
+ {"version":3,"file":"community.summariser.processor.d.ts","sourceRoot":"","sources":["../../../../src/agents/community.summariser/processors/community.summariser.processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAoB,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kEAAkE,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAEtF,UAAU,0BAA0B;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBACa,4BAA6B,SAAQ,UAAU;IAExD,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,mGAAmG;IAGnG,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;gBARhB,iBAAiB,EAAE,0BAA0B,EAC7C,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,iBAAiB,EACzB,mBAAmB,EAAE,mBAAmB,EACxC,gBAAgB,EAAE,gBAAgB;IACnD,mGAAmG;IAGlF,eAAe,CAAC,EAAE,wBAAwB;IAM7D,QAAQ,CAAC,GAAG,EAAE,GAAG;IAKjB,OAAO,CAAC,GAAG,EAAE,GAAG;IAOhB,WAAW,CAAC,GAAG,EAAE,GAAG;IAId,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,0BAA0B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAkCnE"}
@@ -8,20 +8,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.CommunitySummariserProcessor = void 0;
13
16
  const bullmq_1 = require("@nestjs/bullmq");
17
+ const common_1 = require("@nestjs/common");
14
18
  const bullmq_2 = require("bullmq");
15
19
  const nestjs_cls_1 = require("nestjs-cls");
20
+ const credit_gate_1 = require("../../../common/helpers/credit-gate");
21
+ const tokens_1 = require("../../../common/tokens");
16
22
  const config_1 = require("../../../config");
17
23
  const logging_service_1 = require("../../../core/logging/services/logging.service");
24
+ const websocket_service_1 = require("../../../core/websocket/services/websocket.service");
25
+ const community_repository_1 = require("../../../foundations/community/repositories/community.repository");
18
26
  const community_summariser_service_1 = require("../services/community.summariser.service");
19
27
  let CommunitySummariserProcessor = class CommunitySummariserProcessor extends bullmq_1.WorkerHost {
20
- constructor(summariserService, cls, logger) {
28
+ constructor(summariserService, cls, logger, communityRepository, webSocketService, creditValidator) {
21
29
  super();
22
30
  this.summariserService = summariserService;
23
31
  this.cls = cls;
24
32
  this.logger = logger;
33
+ this.communityRepository = communityRepository;
34
+ this.webSocketService = webSocketService;
35
+ this.creditValidator = creditValidator;
25
36
  }
26
37
  onActive(job) {
27
38
  this.logger.debug(`Processing community summariser job ${job.name} (ID: ${job.id})`);
@@ -36,6 +47,18 @@ let CommunitySummariserProcessor = class CommunitySummariserProcessor extends bu
36
47
  const { communityId, companyId } = job.data;
37
48
  await this.cls.run(async () => {
38
49
  this.cls.set("companyId", companyId);
50
+ if (!(await (0, credit_gate_1.hasAvailableCreditsVia)(this.creditValidator, { companyId }))) {
51
+ // Leave isStale set; flag pendingCredits so the 10-minute cron stops
52
+ // re-enqueueing it (spec §2: a fresh top-up must not be silently eaten).
53
+ await this.communityRepository.markPendingCredits(communityId);
54
+ // Deferrals happen without spend, so the frontend needs this push (spec §4.5).
55
+ await this.webSocketService.sendMessageToCompany(companyId, "company:ai_backlog_updated", {
56
+ type: "company:ai_backlog_updated",
57
+ companyId,
58
+ });
59
+ this.logger.log(`Deferred community summarisation for community ${communityId} (company ${companyId}) — no available credits`, "CommunitySummariserProcessor");
60
+ return;
61
+ }
39
62
  this.logger.log(`Starting community summarisation for community ${communityId} (company ${companyId})`, "CommunitySummariserProcessor");
40
63
  await this.summariserService.generateSummaryById(communityId);
41
64
  this.logger.log(`Completed community summarisation for community ${communityId}`, "CommunitySummariserProcessor");
@@ -63,8 +86,12 @@ __decorate([
63
86
  ], CommunitySummariserProcessor.prototype, "onCompleted", null);
64
87
  exports.CommunitySummariserProcessor = CommunitySummariserProcessor = __decorate([
65
88
  (0, bullmq_1.Processor)(config_1.QueueId.COMMUNITY_SUMMARISER, { concurrency: 1, lockDuration: 1000 * 60 * 5 }),
89
+ __param(5, (0, common_1.Optional)()),
90
+ __param(5, (0, common_1.Inject)(tokens_1.CREDIT_VALIDATOR)),
66
91
  __metadata("design:paramtypes", [community_summariser_service_1.CommunitySummariserService,
67
92
  nestjs_cls_1.ClsService,
68
- logging_service_1.AppLoggingService])
93
+ logging_service_1.AppLoggingService,
94
+ community_repository_1.CommunityRepository,
95
+ websocket_service_1.WebSocketService, Object])
69
96
  ], CommunitySummariserProcessor);
70
97
  //# sourceMappingURL=community.summariser.processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"community.summariser.processor.js","source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AM,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAE9D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mDAAmD,WAAW,EAAE,EAAE,8BAA8B,CAAC,CAAC;QACpH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA1CY,oEAA4B;AAUvC;IADC,IAAA,sBAAa,EAAC,QAAQ,CAAC;;qCACV,YAAG;;4DAEhB;AAGD;IADC,IAAA,sBAAa,EAAC,QAAQ,CAAC;;qCACX,YAAG;;2DAIf;AAGD;IADC,IAAA,sBAAa,EAAC,WAAW,CAAC;;qCACV,YAAG;;+DAEnB;uCAxBU,4BAA4B;IADxC,IAAA,kBAAS,EAAC,gBAAO,CAAC,oBAAoB,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;qCAGjD,yDAA0B;QACxC,uBAAU;QACP,mCAAiB;GAJjC,4BAA4B,CA0CxC"}
1
+ {"version":3,"file":"community.summariser.processor.js","sourceRoot":"","sources":["../../../../src/agents/community.summariser/processors/community.summariser.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsE;AACtE,2CAAkD;AAClD,mCAA6B;AAC7B,2CAAwC;AACxC,qEAA6E;AAC7E,mDAAoF;AACpF,4CAA0C;AAC1C,oFAAmF;AACnF,0FAAsF;AACtF,2GAAuG;AACvG,2FAAsF;AAQ/E,IAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,mBAAU;IAC1D,YACmB,iBAA6C,EAC7C,GAAe,EACf,MAAyB,EACzB,mBAAwC,EACxC,gBAAkC,EAIlC,eAA0C;QAE3D,KAAK,EAAE,CAAC;QAVS,sBAAiB,GAAjB,iBAAiB,CAA4B;QAC7C,QAAG,GAAH,GAAG,CAAY;QACf,WAAM,GAAN,MAAM,CAAmB;QACzB,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,qBAA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S,0BAA0B,EAC7G,8BAA8B,CAC/B,CAAC;gBACF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,kDAAkD,WAAW,aAAa,SAAS,GAAG,EACtF,8BAA8B,CAC/B,CAAC;YAEF,MAAM,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAE9D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mDAAmD,WAAW,EAAE,EAAE,8BAA8B,CAAC,CAAC;QACpH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAlEY,oEAA4B;AAgBvC;IADC,IAAA,sBAAa,EAAC,QAAQ,CAAC;;qCACV,YAAG;;4DAEhB;AAGD;IADC,IAAA,sBAAa,EAAC,QAAQ,CAAC;;qCACX,YAAG;;2DAIf;AAGD;IADC,IAAA,sBAAa,EAAC,WAAW,CAAC;;qCACV,YAAG;;+DAEnB;uCA9BU,4BAA4B;IADxC,IAAA,kBAAS,EAAC,gBAAO,CAAC,oBAAoB,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IASpF,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,yBAAgB,CAAC,CAAA;qCAPW,yDAA0B;QACxC,uBAAU;QACP,mCAAiB;QACJ,0CAAmB;QACtB,oCAAgB;GAN1C,4BAA4B,CAkExC"}
@@ -1 +1 @@
1
- {"version":3,"file":"conditional-service.decorator.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/conditional-service.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,oBAAY,OAAO;IACjB,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,eAA2B,CAAC;AAiBvD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,QAAQ,CAYhH;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAEzF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAEtF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAc5F;AAED;;GAEG;AACH,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IAElC,UAAU,CAAC,OAAO,EAAE,aAAa;IAIjC,SAAS,CAAC,SAAS,IAAI,OAAO;IAI9B,SAAS,CAAC,YAAY,IAAI,OAAO;IAIjC,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAItC,SAAS,CAAC,iBAAiB,IAAI,OAAO;CAGvC"}
1
+ {"version":3,"file":"conditional-service.decorator.d.ts","sourceRoot":"","sources":["../../../src/common/decorators/conditional-service.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,oBAAY,OAAO;IACjB,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,eAA2B,CAAC;AA6BvD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,QAAQ,CAYhH;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAEzF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAEtF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,QAAQ,CAc5F;AAED;;GAEG;AACH,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IAElC,UAAU,CAAC,OAAO,EAAE,aAAa;IAIjC,SAAS,CAAC,SAAS,IAAI,OAAO;IAI9B,SAAS,CAAC,YAAY,IAAI,OAAO;IAIjC,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAItC,SAAS,CAAC,iBAAiB,IAAI,OAAO;CAGvC"}
@@ -21,15 +21,25 @@ exports.APP_MODE_TOKEN = Symbol("APP_MODE_TOKEN");
21
21
  /**
22
22
  * Resolves constructor injection tokens, accounting for @Inject() decorator overrides.
23
23
  * NestJS stores custom tokens (from @Inject, @InjectQueue, etc.) in 'self:paramtypes' metadata.
24
+ *
25
+ * `@Optional()` is honoured too. Nest records the optional parameter INDEXES in
26
+ * 'optional:paramtypes' (OPTIONAL_DEPS_METADATA); a factory provider expresses
27
+ * optionality as `{ token, optional: true }` in its `inject` array, so a bare
28
+ * token is ALWAYS required. Without this, a class wrapped by
29
+ * `createWorkerProvider`/`createApiProvider` loses its `@Optional()` markers and
30
+ * the app crashes at boot with `UnknownDependenciesException` whenever an
31
+ * optional seam (e.g. CREDIT_VALIDATOR, TOKEN_USAGE_RECORDER) is unbound — a
32
+ * failure only reproducible in a consumer that does NOT bind that seam.
24
33
  */
25
34
  function resolveInjectionTokens(ServiceClass) {
26
35
  const paramTypes = Reflect.getMetadata("design:paramtypes", ServiceClass) || [];
27
36
  const customTokens = Reflect.getMetadata("self:paramtypes", ServiceClass) || [];
37
+ const optionalIndexes = Reflect.getMetadata("optional:paramtypes", ServiceClass) || [];
28
38
  const tokens = [...paramTypes];
29
39
  for (const { index, param } of customTokens) {
30
40
  tokens[index] = param;
31
41
  }
32
- return tokens;
42
+ return tokens.map((token, index) => (optionalIndexes.includes(index) ? { token, optional: true } : token));
33
43
  }
34
44
  /**
35
45
  * Helper function to create conditional providers based on app mode
@@ -1 +1 @@
1
- {"version":3,"file":"conditional-service.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/conditional-service.decorator.ts"],"names":[],"mappings":";;;AA4CA,8DAYC;AAKD,oDAEC;AAKD,8CAEC;AAKD,0DAcC;AAxFD,4BAA0B;AAE1B;;GAEG;AACH,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,sBAAW,CAAA;IACX,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAYD;;GAEG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD;;;GAGG;AACH,SAAS,sBAAsB,CAAC,YAAyC;IACvE,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,mBA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B,UAAU,EAAE,CAAC,OAAsB,EAAE,GAAG,IAAW,EAAE,EAAE;YACrD,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;YAE3C,IAAI,OAAQ,QAAgB,CAAC,UAAU,KAAK,UAAU;gBAAG,QAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAE9F,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,EAAE,CAAC,sBAAc,EAAE,GAAG,MAAM,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAsB,gBAAgB;IAGpC,UAAU,CAAC,OAAsB;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,SAAS;QACjB,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC;IAC5C,CAAC;IAES,YAAY;QACpB,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC;IAC/C,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,CAAC;CACF;AAtBD,4CAsBC"}
1
+ {"version":3,"file":"conditional-service.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/conditional-service.decorator.ts"],"names":[],"mappings":";;;AAwDA,8DAYC;AAKD,oDAEC;AAKD,8CAEC;AAKD,0DAcC;AApGD,4BAA0B;AAE1B;;GAEG;AACH,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,sBAAW,CAAA;IACX,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAYD;;GAEG;AACU,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD;;;;;;;;;;;;GA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@@ -1,8 +1,36 @@
1
+ /**
2
+ * Two AI-status vocabularies coexist in this codebase — DO NOT unify them:
3
+ *
4
+ * - `AiStatus` (this enum) is the CHUNK-level vocabulary (lowercase snake_case
5
+ * values) used by content-chunking / transcription pipelines.
6
+ * - `EntityAiStatus` (below) is the ENTITY-level vocabulary (PascalCase values)
7
+ * already persisted on narr8's 13 KG entities (Campaign, Clue, Consequence,
8
+ * Decision, Event, Faction, Goal, Item, Location, Npc, Pc, Secret, Threat).
9
+ *
10
+ * Stored values in both are PERMANENT — once written to Neo4j they may never be
11
+ * renamed, only appended to. This mirrors the precedent set by
12
+ * `Narr8TokenUsageType`.
13
+ */
1
14
  export declare enum AiStatus {
2
15
  Pending = "pending",
3
16
  InProgress = "in_progress",
4
17
  Completed = "completed",
5
18
  Failed = "failed",
6
- Summarising = "summarising"
19
+ Summarising = "summarising",
20
+ PendingCredits = "pending_credits",
21
+ Discarded = "discarded"
7
22
  }
23
+ /**
24
+ * Entity-level AI status vocabulary (PascalCase values are what narr8's 13 KG
25
+ * entities already store). VALUES ARE PERMANENT — see the vocabulary note above.
26
+ */
27
+ export declare const EntityAiStatus: {
28
+ readonly Pending: "Pending";
29
+ readonly Summarising: "Summarising";
30
+ readonly Completed: "Completed";
31
+ readonly Failed: "Failed";
32
+ readonly PendingCredits: "PendingCredits";
33
+ readonly Discarded: "Discarded";
34
+ };
35
+ export type EntityAiStatus = (typeof EntityAiStatus)[keyof typeof EntityAiStatus];
8
36
  //# sourceMappingURL=ai.status.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai.status.d.ts","sourceRoot":"","sources":["../../../src/common/enums/ai.status.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,UAAU,gBAAgB;IAC1B,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,WAAW,gBAAgB;CAC5B"}
1
+ {"version":3,"file":"ai.status.d.ts","sourceRoot":"","sources":["../../../src/common/enums/ai.status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,UAAU,gBAAgB;IAC1B,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,WAAW,gBAAgB;IAC3B,cAAc,oBAAoB;IAClC,SAAS,cAAc;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;;;;CAOjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AiStatus = void 0;
3
+ exports.EntityAiStatus = exports.AiStatus = void 0;
4
+ /**
5
+ * Two AI-status vocabularies coexist in this codebase — DO NOT unify them:
6
+ *
7
+ * - `AiStatus` (this enum) is the CHUNK-level vocabulary (lowercase snake_case
8
+ * values) used by content-chunking / transcription pipelines.
9
+ * - `EntityAiStatus` (below) is the ENTITY-level vocabulary (PascalCase values)
10
+ * already persisted on narr8's 13 KG entities (Campaign, Clue, Consequence,
11
+ * Decision, Event, Faction, Goal, Item, Location, Npc, Pc, Secret, Threat).
12
+ *
13
+ * Stored values in both are PERMANENT — once written to Neo4j they may never be
14
+ * renamed, only appended to. This mirrors the precedent set by
15
+ * `Narr8TokenUsageType`.
16
+ */
4
17
  var AiStatus;
5
18
  (function (AiStatus) {
6
19
  AiStatus["Pending"] = "pending";
@@ -8,5 +21,19 @@ var AiStatus;
8
21
  AiStatus["Completed"] = "completed";
9
22
  AiStatus["Failed"] = "failed";
10
23
  AiStatus["Summarising"] = "summarising";
24
+ AiStatus["PendingCredits"] = "pending_credits";
25
+ AiStatus["Discarded"] = "discarded";
11
26
  })(AiStatus || (exports.AiStatus = AiStatus = {}));
27
+ /**
28
+ * Entity-level AI status vocabulary (PascalCase values are what narr8's 13 KG
29
+ * entities already store). VALUES ARE PERMANENT — see the vocabulary note above.
30
+ */
31
+ exports.EntityAiStatus = {
32
+ Pending: "Pending",
33
+ Summarising: "Summarising",
34
+ Completed: "Completed",
35
+ Failed: "Failed",
36
+ PendingCredits: "PendingCredits",
37
+ Discarded: "Discarded",
38
+ };
12
39
  //# sourceMappingURL=ai.status.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai.status.js","sourceRoot":"","sources":["../../../src/common/enums/ai.status.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,+BAAmB,CAAA;IACnB,sCAA0B,CAAA;IAC1B,mCAAuB,CAAA;IACvB,6BAAiB,CAAA;IACjB,uCAA2B,CAAA;AAC7B,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB"}
1
+ {"version":3,"file":"ai.status.js","sourceRoot":"","sources":["../../../src/common/enums/ai.status.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,IAAY,QAQX;AARD,WAAY,QAAQ;IAClB,+BAAmB,CAAA;IACnB,sCAA0B,CAAA;IAC1B,mCAAuB,CAAA;IACvB,6BAAiB,CAAA;IACjB,uCAA2B,CAAA;IAC3B,8CAAkC,CAAA;IAClC,mCAAuB,CAAA;AACzB,CAAC,EARW,QAAQ,wBAAR,QAAQ,QAQnB;AAED;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,cAAc,EAAE,gBAAgB;IAChC,SAAS,EAAE,WAAW;CACd,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { CreditValidatorInterface } from "../tokens";
2
+ /**
3
+ * Non-throwing credit probe for background work.
4
+ *
5
+ * Job processors must DEFER rather than fail when a company is out of credits,
6
+ * so they need a boolean answer. The `CREDIT_VALIDATOR` seam
7
+ * (`common/tokens.ts`) deliberately exposes only the throwing
8
+ * `validateCredits`, because its other consumers (HTTP controllers) want the
9
+ * 402 to propagate. This adapts one to the other.
10
+ *
11
+ * Why the seam rather than injecting `CompanyService` directly: `CompanyModule`
12
+ * declares `CompanyController`, so importing it into a processor's module
13
+ * mounts `companies/*` into every consumer and crashes any app that replaces
14
+ * the company foundation with its own controller (the same reasoning already
15
+ * documented in `agents/drift/drift.module.ts`).
16
+ *
17
+ * Semantics:
18
+ * - No validator bound (app never registered one) → `true`, i.e. ungated,
19
+ * matching the "unchanged behaviour for consumers that opt out" contract.
20
+ * - Validator throws 402 `NO_CREDITS` → `false`, caller defers.
21
+ * - Validator throws anything else (company lookup failed, Neo4j down, …) →
22
+ * RETHROWN. Those are real errors and must not be silently mistaken for an
23
+ * empty balance, which would defer the job forever instead of retrying it.
24
+ * - Credits disabled (`creditCost <= 0`) → the validator is a documented no-op,
25
+ * so this returns `true`.
26
+ */
27
+ export declare function hasAvailableCreditsVia(validator: CreditValidatorInterface | undefined, params: {
28
+ companyId: string;
29
+ }): Promise<boolean>;
30
+ //# sourceMappingURL=credit-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-gate.d.ts","sourceRoot":"","sources":["../../../src/common/helpers/credit-gate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,wBAAwB,GAAG,SAAS,EAC/C,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC,OAAO,CAAC,CAUlB"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasAvailableCreditsVia = hasAvailableCreditsVia;
4
+ const common_1 = require("@nestjs/common");
5
+ /**
6
+ * Non-throwing credit probe for background work.
7
+ *
8
+ * Job processors must DEFER rather than fail when a company is out of credits,
9
+ * so they need a boolean answer. The `CREDIT_VALIDATOR` seam
10
+ * (`common/tokens.ts`) deliberately exposes only the throwing
11
+ * `validateCredits`, because its other consumers (HTTP controllers) want the
12
+ * 402 to propagate. This adapts one to the other.
13
+ *
14
+ * Why the seam rather than injecting `CompanyService` directly: `CompanyModule`
15
+ * declares `CompanyController`, so importing it into a processor's module
16
+ * mounts `companies/*` into every consumer and crashes any app that replaces
17
+ * the company foundation with its own controller (the same reasoning already
18
+ * documented in `agents/drift/drift.module.ts`).
19
+ *
20
+ * Semantics:
21
+ * - No validator bound (app never registered one) → `true`, i.e. ungated,
22
+ * matching the "unchanged behaviour for consumers that opt out" contract.
23
+ * - Validator throws 402 `NO_CREDITS` → `false`, caller defers.
24
+ * - Validator throws anything else (company lookup failed, Neo4j down, …) →
25
+ * RETHROWN. Those are real errors and must not be silently mistaken for an
26
+ * empty balance, which would defer the job forever instead of retrying it.
27
+ * - Credits disabled (`creditCost <= 0`) → the validator is a documented no-op,
28
+ * so this returns `true`.
29
+ */
30
+ async function hasAvailableCreditsVia(validator, params) {
31
+ if (!validator)
32
+ return true;
33
+ try {
34
+ await validator.validateCredits({ companyId: params.companyId });
35
+ return true;
36
+ }
37
+ catch (error) {
38
+ if (error instanceof common_1.HttpException && error.getStatus() === common_1.HttpStatus.PAYMENT_REQUIRED)
39
+ return false;
40
+ throw error;
41
+ }
42
+ }
43
+ //# sourceMappingURL=credit-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-gate.js","sourceRoot":"","sources":["../../../src/common/helpers/credit-gate.ts"],"names":[],"mappings":";;AA4BA,wDAaC;AAzCD,2CAA2D;AAG3D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACI,KAAK,UAAU,sBAAsB,CAC1C,SAA+C,EAC/C,MAA6B;IAE7B,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAE5B,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,sBAAa,IAAI,KAAK,CAAC,SAAS,EAAE,KAAK,mBAAU,CAAC,gBAAgB;YAAE,OAAO,KAAK,CAAC;QACtG,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from "./credit-gate";
1
2
  export * from "./define-entity";
2
3
  export * from "./map-with-concurrency";
3
4
  export * from "./neo4j-date";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC"}
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./credit-gate"), exports);
17
18
  __exportStar(require("./define-entity"), exports);
18
19
  __exportStar(require("./map-with-concurrency"), exports);
19
20
  __exportStar(require("./neo4j-date"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,yDAAuC;AACvC,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,kDAAgC;AAChC,yDAAuC;AACvC,+CAA6B"}
@@ -80,4 +80,55 @@ export interface TokenUsageRecorderInterface {
80
80
  costOverride?: number;
81
81
  }): Promise<void>;
82
82
  }
83
+ /**
84
+ * Application-provided seam for gating AI operations on available company
85
+ * credits. Mirrors `TOKEN_USAGE_RECORDER` above: package code that needs to
86
+ * enforce the credit gate resolves this OPTIONAL token rather than injecting
87
+ * `CompanyService` directly, so consumers that never register a provider see
88
+ * unchanged (ungated) behaviour.
89
+ *
90
+ * `validateCredits` MUST throw `HttpException("NO_CREDITS", HttpStatus.PAYMENT_REQUIRED)`
91
+ * when the company has no available credits, and MUST be a no-op (never throw)
92
+ * when credits are disabled (`creditCost <= 0`).
93
+ *
94
+ * ## THE GATE FAILS OPEN — read this before relying on it
95
+ *
96
+ * Background job processors (`ChunkProcessor`, `ChunkEmbeddingProcessor`,
97
+ * `CommunitySummariserProcessor`) consult this seam through
98
+ * `hasAvailableCreditsVia` (`common/helpers/credit-gate.ts`), which turns the
99
+ * throwing contract above into the non-throwing boolean a processor needs in
100
+ * order to DEFER rather than fail. Its semantics:
101
+ *
102
+ * | Situation | Result |
103
+ * |---------------------------------------------|-----------------------------------------------|
104
+ * | No provider bound for `CREDIT_VALIDATOR` | `true` — work proceeds UNGATED |
105
+ * | Validator throws 402 `NO_CREDITS` | `false` — job defers (marked `PendingCredits`) |
106
+ * | Validator throws anything else | rethrown — never read as an empty balance |
107
+ * | Credits disabled (`creditCost <= 0`) | `true` — validator is a documented no-op |
108
+ *
109
+ * The first row is the dangerous one: **an application that intends to enforce
110
+ * credits but forgets to bind this token runs entirely ungated, silently.**
111
+ * Failing open is deliberate — it preserves behaviour for consumers that never
112
+ * opted in — but it means the binding, not the package, is what enforces
113
+ * billing. Any consumer enforcing credits MUST register a provider, e.g. from a
114
+ * `@Global()` module so package-internal code can resolve it from its own
115
+ * injector:
116
+ *
117
+ * ```ts
118
+ * { provide: CREDIT_VALIDATOR, useExisting: CreditValidatorService }
119
+ * ```
120
+ *
121
+ * A global registration is required rather than merely convenient: a library
122
+ * module can never import an application feature module, so the binding has to
123
+ * be visible application-wide.
124
+ */
125
+ export declare const CREDIT_VALIDATOR: unique symbol;
126
+ /**
127
+ * Contract implemented by an application-provided credit validator.
128
+ */
129
+ export interface CreditValidatorInterface {
130
+ validateCredits(params: {
131
+ companyId: string;
132
+ }): Promise<void>;
133
+ }
83
134
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/common/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE9E;;;;GAIG;AAGH,eAAO,MAAM,YAAY,eAAyB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,eAA8B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,eAAe,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5F;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,oBAAoB,eAAiC,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,WAAW,2BAA2B;IAC1C,gBAAgB,CAAC,MAAM,EAAE;QACvB,MAAM,EAAE,mBAAmB,CAAC;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,MAAM,CAAC;Q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,CAAC,EAAE,WAAW,CAAC;QAC1B,sJAAsJ;QACtJ,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,6HAA6H;QAC7H,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,eAAe,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TOKEN_USAGE_RECORDER = exports.AUTH_CONTEXT_HOOK = exports.SYSTEM_ROLES = void 0;
3
+ exports.CREDIT_VALIDATOR = exports.TOKEN_USAGE_RECORDER = exports.AUTH_CONTEXT_HOOK = exports.SYSTEM_ROLES = void 0;
4
4
  /**
5
5
  * Injection tokens for common module dependencies
6
6
  *
@@ -44,4 +44,47 @@ exports.AUTH_CONTEXT_HOOK = Symbol("AUTH_CONTEXT_HOOK");
44
44
  * `AudioLLMService`.
45
45
  */
46
46
  exports.TOKEN_USAGE_RECORDER = Symbol("TOKEN_USAGE_RECORDER");
47
+ /**
48
+ * Application-provided seam for gating AI operations on available company
49
+ * credits. Mirrors `TOKEN_USAGE_RECORDER` above: package code that needs to
50
+ * enforce the credit gate resolves this OPTIONAL token rather than injecting
51
+ * `CompanyService` directly, so consumers that never register a provider see
52
+ * unchanged (ungated) behaviour.
53
+ *
54
+ * `validateCredits` MUST throw `HttpException("NO_CREDITS", HttpStatus.PAYMENT_REQUIRED)`
55
+ * when the company has no available credits, and MUST be a no-op (never throw)
56
+ * when credits are disabled (`creditCost <= 0`).
57
+ *
58
+ * ## THE GATE FAILS OPEN — read this before relying on it
59
+ *
60
+ * Background job processors (`ChunkProcessor`, `ChunkEmbeddingProcessor`,
61
+ * `CommunitySummariserProcessor`) consult this seam through
62
+ * `hasAvailableCreditsVia` (`common/helpers/credit-gate.ts`), which turns the
63
+ * throwing contract above into the non-throwing boolean a processor needs in
64
+ * order to DEFER rather than fail. Its semantics:
65
+ *
66
+ * | Situation | Result |
67
+ * |---------------------------------------------|-----------------------------------------------|
68
+ * | No provider bound for `CREDIT_VALIDATOR` | `true` — work proceeds UNGATED |
69
+ * | Validator throws 402 `NO_CREDITS` | `false` — job defers (marked `PendingCredits`) |
70
+ * | Validator throws anything else | rethrown — never read as an empty balance |
71
+ * | Credits disabled (`creditCost <= 0`) | `true` — validator is a documented no-op |
72
+ *
73
+ * The first row is the dangerous one: **an application that intends to enforce
74
+ * credits but forgets to bind this token runs entirely ungated, silently.**
75
+ * Failing open is deliberate — it preserves behaviour for consumers that never
76
+ * opted in — but it means the binding, not the package, is what enforces
77
+ * billing. Any consumer enforcing credits MUST register a provider, e.g. from a
78
+ * `@Global()` module so package-internal code can resolve it from its own
79
+ * injector:
80
+ *
81
+ * ```ts
82
+ * { provide: CREDIT_VALIDATOR, useExisting: CreditValidatorService }
83
+ * ```
84
+ *
85
+ * A global registration is required rather than merely convenient: a library
86
+ * module can never import an application feature module, so the binding has to
87
+ * be visible application-wide.
88
+ */
89
+ exports.CREDIT_VALIDATOR = Symbol("CREDIT_VALIDATOR");
47
90
  //# sourceMappingURL=tokens.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/common/tokens.ts"],"names":[],"mappings":";;;AAIA;;;;GAIG;AAEH,8BAA8B;AACjB,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAUnD;;;;;;;;;GASG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAS7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACU,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC"}
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/common/tokens.ts"],"names":[],"mappings":";;;AAIA;;;;GAIG;AAEH,8BAA8B;AACjB,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAUnD;;;;;;;;;GASG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAS7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACU,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAwBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACU,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}
@@ -12,4 +12,5 @@ export * from "./services/rate-limited-embedder";
12
12
  export * from "./services/vision.llm.service";
13
13
  export * from "./utils/mock-from-zod";
14
14
  export * from "./utils/tools.utils";
15
+ export * from "./utils/vertex.utils";
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -28,4 +28,5 @@ __exportStar(require("./services/rate-limited-embedder"), exports);
28
28
  __exportStar(require("./services/vision.llm.service"), exports);
29
29
  __exportStar(require("./utils/mock-from-zod"), exports);
30
30
  __exportStar(require("./utils/tools.utils"), exports);
31
+ __exportStar(require("./utils/vertex.utils"), exports);
31
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/llm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,uDAAqC;AACrC,2DAAyC;AACzC,+CAA6B;AAC7B,+DAA6C;AAC7C,iEAA+C;AAC/C,8DAA4C;AAC5C,2EAAyD;AACzD,yDAAuC;AACvC,2DAAyC;AACzC,mEAAiD;AACjD,gEAA8C;AAC9C,wDAAsC;AACtC,sDAAoC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/llm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,uDAAqC;AACrC,2DAAyC;AACzC,+CAA6B;AAC7B,+DAA6C;AAC7C,iEAA+C;AAC/C,8DAA4C;AAC5C,2EAAyD;AACzD,yDAAuC;AACvC,2DAAyC;AACzC,mEAAiD;AACjD,gEAA8C;AAC9C,wDAAsC;AACtC,sDAAoC;AACpC,uDAAqC"}
@@ -1 +1 @@
1
- {"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Aa;IAqEjB;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,MAAM,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa;IAsB9D;;;;;;;;;OASG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa;IAK7D;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAgMtB;;;;;;;;;;OAUG;IACH,WAAW,IAAI,mBAAmB;IAqBlC,OAAO,CAAC,kBAAkB;IAkE1B,qBAAqB,IAAI,MAAM;IAI/B;;;;;OAKG;IACH,cAAc,IAAI,MAAM,GAAG,WAAW;IAiBhC,eAAe,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAQzG"}
@@ -63,6 +63,7 @@ const nestjs_cls_1 = require("nestjs-cls");
63
63
  const openai_2 = __importStar(require("openai"));
64
64
  const logging_service_1 = require("../../logging/services/logging.service");
65
65
  const model_weight_1 = require("../enums/model.weight");
66
+ const vertex_utils_1 = require("../utils/vertex.utils");
66
67
  const embedder_token_bucket_service_1 = require("./embedder-token-bucket.service");
67
68
  const openrouter_fetch_1 = require("./openrouter-fetch");
68
69
  const rate_limited_embedder_1 = require("./rate-limited-embedder");
@@ -487,6 +488,10 @@ let ModelService = ModelService_1 = class ModelService {
487
488
  model: cfg.model,
488
489
  temperature,
489
490
  location: cfg.region,
491
+ // `region` accepts a region ("europe-west4"), a jurisdictional
492
+ // multi-region ("eu"/"us"), or "global". LangChain only builds the
493
+ // first and third correctly — see vertexLocationParams.
494
+ ...(0, vertex_utils_1.vertexLocationParams)(cfg.region),
490
495
  ...(maxOutputTokens ? { maxOutputTokens } : {}),
491
496
  });
492
497
  }
@@ -626,6 +631,8 @@ let ModelService = ModelService_1 = class ModelService {
626
631
  response = new google_vertexai_1.VertexAIEmbeddings({
627
632
  model: embedderConfig.model,
628
633
  location: embedderConfig.region,
634
+ // EMBEDDER_REGION accepts a region or a multi-region, same as AI_REGION.
635
+ ...(0, vertex_utils_1.vertexLocationParams)(embedderConfig.region),
629
636
  dimensions: embedderConfig.dimensions,
630
637
  });
631
638
  break;