@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":"instruction.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/instruction.ts"],"names":[],"mappings":"AAAA,yGAAyG;AAIzG;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAI3B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /** `ask`'s system instruction: read by the inline-size refusal of the attachments and by the request. */
2
+ import { SYSTEM_INSTRUCTION_SAFETY_EAGER } from '../shared/system-instruction-safety.js';
3
+ /**
4
+ * `ask`'s system instruction: the shared `SYSTEM_INSTRUCTION_SAFETY_EAGER` first — the data-vs-instruction firewall
5
+ * that keeps the workspace files' content from steering the model — then `ask`'s role statement. Cross-tool security
6
+ * rules live in the shared block; what is particular to answering questions lives in the role statement.
7
+ */
8
+ export const SYSTEM_INSTRUCTION_Q_AND_A = [
9
+ SYSTEM_INSTRUCTION_SAFETY_EAGER,
10
+ '',
11
+ 'You are a senior software engineer analysing a codebase. Be precise, reference specific file paths and line numbers, and cite evidence from the provided files rather than guessing. If the answer is not derivable from the context, say so.',
12
+ ].join('\n');
13
+ //# sourceMappingURL=instruction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../../src/tools/ask/instruction.ts"],"names":[],"mappings":"AAAA,yGAAyG;AAEzG,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,+BAA+B;IAC/B,EAAE;IACF,+OAA+O;CAChP,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `ask`'s request on a prepared context: with a cached context, or with the files inline on a context without one.
3
+ * The decode calls it for every request, the stale-cache retry on the rebuilt context too.
4
+ */
5
+ import type { RequestBuilder } from '../shared/eager-answer.js';
6
+ import type { AskSized } from './call.js';
7
+ /**
8
+ * The request builder of one call; what a cached context forbids is `RequestBuilder`'s rule
9
+ * (`../shared/eager-answer.ts`). `maxOutputTokens` goes on the wire only when the cap has a wire value (the caller's
10
+ * `maxOutputTokens`, the operator's force-max, or a cap the input window cut); otherwise Gemini applies the model's own
11
+ * default. The user turn carries the attachments first and the question last, with a cache too.
12
+ */
13
+ export declare function askRequest(call: AskSized): RequestBuilder;
14
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1C;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAsBzD"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `ask`'s request on a prepared context: with a cached context, or with the files inline on a context without one.
3
+ * The decode calls it for every request, the stale-cache retry on the rebuilt context too.
4
+ */
5
+ import { serviceTierConfig } from '../shared/service-tier.js';
6
+ import { SYSTEM_INSTRUCTION_Q_AND_A } from './instruction.js';
7
+ import { thinkingConfigOf } from './thinking.js';
8
+ /**
9
+ * The request builder of one call; what a cached context forbids is `RequestBuilder`'s rule
10
+ * (`../shared/eager-answer.ts`). `maxOutputTokens` goes on the wire only when the cap has a wire value (the caller's
11
+ * `maxOutputTokens`, the operator's force-max, or a cap the input window cut); otherwise Gemini applies the model's own
12
+ * default. The user turn carries the attachments first and the question last, with a cache too.
13
+ */
14
+ export function askRequest(call) {
15
+ const { input, attachments } = call;
16
+ const cap = call.bounded.cap;
17
+ const thinkingConfig = thinkingConfigOf(call.thinking);
18
+ const tierField = serviceTierConfig(call.serviceTier);
19
+ const config = (cacheId) => {
20
+ const maxOutputField = cap.wire !== undefined ? { maxOutputTokens: cap.wire } : {};
21
+ return cacheId
22
+ ? { cachedContent: cacheId, thinkingConfig, ...maxOutputField, ...tierField }
23
+ : {
24
+ systemInstruction: SYSTEM_INSTRUCTION_Q_AND_A,
25
+ thinkingConfig,
26
+ ...maxOutputField,
27
+ ...tierField,
28
+ };
29
+ };
30
+ const userTurn = { role: 'user', parts: [...attachments.parts, { text: input.prompt }] };
31
+ const contents = (prep) => {
32
+ if (prep.cacheId)
33
+ return attachments.parts.length === 0 ? input.prompt : [userTurn];
34
+ return [...prep.inlineContents, userTurn];
35
+ };
36
+ return (prep) => ({ contents: contents(prep), config: config(prep.cacheId) });
37
+ }
38
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/tools/ask/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAc;IACvC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;IAC7B,MAAM,cAAc,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,CAAC,OAAsB,EAAyB,EAAE;QAC/D,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,OAAO,OAAO;YACZ,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,GAAG,SAAS,EAAE;YAC7E,CAAC,CAAC;gBACE,iBAAiB,EAAE,0BAA0B;gBAC7C,cAAc;gBACd,GAAG,cAAc;gBACjB,GAAG,SAAS;aACb,CAAC;IACR,CAAC,CAAC;IACF,MAAM,QAAQ,GAAY,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;IAClG,MAAM,QAAQ,GAAG,CAAC,IAAqB,EAAsB,EAAE;QAC7D,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACpF,OAAO,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC5C,CAAC,CAAC;IACF,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The results an `ask` call returns from its budget reservation on: the refusal over the daily budget, the stop at the
3
+ * output cap, the answer, and the result of a failed call. Each keeps `ask`'s own fields and their order.
4
+ */
5
+ import { type TextToolResult } from '../registry.js';
6
+ import type { ContextDecode } from '../shared/context-decode.js';
7
+ import { type SettledDecode } from '../shared/eager-answer.js';
8
+ import type { FailedEagerCall, ModelReached } from '../shared/eager-call.js';
9
+ import type { OutputCapStop } from '../shared/settle-call.js';
10
+ import type { AskSized } from './call.js';
11
+ /** The daily budget would be exceeded: nothing was reserved. */
12
+ export declare function budgetRejectResult(call: AskSized, message: string): TextToolResult;
13
+ /** Settled and billed: an empty answer at the output cap is a failure the caller can act on, never a success. */
14
+ export declare function outputCapResult(stop: OutputCapStop): TextToolResult;
15
+ /** The answer, its text and what the call ran on, billed and decoded. */
16
+ export declare function answerResult(call: AskSized, decoded: ContextDecode, settledDecode: SettledDecode): TextToolResult;
17
+ /**
18
+ * `ask`'s result of a failed call: the resolved tier, else the one requested. A timeout has its own `errorCode` so a
19
+ * caller can tell "Gemini was slow" from a refusal, and `timeoutKind` (`total` / `stall`) tells the wall-clock cap
20
+ * from the heartbeat-aware stall watchdog (a caller may retry on a stall and not on the total).
21
+ */
22
+ export declare function failedResult(failure: FailedEagerCall<ModelReached>): TextToolResult;
23
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/results.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG1C,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAMlF;AAED,iHAAiH;AACjH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,CAEnE;AAED,yEAAyE;AACzE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,aAAa,GAC3B,cAAc,CAahB;AAqDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,YAAY,CAAC,GAAG,cAAc,CAmBnF"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The results an `ask` call returns from its budget reservation on: the refusal over the daily budget, the stop at the
3
+ * output cap, the answer, and the result of a failed call. Each keeps `ask`'s own fields and their order.
4
+ */
5
+ import { errorResult, textResult } from '../registry.js';
6
+ import { scanFields } from '../shared/eager-answer.js';
7
+ import { preflightFields } from '../shared/eager-steps.js';
8
+ import { attachmentMetadata } from './attachments.js';
9
+ import { thinkingBudgetField } from './thinking.js';
10
+ /** The daily budget would be exceeded: nothing was reserved. */
11
+ export function budgetRejectResult(call, message) {
12
+ return errorResult(message, {
13
+ errorCode: 'BUDGET_REJECT',
14
+ retryable: false,
15
+ serviceTier: call.serviceTier,
16
+ });
17
+ }
18
+ /** Settled and billed: an empty answer at the output cap is a failure the caller can act on, never a success. */
19
+ export function outputCapResult(stop) {
20
+ return errorResult(`ask: ${stop.message}`, stop.fields);
21
+ }
22
+ /** The answer, its text and what the call ran on, billed and decoded. */
23
+ export function answerResult(call, decoded, settledDecode) {
24
+ const { response } = decoded;
25
+ // `collectStream` aggregated the thought-flagged parts and capped the joined summary at 1200 chars: reused as it
26
+ // is, so the summary never drifts from the thoughts emitted live.
27
+ const thinkingSummary = response.thoughtsSummary;
28
+ return textResult(response.text, {
29
+ ...modelFields(call),
30
+ ...decodeFields(decoded, settledDecode),
31
+ ...workspaceFields(call, decoded.prep),
32
+ ...preflightFields(call.count),
33
+ durationMs: settledDecode.durationMs,
34
+ ...(thinkingSummary ? { thinkingSummary } : {}),
35
+ });
36
+ }
37
+ /** The model, the tier, the attachments and the thinking the call ran with. */
38
+ function modelFields(call) {
39
+ const { resolved } = call;
40
+ return {
41
+ resolvedModel: resolved.resolved,
42
+ requestedModel: resolved.requested,
43
+ serviceTier: call.serviceTier,
44
+ ...attachmentMetadata(call.attachments),
45
+ fallbackApplied: resolved.fallbackApplied,
46
+ modelCategory: resolved.category,
47
+ modelCostTier: resolved.capabilities.costTier,
48
+ contextWindow: resolved.inputTokenLimit,
49
+ thinkingBudget: thinkingBudgetField(call.thinking),
50
+ thinkingLevel: call.input.thinkingLevel ?? null,
51
+ };
52
+ }
53
+ /** What the decode billed, how it ended and the context it ran on. */
54
+ function decodeFields(decoded, settledDecode) {
55
+ const { prep: activePrep, retriedOnStaleCache } = decoded;
56
+ const { settled, ran } = settledDecode;
57
+ return {
58
+ ...settled.usage,
59
+ ...settled.cutFields,
60
+ // `truncated`: the answer stopped at the output cap (MAX_TOKENS, or a long decode at its limits) — it is cut
61
+ finishReason: settled.finish.finishReason,
62
+ truncated: settled.finish.truncated,
63
+ cacheHit: activePrep.reused,
64
+ cacheRebuilt: activePrep.rebuilt || retriedOnStaleCache,
65
+ retriedOnStaleCache,
66
+ inlineOnly: activePrep.inlineOnly,
67
+ cachingMode: ran.mode,
68
+ ...(ran.note !== null ? { cachingModeNote: ran.note } : {}),
69
+ };
70
+ }
71
+ /** What the scan indexed, skipped and dropped, and what the upload could not send. */
72
+ function workspaceFields(call, prep) {
73
+ const { scan } = call;
74
+ return {
75
+ filesIndexed: scan.files.length,
76
+ filesSkippedTooLarge: scan.skippedTooLarge,
77
+ ...scanFields(scan, prep),
78
+ workspaceTruncated: scan.truncated,
79
+ maxFilesCap: call.ctx.config.maxFilesPerWorkspace,
80
+ };
81
+ }
82
+ /**
83
+ * `ask`'s result of a failed call: the resolved tier, else the one requested. A timeout has its own `errorCode` so a
84
+ * caller can tell "Gemini was slow" from a refusal, and `timeoutKind` (`total` / `stall`) tells the wall-clock cap
85
+ * from the heartbeat-aware stall watchdog (a caller may retry on a stall and not on the total).
86
+ */
87
+ export function failedResult(failure) {
88
+ const serviceTier = failure.model?.serviceTier ?? failure.requestedTier;
89
+ if (failure.kind === 'timeout') {
90
+ return errorResult(failure.timedOut.message, {
91
+ errorCode: 'TIMEOUT',
92
+ timeoutKind: failure.timedOut.kind,
93
+ timeoutMs: failure.timeoutMs,
94
+ stallMs: failure.stallMs,
95
+ retryable: true,
96
+ serviceTier,
97
+ ...failure.usage,
98
+ });
99
+ }
100
+ return errorResult(failure.message, {
101
+ ...failure.tierMeta,
102
+ serviceTier,
103
+ ...(failure.httpStatus !== undefined ? { httpStatus: failure.httpStatus } : {}),
104
+ ...failure.usage,
105
+ });
106
+ }
107
+ //# sourceMappingURL=results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/tools/ask/results.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAuB,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAAsB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,gEAAgE;AAChE,MAAM,UAAU,kBAAkB,CAAC,IAAc,EAAE,OAAe;IAChE,OAAO,WAAW,CAAC,OAAO,EAAE;QAC1B,SAAS,EAAE,eAAe;QAC1B,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,IAAI,CAAC,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,eAAe,CAAC,IAAmB;IACjD,OAAO,WAAW,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAA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SAAS,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;YAC3C,SAAS,EAAE,SAAS;YACpB,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;YAClC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE,IAAI;YACf,WAAW;YACX,GAAG,OAAO,CAAC,KAAK;SACjB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE;QAClC,GAAG,OAAO,CAAC,QAAQ;QACnB,WAAW;QACX,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,GAAG,OAAO,CAAC,KAAK;KACjB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The steps of an `ask` call before its count: the model and its tier, then the scan and the refusals over it. Nothing
3
+ * is counted by the preflight or reserved yet.
4
+ */
5
+ import type { StepOutcome } from '../shared/eager-call.js';
6
+ import type { AskAttached, AskCall, AskResolved, AskScanned } from './call.js';
7
+ /**
8
+ * Resolve the model asked for and the call's tier. `ask` accepts all three text-generation tiers — the caller picks
9
+ * through an alias (`latest-pro` / `latest-flash` / `latest-lite` / `latest-vision`) or a literal model id; the
10
+ * resolver refuses a category outside them, so an image, audio or agent model never reaches `generateContent`. A tier
11
+ * the backend refuses ends the call (`SERVICE_TIER_UNSUPPORTED`). The model goes into the call's trail at once: from
12
+ * here a failure seeds a 429's retry hint and reports the resolved tier.
13
+ */
14
+ export declare function resolveAsk(call: AskCall): Promise<StepOutcome<AskResolved>>;
15
+ /**
16
+ * Scan the workspace, then the refusals that need the scan and cost nothing: a positive `thinkingBudget` that leaves
17
+ * no answer reserve under the caller's own cap (`thinkingBudgetRefusal`; the budget on the wire is clamped under the
18
+ * cap that runs later), and an inline request over Google's size limit (only with attachments). The input estimate is
19
+ * the one the budget and the TPM reservations both hold.
20
+ */
21
+ export declare function scanAsk(call: AskAttached): Promise<StepOutcome<AskScanned>>;
22
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/setup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAmBjF;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAmBjF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The steps of an `ask` call before its count: the model and its tier, then the scan and the refusals over it. Nothing
3
+ * is counted by the preflight or reserved yet.
4
+ */
5
+ import { thinkingBudgetRefusal } from '../../gemini/long-decode.js';
6
+ import { resolveModel } from '../../gemini/models.js';
7
+ import { errorResult } from '../registry.js';
8
+ import { eagerOutputCap, estimateInput, scanForCall } from '../shared/eager-steps.js';
9
+ import { ServiceTierError, serviceTierOrRefusal } from '../shared/service-tier.js';
10
+ import { inlineRequestRefusal } from './attachments.js';
11
+ /**
12
+ * Resolve the model asked for and the call's tier. `ask` accepts all three text-generation tiers — the caller picks
13
+ * through an alias (`latest-pro` / `latest-flash` / `latest-lite` / `latest-vision`) or a literal model id; the
14
+ * resolver refuses a category outside them, so an image, audio or agent model never reaches `generateContent`. A tier
15
+ * the backend refuses ends the call (`SERVICE_TIER_UNSUPPORTED`). The model goes into the call's trail at once: from
16
+ * here a failure seeds a 429's retry hint and reports the resolved tier.
17
+ */
18
+ export async function resolveAsk(call) {
19
+ const { input, ctx, eager } = call;
20
+ eager.emitter.emit(`resolving model '${call.model}'…`);
21
+ const resolved = await resolveModel(call.model, ctx.client, {
22
+ requiredCategory: ['text-reasoning', 'text-fast', 'text-lite'],
23
+ });
24
+ const serviceTier = serviceTierOrRefusal(input.serviceTier, ctx.config);
25
+ if (serviceTier instanceof ServiceTierError) {
26
+ return {
27
+ end: errorResult(`ask: ${serviceTier.message}`, {
28
+ errorCode: serviceTier.code,
29
+ retryable: false,
30
+ serviceTier: 'flex',
31
+ resolvedModel: resolved.resolved,
32
+ }),
33
+ };
34
+ }
35
+ eager.trail.model = { resolvedModel: resolved.resolved, serviceTier };
36
+ return { next: { ...call, resolved, serviceTier } };
37
+ }
38
+ /**
39
+ * Scan the workspace, then the refusals that need the scan and cost nothing: a positive `thinkingBudget` that leaves
40
+ * no answer reserve under the caller's own cap (`thinkingBudgetRefusal`; the budget on the wire is clamped under the
41
+ * cap that runs later), and an inline request over Google's size limit (only with attachments). The input estimate is
42
+ * the one the budget and the TPM reservations both hold.
43
+ */
44
+ export async function scanAsk(call) {
45
+ const { input, ctx, attachments } = call;
46
+ const scan = await scanForCall(call.eager, ctx, input);
47
+ const outputCap = eagerOutputCap(input.maxOutputTokens, ctx, call.resolved);
48
+ const budgetRefusal = thinkingBudgetRefusal(input.thinkingBudget, input.maxOutputTokens, outputCap.effective);
49
+ if (budgetRefusal !== null)
50
+ return { end: errorResult(`ask: ${budgetRefusal}`) };
51
+ const estimate = estimateInput(scan, input.prompt, attachments.tokens);
52
+ const inlineRefusal = inlineRequestRefusal(attachments, scan.files, input.prompt, call.serviceTier);
53
+ if (inlineRefusal !== undefined)
54
+ return { end: inlineRefusal };
55
+ return { next: { ...call, scan, outputCap, estimate } };
56
+ }
57
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set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reservation of the worst case. */
2
+ import type { StepOutcome } from '../shared/eager-call.js';
3
+ import type { AskCounted, AskSized } from './call.js';
4
+ /**
5
+ * Size the call: the output cap bounded by the model's input window (a cut is said on the progress channel and the
6
+ * log), the thinking normalised under it, then the reservation — the thinking it counts from the cap that runs. Over
7
+ * the daily budget the call ends with nothing reserved; reserved, the call's trail holds the id.
8
+ */
9
+ export declare function sizeAsk(call: AskCounted): StepOutcome<AskSized>;
10
+ //# sourceMappingURL=sizing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sizing.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/sizing.ts"],"names":[],"mappings":"AAAA,oHAAoH;AAGpH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAItD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAwB/D"}
@@ -0,0 +1,33 @@
1
+ /** `ask`'s sizing: the cap that runs, the thinking under it, and the daily-budget reservation of the worst case. */
2
+ import { capThatRuns } from '../../gemini/long-decode.js';
3
+ import { reserveCallBudget } from '../shared/eager-steps.js';
4
+ import { thinkingReserve } from '../shared/thinking.js';
5
+ import { budgetRejectResult } from './results.js';
6
+ import { askThinking, thinkingBudgetField } from './thinking.js';
7
+ /**
8
+ * Size the call: the output cap bounded by the model's input window (a cut is said on the progress channel and the
9
+ * log), the thinking normalised under it, then the reservation — the thinking it counts from the cap that runs. Over
10
+ * the daily budget the call ends with nothing reserved; reserved, the call's trail holds the id.
11
+ */
12
+ export function sizeAsk(call) {
13
+ const { input, eager } = call;
14
+ const bounded = capThatRuns({
15
+ tool: 'ask',
16
+ cap: call.outputCap,
17
+ promptTokens: call.count?.preflight.effectiveTokens,
18
+ inputTokenLimit: call.resolved.inputTokenLimit,
19
+ emit: (message) => eager.emitter.emit(message),
20
+ });
21
+ const thinking = askThinking(input, bounded.cap);
22
+ const sized = { ...call, bounded, thinking };
23
+ const refusal = reserveCallBudget(eager, call.ctx, sized, {
24
+ promptChars: input.prompt.length,
25
+ extraInputTokens: call.attachments.tokens,
26
+ thinkingTokens: thinkingReserve(input.thinkingLevel, thinkingBudgetField(thinking), bounded.cap),
27
+ });
28
+ if (refusal !== null) {
29
+ return { end: budgetRejectResult(sized, refusal) };
30
+ }
31
+ return { next: sized };
32
+ }
33
+ //# sourceMappingURL=sizing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sizing.js","sourceRoot":"","sources":["../../../src/tools/ask/sizing.ts"],"names":[],"mappings":"AAAA,oHAAoH;AAEpH,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEjE;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,IAAgB;IACtC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC9B,MAAM,OAAO,GAAG,WAAW,CAAC;QAC1B,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,IAAI,CAAC,SAAS;QACnB,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,eAAe;QACnD,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe;QAC9C,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;KAC/C,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,KAAK,GAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACvD,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE;QACxD,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;QAChC,gBAAgB,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM;QACzC,cAAc,EAAE,eAAe,CAC7B,KAAK,CAAC,aAAa,EACnB,mBAAmB,CAAC,QAAQ,CAAC,EAC7B,OAAO,CAAC,GAAG,CACZ;KACF,CAAC,CAAC;IACH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;IACrD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * `ask`'s thinking: the caller's `thinkingLevel` or `thinkingBudget` normalised under the cap that runs, the wire
3
+ * config it becomes, the budget the result reports and the progress line that opens the decode. The thinking the budget
4
+ * reservation counts is `thinkingReserve`'s (`../shared/thinking.ts`), called with the level and `thinkingBudgetField`.
5
+ */
6
+ import type { ThinkingConfig } from '@google/genai';
7
+ import type { OutputCap } from '../../gemini/long-decode.js';
8
+ import { type ThinkingLevelLiteral } from '../shared/thinking.js';
9
+ import type { AskInput } from './input.js';
10
+ /**
11
+ * How the call drives the model's reasoning, one of three on the wire:
12
+ * - `level`: the caller's `thinkingLevel`, Google's recommended path on Gemini 3 (rejected by the Gemini 2.5 family).
13
+ * The schema's `.refine()` refuses a `thinkingBudget` beside it; a call that reaches `execute` with both anyway
14
+ * sends the level alone and reports the budget normalised as on the budget path (`reportedBudget`);
15
+ * - `model-default`: neither knob set — nothing goes on the wire but `includeThoughts`, and Gemini uses each model's
16
+ * native default, which per Google's Gemini 3 guide (https://ai.google.dev/gemini-api/docs/gemini-3) is
17
+ * HIGH-dynamic on Gemini 3 Pro. Google flags an explicit `thinkingBudget` as the "legacy" path on Gemini 3 ("may
18
+ * result in unexpected performance"), and Gemini 3 Pro was observed hanging on low positive budgets with cached
19
+ * content active (docs/KNOWN-DEFICITS.md): omitting the field sidesteps both, while power users can still opt
20
+ * into an explicit budget on Gemini 2.5 or for a cost-bounded deep-dive;
21
+ * - `budget`: `-1` (the explicit legacy dynamic budget), `0` (thinking disabled; Gemini 3 Pro answers 400), or a
22
+ * positive budget clamped under the cap that runs.
23
+ */
24
+ export type AskThinking = {
25
+ readonly kind: 'level';
26
+ readonly level: ThinkingLevelLiteral;
27
+ /** The caller's `thinkingBudget` normalised under the cap, never sent: the result reports it. */
28
+ readonly reportedBudget: number | null;
29
+ } | {
30
+ readonly kind: 'model-default';
31
+ } | {
32
+ readonly kind: 'budget';
33
+ readonly budget: number;
34
+ };
35
+ /**
36
+ * Normalise the caller's thinking under `cap`, the cap that runs. A positive budget is clamped to
37
+ * [0, cap − 1024]: the thinking pool is carved out of the candidate-output allowance, so reserving ≥ 1024 tokens for
38
+ * the answer prevents 400s when a caller passes a budget ≥ `maxOutputTokens`, and under a cap the input window cut to
39
+ * one request (its value on the wire) the budget stays below it.
40
+ */
41
+ export declare function askThinking(input: AskInput, cap: OutputCap): AskThinking;
42
+ /**
43
+ * The `thinkingConfig` of every request, with a cache too (`RequestBuilder`, `../shared/eager-answer.ts`).
44
+ * `includeThoughts: true` is always set so the caller sees Gemini's reasoning digest.
45
+ */
46
+ export declare function thinkingConfigOf(thinking: AskThinking): ThinkingConfig;
47
+ /**
48
+ * The budget the result reports and the reservation counts: the one sent on the budget path, the one normalised but
49
+ * not sent on the level path (the reservation then counts the level's tier), `null` when the caller set none.
50
+ */
51
+ export declare function thinkingBudgetField(thinking: AskThinking): number | null;
52
+ /** The progress line that opens the decode. */
53
+ export declare function generatingLine(thinking: AskThinking): string;
54
+ //# sourceMappingURL=thinking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking.d.ts","sourceRoot":"","sources":["../../../src/tools/ask/thinking.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,WAAW,GACnB;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,iGAAiG;IACjG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAClC;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,GAAG,WAAW,CAMxE;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,cAAc,CAStE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CASxE;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAW5D"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * `ask`'s thinking: the caller's `thinkingLevel` or `thinkingBudget` normalised under the cap that runs, the wire
3
+ * config it becomes, the budget the result reports and the progress line that opens the decode. The thinking the budget
4
+ * reservation counts is `thinkingReserve`'s (`../shared/thinking.ts`), called with the level and `thinkingBudgetField`.
5
+ */
6
+ import { levelThinkingConfig, thinkingBudgetUnder, } from '../shared/thinking.js';
7
+ /**
8
+ * Normalise the caller's thinking under `cap`, the cap that runs. A positive budget is clamped to
9
+ * [0, cap − 1024]: the thinking pool is carved out of the candidate-output allowance, so reserving ≥ 1024 tokens for
10
+ * the answer prevents 400s when a caller passes a budget ≥ `maxOutputTokens`, and under a cap the input window cut to
11
+ * one request (its value on the wire) the budget stays below it.
12
+ */
13
+ export function askThinking(input, cap) {
14
+ const budget = normalisedBudget(input.thinkingBudget, cap);
15
+ if (input.thinkingLevel !== undefined) {
16
+ return { kind: 'level', level: input.thinkingLevel, reportedBudget: budget };
17
+ }
18
+ return budget === null ? { kind: 'model-default' } : { kind: 'budget', budget };
19
+ }
20
+ /** The caller's `thinkingBudget` under `cap`: `null` unset, `-1` and `0` as they are, a positive one clamped. */
21
+ function normalisedBudget(raw, cap) {
22
+ if (raw === undefined)
23
+ return null;
24
+ if (raw === -1)
25
+ return -1;
26
+ return raw > 0 ? thinkingBudgetUnder(cap, raw) : 0;
27
+ }
28
+ /**
29
+ * The `thinkingConfig` of every request, with a cache too (`RequestBuilder`, `../shared/eager-answer.ts`).
30
+ * `includeThoughts: true` is always set so the caller sees Gemini's reasoning digest.
31
+ */
32
+ export function thinkingConfigOf(thinking) {
33
+ switch (thinking.kind) {
34
+ case 'level':
35
+ return levelThinkingConfig(thinking.level);
36
+ case 'model-default':
37
+ return { includeThoughts: true };
38
+ case 'budget':
39
+ return { thinkingBudget: thinking.budget, includeThoughts: true };
40
+ }
41
+ }
42
+ /**
43
+ * The budget the result reports and the reservation counts: the one sent on the budget path, the one normalised but
44
+ * not sent on the level path (the reservation then counts the level's tier), `null` when the caller set none.
45
+ */
46
+ export function thinkingBudgetField(thinking) {
47
+ switch (thinking.kind) {
48
+ case 'level':
49
+ return thinking.reportedBudget;
50
+ case 'model-default':
51
+ return null;
52
+ case 'budget':
53
+ return thinking.budget;
54
+ }
55
+ }
56
+ /** The progress line that opens the decode. */
57
+ export function generatingLine(thinking) {
58
+ switch (thinking.kind) {
59
+ case 'level':
60
+ return `generating response (thinking-level=${thinking.level})…`;
61
+ case 'model-default':
62
+ return 'generating response (thinking=model-default)…';
63
+ case 'budget':
64
+ return thinking.budget === -1
65
+ ? 'generating response (thinking=dynamic)…'
66
+ : `generating response (thinking=${thinking.budget})…`;
67
+ }
68
+ }
69
+ //# sourceMappingURL=thinking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking.js","sourceRoot":"","sources":["../../../src/tools/ask/thinking.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAEL,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AA2B/B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAe,EAAE,GAAc;IACzD,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IAC3D,IAAI,KAAK,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC;IAC/E,CAAC;IACD,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAClF,CAAC;AAED,iHAAiH;AACjH,SAAS,gBAAgB,CAAC,GAAuB,EAAE,GAAc;IAC/D,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IAC1B,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAqB;IACpD,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,OAAO;YACV,OAAO,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7C,KAAK,eAAe;YAClB,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACtE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAqB;IACvD,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC,cAAc,CAAC;QACjC,KAAK,eAAe;YAClB,OAAO,IAAI,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,cAAc,CAAC,QAAqB;IAClD,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,OAAO;YACV,OAAO,uCAAuC,QAAQ,CAAC,KAAK,IAAI,CAAC;QACnE,KAAK,eAAe;YAClB,OAAO,+CAA+C,CAAC;QACzD,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;gBAC3B,CAAC,CAAC,yCAAyC;gBAC3C,CAAC,CAAC,iCAAiC,QAAQ,CAAC,MAAM,IAAI,CAAC;IAC7D,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `ask`'s fallback to `ask_agentic` (`onWorkspaceTooLarge: 'fallback-to-agentic'`): the workspace exceeds the eager
3
+ * path's window, so the question goes to the agentic loop and its result is wrapped for `ask`'s caller.
4
+ *
5
+ * The knobs (`docs/DESIGN-agentic-time-bounds.md`, "Target, `ask` fallback"): `ask` resolved its own once — per call,
6
+ * else `GEMINI_CODE_CONTEXT_ASK_TIMEOUT_MS` / `_STALL_MS`, the values its controller holds — and forwards them:
7
+ * `timeoutMs` → `iterationTimeoutMs` (a per-iteration cap: the agentic call can run `maxIterations × timeoutMs`), and
8
+ * `stallMs` → `stallMs` (the same heartbeat watchdog on the loop's streams). `ask`'s own controller is disposed at the
9
+ * hand-off; the agentic call keeps its own clocks, and its timeout messages name `ask`'s knobs.
10
+ */
11
+ import type { PreflightTokenResult } from '../gemini/token-counter.js';
12
+ import type { ProgressEmitter } from '../utils/progress.js';
13
+ import type { KnobNames } from './agentic/run.js';
14
+ import type { AskInput } from './ask/input.js';
15
+ import type { TextToolResult, ToolContext } from './registry.js';
16
+ import { type TimeoutController } from './shared/abort-timeout.js';
17
+ /** The knobs a fallback's timeout message names: `ask`'s, which became the agentic call's. */
18
+ export declare const ASK_KNOB_NAMES: KnobNames;
19
+ /** What `ask` hands over when it falls back. */
20
+ export interface AgenticFallback {
21
+ readonly input: AskInput;
22
+ readonly ctx: ToolContext;
23
+ readonly emitter: ProgressEmitter;
24
+ /** The tier the eager path resolved; a `flex` request is reported downgraded (the agentic loop has no tier). */
25
+ readonly serviceTier: 'standard' | 'flex' | undefined;
26
+ readonly preflight: PreflightTokenResult;
27
+ readonly threshold: number;
28
+ /** `ask`'s own controller: its resolved knobs are forwarded, then it is disposed. */
29
+ readonly timeout: TimeoutController;
30
+ }
31
+ /** Run the question through `ask_agentic` with `ask`'s knobs and wrap the result. */
32
+ export declare function fallBackToAgentic(fallback: AgenticFallback): Promise<TextToolResult>;
33
+ //# sourceMappingURL=ask-agentic-fallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask-agentic-fallback.d.ts","sourceRoot":"","sources":["../../src/tools/ask-agentic-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAErF,8FAA8F;AAC9F,eAAO,MAAM,cAAc,EAAE,SAK3B,CAAC;AAEH,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,gHAAgH;IAChH,QAAQ,CAAC,WAAW,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AAqFD,qFAAqF;AACrF,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAe1F"}