Skip to content

Commit 78c966f

Browse files
committed
more
1 parent db213c7 commit 78c966f

File tree

3 files changed

+29
-16
lines changed
  • apps/sim/app
    • api/a2a/serve/[agentId]
    • workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components

3 files changed

+29
-16
lines changed

apps/sim/app/api/a2a/serve/[agentId]/route.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createLogger } from '@sim/logger'
55
import { eq } from 'drizzle-orm'
66
import { type NextRequest, NextResponse } from 'next/server'
77
import { v4 as uuidv4 } from 'uuid'
8-
import { A2A_DEFAULT_TIMEOUT } from '@/lib/a2a/constants'
8+
import { A2A_DEFAULT_TIMEOUT, A2A_MAX_HISTORY_LENGTH } from '@/lib/a2a/constants'
99
import { notifyTaskStateChange } from '@/lib/a2a/push-notifications'
1010
import {
1111
createAgentMessage,
@@ -332,6 +332,11 @@ async function handleMessageSend(
332332

333333
history.push(message)
334334

335+
// Truncate history to prevent unbounded JSONB growth
336+
if (history.length > A2A_MAX_HISTORY_LENGTH) {
337+
history.splice(0, history.length - A2A_MAX_HISTORY_LENGTH)
338+
}
339+
335340
if (existingTask) {
336341
await db
337342
.update(a2aTask)
@@ -537,6 +542,11 @@ async function handleMessageStream(
537542

538543
history.push(message)
539544

545+
// Truncate history to prevent unbounded JSONB growth
546+
if (history.length > A2A_MAX_HISTORY_LENGTH) {
547+
history.splice(0, history.length - A2A_MAX_HISTORY_LENGTH)
548+
}
549+
540550
if (existingTask) {
541551
await db
542552
.update(a2aTask)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/a2a/a2a.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,13 @@ export function A2aDeploy({
617617

618618
case 'python':
619619
return requiresAuth
620-
? `import requests
620+
? `import os
621+
import requests
621622
622623
response = requests.post(
623624
"${endpoint}",
624625
headers={
625-
"X-API-Key": SIM_API_KEY,
626+
"X-API-Key": os.environ.get("SIM_API_KEY"),
626627
"Content-Type": "application/json"
627628
},
628629
json=${JSON.stringify(payload, null, 4).replace(/\n/g, '\n ')}
@@ -644,7 +645,7 @@ print(response.json())`
644645
? `const response = await fetch("${endpoint}", {
645646
method: "POST",
646647
headers: {
647-
"X-API-Key": SIM_API_KEY,
648+
"X-API-Key": process.env.SIM_API_KEY,
648649
"Content-Type": "application/json"
649650
},
650651
body: JSON.stringify(${JSON.stringify(payload)})
@@ -666,7 +667,7 @@ console.log(data);`
666667
? `const response = await fetch("${endpoint}", {
667668
method: "POST",
668669
headers: {
669-
"X-API-Key": SIM_API_KEY,
670+
"X-API-Key": process.env.SIM_API_KEY,
670671
"Content-Type": "application/json"
671672
},
672673
body: JSON.stringify(${JSON.stringify(payload)})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/api/api.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ export function ApiDeploy({
125125
${endpoint}`
126126

127127
case 'python':
128-
return `import requests
128+
return `import os
129+
import requests
129130
130131
response = requests.post(
131132
"${endpoint}",
132133
headers={
133-
"X-API-Key": SIM_API_KEY,
134+
"X-API-Key": os.environ.get("SIM_API_KEY"),
134135
"Content-Type": "application/json"
135136
},
136137
json=${JSON.stringify(payload, null, 4).replace(/\n/g, '\n ')}
@@ -142,7 +143,7 @@ print(response.json())`
142143
return `const response = await fetch("${endpoint}", {
143144
method: "POST",
144145
headers: {
145-
"X-API-Key": SIM_API_KEY,
146+
"X-API-Key": process.env.SIM_API_KEY,
146147
"Content-Type": "application/json"
147148
},
148149
body: JSON.stringify(${JSON.stringify(payload)})
@@ -155,7 +156,7 @@ console.log(data);`
155156
return `const response = await fetch("${endpoint}", {
156157
method: "POST",
157158
headers: {
158-
"X-API-Key": SIM_API_KEY,
159+
"X-API-Key": process.env.SIM_API_KEY,
159160
"Content-Type": "application/json"
160161
},
161162
body: JSON.stringify(${JSON.stringify(payload)})
@@ -183,12 +184,13 @@ console.log(data);`
183184
${endpoint}`
184185

185186
case 'python':
186-
return `import requests
187+
return `import os
188+
import requests
187189
188190
response = requests.post(
189191
"${endpoint}",
190192
headers={
191-
"X-API-Key": SIM_API_KEY,
193+
"X-API-Key": os.environ.get("SIM_API_KEY"),
192194
"Content-Type": "application/json"
193195
},
194196
json=${JSON.stringify(payload, null, 4).replace(/\n/g, '\n ')},
@@ -203,7 +205,7 @@ for line in response.iter_lines():
203205
return `const response = await fetch("${endpoint}", {
204206
method: "POST",
205207
headers: {
206-
"X-API-Key": SIM_API_KEY,
208+
"X-API-Key": process.env.SIM_API_KEY,
207209
"Content-Type": "application/json"
208210
},
209211
body: JSON.stringify(${JSON.stringify(payload)})
@@ -222,7 +224,7 @@ while (true) {
222224
return `const response = await fetch("${endpoint}", {
223225
method: "POST",
224226
headers: {
225-
"X-API-Key": SIM_API_KEY,
227+
"X-API-Key": process.env.SIM_API_KEY,
226228
"Content-Type": "application/json"
227229
},
228230
body: JSON.stringify(${JSON.stringify(payload)})
@@ -265,7 +267,7 @@ while (true) {
265267
response = requests.post(
266268
"${endpoint}",
267269
headers={
268-
"X-API-Key": SIM_API_KEY,
270+
"X-API-Key": process.env.SIM_API_KEY,
269271
"Content-Type": "application/json",
270272
"X-Execution-Mode": "async"
271273
},
@@ -279,7 +281,7 @@ print(job) # Contains job_id for status checking`
279281
return `const response = await fetch("${endpoint}", {
280282
method: "POST",
281283
headers: {
282-
"X-API-Key": SIM_API_KEY,
284+
"X-API-Key": process.env.SIM_API_KEY,
283285
"Content-Type": "application/json",
284286
"X-Execution-Mode": "async"
285287
},
@@ -293,7 +295,7 @@ console.log(job); // Contains job_id for status checking`
293295
return `const response = await fetch("${endpoint}", {
294296
method: "POST",
295297
headers: {
296-
"X-API-Key": SIM_API_KEY,
298+
"X-API-Key": process.env.SIM_API_KEY,
297299
"Content-Type": "application/json",
298300
"X-Execution-Mode": "async"
299301
},

0 commit comments

Comments
 (0)