pika-shared 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/chatbot/bedrock-lambda-error.js.map +1 -1
- package/dist/types/chatbot/bedrock-lambda-error.mjs.map +1 -1
- package/dist/types/chatbot/chatbot-types.d.mts +421 -24
- package/dist/types/chatbot/chatbot-types.d.ts +421 -24
- package/dist/types/chatbot/chatbot-types.js +9 -1
- package/dist/types/chatbot/chatbot-types.js.map +1 -1
- package/dist/types/chatbot/chatbot-types.mjs +6 -2
- package/dist/types/chatbot/chatbot-types.mjs.map +1 -1
- package/dist/types/chatbot/webcomp-types.d.mts +326 -0
- package/dist/types/chatbot/webcomp-types.d.ts +326 -0
- package/dist/types/chatbot/webcomp-types.js +4 -0
- package/dist/types/chatbot/webcomp-types.js.map +1 -0
- package/dist/types/chatbot/webcomp-types.mjs +3 -0
- package/dist/types/chatbot/webcomp-types.mjs.map +1 -0
- package/dist/util/api-gateway-utils.js.map +1 -1
- package/dist/util/api-gateway-utils.mjs.map +1 -1
- package/dist/util/bad-request-error.js.map +1 -1
- package/dist/util/bad-request-error.mjs.map +1 -1
- package/dist/util/bedrock.js.map +1 -1
- package/dist/util/bedrock.mjs.map +1 -1
- package/dist/util/chatbot-shared-utils.js.map +1 -1
- package/dist/util/chatbot-shared-utils.mjs.map +1 -1
- package/dist/util/forbidden-error.js.map +1 -1
- package/dist/util/forbidden-error.mjs.map +1 -1
- package/dist/util/http-status-error.js.map +1 -1
- package/dist/util/http-status-error.mjs.map +1 -1
- package/dist/util/icon-utils.d.mts +12 -0
- package/dist/util/icon-utils.d.ts +12 -0
- package/dist/util/icon-utils.js +26 -0
- package/dist/util/icon-utils.js.map +1 -0
- package/dist/util/icon-utils.mjs +24 -0
- package/dist/util/icon-utils.mjs.map +1 -0
- package/dist/util/instruction-assistance-utils.d.mts +28 -1
- package/dist/util/instruction-assistance-utils.d.ts +28 -1
- package/dist/util/instruction-assistance-utils.js +56 -8
- package/dist/util/instruction-assistance-utils.js.map +1 -1
- package/dist/util/instruction-assistance-utils.mjs +55 -9
- package/dist/util/instruction-assistance-utils.mjs.map +1 -1
- package/dist/util/jwt.js.map +1 -1
- package/dist/util/jwt.mjs.map +1 -1
- package/dist/util/server-client-utils.js.map +1 -1
- package/dist/util/server-client-utils.mjs.map +1 -1
- package/dist/util/server-utils.js +6 -2
- package/dist/util/server-utils.js.map +1 -1
- package/dist/util/server-utils.mjs +6 -2
- package/dist/util/server-utils.mjs.map +1 -1
- package/dist/util/unauthorized-error.js.map +1 -1
- package/dist/util/unauthorized-error.mjs.map +1 -1
- package/dist/util/wc-utils.d.mts +22 -0
- package/dist/util/wc-utils.d.ts +22 -0
- package/dist/util/wc-utils.js +26 -0
- package/dist/util/wc-utils.js.map +1 -0
- package/dist/util/wc-utils.mjs +24 -0
- package/dist/util/wc-utils.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/api-gateway-utils.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,KAAM,CAAA;AAAA,EACvC,WAAA,CACI,SACgB,UAClB,EAAA;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA;AAIxB,CAAA;;;AC+DA,SAAS,iBAA4B,IAAwG,EAAA;AACzI,EAAO,OAAA,IAAA,KAAS,QAAQ,IAAS,KAAA,MAAA,IAAa,OAAO,IAAS,KAAA,QAAA,KAAa,YAAgB,IAAA,IAAA,IAAQ,MAAU,IAAA,IAAA,CAAA;AACjH;AAaO,SAAS,4BAAqD,EAA8F,EAAA;AAC/J,EAAO,OAAA,OAAO,OAAO,OAAY,KAAA;AAC7B,IAAI,IAAA,KAAA;AACJ,IAAI,IAAA,QAAA;AAIJ,IA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AA;AAAA,QACjD,MAAM,KAAM,CAAA,IAAA;AAAA,QACZ,cAAc,KAAiB,YAAA,KAAA,GAAQ,KAAM,CAAA,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,QACnE,UAAY,EAAA,KAAA,YAAiB,KAAQ,GAAA,KAAA,CAAM,KAAQ,GAAA;AAAA,OACtD,CAAA;AACD,MAAM,MAAA,KAAA;AAAA;AACV;AAGJ,EAAO,OAAA,KAAA;AACX","file":"api-gateway-utils.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","/**\n * Utility functions and types for AWS API Gateway Lambda integration.\n * This module provides type-safe wrappers and helpers for handling\n * API Gateway events and responses in AWS Lambda functions.\n */\nimport type {\n APIGatewayEventRequestContextV2,\n APIGatewayProxyEventV2WithRequestContext,\n APIGatewayProxyHandlerV2,\n APIGatewayProxyResultV2,\n APIGatewayProxyStructuredResultV2,\n Context\n} from 'aws-lambda';\nimport { HttpStatusError } from './http-status-error';\n\n/**\n * Extends the standard Error interface to include an optional HTTP status code.\n * This allows for standardized error handling with appropriate HTTP responses.\n */\nexport interface HttpError extends Error {\n statusCode?: number;\n}\n\n/**\n * A type that enhances the standard API Gateway event by replacing the body property\n * with a strongly-typed version rather than the default string representation.\n *\n * @template TRequestBody - The type of the request body after parsing\n * @template TRequestContext - The type of the request context\n */\ninterface APIGatewayProxyEventPikaWithRequestContext<TRequestBody, TRequestContext> extends Omit<APIGatewayProxyEventV2WithRequestContext<TRequestContext>, 'body'> {\n body: TRequestBody;\n}\n\n/**\n * A specialized API Gateway event type that includes:\n * 1. A strongly-typed request body\n * 2. The standard API Gateway request context\n * 3. Additional path and httpMethod properties for routing\n *\n * @template TRequestBody - The type of the parsed request body (defaults to never if not provided)\n */\nexport type APIGatewayProxyEventPika<TRequestBody = never> = APIGatewayProxyEventPikaWithRequestContext<TRequestBody, APIGatewayEventRequestContextV2> & {\n path: string;\n httpMethod: string;\n resource: string;\n};\n\n/**\n * A generic handler type for AWS Lambda functions.\n *\n * @template TEvent - The event type (input) for the handler\n * @template TResult - The result type (output) returned by the handler\n * @returns Either void or a Promise containing the result\n */\nexport type HandlerPika<TEvent = unknown, TResult = unknown> = (event: TEvent, context: Context) => void | Promise<TResult>;\n\n/**\n * A specialized handler type for API Gateway Lambda integrations with typed request and response.\n *\n * @template B - The request body type (defaults to never if not provided)\n * @template T - The response type (defaults to never if not provided)\n */\nexport type APIGatewayProxyHandlerPika<B = never, T = never> = HandlerPika<APIGatewayProxyEventPika<B>, APIGatewayProxyResultV2<T>>;\n\n/**\n * Type guard function that determines if the provided data is a structured API Gateway response.\n * A structured response must be an object containing either 'statusCode' or 'body' properties.\n *\n * @template TResponse - The expected response type\n * @param data - The data to check\n * @returns A type predicate indicating if the data is a structured API Gateway response\n */\nfunction isObjectResponse<TResponse>(data: undefined | void | APIGatewayProxyResultV2<TResponse>): data is APIGatewayProxyStructuredResultV2 {\n return data !== null && data !== undefined && typeof data === 'object' && ('statusCode' in data || 'body' in data);\n}\n\n/**\n * A higher-order function that wraps a typed Lambda handler to provide:\n * 1. Automatic JSON parsing of the request body\n * 2. Error handling with appropriate status codes\n * 3. Consistent response formatting\n *\n * @template TRequestBody - The expected type of the request body after parsing\n * @template TResponse - The expected type of the response\n * @param fn - The Lambda handler function to wrap\n * @returns A standard API Gateway Lambda handler with error handling and type safety\n */\nexport function apiGatewayFunctionDecorator<TRequestBody, TResponse>(fn: APIGatewayProxyHandlerPika<TRequestBody, TResponse>): APIGatewayProxyHandlerV2<TResponse> {\n return async (event, context) => {\n let error: any; // Use 'any' to preserve original error type for instanceof checks\n let response: undefined | void | APIGatewayProxyResultV2<TResponse>;\n\n // Just in case, add another version of the headers with all lowercase keys;\n // helps when running locally. Seems APIGateway automatically converts to lowercase\n Object.keys(event.headers).forEach((k) => {\n let lowerK = k.toLowerCase();\n if (!event.headers[lowerK]) {\n event.headers[lowerK] = event.headers[k];\n }\n });\n try {\n // Parse the request body if present and create a typed event object\n const eventWithType: APIGatewayProxyEventPika<TRequestBody> = {\n ...(event as any),\n body: event.body ? JSON.parse(event.body) : undefined\n };\n\n // Call the handler with the typed event\n response = await fn(eventWithType, context);\n } catch (err) {\n // Capture any errors that occur during processing\n error = err;\n }\n\n // Handle errors by returning an appropriate error response\n if (error) {\n console.error(error);\n\n // Handle HttpStatusError specifically (has required statusCode property)\n if (error instanceof HttpStatusError) {\n return toResponse(error.message, error.statusCode);\n }\n\n // Handle other HttpError types (has optional statusCode property)\n const httpError = error as HttpError;\n const statusCode = httpError.statusCode || 500;\n return toResponse(typeof error === 'string' ? error : error.message, statusCode);\n }\n\n // Return resource not found if the response is undefined\n if (response === undefined) {\n return toResponse(\n {\n message: 'Resource not found',\n code: 'RESOURCE_NOT_FOUND'\n },\n 404\n );\n }\n\n // Either return the structured response directly or wrap the result in a standard response\n return isObjectResponse(response) ? response : toResponse(response, 200);\n };\n}\n\n/**\n * Creates a standardized API Gateway response object.\n * Handles both string and non-string body types by automatically stringifying as needed.\n *\n * @template T - The type of the response body\n * @param body - The response body to send\n * @param statusCode - The HTTP status code (defaults to 200 OK)\n * @returns A properly formatted API Gateway response object\n */\nexport function toResponse<T>(body: T, statusCode = 200): APIGatewayProxyStructuredResultV2 {\n return {\n body: typeof body === 'string' ? body : JSON.stringify(body),\n statusCode\n };\n}\n\n/**\n * Type definition for Lambda Function URL events with additional IAM authorization details.\n * Extends the standard API Gateway event with specific requestContext properties for\n * Function URL integration patterns.\n *\n * @template T - The request body type\n */\nexport type LambdaFunctionUrlProxyEventPika<T = never> = APIGatewayProxyEventPika<T> & {\n requestContext: {\n authorizer?: {\n iam: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n userId?: string;\n user?: string;\n callerId?: string;\n caller?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n identity?: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n user?: string;\n userId?: string;\n caller?: string;\n callerId?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n};\n\n/**\n * Converts a Lambda Function URL event into a standardized API Gateway event.\n * This function ensures that IAM authorization details are properly mapped\n * from the authorizer to the identity property for consistent access patterns.\n *\n * Also, parses the body string into the generic type T if it exists and is a string\n *\n * This exists because the Lambda Function URL event has a different structure\n * than the API Gateway event and we almost never use Lambdas that are Function URL based\n * and so it's easier to just convert the event to a standard API Gateway event than\n * to handle the different event types.\n *\n * @template T - The request body type\n * @param event - The Lambda Function URL event to convert\n * @returns A standardized API Gateway event\n */\nexport function convertFunctionUrlEventToStandardApiGatewayEvent<T>(event: LambdaFunctionUrlProxyEventPika<T>): APIGatewayProxyEventPika<T> {\n if (event.requestContext.identity == null && event.requestContext.authorizer?.iam != null) {\n event.requestContext.identity = event.requestContext.authorizer.iam;\n event.requestContext.authorizer.iam.cognitoIdentityId = event.headers['cognito-identity-id'];\n event.requestContext.authorizer.iam.user = event.requestContext.authorizer.iam.userId;\n event.requestContext.authorizer.iam.caller = event.requestContext.authorizer.iam.callerId;\n }\n\n // Parse the body string into the generic type T if it exists and is a string\n if (event.body && typeof event.body === 'string') {\n try {\n // If content-type is not application/json, don't attempt to parse\n const contentType = event.headers['content-type'] || event.headers['Content-Type'];\n if (contentType && contentType.includes('application/json')) {\n event.body = JSON.parse(event.body) as T;\n }\n } catch (error) {\n console.error('Error parsing request body as JSON:', {\n body: event.body,\n errorMessage: error instanceof Error ? error.message : String(error),\n errorStack: error instanceof Error ? error.stack : undefined\n });\n throw error;\n }\n }\n\n return event;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/api-gateway-utils.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE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A,CAAe,WAAW,GAAA,CAAI,QAAA;AAAA,EACrF;AAGA,EAAA,IAAI,KAAA,CAAM,IAAA,IAAQ,OAAO,KAAA,CAAM,SAAS,QAAA,EAAU;AAC9C,IAAA,IAAI;AAEA,MAAA,MAAM,cAAc,KAAA,CAAM,OAAA,CAAQ,cAAc,CAAA,IAAK,KAAA,CAAM,QAAQ,cAAc,CAAA;AACjF,MAAA,IAAI,WAAA,IAAe,WAAA,CAAY,QAAA,CAAS,kBAAkB,CAAA,EAAG;AACzD,QAAA,KAAA,CAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAAA,MACtC;AAAA,IACJ,SAAS,KAAA,EAAO;AACZ,MAAA,OAAA,CAAQ,MAAM,qCAAA,EAAuC;AAAA,QACjD,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,cAAc,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,QACnE,UAAA,EAAY,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,KAAA,GAAQ;AAAA,OACtD,CAAA;AACD,MAAA,MAAM,KAAA;AAAA,IACV;AAAA,EACJ;AAEA,EAAA,OAAO,KAAA;AACX","file":"api-gateway-utils.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","/**\n * Utility functions and types for AWS API Gateway Lambda integration.\n * This module provides type-safe wrappers and helpers for handling\n * API Gateway events and responses in AWS Lambda functions.\n */\nimport type {\n APIGatewayEventRequestContextV2,\n APIGatewayProxyEventV2WithRequestContext,\n APIGatewayProxyHandlerV2,\n APIGatewayProxyResultV2,\n APIGatewayProxyStructuredResultV2,\n Context\n} from 'aws-lambda';\nimport { HttpStatusError } from './http-status-error';\n\n/**\n * Extends the standard Error interface to include an optional HTTP status code.\n * This allows for standardized error handling with appropriate HTTP responses.\n */\nexport interface HttpError extends Error {\n statusCode?: number;\n}\n\n/**\n * A type that enhances the standard API Gateway event by replacing the body property\n * with a strongly-typed version rather than the default string representation.\n *\n * @template TRequestBody - The type of the request body after parsing\n * @template TRequestContext - The type of the request context\n */\ninterface APIGatewayProxyEventPikaWithRequestContext<TRequestBody, TRequestContext> extends Omit<APIGatewayProxyEventV2WithRequestContext<TRequestContext>, 'body'> {\n body: TRequestBody;\n}\n\n/**\n * A specialized API Gateway event type that includes:\n * 1. A strongly-typed request body\n * 2. The standard API Gateway request context\n * 3. Additional path and httpMethod properties for routing\n *\n * @template TRequestBody - The type of the parsed request body (defaults to never if not provided)\n */\nexport type APIGatewayProxyEventPika<TRequestBody = never> = APIGatewayProxyEventPikaWithRequestContext<TRequestBody, APIGatewayEventRequestContextV2> & {\n path: string;\n httpMethod: string;\n resource: string;\n};\n\n/**\n * A generic handler type for AWS Lambda functions.\n *\n * @template TEvent - The event type (input) for the handler\n * @template TResult - The result type (output) returned by the handler\n * @returns Either void or a Promise containing the result\n */\nexport type HandlerPika<TEvent = unknown, TResult = unknown> = (event: TEvent, context: Context) => void | Promise<TResult>;\n\n/**\n * A specialized handler type for API Gateway Lambda integrations with typed request and response.\n *\n * @template B - The request body type (defaults to never if not provided)\n * @template T - The response type (defaults to never if not provided)\n */\nexport type APIGatewayProxyHandlerPika<B = never, T = never> = HandlerPika<APIGatewayProxyEventPika<B>, APIGatewayProxyResultV2<T>>;\n\n/**\n * Type guard function that determines if the provided data is a structured API Gateway response.\n * A structured response must be an object containing either 'statusCode' or 'body' properties.\n *\n * @template TResponse - The expected response type\n * @param data - The data to check\n * @returns A type predicate indicating if the data is a structured API Gateway response\n */\nfunction isObjectResponse<TResponse>(data: undefined | void | APIGatewayProxyResultV2<TResponse>): data is APIGatewayProxyStructuredResultV2 {\n return data !== null && data !== undefined && typeof data === 'object' && ('statusCode' in data || 'body' in data);\n}\n\n/**\n * A higher-order function that wraps a typed Lambda handler to provide:\n * 1. Automatic JSON parsing of the request body\n * 2. Error handling with appropriate status codes\n * 3. Consistent response formatting\n *\n * @template TRequestBody - The expected type of the request body after parsing\n * @template TResponse - The expected type of the response\n * @param fn - The Lambda handler function to wrap\n * @returns A standard API Gateway Lambda handler with error handling and type safety\n */\nexport function apiGatewayFunctionDecorator<TRequestBody, TResponse>(fn: APIGatewayProxyHandlerPika<TRequestBody, TResponse>): APIGatewayProxyHandlerV2<TResponse> {\n return async (event, context) => {\n let error: any; // Use 'any' to preserve original error type for instanceof checks\n let response: undefined | void | APIGatewayProxyResultV2<TResponse>;\n\n // Just in case, add another version of the headers with all lowercase keys;\n // helps when running locally. Seems APIGateway automatically converts to lowercase\n Object.keys(event.headers).forEach((k) => {\n let lowerK = k.toLowerCase();\n if (!event.headers[lowerK]) {\n event.headers[lowerK] = event.headers[k];\n }\n });\n try {\n // Parse the request body if present and create a typed event object\n const eventWithType: APIGatewayProxyEventPika<TRequestBody> = {\n ...(event as any),\n body: event.body ? JSON.parse(event.body) : undefined\n };\n\n // Call the handler with the typed event\n response = await fn(eventWithType, context);\n } catch (err) {\n // Capture any errors that occur during processing\n error = err;\n }\n\n // Handle errors by returning an appropriate error response\n if (error) {\n console.error(error);\n\n // Handle HttpStatusError specifically (has required statusCode property)\n if (error instanceof HttpStatusError) {\n return toResponse(error.message, error.statusCode);\n }\n\n // Handle other HttpError types (has optional statusCode property)\n const httpError = error as HttpError;\n const statusCode = httpError.statusCode || 500;\n return toResponse(typeof error === 'string' ? error : error.message, statusCode);\n }\n\n // Return resource not found if the response is undefined\n if (response === undefined) {\n return toResponse(\n {\n message: 'Resource not found',\n code: 'RESOURCE_NOT_FOUND'\n },\n 404\n );\n }\n\n // Either return the structured response directly or wrap the result in a standard response\n return isObjectResponse(response) ? response : toResponse(response, 200);\n };\n}\n\n/**\n * Creates a standardized API Gateway response object.\n * Handles both string and non-string body types by automatically stringifying as needed.\n *\n * @template T - The type of the response body\n * @param body - The response body to send\n * @param statusCode - The HTTP status code (defaults to 200 OK)\n * @returns A properly formatted API Gateway response object\n */\nexport function toResponse<T>(body: T, statusCode = 200): APIGatewayProxyStructuredResultV2 {\n return {\n body: typeof body === 'string' ? body : JSON.stringify(body),\n statusCode\n };\n}\n\n/**\n * Type definition for Lambda Function URL events with additional IAM authorization details.\n * Extends the standard API Gateway event with specific requestContext properties for\n * Function URL integration patterns.\n *\n * @template T - The request body type\n */\nexport type LambdaFunctionUrlProxyEventPika<T = never> = APIGatewayProxyEventPika<T> & {\n requestContext: {\n authorizer?: {\n iam: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n userId?: string;\n user?: string;\n callerId?: string;\n caller?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n identity?: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n user?: string;\n userId?: string;\n caller?: string;\n callerId?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n};\n\n/**\n * Converts a Lambda Function URL event into a standardized API Gateway event.\n * This function ensures that IAM authorization details are properly mapped\n * from the authorizer to the identity property for consistent access patterns.\n *\n * Also, parses the body string into the generic type T if it exists and is a string\n *\n * This exists because the Lambda Function URL event has a different structure\n * than the API Gateway event and we almost never use Lambdas that are Function URL based\n * and so it's easier to just convert the event to a standard API Gateway event than\n * to handle the different event types.\n *\n * @template T - The request body type\n * @param event - The Lambda Function URL event to convert\n * @returns A standardized API Gateway event\n */\nexport function convertFunctionUrlEventToStandardApiGatewayEvent<T>(event: LambdaFunctionUrlProxyEventPika<T>): APIGatewayProxyEventPika<T> {\n if (event.requestContext.identity == null && event.requestContext.authorizer?.iam != null) {\n event.requestContext.identity = event.requestContext.authorizer.iam;\n event.requestContext.authorizer.iam.cognitoIdentityId = event.headers['cognito-identity-id'];\n event.requestContext.authorizer.iam.user = event.requestContext.authorizer.iam.userId;\n event.requestContext.authorizer.iam.caller = event.requestContext.authorizer.iam.callerId;\n }\n\n // Parse the body string into the generic type T if it exists and is a string\n if (event.body && typeof event.body === 'string') {\n try {\n // If content-type is not application/json, don't attempt to parse\n const contentType = event.headers['content-type'] || event.headers['Content-Type'];\n if (contentType && contentType.includes('application/json')) {\n event.body = JSON.parse(event.body) as T;\n }\n } catch (error) {\n console.error('Error parsing request body as JSON:', {\n body: event.body,\n errorMessage: error instanceof Error ? error.message : String(error),\n errorStack: error instanceof Error ? error.stack : undefined\n });\n throw error;\n }\n }\n\n return event;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/api-gateway-utils.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,KAAM,CAAA;AAAA,EACvC,WAAA,CACI,SACgB,UAClB,EAAA;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA;AAIxB,CAAA;;;AC+DA,SAAS,iBAA4B,IAAwG,EAAA;AACzI,EAAO,OAAA,IAAA,KAAS,QAAQ,IAAS,KAAA,MAAA,IAAa,OAAO,IAAS,KAAA,QAAA,KAAa,YAAgB,IAAA,IAAA,IAAQ,MAAU,IAAA,IAAA,CAAA;AACjH;AAaO,SAAS,4BAAqD,EAA8F,EAAA;AAC/J,EAAO,OAAA,OAAO,OAAO,OAAY,KAAA;AAC7B,IAAI,IAAA,KAAA;AACJ,IAAI,IAAA,QAAA;AAIJ,IAAA,MAAA,CAAO,KAAK,KAAM,CAAA,OAAO,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAM,KAAA;AACtC,MAAI,IAAA,MAAA,GAAS,EAAE,WAAY,EAAA;AAC3B,MAAA,IAAI,CAAC,KAAA,CAAM,OAAQ,CAAA,MAAM,CAAG,EAAA;AACxB,QAAA,KAAA,CAAM,OAAQ,CAAA,MAAM,CAAI,GAAA,KAAA,CAAM,QAAQ,CAAC,CAAA;AAAA;AAC3C,KACH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sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","/**\n * Utility functions and types for AWS API Gateway Lambda integration.\n * This module provides type-safe wrappers and helpers for handling\n * API Gateway events and responses in AWS Lambda functions.\n */\nimport type {\n APIGatewayEventRequestContextV2,\n APIGatewayProxyEventV2WithRequestContext,\n APIGatewayProxyHandlerV2,\n APIGatewayProxyResultV2,\n APIGatewayProxyStructuredResultV2,\n Context\n} from 'aws-lambda';\nimport { HttpStatusError } from './http-status-error';\n\n/**\n * Extends the standard Error interface to include an optional HTTP status code.\n * This allows for standardized error handling with appropriate HTTP responses.\n */\nexport interface HttpError extends Error {\n statusCode?: number;\n}\n\n/**\n * A type that enhances the standard API Gateway event by replacing the body property\n * with a strongly-typed version rather than the default string representation.\n *\n * @template TRequestBody - The type of the request body after parsing\n * @template TRequestContext - The type of the request context\n */\ninterface APIGatewayProxyEventPikaWithRequestContext<TRequestBody, TRequestContext> extends Omit<APIGatewayProxyEventV2WithRequestContext<TRequestContext>, 'body'> {\n body: TRequestBody;\n}\n\n/**\n * A specialized API Gateway event type that includes:\n * 1. A strongly-typed request body\n * 2. The standard API Gateway request context\n * 3. Additional path and httpMethod properties for routing\n *\n * @template TRequestBody - The type of the parsed request body (defaults to never if not provided)\n */\nexport type APIGatewayProxyEventPika<TRequestBody = never> = APIGatewayProxyEventPikaWithRequestContext<TRequestBody, APIGatewayEventRequestContextV2> & {\n path: string;\n httpMethod: string;\n resource: string;\n};\n\n/**\n * A generic handler type for AWS Lambda functions.\n *\n * @template TEvent - The event type (input) for the handler\n * @template TResult - The result type (output) returned by the handler\n * @returns Either void or a Promise containing the result\n */\nexport type HandlerPika<TEvent = unknown, TResult = unknown> = (event: TEvent, context: Context) => void | Promise<TResult>;\n\n/**\n * A specialized handler type for API Gateway Lambda integrations with typed request and response.\n *\n * @template B - The request body type (defaults to never if not provided)\n * @template T - The response type (defaults to never if not provided)\n */\nexport type APIGatewayProxyHandlerPika<B = never, T = never> = HandlerPika<APIGatewayProxyEventPika<B>, APIGatewayProxyResultV2<T>>;\n\n/**\n * Type guard function that determines if the provided data is a structured API Gateway response.\n * A structured response must be an object containing either 'statusCode' or 'body' properties.\n *\n * @template TResponse - The expected response type\n * @param data - The data to check\n * @returns A type predicate indicating if the data is a structured API Gateway response\n */\nfunction isObjectResponse<TResponse>(data: undefined | void | APIGatewayProxyResultV2<TResponse>): data is APIGatewayProxyStructuredResultV2 {\n return data !== null && data !== undefined && typeof data === 'object' && ('statusCode' in data || 'body' in data);\n}\n\n/**\n * A higher-order function that wraps a typed Lambda handler to provide:\n * 1. Automatic JSON parsing of the request body\n * 2. Error handling with appropriate status codes\n * 3. Consistent response formatting\n *\n * @template TRequestBody - The expected type of the request body after parsing\n * @template TResponse - The expected type of the response\n * @param fn - The Lambda handler function to wrap\n * @returns A standard API Gateway Lambda handler with error handling and type safety\n */\nexport function apiGatewayFunctionDecorator<TRequestBody, TResponse>(fn: APIGatewayProxyHandlerPika<TRequestBody, TResponse>): APIGatewayProxyHandlerV2<TResponse> {\n return async (event, context) => {\n let error: any; // Use 'any' to preserve original error type for instanceof checks\n let response: undefined | void | APIGatewayProxyResultV2<TResponse>;\n\n // Just in case, add another version of the headers with all lowercase keys;\n // helps when running locally. Seems APIGateway automatically converts to lowercase\n Object.keys(event.headers).forEach((k) => {\n let lowerK = k.toLowerCase();\n if (!event.headers[lowerK]) {\n event.headers[lowerK] = event.headers[k];\n }\n });\n try {\n // Parse the request body if present and create a typed event object\n const eventWithType: APIGatewayProxyEventPika<TRequestBody> = {\n ...(event as any),\n body: event.body ? JSON.parse(event.body) : undefined\n };\n\n // Call the handler with the typed event\n response = await fn(eventWithType, context);\n } catch (err) {\n // Capture any errors that occur during processing\n error = err;\n }\n\n // Handle errors by returning an appropriate error response\n if (error) {\n console.error(error);\n\n // Handle HttpStatusError specifically (has required statusCode property)\n if (error instanceof HttpStatusError) {\n return toResponse(error.message, error.statusCode);\n }\n\n // Handle other HttpError types (has optional statusCode property)\n const httpError = error as HttpError;\n const statusCode = httpError.statusCode || 500;\n return toResponse(typeof error === 'string' ? error : error.message, statusCode);\n }\n\n // Return resource not found if the response is undefined\n if (response === undefined) {\n return toResponse(\n {\n message: 'Resource not found',\n code: 'RESOURCE_NOT_FOUND'\n },\n 404\n );\n }\n\n // Either return the structured response directly or wrap the result in a standard response\n return isObjectResponse(response) ? response : toResponse(response, 200);\n };\n}\n\n/**\n * Creates a standardized API Gateway response object.\n * Handles both string and non-string body types by automatically stringifying as needed.\n *\n * @template T - The type of the response body\n * @param body - The response body to send\n * @param statusCode - The HTTP status code (defaults to 200 OK)\n * @returns A properly formatted API Gateway response object\n */\nexport function toResponse<T>(body: T, statusCode = 200): APIGatewayProxyStructuredResultV2 {\n return {\n body: typeof body === 'string' ? body : JSON.stringify(body),\n statusCode\n };\n}\n\n/**\n * Type definition for Lambda Function URL events with additional IAM authorization details.\n * Extends the standard API Gateway event with specific requestContext properties for\n * Function URL integration patterns.\n *\n * @template T - The request body type\n */\nexport type LambdaFunctionUrlProxyEventPika<T = never> = APIGatewayProxyEventPika<T> & {\n requestContext: {\n authorizer?: {\n iam: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n userId?: string;\n user?: string;\n callerId?: string;\n caller?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n identity?: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n user?: string;\n userId?: string;\n caller?: string;\n callerId?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n};\n\n/**\n * Converts a Lambda Function URL event into a standardized API Gateway event.\n * This function ensures that IAM authorization details are properly mapped\n * from the authorizer to the identity property for consistent access patterns.\n *\n * Also, parses the body string into the generic type T if it exists and is a string\n *\n * This exists because the Lambda Function URL event has a different structure\n * than the API Gateway event and we almost never use Lambdas that are Function URL based\n * and so it's easier to just convert the event to a standard API Gateway event than\n * to handle the different event types.\n *\n * @template T - The request body type\n * @param event - The Lambda Function URL event to convert\n * @returns A standardized API Gateway event\n */\nexport function convertFunctionUrlEventToStandardApiGatewayEvent<T>(event: LambdaFunctionUrlProxyEventPika<T>): APIGatewayProxyEventPika<T> {\n if (event.requestContext.identity == null && event.requestContext.authorizer?.iam != null) {\n event.requestContext.identity = event.requestContext.authorizer.iam;\n event.requestContext.authorizer.iam.cognitoIdentityId = event.headers['cognito-identity-id'];\n event.requestContext.authorizer.iam.user = event.requestContext.authorizer.iam.userId;\n event.requestContext.authorizer.iam.caller = event.requestContext.authorizer.iam.callerId;\n }\n\n // Parse the body string into the generic type T if it exists and is a string\n if (event.body && typeof event.body === 'string') {\n try {\n // If content-type is not application/json, don't attempt to parse\n const contentType = event.headers['content-type'] || event.headers['Content-Type'];\n if (contentType && contentType.includes('application/json')) {\n event.body = JSON.parse(event.body) as T;\n }\n } catch (error) {\n console.error('Error parsing request body as JSON:', {\n body: event.body,\n errorMessage: error instanceof Error ? error.message : String(error),\n errorStack: error instanceof Error ? error.stack : undefined\n });\n throw error;\n }\n }\n\n return event;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/api-gateway-utils.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ,CAAA;;;AC+DA,SAAS,iBAA4B,IAAA,EAAwG;AACzI,EAAA,OAAO,IAAA,KAAS,QAAQ,IAAA,KAAS,MAAA,IAAa,OAAO,IAAA,KAAS,QAAA,KAAa,YAAA,IAAgB,IAAA,IAAQ,MAAA,IAAU,IAAA,CAAA;AACjH;AAaO,SAAS,4BAAqD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,CAAA,EAAG;AACzD,QAAA,KAAA,CAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAAA,MACtC;AAAA,IACJ,SAAS,KAAA,EAAO;AACZ,MAAA,OAAA,CAAQ,MAAM,qCAAA,EAAuC;AAAA,QACjD,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,cAAc,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,QACnE,UAAA,EAAY,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,KAAA,GAAQ;AAAA,OACtD,CAAA;AACD,MAAA,MAAM,KAAA;AAAA,IACV;AAAA,EACJ;AAEA,EAAA,OAAO,KAAA;AACX","file":"api-gateway-utils.mjs","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","/**\n * Utility functions and types for AWS API Gateway Lambda integration.\n * This module provides type-safe wrappers and helpers for handling\n * API Gateway events and responses in AWS Lambda functions.\n */\nimport type {\n APIGatewayEventRequestContextV2,\n APIGatewayProxyEventV2WithRequestContext,\n APIGatewayProxyHandlerV2,\n APIGatewayProxyResultV2,\n APIGatewayProxyStructuredResultV2,\n Context\n} from 'aws-lambda';\nimport { HttpStatusError } from './http-status-error';\n\n/**\n * Extends the standard Error interface to include an optional HTTP status code.\n * This allows for standardized error handling with appropriate HTTP responses.\n */\nexport interface HttpError extends Error {\n statusCode?: number;\n}\n\n/**\n * A type that enhances the standard API Gateway event by replacing the body property\n * with a strongly-typed version rather than the default string representation.\n *\n * @template TRequestBody - The type of the request body after parsing\n * @template TRequestContext - The type of the request context\n */\ninterface APIGatewayProxyEventPikaWithRequestContext<TRequestBody, TRequestContext> extends Omit<APIGatewayProxyEventV2WithRequestContext<TRequestContext>, 'body'> {\n body: TRequestBody;\n}\n\n/**\n * A specialized API Gateway event type that includes:\n * 1. A strongly-typed request body\n * 2. The standard API Gateway request context\n * 3. Additional path and httpMethod properties for routing\n *\n * @template TRequestBody - The type of the parsed request body (defaults to never if not provided)\n */\nexport type APIGatewayProxyEventPika<TRequestBody = never> = APIGatewayProxyEventPikaWithRequestContext<TRequestBody, APIGatewayEventRequestContextV2> & {\n path: string;\n httpMethod: string;\n resource: string;\n};\n\n/**\n * A generic handler type for AWS Lambda functions.\n *\n * @template TEvent - The event type (input) for the handler\n * @template TResult - The result type (output) returned by the handler\n * @returns Either void or a Promise containing the result\n */\nexport type HandlerPika<TEvent = unknown, TResult = unknown> = (event: TEvent, context: Context) => void | Promise<TResult>;\n\n/**\n * A specialized handler type for API Gateway Lambda integrations with typed request and response.\n *\n * @template B - The request body type (defaults to never if not provided)\n * @template T - The response type (defaults to never if not provided)\n */\nexport type APIGatewayProxyHandlerPika<B = never, T = never> = HandlerPika<APIGatewayProxyEventPika<B>, APIGatewayProxyResultV2<T>>;\n\n/**\n * Type guard function that determines if the provided data is a structured API Gateway response.\n * A structured response must be an object containing either 'statusCode' or 'body' properties.\n *\n * @template TResponse - The expected response type\n * @param data - The data to check\n * @returns A type predicate indicating if the data is a structured API Gateway response\n */\nfunction isObjectResponse<TResponse>(data: undefined | void | APIGatewayProxyResultV2<TResponse>): data is APIGatewayProxyStructuredResultV2 {\n return data !== null && data !== undefined && typeof data === 'object' && ('statusCode' in data || 'body' in data);\n}\n\n/**\n * A higher-order function that wraps a typed Lambda handler to provide:\n * 1. Automatic JSON parsing of the request body\n * 2. Error handling with appropriate status codes\n * 3. Consistent response formatting\n *\n * @template TRequestBody - The expected type of the request body after parsing\n * @template TResponse - The expected type of the response\n * @param fn - The Lambda handler function to wrap\n * @returns A standard API Gateway Lambda handler with error handling and type safety\n */\nexport function apiGatewayFunctionDecorator<TRequestBody, TResponse>(fn: APIGatewayProxyHandlerPika<TRequestBody, TResponse>): APIGatewayProxyHandlerV2<TResponse> {\n return async (event, context) => {\n let error: any; // Use 'any' to preserve original error type for instanceof checks\n let response: undefined | void | APIGatewayProxyResultV2<TResponse>;\n\n // Just in case, add another version of the headers with all lowercase keys;\n // helps when running locally. Seems APIGateway automatically converts to lowercase\n Object.keys(event.headers).forEach((k) => {\n let lowerK = k.toLowerCase();\n if (!event.headers[lowerK]) {\n event.headers[lowerK] = event.headers[k];\n }\n });\n try {\n // Parse the request body if present and create a typed event object\n const eventWithType: APIGatewayProxyEventPika<TRequestBody> = {\n ...(event as any),\n body: event.body ? JSON.parse(event.body) : undefined\n };\n\n // Call the handler with the typed event\n response = await fn(eventWithType, context);\n } catch (err) {\n // Capture any errors that occur during processing\n error = err;\n }\n\n // Handle errors by returning an appropriate error response\n if (error) {\n console.error(error);\n\n // Handle HttpStatusError specifically (has required statusCode property)\n if (error instanceof HttpStatusError) {\n return toResponse(error.message, error.statusCode);\n }\n\n // Handle other HttpError types (has optional statusCode property)\n const httpError = error as HttpError;\n const statusCode = httpError.statusCode || 500;\n return toResponse(typeof error === 'string' ? error : error.message, statusCode);\n }\n\n // Return resource not found if the response is undefined\n if (response === undefined) {\n return toResponse(\n {\n message: 'Resource not found',\n code: 'RESOURCE_NOT_FOUND'\n },\n 404\n );\n }\n\n // Either return the structured response directly or wrap the result in a standard response\n return isObjectResponse(response) ? response : toResponse(response, 200);\n };\n}\n\n/**\n * Creates a standardized API Gateway response object.\n * Handles both string and non-string body types by automatically stringifying as needed.\n *\n * @template T - The type of the response body\n * @param body - The response body to send\n * @param statusCode - The HTTP status code (defaults to 200 OK)\n * @returns A properly formatted API Gateway response object\n */\nexport function toResponse<T>(body: T, statusCode = 200): APIGatewayProxyStructuredResultV2 {\n return {\n body: typeof body === 'string' ? body : JSON.stringify(body),\n statusCode\n };\n}\n\n/**\n * Type definition for Lambda Function URL events with additional IAM authorization details.\n * Extends the standard API Gateway event with specific requestContext properties for\n * Function URL integration patterns.\n *\n * @template T - The request body type\n */\nexport type LambdaFunctionUrlProxyEventPika<T = never> = APIGatewayProxyEventPika<T> & {\n requestContext: {\n authorizer?: {\n iam: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n userId?: string;\n user?: string;\n callerId?: string;\n caller?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n identity?: {\n cognitoIdentity?: string;\n cognitoIdentityId?: string;\n user?: string;\n userId?: string;\n caller?: string;\n callerId?: string;\n accessKey?: string;\n principalOrgId?: string;\n accountId?: string;\n userArn?: string;\n [key: string]: any;\n };\n };\n};\n\n/**\n * Converts a Lambda Function URL event into a standardized API Gateway event.\n * This function ensures that IAM authorization details are properly mapped\n * from the authorizer to the identity property for consistent access patterns.\n *\n * Also, parses the body string into the generic type T if it exists and is a string\n *\n * This exists because the Lambda Function URL event has a different structure\n * than the API Gateway event and we almost never use Lambdas that are Function URL based\n * and so it's easier to just convert the event to a standard API Gateway event than\n * to handle the different event types.\n *\n * @template T - The request body type\n * @param event - The Lambda Function URL event to convert\n * @returns A standardized API Gateway event\n */\nexport function convertFunctionUrlEventToStandardApiGatewayEvent<T>(event: LambdaFunctionUrlProxyEventPika<T>): APIGatewayProxyEventPika<T> {\n if (event.requestContext.identity == null && event.requestContext.authorizer?.iam != null) {\n event.requestContext.identity = event.requestContext.authorizer.iam;\n event.requestContext.authorizer.iam.cognitoIdentityId = event.headers['cognito-identity-id'];\n event.requestContext.authorizer.iam.user = event.requestContext.authorizer.iam.userId;\n event.requestContext.authorizer.iam.caller = event.requestContext.authorizer.iam.callerId;\n }\n\n // Parse the body string into the generic type T if it exists and is a string\n if (event.body && typeof event.body === 'string') {\n try {\n // If content-type is not application/json, don't attempt to parse\n const contentType = event.headers['content-type'] || event.headers['Content-Type'];\n if (contentType && contentType.includes('application/json')) {\n event.body = JSON.parse(event.body) as T;\n }\n } catch (error) {\n console.error('Error parsing request body as JSON:', {\n body: event.body,\n errorMessage: error instanceof Error ? error.message : String(error),\n errorStack: error instanceof Error ? error.stack : undefined\n });\n throw error;\n }\n }\n\n return event;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/bad-request-error.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/bad-request-error.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ,CAAA;;;ACRO,IAAM,eAAA,GAAN,cAA8B,eAAA,CAAgB;AAAA,EACjD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,GAAG,CAAA;AAAA,EACtB;AACJ","file":"bad-request-error.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","import { HttpStatusError } from './http-status-error';\n\nexport class BadRequestError extends HttpStatusError {\n constructor(message: string) {\n super(message, 400);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/bad-request-error.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/bad-request-error.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ,CAAA;;;ACRO,IAAM,eAAA,GAAN,cAA8B,eAAA,CAAgB;AAAA,EACjD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,GAAG,CAAA;AAAA,EACtB;AACJ","file":"bad-request-error.mjs","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","import { HttpStatusError } from './http-status-error';\n\nexport class BadRequestError extends HttpStatusError {\n constructor(message: string) {\n super(message, 400);\n }\n}\n"]}
|
package/dist/util/bedrock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/chatbot/bedrock-lambda-error.ts","../../src/util/bedrock.ts"],"names":[],"mappings":";;;AAOO,IAAM,kBAAA,GAAN,cAAiC,
|
|
1
|
+
{"version":3,"sources":["../../src/types/chatbot/bedrock-lambda-error.ts","../../src/util/bedrock.ts"],"names":[],"mappings":";;;AAOO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EAC1C,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,OAAO,CAAA;AAAA,EACjB;AACJ,CAAA;;;ACEO,SAAS,kBAAA,CACZ,KAAA,EACA,KAAA,EACA,iBAAA,EACgC;AAChC,EAAA,IAAI,iBAAiB,kBAAA,EAAoB;AACrC,IAAA,OAAO,2BAAA,CAA4B,KAAA,CAAM,OAAA,EAAS,KAAA,CAAM,WAAA,EAAa,MAAM,cAAA,EAAgB,KAAA,CAAM,QAAA,IAAY,yBAAA,EAA2B,iBAAiB,CAAA;AAAA,EAC7J,CAAA,MAAO;AACH,IAAA,OAAA,CAAQ,KAAA,CAAM,qBAAqB,KAAK,CAAA;AACxC,IAAA,MAAM,eAAe,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC1E,IAAA,OAAO,2BAAA,CAA4B,YAAA,EAAc,KAAA,CAAM,WAAA,EAAa,KAAA,CA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K,CAAA;AAC1H,MAAA,OAAO,GAAA;AAAA,IACX,CAAA;AAAA,IACA;AAAC,OACA,EAAC;AAEd;AAWO,SAAS,2BACZ,iBAAA,EACoE;AACpE,EAAA,IAAI,CAAC,iBAAA,IAAqB,MAAA,CAAO,KAAK,iBAAiB,CAAA,CAAE,WAAW,CAAA,EAAG;AACnE,IAAA,OAAO,MAAA;AAAA,EACX;AAEA,EAAA,OAAO,iBAAA;AACX;AAkBO,SAAS,4BACZ,IAAA,EACA,WAAA,EACA,cAAA,EACA,YAAA,EACA,mBACA,MAAA,EACgC;AAChC,EAAA,OAAO;AAAA,IACH,cAAA;AAAA,IACA,QAAA,EAAU;AAAA,MACN,WAAA;AAAA,MACA,QAAA,EAAU,YAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,QACd,GAAI,MAAA,GAAS,EAAE,aAAA,EAAe,SAAA,KAAc,EAAC;AAAA,QAC7C,YAAA,EAAc;AAAA,UACV,IAAA,EAAM;AAAA,YACF,MAAM,OAAO,IAAA,KAAS,WAAW,IAAA,GAAO,IAAA,CAAK,UAAU,IAAI;AAAA;AAC/D;AACJ;AACJ,KACJ;AAAA,IACA;AAAA,GACJ;AACJ","file":"bedrock.js","sourcesContent":["/**\n * This error is used to allow us to distinguish between errors that are\n * expected to be returned to the user and errors that are unexpected.\n *\n * These errors are caught in the Bedrock Lambda and converted into a\n * BedrockLambdaResponse object using the message as the body.\n */\nexport class BedrockLambdaError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n","import { BedrockActionGroupLambdaEvent, BedrockActionGroupLambdaResponse, Parameter } from '../types/chatbot/bedrock';\nimport { BedrockLambdaError } from '../types/chatbot/bedrock-lambda-error';\nimport { RecordOrUndef, SessionDataWithChatUserCustomDataSpreadIn } from '../types/chatbot/chatbot-types';\n\n/**\n * Handles an error and returns a BedrockLambdaResponse object.\n *\n * If the error is an instance of BedrockLambdaError, it will be returned as is.\n * Otherwise, it will be converted to a string and returned as a BedrockLambdaError.\n *\n * @param error The error to handle.\n * @returns A BedrockLambdaResponse object.\n */\nexport function handleBedrockError(\n error: unknown,\n event: BedrockActionGroupLambdaEvent,\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>\n): BedrockActionGroupLambdaResponse {\n if (error instanceof BedrockLambdaError) {\n return createBedrockLambdaResponse(error.message, event.actionGroup, event.messageVersion, event.function ?? 'NoFunctionNameSpecified', sessionAttributes);\n } else {\n console.error('Unexpected error:', error);\n const errorMessage = error instanceof Error ? error.message : String(error);\n return createBedrockLambdaResponse(errorMessage, event.actionGroup, event.messageVersion, event.function ?? 'NoFunctionNameSpecified', sessionAttributes, true);\n }\n}\n\n/**\n * Converter functions for Bedrock parameters.\n */\nexport const converters: Record<string, (v: string) => any> = {\n defaultPassThrough: (v: string) => v,\n number: (v: string) => parseFloat(v),\n boolean: (v: string) => v === 'true',\n integer: (v: string) => parseInt(v),\n array: (v: string) => {\n try {\n // First try to parse as valid JSON\n return JSON.parse(v);\n } catch {\n /* \n TODO: is this a good idea? Why did Bedrock give me a param that was invalid JSON for the array?\n\n {\n \"name\": \"s3Keys\",\n \"type\": \"array\",\n \"value\": \"[uploads/2fbbf97a-070d-48ca-9d5e-fc9bcc88e570/019735c5-b0f0-7419-94d5-093b4202977a_sample-data.csv]\"\n }\n */\n // If JSON.parse fails, try to handle array with unquoted strings\n // Remove brackets and split by comma, then trim whitespace\n if (v.startsWith('[') && v.endsWith(']')) {\n const content = v.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n return content.split(',').map((item) => item.trim());\n }\n // If it doesn't look like an array format, return as single-item array\n return [v];\n }\n }\n};\n\n/**\n * Converts Bedrock parameters to the correct type.\n * @param params - The parameters to convert.\n * @returns A record of parameter names and their converted values.\n */\nexport function convertBedrockParamsToCorrectType(params?: Parameter[]): Record<string, any> {\n return (\n params?.reduce(\n (acc, param) => {\n acc[param.name] = converters[param.type] ? converters[param.type](param.value) : converters.defaultPassThrough(param.value);\n return acc;\n },\n {} as Record<string, any>\n ) ?? {}\n );\n}\n\n/**\n * Normalizes the session attributes, converting the type to T. An empty sessionAttributes object is the\n * same as undefined.\n *\n * Type T is the type of the session attributes.\n *\n * @param sessionAttributes The session attributes.\n * @returns The normalized session attributes.\n */\nexport function normalizeSessionAttributes(\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>\n): SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef> | undefined {\n if (!sessionAttributes || Object.keys(sessionAttributes).length === 0) {\n return undefined;\n }\n\n return sessionAttributes;\n}\n\n/**\n * Creates a BedrockLambdaResponse object.\n *\n * Type T is the type of the session attributes. By including the sessionAttributes\n * parameter, we are telling Bedrock to persist the session attributes for the\n * duration of the session and they will be passed in on all subsequent calls\n * using the event.sessionAttributes parameter.\n *\n * @param body The body of the response.\n * @param actionGroup The action group.\n * @param messageVersion The message version.\n * @param functionName The function name.\n * @param sessionAttributes The session attributes.\n * @param failed Whether the response is a failure.\n * @returns A BedrockLambdaResponse object.\n */\nexport function createBedrockLambdaResponse(\n body: string | Record<string, any>,\n actionGroup: string,\n messageVersion: string,\n functionName: string,\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>,\n failed?: boolean\n): BedrockActionGroupLambdaResponse {\n return {\n messageVersion,\n response: {\n actionGroup,\n function: functionName,\n functionResponse: {\n ...(failed ? { responseState: 'FAILURE' } : {}),\n responseBody: {\n TEXT: {\n body: typeof body === 'string' ? body : JSON.stringify(body)\n }\n }\n }\n },\n sessionAttributes\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/chatbot/bedrock-lambda-error.ts","../../src/util/bedrock.ts"],"names":[],"mappings":";AAOO,IAAM,kBAAA,GAAN,cAAiC,
|
|
1
|
+
{"version":3,"sources":["../../src/types/chatbot/bedrock-lambda-error.ts","../../src/util/bedrock.ts"],"names":[],"mappings":";AAOO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;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AAS,WAAW,IAAA,GAAO,IAAA,CAAK,UAAU,IAAI;AAAA;AAC/D;AACJ;AACJ,KACJ;AAAA,IACA;AAAA,GACJ;AACJ","file":"bedrock.mjs","sourcesContent":["/**\n * This error is used to allow us to distinguish between errors that are\n * expected to be returned to the user and errors that are unexpected.\n *\n * These errors are caught in the Bedrock Lambda and converted into a\n * BedrockLambdaResponse object using the message as the body.\n */\nexport class BedrockLambdaError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n","import { BedrockActionGroupLambdaEvent, BedrockActionGroupLambdaResponse, Parameter } from '../types/chatbot/bedrock';\nimport { BedrockLambdaError } from '../types/chatbot/bedrock-lambda-error';\nimport { RecordOrUndef, SessionDataWithChatUserCustomDataSpreadIn } from '../types/chatbot/chatbot-types';\n\n/**\n * Handles an error and returns a BedrockLambdaResponse object.\n *\n * If the error is an instance of BedrockLambdaError, it will be returned as is.\n * Otherwise, it will be converted to a string and returned as a BedrockLambdaError.\n *\n * @param error The error to handle.\n * @returns A BedrockLambdaResponse object.\n */\nexport function handleBedrockError(\n error: unknown,\n event: BedrockActionGroupLambdaEvent,\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>\n): BedrockActionGroupLambdaResponse {\n if (error instanceof BedrockLambdaError) {\n return createBedrockLambdaResponse(error.message, event.actionGroup, event.messageVersion, event.function ?? 'NoFunctionNameSpecified', sessionAttributes);\n } else {\n console.error('Unexpected error:', error);\n const errorMessage = error instanceof Error ? error.message : String(error);\n return createBedrockLambdaResponse(errorMessage, event.actionGroup, event.messageVersion, event.function ?? 'NoFunctionNameSpecified', sessionAttributes, true);\n }\n}\n\n/**\n * Converter functions for Bedrock parameters.\n */\nexport const converters: Record<string, (v: string) => any> = {\n defaultPassThrough: (v: string) => v,\n number: (v: string) => parseFloat(v),\n boolean: (v: string) => v === 'true',\n integer: (v: string) => parseInt(v),\n array: (v: string) => {\n try {\n // First try to parse as valid JSON\n return JSON.parse(v);\n } catch {\n /* \n TODO: is this a good idea? Why did Bedrock give me a param that was invalid JSON for the array?\n\n {\n \"name\": \"s3Keys\",\n \"type\": \"array\",\n \"value\": \"[uploads/2fbbf97a-070d-48ca-9d5e-fc9bcc88e570/019735c5-b0f0-7419-94d5-093b4202977a_sample-data.csv]\"\n }\n */\n // If JSON.parse fails, try to handle array with unquoted strings\n // Remove brackets and split by comma, then trim whitespace\n if (v.startsWith('[') && v.endsWith(']')) {\n const content = v.slice(1, -1).trim();\n if (content === '') {\n return [];\n }\n return content.split(',').map((item) => item.trim());\n }\n // If it doesn't look like an array format, return as single-item array\n return [v];\n }\n }\n};\n\n/**\n * Converts Bedrock parameters to the correct type.\n * @param params - The parameters to convert.\n * @returns A record of parameter names and their converted values.\n */\nexport function convertBedrockParamsToCorrectType(params?: Parameter[]): Record<string, any> {\n return (\n params?.reduce(\n (acc, param) => {\n acc[param.name] = converters[param.type] ? converters[param.type](param.value) : converters.defaultPassThrough(param.value);\n return acc;\n },\n {} as Record<string, any>\n ) ?? {}\n );\n}\n\n/**\n * Normalizes the session attributes, converting the type to T. An empty sessionAttributes object is the\n * same as undefined.\n *\n * Type T is the type of the session attributes.\n *\n * @param sessionAttributes The session attributes.\n * @returns The normalized session attributes.\n */\nexport function normalizeSessionAttributes(\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>\n): SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef> | undefined {\n if (!sessionAttributes || Object.keys(sessionAttributes).length === 0) {\n return undefined;\n }\n\n return sessionAttributes;\n}\n\n/**\n * Creates a BedrockLambdaResponse object.\n *\n * Type T is the type of the session attributes. By including the sessionAttributes\n * parameter, we are telling Bedrock to persist the session attributes for the\n * duration of the session and they will be passed in on all subsequent calls\n * using the event.sessionAttributes parameter.\n *\n * @param body The body of the response.\n * @param actionGroup The action group.\n * @param messageVersion The message version.\n * @param functionName The function name.\n * @param sessionAttributes The session attributes.\n * @param failed Whether the response is a failure.\n * @returns A BedrockLambdaResponse object.\n */\nexport function createBedrockLambdaResponse(\n body: string | Record<string, any>,\n actionGroup: string,\n messageVersion: string,\n functionName: string,\n sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn<RecordOrUndef>,\n failed?: boolean\n): BedrockActionGroupLambdaResponse {\n return {\n messageVersion,\n response: {\n actionGroup,\n function: functionName,\n functionResponse: {\n ...(failed ? { responseState: 'FAILURE' } : {}),\n responseBody: {\n TEXT: {\n body: typeof body === 'string' ? body : JSON.stringify(body)\n }\n }\n }\n },\n sessionAttributes\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":["camelcaseKeys","snakecaseKeys"],"mappings":";;;;;;;;;;;AAwBO,SAAS,+BAAA,CAAgC,
|
|
1
|
+
{"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":["camelcaseKeys","snakecaseKeys"],"mappings":";;;;;;;;;;;AAwBO,SAAS,+BAAA,CAAgC,MAAA,EAAgB,QAAA,EAAkB,MAAA,EAAwB;AACtG,EAAA,OAAO,CAAA,QAAA,EAAW,MAAM,CAAA,CAAA,EAAI,MAAM,IAAI,QAAQ,CAAA,CAAA;AAClD;AAQO,SAAS,iBAAiB,QAAA,EAA0B;AACvD,EAAA,MAAM,YAAA,GAAe,QAAA,CAAS,WAAA,CAAY,GAAG,CAAA;AAG7C,EAAA,IAAI,iBAAiB,EAAA,IAAM,YAAA,KAAiB,SAAS,MAAA,GAAS,CAAA,IAAK,iBAAiB,CAAA,EAAG;AACnF,IAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAAA,EACjD;AAEA,EAAA,MAAM,oBAAA,GAAuB,QAAA,CAAS,SAAA,CAAU,CAAA,EAAG,YAAY,CAAA;AAC/D,EAAA,MAAM,SAAA,GAAY,QAAA,CAAS,SAAA,CAAU,YAAA,GAAe,CAAC,CAAA;AAErD,EAAA,MAAM,aAAA,GAAgB,oBAAA,CAAqB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AACxE,EAAA,MAAM,kBAAA,GAAqB,SAAA,CAAU,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAElE,EAAA,OAAO,gBAAgB,GAAA,GAAM,kBAAA;AACjC;AAcO,SAAS,mBAAqC,IAAA,EAAuB;AACxE,EAAA,OAAOA,8BAAA,CAAc,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,mBAAqD,IAAA,EAAuB;AACxF,EAAA,OAAOC,8BAAA,CAAc,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,yBAAyB,GAAA,EAAqB;AAC1D,EAAA,MAAM,OAAA,GAAU,EAAE,CAAC,GAAG,GAAG,IAAA,EAAK;AAC9B,EAAA,MAAM,SAAA,GAAYA,+BAAc,OAAO,CAAA;AACvC,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,SAAS,CAAA,CAAE,CAAC,CAAA;AACnC","file":"chatbot-shared-utils.js","sourcesContent":["/**\n * These utilities are meant to be shared both client and server.\n * Don't add anything that can't be shared (especially dependencies)\n */\n\nimport type { ChatApp, ChatAppFeature, FeatureIdType } from '../types/chatbot/chatbot-types';\nimport camelcaseKeys from 'camelcase-keys';\nimport snakecaseKeys from 'snakecase-keys';\n\n/**\n * Generate a unique S3 key name for a chat file upload.\n *\n * Use the uuid module to generate the v7 uuid as in\n *\n * Replace punctation that isn't _ or - with a _\n *\n * import { v7 as uuidv7 } from 'uuid';\n * uuidv7()\n *\n * @param userId - The user id of the user uploading the file\n * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName\n * @param v7Uuid - The uuidv7 uuid of the file\n * @returns The S3 key name for the file\n */\nexport function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string {\n return `uploads/${userId}/${v7Uuid}_${fileName}`;\n}\n\n/**\n * Remove all punctuation from a file name except for the ending period for the file extension if it exists\n *\n * @param fileName - The name of the file to sanitize\n * @returns The sanitized file name\n */\nexport function sanitizeFileName(fileName: string): string {\n const lastDotIndex = fileName.lastIndexOf('.');\n\n // If there's no dot, or the dot is at the end, or the dot is at the beginning, just remove all punctuation\n if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {\n return fileName.replace(/[^a-zA-Z0-9_-]/g, '');\n }\n\n const nameWithoutExtension = fileName.substring(0, lastDotIndex);\n const extension = fileName.substring(lastDotIndex + 1);\n\n const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, '');\n const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, '');\n\n return sanitizedName + '.' + sanitizedExtension;\n}\n\ntype ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;\n\ntype ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;\n\nexport type SnakeCase<T> = {\n [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];\n};\n\nexport type CamelCase<T> = {\n [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];\n};\n\nexport function convertToCamelCase<T extends object>(data: SnakeCase<T>): T {\n return camelcaseKeys(data, { deep: true }) as unknown as T;\n}\n\nexport function convertToSnakeCase<T extends { [key: string]: any }>(data: T): SnakeCase<T> {\n return snakecaseKeys(data, { deep: true }) as SnakeCase<T>;\n}\n\nexport function convertStringToSnakeCase(str: string): string {\n const tempObj = { [str]: true };\n const converted = snakecaseKeys(tempObj);\n return Object.keys(converted)[0];\n}\n\n// /**\n// * This lets us get a feature from a chat app and make sure it is the correct type.\n// */\n// export function getFeature<T extends FeatureIdType>(chatApp: ChatApp, featureId: T): Extract<ChatAppFeature, { featureId: T }> | undefined {\n// const feature = chatApp.features?.[featureId];\n\n// if (feature && feature.featureId === featureId) {\n// return feature as Extract<ChatAppFeature, { featureId: T }>;\n// }\n\n// return undefined;\n// }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":[],"mappings":";;;;AAwBO,SAAS,+BAAA,CAAgC,
|
|
1
|
+
{"version":3,"sources":["../../src/util/chatbot-shared-utils.ts"],"names":[],"mappings":";;;;AAwBO,SAAS,+BAAA,CAAgC,MAAA,EAAgB,QAAA,EAAkB,MAAA,EAAwB;AACtG,EAAA,OAAO,CAAA,QAAA,EAAW,MAAM,CAAA,CAAA,EAAI,MAAM,IAAI,QAAQ,CAAA,CAAA;AAClD;AAQO,SAAS,iBAAiB,QAAA,EAA0B;AACvD,EAAA,MAAM,YAAA,GAAe,QAAA,CAAS,WAAA,CAAY,GAAG,CAAA;AAG7C,EAAA,IAAI,iBAAiB,EAAA,IAAM,YAAA,KAAiB,SAAS,MAAA,GAAS,CAAA,IAAK,iBAAiB,CAAA,EAAG;AACnF,IAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAAA,EACjD;AAEA,EAAA,MAAM,oBAAA,GAAuB,QAAA,CAAS,SAAA,CAAU,CAAA,EAAG,YAAY,CAAA;AAC/D,EAAA,MAAM,SAAA,GAAY,QAAA,CAAS,SAAA,CAAU,YAAA,GAAe,CAAC,CAAA;AAErD,EAAA,MAAM,aAAA,GAAgB,oBAAA,CAAqB,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AACxE,EAAA,MAAM,kBAAA,GAAqB,SAAA,CAAU,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAElE,EAAA,OAAO,gBAAgB,GAAA,GAAM,kBAAA;AACjC;AAcO,SAAS,mBAAqC,IAAA,EAAuB;AACxE,EAAA,OAAO,aAAA,CAAc,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,mBAAqD,IAAA,EAAuB;AACxF,EAAA,OAAO,aAAA,CAAc,IAAA,EAAM,EAAE,IAAA,EAAM,MAAM,CAAA;AAC7C;AAEO,SAAS,yBAAyB,GAAA,EAAqB;AAC1D,EAAA,MAAM,OAAA,GAAU,EAAE,CAAC,GAAG,GAAG,IAAA,EAAK;AAC9B,EAAA,MAAM,SAAA,GAAY,cAAc,OAAO,CAAA;AACvC,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,SAAS,CAAA,CAAE,CAAC,CAAA;AACnC","file":"chatbot-shared-utils.mjs","sourcesContent":["/**\n * These utilities are meant to be shared both client and server.\n * Don't add anything that can't be shared (especially dependencies)\n */\n\nimport type { ChatApp, ChatAppFeature, FeatureIdType } from '../types/chatbot/chatbot-types';\nimport camelcaseKeys from 'camelcase-keys';\nimport snakecaseKeys from 'snakecase-keys';\n\n/**\n * Generate a unique S3 key name for a chat file upload.\n *\n * Use the uuid module to generate the v7 uuid as in\n *\n * Replace punctation that isn't _ or - with a _\n *\n * import { v7 as uuidv7 } from 'uuid';\n * uuidv7()\n *\n * @param userId - The user id of the user uploading the file\n * @param fileName - The name of the file to upload. it should already be sanitized by calling sanitizeFileName\n * @param v7Uuid - The uuidv7 uuid of the file\n * @returns The S3 key name for the file\n */\nexport function generateChatFileUploadS3KeyName(userId: string, fileName: string, v7Uuid: string): string {\n return `uploads/${userId}/${v7Uuid}_${fileName}`;\n}\n\n/**\n * Remove all punctuation from a file name except for the ending period for the file extension if it exists\n *\n * @param fileName - The name of the file to sanitize\n * @returns The sanitized file name\n */\nexport function sanitizeFileName(fileName: string): string {\n const lastDotIndex = fileName.lastIndexOf('.');\n\n // If there's no dot, or the dot is at the end, or the dot is at the beginning, just remove all punctuation\n if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1 || lastDotIndex === 0) {\n return fileName.replace(/[^a-zA-Z0-9_-]/g, '');\n }\n\n const nameWithoutExtension = fileName.substring(0, lastDotIndex);\n const extension = fileName.substring(lastDotIndex + 1);\n\n const sanitizedName = nameWithoutExtension.replace(/[^a-zA-Z0-9_-]/g, '');\n const sanitizedExtension = extension.replace(/[^a-zA-Z0-9_-]/g, '');\n\n return sanitizedName + '.' + sanitizedExtension;\n}\n\ntype ToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${ToSnakeCase<U>}` : S;\n\ntype ToCamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${ToCamelCase<P3>}` : Lowercase<S>;\n\nexport type SnakeCase<T> = {\n [K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K] extends object ? SnakeCase<T[K]> : T[K];\n};\n\nexport type CamelCase<T> = {\n [K in keyof T as K extends string ? ToCamelCase<K> : K]: T[K] extends object ? CamelCase<T[K]> : T[K];\n};\n\nexport function convertToCamelCase<T extends object>(data: SnakeCase<T>): T {\n return camelcaseKeys(data, { deep: true }) as unknown as T;\n}\n\nexport function convertToSnakeCase<T extends { [key: string]: any }>(data: T): SnakeCase<T> {\n return snakecaseKeys(data, { deep: true }) as SnakeCase<T>;\n}\n\nexport function convertStringToSnakeCase(str: string): string {\n const tempObj = { [str]: true };\n const converted = snakecaseKeys(tempObj);\n return Object.keys(converted)[0];\n}\n\n// /**\n// * This lets us get a feature from a chat app and make sure it is the correct type.\n// */\n// export function getFeature<T extends FeatureIdType>(chatApp: ChatApp, featureId: T): Extract<ChatAppFeature, { featureId: T }> | undefined {\n// const feature = chatApp.features?.[featureId];\n\n// if (feature && feature.featureId === featureId) {\n// return feature as Extract<ChatAppFeature, { featureId: T }>;\n// }\n\n// return undefined;\n// }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/forbidden-error.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/forbidden-error.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ,CAAA;;;ACRO,IAAM,cAAA,GAAN,cAA6B,eAAA,CAAgB;AAAA,EAChD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,GAAG,CAAA;AAAA,EACtB;AACJ","file":"forbidden-error.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","import { HttpStatusError } from './http-status-error';\n\nexport class ForbiddenError extends HttpStatusError {\n constructor(message: string) {\n super(message, 403);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/forbidden-error.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts","../../src/util/forbidden-error.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ,CAAA;;;ACRO,IAAM,cAAA,GAAN,cAA6B,eAAA,CAAgB;AAAA,EAChD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,GAAG,CAAA;AAAA,EACtB;AACJ","file":"forbidden-error.mjs","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n","import { HttpStatusError } from './http-status-error';\n\nexport class ForbiddenError extends HttpStatusError {\n constructor(message: string) {\n super(message, 403);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";;;AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ","file":"http-status-error.js","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/util/http-status-error.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACvC,WAAA,CACI,SACgB,UAAA,EAClB;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAAA,EAGpB;AACJ","file":"http-status-error.mjs","sourcesContent":["/**\n * Throw this error to return a specific HTTP status code from an API Gateway Lambda function.\n */\nexport class HttpStatusError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number\n ) {\n super(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is useful when you need to dynamically retrieve the SVG for an icon.
|
|
3
|
+
* It will cache the icon SVG so that it doesn't need to be fetched multiple times.
|
|
4
|
+
* It will also return the same SVG for the same icon name and collection.
|
|
5
|
+
*
|
|
6
|
+
* @param iconName - The name of the icon to retrieve.
|
|
7
|
+
* @param collection - The collection of the icon to retrieve. Today we only support lucide.
|
|
8
|
+
* @returns The SVG for the icon.
|
|
9
|
+
*/
|
|
10
|
+
declare function getIconSvg(iconName: string, collection?: string): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { getIconSvg };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is useful when you need to dynamically retrieve the SVG for an icon.
|
|
3
|
+
* It will cache the icon SVG so that it doesn't need to be fetched multiple times.
|
|
4
|
+
* It will also return the same SVG for the same icon name and collection.
|
|
5
|
+
*
|
|
6
|
+
* @param iconName - The name of the icon to retrieve.
|
|
7
|
+
* @param collection - The collection of the icon to retrieve. Today we only support lucide.
|
|
8
|
+
* @returns The SVG for the icon.
|
|
9
|
+
*/
|
|
10
|
+
declare function getIconSvg(iconName: string, collection?: string): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { getIconSvg };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/util/icon-utils.ts
|
|
4
|
+
var iconCache = {};
|
|
5
|
+
async function getIconSvg(iconName, collection = "lucide") {
|
|
6
|
+
if (collection !== "lucide") {
|
|
7
|
+
throw new Error(`Unsupported collection: ${collection}`);
|
|
8
|
+
}
|
|
9
|
+
if (iconName !== iconName.toLowerCase()) {
|
|
10
|
+
throw new Error(`Icon name must be all lower case and hyphen based: ${iconName}`);
|
|
11
|
+
}
|
|
12
|
+
const iconKey = `${collection}:${iconName}`;
|
|
13
|
+
if (iconCache[iconKey]) {
|
|
14
|
+
return iconCache[iconKey];
|
|
15
|
+
}
|
|
16
|
+
const lucideIconUrl = `https://cdn.jsdelivr.net/npm/lucide-static@0/icons/${iconName}.svg`;
|
|
17
|
+
const response = await fetch(lucideIconUrl);
|
|
18
|
+
let iconSvg = await response.text();
|
|
19
|
+
iconSvg = iconSvg.replace(/width="\d+" height="\d+"/, 'width="24" height="24"');
|
|
20
|
+
iconCache[iconKey] = iconSvg;
|
|
21
|
+
return iconSvg;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.getIconSvg = getIconSvg;
|
|
25
|
+
//# sourceMappingURL=icon-utils.js.map
|
|
26
|
+
//# sourceMappingURL=icon-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/icon-utils.ts"],"names":[],"mappings":";;;AAAA,IAAM,YAAoC,EAAC;AAW3C,eAAsB,UAAA,CAAW,QAAA,EAAkB,UAAA,GAAa,QAAA,EAA2B;AAEvF,EAAA,IAAI,eAAe,QAAA,EAAU;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wBAAA,EAA2B,UAAU,CAAA,CAAE,CAAA;AAAA,EAC3D;AAIA,EAAA,IAAI,QAAA,KAAa,QAAA,CAAS,WAAA,EAAY,EAAG;AACrC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mDAAA,EAAsD,QAAQ,CAAA,CAAE,CAAA;AAAA,EACpF;AAEA,EAAA,MAAM,OAAA,GAAU,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA;AACzC,EAAA,IAAI,SAAA,CAAU,OAAO,CAAA,EAAG;AACpB,IAAA,OAAO,UAAU,OAAO,CAAA;AAAA,EAC5B;AAEA,EAAA,MAAM,aAAA,GAAgB,sDAAsD,QAAQ,CAAA,IAAA,CAAA;AAGpF,EAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,aAAa,CAAA;AAC1C,EAAA,IAAI,OAAA,GAAU,MAAM,QAAA,CAAS,IAAA,EAAK;AAGlC,EAAA,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,0BAAA,EAA4B,wBAAwB,CAAA;AAE9E,EAAA,SAAA,CAAU,OAAO,CAAA,GAAI,OAAA;AACrB,EAAA,OAAO,OAAA;AACX","file":"icon-utils.js","sourcesContent":["const iconCache: Record<string, string> = {};\n\n/**\n * This is useful when you need to dynamically retrieve the SVG for an icon.\n * It will cache the icon SVG so that it doesn't need to be fetched multiple times.\n * It will also return the same SVG for the same icon name and collection.\n *\n * @param iconName - The name of the icon to retrieve.\n * @param collection - The collection of the icon to retrieve. Today we only support lucide.\n * @returns The SVG for the icon.\n */\nexport async function getIconSvg(iconName: string, collection = 'lucide'): Promise<string> {\n // Today we only support lucide\n if (collection !== 'lucide') {\n throw new Error(`Unsupported collection: ${collection}`);\n }\n\n // Lucide icon names must be lower case and they are all hyphen based, not camel case\n // If the icon name isn't all lower case then throw an error so the developer knows to use the correct icon name\n if (iconName !== iconName.toLowerCase()) {\n throw new Error(`Icon name must be all lower case and hyphen based: ${iconName}`);\n }\n\n const iconKey = `${collection}:${iconName}`;\n if (iconCache[iconKey]) {\n return iconCache[iconKey];\n }\n\n const lucideIconUrl = `https://cdn.jsdelivr.net/npm/lucide-static@0/icons/${iconName}.svg`;\n\n // Use fetch to get the icon SVG\n const response = await fetch(lucideIconUrl);\n let iconSvg = await response.text();\n\n // Replace the width and height attributes with width=\"24\" and height=\"24\"\n iconSvg = iconSvg.replace(/width=\"\\d+\" height=\"\\d+\"/, 'width=\"24\" height=\"24\"');\n\n iconCache[iconKey] = iconSvg;\n return iconSvg;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/util/icon-utils.ts
|
|
2
|
+
var iconCache = {};
|
|
3
|
+
async function getIconSvg(iconName, collection = "lucide") {
|
|
4
|
+
if (collection !== "lucide") {
|
|
5
|
+
throw new Error(`Unsupported collection: ${collection}`);
|
|
6
|
+
}
|
|
7
|
+
if (iconName !== iconName.toLowerCase()) {
|
|
8
|
+
throw new Error(`Icon name must be all lower case and hyphen based: ${iconName}`);
|
|
9
|
+
}
|
|
10
|
+
const iconKey = `${collection}:${iconName}`;
|
|
11
|
+
if (iconCache[iconKey]) {
|
|
12
|
+
return iconCache[iconKey];
|
|
13
|
+
}
|
|
14
|
+
const lucideIconUrl = `https://cdn.jsdelivr.net/npm/lucide-static@0/icons/${iconName}.svg`;
|
|
15
|
+
const response = await fetch(lucideIconUrl);
|
|
16
|
+
let iconSvg = await response.text();
|
|
17
|
+
iconSvg = iconSvg.replace(/width="\d+" height="\d+"/, 'width="24" height="24"');
|
|
18
|
+
iconCache[iconKey] = iconSvg;
|
|
19
|
+
return iconSvg;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { getIconSvg };
|
|
23
|
+
//# sourceMappingURL=icon-utils.mjs.map
|
|
24
|
+
//# sourceMappingURL=icon-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/icon-utils.ts"],"names":[],"mappings":";AAAA,IAAM,YAAoC,EAAC;AAW3C,eAAsB,UAAA,CAAW,QAAA,EAAkB,UAAA,GAAa,QAAA,EAA2B;AAEvF,EAAA,IAAI,eAAe,QAAA,EAAU;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wBAAA,EAA2B,UAAU,CAAA,CAAE,CAAA;AAAA,EAC3D;AAIA,EAAA,IAAI,QAAA,KAAa,QAAA,CAAS,WAAA,EAAY,EAAG;AACrC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mDAAA,EAAsD,QAAQ,CAAA,CAAE,CAAA;AAAA,EACpF;AAEA,EAAA,MAAM,OAAA,GAAU,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA;AACzC,EAAA,IAAI,SAAA,CAAU,OAAO,CAAA,EAAG;AACpB,IAAA,OAAO,UAAU,OAAO,CAAA;AAAA,EAC5B;AAEA,EAAA,MAAM,aAAA,GAAgB,sDAAsD,QAAQ,CAAA,IAAA,CAAA;AAGpF,EAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,aAAa,CAAA;AAC1C,EAAA,IAAI,OAAA,GAAU,MAAM,QAAA,CAAS,IAAA,EAAK;AAGlC,EAAA,OAAA,GAAU,OAAA,CAAQ,OAAA,CAAQ,0BAAA,EAA4B,wBAAwB,CAAA;AAE9E,EAAA,SAAA,CAAU,OAAO,CAAA,GAAI,OAAA;AACrB,EAAA,OAAO,OAAA;AACX","file":"icon-utils.mjs","sourcesContent":["const iconCache: Record<string, string> = {};\n\n/**\n * This is useful when you need to dynamically retrieve the SVG for an icon.\n * It will cache the icon SVG so that it doesn't need to be fetched multiple times.\n * It will also return the same SVG for the same icon name and collection.\n *\n * @param iconName - The name of the icon to retrieve.\n * @param collection - The collection of the icon to retrieve. Today we only support lucide.\n * @returns The SVG for the icon.\n */\nexport async function getIconSvg(iconName: string, collection = 'lucide'): Promise<string> {\n // Today we only support lucide\n if (collection !== 'lucide') {\n throw new Error(`Unsupported collection: ${collection}`);\n }\n\n // Lucide icon names must be lower case and they are all hyphen based, not camel case\n // If the icon name isn't all lower case then throw an error so the developer knows to use the correct icon name\n if (iconName !== iconName.toLowerCase()) {\n throw new Error(`Icon name must be all lower case and hyphen based: ${iconName}`);\n }\n\n const iconKey = `${collection}:${iconName}`;\n if (iconCache[iconKey]) {\n return iconCache[iconKey];\n }\n\n const lucideIconUrl = `https://cdn.jsdelivr.net/npm/lucide-static@0/icons/${iconName}.svg`;\n\n // Use fetch to get the icon SVG\n const response = await fetch(lucideIconUrl);\n let iconSvg = await response.text();\n\n // Replace the width and height attributes with width=\"24\" and height=\"24\"\n iconSvg = iconSvg.replace(/width=\"\\d+\" height=\"\\d+\"/, 'width=\"24\" height=\"24\"');\n\n iconCache[iconKey] = iconSvg;\n return iconSvg;\n}\n"]}
|
|
@@ -35,6 +35,33 @@ declare function generateInstructionAssistanceContent(instructionAssistanceConfi
|
|
|
35
35
|
* Apply instruction assistance to the base prompt using placeholder replacement
|
|
36
36
|
*/
|
|
37
37
|
declare function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string;
|
|
38
|
+
/**
|
|
39
|
+
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
*
|
|
41
|
+
* See header at top of file for important notes.
|
|
42
|
+
*
|
|
43
|
+
* Generate component-specific instruction content for direct component invocations
|
|
44
|
+
*
|
|
45
|
+
* @param tagDefinition - The tag definition with component invocation instructions
|
|
46
|
+
* @param componentAgentInstructionName - The name of the instruction set to use
|
|
47
|
+
* @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement
|
|
48
|
+
* @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced
|
|
49
|
+
* @returns The component instruction content or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
declare function generateComponentInstructionContent(tagDefinition: TagDefinition<TagDefinitionWidget>, componentAgentInstructionName: string, instructionAssistanceConfig?: InstructionAssistanceConfig, agentInstructionFeature?: AgentInstructionChatAppOverridableFeature): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
54
|
+
*
|
|
55
|
+
* See header at top of file for important notes.
|
|
56
|
+
*
|
|
57
|
+
* Apply instruction assistance placeholder replacement to component instructions
|
|
58
|
+
*
|
|
59
|
+
* @param componentInstructions - The raw component instructions with placeholders
|
|
60
|
+
* @param instructionConfig - The instruction assistance configuration
|
|
61
|
+
* @param agentInstructionFeature - The agent instruction feature configuration
|
|
62
|
+
* @returns The component instructions with placeholders replaced
|
|
63
|
+
*/
|
|
64
|
+
declare function applyComponentInstructionAssistance(componentInstructions: string, instructionConfig: InstructionAssistanceConfig, agentInstructionFeature: AgentInstructionChatAppOverridableFeature): string;
|
|
38
65
|
/**
|
|
39
66
|
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
40
67
|
*
|
|
@@ -47,4 +74,4 @@ declare function applyInstructionAssistance(basePrompt: string, instructionConte
|
|
|
47
74
|
*/
|
|
48
75
|
declare function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig;
|
|
49
76
|
|
|
50
|
-
export { applyInstructionAssistance, generateInstructionAssistanceContent, getInstructionsAssistanceConfigFromRawSsmParams };
|
|
77
|
+
export { applyComponentInstructionAssistance, applyInstructionAssistance, generateComponentInstructionContent, generateInstructionAssistanceContent, getInstructionsAssistanceConfigFromRawSsmParams };
|
|
@@ -35,6 +35,33 @@ declare function generateInstructionAssistanceContent(instructionAssistanceConfi
|
|
|
35
35
|
* Apply instruction assistance to the base prompt using placeholder replacement
|
|
36
36
|
*/
|
|
37
37
|
declare function applyInstructionAssistance(basePrompt: string, instructionContent: InstructionAssistanceConfig): string;
|
|
38
|
+
/**
|
|
39
|
+
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
*
|
|
41
|
+
* See header at top of file for important notes.
|
|
42
|
+
*
|
|
43
|
+
* Generate component-specific instruction content for direct component invocations
|
|
44
|
+
*
|
|
45
|
+
* @param tagDefinition - The tag definition with component invocation instructions
|
|
46
|
+
* @param componentAgentInstructionName - The name of the instruction set to use
|
|
47
|
+
* @param instructionAssistanceConfig - Optional instruction assistance config for placeholder replacement
|
|
48
|
+
* @param agentInstructionFeature - Optional agent instruction feature to control which placeholders are replaced
|
|
49
|
+
* @returns The component instruction content or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
declare function generateComponentInstructionContent(tagDefinition: TagDefinition<TagDefinitionWidget>, componentAgentInstructionName: string, instructionAssistanceConfig?: InstructionAssistanceConfig, agentInstructionFeature?: AgentInstructionChatAppOverridableFeature): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
54
|
+
*
|
|
55
|
+
* See header at top of file for important notes.
|
|
56
|
+
*
|
|
57
|
+
* Apply instruction assistance placeholder replacement to component instructions
|
|
58
|
+
*
|
|
59
|
+
* @param componentInstructions - The raw component instructions with placeholders
|
|
60
|
+
* @param instructionConfig - The instruction assistance configuration
|
|
61
|
+
* @param agentInstructionFeature - The agent instruction feature configuration
|
|
62
|
+
* @returns The component instructions with placeholders replaced
|
|
63
|
+
*/
|
|
64
|
+
declare function applyComponentInstructionAssistance(componentInstructions: string, instructionConfig: InstructionAssistanceConfig, agentInstructionFeature: AgentInstructionChatAppOverridableFeature): string;
|
|
38
65
|
/**
|
|
39
66
|
* IMPORTANT!!!!!!!!!!!!!!!!!!!!!!
|
|
40
67
|
*
|
|
@@ -47,4 +74,4 @@ declare function applyInstructionAssistance(basePrompt: string, instructionConte
|
|
|
47
74
|
*/
|
|
48
75
|
declare function getInstructionsAssistanceConfigFromRawSsmParams(params: Record<string, string>): InstructionAssistanceConfig;
|
|
49
76
|
|
|
50
|
-
export { applyInstructionAssistance, generateInstructionAssistanceContent, getInstructionsAssistanceConfigFromRawSsmParams };
|
|
77
|
+
export { applyComponentInstructionAssistance, applyInstructionAssistance, generateComponentInstructionContent, generateInstructionAssistanceContent, getInstructionsAssistanceConfigFromRawSsmParams };
|