@dudousxd/nestjs-agent 1.36.2 → 1.38.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.d.cts CHANGED
@@ -7,8 +7,8 @@ export * from '@dudousxd/nestjs-agent-core';
7
7
  export { FunctionalToolDefinition } from '@dudousxd/nestjs-agent-core';
8
8
  import { A2uiOptions } from '@dudousxd/nestjs-agent-core/a2ui';
9
9
  import { Request, Response } from 'express';
10
- import { A as AgentService, a as ActionProposalService } from './index-CJdTomOT.cjs';
11
- export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-CJdTomOT.cjs';
10
+ import { A as AgentService, a as ActionProposalService } from './index-BJFM1tG8.cjs';
11
+ export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-BJFM1tG8.cjs';
12
12
  import { AgentGenui } from './genui/index.cjs';
13
13
  import { StandardSchemaV1 } from '@standard-schema/spec';
14
14
  import { DiscoveryService, MetadataScanner } from '@nestjs/core';
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@ export * from '@dudousxd/nestjs-agent-core';
7
7
  export { FunctionalToolDefinition } from '@dudousxd/nestjs-agent-core';
8
8
  import { A2uiOptions } from '@dudousxd/nestjs-agent-core/a2ui';
9
9
  import { Request, Response } from 'express';
10
- import { A as AgentService, a as ActionProposalService } from './index-D1xRrnCq.js';
11
- export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-D1xRrnCq.js';
10
+ import { A as AgentService, a as ActionProposalService } from './index-De98CGXa.js';
11
+ export { b as A2uiAdapterOptions, c as A2uiRunHandler, d as AttachmentLimits, C as ChatParams, e as ChatSendMode, f as ChatSendResult, D as DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, g as DEFAULT_MAX_ATTACHMENT_BYTES, F as ForkThreadParams, M as MAX_ATTACHMENTS_PER_MESSAGE, N as NO_USER_MESSAGE_CODE, Q as QueuedSend, T as ThreadDefaultAgentReader, h as ThreadModelReader, i as a2uiAdapter, j as attachmentLimits } from './index-De98CGXa.js';
12
12
  import { AgentGenui } from './genui/index.js';
13
13
  import { StandardSchemaV1 } from '@standard-schema/spec';
14
14
  import { DiscoveryService, MetadataScanner } from '@nestjs/core';
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ var init_kit = __esm({
70
70
 
71
71
  // src/agent.module.ts
72
72
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER14, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL3, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS10, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, ClosedRolesPolicy, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3, personalAgentGate, personalAgentScopes } from "@dudousxd/nestjs-agent-core";
73
- import { Global, Logger as Logger8, Module as Module2 } from "@nestjs/common";
73
+ import { Global, Logger as Logger9, Module as Module2 } from "@nestjs/common";
74
74
  import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
75
75
 
76
76
  // src/agent-deps.factory.ts
@@ -807,8 +807,8 @@ AgentDepsFactory2 = _ts_decorate2([
807
807
  var AGENT_SERVICE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:agent-service");
808
808
 
809
809
  // src/agent.service.ts
810
- import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY as DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY2, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval as mayDecideApproval2, readElicitationQuestions, settleDeadRun, textActionProposalReply as textActionProposalReply2, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
811
- import { BadRequestException as BadRequestException2, ConflictException as ConflictException2, ForbiddenException as ForbiddenException2, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable4, NotFoundException as NotFoundException2, NotImplementedException as NotImplementedException3, Optional as Optional3, PayloadTooLargeException, UnsupportedMediaTypeException } from "@nestjs/common";
810
+ import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY as DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY2, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval as mayDecideApproval2, readElicitationQuestions, recordAiUsage, settleDeadRun, textActionProposalReply as textActionProposalReply2, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
811
+ import { BadRequestException as BadRequestException2, ConflictException as ConflictException2, ForbiddenException as ForbiddenException2, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable4, Logger as Logger2, NotFoundException as NotFoundException2, NotImplementedException as NotImplementedException3, Optional as Optional3, PayloadTooLargeException, UnsupportedMediaTypeException } from "@nestjs/common";
812
812
 
813
813
  // src/agent-deps.ts
814
814
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -1631,6 +1631,7 @@ function _ts_param4(paramIndex, decorator) {
1631
1631
  };
1632
1632
  }
1633
1633
  __name(_ts_param4, "_ts_param");
1634
+ var usageLogger = new Logger2("AgentService");
1634
1635
  var NO_USER_MESSAGE_CODE = "no_user_message";
1635
1636
  function sendableParams(params) {
1636
1637
  const message = params.message;
@@ -2458,9 +2459,28 @@ var AgentService2 = class {
2458
2459
  await this.assertOwnsThread(actor, threadId);
2459
2460
  return this.store.softDeleteThread(threadId);
2460
2461
  }
2461
- async forkThread(actor, threadId, fromMessageId) {
2462
- await this.assertOwnsThread(actor, threadId);
2463
- return this.store.forkThread(threadId, fromMessageId);
2462
+ /**
2463
+ * Copy a thread up to `fromMessageId` (inclusive) into a new one. By default only the thread's
2464
+ * owner may, and the copy is theirs. With `params.authorized`, the host has vouched for `actor`
2465
+ * (a share link it checked) and the copy is `actor`'s — see {@link ForkThreadParams}.
2466
+ */
2467
+ async forkThread(actor, threadId, fromMessageId, params = {}) {
2468
+ if (params.authorized === true) {
2469
+ if (await this.store.ownerOfThread(threadId) === null) {
2470
+ throw new NotFoundException2(`thread ${threadId} not found`);
2471
+ }
2472
+ } else {
2473
+ await this.assertOwnsThread(actor, threadId);
2474
+ }
2475
+ const options = {
2476
+ ...params.authorized === true ? {
2477
+ actorRef: actor.id
2478
+ } : {},
2479
+ ...params.tenantRef !== void 0 ? {
2480
+ tenantRef: params.tenantRef
2481
+ } : {}
2482
+ };
2483
+ return this.store.forkThread(threadId, fromMessageId, options);
2464
2484
  }
2465
2485
  /** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
2466
2486
  async renameThread(actor, threadId, title) {
@@ -2855,6 +2875,31 @@ var AgentService2 = class {
2855
2875
  throw new ForbiddenException2("run belongs to another actor");
2856
2876
  }
2857
2877
  }
2878
+ /**
2879
+ * Record AI spend that did not come from an agent turn — a transcription, a TTS render, a batch of
2880
+ * embeddings, a direct OpenAI/OpenRouter SDK call — on the same ledger the agent's turns write, so
2881
+ * cost, quota and the dashboard see one figure.
2882
+ *
2883
+ * Never throws into the caller's flow by default: a failed write or an invalid input is logged and
2884
+ * answered with `{ recorded: false, error }`. Pass `{ throwOnError: true }` where losing the row
2885
+ * must fail the caller.
2886
+ *
2887
+ * Counted against `actorRef` like an agent turn: the ledger is the budget (`LedgerQuotaProvider`),
2888
+ * so its tokens count in the token windows (a row with no tokens adds 0 there) and its `costUsd` in
2889
+ * the USD windows. A `QuotaStore` counter is bumped only where loop deps carry one (`AgentModule`
2890
+ * wires none). `actorRef: null` is platform cost, recorded under `PLATFORM_ACTOR_REF` and counted
2891
+ * against nobody.
2892
+ */
2893
+ recordUsage(input, options = {}) {
2894
+ return recordAiUsage({
2895
+ store: this.store,
2896
+ quota: this.deps.forAgent().quota,
2897
+ day: utcDay(),
2898
+ input,
2899
+ options,
2900
+ warn: /* @__PURE__ */ __name((message) => usageLogger.warn(message), "warn")
2901
+ });
2902
+ }
2858
2903
  };
2859
2904
  AgentService2 = _ts_decorate5([
2860
2905
  Injectable4(),
@@ -4761,7 +4806,7 @@ ToolsController = _ts_decorate19([
4761
4806
 
4762
4807
  // src/discovery/agent-discovery.service.ts
4763
4808
  import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
4764
- import { Inject as Inject19, Injectable as Injectable6, Logger as Logger2 } from "@nestjs/common";
4809
+ import { Inject as Inject19, Injectable as Injectable6, Logger as Logger3 } from "@nestjs/common";
4765
4810
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
4766
4811
 
4767
4812
  // src/decorator/agent.decorator.ts
@@ -4830,7 +4875,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4830
4875
  scanner;
4831
4876
  registry;
4832
4877
  contributors;
4833
- logger = new Logger2(_AgentDiscoveryService.name);
4878
+ logger = new Logger3(_AgentDiscoveryService.name);
4834
4879
  constructor(discovery, scanner, registry, contributors) {
4835
4880
  this.discovery = discovery;
4836
4881
  this.scanner = scanner;
@@ -5012,7 +5057,7 @@ AgentDiscoveryService = _ts_decorate20([
5012
5057
 
5013
5058
  // src/discovery/ai-tool-discovery.service.ts
5014
5059
  import { AGENT_OPTIONS as AGENT_OPTIONS7, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
5015
- import { Inject as Inject20, Injectable as Injectable7, Logger as Logger3 } from "@nestjs/common";
5060
+ import { Inject as Inject20, Injectable as Injectable7, Logger as Logger4 } from "@nestjs/common";
5016
5061
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
5017
5062
  import { z } from "zod";
5018
5063
 
@@ -5079,7 +5124,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
5079
5124
  registry;
5080
5125
  agents;
5081
5126
  options;
5082
- logger = new Logger3(_AiToolDiscoveryService.name);
5127
+ logger = new Logger4(_AiToolDiscoveryService.name);
5083
5128
  constructor(discovery, registry, agents, options) {
5084
5129
  this.discovery = discovery;
5085
5130
  this.registry = registry;
@@ -5245,7 +5290,7 @@ AiToolDiscoveryService = _ts_decorate21([
5245
5290
 
5246
5291
  // src/discovery/skill-discovery.service.ts
5247
5292
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
5248
- import { Inject as Inject21, Injectable as Injectable8, Logger as Logger4 } from "@nestjs/common";
5293
+ import { Inject as Inject21, Injectable as Injectable8, Logger as Logger5 } from "@nestjs/common";
5249
5294
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
5250
5295
 
5251
5296
  // src/decorator/skill.decorator.ts
@@ -5300,7 +5345,7 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
5300
5345
  }
5301
5346
  discovery;
5302
5347
  declared;
5303
- logger = new Logger4(_SkillDiscoveryService.name);
5348
+ logger = new Logger5(_SkillDiscoveryService.name);
5304
5349
  constructor(discovery, declared) {
5305
5350
  this.discovery = discovery;
5306
5351
  this.declared = declared;
@@ -5608,7 +5653,7 @@ var LedgerQuotaProvider = class {
5608
5653
 
5609
5654
  // src/pricing-boot.service.ts
5610
5655
  import { AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS8, AGENT_PRICING_STORE as AGENT_PRICING_STORE2, ensureModelPricing } from "@dudousxd/nestjs-agent-core";
5611
- import { Inject as Inject22, Injectable as Injectable9, Logger as Logger5, Optional as Optional9 } from "@nestjs/common";
5656
+ import { Inject as Inject22, Injectable as Injectable9, Logger as Logger6, Optional as Optional9 } from "@nestjs/common";
5612
5657
  function _ts_decorate23(decorators, target, key, desc) {
5613
5658
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5614
5659
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -5635,7 +5680,7 @@ function _ts_param22(paramIndex, decorator) {
5635
5680
  };
5636
5681
  }
5637
5682
  __name(_ts_param22, "_ts_param");
5638
- var logger = new Logger5("AgentPricing");
5683
+ var logger = new Logger6("AgentPricing");
5639
5684
  var PricingBootService = class {
5640
5685
  static {
5641
5686
  __name(this, "PricingBootService");
@@ -5698,7 +5743,7 @@ PricingBootService = _ts_decorate23([
5698
5743
  // src/proposals/action-proposal-worker.service.ts
5699
5744
  import { randomUUID } from "crypto";
5700
5745
  import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_OPTIONS as AGENT_OPTIONS9, AGENT_STORE as AGENT_STORE5, ActionProposalExecutor, ActionProposalWorker, assertIndependentActionCapabilities as assertIndependentActionCapabilities2 } from "@dudousxd/nestjs-agent-core";
5701
- import { Inject as Inject23, Injectable as Injectable10, Logger as Logger6 } from "@nestjs/common";
5746
+ import { Inject as Inject23, Injectable as Injectable10, Logger as Logger7 } from "@nestjs/common";
5702
5747
  function _ts_decorate24(decorators, target, key, desc) {
5703
5748
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5704
5749
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -5733,7 +5778,7 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
5733
5778
  options;
5734
5779
  deps;
5735
5780
  worker;
5736
- logger = new Logger6(_ActionProposalWorkerService.name);
5781
+ logger = new Logger7(_ActionProposalWorkerService.name);
5737
5782
  settledListeners = /* @__PURE__ */ new Set();
5738
5783
  admittedListeners = /* @__PURE__ */ new Set();
5739
5784
  /**
@@ -5993,8 +6038,8 @@ ActionProposalController = _ts_decorate25([
5993
6038
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
5994
6039
 
5995
6040
  // src/runner/inline-agent-runner.ts
5996
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, agentRunContext, encodeStreamEvent as encodeStreamEvent2, publishAgentRunCancelled, publishAgentRunFailed, releaseThreadRun, runAgentLoop, runDurationMs, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
5997
- import { Inject as Inject25, Injectable as Injectable11, Logger as Logger7, Optional as Optional10 } from "@nestjs/common";
6041
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, agentRunContext, encodeStreamEvent as encodeStreamEvent2, publishAgentRunCancelled, publishAgentRunFailed, releaseThreadRun, runAgentLoop, runDurationMs, runEndTimings, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
6042
+ import { Inject as Inject25, Injectable as Injectable11, Logger as Logger8, Optional as Optional10 } from "@nestjs/common";
5998
6043
  function _ts_decorate26(decorators, target, key, desc) {
5999
6044
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6000
6045
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -6028,7 +6073,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
6028
6073
  factory;
6029
6074
  store;
6030
6075
  queue;
6031
- logger = new Logger7(_InlineAgentRunner.name);
6076
+ logger = new Logger8(_InlineAgentRunner.name);
6032
6077
  pending = /* @__PURE__ */ new Map();
6033
6078
  /**
6034
6079
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -6065,10 +6110,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
6065
6110
  }
6066
6111
  async start(input, options = {}) {
6067
6112
  const runId = options.runId ?? crypto.randomUUID();
6113
+ const acceptedAt = Date.now();
6068
6114
  const day = input.day ?? utcDay();
6069
6115
  const deps = this.factory.forAgent(input.agentName);
6070
6116
  this.live.add(runId);
6071
6117
  const hooks = this.topLevelHooks({
6118
+ acceptedAt,
6072
6119
  runId,
6073
6120
  deps,
6074
6121
  actor: input.actor,
@@ -6090,8 +6137,9 @@ var InlineAgentRunner = class _InlineAgentRunner {
6090
6137
  const timed = durationMs !== void 0 ? {
6091
6138
  durationMs
6092
6139
  } : {};
6140
+ const measured = runEndTimings(error);
6093
6141
  if (error instanceof RunCancelledError) {
6094
- await this.settleCancelled(runId, input, deps, durationMs);
6142
+ await this.settleCancelled(runId, input, deps, durationMs, measured);
6095
6143
  return;
6096
6144
  }
6097
6145
  const message = error instanceof Error ? error.message : String(error);
@@ -6103,6 +6151,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
6103
6151
  code,
6104
6152
  message,
6105
6153
  ...timed,
6154
+ ...measured,
6106
6155
  context: agentRunContext(input)
6107
6156
  });
6108
6157
  await this.store.recordRunEnd?.({
@@ -6180,7 +6229,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
6180
6229
  * the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
6181
6230
  * streams does not retry this one.
6182
6231
  */
6183
- async settleCancelled(runId, input, deps, durationMs) {
6232
+ async settleCancelled(runId, input, deps, durationMs, measured = {}) {
6184
6233
  this.logger.log(`agent run ${runId} cancelled`);
6185
6234
  const timed = durationMs !== void 0 ? {
6186
6235
  durationMs
@@ -6189,6 +6238,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
6189
6238
  runId,
6190
6239
  threadId: input.threadId,
6191
6240
  ...timed,
6241
+ ...measured,
6192
6242
  context: agentRunContext(input)
6193
6243
  });
6194
6244
  const writer = await deps.sink.open(runId);
@@ -6281,9 +6331,10 @@ var InlineAgentRunner = class _InlineAgentRunner {
6281
6331
  });
6282
6332
  }
6283
6333
  topLevelHooks(args) {
6284
- const { runId, deps, actor, day, threadId, chainBelow, input } = args;
6334
+ const { runId, deps, actor, day, threadId, chainBelow, input, acceptedAt } = args;
6285
6335
  return {
6286
6336
  runId,
6337
+ queueMs: /* @__PURE__ */ __name(() => Date.now() - acceptedAt, "queueMs"),
6287
6338
  // The loop ends the stream when the turn completes. Just before, the thread passes to the next
6288
6339
  // queued message (or is released), and the reader is told which — so by the time a client
6289
6340
  // sees the run end, the thread is already free or already running what it queued.
@@ -6408,10 +6459,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
6408
6459
  const timed = durationMs !== void 0 ? {
6409
6460
  durationMs
6410
6461
  } : {};
6462
+ const measured = runEndTimings(error);
6411
6463
  const settled = {
6412
6464
  runId,
6413
6465
  threadId: subThread.id,
6414
6466
  ...timed,
6467
+ ...measured,
6415
6468
  context: agentRunContext(childInput)
6416
6469
  };
6417
6470
  if (cancelled) {
@@ -6600,7 +6653,7 @@ function _ts_decorate27(decorators, target, key, desc) {
6600
6653
  }
6601
6654
  __name(_ts_decorate27, "_ts_decorate");
6602
6655
  var DEFAULT_PATH = "agent";
6603
- var logger2 = new Logger8("AgentModule");
6656
+ var logger2 = new Logger9("AgentModule");
6604
6657
  function externalWrapper(modules, token) {
6605
6658
  for (const module of modules.values()) {
6606
6659
  if (module.metatype === AgentModule) continue;