@onlyflows/servicenow-mcp 2.3.0-dev.2 → 2.3.0-rc.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 (61) hide show
  1. package/CHANGELOG.md +0 -253
  2. package/README.md +7 -141
  3. package/dist/client.d.ts +2 -14
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +10 -40
  6. package/dist/client.js.map +1 -1
  7. package/dist/encoded-query-policy.d.ts +0 -9
  8. package/dist/encoded-query-policy.d.ts.map +1 -1
  9. package/dist/encoded-query-policy.js +1 -19
  10. package/dist/encoded-query-policy.js.map +1 -1
  11. package/dist/http-runtime.js +0 -16
  12. package/dist/http-runtime.js.map +1 -1
  13. package/dist/metadata-cache.d.ts +7 -97
  14. package/dist/metadata-cache.d.ts.map +1 -1
  15. package/dist/metadata-cache.js +21 -283
  16. package/dist/metadata-cache.js.map +1 -1
  17. package/dist/setup-prompts.js +1 -1
  18. package/dist/setup-prompts.js.map +1 -1
  19. package/dist/setup.d.ts.map +1 -1
  20. package/dist/setup.js +1 -10
  21. package/dist/setup.js.map +1 -1
  22. package/dist/structured-query.d.ts +2 -61
  23. package/dist/structured-query.d.ts.map +1 -1
  24. package/dist/structured-query.js +35 -376
  25. package/dist/structured-query.js.map +1 -1
  26. package/dist/tools/codesearch.d.ts.map +1 -1
  27. package/dist/tools/codesearch.js +4 -24
  28. package/dist/tools/codesearch.js.map +1 -1
  29. package/dist/tools/flow-view-module.js +1 -1
  30. package/dist/tools/flow-view-module.js.map +1 -1
  31. package/dist/tools/get-module.js +1 -1
  32. package/dist/tools/get-module.js.map +1 -1
  33. package/dist/tools/index.d.ts.map +1 -1
  34. package/dist/tools/index.js +11 -24
  35. package/dist/tools/index.js.map +1 -1
  36. package/dist/tools/query-module.d.ts.map +1 -1
  37. package/dist/tools/query-module.js +59 -205
  38. package/dist/tools/query-module.js.map +1 -1
  39. package/dist/tools/result-envelope.d.ts +0 -311
  40. package/dist/tools/result-envelope.d.ts.map +1 -1
  41. package/dist/tools/result-envelope.js +31 -314
  42. package/dist/tools/result-envelope.js.map +1 -1
  43. package/dist/tools/schema-module.d.ts.map +1 -1
  44. package/dist/tools/schema-module.js +1 -1
  45. package/dist/tools/schema-module.js.map +1 -1
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.d.ts.map +1 -1
  48. package/dist/version.js +1 -1
  49. package/dist/version.js.map +1 -1
  50. package/docs/CLIENT-SETUP.md +1 -11
  51. package/docs/PRODUCTION-SECURITY.md +1 -17
  52. package/package.json +1 -1
  53. package/server.json +2 -2
  54. package/dist/call-metrics.d.ts +0 -42
  55. package/dist/call-metrics.d.ts.map +0 -1
  56. package/dist/call-metrics.js +0 -89
  57. package/dist/call-metrics.js.map +0 -1
  58. package/dist/tools/truncation-hint.d.ts +0 -125
  59. package/dist/tools/truncation-hint.d.ts.map +0 -1
  60. package/dist/tools/truncation-hint.js +0 -298
  61. package/dist/tools/truncation-hint.js.map +0 -1
@@ -1,125 +0,0 @@
1
- /**
2
- * The recovery hint on a byte-truncated record list.
3
- *
4
- * Two stages can drop rows from one response: the tool's own budget check and,
5
- * after the shared envelope adds its metadata, the envelope's fit. The first
6
- * writes the hint; the second changes how many rows were dropped and knows
7
- * what the envelope itself costs. The text is therefore built and parsed here,
8
- * in one place, so the envelope can rewrite the counts, the continuation (the
9
- * offset of the first row not returned, which is `next_offset`) and the byte
10
- * budget that would hold the next row from its final state, and the hint and
11
- * the fields beside it never disagree. Rendering and parsing are covered by
12
- * one round-trip test.
13
- *
14
- * The hint is a list of fixed clauses joined by "; ", each matched on its own
15
- * by an anchored pattern, so only text this module wrote is ever rewritten:
16
- *
17
- * Dropped 14/22; continue offset=8 limit=8; retry offset=0 with
18
- * fields="sys_id,name" or max_response_bytes=1500 (fits the next row) or
19
- * max_response_bytes=31500 (fits all 22).
20
- *
21
- * The two budgets are different numbers and the text says which is which:
22
- * the first holds one more row than this response did (each retry with it
23
- * buys a row), the second the whole window. The second is left out when it is
24
- * the first (one row dropped) or when it is more than the maximum.
25
- *
26
- * @module truncation-hint
27
- */
28
- /**
29
- * `max_response_bytes` that would hold the next row: the measured size of the
30
- * response with that row (`measured`) plus a small margin, rounded up to a
31
- * whole {@link NEEDED_BYTES_STEP} (but never past `cap`), and always above the
32
- * budget just used (`current`). Infinity when that is more than `cap`: no
33
- * value the caller may use would hold the row. `cap` is the largest budget the
34
- * schema accepts, or less when a raw-read rule holds the call to a smaller one.
35
- */
36
- export declare function neededResponseBytes(measured: number, current: number, cap?: number): number;
37
- export interface TruncationHintParts {
38
- /** Rows dropped from the window the caller asked for. */
39
- readonly dropped: number;
40
- /** Rows the window held before any were dropped. */
41
- readonly total: number;
42
- /**
43
- * The window's offset: re-read it with a narrower request to get every
44
- * dropped row in one response. The offset to continue at (`next_offset`)
45
- * is not stored; it is this offset plus the rows that were returned.
46
- */
47
- readonly offset: number;
48
- /**
49
- * How to shrink the rows: a `fields="..."` or `response_format="..."`
50
- * suggestion. Absent when none applies; the hint then offers the lower
51
- * `limit` (while a row fits) and the byte budget.
52
- */
53
- readonly advice?: string;
54
- /**
55
- * The `max_response_bytes` that would hold at least the next row, or
56
- * Infinity when that is more than the maximum budget.
57
- */
58
- readonly neededBytes: number;
59
- /**
60
- * The `max_response_bytes` that would hold every row of the window
61
- * (`total`), when that is no more than the maximum budget; absent when it
62
- * is more. When one row was dropped the next row is the whole remainder, so
63
- * this is `neededBytes` and is written once. Infinity stands for the widest
64
- * rendering, which a fit uses to leave room for the real text and which is
65
- * never parsed back.
66
- */
67
- readonly allBytes?: number;
68
- /**
69
- * Render the longest text these parts could ever take, for a fit to size
70
- * rows with: the "exceeds the maximum" clause and a 7-digit next-row figure
71
- * together (no real hint has both), and the 7-digit page figure when
72
- * `allBytes` is Infinity. Never written to a caller as it is, and never
73
- * parsed back.
74
- */
75
- readonly widest?: boolean;
76
- /**
77
- * The largest `max_response_bytes` the caller may use, named when the next
78
- * row exceeds it. Defaults to the schema maximum; a raw-read rule can set a
79
- * smaller one. Only read back from a hint's "exceeds the maximum" clause.
80
- */
81
- readonly capBytes?: number;
82
- }
83
- /**
84
- * Render the hint. When no row is left, the row itself exceeds the budget, so
85
- * a lower limit cannot help and the single-record read is offered instead.
86
- * Field advice that would push the hint past its length limit, in its widest
87
- * form, is left out, so the hint always parses back and a longer real text
88
- * never replaces a shorter one that was used to size the rows.
89
- */
90
- export declare function renderTruncationHint(parts: TruncationHintParts): string;
91
- /** Read back a hint {@link renderTruncationHint} wrote; anything else is undefined. */
92
- export declare function parseTruncationHint(hint: string): TruncationHintParts | undefined;
93
- /**
94
- * Restate a hint for the response's final state: how many rows were dropped
95
- * from the window, so where to continue and which `limit` fits, and, when the
96
- * caller supplies it, the byte budget that would hold the next row. Only hints
97
- * this module wrote are touched; any other text is returned as it came.
98
- */
99
- export declare function refreshTruncationHint(hint: string, final: {
100
- readonly dropped: number;
101
- readonly returned: number;
102
- readonly neededBytes?: number;
103
- /**
104
- * The budget for the whole window: a number to name it, null when it is
105
- * more than the maximum (so it is left out), absent to keep the hint's own.
106
- */
107
- readonly allBytes?: number | null;
108
- /** Leave the field advice out, as a fit does when the result is too tight to carry it. */
109
- readonly withoutAdvice?: boolean;
110
- /** Render the widest text instead (see {@link TruncationHintParts.widest}). */
111
- readonly widest?: boolean;
112
- /** The cap to name if the next row exceeds it; else the one the hint named. */
113
- readonly capBytes?: number;
114
- }): string;
115
- /**
116
- * Restate a continuation hint for the final paging state: the offset of the
117
- * first row not returned, or, when no row fit and there is none, the plain
118
- * instruction that the request must change. Text that is not a continuation
119
- * hint comes back as it was.
120
- */
121
- export declare function restateContinuationHint(hint: string, final: {
122
- readonly offset: number;
123
- readonly nextOffset?: number;
124
- }): string;
125
- //# sourceMappingURL=truncation-hint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncation-hint.d.ts","sourceRoot":"","sources":["../../src/tools/truncation-hint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,GACA,MAAM,CAiBR;AAWD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D,MAAM,CAWR"}
@@ -1,298 +0,0 @@
1
- "use strict";
2
- /**
3
- * The recovery hint on a byte-truncated record list.
4
- *
5
- * Two stages can drop rows from one response: the tool's own budget check and,
6
- * after the shared envelope adds its metadata, the envelope's fit. The first
7
- * writes the hint; the second changes how many rows were dropped and knows
8
- * what the envelope itself costs. The text is therefore built and parsed here,
9
- * in one place, so the envelope can rewrite the counts, the continuation (the
10
- * offset of the first row not returned, which is `next_offset`) and the byte
11
- * budget that would hold the next row from its final state, and the hint and
12
- * the fields beside it never disagree. Rendering and parsing are covered by
13
- * one round-trip test.
14
- *
15
- * The hint is a list of fixed clauses joined by "; ", each matched on its own
16
- * by an anchored pattern, so only text this module wrote is ever rewritten:
17
- *
18
- * Dropped 14/22; continue offset=8 limit=8; retry offset=0 with
19
- * fields="sys_id,name" or max_response_bytes=1500 (fits the next row) or
20
- * max_response_bytes=31500 (fits all 22).
21
- *
22
- * The two budgets are different numbers and the text says which is which:
23
- * the first holds one more row than this response did (each retry with it
24
- * buys a row), the second the whole window. The second is left out when it is
25
- * the first (one row dropped) or when it is more than the maximum.
26
- *
27
- * @module truncation-hint
28
- */
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.neededResponseBytes = neededResponseBytes;
31
- exports.renderTruncationHint = renderTruncationHint;
32
- exports.parseTruncationHint = parseTruncationHint;
33
- exports.refreshTruncationHint = refreshTruncationHint;
34
- exports.restateContinuationHint = restateContinuationHint;
35
- const utils_js_1 = require("../utils.js");
36
- const HINT_MAX_LENGTH = 600;
37
- /**
38
- * Bytes added to the measured size of the next row's response before it is
39
- * offered as `max_response_bytes`, so that a budget with a longer digit count
40
- * or a slightly longer hint still holds it.
41
- */
42
- const NEEDED_BYTES_SLACK = 64;
43
- const NEEDED_BYTES_STEP = 100;
44
- /**
45
- * `max_response_bytes` that would hold the next row: the measured size of the
46
- * response with that row (`measured`) plus a small margin, rounded up to a
47
- * whole {@link NEEDED_BYTES_STEP} (but never past `cap`), and always above the
48
- * budget just used (`current`). Infinity when that is more than `cap`: no
49
- * value the caller may use would hold the row. `cap` is the largest budget the
50
- * schema accepts, or less when a raw-read rule holds the call to a smaller one.
51
- */
52
- function neededResponseBytes(measured, current, cap = utils_js_1.MAX_RESPONSE_BYTES_MAX) {
53
- const padded = Math.max(measured + NEEDED_BYTES_SLACK, current + 1, utils_js_1.MAX_RESPONSE_BYTES_MIN);
54
- if (padded > cap)
55
- return Number.POSITIVE_INFINITY;
56
- return Math.min(Math.ceil(padded / NEEDED_BYTES_STEP) * NEEDED_BYTES_STEP, cap);
57
- }
58
- /** What a hint names for the rows that fit: the continuation and the `limit` to use. */
59
- function returnedRows(parts) {
60
- return parts.total - parts.dropped;
61
- }
62
- const EMPTY_CLAUSE = "row too large";
63
- const NEXT_ROW_NOTE = " (fits the next row)";
64
- function allRowsNote(total) {
65
- return ` (fits all ${total})`;
66
- }
67
- const SN_GET_OPTION = "sn_get";
68
- function overMaximumClause(cap) {
69
- return `the next row exceeds the maximum max_response_bytes (${cap})`;
70
- }
71
- function renderHint(parts, withAdvice) {
72
- const returned = returnedRows(parts);
73
- const empty = returned <= 0;
74
- const over = !Number.isFinite(parts.neededBytes) || parts.widest === true;
75
- // With one row dropped the next row is the whole remainder: one figure.
76
- const nextRow = parts.widest === true
77
- ? `max_response_bytes=${utils_js_1.MAX_RESPONSE_BYTES_MAX}${NEXT_ROW_NOTE}`
78
- : Number.isFinite(parts.neededBytes)
79
- ? `max_response_bytes=${parts.neededBytes}${NEXT_ROW_NOTE}`
80
- : undefined;
81
- const allBytes = parts.dropped > 1 ? parts.allBytes : undefined;
82
- const options = [
83
- withAdvice ? parts.advice : undefined,
84
- nextRow,
85
- allBytes === undefined
86
- ? undefined
87
- // Infinity is the widest form, used while fitting (see finalizeSummaryResult).
88
- : `max_response_bytes=${Number.isFinite(allBytes) ? allBytes : utils_js_1.MAX_RESPONSE_BYTES_MAX}${allRowsNote(parts.total)}`,
89
- // When no row fits, a narrower page cannot help; the single-record read can.
90
- empty ? SN_GET_OPTION : undefined,
91
- ].filter((option) => option !== undefined);
92
- const clauses = [`Dropped ${parts.dropped}/${parts.total}`];
93
- if (empty)
94
- clauses.push(EMPTY_CLAUSE);
95
- else
96
- clauses.push(`continue offset=${parts.offset + returned} limit=${returned}`);
97
- if (over)
98
- clauses.push(overMaximumClause(parts.capBytes ?? utils_js_1.MAX_RESPONSE_BYTES_MAX));
99
- if (options.length > 0) {
100
- clauses.push(`retry offset=${parts.offset} with ${options.join(" or ")}`);
101
- }
102
- return `${clauses.join("; ")}.`;
103
- }
104
- /**
105
- * Render the hint. When no row is left, the row itself exceeds the budget, so
106
- * a lower limit cannot help and the single-record read is offered instead.
107
- * Field advice that would push the hint past its length limit, in its widest
108
- * form, is left out, so the hint always parses back and a longer real text
109
- * never replaces a shorter one that was used to size the rows.
110
- */
111
- function renderTruncationHint(parts) {
112
- // Whether the advice fits is decided once, from the widest rendering of
113
- // these parts (the "exceeds the maximum" clause with a 7-digit next-row
114
- // figure, and a 7-digit page figure: no real figures make a longer text). A
115
- // fit sizes rows with that widest text and then swaps in the real one, so the
116
- // two must make the same choice: if the widest dropped the advice and the
117
- // real text kept it, the real text could be hundreds of characters longer
118
- // than the one the rows were sized for. The page figure is always in this
119
- // text, whether or not the real text has one (it has none when the page is
120
- // over the cap, and a form without it is sized with the same decision), so
121
- // the choice depends only on what the probe and the real text share.
122
- const widest = renderHint({
123
- ...parts,
124
- widest: true,
125
- neededBytes: Number.POSITIVE_INFINITY,
126
- allBytes: Number.POSITIVE_INFINITY,
127
- }, true);
128
- return renderHint(parts, widest.length <= HINT_MAX_LENGTH);
129
- }
130
- const DROPPED_CLAUSE = /^Dropped (\d+)\/(\d+)$/u;
131
- const CONTINUE_CLAUSE = /^continue offset=(\d+) limit=(\d+)$/u;
132
- const RETRY_CLAUSE = /^retry offset=(\d+) with (.+)$/u;
133
- const ADVICE_OPTION = /^(?:fields="[a-z][a-z0-9_]*(?:,[a-z][a-z0-9_]*)*"|response_format="concise")$/u;
134
- const NEXT_ROW_OPTION = /^max_response_bytes=([1-9]\d{3,6}) \(fits the next row\)$/u;
135
- const ALL_ROWS_OPTION = /^max_response_bytes=([1-9]\d{3,6}) \(fits all ([1-9]\d{0,15})\)$/u;
136
- const OVER_MAXIMUM = /^the next row exceeds the maximum max_response_bytes \(([1-9]\d{3,6})\)$/u;
137
- /** A byte value the schema could accept: 1000 to 1,000,000. */
138
- function budgetValue(digits) {
139
- const value = Number(digits);
140
- return Number.isSafeInteger(value) && value >= utils_js_1.MAX_RESPONSE_BYTES_MIN && value <= utils_js_1.MAX_RESPONSE_BYTES_MAX
141
- ? value
142
- : undefined;
143
- }
144
- /** Read back a hint {@link renderTruncationHint} wrote; anything else is undefined. */
145
- function parseTruncationHint(hint) {
146
- if (hint.length > HINT_MAX_LENGTH || !hint.endsWith("."))
147
- return undefined;
148
- const clauses = hint.slice(0, -1).split("; ");
149
- let index = 0;
150
- const dropped = DROPPED_CLAUSE.exec(clauses[index++] ?? "");
151
- if (dropped === null)
152
- return undefined;
153
- const droppedCount = Number(dropped[1]);
154
- const total = Number(dropped[2]);
155
- if (!Number.isSafeInteger(droppedCount) || !Number.isSafeInteger(total) || droppedCount > total) {
156
- return undefined;
157
- }
158
- const returned = total - droppedCount;
159
- const empty = returned === 0;
160
- let offset;
161
- if (empty) {
162
- if (clauses[index++] !== EMPTY_CLAUSE)
163
- return undefined;
164
- }
165
- else {
166
- const next = CONTINUE_CLAUSE.exec(clauses[index++] ?? "");
167
- // The clause restates numbers the counts already fix; a hint that
168
- // disagrees with itself was not written here.
169
- if (next === null || Number(next[2]) !== returned)
170
- return undefined;
171
- offset = Number(next[1]) - returned;
172
- }
173
- let neededBytes;
174
- let allBytes;
175
- let capBytes;
176
- const over = OVER_MAXIMUM.exec(clauses[index] ?? "");
177
- if (over !== null) {
178
- capBytes = budgetValue(over[1]);
179
- if (capBytes === undefined)
180
- return undefined;
181
- neededBytes = Number.POSITIVE_INFINITY;
182
- index += 1;
183
- }
184
- let advice;
185
- let sawSnGet = false;
186
- const retry = clauses[index] === undefined ? null : RETRY_CLAUSE.exec(clauses[index] ?? "");
187
- if (retry !== null) {
188
- index += 1;
189
- const retryOffset = Number(retry[1]);
190
- if (offset !== undefined && offset !== retryOffset)
191
- return undefined;
192
- offset = retryOffset;
193
- for (const option of (retry[2] ?? "").split(" or ")) {
194
- const next = NEXT_ROW_OPTION.exec(option);
195
- const all = next === null ? ALL_ROWS_OPTION.exec(option) : null;
196
- if (next !== null) {
197
- const value = budgetValue(next[1]);
198
- if (neededBytes !== undefined || value === undefined)
199
- return undefined;
200
- neededBytes = value;
201
- }
202
- else if (all !== null) {
203
- const value = budgetValue(all[1]);
204
- // The count restates the window; the figure must follow the next-row
205
- // one, be no smaller, and exist only when more than one row is left.
206
- if (allBytes !== undefined ||
207
- value === undefined ||
208
- Number(all[2]) !== total ||
209
- droppedCount < 2 ||
210
- neededBytes === undefined ||
211
- !Number.isFinite(neededBytes) ||
212
- value < neededBytes) {
213
- return undefined;
214
- }
215
- allBytes = value;
216
- }
217
- else if (ADVICE_OPTION.test(option) && advice === undefined) {
218
- advice = option;
219
- }
220
- else if (option === SN_GET_OPTION && !sawSnGet) {
221
- sawSnGet = true;
222
- }
223
- else {
224
- return undefined;
225
- }
226
- }
227
- }
228
- if (index !== clauses.length ||
229
- offset === undefined ||
230
- neededBytes === undefined ||
231
- sawSnGet !== empty ||
232
- !Number.isSafeInteger(offset) ||
233
- offset < 0) {
234
- return undefined;
235
- }
236
- // One row dropped: the next row is the whole remainder, written once.
237
- if (droppedCount === 1 && Number.isFinite(neededBytes))
238
- allBytes = neededBytes;
239
- return {
240
- dropped: droppedCount,
241
- total,
242
- offset,
243
- ...(advice === undefined ? {} : { advice }),
244
- neededBytes,
245
- ...(allBytes === undefined ? {} : { allBytes }),
246
- ...(capBytes === undefined ? {} : { capBytes }),
247
- };
248
- }
249
- /**
250
- * Restate a hint for the response's final state: how many rows were dropped
251
- * from the window, so where to continue and which `limit` fits, and, when the
252
- * caller supplies it, the byte budget that would hold the next row. Only hints
253
- * this module wrote are touched; any other text is returned as it came.
254
- */
255
- function refreshTruncationHint(hint, final) {
256
- const parts = parseTruncationHint(hint);
257
- if (parts === undefined)
258
- return hint;
259
- return renderTruncationHint({
260
- dropped: final.dropped,
261
- total: final.dropped + final.returned,
262
- offset: parts.offset,
263
- ...(parts.advice === undefined || final.withoutAdvice === true ? {} : { advice: parts.advice }),
264
- neededBytes: final.neededBytes ?? parts.neededBytes,
265
- ...(final.widest === true ? { widest: true } : {}),
266
- ...(final.allBytes === null || (final.allBytes ?? parts.allBytes) === undefined
267
- ? {}
268
- : { allBytes: (final.allBytes ?? parts.allBytes) }),
269
- ...(final.capBytes ?? parts.capBytes) === undefined
270
- ? {}
271
- : { capBytes: (final.capBytes ?? parts.capBytes) },
272
- });
273
- }
274
- /**
275
- * The continuation hint a paging tool writes when nothing was dropped:
276
- * "More records available. Call sn_query again with offset=22." (an
277
- * all-fields notice may follow). A tool writes it from the page it fetched, so
278
- * when the shared envelope later drops rows for size, its offset is stale.
279
- */
280
- const CONTINUATION_HINT = /^(More records available\. Call sn_[a-z_]+ again with offset=)\d+(\.)((?: .*)?)$/su;
281
- /**
282
- * Restate a continuation hint for the final paging state: the offset of the
283
- * first row not returned, or, when no row fit and there is none, the plain
284
- * instruction that the request must change. Text that is not a continuation
285
- * hint comes back as it was.
286
- */
287
- function restateContinuationHint(hint, final) {
288
- const match = CONTINUATION_HINT.exec(hint);
289
- if (match === null)
290
- return hint;
291
- const notice = match[3] ?? "";
292
- if (final.nextOffset === undefined) {
293
- return ("More records available, but no row fit; adjust the request (fewer fields, " +
294
- `a lower limit or a higher max_response_bytes) and retry offset=${final.offset}.${notice}`);
295
- }
296
- return `${match[1]}${final.nextOffset}.${notice}`;
297
- }
298
- //# sourceMappingURL=truncation-hint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncation-hint.js","sourceRoot":"","sources":["../../src/tools/truncation-hint.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAsBH,kDAQC;AAuGD,oDAqBC;AAoBD,kDA8FC;AAQD,sDAmCC;AAiBD,0DAcC;AApVD,0CAA6E;AAE7E,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,QAAgB,EAChB,OAAe,EACf,MAAc,iCAAsB;IAEpC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,kBAAkB,EAAE,OAAO,GAAG,CAAC,EAAE,iCAAsB,CAAC,CAAC;IAC5F,IAAI,MAAM,GAAG,GAAG;QAAE,OAAO,MAAM,CAAC,iBAAiB,CAAC;IAClD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,CAAC;AAClF,CAAC;AAiDD,wFAAwF;AACxF,SAAS,YAAY,CAAC,KAA0B;IAC9C,OAAO,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;AACrC,CAAC;AAED,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAC7C,SAAS,WAAW,CAAC,KAAa;I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