@parcha/agentrun-dsl 0.1.0-beta.111 → 0.1.0-beta.112

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/README.md CHANGED
@@ -178,7 +178,7 @@ The package root exports a deliberate API. The beta retains agent, structured-ou
178
178
  | Language vocabulary | `GENERATIVE_NODE_KINDS`, `JUDGMENT_NODE_KINDS`, `NODE_FIELDS`, `IGNORED_NODE_FIELDS`, `WORKFLOW_PREDICATES`, `MECHANICAL_PREDICATES`, `PREDICATE_FIELDS`, `FIELD_TYPES`, `EFFORT_LEVELS`, `THINKING_LEVELS`, `MODEL_TIERS`, `CALL_TRANSPORTS`, `CALL_RETRY_CLASSES`, `EFFECT_FAILURE_CODES`, `PROSE_ARTIFACT_TYPES`; `WorkflowNodeKind`, `WorkflowPredicateName`, `FieldType`. The validator and the author contract read these same constants. |
179
179
  | Test without a model | `synthesizeInstance`, `synthesizeAnswers`, `DryRunOptions`, `DryRunResult`. Synthetic answers exercise execution mechanics; they do not establish judgment quality. A dry run stops after `maxSteps` synthetic steps (10,000 by default) or at its `signal`, with `skipped` saying so. |
180
180
 
181
- A `code` node runs in the host process through the package's own executor, which shadows common globals and is not a sandbox. A host that runs code from an untrusted author supplies `deps.runCode`: the interpreter then hands it each code node with the state and the transform's context, merges what it returns under the same patch rules and state checks, and never executes a code body itself, not even as a validation probe. `dryRunWorkflow` takes the same `runCode` option and honors it the same way. `validateWorkflow` is synchronous and cannot call a host executor: a host that has one validates with `executeCode: false`, as `runWorkflow` and `dryRunWorkflow` do for it. `deniedGlobalReferences` names the globals a code body reaches for (a lint, never a boundary), so such a host can refuse the node before it runs. A failed effect carries a closed `code` from `EFFECT_FAILURE_CODES` on its `EffectFailure` and on every `effect.failed` event (null when the failure is not an `EffectFailure` with a listed code; any other typed error's own code rides as `error_code`), and `retry.on` names codes as well as retry classes.
181
+ A `code` node runs in the host process through the package's own executor, which shadows common globals and is not a sandbox. A host that runs code from an untrusted author supplies `deps.runCode`: the interpreter then hands it each code node with the state and the transform's context, merges what it returns under the same patch rules and state checks, and never executes a code body itself, not even as a validation probe. `dryRunWorkflow` takes the same `runCode` option and honors it the same way. `validateWorkflow` is synchronous and cannot call a host executor: a host that has one validates with `executeCode: false`, as `runWorkflow` and `dryRunWorkflow` do for it. `deniedGlobalReferences` names the globals a code body reaches for (a lint, never a boundary), so such a host can refuse the node before it runs. A failed effect carries a closed `code` from `EFFECT_FAILURE_CODES` on its `EffectFailure` and on every `effect.failed` event (null when the failure is not an `EffectFailure` with a listed code; any other typed error's own code rides as `error_code`), and `retry.on` names codes as well as retry classes. A host that parsed a provider's Retry-After passes it as `retryAfterMs` on the `EffectFailure`: the retry then waits the longer of that and the linear `backoff_s` × attempt, still capped by the poll window, and the attempt's `effect.failed` event carries it as `retry_after_ms`. The engine puts no other ceiling on it, so a host bounds a value it read from a third party.
182
182
 
183
183
  `runWorkflowSlice` runs selected root steps against supplied state and optional seed data. It returns the slice state without checking the full workflow's terminal output contract. Use `runWorkflow` for a complete run. `getPath` reads dot-separated record keys and canonical in-bounds array indexes, returning `undefined` when a segment cannot be resolved. `predicateMatches` evaluates mechanical predicates only; use `field_equals` with an explicit path for a stored label.
184
184
 
@@ -671,15 +671,20 @@ export type DecisionExchange = {
671
671
  export declare const declaredWrites: (node: WorkflowNode | undefined) => Set<string>;
672
672
  export declare const childSteps: (child: Workflow | undefined) => WorkflowNode[] | null;
673
673
  /** A failed effect: its retry class (null when the failure is not transient by nature), its closed code,
674
- * and what the host observed (`detail`, written onto the attempt's `effect.failed` event). */
674
+ * what the host observed (`detail`, written onto the attempt's `effect.failed` event), and how long the
675
+ * provider asked the caller to wait before trying again (`retryAfterMs`, a Retry-After the host parsed).
676
+ * A retry waits at least `retryAfterMs`; a value that is not a finite number >= 0 is dropped. The engine
677
+ * sets no ceiling on it beyond the poll budget, so a host that reads it from a third party bounds it first. */
675
678
  export declare class EffectFailure extends Error {
676
679
  readonly retryClass: CallRetryClass | null;
677
680
  readonly code: EffectFailureCode | null;
678
681
  readonly detail?: Record<string, unknown>;
682
+ readonly retryAfterMs?: number;
679
683
  constructor(message: string, retryClass?: CallRetryClass | null, options?: {
680
684
  code?: EffectFailureCode | null;
681
685
  detail?: Record<string, unknown>;
682
686
  cause?: unknown;
687
+ retryAfterMs?: number;
683
688
  });
684
689
  }
685
690
  export declare function normalizeStringNullsForSchema(value: unknown, schema: Record<string, unknown> | undefined, depth?: number, root?: Record<string, unknown> | undefined): unknown;
package/dist/workflow.js CHANGED
@@ -179,11 +179,15 @@ export const childSteps = (child) => {
179
179
  /** The code a retry class implies when the failure names none. */
180
180
  const codeOfRetryClass = (retryClass) => retryClass === null ? null : retryClass === "timeout" ? "effect_timeout" : retryClass === "exit" ? "effect_exit" : "effect_transport";
181
181
  /** A failed effect: its retry class (null when the failure is not transient by nature), its closed code,
182
- * and what the host observed (`detail`, written onto the attempt's `effect.failed` event). */
182
+ * what the host observed (`detail`, written onto the attempt's `effect.failed` event), and how long the
183
+ * provider asked the caller to wait before trying again (`retryAfterMs`, a Retry-After the host parsed).
184
+ * A retry waits at least `retryAfterMs`; a value that is not a finite number >= 0 is dropped. The engine
185
+ * sets no ceiling on it beyond the poll budget, so a host that reads it from a third party bounds it first. */
183
186
  export class EffectFailure extends Error {
184
187
  retryClass;
185
188
  code;
186
189
  detail;
190
+ retryAfterMs;
187
191
  constructor(message, retryClass = null, options = {}) {
188
192
  super(message, options.cause === undefined ? undefined : { cause: options.cause });
189
193
  this.retryClass = retryClass;
@@ -191,6 +195,8 @@ export class EffectFailure extends Error {
191
195
  this.code = options.code === undefined ? codeOfRetryClass(retryClass) : options.code;
192
196
  if (options.detail)
193
197
  this.detail = options.detail;
198
+ if (typeof options.retryAfterMs === "number" && Number.isFinite(options.retryAfterMs) && options.retryAfterMs >= 0)
199
+ this.retryAfterMs = options.retryAfterMs;
194
200
  }
195
201
  }
196
202
  function containsReportNode(node) {
@@ -2096,11 +2102,13 @@ async function runCallNode(node, state, workflow, deps) {
2096
2102
  const errorCode = code === null && typeof lastError?.code === "string" ? lastError.code : null;
2097
2103
  // Durable admission is uncertain after failure; only the host can reconcile it.
2098
2104
  const retryable = !deps.signal?.aborted && !deps.recovery && ((retryClass !== null && retryOn.has(retryClass)) || (code !== null && retryOn.has(code))) && attempt < attempts;
2099
- deps.onEvent?.({ type: "effect.failed", label: node.label, detail: { ...(lastError instanceof EffectFailure ? lastError.detail : undefined), via: node.via, attempt, code, ...(errorCode !== null ? { error_code: errorCode } : {}), retry_class: retryClass, retrying: retryable, ...(lastError instanceof EffectOutcomeUnknownError ? { outcome: "unknown", interruption: lastError.interruption, idempotency_key: idempotencyKey } : {}), message: String(lastError?.message || lastError).slice(0, 300) } });
2105
+ const retryAfterMs = lastError instanceof EffectFailure ? lastError.retryAfterMs : undefined;
2106
+ deps.onEvent?.({ type: "effect.failed", label: node.label, detail: { ...(lastError instanceof EffectFailure ? lastError.detail : undefined), via: node.via, attempt, code, ...(errorCode !== null ? { error_code: errorCode } : {}), retry_class: retryClass, retrying: retryable, ...(retryAfterMs !== undefined ? { retry_after_ms: retryAfterMs } : {}), ...(lastError instanceof EffectOutcomeUnknownError ? { outcome: "unknown", interruption: lastError.interruption, idempotency_key: idempotencyKey } : {}), message: String(lastError?.message || lastError).slice(0, 300) } });
2100
2107
  const until = budgetUntil?.();
2101
2108
  if (!retryable || (until !== undefined && Date.now() >= until))
2102
2109
  break;
2103
- const delay = Math.min((node.retry?.backoff_s ?? 1) * 1000 * attempt, until === undefined ? Infinity : Math.max(0, until - Date.now()));
2110
+ // The linear backoff, or the provider's Retry-After when it asks for longer; the poll budget caps either.
2111
+ const delay = Math.min(Math.max((node.retry?.backoff_s ?? 1) * 1000 * attempt, retryAfterMs ?? 0), until === undefined ? Infinity : Math.max(0, until - Date.now()));
2104
2112
  await sleep(delay, deps.signal);
2105
2113
  }
2106
2114
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-dsl",
3
- "version": "0.1.0-beta.111",
3
+ "version": "0.1.0-beta.112",
4
4
  "description": "Composable, typed workflows for agents",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",