@adaptic/lumic-utils 1.0.11 → 1.0.13
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/apollo-client.client-BXL45tI8.js +3704 -0
- package/dist/apollo-client.client-BXL45tI8.js.map +1 -0
- package/dist/apollo-client.client-DU-axkDV.js +3693 -0
- package/dist/apollo-client.client-DU-axkDV.js.map +1 -0
- package/dist/apollo-client.server-CsF1Ouw2.js +16319 -0
- package/dist/apollo-client.server-CsF1Ouw2.js.map +1 -0
- package/dist/apollo-client.server-DsMOuLeH.js +16321 -0
- package/dist/apollo-client.server-DsMOuLeH.js.map +1 -0
- package/dist/index-C01wYFKR.js +81388 -0
- package/dist/index-C01wYFKR.js.map +1 -0
- package/dist/index-ChYbCXnO.js +12271 -0
- package/dist/index-ChYbCXnO.js.map +1 -0
- package/dist/{index-CcXQeJz8.js → index-Cstek604.js} +182 -22
- package/dist/index-Cstek604.js.map +1 -0
- package/dist/{index-CcgbRft2.js → index-DZZCd-1T.js} +182 -22
- package/dist/index-DZZCd-1T.js.map +1 -0
- package/dist/index-FzTQZ3fX.js +81181 -0
- package/dist/index-FzTQZ3fX.js.map +1 -0
- package/dist/index-hlhvI_Sn.js +12108 -0
- package/dist/index-hlhvI_Sn.js.map +1 -0
- package/dist/index.cjs +136 -11417
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +39 -11399
- package/dist/index.mjs.map +1 -1
- package/dist/test.cjs +24 -7
- package/dist/test.cjs.map +1 -1
- package/dist/test.mjs +24 -7
- package/dist/test.mjs.map +1 -1
- package/dist/types/config/__tests__/secrets.test.d.ts +1 -0
- package/dist/types/config/secrets.d.ts +286 -0
- package/dist/types/errors/__tests__/errors.test.d.ts +1 -0
- package/dist/types/errors/index.d.ts +77 -0
- package/dist/types/functions/__tests__/aws-lambda.test.d.ts +1 -0
- package/dist/types/functions/__tests__/aws-s3-utils.test.d.ts +1 -0
- package/dist/types/functions/__tests__/json-llm-tools.test.d.ts +1 -0
- package/dist/types/functions/__tests__/json-tools.test.d.ts +1 -0
- package/dist/types/functions/__tests__/slack-utils.test.d.ts +1 -0
- package/dist/types/functions/aws-lambda.d.ts +1 -1
- package/dist/types/functions/aws-s3-utils.d.ts +2 -2
- package/dist/types/functions/google-sheets.d.ts +4 -4
- package/dist/types/functions/json-llm-tools.d.ts +25 -3
- package/dist/types/functions/llm-anthropic.d.ts +14 -0
- package/dist/types/functions/llm-call.d.ts +14 -3
- package/dist/types/functions/llm-config.d.ts +13 -8
- package/dist/types/functions/llm-deepseek.d.ts +1 -1
- package/dist/types/functions/llm-openai-compatible.d.ts +15 -0
- package/dist/types/functions/llm-openai.d.ts +3 -2
- package/dist/types/functions/llm-utils.d.ts +24 -1
- package/dist/types/functions/slack-utils.d.ts +3 -4
- package/dist/types/functions/utils.d.ts +2 -14
- package/dist/types/functions/zip-utils.d.ts +12 -10
- package/dist/types/index.d.ts +33 -0
- package/dist/types/schemas/aws-schemas.d.ts +210 -0
- package/dist/types/schemas/google-sheets-schemas.d.ts +32 -0
- package/dist/types/schemas/index.d.ts +17 -0
- package/dist/types/schemas/openai-schemas.d.ts +834 -0
- package/dist/types/schemas/perplexity-schemas.d.ts +338 -0
- package/dist/types/schemas/validation-helpers.d.ts +33 -0
- package/dist/types/types/aws-types.d.ts +1 -1
- package/dist/types/types/google-types.d.ts +5 -3
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/openai-types.d.ts +396 -6
- package/dist/types/utils/__tests__/circuit-breaker.test.d.ts +1 -0
- package/dist/types/utils/__tests__/correlation.test.d.ts +1 -0
- package/dist/types/utils/__tests__/input-validator.test.d.ts +1 -0
- package/dist/types/utils/__tests__/llm-cost-tracker.test.d.ts +1 -0
- package/dist/types/utils/__tests__/logger.test.d.ts +1 -0
- package/dist/types/utils/__tests__/metrics.test.d.ts +1 -0
- package/dist/types/utils/__tests__/retry.test.d.ts +1 -0
- package/dist/types/utils/__tests__/sanitizer.test.d.ts +1 -0
- package/dist/types/utils/__tests__/timeouts.test.d.ts +1 -0
- package/dist/types/utils/aws-initialise.d.ts +6 -1
- package/dist/types/utils/circuit-breaker.d.ts +99 -0
- package/dist/types/utils/config.d.ts +40 -2
- package/dist/types/utils/correlation.d.ts +43 -0
- package/dist/types/utils/health-check.d.ts +50 -0
- package/dist/types/utils/input-validator.d.ts +51 -0
- package/dist/types/utils/llm-cost-tracker.d.ts +174 -0
- package/dist/types/utils/logger.d.ts +8 -0
- package/dist/types/utils/metrics.d.ts +61 -0
- package/dist/types/utils/rate-limiter.d.ts +85 -0
- package/dist/types/utils/retry.d.ts +58 -0
- package/dist/types/utils/sanitizer.d.ts +30 -0
- package/dist/types/utils/timeouts.d.ts +44 -0
- package/package.json +3 -2
- package/dist/index-CcXQeJz8.js.map +0 -1
- package/dist/index-CcgbRft2.js.map +0 -1
- package/dist/types/aws-types.ts +0 -64
- package/dist/types/google-types.ts +0 -48
- package/dist/types/index.ts +0 -57
- package/dist/types/openai-types.ts +0 -92
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Lumic utilities errors
|
|
3
|
+
* Provides standardized error handling across all external service integrations
|
|
4
|
+
*/
|
|
5
|
+
export declare class LumicError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly service: string;
|
|
8
|
+
readonly isRetryable: boolean;
|
|
9
|
+
readonly cause?: unknown | undefined;
|
|
10
|
+
name: string;
|
|
11
|
+
constructor(message: string, code: string, service: string, isRetryable?: boolean, cause?: unknown | undefined);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Error class for Slack API operations
|
|
15
|
+
* Marks errors as retryable by default since Slack issues are often transient
|
|
16
|
+
*/
|
|
17
|
+
export declare class SlackError extends LumicError {
|
|
18
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error class for LLM (Language Learning Model) operations
|
|
22
|
+
* Includes model information for better debugging
|
|
23
|
+
* Marks rate limit errors as retryable
|
|
24
|
+
*/
|
|
25
|
+
export declare class LLMError extends LumicError {
|
|
26
|
+
readonly model?: string | undefined;
|
|
27
|
+
constructor(message: string, code?: string, model?: string | undefined, cause?: unknown);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error class for AWS Lambda function invocations
|
|
31
|
+
* Marks throttled errors as retryable
|
|
32
|
+
*/
|
|
33
|
+
export declare class AWSLambdaError extends LumicError {
|
|
34
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error class for AWS S3 operations
|
|
38
|
+
* Marks errors as retryable by default since S3 issues are often transient
|
|
39
|
+
*/
|
|
40
|
+
export declare class AWSS3Error extends LumicError {
|
|
41
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Error class for Google Sheets API operations
|
|
45
|
+
* Marks quota exceeded errors as retryable
|
|
46
|
+
*/
|
|
47
|
+
export declare class GoogleSheetsError extends LumicError {
|
|
48
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error class for Perplexity API operations
|
|
52
|
+
* Marks errors as retryable by default
|
|
53
|
+
*/
|
|
54
|
+
export declare class PerplexityError extends LumicError {
|
|
55
|
+
constructor(message: string, code?: string, cause?: unknown);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Error class for JSON parsing operations
|
|
59
|
+
* Not retryable since malformed JSON won't fix itself
|
|
60
|
+
*/
|
|
61
|
+
export declare class JsonParseError extends LumicError {
|
|
62
|
+
constructor(message: string, cause?: unknown);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Error class for PDF operations
|
|
66
|
+
* Not retryable since PDF generation issues are typically configuration or content related
|
|
67
|
+
*/
|
|
68
|
+
export declare class PDFError extends LumicError {
|
|
69
|
+
constructor(message: string, cause?: unknown);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Error class for Zip file operations
|
|
73
|
+
* Not retryable since file system issues are typically configuration or permission related
|
|
74
|
+
*/
|
|
75
|
+
export declare class ZipError extends LumicError {
|
|
76
|
+
constructor(message: string, cause?: unknown);
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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,
|
|
34
|
+
export declare function fixJsonWithAI(jsonStr: string, options?: string | FixJsonWithAIOptions): Promise<JsonValue>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LLMResponse, LLMOptions, OpenAIResponseFormat } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Makes a call to the Anthropic Messages API.
|
|
4
|
+
*
|
|
5
|
+
* Translates the unified LLMOptions (which use OpenAI-format tools and context)
|
|
6
|
+
* into Anthropic's native format, executes the call, and returns a normalized
|
|
7
|
+
* LLMResponse<T>.
|
|
8
|
+
*
|
|
9
|
+
* @param content The content to pass to the LLM.
|
|
10
|
+
* @param responseFormat The format of the response.
|
|
11
|
+
* @param options The options for the LLM call.
|
|
12
|
+
* @return A promise that resolves to the response from the Anthropic API.
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeAnthropicCall<T = unknown>(content: string, responseFormat?: OpenAIResponseFormat, options?: LLMOptions): Promise<LLMResponse<T>>;
|
|
@@ -2,22 +2,33 @@ import { LLMOptions, LLMResponse, OpenAIModel, OpenAIResponseFormat } from '../t
|
|
|
2
2
|
import { ChatCompletionContentPart } from 'openai/resources/chat';
|
|
3
3
|
import { Tool } from 'openai/resources/responses/responses';
|
|
4
4
|
/**
|
|
5
|
-
* Makes a call to the Lumic LLM interface,
|
|
5
|
+
* Makes a call to the Lumic LLM interface, automatically routing to the correct
|
|
6
|
+
* provider based on the model name.
|
|
7
|
+
*
|
|
8
|
+
* Supported providers:
|
|
9
|
+
* - OpenAI: gpt-5.4, gpt-5.4-mini, gpt-5.4-nano, gpt-5, gpt-5-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, o1, o1-mini, o3, o3-mini, o4-mini
|
|
10
|
+
* - Anthropic: claude-opus-4-6, claude-sonnet-4-6, claude-haiku-4-5
|
|
11
|
+
* - Deepseek: deepseek-chat, deepseek-reasoner
|
|
12
|
+
* - Kimi (Moonshot): kimi-k2-0905-preview, kimi-k2-turbo-preview, kimi-k2-thinking, kimi-k2-thinking-turbo
|
|
13
|
+
* - Qwen (DashScope): qwen3.5-plus, qwen3.5-flash, qwen3-max
|
|
14
|
+
* - xAI (Grok): grok-4, grok-4-fast-reasoning, grok-4-fast-non-reasoning, grok-3, grok-3-mini
|
|
15
|
+
* - Gemini: gemini-3.1-pro-preview, gemini-3-flash-preview, gemini-3.1-flash-lite-preview
|
|
6
16
|
*
|
|
7
17
|
* @param content The content to pass to the LLM.
|
|
8
18
|
* @param responseFormat The format of the response. Defaults to 'text'.
|
|
9
19
|
* @param options The options for the LLM call. Defaults to an empty object.
|
|
10
20
|
* @return A promise that resolves to the response from the LLM.
|
|
11
21
|
*/
|
|
12
|
-
export declare function makeLLMCall<T =
|
|
22
|
+
export declare function makeLLMCall<T = unknown>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions): Promise<LLMResponse<T>>;
|
|
13
23
|
/**
|
|
14
24
|
* Makes a call to the OpenAI Responses API for advanced use cases with built-in tools.
|
|
25
|
+
* This is an OpenAI-specific API and only works with OpenAI models.
|
|
15
26
|
*
|
|
16
27
|
* @param input The text prompt to send to the model (e.g., "What's in this image?")
|
|
17
28
|
* @param options The options for the Responses API call, including optional image data.
|
|
18
29
|
* @return A promise that resolves to the response from the Responses API.
|
|
19
30
|
*/
|
|
20
|
-
export declare function makeResponsesCall<T =
|
|
31
|
+
export declare function makeResponsesCall<T = unknown>(input: string, options?: {
|
|
21
32
|
apiKey?: string;
|
|
22
33
|
model?: OpenAIModel;
|
|
23
34
|
responseFormat?: 'text' | 'json';
|
|
@@ -6,9 +6,14 @@ interface AIModelCosts {
|
|
|
6
6
|
cacheHitCost?: number;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
/** Token costs in USD per
|
|
9
|
+
/** Token costs in USD per token. Last updated Mar 2026. */
|
|
10
10
|
export declare const openAiModelCosts: AIModelCosts;
|
|
11
|
+
export declare const anthropicModelCosts: AIModelCosts;
|
|
11
12
|
export declare const deepseekModelCosts: AIModelCosts;
|
|
13
|
+
export declare const kimiModelCosts: AIModelCosts;
|
|
14
|
+
export declare const qwenModelCosts: AIModelCosts;
|
|
15
|
+
export declare const xaiModelCosts: AIModelCosts;
|
|
16
|
+
export declare const geminiModelCosts: AIModelCosts;
|
|
12
17
|
/** Image generation costs in USD per image. Based on OpenAI pricing as of Feb 2025. */
|
|
13
18
|
export declare const openAiImageCosts: Record<string, number>;
|
|
14
19
|
/**
|
|
@@ -20,14 +25,14 @@ export declare const openAiImageCosts: Record<string, number>;
|
|
|
20
25
|
*/
|
|
21
26
|
export declare function calculateImageCost(model: string, imageCount: number): number;
|
|
22
27
|
/**
|
|
23
|
-
* Calculates the cost of calling a language model in USD based on the provider
|
|
28
|
+
* Calculates the cost of calling a language model in USD based on the provider, model, and token counts.
|
|
24
29
|
*
|
|
25
|
-
* @param provider The provider of the language model.
|
|
26
|
-
* @param model The name of the language model.
|
|
27
|
-
* @param inputTokens The number of input tokens
|
|
28
|
-
* @param outputTokens The number of output tokens
|
|
29
|
-
* @param reasoningTokens The number of
|
|
30
|
-
* @param cacheHitTokens The number of input tokens that were cache hits
|
|
30
|
+
* @param provider The provider of the language model.
|
|
31
|
+
* @param model The name of the language model.
|
|
32
|
+
* @param inputTokens The number of input tokens.
|
|
33
|
+
* @param outputTokens The number of output tokens.
|
|
34
|
+
* @param reasoningTokens The number of reasoning tokens (billed at output rate).
|
|
35
|
+
* @param cacheHitTokens The number of input tokens that were cache hits.
|
|
31
36
|
* @returns The cost of calling the language model in USD.
|
|
32
37
|
*/
|
|
33
38
|
export declare function calculateCost(provider: string, model: string, inputTokens: number, outputTokens: number, reasoningTokens?: number, cacheHitTokens?: number): number;
|
|
@@ -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 =
|
|
11
|
+
export declare const makeDeepseekCall: <T = unknown>(content: string | ChatCompletionContentPart[], responseFormat?: OpenAIResponseFormat, options?: LLMOptions) => Promise<LLMResponse<T>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatCompletionContentPart } from 'openai/resources/chat';
|
|
2
|
+
import { LLMResponse, LLMOptions, OpenAIResponseFormat, LLMProvider } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Makes a call to an OpenAI-compatible provider (Kimi, Qwen, or any future provider).
|
|
5
|
+
*
|
|
6
|
+
* This function uses the OpenAI SDK with a custom baseURL to communicate with
|
|
7
|
+
* providers that implement the OpenAI Chat Completions API format.
|
|
8
|
+
*
|
|
9
|
+
* @param content The content to pass to the LLM.
|
|
10
|
+
* @param responseFormat The format of the response.
|
|
11
|
+
* @param options The options for the LLM call.
|
|
12
|
+
* @param providerName The provider key in OPENAI_COMPATIBLE_PROVIDERS.
|
|
13
|
+
* @return A promise that resolves to the response from the provider.
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeOpenAICompatibleCall<T = unknown>(content: string | ChatCompletionContentPart[], responseFormat: OpenAIResponseFormat | undefined, options: LLMOptions | undefined, providerName: LLMProvider): 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 =
|
|
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 =
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
* The source directory must be
|
|
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
|
|
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.
|
|
20
|
-
* @param destPath The path of the directory to extract the zip file into.
|
|
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
|
|
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
|
|
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.
|
|
32
|
-
* @param itemPath The path of the item to add to the zip file.
|
|
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
|
|
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>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,7 +14,40 @@ 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, getModelProvider, MODEL_ALIASES, OPENAI_COMPATIBLE_PROVIDERS, PROVIDER_DEFAULT_MODELS, } from './types/openai-types';
|
|
45
|
+
export type { SupportedModel, OpenAIModel, AnthropicModel, DeepseekModel, KimiModel, QwenModel, XAIModel, GeminiModel, LLMModel, LLMProvider, ModelCapabilities, OpenAICompatibleProviderConfig, } from './types/openai-types';
|
|
46
|
+
export { LLM_DEFAULT_PROVIDER, LLM_MINI_PROVIDER, LLM_NORMAL_PROVIDER, LLM_ADVANCED_PROVIDER, LLM_PROVIDER, LLM_MODEL_MINI, LLM_MODEL_NORMAL, LLM_MODEL_ADVANCED, } from './utils/config';
|
|
47
|
+
export { makeAnthropicCall } from './functions/llm-anthropic';
|
|
48
|
+
export { makeOpenAICompatibleCall } from './functions/llm-openai-compatible';
|
|
49
|
+
export { openAIChatCompletionSchema, openAIImageResponseSchema, validateOpenAIChatCompletion, safeValidateOpenAIChatCompletion, perplexityResponseSchema, validatePerplexityResponse, safeValidatePerplexityResponse, googleSheetsValueRangeSchema, validateGoogleSheetsResponse, safeValidateGoogleSheetsResponse, s3ListObjectsSchema, s3GetObjectSchema, lambdaInvokeResponseSchema, validateS3ListObjects, safeValidateS3ListObjects, validateLambdaResponse, safeValidateLambdaResponse, createValidator, createSafeValidator, } from './schemas';
|
|
50
|
+
export type { ValidationResult as SchemaValidationResult } from './schemas';
|
|
18
51
|
interface LumicUtilities {
|
|
19
52
|
llm: {
|
|
20
53
|
call: typeof makeLLMCall;
|