@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.mjs CHANGED
@@ -921,18 +921,19 @@ var RuntypeFlowBuilder = class {
921
921
  const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
922
922
  try {
923
923
  for await (const event of streamEvents2(response)) {
924
- if (event.type === "flow_await") {
924
+ const awaitEvent = event;
925
+ if (awaitEvent.type === "flow_await") {
925
926
  pausedState = {
926
- toolName: event.toolName,
927
- parameters: event.parameters,
928
- executionId: event.executionId
927
+ toolName: awaitEvent.toolName || "",
928
+ parameters: awaitEvent.parameters,
929
+ executionId: awaitEvent.executionId || ""
929
930
  };
930
931
  }
931
- if (event.type === "step_await") {
932
+ if (awaitEvent.type === "step_await") {
932
933
  pausedState = {
933
- toolName: event.toolName,
934
- parameters: event.parameters,
935
- executionId: event.executionId
934
+ toolName: awaitEvent.toolName || "",
935
+ parameters: awaitEvent.parameters,
936
+ executionId: awaitEvent.executionId || ""
936
937
  };
937
938
  }
938
939
  switch (event.type) {
@@ -943,7 +944,7 @@ var RuntypeFlowBuilder = class {
943
944
  wrappedCallbacks.onStepStart?.(event);
944
945
  break;
945
946
  case "step_delta": {
946
- const chunkText = event.chunk || event.text || "";
947
+ const chunkText = awaitEvent.chunk || awaitEvent.text || "";
947
948
  wrappedCallbacks.onStepChunk?.(chunkText, event);
948
949
  break;
949
950
  }
@@ -1001,8 +1002,9 @@ var RuntypeFlowBuilder = class {
1001
1002
  new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } })
1002
1003
  );
1003
1004
  }
1004
- if (result.status === "paused" && result.pausedReason?.type === "local_action") {
1005
- const { toolName, parameters, executionId } = result.pausedReason;
1005
+ const pausedResult = result;
1006
+ if (pausedResult.status === "paused" && pausedResult.pausedReason?.type === "local_action") {
1007
+ const { toolName, parameters, executionId } = pausedResult.pausedReason;
1006
1008
  if (!localTools[toolName]) {
1007
1009
  throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
1008
1010
  }
@@ -1457,6 +1459,21 @@ var PromptRunner = class {
1457
1459
  if (this.options.temperature !== void 0) {
1458
1460
  payload.temperature = this.options.temperature;
1459
1461
  }
1462
+ if (this.options.topP !== void 0) {
1463
+ payload.topP = this.options.topP;
1464
+ }
1465
+ if (this.options.topK !== void 0) {
1466
+ payload.topK = this.options.topK;
1467
+ }
1468
+ if (this.options.frequencyPenalty !== void 0) {
1469
+ payload.frequencyPenalty = this.options.frequencyPenalty;
1470
+ }
1471
+ if (this.options.presencePenalty !== void 0) {
1472
+ payload.presencePenalty = this.options.presencePenalty;
1473
+ }
1474
+ if (this.options.seed !== void 0) {
1475
+ payload.seed = this.options.seed;
1476
+ }
1460
1477
  if (this.options.maxTokens !== void 0) {
1461
1478
  payload.maxTokens = this.options.maxTokens;
1462
1479
  }
@@ -7033,6 +7050,11 @@ var FlowBuilder = class {
7033
7050
  outputVariable: config.outputVariable,
7034
7051
  responseFormat: config.responseFormat,
7035
7052
  temperature: config.temperature,
7053
+ topP: config.topP,
7054
+ topK: config.topK,
7055
+ frequencyPenalty: config.frequencyPenalty,
7056
+ presencePenalty: config.presencePenalty,
7057
+ seed: config.seed,
7036
7058
  maxTokens: config.maxTokens,
7037
7059
  reasoning: config.reasoning,
7038
7060
  streamOutput: config.streamOutput,
@@ -7361,6 +7383,103 @@ var FlowBuilder = class {
7361
7383
  return this;
7362
7384
  }
7363
7385
  // ============================================================================
7386
+ // Subagent Helpers
7387
+ // ============================================================================
7388
+ /**
7389
+ * Attach a subagent runtime tool to the most recent prompt step.
7390
+ *
7391
+ * A subagent tool spawns a focused child agent in its own context window
7392
+ * when the parent's model calls it. The child runs with a whitelisted tool
7393
+ * subset drawn from `allowedTools` (every entry must be available on the
7394
+ * parent step). The parent only sees the child's final result.
7395
+ *
7396
+ * Pass either `agentId` (for a saved agent in the same org) or `agent`
7397
+ * (an inline exported-agent JSON shape) — exactly one is required.
7398
+ *
7399
+ * @example
7400
+ * ```typescript
7401
+ * new FlowBuilder()
7402
+ * .createFlow({ name: 'Research' })
7403
+ * .prompt({ name: 'Plan', model: 'claude-sonnet-4-5', userPrompt: '...' })
7404
+ * .withSubagentTool('research_topic', {
7405
+ * agentId: 'agent_01h...',
7406
+ * allowedTools: ['builtin:exa_search'],
7407
+ * outputFormat: 'text',
7408
+ * })
7409
+ * ```
7410
+ */
7411
+ withSubagentTool(name, opts) {
7412
+ const lastStep = this.steps[this.steps.length - 1];
7413
+ if (!lastStep || lastStep.type !== "prompt") {
7414
+ throw new Error(
7415
+ "withSubagentTool() must be called after a .prompt() step \u2014 it attaches a runtime tool to the last prompt step."
7416
+ );
7417
+ }
7418
+ const config = {
7419
+ agentId: opts.agentId,
7420
+ agent: opts.agent,
7421
+ allowedTools: opts.allowedTools,
7422
+ maxTurns: opts.maxTurns,
7423
+ maxCost: opts.maxCost,
7424
+ timeoutMs: opts.timeoutMs,
7425
+ outputFormat: opts.outputFormat,
7426
+ inheritMessages: opts.inheritMessages,
7427
+ taskTemplate: opts.taskTemplate
7428
+ };
7429
+ const tool = {
7430
+ name,
7431
+ description: opts.description ?? `Spawn the ${name} subagent for a focused sub-task. Returns only the subagent's final result.`,
7432
+ toolType: "subagent",
7433
+ parametersSchema: opts.parametersSchema ?? {
7434
+ type: "object",
7435
+ properties: {
7436
+ task: {
7437
+ type: "string",
7438
+ description: "Self-contained task for the subagent. The subagent cannot see this conversation."
7439
+ }
7440
+ },
7441
+ required: ["task"]
7442
+ },
7443
+ config
7444
+ };
7445
+ const existingTools = lastStep.config.tools ?? {};
7446
+ const runtimeTools = [...existingTools.runtimeTools ?? [], tool];
7447
+ lastStep.config.tools = { ...existingTools, runtimeTools };
7448
+ return this;
7449
+ }
7450
+ /**
7451
+ * Enable agent-driven dynamic subagent spawning on the most recent prompt
7452
+ * step (surface C of the subagent design).
7453
+ *
7454
+ * When set, the API synthesizes a `spawn_subagent` tool the parent's model
7455
+ * can call at runtime to spin off a focused child agent. The child's tools
7456
+ * are drawn from `toolPool`, which must be a subset of the parent step's
7457
+ * resolved tools. The API validates pool entries and rejects escalation.
7458
+ *
7459
+ * @example
7460
+ * ```typescript
7461
+ * new FlowBuilder()
7462
+ * .createFlow({ name: 'Explore' })
7463
+ * .prompt({ name: 'Research', model: 'claude-sonnet-4-5', userPrompt: '...' })
7464
+ * .withSubagents({
7465
+ * toolPool: ['builtin:exa_search', 'mcp:*'],
7466
+ * maxSpawnsPerRun: 3,
7467
+ * allowNesting: false,
7468
+ * })
7469
+ * ```
7470
+ */
7471
+ withSubagents(opts) {
7472
+ const lastStep = this.steps[this.steps.length - 1];
7473
+ if (!lastStep || lastStep.type !== "prompt") {
7474
+ throw new Error(
7475
+ "withSubagents() must be called after a .prompt() step \u2014 it configures subagent spawning on the last prompt step."
7476
+ );
7477
+ }
7478
+ const existingTools = lastStep.config.tools ?? {};
7479
+ lastStep.config.tools = { ...existingTools, subagentConfig: opts };
7480
+ return this;
7481
+ }
7482
+ // ============================================================================
7364
7483
  // Build Method
7365
7484
  // ============================================================================
7366
7485
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "1.15.3",
3
+ "version": "1.17.0",
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",