Skip to content

Commit a63f3a3

Browse files
authored
improvement(copilot): added session context checks in copilot tool calls (#1466)
* improvement(copilot): added session context checks in copilot tool calls * remove extraneous comments, remove the ability to view copilot API keys after creation * updated skeleton --------- Co-authored-by: waleed <waleed>
1 parent 3ff6509 commit a63f3a3

File tree

18 files changed

+248
-161
lines changed

18 files changed

+248
-161
lines changed

apps/sim/app/api/copilot/api-keys/generate/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export async function POST(req: NextRequest) {
1515
// Move environment variable access inside the function
1616
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
1717

18+
await req.json().catch(() => ({}))
19+
1820
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/generate`, {
1921
method: 'POST',
2022
headers: {
@@ -31,14 +33,14 @@ export async function POST(req: NextRequest) {
3133
)
3234
}
3335

34-
const data = (await res.json().catch(() => null)) as { apiKey?: string } | null
36+
const data = (await res.json().catch(() => null)) as { apiKey?: string; id?: string } | null
3537

3638
if (!data?.apiKey) {
3739
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
3840
}
3941

4042
return NextResponse.json(
41-
{ success: true, key: { id: 'new', apiKey: data.apiKey } },
43+
{ success: true, key: { id: data?.id || 'new', apiKey: data.apiKey } },
4244
{ status: 201 }
4345
)
4446
} catch (error) {

apps/sim/app/api/copilot/api-keys/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export async function GET(request: NextRequest) {
3333
return NextResponse.json({ error: 'Invalid response from Sim Agent' }, { status: 500 })
3434
}
3535

36-
const keys = apiKeys
36+
const keys = apiKeys.map((k) => {
37+
const value = typeof k.apiKey === 'string' ? k.apiKey : ''
38+
const last6 = value.slice(-6)
39+
const displayKey = `•••••${last6}`
40+
return { id: k.id, displayKey }
41+
})
3742

3843
return NextResponse.json({ keys }, { status: 200 })
3944
} catch (error) {

apps/sim/app/api/copilot/execute-copilot-server-tool/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function POST(req: NextRequest) {
3434
const { toolName, payload } = ExecuteSchema.parse(body)
3535

3636
logger.info(`[${tracker.requestId}] Executing server tool`, { toolName })
37-
const result = await routeExecution(toolName, payload)
37+
const result = await routeExecution(toolName, payload, { userId })
3838

3939
try {
4040
const resultPreview = JSON.stringify(result).slice(0, 300)

apps/sim/app/api/copilot/tools/mark-complete/route.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import { SIM_AGENT_API_URL_DEFAULT } from '@/lib/sim-agent/constants'
1313

1414
const logger = createLogger('CopilotMarkToolCompleteAPI')
1515

16-
// Sim Agent API configuration
1716
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
1817

19-
// Schema for mark-complete request
2018
const MarkCompleteSchema = z.object({
2119
id: z.string(),
2220
name: z.string(),

apps/sim/app/api/yaml/autolayout/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818

1919
const logger = createLogger('YamlAutoLayoutAPI')
2020

21-
// Sim Agent API configuration
2221
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
2322

2423
const AutoLayoutRequestSchema = z.object({

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919

2020
const logger = createLogger('YamlDiffCreateAPI')
2121

22-
// Sim Agent API configuration
2322
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
2423

2524
const CreateDiffRequestSchema = z.object({

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818

1919
const logger = createLogger('YamlDiffMergeAPI')
2020

21-
// Sim Agent API configuration
2221
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
2322

2423
const MergeDiffRequestSchema = z.object({

apps/sim/app/api/yaml/generate/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/w
1111

1212
const logger = createLogger('YamlGenerateAPI')
1313

14-
// Sim Agent API configuration
1514
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
1615

1716
const GenerateRequestSchema = z.object({

apps/sim/app/api/yaml/health/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { generateRequestId } from '@/lib/utils'
66

77
const logger = createLogger('YamlHealthAPI')
88

9-
// Sim Agent API configuration
109
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
1110

1211
export async function GET() {

apps/sim/app/api/yaml/parse/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/w
1111

1212
const logger = createLogger('YamlParseAPI')
1313

14-
// Sim Agent API configuration
1514
const SIM_AGENT_API_URL = env.SIM_AGENT_API_URL || SIM_AGENT_API_URL_DEFAULT
1615

1716
const ParseRequestSchema = z.object({

0 commit comments

Comments
 (0)