@purepageio/fetch-engines 0.7.2 → 0.8.1
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/README.md
CHANGED
|
@@ -65,9 +65,10 @@ await engine.cleanup();
|
|
|
65
65
|
import { fetchStructuredContent } from "@purepageio/fetch-engines";
|
|
66
66
|
import { z } from "zod";
|
|
67
67
|
|
|
68
|
+
// IMPORTANT: All schema fields must have .describe() calls to guide the AI model
|
|
68
69
|
const schema = z.object({
|
|
69
|
-
title: z.string(),
|
|
70
|
-
summary: z.string(),
|
|
70
|
+
title: z.string().describe("The title of the article"),
|
|
71
|
+
summary: z.string().describe("A brief summary of the article content"),
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
// model is required - use any model supported by your API provider
|
|
@@ -92,6 +93,8 @@ const result = await fetchStructuredContent("https://example.com/article", schem
|
|
|
92
93
|
});
|
|
93
94
|
```
|
|
94
95
|
|
|
96
|
+
When you supply a custom `baseURL`, the engine automatically switches to the Vercel AI SDK's `createOpenAICompatible` provider (instead of `createOpenAI`) so OpenAI-compatible services like OpenRouter receive the correct API-key auth flow.
|
|
97
|
+
|
|
95
98
|
## Configuration
|
|
96
99
|
|
|
97
100
|
### Essentials
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import type { PlaywrightEngineConfig } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for OpenAI-compatible API providers
|
|
@@ -49,16 +49,27 @@ export interface StructuredContentResult<T> {
|
|
|
49
49
|
export declare class StructuredContentEngine {
|
|
50
50
|
private hybridEngine;
|
|
51
51
|
constructor(config?: PlaywrightEngineConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Extracts field descriptions from a Zod object schema
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
private extractFieldDescriptions;
|
|
57
|
+
/**
|
|
58
|
+
* Validates that all fields in the schema have descriptions
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private validateSchemaDescriptions;
|
|
52
62
|
/**
|
|
53
63
|
* Fetches content from a URL and extracts structured data using AI
|
|
54
64
|
*
|
|
55
65
|
* @param url The URL to fetch content from
|
|
56
|
-
* @param schema Zod schema defining the structure of data to extract
|
|
66
|
+
* @param schema Zod schema defining the structure of data to extract (all fields must have .describe() calls)
|
|
57
67
|
* @param options Additional options for the extraction process
|
|
58
68
|
* @returns Promise resolving to structured data and metadata
|
|
59
|
-
* @throws Error if API key is not set or if extraction fails
|
|
69
|
+
* @throws Error if API key is not set, if schema fields lack descriptions, or if extraction fails
|
|
60
70
|
*/
|
|
61
71
|
fetchStructuredContent<T>(url: string, schema: z.ZodSchema<T>, options: StructuredContentOptions): Promise<StructuredContentResult<T>>;
|
|
72
|
+
private getOpenAIProvider;
|
|
62
73
|
/**
|
|
63
74
|
* Get model-specific configuration options
|
|
64
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StructuredContentEngine.d.ts","sourceRoot":"","sources":["../src/StructuredContentEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StructuredContentEngine.d.ts","sourceRoot":"","sources":["../src/StructuredContentEngine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAQzD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,sJAAsJ;IACtJ,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,YAAY,CAA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OrC"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { generateObject } from "ai";
|
|
1
|
+
import { generateObject, NoObjectGeneratedError } from "ai";
|
|
2
2
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
3
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
4
|
+
import { z } from "zod";
|
|
3
5
|
import { HybridEngine } from "./HybridEngine.js";
|
|
6
|
+
// Suppress AI SDK warnings about responseFormat/structuredOutputs
|
|
7
|
+
// This warning appears when using OpenAI-compatible APIs that don't support structured outputs
|
|
8
|
+
if (typeof globalThis !== "undefined") {
|
|
9
|
+
globalThis.AI_SDK_LOG_WARNINGS = false;
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Engine for fetching web content and extracting structured data using AI
|
|
6
13
|
*/
|
|
@@ -13,14 +20,82 @@ export class StructuredContentEngine {
|
|
|
13
20
|
markdown: true,
|
|
14
21
|
});
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Extracts field descriptions from a Zod object schema
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
extractFieldDescriptions(schema) {
|
|
28
|
+
const descriptions = new Map();
|
|
29
|
+
if (schema instanceof z.ZodObject) {
|
|
30
|
+
const shape = schema.shape;
|
|
31
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
32
|
+
// In Zod v4, description is stored directly on the schema object
|
|
33
|
+
let description;
|
|
34
|
+
const fieldSchemaAny = fieldSchema;
|
|
35
|
+
const def = fieldSchemaAny._def;
|
|
36
|
+
// Handle optional fields - check innerType for description
|
|
37
|
+
// When using .describe().optional(), description is on innerType
|
|
38
|
+
// When using .optional().describe(), description is on the optional wrapper
|
|
39
|
+
if (def?.typeName === "ZodOptional") {
|
|
40
|
+
description = fieldSchemaAny._def?.innerType?.description || fieldSchemaAny.description;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
description = fieldSchemaAny.description;
|
|
44
|
+
}
|
|
45
|
+
if (description) {
|
|
46
|
+
descriptions.set(key, description);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return descriptions;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validates that all fields in the schema have descriptions
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
validateSchemaDescriptions(schema) {
|
|
57
|
+
if (!(schema instanceof z.ZodObject)) {
|
|
58
|
+
throw new Error("Schema must be a Zod object. Use z.object() to define your schema structure.");
|
|
59
|
+
}
|
|
60
|
+
const shape = schema.shape;
|
|
61
|
+
const missingDescriptions = [];
|
|
62
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
63
|
+
const fieldSchemaAny = fieldSchema;
|
|
64
|
+
// In Zod v4, description is stored directly on the schema object
|
|
65
|
+
// Check if it's an optional field by checking for innerType
|
|
66
|
+
let hasDescription = false;
|
|
67
|
+
// Check if this is an optional field (has innerType)
|
|
68
|
+
if (fieldSchemaAny._def?.innerType) {
|
|
69
|
+
// For optional fields:
|
|
70
|
+
// - When using .describe().optional(), description is on innerType
|
|
71
|
+
// - When using .optional().describe(), description is on the optional wrapper
|
|
72
|
+
hasDescription = !!(fieldSchemaAny._def.innerType.description || fieldSchemaAny.description);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// For non-optional fields, description is directly on the schema
|
|
76
|
+
hasDescription = !!fieldSchemaAny.description;
|
|
77
|
+
}
|
|
78
|
+
if (!hasDescription) {
|
|
79
|
+
missingDescriptions.push(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (missingDescriptions.length > 0) {
|
|
83
|
+
throw new Error(`All schema fields must have descriptions. Missing descriptions for: ${missingDescriptions.join(", ")}\n\n` +
|
|
84
|
+
`Example:\n` +
|
|
85
|
+
`z.object({\n` +
|
|
86
|
+
` ${missingDescriptions[0]}: z.string().describe("Description of ${missingDescriptions[0]}"),\n` +
|
|
87
|
+
` // ... other fields\n` +
|
|
88
|
+
`})`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
16
91
|
/**
|
|
17
92
|
* Fetches content from a URL and extracts structured data using AI
|
|
18
93
|
*
|
|
19
94
|
* @param url The URL to fetch content from
|
|
20
|
-
* @param schema Zod schema defining the structure of data to extract
|
|
95
|
+
* @param schema Zod schema defining the structure of data to extract (all fields must have .describe() calls)
|
|
21
96
|
* @param options Additional options for the extraction process
|
|
22
97
|
* @returns Promise resolving to structured data and metadata
|
|
23
|
-
* @throws Error if API key is not set or if extraction fails
|
|
98
|
+
* @throws Error if API key is not set, if schema fields lack descriptions, or if extraction fails
|
|
24
99
|
*/
|
|
25
100
|
async fetchStructuredContent(url, schema, options) {
|
|
26
101
|
const { model, customPrompt = "", engineConfig = {}, apiConfig = {} } = options;
|
|
@@ -35,20 +110,44 @@ export class StructuredContentEngine {
|
|
|
35
110
|
if (result.contentType !== "markdown") {
|
|
36
111
|
throw new Error("Failed to convert content to markdown");
|
|
37
112
|
}
|
|
113
|
+
// Validate that all fields have descriptions
|
|
114
|
+
this.validateSchemaDescriptions(schema);
|
|
115
|
+
// Extract field descriptions to include in prompt
|
|
116
|
+
const fieldDescriptions = this.extractFieldDescriptions(schema);
|
|
117
|
+
const schemaGuidance = Array.from(fieldDescriptions.entries())
|
|
118
|
+
.map(([field, description]) => `- ${field}: ${description}`)
|
|
119
|
+
.join("\n");
|
|
38
120
|
const systemPrompt = `You are an expert at extracting structured data from web content.
|
|
39
121
|
Extract the requested information from the provided markdown content accurately and completely.
|
|
122
|
+
Return the data as a valid JSON object matching the exact schema provided.
|
|
123
|
+
|
|
124
|
+
Field requirements:
|
|
125
|
+
${schemaGuidance}
|
|
126
|
+
|
|
127
|
+
IMPORTANT: Pay careful attention to data types:
|
|
128
|
+
- Numbers should be returned as numeric values (not strings with currency symbols)
|
|
129
|
+
- Strings should be returned as plain text strings
|
|
130
|
+
- Follow the exact schema structure and field descriptions provided above
|
|
131
|
+
|
|
40
132
|
${customPrompt ? `\nAdditional context: ${customPrompt}` : ""}
|
|
41
133
|
|
|
42
134
|
Content to analyze:
|
|
43
135
|
${result.content}`;
|
|
44
136
|
const modelConfig = this.getModelConfig(model);
|
|
137
|
+
// Build headers - for OpenAI-compatible providers, don't add Authorization header
|
|
138
|
+
// as createOpenAICompatible handles it via apiKey parameter
|
|
139
|
+
const normalizedBaseURL = apiConfig.baseURL?.replace(/\/+$/, "");
|
|
140
|
+
const defaultOpenAIBaseURL = "https://api.openai.com/v1";
|
|
141
|
+
const isOpenAICompatible = normalizedBaseURL && normalizedBaseURL !== defaultOpenAIBaseURL;
|
|
45
142
|
const headers = {
|
|
46
143
|
...(apiConfig.headers ?? {}),
|
|
47
|
-
|
|
144
|
+
// Only add Authorization header for standard OpenAI API
|
|
145
|
+
// OpenAI-compatible providers handle auth via apiKey parameter in createOpenAICompatible
|
|
146
|
+
...(!isOpenAICompatible && !apiConfig.headers?.Authorization ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
48
147
|
};
|
|
49
|
-
const openai =
|
|
148
|
+
const openai = this.getOpenAIProvider({
|
|
50
149
|
apiKey,
|
|
51
|
-
|
|
150
|
+
baseURL: apiConfig.baseURL,
|
|
52
151
|
headers,
|
|
53
152
|
});
|
|
54
153
|
try {
|
|
@@ -71,9 +170,109 @@ ${result.content}`;
|
|
|
71
170
|
};
|
|
72
171
|
}
|
|
73
172
|
catch (error) {
|
|
173
|
+
if (NoObjectGeneratedError.isInstance(error)) {
|
|
174
|
+
const errorMessage = `Failed to extract structured data: ${error.message}`;
|
|
175
|
+
const details = [];
|
|
176
|
+
// Get expected keys from schema
|
|
177
|
+
const expectedKeys = schema instanceof z.ZodObject ? Object.keys(schema.shape) : [];
|
|
178
|
+
if (error.text) {
|
|
179
|
+
// Try to parse and format the JSON response if possible
|
|
180
|
+
let formattedResponse = error.text;
|
|
181
|
+
let hasWeirdKeys = false;
|
|
182
|
+
let receivedKeys = [];
|
|
183
|
+
try {
|
|
184
|
+
const parsed = JSON.parse(error.text);
|
|
185
|
+
formattedResponse = JSON.stringify(parsed, null, 2);
|
|
186
|
+
receivedKeys = Object.keys(parsed);
|
|
187
|
+
// Check if keys have weird prefixes (like dots) or don't match expected keys
|
|
188
|
+
hasWeirdKeys = receivedKeys.some((key) => key.startsWith(".") || key.includes(" ") || (expectedKeys.length > 0 && !expectedKeys.includes(key)));
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// Not valid JSON, show raw text
|
|
192
|
+
formattedResponse = error.text.substring(0, 300) + (error.text.length > 300 ? "..." : "");
|
|
193
|
+
}
|
|
194
|
+
if (hasWeirdKeys && expectedKeys.length > 0) {
|
|
195
|
+
details.push(`⚠️ Key mismatch detected:`);
|
|
196
|
+
details.push(` Expected: ${expectedKeys.join(", ")}`);
|
|
197
|
+
details.push(` Received: ${receivedKeys.join(", ")}`);
|
|
198
|
+
details.push(`\n The model returned keys with unexpected format (possibly prefixed with dots or spaces).`);
|
|
199
|
+
details.push(` This usually indicates the model doesn't properly support structured outputs.`);
|
|
200
|
+
}
|
|
201
|
+
details.push(`Model response:\n${formattedResponse}`);
|
|
202
|
+
}
|
|
203
|
+
if (error.finishReason && error.finishReason !== "unknown") {
|
|
204
|
+
details.push(`Finish reason: ${error.finishReason}`);
|
|
205
|
+
}
|
|
206
|
+
if (error.cause) {
|
|
207
|
+
const causeMessage = error.cause instanceof Error ? error.cause.message : String(error.cause);
|
|
208
|
+
// Parse Zod validation errors if present
|
|
209
|
+
if (causeMessage.includes("Type validation failed")) {
|
|
210
|
+
try {
|
|
211
|
+
// Try to extract the error message array from the cause
|
|
212
|
+
const zodErrorsMatch = causeMessage.match(/Error message:\s*(\[[\s\S]*\])/);
|
|
213
|
+
if (zodErrorsMatch) {
|
|
214
|
+
const zodErrors = JSON.parse(zodErrorsMatch[1]);
|
|
215
|
+
const formattedErrors = zodErrors
|
|
216
|
+
.map((err) => {
|
|
217
|
+
const path = err.path.length > 0 ? err.path.join(".") : "root";
|
|
218
|
+
const received = err.received || "unknown";
|
|
219
|
+
return ` • ${path}: ${err.message} (expected ${err.expected}, received ${received})`;
|
|
220
|
+
})
|
|
221
|
+
.join("\n");
|
|
222
|
+
details.push(`\nSchema validation errors:\n${formattedErrors}`);
|
|
223
|
+
// Detect common type mismatches and provide helpful suggestions
|
|
224
|
+
const typeMismatches = zodErrors.filter((err) => err.expected === "number" && err.received === "string");
|
|
225
|
+
if (typeMismatches.length > 0) {
|
|
226
|
+
const mismatchedFields = typeMismatches
|
|
227
|
+
.map((err) => err.path.join("."))
|
|
228
|
+
.join(", ");
|
|
229
|
+
details.push(`\n💡 Tip: Fields (${mismatchedFields}) are being returned as strings but expected as numbers.`);
|
|
230
|
+
details.push(` Consider using Zod transforms to handle currency strings or other formatted numbers:`);
|
|
231
|
+
details.push(` Example: z.string().transform((val) => parseFloat(val.replace(/[^0-9.-]/g, "")))`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// Fallback: show the cause message
|
|
236
|
+
const shortCause = causeMessage.length > 200 ? causeMessage.substring(0, 200) + "..." : causeMessage;
|
|
237
|
+
details.push(`\nValidation error: ${shortCause}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// If parsing fails, show a shortened version
|
|
242
|
+
const shortCause = causeMessage.length > 300 ? causeMessage.substring(0, 300) + "..." : causeMessage;
|
|
243
|
+
details.push(`\nCause: ${shortCause}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const shortCause = causeMessage.length > 300 ? causeMessage.substring(0, 300) + "..." : causeMessage;
|
|
248
|
+
details.push(`\nCause: ${shortCause}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const fullMessage = details.length > 0
|
|
252
|
+
? `${errorMessage}\n\n${details.join("\n")}\n\n💡 Tip: This model may not support structured outputs properly. Try using a model that supports structured outputs (e.g., gpt-4o-mini, gpt-4o, claude-3.5-sonnet).`
|
|
253
|
+
: errorMessage;
|
|
254
|
+
throw new Error(fullMessage);
|
|
255
|
+
}
|
|
74
256
|
throw new Error(`Failed to extract structured data: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
257
|
}
|
|
76
258
|
}
|
|
259
|
+
getOpenAIProvider(params) {
|
|
260
|
+
const normalizedBaseURL = params.baseURL?.replace(/\/+$/, "");
|
|
261
|
+
const defaultOpenAIBaseURL = "https://api.openai.com/v1";
|
|
262
|
+
if (normalizedBaseURL && normalizedBaseURL !== defaultOpenAIBaseURL) {
|
|
263
|
+
return createOpenAICompatible({
|
|
264
|
+
name: "openai-compatible",
|
|
265
|
+
apiKey: params.apiKey,
|
|
266
|
+
baseURL: normalizedBaseURL,
|
|
267
|
+
headers: params.headers,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return createOpenAI({
|
|
271
|
+
apiKey: params.apiKey,
|
|
272
|
+
...(normalizedBaseURL && { baseURL: normalizedBaseURL }),
|
|
273
|
+
headers: params.headers,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
77
276
|
/**
|
|
78
277
|
* Get model-specific configuration options
|
|
79
278
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StructuredContentEngine.js","sourceRoot":"","sources":["../src/StructuredContentEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"StructuredContentEngine.js","sourceRoot":"","sources":["../src/StructuredContentEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,kEAAkE;AAClE,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,OAAO,MAAM,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purepageio/fetch-engines",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A collection of configurable engines for fetching HTML content using fetch or Playwright.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@ai-sdk/openai": "^2.0.30",
|
|
15
|
+
"@ai-sdk/openai-compatible": "^1.0.28",
|
|
15
16
|
"ai": "^5.0.44",
|
|
16
17
|
"axios": "^1.12.0",
|
|
17
18
|
"node-html-parser": "^7.0.1",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"@types/uuid": "^10.0.0",
|
|
37
38
|
"@typescript-eslint/eslint-plugin": "^8.29.0",
|
|
38
39
|
"@typescript-eslint/parser": "^8.29.0",
|
|
40
|
+
"dotenv": "^17.2.3",
|
|
39
41
|
"eslint": "^9.23.0",
|
|
40
42
|
"eslint-config-prettier": "^10.1.1",
|
|
41
43
|
"eslint-plugin-prettier": "^5.2.5",
|