Skip to content

Commit 732df04

Browse files
authored
improvement(oauth): added advanced mode for all tools with oauth and selectors (#721)
* fixed SVG error, added tool-level awareness for param validation * added advanced mode for oauth block * added wealthbox advanced mode * fixed wealthbox * moved types to types file * ack pr comments
1 parent 3d5d747 commit 732df04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1354
-608
lines changed

apps/sim/blocks/blocks/agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { AgentBlock } from './agent'
2+
import { AgentBlock } from '@/blocks/blocks/agent'
33

44
vi.mock('@/blocks', () => ({
55
getAllBlocks: vi.fn(() => [

apps/sim/blocks/blocks/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AgentIcon } from '@/components/icons'
22
import { isHosted } from '@/lib/environment'
33
import { createLogger } from '@/lib/logs/console-logger'
4+
import type { BlockConfig } from '@/blocks/types'
45
import {
56
getAllModelProviders,
67
getBaseModelProviders,
@@ -13,7 +14,6 @@ import {
1314
} from '@/providers/utils'
1415
import { useOllamaStore } from '@/stores/ollama/store'
1516
import type { ToolResponse } from '@/tools/types'
16-
import type { BlockConfig } from '../types'
1717

1818
const logger = createLogger('AgentBlock')
1919

apps/sim/blocks/blocks/airtable.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import { AirtableIcon } from '@/components/icons'
2-
import type {
3-
AirtableCreateResponse,
4-
AirtableGetResponse,
5-
AirtableListResponse,
6-
AirtableUpdateMultipleResponse,
7-
AirtableUpdateResponse,
8-
} from '@/tools/airtable/types'
9-
import type { BlockConfig } from '../types'
10-
11-
type AirtableResponse =
12-
| AirtableListResponse
13-
| AirtableGetResponse
14-
| AirtableCreateResponse
15-
| AirtableUpdateResponse
16-
| AirtableUpdateMultipleResponse
2+
import type { BlockConfig } from '@/blocks/types'
3+
import type { AirtableResponse } from '@/tools/airtable/types'
174

185
export const AirtableBlock: BlockConfig<AirtableResponse> = {
196
type: 'airtable',

apps/sim/blocks/blocks/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApiIcon } from '@/components/icons'
2+
import type { BlockConfig } from '@/blocks/types'
23
import type { RequestResponse } from '@/tools/http/types'
3-
import type { BlockConfig } from '../types'
44

55
export const ApiBlock: BlockConfig<RequestResponse> = {
66
type: 'api',

apps/sim/blocks/blocks/browser_use.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { BrowserUseIcon } from '@/components/icons'
2-
import type { ToolResponse } from '@/tools/types'
3-
import type { BlockConfig } from '../types'
4-
5-
interface BrowserUseResponse extends ToolResponse {
6-
output: {
7-
id: string
8-
success: boolean
9-
output: any
10-
steps: any[]
11-
}
12-
}
2+
import type { BlockConfig } from '@/blocks/types'
3+
import type { BrowserUseResponse } from '@/tools/browser_use/types'
134

145
export const BrowserUseBlock: BlockConfig<BrowserUseResponse> = {
156
type: 'browser_use',

apps/sim/blocks/blocks/clay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ClayIcon } from '@/components/icons'
2+
import type { BlockConfig } from '@/blocks/types'
23
import type { ClayPopulateResponse } from '@/tools/clay/types'
3-
import type { BlockConfig } from '../types'
44

55
export const ClayBlock: BlockConfig<ClayPopulateResponse> = {
66
type: 'clay',

apps/sim/blocks/blocks/condition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ConditionalIcon } from '@/components/icons'
2-
import type { BlockConfig } from '../types'
2+
import type { BlockConfig } from '@/blocks/types'
33

44
interface ConditionBlockOutput {
55
success: boolean

apps/sim/blocks/blocks/confluence.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { ConfluenceIcon } from '@/components/icons'
2-
import type { ConfluenceRetrieveResponse, ConfluenceUpdateResponse } from '@/tools/confluence/types'
3-
import type { BlockConfig } from '../types'
4-
5-
type ConfluenceResponse = ConfluenceRetrieveResponse | ConfluenceUpdateResponse
2+
import type { BlockConfig } from '@/blocks/types'
3+
import type { ConfluenceResponse } from '@/tools/confluence/types'
64

75
export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
86
type: 'confluence',
@@ -48,7 +46,7 @@ export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
4846
],
4947
placeholder: 'Select Confluence account',
5048
},
51-
// Use file-selector component for page selection
49+
// Page selector (basic mode)
5250
{
5351
id: 'pageId',
5452
title: 'Select Page',
@@ -57,6 +55,16 @@ export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
5755
provider: 'confluence',
5856
serviceId: 'confluence',
5957
placeholder: 'Select Confluence page',
58+
mode: 'basic',
59+
},
60+
// Manual page ID input (advanced mode)
61+
{
62+
id: 'manualPageId',
63+
title: 'Page ID',
64+
type: 'short-input',
65+
layout: 'full',
66+
placeholder: 'Enter Confluence page ID',
67+
mode: 'advanced',
6068
},
6169
// Update page fields
6270
{
@@ -90,10 +98,18 @@ export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
9098
}
9199
},
92100
params: (params) => {
93-
const { credential, ...rest } = params
101+
const { credential, pageId, manualPageId, ...rest } = params
102+
103+
// Use the selected page ID or the manually entered one
104+
const effectivePageId = (pageId || manualPageId || '').trim()
105+
106+
if (!effectivePageId) {
107+
throw new Error('Page ID is required. Please select a page or enter a page ID manually.')
108+
}
94109

95110
return {
96111
accessToken: credential,
112+
pageId: effectivePageId,
97113
...rest,
98114
}
99115
},
@@ -103,7 +119,8 @@ export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
103119
operation: { type: 'string', required: true },
104120
domain: { type: 'string', required: true },
105121
credential: { type: 'string', required: true },
106-
pageId: { type: 'string', required: true },
122+
pageId: { type: 'string', required: false },
123+
manualPageId: { type: 'string', required: false },
107124
// Update operation inputs
108125
title: { type: 'string', required: false },
109126
content: { type: 'string', required: false },

apps/sim/blocks/blocks/discord.ts

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DiscordIcon } from '@/components/icons'
2+
import type { BlockConfig } from '@/blocks/types'
23
import type { DiscordResponse } from '@/tools/discord/types'
3-
import type { BlockConfig } from '../types'
44

55
export const DiscordBlock: BlockConfig<DiscordResponse> = {
66
type: 'discord',
@@ -32,6 +32,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
3232
placeholder: 'Enter Discord bot token',
3333
password: true,
3434
},
35+
// Server selector (basic mode)
3536
{
3637
id: 'serverId',
3738
title: 'Server',
@@ -40,11 +41,26 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
4041
provider: 'discord',
4142
serviceId: 'discord',
4243
placeholder: 'Select Discord server',
44+
mode: 'basic',
4345
condition: {
4446
field: 'operation',
4547
value: ['discord_send_message', 'discord_get_messages', 'discord_get_server'],
4648
},
4749
},
50+
// Manual server ID input (advanced mode)
51+
{
52+
id: 'manualServerId',
53+
title: 'Server ID',
54+
type: 'short-input',
55+
layout: 'full',
56+
placeholder: 'Enter Discord server ID',
57+
mode: 'advanced',
58+
condition: {
59+
field: 'operation',
60+
value: ['discord_send_message', 'discord_get_messages', 'discord_get_server'],
61+
},
62+
},
63+
// Channel selector (basic mode)
4864
{
4965
id: 'channelId',
5066
title: 'Channel',
@@ -53,6 +69,17 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
5369
provider: 'discord',
5470
serviceId: 'discord',
5571
placeholder: 'Select Discord channel',
72+
mode: 'basic',
73+
condition: { field: 'operation', value: ['discord_send_message', 'discord_get_messages'] },
74+
},
75+
// Manual channel ID input (advanced mode)
76+
{
77+
id: 'manualChannelId',
78+
title: 'Channel ID',
79+
type: 'short-input',
80+
layout: 'full',
81+
placeholder: 'Enter Discord channel ID',
82+
mode: 'advanced',
5683
condition: { field: 'operation', value: ['discord_send_message', 'discord_get_messages'] },
5784
},
5885
{
@@ -108,25 +135,56 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
108135
if (!params.botToken) throw new Error('Bot token required for this operation')
109136
commonParams.botToken = params.botToken
110137

138+
// Handle server ID (selector or manual)
139+
const effectiveServerId = (params.serverId || params.manualServerId || '').trim()
140+
141+
// Handle channel ID (selector or manual)
142+
const effectiveChannelId = (params.channelId || params.manualChannelId || '').trim()
143+
111144
switch (params.operation) {
112145
case 'discord_send_message':
146+
if (!effectiveServerId) {
147+
throw new Error(
148+
'Server ID is required. Please select a server or enter a server ID manually.'
149+
)
150+
}
151+
if (!effectiveChannelId) {
152+
throw new Error(
153+
'Channel ID is required. Please select a channel or enter a channel ID manually.'
154+
)
155+
}
113156
return {
114157
...commonParams,
115-
serverId: params.serverId,
116-
channelId: params.channelId,
158+
serverId: effectiveServerId,
159+
channelId: effectiveChannelId,
117160
content: params.content,
118161
}
119162
case 'discord_get_messages':
163+
if (!effectiveServerId) {
164+
throw new Error(
165+
'Server ID is required. Please select a server or enter a server ID manually.'
166+
)
167+
}
168+
if (!effectiveChannelId) {
169+
throw new Error(
170+
'Channel ID is required. Please select a channel or enter a channel ID manually.'
171+
)
172+
}
120173
return {
121174
...commonParams,
122-
serverId: params.serverId,
123-
channelId: params.channelId,
175+
serverId: effectiveServerId,
176+
channelId: effectiveChannelId,
124177
limit: params.limit ? Math.min(Math.max(1, Number(params.limit)), 100) : 10,
125178
}
126179
case 'discord_get_server':
180+
if (!effectiveServerId) {
181+
throw new Error(
182+
'Server ID is required. Please select a server or enter a server ID manually.'
183+
)
184+
}
127185
return {
128186
...commonParams,
129-
serverId: params.serverId,
187+
serverId: effectiveServerId,
130188
}
131189
case 'discord_get_user':
132190
return {
@@ -143,7 +201,9 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
143201
operation: { type: 'string', required: true },
144202
botToken: { type: 'string', required: true },
145203
serverId: { type: 'string', required: false },
204+
manualServerId: { type: 'string', required: false },
146205
channelId: { type: 'string', required: false },
206+
manualChannelId: { type: 'string', required: false },
147207
content: { type: 'string', required: false },
148208
limit: { type: 'number', required: false },
149209
userId: { type: 'string', required: false },

apps/sim/blocks/blocks/elevenlabs.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { ElevenLabsIcon } from '@/components/icons'
2-
import type { ToolResponse } from '@/tools/types'
3-
import type { BlockConfig } from '../types'
4-
5-
interface ElevenLabsBlockResponse extends ToolResponse {
6-
output: {
7-
audioUrl: string
8-
}
9-
}
2+
import type { BlockConfig } from '@/blocks/types'
3+
import type { ElevenLabsBlockResponse } from '@/tools/elevenlabs/types'
104

115
export const ElevenLabsBlock: BlockConfig<ElevenLabsBlockResponse> = {
126
type: 'elevenlabs',

0 commit comments

Comments
 (0)