@adaptic/lumic-utils 1.0.6 → 1.0.8

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.
Files changed (87) hide show
  1. package/dist/apollo-client.client-DE7JUXjy.js +3693 -0
  2. package/dist/apollo-client.client-DE7JUXjy.js.map +1 -0
  3. package/dist/apollo-client.client-DlG4HsFm.js +3704 -0
  4. package/dist/apollo-client.client-DlG4HsFm.js.map +1 -0
  5. package/dist/apollo-client.server-D1QJea5_.js +16319 -0
  6. package/dist/apollo-client.server-D1QJea5_.js.map +1 -0
  7. package/dist/apollo-client.server-uqalq3yp.js +16321 -0
  8. package/dist/apollo-client.server-uqalq3yp.js.map +1 -0
  9. package/dist/index-Bd84zcTQ.js +74944 -0
  10. package/dist/index-Bd84zcTQ.js.map +1 -0
  11. package/dist/index-CZKOqrJ4.js +75137 -0
  12. package/dist/index-CZKOqrJ4.js.map +1 -0
  13. package/dist/index-CsKfs4nG.js +12108 -0
  14. package/dist/index-CsKfs4nG.js.map +1 -0
  15. package/dist/{index-CcXQeJz8.js → index-Cstek604.js} +182 -22
  16. package/dist/index-Cstek604.js.map +1 -0
  17. package/dist/{index-CcgbRft2.js → index-DZZCd-1T.js} +182 -22
  18. package/dist/index-DZZCd-1T.js.map +1 -0
  19. package/dist/index-aP9ow8_W.js +12271 -0
  20. package/dist/index-aP9ow8_W.js.map +1 -0
  21. package/dist/index.cjs +122 -11417
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.mjs +39 -11399
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/test.cjs +24 -7
  26. package/dist/test.cjs.map +1 -1
  27. package/dist/test.mjs +24 -7
  28. package/dist/test.mjs.map +1 -1
  29. package/dist/types/aws-types.ts +1 -1
  30. package/dist/types/config/__tests__/secrets.test.d.ts +1 -0
  31. package/dist/types/config/secrets.d.ts +186 -0
  32. package/dist/types/errors/__tests__/errors.test.d.ts +1 -0
  33. package/dist/types/errors/index.d.ts +77 -0
  34. package/dist/types/functions/__tests__/aws-lambda.test.d.ts +1 -0
  35. package/dist/types/functions/__tests__/aws-s3-utils.test.d.ts +1 -0
  36. package/dist/types/functions/__tests__/json-llm-tools.test.d.ts +1 -0
  37. package/dist/types/functions/__tests__/json-tools.test.d.ts +1 -0
  38. package/dist/types/functions/__tests__/slack-utils.test.d.ts +1 -0
  39. package/dist/types/functions/aws-lambda.d.ts +1 -1
  40. package/dist/types/functions/aws-s3-utils.d.ts +2 -2
  41. package/dist/types/functions/google-sheets.d.ts +4 -4
  42. package/dist/types/functions/json-llm-tools.d.ts +25 -3
  43. package/dist/types/functions/llm-call.d.ts +2 -2
  44. package/dist/types/functions/llm-deepseek.d.ts +1 -1
  45. package/dist/types/functions/llm-openai.d.ts +3 -2
  46. package/dist/types/functions/llm-utils.d.ts +24 -1
  47. package/dist/types/functions/slack-utils.d.ts +3 -4
  48. package/dist/types/functions/utils.d.ts +2 -14
  49. package/dist/types/functions/zip-utils.d.ts +12 -10
  50. package/dist/types/google-types.ts +6 -3
  51. package/dist/types/index.d.ts +30 -0
  52. package/dist/types/index.ts +1 -1
  53. package/dist/types/openai-types.ts +165 -6
  54. package/dist/types/schemas/aws-schemas.d.ts +210 -0
  55. package/dist/types/schemas/google-sheets-schemas.d.ts +32 -0
  56. package/dist/types/schemas/index.d.ts +17 -0
  57. package/dist/types/schemas/openai-schemas.d.ts +834 -0
  58. package/dist/types/schemas/perplexity-schemas.d.ts +338 -0
  59. package/dist/types/schemas/validation-helpers.d.ts +33 -0
  60. package/dist/types/types/aws-types.d.ts +1 -1
  61. package/dist/types/types/google-types.d.ts +5 -3
  62. package/dist/types/types/index.d.ts +1 -1
  63. package/dist/types/types/openai-types.d.ts +149 -3
  64. package/dist/types/utils/__tests__/circuit-breaker.test.d.ts +1 -0
  65. package/dist/types/utils/__tests__/correlation.test.d.ts +1 -0
  66. package/dist/types/utils/__tests__/input-validator.test.d.ts +1 -0
  67. package/dist/types/utils/__tests__/llm-cost-tracker.test.d.ts +1 -0
  68. package/dist/types/utils/__tests__/logger.test.d.ts +1 -0
  69. package/dist/types/utils/__tests__/metrics.test.d.ts +1 -0
  70. package/dist/types/utils/__tests__/retry.test.d.ts +1 -0
  71. package/dist/types/utils/__tests__/sanitizer.test.d.ts +1 -0
  72. package/dist/types/utils/__tests__/timeouts.test.d.ts +1 -0
  73. package/dist/types/utils/aws-initialise.d.ts +6 -1
  74. package/dist/types/utils/circuit-breaker.d.ts +99 -0
  75. package/dist/types/utils/correlation.d.ts +43 -0
  76. package/dist/types/utils/health-check.d.ts +50 -0
  77. package/dist/types/utils/input-validator.d.ts +51 -0
  78. package/dist/types/utils/llm-cost-tracker.d.ts +174 -0
  79. package/dist/types/utils/logger.d.ts +8 -0
  80. package/dist/types/utils/metrics.d.ts +61 -0
  81. package/dist/types/utils/rate-limiter.d.ts +85 -0
  82. package/dist/types/utils/retry.d.ts +58 -0
  83. package/dist/types/utils/sanitizer.d.ts +30 -0
  84. package/dist/types/utils/timeouts.d.ts +44 -0
  85. package/package.json +17 -5
  86. package/dist/index-CcXQeJz8.js.map +0 -1
  87. package/dist/index-CcgbRft2.js.map +0 -1
@@ -14,4 +14,4 @@ import { LambdaResponse, InvocationType } from '../types';
14
14
  * @throws If the Lambda function returns an invalid response
15
15
  * @returns A LambdaResponse object with a statusCode and a body
16
16
  */
17
- export declare const invokeLambdaFunction: (functionName: string, payload?: Record<string, any>, invocationType?: InvocationType, auth?: AWSAuth | null) => Promise<LambdaResponse>;
17
+ export declare const invokeLambdaFunction: (functionName: string, payload?: Record<string, unknown>, invocationType?: InvocationType, auth?: AWSAuth | null) => Promise<LambdaResponse>;
@@ -31,7 +31,7 @@ export declare const createS3: (bucketName: string, auth?: AWSAuth | null) => Pr
31
31
  /**
32
32
  * Uploads a file or directory to an S3 bucket.
33
33
  * @param {string} bucketName - The name of the S3 bucket to upload to.
34
- * @param {string} sourcePath - The path to the file or directory to upload.
34
+ * @param {string} sourcePath - The path to the file or directory to upload. Must start with an allowed path (configurable via LUMIC_ALLOWED_UPLOAD_PATHS environment variable, defaults to '/tmp'). Path traversal (..) is not allowed.
35
35
  * @param {Object} [options] - Optional parameters.
36
36
  * @param {string} [options.destinationPath] - The path to the destination in the S3 bucket.
37
37
  * @param {AWSAuth} [options.auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain.
@@ -59,7 +59,7 @@ export declare function readS3File(bucket: string, key: string, auth?: AWSAuth |
59
59
  * Downloads files from S3 to a local directory.
60
60
  * @param {string} bucketName - The name of the S3 bucket to download from.
61
61
  * @param {string} [s3Path=''] - The path in the S3 bucket to start downloading from. Defaults to the root of the bucket.
62
- * @param {string} [localPath='/tmp'] - The local directory to download the files to. Defaults to '/tmp'.
62
+ * @param {string} [localPath] - The local directory to download the files to. Defaults to os.tmpdir().
63
63
  * @param {AWSAuth} [auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain.
64
64
  * @returns {Promise<AWSApiResponse>} - A Promise that resolves with an AWSApiResponse object.
65
65
  * @example
@@ -1,4 +1,4 @@
1
- import { GoogleSheetConfig, GoogleSheetCell, GoogleSheetAddRowResponse, GoogleSheetAddSheetResponse, GoogleSheetCellResponse, GoogleSheetWriteArrayResponse } from '../types';
1
+ import { GoogleSheetConfig, GoogleSheetCell, GoogleSheetCellValue, GoogleSheetAddRowResponse, GoogleSheetAddSheetResponse, GoogleSheetCellResponse, GoogleSheetWriteArrayResponse } from '../types';
2
2
  import 'dotenv/config';
3
3
  /**
4
4
  * Adds a row of values to the bottom of a specified Google Sheet
@@ -7,7 +7,7 @@ import 'dotenv/config';
7
7
  * @param startColumn Optional starting column (defaults to 'A')
8
8
  * @returns Promise resolving to response with success status and row details
9
9
  */
10
- export declare function addRow(config: GoogleSheetConfig, values: any[], startColumn?: string): Promise<GoogleSheetAddRowResponse>;
10
+ export declare function addRow(config: GoogleSheetConfig, values: GoogleSheetCellValue[], startColumn?: string): Promise<GoogleSheetAddRowResponse>;
11
11
  /**
12
12
  * Adds a new sheet to an existing Google Spreadsheet
13
13
  * @param spreadsheetId The ID of the spreadsheet to add the sheet to
@@ -22,7 +22,7 @@ export declare function addSheet(spreadsheetId: string, sheetTitle: string): Pro
22
22
  * @param value The value to write
23
23
  * @returns Promise resolving to response with success status
24
24
  */
25
- export declare function writeCell(config: GoogleSheetConfig, cell: GoogleSheetCell, value: any): Promise<GoogleSheetCellResponse>;
25
+ export declare function writeCell(config: GoogleSheetConfig, cell: GoogleSheetCell, value: GoogleSheetCellValue): Promise<GoogleSheetCellResponse>;
26
26
  /**
27
27
  * Gets the value from a specific cell in a Google Sheet
28
28
  * @param config The sheet configuration containing spreadsheetId and sheetName
@@ -37,4 +37,4 @@ export declare function getCell(config: GoogleSheetConfig, cell: GoogleSheetCell
37
37
  * @param startCell Optional starting cell in A1 notation (defaults to 'A1')
38
38
  * @returns Promise resolving to response with success status and update details
39
39
  */
40
- export declare function writeArray(config: GoogleSheetConfig, data: any[][], startCell?: string): Promise<GoogleSheetWriteArrayResponse>;
40
+ export declare function writeArray(config: GoogleSheetConfig, data: GoogleSheetCellValue[][], startCell?: string): Promise<GoogleSheetWriteArrayResponse>;
@@ -1,12 +1,34 @@
1
1
  import { JsonValue } from '../types';
2
+ /**
3
+ * Options for AI-powered JSON fixing
4
+ */
5
+ export interface FixJsonWithAIOptions {
6
+ /**
7
+ * The OpenAI API key to use, or undefined to use the value of the OPENAI_API_KEY environment variable
8
+ */
9
+ apiKey?: string;
10
+ /**
11
+ * Maximum recursion depth to prevent infinite loops.
12
+ * @default 2
13
+ */
14
+ maxDepth?: number;
15
+ /**
16
+ * Internal: Current recursion depth. Do not set manually.
17
+ * @internal
18
+ */
19
+ _depth?: number;
20
+ }
2
21
  /**
3
22
  * Fixes broken JSON by sending it to the OpenAI gpt-5 model as a chat completion.
4
23
  * The gpt-5 model is a large language model that can understand and generate code,
5
24
  * including JSON. The returned JSON is the fixed version of the input JSON.
6
25
  * If the model fails to return valid JSON, an error is thrown.
26
+ *
27
+ * WARNING: This function uses AI and adds cost and latency. Use sparingly.
28
+ *
7
29
  * @param jsonStr - the broken JSON to fix
8
- * @param apiKey - the OpenAI API key to use, or undefined to use the value of the OPENAI_API_KEY environment variable
30
+ * @param options - configuration options including API key and recursion limits
9
31
  * @returns the fixed JSON
10
- * @throws an error if the model fails to return valid JSON
32
+ * @throws an error if the model fails to return valid JSON or max depth is exceeded
11
33
  */
12
- export declare function fixJsonWithAI(jsonStr: string, apiKey?: string): Promise<JsonValue>;
34
+ export declare function fixJsonWithAI(jsonStr: string, options?: string | FixJsonWithAIOptions): Promise<JsonValue>;
@@ -9,7 +9,7 @@ import { Tool } from 'openai/resources/responses/responses';
9
9
  * @param options The options for the LLM call. Defaults to an empty object.
10
10
  * @return A promise that resolves to the response from the LLM.
11
11
  */
12
- export declare function makeLLMCall<T = any>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions): Promise<LLMResponse<T>>;
12
+ export declare function makeLLMCall<T = unknown>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions): Promise<LLMResponse<T>>;
13
13
  /**
14
14
  * Makes a call to the OpenAI Responses API for advanced use cases with built-in tools.
15
15
  *
@@ -17,7 +17,7 @@ export declare function makeLLMCall<T = any>(content: string | ChatCompletionCon
17
17
  * @param options The options for the Responses API call, including optional image data.
18
18
  * @return A promise that resolves to the response from the Responses API.
19
19
  */
20
- export declare function makeResponsesCall<T = any>(input: string, options?: {
20
+ export declare function makeResponsesCall<T = unknown>(input: string, options?: {
21
21
  apiKey?: string;
22
22
  model?: OpenAIModel;
23
23
  responseFormat?: 'text' | 'json';
@@ -8,4 +8,4 @@ import { LLMResponse, LLMOptions, OpenAIResponseFormat } from '../types';
8
8
  * @param options Configuration options including model ('deepseek-chat' or 'deepseek-reasoner'), tools, and apiKey.
9
9
  * @return A promise that resolves to the response from the Deepseek API.
10
10
  */
11
- export declare const makeDeepseekCall: <T = any>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
11
+ export declare const makeDeepseekCall: <T = unknown>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
@@ -22,7 +22,7 @@ export declare function isReasoningModel(model: string): boolean;
22
22
  * @param options The options for the LLM call. Defaults to an empty object.
23
23
  * @return A promise that resolves to the response from the LLM.
24
24
  */
25
- export declare const makeOpenAIChatCompletionCall: <T = any>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
25
+ export declare const makeOpenAIChatCompletionCall: <T = unknown>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
26
26
  /**
27
27
  * Makes a call to OpenAI's Responses API for more advanced use cases with built-in tools.
28
28
  *
@@ -49,7 +49,8 @@ export declare const makeOpenAIChatCompletionCall: <T = any>(content: string | C
49
49
  * @returns Promise<LLMResponse<T>> - The response in the same format as makeOpenAIChatCompletionCall
50
50
  * @throws Error if the API call fails
51
51
  */
52
- export declare const makeResponsesAPICall: <T = any>(input: string | ResponseCreateParamsNonStreaming["input"], options?: Omit<ResponseCreateParamsNonStreaming, "input" | "model"> & {
52
+ export declare const makeResponsesAPICall: <T = unknown>(input: string | ResponseCreateParamsNonStreaming["input"], options?: Omit<ResponseCreateParamsNonStreaming, "input" | "model"> & {
53
53
  apiKey?: string;
54
54
  model?: string;
55
+ timeout?: number;
55
56
  }) => Promise<LLMResponse<T>>;
@@ -1,6 +1,28 @@
1
1
  import { OpenAIResponseFormat } from '../types';
2
2
  export declare function normalizeModelName(model: string): string;
3
3
  export declare const CODE_BLOCK_TYPES: string[];
4
+ /**
5
+ * Options for JSON parsing behavior
6
+ */
7
+ export interface ParseJsonOptions {
8
+ /**
9
+ * Enable AI-powered JSON fixing as a fallback strategy.
10
+ * Warning: This adds cost and latency. Disabled by default.
11
+ * @default false
12
+ */
13
+ enableAiFix?: boolean;
14
+ /**
15
+ * Maximum number of times to retry AI fixing if it returns broken JSON.
16
+ * Only applies when enableAiFix is true.
17
+ * @default 2
18
+ */
19
+ maxRetries?: number;
20
+ /**
21
+ * Internal: Current recursion depth. Do not set manually.
22
+ * @internal
23
+ */
24
+ _recursionDepth?: number;
25
+ }
4
26
  /**
5
27
  * Tries to parse JSON from the given content string according to the specified
6
28
  * response format. If the response format is 'json' or a JSON schema object, it
@@ -10,6 +32,7 @@ export declare const CODE_BLOCK_TYPES: string[];
10
32
  *
11
33
  * @param content The content string to parse
12
34
  * @param responseFormat The desired format of the response
35
+ * @param options Optional parsing configuration
13
36
  * @returns The parsed JSON object or null if it fails
14
37
  */
15
- export declare function parseResponse<T>(content: string, responseFormat: OpenAIResponseFormat): Promise<T | null>;
38
+ export declare function parseResponse<T>(content: string, responseFormat: OpenAIResponseFormat, options?: ParseJsonOptions): Promise<T | null>;
@@ -1,11 +1,10 @@
1
- /************* ✨ Codeium Command ⭐ *************/
2
1
  /**
3
2
  * Sends a message to a Slack channel.
4
3
  *
5
4
  * @param channel - The channel to send the message to.
6
5
  * @param message - The message to send.
7
6
  * @param slackBotToken - The slack bot token to use. If not provided, the SLACK_BOT_TOKEN environment variable will be used.
8
- * @returns A promise that resolves to true if the message is sent successfully, false otherwise.
9
-
10
- /****** 739f6db2-05ce-46a9-b3f6-9d22cffb8c30 *******/
7
+ * @returns A promise that resolves to true if the message is sent successfully.
8
+ * @throws {Error} If the Slack API request fails or returns an error status.
9
+ */
11
10
  export declare const sendMessageToSlack: (channel: string, message: string, slackBotToken?: string) => Promise<boolean>;
@@ -1,5 +1,4 @@
1
- declare const LOG_TYPES: readonly ["info", "warn", "error", "debug", "trace"];
2
- type LogType = typeof LOG_TYPES[number];
1
+ type LogType = 'info' | 'warn' | 'error' | 'debug' | 'trace';
3
2
  /**
4
3
  * Debug logging utility that respects environment debug flags
5
4
  * @param message - The message to log
@@ -7,16 +6,5 @@ type LogType = typeof LOG_TYPES[number];
7
6
  * @param type - Log level. One of: 'info' | 'warn' | 'error' | 'debug' | 'trace'
8
7
  */
9
8
  export declare const logIfDebug: (message: string, data?: unknown, type?: LogType) => void;
10
- /**
11
- * Fetches a URL with retry logic. If the response is not 2xx, it will retry up to `retries` times
12
- * with an exponential backoff of `backoff` milliseconds between each attempt.
13
- *
14
- * @param url The URL to fetch
15
- * @param options Optional `RequestInit` object to modify the request
16
- * @param retries The number of times to retry the request (default: 3)
17
- * @param backoff The initial backoff time in milliseconds (default: 300)
18
- * @returns A `Response` object if the fetch is successful
19
- * @throws An error if the fetch fails after all retries
20
- */
21
- export declare function fetchWithRetry(url: string, options?: RequestInit, retries?: number, backoff?: number): Promise<Response>;
9
+ export declare const fetchWithRetry: typeof import("@adaptic/utils/dist/types/misc-utils").fetchWithRetry;
22
10
  export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Creates a zip file containing the contents of the provided directory.
3
- * The zip file is created in the /tmp directory.
4
- * The source directory must be located in the /tmp directory.
3
+ * The zip file is created in the configured temp directory (default: os.tmpdir()).
4
+ * The source directory must be within an allowed path (configurable via LUMIC_ALLOWED_UPLOAD_PATHS).
5
5
  * The zip file name is the same as the source directory name with a .zip extension.
6
6
  * If a node_modules directory exists in the source directory,
7
7
  * it is added separately to ensure it is included in the zip file.
@@ -14,25 +14,27 @@ export declare function createZipFile(sourceDir: string): Promise<string>;
14
14
  /**
15
15
  * Extracts a zip archive into a specified directory.
16
16
  *
17
- * Both the zip file path and destination path must start with /tmp/.
17
+ * Both the zip file path and destination path must be within an allowed path
18
+ * (configurable via LUMIC_ALLOWED_UPLOAD_PATHS, defaults to os.tmpdir()).
18
19
  *
19
- * @param zipPath The path of the zip file to extract. Must start with /tmp/.
20
- * @param destPath The path of the directory to extract the zip file into. Must start with /tmp/.
20
+ * @param zipPath The path of the zip file to extract.
21
+ * @param destPath The path of the directory to extract the zip file into.
21
22
  * @returns The path of the extracted directory.
22
- * @throws If the zip file or destination path does not start with /tmp/.
23
+ * @throws If the paths are not within allowed paths.
23
24
  * @throws If there is an error extracting the zip file.
24
25
  */
25
26
  export declare function extractZipFile(zipPath: string, destPath: string): Promise<string>;
26
27
  /**
27
28
  * Adds a file or directory to an existing zip file.
28
29
  *
29
- * The zip file path and item path must start with /tmp/.
30
+ * The zip file path and item path must be within an allowed path
31
+ * (configurable via LUMIC_ALLOWED_UPLOAD_PATHS, defaults to os.tmpdir()).
30
32
  *
31
- * @param zipFilePath The path of the zip file to add the item to. Must start with /tmp/.
32
- * @param itemPath The path of the item to add to the zip file. Must start with /tmp/.
33
+ * @param zipFilePath The path of the zip file to add the item to.
34
+ * @param itemPath The path of the item to add to the zip file.
33
35
  * @param destPath Optional. The destination path inside the zip file to add the item to. Defaults to the root of the zip file.
34
36
  * @returns The path of the updated zip file.
35
- * @throws If the zip file or item path does not start with /tmp/.
37
+ * @throws If the paths are not within allowed paths.
36
38
  * @throws If there is an error adding the item to the zip file.
37
39
  */
38
40
  export declare function addToZipFile(zipFilePath: string, itemPath: string, destPath?: string): Promise<string>;
@@ -13,16 +13,19 @@ export interface GoogleSheetRange {
13
13
  endCell: GoogleSheetCell;
14
14
  }
15
15
 
16
+ /** Represents a primitive value that can be stored in a Google Sheet cell */
17
+ export type GoogleSheetCellValue = string | number | boolean | null;
18
+
16
19
  export interface GoogleSheetResponse {
17
20
  success: boolean;
18
21
  error?: string;
19
- data?: any;
22
+ data?: unknown;
20
23
  }
21
24
 
22
25
  export interface GoogleSheetAddRowResponse extends GoogleSheetResponse {
23
26
  data?: {
24
27
  rowNumber: number;
25
- values: any[];
28
+ values: GoogleSheetCellValue[];
26
29
  };
27
30
  }
28
31
 
@@ -35,7 +38,7 @@ export interface GoogleSheetAddSheetResponse extends GoogleSheetResponse {
35
38
 
36
39
  export interface GoogleSheetCellResponse extends GoogleSheetResponse {
37
40
  data?: {
38
- value: any;
41
+ value: GoogleSheetCellValue;
39
42
  };
40
43
  }
41
44
 
@@ -14,7 +14,37 @@ import { createPDFFromMarkdown } from './functions/pdf-create';
14
14
  import { addRow, addSheet, writeCell, getCell, writeArray } from './functions/google-sheets';
15
15
  import { parseResponse } from './functions/llm-utils';
16
16
  import { tools } from './llm-tools';
17
+ import { LumicLogger, setLumicLogger, getLumicLogger } from './utils/logger';
18
+ import { sanitizeForLog, sanitizeError, sanitizeAWSAuth, sanitizeObject } from './utils/sanitizer';
17
19
  export * from './types';
20
+ export * from './errors';
21
+ export * from './utils/timeouts';
22
+ export { LumicLogger, setLumicLogger, getLumicLogger };
23
+ export { sanitizeForLog, sanitizeError, sanitizeAWSAuth, sanitizeObject };
24
+ export { getSecrets, resetSecrets, requireSecret } from './config/secrets';
25
+ export type { LumicSecrets } from './config/secrets';
26
+ export { withRetry } from './utils/retry';
27
+ export type { RetryConfig } from './utils/retry';
28
+ export { CircuitBreaker, CircuitBreakerState, CircuitBreakerOpenError, DEFAULT_CIRCUIT_BREAKER_CONFIG, } from './utils/circuit-breaker';
29
+ export type { CircuitBreakerConfig, CircuitBreakerStateChangeCallback, } from './utils/circuit-breaker';
30
+ export { validateSlackChannel, validateS3Key, validateGoogleSheetsRange, } from './utils/input-validator';
31
+ export type { ValidationResult } from './utils/input-validator';
32
+ export { LLMCostTracker, getLLMCostTracker, setLLMCostTracker, resetLLMCostTracker, } from './utils/llm-cost-tracker';
33
+ export type { LLMUsageRecord, ImageUsageRecord, ModelCostSummary, ImageCostSummary, CostSummary, FormattedCostSummary, } from './utils/llm-cost-tracker';
34
+ export { setMetricsCollector, getMetricsCollector, resetMetricsCollector, withMetrics, } from './utils/metrics';
35
+ export type { MetricsCollector } from './utils/metrics';
36
+ export { generateCorrelationId, getCorrelationId, getCorrelationContext, withCorrelationId, getCorrelationHeaders, } from './utils/correlation';
37
+ export type { CorrelationContext } from './utils/correlation';
38
+ export { TokenBucketRateLimiter, RATE_LIMIT_PROFILES, getRateLimiter, resetAllRateLimiters, withRateLimit, } from './utils/rate-limiter';
39
+ export type { RateLimiterConfig } from './utils/rate-limiter';
40
+ export { checkIntegrationHealth } from './utils/health-check';
41
+ export type { IntegrationHealthStatus, HealthCheckResult, } from './utils/health-check';
42
+ export { ParseJsonOptions } from './functions/llm-utils';
43
+ export { FixJsonWithAIOptions } from './functions/json-llm-tools';
44
+ export { SUPPORTED_MODELS, isValidModel, getModelCapabilities } from './types/openai-types';
45
+ export type { SupportedModel, OpenAIModel, DeepseekModel, LLMModel } from './types/openai-types';
46
+ export { openAIChatCompletionSchema, openAIImageResponseSchema, validateOpenAIChatCompletion, safeValidateOpenAIChatCompletion, perplexityResponseSchema, validatePerplexityResponse, safeValidatePerplexityResponse, googleSheetsValueRangeSchema, validateGoogleSheetsResponse, safeValidateGoogleSheetsResponse, s3ListObjectsSchema, s3GetObjectSchema, lambdaInvokeResponseSchema, validateS3ListObjects, safeValidateS3ListObjects, validateLambdaResponse, safeValidateLambdaResponse, createValidator, createSafeValidator, } from './schemas';
47
+ export type { ValidationResult as SchemaValidationResult } from './schemas';
18
48
  interface LumicUtilities {
19
49
  llm: {
20
50
  call: typeof makeLLMCall;
@@ -27,7 +27,7 @@ export type InvocationType = 'RequestResponse' | 'Event' | 'DryRun';
27
27
 
28
28
  export interface LambdaResponse {
29
29
  statusCode: number;
30
- [key: string]: any;
30
+ [key: string]: unknown;
31
31
  }
32
32
 
33
33
  // Export types from sendMessageToSlack
@@ -1,22 +1,176 @@
1
1
  // openai-types.ts
2
2
  import { ChatCompletionMessageParam, ChatCompletionTool, ChatCompletionMessageToolCall } from 'openai/resources/chat/completions';
3
- import { ImageGenerateParams, ImageModel } from 'openai/resources/images';
3
+ import { ImageGenerateParams } from 'openai/resources/images';
4
+
5
+ /**
6
+ * Model capability configuration
7
+ */
8
+ interface ModelCapabilities {
9
+ provider: 'openai' | 'deepseek';
10
+ supportsTools: boolean;
11
+ supportsJson: boolean;
12
+ supportsStructuredOutput: boolean;
13
+ supportsDeveloperPrompt: boolean;
14
+ supportsTemperature: boolean;
15
+ isReasoningModel: boolean;
16
+ }
17
+
18
+ /**
19
+ * Supported models with their capabilities
20
+ */
21
+ export const SUPPORTED_MODELS = {
22
+ // OpenAI GPT-5 series
23
+ 'gpt-5': {
24
+ provider: 'openai',
25
+ supportsTools: true,
26
+ supportsJson: true,
27
+ supportsStructuredOutput: true,
28
+ supportsDeveloperPrompt: true,
29
+ supportsTemperature: true,
30
+ isReasoningModel: false,
31
+ },
32
+ 'gpt-5-mini': {
33
+ provider: 'openai',
34
+ supportsTools: true,
35
+ supportsJson: true,
36
+ supportsStructuredOutput: true,
37
+ supportsDeveloperPrompt: true,
38
+ supportsTemperature: true,
39
+ isReasoningModel: false,
40
+ },
41
+ // OpenAI GPT-4.1 series
42
+ 'gpt-4.1': {
43
+ provider: 'openai',
44
+ supportsTools: true,
45
+ supportsJson: true,
46
+ supportsStructuredOutput: true,
47
+ supportsDeveloperPrompt: true,
48
+ supportsTemperature: true,
49
+ isReasoningModel: false,
50
+ },
51
+ 'gpt-4.1-mini': {
52
+ provider: 'openai',
53
+ supportsTools: true,
54
+ supportsJson: true,
55
+ supportsStructuredOutput: true,
56
+ supportsDeveloperPrompt: true,
57
+ supportsTemperature: true,
58
+ isReasoningModel: false,
59
+ },
60
+ 'gpt-4.1-nano': {
61
+ provider: 'openai',
62
+ supportsTools: true,
63
+ supportsJson: true,
64
+ supportsStructuredOutput: true,
65
+ supportsDeveloperPrompt: true,
66
+ supportsTemperature: true,
67
+ isReasoningModel: false,
68
+ },
69
+ // OpenAI reasoning models (o-series)
70
+ 'o1': {
71
+ provider: 'openai',
72
+ supportsTools: true,
73
+ supportsJson: false,
74
+ supportsStructuredOutput: true,
75
+ supportsDeveloperPrompt: true,
76
+ supportsTemperature: false,
77
+ isReasoningModel: true,
78
+ },
79
+ 'o1-mini': {
80
+ provider: 'openai',
81
+ supportsTools: true,
82
+ supportsJson: false,
83
+ supportsStructuredOutput: false,
84
+ supportsDeveloperPrompt: false,
85
+ supportsTemperature: false,
86
+ isReasoningModel: true,
87
+ },
88
+ 'o3': {
89
+ provider: 'openai',
90
+ supportsTools: true,
91
+ supportsJson: false,
92
+ supportsStructuredOutput: true,
93
+ supportsDeveloperPrompt: true,
94
+ supportsTemperature: false,
95
+ isReasoningModel: true,
96
+ },
97
+ 'o3-mini': {
98
+ provider: 'openai',
99
+ supportsTools: true,
100
+ supportsJson: true,
101
+ supportsStructuredOutput: true,
102
+ supportsDeveloperPrompt: true,
103
+ supportsTemperature: false,
104
+ isReasoningModel: true,
105
+ },
106
+ 'o4-mini': {
107
+ provider: 'openai',
108
+ supportsTools: true,
109
+ supportsJson: false,
110
+ supportsStructuredOutput: true,
111
+ supportsDeveloperPrompt: true,
112
+ supportsTemperature: false,
113
+ isReasoningModel: true,
114
+ },
115
+ // Deepseek models
116
+ 'deepseek-chat': {
117
+ provider: 'deepseek',
118
+ supportsTools: true,
119
+ supportsJson: true,
120
+ supportsStructuredOutput: false,
121
+ supportsDeveloperPrompt: true,
122
+ supportsTemperature: true,
123
+ isReasoningModel: false,
124
+ },
125
+ 'deepseek-reasoner': {
126
+ provider: 'deepseek',
127
+ supportsTools: false,
128
+ supportsJson: false,
129
+ supportsStructuredOutput: false,
130
+ supportsDeveloperPrompt: true,
131
+ supportsTemperature: true,
132
+ isReasoningModel: true,
133
+ },
134
+ } as const satisfies Record<string, ModelCapabilities>;
135
+
136
+ /**
137
+ * Represents all supported LLM models
138
+ */
139
+ export type SupportedModel = keyof typeof SUPPORTED_MODELS;
4
140
 
5
141
  /**
6
142
  * Represents OpenAI models
7
143
  */
144
+ export type OpenAIModel = Extract<SupportedModel, 'gpt-5' | 'gpt-5-mini' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'o4-mini'>;
8
145
 
9
- export type OpenAIModel = 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano'
10
146
  /**
11
147
  * Represents Deepseek models
12
148
  */
13
- export type DeepseekModel = 'deepseek-chat' | 'deepseek-reasoner';
149
+ export type DeepseekModel = Extract<SupportedModel, 'deepseek-chat' | 'deepseek-reasoner'>;
14
150
 
15
151
  /**
16
152
  * Represents all supported LLM models
17
153
  */
18
154
  export type LLMModel = OpenAIModel | DeepseekModel;
19
155
 
156
+ /**
157
+ * Type guard to check if a string is a valid supported model
158
+ * @param model The model name to validate
159
+ * @returns True if the model is supported
160
+ */
161
+ export function isValidModel(model: string): model is SupportedModel {
162
+ return model in SUPPORTED_MODELS;
163
+ }
164
+
165
+ /**
166
+ * Get capabilities for a supported model
167
+ * @param model The model to get capabilities for
168
+ * @returns Model capabilities object
169
+ */
170
+ export function getModelCapabilities(model: SupportedModel): Readonly<ModelCapabilities> {
171
+ return SUPPORTED_MODELS[model];
172
+ }
173
+
20
174
  /**
21
175
  * Represents the usage of the LLM.
22
176
  */
@@ -49,6 +203,11 @@ export interface LLMOptions {
49
203
  parallel_tool_calls?: boolean;
50
204
  service_tier?: 'auto' | 'default';
51
205
  apiKey?: string;
206
+ /**
207
+ * Request timeout in milliseconds. Overrides the default LLM_TIMEOUT_MS (120000ms).
208
+ * Applied to the OpenAI/Deepseek SDK client for the request.
209
+ */
210
+ timeout?: number;
52
211
  }
53
212
 
54
213
  /**
@@ -63,11 +222,11 @@ export interface LLMResponse<T> {
63
222
  /**
64
223
  * Represents the format of the OpenAI response.
65
224
  */
66
- export type OpenAIResponseFormat = 'text' | 'json' | {
67
- type: 'json_schema';
225
+ export type OpenAIResponseFormat = 'text' | 'json' | {
226
+ type: 'json_schema';
68
227
  schema: {
69
228
  type: 'object';
70
- properties: Record<string, any>;
229
+ properties: Record<string, unknown>;
71
230
  required?: string[];
72
231
  }
73
232
  };