| 109 | } |
| 110 | |
| 111 | function buildAppToolParams( |
| 112 | toolId: string, |
| 113 | params: Record<string, unknown>, |
| 114 | context: ToolExecutionContext |
| 115 | ): Record<string, unknown> { |
| 116 | const result = { ...params } |
| 117 | |
| 118 | if (toolId === FUNCTION_EXECUTE_TOOL_ID && context.copilotToolExecution) { |
| 119 | const rawTimeoutSeconds = |
| 120 | result.timeout === undefined || result.timeout === null |
| 121 | ? DEFAULT_FUNCTION_EXECUTE_TIMEOUT_SECONDS |
| 122 | : Number(result.timeout) |
| 123 | const timeoutSeconds = |
| 124 | Number.isFinite(rawTimeoutSeconds) && rawTimeoutSeconds > 0 |
| 125 | ? rawTimeoutSeconds |
| 126 | : DEFAULT_FUNCTION_EXECUTE_TIMEOUT_SECONDS |
| 127 | result.timeout = Math.min( |
| 128 | Math.ceil(timeoutSeconds * MILLISECONDS_PER_SECOND), |
| 129 | DEFAULT_EXECUTION_TIMEOUT_MS |
| 130 | ) |
| 131 | } |
| 132 | |
| 133 | if (result.credentialId && !result.credential && !result.oauthCredential) { |
| 134 | result.credential = result.credentialId |
| 135 | } |
| 136 | |
| 137 | result._context = { |
| 138 | ...(typeof result._context === 'object' && result._context !== null |
| 139 | ? (result._context as object) |
| 140 | : {}), |
| 141 | userId: context.userId, |
| 142 | workflowId: context.workflowId, |
| 143 | workspaceId: context.workspaceId, |
| 144 | chatId: context.chatId, |
| 145 | executionId: context.executionId, |
| 146 | runId: context.runId, |
| 147 | copilotToolExecution: context.copilotToolExecution, |
| 148 | requestMode: context.requestMode, |
| 149 | currentAgentId: context.currentAgentId, |
| 150 | enforceCredentialAccess: true, |
| 151 | } |
| 152 | |
| 153 | return result |
| 154 | } |