@xemahq/memory-api-client 0.2.2 → 0.2.4
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.
- package/dist/custom-fetch.d.ts +68 -16
- package/dist/custom-fetch.js +156 -55
- package/dist/endpoints/memory/memory.d.ts +1 -3
- package/dist/endpoints/org-admin/org-admin.d.ts +1 -3
- package/dist/index.d.ts +1 -1
- package/dist/models/appendEntryBodyDto.d.ts +1 -3
- package/dist/models/appendEntryBodyDto.js +1 -3
- package/dist/models/createMemoryBodyDto.d.ts +1 -3
- package/dist/models/createMemoryBodyDto.js +1 -3
- package/dist/models/maintenanceOrgAdminControllerListRunsParams.d.ts +1 -3
- package/dist/models/maintenanceOrgAdminControllerListRunsParams.js +1 -3
- package/dist/models/maintenanceProposalResponseDto.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoAppliedAt.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoAppliedAt.js +1 -3
- package/dist/models/maintenanceProposalResponseDtoDataEnvelope.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoKind.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoKind.js +1 -3
- package/dist/models/maintenanceProposalResponseDtoPayload.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoPayload.js +1 -3
- package/dist/models/maintenanceProposalResponseDtoReason.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoReason.js +1 -3
- package/dist/models/maintenanceProposalResponseDtoStatus.d.ts +1 -3
- package/dist/models/maintenanceProposalResponseDtoStatus.js +1 -3
- package/dist/models/maintenanceRunDetailDto.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoCompletedAt.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoCompletedAt.js +1 -3
- package/dist/models/maintenanceRunDetailDtoDataEnvelope.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoMode.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoMode.js +1 -3
- package/dist/models/maintenanceRunDetailDtoStatus.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoStatus.js +1 -3
- package/dist/models/maintenanceRunDetailDtoTotals.d.ts +1 -3
- package/dist/models/maintenanceRunDetailDtoTotals.js +1 -3
- package/dist/models/maintenanceRunResponseDto.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoCompletedAt.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoCompletedAt.js +1 -3
- package/dist/models/maintenanceRunResponseDtoDataArrayEnvelope.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoMode.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoMode.js +1 -3
- package/dist/models/maintenanceRunResponseDtoStatus.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoStatus.js +1 -3
- package/dist/models/maintenanceRunResponseDtoTotals.d.ts +1 -3
- package/dist/models/maintenanceRunResponseDtoTotals.js +1 -3
- package/dist/models/memoriesUiControllerDeleteFileParams.d.ts +1 -3
- package/dist/models/memoriesUiControllerDeleteFileParams.js +1 -3
- package/dist/models/memoriesUiControllerGetFileParams.d.ts +1 -3
- package/dist/models/memoriesUiControllerGetFileParams.js +1 -3
- package/dist/models/memoriesUiControllerListParams.d.ts +1 -3
- package/dist/models/memoriesUiControllerSearchParams.d.ts +1 -3
- package/dist/models/memoryDetailDto.d.ts +1 -3
- package/dist/models/memoryDetailDtoDataEnvelope.d.ts +1 -3
- package/dist/models/memoryKind.d.ts +1 -3
- package/dist/models/memoryKind.js +1 -3
- package/dist/models/memoryListResponseDto.d.ts +1 -3
- package/dist/models/memoryListResponseDtoDataEnvelope.d.ts +1 -3
- package/dist/models/memoryProjectDto.d.ts +1 -3
- package/dist/models/memoryProjectDto.js +1 -3
- package/dist/models/memoryProjectListResponseDto.d.ts +1 -3
- package/dist/models/memoryProjectListResponseDtoDataEnvelope.d.ts +1 -3
- package/dist/models/memoryScope.d.ts +1 -3
- package/dist/models/memoryScope.js +1 -3
- package/dist/models/memorySearchResponseDto.d.ts +1 -3
- package/dist/models/memorySearchResponseDtoDataEnvelope.d.ts +1 -3
- package/dist/models/memorySummaryDto.d.ts +1 -3
- package/dist/models/memorySummaryDtoDataEnvelope.d.ts +1 -3
- package/dist/models/memorySurface.d.ts +1 -3
- package/dist/models/memorySurface.js +1 -3
- package/dist/models/orgAdminStartRunBodyDto.d.ts +1 -3
- package/dist/models/orgAdminStartRunBodyDtoMode.d.ts +1 -3
- package/dist/models/orgAdminStartRunBodyDtoMode.js +1 -3
- package/dist/models/renameMemoryBodyDto.d.ts +1 -3
- package/dist/models/renameMemoryBodyDto.js +1 -3
- package/dist/models/startMaintenanceRunResponseDto.d.ts +1 -3
- package/dist/models/startMaintenanceRunResponseDtoDataEnvelope.d.ts +1 -3
- package/dist/models/strReplaceBodyDto.d.ts +1 -3
- package/dist/models/strReplaceBodyDto.js +1 -3
- package/package.json +3 -3
package/dist/custom-fetch.d.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
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`.
|
|
9
|
+
*
|
|
4
10
|
* Consumers must call `configureClient()` before using any endpoint function.
|
|
5
11
|
* The baseUrl is prepended to the relative paths generated by Orval.
|
|
6
12
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - Automatic 401 handling via `onUnauthorized` callback (single retry)
|
|
11
|
-
* - Exponential-backoff retry for transient failures (429, 502, 503, 504)
|
|
12
|
-
* - Typed `ClientError` for non-2xx responses
|
|
13
|
-
* - Per-call header overrides (take precedence over global headers)
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* configureClient({
|
|
17
|
-
* baseUrl: 'http://governance-api:3400',
|
|
18
|
-
* getAuthToken: () => identityBootstrapService.getAccessToken(),
|
|
19
|
-
* getHeaders: () => ({ 'X-Xema-Org-Id': orgId, 'X-Correlation-Id': crypto.randomUUID() }),
|
|
20
|
-
* });
|
|
13
|
+
* By default this transport issues exactly ONE request and adds no delay of its
|
|
14
|
+
* own, so a slow call is a slow server. Retrying is opt-in, and opting in
|
|
15
|
+
* requires supplying an observer — see `maxRetries` / `onRetry` below.
|
|
21
16
|
*/
|
|
17
|
+
/** What {@link ClientConfig.onRetry} is told before each re-attempt. */
|
|
18
|
+
export interface RetryNotice {
|
|
19
|
+
/** 1-based index of the re-attempt about to be made. */
|
|
20
|
+
attempt: number;
|
|
21
|
+
/** The configured budget this re-attempt is spending from. */
|
|
22
|
+
maxRetries: number;
|
|
23
|
+
/** The response status that made the previous attempt retryable. */
|
|
24
|
+
status: number;
|
|
25
|
+
/** Delay before the re-attempt, in ms — from `Retry-After` when the server sent one. */
|
|
26
|
+
waitMs: number;
|
|
27
|
+
/** Whether {@link waitMs} came from the server's `Retry-After` header. */
|
|
28
|
+
retryAfterHonoured: boolean;
|
|
29
|
+
/** Absolute URL being re-requested. */
|
|
30
|
+
url: string;
|
|
31
|
+
/** HTTP method being re-requested. */
|
|
32
|
+
method: string;
|
|
33
|
+
}
|
|
22
34
|
export interface ClientConfig {
|
|
23
35
|
/**
|
|
24
36
|
* Static base URL (e.g. 'http://localhost:3140') — no trailing slash.
|
|
@@ -35,10 +47,50 @@ export interface ClientConfig {
|
|
|
35
47
|
getAuthToken?: () => Promise<string>;
|
|
36
48
|
/** Optional callback returning headers to inject on every request. Per-call headers take precedence. */
|
|
37
49
|
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
38
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Optional resolver for the CORRELATION ID of the request being made — the
|
|
52
|
+
* handle that ties one causal chain together across every service hop.
|
|
53
|
+
*
|
|
54
|
+
* WHY IT IS A CALLBACK AND NOT A VALUE. `ClientConfig` is process-global
|
|
55
|
+
* (`configureClient` is called once at wiring time), and a correlation id is
|
|
56
|
+
* per-request. This is invoked INSIDE the request, so a server can point it
|
|
57
|
+
* at whatever carries its ambient request context and get the CURRENT id
|
|
58
|
+
* rather than the one that happened to be live at boot.
|
|
59
|
+
*
|
|
60
|
+
* WHY THE TRANSPORT DOES NOT MINT ONE. Returning `undefined` sends no header,
|
|
61
|
+
* and the receiving service's `RequestContextMiddleware` mints its own — a
|
|
62
|
+
* new trace, which is honest. A transport that minted per call would produce
|
|
63
|
+
* a FRESH id on every hop while looking like propagation, which is strictly
|
|
64
|
+
* worse than none: every row would carry a correlation id and no two rows
|
|
65
|
+
* that belong together would share one. That is the exact defect this exists
|
|
66
|
+
* to fix, so the transport must not reproduce it one layer down.
|
|
67
|
+
*
|
|
68
|
+
* A caller-supplied `X-Correlation-Id` header always wins, and so does one
|
|
69
|
+
* from `getHeaders`.
|
|
70
|
+
*/
|
|
71
|
+
getCorrelationId?: () => string | undefined | Promise<string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* Optional callback invoked on a 401 before ONE re-attempt. Supplying it is
|
|
74
|
+
* what opts this client into that re-attempt; without it a 401 comes back to
|
|
75
|
+
* the caller as a `ClientError` like any other 4xx.
|
|
76
|
+
*/
|
|
39
77
|
onUnauthorized?: () => Promise<void>;
|
|
40
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Re-attempts for a retryable status. **Defaults to 0 — no retry.**
|
|
80
|
+
*
|
|
81
|
+
* Setting it above 0 REQUIRES `onRetry`; `configureClient` throws otherwise.
|
|
82
|
+
* See the block above `customFetch` for why the budget is opt-in and why an
|
|
83
|
+
* observer is mandatory rather than advisory.
|
|
84
|
+
*/
|
|
41
85
|
maxRetries?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Called immediately before every re-attempt, with the reason and the delay.
|
|
88
|
+
*
|
|
89
|
+
* Mandatory whenever `maxRetries` is above 0. It is the difference between a
|
|
90
|
+
* retry and a hidden degradation path: without it a caller cannot tell a slow
|
|
91
|
+
* server from this transport sleeping between attempts.
|
|
92
|
+
*/
|
|
93
|
+
onRetry?: (notice: RetryNotice) => void;
|
|
42
94
|
}
|
|
43
95
|
export declare class ClientError extends Error {
|
|
44
96
|
readonly status: number;
|
package/dist/custom-fetch.js
CHANGED
|
@@ -2,23 +2,18 @@
|
|
|
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`.
|
|
10
|
+
*
|
|
5
11
|
* Consumers must call `configureClient()` before using any endpoint function.
|
|
6
12
|
* The baseUrl is prepended to the relative paths generated by Orval.
|
|
7
13
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* - Automatic 401 handling via `onUnauthorized` callback (single retry)
|
|
12
|
-
* - Exponential-backoff retry for transient failures (429, 502, 503, 504)
|
|
13
|
-
* - Typed `ClientError` for non-2xx responses
|
|
14
|
-
* - Per-call header overrides (take precedence over global headers)
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* configureClient({
|
|
18
|
-
* baseUrl: 'http://governance-api:3400',
|
|
19
|
-
* getAuthToken: () => identityBootstrapService.getAccessToken(),
|
|
20
|
-
* getHeaders: () => ({ 'X-Xema-Org-Id': orgId, 'X-Correlation-Id': crypto.randomUUID() }),
|
|
21
|
-
* });
|
|
14
|
+
* By default this transport issues exactly ONE request and adds no delay of its
|
|
15
|
+
* own, so a slow call is a slow server. Retrying is opt-in, and opting in
|
|
16
|
+
* requires supplying an observer — see `maxRetries` / `onRetry` below.
|
|
22
17
|
*/
|
|
23
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
19
|
exports.customFetch = exports.ClientError = void 0;
|
|
@@ -39,6 +34,14 @@ class ClientError extends Error {
|
|
|
39
34
|
exports.ClientError = ClientError;
|
|
40
35
|
let clientConfig = null;
|
|
41
36
|
function configureClient(config) {
|
|
37
|
+
// Fail at WIRING time, not on the request that happens to be retried. A
|
|
38
|
+
// client configured to retry without an observer is the exact defect this
|
|
39
|
+
// transport was rebuilt to remove, so it must not be constructible.
|
|
40
|
+
if ((config.maxRetries ?? 0) > 0 && !config.onRetry) {
|
|
41
|
+
throw new Error('configureClient: maxRetries above 0 requires onRetry. A retry nothing ' +
|
|
42
|
+
'reports is indistinguishable from a slow server, which is how two ' +
|
|
43
|
+
'silent re-attempts were read as a 3,312ms call.');
|
|
44
|
+
}
|
|
42
45
|
clientConfig = config;
|
|
43
46
|
}
|
|
44
47
|
function getClientConfig() {
|
|
@@ -47,7 +50,59 @@ function getClientConfig() {
|
|
|
47
50
|
}
|
|
48
51
|
return clientConfig;
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
/*
|
|
54
|
+
* RETRYING IS OPT-IN, OBSERVED, AND NARROW. Do not widen any of the three.
|
|
55
|
+
*
|
|
56
|
+
* This transport used to retry up to `maxRetries` (defaulting to THREE) over
|
|
57
|
+
* 429/502/503/504 AND over any thrown network error, backing off from 1000ms,
|
|
58
|
+
* with no log line anywhere. Three properties were wrong:
|
|
59
|
+
*
|
|
60
|
+
* 1. The DEFAULT was on. ~99% of the fleet's client configurations never
|
|
61
|
+
* mention `maxRetries`, so two re-attempts could add ~3s to any call with
|
|
62
|
+
* nothing to distinguish that from a slow peer. Every caller that DID set
|
|
63
|
+
* it set it LOWER — canopy's control plane to 1, "so a hard outage
|
|
64
|
+
* surfaces inside the turn's latency budget rather than after three
|
|
65
|
+
* backoffs"; two llm-registry callers to 1; a test to 0. Nobody ever
|
|
66
|
+
* raised it. A default three separate call sites work around is not a
|
|
67
|
+
* default, and `configureOrvalClientResolved` cannot express the field at
|
|
68
|
+
* all, so most callers could not have opted out if they had wanted to.
|
|
69
|
+
* 2. It retried AMBIGUOUS failures. 502 and 504 mean a gateway did not get a
|
|
70
|
+
* timely answer from upstream — the upstream may well have APPLIED the
|
|
71
|
+
* request. So did a thrown network error mid-flight. Re-sending a POST in
|
|
72
|
+
* either case is a duplicate write, and no amount of logging makes that
|
|
73
|
+
* safe. Only 429 and 503 state positively that the request was NOT
|
|
74
|
+
* processed, so only those are retried; everything else surfaces at once.
|
|
75
|
+
* 3. Nothing reported it. Now `onRetry` is mandatory whenever the budget is
|
|
76
|
+
* above 0, enforced in `configureClient`.
|
|
77
|
+
*
|
|
78
|
+
* Also note `baseUrlResolver` is awaited ONCE, above the loop: a re-attempt
|
|
79
|
+
* returns to the same resolved instance. In a registry-resolved fleet the cure
|
|
80
|
+
* for an unhealthy peer is re-resolution, which lives above this file — which
|
|
81
|
+
* is a further reason not to lean on retrying here.
|
|
82
|
+
*
|
|
83
|
+
* Retry policy a caller genuinely wants belongs in `@xemahq/managed-fetch`,
|
|
84
|
+
* which has backoff, a circuit breaker, a token bucket and health reporting,
|
|
85
|
+
* and reports what it did.
|
|
86
|
+
*
|
|
87
|
+
* Enforced fleet-wide by `check-client-transport-envelope`, which compares
|
|
88
|
+
* every client's transport to this template.
|
|
89
|
+
*/
|
|
90
|
+
/** The only statuses that state the request was NOT processed. See above. */
|
|
91
|
+
const RETRYABLE_STATUSES = [429, 503];
|
|
92
|
+
/**
|
|
93
|
+
* The platform's correlation header, spelled once.
|
|
94
|
+
*
|
|
95
|
+
* Value-identical to what `RequestContextMiddleware` reads in
|
|
96
|
+
* `@xemahq/platform-common`. It is a literal here rather than an import
|
|
97
|
+
* because this file has ZERO imports on purpose: it ships byte-identical into
|
|
98
|
+
* browser-target clients as well as server-target ones, and a dependency on a
|
|
99
|
+
* NestJS-peer package would follow it into every one of them.
|
|
100
|
+
*/
|
|
101
|
+
const CORRELATION_ID_HEADER = 'X-Correlation-Id';
|
|
102
|
+
/** Backoff floor, doubling per attempt up to {@link MAX_BACKOFF_MS}. */
|
|
103
|
+
const BASE_BACKOFF_MS = 1000;
|
|
104
|
+
/** Ceiling on a single backoff, however many attempts have elapsed. */
|
|
105
|
+
const MAX_BACKOFF_MS = 30_000;
|
|
51
106
|
async function buildHeaders(config, callerHeaders) {
|
|
52
107
|
const headers = new Headers(callerHeaders);
|
|
53
108
|
// Global headers from config (caller-provided headers take precedence)
|
|
@@ -59,6 +114,23 @@ async function buildHeaders(config, callerHeaders) {
|
|
|
59
114
|
}
|
|
60
115
|
}
|
|
61
116
|
}
|
|
117
|
+
// Correlation id (caller and global headers still take precedence).
|
|
118
|
+
//
|
|
119
|
+
// Without this, every server-to-server hop through a generated client started
|
|
120
|
+
// a NEW trace: the id is read-or-minted per hop by the receiving service's
|
|
121
|
+
// RequestContextMiddleware, and nothing carried it outbound — so an audit
|
|
122
|
+
// journal could record a whole causal chain and offer no way to join it back
|
|
123
|
+
// together.
|
|
124
|
+
//
|
|
125
|
+
// Absent resolver, or a resolver that answers `undefined`: NO header. The
|
|
126
|
+
// receiver mints and a new trace begins, which is the truthful outcome when
|
|
127
|
+
// there is nothing to continue.
|
|
128
|
+
if (config.getCorrelationId && !headers.has(CORRELATION_ID_HEADER)) {
|
|
129
|
+
const correlationId = await Promise.resolve(config.getCorrelationId());
|
|
130
|
+
if (correlationId) {
|
|
131
|
+
headers.set(CORRELATION_ID_HEADER, correlationId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
62
134
|
// Auth token (caller or global headers take precedence)
|
|
63
135
|
if (config.getAuthToken && !headers.has('Authorization')) {
|
|
64
136
|
const token = await config.getAuthToken();
|
|
@@ -66,6 +138,29 @@ async function buildHeaders(config, callerHeaders) {
|
|
|
66
138
|
}
|
|
67
139
|
return headers;
|
|
68
140
|
}
|
|
141
|
+
/*
|
|
142
|
+
* THE TRANSPORT RETURNS THE BODY UNCHANGED. Do not reintroduce an unwrap here.
|
|
143
|
+
*
|
|
144
|
+
* Xema services wrap every 2xx payload in a { data: T } envelope via the global
|
|
145
|
+
* ResponseEnvelopeInterceptor (platform-common), and the generator emits types
|
|
146
|
+
* that describe THAT ENVELOPE — every endpoint returns Promise<XDataEnvelope>
|
|
147
|
+
* or Promise<XPaginatedEnvelope>, never a bare inner T. Consumers read the data
|
|
148
|
+
* property themselves.
|
|
149
|
+
*
|
|
150
|
+
* This template used to peel data, justified by a comment claiming generated
|
|
151
|
+
* types describe the inner T. That stopped being true when the generator moved
|
|
152
|
+
* to envelope-typed returns, and the comment outlived the fact — so the peel
|
|
153
|
+
* then contradicted every type in every package it seeded. Four clients shipped
|
|
154
|
+
* that way (resource-governance x3, workload-runtime-api): declared
|
|
155
|
+
* *DataEnvelope, returned the already-peeled inner object, so .data read
|
|
156
|
+
* undefined at runtime on every non-paginated endpoint. Paginated calls hid it,
|
|
157
|
+
* because the old peel deliberately preserved an envelope carrying pagination.
|
|
158
|
+
*
|
|
159
|
+
* Four MORE shipped it in repositories the gate could not see — license-api and
|
|
160
|
+
* license-internal-api in xema-operator, plus their host-web mirrors — because
|
|
161
|
+
* the gate ran in xema-base only. That is why it now runs in every repository
|
|
162
|
+
* that ships a client, and why this file is generator-owned rather than seeded.
|
|
163
|
+
*/
|
|
69
164
|
const customFetch = async (url, options) => {
|
|
70
165
|
const config = getClientConfig();
|
|
71
166
|
const base = config.baseUrlResolver
|
|
@@ -75,51 +170,57 @@ const customFetch = async (url, options) => {
|
|
|
75
170
|
throw new Error('Client not configured: set baseUrl or baseUrlResolver via configureClient().');
|
|
76
171
|
}
|
|
77
172
|
const fullUrl = `${base}${url}`;
|
|
78
|
-
const maxRetries = config.maxRetries ??
|
|
173
|
+
const maxRetries = config.maxRetries ?? 0;
|
|
174
|
+
// A caller that supplied its own Authorization header owns that credential.
|
|
175
|
+
// `buildHeaders` lets it win, so refreshing the CLIENT-WIDE token and
|
|
176
|
+
// re-sending would replay the identical failing request with the identical
|
|
177
|
+
// credential: one wasted round trip, plus a global refresh nobody asked for.
|
|
178
|
+
const callerSuppliedAuth = new Headers(options.headers).has('Authorization');
|
|
79
179
|
const headers = await buildHeaders(config, options.headers);
|
|
80
180
|
const requestInit = { ...options, headers };
|
|
81
|
-
let delay =
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
181
|
+
let delay = BASE_BACKOFF_MS;
|
|
182
|
+
for (let attempt = 0;; attempt++) {
|
|
183
|
+
const response = await fetch(fullUrl, requestInit);
|
|
184
|
+
if (response.status === 401 &&
|
|
185
|
+
config.onUnauthorized &&
|
|
186
|
+
!callerSuppliedAuth &&
|
|
187
|
+
attempt === 0) {
|
|
188
|
+
await config.onUnauthorized();
|
|
189
|
+
const refreshedHeaders = await buildHeaders(config, options.headers);
|
|
190
|
+
const retryResponse = await fetch(fullUrl, {
|
|
191
|
+
...options,
|
|
192
|
+
headers: refreshedHeaders,
|
|
193
|
+
});
|
|
194
|
+
const retryBody = await parseBody(retryResponse);
|
|
195
|
+
if (retryResponse.status >= 400) {
|
|
196
|
+
throw new ClientError(retryResponse.status, fullUrl, retryBody);
|
|
96
197
|
}
|
|
97
|
-
|
|
98
|
-
if (!RETRYABLE_STATUSES.includes(response.status) || attempt >= maxRetries) {
|
|
99
|
-
const body = await parseBody(response);
|
|
100
|
-
if (response.status >= 400) {
|
|
101
|
-
throw new ClientError(response.status, fullUrl, body);
|
|
102
|
-
}
|
|
103
|
-
return body;
|
|
104
|
-
}
|
|
105
|
-
// Retryable — wait and retry
|
|
106
|
-
const retryAfter = parseRetryAfter(response.headers.get('Retry-After'));
|
|
107
|
-
const waitMs = retryAfter ?? addJitter(delay);
|
|
108
|
-
await sleep(waitMs);
|
|
109
|
-
delay = Math.min(delay * 2, 30_000);
|
|
198
|
+
return retryBody;
|
|
110
199
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
await sleep(waitMs);
|
|
119
|
-
delay = Math.min(delay * 2, 30_000);
|
|
200
|
+
if (!RETRYABLE_STATUSES.includes(response.status) ||
|
|
201
|
+
attempt >= maxRetries) {
|
|
202
|
+
const body = await parseBody(response);
|
|
203
|
+
if (response.status >= 400) {
|
|
204
|
+
throw new ClientError(response.status, fullUrl, body);
|
|
205
|
+
}
|
|
206
|
+
return body;
|
|
120
207
|
}
|
|
208
|
+
const retryAfter = parseRetryAfter(response.headers.get('Retry-After'));
|
|
209
|
+
const waitMs = retryAfter ?? addJitter(delay);
|
|
210
|
+
// Non-null: `configureClient` refuses a budget above 0 without an observer,
|
|
211
|
+
// and this line is unreachable unless `maxRetries` is above 0.
|
|
212
|
+
config.onRetry({
|
|
213
|
+
attempt: attempt + 1,
|
|
214
|
+
maxRetries,
|
|
215
|
+
status: response.status,
|
|
216
|
+
waitMs,
|
|
217
|
+
retryAfterHonoured: retryAfter !== undefined,
|
|
218
|
+
url: fullUrl,
|
|
219
|
+
method: options.method ?? 'GET',
|
|
220
|
+
});
|
|
221
|
+
await sleep(waitMs);
|
|
222
|
+
delay = Math.min(delay * 2, MAX_BACKOFF_MS);
|
|
121
223
|
}
|
|
122
|
-
throw lastError ?? new Error(`All retries exhausted for ${fullUrl}`);
|
|
123
224
|
};
|
|
124
225
|
exports.customFetch = customFetch;
|
|
125
226
|
async function parseBody(response) {
|
|
@@ -147,6 +248,6 @@ function addJitter(delay) {
|
|
|
147
248
|
return delay + (Math.random() * 2 - 1) * delay * 0.25;
|
|
148
249
|
}
|
|
149
250
|
function sleep(ms) {
|
|
150
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
251
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
151
252
|
}
|
|
152
253
|
exports.default = exports.customFetch;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
import type { AppendEntryBodyDto, CreateMemoryBodyDto, MemoriesUiControllerDeleteFileParams, MemoriesUiControllerGetFileParams, MemoriesUiControllerListParams, MemoriesUiControllerSearchParams, MemoryDetailDtoDataEnvelope, MemoryListResponseDtoDataEnvelope, MemoryProjectListResponseDtoDataEnvelope, MemorySearchResponseDtoDataEnvelope, MemorySummaryDtoDataEnvelope, RenameMemoryBodyDto, StrReplaceBodyDto } from '../../models';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
import type { MaintenanceOrgAdminControllerListRunsParams, MaintenanceProposalResponseDtoDataEnvelope, MaintenanceRunDetailDtoDataEnvelope, MaintenanceRunResponseDtoDataArrayEnvelope, OrgAdminStartRunBodyDto, StartMaintenanceRunResponseDtoDataEnvelope } from '../../models';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { configureClient, getClientConfig, ClientError, customFetch, type ClientConfig } from './custom-fetch';
|
|
1
|
+
export { configureClient, getClientConfig, ClientError, customFetch, type ClientConfig, type RetryNotice } from './custom-fetch';
|
|
2
2
|
export * from './models';
|
|
3
3
|
export * from './endpoints/memory/memory';
|
|
4
4
|
export * from './endpoints/org-admin/org-admin';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export interface AppendEntryBodyDto {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export interface CreateMemoryBodyDto {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export type MaintenanceOrgAdminControllerListRunsParams = {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
import type { MaintenanceProposalResponseDtoAppliedAt } from './maintenanceProposalResponseDtoAppliedAt.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
/**
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
import type { MaintenanceProposalResponseDto } from './maintenanceProposalResponseDto.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export type MaintenanceProposalResponseDtoKind = typeof MaintenanceProposalResponseDtoKind[keyof typeof MaintenanceProposalResponseDtoKind];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export type MaintenanceProposalResponseDtoPayload = {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
/**
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
export type MaintenanceProposalResponseDtoStatus = typeof MaintenanceProposalResponseDtoStatus[keyof typeof MaintenanceProposalResponseDtoStatus];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
import type { MaintenanceProposalResponseDto } from './maintenanceProposalResponseDto.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generated by
|
|
3
|
-
* Do not edit manually.
|
|
2
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
4
3
|
* Memory API
|
|
5
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
6
4
|
* OpenAPI spec version: 0.1.0
|
|
7
5
|
*/
|
|
8
6
|
/**
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generated by
|
|
4
|
-
* Do not edit manually.
|
|
3
|
+
* Generated by @xemahq/api-client-generator — do not edit manually.
|
|
5
4
|
* Memory API
|
|
6
|
-
* Persistent agent memory — operational insights, decisions, and patterns that survive across executions
|
|
7
5
|
* OpenAPI spec version: 0.1.0
|
|
8
6
|
*/
|
|
9
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|