@intuned/browser-dev 2.2.3-unify-sdks.20
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/.babelrc +21 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/LICENSE +43 -0
- package/dist/ai-extractors/AnthropicClient/index.js +23 -0
- package/dist/ai-extractors/export.d.js +5 -0
- package/dist/ai-extractors/export.d.ts +422 -0
- package/dist/ai-extractors/extractStructuredData.js +79 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/constants.js +7 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/errors.js +42 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingClaude.js +149 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingGoogle.js +37 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingOpenAi.js +144 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStrucutredDataUsingAiInstance.js +123 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/index.js +55 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/isItemTableHeaderOrFooter.js +96 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/screenshotHelpers.js +55 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/types.js +5 -0
- package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/utils.js +53 -0
- package/dist/ai-extractors/extractionHelpers/types.js +5 -0
- package/dist/ai-extractors/fileExtractors.js +176 -0
- package/dist/ai-extractors/index.js +31 -0
- package/dist/ai-extractors/jsonSchema.d.js +5 -0
- package/dist/ai-extractors/jsonSchema.d.ts +49 -0
- package/dist/ai-extractors/openAiClients/index.js +23 -0
- package/dist/ai-extractors/validators.js +239 -0
- package/dist/browser/ai/export.d.js +3 -0
- package/dist/browser/ai/export.d.ts +587 -0
- package/dist/browser/ai/extractMarkdown.js +15 -0
- package/dist/browser/ai/extractStructuredData.js +231 -0
- package/dist/browser/ai/extractStructuredDataUsingAi.js +140 -0
- package/dist/browser/ai/extractionHelpers/screenshotHelpers.js +55 -0
- package/dist/browser/ai/extractionHelpers/validateSchema.js +148 -0
- package/dist/browser/ai/index.d.ts +587 -0
- package/dist/browser/ai/index.js +19 -0
- package/dist/browser/ai/isPageLoaded.js +67 -0
- package/dist/browser/ai/prompt.js +39 -0
- package/dist/browser/ai/tests/testCheckAllTypesAreStrings.spec.js +143 -0
- package/dist/browser/ai/tests/testExtractStructuredData.spec.js +622 -0
- package/dist/browser/ai/tools/index.js +48 -0
- package/dist/browser/ai/types/errors.js +67 -0
- package/dist/browser/ai/types/models.js +45 -0
- package/dist/browser/ai/types/types.js +48 -0
- package/dist/browser/ai/validators.js +136 -0
- package/dist/common/Logger/index.js +60 -0
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/SdkError.js +50 -0
- package/dist/common/aiModelsValidations.js +50 -0
- package/dist/common/browser_scripts.js +2596 -0
- package/dist/common/ensureBrowserScripts.js +17 -0
- package/dist/common/environmentVariables.js +16 -0
- package/dist/common/eventTracking/getAiTrackingHeaders.js +31 -0
- package/dist/common/eventTracking/getFileTrackingHeaders.js +23 -0
- package/dist/common/extendedTest.js +148 -0
- package/dist/common/extractionHelpers.js +19 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/fuzzySearch/fuzzySearch.test.js +250 -0
- package/dist/common/fuzzySearch/levenshtein-search.js +298 -0
- package/dist/common/fuzzySearch/utils.js +23 -0
- package/dist/common/getModelProvider.js +18 -0
- package/dist/common/getSimplifiedHtml.js +122 -0
- package/dist/common/hashObject.js +32 -0
- package/dist/common/html2markdown/convertElementToMarkdown.js +469 -0
- package/dist/common/html2markdown/index.js +19 -0
- package/dist/common/jwtTokenManager.js +18 -0
- package/dist/common/loadRuntime.js +16 -0
- package/dist/common/locatorHelpers.js +41 -0
- package/dist/common/matching/collectStrings.js +32 -0
- package/dist/common/matching/levenshtein.js +40 -0
- package/dist/common/matching/matching.js +317 -0
- package/dist/common/matching/types.js +1 -0
- package/dist/common/noEmpty.js +9 -0
- package/dist/common/saveSnapshotWithExamples.js +60 -0
- package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
- package/dist/common/xpathMapping.js +107 -0
- package/dist/helpers/downloadFile.js +125 -0
- package/dist/helpers/export.d.js +1 -0
- package/dist/helpers/export.d.ts +1294 -0
- package/dist/helpers/extractMarkdown.js +35 -0
- package/dist/helpers/filterEmptyValues.js +54 -0
- package/dist/helpers/gotoUrl.js +93 -0
- package/dist/helpers/index.d.ts +1294 -0
- package/dist/helpers/index.js +115 -0
- package/dist/helpers/processDate.js +25 -0
- package/dist/helpers/resolveUrl.js +63 -0
- package/dist/helpers/sanitizeHtml.js +73 -0
- package/dist/helpers/saveFileToS3.js +46 -0
- package/dist/helpers/scrollToLoadContent.js +50 -0
- package/dist/helpers/tests/extendedTest.js +130 -0
- package/dist/helpers/tests/testDownloadFile.spec.js +197 -0
- package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
- package/dist/helpers/tests/testGoToUrl.spec.js +37 -0
- package/dist/helpers/tests/testIsPageLoaded.spec.js +285 -0
- package/dist/helpers/tests/testProcessDate.spec.js +13 -0
- package/dist/helpers/tests/testResolveUrl.spec.js +341 -0
- package/dist/helpers/tests/testSanitizeHtml.spec.js +330 -0
- package/dist/helpers/tests/testSimplifyHtml.spec.js +251 -0
- package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +380 -0
- package/dist/helpers/tests/testWaitForDomSettled.spec.js +169 -0
- package/dist/helpers/tests/testWaitForNetworkIdle.spec.js +115 -0
- package/dist/helpers/types/Attachment.js +81 -0
- package/dist/helpers/types/CustomTypeRegistry.js +48 -0
- package/dist/helpers/types/RunEnvironment.js +18 -0
- package/dist/helpers/types/ValidationError.js +17 -0
- package/dist/helpers/types/index.js +51 -0
- package/dist/helpers/uploadFileToS3.js +153 -0
- package/dist/helpers/utils/getS3Client.js +21 -0
- package/dist/helpers/utils/index.js +73 -0
- package/dist/helpers/utils/isDownload.js +10 -0
- package/dist/helpers/utils/isGenerateCodeMode.js +9 -0
- package/dist/helpers/utils/isLocator.js +9 -0
- package/dist/helpers/utils/jwtTokenManager.js +18 -0
- package/dist/helpers/validateDataUsingSchema.js +119 -0
- package/dist/helpers/waitForDomSettled.js +182 -0
- package/dist/helpers/waitForNetworkIdle.js +191 -0
- package/dist/index.d.js +82 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +84 -0
- package/dist/intunedServices/ApiGateway/aiApiGateway.js +87 -0
- package/dist/intunedServices/ApiGateway/factory.js +13 -0
- package/dist/intunedServices/ApiGateway/providers/Anthropic.js +26 -0
- package/dist/intunedServices/ApiGateway/providers/Gemini.js +29 -0
- package/dist/intunedServices/ApiGateway/providers/OpenAI.js +29 -0
- package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +221 -0
- package/dist/intunedServices/ApiGateway/types.js +11 -0
- package/dist/intunedServices/cache/cache.js +61 -0
- package/dist/intunedServices/cache/index.js +12 -0
- package/dist/intunedServices/cache/tests/testCache.spec.js +117 -0
- package/dist/optimized-extractors/common/buildExamplesPrompt.js +12 -0
- package/dist/optimized-extractors/common/buildImagesFromPage.js +55 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingClaude.js +149 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +145 -0
- package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
- package/dist/optimized-extractors/common/findTableHeaders.js +175 -0
- package/dist/optimized-extractors/common/index.js +55 -0
- package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +97 -0
- package/dist/optimized-extractors/common/matching/matching.js +212 -0
- package/dist/optimized-extractors/common/matching/matching.test.js +655 -0
- package/dist/optimized-extractors/common/matching/types.js +18 -0
- package/dist/optimized-extractors/common/matching/utils.js +184 -0
- package/dist/optimized-extractors/common/utils.js +58 -0
- package/dist/optimized-extractors/export.d.js +5 -0
- package/dist/optimized-extractors/export.d.ts +397 -0
- package/dist/optimized-extractors/extractArray.js +120 -0
- package/dist/optimized-extractors/extractObject.js +104 -0
- package/dist/optimized-extractors/index.d.ts +397 -0
- package/dist/optimized-extractors/index.js +31 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +312 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/findSetOfXpathsToCreateAnArrayExtractor.test.js +22 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/getContainerElement.test.js +21 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/partOfSameArrayXpath.test.js +42 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
- package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +152 -0
- package/dist/optimized-extractors/listExtractionHelpers/errors.js +46 -0
- package/dist/optimized-extractors/listExtractionHelpers/getListMatches.js +14 -0
- package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +240 -0
- package/dist/optimized-extractors/listExtractionHelpers/typesAndSchema.js +5 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/extractPropertiesUsingGPTFromArray.js +277 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/extractStructuredListUsingAi.js +44 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getListContainerXpath.js +94 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getRelativeContainerXpathSelector.js +20 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getSimplifiedHtmlPerListItem.js +21 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/tablesUtils.js +48 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/validateOptions.js +52 -0
- package/dist/optimized-extractors/models/anthropicModel.js +23 -0
- package/dist/optimized-extractors/models/openaiModel.js +23 -0
- package/dist/optimized-extractors/objectExtractionHelpers/AIExtractors.js +73 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/checksumUtils.test.js +103 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +107 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +107 -0
- package/dist/optimized-extractors/objectExtractionHelpers/calculateObjectExampleHash.js +28 -0
- package/dist/optimized-extractors/objectExtractionHelpers/captureSnapshot.js +26 -0
- package/dist/optimized-extractors/objectExtractionHelpers/checksumUtils.js +32 -0
- package/dist/optimized-extractors/objectExtractionHelpers/constants.js +7 -0
- package/dist/optimized-extractors/objectExtractionHelpers/dynamicObjectExtractor.js +106 -0
- package/dist/optimized-extractors/objectExtractionHelpers/errors.js +42 -0
- package/dist/optimized-extractors/objectExtractionHelpers/findDomMatches.js +54 -0
- package/dist/optimized-extractors/objectExtractionHelpers/getSimplifiedHtml.js +122 -0
- package/dist/optimized-extractors/objectExtractionHelpers/typesAndSchemas.js +5 -0
- package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js +52 -0
- package/dist/optimized-extractors/types/aiModelsValidation.js +45 -0
- package/dist/optimized-extractors/types/errors.js +42 -0
- package/dist/optimized-extractors/types/jsonSchema.d.js +5 -0
- package/dist/optimized-extractors/types/jsonSchema.d.ts +50 -0
- package/dist/optimized-extractors/types/types.js +5 -0
- package/dist/optimized-extractors/validators.js +152 -0
- package/dist/vite-env.d.js +1 -0
- package/dist/vite-env.d.ts +9 -0
- package/docs.md +14 -0
- package/how-to-run-tests.md +10 -0
- package/intuned-runtime-setup.md +13 -0
- package/package.json +124 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { sanitizeHtml } from "./helpers/sanitizeHtml";
|
|
2
|
+
export { downloadFile } from "./helpers/downloadFile";
|
|
3
|
+
export { saveFileToS3 } from "./helpers/saveFileToS3";
|
|
4
|
+
export { filterEmptyValues } from "./helpers/filterEmptyValues";
|
|
5
|
+
export { goToUrl } from "./helpers/gotoUrl";
|
|
6
|
+
export { processDate } from "./helpers/processDate";
|
|
7
|
+
export { resolveUrl } from "./helpers/resolveUrl";
|
|
8
|
+
export { uploadFileToS3 } from "./helpers/uploadFileToS3";
|
|
9
|
+
export { validateDataUsingSchema } from "./helpers/validateDataUsingSchema";
|
|
10
|
+
export { waitForDomSettled } from "./helpers/waitForDomSettled";
|
|
11
|
+
export { waitForNetworkIdle } from "./helpers/waitForNetworkIdle";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "downloadFile", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _helpers.downloadFile;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "extractMarkdown", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _helpers.extractMarkdown;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "filterEmptyValues", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _helpers.filterEmptyValues;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "goToUrl", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _helpers.goToUrl;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "processDate", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _helpers.processDate;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "resolveUrl", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _helpers.resolveUrl;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "sanitizeHtml", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _helpers.sanitizeHtml;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "saveFileToS3", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _helpers.saveFileToS3;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "scrollToLoadContent", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _helpers.scrollToLoadContent;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "uploadFileToS3", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _helpers.uploadFileToS3;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "validateDataUsingSchema", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _helpers.validateDataUsingSchema;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "waitForDomSettled", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _helpers.waitForDomSettled;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "waitForNetworkIdle", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _helpers.waitForNetworkIdle;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
var _helpers = require("./helpers");
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.APIGateway = void 0;
|
|
7
|
+
var _getModelProvider = require("../../common/getModelProvider");
|
|
8
|
+
var _Anthropic = require("./providers/Anthropic");
|
|
9
|
+
var _OpenAI = require("./providers/OpenAI");
|
|
10
|
+
var _Gemini = require("./providers/Gemini");
|
|
11
|
+
class APIGateway {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.config = this.getDefaultConfig();
|
|
14
|
+
this.validateConfig(this.config);
|
|
15
|
+
}
|
|
16
|
+
validateConfig(config) {
|
|
17
|
+
if (!config.functionsDomain || !config.workspaceId || !config.integrationId) {
|
|
18
|
+
throw new Error("Gateway configuration is incomplete. " + "Please provide functionsDomain, workspaceId, and integrationId");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getDefaultConfig() {
|
|
22
|
+
return {
|
|
23
|
+
functionsDomain: process.env.FUNCTIONS_DOMAIN,
|
|
24
|
+
workspaceId: process.env.INTUNED_WORKSPACE_ID,
|
|
25
|
+
integrationId: process.env.INTUNED_INTEGRATION_ID
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
detectProvider(model) {
|
|
29
|
+
const modelLower = model.toLowerCase();
|
|
30
|
+
return (0, _getModelProvider.getModelProvider)(modelLower);
|
|
31
|
+
}
|
|
32
|
+
buildGatewayUrl(provider) {
|
|
33
|
+
var _this$config;
|
|
34
|
+
const baseDomain = (_this$config = this.config) === null || _this$config === void 0 || (_this$config = _this$config.functionsDomain) === null || _this$config === void 0 ? void 0 : _this$config.replace(/\/$/, "");
|
|
35
|
+
return `${baseDomain}/api/${this.config.workspaceId}/functions/${this.config.integrationId}/${provider === "anthropic" ? "anthropic/v1" : provider === "google_vertexai" ? "google_vertexai/v1beta" : provider}`;
|
|
36
|
+
}
|
|
37
|
+
getModelConfig(model, options) {
|
|
38
|
+
const {
|
|
39
|
+
apiKey,
|
|
40
|
+
extraHeaders
|
|
41
|
+
} = options;
|
|
42
|
+
if (apiKey) {
|
|
43
|
+
return {
|
|
44
|
+
model,
|
|
45
|
+
apiKey,
|
|
46
|
+
extraHeaders,
|
|
47
|
+
baseUrl: undefined
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const provider = this.detectProvider(model);
|
|
51
|
+
const baseUrl = this.buildGatewayUrl(provider);
|
|
52
|
+
return {
|
|
53
|
+
model,
|
|
54
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
55
|
+
extraHeaders,
|
|
56
|
+
baseUrl
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
createProviderInstance(model, apiKey, extraHeaders) {
|
|
60
|
+
const config = this.getModelConfig(model, {
|
|
61
|
+
apiKey,
|
|
62
|
+
extraHeaders
|
|
63
|
+
});
|
|
64
|
+
const provider = this.detectProvider(model);
|
|
65
|
+
const input = {
|
|
66
|
+
apiKey: config.apiKey,
|
|
67
|
+
headers: config.extraHeaders,
|
|
68
|
+
model: config.model,
|
|
69
|
+
baseUrl: config.baseUrl
|
|
70
|
+
};
|
|
71
|
+
const providerFactories = {
|
|
72
|
+
anthropic: () => (0, _Anthropic.createAnthropicInstance)(input),
|
|
73
|
+
openai: () => (0, _OpenAI.createOpenAIInstance)(input),
|
|
74
|
+
google_vertexai: () => (0, _Gemini.createGoogleInstance)(input)
|
|
75
|
+
};
|
|
76
|
+
const factory = providerFactories[provider];
|
|
77
|
+
if (!factory) {
|
|
78
|
+
throw new Error(`Unsupported provider: ${provider}`);
|
|
79
|
+
}
|
|
80
|
+
return factory();
|
|
81
|
+
}
|
|
82
|
+
getModel(model, apiKey, extraHeaders) {
|
|
83
|
+
const providerInstance = this.createProviderInstance(model, apiKey, extraHeaders);
|
|
84
|
+
return providerInstance.chat(model);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.APIGateway = APIGateway;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GatewayFactory = void 0;
|
|
7
|
+
var _aiApiGateway = require("./aiApiGateway");
|
|
8
|
+
class GatewayFactory {
|
|
9
|
+
static createAIGateway() {
|
|
10
|
+
return new _aiApiGateway.APIGateway();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.GatewayFactory = GatewayFactory;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAnthropicInstance = void 0;
|
|
7
|
+
var _anthropic = require("@ai-sdk/anthropic");
|
|
8
|
+
var _jwtTokenManager = require("../../../common/jwtTokenManager");
|
|
9
|
+
const createAnthropicInstance = input => {
|
|
10
|
+
const {
|
|
11
|
+
apiKey,
|
|
12
|
+
baseUrl
|
|
13
|
+
} = input;
|
|
14
|
+
if (apiKey && baseUrl === undefined) {
|
|
15
|
+
return (0, _anthropic.createAnthropic)({
|
|
16
|
+
apiKey
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
return (0, _anthropic.createAnthropic)({
|
|
20
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
21
|
+
baseURL: baseUrl,
|
|
22
|
+
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.createAnthropicInstance = createAnthropicInstance;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGoogleInstance = void 0;
|
|
7
|
+
var _google = require("@ai-sdk/google");
|
|
8
|
+
var _jwtTokenManager = require("../../../common/jwtTokenManager");
|
|
9
|
+
const createGoogleInstance = input => {
|
|
10
|
+
const {
|
|
11
|
+
apiKey,
|
|
12
|
+
headers,
|
|
13
|
+
baseUrl
|
|
14
|
+
} = input;
|
|
15
|
+
if (apiKey && baseUrl === undefined) {
|
|
16
|
+
return (0, _google.createGoogleGenerativeAI)({
|
|
17
|
+
apiKey,
|
|
18
|
+
headers
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
return (0, _google.createGoogleGenerativeAI)({
|
|
22
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
23
|
+
headers,
|
|
24
|
+
baseURL: baseUrl,
|
|
25
|
+
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.createGoogleInstance = createGoogleInstance;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createOpenAIInstance = void 0;
|
|
7
|
+
var _openai = require("@ai-sdk/openai");
|
|
8
|
+
var _jwtTokenManager = require("../../../common/jwtTokenManager");
|
|
9
|
+
const createOpenAIInstance = input => {
|
|
10
|
+
const {
|
|
11
|
+
apiKey,
|
|
12
|
+
headers,
|
|
13
|
+
baseUrl
|
|
14
|
+
} = input;
|
|
15
|
+
if (apiKey && baseUrl === undefined) {
|
|
16
|
+
return (0, _openai.createOpenAI)({
|
|
17
|
+
apiKey,
|
|
18
|
+
headers
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
return (0, _openai.createOpenAI)({
|
|
22
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
23
|
+
headers,
|
|
24
|
+
baseURL: baseUrl,
|
|
25
|
+
fetch: _jwtTokenManager.backendFunctionsTokenManager.fetchWithToken.bind(_jwtTokenManager.backendFunctionsTokenManager)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.createOpenAIInstance = createOpenAIInstance;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _extendedTest = require("../../../common/extendedTest");
|
|
4
|
+
var _vitest = require("vitest");
|
|
5
|
+
var _aiApiGateway = require("../aiApiGateway");
|
|
6
|
+
var _getModelProvider = require("../../../common/getModelProvider");
|
|
7
|
+
var _Anthropic = require("../providers/Anthropic");
|
|
8
|
+
var _OpenAI = require("../providers/OpenAI");
|
|
9
|
+
var _Gemini = require("../providers/Gemini");
|
|
10
|
+
_vitest.vi.mock("../../../common/jwtTokenManager", () => ({
|
|
11
|
+
backendFunctionsTokenManager: {
|
|
12
|
+
fetchWithToken: _vitest.vi.fn()
|
|
13
|
+
}
|
|
14
|
+
}));
|
|
15
|
+
_vitest.vi.mock("../../../common/getModelProvider", () => ({
|
|
16
|
+
getModelProvider: _vitest.vi.fn()
|
|
17
|
+
}));
|
|
18
|
+
_vitest.vi.mock("../providers/Anthropic", () => ({
|
|
19
|
+
createAnthropicInstance: _vitest.vi.fn()
|
|
20
|
+
}));
|
|
21
|
+
_vitest.vi.mock("../providers/OpenAI", () => ({
|
|
22
|
+
createOpenAIInstance: _vitest.vi.fn()
|
|
23
|
+
}));
|
|
24
|
+
_vitest.vi.mock("../providers/Gemini", () => ({
|
|
25
|
+
createGoogleInstance: _vitest.vi.fn()
|
|
26
|
+
}));
|
|
27
|
+
const mockGetModelProvider = _vitest.vi.mocked(_getModelProvider.getModelProvider);
|
|
28
|
+
const mockCreateAnthropicInstance = _vitest.vi.mocked(_Anthropic.createAnthropicInstance);
|
|
29
|
+
const mockCreateOpenAIInstance = _vitest.vi.mocked(_OpenAI.createOpenAIInstance);
|
|
30
|
+
const mockCreateGoogleInstance = _vitest.vi.mocked(_Gemini.createGoogleInstance);
|
|
31
|
+
(0, _extendedTest.describe)("APIGateway", () => {
|
|
32
|
+
let originalEnv;
|
|
33
|
+
let gateway;
|
|
34
|
+
(0, _extendedTest.beforeEach)(() => {
|
|
35
|
+
originalEnv = process.env;
|
|
36
|
+
process.env = {
|
|
37
|
+
...originalEnv,
|
|
38
|
+
FUNCTIONS_DOMAIN: "https://functions.example.com",
|
|
39
|
+
INTUNED_WORKSPACE_ID: "workspace123",
|
|
40
|
+
INTUNED_INTEGRATION_ID: "integration456"
|
|
41
|
+
};
|
|
42
|
+
gateway = new _aiApiGateway.APIGateway();
|
|
43
|
+
_vitest.vi.clearAllMocks();
|
|
44
|
+
});
|
|
45
|
+
(0, _extendedTest.afterEach)(() => {
|
|
46
|
+
process.env = originalEnv;
|
|
47
|
+
});
|
|
48
|
+
(0, _extendedTest.describe)("constructor and config", () => {
|
|
49
|
+
(0, _extendedTest.it)("should initialize with default config from environment", () => {
|
|
50
|
+
(0, _extendedTest.expect)(gateway["config"]).toEqual({
|
|
51
|
+
functionsDomain: "https://functions.example.com",
|
|
52
|
+
workspaceId: "workspace123",
|
|
53
|
+
integrationId: "integration456"
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
(0, _extendedTest.describe)("detectProvider", () => {
|
|
58
|
+
(0, _extendedTest.it)("should detect openai models", () => {
|
|
59
|
+
mockGetModelProvider.mockReturnValue("openai");
|
|
60
|
+
(0, _extendedTest.expect)(gateway["detectProvider"]("gpt-4")).toBe("openai");
|
|
61
|
+
(0, _extendedTest.expect)(mockGetModelProvider).toHaveBeenCalledWith("gpt-4");
|
|
62
|
+
});
|
|
63
|
+
(0, _extendedTest.it)("should detect anthropic models", () => {
|
|
64
|
+
mockGetModelProvider.mockReturnValue("anthropic");
|
|
65
|
+
(0, _extendedTest.expect)(gateway["detectProvider"]("claude-3-sonnet")).toBe("anthropic");
|
|
66
|
+
(0, _extendedTest.expect)(mockGetModelProvider).toHaveBeenCalledWith("claude-3-sonnet");
|
|
67
|
+
});
|
|
68
|
+
(0, _extendedTest.it)("should handle case insensitive models", () => {
|
|
69
|
+
mockGetModelProvider.mockReturnValue("anthropic");
|
|
70
|
+
(0, _extendedTest.expect)(gateway["detectProvider"]("CLAUDE-3-OPUS")).toBe("anthropic");
|
|
71
|
+
(0, _extendedTest.expect)(mockGetModelProvider).toHaveBeenCalledWith("claude-3-opus");
|
|
72
|
+
});
|
|
73
|
+
(0, _extendedTest.it)("should return unknown for unsupported models", () => {
|
|
74
|
+
mockGetModelProvider.mockReturnValue("unknown");
|
|
75
|
+
(0, _extendedTest.expect)(gateway["detectProvider"]("unknown-model")).toBe("unknown");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
(0, _extendedTest.describe)("buildGatewayUrl", () => {
|
|
79
|
+
(0, _extendedTest.it)("should build correct URL for anthropic", () => {
|
|
80
|
+
const result = gateway["buildGatewayUrl"]("anthropic");
|
|
81
|
+
(0, _extendedTest.expect)(result).toBe("https://functions.example.com/api/workspace123/functions/integration456/anthropic/v1");
|
|
82
|
+
});
|
|
83
|
+
(0, _extendedTest.it)("should build correct URL for google_vertexai", () => {
|
|
84
|
+
const result = gateway["buildGatewayUrl"]("google_vertexai");
|
|
85
|
+
(0, _extendedTest.expect)(result).toBe("https://functions.example.com/api/workspace123/functions/integration456/google_vertexai/v1beta");
|
|
86
|
+
});
|
|
87
|
+
(0, _extendedTest.it)("should build correct URL for other providers", () => {
|
|
88
|
+
const result = gateway["buildGatewayUrl"]("openai");
|
|
89
|
+
(0, _extendedTest.expect)(result).toBe("https://functions.example.com/api/workspace123/functions/integration456/openai");
|
|
90
|
+
});
|
|
91
|
+
(0, _extendedTest.it)("should strip trailing slash from domain", () => {
|
|
92
|
+
process.env.FUNCTIONS_DOMAIN = "https://functions.example.com/";
|
|
93
|
+
const newGateway = new _aiApiGateway.APIGateway();
|
|
94
|
+
const result = newGateway["buildGatewayUrl"]("openai");
|
|
95
|
+
(0, _extendedTest.expect)(result).toBe("https://functions.example.com/api/workspace123/functions/integration456/openai");
|
|
96
|
+
});
|
|
97
|
+
(0, _extendedTest.it)("should throw error for incomplete config", () => {
|
|
98
|
+
delete process.env.FUNCTIONS_DOMAIN;
|
|
99
|
+
(0, _extendedTest.expect)(() => new _aiApiGateway.APIGateway()).toThrow("Gateway configuration is incomplete");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
(0, _extendedTest.describe)("getModelConfig", () => {
|
|
103
|
+
(0, _extendedTest.it)("should return direct mode config when API key provided", () => {
|
|
104
|
+
const config = gateway.getModelConfig("claude-3-sonnet", {
|
|
105
|
+
apiKey: "sk-test123",
|
|
106
|
+
extraHeaders: {
|
|
107
|
+
"Custom-Header": "value"
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
(0, _extendedTest.expect)(config).toEqual({
|
|
111
|
+
model: "claude-3-sonnet",
|
|
112
|
+
apiKey: "sk-test123",
|
|
113
|
+
extraHeaders: {
|
|
114
|
+
"Custom-Header": "value"
|
|
115
|
+
},
|
|
116
|
+
baseUrl: undefined
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
(0, _extendedTest.it)("should return gateway mode config when no API key", () => {
|
|
120
|
+
mockGetModelProvider.mockReturnValue("anthropic");
|
|
121
|
+
const config = gateway.getModelConfig("claude-3-sonnet", {
|
|
122
|
+
apiKey: undefined,
|
|
123
|
+
extraHeaders: {
|
|
124
|
+
"Custom-Header": "value"
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
(0, _extendedTest.expect)(config).toEqual({
|
|
128
|
+
model: "claude-3-sonnet",
|
|
129
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
130
|
+
extraHeaders: {
|
|
131
|
+
"Custom-Header": "value"
|
|
132
|
+
},
|
|
133
|
+
baseUrl: "https://functions.example.com/api/workspace123/functions/integration456/anthropic/v1"
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
(0, _extendedTest.describe)("createProviderInstance", () => {
|
|
138
|
+
(0, _extendedTest.it)("should create anthropic instance", () => {
|
|
139
|
+
mockGetModelProvider.mockReturnValue("anthropic");
|
|
140
|
+
const mockInstance = {
|
|
141
|
+
chat: _vitest.vi.fn()
|
|
142
|
+
};
|
|
143
|
+
mockCreateAnthropicInstance.mockReturnValue(mockInstance);
|
|
144
|
+
const result = gateway.createProviderInstance("claude-3-sonnet");
|
|
145
|
+
(0, _extendedTest.expect)(mockCreateAnthropicInstance).toHaveBeenCalledWith({
|
|
146
|
+
apiKey: "--THI_VALUE_WILL_BE_REPLACED_BY_INTUNED_BE--",
|
|
147
|
+
headers: undefined,
|
|
148
|
+
model: "claude-3-sonnet",
|
|
149
|
+
baseUrl: "https://functions.example.com/api/workspace123/functions/integration456/anthropic/v1"
|
|
150
|
+
});
|
|
151
|
+
(0, _extendedTest.expect)(result).toBe(mockInstance);
|
|
152
|
+
});
|
|
153
|
+
(0, _extendedTest.it)("should create openai instance", () => {
|
|
154
|
+
mockGetModelProvider.mockReturnValue("openai");
|
|
155
|
+
const mockInstance = {
|
|
156
|
+
chat: _vitest.vi.fn()
|
|
157
|
+
};
|
|
158
|
+
mockCreateOpenAIInstance.mockReturnValue(mockInstance);
|
|
159
|
+
const result = gateway.createProviderInstance("gpt-4", "sk-test123");
|
|
160
|
+
(0, _extendedTest.expect)(mockCreateOpenAIInstance).toHaveBeenCalledWith({
|
|
161
|
+
apiKey: "sk-test123",
|
|
162
|
+
headers: undefined,
|
|
163
|
+
model: "gpt-4",
|
|
164
|
+
baseUrl: undefined
|
|
165
|
+
});
|
|
166
|
+
(0, _extendedTest.expect)(result).toBe(mockInstance);
|
|
167
|
+
});
|
|
168
|
+
(0, _extendedTest.it)("should create google instance", () => {
|
|
169
|
+
mockGetModelProvider.mockReturnValue("google_vertexai");
|
|
170
|
+
const mockInstance = {
|
|
171
|
+
chat: _vitest.vi.fn()
|
|
172
|
+
};
|
|
173
|
+
mockCreateGoogleInstance.mockReturnValue(mockInstance);
|
|
174
|
+
const result = gateway.createProviderInstance("gemini-pro");
|
|
175
|
+
(0, _extendedTest.expect)(mockCreateGoogleInstance).toHaveBeenCalled();
|
|
176
|
+
(0, _extendedTest.expect)(result).toBe(mockInstance);
|
|
177
|
+
});
|
|
178
|
+
(0, _extendedTest.it)("should throw error for unsupported provider", () => {
|
|
179
|
+
mockGetModelProvider.mockReturnValue("unknown");
|
|
180
|
+
(0, _extendedTest.expect)(() => gateway.createProviderInstance("unknown-model")).toThrow("Unsupported provider: unknown");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
(0, _extendedTest.describe)("getModel", () => {
|
|
184
|
+
(0, _extendedTest.it)("should return language model from provider instance", () => {
|
|
185
|
+
mockGetModelProvider.mockReturnValue("anthropic");
|
|
186
|
+
const mockModelInstance = {
|
|
187
|
+
generate: _vitest.vi.fn()
|
|
188
|
+
};
|
|
189
|
+
const mockProviderInstance = {
|
|
190
|
+
chat: _vitest.vi.fn().mockReturnValue(mockModelInstance)
|
|
191
|
+
};
|
|
192
|
+
mockCreateAnthropicInstance.mockReturnValue(mockProviderInstance);
|
|
193
|
+
const result = gateway.getModel("claude-3-sonnet");
|
|
194
|
+
(0, _extendedTest.expect)(mockProviderInstance.chat).toHaveBeenCalledWith("claude-3-sonnet");
|
|
195
|
+
(0, _extendedTest.expect)(result).toBe(mockModelInstance);
|
|
196
|
+
});
|
|
197
|
+
(0, _extendedTest.it)("should pass through API key and headers", () => {
|
|
198
|
+
mockGetModelProvider.mockReturnValue("openai");
|
|
199
|
+
const mockModelInstance = {
|
|
200
|
+
generate: _vitest.vi.fn()
|
|
201
|
+
};
|
|
202
|
+
const mockProviderInstance = {
|
|
203
|
+
chat: _vitest.vi.fn().mockReturnValue(mockModelInstance)
|
|
204
|
+
};
|
|
205
|
+
mockCreateOpenAIInstance.mockReturnValue(mockProviderInstance);
|
|
206
|
+
const result = gateway.getModel("gpt-4", "sk-test123", {
|
|
207
|
+
"Custom-Header": "value"
|
|
208
|
+
});
|
|
209
|
+
(0, _extendedTest.expect)(mockCreateOpenAIInstance).toHaveBeenCalledWith({
|
|
210
|
+
apiKey: "sk-test123",
|
|
211
|
+
headers: {
|
|
212
|
+
"Custom-Header": "value"
|
|
213
|
+
},
|
|
214
|
+
model: "gpt-4",
|
|
215
|
+
baseUrl: undefined
|
|
216
|
+
});
|
|
217
|
+
(0, _extendedTest.expect)(mockProviderInstance.chat).toHaveBeenCalledWith("gpt-4");
|
|
218
|
+
(0, _extendedTest.expect)(result).toBe(mockModelInstance);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GatewayMode = void 0;
|
|
7
|
+
let GatewayMode = exports.GatewayMode = function (GatewayMode) {
|
|
8
|
+
GatewayMode["DIRECT"] = "direct";
|
|
9
|
+
GatewayMode["GATEWAY"] = "gateway";
|
|
10
|
+
return GatewayMode;
|
|
11
|
+
}({});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cache = void 0;
|
|
7
|
+
var _zod = require("zod");
|
|
8
|
+
var _jwtTokenManager = require("../../common/jwtTokenManager");
|
|
9
|
+
var _Logger = require("../../common/Logger");
|
|
10
|
+
const forbiddenCharacters = /[:#]/g;
|
|
11
|
+
const keySchema = _zod.z.string().min(1, "Key must be at least 1 character long").refine(key => {
|
|
12
|
+
var _key$match;
|
|
13
|
+
return (((_key$match = key.match(forbiddenCharacters)) === null || _key$match === void 0 ? void 0 : _key$match.length) ?? 0) === 0;
|
|
14
|
+
}, 'Key cannot contain the following characters: ":" or "#"');
|
|
15
|
+
class Cache {
|
|
16
|
+
async get(key) {
|
|
17
|
+
try {
|
|
18
|
+
const parsedKey = keySchema.parse(key);
|
|
19
|
+
const response = await (0, _jwtTokenManager.callBackendFunctionWithToken)(`cache/${parsedKey}`, {
|
|
20
|
+
method: "GET"
|
|
21
|
+
});
|
|
22
|
+
const contentType = response.headers.get("content-type");
|
|
23
|
+
if (!(contentType !== null && contentType !== void 0 && contentType.includes("application/json"))) {
|
|
24
|
+
const responseText = await response.text();
|
|
25
|
+
throw new Error(`Server returned ${contentType} instead of JSON. This usually indicates an authentication issue or wrong endpoint. Response: ${responseText.substring(0, 200)}...`);
|
|
26
|
+
}
|
|
27
|
+
const json = await response.json();
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(`Failed to get cache value for key ${parsedKey}: ${json.message}`);
|
|
30
|
+
}
|
|
31
|
+
return json.value;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(`Failed to get cache value for key ${key}: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async set(key, value) {
|
|
37
|
+
try {
|
|
38
|
+
const keyResult = keySchema.parse(key);
|
|
39
|
+
const response = await (0, _jwtTokenManager.callBackendFunctionWithToken)(`cache/${keyResult}`, {
|
|
40
|
+
method: "PUT",
|
|
41
|
+
body: JSON.stringify(value),
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const contentType = response.headers.get("content-type");
|
|
47
|
+
if (!(contentType !== null && contentType !== void 0 && contentType.includes("application/json"))) {
|
|
48
|
+
const responseText = await response.text();
|
|
49
|
+
_Logger.logger.error(`Expected JSON but got content-type: ${contentType}`);
|
|
50
|
+
throw new Error(`Server returned ${contentType} instead of JSON. This usually indicates an authentication issue or wrong endpoint. Response: ${responseText.substring(0, 200)}...`);
|
|
51
|
+
}
|
|
52
|
+
const json = await response.json();
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new Error(`Failed to set cache value for key ${keyResult}: ${json.message}`);
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(`Failed to set cache value for key ${key}: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const cache = exports.cache = new Cache();
|