@far-world-labs/verblets 0.7.1 → 0.7.3
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-CHG_x1Br.js} +933 -922
- 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.3", 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,30 @@ 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.
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4772
|
+
const g = Math.min(f.length, p.length);
|
|
4773
|
+
for (let m = 0; m < g; m++)
|
|
4774
|
+
c[d + m] = f[m];
|
|
4775
|
+
u(p.length);
|
|
4776
|
+
} catch (b) {
|
|
4777
|
+
if (b.name === "AbortError" || n?.abortSignal?.aborted || s === z.strict) throw b;
|
|
4777
4778
|
u(p.length);
|
|
4778
4779
|
}
|
|
4779
4780
|
},
|
|
@@ -4800,28 +4801,32 @@ const Or = async function(e, t, n = {}) {
|
|
|
4800
4801
|
_batchDone: u,
|
|
4801
4802
|
_context: s
|
|
4802
4803
|
});
|
|
4803
|
-
for (let
|
|
4804
|
+
for (let b = 1; b < a; b += 1) {
|
|
4804
4805
|
const f = [], g = [];
|
|
4805
|
-
if (p.forEach((
|
|
4806
|
-
|
|
4806
|
+
if (p.forEach((w, S) => {
|
|
4807
|
+
w === rn && (f.push(S), g.push(e[S]));
|
|
4807
4808
|
}), g.length === 0) break;
|
|
4808
4809
|
(await Or(g, r, {
|
|
4809
4810
|
...o,
|
|
4810
4811
|
maxAttempts: a,
|
|
4811
4812
|
maxParallel: c,
|
|
4812
4813
|
_context: s
|
|
4813
|
-
})).forEach((
|
|
4814
|
-
p[f[
|
|
4814
|
+
})).forEach((w, S) => {
|
|
4815
|
+
p[f[S]] = w;
|
|
4815
4816
|
});
|
|
4816
4817
|
}
|
|
4817
4818
|
let d = 0;
|
|
4818
|
-
for (let
|
|
4819
|
-
p[
|
|
4820
|
-
|
|
4819
|
+
for (let b = 0; b < p.length; b++)
|
|
4820
|
+
p[b] === rn && (p[b] = e[b], d++);
|
|
4821
|
+
if (d === p.length && p.length > 0) {
|
|
4822
|
+
const b = new Error(`map: all ${p.length} items failed to process`);
|
|
4823
|
+
throw i.error(b), b;
|
|
4824
|
+
}
|
|
4825
|
+
const h = d > 0 ? T.partial : T.success, y = {
|
|
4821
4826
|
totalItems: p.length,
|
|
4822
4827
|
successCount: p.length - d,
|
|
4823
4828
|
failedItems: d,
|
|
4824
|
-
outcome:
|
|
4829
|
+
outcome: h
|
|
4825
4830
|
};
|
|
4826
4831
|
return i.emit({ event: k.output, value: p }), i.complete(y), p;
|
|
4827
4832
|
} catch (a) {
|
|
@@ -5014,15 +5019,15 @@ const Nr = {
|
|
|
5014
5019
|
});
|
|
5015
5020
|
let l = i.initial;
|
|
5016
5021
|
(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),
|
|
5022
|
+
const p = await Ae(t, i), d = a.batch(t.length), h = p;
|
|
5018
5023
|
a.progress({
|
|
5019
5024
|
event: W.start,
|
|
5020
5025
|
totalItems: t.length,
|
|
5021
|
-
totalBatches:
|
|
5026
|
+
totalBatches: h.length
|
|
5022
5027
|
});
|
|
5023
|
-
for (const { items:
|
|
5028
|
+
for (const { items: b, skip: f } of p) {
|
|
5024
5029
|
if (f) continue;
|
|
5025
|
-
const g = je(i.listStyle,
|
|
5030
|
+
const g = je(i.listStyle, b, i.autoModeThreshold), m = ({ style: x, count: E }) => {
|
|
5026
5031
|
const O = x === ue.XML ? "XML" : "", R = o ? `
|
|
5027
5032
|
|
|
5028
5033
|
${o}` : "";
|
|
@@ -5042,16 +5047,16 @@ ${$(l !== void 0 ? l : "No initial value - use first item as starting point", {
|
|
|
5042
5047
|
})}
|
|
5043
5048
|
|
|
5044
5049
|
Process exactly ${E} items from the ${O} list below and return the final accumulator value.${R}`;
|
|
5045
|
-
},
|
|
5050
|
+
}, w = i.responseFormat || Sh, S = m({ style: g, count: b.length }), v = {
|
|
5046
5051
|
...i,
|
|
5047
5052
|
listStyle: g,
|
|
5048
|
-
responseFormat:
|
|
5049
|
-
}, P = await M(() => be(
|
|
5053
|
+
responseFormat: w
|
|
5054
|
+
}, P = await M(() => be(b, S, v), {
|
|
5050
5055
|
label: "reduce:batch",
|
|
5051
5056
|
config: i,
|
|
5052
5057
|
onProgress: L(i.onProgress, "batch")
|
|
5053
5058
|
});
|
|
5054
|
-
!i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(
|
|
5059
|
+
!i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(b.length);
|
|
5055
5060
|
}
|
|
5056
5061
|
a.progress({
|
|
5057
5062
|
event: W.complete,
|
|
@@ -5060,7 +5065,7 @@ Process exactly ${E} items from the ${O} list below and return the final accumul
|
|
|
5060
5065
|
});
|
|
5061
5066
|
const y = {
|
|
5062
5067
|
totalItems: t.length,
|
|
5063
|
-
totalBatches:
|
|
5068
|
+
totalBatches: h.length,
|
|
5064
5069
|
outcome: T.success
|
|
5065
5070
|
};
|
|
5066
5071
|
return a.emit({ event: k.output, value: l }), a.complete(y), l;
|
|
@@ -5165,8 +5170,8 @@ async function Ji(e, t = {}) {
|
|
|
5165
5170
|
});
|
|
5166
5171
|
if (p(l.length), !Array.isArray(d))
|
|
5167
5172
|
return r.complete({ outcome: T.success }), [];
|
|
5168
|
-
const
|
|
5169
|
-
return r.emit({ event: k.output, value:
|
|
5173
|
+
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);
|
|
5174
|
+
return r.emit({ event: k.output, value: h }), r.complete({ outcome: T.success }), h;
|
|
5170
5175
|
} catch (p) {
|
|
5171
5176
|
throw r.error(p), p;
|
|
5172
5177
|
}
|
|
@@ -5283,23 +5288,23 @@ Accumulator should track:
|
|
|
5283
5288
|
|
|
5284
5289
|
Return the updated accumulator as valid JSON.`, o].filter(Boolean).join(`
|
|
5285
5290
|
|
|
5286
|
-
`),
|
|
5287
|
-
for (let P = 0; P < u.length; P +=
|
|
5288
|
-
const x = u.slice(P, P +
|
|
5291
|
+
`), b = 20, f = [];
|
|
5292
|
+
for (let P = 0; P < u.length; P += b) {
|
|
5293
|
+
const x = u.slice(P, P + b);
|
|
5289
5294
|
f.push(JSON.stringify(x));
|
|
5290
5295
|
}
|
|
5291
5296
|
a.emit({ event: k.phase, phase: "enriched", enrichedData: u });
|
|
5292
|
-
const
|
|
5297
|
+
const m = await Ie(f, y, {
|
|
5293
5298
|
...i,
|
|
5294
5299
|
initial: JSON.stringify(d),
|
|
5295
5300
|
batchSize: c,
|
|
5296
5301
|
responseFormat: C("analysis_accumulator", p),
|
|
5297
5302
|
onProgress: L(i.onProgress, "reduce:analysis")
|
|
5298
|
-
}),
|
|
5303
|
+
}), S = [`Based on the following analysis of ${l.count} data points for property "${t}", generate threshold recommendations.
|
|
5299
5304
|
|
|
5300
5305
|
${$(s, { tag: "goal" })}
|
|
5301
5306
|
|
|
5302
|
-
${$(JSON.stringify(
|
|
5307
|
+
${$(JSON.stringify(m, null, 2), { tag: "accumulated-analysis" })}
|
|
5303
5308
|
|
|
5304
5309
|
${$(
|
|
5305
5310
|
JSON.stringify(
|
|
@@ -5328,8 +5333,8 @@ Generate specific threshold recommendations that:
|
|
|
5328
5333
|
|
|
5329
5334
|
Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
5330
5335
|
|
|
5331
|
-
`),
|
|
5332
|
-
() => _(
|
|
5336
|
+
`), v = await M(
|
|
5337
|
+
() => _(S, {
|
|
5333
5338
|
...i,
|
|
5334
5339
|
responseFormat: C("threshold_result", Oh)
|
|
5335
5340
|
}),
|
|
@@ -5338,9 +5343,9 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
|
5338
5343
|
config: i
|
|
5339
5344
|
}
|
|
5340
5345
|
);
|
|
5341
|
-
return
|
|
5346
|
+
return v.thresholdCandidates && (v.thresholdCandidates = v.thresholdCandidates.filter((P) => P.value < l.min || P.value > l.max ? (ne(
|
|
5342
5347
|
`Threshold value ${P.value} is outside data range [${l.min}, ${l.max}]`
|
|
5343
|
-
), !1) : !0)),
|
|
5348
|
+
), !1) : !0)), v.distributionAnalysis = {
|
|
5344
5349
|
mean: l.mean,
|
|
5345
5350
|
median: l.median,
|
|
5346
5351
|
standardDeviation: l.stdDev,
|
|
@@ -5348,7 +5353,7 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
|
|
|
5348
5353
|
max: l.max,
|
|
5349
5354
|
percentiles: l.percentiles,
|
|
5350
5355
|
dataPoints: l.count
|
|
5351
|
-
}, a.complete({ outcome: T.success }),
|
|
5356
|
+
}, a.complete({ outcome: T.success }), v;
|
|
5352
5357
|
} catch (l) {
|
|
5353
5358
|
throw a.error(l), l;
|
|
5354
5359
|
}
|
|
@@ -5504,7 +5509,7 @@ async function Xi(e, t, n) {
|
|
|
5504
5509
|
|
|
5505
5510
|
${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
5506
5511
|
a.start(), a.emit({ event: k.input, value: e });
|
|
5507
|
-
const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll:
|
|
5512
|
+
const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll: h } = await q(i, {
|
|
5508
5513
|
precision: J(qh, ["windowSize", "overlapSize"]),
|
|
5509
5514
|
maxParallel: 3,
|
|
5510
5515
|
maxAttempts: void 0,
|
|
@@ -5515,13 +5520,13 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5515
5520
|
return a.complete({ blocksExtracted: 0, outcome: T.success }), [];
|
|
5516
5521
|
try {
|
|
5517
5522
|
const y = e.split(`
|
|
5518
|
-
`),
|
|
5519
|
-
for (let x = 0; x <
|
|
5523
|
+
`), b = y.length, f = [];
|
|
5524
|
+
for (let x = 0; x < b; x += l - u)
|
|
5520
5525
|
f.push(x);
|
|
5521
5526
|
a.emit({
|
|
5522
5527
|
event: k.phase,
|
|
5523
5528
|
phase: "windowing",
|
|
5524
|
-
totalLines:
|
|
5529
|
+
totalLines: b,
|
|
5525
5530
|
windowCount: f.length,
|
|
5526
5531
|
windowSize: l,
|
|
5527
5532
|
overlapSize: u
|
|
@@ -5533,10 +5538,10 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5533
5538
|
totalBatches: f.length,
|
|
5534
5539
|
maxParallel: c
|
|
5535
5540
|
}), a.emit({ event: k.phase, phase: "extraction" });
|
|
5536
|
-
const
|
|
5541
|
+
const m = await Q(
|
|
5537
5542
|
f,
|
|
5538
5543
|
async (x) => {
|
|
5539
|
-
const E = Math.min(x + l,
|
|
5544
|
+
const E = Math.min(x + l, b), O = y.slice(x, E), R = zh(O, x, o), j = await M(
|
|
5540
5545
|
async () => {
|
|
5541
5546
|
const F = await _(R, {
|
|
5542
5547
|
...i,
|
|
@@ -5549,7 +5554,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5549
5554
|
config: i,
|
|
5550
5555
|
maxAttempts: p,
|
|
5551
5556
|
retryMode: d,
|
|
5552
|
-
retryOnAll:
|
|
5557
|
+
retryOnAll: h,
|
|
5553
5558
|
onProgress: L(i.onProgress, "window")
|
|
5554
5559
|
}
|
|
5555
5560
|
);
|
|
@@ -5564,24 +5569,24 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
|
|
|
5564
5569
|
a.emit({
|
|
5565
5570
|
event: k.phase,
|
|
5566
5571
|
phase: "merging",
|
|
5567
|
-
rawBlocks:
|
|
5572
|
+
rawBlocks: m.flat().length
|
|
5568
5573
|
});
|
|
5569
|
-
const
|
|
5570
|
-
for (const x of
|
|
5571
|
-
const E =
|
|
5572
|
-
!E || x.startLine > E.endLine ?
|
|
5574
|
+
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 = [];
|
|
5575
|
+
for (const x of w) {
|
|
5576
|
+
const E = S[S.length - 1];
|
|
5577
|
+
!E || x.startLine > E.endLine ? S.push({ ...x }) : x.endLine > E.endLine && (E.endLine = x.endLine);
|
|
5573
5578
|
}
|
|
5574
|
-
const
|
|
5579
|
+
const v = S.map(
|
|
5575
5580
|
({ startLine: x, endLine: E }) => y.slice(x, E + 1)
|
|
5576
5581
|
);
|
|
5577
5582
|
a.progress({
|
|
5578
5583
|
event: W.complete,
|
|
5579
5584
|
totalItems: f.length,
|
|
5580
5585
|
processedItems: g.count,
|
|
5581
|
-
blocksExtracted:
|
|
5586
|
+
blocksExtracted: v.length
|
|
5582
5587
|
});
|
|
5583
|
-
const P = { blocksExtracted:
|
|
5584
|
-
return a.emit({ event: k.output, value:
|
|
5588
|
+
const P = { blocksExtracted: v.length, outcome: T.success };
|
|
5589
|
+
return a.emit({ event: k.output, value: v }), a.complete(P), v;
|
|
5585
5590
|
} catch (y) {
|
|
5586
5591
|
throw a.error(y), y;
|
|
5587
5592
|
}
|
|
@@ -5628,13 +5633,13 @@ const zr = {
|
|
|
5628
5633
|
maxParallel: p = 3
|
|
5629
5634
|
} = await q(a, {
|
|
5630
5635
|
strictness: J(Uh, ["guidance", "errorPosture"])
|
|
5631
|
-
}), d = o.guidance ?? l,
|
|
5636
|
+
}), d = o.guidance ?? l, h = new Array(t.length), y = await Ae(t, a), b = c.batch(t.length);
|
|
5632
5637
|
c.progress({
|
|
5633
5638
|
event: W.start,
|
|
5634
5639
|
totalItems: t.length,
|
|
5635
5640
|
totalBatches: y.length
|
|
5636
5641
|
});
|
|
5637
|
-
const f = ({ style:
|
|
5642
|
+
const f = ({ style: S, count: v }) => {
|
|
5638
5643
|
const P = d ? `
|
|
5639
5644
|
|
|
5640
5645
|
${$(d, { tag: "borderline-handling" })}` : "", x = i ? `
|
|
@@ -5648,34 +5653,34 @@ IMPORTANT:
|
|
|
5648
5653
|
- Consider all aspects of the filtering criteria
|
|
5649
5654
|
- Return only "yes" or "no" for each item
|
|
5650
5655
|
- Maintain the exact order of the input list${x}`;
|
|
5651
|
-
return
|
|
5656
|
+
return S === ue.NEWLINE ? `${E}
|
|
5652
5657
|
|
|
5653
|
-
Process exactly ${
|
|
5658
|
+
Process exactly ${v} items from the list below and return ${v} yes/no decisions.` : `${E}
|
|
5654
5659
|
|
|
5655
|
-
Process exactly ${
|
|
5660
|
+
Process exactly ${v} items from the XML list below and return ${v} yes/no decisions.`;
|
|
5656
5661
|
};
|
|
5657
5662
|
await Q(
|
|
5658
5663
|
y,
|
|
5659
|
-
async ({ items:
|
|
5660
|
-
const P = je(a.listStyle,
|
|
5664
|
+
async ({ items: S, startIndex: v }) => {
|
|
5665
|
+
const P = je(a.listStyle, S, a.autoModeThreshold), x = f({ style: P, count: S.length }), E = {
|
|
5661
5666
|
...a,
|
|
5662
5667
|
listStyle: P,
|
|
5663
5668
|
responseFormat: a.responseFormat ?? Wh
|
|
5664
5669
|
};
|
|
5665
5670
|
try {
|
|
5666
|
-
const O = await M(() => be(
|
|
5671
|
+
const O = await M(() => be(S, x, E), {
|
|
5667
5672
|
label: "filter:batch",
|
|
5668
5673
|
config: a,
|
|
5669
5674
|
onProgress: L(a.onProgress, "batch")
|
|
5670
5675
|
});
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
}),
|
|
5676
|
+
S.forEach((R, j) => {
|
|
5677
|
+
h[v + j] = O[j]?.toLowerCase().trim() === "yes";
|
|
5678
|
+
}), b(S.length);
|
|
5674
5679
|
} catch (O) {
|
|
5675
5680
|
if (O.name === "AbortError" || a?.abortSignal?.aborted || u === z.strict) throw O;
|
|
5676
|
-
c.error(O, { startIndex:
|
|
5677
|
-
for (let R = 0; R <
|
|
5678
|
-
|
|
5681
|
+
c.error(O, { startIndex: v, itemCount: S.length });
|
|
5682
|
+
for (let R = 0; R < S.length; R++)
|
|
5683
|
+
h[v + R] = !1;
|
|
5679
5684
|
}
|
|
5680
5685
|
},
|
|
5681
5686
|
{
|
|
@@ -5684,14 +5689,14 @@ Process exactly ${S} items from the XML list below and return ${S} yes/no decisi
|
|
|
5684
5689
|
abortSignal: a.abortSignal
|
|
5685
5690
|
}
|
|
5686
5691
|
);
|
|
5687
|
-
const g = t.filter((
|
|
5692
|
+
const g = t.filter((S, v) => h[v]);
|
|
5688
5693
|
c.progress({
|
|
5689
5694
|
event: W.complete,
|
|
5690
5695
|
totalItems: t.length,
|
|
5691
|
-
processedItems:
|
|
5696
|
+
processedItems: b.count
|
|
5692
5697
|
});
|
|
5693
|
-
const
|
|
5694
|
-
return c.emit({ event: k.output, value: g }), c.complete(
|
|
5698
|
+
const m = h.some((S) => S === void 0) ? T.partial : T.success, w = { inputCount: t.length, outputCount: g.length, outcome: m };
|
|
5699
|
+
return c.emit({ event: k.output, value: g }), c.complete(w), g;
|
|
5695
5700
|
};
|
|
5696
5701
|
Zi.knownTexts = ["guidance"];
|
|
5697
5702
|
const Wr = {
|
|
@@ -5719,10 +5724,10 @@ const Wr = {
|
|
|
5719
5724
|
const { maxParallel: c, errorPosture: l } = await q(i, {
|
|
5720
5725
|
maxParallel: 3,
|
|
5721
5726
|
errorPosture: z.resilient
|
|
5722
|
-
}), u = ({ style: g, count:
|
|
5723
|
-
const
|
|
5727
|
+
}), u = ({ style: g, count: m }) => {
|
|
5728
|
+
const w = o ? `
|
|
5724
5729
|
|
|
5725
|
-
${o}` : "",
|
|
5730
|
+
${o}` : "", S = `From the list below, identify and return the SINGLE item that BEST matches the search criteria.
|
|
5726
5731
|
|
|
5727
5732
|
${$(s, { tag: "search-criteria" })}
|
|
5728
5733
|
|
|
@@ -5731,31 +5736,31 @@ IMPORTANT:
|
|
|
5731
5736
|
- Choose the BEST match, not just any match
|
|
5732
5737
|
- Return the complete original item text, unchanged
|
|
5733
5738
|
- 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 ? `${
|
|
5739
|
+
- Return ONLY ONE item, even if multiple items match${w}`;
|
|
5740
|
+
return g === ue.NEWLINE ? `${S}
|
|
5736
5741
|
|
|
5737
|
-
Process exactly ${
|
|
5742
|
+
Process exactly ${m} items from the list below and return the single best match.` : `${S}
|
|
5738
5743
|
|
|
5739
|
-
Process exactly ${
|
|
5744
|
+
Process exactly ${m} items from the XML list below and return the single best match.`;
|
|
5740
5745
|
}, p = [];
|
|
5741
5746
|
let d = !1;
|
|
5742
|
-
const
|
|
5747
|
+
const h = await Ae(t, i), y = a.batch(t.length), b = h;
|
|
5743
5748
|
a.progress({
|
|
5744
5749
|
event: W.start,
|
|
5745
5750
|
totalItems: t.length,
|
|
5746
|
-
totalBatches:
|
|
5751
|
+
totalBatches: b.length
|
|
5747
5752
|
});
|
|
5748
|
-
for (let g = 0; g <
|
|
5749
|
-
const
|
|
5753
|
+
for (let g = 0; g < b.length && !d; g += c) {
|
|
5754
|
+
const m = b.slice(g, g + c);
|
|
5750
5755
|
await Q(
|
|
5751
|
-
|
|
5752
|
-
async ({ items:
|
|
5753
|
-
const
|
|
5756
|
+
m,
|
|
5757
|
+
async ({ items: w, startIndex: S }) => {
|
|
5758
|
+
const v = je(i.listStyle, w, i.autoModeThreshold);
|
|
5754
5759
|
try {
|
|
5755
5760
|
const P = await M(
|
|
5756
|
-
() => be(
|
|
5761
|
+
() => be(w, u({ style: v, count: w.length }), {
|
|
5757
5762
|
...i,
|
|
5758
|
-
listStyle:
|
|
5763
|
+
listStyle: v,
|
|
5759
5764
|
responseFormat: i.responseFormat || Vh
|
|
5760
5765
|
}),
|
|
5761
5766
|
{
|
|
@@ -5765,13 +5770,13 @@ Process exactly ${h} items from the XML list below and return the single best ma
|
|
|
5765
5770
|
}
|
|
5766
5771
|
), x = Array.isArray(P) && P[0];
|
|
5767
5772
|
if (x) {
|
|
5768
|
-
const E = t.findIndex((R) => R === x), O = E !== -1 ? E :
|
|
5773
|
+
const E = t.findIndex((R) => R === x), O = E !== -1 ? E : S;
|
|
5769
5774
|
p.push({ result: x, index: O });
|
|
5770
5775
|
}
|
|
5771
|
-
y(
|
|
5776
|
+
y(w.length);
|
|
5772
5777
|
} catch (P) {
|
|
5773
|
-
if (a.error(P, { startIndex:
|
|
5774
|
-
ne(`find batch at index ${
|
|
5778
|
+
if (a.error(P, { startIndex: S, itemCount: w.length }), l === z.strict) throw P;
|
|
5779
|
+
ne(`find batch at index ${S} failed: ${P.message}`);
|
|
5775
5780
|
}
|
|
5776
5781
|
},
|
|
5777
5782
|
{
|
|
@@ -5788,9 +5793,9 @@ Process exactly ${h} items from the XML list below and return the single best ma
|
|
|
5788
5793
|
found: p.length > 0
|
|
5789
5794
|
}), p.length > 0) {
|
|
5790
5795
|
const g = p.reduce(
|
|
5791
|
-
(
|
|
5792
|
-
),
|
|
5793
|
-
return a.emit({ event: k.output, value: g.result }), a.complete(
|
|
5796
|
+
(w, S) => S.index < w.index ? S : w
|
|
5797
|
+
), m = { found: !0, totalItems: t.length, outcome: T.success };
|
|
5798
|
+
return a.emit({ event: k.output, value: g.result }), a.complete(m), g.result;
|
|
5794
5799
|
}
|
|
5795
5800
|
const f = { found: !1, totalItems: t.length, outcome: T.success };
|
|
5796
5801
|
return a.emit({ event: k.output, value: "" }), a.complete(f), "";
|
|
@@ -5825,8 +5830,8 @@ const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn =
|
|
|
5825
5830
|
iterations: l,
|
|
5826
5831
|
criteria: t
|
|
5827
5832
|
});
|
|
5828
|
-
const d = async (
|
|
5829
|
-
const P = ef({ description: r },
|
|
5833
|
+
const d = async (v) => {
|
|
5834
|
+
const P = ef({ description: r }, v);
|
|
5830
5835
|
if (Array.isArray(P))
|
|
5831
5836
|
return P;
|
|
5832
5837
|
const x = s ? `${P}
|
|
@@ -5839,8 +5844,8 @@ ${s}` : P, E = await M(
|
|
|
5839
5844
|
}
|
|
5840
5845
|
), O = E?.items || E;
|
|
5841
5846
|
return Array.isArray(O) ? O.filter(Boolean) : [];
|
|
5842
|
-
},
|
|
5843
|
-
const x = Ce(a)(
|
|
5847
|
+
}, h = async (v, P) => {
|
|
5848
|
+
const x = Ce(a)(v);
|
|
5844
5849
|
let E = [], O = [], R = 0;
|
|
5845
5850
|
const j = i.batch(x.length);
|
|
5846
5851
|
for (const F of x) {
|
|
@@ -5872,40 +5877,40 @@ ${s}` : P, E = await M(
|
|
|
5872
5877
|
bottom: u ? O : [],
|
|
5873
5878
|
selected: /* @__PURE__ */ new Set([...E, ...u ? O : []])
|
|
5874
5879
|
};
|
|
5875
|
-
}, y = [],
|
|
5880
|
+
}, y = [], b = [];
|
|
5876
5881
|
let f = p;
|
|
5877
|
-
for (let
|
|
5882
|
+
for (let v = 0; v < l && f.length > 0; v++) {
|
|
5878
5883
|
i.emit({
|
|
5879
5884
|
event: k.step,
|
|
5880
5885
|
stepName: "extracting-extremes",
|
|
5881
|
-
iteration:
|
|
5886
|
+
iteration: v + 1,
|
|
5882
5887
|
totalIterations: l,
|
|
5883
5888
|
remainingItems: f.length
|
|
5884
5889
|
});
|
|
5885
|
-
const { top: P, bottom: x, selected: E } = await
|
|
5886
|
-
y.push(...P), u &&
|
|
5890
|
+
const { top: P, bottom: x, selected: E } = await h(f, v + 1);
|
|
5891
|
+
y.push(...P), u && b.unshift(...x), f = f.filter((O) => !E.has(O)), i.emit({
|
|
5887
5892
|
event: k.step,
|
|
5888
5893
|
stepName: "iteration-complete",
|
|
5889
|
-
iteration:
|
|
5894
|
+
iteration: v + 1,
|
|
5890
5895
|
totalIterations: l,
|
|
5891
5896
|
topCount: y.length,
|
|
5892
|
-
bottomCount:
|
|
5897
|
+
bottomCount: b.length,
|
|
5893
5898
|
remainingItems: f.length
|
|
5894
5899
|
});
|
|
5895
5900
|
}
|
|
5896
|
-
const g = u ? [...y, ...f, ...
|
|
5897
|
-
for (const
|
|
5898
|
-
|
|
5899
|
-
for (const
|
|
5900
|
-
|
|
5901
|
+
const g = u ? [...y, ...f, ...b] : [...y, ...f], m = new Set(p), w = /* @__PURE__ */ new Set(), S = [];
|
|
5902
|
+
for (const v of g)
|
|
5903
|
+
m.has(v) && !w.has(v) && (w.add(v), S.push(v));
|
|
5904
|
+
for (const v of p)
|
|
5905
|
+
w.has(v) || S.push(v);
|
|
5901
5906
|
return i.progress({
|
|
5902
5907
|
event: W.complete,
|
|
5903
5908
|
totalItems: p.length,
|
|
5904
5909
|
iterations: l,
|
|
5905
5910
|
topItems: y.length,
|
|
5906
|
-
bottomItems:
|
|
5911
|
+
bottomItems: b.length,
|
|
5907
5912
|
remainingItems: f.length
|
|
5908
|
-
}), i.complete({ outcome: T.success, totalItems: p.length }),
|
|
5913
|
+
}), i.complete({ outcome: T.success, totalItems: p.length }), S;
|
|
5909
5914
|
} catch (d) {
|
|
5910
5915
|
throw i.error(d), d;
|
|
5911
5916
|
}
|
|
@@ -5960,39 +5965,39 @@ async function ta(e, t = {}) {
|
|
|
5960
5965
|
if (r.terms)
|
|
5961
5966
|
p = r.terms.split(",").map((y) => y.trim()).filter(Boolean);
|
|
5962
5967
|
else {
|
|
5963
|
-
const
|
|
5964
|
-
if (
|
|
5968
|
+
const b = fo(n).sentences().out("array");
|
|
5969
|
+
if (b.length === 0)
|
|
5965
5970
|
return i.complete({ outcome: T.success, terms: 0 }), [];
|
|
5966
5971
|
const f = [];
|
|
5967
|
-
for (let P = 0; P <
|
|
5968
|
-
const x =
|
|
5972
|
+
for (let P = 0; P < b.length; P += l - u) {
|
|
5973
|
+
const x = b.slice(P, P + l);
|
|
5969
5974
|
x.length > 0 && f.push(x.join(" "));
|
|
5970
5975
|
}
|
|
5971
|
-
const g = i.batch(f.length),
|
|
5976
|
+
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
5977
|
|
|
5973
5978
|
Return a "terms" object containing an array of the extracted terms.${s ? `
|
|
5974
5979
|
|
|
5975
|
-
${s}` : ""}`,
|
|
5980
|
+
${s}` : ""}`, S = await Oe(f, w, {
|
|
5976
5981
|
...o,
|
|
5977
5982
|
batchSize: o.batchSize ?? 1,
|
|
5978
5983
|
responseFormat: rf,
|
|
5979
5984
|
onProgress: L(o.onProgress, "glossary:extract")
|
|
5980
5985
|
});
|
|
5981
5986
|
g(f.length);
|
|
5982
|
-
const
|
|
5983
|
-
|
|
5987
|
+
const v = /* @__PURE__ */ new Set();
|
|
5988
|
+
S.forEach((P) => {
|
|
5984
5989
|
P && P.terms && Array.isArray(P.terms) && P.terms.forEach((x) => {
|
|
5985
|
-
x && typeof x == "string" &&
|
|
5990
|
+
x && typeof x == "string" && v.add(x);
|
|
5986
5991
|
});
|
|
5987
|
-
}), p = Array.from(
|
|
5992
|
+
}), p = Array.from(v);
|
|
5988
5993
|
}
|
|
5989
5994
|
if (i.emit({ event: k.phase, phase: "extracted", terms: p }), p.length === 0)
|
|
5990
5995
|
return i.complete({ outcome: T.success, terms: 0 }), [];
|
|
5991
|
-
const
|
|
5996
|
+
const h = (await Bn(p, c, {
|
|
5992
5997
|
...o,
|
|
5993
5998
|
onProgress: L(o.onProgress, "glossary:sort")
|
|
5994
5999
|
})).slice(0, a);
|
|
5995
|
-
return i.complete({ outcome: T.success, terms:
|
|
6000
|
+
return i.complete({ outcome: T.success, terms: h.length }), h;
|
|
5996
6001
|
} catch (p) {
|
|
5997
6002
|
throw i.error(p), p;
|
|
5998
6003
|
}
|
|
@@ -6065,7 +6070,7 @@ async function na(e, t, n) {
|
|
|
6065
6070
|
granularity: J(sf, ["guidance", "topN"]),
|
|
6066
6071
|
maxParallel: 3,
|
|
6067
6072
|
errorPosture: z.resilient
|
|
6068
|
-
}), { categoryPrompt: d, listStyle:
|
|
6073
|
+
}), { categoryPrompt: d, listStyle: h, autoModeThreshold: y, now: b } = i;
|
|
6069
6074
|
let f;
|
|
6070
6075
|
if (s.categories)
|
|
6071
6076
|
f = Hr(s.categories);
|
|
@@ -6082,7 +6087,7 @@ async function na(e, t, n) {
|
|
|
6082
6087
|
), F = await Ie(e, j, {
|
|
6083
6088
|
...i,
|
|
6084
6089
|
initial: "",
|
|
6085
|
-
now:
|
|
6090
|
+
now: b,
|
|
6086
6091
|
onProgress: L(i.onProgress, "reduce:category-discovery")
|
|
6087
6092
|
});
|
|
6088
6093
|
f = Hr(F);
|
|
@@ -6094,13 +6099,13 @@ async function na(e, t, n) {
|
|
|
6094
6099
|
categories: f,
|
|
6095
6100
|
categoryCount: f.length
|
|
6096
6101
|
});
|
|
6097
|
-
const g = [],
|
|
6102
|
+
const g = [], m = af(f), w = o ? (j) => `${m(j)}
|
|
6098
6103
|
|
|
6099
|
-
${o}` :
|
|
6104
|
+
${o}` : m, v = await Ae(e, i), P = a.batch(e.length);
|
|
6100
6105
|
await Q(
|
|
6101
|
-
|
|
6106
|
+
v,
|
|
6102
6107
|
async ({ items: j, startIndex: F }) => {
|
|
6103
|
-
const V = je(
|
|
6108
|
+
const V = je(h, j, y);
|
|
6104
6109
|
try {
|
|
6105
6110
|
const Y = {
|
|
6106
6111
|
...i,
|
|
@@ -6108,7 +6113,7 @@ ${o}` : h, S = await Ae(e, i), P = a.batch(e.length);
|
|
|
6108
6113
|
}, H = await M(
|
|
6109
6114
|
() => be(
|
|
6110
6115
|
j,
|
|
6111
|
-
|
|
6116
|
+
w({ style: V, count: j.length }),
|
|
6112
6117
|
Y
|
|
6113
6118
|
),
|
|
6114
6119
|
{
|
|
@@ -6280,14 +6285,14 @@ async function oa(e, t, n) {
|
|
|
6280
6285
|
const p = sa(e, c, l);
|
|
6281
6286
|
if (p.length === 0)
|
|
6282
6287
|
return i.complete({ outcome: T.success, combinations: 0 }), {};
|
|
6283
|
-
const d = {},
|
|
6288
|
+
const d = {}, h = i.batch(p.length), y = await Q(
|
|
6284
6289
|
p,
|
|
6285
|
-
async (
|
|
6286
|
-
const f = await jf(
|
|
6290
|
+
async (b) => {
|
|
6291
|
+
const f = await jf(b, r, s, {
|
|
6287
6292
|
...o,
|
|
6288
6293
|
onProgress: L(o.onProgress, "combo")
|
|
6289
6294
|
});
|
|
6290
|
-
return
|
|
6295
|
+
return h(1), f;
|
|
6291
6296
|
},
|
|
6292
6297
|
{
|
|
6293
6298
|
maxParallel: u,
|
|
@@ -6296,8 +6301,8 @@ async function oa(e, t, n) {
|
|
|
6296
6301
|
abortSignal: o.abortSignal
|
|
6297
6302
|
}
|
|
6298
6303
|
);
|
|
6299
|
-
for (const
|
|
6300
|
-
|
|
6304
|
+
for (const b of y)
|
|
6305
|
+
b?.key !== void 0 && (d[b.key] = b.intersection);
|
|
6301
6306
|
if (a && Object.keys(d).length > 0) {
|
|
6302
6307
|
const f = (await Rf(d, o)).intersections || d;
|
|
6303
6308
|
return i.complete({ outcome: T.success, combinations: p.length }), f;
|
|
@@ -6363,8 +6368,8 @@ ${s}` : r, i = A("list:generate", {
|
|
|
6363
6368
|
...n
|
|
6364
6369
|
}), a = [], c = {};
|
|
6365
6370
|
let l = !1;
|
|
6366
|
-
const { shouldSkip: u = Jf, shouldStop: p = Kf } = i, { queryLimit: d = 5, timeoutMs:
|
|
6367
|
-
let
|
|
6371
|
+
const { shouldSkip: u = Jf, shouldStop: p = Kf } = i, { queryLimit: d = 5, timeoutMs: h = zf } = i, y = /* @__PURE__ */ new Date();
|
|
6372
|
+
let b = 0;
|
|
6368
6373
|
for (; !l; ) {
|
|
6369
6374
|
const f = ri(o, {
|
|
6370
6375
|
...i,
|
|
@@ -6372,49 +6377,49 @@ ${s}` : r, i = A("list:generate", {
|
|
|
6372
6377
|
});
|
|
6373
6378
|
let g = [];
|
|
6374
6379
|
try {
|
|
6375
|
-
const
|
|
6380
|
+
const S = await M(
|
|
6376
6381
|
() => _(f, { ...i, ...aa() }),
|
|
6377
6382
|
{
|
|
6378
6383
|
label: "list-generate",
|
|
6379
6384
|
config: i
|
|
6380
6385
|
}
|
|
6381
|
-
),
|
|
6382
|
-
g = Array.isArray(
|
|
6383
|
-
} catch (
|
|
6384
|
-
if (
|
|
6385
|
-
throw
|
|
6386
|
+
), v = S?.items || S;
|
|
6387
|
+
g = Array.isArray(v) ? v.filter(Boolean) : [];
|
|
6388
|
+
} catch (S) {
|
|
6389
|
+
if (S.name === "AbortError")
|
|
6390
|
+
throw S;
|
|
6386
6391
|
ne(
|
|
6387
|
-
`Generate list [error]: ${
|
|
6392
|
+
`Generate list [error]: ${S.message} ${f.slice(0, 100).replace(`
|
|
6388
6393
|
`, "\\n")}`
|
|
6389
6394
|
), l = !0;
|
|
6390
6395
|
break;
|
|
6391
6396
|
}
|
|
6392
|
-
const
|
|
6393
|
-
|
|
6394
|
-
for (const
|
|
6395
|
-
const
|
|
6396
|
-
result:
|
|
6397
|
+
const m = g.filter((S) => !(S in c));
|
|
6398
|
+
b += 1;
|
|
6399
|
+
for (const S of m) {
|
|
6400
|
+
const v = {
|
|
6401
|
+
result: S,
|
|
6397
6402
|
resultsAll: a,
|
|
6398
6403
|
resultsNew: g,
|
|
6399
|
-
queryCount:
|
|
6404
|
+
queryCount: b,
|
|
6400
6405
|
startTime: y,
|
|
6401
6406
|
queryLimit: d,
|
|
6402
|
-
timeoutMs:
|
|
6407
|
+
timeoutMs: h
|
|
6403
6408
|
};
|
|
6404
|
-
if (await p(
|
|
6409
|
+
if (await p(v)) {
|
|
6405
6410
|
l = !0;
|
|
6406
6411
|
break;
|
|
6407
6412
|
}
|
|
6408
|
-
await u(
|
|
6413
|
+
await u(v) || (c[S] = !0, a.push(S), yield S);
|
|
6409
6414
|
}
|
|
6410
6415
|
await p({
|
|
6411
6416
|
result: void 0,
|
|
6412
6417
|
resultsAll: a,
|
|
6413
6418
|
resultsNew: g,
|
|
6414
|
-
queryCount:
|
|
6419
|
+
queryCount: b,
|
|
6415
6420
|
startTime: y,
|
|
6416
6421
|
queryLimit: d,
|
|
6417
|
-
timeoutMs:
|
|
6422
|
+
timeoutMs: h
|
|
6418
6423
|
}) && (l = !0);
|
|
6419
6424
|
}
|
|
6420
6425
|
};
|
|
@@ -6434,16 +6439,16 @@ ${r}` : n, c = await M(
|
|
|
6434
6439
|
if (i && u.length > 0) {
|
|
6435
6440
|
o.emit({ event: k.step, stepName: "transform", itemCount: u.length });
|
|
6436
6441
|
const p = o.batch(u.length), d = [];
|
|
6437
|
-
for (const
|
|
6438
|
-
const y = Vf(
|
|
6442
|
+
for (const h of u) {
|
|
6443
|
+
const y = Vf(h, i), b = await M(() => _(y, s), {
|
|
6439
6444
|
label: "list-transform",
|
|
6440
6445
|
config: s
|
|
6441
6446
|
});
|
|
6442
6447
|
try {
|
|
6443
|
-
const f = JSON.parse(
|
|
6448
|
+
const f = JSON.parse(b);
|
|
6444
6449
|
d.push(f);
|
|
6445
6450
|
} catch (f) {
|
|
6446
|
-
ne(`list-transform JSON.parse failed, keeping original item: ${f.message}`), d.push(
|
|
6451
|
+
ne(`list-transform JSON.parse failed, keeping original item: ${f.message}`), d.push(h);
|
|
6447
6452
|
}
|
|
6448
6453
|
p(1);
|
|
6449
6454
|
}
|
|
@@ -6555,14 +6560,14 @@ ${o}` : r, a = s.spec || await qn(i, n);
|
|
|
6555
6560
|
return mg(e, a, n);
|
|
6556
6561
|
}
|
|
6557
6562
|
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
|
-
|
|
6563
|
+
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);
|
|
6564
|
+
h.progress({
|
|
6560
6565
|
event: W.start,
|
|
6561
6566
|
totalItems: e.length,
|
|
6562
6567
|
totalBatches: p.length,
|
|
6563
6568
|
maxParallel: s
|
|
6564
6569
|
});
|
|
6565
|
-
let
|
|
6570
|
+
let b = l || "";
|
|
6566
6571
|
if (!l && p.length > 0) {
|
|
6567
6572
|
const f = p[0];
|
|
6568
6573
|
try {
|
|
@@ -6571,15 +6576,15 @@ async function rs(e, t, n, r) {
|
|
|
6571
6576
|
config: r,
|
|
6572
6577
|
onProgress: L(i, "batch")
|
|
6573
6578
|
});
|
|
6574
|
-
ns(g, f.items.length).forEach((
|
|
6575
|
-
d[f.startIndex +
|
|
6576
|
-
}),
|
|
6579
|
+
ns(g, f.items.length).forEach((m, w) => {
|
|
6580
|
+
d[f.startIndex + w] = m;
|
|
6581
|
+
}), b = dg(f.items, g, c), h.emit({
|
|
6577
6582
|
event: k.phase,
|
|
6578
6583
|
phase: "anchors-established",
|
|
6579
|
-
anchors:
|
|
6584
|
+
anchors: b
|
|
6580
6585
|
});
|
|
6581
6586
|
} catch (g) {
|
|
6582
|
-
if (
|
|
6587
|
+
if (h.error(g, { batchIndex: 0, itemCount: f.items.length }), o === z.strict) throw g;
|
|
6583
6588
|
a?.error && a.error("Score batch 0 failed", {
|
|
6584
6589
|
error: g.message,
|
|
6585
6590
|
itemCount: f.items.length
|
|
@@ -6588,24 +6593,24 @@ async function rs(e, t, n, r) {
|
|
|
6588
6593
|
y(f.items.length);
|
|
6589
6594
|
}
|
|
6590
6595
|
if (p.length > 1) {
|
|
6591
|
-
const f =
|
|
6592
|
-
${
|
|
6596
|
+
const f = b ? `${t}
|
|
6597
|
+
${b}` : t;
|
|
6593
6598
|
await Q(
|
|
6594
6599
|
p.slice(1),
|
|
6595
|
-
async ({ items: g, startIndex:
|
|
6600
|
+
async ({ items: g, startIndex: m }) => {
|
|
6596
6601
|
try {
|
|
6597
|
-
const
|
|
6602
|
+
const w = await M(() => be(g, f, n), {
|
|
6598
6603
|
label: "score:batch",
|
|
6599
6604
|
config: r,
|
|
6600
6605
|
onProgress: L(i, "batch")
|
|
6601
6606
|
});
|
|
6602
|
-
ns(
|
|
6603
|
-
d[
|
|
6607
|
+
ns(w, g.length).forEach((S, v) => {
|
|
6608
|
+
d[m + v] = S;
|
|
6604
6609
|
});
|
|
6605
|
-
} catch (
|
|
6606
|
-
if (
|
|
6610
|
+
} catch (w) {
|
|
6611
|
+
if (h.error(w, { itemCount: g.length }), o === z.strict) throw w;
|
|
6607
6612
|
a?.error && a.error("Score batch failed", {
|
|
6608
|
-
error:
|
|
6613
|
+
error: w.message,
|
|
6609
6614
|
itemCount: g.length
|
|
6610
6615
|
});
|
|
6611
6616
|
}
|
|
@@ -6614,7 +6619,7 @@ ${w}` : t;
|
|
|
6614
6619
|
{ maxParallel: s, errorPosture: o, abortSignal: r.abortSignal }
|
|
6615
6620
|
);
|
|
6616
6621
|
}
|
|
6617
|
-
return
|
|
6622
|
+
return h.progress({
|
|
6618
6623
|
event: W.complete,
|
|
6619
6624
|
totalItems: e.length,
|
|
6620
6625
|
processedItems: y.count
|
|
@@ -6624,7 +6629,7 @@ async function ke(e, t, n) {
|
|
|
6624
6629
|
[t, n] = K(t, n, ["spec", "anchors"]);
|
|
6625
6630
|
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
6631
|
c.start(), c.emit({ event: k.input, value: e });
|
|
6627
|
-
const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring:
|
|
6632
|
+
const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring: h } = await q(
|
|
6628
6633
|
a,
|
|
6629
6634
|
{
|
|
6630
6635
|
maxParallel: 3,
|
|
@@ -6637,38 +6642,38 @@ async function ke(e, t, n) {
|
|
|
6637
6642
|
c.emit({ event: k.phase, phase: "generating-specification" });
|
|
6638
6643
|
const y = o ? `${r}
|
|
6639
6644
|
|
|
6640
|
-
${o}` : r,
|
|
6641
|
-
c.emit({ event: k.phase, phase: "scoring-items", specification:
|
|
6645
|
+
${o}` : r, b = s.spec || await qn(y, a);
|
|
6646
|
+
c.emit({ event: k.phase, phase: "scoring-items", specification: b });
|
|
6642
6647
|
const f = fg(
|
|
6643
|
-
|
|
6648
|
+
b,
|
|
6644
6649
|
"Return ONLY the numeric score for each item according to the specification range."
|
|
6645
6650
|
), g = {
|
|
6646
6651
|
...a,
|
|
6647
6652
|
responseFormat: pg,
|
|
6648
6653
|
temperature: p
|
|
6649
|
-
},
|
|
6654
|
+
}, m = {
|
|
6650
6655
|
...a,
|
|
6651
6656
|
maxParallel: l,
|
|
6652
6657
|
maxAttempts: u,
|
|
6653
6658
|
errorPosture: d,
|
|
6654
6659
|
now: i,
|
|
6655
|
-
anchoring:
|
|
6660
|
+
anchoring: h,
|
|
6656
6661
|
_providedAnchors: s.anchors
|
|
6657
|
-
},
|
|
6662
|
+
}, w = await rs(e, f, g, m);
|
|
6658
6663
|
for (let x = 1; x < u; x += 1) {
|
|
6659
6664
|
const E = [], O = [];
|
|
6660
|
-
if (
|
|
6665
|
+
if (w.forEach((j, F) => {
|
|
6661
6666
|
j == null && (E.push(F), O.push(e[F]));
|
|
6662
6667
|
}), O.length === 0) break;
|
|
6663
6668
|
(await rs(O, f, g, {
|
|
6664
|
-
...
|
|
6669
|
+
...m,
|
|
6665
6670
|
now: /* @__PURE__ */ new Date()
|
|
6666
6671
|
})).forEach((j, F) => {
|
|
6667
|
-
j !== void 0 && (
|
|
6672
|
+
j !== void 0 && (w[E[F]] = j);
|
|
6668
6673
|
});
|
|
6669
6674
|
}
|
|
6670
|
-
const
|
|
6671
|
-
return c.complete({ totalItems:
|
|
6675
|
+
const S = w.filter((x) => x !== void 0).length, v = w.length - S, P = v > 0 ? T.partial : T.success;
|
|
6676
|
+
return c.complete({ totalItems: w.length, successCount: S, failedItems: v, outcome: P }), w;
|
|
6672
6677
|
}
|
|
6673
6678
|
function fg(e, t = "") {
|
|
6674
6679
|
const n = `Apply this score specification to evaluate each item:
|
|
@@ -6754,7 +6759,7 @@ function $g(e, t, n, r) {
|
|
|
6754
6759
|
let o;
|
|
6755
6760
|
if (r === "rich") {
|
|
6756
6761
|
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((
|
|
6762
|
+
o = p.filter((h) => d.has(h.item) ? !1 : (d.add(h.item), !0));
|
|
6758
6763
|
} else {
|
|
6759
6764
|
const c = Math.min(2, Math.ceil(s.length / 3));
|
|
6760
6765
|
o = [...s.slice(0, c), ...s.slice(-c)];
|
|
@@ -6781,50 +6786,50 @@ ${s}` : os(e, t, n, r), a = xg(e.length, t.length), c = C("score_matrix_result",
|
|
|
6781
6786
|
return Pg(l?.matrix, e.length, t.length);
|
|
6782
6787
|
}
|
|
6783
6788
|
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
|
-
|
|
6789
|
+
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);
|
|
6790
|
+
h.progress({
|
|
6786
6791
|
event: W.start,
|
|
6787
6792
|
totalItems: e.length,
|
|
6788
6793
|
totalBatches: p.length,
|
|
6789
6794
|
maxParallel: i
|
|
6790
6795
|
});
|
|
6791
|
-
let
|
|
6796
|
+
let b = u || "", f = 0;
|
|
6792
6797
|
if (!u && p.length > 0) {
|
|
6793
6798
|
const g = p[0];
|
|
6794
6799
|
try {
|
|
6795
|
-
const
|
|
6800
|
+
const m = await M(
|
|
6796
6801
|
() => is(g.items, t, n, r, "", s),
|
|
6797
6802
|
{ label: "score-matrix:batch", config: o, onProgress: L(c, "batch") }
|
|
6798
6803
|
);
|
|
6799
|
-
|
|
6800
|
-
d[g.startIndex +
|
|
6801
|
-
}),
|
|
6802
|
-
} catch (
|
|
6803
|
-
if (
|
|
6804
|
+
m.forEach((w, S) => {
|
|
6805
|
+
d[g.startIndex + S] = w;
|
|
6806
|
+
}), b = $g(g.items, m, t, l), h.emit({ event: k.phase, phase: "anchors-established" });
|
|
6807
|
+
} catch (m) {
|
|
6808
|
+
if (h.error(m, { batchIndex: 0, itemCount: g.items.length }), a === z.strict) throw m;
|
|
6804
6809
|
}
|
|
6805
6810
|
y(g.items.length), f = 1;
|
|
6806
6811
|
}
|
|
6807
6812
|
return f < p.length && await Q(
|
|
6808
6813
|
p.slice(f),
|
|
6809
|
-
async ({ items: g, startIndex:
|
|
6814
|
+
async ({ items: g, startIndex: m }) => {
|
|
6810
6815
|
try {
|
|
6811
6816
|
(await M(
|
|
6812
|
-
() => is(g, t, n, r,
|
|
6817
|
+
() => is(g, t, n, r, b, s),
|
|
6813
6818
|
{
|
|
6814
6819
|
label: "score-matrix:batch",
|
|
6815
6820
|
config: o,
|
|
6816
6821
|
onProgress: L(c, "batch")
|
|
6817
6822
|
}
|
|
6818
|
-
)).forEach((
|
|
6819
|
-
d[
|
|
6823
|
+
)).forEach((S, v) => {
|
|
6824
|
+
d[m + v] = S;
|
|
6820
6825
|
});
|
|
6821
|
-
} catch (
|
|
6822
|
-
if (
|
|
6826
|
+
} catch (w) {
|
|
6827
|
+
if (h.error(w, { itemCount: g.length }), a === z.strict) throw w;
|
|
6823
6828
|
}
|
|
6824
6829
|
y(g.length);
|
|
6825
6830
|
},
|
|
6826
6831
|
{ maxParallel: i, errorPosture: a, abortSignal: o.abortSignal }
|
|
6827
|
-
),
|
|
6832
|
+
), h.progress({
|
|
6828
6833
|
event: W.complete,
|
|
6829
6834
|
totalItems: e.length,
|
|
6830
6835
|
processedItems: y.count
|
|
@@ -6845,7 +6850,7 @@ async function ua(e, t, n, r) {
|
|
|
6845
6850
|
${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
6846
6851
|
if (u.start({ dimensions: c.length }), u.emit({ event: k.input, value: e }), e.length === 0)
|
|
6847
6852
|
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:
|
|
6853
|
+
const { maxParallel: p, maxAttempts: d, temperature: h, errorPosture: y, anchoring: b } = await q(
|
|
6849
6854
|
l,
|
|
6850
6855
|
{
|
|
6851
6856
|
maxParallel: 3,
|
|
@@ -6854,16 +6859,16 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6854
6859
|
errorPosture: z.resilient,
|
|
6855
6860
|
anchoring: J(Sg)
|
|
6856
6861
|
}
|
|
6857
|
-
), f = { ...l, temperature:
|
|
6862
|
+
), f = { ...l, temperature: h }, g = {
|
|
6858
6863
|
...l,
|
|
6859
6864
|
maxParallel: p,
|
|
6860
6865
|
maxAttempts: d,
|
|
6861
6866
|
errorPosture: y,
|
|
6862
|
-
anchoring:
|
|
6867
|
+
anchoring: b,
|
|
6863
6868
|
_providedAnchors: o.anchors
|
|
6864
6869
|
};
|
|
6865
6870
|
u.emit({ event: k.phase, phase: "scoring-matrix" });
|
|
6866
|
-
const
|
|
6871
|
+
const m = await as(
|
|
6867
6872
|
e,
|
|
6868
6873
|
c,
|
|
6869
6874
|
a,
|
|
@@ -6873,7 +6878,7 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6873
6878
|
);
|
|
6874
6879
|
for (let x = 1; x < d; x += 1) {
|
|
6875
6880
|
const E = [], O = [];
|
|
6876
|
-
if (
|
|
6881
|
+
if (m.forEach((j, F) => {
|
|
6877
6882
|
j == null && (E.push(F), O.push(e[F]));
|
|
6878
6883
|
}), O.length === 0) break;
|
|
6879
6884
|
u.emit({
|
|
@@ -6889,17 +6894,17 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
|
|
|
6889
6894
|
f,
|
|
6890
6895
|
{ ...g, now: /* @__PURE__ */ new Date() }
|
|
6891
6896
|
)).forEach((j, F) => {
|
|
6892
|
-
j !== void 0 && (
|
|
6897
|
+
j !== void 0 && (m[E[F]] = j);
|
|
6893
6898
|
});
|
|
6894
6899
|
}
|
|
6895
|
-
const
|
|
6900
|
+
const w = m.map(
|
|
6896
6901
|
(x) => x ?? c.map(() => ({ score: Ve.min, rationale: "scoring failed" }))
|
|
6897
|
-
),
|
|
6902
|
+
), S = m.filter((x) => x !== void 0).length, v = m.length - S, P = v > 0 ? T.partial : T.success;
|
|
6898
6903
|
return u.emit({
|
|
6899
6904
|
event: k.output,
|
|
6900
|
-
value: { rows:
|
|
6901
|
-
}), u.complete({ totalItems: e.length, successCount:
|
|
6902
|
-
matrix:
|
|
6905
|
+
value: { rows: w.length, columns: c.length }
|
|
6906
|
+
}), u.complete({ totalItems: e.length, successCount: S, failedItems: v, outcome: P }), {
|
|
6907
|
+
matrix: w,
|
|
6903
6908
|
dimensions: c.map((x) => x.dimension),
|
|
6904
6909
|
scale: Ve
|
|
6905
6910
|
};
|
|
@@ -7017,14 +7022,14 @@ ${a}` : o, p = i.spec || await Fn(u, r);
|
|
|
7017
7022
|
Return only IDs from the available tags list.
|
|
7018
7023
|
Return empty array when no tags apply.`,
|
|
7019
7024
|
l
|
|
7020
|
-
),
|
|
7025
|
+
), h = e.map(
|
|
7021
7026
|
(g) => typeof g == "object" && g !== null ? JSON.stringify(g) : g
|
|
7022
|
-
), y = s.batch(
|
|
7027
|
+
), y = s.batch(h.length), b = {
|
|
7023
7028
|
...r,
|
|
7024
7029
|
responseFormat: C("tags_map_result", Cg),
|
|
7025
7030
|
onProgress: L(r.onProgress, "tags:map")
|
|
7026
|
-
}, f = await Oe(
|
|
7027
|
-
return y(
|
|
7031
|
+
}, f = await Oe(h, d, b);
|
|
7032
|
+
return y(h.length), s.complete({ outcome: T.success }), f;
|
|
7028
7033
|
} catch (o) {
|
|
7029
7034
|
throw s.error(o), o;
|
|
7030
7035
|
}
|
|
@@ -7109,7 +7114,7 @@ async function ha(e, t = {}) {
|
|
|
7109
7114
|
diversity: i
|
|
7110
7115
|
}), d = await Ze(p, {
|
|
7111
7116
|
...n,
|
|
7112
|
-
shouldStop: ({ resultsAll:
|
|
7117
|
+
shouldStop: ({ resultsAll: h }) => h.length >= a,
|
|
7113
7118
|
onProgress: L(n.onProgress, "list:sampling")
|
|
7114
7119
|
});
|
|
7115
7120
|
if (!d || d.length === 0)
|
|
@@ -7144,18 +7149,18 @@ async function zn(e, t = {}) {
|
|
|
7144
7149
|
try {
|
|
7145
7150
|
let l;
|
|
7146
7151
|
if (r.uniqueTerms)
|
|
7147
|
-
l = r.uniqueTerms.split(",").map((
|
|
7152
|
+
l = r.uniqueTerms.split(",").map((h) => h.trim()).filter(Boolean);
|
|
7148
7153
|
else {
|
|
7149
|
-
const
|
|
7150
|
-
|
|
7154
|
+
const h = Bg(n, c), y = i.batch(h.length), f = (await Q(
|
|
7155
|
+
h,
|
|
7151
7156
|
async (g) => {
|
|
7152
|
-
const
|
|
7157
|
+
const m = s ? `
|
|
7153
7158
|
|
|
7154
|
-
${s}` : "",
|
|
7155
|
-
`key words and phrases that would help find documents about: ${g}${
|
|
7159
|
+
${s}` : "", w = await Ze(
|
|
7160
|
+
`key words and phrases that would help find documents about: ${g}${m}`,
|
|
7156
7161
|
{ ...o, onProgress: L(o.onProgress, "list:extract") }
|
|
7157
7162
|
);
|
|
7158
|
-
return y(1),
|
|
7163
|
+
return y(1), w;
|
|
7159
7164
|
},
|
|
7160
7165
|
{
|
|
7161
7166
|
maxParallel: 3,
|
|
@@ -7172,8 +7177,8 @@ ${s}` : "", b = await Ze(
|
|
|
7172
7177
|
l,
|
|
7173
7178
|
"relevance as a search term for finding information (1-10, higher is more important)",
|
|
7174
7179
|
{ ...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((
|
|
7180
|
+
), d = l.map((h, y) => ({ term: h, score: u[y] ?? 0 })).toSorted((h, y) => y.score - h.score);
|
|
7181
|
+
return i.emit({ event: k.phase, phase: "scored", termsWithScores: d }), i.complete({ outcome: T.success }), d.slice(0, a).map((h) => h.term);
|
|
7177
7182
|
} catch (l) {
|
|
7178
7183
|
throw i.error(l), l;
|
|
7179
7184
|
}
|
|
@@ -7199,17 +7204,17 @@ async function Un({
|
|
|
7199
7204
|
const u = A(ps, i), p = I(ps, u.onProgress, u);
|
|
7200
7205
|
p.start(), p.emit({ event: k.input, value: { speakers: e, topic: a } });
|
|
7201
7206
|
try {
|
|
7202
|
-
const d = r.length > 0 ? r.map((
|
|
7207
|
+
const d = r.length > 0 ? r.map((S) => `${S.time} ${S.name} (${S.id}): ${S.comment}`).join(`
|
|
7203
7208
|
`) : "", y = [
|
|
7204
7209
|
o.customPrompt || "",
|
|
7205
7210
|
d ? $(d, { tag: "conversation-history" }) : "",
|
|
7206
7211
|
a ? $(a, { tag: "topic" }) : ""
|
|
7207
7212
|
].filter(Boolean).join(`
|
|
7208
7213
|
|
|
7209
|
-
`),
|
|
7210
|
-
const x = [
|
|
7211
|
-
|
|
7212
|
-
const E = s.get?.(
|
|
7214
|
+
`), b = e.map((S, v) => {
|
|
7215
|
+
const x = [S.name || `Speaker ${v + 1}`];
|
|
7216
|
+
S.bio && x.push(`Bio: ${S.bio}`), S.agenda && x.push(`Agenda: ${S.agenda}`);
|
|
7217
|
+
const E = s.get?.(S.id) ?? [];
|
|
7213
7218
|
if (E.length > 0) {
|
|
7214
7219
|
const O = E.map((R) => `[${R.time}] ${R.comment}`).join(`
|
|
7215
7220
|
`);
|
|
@@ -7225,11 +7230,11 @@ ${O}`);
|
|
|
7225
7230
|
l
|
|
7226
7231
|
].filter(Boolean).join(`
|
|
7227
7232
|
|
|
7228
|
-
`),
|
|
7233
|
+
`), m = p.batch(e.length), w = await Oe(b, g, {
|
|
7229
7234
|
...u,
|
|
7230
7235
|
onProgress: L(u.onProgress, "conversation-turn-reduce:map")
|
|
7231
7236
|
});
|
|
7232
|
-
return
|
|
7237
|
+
return m(e.length), p.emit({ event: k.output, value: w }), p.complete({ outcome: T.success, speakers: e.length }), w;
|
|
7233
7238
|
} catch (d) {
|
|
7234
7239
|
throw p.error(d), d;
|
|
7235
7240
|
}
|
|
@@ -7310,9 +7315,9 @@ class vt {
|
|
|
7310
7315
|
llm: u,
|
|
7311
7316
|
clock: p,
|
|
7312
7317
|
onProgress: d,
|
|
7313
|
-
now:
|
|
7318
|
+
now: h,
|
|
7314
7319
|
operation: y,
|
|
7315
|
-
...
|
|
7320
|
+
...b
|
|
7316
7321
|
} = i;
|
|
7317
7322
|
if (a.shouldContinue && typeof a.shouldContinue != "function")
|
|
7318
7323
|
throw new Error("shouldContinue must be a function");
|
|
@@ -7324,7 +7329,7 @@ class vt {
|
|
|
7324
7329
|
turnPolicy: a.turnPolicy || ds(this.speakers)
|
|
7325
7330
|
},
|
|
7326
7331
|
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 =
|
|
7332
|
+
), 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
7333
|
}
|
|
7329
7334
|
_push(t, n) {
|
|
7330
7335
|
const r = (n ?? "").trim();
|
|
@@ -7614,9 +7619,9 @@ ${n}`;
|
|
|
7614
7619
|
} = {}) => {
|
|
7615
7620
|
try {
|
|
7616
7621
|
const d = t ?? n;
|
|
7617
|
-
let
|
|
7622
|
+
let h = e;
|
|
7618
7623
|
if (!e.isEnhanced) {
|
|
7619
|
-
|
|
7624
|
+
h = await s({
|
|
7620
7625
|
name: d,
|
|
7621
7626
|
rootName: n,
|
|
7622
7627
|
fixes: a,
|
|
@@ -7624,8 +7629,8 @@ ${n}`;
|
|
|
7624
7629
|
config: l,
|
|
7625
7630
|
variety: u,
|
|
7626
7631
|
now: p
|
|
7627
|
-
}),
|
|
7628
|
-
const y = e.options?.[0],
|
|
7632
|
+
}), h.isEnhanced = !0;
|
|
7633
|
+
const y = e.options?.[0], b = await r({
|
|
7629
7634
|
name: d,
|
|
7630
7635
|
focus: y,
|
|
7631
7636
|
rootName: n,
|
|
@@ -7635,18 +7640,18 @@ ${n}`;
|
|
|
7635
7640
|
variety: u,
|
|
7636
7641
|
now: p
|
|
7637
7642
|
});
|
|
7638
|
-
|
|
7643
|
+
h.children = b.map((f) => ({
|
|
7639
7644
|
id: i(),
|
|
7640
7645
|
name: f
|
|
7641
7646
|
}));
|
|
7642
7647
|
}
|
|
7643
|
-
return e.id || (
|
|
7648
|
+
return e.id || (h.id = i()), {
|
|
7644
7649
|
...e,
|
|
7645
|
-
...
|
|
7650
|
+
...h
|
|
7646
7651
|
};
|
|
7647
7652
|
} catch (d) {
|
|
7648
|
-
const
|
|
7649
|
-
throw d.message = `makeNode(${
|
|
7653
|
+
const h = t ?? n;
|
|
7654
|
+
throw d.message = `makeNode(${h}): ${d.message}`, d;
|
|
7650
7655
|
}
|
|
7651
7656
|
}, on = async ({
|
|
7652
7657
|
name: e,
|
|
@@ -7664,10 +7669,10 @@ ${n}`;
|
|
|
7664
7669
|
now: d
|
|
7665
7670
|
} = {}) => {
|
|
7666
7671
|
try {
|
|
7667
|
-
let
|
|
7672
|
+
let h = { ...n ?? {} };
|
|
7668
7673
|
const y = await py({
|
|
7669
|
-
node:
|
|
7670
|
-
name: e ??
|
|
7674
|
+
node: h,
|
|
7675
|
+
name: e ?? h.name,
|
|
7671
7676
|
rootName: t,
|
|
7672
7677
|
enhance: o,
|
|
7673
7678
|
decompose: s,
|
|
@@ -7679,13 +7684,13 @@ ${n}`;
|
|
|
7679
7684
|
variety: p,
|
|
7680
7685
|
now: d
|
|
7681
7686
|
});
|
|
7682
|
-
if (
|
|
7683
|
-
...
|
|
7687
|
+
if (h = {
|
|
7688
|
+
...h,
|
|
7684
7689
|
...y
|
|
7685
7690
|
}, r <= 0)
|
|
7686
|
-
return
|
|
7687
|
-
const
|
|
7688
|
-
for (const f of
|
|
7691
|
+
return h;
|
|
7692
|
+
const b = [];
|
|
7693
|
+
for (const f of h.children) {
|
|
7689
7694
|
const g = await on({
|
|
7690
7695
|
tree: f,
|
|
7691
7696
|
rootName: t,
|
|
@@ -7700,12 +7705,12 @@ ${n}`;
|
|
|
7700
7705
|
variety: p,
|
|
7701
7706
|
now: d
|
|
7702
7707
|
});
|
|
7703
|
-
|
|
7708
|
+
b.push(g);
|
|
7704
7709
|
}
|
|
7705
|
-
return
|
|
7706
|
-
} catch (
|
|
7710
|
+
return h.children = b, h;
|
|
7711
|
+
} catch (h) {
|
|
7707
7712
|
const y = e ?? n?.name ?? t;
|
|
7708
|
-
throw
|
|
7713
|
+
throw h.message = `makeSubtree(${y}, depth=${r}): ${h.message}`, h;
|
|
7709
7714
|
}
|
|
7710
7715
|
}, wa = (e) => {
|
|
7711
7716
|
if (!e.children || e.children.length === 0) {
|
|
@@ -7831,18 +7836,18 @@ class dy {
|
|
|
7831
7836
|
if (c === 0)
|
|
7832
7837
|
return [];
|
|
7833
7838
|
const l = [];
|
|
7834
|
-
for (const [d,
|
|
7835
|
-
const y = this._getDocumentVector(this.tfidf,
|
|
7836
|
-
if (
|
|
7837
|
-
const f = this._dotProduct(a, y) / (c *
|
|
7839
|
+
for (const [d, h] of this.chunks.entries()) {
|
|
7840
|
+
const y = this._getDocumentVector(this.tfidf, h.documentIndex), b = this._magnitude(y);
|
|
7841
|
+
if (b === 0) continue;
|
|
7842
|
+
const f = this._dotProduct(a, y) / (c * b);
|
|
7838
7843
|
f >= s && l.push({
|
|
7839
7844
|
id: d,
|
|
7840
|
-
text:
|
|
7845
|
+
text: h.text,
|
|
7841
7846
|
score: f
|
|
7842
7847
|
});
|
|
7843
7848
|
}
|
|
7844
|
-
const p = l.toSorted((d,
|
|
7845
|
-
return o ? p : p.map(({ id: d, text:
|
|
7849
|
+
const p = l.toSorted((d, h) => h.score - d.score).slice(0, r);
|
|
7850
|
+
return o ? p : p.map(({ id: d, text: h }) => ({ id: d, text: h }));
|
|
7846
7851
|
}
|
|
7847
7852
|
findMatches(t, n = {}) {
|
|
7848
7853
|
const { threshold: r = 0.1, includeScores: s = !0 } = n;
|
|
@@ -7998,15 +8003,15 @@ function Ey(e, t, n, r, s = St) {
|
|
|
7998
8003
|
o,
|
|
7999
8004
|
l,
|
|
8000
8005
|
s
|
|
8001
|
-
), d = Math.max(1, Math.floor(u / Sa)),
|
|
8006
|
+
), d = Math.max(1, Math.floor(u / Sa)), h = Math.max(
|
|
8002
8007
|
1,
|
|
8003
8008
|
Math.floor(p / xa)
|
|
8004
|
-
), y =
|
|
8009
|
+
), y = h * a * (1 - Ye), b = o < Sy ? xy : $y, f = Math.min(t * b, y);
|
|
8005
8010
|
return {
|
|
8006
8011
|
tfIdfBudget: t - f,
|
|
8007
8012
|
reservedSpace: f,
|
|
8008
8013
|
chunksWeCanScore: d,
|
|
8009
|
-
chunksWeCanCompress:
|
|
8014
|
+
chunksWeCanCompress: h,
|
|
8010
8015
|
reductionRatio: o,
|
|
8011
8016
|
avgChunkSize: a
|
|
8012
8017
|
};
|
|
@@ -8088,9 +8093,9 @@ async function _y(e, t, n, r = {}) {
|
|
|
8088
8093
|
};
|
|
8089
8094
|
}
|
|
8090
8095
|
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,
|
|
8096
|
+
const { compressionRatio: i = Ye } = o, a = Math.min(s.avgChunkSize * 0.8, 400), c = e.filter((y) => y.size >= a).toSorted((y, b) => {
|
|
8092
8097
|
const f = (y.tfIdfScore || 0) * Math.log(y.size);
|
|
8093
|
-
return (
|
|
8098
|
+
return (b.tfIdfScore || 0) * Math.log(b.size) - f;
|
|
8094
8099
|
}).slice(0, n);
|
|
8095
8100
|
if (c.length === 0)
|
|
8096
8101
|
return { compressed: [], tokensUsed: 0 };
|
|
@@ -8103,17 +8108,17 @@ async function Cy(e, t, n, r, s, o = {}) {
|
|
|
8103
8108
|
onProgress: L(o.onProgress, "map:compression")
|
|
8104
8109
|
}
|
|
8105
8110
|
), d = [];
|
|
8106
|
-
let
|
|
8107
|
-
return p.forEach((y,
|
|
8111
|
+
let h = 0;
|
|
8112
|
+
return p.forEach((y, b) => {
|
|
8108
8113
|
const f = y ? Pa(y) : "";
|
|
8109
|
-
f.length >= $a && f.length <= r -
|
|
8110
|
-
...c[
|
|
8111
|
-
originalText: c[
|
|
8114
|
+
f.length >= $a && f.length <= r - h && (d.push({
|
|
8115
|
+
...c[b],
|
|
8116
|
+
originalText: c[b].text,
|
|
8112
8117
|
text: f,
|
|
8113
8118
|
compressed: !0,
|
|
8114
8119
|
size: f.length,
|
|
8115
|
-
compressionRatio: f.length / c[
|
|
8116
|
-
}),
|
|
8120
|
+
compressionRatio: f.length / c[b].size
|
|
8121
|
+
}), h += f.length);
|
|
8117
8122
|
}), {
|
|
8118
8123
|
compressed: d,
|
|
8119
8124
|
tokensUsed: c.length * xa
|
|
@@ -8180,9 +8185,9 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8180
8185
|
tokenBudget: u,
|
|
8181
8186
|
gapFillerBudgetRatio: p,
|
|
8182
8187
|
compression: d,
|
|
8183
|
-
ranking:
|
|
8188
|
+
ranking: h,
|
|
8184
8189
|
queryExpansion: y,
|
|
8185
|
-
llmScoring:
|
|
8190
|
+
llmScoring: b,
|
|
8186
8191
|
llmCompression: f,
|
|
8187
8192
|
scoringTokenRatio: g
|
|
8188
8193
|
} = await q(a, {
|
|
@@ -8197,7 +8202,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8197
8202
|
"llmCompression",
|
|
8198
8203
|
"scoringTokenRatio"
|
|
8199
8204
|
])
|
|
8200
|
-
}),
|
|
8205
|
+
}), m = {
|
|
8201
8206
|
..._e,
|
|
8202
8207
|
...a,
|
|
8203
8208
|
targetSize: l,
|
|
@@ -8205,7 +8210,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8205
8210
|
gapFillerBudgetRatio: p
|
|
8206
8211
|
};
|
|
8207
8212
|
if (!e || e.length === 0) {
|
|
8208
|
-
const
|
|
8213
|
+
const w = {
|
|
8209
8214
|
content: "",
|
|
8210
8215
|
metadata: {
|
|
8211
8216
|
originalSize: 0,
|
|
@@ -8216,60 +8221,60 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8216
8221
|
tokens: { budget: 0, used: 0, breakdown: {} }
|
|
8217
8222
|
}
|
|
8218
8223
|
};
|
|
8219
|
-
return c.complete({ outcome: T.success }),
|
|
8224
|
+
return c.complete({ outcome: T.success }), w;
|
|
8220
8225
|
}
|
|
8221
8226
|
try {
|
|
8222
|
-
|
|
8223
|
-
let
|
|
8227
|
+
m.targetSize <= 0 && (m.targetSize = _e.targetSize), m.chunkSize <= 0 && (m.chunkSize = _e.chunkSize), m.tokenBudget <= 0 && (m.tokenBudget = _e.tokenBudget);
|
|
8228
|
+
let w = m.tokenBudget;
|
|
8224
8229
|
c.emit({ event: k.phase, phase: "chunking" });
|
|
8225
|
-
const
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8230
|
+
const S = Iy(e, m.chunkSize, m.targetSize), v = Ey(
|
|
8231
|
+
S,
|
|
8232
|
+
m.targetSize,
|
|
8233
|
+
w,
|
|
8229
8234
|
e.length,
|
|
8230
8235
|
g
|
|
8231
8236
|
);
|
|
8232
|
-
!
|
|
8237
|
+
!b && !f && (v.tfIdfBudget = m.targetSize, v.reservedSpace = 0), c.emit({ event: k.phase, phase: "query-expansion" });
|
|
8233
8238
|
const P = a;
|
|
8234
8239
|
let x, E = 0;
|
|
8235
8240
|
if (s.expansions)
|
|
8236
8241
|
x = s.expansions.split(",").map((B) => B.trim()).filter(Boolean), x.unshift(i);
|
|
8237
8242
|
else if (y) {
|
|
8238
|
-
const B = await ky(i,
|
|
8243
|
+
const B = await ky(i, w, P);
|
|
8239
8244
|
x = B.expansions, E = B.tokensUsed;
|
|
8240
8245
|
} else
|
|
8241
8246
|
x = [i];
|
|
8242
|
-
|
|
8243
|
-
const O = Ay(
|
|
8247
|
+
w -= E, c.emit({ event: k.phase, phase: "tfidf-scoring", expansions: x });
|
|
8248
|
+
const O = Ay(S, x), { selected: R, candidates: j, sizeUsed: F } = Oy(
|
|
8244
8249
|
O,
|
|
8245
|
-
|
|
8250
|
+
v.tfIdfBudget
|
|
8246
8251
|
);
|
|
8247
8252
|
c.emit({ event: k.phase, phase: "edge-scoring" });
|
|
8248
|
-
const { scored: V, tokensUsed: Y } =
|
|
8253
|
+
const { scored: V, tokensUsed: Y } = b ? await _y(j, i, v.chunksWeCanScore, {
|
|
8249
8254
|
...P,
|
|
8250
|
-
llmWeight:
|
|
8255
|
+
llmWeight: h
|
|
8251
8256
|
}) : { scored: [], tokensUsed: 0 };
|
|
8252
|
-
|
|
8253
|
-
let H = vs(R, F, V,
|
|
8257
|
+
w -= Y;
|
|
8258
|
+
let H = vs(R, F, V, m.targetSize);
|
|
8254
8259
|
c.emit({ event: k.phase, phase: "compression" });
|
|
8255
|
-
const ee =
|
|
8260
|
+
const ee = m.targetSize - H.size;
|
|
8256
8261
|
let pe = 0;
|
|
8257
|
-
const G = Math.min(
|
|
8258
|
-
if (f && ee > G &&
|
|
8262
|
+
const G = Math.min(v.avgChunkSize * 0.5, 200);
|
|
8263
|
+
if (f && ee > G && v.chunksWeCanCompress > 0) {
|
|
8259
8264
|
const B = jy(O, H.chunks), { compressed: X, tokensUsed: ce } = await Cy(
|
|
8260
8265
|
B,
|
|
8261
8266
|
i,
|
|
8262
|
-
|
|
8267
|
+
v.chunksWeCanCompress,
|
|
8263
8268
|
ee,
|
|
8264
|
-
|
|
8269
|
+
v,
|
|
8265
8270
|
{ ...P, compressionRatio: d }
|
|
8266
8271
|
);
|
|
8267
|
-
pe = ce,
|
|
8272
|
+
pe = ce, w -= ce, H = vs(H.chunks, H.size, X, m.targetSize);
|
|
8268
8273
|
}
|
|
8269
8274
|
c.emit({ event: k.phase, phase: "assembly" });
|
|
8270
8275
|
let te = H.chunks, ie = 0;
|
|
8271
|
-
if (
|
|
8272
|
-
const B = Math.floor(
|
|
8276
|
+
if (m.gapFillerBudgetRatio > 0) {
|
|
8277
|
+
const B = Math.floor(m.targetSize * m.gapFillerBudgetRatio), X = m.targetSize - H.size, ce = Math.min(B, X);
|
|
8273
8278
|
if (ce > 0) {
|
|
8274
8279
|
const ve = Ly(O, te, ce);
|
|
8275
8280
|
ve.length > 0 && (te = [...te, ...ve], ie = ve.length);
|
|
@@ -8277,7 +8282,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8277
8282
|
}
|
|
8278
8283
|
const de = Ny(te);
|
|
8279
8284
|
let Z = Ry(de);
|
|
8280
|
-
Z.length >
|
|
8285
|
+
Z.length > m.targetSize * 3 && (Z = Pa(Z.slice(0, m.targetSize * 2)));
|
|
8281
8286
|
const we = {
|
|
8282
8287
|
content: Z,
|
|
8283
8288
|
metadata: {
|
|
@@ -8285,20 +8290,20 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8285
8290
|
finalSize: Z.length,
|
|
8286
8291
|
reductionRatio: (1 - Z.length / e.length).toFixed(2),
|
|
8287
8292
|
allocation: {
|
|
8288
|
-
tfIdfBudget:
|
|
8289
|
-
reservedForLLM:
|
|
8293
|
+
tfIdfBudget: v.tfIdfBudget,
|
|
8294
|
+
reservedForLLM: v.reservedSpace,
|
|
8290
8295
|
actualLLMSpace: te.filter((B) => B.llmScore).reduce((B, X) => B + X.size, 0)
|
|
8291
8296
|
},
|
|
8292
8297
|
chunks: {
|
|
8293
|
-
total:
|
|
8298
|
+
total: S.length,
|
|
8294
8299
|
tfIdfSelected: R.length,
|
|
8295
8300
|
llmSelected: te.filter((B) => B.llmScore && !B.compressed).length,
|
|
8296
8301
|
compressed: te.filter((B) => B.compressed).length,
|
|
8297
8302
|
gapFillers: ie
|
|
8298
8303
|
},
|
|
8299
8304
|
tokens: {
|
|
8300
|
-
budget:
|
|
8301
|
-
used:
|
|
8305
|
+
budget: m.tokenBudget,
|
|
8306
|
+
used: m.tokenBudget - w,
|
|
8302
8307
|
breakdown: {
|
|
8303
8308
|
expansion: E,
|
|
8304
8309
|
scoring: Y || 0,
|
|
@@ -8308,8 +8313,8 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
|
|
|
8308
8313
|
}
|
|
8309
8314
|
};
|
|
8310
8315
|
return c.complete({ outcome: T.success }), we;
|
|
8311
|
-
} catch (
|
|
8312
|
-
throw c.error(
|
|
8316
|
+
} catch (w) {
|
|
8317
|
+
throw c.error(w), w;
|
|
8313
8318
|
}
|
|
8314
8319
|
}
|
|
8315
8320
|
Ea.knownTexts = ["expansions"];
|
|
@@ -8361,33 +8366,33 @@ async function ka(e, t = {}) {
|
|
|
8361
8366
|
else {
|
|
8362
8367
|
if (!n)
|
|
8363
8368
|
return i.complete({ outcome: T.success }), [];
|
|
8364
|
-
const
|
|
8365
|
-
`).map((
|
|
8366
|
-
if (
|
|
8369
|
+
const b = n.split(`
|
|
8370
|
+
`).map((m) => m.trim()).filter(Boolean);
|
|
8371
|
+
if (b.length === 0)
|
|
8367
8372
|
return i.complete({ outcome: T.success }), [];
|
|
8368
8373
|
const f = s ? `
|
|
8369
8374
|
|
|
8370
8375
|
${s}` : "", g = await ke(
|
|
8371
|
-
|
|
8376
|
+
b,
|
|
8372
8377
|
`How ambiguous or easily misinterpreted is this sentence?${f}`,
|
|
8373
8378
|
{
|
|
8374
8379
|
...o,
|
|
8375
8380
|
onProgress: L(o.onProgress, "score:sentence-ambiguity")
|
|
8376
8381
|
}
|
|
8377
8382
|
);
|
|
8378
|
-
c =
|
|
8383
|
+
c = b.map((m, w) => ({ sentence: m, score: g[w] ?? 0 })).toSorted((m, w) => w.score - m.score).slice(0, a);
|
|
8379
8384
|
}
|
|
8380
8385
|
i.emit({ event: k.phase, phase: "ranked", rankedSentences: c });
|
|
8381
8386
|
const l = i.batch(c.length), p = (await Q(
|
|
8382
8387
|
c,
|
|
8383
|
-
async ({ sentence:
|
|
8388
|
+
async ({ sentence: b }) => {
|
|
8384
8389
|
const f = await Ze("Ambiguous words or short phrases", {
|
|
8385
8390
|
...o,
|
|
8386
|
-
attachments: { text:
|
|
8391
|
+
attachments: { text: b },
|
|
8387
8392
|
targetNewItemsCount: 5,
|
|
8388
8393
|
onProgress: L(o.onProgress, "list:extract")
|
|
8389
8394
|
});
|
|
8390
|
-
return l(1), f.map((g) => ({ term: g, sentence:
|
|
8395
|
+
return l(1), f.map((g) => ({ term: g, sentence: b }));
|
|
8391
8396
|
},
|
|
8392
8397
|
{
|
|
8393
8398
|
maxParallel: 3,
|
|
@@ -8399,13 +8404,13 @@ ${s}` : "", g = await ke(
|
|
|
8399
8404
|
if (p.length === 0)
|
|
8400
8405
|
return i.complete({ outcome: T.success }), [];
|
|
8401
8406
|
const d = await ke(
|
|
8402
|
-
p.map((
|
|
8407
|
+
p.map((b) => `${b.term} | ${b.sentence}`),
|
|
8403
8408
|
"Score how ambiguous the term is within the sentence.",
|
|
8404
8409
|
{
|
|
8405
8410
|
...o,
|
|
8406
8411
|
onProgress: L(o.onProgress, "score:term-ambiguity")
|
|
8407
8412
|
}
|
|
8408
|
-
), y = p.map((
|
|
8413
|
+
), y = p.map((b, f) => ({ ...b, score: d[f] ?? 0 })).toSorted((b, f) => (f.score || 0) - (b.score || 0));
|
|
8409
8414
|
return i.complete({ outcome: T.success }), y.slice(0, a);
|
|
8410
8415
|
} catch (c) {
|
|
8411
8416
|
throw i.error(c), c;
|
|
@@ -8451,22 +8456,22 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
|
|
|
8451
8456
|
windowNumber: g + 1,
|
|
8452
8457
|
totalWindows: p.length
|
|
8453
8458
|
});
|
|
8454
|
-
const
|
|
8455
|
-
`),
|
|
8459
|
+
const m = f.fragments.map((P, x) => `${x + 1}. ${P}`).join(`
|
|
8460
|
+
`), w = c ? `
|
|
8456
8461
|
|
|
8457
|
-
${$(c, { tag: "style-guidance" })}` : "",
|
|
8462
|
+
${$(c, { tag: "style-guidance" })}` : "", S = `${o}${w}
|
|
8458
8463
|
|
|
8459
8464
|
Window ${g + 1} of ${p.length} - Join these fragments:
|
|
8460
8465
|
|
|
8461
|
-
${$(
|
|
8466
|
+
${$(m, { tag: "fragments" })}
|
|
8462
8467
|
|
|
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.`,
|
|
8468
|
+
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
8469
|
label: `join-window-${g + 1}`,
|
|
8465
8470
|
config: i,
|
|
8466
8471
|
onProgress: L(i.onProgress, "window")
|
|
8467
8472
|
});
|
|
8468
8473
|
return d(1), {
|
|
8469
|
-
content:
|
|
8474
|
+
content: v || f.fragments.join(" "),
|
|
8470
8475
|
window: f
|
|
8471
8476
|
};
|
|
8472
8477
|
},
|
|
@@ -8476,7 +8481,7 @@ Important: This is part of a larger sequence. Join these fragments while being m
|
|
|
8476
8481
|
return a.complete({ outcome: T.success, windows: p.length }), e.join(" ");
|
|
8477
8482
|
if (y.length === 1)
|
|
8478
8483
|
return a.complete({ outcome: T.success, windows: p.length }), y[0].content;
|
|
8479
|
-
let
|
|
8484
|
+
let b = y[0].content;
|
|
8480
8485
|
for (let f = 1; f < y.length; f++) {
|
|
8481
8486
|
a.emit({
|
|
8482
8487
|
event: k.step,
|
|
@@ -8484,15 +8489,15 @@ Important: This is part of a larger sequence. Join these fragments while being m
|
|
|
8484
8489
|
stitchNumber: f,
|
|
8485
8490
|
totalStitches: y.length - 1
|
|
8486
8491
|
});
|
|
8487
|
-
const g = y[f],
|
|
8488
|
-
if (
|
|
8489
|
-
const P = e.slice(
|
|
8492
|
+
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);
|
|
8493
|
+
if (S <= v) {
|
|
8494
|
+
const P = e.slice(S, v + 1), x = c ? `
|
|
8490
8495
|
|
|
8491
8496
|
${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), O = `${o}${x}
|
|
8492
8497
|
|
|
8493
8498
|
Stitch these two sections by resolving their overlapping region:
|
|
8494
8499
|
|
|
8495
|
-
${$(
|
|
8500
|
+
${$(b, { tag: "section-a", name: "preserve-terminals" })}
|
|
8496
8501
|
|
|
8497
8502
|
${$(g.content, { tag: "section-b", name: "preserve-terminals" })}
|
|
8498
8503
|
|
|
@@ -8501,10 +8506,10 @@ ${$(E, { tag: "overlapping-fragments" })}
|
|
|
8501
8506
|
The terminal ends of both sections should be preserved. Only resolve the overlapping middle region where these fragments appear.
|
|
8502
8507
|
|
|
8503
8508
|
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
|
-
|
|
8509
|
+
b = await M(() => _(O, i), {
|
|
8505
8510
|
label: `join-stitch-${f}`,
|
|
8506
8511
|
config: i
|
|
8507
|
-
}) ||
|
|
8512
|
+
}) || b;
|
|
8508
8513
|
} else {
|
|
8509
8514
|
const P = c ? `
|
|
8510
8515
|
|
|
@@ -8512,18 +8517,18 @@ ${$(c, { tag: "style-guidance" })}` : "", x = `${o}${P}
|
|
|
8512
8517
|
|
|
8513
8518
|
Join these two non-overlapping sections:
|
|
8514
8519
|
|
|
8515
|
-
${$(
|
|
8520
|
+
${$(b, { tag: "section-1" })}
|
|
8516
8521
|
|
|
8517
8522
|
${$(g.content, { tag: "section-2" })}
|
|
8518
8523
|
|
|
8519
8524
|
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
|
-
|
|
8525
|
+
b = await M(() => _(x, i), {
|
|
8521
8526
|
label: `join-nonoverlap-${f}`,
|
|
8522
8527
|
config: i
|
|
8523
|
-
}) ||
|
|
8528
|
+
}) || b;
|
|
8524
8529
|
}
|
|
8525
8530
|
}
|
|
8526
|
-
return a.complete({ outcome: T.success, windows: p.length }),
|
|
8531
|
+
return a.complete({ outcome: T.success, windows: p.length }), b;
|
|
8527
8532
|
} catch (p) {
|
|
8528
8533
|
throw a.error(p), p;
|
|
8529
8534
|
}
|
|
@@ -8692,9 +8697,9 @@ async function Na(e, t, n) {
|
|
|
8692
8697
|
u = $(f.join(`
|
|
8693
8698
|
`), { tag: "sources" });
|
|
8694
8699
|
}
|
|
8695
|
-
const p = $(e, { tag: "sentence" }), d = $(r, { tag: "description" }),
|
|
8700
|
+
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
8701
|
|
|
8697
|
-
${s}` : "",
|
|
8702
|
+
${s}` : "", b = `Find pop culture references that metaphorically capture the sentence based on its description.
|
|
8698
8703
|
|
|
8699
8704
|
${d}
|
|
8700
8705
|
|
|
@@ -8710,7 +8715,7 @@ Process:
|
|
|
8710
8715
|
3. Score each reference based on how well it fits (0-1 scale)
|
|
8711
8716
|
4. Identify which part of the sentence each reference connects to
|
|
8712
8717
|
|
|
8713
|
-
${
|
|
8718
|
+
${h}
|
|
8714
8719
|
|
|
8715
8720
|
Requirements:
|
|
8716
8721
|
- Each reference should be a specific moment, scene, or concept (not just the source name)
|
|
@@ -8719,7 +8724,7 @@ Requirements:
|
|
|
8719
8724
|
- Higher scores mean stronger metaphorical fit${y}`;
|
|
8720
8725
|
try {
|
|
8721
8726
|
const f = await M(
|
|
8722
|
-
() => _(
|
|
8727
|
+
() => _(b, {
|
|
8723
8728
|
...o,
|
|
8724
8729
|
responseFormat: ib
|
|
8725
8730
|
}),
|
|
@@ -8792,8 +8797,8 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8792
8797
|
const { exploration: c } = await q(i, {
|
|
8793
8798
|
exploration: J(lb)
|
|
8794
8799
|
}), l = [], u = {}, p = [];
|
|
8795
|
-
let d = !1,
|
|
8796
|
-
const { shouldSkip: y = mb, shouldStop:
|
|
8800
|
+
let d = !1, h = o;
|
|
8801
|
+
const { shouldSkip: y = mb, shouldStop: b = hb } = i, f = await re("temperature", i, 1);
|
|
8797
8802
|
let g = 0;
|
|
8798
8803
|
try {
|
|
8799
8804
|
for (; !d; ) {
|
|
@@ -8803,10 +8808,10 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8803
8808
|
attempt: g + 1,
|
|
8804
8809
|
questionsFound: l.length
|
|
8805
8810
|
}), l.length) {
|
|
8806
|
-
const x = l.filter((R) => !p.includes(R)), E = db(
|
|
8811
|
+
const x = l.filter((R) => !p.includes(R)), E = db(h, {
|
|
8807
8812
|
existing: x
|
|
8808
8813
|
});
|
|
8809
|
-
|
|
8814
|
+
h = (await M(
|
|
8810
8815
|
() => _(E, {
|
|
8811
8816
|
...i,
|
|
8812
8817
|
responseFormat: C("selected_question", cb)
|
|
@@ -8815,26 +8820,26 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8815
8820
|
label: "questions-pick-interesting",
|
|
8816
8821
|
config: i
|
|
8817
8822
|
}
|
|
8818
|
-
)).question, p.push(
|
|
8823
|
+
)).question, p.push(h);
|
|
8819
8824
|
}
|
|
8820
|
-
const
|
|
8825
|
+
const m = fb(h, {
|
|
8821
8826
|
existing: l
|
|
8822
|
-
}),
|
|
8827
|
+
}), w = {
|
|
8823
8828
|
...i,
|
|
8824
8829
|
temperature: f,
|
|
8825
8830
|
responseFormat: C("questions_list", ab)
|
|
8826
|
-
},
|
|
8831
|
+
}, S = await M(() => _(m, w), {
|
|
8827
8832
|
label: "questions-generate",
|
|
8828
8833
|
config: i
|
|
8829
|
-
}),
|
|
8834
|
+
}), v = pb(S, c);
|
|
8830
8835
|
if (c < 0.5) {
|
|
8831
|
-
const x = Math.floor(Math.random() *
|
|
8832
|
-
|
|
8836
|
+
const x = Math.floor(Math.random() * v.length);
|
|
8837
|
+
h = v[x];
|
|
8833
8838
|
}
|
|
8834
|
-
const P =
|
|
8839
|
+
const P = v.filter((x) => !(x in u));
|
|
8835
8840
|
g += 1;
|
|
8836
8841
|
for (const x of P) {
|
|
8837
|
-
if (await
|
|
8842
|
+
if (await b(x, l, v, g)) {
|
|
8838
8843
|
d = !0;
|
|
8839
8844
|
break;
|
|
8840
8845
|
}
|
|
@@ -8842,8 +8847,8 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
|
|
|
8842
8847
|
}
|
|
8843
8848
|
}
|
|
8844
8849
|
a.complete({ outcome: T.success, questions: l.length, attempts: g });
|
|
8845
|
-
} catch (
|
|
8846
|
-
throw a.error(
|
|
8850
|
+
} catch (m) {
|
|
8851
|
+
throw a.error(m), m;
|
|
8847
8852
|
}
|
|
8848
8853
|
}, Ra = async (e, t = {}) => {
|
|
8849
8854
|
const n = gb(e, t), r = [];
|
|
@@ -9446,16 +9451,16 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9446
9451
|
temperature: 0.1,
|
|
9447
9452
|
preservation: J(Pw),
|
|
9448
9453
|
mode: "structural"
|
|
9449
|
-
}), { delimiter:
|
|
9454
|
+
}), { delimiter: h = Tw } = i, y = await re(
|
|
9450
9455
|
"preservationShort",
|
|
9451
9456
|
i,
|
|
9452
9457
|
p.short
|
|
9453
|
-
),
|
|
9458
|
+
), b = await re("preservationLong", i, p.long);
|
|
9454
9459
|
try {
|
|
9455
|
-
const f = Kn(e, c), g = a.batch(f.length),
|
|
9460
|
+
const f = Kn(e, c), g = a.batch(f.length), m = await Q(
|
|
9456
9461
|
f,
|
|
9457
|
-
async (
|
|
9458
|
-
const E = kw(
|
|
9462
|
+
async (v, P) => {
|
|
9463
|
+
const E = kw(v, o, h, {
|
|
9459
9464
|
targetSplitCount: l,
|
|
9460
9465
|
mode: d
|
|
9461
9466
|
}), O = {
|
|
@@ -9468,14 +9473,14 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9468
9473
|
config: i,
|
|
9469
9474
|
onProgress: L(i.onProgress, "chunk")
|
|
9470
9475
|
}), j = R.replace(
|
|
9471
|
-
new RegExp(
|
|
9476
|
+
new RegExp(h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
|
|
9472
9477
|
""
|
|
9473
|
-
), F =
|
|
9478
|
+
), F = v.trim(), V = F.length < 100 ? y : b;
|
|
9474
9479
|
return Math.abs(j.length - F.length) > F.length * V ? (i.logger?.warn && i.logger.warn(
|
|
9475
9480
|
`Split output differs significantly from input for chunk ${P + 1}, using original chunk`
|
|
9476
|
-
), g(1),
|
|
9481
|
+
), g(1), v) : (g(1), R);
|
|
9477
9482
|
} catch (R) {
|
|
9478
|
-
return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1),
|
|
9483
|
+
return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1), v;
|
|
9479
9484
|
}
|
|
9480
9485
|
},
|
|
9481
9486
|
{
|
|
@@ -9484,12 +9489,12 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
|
|
|
9484
9489
|
abortSignal: i.abortSignal,
|
|
9485
9490
|
label: "split chunks"
|
|
9486
9491
|
}
|
|
9487
|
-
),
|
|
9492
|
+
), w = h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), S = m.join("").split(new RegExp(w)).map((v) => v.trim()).filter(Boolean);
|
|
9488
9493
|
return a.complete({
|
|
9489
9494
|
outcome: T.success,
|
|
9490
9495
|
chunks: f.length,
|
|
9491
|
-
segments:
|
|
9492
|
-
}),
|
|
9496
|
+
segments: S.length
|
|
9497
|
+
}), S;
|
|
9493
9498
|
} catch (f) {
|
|
9494
9499
|
throw a.error(f), f;
|
|
9495
9500
|
}
|
|
@@ -9516,8 +9521,8 @@ const Rs = (e) => /^\d+$/.test(e), Aw = /^([^.]+(\.[^.]+)*)$/, Ow = (e, t, n) =>
|
|
|
9516
9521
|
const u = Math.max(
|
|
9517
9522
|
Math.ceil((l - s) * a),
|
|
9518
9523
|
t
|
|
9519
|
-
), p = Math.floor(c.length / 2), d = p - Math.ceil(u / 2),
|
|
9520
|
-
c = c.slice(0, d) + i + c.slice(
|
|
9524
|
+
), p = Math.floor(c.length / 2), d = p - Math.ceil(u / 2), h = p + Math.floor(u / 2);
|
|
9525
|
+
c = c.slice(0, d) + i + c.slice(h), l = o.toTokens(c).length;
|
|
9521
9526
|
}
|
|
9522
9527
|
return c;
|
|
9523
9528
|
}, Cw = ({ budget: e, type: t, value: n, fixes: r = [], llmOptions: s, sensitivity: o }) => {
|
|
@@ -9574,22 +9579,22 @@ class Ka extends Map {
|
|
|
9574
9579
|
targetTokenCount: this.maxTokensPerValue,
|
|
9575
9580
|
model: c
|
|
9576
9581
|
}), p = c.toTokens(u).length, d = p < l;
|
|
9577
|
-
let
|
|
9582
|
+
let h = u;
|
|
9578
9583
|
if (o) {
|
|
9579
|
-
const
|
|
9584
|
+
const b = {
|
|
9580
9585
|
...this.llmOptions,
|
|
9581
9586
|
...i.modelOptions
|
|
9582
9587
|
};
|
|
9583
|
-
(i.sensitivity?.whitelist || i.sensitivity?.blacklist) && (
|
|
9588
|
+
(i.sensitivity?.whitelist || i.sensitivity?.blacklist) && (b.sensitive = !0), h = await Cw({
|
|
9584
9589
|
budget: o,
|
|
9585
9590
|
fixes: i.fixes,
|
|
9586
|
-
llmOptions:
|
|
9591
|
+
llmOptions: b,
|
|
9587
9592
|
sensitivity: i.sensitivity,
|
|
9588
9593
|
type: i.type,
|
|
9589
9594
|
value: u
|
|
9590
9595
|
});
|
|
9591
9596
|
}
|
|
9592
|
-
const y = c.toTokens(
|
|
9597
|
+
const y = c.toTokens(h).length;
|
|
9593
9598
|
t.emit({
|
|
9594
9599
|
event: k.step,
|
|
9595
9600
|
stepName: "context-trim",
|
|
@@ -9600,7 +9605,7 @@ class Ka extends Map {
|
|
|
9600
9605
|
budget: o,
|
|
9601
9606
|
strategy: o ? "shorten+summarize" : "shorten",
|
|
9602
9607
|
ratio: Number((y / l).toFixed(3))
|
|
9603
|
-
}), this.cache.set(s,
|
|
9608
|
+
}), this.cache.set(s, h), r(1);
|
|
9604
9609
|
}
|
|
9605
9610
|
this.isCacheValid = !0, t.complete({ outcome: T.success, entries: n.length });
|
|
9606
9611
|
} catch (n) {
|
|
@@ -9673,42 +9678,42 @@ const Nw = "http://json-schema.org/draft-07/schema#", Rw = "object", Mw = { tags
|
|
|
9673
9678
|
}, Ls = "tag-vocabulary";
|
|
9674
9679
|
function Gn(e, t, n = {}) {
|
|
9675
9680
|
const { topN: r = 3, bottomN: s = 3, problematicSampleSize: o = 3 } = n, i = {};
|
|
9676
|
-
e.tags.forEach((
|
|
9677
|
-
i[
|
|
9678
|
-
}), t.forEach((
|
|
9679
|
-
|
|
9680
|
-
i[
|
|
9681
|
+
e.tags.forEach((m) => {
|
|
9682
|
+
i[m.id] = 0;
|
|
9683
|
+
}), t.forEach((m) => {
|
|
9684
|
+
m && Array.isArray(m) && m.forEach((w) => {
|
|
9685
|
+
i[w] !== void 0 && i[w]++;
|
|
9681
9686
|
});
|
|
9682
9687
|
});
|
|
9683
|
-
const a = Object.entries(i).map(([
|
|
9684
|
-
tag: e.tags.find((
|
|
9685
|
-
count:
|
|
9686
|
-
})).toSorted((
|
|
9688
|
+
const a = Object.entries(i).map(([m, w]) => ({
|
|
9689
|
+
tag: e.tags.find((S) => S.id === m),
|
|
9690
|
+
count: w
|
|
9691
|
+
})).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
9692
|
totalItems: t.length,
|
|
9688
9693
|
itemsWithTags: u,
|
|
9689
9694
|
coveragePercent: t.length > 0 ? u / t.length * 100 : 0,
|
|
9690
9695
|
avgTagsPerItem: d,
|
|
9691
9696
|
totalTags: e.tags.length,
|
|
9692
|
-
unusedTags: a.filter((
|
|
9693
|
-
}, y = [],
|
|
9694
|
-
return t.forEach((
|
|
9695
|
-
!
|
|
9697
|
+
unusedTags: a.filter((m) => m.count === 0).length
|
|
9698
|
+
}, y = [], b = [], f = [], g = [];
|
|
9699
|
+
return t.forEach((m, w) => {
|
|
9700
|
+
!m || m.length === 0 ? b.length < o && b.push({
|
|
9696
9701
|
type: "untagged",
|
|
9697
|
-
itemIndex:
|
|
9702
|
+
itemIndex: w,
|
|
9698
9703
|
tags: []
|
|
9699
|
-
}) :
|
|
9704
|
+
}) : m.length > d * 2 ? f.length < o && f.push({
|
|
9700
9705
|
type: "overtagged",
|
|
9701
|
-
itemIndex:
|
|
9702
|
-
tags:
|
|
9703
|
-
tagCount:
|
|
9704
|
-
}) :
|
|
9706
|
+
itemIndex: w,
|
|
9707
|
+
tags: m,
|
|
9708
|
+
tagCount: m.length
|
|
9709
|
+
}) : m.length === 1 && d > 1.5 && g.length < o && g.push({
|
|
9705
9710
|
type: "ambiguous",
|
|
9706
|
-
itemIndex:
|
|
9707
|
-
tags:
|
|
9711
|
+
itemIndex: w,
|
|
9712
|
+
tags: m,
|
|
9708
9713
|
tagCount: 1
|
|
9709
9714
|
});
|
|
9710
|
-
}), y.push(...
|
|
9711
|
-
stats:
|
|
9715
|
+
}), y.push(...b, ...f, ...g), {
|
|
9716
|
+
stats: h,
|
|
9712
9717
|
mostUsed: c,
|
|
9713
9718
|
leastUsed: l,
|
|
9714
9719
|
problematicItems: y,
|
|
@@ -9793,12 +9798,12 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
|
|
|
9793
9798
|
if (s.initialVocab)
|
|
9794
9799
|
p = JSON.parse(s.initialVocab);
|
|
9795
9800
|
else {
|
|
9796
|
-
const
|
|
9801
|
+
const b = t.slice(0, Math.min(u, t.length));
|
|
9797
9802
|
c.emit({
|
|
9798
9803
|
event: k.step,
|
|
9799
9804
|
stepName: "generate-initial-vocabulary",
|
|
9800
|
-
sampleCount:
|
|
9801
|
-
}), p = await Dw(i,
|
|
9805
|
+
sampleCount: b.length
|
|
9806
|
+
}), p = await Dw(i, b, a);
|
|
9802
9807
|
}
|
|
9803
9808
|
c.emit({
|
|
9804
9809
|
event: k.step,
|
|
@@ -9806,8 +9811,8 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
|
|
|
9806
9811
|
itemCount: t.length,
|
|
9807
9812
|
initialVocab: p
|
|
9808
9813
|
});
|
|
9809
|
-
const d = await l(t, p),
|
|
9810
|
-
c.emit({ event: k.step, stepName: "refine-vocabulary", statistics:
|
|
9814
|
+
const d = await l(t, p), h = Gn(p, d);
|
|
9815
|
+
c.emit({ event: k.step, stepName: "refine-vocabulary", statistics: h });
|
|
9811
9816
|
const y = await qw(p, d, i, a);
|
|
9812
9817
|
return c.complete({ outcome: T.success }), y;
|
|
9813
9818
|
} catch (l) {
|
|
@@ -9825,20 +9830,20 @@ async function Ha(e, t = {}) {
|
|
|
9825
9830
|
try {
|
|
9826
9831
|
let c;
|
|
9827
9832
|
if (r.rawThemes)
|
|
9828
|
-
c = r.rawThemes.split(",").map((
|
|
9833
|
+
c = r.rawThemes.split(",").map((h) => h.trim()).filter(Boolean);
|
|
9829
9834
|
else {
|
|
9830
|
-
const
|
|
9835
|
+
const h = Fw(n);
|
|
9831
9836
|
i.emit({
|
|
9832
9837
|
event: k.phase,
|
|
9833
9838
|
phase: "extraction"
|
|
9834
9839
|
});
|
|
9835
|
-
const
|
|
9840
|
+
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
9841
|
|
|
9837
|
-
${s}` : ""}`, f = Wn(
|
|
9838
|
-
c = (await Ie(f,
|
|
9842
|
+
${s}` : ""}`, f = Wn(h);
|
|
9843
|
+
c = (await Ie(f, b, {
|
|
9839
9844
|
...o,
|
|
9840
9845
|
onProgress: L(o.onProgress, "themes:extract")
|
|
9841
|
-
})).split(",").map((
|
|
9846
|
+
})).split(",").map((m) => m.trim()).filter(Boolean);
|
|
9842
9847
|
}
|
|
9843
9848
|
i.emit({
|
|
9844
9849
|
event: k.phase,
|
|
@@ -9848,7 +9853,7 @@ ${s}` : ""}`, f = Wn(m);
|
|
|
9848
9853
|
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
9854
|
...o,
|
|
9850
9855
|
onProgress: L(o.onProgress, "themes:refine")
|
|
9851
|
-
})).split(",").map((
|
|
9856
|
+
})).split(",").map((h) => h.trim()).filter(Boolean);
|
|
9852
9857
|
return i.complete({ outcome: T.success, themes: d.length }), d;
|
|
9853
9858
|
} catch (c) {
|
|
9854
9859
|
throw i.error(c), c;
|
|
@@ -9927,25 +9932,25 @@ async function Qa(e, t, n) {
|
|
|
9927
9932
|
overlap: u,
|
|
9928
9933
|
maxParallel: p,
|
|
9929
9934
|
errorPosture: d,
|
|
9930
|
-
llmDedup:
|
|
9935
|
+
llmDedup: h,
|
|
9931
9936
|
knowledgeBase: y,
|
|
9932
|
-
enrichMap:
|
|
9937
|
+
enrichMap: b
|
|
9933
9938
|
} = await q(i, {
|
|
9934
9939
|
enrichment: J(zw, ["llmDedup", "knowledgeBase", "enrichMap"]),
|
|
9935
9940
|
chunkSize: 2e3,
|
|
9936
9941
|
overlap: 200,
|
|
9937
9942
|
maxParallel: 3,
|
|
9938
9943
|
errorPosture: z.resilient
|
|
9939
|
-
}), f = s.knowledge, { onProgress: g, batchSize:
|
|
9944
|
+
}), f = s.knowledge, { onProgress: g, batchSize: m, now: w } = i;
|
|
9940
9945
|
try {
|
|
9941
|
-
const
|
|
9946
|
+
const S = 1 + (h ? 1 : 0) + (y ? 2 : 0), v = c.batch(S), P = Kn(e, l, { overlap: u }), x = [];
|
|
9942
9947
|
let E = 0;
|
|
9943
9948
|
await Q(
|
|
9944
9949
|
P,
|
|
9945
9950
|
async (j, F) => {
|
|
9946
9951
|
try {
|
|
9947
9952
|
const V = await M(
|
|
9948
|
-
() => Vw(j, { ...i, now:
|
|
9953
|
+
() => Vw(j, { ...i, now: w, systemPrompt: a }),
|
|
9949
9954
|
{
|
|
9950
9955
|
label: `timeline chunk ${F + 1}`,
|
|
9951
9956
|
config: i
|
|
@@ -9966,9 +9971,9 @@ async function Qa(e, t, n) {
|
|
|
9966
9971
|
label: "timeline chunks",
|
|
9967
9972
|
abortSignal: i.abortSignal
|
|
9968
9973
|
}
|
|
9969
|
-
), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`),
|
|
9974
|
+
), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`), v(1);
|
|
9970
9975
|
let O = Ww([x]);
|
|
9971
|
-
if (
|
|
9976
|
+
if (h && O.length > 0) {
|
|
9972
9977
|
const j = O.map((H) => `- ${H.timestamp}: ${H.name}`).join(`
|
|
9973
9978
|
`), 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
9979
|
|
|
@@ -9977,7 +9982,7 @@ ${$(j, { tag: "events" })}`, V = await _(F, {
|
|
|
9977
9982
|
systemPrompt: "You are a timeline deduplication engine. Return all unique events, merging only true duplicates.",
|
|
9978
9983
|
responseFormat: C(Le.name, Le.schema)
|
|
9979
9984
|
}), Y = V?.events || V;
|
|
9980
|
-
Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)),
|
|
9985
|
+
Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)), v(1);
|
|
9981
9986
|
}
|
|
9982
9987
|
if ((y || f) && O.length > 0) {
|
|
9983
9988
|
let j = [];
|
|
@@ -10002,7 +10007,7 @@ Return as JSON with the same event format, maintaining chronological order.`, ie
|
|
|
10002
10007
|
...i,
|
|
10003
10008
|
initial: JSON.stringify({ events: [] }),
|
|
10004
10009
|
responseFormat: C(Le.name, Le.schema),
|
|
10005
|
-
...
|
|
10010
|
+
...m !== void 0 && { batchSize: m },
|
|
10006
10011
|
onProgress: L(i.onProgress, "reduce:knowledge-base")
|
|
10007
10012
|
});
|
|
10008
10013
|
try {
|
|
@@ -10011,7 +10016,7 @@ Return as JSON with the same event format, maintaining chronological order.`, ie
|
|
|
10011
10016
|
ne("Failed to parse knowledge base:", Z.message);
|
|
10012
10017
|
}
|
|
10013
10018
|
}
|
|
10014
|
-
c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }),
|
|
10019
|
+
c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }), v(1);
|
|
10015
10020
|
const F = j.map((G) => `- ${G.timestamp}: ${G.name}`).join(`
|
|
10016
10021
|
`), V = `Given an extracted event, enrich it using this knowledge base:
|
|
10017
10022
|
|
|
@@ -10028,7 +10033,7 @@ Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate t
|
|
|
10028
10033
|
V,
|
|
10029
10034
|
{
|
|
10030
10035
|
...i,
|
|
10031
|
-
...
|
|
10036
|
+
...m !== void 0 && { batchSize: m },
|
|
10032
10037
|
maxParallel: p,
|
|
10033
10038
|
onProgress: L(i.onProgress, "map:enrichment")
|
|
10034
10039
|
}
|
|
@@ -10045,12 +10050,12 @@ Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate t
|
|
|
10045
10050
|
}
|
|
10046
10051
|
return O[te];
|
|
10047
10052
|
}), ee = new Set(H.map((G) => G.name.toLowerCase())), pe = j.filter((G) => !ee.has(G.name.toLowerCase()));
|
|
10048
|
-
O = Ke([...H, ...pe]),
|
|
10053
|
+
O = Ke([...H, ...pe]), v(1);
|
|
10049
10054
|
}
|
|
10050
10055
|
const R = E > 0 ? T.partial : T.success;
|
|
10051
10056
|
return c.complete({ outcome: R }), O;
|
|
10052
|
-
} catch (
|
|
10053
|
-
throw c.error(
|
|
10057
|
+
} catch (S) {
|
|
10058
|
+
throw c.error(S), S;
|
|
10054
10059
|
}
|
|
10055
10060
|
}
|
|
10056
10061
|
Qa.knownTexts = ["knowledge"];
|
|
@@ -10175,19 +10180,19 @@ async function tc(e, t, n) {
|
|
|
10175
10180
|
try {
|
|
10176
10181
|
const l = Zw(e, a), p = [...l].reverse().map((g) => g.text), d = s ? `
|
|
10177
10182
|
|
|
10178
|
-
${s}` : "",
|
|
10183
|
+
${s}` : "", h = `${$(r, { tag: "removal_criteria" })}
|
|
10179
10184
|
|
|
10180
10185
|
NOTE: These text blocks are in REVERSE order (from end to beginning of document).
|
|
10181
10186
|
Score how important THE ENTIRE TEXT BLOCK is to KEEP in the document (0 = should be removed, 10 = must keep).
|
|
10182
10187
|
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}`,
|
|
10188
|
+
Consider the removal criteria above when scoring.${d}`, b = (await ke(p, h, {
|
|
10184
10189
|
...o,
|
|
10185
10190
|
onProgress: L(o.onProgress, "score:relevance")
|
|
10186
10191
|
// Don't use stopOnThreshold - we need all scores to find high ones
|
|
10187
10192
|
})).findIndex((g) => (g ?? 1 / 0) < c);
|
|
10188
10193
|
let f;
|
|
10189
|
-
if (
|
|
10190
|
-
const g = l.length - 1 -
|
|
10194
|
+
if (b >= 0) {
|
|
10195
|
+
const g = l.length - 1 - b;
|
|
10191
10196
|
g > 0 ? f = l[g - 1].endIndex : f = 0;
|
|
10192
10197
|
} else
|
|
10193
10198
|
f = e.length;
|
|
@@ -10254,12 +10259,12 @@ ${r}` : "", o = A(Us, { llm: { sensitive: !0 }, ...t }), i = I(Us, o.onProgress,
|
|
|
10254
10259
|
const u = i.batch(l.length), p = await Q(
|
|
10255
10260
|
l,
|
|
10256
10261
|
async (d) => {
|
|
10257
|
-
const
|
|
10262
|
+
const h = await M(() => _(d, { ...o, responseFormat: tv }), {
|
|
10258
10263
|
label: "veiled-variants",
|
|
10259
10264
|
config: o,
|
|
10260
10265
|
onProgress: L(o.onProgress, "strategy")
|
|
10261
10266
|
});
|
|
10262
|
-
return u(1),
|
|
10267
|
+
return u(1), h;
|
|
10263
10268
|
},
|
|
10264
10269
|
{ maxParallel: 3, errorPosture: z.resilient, abortSignal: o.abortSignal }
|
|
10265
10270
|
);
|
|
@@ -10363,22 +10368,22 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
|
|
|
10363
10368
|
w: f.info.width,
|
|
10364
10369
|
h: f.info.height
|
|
10365
10370
|
})), 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),
|
|
10371
|
+
const m = c.filter((w, S) => S % t === g);
|
|
10372
|
+
return m.length > 0 ? Math.max(...m.map((w) => w.w)) : 0;
|
|
10373
|
+
}), p = u.reduce((f, g) => f + g, 0) + r * (t - 1), d = l * n + r * (l - 1), h = [];
|
|
10369
10374
|
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="${
|
|
10375
|
+
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);
|
|
10376
|
+
if (c[f].x = w, c[f].y = S, h.push({ input: a[f].data, left: w, top: S }), c[f].label) {
|
|
10377
|
+
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(
|
|
10378
|
+
`<svg width="${c[f].w}" height="${v}">
|
|
10379
|
+
<rect x="0" y="0" width="${c[f].w}" height="${v}" fill="rgba(0,0,0,0.6)"/>
|
|
10380
|
+
<text x="4" y="${v - 3}" font-family="sans-serif" font-size="${P}" fill="white">${x}</text>
|
|
10376
10381
|
</svg>`
|
|
10377
10382
|
);
|
|
10378
|
-
|
|
10383
|
+
h.push({
|
|
10379
10384
|
input: E,
|
|
10380
|
-
left:
|
|
10381
|
-
top:
|
|
10385
|
+
left: w,
|
|
10386
|
+
top: S + c[f].h - v
|
|
10382
10387
|
});
|
|
10383
10388
|
}
|
|
10384
10389
|
}
|
|
@@ -10390,13 +10395,13 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
|
|
|
10390
10395
|
channels: 3,
|
|
10391
10396
|
background: { r: 128, g: 128, b: 128 }
|
|
10392
10397
|
}
|
|
10393
|
-
}).composite(
|
|
10394
|
-
const
|
|
10398
|
+
}).composite(h).jpeg({ quality: s }).toFile(y);
|
|
10399
|
+
const b = await go(y);
|
|
10395
10400
|
return {
|
|
10396
10401
|
path: y,
|
|
10397
10402
|
width: p,
|
|
10398
10403
|
height: d,
|
|
10399
|
-
sizeBytes:
|
|
10404
|
+
sizeBytes: b.size,
|
|
10400
10405
|
tiles: c
|
|
10401
10406
|
};
|
|
10402
10407
|
}
|
|
@@ -10426,28 +10431,28 @@ ${s}` : r, i = A(Vs, n), a = I(Vs, i.onProgress, i);
|
|
|
10426
10431
|
}), p = u && c.length > 1;
|
|
10427
10432
|
let d;
|
|
10428
10433
|
if (p) {
|
|
10429
|
-
const f = c.map((
|
|
10434
|
+
const f = c.map((S) => S.path), g = c.map((S) => S.label).filter(Boolean), m = await pv(f, {
|
|
10430
10435
|
labels: g.length > 0 ? g : void 0
|
|
10431
10436
|
});
|
|
10432
10437
|
a.emit({
|
|
10433
10438
|
event: "tile",
|
|
10434
|
-
path:
|
|
10435
|
-
width:
|
|
10436
|
-
height:
|
|
10437
|
-
sizeBytes:
|
|
10438
|
-
}), d = [await Ws(
|
|
10439
|
+
path: m.path,
|
|
10440
|
+
width: m.width,
|
|
10441
|
+
height: m.height,
|
|
10442
|
+
sizeBytes: m.sizeBytes
|
|
10443
|
+
}), d = [await Ws(m.path)];
|
|
10439
10444
|
} else
|
|
10440
10445
|
d = await Q(c, (f) => Ws(f.path), {
|
|
10441
10446
|
maxParallel: 4,
|
|
10442
10447
|
label: "analyze-image:encode",
|
|
10443
10448
|
abortSignal: i.abortSignal
|
|
10444
10449
|
});
|
|
10445
|
-
const
|
|
10450
|
+
const h = Zo(o, d), y = i.responseFormat ? i : { ...i, responseFormat: dv }, b = await M(() => _(h, y), {
|
|
10446
10451
|
label: "analyze-image:llm",
|
|
10447
10452
|
config: i,
|
|
10448
10453
|
onProgress: L(i.onProgress, "llm")
|
|
10449
10454
|
});
|
|
10450
|
-
return a.complete({ outcome: T.success, imageCount: l, tiled: p }),
|
|
10455
|
+
return a.complete({ outcome: T.success, imageCount: l, tiled: p }), b;
|
|
10451
10456
|
} catch (u) {
|
|
10452
10457
|
throw a.error(u, { imageCount: l }), u;
|
|
10453
10458
|
}
|
|
@@ -10491,7 +10496,7 @@ ${r}` : n, o = A(Js, t), i = I(Js, o.onProgress, o);
|
|
|
10491
10496
|
functionArgsAsArray: [l]
|
|
10492
10497
|
};
|
|
10493
10498
|
else {
|
|
10494
|
-
const
|
|
10499
|
+
const h = p.arguments, y = Array.isArray(h) ? h : [h];
|
|
10495
10500
|
d = {
|
|
10496
10501
|
...p,
|
|
10497
10502
|
functionArgsAsArray: y,
|
|
@@ -10838,15 +10843,15 @@ function mc(e = {}) {
|
|
|
10838
10843
|
const t = A(Qs, e), n = I(Qs, t.onProgress, t);
|
|
10839
10844
|
n.start();
|
|
10840
10845
|
try {
|
|
10841
|
-
let g = function(
|
|
10842
|
-
const
|
|
10846
|
+
let g = function(m, w = "log", S = 0) {
|
|
10847
|
+
const v = Ov(S), P = {
|
|
10843
10848
|
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
10844
10849
|
ts: /* @__PURE__ */ new Date(),
|
|
10845
|
-
raw:
|
|
10850
|
+
raw: m,
|
|
10846
10851
|
// Store original data as-is (any structure)
|
|
10847
10852
|
meta: /* @__PURE__ */ new Map([
|
|
10848
|
-
["level",
|
|
10849
|
-
["fileContext",
|
|
10853
|
+
["level", w],
|
|
10854
|
+
["fileContext", v]
|
|
10850
10855
|
]),
|
|
10851
10856
|
attachments: {},
|
|
10852
10857
|
// AI enrichments to merge
|
|
@@ -10857,41 +10862,41 @@ function mc(e = {}) {
|
|
|
10857
10862
|
for (const x of s)
|
|
10858
10863
|
if (!x.filters || x.filters(P)) {
|
|
10859
10864
|
let E;
|
|
10860
|
-
|
|
10861
|
-
data:
|
|
10865
|
+
m == null ? E = {
|
|
10866
|
+
data: m,
|
|
10862
10867
|
id: P.id,
|
|
10863
10868
|
ts: P.ts,
|
|
10864
|
-
level:
|
|
10869
|
+
level: w,
|
|
10865
10870
|
...P.attachments
|
|
10866
|
-
} : typeof
|
|
10867
|
-
data:
|
|
10871
|
+
} : typeof m == "string" || typeof m == "number" || typeof m == "boolean" ? E = {
|
|
10872
|
+
data: m,
|
|
10868
10873
|
id: P.id,
|
|
10869
10874
|
ts: P.ts,
|
|
10870
|
-
level:
|
|
10875
|
+
level: w,
|
|
10871
10876
|
...P.attachments
|
|
10872
|
-
} : typeof
|
|
10873
|
-
...
|
|
10877
|
+
} : typeof m == "object" ? E = {
|
|
10878
|
+
...m,
|
|
10874
10879
|
// Spread all original properties
|
|
10875
10880
|
...P.attachments,
|
|
10876
10881
|
// Merge AI enrichments
|
|
10877
10882
|
// Add internal metadata only if not already present
|
|
10878
|
-
...
|
|
10879
|
-
...
|
|
10880
|
-
...
|
|
10883
|
+
...m.id ? {} : { id: P.id },
|
|
10884
|
+
...m.ts ? {} : { ts: P.ts },
|
|
10885
|
+
...m.level ? {} : { level: w },
|
|
10881
10886
|
// Add file context
|
|
10882
|
-
...
|
|
10883
|
-
...
|
|
10887
|
+
...m.file ? {} : { file: v.filePath },
|
|
10888
|
+
...m.line ? {} : { line: v.line }
|
|
10884
10889
|
} : E = {
|
|
10885
|
-
data:
|
|
10890
|
+
data: m,
|
|
10886
10891
|
id: P.id,
|
|
10887
10892
|
ts: P.ts,
|
|
10888
|
-
level:
|
|
10893
|
+
level: w,
|
|
10889
10894
|
...P.attachments
|
|
10890
10895
|
}, E.aiMeta = P.aiMeta, d.get(x.laneId).push(E);
|
|
10891
10896
|
}
|
|
10892
10897
|
if (a && f(), p) {
|
|
10893
|
-
const x = `LLM Logger processed: ${JSON.stringify(
|
|
10894
|
-
switch (
|
|
10898
|
+
const x = `LLM Logger processed: ${JSON.stringify(m)}`;
|
|
10899
|
+
switch (w) {
|
|
10895
10900
|
case "error":
|
|
10896
10901
|
p.error(x);
|
|
10897
10902
|
break;
|
|
@@ -10923,19 +10928,19 @@ function mc(e = {}) {
|
|
|
10923
10928
|
immediateFlush: a = !1,
|
|
10924
10929
|
hostLogger: c = void 0
|
|
10925
10930
|
} = e, l = new Mn(r), u = [], p = c ? Hs(c) : void 0, d = /* @__PURE__ */ new Map();
|
|
10926
|
-
s.forEach((
|
|
10927
|
-
Iv(
|
|
10931
|
+
s.forEach((m) => {
|
|
10932
|
+
Iv(m.laneId !== void 0, "Each lane must have an laneId property").toBe(!0), d.set(m.laneId, []);
|
|
10928
10933
|
});
|
|
10929
|
-
const
|
|
10930
|
-
let
|
|
10931
|
-
o.forEach((
|
|
10932
|
-
const
|
|
10933
|
-
y.set(
|
|
10934
|
-
const
|
|
10935
|
-
if (!
|
|
10934
|
+
const h = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
|
|
10935
|
+
let b = !1;
|
|
10936
|
+
o.forEach((m) => {
|
|
10937
|
+
const w = l.registerReader();
|
|
10938
|
+
y.set(m.processorId, w), h.set(m.processorId, -1);
|
|
10939
|
+
const S = m.batchSize || 10, v = async () => {
|
|
10940
|
+
if (!b)
|
|
10936
10941
|
try {
|
|
10937
|
-
const P = await l.readBatch(
|
|
10938
|
-
# Processor: ${
|
|
10942
|
+
const P = await l.readBatch(w, S, m.batchTimeout), x = Cv(P.data), O = `# Log Processing Context
|
|
10943
|
+
# Processor: ${m.processorId} (${m.description || "No description"})
|
|
10939
10944
|
# Batch size: ${P.data.length} logs
|
|
10940
10945
|
# Task: Analyze the following NDJSON log entries and return bulk adjustments
|
|
10941
10946
|
#
|
|
@@ -10955,7 +10960,7 @@ function mc(e = {}) {
|
|
|
10955
10960
|
# ]
|
|
10956
10961
|
#
|
|
10957
10962
|
# NDJSON Log Data:
|
|
10958
|
-
` + x, R = await
|
|
10963
|
+
` + x, R = await m.process(O);
|
|
10959
10964
|
if (Array.isArray(R))
|
|
10960
10965
|
for (const j of R) {
|
|
10961
10966
|
const F = u.findIndex((V) => V.id === j.logId);
|
|
@@ -10967,53 +10972,53 @@ function mc(e = {}) {
|
|
|
10967
10972
|
j.aiMeta && (V.aiMeta || (V.aiMeta = {}), Object.assign(V.aiMeta, j.aiMeta));
|
|
10968
10973
|
}
|
|
10969
10974
|
}
|
|
10970
|
-
|
|
10975
|
+
h.set(m.processorId, P.lastOffset), b || setTimeout(v, 0);
|
|
10971
10976
|
} catch (P) {
|
|
10972
|
-
p && p.error(`Processor ${
|
|
10977
|
+
p && p.error(`Processor ${m.processorId} error: ${P.message}`), b || setTimeout(v, 1e3);
|
|
10973
10978
|
}
|
|
10974
10979
|
};
|
|
10975
|
-
|
|
10980
|
+
v();
|
|
10976
10981
|
});
|
|
10977
10982
|
const f = () => {
|
|
10978
|
-
for (const [
|
|
10979
|
-
if (
|
|
10980
|
-
const
|
|
10981
|
-
if (
|
|
10982
|
-
const
|
|
10983
|
-
|
|
10983
|
+
for (const [m, w] of d)
|
|
10984
|
+
if (w.length > 0) {
|
|
10985
|
+
const S = s.find((v) => v.laneId === m);
|
|
10986
|
+
if (S) {
|
|
10987
|
+
const v = w.filter((P) => !P.aiMeta?.skip);
|
|
10988
|
+
v.length > 0 && S.writer(v), w.length = 0;
|
|
10984
10989
|
}
|
|
10985
10990
|
}
|
|
10986
10991
|
};
|
|
10987
|
-
return a || s.forEach((
|
|
10988
|
-
const
|
|
10989
|
-
|
|
10992
|
+
return a || s.forEach((m) => {
|
|
10993
|
+
const w = () => {
|
|
10994
|
+
b || (f(), setTimeout(w, i));
|
|
10990
10995
|
};
|
|
10991
|
-
|
|
10996
|
+
w();
|
|
10992
10997
|
}), n.complete({
|
|
10993
10998
|
outcome: T.success,
|
|
10994
10999
|
lanes: s.length,
|
|
10995
11000
|
processors: o.length
|
|
10996
11001
|
}), {
|
|
10997
11002
|
// Standard logger interface - accepts any structured data
|
|
10998
|
-
log: (
|
|
10999
|
-
info: (
|
|
11000
|
-
warn: (
|
|
11001
|
-
error: (
|
|
11002
|
-
debug: (
|
|
11003
|
-
trace: (
|
|
11004
|
-
fatal: (
|
|
11003
|
+
log: (m, w = 0) => g(m, "log", w),
|
|
11004
|
+
info: (m, w = 0) => g(m, "info", w),
|
|
11005
|
+
warn: (m, w = 0) => g(m, "warn", w),
|
|
11006
|
+
error: (m, w = 0) => g(m, "error", w),
|
|
11007
|
+
debug: (m, w = 0) => g(m, "debug", w),
|
|
11008
|
+
trace: (m, w = 0) => g(m, "trace", w),
|
|
11009
|
+
fatal: (m, w = 0) => g(m, "fatal", w),
|
|
11005
11010
|
// Enhanced attachment API
|
|
11006
|
-
attachToLog: (
|
|
11007
|
-
const
|
|
11008
|
-
return
|
|
11011
|
+
attachToLog: (m, w, S) => {
|
|
11012
|
+
const v = u.findIndex((P) => P.id === m);
|
|
11013
|
+
return v !== -1 ? (Ys(u[v].attachments, w, S), !0) : !1;
|
|
11009
11014
|
},
|
|
11010
|
-
getLogAttachment: (
|
|
11011
|
-
const
|
|
11012
|
-
return
|
|
11015
|
+
getLogAttachment: (m, w) => {
|
|
11016
|
+
const S = u.find((v) => v.id === m);
|
|
11017
|
+
return S ? _v(S.attachments, w) : void 0;
|
|
11013
11018
|
},
|
|
11014
|
-
markLogSkippable: (
|
|
11015
|
-
const
|
|
11016
|
-
return
|
|
11019
|
+
markLogSkippable: (m, w = !0) => {
|
|
11020
|
+
const S = u.findIndex((v) => v.id === m);
|
|
11021
|
+
return S !== -1 ? (u[S].aiMeta.skip = w, !0) : !1;
|
|
11017
11022
|
},
|
|
11018
11023
|
// Ring buffer access - legacy API compatibility
|
|
11019
11024
|
ringBuffer: {
|
|
@@ -11022,27 +11027,27 @@ function mc(e = {}) {
|
|
|
11022
11027
|
clear: () => {
|
|
11023
11028
|
u.length = 0, l.clear();
|
|
11024
11029
|
},
|
|
11025
|
-
tail: (
|
|
11026
|
-
head: (
|
|
11027
|
-
filter: (
|
|
11030
|
+
tail: (m) => u.slice(-m),
|
|
11031
|
+
head: (m) => u.slice(0, m),
|
|
11032
|
+
filter: (m) => u.filter(m)
|
|
11028
11033
|
},
|
|
11029
11034
|
// Processor status
|
|
11030
|
-
getProcessorOffsets: () => new Map(
|
|
11035
|
+
getProcessorOffsets: () => new Map(h),
|
|
11031
11036
|
// Host logger integration
|
|
11032
|
-
setHostLogger: (
|
|
11037
|
+
setHostLogger: (m) => (e.hostLogger = m, Hs(m)),
|
|
11033
11038
|
// Utility methods
|
|
11034
11039
|
flush: () => {
|
|
11035
11040
|
f();
|
|
11036
11041
|
},
|
|
11037
11042
|
clear: () => {
|
|
11038
11043
|
u.length = 0, l.clear();
|
|
11039
|
-
for (const
|
|
11040
|
-
|
|
11044
|
+
for (const m of d.values())
|
|
11045
|
+
m.length = 0;
|
|
11041
11046
|
},
|
|
11042
11047
|
destroy: () => {
|
|
11043
|
-
|
|
11044
|
-
for (const
|
|
11045
|
-
|
|
11048
|
+
b = !0, f(), u.length = 0, l.clear();
|
|
11049
|
+
for (const m of d.values())
|
|
11050
|
+
m.length = 0;
|
|
11046
11051
|
},
|
|
11047
11052
|
getConfig: () => ({
|
|
11048
11053
|
ringBufferSize: r,
|
|
@@ -11053,22 +11058,22 @@ function mc(e = {}) {
|
|
|
11053
11058
|
}),
|
|
11054
11059
|
getStats: () => ({
|
|
11055
11060
|
...l.getStats(),
|
|
11056
|
-
processorOffsets: Object.fromEntries(
|
|
11057
|
-
processors: o.map((
|
|
11058
|
-
id:
|
|
11059
|
-
processedOffset:
|
|
11061
|
+
processorOffsets: Object.fromEntries(h),
|
|
11062
|
+
processors: o.map((m) => ({
|
|
11063
|
+
id: m.processorId,
|
|
11064
|
+
processedOffset: h.get(m.processorId)
|
|
11060
11065
|
}))
|
|
11061
11066
|
}),
|
|
11062
11067
|
// Wait for all processors to catch up to current write position
|
|
11063
|
-
waitForProcessing: async (
|
|
11064
|
-
const
|
|
11065
|
-
if (
|
|
11068
|
+
waitForProcessing: async (m = 3e4) => {
|
|
11069
|
+
const w = Date.now(), v = l.getStats().writeOffset;
|
|
11070
|
+
if (v === 0)
|
|
11066
11071
|
return;
|
|
11067
11072
|
f();
|
|
11068
|
-
const P = (x, E) => E + 1 <
|
|
11069
|
-
for (; Date.now() -
|
|
11073
|
+
const P = (x, E) => E + 1 < v;
|
|
11074
|
+
for (; Date.now() - w < m; ) {
|
|
11070
11075
|
let x = !0;
|
|
11071
|
-
for (const [E, O] of
|
|
11076
|
+
for (const [E, O] of h)
|
|
11072
11077
|
if (P(E, O)) {
|
|
11073
11078
|
x = !1;
|
|
11074
11079
|
break;
|
|
@@ -11081,13 +11086,13 @@ function mc(e = {}) {
|
|
|
11081
11086
|
}
|
|
11082
11087
|
if (p) {
|
|
11083
11088
|
const x = [];
|
|
11084
|
-
for (const [E, O] of
|
|
11089
|
+
for (const [E, O] of h)
|
|
11085
11090
|
if (P(E, O)) {
|
|
11086
|
-
const R =
|
|
11091
|
+
const R = v - O - 1;
|
|
11087
11092
|
x.push(`${E} (${R} logs pending)`);
|
|
11088
11093
|
}
|
|
11089
11094
|
p.warn(
|
|
11090
|
-
`waitForProcessing timeout after ${
|
|
11095
|
+
`waitForProcessing timeout after ${m}ms. Lagging processors: ${x.join(
|
|
11091
11096
|
", "
|
|
11092
11097
|
)}`
|
|
11093
11098
|
);
|
|
@@ -11366,15 +11371,15 @@ function gc({
|
|
|
11366
11371
|
const { text: a, context: c } = N(e, []), l = A(eo, { llm: o, ...i }), u = I(eo, l.onProgress, l);
|
|
11367
11372
|
u.start(), u.emit({ event: k.input, value: a });
|
|
11368
11373
|
const p = l.now ?? /* @__PURE__ */ new Date(), d = u.batch();
|
|
11369
|
-
let
|
|
11374
|
+
let h, y = 0, b = 0, f = r;
|
|
11370
11375
|
const g = [];
|
|
11371
|
-
let
|
|
11372
|
-
const
|
|
11373
|
-
if (!
|
|
11374
|
-
|
|
11376
|
+
let m = !0, w;
|
|
11377
|
+
const S = async () => {
|
|
11378
|
+
if (!m) return;
|
|
11379
|
+
w || (w = await q(l, {
|
|
11375
11380
|
tolerance: J(Wv)
|
|
11376
11381
|
}));
|
|
11377
|
-
const { tolerance: P } =
|
|
11382
|
+
const { tolerance: P } = w;
|
|
11378
11383
|
try {
|
|
11379
11384
|
u.emit({
|
|
11380
11385
|
event: k.step,
|
|
@@ -11420,29 +11425,29 @@ function gc({
|
|
|
11420
11425
|
metric: ge.tickDuration,
|
|
11421
11426
|
value: Date.now() - p.getTime(),
|
|
11422
11427
|
tickNumber: y + 1
|
|
11423
|
-
}),
|
|
11428
|
+
}), b = 0, y += 1, d(1), m && (h = setTimeout(S, j));
|
|
11424
11429
|
} catch (x) {
|
|
11425
|
-
if (ne(`Error in setInterval step: ${x.message}`),
|
|
11430
|
+
if (ne(`Error in setInterval step: ${x.message}`), b += 1, u.emit({
|
|
11426
11431
|
event: k.step,
|
|
11427
11432
|
stepName: "tick-error",
|
|
11428
11433
|
tickNumber: y + 1,
|
|
11429
11434
|
error: x.message,
|
|
11430
|
-
consecutiveErrors:
|
|
11435
|
+
consecutiveErrors: b
|
|
11431
11436
|
}), s && f && await s({
|
|
11432
11437
|
timingString: "error - using fallback",
|
|
11433
11438
|
data: f,
|
|
11434
11439
|
nextDate: new Date(Date.now() + 1e3),
|
|
11435
11440
|
// 1 second fallback
|
|
11436
11441
|
error: x.message
|
|
11437
|
-
}), y += 1, d(1),
|
|
11438
|
-
|
|
11442
|
+
}), y += 1, d(1), b >= P) {
|
|
11443
|
+
m = !1, clearTimeout(h), u.error(x);
|
|
11439
11444
|
return;
|
|
11440
11445
|
}
|
|
11441
|
-
|
|
11446
|
+
m && (h = setTimeout(S, 1e3));
|
|
11442
11447
|
}
|
|
11443
11448
|
};
|
|
11444
|
-
return
|
|
11445
|
-
|
|
11449
|
+
return h = setTimeout(S, 0), () => {
|
|
11450
|
+
m = !1, clearTimeout(h), u.complete({ outcome: T.success, ticks: y });
|
|
11446
11451
|
};
|
|
11447
11452
|
}
|
|
11448
11453
|
gc.knownTexts = [];
|
|
@@ -11513,12 +11518,12 @@ async function Gv(e) {
|
|
|
11513
11518
|
console.error(`[verblets:embed] Loading pipeline model "${t}"…`);
|
|
11514
11519
|
const a = await Xc("feature-extraction", t, { dtype: n });
|
|
11515
11520
|
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
|
|
11521
|
+
const { batchSize: p = o, abortSignal: d } = u, h = dn(l, p), y = [];
|
|
11522
|
+
for (const b of h) {
|
|
11518
11523
|
d?.throwIfAborted();
|
|
11519
|
-
const f = await a(
|
|
11520
|
-
for (let
|
|
11521
|
-
y.push(new Float32Array(f.data.slice(
|
|
11524
|
+
const f = await a(b, { pooling: r, normalize: s }), g = f.dims.at(-1);
|
|
11525
|
+
for (let m = 0; m < b.length; m++)
|
|
11526
|
+
y.push(new Float32Array(f.data.slice(m * g, (m + 1) * g)));
|
|
11522
11527
|
}
|
|
11523
11528
|
return y;
|
|
11524
11529
|
}, embedImages: void 0, dimensions: e.dimensions };
|
|
@@ -11532,21 +11537,21 @@ async function Yv(e) {
|
|
|
11532
11537
|
Hc.from_pretrained(t),
|
|
11533
11538
|
Qc.from_pretrained(t, { dtype: n })
|
|
11534
11539
|
]);
|
|
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(
|
|
11540
|
+
return console.error(`[verblets:embed] CLIP model "${t}" ready (${Date.now() - o}ms)`), { embedTexts: async (d, h = {}) => {
|
|
11541
|
+
const { batchSize: y = r, abortSignal: b } = h, f = dn(d, y), g = [];
|
|
11542
|
+
for (const m of f) {
|
|
11543
|
+
b?.throwIfAborted();
|
|
11544
|
+
const w = i(m, { padding: !0, truncation: !0 }), v = (await a(w)).text_embeds, P = v.dims[1];
|
|
11545
|
+
for (let x = 0; x < m.length; x++)
|
|
11546
|
+
g.push(no(new Float32Array(v.data.slice(x * P, (x + 1) * P))));
|
|
11542
11547
|
}
|
|
11543
11548
|
return g;
|
|
11544
|
-
}, embedImages: async (d,
|
|
11545
|
-
const { batchSize: y = s, abortSignal:
|
|
11546
|
-
for (const
|
|
11547
|
-
|
|
11548
|
-
const
|
|
11549
|
-
for (let E = 0; E <
|
|
11549
|
+
}, embedImages: async (d, h = {}) => {
|
|
11550
|
+
const { batchSize: y = s, abortSignal: b } = h, f = dn(d, y), g = [];
|
|
11551
|
+
for (const m of f) {
|
|
11552
|
+
b?.throwIfAborted();
|
|
11553
|
+
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];
|
|
11554
|
+
for (let E = 0; E < m.length; E++)
|
|
11550
11555
|
g.push(no(new Float32Array(P.data.slice(E * x, (E + 1) * x))));
|
|
11551
11556
|
}
|
|
11552
11557
|
return g;
|
|
@@ -11717,8 +11722,8 @@ function Xv(e, t, n) {
|
|
|
11717
11722
|
if (o && i + u > n && c(), u > n) {
|
|
11718
11723
|
const p = l.split(new RegExp("(?<=[.!?])\\s+"));
|
|
11719
11724
|
for (const d of p) {
|
|
11720
|
-
const
|
|
11721
|
-
o && i +
|
|
11725
|
+
const h = or(d).length;
|
|
11726
|
+
o && i + h > n && c(), o += (o ? " " : "") + d, i += h;
|
|
11722
11727
|
}
|
|
11723
11728
|
} else
|
|
11724
11729
|
o += (o ? `
|
|
@@ -11942,8 +11947,8 @@ function aS(e, t, n = {}) {
|
|
|
11942
11947
|
i.push(u);
|
|
11943
11948
|
continue;
|
|
11944
11949
|
}
|
|
11945
|
-
const d = Math.max(0, p - r),
|
|
11946
|
-
o.push({ lo: d, hi:
|
|
11950
|
+
const d = Math.max(0, p - r), h = Math.min(t.length - 1, p + r);
|
|
11951
|
+
o.push({ lo: d, hi: h, score: u.score ?? 0 });
|
|
11947
11952
|
}
|
|
11948
11953
|
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
11954
|
for (const u of i)
|
|
@@ -12118,24 +12123,24 @@ function TS(e, { cwd: t, timeout: n, abortSignal: r }) {
|
|
|
12118
12123
|
env: PS()
|
|
12119
12124
|
}), l = [], u = [];
|
|
12120
12125
|
let p = !1;
|
|
12121
|
-
c.stdout.on("data", (
|
|
12126
|
+
c.stdout.on("data", (h) => l.push(h)), c.stderr.on("data", (h) => u.push(h));
|
|
12122
12127
|
const d = n ? setTimeout(() => {
|
|
12123
12128
|
c.kill("SIGTERM"), p || (p = !0, o(new Error(`Agent timed out after ${n}ms`)));
|
|
12124
12129
|
}, n) : void 0;
|
|
12125
|
-
if (c.on("close", (
|
|
12130
|
+
if (c.on("close", (h) => {
|
|
12126
12131
|
if (d && clearTimeout(d), p) return;
|
|
12127
12132
|
p = !0;
|
|
12128
|
-
const y = Buffer.concat(l).toString(),
|
|
12129
|
-
if (
|
|
12130
|
-
const f =
|
|
12131
|
-
o(new Error(`Agent exited with code ${
|
|
12133
|
+
const y = Buffer.concat(l).toString(), b = Buffer.concat(u).toString();
|
|
12134
|
+
if (h !== 0 && !y.trim()) {
|
|
12135
|
+
const f = b?.trim() || `exit code ${h}`;
|
|
12136
|
+
o(new Error(`Agent exited with code ${h}: ${f}`));
|
|
12132
12137
|
} else
|
|
12133
12138
|
s(y);
|
|
12134
12139
|
}), r) {
|
|
12135
|
-
const
|
|
12140
|
+
const h = () => {
|
|
12136
12141
|
c.kill("SIGTERM"), p || (p = !0, o(new Error("Agent execution aborted")));
|
|
12137
12142
|
};
|
|
12138
|
-
r.aborted ? (c.kill("SIGTERM"), p = !0, o(new Error("Agent execution aborted"))) : (r.addEventListener("abort",
|
|
12143
|
+
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
12144
|
}
|
|
12140
12145
|
});
|
|
12141
12146
|
}
|
|
@@ -12153,23 +12158,23 @@ async function ES(e, t, n = {}) {
|
|
|
12153
12158
|
const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
|
|
12154
12159
|
let d = 0;
|
|
12155
12160
|
try {
|
|
12156
|
-
for (const
|
|
12161
|
+
for (const h of p) {
|
|
12157
12162
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12158
|
-
const y =
|
|
12163
|
+
const y = h.map(async (b, f) => {
|
|
12159
12164
|
const g = d + f;
|
|
12160
12165
|
try {
|
|
12161
|
-
u[g] = await e(
|
|
12162
|
-
} catch (
|
|
12163
|
-
if (s === z.strict) throw
|
|
12164
|
-
u[g] =
|
|
12166
|
+
u[g] = await e(b, g);
|
|
12167
|
+
} catch (m) {
|
|
12168
|
+
if (s === z.strict) throw m;
|
|
12169
|
+
u[g] = b;
|
|
12165
12170
|
}
|
|
12166
12171
|
l(1);
|
|
12167
12172
|
});
|
|
12168
|
-
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y), d +=
|
|
12173
|
+
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y), d += h.length;
|
|
12169
12174
|
}
|
|
12170
12175
|
return c.complete({ outcome: T.success, totalItems: t.length }), u;
|
|
12171
|
-
} catch (
|
|
12172
|
-
throw c.error(
|
|
12176
|
+
} catch (h) {
|
|
12177
|
+
throw c.error(h), h;
|
|
12173
12178
|
}
|
|
12174
12179
|
}
|
|
12175
12180
|
async function IS(e, t, n = {}) {
|
|
@@ -12188,22 +12193,22 @@ async function IS(e, t, n = {}) {
|
|
|
12188
12193
|
try {
|
|
12189
12194
|
for (const y of p) {
|
|
12190
12195
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12191
|
-
const
|
|
12192
|
-
const
|
|
12196
|
+
const b = y.map(async (f, g) => {
|
|
12197
|
+
const m = d + g;
|
|
12193
12198
|
try {
|
|
12194
|
-
u[
|
|
12195
|
-
} catch (
|
|
12196
|
-
if (s === z.strict) throw
|
|
12197
|
-
u[
|
|
12199
|
+
u[m] = await e(f, m);
|
|
12200
|
+
} catch (w) {
|
|
12201
|
+
if (s === z.strict) throw w;
|
|
12202
|
+
u[m] = !1;
|
|
12198
12203
|
}
|
|
12199
12204
|
l(1);
|
|
12200
12205
|
});
|
|
12201
|
-
s === z.strict ? await Promise.all(
|
|
12206
|
+
s === z.strict ? await Promise.all(b) : await Promise.allSettled(b), d += y.length;
|
|
12202
12207
|
}
|
|
12203
|
-
const
|
|
12204
|
-
return c.complete({ outcome: T.success, totalItems: t.length, kept:
|
|
12205
|
-
} catch (
|
|
12206
|
-
throw c.error(
|
|
12208
|
+
const h = t.filter((y, b) => u[b]);
|
|
12209
|
+
return c.complete({ outcome: T.success, totalItems: t.length, kept: h.length }), h;
|
|
12210
|
+
} catch (h) {
|
|
12211
|
+
throw c.error(h), h;
|
|
12207
12212
|
}
|
|
12208
12213
|
}
|
|
12209
12214
|
async function kS(e, t, n = {}) {
|
|
@@ -12222,19 +12227,19 @@ async function kS(e, t, n = {}) {
|
|
|
12222
12227
|
try {
|
|
12223
12228
|
for (const d of u) {
|
|
12224
12229
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12225
|
-
const
|
|
12230
|
+
const h = new Array(d.length), y = d.map(async (f, g) => {
|
|
12226
12231
|
try {
|
|
12227
|
-
|
|
12228
|
-
} catch (
|
|
12229
|
-
if (s === z.strict) throw
|
|
12230
|
-
|
|
12232
|
+
h[g] = { item: f, matched: await e(f, p + g) };
|
|
12233
|
+
} catch (m) {
|
|
12234
|
+
if (s === z.strict) throw m;
|
|
12235
|
+
h[g] = { item: f, matched: !1 };
|
|
12231
12236
|
}
|
|
12232
12237
|
l(1);
|
|
12233
12238
|
});
|
|
12234
12239
|
s === z.strict ? await Promise.all(y) : await Promise.allSettled(y);
|
|
12235
|
-
const
|
|
12236
|
-
if (
|
|
12237
|
-
return c.complete({ outcome: T.success, found: !0 }),
|
|
12240
|
+
const b = h.find((f) => f.matched);
|
|
12241
|
+
if (b)
|
|
12242
|
+
return c.complete({ outcome: T.success, found: !0 }), b.item;
|
|
12238
12243
|
p += d.length;
|
|
12239
12244
|
}
|
|
12240
12245
|
c.complete({ outcome: T.success, found: !1 });
|
|
@@ -12274,29 +12279,29 @@ async function OS(e, t, n = {}) {
|
|
|
12274
12279
|
try {
|
|
12275
12280
|
for (const y of p) {
|
|
12276
12281
|
if (o?.aborted) throw o.reason ?? new Error("Aborted");
|
|
12277
|
-
const
|
|
12278
|
-
const
|
|
12282
|
+
const b = y.map(async (f, g) => {
|
|
12283
|
+
const m = d + g;
|
|
12279
12284
|
try {
|
|
12280
|
-
u[
|
|
12281
|
-
} catch (
|
|
12282
|
-
if (s === z.strict) throw
|
|
12283
|
-
u[
|
|
12285
|
+
u[m] = await e(f, m);
|
|
12286
|
+
} catch (w) {
|
|
12287
|
+
if (s === z.strict) throw w;
|
|
12288
|
+
u[m] = "other";
|
|
12284
12289
|
}
|
|
12285
12290
|
l(1);
|
|
12286
12291
|
});
|
|
12287
|
-
s === z.strict ? await Promise.all(
|
|
12292
|
+
s === z.strict ? await Promise.all(b) : await Promise.allSettled(b), d += y.length;
|
|
12288
12293
|
}
|
|
12289
|
-
const
|
|
12290
|
-
return t.forEach((y,
|
|
12291
|
-
const f = String(u[
|
|
12292
|
-
|
|
12294
|
+
const h = {};
|
|
12295
|
+
return t.forEach((y, b) => {
|
|
12296
|
+
const f = String(u[b] ?? "other");
|
|
12297
|
+
h[f] || (h[f] = []), h[f].push(y);
|
|
12293
12298
|
}), c.complete({
|
|
12294
12299
|
outcome: T.success,
|
|
12295
12300
|
totalItems: t.length,
|
|
12296
|
-
groupCount: Object.keys(
|
|
12297
|
-
}),
|
|
12298
|
-
} catch (
|
|
12299
|
-
throw c.error(
|
|
12301
|
+
groupCount: Object.keys(h).length
|
|
12302
|
+
}), h;
|
|
12303
|
+
} catch (h) {
|
|
12304
|
+
throw c.error(h), h;
|
|
12300
12305
|
}
|
|
12301
12306
|
}
|
|
12302
12307
|
async function _S(e, t, n = {}) {
|
|
@@ -12398,8 +12403,8 @@ function MS(e, t, n = {}) {
|
|
|
12398
12403
|
}, t));
|
|
12399
12404
|
}
|
|
12400
12405
|
let l, u;
|
|
12401
|
-
const p = new Promise((y,
|
|
12402
|
-
l = y, u =
|
|
12406
|
+
const p = new Promise((y, b) => {
|
|
12407
|
+
l = y, u = b;
|
|
12403
12408
|
}), d = () => {
|
|
12404
12409
|
if (!i) {
|
|
12405
12410
|
a();
|
|
@@ -12407,8 +12412,8 @@ function MS(e, t, n = {}) {
|
|
|
12407
12412
|
r && r(void 0, y), u(y);
|
|
12408
12413
|
}
|
|
12409
12414
|
};
|
|
12410
|
-
return s?.aborted ? (d(), p) : (s?.addEventListener("abort", d, { once: !0 }), c(), e((y,
|
|
12411
|
-
r && r(y,
|
|
12415
|
+
return s?.aborted ? (d(), p) : (s?.addEventListener("abort", d, { once: !0 }), c(), e((y, b) => {
|
|
12416
|
+
r && r(y, b), c();
|
|
12412
12417
|
}).then((y) => {
|
|
12413
12418
|
i || (a(), l(y));
|
|
12414
12419
|
}).catch((y) => {
|
|
@@ -12630,17 +12635,17 @@ const US = {
|
|
|
12630
12635
|
const s = async (o, i = {}) => {
|
|
12631
12636
|
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
12637
|
p.start(), p.emit({ event: k.step, stepName: "analyzing" });
|
|
12633
|
-
const d = r(o, c),
|
|
12638
|
+
const d = r(o, c), h = a ? u + ai : u, y = a ? [ci, ...d] : d, b = await M(
|
|
12634
12639
|
() => _(y.join(`
|
|
12635
12640
|
|
|
12636
12641
|
`), {
|
|
12637
12642
|
...c,
|
|
12638
|
-
systemPrompt:
|
|
12643
|
+
systemPrompt: h,
|
|
12639
12644
|
responseFormat: C(l.name, l.schema)
|
|
12640
12645
|
}),
|
|
12641
12646
|
{ label: e, config: c }
|
|
12642
12647
|
);
|
|
12643
|
-
return ne(`${e}: complete`), p.complete({ outcome: T.success }),
|
|
12648
|
+
return ne(`${e}: complete`), p.complete({ outcome: T.success }), b;
|
|
12644
12649
|
};
|
|
12645
12650
|
return s.with = (o = {}) => (i) => s(i, o), s;
|
|
12646
12651
|
}, 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 +12851,11 @@ async function wx({ sourceTexts: e, schema: t }, n = {}) {
|
|
|
12846
12851
|
const l = s.batch(e.length), p = (await Q(
|
|
12847
12852
|
c,
|
|
12848
12853
|
async (d) => {
|
|
12849
|
-
const
|
|
12854
|
+
const h = await bx(d, t, {
|
|
12850
12855
|
...r,
|
|
12851
12856
|
onProgress: L(r.onProgress, "batch")
|
|
12852
12857
|
});
|
|
12853
|
-
return l(d.length),
|
|
12858
|
+
return l(d.length), h;
|
|
12854
12859
|
},
|
|
12855
12860
|
{ maxParallel: o }
|
|
12856
12861
|
)).flat();
|
|
@@ -12971,25 +12976,25 @@ async function Ox(e, t) {
|
|
|
12971
12976
|
async function _x({ fragmentSets: e, schema: t }, n = {}) {
|
|
12972
12977
|
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
12978
|
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
|
|
12979
|
+
for (const m of g.fragments) {
|
|
12980
|
+
const w = !!m.image, S = w ? `img:${m.image}` : `txt:${m.text}`;
|
|
12981
|
+
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));
|
|
12982
|
+
const v = m.sourceIds?.[0] ?? g.fragmentSetId;
|
|
12983
|
+
u.has(v) || u.set(v, /* @__PURE__ */ new Map());
|
|
12984
|
+
const P = u.get(v);
|
|
12985
|
+
P.has(m.projectionName) || P.set(m.projectionName, []), P.get(m.projectionName).push(S);
|
|
12986
|
+
}
|
|
12987
|
+
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 = [];
|
|
12988
|
+
for (const [g, m] of u) {
|
|
12989
|
+
const w = {}, S = [];
|
|
12990
|
+
for (const [P, x] of m) {
|
|
12991
|
+
const E = x.map(h), O = mn(E);
|
|
12992
|
+
O && (w[P] = ft(O), S.push(...E));
|
|
12993
|
+
}
|
|
12994
|
+
const v = S.length > 0 ? ft(mn(S)) : void 0;
|
|
12995
|
+
y.push({ stateId: g, vectorsByProjectionName: w, baseVector: v });
|
|
12996
|
+
}
|
|
12997
|
+
const b = await Ox(t, o), f = b !== t._poles ? { ...t, _poles: b } : t;
|
|
12993
12998
|
return { states: y, schema: f };
|
|
12994
12999
|
}
|
|
12995
13000
|
function Cx({ states: e, editsByProjectionName: t }) {
|
|
@@ -13033,17 +13038,17 @@ function Lc(e, t, n, r) {
|
|
|
13033
13038
|
continue;
|
|
13034
13039
|
}
|
|
13035
13040
|
let u = 0, p = 0, d = 0;
|
|
13036
|
-
for (const [
|
|
13037
|
-
const
|
|
13038
|
-
if (!
|
|
13039
|
-
const
|
|
13041
|
+
for (const [m, w] of Object.entries(c.projectionWeights)) {
|
|
13042
|
+
const S = e.vectorsByProjectionName[m];
|
|
13043
|
+
if (!S) continue;
|
|
13044
|
+
const v = n[m] ?? 1, P = w * v, x = Ix(S, l.low, l.high);
|
|
13040
13045
|
u += x * P, p += P, d += 1;
|
|
13041
13046
|
}
|
|
13042
13047
|
if (p === 0) {
|
|
13043
13048
|
s[c.propertyName] = void 0, o[c.propertyName] = { value: void 0, confidence: 0 };
|
|
13044
13049
|
continue;
|
|
13045
13050
|
}
|
|
13046
|
-
const
|
|
13051
|
+
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
13052
|
s[c.propertyName] = y, o[c.propertyName] = { value: y, confidence: g };
|
|
13048
13053
|
}
|
|
13049
13054
|
return { values: s, details: o };
|
|
@@ -13072,20 +13077,20 @@ async function Lx({ leftStates: e, rightStates: t, intent: n }, r = {}) {
|
|
|
13072
13077
|
const l = Object.entries(s).filter(([p]) => !a.has(p)).filter(([, p]) => p !== 0), u = [];
|
|
13073
13078
|
for (const p of e)
|
|
13074
13079
|
for (const d of t) {
|
|
13075
|
-
let
|
|
13080
|
+
let h = 0, y = 0;
|
|
13076
13081
|
for (const [f, g] of l) {
|
|
13077
|
-
const
|
|
13078
|
-
if (
|
|
13079
|
-
let
|
|
13082
|
+
const m = p.vectorsByProjectionName[f], w = d.vectorsByProjectionName[f];
|
|
13083
|
+
if (m && w) {
|
|
13084
|
+
let S = Pe(m, w);
|
|
13080
13085
|
if (c) {
|
|
13081
|
-
const
|
|
13082
|
-
|
|
13086
|
+
const v = Pe(c, m), P = Pe(c, w);
|
|
13087
|
+
S = S * 0.6 + (v + P) * 0.2;
|
|
13083
13088
|
}
|
|
13084
|
-
|
|
13089
|
+
h += S * g, y += g;
|
|
13085
13090
|
}
|
|
13086
13091
|
}
|
|
13087
|
-
const
|
|
13088
|
-
u.push({ leftStateId: p.stateId, rightStateId: d.stateId, score:
|
|
13092
|
+
const b = y > 0 ? h / y : 0;
|
|
13093
|
+
u.push({ leftStateId: p.stateId, rightStateId: d.stateId, score: b });
|
|
13089
13094
|
}
|
|
13090
13095
|
return u;
|
|
13091
13096
|
}
|
|
@@ -13167,22 +13172,28 @@ function zx(e = {}) {
|
|
|
13167
13172
|
embedModels: a,
|
|
13168
13173
|
embedRules: c,
|
|
13169
13174
|
policy: l,
|
|
13170
|
-
runtimeProvider: u
|
|
13171
|
-
|
|
13172
|
-
|
|
13175
|
+
runtimeProvider: u,
|
|
13176
|
+
llm: p
|
|
13177
|
+
} = e, d = yn();
|
|
13178
|
+
if (d.length > 0)
|
|
13173
13179
|
throw new Error(`Config validation failed:
|
|
13174
|
-
${
|
|
13180
|
+
${d.join(`
|
|
13175
13181
|
`)}`);
|
|
13176
13182
|
u && xo(u);
|
|
13177
|
-
const
|
|
13178
|
-
|
|
13179
|
-
const
|
|
13180
|
-
o &&
|
|
13181
|
-
let
|
|
13182
|
-
|
|
13183
|
-
const
|
|
13184
|
-
|
|
13185
|
-
const
|
|
13183
|
+
const h = t ?? (!!(a || c) || !1);
|
|
13184
|
+
h && Zn(!0), n && ov(!0), r && qx(!0);
|
|
13185
|
+
const y = new Sn();
|
|
13186
|
+
o && y.addModels(o), i && y.setRules(i), l && xp(l);
|
|
13187
|
+
let b;
|
|
13188
|
+
h && (b = new Qn(), a && b.addModels(a), c && b.setRules(c));
|
|
13189
|
+
const f = s ? () => Promise.resolve(s) : void 0, g = Ni();
|
|
13190
|
+
g.setApplication(Ri()), g.setProviders(Mi());
|
|
13191
|
+
const m = {
|
|
13192
|
+
modelService: y,
|
|
13193
|
+
embeddingService: b,
|
|
13194
|
+
getRedis: f,
|
|
13195
|
+
...p !== void 0 ? { llm: p } : {}
|
|
13196
|
+
}, w = /* @__PURE__ */ new Set([
|
|
13186
13197
|
"init",
|
|
13187
13198
|
"config",
|
|
13188
13199
|
"services",
|
|
@@ -13206,23 +13217,23 @@ function zx(e = {}) {
|
|
|
13206
13217
|
"eventToTrace",
|
|
13207
13218
|
"scopePhase",
|
|
13208
13219
|
"nameStep"
|
|
13209
|
-
]),
|
|
13210
|
-
for (const [
|
|
13211
|
-
if (!
|
|
13212
|
-
if (
|
|
13213
|
-
v[
|
|
13214
|
-
Object.entries(
|
|
13220
|
+
]), S = /* @__PURE__ */ new Set(["embedObject"]), v = {};
|
|
13221
|
+
for (const [P, x] of Object.entries(rl))
|
|
13222
|
+
if (!w.has(P)) {
|
|
13223
|
+
if (S.has(P) && typeof x == "object" && x !== null) {
|
|
13224
|
+
v[P] = Object.fromEntries(
|
|
13225
|
+
Object.entries(x).map(([E, O]) => [E, hn(m, O)])
|
|
13215
13226
|
);
|
|
13216
13227
|
continue;
|
|
13217
13228
|
}
|
|
13218
|
-
v[
|
|
13229
|
+
v[P] = hn(m, x);
|
|
13219
13230
|
}
|
|
13220
13231
|
return {
|
|
13221
13232
|
...v,
|
|
13222
|
-
config:
|
|
13223
|
-
modelService:
|
|
13224
|
-
embeddingService:
|
|
13225
|
-
context:
|
|
13233
|
+
config: m,
|
|
13234
|
+
modelService: y,
|
|
13235
|
+
embeddingService: b,
|
|
13236
|
+
context: g
|
|
13226
13237
|
};
|
|
13227
13238
|
}
|
|
13228
13239
|
const Ux = {
|