mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:00:54 +00:00
perf: avoid sort-for-single selection
This commit is contained in:
@@ -36,9 +36,14 @@ export function selectPendingApprovalRequest(params: {
|
||||
}
|
||||
|
||||
if (normalizeLowercaseStringOrEmpty(params.requested) === "latest") {
|
||||
return {
|
||||
pending: [...params.pending].toSorted((a, b) => (b.ts ?? 0) - (a.ts ?? 0))[0],
|
||||
};
|
||||
let latest = params.pending[0];
|
||||
for (let index = 1; index < params.pending.length; index += 1) {
|
||||
const pending = params.pending[index];
|
||||
if ((pending.ts ?? 0) > (latest.ts ?? 0)) {
|
||||
latest = pending;
|
||||
}
|
||||
}
|
||||
return { pending: latest };
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -677,6 +677,22 @@ function isRoutingSummary(summary: SectionSummary): boolean {
|
||||
return summary.scores.routing > 0 || REM_ROUTING_SIGNAL_RE.test(summary.text);
|
||||
}
|
||||
|
||||
function findStrongestSummary(
|
||||
summaries: SectionSummary[],
|
||||
predicate: (summary: SectionSummary) => boolean,
|
||||
): SectionSummary | undefined {
|
||||
let strongest: SectionSummary | undefined;
|
||||
for (const summary of summaries) {
|
||||
if (!predicate(summary)) {
|
||||
continue;
|
||||
}
|
||||
if (!strongest || summary.scores.overall > strongest.scores.overall) {
|
||||
strongest = summary;
|
||||
}
|
||||
}
|
||||
return strongest;
|
||||
}
|
||||
|
||||
function previewGroundedRemForFile(params: {
|
||||
relPath: string;
|
||||
content: string;
|
||||
@@ -847,15 +863,15 @@ function previewGroundedRemForFile(params: {
|
||||
(sum, { section, snippets }) => sum + scoreSection(section, snippets).tasks,
|
||||
0,
|
||||
);
|
||||
const strongestRoutingSummary = summaries
|
||||
.filter((summary) => isRoutingSummary(summary))
|
||||
.toSorted((left, right) => right.scores.overall - left.scores.overall)[0];
|
||||
const strongestIncidentSummary = summaries
|
||||
.filter((summary) => summary.scores.incident > 0)
|
||||
.toSorted((left, right) => right.scores.overall - left.scores.overall)[0];
|
||||
const strongestExternalizationSummary = summaries
|
||||
.filter((summary) => summary.scores.externalization > 0)
|
||||
.toSorted((left, right) => right.scores.overall - left.scores.overall)[0];
|
||||
const strongestRoutingSummary = findStrongestSummary(summaries, isRoutingSummary);
|
||||
const strongestIncidentSummary = findStrongestSummary(
|
||||
summaries,
|
||||
(summary) => summary.scores.incident > 0,
|
||||
);
|
||||
const strongestExternalizationSummary = findStrongestSummary(
|
||||
summaries,
|
||||
(summary) => summary.scores.externalization > 0,
|
||||
);
|
||||
|
||||
if (facts.length === 0 && monitoringSignal >= 3) {
|
||||
addReflection(
|
||||
|
||||
@@ -207,12 +207,16 @@ async function mapWithConcurrency<T, U>(
|
||||
}
|
||||
|
||||
function extractTranscript(result: QaSuiteResult) {
|
||||
const details = result.scenarios.flatMap((scenario) =>
|
||||
scenario.steps
|
||||
.map((step) => step.details)
|
||||
.filter((detail): detail is string => Boolean(detail)),
|
||||
);
|
||||
return details.toSorted((left, right) => right.length - left.length)[0] ?? result.report;
|
||||
let longestDetail: string | undefined;
|
||||
for (const scenario of result.scenarios) {
|
||||
for (const step of scenario.steps) {
|
||||
const detail = step.details;
|
||||
if (detail && (!longestDetail || detail.length > longestDetail.length)) {
|
||||
longestDetail = detail;
|
||||
}
|
||||
}
|
||||
}
|
||||
return longestDetail ?? result.report;
|
||||
}
|
||||
|
||||
function collectTranscriptStats(transcript: string) {
|
||||
|
||||
Reference in New Issue
Block a user