@namzu/sdk 50.1.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.
Files changed (161) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  3. package/dist/bridge/sse/mapper.js +1 -0
  4. package/dist/bridge/sse/mapper.js.map +1 -1
  5. package/dist/execution/code-runtime/types.d.ts +35 -0
  6. package/dist/execution/code-runtime/types.d.ts.map +1 -1
  7. package/dist/execution/code-runtime/types.js.map +1 -1
  8. package/dist/execution/code-runtime/worker-program.d.ts +1 -1
  9. package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
  10. package/dist/execution/code-runtime/worker-program.js +72 -13
  11. package/dist/execution/code-runtime/worker-program.js.map +1 -1
  12. package/dist/execution/code-runtime/worker.d.ts.map +1 -1
  13. package/dist/execution/code-runtime/worker.js +35 -1
  14. package/dist/execution/code-runtime/worker.js.map +1 -1
  15. package/dist/execution/workflow/errors.d.ts +5 -0
  16. package/dist/execution/workflow/errors.d.ts.map +1 -0
  17. package/dist/execution/workflow/errors.js +8 -0
  18. package/dist/execution/workflow/errors.js.map +1 -0
  19. package/dist/execution/workflow/index.d.ts +9 -0
  20. package/dist/execution/workflow/index.d.ts.map +1 -0
  21. package/dist/execution/workflow/index.js +6 -0
  22. package/dist/execution/workflow/index.js.map +1 -0
  23. package/dist/execution/workflow/journal.d.ts +18 -0
  24. package/dist/execution/workflow/journal.d.ts.map +1 -0
  25. package/dist/execution/workflow/journal.js +43 -0
  26. package/dist/execution/workflow/journal.js.map +1 -0
  27. package/dist/execution/workflow/meta.d.ts +14 -0
  28. package/dist/execution/workflow/meta.d.ts.map +1 -0
  29. package/dist/execution/workflow/meta.js +314 -0
  30. package/dist/execution/workflow/meta.js.map +1 -0
  31. package/dist/execution/workflow/phases.d.ts +32 -0
  32. package/dist/execution/workflow/phases.d.ts.map +1 -0
  33. package/dist/execution/workflow/phases.js +57 -0
  34. package/dist/execution/workflow/phases.js.map +1 -0
  35. package/dist/execution/workflow/prelude.d.ts +15 -0
  36. package/dist/execution/workflow/prelude.d.ts.map +1 -0
  37. package/dist/execution/workflow/prelude.js +128 -0
  38. package/dist/execution/workflow/prelude.js.map +1 -0
  39. package/dist/execution/workflow/runtime.d.ts +31 -0
  40. package/dist/execution/workflow/runtime.d.ts.map +1 -0
  41. package/dist/execution/workflow/runtime.js +682 -0
  42. package/dist/execution/workflow/runtime.js.map +1 -0
  43. package/dist/execution/workflow/schema.d.ts +10 -0
  44. package/dist/execution/workflow/schema.d.ts.map +1 -0
  45. package/dist/execution/workflow/schema.js +145 -0
  46. package/dist/execution/workflow/schema.js.map +1 -0
  47. package/dist/execution/workflow/types.d.ts +267 -0
  48. package/dist/execution/workflow/types.d.ts.map +1 -0
  49. package/dist/execution/workflow/types.js +7 -0
  50. package/dist/execution/workflow/types.js.map +1 -0
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/plugin/shell-hook.d.ts.map +1 -1
  56. package/dist/plugin/shell-hook.js +2 -1
  57. package/dist/plugin/shell-hook.js.map +1 -1
  58. package/dist/process/kill-tree.d.ts +7 -0
  59. package/dist/process/kill-tree.d.ts.map +1 -1
  60. package/dist/process/kill-tree.js +41 -0
  61. package/dist/process/kill-tree.js.map +1 -1
  62. package/dist/provider/errors.d.ts +10 -0
  63. package/dist/provider/errors.d.ts.map +1 -1
  64. package/dist/provider/errors.js +16 -0
  65. package/dist/provider/errors.js.map +1 -1
  66. package/dist/provider/retry.d.ts +27 -0
  67. package/dist/provider/retry.d.ts.map +1 -1
  68. package/dist/provider/retry.js +19 -3
  69. package/dist/provider/retry.js.map +1 -1
  70. package/dist/provider/token-budget.d.ts.map +1 -1
  71. package/dist/provider/token-budget.js +31 -2
  72. package/dist/provider/token-budget.js.map +1 -1
  73. package/dist/public-runtime.d.ts +1 -0
  74. package/dist/public-runtime.d.ts.map +1 -1
  75. package/dist/public-runtime.js +3 -0
  76. package/dist/public-runtime.js.map +1 -1
  77. package/dist/public-tools.d.ts +1 -1
  78. package/dist/public-tools.d.ts.map +1 -1
  79. package/dist/public-tools.js +1 -1
  80. package/dist/public-tools.js.map +1 -1
  81. package/dist/public-types.d.ts +3 -0
  82. package/dist/public-types.d.ts.map +1 -1
  83. package/dist/runtime/jobs/job-id.d.ts +21 -0
  84. package/dist/runtime/jobs/job-id.d.ts.map +1 -0
  85. package/dist/runtime/jobs/job-id.js +66 -0
  86. package/dist/runtime/jobs/job-id.js.map +1 -0
  87. package/dist/runtime/jobs/registry.d.ts +0 -1
  88. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  89. package/dist/runtime/jobs/registry.js +2 -3
  90. package/dist/runtime/jobs/registry.js.map +1 -1
  91. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  92. package/dist/runtime/query/iteration/stream-turn.js +24 -1
  93. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  94. package/dist/runtime/query/prompt.d.ts.map +1 -1
  95. package/dist/runtime/query/prompt.js +5 -1
  96. package/dist/runtime/query/prompt.js.map +1 -1
  97. package/dist/tools/builtins/bash.d.ts +8 -1
  98. package/dist/tools/builtins/bash.d.ts.map +1 -1
  99. package/dist/tools/builtins/bash.js +20 -3
  100. package/dist/tools/builtins/bash.js.map +1 -1
  101. package/dist/tools/builtins/job.d.ts.map +1 -1
  102. package/dist/tools/builtins/job.js +4 -0
  103. package/dist/tools/builtins/job.js.map +1 -1
  104. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  105. package/dist/tools/builtins/wait-for-job.js +4 -0
  106. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  107. package/dist/tools/command-shell.d.ts +55 -0
  108. package/dist/tools/command-shell.d.ts.map +1 -1
  109. package/dist/tools/command-shell.js +174 -13
  110. package/dist/tools/command-shell.js.map +1 -1
  111. package/dist/types/provider/error.d.ts +6 -0
  112. package/dist/types/provider/error.d.ts.map +1 -1
  113. package/dist/types/provider/errors.d.ts.map +1 -1
  114. package/dist/types/provider/errors.js +15 -1
  115. package/dist/types/provider/errors.js.map +1 -1
  116. package/dist/types/provider/stream.d.ts +6 -0
  117. package/dist/types/provider/stream.d.ts.map +1 -1
  118. package/dist/types/session/events.d.ts +5 -0
  119. package/dist/types/session/events.d.ts.map +1 -1
  120. package/dist/types/session/events.js.map +1 -1
  121. package/dist/utils/backoff.d.ts +12 -0
  122. package/dist/utils/backoff.d.ts.map +1 -1
  123. package/dist/utils/backoff.js +15 -0
  124. package/dist/utils/backoff.js.map +1 -1
  125. package/package.json +1 -1
  126. package/src/agents/AGENTS.md +134 -46
  127. package/src/bridge/sse/mapper.ts +1 -0
  128. package/src/execution/code-runtime/types.ts +37 -1
  129. package/src/execution/code-runtime/worker-program.ts +72 -13
  130. package/src/execution/code-runtime/worker.ts +40 -1
  131. package/src/execution/workflow/errors.ts +7 -0
  132. package/src/execution/workflow/index.ts +8 -0
  133. package/src/execution/workflow/journal.ts +46 -0
  134. package/src/execution/workflow/meta.ts +316 -0
  135. package/src/execution/workflow/phases.ts +91 -0
  136. package/src/execution/workflow/prelude.ts +135 -0
  137. package/src/execution/workflow/runtime.ts +786 -0
  138. package/src/execution/workflow/schema.ts +137 -0
  139. package/src/execution/workflow/types.ts +300 -0
  140. package/src/index.ts +4 -0
  141. package/src/plugin/shell-hook.ts +2 -1
  142. package/src/process/kill-tree.ts +43 -0
  143. package/src/provider/errors.ts +18 -0
  144. package/src/provider/retry.ts +53 -3
  145. package/src/provider/token-budget.ts +31 -1
  146. package/src/public-runtime.ts +11 -0
  147. package/src/public-tools.ts +6 -0
  148. package/src/public-types.ts +3 -0
  149. package/src/runtime/jobs/job-id.ts +66 -0
  150. package/src/runtime/jobs/registry.ts +2 -3
  151. package/src/runtime/query/iteration/stream-turn.ts +24 -1
  152. package/src/runtime/query/prompt.ts +5 -1
  153. package/src/tools/builtins/bash.ts +33 -3
  154. package/src/tools/builtins/job.ts +4 -0
  155. package/src/tools/builtins/wait-for-job.ts +4 -0
  156. package/src/tools/command-shell.ts +194 -11
  157. package/src/types/provider/error.ts +6 -0
  158. package/src/types/provider/errors.ts +16 -1
  159. package/src/types/provider/stream.ts +6 -0
  160. package/src/types/session/events.ts +5 -0
  161. package/src/utils/backoff.ts +21 -0
@@ -54,6 +54,16 @@ export interface ProviderErrorInit {
54
54
  readonly cause?: unknown
55
55
  }
56
56
 
57
+ function shouldRetryHeader(link: Record<string, unknown>): false | undefined {
58
+ const headers = link.headers
59
+ if (!headers || typeof headers !== 'object') return undefined
60
+ const raw =
61
+ typeof (headers as Headers).get === 'function'
62
+ ? (headers as Headers).get('x-should-retry')
63
+ : (headers as Record<string, unknown>)['x-should-retry']
64
+ return typeof raw === 'string' && raw.trim().toLowerCase() === 'false' ? false : undefined
65
+ }
66
+
57
67
  /**
58
68
  * A `retryable` flag declared anywhere on the cause chain.
59
69
  *
@@ -72,6 +82,9 @@ export function declaredRetryable(err: unknown): boolean | undefined {
72
82
  for (const link of causeChain(err)) {
73
83
  const declared = link.retryable
74
84
  if (typeof declared === 'boolean') return declared
85
+ // A raw vendor error that still carries its response headers: the
86
+ // provider's own `x-should-retry: false` is a first-hand "do not resend".
87
+ if (shouldRetryHeader(link) === false) return false
75
88
  }
76
89
  return undefined
77
90
  }
@@ -395,6 +408,7 @@ function classifyFromProviderRequestError(
395
408
  providerId?: unknown
396
409
  status?: unknown
397
410
  retryAfterMs?: unknown
411
+ shouldRetry?: unknown
398
412
  }
399
413
  if (typeof candidate.kind !== 'string') return undefined
400
414
  const mapped = KIND_TO_CODE[candidate.kind]
@@ -406,7 +420,8 @@ function classifyFromProviderRequestError(
406
420
  return new ProviderError({
407
421
  code: mapped.code,
408
422
  message: err.message,
409
- retryable: mapped.retryable,
423
+ // The provider saying "do not resend" beats the kind's own verdict.
424
+ retryable: candidate.shouldRetry === false ? false : mapped.retryable,
410
425
  cause: err,
411
426
  ...(typeof candidate.providerId === 'string'
412
427
  ? { providerId: candidate.providerId }
@@ -173,6 +173,12 @@ export interface ProviderRetryNotice {
173
173
  readonly status?: number
174
174
  /** The delay came from the server's own `Retry-After`, not backoff. */
175
175
  readonly serverDirected: boolean
176
+ /**
177
+ * The failed attempt had already streamed text or reasoning, and the request
178
+ * is being sent again from the start. Whatever that attempt produced is void
179
+ * and the consumer must drop it before the next chunk.
180
+ */
181
+ readonly restart?: boolean
176
182
  }
177
183
 
178
184
  /**
@@ -381,6 +381,11 @@ type CoreSessionEvent =
381
381
  status?: number
382
382
  /** The delay came from the server's own `Retry-After`. */
383
383
  serverDirected: boolean
384
+ /**
385
+ * The failed attempt had already streamed text or reasoning and the
386
+ * request starts over: drop what this message showed so far.
387
+ */
388
+ restart?: boolean
384
389
  }
385
390
  /**
386
391
  * A member of the provider chain could not serve, and a later member has
@@ -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
  *