@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-call.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/eager-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,yBAAyB,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAItB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAGnB,MAAM,mBAAmB,CAAC;AAG3B,gGAAgG;AAChG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;CACvC;AAED,8FAA8F;AAC9F,MAAM,WAAW,gBAAgB;IAC/B;0CACsC;IACtC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;mBACmB;AACnB,MAAM,WAAW,YAAY,CAAC,CAA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AC,CAAC,CAAC,EAClB,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,OAAO,GACX,eAAe,CAAC,CAAC,CAAC,CA0BpB;AAmBD,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAGzD"}
@@ -0,0 +1,95 @@
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 { logger, safeForLog } from '../../utils/logger.js';
13
+ import { createProgressEmitter } from '../../utils/progress.js';
14
+ import { isTimeoutAbort, timedOutCall, toolTimeoutController, } from './abort-timeout.js';
15
+ import { CompletedRequests } from './continuation.js';
16
+ import { DispatchThrottle } from './dispatch-throttle.js';
17
+ import { statusOf, tierErrorMeta, } from './service-tier.js';
18
+ import { settleFailure } from './settle-call.js';
19
+ /** Open a call: synchronous, so the controller exists before the call's first await. */
20
+ export function openEagerCall(request, ctx) {
21
+ const completed = new CompletedRequests();
22
+ const tracking = { ledgerEntry: null, streamOpened: false };
23
+ const emitter = createProgressEmitter(ctx.server, ctx.progressToken);
24
+ const timeout = toolTimeoutController(request.tool, request.knobs);
25
+ // Each request of the decode holds its own TPM reservation; a failure drops the one held.
26
+ const dispatch = new DispatchThrottle({
27
+ throttle: ctx.throttle,
28
+ enabled: ctx.config.tpmThrottleLimit > 0,
29
+ signal: timeout.signal,
30
+ emit: (message) => emitter.emit(message),
31
+ });
32
+ return {
33
+ tool: request.tool,
34
+ workspaceRoot: request.workspaceRoot,
35
+ started: request.started,
36
+ requestedTier: request.requestedTier,
37
+ emitter,
38
+ timeout,
39
+ dispatch,
40
+ completed,
41
+ tracking,
42
+ trail: { reservationId: null, model: null },
43
+ };
44
+ }
45
+ /**
46
+ * Settle a failed call, then classify it. A 429's retry hint seeds the throttle once the model resolved; the ledger
47
+ * keeps what the completed requests billed and releases the rest of the reservation (all of it when none completed);
48
+ * the TPM reservation held is dropped. A timeout's progress line follows the settlement.
49
+ */
50
+ export function settleFailedEager(call, ctx, err) {
51
+ logger.error(`${call.tool} failed: ${safeForLog(err)}`);
52
+ const usage = settleFailure({
53
+ manifest: ctx.manifest,
54
+ failed: {
55
+ toolName: call.tool,
56
+ reservationId: call.trail.reservationId,
57
+ entry: call.tracking.ledgerEntry,
58
+ completed: call.completed,
59
+ durationMs: Date.now() - call.started,
60
+ },
61
+ err,
62
+ model: call.trail.model?.resolvedModel ?? null,
63
+ throttle: ctx.throttle,
64
+ dispatch: call.dispatch,
65
+ });
66
+ call.trail.reservationId = null;
67
+ const common = { usage, model: call.trail.model, requestedTier: call.requestedTier };
68
+ if (isTimeoutAbort(err))
69
+ return timedOutFailure(call, err, common);
70
+ return {
71
+ kind: 'error',
72
+ ...common,
73
+ message: `${call.tool} failed: ${err instanceof Error ? err.message : String(err)}`,
74
+ tierMeta: tierErrorMeta(err, call.tracking.streamOpened),
75
+ httpStatus: statusOf(err),
76
+ };
77
+ }
78
+ /** The timeout of a call: the limit that fired, said on the progress channel, and both knobs of its controller. */
79
+ function timedOutFailure(call, err, common) {
80
+ const timedOut = timedOutCall(call.tool, err, call.timeout);
81
+ call.emitter.emit(`${call.tool}: aborted after ${timedOut.limitMs ?? '?'}ms ${timedOut.kind}`);
82
+ return {
83
+ kind: 'timeout',
84
+ ...common,
85
+ timedOut,
86
+ timeoutMs: call.timeout.timeoutMs,
87
+ stallMs: call.timeout.stallMs,
88
+ };
89
+ }
90
+ /** Close a call, on every path: the controller disposed, then the emitter stopped. */
91
+ export function closeEagerCall(call) {
92
+ call.timeout.dispose();
93
+ call.emitter.stop();
94
+ }
95
+ //# sourceMappingURL=eager-call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-call.js","sourceRoot":"","sources":["../../../src/tools/shared/eager-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAwB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEtF,OAAO,EAKL,cAAc,EACd,YAAY,EACZ,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAGL,QAAQ,EACR,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA4FjD,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAC3B,OAAyB,EACzB,GAAgB;IAEhB,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC1C,MAAM,QAAQ,GAAmB,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC5E,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,0FAA0F;IAC1F,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC;QACpC,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC;QACxC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,CAAC,OAAO,EAAE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,CAAC,aAAa,EAAE,CAAC;IACrF,IAAI,cAAc,CAAC,GAAG,CAAC;QAAE,OAAO,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACnE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,GAAG,MAAM;QACT,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,YAAY,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QACnF,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACxD,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED,mHAAmH;AACnH,SAAS,eAAe,CACtB,IAAkB,EAClB,GAAY,EACZ,MAAwB;IAExB,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,mBAAmB,QAAQ,CAAC,OAAO,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/F,OAAO;QACL,IAAI,EAAE,SAAS;QACf,GAAG,MAAM;QACT,QAAQ;QACR,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,IAAoB;IACjD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACvB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The steps of an `ask` / `code` call before its context that both tools run the same way. Each returns values or a
3
+ * refusal for its tool to report; every result keeps its tool's own fields and their order.
4
+ */
5
+ import { type BoundedOutputCap, type OutputCap, type PreflightMode } from '../../gemini/long-decode.js';
6
+ import { type PreflightTokenResult } from '../../gemini/token-counter.js';
7
+ import { type ScanResult } from '../../indexer/workspace-scanner.js';
8
+ import type { ResolvedModel } from '../../types.js';
9
+ import type { ToolContext } from '../registry.js';
10
+ import type { EagerMachinery } from './eager-call.js';
11
+ import type { ServiceTierName } from './service-tier.js';
12
+ /** The caller's narrowing of the workspace scan: the knobs of both tools' input, read from it as it is. */
13
+ export interface ScanFilters {
14
+ readonly includeGlobs?: readonly string[] | undefined;
15
+ readonly excludeGlobs?: readonly string[] | undefined;
16
+ readonly forceRescan?: boolean | undefined;
17
+ }
18
+ /**
19
+ * Scan the call's workspace. The scan memo, built from the stored file rows, lets the scanner skip re-hashing a file
20
+ * whose mtime and size are unchanged (a new workspace has none: every file hashes); `forceRescan` per call or by the
21
+ * operator bypasses it.
22
+ */
23
+ export declare function scanForCall(call: EagerMachinery, ctx: ToolContext, filters: ScanFilters): Promise<ScanResult>;
24
+ /**
25
+ * The output cap, in three layers (`resolveOutputCap`): the caller's `maxOutputTokens` (clamped to the model's
26
+ * per-request limit, or on a long-decode model to its long-decode total), else the operator's `forceMaxOutputTokens`
27
+ * (the per-request limit on every call), else none on the wire — one request at the model's own default. A caller's
28
+ * `thinkingBudget` is checked against this cap; the clamp and the reservation use the cap that runs (`capThatRuns`).
29
+ */
30
+ export declare function eagerOutputCap(requested: number | undefined, ctx: ToolContext, resolved: ResolvedModel): OutputCap;
31
+ /** The call's input as the budget and the TPM throttle estimate it, before any count. */
32
+ export interface InputEstimate {
33
+ readonly workspaceBytes: number;
34
+ /** bytes/4 of the workspace and the prompt, plus the extra tokens: what the TPM reservation holds. */
35
+ readonly tokens: number;
36
+ }
37
+ /** One estimate for both the budget reservation and the TPM reservation, so the two never drift apart. */
38
+ export declare function estimateInput(scan: ScanResult, prompt: string, extraTokens: number): InputEstimate;
39
+ /** What the preflight counts. */
40
+ export interface PreflightRequest {
41
+ readonly scan: ScanResult;
42
+ readonly prompt: string;
43
+ readonly resolved: ResolvedModel;
44
+ readonly mode: PreflightMode | undefined;
45
+ /** The cap asked for: a cap that may take more than one request takes the exact count (`preflightModeFor`). */
46
+ readonly cap: OutputCap;
47
+ /** Tokens beyond the files and the prompt, counted by Gemini (`ask`'s attachments; 0 for `code`). */
48
+ readonly extraTokens: number;
49
+ }
50
+ /** The preflight's count and the window it is held against. */
51
+ export interface PreflightCount {
52
+ /** The count, the extra tokens included: the window must hold them whichever way the count was made. */
53
+ readonly preflight: PreflightTokenResult;
54
+ readonly contextWindow: number;
55
+ /** `contextWindow × workspaceGuardRatio`: a count above it is too large for the eager path. */
56
+ readonly threshold: number;
57
+ }
58
+ /**
59
+ * Count the call's input against the model's advertised input limit (`countForPreflight`: the bytes/4 heuristic well
60
+ * under the limit, Gemini's `countTokens` near it, under the call's signal so a timeout ends the count). `null` when
61
+ * the model advertises no limit: the guard is skipped with a warning, and the request may fail downstream.
62
+ */
63
+ export declare function countPreflight(call: EagerMachinery, ctx: ToolContext, req: PreflightRequest): Promise<PreflightCount | null>;
64
+ /**
65
+ * The count's provenance as both tools' answers report it: which path produced the count (`heuristic`, `exact`,
66
+ * `fallback`), whether the cache saved an API round-trip, and the raw count before the system-instruction reserve was
67
+ * applied — so an orchestrator can see how the guard decided. Nothing when the model advertises no input limit (the
68
+ * count did not run).
69
+ */
70
+ export declare function preflightFields(count: PreflightCount | null): Record<string, unknown>;
71
+ /** A count over the window: the workspace is too large for the eager path. */
72
+ export interface OverWindow {
73
+ /** The count, the extra tokens included. */
74
+ readonly counted: PreflightTokenResult;
75
+ readonly contextWindow: number;
76
+ readonly threshold: number;
77
+ /** `workspaceGuardRatio` as a whole percent, as the refusal says it. */
78
+ readonly pctDisplay: number;
79
+ }
80
+ /**
81
+ * The guard's verdict on the count: the values a refusal reports when the count passed the threshold, else `null` —
82
+ * the count fits, or the model advertises no input limit (the guard did not run). Each tool composes its own refusal.
83
+ */
84
+ export declare function overWindow(count: PreflightCount | null, ctx: ToolContext): OverWindow | null;
85
+ /**
86
+ * What a call runs under once it is sized, built once per call: the budget reservation, the decode and the
87
+ * settlement read the same values.
88
+ */
89
+ export interface SizedCall {
90
+ readonly resolved: ResolvedModel;
91
+ readonly serviceTier: ServiceTierName;
92
+ readonly estimate: InputEstimate;
93
+ /** The preflight's count; `null` when the model advertises no input limit (the count did not run). */
94
+ readonly count: PreflightCount | null;
95
+ /** The cap that runs — after the input window's cut — and the cut. Its value bounds what a completed request bills;
96
+ * above the per-request limit (a long decode) every continuation request bills the input again. */
97
+ readonly bounded: BoundedOutputCap;
98
+ }
99
+ /** What the daily-budget reservation adds to the sized call. */
100
+ export interface ReservationRequest {
101
+ readonly promptChars: number;
102
+ /** Input tokens beyond the files and the prompt (`ask`'s attachments; 0 for `code`). */
103
+ readonly extraInputTokens: number;
104
+ readonly thinkingTokens: number;
105
+ }
106
+ /**
107
+ * Reserve the call's worst case against the daily budget: after the scan (the estimate needs it), before anything
108
+ * billable. `reserveBudget` checks and inserts in one `BEGIN IMMEDIATE` transaction, so concurrent calls cannot all
109
+ * pass the check and overshoot the cap together. The id goes into the call's trail at once: no statement comes
110
+ * between a reservation and its owner. Returns the refusal's message when the cap would be exceeded (nothing is
111
+ * reserved; the message is the same for both tools), or null when the call may go on (no daily cap, or reserved).
112
+ */
113
+ export declare function reserveCallBudget(call: EagerMachinery, ctx: ToolContext, sized: SizedCall, req: ReservationRequest): string | null;
114
+ //# sourceMappingURL=eager-steps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-steps.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/eager-steps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAGnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,oBAAoB,EAAqB,MAAM,+BAA+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,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,sGAAsG;IACtG,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC;uGACmG;IACnG,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;CACpC;AAED,gEAAgE;AAChE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wFAAwF;IACxF,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,kBAAkB,GACtB,MAAM,GAAG,IAAI,CA+Bf"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The steps of an `ask` / `code` call before its context that both tools run the same way. Each returns values or a
3
+ * refusal for its tool to report; every result keeps its tool's own fields and their order.
4
+ */
5
+ import { preflightModeFor, resolveOutputCap, } from '../../gemini/long-decode.js';
6
+ import { countForPreflight } from '../../gemini/token-counter.js';
7
+ import { buildScanMemo, scanWorkspace } from '../../indexer/workspace-scanner.js';
8
+ import { estimatePreCallCostUsd, toMicrosUsd } from '../../utils/cost-estimator.js';
9
+ import { logger, safeForLog } from '../../utils/logger.js';
10
+ /**
11
+ * Scan the call's workspace. The scan memo, built from the stored file rows, lets the scanner skip re-hashing a file
12
+ * whose mtime and size are unchanged (a new workspace has none: every file hashes); `forceRescan` per call or by the
13
+ * operator bypasses it.
14
+ */
15
+ export function scanForCall(call, ctx, filters) {
16
+ call.emitter.emit(`scanning workspace ${call.workspaceRoot}…`);
17
+ const scanMemo = buildScanMemo(ctx.manifest.getFiles(call.workspaceRoot));
18
+ return scanWorkspace(call.workspaceRoot, {
19
+ ...(filters.includeGlobs !== undefined ? { includeGlobs: filters.includeGlobs } : {}),
20
+ ...(filters.excludeGlobs !== undefined ? { excludeGlobs: filters.excludeGlobs } : {}),
21
+ maxFiles: ctx.config.maxFilesPerWorkspace,
22
+ maxFileSizeBytes: ctx.config.maxFileSizeBytes,
23
+ manifestMemo: scanMemo,
24
+ forceRescan: filters.forceRescan === true || ctx.config.forceRescan === true,
25
+ });
26
+ }
27
+ /** The output cap of a model that advertises no `outputTokenLimit`: the pro-tier ceiling, the model's full capacity. */
28
+ const EAGER_OUTPUT_FALLBACK_TOKENS = 65_536;
29
+ /**
30
+ * The output cap, in three layers (`resolveOutputCap`): the caller's `maxOutputTokens` (clamped to the model's
31
+ * per-request limit, or on a long-decode model to its long-decode total), else the operator's `forceMaxOutputTokens`
32
+ * (the per-request limit on every call), else none on the wire — one request at the model's own default. A caller's
33
+ * `thinkingBudget` is checked against this cap; the clamp and the reservation use the cap that runs (`capThatRuns`).
34
+ */
35
+ export function eagerOutputCap(requested, ctx, resolved) {
36
+ return resolveOutputCap({
37
+ requested,
38
+ forceMax: ctx.config.forceMaxOutputTokens,
39
+ outputTokenLimit: resolved.outputTokenLimit,
40
+ longDecodeTokenLimit: resolved.longDecodeTokenLimit,
41
+ fallbackLimit: EAGER_OUTPUT_FALLBACK_TOKENS,
42
+ });
43
+ }
44
+ /** One estimate for both the budget reservation and the TPM reservation, so the two never drift apart. */
45
+ export function estimateInput(scan, prompt, extraTokens) {
46
+ const workspaceBytes = scan.files.reduce((sum, f) => sum + f.size, 0);
47
+ return {
48
+ workspaceBytes,
49
+ tokens: Math.ceil(workspaceBytes / 4) + Math.ceil(prompt.length / 4) + extraTokens,
50
+ };
51
+ }
52
+ /**
53
+ * Count the call's input against the model's advertised input limit (`countForPreflight`: the bytes/4 heuristic well
54
+ * under the limit, Gemini's `countTokens` near it, under the call's signal so a timeout ends the count). `null` when
55
+ * the model advertises no limit: the guard is skipped with a warning, and the request may fail downstream.
56
+ */
57
+ export async function countPreflight(call, ctx, req) {
58
+ const contextWindow = req.resolved.inputTokenLimit;
59
+ const preflightMode = preflightModeFor(req.mode, req.cap);
60
+ if (typeof contextWindow !== 'number' || contextWindow <= 0) {
61
+ logger.warn(`${call.tool}: resolved model ${safeForLog(req.resolved.resolved)} has no advertised inputTokenLimit — workspace size guard skipped. Request may fail downstream if the workspace exceeds the model's context window.`);
62
+ return null;
63
+ }
64
+ const counted = await countForPreflight(ctx.client, {
65
+ files: req.scan.files,
66
+ prompt: req.prompt,
67
+ model: req.resolved.resolved,
68
+ // post-glob-filter: the hash already encodes the caller's include / exclude globs
69
+ filesHash: req.scan.filesHash,
70
+ ...(preflightMode !== undefined ? { preflightMode } : {}),
71
+ inputTokenLimit: contextWindow,
72
+ extraTokens: req.extraTokens, // weighs on the heuristic-vs-exact decision, added to the count below
73
+ signal: call.timeout.signal,
74
+ });
75
+ return {
76
+ preflight: { ...counted, effectiveTokens: counted.effectiveTokens + req.extraTokens },
77
+ contextWindow,
78
+ threshold: Math.floor(contextWindow * ctx.config.workspaceGuardRatio),
79
+ };
80
+ }
81
+ /**
82
+ * The count's provenance as both tools' answers report it: which path produced the count (`heuristic`, `exact`,
83
+ * `fallback`), whether the cache saved an API round-trip, and the raw count before the system-instruction reserve was
84
+ * applied — so an orchestrator can see how the guard decided. Nothing when the model advertises no input limit (the
85
+ * count did not run).
86
+ */
87
+ export function preflightFields(count) {
88
+ const preflight = count?.preflight;
89
+ if (preflight === undefined)
90
+ return {};
91
+ return {
92
+ tokenCountMethod: preflight.method,
93
+ rawTokenCount: preflight.rawTokens,
94
+ tokenCountCacheHit: preflight.cacheHit,
95
+ };
96
+ }
97
+ /**
98
+ * The guard's verdict on the count: the values a refusal reports when the count passed the threshold, else `null` —
99
+ * the count fits, or the model advertises no input limit (the guard did not run). Each tool composes its own refusal.
100
+ */
101
+ export function overWindow(count, ctx) {
102
+ if (count !== null && count.preflight.effectiveTokens > count.threshold) {
103
+ return {
104
+ counted: count.preflight,
105
+ contextWindow: count.contextWindow,
106
+ threshold: count.threshold,
107
+ pctDisplay: Math.round(ctx.config.workspaceGuardRatio * 100),
108
+ };
109
+ }
110
+ return null;
111
+ }
112
+ /**
113
+ * Reserve the call's worst case against the daily budget: after the scan (the estimate needs it), before anything
114
+ * billable. `reserveBudget` checks and inserts in one `BEGIN IMMEDIATE` transaction, so concurrent calls cannot all
115
+ * pass the check and overshoot the cap together. The id goes into the call's trail at once: no statement comes
116
+ * between a reservation and its owner. Returns the refusal's message when the cap would be exceeded (nothing is
117
+ * reserved; the message is the same for both tools), or null when the call may go on (no daily cap, or reserved).
118
+ */
119
+ export function reserveCallBudget(call, ctx, sized, req) {
120
+ const dailyBudgetUsd = ctx.config.dailyBudgetUsd;
121
+ if (!Number.isFinite(dailyBudgetUsd))
122
+ return null;
123
+ const cap = sized.bounded.cap;
124
+ const estimateUsd = estimatePreCallCostUsd({
125
+ model: sized.resolved.resolved,
126
+ serviceTier: sized.serviceTier,
127
+ extraInputTokens: req.extraInputTokens,
128
+ workspaceBytes: sized.estimate.workspaceBytes,
129
+ promptChars: req.promptChars,
130
+ expectedOutputTokens: cap.effective,
131
+ perRequestOutputTokens: cap.perRequest,
132
+ // the larger of the preflight's count and the bytes/4 heuristic is reserved
133
+ countedInputTokens: sized.count?.preflight.effectiveTokens,
134
+ thinkingTokens: req.thinkingTokens,
135
+ coverMs: call.timeout.timeoutMs,
136
+ });
137
+ const reserve = ctx.manifest.reserveBudget({
138
+ workspaceRoot: call.workspaceRoot,
139
+ toolName: call.tool,
140
+ model: sized.resolved.resolved,
141
+ estimatedCostMicros: toMicrosUsd(estimateUsd),
142
+ dailyBudgetMicros: toMicrosUsd(dailyBudgetUsd),
143
+ nowMs: Date.now(),
144
+ });
145
+ if ('rejected' in reserve) {
146
+ const spentUsd = reserve.spentMicros / 1_000_000;
147
+ return `Daily budget cap would be exceeded: spent $${spentUsd.toFixed(4)} + estimate $${estimateUsd.toFixed(4)} > cap $${dailyBudgetUsd.toFixed(2)}. Retry after UTC midnight, or raise \`GEMINI_DAILY_BUDGET_USD\`.`;
148
+ }
149
+ call.trail.reservationId = reserve.id;
150
+ return null;
151
+ }
152
+ //# sourceMappingURL=eager-steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eager-steps.js","sourceRoot":"","sources":["../../../src/tools/shared/eager-steps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAA6B,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAmB,aAAa,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnG,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAY3D;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,IAAoB,EACpB,GAAgB,EAChB,OAAoB;IAEpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC1E,OAAO,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE;QACvC,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,oBAAoB;QACzC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB;QAC7C,YAAY,EAAE,QAAQ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AAS;KAChC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;QAC9B,mBAAmB,EAAE,WAAW,CAAC,WAAW,CAAC;QAC7C,iBAAiB,EAAE,WAAW,CAAC,cAAc,CAAC;QAC9C,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE;KAClB,CAAC,CAAC;IACH,IAAI,UAAU,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;QACjD,OAAO,8CAA8C,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,mEAAmE,CAAC;IACxN,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The input fields `ask` and `ask_agentic` share — the question and the workspace it is about: one schema, one text
3
+ * (`ask` hands its input to `ask_agentic` when a workspace is too large for it).
4
+ */
5
+ import { z } from 'zod';
6
+ /** The question, as both tools take it. */
7
+ export declare const PROMPT_FIELD: z.ZodString;
8
+ /** The workspace the question is about, as both tools take it. */
9
+ export declare const WORKSPACE_FIELD: z.ZodOptional<z.ZodString>;
10
+ //# sourceMappingURL=question-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-fields.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/question-fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2CAA2C;AAC3C,eAAO,MAAM,YAAY,aAAkE,CAAC;AAE5F,kEAAkE;AAClE,eAAO,MAAM,eAAe,4BAG6D,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The input fields `ask` and `ask_agentic` share — the question and the workspace it is about: one schema, one text
3
+ * (`ask` hands its input to `ask_agentic` when a workspace is too large for it).
4
+ */
5
+ import { z } from 'zod';
6
+ /** The question, as both tools take it. */
7
+ export const PROMPT_FIELD = z.string().min(1).describe('The question or analysis request.');
8
+ /** The workspace the question is about, as both tools take it. */
9
+ export const WORKSPACE_FIELD = z
10
+ .string()
11
+ .optional()
12
+ .describe('Absolute or cwd-relative path to the workspace. Defaults to process.cwd().');
13
+ //# sourceMappingURL=question-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-fields.js","sourceRoot":"","sources":["../../../src/tools/shared/question-fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2CAA2C;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mCAAmC,CAAC,CAAC;AAE5F,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,QAAQ,EAAE;KACV,QAAQ,CAAC,4EAA4E,CAAC,CAAC"}
@@ -15,6 +15,15 @@ export declare class ServiceTierError extends Error {
15
15
  }
16
16
  /** The tier of a call: the per-call value wins; on Vertex a per-call `flex` is refused, a default `flex` is standard. */
17
17
  export declare function resolveServiceTier(perCall: ServiceTierName | undefined, operatorDefault: ServiceTierName, vertex?: boolean): ServiceTierName;
18
+ /**
19
+ * The tier of an `ask` / `code` call from the per-call value and the operator's configuration, or its refusal as a
20
+ * value: each tool reports a `ServiceTierError` with its own fields. Any other error is thrown, to the call's failure
21
+ * path.
22
+ */
23
+ export declare function serviceTierOrRefusal(perCall: ServiceTierName | undefined, config: {
24
+ readonly serviceTier: ServiceTierName;
25
+ readonly vertex: boolean;
26
+ }): ServiceTierName | ServiceTierError;
18
27
  /** What goes into `GenerateContentConfig`: nothing on standard, the enum on flex. */
19
28
  export declare function serviceTierConfig(tier: ServiceTierName): Pick<GenerateContentConfig, 'serviceTier'>;
20
29
  /** On flex every send is billed and a queued stream may outlive Node's 300 s header wait: the server never re-sends
@@ -1 +1 @@
1
- {"version":3,"file":"service-tier.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/service-tier.ts"],"names":[],"mappings":"AAAA;;;;;;sGAMsG;AACtG,OAAO,EAAE,KAAK,qBAAqB,EAAe,MAAM,eAAe,CAAC;AAIxE,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,MAAM,CAAC;AAElD,wDAAwD;AACxD,eAAO,MAAM,wBAAwB,inBACskB,CAAC;AAE5mB,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,8BAA8B;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,yHAAyH;AACzH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,eAAe,EAAE,eAAe,EAChC,MAAM,UAAQ,GACb,eAAe,CASjB;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,eAAe,GACpB,IAAI,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAE5C;AAED;yFACyF;AACzF,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAE7D;AAED,oDAAoD;AACpD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGzD;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,SAAS,CAAC;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,sDAA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EAAE,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,SAAS,CAAC;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,sDAAsD;IACtD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;gHACgH;AAChH;kCACkC;AAClC,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,UAAQ,GAAG,aAAa,CAgBhF"}
@@ -27,6 +27,21 @@ export function resolveServiceTier(perCall, operatorDefault, vertex = false) {
27
27
  }
28
28
  return 'standard';
29
29
  }
30
+ /**
31
+ * The tier of an `ask` / `code` call from the per-call value and the operator's configuration, or its refusal as a
32
+ * value: each tool reports a `ServiceTierError` with its own fields. Any other error is thrown, to the call's failure
33
+ * path.
34
+ */
35
+ export function serviceTierOrRefusal(perCall, config) {
36
+ try {
37
+ return resolveServiceTier(perCall, config.serviceTier, config.vertex);
38
+ }
39
+ catch (err) {
40
+ if (err instanceof ServiceTierError)
41
+ return err;
42
+ throw err;
43
+ }
44
+ }
30
45
  /** What goes into `GenerateContentConfig`: nothing on standard, the enum on flex. */
31
46
  export function serviceTierConfig(tier) {
32
47
  return tier === 'flex' ? { serviceTier: ServiceTier.FLEX } : {};
@@ -1 +1 @@
1
- {"version":3,"file":"service-tier.js","sourceRoot":"","sources":["../../../src/tools/shared/service-tier.ts"],"names":[],"mappings":"AAAA;;;;;;sGAMsG;AACtG,OAAO,EAA8B,WAAW,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAI/D,wDAAwD;AACxD,MAAM,CAAC,MAAM,wBAAwB,GACnC,ymBAAymB,CAAC;AAE5mB,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,GAAG,0BAA0B,CAAC;IAC3C,YAAY,OAAe;QACzB,KAAK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AC7B,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,uCAAuC;QAC9G,OAAO;YACL,SAAS,EAAE,YAAY;YACvB,SAAS,EAAE,IAAI;YACf,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACxE,gHAAgH;IAChH,kDAAkD;IAClD,IAAI,uBAAuB,CAAC,GAAG,CAAC;QAC9B,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,aAAa,EAAE,CAAC;IACnE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAClC,CAAC"}
@@ -2,8 +2,9 @@
2
2
  * How an `ask` / `code` call settles — the one place both tools do it, so they book the same way and return the same
3
3
  * fields.
4
4
  *
5
- * - An answer: the ledger books every completed request at what it billed; a stop at the output cap with no text is
6
- * an `OUTPUT_CAP` error with the usage, the model, the tier and the finish reason.
5
+ * - An answer: the ledger books every completed request at what it billed (best-effort: a failed write is logged, the
6
+ * answer is returned); a stop at the output cap with no text is an `OUTPUT_CAP` error with the usage, the model,
7
+ * the tier and the finish reason.
7
8
  * - A failure: a 429's retry hint seeds the per-minute throttle, the ledger keeps what the completed requests billed
8
9
  * and releases the rest (all of it when none completed), and the request's per-minute reservation is dropped.
9
10
  */
@@ -42,7 +43,11 @@ export interface SettledAnswer {
42
43
  /** Set when the call stopped at the cap before writing an answer: the caller returns it as an error. */
43
44
  readonly outputCapStop: OutputCapStop | null;
44
45
  }
45
- /** Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. */
46
+ /**
47
+ * Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. The booking
48
+ * is best-effort (`recordBilledCall` logs a failed write and never throws): the paid answer is returned whatever the
49
+ * ledger does.
50
+ */
46
51
  export declare function settleAnswer(call: AnsweredCall): SettledAnswer;
47
52
  /** A call that failed, with what its failure path settles. */
48
53
  export interface FailedCallSettlement {
@@ -55,9 +60,9 @@ export interface FailedCallSettlement {
55
60
  readonly dispatch: DispatchThrottle;
56
61
  }
57
62
  /**
58
- * Settle a failed call; its usage when completed requests were billed, else `null`. The retry hint is read only from
59
- * a real `ApiError` with status 429 (`isGemini429`): text a prompt can echo never reaches the throttle. A ledger write
60
- * that throws is logged by `settleFailedCall` and never replaces the call's own error.
63
+ * Settle a failed call; its usage when completed requests were billed, else `null`. A 429's retry hint seeds the
64
+ * throttle through `seedRetryHint`, once per error. A ledger write that throws is logged by `recordBilledCall` /
65
+ * `settleFailedCall` and never replaces the call's own error.
61
66
  */
62
67
  export declare function settleFailure(settlement: FailedCallSettlement): UsageFields | null;
63
68
  //# sourceMappingURL=settle-call.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settle-call.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/settle-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAKjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,UAAU,EAIhB,MAAM,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`code` call settles — the one place both tools do it, so they book the same way and return the same
3
3
  * fields.
4
4
  *
5
- * - An answer: the ledger books every completed request at what it billed; a stop at the output cap with no text is
6
- * an `OUTPUT_CAP` error with the usage, the model, the tier and the finish reason.
5
+ * - An answer: the ledger books every completed request at what it billed (best-effort: a failed write is logged, the
6
+ * answer is returned); a stop at the output cap with no text is an `OUTPUT_CAP` error with the usage, the model,
7
+ * the tier and the finish reason.
7
8
  * - A failure: a 429's retry hint seeds the per-minute throttle, the ledger keeps what the completed requests billed
8
9
  * and releases the rest (all of it when none completed), and the request's per-minute reservation is dropped.
9
10
  */
10
11
  import { billedUsage, recordBilledCall, settleFailedCall, usageFields, } from './call-ledger.js';
11
12
  import { OUTPUT_CAP_ERROR_CODE, answerFinish, emptyAtOutputCap, } from './thinking.js';
12
- import { isGemini429, parseRetryDelayMs } from './throttle.js';
13
- /** Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. */
13
+ import { seedRetryHint } from './throttle.js';
14
+ /**
15
+ * Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. The booking
16
+ * is best-effort (`recordBilledCall` logs a failed write and never throws): the paid answer is returned whatever the
17
+ * ledger does.
18
+ */
14
19
  export function settleAnswer(call) {
15
20
  const billed = billedUsage(call.completed.usage(), call.entry.model, call.entry.serviceTier);
16
21
  recordBilledCall(call.manifest, call.reservationId, call.entry, billed, call.durationMs);
@@ -38,15 +43,14 @@ function inputWindowCutFields(cut) {
38
43
  return cut === null ? {} : { outputCapCutByInputWindow: cut };
39
44
  }
40
45
  /**
41
- * Settle a failed call; its usage when completed requests were billed, else `null`. The retry hint is read only from
42
- * a real `ApiError` with status 429 (`isGemini429`): text a prompt can echo never reaches the throttle. A ledger write
43
- * that throws is logged by `settleFailedCall` and never replaces the call's own error.
46
+ * Settle a failed call; its usage when completed requests were billed, else `null`. A 429's retry hint seeds the
47
+ * throttle through `seedRetryHint`, once per error. A ledger write that throws is logged by `recordBilledCall` /
48
+ * `settleFailedCall` and never replaces the call's own error.
44
49
  */
45
50
  export function settleFailure(settlement) {
46
51
  const { err, model } = settlement;
47
- const retryDelayMs = isGemini429(err) ? parseRetryDelayMs(err.message) : null;
48
- if (retryDelayMs !== null && model !== null) {
49
- settlement.throttle.recordRetryHint(model, retryDelayMs);
52
+ if (model !== null) {
53
+ seedRetryHint(settlement.throttle, model, err);
50
54
  }
51
55
  const usage = settleFailedCall(settlement.manifest, settlement.failed);
52
56
  settlement.dispatch.cancel();
@@ -1 +1 @@
1
- {"version":3,"file":"settle-call.js","sourceRoot":"","sources":["../../../src/tools/shared/settle-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAIL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAGL,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAoB,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAiCjF,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAAC,IAAkB;IAC7C,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC7F,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzF,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,OAAO,G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