Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/docs/content/docs/integrations/browser_use.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Runs a browser automation task using BrowserUse
| `flashMode` | boolean | No | Enable flash mode \(faster, less careful navigation\) |
| `thinking` | boolean | No | Enable extended reasoning mode |
| `vision` | string | No | Vision capability: "true", "false", or "auto" |
| `systemPromptExtension` | string | No | Optional text appended to the agent system prompt \(max 2000 chars\) |
| `systemPromptExtension` | string | No | Optional text appended to the agent system prompt \(max 10000 chars\) |
| `structuredOutput` | string | No | Stringified JSON schema for the structured output |
| `highlightElements` | boolean | No | Highlight interactive elements on the page \(default true\) |
| `highlightElements` | boolean | No | Highlight interactive elements on the page \(default false\) |
| `metadata` | json | No | Custom key-value metadata \(up to 10 pairs\) for tracking |
| `model` | string | No | LLM model identifier \(e.g. browser-use-2.0\) |
| `profile_id` | string | No | Browser profile ID for persistent sessions \(cookies, login state\) |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/integrations/extend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Parse and extract content from documents using Extend AI
| `id` | string | Unique identifier for the parser run |
| `status` | string | Processing status |
| `chunks` | json | Parsed document content chunks |
| `blocks` | json | Block-level document elements with type and content |
| `blocks` | json | Top-level block elements; Extend returns blocks inside each chunk \(chunks\[\].blocks\), so this is usually empty |
| `pageCount` | number | Number of pages processed |
| `creditsUsed` | number | API credits consumed |

Expand Down
6 changes: 5 additions & 1 deletion apps/docs/content/docs/integrations/firecrawl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ Convert web pages to Markdown or HTML, including SEO metadata, Open Graph tags,
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `markdown` | string | Page content in markdown format |
| `html` | string | Raw HTML content of the page |
| `html` | string | Processed HTML content of the page |
| `rawHtml` | string | Unmodified HTML of the page, when the rawHtml format is requested |
| `summary` | string | Summary of the page, when the summary format is requested |
| `links` | array | Links found on the page, when the links format is requested |
| `screenshot` | string | Screenshot URL of the page, when the screenshot format is requested \(expires after 24 hours\) |
| `metadata` | object | Page metadata including SEO and Open Graph information |
| ↳ `title` | string | Page title |
| ↳ `description` | string | Page meta description |
Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/integrations/pulse.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Parse documents (PDF, images, Office docs) using Pulse OCR API
| `markdown` | string | Extracted content in markdown format |
| `page_count` | number | Number of pages in the document |
| `job_id` | string | Unique job identifier |
| `extraction_id` | string | Persisted extraction ID, for use with Pulse split and schema steps |
| `bounding_boxes` | json | Bounding box layout information |
| `extraction_url` | string | URL for extraction results \(for large documents\) |
| `html` | string | HTML content; returned only when the hidden returnHtml input is enabled |
Expand Down
15 changes: 11 additions & 4 deletions apps/sim/blocks/blocks/browser_use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,30 @@ export const BrowserUseBlock: BlockConfig = {
options: [
{ label: 'Browser Use LLM', id: 'browser-use-llm' },
{ label: 'Browser Use 2.0', id: 'browser-use-2.0' },
{ label: 'GPT-4o', id: 'gpt-4o' },
{ label: 'GPT-4o Mini', id: 'gpt-4o-mini' },
{ label: 'GPT-4o', id: 'gpt-4o', hidden: true },
{ label: 'GPT-4o Mini', id: 'gpt-4o-mini', hidden: true },
{ label: 'GPT-5.5', id: 'gpt-5.5' },
{ label: 'GPT-4.1', id: 'gpt-4.1' },
{ label: 'GPT-4.1 Mini', id: 'gpt-4.1-mini' },
{ label: 'O3', id: 'o3' },
{ label: 'O4 Mini', id: 'o4-mini' },
{ label: 'Gemini 2.5 Flash', id: 'gemini-2.5-flash' },
{ label: 'Gemini 2.5 Pro', id: 'gemini-2.5-pro' },
{ label: 'Gemini 3 Pro Preview', id: 'gemini-3-pro-preview' },
{ label: 'Gemini 3.1 Pro Preview', id: 'gemini-3.1-pro-preview' },
{ label: 'Gemini 3 Flash Preview', id: 'gemini-3-flash-preview' },
{ label: 'Gemini 3.5 Flash', id: 'gemini-3.5-flash' },
{ label: 'Gemini Flash Latest', id: 'gemini-flash-latest' },
{ label: 'Gemini Flash Lite Latest', id: 'gemini-flash-lite-latest' },
{ label: 'Claude 3.7 Sonnet', id: 'claude-3-7-sonnet-20250219' },
{ label: 'Claude Sonnet 4', id: 'claude-sonnet-4-20250514' },
{ label: 'Claude Sonnet 4.5', id: 'claude-sonnet-4-5-20250929' },
{ label: 'Claude Sonnet 4.6', id: 'claude-sonnet-4-6' },
{ label: 'Claude Sonnet 4.6', id: 'claude-sonnet-4-6', hidden: true },
{ label: 'Claude Sonnet 5', id: 'claude-sonnet-5' },
{ label: 'Claude Opus 4.5', id: 'claude-opus-4-5-20251101' },
{ label: 'Claude Opus 4.7', id: 'claude-opus-4-7' },
{ label: 'Claude Opus 4.8', id: 'claude-opus-4-8' },
{ label: 'Claude Opus 5', id: 'claude-opus-5' },
{ label: 'Llama 4 Maverick', id: 'llama-4-maverick-17b-128e-instruct' },
],
},
Expand Down Expand Up @@ -130,7 +137,7 @@ export const BrowserUseBlock: BlockConfig = {
id: 'systemPromptExtension',
title: 'System Prompt Extension',
type: 'long-input',
placeholder: 'Append custom instructions to the agent system prompt (max 2000 chars)',
placeholder: 'Append custom instructions to the agent system prompt (max 10000 chars)',
mode: 'advanced',
},
{
Expand Down
6 changes: 5 additions & 1 deletion apps/sim/blocks/blocks/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ export const ExtendBlock: BlockConfig = {
id: { type: 'string', description: 'Unique identifier for the parser run' },
status: { type: 'string', description: 'Processing status' },
chunks: { type: 'json', description: 'Parsed document content chunks' },
blocks: { type: 'json', description: 'Block-level document elements' },
blocks: {
type: 'json',
description:
'Top-level block elements; Extend returns blocks inside each chunk (chunks[].blocks)',
},
pageCount: { type: 'number', description: 'Number of pages processed' },
creditsUsed: { type: 'number', description: 'API credits consumed' },
},
Expand Down
17 changes: 17 additions & 0 deletions apps/sim/blocks/blocks/pulse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { PulseV3Block } from '@/blocks/blocks/pulse'

const file = { name: 'report.pdf', key: 'workspace/report.pdf', url: '/api/files/serve/report.pdf' }

describe('PulseV3Block tool calls', () => {
it('accepts the numeric chunk size an Agent tool call sends', () => {
const params = PulseV3Block.tools.config?.params?.(
{ file, chunkSize: 800 },
{
operation: 'pulse_parser_v2',
}
)

expect(params?.chunkSize).toBe(800)
})
})
26 changes: 16 additions & 10 deletions apps/sim/blocks/blocks/pulse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const DOCUMENT_FIELD = ['fileUpload', 'filePath'] as const
/* v2 swaps the advanced URL input for a file reference, so the pair differs. */
const DOCUMENT_V2_FIELD = ['fileUpload', 'fileReference'] as const

/** A positive chunk size from the canvas's text field or the number an Agent tool call sends. */
function parseChunkSize(value: unknown): number | undefined {
const size = typeof value === 'number' ? value : Number.parseInt(String(value ?? '').trim(), 10)
return Number.isInteger(size) && size > 0 ? size : undefined
}

export const PulseBlock: BlockConfig = {
type: 'pulse',
name: 'Pulse',
Expand Down Expand Up @@ -112,11 +118,9 @@ export const PulseBlock: BlockConfig = {
parameters.chunking = params.chunking.trim()
}

if (params.chunkSize && params.chunkSize.trim() !== '') {
const size = Number.parseInt(params.chunkSize.trim(), 10)
if (!Number.isNaN(size) && size > 0) {
parameters.chunkSize = size
}
const chunkSize = parseChunkSize(params.chunkSize)
if (chunkSize !== undefined) {
parameters.chunkSize = chunkSize
}

return parameters
Expand All @@ -140,6 +144,10 @@ export const PulseBlock: BlockConfig = {
markdown: { type: 'string', description: 'Extracted content in markdown format' },
page_count: { type: 'number', description: 'Number of pages in the document' },
job_id: { type: 'string', description: 'Unique job identifier' },
extraction_id: {
type: 'string',
description: 'Persisted extraction ID, for use with Pulse split and schema steps',
},
'plan-info': { type: 'json', description: 'Plan usage information' },
bounding_boxes: { type: 'json', description: 'Bounding box layout information' },
extraction_url: { type: 'string', description: 'URL for extraction results (large documents)' },
Expand Down Expand Up @@ -203,11 +211,9 @@ function pulseV2ToolParams(params: BlockToolParams, credentials: { apiKey?: stri
parameters.chunking = params.chunking.trim()
}

if (params.chunkSize && params.chunkSize.trim() !== '') {
const size = Number.parseInt(params.chunkSize.trim(), 10)
if (!Number.isNaN(size) && size > 0) {
parameters.chunkSize = size
}
const chunkSize = parseChunkSize(params.chunkSize)
if (chunkSize !== undefined) {
parameters.chunkSize = chunkSize
}

return parameters
Expand Down
17 changes: 17 additions & 0 deletions apps/sim/blocks/blocks/reducto.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { ReductoV3Block } from '@/blocks/blocks/reducto'

const file = { name: 'report.pdf', key: 'workspace/report.pdf', url: '/api/files/serve/report.pdf' }

describe('ReductoV3Block tool calls', () => {
it('accepts the page array an Agent tool call sends', () => {
const params = ReductoV3Block.tools.config?.params?.(
{ file, pages: [1, 3] },
{
operation: 'reducto_parser_v2',
}
)

expect(params?.pages).toEqual([1, 3])
})
})
83 changes: 30 additions & 53 deletions apps/sim/blocks/blocks/reducto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { toError } from '@sim/utils/errors'
import { ReductoIcon } from '@/components/icons'
import {
AuthMode,
Expand All @@ -18,6 +17,30 @@ const DOCUMENT_FIELD = ['fileUpload', 'filePath'] as const
/* v2 swaps the advanced URL input for a file reference, so the pair differs. */
const DOCUMENT_V2_FIELD = ['fileUpload', 'fileReference'] as const

/**
* Page numbers from the canvas's comma-separated text, or the array an Agent tool call sends.
* Returns `undefined` when no page is given.
*/
function parsePages(value: unknown): number[] | undefined {
const entries = Array.isArray(value)
? value.map((page) => String(page).trim())
: typeof value === 'string' || typeof value === 'number'
? String(value)
.split(',')
.map((page) => page.trim())
: []
const pages = entries
.filter((page) => page.length > 0)
.map((page) => {
const num = Number.parseInt(page, 10)
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
if (Number.isNaN(num) || num < 0) {
throw new Error(`Page number format error: Invalid page number: ${page}`)
}
return num
})
return pages.length > 0 ? pages : undefined
}

export const ReductoBlock: BlockConfig = {
type: 'reducto',
name: 'Reducto',
Expand Down Expand Up @@ -103,32 +126,9 @@ export const ReductoBlock: BlockConfig = {
parameters.filePath = documentInput.trim()
}

let pagesArray: number[] | undefined
if (params.pages && params.pages.trim() !== '') {
try {
pagesArray = params.pages
.split(',')
.map((p: string) => p.trim())
.filter((p: string) => p.length > 0)
.map((p: string) => {
const num = Number.parseInt(p, 10)
if (Number.isNaN(num) || num < 0) {
throw new Error(`Invalid page number: ${p}`)
}
return num
})

if (pagesArray && pagesArray.length === 0) {
pagesArray = undefined
}
} catch (error: unknown) {
const errorMessage = toError(error).message
throw new Error(`Page number format error: ${errorMessage}`)
}
}

if (pagesArray && pagesArray.length > 0) {
parameters.pages = pagesArray
const pages = parsePages(params.pages)
if (pages) {
parameters.pages = pages
}

if (params.tableOutputFormat) {
Expand Down Expand Up @@ -198,32 +198,9 @@ function reductoV2ToolParams(params: BlockToolParams, credentials: { apiKey?: st
}
parameters.file = fileInput

let pagesArray: number[] | undefined
if (params.pages && params.pages.trim() !== '') {
try {
pagesArray = params.pages
.split(',')
.map((p: string) => p.trim())
.filter((p: string) => p.length > 0)
.map((p: string) => {
const num = Number.parseInt(p, 10)
if (Number.isNaN(num) || num < 0) {
throw new Error(`Invalid page number: ${p}`)
}
return num
})

if (pagesArray && pagesArray.length === 0) {
pagesArray = undefined
}
} catch (error: unknown) {
const errorMessage = toError(error).message
throw new Error(`Page number format error: ${errorMessage}`)
}
}

if (pagesArray && pagesArray.length > 0) {
parameters.pages = pagesArray
const pages = parsePages(params.pages)
if (pages) {
parameters.pages = pages
}

if (params.tableOutputFormat) {
Expand Down
41 changes: 34 additions & 7 deletions apps/sim/lib/internal/browser-use/operations/run-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { sleep } from '@sim/utils/helpers'
import { z } from 'zod'
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
import { outboundFetch } from '@/lib/core/network/outbound-fetch.server'
import {
DEFAULT_MAX_ERROR_BODY_BYTES,
readResponseJsonWithLimit,
readResponseTextWithLimit,
} from '@/lib/core/utils/stream-limits'
import { MAX_TOOL_RESPONSE_BODY_BYTES } from '@/lib/internal/tool-operations/response-limits'
import type { InternalToolOperationImplementation } from '@/lib/internal/tool-operations/types'
import type {
BrowserUseRunTaskParams,
Expand Down Expand Up @@ -101,6 +107,25 @@ async function fetchBrowserUse(
return response
}

function readBrowserUseJson(response: Response, signal?: AbortSignal): Promise<unknown> {
return readResponseJsonWithLimit(response, {
maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES,
label: 'Browser Use response',
signal,
})
}

function readBrowserUseErrorText(response: Response, signal?: AbortSignal): Promise<string> {
return readResponseTextWithLimit(response, {
maxBytes: DEFAULT_MAX_ERROR_BODY_BYTES,
label: 'Browser Use error response',
signal,
}).catch(() => {
signal?.throwIfAborted()
return response.statusText
})
}

async function waitForNextPoll(signal?: AbortSignal): Promise<void> {
if (!signal) {
await sleep(POLL_INTERVAL_MS)
Expand Down Expand Up @@ -135,12 +160,12 @@ async function createSessionWithProfile(
})

if (!response.ok) {
const errorText = await response.text()
const errorText = await readBrowserUseErrorText(response, signal)
logger.error(`Failed to create session with profile: ${errorText}`)
return { error: `Failed to create session with profile: ${response.statusText}` }
}

const parsed = createSessionResponseSchema.safeParse(await response.json())
const parsed = createSessionResponseSchema.safeParse(await readBrowserUseJson(response, signal))
signal?.throwIfAborted()
if (!parsed.success) {
logger.error('BrowserUse returned an invalid create-session response')
Expand Down Expand Up @@ -186,7 +211,9 @@ async function fetchSessionLiveUrl(
if (!response.ok) {
return { liveUrl: null, publicShareUrl: null }
}
const parsed = sessionDetailsResponseSchema.safeParse(await response.json())
const parsed = sessionDetailsResponseSchema.safeParse(
await readBrowserUseJson(response, signal)
)
signal?.throwIfAborted()
if (!parsed.success) {
logger.warn(`BrowserUse returned an invalid session response for ${sessionId}`)
Expand Down Expand Up @@ -291,7 +318,7 @@ async function fetchTaskStatus(
return { ok: false, error: `HTTP ${response.status}: ${response.statusText}` }
}

const parsed = taskStatusResponseSchema.safeParse(await response.json())
const parsed = taskStatusResponseSchema.safeParse(await readBrowserUseJson(response, signal))
signal?.throwIfAborted()
if (!parsed.success) {
return { ok: false, error: 'BrowserUse returned an invalid task-status response' }
Expand Down Expand Up @@ -455,7 +482,7 @@ async function createShareUrl(
return null
}

const parsed = shareResponseSchema.safeParse(await response.json())
const parsed = shareResponseSchema.safeParse(await readBrowserUseJson(response, signal))
signal?.throwIfAborted()
if (!parsed.success) {
logger.warn(`BrowserUse returned an invalid share response for session ${sessionId}`)
Expand Down Expand Up @@ -510,7 +537,7 @@ export const executeRunTaskOperation: InternalToolOperationImplementation<
})

if (!response.ok) {
const errorText = await response.text()
const errorText = await readBrowserUseErrorText(response, signal)
logger.error(`Failed to create task: ${errorText}`)
return {
success: false,
Expand All @@ -519,7 +546,7 @@ export const executeRunTaskOperation: InternalToolOperationImplementation<
}
}

const parsed = createTaskResponseSchema.safeParse(await response.json())
const parsed = createTaskResponseSchema.safeParse(await readBrowserUseJson(response, signal))
signal?.throwIfAborted()
if (!parsed.success) {
logger.error('BrowserUse returned an invalid create-task response')
Expand Down
Loading
Loading