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
10 changes: 6 additions & 4 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [web, worker]
target: [web, worker, tex]
steps:
- name: Free disk for the Mathlib layer
if: matrix.target == 'worker'
Expand Down Expand Up @@ -72,18 +72,20 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Record the complete image pair
- name: Record the complete image set
env:
RELEASE_COMMIT: ${{ github.sha }}
run: |
set -eu
web="ghcr.io/huggingmath/theorem-os-web:$RELEASE_COMMIT"
worker="ghcr.io/huggingmath/theorem-os-worker:$RELEASE_COMMIT"
tex="ghcr.io/huggingmath/theorem-os-tex:$RELEASE_COMMIT"
web_digest=$(docker buildx imagetools inspect "$web" --format '{{.Manifest.Digest}}')
worker_digest=$(docker buildx imagetools inspect "$worker" --format '{{.Manifest.Digest}}')
tex_digest=$(docker buildx imagetools inspect "$tex" --format '{{.Manifest.Digest}}')
jq -n --arg commit "$RELEASE_COMMIT" --arg web "$web" --arg webDigest "$web_digest" \
--arg worker "$worker" --arg workerDigest "$worker_digest" \
'{schema:"theorem-os.image-release.v1",commit:$commit,web:{image:$web,digest:$webDigest},worker:{image:$worker,digest:$workerDigest}}' > image-release.json
--arg worker "$worker" --arg workerDigest "$worker_digest" --arg tex "$tex" --arg texDigest "$tex_digest" \
'{schema:"theorem-os.image-release.v1",commit:$commit,web:{image:$web,digest:$webDigest},worker:{image:$worker,digest:$workerDigest},tex:{image:$tex,digest:$texDigest}}' > image-release.json
- uses: actions/upload-artifact@v4
with:
name: image-release-${{ github.sha }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: bun scripts/test-web-proof-thinking.ts --simple-reading
- name: Verify the browser's login and research flows with local fixtures
run: bun run test:web-login && bun run test:web-natural-first && bun run test:web-chat-session && bun run test:web-chat-cancel-recovery && bun run test:web-key-memory && bun run test:web-saved-key && bun run test:web-solve-process && bun run test:web-review-regressions && bun run test:web-plan-recovery && bun run test:web-plan-ownership && bun run test:web-explain && bun run test:web-explain-recovery
- name: Verify paper drafting and download with local fixtures
run: bun scripts/test-web-paper.ts
- name: Verify research account switching and interrupted frontend operations
run: bun run test:frontend-round5
- name: Verify session renewal, candidate review and route evidence readers
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ bun run math inspect --run "$THEOREMOS_REPLAY/result.json"
完整依赖与 FUSE / 磁盘要求(建议为每个并发 Mathlib 任务预留 30 GiB 可用磁盘)详见 [网页工作台文档](./docs/web-workbench.md) 与[运维指南](./docs/web-operations.md):

```bash
# 方式 A:从当前源码构建 web 与 worker 镜像并启动
THEOREMOS_SOURCE_COMMIT=$(git rev-parse HEAD) docker compose -f apps/web/compose.yml build worker web
# 方式 A:从当前源码构建 web、worker 和 tex 镜像并启动
THEOREMOS_SOURCE_COMMIT=$(git rev-parse HEAD) docker compose -f apps/web/compose.yml build worker web tex
docker compose -f apps/web/compose.yml up -d web
docker compose -f apps/web/compose.yml ps

# 方式 B:拉取 GitHub Actions 发布到 GHCR 的完整 SHA 镜像对
# 方式 B:拉取 GitHub Actions 发布到 GHCR 的同一 SHA 的三个镜像
export THEOREMOS_IMAGE_TAG=<完整的40位提交SHA>
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml pull worker web
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml pull worker web tex
bun scripts/web-operations.ts images --commit "$THEOREMOS_IMAGE_TAG"
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml up -d --no-build web
```
Expand Down
8 changes: 4 additions & 4 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ The replay builds the pinned runtime, submits a deliberately failing candidate,
See the [Web Workbench Guide](./docs/web-workbench.md) and [Operations Guide](./docs/web-operations.md) for host `/dev/fuse` requirements and disk headroom (~30 GiB recommended per concurrent Mathlib run):

```bash
# Option A: Build and start web + worker locally
THEOREMOS_SOURCE_COMMIT=$(git rev-parse HEAD) docker compose -f apps/web/compose.yml build worker web
# Option A: Build web, worker and tex locally, then start the workbench
THEOREMOS_SOURCE_COMMIT=$(git rev-parse HEAD) docker compose -f apps/web/compose.yml build worker web tex
docker compose -f apps/web/compose.yml up -d web
docker compose -f apps/web/compose.yml ps

# Option B: Pull paired full-SHA images built by GitHub Actions
# Option B: Pull all three images published by GitHub Actions for the same commit
export THEOREMOS_IMAGE_TAG=<full-40-char-commit-sha>
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml pull worker web
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml pull worker web tex
bun scripts/web-operations.ts images --commit "$THEOREMOS_IMAGE_TAG"
docker compose -f apps/web/compose.yml -f apps/web/compose.ghcr.yml up -d --no-build web
```
Expand Down
15 changes: 15 additions & 0 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ COPY LICENSE NOTICE CITATION.cff ./
COPY LICENSES ./LICENSES
COPY third_party ./third_party

# A small, independent image for untrusted LaTeX snapshots. It deliberately has no project source or network client.
FROM debian:bookworm-slim AS tex
ARG THEOREMOS_SOURCE_COMMIT=unknown
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates fontconfig latexmk python3 texlive-fonts-recommended \
texlive-latex-recommended texlive-xetex \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --uid 10001 --create-home --home-dir /work --shell /usr/sbin/nologin theorem \
&& chmod 0700 /work
ENV HOME=/tmp TEXMFCONFIG=/tmp/texmf-config TEXMFVAR=/tmp/texmf-var XDG_CACHE_HOME=/tmp/cache
WORKDIR /work
USER 10001:10001
LABEL org.opencontainers.image.revision=$THEOREMOS_SOURCE_COMMIT
ENTRYPOINT ["sh"]

FROM base AS worker-tools
ENV ELAN_HOME=/opt/elan \
PATH=/opt/elan/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin \
Expand Down
43 changes: 36 additions & 7 deletions apps/web/client/chatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { backgroundReviewPending } from './backgroundReview';
import { ChatAnswers } from './chatAnswer';
import { chatMathematics } from './chatMathematics';
import { detailLevel } from './detailLevel';
import { forgetKey, ownedTabKeyStorage, rememberedKey, rememberKey } from './keyMemory';

const running = (item?: { status: string }) => item?.status === 'queued' || item?.status === 'running';
const reason = (error: unknown) => localizeMessage(error instanceof Error ? error.message : String(error));
Expand Down Expand Up @@ -420,14 +421,35 @@ export class ChatSession {
}
private activeProviderId() { return this.run?.providerId ?? this.formalization?.providerId ?? this.providerId; }
private activeModel() { return this.run?.model ?? this.formalization?.model ?? this.model; }
private get tabKeyProvider() {
const session = this.options.session();
if (!session?.account?.keyVault) return session?.providers.find(provider => provider.id === this.activeProviderId());
}
private get tabKey() {
const provider = this.tabKeyProvider;
return provider && rememberedKey(ownedTabKeyStorage(this.options.session()), provider.id, provider.baseUrl);
}
private get activeKey() {
return this.apiKey || this.tabKey || '';
}
private setRememberedKey(remember: boolean) {
const provider = this.tabKeyProvider;
if (!provider) return;
const storage = ownedTabKeyStorage(this.options.session());
if (!remember) {
if (this.tabKey) forgetKey(storage);
} else if (this.apiKey.trim() && !rememberKey(storage, { providerId: provider.id, baseUrl: provider.baseUrl, apiKey: this.apiKey.trim() })) {
this.keyNotice = t('浏览器不允许保存,Key 只保留到这次提交');
}
}
private clearConnection() { this.connectionRevision++; this.connection = undefined; this.checkingConnection = false; }
private async checkConnection() {
if (this.checkingConnection) return;
const revision = ++this.connectionRevision;
this.checkingConnection = true; this.connection = undefined; this.draw();
try {
const result = await this.post<{ status: 'available' | 'unknown'; message: string }>(`/api/providers/${encodeURIComponent(this.activeProviderId())}/check`,
{ apiKey: this.apiKey, model: this.activeModel() });
{ apiKey: this.activeKey, model: this.activeModel() });
if (revision === this.connectionRevision) this.connection = { ...result, message: reason(result.message) };
} catch (error) { if (revision === this.connectionRevision) this.connection = { status: 'error', message: reason(error) }; }
finally { if (revision === this.connectionRevision) { this.checkingConnection = false; this.draw(); } }
Expand All @@ -436,7 +458,7 @@ export class ChatSession {
const item = this.formalization;
if (!item || item.runId || this.startingResearch || (item.status !== 'confirmed'
&& !(confirmStatement && item.humanReview && item.status === 'review' && item.report))) return;
if (!this.apiKey && this.options.keyRequired(this.activeProviderId())) {
if (!this.activeKey && this.options.keyRequired(this.activeProviderId())) {
this.error = t('请在设置中填写 API Key 后发送。'); this.draw();
const settings = this.composer.querySelector<HTMLDetailsElement>('#formalize-settings');
if (settings) settings.open = true;
Expand All @@ -454,7 +476,7 @@ export class ChatSession {
this.formalizations = this.formalizations.map(record => record.id === formalization.id ? formalization : record);
this.draw();
}
const { formalization } = await this.post<{ formalization: WebFormalization }>(`/api/formalizations/${item.id}/research`, { apiKey: this.apiKey });
const { formalization } = await this.post<{ formalization: WebFormalization }>(`/api/formalizations/${item.id}/research`, { apiKey: this.activeKey });
if (generation !== this.generation) return;
this.formalization = formalization;
this.formalizations = this.formalizations.map(record => record.id === formalization.id ? formalization : record);
Expand Down Expand Up @@ -816,7 +838,7 @@ export class ChatSession {
|| !(this.pendingMessage?.text ?? retryText ?? this.draft).trim()) return;
// A received task can be reattached without starting it again. Editing its original instead needs an explicit choice.
if (this.seed && retryText === undefined && withLibraryReferences(this.draft, this.references, locale) !== this.seed.original) { this.draw(); return; }
const generation = this.generation, owner = this.ownerRevision, seed = this.seed, conversation = this.conversation, key = this.apiKey,
const generation = this.generation, owner = this.ownerRevision, seed = this.seed, conversation = this.conversation, key = this.activeKey,
draftText = this.draft, references = this.references;
const message = conversation ? this.pendingMessage ?? { requestId: crypto.randomUUID(), text: retryText ?? withLibraryReferences(draftText, references, locale) } : undefined;
const text = seed?.original ?? message?.text ?? retryText ?? withLibraryReferences(draftText, references, locale);
Expand Down Expand Up @@ -1245,7 +1267,7 @@ export class ChatSession {
this.composer.querySelector<HTMLSelectElement>('#formalize-provider')?.focus();
},
startGuide: { onTemplate: () => this.fillOriginal(this.draft.trim() ? this.draft : statementTemplate()), onLean: this.options.onLean,
ready: !!this.activeModel().trim() && (!this.options.keyRequired(this.activeProviderId()) || !!this.apiKey.trim()) },
ready: !!this.activeModel().trim() && (!this.options.keyRequired(this.activeProviderId()) || !!this.activeKey.trim()) },
overview: { owner: this.options.draftScope, runs: this.options.runs(), conversations: this.summaries, formalizations: this.formalizations,
request: this.options.request, onOpenRun: this.options.onOpenRun, onOpenConversation: (id: string) => void this.open(id) },
};
Expand Down Expand Up @@ -1351,7 +1373,9 @@ export class ChatSession {
onPrepareEdited: () => void this.submit(this.seed!.original, true) } } : {}),
participation: this.participation, participationLocked: Boolean(this.seed || this.submissionIdentity.unresolved || this.run),
onParticipation: value => { this.participation = value; this.rememberDraft(); this.draw(); },
keyRequired: guidance || pendingSubmission || this.pendingMessage ? false : this.options.keyRequired(this.activeProviderId()),
keyRequired: guidance || pendingSubmission || this.pendingMessage || this.tabKey ? false : this.options.keyRequired(this.activeProviderId()),
...(this.tabKeyProvider ? { tabKeyMemory: { remembered: Boolean(this.tabKey), notice: this.keyNotice,
onChange: (remember: boolean) => { this.keyNotice = ''; this.setRememberedKey(remember); this.clearConnection(); this.draw(); } } } : {}),
providers: this.providers(), providerId: this.activeProviderId(), model: this.activeModel(),
onProvider: value => { this.providerId = value; this.model = this.providers().find(item => item.id === value)?.defaultModel ?? ''; this.apiKey = ''; this.keyNotice = ''; this.clearConnection(); this.rememberDraft(); this.draw(); },
onModel: value => { this.model = value; this.clearConnection(); this.rememberDraft(); this.draw(); },
Expand Down Expand Up @@ -1396,7 +1420,12 @@ export class ChatSession {
: this.conversation && this.run?.status === 'running' && !showGuidance && !canDecide && !this.options.isSample(this.run)
? t('这里发送的是讨论,不会调整正在进行的解题。') : undefined,
onEnvironment: () => { if (!this.submissionIdentity.unresolved && !this.seed && !this.conversation && !this.run) this.environment = webTaskEnvironment; this.rememberDraft(); this.draw(); }, onEffort: value => { this.effort = value; this.researchEffort = value; this.rememberDraft(); this.draw(); },
onKey: value => { this.apiKey = value; this.keyNotice = ''; this.clearConnection(); this.draw(); },
onKey: value => {
const remembered = this.tabKey;
this.apiKey = value; this.keyNotice = '';
if (remembered) this.setRememberedKey(Boolean(value.trim()));
this.clearConnection(); this.draw();
},
onExample: id => this.useExample(id),
onLean: this.options.onLean,
});
Expand Down
11 changes: 11 additions & 0 deletions apps/web/client/keyMemory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { WebSession } from '../shared';
import { draftOwnerStorageKey, webDraftOwner } from './ownedDrafts';

/**
* Opt-in memory of one API Key for the current tab. It lives in sessionStorage, so closing the tab clears it, and it only
* answers for the provider and address it was entered for; a key typed for one endpoint is never offered to another.
Expand All @@ -8,6 +11,14 @@ type KeyStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
type StorageSource = () => KeyStorage;
type Remembered = { providerId: string; baseUrl: string; apiKey: string };

/** Standalone pages share tab credentials only with the workbench owner who saved them. */
export function ownedTabKeyStorage(session?: WebSession): StorageSource {
return () => {
if (!session || sessionStorage.getItem(draftOwnerStorageKey) !== webDraftOwner(session)) throw new Error('tab_key_owner_unavailable');
return sessionStorage;
};
}

function read(storage: StorageSource): Remembered | undefined {
try {
const value = JSON.parse(storage().getItem(keyMemoryStorageKey) ?? 'null');
Expand Down
Loading
Loading