Skip to content

Commit cc790aa

Browse files
committed
fix agent tool input
1 parent 94d5268 commit cc790aa

File tree

4 files changed

+13
-101
lines changed

4 files changed

+13
-101
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ import {
2424
getMcpToolIssue as validateMcpTool,
2525
} from '@/lib/mcp/tool-validation'
2626
import type { McpToolSchema } from '@/lib/mcp/types'
27-
import {
28-
getCanonicalScopesForProvider,
29-
getProviderIdFromServiceId,
30-
type OAuthProvider,
31-
type OAuthService,
32-
} from '@/lib/oauth'
27+
import { getProviderIdFromServiceId, type OAuthProvider, type OAuthService } from '@/lib/oauth'
3328
import { extractInputFieldsFromBlocks } from '@/lib/workflows/input-format'
3429
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
3530
import {
@@ -1414,16 +1409,6 @@ export const ToolInput = memo(function ToolInput({
14141409
isToolAlreadySelected,
14151410
])
14161411

1417-
const toolRequiresOAuth = (toolId: string): boolean => {
1418-
const toolParams = getToolParametersConfig(toolId)
1419-
return toolParams?.toolConfig?.oauth?.required || false
1420-
}
1421-
1422-
const getToolOAuthConfig = (toolId: string) => {
1423-
const toolParams = getToolParametersConfig(toolId)
1424-
return toolParams?.toolConfig?.oauth
1425-
}
1426-
14271412
return (
14281413
<div className='w-full space-y-[8px]'>
14291414
<Combobox
@@ -1537,16 +1522,11 @@ export const ToolInput = memo(function ToolInput({
15371522
? subBlocksResult!.subBlocks
15381523
: []
15391524

1540-
const requiresOAuth =
1541-
!isCustomTool && !isMcpTool && currentToolId && toolRequiresOAuth(currentToolId)
1542-
const oauthConfig =
1543-
!isCustomTool && !isMcpTool && currentToolId ? getToolOAuthConfig(currentToolId) : null
1544-
15451525
const hasOperations = !isCustomTool && !isMcpTool && hasMultipleOperations(tool.type)
15461526
const hasParams = useSubBlocks
15471527
? displaySubBlocks.length > 0
15481528
: displayParams.filter((param) => evaluateParameterCondition(param, tool)).length > 0
1549-
const hasToolBody = hasOperations || (requiresOAuth && oauthConfig) || hasParams
1529+
const hasToolBody = hasOperations || hasParams
15501530

15511531
const isExpandedForDisplay = hasToolBody
15521532
? isPreview
@@ -1746,39 +1726,6 @@ export const ToolInput = memo(function ToolInput({
17461726
{(() => {
17471727
const renderedElements: React.ReactNode[] = []
17481728

1749-
const showOAuth =
1750-
requiresOAuth && oauthConfig && tool.params?.authMethod !== 'bot_token'
1751-
1752-
const renderOAuthAccount = (): React.ReactNode => {
1753-
if (!showOAuth || !oauthConfig) return null
1754-
const credentialSubBlock = toolBlock?.subBlocks?.find(
1755-
(s) => s.type === 'oauth-input'
1756-
)
1757-
return (
1758-
<div key='oauth-account' className='relative min-w-0 space-y-[6px]'>
1759-
<div className='font-medium text-[13px] text-[var(--text-primary)]'>
1760-
{credentialSubBlock?.title || 'Account'}{' '}
1761-
<span className='ml-0.5'>*</span>
1762-
</div>
1763-
<div className='w-full min-w-0'>
1764-
<ToolCredentialSelector
1765-
value={tool.params?.credential || ''}
1766-
onChange={(value: string) =>
1767-
handleParamChange(toolIndex, 'credential', value)
1768-
}
1769-
provider={oauthConfig.provider as OAuthProvider}
1770-
requiredScopes={
1771-
credentialSubBlock?.requiredScopes ||
1772-
getCanonicalScopesForProvider(oauthConfig.provider)
1773-
}
1774-
serviceId={oauthConfig.provider}
1775-
disabled={disabled}
1776-
/>
1777-
</div>
1778-
</div>
1779-
)
1780-
}
1781-
17821729
const renderSubBlock = (sb: BlockSubBlockConfig): React.ReactNode => {
17831730
const effectiveParamId = sb.id
17841731
const canonicalId = toolCanonicalIndex?.canonicalIdBySubBlockId[sb.id]
@@ -1848,44 +1795,8 @@ export const ToolInput = memo(function ToolInput({
18481795
})
18491796
)
18501797

1851-
type RenderItem =
1852-
| { kind: 'subblock'; sb: BlockSubBlockConfig }
1853-
| { kind: 'oauth' }
1854-
1855-
const renderOrder: RenderItem[] = displaySubBlocks.map((sb) => ({
1856-
kind: 'subblock' as const,
1857-
sb,
1858-
}))
1859-
1860-
if (showOAuth) {
1861-
const credentialIdx = allBlockSubBlocks.findIndex(
1862-
(sb) => sb.type === 'oauth-input'
1863-
)
1864-
if (credentialIdx >= 0) {
1865-
const sbPositions = new Map(allBlockSubBlocks.map((sb, i) => [sb.id, i]))
1866-
const insertAt = renderOrder.findIndex(
1867-
(item) =>
1868-
item.kind === 'subblock' &&
1869-
(sbPositions.get(item.sb.id) ?? Number.POSITIVE_INFINITY) >
1870-
credentialIdx
1871-
)
1872-
if (insertAt === -1) {
1873-
renderOrder.push({ kind: 'oauth' })
1874-
} else {
1875-
renderOrder.splice(insertAt, 0, { kind: 'oauth' })
1876-
}
1877-
} else {
1878-
renderOrder.unshift({ kind: 'oauth' })
1879-
}
1880-
}
1881-
1882-
for (const item of renderOrder) {
1883-
if (item.kind === 'oauth') {
1884-
const el = renderOAuthAccount()
1885-
if (el) renderedElements.push(el)
1886-
} else {
1887-
renderedElements.push(renderSubBlock(item.sb))
1888-
}
1798+
for (const sb of displaySubBlocks) {
1799+
renderedElements.push(renderSubBlock(sb))
18891800
}
18901801

18911802
const uncoveredParams = displayParams.filter(
@@ -1924,11 +1835,6 @@ export const ToolInput = memo(function ToolInput({
19241835
)
19251836
}
19261837

1927-
{
1928-
const el = renderOAuthAccount()
1929-
if (el) renderedElements.push(el)
1930-
}
1931-
19321838
const filteredParams = displayParams.filter((param) =>
19331839
evaluateParameterCondition(param, tool)
19341840
)

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ export class AgentBlockHandler implements BlockHandler {
10041004
responseFormat,
10051005
workflowId: ctx.workflowId,
10061006
workspaceId: ctx.workspaceId,
1007+
userId: ctx.userId,
10071008
stream: streaming,
10081009
messages: messages?.map(({ executionId, ...msg }) => msg),
10091010
environmentVariables: ctx.environmentVariables || {},

apps/sim/tools/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ export async function executeTool(
298298
throw new Error(`Tool not found: ${toolId}`)
299299
}
300300

301-
// If we have a credential parameter, fetch the access token
301+
if (contextParams.oauthCredential) {
302+
contextParams.credential = contextParams.oauthCredential
303+
}
304+
302305
if (contextParams.credential) {
303306
logger.info(
304307
`[${requestId}] Tool ${toolId} needs access token for credential: ${contextParams.credential}`
@@ -330,7 +333,7 @@ export async function executeTool(
330333
const tokenHeaders: Record<string, string> = { 'Content-Type': 'application/json' }
331334
if (typeof window === 'undefined') {
332335
try {
333-
const internalToken = await generateInternalToken()
336+
const internalToken = await generateInternalToken(userId)
334337
tokenHeaders.Authorization = `Bearer ${internalToken}`
335338
} catch (_e) {
336339
// Swallow token generation errors; the request will fail and be reported upstream

apps/sim/tools/params.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,10 @@ export function getSubBlocksForToolInput(
942942
// Infer from structural checks
943943
if (STRUCTURAL_SUBBLOCK_IDS.has(sb.id)) {
944944
visibility = 'hidden'
945-
} else if (AUTH_SUBBLOCK_TYPES.has(sb.type)) {
945+
} else if (AUTH_SUBBLOCK_TYPES.has(sb.type) && sb.canonicalParamId !== 'oauthCredential') {
946946
visibility = 'hidden'
947+
} else if (sb.canonicalParamId === 'oauthCredential') {
948+
visibility = 'user-only'
947949
} else if (
948950
sb.password &&
949951
(sb.id === 'botToken' || sb.id === 'accessToken' || sb.id === 'apiKey')

0 commit comments

Comments
 (0)