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
24 changes: 2 additions & 22 deletions apps/web/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export class WebAuth {
private readonly storage: WebStorage,
private readonly mailer: WebMailer = smtpMailer(config),
private readonly answer: () => string = () => String(crypto.randomInt(0, 100_000)).padStart(5, '0'),
private readonly writer?: (message: object) => WebAccount,
) {}

/** Sliding-window counter; returns false once `max` events already fall inside `windowMs`. */
Expand Down Expand Up @@ -215,17 +214,13 @@ export class WebAuth {
const version = this.checkTerms(body, account);
return this.recordTerms(account, version);
}
invalidateLoginCode(login: string) {
private invalidateLoginCode(login: string) {
this.codes.delete(login);
for (const delivery of this.sending) if (delivery.email === login) this.sending.delete(delivery);
}
/** Suspension keeps records for restoration, blocks both login methods and invalidates admission on the next request. */
setSuspended(value: unknown, suspended: boolean): WebAccount {
const login = normalizeLogin(value);
if (this.writer) {
if (suspended) this.invalidateLoginCode(login);
return this.writer({ op: 'account', action: 'suspend', login, data: { suspended } });
}
const account = this.getAccount(login);
if (!account) throw new WebAuthError(404, '账号不存在。');
if (this.isAdmin(login) && suspended) throw new WebAuthError(400, '管理员账号不能暂停。');
Expand Down Expand Up @@ -275,7 +270,6 @@ export class WebAuth {
this.fileLines().filter(line => line.replace(/#.*/u, '').trim().toLowerCase() !== email),
);
this.invalidateLoginCode(email);
this.writer?.({ op: 'invalidateCode', login: email });
}
allowlistWritable(): boolean {
return Boolean(this.config.allowlistFile);
Expand Down Expand Up @@ -339,7 +333,7 @@ export class WebAuth {
return { email, expiresInSeconds: codeTtlMs / 1000, resendAfterSeconds: resendAfterMs / 1000 };
}

sendLoginCode(email: string, code: string) {
private sendLoginCode(email: string, code: string) {
return this.mailer({
to: email,
subject: `TheoremOS 登录验证码 ${code}`,
Expand Down Expand Up @@ -527,15 +521,6 @@ export class WebAuth {
/** Stamps a milestone the first time it happens; later runs leave the first time unchanged. */
markMilestone(accountId: string, milestone: WebMilestone, at = new Date().toISOString()) {
const account = this.listAccounts().find(item => item.id === accountId);
if (account && this.writer) {
this.writer({
op: 'account',
action: 'milestone',
login: accountLogin(account),
data: { id: accountId, field: milestone, at },
});
return;
}
if (account && !account[milestone])
this.storage.saveRecord(this.accountPath(accountLogin(account)), { ...account, [milestone]: at });
}
Expand All @@ -557,11 +542,6 @@ export class WebAuth {
await this.mailer({ to, ...message });
}
deleteAccount(login: string) {
if (this.writer) {
this.writer({ op: 'account', action: 'delete', login, data: {} });
this.codes.delete(login);
return;
}
// Keep the account retryable if credential deletion fails; a recreated account must never inherit its password.
this.storage.deleteRecord(this.passwordPath(login));
this.storage.deleteRecord(this.accountPath(login));
Expand Down
430 changes: 154 additions & 276 deletions apps/web/community.ts

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions apps/web/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export class WebExplainer {
private readonly busy = new Set<string>();
private readonly asked = new Map<string, number[]>();
constructor(private readonly timeoutMs = 0) {}
onQueueChange?: () => void;
queueState() {
return { running: this.busy.size, waiting: [] };
}
Expand All @@ -274,13 +273,11 @@ export class WebExplainer {
if (this.busy.has(owner)) throw new WebExplainError(429, '上一个问题还在回答,请等它结束或先停止。');
if (recent.length >= pace.questions) throw new WebExplainError(429, '提问太频繁,请过几分钟再问。');
this.busy.add(owner);
this.onQueueChange?.();
this.asked.set(owner, [...recent, now]);
try {
return await askProvider({ ...call, timeoutMs: this.timeoutMs }, signal);
} finally {
this.busy.delete(owner);
this.onQueueChange?.();
}
}
prune() {
Expand Down
6 changes: 0 additions & 6 deletions apps/web/explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export class WebExplanations {
}
}

onQueueChange?: () => void;
queueState() {
const waiting = [...this.jobs.values()]
.filter(job => job.explanation.status === 'queued')
Expand Down Expand Up @@ -174,7 +173,6 @@ export class WebExplanations {
}
}
}
this.onQueueChange?.();
queueMicrotask(() => this.pump());
}
private capacity(owner: string) {
Expand Down Expand Up @@ -257,7 +255,6 @@ export class WebExplanations {
this.release(job);
throw error;
}
this.onQueueChange?.();
queueMicrotask(() => this.pump());
return this.view(job);
}
Expand Down Expand Up @@ -317,7 +314,6 @@ export class WebExplanations {
return this.jobs.get(this.id(job.owner, job.run.id, job.key)) === job;
}
private release(job: Job) {
this.onQueueChange?.();
if (this.current(job)) this.jobs.delete(this.id(job.owner, job.run.id, job.key));
job.input.apiKey = '';
delete job.input.checkpoint;
Expand Down Expand Up @@ -354,7 +350,6 @@ export class WebExplanations {
);
if (!job) break;
this.running++;
this.onQueueChange?.();
const now = new Date().toISOString();
Object.assign(job.explanation, {
status: 'running',
Expand All @@ -363,7 +358,6 @@ export class WebExplanations {
});
void this.execute(job).finally(() => {
this.running--;
this.onQueueChange?.();
this.pump();
});
}
Expand Down
9 changes: 0 additions & 9 deletions apps/web/formalizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export class WebFormalizations {
})
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
}
onQueueChange?: () => void;
queueState() {
const waiting = [
...[...this.jobs.values()]
Expand Down Expand Up @@ -544,7 +543,6 @@ export class WebFormalizations {
this.release(job);
throw error;
}
this.onQueueChange?.();
queueMicrotask(() => this.pump());
return this.view(formalization);
}
Expand Down Expand Up @@ -688,7 +686,6 @@ export class WebFormalizations {
this.storage.saveRecord([...recordPath(record.owner, record.formalization.id), 'record.json'], record);
}
private release(job: Job) {
this.onQueueChange?.();
if (this.current(job)) this.jobs.delete(this.key(job.record.owner, job.record.formalization.id));
job.input.apiKey = '';
}
Expand Down Expand Up @@ -760,7 +757,6 @@ export class WebFormalizations {
maxTotalTokens,
maxRunSeconds: 0,
};
this.onQueueChange?.();
this.auditJobs.set(this.key(job.record.owner, value.id), {
record: job.record,
input,
Expand All @@ -774,7 +770,6 @@ export class WebFormalizations {
return this.auditJobs.get(this.key(job.record.owner, job.record.formalization.id)) === job;
}
private releaseAudit(job: AuditJob) {
this.onQueueChange?.();
if (this.currentAudit(job)) this.auditJobs.delete(this.key(job.record.owner, job.record.formalization.id));
job.input.apiKey = '';
}
Expand Down Expand Up @@ -811,10 +806,8 @@ export class WebFormalizations {
job.record.formalization.updatedAt = now;
this.save(job.record);
this.auditsRunning++;
this.onQueueChange?.();
void this.executeAudit(job).finally(() => {
this.auditsRunning--;
this.onQueueChange?.();
this.pumpAudits();
});
}
Expand Down Expand Up @@ -880,14 +873,12 @@ export class WebFormalizations {
const job = [...this.jobs.values()].find(item => item.record.formalization.status === 'queued');
if (!job) break;
this.running++;
this.onQueueChange?.();
Object.assign(job.record.formalization, {
status: 'running',
progress: { phase: 'preparing', updatedAt: new Date().toISOString() },
});
void this.execute(job).finally(() => {
this.running--;
this.onQueueChange?.();
this.pump();
});
}
Expand Down
3 changes: 0 additions & 3 deletions apps/web/i18n/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ export const errors: Record<string, string> = {
'排队中或运行中的任务不能删除,请先取消或等待结束。':
'A queued or running task cannot be deleted; cancel it or wait for it to finish.',
'运行尚未结束,且结果尚未生成。': 'The run has not finished and has no result yet.',
'接口不存在。': 'Endpoint not found.',
'验证码格式无效。': 'Invalid verification code format.',
'账号状态已变更,请重新读取。': 'The account status changed. Reload and try again.',
'知识查询或分页参数无效。': 'Invalid knowledge query or paging parameters.',
'服务暂时不可用。': 'The service is temporarily unavailable.',
'服务已重启;保留最后观测与已有证据。本次运行未恢复执行。':
Expand Down
1 change: 0 additions & 1 deletion apps/web/i18n/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export const server: Record<string, string> = {
有界证明研究: 'Bounded proof research',
'Lean 局部检查': 'Local Lean checks',
计划顺序: 'Plan order',
关键路径: 'Critical path',
必要证明上下文: 'Essential proof context',
角色分工与交付: 'Roles and handoffs',
完整原题独立验收: 'Independent acceptance of the complete problem',
Expand Down
Loading
Loading