@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/README.md +1 -1
  3. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  4. package/dist/agents/ReactiveAgent.js +3 -0
  5. package/dist/agents/ReactiveAgent.js.map +1 -1
  6. package/dist/connector/mcp/stdio.d.ts +11 -0
  7. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  8. package/dist/connector/mcp/stdio.js +106 -1
  9. package/dist/connector/mcp/stdio.js.map +1 -1
  10. package/dist/constants/telemetry/index.d.ts +15 -1
  11. package/dist/constants/telemetry/index.d.ts.map +1 -1
  12. package/dist/constants/telemetry/index.js +15 -1
  13. package/dist/constants/telemetry/index.js.map +1 -1
  14. package/dist/provider/fallback.d.ts.map +1 -1
  15. package/dist/provider/fallback.js +8 -2
  16. package/dist/provider/fallback.js.map +1 -1
  17. package/dist/provider/retry.d.ts +10 -5
  18. package/dist/provider/retry.d.ts.map +1 -1
  19. package/dist/provider/retry.js +11 -31
  20. package/dist/provider/retry.js.map +1 -1
  21. package/dist/public-runtime.d.ts +1 -0
  22. package/dist/public-runtime.d.ts.map +1 -1
  23. package/dist/public-runtime.js.map +1 -1
  24. package/dist/registry/tool/execute.d.ts.map +1 -1
  25. package/dist/registry/tool/execute.js +12 -0
  26. package/dist/registry/tool/execute.js.map +1 -1
  27. package/dist/runtime/query/executor.d.ts +34 -0
  28. package/dist/runtime/query/executor.d.ts.map +1 -1
  29. package/dist/runtime/query/executor.js +61 -0
  30. package/dist/runtime/query/executor.js.map +1 -1
  31. package/dist/runtime/query/index.d.ts +31 -13
  32. package/dist/runtime/query/index.d.ts.map +1 -1
  33. package/dist/runtime/query/index.js +28 -6
  34. package/dist/runtime/query/index.js.map +1 -1
  35. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  36. package/dist/runtime/query/iteration/index.js +178 -20
  37. package/dist/runtime/query/iteration/index.js.map +1 -1
  38. package/dist/runtime/query/iteration/stream-turn.d.ts +14 -1
  39. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  40. package/dist/runtime/query/iteration/stream-turn.js +19 -3
  41. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  42. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  43. package/dist/runtime/query/resume-pending.js +10 -1
  44. package/dist/runtime/query/resume-pending.js.map +1 -1
  45. package/dist/runtime/query/tool-pause.d.ts +35 -0
  46. package/dist/runtime/query/tool-pause.d.ts.map +1 -1
  47. package/dist/runtime/query/tool-pause.js +35 -0
  48. package/dist/runtime/query/tool-pause.js.map +1 -1
  49. package/dist/runtime/query/tooling.d.ts +2 -0
  50. package/dist/runtime/query/tooling.d.ts.map +1 -1
  51. package/dist/runtime/query/tooling.js +3 -0
  52. package/dist/runtime/query/tooling.js.map +1 -1
  53. package/dist/types/agent/reactive.d.ts +1 -0
  54. package/dist/types/agent/reactive.d.ts.map +1 -1
  55. package/dist/types/connector/mcp.d.ts +17 -0
  56. package/dist/types/connector/mcp.d.ts.map +1 -1
  57. package/dist/types/provider/interface.d.ts +23 -2
  58. package/dist/types/provider/interface.d.ts.map +1 -1
  59. package/dist/types/run/step.d.ts +75 -3
  60. package/dist/types/run/step.d.ts.map +1 -1
  61. package/dist/types/run/step.js.map +1 -1
  62. package/dist/utils/backoff.d.ts +44 -0
  63. package/dist/utils/backoff.d.ts.map +1 -0
  64. package/dist/utils/backoff.js +58 -0
  65. package/dist/utils/backoff.js.map +1 -0
  66. package/package.json +1 -1
  67. package/src/agents/ReactiveAgent.ts +3 -0
  68. package/src/connector/mcp/stdio.ts +106 -1
  69. package/src/constants/telemetry/index.ts +16 -1
  70. package/src/provider/fallback.ts +8 -2
  71. package/src/provider/retry.ts +20 -37
  72. package/src/public-runtime.ts +5 -0
  73. package/src/registry/tool/execute.ts +12 -0
  74. package/src/runtime/query/executor.ts +74 -0
  75. package/src/runtime/query/index.ts +59 -18
  76. package/src/runtime/query/iteration/index.ts +199 -22
  77. package/src/runtime/query/iteration/stream-turn.ts +24 -3
  78. package/src/runtime/query/resume-pending.ts +10 -1
  79. package/src/runtime/query/tool-pause.ts +37 -0
  80. package/src/runtime/query/tooling.ts +5 -0
  81. package/src/types/agent/reactive.ts +1 -0
  82. package/src/types/connector/mcp.ts +17 -0
  83. package/src/types/provider/interface.ts +23 -2
  84. package/src/types/run/step.ts +76 -3
  85. 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
+ }