@runtypelabs/sdk 1.8.2 → 1.9.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.d.cts CHANGED
@@ -871,6 +871,33 @@ interface FetchUrlStepConfig$1 {
871
871
  streamOutput?: boolean;
872
872
  enabled?: boolean;
873
873
  }
874
+ interface CrawlStepConfig {
875
+ name: string;
876
+ url: string;
877
+ limit?: number;
878
+ depth?: number;
879
+ source?: string;
880
+ formats?: string[];
881
+ render?: boolean;
882
+ maxAge?: number;
883
+ modifiedSince?: string;
884
+ options?: Record<string, unknown>;
885
+ authenticate?: Record<string, unknown>;
886
+ cookies?: Array<Record<string, unknown>>;
887
+ setExtraHTTPHeaders?: Record<string, string>;
888
+ gotoOptions?: Record<string, unknown>;
889
+ waitForSelector?: string;
890
+ rejectResourceTypes?: string[];
891
+ rejectRequestPattern?: string | string[];
892
+ userAgent?: string;
893
+ jsonOptions?: Record<string, unknown>;
894
+ outputVariable?: string;
895
+ streamOutput?: boolean;
896
+ errorHandling?: ErrorHandlingMode | ContextErrorHandling;
897
+ pollIntervalMs?: number;
898
+ completionTimeoutMs?: number;
899
+ enabled?: boolean;
900
+ }
874
901
  interface TransformDataStepConfig$1 {
875
902
  name: string;
876
903
  script: string;
@@ -1297,6 +1324,10 @@ declare class FlowBuilder {
1297
1324
  * Add a prompt step
1298
1325
  */
1299
1326
  prompt(config: PromptStepConfig$1): this;
1327
+ /**
1328
+ * Add a crawl step
1329
+ */
1330
+ crawl(config: CrawlStepConfig): this;
1300
1331
  /**
1301
1332
  * Add a fetch URL step
1302
1333
  */
@@ -4686,6 +4717,18 @@ declare class AgentsEndpoint {
4686
4717
  * Used when compact mode is enabled to keep token usage low.
4687
4718
  */
4688
4719
  private generateCompactSummary;
4720
+ private isAssistantToolCallMessage;
4721
+ private isToolResultMessage;
4722
+ /**
4723
+ * Replay only complete adjacent tool-call/result pairs so provider validation
4724
+ * never sees an orphaned tool result after history trimming or resume.
4725
+ */
4726
+ private sanitizeReplayHistoryMessages;
4727
+ /**
4728
+ * Keep replay trimming on a pair boundary. If the trim cut would start on a
4729
+ * tool-result message, slide back to include the matching assistant tool call.
4730
+ */
4731
+ private trimReplayHistoryMessages;
4689
4732
  /**
4690
4733
  * Build messages for a session, injecting progress context for continuation sessions.
4691
4734
  * Optionally accepts continuation context for marathon resume scenarios.
package/dist/index.d.ts CHANGED
@@ -871,6 +871,33 @@ interface FetchUrlStepConfig$1 {
871
871
  streamOutput?: boolean;
872
872
  enabled?: boolean;
873
873
  }
874
+ interface CrawlStepConfig {
875
+ name: string;
876
+ url: string;
877
+ limit?: number;
878
+ depth?: number;
879
+ source?: string;
880
+ formats?: string[];
881
+ render?: boolean;
882
+ maxAge?: number;
883
+ modifiedSince?: string;
884
+ options?: Record<string, unknown>;
885
+ authenticate?: Record<string, unknown>;
886
+ cookies?: Array<Record<string, unknown>>;
887
+ setExtraHTTPHeaders?: Record<string, string>;
888
+ gotoOptions?: Record<string, unknown>;
889
+ waitForSelector?: string;
890
+ rejectResourceTypes?: string[];
891
+ rejectRequestPattern?: string | string[];
892
+ userAgent?: string;
893
+ jsonOptions?: Record<string, unknown>;
894
+ outputVariable?: string;
895
+ streamOutput?: boolean;
896
+ errorHandling?: ErrorHandlingMode | ContextErrorHandling;
897
+ pollIntervalMs?: number;
898
+ completionTimeoutMs?: number;
899
+ enabled?: boolean;
900
+ }
874
901
  interface TransformDataStepConfig$1 {
875
902
  name: string;
876
903
  script: string;
@@ -1297,6 +1324,10 @@ declare class FlowBuilder {
1297
1324
  * Add a prompt step
1298
1325
  */
1299
1326
  prompt(config: PromptStepConfig$1): this;
1327
+ /**
1328
+ * Add a crawl step
1329
+ */
1330
+ crawl(config: CrawlStepConfig): this;
1300
1331
  /**
1301
1332
  * Add a fetch URL step
1302
1333
  */
@@ -4686,6 +4717,18 @@ declare class AgentsEndpoint {
4686
4717
  * Used when compact mode is enabled to keep token usage low.
4687
4718
  */
4688
4719
  private generateCompactSummary;
4720
+ private isAssistantToolCallMessage;
4721
+ private isToolResultMessage;
4722
+ /**
4723
+ * Replay only complete adjacent tool-call/result pairs so provider validation
4724
+ * never sees an orphaned tool result after history trimming or resume.
4725
+ */
4726
+ private sanitizeReplayHistoryMessages;
4727
+ /**
4728
+ * Keep replay trimming on a pair boundary. If the trim cut would start on a
4729
+ * tool-result message, slide back to include the matching assistant tool call.
4730
+ */
4731
+ private trimReplayHistoryMessages;
4689
4732
  /**
4690
4733
  * Build messages for a session, injecting progress context for continuation sessions.
4691
4734
  * Optionally accepts continuation context for marathon resume scenarios.
package/dist/index.js CHANGED
@@ -6169,6 +6169,75 @@ Do NOT redo any of the above work.`
6169
6169
  (state.lastOutput || "").slice(0, 1800) || "- No final output recorded yet."
6170
6170
  ].join("\n");
6171
6171
  }
6172
+ isAssistantToolCallMessage(message) {
6173
+ return Boolean(message?.role === "assistant" && message.toolCalls && message.toolCalls.length > 0);
6174
+ }
6175
+ isToolResultMessage(message) {
6176
+ return Boolean(message?.role === "tool" && message.toolResults && message.toolResults.length > 0);
6177
+ }
6178
+ /**
6179
+ * Replay only complete adjacent tool-call/result pairs so provider validation
6180
+ * never sees an orphaned tool result after history trimming or resume.
6181
+ */
6182
+ sanitizeReplayHistoryMessages(messages) {
6183
+ const sanitized = [];
6184
+ for (let index = 0; index < messages.length; index++) {
6185
+ const message = messages[index];
6186
+ if (this.isAssistantToolCallMessage(message)) {
6187
+ const nextMessage = messages[index + 1];
6188
+ if (!this.isToolResultMessage(nextMessage)) {
6189
+ continue;
6190
+ }
6191
+ const matchedResultIds = new Set(
6192
+ nextMessage.toolResults.filter(
6193
+ (toolResult) => message.toolCalls.some((toolCall) => toolCall.toolCallId === toolResult.toolCallId)
6194
+ ).map((toolResult) => toolResult.toolCallId)
6195
+ );
6196
+ if (matchedResultIds.size === 0) {
6197
+ continue;
6198
+ }
6199
+ const matchedToolCalls = message.toolCalls.filter(
6200
+ (toolCall) => matchedResultIds.has(toolCall.toolCallId)
6201
+ );
6202
+ const matchedToolResults = nextMessage.toolResults.filter(
6203
+ (toolResult) => matchedResultIds.has(toolResult.toolCallId)
6204
+ );
6205
+ sanitized.push(
6206
+ matchedToolCalls.length === message.toolCalls.length ? message : { ...message, toolCalls: matchedToolCalls }
6207
+ );
6208
+ sanitized.push(
6209
+ matchedToolResults.length === nextMessage.toolResults.length ? nextMessage : { ...nextMessage, toolResults: matchedToolResults }
6210
+ );
6211
+ index += 1;
6212
+ continue;
6213
+ }
6214
+ if (this.isToolResultMessage(message)) {
6215
+ continue;
6216
+ }
6217
+ sanitized.push(message);
6218
+ }
6219
+ return sanitized;
6220
+ }
6221
+ /**
6222
+ * Keep replay trimming on a pair boundary. If the trim cut would start on a
6223
+ * tool-result message, slide back to include the matching assistant tool call.
6224
+ */
6225
+ trimReplayHistoryMessages(messages, maxMessages) {
6226
+ if (messages.length <= maxMessages) {
6227
+ return {
6228
+ historyMessages: messages,
6229
+ trimmedCount: 0
6230
+ };
6231
+ }
6232
+ let startIndex = messages.length - maxMessages;
6233
+ while (startIndex > 0 && messages[startIndex]?.role === "tool") {
6234
+ startIndex -= 1;
6235
+ }
6236
+ return {
6237
+ historyMessages: messages.slice(startIndex),
6238
+ trimmedCount: startIndex
6239
+ };
6240
+ }
6172
6241
  /**
6173
6242
  * Build messages for a session, injecting progress context for continuation sessions.
6174
6243
  * Optionally accepts continuation context for marathon resume scenarios.
@@ -6271,6 +6340,9 @@ Do NOT redo any of the above work.`
6271
6340
  const candidateBlock = wf.buildCandidateBlock?.(state) ?? "";
6272
6341
  const multiSessionInstruction = `This is a multi-session task (session ${sessionIndex + 1}/${maxSessions}). When you have fully completed the task, end your response with TASK_COMPLETE on its own line.`;
6273
6342
  if (continuationContext && sessionIndex === 0) {
6343
+ const replayHistoryMessages = this.sanitizeReplayHistoryMessages(
6344
+ continuationContext.previousMessages
6345
+ );
6274
6346
  const defaultContinueMessage = "Continue the task. Review your prior work above and proceed with any remaining work. If everything is already complete, respond with TASK_COMPLETE.";
6275
6347
  const userMessage = continuationContext.newUserMessage || defaultContinueMessage;
6276
6348
  const userContent = [
@@ -6283,7 +6355,7 @@ Do NOT redo any of the above work.`
6283
6355
  multiSessionInstruction
6284
6356
  ].join("\n");
6285
6357
  const fullHistoryMessages = [
6286
- ...continuationContext.previousMessages,
6358
+ ...replayHistoryMessages,
6287
6359
  {
6288
6360
  role: "system",
6289
6361
  content: "IMPORTANT: You are continuing a previously completed task. The conversation above shows your prior work. Do NOT redo any of it. Build on what was already accomplished. If there is nothing new to do, respond with TASK_COMPLETE."
@@ -6295,7 +6367,7 @@ Do NOT redo any of the above work.`
6295
6367
  ];
6296
6368
  const summaryText = this.generateCompactSummary(state, compactInstructions);
6297
6369
  const breakdown = this.buildContextBudgetBreakdown({
6298
- historyMessages: continuationContext.previousMessages,
6370
+ historyMessages: replayHistoryMessages,
6299
6371
  currentTurnContent: userContent,
6300
6372
  localTools: compactionOptions?.localTools,
6301
6373
  builtinToolSchemas: compactionOptions?.builtinToolSchemas || [],
@@ -6385,16 +6457,19 @@ Do NOT redo any of the above work.`
6385
6457
  "Do not redo previous work. If the task is already complete, respond with TASK_COMPLETE."
6386
6458
  ].join("\n");
6387
6459
  const MAX_HISTORY_MESSAGES = 60;
6388
- let historyMessages = state.messages;
6460
+ let historyMessages = this.sanitizeReplayHistoryMessages(state.messages);
6389
6461
  if (historyMessages.length > MAX_HISTORY_MESSAGES) {
6390
- const trimmedCount = historyMessages.length - MAX_HISTORY_MESSAGES;
6391
- historyMessages = [
6392
- {
6393
- role: "system",
6394
- content: `[${trimmedCount} earlier messages trimmed to stay within context limits. Original task: ${(state.originalMessage || originalMessage).slice(0, 500)}]`
6395
- },
6396
- ...historyMessages.slice(-MAX_HISTORY_MESSAGES)
6397
- ];
6462
+ const trimmedHistory = this.trimReplayHistoryMessages(historyMessages, MAX_HISTORY_MESSAGES);
6463
+ historyMessages = trimmedHistory.historyMessages;
6464
+ if (trimmedHistory.trimmedCount > 0) {
6465
+ historyMessages = [
6466
+ {
6467
+ role: "system",
6468
+ content: `[${trimmedHistory.trimmedCount} earlier messages trimmed to stay within context limits. Original task: ${(state.originalMessage || originalMessage).slice(0, 500)}]`
6469
+ },
6470
+ ...historyMessages
6471
+ ];
6472
+ }
6398
6473
  }
6399
6474
  const summaryText = this.generateCompactSummary(state, compactInstructions);
6400
6475
  const breakdown = this.buildContextBudgetBreakdown({
@@ -6656,6 +6731,42 @@ var FlowBuilder = class {
6656
6731
  );
6657
6732
  return this;
6658
6733
  }
6734
+ /**
6735
+ * Add a crawl step
6736
+ */
6737
+ crawl(config) {
6738
+ this.addStep(
6739
+ "crawl",
6740
+ config.name,
6741
+ {
6742
+ url: config.url,
6743
+ limit: config.limit,
6744
+ depth: config.depth,
6745
+ source: config.source,
6746
+ formats: config.formats,
6747
+ render: config.render,
6748
+ maxAge: config.maxAge,
6749
+ modifiedSince: config.modifiedSince,
6750
+ options: config.options,
6751
+ authenticate: config.authenticate,
6752
+ cookies: config.cookies,
6753
+ setExtraHTTPHeaders: config.setExtraHTTPHeaders,
6754
+ gotoOptions: config.gotoOptions,
6755
+ waitForSelector: config.waitForSelector,
6756
+ rejectResourceTypes: config.rejectResourceTypes,
6757
+ rejectRequestPattern: config.rejectRequestPattern,
6758
+ userAgent: config.userAgent,
6759
+ jsonOptions: config.jsonOptions,
6760
+ outputVariable: config.outputVariable,
6761
+ errorHandling: config.errorHandling,
6762
+ streamOutput: config.streamOutput,
6763
+ pollIntervalMs: config.pollIntervalMs,
6764
+ completionTimeoutMs: config.completionTimeoutMs
6765
+ },
6766
+ config.enabled
6767
+ );
6768
+ return this;
6769
+ }
6659
6770
  /**
6660
6771
  * Add a fetch URL step
6661
6772
  */
@@ -6998,7 +7109,7 @@ var ClientFlowBuilder = class extends FlowBuilder {
6998
7109
  this.boundClient = client;
6999
7110
  this.createFlow({ name });
7000
7111
  }
7001
- async run(arg1, arg2, arg3, arg4) {
7112
+ async run(arg1, arg2, arg3, _arg4) {
7002
7113
  const config = this.build();
7003
7114
  let runOptions;
7004
7115
  let runCallbacks;