@amigo-ai/platform-sdk 0.4.3 → 0.4.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/README.md +46 -13
- package/assets/readme/amigo-banner.png +0 -0
- package/assets/readme/platform-architecture.svg +117 -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,117 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="540" viewBox="0 0 1200 540">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0%" stop-color="#081E2A"/>
|
|
5
|
+
<stop offset="55%" stop-color="#0A2C3B"/>
|
|
6
|
+
<stop offset="100%" stop-color="#051822"/>
|
|
7
|
+
</linearGradient>
|
|
8
|
+
<radialGradient id="glowLeft" cx="0.2" cy="0.22" r="0.7">
|
|
9
|
+
<stop offset="0%" stop-color="#26C6FF" stop-opacity="0.18"/>
|
|
10
|
+
<stop offset="100%" stop-color="#26C6FF" stop-opacity="0"/>
|
|
11
|
+
</radialGradient>
|
|
12
|
+
<radialGradient id="glowRight" cx="0.84" cy="0.16" r="0.55">
|
|
13
|
+
<stop offset="0%" stop-color="#7DE1B5" stop-opacity="0.12"/>
|
|
14
|
+
<stop offset="100%" stop-color="#7DE1B5" stop-opacity="0"/>
|
|
15
|
+
</radialGradient>
|
|
16
|
+
<linearGradient id="panelStroke" x1="0" y1="0" x2="1" y2="1">
|
|
17
|
+
<stop offset="0%" stop-color="#FFFFFF" stop-opacity="0.14"/>
|
|
18
|
+
<stop offset="100%" stop-color="#92B4C3" stop-opacity="0.06"/>
|
|
19
|
+
</linearGradient>
|
|
20
|
+
<linearGradient id="highlightStroke" x1="0" y1="0" x2="1" y2="1">
|
|
21
|
+
<stop offset="0%" stop-color="#82E4FF" stop-opacity="0.92"/>
|
|
22
|
+
<stop offset="100%" stop-color="#64AFFF" stop-opacity="0.56"/>
|
|
23
|
+
</linearGradient>
|
|
24
|
+
<linearGradient id="arrowStroke" x1="0" y1="0" x2="1" y2="0">
|
|
25
|
+
<stop offset="0%" stop-color="#8EE4FF"/>
|
|
26
|
+
<stop offset="100%" stop-color="#7FC8FF"/>
|
|
27
|
+
</linearGradient>
|
|
28
|
+
<marker id="arrow" viewBox="0 0 12 12" refX="10.5" refY="6" markerWidth="8" markerHeight="8" orient="auto">
|
|
29
|
+
<path d="M 0 0 L 12 6 L 0 12 z" fill="#8EE4FF"/>
|
|
30
|
+
</marker>
|
|
31
|
+
</defs>
|
|
32
|
+
|
|
33
|
+
<rect width="1200" height="540" fill="url(#bg)"/>
|
|
34
|
+
<rect width="1200" height="540" fill="url(#glowLeft)"/>
|
|
35
|
+
<rect width="1200" height="540" fill="url(#glowRight)"/>
|
|
36
|
+
|
|
37
|
+
<text x="68" y="62" font-family="'SFMono-Regular', Menlo, monospace" font-size="13" font-weight="600" fill="#BBD1DC" letter-spacing="2.4">PLATFORM CONTEXT</text>
|
|
38
|
+
<text x="68" y="98" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="30" font-weight="700" fill="white">How the TypeScript SDK fits into the stack</text>
|
|
39
|
+
<text x="68" y="126" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="15" fill="#A9C0CB">Your runtime calls the SDK, the SDK targets the workspace-scoped Platform API, and the API fronts the operational systems behind the product.</text>
|
|
40
|
+
|
|
41
|
+
<rect x="60" y="152" width="246" height="208" rx="22" fill="white" fill-opacity="0.045" stroke="url(#panelStroke)" stroke-width="1"/>
|
|
42
|
+
<text x="88" y="184" font-family="'SFMono-Regular', Menlo, monospace" font-size="12" font-weight="600" fill="#B4C9D4" letter-spacing="2">YOUR RUNTIME</text>
|
|
43
|
+
|
|
44
|
+
<rect x="82" y="206" width="202" height="42" rx="12" fill="#173E4D" fill-opacity="0.95" stroke="white" stroke-opacity="0.06"/>
|
|
45
|
+
<text x="183" y="231" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" font-weight="600" fill="white">Node servers</text>
|
|
46
|
+
|
|
47
|
+
<rect x="82" y="260" width="202" height="42" rx="12" fill="#173E4D" fill-opacity="0.88" stroke="white" stroke-opacity="0.06"/>
|
|
48
|
+
<text x="183" y="285" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" font-weight="600" fill="white">Workers and jobs</text>
|
|
49
|
+
|
|
50
|
+
<rect x="82" y="314" width="202" height="42" rx="12" fill="#173E4D" fill-opacity="0.82" stroke="white" stroke-opacity="0.06"/>
|
|
51
|
+
<text x="183" y="339" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" font-weight="600" fill="white">Edge or BFF layers</text>
|
|
52
|
+
|
|
53
|
+
<rect x="366" y="128" width="338" height="256" rx="24" fill="#0D3446" fill-opacity="0.9" stroke="url(#highlightStroke)" stroke-width="1.5"/>
|
|
54
|
+
<text x="394" y="162" font-family="'SFMono-Regular', Menlo, monospace" font-size="12" font-weight="600" fill="#BFEBFF" letter-spacing="2">SDK LAYER</text>
|
|
55
|
+
<text x="394" y="214" font-family="'SFMono-Regular', Menlo, monospace" font-size="28" font-weight="700" fill="white">@amigo-ai/platform-sdk</text>
|
|
56
|
+
<text x="394" y="245" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" fill="#C4D8E1">Typed workspace-scoped client for the Platform API.</text>
|
|
57
|
+
<text x="394" y="271" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" fill="#C4D8E1">It keeps auth, retries, webhooks, request control,</text>
|
|
58
|
+
<text x="394" y="295" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="16" fill="#C4D8E1">and generated types on the package surface.</text>
|
|
59
|
+
|
|
60
|
+
<rect x="394" y="321" width="114" height="30" rx="15" fill="#123D50" stroke="#7CCFFF" stroke-opacity="0.28"/>
|
|
61
|
+
<text x="451" y="340" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="13" font-weight="600" fill="#DFF4FF">Typed surface</text>
|
|
62
|
+
<rect x="519" y="321" width="104" height="30" rx="15" fill="#123D50" stroke="#7CCFFF" stroke-opacity="0.22"/>
|
|
63
|
+
<text x="571" y="340" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="13" font-weight="600" fill="#DFF4FF">ESM + CJS</text>
|
|
64
|
+
<rect x="394" y="360" width="110" height="30" rx="15" fill="#123D50" stroke="#7CCFFF" stroke-opacity="0.22"/>
|
|
65
|
+
<text x="449" y="379" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="13" font-weight="600" fill="#DFF4FF">Webhooks</text>
|
|
66
|
+
<rect x="515" y="360" width="136" height="30" rx="15" fill="#123D50" stroke="#7CCFFF" stroke-opacity="0.22"/>
|
|
67
|
+
<text x="583" y="379" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="13" font-weight="600" fill="#DFF4FF">Request control</text>
|
|
68
|
+
|
|
69
|
+
<rect x="764" y="110" width="376" height="296" rx="22" fill="white" fill-opacity="0.045" stroke="url(#panelStroke)" stroke-width="1"/>
|
|
70
|
+
<text x="792" y="142" font-family="'SFMono-Regular', Menlo, monospace" font-size="12" font-weight="600" fill="#B4C9D4" letter-spacing="2">PLATFORM API</text>
|
|
71
|
+
<text x="792" y="172" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="15" fill="#C0D4DE">Workspace-scoped REST resources exposed by the SDK.</text>
|
|
72
|
+
|
|
73
|
+
<rect x="792" y="198" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.9" stroke="white" stroke-opacity="0.06"/>
|
|
74
|
+
<text x="866" y="222" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">Agents</text>
|
|
75
|
+
<text x="866" y="241" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Actions, skills, services</text>
|
|
76
|
+
|
|
77
|
+
<rect x="962" y="198" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.86" stroke="white" stroke-opacity="0.06"/>
|
|
78
|
+
<text x="1036" y="222" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">Calls</text>
|
|
79
|
+
<text x="1036" y="241" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Voice, history, recordings</text>
|
|
80
|
+
|
|
81
|
+
<rect x="792" y="270" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.86" stroke="white" stroke-opacity="0.06"/>
|
|
82
|
+
<text x="866" y="294" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">World</text>
|
|
83
|
+
<text x="866" y="313" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Entities and events</text>
|
|
84
|
+
|
|
85
|
+
<rect x="962" y="270" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.82" stroke="white" stroke-opacity="0.06"/>
|
|
86
|
+
<text x="1036" y="294" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">Analytics</text>
|
|
87
|
+
<text x="1036" y="313" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Dashboards and trends</text>
|
|
88
|
+
|
|
89
|
+
<rect x="792" y="342" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.82" stroke="white" stroke-opacity="0.06"/>
|
|
90
|
+
<text x="866" y="366" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">Webhooks</text>
|
|
91
|
+
<text x="866" y="385" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Signed inbound events</text>
|
|
92
|
+
|
|
93
|
+
<rect x="962" y="342" width="148" height="54" rx="14" fill="#173E4D" fill-opacity="0.78" stroke="white" stroke-opacity="0.06"/>
|
|
94
|
+
<text x="1036" y="366" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="17" font-weight="600" fill="white">Operations</text>
|
|
95
|
+
<text x="1036" y="385" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="12" fill="#B0C5CF">Operators, integrations, numbers</text>
|
|
96
|
+
|
|
97
|
+
<path d="M 306 256 C 328 256 344 256 366 256" fill="none" stroke="url(#arrowStroke)" stroke-width="2.5" stroke-linecap="round" marker-end="url(#arrow)"/>
|
|
98
|
+
|
|
99
|
+
<path d="M 704 256 C 728 256 740 256 764 256" fill="none" stroke="url(#arrowStroke)" stroke-width="2.5" stroke-linecap="round" marker-end="url(#arrow)"/>
|
|
100
|
+
|
|
101
|
+
<path d="M 952 406 C 952 420 952 430 952 446" fill="none" stroke="url(#arrowStroke)" stroke-width="2.5" stroke-linecap="round" marker-end="url(#arrow)"/>
|
|
102
|
+
|
|
103
|
+
<rect x="60" y="448" width="1080" height="70" rx="20" fill="white" fill-opacity="0.05" stroke="url(#panelStroke)" stroke-width="1"/>
|
|
104
|
+
<text x="88" y="477" font-family="'SFMono-Regular', Menlo, monospace" font-size="12" font-weight="600" fill="#B4C9D4" letter-spacing="2">PLATFORM SYSTEMS</text>
|
|
105
|
+
|
|
106
|
+
<rect x="84" y="487" width="238" height="18" rx="9" fill="#173E4D" fill-opacity="0.84"/>
|
|
107
|
+
<text x="203" y="500" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="11" font-weight="600" fill="#D6E7EE">Connectors and EHR sync</text>
|
|
108
|
+
|
|
109
|
+
<rect x="350" y="487" width="222" height="18" rx="9" fill="#173E4D" fill-opacity="0.84"/>
|
|
110
|
+
<text x="461" y="500" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="11" font-weight="600" fill="#D6E7EE">World model and projections</text>
|
|
111
|
+
|
|
112
|
+
<rect x="600" y="487" width="226" height="18" rx="9" fill="#173E4D" fill-opacity="0.84"/>
|
|
113
|
+
<text x="713" y="500" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="11" font-weight="600" fill="#D6E7EE">Operators and outbound automation</text>
|
|
114
|
+
|
|
115
|
+
<rect x="854" y="487" width="262" height="18" rx="9" fill="#173E4D" fill-opacity="0.84"/>
|
|
116
|
+
<text x="985" y="500" text-anchor="middle" font-family="'Inter', 'Helvetica Neue', Arial, sans-serif" font-size="11" font-weight="600" fill="#D6E7EE">Observability, analytics, and webhook delivery</text>
|
|
117
|
+
</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,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AE,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) {
|