@intuned/browser-dev 2.2.3-unify-sdks.23 → 2.2.3-unify-sdks.24
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/ai/export.d.ts +25 -27
- package/dist/ai/extractStructuredDataUsingAi.js +32 -11
- package/dist/ai/index.d.ts +25 -27
- package/dist/ai/tests/testCheckAllTypesAreStrings.spec.js +5 -9
- package/dist/ai/tests/testExtractStructuredData.spec.js +2 -3
- package/dist/ai/types/types.js +4 -4
- package/dist/ai/validators.js +6 -8
- package/dist/helpers/export.d.ts +1 -68
- package/dist/helpers/index.d.ts +1 -68
- package/dist/helpers/waitForNetworkIdle.js +7 -6
- package/dist/index.d.js +11 -77
- package/dist/index.d.ts +13 -11
- package/dist/index.js +11 -79
- package/dist/intunedServices/ApiGateway/aiApiGateway.js +14 -2
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +2 -2
- package/package.json +1 -1
- package/dist/ai-extractors/jsonSchema.d.js +0 -5
- package/dist/ai-extractors/jsonSchema.d.ts +0 -49
package/dist/ai/export.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Locator, Page } from "playwright-core";
|
|
2
2
|
import { JSONSchema7TypeName } from "json-schema";
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Base schema interface that all JSON schema types extend from.
|
|
6
5
|
* Provides common properties like type and description.
|
|
7
6
|
*
|
|
8
|
-
* @interface
|
|
7
|
+
* @interface BasicSchema
|
|
9
8
|
*/
|
|
10
|
-
export interface
|
|
9
|
+
export interface BasicSchema {
|
|
11
10
|
/** The JSON schema type(s) for this schema definition */
|
|
12
|
-
type:
|
|
11
|
+
type: "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
13
12
|
/** Optional description of what this schema represents */
|
|
14
13
|
description?: string;
|
|
15
14
|
}
|
|
@@ -18,7 +17,7 @@ export interface BaseSchema {
|
|
|
18
17
|
* Schema definition for string values with validation constraints.
|
|
19
18
|
*
|
|
20
19
|
* @interface StringSchema
|
|
21
|
-
* @extends
|
|
20
|
+
* @extends BasicSchema
|
|
22
21
|
* @example
|
|
23
22
|
* ```typescript
|
|
24
23
|
* const nameSchema: StringSchema = {
|
|
@@ -30,7 +29,7 @@ export interface BaseSchema {
|
|
|
30
29
|
* };
|
|
31
30
|
* ```
|
|
32
31
|
*/
|
|
33
|
-
export interface StringSchema extends
|
|
32
|
+
export interface StringSchema extends BasicSchema {
|
|
34
33
|
/** Must be "string" for string schemas */
|
|
35
34
|
type: "string";
|
|
36
35
|
/** Array of allowed string values (enumeration) */
|
|
@@ -47,7 +46,7 @@ export interface StringSchema extends BaseSchema {
|
|
|
47
46
|
* Schema definition for numeric values (numbers and integers) with validation constraints.
|
|
48
47
|
*
|
|
49
48
|
* @interface NumberSchema
|
|
50
|
-
* @extends
|
|
49
|
+
* @extends BasicSchema
|
|
51
50
|
* @example
|
|
52
51
|
* ```typescript
|
|
53
52
|
* const ageSchema: NumberSchema = {
|
|
@@ -58,7 +57,7 @@ export interface StringSchema extends BaseSchema {
|
|
|
58
57
|
* };
|
|
59
58
|
* ```
|
|
60
59
|
*/
|
|
61
|
-
export interface NumberSchema extends
|
|
60
|
+
export interface NumberSchema extends BasicSchema {
|
|
62
61
|
/** Must be "number" or "integer" for numeric schemas */
|
|
63
62
|
type: "number" | "integer";
|
|
64
63
|
/** Number must be a multiple of this value */
|
|
@@ -77,7 +76,7 @@ export interface NumberSchema extends BaseSchema {
|
|
|
77
76
|
* Schema definition for boolean values.
|
|
78
77
|
*
|
|
79
78
|
* @interface BooleanSchema
|
|
80
|
-
* @extends
|
|
79
|
+
* @extends BasicSchema
|
|
81
80
|
* @example
|
|
82
81
|
* ```typescript
|
|
83
82
|
* const isActiveSchema: BooleanSchema = {
|
|
@@ -86,7 +85,7 @@ export interface NumberSchema extends BaseSchema {
|
|
|
86
85
|
* };
|
|
87
86
|
* ```
|
|
88
87
|
*/
|
|
89
|
-
export interface BooleanSchema extends
|
|
88
|
+
export interface BooleanSchema extends BasicSchema {
|
|
90
89
|
/** Must be "boolean" for boolean schemas */
|
|
91
90
|
type: "boolean";
|
|
92
91
|
}
|
|
@@ -95,7 +94,7 @@ export interface BooleanSchema extends BaseSchema {
|
|
|
95
94
|
* Schema definition for array values with item validation and constraints.
|
|
96
95
|
*
|
|
97
96
|
* @interface ArraySchema
|
|
98
|
-
* @extends
|
|
97
|
+
* @extends BasicSchema
|
|
99
98
|
* @example
|
|
100
99
|
* ```typescript
|
|
101
100
|
* const tagsSchema: ArraySchema = {
|
|
@@ -108,11 +107,11 @@ export interface BooleanSchema extends BaseSchema {
|
|
|
108
107
|
* };
|
|
109
108
|
* ```
|
|
110
109
|
*/
|
|
111
|
-
export interface ArraySchema extends
|
|
110
|
+
export interface ArraySchema extends BasicSchema {
|
|
112
111
|
/** Must be "array" for array schemas */
|
|
113
112
|
type: "array";
|
|
114
113
|
/** Schema definition for array items */
|
|
115
|
-
items:
|
|
114
|
+
items: JsonSchema;
|
|
116
115
|
/** Maximum number of items allowed */
|
|
117
116
|
maxItems?: number;
|
|
118
117
|
/** Minimum number of items required */
|
|
@@ -125,7 +124,7 @@ export interface ArraySchema extends BaseSchema {
|
|
|
125
124
|
* Schema definition for object values with property validation and constraints.
|
|
126
125
|
*
|
|
127
126
|
* @interface ObjectSchema
|
|
128
|
-
* @extends
|
|
127
|
+
* @extends BasicSchema
|
|
129
128
|
* @example
|
|
130
129
|
* ```typescript
|
|
131
130
|
* const userSchema: ObjectSchema = {
|
|
@@ -140,11 +139,11 @@ export interface ArraySchema extends BaseSchema {
|
|
|
140
139
|
* };
|
|
141
140
|
* ```
|
|
142
141
|
*/
|
|
143
|
-
export interface ObjectSchema extends
|
|
142
|
+
export interface ObjectSchema extends BasicSchema {
|
|
144
143
|
/** Must be "object" for object schemas */
|
|
145
144
|
type: "object";
|
|
146
145
|
/** Schema definitions for object properties */
|
|
147
|
-
properties:
|
|
146
|
+
properties: Record<string, JsonSchema>;
|
|
148
147
|
/** Array of required property names */
|
|
149
148
|
required?: string[];
|
|
150
149
|
/** Maximum number of properties allowed */
|
|
@@ -152,6 +151,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
152
151
|
/** Minimum number of properties required */
|
|
153
152
|
minProperties?: number;
|
|
154
153
|
}
|
|
154
|
+
|
|
155
155
|
/**
|
|
156
156
|
* Extract structured data from web pages using AI-powered content analysis.
|
|
157
157
|
*
|
|
@@ -163,7 +163,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
163
163
|
* @param {Page | Locator} [options.source] - Playwright Page object to extract data from the entire page or Locator object to extract data from a specific element
|
|
164
164
|
* @param {SUPPORTED_MODELS} [options.model] - AI model to use for extraction (e.g., "gpt-4", "claude-3"), see [SUPPORTED_MODELS](../type-aliases/SUPPORTED_MODELS) for all supported models.
|
|
165
165
|
* @param {string} [options.strategy] - Type of extraction: "HTML", "IMAGE", or "MARKDOWN"
|
|
166
|
-
* @param {
|
|
166
|
+
* @param {JsonSchema} options.dataSchema - [JsonSchema](../interfaces/JsonSchema) defining the structure of the data to extract
|
|
167
167
|
* @param {string} [options.prompt] - Optional prompt to guide the extraction process and provide more context
|
|
168
168
|
* @param {string} [options.apiKey] - Optional API key for AI extraction (if provided, will not be billed to your account)s
|
|
169
169
|
* @param {boolean} [options.enableDomMatching=false] - Whether to disable DOM element matching during extraction. Defaults to False. When set to false, all types in the schema must be strings to match with the DOM elements. The extracted resultes will be matched with the DOM elements and returned, then will be cached in a smart fashion so that the next time the same data is extracted, the result will be returned from the cache even if the DOM has minor changes.
|
|
@@ -267,7 +267,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
267
267
|
*/
|
|
268
268
|
export declare function extractStructuredData(options: {
|
|
269
269
|
source: Page | Locator;
|
|
270
|
-
dataSchema:
|
|
270
|
+
dataSchema: JsonSchema;
|
|
271
271
|
prompt?: string;
|
|
272
272
|
strategy?: "IMAGE" | "MARKDOWN" | "HTML";
|
|
273
273
|
model?: SUPPORTED_MODELS;
|
|
@@ -369,10 +369,10 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
369
369
|
* - ArraySchema: For array validation with item constraints
|
|
370
370
|
* - ObjectSchema: For object validation with property constraints
|
|
371
371
|
*
|
|
372
|
-
* @type
|
|
372
|
+
* @type JsonSchema
|
|
373
373
|
* @example
|
|
374
374
|
* ```typescript String Schema
|
|
375
|
-
* const stringSchema:
|
|
375
|
+
* const stringSchema: JsonSchema = {
|
|
376
376
|
* type: "string",
|
|
377
377
|
* minLength: 3,
|
|
378
378
|
* maxLength: 50,
|
|
@@ -382,7 +382,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
382
382
|
*
|
|
383
383
|
* @example
|
|
384
384
|
* ```typescript Number Schema
|
|
385
|
-
* const numberSchema:
|
|
385
|
+
* const numberSchema: JsonSchema = {
|
|
386
386
|
* type: "number",
|
|
387
387
|
* minimum: 0,
|
|
388
388
|
* maximum: 100,
|
|
@@ -392,7 +392,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
392
392
|
*
|
|
393
393
|
* @example
|
|
394
394
|
* ```typescript Array Schema
|
|
395
|
-
* const arraySchema:
|
|
395
|
+
* const arraySchema: JsonSchema = {
|
|
396
396
|
* type: "array",
|
|
397
397
|
* items: {
|
|
398
398
|
* type: "string"
|
|
@@ -405,7 +405,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
405
405
|
*
|
|
406
406
|
* @example
|
|
407
407
|
* ```typescript Object Schema
|
|
408
|
-
* const objectSchema:
|
|
408
|
+
* const objectSchema: JsonSchema = {
|
|
409
409
|
* type: "object",
|
|
410
410
|
* properties: {
|
|
411
411
|
* name: { type: "string" },
|
|
@@ -664,11 +664,9 @@ export declare function isPageLoaded(
|
|
|
664
664
|
* LoadingStatus is a union of true, false, and "Dont know".
|
|
665
665
|
*/
|
|
666
666
|
export type LoadingStatus = true | false | "Dont know";
|
|
667
|
-
|
|
668
|
-
export type JSONSchema =
|
|
667
|
+
export type JsonSchema =
|
|
669
668
|
| StringSchema
|
|
670
669
|
| NumberSchema
|
|
671
670
|
| BooleanSchema
|
|
672
671
|
| ArraySchema
|
|
673
|
-
| ObjectSchema
|
|
674
|
-
| BaseSchema;
|
|
672
|
+
| ObjectSchema;
|
|
@@ -19,7 +19,7 @@ var _ai = require("ai");
|
|
|
19
19
|
var _loadRuntime = require("../common/loadRuntime");
|
|
20
20
|
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); }
|
|
21
21
|
async function extractStructuredDataUsingAi(page, input) {
|
|
22
|
-
var _getExecutionContext, _getExecutionContext2, _getExecutionContext3
|
|
22
|
+
var _getExecutionContext, _getExecutionContext2, _getExecutionContext3;
|
|
23
23
|
const {
|
|
24
24
|
apiKey,
|
|
25
25
|
enableDomMatching,
|
|
@@ -54,7 +54,6 @@ async function extractStructuredDataUsingAi(page, input) {
|
|
|
54
54
|
let result;
|
|
55
55
|
while (currentRetry < maxRetries) {
|
|
56
56
|
try {
|
|
57
|
-
var _result$usage, _result$usage4;
|
|
58
57
|
result = await (0, _ai.generateText)({
|
|
59
58
|
model: gatewayModel,
|
|
60
59
|
messages: messagesHistory,
|
|
@@ -63,7 +62,12 @@ async function extractStructuredDataUsingAi(page, input) {
|
|
|
63
62
|
maxRetries,
|
|
64
63
|
headers
|
|
65
64
|
});
|
|
66
|
-
|
|
65
|
+
if (!apiKey) {
|
|
66
|
+
accumulatedTokens += result.response.headers["x-ai-cost-in-cents"];
|
|
67
|
+
} else {
|
|
68
|
+
var _result$usage;
|
|
69
|
+
accumulatedTokens += ((_result$usage = result.usage) === null || _result$usage === void 0 ? void 0 : _result$usage.totalTokens) ?? 0;
|
|
70
|
+
}
|
|
67
71
|
const toolCall = result.toolCalls[0] ?? null;
|
|
68
72
|
let extractedData = toolCall.input;
|
|
69
73
|
const isArray = jsonSchema.type === "array";
|
|
@@ -94,8 +98,11 @@ async function extractStructuredDataUsingAi(page, input) {
|
|
|
94
98
|
continue;
|
|
95
99
|
}
|
|
96
100
|
if (!enableDomMatching) {
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
if (!apiKey) {
|
|
102
|
+
_Logger.logger.info(`Total LLM Cost: ${accumulatedTokens}`);
|
|
103
|
+
} else {
|
|
104
|
+
_Logger.logger.info(`Total LLM Tokens: ${accumulatedTokens}`);
|
|
105
|
+
}
|
|
99
106
|
return (0, _neverthrow.ok)({
|
|
100
107
|
result: extractedData,
|
|
101
108
|
xpathMapping: {}
|
|
@@ -105,8 +112,11 @@ async function extractStructuredDataUsingAi(page, input) {
|
|
|
105
112
|
dataStructure: extractedData
|
|
106
113
|
});
|
|
107
114
|
if (!stringsToMatch || stringsToMatch.length === 0) {
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
if (!apiKey) {
|
|
116
|
+
_Logger.logger.info(`Total LLM Cost: ${accumulatedTokens}`);
|
|
117
|
+
} else {
|
|
118
|
+
_Logger.logger.info(`Total LLM Tokens: ${accumulatedTokens}`);
|
|
119
|
+
}
|
|
110
120
|
return (0, _neverthrow.ok)({
|
|
111
121
|
result: [],
|
|
112
122
|
xpathMapping: {}
|
|
@@ -124,21 +134,32 @@ async function extractStructuredDataUsingAi(page, input) {
|
|
|
124
134
|
stringReplacements[key] = (value === null || value === void 0 ? void 0 : value.matchText) || null;
|
|
125
135
|
});
|
|
126
136
|
const matchesData = await (0, _validateSchema.recursivelyReplaceStrings)(extractedData, stringReplacements);
|
|
127
|
-
|
|
137
|
+
if (!apiKey) {
|
|
138
|
+
_Logger.logger.info(`Total LLM Cost: ${accumulatedTokens}`);
|
|
139
|
+
} else {
|
|
140
|
+
_Logger.logger.info(`Total LLM Tokens: ${accumulatedTokens}`);
|
|
141
|
+
}
|
|
128
142
|
return (0, _neverthrow.ok)({
|
|
129
143
|
result: matchesData,
|
|
130
144
|
xpathMapping
|
|
131
145
|
});
|
|
132
146
|
} catch (error) {
|
|
133
|
-
var _result$usage5;
|
|
134
147
|
_Logger.logger.error("Error during AI extraction", {
|
|
135
148
|
error,
|
|
136
149
|
model
|
|
137
150
|
});
|
|
138
|
-
|
|
151
|
+
if (!apiKey) {
|
|
152
|
+
_Logger.logger.info(`Total LLM Cost: ${accumulatedTokens}`);
|
|
153
|
+
} else {
|
|
154
|
+
_Logger.logger.info(`Total LLM Tokens: ${accumulatedTokens}`);
|
|
155
|
+
}
|
|
139
156
|
return (0, _neverthrow.err)(Errors.invalidExtractionResult(error instanceof Error ? error.message : "Unknown error during extraction"));
|
|
140
157
|
}
|
|
141
158
|
}
|
|
142
|
-
|
|
159
|
+
if (!apiKey) {
|
|
160
|
+
_Logger.logger.info(`Total LLM Cost: ${accumulatedTokens}`);
|
|
161
|
+
} else {
|
|
162
|
+
_Logger.logger.info(`Total LLM Tokens: ${accumulatedTokens}`);
|
|
163
|
+
}
|
|
143
164
|
return (0, _neverthrow.err)(Errors.maxRetriesExceeded(`Max retries of ${maxRetries} exceeded for extraction`));
|
|
144
165
|
}
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Locator, Page } from "playwright-core";
|
|
2
2
|
import { JSONSchema7TypeName } from "json-schema";
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Base schema interface that all JSON schema types extend from.
|
|
6
5
|
* Provides common properties like type and description.
|
|
7
6
|
*
|
|
8
|
-
* @interface
|
|
7
|
+
* @interface BasicSchema
|
|
9
8
|
*/
|
|
10
|
-
export interface
|
|
9
|
+
export interface BasicSchema {
|
|
11
10
|
/** The JSON schema type(s) for this schema definition */
|
|
12
|
-
type:
|
|
11
|
+
type: "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
13
12
|
/** Optional description of what this schema represents */
|
|
14
13
|
description?: string;
|
|
15
14
|
}
|
|
@@ -18,7 +17,7 @@ export interface BaseSchema {
|
|
|
18
17
|
* Schema definition for string values with validation constraints.
|
|
19
18
|
*
|
|
20
19
|
* @interface StringSchema
|
|
21
|
-
* @extends
|
|
20
|
+
* @extends BasicSchema
|
|
22
21
|
* @example
|
|
23
22
|
* ```typescript
|
|
24
23
|
* const nameSchema: StringSchema = {
|
|
@@ -30,7 +29,7 @@ export interface BaseSchema {
|
|
|
30
29
|
* };
|
|
31
30
|
* ```
|
|
32
31
|
*/
|
|
33
|
-
export interface StringSchema extends
|
|
32
|
+
export interface StringSchema extends BasicSchema {
|
|
34
33
|
/** Must be "string" for string schemas */
|
|
35
34
|
type: "string";
|
|
36
35
|
/** Array of allowed string values (enumeration) */
|
|
@@ -47,7 +46,7 @@ export interface StringSchema extends BaseSchema {
|
|
|
47
46
|
* Schema definition for numeric values (numbers and integers) with validation constraints.
|
|
48
47
|
*
|
|
49
48
|
* @interface NumberSchema
|
|
50
|
-
* @extends
|
|
49
|
+
* @extends BasicSchema
|
|
51
50
|
* @example
|
|
52
51
|
* ```typescript
|
|
53
52
|
* const ageSchema: NumberSchema = {
|
|
@@ -58,7 +57,7 @@ export interface StringSchema extends BaseSchema {
|
|
|
58
57
|
* };
|
|
59
58
|
* ```
|
|
60
59
|
*/
|
|
61
|
-
export interface NumberSchema extends
|
|
60
|
+
export interface NumberSchema extends BasicSchema {
|
|
62
61
|
/** Must be "number" or "integer" for numeric schemas */
|
|
63
62
|
type: "number" | "integer";
|
|
64
63
|
/** Number must be a multiple of this value */
|
|
@@ -77,7 +76,7 @@ export interface NumberSchema extends BaseSchema {
|
|
|
77
76
|
* Schema definition for boolean values.
|
|
78
77
|
*
|
|
79
78
|
* @interface BooleanSchema
|
|
80
|
-
* @extends
|
|
79
|
+
* @extends BasicSchema
|
|
81
80
|
* @example
|
|
82
81
|
* ```typescript
|
|
83
82
|
* const isActiveSchema: BooleanSchema = {
|
|
@@ -86,7 +85,7 @@ export interface NumberSchema extends BaseSchema {
|
|
|
86
85
|
* };
|
|
87
86
|
* ```
|
|
88
87
|
*/
|
|
89
|
-
export interface BooleanSchema extends
|
|
88
|
+
export interface BooleanSchema extends BasicSchema {
|
|
90
89
|
/** Must be "boolean" for boolean schemas */
|
|
91
90
|
type: "boolean";
|
|
92
91
|
}
|
|
@@ -95,7 +94,7 @@ export interface BooleanSchema extends BaseSchema {
|
|
|
95
94
|
* Schema definition for array values with item validation and constraints.
|
|
96
95
|
*
|
|
97
96
|
* @interface ArraySchema
|
|
98
|
-
* @extends
|
|
97
|
+
* @extends BasicSchema
|
|
99
98
|
* @example
|
|
100
99
|
* ```typescript
|
|
101
100
|
* const tagsSchema: ArraySchema = {
|
|
@@ -108,11 +107,11 @@ export interface BooleanSchema extends BaseSchema {
|
|
|
108
107
|
* };
|
|
109
108
|
* ```
|
|
110
109
|
*/
|
|
111
|
-
export interface ArraySchema extends
|
|
110
|
+
export interface ArraySchema extends BasicSchema {
|
|
112
111
|
/** Must be "array" for array schemas */
|
|
113
112
|
type: "array";
|
|
114
113
|
/** Schema definition for array items */
|
|
115
|
-
items:
|
|
114
|
+
items: JsonSchema;
|
|
116
115
|
/** Maximum number of items allowed */
|
|
117
116
|
maxItems?: number;
|
|
118
117
|
/** Minimum number of items required */
|
|
@@ -125,7 +124,7 @@ export interface ArraySchema extends BaseSchema {
|
|
|
125
124
|
* Schema definition for object values with property validation and constraints.
|
|
126
125
|
*
|
|
127
126
|
* @interface ObjectSchema
|
|
128
|
-
* @extends
|
|
127
|
+
* @extends BasicSchema
|
|
129
128
|
* @example
|
|
130
129
|
* ```typescript
|
|
131
130
|
* const userSchema: ObjectSchema = {
|
|
@@ -140,11 +139,11 @@ export interface ArraySchema extends BaseSchema {
|
|
|
140
139
|
* };
|
|
141
140
|
* ```
|
|
142
141
|
*/
|
|
143
|
-
export interface ObjectSchema extends
|
|
142
|
+
export interface ObjectSchema extends BasicSchema {
|
|
144
143
|
/** Must be "object" for object schemas */
|
|
145
144
|
type: "object";
|
|
146
145
|
/** Schema definitions for object properties */
|
|
147
|
-
properties:
|
|
146
|
+
properties: Record<string, JsonSchema>;
|
|
148
147
|
/** Array of required property names */
|
|
149
148
|
required?: string[];
|
|
150
149
|
/** Maximum number of properties allowed */
|
|
@@ -152,6 +151,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
152
151
|
/** Minimum number of properties required */
|
|
153
152
|
minProperties?: number;
|
|
154
153
|
}
|
|
154
|
+
|
|
155
155
|
/**
|
|
156
156
|
* Extract structured data from web pages using AI-powered content analysis.
|
|
157
157
|
*
|
|
@@ -163,7 +163,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
163
163
|
* @param {Page | Locator} [options.source] - Playwright Page object to extract data from the entire page or Locator object to extract data from a specific element
|
|
164
164
|
* @param {SUPPORTED_MODELS} [options.model] - AI model to use for extraction (e.g., "gpt-4", "claude-3"), see [SUPPORTED_MODELS](../type-aliases/SUPPORTED_MODELS) for all supported models.
|
|
165
165
|
* @param {string} [options.strategy] - Type of extraction: "HTML", "IMAGE", or "MARKDOWN"
|
|
166
|
-
* @param {
|
|
166
|
+
* @param {JsonSchema} options.dataSchema - [JsonSchema](../interfaces/JsonSchema) defining the structure of the data to extract
|
|
167
167
|
* @param {string} [options.prompt] - Optional prompt to guide the extraction process and provide more context
|
|
168
168
|
* @param {string} [options.apiKey] - Optional API key for AI extraction (if provided, will not be billed to your account)s
|
|
169
169
|
* @param {boolean} [options.enableDomMatching=false] - Whether to disable DOM element matching during extraction. Defaults to False. When set to false, all types in the schema must be strings to match with the DOM elements. The extracted resultes will be matched with the DOM elements and returned, then will be cached in a smart fashion so that the next time the same data is extracted, the result will be returned from the cache even if the DOM has minor changes.
|
|
@@ -267,7 +267,7 @@ export interface ObjectSchema extends BaseSchema {
|
|
|
267
267
|
*/
|
|
268
268
|
export declare function extractStructuredData(options: {
|
|
269
269
|
source: Page | Locator;
|
|
270
|
-
dataSchema:
|
|
270
|
+
dataSchema: JsonSchema;
|
|
271
271
|
prompt?: string;
|
|
272
272
|
strategy?: "IMAGE" | "MARKDOWN" | "HTML";
|
|
273
273
|
model?: SUPPORTED_MODELS;
|
|
@@ -369,10 +369,10 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
369
369
|
* - ArraySchema: For array validation with item constraints
|
|
370
370
|
* - ObjectSchema: For object validation with property constraints
|
|
371
371
|
*
|
|
372
|
-
* @type
|
|
372
|
+
* @type JsonSchema
|
|
373
373
|
* @example
|
|
374
374
|
* ```typescript String Schema
|
|
375
|
-
* const stringSchema:
|
|
375
|
+
* const stringSchema: JsonSchema = {
|
|
376
376
|
* type: "string",
|
|
377
377
|
* minLength: 3,
|
|
378
378
|
* maxLength: 50,
|
|
@@ -382,7 +382,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
382
382
|
*
|
|
383
383
|
* @example
|
|
384
384
|
* ```typescript Number Schema
|
|
385
|
-
* const numberSchema:
|
|
385
|
+
* const numberSchema: JsonSchema = {
|
|
386
386
|
* type: "number",
|
|
387
387
|
* minimum: 0,
|
|
388
388
|
* maximum: 100,
|
|
@@ -392,7 +392,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
392
392
|
*
|
|
393
393
|
* @example
|
|
394
394
|
* ```typescript Array Schema
|
|
395
|
-
* const arraySchema:
|
|
395
|
+
* const arraySchema: JsonSchema = {
|
|
396
396
|
* type: "array",
|
|
397
397
|
* items: {
|
|
398
398
|
* type: "string"
|
|
@@ -405,7 +405,7 @@ type SUPPORTED_MODELS = SUPPORTED_CLAUDE_MODELS | SUPPORTED_OPENAI_MODELS;
|
|
|
405
405
|
*
|
|
406
406
|
* @example
|
|
407
407
|
* ```typescript Object Schema
|
|
408
|
-
* const objectSchema:
|
|
408
|
+
* const objectSchema: JsonSchema = {
|
|
409
409
|
* type: "object",
|
|
410
410
|
* properties: {
|
|
411
411
|
* name: { type: "string" },
|
|
@@ -664,11 +664,9 @@ export declare function isPageLoaded(
|
|
|
664
664
|
* LoadingStatus is a union of true, false, and "Dont know".
|
|
665
665
|
*/
|
|
666
666
|
export type LoadingStatus = true | false | "Dont know";
|
|
667
|
-
|
|
668
|
-
export type JSONSchema =
|
|
667
|
+
export type JsonSchema =
|
|
669
668
|
| StringSchema
|
|
670
669
|
| NumberSchema
|
|
671
670
|
| BooleanSchema
|
|
672
671
|
| ArraySchema
|
|
673
|
-
| ObjectSchema
|
|
674
|
-
| BaseSchema;
|
|
672
|
+
| ObjectSchema;
|
|
@@ -33,19 +33,13 @@ var _validators = require("../validators");
|
|
|
33
33
|
};
|
|
34
34
|
(0, _extendedTest.expect)((0, _validators.checkAllTypesAreStrings)(schema)).toBe(true);
|
|
35
35
|
});
|
|
36
|
-
(0, _extendedTest.test)("should return
|
|
36
|
+
(0, _extendedTest.test)("should return true for array with no items constraint", async () => {
|
|
37
37
|
const schema = {
|
|
38
38
|
type: "array",
|
|
39
39
|
items: {
|
|
40
|
-
type: "
|
|
40
|
+
type: "string"
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
(0, _extendedTest.expect)((0, _validators.checkAllTypesAreStrings)(schema)).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
(0, _extendedTest.test)("should return true for array with no items constraint", async () => {
|
|
46
|
-
const schema = {
|
|
47
|
-
type: "array"
|
|
48
|
-
};
|
|
49
43
|
(0, _extendedTest.expect)((0, _validators.checkAllTypesAreStrings)(schema)).toBe(true);
|
|
50
44
|
});
|
|
51
45
|
(0, _extendedTest.test)("should return true for object with all string properties", async () => {
|
|
@@ -80,7 +74,9 @@ var _validators = require("../validators");
|
|
|
80
74
|
});
|
|
81
75
|
(0, _extendedTest.test)("should return true for object with no properties", async () => {
|
|
82
76
|
const schema = {
|
|
83
|
-
type: "object"
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {},
|
|
79
|
+
required: []
|
|
84
80
|
};
|
|
85
81
|
(0, _extendedTest.expect)((0, _validators.checkAllTypesAreStrings)(schema)).toBe(true);
|
|
86
82
|
});
|
|
@@ -173,11 +173,10 @@ const userProfileTemplate = `
|
|
|
173
173
|
required: ["title", "price", "stock"]
|
|
174
174
|
}
|
|
175
175
|
},
|
|
176
|
-
prompt:
|
|
176
|
+
prompt: "extract product information including title, price, stock status, and rating pls",
|
|
177
177
|
enableDomMatching: true,
|
|
178
178
|
strategy: "HTML",
|
|
179
|
-
model: "
|
|
180
|
-
apiKey: process.env.ANTHROPIC_API_KEY
|
|
179
|
+
model: "o4-mini"
|
|
181
180
|
});
|
|
182
181
|
(0, _extendedTest.expect)(Array.isArray(data)).toBe(true);
|
|
183
182
|
(0, _extendedTest.expect)(data.length).toBe(3);
|
package/dist/ai/types/types.js
CHANGED
|
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "ArraySchema", {
|
|
|
9
9
|
return _export.ArraySchema;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "BasicSchema", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return _export.
|
|
15
|
+
return _export.BasicSchema;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "BooleanSchema", {
|
|
@@ -21,10 +21,10 @@ Object.defineProperty(exports, "BooleanSchema", {
|
|
|
21
21
|
return _export.BooleanSchema;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "JsonSchema", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return _export.
|
|
27
|
+
return _export.JsonSchema;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "NumberSchema", {
|
package/dist/ai/validators.js
CHANGED
|
@@ -118,21 +118,19 @@ function checkAllTypesAreStrings(schema) {
|
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
120
|
if (schema.type === "array") {
|
|
121
|
-
|
|
122
|
-
if (!arraySchema.items) {
|
|
121
|
+
if (!schema.items) {
|
|
123
122
|
return true;
|
|
124
123
|
}
|
|
125
|
-
if (Array.isArray(
|
|
126
|
-
return
|
|
124
|
+
if (Array.isArray(schema.items)) {
|
|
125
|
+
return schema.items.every(item => checkAllTypesAreStrings(item));
|
|
127
126
|
}
|
|
128
|
-
return checkAllTypesAreStrings(
|
|
127
|
+
return checkAllTypesAreStrings(schema.items);
|
|
129
128
|
}
|
|
130
129
|
if (schema.type === "object") {
|
|
131
|
-
|
|
132
|
-
if (!objectSchema.properties) {
|
|
130
|
+
if (!schema.properties) {
|
|
133
131
|
return true;
|
|
134
132
|
}
|
|
135
|
-
return Object.values(
|
|
133
|
+
return Object.values(schema.properties).every(prop => checkAllTypesAreStrings(prop));
|
|
136
134
|
}
|
|
137
135
|
return false;
|
|
138
136
|
}
|
package/dist/helpers/export.d.ts
CHANGED
|
@@ -1023,7 +1023,7 @@ export type Trigger = string | Locator | ((page: Page) => Promise<void>);
|
|
|
1023
1023
|
* const attachment = await uploadFileToS3(file, { s3Configs: s3Config });
|
|
1024
1024
|
*
|
|
1025
1025
|
* // Use with download operations
|
|
1026
|
-
* const downloadedFile = await
|
|
1026
|
+
* const downloadedFile = await saveFileToS3(page, url, { s3Configs: s3Config });
|
|
1027
1027
|
* ```
|
|
1028
1028
|
*/
|
|
1029
1029
|
export interface S3Configs {
|
|
@@ -1090,73 +1090,6 @@ export interface S3UploadOptions {
|
|
|
1090
1090
|
*/
|
|
1091
1091
|
export type S3UploadableFile = Download | Uint8Array | Buffer | ReadStream;
|
|
1092
1092
|
|
|
1093
|
-
/**
|
|
1094
|
-
* Downloads a file from a web page and uploads it to S3 storage.
|
|
1095
|
-
* This function supports three different ways to trigger a download:
|
|
1096
|
-
* - By URL
|
|
1097
|
-
* - By clicking on a Playwright locator
|
|
1098
|
-
* - By executing a callback function that takes a Playwright page as an argument and uses it to initiate the download.
|
|
1099
|
-
* @param {Page} page - The Playwright Page object.
|
|
1100
|
-
* @param {Trigger} trigger - [Trigger](../type-aliases/Trigger) to use for downloading the file.
|
|
1101
|
-
* @param {number} [timeoutInMs] - The timeout in milliseconds for the download operation. Default = 5000
|
|
1102
|
-
* @param {S3UploadOptions} uploadOptions - [S3UploadOptions](../interfaces/S3UploadOptions) for uploading the file to S3.
|
|
1103
|
-
* @returns {Promise<Attachment>} A promise that resolves to an [Attachment](../interfaces/Attachment) object containing the uploaded file's details.
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```typescript URL Download and Upload
|
|
1107
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1108
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1109
|
-
*
|
|
1110
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1111
|
-
* s3Configs: {
|
|
1112
|
-
* bucket: 'my-bucket',
|
|
1113
|
-
* region: 'us-west-1',
|
|
1114
|
-
* }
|
|
1115
|
-
* };
|
|
1116
|
-
* const uploadedFile = await downloadFromPageToS3(page, "https://sandbox.intuned.dev/pdfs", uploadOptions);
|
|
1117
|
-
* console.log(uploadedFile.getS3Key());
|
|
1118
|
-
* ```
|
|
1119
|
-
*
|
|
1120
|
-
* @example
|
|
1121
|
-
* ```typescript Locator Download and Upload
|
|
1122
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1123
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1124
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1125
|
-
* s3Configs: {
|
|
1126
|
-
* bucket: 'my-bucket',
|
|
1127
|
-
* region: 'us-west-1',
|
|
1128
|
-
* }
|
|
1129
|
-
* };
|
|
1130
|
-
* const uploadedFile = await downloadFromPageToS3(page, page.locator("[href='/download/file.pdf']"), uploadOptions);
|
|
1131
|
-
* console.log(uploadedFile.getS3Key());
|
|
1132
|
-
* ```
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```typescript Callback Function Download and Upload
|
|
1136
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1137
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1138
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1139
|
-
* s3Configs: {
|
|
1140
|
-
* bucket: 'my-bucket',
|
|
1141
|
-
* region: 'us-west-1',
|
|
1142
|
-
* }
|
|
1143
|
-
* };
|
|
1144
|
-
* const uploadedFile = await downloadFromPageToS3(page, async (page) => {
|
|
1145
|
-
* await page.locator("button:has-text('Download')").click();
|
|
1146
|
-
* }, uploadOptions);
|
|
1147
|
-
* console.log(uploadedFile.getS3Key());
|
|
1148
|
-
* ```
|
|
1149
|
-
* @note
|
|
1150
|
-
* - If a URL is provided as the trigger, a new page will be created and closed after the download is complete.
|
|
1151
|
-
* - If a locator is provided as the trigger, the page will be used to click the element and initiate the download.
|
|
1152
|
-
* - If a callback function is provided as the trigger, the function will be called with the page object as an argument and will be responsible for initiating the download.
|
|
1153
|
-
*/
|
|
1154
|
-
export declare function downloadFromPageToS3(
|
|
1155
|
-
page: Page,
|
|
1156
|
-
trigger: Trigger,
|
|
1157
|
-
uploadOptions: S3UploadOptions,
|
|
1158
|
-
timeoutInMs?: number
|
|
1159
|
-
): Promise<Attachment>;
|
|
1160
1093
|
/**
|
|
1161
1094
|
* Downloads a file from a web page and uploads it to S3 storage.
|
|
1162
1095
|
* This function supports three different ways to trigger a download:
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1023,7 +1023,7 @@ export type Trigger = string | Locator | ((page: Page) => Promise<void>);
|
|
|
1023
1023
|
* const attachment = await uploadFileToS3(file, { s3Configs: s3Config });
|
|
1024
1024
|
*
|
|
1025
1025
|
* // Use with download operations
|
|
1026
|
-
* const downloadedFile = await
|
|
1026
|
+
* const downloadedFile = await saveFileToS3(page, url, { s3Configs: s3Config });
|
|
1027
1027
|
* ```
|
|
1028
1028
|
*/
|
|
1029
1029
|
export interface S3Configs {
|
|
@@ -1090,73 +1090,6 @@ export interface S3UploadOptions {
|
|
|
1090
1090
|
*/
|
|
1091
1091
|
export type S3UploadableFile = Download | Uint8Array | Buffer | ReadStream;
|
|
1092
1092
|
|
|
1093
|
-
/**
|
|
1094
|
-
* Downloads a file from a web page and uploads it to S3 storage.
|
|
1095
|
-
* This function supports three different ways to trigger a download:
|
|
1096
|
-
* - By URL
|
|
1097
|
-
* - By clicking on a Playwright locator
|
|
1098
|
-
* - By executing a callback function that takes a Playwright page as an argument and uses it to initiate the download.
|
|
1099
|
-
* @param {Page} page - The Playwright Page object.
|
|
1100
|
-
* @param {Trigger} trigger - [Trigger](../type-aliases/Trigger) to use for downloading the file.
|
|
1101
|
-
* @param {number} [timeoutInMs] - The timeout in milliseconds for the download operation. Default = 5000
|
|
1102
|
-
* @param {S3UploadOptions} uploadOptions - [S3UploadOptions](../interfaces/S3UploadOptions) for uploading the file to S3.
|
|
1103
|
-
* @returns {Promise<Attachment>} A promise that resolves to an [Attachment](../interfaces/Attachment) object containing the uploaded file's details.
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```typescript URL Download and Upload
|
|
1107
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1108
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1109
|
-
*
|
|
1110
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1111
|
-
* s3Configs: {
|
|
1112
|
-
* bucket: 'my-bucket',
|
|
1113
|
-
* region: 'us-west-1',
|
|
1114
|
-
* }
|
|
1115
|
-
* };
|
|
1116
|
-
* const uploadedFile = await downloadFromPageToS3(page, "https://sandbox.intuned.dev/pdfs", uploadOptions);
|
|
1117
|
-
* console.log(uploadedFile.getS3Key());
|
|
1118
|
-
* ```
|
|
1119
|
-
*
|
|
1120
|
-
* @example
|
|
1121
|
-
* ```typescript Locator Download and Upload
|
|
1122
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1123
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1124
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1125
|
-
* s3Configs: {
|
|
1126
|
-
* bucket: 'my-bucket',
|
|
1127
|
-
* region: 'us-west-1',
|
|
1128
|
-
* }
|
|
1129
|
-
* };
|
|
1130
|
-
* const uploadedFile = await downloadFromPageToS3(page, page.locator("[href='/download/file.pdf']"), uploadOptions);
|
|
1131
|
-
* console.log(uploadedFile.getS3Key());
|
|
1132
|
-
* ```
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```typescript Callback Function Download and Upload
|
|
1136
|
-
* import { downloadFromPageToS3 } from "@intuned/browser";
|
|
1137
|
-
* import { S3UploadOptions } from "@intuned/sdk/types";
|
|
1138
|
-
* const uploadOptions: S3UploadOptions = {
|
|
1139
|
-
* s3Configs: {
|
|
1140
|
-
* bucket: 'my-bucket',
|
|
1141
|
-
* region: 'us-west-1',
|
|
1142
|
-
* }
|
|
1143
|
-
* };
|
|
1144
|
-
* const uploadedFile = await downloadFromPageToS3(page, async (page) => {
|
|
1145
|
-
* await page.locator("button:has-text('Download')").click();
|
|
1146
|
-
* }, uploadOptions);
|
|
1147
|
-
* console.log(uploadedFile.getS3Key());
|
|
1148
|
-
* ```
|
|
1149
|
-
* @note
|
|
1150
|
-
* - If a URL is provided as the trigger, a new page will be created and closed after the download is complete.
|
|
1151
|
-
* - If a locator is provided as the trigger, the page will be used to click the element and initiate the download.
|
|
1152
|
-
* - If a callback function is provided as the trigger, the function will be called with the page object as an argument and will be responsible for initiating the download.
|
|
1153
|
-
*/
|
|
1154
|
-
export declare function downloadFromPageToS3(
|
|
1155
|
-
page: Page,
|
|
1156
|
-
trigger: Trigger,
|
|
1157
|
-
uploadOptions: S3UploadOptions,
|
|
1158
|
-
timeoutInMs?: number
|
|
1159
|
-
): Promise<Attachment>;
|
|
1160
1093
|
/**
|
|
1161
1094
|
* Downloads a file from a web page and uploads it to S3 storage.
|
|
1162
1095
|
* This function supports three different ways to trigger a download:
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.waitForNetworkIdle = waitForNetworkIdle;
|
|
7
7
|
var _locatorHelpers = require("../common/locatorHelpers");
|
|
8
|
+
var _Logger = require("../common/Logger");
|
|
8
9
|
function waitForNetworkIdle(funcOrOptions) {
|
|
9
10
|
if (funcOrOptions && typeof funcOrOptions === "object" && "page" in funcOrOptions) {
|
|
10
11
|
const {
|
|
@@ -151,7 +152,7 @@ async function waitForNetworkIdleCore({
|
|
|
151
152
|
const timeoutPromise = new Promise(resolve => {
|
|
152
153
|
setTimeout(() => {
|
|
153
154
|
var _networkSettledResolv2;
|
|
154
|
-
|
|
155
|
+
_Logger.logger.info("waiting for network to settle timed out");
|
|
155
156
|
isTimeout = true;
|
|
156
157
|
(_networkSettledResolv2 = networkSettledResolve) === null || _networkSettledResolv2 === void 0 || _networkSettledResolv2();
|
|
157
158
|
resolve();
|
|
@@ -162,17 +163,17 @@ async function waitForNetworkIdleCore({
|
|
|
162
163
|
actionDone = true;
|
|
163
164
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
164
165
|
await maybeSettle();
|
|
165
|
-
|
|
166
|
+
_Logger.logger.info("-- Start waiting for network to settle... --");
|
|
166
167
|
let shouldContinue = true;
|
|
167
168
|
while (shouldContinue) {
|
|
168
|
-
|
|
169
|
+
_Logger.logger.info(`waiting for network to settle, ${requestCounter} requests pending`);
|
|
169
170
|
await Promise.race([networkSettledPromise, timeoutPromise]);
|
|
170
171
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
171
172
|
if (actionDone && requestCounter <= maxInflightRequests || isTimeout) {
|
|
172
173
|
if (isTimeout) {
|
|
173
|
-
|
|
174
|
+
_Logger.logger.info("Exiting due to timeout, network did not settle");
|
|
174
175
|
} else {
|
|
175
|
-
|
|
176
|
+
_Logger.logger.info("network settled, no pending requests");
|
|
176
177
|
}
|
|
177
178
|
shouldContinue = false;
|
|
178
179
|
} else {
|
|
@@ -181,7 +182,7 @@ async function waitForNetworkIdleCore({
|
|
|
181
182
|
});
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
|
-
|
|
185
|
+
_Logger.logger.info("-- Finished waiting for network to settle --");
|
|
185
186
|
return result;
|
|
186
187
|
} finally {
|
|
187
188
|
page.off("request", onRequest);
|
package/dist/index.d.js
CHANGED
|
@@ -3,80 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "goToUrl", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _gotoUrl.goToUrl;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "processDate", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _processDate.processDate;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "resolveUrl", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _resolveUrl.resolveUrl;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "sanitizeHtml", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _sanitizeHtml.sanitizeHtml;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "saveFileToS3", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _saveFileToS.saveFileToS3;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "uploadFileToS3", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _uploadFileToS.uploadFileToS3;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "validateDataUsingSchema", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _validateDataUsingSchema.validateDataUsingSchema;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "waitForDomSettled", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _waitForDomSettled.waitForDomSettled;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, "waitForNetworkIdle", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return _waitForNetworkIdle.waitForNetworkIdle;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
var _sanitizeHtml = require("./helpers/sanitizeHtml");
|
|
73
|
-
var _downloadFile = require("./helpers/downloadFile");
|
|
74
|
-
var _saveFileToS = require("./helpers/saveFileToS3");
|
|
75
|
-
var _filterEmptyValues = require("./helpers/filterEmptyValues");
|
|
76
|
-
var _gotoUrl = require("./helpers/gotoUrl");
|
|
77
|
-
var _processDate = require("./helpers/processDate");
|
|
78
|
-
var _resolveUrl = require("./helpers/resolveUrl");
|
|
79
|
-
var _uploadFileToS = require("./helpers/uploadFileToS3");
|
|
80
|
-
var _validateDataUsingSchema = require("./helpers/validateDataUsingSchema");
|
|
81
|
-
var _waitForDomSettled = require("./helpers/waitForDomSettled");
|
|
82
|
-
var _waitForNetworkIdle = require("./helpers/waitForNetworkIdle");
|
|
6
|
+
var _export = require("./helpers/export");
|
|
7
|
+
Object.keys(_export).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _export[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _export[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export * from "./helpers/export";
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
DataObject,
|
|
5
|
+
DataInput,
|
|
6
|
+
Attachment,
|
|
7
|
+
Trigger,
|
|
8
|
+
S3Configs,
|
|
9
|
+
S3UploadOptions,
|
|
10
|
+
S3UploadableFile,
|
|
11
|
+
AttachmentType,
|
|
12
|
+
SanitizeHtmlOptions,
|
|
13
|
+
} from "./helpers/export";
|
package/dist/index.js
CHANGED
|
@@ -3,82 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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");
|
|
6
|
+
var _helpers = require("./helpers");
|
|
7
|
+
Object.keys(_helpers).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _helpers[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _helpers[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -8,6 +8,8 @@ var _getModelProvider = require("../../common/getModelProvider");
|
|
|
8
8
|
var _Anthropic = require("./providers/Anthropic");
|
|
9
9
|
var _OpenAI = require("./providers/OpenAI");
|
|
10
10
|
var _Gemini = require("./providers/Gemini");
|
|
11
|
+
var _dotenv = require("dotenv");
|
|
12
|
+
(0, _dotenv.config)();
|
|
11
13
|
class APIGateway {
|
|
12
14
|
constructor() {
|
|
13
15
|
this.config = this.getDefaultConfig();
|
|
@@ -39,10 +41,20 @@ class APIGateway {
|
|
|
39
41
|
apiKey,
|
|
40
42
|
extraHeaders
|
|
41
43
|
} = options;
|
|
42
|
-
|
|
44
|
+
let apiKeyToUse = apiKey;
|
|
45
|
+
if (apiKey === undefined) {
|
|
46
|
+
if (model.toLowerCase().includes("anthropic")) {
|
|
47
|
+
apiKeyToUse = process.env.ANTHROPIC_API_KEY;
|
|
48
|
+
} else if (model.toLowerCase().includes("openai")) {
|
|
49
|
+
apiKeyToUse = process.env.OPENAI_API_KEY;
|
|
50
|
+
} else if (model.toLowerCase().includes("google")) {
|
|
51
|
+
apiKeyToUse = process.env.GOOGLE_API_KEY;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (apiKeyToUse) {
|
|
43
55
|
return {
|
|
44
56
|
model,
|
|
45
|
-
apiKey,
|
|
57
|
+
apiKey: apiKeyToUse,
|
|
46
58
|
extraHeaders,
|
|
47
59
|
baseUrl: undefined
|
|
48
60
|
};
|
package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js
CHANGED
|
@@ -195,7 +195,7 @@ const booksTemplate = `
|
|
|
195
195
|
(0, _extendedTest.expect)(fifthResult.isOk()).toBe(true);
|
|
196
196
|
const appendedBooks = fifthResult._unsafeUnwrap();
|
|
197
197
|
(0, _extendedTest.expect)(appendedBooks).toHaveLength(4);
|
|
198
|
-
|
|
198
|
+
_Logger.logger.info("All cache behavior tests completed successfully!");
|
|
199
199
|
const outsideTemplate = appendedTemplate + `
|
|
200
200
|
<div class="outside-books-list">
|
|
201
201
|
<div class="book-page">
|
|
@@ -210,7 +210,7 @@ const booksTemplate = `
|
|
|
210
210
|
(0, _extendedTest.expect)(sixthResult.isOk()).toBe(true);
|
|
211
211
|
const outsideBooks = sixthResult._unsafeUnwrap();
|
|
212
212
|
(0, _extendedTest.expect)(outsideBooks).toHaveLength(4);
|
|
213
|
-
|
|
213
|
+
_Logger.logger.info("All cache behavior tests completed successfully!");
|
|
214
214
|
});
|
|
215
215
|
(0, _extendedTest.test)("should handle cache size limit correctly", async ({
|
|
216
216
|
page
|
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
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;
|