@runtypelabs/sdk 9.3.0 → 9.3.2

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/dist/index.cjs CHANGED
@@ -375,10 +375,7 @@ function createFlowEventTranslator() {
375
375
  pageOrigin: data.pageOrigin
376
376
  })
377
377
  ];
378
- // Channels/markers/tool-family/approval/skip/source/state/custom/ping the
379
- // flow consumer never read → no callback event. (A non-terminal `error` is
380
- // only produced on agent streams; dropping it here avoids a false
381
- // flow_error.)
378
+ // WHY(docs/why/packages/client/src.md#default-case-drops-events-the-flow-consumer-neve): Default case drops events the flow consumer never reads; a non-terminal error is agent-only, dropped here.
382
379
  default:
383
380
  return [];
384
381
  }
@@ -550,9 +547,7 @@ function createAgentEventTranslator() {
550
547
  toolName: data.toolName,
551
548
  success: data.success,
552
549
  result: data.result,
553
- // A failure's reason travels on the frame's `error` field the
554
- // only carrier for complete-only failures like the MCP discovery
555
- // connection pseudo-tool, which no longer emits an `error` frame.
550
+ // WHY(docs/why/packages/client/src.md#a-failures-reason-travels-on-error-the-only-carr): A failure's reason travels on `error`, the only carrier for complete-only MCP discovery failures.
556
551
  error: str(data.error),
557
552
  executionTime: data.executionTime
558
553
  })
@@ -671,7 +666,8 @@ function createAgentEventTranslator() {
671
666
  seq,
672
667
  agentId,
673
668
  success: false,
674
- stopReason: "error",
669
+ // WHY(#7794): Forward the loop verdict like the execution_complete arm; `error` is the no-verdict answer.
670
+ stopReason: data.stopReason ?? "error",
675
671
  error: errorMessage(data.error),
676
672
  completedAt: data.completedAt
677
673
  })
@@ -689,10 +685,7 @@ function createAgentEventTranslator() {
689
685
  ];
690
686
  case "ping":
691
687
  return [compact({ type: "agent_ping", executionId, seq, timestamp: data.timestamp })];
692
- // turn/text/reasoning open+close markers, step_*, artifact_*, source,
693
- // state_snapshot/state_delta (agent-state channel with no stable SDK
694
- // callback), custom (fallback beat / routing), and the skill-fold result
695
- // envelope the SDK never consumed → no callback event.
688
+ // WHY(docs/why/packages/client/src.md#default-case-lists-every-channel-type-the-sdk-ca): Default case lists every channel type the SDK callback surface never consumed, so it maps to nothing.
696
689
  default:
697
690
  return [];
698
691
  }
@@ -1247,9 +1240,6 @@ var FlowBuilder = class {
1247
1240
  );
1248
1241
  return this;
1249
1242
  }
1250
- // ============================================================================
1251
- // Step Methods
1252
- // ============================================================================
1253
1243
  /**
1254
1244
  * Add a prompt step
1255
1245
  */
@@ -1748,9 +1738,6 @@ var FlowBuilder = class {
1748
1738
  memorySummary(config) {
1749
1739
  return this.addRawStep("memory-summary", config);
1750
1740
  }
1751
- // ============================================================================
1752
- // Subagent Helpers
1753
- // ============================================================================
1754
1741
  /**
1755
1742
  * Attach a subagent runtime tool to the most recent prompt step.
1756
1743
  *
@@ -1845,9 +1832,6 @@ var FlowBuilder = class {
1845
1832
  lastStep.config.tools = { ...existingTools, subagentConfig: opts };
1846
1833
  return this;
1847
1834
  }
1848
- // ============================================================================
1849
- // Build Method
1850
- // ============================================================================
1851
1835
  /**
1852
1836
  * Build the final dispatch request configuration
1853
1837
  */
@@ -1938,9 +1922,6 @@ var FlowBuilder = class {
1938
1922
  if (lastStep) lastStep.when = expression;
1939
1923
  return this;
1940
1924
  }
1941
- // ============================================================================
1942
- // Private Helpers
1943
- // ============================================================================
1944
1925
  addRawStep(type, config) {
1945
1926
  const { name, enabled, when, ...stepConfig } = config;
1946
1927
  this.addStep(type, name, stepConfig, enabled, when);
@@ -2144,7 +2125,6 @@ var CHECK_GRADER_KINDS = /* @__PURE__ */ new Set([
2144
2125
  "length",
2145
2126
  "latency",
2146
2127
  "no_error",
2147
- // Trace checks.
2148
2128
  "called_tool",
2149
2129
  "not_called_tool",
2150
2130
  "used_no_tools",
@@ -2428,7 +2408,8 @@ function normalizeCaseInput(input, where) {
2428
2408
  const mock = { toolName: m.toolName, output: m.output };
2429
2409
  if (m.input !== void 0) mock.input = m.input;
2430
2410
  if (typeof m.isError === "boolean") mock.isError = m.isError;
2431
- if (typeof m.sourceToolExecutionId === "string") mock.sourceToolExecutionId = m.sourceToolExecutionId;
2411
+ if (typeof m.sourceToolExecutionId === "string")
2412
+ mock.sourceToolExecutionId = m.sourceToolExecutionId;
2432
2413
  if (typeof m.truncated === "boolean") mock.truncated = m.truncated;
2433
2414
  return mock;
2434
2415
  });
@@ -2533,7 +2514,7 @@ async function computeEvalContentHash(definition) {
2533
2514
  name: c.name,
2534
2515
  input: normalizeForHash(c.input),
2535
2516
  ...c.expected !== void 0 ? { expected: normalizeForHash(c.expected) } : {},
2536
- // Grader order preserved on purpose (it maps to the result index).
2517
+ // INVARIANT: Grader order is preserved on purpose; it maps to the result index.
2537
2518
  expect: c.expect.map((g) => normalizeForHash(g))
2538
2519
  }))
2539
2520
  };
@@ -2739,8 +2720,7 @@ function defineFlow(input) {
2739
2720
  return {
2740
2721
  type: step.type,
2741
2722
  name: step.name,
2742
- // Explicit 1-based order (the flow builder's convention) so the local
2743
- // probe hash agrees with the server's persisted step order.
2723
+ // WHY(docs/why/packages/client/src.md#explicit-1-based-order-matches-the-flow-builders): Explicit 1-based order matches the flow builder's convention so the local hash agrees with the server
2744
2724
  order: typeof step.order === "number" ? step.order : index + 1,
2745
2725
  ...step.enabled !== void 0 ? { enabled: step.enabled } : {},
2746
2726
  ...typeof step.when === "string" ? { when: step.when } : {},
@@ -3042,9 +3022,6 @@ var RuntypeFlowBuilder = class {
3042
3022
  this.flowConfig = { name: "Untitled Flow" };
3043
3023
  }
3044
3024
  }
3045
- // ============================================================================
3046
- // Configuration Methods
3047
- // ============================================================================
3048
3025
  /**
3049
3026
  * Set the record configuration
3050
3027
  */
@@ -3088,9 +3065,6 @@ var RuntypeFlowBuilder = class {
3088
3065
  );
3089
3066
  return this;
3090
3067
  }
3091
- // ============================================================================
3092
- // Step Methods
3093
- // ============================================================================
3094
3068
  /**
3095
3069
  * Add a prompt step
3096
3070
  */
@@ -3874,9 +3848,6 @@ var RuntypeFlowBuilder = class {
3874
3848
  "Use Runtype.flows.virtual(...) or Runtype.flows.upsert(...) with inline steps to validate a flow before saving."
3875
3849
  );
3876
3850
  }
3877
- // ============================================================================
3878
- // Private Helpers
3879
- // ============================================================================
3880
3851
  /**
3881
3852
  * Persisted flow protocol (APQ-style): send hash-only first, retry with
3882
3853
  * full definition on FLOW_DEFINITION_REQUIRED. For non-upsert modes,
@@ -6239,9 +6210,6 @@ var RuntypeClient = class {
6239
6210
  }
6240
6211
  };
6241
6212
  var Runtype = class {
6242
- // ============================================================================
6243
- // Global Configuration
6244
- // ============================================================================
6245
6213
  /**
6246
6214
  * Configure the global Runtype client
6247
6215
  *
@@ -6279,9 +6247,6 @@ var Runtype = class {
6279
6247
  static createClient(config) {
6280
6248
  return new RuntypeClient({ ...globalConfig, ...config });
6281
6249
  }
6282
- // ============================================================================
6283
- // Static Namespaces
6284
- // ============================================================================
6285
6250
  /**
6286
6251
  * Flows namespace - Build and execute flows
6287
6252
  *
@@ -6523,7 +6488,7 @@ var Runtype = class {
6523
6488
 
6524
6489
  // src/version.ts
6525
6490
  var FALLBACK_VERSION = "0.0.0";
6526
- var SDK_VERSION = "9.3.0".length > 0 ? "9.3.0" : FALLBACK_VERSION;
6491
+ var SDK_VERSION = "9.3.2".length > 0 ? "9.3.2" : FALLBACK_VERSION;
6527
6492
  var RUNTYPE_CLIENT_KIND = "sdk";
6528
6493
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6529
6494
 
@@ -6617,8 +6582,7 @@ function withDetachedReconnect(response, reattach, options = {}) {
6617
6582
  if (cancelled) break;
6618
6583
  current = await reattach({
6619
6584
  executionId: observed.executionId,
6620
- // `'0'` replays the whole turn the fail-open answer for a leg
6621
- // that produced no cursor at all.
6585
+ // WHY(docs/why/packages/client/src.md#0-replays-the-whole-turn-the-fail-open-answer-fo): '0' replays the whole turn, the fail-open answer for a leg that produced no cursor.
6622
6586
  after: observed.lastId ?? "0",
6623
6587
  signal: abort.signal
6624
6588
  });
@@ -6939,11 +6903,7 @@ function attachRuntimeToolsToDispatchRequest(request6, runtimeTools, options = {
6939
6903
  ...request6,
6940
6904
  flow: {
6941
6905
  ...flow,
6942
- // `clonedSteps` is a structural clone of `request.flow.steps` (already
6943
- // `FlowStepDefinition[]`); only the prompt step's `config.tools` was
6944
- // merged, so every step's `type` discriminant is preserved. The clone is
6945
- // intentionally built as loose records to merge tool config opaquely, so
6946
- // re-narrow to the typed step shape at this boundary.
6906
+ // WHY(docs/why/packages/client/src.md#clonedsteps-preserves-each-steps-type-discrimina): clonedSteps preserves each step's type discriminant; re-narrow from loose records here
6947
6907
  steps: clonedSteps
6948
6908
  }
6949
6909
  };
@@ -8207,13 +8167,7 @@ function ensureDefaultWorkflowHooks() {
8207
8167
  }
8208
8168
  var defaultWorkflowConfig = {
8209
8169
  name: "default",
8210
- // Empty-session escalation. The counter only counts tool actions, so
8211
- // narration-only sessions ("I'll create the files now" with no tool calls)
8212
- // escalate here even though the phase recovery conditions keyed on
8213
- // hadTextOutput skip them: nudge after the first actionless session, signal
8214
- // model escalation after the second (a no-op unless the caller configured a
8215
- // fallback model), and stop as 'stalled' after the third — the same total
8216
- // session budget as before stallPolicy existed.
8170
+ // WHY(docs/why/packages/client/src/workflows.md#empty-session-escalation-preserves-legacy-behavi): empty-session escalation preserves legacy behavior: nudge, then escalate, then stall after three
8217
8171
  stallPolicy: { nudgeAfter: 1, escalateModelAfter: 2, stopAfter: 3 },
8218
8172
  classifyVariant: "builtin:classify-task-variant",
8219
8173
  bootstrap: "builtin:repo-bootstrap-discovery",
@@ -8241,16 +8195,14 @@ var defaultWorkflowConfig = {
8241
8195
  transitionSummary: "builtin:planning-transition-summary",
8242
8196
  recovery: "builtin:planning-recovery",
8243
8197
  forceEndTurn: "builtin:planning-force-end-turn"
8244
- // canAcceptCompletion intentionally absent: the hand-written planning
8245
- // phase never defined it, and the SDK accepts completion when the slot
8246
- // is undefined. Keep parity.
8198
+ // WHY(docs/why/packages/client/src/workflows.md#canacceptcompletion-is-intentionally-absent-for): canAcceptCompletion is intentionally absent for planning to keep parity with the hand-written phase
8247
8199
  },
8248
8200
  {
8249
8201
  name: "execution",
8250
8202
  description: "Execute the plan by editing target files",
8251
8203
  instructions: "builtin:execution-instructions",
8252
8204
  toolGuidance: "builtin:execution-tool-guidance",
8253
- // Execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8205
+ // WHY(needs-review): execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8254
8206
  completionCriteria: { type: "never" },
8255
8207
  intercept: "builtin:execution-guard",
8256
8208
  recovery: "builtin:execution-recovery",
@@ -8420,11 +8372,11 @@ var deployWorkflow = {
8420
8372
  name: "deploy",
8421
8373
  phases: [scaffoldPhase, deployPhase],
8422
8374
  classifyVariant: classifyVariant2,
8423
- // No bootstrap context needed we're not searching the repo
8375
+ // WHY(needs-review): no bootstrap context needed; this workflow doesn't search the repo
8424
8376
  async generateBootstrapContext() {
8425
8377
  return void 0;
8426
8378
  },
8427
- // No candidate block we're not editing repo files
8379
+ // WHY(needs-review): no candidate block; this workflow doesn't edit repo files
8428
8380
  buildCandidateBlock() {
8429
8381
  return "";
8430
8382
  }
@@ -9795,9 +9747,7 @@ var ClientTokensEndpoint = class {
9795
9747
  if (params?.limit !== void 0) {
9796
9748
  return {
9797
9749
  clientTokens: response.clientTokens,
9798
- // The API always includes pagination when limit is supplied; the
9799
- // fallback mirrors the server's own envelope math so the paged
9800
- // overload stays total against older API deployments.
9750
+ // WHY(docs/why/packages/client/src.md#the-fallback-mirrors-the-servers-own-envelope-ma): The fallback mirrors the server's own envelope math so paging stays correct against older API deployments.
9801
9751
  pagination: response.pagination ?? {
9802
9752
  limit: params.limit,
9803
9753
  offset: params.offset ?? 0,
@@ -10549,8 +10499,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10549
10499
  iterations: 1,
10550
10500
  stopReason: "end_turn",
10551
10501
  completedAt: (/* @__PURE__ */ new Date()).toISOString(),
10552
- // Carry the spend observed so far so the interrupted session's
10553
- // cost still lands in marathon totals and budget accounting
10502
+ // WHY(docs/why/packages/client/src.md#carries-accumulated-spend-so-an-interrupted-sess): Carries accumulated spend so an interrupted session's cost still lands in totals
10554
10503
  totalCost: lastKnownCost,
10555
10504
  ...lastKnownTokens ? { totalTokens: lastKnownTokens } : {},
10556
10505
  finalOutput: [
@@ -10604,7 +10553,6 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10604
10553
  return null;
10605
10554
  }
10606
10555
  }
10607
- // ─── Long-Task Agent Execution ───────────────────────────────────────
10608
10556
  createEmptyToolTrace() {
10609
10557
  return {
10610
10558
  entries: [],
@@ -13179,9 +13127,10 @@ var AgentVersionsEndpoint = class {
13179
13127
  /**
13180
13128
  * Publish a version (promote it to the agent's published version).
13181
13129
  */
13182
- async publish(agentId, versionId) {
13130
+ async publish(agentId, versionId, options = {}) {
13183
13131
  return this.client.post(`/agent-versions/${agentId}/publish`, {
13184
- versionId
13132
+ versionId,
13133
+ ...options
13185
13134
  });
13186
13135
  }
13187
13136
  };
@@ -13210,9 +13159,10 @@ var FlowVersionsEndpoint = class {
13210
13159
  /**
13211
13160
  * Publish a version (promote it to the flow's published version).
13212
13161
  */
13213
- async publish(flowId, versionId) {
13162
+ async publish(flowId, versionId, options = {}) {
13214
13163
  return this.client.post(`/flow-versions/${flowId}/publish`, {
13215
- versionId
13164
+ versionId,
13165
+ ...options
13216
13166
  });
13217
13167
  }
13218
13168
  };
@@ -13379,12 +13329,7 @@ var RuntypeClient2 = class {
13379
13329
  this.timeout = config.timeout === void 0 ? 3e4 : config.timeout;
13380
13330
  this.headers = {
13381
13331
  "Content-Type": "application/json",
13382
- // Advertise client identity + version so the API can attribute SDK traffic
13383
- // (see detectActorSource in apps/api/src/lib/audit-log.ts). Defaults come
13384
- // first so callers that wrap this client with their own attribution — the
13385
- // CLI sends `X-Runtype-Client: cli` + `runtype-cli/<v>` — override them.
13386
- // `User-Agent` is a forbidden header in browsers and is silently dropped
13387
- // there; `X-Runtype-Client` is the reliable cross-environment signal.
13332
+ // WHY(docs/why/packages/client/src.md#user-agent-is-a-forbidden-header-in-browsers-and): User-Agent is a forbidden header in browsers and is silently dropped; X-Runtype-Client is the reliable
13388
13333
  "X-Runtype-Client": RUNTYPE_CLIENT_KIND,
13389
13334
  "User-Agent": SDK_USER_AGENT,
13390
13335
  ...config.headers || {}
@@ -13445,8 +13390,7 @@ var RuntypeClient2 = class {
13445
13390
  {
13446
13391
  dispatch: (config) => this.dispatch.executeStream(config),
13447
13392
  runWithLocalTools: (config, tools, callbacks, opts) => this.runWithLocalTools(config, tools, callbacks, opts),
13448
- // Validation capability for ClientFlowBuilder.validate() reuses the
13449
- // client's JSON POST transport (zero new HTTP plumbing).
13393
+ // WHY(docs/why/packages/client/src.md#clientflowbuilder-validate-reuses-the-clients-js): ClientFlowBuilder.validate() reuses the client's JSON POST transport instead of new HTTP plumbing.
13450
13394
  post: (path, data) => this.post(path, data)
13451
13395
  },
13452
13396
  name
@@ -13700,8 +13644,7 @@ var RuntypeClient2 = class {
13700
13644
  const response = await this.makeRequest(url, {
13701
13645
  method: "POST",
13702
13646
  headers,
13703
- // TS 5.7 types Uint8Array over ArrayBufferLike, which no longer
13704
- // overlaps DOM BodyInit; the runtime value is a valid fetch body.
13647
+ // WORKAROUND(docs/why/packages/client/src.md#ts-5-7-types-uint8array-over-arraybufferlike-whi): TS 5.7 types Uint8Array over ArrayBufferLike, which no longer overlaps DOM BodyInit, though the
13705
13648
  body
13706
13649
  });
13707
13650
  return transformResponse(response);