mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
Abstract timeout and memory
This commit is contained in:
@@ -20,14 +20,13 @@ const DeployRequestSchema = z.object({
|
||||
region: z.string().min(1, 'AWS Region is required'),
|
||||
functionName: z.string().min(1, 'Function name is required'),
|
||||
handler: z.string().optional(),
|
||||
runtime: z.string().min(1, 'Runtime is required').optional().default('nodejs18.x'),
|
||||
runtime: z.string().min(1, 'Runtime is required'),
|
||||
code: z
|
||||
.record(z.string())
|
||||
.refine((val) => Object.keys(val).length > 0, 'At least one code file is required'),
|
||||
requirements: z.string().nullable().optional(),
|
||||
packageJson: z.string().nullable().optional(),
|
||||
timeout: z.number().min(1).max(900).optional().default(3),
|
||||
memorySize: z.number().min(128).max(10240),
|
||||
|
||||
timeout: z.coerce.number().min(1).max(900).optional().default(3),
|
||||
memorySize: z.coerce.number().min(128).max(10240).optional().default(128),
|
||||
environmentVariables: z.record(z.string()).default({}),
|
||||
tags: z.record(z.string()).default({}),
|
||||
role: z.string().min(1, 'Role ARN is required'),
|
||||
@@ -74,12 +73,7 @@ async function createLambdaPackage(params: DeployRequest): Promise<Buffer> {
|
||||
zip.file(filePath, codeContent)
|
||||
}
|
||||
|
||||
// Add dependencies based on runtime
|
||||
if (params.runtime.startsWith('python') && params.requirements?.trim()) {
|
||||
zip.file('requirements.txt', params.requirements)
|
||||
} else if (params.runtime.startsWith('nodejs') && params.packageJson?.trim()) {
|
||||
zip.file('package.json', params.packageJson)
|
||||
}
|
||||
|
||||
|
||||
return await zip.generateAsync({ type: 'nodebuffer' })
|
||||
}
|
||||
@@ -210,6 +204,48 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the runtime field if it's a JSON string
|
||||
if (typeof body.runtime === 'string') {
|
||||
try {
|
||||
body.runtime = JSON.parse(body.runtime)
|
||||
logger.info(`[${requestId}] Parsed runtime field:`, { parsedRuntime: body.runtime })
|
||||
} catch (parseError) {
|
||||
logger.error(`[${requestId}] Failed to parse runtime field as JSON`, {
|
||||
error: parseError instanceof Error ? parseError.message : String(parseError),
|
||||
runtimeString: body.runtime,
|
||||
})
|
||||
return createErrorResponse('Invalid JSON in runtime field', 400, 'INVALID_RUNTIME_JSON')
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the timeout field if it's a JSON string
|
||||
if (typeof body.timeout === 'string') {
|
||||
try {
|
||||
body.timeout = JSON.parse(body.timeout)
|
||||
logger.info(`[${requestId}] Parsed timeout field:`, { parsedTimeout: body.timeout })
|
||||
} catch (parseError) {
|
||||
logger.error(`[${requestId}] Failed to parse timeout field as JSON`, {
|
||||
error: parseError instanceof Error ? parseError.message : String(parseError),
|
||||
timeoutString: body.timeout,
|
||||
})
|
||||
return createErrorResponse('Invalid JSON in timeout field', 400, 'INVALID_TIMEOUT_JSON')
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the memorySize field if it's a JSON string
|
||||
if (typeof body.memorySize === 'string') {
|
||||
try {
|
||||
body.memorySize = JSON.parse(body.memorySize)
|
||||
logger.info(`[${requestId}] Parsed memorySize field:`, { parsedMemorySize: body.memorySize })
|
||||
} catch (parseError) {
|
||||
logger.error(`[${requestId}] Failed to parse memorySize field as JSON`, {
|
||||
error: parseError instanceof Error ? parseError.message : String(parseError),
|
||||
memorySizeString: body.memorySize,
|
||||
})
|
||||
return createErrorResponse('Invalid JSON in memorySize field', 400, 'INVALID_MEMORYSIZE_JSON')
|
||||
}
|
||||
}
|
||||
|
||||
const validationResult = DeployRequestSchema.safeParse(body)
|
||||
if (!validationResult.success) {
|
||||
logger.warn(`[${requestId}] Invalid request body`, { errors: validationResult.error.errors })
|
||||
|
||||
@@ -107,25 +107,9 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
{
|
||||
id: 'runtime',
|
||||
title: 'Runtime',
|
||||
type: 'dropdown',
|
||||
type: 'short-input',
|
||||
layout: 'full',
|
||||
options: [
|
||||
'nodejs18.x',
|
||||
'nodejs16.x',
|
||||
'nodejs14.x',
|
||||
'python3.11',
|
||||
'python3.10',
|
||||
'python3.9',
|
||||
'python3.8',
|
||||
'java11',
|
||||
'java8.al2',
|
||||
'dotnet6',
|
||||
'dotnetcore3.1',
|
||||
'go1.x',
|
||||
'ruby2.7',
|
||||
'provided.al2',
|
||||
'provided',
|
||||
],
|
||||
placeholder: 'e.g., nodejs18.x, python3.11, java11',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
@@ -140,23 +124,6 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
and: {
|
||||
field: 'runtime',
|
||||
value: [
|
||||
'nodejs18.x',
|
||||
'nodejs16.x',
|
||||
'nodejs14.x',
|
||||
'python3.11',
|
||||
'python3.10',
|
||||
'python3.9',
|
||||
'python3.8',
|
||||
'java11',
|
||||
'java8.al2',
|
||||
'dotnet6',
|
||||
'dotnetcore3.1',
|
||||
'ruby2.7',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -172,49 +139,13 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'requirements',
|
||||
title: 'Requirements (Python)',
|
||||
type: 'code',
|
||||
layout: 'full',
|
||||
language: 'javascript',
|
||||
placeholder:
|
||||
'// Enter Python dependencies (requirements.txt format)\n// e.g., requests==2.31.0\n// boto3==1.34.0',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
and: {
|
||||
field: 'runtime',
|
||||
value: ['python3.11', 'python3.10', 'python3.9', 'python3.8'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'packageJson',
|
||||
title: 'Package.json (Node.js)',
|
||||
type: 'code',
|
||||
layout: 'full',
|
||||
language: 'json',
|
||||
placeholder:
|
||||
'{\n "name": "lambda-function",\n "version": "1.0.0",\n "dependencies": {\n "axios": "^1.6.0",\n "lodash": "^4.17.21"\n }\n}',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
and: {
|
||||
field: 'runtime',
|
||||
value: ['nodejs18.x', 'nodejs16.x', 'nodejs14.x'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: 'timeout',
|
||||
title: 'Timeout (seconds)',
|
||||
type: 'slider',
|
||||
layout: 'full',
|
||||
min: 1,
|
||||
max: 900,
|
||||
step: 1,
|
||||
integer: true,
|
||||
type: 'short-input',
|
||||
layout: 'half',
|
||||
placeholder: 'Enter timeout in seconds (1-900)',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
@@ -223,12 +154,9 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
{
|
||||
id: 'memorySize',
|
||||
title: 'Memory (MB)',
|
||||
type: 'slider',
|
||||
type: 'short-input',
|
||||
layout: 'half',
|
||||
min: 128,
|
||||
max: 10240,
|
||||
step: 64,
|
||||
integer: true,
|
||||
placeholder: 'Enter memory in MB (128-10240)',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
value: ['create/update'],
|
||||
@@ -260,7 +188,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
},
|
||||
],
|
||||
tools: {
|
||||
access: ['aws_lambda_deploy', 'aws_lambda_update', 'aws_lambda_invoke', 'aws_lambda_fetch'],
|
||||
access: ['aws_lambda_deploy', 'aws_lambda_fetch'],
|
||||
config: {
|
||||
tool: (params: Record<string, any>) => {
|
||||
switch (params.operationType) {
|
||||
@@ -284,8 +212,6 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
handler: { type: 'string', required: false },
|
||||
runtime: { type: 'string', required: false },
|
||||
code: { type: 'json', required: false },
|
||||
requirements: { type: 'string', required: false },
|
||||
packageJson: { type: 'string', required: false },
|
||||
timeout: { type: 'number', required: false },
|
||||
memorySize: { type: 'number', required: false },
|
||||
environmentVariables: { type: 'json', required: false },
|
||||
|
||||
@@ -9,10 +9,8 @@ interface AWSLambdaDeployInput {
|
||||
handler?: string
|
||||
runtime: string
|
||||
code: Record<string, string>
|
||||
requirements?: string
|
||||
packageJson?: string
|
||||
timeout: number
|
||||
memorySize: number
|
||||
timeout?: number
|
||||
memorySize?: number
|
||||
environmentVariables: Record<string, string>
|
||||
tags: Record<string, string>
|
||||
}
|
||||
@@ -76,7 +74,7 @@ export const awsLambdaDeployTool: ToolConfig<AWSLambdaDeployInput, AWSLambdaDepl
|
||||
runtime: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Lambda runtime (e.g., nodejs18.x, python3.11)',
|
||||
description: 'Lambda runtime (e.g., nodejs18.x, python3.11, java11)',
|
||||
},
|
||||
code: {
|
||||
type: 'object',
|
||||
@@ -84,25 +82,18 @@ export const awsLambdaDeployTool: ToolConfig<AWSLambdaDeployInput, AWSLambdaDepl
|
||||
description:
|
||||
'Function code files as JSON object with file paths as keys and code content as values',
|
||||
},
|
||||
requirements: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'Python requirements.txt content',
|
||||
},
|
||||
packageJson: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'Node.js package.json content',
|
||||
},
|
||||
|
||||
timeout: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
required: false,
|
||||
description: 'Function timeout in seconds (1-900)',
|
||||
default: 3,
|
||||
},
|
||||
memorySize: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
required: false,
|
||||
description: 'Function memory size in MB (128-10240)',
|
||||
default: 128,
|
||||
},
|
||||
environmentVariables: {
|
||||
type: 'object',
|
||||
@@ -133,10 +124,9 @@ export const awsLambdaDeployTool: ToolConfig<AWSLambdaDeployInput, AWSLambdaDepl
|
||||
handler: params.handler,
|
||||
runtime: params.runtime,
|
||||
code: params.code,
|
||||
requirements: params.requirements,
|
||||
packageJson: params.packageJson,
|
||||
timeout: params.timeout,
|
||||
memorySize: params.memorySize,
|
||||
|
||||
timeout: params.timeout || 30,
|
||||
memorySize: params.memorySize || 128,
|
||||
environmentVariables: params.environmentVariables || {},
|
||||
tags: params.tags || {},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user