@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.
- package/CHANGELOG.md +28 -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/execution/code-runtime/types.d.ts +35 -0
- package/dist/execution/code-runtime/types.d.ts.map +1 -1
- package/dist/execution/code-runtime/types.js.map +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
- package/dist/execution/code-runtime/worker-program.js +72 -13
- package/dist/execution/code-runtime/worker-program.js.map +1 -1
- package/dist/execution/code-runtime/worker.d.ts.map +1 -1
- package/dist/execution/code-runtime/worker.js +35 -1
- package/dist/execution/code-runtime/worker.js.map +1 -1
- package/dist/execution/workflow/errors.d.ts +5 -0
- package/dist/execution/workflow/errors.d.ts.map +1 -0
- package/dist/execution/workflow/errors.js +8 -0
- package/dist/execution/workflow/errors.js.map +1 -0
- package/dist/execution/workflow/index.d.ts +9 -0
- package/dist/execution/workflow/index.d.ts.map +1 -0
- package/dist/execution/workflow/index.js +6 -0
- package/dist/execution/workflow/index.js.map +1 -0
- package/dist/execution/workflow/journal.d.ts +18 -0
- package/dist/execution/workflow/journal.d.ts.map +1 -0
- package/dist/execution/workflow/journal.js +43 -0
- package/dist/execution/workflow/journal.js.map +1 -0
- package/dist/execution/workflow/meta.d.ts +14 -0
- package/dist/execution/workflow/meta.d.ts.map +1 -0
- package/dist/execution/workflow/meta.js +314 -0
- package/dist/execution/workflow/meta.js.map +1 -0
- package/dist/execution/workflow/phases.d.ts +32 -0
- package/dist/execution/workflow/phases.d.ts.map +1 -0
- package/dist/execution/workflow/phases.js +57 -0
- package/dist/execution/workflow/phases.js.map +1 -0
- package/dist/execution/workflow/prelude.d.ts +15 -0
- package/dist/execution/workflow/prelude.d.ts.map +1 -0
- package/dist/execution/workflow/prelude.js +128 -0
- package/dist/execution/workflow/prelude.js.map +1 -0
- package/dist/execution/workflow/runtime.d.ts +31 -0
- package/dist/execution/workflow/runtime.d.ts.map +1 -0
- package/dist/execution/workflow/runtime.js +682 -0
- package/dist/execution/workflow/runtime.js.map +1 -0
- package/dist/execution/workflow/schema.d.ts +10 -0
- package/dist/execution/workflow/schema.d.ts.map +1 -0
- package/dist/execution/workflow/schema.js +145 -0
- package/dist/execution/workflow/schema.js.map +1 -0
- package/dist/execution/workflow/types.d.ts +267 -0
- package/dist/execution/workflow/types.d.ts.map +1 -0
- package/dist/execution/workflow/types.js +7 -0
- package/dist/execution/workflow/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +2 -1
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/process/kill-tree.d.ts +7 -0
- package/dist/process/kill-tree.d.ts.map +1 -1
- package/dist/process/kill-tree.js +41 -0
- package/dist/process/kill-tree.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/provider/token-budget.d.ts.map +1 -1
- package/dist/provider/token-budget.js +31 -2
- package/dist/provider/token-budget.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 +3 -0
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/job-id.d.ts +21 -0
- package/dist/runtime/jobs/job-id.d.ts.map +1 -0
- package/dist/runtime/jobs/job-id.js +66 -0
- package/dist/runtime/jobs/job-id.js.map +1 -0
- package/dist/runtime/jobs/registry.d.ts +0 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +2 -3
- package/dist/runtime/jobs/registry.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/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +5 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +8 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +20 -3
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -0
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +4 -0
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/command-shell.d.ts +55 -0
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +174 -13
- package/dist/tools/command-shell.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/agents/AGENTS.md +134 -46
- package/src/bridge/sse/mapper.ts +1 -0
- package/src/execution/code-runtime/types.ts +37 -1
- package/src/execution/code-runtime/worker-program.ts +72 -13
- package/src/execution/code-runtime/worker.ts +40 -1
- package/src/execution/workflow/errors.ts +7 -0
- package/src/execution/workflow/index.ts +8 -0
- package/src/execution/workflow/journal.ts +46 -0
- package/src/execution/workflow/meta.ts +316 -0
- package/src/execution/workflow/phases.ts +91 -0
- package/src/execution/workflow/prelude.ts +135 -0
- package/src/execution/workflow/runtime.ts +786 -0
- package/src/execution/workflow/schema.ts +137 -0
- package/src/execution/workflow/types.ts +300 -0
- package/src/index.ts +4 -0
- package/src/plugin/shell-hook.ts +2 -1
- package/src/process/kill-tree.ts +43 -0
- package/src/provider/errors.ts +18 -0
- package/src/provider/retry.ts +53 -3
- package/src/provider/token-budget.ts +31 -1
- package/src/public-runtime.ts +11 -0
- package/src/public-tools.ts +6 -0
- package/src/public-types.ts +3 -0
- package/src/runtime/jobs/job-id.ts +66 -0
- package/src/runtime/jobs/registry.ts +2 -3
- package/src/runtime/query/iteration/stream-turn.ts +24 -1
- package/src/runtime/query/prompt.ts +5 -1
- package/src/tools/builtins/bash.ts +33 -3
- package/src/tools/builtins/job.ts +4 -0
- package/src/tools/builtins/wait-for-job.ts +4 -0
- package/src/tools/command-shell.ts +194 -11
- 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
|
@@ -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
|
-
|
|
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
|
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
|
*
|