@qmediat.io/gemini-code-context-mcp 1.24.0 → 1.25.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 (189) hide show
  1. package/CHANGELOG.md +110 -1
  2. package/README.md +1 -1
  3. package/dist/cache/cache-manager.d.ts +23 -34
  4. package/dist/cache/cache-manager.d.ts.map +1 -1
  5. package/dist/cache/cache-manager.js +324 -272
  6. package/dist/cache/cache-manager.js.map +1 -1
  7. package/dist/cache/caching-mode.d.ts +5 -3
  8. package/dist/cache/caching-mode.d.ts.map +1 -1
  9. package/dist/cache/caching-mode.js +6 -4
  10. package/dist/cache/caching-mode.js.map +1 -1
  11. package/dist/cache/ttl-watcher.d.ts.map +1 -1
  12. package/dist/cache/ttl-watcher.js +7 -1
  13. package/dist/cache/ttl-watcher.js.map +1 -1
  14. package/dist/cache/ttl.d.ts +8 -0
  15. package/dist/cache/ttl.d.ts.map +1 -0
  16. package/dist/cache/ttl.js +10 -0
  17. package/dist/cache/ttl.js.map +1 -0
  18. package/dist/manifest/db.d.ts.map +1 -1
  19. package/dist/manifest/db.js +2 -1
  20. package/dist/manifest/db.js.map +1 -1
  21. package/dist/tools/agentic/dispatch.d.ts +68 -0
  22. package/dist/tools/agentic/dispatch.d.ts.map +1 -0
  23. package/dist/tools/agentic/dispatch.js +167 -0
  24. package/dist/tools/agentic/dispatch.js.map +1 -0
  25. package/dist/tools/agentic/input.d.ts +28 -0
  26. package/dist/tools/agentic/input.d.ts.map +1 -0
  27. package/dist/tools/agentic/input.js +66 -0
  28. package/dist/tools/agentic/input.js.map +1 -0
  29. package/dist/tools/agentic/instructions.d.ts +46 -0
  30. package/dist/tools/agentic/instructions.d.ts.map +1 -0
  31. package/dist/tools/agentic/instructions.js +170 -0
  32. package/dist/tools/agentic/instructions.js.map +1 -0
  33. package/dist/tools/agentic/iteration.d.ts +81 -0
  34. package/dist/tools/agentic/iteration.d.ts.map +1 -0
  35. package/dist/tools/agentic/iteration.js +317 -0
  36. package/dist/tools/agentic/iteration.js.map +1 -0
  37. package/dist/tools/agentic/ledger.d.ts +64 -0
  38. package/dist/tools/agentic/ledger.d.ts.map +1 -0
  39. package/dist/tools/agentic/ledger.js +110 -0
  40. package/dist/tools/agentic/ledger.js.map +1 -0
  41. package/dist/tools/agentic/loop.d.ts +10 -0
  42. package/dist/tools/agentic/loop.d.ts.map +1 -0
  43. package/dist/tools/agentic/loop.js +179 -0
  44. package/dist/tools/agentic/loop.js.map +1 -0
  45. package/dist/tools/agentic/no-progress.d.ts +90 -0
  46. package/dist/tools/agentic/no-progress.d.ts.map +1 -0
  47. package/dist/tools/agentic/no-progress.js +107 -0
  48. package/dist/tools/agentic/no-progress.js.map +1 -0
  49. package/dist/tools/agentic/pass-clock.d.ts +85 -0
  50. package/dist/tools/agentic/pass-clock.d.ts.map +1 -0
  51. package/dist/tools/agentic/pass-clock.js +162 -0
  52. package/dist/tools/agentic/pass-clock.js.map +1 -0
  53. package/dist/tools/agentic/phase-defaults.d.ts +29 -0
  54. package/dist/tools/agentic/phase-defaults.d.ts.map +1 -0
  55. package/dist/tools/agentic/phase-defaults.js +23 -0
  56. package/dist/tools/agentic/phase-defaults.js.map +1 -0
  57. package/dist/tools/agentic/rescue.d.ts +69 -0
  58. package/dist/tools/agentic/rescue.d.ts.map +1 -0
  59. package/dist/tools/agentic/rescue.js +203 -0
  60. package/dist/tools/agentic/rescue.js.map +1 -0
  61. package/dist/tools/agentic/response.d.ts +16 -0
  62. package/dist/tools/agentic/response.d.ts.map +1 -0
  63. package/dist/tools/agentic/response.js +25 -0
  64. package/dist/tools/agentic/response.js.map +1 -0
  65. package/dist/tools/agentic/results.d.ts +76 -0
  66. package/dist/tools/agentic/results.d.ts.map +1 -0
  67. package/dist/tools/agentic/results.js +228 -0
  68. package/dist/tools/agentic/results.js.map +1 -0
  69. package/dist/tools/agentic/run.d.ts +130 -0
  70. package/dist/tools/agentic/run.d.ts.map +1 -0
  71. package/dist/tools/agentic/run.js +128 -0
  72. package/dist/tools/agentic/run.js.map +1 -0
  73. package/dist/tools/agentic/sandbox.d.ts +13 -2
  74. package/dist/tools/agentic/sandbox.d.ts.map +1 -1
  75. package/dist/tools/agentic/sandbox.js +127 -111
  76. package/dist/tools/agentic/sandbox.js.map +1 -1
  77. package/dist/tools/agentic/workspace-tools.d.ts +30 -27
  78. package/dist/tools/agentic/workspace-tools.d.ts.map +1 -1
  79. package/dist/tools/agentic/workspace-tools.js +324 -385
  80. package/dist/tools/agentic/workspace-tools.js.map +1 -1
  81. package/dist/tools/ask/answer.d.ts +9 -0
  82. package/dist/tools/ask/answer.d.ts.map +1 -0
  83. package/dist/tools/ask/answer.js +28 -0
  84. package/dist/tools/ask/answer.js.map +1 -0
  85. package/dist/tools/ask/attachments.d.ts +25 -0
  86. package/dist/tools/ask/attachments.d.ts.map +1 -0
  87. package/dist/tools/ask/attachments.js +85 -0
  88. package/dist/tools/ask/attachments.js.map +1 -0
  89. package/dist/tools/ask/call.d.ts +61 -0
  90. package/dist/tools/ask/call.d.ts.map +1 -0
  91. package/dist/tools/ask/call.js +6 -0
  92. package/dist/tools/ask/call.js.map +1 -0
  93. package/dist/tools/ask/guard.d.ts +24 -0
  94. package/dist/tools/ask/guard.d.ts.map +1 -0
  95. package/dist/tools/ask/guard.js +79 -0
  96. package/dist/tools/ask/guard.js.map +1 -0
  97. package/dist/tools/ask/input.d.ts +45 -0
  98. package/dist/tools/ask/input.d.ts.map +1 -0
  99. package/dist/tools/ask/input.js +93 -0
  100. package/dist/tools/ask/input.js.map +1 -0
  101. package/dist/tools/ask/instruction.d.ts +8 -0
  102. package/dist/tools/ask/instruction.d.ts.map +1 -0
  103. package/dist/tools/ask/instruction.js +13 -0
  104. package/dist/tools/ask/instruction.js.map +1 -0
  105. package/dist/tools/ask/request.d.ts +14 -0
  106. package/dist/tools/ask/request.d.ts.map +1 -0
  107. package/dist/tools/ask/request.js +38 -0
  108. package/dist/tools/ask/request.js.map +1 -0
  109. package/dist/tools/ask/results.d.ts +23 -0
  110. package/dist/tools/ask/results.d.ts.map +1 -0
  111. package/dist/tools/ask/results.js +107 -0
  112. package/dist/tools/ask/results.js.map +1 -0
  113. package/dist/tools/ask/setup.d.ts +22 -0
  114. package/dist/tools/ask/setup.d.ts.map +1 -0
  115. package/dist/tools/ask/setup.js +57 -0
  116. package/dist/tools/ask/setup.js.map +1 -0
  117. package/dist/tools/ask/sizing.d.ts +10 -0
  118. package/dist/tools/ask/sizing.d.ts.map +1 -0
  119. package/dist/tools/ask/sizing.js +33 -0
  120. package/dist/tools/ask/sizing.js.map +1 -0
  121. package/dist/tools/ask/thinking.d.ts +54 -0
  122. package/dist/tools/ask/thinking.d.ts.map +1 -0
  123. package/dist/tools/ask/thinking.js +69 -0
  124. package/dist/tools/ask/thinking.js.map +1 -0
  125. package/dist/tools/ask-agentic-fallback.d.ts +33 -0
  126. package/dist/tools/ask-agentic-fallback.d.ts.map +1 -0
  127. package/dist/tools/ask-agentic-fallback.js +113 -0
  128. package/dist/tools/ask-agentic-fallback.js.map +1 -0
  129. package/dist/tools/ask-agentic.tool.d.ts +11 -44
  130. package/dist/tools/ask-agentic.tool.d.ts.map +1 -1
  131. package/dist/tools/ask-agentic.tool.js +139 -1618
  132. package/dist/tools/ask-agentic.tool.js.map +1 -1
  133. package/dist/tools/ask.tool.d.ts +3 -41
  134. package/dist/tools/ask.tool.d.ts.map +1 -1
  135. package/dist/tools/ask.tool.js +46 -944
  136. package/dist/tools/ask.tool.js.map +1 -1
  137. package/dist/tools/code.tool.d.ts.map +1 -1
  138. package/dist/tools/code.tool.js +376 -514
  139. package/dist/tools/code.tool.js.map +1 -1
  140. package/dist/tools/reindex.tool.d.ts.map +1 -1
  141. package/dist/tools/reindex.tool.js +19 -22
  142. package/dist/tools/reindex.tool.js.map +1 -1
  143. package/dist/tools/shared/abort-timeout.d.ts +43 -5
  144. package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
  145. package/dist/tools/shared/abort-timeout.js +111 -102
  146. package/dist/tools/shared/abort-timeout.js.map +1 -1
  147. package/dist/tools/shared/call-ledger.d.ts +27 -12
  148. package/dist/tools/shared/call-ledger.d.ts.map +1 -1
  149. package/dist/tools/shared/call-ledger.js +57 -39
  150. package/dist/tools/shared/call-ledger.js.map +1 -1
  151. package/dist/tools/shared/continuation.d.ts +1 -1
  152. package/dist/tools/shared/continuation.d.ts.map +1 -1
  153. package/dist/tools/shared/eager-answer.d.ts +78 -0
  154. package/dist/tools/shared/eager-answer.d.ts.map +1 -0
  155. package/dist/tools/shared/eager-answer.js +130 -0
  156. package/dist/tools/shared/eager-answer.js.map +1 -0
  157. package/dist/tools/shared/eager-call.d.ts +114 -0
  158. package/dist/tools/shared/eager-call.d.ts.map +1 -0
  159. package/dist/tools/shared/eager-call.js +95 -0
  160. package/dist/tools/shared/eager-call.js.map +1 -0
  161. package/dist/tools/shared/eager-steps.d.ts +114 -0
  162. package/dist/tools/shared/eager-steps.d.ts.map +1 -0
  163. package/dist/tools/shared/eager-steps.js +152 -0
  164. package/dist/tools/shared/eager-steps.js.map +1 -0
  165. package/dist/tools/shared/question-fields.d.ts +10 -0
  166. package/dist/tools/shared/question-fields.d.ts.map +1 -0
  167. package/dist/tools/shared/question-fields.js +13 -0
  168. package/dist/tools/shared/question-fields.js.map +1 -0
  169. package/dist/tools/shared/service-tier.d.ts +9 -0
  170. package/dist/tools/shared/service-tier.d.ts.map +1 -1
  171. package/dist/tools/shared/service-tier.js +15 -0
  172. package/dist/tools/shared/service-tier.js.map +1 -1
  173. package/dist/tools/shared/settle-call.d.ts +11 -6
  174. package/dist/tools/shared/settle-call.d.ts.map +1 -1
  175. package/dist/tools/shared/settle-call.js +14 -10
  176. package/dist/tools/shared/settle-call.js.map +1 -1
  177. package/dist/tools/shared/thinking.d.ts +9 -0
  178. package/dist/tools/shared/thinking.d.ts.map +1 -1
  179. package/dist/tools/shared/thinking.js +10 -0
  180. package/dist/tools/shared/thinking.js.map +1 -1
  181. package/dist/tools/shared/throttle.d.ts +7 -0
  182. package/dist/tools/shared/throttle.d.ts.map +1 -1
  183. package/dist/tools/shared/throttle.js +18 -0
  184. package/dist/tools/shared/throttle.js.map +1 -1
  185. package/dist/tools/shared/workspace-refusal.d.ts +13 -0
  186. package/dist/tools/shared/workspace-refusal.d.ts.map +1 -0
  187. package/dist/tools/shared/workspace-refusal.js +23 -0
  188. package/dist/tools/shared/workspace-refusal.js.map +1 -0
  189. package/package.json +1 -1
@@ -2,15 +2,16 @@
2
2
  * The ledger side of an `ask` / `code` call: what its completed requests billed, and how the call settles its budget
3
3
  * reservation — on an answer, and on a failure.
4
4
  *
5
- * `GEMINI_DAILY_BUDGET_USD` bounds completed spend: every request that streamed to its end was billed, so its
6
- * reported usage, at list price, stays in the ledger whatever becomes of the call; only the unspent remainder of the
7
- * reservation is released. A call that fails before any request completed releases its reservation whole.
5
+ * The ledger books completed requests: every request that streamed to its end was billed, so its reported usage, at
6
+ * list price, stays in the ledger whatever becomes of the call; only the unspent remainder of the reservation is
7
+ * released. A call that fails before any request completed releases its reservation whole — whether Google bills a
8
+ * request aborted after its stream opened is not measured, and the ledger books it 0 (`docs/cost-model.md`).
8
9
  */
9
10
  import type { RanCachingMode } from '../../cache/caching-mode.js';
10
11
  import type { ManifestDb } from '../../manifest/db.js';
11
12
  import type { CompletedRequests, DecodeUsage } from './continuation.js';
12
13
  /** The tool a ledger row belongs to. */
13
- export type LedgerTool = 'ask' | 'code';
14
+ export type LedgerTool = 'ask' | 'code' | 'ask_agentic';
14
15
  /** What the completed requests of a call billed: their reported tokens and their cost at list price. */
15
16
  export interface BilledUsage {
16
17
  readonly cachedTokens: number;
@@ -21,13 +22,16 @@ export interface BilledUsage {
21
22
  readonly promptTokens: number;
22
23
  readonly costUsd: number;
23
24
  }
24
- /** The usage fields of a result: an answer, an `OUTPUT_CAP` stop, or a failure after completed requests. */
25
- export interface UsageFields {
25
+ /** The token and cost fields of a result: what the requests they describe billed. */
26
+ export interface BilledFields {
26
27
  readonly cachedTokens: number;
27
28
  readonly uncachedTokens: number;
28
29
  readonly outputTokens: number;
29
30
  readonly thinkingTokens: number;
30
31
  readonly costEstimateUsd: number;
32
+ }
33
+ /** The usage fields of a result: an answer, an `OUTPUT_CAP` stop, or a failure after completed requests. */
34
+ export interface UsageFields extends BilledFields {
31
35
  readonly continuationHops: number;
32
36
  }
33
37
  /** Where a call's spend is booked. */
@@ -36,7 +40,8 @@ export interface LedgerEntry {
36
40
  readonly toolName: LedgerTool;
37
41
  readonly model: string;
38
42
  readonly serviceTier: 'standard' | 'flex' | undefined;
39
- readonly cachingMode: RanCachingMode;
43
+ /** The caching mode that ran; `null` for a tool that sends no cached content (`ask_agentic`): no mode is booked. */
44
+ readonly cachingMode: RanCachingMode | null;
40
45
  }
41
46
  /** A call that failed, as its ledger sees it. */
42
47
  export interface FailedCall {
@@ -50,19 +55,24 @@ export interface FailedCall {
50
55
  }
51
56
  /**
52
57
  * The input a request that went through is billed at: the prompt tokens it reported, else — a response that carried
53
- * no usage — the input it was estimated to send. Under-billing a request the API completed is the worse error: the
54
- * estimate keeps the daily cap and the per-minute window a bound.
58
+ * no usage — the input it was estimated to send. Under-billing a request the API completed is the worse error, so it
59
+ * is booked at what its reservation covered, never 0. The estimate bounds the real input for `ask` / `code`; for an
60
+ * `ask_agentic` loop iteration it is a fixed 50,000 tokens and can be below it (`docs/cost-model.md`).
55
61
  */
56
62
  export declare function billedInputTokens(reported: number | undefined, estimate: number): number;
57
63
  /** The tokens a (summed) usage reports and their cost: the one cost function of a settled call. */
58
64
  export declare function billedUsage(usage: DecodeUsage | undefined, model: string, serviceTier: 'standard' | 'flex' | undefined): BilledUsage;
65
+ /** A billed usage as a result reports it, the cost rounded to 4 decimals. */
66
+ export declare function billedFields(billed: BilledUsage): BilledFields;
59
67
  export declare function usageFields(billed: BilledUsage, continuationHops: number): UsageFields;
60
68
  /**
61
69
  * Books a call at what it billed: its reservation finalised at that cost (the rest released), or — with no daily cap,
62
- * so no reservation — a usage row. A finalise that throws leaves the reservation's estimate booked, which stays a
63
- * bound; it is logged.
70
+ * so no reservation — a usage row. The booking is best-effort and never throws: it runs once the call's work is
71
+ * billed (an answer exists, or a request completed), and a failed write must not lose that answer nor replace the
72
+ * call's own error. A finalise that throws leaves the reservation's estimate booked; an insert that throws leaves no
73
+ * row. Either is logged.
64
74
  */
65
- export declare function recordBilledCall(manifest: ManifestDb, reservationId: number | null, entry: LedgerEntry, billed: BilledUsage, durationMs: number): void;
75
+ export declare function recordBilledCall(manifest: ManifestDb, reservationId: number | null, entry: LedgerEntry, billed: BilledUsage, durationMs: number, label?: string): void;
66
76
  /**
67
77
  * Settles the ledger of a failed call. With no request completed the reservation is released whole; after one or
68
78
  * more, the ledger keeps what they billed and the result gets their usage and the continuation requests whose
@@ -70,4 +80,9 @@ export declare function recordBilledCall(manifest: ManifestDb, reservationId: nu
70
80
  * A ledger write that throws is logged and never replaces the call's own error.
71
81
  */
72
82
  export declare function settleFailedCall(manifest: ManifestDb, failed: FailedCall): UsageFields | null;
83
+ /**
84
+ * Cancel a budget reservation (`null`: none was taken). A cancel that throws leaves the row at its estimate until the
85
+ * day ends; it is logged under `label`.
86
+ */
87
+ export declare function releaseReservation(manifest: ManifestDb, label: string, reservationId: number | null): void;
73
88
  //# sourceMappingURL=call-ledger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"call-ledger.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/call-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAExE,wCAAwC;AACxC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,CAAC;AAExC,wGAAwG;AACxG,MAAM,WAAW,WAAW;IAC1B,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AAED,mGAAmG;AACnG,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,GAAG,SAAS,EAC9B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,GAC3C,WAAW,CAsBb;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAQ9D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAEtF;AA+BD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,UAAU,EACpB,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,MAAuB,GAC7B,IAAI,CAiBN;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAY7F;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GAAG,IAAI,GAC3B,IAAI,CASN"}
@@ -2,17 +2,19 @@
2
2
  * The ledger side of an `ask` / `code` call: what its completed requests billed, and how the call settles its budget
3
3
  * reservation — on an answer, and on a failure.
4
4
  *
5
- * `GEMINI_DAILY_BUDGET_USD` bounds completed spend: every request that streamed to its end was billed, so its
6
- * reported usage, at list price, stays in the ledger whatever becomes of the call; only the unspent remainder of the
7
- * reservation is released. A call that fails before any request completed releases its reservation whole.
5
+ * The ledger books completed requests: every request that streamed to its end was billed, so its reported usage, at
6
+ * list price, stays in the ledger whatever becomes of the call; only the unspent remainder of the reservation is
7
+ * released. A call that fails before any request completed releases its reservation whole — whether Google bills a
8
+ * request aborted after its stream opened is not measured, and the ledger books it 0 (`docs/cost-model.md`).
8
9
  */
9
10
  import { estimateCostUsd, toMicrosUsd } from '../../utils/cost-estimator.js';
10
- import { logger } from '../../utils/logger.js';
11
+ import { logger, safeForLog } from '../../utils/logger.js';
11
12
  const tokens = (n) => (typeof n === 'number' ? n : 0);
12
13
  /**
13
14
  * The input a request that went through is billed at: the prompt tokens it reported, else — a response that carried
14
- * no usage — the input it was estimated to send. Under-billing a request the API completed is the worse error: the
15
- * estimate keeps the daily cap and the per-minute window a bound.
15
+ * no usage — the input it was estimated to send. Under-billing a request the API completed is the worse error, so it
16
+ * is booked at what its reservation covered, never 0. The estimate bounds the real input for `ask` / `code`; for an
17
+ * `ask_agentic` loop iteration it is a fixed 50,000 tokens and can be below it (`docs/cost-model.md`).
16
18
  */
17
19
  export function billedInputTokens(reported, estimate) {
18
20
  return typeof reported === 'number' && reported > 0 ? reported : estimate;
@@ -41,45 +43,62 @@ export function billedUsage(usage, model, serviceTier) {
41
43
  costUsd,
42
44
  };
43
45
  }
44
- export function usageFields(billed, continuationHops) {
46
+ /** A billed usage as a result reports it, the cost rounded to 4 decimals. */
47
+ export function billedFields(billed) {
45
48
  return {
46
49
  cachedTokens: billed.cachedTokens,
47
50
  uncachedTokens: billed.uncachedTokens,
48
51
  outputTokens: billed.outputTokens,
49
52
  thinkingTokens: billed.thinkingTokens,
50
53
  costEstimateUsd: Math.round(billed.costUsd * 10000) / 10000,
51
- continuationHops,
52
54
  };
53
55
  }
54
- /**
55
- * Books a call at what it billed: its reservation finalised at that cost (the rest released), or — with no daily cap,
56
- * so no reservation — a usage row. A finalise that throws leaves the reservation's estimate booked, which stays a
57
- * bound; it is logged.
58
- */
59
- export function recordBilledCall(manifest, reservationId, entry, billed, durationMs) {
60
- const settled = {
56
+ export function usageFields(billed, continuationHops) {
57
+ return { ...billedFields(billed), continuationHops };
58
+ }
59
+ function settledRowOf(entry, billed, durationMs) {
60
+ return {
61
61
  cachedTokens: billed.cachedTokens,
62
62
  uncachedTokens: billed.uncachedTokens,
63
63
  costUsdMicro: toMicrosUsd(billed.costUsd),
64
- durationMs,
65
- cachingMode: entry.cachingMode,
66
- cachedContentTokenCount: billed.cachedTokens,
64
+ durationMs: Math.max(1, durationMs),
65
+ ...(entry.cachingMode === null
66
+ ? {}
67
+ : { cachingMode: entry.cachingMode, cachedContentTokenCount: billed.cachedTokens }),
67
68
  };
68
- if (reservationId === null) {
69
- manifest.insertUsageMetric({
70
- workspaceRoot: entry.workspaceRoot,
71
- toolName: entry.toolName,
72
- model: entry.model,
73
- occurredAt: Date.now(),
74
- ...settled,
75
- });
76
- return;
77
- }
69
+ }
70
+ /** What the log says of a booking that could not be written: what the ledger holds instead. */
71
+ function unwrittenBookingLine(label, reservationId, costUsdMicro, err) {
72
+ const held = reservationId === null
73
+ ? 'insertUsageMetric failed; no usage row was written'
74
+ : `finalizeBudgetReservation failed for id=${reservationId}; the row keeps its reserved estimate`;
75
+ return `${label}: ${held}, the billed ${costUsdMicro} micros were not written. Error: ${safeForLog(err)}`;
76
+ }
77
+ /**
78
+ * Books a call at what it billed: its reservation finalised at that cost (the rest released), or — with no daily cap,
79
+ * so no reservation — a usage row. The booking is best-effort and never throws: it runs once the call's work is
80
+ * billed (an answer exists, or a request completed), and a failed write must not lose that answer nor replace the
81
+ * call's own error. A finalise that throws leaves the reservation's estimate booked; an insert that throws leaves no
82
+ * row. Either is logged.
83
+ */
84
+ export function recordBilledCall(manifest, reservationId, entry, billed, durationMs, label = entry.toolName) {
85
+ const settled = settledRowOf(entry, billed, durationMs);
78
86
  try {
79
- manifest.finalizeBudgetReservation(reservationId, settled);
87
+ if (reservationId === null) {
88
+ manifest.insertUsageMetric({
89
+ workspaceRoot: entry.workspaceRoot,
90
+ toolName: entry.toolName,
91
+ model: entry.model,
92
+ occurredAt: Date.now(),
93
+ ...settled,
94
+ });
95
+ }
96
+ else {
97
+ manifest.finalizeBudgetReservation(reservationId, settled);
98
+ }
80
99
  }
81
- catch (finalizeErr) {
82
- logger.error(`${entry.toolName}: finalizeBudgetReservation failed for id=${reservationId}; reservation row keeps the estimate (${settled.costUsdMicro} micros). Error: ${String(finalizeErr)}`);
100
+ catch (writeErr) {
101
+ logger.error(unwrittenBookingLine(label, reservationId, settled.costUsdMicro, writeErr));
83
102
  }
84
103
  }
85
104
  /**
@@ -94,22 +113,21 @@ export function settleFailedCall(manifest, failed) {
94
113
  return null;
95
114
  }
96
115
  const billed = billedUsage(failed.completed.usage(), failed.entry.model, failed.entry.serviceTier);
97
- try {
98
- recordBilledCall(manifest, failed.reservationId, failed.entry, billed, failed.durationMs);
99
- }
100
- catch (recordErr) {
101
- logger.error(`${failed.toolName}: the usage of ${failed.completed.count} completed request(s) could not be recorded. Error: ${String(recordErr)}`);
102
- }
116
+ recordBilledCall(manifest, failed.reservationId, failed.entry, billed, failed.durationMs);
103
117
  return usageFields(billed, failed.completed.continuationHops());
104
118
  }
105
- function releaseReservation(manifest, toolName, reservationId) {
119
+ /**
120
+ * Cancel a budget reservation (`null`: none was taken). A cancel that throws leaves the row at its estimate until the
121
+ * day ends; it is logged under `label`.
122
+ */
123
+ export function releaseReservation(manifest, label, reservationId) {
106
124
  if (reservationId === null)
107
125
  return;
108
126
  try {
109
127
  manifest.cancelBudgetReservation(reservationId);
110
128
  }
111
129
  catch (cancelErr) {
112
- logger.error(`${toolName}: cancelBudgetReservation failed for id=${reservationId}; reservation row keeps the estimate. Error: ${String(cancelErr)}`);
130
+ logger.error(`${label}: cancelBudgetReservation failed for id=${reservationId}; reservation row keeps the estimate. Error: ${safeForLog(cancelErr)}`);
113
131
  }
114
132
  }
115
133
  //# sourceMappingURL=call-ledger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"call-ledger.js","sourceRoot":"","sources":["../../../src/tools/shared/call-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC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CAAC,SAAS,CAAC,KAAK,EAAE,EACxB,MAAM,CAAC,KAAK,CAAC,KAAK,EAClB,MAAM,CAAC,KAAK,CAAC,WAAW,CACzB,CAAC;IACF,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC1F,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAoB,EACpB,KAAa,EACb,aAA4B;IAE5B,IAAI,aAAa,KAAK,IAAI;QAAE,OAAO;IACnC,IAAI,CAAC;QACH,QAAQ,CAAC,uBAAuB,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,KAAK,CACV,GAAG,KAAK,2CAA2C,aAAa,gDAAgD,UAAU,CAAC,SAAS,CAAC,EAAE,CACxI,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -49,7 +49,7 @@ export interface DecodeCall {
49
49
  readonly collector: StreamCollectorOptions & {
50
50
  readonly signal: AbortSignal;
51
51
  };
52
- /** Called each time a request's stream opened: from then on its work is billed. */
52
+ /** Called each time a request's stream opened: from then on the request is never re-sent. */
53
53
  readonly onRequestOpened: () => void;
54
54
  /** The call's record of its requests, kept across its decodes and its failures. */
55
55
  readonly completed: CompletedRequests;
@@ -1 +1 @@
1
- {"version":3,"file":"continuation.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/continuation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAEjB,MAAM,eAAe,CAAC;AAKvB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK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AC,MAAM,CAAqB;IAC5C,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,YAAY,CAAK;IAEzB,2EAA2E;IAC3E,WAAW,IAAI,IAAI,CAGlB;IAED,gGAAgG;IAChG,IAAI,IAAI,IAAI,CAEX;IAED,yGAAyG;IACzG,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAKlE;IAED,qEAAqE;IACrE,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,wDAAwD;IACxD,IAAI,uBAAuB,IAAI,MAAM,CAEpC;IAED;;;OAGG;IACH,gBAAgB,IAAI,MAAM,CAEzB;IAED,8GAA8G;IAC9G,KAAK,IAAI,WAAW,GAAG,SAAS,CAE/B;CACF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAmBpE;AAkHD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,sBAAsB,EAC5B,KAAK,GAAE,WAAgB,GACtB,OAAO,CAAC,eAAe,CAAC,CAgB1B"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The answer of an `ask` / `code` call, as both tools run it: the context (prepared once, and again by the stale-cache
3
+ * retry), the decode on it with the tool's request, the settlement that books it once, the warning of a truncated scan
4
+ * and the scan's result fields. Each result keeps its tool's own fields and their order.
5
+ */
6
+ import { type PreparedContext } from '../../cache/cache-manager.js';
7
+ import { type CachingModeChoice, type RanCaching } from '../../cache/caching-mode.js';
8
+ import type { ScanResult } from '../../indexer/workspace-scanner.js';
9
+ import type { ResolvedModel } from '../../types.js';
10
+ import type { ToolContext } from '../registry.js';
11
+ import { type ContextDecode, type ContextRequest } from './context-decode.js';
12
+ import type { EagerMachinery } from './eager-call.js';
13
+ import type { SizedCall } from './eager-steps.js';
14
+ import { type SettledAnswer } from './settle-call.js';
15
+ /** What the call's context is built from. */
16
+ export interface ContextSpec {
17
+ readonly scan: ScanResult;
18
+ readonly resolved: ResolvedModel;
19
+ /** The tool's system instruction: baked into a cache, or sent with each request without one. */
20
+ readonly systemInstruction: string;
21
+ /** `false` forces the files inline (no cache built): `ask`'s `noCache`, `code`'s `codeExecution`, no files. */
22
+ readonly allowCaching: boolean;
23
+ /** The caching mode asked for: per call, else the operator's. */
24
+ readonly requestedMode: 'explicit' | 'implicit';
25
+ }
26
+ /** The call's context and how to build it again. */
27
+ export interface CallContext {
28
+ /** The mode the call runs with, and why it differs from the one asked for. */
29
+ readonly caching: CachingModeChoice;
30
+ /** Builds the context again, with the same arguments: the stale-cache retry calls it on a fresh cache. */
31
+ readonly prepare: () => Promise<PreparedContext>;
32
+ readonly prepared: PreparedContext;
33
+ }
34
+ /**
35
+ * Prepare the call's context: the caching mode the model allows (a model without `createCachedContent` runs
36
+ * `explicit` as `implicit`, said on the progress channel), then the context itself under the call's signal, so a
37
+ * timeout also ends an upload.
38
+ */
39
+ export declare function prepareCallContext(call: EagerMachinery, ctx: ToolContext, spec: ContextSpec): Promise<CallContext>;
40
+ /**
41
+ * A tool's request on a prepared context, built for every request of the decode — the stale-cache retry's rebuilt
42
+ * context included. On a context with a cache the request carries `cachedContent` and never `systemInstruction`,
43
+ * `tools` or `toolConfig`: Gemini answers that combination with 400 ("CachedContent can not be used with
44
+ * GenerateContent request setting system_instruction, tools or tool_config"), and the system instruction is baked into
45
+ * the cache when it is built (`cache-manager.ts`, `cacheConfig.systemInstruction`). On a context without one the
46
+ * request carries the files inline and the tool's full config. `thinkingConfig` is a per-request control and travels
47
+ * either way.
48
+ */
49
+ export type RequestBuilder = (prep: PreparedContext) => ContextRequest;
50
+ /**
51
+ * Decode the answer on the call's context with the tool's request — with a cache, or inline on a context without one —
52
+ * and, on a stale cache before any request completed, once more on a rebuilt one (`decodeOnContext`). The TPM
53
+ * reservation is taken after the context and just before the first request, so its timestamp is when the tokens reach
54
+ * Gemini's quota counter; only the OPENING of a request is retried (a flex request never): a mid-stream failure re-sent
55
+ * would bill the work again.
56
+ */
57
+ export declare function decodeEagerCall(call: EagerMachinery, ctx: ToolContext, sized: SizedCall, request: RequestBuilder, context: CallContext): Promise<ContextDecode>;
58
+ /** The answer booked, the caching mode that ran, the call's duration. */
59
+ export interface SettledDecode {
60
+ readonly settled: SettledAnswer;
61
+ readonly ran: RanCaching;
62
+ readonly durationMs: number;
63
+ }
64
+ /**
65
+ * Book the answered call once, at every request that completed (over a long decode and a stale-cache retry alike).
66
+ * The trail's reservation and the decode's entry are cleared BEFORE the booking, so a failure after it neither books
67
+ * the call again nor releases what was booked — and reports no usage.
68
+ */
69
+ export declare function settleDecoded(call: EagerMachinery, ctx: ToolContext, decoded: ContextDecode, sized: SizedCall, caching: CachingModeChoice): SettledDecode;
70
+ /** Said in the log when the scan dropped the files past `GEMINI_CODE_CONTEXT_MAX_FILES`. */
71
+ export declare function warnTruncatedScan(call: EagerMachinery, ctx: ToolContext, scan: ScanResult): void;
72
+ /**
73
+ * What the scan left out and what the upload could not send, as both tools' answers report it: the excluded
74
+ * directories met, the files that are neither source by extension nor a `#!` script — so a caller can tell "not in
75
+ * the workspace" from "not indexed" — and the first five failed uploads.
76
+ */
77
+ export declare function scanFields(scan: ScanResult, prep: PreparedContext): Record<string, unknown>;
78
+ //# sourceMappingURL=eager-answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-answer.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/eager-answer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,8BAA8B,CAAC;AACpF,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAGhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE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AAK,EAAE,SAAS,EAChB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAiCxB;AAED,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAwBf;AAED,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAKhG;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAU3F"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The answer of an `ask` / `code` call, as both tools run it: the context (prepared once, and again by the stale-cache
3
+ * retry), the decode on it with the tool's request, the settlement that books it once, the warning of a truncated scan
4
+ * and the scan's result fields. Each result keeps its tool's own fields and their order.
5
+ */
6
+ import { createHash } from 'node:crypto';
7
+ import { prepareContext } from '../../cache/cache-manager.js';
8
+ import { cachingModeFor, cachingRan, } from '../../cache/caching-mode.js';
9
+ import { logger } from '../../utils/logger.js';
10
+ import { decodeOnContext } from './context-decode.js';
11
+ import { networkAttempts } from './service-tier.js';
12
+ import { settleAnswer } from './settle-call.js';
13
+ /**
14
+ * Prepare the call's context: the caching mode the model allows (a model without `createCachedContent` runs
15
+ * `explicit` as `implicit`, said on the progress channel), then the context itself under the call's signal, so a
16
+ * timeout also ends an upload.
17
+ */
18
+ export async function prepareCallContext(call, ctx, spec) {
19
+ const systemPromptHash = createHash('sha256')
20
+ .update(spec.systemInstruction)
21
+ .digest('hex')
22
+ .slice(0, 16);
23
+ const caching = cachingModeFor(spec.requestedMode, spec.resolved, call.emitter);
24
+ const prepare = () => prepareContext({
25
+ client: ctx.client,
26
+ manifest: ctx.manifest,
27
+ scan: spec.scan,
28
+ model: spec.resolved,
29
+ systemPromptHash,
30
+ systemInstruction: spec.systemInstruction,
31
+ ttlSeconds: ctx.config.cacheTtlSeconds,
32
+ cacheMinTokens: ctx.config.cacheMinTokens,
33
+ emitter: call.emitter,
34
+ allowCaching: spec.allowCaching,
35
+ signal: call.timeout.signal,
36
+ cachingMode: caching.mode,
37
+ });
38
+ return { caching, prepare, prepared: await prepare() };
39
+ }
40
+ /**
41
+ * Decode the answer on the call's context with the tool's request — with a cache, or inline on a context without one —
42
+ * and, on a stale cache before any request completed, once more on a rebuilt one (`decodeOnContext`). The TPM
43
+ * reservation is taken after the context and just before the first request, so its timestamp is when the tokens reach
44
+ * Gemini's quota counter; only the OPENING of a request is retried (a flex request never): a mid-stream failure re-sent
45
+ * would bill the work again.
46
+ */
47
+ export function decodeEagerCall(call, ctx, sized, request, context) {
48
+ const cap = sized.bounded.cap;
49
+ return decodeOnContext({
50
+ client: ctx.client,
51
+ booking: {
52
+ workspaceRoot: call.workspaceRoot,
53
+ toolName: call.tool,
54
+ model: sized.resolved.resolved,
55
+ serviceTier: sized.serviceTier,
56
+ },
57
+ cachingMode: (prep) => cachingRan(prep, context.caching).mode,
58
+ request,
59
+ cache: {
60
+ ttlWatcher: ctx.ttlWatcher,
61
+ manifest: ctx.manifest,
62
+ ttlSeconds: ctx.config.cacheTtlSeconds,
63
+ prepare: context.prepare,
64
+ },
65
+ openAttempts: networkAttempts(sized.serviceTier),
66
+ limits: { maxRequests: cap.maxRequests, cap: cap.effective },
67
+ timeout: call.timeout,
68
+ emit: (message) => call.emitter.emit(message),
69
+ completed: call.completed,
70
+ tracking: call.tracking,
71
+ throttle: call.dispatch,
72
+ inputTokens: {
73
+ estimated: sized.estimate.tokens,
74
+ counted: sized.count?.preflight.effectiveTokens,
75
+ },
76
+ }, context.prepared);
77
+ }
78
+ /**
79
+ * Book the answered call once, at every request that completed (over a long decode and a stale-cache retry alike).
80
+ * The trail's reservation and the decode's entry are cleared BEFORE the booking, so a failure after it neither books
81
+ * the call again nor releases what was booked — and reports no usage.
82
+ */
83
+ export function settleDecoded(call, ctx, decoded, sized, caching) {
84
+ // the mode that ran, not the one asked for: telemetry and the result record it
85
+ const ran = cachingRan(decoded.prep, caching);
86
+ const durationMs = Date.now() - call.started;
87
+ const settledReservation = call.trail.reservationId;
88
+ call.trail.reservationId = null;
89
+ call.tracking.ledgerEntry = null;
90
+ const settled = settleAnswer({
91
+ manifest: ctx.manifest,
92
+ reservationId: settledReservation,
93
+ entry: {
94
+ workspaceRoot: call.workspaceRoot,
95
+ toolName: call.tool,
96
+ model: sized.resolved.resolved,
97
+ serviceTier: sized.serviceTier,
98
+ cachingMode: ran.mode,
99
+ },
100
+ completed: call.completed,
101
+ response: decoded.response,
102
+ cap: sized.bounded.cap,
103
+ cut: sized.bounded.cut,
104
+ durationMs,
105
+ });
106
+ return { settled, ran, durationMs };
107
+ }
108
+ /** Said in the log when the scan dropped the files past `GEMINI_CODE_CONTEXT_MAX_FILES`. */
109
+ export function warnTruncatedScan(call, ctx, scan) {
110
+ if (!scan.truncated)
111
+ return;
112
+ logger.warn(`workspace ${call.workspaceRoot} contains more files than GEMINI_CODE_CONTEXT_MAX_FILES (${ctx.config.maxFilesPerWorkspace}); the tail was dropped before indexing.`);
113
+ }
114
+ /**
115
+ * What the scan left out and what the upload could not send, as both tools' answers report it: the excluded
116
+ * directories met, the files that are neither source by extension nor a `#!` script — so a caller can tell "not in
117
+ * the workspace" from "not indexed" — and the first five failed uploads.
118
+ */
119
+ export function scanFields(scan, prep) {
120
+ return {
121
+ excludedDirs: scan.excludedDirs,
122
+ excludedDirsTotal: scan.excludedDirsTotal,
123
+ filesSkippedNonSource: scan.skippedNonSource,
124
+ filesUploadFailed: prep.uploaded.failedCount,
125
+ ...(prep.uploaded.failedCount > 0
126
+ ? { uploadFailures: prep.uploaded.failures.slice(0, 5) }
127
+ : {}),
128
+ };
129
+ }
130
+ //# sourceMappingURL=eager-answer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-answer.js","sourceRoot":"","sources":["../../../src/tools/shared/eager-answer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAwB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAGL,cAAc,EACd,UAAU,GACX,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAA2C,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG/F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAsB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAuBpE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAoB,EACpB,GAAgB,EAChB,IAAiB;IAEjB,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;SAC9B,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,cAAc,CAAC;QACb,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,IAAI,C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Q;YAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,WAAW,EAAE,GAAG,CAAC,IAAI;SACtB;QACD,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG;QACtB,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG;QACtB,UAAU;KACX,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AACtC,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,IAAoB,EAAE,GAAgB,EAAE,IAAgB;IACxF,IAAI,CAAC,IAAI,CAAC,SAAS;QAAE,OAAO;IAC5B,MAAM,CAAC,IAAI,CACT,aAAa,IAAI,CAAC,aAAa,4DAA4D,GAAG,CAAC,MAAM,CAAC,oBAAoB,0CAA0C,CACrK,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAgB,EAAE,IAAqB;IAChE,OAAO;QACL,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;QACzC,qBAAqB,EAAE,IAAI,CAAC,gBAAgB;QAC5C,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;QAC5C,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC;YAC/B,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;YACxD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The machinery of one `ask` / `code` call and its failure path — the one place both tools open, settle on a failure
3
+ * and close a call.
4
+ *
5
+ * - Opened before the call's first await: the progress emitter, then the timeout controller (its total timer arms at
6
+ * once, its stall timer at the first chunk), then the per-request TPM throttle on the controller's signal.
7
+ * - One tracking object, one completed-request accumulator, one dispatch throttle and one failure trail live through
8
+ * the whole call: every step writes into them the moment it has a value, the failure path reads them.
9
+ * - A failure is settled first (the error line, a 429's retry hint, the ledger, the TPM reservation dropped), then
10
+ * classified (a timeout's progress line); each tool builds its result from the classification, in its own order.
11
+ */
12
+ import { type ProgressEmitter } from '../../utils/progress.js';
13
+ import type { TextToolResult, ToolContext } from '../registry.js';
14
+ import { type TimedOutCall, type TimedTool, type TimeoutController, type ToolTimeoutKnobs } from './abort-timeout.js';
15
+ import type { UsageFields } from './call-ledger.js';
16
+ import type { DecodeTracking } from './context-decode.js';
17
+ import { CompletedRequests } from './continuation.js';
18
+ import { DispatchThrottle } from './dispatch-throttle.js';
19
+ import { type ServiceTierName, type TierErrorMeta } from './service-tier.js';
20
+ /** What the failure path reports of the model: written once the model and its tier resolved. */
21
+ export interface ModelReached {
22
+ readonly resolvedModel: string;
23
+ readonly serviceTier: ServiceTierName;
24
+ }
25
+ /** The part of a call's failure trail the shared steps keep: the daily-budget reservation. */
26
+ export interface ReservationTrail {
27
+ /** The daily-budget reservation held: set as soon as `reserveBudget` returned its id; cleared before the answer is
28
+ * booked, and by the failure path. */
29
+ reservationId: number | null;
30
+ }
31
+ /** What a call's failure path reads besides the decode's tracking: each field written by its step the moment its
32
+ * value exists. */
33
+ export interface FailureTrail<M extends ModelReached> extends ReservationTrail {
34
+ /** Set by the tool's model step once the model and its tier resolved; `null` before: no retry hint is seeded, the
35
+ * requested tier is reported. */
36
+ model: M | null;
37
+ }
38
+ /** What opens a call. */
39
+ export interface EagerCallRequest {
40
+ readonly tool: TimedTool;
41
+ /** The per-call `timeoutMs` / `stallMs`; an unset one falls back to the tool's env var. */
42
+ readonly knobs: ToolTimeoutKnobs;
43
+ /** The tier asked for (per call, else the configured one): what a failure reports before the model resolved. */
44
+ readonly requestedTier: ServiceTierName;
45
+ readonly workspaceRoot: string;
46
+ readonly started: number;
47
+ }
48
+ /**
49
+ * The machinery of one `ask` / `code` call as the shared steps read and write it: everything but the trail's model,
50
+ * which only the tool's own model step writes — a shared step cannot replace a tool's model with a narrower one.
51
+ */
52
+ export interface EagerMachinery {
53
+ readonly tool: TimedTool;
54
+ readonly workspaceRoot: string;
55
+ readonly started: number;
56
+ readonly requestedTier: ServiceTierName;
57
+ readonly emitter: ProgressEmitter;
58
+ readonly timeout: TimeoutController;
59
+ readonly dispatch: DispatchThrottle;
60
+ /** Every request that completed is billed: the ledger settles from these, on an answer and on a failure alike. */
61
+ readonly completed: CompletedRequests;
62
+ /** The running decode's booking and whether a stream opened (a later failure is then billed work, not re-sent). */
63
+ readonly tracking: DecodeTracking;
64
+ readonly trail: ReservationTrail;
65
+ }
66
+ /** The machinery of one `ask` / `code` call, created before its first await, with the tool's model in its trail. */
67
+ export interface EagerCall<M extends ModelReached> extends EagerMachinery {
68
+ readonly trail: FailureTrail<M>;
69
+ }
70
+ /** A step's outcome: the next stage, or the result that ends the call (a refusal). */
71
+ export type StepOutcome<T> = {
72
+ readonly next: T;
73
+ } | {
74
+ readonly end: TextToolResult;
75
+ };
76
+ interface FailureCommon<M extends ModelReached> {
77
+ /** What the completed requests billed; `null` when no decode started, none of its requests completed, or the call
78
+ * failed after its answer was settled (the decode's entry was cleared then). */
79
+ readonly usage: UsageFields | null;
80
+ /** The trail's model at the failure; `null` before the model resolved. */
81
+ readonly model: M | null;
82
+ readonly requestedTier: ServiceTierName;
83
+ }
84
+ /** A call its controller aborted: the progress line `<tool>: aborted after …` is emitted. */
85
+ interface TimedOutEagerCall<M extends ModelReached> extends FailureCommon<M> {
86
+ readonly kind: 'timeout';
87
+ /** The limit that fired and its message. */
88
+ readonly timedOut: TimedOutCall;
89
+ /** Both knobs of the controller, whichever fired: the result reports both. */
90
+ readonly timeoutMs: number | null;
91
+ readonly stallMs: number | null;
92
+ }
93
+ /** A call that failed otherwise. */
94
+ interface ErroredEagerCall<M extends ModelReached> extends FailureCommon<M> {
95
+ readonly kind: 'error';
96
+ /** `<tool> failed: <message>`. */
97
+ readonly message: string;
98
+ readonly tierMeta: TierErrorMeta;
99
+ readonly httpStatus: number | undefined;
100
+ }
101
+ /** A failed call, settled and classified. */
102
+ export type FailedEagerCall<M extends ModelReached> = TimedOutEagerCall<M> | ErroredEagerCall<M>;
103
+ /** Open a call: synchronous, so the controller exists before the call's first await. */
104
+ export declare function openEagerCall<M extends ModelReached>(request: EagerCallRequest, ctx: ToolContext): EagerCall<M>;
105
+ /**
106
+ * Settle a failed call, then classify it. A 429's retry hint seeds the throttle once the model resolved; the ledger
107
+ * keeps what the completed requests billed and releases the rest of the reservation (all of it when none completed);
108
+ * the TPM reservation held is dropped. A timeout's progress line follows the settlement.
109
+ */
110
+ export declare function settleFailedEager<M extends ModelReached>(call: EagerCall<M>, ctx: ToolContext, err: unknown): FailedEagerCall<M>;
111
+ /** Close a call, on every path: the controller disposed, then the emitter stopped. */
112
+ export declare function closeEagerCall(call: EagerMachinery): void;
113
+ export {};
114
+ //# sourceMappingURL=eager-call.d.ts.map