Skip to content

Commit 521316b

Browse files
committed
Lint
1 parent adf8c22 commit 521316b

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

apps/sim/app/api/workflows/[id]/state/route.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { getSession } from '@/lib/auth'
55
import { createLogger } from '@/lib/logs/console/logger'
66
import { getUserEntityPermissions } from '@/lib/permissions/utils'
77
import { saveWorkflowToNormalizedTables } from '@/lib/workflows/db-helpers'
8+
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
89
import { db } from '@/db'
910
import { workflow } from '@/db/schema'
10-
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
1111

1212
const logger = createLogger('WorkflowStateAPI')
1313

@@ -229,10 +229,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
229229
const elapsed = Date.now() - startTime
230230
logger.info(`[${requestId}] Successfully saved workflow ${workflowId} state in ${elapsed}ms`)
231231

232-
return NextResponse.json(
233-
{ success: true, warnings },
234-
{ status: 200 }
235-
)
232+
return NextResponse.json({ success: true, warnings }, { status: 200 })
236233
} catch (error: any) {
237234
const elapsed = Date.now() - startTime
238235
logger.error(
@@ -241,7 +238,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
241238
)
242239

243240
if (error instanceof z.ZodError) {
244-
return NextResponse.json({ error: 'Invalid request body', details: error.errors }, { status: 400 })
241+
return NextResponse.json(
242+
{ error: 'Invalid request body', details: error.errors },
243+
{ status: 400 }
244+
)
245245
}
246246

247247
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })

apps/sim/app/api/workflows/[id]/yaml/route.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import { type NextRequest, NextResponse } from 'next/server'
44
import { z } from 'zod'
55
import { env } from '@/lib/env'
66
import { createLogger } from '@/lib/logs/console/logger'
7-
import { db } from '@/db'
8-
import { workflow as workflowTable, workflowCheckpoints, customTools } from '@/db/schema'
7+
import { simAgentClient } from '@/lib/sim-agent'
8+
import {
9+
loadWorkflowFromNormalizedTables,
10+
saveWorkflowToNormalizedTables,
11+
} from '@/lib/workflows/db-helpers'
12+
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
13+
import { getUserId } from '@/app/api/auth/oauth/utils'
914
import { getAllBlocks, getBlock } from '@/blocks'
1015
import type { BlockConfig } from '@/blocks/types'
11-
import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/workflow/utils'
1216
import { resolveOutputType } from '@/blocks/utils'
13-
import { getUserId } from '@/app/api/auth/oauth/utils'
14-
import { simAgentClient } from '@/lib/sim-agent'
15-
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
16-
import { loadWorkflowFromNormalizedTables, saveWorkflowToNormalizedTables } from '@/lib/workflows/db-helpers'
17+
import { db } from '@/db'
18+
import { customTools, workflowCheckpoints, workflow as workflowTable } from '@/db/schema'
19+
import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/workflow/utils'
1720

1821
const logger = createLogger('YamlWorkflowAPI')
1922

@@ -35,9 +38,7 @@ function updateBlockReferences(
3538
// Replace references in string values
3639
for (const [oldId, newId] of blockIdMapping.entries()) {
3740
if (value.includes(oldId)) {
38-
value = value
39-
.replaceAll(`<${oldId}.`, `<${newId}.`)
40-
.replaceAll(`%${oldId}.`, `%${newId}.`)
41+
value = value.replaceAll(`<${oldId}.`, `<${newId}.`).replaceAll(`%${oldId}.`, `%${newId}.`)
4142
}
4243
}
4344
return value
@@ -171,7 +172,11 @@ async function upsertCustomToolsFromBlocks(
171172
tool.schema.function.name &&
172173
typeof tool.code === 'string'
173174
) {
174-
collected.push({ title: tool.title || tool.schema.function.name, schema: tool.schema, code: tool.code })
175+
collected.push({
176+
title: tool.title || tool.schema.function.name,
177+
schema: tool.schema,
178+
code: tool.code,
179+
})
175180
}
176181
}
177182
}
@@ -186,10 +191,7 @@ async function upsertCustomToolsFromBlocks(
186191
}
187192

188193
// Load existing user's tools
189-
const existing = await db
190-
.select()
191-
.from(customTools)
192-
.where(eq(customTools.userId, userId))
194+
const existing = await db.select().from(customTools).where(eq(customTools.userId, userId))
193195

194196
const existingByName = new Map<string, (typeof existing)[number]>()
195197
for (const row of existing) {
@@ -325,8 +327,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
325327

326328
const conversionResult = await conversionResponse.json()
327329

328-
const workflowState =
329-
conversionResult.workflowState || (conversionResult.diff && conversionResult.diff.proposedState)
330+
const workflowState = conversionResult.workflowState || conversionResult.diff?.proposedState
330331

331332
if (!conversionResult.success || !workflowState) {
332333
logger.error(`[${requestId}] YAML conversion failed`, {
@@ -639,9 +640,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
639640
newWorkflowState.blocks
640641
)
641642
if (sanitationWarnings.length > 0) {
642-
logger.warn(
643-
`[${requestId}] Tool sanitation produced ${sanitationWarnings.length} warning(s)`
644-
)
643+
logger.warn(`[${requestId}] Tool sanitation produced ${sanitationWarnings.length} warning(s)`)
645644
}
646645
newWorkflowState.blocks = sanitizedBlocks
647646

apps/sim/lib/workflows/db-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { eq } from 'drizzle-orm'
22
import { createLogger } from '@/lib/logs/console/logger'
3+
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
34
import { db } from '@/db'
45
import { workflow, workflowBlocks, workflowEdges, workflowSubflows } from '@/db/schema'
56
import type { WorkflowState } from '@/stores/workflows/workflow/types'
67
import { SUBFLOW_TYPES } from '@/stores/workflows/workflow/types'
7-
import { sanitizeAgentToolsInBlocks } from '@/lib/workflows/validation'
88

99
const logger = createLogger('WorkflowDBHelpers')
1010

apps/sim/lib/workflows/validation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ function isValidCustomToolSchema(tool: any): boolean {
2424
}
2525
}
2626

27-
export function sanitizeAgentToolsInBlocks(
27+
export function sanitizeAgentToolsInBlocks(blocks: Record<string, any>): {
2828
blocks: Record<string, any>
29-
): { blocks: Record<string, any>; warnings: string[] } {
29+
warnings: string[]
30+
} {
3031
const warnings: string[] = []
3132

3233
// Shallow clone to avoid mutating callers
@@ -46,7 +47,9 @@ export function sanitizeAgentToolsInBlocks(
4647
try {
4748
value = JSON.parse(value)
4849
} catch (_e) {
49-
warnings.push(`Block ${block.name || blockId}: invalid tools JSON; resetting tools to empty array`)
50+
warnings.push(
51+
`Block ${block.name || blockId}: invalid tools JSON; resetting tools to empty array`
52+
)
5053
value = []
5154
}
5255
}
@@ -103,4 +106,4 @@ export function sanitizeAgentToolsInBlocks(
103106
}
104107

105108
return { blocks: sanitizedBlocks, warnings }
106-
}
109+
}

0 commit comments

Comments
 (0)