"""Construct only the approved public demonstration files, with no runtime state or credentials.""" from pathlib import Path import shutil,json,hashlib,zipfile,re def build_space(source,target): source=Path(source).resolve();target=Path(target).resolve() if target.is_relative_to(source):raise ValueError('Build destination must be outside the source tree') target.mkdir(parents=True,exist_ok=True) if any(target.iterdir()):raise ValueError('Build destination must be empty') excluded={'.local-data','.test-data','__pycache__','.git','.secrets','.venv','node_modules','.workos-builds'} for p in source.rglob('*'): if not p.is_file():continue rel=p.relative_to(source) if any(x in excluded for x in rel.parts) or p.name.startswith('.env') or p.name in {'last-publication.json','last-smoke.json'} or p.suffix in {'.db','.sqlite','.log','.pyc','.pem','.key'}:continue dest=target/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(p,dest) # All admin frontend requests use the distinct management API. Local dual-port files remain intact. for p in (target/'AdminWeb').glob('*'): if p.suffix not in {'.js','.html'}:continue s=p.read_text(encoding='utf-8').replace('http://127.0.0.1:8868/','/').replace("fetch('/api/v1'","fetch((window.WORKOS_ADMIN_API_PREFIX||'/api/v1')") s=s.replace("fetch('/api/v1/auth/login'","fetch((window.WORKOS_ADMIN_API_PREFIX||'/api/v1')+'/auth/login'") s=s.replace("fetch('/api/v1/admin/knowledge/bases/'","fetch((window.WORKOS_ADMIN_API_PREFIX||'/api/v1')+'/admin/knowledge/bases/'") s=s.replace('http://127.0.0.1:8768/','/') if p.suffix=='.html':s=s.replace('','') p.write_text(s,encoding='utf-8') for p in (target/'EmployeeWeb').glob('*'): if p.suffix not in {'.js','.html'}:continue s=p.read_text(encoding='utf-8').replace('http://127.0.0.1:8769/','/manage').replace('http://127.0.0.1:8769','/manage') if p.suffix=='.html':s=s.replace('','') p.write_text(s,encoding='utf-8') # Visible disclosure on both surfaces; no request is sent to the user's local Qwen account. for folder in ['EmployeeWeb','AdminWeb']: p=target/folder/'index.html';s=p.read_text(encoding='utf-8') s=s.replace('','
公开演示 · 真实千问 · 访客数据独立 · 15分钟闲置后清理 · 请勿上传真实办公材料
') p.write_text(s,encoding='utf-8') connection=json.loads((target/'LLMGateway/connection.json').read_text(encoding='utf-8'));connection['mode']='real' (target/'LLMGateway/connection.json').write_text(json.dumps(connection,indent=2),encoding='utf-8') shutil.copyfile(source/'deploy/huggingface/Dockerfile',target/'Dockerfile') (target/'.dockerignore').write_text('.git\n**/.env*\n**/.local-data\n**/.test-data\n**/__pycache__\n**/*.db\n**/*.pyc\n',encoding='utf-8') (target/'README.md').write_text('''--- title: Work OS 智能办公平台 emoji: 🌐 colorFrom: purple colorTo: green sdk: docker app_port: 7860 pinned: false --- # Work OS 智能办公平台 · v0.8 平台演示 员工入口:本页;管理入口:[/manage](/manage)。员工 lin / demo123;管理员 admin / admin123。 本公开展示通过服务端 Space Secrets 连接真实千问模型,模型请求失败时明确报错,不自动退回演示桩。支持办公数据查询、知识检索与原文引用、数字员工画布、PDF生成,以及受限技能示例的测试、发布和复用。模型密钥只由服务端读取,浏览器不接触密钥。公开服务设有共享并发、排队和小时调用额度。 不同浏览器访客分配独立数据库。演示账户仅在该访客内部有效;最多8个访客、15分钟闲置后清理,容器重启会重置。单次请求512KiB,单会话120次写操作及32MiB存储上限。请勿上传真实办公材料。可查看钉钉、邮箱和会议连接目录;公开访客外部发送、通用 URL 接口与 MCP 禁用。 知识素材包括合成样例与保留出处、许可证的 Microsoft Writing Style Guide 改编材料(CC BY 4.0);详见 KnowledgeService/open_sources/ 与知识原文中的来源信息。 这是一份独立的公开演示源码,不包含本地用户附件、运行数据库和模型凭据。生产部署请参阅系统设计与任务审视文档。 ''',encoding='utf-8') readme=target/'README.md' readme.write_text(readme.read_text(encoding='utf-8').replace('\n ','\n'),encoding='utf-8') assert readme.read_text(encoding='utf-8').startswith('---\ntitle:') # Scan known local key bytes without printing or copying them. secretfile=source/'LLMGateway/.env.local' secrets=[] if secretfile.exists(): for line in secretfile.read_text(encoding='utf-8').splitlines(): if '=' in line and not line.startswith('#') and any(k in line.split('=',1)[0].upper() for k in ['API_KEY','TOKEN','SECRET','PASSWORD']): value=line.split('=',1)[1].strip().strip('"').strip("'") if len(value)>16:secrets.append(value.encode()) for p in target.rglob('*'): if p.is_file(): assert not re.search(rb'hf_[A-Za-z0-9]{25,}',p.read_bytes()),'Credential-like value found in public build' assert not any(secret in p.read_bytes() for secret in secrets),f'Secret in {p.name}' digest=hashlib.sha256() for p in sorted(target.rglob('*')): if p.is_file():digest.update(p.relative_to(target).as_posix().encode());digest.update(p.read_bytes()) manifest={'build_id':digest.hexdigest(),'public_demo_source':str(target),'files':sum(p.is_file() for p in target.rglob('*')),'known_secret_scan':'passed'} (target/'deployment-manifest.json').write_text(json.dumps({k:v for k,v in manifest.items() if k!='public_demo_source'},indent=2),encoding='utf-8') return manifest