Skip to content

Commit d6549d8

Browse files
committed
Lint
1 parent 6efb116 commit d6549d8

File tree

15 files changed

+283
-261
lines changed

15 files changed

+283
-261
lines changed
Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,85 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
3-
import { createLogger } from '@/lib/logs/console/logger'
43
import { authenticateCopilotRequestSessionOnly } from '@/lib/copilot/auth'
5-
6-
// Import server-side tool implementations from lib
7-
import { searchDocsTool } from '@/lib/copilot/tools/server-tools/docs/search-docs'
84
import { getBlocksAndToolsTool } from '@/lib/copilot/tools/server-tools/blocks/get-blocks-and-tools'
95
import { getBlocksMetadataTool } from '@/lib/copilot/tools/server-tools/blocks/get-blocks-metadata'
10-
import { getEnvironmentVariablesTool } from '@/lib/copilot/tools/server-tools/user/get-environment-variables'
11-
import { getOAuthCredentialsTool } from '@/lib/copilot/tools/server-tools/user/get-oauth-credentials'
6+
// Import server-side tool implementations from lib
7+
import { searchDocsTool } from '@/lib/copilot/tools/server-tools/docs/search-docs'
128
import { listGDriveFilesTool } from '@/lib/copilot/tools/server-tools/gdrive/list-gdrive-files'
139
import { readGDriveFileTool } from '@/lib/copilot/tools/server-tools/gdrive/read-gdrive-file'
1410
import { gdriveRequestAccessServerTool } from '@/lib/copilot/tools/server-tools/other/gdrive-request-access'
1511
import { makeApiRequestTool } from '@/lib/copilot/tools/server-tools/other/make-api-request'
1612
import { onlineSearchTool } from '@/lib/copilot/tools/server-tools/other/online-search'
17-
import { getWorkflowConsoleTool } from '@/lib/copilot/tools/server-tools/workflow/get-workflow-console'
13+
import { getEnvironmentVariablesTool } from '@/lib/copilot/tools/server-tools/user/get-environment-variables'
14+
import { getOAuthCredentialsTool } from '@/lib/copilot/tools/server-tools/user/get-oauth-credentials'
1815
import { buildWorkflowTool } from '@/lib/copilot/tools/server-tools/workflow/build-workflow'
1916
import { editWorkflowTool } from '@/lib/copilot/tools/server-tools/workflow/edit-workflow'
17+
import { getWorkflowConsoleTool } from '@/lib/copilot/tools/server-tools/workflow/get-workflow-console'
18+
import { createLogger } from '@/lib/logs/console/logger'
2019

2120
const logger = createLogger('CopilotToolsExecuteAPI')
2221

2322
const Schema = z.object({
24-
methodId: z.string().min(1),
25-
params: z.record(z.any()).optional().default({}),
23+
methodId: z.string().min(1),
24+
params: z.record(z.any()).optional().default({}),
2625
})
2726

2827
const HANDLERS: Record<string, (params: any) => Promise<any>> = {
29-
search_documentation: (p) => searchDocsTool.execute(p),
30-
get_blocks_and_tools: (p) => getBlocksAndToolsTool.execute(p),
31-
get_blocks_metadata: (p) => getBlocksMetadataTool.execute(p),
32-
get_environment_variables: (p) => getEnvironmentVariablesTool.execute(p),
33-
get_oauth_credentials: (p) => getOAuthCredentialsTool.execute(p),
34-
list_gdrive_files: (p) => listGDriveFilesTool.execute(p),
35-
read_gdrive_file: (p) => readGDriveFileTool.execute(p),
36-
gdrive_request_access: (p) => gdriveRequestAccessServerTool.execute(p),
37-
make_api_request: (p) => makeApiRequestTool.execute(p),
38-
search_online: (p) => onlineSearchTool.execute(p),
39-
get_workflow_console: (p) => getWorkflowConsoleTool.execute(p),
40-
build_workflow: (p) => buildWorkflowTool.execute(p),
41-
edit_workflow: (p) => editWorkflowTool.execute(p),
28+
search_documentation: (p) => searchDocsTool.execute(p),
29+
get_blocks_and_tools: (p) => getBlocksAndToolsTool.execute(p),
30+
get_blocks_metadata: (p) => getBlocksMetadataTool.execute(p),
31+
get_environment_variables: (p) => getEnvironmentVariablesTool.execute(p),
32+
get_oauth_credentials: (p) => getOAuthCredentialsTool.execute(p),
33+
list_gdrive_files: (p) => listGDriveFilesTool.execute(p),
34+
read_gdrive_file: (p) => readGDriveFileTool.execute(p),
35+
gdrive_request_access: (p) => gdriveRequestAccessServerTool.execute(p),
36+
make_api_request: (p) => makeApiRequestTool.execute(p),
37+
search_online: (p) => onlineSearchTool.execute(p),
38+
get_workflow_console: (p) => getWorkflowConsoleTool.execute(p),
39+
build_workflow: (p) => buildWorkflowTool.execute(p),
40+
edit_workflow: (p) => editWorkflowTool.execute(p),
4241
}
4342

4443
export async function POST(req: NextRequest) {
45-
const requestId = crypto.randomUUID()
46-
const start = Date.now()
47-
try {
48-
// Require session
49-
const sessionAuth = await authenticateCopilotRequestSessionOnly()
50-
if (!sessionAuth.isAuthenticated) {
51-
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
52-
}
44+
const requestId = crypto.randomUUID()
45+
const start = Date.now()
46+
try {
47+
// Require session
48+
const sessionAuth = await authenticateCopilotRequestSessionOnly()
49+
if (!sessionAuth.isAuthenticated) {
50+
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
51+
}
5352

54-
const body = await req.json()
55-
const { methodId, params } = Schema.parse(body)
53+
const body = await req.json()
54+
const { methodId, params } = Schema.parse(body)
5655

57-
const handler = HANDLERS[methodId]
58-
if (!handler) {
59-
logger.warn(`[${requestId}] Unknown methodId`, { methodId })
60-
return NextResponse.json(
61-
{ success: false, error: `Unknown method: ${methodId}` },
62-
{ status: 400 }
63-
)
64-
}
56+
const handler = HANDLERS[methodId]
57+
if (!handler) {
58+
logger.warn(`[${requestId}] Unknown methodId`, { methodId })
59+
return NextResponse.json(
60+
{ success: false, error: `Unknown method: ${methodId}` },
61+
{ status: 400 }
62+
)
63+
}
6564

66-
logger.info(`[${requestId}] Executing tool`, {
67-
methodId,
68-
paramsKeys: Object.keys(params || {}),
69-
})
65+
logger.info(`[${requestId}] Executing tool`, {
66+
methodId,
67+
paramsKeys: Object.keys(params || {}),
68+
})
7069

71-
const result = await handler(params)
72-
const duration = Date.now() - start
73-
logger.info(`[${requestId}] Tool executed`, { methodId, success: result?.success, duration })
70+
const result = await handler(params)
71+
const duration = Date.now() - start
72+
logger.info(`[${requestId}] Tool executed`, { methodId, success: result?.success, duration })
7473

75-
return NextResponse.json(result, { status: result?.success ? 200 : 400 })
76-
} catch (e) {
77-
logger.error('Execute failed', { error: e instanceof Error ? e.message : 'Unknown error' })
78-
if (e instanceof z.ZodError) {
79-
return NextResponse.json(
80-
{ success: false, error: e.errors.map((er) => er.message).join(', ') },
81-
{ status: 400 }
82-
)
83-
}
84-
return NextResponse.json({ success: false, error: 'Internal server error' }, { status: 500 })
85-
}
86-
}
74+
return NextResponse.json(result, { status: result?.success ? 200 : 400 })
75+
} catch (e) {
76+
logger.error('Execute failed', { error: e instanceof Error ? e.message : 'Unknown error' })
77+
if (e instanceof z.ZodError) {
78+
return NextResponse.json(
79+
{ success: false, error: e.errors.map((er) => er.message).join(', ') },
80+
{ status: 400 }
81+
)
82+
}
83+
return NextResponse.json({ success: false, error: 'Internal server error' }, { status: 500 })
84+
}
85+
}

apps/sim/app/api/yaml/diff/create/route.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,17 @@ export async function POST(request: NextRequest) {
153153
const nonExistentEdgeRef = /references non-existent block '([^']+)'/i.test(errorText)
154154
if (nonExistentEdgeRef && currentWorkflowState && Array.isArray(currentWorkflowState.edges)) {
155155
try {
156-
const missingIds = [...errorText.matchAll(/references non-existent block '([^']+)'/gi)].map(
157-
(m) => m[1]
158-
)
156+
const missingIds = [
157+
...errorText.matchAll(/references non-existent block '([^']+)'/gi),
158+
].map((m) => m[1])
159159
const existingIds = new Set(Object.keys(currentWorkflowState.blocks || {}))
160160
// Remove edges whose source or target is missing from current blocks or includes missing IDs
161161
const originalEdgeCount = currentWorkflowState.edges.length
162162
currentWorkflowState.edges = currentWorkflowState.edges.filter((e: any) => {
163163
const srcOk = e?.source && existingIds.has(e.source)
164164
const tgtOk = e?.target && existingIds.has(e.target)
165-
const hitsMissing = missingIds.includes(String(e?.source)) || missingIds.includes(String(e?.target))
165+
const hitsMissing =
166+
missingIds.includes(String(e?.source)) || missingIds.includes(String(e?.target))
166167
return srcOk && tgtOk && !hitsMissing
167168
})
168169
logger.warn(`[${requestId}] Stripped invalid edges`, {

apps/sim/lib/copilot/tools/client-tools/display-only.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { BaseTool } from '@/lib/copilot/tools/base-tool'
2-
import type { CopilotToolCall, ToolExecuteResult, ToolExecutionOptions, ToolMetadata } from '@/lib/copilot/tools/types'
2+
import type {
3+
CopilotToolCall,
4+
ToolExecuteResult,
5+
ToolExecutionOptions,
6+
ToolMetadata,
7+
} from '@/lib/copilot/tools/types'
38

49
function makeDisplayOnlyTool(
510
id: string,
@@ -14,7 +19,10 @@ function makeDisplayOnlyTool(
1419
schema: { name: id, description },
1520
requiresInterrupt: false,
1621
}
17-
async execute(toolCall: CopilotToolCall, options?: ToolExecutionOptions): Promise<ToolExecuteResult> {
22+
async execute(
23+
toolCall: CopilotToolCall,
24+
options?: ToolExecutionOptions
25+
): Promise<ToolExecuteResult> {
1826
options?.onStateChange?.('success')
1927
return { success: true, data: toolCall.parameters || toolCall.input || {} }
2028
}
@@ -67,4 +75,4 @@ export const GetBlockBestPracticesTool = makeDisplayOnlyTool(
6775
aborted: { displayName: 'Recommendations review aborted', icon: 'x' },
6876
},
6977
'Get best practices and usage guidelines for workflow blocks and tools'
70-
)
78+
)

apps/sim/lib/copilot/tools/client-tools/gdrive-request-access.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { BaseTool } from '@/lib/copilot/tools/base-tool'
2+
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
23
import type {
34
CopilotToolCall,
45
ToolExecuteResult,
56
ToolExecutionOptions,
67
ToolMetadata,
78
} from '@/lib/copilot/tools/types'
89
import { createLogger } from '@/lib/logs/console/logger'
9-
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
1010

1111
export class GDriveRequestAccessTool extends BaseTool {
1212
static readonly id = 'gdrive_request_access'

apps/sim/lib/copilot/tools/client-tools/get-environment-variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import { BaseTool } from '@/lib/copilot/tools/base-tool'
6+
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
67
import type {
78
CopilotToolCall,
89
ToolExecuteResult,
@@ -11,7 +12,6 @@ import type {
1112
} from '@/lib/copilot/tools/types'
1213
import { createLogger } from '@/lib/logs/console/logger'
1314
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
14-
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
1515

1616
export class GetEnvironmentVariablesClientTool extends BaseTool {
1717
static readonly id = 'get_environment_variables'

apps/sim/lib/copilot/tools/client-tools/get-oauth-credentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44

55
import { BaseTool } from '@/lib/copilot/tools/base-tool'
6+
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
67
import type {
78
CopilotToolCall,
89
ToolExecuteResult,
910
ToolExecutionOptions,
1011
ToolMetadata,
1112
} from '@/lib/copilot/tools/types'
1213
import { createLogger } from '@/lib/logs/console/logger'
13-
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
1414

1515
export class GetOAuthCredentialsClientTool extends BaseTool {
1616
static readonly id = 'get_oauth_credentials'

apps/sim/lib/copilot/tools/client-tools/online-search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44

55
import { BaseTool } from '@/lib/copilot/tools/base-tool'
6+
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
67
import type {
78
CopilotToolCall,
89
ToolExecuteResult,
910
ToolExecutionOptions,
1011
ToolMetadata,
1112
} from '@/lib/copilot/tools/types'
1213
import { createLogger } from '@/lib/logs/console/logger'
13-
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
1414

1515
export class OnlineSearchClientTool extends BaseTool {
1616
static readonly id = 'search_online'

apps/sim/lib/copilot/tools/client-tools/plan.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { BaseTool } from '@/lib/copilot/tools/base-tool'
2-
import type { CopilotToolCall, ToolExecuteResult, ToolExecutionOptions, ToolMetadata } from '@/lib/copilot/tools/types'
2+
import type {
3+
CopilotToolCall,
4+
ToolExecuteResult,
5+
ToolExecutionOptions,
6+
ToolMetadata,
7+
} from '@/lib/copilot/tools/types'
38

49
export class PlanClientTool extends BaseTool {
510
static readonly id = 'plan'
@@ -19,8 +24,11 @@ export class PlanClientTool extends BaseTool {
1924
requiresInterrupt: false,
2025
}
2126

22-
async execute(toolCall: CopilotToolCall, options?: ToolExecutionOptions): Promise<ToolExecuteResult> {
27+
async execute(
28+
toolCall: CopilotToolCall,
29+
options?: ToolExecutionOptions
30+
): Promise<ToolExecuteResult> {
2331
options?.onStateChange?.('success')
2432
return { success: true, data: toolCall.parameters || toolCall.input || {} }
2533
}
26-
}
34+
}

apps/sim/lib/copilot/tools/client-tools/read-gdrive-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*/
44

55
import { BaseTool } from '@/lib/copilot/tools/base-tool'
6+
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
67
import type {
78
CopilotToolCall,
89
ToolExecuteResult,
910
ToolExecutionOptions,
1011
ToolMetadata,
1112
} from '@/lib/copilot/tools/types'
1213
import { createLogger } from '@/lib/logs/console/logger'
13-
import { postToExecuteAndComplete } from '@/lib/copilot/tools/client-tools/client-utils'
1414

1515
export class ReadGDriveFileClientTool extends BaseTool {
1616
static readonly id = 'read_gdrive_file'

apps/sim/lib/copilot/tools/client-tools/reason.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { BaseTool } from '@/lib/copilot/tools/base-tool'
2-
import type { CopilotToolCall, ToolExecuteResult, ToolExecutionOptions, ToolMetadata } from '@/lib/copilot/tools/types'
2+
import type {
3+
CopilotToolCall,
4+
ToolExecuteResult,
5+
ToolExecutionOptions,
6+
ToolMetadata,
7+
} from '@/lib/copilot/tools/types'
38

49
export class ReasonClientTool extends BaseTool {
510
static readonly id = 'reason'
@@ -19,8 +24,11 @@ export class ReasonClientTool extends BaseTool {
1924
requiresInterrupt: false,
2025
}
2126

22-
async execute(toolCall: CopilotToolCall, options?: ToolExecutionOptions): Promise<ToolExecuteResult> {
27+
async execute(
28+
toolCall: CopilotToolCall,
29+
options?: ToolExecutionOptions
30+
): Promise<ToolExecuteResult> {
2331
options?.onStateChange?.('success')
2432
return { success: true, data: toolCall.parameters || toolCall.input || {} }
2533
}
26-
}
34+
}

0 commit comments

Comments
 (0)