@citeark/agent 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +128 -0
- package/data/dataset-source-registry.v1.json +300 -0
- package/dist/arkgraph/boot.js +6 -0
- package/dist/arkgraph/index.html +1 -0
- package/dist/arkgraph/viewer.css +1 -0
- package/dist/arkgraph/viewer.en.css +1 -0
- package/dist/arkgraph/viewer.en.js +49 -0
- package/dist/arkgraph/viewer.en.js.LEGAL.txt +56 -0
- package/dist/arkgraph/viewer.js +49 -0
- package/dist/arkgraph/viewer.js.LEGAL.txt +56 -0
- package/docker/claude-code/Dockerfile +97 -0
- package/docker/claude-code/codex-pro-relay.mjs +466 -0
- package/docker/claude-code/runtime-contract-check.mjs +79 -0
- package/docs/arkgraph-reading.md +79 -0
- package/docs/configuration.md +100 -0
- package/docs/integration.md +92 -0
- package/docs/maturity-plan.md +27 -0
- package/docs/npm-release.md +44 -0
- package/docs/paper-reading.md +40 -0
- package/docs/research-plan-granularity.md +27 -0
- package/docs/terminal.md +49 -0
- package/examples/toy-evaluation/compile-task.json +27 -0
- package/examples/toy-evaluation/paper.md +5 -0
- package/examples/toy-evaluation/repository/README.md +9 -0
- package/examples/toy-evaluation/repository/checkpoint.json +4 -0
- package/examples/toy-evaluation/repository/evaluate.py +17 -0
- package/examples/toy-evaluation/task.json +81 -0
- package/package.json +59 -0
- package/prompts/compile-research.md +58 -0
- package/prompts/execute-contract.md +72 -0
- package/prompts/execute-workspace-simple.md +51 -0
- package/prompts/execute-workspace.md +34 -0
- package/prompts/prepare-reproduction.md +82 -0
- package/prompts/repair-research.md +45 -0
- package/protocol/CAP.md +129 -0
- package/protocol/LICENSE +12 -0
- package/protocol/MAPPINGS.md +72 -0
- package/protocol/README.md +38 -0
- package/protocol/conformance-v2.0-alpha.1.json +36 -0
- package/protocol/examples/arkgraph/checkpoint-evaluation.json +309 -0
- package/protocol/examples/arkgraph/fixtures.mjs +49 -0
- package/protocol/examples/arkgraph/paper-free.json +291 -0
- package/protocol/examples/arkgraph/partial-failure.json +344 -0
- package/protocol/examples/arkgraph/training-evaluation.json +443 -0
- package/protocol/profiles/agent-trace.md +16 -0
- package/protocol/profiles/computational-run.md +16 -0
- package/protocol/profiles/core.md +15 -0
- package/protocol/profiles/public-bundle.md +18 -0
- package/protocol/profiles/reproduction.md +29 -0
- package/protocol/profiles/research-compilation.md +44 -0
- package/protocol/profiles/research-plan.md +39 -0
- package/protocol/profiles/restricted-evidence.md +15 -0
- package/runtime/bootstrap-autodl-runtime.sh +314 -0
- package/runtime/create-runtime-venv.sh +41 -0
- package/runtime/install-local-cpu-runtime.sh +23 -0
- package/runtime/install-scientific-runtime.sh +153 -0
- package/runtime/mineru/parse.py +62 -0
- package/runtime/mineru/requirements.txt +4 -0
- package/runtime/requirements-baseline.txt +38 -0
- package/schemas/cap/v2/activity.schema.json +47 -0
- package/schemas/cap/v2/agent.schema.json +32 -0
- package/schemas/cap/v2/assertion.schema.json +110 -0
- package/schemas/cap/v2/descriptor.schema.json +243 -0
- package/schemas/cap/v2/entity.schema.json +64 -0
- package/schemas/cap/v2/manifest.schema.json +67 -0
- package/schemas/cap/v2/relation.schema.json +82 -0
- package/schemas/compute-catalog.schema.json +63 -0
- package/schemas/compute-decision.schema.json +27 -0
- package/schemas/execution-contract.schema.json +1024 -0
- package/schemas/research-card.schema.json +30 -0
- package/schemas/research-inventory-draft.schema.json +366 -0
- package/schemas/research.schema.json +1044 -0
- package/schemas/result.schema.json +173 -0
- package/schemas/verification-policy.schema.json +47 -0
- package/schemas/verified-conclusion.schema.json +58 -0
- package/schemas/workspace-summary.schema.json +24 -0
- package/scripts/build-arkgraph-view.mjs +12 -0
- package/scripts/check-execution-feasibility.mjs +24 -0
- package/scripts/check-syntax.mjs +15 -0
- package/scripts/deterministic-asset-preparation.py +438 -0
- package/scripts/package-cap.mjs +23 -0
- package/scripts/package-local-agent.mjs +23 -0
- package/scripts/preview-arkgraph.mjs +25 -0
- package/scripts/replay-research-compiler-candidate.mjs +134 -0
- package/scripts/review-compiler-sources.mjs +44 -0
- package/scripts/run-asset-preparation.sh +17 -0
- package/scripts/run-research-plan.mjs +98 -0
- package/scripts/validate-asset-preparation.py +290 -0
- package/scripts/verify-local-runtime.mjs +57 -0
- package/scripts/verify-npm-package.mjs +57 -0
- package/src/adapters/paper2agent.mjs +107 -0
- package/src/assets/cache.mjs +159 -0
- package/src/assets/compute.mjs +98 -0
- package/src/assets/executor.mjs +145 -0
- package/src/assets/lifecycle.mjs +213 -0
- package/src/assets/manifest.mjs +242 -0
- package/src/assets/opportunistic-preparation.mjs +81 -0
- package/src/assets/plan.mjs +411 -0
- package/src/assets/prompts.mjs +29 -0
- package/src/assets/public-asset-probe.mjs +525 -0
- package/src/assets/qualification.mjs +119 -0
- package/src/assets/readiness.mjs +130 -0
- package/src/assets/reproduction-admission.mjs +355 -0
- package/src/assets/requirements.mjs +152 -0
- package/src/assets/source-grounding.mjs +341 -0
- package/src/assets/source-policy.mjs +118 -0
- package/src/autodl/client.mjs +260 -0
- package/src/autodl/ssh.mjs +380 -0
- package/src/autodl/tools.mjs +129 -0
- package/src/cap/redaction.mjs +38 -0
- package/src/cap/v2/archive.mjs +152 -0
- package/src/cap/v2/attestation.mjs +204 -0
- package/src/cap/v2/canonical-json.mjs +114 -0
- package/src/cap/v2/compilation-artifact.mjs +240 -0
- package/src/cap/v2/core.mjs +282 -0
- package/src/cap/v2/measurement-assessment-records.mjs +23 -0
- package/src/cap/v2/pipeline-artifact.mjs +922 -0
- package/src/cap/v2/read.mjs +41 -0
- package/src/cap/v2/reassessment-artifact.mjs +383 -0
- package/src/cap/v2/research-artifact.mjs +231 -0
- package/src/cap/v2/research-map-records.mjs +46 -0
- package/src/cap/v2/research-object-records.mjs +163 -0
- package/src/cap/v2/research-records.mjs +187 -0
- package/src/cap/v2/verify.mjs +642 -0
- package/src/cli.mjs +1146 -0
- package/src/compute/autodl-pro-compiler.mjs +347 -0
- package/src/compute/autodl-pro-executor.mjs +459 -0
- package/src/compute/autodl-pro-job.mjs +843 -0
- package/src/compute/autodl-pro-network.mjs +295 -0
- package/src/compute/autodl-pro-remote.mjs +810 -0
- package/src/compute/autodl-pro-staging.mjs +117 -0
- package/src/compute/campaign.mjs +110 -0
- package/src/compute/catalog.mjs +123 -0
- package/src/compute/checkpoint-protocol.mjs +154 -0
- package/src/compute/codex-account-lock.mjs +111 -0
- package/src/compute/codex-account-session.mjs +107 -0
- package/src/compute/compiler-profile.mjs +38 -0
- package/src/compute/compiler-router.mjs +23 -0
- package/src/compute/coordinator-recovery.mjs +210 -0
- package/src/compute/executor-router.mjs +29 -0
- package/src/compute/gcp-batch-compiler.mjs +685 -0
- package/src/compute/gcp-batch-executor.mjs +1215 -0
- package/src/compute/gcp-batch-failure.mjs +92 -0
- package/src/compute/gcp-batch-job.mjs +527 -0
- package/src/compute/gcp-batch-lifecycle.mjs +81 -0
- package/src/compute/gcp-checkpoint-worker.mjs +1633 -0
- package/src/compute/local-codex-compiler.mjs +52 -0
- package/src/compute/measurement-hardware.mjs +128 -0
- package/src/compute/remote-attempt.mjs +226 -0
- package/src/compute/requirements.mjs +124 -0
- package/src/compute/research-phases.mjs +48 -0
- package/src/compute/scheduler.mjs +452 -0
- package/src/compute/shared-workloads.mjs +26 -0
- package/src/compute/stage-archive.mjs +79 -0
- package/src/contracts/campaign-contract.mjs +52 -0
- package/src/contracts/execution-contract.mjs +819 -0
- package/src/contracts/execution-mode.mjs +19 -0
- package/src/contracts/execution-timeouts.mjs +45 -0
- package/src/contracts/execution-workload.mjs +68 -0
- package/src/contracts/preflight-schema.mjs +25 -0
- package/src/contracts/public-contract.mjs +63 -0
- package/src/contracts/subject-tags.mjs +31 -0
- package/src/dashboard/data.mjs +898 -0
- package/src/dashboard/server.mjs +79 -0
- package/src/dashboard/static/dashboard.css +366 -0
- package/src/dashboard/static/dashboard.js +560 -0
- package/src/dashboard/static/index.html +85 -0
- package/src/deployment/community-policy.mjs +9 -0
- package/src/deployment/environment.mjs +112 -0
- package/src/deployment/guided.mjs +98 -0
- package/src/deployment/handoff.mjs +102 -0
- package/src/deployment/local-contract.mjs +31 -0
- package/src/deployment/local.mjs +100 -0
- package/src/deployment/prepare.mjs +46 -0
- package/src/deployment/recipe.mjs +108 -0
- package/src/deployment/supplement.mjs +51 -0
- package/src/deployment/terminal.mjs +43 -0
- package/src/diagnosis/renderer.mjs +75 -0
- package/src/diagnosis/target-failure.mjs +46 -0
- package/src/evidence/parser-registry.mjs +54 -0
- package/src/evidence/parsers/fasttext-classification.mjs +82 -0
- package/src/evidence/parsers/json-scalar.mjs +96 -0
- package/src/evidence/parsers/simcse-senteval.mjs +104 -0
- package/src/evidence/parsers/starspace-classification.mjs +78 -0
- package/src/evidence/registry.mjs +147 -0
- package/src/execution/runner-audit.mjs +473 -0
- package/src/gcp/auth.mjs +106 -0
- package/src/gcp/batch-client.mjs +120 -0
- package/src/gcp/resource-discovery.mjs +177 -0
- package/src/gcp/rest.mjs +82 -0
- package/src/gcp/secret-manager.mjs +34 -0
- package/src/gcp/signed-url.mjs +133 -0
- package/src/gcp/storage.mjs +220 -0
- package/src/graph/command.mjs +41 -0
- package/src/graph/execution.mjs +97 -0
- package/src/graph/model.mjs +37 -0
- package/src/graph/presentation.mjs +110 -0
- package/src/graph/query.mjs +159 -0
- package/src/graph/research-relations.mjs +69 -0
- package/src/graph/source-page.mjs +12 -0
- package/src/graph/source-preview.mjs +34 -0
- package/src/graph/validate.mjs +76 -0
- package/src/job.mjs +496 -0
- package/src/network/autodl-routing-proxy.mjs +462 -0
- package/src/network/egress-proxy.mjs +158 -0
- package/src/observability/event-contract.mjs +230 -0
- package/src/observability/pipeline-monitor.mjs +166 -0
- package/src/pipeline/orchestrator.mjs +1281 -0
- package/src/pipeline/recovery-error.mjs +11 -0
- package/src/pipeline/replay.mjs +304 -0
- package/src/pipeline/shared-execution.mjs +115 -0
- package/src/pipeline/stage-checkpoint.mjs +86 -0
- package/src/pipeline/stage-recovery.mjs +101 -0
- package/src/pipeline/targets.mjs +110 -0
- package/src/process.mjs +143 -0
- package/src/protocol.mjs +312 -0
- package/src/provider/codex-account.mjs +44 -0
- package/src/provider/codex-completion.mjs +49 -0
- package/src/provider/completion.mjs +292 -0
- package/src/provider/model-client.mjs +44 -0
- package/src/provider/model-route.mjs +29 -0
- package/src/provider/openrouter-readiness.mjs +189 -0
- package/src/provider/reader-bridge.mjs +35 -0
- package/src/provider/relay.mjs +263 -0
- package/src/provider/runtime-auth.mjs +40 -0
- package/src/public/cap.d.mts +90 -0
- package/src/public/cap.mjs +12 -0
- package/src/public/contracts.d.mts +2 -0
- package/src/public/host.mjs +171 -0
- package/src/public/operations.d.mts +11 -0
- package/src/public/presentation.d.mts +4 -0
- package/src/records/views.mjs +26 -0
- package/src/remote/command.mjs +178 -0
- package/src/remote/ssh.mjs +59 -0
- package/src/repository-origin.mjs +81 -0
- package/src/reproduction/evidence-feedback.mjs +96 -0
- package/src/reproduction/incomplete-initialization.mjs +25 -0
- package/src/reproduction/lifecycle.mjs +253 -0
- package/src/reproduction/plan.mjs +132 -0
- package/src/reproduction/prompts.mjs +70 -0
- package/src/reproduction/runner.mjs +188 -0
- package/src/reproduction/summary.mjs +130 -0
- package/src/reproduction/workspace-mode.mjs +7 -0
- package/src/research/automatic-admission.mjs +156 -0
- package/src/research/compiler-coverage.mjs +85 -0
- package/src/research/compiler-failure.mjs +24 -0
- package/src/research/compiler-normalization-guards.mjs +112 -0
- package/src/research/compiler-repair.mjs +3 -0
- package/src/research/compiler.mjs +853 -0
- package/src/research/continuation-selection.mjs +26 -0
- package/src/research/execution-graph-context.mjs +43 -0
- package/src/research/experiment-importance.mjs +15 -0
- package/src/research/inventory-handoff.mjs +104 -0
- package/src/research/inventory-revisions.mjs +32 -0
- package/src/research/mineru-local.mjs +73 -0
- package/src/research/paper-command.mjs +19 -0
- package/src/research/paper-markdown.mjs +180 -0
- package/src/research/paper-source-map.mjs +69 -0
- package/src/research/planning-policy.mjs +88 -0
- package/src/research/reference-materials.mjs +11 -0
- package/src/research/reproduction-scope.mjs +30 -0
- package/src/research/research-map.mjs +94 -0
- package/src/research/research-objects.mjs +88 -0
- package/src/research/source-discovery.mjs +646 -0
- package/src/research/source-observations.mjs +75 -0
- package/src/research/source-review-cli-mcp.mjs +26 -0
- package/src/research/source-review-input.mjs +209 -0
- package/src/research/source-review-local-codex.mjs +36 -0
- package/src/research/source-review-model.mjs +70 -0
- package/src/research/source-review.mjs +173 -0
- package/src/research/structure.mjs +3163 -0
- package/src/research-card/renderer.mjs +277 -0
- package/src/research-card/verified-conclusion.mjs +143 -0
- package/src/results/output-registry.mjs +183 -0
- package/src/runtime/claude-code.mjs +52 -0
- package/src/runtime/codex-capacity-retry.mjs +87 -0
- package/src/runtime/codex.mjs +64 -0
- package/src/runtime/config.mjs +157 -0
- package/src/runtime/final-output.mjs +40 -0
- package/src/runtime/index.mjs +21 -0
- package/src/runtime/local-codex.mjs +74 -0
- package/src/runtime/opencode.mjs +95 -0
- package/src/runtime/prompt.mjs +13 -0
- package/src/sandbox/docker.mjs +363 -0
- package/src/settings/command.mjs +297 -0
- package/src/settings/store.mjs +119 -0
- package/src/telemetry/pricing.mjs +68 -0
- package/src/telemetry/usage.mjs +265 -0
- package/src/terminal/events.mjs +97 -0
- package/src/terminal/input.mjs +40 -0
- package/src/terminal/plain.mjs +40 -0
- package/src/terminal/remote-stream.mjs +22 -0
- package/src/terminal/screen.mjs +214 -0
- package/src/terminal/transcript.mjs +69 -0
- package/src/util.mjs +107 -0
- package/src/verification/ai-assessor.mjs +534 -0
- package/src/verification/claim-evaluator.mjs +242 -0
- package/src/verification/evidence-context.mjs +165 -0
- package/src/verification/evidence-reader.mjs +95 -0
- package/src/verification/integrity.mjs +570 -0
- package/src/verification/tolerance.mjs +32 -0
- package/src/workloads/cpu-research-preparation.mjs +56 -0
- package/src/workloads/definition.mjs +74 -0
- package/src/workloads/phase-aware-reproduction.mjs +46 -0
- package/src/workloads/reproduction.mjs +85 -0
- package/src/workspace/command.mjs +242 -0
- package/src/workspace/control.mjs +49 -0
- package/src/workspace/entry.mjs +28 -0
- package/src/workspace/input.mjs +93 -0
- package/src/workspace/interactive.mjs +94 -0
- package/src/workspace/jobs.mjs +418 -0
- package/src/workspace/session.mjs +97 -0
- package/src/workspace/worker.mjs +137 -0
- package/ui/arkgraph/ambient-motion.mjs +10 -0
- package/ui/arkgraph/app.jsx +153 -0
- package/ui/arkgraph/boot.js +6 -0
- package/ui/arkgraph/camera-motion.mjs +20 -0
- package/ui/arkgraph/context-reveal.mjs +39 -0
- package/ui/arkgraph/details.css +3 -0
- package/ui/arkgraph/entry.jsx +28 -0
- package/ui/arkgraph/experiment-curves.mjs +17 -0
- package/ui/arkgraph/experiment-selection.mjs +15 -0
- package/ui/arkgraph/experiment-style.css +26 -0
- package/ui/arkgraph/experiment-ui.jsx +32 -0
- package/ui/arkgraph/frame.html +1 -0
- package/ui/arkgraph/graph-gestures.mjs +62 -0
- package/ui/arkgraph/label-layout.mjs +57 -0
- package/ui/arkgraph/locales/en.json +229 -0
- package/ui/arkgraph/locales/source-types.json +15 -0
- package/ui/arkgraph/localization-build.mjs +27 -0
- package/ui/arkgraph/material-build.mjs +23 -0
- package/ui/arkgraph/material-colors.mjs +39 -0
- package/ui/arkgraph/material-style.css +15 -0
- package/ui/arkgraph/open-graph.jsx +326 -0
- package/ui/arkgraph/outline.jsx +49 -0
- package/ui/arkgraph/package-lock.json +888 -0
- package/ui/arkgraph/package.json +17 -0
- package/ui/arkgraph/reading-layout.mjs +130 -0
- package/ui/arkgraph/reading-presentation.mjs +73 -0
- package/ui/arkgraph/record-detail.css +51 -0
- package/ui/arkgraph/record-details.jsx +29 -0
- package/ui/arkgraph/research-types.mjs +31 -0
- package/ui/arkgraph/selection-mark.jsx +6 -0
- package/ui/arkgraph/soft-spine.mjs +26 -0
- package/ui/arkgraph/steering-style.css +187 -0
- package/ui/arkgraph/style.css +272 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import { GcpSecretManagerClient } from "../gcp/secret-manager.mjs";
|
|
4
|
+
import { shellQuote } from "../util.mjs";
|
|
5
|
+
|
|
6
|
+
const ROUTER_SOURCE = new URL("../network/autodl-routing-proxy.mjs", import.meta.url);
|
|
7
|
+
|
|
8
|
+
export async function resolveAutoDlManagedNetwork({ config, secretManager }) {
|
|
9
|
+
const resource = config.liguseSgTunnelSecretResource;
|
|
10
|
+
if (!resource) return null;
|
|
11
|
+
const resolver = secretManager ?? new GcpSecretManagerClient();
|
|
12
|
+
const raw = await resolver.accessVersion(resource);
|
|
13
|
+
return parseLiguseSgTunnelSecret(raw);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parseLiguseSgTunnelSecret(raw) {
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = JSON.parse(String(raw));
|
|
20
|
+
} catch {
|
|
21
|
+
throw new TypeError("LiguseSG 隧道 Secret 必须是 JSON");
|
|
22
|
+
}
|
|
23
|
+
const host = requiredText(value.host, "host", 255);
|
|
24
|
+
const username = requiredText(value.username, "username", 64);
|
|
25
|
+
const privateKey = requiredText(value.privateKey, "privateKey", 32 * 1024);
|
|
26
|
+
const knownHosts = requiredText(value.knownHosts, "knownHosts", 16 * 1024);
|
|
27
|
+
const port = positiveInteger(value.port, "port");
|
|
28
|
+
const remoteProxyPort = positiveInteger(value.remoteProxyPort ?? 18118, "remoteProxyPort");
|
|
29
|
+
if (!/^[a-z_][a-z0-9_-]*[$]?$/i.test(username)) {
|
|
30
|
+
throw new TypeError("LiguseSG 隧道 username 格式无效");
|
|
31
|
+
}
|
|
32
|
+
if (!privateKey.includes("BEGIN OPENSSH PRIVATE KEY")) {
|
|
33
|
+
throw new TypeError("LiguseSG 隧道 privateKey 不是 OpenSSH 私钥");
|
|
34
|
+
}
|
|
35
|
+
if (!/\bssh-(ed25519|rsa)\b/.test(knownHosts)) {
|
|
36
|
+
throw new TypeError("LiguseSG 隧道 knownHosts 缺少 SSH 主机公钥");
|
|
37
|
+
}
|
|
38
|
+
return { host, port, username, privateKey, knownHosts, remoteProxyPort };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function autoDlRoutingProxySource() {
|
|
42
|
+
return await readFile(ROUTER_SOURCE, "utf8");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildAutoDlNetworkRunnerScript({
|
|
46
|
+
workerPath,
|
|
47
|
+
routerPath,
|
|
48
|
+
keyPath,
|
|
49
|
+
knownHostsPath,
|
|
50
|
+
turboScript,
|
|
51
|
+
tunnel,
|
|
52
|
+
providerBaseUrl = "",
|
|
53
|
+
alwaysProxyHosts = [],
|
|
54
|
+
routerPort = 18080,
|
|
55
|
+
tunnelPort = 18081,
|
|
56
|
+
executionDirectory = "/job/execution",
|
|
57
|
+
}) {
|
|
58
|
+
const sshTarget = `${tunnel.username}@${tunnel.host}`;
|
|
59
|
+
return `#!/usr/bin/env bash
|
|
60
|
+
set -euo pipefail
|
|
61
|
+
|
|
62
|
+
WORKER=${shellQuote(workerPath)}
|
|
63
|
+
ROUTER=${shellQuote(routerPath)}
|
|
64
|
+
TUNNEL_KEY=${shellQuote(keyPath)}
|
|
65
|
+
KNOWN_HOSTS=${shellQuote(knownHostsPath)}
|
|
66
|
+
TURBO_SCRIPT=${shellQuote(turboScript)}
|
|
67
|
+
ROUTER_PORT=${routerPort}
|
|
68
|
+
TUNNEL_PORT=${tunnelPort}
|
|
69
|
+
EXECUTION_DIRECTORY=${shellQuote(executionDirectory)}
|
|
70
|
+
PROVIDER_BASE_URL=${shellQuote(providerBaseUrl)}
|
|
71
|
+
ALWAYS_PROXY_HOSTS=${shellQuote(alwaysProxyHosts.join(","))}
|
|
72
|
+
TUNNEL_PID=
|
|
73
|
+
ROUTER_PID=
|
|
74
|
+
|
|
75
|
+
cleanup_network() {
|
|
76
|
+
rm -f "$TUNNEL_KEY"
|
|
77
|
+
if [ -n "\${ROUTER_PID:-}" ] && kill -0 "$ROUTER_PID" 2>/dev/null; then
|
|
78
|
+
kill -TERM "$ROUTER_PID" 2>/dev/null || true
|
|
79
|
+
wait "$ROUTER_PID" 2>/dev/null || true
|
|
80
|
+
fi
|
|
81
|
+
if [ -n "\${TUNNEL_PID:-}" ] && kill -0 "$TUNNEL_PID" 2>/dev/null; then
|
|
82
|
+
kill -TERM "$TUNNEL_PID" 2>/dev/null || true
|
|
83
|
+
wait "$TUNNEL_PID" 2>/dev/null || true
|
|
84
|
+
fi
|
|
85
|
+
}
|
|
86
|
+
trap cleanup_network EXIT TERM INT
|
|
87
|
+
|
|
88
|
+
mkdir -p "$EXECUTION_DIRECTORY"
|
|
89
|
+
if [ ! -r "$TURBO_SCRIPT" ]; then
|
|
90
|
+
printf '%s\n' "AutoDL 学术加速脚本不存在:$TURBO_SCRIPT" >&2
|
|
91
|
+
exit 70
|
|
92
|
+
fi
|
|
93
|
+
set +u
|
|
94
|
+
. "$TURBO_SCRIPT" >/dev/null
|
|
95
|
+
set -u
|
|
96
|
+
TURBO_PROXY="\${https_proxy:-\${HTTPS_PROXY:-\${http_proxy:-\${HTTP_PROXY:-}}}}"
|
|
97
|
+
case "$TURBO_PROXY" in
|
|
98
|
+
http://*|https://*) ;;
|
|
99
|
+
*) printf '%s\n' "AutoDL 学术加速没有提供 http/https 代理" >&2; exit 70 ;;
|
|
100
|
+
esac
|
|
101
|
+
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy ALL_PROXY no_proxy NO_PROXY
|
|
102
|
+
|
|
103
|
+
ssh -N -T \
|
|
104
|
+
-L "127.0.0.1:$TUNNEL_PORT:127.0.0.1:${tunnel.remoteProxyPort}" \
|
|
105
|
+
-i "$TUNNEL_KEY" \
|
|
106
|
+
-p ${tunnel.port} \
|
|
107
|
+
-o BatchMode=yes \
|
|
108
|
+
-o ConnectTimeout=20 \
|
|
109
|
+
-o ConnectionAttempts=3 \
|
|
110
|
+
-o ExitOnForwardFailure=yes \
|
|
111
|
+
-o IdentitiesOnly=yes \
|
|
112
|
+
-o ServerAliveInterval=15 \
|
|
113
|
+
-o ServerAliveCountMax=3 \
|
|
114
|
+
-o StrictHostKeyChecking=yes \
|
|
115
|
+
-o UserKnownHostsFile="$KNOWN_HOSTS" \
|
|
116
|
+
${shellQuote(sshTarget)} >> "$EXECUTION_DIRECTORY/liguse-tunnel.log" 2>&1 &
|
|
117
|
+
TUNNEL_PID=$!
|
|
118
|
+
|
|
119
|
+
TUNNEL_READY=0
|
|
120
|
+
TUNNEL_READY_DEADLINE=$((SECONDS + 60))
|
|
121
|
+
while [ "$SECONDS" -lt "$TUNNEL_READY_DEADLINE" ]; do
|
|
122
|
+
kill -0 "$TUNNEL_PID" 2>/dev/null || {
|
|
123
|
+
printf '%s\n' "LiguseSG SSH 隧道启动失败" >&2
|
|
124
|
+
exit 70
|
|
125
|
+
}
|
|
126
|
+
if curl --proxy "http://127.0.0.1:$TUNNEL_PORT" --fail --silent \
|
|
127
|
+
--output /dev/null --connect-timeout 3 --max-time 10 \
|
|
128
|
+
https://www.google.com/generate_204; then
|
|
129
|
+
TUNNEL_READY=1
|
|
130
|
+
break
|
|
131
|
+
fi
|
|
132
|
+
sleep 0.5
|
|
133
|
+
done
|
|
134
|
+
if [ "$TUNNEL_READY" -ne 1 ]; then
|
|
135
|
+
printf '%s\n' "LiguseSG 受限公网出口在 60 秒内未就绪" >&2
|
|
136
|
+
exit 70
|
|
137
|
+
fi
|
|
138
|
+
rm -f "$TUNNEL_KEY"
|
|
139
|
+
|
|
140
|
+
env \
|
|
141
|
+
CITEARK_ROUTING_PROXY_HOST=127.0.0.1 \
|
|
142
|
+
CITEARK_ROUTING_PROXY_PORT="$ROUTER_PORT" \
|
|
143
|
+
CITEARK_AUTODL_TURBO_PROXY="$TURBO_PROXY" \
|
|
144
|
+
CITEARK_LIGUSE_SG_PROXY="http://127.0.0.1:$TUNNEL_PORT" \
|
|
145
|
+
CITEARK_ALWAYS_PROXY_HOSTS="$ALWAYS_PROXY_HOSTS" \
|
|
146
|
+
node "$ROUTER" >> "$EXECUTION_DIRECTORY/network-router.log" 2>&1 &
|
|
147
|
+
ROUTER_PID=$!
|
|
148
|
+
unset TURBO_PROXY
|
|
149
|
+
|
|
150
|
+
ROUTER_READY=0
|
|
151
|
+
ROUTER_READY_DEADLINE=$((SECONDS + 30))
|
|
152
|
+
while [ "$SECONDS" -lt "$ROUTER_READY_DEADLINE" ]; do
|
|
153
|
+
kill -0 "$ROUTER_PID" 2>/dev/null || {
|
|
154
|
+
printf '%s\n' "AutoDL 分域代理启动失败" >&2
|
|
155
|
+
exit 70
|
|
156
|
+
}
|
|
157
|
+
if curl --fail --silent --output /dev/null --connect-timeout 1 --max-time 2 \
|
|
158
|
+
"http://127.0.0.1:$ROUTER_PORT/__citeark_health"; then
|
|
159
|
+
ROUTER_READY=1
|
|
160
|
+
break
|
|
161
|
+
fi
|
|
162
|
+
sleep 0.25
|
|
163
|
+
done
|
|
164
|
+
if [ "$ROUTER_READY" -ne 1 ]; then
|
|
165
|
+
printf '%s\n' "AutoDL 分域代理在 30 秒内未就绪" >&2
|
|
166
|
+
exit 70
|
|
167
|
+
fi
|
|
168
|
+
|
|
169
|
+
PROXY_URL="http://127.0.0.1:$ROUTER_PORT"
|
|
170
|
+
export HTTP_PROXY="$PROXY_URL" HTTPS_PROXY="$PROXY_URL"
|
|
171
|
+
export http_proxy="$PROXY_URL" https_proxy="$PROXY_URL"
|
|
172
|
+
export ALL_PROXY="$PROXY_URL" all_proxy="$PROXY_URL"
|
|
173
|
+
export NO_PROXY="127.0.0.1,localhost,::1"
|
|
174
|
+
export no_proxy="$NO_PROXY"
|
|
175
|
+
export NODE_USE_ENV_PROXY=1
|
|
176
|
+
install -d -o node -g node -m 0755 /opt/citeark/cache/cargo /opt/citeark/cache/pip /opt/citeark/cache/uv
|
|
177
|
+
if [ -x /opt/citeark/venv/bin/python ]; then
|
|
178
|
+
if [ ! -e /opt/citeark/.baseline-readonly-v1 ]; then
|
|
179
|
+
chmod -R a-w /opt/citeark/venv
|
|
180
|
+
touch /opt/citeark/.baseline-readonly-v1
|
|
181
|
+
fi
|
|
182
|
+
TARGET_VIRTUAL_ENV=/job/runtime-venv
|
|
183
|
+
if [ ! -x /opt/citeark/create-runtime-venv.sh ]; then
|
|
184
|
+
printf '%s\n' "AutoDL 私有镜像缺少运行虚拟环境脚本" >&2
|
|
185
|
+
exit 70
|
|
186
|
+
fi
|
|
187
|
+
/opt/citeark/create-runtime-venv.sh "$TARGET_VIRTUAL_ENV"
|
|
188
|
+
export VIRTUAL_ENV="$TARGET_VIRTUAL_ENV"
|
|
189
|
+
export PATH="$TARGET_VIRTUAL_ENV/bin:/opt/citeark/venv/bin:$PATH"
|
|
190
|
+
export UV_PROJECT_ENVIRONMENT="$TARGET_VIRTUAL_ENV"
|
|
191
|
+
fi
|
|
192
|
+
export PIP_CACHE_DIR=/opt/citeark/cache/pip
|
|
193
|
+
export UV_CACHE_DIR=/opt/citeark/cache/uv
|
|
194
|
+
export UV_CONFIG_FILE=/dev/null
|
|
195
|
+
PYTHON_PACKAGE_INDEX="\${CITEARK_PYTHON_PACKAGE_INDEX:-https://pypi.tuna.tsinghua.edu.cn/simple}"
|
|
196
|
+
PYTHON_PACKAGE_FALLBACK_INDEX="\${CITEARK_PYTHON_PACKAGE_FALLBACK_INDEX:-https://mirrors.aliyun.com/pypi/simple}"
|
|
197
|
+
HUGGINGFACE_ENDPOINT="\${CITEARK_HUGGINGFACE_ENDPOINT:-https://hf-mirror.com}"
|
|
198
|
+
export PIP_INDEX_URL="$PYTHON_PACKAGE_INDEX"
|
|
199
|
+
export PIP_DEFAULT_TIMEOUT=60
|
|
200
|
+
export PIP_RETRIES=8
|
|
201
|
+
export UV_INDEX="$PYTHON_PACKAGE_INDEX"
|
|
202
|
+
export UV_DEFAULT_INDEX="$PYTHON_PACKAGE_FALLBACK_INDEX"
|
|
203
|
+
export UV_INDEX_STRATEGY=first-index
|
|
204
|
+
export UV_HTTP_TIMEOUT=60
|
|
205
|
+
export UV_HTTP_RETRIES=8
|
|
206
|
+
export PIP_FIND_LINKS=/opt/citeark/wheels
|
|
207
|
+
export UV_FIND_LINKS=/opt/citeark/wheels
|
|
208
|
+
export CARGO_HOME=/opt/citeark/cache/cargo
|
|
209
|
+
export CARGO_NET_GIT_FETCH_WITH_CLI=true
|
|
210
|
+
export HF_HOME=/job/runtime-cache/huggingface
|
|
211
|
+
export HF_ENDPOINT="$HUGGINGFACE_ENDPOINT"
|
|
212
|
+
export HF_HUB_ETAG_TIMEOUT=30
|
|
213
|
+
export HF_HUB_DOWNLOAD_TIMEOUT=120
|
|
214
|
+
export TORCH_HOME=/job/runtime-cache/torch
|
|
215
|
+
install -d -o node -g node -m 0700 "$HF_HOME" "$TORCH_HOME"
|
|
216
|
+
|
|
217
|
+
if ! node --help 2>&1 | grep -q -- '--use-env-proxy'; then
|
|
218
|
+
printf '%s\n' "AutoDL Node.js 运行时不支持全局环境代理" >&2
|
|
219
|
+
exit 70
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
probe() {
|
|
223
|
+
local name="$1"
|
|
224
|
+
local url attempt
|
|
225
|
+
shift
|
|
226
|
+
for url in "$@"; do
|
|
227
|
+
attempt=1
|
|
228
|
+
while [ "$attempt" -le 5 ]; do
|
|
229
|
+
if curl --proxy "$PROXY_URL" --fail --silent --show-error --location \
|
|
230
|
+
--retry 2 --retry-all-errors --retry-delay 1 --connect-timeout 10 \
|
|
231
|
+
--output /dev/null --max-time 30 "$url"; then
|
|
232
|
+
return 0
|
|
233
|
+
fi
|
|
234
|
+
if [ "$attempt" -lt 5 ]; then sleep "$attempt"; fi
|
|
235
|
+
attempt=$((attempt + 1))
|
|
236
|
+
done
|
|
237
|
+
printf '%s\n' "AutoDL 网络预检候选失败:$name $url" >&2
|
|
238
|
+
done
|
|
239
|
+
printf '%s\n' "AutoDL 网络预检失败:$name(所有候选传输均不可达)" >&2
|
|
240
|
+
exit 70
|
|
241
|
+
}
|
|
242
|
+
probe github https://github.com/
|
|
243
|
+
probe huggingface "$HUGGINGFACE_ENDPOINT/" https://huggingface.co/
|
|
244
|
+
probe python-index "$PYTHON_PACKAGE_INDEX/pip/" "$PYTHON_PACKAGE_FALLBACK_INDEX/pip/"
|
|
245
|
+
probe google https://www.google.com/generate_204
|
|
246
|
+
probe citeark https://citeark.co/api/health
|
|
247
|
+
if [ -n "$PROVIDER_BASE_URL" ]; then
|
|
248
|
+
if ! node --use-env-proxy --input-type=module -e '
|
|
249
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
250
|
+
for (let attempt = 1; attempt <= 5; attempt += 1) {
|
|
251
|
+
try {
|
|
252
|
+
const response = await fetch(process.argv[1], {
|
|
253
|
+
redirect: "manual",
|
|
254
|
+
signal: AbortSignal.timeout(20_000),
|
|
255
|
+
});
|
|
256
|
+
const reachable = response.status < 500;
|
|
257
|
+
await response.body?.cancel();
|
|
258
|
+
if (reachable) process.exit(0);
|
|
259
|
+
} catch {}
|
|
260
|
+
if (attempt < 5) await delay(attempt * 1_000);
|
|
261
|
+
}
|
|
262
|
+
process.exit(1);
|
|
263
|
+
' "$PROVIDER_BASE_URL"; then
|
|
264
|
+
printf '%s\n' "AutoDL 网络预检失败:Node.js 全局代理未能访问模型 API" >&2
|
|
265
|
+
exit 70
|
|
266
|
+
fi
|
|
267
|
+
fi
|
|
268
|
+
|
|
269
|
+
jq -nc \
|
|
270
|
+
--arg checkedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
271
|
+
'{schemaVersion:"0.1",status:"passed",checkedAt:$checkedAt,globalHttpProxy:true,nodeEnvProxy:true,routes:{github:"autodl-network-turbo-with-liguse-fallback",huggingface:"domestic-endpoint-with-official-turbo-fallback",google:"liguse-sg",openrouter:"liguse-sg",citeark:"direct-with-liguse-fallback",provider:"policy-routed",default:"direct-with-liguse-fallback"}}' \
|
|
272
|
+
> "$EXECUTION_DIRECTORY/network-preflight.json"
|
|
273
|
+
|
|
274
|
+
set +e
|
|
275
|
+
bash "$WORKER"
|
|
276
|
+
WORKER_EXIT=$?
|
|
277
|
+
set -e
|
|
278
|
+
exit "$WORKER_EXIT"
|
|
279
|
+
`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function requiredText(value, field, maximumLength) {
|
|
283
|
+
if (typeof value !== "string" || !value.trim() || value.length > maximumLength) {
|
|
284
|
+
throw new TypeError(`LiguseSG 隧道 ${field} 无效`);
|
|
285
|
+
}
|
|
286
|
+
return value.trim();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function positiveInteger(value, field) {
|
|
290
|
+
const numeric = Number(value);
|
|
291
|
+
if (!Number.isInteger(numeric) || numeric <= 0 || numeric > 65_535) {
|
|
292
|
+
throw new TypeError(`LiguseSG 隧道 ${field} 必须是有效端口`);
|
|
293
|
+
}
|
|
294
|
+
return numeric;
|
|
295
|
+
}
|