@far-world-labs/verblets 0.7.1 → 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.browser.js +2 -2
- package/dist/index.js +2 -2
- package/dist/{shared-CNTi6iN9.js → shared-BE8DOT4r.js} +931 -921
- package/package.json +1 -1
|
@@ -878,7 +878,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
878
878
|
...y,
|
|
879
879
|
content: ko(y.content)
|
|
880
880
|
}))), o !== void 0 && (d.max_completion_tokens = o), $l(d.model) || (i !== void 0 && (d.temperature = i), a !== void 0 && (d.top_p = a), c !== void 0 && (d.frequency_penalty = c), l !== void 0 && (d.presence_penalty = l));
|
|
881
|
-
const
|
|
881
|
+
const h = {
|
|
882
882
|
method: "POST",
|
|
883
883
|
headers: {
|
|
884
884
|
Authorization: `Bearer ${t}`,
|
|
@@ -886,7 +886,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
886
886
|
},
|
|
887
887
|
body: JSON.stringify(d)
|
|
888
888
|
};
|
|
889
|
-
return { url: s, fetchOptions:
|
|
889
|
+
return { url: s, fetchOptions: h };
|
|
890
890
|
}, Tl = (e) => e, El = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
891
891
|
__proto__: null,
|
|
892
892
|
buildRequest: Pl,
|
|
@@ -922,34 +922,34 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
922
922
|
// eslint-disable-line no-unused-vars
|
|
923
923
|
top_p: d,
|
|
924
924
|
// eslint-disable-line no-unused-vars
|
|
925
|
-
frequency_penalty:
|
|
925
|
+
frequency_penalty: h,
|
|
926
926
|
// eslint-disable-line no-unused-vars
|
|
927
927
|
presence_penalty: y,
|
|
928
928
|
// eslint-disable-line no-unused-vars
|
|
929
|
-
...
|
|
930
|
-
} = r, { instructions: f, messages: g } = Il(o),
|
|
929
|
+
...b
|
|
930
|
+
} = r, { instructions: f, messages: g } = Il(o), m = {
|
|
931
931
|
model: i,
|
|
932
932
|
input: g,
|
|
933
|
-
...
|
|
933
|
+
...b
|
|
934
934
|
};
|
|
935
|
-
f && (
|
|
935
|
+
f && (m.instructions = f), a && (m.max_output_tokens = a), l && (m.tools = l.map((v) => v.type === "function" ? {
|
|
936
936
|
type: "function",
|
|
937
|
-
name:
|
|
938
|
-
description:
|
|
939
|
-
parameters:
|
|
940
|
-
strict:
|
|
941
|
-
} :
|
|
942
|
-
const
|
|
943
|
-
Object.assign(
|
|
944
|
-
const
|
|
937
|
+
name: v.function.name,
|
|
938
|
+
description: v.function.description,
|
|
939
|
+
parameters: v.function.parameters,
|
|
940
|
+
strict: v.function.strict
|
|
941
|
+
} : v), u && (m.tool_choice = u));
|
|
942
|
+
const w = kl(c);
|
|
943
|
+
Object.assign(m, w);
|
|
944
|
+
const S = {
|
|
945
945
|
method: "POST",
|
|
946
946
|
headers: {
|
|
947
947
|
Authorization: `Bearer ${t}`,
|
|
948
948
|
"Content-Type": "application/json"
|
|
949
949
|
},
|
|
950
|
-
body: JSON.stringify(
|
|
950
|
+
body: JSON.stringify(m)
|
|
951
951
|
};
|
|
952
|
-
return { url: s, fetchOptions:
|
|
952
|
+
return { url: s, fetchOptions: S };
|
|
953
953
|
}, Ol = (e) => {
|
|
954
954
|
const t = e.output || [], n = t.find((i) => i.type === "message"), r = t.filter((i) => i.type === "function_call");
|
|
955
955
|
let s = "";
|
|
@@ -1082,29 +1082,29 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1082
1082
|
// Strip unsupported params
|
|
1083
1083
|
top_p: d,
|
|
1084
1084
|
// eslint-disable-line no-unused-vars
|
|
1085
|
-
frequency_penalty:
|
|
1085
|
+
frequency_penalty: h,
|
|
1086
1086
|
// eslint-disable-line no-unused-vars
|
|
1087
1087
|
presence_penalty: y,
|
|
1088
1088
|
// eslint-disable-line no-unused-vars
|
|
1089
|
-
...
|
|
1090
|
-
} = r, { systemText: f, messages: g } = Nl(o),
|
|
1089
|
+
...b
|
|
1090
|
+
} = r, { systemText: f, messages: g } = Nl(o), m = g.map((x) => ({
|
|
1091
1091
|
...x,
|
|
1092
1092
|
content: Ao(x.content)
|
|
1093
|
-
})),
|
|
1093
|
+
})), w = {
|
|
1094
1094
|
model: i,
|
|
1095
|
-
messages:
|
|
1095
|
+
messages: m,
|
|
1096
1096
|
max_tokens: a || 4096,
|
|
1097
|
-
...
|
|
1097
|
+
...b
|
|
1098
1098
|
};
|
|
1099
|
-
f && (
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
-
|
|
1099
|
+
f && (w.system = f), c !== void 0 && (w.temperature = c);
|
|
1100
|
+
const S = Dl(u);
|
|
1101
|
+
if (S) {
|
|
1102
|
+
w.tools = S;
|
|
1103
1103
|
const x = jl(p);
|
|
1104
|
-
x && (
|
|
1104
|
+
x && (w.tool_choice = x);
|
|
1105
1105
|
}
|
|
1106
|
-
const
|
|
1107
|
-
Object.assign(
|
|
1106
|
+
const v = Bl(l);
|
|
1107
|
+
Object.assign(w, v);
|
|
1108
1108
|
const P = {
|
|
1109
1109
|
method: "POST",
|
|
1110
1110
|
headers: {
|
|
@@ -1112,7 +1112,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1112
1112
|
"anthropic-version": Cl,
|
|
1113
1113
|
"Content-Type": "application/json"
|
|
1114
1114
|
},
|
|
1115
|
-
body: JSON.stringify(
|
|
1115
|
+
body: JSON.stringify(w)
|
|
1116
1116
|
};
|
|
1117
1117
|
return { url: s, fetchOptions: P };
|
|
1118
1118
|
}, Be = (e) => {
|
|
@@ -1732,9 +1732,9 @@ class Sn {
|
|
|
1732
1732
|
const { tools: n, toolChoice: r, modelName: s, prompt: o, systemPrompt: i, responseFormat: a } = t, c = this.getModel(s), l = i ?? c.systemPrompt;
|
|
1733
1733
|
let u = { prompt: o };
|
|
1734
1734
|
if (/chat|responses|messages/.test(c.endpoint)) {
|
|
1735
|
-
const
|
|
1735
|
+
const h = { role: "user", content: o };
|
|
1736
1736
|
u = {
|
|
1737
|
-
messages: [...l ? [{ role: "system", content: l }] : [],
|
|
1737
|
+
messages: [...l ? [{ role: "system", content: l }] : [], h],
|
|
1738
1738
|
tools: n,
|
|
1739
1739
|
tool_choice: n && !r ? "auto" : r
|
|
1740
1740
|
};
|
|
@@ -1745,10 +1745,10 @@ class Sn {
|
|
|
1745
1745
|
};
|
|
1746
1746
|
if (a)
|
|
1747
1747
|
if (a.json_schema?.schema?.$schema) {
|
|
1748
|
-
const
|
|
1749
|
-
delete
|
|
1748
|
+
const h = { ...a.json_schema.schema };
|
|
1749
|
+
delete h.$schema, d.responseFormat = {
|
|
1750
1750
|
...a,
|
|
1751
|
-
json_schema: { ...a.json_schema, schema:
|
|
1751
|
+
json_schema: { ...a.json_schema, schema: h }
|
|
1752
1752
|
};
|
|
1753
1753
|
} else
|
|
1754
1754
|
d.responseFormat = a;
|
|
@@ -1884,7 +1884,7 @@ function op(e, { forceHTML: t = !1, name: n, tag: r = "data", title: s, fit: o =
|
|
|
1884
1884
|
const i = typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
1885
1885
|
return /\n/.test(i) || t || n ? $(i, { name: n, tag: r, title: s, fit: o }) : Qo(i, { title: s });
|
|
1886
1886
|
}
|
|
1887
|
-
const ip = "0.7.
|
|
1887
|
+
const ip = "0.7.2", ap = {
|
|
1888
1888
|
version: ip
|
|
1889
1889
|
}, In = ap.version, fe = Object.freeze({
|
|
1890
1890
|
/** Decisions, phases, meaningful outcomes. Audit-log-shaped. */
|
|
@@ -2012,7 +2012,7 @@ function dp(e, t) {
|
|
|
2012
2012
|
function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i, eventFilter: a } = {}) {
|
|
2013
2013
|
const c = dp(t, a), l = r, u = {};
|
|
2014
2014
|
s && (u.traceId = s), o && (u.spanId = o), i && (u.parentSpanId = i);
|
|
2015
|
-
const d = { step: e, operation: n, ...u, ...{ libraryName: "verblets", libraryVersion: In } },
|
|
2015
|
+
const d = { step: e, operation: n, ...u, ...{ libraryName: "verblets", libraryVersion: In } }, h = {
|
|
2016
2016
|
start() {
|
|
2017
2017
|
xe(c, { kind: fe.telemetry, ...d, event: De.start });
|
|
2018
2018
|
},
|
|
@@ -2044,7 +2044,7 @@ function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i,
|
|
|
2044
2044
|
xe(c, { kind: fe.event, ...d, event: k.uncertainty, ...y });
|
|
2045
2045
|
},
|
|
2046
2046
|
complete(y = {}) {
|
|
2047
|
-
const { durationMs:
|
|
2047
|
+
const { durationMs: b, ...f } = y, g = b ?? (l ? Date.now() - l.getTime() : void 0);
|
|
2048
2048
|
xe(c, {
|
|
2049
2049
|
kind: fe.telemetry,
|
|
2050
2050
|
...d,
|
|
@@ -2054,32 +2054,32 @@ function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i,
|
|
|
2054
2054
|
...f
|
|
2055
2055
|
});
|
|
2056
2056
|
},
|
|
2057
|
-
error(y,
|
|
2058
|
-
const { durationMs: f, ...g } =
|
|
2057
|
+
error(y, b = {}) {
|
|
2058
|
+
const { durationMs: f, ...g } = b, m = f ?? (l ? Date.now() - l.getTime() : void 0);
|
|
2059
2059
|
xe(c, {
|
|
2060
2060
|
kind: fe.telemetry,
|
|
2061
2061
|
...d,
|
|
2062
2062
|
event: De.error,
|
|
2063
2063
|
statusCode: Zt.error,
|
|
2064
|
-
...
|
|
2064
|
+
...m !== void 0 && { durationMs: m },
|
|
2065
2065
|
error: { message: y.message, type: y.constructor?.name },
|
|
2066
2066
|
...g
|
|
2067
2067
|
});
|
|
2068
2068
|
},
|
|
2069
2069
|
batch(y) {
|
|
2070
|
-
let
|
|
2070
|
+
let b = 0;
|
|
2071
2071
|
function f(g) {
|
|
2072
|
-
return
|
|
2072
|
+
return b += g, f.count = b, h.progress({
|
|
2073
2073
|
event: W.batchComplete,
|
|
2074
2074
|
totalItems: y,
|
|
2075
|
-
processedItems:
|
|
2075
|
+
processedItems: b,
|
|
2076
2076
|
batchSize: g
|
|
2077
|
-
}),
|
|
2077
|
+
}), b;
|
|
2078
2078
|
}
|
|
2079
2079
|
return f.count = 0, f;
|
|
2080
2080
|
}
|
|
2081
2081
|
};
|
|
2082
|
-
return
|
|
2082
|
+
return h;
|
|
2083
2083
|
}
|
|
2084
2084
|
function L(e, t) {
|
|
2085
2085
|
if (!(!e || typeof e != "function"))
|
|
@@ -2221,34 +2221,34 @@ const xp = (e) => {
|
|
|
2221
2221
|
onAfterRequest: u = Sp,
|
|
2222
2222
|
onBeforeRequest: p = vp,
|
|
2223
2223
|
shapeOutput: d = wp,
|
|
2224
|
-
skipResponseParse:
|
|
2224
|
+
skipResponseParse: h,
|
|
2225
2225
|
unwrapValues: y,
|
|
2226
|
-
unwrapCollections:
|
|
2227
|
-
} = t, f = en ? { ...en, ...t.policy } : t.policy, g = f ? { ...t, policy: f } : t,
|
|
2226
|
+
unwrapCollections: b
|
|
2227
|
+
} = t, f = en ? { ...en, ...t.policy } : t.policy, g = f ? { ...t, policy: f } : t, m = await re("forceQuery", g, !1), w = { ...Oo(c) };
|
|
2228
2228
|
for (const B of $p) {
|
|
2229
2229
|
const X = await re(B, g, void 0);
|
|
2230
|
-
X !== void 0 && (
|
|
2230
|
+
X !== void 0 && (w[B] = X);
|
|
2231
2231
|
}
|
|
2232
2232
|
for (const B of Qe) {
|
|
2233
2233
|
const X = await re(B, g, void 0);
|
|
2234
|
-
X !== void 0 && (
|
|
2234
|
+
X !== void 0 && (w[B] = X);
|
|
2235
2235
|
}
|
|
2236
|
-
const
|
|
2236
|
+
const S = Date.now(), v = {};
|
|
2237
2237
|
let P = !1;
|
|
2238
|
-
|
|
2238
|
+
w.negotiate && (Object.assign(v, w.negotiate), P = !0);
|
|
2239
2239
|
for (const B of Qe)
|
|
2240
|
-
B in
|
|
2241
|
-
const x =
|
|
2240
|
+
B in w && (v[B] = w[B], P = !0);
|
|
2241
|
+
const x = w.modelName;
|
|
2242
2242
|
let E, O;
|
|
2243
|
-
P ? (E = n.negotiateModel(x,
|
|
2244
|
-
const R = I("llm", t.onProgress, t), j = P ? Ge.negotiated :
|
|
2243
|
+
P ? (E = n.negotiateModel(x, v), O = E?.name) : (O = w.modelName, E = n.getModel(O));
|
|
2244
|
+
const R = I("llm", t.onProgress, t), j = P ? Ge.negotiated : w.modelName ? Ge.config : Ge.default;
|
|
2245
2245
|
R.metrics({
|
|
2246
2246
|
event: ye.llmModel,
|
|
2247
2247
|
model: O,
|
|
2248
2248
|
provider: E?.provider || "openai",
|
|
2249
2249
|
source: j,
|
|
2250
|
-
negotiation: P ?
|
|
2251
|
-
preferred:
|
|
2250
|
+
negotiation: P ? v : void 0,
|
|
2251
|
+
preferred: w.modelName
|
|
2252
2252
|
});
|
|
2253
2253
|
const F = Array.isArray(e) ? e.reduce((B, X) => B + (X.type === "text" ? X.text.length : 0), 0) : e.length;
|
|
2254
2254
|
l?.info && l.info({
|
|
@@ -2258,7 +2258,7 @@ const xp = (e) => {
|
|
|
2258
2258
|
});
|
|
2259
2259
|
const V = n.getDefaultModel(), Y = E?.apiUrl || V?.apiUrl, H = E?.apiKey || V?.apiKey, ee = n.getRequestConfig({
|
|
2260
2260
|
prompt: e,
|
|
2261
|
-
...
|
|
2261
|
+
...w,
|
|
2262
2262
|
modelName: O
|
|
2263
2263
|
}), pe = E.structuredOutput === !1 && !!ee.responseFormat;
|
|
2264
2264
|
let G = ee;
|
|
@@ -2285,8 +2285,8 @@ ${X}`, ve = ee.messages?.map(
|
|
|
2285
2285
|
});
|
|
2286
2286
|
try {
|
|
2287
2287
|
let B = Z;
|
|
2288
|
-
if (!Z ||
|
|
2289
|
-
const le =
|
|
2288
|
+
if (!Z || m) {
|
|
2289
|
+
const le = w.requestTimeout || n.getModel(O).requestTimeout, Ne = new Lo(le), Ue = E.provider || "openai", nr = Yl(Ue), { url: Dc, fetchOptions: rr } = nr.buildRequest(
|
|
2290
2290
|
Y,
|
|
2291
2291
|
H,
|
|
2292
2292
|
E.endpoint,
|
|
@@ -2331,9 +2331,9 @@ ${X}`, ve = ee.messages?.map(
|
|
|
2331
2331
|
}
|
|
2332
2332
|
}
|
|
2333
2333
|
const X = d(B, ee, {
|
|
2334
|
-
skipResponseParse:
|
|
2334
|
+
skipResponseParse: h,
|
|
2335
2335
|
unwrapValues: y,
|
|
2336
|
-
unwrapCollections:
|
|
2336
|
+
unwrapCollections: b
|
|
2337
2337
|
});
|
|
2338
2338
|
u({
|
|
2339
2339
|
debugResult: i,
|
|
@@ -2344,7 +2344,7 @@ ${X}`, ve = ee.messages?.map(
|
|
|
2344
2344
|
resultShaped: X
|
|
2345
2345
|
}), l?.info && l.info({
|
|
2346
2346
|
event: "llm:end",
|
|
2347
|
-
duration: Date.now() -
|
|
2347
|
+
duration: Date.now() - S,
|
|
2348
2348
|
cached: !!Z,
|
|
2349
2349
|
model: O
|
|
2350
2350
|
});
|
|
@@ -2371,7 +2371,7 @@ ${X}`, ve = ee.messages?.map(
|
|
|
2371
2371
|
...ce
|
|
2372
2372
|
}), R.measure({
|
|
2373
2373
|
metric: ge.llmDuration,
|
|
2374
|
-
value: Date.now() -
|
|
2374
|
+
value: Date.now() - S,
|
|
2375
2375
|
...ce
|
|
2376
2376
|
}), X;
|
|
2377
2377
|
} catch (B) {
|
|
@@ -2390,7 +2390,7 @@ ${X}`, ve = ee.messages?.map(
|
|
|
2390
2390
|
}
|
|
2391
2391
|
}), R.measure({
|
|
2392
2392
|
metric: ge.llmDuration,
|
|
2393
|
-
value: Date.now() -
|
|
2393
|
+
value: Date.now() - S,
|
|
2394
2394
|
...X
|
|
2395
2395
|
}), B;
|
|
2396
2396
|
}
|
|
@@ -2547,8 +2547,8 @@ ${Xe}`;
|
|
|
2547
2547
|
maxWords: a
|
|
2548
2548
|
} = {}) => {
|
|
2549
2549
|
const c = `Tone: ${t.join(", ")}`, l = `Vocabulary: ${n.join(", ")}`, u = `Sentence structure: ${r.join(", ")}`, p = `Point of view: ${s.join(", ")}`, d = `Use between ${i} and ${a ?? "any number"} of words`;
|
|
2550
|
-
let
|
|
2551
|
-
return o > 0.5 && (
|
|
2550
|
+
let h = "";
|
|
2551
|
+
return o > 0.5 && (h = "Completely reshape the ideas here, don't stick with the original structure. Don't change the meaning of the content though."), `Rewrite the following content:
|
|
2552
2552
|
\`\`\`
|
|
2553
2553
|
${e}
|
|
2554
2554
|
\`\`\`
|
|
@@ -2559,7 +2559,7 @@ ${l}
|
|
|
2559
2559
|
${u}
|
|
2560
2560
|
${p}
|
|
2561
2561
|
${d}
|
|
2562
|
-
${
|
|
2562
|
+
${h}
|
|
2563
2563
|
`;
|
|
2564
2564
|
}, oi = (e = 10) => `Keep the output within ${e} tokens.`, ii = (e, t = "") => `Summarize the content below according to the instructions provided.
|
|
2565
2565
|
|
|
@@ -2800,7 +2800,7 @@ async function M(e, t = {}) {
|
|
|
2800
2800
|
overloadBackoffCeiling: t.overloadBackoffCeiling
|
|
2801
2801
|
}
|
|
2802
2802
|
};
|
|
2803
|
-
let p = 0, d = 0,
|
|
2803
|
+
let p = 0, d = 0, h = new Error("Nothing to run"), y;
|
|
2804
2804
|
const f = I(n || "retry", c, r);
|
|
2805
2805
|
c && f.progress({
|
|
2806
2806
|
event: W.start,
|
|
@@ -2809,24 +2809,24 @@ async function M(e, t = {}) {
|
|
|
2809
2809
|
retryOnAll: i,
|
|
2810
2810
|
retryMode: a
|
|
2811
2811
|
});
|
|
2812
|
-
const g = (
|
|
2812
|
+
const g = (w) => new Promise((S, v) => {
|
|
2813
2813
|
if (l?.aborted) {
|
|
2814
|
-
|
|
2814
|
+
v(Ot(l));
|
|
2815
2815
|
return;
|
|
2816
2816
|
}
|
|
2817
|
-
const P = setTimeout(
|
|
2817
|
+
const P = setTimeout(S, w);
|
|
2818
2818
|
l?.addEventListener(
|
|
2819
2819
|
"abort",
|
|
2820
2820
|
() => {
|
|
2821
|
-
clearTimeout(P),
|
|
2821
|
+
clearTimeout(P), v(Ot(l));
|
|
2822
2822
|
},
|
|
2823
2823
|
{ once: !0 }
|
|
2824
2824
|
);
|
|
2825
|
-
}),
|
|
2826
|
-
let
|
|
2827
|
-
for (;
|
|
2828
|
-
const P = Math.min(
|
|
2829
|
-
await g(P),
|
|
2825
|
+
}), m = async (w, S) => {
|
|
2826
|
+
let v = w;
|
|
2827
|
+
for (; v > 0; ) {
|
|
2828
|
+
const P = Math.min(v, Sd);
|
|
2829
|
+
await g(P), v -= P, v > 0 && f.progress({ ...S, remaining: v, elapsed: w - v });
|
|
2830
2830
|
}
|
|
2831
2831
|
};
|
|
2832
2832
|
e: for (; p < s; ) {
|
|
@@ -2853,68 +2853,68 @@ async function M(e, t = {}) {
|
|
|
2853
2853
|
y = x;
|
|
2854
2854
|
}
|
|
2855
2855
|
}
|
|
2856
|
-
|
|
2857
|
-
const
|
|
2858
|
-
if (y = void 0,
|
|
2856
|
+
h = y;
|
|
2857
|
+
const w = fr(y);
|
|
2858
|
+
if (y = void 0, w.category === U.authFailure)
|
|
2859
2859
|
throw f.progress({
|
|
2860
2860
|
event: W.error,
|
|
2861
2861
|
attemptNumber: p + 1,
|
|
2862
2862
|
maxAttempts: s,
|
|
2863
|
-
error:
|
|
2863
|
+
error: h.message,
|
|
2864
2864
|
category: U.authFailure,
|
|
2865
2865
|
final: !0
|
|
2866
|
-
}),
|
|
2866
|
+
}), h;
|
|
2867
2867
|
if (a !== qe.strict && d < vd) {
|
|
2868
|
-
if (
|
|
2869
|
-
const x =
|
|
2868
|
+
if (w.category === U.rateLimited) {
|
|
2869
|
+
const x = w.retryAfterMs || Math.min(u.rateLimitCeiling, o * Math.pow(2, d));
|
|
2870
2870
|
if (x <= u.rateLimitCeiling) {
|
|
2871
2871
|
const E = {
|
|
2872
2872
|
event: W.providerWait,
|
|
2873
2873
|
category: U.rateLimited,
|
|
2874
|
-
provider:
|
|
2874
|
+
provider: h.provider,
|
|
2875
2875
|
delay: x,
|
|
2876
2876
|
attempt: d + 1,
|
|
2877
2877
|
resumeAt: new Date(Date.now() + x).toISOString(),
|
|
2878
|
-
error: { message:
|
|
2878
|
+
error: { message: h.message, httpStatus: h.httpStatus }
|
|
2879
2879
|
};
|
|
2880
|
-
f.progress(E), await
|
|
2880
|
+
f.progress(E), await m(x, E), d++, f.progress({
|
|
2881
2881
|
event: W.providerRetry,
|
|
2882
2882
|
category: U.rateLimited,
|
|
2883
|
-
provider:
|
|
2883
|
+
provider: h.provider,
|
|
2884
2884
|
attempt: d
|
|
2885
2885
|
}), f.measure({
|
|
2886
2886
|
metric: ge.providerWait,
|
|
2887
2887
|
value: x,
|
|
2888
2888
|
category: U.rateLimited,
|
|
2889
|
-
provider:
|
|
2889
|
+
provider: h.provider
|
|
2890
2890
|
});
|
|
2891
2891
|
continue e;
|
|
2892
2892
|
}
|
|
2893
2893
|
}
|
|
2894
|
-
if (
|
|
2894
|
+
if (w.category === U.creditExhausted && u.creditRetryInterval > 0) {
|
|
2895
2895
|
let x = 0, E = 0;
|
|
2896
2896
|
for (; ; ) {
|
|
2897
2897
|
x++;
|
|
2898
2898
|
const O = u.creditRetryInterval, R = {
|
|
2899
2899
|
event: W.providerWait,
|
|
2900
2900
|
category: U.creditExhausted,
|
|
2901
|
-
provider:
|
|
2901
|
+
provider: h.provider,
|
|
2902
2902
|
delay: O,
|
|
2903
2903
|
attempt: x,
|
|
2904
2904
|
elapsed: E,
|
|
2905
|
-
error: { message:
|
|
2905
|
+
error: { message: h.message, httpStatus: h.httpStatus }
|
|
2906
2906
|
};
|
|
2907
|
-
f.progress(R), await
|
|
2907
|
+
f.progress(R), await m(O, R), E += O, f.progress({
|
|
2908
2908
|
event: W.providerRetry,
|
|
2909
2909
|
category: U.creditExhausted,
|
|
2910
|
-
provider:
|
|
2910
|
+
provider: h.provider,
|
|
2911
2911
|
attempt: x,
|
|
2912
2912
|
elapsed: E
|
|
2913
2913
|
}), f.measure({
|
|
2914
2914
|
metric: ge.providerWait,
|
|
2915
2915
|
value: O,
|
|
2916
2916
|
category: U.creditExhausted,
|
|
2917
|
-
provider:
|
|
2917
|
+
provider: h.provider
|
|
2918
2918
|
});
|
|
2919
2919
|
try {
|
|
2920
2920
|
const j = await e();
|
|
@@ -2932,59 +2932,59 @@ async function M(e, t = {}) {
|
|
|
2932
2932
|
y = j, d += x;
|
|
2933
2933
|
continue e;
|
|
2934
2934
|
}
|
|
2935
|
-
|
|
2935
|
+
h = j;
|
|
2936
2936
|
}
|
|
2937
2937
|
}
|
|
2938
2938
|
}
|
|
2939
|
-
if (
|
|
2939
|
+
if (w.category === U.overloaded) {
|
|
2940
2940
|
const x = Math.min(
|
|
2941
2941
|
u.overloadBackoffCeiling,
|
|
2942
2942
|
o * Math.pow(2, d)
|
|
2943
2943
|
), E = {
|
|
2944
2944
|
event: W.providerWait,
|
|
2945
2945
|
category: U.overloaded,
|
|
2946
|
-
provider:
|
|
2946
|
+
provider: h.provider,
|
|
2947
2947
|
delay: x,
|
|
2948
2948
|
attempt: d + 1,
|
|
2949
2949
|
resumeAt: new Date(Date.now() + x).toISOString(),
|
|
2950
|
-
error: { message:
|
|
2950
|
+
error: { message: h.message, httpStatus: h.httpStatus }
|
|
2951
2951
|
};
|
|
2952
|
-
f.progress(E), await
|
|
2952
|
+
f.progress(E), await m(x, E), d++, f.progress({
|
|
2953
2953
|
event: W.providerRetry,
|
|
2954
2954
|
category: U.overloaded,
|
|
2955
|
-
provider:
|
|
2955
|
+
provider: h.provider,
|
|
2956
2956
|
attempt: d
|
|
2957
2957
|
}), f.measure({
|
|
2958
2958
|
metric: ge.providerWait,
|
|
2959
2959
|
value: x,
|
|
2960
2960
|
category: U.overloaded,
|
|
2961
|
-
provider:
|
|
2961
|
+
provider: h.provider
|
|
2962
2962
|
});
|
|
2963
2963
|
continue e;
|
|
2964
2964
|
}
|
|
2965
|
-
if (
|
|
2965
|
+
if (w.category === U.serverError) {
|
|
2966
2966
|
const x = Math.min(
|
|
2967
2967
|
u.overloadBackoffCeiling,
|
|
2968
2968
|
o * Math.pow(2, d)
|
|
2969
2969
|
), E = {
|
|
2970
2970
|
event: W.providerWait,
|
|
2971
2971
|
category: U.serverError,
|
|
2972
|
-
provider:
|
|
2972
|
+
provider: h.provider,
|
|
2973
2973
|
delay: x,
|
|
2974
2974
|
attempt: d + 1,
|
|
2975
|
-
error: { message:
|
|
2975
|
+
error: { message: h.message, httpStatus: h.httpStatus }
|
|
2976
2976
|
};
|
|
2977
|
-
f.progress(E), await
|
|
2977
|
+
f.progress(E), await m(x, E), d++, f.progress({
|
|
2978
2978
|
event: W.providerRetry,
|
|
2979
2979
|
category: U.serverError,
|
|
2980
|
-
provider:
|
|
2980
|
+
provider: h.provider,
|
|
2981
2981
|
attempt: d
|
|
2982
2982
|
});
|
|
2983
2983
|
continue e;
|
|
2984
2984
|
}
|
|
2985
2985
|
}
|
|
2986
|
-
const
|
|
2987
|
-
if (
|
|
2986
|
+
const S = h.httpStatus ?? h.response?.status, v = i || S === 429 || S >= 500 && S < 600, P = !v || p >= s - 1;
|
|
2987
|
+
if (v && p < s - 1) {
|
|
2988
2988
|
const x = o * p;
|
|
2989
2989
|
if (c) {
|
|
2990
2990
|
const E = {
|
|
@@ -2992,7 +2992,7 @@ async function M(e, t = {}) {
|
|
|
2992
2992
|
attemptNumber: p + 1,
|
|
2993
2993
|
maxAttempts: s,
|
|
2994
2994
|
delay: x,
|
|
2995
|
-
error:
|
|
2995
|
+
error: h.message
|
|
2996
2996
|
};
|
|
2997
2997
|
p + 1 < s - 1 && (E.nextAttempt = p + 2), f.progress(E);
|
|
2998
2998
|
}
|
|
@@ -3002,9 +3002,9 @@ async function M(e, t = {}) {
|
|
|
3002
3002
|
maxAttempts: s,
|
|
3003
3003
|
outcome: At.error,
|
|
3004
3004
|
error: {
|
|
3005
|
-
message:
|
|
3006
|
-
httpStatus:
|
|
3007
|
-
type:
|
|
3005
|
+
message: h.message,
|
|
3006
|
+
httpStatus: h.httpStatus,
|
|
3007
|
+
type: h.errorType
|
|
3008
3008
|
}
|
|
3009
3009
|
}), f.measure({
|
|
3010
3010
|
metric: ge.retryDelay,
|
|
@@ -3017,7 +3017,7 @@ async function M(e, t = {}) {
|
|
|
3017
3017
|
event: W.error,
|
|
3018
3018
|
attemptNumber: p + 1,
|
|
3019
3019
|
maxAttempts: s,
|
|
3020
|
-
error:
|
|
3020
|
+
error: h.message,
|
|
3021
3021
|
totalAttempts: p + 1,
|
|
3022
3022
|
final: !0
|
|
3023
3023
|
}), f.metrics({
|
|
@@ -3026,13 +3026,13 @@ async function M(e, t = {}) {
|
|
|
3026
3026
|
maxAttempts: s,
|
|
3027
3027
|
outcome: At.exhaust,
|
|
3028
3028
|
error: {
|
|
3029
|
-
message:
|
|
3030
|
-
httpStatus:
|
|
3031
|
-
type:
|
|
3029
|
+
message: h.message,
|
|
3030
|
+
httpStatus: h.httpStatus,
|
|
3031
|
+
type: h.errorType
|
|
3032
3032
|
}
|
|
3033
3033
|
});
|
|
3034
3034
|
}
|
|
3035
|
-
throw
|
|
3035
|
+
throw h;
|
|
3036
3036
|
}
|
|
3037
3037
|
const xd = {
|
|
3038
3038
|
type: "object",
|
|
@@ -3143,51 +3143,51 @@ async function Q(e, t, n = {}) {
|
|
|
3143
3143
|
if (!Array.isArray(e) || e.length === 0)
|
|
3144
3144
|
return [];
|
|
3145
3145
|
if (!(s !== void 0 && s < r)) {
|
|
3146
|
-
const
|
|
3146
|
+
const b = [], f = Ce(r)(e);
|
|
3147
3147
|
let g = 0;
|
|
3148
|
-
for (const
|
|
3148
|
+
for (const m of f) {
|
|
3149
3149
|
if (c?.aborted)
|
|
3150
3150
|
throw c.reason ?? new Error("The operation was aborted.");
|
|
3151
3151
|
if (a === z.resilient) {
|
|
3152
|
-
const
|
|
3153
|
-
|
|
3152
|
+
const w = await Promise.allSettled(
|
|
3153
|
+
m.map((S, v) => t(S, g + v))
|
|
3154
3154
|
);
|
|
3155
|
-
|
|
3155
|
+
b.push(...w.map((S, v) => S.status === "fulfilled" ? S.value : m[v]));
|
|
3156
3156
|
} else {
|
|
3157
|
-
const
|
|
3158
|
-
|
|
3157
|
+
const w = await Promise.all(
|
|
3158
|
+
m.map((S, v) => t(S, g + v))
|
|
3159
3159
|
);
|
|
3160
|
-
|
|
3160
|
+
b.push(...w);
|
|
3161
3161
|
}
|
|
3162
|
-
g +=
|
|
3162
|
+
g += m.length;
|
|
3163
3163
|
}
|
|
3164
|
-
return
|
|
3164
|
+
return b;
|
|
3165
3165
|
}
|
|
3166
3166
|
const u = Math.max(1, s), p = [], d = Cd(Ad);
|
|
3167
|
-
let
|
|
3167
|
+
let h = r, y = 0;
|
|
3168
3168
|
for (; y < e.length; ) {
|
|
3169
3169
|
if (c?.aborted)
|
|
3170
3170
|
throw c.reason ?? new Error("The operation was aborted.");
|
|
3171
|
-
const
|
|
3171
|
+
const b = e.slice(y, y + h), f = Date.now();
|
|
3172
3172
|
let g = 0;
|
|
3173
3173
|
if (a === z.resilient) {
|
|
3174
|
-
const
|
|
3175
|
-
|
|
3174
|
+
const S = await Promise.allSettled(
|
|
3175
|
+
b.map((v, P) => t(v, y + P))
|
|
3176
3176
|
);
|
|
3177
|
-
g =
|
|
3177
|
+
g = S.filter((v) => v.status === "rejected").length, p.push(...S.map((v, P) => v.status === "fulfilled" ? v.value : b[P]));
|
|
3178
3178
|
} else {
|
|
3179
|
-
const
|
|
3180
|
-
|
|
3179
|
+
const S = await Promise.all(
|
|
3180
|
+
b.map((v, P) => t(v, y + P))
|
|
3181
3181
|
);
|
|
3182
|
-
p.push(...
|
|
3182
|
+
p.push(...S);
|
|
3183
3183
|
}
|
|
3184
|
-
const
|
|
3185
|
-
d.record(
|
|
3186
|
-
|
|
3184
|
+
const m = Date.now() - f, w = g / b.length;
|
|
3185
|
+
d.record(m, w), h = jd(
|
|
3186
|
+
h,
|
|
3187
3187
|
d,
|
|
3188
3188
|
{ min: u, max: r },
|
|
3189
3189
|
{ latency: o, error: i }
|
|
3190
|
-
), y +=
|
|
3190
|
+
), y += b.length;
|
|
3191
3191
|
}
|
|
3192
3192
|
return p;
|
|
3193
3193
|
}
|
|
@@ -3348,10 +3348,10 @@ ${r}` : n, o = A(yr, t), i = I(yr, o.onProgress, o);
|
|
|
3348
3348
|
try {
|
|
3349
3349
|
const u = Wd(s), p = br(s);
|
|
3350
3350
|
if (!c) {
|
|
3351
|
-
const
|
|
3352
|
-
return i.emit({ event: k.output, value:
|
|
3351
|
+
const S = await Ct(p, o);
|
|
3352
|
+
return i.emit({ event: k.output, value: S }), i.complete({ outcome: T.success }), S;
|
|
3353
3353
|
}
|
|
3354
|
-
const [d,
|
|
3354
|
+
const [d, h] = await Q(
|
|
3355
3355
|
[
|
|
3356
3356
|
() => _(u, {
|
|
3357
3357
|
...o,
|
|
@@ -3363,30 +3363,30 @@ ${r}` : n, o = A(yr, t), i = I(yr, o.onProgress, o);
|
|
|
3363
3363
|
onProgress: L(o.onProgress, "extract")
|
|
3364
3364
|
})
|
|
3365
3365
|
],
|
|
3366
|
-
(
|
|
3366
|
+
(S) => S(),
|
|
3367
3367
|
{ maxParallel: 2, abortSignal: o?.abortSignal }
|
|
3368
3368
|
), y = d.length > 0 ? d : ["The result is a valid date"];
|
|
3369
|
-
if (!
|
|
3369
|
+
if (!h) {
|
|
3370
3370
|
i.emit({ event: k.output, value: void 0 }), i.complete({ outcome: T.success });
|
|
3371
3371
|
return;
|
|
3372
3372
|
}
|
|
3373
|
-
let
|
|
3374
|
-
const
|
|
3373
|
+
let b = h, f = e, g = 0;
|
|
3374
|
+
const m = i.batch(a), w = await M(
|
|
3375
3375
|
async () => {
|
|
3376
3376
|
g += 1, i.emit({
|
|
3377
3377
|
event: k.step,
|
|
3378
3378
|
stepName: "validation-attempt",
|
|
3379
3379
|
attempt: g,
|
|
3380
3380
|
maxAttempts: a,
|
|
3381
|
-
currentDate:
|
|
3381
|
+
currentDate: b?.toISOString()
|
|
3382
3382
|
});
|
|
3383
|
-
const
|
|
3384
|
-
if (
|
|
3385
|
-
return
|
|
3386
|
-
f = `${s} The previous answer (${
|
|
3387
|
-
const
|
|
3388
|
-
if (!P || (
|
|
3389
|
-
return l ?
|
|
3383
|
+
const S = await Kd(b, y, o);
|
|
3384
|
+
if (m(1), S.passed)
|
|
3385
|
+
return b;
|
|
3386
|
+
f = `${s} The previous answer (${b.toISOString()}) failed to satisfy: "${S.failedCheck}". Try again.`;
|
|
3387
|
+
const v = br(f), P = await Ct(v, o);
|
|
3388
|
+
if (!P || (b = P, g >= a))
|
|
3389
|
+
return l ? b : void 0;
|
|
3390
3390
|
throw new Error("Retrying after validation failure");
|
|
3391
3391
|
},
|
|
3392
3392
|
{
|
|
@@ -3396,7 +3396,7 @@ ${r}` : n, o = A(yr, t), i = I(yr, o.onProgress, o);
|
|
|
3396
3396
|
retryOnAll: !0
|
|
3397
3397
|
}
|
|
3398
3398
|
);
|
|
3399
|
-
return i.emit({ event: k.output, value:
|
|
3399
|
+
return i.emit({ event: k.output, value: w }), i.complete({ outcome: T.success }), w;
|
|
3400
3400
|
} catch (u) {
|
|
3401
3401
|
throw i.error(u), u;
|
|
3402
3402
|
}
|
|
@@ -3735,7 +3735,7 @@ ${$(i, { tag: "classification-instructions" })}` : "", u = {
|
|
|
3735
3735
|
- Salience should reflect absolute significance, not relative standing`
|
|
3736
3736
|
}, p = s !== "statistical" ? `
|
|
3737
3737
|
|
|
3738
|
-
Threshold derivation strategy: ${s}${u[s] || u.fixed}` : "",
|
|
3738
|
+
Threshold derivation strategy: ${s}${u[s] || u.fixed}` : "", h = {
|
|
3739
3739
|
low: `
|
|
3740
3740
|
|
|
3741
3741
|
Classification posture: conservative. Prefer false negatives over false positives. Only flag items with strong, unambiguous signals. Set severity and salience thresholds high — routine items should classify as none/routine unless clearly elevated.`,
|
|
@@ -3744,7 +3744,7 @@ Classification posture: conservative. Prefer false negatives over false positive
|
|
|
3744
3744
|
Classification posture: sensitive. Prefer false positives over false negatives. Flag items with even weak or ambiguous signals. Set severity and salience thresholds low to catch edge cases — when in doubt, classify higher.`
|
|
3745
3745
|
}[o] || "", y = `Analyze these corpus scan statistics and generate a calibration specification.
|
|
3746
3746
|
|
|
3747
|
-
${$(a, { tag: "scan-statistics" })}${l}${p}${
|
|
3747
|
+
${$(a, { tag: "scan-statistics" })}${l}${p}${h}
|
|
3748
3748
|
|
|
3749
3749
|
Provide a JSON object with exactly four string properties:
|
|
3750
3750
|
- corpusProfile: Overview of the corpus sensitivity landscape — what categories appear, how prevalent, overall risk profile
|
|
@@ -3754,7 +3754,7 @@ Provide a JSON object with exactly four string properties:
|
|
|
3754
3754
|
|
|
3755
3755
|
IMPORTANT: Each property must be a simple string value, not a nested object or array.`;
|
|
3756
3756
|
try {
|
|
3757
|
-
const
|
|
3757
|
+
const b = await M(
|
|
3758
3758
|
() => _(y, {
|
|
3759
3759
|
...n,
|
|
3760
3760
|
systemPrompt: c,
|
|
@@ -3768,9 +3768,9 @@ IMPORTANT: Each property must be a simple string value, not a nested object or a
|
|
|
3768
3768
|
config: n
|
|
3769
3769
|
}
|
|
3770
3770
|
);
|
|
3771
|
-
return r.complete({ outcome: T.success }),
|
|
3772
|
-
} catch (
|
|
3773
|
-
throw r.error(
|
|
3771
|
+
return r.complete({ outcome: T.success }), b;
|
|
3772
|
+
} catch (b) {
|
|
3773
|
+
throw r.error(b), b;
|
|
3774
3774
|
}
|
|
3775
3775
|
}
|
|
3776
3776
|
async function _m(e, t, n = {}) {
|
|
@@ -4036,26 +4036,26 @@ async function Dm(e, t, n, r) {
|
|
|
4036
4036
|
dimensions: n.map((g) => g.name)
|
|
4037
4037
|
}), a?.length) {
|
|
4038
4038
|
const g = () => {
|
|
4039
|
-
const
|
|
4040
|
-
for (const
|
|
4041
|
-
const
|
|
4042
|
-
|
|
4039
|
+
const m = {};
|
|
4040
|
+
for (const w of n) {
|
|
4041
|
+
const S = l.get(w.name);
|
|
4042
|
+
m[w.name] = S.selection ?? S.candidates[0];
|
|
4043
4043
|
}
|
|
4044
|
-
return
|
|
4044
|
+
return m;
|
|
4045
4045
|
};
|
|
4046
|
-
for (const
|
|
4047
|
-
const
|
|
4048
|
-
if (
|
|
4049
|
-
for (const [
|
|
4050
|
-
const x = n.find((F) => F.name ===
|
|
4046
|
+
for (const m of a) {
|
|
4047
|
+
const w = g(), S = m.enforce(w);
|
|
4048
|
+
if (S)
|
|
4049
|
+
for (const [v, P] of Object.entries(S)) {
|
|
4050
|
+
const x = n.find((F) => F.name === v);
|
|
4051
4051
|
if (!x) continue;
|
|
4052
4052
|
const E = x.values.indexOf(P);
|
|
4053
4053
|
if (E < 0) continue;
|
|
4054
|
-
const O = l.get(
|
|
4054
|
+
const O = l.get(v);
|
|
4055
4055
|
if (E <= O.floorIdx) continue;
|
|
4056
4056
|
const R = x.values.slice(E);
|
|
4057
4057
|
let j;
|
|
4058
|
-
R.length <= 1 ? j = R[0] ?? x.values[x.values.length - 1] : O.selection !== void 0 && R.includes(O.selection) ? j = O.selection : j = P, l.set(
|
|
4058
|
+
R.length <= 1 ? j = R[0] ?? x.values[x.values.length - 1] : O.selection !== void 0 && R.includes(O.selection) ? j = O.selection : j = P, l.set(v, {
|
|
4059
4059
|
...O,
|
|
4060
4060
|
floorIdx: E,
|
|
4061
4061
|
candidates: R,
|
|
@@ -4071,32 +4071,32 @@ async function Dm(e, t, n, r) {
|
|
|
4071
4071
|
if (u.length === 0)
|
|
4072
4072
|
return o.complete({ outcome: T.success, dimensions: n.length }), n.map((g) => l.get(g.name).selection);
|
|
4073
4073
|
const p = u.map((g) => {
|
|
4074
|
-
const
|
|
4075
|
-
return { dim: g, candidates:
|
|
4076
|
-
}), d = Lm(p, i),
|
|
4077
|
-
for (const { dim: g, candidates:
|
|
4078
|
-
y[g.name] = Object.fromEntries(
|
|
4074
|
+
const m = l.get(g.name), w = m.mayResults.filter((S) => m.candidates.includes(S.resolved));
|
|
4075
|
+
return { dim: g, candidates: m.candidates, viableMays: w };
|
|
4076
|
+
}), d = Lm(p, i), h = {}, y = {};
|
|
4077
|
+
for (const { dim: g, candidates: m } of p)
|
|
4078
|
+
y[g.name] = Object.fromEntries(m.map((w) => [String(w), w])), h[g.name] = {
|
|
4079
4079
|
type: "string",
|
|
4080
|
-
enum:
|
|
4080
|
+
enum: m.map(String),
|
|
4081
4081
|
description: `Selected value for ${g.name}`
|
|
4082
4082
|
};
|
|
4083
|
-
const
|
|
4083
|
+
const b = {
|
|
4084
4084
|
type: "object",
|
|
4085
|
-
properties:
|
|
4085
|
+
properties: h,
|
|
4086
4086
|
required: u.map((g) => g.name),
|
|
4087
4087
|
additionalProperties: !1
|
|
4088
4088
|
}, f = await M(
|
|
4089
4089
|
() => _(d, {
|
|
4090
4090
|
...s,
|
|
4091
|
-
responseFormat: C("value_arbitrate_multi",
|
|
4091
|
+
responseFormat: C("value_arbitrate_multi", b)
|
|
4092
4092
|
}),
|
|
4093
4093
|
{ label: "value-arbitrate", config: s }
|
|
4094
4094
|
);
|
|
4095
4095
|
for (const g of u) {
|
|
4096
|
-
const
|
|
4096
|
+
const m = l.get(g.name), w = f?.[g.name], S = y[g.name]?.[w];
|
|
4097
4097
|
l.set(g.name, {
|
|
4098
|
-
...
|
|
4099
|
-
selection:
|
|
4098
|
+
...m,
|
|
4099
|
+
selection: S !== void 0 ? S : m.candidates[0]
|
|
4100
4100
|
});
|
|
4101
4101
|
}
|
|
4102
4102
|
return o.complete({
|
|
@@ -4121,25 +4121,25 @@ async function Bi(e, t, n, r = {}) {
|
|
|
4121
4121
|
try {
|
|
4122
4122
|
const a = await Q(
|
|
4123
4123
|
e,
|
|
4124
|
-
async (
|
|
4125
|
-
name:
|
|
4126
|
-
strictness:
|
|
4127
|
-
weight:
|
|
4128
|
-
prompt:
|
|
4129
|
-
resolved: await
|
|
4124
|
+
async (w) => ({
|
|
4125
|
+
name: w.name,
|
|
4126
|
+
strictness: w.strictness,
|
|
4127
|
+
weight: w.weight,
|
|
4128
|
+
prompt: w.prompt,
|
|
4129
|
+
resolved: await w.value(t)
|
|
4130
4130
|
}),
|
|
4131
4131
|
{ maxParallel: 5, errorPosture: z.resilient, abortSignal: s.abortSignal }
|
|
4132
|
-
), c = a.filter((
|
|
4132
|
+
), c = a.filter((w) => w.strictness === "must"), l = a.filter((w) => w.strictness === "may"), u = c.length > 0 ? Li(c, n) : -1, p = u >= 0 ? n.slice(u) : [...n];
|
|
4133
4133
|
if (p.length === 0)
|
|
4134
4134
|
return o.complete({ outcome: T.success }), n[n.length - 1];
|
|
4135
4135
|
if (p.length === 1)
|
|
4136
4136
|
return o.complete({ outcome: T.success }), p[0];
|
|
4137
|
-
const d = l.filter((
|
|
4138
|
-
if (
|
|
4139
|
-
return o.complete({ outcome: T.success }),
|
|
4137
|
+
const d = l.filter((w) => p.includes(w.resolved)), h = [...new Set(d.map((w) => w.resolved))];
|
|
4138
|
+
if (h.length === 1)
|
|
4139
|
+
return o.complete({ outcome: T.success }), h[0];
|
|
4140
4140
|
if (d.length === 0)
|
|
4141
4141
|
return o.complete({ outcome: T.success }), p[0];
|
|
4142
|
-
const y = Mm(d, p, i),
|
|
4142
|
+
const y = Mm(d, p, i), b = Object.fromEntries(p.map((w) => [String(w), w])), f = {
|
|
4143
4143
|
type: "object",
|
|
4144
4144
|
properties: {
|
|
4145
4145
|
value: {
|
|
@@ -4156,8 +4156,8 @@ async function Bi(e, t, n, r = {}) {
|
|
|
4156
4156
|
responseFormat: C("value_arbitrate", f)
|
|
4157
4157
|
}),
|
|
4158
4158
|
{ label: "value-arbitrate", config: s }
|
|
4159
|
-
),
|
|
4160
|
-
return o.complete({ outcome: T.success }),
|
|
4159
|
+
), m = b[g];
|
|
4160
|
+
return o.complete({ outcome: T.success }), m !== void 0 ? m : p[0];
|
|
4161
4161
|
} catch (a) {
|
|
4162
4162
|
throw o.error(a), a;
|
|
4163
4163
|
}
|
|
@@ -4652,10 +4652,10 @@ async function be(e, t, n) {
|
|
|
4652
4652
|
if (typeof t == "function")
|
|
4653
4653
|
r = t;
|
|
4654
4654
|
else {
|
|
4655
|
-
const { text:
|
|
4656
|
-
r = y ? `${
|
|
4655
|
+
const { text: h, context: y } = N(t, []);
|
|
4656
|
+
r = y ? `${h}
|
|
4657
4657
|
|
|
4658
|
-
${y}` :
|
|
4658
|
+
${y}` : h;
|
|
4659
4659
|
}
|
|
4660
4660
|
const s = A(kr, n), o = I(kr, s.onProgress, s);
|
|
4661
4661
|
o.start();
|
|
@@ -4677,9 +4677,9 @@ ${y}` : m;
|
|
|
4677
4677
|
}), !e || e.length === 0)
|
|
4678
4678
|
return o.complete({ outcome: T.success }), [];
|
|
4679
4679
|
try {
|
|
4680
|
-
const
|
|
4680
|
+
const h = je(i, e, a), y = ah(e, r, h), b = l ?? C("list_result", ch), f = {
|
|
4681
4681
|
...c && { maxTokens: c },
|
|
4682
|
-
responseFormat:
|
|
4682
|
+
responseFormat: b
|
|
4683
4683
|
};
|
|
4684
4684
|
p?.debug && p.debug("Calling llm", {
|
|
4685
4685
|
promptLength: y.length,
|
|
@@ -4700,18 +4700,18 @@ ${y}` : m;
|
|
|
4700
4700
|
hasAbortSignal: !!g.abortSignal,
|
|
4701
4701
|
modelKeys: Object.keys(f)
|
|
4702
4702
|
});
|
|
4703
|
-
const
|
|
4703
|
+
const m = await _(y, g);
|
|
4704
4704
|
return p?.debug && p.debug("LLM response received", {
|
|
4705
|
-
outputType: Array.isArray(
|
|
4706
|
-
outputLength: Array.isArray(
|
|
4707
|
-
}), o.complete({ outcome: T.success }),
|
|
4708
|
-
} catch (
|
|
4705
|
+
outputType: Array.isArray(m) ? "array" : typeof m,
|
|
4706
|
+
outputLength: Array.isArray(m) ? m.length : void 0
|
|
4707
|
+
}), o.complete({ outcome: T.success }), m;
|
|
4708
|
+
} catch (h) {
|
|
4709
4709
|
throw p?.error && p.error("LLM request failed in listBatch", {
|
|
4710
|
-
error:
|
|
4710
|
+
error: h.message,
|
|
4711
4711
|
llmConfig: u,
|
|
4712
4712
|
promptLength: e?.length,
|
|
4713
4713
|
itemCount: e?.length
|
|
4714
|
-
}), o.error(
|
|
4714
|
+
}), o.error(h), h;
|
|
4715
4715
|
}
|
|
4716
4716
|
}
|
|
4717
4717
|
be.knownTexts = [];
|
|
@@ -4751,29 +4751,29 @@ const Or = async function(e, t, n = {}) {
|
|
|
4751
4751
|
return await Q(
|
|
4752
4752
|
l,
|
|
4753
4753
|
async ({ items: p, startIndex: d }) => {
|
|
4754
|
-
const
|
|
4754
|
+
const h = je(n.listStyle, p, n.autoModeThreshold), y = lh(
|
|
4755
4755
|
t,
|
|
4756
4756
|
p,
|
|
4757
|
-
|
|
4757
|
+
h,
|
|
4758
4758
|
a,
|
|
4759
4759
|
n.responseFormat
|
|
4760
4760
|
);
|
|
4761
4761
|
try {
|
|
4762
|
-
const
|
|
4762
|
+
const b = {
|
|
4763
4763
|
...n,
|
|
4764
4764
|
onProgress: L(o, "map:list-batch"),
|
|
4765
|
-
listStyle:
|
|
4766
|
-
}, f = await M(() => be(p, y,
|
|
4765
|
+
listStyle: h
|
|
4766
|
+
}, f = await M(() => be(p, y, b), {
|
|
4767
4767
|
label: "map:batch",
|
|
4768
4768
|
config: n
|
|
4769
4769
|
});
|
|
4770
4770
|
if (!Array.isArray(f))
|
|
4771
4771
|
throw new Error(`Expected array from listBatch, got: ${typeof f}`);
|
|
4772
|
-
f.forEach((g,
|
|
4773
|
-
c[d +
|
|
4772
|
+
f.forEach((g, m) => {
|
|
4773
|
+
c[d + m] = g;
|
|
4774
4774
|
}), u(p.length);
|
|
4775
|
-
} catch (
|
|
4776
|
-
if (
|
|
4775
|
+
} catch (b) {
|
|
4776
|
+
if (b.name === "AbortError" || n?.abortSignal?.aborted || s === z.strict) throw b;
|
|
4777
4777
|
u(p.length);
|
|
4778
4778
|
}
|
|
4779
4779
|
},
|
|
@@ -4800,28 +4800,32 @@ const Or = async function(e, t, n = {}) {
|
|
|
4800
4800
|
_batchDone: u,
|
|
4801
4801
|
_context: s
|
|
4802
4802
|
});
|
|
4803
|
-
for (let
|
|
4803
|
+
for (let b = 1; b < a; b += 1) {
|
|
4804
4804
|
const f = [], g = [];
|
|
4805
|
-
if (p.forEach((
|
|
4806
|
-
|
|
4805
|
+
if (p.forEach((w, S) => {
|
|
4806
|
+
w === rn && (f.push(S), g.push(e[S]));
|
|
4807
4807
|
}), g.length === 0) break;
|
|
4808
4808
|
(await Or(g, r, {
|
|
4809
4809
|
...o,
|
|
4810
4810
|
maxAttempts: a,
|
|
4811
4811
|
maxParallel: c,
|
|
4812
4812
|
_context: s
|
|
4813
|
-
})).forEach((
|
|
4814
|
-
p[f[
|
|
4813
|
+
})).forEach((w, S) => {
|
|
4814
|
+
p[f[S]] = w;
|
|
4815
4815
|
});
|
|
4816
4816
|
}
|
|
4817
4817
|
let d = 0;
|
|
4818
|
-
for (let
|
|
4819
|
-
p[
|
|
4820
|
-
|
|
4818
|
+
for (let b = 0; b < p.length; b++)
|
|
4819
|
+
p[b] === rn && (p[b] = e[b], d++);
|
|
4820
|
+
if (d === p.length && p.length > 0) {
|
|
4821
|
+
const b = new Error(`map: all ${p.length} items failed to process`);
|
|
4822
|
+
throw i.error(b), b;
|
|
4823
|
+
}
|
|
4824
|
+
const h = d > 0 ? T.partial : T.success, y = {
|
|
4821
4825
|
totalItems: p.length,
|
|
4822
4826
|
successCount: p.length - d,
|
|
4823
4827
|
failedItems: d,
|
|
4824
|
-
outcome:
|
|
4828
|
+
outcome: h
|
|
4825
4829
|
};
|
|
4826
4830
|
return i.emit({ event: k.output, value: p }), i.complete(y), p;
|
|
4827
4831
|
} catch (a) {
|
|
@@ -5014,15 +5018,15 @@ const Nr = {
|
|
|
5014
5018
|
});
|
|
5015
5019
|
let l = i.initial;
|
|
5016
5020
|
(c === "collection" || c === "auto" && Array.isArray(i.initial) && !i.responseFormat) && (l = { items: i.initial });
|
|
5017
|
-
const p = await Ae(t, i), d = a.batch(t.length),
|
|
5021
|
+
const p = await Ae(t, i), d = a.batch(t.length), h = p;
|
|
5018
5022
|
a.progress({
|
|
5019
5023
|
event: W.start,
|
|
5020
5024
|
totalItems: t.length,
|
|
5021
|
-
totalBatches:
|
|
5025
|
+
totalBatches: h.length
|
|
5022
5026
|
});
|
|
5023
|
-
for (const { items:
|
|
5027
|
+
for (const { items: b, skip: f } of p) {
|
|
5024
5028
|
if (f) continue;
|
|
5025
|
-
const g = je(i.listStyle,
|
|
5029
|
+
const g = je(i.listStyle, b, i.autoModeThreshold), m = ({ style: x, count: E }) => {
|
|
5026
5030
|
const O = x === ue.XML ? "XML" : "", R = o ? `
|
|
5027
5031
|
|
|
5028
5032
|
${o}` : "";
|
|
@@ -5042,16 +5046,16 @@ ${$(l !== void 0 ? l : "No initial value - use first item as starting point", {
|
|
|
5042
5046
|
})}
|
|
5043
5047
|
|
|
5044
5048
|
Process exactly ${E} items from the ${O} list below and return the final accumulator value.${R}`;
|
|
5045
|
-
},
|
|
5049
|
+
}, w = i.responseFormat || Sh, S = m({ style: g, count: b.length }), v = {
|
|
5046
5050
|
...i,
|
|
5047
5051
|
listStyle: g,
|
|
5048
|
-
responseFormat:
|
|
5049
|
-
}, P = await M(() => be(
|
|
5052
|
+
responseFormat: w
|
|
5053
|
+
}, P = await M(() => be(b, S, v), {
|
|
5050
5054
|
label: "reduce:batch",
|
|
5051
5055
|
config: i,
|
|
5052
5056
|
onProgress: L(i.onProgress, "batch")
|
|
5053
5057
|
});
|
|
5054
|
-
!i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(
|
|
5058
|
+
!i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(b.length);
|
|
5055
5059
|
}
|
|
5056
5060
|
a.progress({
|
|
5057
5061
|
event: W.complete,
|
|
@@ -5060,7 +5064,7 @@ Process exactly ${E} items from the ${O} list below and return the final accumul
|
|
|
5060
5064
|
});
|
|
5061
5065
|
const y = {
|
|
5062
5066
|
totalItems: t.length,
|
|
5063
|
-
totalBatches:
|
|
5067
|
+
totalBatches: h.length,
|
|
5064
5068
|
outcome: T.success
|
|
5065
5069
|
};
|
|
5066
5070
|
return a.emit({ event: k.output, value: l }), a.complete(y), l;
|
|
@@ -5165,8 +5169,8 @@ async function Ji(e, t = {}) {
|
|
|
5165
5169
|
});
|
|
5166
5170
|
if (p(l.length), !Array.isArray(d))
|
|
5167
5171
|
return r.complete({ outcome: T.success }), [];
|
|
5168
|
-
const
|
|
5169
|
-
return r.emit({ event: k.output, value:
|
|
5172
|
+
const h = d.filter((y) => y.type === "pattern" && y.count >= 2).toSorted((y, b) => b.count - y.count).map((y) => y.template).slice(0, i);
|
|
5173
|
+
return r.emit({ event: k.output, value: h }), r.complete({ outcome: T.success }), h;
|
|
5170
5174
|
} catch (p) {
|
|
5171
5175
|
throw r.error(p), p;
|
|
5172
5176
|
}
|
|
@@ -5283,23 +5287,23 @@ Accumulator should track:
|
|
|
5283
5287
|
|
|
5284
5288
|
Return the updated accumulator as valid JSON.`, o].filter(Boolean).join(`
|
|
5285
5289
|
|
|
5286
|
-
`),
|
|
5287
|
-
for (let P = 0; P < u.length; P +=
|
|
5288
|
-
const x = u.slice(P, P +
|
|
5290
|
+
`), b = 20, f = [];
|
|
5291
|
+
for (let P = 0; P < u.length; P += b) {
|
|
5292
|
+
const x = u.slice(P, P + b);
|
|
5289
5293
|
f.push(JSON.stringify(x));
|
|
5290
5294
|
}
|
|
5291
5295
|
a.emit({ event: k.phase, phase: "enriched", enrichedData: u });
|
|
5292
|
-
const
|
|
5296
|
+
const m = await Ie(f, y, {
|
|
5293
5297
|
...i,
|
|
5294
5298
|
initial: JSON.stringify(d),
|
|
5295
5299
|
batchSize: c,
|
|
5296
5300
|
responseFormat: C("analysis_accumulator", p),
|
|
5297
5301
|
onProgress: L(i.onProgress, "reduce:analysis")
|
|
5298
|
-
}),
|
|
5302
|
+
}), S = [`Based on the following analysis of ${l.count} data points for property "${t}", generate threshold recommendations.
|
|
5299
5303
|
|
|
5300
5304
|
${$(s, { tag: "goal" })}
|
|
5301
5305
|
|
|
5302
|
-
${$(JSON.stringify(
|
|
5306
|
+
${$(JSON.stringify(m, null, 2), { tag: "accumulated-analysis" })}
|
|
5303
5307
|
|
|
5304
5308
|
${$(
|
|
5305
5309
|
JSON.stringify(
|
|
@@ -5328,8 +5332,8 @@ Generate specific threshold recommendations that:
|
|
|
5328
5332
|
|
|
5329
5333
|
Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
5330
5334
|
|
|
5331
|
-
`),
|
|
5332
|
-
() => _(
|
|
5335
|
+
`), v = await M(
|
|
5336
|
+
() => _(S, {
|
|
5333
5337
|
...i,
|
|
5334
5338
|
responseFormat: C("threshold_result", Oh)
|
|
5335
5339
|
}),
|
|
@@ -5338,9 +5342,9 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
|
5338
5342
|
config: i
|
|
5339
5343
|
}
|
|
5340
5344
|
);
|
|
5341
|
-
return
|
|
5345
|
+
return v.thresholdCandidates && (v.thresholdCandidates = v.thresholdCandidates.filter((P) => P.value < l.min || P.value > l.max ? (ne(
|
|
5342
5346
|
`Threshold value ${P.value} is outside data range [${l.min}, ${l.max}]`
|
|
5343
|
-
), !1) : !0)),
|
|
5347
|
+
), !1) : !0)), v.distributionAnalysis = {
|
|
5344
5348
|
mean: l.mean,
|
|
5345
5349
|
median: l.median,
|
|
5346
5350
|
standardDeviation: l.stdDev,
|
|
@@ -5348,7 +5352,7 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
|
5348
5352
|
max: l.max,
|
|
5349
5353
|
percentiles: l.percentiles,
|
|
5350
5354
|
dataPoints: l.count
|
|
5351
|
-
}, a.complete({ outcome: T.success }),
|
|
5355
|
+
}, a.complete({ outcome: T.success }), v;
|
|
5352
5356
|
} catch (l) {
|
|
5353
5357
|
throw a.error(l), l;
|
|
5354
5358
|
}
|
|
@@ -5504,7 +5508,7 @@ async function Xi(e, t, n) {
|
|
|
5504
5508
|
|
|
5505
5509
|
${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
5506
5510
|
a.start(), a.emit({ event: k.input, value: e });
|
|
5507
|
-
const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll:
|
|
5511
|
+
const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll: h } = await q(i, {
|
|
5508
5512
|
precision: J(qh, ["windowSize", "overlapSize"]),
|
|
5509
5513
|
maxParallel: 3,
|
|
5510
5514
|
maxAttempts: void 0,
|
|
@@ -5515,13 +5519,13 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5515
5519
|
return a.complete({ blocksExtracted: 0, outcome: T.success }), [];
|
|
5516
5520
|
try {
|
|
5517
5521
|
const y = e.split(`
|
|
5518
|
-
`),
|
|
5519
|
-
for (let x = 0; x <
|
|
5522
|
+
`), b = y.length, f = [];
|
|
5523
|
+
for (let x = 0; x < b; x += l - u)
|
|
5520
5524
|
f.push(x);
|
|
5521
5525
|
a.emit({
|
|
5522
5526
|
event: k.phase,
|
|
5523
5527
|
phase: "windowing",
|
|
5524
|
-
totalLines:
|
|
5528
|
+
totalLines: b,
|
|
5525
5529
|
windowCount: f.length,
|
|
5526
5530
|
windowSize: l,
|
|
5527
5531
|
overlapSize: u
|
|
@@ -5533,10 +5537,10 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5533
5537
|
totalBatches: f.length,
|
|
5534
5538
|
maxParallel: c
|
|
5535
5539
|
}), a.emit({ event: k.phase, phase: "extraction" });
|
|
5536
|
-
const
|
|
5540
|
+
const m = await Q(
|
|
5537
5541
|
f,
|
|
5538
5542
|
async (x) => {
|
|
5539
|
-
const E = Math.min(x + l,
|
|
5543
|
+
const E = Math.min(x + l, b), O = y.slice(x, E), R = zh(O, x, o), j = await M(
|
|
5540
5544
|
async () => {
|
|
5541
5545
|
const F = await _(R, {
|
|
5542
5546
|
...i,
|
|
@@ -5549,7 +5553,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5549
5553
|
config: i,
|
|
5550
5554
|
maxAttempts: p,
|
|
5551
5555
|
retryMode: d,
|
|
5552
|
-
retryOnAll:
|
|
5556
|
+
retryOnAll: h,
|
|
5553
5557
|
onProgress: L(i.onProgress, "window")
|
|
5554
5558
|
}
|
|
5555
5559
|
);
|
|
@@ -5564,24 +5568,24 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5564
5568
|
a.emit({
|
|
5565
5569
|
event: k.phase,
|
|
5566
5570
|
phase: "merging",
|
|
5567
|
-
rawBlocks:
|
|
5571
|
+
rawBlocks: m.flat().length
|
|
5568
5572
|
});
|
|
5569
|
-
const
|
|
5570
|
-
for (const x of
|
|
5571
|
-
const E =
|
|
5572
|
-
!E || x.startLine > E.endLine ?
|
|
5573
|
+
const w = m.flat().filter((x) => x && x.startLine !== void 0 && x.endLine !== void 0).toSorted((x, E) => x.startLine - E.startLine || E.endLine - x.endLine), S = [];
|
|
5574
|
+
for (const x of w) {
|
|
5575
|
+
const E = S[S.length - 1];
|
|
5576
|
+
!E || x.startLine > E.endLine ? S.push({ ...x }) : x.endLine > E.endLine && (E.endLine = x.endLine);
|
|
5573
5577
|
}
|
|
5574
|
-
const
|
|
5578
|
+
const v = S.map(
|
|
5575
5579
|
({ startLine: x, endLine: E }) => y.slice(x, E + 1)
|
|
5576
5580
|
);
|
|
5577
5581
|
a.progress({
|
|
5578
5582
|
event: W.complete,
|
|
5579
5583
|
totalItems: f.length,
|
|
5580
5584
|
processedItems: g.count,
|
|
5581
|
-
blocksExtracted:
|
|
5585
|
+
blocksExtracted: v.length
|
|
5582
5586
|
});
|
|
5583
|
-
const P = { blocksExtracted:
|
|
5584
|
-
return a.emit({ event: k.output, value:
|
|
5587
|
+
const P = { blocksExtracted: v.length, outcome: T.success };
|
|
5588
|
+
return a.emit({ event: k.output, value: v }), a.complete(P), v;
|
|
5585
5589
|
} catch (y) {
|
|
5586
5590
|
throw a.error(y), y;
|
|
5587
5591
|
}
|
|
@@ -5628,13 +5632,13 @@ const zr = {
|
|
|
5628
5632
|
maxParallel: p = 3
|
|
5629
5633
|
} = await q(a, {
|
|
5630
5634
|
strictness: J(Uh, ["guidance", "errorPosture"])
|
|
5631
|
-
}), d = o.guidance ?? l,
|
|
5635
|
+
}), d = o.guidance ?? l, h = new Array(t.length), y = await Ae(t, a), b = c.batch(t.length);
|
|
5632
5636
|
c.progress({
|
|
5633
5637
|
event: W.start,
|
|
5634
5638
|
totalItems: t.length,
|
|
5635
5639
|
totalBatches: y.length
|
|
5636
5640
|
});
|
|
5637
|
-
const f = ({ style:
|
|
5641
|
+
const f = ({ style: S, count: v }) => {
|
|
5638
5642
|
const P = d ? `
|
|
5639
5643
|
|
|
5640
5644
|
${$(d, { tag: "borderline-handling" })}` : "", x = i ? `
|
|
@@ -5648,34 +5652,34 @@ IMPORTANT:
|
|
|
5648
5652
|
- Consider all aspects of the filtering criteria
|
|
5649
5653
|
- Return only "yes" or "no" for each item
|
|
5650
5654
|
- Maintain the exact order of the input list${x}`;
|
|
5651
|
-
return
|
|
5655
|
+
return S === ue.NEWLINE ? `${E}
|
|
5652
5656
|
|
|
5653
|
-
Process exactly ${
|
|
5657
|
+
Process exactly ${v} items from the list below and return ${v} yes/no decisions.` : `${E}
|
|
5654
5658
|
|
|
5655
|
-
Process exactly ${
|
|
5659
|
+
Process exactly ${v} items from the XML list below and return ${v} yes/no decisions.`;
|
|
5656
5660
|
};
|
|
5657
5661
|
await Q(
|
|
5658
5662
|
y,
|
|
5659
|
-
async ({ items:
|
|
5660
|
-
const P = je(a.listStyle,
|
|
5663
|
+
async ({ items: S, startIndex: v }) => {
|
|
5664
|
+
const P = je(a.listStyle, S, a.autoModeThreshold), x = f({ style: P, count: S.length }), E = {
|
|
5661
5665
|
...a,
|
|
5662
5666
|
listStyle: P,
|
|
5663
5667
|
responseFormat: a.responseFormat ?? Wh
|
|
5664
5668
|
};
|
|
5665
5669
|
try {
|
|
5666
|
-
const O = await M(() => be(
|
|
5670
|
+
const O = await M(() => be(S, x, E), {
|
|
5667
5671
|
label: "filter:batch",
|
|
5668
5672
|
config: a,
|
|
5669
5673
|
onProgress: L(a.onProgress, "batch")
|
|
5670
5674
|
});
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
}),
|
|
5675
|
+
S.forEach((R, j) => {
|
|
5676
|
+
h[v + j] = O[j]?.toLowerCase().trim() === "yes";
|
|
5677
|
+
}), b(S.length);
|
|
5674
5678
|
} catch (O) {
|
|
5675
5679
|
if (O.name === "AbortError" || a?.abortSignal?.aborted || u === z.strict) throw O;
|
|
5676
|
-
c.error(O, { startIndex:
|
|
5677
|
-
for (let R = 0; R <
|
|
5678
|
-
|
|
5680
|
+
c.error(O, { startIndex: v, itemCount: S.length });
|
|
5681
|
+
for (let R = 0; R < S.length; R++)
|
|
5682
|
+
h[v + R] = !1;
|
|
5679
5683
|
}
|
|
5680
5684
|
},
|
|
5681
5685
|
{
|
|
@@ -5684,14 +5688,14 @@ Process exactly ${S} items from the XML list below and return ${S} yes/no decisi
|
|
|
5684
5688
|
abortSignal: a.abortSignal
|
|
5685
5689
|
}
|
|
5686
5690
|
);
|
|
5687
|
-
const g = t.filter((
|
|
5691
|
+
const g = t.filter((S, v) => h[v]);
|
|
5688
5692
|
c.progress({
|
|
5689
5693
|
event: W.complete,
|
|
5690
5694
|
totalItems: t.length,
|
|
5691
|
-
processedItems:
|
|
5695
|
+
processedItems: b.count
|
|
5692
5696
|
});
|
|
5693
|
-
const
|
|
5694
|
-
return c.emit({ event: k.output, value: g }), c.complete(
|
|
5697
|
+
const m = h.some((S) => S === void 0) ? T.partial : T.success, w = { inputCount: t.length, outputCount: g.length, outcome: m };
|
|
5698
|
+
return c.emit({ event: k.output, value: g }), c.complete(w), g;
|
|
5695
5699
|
};
|
|
5696
5700
|
Zi.knownTexts = ["guidance"];
|
|
5697
5701
|
const Wr = {
|
|
@@ -5719,10 +5723,10 @@ const Wr = {
|
|
|
5719
5723
|
const { maxParallel: c, errorPosture: l } = await q(i, {
|
|
5720
5724
|
maxParallel: 3,
|
|
5721
5725
|
errorPosture: z.resilient
|
|
5722
|
-
}), u = ({ style: g, count:
|
|
5723
|
-
const
|
|
5726
|
+
}), u = ({ style: g, count: m }) => {
|
|
5727
|
+
const w = o ? `
|
|
5724
5728
|
|
|
5725
|
-
${o}` : "",
|
|
5729
|
+
${o}` : "", S = `From the list below, identify and return the SINGLE item that BEST matches the search criteria.
|
|
5726
5730
|
|
|
5727
5731
|
${$(s, { tag: "search-criteria" })}
|
|
5728
5732
|
|
|
@@ -5731,31 +5735,31 @@ IMPORTANT:
|
|
|
5731
5735
|
- Choose the BEST match, not just any match
|
|
5732
5736
|
- Return the complete original item text, unchanged
|
|
5733
5737
|
- If NO items match the criteria, return an empty string
|
|
5734
|
-
- Return ONLY ONE item, even if multiple items match${
|
|
5735
|
-
return g === ue.NEWLINE ? `${
|
|
5738
|
+
- Return ONLY ONE item, even if multiple items match${w}`;
|
|
5739
|
+
return g === ue.NEWLINE ? `${S}
|
|
5736
5740
|
|
|
5737
|
-
Process exactly ${
|
|
5741
|
+
Process exactly ${m} items from the list below and return the single best match.` : `${S}
|
|
5738
5742
|
|
|
5739
|
-
Process exactly ${
|
|
5743
|
+
Process exactly ${m} items from the XML list below and return the single best match.`;
|
|
5740
5744
|
}, p = [];
|
|
5741
5745
|
let d = !1;
|
|
5742
|
-
const
|
|
5746
|
+
const h = await Ae(t, i), y = a.batch(t.length), b = h;
|
|
5743
5747
|
a.progress({
|
|
5744
5748
|
event: W.start,
|
|
5745
5749
|
totalItems: t.length,
|
|
5746
|
-
totalBatches:
|
|
5750
|
+
totalBatches: b.length
|
|
5747
5751
|
});
|
|
5748
|
-
for (let g = 0; g <
|
|
5749
|
-
const
|
|
5752
|
+
for (let g = 0; g < b.length && !d; g += c) {
|
|
5753
|
+
const m = b.slice(g, g + c);
|
|
5750
5754
|
await Q(
|
|
5751
|
-
|
|
5752
|
-
async ({ items:
|
|
5753
|
-
const
|
|
5755
|
+
m,
|
|
5756
|
+
async ({ items: w, startIndex: S }) => {
|
|
5757
|
+
const v = je(i.listStyle, w, i.autoModeThreshold);
|
|
5754
5758
|
try {
|
|
5755
5759
|
const P = await M(
|
|
5756
|
-
() => be(
|
|
5760
|
+
() => be(w, u({ style: v, count: w.length }), {
|
|
5757
5761
|
...i,
|
|
5758
|
-
listStyle:
|
|
5762
|
+
listStyle: v,
|
|
5759
5763
|
responseFormat: i.responseFormat || Vh
|
|
5760
5764
|
}),
|
|
5761
5765
|
{
|
|
@@ -5765,13 +5769,13 @@ Process exactly ${h} items from the XML list below and return the single best ma
|
|
|
5765
5769
|
}
|
|
5766
5770
|
), x = Array.isArray(P) && P[0];
|
|
5767
5771
|
if (x) {
|
|
5768
|
-
const E = t.findIndex((R) => R === x), O = E !== -1 ? E :
|
|
5772
|
+
const E = t.findIndex((R) => R === x), O = E !== -1 ? E : S;
|
|
5769
5773
|
p.push({ result: x, index: O });
|
|
5770
5774
|
}
|
|
5771
|
-
y(
|
|
5775
|
+
y(w.length);
|
|
5772
5776
|
} catch (P) {
|
|
5773
|
-
if (a.error(P, { startIndex:
|
|
5774
|
-
ne(`find batch at index ${
|
|
5777
|
+
if (a.error(P, { startIndex: S, itemCount: w.length }), l === z.strict) throw P;
|
|
5778
|
+
ne(`find batch at index ${S} failed: ${P.message}`);
|
|
5775
5779
|
}
|
|
5776
5780
|
},
|
|
5777
5781
|
{
|
|
@@ -5788,9 +5792,9 @@ Process exactly ${h} items from the XML list below and return the single best ma
|
|
|
5788
5792
|
found: p.length > 0
|
|
5789
5793
|
}), p.length > 0) {
|
|
5790
5794
|
const g = p.reduce(
|
|
5791
|
-
(
|
|
5792
|
-
),
|
|
5793
|
-
return a.emit({ event: k.output, value: g.result }), a.complete(
|
|
5795
|
+
(w, S) => S.index < w.index ? S : w
|
|
5796
|
+
), m = { found: !0, totalItems: t.length, outcome: T.success };
|
|
5797
|
+
return a.emit({ event: k.output, value: g.result }), a.complete(m), g.result;
|
|
5794
5798
|
}
|
|
5795
5799
|
const f = { found: !1, totalItems: t.length, outcome: T.success };
|
|
5796
5800
|
return a.emit({ event: k.output, value: "" }), a.complete(f), "";
|
|
@@ -5825,8 +5829,8 @@ const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn =
|
|
|
5825
5829
|
iterations: l,
|
|
5826
5830
|
criteria: t
|
|
5827
5831
|
});
|
|
5828
|
-
const d = async (
|
|
5829
|
-
const P = ef({ description: r },
|
|
5832
|
+
const d = async (v) => {
|
|
5833
|
+
const P = ef({ description: r }, v);
|
|
5830
5834
|
if (Array.isArray(P))
|
|
5831
5835
|
return P;
|
|
5832
5836
|
const x = s ? `${P}
|
|
@@ -5839,8 +5843,8 @@ ${s}` : P, E = await M(
|
|
|
5839
5843
|
}
|
|
5840
5844
|
), O = E?.items || E;
|
|
5841
5845
|
return Array.isArray(O) ? O.filter(Boolean) : [];
|
|
5842
|
-
},
|
|
5843
|
-
const x = Ce(a)(
|
|
5846
|
+
}, h = async (v, P) => {
|
|
5847
|
+
const x = Ce(a)(v);
|
|
5844
5848
|
let E = [], O = [], R = 0;
|
|
5845
5849
|
const j = i.batch(x.length);
|
|
5846
5850
|
for (const F of x) {
|
|
@@ -5872,40 +5876,40 @@ ${s}` : P, E = await M(
|
|
|
5872
5876
|
bottom: u ? O : [],
|
|
5873
5877
|
selected: /* @__PURE__ */ new Set([...E, ...u ? O : []])
|
|
5874
5878
|
};
|
|
5875
|
-
}, y = [],
|
|
5879
|
+
}, y = [], b = [];
|
|
5876
5880
|
let f = p;
|
|
5877
|
-
for (let
|
|
5881
|
+
for (let v = 0; v < l && f.length > 0; v++) {
|
|
5878
5882
|
i.emit({
|
|
5879
5883
|
event: k.step,
|
|
5880
5884
|
stepName: "extracting-extremes",
|
|
5881
|
-
iteration:
|
|
5885
|
+
iteration: v + 1,
|
|
5882
5886
|
totalIterations: l,
|
|
5883
5887
|
remainingItems: f.length
|
|
5884
5888
|
});
|
|
5885
|
-
const { top: P, bottom: x, selected: E } = await
|
|
5886
|
-
y.push(...P), u &&
|
|
5889
|
+
const { top: P, bottom: x, selected: E } = await h(f, v + 1);
|
|
5890
|
+
y.push(...P), u && b.unshift(...x), f = f.filter((O) => !E.has(O)), i.emit({
|
|
5887
5891
|
event: k.step,
|
|
5888
5892
|
stepName: "iteration-complete",
|
|
5889
|
-
iteration:
|
|
5893
|
+
iteration: v + 1,
|
|
5890
5894
|
totalIterations: l,
|
|
5891
5895
|
topCount: y.length,
|
|
5892
|
-
bottomCount:
|
|
5896
|
+
bottomCount: b.length,
|
|
5893
5897
|
remainingItems: f.length
|
|
5894
5898
|
});
|
|
5895
5899
|
}
|
|
5896
|
-
const g = u ? [...y, ...f, ...
|
|
5897
|
-
for (const
|
|
5898
|
-
|
|
5899
|
-
for (const
|
|
5900
|
-
|
|
5900
|
+
const g = u ? [...y, ...f, ...b] : [...y, ...f], m = new Set(p), w = /* @__PURE__ */ new Set(), S = [];
|
|
5901
|
+
for (const v of g)
|
|
5902
|
+
m.has(v) && !w.has(v) && (w.add(v), S.push(v));
|
|
5903
|
+
for (const v of p)
|
|
5904
|
+
w.has(v) || S.push(v);
|
|
5901
5905
|
return i.progress({
|
|
5902
5906
|
event: W.complete,
|
|
5903
5907
|
totalItems: p.length,
|
|
5904
5908
|
iterations: l,
|
|
5905
5909
|
topItems: y.length,
|
|
5906
|
-
bottomItems:
|
|
5910
|
+
bottomItems: b.length,
|
|
5907
5911
|
remainingItems: f.length
|
|
5908
|
-
}), i.complete({ outcome: T.success, totalItems: p.length }),
|
|
5912
|
+
}), i.complete({ outcome: T.success, totalItems: p.length }), S;
|
|
5909
5913
|
} catch (d) {
|
|
5910
5914
|
throw i.error(d), d;
|
|
5911
5915
|
}
|
|
@@ -5960,39 +5964,39 @@ async function ta(e, t = {}) {
|
|
|
5960
5964
|
if (r.terms)
|
|
5961
5965
|
p = r.terms.split(",").map((y) => y.trim()).filter(Boolean);
|
|
5962
5966
|
else {
|
|
5963
|
-
const
|
|
5964
|
-
if (
|
|
5967
|
+
const b = fo(n).sentences().out("array");
|
|
5968
|
+
if (b.length === 0)
|
|
5965
5969
|
return i.complete({ outcome: T.success, terms: 0 }), [];
|
|
5966
5970
|
const f = [];
|
|
5967
|
-
for (let P = 0; P <
|
|
5968
|
-
const x =
|
|
5971
|
+
for (let P = 0; P < b.length; P += l - u) {
|
|
5972
|
+
const x = b.slice(P, P + l);
|
|
5969
5973
|
x.length > 0 && f.push(x.join(" "));
|
|
5970
5974
|
}
|
|
5971
|
-
const g = i.batch(f.length),
|
|
5975
|
+
const g = i.batch(f.length), w = `Extract every proper noun and every term that a general reader would need to look up. Over-extract — the list will be filtered later.
|
|
5972
5976
|
|
|
5973
5977
|
Return a "terms" object containing an array of the extracted terms.${s ? `
|
|
5974
5978
|
|
|
5975
|
-
${s}` : ""}`,
|
|
5979
|
+
${s}` : ""}`, S = await Oe(f, w, {
|
|
5976
5980
|
...o,
|
|
5977
5981
|
batchSize: o.batchSize ?? 1,
|
|
5978
5982
|
responseFormat: rf,
|
|
5979
5983
|
onProgress: L(o.onProgress, "glossary:extract")
|
|
5980
5984
|
});
|
|
5981
5985
|
g(f.length);
|
|
5982
|
-
const
|
|
5983
|
-
|
|
5986
|
+
const v = /* @__PURE__ */ new Set();
|
|
5987
|
+
S.forEach((P) => {
|
|
5984
5988
|
P && P.terms && Array.isArray(P.terms) && P.terms.forEach((x) => {
|
|
5985
|
-
x && typeof x == "string" &&
|
|
5989
|
+
x && typeof x == "string" && v.add(x);
|
|
5986
5990
|
});
|
|
5987
|
-
}), p = Array.from(
|
|
5991
|
+
}), p = Array.from(v);
|
|
5988
5992
|
}
|
|
5989
5993
|
if (i.emit({ event: k.phase, phase: "extracted", terms: p }), p.length === 0)
|
|
5990
5994
|
return i.complete({ outcome: T.success, terms: 0 }), [];
|
|
5991
|
-
const
|
|
5995
|
+
const h = (await Bn(p, c, {
|
|
5992
5996
|
...o,
|
|
5993
5997
|
onProgress: L(o.onProgress, "glossary:sort")
|
|
5994
5998
|
})).slice(0, a);
|
|
5995
|
-
return i.complete({ outcome: T.success, terms:
|
|
5999
|
+
return i.complete({ outcome: T.success, terms: h.length }), h;
|
|
5996
6000
|
} catch (p) {
|
|
5997
6001
|
throw i.error(p), p;
|
|
5998
6002
|
}
|
|
@@ -6065,7 +6069,7 @@ async function na(e, t, n) {
|
|
|
6065
6069
|
granularity: J(sf, ["guidance", "topN"]),
|
|
6066
6070
|
maxParallel: 3,
|
|
6067
6071
|
errorPosture: z.resilient
|
|
6068
|
-
}), { categoryPrompt: d, listStyle:
|
|
6072
|
+
}), { categoryPrompt: d, listStyle: h, autoModeThreshold: y, now: b } = i;
|
|
6069
6073
|
let f;
|
|
6070
6074
|
if (s.categories)
|
|
6071
6075
|
f = Hr(s.categories);
|
|
@@ -6082,7 +6086,7 @@ async function na(e, t, n) {
|
|
|
6082
6086
|
), F = await Ie(e, j, {
|
|
6083
6087
|
...i,
|
|
6084
6088
|
initial: "",
|
|
6085
|
-
now:
|
|
6089
|
+
now: b,
|
|
6086
6090
|
onProgress: L(i.onProgress, "reduce:category-discovery")
|
|
6087
6091
|
});
|
|
6088
6092
|
f = Hr(F);
|
|
@@ -6094,13 +6098,13 @@ async function na(e, t, n) {
|
|
|
6094
6098
|
categories: f,
|
|
6095
6099
|
categoryCount: f.length
|
|
6096
6100
|
});
|
|
6097
|
-
const g = [],
|
|
6101
|
+
const g = [], m = af(f), w = o ? (j) => `${m(j)}
|
|
6098
6102
|
|
|
6099
|
-
${o}` :
|
|
6103
|
+
${o}` : m, v = await Ae(e, i), P = a.batch(e.length);
|
|
6100
6104
|
await Q(
|
|
6101
|
-
|
|
6105
|
+
v,
|
|
6102
6106
|
async ({ items: j, startIndex: F }) => {
|
|
6103
|
-
const V = je(
|
|
6107
|
+
const V = je(h, j, y);
|
|
6104
6108
|
try {
|
|
6105
6109
|
const Y = {
|
|
6106
6110
|
...i,
|
|
@@ -6108,7 +6112,7 @@ ${o}` : h, S = await Ae(e, i), P = a.batch(e.length);
|
|
|
6108
6112
|
}, H = await M(
|
|
6109
6113
|
() => be(
|
|
6110
6114
|
j,
|
|
6111
|
-
|
|
6115
|
+
w({ style: V, count: j.length }),
|
|
6112
6116
|
Y
|
|
6113
6117
|
),
|
|
6114
6118
|
{
|
|
@@ -6280,14 +6284,14 @@ async function oa(e, t, n) {
|
|
|
6280
6284
|
const p = sa(e, c, l);
|
|
6281
6285
|
if (p.length === 0)
|
|
6282
6286
|
return i.complete({ outcome: T.success, combinations: 0 }), {};
|
|
6283
|
-
const d = {},
|
|
6287
|
+
const d = {}, h = i.batch(p.length), y = await Q(
|
|
6284
6288
|
p,
|
|
6285
|
-
async (
|
|
6286
|
-
const f = await jf(
|
|
6289
|
+
async (b) => {
|
|
6290
|
+
const f = await jf(b, r, s, {
|
|
6287
6291
|
...o,
|
|
6288
6292
|
onProgress: L(o.onProgress, "combo")
|
|
6289
6293
|
});
|
|
6290
|
-
return
|
|
6294
|
+
return h(1), f;
|
|
6291
6295
|
},
|
|
6292
6296
|
{
|
|
6293
6297
|
maxParallel: u,
|
|
@@ -6296,8 +6300,8 @@ async function oa(e, t, n) {
|
|
|
6296
6300
|
abortSignal: o.abortSignal
|
|
6297
6301
|
}
|
|
6298
6302
|
);
|
|
6299
|
-
for (const
|
|
6300
|
-
|
|
6303
|
+
for (const b of y)
|
|
6304
|
+
b?.key !== void 0 && (d[b.key] = b.intersection);
|
|
6301
6305
|
if (a && Object.keys(d).length > 0) {
|
|
6302
6306
|
const f = (await Rf(d, o)).intersections || d;
|
|
6303
6307
|
return i.complete({ outcome: T.success, combinations: p.length }), f;
|
|
@@ -6363,8 +6367,8 @@ ${s}` : r, i = A("list:generate", {
|
|
|
6363
6367
|
...n
|
|
6364
6368
|
}), a = [], c = {};
|
|
6365
6369
|
let l = !1;
|
|
6366
|
-
const { shouldSkip: u = Jf, shouldStop: p = Kf } = i, { queryLimit: d = 5, timeoutMs:
|
|
6367
|
-
let
|
|
6370
|
+
const { shouldSkip: u = Jf, shouldStop: p = Kf } = i, { queryLimit: d = 5, timeoutMs: h = zf } = i, y = /* @__PURE__ */ new Date();
|
|
6371
|
+
let b = 0;
|
|
6368
6372
|
for (; !l; ) {
|
|
6369
6373
|
const f = ri(o, {
|
|
6370
6374
|
...i,
|
|
@@ -6372,49 +6376,49 @@ ${s}` : r, i = A("list:generate", {
|
|
|
6372
6376
|
});
|
|
6373
6377
|
let g = [];
|
|
6374
6378
|
try {
|
|
6375
|
-
const
|
|
6379
|
+
const S = await M(
|
|
6376
6380
|
() => _(f, { ...i, ...aa() }),
|
|
6377
6381
|
{
|
|
6378
6382
|
label: "list-generate",
|
|
6379
6383
|
config: i
|
|
6380
6384
|
}
|
|
6381
|
-
),
|
|
6382
|
-
g = Array.isArray(
|
|
6383
|
-
} catch (
|
|
6384
|
-
if (
|
|
6385
|
-
throw
|
|
6385
|
+
), v = S?.items || S;
|
|
6386
|
+
g = Array.isArray(v) ? v.filter(Boolean) : [];
|
|
6387
|
+
} catch (S) {
|
|
6388
|
+
if (S.name === "AbortError")
|
|
6389
|
+
throw S;
|
|
6386
6390
|
ne(
|
|
6387
|
-
`Generate list [error]: ${
|
|
6391
|
+
`Generate list [error]: ${S.message} ${f.slice(0, 100).replace(`
|
|
6388
6392
|
`, "\\n")}`
|
|
6389
6393
|
), l = !0;
|
|
6390
6394
|
break;
|
|
6391
6395
|
}
|
|
6392
|
-
const
|
|
6393
|
-
|
|
6394
|
-
for (const
|
|
6395
|
-
const
|
|
6396
|
-
result:
|
|
6396
|
+
const m = g.filter((S) => !(S in c));
|
|
6397
|
+
b += 1;
|
|
6398
|
+
for (const S of m) {
|
|
6399
|
+
const v = {
|
|
6400
|
+
result: S,
|
|
6397
6401
|
resultsAll: a,
|
|
6398
6402
|
resultsNew: g,
|
|
6399
|
-
queryCount:
|
|
6403
|
+
queryCount: b,
|
|
6400
6404
|
startTime: y,
|
|
6401
6405
|
queryLimit: d,
|
|
6402
|
-
timeoutMs:
|
|
6406
|
+
timeoutMs: h
|
|
6403
6407
|
};
|
|
6404
|
-
if (await p(
|
|
6408
|
+
if (await p(v)) {
|
|
6405
6409
|
l = !0;
|
|
6406
6410
|
break;
|
|
6407
6411
|
}
|
|
6408
|
-
await u(
|
|
6412
|
+
await u(v) || (c[S] = !0, a.push(S), yield S);
|
|
6409
6413
|
}
|
|
6410
6414
|
await p({
|
|
6411
6415
|
result: void 0,
|
|
6412
6416
|
resultsAll: a,
|
|
6413
6417
|
resultsNew: g,
|
|
6414
|
-
queryCount:
|
|
6418
|
+
queryCount: b,
|
|
6415
6419
|
startTime: y,
|
|
6416
6420
|
queryLimit: d,
|
|
6417
|
-
timeoutMs:
|
|
6421
|
+
timeoutMs: h
|
|
6418
6422
|
}) && (l = !0);
|
|
6419
6423
|
}
|
|
6420
6424
|
};
|
|
@@ -6434,16 +6438,16 @@ ${r}` : n, c = await M(
|
|
|
6434
6438
|
if (i && u.length > 0) {
|
|
6435
6439
|
o.emit({ event: k.step, stepName: "transform", itemCount: u.length });
|
|
6436
6440
|
const p = o.batch(u.length), d = [];
|
|
6437
|
-
for (const
|
|
6438
|
-
const y = Vf(
|
|
6441
|
+
for (const h of u) {
|
|
6442
|
+
const y = Vf(h, i), b = await M(() => _(y, s), {
|
|
6439
6443
|
label: "list-transform",
|
|
6440
6444
|
config: s
|
|
6441
6445
|
});
|
|
6442
6446
|
try {
|
|
6443
|
-
const f = JSON.parse(
|
|
6447
|
+
const f = JSON.parse(b);
|
|
6444
6448
|
d.push(f);
|
|
6445
6449
|
} catch (f) {
|
|
6446
|
-
ne(`list-transform JSON.parse failed, keeping original item: ${f.message}`), d.push(
|
|
6450
|
+
ne(`list-transform JSON.parse failed, keeping original item: ${f.message}`), d.push(h);
|
|
6447
6451
|
}
|
|
6448
6452
|
p(1);
|
|
6449
6453
|
}
|
|
@@ -6555,14 +6559,14 @@ ${o}` : r, a = s.spec || await qn(i, n);
|
|
|
6555
6559
|
return mg(e, a, n);
|
|
6556
6560
|
}
|
|
6557
6561
|
async function rs(e, t, n, r) {
|
|
6558
|
-
const { maxParallel: s, errorPosture: o, onProgress: i, logger: a, anchoring: c, _providedAnchors: l } = r, p = await Ae(e, n), d = new Array(e.length).fill(void 0),
|
|
6559
|
-
|
|
6562
|
+
const { maxParallel: s, errorPosture: o, onProgress: i, logger: a, anchoring: c, _providedAnchors: l } = r, p = await Ae(e, n), d = new Array(e.length).fill(void 0), h = I("score", i, r), y = h.batch(e.length);
|
|
6563
|
+
h.progress({
|
|
6560
6564
|
event: W.start,
|
|
6561
6565
|
totalItems: e.length,
|
|
6562
6566
|
totalBatches: p.length,
|
|
6563
6567
|
maxParallel: s
|
|
6564
6568
|
});
|
|
6565
|
-
let
|
|
6569
|
+
let b = l || "";
|
|
6566
6570
|
if (!l && p.length > 0) {
|
|
6567
6571
|
const f = p[0];
|
|
6568
6572
|
try {
|
|
@@ -6571,15 +6575,15 @@ async function rs(e, t, n, r) {
|
|
|
6571
6575
|
config: r,
|
|
6572
6576
|
onProgress: L(i, "batch")
|
|
6573
6577
|
});
|
|
6574
|
-
ns(g, f.items.length).forEach((
|
|
6575
|
-
d[f.startIndex +
|
|
6576
|
-
}),
|
|
6578
|
+
ns(g, f.items.length).forEach((m, w) => {
|
|
6579
|
+
d[f.startIndex + w] = m;
|
|
6580
|
+
}), b = dg(f.items, g, c), h.emit({
|
|
6577
6581
|
event: k.phase,
|
|
6578
6582
|
phase: "anchors-established",
|
|
6579
|
-
anchors:
|
|
6583
|
+
anchors: b
|
|
6580
6584
|
});
|
|
6581
6585
|
} catch (g) {
|
|
6582
|
-
if (
|
|
6586
|
+
if (h.error(g, { batchIndex: 0, itemCount: f.items.length }), o === z.strict) throw g;
|
|
6583
6587
|
a?.error && a.error("Score batch 0 failed", {
|
|
6584
6588
|
error: g.message,
|
|
6585
6589
|
itemCount: f.items.length
|
|
@@ -6588,24 +6592,24 @@ async function rs(e, t, n, r) {
|
|
|
6588
6592
|
y(f.items.length);
|
|
6589
6593
|
}
|
|
6590
6594
|
if (p.length > 1) {
|
|
6591
|
-
const f =
|
|
6592
|
-
${
|
|
6595
|
+
const f = b ? `${t}
|
|
6596
|
+
${b}` : t;
|
|
6593
6597
|
await Q(
|
|
6594
6598
|
p.slice(1),
|
|
6595
|
-
async ({ items: g, startIndex:
|
|
6599
|
+
async ({ items: g, startIndex: m }) => {
|
|
6596
6600
|
try {
|
|
6597
|
-
const
|
|
6601
|
+
const w = await M(() => be(g, f, n), {
|
|
6598
6602
|
label: "score:batch",
|
|
6599
6603
|
config: r,
|
|
6600
6604
|
onProgress: L(i, "batch")
|
|
6601
6605
|
});
|
|
6602
|
-
ns(
|
|
6603
|
-
d[
|
|
6606
|
+
ns(w, g.length).forEach((S, v) => {
|
|
6607
|
+
d[m + v] = S;
|
|
6604
6608
|
});
|
|
6605
|
-
} catch (
|
|
6606
|
-
if (
|
|
6609
|
+
} catch (w) {
|
|
6610
|
+
if (h.error(w, { itemCount: g.length }), o === z.strict) throw w;
|
|
6607
6611
|
a?.error && a.error("Score batch failed", {
|
|
6608
|
-
error:
|
|
6612
|
+
error: w.message,
|
|
6609
6613
|
itemCount: g.length
|
|
6610
6614
|
});
|
|
6611
6615
|
}
|
|
@@ -6614,7 +6618,7 @@ ${w}` : t;
|
|
|
6614
6618
|
{ maxParallel: s, errorPosture: o, abortSignal: r.abortSignal }
|
|
6615
6619
|
);
|
|
6616
6620
|
}
|
|
6617
|
-
return
|
|
6621
|
+
return h.progress({
|
|
6618
6622
|
event: W.complete,
|
|
6619
6623
|
totalItems: e.length,
|
|
6620
6624
|
processedItems: y.count
|
|
@@ -6624,7 +6628,7 @@ async function ke(e, t, n) {
|
|
|
6624
6628
|
[t, n] = K(t, n, ["spec", "anchors"]);
|
|
6625
6629
|
const { text: r, known: s, context: o } = N(t, ["spec", "anchors"]), { now: i } = n, a = A(ts, n), c = I(ts, a.onProgress, a);
|
|
6626
6630
|
c.start(), c.emit({ event: k.input, value: e });
|
|
6627
|
-
const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring:
|
|
6631
|
+
const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring: h } = await q(
|
|
6628
6632
|
a,
|
|
6629
6633
|
{
|
|
6630
6634
|
maxParallel: 3,
|
|
@@ -6637,38 +6641,38 @@ async function ke(e, t, n) {
|
|
|
6637
6641
|
c.emit({ event: k.phase, phase: "generating-specification" });
|
|
6638
6642
|
const y = o ? `${r}
|
|
6639
6643
|
|
|
6640
|
-
${o}` : r,
|
|
6641
|
-
c.emit({ event: k.phase, phase: "scoring-items", specification:
|
|
6644
|
+
${o}` : r, b = s.spec || await qn(y, a);
|
|
6645
|
+
c.emit({ event: k.phase, phase: "scoring-items", specification: b });
|
|
6642
6646
|
const f = fg(
|
|
6643
|
-
|
|
6647
|
+
b,
|
|
6644
6648
|
"Return ONLY the numeric score for each item according to the specification range."
|
|
6645
6649
|
), g = {
|
|
6646
6650
|
...a,
|
|
6647
6651
|
responseFormat: pg,
|
|
6648
6652
|
temperature: p
|
|
6649
|
-
},
|
|
6653
|
+
}, m = {
|
|
6650
6654
|
...a,
|
|
6651
6655
|
maxParallel: l,
|
|
6652
6656
|
maxAttempts: u,
|
|
6653
6657
|
errorPosture: d,
|
|
6654
6658
|
now: i,
|
|
6655
|
-
anchoring:
|
|
6659
|
+
anchoring: h,
|
|
6656
6660
|
_providedAnchors: s.anchors
|
|
6657
|
-
},
|
|
6661
|
+
}, w = await rs(e, f, g, m);
|
|
6658
6662
|
for (let x = 1; x < u; x += 1) {
|
|
6659
6663
|
const E = [], O = [];
|
|
6660
|
-
if (
|
|
6664
|
+
if (w.forEach((j, F) => {
|
|
6661
6665
|
j == null && (E.push(F), O.push(e[F]));
|
|
6662
6666
|
}), O.length === 0) break;
|
|
6663
6667
|
(await rs(O, f, g, {
|
|
6664
|
-
...
|
|
6668
|
+
...m,
|
|
6665
6669
|
now: /* @__PURE__ */ new Date()
|
|
6666
6670
|
})).forEach((j, F) => {
|
|
6667
|
-
j !== void 0 && (
|
|
6671
|
+
j !== void 0 && (w[E[F]] = j);
|
|
6668
6672
|
});
|
|
6669
6673
|
}
|
|
6670
|
-
const
|
|
6671
|
-
return c.complete({ totalItems:
|
|
6674
|
+
const S = w.filter((x) => x !== void 0).length, v = w.length - S, P = v > 0 ? T.partial : T.success;
|
|
6675
|
+
return c.complete({ totalItems: w.length, successCount: S, failedItems: v, outcome: P }), w;
|
|
6672
6676
|
}
|
|
6673
6677
|
function fg(e, t = "") {
|
|
6674
6678
|
const n = `Apply this score specification to evaluate each item:
|
|
@@ -6754,7 +6758,7 @@ function $g(e, t, n, r) {
|
|
|
6754
6758
|
let o;
|
|
6755
6759
|
if (r === "rich") {
|
|
6756
6760
|
const c = Math.min(3, Math.ceil(s.length / 4)), l = Math.floor(s.length / 2), u = s.slice(Math.max(0, l - 1), l + 1), p = [...s.slice(0, c), ...u, ...s.slice(-c)], d = /* @__PURE__ */ new Set();
|
|
6757
|
-
o = p.filter((
|
|
6761
|
+
o = p.filter((h) => d.has(h.item) ? !1 : (d.add(h.item), !0));
|
|
6758
6762
|
} else {
|
|
6759
6763
|
const c = Math.min(2, Math.ceil(s.length / 3));
|
|
6760
6764
|
o = [...s.slice(0, c), ...s.slice(-c)];
|
|
@@ -6781,50 +6785,50 @@ ${s}` : os(e, t, n, r), a = xg(e.length, t.length), c = C("score_matrix_result",
|
|
|
6781
6785
|
return Pg(l?.matrix, e.length, t.length);
|
|
6782
6786
|
}
|
|
6783
6787
|
async function as(e, t, n, r, s, o) {
|
|
6784
|
-
const { maxParallel: i, errorPosture: a, onProgress: c, anchoring: l, _providedAnchors: u } = o, p = await Ae(e, { ...s, outputRatio: 4 }), d = Array.from({ length: e.length }),
|
|
6785
|
-
|
|
6788
|
+
const { maxParallel: i, errorPosture: a, onProgress: c, anchoring: l, _providedAnchors: u } = o, p = await Ae(e, { ...s, outputRatio: 4 }), d = Array.from({ length: e.length }), h = I("score-matrix", c, o), y = h.batch(e.length);
|
|
6789
|
+
h.progress({
|
|
6786
6790
|
event: W.start,
|
|
6787
6791
|
totalItems: e.length,
|
|
6788
6792
|
totalBatches: p.length,
|
|
6789
6793
|
maxParallel: i
|
|
6790
6794
|
});
|
|
6791
|
-
let
|
|
6795
|
+
let b = u || "", f = 0;
|
|
6792
6796
|
if (!u && p.length > 0) {
|
|
6793
6797
|
const g = p[0];
|
|
6794
6798
|
try {
|
|
6795
|
-
const
|
|
6799
|
+
const m = await M(
|
|
6796
6800
|
() => is(g.items, t, n, r, "", s),
|
|
6797
6801
|
{ label: "score-matrix:batch", config: o, onProgress: L(c, "batch") }
|
|
6798
6802
|
);
|
|
6799
|
-
|
|
6800
|
-
d[g.startIndex +
|
|
6801
|
-
}),
|
|
6802
|
-
} catch (
|
|
6803
|
-
if (
|
|
6803
|
+
m.forEach((w, S) => {
|
|
6804
|
+
d[g.startIndex + S] = w;
|
|
6805
|
+
}), b = $g(g.items, m, t, l), h.emit({ event: k.phase, phase: "anchors-established" });
|
|
6806
|
+
} catch (m) {
|
|
6807
|
+
if (h.error(m, { batchIndex: 0, itemCount: g.items.length }), a === z.strict) throw m;
|
|
6804
6808
|
}
|
|
6805
6809
|
y(g.items.length), f = 1;
|
|
6806
6810
|
}
|
|
6807
6811
|
return f < p.length && await Q(
|
|
6808
6812
|
p.slice(f),
|
|
6809
|
-
async ({ items: g, startIndex:
|
|
6813
|
+
async ({ items: g, startIndex: m }) => {
|
|
6810
6814
|
try {
|
|
6811
6815
|
(await M(
|
|
6812
|
-
() => is(g, t, n, r,
|
|
6816
|
+
() => is(g, t, n, r, b, s),
|
|
6813
6817
|
{
|
|
6814
6818
|
label: "score-matrix:batch",
|
|
6815
6819
|
config: o,
|
|
6816
6820
|
onProgress: L(c, "batch")
|
|
6817
6821
|
}
|
|
6818
|
-
)).forEach((
|
|
6819
|
-
d[
|
|
6822
|
+
)).forEach((S, v) => {
|
|
6823
|
+
d[m + v] = S;
|
|
6820
6824
|
});
|
|
6821
|
-
} catch (
|
|
6822
|
-
if (
|
|
6825
|
+
} catch (w) {
|
|
6826
|
+
if (h.error(w, { itemCount: g.length }), a === z.strict) throw w;
|
|
6823
6827
|
}
|
|
6824
6828
|
y(g.length);
|
|
6825
6829
|
},
|
|
6826
6830
|
{ maxParallel: i, errorPosture: a, abortSignal: o.abortSignal }
|
|
6827
|
-
),
|
|
6831
|
+
), h.progress({
|
|
6828
6832
|
event: W.complete,
|
|
6829
6833
|
totalItems: e.length,
|
|
6830
6834
|
processedItems: y.count
|
|
@@ -6845,7 +6849,7 @@ async function ua(e, t, n, r) {
|
|
|
6845
6849
|
${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
6846
6850
|
if (u.start({ dimensions: c.length }), u.emit({ event: k.input, value: e }), e.length === 0)
|
|
6847
6851
|
return u.complete({ rows: 0, columns: c.length, outcome: T.success }), { matrix: [], dimensions: c.map((x) => x.dimension), scale: Ve };
|
|
6848
|
-
const { maxParallel: p, maxAttempts: d, temperature:
|
|
6852
|
+
const { maxParallel: p, maxAttempts: d, temperature: h, errorPosture: y, anchoring: b } = await q(
|
|
6849
6853
|
l,
|
|
6850
6854
|
{
|
|
6851
6855
|
maxParallel: 3,
|
|
@@ -6854,16 +6858,16 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6854
6858
|
errorPosture: z.resilient,
|
|
6855
6859
|
anchoring: J(Sg)
|
|
6856
6860
|
}
|
|
6857
|
-
), f = { ...l, temperature:
|
|
6861
|
+
), f = { ...l, temperature: h }, g = {
|
|
6858
6862
|
...l,
|
|
6859
6863
|
maxParallel: p,
|
|
6860
6864
|
maxAttempts: d,
|
|
6861
6865
|
errorPosture: y,
|
|
6862
|
-
anchoring:
|
|
6866
|
+
anchoring: b,
|
|
6863
6867
|
_providedAnchors: o.anchors
|
|
6864
6868
|
};
|
|
6865
6869
|
u.emit({ event: k.phase, phase: "scoring-matrix" });
|
|
6866
|
-
const
|
|
6870
|
+
const m = await as(
|
|
6867
6871
|
e,
|
|
6868
6872
|
c,
|
|
6869
6873
|
a,
|
|
@@ -6873,7 +6877,7 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6873
6877
|
);
|
|
6874
6878
|
for (let x = 1; x < d; x += 1) {
|
|
6875
6879
|
const E = [], O = [];
|
|
6876
|
-
if (
|
|
6880
|
+
if (m.forEach((j, F) => {
|
|
6877
6881
|
j == null && (E.push(F), O.push(e[F]));
|
|
6878
6882
|
}), O.length === 0) break;
|
|
6879
6883
|
u.emit({
|
|
@@ -6889,17 +6893,17 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6889
6893
|
f,
|
|
6890
6894
|
{ ...g, now: /* @__PURE__ */ new Date() }
|
|
6891
6895
|
)).forEach((j, F) => {
|
|
6892
|
-
j !== void 0 && (
|
|
6896
|
+
j !== void 0 && (m[E[F]] = j);
|
|
6893
6897
|
});
|
|
6894
6898
|
}
|
|
6895
|
-
const
|
|
6899
|
+
const w = m.map(
|
|
6896
6900
|
(x) => x ?? c.map(() => ({ score: Ve.min, rationale: "scoring failed" }))
|
|
6897
|
-
),
|
|
6901
|
+
), S = m.filter((x) => x !== void 0).length, v = m.length - S, P = v > 0 ? T.partial : T.success;
|
|
6898
6902
|
return u.emit({
|
|
6899
6903
|
event: k.output,
|
|
6900
|
-
value: { rows:
|
|
6901
|
-
}), u.complete({ totalItems: e.length, successCount:
|
|
6902
|
-
matrix:
|
|
6904
|
+
value: { rows: w.length, columns: c.length }
|
|
6905
|
+
}), u.complete({ totalItems: e.length, successCount: S, failedItems: v, outcome: P }), {
|
|
6906
|
+
matrix: w,
|
|
6903
6907
|
dimensions: c.map((x) => x.dimension),
|
|
6904
6908
|
scale: Ve
|
|
6905
6909
|
};
|
|
@@ -7017,14 +7021,14 @@ ${a}` : o, p = i.spec || await Fn(u, r);
|
|
|
7017
7021
|
Return only IDs from the available tags list.
|
|
7018
7022
|
Return empty array when no tags apply.`,
|
|
7019
7023
|
l
|
|
7020
|
-
),
|
|
7024
|
+
), h = e.map(
|
|
7021
7025
|
(g) => typeof g == "object" && g !== null ? JSON.stringify(g) : g
|
|
7022
|
-
), y = s.batch(
|
|
7026
|
+
), y = s.batch(h.length), b = {
|
|
7023
7027
|
...r,
|
|
7024
7028
|
responseFormat: C("tags_map_result", Cg),
|
|
7025
7029
|
onProgress: L(r.onProgress, "tags:map")
|
|
7026
|
-
}, f = await Oe(
|
|
7027
|
-
return y(
|
|
7030
|
+
}, f = await Oe(h, d, b);
|
|
7031
|
+
return y(h.length), s.complete({ outcome: T.success }), f;
|
|
7028
7032
|
} catch (o) {
|
|
7029
7033
|
throw s.error(o), o;
|
|
7030
7034
|
}
|
|
@@ -7109,7 +7113,7 @@ async function ha(e, t = {}) {
|
|
|
7109
7113
|
diversity: i
|
|
7110
7114
|
}), d = await Ze(p, {
|
|
7111
7115
|
...n,
|
|
7112
|
-
shouldStop: ({ resultsAll:
|
|
7116
|
+
shouldStop: ({ resultsAll: h }) => h.length >= a,
|
|
7113
7117
|
onProgress: L(n.onProgress, "list:sampling")
|
|
7114
7118
|
});
|
|
7115
7119
|
if (!d || d.length === 0)
|
|
@@ -7144,18 +7148,18 @@ async function zn(e, t = {}) {
|
|
|
7144
7148
|
try {
|
|
7145
7149
|
let l;
|
|
7146
7150
|
if (r.uniqueTerms)
|
|
7147
|
-
l = r.uniqueTerms.split(",").map((
|
|
7151
|
+
l = r.uniqueTerms.split(",").map((h) => h.trim()).filter(Boolean);
|
|
7148
7152
|
else {
|
|
7149
|
-
const
|
|
7150
|
-
|
|
7153
|
+
const h = Bg(n, c), y = i.batch(h.length), f = (await Q(
|
|
7154
|
+
h,
|
|
7151
7155
|
async (g) => {
|
|
7152
|
-
const
|
|
7156
|
+
const m = s ? `
|
|
7153
7157
|
|
|
7154
|
-
${s}` : "",
|
|
7155
|
-
`key words and phrases that would help find documents about: ${g}${
|
|
7158
|
+
${s}` : "", w = await Ze(
|
|
7159
|
+
`key words and phrases that would help find documents about: ${g}${m}`,
|
|
7156
7160
|
{ ...o, onProgress: L(o.onProgress, "list:extract") }
|
|
7157
7161
|
);
|
|
7158
|
-
return y(1),
|
|
7162
|
+
return y(1), w;
|
|
7159
7163
|
},
|
|
7160
7164
|
{
|
|
7161
7165
|
maxParallel: 3,
|
|
@@ -7172,8 +7176,8 @@ ${s}` : "", b = await Ze(
|
|
|
7172
7176
|
l,
|
|
7173
7177
|
"relevance as a search term for finding information (1-10, higher is more important)",
|
|
7174
7178
|
{ ...o, onProgress: L(o.onProgress, "score:rank") }
|
|
7175
|
-
), d = l.map((
|
|
7176
|
-
return i.emit({ event: k.phase, phase: "scored", termsWithScores: d }), i.complete({ outcome: T.success }), d.slice(0, a).map((
|
|
7179
|
+
), d = l.map((h, y) => ({ term: h, score: u[y] ?? 0 })).toSorted((h, y) => y.score - h.score);
|
|
7180
|
+
return i.emit({ event: k.phase, phase: "scored", termsWithScores: d }), i.complete({ outcome: T.success }), d.slice(0, a).map((h) => h.term);
|
|
7177
7181
|
} catch (l) {
|
|
7178
7182
|
throw i.error(l), l;
|
|
7179
7183
|
}
|
|
@@ -7199,17 +7203,17 @@ async function Un({
|
|
|
7199
7203
|
const u = A(ps, i), p = I(ps, u.onProgress, u);
|
|
7200
7204
|
p.start(), p.emit({ event: k.input, value: { speakers: e, topic: a } });
|
|
7201
7205
|
try {
|
|
7202
|
-
const d = r.length > 0 ? r.map((
|
|
7206
|
+
const d = r.length > 0 ? r.map((S) => `${S.time} ${S.name} (${S.id}): ${S.comment}`).join(`
|
|
7203
7207
|
`) : "", y = [
|
|
7204
7208
|
o.customPrompt || "",
|
|
7205
7209
|
d ? $(d, { tag: "conversation-history" }) : "",
|
|
7206
7210
|
a ? $(a, { tag: "topic" }) : ""
|
|
7207
7211
|
].filter(Boolean).join(`
|
|
7208
7212
|
|
|
7209
|
-
`),
|
|
7210
|
-
const x = [
|
|
7211
|
-
|
|
7212
|
-
const E = s.get?.(
|
|
7213
|
+
`), b = e.map((S, v) => {
|
|
7214
|
+
const x = [S.name || `Speaker ${v + 1}`];
|
|
7215
|
+
S.bio && x.push(`Bio: ${S.bio}`), S.agenda && x.push(`Agenda: ${S.agenda}`);
|
|
7216
|
+
const E = s.get?.(S.id) ?? [];
|
|
7213
7217
|
if (E.length > 0) {
|
|
7214
7218
|
const O = E.map((R) => `[${R.time}] ${R.comment}`).join(`
|
|
7215
7219
|
`);
|
|
@@ -7225,11 +7229,11 @@ ${O}`);
|
|
|
7225
7229
|
l
|
|
7226
7230
|
].filter(Boolean).join(`
|
|
7227
7231
|
|
|
7228
|
-
`),
|
|
7232
|
+
`), m = p.batch(e.length), w = await Oe(b, g, {
|
|
7229
7233
|
...u,
|
|
7230
7234
|
onProgress: L(u.onProgress, "conversation-turn-reduce:map")
|
|
7231
7235
|
});
|
|
7232
|
-
return
|
|
7236
|
+
return m(e.length), p.emit({ event: k.output, value: w }), p.complete({ outcome: T.success, speakers: e.length }), w;
|
|
7233
7237
|
} catch (d) {
|
|
7234
7238
|
throw p.error(d), d;
|
|
7235
7239
|
}
|
|
@@ -7310,9 +7314,9 @@ class vt {
|
|
|
7310
7314
|
llm: u,
|
|
7311
7315
|
clock: p,
|
|
7312
7316
|
onProgress: d,
|
|
7313
|
-
now:
|
|
7317
|
+
now: h,
|
|
7314
7318
|
operation: y,
|
|
7315
|
-
...
|
|
7319
|
+
...b
|
|
7316
7320
|
} = i;
|
|
7317
7321
|
if (a.shouldContinue && typeof a.shouldContinue != "function")
|
|
7318
7322
|
throw new Error("shouldContinue must be a function");
|
|
@@ -7324,7 +7328,7 @@ class vt {
|
|
|
7324
7328
|
turnPolicy: a.turnPolicy || ds(this.speakers)
|
|
7325
7329
|
},
|
|
7326
7330
|
a
|
|
7327
|
-
), this.speakFn = c, this.bulkSpeakFn = l, this.maxParallel = s.maxParallel ?? 3, !this.speakFn && !this.bulkSpeakFn && (this.bulkSpeakFn = Un), this.llm = u, this.clock = p || (() => /* @__PURE__ */ new Date()), this.emitter || (this.emitter = I(st, i.onProgress, i)), this.onProgress = i.onProgress, this.runConfig = i, this.otherOptions =
|
|
7331
|
+
), this.speakFn = c, this.bulkSpeakFn = l, this.maxParallel = s.maxParallel ?? 3, !this.speakFn && !this.bulkSpeakFn && (this.bulkSpeakFn = Un), this.llm = u, this.clock = p || (() => /* @__PURE__ */ new Date()), this.emitter || (this.emitter = I(st, i.onProgress, i)), this.onProgress = i.onProgress, this.runConfig = i, this.otherOptions = b, this.messages = [], this.speakerMemory = /* @__PURE__ */ new Map();
|
|
7328
7332
|
}
|
|
7329
7333
|
_push(t, n) {
|
|
7330
7334
|
const r = (n ?? "").trim();
|
|
@@ -7614,9 +7618,9 @@ ${n}`;
|
|
|
7614
7618
|
} = {}) => {
|
|
7615
7619
|
try {
|
|
7616
7620
|
const d = t ?? n;
|
|
7617
|
-
let
|
|
7621
|
+
let h = e;
|
|
7618
7622
|
if (!e.isEnhanced) {
|
|
7619
|
-
|
|
7623
|
+
h = await s({
|
|
7620
7624
|
name: d,
|
|
7621
7625
|
rootName: n,
|
|
7622
7626
|
fixes: a,
|
|
@@ -7624,8 +7628,8 @@ ${n}`;
|
|
|
7624
7628
|
config: l,
|
|
7625
7629
|
variety: u,
|
|
7626
7630
|
now: p
|
|
7627
|
-
}),
|
|
7628
|
-
const y = e.options?.[0],
|
|
7631
|
+
}), h.isEnhanced = !0;
|
|
7632
|
+
const y = e.options?.[0], b = await r({
|
|
7629
7633
|
name: d,
|
|
7630
7634
|
focus: y,
|
|
7631
7635
|
rootName: n,
|
|
@@ -7635,18 +7639,18 @@ ${n}`;
|
|
|
7635
7639
|
variety: u,
|
|
7636
7640
|
now: p
|
|
7637
7641
|
});
|
|
7638
|
-
|
|
7642
|
+
h.children = b.map((f) => ({
|
|
7639
7643
|
id: i(),
|
|
7640
7644
|
name: f
|
|
7641
7645
|
}));
|
|
7642
7646
|
}
|
|
7643
|
-
return e.id || (
|
|
7647
|
+
return e.id || (h.id = i()), {
|
|
7644
7648
|
...e,
|
|
7645
|
-
...
|
|
7649
|
+
...h
|
|
7646
7650
|
};
|
|
7647
7651
|
} catch (d) {
|
|
7648
|
-
const
|
|
7649
|
-
throw d.message = `makeNode(${
|
|
7652
|
+
const h = t ?? n;
|
|
7653
|
+
throw d.message = `makeNode(${h}): ${d.message}`, d;
|
|
7650
7654
|
}
|
|
7651
7655
|
}, on = async ({
|
|
7652
7656
|
name: e,
|
|
@@ -7664,10 +7668,10 @@ ${n}`;
|
|
|
7664
7668
|
now: d
|
|
7665
7669
|
} = {}) => {
|
|
7666
7670
|
try {
|
|
7667
|
-
let
|
|
7671
|
+
let h = { ...n ?? {} };
|
|
7668
7672
|
const y = await py({
|
|
7669
|
-
node:
|
|
7670
|
-
name: e ??
|
|
7673
|
+
node: h,
|
|
7674
|
+
name: e ?? h.name,
|
|
7671
7675
|
rootName: t,
|
|
7672
7676
|
enhance: o,
|
|
7673
7677
|
decompose: s,
|
|
@@ -7679,13 +7683,13 @@ ${n}`;
|
|
|
7679
7683
|
variety: p,
|
|
7680
7684
|
now: d
|
|
7681
7685
|
});
|
|
7682
|
-
if (
|
|
7683
|
-
...
|
|
7686
|
+
if (h = {
|
|
7687
|
+
...h,
|
|
7684
7688
|
...y
|
|
7685
7689
|
}, r <= 0)
|
|
7686
|
-
return
|
|
7687
|
-
const
|
|
7688
|
-
for (const f of
|
|
7690
|
+
return h;
|
|
7691
|
+
const b = [];
|
|
7692
|
+
for (const f of h.children) {
|
|
7689
7693
|
const g = await on({
|
|
7690
7694
|
tree: f,
|
|
7691
7695
|
rootName: t,
|
|
@@ -7700,12 +7704,12 @@ ${n}`;
|
|
|
7700
7704
|
variety: p,
|
|
7701
7705
|
now: d
|
|
7702
7706
|
});
|
|
7703
|
-
|
|
7707
|
+
b.push(g);
|
|
7704
7708
|
}
|
|
7705
|
-
return
|
|
7706
|
-
} catch (
|
|
7709
|
+
return h.children = b, h;
|
|
7710
|
+
} catch (h) {
|
|
7707
7711
|
const y = e ?? n?.name ?? t;
|
|
7708
|
-
throw
|
|
7712
|
+
throw h.message = `makeSubtree(${y}, depth=${r}): ${h.message}`, h;
|
|
7709
7713
|
}
|
|
7710
7714
|
}, wa = (e) => {
|
|
7711
7715
|
if (!e.children || e.children.length === 0) {
|
|
@@ -7831,18 +7835,18 @@ class dy {
|
|
|
7831
7835
|
if (c === 0)
|
|
7832
7836
|
return [];
|
|
7833
7837
|
const l = [];
|
|
7834
|
-
for (const [d,
|
|
7835
|
-
const y = this._getDocumentVector(this.tfidf,
|
|
7836
|
-
if (
|
|
7837
|
-
const f = this._dotProduct(a, y) / (c *
|
|
7838
|
+
for (const [d, h] of this.chunks.entries()) {
|
|
7839
|
+
const y = this._getDocumentVector(this.tfidf, h.documentIndex), b = this._magnitude(y);
|
|
7840
|
+
if (b === 0) continue;
|
|
7841
|
+
const f = this._dotProduct(a, y) / (c * b);
|
|
7838
7842
|
f >= s && l.push({
|
|
7839
7843
|
id: d,
|
|
7840
|
-
text:
|
|
7844
|
+
text: h.text,
|
|
7841
7845
|
score: f
|
|
7842
7846
|
});
|
|
7843
7847
|
}
|
|
7844
|
-
const p = l.toSorted((d,
|
|
7845
|
-
return o ? p : p.map(({ id: d, text:
|
|
7848
|
+
const p = l.toSorted((d, h) => h.score - d.score).slice(0, r);
|
|
7849
|
+
return o ? p : p.map(({ id: d, text: h }) => ({ id: d, text: h }));
|
|
7846
7850
|
}
|
|
7847
7851
|
findMatches(t, n = {}) {
|
|
7848
7852
|
const { threshold: r = 0.1, includeScores: s = !0 } = n;
|
|
@@ -7998,15 +8002,15 @@ function Ey(e, t, n, r, s = St) {
|
|
|
7998
8002
|
o,
|
|
7999
8003
|
l,
|
|
8000
8004
|
s
|
|
8001
|
-
), d = Math.max(1, Math.floor(u / Sa)),
|
|
8005
|
+
), d = Math.max(1, Math.floor(u / Sa)), h = Math.max(
|
|
8002
8006
|
1,
|
|
8003
8007
|
Math.floor(p / xa)
|
|
8004
|
-
), y =
|
|
8008
|
+
), y = h * a * (1 - Ye), b = o < Sy ? xy : $y, f = Math.min(t * b, y);
|
|
8005
8009
|
return {
|
|
8006
8010
|
tfIdfBudget: t - f,
|
|
8007
8011
|
reservedSpace: f,
|
|
8008
8012
|
chunksWeCanScore: d,
|
|
8009
|
-
chunksWeCanCompress:
|
|
8013
|
+
chunksWeCanCompress: h,
|
|
8010
8014
|
reductionRatio: o,
|
|
8011
8015
|
avgChunkSize: a
|
|
8012
8016
|
};
|
|
@@ -8088,9 +8092,9 @@ async function _y(e, t, n, r = {}) {
|
|
|
8088
8092
|
};
|
|
8089
8093
|
}
|
|
8090
8094
|
async function Cy(e, t, n, r, s, o = {}) {
|
|
8091
|
-
const { compressionRatio: i = Ye } = o, a = Math.min(s.avgChunkSize * 0.8, 400), c = e.filter((y) => y.size >= a).toSorted((y,
|
|
8095
|
+
const { compressionRatio: i = Ye } = o, a = Math.min(s.avgChunkSize * 0.8, 400), c = e.filter((y) => y.size >= a).toSorted((y, b) => {
|
|
8092
8096
|
const f = (y.tfIdfScore || 0) * Math.log(y.size);
|
|
8093
|
-
return (
|
|
8097
|
+
return (b.tfIdfScore || 0) * Math.log(b.size) - f;
|
|
8094
8098
|
}).slice(0, n);
|
|
8095
8099
|
if (c.length === 0)
|
|
8096
8100
|
return { compressed: [], tokensUsed: 0 };
|
|
@@ -8103,17 +8107,17 @@ async function Cy(e, t, n, r, s, o = {}) {
|
|
|
8103
8107
|
onProgress: L(o.onProgress, "map:compression")
|
|
8104
8108
|
}
|
|
8105
8109
|
), d = [];
|
|
8106
|
-
let
|
|
8107
|
-
return p.forEach((y,
|
|
8110
|
+
let h = 0;
|
|
8111
|
+
return p.forEach((y, b) => {
|
|
8108
8112
|
const f = y ? Pa(y) : "";
|
|
8109
|
-
f.length >= $a && f.length <= r -
|
|
8110
|
-
...c[
|
|
8111
|
-
originalText: c[
|
|
8113
|
+
f.length >= $a && f.length <= r - h && (d.push({
|
|
8114
|
+
...c[b],
|
|
8115
|
+
originalText: c[b].text,
|
|
8112
8116
|
text: f,
|
|
8113
8117
|
compressed: !0,
|
|
8114
8118
|
size: f.length,
|
|
8115
|
-
compressionRatio: f.length / c[
|
|
8116
|
-
}),
|
|
8119
|
+
compressionRatio: f.length / c[b].size
|
|
8120
|
+
}), h += f.length);
|
|
8117
8121
|
}), {
|
|
8118
8122
|
compressed: d,
|
|
8119
8123
|
tokensUsed: c.length * xa
|
|
@@ -8180,9 +8184,9 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8180
8184
|
tokenBudget: u,
|
|
8181
8185
|
gapFillerBudgetRatio: p,
|
|
8182
8186
|
compression: d,
|
|
8183
|
-
ranking:
|
|
8187
|
+
ranking: h,
|
|
8184
8188
|
queryExpansion: y,
|
|
8185
|
-
llmScoring:
|
|
8189
|
+
llmScoring: b,
|
|
8186
8190
|
llmCompression: f,
|
|
8187
8191
|
scoringTokenRatio: g
|
|
8188
8192
|
} = await q(a, {
|
|
@@ -8197,7 +8201,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8197
8201
|
"llmCompression",
|
|
8198
8202
|
"scoringTokenRatio"
|
|
8199
8203
|
])
|
|
8200
|
-
}),
|
|
8204
|
+
}), m = {
|
|
8201
8205
|
..._e,
|
|
8202
8206
|
...a,
|
|
8203
8207
|
targetSize: l,
|
|
@@ -8205,7 +8209,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8205
8209
|
gapFillerBudgetRatio: p
|
|
8206
8210
|
};
|
|
8207
8211
|
if (!e || e.length === 0) {
|
|
8208
|
-
const
|
|
8212
|
+
const w = {
|
|
8209
8213
|
content: "",
|
|
8210
8214
|
metadata: {
|
|
8211
8215
|
originalSize: 0,
|
|
@@ -8216,60 +8220,60 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8216
8220
|
tokens: { budget: 0, used: 0, breakdown: {} }
|
|
8217
8221
|
}
|
|
8218
8222
|
};
|
|
8219
|
-
return c.complete({ outcome: T.success }),
|
|
8223
|
+
return c.complete({ outcome: T.success }), w;
|
|
8220
8224
|
}
|
|
8221
8225
|
try {
|
|
8222
|
-
|
|
8223
|
-
let
|
|
8226
|
+
m.targetSize <= 0 && (m.targetSize = _e.targetSize), m.chunkSize <= 0 && (m.chunkSize = _e.chunkSize), m.tokenBudget <= 0 && (m.tokenBudget = _e.tokenBudget);
|
|
8227
|
+
let w = m.tokenBudget;
|
|
8224
8228
|
c.emit({ event: k.phase, phase: "chunking" });
|
|
8225
|
-
const
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
+
const S = Iy(e, m.chunkSize, m.targetSize), v = Ey(
|
|
8230
|
+
S,
|
|
8231
|
+
m.targetSize,
|
|
8232
|
+
w,
|
|
8229
8233
|
e.length,
|
|
8230
8234
|
g
|
|
8231
8235
|
);
|
|
8232
|
-
!
|
|
8236
|
+
!b && !f && (v.tfIdfBudget = m.targetSize, v.reservedSpace = 0), c.emit({ event: k.phase, phase: "query-expansion" });
|
|
8233
8237
|
const P = a;
|
|
8234
8238
|
let x, E = 0;
|
|
8235
8239
|
if (s.expansions)
|
|
8236
8240
|
x = s.expansions.split(",").map((B) => B.trim()).filter(Boolean), x.unshift(i);
|
|
8237
8241
|
else if (y) {
|
|
8238
|
-
const B = await ky(i,
|
|
8242
|
+
const B = await ky(i, w, P);
|
|
8239
8243
|
x = B.expansions, E = B.tokensUsed;
|
|
8240
8244
|
} else
|
|
8241
8245
|
x = [i];
|
|
8242
|
-
|
|
8243
|
-
const O = Ay(
|
|
8246
|
+
w -= E, c.emit({ event: k.phase, phase: "tfidf-scoring", expansions: x });
|
|
8247
|
+
const O = Ay(S, x), { selected: R, candidates: j, sizeUsed: F } = Oy(
|
|
8244
8248
|
O,
|
|
8245
|
-
|
|
8249
|
+
v.tfIdfBudget
|
|
8246
8250
|
);
|
|
8247
8251
|
c.emit({ event: k.phase, phase: "edge-scoring" });
|
|
8248
|
-
const { scored: V, tokensUsed: Y } =
|
|
8252
|
+
const { scored: V, tokensUsed: Y } = b ? await _y(j, i, v.chunksWeCanScore, {
|
|
8249
8253
|
...P,
|
|
8250
|
-
llmWeight:
|
|
8254
|
+
llmWeight: h
|
|
8251
8255
|
}) : { scored: [], tokensUsed: 0 };
|
|
8252
|
-
|
|
8253
|
-
let H = vs(R, F, V,
|
|
8256
|
+
w -= Y;
|
|
8257
|
+
let H = vs(R, F, V, m.targetSize);
|
|
8254
8258
|
c.emit({ event: k.phase, phase: "compression" });
|
|
8255
|
-
const ee =
|
|
8259
|
+
const ee = m.targetSize - H.size;
|
|
8256
8260
|
let pe = 0;
|
|
8257
|
-
const G = Math.min(
|
|
8258
|
-
if (f && ee > G &&
|
|
8261
|
+
const G = Math.min(v.avgChunkSize * 0.5, 200);
|
|
8262
|
+
if (f && ee > G && v.chunksWeCanCompress > 0) {
|
|
8259
8263
|
const B = jy(O, H.chunks), { compressed: X, tokensUsed: ce } = await Cy(
|
|
8260
8264
|
B,
|
|
8261
8265
|
i,
|
|
8262
|
-
|
|
8266
|
+
v.chunksWeCanCompress,
|
|
8263
8267
|
ee,
|
|
8264
|
-
|
|
8268
|
+
v,
|
|
8265
8269
|
{ ...P, compressionRatio: d }
|
|
8266
8270
|
);
|
|
8267
|
-
pe = ce,
|
|
8271
|
+
pe = ce, w -= ce, H = vs(H.chunks, H.size, X, m.targetSize);
|
|
8268
8272
|
}
|
|
8269
8273
|
c.emit({ event: k.phase, phase: "assembly" });
|
|
8270
8274
|
let te = H.chunks, ie = 0;
|
|
8271
|
-
if (
|
|
8272
|
-
const B = Math.floor(
|
|
8275
|
+
if (m.gapFillerBudgetRatio > 0) {
|
|
8276
|
+
const B = Math.floor(m.targetSize * m.gapFillerBudgetRatio), X = m.targetSize - H.size, ce = Math.min(B, X);
|
|
8273
8277
|
if (ce > 0) {
|
|
8274
8278
|
const ve = Ly(O, te, ce);
|
|
8275
8279
|
ve.length > 0 && (te = [...te, ...ve], ie = ve.length);
|
|
@@ -8277,7 +8281,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8277
8281
|
}
|
|
8278
8282
|
const de = Ny(te);
|
|
8279
8283
|
let Z = Ry(de);
|
|
8280
|
-
Z.length >
|
|
8284
|
+
Z.length > m.targetSize * 3 && (Z = Pa(Z.slice(0, m.targetSize * 2)));
|
|
8281
8285
|
const we = {
|
|
8282
8286
|
content: Z,
|
|
8283
8287
|
metadata: {
|
|
@@ -8285,20 +8289,20 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8285
8289
|
finalSize: Z.length,
|
|
8286
8290
|
reductionRatio: (1 - Z.length / e.length).toFixed(2),
|
|
8287
8291
|
allocation: {
|
|
8288
|
-
tfIdfBudget:
|
|
8289
|
-
reservedForLLM:
|
|
8292
|
+
tfIdfBudget: v.tfIdfBudget,
|
|
8293
|
+
reservedForLLM: v.reservedSpace,
|
|
8290
8294
|
actualLLMSpace: te.filter((B) => B.llmScore).reduce((B, X) => B + X.size, 0)
|
|
8291
8295
|
},
|
|
8292
8296
|
chunks: {
|
|
8293
|
-
total:
|
|
8297
|
+
total: S.length,
|
|
8294
8298
|
tfIdfSelected: R.length,
|
|
8295
8299
|
llmSelected: te.filter((B) => B.llmScore && !B.compressed).length,
|
|
8296
8300
|
compressed: te.filter((B) => B.compressed).length,
|
|
8297
8301
|
gapFillers: ie
|
|
8298
8302
|
},
|
|
8299
8303
|
tokens: {
|
|
8300
|
-
budget:
|
|
8301
|
-
used:
|
|
8304
|
+
budget: m.tokenBudget,
|
|
8305
|
+
used: m.tokenBudget - w,
|
|
8302
8306
|
breakdown: {
|
|
8303
8307
|
expansion: E,
|
|
8304
8308
|
scoring: Y || 0,
|
|
@@ -8308,8 +8312,8 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8308
8312
|
}
|
|
8309
8313
|
};
|
|
8310
8314
|
return c.complete({ outcome: T.success }), we;
|
|
8311
|
-
} catch (
|
|
8312
|
-
throw c.error(
|
|
8315
|
+
} catch (w) {
|
|
8316
|
+
throw c.error(w), w;
|
|
8313
8317
|
}
|
|
8314
8318
|
}
|
|
8315
8319
|
Ea.knownTexts = ["expansions"];
|
|
@@ -8361,33 +8365,33 @@ async function ka(e, t = {}) {
|
|
|
8361
8365
|
else {
|
|
8362
8366
|
if (!n)
|
|
8363
8367
|
return i.complete({ outcome: T.success }), [];
|
|
8364
|
-
const
|
|
8365
|
-
`).map((
|
|
8366
|
-
if (
|
|
8368
|
+
const b = n.split(`
|
|
8369
|
+
`).map((m) => m.trim()).filter(Boolean);
|
|
8370
|
+
if (b.length === 0)
|
|
8367
8371
|
return i.complete({ outcome: T.success }), [];
|
|
8368
8372
|
const f = s ? `
|
|
8369
8373
|
|
|
8370
8374
|
${s}` : "", g = await ke(
|
|
8371
|
-
|
|
8375
|
+
b,
|
|
8372
8376
|
`How ambiguous or easily misinterpreted is this sentence?${f}`,
|
|
8373
8377
|
{
|
|
8374
8378
|
...o,
|
|
8375
8379
|
onProgress: L(o.onProgress, "score:sentence-ambiguity")
|
|
8376
8380
|
}
|
|
8377
8381
|
);
|
|
8378
|
-
c =
|
|
8382
|
+
c = b.map((m, w) => ({ sentence: m, score: g[w] ?? 0 })).toSorted((m, w) => w.score - m.score).slice(0, a);
|
|
8379
8383
|
}
|
|
8380
8384
|
i.emit({ event: k.phase, phase: "ranked", rankedSentences: c });
|
|
8381
8385
|
const l = i.batch(c.length), p = (await Q(
|
|
8382
8386
|
c,
|
|
8383
|
-
async ({ sentence:
|
|
8387
|
+
async ({ sentence: b }) => {
|
|
8384
8388
|
const f = await Ze("Ambiguous words or short phrases", {
|
|
8385
8389
|
...o,
|
|
8386
|
-
attachments: { text:
|
|
8390
|
+
attachments: { text: b },
|
|
8387
8391
|
targetNewItemsCount: 5,
|
|
8388
8392
|
onProgress: L(o.onProgress, "list:extract")
|
|
8389
8393
|
});
|
|
8390
|
-
return l(1), f.map((g) => ({ term: g, sentence:
|
|
8394
|
+
return l(1), f.map((g) => ({ term: g, sentence: b }));
|
|
8391
8395
|
},
|
|
8392
8396
|
{
|
|
8393
8397
|
maxParallel: 3,
|
|
@@ -8399,13 +8403,13 @@ ${s}` : "", g = await ke(
|
|
|
8399
8403
|
if (p.length === 0)
|
|
8400
8404
|
return i.complete({ outcome: T.success }), [];
|
|
8401
8405
|
const d = await ke(
|
|
8402
|
-
p.map((
|
|
8406
|
+
p.map((b) => `${b.term} | ${b.sentence}`),
|
|
8403
8407
|
"Score how ambiguous the term is within the sentence.",
|
|
8404
8408
|
{
|
|
8405
8409
|
...o,
|
|
8406
8410
|
onProgress: L(o.onProgress, "score:term-ambiguity")
|
|
8407
8411
|
}
|
|
8408
|
-
), y = p.map((
|
|
8412
|
+
), y = p.map((b, f) => ({ ...b, score: d[f] ?? 0 })).toSorted((b, f) => (f.score || 0) - (b.score || 0));
|
|
8409
8413
|
return i.complete({ outcome: T.success }), y.slice(0, a);
|
|
8410
8414
|
} catch (c) {
|
|
8411
8415
|
throw i.error(c), c;
|
|
@@ -8451,22 +8455,22 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
|
|
|
8451
8455
|
windowNumber: g + 1,
|
|
8452
8456
|
totalWindows: p.length
|
|
8453
8457
|
});
|
|
8454
|
-
const
|
|
8455
|
-
`),
|
|
8458
|
+
const m = f.fragments.map((P, x) => `${x + 1}. ${P}`).join(`
|
|
8459
|
+
`), w = c ? `
|
|
8456
8460
|
|
|
8457
|
-
${$(c, { tag: "style-guidance" })}` : "",
|
|
8461
|
+
${$(c, { tag: "style-guidance" })}` : "", S = `${o}${w}
|
|
8458
8462
|
|
|
8459
8463
|
Window ${g + 1} of ${p.length} - Join these fragments:
|
|
8460
8464
|
|
|
8461
|
-
${$(
|
|
8465
|
+
${$(m, { tag: "fragments" })}
|
|
8462
8466
|
|
|
8463
|
-
Important: This is part of a larger sequence. Join these fragments while being mindful that this result will be combined with other processed windows. Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the joined result for this window.`,
|
|
8467
|
+
Important: This is part of a larger sequence. Join these fragments while being mindful that this result will be combined with other processed windows. Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the joined result for this window.`, v = await M(() => _(S, i), {
|
|
8464
8468
|
label: `join-window-${g + 1}`,
|
|
8465
8469
|
config: i,
|
|
8466
8470
|
onProgress: L(i.onProgress, "window")
|
|
8467
8471
|
});
|
|
8468
8472
|
return d(1), {
|
|
8469
|
-
content:
|
|
8473
|
+
content: v || f.fragments.join(" "),
|
|
8470
8474
|
window: f
|
|
8471
8475
|
};
|
|
8472
8476
|
},
|
|
@@ -8476,7 +8480,7 @@ Important: This is part of a larger sequence. Join these fragments while being m
|
|
|
8476
8480
|
return a.complete({ outcome: T.success, windows: p.length }), e.join(" ");
|
|
8477
8481
|
if (y.length === 1)
|
|
8478
8482
|
return a.complete({ outcome: T.success, windows: p.length }), y[0].content;
|
|
8479
|
-
let
|
|
8483
|
+
let b = y[0].content;
|
|
8480
8484
|
for (let f = 1; f < y.length; f++) {
|
|
8481
8485
|
a.emit({
|
|
8482
8486
|
event: k.step,
|
|
@@ -8484,15 +8488,15 @@ Important: This is part of a larger sequence. Join these fragments while being m
|
|
|
8484
8488
|
stitchNumber: f,
|
|
8485
8489
|
totalStitches: y.length - 1
|
|
8486
8490
|
});
|
|
8487
|
-
const g = y[f],
|
|
8488
|
-
if (
|
|
8489
|
-
const P = e.slice(
|
|
8491
|
+
const g = y[f], m = y[f - 1].window, w = g.window, S = Math.max(m.startIndex, w.startIndex), v = Math.min(m.endIndex, w.endIndex);
|
|
8492
|
+
if (S <= v) {
|
|
8493
|
+
const P = e.slice(S, v + 1), x = c ? `
|
|
8490
8494
|
|
|
8491
8495
|
${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), O = `${o}${x}
|
|
8492
8496
|
|
|
8493
8497
|
Stitch these two sections by resolving their overlapping region:
|
|
8494
8498
|
|
|
8495
|
-
${$(
|
|
8499
|
+
${$(b, { tag: "section-a", name: "preserve-terminals" })}
|
|
8496
8500
|
|
|
8497
8501
|
${$(g.content, { tag: "section-b", name: "preserve-terminals" })}
|
|
8498
8502
|
|
|
@@ -8501,10 +8505,10 @@ ${$(E, { tag: "overlapping-fragments" })}
|
|
|
8501
8505
|
The terminal ends of both sections should be preserved. Only resolve the overlapping middle region where these fragments appear.
|
|
8502
8506
|
|
|
8503
8507
|
Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the final stitched result with terminals preserved.`;
|
|
8504
|
-
|
|
8508
|
+
b = await M(() => _(O, i), {
|
|
8505
8509
|
label: `join-stitch-${f}`,
|
|
8506
8510
|
config: i
|
|
8507
|
-
}) ||
|
|
8511
|
+
}) || b;
|
|
8508
8512
|
} else {
|
|
8509
8513
|
const P = c ? `
|
|
8510
8514
|
|
|
@@ -8512,18 +8516,18 @@ ${$(c, { tag: "style-guidance" })}` : "", x = `${o}${P}
|
|
|
8512
8516
|
|
|
8513
8517
|
Join these two non-overlapping sections:
|
|
8514
8518
|
|
|
8515
|
-
${$(
|
|
8519
|
+
${$(b, { tag: "section-1" })}
|
|
8516
8520
|
|
|
8517
8521
|
${$(g.content, { tag: "section-2" })}
|
|
8518
8522
|
|
|
8519
8523
|
Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the joined result.`;
|
|
8520
|
-
|
|
8524
|
+
b = await M(() => _(x, i), {
|
|
8521
8525
|
label: `join-nonoverlap-${f}`,
|
|
8522
8526
|
config: i
|
|
8523
|
-
}) ||
|
|
8527
|
+
}) || b;
|
|
8524
8528
|
}
|
|
8525
8529
|
}
|
|
8526
|
-
return a.complete({ outcome: T.success, windows: p.length }),
|
|
8530
|
+
return a.complete({ outcome: T.success, windows: p.length }), b;
|
|
8527
8531
|
} catch (p) {
|
|
8528
8532
|
throw a.error(p), p;
|
|
8529
8533
|
}
|
|
@@ -8692,9 +8696,9 @@ async function Na(e, t, n) {
|
|
|
8692
8696
|
u = $(f.join(`
|
|
8693
8697
|
`), { tag: "sources" });
|
|
8694
8698
|
}
|
|
8695
|
-
const p = $(e, { tag: "sentence" }), d = $(r, { tag: "description" }),
|
|
8699
|
+
const p = $(e, { tag: "sentence" }), d = $(r, { tag: "description" }), h = a ? "Include a brief context description for each reference explaining the scene or idea being referenced." : "Do not include context descriptions.", y = s ? `
|
|
8696
8700
|
|
|
8697
|
-
${s}` : "",
|
|
8701
|
+
${s}` : "", b = `Find pop culture references that metaphorically capture the sentence based on its description.
|
|
8698
8702
|
|
|
8699
8703
|
${d}
|
|
8700
8704
|
|
|
@@ -8710,7 +8714,7 @@ Process:
|
|
|
8710
8714
|
3. Score each reference based on how well it fits (0-1 scale)
|
|
8711
8715
|
4. Identify which part of the sentence each reference connects to
|
|
8712
8716
|
|
|
8713
|
-
${
|
|
8717
|
+
${h}
|
|
8714
8718
|
|
|
8715
8719
|
Requirements:
|
|
8716
8720
|
- Each reference should be a specific moment, scene, or concept (not just the source name)
|
|
@@ -8719,7 +8723,7 @@ Requirements:
|
|
|
8719
8723
|
- Higher scores mean stronger metaphorical fit${y}`;
|
|
8720
8724
|
try {
|
|
8721
8725
|
const f = await M(
|
|
8722
|
-
() => _(
|
|
8726
|
+
() => _(b, {
|
|
8723
8727
|
...o,
|
|
8724
8728
|
responseFormat: ib
|
|
8725
8729
|
}),
|
|
@@ -8792,8 +8796,8 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8792
8796
|
const { exploration: c } = await q(i, {
|
|
8793
8797
|
exploration: J(lb)
|
|
8794
8798
|
}), l = [], u = {}, p = [];
|
|
8795
|
-
let d = !1,
|
|
8796
|
-
const { shouldSkip: y = mb, shouldStop:
|
|
8799
|
+
let d = !1, h = o;
|
|
8800
|
+
const { shouldSkip: y = mb, shouldStop: b = hb } = i, f = await re("temperature", i, 1);
|
|
8797
8801
|
let g = 0;
|
|
8798
8802
|
try {
|
|
8799
8803
|
for (; !d; ) {
|
|
@@ -8803,10 +8807,10 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8803
8807
|
attempt: g + 1,
|
|
8804
8808
|
questionsFound: l.length
|
|
8805
8809
|
}), l.length) {
|
|
8806
|
-
const x = l.filter((R) => !p.includes(R)), E = db(
|
|
8810
|
+
const x = l.filter((R) => !p.includes(R)), E = db(h, {
|
|
8807
8811
|
existing: x
|
|
8808
8812
|
});
|
|
8809
|
-
|
|
8813
|
+
h = (await M(
|
|
8810
8814
|
() => _(E, {
|
|
8811
8815
|
...i,
|
|
8812
8816
|
responseFormat: C("selected_question", cb)
|
|
@@ -8815,26 +8819,26 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8815
8819
|
label: "questions-pick-interesting",
|
|
8816
8820
|
config: i
|
|
8817
8821
|
}
|
|
8818
|
-
)).question, p.push(
|
|
8822
|
+
)).question, p.push(h);
|
|
8819
8823
|
}
|
|
8820
|
-
const
|
|
8824
|
+
const m = fb(h, {
|
|
8821
8825
|
existing: l
|
|
8822
|
-
}),
|
|
8826
|
+
}), w = {
|
|
8823
8827
|
...i,
|
|
8824
8828
|
temperature: f,
|
|
8825
8829
|
responseFormat: C("questions_list", ab)
|
|
8826
|
-
},
|
|
8830
|
+
}, S = await M(() => _(m, w), {
|
|
8827
8831
|
label: "questions-generate",
|
|
8828
8832
|
config: i
|
|
8829
|
-
}),
|
|
8833
|
+
}), v = pb(S, c);
|
|
8830
8834
|
if (c < 0.5) {
|
|
8831
|
-
const x = Math.floor(Math.random() *
|
|
8832
|
-
|
|
8835
|
+
const x = Math.floor(Math.random() * v.length);
|
|
8836
|
+
h = v[x];
|
|
8833
8837
|
}
|
|
8834
|
-
const P =
|
|
8838
|
+
const P = v.filter((x) => !(x in u));
|
|
8835
8839
|
g += 1;
|
|
8836
8840
|
for (const x of P) {
|
|
8837
|
-
if (await
|
|
8841
|
+
if (await b(x, l, v, g)) {
|
|
8838
8842
|
d = !0;
|
|
8839
8843
|
break;
|
|
8840
8844
|
}
|
|
@@ -8842,8 +8846,8 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8842
8846
|
}
|
|
8843
8847
|
}
|
|
8844
8848
|
a.complete({ outcome: T.success, questions: l.length, attempts: g });
|
|
8845
|
-
} catch (
|
|
8846
|
-
throw a.error(
|
|
8849
|
+
} catch (m) {
|
|
8850
|
+
throw a.error(m), m;
|
|
8847
8851
|
}
|
|
8848
8852
|
}, Ra = async (e, t = {}) => {
|
|
8849
8853
|
const n = gb(e, t), r = [];
|
|
@@ -9446,16 +9450,16 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9446
9450
|
temperature: 0.1,
|
|
9447
9451
|
preservation: J(Pw),
|
|
9448
9452
|
mode: "structural"
|
|
9449
|
-
}), { delimiter:
|
|
9453
|
+
}), { delimiter: h = Tw } = i, y = await re(
|
|
9450
9454
|
"preservationShort",
|
|
9451
9455
|
i,
|
|
9452
9456
|
p.short
|
|
9453
|
-
),
|
|
9457
|
+
), b = await re("preservationLong", i, p.long);
|
|
9454
9458
|
try {
|
|
9455
|
-
const f = Kn(e, c), g = a.batch(f.length),
|
|
9459
|
+
const f = Kn(e, c), g = a.batch(f.length), m = await Q(
|
|
9456
9460
|
f,
|
|
9457
|
-
async (
|
|
9458
|
-
const E = kw(
|
|
9461
|
+
async (v, P) => {
|
|
9462
|
+
const E = kw(v, o, h, {
|
|
9459
9463
|
targetSplitCount: l,
|
|
9460
9464
|
mode: d
|
|
9461
9465
|
}), O = {
|
|
@@ -9468,14 +9472,14 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9468
9472
|
config: i,
|
|
9469
9473
|
onProgress: L(i.onProgress, "chunk")
|
|
9470
9474
|
}), j = R.replace(
|
|
9471
|
-
new RegExp(
|
|
9475
|
+
new RegExp(h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
|
|
9472
9476
|
""
|
|
9473
|
-
), F =
|
|
9477
|
+
), F = v.trim(), V = F.length < 100 ? y : b;
|
|
9474
9478
|
return Math.abs(j.length - F.length) > F.length * V ? (i.logger?.warn && i.logger.warn(
|
|
9475
9479
|
`Split output differs significantly from input for chunk ${P + 1}, using original chunk`
|
|
9476
|
-
), g(1),
|
|
9480
|
+
), g(1), v) : (g(1), R);
|
|
9477
9481
|
} catch (R) {
|
|
9478
|
-
return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1),
|
|
9482
|
+
return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1), v;
|
|
9479
9483
|
}
|
|
9480
9484
|
},
|
|
9481
9485
|
{
|
|
@@ -9484,12 +9488,12 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9484
9488
|
abortSignal: i.abortSignal,
|
|
9485
9489
|
label: "split chunks"
|
|
9486
9490
|
}
|
|
9487
|
-
),
|
|
9491
|
+
), w = h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), S = m.join("").split(new RegExp(w)).map((v) => v.trim()).filter(Boolean);
|
|
9488
9492
|
return a.complete({
|
|
9489
9493
|
outcome: T.success,
|
|
9490
9494
|
chunks: f.length,
|
|
9491
|
-
segments:
|
|
9492
|
-
}),
|
|
9495
|
+
segments: S.length
|
|
9496
|
+
}), S;
|
|
9493
9497
|
} catch (f) {
|
|
9494
9498
|
throw a.error(f), f;
|
|
9495
9499
|
}
|
|
@@ -9516,8 +9520,8 @@ const Rs = (e) => /^\d+$/.test(e), Aw = /^([^.]+(\.[^.]+)*)$/, Ow = (e, t, n) =>
|
|
|
9516
9520
|
const u = Math.max(
|
|
9517
9521
|
Math.ceil((l - s) * a),
|
|
9518
9522
|
t
|
|
9519
|
-
), p = Math.floor(c.length / 2), d = p - Math.ceil(u / 2),
|
|
9520
|
-
c = c.slice(0, d) + i + c.slice(
|
|
9523
|
+
), p = Math.floor(c.length / 2), d = p - Math.ceil(u / 2), h = p + Math.floor(u / 2);
|
|
9524
|
+
c = c.slice(0, d) + i + c.slice(h), l = o.toTokens(c).length;
|
|
9521
9525
|
}
|
|
9522
9526
|
return c;
|
|
9523
9527
|
}, Cw = ({ budget: e, type: t, value: n, fixes: r = [], llmOptions: s, sensitivity: o }) => {
|
|
@@ -9574,22 +9578,22 @@ class Ka extends Map {
|
|
|
9574
9578
|
targetTokenCount: this.maxTokensPerValue,
|
|
9575
9579
|
model: c
|
|
9576
9580
|
}), p = c.toTokens(u).length, d = p < l;
|
|
9577
|
-
let
|
|
9581
|
+
let h = u;
|
|
9578
9582
|
if (o) {
|
|
9579
|
-
const
|
|
9583
|
+
const b = {
|
|
9580
9584
|
...this.llmOptions,
|
|
9581
9585
|
...i.modelOptions
|
|
9582
9586
|
};
|
|
9583
|
-
(i.sensitivity?.whitelist || i.sensitivity?.blacklist) && (
|
|
9587
|
+
(i.sensitivity?.whitelist || i.sensitivity?.blacklist) && (b.sensitive = !0), h = await Cw({
|
|
9584
9588
|
budget: o,
|
|
9585
9589
|
fixes: i.fixes,
|
|
9586
|
-
llmOptions:
|
|
9590
|
+
llmOptions: b,
|
|
9587
9591
|
sensitivity: i.sensitivity,
|
|
9588
9592
|
type: i.type,
|
|
9589
9593
|
value: u
|
|
9590
9594
|
});
|
|
9591
9595
|
}
|
|
9592
|
-
const y = c.toTokens(
|
|
9596
|
+
const y = c.toTokens(h).length;
|
|
9593
9597
|
t.emit({
|
|
9594
9598
|
event: k.step,
|
|
9595
9599
|
stepName: "context-trim",
|
|
@@ -9600,7 +9604,7 @@ class Ka extends Map {
|
|
|
9600
9604
|
budget: o,
|
|
9601
9605
|
strategy: o ? "shorten+summarize" : "shorten",
|
|
9602
9606
|
ratio: Number((y / l).toFixed(3))
|
|
9603
|
-
}), this.cache.set(s,
|
|
9607
|
+
}), this.cache.set(s, h), r(1);
|
|
9604
9608
|
}
|
|
9605
9609
|
this.isCacheValid = !0, t.complete({ outcome: T.success, entries: n.length });
|
|
9606
9610
|
} catch (n) {
|
|
@@ -9673,42 +9677,42 @@ const Nw = "http://json-schema.org/draft-07/schema#", Rw = "object", Mw = { tags
|
|
|
9673
9677
|
}, Ls = "tag-vocabulary";
|
|
9674
9678
|
function Gn(e, t, n = {}) {
|
|
9675
9679
|
const { topN: r = 3, bottomN: s = 3, problematicSampleSize: o = 3 } = n, i = {};
|
|
9676
|
-
e.tags.forEach((
|
|
9677
|
-
i[
|
|
9678
|
-
}), t.forEach((
|
|
9679
|
-
|
|
9680
|
-
i[
|
|
9680
|
+
e.tags.forEach((m) => {
|
|
9681
|
+
i[m.id] = 0;
|
|
9682
|
+
}), t.forEach((m) => {
|
|
9683
|
+
m && Array.isArray(m) && m.forEach((w) => {
|
|
9684
|
+
i[w] !== void 0 && i[w]++;
|
|
9681
9685
|
});
|
|
9682
9686
|
});
|
|
9683
|
-
const a = Object.entries(i).map(([
|
|
9684
|
-
tag: e.tags.find((
|
|
9685
|
-
count:
|
|
9686
|
-
})).toSorted((
|
|
9687
|
+
const a = Object.entries(i).map(([m, w]) => ({
|
|
9688
|
+
tag: e.tags.find((S) => S.id === m),
|
|
9689
|
+
count: w
|
|
9690
|
+
})).toSorted((m, w) => w.count - m.count), c = a.slice(0, r), l = a.slice(-s), u = t.filter((m) => m && m.length > 0).length, p = t.reduce((m, w) => m + (w ? w.length : 0), 0), d = t.length > 0 ? p / t.length : 0, h = {
|
|
9687
9691
|
totalItems: t.length,
|
|
9688
9692
|
itemsWithTags: u,
|
|
9689
9693
|
coveragePercent: t.length > 0 ? u / t.length * 100 : 0,
|
|
9690
9694
|
avgTagsPerItem: d,
|
|
9691
9695
|
totalTags: e.tags.length,
|
|
9692
|
-
unusedTags: a.filter((
|
|
9693
|
-
}, y = [],
|
|
9694
|
-
return t.forEach((
|
|
9695
|
-
!
|
|
9696
|
+
unusedTags: a.filter((m) => m.count === 0).length
|
|
9697
|
+
}, y = [], b = [], f = [], g = [];
|
|
9698
|
+
return t.forEach((m, w) => {
|
|
9699
|
+
!m || m.length === 0 ? b.length < o && b.push({
|
|
9696
9700
|
type: "untagged",
|
|
9697
|
-
itemIndex:
|
|
9701
|
+
itemIndex: w,
|
|
9698
9702
|
tags: []
|
|
9699
|
-
}) :
|
|
9703
|
+
}) : m.length > d * 2 ? f.length < o && f.push({
|
|
9700
9704
|
type: "overtagged",
|
|
9701
|
-
itemIndex:
|
|
9702
|
-
tags:
|
|
9703
|
-
tagCount:
|
|
9704
|
-
}) :
|
|
9705
|
+
itemIndex: w,
|
|
9706
|
+
tags: m,
|
|
9707
|
+
tagCount: m.length
|
|
9708
|
+
}) : m.length === 1 && d > 1.5 && g.length < o && g.push({
|
|
9705
9709
|
type: "ambiguous",
|
|
9706
|
-
itemIndex:
|
|
9707
|
-
tags:
|
|
9710
|
+
itemIndex: w,
|
|
9711
|
+
tags: m,
|
|
9708
9712
|
tagCount: 1
|
|
9709
9713
|
});
|
|
9710
|
-
}), y.push(...
|
|
9711
|
-
stats:
|
|
9714
|
+
}), y.push(...b, ...f, ...g), {
|
|
9715
|
+
stats: h,
|
|
9712
9716
|
mostUsed: c,
|
|
9713
9717
|
leastUsed: l,
|
|
9714
9718
|
problematicItems: y,
|
|
@@ -9793,12 +9797,12 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
|
|
|
9793
9797
|
if (s.initialVocab)
|
|
9794
9798
|
p = JSON.parse(s.initialVocab);
|
|
9795
9799
|
else {
|
|
9796
|
-
const
|
|
9800
|
+
const b = t.slice(0, Math.min(u, t.length));
|
|
9797
9801
|
c.emit({
|
|
9798
9802
|
event: k.step,
|
|
9799
9803
|
stepName: "generate-initial-vocabulary",
|
|
9800
|
-
sampleCount:
|
|
9801
|
-
}), p = await Dw(i,
|
|
9804
|
+
sampleCount: b.length
|
|
9805
|
+
}), p = await Dw(i, b, a);
|
|
9802
9806
|
}
|
|
9803
9807
|
c.emit({
|
|
9804
9808
|
event: k.step,
|
|
@@ -9806,8 +9810,8 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
|
|
|
9806
9810
|
itemCount: t.length,
|
|
9807
9811
|
initialVocab: p
|
|
9808
9812
|
});
|
|
9809
|
-
const d = await l(t, p),
|
|
9810
|
-
c.emit({ event: k.step, stepName: "refine-vocabulary", statistics:
|
|
9813
|
+
const d = await l(t, p), h = Gn(p, d);
|
|
9814
|
+
c.emit({ event: k.step, stepName: "refine-vocabulary", statistics: h });
|
|
9811
9815
|
const y = await qw(p, d, i, a);
|
|
9812
9816
|
return c.complete({ outcome: T.success }), y;
|
|
9813
9817
|
} catch (l) {
|
|
@@ -9825,20 +9829,20 @@ async function Ha(e, t = {}) {
|
|
|
9825
9829
|
try {
|
|
9826
9830
|
let c;
|
|
9827
9831
|
if (r.rawThemes)
|
|
9828
|
-
c = r.rawThemes.split(",").map((
|
|
9832
|
+
c = r.rawThemes.split(",").map((h) => h.trim()).filter(Boolean);
|
|
9829
9833
|
else {
|
|
9830
|
-
const
|
|
9834
|
+
const h = Fw(n);
|
|
9831
9835
|
i.emit({
|
|
9832
9836
|
event: k.phase,
|
|
9833
9837
|
phase: "extraction"
|
|
9834
9838
|
});
|
|
9835
|
-
const
|
|
9839
|
+
const b = `Update the accumulator with short themes from this text. Avoid duplicates. Return ONLY a comma-separated list of themes with no explanation or additional text.${s ? `
|
|
9836
9840
|
|
|
9837
|
-
${s}` : ""}`, f = Wn(
|
|
9838
|
-
c = (await Ie(f,
|
|
9841
|
+
${s}` : ""}`, f = Wn(h);
|
|
9842
|
+
c = (await Ie(f, b, {
|
|
9839
9843
|
...o,
|
|
9840
9844
|
onProgress: L(o.onProgress, "themes:extract")
|
|
9841
|
-
})).split(",").map((
|
|
9845
|
+
})).split(",").map((m) => m.trim()).filter(Boolean);
|
|
9842
9846
|
}
|
|
9843
9847
|
i.emit({
|
|
9844
9848
|
event: k.phase,
|
|
@@ -9848,7 +9852,7 @@ ${s}` : ""}`, f = Wn(m);
|
|
|
9848
9852
|
const u = `Refine the accumulator by merging similar themes. ${a ? `Limit to the top ${a} themes.` : "Return all meaningful themes."} Return ONLY a comma-separated list with no explanation or additional text.`, d = (await Ie(c, u, {
|
|
9849
9853
|
...o,
|
|
9850
9854
|
onProgress: L(o.onProgress, "themes:refine")
|
|
9851
|
-
})).split(",").map((
|
|
9855
|
+
})).split(",").map((h) => h.trim()).filter(Boolean);
|
|
9852
9856
|
return i.complete({ outcome: T.success, themes: d.length }), d;
|
|
9853
9857
|
} catch (c) {
|
|
9854
9858
|
throw i.error(c), c;
|
|
@@ -9927,25 +9931,25 @@ async function Qa(e, t, n) {
|
|
|
9927
9931
|
overlap: u,
|
|
9928
9932
|
maxParallel: p,
|
|
9929
9933
|
errorPosture: d,
|
|
9930
|
-
llmDedup:
|
|
9934
|
+
llmDedup: h,
|
|
9931
9935
|
knowledgeBase: y,
|
|
9932
|
-
enrichMap:
|
|
9936
|
+
enrichMap: b
|
|
9933
9937
|
} = await q(i, {
|
|
9934
9938
|
enrichment: J(zw, ["llmDedup", "knowledgeBase", "enrichMap"]),
|
|
9935
9939
|
chunkSize: 2e3,
|
|
9936
9940
|
overlap: 200,
|
|
9937
9941
|
maxParallel: 3,
|
|
9938
9942
|
errorPosture: z.resilient
|
|
9939
|
-
}), f = s.knowledge, { onProgress: g, batchSize:
|
|
9943
|
+
}), f = s.knowledge, { onProgress: g, batchSize: m, now: w } = i;
|
|
9940
9944
|
try {
|
|
9941
|
-
const
|
|
9945
|
+
const S = 1 + (h ? 1 : 0) + (y ? 2 : 0), v = c.batch(S), P = Kn(e, l, { overlap: u }), x = [];
|
|
9942
9946
|
let E = 0;
|
|
9943
9947
|
await Q(
|
|
9944
9948
|
P,
|
|
9945
9949
|
async (j, F) => {
|
|
9946
9950
|
try {
|
|
9947
9951
|
const V = await M(
|
|
9948
|
-
() => Vw(j, { ...i, now:
|
|
9952
|
+
() => Vw(j, { ...i, now: w, systemPrompt: a }),
|
|
9949
9953
|
{
|
|
9950
9954
|
label: `timeline chunk ${F + 1}`,
|
|
9951
9955
|
config: i
|
|
@@ -9966,9 +9970,9 @@ async function Qa(e, t, n) {
|
|
|
9966
9970
|
label: "timeline chunks",
|
|
9967
9971
|
abortSignal: i.abortSignal
|
|
9968
9972
|
}
|
|
9969
|
-
), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`),
|
|
9973
|
+
), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`), v(1);
|
|
9970
9974
|
let O = Ww([x]);
|
|
9971
|
-
if (
|
|
9975
|
+
if (h && O.length > 0) {
|
|
9972
9976
|
const j = O.map((H) => `- ${H.timestamp}: ${H.name}`).join(`
|
|
9973
9977
|
`), F = `Consolidate these timeline events by merging duplicates that refer to the same occurrence. Keep the most descriptive version of each event and preserve ALL unique events.
|
|
9974
9978
|
|
|
@@ -9977,7 +9981,7 @@ ${$(j, { tag: "events" })}`, V = await _(F, {
|
|
|
9977
9981
|
systemPrompt: "You are a timeline deduplication engine. Return all unique events, merging only true duplicates.",
|
|
9978
9982
|
responseFormat: C(Le.name, Le.schema)
|
|
9979
9983
|
}), Y = V?.events || V;
|
|
9980
|
-
Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)),
|
|
9984
|
+
Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)), v(1);
|
|
9981
9985
|
}
|
|
9982
9986
|
if ((y || f) && O.length > 0) {
|
|
9983
9987
|
let j = [];
|
|
@@ -10002,7 +10006,7 @@ Return as JSON with the same event format, maintaining chronological order.`, ie
|
|
|
10002
10006
|
...i,
|
|
10003
10007
|
initial: JSON.stringify({ events: [] }),
|
|
10004
10008
|
responseFormat: C(Le.name, Le.schema),
|
|
10005
|
-
...
|
|
10009
|
+
...m !== void 0 && { batchSize: m },
|
|
10006
10010
|
onProgress: L(i.onProgress, "reduce:knowledge-base")
|
|
10007
10011
|
});
|
|
10008
10012
|
try {
|
|
@@ -10011,7 +10015,7 @@ Return as JSON with the same event format, maintaining chronological order.`, ie
|
|
|
10011
10015
|
ne("Failed to parse knowledge base:", Z.message);
|
|
10012
10016
|
}
|
|
10013
10017
|
}
|
|
10014
|
-
c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }),
|
|
10018
|
+
c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }), v(1);
|
|
10015
10019
|
const F = j.map((G) => `- ${G.timestamp}: ${G.name}`).join(`
|
|
10016
10020
|
`), V = `Given an extracted event, enrich it using this knowledge base:
|
|
10017
10021
|
|
|
@@ -10028,7 +10032,7 @@ Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate t
|
|
|
10028
10032
|
V,
|
|
10029
10033
|
{
|
|
10030
10034
|
...i,
|
|
10031
|
-
...
|
|
10035
|
+
...m !== void 0 && { batchSize: m },
|
|
10032
10036
|
maxParallel: p,
|
|
10033
10037
|
onProgress: L(i.onProgress, "map:enrichment")
|
|
10034
10038
|
}
|
|
@@ -10045,12 +10049,12 @@ Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate t
|
|
|
10045
10049
|
}
|
|
10046
10050
|
return O[te];
|
|
10047
10051
|
}), ee = new Set(H.map((G) => G.name.toLowerCase())), pe = j.filter((G) => !ee.has(G.name.toLowerCase()));
|
|
10048
|
-
O = Ke([...H, ...pe]),
|
|
10052
|
+
O = Ke([...H, ...pe]), v(1);
|
|
10049
10053
|
}
|
|
10050
10054
|
const R = E > 0 ? T.partial : T.success;
|
|
10051
10055
|
return c.complete({ outcome: R }), O;
|
|
10052
|
-
} catch (
|
|
10053
|
-
throw c.error(
|
|
10056
|
+
} catch (S) {
|
|
10057
|
+
throw c.error(S), S;
|
|
10054
10058
|
}
|
|
10055
10059
|
}
|
|
10056
10060
|
Qa.knownTexts = ["knowledge"];
|
|
@@ -10175,19 +10179,19 @@ async function tc(e, t, n) {
|
|
|
10175
10179
|
try {
|
|
10176
10180
|
const l = Zw(e, a), p = [...l].reverse().map((g) => g.text), d = s ? `
|
|
10177
10181
|
|
|
10178
|
-
${s}` : "",
|
|
10182
|
+
${s}` : "", h = `${$(r, { tag: "removal_criteria" })}
|
|
10179
10183
|
|
|
10180
10184
|
NOTE: These text blocks are in REVERSE order (from end to beginning of document).
|
|
10181
10185
|
Score how important THE ENTIRE TEXT BLOCK is to KEEP in the document (0 = should be removed, 10 = must keep).
|
|
10182
10186
|
Each item in the list is ONE complete text block - evaluate it as a whole unit.
|
|
10183
|
-
Consider the removal criteria above when scoring.${d}`,
|
|
10187
|
+
Consider the removal criteria above when scoring.${d}`, b = (await ke(p, h, {
|
|
10184
10188
|
...o,
|
|
10185
10189
|
onProgress: L(o.onProgress, "score:relevance")
|
|
10186
10190
|
// Don't use stopOnThreshold - we need all scores to find high ones
|
|
10187
10191
|
})).findIndex((g) => (g ?? 1 / 0) < c);
|
|
10188
10192
|
let f;
|
|
10189
|
-
if (
|
|
10190
|
-
const g = l.length - 1 -
|
|
10193
|
+
if (b >= 0) {
|
|
10194
|
+
const g = l.length - 1 - b;
|
|
10191
10195
|
g > 0 ? f = l[g - 1].endIndex : f = 0;
|
|
10192
10196
|
} else
|
|
10193
10197
|
f = e.length;
|
|
@@ -10254,12 +10258,12 @@ ${r}` : "", o = A(Us, { llm: { sensitive: !0 }, ...t }), i = I(Us, o.onProgress,
|
|
|
10254
10258
|
const u = i.batch(l.length), p = await Q(
|
|
10255
10259
|
l,
|
|
10256
10260
|
async (d) => {
|
|
10257
|
-
const
|
|
10261
|
+
const h = await M(() => _(d, { ...o, responseFormat: tv }), {
|
|
10258
10262
|
label: "veiled-variants",
|
|
10259
10263
|
config: o,
|
|
10260
10264
|
onProgress: L(o.onProgress, "strategy")
|
|
10261
10265
|
});
|
|
10262
|
-
return u(1),
|
|
10266
|
+
return u(1), h;
|
|
10263
10267
|
},
|
|
10264
10268
|
{ maxParallel: 3, errorPosture: z.resilient, abortSignal: o.abortSignal }
|
|
10265
10269
|
);
|
|
@@ -10363,22 +10367,22 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
|
|
|
10363
10367
|
w: f.info.width,
|
|
10364
10368
|
h: f.info.height
|
|
10365
10369
|
})), l = Math.ceil(e.length / t), u = Array.from({ length: t }, (f, g) => {
|
|
10366
|
-
const
|
|
10367
|
-
return
|
|
10368
|
-
}), p = u.reduce((f, g) => f + g, 0) + r * (t - 1), d = l * n + r * (l - 1),
|
|
10370
|
+
const m = c.filter((w, S) => S % t === g);
|
|
10371
|
+
return m.length > 0 ? Math.max(...m.map((w) => w.w)) : 0;
|
|
10372
|
+
}), p = u.reduce((f, g) => f + g, 0) + r * (t - 1), d = l * n + r * (l - 1), h = [];
|
|
10369
10373
|
for (let f = 0; f < c.length; f++) {
|
|
10370
|
-
const g = f % t,
|
|
10371
|
-
if (c[f].x =
|
|
10372
|
-
const
|
|
10373
|
-
`<svg width="${c[f].w}" height="${
|
|
10374
|
-
<rect x="0" y="0" width="${c[f].w}" height="${
|
|
10375
|
-
<text x="4" y="${
|
|
10374
|
+
const g = f % t, m = Math.floor(f / t), w = u.slice(0, g).reduce((v, P) => v + P, 0) + r * g, S = m * (n + r);
|
|
10375
|
+
if (c[f].x = w, c[f].y = S, h.push({ input: a[f].data, left: w, top: S }), c[f].label) {
|
|
10376
|
+
const v = Math.min(24, c[f].h), P = Math.min(14, v - 2), x = c[f].label.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """), E = Buffer.from(
|
|
10377
|
+
`<svg width="${c[f].w}" height="${v}">
|
|
10378
|
+
<rect x="0" y="0" width="${c[f].w}" height="${v}" fill="rgba(0,0,0,0.6)"/>
|
|
10379
|
+
<text x="4" y="${v - 3}" font-family="sans-serif" font-size="${P}" fill="white">${x}</text>
|
|
10376
10380
|
</svg>`
|
|
10377
10381
|
);
|
|
10378
|
-
|
|
10382
|
+
h.push({
|
|
10379
10383
|
input: E,
|
|
10380
|
-
left:
|
|
10381
|
-
top:
|
|
10384
|
+
left: w,
|
|
10385
|
+
top: S + c[f].h - v
|
|
10382
10386
|
});
|
|
10383
10387
|
}
|
|
10384
10388
|
}
|
|
@@ -10390,13 +10394,13 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
|
|
|
10390
10394
|
channels: 3,
|
|
10391
10395
|
background: { r: 128, g: 128, b: 128 }
|
|
10392
10396
|
}
|
|
10393
|
-
}).composite(
|
|
10394
|
-
const
|
|
10397
|
+
}).composite(h).jpeg({ quality: s }).toFile(y);
|
|
10398
|
+
const b = await go(y);
|
|
10395
10399
|
return {
|
|
10396
10400
|
path: y,
|
|
10397
10401
|
width: p,
|
|
10398
10402
|
height: d,
|
|
10399
|
-
sizeBytes:
|
|
10403
|
+
sizeBytes: b.size,
|
|
10400
10404
|
tiles: c
|
|
10401
10405
|
};
|
|
10402
10406
|
}
|
|
@@ -10426,28 +10430,28 @@ ${s}` : r, i = A(Vs, n), a = I(Vs, i.onProgress, i);
|
|
|
10426
10430
|
}), p = u && c.length > 1;
|
|
10427
10431
|
let d;
|
|
10428
10432
|
if (p) {
|
|
10429
|
-
const f = c.map((
|
|
10433
|
+
const f = c.map((S) => S.path), g = c.map((S) => S.label).filter(Boolean), m = await pv(f, {
|
|
10430
10434
|
labels: g.length > 0 ? g : void 0
|
|
10431
10435
|
});
|
|
10432
10436
|
a.emit({
|
|
10433
10437
|
event: "tile",
|
|
10434
|
-
path:
|
|
10435
|
-
width:
|
|
10436
|
-
height:
|
|
10437
|
-
sizeBytes:
|
|
10438
|
-
}), d = [await Ws(
|
|
10438
|
+
path: m.path,
|
|
10439
|
+
width: m.width,
|
|
10440
|
+
height: m.height,
|
|
10441
|
+
sizeBytes: m.sizeBytes
|
|
10442
|
+
}), d = [await Ws(m.path)];
|
|
10439
10443
|
} else
|
|
10440
10444
|
d = await Q(c, (f) => Ws(f.path), {
|
|
10441
10445
|
maxParallel: 4,
|
|
10442
10446
|
label: "analyze-image:encode",
|
|
10443
10447
|
abortSignal: i.abortSignal
|
|
10444
10448
|
});
|
|
10445
|
-
const
|
|
10449
|
+
const h = Zo(o, d), y = i.responseFormat ? i : { ...i, responseFormat: dv }, b = await M(() => _(h, y), {
|
|
10446
10450
|
label: "analyze-image:llm",
|
|
10447
10451
|
config: i,
|
|
10448
10452
|
onProgress: L(i.onProgress, "llm")
|
|
10449
10453
|
});
|
|
10450
|
-
return a.complete({ outcome: T.success, imageCount: l, tiled: p }),
|
|
10454
|
+
return a.complete({ outcome: T.success, imageCount: l, tiled: p }), b;
|
|
10451
10455
|
} catch (u) {
|
|
10452
10456
|
throw a.error(u, { imageCount: l }), u;
|
|
10453
10457
|
}
|
|
@@ -10491,7 +10495,7 @@ ${r}` : n, o = A(Js, t), i = I(Js, o.onProgress, o);
|
|
|
10491
10495
|
functionArgsAsArray: [l]
|
|
10492
10496
|
};
|
|
10493
10497
|
else {
|
|
10494
|
-
const
|
|
10498
|
+
const h = p.arguments, y = Array.isArray(h) ? h : [h];
|
|
10495
10499
|
d = {
|
|
10496
10500
|
...p,
|
|
10497
10501
|
functionArgsAsArray: y,
|
|
@@ -10838,15 +10842,15 @@ function mc(e = {}) {
|
|
|
10838
10842
|
const t = A(Qs, e), n = I(Qs, t.onProgress, t);
|
|
10839
10843
|
n.start();
|
|
10840
10844
|
try {
|
|
10841
|
-
let g = function(
|
|
10842
|
-
const
|
|
10845
|
+
let g = function(m, w = "log", S = 0) {
|
|
10846
|
+
const v = Ov(S), P = {
|
|
10843
10847
|
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
10844
10848
|
ts: /* @__PURE__ */ new Date(),
|
|
10845
|
-
raw:
|
|
10849
|
+
raw: m,
|
|
10846
10850
|
// Store original data as-is (any structure)
|
|
10847
10851
|
meta: /* @__PURE__ */ new Map([
|
|
10848
|
-
["level",
|
|
10849
|
-
["fileContext",
|
|
10852
|
+
["level", w],
|
|
10853
|
+
["fileContext", v]
|
|
10850
10854
|
]),
|
|
10851
10855
|
attachments: {},
|
|
10852
10856
|
// AI enrichments to merge
|
|
@@ -10857,41 +10861,41 @@ function mc(e = {}) {
|
|
|
10857
10861
|
for (const x of s)
|
|
10858
10862
|
if (!x.filters || x.filters(P)) {
|
|
10859
10863
|
let E;
|
|
10860
|
-
|
|
10861
|
-
data:
|
|
10864
|
+
m == null ? E = {
|
|
10865
|
+
data: m,
|
|
10862
10866
|
id: P.id,
|
|
10863
10867
|
ts: P.ts,
|
|
10864
|
-
level:
|
|
10868
|
+
level: w,
|
|
10865
10869
|
...P.attachments
|
|
10866
|
-
} : typeof
|
|
10867
|
-
data:
|
|
10870
|
+
} : typeof m == "string" || typeof m == "number" || typeof m == "boolean" ? E = {
|
|
10871
|
+
data: m,
|
|
10868
10872
|
id: P.id,
|
|
10869
10873
|
ts: P.ts,
|
|
10870
|
-
level:
|
|
10874
|
+
level: w,
|
|
10871
10875
|
...P.attachments
|
|
10872
|
-
} : typeof
|
|
10873
|
-
...
|
|
10876
|
+
} : typeof m == "object" ? E = {
|
|
10877
|
+
...m,
|
|
10874
10878
|
// Spread all original properties
|
|
10875
10879
|
...P.attachments,
|
|
10876
10880
|
// Merge AI enrichments
|
|
10877
10881
|
// Add internal metadata only if not already present
|
|
10878
|
-
...
|
|
10879
|
-
...
|
|
10880
|
-
...
|
|
10882
|
+
...m.id ? {} : { id: P.id },
|
|
10883
|
+
...m.ts ? {} : { ts: P.ts },
|
|
10884
|
+
...m.level ? {} : { level: w },
|
|
10881
10885
|
// Add file context
|
|
10882
|
-
...
|
|
10883
|
-
...
|
|
10886
|
+
...m.file ? {} : { file: v.filePath },
|
|
10887
|
+
...m.line ? {} : { line: v.line }
|
|
10884
10888
|
} : E = {
|
|
10885
|
-
data:
|
|
10889
|
+
data: m,
|
|
10886
10890
|
id: P.id,
|
|
10887
10891
|
ts: P.ts,
|
|
10888
|
-
level:
|
|
10892
|
+
level: w,
|
|
10889
10893
|
...P.attachments
|
|
10890
10894
|
}, E.aiMeta = P.aiMeta, d.get(x.laneId).push(E);
|
|
10891
10895
|
}
|
|
10892
10896
|
if (a && f(), p) {
|
|
10893
|
-
const x = `LLM Logger processed: ${JSON.stringify(
|
|
10894
|
-
switch (
|
|
10897
|
+
const x = `LLM Logger processed: ${JSON.stringify(m)}`;
|
|
10898
|
+
switch (w) {
|
|
10895
10899
|
case "error":
|
|
10896
10900
|
p.error(x);
|
|
10897
10901
|
break;
|
|
@@ -10923,19 +10927,19 @@ function mc(e = {}) {
|
|
|
10923
10927
|
immediateFlush: a = !1,
|
|
10924
10928
|
hostLogger: c = void 0
|
|
10925
10929
|
} = e, l = new Mn(r), u = [], p = c ? Hs(c) : void 0, d = /* @__PURE__ */ new Map();
|
|
10926
|
-
s.forEach((
|
|
10927
|
-
Iv(
|
|
10930
|
+
s.forEach((m) => {
|
|
10931
|
+
Iv(m.laneId !== void 0, "Each lane must have an laneId property").toBe(!0), d.set(m.laneId, []);
|
|
10928
10932
|
});
|
|
10929
|
-
const
|
|
10930
|
-
let
|
|
10931
|
-
o.forEach((
|
|
10932
|
-
const
|
|
10933
|
-
y.set(
|
|
10934
|
-
const
|
|
10935
|
-
if (!
|
|
10933
|
+
const h = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
|
|
10934
|
+
let b = !1;
|
|
10935
|
+
o.forEach((m) => {
|
|
10936
|
+
const w = l.registerReader();
|
|
10937
|
+
y.set(m.processorId, w), h.set(m.processorId, -1);
|
|
10938
|
+
const S = m.batchSize || 10, v = async () => {
|
|
10939
|
+
if (!b)
|
|
10936
10940
|
try {
|
|
10937
|
-
const P = await l.readBatch(
|
|
10938
|
-
# Processor: ${
|
|
10941
|
+
const P = await l.readBatch(w, S, m.batchTimeout), x = Cv(P.data), O = `# Log Processing Context
|
|
10942
|
+
# Processor: ${m.processorId} (${m.description || "No description"})
|
|
10939
10943
|
# Batch size: ${P.data.length} logs
|
|
10940
10944
|
# Task: Analyze the following NDJSON log entries and return bulk adjustments
|
|
10941
10945
|
#
|
|
@@ -10955,7 +10959,7 @@ function mc(e = {}) {
|
|
|
10955
10959
|
# ]
|
|
10956
10960
|
#
|
|
10957
10961
|
# NDJSON Log Data:
|
|
10958
|
-
` + x, R = await
|
|
10962
|
+
` + x, R = await m.process(O);
|
|
10959
10963
|
if (Array.isArray(R))
|
|
10960
10964
|
for (const j of R) {
|
|
10961
10965
|
const F = u.findIndex((V) => V.id === j.logId);
|
|
@@ -10967,53 +10971,53 @@ function mc(e = {}) {
|
|
|
10967
10971
|
j.aiMeta && (V.aiMeta || (V.aiMeta = {}), Object.assign(V.aiMeta, j.aiMeta));
|
|
10968
10972
|
}
|
|
10969
10973
|
}
|
|
10970
|
-
|
|
10974
|
+
h.set(m.processorId, P.lastOffset), b || setTimeout(v, 0);
|
|
10971
10975
|
} catch (P) {
|
|
10972
|
-
p && p.error(`Processor ${
|
|
10976
|
+
p && p.error(`Processor ${m.processorId} error: ${P.message}`), b || setTimeout(v, 1e3);
|
|
10973
10977
|
}
|
|
10974
10978
|
};
|
|
10975
|
-
|
|
10979
|
+
v();
|
|
10976
10980
|
});
|
|
10977
10981
|
const f = () => {
|
|
10978
|
-
for (const [
|
|
10979
|
-
if (
|
|
10980
|
-
const
|
|
10981
|
-
if (
|
|
10982
|
-
const
|
|
10983
|
-
|
|
10982
|
+
for (const [m, w] of d)
|
|
10983
|
+
if (w.length > 0) {
|
|
10984
|
+
const S = s.find((v) => v.laneId === m);
|
|
10985
|
+
if (S) {
|
|
10986
|
+
const v = w.filter((P) => !P.aiMeta?.skip);
|
|
10987
|
+
v.length > 0 && S.writer(v), w.length = 0;
|
|
10984
10988
|
}
|
|
10985
10989
|
}
|
|
10986
10990
|
};
|
|
10987
|
-
return a || s.forEach((
|
|
10988
|
-
const
|
|
10989
|
-
|
|
10991
|
+
return a || s.forEach((m) => {
|
|
10992
|
+
const w = () => {
|
|
10993
|
+
b || (f(), setTimeout(w, i));
|
|
10990
10994
|
};
|
|
10991
|
-
|
|
10995
|
+
w();
|
|
10992
10996
|
}), n.complete({
|
|
10993
10997
|
outcome: T.success,
|
|
10994
10998
|
lanes: s.length,
|
|
10995
10999
|
processors: o.length
|
|
10996
11000
|
}), {
|
|
10997
11001
|
// Standard logger interface - accepts any structured data
|
|
10998
|
-
log: (
|
|
10999
|
-
info: (
|
|
11000
|
-
warn: (
|
|
11001
|
-
error: (
|
|
11002
|
-
debug: (
|
|
11003
|
-
trace: (
|
|
11004
|
-
fatal: (
|
|
11002
|
+
log: (m, w = 0) => g(m, "log", w),
|
|
11003
|
+
info: (m, w = 0) => g(m, "info", w),
|
|
11004
|
+
warn: (m, w = 0) => g(m, "warn", w),
|
|
11005
|
+
error: (m, w = 0) => g(m, "error", w),
|
|
11006
|
+
debug: (m, w = 0) => g(m, "debug", w),
|
|
11007
|
+
trace: (m, w = 0) => g(m, "trace", w),
|
|
11008
|
+
fatal: (m, w = 0) => g(m, "fatal", w),
|
|
11005
11009
|
// Enhanced attachment API
|
|
11006
|
-
attachToLog: (
|
|
11007
|
-
const
|
|
11008
|
-
return
|
|
11010
|
+
attachToLog: (m, w, S) => {
|
|
11011
|
+
const v = u.findIndex((P) => P.id === m);
|
|
11012
|
+
return v !== -1 ? (Ys(u[v].attachments, w, S), !0) : !1;
|
|
11009
11013
|
},
|
|
11010
|
-
getLogAttachment: (
|
|
11011
|
-
const
|
|
11012
|
-
return
|
|
11014
|
+
getLogAttachment: (m, w) => {
|
|
11015
|
+
const S = u.find((v) => v.id === m);
|
|
11016
|
+
return S ? _v(S.attachments, w) : void 0;
|
|
11013
11017
|
},
|
|
11014
|
-
markLogSkippable: (
|
|
11015
|
-
const
|
|
11016
|
-
return
|
|
11018
|
+
markLogSkippable: (m, w = !0) => {
|
|
11019
|
+
const S = u.findIndex((v) => v.id === m);
|
|
11020
|
+
return S !== -1 ? (u[S].aiMeta.skip = w, !0) : !1;
|
|
11017
11021
|
},
|
|
11018
11022
|
// Ring buffer access - legacy API compatibility
|
|
11019
11023
|
ringBuffer: {
|
|
@@ -11022,27 +11026,27 @@ function mc(e = {}) {
|
|
|
11022
11026
|
clear: () => {
|
|
11023
11027
|
u.length = 0, l.clear();
|
|
11024
11028
|
},
|
|
11025
|
-
tail: (
|
|
11026
|
-
head: (
|
|
11027
|
-
filter: (
|
|
11029
|
+
tail: (m) => u.slice(-m),
|
|
11030
|
+
head: (m) => u.slice(0, m),
|
|
11031
|
+
filter: (m) => u.filter(m)
|
|
11028
11032
|
},
|
|
11029
11033
|
// Processor status
|
|
11030
|
-
getProcessorOffsets: () => new Map(
|
|
11034
|
+
getProcessorOffsets: () => new Map(h),
|
|
11031
11035
|
// Host logger integration
|
|
11032
|
-
setHostLogger: (
|
|
11036
|
+
setHostLogger: (m) => (e.hostLogger = m, Hs(m)),
|
|
11033
11037
|
// Utility methods
|
|
11034
11038
|
flush: () => {
|
|
11035
11039
|
f();
|
|
11036
11040
|
},
|
|
11037
11041
|
clear: () => {
|
|
11038
11042
|
u.length = 0, l.clear();
|
|
11039
|
-
for (const
|
|
11040
|
-
|
|
11043
|
+
for (const m of d.values())
|
|
11044
|
+
m.length = 0;
|
|
11041
11045
|
},
|
|
11042
11046
|
destroy: () => {
|
|
11043
|
-
|
|
11044
|
-
for (const
|
|
11045
|
-
|
|
11047
|
+
b = !0, f(), u.length = 0, l.clear();
|
|
11048
|
+
for (const m of d.values())
|
|
11049
|
+
m.length = 0;
|
|
11046
11050
|
},
|
|
11047
11051
|
getConfig: () => ({
|
|
11048
11052
|
ringBufferSize: r,
|
|
@@ -11053,22 +11057,22 @@ function mc(e = {}) {
|
|
|
11053
11057
|
}),
|
|
11054
11058
|
getStats: () => ({
|
|
11055
11059
|
...l.getStats(),
|
|
11056
|
-
processorOffsets: Object.fromEntries(
|
|
11057
|
-
processors: o.map((
|
|
11058
|
-
id:
|
|
11059
|
-
processedOffset:
|
|
11060
|
+
processorOffsets: Object.fromEntries(h),
|
|
11061
|
+
processors: o.map((m) => ({
|
|
11062
|
+
id: m.processorId,
|
|
11063
|
+
processedOffset: h.get(m.processorId)
|
|
11060
11064
|
}))
|
|
11061
11065
|
}),
|
|
11062
11066
|
// Wait for all processors to catch up to current write position
|
|
11063
|
-
waitForProcessing: async (
|
|
11064
|
-
const
|
|
11065
|
-
if (
|
|
11067
|
+
waitForProcessing: async (m = 3e4) => {
|
|
11068
|
+
const w = Date.now(), v = l.getStats().writeOffset;
|
|
11069
|
+
if (v === 0)
|
|
11066
11070
|
return;
|
|
11067
11071
|
f();
|
|
11068
|
-
const P = (x, E) => E + 1 <
|
|
11069
|
-
for (; Date.now() -
|
|
11072
|
+
const P = (x, E) => E + 1 < v;
|
|
11073
|
+
for (; Date.now() - w < m; ) {
|
|
11070
11074
|
let x = !0;
|
|
11071
|
-
for (const [E, O] of
|
|
11075
|
+
for (const [E, O] of h)
|
|
11072
11076
|
if (P(E, O)) {
|
|
11073
11077
|
x = !1;
|
|
11074
11078
|
break;
|
|
@@ -11081,13 +11085,13 @@ function mc(e = {}) {
|
|
|
11081
11085
|
}
|
|
11082
11086
|
if (p) {
|
|
11083
11087
|
const x = [];
|
|
11084
|
-
for (const [E, O] of
|
|
11088
|
+
for (const [E, O] of h)
|
|
11085
11089
|
if (P(E, O)) {
|
|
11086
|
-
const R =
|
|
11090
|
+
const R = v - O - 1;
|
|
11087
11091
|
x.push(`${E} (${R} logs pending)`);
|
|
11088
11092
|
}
|
|
11089
11093
|
p.warn(
|
|
11090
|
-
`waitForProcessing timeout after ${
|
|
11094
|
+
`waitForProcessing timeout after ${m}ms. Lagging processors: ${x.join(
|
|
11091
11095
|
", "
|
|
11092
11096
|
)}`
|
|
11093
11097
|
);
|
|
@@ -11366,15 +11370,15 @@ function gc({
|
|
|
11366
11370
|
const { text: a, context: c } = N(e, []), l = A(eo, { llm: o, ...i }), u = I(eo, l.onProgress, l);
|
|
11367
11371
|
u.start(), u.emit({ event: k.input, value: a });
|
|
11368
11372
|
const p = l.now ?? /* @__PURE__ */ new Date(), d = u.batch();
|
|
11369
|
-
let
|
|
11373
|
+
let h, y = 0, b = 0, f = r;
|
|
11370
11374
|
const g = [];
|
|
11371
|
-
let
|
|
11372
|
-
const
|
|
11373
|
-
if (!
|
|
11374
|
-
|
|
11375
|
+
let m = !0, w;
|
|
11376
|
+
const S = async () => {
|
|
11377
|
+
if (!m) return;
|
|
11378
|
+
w || (w = await q(l, {
|
|
11375
11379
|
tolerance: J(Wv)
|
|
11376
11380
|
}));
|
|
11377
|
-
const { tolerance: P } =
|
|
11381
|
+
const { tolerance: P } = w;
|
|
11378
11382
|
try {
|
|
11379
11383
|
u.emit({
|
|
11380
11384
|
event: k.step,
|
|
@@ -11420,29 +11424,29 @@ function gc({
|
|
|
11420
11424
|
metric: ge.tickDuration,
|
|
11421
11425
|
value: Date.now() - p.getTime(),
|
|
11422
11426
|
tickNumber: y + 1
|
|
11423
|
-
}),
|
|
11427
|
+
}), b = 0, y += 1, d(1), m && (h = setTimeout(S, j));
|
|
11424
11428
|
} catch (x) {
|
|
11425
|
-
if (ne(`Error in setInterval step: ${x.message}`),
|
|
11429
|
+
if (ne(`Error in setInterval step: ${x.message}`), b += 1, u.emit({
|
|
11426
11430
|
event: k.step,
|
|
11427
11431
|
stepName: "tick-error",
|
|
11428
11432
|
tickNumber: y + 1,
|
|
11429
11433
|
error: x.message,
|
|
11430
|
-
consecutiveErrors:
|
|
11434
|
+
consecutiveErrors: b
|
|
11431
11435
|
}), s && f && await s({
|
|
11432
11436
|
timingString: "error - using fallback",
|
|
11433
11437
|
data: f,
|
|
11434
11438
|
nextDate: new Date(Date.now() + 1e3),
|
|
11435
11439
|
// 1 second fallback
|
|
11436
11440
|
error: x.message
|
|
11437
|
-
}), y += 1, d(1),
|
|
11438
|
-
|
|
11441
|
+
}), y += 1, d(1), b >= P) {
|
|
11442
|
+
m = !1, clearTimeout(h), u.error(x);
|
|
11439
11443
|
return;
|
|
11440
11444
|
}
|
|
11441
|
-
|
|
11445
|
+
m && (h = setTimeout(S, 1e3));
|
|
11442
11446
|
}
|
|
11443
11447
|
};
|
|
11444
|
-
return
|
|
11445
|
-
|
|
11448
|
+
return h = setTimeout(S, 0), () => {
|
|
11449
|
+
m = !1, clearTimeout(h), u.complete({ outcome: T.success, ticks: y });
|
|
11446
11450
|
};
|
|
11447
11451
|
}
|
|
11448
11452
|
gc.knownTexts = [];
|
|
@@ -11513,12 +11517,12 @@ async function Gv(e) {
|
|
|
11513
11517
|
console.error(`[verblets:embed] Loading pipeline model "${t}"…`);
|
|
11514
11518
|
const a = await Xc("feature-extraction", t, { dtype: n });
|
|
11515
11519
|
return console.error(`[verblets:embed] Pipeline model "${t}" ready (${Date.now() - i}ms)`), { embedTexts: async (l, u = {}) => {
|
|
11516
|
-
const { batchSize: p = o, abortSignal: d } = u,
|
|
11517
|
-
for (const
|
|
11520
|
+
const { batchSize: p = o, abortSignal: d } = u, h = dn(l, p), y = [];
|
|
11521
|
+
for (const b of h) {
|
|
11518
11522
|
d?.throwIfAborted();
|
|
11519
|
-
const f = await a(
|
|
11520
|
-
for (let
|
|
11521
|
-
y.push(new Float32Array(f.data.slice(
|
|
11523
|
+
const f = await a(b, { pooling: r, normalize: s }), g = f.dims.at(-1);
|
|
11524
|
+
for (let m = 0; m < b.length; m++)
|
|
11525
|
+
y.push(new Float32Array(f.data.slice(m * g, (m + 1) * g)));
|
|
11522
11526
|
}
|
|
11523
11527
|
return y;
|
|
11524
11528
|
}, embedImages: void 0, dimensions: e.dimensions };
|
|
@@ -11532,21 +11536,21 @@ async function Yv(e) {
|
|
|
11532
11536
|
Hc.from_pretrained(t),
|
|
11533
11537
|
Qc.from_pretrained(t, { dtype: n })
|
|
11534
11538
|
]);
|
|
11535
|
-
return console.error(`[verblets:embed] CLIP model "${t}" ready (${Date.now() - o}ms)`), { embedTexts: async (d,
|
|
11536
|
-
const { batchSize: y = r, abortSignal:
|
|
11537
|
-
for (const
|
|
11538
|
-
|
|
11539
|
-
const
|
|
11540
|
-
for (let x = 0; x <
|
|
11541
|
-
g.push(no(new Float32Array(
|
|
11539
|
+
return console.error(`[verblets:embed] CLIP model "${t}" ready (${Date.now() - o}ms)`), { embedTexts: async (d, h = {}) => {
|
|
11540
|
+
const { batchSize: y = r, abortSignal: b } = h, f = dn(d, y), g = [];
|
|
11541
|
+
for (const m of f) {
|
|
11542
|
+
b?.throwIfAborted();
|
|
11543
|
+
const w = i(m, { padding: !0, truncation: !0 }), v = (await a(w)).text_embeds, P = v.dims[1];
|
|
11544
|
+
for (let x = 0; x < m.length; x++)
|
|
11545
|
+
g.push(no(new Float32Array(v.data.slice(x * P, (x + 1) * P))));
|
|
11542
11546
|
}
|
|
11543
11547
|
return g;
|
|
11544
|
-
}, embedImages: async (d,
|
|
11545
|
-
const { batchSize: y = s, abortSignal:
|
|
11546
|
-
for (const
|
|
11547
|
-
|
|
11548
|
-
const
|
|
11549
|
-
for (let E = 0; E <
|
|
11548
|
+
}, embedImages: async (d, h = {}) => {
|
|
11549
|
+
const { batchSize: y = s, abortSignal: b } = h, f = dn(d, y), g = [];
|
|
11550
|
+
for (const m of f) {
|
|
11551
|
+
b?.throwIfAborted();
|
|
11552
|
+
const w = await Promise.all(m.map((E) => Zc.read(E))), S = await c(w), P = (await l(S)).image_embeds, x = P.dims[1];
|
|
11553
|
+
for (let E = 0; E < m.length; E++)
|
|
11550
11554
|
g.push(no(new Float32Array(P.data.slice(E * x, (E + 1) * x))));
|
|
11551
11555
|
}
|
|
11552
11556
|
return g;
|
|
@@ -11717,8 +11721,8 @@ function Xv(e, t, n) {
|
|
|
11717
11721
|
if (o && i + u > n && c(), u > n) {
|
|
11718
11722
|
const p = l.split(new RegExp("(?<=[.!?])\\s+"));
|
|
11719
11723
|
for (const d of p) {
|
|
11720
|
-
const
|
|
11721
|
-
o && i +
|
|
11724
|
+
const h = or(d).length;
|
|
11725
|
+
o && i + h > n && c(), o += (o ? " " : "") + d, i += h;
|
|
11722
11726
|
}
|
|
11723
11727
|
} else
|
|
11724
11728
|
o += (o ? `
|
|
@@ -11942,8 +11946,8 @@ function aS(e, t, n = {}) {
|
|
|
11942
11946
|
i.push(u);
|
|
11943
11947
|
continue;
|
|
11944
11948
|
}
|
|
11945
|
-
const d = Math.max(0, p - r),
|
|
11946
|
-
o.push({ lo: d, hi:
|
|
11949
|
+
const d = Math.max(0, p - r), h = Math.min(t.length - 1, p + r);
|
|
11950
|
+
o.push({ lo: d, hi: h, score: u.score ?? 0 });
|
|
11947
11951
|
}
|
|
11948
11952
|
const a = o.toSorted((u, p) => u.lo - p.lo), l = _c(a).map(({ lo: u, hi: p, score: d }) => Cc(t, u, p, d));
|
|
11949
11953
|
for (const u of i)
|
|
@@ -12118,24 +12122,24 @@ function TS(e, { cwd: t, timeout: n, abortSignal: r }) {
|
|
|
12118
12122
|
env: PS()
|
|
12119
12123
|
}), l = [], u = [];
|
|
12120
12124
|
let p = !1;
|
|
12121
|
-
c.stdout.on("data", (
|
|
12125
|
+
c.stdout.on("data", (h) => l.push(h)), c.stderr.on("data", (h) => u.push(h));
|
|
12122
12126
|
const d = n ? setTimeout(() => {
|
|
12123
12127
|
c.kill("SIGTERM"), p || (p = !0, o(new Error(`Agent timed out after ${n}ms`)));
|
|
12124
12128
|
}, n) : void 0;
|
|
12125
|
-
if (c.on("close", (
|
|
12129
|
+
if (c.on("close", (h) => {
|
|
12126
12130
|
if (d && clearTimeout(d), p) return;
|
|
12127
12131
|
p = !0;
|
|
12128
|
-
const y = Buffer.concat(l).toString(),
|
|
12129
|
-
if (
|
|
12130
|
-
const f =
|
|
12131
|
-
o(new Error(`Agent exited with code ${
|
|
12132
|
+
const y = Buffer.concat(l).toString(), b = Buffer.concat(u).toString();
|
|
12133
|
+
if (h !== 0 && !y.trim()) {
|
|
12134
|
+
const f = b?.trim() || `exit code ${h}`;
|
|
12135
|
+
o(new Error(`Agent exited with code ${h}: ${f}`));
|
|
12132
12136
|
} else
|
|
12133
12137
|
s(y);
|
|
12134
12138
|
}), r) {
|
|
12135
|
-
const
|
|
12139
|
+
const h = () => {
|
|
12136
12140
|
c.kill("SIGTERM"), p || (p = !0, o(new Error("Agent execution aborted")));
|
|
12137
12141
|
};
|
|
12138
|
-
r.aborted ? (c.kill("SIGTERM"), p = !0, o(new Error("Agent execution aborted"))) : (r.addEventListener("abort",
|
|
12142
|
+
r.aborted ? (c.kill("SIGTERM"), p = !0, o(new Error("Agent execution aborted"))) : (r.addEventListener("abort", h, { once: !0 }), c.on("close", () => r.removeEventListener("abort", h)));
|
|
12139
12143
|
}
|
|
12140
12144
|
});
|
|
12141
12145
|
}
|
|
@@ -12153,23 +12157,23 @@ async function ES(e, t, n = {}) {
|
|
|
12153
12157
|
const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
|
|
12154
12158
|
let d = 0;
|
|
12155
12159
|
try {
|
|
12156
|
-
for (const
|
|
12160
|
+
for (const h of p) {
|
|
12157
12161
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12158
|
-
const y =
|
|
12162
|
+
const y = h.map(async (b, f) => {
|
|
12159
12163
|
const g = d + f;
|
|
12160
12164
|
try {
|
|
12161
|
-
u[g] = await e(
|
|
12162
|
-
} catch (
|
|
12163
|
-
if (s === z.strict) throw
|
|
12164
|
-
u[g] =
|
|
12165
|
+
u[g] = await e(b, g);
|
|
12166
|
+
} catch (m) {
|
|
12167
|
+
if (s === z.strict) throw m;
|
|
12168
|
+
u[g] = b;
|
|
12165
12169
|
}
|
|
12166
12170
|
l(1);
|
|
12167
12171
|
});
|
|
12168
|
-
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y), d +=
|
|
12172
|
+
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y), d += h.length;
|
|
12169
12173
|
}
|
|
12170
12174
|
return c.complete({ outcome: T.success, totalItems: t.length }), u;
|
|
12171
|
-
} catch (
|
|
12172
|
-
throw c.error(
|
|
12175
|
+
} catch (h) {
|
|
12176
|
+
throw c.error(h), h;
|
|
12173
12177
|
}
|
|
12174
12178
|
}
|
|
12175
12179
|
async function IS(e, t, n = {}) {
|
|
@@ -12188,22 +12192,22 @@ async function IS(e, t, n = {}) {
|
|
|
12188
12192
|
try {
|
|
12189
12193
|
for (const y of p) {
|
|
12190
12194
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12191
|
-
const
|
|
12192
|
-
const
|
|
12195
|
+
const b = y.map(async (f, g) => {
|
|
12196
|
+
const m = d + g;
|
|
12193
12197
|
try {
|
|
12194
|
-
u[
|
|
12195
|
-
} catch (
|
|
12196
|
-
if (s === z.strict) throw
|
|
12197
|
-
u[
|
|
12198
|
+
u[m] = await e(f, m);
|
|
12199
|
+
} catch (w) {
|
|
12200
|
+
if (s === z.strict) throw w;
|
|
12201
|
+
u[m] = !1;
|
|
12198
12202
|
}
|
|
12199
12203
|
l(1);
|
|
12200
12204
|
});
|
|
12201
|
-
s === z.strict ? await Promise.all(
|
|
12205
|
+
s === z.strict ? await Promise.all(b) : await Promise.allSettled(b), d += y.length;
|
|
12202
12206
|
}
|
|
12203
|
-
const
|
|
12204
|
-
return c.complete({ outcome: T.success, totalItems: t.length, kept:
|
|
12205
|
-
} catch (
|
|
12206
|
-
throw c.error(
|
|
12207
|
+
const h = t.filter((y, b) => u[b]);
|
|
12208
|
+
return c.complete({ outcome: T.success, totalItems: t.length, kept: h.length }), h;
|
|
12209
|
+
} catch (h) {
|
|
12210
|
+
throw c.error(h), h;
|
|
12207
12211
|
}
|
|
12208
12212
|
}
|
|
12209
12213
|
async function kS(e, t, n = {}) {
|
|
@@ -12222,19 +12226,19 @@ async function kS(e, t, n = {}) {
|
|
|
12222
12226
|
try {
|
|
12223
12227
|
for (const d of u) {
|
|
12224
12228
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12225
|
-
const
|
|
12229
|
+
const h = new Array(d.length), y = d.map(async (f, g) => {
|
|
12226
12230
|
try {
|
|
12227
|
-
|
|
12228
|
-
} catch (
|
|
12229
|
-
if (s === z.strict) throw
|
|
12230
|
-
|
|
12231
|
+
h[g] = { item: f, matched: await e(f, p + g) };
|
|
12232
|
+
} catch (m) {
|
|
12233
|
+
if (s === z.strict) throw m;
|
|
12234
|
+
h[g] = { item: f, matched: !1 };
|
|
12231
12235
|
}
|
|
12232
12236
|
l(1);
|
|
12233
12237
|
});
|
|
12234
12238
|
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y);
|
|
12235
|
-
const
|
|
12236
|
-
if (
|
|
12237
|
-
return c.complete({ outcome: T.success, found: !0 }),
|
|
12239
|
+
const b = h.find((f) => f.matched);
|
|
12240
|
+
if (b)
|
|
12241
|
+
return c.complete({ outcome: T.success, found: !0 }), b.item;
|
|
12238
12242
|
p += d.length;
|
|
12239
12243
|
}
|
|
12240
12244
|
c.complete({ outcome: T.success, found: !1 });
|
|
@@ -12274,29 +12278,29 @@ async function OS(e, t, n = {}) {
|
|
|
12274
12278
|
try {
|
|
12275
12279
|
for (const y of p) {
|
|
12276
12280
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12277
|
-
const
|
|
12278
|
-
const
|
|
12281
|
+
const b = y.map(async (f, g) => {
|
|
12282
|
+
const m = d + g;
|
|
12279
12283
|
try {
|
|
12280
|
-
u[
|
|
12281
|
-
} catch (
|
|
12282
|
-
if (s === z.strict) throw
|
|
12283
|
-
u[
|
|
12284
|
+
u[m] = await e(f, m);
|
|
12285
|
+
} catch (w) {
|
|
12286
|
+
if (s === z.strict) throw w;
|
|
12287
|
+
u[m] = "other";
|
|
12284
12288
|
}
|
|
12285
12289
|
l(1);
|
|
12286
12290
|
});
|
|
12287
|
-
s === z.strict ? await Promise.all(
|
|
12291
|
+
s === z.strict ? await Promise.all(b) : await Promise.allSettled(b), d += y.length;
|
|
12288
12292
|
}
|
|
12289
|
-
const
|
|
12290
|
-
return t.forEach((y,
|
|
12291
|
-
const f = String(u[
|
|
12292
|
-
|
|
12293
|
+
const h = {};
|
|
12294
|
+
return t.forEach((y, b) => {
|
|
12295
|
+
const f = String(u[b] ?? "other");
|
|
12296
|
+
h[f] || (h[f] = []), h[f].push(y);
|
|
12293
12297
|
}), c.complete({
|
|
12294
12298
|
outcome: T.success,
|
|
12295
12299
|
totalItems: t.length,
|
|
12296
|
-
groupCount: Object.keys(
|
|
12297
|
-
}),
|
|
12298
|
-
} catch (
|
|
12299
|
-
throw c.error(
|
|
12300
|
+
groupCount: Object.keys(h).length
|
|
12301
|
+
}), h;
|
|
12302
|
+
} catch (h) {
|
|
12303
|
+
throw c.error(h), h;
|
|
12300
12304
|
}
|
|
12301
12305
|
}
|
|
12302
12306
|
async function _S(e, t, n = {}) {
|
|
@@ -12398,8 +12402,8 @@ function MS(e, t, n = {}) {
|
|
|
12398
12402
|
}, t));
|
|
12399
12403
|
}
|
|
12400
12404
|
let l, u;
|
|
12401
|
-
const p = new Promise((y,
|
|
12402
|
-
l = y, u =
|
|
12405
|
+
const p = new Promise((y, b) => {
|
|
12406
|
+
l = y, u = b;
|
|
12403
12407
|
}), d = () => {
|
|
12404
12408
|
if (!i) {
|
|
12405
12409
|
a();
|
|
@@ -12407,8 +12411,8 @@ function MS(e, t, n = {}) {
|
|
|
12407
12411
|
r && r(void 0, y), u(y);
|
|
12408
12412
|
}
|
|
12409
12413
|
};
|
|
12410
|
-
return s?.aborted ? (d(), p) : (s?.addEventListener("abort", d, { once: !0 }), c(), e((y,
|
|
12411
|
-
r && r(y,
|
|
12414
|
+
return s?.aborted ? (d(), p) : (s?.addEventListener("abort", d, { once: !0 }), c(), e((y, b) => {
|
|
12415
|
+
r && r(y, b), c();
|
|
12412
12416
|
}).then((y) => {
|
|
12413
12417
|
i || (a(), l(y));
|
|
12414
12418
|
}).catch((y) => {
|
|
@@ -12630,17 +12634,17 @@ const US = {
|
|
|
12630
12634
|
const s = async (o, i = {}) => {
|
|
12631
12635
|
const { untrusted: a = !1 } = i, c = A(e, { maxAttempts: 3, ...i }), l = typeof n == "function" ? n(o, c) : n, u = typeof t == "function" ? t(o, c) : t, p = I(e, c.onProgress, c);
|
|
12632
12636
|
p.start(), p.emit({ event: k.step, stepName: "analyzing" });
|
|
12633
|
-
const d = r(o, c),
|
|
12637
|
+
const d = r(o, c), h = a ? u + ai : u, y = a ? [ci, ...d] : d, b = await M(
|
|
12634
12638
|
() => _(y.join(`
|
|
12635
12639
|
|
|
12636
12640
|
`), {
|
|
12637
12641
|
...c,
|
|
12638
|
-
systemPrompt:
|
|
12642
|
+
systemPrompt: h,
|
|
12639
12643
|
responseFormat: C(l.name, l.schema)
|
|
12640
12644
|
}),
|
|
12641
12645
|
{ label: e, config: c }
|
|
12642
12646
|
);
|
|
12643
|
-
return ne(`${e}: complete`), p.complete({ outcome: T.success }),
|
|
12647
|
+
return ne(`${e}: complete`), p.complete({ outcome: T.success }), b;
|
|
12644
12648
|
};
|
|
12645
12649
|
return s.with = (o = {}) => (i) => s(i, o), s;
|
|
12646
12650
|
}, co = `You are a prompt structure advisor. You analyze prompt text and propose structural improvements — inputs to add, remove, or modify, and text changes to make the piece work better with external material.
|
|
@@ -12846,11 +12850,11 @@ async function wx({ sourceTexts: e, schema: t }, n = {}) {
|
|
|
12846
12850
|
const l = s.batch(e.length), p = (await Q(
|
|
12847
12851
|
c,
|
|
12848
12852
|
async (d) => {
|
|
12849
|
-
const
|
|
12853
|
+
const h = await bx(d, t, {
|
|
12850
12854
|
...r,
|
|
12851
12855
|
onProgress: L(r.onProgress, "batch")
|
|
12852
12856
|
});
|
|
12853
|
-
return l(d.length),
|
|
12857
|
+
return l(d.length), h;
|
|
12854
12858
|
},
|
|
12855
12859
|
{ maxParallel: o }
|
|
12856
12860
|
)).flat();
|
|
@@ -12971,25 +12975,25 @@ async function Ox(e, t) {
|
|
|
12971
12975
|
async function _x({ fragmentSets: e, schema: t }, n = {}) {
|
|
12972
12976
|
const o = e.flatMap((g) => g.fragments).some((g) => g.image) ? { ...n, embedding: { multi: !0 } } : n, i = [], a = /* @__PURE__ */ new Map(), c = [], l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
|
|
12973
12977
|
for (const g of e)
|
|
12974
|
-
for (const
|
|
12975
|
-
const
|
|
12976
|
-
|
|
12977
|
-
const
|
|
12978
|
-
u.has(
|
|
12979
|
-
const P = u.get(
|
|
12980
|
-
P.has(
|
|
12981
|
-
}
|
|
12982
|
-
const p = i.length > 0 ? await nt(i, o) : [], d = c.length > 0 ? await er(c, o) : [],
|
|
12983
|
-
for (const [g,
|
|
12984
|
-
const
|
|
12985
|
-
for (const [P, x] of
|
|
12986
|
-
const E = x.map(
|
|
12987
|
-
O && (
|
|
12988
|
-
}
|
|
12989
|
-
const
|
|
12990
|
-
y.push({ stateId: g, vectorsByProjectionName:
|
|
12991
|
-
}
|
|
12992
|
-
const
|
|
12978
|
+
for (const m of g.fragments) {
|
|
12979
|
+
const w = !!m.image, S = w ? `img:${m.image}` : `txt:${m.text}`;
|
|
12980
|
+
w && !l.has(m.image) && (l.set(m.image, c.length), c.push(m.image)), !w && !a.has(m.text) && (a.set(m.text, i.length), i.push(m.text));
|
|
12981
|
+
const v = m.sourceIds?.[0] ?? g.fragmentSetId;
|
|
12982
|
+
u.has(v) || u.set(v, /* @__PURE__ */ new Map());
|
|
12983
|
+
const P = u.get(v);
|
|
12984
|
+
P.has(m.projectionName) || P.set(m.projectionName, []), P.get(m.projectionName).push(S);
|
|
12985
|
+
}
|
|
12986
|
+
const p = i.length > 0 ? await nt(i, o) : [], d = c.length > 0 ? await er(c, o) : [], h = (g) => g.startsWith("img:") ? d[l.get(g.slice(4))] : p[a.get(g.slice(4))], y = [];
|
|
12987
|
+
for (const [g, m] of u) {
|
|
12988
|
+
const w = {}, S = [];
|
|
12989
|
+
for (const [P, x] of m) {
|
|
12990
|
+
const E = x.map(h), O = mn(E);
|
|
12991
|
+
O && (w[P] = ft(O), S.push(...E));
|
|
12992
|
+
}
|
|
12993
|
+
const v = S.length > 0 ? ft(mn(S)) : void 0;
|
|
12994
|
+
y.push({ stateId: g, vectorsByProjectionName: w, baseVector: v });
|
|
12995
|
+
}
|
|
12996
|
+
const b = await Ox(t, o), f = b !== t._poles ? { ...t, _poles: b } : t;
|
|
12993
12997
|
return { states: y, schema: f };
|
|
12994
12998
|
}
|
|
12995
12999
|
function Cx({ states: e, editsByProjectionName: t }) {
|
|
@@ -13033,17 +13037,17 @@ function Lc(e, t, n, r) {
|
|
|
13033
13037
|
continue;
|
|
13034
13038
|
}
|
|
13035
13039
|
let u = 0, p = 0, d = 0;
|
|
13036
|
-
for (const [
|
|
13037
|
-
const
|
|
13038
|
-
if (!
|
|
13039
|
-
const
|
|
13040
|
+
for (const [m, w] of Object.entries(c.projectionWeights)) {
|
|
13041
|
+
const S = e.vectorsByProjectionName[m];
|
|
13042
|
+
if (!S) continue;
|
|
13043
|
+
const v = n[m] ?? 1, P = w * v, x = Ix(S, l.low, l.high);
|
|
13040
13044
|
u += x * P, p += P, d += 1;
|
|
13041
13045
|
}
|
|
13042
13046
|
if (p === 0) {
|
|
13043
13047
|
s[c.propertyName] = void 0, o[c.propertyName] = { value: void 0, confidence: 0 };
|
|
13044
13048
|
continue;
|
|
13045
13049
|
}
|
|
13046
|
-
const
|
|
13050
|
+
const h = u / p, y = Nx(h, c.valueRange), b = d / Math.max(1, Object.keys(c.projectionWeights).length), f = Math.min(1, a / 0.5), g = b * f;
|
|
13047
13051
|
s[c.propertyName] = y, o[c.propertyName] = { value: y, confidence: g };
|
|
13048
13052
|
}
|
|
13049
13053
|
return { values: s, details: o };
|
|
@@ -13072,20 +13076,20 @@ async function Lx({ leftStates: e, rightStates: t, intent: n }, r = {}) {
|
|
|
13072
13076
|
const l = Object.entries(s).filter(([p]) => !a.has(p)).filter(([, p]) => p !== 0), u = [];
|
|
13073
13077
|
for (const p of e)
|
|
13074
13078
|
for (const d of t) {
|
|
13075
|
-
let
|
|
13079
|
+
let h = 0, y = 0;
|
|
13076
13080
|
for (const [f, g] of l) {
|
|
13077
|
-
const
|
|
13078
|
-
if (
|
|
13079
|
-
let
|
|
13081
|
+
const m = p.vectorsByProjectionName[f], w = d.vectorsByProjectionName[f];
|
|
13082
|
+
if (m && w) {
|
|
13083
|
+
let S = Pe(m, w);
|
|
13080
13084
|
if (c) {
|
|
13081
|
-
const
|
|
13082
|
-
|
|
13085
|
+
const v = Pe(c, m), P = Pe(c, w);
|
|
13086
|
+
S = S * 0.6 + (v + P) * 0.2;
|
|
13083
13087
|
}
|
|
13084
|
-
|
|
13088
|
+
h += S * g, y += g;
|
|
13085
13089
|
}
|
|
13086
13090
|
}
|
|
13087
|
-
const
|
|
13088
|
-
u.push({ leftStateId: p.stateId, rightStateId: d.stateId, score:
|
|
13091
|
+
const b = y > 0 ? h / y : 0;
|
|
13092
|
+
u.push({ leftStateId: p.stateId, rightStateId: d.stateId, score: b });
|
|
13089
13093
|
}
|
|
13090
13094
|
return u;
|
|
13091
13095
|
}
|
|
@@ -13167,22 +13171,28 @@ function zx(e = {}) {
|
|
|
13167
13171
|
embedModels: a,
|
|
13168
13172
|
embedRules: c,
|
|
13169
13173
|
policy: l,
|
|
13170
|
-
runtimeProvider: u
|
|
13171
|
-
|
|
13172
|
-
|
|
13174
|
+
runtimeProvider: u,
|
|
13175
|
+
llm: p
|
|
13176
|
+
} = e, d = yn();
|
|
13177
|
+
if (d.length > 0)
|
|
13173
13178
|
throw new Error(`Config validation failed:
|
|
13174
|
-
${
|
|
13179
|
+
${d.join(`
|
|
13175
13180
|
`)}`);
|
|
13176
13181
|
u && xo(u);
|
|
13177
|
-
const
|
|
13178
|
-
|
|
13179
|
-
const
|
|
13180
|
-
o &&
|
|
13181
|
-
let
|
|
13182
|
-
|
|
13183
|
-
const
|
|
13184
|
-
|
|
13185
|
-
const
|
|
13182
|
+
const h = t ?? (!!(a || c) || !1);
|
|
13183
|
+
h && Zn(!0), n && ov(!0), r && qx(!0);
|
|
13184
|
+
const y = new Sn();
|
|
13185
|
+
o && y.addModels(o), i && y.setRules(i), l && xp(l);
|
|
13186
|
+
let b;
|
|
13187
|
+
h && (b = new Qn(), a && b.addModels(a), c && b.setRules(c));
|
|
13188
|
+
const f = s ? () => Promise.resolve(s) : void 0, g = Ni();
|
|
13189
|
+
g.setApplication(Ri()), g.setProviders(Mi());
|
|
13190
|
+
const m = {
|
|
13191
|
+
modelService: y,
|
|
13192
|
+
embeddingService: b,
|
|
13193
|
+
getRedis: f,
|
|
13194
|
+
...p !== void 0 ? { llm: p } : {}
|
|
13195
|
+
}, w = /* @__PURE__ */ new Set([
|
|
13186
13196
|
"init",
|
|
13187
13197
|
"config",
|
|
13188
13198
|
"services",
|
|
@@ -13206,23 +13216,23 @@ function zx(e = {}) {
|
|
|
13206
13216
|
"eventToTrace",
|
|
13207
13217
|
"scopePhase",
|
|
13208
13218
|
"nameStep"
|
|
13209
|
-
]),
|
|
13210
|
-
for (const [
|
|
13211
|
-
if (!
|
|
13212
|
-
if (
|
|
13213
|
-
v[
|
|
13214
|
-
Object.entries(
|
|
13219
|
+
]), S = /* @__PURE__ */ new Set(["embedObject"]), v = {};
|
|
13220
|
+
for (const [P, x] of Object.entries(rl))
|
|
13221
|
+
if (!w.has(P)) {
|
|
13222
|
+
if (S.has(P) && typeof x == "object" && x !== null) {
|
|
13223
|
+
v[P] = Object.fromEntries(
|
|
13224
|
+
Object.entries(x).map(([E, O]) => [E, hn(m, O)])
|
|
13215
13225
|
);
|
|
13216
13226
|
continue;
|
|
13217
13227
|
}
|
|
13218
|
-
v[
|
|
13228
|
+
v[P] = hn(m, x);
|
|
13219
13229
|
}
|
|
13220
13230
|
return {
|
|
13221
13231
|
...v,
|
|
13222
|
-
config:
|
|
13223
|
-
modelService:
|
|
13224
|
-
embeddingService:
|
|
13225
|
-
context:
|
|
13232
|
+
config: m,
|
|
13233
|
+
modelService: y,
|
|
13234
|
+
embeddingService: b,
|
|
13235
|
+
context: g
|
|
13226
13236
|
};
|
|
13227
13237
|
}
|
|
13228
13238
|
const Ux = {
|