@runtypelabs/sdk 1.15.3 → 1.17.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/dist/index.cjs CHANGED
@@ -991,18 +991,19 @@ var RuntypeFlowBuilder = class {
991
991
  const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
992
992
  try {
993
993
  for await (const event of streamEvents2(response)) {
994
- if (event.type === "flow_await") {
994
+ const awaitEvent = event;
995
+ if (awaitEvent.type === "flow_await") {
995
996
  pausedState = {
996
- toolName: event.toolName,
997
- parameters: event.parameters,
998
- executionId: event.executionId
997
+ toolName: awaitEvent.toolName || "",
998
+ parameters: awaitEvent.parameters,
999
+ executionId: awaitEvent.executionId || ""
999
1000
  };
1000
1001
  }
1001
- if (event.type === "step_await") {
1002
+ if (awaitEvent.type === "step_await") {
1002
1003
  pausedState = {
1003
- toolName: event.toolName,
1004
- parameters: event.parameters,
1005
- executionId: event.executionId
1004
+ toolName: awaitEvent.toolName || "",
1005
+ parameters: awaitEvent.parameters,
1006
+ executionId: awaitEvent.executionId || ""
1006
1007
  };
1007
1008
  }
1008
1009
  switch (event.type) {
@@ -1013,7 +1014,7 @@ var RuntypeFlowBuilder = class {
1013
1014
  wrappedCallbacks.onStepStart?.(event);
1014
1015
  break;
1015
1016
  case "step_delta": {
1016
- const chunkText = event.chunk || event.text || "";
1017
+ const chunkText = awaitEvent.chunk || awaitEvent.text || "";
1017
1018
  wrappedCallbacks.onStepChunk?.(chunkText, event);
1018
1019
  break;
1019
1020
  }
@@ -1071,8 +1072,9 @@ var RuntypeFlowBuilder = class {
1071
1072
  new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } })
1072
1073
  );
1073
1074
  }
1074
- if (result.status === "paused" && result.pausedReason?.type === "local_action") {
1075
- const { toolName, parameters, executionId } = result.pausedReason;
1075
+ const pausedResult = result;
1076
+ if (pausedResult.status === "paused" && pausedResult.pausedReason?.type === "local_action") {
1077
+ const { toolName, parameters, executionId } = pausedResult.pausedReason;
1076
1078
  if (!localTools[toolName]) {
1077
1079
  throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
1078
1080
  }
@@ -1527,6 +1529,21 @@ var PromptRunner = class {
1527
1529
  if (this.options.temperature !== void 0) {
1528
1530
  payload.temperature = this.options.temperature;
1529
1531
  }
1532
+ if (this.options.topP !== void 0) {
1533
+ payload.topP = this.options.topP;
1534
+ }
1535
+ if (this.options.topK !== void 0) {
1536
+ payload.topK = this.options.topK;
1537
+ }
1538
+ if (this.options.frequencyPenalty !== void 0) {
1539
+ payload.frequencyPenalty = this.options.frequencyPenalty;
1540
+ }
1541
+ if (this.options.presencePenalty !== void 0) {
1542
+ payload.presencePenalty = this.options.presencePenalty;
1543
+ }
1544
+ if (this.options.seed !== void 0) {
1545
+ payload.seed = this.options.seed;
1546
+ }
1530
1547
  if (this.options.maxTokens !== void 0) {
1531
1548
  payload.maxTokens = this.options.maxTokens;
1532
1549
  }
@@ -7103,6 +7120,11 @@ var FlowBuilder = class {
7103
7120
  outputVariable: config.outputVariable,
7104
7121
  responseFormat: config.responseFormat,
7105
7122
  temperature: config.temperature,
7123
+ topP: config.topP,
7124
+ topK: config.topK,
7125
+ frequencyPenalty: config.frequencyPenalty,
7126
+ presencePenalty: config.presencePenalty,
7127
+ seed: config.seed,
7106
7128
  maxTokens: config.maxTokens,
7107
7129
  reasoning: config.reasoning,
7108
7130
  streamOutput: config.streamOutput,
@@ -7431,6 +7453,103 @@ var FlowBuilder = class {
7431
7453
  return this;
7432
7454
  }
7433
7455
  // ============================================================================
7456
+ // Subagent Helpers
7457
+ // ============================================================================
7458
+ /**
7459
+ * Attach a subagent runtime tool to the most recent prompt step.
7460
+ *
7461
+ * A subagent tool spawns a focused child agent in its own context window
7462
+ * when the parent's model calls it. The child runs with a whitelisted tool
7463
+ * subset drawn from `allowedTools` (every entry must be available on the
7464
+ * parent step). The parent only sees the child's final result.
7465
+ *
7466
+ * Pass either `agentId` (for a saved agent in the same org) or `agent`
7467
+ * (an inline exported-agent JSON shape) — exactly one is required.
7468
+ *
7469
+ * @example
7470
+ * ```typescript
7471
+ * new FlowBuilder()
7472
+ * .createFlow({ name: 'Research' })
7473
+ * .prompt({ name: 'Plan', model: 'claude-sonnet-4-5', userPrompt: '...' })
7474
+ * .withSubagentTool('research_topic', {
7475
+ * agentId: 'agent_01h...',
7476
+ * allowedTools: ['builtin:exa_search'],
7477
+ * outputFormat: 'text',
7478
+ * })
7479
+ * ```
7480
+ */
7481
+ withSubagentTool(name, opts) {
7482
+ const lastStep = this.steps[this.steps.length - 1];
7483
+ if (!lastStep || lastStep.type !== "prompt") {
7484
+ throw new Error(
7485
+ "withSubagentTool() must be called after a .prompt() step \u2014 it attaches a runtime tool to the last prompt step."
7486
+ );
7487
+ }
7488
+ const config = {
7489
+ agentId: opts.agentId,
7490
+ agent: opts.agent,
7491
+ allowedTools: opts.allowedTools,
7492
+ maxTurns: opts.maxTurns,
7493
+ maxCost: opts.maxCost,
7494
+ timeoutMs: opts.timeoutMs,
7495
+ outputFormat: opts.outputFormat,
7496
+ inheritMessages: opts.inheritMessages,
7497
+ taskTemplate: opts.taskTemplate
7498
+ };
7499
+ const tool = {
7500
+ name,
7501
+ description: opts.description ?? `Spawn the ${name} subagent for a focused sub-task. Returns only the subagent's final result.`,
7502
+ toolType: "subagent",
7503
+ parametersSchema: opts.parametersSchema ?? {
7504
+ type: "object",
7505
+ properties: {
7506
+ task: {
7507
+ type: "string",
7508
+ description: "Self-contained task for the subagent. The subagent cannot see this conversation."
7509
+ }
7510
+ },
7511
+ required: ["task"]
7512
+ },
7513
+ config
7514
+ };
7515
+ const existingTools = lastStep.config.tools ?? {};
7516
+ const runtimeTools = [...existingTools.runtimeTools ?? [], tool];
7517
+ lastStep.config.tools = { ...existingTools, runtimeTools };
7518
+ return this;
7519
+ }
7520
+ /**
7521
+ * Enable agent-driven dynamic subagent spawning on the most recent prompt
7522
+ * step (surface C of the subagent design).
7523
+ *
7524
+ * When set, the API synthesizes a `spawn_subagent` tool the parent's model
7525
+ * can call at runtime to spin off a focused child agent. The child's tools
7526
+ * are drawn from `toolPool`, which must be a subset of the parent step's
7527
+ * resolved tools. The API validates pool entries and rejects escalation.
7528
+ *
7529
+ * @example
7530
+ * ```typescript
7531
+ * new FlowBuilder()
7532
+ * .createFlow({ name: 'Explore' })
7533
+ * .prompt({ name: 'Research', model: 'claude-sonnet-4-5', userPrompt: '...' })
7534
+ * .withSubagents({
7535
+ * toolPool: ['builtin:exa_search', 'mcp:*'],
7536
+ * maxSpawnsPerRun: 3,
7537
+ * allowNesting: false,
7538
+ * })
7539
+ * ```
7540
+ */
7541
+ withSubagents(opts) {
7542
+ const lastStep = this.steps[this.steps.length - 1];
7543
+ if (!lastStep || lastStep.type !== "prompt") {
7544
+ throw new Error(
7545
+ "withSubagents() must be called after a .prompt() step \u2014 it configures subagent spawning on the last prompt step."
7546
+ );
7547
+ }
7548
+ const existingTools = lastStep.config.tools ?? {};
7549
+ lastStep.config.tools = { ...existingTools, subagentConfig: opts };
7550
+ return this;
7551
+ }
7552
+ // ============================================================================
7434
7553
  // Build Method
7435
7554
  // ============================================================================
7436
7555
  /**