Repository navigation
Expand file tree
/
Copy pathproblemDraftSubmission.ts
More file actions
102 lines (101 loc) · 5.11 KB
/
Copy pathproblemDraftSubmission.ts
File metadata and controls
102 lines (101 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { canonicalMathJson, mathDigest } from '../../src/math/mathRuntimeIo';
import {
currentResearchModulePlan,
defaultResearchModulePlan,
type ResearchModulePlan,
} from '../../src/solver/modules/policy';
import type { ProblemDraftValue } from './problemDraftTypes';
import type { WebFormalization } from './formalizationTypes';
import type { WebRun } from './shared';
import type { ResearchReleaseRef } from './researchAssetTypes';
const equal = (left: unknown, right: unknown) => canonicalMathJson(left) === canonicalMathJson(right);
export function matchesProblemFormalization(value: ProblemDraftValue, item: WebFormalization): boolean {
if (value.mode !== 'natural') return false;
const { settings } = value;
return (
item.original === value.text &&
item.workflow === 'solve' &&
item.environment === settings.environment &&
item.providerId === settings.providerId &&
item.model === settings.model.trim() &&
item.effort === settings.effort &&
(item.researchEffort ?? item.effort) === (settings.researchEffort ?? settings.effort) &&
Boolean(item.humanReview) === (settings.participation === 'guided') &&
item.maxRunSeconds === settings.maxRunSeconds &&
item.maxTotalTokens === settings.maxTotalTokens &&
equal(item.research, settings.research)
);
}
export function matchesProblemRun(value: ProblemDraftValue, run: WebRun): boolean {
if (value.mode !== 'lean') return false;
const { draft } = value,
config = run.researchConfiguration;
// The run endpoint trims ordinary Lean sources and instructions; keep the original draft unchanged.
const submittedSource = run.formalization ? draft.source : draft.source.trim();
if (
run.source !== submittedSource ||
run.task !== draft.task.trim() ||
run.providerId !== draft.providerId ||
run.model !== draft.model.trim() ||
run.environment !== draft.environment ||
run.effort !== draft.effort ||
run.coordination !== draft.coordination ||
(run.researchMode ?? 'legacy') !== (draft.researchMode ?? 'legacy') ||
(run.researchMode === 'skill' && (run.skillLoading ?? 'native') !== (draft.skillLoading ?? 'native')) ||
run.nativeTeamCapacity !== draft.nativeTeamCapacity ||
!equal(run.nativeTeamPreferredProfiles ?? [], [...new Set(draft.nativeTeamPreferredProfiles ?? [])].sort()) ||
run.maxTurns !== Number(draft.maxTurns) ||
run.maxRunSeconds !== Number(draft.maxRunSeconds) ||
run.workers !== Number(draft.workers) ||
(run.maxTotalTokens ?? 0) !== Math.round(Number(draft.maxTotalTokens ?? '') * 10_000) ||
Boolean(run.planApproval) !==
Boolean(
draft.planApproval &&
(draft.nativeTeamCapacity || (draft.coordination === 'cooperative' && Number(draft.workers) >= 2)),
) ||
(draft.knowledgeDigest !== undefined && (run.knowledgeDigest ?? null) !== draft.knowledgeDigest)
)
return false;
const refs = [
...(config?.agent ? [config.agent.ref] : []),
...(config?.skills.map(item => item.ref) ?? []),
...(config?.libraries.map(item => item.ref) ?? []),
];
const sameRef = (a: ResearchReleaseRef, b: ResearchReleaseRef) =>
a.assetId === b.assetId && a.version === b.version && (!a.digest || a.digest === b.digest);
const selected = [...(value.libraries ?? [])];
if (run.nativeTeamCapacity && config?.personalExpertSelection) {
const pick = config.personalExpertSelection;
const explicit = [...(pick.agent ? [pick.agent] : []), ...(pick.skills ?? []), ...(pick.libraries ?? [])];
return (
selected.every(ref => explicit.some(actual => sameRef(ref, actual))) &&
explicit.every(actual => selected.some(ref => sameRef(ref, actual))) &&
!run.modulePlan &&
!draft.modulePlan
);
}
if (selected.some(ref => !refs.some(actual => sameRef(ref, actual)))) return false;
// Frozen selections also contain Agent/Skill dependencies. Only those dependencies may be extra.
for (let index = 0; index < selected.length; index++) {
const ref = selected[index],
agent = config?.agent && sameRef(ref, config.agent.ref) ? config.agent.content : undefined;
const skill = config?.skills.find(item => sameRef(ref, item.ref))?.content;
for (const dependency of [...(agent?.skills ?? []), ...(agent?.libraries ?? []), ...(skill?.dependencies ?? [])]) {
if (!selected.some(item => sameRef(dependency, item))) selected.push(dependency);
}
}
if (refs.some(ref => !selected.some(item => sameRef(item, ref)))) return false;
const expectedPlan = draft.modulePlan ?? config?.agent?.content.modulePlan ?? defaultResearchModulePlan();
const actualPlan = run.modulePlan ?? defaultResearchModulePlan();
const matchesPlan = (plan: ResearchModulePlan) =>
equal(expectedPlan, plan) || (plan.scheduler === 'plan' && equal(currentResearchModulePlan(expectedPlan), plan));
if (matchesPlan(actualPlan)) return true;
const skillIds = new Set(
config?.skills.flatMap(item =>
item.content.slots.map(
slot => `skill_${mathDigest(`${item.ref.assetId}\0${item.ref.version}\0${slot}`).slice(0, 24)}`,
),
),
);
return matchesPlan({ ...actualPlan, custom: actualPlan.custom.filter(item => !skillIds.has(item.id)) });
}