@adcp/sdk 17.0.0-beta.31 → 17.0.0-beta.32

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 (36) hide show
  1. package/dist/lib/identity-3.3/trust.js +10 -4
  2. package/dist/lib/identity-3.3/trust.mjs +10 -4
  3. package/dist/lib/server/create-adcp-server.js +7 -8
  4. package/dist/lib/server/create-adcp-server.mjs +9 -10
  5. package/dist/lib/server/error-arm-tools.d.mts +23 -14
  6. package/dist/lib/server/error-arm-tools.d.ts +23 -14
  7. package/dist/lib/server/error-arm-tools.js +82 -34
  8. package/dist/lib/server/error-arm-tools.mjs +81 -34
  9. package/dist/lib/testing/storyboard/compliance.js +53 -24
  10. package/dist/lib/testing/storyboard/compliance.mjs +53 -24
  11. package/dist/lib/testing/storyboard/loader.js +2 -2
  12. package/dist/lib/testing/storyboard/loader.mjs +2 -2
  13. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  14. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  15. package/dist/lib/testing/storyboard/yaml-cache.d.mts +21 -0
  16. package/dist/lib/testing/storyboard/yaml-cache.d.ts +21 -0
  17. package/dist/lib/testing/storyboard/yaml-cache.js +168 -0
  18. package/dist/lib/testing/storyboard/yaml-cache.mjs +139 -0
  19. package/dist/lib/validation/schema-diagnostic-origins.js +55 -25
  20. package/dist/lib/validation/schema-diagnostic-origins.mjs +55 -25
  21. package/dist/lib/validation/schema-loader.js +499 -44
  22. package/dist/lib/validation/schema-loader.mjs +499 -46
  23. package/dist/lib/validation/schema-validator.js +4 -6
  24. package/dist/lib/validation/schema-validator.mjs +6 -7
  25. package/dist/lib/validation/validator-cache.d.mts +45 -0
  26. package/dist/lib/validation/validator-cache.d.ts +45 -0
  27. package/dist/lib/validation/validator-cache.js +249 -0
  28. package/dist/lib/validation/validator-cache.mjs +227 -0
  29. package/dist/lib/version.d.mts +3 -3
  30. package/dist/lib/version.d.ts +3 -3
  31. package/dist/lib/version.js +3 -3
  32. package/dist/lib/version.mjs +3 -3
  33. package/docs/TYPE-SUMMARY.md +2 -2
  34. package/docs/llms.txt +2 -2
  35. package/docs/migration-14.x-rc-worksheet.md +4 -4
  36. package/package.json +1 -1
@@ -47,11 +47,17 @@ var import_etld = require('../signing/agent-resolver/etld.js');
47
47
  var import_strict_json = require('../signing/agent-resolver/strict-json.js');
48
48
  var import_tldts = require("tldts");
49
49
  var import_schemas = __toESM(require('./schemas.draft.js'));
50
- const ajv = new import_ajv.default({ inlineRefs: false, strict: false, allErrors: false });
51
- (0, import_ajv_formats.default)(ajv);
52
- for (const schema of import_schemas.default) ajv.addSchema(schema);
50
+ let identityAjv;
51
+ function identitySchemas() {
52
+ if (identityAjv) return identityAjv;
53
+ const ajv = new import_ajv.default({ inlineRefs: false, strict: false, allErrors: false });
54
+ (0, import_ajv_formats.default)(ajv);
55
+ for (const schema of import_schemas.default) ajv.addSchema(schema);
56
+ identityAjv = ajv;
57
+ return ajv;
58
+ }
53
59
  function validateIdentity33Schema(id, value) {
54
- return ajv.getSchema(`/schemas/${id}.json`)?.(value) === true;
60
+ return identitySchemas().getSchema(`/schemas/${id}.json`)?.(value) === true;
55
61
  }
56
62
  class IdentityAuthorizationError extends Error {
57
63
  code = "PERMISSION_DENIED";
@@ -6,11 +6,17 @@ import { eTldPlusOne } from "../signing/agent-resolver/etld.mjs";
6
6
  import { parseStrictJson } from "../signing/agent-resolver/strict-json.mjs";
7
7
  import { parse as parseDomain } from "tldts";
8
8
  import schemas from "./schemas.draft.mjs";
9
- const ajv = new Ajv({ inlineRefs: false, strict: false, allErrors: false });
10
- addFormats(ajv);
11
- for (const schema of schemas) ajv.addSchema(schema);
9
+ let identityAjv;
10
+ function identitySchemas() {
11
+ if (identityAjv) return identityAjv;
12
+ const ajv = new Ajv({ inlineRefs: false, strict: false, allErrors: false });
13
+ addFormats(ajv);
14
+ for (const schema of schemas) ajv.addSchema(schema);
15
+ identityAjv = ajv;
16
+ return ajv;
17
+ }
12
18
  function validateIdentity33Schema(id, value) {
13
- return ajv.getSchema(`/schemas/${id}.json`)?.(value) === true;
19
+ return identitySchemas().getSchema(`/schemas/${id}.json`)?.(value) === true;
14
20
  }
15
21
  class IdentityAuthorizationError extends Error {
16
22
  code = "PERMISSION_DENIED";
@@ -1326,15 +1326,16 @@ function projectPayloadErrorToEnvelope(payloadError) {
1326
1326
  }
1327
1327
  return out;
1328
1328
  }
1329
- function enrichErrorTwoLayer(response, toolName, toolsWithErrorArm) {
1330
- const descriptor = toolsWithErrorArm.get(toolName);
1331
- if (!descriptor) return;
1329
+ function enrichErrorTwoLayer(response, toolName, version) {
1332
1330
  const sc = response.structuredContent;
1333
1331
  if (!sc || typeof sc !== "object") return;
1334
1332
  const env = sc.adcp_error;
1335
1333
  const envValid = env != null && typeof env === "object" && typeof env.code === "string";
1336
1334
  const payloadList = sc.errors;
1337
1335
  const payloadValid = Array.isArray(payloadList) && payloadList.length > 0;
1336
+ if (!envValid && !payloadValid) return;
1337
+ const descriptor = (0, import_error_arm_tools.getErrorArmDescriptor)(toolName, version);
1338
+ if (!descriptor) return;
1338
1339
  const mirrorsBeforePayloadSanitization = contentTextMirrorsStructuredContent(response, sc);
1339
1340
  if (payloadValid && sanitizePayloadErrors(sc)) {
1340
1341
  syncContentJsonText(response, sc, mirrorsBeforePayloadSanitization);
@@ -2226,7 +2227,6 @@ function createAdcpServer(config) {
2226
2227
  if (config.webhooks?.webBotAuth && !config.identity33)
2227
2228
  throw new Error("Web Bot Auth webhook signing requires the identity33 experiment");
2228
2229
  if (config.webhooks?.webBotAuth?.key) (0, import_web_bot_auth.assertWebBotAuthSigningKey)(config.webhooks.webBotAuth.key);
2229
- const toolsWithErrorArm = (0, import_error_arm_tools.getToolsWithErrorArm)(adcpVersion);
2230
2230
  const isProduction = process.env.NODE_ENV === "production";
2231
2231
  const requestValidationMode = validationConfig?.requests ?? (isProduction ? "off" : "strict");
2232
2232
  const responseValidationMode = validationConfig?.responses ?? (isProduction ? "off" : "strict");
@@ -2488,7 +2488,7 @@ function createAdcpServer(config) {
2488
2488
  const releaseDefinesTool = (toolName, release) => {
2489
2489
  if (toolName === "refine_proposals") return true;
2490
2490
  try {
2491
- return (0, import_schema_loader2.getValidator)(toolName, "request", release.validationVersion) !== void 0;
2491
+ return (0, import_schema_loader2.definesToolRequest)(toolName, release.validationVersion);
2492
2492
  } catch {
2493
2493
  return false;
2494
2494
  }
@@ -2499,7 +2499,7 @@ function createAdcpServer(config) {
2499
2499
  ...servedAdcpVersion !== void 0 && { wireVersion: servedAdcpVersion }
2500
2500
  };
2501
2501
  sanitizeAdcpErrorEnvelope(response);
2502
- enrichErrorTwoLayer(response, toolName, (0, import_error_arm_tools.getToolsWithErrorArm)(release.validationVersion));
2502
+ enrichErrorTwoLayer(response, toolName, release.validationVersion);
2503
2503
  if (!isErrorResponse(response)) {
2504
2504
  response = downgradeTaskStatusResult(toolName, response, release.validationVersion);
2505
2505
  normalizeMediaBuyStatusCollision(response, toolName, release.validationVersion);
@@ -2860,7 +2860,6 @@ function createAdcpServer(config) {
2860
2860
  } else {
2861
2861
  requestRelease = releaseSelection;
2862
2862
  }
2863
- const requestErrorArms = (0, import_error_arm_tools.getToolsWithErrorArm)(requestRelease.validationVersion);
2864
2863
  const translatesRelease = toolName !== "get_adcp_capabilities" && (0, import_version.translationSteps)(adcpVersion, requestRelease.validationVersion).length > 0;
2865
2864
  const ctx = withImmutableServedAdcpVersion(
2866
2865
  {
@@ -2881,7 +2880,7 @@ function createAdcpServer(config) {
2881
2880
  }
2882
2881
  const finalizeProtocolEnvelope = (response) => {
2883
2882
  sanitizeAdcpErrorEnvelope(response);
2884
- enrichErrorTwoLayer(response, toolName, requestErrorArms);
2883
+ enrichErrorTwoLayer(response, toolName, requestRelease.validationVersion);
2885
2884
  normalizeMediaBuyStatusCollision(response, toolName, requestRelease.validationVersion);
2886
2885
  injectEnvelopeStatusIntoResponse(response, toolName, requestRelease.validationVersion);
2887
2886
  injectContextIntoResponse(response, params.context);
@@ -56,7 +56,7 @@ import {
56
56
  } from "../media-buy/creative-start-policy.mjs";
57
57
  import { ConfigurationError } from "../errors/index.mjs";
58
58
  import {
59
- getValidator,
59
+ definesToolRequest,
60
60
  getToolSchemaDocument,
61
61
  hasSchemaBundle,
62
62
  resolveBundleKey,
@@ -65,7 +65,7 @@ import {
65
65
  import { TOOL_INPUT_SHAPES } from "../schemas/index.mjs";
66
66
  import { TaskTypeValues } from "../types/enums.generated.mjs";
67
67
  import { bundleSupportsAdcpVersionField } from "../protocols/index.mjs";
68
- import { getToolsWithErrorArm } from "./error-arm-tools.mjs";
68
+ import { getErrorArmDescriptor } from "./error-arm-tools.mjs";
69
69
  import { applyStructuredContentTextFallback } from "./structured-content-fallback.mjs";
70
70
  import {
71
71
  ADCP_CAPABILITIES,
@@ -1441,15 +1441,16 @@ function projectPayloadErrorToEnvelope(payloadError) {
1441
1441
  }
1442
1442
  return out;
1443
1443
  }
1444
- function enrichErrorTwoLayer(response, toolName, toolsWithErrorArm) {
1445
- const descriptor = toolsWithErrorArm.get(toolName);
1446
- if (!descriptor) return;
1444
+ function enrichErrorTwoLayer(response, toolName, version) {
1447
1445
  const sc = response.structuredContent;
1448
1446
  if (!sc || typeof sc !== "object") return;
1449
1447
  const env = sc.adcp_error;
1450
1448
  const envValid = env != null && typeof env === "object" && typeof env.code === "string";
1451
1449
  const payloadList = sc.errors;
1452
1450
  const payloadValid = Array.isArray(payloadList) && payloadList.length > 0;
1451
+ if (!envValid && !payloadValid) return;
1452
+ const descriptor = getErrorArmDescriptor(toolName, version);
1453
+ if (!descriptor) return;
1453
1454
  const mirrorsBeforePayloadSanitization = contentTextMirrorsStructuredContent(response, sc);
1454
1455
  if (payloadValid && sanitizePayloadErrors(sc)) {
1455
1456
  syncContentJsonText(response, sc, mirrorsBeforePayloadSanitization);
@@ -2341,7 +2342,6 @@ function createAdcpServer(config) {
2341
2342
  if (config.webhooks?.webBotAuth && !config.identity33)
2342
2343
  throw new Error("Web Bot Auth webhook signing requires the identity33 experiment");
2343
2344
  if (config.webhooks?.webBotAuth?.key) assertWebBotAuthSigningKey(config.webhooks.webBotAuth.key);
2344
- const toolsWithErrorArm = getToolsWithErrorArm(adcpVersion);
2345
2345
  const isProduction = process.env.NODE_ENV === "production";
2346
2346
  const requestValidationMode = validationConfig?.requests ?? (isProduction ? "off" : "strict");
2347
2347
  const responseValidationMode = validationConfig?.responses ?? (isProduction ? "off" : "strict");
@@ -2603,7 +2603,7 @@ function createAdcpServer(config) {
2603
2603
  const releaseDefinesTool = (toolName, release) => {
2604
2604
  if (toolName === "refine_proposals") return true;
2605
2605
  try {
2606
- return getValidator(toolName, "request", release.validationVersion) !== void 0;
2606
+ return definesToolRequest(toolName, release.validationVersion);
2607
2607
  } catch {
2608
2608
  return false;
2609
2609
  }
@@ -2614,7 +2614,7 @@ function createAdcpServer(config) {
2614
2614
  ...servedAdcpVersion !== void 0 && { wireVersion: servedAdcpVersion }
2615
2615
  };
2616
2616
  sanitizeAdcpErrorEnvelope(response);
2617
- enrichErrorTwoLayer(response, toolName, getToolsWithErrorArm(release.validationVersion));
2617
+ enrichErrorTwoLayer(response, toolName, release.validationVersion);
2618
2618
  if (!isErrorResponse(response)) {
2619
2619
  response = downgradeTaskStatusResult(toolName, response, release.validationVersion);
2620
2620
  normalizeMediaBuyStatusCollision(response, toolName, release.validationVersion);
@@ -2975,7 +2975,6 @@ function createAdcpServer(config) {
2975
2975
  } else {
2976
2976
  requestRelease = releaseSelection;
2977
2977
  }
2978
- const requestErrorArms = getToolsWithErrorArm(requestRelease.validationVersion);
2979
2978
  const translatesRelease = toolName !== "get_adcp_capabilities" && translationSteps(adcpVersion, requestRelease.validationVersion).length > 0;
2980
2979
  const ctx = withImmutableServedAdcpVersion(
2981
2980
  {
@@ -2996,7 +2995,7 @@ function createAdcpServer(config) {
2996
2995
  }
2997
2996
  const finalizeProtocolEnvelope = (response) => {
2998
2997
  sanitizeAdcpErrorEnvelope(response);
2999
- enrichErrorTwoLayer(response, toolName, requestErrorArms);
2998
+ enrichErrorTwoLayer(response, toolName, requestRelease.validationVersion);
3000
2999
  normalizeMediaBuyStatusCollision(response, toolName, requestRelease.validationVersion);
3001
3000
  injectEnvelopeStatusIntoResponse(response, toolName, requestRelease.validationVersion);
3002
3001
  injectContextIntoResponse(response, params.context);
@@ -10,11 +10,11 @@
10
10
  * response schema doesn't define it would add a key the schema
11
11
  * doesn't expect.
12
12
  *
13
- * Derived from the active schema-loader authority. Bundle inventories are
14
- * memoised by bundle key and resolved root, with loader-epoch invalidation
15
- * so scoped or re-registered candidate bundles cannot leak.
16
- * Raw external roots use the loader's response index when no bundled
17
- * store exists.
13
+ * Derived from the active schema-loader authority, one tool at a time: a
14
+ * lookup reads only that tool's response schema, and results are memoised
15
+ * by bundle key and resolved root, with loader-epoch invalidation so scoped
16
+ * or re-registered candidate bundles cannot leak. Raw external roots use the
17
+ * loader's response index when no bundled store exists.
18
18
  *
19
19
  * Spec basis: `error-code.json#GOVERNANCE_DENIED` and
20
20
  * `#GOVERNANCE_UNAVAILABLE` both prescribe "populate `errors[].code` in
@@ -40,16 +40,25 @@ export interface ErrorArmDescriptor {
40
40
  extraRequired: Readonly<Record<string, unknown>>;
41
41
  }
42
42
  /**
43
- * Per-tool descriptors for tools whose response schema (at `version`)
44
- * declares a top-level Error arm requiring `errors[]`. Dispatcher-side
45
- * gate for two-layer auto-emission, plus the per-arm constants the
46
- * dispatcher needs to set when synthesising the wrap.
43
+ * Error-arm descriptor of `toolName`'s response schema at `version`, or
44
+ * undefined when the response declares no top-level Error arm requiring
45
+ * `errors[]`. Dispatcher-side gate for two-layer auto-emission, plus the
46
+ * per-arm constants the dispatcher sets when synthesising the wrap.
47
47
  *
48
- * Scans the active schema authority lazily. Missing roots return an empty map
49
- * without caching, so later external registration takes effect. Re-registering
50
- * or entering another schema scope invalidates cached inventories, including
51
- * replacements of candidate bundles at the same path.
48
+ * Reads only that tool's response schema, once per loader generation.
49
+ * Missing roots return undefined without caching, so later external
50
+ * registration takes effect. Re-registering or entering another schema
51
+ * scope starts a new generation, including replacements of candidate
52
+ * bundles at the same path.
53
+ */
54
+ export declare function getErrorArmDescriptor(toolName: string, version?: string): ErrorArmDescriptor | undefined;
55
+ /**
56
+ * Every tool at `version` whose response declares an Error arm, built from
57
+ * the same per-tool lookups and cache as {@link getErrorArmDescriptor}. Tool
58
+ * names come from the bundled store's response files, or from the loader's
59
+ * response index for raw external roots. For audits and tests; the
60
+ * dispatcher looks tools up one at a time.
52
61
  */
53
62
  export declare function getToolsWithErrorArm(version?: string): ReadonlyMap<string, ErrorArmDescriptor>;
54
- /** Test hook: clear cached error-arm inventories. */
63
+ /** Test hook: clear cached error-arm lookups. */
55
64
  export declare function _resetErrorArmToolsCache(): void;
@@ -10,11 +10,11 @@
10
10
  * response schema doesn't define it would add a key the schema
11
11
  * doesn't expect.
12
12
  *
13
- * Derived from the active schema-loader authority. Bundle inventories are
14
- * memoised by bundle key and resolved root, with loader-epoch invalidation
15
- * so scoped or re-registered candidate bundles cannot leak.
16
- * Raw external roots use the loader's response index when no bundled
17
- * store exists.
13
+ * Derived from the active schema-loader authority, one tool at a time: a
14
+ * lookup reads only that tool's response schema, and results are memoised
15
+ * by bundle key and resolved root, with loader-epoch invalidation so scoped
16
+ * or re-registered candidate bundles cannot leak. Raw external roots use the
17
+ * loader's response index when no bundled store exists.
18
18
  *
19
19
  * Spec basis: `error-code.json#GOVERNANCE_DENIED` and
20
20
  * `#GOVERNANCE_UNAVAILABLE` both prescribe "populate `errors[].code` in
@@ -40,16 +40,25 @@ export interface ErrorArmDescriptor {
40
40
  extraRequired: Readonly<Record<string, unknown>>;
41
41
  }
42
42
  /**
43
- * Per-tool descriptors for tools whose response schema (at `version`)
44
- * declares a top-level Error arm requiring `errors[]`. Dispatcher-side
45
- * gate for two-layer auto-emission, plus the per-arm constants the
46
- * dispatcher needs to set when synthesising the wrap.
43
+ * Error-arm descriptor of `toolName`'s response schema at `version`, or
44
+ * undefined when the response declares no top-level Error arm requiring
45
+ * `errors[]`. Dispatcher-side gate for two-layer auto-emission, plus the
46
+ * per-arm constants the dispatcher sets when synthesising the wrap.
47
47
  *
48
- * Scans the active schema authority lazily. Missing roots return an empty map
49
- * without caching, so later external registration takes effect. Re-registering
50
- * or entering another schema scope invalidates cached inventories, including
51
- * replacements of candidate bundles at the same path.
48
+ * Reads only that tool's response schema, once per loader generation.
49
+ * Missing roots return undefined without caching, so later external
50
+ * registration takes effect. Re-registering or entering another schema
51
+ * scope starts a new generation, including replacements of candidate
52
+ * bundles at the same path.
53
+ */
54
+ export declare function getErrorArmDescriptor(toolName: string, version?: string): ErrorArmDescriptor | undefined;
55
+ /**
56
+ * Every tool at `version` whose response declares an Error arm, built from
57
+ * the same per-tool lookups and cache as {@link getErrorArmDescriptor}. Tool
58
+ * names come from the bundled store's response files, or from the loader's
59
+ * response index for raw external roots. For audits and tests; the
60
+ * dispatcher looks tools up one at a time.
52
61
  */
53
62
  export declare function getToolsWithErrorArm(version?: string): ReadonlyMap<string, ErrorArmDescriptor>;
54
- /** Test hook: clear cached error-arm inventories. */
63
+ /** Test hook: clear cached error-arm lookups. */
55
64
  export declare function _resetErrorArmToolsCache(): void;
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var error_arm_tools_exports = {};
30
30
  __export(error_arm_tools_exports, {
31
31
  _resetErrorArmToolsCache: () => _resetErrorArmToolsCache,
32
+ getErrorArmDescriptor: () => getErrorArmDescriptor,
32
33
  getToolsWithErrorArm: () => getToolsWithErrorArm
33
34
  });
34
35
  module.exports = __toCommonJS(error_arm_tools_exports);
@@ -70,69 +71,116 @@ function describeErrorArm(branch, rootSchema) {
70
71
  }
71
72
  return { extraRequired: Object.freeze(extraRequired) };
72
73
  }
73
- function scanForErrorArmTools(root, version) {
74
- const bundledRoot = import_path.default.join(root, "bundled");
75
- const map = /* @__PURE__ */ new Map();
76
- let manifestTools;
74
+ function readManifestTools(root) {
77
75
  try {
78
76
  const manifest = JSON.parse((0, import_fs.readFileSync)(import_path.default.join(root, "manifest.json"), "utf-8"));
79
- if (manifest.tools) manifestTools = new Set(Object.keys(manifest.tools));
77
+ return manifest.tools ? new Set(Object.keys(manifest.tools)) : void 0;
80
78
  } catch {
79
+ return void 0;
80
+ }
81
+ }
82
+ function listResponseFiles(root) {
83
+ const bundledRoot = import_path.default.join(root, "bundled");
84
+ if (!(0, import_bundled_schema_store.hasBundledSchemaStore)(bundledRoot)) return void 0;
85
+ const byTool = /* @__PURE__ */ new Map();
86
+ for (const file of (0, import_bundled_schema_store.listBundledSchemaFiles)(bundledRoot)) {
87
+ if (!file.endsWith("-response.json")) continue;
88
+ const toolName = import_path.default.basename(file, "-response.json").replace(/-/g, "_");
89
+ const files = byTool.get(toolName);
90
+ if (files) files.push(file);
91
+ else byTool.set(toolName, [file]);
92
+ }
93
+ return byTool;
94
+ }
95
+ function describeResponse(schema) {
96
+ const branches = schema.oneOf ?? schema.anyOf;
97
+ if (!Array.isArray(branches)) return void 0;
98
+ for (const branch of branches) {
99
+ const candidate = describeErrorArm(branch, schema);
100
+ if (candidate) return candidate;
101
+ }
102
+ return void 0;
103
+ }
104
+ function resolveDescriptor(index, toolName) {
105
+ if (index.manifestTools && !index.manifestTools.has(toolName)) return void 0;
106
+ if (!index.responseFiles) {
107
+ try {
108
+ const schema = (0, import_schema_loader.getToolSchemaDocument)(toolName, "sync", index.version)?.schema;
109
+ return schema ? describeResponse(schema) : void 0;
110
+ } catch {
111
+ return void 0;
112
+ }
81
113
  }
82
- const bundled = (0, import_bundled_schema_store.hasBundledSchemaStore)(bundledRoot);
83
- const responses = bundled ? (0, import_bundled_schema_store.listBundledSchemaFiles)(bundledRoot).filter((file) => file.endsWith("-response.json")).map((file) => ({ toolName: import_path.default.basename(file, "-response.json").replace(/-/g, "_"), file })) : (0, import_schema_loader.listValidatorKeys)(version).filter((key) => key.endsWith("::sync")).map((key) => ({ toolName: key.slice(0, -"::sync".length), file: void 0 }));
84
- for (const { toolName, file } of responses) {
114
+ let descriptor;
115
+ for (const file of index.responseFiles.get(toolName) ?? []) {
85
116
  let schema;
86
117
  try {
87
- const loaded = file ? (0, import_bundled_schema_store.loadBundledSchemaFile)(file) : (0, import_schema_loader.getToolSchemaDocument)(toolName, "sync", version)?.schema;
88
- if (!loaded) continue;
89
- schema = loaded;
118
+ schema = (0, import_bundled_schema_store.loadBundledSchemaFile)(file);
90
119
  } catch {
91
120
  continue;
92
121
  }
93
- const branches = schema.oneOf ?? schema.anyOf;
94
- if (!Array.isArray(branches)) continue;
95
- let descriptor;
96
- for (const branch of branches) {
97
- const candidate = describeErrorArm(branch, schema);
98
- if (candidate) {
99
- descriptor = candidate;
100
- break;
101
- }
102
- }
103
- if (!descriptor) continue;
104
- if (manifestTools && !manifestTools.has(toolName)) continue;
105
- map.set(toolName, descriptor);
122
+ const candidate = schema ? describeResponse(schema) : void 0;
123
+ if (candidate) descriptor = candidate;
106
124
  }
107
- return map;
125
+ return descriptor;
108
126
  }
109
127
  let cachedGeneration = -1;
110
- const cachedMaps = /* @__PURE__ */ new Map();
111
- function getToolsWithErrorArm(version = import_version.ADCP_VERSION) {
128
+ const cachedIndexes = /* @__PURE__ */ new Map();
129
+ function activeRootIndex(version) {
112
130
  const bundleKey = (0, import_schema_loader.resolveBundleKey)(version);
113
131
  let root;
114
132
  try {
115
133
  root = (0, import_schema_loader.resolveSchemaRoot)(version);
116
134
  } catch {
117
- return /* @__PURE__ */ new Map();
135
+ return void 0;
118
136
  }
119
137
  const generation = (0, import_schema_loader.getSchemaLoaderGeneration)();
120
138
  if (cachedGeneration !== generation) {
121
- cachedMaps.clear();
139
+ cachedIndexes.clear();
122
140
  cachedGeneration = generation;
123
141
  }
124
142
  const key = `${bundleKey}\0${import_path.default.resolve(root)}`;
125
- const cached = cachedMaps.get(key);
126
- if (cached) return cached;
127
- const map = scanForErrorArmTools(root, version);
128
- cachedMaps.set(key, map);
143
+ let index = cachedIndexes.get(key);
144
+ if (!index) {
145
+ index = {
146
+ root,
147
+ version,
148
+ manifestTools: readManifestTools(root),
149
+ responseFiles: listResponseFiles(root),
150
+ descriptors: /* @__PURE__ */ new Map()
151
+ };
152
+ cachedIndexes.set(key, index);
153
+ }
154
+ return index;
155
+ }
156
+ function getErrorArmDescriptor(toolName, version = import_version.ADCP_VERSION) {
157
+ const index = activeRootIndex(version);
158
+ if (!index) return void 0;
159
+ const cached = index.descriptors.get(toolName);
160
+ if (cached !== void 0) return cached ?? void 0;
161
+ const descriptor = resolveDescriptor(index, toolName);
162
+ index.descriptors.set(toolName, descriptor ?? null);
163
+ return descriptor;
164
+ }
165
+ function getToolsWithErrorArm(version = import_version.ADCP_VERSION) {
166
+ const index = activeRootIndex(version);
167
+ if (!index) return /* @__PURE__ */ new Map();
168
+ if (index.inventory) return index.inventory;
169
+ const names = index.responseFiles ? [...index.responseFiles.keys()] : (0, import_schema_loader.listValidatorKeys)(version).filter((key) => key.endsWith("::sync")).map((key) => key.slice(0, -"::sync".length));
170
+ const map = /* @__PURE__ */ new Map();
171
+ for (const toolName of names) {
172
+ const descriptor = getErrorArmDescriptor(toolName, version);
173
+ if (descriptor) map.set(toolName, descriptor);
174
+ }
175
+ index.inventory = map;
129
176
  return map;
130
177
  }
131
178
  function _resetErrorArmToolsCache() {
132
- cachedMaps.clear();
179
+ cachedIndexes.clear();
133
180
  }
134
181
  // Annotate the CommonJS export names for ESM import in node:
135
182
  0 && (module.exports = {
136
183
  _resetErrorArmToolsCache,
184
+ getErrorArmDescriptor,
137
185
  getToolsWithErrorArm
138
186
  });
@@ -46,68 +46,115 @@ function describeErrorArm(branch, rootSchema) {
46
46
  }
47
47
  return { extraRequired: Object.freeze(extraRequired) };
48
48
  }
49
- function scanForErrorArmTools(root, version) {
50
- const bundledRoot = path.join(root, "bundled");
51
- const map = /* @__PURE__ */ new Map();
52
- let manifestTools;
49
+ function readManifestTools(root) {
53
50
  try {
54
51
  const manifest = JSON.parse(readFileSync(path.join(root, "manifest.json"), "utf-8"));
55
- if (manifest.tools) manifestTools = new Set(Object.keys(manifest.tools));
52
+ return manifest.tools ? new Set(Object.keys(manifest.tools)) : void 0;
56
53
  } catch {
54
+ return void 0;
55
+ }
56
+ }
57
+ function listResponseFiles(root) {
58
+ const bundledRoot = path.join(root, "bundled");
59
+ if (!hasBundledSchemaStore(bundledRoot)) return void 0;
60
+ const byTool = /* @__PURE__ */ new Map();
61
+ for (const file of listBundledSchemaFiles(bundledRoot)) {
62
+ if (!file.endsWith("-response.json")) continue;
63
+ const toolName = path.basename(file, "-response.json").replace(/-/g, "_");
64
+ const files = byTool.get(toolName);
65
+ if (files) files.push(file);
66
+ else byTool.set(toolName, [file]);
67
+ }
68
+ return byTool;
69
+ }
70
+ function describeResponse(schema) {
71
+ const branches = schema.oneOf ?? schema.anyOf;
72
+ if (!Array.isArray(branches)) return void 0;
73
+ for (const branch of branches) {
74
+ const candidate = describeErrorArm(branch, schema);
75
+ if (candidate) return candidate;
76
+ }
77
+ return void 0;
78
+ }
79
+ function resolveDescriptor(index, toolName) {
80
+ if (index.manifestTools && !index.manifestTools.has(toolName)) return void 0;
81
+ if (!index.responseFiles) {
82
+ try {
83
+ const schema = getToolSchemaDocument(toolName, "sync", index.version)?.schema;
84
+ return schema ? describeResponse(schema) : void 0;
85
+ } catch {
86
+ return void 0;
87
+ }
57
88
  }
58
- const bundled = hasBundledSchemaStore(bundledRoot);
59
- const responses = bundled ? listBundledSchemaFiles(bundledRoot).filter((file) => file.endsWith("-response.json")).map((file) => ({ toolName: path.basename(file, "-response.json").replace(/-/g, "_"), file })) : listValidatorKeys(version).filter((key) => key.endsWith("::sync")).map((key) => ({ toolName: key.slice(0, -"::sync".length), file: void 0 }));
60
- for (const { toolName, file } of responses) {
89
+ let descriptor;
90
+ for (const file of index.responseFiles.get(toolName) ?? []) {
61
91
  let schema;
62
92
  try {
63
- const loaded = file ? loadBundledSchemaFile(file) : getToolSchemaDocument(toolName, "sync", version)?.schema;
64
- if (!loaded) continue;
65
- schema = loaded;
93
+ schema = loadBundledSchemaFile(file);
66
94
  } catch {
67
95
  continue;
68
96
  }
69
- const branches = schema.oneOf ?? schema.anyOf;
70
- if (!Array.isArray(branches)) continue;
71
- let descriptor;
72
- for (const branch of branches) {
73
- const candidate = describeErrorArm(branch, schema);
74
- if (candidate) {
75
- descriptor = candidate;
76
- break;
77
- }
78
- }
79
- if (!descriptor) continue;
80
- if (manifestTools && !manifestTools.has(toolName)) continue;
81
- map.set(toolName, descriptor);
97
+ const candidate = schema ? describeResponse(schema) : void 0;
98
+ if (candidate) descriptor = candidate;
82
99
  }
83
- return map;
100
+ return descriptor;
84
101
  }
85
102
  let cachedGeneration = -1;
86
- const cachedMaps = /* @__PURE__ */ new Map();
87
- function getToolsWithErrorArm(version = ADCP_VERSION) {
103
+ const cachedIndexes = /* @__PURE__ */ new Map();
104
+ function activeRootIndex(version) {
88
105
  const bundleKey = resolveBundleKey(version);
89
106
  let root;
90
107
  try {
91
108
  root = resolveSchemaRoot(version);
92
109
  } catch {
93
- return /* @__PURE__ */ new Map();
110
+ return void 0;
94
111
  }
95
112
  const generation = getSchemaLoaderGeneration();
96
113
  if (cachedGeneration !== generation) {
97
- cachedMaps.clear();
114
+ cachedIndexes.clear();
98
115
  cachedGeneration = generation;
99
116
  }
100
117
  const key = `${bundleKey}\0${path.resolve(root)}`;
101
- const cached = cachedMaps.get(key);
102
- if (cached) return cached;
103
- const map = scanForErrorArmTools(root, version);
104
- cachedMaps.set(key, map);
118
+ let index = cachedIndexes.get(key);
119
+ if (!index) {
120
+ index = {
121
+ root,
122
+ version,
123
+ manifestTools: readManifestTools(root),
124
+ responseFiles: listResponseFiles(root),
125
+ descriptors: /* @__PURE__ */ new Map()
126
+ };
127
+ cachedIndexes.set(key, index);
128
+ }
129
+ return index;
130
+ }
131
+ function getErrorArmDescriptor(toolName, version = ADCP_VERSION) {
132
+ const index = activeRootIndex(version);
133
+ if (!index) return void 0;
134
+ const cached = index.descriptors.get(toolName);
135
+ if (cached !== void 0) return cached ?? void 0;
136
+ const descriptor = resolveDescriptor(index, toolName);
137
+ index.descriptors.set(toolName, descriptor ?? null);
138
+ return descriptor;
139
+ }
140
+ function getToolsWithErrorArm(version = ADCP_VERSION) {
141
+ const index = activeRootIndex(version);
142
+ if (!index) return /* @__PURE__ */ new Map();
143
+ if (index.inventory) return index.inventory;
144
+ const names = index.responseFiles ? [...index.responseFiles.keys()] : listValidatorKeys(version).filter((key) => key.endsWith("::sync")).map((key) => key.slice(0, -"::sync".length));
145
+ const map = /* @__PURE__ */ new Map();
146
+ for (const toolName of names) {
147
+ const descriptor = getErrorArmDescriptor(toolName, version);
148
+ if (descriptor) map.set(toolName, descriptor);
149
+ }
150
+ index.inventory = map;
105
151
  return map;
106
152
  }
107
153
  function _resetErrorArmToolsCache() {
108
- cachedMaps.clear();
154
+ cachedIndexes.clear();
109
155
  }
110
156
  export {
111
157
  _resetErrorArmToolsCache,
158
+ getErrorArmDescriptor,
112
159
  getToolsWithErrorArm
113
160
  };