@namzu/sdk 51.0.0 → 51.1.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/CHANGELOG.md +10 -0
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +1 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/provider/errors.d.ts +10 -0
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +16 -0
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/retry.d.ts +27 -0
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +19 -3
- package/dist/provider/retry.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +24 -1
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/types/provider/error.d.ts +6 -0
- package/dist/types/provider/error.d.ts.map +1 -1
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +15 -1
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/provider/stream.d.ts +6 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/session/events.d.ts +5 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/utils/backoff.d.ts +12 -0
- package/dist/utils/backoff.d.ts.map +1 -1
- package/dist/utils/backoff.js +15 -0
- package/dist/utils/backoff.js.map +1 -1
- package/package.json +1 -1
- package/src/bridge/sse/mapper.ts +1 -0
- package/src/provider/errors.ts +18 -0
- package/src/provider/retry.ts +53 -3
- package/src/runtime/query/iteration/stream-turn.ts +24 -1
- package/src/types/provider/error.ts +6 -0
- package/src/types/provider/errors.ts +16 -1
- package/src/types/provider/stream.ts +6 -0
- package/src/types/session/events.ts +5 -0
- package/src/utils/backoff.ts +21 -0
package/src/utils/backoff.ts
CHANGED
|
@@ -43,6 +43,27 @@ export function backoffWithJitter(
|
|
|
43
43
|
return Math.round(random() * exponential)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Exponential backoff that only ever adds jitter: the delay is the exponential
|
|
48
|
+
* step plus up to `ratio` of itself (a quarter by default), never less.
|
|
49
|
+
*
|
|
50
|
+
* Full jitter spreads a herd better but can answer a failure after a few
|
|
51
|
+
* milliseconds, which is a poor way to treat a server that just said it is
|
|
52
|
+
* struggling. This curve keeps the floor of every step, so a person watching a
|
|
53
|
+
* countdown sees a wait that grows the way the numbers on screen say it does.
|
|
54
|
+
*
|
|
55
|
+
* `attempt` is 0-based: attempt 0 draws from `[initialDelayMs, initialDelayMs * (1 + ratio)]`.
|
|
56
|
+
*/
|
|
57
|
+
export function backoffProportional(
|
|
58
|
+
attempt: number,
|
|
59
|
+
policy: BackoffPolicy,
|
|
60
|
+
random: () => number = Math.random,
|
|
61
|
+
ratio = 0.25,
|
|
62
|
+
): number {
|
|
63
|
+
const exponential = Math.min(policy.initialDelayMs * 2 ** attempt, policy.maxDelayMs)
|
|
64
|
+
return Math.round(exponential + random() * ratio * exponential)
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
/**
|
|
47
68
|
* Sleep, unless the signal says not to.
|
|
48
69
|
*
|