@amigo-ai/platform-sdk 0.4.3 → 0.4.5
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 +46 -13
- package/assets/readme/amigo-banner.png +0 -0
- package/assets/readme/platform-architecture.svg +103 -0
- package/dist/core/retry.js +29 -1
- package/dist/core/retry.js.map +1 -1
- package/dist/index.cjs +27 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +27 -1
- package/dist/index.mjs.map +2 -2
- package/dist/types/core/retry.d.ts.map +1 -1
- package/dist/types/generated/api.d.ts +1132 -244
- package/dist/types/generated/api.d.ts.map +1 -1
- package/dist/types/resources/actions.d.ts.map +1 -1
- package/dist/types/resources/agents.d.ts +4 -4
- package/dist/types/resources/agents.d.ts.map +1 -1
- package/dist/types/resources/analytics.d.ts +1 -3
- package/dist/types/resources/analytics.d.ts.map +1 -1
- package/dist/types/resources/api-keys.d.ts.map +1 -1
- package/dist/types/resources/audit.d.ts.map +1 -1
- package/dist/types/resources/billing.d.ts.map +1 -1
- package/dist/types/resources/calls.d.ts +1 -1
- package/dist/types/resources/calls.d.ts.map +1 -1
- package/dist/types/resources/context-graphs.d.ts.map +1 -1
- package/dist/types/resources/data-sources.d.ts.map +1 -1
- package/dist/types/resources/functions.d.ts.map +1 -1
- package/dist/types/resources/integrations.d.ts.map +1 -1
- package/dist/types/resources/memory.d.ts.map +1 -1
- package/dist/types/resources/operators.d.ts +18 -18
- package/dist/types/resources/operators.d.ts.map +1 -1
- package/dist/types/resources/personas.d.ts.map +1 -1
- package/dist/types/resources/phone-numbers.d.ts +8 -8
- package/dist/types/resources/phone-numbers.d.ts.map +1 -1
- package/dist/types/resources/review-queue.d.ts +6 -6
- package/dist/types/resources/review-queue.d.ts.map +1 -1
- package/dist/types/resources/safety.d.ts.map +1 -1
- package/dist/types/resources/services.d.ts.map +1 -1
- package/dist/types/resources/settings.d.ts.map +1 -1
- package/dist/types/resources/simulations.d.ts.map +1 -1
- package/dist/types/resources/skills.d.ts.map +1 -1
- package/dist/types/resources/triggers.d.ts +35 -35
- package/dist/types/resources/triggers.d.ts.map +1 -1
- package/dist/types/resources/webhook-destinations.d.ts +6 -6
- package/dist/types/resources/webhook-destinations.d.ts.map +1 -1
- package/dist/types/resources/workspaces.d.ts.map +1 -1
- package/dist/types/resources/world.d.ts.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,10 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/readme/amigo-banner.png" alt="Amigo banner" width="100%" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
[](https://github.com/amigo-ai/amigo-platform-typescript-sdk/actions/workflows/test.yml)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
<h1 align="center">@amigo-ai/platform-sdk</h1>
|
|
6
6
|
|
|
7
|
-
Official TypeScript SDK for the
|
|
7
|
+
<p align="center">Official TypeScript SDK for the <a href="https://api.platform.amigo.ai/v1/docs">Amigo Platform API</a>.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://docs.amigo.ai">Product Docs</a>
|
|
11
|
+
·
|
|
12
|
+
<a href="https://docs.amigo.ai/developer-guide">Developer Guide</a>
|
|
13
|
+
·
|
|
14
|
+
<a href="https://docs.amigo.ai/api-reference">API Reference</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="./examples/README.md">Examples</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="./api.md">API Surface</a>
|
|
19
|
+
·
|
|
20
|
+
<a href="./CHANGELOG.md">Changelog</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://www.npmjs.com/package/@amigo-ai/platform-sdk"><img src="https://img.shields.io/npm/v/@amigo-ai/platform-sdk.svg" alt="npm version" /></a>
|
|
25
|
+
<a href="https://github.com/amigo-ai/amigo-platform-typescript-sdk/actions/workflows/test.yml"><img src="https://github.com/amigo-ai/amigo-platform-typescript-sdk/actions/workflows/test.yml/badge.svg" alt="CI" /></a>
|
|
26
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License" /></a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
Typed from the committed `openapi.json` snapshot, validated on Node 18, 20, and 22, and tested as packaged ESM and CommonJS tarballs before release.
|
|
30
|
+
|
|
31
|
+
## Platform context
|
|
32
|
+
|
|
33
|
+
The SDK is the typed client boundary between your runtime and the workspace-scoped Platform API. The API then fronts the platform systems that power agents, actions, calls, analytics, world state, connectors, and webhooks.
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
| Need | Best entry point |
|
|
40
|
+
| ------------------------------------------- | -------------------------------------------------------- |
|
|
41
|
+
| Product architecture and deployment context | [docs.amigo.ai](https://docs.amigo.ai/) |
|
|
42
|
+
| Tutorials and integration guidance | [Developer Guide](https://docs.amigo.ai/developer-guide) |
|
|
43
|
+
| Endpoint-by-endpoint REST reference | [API Reference](https://docs.amigo.ai/api-reference) |
|
|
44
|
+
| Repo-local SDK examples | [examples/README.md](./examples/README.md) |
|
|
45
|
+
| Generated package surface | [api.md](./api.md) |
|
|
46
|
+
| Published release history | [CHANGELOG.md](./CHANGELOG.md) |
|
|
47
|
+
|
|
48
|
+
The docs site remains the primary reference. The repo-local examples stay close to the shipped package surface and are typechecked in CI to reduce drift.
|
|
8
49
|
|
|
9
50
|
## Installation
|
|
10
51
|
|
|
@@ -39,14 +80,6 @@ const stats = await client.analytics.getCalls({ days: 30 })
|
|
|
39
80
|
console.log(stats.total_calls, stats.avg_duration_seconds)
|
|
40
81
|
```
|
|
41
82
|
|
|
42
|
-
## Examples and Docs
|
|
43
|
-
|
|
44
|
-
- Product docs and API reference: [docs.amigo.ai](https://docs.amigo.ai/)
|
|
45
|
-
- Repo-local SDK examples: [examples/README.md](./examples/README.md)
|
|
46
|
-
- Repo-local API surface guide: [api.md](./api.md)
|
|
47
|
-
|
|
48
|
-
The docs site remains the primary reference. The examples in this repo stay close to the package surface and are typechecked in CI to reduce drift.
|
|
49
|
-
|
|
50
83
|
## Configuration
|
|
51
84
|
|
|
52
85
|
| Option | Type | Required | Description |
|
|
Binary file
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="480" viewBox="0 0 1200 480">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0.6" y2="1">
|
|
4
|
+
<stop offset="0%" stop-color="#083241"/>
|
|
5
|
+
<stop offset="100%" stop-color="#051A24"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="strokeGrad" x1="0" y1="0" x2="1" y2="1">
|
|
8
|
+
<stop offset="0%" stop-color="white" stop-opacity="0.1"/>
|
|
9
|
+
<stop offset="100%" stop-color="#999" stop-opacity="0.04"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
<linearGradient id="strokeGradSubtle" x1="0" y1="0" x2="1" y2="1">
|
|
12
|
+
<stop offset="0%" stop-color="white" stop-opacity="0.08"/>
|
|
13
|
+
<stop offset="100%" stop-color="#999" stop-opacity="0.03"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
<marker id="arrow" viewBox="0 0 10 7" refX="9" refY="3.5" markerWidth="8" markerHeight="6" orient="auto-start-reverse">
|
|
16
|
+
<path d="M 0 0.5 L 9 3.5 L 0 6.5" fill="none" stroke="white" stroke-width="1" opacity="0.2"/>
|
|
17
|
+
</marker>
|
|
18
|
+
</defs>
|
|
19
|
+
|
|
20
|
+
<rect width="1200" height="480" fill="url(#bg)"/>
|
|
21
|
+
|
|
22
|
+
<!-- ====== PLATFORM SYSTEMS (top) ====== -->
|
|
23
|
+
<rect x="32" y="32" width="880" height="260" rx="10" fill="white" fill-opacity="0.03" stroke="url(#strokeGrad)" stroke-width="0.75"/>
|
|
24
|
+
<text x="60" y="60" font-family="'Diatype Mono', 'SF Mono', monospace" font-size="13" font-weight="500" fill="white" fill-opacity="0.55" letter-spacing="2">PLATFORM SYSTEMS</text>
|
|
25
|
+
|
|
26
|
+
<!-- Row 1 -->
|
|
27
|
+
<rect x="52" y="78" width="200" height="60" rx="8" fill="white" fill-opacity="0.1" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
28
|
+
<text x="152" y="103" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Agent Engine</text>
|
|
29
|
+
<text x="152" y="121" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Phone, text, simulation</text>
|
|
30
|
+
|
|
31
|
+
<rect x="268" y="78" width="200" height="60" rx="8" fill="white" fill-opacity="0.1" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
32
|
+
<text x="368" y="103" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Clinical Copilot</text>
|
|
33
|
+
<text x="368" y="121" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">SOAP, ICD-10, CDS</text>
|
|
34
|
+
|
|
35
|
+
<rect x="484" y="78" width="200" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
36
|
+
<text x="584" y="103" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Emotion Engine</text>
|
|
37
|
+
<text x="584" y="121" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Acoustic intelligence</text>
|
|
38
|
+
|
|
39
|
+
<rect x="700" y="78" width="192" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
40
|
+
<text x="796" y="103" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Connector Runner</text>
|
|
41
|
+
<text x="796" y="121" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">EHR, FHIR, CRM sync</text>
|
|
42
|
+
|
|
43
|
+
<!-- Row 2 -->
|
|
44
|
+
<rect x="52" y="152" width="200" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
45
|
+
<text x="152" y="177" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Operators</text>
|
|
46
|
+
<text x="152" y="195" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Monitoring, escalation</text>
|
|
47
|
+
|
|
48
|
+
<rect x="268" y="152" width="200" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
49
|
+
<text x="368" y="177" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Metric Store</text>
|
|
50
|
+
<text x="368" y="195" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Config-driven analytics</text>
|
|
51
|
+
|
|
52
|
+
<rect x="484" y="152" width="200" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
53
|
+
<text x="584" y="177" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Surfaces</text>
|
|
54
|
+
<text x="584" y="195" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Forms, data capture</text>
|
|
55
|
+
|
|
56
|
+
<rect x="700" y="152" width="192" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
57
|
+
<text x="796" y="177" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Outbound Dispatch</text>
|
|
58
|
+
<text x="796" y="195" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Campaigns, follow-ups</text>
|
|
59
|
+
|
|
60
|
+
<!-- Annotation: read + write -->
|
|
61
|
+
<text x="472" y="248" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" font-weight="500" fill="white" fill-opacity="0.5">read + write</text>
|
|
62
|
+
<line x1="390" y1="254" x2="390" y2="280" stroke="white" stroke-width="1" stroke-opacity="0.15" marker-end="url(#arrow)"/>
|
|
63
|
+
<line x1="555" y1="254" x2="555" y2="280" stroke="white" stroke-width="1" stroke-opacity="0.15" marker-end="url(#arrow)"/>
|
|
64
|
+
|
|
65
|
+
<!-- ====== CLASSIC API (top right) ====== -->
|
|
66
|
+
<rect x="940" y="32" width="228" height="260" rx="10" fill="white" fill-opacity="0.03" stroke="url(#strokeGrad)" stroke-width="0.75"/>
|
|
67
|
+
<text x="968" y="60" font-family="'Diatype Mono', 'SF Mono', monospace" font-size="13" font-weight="500" fill="white" fill-opacity="0.55" letter-spacing="2">CLASSIC API</text>
|
|
68
|
+
|
|
69
|
+
<rect x="960" y="78" width="188" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
70
|
+
<text x="1054" y="103" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Text Chat</text>
|
|
71
|
+
<text x="1054" y="121" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">WebSocket streaming</text>
|
|
72
|
+
|
|
73
|
+
<rect x="960" y="152" width="188" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
74
|
+
<text x="1054" y="177" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">User Models</text>
|
|
75
|
+
<text x="1054" y="195" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Memory, personalization</text>
|
|
76
|
+
|
|
77
|
+
<!-- Classic API annotation -->
|
|
78
|
+
<text x="1054" y="248" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" font-weight="500" fill="white" fill-opacity="0.5">read + write</text>
|
|
79
|
+
<line x1="1054" y1="254" x2="1054" y2="280" stroke="white" stroke-width="1" stroke-opacity="0.15" marker-end="url(#arrow)"/>
|
|
80
|
+
|
|
81
|
+
<!-- ====== WORLD MODEL (bottom foundation) ====== -->
|
|
82
|
+
<rect x="32" y="290" width="1136" height="150" rx="10" fill="white" fill-opacity="0.05" stroke="url(#strokeGrad)" stroke-width="0.75"/>
|
|
83
|
+
<text x="60" y="318" font-family="'Diatype Mono', 'SF Mono', monospace" font-size="13" font-weight="500" fill="white" fill-opacity="0.55" letter-spacing="2">WORLD MODEL</text>
|
|
84
|
+
|
|
85
|
+
<rect x="52" y="336" width="260" height="60" rx="8" fill="white" fill-opacity="0.1" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
86
|
+
<text x="182" y="361" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Event Store</text>
|
|
87
|
+
<text x="182" y="379" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Confidence-scored, immutable facts</text>
|
|
88
|
+
|
|
89
|
+
<rect x="332" y="336" width="260" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
90
|
+
<text x="462" y="361" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Entity Projections</text>
|
|
91
|
+
<text x="462" y="379" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Entity state from events</text>
|
|
92
|
+
|
|
93
|
+
<rect x="612" y="336" width="260" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
94
|
+
<text x="742" y="361" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Intelligence Projections</text>
|
|
95
|
+
<text x="742" y="379" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Memory, scheduling, clinical</text>
|
|
96
|
+
|
|
97
|
+
<rect x="892" y="336" width="256" height="60" rx="8" fill="white" fill-opacity="0.08" stroke="url(#strokeGradSubtle)" stroke-width="0.75"/>
|
|
98
|
+
<text x="1020" y="361" text-anchor="middle" font-family="'Flecha S', Georgia, serif" font-size="16" fill="white" fill-opacity="0.95">Vector Search</text>
|
|
99
|
+
<text x="1020" y="379" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" fill="white" fill-opacity="0.7">Semantic queries</text>
|
|
100
|
+
|
|
101
|
+
<!-- Footer -->
|
|
102
|
+
<text x="600" y="462" text-anchor="middle" font-family="Inter, sans-serif" font-size="12" font-weight="500" fill="white" fill-opacity="0.55">All systems read from and write to the world model - confidence propagates through every projection level</text>
|
|
103
|
+
</svg>
|
package/dist/core/retry.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const RETRYABLE_STATUS_CODES = new Set([408, 429, 500, 502, 503, 504]);
|
|
5
5
|
// POST is only retried on 429 with a Retry-After header (idempotency concern)
|
|
6
6
|
const POST_RETRYABLE_STATUS_CODES = new Set([429]);
|
|
7
|
+
let jitterCounter = 0;
|
|
7
8
|
export function shouldRetry(ctx) {
|
|
8
9
|
const { method, attempt, response, options } = ctx;
|
|
9
10
|
if (attempt >= options.maxAttempts)
|
|
@@ -26,7 +27,7 @@ export function computeDelay(attempt, response, options) {
|
|
|
26
27
|
}
|
|
27
28
|
// Exponential backoff with full jitter: random value in [0, min(maxDelay, base * 2^attempt)]
|
|
28
29
|
const exponential = Math.min(options.maxDelayMs, options.baseDelayMs * Math.pow(2, attempt));
|
|
29
|
-
return
|
|
30
|
+
return jitterFraction() * exponential;
|
|
30
31
|
}
|
|
31
32
|
function parseRetryAfterHeader(header) {
|
|
32
33
|
const seconds = Number(header);
|
|
@@ -48,4 +49,31 @@ export function resolveRetryOptions(opts, maxRetries) {
|
|
|
48
49
|
maxDelayMs: opts?.maxDelayMs ?? 30_000,
|
|
49
50
|
};
|
|
50
51
|
}
|
|
52
|
+
function jitterFraction() {
|
|
53
|
+
const cryptoApi = getCryptoApi();
|
|
54
|
+
if (cryptoApi) {
|
|
55
|
+
const value = new Uint32Array(1);
|
|
56
|
+
cryptoApi.getRandomValues(value);
|
|
57
|
+
return (value[0] ?? 0) / 0x1_0000_0000;
|
|
58
|
+
}
|
|
59
|
+
// Retry jitter is not a security primitive, but we still want a stable
|
|
60
|
+
// spread for runtimes that do not expose Web Crypto.
|
|
61
|
+
jitterCounter = (jitterCounter + 1) >>> 0;
|
|
62
|
+
const mixed = mixUint32((Date.now() ^ Math.imul(jitterCounter, 0x9e37_79b9)) >>> 0);
|
|
63
|
+
return mixed / 0x1_0000_0000;
|
|
64
|
+
}
|
|
65
|
+
function getCryptoApi() {
|
|
66
|
+
const cryptoApi = globalThis.crypto;
|
|
67
|
+
if (cryptoApi && typeof cryptoApi.getRandomValues === 'function') {
|
|
68
|
+
return cryptoApi;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
function mixUint32(value) {
|
|
73
|
+
let mixed = (value ^ (value >>> 16)) >>> 0;
|
|
74
|
+
mixed = Math.imul(mixed, 0x7feb_352d) >>> 0;
|
|
75
|
+
mixed = (mixed ^ (mixed >>> 15)) >>> 0;
|
|
76
|
+
mixed = Math.imul(mixed, 0x846c_a68b) >>> 0;
|
|
77
|
+
return (mixed ^ (mixed >>> 16)) >>> 0;
|
|
78
|
+
}
|
|
51
79
|
//# sourceMappingURL=retry.js.map
|
package/dist/core/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/core/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AACtE,8EAA8E;AAC9E,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/core/retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AACtE,8EAA8E;AAC9E,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAClD,IAAI,aAAa,GAAG,CAAC,CAAA;AAYrB,MAAM,UAAU,WAAW,CAAC,GAAiB;IAC3C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;IAClD,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW;QAAE,OAAO,KAAK,CAAA;IAEhD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAA;IAC9B,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1C,OAAO,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3C,CAAC;IACD,IAAI,MAAM,KAAK,MAAM,IAAI,2BAA2B,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAC5C,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AA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,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;IACtC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IAC3C,OAAO,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;AACvC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -401,6 +401,7 @@ function applyHeaders(target, source, onSet) {
|
|
|
401
401
|
// src/core/retry.ts
|
|
402
402
|
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
403
403
|
var POST_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429]);
|
|
404
|
+
var jitterCounter = 0;
|
|
404
405
|
function shouldRetry(ctx) {
|
|
405
406
|
const { method, attempt, response, options } = ctx;
|
|
406
407
|
if (attempt >= options.maxAttempts) return false;
|
|
@@ -420,7 +421,7 @@ function computeDelay(attempt, response, options) {
|
|
|
420
421
|
if (seconds !== void 0) return seconds * 1e3;
|
|
421
422
|
}
|
|
422
423
|
const exponential = Math.min(options.maxDelayMs, options.baseDelayMs * Math.pow(2, attempt));
|
|
423
|
-
return
|
|
424
|
+
return jitterFraction() * exponential;
|
|
424
425
|
}
|
|
425
426
|
function parseRetryAfterHeader(header) {
|
|
426
427
|
const seconds = Number(header);
|
|
@@ -439,6 +440,31 @@ function resolveRetryOptions(opts, maxRetries) {
|
|
|
439
440
|
maxDelayMs: opts?.maxDelayMs ?? 3e4
|
|
440
441
|
};
|
|
441
442
|
}
|
|
443
|
+
function jitterFraction() {
|
|
444
|
+
const cryptoApi = getCryptoApi();
|
|
445
|
+
if (cryptoApi) {
|
|
446
|
+
const value = new Uint32Array(1);
|
|
447
|
+
cryptoApi.getRandomValues(value);
|
|
448
|
+
return (value[0] ?? 0) / 4294967296;
|
|
449
|
+
}
|
|
450
|
+
jitterCounter = jitterCounter + 1 >>> 0;
|
|
451
|
+
const mixed = mixUint32((Date.now() ^ Math.imul(jitterCounter, 2654435769)) >>> 0);
|
|
452
|
+
return mixed / 4294967296;
|
|
453
|
+
}
|
|
454
|
+
function getCryptoApi() {
|
|
455
|
+
const cryptoApi = globalThis.crypto;
|
|
456
|
+
if (cryptoApi && typeof cryptoApi.getRandomValues === "function") {
|
|
457
|
+
return cryptoApi;
|
|
458
|
+
}
|
|
459
|
+
return void 0;
|
|
460
|
+
}
|
|
461
|
+
function mixUint32(value) {
|
|
462
|
+
let mixed = (value ^ value >>> 16) >>> 0;
|
|
463
|
+
mixed = Math.imul(mixed, 2146121005) >>> 0;
|
|
464
|
+
mixed = (mixed ^ mixed >>> 15) >>> 0;
|
|
465
|
+
mixed = Math.imul(mixed, 2221713035) >>> 0;
|
|
466
|
+
return (mixed ^ mixed >>> 16) >>> 0;
|
|
467
|
+
}
|
|
442
468
|
|
|
443
469
|
// src/core/utils.ts
|
|
444
470
|
function extractRequestId(response) {
|