@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.mjs CHANGED
@@ -180,10 +180,7 @@ function createFlowEventTranslator() {
180
180
  pageOrigin: data.pageOrigin
181
181
  })
182
182
  ];
183
- // Channels/markers/tool-family/approval/skip/source/state/custom/ping the
184
- // flow consumer never read → no callback event. (A non-terminal `error` is
185
- // only produced on agent streams; dropping it here avoids a false
186
- // flow_error.)
183
+ // 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.
187
184
  default:
188
185
  return [];
189
186
  }
@@ -355,9 +352,7 @@ function createAgentEventTranslator() {
355
352
  toolName: data.toolName,
356
353
  success: data.success,
357
354
  result: data.result,
358
- // A failure's reason travels on the frame's `error` field the
359
- // only carrier for complete-only failures like the MCP discovery
360
- // connection pseudo-tool, which no longer emits an `error` frame.
355
+ // 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.
361
356
  error: str(data.error),
362
357
  executionTime: data.executionTime
363
358
  })
@@ -476,7 +471,8 @@ function createAgentEventTranslator() {
476
471
  seq,
477
472
  agentId,
478
473
  success: false,
479
- stopReason: "error",
474
+ // WHY(#7794): Forward the loop verdict like the execution_complete arm; `error` is the no-verdict answer.
475
+ stopReason: data.stopReason ?? "error",
480
476
  error: errorMessage(data.error),
481
477
  completedAt: data.completedAt
482
478
  })
@@ -494,10 +490,7 @@ function createAgentEventTranslator() {
494
490
  ];
495
491
  case "ping":
496
492
  return [compact({ type: "agent_ping", executionId, seq, timestamp: data.timestamp })];
497
- // turn/text/reasoning open+close markers, step_*, artifact_*, source,
498
- // state_snapshot/state_delta (agent-state channel with no stable SDK
499
- // callback), custom (fallback beat / routing), and the skill-fold result
500
- // envelope the SDK never consumed → no callback event.
493
+ // 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.
501
494
  default:
502
495
  return [];
503
496
  }
@@ -1052,9 +1045,6 @@ var FlowBuilder = class {
1052
1045
  );
1053
1046
  return this;
1054
1047
  }
1055
- // ============================================================================
1056
- // Step Methods
1057
- // ============================================================================
1058
1048
  /**
1059
1049
  * Add a prompt step
1060
1050
  */
@@ -1553,9 +1543,6 @@ var FlowBuilder = class {
1553
1543
  memorySummary(config) {
1554
1544
  return this.addRawStep("memory-summary", config);
1555
1545
  }
1556
- // ============================================================================
1557
- // Subagent Helpers
1558
- // ============================================================================
1559
1546
  /**
1560
1547
  * Attach a subagent runtime tool to the most recent prompt step.
1561
1548
  *
@@ -1650,9 +1637,6 @@ var FlowBuilder = class {
1650
1637
  lastStep.config.tools = { ...existingTools, subagentConfig: opts };
1651
1638
  return this;
1652
1639
  }
1653
- // ============================================================================
1654
- // Build Method
1655
- // ============================================================================
1656
1640
  /**
1657
1641
  * Build the final dispatch request configuration
1658
1642
  */
@@ -1743,9 +1727,6 @@ var FlowBuilder = class {
1743
1727
  if (lastStep) lastStep.when = expression;
1744
1728
  return this;
1745
1729
  }
1746
- // ============================================================================
1747
- // Private Helpers
1748
- // ============================================================================
1749
1730
  addRawStep(type, config) {
1750
1731
  const { name, enabled, when, ...stepConfig } = config;
1751
1732
  this.addStep(type, name, stepConfig, enabled, when);
@@ -1949,7 +1930,6 @@ var CHECK_GRADER_KINDS = /* @__PURE__ */ new Set([
1949
1930
  "length",
1950
1931
  "latency",
1951
1932
  "no_error",
1952
- // Trace checks.
1953
1933
  "called_tool",
1954
1934
  "not_called_tool",
1955
1935
  "used_no_tools",
@@ -2233,7 +2213,8 @@ function normalizeCaseInput(input, where) {
2233
2213
  const mock = { toolName: m.toolName, output: m.output };
2234
2214
  if (m.input !== void 0) mock.input = m.input;
2235
2215
  if (typeof m.isError === "boolean") mock.isError = m.isError;
2236
- if (typeof m.sourceToolExecutionId === "string") mock.sourceToolExecutionId = m.sourceToolExecutionId;
2216
+ if (typeof m.sourceToolExecutionId === "string")
2217
+ mock.sourceToolExecutionId = m.sourceToolExecutionId;
2237
2218
  if (typeof m.truncated === "boolean") mock.truncated = m.truncated;
2238
2219
  return mock;
2239
2220
  });
@@ -2338,7 +2319,7 @@ async function computeEvalContentHash(definition) {
2338
2319
  name: c.name,
2339
2320
  input: normalizeForHash(c.input),
2340
2321
  ...c.expected !== void 0 ? { expected: normalizeForHash(c.expected) } : {},
2341
- // Grader order preserved on purpose (it maps to the result index).
2322
+ // INVARIANT: Grader order is preserved on purpose; it maps to the result index.
2342
2323
  expect: c.expect.map((g) => normalizeForHash(g))
2343
2324
  }))
2344
2325
  };
@@ -2544,8 +2525,7 @@ function defineFlow(input) {
2544
2525
  return {
2545
2526
  type: step.type,
2546
2527
  name: step.name,
2547
- // Explicit 1-based order (the flow builder's convention) so the local
2548
- // probe hash agrees with the server's persisted step order.
2528
+ // 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
2549
2529
  order: typeof step.order === "number" ? step.order : index + 1,
2550
2530
  ...step.enabled !== void 0 ? { enabled: step.enabled } : {},
2551
2531
  ...typeof step.when === "string" ? { when: step.when } : {},
@@ -2847,9 +2827,6 @@ var RuntypeFlowBuilder = class {
2847
2827
  this.flowConfig = { name: "Untitled Flow" };
2848
2828
  }
2849
2829
  }
2850
- // ============================================================================
2851
- // Configuration Methods
2852
- // ============================================================================
2853
2830
  /**
2854
2831
  * Set the record configuration
2855
2832
  */
@@ -2893,9 +2870,6 @@ var RuntypeFlowBuilder = class {
2893
2870
  );
2894
2871
  return this;
2895
2872
  }
2896
- // ============================================================================
2897
- // Step Methods
2898
- // ============================================================================
2899
2873
  /**
2900
2874
  * Add a prompt step
2901
2875
  */
@@ -3679,9 +3653,6 @@ var RuntypeFlowBuilder = class {
3679
3653
  "Use Runtype.flows.virtual(...) or Runtype.flows.upsert(...) with inline steps to validate a flow before saving."
3680
3654
  );
3681
3655
  }
3682
- // ============================================================================
3683
- // Private Helpers
3684
- // ============================================================================
3685
3656
  /**
3686
3657
  * Persisted flow protocol (APQ-style): send hash-only first, retry with
3687
3658
  * full definition on FLOW_DEFINITION_REQUIRED. For non-upsert modes,
@@ -6044,9 +6015,6 @@ var RuntypeClient = class {
6044
6015
  }
6045
6016
  };
6046
6017
  var Runtype = class {
6047
- // ============================================================================
6048
- // Global Configuration
6049
- // ============================================================================
6050
6018
  /**
6051
6019
  * Configure the global Runtype client
6052
6020
  *
@@ -6084,9 +6052,6 @@ var Runtype = class {
6084
6052
  static createClient(config) {
6085
6053
  return new RuntypeClient({ ...globalConfig, ...config });
6086
6054
  }
6087
- // ============================================================================
6088
- // Static Namespaces
6089
- // ============================================================================
6090
6055
  /**
6091
6056
  * Flows namespace - Build and execute flows
6092
6057
  *
@@ -6328,7 +6293,7 @@ var Runtype = class {
6328
6293
 
6329
6294
  // src/version.ts
6330
6295
  var FALLBACK_VERSION = "0.0.0";
6331
- var SDK_VERSION = "9.3.0".length > 0 ? "9.3.0" : FALLBACK_VERSION;
6296
+ var SDK_VERSION = "9.3.2".length > 0 ? "9.3.2" : FALLBACK_VERSION;
6332
6297
  var RUNTYPE_CLIENT_KIND = "sdk";
6333
6298
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6334
6299
 
@@ -6422,8 +6387,7 @@ function withDetachedReconnect(response, reattach, options = {}) {
6422
6387
  if (cancelled) break;
6423
6388
  current = await reattach({
6424
6389
  executionId: observed.executionId,
6425
- // `'0'` replays the whole turn the fail-open answer for a leg
6426
- // that produced no cursor at all.
6390
+ // 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.
6427
6391
  after: observed.lastId ?? "0",
6428
6392
  signal: abort.signal
6429
6393
  });
@@ -6744,11 +6708,7 @@ function attachRuntimeToolsToDispatchRequest(request6, runtimeTools, options = {
6744
6708
  ...request6,
6745
6709
  flow: {
6746
6710
  ...flow,
6747
- // `clonedSteps` is a structural clone of `request.flow.steps` (already
6748
- // `FlowStepDefinition[]`); only the prompt step's `config.tools` was
6749
- // merged, so every step's `type` discriminant is preserved. The clone is
6750
- // intentionally built as loose records to merge tool config opaquely, so
6751
- // re-narrow to the typed step shape at this boundary.
6711
+ // 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
6752
6712
  steps: clonedSteps
6753
6713
  }
6754
6714
  };
@@ -8012,13 +7972,7 @@ function ensureDefaultWorkflowHooks() {
8012
7972
  }
8013
7973
  var defaultWorkflowConfig = {
8014
7974
  name: "default",
8015
- // Empty-session escalation. The counter only counts tool actions, so
8016
- // narration-only sessions ("I'll create the files now" with no tool calls)
8017
- // escalate here even though the phase recovery conditions keyed on
8018
- // hadTextOutput skip them: nudge after the first actionless session, signal
8019
- // model escalation after the second (a no-op unless the caller configured a
8020
- // fallback model), and stop as 'stalled' after the third — the same total
8021
- // session budget as before stallPolicy existed.
7975
+ // 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
8022
7976
  stallPolicy: { nudgeAfter: 1, escalateModelAfter: 2, stopAfter: 3 },
8023
7977
  classifyVariant: "builtin:classify-task-variant",
8024
7978
  bootstrap: "builtin:repo-bootstrap-discovery",
@@ -8046,16 +8000,14 @@ var defaultWorkflowConfig = {
8046
8000
  transitionSummary: "builtin:planning-transition-summary",
8047
8001
  recovery: "builtin:planning-recovery",
8048
8002
  forceEndTurn: "builtin:planning-force-end-turn"
8049
- // canAcceptCompletion intentionally absent: the hand-written planning
8050
- // phase never defined it, and the SDK accepts completion when the slot
8051
- // is undefined. Keep parity.
8003
+ // 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
8052
8004
  },
8053
8005
  {
8054
8006
  name: "execution",
8055
8007
  description: "Execute the plan by editing target files",
8056
8008
  instructions: "builtin:execution-instructions",
8057
8009
  toolGuidance: "builtin:execution-tool-guidance",
8058
- // Execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8010
+ // WHY(needs-review): execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8059
8011
  completionCriteria: { type: "never" },
8060
8012
  intercept: "builtin:execution-guard",
8061
8013
  recovery: "builtin:execution-recovery",
@@ -8225,11 +8177,11 @@ var deployWorkflow = {
8225
8177
  name: "deploy",
8226
8178
  phases: [scaffoldPhase, deployPhase],
8227
8179
  classifyVariant: classifyVariant2,
8228
- // No bootstrap context needed we're not searching the repo
8180
+ // WHY(needs-review): no bootstrap context needed; this workflow doesn't search the repo
8229
8181
  async generateBootstrapContext() {
8230
8182
  return void 0;
8231
8183
  },
8232
- // No candidate block we're not editing repo files
8184
+ // WHY(needs-review): no candidate block; this workflow doesn't edit repo files
8233
8185
  buildCandidateBlock() {
8234
8186
  return "";
8235
8187
  }
@@ -9600,9 +9552,7 @@ var ClientTokensEndpoint = class {
9600
9552
  if (params?.limit !== void 0) {
9601
9553
  return {
9602
9554
  clientTokens: response.clientTokens,
9603
- // The API always includes pagination when limit is supplied; the
9604
- // fallback mirrors the server's own envelope math so the paged
9605
- // overload stays total against older API deployments.
9555
+ // 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.
9606
9556
  pagination: response.pagination ?? {
9607
9557
  limit: params.limit,
9608
9558
  offset: params.offset ?? 0,
@@ -10354,8 +10304,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10354
10304
  iterations: 1,
10355
10305
  stopReason: "end_turn",
10356
10306
  completedAt: (/* @__PURE__ */ new Date()).toISOString(),
10357
- // Carry the spend observed so far so the interrupted session's
10358
- // cost still lands in marathon totals and budget accounting
10307
+ // 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
10359
10308
  totalCost: lastKnownCost,
10360
10309
  ...lastKnownTokens ? { totalTokens: lastKnownTokens } : {},
10361
10310
  finalOutput: [
@@ -10409,7 +10358,6 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10409
10358
  return null;
10410
10359
  }
10411
10360
  }
10412
- // ─── Long-Task Agent Execution ───────────────────────────────────────
10413
10361
  createEmptyToolTrace() {
10414
10362
  return {
10415
10363
  entries: [],
@@ -12984,9 +12932,10 @@ var AgentVersionsEndpoint = class {
12984
12932
  /**
12985
12933
  * Publish a version (promote it to the agent's published version).
12986
12934
  */
12987
- async publish(agentId, versionId) {
12935
+ async publish(agentId, versionId, options = {}) {
12988
12936
  return this.client.post(`/agent-versions/${agentId}/publish`, {
12989
- versionId
12937
+ versionId,
12938
+ ...options
12990
12939
  });
12991
12940
  }
12992
12941
  };
@@ -13015,9 +12964,10 @@ var FlowVersionsEndpoint = class {
13015
12964
  /**
13016
12965
  * Publish a version (promote it to the flow's published version).
13017
12966
  */
13018
- async publish(flowId, versionId) {
12967
+ async publish(flowId, versionId, options = {}) {
13019
12968
  return this.client.post(`/flow-versions/${flowId}/publish`, {
13020
- versionId
12969
+ versionId,
12970
+ ...options
13021
12971
  });
13022
12972
  }
13023
12973
  };
@@ -13184,12 +13134,7 @@ var RuntypeClient2 = class {
13184
13134
  this.timeout = config.timeout === void 0 ? 3e4 : config.timeout;
13185
13135
  this.headers = {
13186
13136
  "Content-Type": "application/json",
13187
- // Advertise client identity + version so the API can attribute SDK traffic
13188
- // (see detectActorSource in apps/api/src/lib/audit-log.ts). Defaults come
13189
- // first so callers that wrap this client with their own attribution — the
13190
- // CLI sends `X-Runtype-Client: cli` + `runtype-cli/<v>` — override them.
13191
- // `User-Agent` is a forbidden header in browsers and is silently dropped
13192
- // there; `X-Runtype-Client` is the reliable cross-environment signal.
13137
+ // 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
13193
13138
  "X-Runtype-Client": RUNTYPE_CLIENT_KIND,
13194
13139
  "User-Agent": SDK_USER_AGENT,
13195
13140
  ...config.headers || {}
@@ -13250,8 +13195,7 @@ var RuntypeClient2 = class {
13250
13195
  {
13251
13196
  dispatch: (config) => this.dispatch.executeStream(config),
13252
13197
  runWithLocalTools: (config, tools, callbacks, opts) => this.runWithLocalTools(config, tools, callbacks, opts),
13253
- // Validation capability for ClientFlowBuilder.validate() reuses the
13254
- // client's JSON POST transport (zero new HTTP plumbing).
13198
+ // 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.
13255
13199
  post: (path, data) => this.post(path, data)
13256
13200
  },
13257
13201
  name
@@ -13505,8 +13449,7 @@ var RuntypeClient2 = class {
13505
13449
  const response = await this.makeRequest(url, {
13506
13450
  method: "POST",
13507
13451
  headers,
13508
- // TS 5.7 types Uint8Array over ArrayBufferLike, which no longer
13509
- // overlaps DOM BodyInit; the runtime value is a valid fetch body.
13452
+ // 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
13510
13453
  body
13511
13454
  });
13512
13455
  return transformResponse(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "9.3.0",
3
+ "version": "9.3.2",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Runtype API with fluent methods. Use it to quickly realize AI products, agents, and workflows.",
6
6
  "main": "dist/index.cjs",