@dudousxd/nestjs-agent-core 0.23.0 → 0.25.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.
@@ -1,4 +1,4 @@
1
- import { A as Actor, I as InputProcessor, O as OutputProcessor, T as ToolHandler } from '../tool-BdW-LV1J.cjs';
1
+ import { A as Actor, I as InputProcessor, O as OutputProcessor, T as ToolHandler } from '../tool-fLRLs_f3.cjs';
2
2
  import '@standard-schema/spec';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { A as Actor, I as InputProcessor, O as OutputProcessor, T as ToolHandler } from '../tool-BdW-LV1J.js';
1
+ import { A as Actor, I as InputProcessor, O as OutputProcessor, T as ToolHandler } from '../tool-fLRLs_f3.js';
2
2
  import '@standard-schema/spec';
3
3
 
4
4
  /**
package/dist/index.cjs CHANGED
@@ -32,9 +32,11 @@ __export(src_exports, {
32
32
  AGENT_GOVERNANCE_QUERIES: () => AGENT_GOVERNANCE_QUERIES,
33
33
  AGENT_MEMORY: () => AGENT_MEMORY,
34
34
  AGENT_MODEL: () => AGENT_MODEL,
35
+ AGENT_MODEL_CATALOG: () => AGENT_MODEL_CATALOG,
35
36
  AGENT_OPTIONS: () => AGENT_OPTIONS,
36
37
  AGENT_PRICING_STORE: () => AGENT_PRICING_STORE,
37
38
  AGENT_PROMPT_CONTRIBUTORS: () => AGENT_PROMPT_CONTRIBUTORS,
39
+ AGENT_QUOTA_PROVIDER: () => AGENT_QUOTA_PROVIDER,
38
40
  AGENT_QUOTA_STORE: () => AGENT_QUOTA_STORE,
39
41
  AGENT_REGISTRY: () => AGENT_REGISTRY,
40
42
  AGENT_RETRIEVER: () => AGENT_RETRIEVER,
@@ -108,11 +110,13 @@ __export(src_exports, {
108
110
  encodeStreamEvent: () => encodeStreamEvent,
109
111
  estimateCost: () => estimateCost,
110
112
  estimateMessageTokens: () => estimateMessageTokens,
113
+ exhaustedWindow: () => exhaustedWindow,
111
114
  extractJson: () => extractJson,
112
115
  filterToolsByAllowList: () => filterToolsByAllowList,
113
116
  filterToolsByCanUse: () => filterToolsByCanUse,
114
117
  filterToolsByEnabled: () => filterToolsByEnabled,
115
118
  filterToolsByRole: () => filterToolsByRole,
119
+ findCatalogModel: () => findCatalogModel,
116
120
  gateFollowUps: () => gateFollowUps,
117
121
  gateTail: () => gateTail,
118
122
  invokeWithTransientRetry: () => invokeWithTransientRetry,
@@ -144,6 +148,7 @@ __export(src_exports, {
144
148
  publishAgentToolCall: () => publishAgentToolCall,
145
149
  publishAgentToolRetry: () => publishAgentToolRetry,
146
150
  questionOptions: () => questionOptions,
151
+ quotaPeriodRange: () => quotaPeriodRange,
147
152
  readElicitationInput: () => readElicitationInput,
148
153
  readElicitationQuestions: () => readElicitationQuestions,
149
154
  releaseGatedFrames: () => releaseGatedFrames,
@@ -169,6 +174,7 @@ __export(src_exports, {
169
174
  skillToolDefinition: () => skillToolDefinition,
170
175
  skillWriteVerdict: () => skillWriteVerdict,
171
176
  stampToolKinds: () => stampToolKinds,
177
+ staticModelCatalog: () => staticModelCatalog,
172
178
  staticSkillProvider: () => staticSkillProvider,
173
179
  summarizeWithModel: () => summarizeWithModel,
174
180
  tenantScope: () => tenantScope,
@@ -183,6 +189,7 @@ __export(src_exports, {
183
189
  windowHistory: () => windowHistory,
184
190
  withAskTool: () => withAskTool,
185
191
  withMemoryTool: () => withMemoryTool,
192
+ withSelectedModel: () => withSelectedModel,
186
193
  withSkillTool: () => withSkillTool,
187
194
  withToolTimeout: () => withToolTimeout,
188
195
  withTurnFrames: () => withTurnFrames,
@@ -204,6 +211,8 @@ var AGENT_TOOL_REGISTRY = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:too
204
211
  var AGENT_REGISTRY = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:agent-registry");
205
212
  var AGENT_ACTOR_RESOLVER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:actor-resolver");
206
213
  var AGENT_GOVERNANCE_QUERIES = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:governance-queries");
214
+ var AGENT_QUOTA_PROVIDER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:quota-provider");
215
+ var AGENT_MODEL_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:model-catalog");
207
216
  var AGENT_PRICING_STORE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:pricing-store");
208
217
  var AGENT_RETRIEVER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:retriever");
209
218
  var AGENT_EMBEDDING_PROVIDER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:embedding-provider");
@@ -216,6 +225,31 @@ var AGENT_SKILLS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skills");
216
225
  var AGENT_MEMORY = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:memory");
217
226
  var AGENT_SKILL_SOURCES = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-sources");
218
227
 
228
+ // src/spi/model-catalog.ts
229
+ function staticModelCatalog(view) {
230
+ return {
231
+ list: /* @__PURE__ */ __name(() => view, "list")
232
+ };
233
+ }
234
+ __name(staticModelCatalog, "staticModelCatalog");
235
+ function findCatalogModel(view, id) {
236
+ for (const group of view.providers) {
237
+ const found = group.models.find((model) => model.id === id);
238
+ if (found !== void 0) return found;
239
+ }
240
+ return void 0;
241
+ }
242
+ __name(findCatalogModel, "findCatalogModel");
243
+ function withSelectedModel(provider, model) {
244
+ return {
245
+ runTurn: /* @__PURE__ */ __name((args) => provider.runTurn({
246
+ ...args,
247
+ model
248
+ }), "runTurn")
249
+ };
250
+ }
251
+ __name(withSelectedModel, "withSelectedModel");
252
+
219
253
  // src/spi/token-stream-sink.ts
220
254
  var AgentStreamError = class extends Error {
221
255
  static {
@@ -436,6 +470,43 @@ function mergeUi(...lists) {
436
470
  }
437
471
  __name(mergeUi, "mergeUi");
438
472
 
473
+ // src/spi/quota-provider.ts
474
+ function exhaustedWindow(windows) {
475
+ for (const window of windows) {
476
+ const tokensOut = window.limitTokens !== void 0 && window.usedTokens >= window.limitTokens;
477
+ const spendOut = window.limitUsd !== void 0 && window.usedUsd >= window.limitUsd;
478
+ if (tokensOut || spendOut) {
479
+ return {
480
+ period: window.period,
481
+ reason: `${window.period === "day" ? "Daily" : "Monthly"} ${spendOut ? "spend" : "token"} limit reached`
482
+ };
483
+ }
484
+ }
485
+ return void 0;
486
+ }
487
+ __name(exhaustedWindow, "exhaustedWindow");
488
+ function quotaPeriodRange(period, now) {
489
+ const year = now.getUTCFullYear();
490
+ const month = now.getUTCMonth();
491
+ const day = now.toISOString().slice(0, 10);
492
+ if (period === "day") {
493
+ const next = new Date(Date.UTC(year, month, now.getUTCDate() + 1));
494
+ return {
495
+ fromDay: day,
496
+ toDay: day,
497
+ resetsAt: next.toISOString()
498
+ };
499
+ }
500
+ const first = new Date(Date.UTC(year, month, 1));
501
+ const last = new Date(Date.UTC(year, month + 1, 0));
502
+ return {
503
+ fromDay: first.toISOString().slice(0, 10),
504
+ toDay: last.toISOString().slice(0, 10),
505
+ resetsAt: new Date(Date.UTC(year, month + 1, 1)).toISOString()
506
+ };
507
+ }
508
+ __name(quotaPeriodRange, "quotaPeriodRange");
509
+
439
510
  // src/spi/pricing-store.ts
440
511
  async function seedModelPrices(store, prices) {
441
512
  for (const price of prices) {
@@ -4112,7 +4183,12 @@ async function invokeClaimedToolsTogether(turn, parallel, claimed) {
4112
4183
  return results;
4113
4184
  }
4114
4185
  __name(invokeClaimedToolsTogether, "invokeClaimedToolsTogether");
4115
- async function runAgentLoop(deps, input, hooks) {
4186
+ async function runAgentLoop(boundDeps, input, hooks) {
4187
+ const deps = input.model === void 0 ? boundDeps : {
4188
+ ...boundDeps,
4189
+ model: withSelectedModel(boundDeps.model, input.model),
4190
+ modelId: input.model
4191
+ };
4116
4192
  const maxSteps = deps.maxSteps ?? 8;
4117
4193
  let system = await resolveSystemPrompt(deps, input);
4118
4194
  const inputProcessors = deps.inputProcessors ?? [];
@@ -4309,6 +4385,9 @@ ${block}`;
4309
4385
  actor: input.actor,
4310
4386
  ...gated ? {
4311
4387
  bufferOutput: true
4388
+ } : {},
4389
+ ...input.model !== void 0 ? {
4390
+ model: input.model
4312
4391
  } : {}
4313
4392
  });
4314
4393
  } else {
@@ -4728,9 +4807,11 @@ __name(runAgentLoop, "runAgentLoop");
4728
4807
  AGENT_GOVERNANCE_QUERIES,
4729
4808
  AGENT_MEMORY,
4730
4809
  AGENT_MODEL,
4810
+ AGENT_MODEL_CATALOG,
4731
4811
  AGENT_OPTIONS,
4732
4812
  AGENT_PRICING_STORE,
4733
4813
  AGENT_PROMPT_CONTRIBUTORS,
4814
+ AGENT_QUOTA_PROVIDER,
4734
4815
  AGENT_QUOTA_STORE,
4735
4816
  AGENT_REGISTRY,
4736
4817
  AGENT_RETRIEVER,
@@ -4804,11 +4885,13 @@ __name(runAgentLoop, "runAgentLoop");
4804
4885
  encodeStreamEvent,
4805
4886
  estimateCost,
4806
4887
  estimateMessageTokens,
4888
+ exhaustedWindow,
4807
4889
  extractJson,
4808
4890
  filterToolsByAllowList,
4809
4891
  filterToolsByCanUse,
4810
4892
  filterToolsByEnabled,
4811
4893
  filterToolsByRole,
4894
+ findCatalogModel,
4812
4895
  gateFollowUps,
4813
4896
  gateTail,
4814
4897
  invokeWithTransientRetry,
@@ -4840,6 +4923,7 @@ __name(runAgentLoop, "runAgentLoop");
4840
4923
  publishAgentToolCall,
4841
4924
  publishAgentToolRetry,
4842
4925
  questionOptions,
4926
+ quotaPeriodRange,
4843
4927
  readElicitationInput,
4844
4928
  readElicitationQuestions,
4845
4929
  releaseGatedFrames,
@@ -4865,6 +4949,7 @@ __name(runAgentLoop, "runAgentLoop");
4865
4949
  skillToolDefinition,
4866
4950
  skillWriteVerdict,
4867
4951
  stampToolKinds,
4952
+ staticModelCatalog,
4868
4953
  staticSkillProvider,
4869
4954
  summarizeWithModel,
4870
4955
  tenantScope,
@@ -4879,6 +4964,7 @@ __name(runAgentLoop, "runAgentLoop");
4879
4964
  windowHistory,
4880
4965
  withAskTool,
4881
4966
  withMemoryTool,
4967
+ withSelectedModel,
4882
4968
  withSkillTool,
4883
4969
  withToolTimeout,
4884
4970
  withTurnFrames,