mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-25 14:58:14 -05:00
Compare commits
38 Commits
fix/copilo
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d63a5cb504 | ||
|
|
8bd5d41723 | ||
|
|
c12931bc50 | ||
|
|
e9c4251c1c | ||
|
|
cc2be33d6b | ||
|
|
45371e521e | ||
|
|
0ce0f98aa5 | ||
|
|
dff1c9d083 | ||
|
|
b09f683072 | ||
|
|
a8bb0db660 | ||
|
|
af82820a28 | ||
|
|
4372841797 | ||
|
|
5e8c843241 | ||
|
|
7bf3d73ee6 | ||
|
|
7ffc11a738 | ||
|
|
be578e2ed7 | ||
|
|
f415e5edc4 | ||
|
|
13a6e6c3fa | ||
|
|
f5ab7f21ae | ||
|
|
bfb6fffe38 | ||
|
|
4fbec0a43f | ||
|
|
585f5e365b | ||
|
|
3792bdd252 | ||
|
|
eb5d1f3e5b | ||
|
|
54ab82c8dd | ||
|
|
f895bf469b | ||
|
|
dd3209af06 | ||
|
|
b6ba3b50a7 | ||
|
|
b304233062 | ||
|
|
57e4b49bd6 | ||
|
|
e12dd204ed | ||
|
|
3d9d9cbc54 | ||
|
|
0f4ec962ad | ||
|
|
4827866f9a | ||
|
|
3e697d9ed9 | ||
|
|
4431a1a484 | ||
|
|
4d1a9a3f22 | ||
|
|
eb07a080fb |
@@ -2508,10 +2508,6 @@ async function validateWorkflowSelectorIds(
|
|||||||
for (const subBlockConfig of blockConfig.subBlocks) {
|
for (const subBlockConfig of blockConfig.subBlocks) {
|
||||||
if (!SELECTOR_TYPES.has(subBlockConfig.type)) continue
|
if (!SELECTOR_TYPES.has(subBlockConfig.type)) continue
|
||||||
|
|
||||||
// Skip oauth-input - credentials are pre-validated before edit application
|
|
||||||
// This allows existing collaborator credentials to remain untouched
|
|
||||||
if (subBlockConfig.type === 'oauth-input') continue
|
|
||||||
|
|
||||||
const subBlockValue = blockData.subBlocks?.[subBlockConfig.id]?.value
|
const subBlockValue = blockData.subBlocks?.[subBlockConfig.id]?.value
|
||||||
if (!subBlockValue) continue
|
if (!subBlockValue) continue
|
||||||
|
|
||||||
@@ -2577,105 +2573,6 @@ async function validateWorkflowSelectorIds(
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-validates oauth-input (credential) values in operations before they are applied.
|
|
||||||
* Removes invalid credential inputs from operations so they are never applied.
|
|
||||||
* Returns validation errors for any removed credentials.
|
|
||||||
*/
|
|
||||||
async function preValidateCredentialInputs(
|
|
||||||
operations: EditWorkflowOperation[],
|
|
||||||
context: { userId: string }
|
|
||||||
): Promise<{ filteredOperations: EditWorkflowOperation[]; errors: ValidationError[] }> {
|
|
||||||
const logger = createLogger('PreValidateCredentials')
|
|
||||||
const errors: ValidationError[] = []
|
|
||||||
|
|
||||||
// Collect all credential values from operations that need validation
|
|
||||||
const credentialInputs: Array<{
|
|
||||||
operationIndex: number
|
|
||||||
blockId: string
|
|
||||||
blockType: string
|
|
||||||
fieldName: string
|
|
||||||
value: string
|
|
||||||
}> = []
|
|
||||||
|
|
||||||
operations.forEach((op, opIndex) => {
|
|
||||||
if (!op.params?.inputs || !op.params?.type) return
|
|
||||||
|
|
||||||
const blockConfig = getBlock(op.params.type)
|
|
||||||
if (!blockConfig) return
|
|
||||||
|
|
||||||
// Find oauth-input subblocks in this block type
|
|
||||||
for (const subBlockConfig of blockConfig.subBlocks) {
|
|
||||||
if (subBlockConfig.type !== 'oauth-input') continue
|
|
||||||
|
|
||||||
const inputValue = op.params.inputs[subBlockConfig.id]
|
|
||||||
if (!inputValue || typeof inputValue !== 'string' || inputValue.trim() === '') continue
|
|
||||||
|
|
||||||
credentialInputs.push({
|
|
||||||
operationIndex: opIndex,
|
|
||||||
blockId: op.block_id,
|
|
||||||
blockType: op.params.type,
|
|
||||||
fieldName: subBlockConfig.id,
|
|
||||||
value: inputValue,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (credentialInputs.length === 0) {
|
|
||||||
return { filteredOperations: operations, errors }
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Pre-validating credential inputs', {
|
|
||||||
credentialCount: credentialInputs.length,
|
|
||||||
userId: context.userId,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Validate all credential IDs at once
|
|
||||||
const allCredentialIds = credentialInputs.map((c) => c.value)
|
|
||||||
const validationResult = await validateSelectorIds('oauth-input', allCredentialIds, context)
|
|
||||||
const invalidSet = new Set(validationResult.invalid)
|
|
||||||
|
|
||||||
if (invalidSet.size === 0) {
|
|
||||||
return { filteredOperations: operations, errors }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deep clone operations so we can modify them
|
|
||||||
const filteredOperations = JSON.parse(JSON.stringify(operations)) as EditWorkflowOperation[]
|
|
||||||
|
|
||||||
// Remove invalid credential inputs from operations
|
|
||||||
for (const credInput of credentialInputs) {
|
|
||||||
if (!invalidSet.has(credInput.value)) continue
|
|
||||||
|
|
||||||
// Remove this credential input from the operation
|
|
||||||
const op = filteredOperations[credInput.operationIndex]
|
|
||||||
if (op.params?.inputs?.[credInput.fieldName]) {
|
|
||||||
delete op.params.inputs[credInput.fieldName]
|
|
||||||
logger.info('Removed invalid credential from operation', {
|
|
||||||
blockId: credInput.blockId,
|
|
||||||
field: credInput.fieldName,
|
|
||||||
invalidValue: credInput.value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add error for LLM feedback
|
|
||||||
const warningInfo = validationResult.warning ? `. ${validationResult.warning}` : ''
|
|
||||||
errors.push({
|
|
||||||
blockId: credInput.blockId,
|
|
||||||
blockType: credInput.blockType,
|
|
||||||
field: credInput.fieldName,
|
|
||||||
value: credInput.value,
|
|
||||||
error: `Invalid credential ID "${credInput.value}" - credential does not exist or user doesn't have access${warningInfo}`,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.warn('Filtered out invalid credentials from operations', {
|
|
||||||
invalidCount: invalidSet.size,
|
|
||||||
errors: errors.map((e) => ({ blockId: e.blockId, field: e.field })),
|
|
||||||
})
|
|
||||||
|
|
||||||
return { filteredOperations, errors }
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getCurrentWorkflowStateFromDb(
|
async function getCurrentWorkflowStateFromDb(
|
||||||
workflowId: string
|
workflowId: string
|
||||||
): Promise<{ workflowState: any; subBlockValues: Record<string, Record<string, any>> }> {
|
): Promise<{ workflowState: any; subBlockValues: Record<string, Record<string, any>> }> {
|
||||||
@@ -2760,28 +2657,12 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, any> = {
|
|||||||
// Get permission config for the user
|
// Get permission config for the user
|
||||||
const permissionConfig = context?.userId ? await getUserPermissionConfig(context.userId) : null
|
const permissionConfig = context?.userId ? await getUserPermissionConfig(context.userId) : null
|
||||||
|
|
||||||
// Pre-validate credential inputs before applying operations
|
|
||||||
// This filters out invalid credentials so they never get applied
|
|
||||||
let operationsToApply = operations
|
|
||||||
const credentialErrors: ValidationError[] = []
|
|
||||||
if (context?.userId) {
|
|
||||||
const { filteredOperations, errors: credErrors } = await preValidateCredentialInputs(
|
|
||||||
operations,
|
|
||||||
{ userId: context.userId }
|
|
||||||
)
|
|
||||||
operationsToApply = filteredOperations
|
|
||||||
credentialErrors.push(...credErrors)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply operations directly to the workflow state
|
// Apply operations directly to the workflow state
|
||||||
const {
|
const {
|
||||||
state: modifiedWorkflowState,
|
state: modifiedWorkflowState,
|
||||||
validationErrors,
|
validationErrors,
|
||||||
skippedItems,
|
skippedItems,
|
||||||
} = applyOperationsToWorkflowState(workflowState, operationsToApply, permissionConfig)
|
} = applyOperationsToWorkflowState(workflowState, operations, permissionConfig)
|
||||||
|
|
||||||
// Add credential validation errors
|
|
||||||
validationErrors.push(...credentialErrors)
|
|
||||||
|
|
||||||
// Get workspaceId for selector validation
|
// Get workspaceId for selector validation
|
||||||
let workspaceId: string | undefined
|
let workspaceId: string | undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user