@namzu/sdk 23.0.0 → 26.0.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 +208 -0
- package/README.md +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +3 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/connector/mcp/stdio.d.ts +11 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +106 -1
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/constants/telemetry/index.d.ts +15 -1
- package/dist/constants/telemetry/index.d.ts.map +1 -1
- package/dist/constants/telemetry/index.js +15 -1
- package/dist/constants/telemetry/index.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +8 -2
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/retry.d.ts +10 -5
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +11 -31
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +1 -0
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +12 -0
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +34 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +61 -0
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +31 -13
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +28 -6
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +178 -20
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts +14 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +19 -3
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +10 -1
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/tool-pause.d.ts +35 -0
- package/dist/runtime/query/tool-pause.d.ts.map +1 -1
- package/dist/runtime/query/tool-pause.js +35 -0
- package/dist/runtime/query/tool-pause.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +2 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +3 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/types/agent/reactive.d.ts +1 -0
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +17 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +23 -2
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/run/step.d.ts +75 -3
- package/dist/types/run/step.d.ts.map +1 -1
- package/dist/types/run/step.js.map +1 -1
- package/dist/utils/backoff.d.ts +44 -0
- package/dist/utils/backoff.d.ts.map +1 -0
- package/dist/utils/backoff.js +58 -0
- package/dist/utils/backoff.js.map +1 -0
- package/package.json +1 -1
- package/src/agents/ReactiveAgent.ts +3 -0
- package/src/connector/mcp/stdio.ts +106 -1
- package/src/constants/telemetry/index.ts +16 -1
- package/src/provider/fallback.ts +8 -2
- package/src/provider/retry.ts +20 -37
- package/src/public-runtime.ts +5 -0
- package/src/registry/tool/execute.ts +12 -0
- package/src/runtime/query/executor.ts +74 -0
- package/src/runtime/query/index.ts +59 -18
- package/src/runtime/query/iteration/index.ts +199 -22
- package/src/runtime/query/iteration/stream-turn.ts +24 -3
- package/src/runtime/query/resume-pending.ts +10 -1
- package/src/runtime/query/tool-pause.ts +37 -0
- package/src/runtime/query/tooling.ts +5 -0
- package/src/types/agent/reactive.ts +1 -0
- package/src/types/connector/mcp.ts +17 -0
- package/src/types/provider/interface.ts +23 -2
- package/src/types/run/step.ts +76 -3
- package/src/utils/backoff.ts +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exponential backoff with full jitter, and an abortable sleep.
|
|
3
|
+
*
|
|
4
|
+
* Both were private to `provider/retry.ts`, which is where they were needed
|
|
5
|
+
* first and is not where they stop being needed. The tool executor's in-loop
|
|
6
|
+
* retry re-ran a failed call immediately, several times, which is the pattern
|
|
7
|
+
* most likely to prolong the very condition it is retrying against — and the
|
|
8
|
+
* correct implementation was one directory away, already reviewed, already
|
|
9
|
+
* doing the hard part right.
|
|
10
|
+
*
|
|
11
|
+
* So they live here, in one copy, and both retry loops call them. A second
|
|
12
|
+
* implementation of a backoff curve is a second thing to get wrong, and the
|
|
13
|
+
* two would drift on exactly the axis nobody re-derives: jitter.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The shape a backoff curve needs. */
|
|
17
|
+
export interface BackoffPolicy {
|
|
18
|
+
/** First backoff, doubled each attempt. */
|
|
19
|
+
readonly initialDelayMs: number
|
|
20
|
+
/** Ceiling for a single backoff, before jitter. */
|
|
21
|
+
readonly maxDelayMs: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Full jitter (AWS's formulation): sleep a uniform random amount in
|
|
26
|
+
* `[0, backoff]` rather than `backoff` exactly. Equal-jitter and no-jitter
|
|
27
|
+
* both keep a fleet of clients that failed together retrying together;
|
|
28
|
+
* full jitter is what actually spreads a thundering herd.
|
|
29
|
+
*
|
|
30
|
+
* `attempt` is 0-based: attempt 0 draws from `[0, initialDelayMs]`.
|
|
31
|
+
*
|
|
32
|
+
* The concurrency this matters for is not hypothetical on the tool path. A
|
|
33
|
+
* model emits a batch of parallel calls, they hit one rate-limited endpoint
|
|
34
|
+
* together, and they fail together — so a fixed delay would resynchronise
|
|
35
|
+
* them on every attempt, which is a herd this loop creates itself.
|
|
36
|
+
*/
|
|
37
|
+
export function backoffWithJitter(
|
|
38
|
+
attempt: number,
|
|
39
|
+
policy: BackoffPolicy,
|
|
40
|
+
random: () => number = Math.random,
|
|
41
|
+
): number {
|
|
42
|
+
const exponential = Math.min(policy.initialDelayMs * 2 ** attempt, policy.maxDelayMs)
|
|
43
|
+
return Math.round(random() * exponential)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sleep, unless the signal says not to.
|
|
48
|
+
*
|
|
49
|
+
* Rejects with the signal's reason when aborted — before sleeping if it is
|
|
50
|
+
* already aborted, and mid-sleep otherwise. A caller that must not throw over
|
|
51
|
+
* an abort catches it; a caller that wants the abort to propagate does not.
|
|
52
|
+
*/
|
|
53
|
+
export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
54
|
+
if (ms <= 0) return Promise.resolve()
|
|
55
|
+
return new Promise<void>((resolve, reject) => {
|
|
56
|
+
if (signal?.aborted) {
|
|
57
|
+
reject(signal.reason)
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
const timer = setTimeout(() => {
|
|
61
|
+
signal?.removeEventListener('abort', onAbort)
|
|
62
|
+
resolve()
|
|
63
|
+
}, ms)
|
|
64
|
+
const onAbort = () => {
|
|
65
|
+
clearTimeout(timer)
|
|
66
|
+
reject(signal?.reason)
|
|
67
|
+
}
|
|
68
|
+
signal?.addEventListener('abort', onAbort, { once: true })
|
|
69
|
+
})
|
|
70
|
+
}
|