@xemahq/llm-registry-internal-api-client 0.7.29 → 0.15.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 (82) hide show
  1. package/README.md +1 -1
  2. package/dist/custom-fetch.d.ts +53 -9
  3. package/dist/custom-fetch.js +323 -24
  4. package/dist/endpoints/agent-reach-tier-declarations/agent-reach-tier-declarations.d.ts +11 -0
  5. package/dist/endpoints/agent-reach-tier-declarations/agent-reach-tier-declarations.js +37 -0
  6. package/dist/endpoints/contribution-sync/contribution-sync.d.ts +2 -0
  7. package/dist/endpoints/contribution-sync/contribution-sync.js +12 -1
  8. package/dist/endpoints/internal-managed-model-resolution-rules/internal-managed-model-resolution-rules.d.ts +2 -14
  9. package/dist/endpoints/internal-managed-model-resolution-rules/internal-managed-model-resolution-rules.js +2 -34
  10. package/dist/endpoints/internal-org-model-default/internal-org-model-default.d.ts +12 -0
  11. package/dist/endpoints/internal-org-model-default/internal-org-model-default.js +19 -0
  12. package/dist/endpoints/internal-org-providers/internal-org-providers.d.ts +12 -0
  13. package/dist/endpoints/internal-org-providers/internal-org-providers.js +38 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js +3 -0
  16. package/dist/models/agentInvokeRequestDto.d.ts +18 -4
  17. package/dist/models/agentReachTier.d.ts +15 -0
  18. package/dist/models/{modelResolutionRuleResponseDtoTargetKind.js → agentReachTier.js} +6 -4
  19. package/dist/models/agentReachTierDeclarationDto.d.ts +17 -0
  20. package/dist/models/agentReachTierDeclarationPageDto.d.ts +14 -0
  21. package/dist/models/agentReachTierDeclarationPageDtoDataEnvelope.d.ts +9 -0
  22. package/dist/models/exactLogicalModelResolutionDto.d.ts +2 -1
  23. package/dist/models/index.d.ts +17 -15
  24. package/dist/models/index.js +17 -15
  25. package/dist/models/internalAgentReachTierControllerReachTierDeclarationsParams.d.ts +11 -0
  26. package/dist/models/internalOrgModelDefaultDto.d.ts +15 -0
  27. package/dist/models/internalOrgModelDefaultDtoDataEnvelope.d.ts +9 -0
  28. package/dist/models/internalOrgModelDefaultDtoDataEnvelope.js +2 -0
  29. package/dist/models/internalOrgProviderDto.d.ts +13 -0
  30. package/dist/models/internalOrgProviderDto.js +2 -0
  31. package/dist/models/internalOrgProviderDtoDataArrayEnvelope.d.ts +9 -0
  32. package/dist/models/internalOrgProviderDtoDataArrayEnvelope.js +2 -0
  33. package/dist/models/internalOrgProvidersControllerListParams.d.ts +11 -0
  34. package/dist/models/logicalModelIntentDto.d.ts +5 -2
  35. package/dist/models/logicalModelIntentDto.js +5 -0
  36. package/dist/models/modelResolutionRuleResponseDto.d.ts +9 -42
  37. package/dist/models/modelResolutionSelectorDto.d.ts +5 -3
  38. package/dist/models/modelResolutionSelectorResponseDto.d.ts +1 -2
  39. package/dist/models/problemActionableBy.d.ts +15 -0
  40. package/dist/models/{upsertManagedModelResolutionRuleDtoTargetKind.js → problemActionableBy.js} +6 -4
  41. package/dist/models/problemDetailsDto.d.ts +37 -0
  42. package/dist/models/problemDetailsDto.js +2 -0
  43. package/dist/models/problemDetailsDtoParams.d.ts +11 -0
  44. package/dist/models/{errorDetailsDtoDetails.d.ts → problemDetailsDtoParams.js} +2 -6
  45. package/dist/models/problemFieldIssueDto.d.ts +16 -0
  46. package/dist/models/problemFieldIssueDto.js +2 -0
  47. package/dist/models/problemFieldIssueDtoParams.d.ts +11 -0
  48. package/dist/models/problemFieldIssueDtoParams.js +7 -0
  49. package/dist/models/problemRetry.d.ts +14 -0
  50. package/dist/models/problemRetry.js +13 -0
  51. package/dist/models/providerOwnerSpaceKind.d.ts +13 -0
  52. package/dist/models/providerOwnerSpaceKind.js +12 -0
  53. package/dist/models/resolveExactLogicalModelDto.d.ts +27 -3
  54. package/dist/models/upsertManagedModelResolutionRuleDto.d.ts +10 -12
  55. package/package.json +30 -3
  56. package/dist/models/defaultTargetRefDto.d.ts +0 -11
  57. package/dist/models/errorDetailsDto.d.ts +0 -10
  58. package/dist/models/errorPayloadDto.d.ts +0 -11
  59. package/dist/models/errorResponseDto.d.ts +0 -9
  60. package/dist/models/modelClass.d.ts +0 -14
  61. package/dist/models/modelClass.js +0 -16
  62. package/dist/models/modelResolutionRuleResponseDtoDefaultTargetOverridePrevModelClass.d.ts +0 -17
  63. package/dist/models/modelResolutionRuleResponseDtoDefaultTargetOverridePrevModelClass.js +0 -15
  64. package/dist/models/modelResolutionRuleResponseDtoDefaultTargetOverridePrevTargetKind.d.ts +0 -14
  65. package/dist/models/modelResolutionRuleResponseDtoDefaultTargetOverridePrevTargetKind.js +0 -12
  66. package/dist/models/modelResolutionRuleResponseDtoTargetKind.d.ts +0 -10
  67. package/dist/models/modelResolutionRuleResponseDtoTargetModelClass.d.ts +0 -16
  68. package/dist/models/modelResolutionRuleResponseDtoTargetModelClass.js +0 -15
  69. package/dist/models/modelResolutionSelectorDtoModelClass.d.ts +0 -16
  70. package/dist/models/modelResolutionSelectorDtoModelClass.js +0 -15
  71. package/dist/models/modelResolutionSelectorResponseDtoModelClass.d.ts +0 -16
  72. package/dist/models/modelResolutionSelectorResponseDtoModelClass.js +0 -15
  73. package/dist/models/repointDefaultTargetDto.d.ts +0 -10
  74. package/dist/models/upsertManagedModelResolutionRuleDtoTargetKind.d.ts +0 -13
  75. package/dist/models/upsertManagedModelResolutionRuleDtoTargetModelClass.d.ts +0 -16
  76. package/dist/models/upsertManagedModelResolutionRuleDtoTargetModelClass.js +0 -15
  77. /package/dist/models/{errorDetailsDto.js → agentReachTierDeclarationDto.js} +0 -0
  78. /package/dist/models/{errorPayloadDto.js → agentReachTierDeclarationPageDto.js} +0 -0
  79. /package/dist/models/{errorResponseDto.js → agentReachTierDeclarationPageDtoDataEnvelope.js} +0 -0
  80. /package/dist/models/{defaultTargetRefDto.js → internalAgentReachTierControllerReachTierDeclarationsParams.js} +0 -0
  81. /package/dist/models/{repointDefaultTargetDto.js → internalOrgModelDefaultDto.js} +0 -0
  82. /package/dist/models/{errorDetailsDtoDetails.js → internalOrgProvidersControllerListParams.js} +0 -0
package/README.md CHANGED
@@ -59,4 +59,4 @@ from the service's OpenAPI spec.
59
59
 
60
60
  ## License
61
61
 
62
- Proprietary — © Xema. All rights reserved. — [xema.dev](https://xema.dev)
62
+ LicenseRef-Xema-BSL-1.1 — © Neuralchowder Inc.. All rights reserved.
@@ -1,11 +1,21 @@
1
1
  /**
2
2
  * Configurable fetch wrapper for Orval-generated clients.
3
3
  *
4
- * GENERATED by `@xemahq/api-client-generator` — do not edit. Every client in
5
- * the fleet ships this file byte-for-byte; a local edit is erased by the next
6
- * `pnpm refresh` and, until then, makes this one client speak to the platform
7
- * differently from all of its siblings. Change the template instead:
8
- * `api-client-generator/src/lib/custom-fetch-template.ts`.
4
+ * AUTO-GENERATED by `@xemahq/api-client-generator` — DO NOT EDIT. Every client
5
+ * in the fleet ships this file byte-for-byte; a hand edit is erased by the next
6
+ * regeneration and, until then, makes this one client speak to the platform
7
+ * differently from all of its siblings.
8
+ *
9
+ * Canonical source: `CANONICAL_CUSTOM_FETCH` in
10
+ * `packages/sdks/api-client-generator/src/lib/custom-fetch-template.ts`
11
+ * (repository `xema-kernel-sdk`). Change it there.
12
+ *
13
+ * Regenerate, from the root of THIS repository:
14
+ * pnpm --filter <owning-service> run openapi
15
+ * pnpm --filter <owning-service> run client:generate
16
+ * A mirror of this client under `xema-host-web` is not regenerated there: it
17
+ * is written by the frontend bridge, `tooling/frontend-bridge` in the
18
+ * xema-monorepo aggregator.
9
19
  *
10
20
  * Consumers must call `configureClient()` before using any endpoint function.
11
21
  * The baseUrl is prepended to the relative paths generated by Orval.
@@ -31,6 +41,31 @@ export interface RetryNotice {
31
41
  /** HTTP method being re-requested. */
32
42
  method: string;
33
43
  }
44
+ /**
45
+ * Per-request context handed to the callbacks this transport awaits BEFORE it
46
+ * sends the request.
47
+ *
48
+ * `signal` is the request's own `AbortSignal` (`options.signal`). It is the
49
+ * CALLER's cancellation: a callback may use it to stop work that is private to
50
+ * this request, but a callback serving several requests from one shared,
51
+ * single-flight acquisition (a token refresh) must NOT abort that shared work
52
+ * because one caller stopped — every other caller waiting on it would fail.
53
+ * The transport stops WAITING on its own regardless, so a callback that
54
+ * ignores the signal still cannot hold an aborted request.
55
+ */
56
+ export interface ClientCallbackOptions {
57
+ signal?: AbortSignal;
58
+ }
59
+ /** What {@link ClientConfig.onUnauthorized} is told about the 401 it answers. */
60
+ export interface UnauthorizedContext {
61
+ /**
62
+ * The token `getAuthToken` returned for the attempt the server rejected.
63
+ * `undefined` when no `getAuthToken` produced the Authorization header
64
+ * (a header from `getHeaders` or no credential at all): there is then no
65
+ * client-held token to drop.
66
+ */
67
+ readonly rejectedToken: string | undefined;
68
+ }
34
69
  export interface ClientConfig {
35
70
  /**
36
71
  * Static base URL (e.g. 'http://localhost:3140') — no trailing slash.
@@ -42,9 +77,13 @@ export interface ClientConfig {
42
77
  * the service registry on EVERY request (boot-order-safe). Wired by
43
78
  * `configureOrvalClientResolved` from `@xemahq/platform-common`.
44
79
  */
45
- baseUrlResolver?: () => string | Promise<string>;
46
- /** Optional async callback to get an auth token. Auto-sets Authorization header on every request. */
47
- getAuthToken?: () => Promise<string>;
80
+ baseUrlResolver?: (options?: ClientCallbackOptions) => string | Promise<string>;
81
+ /**
82
+ * Optional async callback to get an auth token. Auto-sets Authorization
83
+ * header on every request. Receives the request's signal — see
84
+ * {@link ClientCallbackOptions} for what it may and may not abort.
85
+ */
86
+ getAuthToken?: (options?: ClientCallbackOptions) => Promise<string>;
48
87
  /** Optional callback returning headers to inject on every request. Per-call headers take precedence. */
49
88
  getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
50
89
  /**
@@ -73,8 +112,12 @@ export interface ClientConfig {
73
112
  * Optional callback invoked on a 401 before ONE re-attempt. Supplying it is
74
113
  * what opts this client into that re-attempt; without it a 401 comes back to
75
114
  * the caller as a `ClientError` like any other 4xx.
115
+ *
116
+ * It is told WHAT was rejected (see {@link UnauthorizedContext}), so a
117
+ * callback that drops a cached credential can drop exactly that one and leave
118
+ * a newer one, minted by a concurrent request, alone.
76
119
  */
77
- onUnauthorized?: () => Promise<void>;
120
+ onUnauthorized?: (context: UnauthorizedContext) => Promise<void>;
78
121
  /**
79
122
  * Re-attempts for a retryable status. **Defaults to 0 — no retry.**
80
123
  *
@@ -97,6 +140,7 @@ export declare class ClientError extends Error {
97
140
  readonly url: string;
98
141
  readonly body: unknown;
99
142
  constructor(status: number, url: string, body: unknown);
143
+ static [Symbol.hasInstance](candidate: unknown): boolean;
100
144
  }
101
145
  export declare function configureClient(config: ClientConfig): void;
102
146
  export declare function getClientConfig(): ClientConfig;
@@ -2,11 +2,21 @@
2
2
  /**
3
3
  * Configurable fetch wrapper for Orval-generated clients.
4
4
  *
5
- * GENERATED by `@xemahq/api-client-generator` — do not edit. Every client in
6
- * the fleet ships this file byte-for-byte; a local edit is erased by the next
7
- * `pnpm refresh` and, until then, makes this one client speak to the platform
8
- * differently from all of its siblings. Change the template instead:
9
- * `api-client-generator/src/lib/custom-fetch-template.ts`.
5
+ * AUTO-GENERATED by `@xemahq/api-client-generator` — DO NOT EDIT. Every client
6
+ * in the fleet ships this file byte-for-byte; a hand edit is erased by the next
7
+ * regeneration and, until then, makes this one client speak to the platform
8
+ * differently from all of its siblings.
9
+ *
10
+ * Canonical source: `CANONICAL_CUSTOM_FETCH` in
11
+ * `packages/sdks/api-client-generator/src/lib/custom-fetch-template.ts`
12
+ * (repository `xema-kernel-sdk`). Change it there.
13
+ *
14
+ * Regenerate, from the root of THIS repository:
15
+ * pnpm --filter <owning-service> run openapi
16
+ * pnpm --filter <owning-service> run client:generate
17
+ * A mirror of this client under `xema-host-web` is not regenerated there: it
18
+ * is written by the frontend bridge, `tooling/frontend-bridge` in the
19
+ * xema-monorepo aggregator.
10
20
  *
11
21
  * Consumers must call `configureClient()` before using any endpoint function.
12
22
  * The baseUrl is prepended to the relative paths generated by Orval.
@@ -19,6 +29,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
29
  exports.customFetch = exports.ClientError = void 0;
20
30
  exports.configureClient = configureClient;
21
31
  exports.getClientConfig = getClientConfig;
32
+ /**
33
+ * Cross-package identity for `ClientError`.
34
+ *
35
+ * ── THE OUTAGE THIS IS FOR ────────────────────────────────────────────────
36
+ *
37
+ * PRODUCTION, 2026-09-22. A session launch aborted on
38
+ * `HTTP 503 from http://skill-registry-api…/skills`. A 503 is the archetypal
39
+ * TRANSIENT — agent-session's launch taxonomy already listed it as retryable —
40
+ * but it was classified PERMANENT and the launch was abandoned.
41
+ *
42
+ * The cause was this file. Every generated client package gets its OWN copy of
43
+ * `ClientError`, so there are as many classes as there are clients (81 at the
44
+ * time of writing), all byte-identical and all DIFFERENT OBJECTS. A consumer
45
+ * naturally writes `err instanceof ClientError` against the one client it
46
+ * imported — which reads as obviously correct and is silently package-local. An
47
+ * error from any OTHER client fails it, falls past every status check, and lands
48
+ * on whatever the default is.
49
+ *
50
+ * That was not the first time: biome-host had already switched to structural
51
+ * detection for the same reason, and canopy imports TWO `ClientError` classes
52
+ * and tests both. Three more call sites elsewhere carry the same shape.
53
+ *
54
+ * ── WHY A BRAND AND NOT A SHARED PACKAGE ─────────────────────────────────
55
+ *
56
+ * The obvious fix is one shared runtime class every client imports. It was
57
+ * rejected on measurement: the 81 generated clients are DEPENDENCY-FREE by
58
+ * design (exactly one has any dependency at all), and a shared class would have
59
+ * to be a PEER dependency to be safe — a normal dependency can be installed
60
+ * twice under version skew, which reinstates this identical bug in a form that
61
+ * is HARDER to see, because the classes then look like they ought to match.
62
+ *
63
+ * `Symbol.for` is a process-wide registry keyed by STRING, so every copy of
64
+ * this template resolves the same symbol without importing anything. The brand
65
+ * costs no dependency, cannot skew, and needs no new package.
66
+ *
67
+ * `Symbol.hasInstance` then makes plain `instanceof` mean the right thing
68
+ * fleet-wide: an error from ANY generated client satisfies `instanceof
69
+ * ClientError` in ANY other. A helper would have made the safe pattern
70
+ * available; this makes the dangerous pattern impossible.
71
+ *
72
+ * Narrow on purpose — the brand is set only by this constructor, so an unrelated
73
+ * error carrying a `status` is not admitted.
74
+ */
75
+ const CLIENT_ERROR_BRAND = Symbol.for('xema.generatedClientError');
22
76
  class ClientError extends Error {
23
77
  status;
24
78
  url;
@@ -29,10 +83,67 @@ class ClientError extends Error {
29
83
  this.url = url;
30
84
  this.body = body;
31
85
  this.name = 'ClientError';
86
+ // Non-enumerable: it must not appear in JSON, logs or snapshots — it is an
87
+ // identity marker, not payload.
88
+ Object.defineProperty(this, CLIENT_ERROR_BRAND, { value: true });
89
+ }
90
+ // `override` because the member shadows `Function.prototype[Symbol.hasInstance]`,
91
+ // which a class constructor inherits: TypeScript 5.9+ reports TS4114 without it
92
+ // under `noImplicitOverride`. Measured to compile on 5.5.4, 5.9.3, 6.0.3 and
93
+ // 7.0.2 with the flag on AND off — pinned by
94
+ // tests/custom-fetch-compiles-standalone.test.cjs.
95
+ static [Symbol.hasInstance](candidate) {
96
+ return (typeof candidate === 'object' &&
97
+ candidate !== null &&
98
+ CLIENT_ERROR_BRAND in candidate);
32
99
  }
33
100
  }
34
101
  exports.ClientError = ClientError;
35
102
  let clientConfig = null;
103
+ /**
104
+ * THE MOUNT SCOPE — how one process can host several services without their
105
+ * clients speaking for each other.
106
+ *
107
+ * `clientConfig` below is a MODULE global, and in a single-service process
108
+ * that is correct: one writer, one configuration. Compose two services into one
109
+ * process and both call `configureClient` on THIS SAME module instance, so the
110
+ * second overwrites the first and every outbound call from BOTH services leaves
111
+ * as whichever wired itself last — wrong base URL, and, because
112
+ * `getAuthToken` is part of the config, WRONG BEARER. That is one tenant's
113
+ * service calling a peer holding another tenant's credential, and it is silent.
114
+ *
115
+ * A composing host installs a hook under this well-known symbol that answers
116
+ * one question: WHICH MOUNT is currently on the stack. Nothing else crosses.
117
+ * `configureClient` then files the config under that mount, and
118
+ * `getClientConfig` reads it back out under the same key.
119
+ *
120
+ * Three properties make this safe rather than clever:
121
+ *
122
+ * - The CONFIG is still built by the mount's own wiring, exactly as today.
123
+ * The hook never supplies one. So a mount's base URL and bearer are
124
+ * resolved FROM THE MOUNT; the scope only decides which drawer they go in.
125
+ * A hook that RETURNED configuration would be a mount taking its identity
126
+ * from ambient storage a neighbour can write — the inversion to refuse.
127
+ * - The key is an OPAQUE OBJECT and the store is a `WeakMap`, so a mount's
128
+ * configuration becomes unreachable when the host drops the mount, and no
129
+ * client can enumerate the mounts or reach a sibling's entry.
130
+ * - With NO hook installed — every process in the fleet today — both
131
+ * functions behave exactly as they did before this existed.
132
+ *
133
+ * `Symbol.for` is the seam because a generated client must keep its
134
+ * dependency surface at zero and a host cannot enumerate the clients a process
135
+ * happens to load. It is the same instrument, and the same reasoning, as the
136
+ * `ClientError` brand above.
137
+ */
138
+ const XEMA_CLIENT_CONFIG_SCOPE = Symbol.for('xema.client-config-scope');
139
+ function mountScopeHook() {
140
+ const hook = globalThis[XEMA_CLIENT_CONFIG_SCOPE];
141
+ return typeof hook === 'function' ? hook : undefined;
142
+ }
143
+ function currentMountKey() {
144
+ return mountScopeHook()?.();
145
+ }
146
+ const perMountConfig = new WeakMap();
36
147
  function configureClient(config) {
37
148
  // Fail at WIRING time, not on the request that happens to be retried. A
38
149
  // client configured to retry without an observer is the exact defect this
@@ -42,9 +153,38 @@ function configureClient(config) {
42
153
  'reports is indistinguishable from a slow server, which is how two ' +
43
154
  'silent re-attempts were read as a 3,312ms call.');
44
155
  }
156
+ const hook = mountScopeHook();
157
+ if (hook !== undefined) {
158
+ const mount = hook();
159
+ if (mount === undefined) {
160
+ // A composing host is installed and no member is on the stack, so this
161
+ // configuration belongs to NO member. Filing it in the module global
162
+ // would hand it to every member that did not configure this client —
163
+ // someone else's base URL and bearer, silently.
164
+ throw new Error('configureClient: called in a composed process outside every member. ' +
165
+ 'Configure the client inside the member that uses it (its providers ' +
166
+ 'and factories already run there).');
167
+ }
168
+ perMountConfig.set(mount, config);
169
+ return;
170
+ }
45
171
  clientConfig = config;
46
172
  }
47
173
  function getClientConfig() {
174
+ const mount = currentMountKey();
175
+ if (mount !== undefined) {
176
+ const scoped = perMountConfig.get(mount);
177
+ if (scoped) {
178
+ return scoped;
179
+ }
180
+ // A member that never configured THIS client behaves exactly like a
181
+ // dedicated service that did not either: it is refused. It used to fall
182
+ // through to the module global, which in a composed process can only have
183
+ // been written by some OTHER code — so the member called peers under a
184
+ // base URL and bearer that were never its own.
185
+ throw new Error('Client not configured for this member. Call configureClient({ baseUrl }) ' +
186
+ 'inside the member before using endpoint functions.');
187
+ }
48
188
  if (!clientConfig) {
49
189
  throw new Error('Client not configured. Call configureClient({ baseUrl }) before using endpoint functions.');
50
190
  }
@@ -103,11 +243,64 @@ const CORRELATION_ID_HEADER = 'X-Correlation-Id';
103
243
  const BASE_BACKOFF_MS = 1000;
104
244
  /** Ceiling on a single backoff, however many attempts have elapsed. */
105
245
  const MAX_BACKOFF_MS = 30_000;
106
- async function buildHeaders(config, callerHeaders) {
246
+ /*
247
+ * CALLER CANCELLATION REACHES EVERY WAIT BEFORE THE REQUEST IS SENT.
248
+ *
249
+ * `fetch` always honoured `options.signal`, but everything this transport
250
+ * awaits BEFORE `fetch` — base-URL resolution, the header callbacks, the auth
251
+ * token — did not, so a caller that aborted while a token was being minted sat
252
+ * out the mint and then, at best, had its request refused. The only way to
253
+ * cancel that wait was a process-wide interceptor aborting every outbound
254
+ * request, which also aborts a SHARED single-flight token refresh and so fails
255
+ * every other caller waiting on it.
256
+ *
257
+ * So each pre-send wait is RACED against the signal: the caller stops waiting
258
+ * at once, and the work it was waiting on carries on for anybody else. The
259
+ * rejection is the signal's own reason — exactly what `fetch` rejects with —
260
+ * so a caller sees ONE abort shape whenever it aborts. An aborted request is
261
+ * never retried. Without a signal nothing here changes.
262
+ */
263
+ function abortedReason(signal) {
264
+ // `abort()` with no argument sets a DOMException reason, so this is only
265
+ // ever `undefined` for a hand-built signal; say so rather than throw it.
266
+ return signal.reason ?? new DOMException('This operation was aborted', 'AbortError');
267
+ }
268
+ function throwIfAborted(signal) {
269
+ if (signal?.aborted) {
270
+ throw abortedReason(signal);
271
+ }
272
+ }
273
+ function raceAbort(pending, signal) {
274
+ const promise = Promise.resolve(pending);
275
+ if (!signal) {
276
+ return promise;
277
+ }
278
+ if (signal.aborted) {
279
+ promise.catch(() => undefined);
280
+ return Promise.reject(abortedReason(signal));
281
+ }
282
+ return new Promise((resolve, reject) => {
283
+ const onAbort = () => {
284
+ // The pending work may be shared; it carries on, and its eventual
285
+ // rejection must not surface as an unhandled one on this side.
286
+ promise.catch(() => undefined);
287
+ reject(abortedReason(signal));
288
+ };
289
+ signal.addEventListener('abort', onAbort, { once: true });
290
+ promise.then((value) => {
291
+ signal.removeEventListener('abort', onAbort);
292
+ resolve(value);
293
+ }, (err) => {
294
+ signal.removeEventListener('abort', onAbort);
295
+ reject(err);
296
+ });
297
+ });
298
+ }
299
+ async function buildHeaders(config, callerHeaders, signal) {
107
300
  const headers = new Headers(callerHeaders);
108
301
  // Global headers from config (caller-provided headers take precedence)
109
302
  if (config.getHeaders) {
110
- const globalHeaders = await Promise.resolve(config.getHeaders());
303
+ const globalHeaders = await raceAbort(config.getHeaders(), signal);
111
304
  for (const [key, value] of Object.entries(globalHeaders)) {
112
305
  if (!headers.has(key)) {
113
306
  headers.set(key, value);
@@ -126,17 +319,18 @@ async function buildHeaders(config, callerHeaders) {
126
319
  // receiver mints and a new trace begins, which is the truthful outcome when
127
320
  // there is nothing to continue.
128
321
  if (config.getCorrelationId && !headers.has(CORRELATION_ID_HEADER)) {
129
- const correlationId = await Promise.resolve(config.getCorrelationId());
322
+ const correlationId = await raceAbort(config.getCorrelationId(), signal);
130
323
  if (correlationId) {
131
324
  headers.set(CORRELATION_ID_HEADER, correlationId);
132
325
  }
133
326
  }
134
327
  // Auth token (caller or global headers take precedence)
328
+ let authToken;
135
329
  if (config.getAuthToken && !headers.has('Authorization')) {
136
- const token = await config.getAuthToken();
137
- headers.set('Authorization', `Bearer ${token}`);
330
+ authToken = await raceAbort(config.getAuthToken(signal ? { signal } : undefined), signal);
331
+ headers.set('Authorization', `Bearer ${authToken}`);
138
332
  }
139
- return headers;
333
+ return { headers, authToken };
140
334
  }
141
335
  /*
142
336
  * THE TRANSPORT RETURNS THE BODY UNCHANGED. Do not reintroduce an unwrap here.
@@ -163,8 +357,10 @@ async function buildHeaders(config, callerHeaders) {
163
357
  */
164
358
  const customFetch = async (url, options) => {
165
359
  const config = getClientConfig();
360
+ const signal = options.signal ?? undefined;
361
+ throwIfAborted(signal);
166
362
  const base = config.baseUrlResolver
167
- ? await config.baseUrlResolver()
363
+ ? await raceAbort(config.baseUrlResolver(signal ? { signal } : undefined), signal)
168
364
  : config.baseUrl;
169
365
  if (base === undefined) {
170
366
  throw new Error('Client not configured: set baseUrl or baseUrlResolver via configureClient().');
@@ -176,8 +372,8 @@ const customFetch = async (url, options) => {
176
372
  // re-sending would replay the identical failing request with the identical
177
373
  // credential: one wasted round trip, plus a global refresh nobody asked for.
178
374
  const callerSuppliedAuth = new Headers(options.headers).has('Authorization');
179
- const headers = await buildHeaders(config, options.headers);
180
- const requestInit = { ...options, headers };
375
+ const built = await buildHeaders(config, options.headers, signal);
376
+ const requestInit = { ...options, headers: built.headers };
181
377
  let delay = BASE_BACKOFF_MS;
182
378
  for (let attempt = 0;; attempt++) {
183
379
  const response = await fetch(fullUrl, requestInit);
@@ -185,11 +381,11 @@ const customFetch = async (url, options) => {
185
381
  config.onUnauthorized &&
186
382
  !callerSuppliedAuth &&
187
383
  attempt === 0) {
188
- await config.onUnauthorized();
189
- const refreshedHeaders = await buildHeaders(config, options.headers);
384
+ await raceAbort(config.onUnauthorized({ rejectedToken: built.authToken }), signal);
385
+ const refreshed = await buildHeaders(config, options.headers, signal);
190
386
  const retryResponse = await fetch(fullUrl, {
191
387
  ...options,
192
- headers: refreshedHeaders,
388
+ headers: refreshed.headers,
193
389
  });
194
390
  const retryBody = await parseBody(retryResponse);
195
391
  if (retryResponse.status >= 400) {
@@ -218,20 +414,106 @@ const customFetch = async (url, options) => {
218
414
  url: fullUrl,
219
415
  method: options.method ?? 'GET',
220
416
  });
221
- await sleep(waitMs);
417
+ await sleep(waitMs, signal);
222
418
  delay = Math.min(delay * 2, MAX_BACKOFF_MS);
223
419
  }
224
420
  };
225
421
  exports.customFetch = customFetch;
422
+ /**
423
+ * Does this media type carry JSON?
424
+ *
425
+ * ── THE OUTAGE THIS FIXES ────────────────────────────────────────────────
426
+ *
427
+ * This used to be `contentType?.includes('application/json')`, and EVERY error
428
+ * this fleet returns failed that test. The platform's `GlobalExceptionFilter`
429
+ * emits RFC 9457 problem documents and sets the media type explicitly —
430
+ * `.type(PROBLEM_DETAILS_CONTENT_TYPE)` before `.json()`, so it cannot be
431
+ * overridden — and that constant is `application/problem+json`, which does NOT
432
+ * contain the substring `application/json`: after `application/` comes
433
+ * `problem+json`.
434
+ *
435
+ * So every non-2xx body fell through to `response.text()` and reached the
436
+ * caller as an UNPARSED STRING. `ClientError.body` is typed `unknown`, so
437
+ * nothing complained; every consumer that reads a machine-readable code off an
438
+ * error — `error.body.code`, `error.body.details.code` — silently read
439
+ * `undefined` instead, for every error, in every service.
440
+ *
441
+ * Measured in production on 2026-09-15: skill-registry-api's
442
+ * `resolveOrNull()` absorbs `RELEASE_CHANNEL_NOT_FOUND` into `null` by exactly
443
+ * that read. With the code unreadable the absorb never fired, a routine "no
444
+ * pointer on this channel" 404 became a 500 on `GET /skills` and
445
+ * `GET /describe-objects`, and agent-session-api's `apply_control_bundle` step
446
+ * aborted EVERY session launch in the organisation — 7,871 failed resolutions
447
+ * an hour. A fix written for that exact page months earlier was present in the
448
+ * running image and could not help, because the classifier it repaired was
449
+ * being handed a string.
450
+ *
451
+ * ── WHY THE STRUCTURED SUFFIX, NOT A SECOND SUBSTRING ────────────────────
452
+ *
453
+ * Adding `|| includes('application/problem+json')` would fix this one media
454
+ * type and leave the next one — `application/vnd.api+json`, and anything else
455
+ * a service legitimately emits. RFC 6839 defines `+json` as the structured
456
+ * syntax suffix meaning "this is JSON"; that is the actual rule, so it is the
457
+ * rule implemented. Parameters are stripped first, because
458
+ * `application/problem+json; charset=utf-8` is the same media type.
459
+ */
460
+ function isJsonMediaType(contentType) {
461
+ if (contentType === null) {
462
+ return false;
463
+ }
464
+ const essence = contentType.split(';')[0]?.trim().toLowerCase() ?? '';
465
+ return essence === 'application/json' || essence.endsWith('+json');
466
+ }
467
+ /**
468
+ * Does this media type carry TEXT a caller reads as a string?
469
+ *
470
+ * The response body is decoded by its declared media type, in three classes,
471
+ * and each class matches what the generated function's return type says for
472
+ * the schema such a route declares:
473
+ *
474
+ * - JSON (`application/json` or an RFC 6839 `+json` suffix) → parsed;
475
+ * - TEXT (`text/*` — including `text/event-stream` — `application/javascript`,
476
+ * `application/ecmascript`, `application/xml` or an RFC 7303 `+xml`
477
+ * suffix) → a string, which is what a `{ type: string }` schema generates;
478
+ * - anything else — `application/octet-stream`, `application/gzip`,
479
+ * `application/pdf`, an Office document type, any `format: binary` body —
480
+ * → a `Blob`, which is what a `format: binary` schema generates.
481
+ *
482
+ * Reading every non-JSON body as text, as this transport did until 2026-10-04,
483
+ * handed a caller typed `Blob` a string: `response.text()` decodes the bytes
484
+ * as UTF-8, so a PDF or a gzip tarball arrived corrupted under a type that
485
+ * promised the bytes.
486
+ *
487
+ * A response with NO content type is read as text, so an empty body stays the
488
+ * empty string it always was.
489
+ */
490
+ function isTextMediaType(contentType) {
491
+ const essence = contentType.split(';')[0]?.trim().toLowerCase() ?? '';
492
+ return (essence.startsWith('text/') ||
493
+ essence === 'application/javascript' ||
494
+ essence === 'application/ecmascript' ||
495
+ essence === 'application/xml' ||
496
+ essence.endsWith('+xml'));
497
+ }
226
498
  async function parseBody(response) {
499
+ // 204 FIRST, and deliberately — this ORDER is carried from `develop`, which
500
+ // fixed the same defect independently and got this half right where `main`
501
+ // did not. A 204 carries no body, so `response.json()` on one throws
502
+ // SyntaxError; and a 204 whose headers STILL declare a JSON content type is
503
+ // ordinary, because the framework sets the header before the handler returns
504
+ // nothing. With the JSON branch first, a documented `undefined` becomes a
505
+ // thrown parse error. Pinned by a case in `transport-problem-json.test.cjs`.
506
+ if (response.status === 204) {
507
+ return undefined;
508
+ }
227
509
  const contentType = response.headers.get('content-type');
228
- if (contentType?.includes('application/json')) {
510
+ if (isJsonMediaType(contentType)) {
229
511
  return response.json();
230
512
  }
231
- if (response.status === 204) {
232
- return undefined;
513
+ if (contentType === null || isTextMediaType(contentType)) {
514
+ return response.text();
233
515
  }
234
- return response.text();
516
+ return response.blob();
235
517
  }
236
518
  function parseRetryAfter(value) {
237
519
  if (!value)
@@ -247,7 +529,24 @@ function parseRetryAfter(value) {
247
529
  function addJitter(delay) {
248
530
  return delay + (Math.random() * 2 - 1) * delay * 0.25;
249
531
  }
250
- function sleep(ms) {
251
- return new Promise((resolve) => setTimeout(resolve, ms));
532
+ /** A retry backoff; the caller's signal ends it at once and is never retried. */
533
+ function sleep(ms, signal) {
534
+ if (!signal) {
535
+ return new Promise((resolve) => setTimeout(resolve, ms));
536
+ }
537
+ if (signal.aborted) {
538
+ return Promise.reject(abortedReason(signal));
539
+ }
540
+ return new Promise((resolve, reject) => {
541
+ const onAbort = () => {
542
+ clearTimeout(timer);
543
+ reject(abortedReason(signal));
544
+ };
545
+ const timer = setTimeout(() => {
546
+ signal.removeEventListener('abort', onAbort);
547
+ resolve();
548
+ }, ms);
549
+ signal.addEventListener('abort', onAbort, { once: true });
550
+ });
252
551
  }
253
552
  exports.default = exports.customFetch;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generated by @xemahq/api-client-generator — do not edit manually.
3
+ * LLM Registry API
4
+ * OpenAPI spec version: 0.1.3
5
+ */
6
+ import type { AgentReachTierDeclarationPageDtoDataEnvelope, InternalAgentReachTierControllerReachTierDeclarationsParams } from '../../models';
7
+ export declare const getInternalAgentReachTierControllerReachTierDeclarationsUrl: (params?: InternalAgentReachTierControllerReachTierDeclarationsParams) => string;
8
+ /**
9
+ * @summary Every Agent's DECLARED reach-tier ceiling, across every tenant, for a consumer-owned projection.
10
+ */
11
+ export declare const internalAgentReachTierControllerReachTierDeclarations: (params?: InternalAgentReachTierControllerReachTierDeclarationsParams, options?: RequestInit) => Promise<AgentReachTierDeclarationPageDtoDataEnvelope>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.internalAgentReachTierControllerReachTierDeclarations = exports.getInternalAgentReachTierControllerReachTierDeclarationsUrl = void 0;
4
+ const custom_fetch_1 = require("../../custom-fetch");
5
+ const getInternalAgentReachTierControllerReachTierDeclarationsUrl = (params) => {
6
+ const normalizedParams = new URLSearchParams();
7
+ Object.entries(params || {}).forEach(([key, value]) => {
8
+ if (value === undefined)
9
+ return;
10
+ if (value === null) {
11
+ normalizedParams.append(key, 'null');
12
+ return;
13
+ }
14
+ if (Array.isArray(value)) {
15
+ for (const item of value) {
16
+ if (item === undefined || item === null)
17
+ continue;
18
+ normalizedParams.append(key, item.toString());
19
+ }
20
+ return;
21
+ }
22
+ normalizedParams.append(key, value.toString());
23
+ });
24
+ const stringifiedParams = normalizedParams.toString();
25
+ return stringifiedParams.length > 0 ? `/internal/agents/reach-tier-declarations?${stringifiedParams}` : `/internal/agents/reach-tier-declarations`;
26
+ };
27
+ exports.getInternalAgentReachTierControllerReachTierDeclarationsUrl = getInternalAgentReachTierControllerReachTierDeclarationsUrl;
28
+ /**
29
+ * @summary Every Agent's DECLARED reach-tier ceiling, across every tenant, for a consumer-owned projection.
30
+ */
31
+ const internalAgentReachTierControllerReachTierDeclarations = async (params, options) => {
32
+ return (0, custom_fetch_1.customFetch)((0, exports.getInternalAgentReachTierControllerReachTierDeclarationsUrl)(params), {
33
+ ...options,
34
+ method: 'GET'
35
+ });
36
+ };
37
+ exports.internalAgentReachTierControllerReachTierDeclarations = internalAgentReachTierControllerReachTierDeclarations;
@@ -1,2 +1,4 @@
1
1
  export declare const getContributionSyncControllerSyncUrl: () => string;
2
2
  export declare const contributionSyncControllerSync: (options?: RequestInit) => Promise<void>;
3
+ export declare const getContributionSyncControllerSyncOrgUrl: (orgId: string) => string;
4
+ export declare const contributionSyncControllerSyncOrg: (orgId: string, options?: RequestInit) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contributionSyncControllerSync = exports.getContributionSyncControllerSyncUrl = void 0;
3
+ exports.contributionSyncControllerSyncOrg = exports.getContributionSyncControllerSyncOrgUrl = exports.contributionSyncControllerSync = exports.getContributionSyncControllerSyncUrl = void 0;
4
4
  /**
5
5
  * Generated by @xemahq/api-client-generator — do not edit manually.
6
6
  * LLM Registry API
@@ -18,3 +18,14 @@ const contributionSyncControllerSync = async (options) => {
18
18
  });
19
19
  };
20
20
  exports.contributionSyncControllerSync = contributionSyncControllerSync;
21
+ const getContributionSyncControllerSyncOrgUrl = (orgId) => {
22
+ return `/contributions/orgs/${orgId}/sync`;
23
+ };
24
+ exports.getContributionSyncControllerSyncOrgUrl = getContributionSyncControllerSyncOrgUrl;
25
+ const contributionSyncControllerSyncOrg = async (orgId, options) => {
26
+ return (0, custom_fetch_1.customFetch)((0, exports.getContributionSyncControllerSyncOrgUrl)(orgId), {
27
+ ...options,
28
+ method: 'PUT'
29
+ });
30
+ };
31
+ exports.contributionSyncControllerSyncOrg = contributionSyncControllerSyncOrg;
@@ -3,25 +3,13 @@
3
3
  * LLM Registry API
4
4
  * OpenAPI spec version: 0.1.3
5
5
  */
6
- import type { ModelResolutionRuleResponseDtoDataEnvelope, RepointDefaultTargetDto, UpsertManagedModelResolutionRuleDto } from '../../models';
6
+ import type { ModelResolutionRuleResponseDtoDataEnvelope, UpsertManagedModelResolutionRuleDto } from '../../models';
7
7
  export declare const getManagedModelResolutionRuleControllerUpsertUrl: (orgId: string) => string;
8
8
  /**
9
- * Upserts a rule keyed by (orgId, owner, managedKey). The owner is derived from the authenticated service subject. Re-PUT with the same managedKey updates the rule in place. A managed rule can never be the org default.
9
+ * Upserts a rule keyed by (orgId, owner, managedKey). The owner is derived from the authenticated service subject. Re-PUT with the same managedKey updates the rule in place.
10
10
  * @summary Idempotently upsert a service-owned Model Resolution Matrix rule
11
11
  */
12
12
  export declare const managedModelResolutionRuleControllerUpsert: (orgId: string, upsertManagedModelResolutionRuleDto: UpsertManagedModelResolutionRuleDto, options?: RequestInit) => Promise<ModelResolutionRuleResponseDtoDataEnvelope>;
13
- export declare const getManagedModelResolutionRuleControllerRepointDefaultTargetUrl: (orgId: string) => string;
14
- /**
15
- * Repoints the TARGET of the org's EXISTING single default rule (empty selector) to a concrete model. Does NOT create a second default, change the selector, or transfer ownership — the rule stays provisioning-owned. Captures the prior target on the first override (for revert) under the authenticated service subject; a second service is refused (403). Fail-fast 404 if the org has no default rule.
16
- * @summary Repoint ONLY the org default rule's target (managed steer)
17
- */
18
- export declare const managedModelResolutionRuleControllerRepointDefaultTarget: (orgId: string, repointDefaultTargetDto: RepointDefaultTargetDto, options?: RequestInit) => Promise<ModelResolutionRuleResponseDtoDataEnvelope>;
19
- export declare const getManagedModelResolutionRuleControllerRevertDefaultTargetUrl: (orgId: string) => string;
20
- /**
21
- * Restores the target captured before the FIRST service override and clears all override state. Idempotent — an absent override is a no-op success. Only the service that set the override may clear it (403 otherwise). Fail-fast 404 if the org has no default rule.
22
- * @summary Revert the org default rule's target to its pre-override value
23
- */
24
- export declare const managedModelResolutionRuleControllerRevertDefaultTarget: (orgId: string, options?: RequestInit) => Promise<ModelResolutionRuleResponseDtoDataEnvelope>;
25
13
  export declare const getManagedModelResolutionRuleControllerRemoveUrl: (orgId: string, managedKey: string) => string;
26
14
  /**
27
15
  * Deletes the caller's own rule identified by (orgId, owner, managedKey). Idempotent — removing a non-existent rule succeeds. Scoped to the authenticated service's ownership; a service can only delete its own rules.