Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions apps/web/client/researchLibraryTrial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function LibraryTrial({ release, context }: { release: ResearchAssetRelea
: <><CheckedMathExamples release={release} /><a class="button" href={`login.html?${signIn}`}>{tx('登录后在研究目标中试用', 'Sign in to try this on a research goal')}</a></>;
}
function TrialForm({ release, owner }: { release: ResearchAssetRelease; owner: string }) {
const parameters = new URLSearchParams(location.search), linkedRun = parameters.get('run'), linkedTask = parameters.get('task');
const parameters = new URLSearchParams(location.search), linkedRun = parameters.get('run'), linkedTask = parameters.get('task'), linkedProject = parameters.get('project');
const [trialId, setTrialId] = useState(parameters.get('trial') ?? '');
const [open, setOpen] = useState(Boolean(linkedRun || trialId)), [selected, setSelected] = useState('');
const [prepared, setPrepared] = useState<{ input: string; item: ResearchLibraryTrial }>(), [confirmed, setConfirmed] = useState('');
Expand All @@ -41,7 +41,7 @@ function TrialForm({ release, owner }: { release: ResearchAssetRelease; owner: s
} else setPrepared(previous => previous?.item.id === recovery.id && !(previous.item.check && !recovery.check) ? { ...previous, item: recovery } : previous);
}, [recovery, matchingRecovery]);
const available = targets.data?.items ?? [], requested = available.find(item => item.ref.runId === linkedRun && (!linkedTask || item.ref.taskId === linkedTask)
&& (!parameters.get('project') || !item.ref.projectId || item.ref.projectId === parameters.get('project'))
&& (!linkedProject || item.ref.projectId === linkedProject)
&& (!parameters.get('taskVersion') || item.ref.taskVersion === parameters.get('taskVersion')) && (!parameters.get('commit') || item.ref.commit === parameters.get('commit')));
const target = selected ? available.find(item => targetKey(item) === selected) : linkedRun ? requested : available.find(item => item.compatible);
const editorReady = !trialId || prepared?.item.id === trialId || Boolean(saved.error) || Boolean(recovery && !matchingRecovery);
Expand All @@ -51,7 +51,7 @@ function TrialForm({ release, owner }: { release: ResearchAssetRelease; owner: s
: { declaration: release.mathematics!.declarations[0]?.name ?? '', proof: '', argumentNotes: '', missingPremises: '' });
const { declaration: name, proof, argumentNotes: argumentsNote, missingPremises: missing } = editor.value;
const declaration = release.mathematics!.declarations.find(item => item.name === name);
const input = JSON.stringify([target ? targetKey(target) : undefined, name, proof, argumentsNote, missing]);
const input = JSON.stringify([target ? targetKey(target) : undefined, name, proof.trim(), argumentsNote, missing]);
const draft = prepared?.input === input ? prepared.item : undefined;
const busy = prepare.busy || check.busy || draft?.status === 'checking';
const loadExample = (example: ResearchCheckedMathExample) => {
Expand All @@ -74,18 +74,17 @@ function TrialForm({ release, owner }: { release: ResearchAssetRelease; owner: s
{targets.data && !available.length && <p class="research-status">{tx('当前没有保存了定理源码的可试用任务。先打开一次研究;项目任务需要候选证明权限。', 'No eligible task with saved theorem source is available. Open a research run first; project tasks require proof submission permission.')}</p>}
{targets.data && Boolean(available.length) && <form class="research-form" onSubmit={event => {
event.preventDefault(); if (!target || !target.compatible || !declaration || !editor.ready) return;
const submitted = input;
void prepare.run<Item<ResearchLibraryTrial>>('POST', `${base}/library/${enc(release.assetId)}/releases/${enc(release.version)}/trials`, {
releaseDigest: release.digest, target: target.ref, declaration: name, proof, argumentNotes: argumentsNote, missingPremises: missing,
}, result => {
restored.current = result.item.id; setTrialId(result.item.id);
const next = new URL(location.href); next.searchParams.set('trial', result.item.id); history.replaceState(null, '', next);
setPrepared({ input: submitted, item: result.item }); setConfirmed(''); check.reset();
setPrepared({ input: draftInput(result.item), item: result.item }); setConfirmed(''); check.reset();
});
}}>
<label>{tx('研究 / 精确任务版本', 'Research / exact task version')}<select value={target ? targetKey(target) : ''} disabled={busy || !editorReady} onChange={event => { setSelected(event.currentTarget.value); setConfirmed(''); }}>
<option value="">{tx('选择一个当前目标', 'Choose a current goal')}</option>{available.map(item => <option key={targetKey(item)} value={targetKey(item)} disabled={!item.compatible}>
{item.runTitle} · {item.taskTitle} · {item.ref.taskVersion.slice(0, 10)} · {item.ref.commit.slice(0, 10)}{item.compatible ? '' : ` · ${tx('环境不同', 'Different environment')}`}</option>)}</select></label>
{item.projectTitle ?? tx('个人运行', 'Personal run')} · {item.runTitle} · {item.taskTitle} · {item.ref.taskVersion.slice(0, 10)} · {item.ref.commit.slice(0, 10)}{item.compatible ? '' : ` · ${tx('环境不同', 'Different environment')}`}</option>)}</select></label>
{linkedRun && !requested && !selected && <ErrorBox message={tx('入口对应的任务版本或源码提交已改变。请明确选择当前目标后重新准备。', 'The linked task version or source commit has changed. Select the current goal explicitly to prepare a new candidate.')} />}
{target && <section class="research-trial-target"><h4><Rich text={target.taskTitle} /></h4><pre class="research-block-code">{target.type}</pre>
{target.premises.length > 0 && <><h4>{tx('任务记录的前提', 'Recorded task premises')}</h4><ul>{target.premises.map((premise, index) => <li key={index}><Rich text={premise} /></li>)}</ul></>}
Expand Down
20 changes: 12 additions & 8 deletions apps/web/client/trajectoryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ type Item = { step: TrajectoryStep; key: string; index: number };
type Loaded = { status: 'loading' } | { status: 'ready'; revision: number; detail: TrajectoryVersionDetail } | { status: 'failed'; error: string };
/** Where the key for a question comes from; with none, the panel asks for one and keeps it on this page only. */
export type ExplainKey = { source: 'saved'; ending: string } | { source: 'server' } | { source: 'remembered' } | { source: 'none' };
export type ExplainRequest = { taskId: string; commit: string; taskVersion?: string; question: string; turns: WebExplainTurn[]; apiKey?: string };
export type ExplainRequest = { taskId: string; commit: string; taskVersion?: string; receiptId: string; checkAt: number; question: string; turns: WebExplainTurn[]; apiKey?: string };
/** What a reader may do with a run of their own: start a new run from a version, and ask why a version failed. */
export type OwnRunActions = {
allowed(run: WebRun): boolean;
start(run: WebRun, from: WebContinuation): void;
explain?: { key(run: WebRun): ExplainKey; ask(run: WebRun, request: ExplainRequest, signal: AbortSignal): Promise<WebExplainAnswer> };
};
/** One version's questions and answers, kept on the page; nothing is stored on the server. */
/** One check's questions and answers, kept on the page; nothing is stored on the server. */
type AskTurn = WebExplainTurn & { truncated?: boolean; usage?: WebExplainAnswer['usage'] };
type AskThread = { turns: AskTurn[]; draft: string; pending?: { question: string; controller: AbortController }; error?: string };
type Built = { key: string; steps: TrajectoryStep[]; keys: string[]; names: Map<string, string> };
Expand All @@ -113,7 +113,7 @@ type Ctx = { run: WebRun; state: RunState; names: Map<string, string>; tasks: Ma
type Content = { title: ComponentChildren; meta?: string[]; badge?: [string, Tone]; body?: ComponentChildren };

const shortName = (name: string) => name.split('.').at(-1) || name;
const detailKey = ({ version, check }: TrajectoryRef) => check?.taskVersion ? `${version.key}\u0000${check.taskVersion}` : version.key;
const detailKey = ({ version, check }: TrajectoryRef) => JSON.stringify([version.key, check?.taskVersion, check?.at, check?.receiptIds[0]]);
/** The Lean output of a version's check (`ids`, its receipts; none means all), failed receipts first, each output once. */
function checkEntries(detail: TrajectoryVersionDetail, ids: readonly string[]) {
const wanted = new Set(ids), checks = detail.checks.filter(check => !wanted.size || wanted.has(check.id))
Expand Down Expand Up @@ -966,7 +966,7 @@ export class TrajectoryView {
if (step.kind !== 'attempt' && step.kind !== 'proof') return [];
const version = step.ref?.version, saved = version?.source !== undefined, failed = Boolean(version) && step.outcome === 'failed';
return [saved && 'code', saved && step.kind === 'attempt' && step.previous?.version.source !== undefined && 'diff',
failed && 'feedback', failed && this.asks(run) && 'ask'].filter((mode): mode is Mode => Boolean(mode));
failed && 'feedback', failed && step.ref?.check?.receiptIds[0] && this.asks(run) && 'ask'].filter((mode): mode is Mode => Boolean(mode));
}
private asks(run: WebRun) { return Boolean(this.own?.explain && this.own.allowed(run)); }

Expand Down Expand Up @@ -1100,6 +1100,10 @@ export class TrajectoryView {
for (const old of versions.keys()) { if (versions.size <= limits.versions) break; versions.delete(old); }
const query = new URLSearchParams({ task: version.taskId, commit: version.commit });
if (check?.taskVersion) query.set('taskVersion', check.taskVersion);
if (check?.receiptIds[0]) {
query.set('receiptId', check.receiptIds[0]);
query.set('checkAt', String(check.at));
}
void this.api<{ version: TrajectoryVersionDetail }>(`/api/runs/${encodeURIComponent(ctx.run.id)}/trajectory/version?${query}`)
.then(({ version: detail }) => { versions.set(key, { status: 'ready', revision: version.revision, detail }); },
error => { versions.set(key, { status: 'failed', error: errorText(error) }); })
Expand Down Expand Up @@ -1291,7 +1295,7 @@ export class TrajectoryView {
}

/**
* Questions about a failed version, answered by the run's own model through its provider: each is a call the reader
* Questions about a failed check, answered by the run's own model through its provider: each is a call the reader
* pays for, outside the run's budget, and the run never sees it. The thread stays on this page until it is left;
* each question carries the last few answers with it.
*/
Expand Down Expand Up @@ -1330,8 +1334,8 @@ export class TrajectoryView {
</div>;
}
private async send(ctx: Ctx, { version, check }: TrajectoryRef, thread: AskThread, form: HTMLFormElement) {
const explain = this.own?.explain, question = thread.draft.trim(), run = ctx.run;
if (!explain || !question || thread.pending) return;
const explain = this.own?.explain, question = thread.draft.trim(), run = ctx.run, receiptId = check?.receiptIds[0];
if (!explain || !question || !check || !receiptId || thread.pending) return;
const source = explain.key(run).source, typed = this.typedKeys.get(run.providerId) ?? '';
if (source === 'none' && !/^[\x21-\x7e]{8,4096}$/u.test(typed)) {
thread.error = t('请填写这个服务商的 API Key'); this.render();
Expand All @@ -1343,7 +1347,7 @@ export class TrajectoryView {
thread.pending = { question, controller }; thread.error = undefined; thread.draft = '';
this.render();
try {
const answer = await explain.ask(run, { taskId: version.taskId, commit: version.commit, question,
const answer = await explain.ask(run, { taskId: version.taskId, commit: version.commit, receiptId, checkAt: check.at, question,
...(check?.taskVersion ? { taskVersion: check.taskVersion } : {}),
turns: thread.turns.slice(-explainLimits.turns).map(turn => ({ question: turn.question, answer: turn.answer })),
...(source === 'none' ? { apiKey: typed } : {}) }, controller.signal);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export type WebCommand =
| { type: 'guidance-withdraw'; id: string; guidanceId: string }
| { type: 'plan-approval'; approval: WebPlanApprovalInput }
| { type: 'capture' };
export type WebLibraryRestart = { previousSolverRunId: string; solverRunId: string; round: number };
export type WebCommandResult = {
id: string; status: string; baseVersion?: string; planVersion?: string; reason?: string;
commandDigest?: string;
Expand All @@ -220,6 +221,7 @@ export type WebCommandResult = {
edit?: WebHumanEdit;
observation?: WebObservation;
catalog?: unknown;
libraryRestart?: WebLibraryRestart;
};
export type WebArchive = {
id: string; runId: string; createdAt: string; digest: string;
Expand Down
4 changes: 3 additions & 1 deletion apps/web/i18n/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ export const errors: Record<string, string> = {
"这个版本没有记录或已超出保留范围。": "This version was not recorded or is no longer kept.",
"请检查问题、版本与 API Key。": "Check the question, the version and the API key.",
"这次运行的模型服务已不在配置中。": "This run's model provider is no longer configured.",
"这个版本没有未通过的 Lean 检查可以解释。": "This version has no failed Lean check to explain.",
"这个检查没有记录或已超出保留范围。": "This check was not recorded or is no longer kept.",
"这个版本有多次检查,请选择要解释的一次。": "This version was checked more than once. Choose the check to explain.",
"没有未通过的 Lean 检查可以解释。": "There is no failed Lean check to explain.",
"该任务版本没有已保存的源码。": "This task version has no saved source.",
"检查回执不存在或未保存。": "The check receipt does not exist or was not saved.",
"指导回执尚不可用。": "The guidance receipt is not available yet.",
Expand Down
Loading
Loading