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
28 changes: 14 additions & 14 deletions apps/docs/content/docs/blocks/workflow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ Define the data to pass to the child workflow:

- **Single Variable Input**: Select a variable or block output to pass to the child workflow
- **Variable References**: Use `<variable.name>` to reference workflow variables
- **Block References**: Use `<blockName.response.field>` to reference outputs from previous blocks
- **Automatic Mapping**: The selected data is automatically available as `start.response.input` in the child workflow
- **Block References**: Use `<blockName.field>` to reference outputs from previous blocks
- **Automatic Mapping**: The selected data is automatically available as `start.input` in the child workflow
- **Optional**: The input field is optional - child workflows can run without input data
- **Type Preservation**: Variable types (strings, numbers, objects, etc.) are preserved when passed to the child workflow

### Examples of Input References

- `<variable.customerData>` - Pass a workflow variable
- `<dataProcessor.response.result>` - Pass the result from a previous block
- `<start.response.input>` - Pass the original workflow input
- `<apiCall.response.data.user>` - Pass a specific field from an API response
- `<dataProcessor.result>` - Pass the result from a previous block
- `<start.input>` - Pass the original workflow input
- `<apiCall.data.user>` - Pass a specific field from an API response

### Execution Context

Expand Down Expand Up @@ -109,7 +109,7 @@ To prevent infinite recursion and ensure system stability, the Workflow block in
<strong>Workflow ID</strong>: The identifier of the workflow to execute
</li>
<li>
<strong>Input Variable</strong>: Variable or block reference to pass to the child workflow (e.g., `<variable.name>` or `<block.response.field>`)
<strong>Input Variable</strong>: Variable or block reference to pass to the child workflow (e.g., `<variable.name>` or `<block.field>`)
</li>
</ul>
</Tab>
Expand Down Expand Up @@ -150,31 +150,31 @@ blocks:
- type: workflow
name: "Setup Customer Account"
workflowId: "account-setup-workflow"
input: "<Validate Customer Data.response.result>"
input: "<Validate Customer Data.result>"

- type: workflow
name: "Send Welcome Email"
workflowId: "welcome-email-workflow"
input: "<Setup Customer Account.response.result.accountDetails>"
input: "<Setup Customer Account.result.accountDetails>"
```

### Child Workflow: Customer Validation
```yaml
# Reusable customer validation workflow
# Access the input data using: start.response.input
# Access the input data using: start.input
blocks:
- type: function
name: "Validate Email"
code: |
const customerData = start.response.input;
const customerData = start.input;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(customerData.email);

- type: api
name: "Check Credit Score"
url: "https://api.creditcheck.com/score"
method: "POST"
body: "<start.response.input>"
body: "<start.input>"
```

### Variable Reference Examples
Expand All @@ -184,13 +184,13 @@ blocks:
input: "<variable.customerInfo>"

# Using block outputs
input: "<dataProcessor.response.cleanedData>"
input: "<dataProcessor.cleanedData>"

# Using nested object properties
input: "<apiCall.response.data.user.profile>"
input: "<apiCall.data.user.profile>"

# Using array elements (if supported by the resolver)
input: "<listProcessor.response.items[0]>"
input: "<listProcessor.items[0]>"
```

## Access Control and Permissions
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/__test-utils__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const sampleWorkflowState = {
webhookPath: { id: 'webhookPath', type: 'short-input', value: '' },
},
outputs: {
response: { type: { input: 'any' } },
input: 'any',
},
enabled: true,
horizontalHandles: true,
Expand All @@ -111,7 +111,7 @@ export const sampleWorkflowState = {
type: 'long-input',
value: 'You are a helpful assistant',
},
context: { id: 'context', type: 'short-input', value: '<start.response.input>' },
context: { id: 'context', type: 'short-input', value: '<start.input>' },
model: { id: 'model', type: 'dropdown', value: 'gpt-4o' },
apiKey: { id: 'apiKey', type: 'short-input', value: '{{OPENAI_API_KEY}}' },
},
Expand Down
20 changes: 10 additions & 10 deletions apps/sim/app/api/chat/[subdomain]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('Chat Subdomain API Route', () => {
})

describe('POST endpoint', () => {
it('should handle authentication requests without messages', async () => {
it('should handle authentication requests without input', async () => {
const req = createMockRequest('POST', { password: 'test-password' })
const params = Promise.resolve({ subdomain: 'password-protected-chat' })

Expand All @@ -257,7 +257,7 @@ describe('Chat Subdomain API Route', () => {
expect(mockSetChatAuthCookie).toHaveBeenCalled()
})

it('should return 400 for requests without message', async () => {
it('should return 400 for requests without input', async () => {
const req = createMockRequest('POST', {})
const params = Promise.resolve({ subdomain: 'test-chat' })

Expand All @@ -269,7 +269,7 @@ describe('Chat Subdomain API Route', () => {

const data = await response.json()
expect(data).toHaveProperty('error')
expect(data).toHaveProperty('message', 'No message provided')
expect(data).toHaveProperty('message', 'No input provided')
})

it('should return 401 for unauthorized access', async () => {
Expand All @@ -279,7 +279,7 @@ describe('Chat Subdomain API Route', () => {
error: 'Authentication required',
}))

const req = createMockRequest('POST', { message: 'Hello' })
const req = createMockRequest('POST', { input: 'Hello' })
const params = Promise.resolve({ subdomain: 'protected-chat' })

const { POST } = await import('./route')
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('Chat Subdomain API Route', () => {
}
})

const req = createMockRequest('POST', { message: 'Hello' })
const req = createMockRequest('POST', { input: 'Hello' })
const params = Promise.resolve({ subdomain: 'test-chat' })

const { POST } = await import('./route')
Expand All @@ -357,7 +357,7 @@ describe('Chat Subdomain API Route', () => {
})

it('should return streaming response for valid chat messages', async () => {
const req = createMockRequest('POST', { message: 'Hello world', conversationId: 'conv-123' })
const req = createMockRequest('POST', { input: 'Hello world', conversationId: 'conv-123' })
const params = Promise.resolve({ subdomain: 'test-chat' })

const { POST } = await import('./route')
Expand All @@ -374,7 +374,7 @@ describe('Chat Subdomain API Route', () => {
})

it('should handle streaming response body correctly', async () => {
const req = createMockRequest('POST', { message: 'Hello world' })
const req = createMockRequest('POST', { input: 'Hello world' })
const params = Promise.resolve({ subdomain: 'test-chat' })

const { POST } = await import('./route')
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('Chat Subdomain API Route', () => {
throw new Error('Execution failed')
})

const req = createMockRequest('POST', { message: 'Trigger error' })
const req = createMockRequest('POST', { input: 'Trigger error' })
const params = Promise.resolve({ subdomain: 'test-chat' })

const { POST } = await import('./route')
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('Chat Subdomain API Route', () => {

it('should pass conversationId to executeWorkflowForChat when provided', async () => {
const req = createMockRequest('POST', {
message: 'Hello world',
input: 'Hello world',
conversationId: 'test-conversation-123',
})
const params = Promise.resolve({ subdomain: 'test-chat' })
Expand All @@ -461,7 +461,7 @@ describe('Chat Subdomain API Route', () => {
})

it('should handle missing conversationId gracefully', async () => {
const req = createMockRequest('POST', { message: 'Hello world' })
const req = createMockRequest('POST', { input: 'Hello world' })
const params = Promise.resolve({ subdomain: 'test-chat' })

const { POST } = await import('./route')
Expand Down
14 changes: 7 additions & 7 deletions apps/sim/app/api/chat/[subdomain]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export async function POST(
}

// Use the already parsed body
const { message, password, email, conversationId } = parsedBody
const { input, password, email, conversationId } = parsedBody

// If this is an authentication request (has password or email but no message),
// If this is an authentication request (has password or email but no input),
// set auth cookie and return success
if ((password || email) && !message) {
if ((password || email) && !input) {
const response = addCorsHeaders(createSuccessResponse({ authenticated: true }), request)

// Set authentication cookie
Expand All @@ -86,8 +86,8 @@ export async function POST(
}

// For chat messages, create regular response
if (!message) {
return addCorsHeaders(createErrorResponse('No message provided', 400), request)
if (!input) {
return addCorsHeaders(createErrorResponse('No input provided', 400), request)
}

// Get the workflow for this chat
Expand All @@ -105,8 +105,8 @@ export async function POST(
}

try {
// Execute workflow with structured input (message + conversationId for context)
const result = await executeWorkflowForChat(deployment.id, message, conversationId)
// Execute workflow with structured input (input + conversationId for context)
const result = await executeWorkflowForChat(deployment.id, input, conversationId)

// The result is always a ReadableStream that we can pipe to the client
const streamResponse = new NextResponse(result, {
Expand Down
22 changes: 11 additions & 11 deletions apps/sim/app/api/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ export async function validateChatAuth(
return { authorized: false, error: 'Password is required' }
}

const { password, message } = parsedBody
const { password, input } = parsedBody

// If this is a chat message, not an auth attempt
if (message && !password) {
if (input && !password) {
return { authorized: false, error: 'auth_required_password' }
}

Expand Down Expand Up @@ -170,10 +170,10 @@ export async function validateChatAuth(
return { authorized: false, error: 'Email is required' }
}

const { email, message } = parsedBody
const { email, input } = parsedBody

// If this is a chat message, not an auth attempt
if (message && !email) {
if (input && !email) {
return { authorized: false, error: 'auth_required_email' }
}

Expand Down Expand Up @@ -211,17 +211,17 @@ export async function validateChatAuth(
/**
* Executes a workflow for a chat request and returns the formatted output.
*
* When workflows reference <start.response.input>, they receive a structured JSON
* containing both the message and conversationId for maintaining chat context.
* When workflows reference <start.input>, they receive the input directly.
* The conversationId is available at <start.conversationId> for maintaining chat context.
*
* @param chatId - Chat deployment identifier
* @param message - User's chat message
* @param input - User's chat input
* @param conversationId - Optional ID for maintaining conversation context
* @returns Workflow execution result formatted for the chat interface
*/
export async function executeWorkflowForChat(
chatId: string,
message: string,
input: string,
conversationId?: string
): Promise<any> {
const requestId = crypto.randomUUID().slice(0, 8)
Expand Down Expand Up @@ -445,7 +445,7 @@ export async function executeWorkflowForChat(
workflow: serializedWorkflow,
currentBlockStates: processedBlockStates,
envVarValues: decryptedEnvVars,
workflowInput: { input: message, conversationId },
workflowInput: { input: input, conversationId },
workflowVariables,
contextExtensions: {
stream: true,
Expand All @@ -463,8 +463,8 @@ export async function executeWorkflowForChat(
if (result && 'success' in result) {
result.logs?.forEach((log: BlockLog) => {
if (streamedContent.has(log.blockId)) {
if (log.output?.response) {
log.output.response.content = streamedContent.get(log.blockId)
if (log.output) {
log.output.content = streamedContent.get(log.blockId)
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/codegen/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Example Scenario:
User Prompt: "Fetch user data from an API. Use the User ID passed in as 'userId' and an API Key stored as the 'SERVICE_API_KEY' environment variable."

Generated Code:
const userId = <block.response.content>; // Correct: Accessing input parameter without quotes
const userId = <block.content>; // Correct: Accessing input parameter without quotes
const apiKey = {{SERVICE_API_KEY}}; // Correct: Accessing environment variable without quotes
const url = \`https://api.example.com/users/\${userId}\`;

Expand Down Expand Up @@ -273,7 +273,7 @@ Do not include import/require statements unless absolutely necessary and they ar
Do not include markdown formatting or explanations.
Output only the raw TypeScript code. Use modern TypeScript features where appropriate. Do not use semicolons.
Example:
const userId = <block.response.content> as string
const userId = <block.content> as string
const apiKey = {{SERVICE_API_KEY}}
const response = await fetch(\`https://api.example.com/users/\${userId}\`, { headers: { Authorization: \`Bearer \${apiKey}\` } })
if (!response.ok) {
Expand Down
32 changes: 15 additions & 17 deletions apps/sim/app/api/providers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,22 @@ export async function POST(request: NextRequest) {
const safeExecutionData = {
success: executionData.success,
output: {
response: {
// Sanitize content to remove non-ASCII characters that would cause ByteString errors
content: executionData.output?.response?.content
? String(executionData.output.response.content).replace(/[\u0080-\uFFFF]/g, '')
: '',
model: executionData.output?.response?.model,
tokens: executionData.output?.response?.tokens || {
prompt: 0,
completion: 0,
total: 0,
},
// Sanitize any potential Unicode characters in tool calls
toolCalls: executionData.output?.response?.toolCalls
? sanitizeToolCalls(executionData.output.response.toolCalls)
: undefined,
providerTiming: executionData.output?.response?.providerTiming,
cost: executionData.output?.response?.cost,
// Sanitize content to remove non-ASCII characters that would cause ByteString errors
content: executionData.output?.content
? String(executionData.output.content).replace(/[\u0080-\uFFFF]/g, '')
: '',
model: executionData.output?.model,
tokens: executionData.output?.tokens || {
prompt: 0,
completion: 0,
total: 0,
},
// Sanitize any potential Unicode characters in tool calls
toolCalls: executionData.output?.toolCalls
? sanitizeToolCalls(executionData.output.toolCalls)
: undefined,
providerTiming: executionData.output?.providerTiming,
cost: executionData.output?.cost,
},
error: executionData.error,
logs: [], // Strip logs from header to avoid encoding issues
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/app/api/user/settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SettingsSchema = z.object({
debugMode: z.boolean().optional(),
autoConnect: z.boolean().optional(),
autoFillEnvVars: z.boolean().optional(),
autoPan: z.boolean().optional(),
telemetryEnabled: z.boolean().optional(),
telemetryNotifiedUser: z.boolean().optional(),
emailPreferences: z
Expand All @@ -32,6 +33,7 @@ const defaultSettings = {
debugMode: false,
autoConnect: true,
autoFillEnvVars: true,
autoPan: true,
telemetryEnabled: true,
telemetryNotifiedUser: false,
emailPreferences: {},
Expand Down Expand Up @@ -65,6 +67,7 @@ export async function GET() {
debugMode: userSettings.debugMode,
autoConnect: userSettings.autoConnect,
autoFillEnvVars: userSettings.autoFillEnvVars,
autoPan: userSettings.autoPan,
telemetryEnabled: userSettings.telemetryEnabled,
telemetryNotifiedUser: userSettings.telemetryNotifiedUser,
emailPreferences: userSettings.emailPreferences ?? {},
Expand Down
Loading