@onlyflows/servicenow-mcp 2.3.0-rc.1 → 2.3.0-rc.3

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 (248) hide show
  1. package/CHANGELOG.md +788 -3
  2. package/README.md +446 -41
  3. package/dist/atf-policy.d.ts +1 -1
  4. package/dist/atf-policy.d.ts.map +1 -1
  5. package/dist/atf-policy.js +2 -0
  6. package/dist/atf-policy.js.map +1 -1
  7. package/dist/call-metrics.d.ts +42 -0
  8. package/dist/call-metrics.d.ts.map +1 -0
  9. package/dist/call-metrics.js +89 -0
  10. package/dist/call-metrics.js.map +1 -0
  11. package/dist/client.d.ts +18 -14
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +51 -36
  14. package/dist/client.js.map +1 -1
  15. package/dist/code-search-snippet.d.ts +25 -0
  16. package/dist/code-search-snippet.d.ts.map +1 -0
  17. package/dist/code-search-snippet.js +67 -0
  18. package/dist/code-search-snippet.js.map +1 -0
  19. package/dist/code-search-targets.d.ts +66 -0
  20. package/dist/code-search-targets.d.ts.map +1 -0
  21. package/dist/code-search-targets.js +82 -0
  22. package/dist/code-search-targets.js.map +1 -0
  23. package/dist/config.d.ts +1 -1
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/credential-tables.d.ts +32 -0
  26. package/dist/credential-tables.d.ts.map +1 -0
  27. package/dist/credential-tables.js +58 -0
  28. package/dist/credential-tables.js.map +1 -0
  29. package/dist/encoded-query-policy.d.ts +9 -0
  30. package/dist/encoded-query-policy.d.ts.map +1 -1
  31. package/dist/encoded-query-policy.js +27 -2
  32. package/dist/encoded-query-policy.js.map +1 -1
  33. package/dist/execution-context.d.ts +14 -0
  34. package/dist/execution-context.d.ts.map +1 -1
  35. package/dist/execution-context.js +8 -0
  36. package/dist/execution-context.js.map +1 -1
  37. package/dist/field-policy.d.ts +44 -1
  38. package/dist/field-policy.d.ts.map +1 -1
  39. package/dist/field-policy.js +623 -35
  40. package/dist/field-policy.js.map +1 -1
  41. package/dist/hidden-values.d.ts +225 -0
  42. package/dist/hidden-values.d.ts.map +1 -0
  43. package/dist/hidden-values.js +748 -0
  44. package/dist/hidden-values.js.map +1 -0
  45. package/dist/http-entrypoint.d.ts.map +1 -1
  46. package/dist/http-entrypoint.js +7 -0
  47. package/dist/http-entrypoint.js.map +1 -1
  48. package/dist/http-observability.js +1 -0
  49. package/dist/http-observability.js.map +1 -1
  50. package/dist/http-runtime.js +16 -0
  51. package/dist/http-runtime.js.map +1 -1
  52. package/dist/index.js +7 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/metadata-cache.d.ts +135 -7
  55. package/dist/metadata-cache.d.ts.map +1 -1
  56. package/dist/metadata-cache.js +357 -21
  57. package/dist/metadata-cache.js.map +1 -1
  58. package/dist/policy-card.d.ts +16 -1
  59. package/dist/policy-card.d.ts.map +1 -1
  60. package/dist/policy-card.js +15 -2
  61. package/dist/policy-card.js.map +1 -1
  62. package/dist/profile-admin.d.ts +18 -0
  63. package/dist/profile-admin.d.ts.map +1 -1
  64. package/dist/profile-admin.js +26 -1
  65. package/dist/profile-admin.js.map +1 -1
  66. package/dist/profile-manager.d.ts +13 -1
  67. package/dist/profile-manager.d.ts.map +1 -1
  68. package/dist/profile-manager.js +23 -1
  69. package/dist/profile-manager.js.map +1 -1
  70. package/dist/response-too-large.d.ts +23 -0
  71. package/dist/response-too-large.d.ts.map +1 -0
  72. package/dist/response-too-large.js +42 -0
  73. package/dist/response-too-large.js.map +1 -0
  74. package/dist/risky-grants.d.ts +6 -2
  75. package/dist/risky-grants.d.ts.map +1 -1
  76. package/dist/risky-grants.js +58 -5
  77. package/dist/risky-grants.js.map +1 -1
  78. package/dist/setup-prompts.js +1 -1
  79. package/dist/setup-prompts.js.map +1 -1
  80. package/dist/setup.d.ts +4 -0
  81. package/dist/setup.d.ts.map +1 -1
  82. package/dist/setup.js +176 -68
  83. package/dist/setup.js.map +1 -1
  84. package/dist/structured-query.d.ts +61 -2
  85. package/dist/structured-query.d.ts.map +1 -1
  86. package/dist/structured-query.js +382 -36
  87. package/dist/structured-query.js.map +1 -1
  88. package/dist/table-policy.d.ts +75 -2
  89. package/dist/table-policy.d.ts.map +1 -1
  90. package/dist/table-policy.js +184 -15
  91. package/dist/table-policy.js.map +1 -1
  92. package/dist/tool-error.d.ts +47 -4
  93. package/dist/tool-error.d.ts.map +1 -1
  94. package/dist/tool-error.js +104 -4
  95. package/dist/tool-error.js.map +1 -1
  96. package/dist/tool-table-access.d.ts +9 -2
  97. package/dist/tool-table-access.d.ts.map +1 -1
  98. package/dist/tool-table-access.js +118 -36
  99. package/dist/tool-table-access.js.map +1 -1
  100. package/dist/tools/aggregate.js +2 -2
  101. package/dist/tools/aggregate.js.map +1 -1
  102. package/dist/tools/all-fields-cap.d.ts.map +1 -1
  103. package/dist/tools/all-fields-cap.js +29 -7
  104. package/dist/tools/all-fields-cap.js.map +1 -1
  105. package/dist/tools/atf-author-module.d.ts +1 -7
  106. package/dist/tools/atf-author-module.d.ts.map +1 -1
  107. package/dist/tools/atf-author-module.js +16 -7
  108. package/dist/tools/atf-author-module.js.map +1 -1
  109. package/dist/tools/atf-contracts.d.ts +69 -4
  110. package/dist/tools/atf-contracts.d.ts.map +1 -1
  111. package/dist/tools/atf-contracts.js +32 -2
  112. package/dist/tools/atf-contracts.js.map +1 -1
  113. package/dist/tools/atf-renderers.js +2 -1
  114. package/dist/tools/atf-renderers.js.map +1 -1
  115. package/dist/tools/atf-results-module.d.ts.map +1 -1
  116. package/dist/tools/atf-results-module.js +5 -3
  117. package/dist/tools/atf-results-module.js.map +1 -1
  118. package/dist/tools/atf-run-module.js +3 -2
  119. package/dist/tools/atf-run-module.js.map +1 -1
  120. package/dist/tools/atf-shared.d.ts +6 -0
  121. package/dist/tools/atf-shared.d.ts.map +1 -1
  122. package/dist/tools/atf-shared.js +49 -10
  123. package/dist/tools/atf-shared.js.map +1 -1
  124. package/dist/tools/atf-step-catalog.d.ts +13 -8
  125. package/dist/tools/atf-step-catalog.d.ts.map +1 -1
  126. package/dist/tools/atf-step-catalog.js +169 -5
  127. package/dist/tools/atf-step-catalog.js.map +1 -1
  128. package/dist/tools/batch.d.ts.map +1 -1
  129. package/dist/tools/batch.js +25 -7
  130. package/dist/tools/batch.js.map +1 -1
  131. package/dist/tools/catalog.d.ts.map +1 -1
  132. package/dist/tools/catalog.js +2 -1
  133. package/dist/tools/catalog.js.map +1 -1
  134. package/dist/tools/codesearch.d.ts +2 -2
  135. package/dist/tools/codesearch.d.ts.map +1 -1
  136. package/dist/tools/codesearch.js +536 -67
  137. package/dist/tools/codesearch.js.map +1 -1
  138. package/dist/tools/flow-view-contracts.d.ts +59 -3
  139. package/dist/tools/flow-view-contracts.d.ts.map +1 -1
  140. package/dist/tools/flow-view-contracts.js +34 -2
  141. package/dist/tools/flow-view-contracts.js.map +1 -1
  142. package/dist/tools/flow-view-graph.d.ts +14 -0
  143. package/dist/tools/flow-view-graph.d.ts.map +1 -1
  144. package/dist/tools/flow-view-graph.js +43 -1
  145. package/dist/tools/flow-view-graph.js.map +1 -1
  146. package/dist/tools/flow-view-module.js +2 -2
  147. package/dist/tools/flow-view-module.js.map +1 -1
  148. package/dist/tools/flow-view-policy.d.ts +3 -3
  149. package/dist/tools/flow-view-policy.d.ts.map +1 -1
  150. package/dist/tools/flow-view-policy.js +5 -4
  151. package/dist/tools/flow-view-policy.js.map +1 -1
  152. package/dist/tools/flow-view-renderers.d.ts.map +1 -1
  153. package/dist/tools/flow-view-renderers.js +9 -21
  154. package/dist/tools/flow-view-renderers.js.map +1 -1
  155. package/dist/tools/get-module.js +1 -1
  156. package/dist/tools/get-module.js.map +1 -1
  157. package/dist/tools/index.d.ts.map +1 -1
  158. package/dist/tools/index.js +116 -25
  159. package/dist/tools/index.js.map +1 -1
  160. package/dist/tools/platform-view-contracts.d.ts +189 -0
  161. package/dist/tools/platform-view-contracts.d.ts.map +1 -0
  162. package/dist/tools/platform-view-contracts.js +353 -0
  163. package/dist/tools/platform-view-contracts.js.map +1 -0
  164. package/dist/tools/platform-view-evaluate.d.ts +219 -0
  165. package/dist/tools/platform-view-evaluate.d.ts.map +1 -0
  166. package/dist/tools/platform-view-evaluate.js +1346 -0
  167. package/dist/tools/platform-view-evaluate.js.map +1 -0
  168. package/dist/tools/platform-view-module.d.ts +28 -0
  169. package/dist/tools/platform-view-module.d.ts.map +1 -0
  170. package/dist/tools/platform-view-module.js +111 -0
  171. package/dist/tools/platform-view-module.js.map +1 -0
  172. package/dist/tools/platform-view-scan.d.ts +57 -0
  173. package/dist/tools/platform-view-scan.d.ts.map +1 -0
  174. package/dist/tools/platform-view-scan.js +375 -0
  175. package/dist/tools/platform-view-scan.js.map +1 -0
  176. package/dist/tools/platform-view-upgrades.d.ts +152 -0
  177. package/dist/tools/platform-view-upgrades.d.ts.map +1 -0
  178. package/dist/tools/platform-view-upgrades.js +545 -0
  179. package/dist/tools/platform-view-upgrades.js.map +1 -0
  180. package/dist/tools/profile.d.ts.map +1 -1
  181. package/dist/tools/profile.js +1 -0
  182. package/dist/tools/profile.js.map +1 -1
  183. package/dist/tools/query-module.d.ts.map +1 -1
  184. package/dist/tools/query-module.js +231 -64
  185. package/dist/tools/query-module.js.map +1 -1
  186. package/dist/tools/record-write-shared.d.ts.map +1 -1
  187. package/dist/tools/record-write-shared.js +4 -3
  188. package/dist/tools/record-write-shared.js.map +1 -1
  189. package/dist/tools/result-envelope.d.ts +429 -38
  190. package/dist/tools/result-envelope.d.ts.map +1 -1
  191. package/dist/tools/result-envelope.js +372 -36
  192. package/dist/tools/result-envelope.js.map +1 -1
  193. package/dist/tools/schema-module.d.ts.map +1 -1
  194. package/dist/tools/schema-module.js +1 -1
  195. package/dist/tools/schema-module.js.map +1 -1
  196. package/dist/tools/syslog-cursor.d.ts +61 -0
  197. package/dist/tools/syslog-cursor.d.ts.map +1 -0
  198. package/dist/tools/syslog-cursor.js +146 -0
  199. package/dist/tools/syslog-cursor.js.map +1 -0
  200. package/dist/tools/syslog.d.ts +2 -0
  201. package/dist/tools/syslog.d.ts.map +1 -1
  202. package/dist/tools/syslog.js +126 -2
  203. package/dist/tools/syslog.js.map +1 -1
  204. package/dist/tools/truncation-hint.d.ts +125 -0
  205. package/dist/tools/truncation-hint.d.ts.map +1 -0
  206. package/dist/tools/truncation-hint.js +298 -0
  207. package/dist/tools/truncation-hint.js.map +1 -0
  208. package/dist/unknown-filter-fields.d.ts +52 -0
  209. package/dist/unknown-filter-fields.d.ts.map +1 -0
  210. package/dist/unknown-filter-fields.js +87 -0
  211. package/dist/unknown-filter-fields.js.map +1 -0
  212. package/dist/update-set-eval/engine.d.ts +29 -0
  213. package/dist/update-set-eval/engine.d.ts.map +1 -0
  214. package/dist/update-set-eval/engine.js +405 -0
  215. package/dist/update-set-eval/engine.js.map +1 -0
  216. package/dist/update-set-eval/prepare.d.ts +72 -0
  217. package/dist/update-set-eval/prepare.d.ts.map +1 -0
  218. package/dist/update-set-eval/prepare.js +216 -0
  219. package/dist/update-set-eval/prepare.js.map +1 -0
  220. package/dist/update-set-eval/rules.d.ts +126 -0
  221. package/dist/update-set-eval/rules.d.ts.map +1 -0
  222. package/dist/update-set-eval/rules.js +927 -0
  223. package/dist/update-set-eval/rules.js.map +1 -0
  224. package/dist/update-set-eval/script-scan.d.ts +65 -0
  225. package/dist/update-set-eval/script-scan.d.ts.map +1 -0
  226. package/dist/update-set-eval/script-scan.js +378 -0
  227. package/dist/update-set-eval/script-scan.js.map +1 -0
  228. package/dist/update-set-eval/secret-patterns.d.ts +75 -0
  229. package/dist/update-set-eval/secret-patterns.d.ts.map +1 -0
  230. package/dist/update-set-eval/secret-patterns.js +570 -0
  231. package/dist/update-set-eval/secret-patterns.js.map +1 -0
  232. package/dist/update-set-eval/types.d.ts +181 -0
  233. package/dist/update-set-eval/types.d.ts.map +1 -0
  234. package/dist/update-set-eval/types.js +20 -0
  235. package/dist/update-set-eval/types.js.map +1 -0
  236. package/dist/update-set-eval/xml-reader.d.ts +117 -0
  237. package/dist/update-set-eval/xml-reader.d.ts.map +1 -0
  238. package/dist/update-set-eval/xml-reader.js +561 -0
  239. package/dist/update-set-eval/xml-reader.js.map +1 -0
  240. package/dist/version.d.ts +1 -1
  241. package/dist/version.js +1 -1
  242. package/docs/CLIENT-SETUP.md +30 -7
  243. package/docs/FLOW-VIEW.md +14 -5
  244. package/docs/PRODUCTION-SECURITY.md +84 -1
  245. package/docs/PROFILE-CREDENTIALS.md +10 -4
  246. package/docs/V2-MIGRATION.md +1 -1
  247. package/package.json +1 -1
  248. package/server.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"result-envelope.d.ts","sourceRoot":"","sources":["../../src/tools/result-envelope.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,eAAO,MAAM,2BAA2B,OAAQ,CAAC;AACjD,eAAO,MAAM,yBAAyB,SAA6B,CAAC;AACpE,eAAO,MAAM,4BAA4B,QAAmB,CAAC;AAuC7D,kFAAkF;AAClF,eAAO,MAAM,sBAAsB;;;;;;;;;;;oBAGjC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAuBtB,CAAC;AAEZ,wBAAgB,4BAA4B,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EACpE,UAAU,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAUpB;AAwBD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAiIzC,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,yBAAyB,KAC/B,MAAM,CAAC;AAOZ,kFAAkF;AAClF,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,kBAAkB,EACxB,QAAQ,EAAE,oBAAoB,GAC7B,IAAI,CAcN;AA2aD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAS1E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,cAAc,EAC7B,QAAQ,EAAE,mBAAmB,GAC5B,cAAc,CAsBhB;AA0BD,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACvC,MAAM,EAAE,cAAc,GACrB,cAAc,CA6FhB;AA+JD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,cAAc,EACtB,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,GAAE,yBAA8B,GACtC,cAAc,GAAG,SAAS,CA+B5B"}
@@ -4,6 +4,8 @@ exports.productionToolOutputSchemas = exports.ENVELOPE_HINT_KEY = exports.result
4
4
  exports.withStructuredResultEnvelope = withStructuredResultEnvelope;
5
5
  exports.isProductionToolName = isProductionToolName;
6
6
  exports.registerEnvelopeTextRenderer = registerEnvelopeTextRenderer;
7
+ exports.withoutCallMetadata = withoutCallMetadata;
8
+ exports.withCallMetadata = withCallMetadata;
7
9
  exports.envelopeCompatibilityResult = envelopeCompatibilityResult;
8
10
  exports.finalizeEnvelopeResult = finalizeEnvelopeResult;
9
11
  const atf_contracts_js_1 = require("./atf-contracts.js");
@@ -13,7 +15,9 @@ const batch_limits_js_1 = require("../batch-limits.js");
13
15
  const field_policy_js_1 = require("../field-policy.js");
14
16
  const utils_js_1 = require("../utils.js");
15
17
  const markdown_js_1 = require("./markdown.js");
18
+ const truncation_hint_js_1 = require("./truncation-hint.js");
16
19
  const tool_module_js_1 = require("./tool-module.js");
20
+ const syslog_cursor_js_1 = require("./syslog-cursor.js");
17
21
  exports.DEFAULT_RESULT_RECORD_LIMIT = 1_000;
18
22
  exports.DEFAULT_RESULT_BYTE_LIMIT = utils_js_1.MAX_RESPONSE_BYTES_DEFAULT;
19
23
  exports.ATTACHMENT_RESULT_BYTE_LIMIT = 14 * 1024 * 1024;
@@ -34,11 +38,18 @@ const offsetPaginationSchema = zod_1.z
34
38
  })
35
39
  .strict()
36
40
  .superRefine((value, context) => {
41
+ // has_more means rows exist that this response did not contain. Normally
42
+ // next_offset points at the first of them. When rows were dropped for
43
+ // size and not one fit, no offset can advance: `recovery` then marks that
44
+ // the request itself must change, and next_offset is left out.
37
45
  if (value.has_more &&
38
- (value.next_offset === undefined || value.next_offset <= value.offset)) {
46
+ (value.next_offset === undefined
47
+ ? value.recovery === undefined
48
+ : value.next_offset <= value.offset)) {
39
49
  context.addIssue({
40
50
  code: zod_1.z.ZodIssueCode.custom,
41
- message: "next_offset must advance beyond offset when has_more is true",
51
+ message: "next_offset must advance beyond offset when has_more is true, " +
52
+ "unless recovery says the request must change",
42
53
  path: ["next_offset"],
43
54
  });
44
55
  }
@@ -55,6 +66,29 @@ exports.resultPaginationSchema = zod_1.z.union([
55
66
  zod_1.z.object({ mode: zod_1.z.literal("none") }).strict(),
56
67
  offsetPaginationSchema,
57
68
  ]);
69
+ /**
70
+ * What a call reports about itself (see `call-metrics.ts`): one compact
71
+ * definition, shared by every tool's output schema. `metadata.cache` and
72
+ * `metadata.timing` are both optional: a handler builds its envelope without
73
+ * them and the dispatcher adds them, and `cache` is absent when the call made
74
+ * no cacheable read.
75
+ */
76
+ // Validation still bounds these to safe integers; only the advertised
77
+ // `maximum` (2^53 - 1, 81 characters per tool in `tools/list`) is left out,
78
+ // since no duration comes near it. The undefined meta value removes the key.
79
+ const wholeMilliseconds = nonNegativeInteger.meta({ maximum: undefined });
80
+ const callTimingSchema = zod_1.z
81
+ .object({
82
+ total_ms: wholeMilliseconds,
83
+ upstream_ms: wholeMilliseconds,
84
+ watermark_ms: wholeMilliseconds,
85
+ })
86
+ .strict();
87
+ const callMetadataShape = {
88
+ cache: zod_1.z.enum(["hit", "miss", "bypass", "mixed"]).optional(),
89
+ timing: callTimingSchema.optional(),
90
+ };
91
+ const callMetadataSchema = zod_1.z.object(callMetadataShape).strict();
58
92
  exports.resultMetadataSchema = zod_1.z
59
93
  .object({
60
94
  kind: zod_1.z.enum(["single", "collection", "operation"]),
@@ -77,6 +111,7 @@ exports.resultMetadataSchema = zod_1.z
77
111
  dropped_records: nonNegativeInteger.optional(),
78
112
  })
79
113
  .strict(),
114
+ ...callMetadataShape,
80
115
  })
81
116
  .strict();
82
117
  function withStructuredResultEnvelope(dataSchema) {
@@ -153,6 +188,7 @@ const atfAuthorResultSchema = zod_1.z.object({
153
188
  rollback_failed: zod_1.z.array(atfRecordIdSchema).max(1000),
154
189
  uncertain_insert: zod_1.z.boolean(),
155
190
  message: zod_1.z.string().max(1000).optional(),
191
+ advice: zod_1.z.array(zod_1.z.string().max(500)).max(5).optional(),
156
192
  }).strict();
157
193
  const queryResultSchema = zod_1.z
158
194
  .object({
@@ -166,6 +202,10 @@ const queryResultSchema = zod_1.z
166
202
  results: dynamicArraySchema,
167
203
  })
168
204
  .strict();
205
+ /** sn_syslog's page, plus the cursor a tail returns. */
206
+ const syslogResultSchema = queryResultSchema.extend({
207
+ cursor: zod_1.z.string().max(syslog_cursor_js_1.MAX_CURSOR_LENGTH).optional(),
208
+ });
169
209
  const createResultSchema = zod_1.z
170
210
  .object({
171
211
  sys_id: canonicalSysIdSchema,
@@ -246,7 +286,7 @@ const productionDataSchemas = Object.freeze({
246
286
  sn_health: healthResultSchema,
247
287
  sn_attach: attachmentResultEnvelopeSchema,
248
288
  sn_relationships: relationshipResultSchema,
249
- sn_syslog: queryResultSchema,
289
+ sn_syslog: syslogResultSchema,
250
290
  sn_codesearch: listResultSchema,
251
291
  sn_discover: listResultSchema,
252
292
  sn_atf: atfResultEnvelopeSchema,
@@ -524,7 +564,10 @@ function effectiveOrder(name, args) {
524
564
  case "sn_relationships":
525
565
  return ["depth_first", "relationship_sys_id"];
526
566
  case "sn_codesearch":
527
- return ["table", "sys_id"];
567
+ // One table: its own sys_id order. Several: each table's first match
568
+ // (script includes first), then each table's second, and so on; `round`
569
+ // is that turn, a position and not a field of the rows.
570
+ return typeof args.table === "string" ? ["sys_id"] : ["round", "table", "sys_id"];
528
571
  case "sn_discover":
529
572
  return args.type === "apps" ? ["source", "sys_id"] : ["sys_id"];
530
573
  case "sn_aggregate":
@@ -550,7 +593,28 @@ function synchronizeRecordCount(data, count) {
550
593
  }
551
594
  }
552
595
  }
553
- function synchronizePagingFields(data, pagination, truncation, depth = 0) {
596
+ /**
597
+ * The truncation hint a tool wrote, if `data` carries one this module's
598
+ * parser accepts, looked for where {@link synchronizePagingFields} restates it.
599
+ */
600
+ function truncationHintParts(data, depth = 0) {
601
+ if (typeof data !== "object" || data === null || Array.isArray(data) || depth > 3) {
602
+ return undefined;
603
+ }
604
+ const record = data;
605
+ if (typeof record.hint === "string" && Object.hasOwn(record, "dropped_records")) {
606
+ const parts = (0, truncation_hint_js_1.parseTruncationHint)(record.hint);
607
+ if (parts !== undefined)
608
+ return parts;
609
+ }
610
+ for (const wrapper of ["meta", "request", "result"]) {
611
+ const parts = truncationHintParts(record[wrapper], depth + 1);
612
+ if (parts !== undefined)
613
+ return parts;
614
+ }
615
+ return undefined;
616
+ }
617
+ function synchronizePagingFields(data, pagination, truncation, depth = 0, neededBytes, capBytes, allBytes, withoutAdvice, widestHint) {
554
618
  if (pagination.mode !== "offset" ||
555
619
  typeof data !== "object" ||
556
620
  data === null ||
@@ -571,13 +635,25 @@ function synchronizePagingFields(data, pagination, truncation, depth = 0) {
571
635
  target.has_more = pagination.has_more;
572
636
  }
573
637
  if (pagination.has_more && pagination.next_offset !== undefined) {
574
- if (Object.hasOwn(target, "next_offset")) {
638
+ // A tool that reports has_more reports where to continue, even when
639
+ // the fit created the continuation (rows dropped for size).
640
+ if (Object.hasOwn(target, "next_offset") || Object.hasOwn(target, "has_more")) {
575
641
  target.next_offset = pagination.next_offset;
576
642
  }
577
643
  }
578
644
  else if (Object.hasOwn(target, "next_offset")) {
579
645
  delete target.next_offset;
580
646
  }
647
+ if (pagination.has_more && typeof target.hint === "string") {
648
+ // The tool wrote its continuation from the page it fetched; if the fit
649
+ // dropped rows, the first row not returned is where to continue.
650
+ target.hint = (0, truncation_hint_js_1.restateContinuationHint)(target.hint, {
651
+ offset: pagination.offset,
652
+ ...(pagination.next_offset === undefined
653
+ ? {}
654
+ : { nextOffset: pagination.next_offset }),
655
+ });
656
+ }
581
657
  if (Object.hasOwn(target, "truncated")) {
582
658
  target.truncated = truncation.truncated;
583
659
  }
@@ -587,6 +663,20 @@ function synchronizePagingFields(data, pagination, truncation, depth = 0) {
587
663
  }
588
664
  else {
589
665
  target.dropped_records = truncation.dropped_records;
666
+ // A tool that explains the drop in a hint wrote it before this fit
667
+ // dropped more rows. Restate it from the final counts and
668
+ // continuation so the text agrees with the fields beside it.
669
+ if (typeof target.hint === "string") {
670
+ target.hint = (0, truncation_hint_js_1.refreshTruncationHint)(target.hint, {
671
+ dropped: truncation.dropped_records,
672
+ returned: pagination.returned,
673
+ ...(neededBytes === undefined ? {} : { neededBytes }),
674
+ ...(allBytes === undefined ? {} : { allBytes }),
675
+ ...(withoutAdvice === true ? { withoutAdvice } : {}),
676
+ ...(widestHint === true ? { widest: true } : {}),
677
+ ...(capBytes === undefined ? {} : { capBytes }),
678
+ });
679
+ }
590
680
  }
591
681
  }
592
682
  };
@@ -595,9 +685,84 @@ function synchronizePagingFields(data, pagination, truncation, depth = 0) {
595
685
  synchronizeObject(record.meta);
596
686
  }
597
687
  for (const wrapper of ["request", "result"]) {
598
- synchronizePagingFields(record[wrapper], pagination, truncation, depth + 1);
688
+ synchronizePagingFields(record[wrapper], pagination, truncation, depth + 1, neededBytes, capBytes, allBytes, withoutAdvice, widestHint);
599
689
  }
600
690
  }
691
+ /**
692
+ * Remove `metadata.cache` and `metadata.timing` from a handler's result. Only
693
+ * the dispatcher reports them, from what it observed, so a value a handler
694
+ * sets is never passed on, whether or not the dispatcher adds its own.
695
+ */
696
+ function withoutCallMetadata(result) {
697
+ const content = result.structuredContent;
698
+ if (typeof content !== "object" || content === null)
699
+ return result;
700
+ const metadata = content.metadata;
701
+ if (typeof metadata !== "object" || metadata === null)
702
+ return result;
703
+ const rest = { ...metadata };
704
+ delete rest.cache;
705
+ delete rest.timing;
706
+ return { ...result, structuredContent: { ...content, metadata: rest } };
707
+ }
708
+ /**
709
+ * Add what the call reports about itself to a finished result's envelope
710
+ * metadata. The two fields are not counted against the result's byte limit.
711
+ *
712
+ * They are diagnostics, so they never cost the caller anything: the result is
713
+ * fitted to its limit first, exactly as before, with the fit, the paging
714
+ * fields and the truncation hint knowing nothing about them, and the fields
715
+ * are added after. A successful response therefore carries them always, on the
716
+ * calls where the timing matters most (a truncated one is often fitted to
717
+ * within a few bytes of the limit), and may exceed the limit by their size,
718
+ * under 100 bytes. A result that is not an envelope comes back untouched.
719
+ */
720
+ function withCallMetadata(handlerResult, snapshot) {
721
+ // Whatever the handler put in the two fields never survives, fitted or not.
722
+ const result = withoutCallMetadata(handlerResult);
723
+ const content = result.structuredContent;
724
+ if (typeof content !== "object" || content === null)
725
+ return result;
726
+ const metadata = content.metadata;
727
+ if (typeof metadata !== "object" || metadata === null)
728
+ return result;
729
+ // Only an envelope has limits; anything else is not this function's to annotate.
730
+ const maxBytes = metadata.limits?.max_bytes;
731
+ if (typeof maxBytes !== "number")
732
+ return result;
733
+ const added = callMetadataSchema.safeParse({
734
+ ...(snapshot.cache === undefined ? {} : { cache: snapshot.cache }),
735
+ timing: snapshot.timing,
736
+ });
737
+ if (!added.success)
738
+ return result;
739
+ return {
740
+ ...result,
741
+ structuredContent: {
742
+ ...content,
743
+ metadata: { ...metadata, ...added.data },
744
+ },
745
+ };
746
+ }
747
+ /**
748
+ * The tools whose handler reads one row past the page it was asked for (limit
749
+ * + 1) and hands that row back with the page. It is not a result: it only
750
+ * says another page exists, so the envelope cuts it, reports `has_more`, and
751
+ * does not count it as dropped. A tool not listed here that returns more rows
752
+ * than the limit has rows cut by the limit, and that is reported.
753
+ */
754
+ const LOOK_AHEAD_TOOLS = new Set([
755
+ "sn_codesearch",
756
+ "sn_discover",
757
+ "sn_aggregate",
758
+ ]);
759
+ /**
760
+ * A tail read of the system log pages by cursor, not by offset: it has no
761
+ * offset to continue at, and its `has_more` and `cursor` are the tool's own.
762
+ */
763
+ function isTailRead(name, args) {
764
+ return name === "sn_syslog" && (args.tail === true || args.after_cursor !== undefined);
765
+ }
601
766
  function envelopeCompatibilityResult(name, args, result) {
602
767
  if (result.isError)
603
768
  return result;
@@ -616,14 +781,23 @@ function envelopeCompatibilityResult(name, args, result) {
616
781
  const explicitNextOffset = numericObjectField(data, "next_offset");
617
782
  const legacyTruncated = booleanObjectField(data, "truncated") === true;
618
783
  const priorDropped = numericObjectField(data, "dropped_records") ?? 0;
784
+ // A tool that dropped rows for size says so (truncated, dropped_records):
785
+ // rows exist that its response does not hold, so there is more to fetch.
786
+ const droppedForSize = collection && legacyTruncated && priorDropped > 0;
619
787
  let hasMore = collection &&
620
788
  (originalCount > returned ||
621
789
  explicitHasMore === true ||
790
+ droppedForSize ||
622
791
  (explicitHasMore === undefined && returned >= limit));
623
792
  let nextOffset;
624
793
  let recovery = legacyTruncated ? "adjust_request_and_retry_same_offset" : undefined;
625
794
  if (hasMore) {
626
- if (explicitNextOffset !== undefined && explicitNextOffset > offset) {
795
+ if (droppedForSize && returned > 0) {
796
+ // The rows returned are a prefix of the window, so the first row not
797
+ // returned is the one to continue at; nothing is skipped.
798
+ nextOffset = offset + returned;
799
+ }
800
+ else if (explicitNextOffset !== undefined && explicitNextOffset > offset) {
627
801
  nextOffset = explicitNextOffset;
628
802
  }
629
803
  else if (originalCount > returned && returned > 0) {
@@ -635,12 +809,20 @@ function envelopeCompatibilityResult(name, args, result) {
635
809
  // the effective limit prevents ACL-filtered windows from being replayed.
636
810
  nextOffset = offset + limit;
637
811
  }
812
+ else if (droppedForSize) {
813
+ // Not one row fit: has_more stays true, no offset can advance, and the
814
+ // request has to change.
815
+ recovery = "adjust_request_and_retry_same_offset";
816
+ }
638
817
  else {
639
818
  hasMore = false;
640
819
  recovery = "adjust_request_and_retry_same_offset";
641
820
  }
642
821
  }
643
- const droppedByRecordLimit = originalCount - returned;
822
+ // The look-ahead row was read to find out whether more exists, not to be
823
+ // returned: it is not a dropped record. Rows past it still are.
824
+ const lookAheadRow = LOOK_AHEAD_TOOLS.has(name) && originalCount > returned ? 1 : 0;
825
+ const droppedByRecordLimit = originalCount - returned - lookAheadRow;
644
826
  const droppedRecords = priorDropped + droppedByRecordLimit;
645
827
  const truncation = legacyTruncated || droppedByRecordLimit > 0
646
828
  ? {
@@ -656,7 +838,7 @@ function envelopeCompatibilityResult(name, args, result) {
656
838
  max_records: maximumRecords,
657
839
  max_bytes: byteLimit(name, args),
658
840
  },
659
- pagination: collection
841
+ pagination: collection && !isTailRead(name, args)
660
842
  ? {
661
843
  mode: "offset",
662
844
  limit,
@@ -689,13 +871,20 @@ function isMutableEnvelope(candidate) {
689
871
  }
690
872
  function renderEnvelopeText(envelope) {
691
873
  const pagination = envelope.metadata.pagination;
874
+ const noRowFit = pagination.mode === "offset" && pagination.returned === 0;
692
875
  const continuation = pagination.mode === "offset" && pagination.has_more
693
- ? ` More records are available at offset ${pagination.next_offset}.`
876
+ ? pagination.next_offset !== undefined
877
+ ? ` More records are available at offset ${pagination.next_offset}.`
878
+ : noRowFit
879
+ ? " More records are available, but none fit."
880
+ : " More records are available; this result has no offset to continue at."
694
881
  : "";
695
882
  const recovery = pagination.mode === "offset" && pagination.recovery !== undefined
696
- ? pagination.has_more
697
- ? ` To recover records dropped from the current window, adjust the request and retry offset ${pagination.offset}; use offset ${pagination.next_offset} only to resume after the consumed window.`
698
- : ` No automatic post-window continuation is available; adjust the request and retry offset ${pagination.offset}.`
883
+ ? pagination.has_more && pagination.next_offset !== undefined
884
+ ? ` Rows were dropped from the current window; next_offset is the first row not returned, or adjust the request and retry offset ${pagination.offset} to get them in one response.`
885
+ : noRowFit
886
+ ? ` No row fit; adjust the request (fewer fields, a lower limit or a higher max_response_bytes) and retry offset ${pagination.offset}.`
887
+ : ` Rows were dropped from the current window; adjust the request (fewer fields, a lower limit or a higher max_response_bytes) and retry offset ${pagination.offset}.`
699
888
  : "";
700
889
  const truncated = envelope.metadata.truncation.truncated
701
890
  ? ` Output was truncated by ${envelope.metadata.truncation.reason}.`
@@ -772,6 +961,24 @@ function truncateLongestString(data) {
772
961
  }
773
962
  return true;
774
963
  }
964
+ /**
965
+ * Give up a derived diagram before any text is cut. A diagram's source is a
966
+ * rendering of fields the result already carries, and cutting it mid-line
967
+ * leaves source that does not parse, so it goes whole, with a note.
968
+ */
969
+ function dropDerivedDiagram(data) {
970
+ if (typeof data !== "object" || data === null)
971
+ return false;
972
+ const diagram = data.diagram;
973
+ if (typeof diagram !== "object" || diagram === null)
974
+ return false;
975
+ const entry = diagram;
976
+ if (typeof entry.source !== "string")
977
+ return false;
978
+ delete entry.source;
979
+ entry.note = flow_view_contracts_js_1.FLOW_DIAGRAM_OMITTED_NOTE;
980
+ return true;
981
+ }
775
982
  function deepFreeze(value) {
776
983
  if (typeof value === "object" && value !== null) {
777
984
  for (const entry of Object.values(value))
@@ -803,7 +1010,7 @@ function renderedEnvelopeText(renderer, envelope, context) {
803
1010
  */
804
1011
  function finalizeEnvelopeResult(result, tool, options = {}) {
805
1012
  envelopeTextRenderersSealed = true;
806
- const summarized = finalizeSummaryResult(result);
1013
+ const summarized = finalizeSummaryResult(result, tool, options.maxResponseBytesCap);
807
1014
  const renderer = tool === undefined ? undefined : ENVELOPE_TEXT_RENDERERS.get(tool);
808
1015
  if (!summarized ||
809
1016
  !renderer ||
@@ -827,20 +1034,75 @@ function finalizeEnvelopeResult(result, tool, options = {}) {
827
1034
  ? rendered
828
1035
  : summarized;
829
1036
  }
830
- function finalizeSummaryResult(result) {
1037
+ /**
1038
+ * The `max_response_bytes` to name for the whole window: what the tool
1039
+ * measured for all its rows, plus what the envelope adds around them. Null
1040
+ * when the tool named none (the window exceeded the maximum on its own) or
1041
+ * when the sum exceeds the maximum, so the hint leaves it out.
1042
+ */
1043
+ function wholeWindowBytes(toolHint, envelopeBytes, current, cap) {
1044
+ if (toolHint.allBytes === undefined)
1045
+ return null;
1046
+ const needed = (0, truncation_hint_js_1.neededResponseBytes)(toolHint.allBytes + envelopeBytes, current, cap);
1047
+ return Number.isFinite(needed) ? needed : null;
1048
+ }
1049
+ /**
1050
+ * The tools whose `offset` argument is a row offset into the collection they
1051
+ * return, so that `offset + rows returned` is the first row not returned. For
1052
+ * these a fit that drops rows for size can offer that offset as
1053
+ * `next_offset`. Any other collection still reports `has_more`, but with no
1054
+ * offset to give: the request has to change.
1055
+ */
1056
+ const OFFSET_PAGED_TOOLS = new Set([
1057
+ "sn_query",
1058
+ "sn_syslog",
1059
+ "sn_schema",
1060
+ "sn_relationships",
1061
+ "sn_codesearch",
1062
+ "sn_discover",
1063
+ "sn_attach",
1064
+ "sn_atf",
1065
+ ]);
1066
+ /**
1067
+ * Fit the result to its byte limit by dropping whole rows from the tail.
1068
+ * Rows dropped for size mean rows exist that the response does not hold, so
1069
+ * `has_more` is true; the rows returned are a prefix of the window, so a
1070
+ * paged tool continues at `offset + rows returned` and loses nothing, and
1071
+ * when no row fits there is no offset to give. With no `tool` (a caller that
1072
+ * does not say which), the offset is offered as for a paged tool.
1073
+ */
1074
+ function finalizeSummaryResult(result, tool, byteCap = utils_js_1.MAX_RESPONSE_BYTES_MAX) {
1075
+ const offsetPaged = tool === undefined || OFFSET_PAGED_TOOLS.has(tool);
831
1076
  if (!isMutableEnvelope(result.structuredContent))
832
1077
  return result;
833
1078
  const sourceEnvelope = JSON.parse(JSON.stringify(result.structuredContent));
834
1079
  let candidate = candidateResult(result, sourceEnvelope);
835
1080
  const maximum = sourceEnvelope.metadata.limits.max_bytes;
836
- if (resultBytes(candidate) <= maximum)
837
- return candidate;
1081
+ // A tool that dropped rows for size wrote the budget that would hold the
1082
+ // next row from what it could measure, the payload alone. Only here is the
1083
+ // rest of the result known.
1084
+ const toolHint = truncationHintParts(sourceEnvelope.data);
1085
+ if (resultBytes(candidate) <= maximum) {
1086
+ if (toolHint === undefined || !Number.isFinite(toolHint.neededBytes))
1087
+ return candidate;
1088
+ const overhead = resultBytes(candidate) - Buffer.byteLength(JSON.stringify(sourceEnvelope.data), "utf8");
1089
+ const restated = JSON.parse(JSON.stringify(sourceEnvelope));
1090
+ synchronizePagingFields(restated.data, restated.metadata.pagination, restated.metadata.truncation, 0, (0, truncation_hint_js_1.neededResponseBytes)(toolHint.neededBytes + overhead, maximum, byteCap), byteCap, wholeWindowBytes(toolHint, overhead, maximum, byteCap));
1091
+ const restatedCandidate = candidateResult(result, restated);
1092
+ // The larger number can add a digit; if that tips the result over its
1093
+ // limit, fit it like any other result that is too big.
1094
+ if (resultBytes(restatedCandidate) <= maximum)
1095
+ return restatedCandidate;
1096
+ }
838
1097
  const sourceRecords = collectionArray(sourceEnvelope.data);
839
1098
  let envelope = sourceEnvelope;
840
1099
  if (sourceRecords) {
841
1100
  const originalRecordCount = sourceRecords.length;
842
1101
  const priorDropped = sourceEnvelope.metadata.truncation.dropped_records ?? 0;
843
- const envelopeForCount = (count) => {
1102
+ // While fitting, a hint carries the widest form of its byte budget (the
1103
+ // "exceeds the maximum" clause), which is never shorter than a number, so
1104
+ // a result that fits that way still fits with the real number.
1105
+ const envelopeForCount = (count, neededBytes, allBytes, withoutAdvice, widestHint) => {
844
1106
  const probe = JSON.parse(JSON.stringify(sourceEnvelope));
845
1107
  const probeRecords = collectionArray(probe.data);
846
1108
  if (!probeRecords)
@@ -848,41 +1110,115 @@ function finalizeSummaryResult(result) {
848
1110
  probeRecords.splice(count);
849
1111
  probe.metadata.record_count = count;
850
1112
  synchronizeRecordCount(probe.data, count);
1113
+ if (tool === "sn_syslog" && probe.metadata.pagination.mode === "none" && count < originalRecordCount) {
1114
+ (0, syslog_cursor_js_1.restateTailPageAfterFit)(probe.data, count);
1115
+ }
851
1116
  if (probe.metadata.pagination.mode === "offset") {
852
1117
  probe.metadata.pagination.returned = count;
853
1118
  if (count < originalRecordCount) {
854
- probe.metadata.pagination.recovery =
855
- "adjust_request_and_retry_same_offset";
1119
+ const paging = probe.metadata.pagination;
1120
+ paging.recovery = "adjust_request_and_retry_same_offset";
1121
+ paging.has_more = true;
1122
+ if (offsetPaged && count > 0) {
1123
+ paging.next_offset = paging.offset + count;
1124
+ }
1125
+ else {
1126
+ delete paging.next_offset;
1127
+ }
856
1128
  }
857
1129
  }
858
1130
  applyByteTruncation(probe, priorDropped + originalRecordCount - count);
859
- synchronizePagingFields(probe.data, probe.metadata.pagination, probe.metadata.truncation);
1131
+ synchronizePagingFields(probe.data, probe.metadata.pagination, probe.metadata.truncation, 0, neededBytes, byteCap, allBytes, withoutAdvice, widestHint);
860
1132
  return probe;
861
1133
  };
862
- let low = 0;
863
- let high = originalRecordCount;
1134
+ const widest = Number.POSITIVE_INFINITY;
1135
+ // The forms the hint can take while fitting, fullest first. The labelled
1136
+ // hint is longer than the bare one was, and at the smallest budgets the
1137
+ // envelope's own metadata leaves room for little more than the counts: the
1138
+ // page figure can go, then the field advice, which is the least that
1139
+ // still names the next row's budget. A narrower form is used only when no
1140
+ // row, not even zero, fits beside the fuller one. Each form's widest text
1141
+ // (the longest any real figures could make it) is what rows are sized
1142
+ // with, and the real text is rendered in the same form, so it is never
1143
+ // longer than the probe. The budget named for the next row is always
1144
+ // measured with the fullest form, so a call at that budget, which takes
1145
+ // the fullest form that fits, returns the row.
1146
+ const forms = toolHint === undefined
1147
+ ? [{ all: widest, withoutAdvice: false }]
1148
+ : [
1149
+ { all: widest, withoutAdvice: false },
1150
+ { all: null, withoutAdvice: false },
1151
+ { all: null, withoutAdvice: true },
1152
+ ];
864
1153
  let best = -1;
865
- while (low <= high) {
866
- const midpoint = Math.floor((low + high) / 2);
867
- const probe = candidateResult(result, envelopeForCount(midpoint));
868
- if (resultBytes(probe) <= maximum) {
869
- best = midpoint;
870
- low = midpoint + 1;
871
- }
872
- else {
873
- high = midpoint - 1;
1154
+ let form = forms[0];
1155
+ for (const candidateForm of forms) {
1156
+ let low = 0;
1157
+ let high = originalRecordCount;
1158
+ let fitted = -1;
1159
+ while (low <= high) {
1160
+ const midpoint = Math.floor((low + high) / 2);
1161
+ const probe = candidateResult(result, envelopeForCount(midpoint, widest, candidateForm.all, candidateForm.withoutAdvice, true));
1162
+ if (resultBytes(probe) <= maximum) {
1163
+ fitted = midpoint;
1164
+ low = midpoint + 1;
1165
+ }
1166
+ else {
1167
+ high = midpoint - 1;
1168
+ }
874
1169
  }
1170
+ // The first form that fits (zero rows is enough) is the one used.
1171
+ form = candidateForm;
1172
+ best = fitted;
1173
+ if (best >= 0)
1174
+ break;
875
1175
  }
876
1176
  // Collections are fitted only by removing complete rows. In particular,
877
1177
  // never shorten a field merely to force one row into the envelope: callers
878
1178
  // can retry this exact window with a narrower projection/larger budget,
879
1179
  // while next_offset (when present) remains the separately authoritative
880
1180
  // post-window resume point.
881
- envelope = envelopeForCount(Math.max(best, 0));
1181
+ const kept = Math.max(best, 0);
1182
+ envelope = envelopeForCount(kept, widest, form.all, form.withoutAdvice, true);
882
1183
  candidate = candidateResult(result, envelope);
883
- return resultBytes(candidate) <= maximum ? candidate : undefined;
1184
+ if (resultBytes(candidate) > maximum)
1185
+ return undefined;
1186
+ if (toolHint === undefined)
1187
+ return candidate;
1188
+ // The rows the tool already dropped are not here to measure, so the whole
1189
+ // window is its payload size, which the tool measured, plus what this
1190
+ // envelope adds around the rows. The envelope of a whole page carries no
1191
+ // truncation fields, so this is never too small.
1192
+ const overhead = resultBytes(candidate) - Buffer.byteLength(JSON.stringify(envelope.data), "utf8");
1193
+ // The budget that would hold one more row is measured here, with the
1194
+ // envelope's own cost in it, not guessed. When the fit dropped nothing
1195
+ // (the tool had already dropped every row, and only a narrower form
1196
+ // fitted) there is no row of ours to add: it is the tool's figure plus
1197
+ // the envelope's cost, as in the first branch.
1198
+ // With no row returned the envelope carries no `next_offset`, which the
1199
+ // first row brings with it, in the data and in the pagination metadata. The
1200
+ // zero-row overhead would then name a budget a few bytes short of one row.
1201
+ const overheadWithARow = (zeroOrMore, rows, base) => {
1202
+ if (rows > 0 || !offsetPaged)
1203
+ return base;
1204
+ const withRow = JSON.parse(JSON.stringify(zeroOrMore));
1205
+ const paging = withRow.metadata.pagination;
1206
+ if (paging.mode !== "offset")
1207
+ return base;
1208
+ paging.returned = 1;
1209
+ paging.next_offset = paging.offset + 1;
1210
+ synchronizePagingFields(withRow.data, withRow.metadata.pagination, withRow.metadata.truncation, 0, undefined, byteCap);
1211
+ return (resultBytes(candidateResult(result, withRow)) -
1212
+ Buffer.byteLength(JSON.stringify(withRow.data), "utf8"));
1213
+ };
1214
+ const needed = kept >= originalRecordCount
1215
+ ? (0, truncation_hint_js_1.neededResponseBytes)(toolHint.neededBytes + overheadWithARow(envelope, kept, overhead), maximum, byteCap)
1216
+ : (0, truncation_hint_js_1.neededResponseBytes)(resultBytes(candidateResult(result, envelopeForCount(kept + 1, widest, forms[0].all, false, true))), maximum, byteCap);
1217
+ const restated = candidateResult(result, envelopeForCount(kept, needed, form.all === null ? null : wholeWindowBytes(toolHint, overhead, maximum, byteCap), form.withoutAdvice));
1218
+ return resultBytes(restated) <= maximum ? restated : candidate;
884
1219
  }
885
- while (resultBytes(candidate) > maximum && truncateLongestString(envelope.data)) {
1220
+ while (resultBytes(candidate) > maximum &&
1221
+ (dropDerivedDiagram(envelope.data) || truncateLongestString(envelope.data))) {
886
1222
  applyByteTruncation(envelope, envelope.metadata.truncation.dropped_records ?? 0);
887
1223
  synchronizePagingFields(envelope.data, envelope.metadata.pagination, envelope.metadata.truncation);
888
1224
  candidate = candidateResult(result, envelope);