@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 CHANGED
@@ -241,16 +241,22 @@ module.exports = __toCommonJS(index_exports);
241
241
  // src/core/retry.ts
242
242
  var MAX_RETRIES = 5;
243
243
  var BASE_DELAY_MS = 2e3;
244
- function isRateLimitError(error) {
244
+ function isRetryableError(error) {
245
245
  if (error instanceof Error) {
246
246
  const msg = error.message.toLowerCase();
247
247
  if (msg.includes("rate limit") || msg.includes("rate_limit") || msg.includes("too many requests")) {
248
248
  return true;
249
249
  }
250
+ if (msg.includes("grammar compilation timed out")) return true;
251
+ if (msg.includes("no output generated")) return true;
252
+ if (msg.includes("overloaded")) return true;
253
+ if (msg.includes("internal server error")) return true;
254
+ if (msg.includes("service unavailable")) return true;
255
+ if (msg.includes("gateway timeout")) return true;
250
256
  }
251
257
  if (typeof error === "object" && error !== null) {
252
258
  const status = error.status ?? error.statusCode;
253
- if (status === 429) return true;
259
+ if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
254
260
  }
255
261
  return false;
256
262
  }
@@ -259,12 +265,12 @@ async function withRetry(fn, log) {
259
265
  try {
260
266
  return await fn();
261
267
  } catch (error) {
262
- if (!isRateLimitError(error) || attempt >= MAX_RETRIES) {
268
+ if (!isRetryableError(error) || attempt >= MAX_RETRIES) {
263
269
  throw error;
264
270
  }
265
271
  const jitter = Math.random() * 1e3;
266
272
  const delay = BASE_DELAY_MS * Math.pow(2, attempt) + jitter;
267
- await log?.(`Rate limited, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
273
+ await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
268
274
  await new Promise((resolve) => setTimeout(resolve, delay));
269
275
  }
270
276
  }
@@ -3173,9 +3179,14 @@ Return JSON only.`;
3173
3179
 
3174
3180
  // src/prompts/extractors/declarations.ts
3175
3181
  var import_zod27 = require("zod");
3176
- var DeclarationsExtractSchema = import_zod27.z.record(import_zod27.z.string(), import_zod27.z.unknown()).describe(
3177
- "Flexible declarations data \u2014 structure varies by line of business. Keys are descriptive field names, values are the extracted data."
3178
- );
3182
+ var DeclarationsFieldSchema = import_zod27.z.object({
3183
+ field: import_zod27.z.string().describe("Descriptive field name (e.g. 'policyNumber', 'effectiveDate', 'coverageALimit')"),
3184
+ value: import_zod27.z.string().describe("Extracted value exactly as it appears in the document"),
3185
+ section: import_zod27.z.string().optional().describe("Section or grouping this field belongs to (e.g. 'Coverage Limits', 'Vehicle Schedule')")
3186
+ });
3187
+ var DeclarationsExtractSchema = import_zod27.z.object({
3188
+ fields: import_zod27.z.array(DeclarationsFieldSchema).describe("All declarations page fields extracted as key-value pairs. Structure varies by line of business.")
3189
+ });
3179
3190
  function buildDeclarationsPrompt() {
3180
3191
  return `You are an expert insurance document analyst. Extract all declarations page data from this document into a flexible key-value structure.
3181
3192
 
@@ -3199,9 +3210,18 @@ For PERSONAL LINES declarations:
3199
3210
  - Flood (NFIP): flood zone, community number, building/contents coverage
3200
3211
  - Personal Articles: scheduled items list with appraised values
3201
3212
 
3202
- Use descriptive field names as keys. Preserve original values exactly as they appear.
3213
+ Return each field as an object with "field" (descriptive name), "value" (exact text from document), and optional "section" (grouping).
3203
3214
 
3204
- Return JSON only.`;
3215
+ Example output:
3216
+ {
3217
+ "fields": [
3218
+ { "field": "policyNumber", "value": "GL-2025-78432", "section": "Policy Info" },
3219
+ { "field": "effectiveDate", "value": "04/10/2025", "section": "Policy Info" },
3220
+ { "field": "eachOccurrenceLimit", "value": "$1,000,000", "section": "Coverage Limits" }
3221
+ ]
3222
+ }
3223
+
3224
+ Preserve original values exactly as they appear. Return JSON only.`;
3205
3225
  }
3206
3226
 
3207
3227
  // src/prompts/extractors/loss-history.ts