@runtypelabs/sdk 9.3.0 → 9.3.1

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
  })
@@ -494,10 +489,7 @@ function createAgentEventTranslator() {
494
489
  ];
495
490
  case "ping":
496
491
  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.
492
+ // 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
493
  default:
502
494
  return [];
503
495
  }
@@ -1052,9 +1044,6 @@ var FlowBuilder = class {
1052
1044
  );
1053
1045
  return this;
1054
1046
  }
1055
- // ============================================================================
1056
- // Step Methods
1057
- // ============================================================================
1058
1047
  /**
1059
1048
  * Add a prompt step
1060
1049
  */
@@ -1553,9 +1542,6 @@ var FlowBuilder = class {
1553
1542
  memorySummary(config) {
1554
1543
  return this.addRawStep("memory-summary", config);
1555
1544
  }
1556
- // ============================================================================
1557
- // Subagent Helpers
1558
- // ============================================================================
1559
1545
  /**
1560
1546
  * Attach a subagent runtime tool to the most recent prompt step.
1561
1547
  *
@@ -1650,9 +1636,6 @@ var FlowBuilder = class {
1650
1636
  lastStep.config.tools = { ...existingTools, subagentConfig: opts };
1651
1637
  return this;
1652
1638
  }
1653
- // ============================================================================
1654
- // Build Method
1655
- // ============================================================================
1656
1639
  /**
1657
1640
  * Build the final dispatch request configuration
1658
1641
  */
@@ -1743,9 +1726,6 @@ var FlowBuilder = class {
1743
1726
  if (lastStep) lastStep.when = expression;
1744
1727
  return this;
1745
1728
  }
1746
- // ============================================================================
1747
- // Private Helpers
1748
- // ============================================================================
1749
1729
  addRawStep(type, config) {
1750
1730
  const { name, enabled, when, ...stepConfig } = config;
1751
1731
  this.addStep(type, name, stepConfig, enabled, when);
@@ -1949,7 +1929,6 @@ var CHECK_GRADER_KINDS = /* @__PURE__ */ new Set([
1949
1929
  "length",
1950
1930
  "latency",
1951
1931
  "no_error",
1952
- // Trace checks.
1953
1932
  "called_tool",
1954
1933
  "not_called_tool",
1955
1934
  "used_no_tools",
@@ -2233,7 +2212,8 @@ function normalizeCaseInput(input, where) {
2233
2212
  const mock = { toolName: m.toolName, output: m.output };
2234
2213
  if (m.input !== void 0) mock.input = m.input;
2235
2214
  if (typeof m.isError === "boolean") mock.isError = m.isError;
2236
- if (typeof m.sourceToolExecutionId === "string") mock.sourceToolExecutionId = m.sourceToolExecutionId;
2215
+ if (typeof m.sourceToolExecutionId === "string")
2216
+ mock.sourceToolExecutionId = m.sourceToolExecutionId;
2237
2217
  if (typeof m.truncated === "boolean") mock.truncated = m.truncated;
2238
2218
  return mock;
2239
2219
  });
@@ -2338,7 +2318,7 @@ async function computeEvalContentHash(definition) {
2338
2318
  name: c.name,
2339
2319
  input: normalizeForHash(c.input),
2340
2320
  ...c.expected !== void 0 ? { expected: normalizeForHash(c.expected) } : {},
2341
- // Grader order preserved on purpose (it maps to the result index).
2321
+ // INVARIANT: Grader order is preserved on purpose; it maps to the result index.
2342
2322
  expect: c.expect.map((g) => normalizeForHash(g))
2343
2323
  }))
2344
2324
  };
@@ -2544,8 +2524,7 @@ function defineFlow(input) {
2544
2524
  return {
2545
2525
  type: step.type,
2546
2526
  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.
2527
+ // 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
2528
  order: typeof step.order === "number" ? step.order : index + 1,
2550
2529
  ...step.enabled !== void 0 ? { enabled: step.enabled } : {},
2551
2530
  ...typeof step.when === "string" ? { when: step.when } : {},
@@ -2847,9 +2826,6 @@ var RuntypeFlowBuilder = class {
2847
2826
  this.flowConfig = { name: "Untitled Flow" };
2848
2827
  }
2849
2828
  }
2850
- // ============================================================================
2851
- // Configuration Methods
2852
- // ============================================================================
2853
2829
  /**
2854
2830
  * Set the record configuration
2855
2831
  */
@@ -2893,9 +2869,6 @@ var RuntypeFlowBuilder = class {
2893
2869
  );
2894
2870
  return this;
2895
2871
  }
2896
- // ============================================================================
2897
- // Step Methods
2898
- // ============================================================================
2899
2872
  /**
2900
2873
  * Add a prompt step
2901
2874
  */
@@ -3679,9 +3652,6 @@ var RuntypeFlowBuilder = class {
3679
3652
  "Use Runtype.flows.virtual(...) or Runtype.flows.upsert(...) with inline steps to validate a flow before saving."
3680
3653
  );
3681
3654
  }
3682
- // ============================================================================
3683
- // Private Helpers
3684
- // ============================================================================
3685
3655
  /**
3686
3656
  * Persisted flow protocol (APQ-style): send hash-only first, retry with
3687
3657
  * full definition on FLOW_DEFINITION_REQUIRED. For non-upsert modes,
@@ -6044,9 +6014,6 @@ var RuntypeClient = class {
6044
6014
  }
6045
6015
  };
6046
6016
  var Runtype = class {
6047
- // ============================================================================
6048
- // Global Configuration
6049
- // ============================================================================
6050
6017
  /**
6051
6018
  * Configure the global Runtype client
6052
6019
  *
@@ -6084,9 +6051,6 @@ var Runtype = class {
6084
6051
  static createClient(config) {
6085
6052
  return new RuntypeClient({ ...globalConfig, ...config });
6086
6053
  }
6087
- // ============================================================================
6088
- // Static Namespaces
6089
- // ============================================================================
6090
6054
  /**
6091
6055
  * Flows namespace - Build and execute flows
6092
6056
  *
@@ -6328,7 +6292,7 @@ var Runtype = class {
6328
6292
 
6329
6293
  // src/version.ts
6330
6294
  var FALLBACK_VERSION = "0.0.0";
6331
- var SDK_VERSION = "9.3.0".length > 0 ? "9.3.0" : FALLBACK_VERSION;
6295
+ var SDK_VERSION = "9.3.1".length > 0 ? "9.3.1" : FALLBACK_VERSION;
6332
6296
  var RUNTYPE_CLIENT_KIND = "sdk";
6333
6297
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
6334
6298
 
@@ -6422,8 +6386,7 @@ function withDetachedReconnect(response, reattach, options = {}) {
6422
6386
  if (cancelled) break;
6423
6387
  current = await reattach({
6424
6388
  executionId: observed.executionId,
6425
- // `'0'` replays the whole turn the fail-open answer for a leg
6426
- // that produced no cursor at all.
6389
+ // 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
6390
  after: observed.lastId ?? "0",
6428
6391
  signal: abort.signal
6429
6392
  });
@@ -6744,11 +6707,7 @@ function attachRuntimeToolsToDispatchRequest(request6, runtimeTools, options = {
6744
6707
  ...request6,
6745
6708
  flow: {
6746
6709
  ...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.
6710
+ // 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
6711
  steps: clonedSteps
6753
6712
  }
6754
6713
  };
@@ -8012,13 +7971,7 @@ function ensureDefaultWorkflowHooks() {
8012
7971
  }
8013
7972
  var defaultWorkflowConfig = {
8014
7973
  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.
7974
+ // 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
7975
  stallPolicy: { nudgeAfter: 1, escalateModelAfter: 2, stopAfter: 3 },
8023
7976
  classifyVariant: "builtin:classify-task-variant",
8024
7977
  bootstrap: "builtin:repo-bootstrap-discovery",
@@ -8046,16 +7999,14 @@ var defaultWorkflowConfig = {
8046
7999
  transitionSummary: "builtin:planning-transition-summary",
8047
8000
  recovery: "builtin:planning-recovery",
8048
8001
  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.
8002
+ // 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
8003
  },
8053
8004
  {
8054
8005
  name: "execution",
8055
8006
  description: "Execute the plan by editing target files",
8056
8007
  instructions: "builtin:execution-instructions",
8057
8008
  toolGuidance: "builtin:execution-tool-guidance",
8058
- // Execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8009
+ // WHY(needs-review): execution never auto-advances; completion is agent-driven via TASK_COMPLETE
8059
8010
  completionCriteria: { type: "never" },
8060
8011
  intercept: "builtin:execution-guard",
8061
8012
  recovery: "builtin:execution-recovery",
@@ -8225,11 +8176,11 @@ var deployWorkflow = {
8225
8176
  name: "deploy",
8226
8177
  phases: [scaffoldPhase, deployPhase],
8227
8178
  classifyVariant: classifyVariant2,
8228
- // No bootstrap context needed we're not searching the repo
8179
+ // WHY(needs-review): no bootstrap context needed; this workflow doesn't search the repo
8229
8180
  async generateBootstrapContext() {
8230
8181
  return void 0;
8231
8182
  },
8232
- // No candidate block we're not editing repo files
8183
+ // WHY(needs-review): no candidate block; this workflow doesn't edit repo files
8233
8184
  buildCandidateBlock() {
8234
8185
  return "";
8235
8186
  }
@@ -9600,9 +9551,7 @@ var ClientTokensEndpoint = class {
9600
9551
  if (params?.limit !== void 0) {
9601
9552
  return {
9602
9553
  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.
9554
+ // 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
9555
  pagination: response.pagination ?? {
9607
9556
  limit: params.limit,
9608
9557
  offset: params.offset ?? 0,
@@ -10354,8 +10303,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10354
10303
  iterations: 1,
10355
10304
  stopReason: "end_turn",
10356
10305
  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
10306
+ // 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
10307
  totalCost: lastKnownCost,
10360
10308
  ...lastKnownTokens ? { totalTokens: lastKnownTokens } : {},
10361
10309
  finalOutput: [
@@ -10409,7 +10357,6 @@ var _AgentsEndpoint = class _AgentsEndpoint {
10409
10357
  return null;
10410
10358
  }
10411
10359
  }
10412
- // ─── Long-Task Agent Execution ───────────────────────────────────────
10413
10360
  createEmptyToolTrace() {
10414
10361
  return {
10415
10362
  entries: [],
@@ -13184,12 +13131,7 @@ var RuntypeClient2 = class {
13184
13131
  this.timeout = config.timeout === void 0 ? 3e4 : config.timeout;
13185
13132
  this.headers = {
13186
13133
  "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.
13134
+ // 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
13135
  "X-Runtype-Client": RUNTYPE_CLIENT_KIND,
13194
13136
  "User-Agent": SDK_USER_AGENT,
13195
13137
  ...config.headers || {}
@@ -13250,8 +13192,7 @@ var RuntypeClient2 = class {
13250
13192
  {
13251
13193
  dispatch: (config) => this.dispatch.executeStream(config),
13252
13194
  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).
13195
+ // 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
13196
  post: (path, data) => this.post(path, data)
13256
13197
  },
13257
13198
  name
@@ -13505,8 +13446,7 @@ var RuntypeClient2 = class {
13505
13446
  const response = await this.makeRequest(url, {
13506
13447
  method: "POST",
13507
13448
  headers,
13508
- // TS 5.7 types Uint8Array over ArrayBufferLike, which no longer
13509
- // overlaps DOM BodyInit; the runtime value is a valid fetch body.
13449
+ // 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
13450
  body
13511
13451
  });
13512
13452
  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.1",
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",