iit-mcp-autotask 0.54.2

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 (164) hide show
  1. package/.env.example +123 -0
  2. package/LICENSE +21 -0
  3. package/README.md +788 -0
  4. package/capabilities.json +487 -0
  5. package/dist/access/gate.d.ts +34 -0
  6. package/dist/access/gate.js +76 -0
  7. package/dist/access/grants.d.ts +20 -0
  8. package/dist/access/grants.js +35 -0
  9. package/dist/access/write-env.d.ts +41 -0
  10. package/dist/access/write-env.js +166 -0
  11. package/dist/auth.d.ts +74 -0
  12. package/dist/auth.js +129 -0
  13. package/dist/base-hosts.d.ts +38 -0
  14. package/dist/base-hosts.js +70 -0
  15. package/dist/config/load.d.ts +28 -0
  16. package/dist/config/load.js +105 -0
  17. package/dist/config/schema.d.ts +166 -0
  18. package/dist/config/schema.js +311 -0
  19. package/dist/credential.d.ts +28 -0
  20. package/dist/credential.js +32 -0
  21. package/dist/doctor.d.ts +112 -0
  22. package/dist/doctor.js +154 -0
  23. package/dist/http-guard.d.ts +57 -0
  24. package/dist/http-guard.js +134 -0
  25. package/dist/http.d.ts +50 -0
  26. package/dist/http.js +290 -0
  27. package/dist/lifecycle.d.ts +29 -0
  28. package/dist/lifecycle.js +52 -0
  29. package/dist/logger.d.ts +26 -0
  30. package/dist/logger.js +28 -0
  31. package/dist/main.d.ts +12 -0
  32. package/dist/main.js +283 -0
  33. package/dist/policy.d.ts +54 -0
  34. package/dist/policy.js +80 -0
  35. package/dist/tools/aggregate.d.ts +16 -0
  36. package/dist/tools/aggregate.js +64 -0
  37. package/dist/tools/capabilities-manifest.d.ts +4 -0
  38. package/dist/tools/capabilities-manifest.js +94 -0
  39. package/dist/tools/catalog-data.d.ts +116 -0
  40. package/dist/tools/catalog-data.js +207 -0
  41. package/dist/tools/clock.d.ts +17 -0
  42. package/dist/tools/clock.js +43 -0
  43. package/dist/tools/composites.d.ts +36 -0
  44. package/dist/tools/composites.js +305 -0
  45. package/dist/tools/context/client.d.ts +41 -0
  46. package/dist/tools/context/client.js +139 -0
  47. package/dist/tools/context/derive.d.ts +9 -0
  48. package/dist/tools/context/derive.js +32 -0
  49. package/dist/tools/context/scope.d.ts +24 -0
  50. package/dist/tools/context/scope.js +180 -0
  51. package/dist/tools/context/types.d.ts +141 -0
  52. package/dist/tools/context/types.js +2 -0
  53. package/dist/tools/dispatch.d.ts +78 -0
  54. package/dist/tools/dispatch.js +272 -0
  55. package/dist/tools/field-pointer.d.ts +25 -0
  56. package/dist/tools/field-pointer.js +45 -0
  57. package/dist/tools/guide.d.ts +30 -0
  58. package/dist/tools/guide.js +97 -0
  59. package/dist/tools/lists.d.ts +9 -0
  60. package/dist/tools/lists.js +205 -0
  61. package/dist/tools/meta.d.ts +22 -0
  62. package/dist/tools/meta.js +709 -0
  63. package/dist/tools/output-file.d.ts +26 -0
  64. package/dist/tools/output-file.js +140 -0
  65. package/dist/tools/rank.d.ts +21 -0
  66. package/dist/tools/rank.js +57 -0
  67. package/dist/tools/reasons.d.ts +33 -0
  68. package/dist/tools/reasons.js +121 -0
  69. package/dist/tools/register.d.ts +23 -0
  70. package/dist/tools/register.js +50 -0
  71. package/dist/tools/resolves.d.ts +28 -0
  72. package/dist/tools/resolves.js +399 -0
  73. package/dist/tools/results/envelope.d.ts +55 -0
  74. package/dist/tools/results/envelope.js +63 -0
  75. package/dist/tools/results/errors.d.ts +147 -0
  76. package/dist/tools/results/errors.js +384 -0
  77. package/dist/tools/results/untrusted.d.ts +129 -0
  78. package/dist/tools/results/untrusted.js +218 -0
  79. package/dist/tools/revenue-rollup.d.ts +8 -0
  80. package/dist/tools/revenue-rollup.js +112 -0
  81. package/dist/tools/schemas.d.ts +467 -0
  82. package/dist/tools/schemas.js +444 -0
  83. package/dist/tools/scope-guard.d.ts +2 -0
  84. package/dist/tools/scope-guard.js +11 -0
  85. package/dist/tools/server-version.d.ts +3 -0
  86. package/dist/tools/server-version.js +14 -0
  87. package/dist/tools/server.d.ts +92 -0
  88. package/dist/tools/server.js +170 -0
  89. package/dist/tools/surface.d.ts +37 -0
  90. package/dist/tools/surface.js +94 -0
  91. package/dist/tools/tsv.d.ts +52 -0
  92. package/dist/tools/tsv.js +95 -0
  93. package/dist/tools/write/apply.d.ts +40 -0
  94. package/dist/tools/write/apply.js +500 -0
  95. package/dist/tools/write/checks.d.ts +39 -0
  96. package/dist/tools/write/checks.js +137 -0
  97. package/dist/tools/write/common.d.ts +23 -0
  98. package/dist/tools/write/common.js +33 -0
  99. package/dist/tools/write/facts.d.ts +52 -0
  100. package/dist/tools/write/facts.js +151 -0
  101. package/dist/tools/write/outcome.d.ts +23 -0
  102. package/dist/tools/write/outcome.js +67 -0
  103. package/dist/tools/write/parse.d.ts +37 -0
  104. package/dist/tools/write/parse.js +166 -0
  105. package/dist/tools/write/payload.d.ts +44 -0
  106. package/dist/tools/write/payload.js +119 -0
  107. package/dist/tools/write/preview.d.ts +3 -0
  108. package/dist/tools/write/preview.js +317 -0
  109. package/dist/tools/write/snapshot.d.ts +68 -0
  110. package/dist/tools/write/snapshot.js +360 -0
  111. package/dist/tools/write-guidance.d.ts +174 -0
  112. package/dist/tools/write-guidance.js +317 -0
  113. package/dist/tools/write.d.ts +9 -0
  114. package/dist/tools/write.js +10 -0
  115. package/dist/write/canonical.d.ts +12 -0
  116. package/dist/write/canonical.js +31 -0
  117. package/dist/write/evaluate.d.ts +77 -0
  118. package/dist/write/evaluate.js +91 -0
  119. package/dist/write/hard-rules.d.ts +49 -0
  120. package/dist/write/hard-rules.js +48 -0
  121. package/dist/write/runtime.d.ts +37 -0
  122. package/dist/write/runtime.js +72 -0
  123. package/dist/write/store/audit-log.d.ts +13 -0
  124. package/dist/write/store/audit-log.js +25 -0
  125. package/dist/write/store/constants.d.ts +34 -0
  126. package/dist/write/store/constants.js +35 -0
  127. package/dist/write/store/files.d.ts +44 -0
  128. package/dist/write/store/files.js +157 -0
  129. package/dist/write/store/heartbeat.d.ts +9 -0
  130. package/dist/write/store/heartbeat.js +65 -0
  131. package/dist/write/store/ledger.d.ts +15 -0
  132. package/dist/write/store/ledger.js +86 -0
  133. package/dist/write/store/lifecycle.d.ts +35 -0
  134. package/dist/write/store/lifecycle.js +114 -0
  135. package/dist/write/store/lock.d.ts +97 -0
  136. package/dist/write/store/lock.js +464 -0
  137. package/dist/write/store/op-lock.d.ts +13 -0
  138. package/dist/write/store/op-lock.js +175 -0
  139. package/dist/write/store/plan-store.d.ts +7 -0
  140. package/dist/write/store/plan-store.js +48 -0
  141. package/dist/write/store/plans.d.ts +5 -0
  142. package/dist/write/store/plans.js +19 -0
  143. package/dist/write/store/types.d.ts +195 -0
  144. package/dist/write/store/types.js +2 -0
  145. package/dist/write/store.d.ts +6 -0
  146. package/dist/write/store.js +182 -0
  147. package/examples/agentgateway.write-gate.yaml +29 -0
  148. package/package.json +71 -0
  149. package/server.json +69 -0
  150. package/skills/ar-aging.md +65 -0
  151. package/skills/company-360.md +69 -0
  152. package/skills/contract-profitability.md +65 -0
  153. package/skills/crm-management.md +87 -0
  154. package/skills/filter-semantics.md +75 -0
  155. package/skills/invoice-export.md +61 -0
  156. package/skills/log-time-entry.md +77 -0
  157. package/skills/non-chargeable-work.md +67 -0
  158. package/skills/portfolio-margin.md +66 -0
  159. package/skills/recurring-revenue.md +65 -0
  160. package/skills/revenue-rollup.md +65 -0
  161. package/skills/slim-reads.md +67 -0
  162. package/skills/ticket-triage.md +64 -0
  163. package/skills/unbilled-work-review.md +66 -0
  164. package/skills/wip-hours.md +68 -0
@@ -0,0 +1,147 @@
1
+ import { type ToolReturn } from './envelope.js';
2
+ /** Hard cap on the model-facing error text; see {@link boundErrorMessage}. */
3
+ export declare const MAX_ERROR_MESSAGE_CHARS = 200;
4
+ /** Per-string free-text cap inside a served `vendorError` (V23/FT-5). */
5
+ export declare const VENDOR_FIELD_MAX = 200;
6
+ /** Total serialized cap for the served `vendorError` (V23/FT-5). */
7
+ export declare const VENDOR_ERROR_MAX = 2000;
8
+ /** The value-free marker a credential echo is replaced with (never the echoed value). */
9
+ export declare const SECRET_MARKER = "[REDACTED]";
10
+ /**
11
+ * The SDK's "no shape anomaly" 401 diagnostic literal(s) (node-autotask 0.8.0, chunk-5QVXRT3A:
12
+ * `DIAGNOSTIC_NO_ANOMALY`). `credentialDiagnosticDetails` stamps it on EVERY 401 whose values were
13
+ * clean, so it must never be read as an anomaly statement: the 401 branch treats an exact match as
14
+ * ABSENT and keeps the pre-hardening envelope byte-identical. Exact match only — never a substring
15
+ * test, so a diagnostic that merely mentions the clean phrase still crosses as an anomaly.
16
+ */
17
+ export declare const ANOMALY_FREE_DIAGNOSTIC_LITERALS: ReadonlySet<string>;
18
+ /** The host part of a request URL, or `undefined` when there is none or it cannot be parsed. */
19
+ export declare function hostFromUrl(url: string | undefined): string | undefined;
20
+ /**
21
+ * The response SHAPE — the only upstream-derived text a vendor-side error (an `httpStatus` is
22
+ * present) serves as `message`: status + dialed host, never the vendor's own words.
23
+ */
24
+ export declare function shapeMessage(status: number, url: string | undefined): string;
25
+ /**
26
+ * Bound the upstream-derived text the SDK carries in `err.message`.
27
+ *
28
+ * The SDK puts a string upstream body into `err.message` verbatim by design (an edge-served
29
+ * HTML page is "surfaced verbatim rather than rejected"): a multi-kilobyte page has no business
30
+ * in a model-facing envelope. Text at or under the cap crosses unchanged (every fixed envelope
31
+ * is short, so their bytes never change); longer text is replaced by the SHAPE of the response —
32
+ * status and dialed host — never by its body.
33
+ */
34
+ export declare function boundErrorMessage(raw: string, url: string | undefined): string;
35
+ /**
36
+ * Value-based scrub (V23/FT-5): a string that carries ANY of the request's own credential values
37
+ * (the 3-tuple + the impersonation id) is a credential echo, not data — the whole value is
38
+ * replaced with the value-free marker. The SDK's redaction is name-based (its documented no-op
39
+ * on free text), so only this value-based pass can catch a vendor body that echoes a request
40
+ * value in a field the name list does not know. Also reused by the http last-resort error log
41
+ * (security R2).
42
+ */
43
+ export declare function scrubSecrets(value: string, secrets: readonly string[]): string;
44
+ /**
45
+ * Bound + scrub the vendor body the SDK carries under `vendorError` (V23/FT-5): the served
46
+ * envelope is typed-only — never the raw body, never a request's own credential value.
47
+ *
48
+ * - a STRING body (an edge-served HTML page) serves its SHAPE only (`{type, bytes, truncated}`);
49
+ * - an OBJECT body keeps its structure, but every string is scrubbed (credential echo → the
50
+ * marker) and capped, and the whole thing is dropped to a shape descriptor when it would
51
+ * exceed the total cap.
52
+ */
53
+ export declare function boundVendorError(vendorError: unknown, secrets: readonly string[]): unknown;
54
+ /**
55
+ * The clean credential-refusal answer: the exact `UNAUTHORIZED` 401 envelope every tool returns
56
+ * when the vendor rejects the identity. Fixed rather than echoed: the upstream auth message is
57
+ * vendor text and may name the resource the identity may not read, so only the code, the status
58
+ * and the stable message cross this boundary.
59
+ */
60
+ export declare function unauthorizedPayload(correlationId?: string, shapeDiagnostic?: string): Record<string, unknown>;
61
+ export declare function unauthorizedContent(correlationId?: string, shapeDiagnostic?: string): ToolReturn;
62
+ /**
63
+ * The vendor-401 shape diagnostic (issue #4c), value-free.
64
+ *
65
+ * node-autotask 0.8.0 stamps a `details.diagnostic` on a vendor 401 (code `UNAUTHORIZED`: a typed `UnauthorizedError`
66
+ * before SDK 0.46.0, a plain `AutotaskError` since) whenever it knows
67
+ * the shape of the values that went out. For an ANOMALY it is the value-free statement "sent value
68
+ * shows shell-quoting/line-break artifacts (<problem>) — check your env load", consumed verbatim. For
69
+ * CLEAN values it is the fixed no-anomaly literal, which is NOT an anomaly report and is treated as
70
+ * absent (F1), so a genuine vendor-side 401 keeps the legacy envelope. When the SDK carries no diagnostic — an older SDK, an error built by a fixture — this
71
+ * server's own view of the request's credential values is the second source: a shape anomaly there
72
+ * makes the same statement in this package's own words. An interpreter-backed value is never
73
+ * reported by name (`credentialShapeProblem` describes it value-free as "no shape problem").
74
+ *
75
+ * Returns `undefined` for clean values, which keeps the envelope byte-identical to the pinned one.
76
+ *
77
+ * The SDK stamps a diagnostic on EVERY 401 it maps (node-autotask 0.8.0, chunk-5QVXRT3A:
78
+ * `credentialDiagnosticDetails` -> `credential.allValuesClean ? NO_ANOMALY : ANOMALY(problem)`), so
79
+ * the no-anomaly literal is the SDK saying "clean" — not an anomaly report. It is recognised by
80
+ * EXACT match against the pinned literals below and treated as ABSENT, so a genuine vendor-side 401
81
+ * on clean values keeps the pre-hardening envelope byte-for-byte. Only a diagnostic that is NOT one
82
+ * of the known no-anomaly literals is consumed as an anomaly statement.
83
+ */
84
+ export declare function isAnomalyFreeDiagnostic(diagnostic: string): boolean;
85
+ export declare function vendorShapeDiagnostic(err: unknown, secrets: readonly string[]): string | undefined;
86
+ /**
87
+ * True when the SDK error is an upstream credential refusal (401/403-class). The typed status
88
+ * decides: the SDK keeps a machine-shaped vendor code (e.g. `AUTH_401`) in place of
89
+ * UNAUTHORIZED/FORBIDDEN, so the code alone does not. Category `auth` keeps a policy 403
90
+ * (HOST_POLICY_DENIED) out.
91
+ */
92
+ export declare function isAuthFailure(err: unknown): boolean;
93
+ /**
94
+ * Surface the SDK's error contract so the model can correct itself (architecture section 8:
95
+ * wrap, never flatten). The SDK's fields cross this boundary: `code`, `category`, `retryable`,
96
+ * `httpStatus`, `operation`, `suggestedAction`, `resourceIds`, `details`, plus `notSent` /
97
+ * `retryAfter` where present and the `vendorError` — which the SDK redacts by FIELD NAME, and
98
+ * this function bounds + value-scrubs (V23/FT-5), because a name-based redaction is a
99
+ * documented no-op on free text.
100
+ *
101
+ * A correlation id is always present in the served envelope: the SDK's when it stamped one,
102
+ * otherwise the server's request correlation id (mandatory on every error).
103
+ *
104
+ * `secrets` (V23/FT-5): the request's own credential values (the 3-tuple + the impersonation
105
+ * id). A vendor 4xx body that ECHOES a request value in free text crosses the SDK's name-based
106
+ * redaction untouched; only this value-based scrub (plus the shape-only message and the bounded
107
+ * vendorError) keeps the typed envelope the only thing that crosses.
108
+ *
109
+ * This is the typed payload itself (the envelope's text block is its JSON) — the single source
110
+ * for the mapping, shared by the tool-level envelope ({@link errorContent}) and the per-item
111
+ * slot of the batched read (issue #15: a refused or failing item rides the SAME envelope in its
112
+ * own slot — the batch never invents its own error shape).
113
+ */
114
+ export declare function typedErrorPayload(err: unknown, correlationId?: string, secrets?: readonly string[]): Record<string, unknown>;
115
+ /** The tool-level error envelope: the typed payload as the text block (the batch's per-item
116
+ * slot — issue #15 — rides the SAME payload object, so a slot error is exactly what the single
117
+ * read would have served). */
118
+ export declare function errorContent(err: unknown, correlationId?: string, secrets?: readonly string[]): ToolReturn;
119
+ /** The kinds of a server-side fail-closed refusal (the placeholder clients, see `context/scope.ts`). */
120
+ export type RefusalKind = 'no_credential' | 'partial_credential' | 'no_origin' | 'bad_origin' | 'origin_not_allowed' | 'malformed_credential';
121
+ /** The fixed, value-free message per refusal kind (never carries a part of the refused value). */
122
+ export declare const REFUSAL_MESSAGES: Record<RefusalKind, string>;
123
+ /** The machine code per refusal kind (credential refusals vs host-policy refusals). */
124
+ export declare function refusalCode(kind: RefusalKind): {
125
+ code: string;
126
+ category: string;
127
+ };
128
+ /**
129
+ * The typed refusal a tool call gets when its resolved client is a fail-closed placeholder.
130
+ * Pre-request, zero vendor wire; the message names the missing input or the policy, never a
131
+ * part of the refused value (a credential presented twice is treated as absent — the kind is
132
+ * then `no_credential` for that member's effect).
133
+ */
134
+ export declare function refusalContent(kind: RefusalKind, correlationId?: string, anomalies?: readonly string[]): ToolReturn;
135
+ /**
136
+ * The typed answer for a call whose MCP request was cancelled before the upstream call settled
137
+ * (the SDK's `withSignal` resolves `undefined` in that case). Cancellation is a client action,
138
+ * not a vendor fault: `category: client`, retryable (a fresh call is the retry).
139
+ */
140
+ export declare function abortedResult(correlationId?: string): ToolReturn;
141
+ /**
142
+ * The handler-side typed refusal for a tool call whose top-level argument set is not closed
143
+ * (issue #3): the SDK's shared `unknownKeysRefusal` names the unknown key(s) + the valid keys
144
+ * + a did-you-mean — never the values — and the refusal rides the standard error envelope.
145
+ * Returns `null` when every key is known (no refusal).
146
+ */
147
+ export declare function closedArgsError(raw: unknown, validKeys: readonly string[], correlationId?: string): ToolReturn | null;
@@ -0,0 +1,384 @@
1
+ /** Error mapping and secret scrubbing: typed error payloads, bounded vendor errors, refusals and aborted results (issue #90). */
2
+ import { credentialShapeProblem, isAutotaskError } from 'node-autotask';
3
+ import { CREDENTIAL_LOAD_HINT } from '../../credential.js';
4
+ import { unknownKeysRefusal } from 'node-autotask/operations';
5
+ import { errorEnvelope } from './envelope.js';
6
+ import { classifyError } from '../reasons.js';
7
+ import { cleanUntrustedText, EVERY_ITEM, note } from './untrusted.js';
8
+ /** Hard cap on the model-facing error text; see {@link boundErrorMessage}. */
9
+ export const MAX_ERROR_MESSAGE_CHARS = 200;
10
+ /** Per-string free-text cap inside a served `vendorError` (V23/FT-5). */
11
+ export const VENDOR_FIELD_MAX = 200;
12
+ /** Total serialized cap for the served `vendorError` (V23/FT-5). */
13
+ export const VENDOR_ERROR_MAX = 2000;
14
+ /** The value-free marker a credential echo is replaced with (never the echoed value). */
15
+ export const SECRET_MARKER = '[REDACTED]';
16
+ /**
17
+ * The SDK's "no shape anomaly" 401 diagnostic literal(s) (node-autotask 0.8.0, chunk-5QVXRT3A:
18
+ * `DIAGNOSTIC_NO_ANOMALY`). `credentialDiagnosticDetails` stamps it on EVERY 401 whose values were
19
+ * clean, so it must never be read as an anomaly statement: the 401 branch treats an exact match as
20
+ * ABSENT and keeps the pre-hardening envelope byte-identical. Exact match only — never a substring
21
+ * test, so a diagnostic that merely mentions the clean phrase still crosses as an anomaly.
22
+ */
23
+ export const ANOMALY_FREE_DIAGNOSTIC_LITERALS = new Set([
24
+ 'sent value shows no shape anomalies \u2014 credentials or account state are the likely cause',
25
+ ]);
26
+ /** The host part of a request URL, or `undefined` when there is none or it cannot be parsed. */
27
+ export function hostFromUrl(url) {
28
+ if (url === undefined)
29
+ return undefined;
30
+ try {
31
+ return new URL(url).host;
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ }
37
+ /**
38
+ * The response SHAPE — the only upstream-derived text a vendor-side error (an `httpStatus` is
39
+ * present) serves as `message`: status + dialed host, never the vendor's own words.
40
+ */
41
+ export function shapeMessage(status, url) {
42
+ const host = hostFromUrl(url);
43
+ return host === undefined ? `upstream responded ${status}` : `upstream responded ${status} for host ${host}`;
44
+ }
45
+ /**
46
+ * Bound the upstream-derived text the SDK carries in `err.message`.
47
+ *
48
+ * The SDK puts a string upstream body into `err.message` verbatim by design (an edge-served
49
+ * HTML page is "surfaced verbatim rather than rejected"): a multi-kilobyte page has no business
50
+ * in a model-facing envelope. Text at or under the cap crosses unchanged (every fixed envelope
51
+ * is short, so their bytes never change); longer text is replaced by the SHAPE of the response —
52
+ * status and dialed host — never by its body.
53
+ */
54
+ export function boundErrorMessage(raw, url) {
55
+ if (raw.length <= MAX_ERROR_MESSAGE_CHARS)
56
+ return raw;
57
+ const host = hostFromUrl(url);
58
+ return host === undefined ? raw.slice(0, MAX_ERROR_MESSAGE_CHARS) : `upstream error for host ${host}`;
59
+ }
60
+ /**
61
+ * Value-based scrub (V23/FT-5): a string that carries ANY of the request's own credential values
62
+ * (the 3-tuple + the impersonation id) is a credential echo, not data — the whole value is
63
+ * replaced with the value-free marker. The SDK's redaction is name-based (its documented no-op
64
+ * on free text), so only this value-based pass can catch a vendor body that echoes a request
65
+ * value in a field the name list does not know. Also reused by the http last-resort error log
66
+ * (security R2).
67
+ */
68
+ export function scrubSecrets(value, secrets) {
69
+ for (const s of secrets)
70
+ if (s.length > 0 && value.includes(s))
71
+ return SECRET_MARKER;
72
+ return value;
73
+ }
74
+ /**
75
+ * Bound + scrub the vendor body the SDK carries under `vendorError` (V23/FT-5): the served
76
+ * envelope is typed-only — never the raw body, never a request's own credential value.
77
+ *
78
+ * - a STRING body (an edge-served HTML page) serves its SHAPE only (`{type, bytes, truncated}`);
79
+ * - an OBJECT body keeps its structure, but every string is scrubbed (credential echo → the
80
+ * marker) and capped, and the whole thing is dropped to a shape descriptor when it would
81
+ * exceed the total cap.
82
+ */
83
+ export function boundVendorError(vendorError, secrets) {
84
+ if (typeof vendorError === 'string') {
85
+ return { type: 'text', bytes: vendorError.length, truncated: vendorError.length > VENDOR_FIELD_MAX };
86
+ }
87
+ if (vendorError === null || typeof vendorError !== 'object')
88
+ return vendorError;
89
+ const bound = (v, depth) => {
90
+ if (depth > 6)
91
+ return '[DEPTH]';
92
+ if (typeof v === 'string') {
93
+ const scrubbed = scrubSecrets(v, secrets);
94
+ if (scrubbed !== v)
95
+ return SECRET_MARKER;
96
+ // R5: vendor error text is cleaned like any other vendor text (strip; the per-string cap is the line below)
97
+ const clean = cleanUntrustedText(v, false);
98
+ return clean.length > VENDOR_FIELD_MAX ? `[TRUNCATED ${v.length}]` : clean;
99
+ }
100
+ // Each string here is already cleaned, so it is recorded `server`: the choke point keeps a
101
+ // server-marked value as-is, so the cleaning above is never applied twice.
102
+ if (Array.isArray(v)) {
103
+ const arr = v.map((x) => bound(x, depth + 1));
104
+ note(arr, EVERY_ITEM, 'server');
105
+ return arr;
106
+ }
107
+ if (v !== null && typeof v === 'object') {
108
+ const out = {};
109
+ for (const [k, x] of Object.entries(v)) {
110
+ out[k] = bound(x, depth + 1);
111
+ if (typeof out[k] === 'string')
112
+ note(out, k, 'server');
113
+ }
114
+ return out;
115
+ }
116
+ return v;
117
+ };
118
+ const out = bound(vendorError, 0);
119
+ try {
120
+ if (JSON.stringify(out).length > VENDOR_ERROR_MAX) {
121
+ return { truncated: true, fieldNames: Object.keys(vendorError) };
122
+ }
123
+ }
124
+ catch {
125
+ return { truncated: true };
126
+ }
127
+ return out;
128
+ }
129
+ /**
130
+ * The clean credential-refusal answer: the exact `UNAUTHORIZED` 401 envelope every tool returns
131
+ * when the vendor rejects the identity. Fixed rather than echoed: the upstream auth message is
132
+ * vendor text and may name the resource the identity may not read, so only the code, the status
133
+ * and the stable message cross this boundary.
134
+ */
135
+ export function unauthorizedPayload(correlationId, shapeDiagnostic) {
136
+ // The ONE addition the shape annotation makes (issue #4c). With a clean (or unknown) shape the
137
+ // envelope is byte-identical to the pinned one below — `code`, `category`, `httpStatus`,
138
+ // `retryable`, `message` and `correlationId` never move.
139
+ const annotated = shapeDiagnostic !== undefined && shapeDiagnostic.length > 0;
140
+ return {
141
+ error: true,
142
+ code: 'UNAUTHORIZED',
143
+ category: 'auth',
144
+ httpStatus: 401,
145
+ retryable: false,
146
+ message: 'Bad credentials',
147
+ ...(annotated ? { credentialShape: 'anomalous', shapeDiagnostic, suggestedAction: CREDENTIAL_LOAD_HINT } : {}),
148
+ correlationId,
149
+ };
150
+ }
151
+ export function unauthorizedContent(correlationId = '', shapeDiagnostic) {
152
+ return errorEnvelope(unauthorizedPayload(correlationId, shapeDiagnostic), correlationId);
153
+ }
154
+ /**
155
+ * The vendor-401 shape diagnostic (issue #4c), value-free.
156
+ *
157
+ * node-autotask 0.8.0 stamps a `details.diagnostic` on a vendor 401 (code `UNAUTHORIZED`: a typed `UnauthorizedError`
158
+ * before SDK 0.46.0, a plain `AutotaskError` since) whenever it knows
159
+ * the shape of the values that went out. For an ANOMALY it is the value-free statement "sent value
160
+ * shows shell-quoting/line-break artifacts (<problem>) — check your env load", consumed verbatim. For
161
+ * CLEAN values it is the fixed no-anomaly literal, which is NOT an anomaly report and is treated as
162
+ * absent (F1), so a genuine vendor-side 401 keeps the legacy envelope. When the SDK carries no diagnostic — an older SDK, an error built by a fixture — this
163
+ * server's own view of the request's credential values is the second source: a shape anomaly there
164
+ * makes the same statement in this package's own words. An interpreter-backed value is never
165
+ * reported by name (`credentialShapeProblem` describes it value-free as "no shape problem").
166
+ *
167
+ * Returns `undefined` for clean values, which keeps the envelope byte-identical to the pinned one.
168
+ *
169
+ * The SDK stamps a diagnostic on EVERY 401 it maps (node-autotask 0.8.0, chunk-5QVXRT3A:
170
+ * `credentialDiagnosticDetails` -> `credential.allValuesClean ? NO_ANOMALY : ANOMALY(problem)`), so
171
+ * the no-anomaly literal is the SDK saying "clean" — not an anomaly report. It is recognised by
172
+ * EXACT match against the pinned literals below and treated as ABSENT, so a genuine vendor-side 401
173
+ * on clean values keeps the pre-hardening envelope byte-for-byte. Only a diagnostic that is NOT one
174
+ * of the known no-anomaly literals is consumed as an anomaly statement.
175
+ */
176
+ export function isAnomalyFreeDiagnostic(diagnostic) {
177
+ return ANOMALY_FREE_DIAGNOSTIC_LITERALS.has(diagnostic);
178
+ }
179
+ export function vendorShapeDiagnostic(err, secrets) {
180
+ const details = err?.details;
181
+ if (details !== null && typeof details === 'object') {
182
+ const diagnostic = details.diagnostic;
183
+ if (typeof diagnostic === 'string' && diagnostic.length > 0) {
184
+ const scrubbed = scrubSecrets(diagnostic, secrets);
185
+ // The scrub already replaced an echoed value: the statement is unreadable, so it is ABSENT.
186
+ const clean = scrubbed !== diagnostic || isAnomalyFreeDiagnostic(scrubbed);
187
+ return clean ? undefined : scrubbed;
188
+ }
189
+ const problem = details.problem;
190
+ if (typeof problem === 'string' && problem.length > 0) {
191
+ return scrubSecrets(`sent value shows shell-quoting/line-break artifacts (${problem}) — check your env load`, secrets);
192
+ }
193
+ }
194
+ for (const value of secrets) {
195
+ if (value.length === 0)
196
+ continue;
197
+ const problem = credentialShapeProblem(value);
198
+ if (problem !== undefined)
199
+ return `sent value shows shell-quoting/line-break artifacts (${problem}) — check your env load`;
200
+ }
201
+ return undefined;
202
+ }
203
+ /**
204
+ * True when the SDK error is an upstream credential refusal (401/403-class). The typed status
205
+ * decides: the SDK keeps a machine-shaped vendor code (e.g. `AUTH_401`) in place of
206
+ * UNAUTHORIZED/FORBIDDEN, so the code alone does not. Category `auth` keeps a policy 403
207
+ * (HOST_POLICY_DENIED) out.
208
+ */
209
+ export function isAuthFailure(err) {
210
+ const e = err;
211
+ const code = e?.code;
212
+ return (((e?.httpStatus === 401 || e?.httpStatus === 403) && e.category === 'auth') ||
213
+ (typeof code === 'string' && (code === 'UNAUTHORIZED' || code === 'FORBIDDEN')) ||
214
+ err?.name === 'UnauthorizedError' ||
215
+ err?.name === 'ForbiddenError');
216
+ }
217
+ /**
218
+ * Surface the SDK's error contract so the model can correct itself (architecture section 8:
219
+ * wrap, never flatten). The SDK's fields cross this boundary: `code`, `category`, `retryable`,
220
+ * `httpStatus`, `operation`, `suggestedAction`, `resourceIds`, `details`, plus `notSent` /
221
+ * `retryAfter` where present and the `vendorError` — which the SDK redacts by FIELD NAME, and
222
+ * this function bounds + value-scrubs (V23/FT-5), because a name-based redaction is a
223
+ * documented no-op on free text.
224
+ *
225
+ * A correlation id is always present in the served envelope: the SDK's when it stamped one,
226
+ * otherwise the server's request correlation id (mandatory on every error).
227
+ *
228
+ * `secrets` (V23/FT-5): the request's own credential values (the 3-tuple + the impersonation
229
+ * id). A vendor 4xx body that ECHOES a request value in free text crosses the SDK's name-based
230
+ * redaction untouched; only this value-based scrub (plus the shape-only message and the bounded
231
+ * vendorError) keeps the typed envelope the only thing that crosses.
232
+ *
233
+ * This is the typed payload itself (the envelope's text block is its JSON) — the single source
234
+ * for the mapping, shared by the tool-level envelope ({@link errorContent}) and the per-item
235
+ * slot of the batched read (issue #15: a refused or failing item rides the SAME envelope in its
236
+ * own slot — the batch never invents its own error shape).
237
+ */
238
+ export function typedErrorPayload(err, correlationId, secrets = []) {
239
+ if (isAuthFailure(err))
240
+ return unauthorizedPayload(correlationId, vendorShapeDiagnostic(err, secrets));
241
+ const e = (typeof err === 'object' && err !== null ? err : {});
242
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
243
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
244
+ const bool = (v) => (typeof v === 'boolean' ? v : undefined);
245
+ const code = str(e.code) ?? (isAutotaskError(err) ? 'AUTOTASK_ERROR' : undefined) ?? 'INTERNAL_ERROR';
246
+ const httpStatus = num(e.httpStatus);
247
+ const url = str(e.url);
248
+ const payload = { error: true, code };
249
+ const category = str(e.category);
250
+ if (category !== undefined)
251
+ payload.category = category;
252
+ const retryable = bool(e.retryable);
253
+ if (retryable !== undefined)
254
+ payload.retryable = retryable;
255
+ if (httpStatus !== undefined)
256
+ payload.httpStatus = httpStatus;
257
+ const operation = str(e.operation);
258
+ if (operation !== undefined)
259
+ payload.operation = operation;
260
+ const rollupBudget = isAutotaskError(err) && code === 'BUDGET_EXCEEDED' && (operation === 'operations.revenueRollup' || operation === 'operations.portfolioMargin' || operation === 'operations.recurringRevenue' || operation === 'operations.arAging' || operation === 'operations.wipHours' || operation === 'operations.nonChargeableWork') && category === 'policy' && e.httpStatus === undefined && e.url === undefined && e.vendorError === undefined;
261
+ // V23: a vendor-side error serves the response SHAPE as its message — the SDK puts the
262
+ // upstream body into err.message by design, and a SHORT body (a credential echo) would
263
+ // otherwise cross under the 200-char bound. Client-side errors (no httpStatus) keep the
264
+ // SDK's own deterministic text (bounded as before).
265
+ payload.message =
266
+ httpStatus !== undefined
267
+ ? shapeMessage(httpStatus, url)
268
+ : scrubSecrets(rollupBudget ? err.message : boundErrorMessage(err instanceof Error ? err.message : String(err), url), secrets);
269
+ const suggestedAction = str(e.suggestedAction);
270
+ if (suggestedAction !== undefined)
271
+ payload.suggestedAction = scrubSecrets(suggestedAction, secrets);
272
+ // SDK-built budget guidance contains no vendor text; preserve its complete narrowing options.
273
+ if (rollupBudget)
274
+ for (const key of ['message', 'suggestedAction'])
275
+ if (typeof payload[key] === 'string') {
276
+ payload[key] = cleanUntrustedText(payload[key], false);
277
+ note(payload, key, 'server');
278
+ }
279
+ const retryAfter = num(e.retryAfter);
280
+ if (retryAfter !== undefined)
281
+ payload.retryAfter = retryAfter;
282
+ if (e.notSent === true)
283
+ payload.notSent = true;
284
+ if (e.callerInput === true)
285
+ payload.callerInput = true;
286
+ // #254: the SDK's deterministic next step (node-autotask #296), as the server classifies it (the same value as the
287
+ // envelope `next`; a batched read slot has no envelope, so this is its only hint)
288
+ payload.nextAction = classifyError({ ...payload, nextAction: str(e.nextAction) }).next;
289
+ // V23/FT-5: the vendor body crosses bounded + scrubbed, never raw (a string body serves its
290
+ // shape; an object body keeps structure with scrubbed/capped strings, dropped to a shape
291
+ // descriptor past the total cap).
292
+ if (e.vendorError !== undefined && e.vendorError !== null && e.vendorError !== '') {
293
+ payload.vendorError = boundVendorError(e.vendorError, secrets);
294
+ }
295
+ if (Array.isArray(e.resourceIds))
296
+ payload.resourceIds = e.resourceIds;
297
+ if (e.details !== null && typeof e.details === 'object' && !Array.isArray(e.details)) {
298
+ payload.details = boundVendorError(e.details, secrets);
299
+ }
300
+ payload.correlationId = str(e.correlationId) ?? correlationId;
301
+ return payload;
302
+ }
303
+ /** The tool-level error envelope: the typed payload as the text block (the batch's per-item
304
+ * slot — issue #15 — rides the SAME payload object, so a slot error is exactly what the single
305
+ * read would have served). */
306
+ export function errorContent(err, correlationId = '', secrets = []) {
307
+ const payload = typedErrorPayload(err, correlationId, secrets);
308
+ const field = err?.field;
309
+ return errorEnvelope(payload, String(payload.correlationId ?? correlationId), typeof field === 'string' ? field : undefined);
310
+ }
311
+ /** The fixed, value-free message per refusal kind (never carries a part of the refused value). */
312
+ export const REFUSAL_MESSAGES = {
313
+ malformed_credential: 'Malformed Autotask credential shape; correct the reported anomalies before retrying, nothing was dialed.',
314
+ no_credential: 'Supply all three Autotask credential headers through the gateway before calling tools.',
315
+ partial_credential: 'Supply all three Autotask credential headers or none; partial credentials are never filled from defaults.',
316
+ no_origin: 'Supply the Autotask zone origin in X-Autotask-Base-Url or configure the deployment default.',
317
+ bad_origin: 'X-Autotask-Base-Url must be an https origin with no path.',
318
+ origin_not_allowed: 'The origin host is refused by AUTOTASK_ALLOWED_BASE_HOSTS; contact the operator for allowed hosts.',
319
+ };
320
+ /** The machine code per refusal kind (credential refusals vs host-policy refusals). */
321
+ export function refusalCode(kind) {
322
+ switch (kind) {
323
+ case 'no_credential':
324
+ case 'partial_credential':
325
+ return { code: 'CREDENTIAL_MISSING', category: 'auth' };
326
+ case 'malformed_credential':
327
+ // A malformed load is a validation failure, not an auth one: nothing was dialed, so a 401
328
+ // shape would be a lie, and `retryable: false` is what stops a retry loop against an account
329
+ // where repeated auth failures risk a lock (issue #4, the template's C1 shape).
330
+ return { code: 'CREDENTIAL_MALFORMED', category: 'validation' };
331
+ default:
332
+ return { code: 'HOST_POLICY_DENIED', category: 'policy' };
333
+ }
334
+ }
335
+ /**
336
+ * The typed refusal a tool call gets when its resolved client is a fail-closed placeholder.
337
+ * Pre-request, zero vendor wire; the message names the missing input or the policy, never a
338
+ * part of the refused value (a credential presented twice is treated as absent — the kind is
339
+ * then `no_credential` for that member's effect).
340
+ */
341
+ export function refusalContent(kind, correlationId = '', anomalies = []) {
342
+ const { code, category } = refusalCode(kind);
343
+ const malformed = kind === 'malformed_credential';
344
+ return errorEnvelope({
345
+ error: true,
346
+ code,
347
+ category,
348
+ retryable: false,
349
+ // The anomaly NAMES are the diagnostic (never a character of the value); the
350
+ // `suggestedAction` is the env-load pitfall this class of anomaly overwhelmingly has.
351
+ ...(malformed && anomalies.length > 0 ? { credentialShape: 'anomalous', anomalies } : {}),
352
+ message: REFUSAL_MESSAGES[kind],
353
+ ...(malformed ? { suggestedAction: CREDENTIAL_LOAD_HINT } : {}),
354
+ correlationId,
355
+ }, correlationId);
356
+ }
357
+ /**
358
+ * The typed answer for a call whose MCP request was cancelled before the upstream call settled
359
+ * (the SDK's `withSignal` resolves `undefined` in that case). Cancellation is a client action,
360
+ * not a vendor fault: `category: client`, retryable (a fresh call is the retry).
361
+ */
362
+ export function abortedResult(correlationId = '') {
363
+ return errorEnvelope({
364
+ error: true,
365
+ code: 'ABORTED',
366
+ category: 'client',
367
+ retryable: true,
368
+ message: 'The MCP request was cancelled before the upstream call settled; no result was produced.',
369
+ correlationId,
370
+ }, correlationId);
371
+ }
372
+ /**
373
+ * The handler-side typed refusal for a tool call whose top-level argument set is not closed
374
+ * (issue #3): the SDK's shared `unknownKeysRefusal` names the unknown key(s) + the valid keys
375
+ * + a did-you-mean — never the values — and the refusal rides the standard error envelope.
376
+ * Returns `null` when every key is known (no refusal).
377
+ */
378
+ export function closedArgsError(raw, validKeys, correlationId = '') {
379
+ const refusal = unknownKeysRefusal(raw, validKeys, 'argument');
380
+ if (refusal === null)
381
+ return null;
382
+ return errorContent(refusal, correlationId);
383
+ }
384
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,129 @@
1
+ import { type ToolReturn } from './envelope.js';
2
+ /**
3
+ * Characters stripped from every untrusted free-text value (M8, review F3, pre-release V9 and the
4
+ * follow-up review): every control character except `\n` and `\t` (`\p{Cc}`), every format
5
+ * character (`\p{Cf}`: bidi controls, zero-width characters, the soft hyphen, the tag block U+E0000-
6
+ * E007F, ...), every default-ignorable code point (variation selectors, fillers, the grapheme
7
+ * joiner, Mongolian free variation selectors, ...), and the line and paragraph separators
8
+ * U+2028/9. They hide or reorder text a model then reads as instructions, or split a token so one
9
+ * check misses what a later reader sees.
10
+ *
11
+ * Tradeoff, decided conservatively: the zero-width joiner and the emoji variation selector are in
12
+ * this set, so an emoji ZWJ sequence crosses as its separate emoji (a family emoji as three
13
+ * people) and a text-or-emoji presentation choice is lost. Letters, accents and plain emoji are kept.
14
+ */
15
+ export declare const UNSAFE_CHARS: RegExp;
16
+ /** The per-value cap on untrusted free text (M8). */
17
+ export declare const UNTRUSTED_TEXT_CAP = 500;
18
+ /** Strip the unsafe characters only (write payloads: D-21; nothing else is changed). */
19
+ export declare function stripUnsafeChars(text: string): string;
20
+ /**
21
+ * The angle-bracket escape of untrusted vendor text (the pre-release follow-up reviews) was
22
+ * REMOVED in 0.9.0 (issue #70): it was pure cost for LLM consumers and broke read-modify-write
23
+ * round-trips of values carrying &, < or >. The injection controls are the strip pass above and
24
+ * the <untrusted_content> wrapper the choke point applies to stamped fields (the wrapper marks
25
+ * the whole field untrusted; the server instructions carry the data-never-instructions rule).
26
+ */
27
+ /**
28
+ * Clean one untrusted value: strip the unsafe characters, then (when `cap`) cut at
29
+ * {@link UNTRUSTED_TEXT_CAP}; a cut value carries {@link TRUNCATION_MARKER}.
30
+ */
31
+ export declare function cleanUntrustedText(text: string, cap?: boolean, max?: number): string;
32
+ /** One character outside the base64 alphabet (a linear test: no backtracking, any length). */
33
+ export declare const NOT_BASE64: RegExp;
34
+ /** Nesting past this depth is dropped rather than walked (final review R7). */
35
+ export declare const MAX_OUTPUT_DEPTH = 64;
36
+ /** The per-array provenance key: applies to every string item of an array. */
37
+ export declare const EVERY_ITEM = "*";
38
+ /**
39
+ * What the server knows about a field it produced, by provenance, never by content or shape:
40
+ * - `wrap`: an untrusted free-text field (the registry stamp, a UDF value): cleaned, capped, wrapped;
41
+ * - `document`: a vendor document (an invoice export): cleaned, wrapped, never capped;
42
+ * - `server`: a value the server built from values that already passed the choke point (a TSV
43
+ * table): kept as it is;
44
+ * - `binary`: the file payload of a download (sanitiser review S1/S2): kept uncapped only while it
45
+ * is pure base64, otherwise it is vendor text like any other;
46
+ * - `cursor`: a pagination cursor the caller passes back verbatim (the `nextCursor` of the four
47
+ * time_entries posted-state reads, #224): cleaned and unwrapped, capped at {@link CURSOR_CAP} (the
48
+ * SDK refuses a longer one) instead of 500, a cut one carrying the truncation marker.
49
+ * No other field is ever exempt from the cap, whatever its content looks like.
50
+ * Keyed by the exact object the server built (a WeakMap: vendor data can never be in it), so a
51
+ * vendor key that merely shares a name (`tsv`, `result`) at any depth is plain vendor text.
52
+ */
53
+ export type Provenance = 'wrap' | 'document' | 'server' | 'binary' | 'cursor';
54
+ /** The cap on a `cursor` value: the SDK's own cursor cap (a longer cursor is refused before any request). */
55
+ export declare const CURSOR_CAP = 2048;
56
+ export declare const PROVENANCE: WeakMap<object, Map<string, Provenance>>;
57
+ export declare function note(target: object, key: string, kind: Provenance): void;
58
+ /** Record that `target[key]` is a server-built document or table (see {@link Provenance}). */
59
+ export declare function markServerField(target: object, key: string, kind: Provenance): void;
60
+ export interface SanitiseOptions {
61
+ /** false: no cap anywhere (the output_path file form). */
62
+ cap?: boolean;
63
+ }
64
+ /** The operations whose result carries a file payload in `data` (FileQueryResultModel). */
65
+ export declare function isFileOperation(operation: string): boolean;
66
+ /** Record a file result's `data` as `binary` (provenance: only for {@link isFileOperation} results). */
67
+ export declare function markFilePayload(value: unknown): void;
68
+ export declare function wrapOrSelf(clean: string): string;
69
+ /**
70
+ * Drop ONE outer wrapper pair, unconditionally, from a value that starts with the open tag and ends
71
+ * with the close tag. The pinned SDK's read path returns raw values (node-autotask#103: wrapping is
72
+ * projection-layer only), except the `contracts.profitability` renewal labels it wraps at the producer
73
+ * (SDK 0.47.2, node-autotask#375); otherwise the live input class is a vendor forgery. Both get exactly
74
+ * the same treatment: nothing about the value is trusted, the inner text is then cleaned like any
75
+ * vendor text and wrapped once by this server.
76
+ */
77
+ export declare function outerUnwrap(value: string): string | undefined;
78
+ /**
79
+ * The vendor document core of a value that may arrive pre-wrapped (issue #54): drop exactly ONE outer
80
+ * wrapper pair — the live class is a vendor forgery (the pinned SDK's read path returns raw values,
81
+ * node-autotask#103), otherwise the value unchanged. The invoice export channels encode and write the
82
+ * document core, so the artifact is the vendor document, never a wrapped one.
83
+ */
84
+ export declare function documentCore(value: string): string;
85
+ /**
86
+ * The deny-by-default choke point for vendor output (final review R1-R3, R5, R7, and the two
87
+ * follow-up findings): every string in a vendor-calling tool's result, at any depth, and every
88
+ * object key, is vendor text: cleaned ({@link cleanUntrustedText}: unsafe characters stripped,
89
+ * capped at 500). Nothing is ever skipped because of what a string looks
90
+ * like. A value that arrives pre-wrapped (a vendor forgery, or an SDK producer-wrapped profitability
91
+ * renewal label: see {@link outerUnwrap}) loses its one outer pair ({@link outerUnwrap}); its inner
92
+ * text is cleaned and capped like any vendor text and wrapped once, since it came marked
93
+ * untrusted. An unmarked string is
94
+ * cleaned, not wrapped. Otherwise the wrapper is applied here and only here, to the fields the
95
+ * server recorded by provenance ({@link markResult}, {@link markServerField}).
96
+ */
97
+ export declare function sanitiseVendorOutput(value: unknown, opts?: SanitiseOptions, kind?: Provenance, depth?: number): unknown;
98
+ export declare const CORRELATION_ID: RegExp;
99
+ /**
100
+ * Server prose (summary, reason detail and field) can embed vendor values that arrive pre-wrapped
101
+ * (a vendor forgery — the pinned SDK's read path returns raw values).
102
+ * Prose is cleaned, never wrapped, so the embedded wrapper tags are dropped (the split/join below)
103
+ * before cleaning: the dropped tags are the injection control here — no wrapper tag survives into
104
+ * prose, and the brackets left over stay raw (0.9.0 removed the escape, issue #70).
105
+ */
106
+ export declare function cleanProse(text: string, cap?: boolean): string;
107
+ /**
108
+ * Apply {@link sanitiseVendorOutput} to a finished vendor-tool result and re-mirror its text block.
109
+ * `serverCorrelationId` replaces a top-level correlation id that is not this server's own shape
110
+ * (sanitiser review S5). Every envelope string that is not a fixed enum passes the choke point:
111
+ * data, summary, candidates, and each reason's detail and field (S4).
112
+ */
113
+ export declare function sanitiseToolReturn(result: ToolReturn, serverCorrelationId?: string): ToolReturn;
114
+ /**
115
+ * Record the untrusted-content projection on a result: a copy in which the plan-derived field list
116
+ * (the registry stamp) and every user-defined field value (`userDefinedFields[].value`, review F3)
117
+ * are marked `wrap` by provenance through the SDK's field/UDF projection. Nothing is cleaned or wrapped here: the choke point
118
+ * ({@link sanitiseVendorOutput}, run on every vendor tool's result and on TSV cells and
119
+ * output_path files) cleans every string and wraps exactly the marked ones.
120
+ */
121
+ export declare function markResult(value: unknown, fields: readonly string[]): unknown;
122
+ /**
123
+ * The cross-resource untrusted field union (resolveAny / searchAcrossResources /
124
+ * the mode tools serve records from several resources — the superset is safe: the wrapper only
125
+ * affects fields that are present).
126
+ */
127
+ export declare const CROSS_RESOURCE_UNTRUSTED: readonly string[];
128
+ /** The cross-resource untrusted field union (see {@link CROSS_RESOURCE_UNTRUSTED}). */
129
+ export declare function crossResourceUntrusted(): readonly string[];