mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
Fix switch statement
This commit is contained in:
95
apps/sim/app/api/tools/aws-lambda/get-prompts/route.ts
Normal file
95
apps/sim/app/api/tools/aws-lambda/get-prompts/route.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console-logger'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
|
||||
const logger = createLogger('AWSLambdaGetPromptsAPI')
|
||||
|
||||
// Constants for getPrompts operation
|
||||
const system_prompt = `You are an expert in writing aws lambda functions. The user will provide an input which may contain the the existing lambda code, or they may not. If the initial code is provided, make the changes to the initial code to reflect what the user wants. If no code is provided, your job is to write the lambda function, choosing a runtime and handler.
|
||||
|
||||
Your output should be a valid JSON object, with the following structure:
|
||||
|
||||
[
|
||||
"runtime": runtime string,
|
||||
"handler": handler,
|
||||
"timeout": timeout,
|
||||
"memory": memory,
|
||||
"files":
|
||||
{
|
||||
"file_path_1": "code string for first file",
|
||||
"file_path_2": "code string for second file"
|
||||
}
|
||||
]`
|
||||
|
||||
const schema = {
|
||||
"name": "aws_lambda_function",
|
||||
"description": "Defines the structure for an AWS Lambda function configuration.",
|
||||
"strict": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"runtime": {
|
||||
"type": "string",
|
||||
"description": "The runtime environment for the Lambda function."
|
||||
},
|
||||
"handler": {
|
||||
"type": "string",
|
||||
"description": "The function handler that Lambda calls to start execution."
|
||||
},
|
||||
"memory": {
|
||||
"type": "integer",
|
||||
"description": "The amount of memory allocated to the Lambda function in MB (128-10240).",
|
||||
"minimum": 128,
|
||||
"maximum": 10240
|
||||
},
|
||||
"timeout": {
|
||||
"type": "integer",
|
||||
"description": "The maximum execution time for the Lambda function in seconds (1-900).",
|
||||
"minimum": 1,
|
||||
"maximum": 900
|
||||
},
|
||||
"files": {
|
||||
"type": "object",
|
||||
"description": "A mapping of file paths to their respective code strings.",
|
||||
"additionalProperties": {
|
||||
"type": "string",
|
||||
"description": "The code string for a specific file."
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["runtime", "handler", "files", "memory", "timeout"]
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const requestId = crypto.randomUUID().slice(0, 8)
|
||||
|
||||
try {
|
||||
logger.info(`[${requestId}] Processing AWS Lambda get prompts request`)
|
||||
|
||||
// No validation needed since this endpoint doesn't require any parameters
|
||||
// Just return the hardcoded system prompt and schema
|
||||
|
||||
logger.info(`[${requestId}] Returning system prompt and schema`)
|
||||
|
||||
return createSuccessResponse({
|
||||
success: true,
|
||||
output: {
|
||||
systemPrompt: system_prompt,
|
||||
schema: schema,
|
||||
},
|
||||
})
|
||||
} catch (error: any) {
|
||||
logger.error(`[${requestId}] Error in get prompts operation`, {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
})
|
||||
|
||||
return createErrorResponse(
|
||||
'Failed to get prompts and schema',
|
||||
500,
|
||||
'GET_PROMPTS_ERROR'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import { S3Icon } from '@/components/icons'
|
||||
import type { ToolResponse } from '@/tools/types'
|
||||
import type { BlockConfig } from '../types'
|
||||
|
||||
|
||||
|
||||
// Define the expected response type for AWS Lambda operations
|
||||
interface AWSLambdaResponse extends ToolResponse {
|
||||
output: {
|
||||
@@ -40,6 +42,10 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'full',
|
||||
placeholder: 'Enter AWS Access Key ID',
|
||||
password: true,
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['fetch', 'create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'secretAccessKey',
|
||||
@@ -48,6 +54,10 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'full',
|
||||
placeholder: 'Enter AWS Secret Access Key',
|
||||
password: true,
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['fetch', 'create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'region',
|
||||
@@ -77,6 +87,10 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
'me-south-1',
|
||||
'sa-east-1',
|
||||
],
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['fetch', 'create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'role',
|
||||
@@ -86,16 +100,20 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
placeholder: 'Enter the IAM Role ARN for Lambda execution',
|
||||
password: false,
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'operationType',
|
||||
title: 'Operation Type',
|
||||
id: 'operation',
|
||||
title: 'Operation',
|
||||
type: 'dropdown',
|
||||
layout: 'full',
|
||||
options: ['fetch', 'create/update'],
|
||||
options: [
|
||||
{ label: 'Fetch', id: 'fetch' },
|
||||
{ label: 'Create/Update', id: 'create/update' },
|
||||
{ label: 'Get Prompts', id: 'getPrompts' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'functionName',
|
||||
@@ -103,6 +121,10 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
type: 'short-input',
|
||||
layout: 'full',
|
||||
placeholder: 'Enter Lambda function name',
|
||||
condition: {
|
||||
field: 'operation',
|
||||
value: ['fetch', 'create/update'],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'runtime',
|
||||
@@ -111,7 +133,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'full',
|
||||
placeholder: 'e.g., nodejs18.x, python3.11, java11',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -122,7 +144,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'full',
|
||||
placeholder: 'e.g., index.handler',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -133,9 +155,9 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'full',
|
||||
language: 'json',
|
||||
placeholder:
|
||||
'{\n "index.js": "exports.handler = async (event) => {\\n return {\\n statusCode: 200,\\n body: JSON.stringify({\\n message: \\"Hello from Lambda!\\"\\n })\\n };\\n };"\n}',
|
||||
'{\n "index.js": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify({\n message: \"Hello from Lambda!\"\n })\n };\n };"\n}',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -147,7 +169,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'half',
|
||||
placeholder: 'Enter timeout in seconds (1-900)',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -158,7 +180,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
layout: 'half',
|
||||
placeholder: 'Enter memory in MB (128-10240)',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -170,7 +192,7 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
columns: ['Key', 'Value'],
|
||||
placeholder: 'Add environment variables as key-value pairs',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
@@ -182,33 +204,46 @@ export const AWSLambdaBlock: BlockConfig<AWSLambdaResponse> = {
|
||||
columns: ['Key', 'Value'],
|
||||
placeholder: 'Add tags as key-value pairs',
|
||||
condition: {
|
||||
field: 'operationType',
|
||||
field: 'operation',
|
||||
value: ['create/update'],
|
||||
},
|
||||
},
|
||||
],
|
||||
tools: {
|
||||
access: ['aws_lambda_deploy', 'aws_lambda_fetch'],
|
||||
access: ['aws_lambda_deploy', 'aws_lambda_fetch', 'aws_lambda_get_prompts'],
|
||||
config: {
|
||||
tool: (params: Record<string, any>) => {
|
||||
switch (params.operationType) {
|
||||
case 'fetch':
|
||||
return 'aws_lambda_fetch'
|
||||
case 'create/update':
|
||||
return 'aws_lambda_deploy'
|
||||
default:
|
||||
return 'aws_lambda_deploy' // Default to deploy
|
||||
const operation = String(params.operation || '').trim();
|
||||
// Only map user-facing names; pass through tool IDs as-is
|
||||
const operationMap: Record<string, string> = {
|
||||
'fetch': 'aws_lambda_fetch',
|
||||
'create/update': 'aws_lambda_deploy',
|
||||
'getPrompts': 'aws_lambda_get_prompts',
|
||||
};
|
||||
if (operationMap[operation]) {
|
||||
return operationMap[operation];
|
||||
}
|
||||
// If already a tool ID, return as-is
|
||||
if (
|
||||
operation === 'aws_lambda_fetch' ||
|
||||
operation === 'aws_lambda_deploy' ||
|
||||
operation === 'aws_lambda_get_prompts'
|
||||
) {
|
||||
return operation;
|
||||
}
|
||||
// Default fallback
|
||||
console.warn(`Unknown operation: "${operation}", defaulting to aws_lambda_fetch`);
|
||||
return 'aws_lambda_fetch';
|
||||
},
|
||||
},
|
||||
},
|
||||
inputs: {
|
||||
accessKeyId: { type: 'string', required: true },
|
||||
secretAccessKey: { type: 'string', required: true },
|
||||
region: { type: 'string', required: true },
|
||||
accessKeyId: { type: 'string', required: false },
|
||||
secretAccessKey: { type: 'string', required: false },
|
||||
region: { type: 'string', required: false },
|
||||
role: { type: 'string', required: false },
|
||||
operationType: { type: 'string', required: true },
|
||||
functionName: { type: 'string', required: true },
|
||||
operation: { type: 'string', required: true },
|
||||
functionName: { type: 'string', required: false },
|
||||
handler: { type: 'string', required: false },
|
||||
runtime: { type: 'string', required: false },
|
||||
code: { type: 'json', required: false },
|
||||
|
||||
32
apps/sim/tools/aws_lambda/get_prompts.ts
Normal file
32
apps/sim/tools/aws_lambda/get_prompts.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { ToolConfig } from '../types'
|
||||
|
||||
interface AWSLambdaGetPromptsParams {
|
||||
// No parameters needed for this operation
|
||||
}
|
||||
|
||||
interface AWSLambdaGetPromptsResponse {
|
||||
systemPrompt: string
|
||||
schema: Record<string, any>
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const awsLambdaGetPromptsTool: ToolConfig<AWSLambdaGetPromptsParams, AWSLambdaGetPromptsResponse> = {
|
||||
id: 'aws_lambda_get_prompts',
|
||||
name: 'AWS Lambda Get Prompts',
|
||||
description: 'Get system prompt and schema for AWS Lambda operations',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
// No parameters needed for this operation
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/aws-lambda/get-prompts',
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: () => ({}), // No body needed
|
||||
},
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export { awsLambdaDeployTool } from './deploy'
|
||||
export { awsLambdaFetchTool } from './fetch'
|
||||
export { awsLambdaGetPromptsTool } from './get_prompts'
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
airtableUpdateRecordTool,
|
||||
} from './airtable'
|
||||
import { autoblocksPromptManagerTool } from './autoblocks'
|
||||
import { awsLambdaDeployTool, awsLambdaFetchTool } from './aws_lambda'
|
||||
import { awsLambdaDeployTool, awsLambdaFetchTool, awsLambdaGetPromptsTool } from './aws_lambda'
|
||||
import { browserUseRunTaskTool } from './browser_use'
|
||||
import { clayPopulateTool } from './clay'
|
||||
import { confluenceRetrieveTool, confluenceUpdateTool } from './confluence'
|
||||
@@ -226,4 +226,5 @@ export const tools: Record<string, ToolConfig> = {
|
||||
workflow_executor: workflowExecutorTool,
|
||||
aws_lambda_deploy: awsLambdaDeployTool,
|
||||
aws_lambda_fetch: awsLambdaFetchTool,
|
||||
aws_lambda_get_prompts: awsLambdaGetPromptsTool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user