diff --git a/backend/src/distribution/file_format.rs b/backend/src/distribution/file_format.rs index 2087ad7..d7b6bc4 100644 --- a/backend/src/distribution/file_format.rs +++ b/backend/src/distribution/file_format.rs @@ -254,19 +254,9 @@ pub(super) struct DocumentProcessingFile { #[serde(default)] pub(super) allowed_operations: Vec, #[serde(default)] - pub(super) operation_policies: Vec, - #[serde(default)] pub(super) input_profiles: Vec, } -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub(super) struct ProcessingOperationPolicyFile { - pub(super) operation: ProcessingOperation, - #[serde(default)] - pub(super) required_typst_packages: Vec, -} - #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub(super) struct ProcessingInputProfilesFile { @@ -284,15 +274,6 @@ pub(super) struct ProcessingInputProfileFile { pub(super) description: LocalizedTextFile, } -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub(super) struct TypstPackageRequirementFile { - pub(super) namespace: String, - pub(super) name: String, - #[serde(default)] - pub(super) allowed_versions: Vec, -} - #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub(super) struct TypstFile { diff --git a/backend/src/distribution/loader.rs b/backend/src/distribution/loader.rs index 6052bfe..ac1c6b2 100644 --- a/backend/src/distribution/loader.rs +++ b/backend/src/distribution/loader.rs @@ -2,21 +2,18 @@ use super::ai_assistant::load_ai_assistant; use super::experience_content::load_experience; -use super::file_format::{ - DistributionFile, ProcessingInputProfilesFile, ProcessingOperationPolicyFile, -}; +use super::file_format::{DistributionFile, ProcessingInputProfilesFile}; use super::template_catalog::load_builtin_templates; use super::{ is_hex_color, read_template, resolve_distribution_file, resolve_path, validate_localized_text, validate_slug, CheckpointBranchPrefix, DistributionConfig, DocumentProcessingDistributionConfig, FrontendFeature, FrontendFeaturesConfig, GitConfig, - ProcessingOperationInputProfiles, ProcessingOperationPolicy, ProductAsset, ProductConfig, - CONFIG_SCHEMA_VERSION, MAX_PRODUCT_ASSET_BYTES, + ProcessingOperationInputProfiles, ProductAsset, ProductConfig, CONFIG_SCHEMA_VERSION, + MAX_PRODUCT_ASSET_BYTES, }; use crate::document_processing::{ ProcessingInputProfile, ProcessingInputProfileSelector, ProcessingOperation, }; -use crate::typst_runtime::TypstPackageRequirement; use crate::workspace::ProjectType; use std::collections::HashSet; use std::env; @@ -134,10 +131,6 @@ impl DistributionConfig { file.document_processing.allowed_operations, &project_types, )?; - let processing_operation_policies = validate_processing_operation_policies( - file.document_processing.operation_policies, - &processing_operations, - )?; let processing_input_profiles = validate_processing_input_profiles( file.document_processing.input_profiles, &processing_operations, @@ -205,7 +198,6 @@ impl DistributionConfig { ai_assistant, document_processing: DocumentProcessingDistributionConfig { allowed_operations: processing_operations, - operation_policies: processing_operation_policies, input_profiles: processing_input_profiles, }, experience, @@ -304,68 +296,6 @@ fn validate_processing_operations( Ok(normalized) } -fn validate_processing_operation_policies( - values: Vec, - allowed_operations: &[ProcessingOperation], -) -> Result, String> { - let mut policies = Vec::with_capacity(values.len()); - let mut operations = HashSet::new(); - for value in values { - if !allowed_operations.contains(&value.operation) { - return Err(format!( - "document_processing.operation_policies cannot configure disabled operation {}", - value.operation - )); - } - if value.operation.project_type() != Some(ProjectType::Typst) { - return Err(format!( - "document_processing.operation_policies cannot require Typst packages for {}", - value.operation - )); - } - if !operations.insert(value.operation) { - return Err(format!( - "document_processing.operation_policies repeats operation {}", - value.operation - )); - } - if value.required_typst_packages.is_empty() { - return Err(format!( - "document_processing.operation_policies for {} must contain a requirement", - value.operation - )); - } - let mut requirements = Vec::with_capacity(value.required_typst_packages.len()); - let mut identities = HashSet::new(); - for requirement in value.required_typst_packages { - let identity = format!("@{}/{}", requirement.namespace, requirement.name); - if !identities.insert(identity.clone()) { - return Err(format!( - "document_processing.operation_policies for {} repeats package {identity}", - value.operation - )); - } - let requirement = TypstPackageRequirement::parse( - requirement.namespace, - requirement.name, - requirement.allowed_versions, - ) - .ok_or_else(|| { - format!( - "document_processing.operation_policies for {} contains invalid package {identity}", - value.operation - ) - })?; - requirements.push(requirement); - } - policies.push(ProcessingOperationPolicy { - operation: value.operation, - required_typst_packages: requirements, - }); - } - Ok(policies) -} - fn validate_processing_input_profiles( values: Vec, allowed_operations: &[ProcessingOperation], diff --git a/backend/src/distribution/mod.rs b/backend/src/distribution/mod.rs index e6175ad..e0212e3 100644 --- a/backend/src/distribution/mod.rs +++ b/backend/src/distribution/mod.rs @@ -9,7 +9,6 @@ pub(crate) mod template_catalog; use crate::document_processing::{ProcessingInputProfileSelector, ProcessingOperation}; use crate::experience::{ExperienceResourceKind, ExperienceVisibility}; use crate::text_enum::text_enum; -use crate::typst_runtime::{TypstPackageRequirement, TypstProjectDependencies}; use crate::workspace::ProjectType; pub use ai_assistant::{AiAssistantConfig, AiConnectionPolicyKind, ManagedAiCatalogConfig}; use experience_content::{ExperienceConfig, ExperienceResource, LandingConfig, LandingHighlight}; @@ -138,16 +137,9 @@ pub struct FrontendFeaturesConfig { #[derive(Clone, Debug)] pub struct DocumentProcessingDistributionConfig { pub allowed_operations: Vec, - pub operation_policies: Vec, pub input_profiles: Vec, } -#[derive(Clone, Debug)] -pub struct ProcessingOperationPolicy { - pub operation: ProcessingOperation, - pub required_typst_packages: Vec, -} - #[derive(Clone, Debug)] pub struct ProcessingOperationInputProfiles { pub operation: ProcessingOperation, @@ -188,7 +180,6 @@ impl Default for DistributionConfig { ai_assistant: None, document_processing: DocumentProcessingDistributionConfig { allowed_operations: vec![ProcessingOperation::LatexCompilePdfV1], - operation_policies: Vec::new(), input_profiles: Vec::new(), }, experience: ExperienceConfig { @@ -276,30 +267,6 @@ impl DistributionConfig { .contains(&operation) } - pub(crate) fn processing_operation_applicable( - &self, - operation: ProcessingOperation, - dependencies: Option<&TypstProjectDependencies>, - ) -> bool { - let Some(policy) = self - .document_processing - .operation_policies - .iter() - .find(|policy| policy.operation == operation) - else { - return true; - }; - let Some(dependencies) = dependencies else { - return false; - }; - policy.required_typst_packages.iter().all(|requirement| { - dependencies - .packages - .iter() - .any(|package| requirement.matches(package)) - }) - } - pub(crate) fn processing_input_profile_selector( &self, operation: ProcessingOperation, @@ -369,13 +336,11 @@ fn is_hex_color(value: &str) -> bool { mod tests { use super::{ AiConnectionPolicyKind, CheckpointBranchPrefix, DistributionConfig, - InvalidCheckpointBranchPrefix, ProcessingOperationPolicy, + InvalidCheckpointBranchPrefix, }; use crate::document_processing::ProcessingOperation; use crate::experience::ExperienceVisibility; - use crate::typst_runtime::{PackageSpec, TypstPackageRequirement, TypstProjectDependencies}; use crate::workspace::ProjectType; - use std::collections::HashSet; use std::error::Error; use std::path::Path; use uuid::Uuid; @@ -464,51 +429,4 @@ mod tests { ); } } - - #[test] - fn processing_policy_matches_an_exact_reachable_typst_package( - ) -> Result<(), Box> { - let mut config = DistributionConfig::default(); - let requirement = TypstPackageRequirement::parse( - "local".to_string(), - "slides".to_string(), - vec!["0.7.0".to_string()], - ) - .ok_or("test package requirement is invalid")?; - config.document_processing.operation_policies = vec![ProcessingOperationPolicy { - operation: ProcessingOperation::TypstExportPptxV1, - required_typst_packages: vec![requirement], - }]; - let matching = TypstProjectDependencies { - packages: HashSet::from([PackageSpec::parse( - "local".to_string(), - "slides".to_string(), - "0.7.0".to_string(), - ) - .ok_or("matching test package spec is invalid")?]), - has_dynamic_imports: false, - }; - let wrong_version = TypstProjectDependencies { - packages: HashSet::from([PackageSpec::parse( - "local".to_string(), - "slides".to_string(), - "0.6.0".to_string(), - ) - .ok_or("wrong-version test package spec is invalid")?]), - has_dynamic_imports: false, - }; - - assert!(config.processing_operation_applicable( - ProcessingOperation::TypstExportPptxV1, - Some(&matching) - )); - assert!(!config.processing_operation_applicable( - ProcessingOperation::TypstExportPptxV1, - Some(&wrong_version) - )); - assert!( - config.processing_operation_applicable(ProcessingOperation::LatexCompilePdfV1, None) - ); - Ok(()) - } } diff --git a/backend/src/document_processing/project_input.rs b/backend/src/document_processing/project_input.rs index 57bd98b..5e7358d 100644 --- a/backend/src/document_processing/project_input.rs +++ b/backend/src/document_processing/project_input.rs @@ -3,7 +3,6 @@ use super::persistence::{pin_project_assets, release_project_asset_pins}; use super::ProcessingOperation; use crate::collaboration::{CollaborationContext, FlushProjectCollaborationError}; -use crate::distribution::DistributionConfig; use crate::object_storage::ObjectStorage; use crate::typst_runtime::{ analyze_project_dependencies, resolve_processing_package_closure, @@ -45,7 +44,6 @@ pub(super) struct TypstProjectBundleCapture<'a> { pub db: &'a PgPool, pub storage: Option<&'a ObjectStorage>, pub collaboration: &'a CollaborationContext, - pub distribution: &'a DistributionConfig, pub builtin_dir: &'a Path, pub operation: ProcessingOperation, pub job_id: Uuid, @@ -65,8 +63,6 @@ pub(super) enum CaptureProjectBundleError { TooManyFiles, #[error("project input exceeds the configured processing limit")] TooLarge, - #[error("project does not satisfy the processing operation policy")] - OperationInapplicable, #[error(transparent)] Package(#[from] ResolveProcessingPackagesError), #[error("collaboration state could not be captured")] @@ -173,7 +169,6 @@ pub(super) async fn capture_typst_project_bundle( db, storage, collaboration, - distribution, builtin_dir, operation, job_id, @@ -182,9 +177,7 @@ pub(super) async fn capture_typst_project_bundle( } = capture; let snapshot = capture_project_snapshot(db, collaboration, job_id, project_id).await?; let dependencies = analyze_project_dependencies(&snapshot.entry_file_path, &snapshot.documents); - let result = if !distribution.processing_operation_applicable(operation, Some(&dependencies)) { - Err(CaptureProjectBundleError::OperationInapplicable) - } else { + let result = match resolve_processing_package_closure(builtin_dir, &dependencies, max_input_bytes).await { Ok(packages) => { @@ -200,8 +193,7 @@ pub(super) async fn capture_typst_project_bundle( .await } Err(error) => Err(error.into()), - } - }; + }; release_pins(db, job_id).await; result } diff --git a/backend/src/document_processing/public_http.rs b/backend/src/document_processing/public_http.rs index 4c04a28..1590ae3 100644 --- a/backend/src/document_processing/public_http.rs +++ b/backend/src/document_processing/public_http.rs @@ -127,7 +127,6 @@ pub(crate) async fn create_typst_pptx_export( db: &state.db, storage: state.storage.as_ref(), collaboration: &state.collaboration, - distribution: &state.distribution, builtin_dir: &state.typst_builtin_dir, operation, job_id: reserved.job_id, @@ -608,14 +607,6 @@ pub(crate) async fn project_processing_capabilities( ProjectProcessingCapabilityState::Inapplicable, Some("dynamic_typst_dependency".to_string()), ) - } else if !state - .distribution - .processing_operation_applicable(operation, dependencies.as_ref()) - { - ( - ProjectProcessingCapabilityState::Inapplicable, - Some("required_typst_package_missing".to_string()), - ) } else { let stats = capability_stats(&state.db, operation) .await @@ -876,10 +867,6 @@ fn capture_failure(error: &CaptureProjectBundleError) -> (&'static str, &'static "input_too_large", "Project exceeds the processing input limit", ), - CaptureProjectBundleError::OperationInapplicable => ( - "operation_inapplicable", - "Project does not satisfy the processing operation policy", - ), CaptureProjectBundleError::Package( ResolveProcessingPackagesError::TooManyPackages | ResolveProcessingPackagesError::TooLarge, @@ -889,7 +876,7 @@ fn capture_failure(error: &CaptureProjectBundleError) -> (&'static str, &'static ), CaptureProjectBundleError::Package(ResolveProcessingPackagesError::DynamicDependency) => ( "dynamic_typst_dependency", - "Project contains a dynamic Typst package dependency", + "Project contains a dynamic Typst dependency", ), CaptureProjectBundleError::Package(_) => ( "package_capture_failed", @@ -927,11 +914,6 @@ fn capture_error(error: CaptureProjectBundleError) -> ApiError { "Project exceeds the processing input limit", ) } - CaptureProjectBundleError::OperationInapplicable => ApiError::new( - StatusCode::UNPROCESSABLE_ENTITY, - ApiErrorCode::ProcessingOperationInvalid, - "Project does not satisfy the processing operation policy", - ), CaptureProjectBundleError::Package( ResolveProcessingPackagesError::TooManyPackages | ResolveProcessingPackagesError::TooLarge, diff --git a/backend/src/typst_runtime/mod.rs b/backend/src/typst_runtime/mod.rs index dc5c54a..b71cd3a 100644 --- a/backend/src/typst_runtime/mod.rs +++ b/backend/src/typst_runtime/mod.rs @@ -11,7 +11,7 @@ mod universe; pub(crate) use dependencies::{analyze_project_dependencies, TypstProjectDependencies}; pub(crate) use http::{typst_builtin_asset, typst_package_proxy}; -pub(crate) use package::{PackageSpec, TypstPackageRequirement}; +pub(crate) use package::PackageSpec; pub(crate) use processing_packages::{ resolve_processing_package_closure, ResolveProcessingPackagesError, ResolvedTypstPackage, }; diff --git a/backend/src/typst_runtime/package.rs b/backend/src/typst_runtime/package.rs index 9cf5602..36b2a6c 100644 --- a/backend/src/typst_runtime/package.rs +++ b/backend/src/typst_runtime/package.rs @@ -44,65 +44,6 @@ impl PackageSpec { } } -#[derive(Clone, Debug, PartialEq, Eq)] -pub(crate) struct TypstPackageRequirement { - namespace: String, - name: String, - allowed_versions: Vec, -} - -impl TypstPackageRequirement { - pub(crate) fn parse( - namespace: String, - name: String, - allowed_versions: Vec, - ) -> Option { - let validation_version = allowed_versions - .first() - .cloned() - .unwrap_or_else(|| "0.0.0".to_string()); - PackageSpec::parse(namespace.clone(), name.clone(), validation_version)?; - let mut normalized_versions = Vec::with_capacity(allowed_versions.len()); - for version in allowed_versions { - let parsed = Version::parse(&version).ok()?; - if parsed.to_string() != version || !normalized_versions.insert_sorted_unique(version) { - return None; - } - } - Some(Self { - namespace, - name, - allowed_versions: normalized_versions, - }) - } - - pub(crate) fn matches(&self, package: &PackageSpec) -> bool { - self.namespace == package.namespace() - && self.name == package.name() - && (self.allowed_versions.is_empty() - || self - .allowed_versions - .iter() - .any(|version| version == package.version())) - } -} - -trait InsertSortedUnique { - fn insert_sorted_unique(&mut self, value: String) -> bool; -} - -impl InsertSortedUnique for Vec { - fn insert_sorted_unique(&mut self, value: String) -> bool { - match self.binary_search(&value) { - Ok(_) => false, - Err(index) => { - self.insert(index, value); - true - } - } - } -} - #[derive(Clone, Copy)] pub(super) struct PackageLimits { pub(super) max_archive_bytes: u64, diff --git a/backend/src/typst_runtime/processing_packages.rs b/backend/src/typst_runtime/processing_packages.rs index 0d9651e..1a602b1 100644 --- a/backend/src/typst_runtime/processing_packages.rs +++ b/backend/src/typst_runtime/processing_packages.rs @@ -31,7 +31,7 @@ pub(crate) struct ResolvedTypstPackageFile { #[derive(Debug, Error)] pub(crate) enum ResolveProcessingPackagesError { - #[error("Typst package dependency is dynamic and cannot be captured")] + #[error("Typst dependency is dynamic and cannot be captured")] DynamicDependency, #[error("Typst package closure contains too many packages")] TooManyPackages, diff --git a/docs/community/architecture/document-processing.md b/docs/community/architecture/document-processing.md index 182fbbe..98f0e07 100644 --- a/docs/community/architecture/document-processing.md +++ b/docs/community/architecture/document-processing.md @@ -269,8 +269,8 @@ without holding the editor still for the duration of a build. The manifest includes schema, project type, entry path, operation-relevant settings, Workspace version, content generation, and sorted file records with kind, length, and SHA-256. A Typst processing bundle additionally carries the -exact reachable `@local` and `@preview` package closure. Dynamic package -imports are rejected because they cannot produce a coherent immutable input. +exact reachable `@local` and `@preview` package closure. Dynamic imports are +rejected because they cannot produce a coherent immutable input. The `input_digest` covers the canonical manifest and all file and package content. It is distinct from the browser's local `CompileWorld` and from a user-created named snapshot. diff --git a/docs/community/configuration/distributions.md b/docs/community/configuration/distributions.md index ecdcda8..5ab45de 100644 --- a/docs/community/configuration/distributions.md +++ b/docs/community/configuration/distributions.md @@ -100,13 +100,11 @@ distribution loading. See the complete shape and ownership rules in `document_processing.allowed_operations` is a closed allowlist of Core-known, versioned operations. The default Community distribution enables `latex.compile.pdf/v1`; the generic PPTX operations remain available to other -distributions without embedding a converter in Core. Optional -`operation_policies` may require exact reachable Typst package identities and -versions for a project operation. This is product applicability, not worker -configuration: deployment TOML still binds identities to exact processor -contracts, and live availability requires a compatible healthy session. Do -not put worker identities, tokens, or implementation-specific configuration in -the distribution file. +distributions without embedding a converter in Core. This is product policy, +not worker configuration: deployment TOML still binds identities to exact +processor contracts, and live availability requires a compatible healthy +session. Do not put worker identities, tokens, or implementation-specific +configuration in the distribution file. `document_processing.input_profiles` may give PPTX import a small closed set of distribution-owned user choices, with localized labels and descriptions plus diff --git a/web/src/lib/i18n.ts b/web/src/lib/i18n.ts index cab4520..a4cefaf 100644 --- a/web/src/lib/i18n.ts +++ b/web/src/lib/i18n.ts @@ -87,8 +87,7 @@ const messages: Record> = { "processing.importPptxAction": "Import PPTX", "processing.pptxFile": "PowerPoint file", "processing.reason.workerOffline": "The converter is temporarily offline. The task will wait for capacity.", - "processing.reason.requiredPackageMissing": "This project does not use the package required by this converter.", - "processing.reason.dynamicDependency": "Package eligibility cannot be verified because this project uses a dynamic import.", + "processing.reason.dynamicDependency": "This project uses a dynamic import that cannot be captured for background processing.", "processing.reason.unavailable": "This conversion is unavailable for the current project.", "processing.openProject": "Open project", "processing.openProjectFailed": "Unable to open the imported project", @@ -997,8 +996,7 @@ const messages: Record> = { "processing.importPptxAction": "导入 PPTX", "processing.pptxFile": "PowerPoint 文件", "processing.reason.workerOffline": "转换服务暂时离线,任务会等待可用容量。", - "processing.reason.requiredPackageMissing": "当前项目没有使用此转换器要求的 Typst 包。", - "processing.reason.dynamicDependency": "项目使用了动态导入,无法验证所需 Typst 包。", + "processing.reason.dynamicDependency": "项目使用了后台处理无法捕获的动态导入。", "processing.reason.unavailable": "当前项目无法使用此转换能力。", "processing.openProject": "打开项目", "processing.openProjectFailed": "无法打开导入后的项目", diff --git a/web/src/pages/processing/model.ts b/web/src/pages/processing/model.ts index 4ee1d95..f54205e 100644 --- a/web/src/pages/processing/model.ts +++ b/web/src/pages/processing/model.ts @@ -41,8 +41,6 @@ export function processingCapabilityReasonLabel( switch (reason) { case "worker_temporarily_offline": return t("processing.reason.workerOffline"); - case "required_typst_package_missing": - return t("processing.reason.requiredPackageMissing"); case "dynamic_typst_dependency": return t("processing.reason.dynamicDependency"); default: diff --git a/workers/latex/processor-contract.json b/workers/latex/processor-contract.json index 4c491a2..44ea595 100644 --- a/workers/latex/processor-contract.json +++ b/workers/latex/processor-contract.json @@ -4,7 +4,7 @@ "input_schema": "project-bundle/v1", "adapter_revision": 1, "worker_sdk_protocol": 1, - "implementation_sha256": "34a3708cca599dd377b4cd083e158edde73b874a610de255dd019f958ecf7a65", + "implementation_sha256": "4d04985c773c86ce19809d22b6d2a72221bacb75d6d3175de0187c013e5da504", "runtime": { "image": "texlive/texlive@sha256:d39efa547acfa518072600315280f92357ca8e0b9e295e09b6ccd5f5d82a1373", "tex_live_release": "2026", diff --git a/workers/processing-sdk/src/input.rs b/workers/processing-sdk/src/input.rs index b7e36b1..2bb9667 100644 --- a/workers/processing-sdk/src/input.rs +++ b/workers/processing-sdk/src/input.rs @@ -125,6 +125,7 @@ fn verify_and_extract_project( let project_dir = root.path().join("project"); let packages_dir = root.path().join("packages"); fs::create_dir(&project_dir).map_err(InputError::Io)?; + fs::create_dir(&packages_dir).map_err(InputError::Io)?; let mut archive = zip::ZipArchive::new(Cursor::new(content)).map_err(|_| InputError::Archive)?; if archive.is_empty() || archive.len() > MAX_BUNDLE_FILES + 1 { @@ -492,6 +493,7 @@ mod tests { std::fs::read(verified.project_dir.join("main.tex"))?, b"Hello from LaTeX" ); + assert!(verified.packages_dir.is_dir()); Ok(()) }