@ordis-dev/ordis 0.1.1 ā 0.4.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/README.md +47 -0
- package/dist/cli.js +20 -4
- package/dist/cli.js.map +1 -1
- package/dist/core/error-formatter.d.ts +35 -0
- package/dist/core/error-formatter.d.ts.map +1 -0
- package/dist/core/error-formatter.js +319 -0
- package/dist/core/error-formatter.js.map +1 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +17 -3
- package/dist/core/pipeline.js.map +1 -1
- package/dist/core/preprocessor.d.ts +35 -0
- package/dist/core/preprocessor.d.ts.map +1 -0
- package/dist/core/preprocessor.js +297 -0
- package/dist/core/preprocessor.js.map +1 -0
- package/dist/core/types.d.ts +24 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/validator.d.ts +3 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/client.d.ts.map +1 -1
- package/dist/llm/client.js +23 -3
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/types.d.ts +2 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/schemas/types.d.ts +3 -1
- package/dist/schemas/types.d.ts.map +1 -1
- package/package.json +4 -1
- package/dist/__tests__/api.test.d.ts +0 -5
- package/dist/__tests__/api.test.d.ts.map +0 -1
- package/dist/__tests__/api.test.js +0 -95
- package/dist/__tests__/api.test.js.map +0 -1
- package/dist/__tests__/cli.test.d.ts +0 -6
- package/dist/__tests__/cli.test.d.ts.map +0 -1
- package/dist/__tests__/cli.test.js +0 -103
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/cli/__tests__/cli.test.d.ts +0 -5
- package/dist/cli/__tests__/cli.test.d.ts.map +0 -1
- package/dist/cli/__tests__/cli.test.js +0 -13
- package/dist/cli/__tests__/cli.test.js.map +0 -1
- package/dist/core/__tests__/pipeline.test.d.ts +0 -5
- package/dist/core/__tests__/pipeline.test.d.ts.map +0 -1
- package/dist/core/__tests__/pipeline.test.js +0 -334
- package/dist/core/__tests__/pipeline.test.js.map +0 -1
- package/dist/core/__tests__/validator.test.d.ts +0 -5
- package/dist/core/__tests__/validator.test.d.ts.map +0 -1
- package/dist/core/__tests__/validator.test.js +0 -124
- package/dist/core/__tests__/validator.test.js.map +0 -1
- package/dist/llm/__tests__/client.test.d.ts +0 -5
- package/dist/llm/__tests__/client.test.d.ts.map +0 -1
- package/dist/llm/__tests__/client.test.js +0 -350
- package/dist/llm/__tests__/client.test.js.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.d.ts +0 -5
- package/dist/llm/__tests__/prompt-builder.test.d.ts.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.js +0 -171
- package/dist/llm/__tests__/prompt-builder.test.js.map +0 -1
- package/dist/llm/__tests__/retry.test.d.ts +0 -5
- package/dist/llm/__tests__/retry.test.d.ts.map +0 -1
- package/dist/llm/__tests__/retry.test.js +0 -350
- package/dist/llm/__tests__/retry.test.js.map +0 -1
- package/dist/llm/__tests__/token-counter.test.d.ts +0 -5
- package/dist/llm/__tests__/token-counter.test.d.ts.map +0 -1
- package/dist/llm/__tests__/token-counter.test.js +0 -166
- package/dist/llm/__tests__/token-counter.test.js.map +0 -1
- package/dist/schemas/__tests__/integration.test.d.ts +0 -5
- package/dist/schemas/__tests__/integration.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/integration.test.js +0 -366
- package/dist/schemas/__tests__/integration.test.js.map +0 -1
- package/dist/schemas/__tests__/loader.test.d.ts +0 -5
- package/dist/schemas/__tests__/loader.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/loader.test.js +0 -271
- package/dist/schemas/__tests__/loader.test.js.map +0 -1
- package/dist/schemas/__tests__/validator.test.d.ts +0 -5
- package/dist/schemas/__tests__/validator.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/validator.test.js +0 -592
- package/dist/schemas/__tests__/validator.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Ordis is a local-first tool and library that turns messy, unstructured text into
|
|
|
16
16
|
- **Schema-first workflow**: Define your data structure upfront
|
|
17
17
|
- **Deterministic output**: Returns validated records or structured failures
|
|
18
18
|
- **Token budget awareness**: Automatic token counting with warnings and limits
|
|
19
|
+
- **HTML preprocessing**: Strip noise from web pages before extraction
|
|
19
20
|
- **Dual-purpose**: Use as a CLI or import as a library
|
|
20
21
|
- **TypeScript support**: Full type definitions included
|
|
21
22
|
|
|
@@ -167,6 +168,30 @@ const result = await extract({
|
|
|
167
168
|
});
|
|
168
169
|
```
|
|
169
170
|
|
|
171
|
+
**Extracting from HTML:**
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { extract, loadSchema } from '@ordis-dev/ordis';
|
|
175
|
+
|
|
176
|
+
const schema = await loadSchema('./schema.json');
|
|
177
|
+
|
|
178
|
+
// Strip HTML noise before extraction
|
|
179
|
+
const result = await extract({
|
|
180
|
+
input: rawHtmlContent,
|
|
181
|
+
schema,
|
|
182
|
+
llmConfig: { baseURL: 'http://localhost:11434/v1', model: 'llama3.2:3b' },
|
|
183
|
+
preprocessing: {
|
|
184
|
+
stripHtml: true // Removes scripts, styles, nav, ads, etc.
|
|
185
|
+
// Or with options:
|
|
186
|
+
// stripHtml: {
|
|
187
|
+
// preserveStructure: true, // Convert headings/lists to markdown
|
|
188
|
+
// removeSelectors: ['.sidebar', '#comments'],
|
|
189
|
+
// maxLength: 10000
|
|
190
|
+
// }
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
170
195
|
## What Works
|
|
171
196
|
|
|
172
197
|
- ā
Schema loader and validator
|
|
@@ -179,6 +204,7 @@ const result = await extract({
|
|
|
179
204
|
- ā
Field-level confidence tracking
|
|
180
205
|
- ā
TypeScript type definitions
|
|
181
206
|
- ā
Performance benchmarks
|
|
207
|
+
- ā
HTML preprocessing for noisy web content
|
|
182
208
|
|
|
183
209
|
## Performance
|
|
184
210
|
|
|
@@ -191,6 +217,26 @@ npm run benchmark
|
|
|
191
217
|
|
|
192
218
|
## Roadmap
|
|
193
219
|
|
|
220
|
+
**Completed in v0.4.0:**
|
|
221
|
+
- ā
User-friendly error messages ([#63](https://github.com/ordis-dev/ordis/issues/63))
|
|
222
|
+
- Emoji indicators (ā, š”, ā¹ļø) for quick scanning
|
|
223
|
+
- Expected vs. actual values for validation errors
|
|
224
|
+
- Actionable suggestions for common issues
|
|
225
|
+
- Service-specific troubleshooting (Ollama, LM Studio, OpenAI)
|
|
226
|
+
- File system error handling (ENOENT, EACCES)
|
|
227
|
+
- ā
Debug mode enhancements
|
|
228
|
+
- Full LLM request/response logging
|
|
229
|
+
- Token usage breakdown
|
|
230
|
+
- System and user prompt visibility
|
|
231
|
+
- Detailed error context
|
|
232
|
+
|
|
233
|
+
**Completed in v0.2.0:**
|
|
234
|
+
- ā
HTML stripping/preprocessing before extraction ([#59](https://github.com/ordis-dev/ordis/issues/59))
|
|
235
|
+
- `stripHtml: true` removes HTML tags, keeps text content
|
|
236
|
+
- `preserveStructure: true` converts headings/lists to markdown-like format
|
|
237
|
+
- `removeSelectors` for custom element removal
|
|
238
|
+
- Automatic removal of scripts, styles, nav, footer, ads
|
|
239
|
+
|
|
194
240
|
**Completed in v0.1.0:**
|
|
195
241
|
- ā
Core extraction pipeline with schema validation
|
|
196
242
|
- ā
Token budget awareness and management
|
|
@@ -201,6 +247,7 @@ npm run benchmark
|
|
|
201
247
|
- ā
Support for any OpenAI-compatible API
|
|
202
248
|
|
|
203
249
|
**Upcoming:**
|
|
250
|
+
- [ ] Schema validation error line numbers ([#64](https://github.com/ordis-dev/ordis/issues/64))
|
|
204
251
|
- [ ] Smart input truncation ([#40](https://github.com/ordis-dev/ordis/issues/40))
|
|
205
252
|
- [ ] Multi-pass extraction for large inputs ([#41](https://github.com/ordis-dev/ordis/issues/41))
|
|
206
253
|
- [ ] Config file support ([#16](https://github.com/ordis-dev/ordis/issues/16))
|
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import * as fs from 'node:fs/promises';
|
|
|
8
8
|
import * as path from 'node:path';
|
|
9
9
|
import { loadSchema } from './schemas/loader.js';
|
|
10
10
|
import { extract } from './core/pipeline.js';
|
|
11
|
+
import { formatError } from './core/error-formatter.js';
|
|
11
12
|
import packageJson from '../package.json' with { type: 'json' };
|
|
12
13
|
function parseArgs(args) {
|
|
13
14
|
const parsed = {};
|
|
@@ -130,6 +131,7 @@ async function runExtraction(args) {
|
|
|
130
131
|
baseURL: args.base,
|
|
131
132
|
model: args.model,
|
|
132
133
|
...(args.apiKey && { apiKey: args.apiKey }),
|
|
134
|
+
debug: args.debug,
|
|
133
135
|
};
|
|
134
136
|
if (args.debug) {
|
|
135
137
|
console.log('[DEBUG] LLM config:', {
|
|
@@ -171,10 +173,23 @@ async function runExtraction(args) {
|
|
|
171
173
|
process.exit(0);
|
|
172
174
|
}
|
|
173
175
|
else {
|
|
174
|
-
// Output failure with errors
|
|
176
|
+
// Output failure with formatted errors
|
|
177
|
+
const formattedErrors = result.errors.map((err) => {
|
|
178
|
+
// If we have the original error in details, format that
|
|
179
|
+
const errorToFormat = err.details?.error || err;
|
|
180
|
+
const formatted = formatError(errorToFormat, {
|
|
181
|
+
model: args.model,
|
|
182
|
+
baseURL: args.base,
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
message: formatted,
|
|
186
|
+
code: err.code,
|
|
187
|
+
field: err.field,
|
|
188
|
+
};
|
|
189
|
+
});
|
|
175
190
|
const output = {
|
|
176
191
|
success: false,
|
|
177
|
-
errors:
|
|
192
|
+
errors: formattedErrors,
|
|
178
193
|
data: result.data, // May be partial
|
|
179
194
|
confidence: result.confidence,
|
|
180
195
|
meetsThreshold: result.meetsThreshold,
|
|
@@ -185,15 +200,16 @@ async function runExtraction(args) {
|
|
|
185
200
|
}
|
|
186
201
|
}
|
|
187
202
|
catch (error) {
|
|
188
|
-
// Handle unexpected errors
|
|
203
|
+
// Handle unexpected errors with formatted messages
|
|
189
204
|
if (args.debug && error instanceof Error) {
|
|
190
205
|
console.error('[DEBUG] Stack trace:', error.stack);
|
|
191
206
|
}
|
|
207
|
+
const formattedMessage = formatError(error);
|
|
192
208
|
const errorOutput = {
|
|
193
209
|
success: false,
|
|
194
210
|
errors: [
|
|
195
211
|
{
|
|
196
|
-
message:
|
|
212
|
+
message: formattedMessage,
|
|
197
213
|
code: error.code || 'UNKNOWN_ERROR',
|
|
198
214
|
},
|
|
199
215
|
],
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAEH,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAYhE,SAAS,SAAS,CAAC,IAAc;IAC7B,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACnC,QAAQ,EAAE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,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE;gBAClD,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;aACpB,CAAC,CAAC;QACP,CAAC;QAED,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,OAAO,kCAAkC,CAAC,CAAC;QACzF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error formatting utilities for user-friendly error messages
|
|
3
|
+
*/
|
|
4
|
+
import type { ValidationError } from './validator.js';
|
|
5
|
+
import type { Schema } from '../schemas/types.js';
|
|
6
|
+
import type { LLMError } from '../llm/errors.js';
|
|
7
|
+
export interface FormattedError {
|
|
8
|
+
title: string;
|
|
9
|
+
message: string;
|
|
10
|
+
suggestion?: string;
|
|
11
|
+
details?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format validation error with context and suggestions
|
|
15
|
+
* Returns a formatted string with title, message, and suggestions
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatValidationError(error: ValidationError, schema?: Schema, value?: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Format LLM error with context and recovery suggestions
|
|
20
|
+
* Returns a formatted string with title, message, suggestions, and details
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatLLMError(error: LLMError, context?: {
|
|
23
|
+
model?: string;
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
inputLength?: number;
|
|
26
|
+
}): string;
|
|
27
|
+
/**
|
|
28
|
+
* Format multiple validation errors into a readable message
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatValidationErrors(errors: ValidationError[], schema?: Schema): string;
|
|
31
|
+
/**
|
|
32
|
+
* Format any error into a user-friendly message
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatError(error: unknown, context?: Record<string, unknown>): string;
|
|
35
|
+
//# sourceMappingURL=error-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-formatter.d.ts","sourceRoot":"","sources":["../../src/core/error-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAmB,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,eAAe,EACtB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GAChB,MAAM,CAuGR;AAuBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,MAAM,CA4HT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,eAAe,EAAE,EACzB,MAAM,CAAC,EAAE,MAAM,GAChB,MAAM,CAcR;AAED;;GAEG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,MAAM,CAwDR"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error formatting utilities for user-friendly error messages
|
|
3
|
+
*/
|
|
4
|
+
import { LLMErrorCodes } from '../llm/errors.js';
|
|
5
|
+
import { PipelineErrorCodes } from './errors.js';
|
|
6
|
+
/**
|
|
7
|
+
* Format validation error with context and suggestions
|
|
8
|
+
* Returns a formatted string with title, message, and suggestions
|
|
9
|
+
*/
|
|
10
|
+
export function formatValidationError(error, schema, value) {
|
|
11
|
+
const field = error.field ? schema?.fields?.[error.field] : undefined;
|
|
12
|
+
const fieldDesc = field?.description ? ` (${field.description})` : '';
|
|
13
|
+
const formatted = {
|
|
14
|
+
title: 'Field Validation Error',
|
|
15
|
+
message: '',
|
|
16
|
+
details: [],
|
|
17
|
+
};
|
|
18
|
+
switch (error.code) {
|
|
19
|
+
case PipelineErrorCodes.FIELD_MISSING:
|
|
20
|
+
formatted.message = `Required field '${error.field}' is missing${fieldDesc}`;
|
|
21
|
+
formatted.suggestion = field?.optional
|
|
22
|
+
? `This field was expected but not marked as optional in the schema.`
|
|
23
|
+
: `The LLM didn't extract this field. Try:\n` +
|
|
24
|
+
` ⢠Make the field description more explicit\n` +
|
|
25
|
+
` ⢠Ensure the input text contains this information\n` +
|
|
26
|
+
` ⢠Mark the field as optional if it's not always present`;
|
|
27
|
+
break;
|
|
28
|
+
case PipelineErrorCodes.TYPE_MISMATCH:
|
|
29
|
+
// Use expected/actual from error if provided, otherwise infer from schema
|
|
30
|
+
const expectedType = error.expected || field?.type || 'unknown';
|
|
31
|
+
const actualType = error.actual || typeof error.value;
|
|
32
|
+
const gotValue = JSON.stringify(error.value);
|
|
33
|
+
formatted.message = `Field '${error.field}'${fieldDesc}\n` +
|
|
34
|
+
` Expected: ${expectedType}\n` +
|
|
35
|
+
` Got: ${gotValue} (${actualType})`;
|
|
36
|
+
// Type-specific suggestions
|
|
37
|
+
if (expectedType === 'number' && actualType === 'string') {
|
|
38
|
+
formatted.suggestion = `The LLM returned a string instead of a number.\n` +
|
|
39
|
+
` ⢠Check if the value contains formatting (e.g., "$1,250.00")\n` +
|
|
40
|
+
` ⢠Update schema description to request "raw number without formatting"\n` +
|
|
41
|
+
` ⢠Example: "amount as a number (e.g., 1250, not $1,250.00)"`;
|
|
42
|
+
}
|
|
43
|
+
else if (expectedType === 'string' && actualType === 'number') {
|
|
44
|
+
formatted.suggestion = `The LLM returned a number instead of a string.\n` +
|
|
45
|
+
` ⢠Update schema to use type: "number" if numeric data is expected\n` +
|
|
46
|
+
` ⢠Or clarify in description that quotes are required`;
|
|
47
|
+
}
|
|
48
|
+
else if (expectedType === 'integer' && actualType === 'number') {
|
|
49
|
+
formatted.suggestion = `Got a decimal number but expected an integer.\n` +
|
|
50
|
+
` ⢠Ask for "whole number" or "integer" in the field description`;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case PipelineErrorCodes.FIELD_INVALID:
|
|
54
|
+
// Check if expected is an array (enum values) or string (pattern)
|
|
55
|
+
const expectedValue = error.expected;
|
|
56
|
+
if (Array.isArray(expectedValue)) {
|
|
57
|
+
// Enum validation error
|
|
58
|
+
formatted.message = `Field '${error.field}' has invalid value\n` +
|
|
59
|
+
` Allowed: ${expectedValue.join(', ')}\n` +
|
|
60
|
+
` Got: ${JSON.stringify(error.value)}`;
|
|
61
|
+
formatted.suggestion = `The LLM returned a value not in the allowed list.\n` +
|
|
62
|
+
` ⢠Add the value to the enum list if it's valid\n` +
|
|
63
|
+
` ⢠Provide examples in the field description\n` +
|
|
64
|
+
` ⢠Use pattern matching if exact values aren't required`;
|
|
65
|
+
}
|
|
66
|
+
else if (typeof expectedValue === 'string' && expectedValue.startsWith('^')) {
|
|
67
|
+
// Pattern validation error
|
|
68
|
+
formatted.message = `Field '${error.field}' doesn't match required pattern\n` +
|
|
69
|
+
` Pattern: ${expectedValue}\n` +
|
|
70
|
+
` Got: ${JSON.stringify(error.value)}`;
|
|
71
|
+
formatted.suggestion = `The value doesn't match the regex pattern.\n` +
|
|
72
|
+
` ⢠Provide an example in the field description\n` +
|
|
73
|
+
` ⢠Simplify the pattern if it's too strict`;
|
|
74
|
+
}
|
|
75
|
+
else if (field?.enum) {
|
|
76
|
+
formatted.message = `Field '${error.field}' has invalid value\n` +
|
|
77
|
+
` Allowed: ${field.enum.join(', ')}\n` +
|
|
78
|
+
` Got: ${JSON.stringify(error.value)}`;
|
|
79
|
+
formatted.suggestion = `The LLM returned a value not in the allowed list.\n` +
|
|
80
|
+
` ⢠Add the value to the enum list if it's valid\n` +
|
|
81
|
+
` ⢠Provide examples in the field description\n` +
|
|
82
|
+
` ⢠Use pattern matching if exact values aren't required`;
|
|
83
|
+
}
|
|
84
|
+
else if (field?.pattern) {
|
|
85
|
+
formatted.message = `Field '${error.field}' doesn't match required pattern\n` +
|
|
86
|
+
` Pattern: ${field.pattern}\n` +
|
|
87
|
+
` Got: ${JSON.stringify(error.value)}`;
|
|
88
|
+
formatted.suggestion = `The value doesn't match the regex pattern.\n` +
|
|
89
|
+
` ⢠Provide an example in the field description\n` +
|
|
90
|
+
` ⢠Simplify the pattern if it's too strict`;
|
|
91
|
+
}
|
|
92
|
+
else if (field?.min !== undefined || field?.max !== undefined) {
|
|
93
|
+
formatted.message = error.message;
|
|
94
|
+
formatted.suggestion = `Value is out of the allowed range.\n` +
|
|
95
|
+
` ⢠Check if the constraint is correct\n` +
|
|
96
|
+
` ⢠Mention the range in the field description`;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Generic field invalid error
|
|
100
|
+
formatted.message = error.message;
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
formatted.message = error.message;
|
|
105
|
+
}
|
|
106
|
+
// Add field location in schema
|
|
107
|
+
if (schema?.metadata?.name) {
|
|
108
|
+
formatted.details = [` Field: ${error.field}`, `Schema: ${schema.metadata.name}`];
|
|
109
|
+
}
|
|
110
|
+
return formatFormattedError(formatted);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Helper to format a FormattedError into a string
|
|
114
|
+
*/
|
|
115
|
+
function formatFormattedError(error) {
|
|
116
|
+
const lines = [`ā ${error.title}`, ` ${error.message.replace(/\n/g, '\n ')}`];
|
|
117
|
+
if (error.suggestion) {
|
|
118
|
+
lines.push('', `š” Tip:`);
|
|
119
|
+
lines.push(` ${error.suggestion.replace(/\n/g, '\n ')}`);
|
|
120
|
+
}
|
|
121
|
+
if (error.details && error.details.length > 0) {
|
|
122
|
+
lines.push('', `ā¹ļø Details:`);
|
|
123
|
+
for (const detail of error.details) {
|
|
124
|
+
lines.push(` ⢠${detail}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Format LLM error with context and recovery suggestions
|
|
131
|
+
* Returns a formatted string with title, message, suggestions, and details
|
|
132
|
+
*/
|
|
133
|
+
export function formatLLMError(error, context) {
|
|
134
|
+
const formatted = {
|
|
135
|
+
title: 'LLM Service Error',
|
|
136
|
+
message: error.message,
|
|
137
|
+
details: [],
|
|
138
|
+
};
|
|
139
|
+
switch (error.code) {
|
|
140
|
+
case LLMErrorCodes.NETWORK_ERROR:
|
|
141
|
+
formatted.title = 'Network Connection Error';
|
|
142
|
+
formatted.suggestion = `Cannot reach the LLM service.\n` +
|
|
143
|
+
` ⢠Check if the service is running (${context?.baseURL || 'unknown URL'})\n` +
|
|
144
|
+
` ⢠For Ollama: run 'ollama serve'\n` +
|
|
145
|
+
` ⢠For LM Studio: ensure the server is started\n` +
|
|
146
|
+
` ⢠Check firewall settings`;
|
|
147
|
+
break;
|
|
148
|
+
case LLMErrorCodes.AUTHENTICATION_ERROR:
|
|
149
|
+
formatted.title = 'Authentication Failed';
|
|
150
|
+
formatted.suggestion = `Invalid or missing API key.\n` +
|
|
151
|
+
` ⢠Check your API key is correct\n` +
|
|
152
|
+
` ⢠Use --api-key option or set in config\n` +
|
|
153
|
+
` ⢠For local models (Ollama/LM Studio), API key is not needed`;
|
|
154
|
+
break;
|
|
155
|
+
case LLMErrorCodes.RATE_LIMIT:
|
|
156
|
+
formatted.title = 'Rate Limit Exceeded';
|
|
157
|
+
const retryAfter = error.details?.retryAfter;
|
|
158
|
+
formatted.suggestion = retryAfter
|
|
159
|
+
? `Too many requests. Retry after ${retryAfter} seconds.`
|
|
160
|
+
: `Too many requests.\n` +
|
|
161
|
+
` ⢠Wait a moment and try again\n` +
|
|
162
|
+
` ⢠Reduce request frequency\n` +
|
|
163
|
+
` ⢠Check your API plan limits`;
|
|
164
|
+
break;
|
|
165
|
+
case LLMErrorCodes.TIMEOUT:
|
|
166
|
+
formatted.title = 'Request Timeout';
|
|
167
|
+
formatted.suggestion = `The LLM service didn't respond in time.\n` +
|
|
168
|
+
` ⢠Local models: this is normal for long inputs or slower hardware\n` +
|
|
169
|
+
` ⢠Try a faster model (e.g., llama3.2:3b instead of 70b)\n` +
|
|
170
|
+
` ⢠Reduce input size\n` +
|
|
171
|
+
` ⢠Increase timeout in config`;
|
|
172
|
+
break;
|
|
173
|
+
case LLMErrorCodes.TOKEN_LIMIT_EXCEEDED:
|
|
174
|
+
formatted.title = 'Context Window Exceeded';
|
|
175
|
+
formatted.message = error.message;
|
|
176
|
+
formatted.suggestion = `The input is too large for this model's context window.\n` +
|
|
177
|
+
` ⢠Model: ${context?.model || 'unknown'}\n` +
|
|
178
|
+
` ⢠Input length: ~${context?.inputLength || 'unknown'} characters\n` +
|
|
179
|
+
`\n` +
|
|
180
|
+
` Solutions:\n` +
|
|
181
|
+
` ⢠Reduce input size (extract relevant sections only)\n` +
|
|
182
|
+
` ⢠Use HTML preprocessing to strip noise: --strip-html\n` +
|
|
183
|
+
` ⢠Switch to a model with larger context window\n` +
|
|
184
|
+
` ⢠Split extraction into multiple passes (coming soon)`;
|
|
185
|
+
break;
|
|
186
|
+
case LLMErrorCodes.INVALID_RESPONSE:
|
|
187
|
+
formatted.title = 'Invalid LLM Response';
|
|
188
|
+
if (error.message.includes('JSON')) {
|
|
189
|
+
formatted.suggestion = `The LLM didn't return valid JSON.\n` +
|
|
190
|
+
` ⢠This usually happens with smaller or undertrained models\n` +
|
|
191
|
+
` ⢠Try a more capable model (e.g., llama3.1:8b instead of 3b)\n` +
|
|
192
|
+
` ⢠Simplify your schema\n` +
|
|
193
|
+
` ⢠Reduce input complexity`;
|
|
194
|
+
}
|
|
195
|
+
else if (error.message.includes('confidence')) {
|
|
196
|
+
formatted.suggestion = `The LLM response is missing the confidence score.\n` +
|
|
197
|
+
` ⢠This is a model capability issue\n` +
|
|
198
|
+
` ⢠Try a different model`;
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
case LLMErrorCodes.API_ERROR:
|
|
202
|
+
// Check for common API error patterns
|
|
203
|
+
const msg = error.message.toLowerCase();
|
|
204
|
+
if (msg.includes('context') || msg.includes('token') || msg.includes('length')) {
|
|
205
|
+
formatted.title = 'Context Window Exceeded';
|
|
206
|
+
formatted.suggestion = `The input is too large for this model's context window.\n` +
|
|
207
|
+
` ⢠Model: ${context?.model || 'unknown'}\n` +
|
|
208
|
+
` ⢠Input length: ~${context?.inputLength || 'unknown'} characters\n` +
|
|
209
|
+
`\n` +
|
|
210
|
+
` Solutions:\n` +
|
|
211
|
+
` ⢠Reduce input size (extract relevant sections only)\n` +
|
|
212
|
+
` ⢠Use HTML preprocessing to strip noise: --strip-html\n` +
|
|
213
|
+
` ⢠Switch to a model with larger context window\n` +
|
|
214
|
+
` ⢠Split extraction into multiple passes (coming soon)`;
|
|
215
|
+
}
|
|
216
|
+
else if (msg.includes('model') && msg.includes('not found')) {
|
|
217
|
+
formatted.title = 'Model Not Found';
|
|
218
|
+
formatted.suggestion = `The specified model is not available.\n` +
|
|
219
|
+
` ⢠Model: ${context?.model || 'unknown'}\n` +
|
|
220
|
+
` ⢠For Ollama: run 'ollama list' to see available models\n` +
|
|
221
|
+
` ⢠Pull the model: 'ollama pull ${context?.model}'\n` +
|
|
222
|
+
` ⢠For LM Studio: check loaded models in the UI`;
|
|
223
|
+
}
|
|
224
|
+
else if (error.statusCode === 404) {
|
|
225
|
+
formatted.title = 'Endpoint Not Found';
|
|
226
|
+
formatted.suggestion = `The API endpoint doesn't exist.\n` +
|
|
227
|
+
` ⢠Check the base URL: ${context?.baseURL || 'unknown'}\n` +
|
|
228
|
+
` ⢠Ensure /v1 suffix for Ollama/LM Studio\n` +
|
|
229
|
+
` ⢠Verify the service supports OpenAI-compatible API`;
|
|
230
|
+
}
|
|
231
|
+
else if (error.statusCode && error.statusCode >= 500) {
|
|
232
|
+
formatted.title = 'Service Error';
|
|
233
|
+
formatted.suggestion = `The LLM service encountered an internal error.\n` +
|
|
234
|
+
` ⢠Check service logs for details\n` +
|
|
235
|
+
` ⢠Try again in a moment\n` +
|
|
236
|
+
` ⢠Report to service provider if persistent`;
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
// Add error details
|
|
241
|
+
if (error.statusCode) {
|
|
242
|
+
formatted.details?.push(`Status: ${error.statusCode}`);
|
|
243
|
+
}
|
|
244
|
+
if (context?.model) {
|
|
245
|
+
formatted.details?.push(`Model: ${context.model}`);
|
|
246
|
+
}
|
|
247
|
+
if (context?.baseURL) {
|
|
248
|
+
formatted.details?.push(`URL: ${context.baseURL}`);
|
|
249
|
+
}
|
|
250
|
+
return formatFormattedError(formatted);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Format multiple validation errors into a readable message
|
|
254
|
+
*/
|
|
255
|
+
export function formatValidationErrors(errors, schema) {
|
|
256
|
+
if (errors.length === 0) {
|
|
257
|
+
return 'Validation passed';
|
|
258
|
+
}
|
|
259
|
+
const lines = [`Found ${errors.length} validation error${errors.length > 1 ? 's' : ''}:\n`];
|
|
260
|
+
for (const error of errors) {
|
|
261
|
+
const formatted = formatValidationError(error, schema, error.value);
|
|
262
|
+
lines.push(formatted);
|
|
263
|
+
lines.push('');
|
|
264
|
+
}
|
|
265
|
+
return lines.join('\n');
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Format any error into a user-friendly message
|
|
269
|
+
*/
|
|
270
|
+
export function formatError(error, context) {
|
|
271
|
+
// Handle null/undefined
|
|
272
|
+
if (error === null || error === undefined) {
|
|
273
|
+
return 'Unknown error occurred';
|
|
274
|
+
}
|
|
275
|
+
// Handle string
|
|
276
|
+
if (typeof error === 'string') {
|
|
277
|
+
return error;
|
|
278
|
+
}
|
|
279
|
+
// Handle non-object types
|
|
280
|
+
if (typeof error !== 'object') {
|
|
281
|
+
return `Unknown error: ${String(error)}`;
|
|
282
|
+
}
|
|
283
|
+
// Handle validation error plain objects from pipeline
|
|
284
|
+
if ('field' in error && 'code' in error && 'message' in error) {
|
|
285
|
+
const validationError = error;
|
|
286
|
+
return formatValidationError(validationError, undefined, validationError.value);
|
|
287
|
+
}
|
|
288
|
+
// Handle LLMError
|
|
289
|
+
if (error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code in LLMErrorCodes) {
|
|
290
|
+
return formatLLMError(error, context);
|
|
291
|
+
}
|
|
292
|
+
// Handle SchemaValidationError
|
|
293
|
+
if (error instanceof Error && 'errors' in error && Array.isArray(error.errors)) {
|
|
294
|
+
const schemaError = error;
|
|
295
|
+
return `Schema validation failed:\n\n${formatValidationErrors(schemaError.errors)}`;
|
|
296
|
+
}
|
|
297
|
+
// Handle FormattedError
|
|
298
|
+
if ('title' in error && 'message' in error) {
|
|
299
|
+
return formatFormattedError(error);
|
|
300
|
+
}
|
|
301
|
+
// Handle common Node.js errors
|
|
302
|
+
if (error instanceof Error && 'code' in error) {
|
|
303
|
+
const nodeError = error;
|
|
304
|
+
if (nodeError.code === 'ENOENT') {
|
|
305
|
+
const path = nodeError.path || 'file';
|
|
306
|
+
return `ā File Not Found\n Cannot find: ${path}\n\nš” Tip:\n ⢠Check the file path is correct\n ⢠Verify the file exists\n ⢠Use absolute path or check current directory`;
|
|
307
|
+
}
|
|
308
|
+
else if (nodeError.code === 'EACCES' || nodeError.code === 'EPERM') {
|
|
309
|
+
return `ā Permission Denied\n ${error.message}\n\nš” Tip:\n ⢠Check file permissions\n ⢠Make sure you have read access\n ⢠Try running with appropriate permissions`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Handle generic Error
|
|
313
|
+
if (error instanceof Error) {
|
|
314
|
+
return error.message;
|
|
315
|
+
}
|
|
316
|
+
// Fallback
|
|
317
|
+
return `Unknown error: ${JSON.stringify(error)}`;
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=error-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-formatter.js","sourceRoot":"","sources":["../../src/core/error-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AASjD;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACjC,KAAsB,EACtB,MAAe,EACf,KAAe;IAEf,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,MAAM,SAAS,GAAG,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEtE,MAAM,SAAS,GAAmB;QAC9B,KAAK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,CAAC;QACjC,OAAO,gCAAgC,sBAAsB,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;IACxF,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACzC,OAAO,oBAAoB,CAAC,KAAuB,CAAC,CAAC;IACzD,CAAC;IAED,+BAA+B;IAC/B,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,KAAY,CAAC;QAC/B,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,MAAM,CAAC;YACtC,OAAO,qCAAqC,IAAI,kIAAkI,CAAC;QACvL,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACnE,OAAO,2BAA2B,KAAK,CAAC,OAAO,8HAA8H,CAAC;QAClL,CAAC;IACL,CAAC;IAED,uBAAuB;IACvB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,WAAW;IACX,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
export { ExtractionPipeline, extract } from './pipeline.js';
|
|
5
5
|
export { validateExtractedData } from './validator.js';
|
|
6
6
|
export { PipelineError, PipelineErrorCodes } from './errors.js';
|
|
7
|
-
export
|
|
7
|
+
export { stripHtml, preprocess, preprocessWithDetails, resolveHtmlStripOptions, } from './preprocessor.js';
|
|
8
|
+
export type { PreprocessResult } from './preprocessor.js';
|
|
9
|
+
export type { PipelineConfig, ExtractionRequest, PipelineResult, StepResult, HtmlStripOptions, PreprocessingConfig, } from './types.js';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACH,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,mBAAmB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
export { ExtractionPipeline, extract } from './pipeline.js';
|
|
5
5
|
export { validateExtractedData } from './validator.js';
|
|
6
6
|
export { PipelineError, PipelineErrorCodes } from './errors.js';
|
|
7
|
+
export { stripHtml, preprocess, preprocessWithDetails, resolveHtmlStripOptions, } from './preprocessor.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACH,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/core/pipeline.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/core/pipeline.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAc,MAAM,YAAY,CAAC;AAEhF;;GAEG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,KAAK,CAAU;gBAEX,KAAK,GAAE,OAAe;IAIlC;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC;IAqLlE;;OAEG;IACH,OAAO,CAAC,UAAU;IAsBlB;;OAEG;YACW,eAAe;CAqBhC;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAGjF"}
|
package/dist/core/pipeline.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { LLMClient } from '../llm/client.js';
|
|
5
5
|
import { validateExtractedData } from './validator.js';
|
|
6
6
|
import { PipelineError, PipelineErrorCodes } from './errors.js';
|
|
7
|
+
import { preprocessWithDetails } from './preprocessor.js';
|
|
7
8
|
/**
|
|
8
9
|
* Main extraction pipeline
|
|
9
10
|
*/
|
|
@@ -19,6 +20,18 @@ export class ExtractionPipeline {
|
|
|
19
20
|
const startTime = Date.now();
|
|
20
21
|
const steps = [];
|
|
21
22
|
try {
|
|
23
|
+
// Step 0: Preprocess input (if configured)
|
|
24
|
+
let processedInput = request.input;
|
|
25
|
+
if (request.preprocessing) {
|
|
26
|
+
const preprocessStep = this.recordStep('preprocess', () => {
|
|
27
|
+
return preprocessWithDetails(request.input, request.preprocessing);
|
|
28
|
+
});
|
|
29
|
+
steps.push(preprocessStep);
|
|
30
|
+
if (preprocessStep.success && preprocessStep.data) {
|
|
31
|
+
const result = preprocessStep.data;
|
|
32
|
+
processedInput = result.text;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
22
35
|
// Step 1: Create LLM client
|
|
23
36
|
const clientStep = this.recordStep('create_client', () => {
|
|
24
37
|
return new LLMClient(request.llmConfig);
|
|
@@ -32,7 +45,7 @@ export class ExtractionPipeline {
|
|
|
32
45
|
const extractStep = await this.recordStepAsync('llm_extract', async () => {
|
|
33
46
|
return await client.extract({
|
|
34
47
|
schema: request.schema,
|
|
35
|
-
input:
|
|
48
|
+
input: processedInput,
|
|
36
49
|
});
|
|
37
50
|
});
|
|
38
51
|
steps.push(extractStep);
|
|
@@ -123,6 +136,7 @@ export class ExtractionPipeline {
|
|
|
123
136
|
{
|
|
124
137
|
message: error.message,
|
|
125
138
|
code: error.code,
|
|
139
|
+
details: error.details, // Include original error details
|
|
126
140
|
},
|
|
127
141
|
],
|
|
128
142
|
steps: this.debug ? steps : undefined,
|
|
@@ -171,7 +185,7 @@ export class ExtractionPipeline {
|
|
|
171
185
|
return {
|
|
172
186
|
step: name,
|
|
173
187
|
success: false,
|
|
174
|
-
error
|
|
188
|
+
error, // Preserve full error object for formatting
|
|
175
189
|
duration,
|
|
176
190
|
};
|
|
177
191
|
}
|
|
@@ -196,7 +210,7 @@ export class ExtractionPipeline {
|
|
|
196
210
|
return {
|
|
197
211
|
step: name,
|
|
198
212
|
success: false,
|
|
199
|
-
error
|
|
213
|
+
error, // Preserve full error object for formatting
|
|
200
214
|
duration,
|
|
201
215
|
};
|
|
202
216
|
}
|