@claritylabs/cl-sdk 3.1.18 → 3.1.19
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/application.js +6 -4
- package/dist/application.js.map +1 -1
- package/dist/application.mjs +6 -4
- package/dist/application.mjs.map +1 -1
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +53 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -20,17 +20,19 @@ function isRetryableError(error) {
|
|
|
20
20
|
}
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
|
-
async function withRetry(fn, log) {
|
|
23
|
+
async function withRetry(fn, log, options) {
|
|
24
|
+
const maxRetries = options?.maxRetries ?? MAX_RETRIES;
|
|
25
|
+
const baseDelayMs = options?.baseDelayMs ?? BASE_DELAY_MS;
|
|
24
26
|
for (let attempt = 0; ; attempt++) {
|
|
25
27
|
try {
|
|
26
28
|
return await fn();
|
|
27
29
|
} catch (error) {
|
|
28
|
-
if (!isRetryableError(error) || attempt >=
|
|
30
|
+
if (!isRetryableError(error) || attempt >= maxRetries) {
|
|
29
31
|
throw error;
|
|
30
32
|
}
|
|
31
33
|
const jitter = Math.random() * 1e3;
|
|
32
|
-
const delay =
|
|
33
|
-
await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${
|
|
34
|
+
const delay = baseDelayMs * Math.pow(2, attempt) + jitter;
|
|
35
|
+
await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${maxRetries})...`);
|
|
34
36
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -157,10 +159,8 @@ async function safeGenerateObject(generateObject, params, options) {
|
|
|
157
159
|
const strictParams = { ...params, schema: toStrictSchema(params.schema) };
|
|
158
160
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
159
161
|
try {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
options?.log
|
|
163
|
-
);
|
|
162
|
+
const generate = () => generateObject(strictParams);
|
|
163
|
+
const result = options?.retry === false ? await generate() : await withRetry(generate, options?.log, options?.retry);
|
|
164
164
|
return {
|
|
165
165
|
...result,
|
|
166
166
|
object: params.schema.parse(sanitizeNulls(result.object))
|
|
@@ -11414,7 +11414,9 @@ async function runVisualTableRepair(params) {
|
|
|
11414
11414
|
},
|
|
11415
11415
|
{
|
|
11416
11416
|
fallback: { tables: [], warnings: [] },
|
|
11417
|
-
|
|
11417
|
+
maxRetries: 0,
|
|
11418
|
+
log: params.log,
|
|
11419
|
+
retry: false
|
|
11418
11420
|
}
|
|
11419
11421
|
);
|
|
11420
11422
|
return {
|
|
@@ -11545,32 +11547,6 @@ var NORMALIZED_COMPATIBILITY_FIELDS = /* @__PURE__ */ new Set([
|
|
|
11545
11547
|
"insurer",
|
|
11546
11548
|
"broker"
|
|
11547
11549
|
]);
|
|
11548
|
-
function coverageBelongsToEndorsementCleanupChunk(coverage) {
|
|
11549
|
-
return coverage.coverageOrigin === "endorsement" || Boolean(coverage.endorsementNumber);
|
|
11550
|
-
}
|
|
11551
|
-
function coverageCleanupChunks(profile) {
|
|
11552
|
-
const basePolicy = [];
|
|
11553
|
-
const endorsements = [];
|
|
11554
|
-
profile.coverages.forEach((coverage, coverageIndex) => {
|
|
11555
|
-
if (coverageBelongsToEndorsementCleanupChunk(coverage)) {
|
|
11556
|
-
endorsements.push(coverageIndex);
|
|
11557
|
-
} else {
|
|
11558
|
-
basePolicy.push(coverageIndex);
|
|
11559
|
-
}
|
|
11560
|
-
});
|
|
11561
|
-
return [
|
|
11562
|
-
basePolicy.length ? {
|
|
11563
|
-
group: "base_policy",
|
|
11564
|
-
label: "Coverage cleanup: base policy",
|
|
11565
|
-
coverageIndexes: basePolicy
|
|
11566
|
-
} : void 0,
|
|
11567
|
-
endorsements.length ? {
|
|
11568
|
-
group: "endorsements",
|
|
11569
|
-
label: "Coverage cleanup: endorsements",
|
|
11570
|
-
coverageIndexes: endorsements
|
|
11571
|
-
} : void 0
|
|
11572
|
-
].filter((chunk) => Boolean(chunk));
|
|
11573
|
-
}
|
|
11574
11550
|
function valueOf(profile, key) {
|
|
11575
11551
|
const value = profile[key];
|
|
11576
11552
|
if (!value || typeof value !== "object" || Array.isArray(value) || !("value" in value)) return void 0;
|
|
@@ -11749,7 +11725,9 @@ async function runSourceTreeExtraction(params) {
|
|
|
11749
11725
|
},
|
|
11750
11726
|
{
|
|
11751
11727
|
fallback: { labels: [], groups: [] },
|
|
11752
|
-
|
|
11728
|
+
maxRetries: 0,
|
|
11729
|
+
log: params.log,
|
|
11730
|
+
retry: false
|
|
11753
11731
|
}
|
|
11754
11732
|
);
|
|
11755
11733
|
return {
|
|
@@ -11794,7 +11772,9 @@ async function runSourceTreeExtraction(params) {
|
|
|
11794
11772
|
},
|
|
11795
11773
|
{
|
|
11796
11774
|
fallback: { labels: [], groups: [] },
|
|
11797
|
-
|
|
11775
|
+
maxRetries: 0,
|
|
11776
|
+
log: params.log,
|
|
11777
|
+
retry: false
|
|
11798
11778
|
}
|
|
11799
11779
|
);
|
|
11800
11780
|
localTrack(response.usage, {
|
|
@@ -11836,7 +11816,9 @@ async function runSourceTreeExtraction(params) {
|
|
|
11836
11816
|
},
|
|
11837
11817
|
{
|
|
11838
11818
|
fallback: emptyProfile,
|
|
11839
|
-
|
|
11819
|
+
maxRetries: 0,
|
|
11820
|
+
log: params.log,
|
|
11821
|
+
retry: false
|
|
11840
11822
|
}
|
|
11841
11823
|
);
|
|
11842
11824
|
localTrack(response.usage, {
|
|
@@ -11858,64 +11840,40 @@ async function runSourceTreeExtraction(params) {
|
|
|
11858
11840
|
try {
|
|
11859
11841
|
const validNodeIds = new Set(sourceTree.map((node) => node.id));
|
|
11860
11842
|
const validSpanIds = new Set(sourceSpans.map((span) => span.id));
|
|
11861
|
-
const
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
params.generateObject,
|
|
11870
|
-
{
|
|
11871
|
-
prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile, {
|
|
11872
|
-
coverageIndexes: chunk.coverageIndexes,
|
|
11873
|
-
label: chunk.label
|
|
11874
|
-
}),
|
|
11875
|
-
schema: OperationalProfileCleanupSchema,
|
|
11876
|
-
maxTokens: budget.maxTokens,
|
|
11877
|
-
taskKind: "extraction_coverage_cleanup",
|
|
11878
|
-
budgetDiagnostics: budget,
|
|
11879
|
-
providerOptions: params.providerOptions,
|
|
11880
|
-
trace: {
|
|
11881
|
-
phase: "coverage_cleanup",
|
|
11882
|
-
label: chunk.label,
|
|
11883
|
-
batchIndex: batchIndex + 1,
|
|
11884
|
-
batchCount: chunks.length,
|
|
11885
|
-
coverageGroup: chunk.group,
|
|
11886
|
-
itemCount: chunk.coverageIndexes.length,
|
|
11887
|
-
sourceBacked: true
|
|
11888
|
-
}
|
|
11889
|
-
},
|
|
11890
|
-
{
|
|
11891
|
-
fallback: { coverageDecisions: [], warnings: [] },
|
|
11892
|
-
maxRetries: 0,
|
|
11893
|
-
log: params.log
|
|
11894
|
-
}
|
|
11895
|
-
);
|
|
11896
|
-
return {
|
|
11897
|
-
batchIndex,
|
|
11898
|
-
chunk,
|
|
11899
|
-
budget,
|
|
11900
|
-
durationMs: Date.now() - startedAt,
|
|
11901
|
-
usage: response.usage,
|
|
11902
|
-
cleanup: response.object
|
|
11903
|
-
};
|
|
11904
|
-
}));
|
|
11905
|
-
const cleanup = { coverageDecisions: [], warnings: [] };
|
|
11906
|
-
for (const result of cleanupResults.sort((left, right) => left.batchIndex - right.batchIndex)) {
|
|
11907
|
-
localTrack(result.usage, {
|
|
11843
|
+
const budget = params.resolveBudget("extraction_coverage_cleanup", 4096);
|
|
11844
|
+
const startedAt = Date.now();
|
|
11845
|
+
const response = await safeGenerateObject(
|
|
11846
|
+
params.generateObject,
|
|
11847
|
+
{
|
|
11848
|
+
prompt: buildOperationalProfileCleanupPrompt(sourceTree, operationalProfile),
|
|
11849
|
+
schema: OperationalProfileCleanupSchema,
|
|
11850
|
+
maxTokens: budget.maxTokens,
|
|
11908
11851
|
taskKind: "extraction_coverage_cleanup",
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
11852
|
+
budgetDiagnostics: budget,
|
|
11853
|
+
providerOptions: params.providerOptions,
|
|
11854
|
+
trace: {
|
|
11855
|
+
phase: "coverage_cleanup",
|
|
11856
|
+
label: "Coverage cleanup",
|
|
11857
|
+
itemCount: operationalProfile.coverages.length,
|
|
11858
|
+
sourceBacked: true
|
|
11859
|
+
}
|
|
11860
|
+
},
|
|
11861
|
+
{
|
|
11862
|
+
fallback: { coverageDecisions: [], warnings: [] },
|
|
11863
|
+
maxRetries: 0,
|
|
11864
|
+
log: params.log,
|
|
11865
|
+
retry: false
|
|
11866
|
+
}
|
|
11867
|
+
);
|
|
11868
|
+
localTrack(response.usage, {
|
|
11869
|
+
taskKind: "extraction_coverage_cleanup",
|
|
11870
|
+
label: "coverage_cleanup",
|
|
11871
|
+
maxTokens: budget.maxTokens,
|
|
11872
|
+
durationMs: Date.now() - startedAt
|
|
11873
|
+
});
|
|
11916
11874
|
operationalProfile = applyOperationalProfileCleanup(
|
|
11917
11875
|
operationalProfile,
|
|
11918
|
-
|
|
11876
|
+
response.object,
|
|
11919
11877
|
validNodeIds,
|
|
11920
11878
|
validSpanIds
|
|
11921
11879
|
);
|
|
@@ -12313,7 +12271,9 @@ ${sourceText}`;
|
|
|
12313
12271
|
},
|
|
12314
12272
|
{
|
|
12315
12273
|
fallback: { forms: [] },
|
|
12274
|
+
maxRetries: 0,
|
|
12316
12275
|
log,
|
|
12276
|
+
retry: false,
|
|
12317
12277
|
onError: (err, attempt) => log?.(`Form inventory attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
12318
12278
|
}
|
|
12319
12279
|
);
|