@claritylabs/cl-sdk 0.7.0 → 0.7.2
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/index.js +29 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
// src/core/retry.ts
|
|
2
2
|
var MAX_RETRIES = 5;
|
|
3
3
|
var BASE_DELAY_MS = 2e3;
|
|
4
|
-
function
|
|
4
|
+
function isRetryableError(error) {
|
|
5
5
|
if (error instanceof Error) {
|
|
6
6
|
const msg = error.message.toLowerCase();
|
|
7
7
|
if (msg.includes("rate limit") || msg.includes("rate_limit") || msg.includes("too many requests")) {
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
+
if (msg.includes("grammar compilation timed out")) return true;
|
|
11
|
+
if (msg.includes("no output generated")) return true;
|
|
12
|
+
if (msg.includes("overloaded")) return true;
|
|
13
|
+
if (msg.includes("internal server error")) return true;
|
|
14
|
+
if (msg.includes("service unavailable")) return true;
|
|
15
|
+
if (msg.includes("gateway timeout")) return true;
|
|
10
16
|
}
|
|
11
17
|
if (typeof error === "object" && error !== null) {
|
|
12
18
|
const status = error.status ?? error.statusCode;
|
|
13
|
-
if (status === 429) return true;
|
|
19
|
+
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
|
|
14
20
|
}
|
|
15
21
|
return false;
|
|
16
22
|
}
|
|
@@ -19,12 +25,12 @@ async function withRetry(fn, log) {
|
|
|
19
25
|
try {
|
|
20
26
|
return await fn();
|
|
21
27
|
} catch (error) {
|
|
22
|
-
if (!
|
|
28
|
+
if (!isRetryableError(error) || attempt >= MAX_RETRIES) {
|
|
23
29
|
throw error;
|
|
24
30
|
}
|
|
25
31
|
const jitter = Math.random() * 1e3;
|
|
26
32
|
const delay = BASE_DELAY_MS * Math.pow(2, attempt) + jitter;
|
|
27
|
-
await log?.(`
|
|
33
|
+
await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
|
|
28
34
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
29
35
|
}
|
|
30
36
|
}
|
|
@@ -2941,9 +2947,14 @@ Return JSON only.`;
|
|
|
2941
2947
|
|
|
2942
2948
|
// src/prompts/extractors/declarations.ts
|
|
2943
2949
|
import { z as z27 } from "zod";
|
|
2944
|
-
var
|
|
2945
|
-
"
|
|
2946
|
-
)
|
|
2950
|
+
var DeclarationsFieldSchema = z27.object({
|
|
2951
|
+
field: z27.string().describe("Descriptive field name (e.g. 'policyNumber', 'effectiveDate', 'coverageALimit')"),
|
|
2952
|
+
value: z27.string().describe("Extracted value exactly as it appears in the document"),
|
|
2953
|
+
section: z27.string().optional().describe("Section or grouping this field belongs to (e.g. 'Coverage Limits', 'Vehicle Schedule')")
|
|
2954
|
+
});
|
|
2955
|
+
var DeclarationsExtractSchema = z27.object({
|
|
2956
|
+
fields: z27.array(DeclarationsFieldSchema).describe("All declarations page fields extracted as key-value pairs. Structure varies by line of business.")
|
|
2957
|
+
});
|
|
2947
2958
|
function buildDeclarationsPrompt() {
|
|
2948
2959
|
return `You are an expert insurance document analyst. Extract all declarations page data from this document into a flexible key-value structure.
|
|
2949
2960
|
|
|
@@ -2967,9 +2978,18 @@ For PERSONAL LINES declarations:
|
|
|
2967
2978
|
- Flood (NFIP): flood zone, community number, building/contents coverage
|
|
2968
2979
|
- Personal Articles: scheduled items list with appraised values
|
|
2969
2980
|
|
|
2970
|
-
|
|
2981
|
+
Return each field as an object with "field" (descriptive name), "value" (exact text from document), and optional "section" (grouping).
|
|
2971
2982
|
|
|
2972
|
-
|
|
2983
|
+
Example output:
|
|
2984
|
+
{
|
|
2985
|
+
"fields": [
|
|
2986
|
+
{ "field": "policyNumber", "value": "GL-2025-78432", "section": "Policy Info" },
|
|
2987
|
+
{ "field": "effectiveDate", "value": "04/10/2025", "section": "Policy Info" },
|
|
2988
|
+
{ "field": "eachOccurrenceLimit", "value": "$1,000,000", "section": "Coverage Limits" }
|
|
2989
|
+
]
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
Preserve original values exactly as they appear. Return JSON only.`;
|
|
2973
2993
|
}
|
|
2974
2994
|
|
|
2975
2995
|
// src/prompts/extractors/loss-history.ts
|