@expandai/sdk 0.17.2 → 0.19.0
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/README.md +4 -0
- package/build/dts/Client.d.ts +10 -4
- package/build/dts/Client.d.ts.map +1 -1
- package/build/dts/Error.d.ts.map +1 -1
- package/build/dts/FetchJson.d.ts +171 -149
- package/build/dts/FetchJson.d.ts.map +1 -1
- package/build/dts/Generated.d.ts +512 -452
- package/build/dts/Generated.d.ts.map +1 -1
- package/build/dts/HttpClientHelpers.d.ts +1 -1
- package/build/dts/Internal.d.ts +4 -3
- package/build/dts/Internal.d.ts.map +1 -1
- package/build/dts/Playground.d.ts +8 -4
- package/build/dts/Playground.d.ts.map +1 -1
- package/build/dts/Service.d.ts +91 -85
- package/build/dts/Service.d.ts.map +1 -1
- package/build/dts/index.d.ts +1 -1
- package/build/dts/index.d.ts.map +1 -1
- package/build/esm/Client.js +9 -1
- package/build/esm/Client.js.map +1 -1
- package/build/esm/Error.js.map +1 -1
- package/build/esm/FetchJson.js +8 -12
- package/build/esm/FetchJson.js.map +1 -1
- package/build/esm/Generated.js +155 -84
- package/build/esm/Generated.js.map +1 -1
- package/build/esm/Internal.js +38 -9
- package/build/esm/Internal.js.map +1 -1
- package/build/esm/Playground.js +38 -18
- package/build/esm/Playground.js.map +1 -1
- package/build/esm/Service.js +45 -23
- package/build/esm/Service.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/package.json +4 -3
- package/src/Client.ts +15 -2
- package/src/FetchJson.ts +8 -12
- package/src/Generated.ts +217 -111
- package/src/Internal.ts +59 -10
- package/src/Playground.ts +54 -20
- package/src/Service.ts +78 -24
- package/src/index.ts +2 -0
package/build/esm/Internal.js
CHANGED
|
@@ -3,14 +3,20 @@ import { Cause, Effect, HashSet, Layer, Match, Option, ParseResult } from 'effec
|
|
|
3
3
|
import { ExpandApiError, ExpandClientError, ExpandConnectionError, ExpandSdkError, ExpandTimeoutError, } from './Error.js';
|
|
4
4
|
import * as Generated from './Generated.js';
|
|
5
5
|
import { ExpandService, } from './Service.js';
|
|
6
|
-
const RETRYABLE_STATUS_CODES = HashSet.make(408, 409, 429, 500, 502, 503, 504);
|
|
6
|
+
const RETRYABLE_STATUS_CODES = HashSet.make(408, 409, 429, 500, 502, 503, 504, 529);
|
|
7
7
|
function hasApiErrorTag(error, tag) {
|
|
8
8
|
return typeof error === 'object' && error !== null && '_tag' in error && error._tag === tag;
|
|
9
9
|
}
|
|
10
10
|
function apiError(status, error) {
|
|
11
|
-
const message = typeof error === 'object' &&
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const message = typeof error === 'object' &&
|
|
12
|
+
error !== null &&
|
|
13
|
+
'message' in error &&
|
|
14
|
+
typeof error.message === 'string' &&
|
|
15
|
+
error.message.length > 0
|
|
16
|
+
? error.message
|
|
17
|
+
: typeof error === 'object' && error !== null && '_tag' in error && typeof error._tag === 'string'
|
|
18
|
+
? error._tag
|
|
19
|
+
: `HTTP ${status}`;
|
|
14
20
|
return new ExpandApiError({ message, status, body: error, cause: error });
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
@@ -19,12 +25,18 @@ function apiError(status, error) {
|
|
|
19
25
|
* its public error channel.
|
|
20
26
|
*/
|
|
21
27
|
export function toExpandError(error, timeoutMs) {
|
|
22
|
-
|
|
28
|
+
// Split across two `pipe` calls: the arm list is longer than `pipe`'s 20-argument overloads.
|
|
29
|
+
// Arms are evaluated top to bottom across both halves, so the ordering is unaffected.
|
|
30
|
+
const transportAndClientErrors = Match.value(error).pipe(Match.when((error) => error instanceof Cause.TimeoutException, (error) => new ExpandTimeoutError({ message: `Request timed out after ${timeoutMs}ms`, timeoutMs, cause: error })), Match.when((error) => error instanceof HttpClientError.RequestError, (error) => new ExpandConnectionError({ message: error.message, cause: error })), Match.when((error) => error instanceof HttpClientError.ResponseError, (error) => new ExpandApiError({
|
|
23
31
|
message: error.message,
|
|
24
32
|
status: error.response.status,
|
|
25
33
|
body: error.description,
|
|
26
34
|
cause: error,
|
|
27
|
-
})), Match.when((error) => error instanceof Generated.AuthFailed, (error) => new ExpandApiError({ message: 'AuthFailed', status: 401, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'AuthFailed'), (error) => apiError(401, error)), Match.when((error) => hasApiErrorTag(error, 'AccessBlocked'), (error) => apiError(403, error)), Match.when((error) =>
|
|
35
|
+
})), Match.when((error) => error instanceof Generated.AuthFailed, (error) => new ExpandApiError({ message: 'AuthFailed', status: 401, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'AuthFailed'), (error) => apiError(401, error)), Match.when((error) => hasApiErrorTag(error, 'AccessBlocked'), (error) => apiError(403, error)), Match.when((error) => hasApiErrorTag(error, 'BatchedIdempotencyConflict') || hasApiErrorTag(error, 'BatchedCancellationConflict'), (error) => apiError(409, error)), Match.when((error) => error instanceof Generated.PayloadTooLarge, (error) => new ExpandApiError({ message: 'PayloadTooLarge', status: 413, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'PayloadTooLarge'), (error) => apiError(413, error)), Match.when((error) => error instanceof Generated.TooManyRequests, (error) => new ExpandApiError({ message: 'TooManyRequests', status: 429, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'TooManyRequests'), (error) => apiError(429, error)));
|
|
36
|
+
return transportAndClientErrors.pipe(Match.when((error) => error instanceof Generated.InternalError, (error) => new ExpandApiError({ message: 'InternalError', status: 500, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'InternalError'), (error) => apiError(500, error)), Match.when((error) => hasApiErrorTag(error, 'FetchNavigationFailed'), (error) => apiError(502, error)),
|
|
37
|
+
// No `instanceof Generated.ServiceUnavailable` arm: decoded instances carry `_tag`, so the
|
|
38
|
+
// tag predicate already matches them and both would produce the same `apiError(503, ...)`.
|
|
39
|
+
Match.when((error) => hasApiErrorTag(error, 'ServiceUnavailable'), (error) => apiError(503, error)), Match.when((error) => hasApiErrorTag(error, 'FetchCaptureTimeout'), (error) => apiError(504, error)), Match.when((error) => hasApiErrorTag(error, 'FetchCapacityTimeout'), (error) => apiError(529, error)), Match.when((error) => error instanceof Generated.HttpApiDecodeError, (error) => new ExpandApiError({ message: 'HttpApiDecodeError', status: 400, body: error, cause: error })), Match.when((error) => hasApiErrorTag(error, 'HttpApiDecodeError') || hasApiErrorTag(error, 'BadRequest'), (error) => apiError(400, error)), Match.when((error) => hasApiErrorTag(error, 'FetchSnapshotSearchNotFound'), (error) => apiError(404, error)),
|
|
28
40
|
// A response we couldn't decode (e.g. a 5xx whose body is empty or doesn't match the declared
|
|
29
41
|
// error schema) arrives as a bare ParseError with no status. Surface a clear SDK error instead
|
|
30
42
|
// of dumping the raw schema-mismatch tree as the message.
|
|
@@ -35,6 +47,22 @@ export function toExpandError(error, timeoutMs) {
|
|
|
35
47
|
* retryable; API errors are retryable only for the standard transient status codes (408/409/429/5xx).
|
|
36
48
|
*/
|
|
37
49
|
export function isRetryable(error, timeoutMs) {
|
|
50
|
+
if (hasApiErrorTag(error, 'BatchedIdempotencyConflict') || hasApiErrorTag(error, 'BatchedCancellationConflict')) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// A 502 FetchNavigationFailed is a deterministic verdict about the target page (the browser
|
|
54
|
+
// committed an internal error document), not a transient gateway failure — retrying re-runs a
|
|
55
|
+
// full capture for the same outcome.
|
|
56
|
+
if (hasApiErrorTag(error, 'FetchNavigationFailed')) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// A typed 504 FetchCaptureTimeout is the conservative fallback when no result was publishable by
|
|
60
|
+
// the request deadline and queue-only expiry was not proven. Automatic retry remains disabled so
|
|
61
|
+
// ambiguous timeouts do not amplify a control-plane incident. A deliberate retry may still be
|
|
62
|
+
// appropriate; a bare intermediary 504 stays on the normal retryable-status path.
|
|
63
|
+
if (hasApiErrorTag(error, 'FetchCaptureTimeout')) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
38
66
|
// An undecodable response (a transient 5xx with an empty/garbled body, a proxy error page, etc.)
|
|
39
67
|
// surfaces as a bare ParseError with no HTTP status, so the status-based classification below can't
|
|
40
68
|
// see the 5xx and the request would fail un-retried. Treat decode failures as retryable — the
|
|
@@ -48,7 +76,7 @@ export function isRetryable(error, timeoutMs) {
|
|
|
48
76
|
/**
|
|
49
77
|
* Effect-side bridge between {@link ExpandService} and the Promise-based {@link ExpandClient}.
|
|
50
78
|
*
|
|
51
|
-
* Exposes the same fetch/batched/getBatched methods as `ExpandService` but with the typed `ExpandError`
|
|
79
|
+
* Exposes the same fetch/batched/getBatched/cancelBatched methods as `ExpandService` but with the typed `ExpandError`
|
|
52
80
|
* channel mapped to the `ExpandClientError` hierarchy that async/await consumers expect. Not exported
|
|
53
81
|
* from the package — Effect consumers depend on `ExpandService` directly and receive the typed
|
|
54
82
|
* `ExpandError` unions as-is.
|
|
@@ -59,9 +87,10 @@ export class InternalClient extends Effect.Service()('@expandai/sdk/InternalClie
|
|
|
59
87
|
const fetch = (params, options = {}) => service.fetch(params, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
60
88
|
const fetchJson = (params, options = {}) => service.fetchJson(params, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
61
89
|
const fetchSearch = (params, options = {}) => service.fetchSearch(params, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
62
|
-
const batched = (params, options
|
|
90
|
+
const batched = (params, options) => service.batched(params, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
63
91
|
const getBatched = (id, options = {}) => service.getBatched(id, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
64
|
-
|
|
92
|
+
const cancelBatched = (id, options = {}) => service.cancelBatched(id, options).pipe(Effect.mapError((error) => error.toPublicError()));
|
|
93
|
+
return { fetch, fetchJson, fetchSearch, batched, getBatched, cancelBatched };
|
|
65
94
|
}),
|
|
66
95
|
}) {
|
|
67
96
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Internal.js","sourceRoot":"","sources":["../../src/Internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAClF,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EAErB,cAAc,EACd,kBAAkB,GAClB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"Internal.js","sourceRoot":"","sources":["../../src/Internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAClF,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EAErB,cAAc,EACd,kBAAkB,GAClB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAKN,aAAa,GAWb,MAAM,cAAc,CAAA;AAErB,MAAM,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAMnF,SAAS,cAAc,CAAC,KAAc,EAAE,GAAW;IAClD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,CAAA;AAC5F,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc,EAAE,KAAc;IAC/C,MAAM,OAAO,GACZ,OAAO,KAAK,KAAK,QAAQ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;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,GAAyB,EAAE;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACtE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,KAA2B;QAChD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC5F,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE;YAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;YACnG,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACjH,CAAC,CAAA;IACH,CAAC;IAEO,MAAM,CAAC,wBAAwB,CAAC,KAAc;QACrD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACd,eAAe,IAAI,KAAK;YACxB,OAAO,KAAK,CAAC,aAAa,KAAK,UAAU,CACzC,CAAA;IACF,CAAC;CACD"}
|
package/build/esm/Playground.js
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
// Canonical public snapshot URLs (all public, no auth, no TTL):
|
|
4
4
|
//
|
|
5
5
|
// /s/<snapshotId> — whole snapshot
|
|
6
|
-
// /s/<snapshotId
|
|
7
|
-
// /s/<snapshotId>?id=<evidenceId> — open extracted State JSON evidence
|
|
6
|
+
// /s/<snapshotId>?id=<evidenceId> — open any public evidence target
|
|
8
7
|
//
|
|
9
|
-
// A citation maps a search snippet
|
|
10
|
-
import { Match } from 'effect';
|
|
8
|
+
// A citation maps a search snippet location to the view that audits it.
|
|
11
9
|
export const DEFAULT_PLAYGROUND_HOST = 'https://expand.land';
|
|
12
10
|
function normalizeHost(host) {
|
|
13
11
|
return host.replace(/\/+$/, '');
|
|
14
12
|
}
|
|
13
|
+
function publicEvidenceId(value) {
|
|
14
|
+
return value !== null && value !== undefined && Number.isInteger(value) && value > 0 && value <= 2_147_483_647
|
|
15
|
+
? value
|
|
16
|
+
: undefined;
|
|
17
|
+
}
|
|
18
|
+
function legacyArchiveId(value) {
|
|
19
|
+
return value !== null && value !== undefined && Number.isInteger(value) && value >= 0 && value <= 0xffffffff
|
|
20
|
+
? value
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
15
23
|
/** Whole-snapshot URL: `${host}/s/${snapshotId}`. */
|
|
16
24
|
export function playgroundBase(snapshotId, host = DEFAULT_PLAYGROUND_HOST) {
|
|
17
25
|
return `${normalizeHost(host)}/s/${encodeURIComponent(snapshotId)}`;
|
|
@@ -36,20 +44,32 @@ export function resolvePlaygroundHost(metaPlayground, fallback) {
|
|
|
36
44
|
return fallback;
|
|
37
45
|
}
|
|
38
46
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
export function citationUrl(snapshotId, sourceOrLocation, locationOrHost, legacyHost = DEFAULT_PLAYGROUND_HOST) {
|
|
48
|
+
const legacySignature = typeof sourceOrLocation === 'string';
|
|
49
|
+
const source = legacySignature ? sourceOrLocation : undefined;
|
|
50
|
+
const location = legacySignature
|
|
51
|
+
? typeof locationOrHost === 'string'
|
|
52
|
+
? undefined
|
|
53
|
+
: locationOrHost
|
|
54
|
+
: sourceOrLocation;
|
|
55
|
+
const host = legacySignature
|
|
56
|
+
? legacyHost
|
|
57
|
+
: typeof locationOrHost === 'string'
|
|
58
|
+
? locationOrHost
|
|
59
|
+
: DEFAULT_PLAYGROUND_HOST;
|
|
46
60
|
const base = playgroundBase(snapshotId, host);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const evidenceId = publicEvidenceId(location?.evidenceId);
|
|
62
|
+
if (evidenceId !== undefined) {
|
|
63
|
+
return `${base}?id=${evidenceId}`;
|
|
64
|
+
}
|
|
65
|
+
if (source === 'statejson') {
|
|
66
|
+
const legacyId = legacyArchiveId(location?.stateJsonSourceId);
|
|
67
|
+
return legacyId === undefined ? base : `${base}?id=${legacyId}`;
|
|
68
|
+
}
|
|
69
|
+
if (source === 'markdown' || source === 'appendix') {
|
|
70
|
+
const nodeId = legacyArchiveId(location?.nodeIds?.[0]);
|
|
71
|
+
return nodeId === undefined ? base : `${base}/playground#focus=${nodeId}`;
|
|
72
|
+
}
|
|
73
|
+
return base;
|
|
54
74
|
}
|
|
55
75
|
//# sourceMappingURL=Playground.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Playground.js","sourceRoot":"","sources":["../../src/Playground.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,8DAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"Playground.js","sourceRoot":"","sources":["../../src/Playground.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,8DAA8D;AAC9D,+EAA+E;AAC/E,EAAE;AACF,wEAAwE;AAExE,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAA;AAe5D,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,C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CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform';
|
|
2
2
|
import { NodeHttpClient } from '@effect/platform-node';
|
|
3
|
-
import { Context, Duration, Effect, flow, Layer, Schedule, Schema } from 'effect';
|
|
3
|
+
import { Context, Duration, Effect, flow, Layer, Option, Random, Schedule, Schema } from 'effect';
|
|
4
4
|
import { ExpandSdkError } from './Error.js';
|
|
5
5
|
import { fetchObjectModeJson, fetchSnapshotSearch, } from './FetchJson.js';
|
|
6
6
|
import * as Generated from './Generated.js';
|
|
@@ -23,25 +23,24 @@ export class ExpandServiceOptions extends Schema.Class('ExpandServiceOptions')({
|
|
|
23
23
|
}),
|
|
24
24
|
/**
|
|
25
25
|
* Total wall-clock budget in milliseconds for the operation, including retries and backoff.
|
|
26
|
-
*
|
|
26
|
+
* A successful attempt may use the remaining operation budget. Defaults to 60_000.
|
|
27
27
|
*/
|
|
28
28
|
timeoutMs: Schema.optional(Schema.Number).annotations({
|
|
29
29
|
description: 'Total wall-clock budget in milliseconds for the operation, including retries and backoff. ' +
|
|
30
|
-
'
|
|
30
|
+
'A successful attempt may use the remaining operation budget. Defaults to 60_000.',
|
|
31
31
|
}),
|
|
32
32
|
/**
|
|
33
33
|
* Number of retry attempts for retryable failures (timeouts, connection errors, 408/409/429/5xx).
|
|
34
|
-
* Defaults to 2.
|
|
35
|
-
* per-call to opt in.
|
|
34
|
+
* Defaults to 2.
|
|
36
35
|
*/
|
|
37
36
|
maxRetries: Schema.optional(Schema.Number).annotations({
|
|
38
37
|
description: 'Number of retry attempts for retryable failures (timeouts, connection errors, 408/409/429/5xx). ' +
|
|
39
|
-
'Defaults to 2.
|
|
38
|
+
'Defaults to 2.',
|
|
40
39
|
}),
|
|
41
40
|
}, { description: 'Options for constructing an `ExpandService` layer or `ExpandClient` instance.' }) {
|
|
42
41
|
}
|
|
43
42
|
/**
|
|
44
|
-
* Per-request overrides accepted by `ExpandService.fetch`/`batched`/`getBatched` (and, transitively,
|
|
43
|
+
* Per-request overrides accepted by `ExpandService.fetch`/`batched`/`getBatched`/`cancelBatched` (and, transitively,
|
|
45
44
|
* by `ExpandClient`'s methods).
|
|
46
45
|
*/
|
|
47
46
|
export class RequestOptions extends Schema.Class('RequestOptions')({
|
|
@@ -113,7 +112,10 @@ export class ExpandService extends Effect.Service()('@expandai/sdk/ExpandService
|
|
|
113
112
|
'413': (response) => decodeError(response, Generated.PayloadTooLarge),
|
|
114
113
|
'429': (response) => decodeError(response, Generated.TooManyRequests),
|
|
115
114
|
'500': (response) => decodeError(response, Generated.InternalError),
|
|
115
|
+
'502': (response) => decodeError(response, Generated.FetchNavigationFailed),
|
|
116
116
|
'503': (response) => decodeError(response, Generated.ServiceUnavailable),
|
|
117
|
+
'504': (response) => decodeError(response, Generated.FetchCaptureTimeout),
|
|
118
|
+
'529': (response) => decodeError(response, Generated.FetchCapacityTimeout),
|
|
117
119
|
orElse: (response) => unexpectedStatus(request, response),
|
|
118
120
|
}))));
|
|
119
121
|
// Generic over the operation's success/error/requirement channels so callers (fetch/batched/getBatched)
|
|
@@ -121,15 +123,10 @@ export class ExpandService extends Effect.Service()('@expandai/sdk/ExpandService
|
|
|
121
123
|
const withRetries = Effect.fn('ExpandService.withRetries')(function* (operation, requestOptions = {}) {
|
|
122
124
|
const totalTimeoutMs = requestOptions.timeoutMs ?? config.timeoutMs;
|
|
123
125
|
const maxRetries = requestOptions.maxRetries ?? config.maxRetries;
|
|
124
|
-
// `timeoutMs` is
|
|
125
|
-
//
|
|
126
|
-
// including retry backoff. Pipe ordering matters: per-attempt timeout must wrap the operation
|
|
127
|
-
// (so retry can catch its TimeoutException), and total timeout must wrap retry (so it caps
|
|
128
|
-
// backoff between attempts). Floor with a 1ms minimum so degenerate inputs don't produce a
|
|
129
|
-
// zero-millisecond budget that fires before any work happens.
|
|
130
|
-
const perAttemptTimeoutMs = Math.max(1, Math.floor(totalTimeoutMs / (maxRetries + 1)));
|
|
126
|
+
// `timeoutMs` is one wall-clock budget for the operation, including retries and backoff. A slow
|
|
127
|
+
// valid capture may use most of that budget; only failures that arrive before it expires can retry.
|
|
131
128
|
const retrySchedule = Schedule.exponential(Duration.millis(250)).pipe(Schedule.jittered, Schedule.compose(Schedule.recurs(maxRetries)), Schedule.whileInput((error) => isRetryable(error, totalTimeoutMs)));
|
|
132
|
-
return yield* operation.pipe(Effect.
|
|
129
|
+
return yield* operation.pipe(Effect.retry(retrySchedule), Effect.timeout(Duration.millis(totalTimeoutMs)), Effect.mapError((error) => toExpandError(error, totalTimeoutMs)));
|
|
133
130
|
});
|
|
134
131
|
const fetch = Effect.fn('ExpandService.fetch')(function* (params, requestOptions = {}) {
|
|
135
132
|
const { include, ...retryOptions } = requestOptions;
|
|
@@ -146,13 +143,35 @@ export class ExpandService extends Effect.Service()('@expandai/sdk/ExpandService
|
|
|
146
143
|
return yield* withRetries(fetchSnapshotSearch(authedClient, params), requestOptions);
|
|
147
144
|
});
|
|
148
145
|
const batched = Effect.fn('ExpandService.batched')(function* (params, requestOptions = {}) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
const { idempotencyKey: providedIdempotencyKey, ...retryOptions } = requestOptions;
|
|
147
|
+
const idempotencyKey = yield* Option.fromNullable(providedIdempotencyKey).pipe(Option.match({
|
|
148
|
+
onSome: Effect.succeed,
|
|
149
|
+
onNone: () => Effect.all([Random.nextInt, Random.nextInt, Random.nextInt]).pipe(Effect.map(([first, second, third]) => `sdk-${Math.abs(first).toString(36)}-${Math.abs(second).toString(36)}-${Math.abs(third).toString(36)}`)),
|
|
150
|
+
}));
|
|
151
|
+
// Merged after the generated payload because the generated schema drops any
|
|
152
|
+
// key it does not declare — silently, which is the dangerous part. See
|
|
153
|
+
// `BatchedRequestOptions.internalOverrides` for why it is not declared.
|
|
154
|
+
//
|
|
155
|
+
// A collision is refused rather than resolved: this hatch exists to add
|
|
156
|
+
// undeclared fields, and letting it win over `urls` or `include` would
|
|
157
|
+
// mean a request could quietly fetch something other than what the caller
|
|
158
|
+
// passed.
|
|
159
|
+
const overrides = requestOptions.internalOverrides ?? {};
|
|
160
|
+
// Checked against the schema's declared fields, not against the keys this
|
|
161
|
+
// particular call happened to set: an omitted-but-declared field like
|
|
162
|
+
// `include` could otherwise be supplied here and bypass the generated
|
|
163
|
+
// contract entirely.
|
|
164
|
+
const collisions = Object.keys(overrides).filter((key) => Object.hasOwn(Generated.FetchBatchedRequest.fields, key));
|
|
165
|
+
if (collisions.length > 0) {
|
|
166
|
+
return yield* new ExpandSdkError({
|
|
167
|
+
message: `internalOverrides may not replace declared request fields: ${collisions.join(', ')}`,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const generatedRequest = {
|
|
171
|
+
params: { 'x-idempotency-key': idempotencyKey },
|
|
172
|
+
payload: { ...params, ...overrides },
|
|
173
|
+
};
|
|
174
|
+
return yield* withRetries(generated.fetchBatched(generatedRequest), retryOptions);
|
|
156
175
|
});
|
|
157
176
|
const getBatched = Effect.fn('ExpandService.getBatched')(function* (id, options = {}) {
|
|
158
177
|
// Pull RequestOptions out, pass everything else through as query params. Drift-resilient: any
|
|
@@ -160,7 +179,10 @@ export class ExpandService extends Effect.Service()('@expandai/sdk/ExpandService
|
|
|
160
179
|
const { timeoutMs, maxRetries, ...params } = options;
|
|
161
180
|
return yield* withRetries(generated.fetchGetBatched(id, params), { timeoutMs, maxRetries });
|
|
162
181
|
});
|
|
163
|
-
|
|
182
|
+
const cancelBatched = Effect.fn('ExpandService.cancelBatched')(function* (id, requestOptions = {}) {
|
|
183
|
+
return yield* withRetries(generated.fetchCancelBatched(id), requestOptions);
|
|
184
|
+
});
|
|
185
|
+
return { fetch, fetchJson, fetchSearch, batched, getBatched, cancelBatched };
|
|
164
186
|
}),
|
|
165
187
|
}) {
|
|
166
188
|
/**
|
package/build/esm/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACjG,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAGN,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE1D,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAChD,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAE7B;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,KAAK,CAAuB,sBAAsB,CAAC,CACnG;IACC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAA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AA;QAEF,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,6BAA6B,CAAC,CAAC,QAAQ,CAAC,EACvE,EAAU,EACV,cAAc,GAAmB,EAAE;YAEnC,OAAO,KAAK,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAA;QAC5E,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAW,CAAA;IACtF,CAAC,CAAC;CACF,CAAC;IACD;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,GAAyB,EAAE;QAC9C,OAAO,KAAK,CAAC,YAAY,CACxB,kBAAkB,CAAC,OAAO,CAAC,CAAC,IAAI,CAC/B,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAC1G,CACD,CAAA;IACF,CAAC;CACD"}
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EACN,cAAc,EACd,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,GAClB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expandai/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "TypeScript SDK for ExpandAI",
|
|
7
7
|
"author": "ExpandAI",
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"./*": {
|
|
45
45
|
"types": "./build/dts/*.d.ts",
|
|
46
46
|
"import": "./build/esm/*.js"
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
"./internal/*": "./src/*.ts"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"generate": "tsx scripts/generate-client.ts",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"format": "biome format --write",
|
|
57
58
|
"format:check": "biome format",
|
|
58
59
|
"test": "vitest run --exclude 'test/**/*.integration.test.ts'",
|
|
59
|
-
"test:integration": "vitest run integration"
|
|
60
|
+
"test:integration": "vitest run integration --fileParallelism=false --testTimeout=30000"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"@effect/platform": "0.96.1",
|
package/src/Client.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { Effect, Either, Exit, Layer } from 'effect'
|
|
|
2
2
|
import { InternalClient } from './Internal.js'
|
|
3
3
|
import {
|
|
4
4
|
type BatchedParams,
|
|
5
|
+
type BatchedRequestOptions,
|
|
5
6
|
type BatchedResponse,
|
|
6
7
|
buildServiceConfig,
|
|
8
|
+
type CancelBatchedResponse,
|
|
7
9
|
type ExpandServiceOptions,
|
|
8
10
|
type FetchJsonParams,
|
|
9
11
|
type FetchJsonRequestOptions,
|
|
@@ -20,7 +22,9 @@ import {
|
|
|
20
22
|
|
|
21
23
|
export type {
|
|
22
24
|
BatchedParams,
|
|
25
|
+
BatchedRequestOptions,
|
|
23
26
|
BatchedResponse,
|
|
27
|
+
CancelBatchedResponse,
|
|
24
28
|
FetchJsonParams,
|
|
25
29
|
FetchJsonRequestOptions,
|
|
26
30
|
FetchJsonResponse,
|
|
@@ -95,14 +99,16 @@ export class ExpandClient {
|
|
|
95
99
|
* Kick off an asynchronous batched fetch over one or more URLs. Returns a batched-run ID that can
|
|
96
100
|
* be polled via {@link getBatched}.
|
|
97
101
|
*
|
|
98
|
-
*
|
|
102
|
+
* When `idempotencyKey` is omitted, the client generates one and reuses it for automatic retries.
|
|
103
|
+
* Provide a stable key to deduplicate separate calls or calls made after a process restart. Reusing
|
|
104
|
+
* a key with a different payload surfaces an idempotency conflict.
|
|
99
105
|
*
|
|
100
106
|
* @throws {ExpandClientApiError} on 4xx/5xx responses
|
|
101
107
|
* @throws {ExpandClientTimeoutError} when the request exceeds `timeoutMs`
|
|
102
108
|
* @throws {ExpandClientConnectionError} on network failures
|
|
103
109
|
* @throws {ExpandClientError} for any other failure
|
|
104
110
|
*/
|
|
105
|
-
async batched(params: BatchedParams, options:
|
|
111
|
+
async batched(params: BatchedParams, options: BatchedRequestOptions = {}): Promise<BatchedResponse> {
|
|
106
112
|
return this.run((client) => client.batched(params, options))
|
|
107
113
|
}
|
|
108
114
|
|
|
@@ -118,6 +124,13 @@ export class ExpandClient {
|
|
|
118
124
|
return this.run((client) => client.getBatched(id, options))
|
|
119
125
|
}
|
|
120
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Request cancellation of a batched run. The command is idempotent and uses the configured retry policy.
|
|
129
|
+
*/
|
|
130
|
+
async cancelBatched(id: string, options: RequestOptions = {}): Promise<CancelBatchedResponse> {
|
|
131
|
+
return this.run((client) => client.cancelBatched(id, options))
|
|
132
|
+
}
|
|
133
|
+
|
|
121
134
|
private async run<A>(body: (ic: InternalClient) => Effect.Effect<A, Error>): Promise<A> {
|
|
122
135
|
const exit = await Effect.runPromiseExit(InternalClient.use(body).pipe(Effect.provide(this.layer)))
|
|
123
136
|
if (Exit.isSuccess(exit)) {
|
package/src/FetchJson.ts
CHANGED
|
@@ -14,30 +14,22 @@ import { decodeError, unexpectedStatus } from './HttpClientHelpers.js'
|
|
|
14
14
|
|
|
15
15
|
/** Search snippet with the extracted `json` value preserved (statejson snippets only). */
|
|
16
16
|
export const FetchSearchSnippetWithJson = S.Struct({
|
|
17
|
-
|
|
18
|
-
source: S.Literal('markdown', 'appendix', 'statejson'),
|
|
19
|
-
text: S.String,
|
|
17
|
+
...Generated.FetchSearchResult.fields.snippets.value.fields,
|
|
20
18
|
json: S.optionalWith(S.Unknown, { nullable: true }),
|
|
21
|
-
score: S.Number.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1)),
|
|
22
|
-
location: S.optionalWith(Generated.FetchSearchSnippetLocation, { nullable: true }),
|
|
23
19
|
})
|
|
24
20
|
|
|
25
21
|
export const FetchSearchResultWithJson = S.Struct({
|
|
26
|
-
|
|
22
|
+
...Generated.FetchSearchResult.fields,
|
|
27
23
|
snippets: S.Array(FetchSearchSnippetWithJson),
|
|
28
|
-
meta: S.optionalWith(Generated.FetchSearchMeta, { nullable: true }),
|
|
29
24
|
})
|
|
30
25
|
|
|
31
26
|
export class FetchObjectModeResultWithJson extends S.Class<FetchObjectModeResultWithJson>(
|
|
32
27
|
'FetchObjectModeResultWithJson',
|
|
33
28
|
)({
|
|
34
|
-
|
|
35
|
-
markdown: S.String,
|
|
36
|
-
json: S.Array(Generated.FetchObjectModeEvidence),
|
|
29
|
+
...Generated.FetchObjectModeResult.fields,
|
|
37
30
|
data: S.optionalWith(
|
|
38
31
|
S.Struct({
|
|
39
|
-
|
|
40
|
-
captureTelemetry: S.optionalWith(Generated.CaptureTelemetryInfo, { nullable: true }),
|
|
32
|
+
...Generated.FetchObjectModeResult.fields.data.from.fields,
|
|
41
33
|
search: S.optionalWith(FetchSearchResultWithJson, { nullable: true }),
|
|
42
34
|
}),
|
|
43
35
|
{ nullable: true },
|
|
@@ -51,6 +43,7 @@ export class FetchSnapshotSearchResultWithJson extends S.Class<FetchSnapshotSear
|
|
|
51
43
|
response: Generated.ResponseInfo,
|
|
52
44
|
search: FetchSearchResultWithJson,
|
|
53
45
|
durationMs: S.Number.pipe(S.greaterThanOrEqualTo(0)),
|
|
46
|
+
playground: S.String,
|
|
54
47
|
}) {}
|
|
55
48
|
|
|
56
49
|
/** Mirrors `Generated.Client['fetchFetchJson']` but decodes the 200 body with `json` preserved. */
|
|
@@ -75,7 +68,10 @@ export const fetchObjectModeJson = (
|
|
|
75
68
|
'413': (response) => decodeError(response, Generated.PayloadTooLarge),
|
|
76
69
|
'429': (response) => decodeError(response, Generated.TooManyRequests),
|
|
77
70
|
'500': (response) => decodeError(response, Generated.InternalError),
|
|
71
|
+
'502': (response) => decodeError(response, Generated.FetchNavigationFailed),
|
|
78
72
|
'503': (response) => decodeError(response, Generated.ServiceUnavailable),
|
|
73
|
+
'504': (response) => decodeError(response, Generated.FetchCaptureTimeout),
|
|
74
|
+
'529': (response) => decodeError(response, Generated.FetchCapacityTimeout),
|
|
79
75
|
orElse: (response) => unexpectedStatus(request, response),
|
|
80
76
|
}),
|
|
81
77
|
),
|