@intuned/browser-dev 0.1.4-dev.0
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/BROWSER_SCRIPTS_SETUP.md +84 -0
- package/LICENSE +43 -0
- package/README.md +160 -0
- package/RELEASE.md +60 -0
- package/dist/ai/export.d.js +5 -0
- package/dist/ai/export.d.ts +641 -0
- package/dist/ai/extractStructuredData.js +320 -0
- package/dist/ai/extractStructuredDataUsingAi.js +142 -0
- package/dist/ai/extractionHelpers/screenshotHelpers.js +56 -0
- package/dist/ai/extractionHelpers/validateSchema.js +148 -0
- package/dist/ai/index.d.ts +641 -0
- package/dist/ai/index.js +19 -0
- package/dist/ai/isPageLoaded.js +80 -0
- package/dist/ai/prompt.js +39 -0
- package/dist/ai/tests/testCheckAllTypesAreStrings.spec.js +137 -0
- package/dist/ai/tests/testExtractFromContent.spec.js +372 -0
- package/dist/ai/tests/testExtractStructuredData.spec.js +646 -0
- package/dist/ai/tests/testIsPageLoaded.spec.js +277 -0
- package/dist/ai/tools/index.js +48 -0
- package/dist/ai/types/errors.js +67 -0
- package/dist/ai/types/models.js +45 -0
- package/dist/ai/types/types.js +48 -0
- package/dist/ai/validators.js +167 -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 +32 -0
- package/dist/common/ensureBrowserScripts.js +14 -0
- package/dist/common/extendedTest.js +157 -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 +57 -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/script.js +2602 -0
- package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
- package/dist/common/xpathMapping.js +107 -0
- package/dist/helpers/clickUntilExhausted.js +85 -0
- package/dist/helpers/downloadFile.js +125 -0
- package/dist/helpers/export.d.js +5 -0
- package/dist/helpers/export.d.ts +1220 -0
- package/dist/helpers/extractMarkdown.js +35 -0
- package/dist/helpers/filterEmptyValues.js +54 -0
- package/dist/helpers/gotoUrl.js +98 -0
- package/dist/helpers/index.d.ts +1220 -0
- package/dist/helpers/index.js +122 -0
- package/dist/helpers/processDate.js +25 -0
- package/dist/helpers/resolveUrl.js +64 -0
- package/dist/helpers/sanitizeHtml.js +74 -0
- package/dist/helpers/saveFileToS3.js +50 -0
- package/dist/helpers/scrollToLoadContent.js +57 -0
- package/dist/helpers/tests/testClickUntilExhausted.spec.js +372 -0
- package/dist/helpers/tests/testDownloadFile.spec.js +206 -0
- package/dist/helpers/tests/testExtractMarkdown.spec.js +290 -0
- package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
- package/dist/helpers/tests/testGoToUrl.spec.js +37 -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/testScrollToLoadContent.spec.js +163 -0
- package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +342 -0
- package/dist/helpers/tests/testWithDomSettledWait.spec.js +164 -0
- package/dist/helpers/tests/testWithNetworkIdleWait.spec.js +114 -0
- package/dist/helpers/types/Attachment.js +115 -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 +154 -0
- package/dist/helpers/utils/getS3Client.js +22 -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 +103 -0
- package/dist/helpers/waitForDomSettled.js +90 -0
- package/dist/helpers/withNetworkSettledWait.js +91 -0
- package/dist/index.d.js +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -0
- package/dist/intunedServices/ApiGateway/aiApiGateway.js +143 -0
- package/dist/intunedServices/ApiGateway/factory.js +16 -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 +355 -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 +135 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +132 -0
- package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
- package/dist/optimized-extractors/common/findTableHeaders.js +162 -0
- package/dist/optimized-extractors/common/index.js +55 -0
- package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +84 -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 +269 -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__/testArrayExtractorFromLocator.spec.js +146 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromPage.spec.js +130 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
- package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +160 -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 +243 -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/types/intuned-runtime.d.js +1 -0
- package/dist/types/intuned-runtime.d.ts +64 -0
- package/dist/vite-env.d.js +1 -0
- package/dist/vite-env.d.ts +9 -0
- package/generated-docs/ai/functions/extractStructuredData.mdx +255 -0
- package/generated-docs/ai/functions/isPageLoaded.mdx +88 -0
- package/generated-docs/ai/interfaces/ArraySchema.mdx +36 -0
- package/generated-docs/ai/interfaces/BasicSchema.mdx +14 -0
- package/generated-docs/ai/interfaces/BooleanSchema.mdx +28 -0
- package/generated-docs/ai/interfaces/ImageBufferContentItem.mdx +16 -0
- package/generated-docs/ai/interfaces/ImageUrlContentItem.mdx +16 -0
- package/generated-docs/ai/interfaces/NumberSchema.mdx +35 -0
- package/generated-docs/ai/interfaces/ObjectSchema.mdx +39 -0
- package/generated-docs/ai/interfaces/StringSchema.mdx +35 -0
- package/generated-docs/ai/interfaces/TextContentItem.mdx +14 -0
- package/generated-docs/ai/type-aliases/ContentItem.mdx +12 -0
- package/generated-docs/ai/type-aliases/JsonSchema.mdx +47 -0
- package/generated-docs/ai/type-aliases/SUPPORTED_MODELS.mdx +85 -0
- package/generated-docs/helpers/functions/downloadFile.mdx +99 -0
- package/generated-docs/helpers/functions/extractMarkdown.mdx +56 -0
- package/generated-docs/helpers/functions/filterEmptyValues.mdx +51 -0
- package/generated-docs/helpers/functions/goToUrl.mdx +124 -0
- package/generated-docs/helpers/functions/processDate.mdx +55 -0
- package/generated-docs/helpers/functions/resolveUrl.mdx +165 -0
- package/generated-docs/helpers/functions/sanitizeHtml.mdx +113 -0
- package/generated-docs/helpers/functions/saveFileToS3.mdx +127 -0
- package/generated-docs/helpers/functions/scrollToLoadContent.mdx +89 -0
- package/generated-docs/helpers/functions/uploadFileToS3.mdx +121 -0
- package/generated-docs/helpers/functions/validateDataUsingSchema.mdx +90 -0
- package/generated-docs/helpers/functions/waitForDomSettled.mdx +91 -0
- package/generated-docs/helpers/functions/withNetworkSettledWait.mdx +76 -0
- package/generated-docs/helpers/interfaces/Attachment.mdx +56 -0
- package/generated-docs/helpers/interfaces/S3Configs.mdx +52 -0
- package/generated-docs/helpers/interfaces/SanitizeHtmlOptions.mdx +22 -0
- package/generated-docs/helpers/type-aliases/AttachmentType.mdx +10 -0
- package/generated-docs/helpers/type-aliases/FileType.mdx +61 -0
- package/generated-docs/helpers/type-aliases/Trigger.mdx +62 -0
- package/how-to-generate-docs.md +61 -0
- package/how-to-run-tests.md +42 -0
- package/intuned-runtime-setup.md +13 -0
- package/package.json +124 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDomMatches = getDomMatches;
|
|
7
|
+
exports.getDomMatchesFromItemsHandles = getDomMatchesFromItemsHandles;
|
|
8
|
+
var _types = require("../common/matching/types");
|
|
9
|
+
var _ensureBrowserScripts = require("../../common/ensureBrowserScripts");
|
|
10
|
+
async function getDomMatches(page, container, searchTexts) {
|
|
11
|
+
await (0, _ensureBrowserScripts.ensureBrowserScripts)(page);
|
|
12
|
+
const result = await page.evaluate(async ({
|
|
13
|
+
container,
|
|
14
|
+
searchTexts
|
|
15
|
+
}) => {
|
|
16
|
+
const result = await window.__INTUNED__.matchStringsWithDomContent(container, searchTexts);
|
|
17
|
+
return result;
|
|
18
|
+
}, {
|
|
19
|
+
container,
|
|
20
|
+
searchTexts
|
|
21
|
+
});
|
|
22
|
+
return new Map(Object.entries(result).map(([searchText, matchResults]) => {
|
|
23
|
+
const mappedMatches = matchResults.map(matchResult => {
|
|
24
|
+
const matchedXpath = matchResult.xpath + (matchResult.match_source === _types.MatchSource.DIRECT_TEXT_NODE ? "" : matchResult.match_source === _types.MatchSource.ATTRIBUTE ? `[@${matchResult.attribute}]` : "");
|
|
25
|
+
return {
|
|
26
|
+
sourceText: matchResult.matched_source_value,
|
|
27
|
+
matchText: matchResult.matched_value,
|
|
28
|
+
nodeXpath: matchResult.xpath,
|
|
29
|
+
matchXpath: matchedXpath,
|
|
30
|
+
exact: matchResult.match_mode === _types.MatchMode.FULL,
|
|
31
|
+
matchType: matchResult.match_source === _types.MatchSource.TEXT_CONTENT ? "all-text" : matchResult.match_source === _types.MatchSource.DIRECT_TEXT_NODE ? "direct-text" : {
|
|
32
|
+
attribute: matchResult.attribute
|
|
33
|
+
},
|
|
34
|
+
isFuzzy: matchResult.match_mode === _types.MatchMode.FUZZY,
|
|
35
|
+
fuzzyDistance: matchResult.fuzzy_distance ?? undefined
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return [searchText, mappedMatches];
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
async function getDomMatchesFromItemsHandles(page, handle, searchTexts) {
|
|
42
|
+
const matchesArrays = [];
|
|
43
|
+
const matches = await getDomMatches(page, handle, searchTexts);
|
|
44
|
+
matchesArrays.push(matches);
|
|
45
|
+
const mergedMatches = new Map();
|
|
46
|
+
for (const matches of matchesArrays) {
|
|
47
|
+
for (const [searchText, matchesArray] of matches) {
|
|
48
|
+
const existingMatches = mergedMatches.get(searchText) || [];
|
|
49
|
+
existingMatches.push(...matchesArray);
|
|
50
|
+
mergedMatches.set(searchText, existingMatches);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return mergedMatches;
|
|
54
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSimplifiedHtml = getSimplifiedHtml;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
async function getSimplifiedHtml(containerHandle, options) {
|
|
9
|
+
const tagName = await containerHandle.evaluateHandle(element => element.tagName.toLowerCase());
|
|
10
|
+
const shouldReturnFullHtml = (await tagName.jsonValue()) === "html";
|
|
11
|
+
const optionsWithDefault = {
|
|
12
|
+
shouldIncludeOnClick: false,
|
|
13
|
+
shouldIncludeContentAsProp: false,
|
|
14
|
+
keepOnlyVisibleElements: true,
|
|
15
|
+
shouldReturnFullHtml,
|
|
16
|
+
...options
|
|
17
|
+
};
|
|
18
|
+
const simplifiedHtml = await containerHandle.evaluate((element, {
|
|
19
|
+
optionsWithDefault,
|
|
20
|
+
ALLOWED_ATTRIBUTES
|
|
21
|
+
}) => {
|
|
22
|
+
function truthyFilter(value) {
|
|
23
|
+
return Boolean(value);
|
|
24
|
+
}
|
|
25
|
+
function isElementNode(node) {
|
|
26
|
+
return node.nodeType === node.ELEMENT_NODE;
|
|
27
|
+
}
|
|
28
|
+
const hasAnyAllowedAttribute = (element, allowedAttributes) => {
|
|
29
|
+
const elementAttributes = element.getAttributeNames();
|
|
30
|
+
const hasAllowedAttribute = !!allowedAttributes.some(attr => {
|
|
31
|
+
if (typeof attr === "string") {
|
|
32
|
+
return element.hasAttribute(attr);
|
|
33
|
+
} else if (attr instanceof RegExp) {
|
|
34
|
+
return elementAttributes.some(attrName => attr.test(attrName));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return hasAllowedAttribute;
|
|
38
|
+
};
|
|
39
|
+
function isElementVisible(style) {
|
|
40
|
+
return style.opacity !== "" && style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
|
|
41
|
+
}
|
|
42
|
+
function isElementInteractive(element, style) {
|
|
43
|
+
return element.tagName === "A" || element.tagName === "INPUT" || element.tagName === "BUTTON" || element.tagName === "SELECT" || element.tagName === "TEXTAREA" || element.hasAttribute("onclick") || element.hasAttribute("onmousedown") || element.hasAttribute("onmouseup") || element.hasAttribute("onkeydown") || element.hasAttribute("onkeyup") || style.cursor === "pointer";
|
|
44
|
+
}
|
|
45
|
+
function getDocumentFromIframeElementSafely(element) {
|
|
46
|
+
try {
|
|
47
|
+
if (element.contentWindow && element.contentWindow.document) {
|
|
48
|
+
return element.contentWindow.document.documentElement;
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function isInputWithValue(element) {
|
|
55
|
+
return element.tagName === "INPUT" && element.value && element.value.trim();
|
|
56
|
+
}
|
|
57
|
+
function generateSimplifiedDom(element, interactiveElements, document, allowedAttributes, shouldIncludeContentAsProp, keepOnlyVisibleElements) {
|
|
58
|
+
var _element$textContent;
|
|
59
|
+
if (element.nodeType === 3 && (_element$textContent = element.textContent) !== null && _element$textContent !== void 0 && _element$textContent.trim()) {
|
|
60
|
+
return document.createTextNode(element.textContent + " ");
|
|
61
|
+
}
|
|
62
|
+
const shouldSkipElementChecks = optionsWithDefault.shouldIncludeIframes ? ["BODY", "HTML", "IFRAME"] : ["BODY", "HTML"].includes(element.nodeName);
|
|
63
|
+
if (!isElementNode(element)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const style = window.getComputedStyle(element);
|
|
67
|
+
const isVisible = isElementVisible(style) || shouldSkipElementChecks;
|
|
68
|
+
if (keepOnlyVisibleElements && !isVisible && !isInputWithValue(element)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let children = optionsWithDefault.shouldIncludeIframes && element.nodeName === "IFRAME" ? [getDocumentFromIframeElementSafely(element)].filter(Boolean) : Array.from(element.childNodes).map(c => generateSimplifiedDom(c, interactiveElements, document, allowedAttributes, shouldIncludeContentAsProp, keepOnlyVisibleElements)).filter(truthyFilter);
|
|
72
|
+
if (element.tagName === "BODY") children = children.filter(c => c.nodeType !== 3);
|
|
73
|
+
const interactive = isElementInteractive(element, style) || element.hasAttribute("role");
|
|
74
|
+
const hasLabel = element.hasAttribute("aria-label") || element.hasAttribute("name");
|
|
75
|
+
const hasAllowedAttribute = hasAnyAllowedAttribute(element, allowedAttributes);
|
|
76
|
+
let includeNode = interactive || hasLabel || hasAllowedAttribute || shouldSkipElementChecks;
|
|
77
|
+
if (children.length === 0 && !hasAnyAllowedAttribute(element, allowedAttributes)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (children.length === 1 && !hasAnyAllowedAttribute(element, allowedAttributes) && children[0].nodeType !== 3 && !(shouldSkipElementChecks && optionsWithDefault.shouldReturnFullHtml)) {
|
|
81
|
+
return children[0];
|
|
82
|
+
}
|
|
83
|
+
if (!includeNode && children.length === 0) return null;
|
|
84
|
+
if (!includeNode && children.some(c => c.nodeType === 3)) {
|
|
85
|
+
includeNode = true;
|
|
86
|
+
}
|
|
87
|
+
if (!includeNode && children.length === 1) {
|
|
88
|
+
return children[0];
|
|
89
|
+
}
|
|
90
|
+
const container = element.cloneNode();
|
|
91
|
+
const allAttributes = element.getAttributeNames();
|
|
92
|
+
const listOfAttributesToRemove = allAttributes.filter(attr => {
|
|
93
|
+
const isAllowedString = allowedAttributes.includes(attr);
|
|
94
|
+
const isAllowedRegExp = allowedAttributes.some(regex => regex instanceof RegExp && regex.test(attr));
|
|
95
|
+
return !isAllowedString && !isAllowedRegExp;
|
|
96
|
+
});
|
|
97
|
+
for (const attr of listOfAttributesToRemove) {
|
|
98
|
+
container.removeAttribute(attr);
|
|
99
|
+
}
|
|
100
|
+
if (interactive) {
|
|
101
|
+
interactiveElements.push(element);
|
|
102
|
+
}
|
|
103
|
+
if (shouldIncludeContentAsProp && element.textContent) {
|
|
104
|
+
container.setAttribute("content", element.textContent);
|
|
105
|
+
}
|
|
106
|
+
children.forEach(child => container.appendChild(child));
|
|
107
|
+
return container;
|
|
108
|
+
}
|
|
109
|
+
function getSimplifiedDomFromElement(htmlElement, shouldIncludeOnClick, shouldIncludeContentAsProp, keepOnlyVisibleElements) {
|
|
110
|
+
const interactiveElements = [];
|
|
111
|
+
const allowedAttributes = shouldIncludeOnClick ? [...ALLOWED_ATTRIBUTES, "onclick"] : ALLOWED_ATTRIBUTES;
|
|
112
|
+
const simplifiedDom = generateSimplifiedDom(htmlElement, interactiveElements, htmlElement.ownerDocument, allowedAttributes, shouldIncludeContentAsProp, keepOnlyVisibleElements);
|
|
113
|
+
if (!simplifiedDom) return "";
|
|
114
|
+
return simplifiedDom.outerHTML;
|
|
115
|
+
}
|
|
116
|
+
return getSimplifiedDomFromElement(element, optionsWithDefault.shouldIncludeOnClick, optionsWithDefault.shouldIncludeContentAsProp, optionsWithDefault.keepOnlyVisibleElements);
|
|
117
|
+
}, {
|
|
118
|
+
optionsWithDefault,
|
|
119
|
+
ALLOWED_ATTRIBUTES: _constants.ALLOWED_ATTRIBUTES
|
|
120
|
+
});
|
|
121
|
+
return simplifiedHtml;
|
|
122
|
+
}
|
package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateDynamicObjectExtractorOptions = validateDynamicObjectExtractorOptions;
|
|
7
|
+
var _neverthrow = require("neverthrow");
|
|
8
|
+
var Errors = _interopRequireWildcard(require("./errors"));
|
|
9
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
10
|
+
var _locatorHelpers = require("../../common/locatorHelpers");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
async function validateDynamicObjectExtractorOptions(page, label, options) {
|
|
13
|
+
const invalidate = options.optionalPropertiesInvalidator ?? (_extractionResult => []);
|
|
14
|
+
const searchRegion = options.searchRegion ?? page.locator("html");
|
|
15
|
+
const elementExist = (await searchRegion.count()) > 0;
|
|
16
|
+
const isElementVisible = await searchRegion.isVisible();
|
|
17
|
+
if (!elementExist || !isElementVisible) {
|
|
18
|
+
return (0, _neverthrow.err)(Errors.invalidSearchRegion(!elementExist ? "Element not found" : "Element is not visible"));
|
|
19
|
+
}
|
|
20
|
+
const searchRegionHandler = await searchRegion.elementHandle();
|
|
21
|
+
if (!searchRegionHandler) {
|
|
22
|
+
return (0, _neverthrow.err)(Errors.invalidSearchRegion());
|
|
23
|
+
}
|
|
24
|
+
let currentPageUrl = page.url();
|
|
25
|
+
const validationResult = z.string().nonempty().safeParse(currentPageUrl);
|
|
26
|
+
if (!validationResult.success) {
|
|
27
|
+
return (0, _neverthrow.err)(Errors.invalidPageState("Cannot get page url."));
|
|
28
|
+
}
|
|
29
|
+
currentPageUrl = validationResult.data;
|
|
30
|
+
const getPageUrlOrigin = () => new URL(page.url()).origin;
|
|
31
|
+
const safeGetPageUrlOrigin = (0, _neverthrow.fromThrowable)(getPageUrlOrigin, () => Errors.invalidPageState("Cannot get page url origin."));
|
|
32
|
+
const variantKey = options.variantKey ? (0, _neverthrow.ok)(options.variantKey) : safeGetPageUrlOrigin();
|
|
33
|
+
if (variantKey.isErr()) {
|
|
34
|
+
return (0, _neverthrow.err)(variantKey.error);
|
|
35
|
+
}
|
|
36
|
+
return (0, _neverthrow.ok)({
|
|
37
|
+
entityName: options.entityName,
|
|
38
|
+
entitySchema: options.entitySchema,
|
|
39
|
+
invalidate,
|
|
40
|
+
searchRegion,
|
|
41
|
+
searchRegionHandler,
|
|
42
|
+
variantKey: variantKey.value,
|
|
43
|
+
currentPageUrl,
|
|
44
|
+
searchRegionKey: options.searchRegion ? (0, _locatorHelpers.getLocatorInternalKey)(options.searchRegion) : null,
|
|
45
|
+
hasSearchRegionContainer: !!options.searchRegion,
|
|
46
|
+
label,
|
|
47
|
+
strategy: options.strategy,
|
|
48
|
+
prompt: options.prompt,
|
|
49
|
+
searchRegionXpath: options.searchRegion ? await (0, _locatorHelpers.findXPathForLocator)(options.searchRegion) : undefined,
|
|
50
|
+
apiKey: options.apiKey
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SUPPORTED_VISION_MODELS = exports.SUPPORTED_TEXT_MODELS = exports.SUPPORTED_GPT_MODELS = exports.SUPPORTED_GOOGLE_MODELS = exports.SUPPORTED_CLAUDE_MODELS = exports.MODELS_MAPPINGS = exports.MAX_TOKENS_OVERRIDES = exports.GPT_MODELS_MAPPINGS = exports.GOOGLE_MODELS_MAPPINGS = exports.CLAUDE_VISION_SUPPORTED_MODELS = exports.CLAUDE_ONLY_TEXT_MODELS = exports.CLAUDE_MODELS_MAPPINGS = void 0;
|
|
7
|
+
const CLAUDE_ONLY_TEXT_MODELS = exports.CLAUDE_ONLY_TEXT_MODELS = ["claude-3-5-haiku", "claude-3-5-haiku-20241022"];
|
|
8
|
+
const CLAUDE_VISION_SUPPORTED_MODELS = exports.CLAUDE_VISION_SUPPORTED_MODELS = ["claude-3-haiku", "claude-3-haiku-20240307", "claude-3.5-sonnet", "claude-3-5-sonnet-20240620", "claude-3-5-sonnet-20241022", "claude-opus-4", "claude-opus-4-20250514", "claude-sonnet-4", "claude-sonnet-4-20250514"];
|
|
9
|
+
const SUPPORTED_CLAUDE_MODELS = exports.SUPPORTED_CLAUDE_MODELS = [...CLAUDE_ONLY_TEXT_MODELS, ...CLAUDE_VISION_SUPPORTED_MODELS];
|
|
10
|
+
const CLAUDE_MODELS_MAPPINGS = exports.CLAUDE_MODELS_MAPPINGS = {
|
|
11
|
+
"claude-3-haiku": "claude-3-haiku-20240307",
|
|
12
|
+
"claude-3-5-haiku": "claude-3-5-haiku-20241022",
|
|
13
|
+
"claude-3.5-sonnet": "claude-3-5-sonnet-20241022",
|
|
14
|
+
"claude-opus-4": "claude-opus-4-20250514",
|
|
15
|
+
"claude-sonnet-4": "claude-sonnet-4-20250514"
|
|
16
|
+
};
|
|
17
|
+
const GPT_ONLY_TEXT_GPT_MODELS = ["gpt3.5-turbo", "gpt-3.5-turbo-0125"];
|
|
18
|
+
const GPT_VISION_SUPPORTED_MODELS = ["gpt4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"];
|
|
19
|
+
const SUPPORTED_GPT_MODELS = exports.SUPPORTED_GPT_MODELS = [...GPT_ONLY_TEXT_GPT_MODELS, ...GPT_VISION_SUPPORTED_MODELS];
|
|
20
|
+
const GPT_MODELS_MAPPINGS = exports.GPT_MODELS_MAPPINGS = {
|
|
21
|
+
"gpt4-turbo": "gpt-4-turbo-2024-04-09",
|
|
22
|
+
"gpt3.5-turbo": "gpt-3.5-turbo-0125",
|
|
23
|
+
"gpt-4o": "gpt-4o-2024-05-13",
|
|
24
|
+
"gpt-4o-mini": "gpt-4o-mini-2024-07-18"
|
|
25
|
+
};
|
|
26
|
+
const SUPPORTED_GOOGLE_MODELS = exports.SUPPORTED_GOOGLE_MODELS = ["gemini-1.5-pro", "gemini-1.5-pro-002", "gemini-1.5-flash-8b", "gemini-1.5-flash-8b-002", "gemini-1.5-flash", "gemini-1.5-flash-002", "gemini-2.0-flash-exp"];
|
|
27
|
+
const GOOGLE_MODELS_MAPPINGS = exports.GOOGLE_MODELS_MAPPINGS = {
|
|
28
|
+
"gemini-1.5-pro": "gemini-1.5-pro-002",
|
|
29
|
+
"gemini-1.5-flash-8b": "gemini-1.5-flash-8b-002",
|
|
30
|
+
"gemini-1.5-flash": "gemini-1.5-flash-002"
|
|
31
|
+
};
|
|
32
|
+
const SUPPORTED_TEXT_MODELS = exports.SUPPORTED_TEXT_MODELS = [...SUPPORTED_CLAUDE_MODELS, ...SUPPORTED_GPT_MODELS, ...SUPPORTED_GOOGLE_MODELS];
|
|
33
|
+
const SUPPORTED_VISION_MODELS = exports.SUPPORTED_VISION_MODELS = [...CLAUDE_VISION_SUPPORTED_MODELS, ...GPT_VISION_SUPPORTED_MODELS, ...SUPPORTED_GOOGLE_MODELS];
|
|
34
|
+
const MODELS_MAPPINGS = exports.MODELS_MAPPINGS = {
|
|
35
|
+
...GPT_MODELS_MAPPINGS,
|
|
36
|
+
...CLAUDE_MODELS_MAPPINGS,
|
|
37
|
+
...GOOGLE_MODELS_MAPPINGS
|
|
38
|
+
};
|
|
39
|
+
const MAX_TOKENS_OVERRIDES = exports.MAX_TOKENS_OVERRIDES = {
|
|
40
|
+
"claude-3-5-sonnet-20240620": 8192,
|
|
41
|
+
"gemini-1.5-pro-002": 8192,
|
|
42
|
+
"gemini-1.5-flash-8b-002": 8192,
|
|
43
|
+
"gemini-1.5-flash-002": 8192,
|
|
44
|
+
"gemini-2.0-flash-exp": 8192
|
|
45
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.other = exports.invalidInput = exports.invalidExtractionResult = exports.insufficientAiCredits = exports.NoToolUsage = exports.NoDataFound = exports.AiCallFailed = void 0;
|
|
7
|
+
const NoDataFound = context => ({
|
|
8
|
+
type: "NoDataFound",
|
|
9
|
+
context
|
|
10
|
+
});
|
|
11
|
+
exports.NoDataFound = NoDataFound;
|
|
12
|
+
const NoToolUsage = context => ({
|
|
13
|
+
type: "NoToolUsage",
|
|
14
|
+
context
|
|
15
|
+
});
|
|
16
|
+
exports.NoToolUsage = NoToolUsage;
|
|
17
|
+
const AiCallFailed = (context, error) => ({
|
|
18
|
+
type: "AiCallFailed",
|
|
19
|
+
context,
|
|
20
|
+
error
|
|
21
|
+
});
|
|
22
|
+
exports.AiCallFailed = AiCallFailed;
|
|
23
|
+
const invalidExtractionResult = context => ({
|
|
24
|
+
type: "InvalidExtractionResult",
|
|
25
|
+
context
|
|
26
|
+
});
|
|
27
|
+
exports.invalidExtractionResult = invalidExtractionResult;
|
|
28
|
+
const invalidInput = context => ({
|
|
29
|
+
type: "invalidInput",
|
|
30
|
+
context
|
|
31
|
+
});
|
|
32
|
+
exports.invalidInput = invalidInput;
|
|
33
|
+
const other = context => ({
|
|
34
|
+
type: "other",
|
|
35
|
+
context
|
|
36
|
+
});
|
|
37
|
+
exports.other = other;
|
|
38
|
+
const insufficientAiCredits = context => ({
|
|
39
|
+
type: "InsufficientAiCredits",
|
|
40
|
+
context
|
|
41
|
+
});
|
|
42
|
+
exports.insufficientAiCredits = insufficientAiCredits;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface BasicSchema {
|
|
2
|
+
type: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface StringSchema extends BasicSchema {
|
|
7
|
+
type: "string";
|
|
8
|
+
enum?: string[];
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
minLength?: number;
|
|
11
|
+
pattern?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface NumberSchema extends BasicSchema {
|
|
15
|
+
type: "number" | "integer";
|
|
16
|
+
multipleOf?: number;
|
|
17
|
+
maximum?: number;
|
|
18
|
+
exclusiveMaximum?: number;
|
|
19
|
+
minimum?: number;
|
|
20
|
+
exclusiveMinimum?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BooleanSchema extends BasicSchema {
|
|
24
|
+
type: "boolean";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ArraySchema extends BasicSchema {
|
|
28
|
+
type: "array";
|
|
29
|
+
items: JsonSchema;
|
|
30
|
+
maxItems?: number;
|
|
31
|
+
minItems?: number;
|
|
32
|
+
uniqueItems?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ObjectSchema extends BasicSchema {
|
|
36
|
+
type: "object";
|
|
37
|
+
properties: Record<string, JsonSchema>;
|
|
38
|
+
required?: string[];
|
|
39
|
+
|
|
40
|
+
maxProperties?: number;
|
|
41
|
+
minProperties?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type JsonSchema =
|
|
45
|
+
| StringSchema
|
|
46
|
+
| NumberSchema
|
|
47
|
+
| BooleanSchema
|
|
48
|
+
| ArraySchema
|
|
49
|
+
| ObjectSchema;
|
|
50
|
+
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.strategySchema = exports.simpleObjectJsonSchema = exports.simpleArrayItemJsonSchema = exports.extractObjectOptimizedInputSchema = exports.extractArrayOptimizedInputSchema = void 0;
|
|
7
|
+
var _zod = require("zod");
|
|
8
|
+
var _aiModelsValidation = require("./types/aiModelsValidation");
|
|
9
|
+
const htmlStrategySchema = _zod.z.object({
|
|
10
|
+
model: _zod.z.enum(_aiModelsValidation.SUPPORTED_TEXT_MODELS, {
|
|
11
|
+
required_error: "strategy model is required",
|
|
12
|
+
invalid_type_error: "strategy model is invalid"
|
|
13
|
+
}),
|
|
14
|
+
type: _zod.z.literal("HTML", {
|
|
15
|
+
required_error: "strategy type is required",
|
|
16
|
+
invalid_type_error: "strategy type is invalid"
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
const imageStrategySchema = _zod.z.object({
|
|
20
|
+
model: _zod.z.enum(_aiModelsValidation.SUPPORTED_VISION_MODELS, {
|
|
21
|
+
required_error: "strategy model is required",
|
|
22
|
+
invalid_type_error: "strategy model is invalid"
|
|
23
|
+
}),
|
|
24
|
+
type: _zod.z.literal("IMAGE", {
|
|
25
|
+
required_error: "strategy type is required",
|
|
26
|
+
invalid_type_error: "strategy type is invalid"
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
const simpleStringSchema = _zod.z.object({
|
|
30
|
+
type: _zod.z.literal("string", {
|
|
31
|
+
required_error: "property type is required",
|
|
32
|
+
invalid_type_error: "optimized extractors only support string types"
|
|
33
|
+
}),
|
|
34
|
+
description: _zod.z.string({
|
|
35
|
+
required_error: "property description is required",
|
|
36
|
+
invalid_type_error: "property description must be a string"
|
|
37
|
+
}).optional()
|
|
38
|
+
});
|
|
39
|
+
const simpleArrayStringSchema = simpleStringSchema.extend({
|
|
40
|
+
primary: _zod.z.boolean().optional()
|
|
41
|
+
});
|
|
42
|
+
const simpleObjectJsonSchema = exports.simpleObjectJsonSchema = _zod.z.object({
|
|
43
|
+
type: _zod.z.literal("object", {
|
|
44
|
+
errorMap: () => ({
|
|
45
|
+
message: 'schema type is required, and must have the value "object"'
|
|
46
|
+
})
|
|
47
|
+
}),
|
|
48
|
+
description: _zod.z.string().optional(),
|
|
49
|
+
properties: _zod.z.record(_zod.z.string(), simpleStringSchema, {
|
|
50
|
+
required_error: "properties is required in object schemas"
|
|
51
|
+
}),
|
|
52
|
+
required: _zod.z.array(_zod.z.string(), {
|
|
53
|
+
required_error: "required must be an array of strings",
|
|
54
|
+
invalid_type_error: "required must be an array of strings"
|
|
55
|
+
}).min(1, {
|
|
56
|
+
message: "at least one property must be required"
|
|
57
|
+
})
|
|
58
|
+
}, {
|
|
59
|
+
required_error: "schema is required"
|
|
60
|
+
}).refine(data => {
|
|
61
|
+
return data.required.every(key => Object.keys(data.properties).includes(key));
|
|
62
|
+
}, {
|
|
63
|
+
message: "All required keys must be defined in the properties object"
|
|
64
|
+
}).refine(data => {
|
|
65
|
+
return Object.keys(data.properties).length > 0;
|
|
66
|
+
}, {
|
|
67
|
+
message: "you must have at least one property in the properties object"
|
|
68
|
+
});
|
|
69
|
+
const simpleArrayItemJsonSchema = exports.simpleArrayItemJsonSchema = _zod.z.object({
|
|
70
|
+
type: _zod.z.literal("object", {
|
|
71
|
+
errorMap: () => ({
|
|
72
|
+
message: 'schema type is required, and must have the value "object"'
|
|
73
|
+
})
|
|
74
|
+
}),
|
|
75
|
+
description: _zod.z.string().optional(),
|
|
76
|
+
properties: _zod.z.record(_zod.z.string(), simpleArrayStringSchema, {
|
|
77
|
+
required_error: "properties is required in object schemas"
|
|
78
|
+
}),
|
|
79
|
+
required: _zod.z.array(_zod.z.string(), {
|
|
80
|
+
required_error: "required must be an array of strings",
|
|
81
|
+
invalid_type_error: "required must be an array of strings"
|
|
82
|
+
}).min(1, {
|
|
83
|
+
message: "at least one property must be required"
|
|
84
|
+
})
|
|
85
|
+
}, {
|
|
86
|
+
required_error: "schema is required"
|
|
87
|
+
}).refine(data => {
|
|
88
|
+
return data.required.every(key => Object.keys(data.properties).includes(key));
|
|
89
|
+
}, {
|
|
90
|
+
message: "All required keys must be defined in the properties object"
|
|
91
|
+
}).refine(data => {
|
|
92
|
+
const primaryField = Object.entries(data.properties).find(([_, v]) => v.primary);
|
|
93
|
+
return primaryField;
|
|
94
|
+
}, {
|
|
95
|
+
message: "you must have one primary property"
|
|
96
|
+
}).refine(data => {
|
|
97
|
+
const primaryField = Object.entries(data.properties).find(([_, v]) => v.primary);
|
|
98
|
+
if (!primaryField) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return data.required.includes(primaryField[0]);
|
|
102
|
+
}, {
|
|
103
|
+
message: "The primary field must be required"
|
|
104
|
+
});
|
|
105
|
+
const strategySchema = exports.strategySchema = _zod.z.union([htmlStrategySchema, imageStrategySchema], {
|
|
106
|
+
errorMap: (err, context) => {
|
|
107
|
+
if (err.code === "invalid_union" && context.data.model === "gpt3.5-turbo" && context.data.type === "IMAGE") {
|
|
108
|
+
return {
|
|
109
|
+
message: "gpt3.5-turbo does not support IMAGE strategy"
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
message: err.message ?? "invalid strategy configuration"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}).optional().default({
|
|
117
|
+
model: "claude-3-haiku",
|
|
118
|
+
type: "HTML"
|
|
119
|
+
});
|
|
120
|
+
const labelSchema = _zod.z.string({
|
|
121
|
+
invalid_type_error: "label must be a string",
|
|
122
|
+
required_error: "label is required"
|
|
123
|
+
}).min(1, "label must be at least 1 character long");
|
|
124
|
+
const entityNameSchema = _zod.z.string().min(1, {
|
|
125
|
+
message: "entity name must be at least 1 character long."
|
|
126
|
+
}).max(50, {
|
|
127
|
+
message: "entity name must be no more than 50 characters long."
|
|
128
|
+
}).regex(/^[a-zA-Z0-9_-]+$/, {
|
|
129
|
+
message: "entity name can only contain letters, digits, underscores, and hyphens."
|
|
130
|
+
});
|
|
131
|
+
const extractObjectOptimizedInputSchema = exports.extractObjectOptimizedInputSchema = _zod.z.object({
|
|
132
|
+
label: labelSchema,
|
|
133
|
+
strategy: strategySchema,
|
|
134
|
+
entityName: entityNameSchema,
|
|
135
|
+
entitySchema: simpleObjectJsonSchema,
|
|
136
|
+
variantKey: _zod.z.string().optional().default("about:blank"),
|
|
137
|
+
prompt: _zod.z.string().optional(),
|
|
138
|
+
optionalPropertiesInvalidator: _zod.z.function().returns(_zod.z.array(_zod.z.string())).optional().default(() => () => []),
|
|
139
|
+
apiKey: _zod.z.string().optional()
|
|
140
|
+
}, {
|
|
141
|
+
required_error: "extractObjectOptimized function missing configurations"
|
|
142
|
+
});
|
|
143
|
+
const extractArrayOptimizedInputSchema = exports.extractArrayOptimizedInputSchema = _zod.z.object({
|
|
144
|
+
label: labelSchema,
|
|
145
|
+
strategy: strategySchema,
|
|
146
|
+
prompt: _zod.z.string().optional(),
|
|
147
|
+
itemEntityName: entityNameSchema,
|
|
148
|
+
itemEntitySchema: simpleArrayItemJsonSchema,
|
|
149
|
+
variantKey: _zod.z.string().optional(),
|
|
150
|
+
optionalPropertiesInvalidator: _zod.z.function().returns(_zod.z.array(_zod.z.string())).optional().default(() => () => []),
|
|
151
|
+
apiKey: _zod.z.string().optional()
|
|
152
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Type declaration for optional peer dependency @intuned/runtime
|
|
2
|
+
// When the package is installed, its actual types will be used instead
|
|
3
|
+
declare module "@intuned/runtime" {
|
|
4
|
+
import type { BrowserContext, Page } from "playwright";
|
|
5
|
+
|
|
6
|
+
export interface Proxy {
|
|
7
|
+
server: string;
|
|
8
|
+
username: string;
|
|
9
|
+
password: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type WithPlaywrightContextWrappedFunction<R> = (
|
|
13
|
+
context: BrowserContext,
|
|
14
|
+
page: Page
|
|
15
|
+
) => Promise<any>;
|
|
16
|
+
|
|
17
|
+
export function getExecutionContext(): any;
|
|
18
|
+
export function extendTimeout(): void;
|
|
19
|
+
export function runWithContext<T>(
|
|
20
|
+
context: any,
|
|
21
|
+
fn: () => T | Promise<T>
|
|
22
|
+
): Promise<T>;
|
|
23
|
+
export function getDownloadDirectoryPath(): string;
|
|
24
|
+
|
|
25
|
+
export function withPlaywrightContext<R>(
|
|
26
|
+
options: {
|
|
27
|
+
proxy?: Proxy;
|
|
28
|
+
headless: boolean;
|
|
29
|
+
downloadsPath: string;
|
|
30
|
+
importFunction?: any;
|
|
31
|
+
apiName?: string;
|
|
32
|
+
apiParameters?: any;
|
|
33
|
+
},
|
|
34
|
+
fn: WithPlaywrightContextWrappedFunction<R>
|
|
35
|
+
): Promise<any>;
|
|
36
|
+
|
|
37
|
+
export function withPlaywrightContext<R>(
|
|
38
|
+
options: {
|
|
39
|
+
cdpAddress: string;
|
|
40
|
+
importFunction?: any;
|
|
41
|
+
apiName?: string;
|
|
42
|
+
apiParameters?: any;
|
|
43
|
+
},
|
|
44
|
+
fn: WithPlaywrightContextWrappedFunction<R>
|
|
45
|
+
): Promise<any>;
|
|
46
|
+
|
|
47
|
+
// Add other exports from @intuned/runtime if needed
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare module "@intuned/runtime/dist/common/jwtTokenManager" {
|
|
51
|
+
export interface BackendFunctionsTokenManager {
|
|
52
|
+
getToken(): Promise<string>;
|
|
53
|
+
refreshToken(): Promise<string>;
|
|
54
|
+
clearToken(): void;
|
|
55
|
+
// Add other methods as needed
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const backendFunctionsTokenManager: BackendFunctionsTokenManager;
|
|
59
|
+
|
|
60
|
+
export function callBackendFunctionWithToken<T = any>(
|
|
61
|
+
functionName: string,
|
|
62
|
+
params?: any
|
|
63
|
+
): Promise<T>;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|