@namzu/sdk 64.2.0 → 64.4.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/advisory/executor.d.ts +2 -1
  3. package/dist/advisory/executor.d.ts.map +1 -1
  4. package/dist/advisory/executor.js +8 -2
  5. package/dist/advisory/executor.js.map +1 -1
  6. package/dist/compaction/context-window.d.ts.map +1 -1
  7. package/dist/compaction/context-window.js +9 -2
  8. package/dist/compaction/context-window.js.map +1 -1
  9. package/dist/eval/judge.d.ts.map +1 -1
  10. package/dist/eval/judge.js +6 -2
  11. package/dist/eval/judge.js.map +1 -1
  12. package/dist/manager/agent/lifecycle.d.ts +1 -0
  13. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  14. package/dist/manager/agent/lifecycle.js +20 -6
  15. package/dist/manager/agent/lifecycle.js.map +1 -1
  16. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  17. package/dist/manager/session/turn-recorder.js +11 -2
  18. package/dist/manager/session/turn-recorder.js.map +1 -1
  19. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  20. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  21. package/dist/prompt/coding-agent-doctrine.js +7 -1
  22. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  23. package/dist/provider/fallback.d.ts.map +1 -1
  24. package/dist/provider/fallback.js +2 -1
  25. package/dist/provider/fallback.js.map +1 -1
  26. package/dist/provider/idle-timeout.d.ts.map +1 -1
  27. package/dist/provider/idle-timeout.js +1 -1
  28. package/dist/provider/idle-timeout.js.map +1 -1
  29. package/dist/provider/instrumentation.js +1 -1
  30. package/dist/provider/instrumentation.js.map +1 -1
  31. package/dist/provider/retry.d.ts.map +1 -1
  32. package/dist/provider/retry.js +1 -1
  33. package/dist/provider/retry.js.map +1 -1
  34. package/dist/provider/side-request-reasoning.d.ts +32 -0
  35. package/dist/provider/side-request-reasoning.d.ts.map +1 -0
  36. package/dist/provider/side-request-reasoning.js +97 -0
  37. package/dist/provider/side-request-reasoning.js.map +1 -0
  38. package/dist/public-runtime.d.ts +3 -1
  39. package/dist/public-runtime.d.ts.map +1 -1
  40. package/dist/public-runtime.js +2 -1
  41. package/dist/public-runtime.js.map +1 -1
  42. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  43. package/dist/runtime/query/auto-review/classifier.js +8 -2
  44. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  45. package/dist/runtime/query/callback-inference.d.ts.map +1 -1
  46. package/dist/runtime/query/callback-inference.js +14 -3
  47. package/dist/runtime/query/callback-inference.js.map +1 -1
  48. package/dist/runtime/query/iteration/index.d.ts +8 -0
  49. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  50. package/dist/runtime/query/iteration/index.js +36 -5
  51. package/dist/runtime/query/iteration/index.js.map +1 -1
  52. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  53. package/dist/runtime/query/prepare-turn.js +3 -0
  54. package/dist/runtime/query/prepare-turn.js.map +1 -1
  55. package/dist/runtime/query/repeat-call.js +2 -2
  56. package/dist/runtime/query/repeat-call.js.map +1 -1
  57. package/dist/runtime/query/turn/stall-monitor.d.ts +26 -2
  58. package/dist/runtime/query/turn/stall-monitor.d.ts.map +1 -1
  59. package/dist/runtime/query/turn/stall-monitor.js +36 -4
  60. package/dist/runtime/query/turn/stall-monitor.js.map +1 -1
  61. package/dist/turn/evidence-query.d.ts.map +1 -1
  62. package/dist/turn/evidence-query.js +7 -1
  63. package/dist/turn/evidence-query.js.map +1 -1
  64. package/dist/types/common/index.d.ts +14 -0
  65. package/dist/types/common/index.d.ts.map +1 -1
  66. package/dist/types/common/index.js +7 -0
  67. package/dist/types/common/index.js.map +1 -1
  68. package/dist/types/provider/config.d.ts +6 -0
  69. package/dist/types/provider/config.d.ts.map +1 -1
  70. package/dist/types/provider/interface.d.ts +5 -2
  71. package/dist/types/provider/interface.d.ts.map +1 -1
  72. package/dist/types/session/prepare-step.d.ts +7 -0
  73. package/dist/types/session/prepare-step.d.ts.map +1 -1
  74. package/dist/utils/cost.d.ts +14 -0
  75. package/dist/utils/cost.d.ts.map +1 -1
  76. package/dist/utils/cost.js +20 -0
  77. package/dist/utils/cost.js.map +1 -1
  78. package/package.json +1 -1
  79. package/src/advisory/executor.ts +13 -2
  80. package/src/compaction/context-window.ts +9 -2
  81. package/src/eval/judge.ts +16 -9
  82. package/src/manager/agent/lifecycle.ts +19 -6
  83. package/src/manager/session/turn-recorder.ts +12 -1
  84. package/src/prompt/coding-agent-doctrine.ts +7 -1
  85. package/src/provider/fallback.ts +7 -2
  86. package/src/provider/idle-timeout.ts +2 -1
  87. package/src/provider/instrumentation.ts +1 -1
  88. package/src/provider/retry.ts +2 -1
  89. package/src/provider/side-request-reasoning.ts +121 -0
  90. package/src/public-runtime.ts +7 -0
  91. package/src/runtime/query/auto-review/classifier.ts +17 -9
  92. package/src/runtime/query/callback-inference.ts +13 -3
  93. package/src/runtime/query/iteration/index.ts +43 -3
  94. package/src/runtime/query/prepare-turn.ts +2 -0
  95. package/src/runtime/query/repeat-call.ts +2 -2
  96. package/src/runtime/query/turn/stall-monitor.ts +48 -4
  97. package/src/turn/evidence-query.ts +8 -1
  98. package/src/types/common/index.ts +22 -0
  99. package/src/types/provider/config.ts +6 -0
  100. package/src/types/provider/interface.ts +9 -2
  101. package/src/types/session/prepare-step.ts +7 -0
  102. package/src/utils/cost.ts +24 -0
@@ -1 +1 @@
1
- {"version":3,"file":"prepare-step.d.ts","sourceRoot":"","sources":["../../../src/types/session/prepare-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,E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AQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,yHAAyH;IACzH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,CACzB,OAAO,EAAE,kBAAkB,KACvB,iBAAiB,GAAG,SAAS,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;AAE3E;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,UAAU,GAAG,CACxB,OAAO,EAAE,kBAAkB,KACvB,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,SAAS,WAAW,EAAE,CAAA"}
@@ -68,6 +68,20 @@ export declare function accumulateCost(current: CostInfo, additionalUsage: Token
68
68
  * not described by any single card.
69
69
  */
70
70
  export declare function accumulateUnpricedCost(current: CostInfo, additionalUsage: TokenUsage): CostInfo;
71
+ /**
72
+ * Record a call whose cost the provider reported.
73
+ *
74
+ * The vendor's figure is what the account was charged, so it wins over a rate
75
+ * card: a card is an estimate of one model at one list price, while the report
76
+ * already includes the route that served the call, the cache discount and any
77
+ * tier. The rate fields go, as for unpriced tokens: no single card describes
78
+ * a total that holds a reported figure.
79
+ */
80
+ export declare function accumulateReportedCost(current: CostInfo, reportedCostUsd: number): CostInfo;
81
+ /** Whether a usage frame carries a usable vendor-reported cost. */
82
+ export declare function hasReportedCost(usage: TokenUsage): usage is TokenUsage & {
83
+ reportedCostUsd: number;
84
+ };
71
85
  export declare function formatCost(usd: number): string;
72
86
  /**
73
87
  * How a total should be shown, given what is and is not known about it.
@@ -1 +1 @@
1
- {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAEpE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,UAAU;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAA;IAC1C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAChC;AAED,MAAM,WAAW,YAAY;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,eAAe,EAAE,MAAM,CAAA;IACvB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,OAAO,EAAE,SAAS,EAAE,CAAA;AAqFpB,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,QAAQ,CAShF;AAyDD,wBAAgB,cAAc,CAC7B,OAAO,EAAE,QAAQ,EACjB,eAAe,EAAE,UAAU,EAC3B,OAAO,EAAE,YAAY,GACnB,QAAQ,CASV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,GAAG,QAAQ,CAM/F;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAMnD"}
1
+ {"version":3,"file":"cost.d.ts","sourceRoot":"","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BAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAMnD"}
@@ -151,6 +151,26 @@ export function accumulateUnpricedCost(current, additionalUsage) {
151
151
  unpricedTokens: current.unpricedTokens + additionalUsage.totalTokens,
152
152
  };
153
153
  }
154
+ /**
155
+ * Record a call whose cost the provider reported.
156
+ *
157
+ * The vendor's figure is what the account was charged, so it wins over a rate
158
+ * card: a card is an estimate of one model at one list price, while the report
159
+ * already includes the route that served the call, the cache discount and any
160
+ * tier. The rate fields go, as for unpriced tokens: no single card describes
161
+ * a total that holds a reported figure.
162
+ */
163
+ export function accumulateReportedCost(current, reportedCostUsd) {
164
+ return {
165
+ totalCost: current.totalCost + reportedCostUsd,
166
+ cacheDiscount: current.cacheDiscount,
167
+ unpricedTokens: current.unpricedTokens,
168
+ };
169
+ }
170
+ /** Whether a usage frame carries a usable vendor-reported cost. */
171
+ export function hasReportedCost(usage) {
172
+ return Number.isFinite(usage.reportedCostUsd) && usage.reportedCostUsd >= 0;
173
+ }
154
174
  export function formatCost(usd) {
155
175
  if (usd === 0)
156
176
  return '$0.00';
@@ -1 +1 @@
1
- {"version":3,"file":"cost.js","sourceRoot":"","sources":["../../src/utils/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AA0DlD,OAAO,EAAE,SAAS,EAAE,CAAA;AAUpB,SAAS,UAAU,CAAC,KAAiB,EAAE,OAAqB;IAC3D,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,iBAAiB,IAAI,CAAC,CAAA;IAC7C,IAAI,QAAQ,KAAK,CAAC,IAAI,OAAO,CAAC,oBAAoB,KAAK,SAAS;QAAE,OAAO,MAAM,CAAA;IAC/E,2DAA2D;IAC3D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,UAAU,eAAe,CAC9B,KAAiB;IAEjB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,IAAK,KAAK,CAAC,eAA0B,IAAI,CAAC,CAAA;AACxF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACrC,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,OAAO,CAAA;IAC7B,IAAI,GAAG,GAAG,IAAI;QAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3C,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc;IAC1C,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAChE,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,YAAY,IAAI,CAAC,cAAc,2BAA2B,CAAA;IAClE,CAAC;IACD,OAAO,YAAY,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,cAAc,2BAA2B,CAAA;AACjG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/sdk",
3
- "version": "64.2.0",
3
+ "version": "64.4.0",
4
4
  "description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "engines": {
@@ -10,7 +10,12 @@ import type { AdvisoryRequest, AdvisoryResult } from '../types/advisory/result.j
10
10
  import type { CostInfo, TokenUsage } from '../types/common/index.js'
11
11
  import { type Message, createSystemMessage, createUserMessage } from '../types/message/index.js'
12
12
  import type { LLMToolSchema } from '../types/tool/index.js'
13
- import { accumulateUnpricedCost, calculateCost } from '../utils/cost.js'
13
+ import {
14
+ accumulateReportedCost,
15
+ accumulateUnpricedCost,
16
+ calculateCost,
17
+ hasReportedCost,
18
+ } from '../utils/cost.js'
14
19
  import { type Logger, resolveLogger } from '../utils/logger.js'
15
20
  import { renderAdvisoryHistory } from './history.js'
16
21
  import { ADVISORY_RESPONSE_CONTRACT, parseAdvisoryResponse } from './parse.js'
@@ -212,7 +217,8 @@ export class AdvisoryExecutor {
212
217
  }
213
218
 
214
219
  /**
215
- * Cost for one call, from the advisor's own pricing, then the catalogue.
220
+ * Cost for one call: the provider's reported charge, else the advisor's own
221
+ * pricing, else the catalogue.
216
222
  *
217
223
  * When neither has a rate this reports the tokens as UNPRICED rather than
218
224
  * as a cost of zero. The previous version returned a zero rate card and a
@@ -224,6 +230,11 @@ export class AdvisoryExecutor {
224
230
  * because the number happens to be unenforced.
225
231
  */
226
232
  private computeCost(advisor: AdvisorDefinition, usage: TokenUsage): CostInfo {
233
+ // A charge the provider reported is what the account paid, so it wins over
234
+ // any rate card (the same order the session recorder uses).
235
+ if (hasReportedCost(usage)) {
236
+ return accumulateReportedCost(ZERO_COST, usage.reportedCostUsd)
237
+ }
227
238
  const pricing = advisor.pricing ?? resolveModelPricing(advisor.provider.id, advisor.model)
228
239
  if (!pricing) {
229
240
  return accumulateUnpricedCost(ZERO_COST, usage)
@@ -197,8 +197,8 @@ const WINDOWS: ReadonlyArray<readonly [prefix: string, tokens: number]> = [
197
197
  // (a fine-tune, a distill), and nothing says it keeps the parent's window.
198
198
  // Over-estimating ends a turn on a provider rejection; under-estimating
199
199
  // costs a summary. So an id not named here falls to the bare `deepseek`
200
- // row below, the 64k the older ids (chat, reasoner, R1 distills) had. The
201
- // three ids are matched whole (see `DEEPSEEK_ONE_MILLION_IDS`), never by
200
+ // row below, the 64k the older ids (chat, reasoner, R1 distills) had. Listed
201
+ // ids are matched whole (see `DEEPSEEK_ONE_MILLION_IDS`), never by
202
202
  // substring.
203
203
  ['deepseek', 64_000],
204
204
  ]
@@ -208,6 +208,13 @@ const DEEPSEEK_ONE_MILLION_IDS: ReadonlySet<string> = new Set([
208
208
  'deepseek-v4-flash',
209
209
  'deepseek-v4-pro',
210
210
  'deepseek-flash',
211
+ // The revisions and dated snapshots a gateway's model list names for the
212
+ // same generation. Each is listed whole: a new revision is a new row here
213
+ // (or is reported by the provider), never a prefix match.
214
+ 'deepseek-v4.1-flash',
215
+ 'deepseek-v4.1-flash-1017',
216
+ 'deepseek-v4-flash-0731',
217
+ 'deepseek-v4-pro-0813',
211
218
  ])
212
219
 
213
220
  /** The id with a gateway prefix (`deepseek/`) and a `:tag` (`:free`) removed. */
package/src/eval/judge.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { collectChatCompletion } from '../provider/collect-chat-completion.js'
2
2
  import { resolveStreamIdleTimeoutMs, withStreamIdleTimeout } from '../provider/idle-timeout.js'
3
+ import { chatStreamForSideRequest } from '../provider/side-request-reasoning.js'
3
4
  import { chatStreamWithSamplingRepair } from '../runtime/query/iteration/side-call.js'
4
5
  import type { LLMProvider } from '../types/provider/interface.js'
5
6
  import type { EvalCase, EvalTurn, Score, Scorer } from './types.js'
@@ -222,15 +223,21 @@ export function judgeScorer(config: JudgeScorerConfig): Scorer {
222
223
  name: config.name ?? 'judge',
223
224
  async score(turn: EvalTurn, evalCase: EvalCase, signal?: AbortSignal): Promise<Score> {
224
225
  const response = await collectChatCompletion(
225
- chatStreamWithSamplingRepair(provider, {
226
- model: config.model,
227
- messages: [{ role: 'user', content: buildPrompt(config, turn, evalCase, scale) }],
228
- // The same turn must grade the same way twice, or a
229
- // regression cannot be told from sampling noise.
230
- temperature: 0,
231
- maxTokens: 512,
232
- ...(signal ? { signal } : {}),
233
- }),
226
+ // A grade is a side request: a thinking model must not spend the
227
+ // whole allowance on reasoning and hand back nothing to grade.
228
+ chatStreamForSideRequest(
229
+ provider,
230
+ {
231
+ model: config.model,
232
+ messages: [{ role: 'user', content: buildPrompt(config, turn, evalCase, scale) }],
233
+ // The same turn must grade the same way twice, or a
234
+ // regression cannot be told from sampling noise.
235
+ temperature: 0,
236
+ maxTokens: 512,
237
+ ...(signal ? { signal } : {}),
238
+ },
239
+ (request) => chatStreamWithSamplingRepair(provider, request),
240
+ ),
234
241
  )
235
242
 
236
243
  const verdict = parseVerdict(response.message.content ?? '', scale)
@@ -323,7 +323,7 @@ export class AgentManager {
323
323
  private deps: AgentManagerDeps
324
324
  private topicManager: TopicManager
325
325
  private readonly pendingSpawns = new Map<SessionId, PendingSpawn[]>()
326
- private readonly drainingParents = new Set<SessionId>()
326
+ private readonly drainingParents = new Map<SessionId, Promise<void>>()
327
327
  private readonly executingTasks = new Set<TaskId>()
328
328
  private readonly cancelingTasks = new Set<TaskId>()
329
329
  private admissionTimer: ReturnType<typeof setTimeout> | undefined
@@ -441,14 +441,25 @@ export class AgentManager {
441
441
  } catch (error) {
442
442
  this.failAdmission(entry, error)
443
443
  }
444
- this.pumpAdmissions(options.parentSessionId)
444
+ // Report the task as it stands once admission has had its turn: started
445
+ // when there was room, still pending only when the pass stopped at a
446
+ // capacity or budget limit. Returned earlier, every task of a burst
447
+ // launched at the same moment would read as waiting for a slot.
448
+ await this.pumpAdmissions(options.parentSessionId)
449
+ // A pass that was already running may have looked at the queue before this
450
+ // entry was ready and ended without it. One more pass admits it now; if
451
+ // the first pass stopped at a limit, the second stops at the same limit.
452
+ if (entry.ready && task.state === 'pending' && !this.disposed)
453
+ await this.pumpAdmissions(options.parentSessionId)
445
454
  return task
446
455
  }
447
456
 
448
- private pumpAdmissions(parentSessionId: SessionId): void {
449
- if (this.disposed || this.drainingParents.has(parentSessionId)) return
450
- this.drainingParents.add(parentSessionId)
451
- void this.drainAdmissions(parentSessionId)
457
+ /** Run one admission pass; resolves when it has started what it can, never rejects. */
458
+ private pumpAdmissions(parentSessionId: SessionId): Promise<void> {
459
+ if (this.disposed) return Promise.resolve()
460
+ const running = this.drainingParents.get(parentSessionId)
461
+ if (running) return running
462
+ const pass = this.drainAdmissions(parentSessionId)
452
463
  .finally(() => {
453
464
  this.drainingParents.delete(parentSessionId)
454
465
  // External handoffs and metadata changes have no manager event. A
@@ -467,6 +478,8 @@ export class AgentManager {
467
478
  'exception.message': toErrorMessage(error),
468
479
  }),
469
480
  )
481
+ this.drainingParents.set(parentSessionId, pass)
482
+ return pass
470
483
  }
471
484
 
472
485
  private async drainAdmissions(parentSessionId: SessionId): Promise<void> {
@@ -61,7 +61,9 @@ import {
61
61
  type ModelPricing,
62
62
  ZERO_COST,
63
63
  accumulateCost,
64
+ accumulateReportedCost,
64
65
  accumulateUnpricedCost,
66
+ hasReportedCost,
65
67
  } from '../../utils/cost.js'
66
68
  import { asCheckpointId, generateAuditEventId, generateMessageId } from '../../utils/id.js'
67
69
  import { childOutcomeRecorded, childSessionEnded } from '../agent/child-session.js'
@@ -544,7 +546,16 @@ export class TurnRecorder {
544
546
  }
545
547
 
546
548
  accumulateUsage(usage: TokenUsage, servedBy: PricingSubject): void {
547
- this.#turn.tokenUsage = accumulateTokenUsage(this.#turn.tokenUsage, usage)
549
+ // The reported charge is money, and it is recorded in `costInfo` below; the
550
+ // usage totals that reach the session log stay token counts.
551
+ const { reportedCostUsd: _charged, ...counted } = usage
552
+ this.#turn.tokenUsage = accumulateTokenUsage(this.#turn.tokenUsage, counted)
553
+ // What the provider says it charged wins over a rate card; the card is
554
+ // the fallback for a call that reported nothing.
555
+ if (hasReportedCost(usage)) {
556
+ this.#turn.costInfo = accumulateReportedCost(this.#turn.costInfo, usage.reportedCostUsd)
557
+ return
558
+ }
548
559
  const pricing = this.#resolvePricing(servedBy)
549
560
  this.#turn.costInfo =
550
561
  pricing === undefined
@@ -71,8 +71,14 @@ export const CODING_AGENT_WORKING_DOCTRINE = `## How you work
71
71
  - After a broad \`git add\`, review what was staged before committing; a file whose name looks harmless can still carry a secret.
72
72
  - Never change git configuration or other persistent settings without asking: not \`user.name\` or \`user.email\`, hooks, remotes, credential helpers, or any \`git config\` (local or global), nor a shell profile or a tool's own config file. If a commit fails because no identity is set, stop and tell the user the command to set one; do not invent one.
73
73
 
74
+ ### Answering a question
75
+ - When the user asks a question or describes a problem, your reply answers or assesses it first. Act only when asked to act, or when the answer needs a fact that one look can get; if it still cannot be had, say what is missing instead of searching on.
76
+ - Never open a reply with an apology or with agreement for its own sake. Begin with the answer.
77
+ - A step that says it will do something does it in that step, and a turn never ends on a promise of a later answer.
78
+ - Reply in the language the user wrote in and keep to the form they asked for, for example money and not tokens.
79
+
74
80
  ### Keeping the user informed
75
- - Before your first tool call, say in one short line what you are about to do and why. While you work, add a one-line update when you find something, change direction or hit a blocker, and after a long stretch without one, say in a few words where you are, then continue. Brief is good and silence is not; the tool rows on screen already show the details.
81
+ - Before your first tool call, say in one short line what you are about to do and why. While you work, add a one-line update when you find something, change direction or hit a blocker, and after a long stretch without one, say in a few words where you are, then continue. Brief is good and silence is not; the tool rows on screen already show the details. A reply that is itself the answer needs no such line.
76
82
  - Keep the final reply short and specific: what changed, what was verified, what is left.`
77
83
 
78
84
  /**
@@ -563,10 +563,15 @@ export function withProviderFallback(
563
563
  },
564
564
  // A chain takes a forced choice only if every member does: the request may
565
565
  // be served by any of them, and the one that refuses would fail the step.
566
- acceptsForcedToolChoiceFor: (model: string, thinking?: ThinkingConfig) =>
566
+ acceptsForcedToolChoiceFor: (
567
+ model: string,
568
+ thinking?: ThinkingConfig,
569
+ effort?: ReasoningEffort,
570
+ ) =>
567
571
  members.every(
568
572
  (member) =>
569
- member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking) ?? true,
573
+ member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking, effort) ??
574
+ true,
570
575
  ),
571
576
  reasoningEffortLevelsFor: (model: string, thinking?: ThinkingConfig) =>
572
577
  commonReasoningEffortLevels(members, model, thinking),
@@ -228,7 +228,8 @@ export function withStreamIdleTimeout(
228
228
  acceptsForcedToolChoiceFor: (
229
229
  model: string,
230
230
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
231
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking) ?? true,
231
+ effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
232
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
232
233
  }
233
234
  : {}),
234
235
  ...(provider.reasoningEffortLevelsFor
@@ -31,7 +31,7 @@ function extractStreamUsage(usage: TokenUsage | undefined): ProviderCallUsage |
31
31
  inputTokens: u.inputTokens ?? u.promptTokens,
32
32
  outputTokens: u.outputTokens ?? u.completionTokens,
33
33
  totalTokens: u.totalTokens,
34
- costUsd: u.costUsd,
34
+ costUsd: u.costUsd ?? u.reportedCostUsd,
35
35
  }
36
36
  }
37
37
 
@@ -440,7 +440,8 @@ export function withProviderRetry(
440
440
  acceptsForcedToolChoiceFor: (
441
441
  model: string,
442
442
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
443
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking) ?? true,
443
+ effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
444
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
444
445
  }
445
446
  : {}),
446
447
  ...(provider.reasoningEffortLevelsFor
@@ -0,0 +1,121 @@
1
+ import type {
2
+ ChatCompletionParams,
3
+ LLMProvider,
4
+ ReasoningEffort,
5
+ StreamChunk,
6
+ ThinkingConfig,
7
+ } from '../types/provider/index.js'
8
+
9
+ /**
10
+ * Room added to a side request's answer allowance when the provider could not
11
+ * promise that reasoning is off. A thinking model spends tokens on reasoning
12
+ * before the first word of the answer, and a small answer allowance is gone by
13
+ * then: the reply is cut off with nothing in it.
14
+ */
15
+ export const SIDE_REQUEST_REASONING_HEADROOM = 2048
16
+
17
+ const DISABLED: ThinkingConfig = { type: 'disabled' }
18
+
19
+ /** Efforts a driver may offer for "as little as possible", cheapest first. */
20
+ const LOWEST_FIRST: readonly ReasoningEffort[] = ['none', 'minimal', 'low', 'medium']
21
+
22
+ /** The request fields a side request sets: thinking, effort and the answer allowance. */
23
+ export type SideReasoningFields = Pick<ChatCompletionParams, 'thinking' | 'effort' | 'maxTokens'>
24
+
25
+ /**
26
+ * The reasoning settings for a small request made beside a turn (a lookup, a
27
+ * label, a title, a classifier): ask the provider for no reasoning where it can
28
+ * switch it off for one request, and where it cannot, leave room in the answer
29
+ * allowance for the reasoning it will spend.
30
+ *
31
+ * The turn's own thinking and effort are never inherited: a side request is not
32
+ * the turn, and a high effort chosen for the turn's work would starve a
33
+ * 60-token label. The turn's own requests are not touched by this.
34
+ *
35
+ * Each driver answers through `reasoningEffortLevelsFor(model, disabled)`:
36
+ * - a list that holds `none`: send thinking disabled and effort `none`;
37
+ * - a list without `none` (effort is still offered beside a disabled body): send
38
+ * thinking disabled and the lowest level it offers, and add headroom;
39
+ * - no answer: send thinking disabled, which every driver either carries or
40
+ * leaves out, and add headroom because nothing confirms it took effect.
41
+ */
42
+ export function sideRequestReasoning(
43
+ provider: Pick<LLMProvider, 'reasoningEffortLevelsFor'>,
44
+ model: string,
45
+ maxTokens: number,
46
+ ): SideReasoningFields {
47
+ let levels: readonly ReasoningEffort[] | undefined
48
+ try {
49
+ levels = provider.reasoningEffortLevelsFor?.(model, DISABLED)
50
+ } catch {
51
+ levels = undefined
52
+ }
53
+ if (levels?.includes('none')) {
54
+ return { thinking: DISABLED, effort: 'none', maxTokens }
55
+ }
56
+ const roomy = maxTokens + SIDE_REQUEST_REASONING_HEADROOM
57
+ if (levels !== undefined && levels.length > 0) {
58
+ const lowest = LOWEST_FIRST.find((level) => levels.includes(level)) ?? levels[0]
59
+ // The levels were asked with thinking disabled, so the driver accepts a
60
+ // disabled body here; send it so reasoning is off, not merely cheap.
61
+ return { thinking: DISABLED, ...(lowest ? { effort: lowest } : {}), maxTokens: roomy }
62
+ }
63
+ return { thinking: DISABLED, maxTokens: roomy }
64
+ }
65
+
66
+ /** A refusal of the reasoning controls themselves, before any output. */
67
+ function refusesReasoningControls(error: unknown): boolean {
68
+ const text = error instanceof Error ? error.message : String(error)
69
+ // An error that merely mentions the words (a rate limit, an overload, a
70
+ // timeout) is not a refusal of the controls: it must neither cost an extra
71
+ // request nor switch the controls off for the model.
72
+ if (/rate.?limit|too many requests|overloaded|timed? ?out|\b(429|5\d\d)\b/i.test(text))
73
+ return false
74
+ const names = /\b(thinking|reasoning|effort)\b/i.test(text)
75
+ const rejects =
76
+ /unsupported|not supported|unsupport|invalid|unknown|unrecogni[sz]ed|unexpected|not allowed|not permitted|does not (?:accept|support|allow)|not accept|extra inputs|bad request|\b400\b|\b422\b/i.test(
77
+ text,
78
+ )
79
+ return names && rejects
80
+ }
81
+
82
+ /**
83
+ * Stream a side request with {@link sideRequestReasoning} applied. A driver that
84
+ * refuses the reasoning controls before sending anything gets the request again
85
+ * without them, at the roomy allowance, and the model is remembered so the next
86
+ * request does not ask again. Any other failure is thrown unchanged.
87
+ */
88
+ const noControls = new WeakMap<object, Set<string>>()
89
+
90
+ export async function* chatStreamForSideRequest(
91
+ provider: LLMProvider,
92
+ params: Omit<ChatCompletionParams, 'thinking' | 'effort'>,
93
+ /** How the request is sent; a caller with its own repair layer passes it. */
94
+ send: (request: ChatCompletionParams) => AsyncIterable<StreamChunk> = (request) =>
95
+ provider.chatStream(request),
96
+ ): AsyncGenerator<StreamChunk> {
97
+ const base = params.maxTokens ?? 256
98
+ const skip = noControls.get(provider)?.has(params.model) === true
99
+ const fields = sideRequestReasoning(provider, params.model, base)
100
+ const plain: ChatCompletionParams = {
101
+ ...params,
102
+ maxTokens: base + SIDE_REQUEST_REASONING_HEADROOM,
103
+ }
104
+ if (skip) {
105
+ yield* send(plain)
106
+ return
107
+ }
108
+ let yielded = false
109
+ try {
110
+ for await (const chunk of send({ ...params, ...fields })) {
111
+ yielded = true
112
+ yield chunk
113
+ }
114
+ } catch (error) {
115
+ if (yielded || params.signal?.aborted || !refusesReasoningControls(error)) throw error
116
+ const seen = noControls.get(provider) ?? new Set<string>()
117
+ seen.add(params.model)
118
+ noControls.set(provider, seen)
119
+ yield* send(plain)
120
+ }
121
+ }
@@ -126,6 +126,7 @@ export * from './utils/id.js'
126
126
 
127
127
  export {
128
128
  accumulateCost,
129
+ accumulateReportedCost,
129
130
  accumulateUnpricedCost,
130
131
  calculateCost,
131
132
  describeCost,
@@ -1196,6 +1197,12 @@ export { wrapProviderWithProbes } from './provider/instrumentation.js'
1196
1197
  export type { ProviderInstrumentationOptions } from './provider/instrumentation.js'
1197
1198
  export type { ResolvedProviderCapabilities } from './provider/capabilities.js'
1198
1199
  export { collectChatCompletion } from './provider/collect-chat-completion.js'
1200
+ export {
1201
+ chatStreamForSideRequest,
1202
+ sideRequestReasoning,
1203
+ SIDE_REQUEST_REASONING_HEADROOM,
1204
+ } from './provider/side-request-reasoning.js'
1205
+ export type { SideReasoningFields } from './provider/side-request-reasoning.js'
1199
1206
  export { withModelWindowSuffixStripped } from './provider/model-window-suffix.js'
1200
1207
 
1201
1208
  // Old spellings of renamed exports, still live for one deprecation window.
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { GENAI } from '../../../constants/telemetry/index.js'
23
23
  import { collectChatCompletion } from '../../../provider/collect-chat-completion.js'
24
+ import { chatStreamForSideRequest } from '../../../provider/side-request-reasoning.js'
24
25
  import type { ToolManager } from '../../../toolsets/manager.js'
25
26
  import type { TokenUsage } from '../../../types/common/index.js'
26
27
  import type { LaunchedScript, ToolCallSummary } from '../../../types/hitl/index.js'
@@ -216,16 +217,23 @@ export function createAutoReviewClassifier(
216
217
  // Raced against the abort, not only handed the signal: a provider that
217
218
  // ignores it would otherwise hold the call open past its deadline, and
218
219
  // a turn cancelled while it waits would wait with it.
220
+ const request = {
221
+ model: options.model,
222
+ messages,
223
+ maxTokens: stage === 1 ? 64 : 8_192,
224
+ temperature: options.temperature ?? 0,
225
+ ...(stage === 1 ? { stop: [VERDICT_STOP] } : {}),
226
+ cacheControl: { type: 'auto' as const },
227
+ signal: controller.signal,
228
+ }
229
+ // The quick pass answers in 64 tokens, so it asks for no reasoning
230
+ // (or leaves room for it); the reasoned pass has its own large budget.
219
231
  const collected = collectChatCompletion(
220
- chatStreamWithSamplingRepair(options.provider, {
221
- model: options.model,
222
- messages,
223
- maxTokens: stage === 1 ? 64 : 8_192,
224
- temperature: options.temperature ?? 0,
225
- ...(stage === 1 ? { stop: [VERDICT_STOP] } : {}),
226
- cacheControl: { type: 'auto' },
227
- signal: controller.signal,
228
- }),
232
+ stage === 1
233
+ ? chatStreamForSideRequest(options.provider, request, (sent) =>
234
+ chatStreamWithSamplingRepair(options.provider, sent),
235
+ )
236
+ : chatStreamWithSamplingRepair(options.provider, request),
229
237
  )
230
238
  collected.catch(() => {})
231
239
  const cutOff = new Promise<never>((_resolve, reject) => {
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod'
2
+ import { chatStreamForSideRequest } from '../../provider/side-request-reasoning.js'
2
3
  import { StreamTextAccumulator } from '../../provider/stream-text.js'
3
4
  import { type TokenUsage, mergeTokenUsage } from '../../types/common/index.js'
4
5
  import { createSystemMessage, createUserMessage } from '../../types/message/index.js'
@@ -69,15 +70,19 @@ export function createCallbackInference(
69
70
  const text = new StreamTextAccumulator()
70
71
  let invalidOutput: string | undefined
71
72
  let usage: TokenUsage | undefined
73
+ let finishReason: PreparationTextResult['finishReason']
72
74
  try {
73
- for await (const chunk of ctx.provider.chatStream({
75
+ // A small request beside the turn: reasoning off where the driver
76
+ // can switch it off for one request, room for it where it cannot.
77
+ // The turn's own thinking and effort stay the turn's.
78
+ for await (const chunk of chatStreamForSideRequest(ctx.provider, {
74
79
  model,
75
80
  providerRoute: route(),
76
81
  messages: [createSystemMessage(input.system), createUserMessage(input.prompt)],
77
82
  maxTokens: input.maxTokens,
78
- ...(ctx.turnConfig.effort ? { effort: ctx.turnConfig.effort } : {}),
79
83
  signal,
80
84
  })) {
85
+ if (chunk.finishReason) finishReason = chunk.finishReason
81
86
  if (chunk.usage) usage = usage ? mergeTokenUsage(usage, chunk.usage) : { ...chunk.usage }
82
87
  if (chunk.error) throw new Error(chunk.error)
83
88
  signal.throwIfAborted()
@@ -91,7 +96,12 @@ export function createCallbackInference(
91
96
  signal.throwIfAborted()
92
97
  if (!usage) throw new Error(`${label} inference ended without usage.`)
93
98
  if (invalidOutput) throw new Error(invalidOutput)
94
- return { text: text.text, usage, servedBy: route() }
99
+ return {
100
+ text: text.text,
101
+ usage,
102
+ servedBy: route(),
103
+ ...(finishReason ? { finishReason } : {}),
104
+ }
95
105
  } finally {
96
106
  if (usage) ctx.recorder.accumulateUsage(usage, route())
97
107
  }