foxclaw 0.1.0 → 0.1.3
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/README.md +54 -29
- package/bin/foxclaw.cjs +51 -0
- package/index.js +4 -10
- package/package.json +46 -38
- package/python/.dockerignore +35 -0
- package/python/.env.example +173 -0
- package/python/.gitattributes +46 -0
- package/python/.github/workflows/ci.yml +167 -0
- package/python/.github/workflows/release.yml +183 -0
- package/python/CHANGELOG.md +57 -0
- package/python/CHANGELOG_CN.md +57 -0
- package/python/Dockerfile +64 -0
- package/python/LICENSE +21 -0
- package/python/MANIFEST.in +14 -0
- package/python/README.md +201 -0
- package/python/README_CN.md +336 -0
- package/python/bench/bm25_audit.py +186 -0
- package/python/bench/bm25_regression.py +177 -0
- package/python/bench/bm25_stress.py +155 -0
- package/python/bench/cd_audit.py +215 -0
- package/python/bench/chaos.py +140 -0
- package/python/bench/concurrency.py +103 -0
- package/python/bench/e2e_real_models.py +94 -0
- package/python/bench/llm_retry_test.py +241 -0
- package/python/bench/load_test.py +193 -0
- package/python/bench/vector_ivf_upgrade.py +128 -0
- package/python/docs/CHANNELS.md +195 -0
- package/python/docs/GOVERNANCE.md +164 -0
- package/python/docs/RELEASE.md +110 -0
- package/python/docs/RUN.md +75 -0
- package/python/docs/RUN_CN.md +121 -0
- package/python/docs//351/205/215/347/275/256/346/214/207/345/215/227.md +152 -0
- package/python/evals/__init__.py +0 -0
- package/python/evals/governance/README.md +61 -0
- package/python/evals/governance/__init__.py +0 -0
- package/python/evals/governance/cases.py +115 -0
- package/python/evals/governance/compare_embeddings.py +94 -0
- package/python/evals/governance/convergence.svg +11 -0
- package/python/evals/governance/report.json +371 -0
- package/python/evals/governance/run_evals.py +368 -0
- package/python/examples/governance_middleware_demo.py +72 -0
- package/python/examples/langgraph_governance_demo.py +104 -0
- package/python/examples/sample_itinerary.csv +6 -0
- package/python/examples/sample_knowledge.csv +9 -0
- package/python/examples/sample_transactions.csv +14 -0
- package/python/foxclaw/__init__.py +408 -0
- package/python/foxclaw/agents/__init__.py +12 -0
- package/python/foxclaw/agents/agents.py +35 -0
- package/python/foxclaw/agents/base.py +794 -0
- package/python/foxclaw/agents/impl/__init__.py +1 -0
- package/python/foxclaw/agents/impl/_helpers.py +70 -0
- package/python/foxclaw/agents/impl/finance.py +231 -0
- package/python/foxclaw/agents/impl/office.py +350 -0
- package/python/foxclaw/agents/impl/supervisor.py +592 -0
- package/python/foxclaw/agents/mixins/_context.py +128 -0
- package/python/foxclaw/agents/mixins/augment.py +143 -0
- package/python/foxclaw/agents/mixins/llm.py +67 -0
- package/python/foxclaw/agents/mixins/memory.py +41 -0
- package/python/foxclaw/agents/mixins/preference.py +131 -0
- package/python/foxclaw/agents/mixins/prompt.py +71 -0
- package/python/foxclaw/agents/mixins/skillbox.py +58 -0
- package/python/foxclaw/agents/mixins/tool_exec.py +417 -0
- package/python/foxclaw/api/__init__.py +224 -0
- package/python/foxclaw/api/_state.py +43 -0
- package/python/foxclaw/api/bootstrap.py +96 -0
- package/python/foxclaw/api/middleware.py +294 -0
- package/python/foxclaw/api/routes/ahs.py +404 -0
- package/python/foxclaw/api/routes/attachments.py +116 -0
- package/python/foxclaw/api/routes/browser.py +35 -0
- package/python/foxclaw/api/routes/domain.py +306 -0
- package/python/foxclaw/api/routes/knowledge.py +145 -0
- package/python/foxclaw/api/routes/llm_admin.py +449 -0
- package/python/foxclaw/api/routes/memory.py +105 -0
- package/python/foxclaw/api/routes/orchestration.py +39 -0
- package/python/foxclaw/api/routes/recovery.py +44 -0
- package/python/foxclaw/api/routes/review.py +266 -0
- package/python/foxclaw/api/routes/search.py +33 -0
- package/python/foxclaw/api/routes/system.py +311 -0
- package/python/foxclaw/api/routes/task.py +263 -0
- package/python/foxclaw/api/routes/ws.py +64 -0
- package/python/foxclaw/api/spine.py +52 -0
- package/python/foxclaw/browser/__init__.py +13 -0
- package/python/foxclaw/browser/action/__init__.py +1 -0
- package/python/foxclaw/browser/action/action_executor.py +50 -0
- package/python/foxclaw/browser/action/action_types.py +44 -0
- package/python/foxclaw/browser/action/action_verifier.py +68 -0
- package/python/foxclaw/browser/action/url_policy.py +143 -0
- package/python/foxclaw/browser/adapter/__init__.py +1 -0
- package/python/foxclaw/browser/adapter/base_adapter.py +23 -0
- package/python/foxclaw/browser/adapter/web_adapter.py +46 -0
- package/python/foxclaw/browser/driver/__init__.py +1 -0
- package/python/foxclaw/browser/driver/base_driver.py +61 -0
- package/python/foxclaw/browser/driver/playwright_driver.py +170 -0
- package/python/foxclaw/browser/perception/__init__.py +1 -0
- package/python/foxclaw/browser/perception/dom_extractor.py +42 -0
- package/python/foxclaw/browser/perception/element_indexer.py +56 -0
- package/python/foxclaw/browser/perception/semantic_reducer.py +33 -0
- package/python/foxclaw/browser/perception/snapshot.py +29 -0
- package/python/foxclaw/browser/service.py +144 -0
- package/python/foxclaw/browser/session/__init__.py +1 -0
- package/python/foxclaw/browser/session/session_manager.py +57 -0
- package/python/foxclaw/capability/__init__.py +12 -0
- package/python/foxclaw/capability/embedding_service.py +65 -0
- package/python/foxclaw/channels/__init__.py +138 -0
- package/python/foxclaw/channels/discord.py +175 -0
- package/python/foxclaw/channels/dispatcher.py +179 -0
- package/python/foxclaw/channels/feishu.py +215 -0
- package/python/foxclaw/channels/openclaw_bridge.py +151 -0
- package/python/foxclaw/channels/signing.py +187 -0
- package/python/foxclaw/channels/telegram.py +120 -0
- package/python/foxclaw/channels/weixin.py +215 -0
- package/python/foxclaw/cli.py +183 -0
- package/python/foxclaw/cognitive/__init__.py +4 -0
- package/python/foxclaw/cognitive/reasoner.py +81 -0
- package/python/foxclaw/cognitive/state.py +141 -0
- package/python/foxclaw/core/__init__.py +9 -0
- package/python/foxclaw/core/audit_chain.py +131 -0
- package/python/foxclaw/core/audit_sink.py +100 -0
- package/python/foxclaw/core/compaction.py +265 -0
- package/python/foxclaw/core/config.py +65 -0
- package/python/foxclaw/core/confirm_nonce.py +151 -0
- package/python/foxclaw/core/dispatch.py +27 -0
- package/python/foxclaw/core/envfile.py +48 -0
- package/python/foxclaw/core/failure_policy.py +142 -0
- package/python/foxclaw/core/gateway.py +81 -0
- package/python/foxclaw/core/governance_audit.py +171 -0
- package/python/foxclaw/core/idempotency.py +282 -0
- package/python/foxclaw/core/injection_guard.py +202 -0
- package/python/foxclaw/core/memory_adapter.py +489 -0
- package/python/foxclaw/core/metrics.py +88 -0
- package/python/foxclaw/core/model_router.py +985 -0
- package/python/foxclaw/core/paths.py +103 -0
- package/python/foxclaw/core/recovery.py +349 -0
- package/python/foxclaw/core/scheduler.py +141 -0
- package/python/foxclaw/core/secrets.py +131 -0
- package/python/foxclaw/core/sessions.py +155 -0
- package/python/foxclaw/core/settings.py +414 -0
- package/python/foxclaw/core/shared_write.py +186 -0
- package/python/foxclaw/core/steering_queue.py +154 -0
- package/python/foxclaw/core/system_bus.py +84 -0
- package/python/foxclaw/core/thought_chain.py +316 -0
- package/python/foxclaw/core/token_meter.py +231 -0
- package/python/foxclaw/core/tools.py +164 -0
- package/python/foxclaw/core/tracing.py +375 -0
- package/python/foxclaw/core/truth_pipeline.py +110 -0
- package/python/foxclaw/core/update_check.py +149 -0
- package/python/foxclaw/core/vec_recall_adapter.py +477 -0
- package/python/foxclaw/core/verify.py +173 -0
- package/python/foxclaw/core/web_search.py +218 -0
- package/python/foxclaw/finance/__init__.py +15 -0
- package/python/foxclaw/finance/evidence.py +149 -0
- package/python/foxclaw/finance/fx.py +98 -0
- package/python/foxclaw/finance/graph.py +179 -0
- package/python/foxclaw/finance/models.py +146 -0
- package/python/foxclaw/finance/nlparse.py +515 -0
- package/python/foxclaw/finance/policy.py +301 -0
- package/python/foxclaw/finance/reasoner.py +121 -0
- package/python/foxclaw/finance/reasoning.py +319 -0
- package/python/foxclaw/finance/reconcile.py +175 -0
- package/python/foxclaw/finance/runtime.py +500 -0
- package/python/foxclaw/governance/__init__.py +24 -0
- package/python/foxclaw/governance/middleware.py +176 -0
- package/python/foxclaw/harness/__init__.py +17 -0
- package/python/foxclaw/harness/_base.py +66 -0
- package/python/foxclaw/harness/_policy.py +340 -0
- package/python/foxclaw/harness/drift.py +77 -0
- package/python/foxclaw/harness/event_bus.py +28 -0
- package/python/foxclaw/harness/harness.py +358 -0
- package/python/foxclaw/harness/loop_detection.py +145 -0
- package/python/foxclaw/itinerary/__init__.py +10 -0
- package/python/foxclaw/itinerary/amap_client.py +114 -0
- package/python/foxclaw/itinerary/models.py +80 -0
- package/python/foxclaw/itinerary/reasoner.py +96 -0
- package/python/foxclaw/itinerary/reasoning.py +168 -0
- package/python/foxclaw/itinerary/runtime.py +144 -0
- package/python/foxclaw/kernel/__init__.py +13 -0
- package/python/foxclaw/kernel/capabilities.py +72 -0
- package/python/foxclaw/kernel/policy_gate.py +108 -0
- package/python/foxclaw/kernel/process_manager.py +186 -0
- package/python/foxclaw/kernel/scheduler.py +125 -0
- package/python/foxclaw/kernel/sentinel.py +443 -0
- package/python/foxclaw/kernel/sentinel_client.py +243 -0
- package/python/foxclaw/kernel/spine.py +97 -0
- package/python/foxclaw/knowledge/__init__.py +360 -0
- package/python/foxclaw/knowledge/truth_crystallizer.py +89 -0
- package/python/foxclaw/learning/__init__.py +12 -0
- package/python/foxclaw/learning/knowledge_graph.py +144 -0
- package/python/foxclaw/learning/models.py +93 -0
- package/python/foxclaw/learning/reasoner.py +67 -0
- package/python/foxclaw/learning/runtime.py +351 -0
- package/python/foxclaw/learning/spaced_repetition.py +91 -0
- package/python/foxclaw/mcp_server.py +188 -0
- package/python/foxclaw/orchestration/__init__.py +167 -0
- package/python/foxclaw/pipeline/__init__.py +23 -0
- package/python/foxclaw/pipeline/cognitive_pipeline.py +429 -0
- package/python/foxclaw/pipeline/stage_meta.py +21 -0
- package/python/foxclaw/pipeline/supervisor_stages.py +201 -0
- package/python/foxclaw/planning/__init__.py +17 -0
- package/python/foxclaw/planning/llm_planner.py +232 -0
- package/python/foxclaw/planning/planner.py +94 -0
- package/python/foxclaw/search/__init__.py +24 -0
- package/python/foxclaw/search/agent_port.py +190 -0
- package/python/foxclaw/search/evidence.py +109 -0
- package/python/foxclaw/search/external_search.py +50 -0
- package/python/foxclaw/search/hkc_read_port.py +60 -0
- package/python/foxclaw/search/internal_search.py +71 -0
- package/python/foxclaw/search/models.py +127 -0
- package/python/foxclaw/search/planner.py +44 -0
- package/python/foxclaw/search/retriever.py +39 -0
- package/python/foxclaw/search/runtime.py +127 -0
- package/python/foxclaw/search/strategy.py +44 -0
- package/python/foxclaw/skills/__init__.py +559 -0
- package/python/foxclaw/skills/archive.py +111 -0
- package/python/foxclaw/skills/fetch.py +226 -0
- package/python/foxclaw/skills/hooks_spec.py +69 -0
- package/python/foxclaw/skills/install_cmd.py +216 -0
- package/python/foxclaw/skills/lifecycle.py +252 -0
- package/python/foxclaw/skills/markdown_skill.py +175 -0
- package/python/foxclaw/skills/markdown_store.py +39 -0
- package/python/foxclaw/skills/mcp_client.py +184 -0
- package/python/foxclaw/skills/mcp_store.py +40 -0
- package/python/foxclaw/skills/permission.py +145 -0
- package/python/foxclaw/skills/pipeline.py +354 -0
- package/python/foxclaw/skills/policy.py +74 -0
- package/python/foxclaw/skills/review.py +72 -0
- package/python/foxclaw/skills/store.py +57 -0
- package/python/frontend/assets/core_bg.jpg +0 -0
- package/python/frontend/deck/auth.js +25 -0
- package/python/frontend/deck/chat_model_picker.js +483 -0
- package/python/frontend/deck/domain.js +276 -0
- package/python/frontend/deck/main.js +1806 -0
- package/python/frontend/deck/markdown.js +44 -0
- package/python/frontend/deck/settings.js +307 -0
- package/python/frontend/deck/state.js +5 -0
- package/python/frontend/deck/util.js +4 -0
- package/python/frontend/deck/visuals.js +190 -0
- package/python/frontend/deck.css +855 -0
- package/python/frontend/deck.html +686 -0
- package/python/frontend/deck_v2.html +341 -0
- package/python/frontend/planet/index.html +266 -0
- package/python/frontend/planet/planet.css +579 -0
- package/python/frontend/planet/planet.js +1436 -0
- package/python/frontend/planet/vendor/three.core.min.js +6 -0
- package/python/frontend/planet/vendor/three.module.min.js +6 -0
- package/python/frontend/v3/assets/index-CQSBdxk4.js +34 -0
- package/python/frontend/v3/assets/index-D5nIsjms.css +1 -0
- package/python/frontend/v3/index.html +15 -0
- package/python/frontend/widget_runtime.js +252 -0
- package/python/frontend/widgets.js +639 -0
- package/python/frontend_src/index.html +14 -0
- package/python/frontend_src/package-lock.json +1376 -0
- package/python/frontend_src/package.json +19 -0
- package/python/frontend_src/src/App.vue +58 -0
- package/python/frontend_src/src/api.js +82 -0
- package/python/frontend_src/src/components/ChatDock.vue +365 -0
- package/python/frontend_src/src/components/ComposerMenu.vue +75 -0
- package/python/frontend_src/src/components/DocViewer.vue +162 -0
- package/python/frontend_src/src/components/Inspector.vue +235 -0
- package/python/frontend_src/src/components/LeftRail.vue +415 -0
- package/python/frontend_src/src/components/MenuPopover.vue +128 -0
- package/python/frontend_src/src/components/MessageStream.vue +389 -0
- package/python/frontend_src/src/components/ModelPicker.vue +350 -0
- package/python/frontend_src/src/components/QuickIngest.vue +112 -0
- package/python/frontend_src/src/components/Stage.vue +272 -0
- package/python/frontend_src/src/components/ToolMenu.vue +141 -0
- package/python/frontend_src/src/components/TopBar.vue +118 -0
- package/python/frontend_src/src/components/panels/ActivityPanel.vue +82 -0
- package/python/frontend_src/src/components/panels/AgentsPanel.vue +83 -0
- package/python/frontend_src/src/components/panels/KnowledgePanel.vue +425 -0
- package/python/frontend_src/src/components/panels/MemoryPanel.vue +117 -0
- package/python/frontend_src/src/components/panels/PanelBox.vue +50 -0
- package/python/frontend_src/src/components/panels/ReviewPanel.vue +292 -0
- package/python/frontend_src/src/components/panels/SettingsPanel.vue +358 -0
- package/python/frontend_src/src/components/panels/TasksPanel.vue +73 -0
- package/python/frontend_src/src/components/panels/ToolsPanel.vue +746 -0
- package/python/frontend_src/src/components/panels/UsagePanel.vue +105 -0
- package/python/frontend_src/src/lib/fmt.js +44 -0
- package/python/frontend_src/src/lib/i18n.js +53 -0
- package/python/frontend_src/src/lib/locales/en.js +173 -0
- package/python/frontend_src/src/lib/locales/zh.js +174 -0
- package/python/frontend_src/src/lib/md.js +190 -0
- package/python/frontend_src/src/main.js +9 -0
- package/python/frontend_src/src/stores/app.js +91 -0
- package/python/frontend_src/src/stores/chat.js +450 -0
- package/python/frontend_src/src/stores/model.js +96 -0
- package/python/frontend_src/src/stores/panels.js +289 -0
- package/python/frontend_src/src/stores/profile.js +31 -0
- package/python/frontend_src/src/stores/system.js +25 -0
- package/python/frontend_src/src/styles/base.css +138 -0
- package/python/frontend_src/src/styles/panel.css +117 -0
- package/python/frontend_src/src/styles/tokens.css +78 -0
- package/python/frontend_src/vite.config.js +39 -0
- package/python/pyproject.toml +268 -0
- package/python/requirements.txt +311 -0
- package/python/skills/README.md +123 -0
- package/python/skills/execution-contract/SKILL.md +30 -0
- package/python/skills/general-assistant/SKILL.md +34 -0
- package/python/skills/planner/SKILL.md +33 -0
- package/python/skills/schedule-itinerary/SKILL.md +35 -0
- package/python/skills/skill-composition/SKILL.md +31 -0
- package/python/skills/skill-guard/SKILL.md +67 -0
- package/python/skills/skill-memory/SKILL.md +50 -0
- package/python/skills/skill-router/SKILL.md +35 -0
- package/python/tests/conftest.py +54 -0
- package/python/tests/run_all.py +200 -0
- package/python/tests/test_agent_lifecycle.py +326 -0
- package/python/tests/test_ahs_p2.py +393 -0
- package/python/tests/test_anthropic_tools.py +192 -0
- package/python/tests/test_api.py +97 -0
- package/python/tests/test_api_auth.py +79 -0
- package/python/tests/test_api_host_guard.py +69 -0
- package/python/tests/test_attachments.py +151 -0
- package/python/tests/test_audit_chain.py +116 -0
- package/python/tests/test_audit_sink.py +130 -0
- package/python/tests/test_browser.py +149 -0
- package/python/tests/test_browser_request_guard.py +180 -0
- package/python/tests/test_capabilities.py +152 -0
- package/python/tests/test_channel_signing.py +185 -0
- package/python/tests/test_channel_trust.py +109 -0
- package/python/tests/test_channels.py +174 -0
- package/python/tests/test_cli.py +46 -0
- package/python/tests/test_compaction_toolpair.py +119 -0
- package/python/tests/test_config_layering.py +61 -0
- package/python/tests/test_confirm_nonce.py +186 -0
- package/python/tests/test_context_compaction_wiring.py +124 -0
- package/python/tests/test_dispatch.py +89 -0
- package/python/tests/test_domain_evals.py +334 -0
- package/python/tests/test_domain_import.py +72 -0
- package/python/tests/test_domain_reasoners.py +134 -0
- package/python/tests/test_e2e.py +161 -0
- package/python/tests/test_emb_cache.py +97 -0
- package/python/tests/test_embedding_singleton.py +87 -0
- package/python/tests/test_envfile.py +83 -0
- package/python/tests/test_evals_smoke.py +90 -0
- package/python/tests/test_event_spine.py +174 -0
- package/python/tests/test_evidence_semantic.py +88 -0
- package/python/tests/test_evidence_sse.py +94 -0
- package/python/tests/test_file_ingest.py +135 -0
- package/python/tests/test_finance.py +144 -0
- package/python/tests/test_finance_ledger.py +245 -0
- package/python/tests/test_finance_persist.py +174 -0
- package/python/tests/test_gateway.py +125 -0
- package/python/tests/test_governance.py +421 -0
- package/python/tests/test_governance_audit.py +324 -0
- package/python/tests/test_governance_middleware.py +137 -0
- package/python/tests/test_hkc.py +268 -0
- package/python/tests/test_hkc_index_build_manager.py +306 -0
- package/python/tests/test_hkc_manifest_reuse.py +294 -0
- package/python/tests/test_hkc_search_event_sync.py +482 -0
- package/python/tests/test_import_path_guard.py +155 -0
- package/python/tests/test_injection_guard.py +193 -0
- package/python/tests/test_integration.py +117 -0
- package/python/tests/test_itinerary.py +100 -0
- package/python/tests/test_kee_semantic.py +84 -0
- package/python/tests/test_kernel.py +212 -0
- package/python/tests/test_learning.py +101 -0
- package/python/tests/test_llm_admin.py +145 -0
- package/python/tests/test_llm_planner.py +344 -0
- package/python/tests/test_markdown_skills.py +62 -0
- package/python/tests/test_markdown_skills_openclaw.py +66 -0
- package/python/tests/test_mcp_connectors.py +97 -0
- package/python/tests/test_mcp_guardian_discovery.py +87 -0
- package/python/tests/test_mcp_no_memory.py +43 -0
- package/python/tests/test_mcp_policy_gate.py +76 -0
- package/python/tests/test_mcp_server.py +92 -0
- package/python/tests/test_memory_recall.py +92 -0
- package/python/tests/test_metrics.py +58 -0
- package/python/tests/test_multi_chain.py +90 -0
- package/python/tests/test_multimodal.py +122 -0
- package/python/tests/test_negotiation.py +136 -0
- package/python/tests/test_orchestration.py +109 -0
- package/python/tests/test_orchestration_decoupled.py +103 -0
- package/python/tests/test_p3_p5_hardening.py +324 -0
- package/python/tests/test_parallel_dispatch.py +207 -0
- package/python/tests/test_pipeline.py +492 -0
- package/python/tests/test_plan_visible.py +86 -0
- package/python/tests/test_planner.py +88 -0
- package/python/tests/test_policy_gate.py +108 -0
- package/python/tests/test_profile.py +67 -0
- package/python/tests/test_readme_claims.py +163 -0
- package/python/tests/test_reasoner.py +170 -0
- package/python/tests/test_release_check.py +252 -0
- package/python/tests/test_resume_checkpoint.py +148 -0
- package/python/tests/test_routing.py +85 -0
- package/python/tests/test_scheduler.py +138 -0
- package/python/tests/test_search.py +194 -0
- package/python/tests/test_secrets.py +153 -0
- package/python/tests/test_semantic.py +69 -0
- package/python/tests/test_sessions.py +90 -0
- package/python/tests/test_settings.py +265 -0
- package/python/tests/test_shadow_learning.py +290 -0
- package/python/tests/test_shared_write.py +200 -0
- package/python/tests/test_skill_taint_gate.py +145 -0
- package/python/tests/test_skills.py +117 -0
- package/python/tests/test_skills_fetch.py +282 -0
- package/python/tests/test_stats_and_events.py +162 -0
- package/python/tests/test_streaming.py +55 -0
- package/python/tests/test_supervisor_pipeline.py +176 -0
- package/python/tests/test_supervisor_triage.py +102 -0
- package/python/tests/test_taint.py +112 -0
- package/python/tests/test_task_stream.py +74 -0
- package/python/tests/test_thinking_sse.py +66 -0
- package/python/tests/test_thinking_stream.py +76 -0
- package/python/tests/test_tool_center.py +113 -0
- package/python/tests/test_tool_parallel.py +113 -0
- package/python/tests/test_tool_params.py +99 -0
- package/python/tests/test_tool_use.py +229 -0
- package/python/tests/test_toplevel_concurrency.py +116 -0
- package/python/tests/test_tracing.py +256 -0
- package/python/tests/test_truth_crystallizer.py +125 -0
- package/python/tests/test_truth_flow.py +88 -0
- package/python/tests/test_update_check.py +95 -0
- package/python/tests/test_url_policy.py +53 -0
- package/python/tests/test_verify_evidence.py +212 -0
- package/python/tests/test_version_sync.py +100 -0
- package/python/tests/test_web_trigger.py +82 -0
- package/python/tools/check_faiss_type.py +30 -0
- package/python/tools/check_log.ps1 +38 -0
- package/python/tools/ivf_status.py +72 -0
- package/python/tools/mypy_baseline.txt +13 -0
- package/python/tools/mypy_ratchet.py +143 -0
- package/python/tools/pack.py +173 -0
- package/python/tools/release_check.py +349 -0
- package/python/tools/restart_foxclaw.ps1 +71 -0
- package/python/tools/shared_write_audit.py +190 -0
- package/python/tools/size_baseline.txt +28 -0
- package/python/tools/size_check.py +102 -0
- package/python/tools/strip_comments.py +228 -0
- package/python/tools/verify_env.bat +2 -0
- package/python/tools/verify_env.py +25 -0
- package/python/vendor/HMR_LICENSE +37 -0
- package/python/vendor/HMR_README.md +65 -0
- package/python/vendor/hkc/LICENSE +37 -0
- package/python/vendor/hkc/hkc_ace/__init__.py +0 -0
- package/python/vendor/hkc/hkc_ace/ace.py +457 -0
- package/python/vendor/hkc/hkc_ace/skill_taxonomy.json +465 -0
- package/python/vendor/hkc/hkc_api/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/container.py +416 -0
- package/python/vendor/hkc/hkc_api/ingest_jobs.py +103 -0
- package/python/vendor/hkc/hkc_api/main.py +157 -0
- package/python/vendor/hkc/hkc_api/routes/__init__.py +0 -0
- package/python/vendor/hkc/hkc_api/routes/ability.py +151 -0
- package/python/vendor/hkc/hkc_api/routes/config.py +51 -0
- package/python/vendor/hkc/hkc_api/routes/knowledge.py +630 -0
- package/python/vendor/hkc/hkc_api/routes/search.py +88 -0
- package/python/vendor/hkc/hkc_api/schemas.py +153 -0
- package/python/vendor/hkc/hkc_api/synthesis.py +179 -0
- package/python/vendor/hkc/hkc_core/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/graph/base.py +188 -0
- package/python/vendor/hkc/hkc_core/graph/sqlite_store.py +789 -0
- package/python/vendor/hkc/hkc_core/models/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/models/enums.py +65 -0
- package/python/vendor/hkc/hkc_core/models/ku.py +307 -0
- package/python/vendor/hkc/hkc_core/utils/__init__.py +0 -0
- package/python/vendor/hkc/hkc_core/utils/id_gen.py +113 -0
- package/python/vendor/hkc/hkc_crystallizer/__init__.py +44 -0
- package/python/vendor/hkc/hkc_crystallizer/adapters.py +94 -0
- package/python/vendor/hkc/hkc_crystallizer/candidate.py +145 -0
- package/python/vendor/hkc/hkc_crystallizer/crystallizer.py +179 -0
- package/python/vendor/hkc/hkc_crystallizer/ingress.py +90 -0
- package/python/vendor/hkc/hkc_kde/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/chunker.py +197 -0
- package/python/vendor/hkc/hkc_kde/extractor.py +623 -0
- package/python/vendor/hkc/hkc_kde/kde.py +298 -0
- package/python/vendor/hkc/hkc_kde/loaders/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kde/loaders/ebook_loader.py +153 -0
- package/python/vendor/hkc/hkc_kde/loaders/office_loader.py +194 -0
- package/python/vendor/hkc/hkc_kde/loaders/pdf_loader.py +162 -0
- package/python/vendor/hkc/hkc_kde/loaders/text_loader.py +157 -0
- package/python/vendor/hkc/hkc_kde/loaders/web_loader.py +91 -0
- package/python/vendor/hkc/hkc_kde/models.py +74 -0
- package/python/vendor/hkc/hkc_kde/packager.py +329 -0
- package/python/vendor/hkc/hkc_kde/relation_disc.py +151 -0
- package/python/vendor/hkc/hkc_kee/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kee/dedup.py +227 -0
- package/python/vendor/hkc/hkc_kee/fingerprint.py +106 -0
- package/python/vendor/hkc/hkc_kee/kee.py +541 -0
- package/python/vendor/hkc/hkc_kep/__init__.py +0 -0
- package/python/vendor/hkc/hkc_kep/event_bus.py +205 -0
- package/python/vendor/hkc/hkc_sdk/__init__.py +63 -0
- package/python/vendor/hkc/hkc_sdk/base.py +151 -0
- package/python/vendor/hkc/hkc_sdk/direct_client.py +153 -0
- package/python/vendor/hkc/hkc_sdk/exceptions.py +39 -0
- package/python/vendor/hkc/hkc_sdk/http_client.py +166 -0
- package/python/vendor/hkc/hkc_sdk/models.py +171 -0
- package/python/vendor/hkc/hkc_search/__init__.py +0 -0
- package/python/vendor/hkc/hkc_search/bm25.py +325 -0
- package/python/vendor/hkc/hkc_search/embedding_backends.py +374 -0
- package/python/vendor/hkc/hkc_search/graph_search.py +132 -0
- package/python/vendor/hkc/hkc_search/hybrid.py +331 -0
- package/python/vendor/hkc/hkc_search/index_build_manager.py +378 -0
- package/python/vendor/hkc/hkc_search/vector_search.py +484 -0
- package/python/vendor/hmr/__init__.py +0 -0
- package/python/vendor/hmr/core/__init__.py +0 -0
- package/python/vendor/hmr/core/hmr.py +684 -0
- package/python/vendor/hmr/core/models.py +310 -0
- package/python/vendor/hmr/engines/__init__.py +0 -0
- package/python/vendor/hmr/engines/evolution.py +710 -0
- package/python/vendor/hmr/engines/jit_compiler.py +472 -0
- package/python/vendor/hmr/engines/lifecycle.py +264 -0
- package/python/vendor/hmr/engines/policy.py +625 -0
- package/python/vendor/hmr/engines/recall.py +260 -0
- package/python/vendor/hmr/engines/runtime_state.py +158 -0
- package/python/vendor/hmr/engines/scheduler.py +323 -0
- package/python/vendor/hmr/engines/semantic.py +150 -0
- package/python/vendor/hmr/engines/temporal.py +261 -0
- package/python/vendor/hmr/engines/thought_chain.py +635 -0
- package/python/vendor/hmr/graph/__init__.py +0 -0
- package/python/vendor/hmr/graph/cwg.py +338 -0
- package/python/vendor/hmr/graph/memory_graph.py +530 -0
- package/python/vendor/hmr/storage/__init__.py +0 -0
- package/python/vendor/hmr/storage/memory_fs.py +300 -0
- package/python/vendor/hmr/storage/vector_store.py +520 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""用户安装技能 + 内置技能启停覆盖的持久化。知识/记忆各有真源;技能注册表原为纯内存,
|
|
2
|
+
本层让"安装"重启不丢。文件:<data_dir>/user_skills.json。"""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import json
|
|
5
|
+
import threading
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from dataclasses import fields as _fields
|
|
8
|
+
|
|
9
|
+
from . import SkillSpec, SkillRegistry
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SkillStore:
|
|
13
|
+
def __init__(self, data_dir):
|
|
14
|
+
self._path = Path(data_dir) / "user_skills.json"
|
|
15
|
+
self._lock = threading.Lock()
|
|
16
|
+
|
|
17
|
+
def _spec_fields(self) -> set:
|
|
18
|
+
return {f.name for f in _fields(SkillSpec) if f.name != "handler"}
|
|
19
|
+
|
|
20
|
+
def load(self, registry: SkillRegistry):
|
|
21
|
+
"""启动恢复:注册用户技能 + 应用内置启停覆盖。文件缺失/损坏 → 静默跳过(全新库)。"""
|
|
22
|
+
if not self._path.exists():
|
|
23
|
+
return
|
|
24
|
+
try:
|
|
25
|
+
data = json.loads(self._path.read_text(encoding="utf-8"))
|
|
26
|
+
except Exception:
|
|
27
|
+
return
|
|
28
|
+
allowed = self._spec_fields()
|
|
29
|
+
for d in data.get("skills", []):
|
|
30
|
+
try:
|
|
31
|
+
spec = SkillSpec(**{k: v for k, v in d.items() if k in allowed})
|
|
32
|
+
spec.source = "user"
|
|
33
|
+
registry.register(spec)
|
|
34
|
+
except Exception:
|
|
35
|
+
continue
|
|
36
|
+
for sid, ov in (data.get("overrides") or {}).items():
|
|
37
|
+
sp = registry.get(sid)
|
|
38
|
+
if sp is not None and "enabled" in ov:
|
|
39
|
+
sp.enabled = bool(ov["enabled"])
|
|
40
|
+
|
|
41
|
+
def save(self, registry: SkillRegistry):
|
|
42
|
+
"""把用户技能 + 被改过 enabled 的内置技能原子写回。写盘失败不抛(内存注册仍生效)。"""
|
|
43
|
+
with self._lock:
|
|
44
|
+
user_skills, overrides = [], {}
|
|
45
|
+
for sp in registry.all_including_disabled():
|
|
46
|
+
if sp.source == "user":
|
|
47
|
+
user_skills.append(sp.to_dict())
|
|
48
|
+
elif sp.enabled is False:
|
|
49
|
+
overrides[sp.id] = {"enabled": False}
|
|
50
|
+
payload = {"skills": user_skills, "overrides": overrides}
|
|
51
|
+
try:
|
|
52
|
+
self._path.parent.mkdir(parents=True, exist_ok=True)
|
|
53
|
+
tmp = self._path.with_suffix(".tmp")
|
|
54
|
+
tmp.write_text(json.dumps(payload, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
55
|
+
tmp.replace(self._path)
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
if(window.__foxclawFetchPatched) return;
|
|
3
|
+
const _fetch=window.fetch.bind(window);
|
|
4
|
+
let _authHinted=false;
|
|
5
|
+
window.fetch=function(url,opts){
|
|
6
|
+
try{
|
|
7
|
+
const key=localStorage.getItem('foxclawApiKey');
|
|
8
|
+
const u=String(url||'');
|
|
9
|
+
if(key && (u.indexOf('/api')>=0 || u.indexOf('/knowledge')>=0 || u.indexOf('/stats')>=0)){
|
|
10
|
+
opts=opts||{}; opts.headers=Object.assign({}, opts.headers, {'X-API-Key':key});
|
|
11
|
+
}
|
|
12
|
+
}catch(e){}
|
|
13
|
+
const p=_fetch(url,opts);
|
|
14
|
+
try{
|
|
15
|
+
p.then(r=>{
|
|
16
|
+
if(r && r.status===401 && !_authHinted){
|
|
17
|
+
_authHinted=true;
|
|
18
|
+
if(typeof window.__foxclawAuthHint==='function') window.__foxclawAuthHint();
|
|
19
|
+
}
|
|
20
|
+
}).catch(()=>{});
|
|
21
|
+
}catch(e){}
|
|
22
|
+
return p;
|
|
23
|
+
};
|
|
24
|
+
window.__foxclawFetchPatched=true;
|
|
25
|
+
})();
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
|
|
2
|
+
const API_BASE = (typeof window !== 'undefined' && window.API_BASE) || '';
|
|
3
|
+
const _api = (p) => `${API_BASE}/api/llm${p}`;
|
|
4
|
+
|
|
5
|
+
let _models = { providers: [], custom: [], current: null };
|
|
6
|
+
let _menuOpen = false;
|
|
7
|
+
|
|
8
|
+
function _esc(s) {
|
|
9
|
+
return String(s == null ? '' : s)
|
|
10
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
11
|
+
.replace(/"/g, '"').replace(/'/g, ''');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function _normalizeBaseUrl(u) {
|
|
15
|
+
let s = String(u || '').trim();
|
|
16
|
+
if (!s) return s;
|
|
17
|
+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(s)) s = 'https://' + s;
|
|
18
|
+
let parsed;
|
|
19
|
+
try { parsed = new URL(s); } catch { return s; }
|
|
20
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return s;
|
|
21
|
+
let path = parsed.pathname.replace(/\/+$/, '');
|
|
22
|
+
if (!path) path = '/v1';
|
|
23
|
+
return `${parsed.protocol}//${parsed.host}${path}${parsed.search || ''}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const _MODEL_HINTS = [
|
|
27
|
+
{ re: /api\.deepseek\.com/i, hint: 'deepseek-chat', note: 'DeepSeek 官方 ID:deepseek-chat / deepseek-reasoner' },
|
|
28
|
+
{ re: /api\.openai\.com/i, hint: 'gpt-4o-mini', note: 'OpenAI 官方 ID:gpt-4o-mini / gpt-4o' },
|
|
29
|
+
{ re: /dashscope\.aliyuncs/i, hint: 'qwen-plus', note: '通义千问 ID:qwen-plus / qwen-max' },
|
|
30
|
+
{ re: /minimax/i, hint: 'MiniMax-Text-01', note: 'MiniMax ID:MiniMax-Text-01 / abab6.5s-chat' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function _hintForBaseUrl(u) {
|
|
34
|
+
const s = String(u || '');
|
|
35
|
+
for (const h of _MODEL_HINTS) if (h.re.test(s)) return h;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _isCustomCurrent() {
|
|
40
|
+
return _models.current && _models.current.source === 'custom';
|
|
41
|
+
}
|
|
42
|
+
function _isPresetCurrent() {
|
|
43
|
+
return _models.current && _models.current.source === 'preset';
|
|
44
|
+
}
|
|
45
|
+
function _autoCurrent() {
|
|
46
|
+
return !_models.current;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _currentLabel() {
|
|
50
|
+
if (_isCustomCurrent()) {
|
|
51
|
+
const m = _models.custom.find(m => m.name === _models.current.name);
|
|
52
|
+
return { name: m ? m.name : _models.current.name,
|
|
53
|
+
color: '#a78bfa', isCustom: true };
|
|
54
|
+
}
|
|
55
|
+
if (_isPresetCurrent()) {
|
|
56
|
+
const p = _models.providers.find(p => p.provider === _models.current.provider);
|
|
57
|
+
return { name: p ? p.label : _models.current.provider,
|
|
58
|
+
color: p ? p.color : '#7e93b8', isCustom: false };
|
|
59
|
+
}
|
|
60
|
+
return { name: 'Auto', color: '#7e93b8', isCustom: false };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function renderMenu() {
|
|
64
|
+
const menu = document.getElementById('chatModelMenu');
|
|
65
|
+
if (!menu) return;
|
|
66
|
+
const cur = _currentLabel();
|
|
67
|
+
let h = '';
|
|
68
|
+
|
|
69
|
+
h += `<div class="mp-item ${_autoCurrent() ? 'active' : ''}" data-act="auto">
|
|
70
|
+
<span class="mp-dot" style="background:#7e93b8"></span>
|
|
71
|
+
<span class="mp-name"><b>Auto</b><span>跟随 .env 默认</span></span>
|
|
72
|
+
${_autoCurrent() ? '<span class="mp-tag">当前</span>' : ''}
|
|
73
|
+
</div>`;
|
|
74
|
+
|
|
75
|
+
h += '<div class="mp-sep">预置</div>';
|
|
76
|
+
_models.providers.forEach(p => {
|
|
77
|
+
const isCur = _isPresetCurrent() && _models.current.provider === p.provider;
|
|
78
|
+
const isDis = !p.configured;
|
|
79
|
+
h += `<div class="mp-item ${isCur ? 'active' : ''} ${isDis ? 'disabled' : ''}" data-act="preset" data-prov="${_esc(p.provider)}">
|
|
80
|
+
<span class="mp-dot" style="background:${p.color};box-shadow:0 0 6px ${p.color}"></span>
|
|
81
|
+
<span class="mp-name"><b>${_esc(p.label)}</b><span>${_esc(p.provider)}</span></span>
|
|
82
|
+
${isCur ? '<span class="mp-tag mp-cur">当前</span>' :
|
|
83
|
+
isDis ? '<span class="mp-tag mp-warn">未配置</span>' : ''}
|
|
84
|
+
</div>`;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (_models.custom.length) {
|
|
88
|
+
h += '<div class="mp-sep">自定义</div>';
|
|
89
|
+
_models.custom.forEach(m => {
|
|
90
|
+
const isCur = _isCustomCurrent() && _models.current.name === m.name;
|
|
91
|
+
h += `<div class="mp-item ${isCur ? 'active' : ''}" data-act="custom" data-name="${_esc(m.name)}">
|
|
92
|
+
<span class="mp-dot" style="background:#a78bfa;box-shadow:0 0 6px #a78bfa"></span>
|
|
93
|
+
<span class="mp-name"><b>${_esc(m.name)}</b><span>${_esc(m.model)}</span></span>
|
|
94
|
+
<span class="mp-tag mp-cur${isCur ? '' : ' hidden'}">当前</span>
|
|
95
|
+
<span class="mp-tag mp-edit" title="编辑(key / base_url / group_id / 模型 ID)">✎</span>
|
|
96
|
+
<span class="mp-tag mp-del" title="删除">✕</span>
|
|
97
|
+
</div>`;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
h += `<div class="mp-foot">
|
|
102
|
+
<button class="mp-btn" data-foot="add">+ 添加自定义模型</button>
|
|
103
|
+
<button class="mp-btn" data-foot="env">📂 打开配置文件</button>
|
|
104
|
+
</div>`;
|
|
105
|
+
|
|
106
|
+
menu.innerHTML = h;
|
|
107
|
+
|
|
108
|
+
menu.querySelectorAll('.mp-item').forEach(el => {
|
|
109
|
+
el.addEventListener('click', (e) => {
|
|
110
|
+
if (e.target.classList.contains('mp-del')) {
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
const name = el.dataset.name;
|
|
113
|
+
if (confirm(`删除自定义模型「${name}」?`)) deleteCustom(name);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (e.target.classList.contains('mp-edit')) {
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
editCustom(el.dataset.name);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const act = el.dataset.act;
|
|
122
|
+
if (act === 'auto') selectModel('auto', null, null);
|
|
123
|
+
else if (act === 'preset') selectModel('preset', el.dataset.prov, null);
|
|
124
|
+
else if (act === 'custom') selectModel('custom', null, el.dataset.name);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
menu.querySelectorAll('.mp-foot .mp-btn').forEach(btn => {
|
|
128
|
+
btn.addEventListener('click', (e) => {
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
if (btn.dataset.foot === 'add') openAddDialog();
|
|
131
|
+
else if (btn.dataset.foot === 'env') window.open('/.env', '_blank');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function renderPill() {
|
|
137
|
+
const cur = _currentLabel();
|
|
138
|
+
const dot = document.getElementById('chatModelDot');
|
|
139
|
+
const name = document.getElementById('chatModelName');
|
|
140
|
+
if (dot) dot.style.cssText = `background:${cur.color};box-shadow:0 0 6px ${cur.color}`;
|
|
141
|
+
if (name) name.textContent = cur.name;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function loadModels() {
|
|
145
|
+
try {
|
|
146
|
+
const r = await fetch(_api('/models'));
|
|
147
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
148
|
+
_models = await r.json();
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.warn('[chat_model_picker] load /models failed', e);
|
|
151
|
+
_models = { providers: [], custom: [], current: null };
|
|
152
|
+
}
|
|
153
|
+
renderPill();
|
|
154
|
+
renderMenu();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function selectModel(source, provider, name) {
|
|
158
|
+
try {
|
|
159
|
+
const body = { source };
|
|
160
|
+
if (source === 'preset' && provider) body.provider = provider;
|
|
161
|
+
if (source === 'custom' && name) body.name = name;
|
|
162
|
+
const r = await fetch(_api('/select'), {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'Content-Type': 'application/json' },
|
|
165
|
+
body: JSON.stringify(body),
|
|
166
|
+
});
|
|
167
|
+
if (!r.ok) {
|
|
168
|
+
let msg = `HTTP ${r.status}`;
|
|
169
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
170
|
+
alert(`切换失败: ${msg}`);
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const j = await r.json();
|
|
174
|
+
_models.current = j.current;
|
|
175
|
+
_menuOpen = false;
|
|
176
|
+
document.getElementById('chatModelMenu')?.classList.remove('show');
|
|
177
|
+
renderPill();
|
|
178
|
+
renderMenu();
|
|
179
|
+
return true;
|
|
180
|
+
} catch (e) {
|
|
181
|
+
alert(`切换失败: ${e.message || e}`);
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function deleteCustom(name) {
|
|
187
|
+
try {
|
|
188
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`), { method: 'DELETE' });
|
|
189
|
+
if (!r.ok) { alert('删除失败'); return; }
|
|
190
|
+
await loadModels();
|
|
191
|
+
} catch (e) { alert(`删除失败: ${e.message || e}`); }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function addCustom(payload) {
|
|
195
|
+
const r = await fetch(_api('/custom/add'), {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
headers: { 'Content-Type': 'application/json' },
|
|
198
|
+
body: JSON.stringify(payload),
|
|
199
|
+
});
|
|
200
|
+
if (!r.ok) {
|
|
201
|
+
let msg = `HTTP ${r.status}`;
|
|
202
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
203
|
+
throw new Error(msg);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function getCustom(name) {
|
|
208
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`));
|
|
209
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
210
|
+
return r.json();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function updateCustom(name, payload) {
|
|
214
|
+
const r = await fetch(_api(`/custom/${encodeURIComponent(name)}`), {
|
|
215
|
+
method: 'PUT',
|
|
216
|
+
headers: { 'Content-Type': 'application/json' },
|
|
217
|
+
body: JSON.stringify(payload),
|
|
218
|
+
});
|
|
219
|
+
if (!r.ok) {
|
|
220
|
+
let msg = `HTTP ${r.status}`;
|
|
221
|
+
try { const j = await r.json(); msg = j.detail || JSON.stringify(j); } catch {}
|
|
222
|
+
throw new Error(msg);
|
|
223
|
+
}
|
|
224
|
+
return r.json();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function editCustom(name) {
|
|
228
|
+
try {
|
|
229
|
+
const m = await getCustom(name);
|
|
230
|
+
openAddDialog('edit', { ...m, _editingName: name });
|
|
231
|
+
} catch (e) {
|
|
232
|
+
alert(`加载详情失败: ${e.message || e}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function testModel(source, provider, name) {
|
|
237
|
+
const body = { source };
|
|
238
|
+
if (source === 'preset' && provider) body.provider = provider;
|
|
239
|
+
if (source === 'custom' && name) body.name = name;
|
|
240
|
+
const r = await fetch(_api('/test'), {
|
|
241
|
+
method: 'POST',
|
|
242
|
+
headers: { 'Content-Type': 'application/json' },
|
|
243
|
+
body: JSON.stringify(body),
|
|
244
|
+
});
|
|
245
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
246
|
+
return r.json();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let _cmMode = 'add'; // 'add' | 'edit'
|
|
250
|
+
let _cmEditingName = null; // edit 模式下的原名(PUT URL 用);改名后仍指向磁盘上那条记录
|
|
251
|
+
|
|
252
|
+
function openAddDialog(mode = 'add', preset = null) {
|
|
253
|
+
_cmMode = mode;
|
|
254
|
+
_cmEditingName = (mode === 'edit' && preset)
|
|
255
|
+
? (preset._editingName || preset.name)
|
|
256
|
+
: null;
|
|
257
|
+
|
|
258
|
+
const mask = document.getElementById('cmAddMask');
|
|
259
|
+
if (!mask) return;
|
|
260
|
+
|
|
261
|
+
const title = document.getElementById('cmAddTitle');
|
|
262
|
+
if (title) {
|
|
263
|
+
title.textContent = mode === 'edit' && preset?.name
|
|
264
|
+
? `编辑自定义模型 · ${preset.name}`
|
|
265
|
+
: '添加自定义模型';
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const set = (id, v) => { const el = document.getElementById(id); if (el) el.value = v || ''; };
|
|
269
|
+
set('cm_name', preset?.name);
|
|
270
|
+
set('cm_base_url', preset?.base_url);
|
|
271
|
+
set('cm_api_key', '');
|
|
272
|
+
set('cm_model', preset?.model);
|
|
273
|
+
set('cm_group_id', preset?.group_id);
|
|
274
|
+
set('cm_extra_headers', preset?.extra_headers && Object.keys(preset.extra_headers).length
|
|
275
|
+
? JSON.stringify(preset.extra_headers) : '');
|
|
276
|
+
set('cm_note', preset?.note);
|
|
277
|
+
_applyModelHint(preset?.base_url);
|
|
278
|
+
|
|
279
|
+
const keyInp = document.getElementById('cm_api_key');
|
|
280
|
+
if (keyInp) {
|
|
281
|
+
keyInp.placeholder = (mode === 'edit' && preset?.has_key)
|
|
282
|
+
? '留空保持原值;填入则覆盖'
|
|
283
|
+
: '请输入 API Key';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const msg = document.getElementById('cm_msg');
|
|
287
|
+
if (msg) { msg.textContent = ''; msg.className = 'cm-msg'; }
|
|
288
|
+
mask.classList.add('show');
|
|
289
|
+
setTimeout(() => document.getElementById('cm_name')?.focus(), 50);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function _modelWarning(baseUrl, modelId) {
|
|
293
|
+
const s = String(baseUrl || ''), m = String(modelId || '').trim();
|
|
294
|
+
if (!m) return '';
|
|
295
|
+
if (/api\.deepseek\.com/i.test(s) && !/^deepseek-(chat|reasoner)$/.test(m))
|
|
296
|
+
return `⚠ DeepSeek 官方没有「${m}」,应填 deepseek-chat 或 deepseek-reasoner`;
|
|
297
|
+
return '';
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function _applyModelHint(baseUrl) {
|
|
301
|
+
const hint = _hintForBaseUrl(baseUrl);
|
|
302
|
+
const inp = document.getElementById('cm_model');
|
|
303
|
+
if (inp) inp.placeholder = hint ? `例:${hint.hint}` : '例:MiniMax-Text-01';
|
|
304
|
+
const sub = document.getElementById('cmAddSubHint');
|
|
305
|
+
if (sub) {
|
|
306
|
+
const warn = _modelWarning(baseUrl, inp?.value);
|
|
307
|
+
sub.textContent = warn || (hint ? hint.note : '');
|
|
308
|
+
sub.style.color = warn ? '#e0685a' : '#e0a45c';
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function closeAddDialog() {
|
|
313
|
+
document.getElementById('cmAddMask')?.classList.remove('show');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function _setMsg(text, kind) {
|
|
317
|
+
const msg = document.getElementById('cm_msg');
|
|
318
|
+
if (!msg) return;
|
|
319
|
+
msg.textContent = text;
|
|
320
|
+
msg.className = 'cm-msg' + (kind ? ' cm-msg-' + kind : '');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function _readForm() {
|
|
324
|
+
const v = (id) => (document.getElementById(id)?.value || '').trim();
|
|
325
|
+
const out = {
|
|
326
|
+
name: v('cm_name'),
|
|
327
|
+
base_url: _normalizeBaseUrl(v('cm_base_url')),
|
|
328
|
+
api_key: v('cm_api_key'),
|
|
329
|
+
model: v('cm_model'),
|
|
330
|
+
group_id: v('cm_group_id'),
|
|
331
|
+
note: v('cm_note'),
|
|
332
|
+
};
|
|
333
|
+
const raw = v('cm_extra_headers');
|
|
334
|
+
if (raw) {
|
|
335
|
+
try {
|
|
336
|
+
const parsed = JSON.parse(raw);
|
|
337
|
+
if (typeof parsed === 'object' && parsed && !Array.isArray(parsed)) {
|
|
338
|
+
out.extra_headers = parsed;
|
|
339
|
+
} else { throw new Error('必须是 JSON object'); }
|
|
340
|
+
} catch (e) {
|
|
341
|
+
throw new Error(`额外 header JSON 不合法: ${e.message}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function _onSave() {
|
|
348
|
+
try {
|
|
349
|
+
const payload = _readForm();
|
|
350
|
+
if (!payload.name || !payload.base_url || !payload.model) {
|
|
351
|
+
_setMsg('请填全 * 号必填项', 'err');
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (_cmMode === 'add' && !payload.api_key) {
|
|
355
|
+
_setMsg('add 模式必须填 API KEY(edit 模式可留空保留原值)', 'err');
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
_setMsg('保存中…', 'info');
|
|
359
|
+
let savedName = payload.name;
|
|
360
|
+
if (_cmMode === 'add') {
|
|
361
|
+
await addCustom(payload);
|
|
362
|
+
savedName = payload.name;
|
|
363
|
+
} else {
|
|
364
|
+
const r = await updateCustom(_cmEditingName, payload);
|
|
365
|
+
savedName = r.name;
|
|
366
|
+
_cmEditingName = r.name;
|
|
367
|
+
}
|
|
368
|
+
await loadModels();
|
|
369
|
+
_setMsg('已保存,正在切换…', 'info');
|
|
370
|
+
const ok = await selectModel('custom', null, savedName);
|
|
371
|
+
_setMsg(ok ? `已保存并切换到 ${savedName}` : `已保存 ${savedName},但切换失败(见弹窗)`,
|
|
372
|
+
ok ? 'ok' : 'err');
|
|
373
|
+
setTimeout(closeAddDialog, 600);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
_setMsg(`保存失败: ${e.message || e}`, 'err');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function _onTest() {
|
|
380
|
+
try {
|
|
381
|
+
const payload = _readForm();
|
|
382
|
+
if (!payload.base_url || !payload.model) {
|
|
383
|
+
_setMsg('请先填 BASE URL / 模型 ID 再测', 'err');
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (_cmMode === 'edit') {
|
|
387
|
+
_setMsg(`测试已保存配置(${_cmEditingName})…`, 'info');
|
|
388
|
+
const r = await testModel('custom', null, _cmEditingName);
|
|
389
|
+
if (r.ok) {
|
|
390
|
+
_setMsg(`✓ 连通 (${r.latency_ms} ms, model=${r.model}, reply="${(r.reply || '').slice(0, 30)}")`, 'ok');
|
|
391
|
+
} else {
|
|
392
|
+
_setMsg(`✗ 连通失败: ${(r.error || '').slice(0, 200)}\n(测的是已保存配置;要测表单里的新值请先点「保存」)`, 'err');
|
|
393
|
+
}
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (!payload.name || !payload.api_key) {
|
|
397
|
+
_setMsg('add 模式请先填「模型名称」+「API KEY」再测试', 'err');
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
_setMsg('保存并测试中…', 'info');
|
|
401
|
+
await addCustom(payload);
|
|
402
|
+
const r = await testModel('custom', null, payload.name);
|
|
403
|
+
if (r.ok) {
|
|
404
|
+
await loadModels();
|
|
405
|
+
await selectModel('custom', null, payload.name);
|
|
406
|
+
_setMsg(`✓ 连通 (${r.latency_ms} ms, model=${r.model}) — 已切换`, 'ok');
|
|
407
|
+
} else {
|
|
408
|
+
_setMsg(`✗ 连通失败: ${(r.error || '').slice(0, 200)}\n(已为你保留,可手动改后再测或删除)`, 'err');
|
|
409
|
+
}
|
|
410
|
+
await loadModels();
|
|
411
|
+
} catch (e) {
|
|
412
|
+
_setMsg(`测试失败: ${e.message || e}`, 'err');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function bindEvents() {
|
|
417
|
+
const pill = document.getElementById('chatModelPill');
|
|
418
|
+
const menu = document.getElementById('chatModelMenu');
|
|
419
|
+
if (pill && menu) {
|
|
420
|
+
pill.addEventListener('click', (e) => {
|
|
421
|
+
e.stopPropagation();
|
|
422
|
+
_menuOpen = !_menuOpen;
|
|
423
|
+
menu.classList.toggle('show', _menuOpen);
|
|
424
|
+
});
|
|
425
|
+
document.addEventListener('click', (e) => {
|
|
426
|
+
if (!_menuOpen) return;
|
|
427
|
+
if (e.target.closest('#chatModelPick')) return;
|
|
428
|
+
_menuOpen = false;
|
|
429
|
+
menu.classList.remove('show');
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
const closeBtn = document.getElementById('cmAddClose');
|
|
433
|
+
const cancelBtn = document.getElementById('cm_cancel');
|
|
434
|
+
const saveBtn = document.getElementById('cm_save');
|
|
435
|
+
const testBtn = document.getElementById('cm_test');
|
|
436
|
+
const eyeBtn = document.getElementById('cm_eye');
|
|
437
|
+
const mask = document.getElementById('cmAddMask');
|
|
438
|
+
if (closeBtn) closeBtn.addEventListener('click', closeAddDialog);
|
|
439
|
+
if (cancelBtn) cancelBtn.addEventListener('click', closeAddDialog);
|
|
440
|
+
if (saveBtn) saveBtn.addEventListener('click', _onSave);
|
|
441
|
+
if (testBtn) testBtn.addEventListener('click', _onTest);
|
|
442
|
+
if (eyeBtn) {
|
|
443
|
+
eyeBtn.addEventListener('click', () => {
|
|
444
|
+
const inp = document.getElementById('cm_api_key');
|
|
445
|
+
if (!inp) return;
|
|
446
|
+
inp.type = inp.type === 'password' ? 'text' : 'password';
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (mask) {
|
|
450
|
+
mask.addEventListener('click', (e) => {
|
|
451
|
+
if (e.target === mask) closeAddDialog();
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const baseInp = document.getElementById('cm_base_url');
|
|
455
|
+
if (baseInp) {
|
|
456
|
+
baseInp.addEventListener('blur', () => {
|
|
457
|
+
const v = baseInp.value.trim();
|
|
458
|
+
if (!v) return;
|
|
459
|
+
baseInp.value = _normalizeBaseUrl(v);
|
|
460
|
+
_applyModelHint(baseInp.value);
|
|
461
|
+
});
|
|
462
|
+
baseInp.addEventListener('input', () => _applyModelHint(baseInp.value));
|
|
463
|
+
}
|
|
464
|
+
const modelInp = document.getElementById('cm_model');
|
|
465
|
+
if (modelInp) modelInp.addEventListener('input', () => _applyModelHint(baseInp?.value));
|
|
466
|
+
document.addEventListener('keydown', (e) => {
|
|
467
|
+
if (e.key === 'Escape') {
|
|
468
|
+
if (mask?.classList.contains('show')) closeAddDialog();
|
|
469
|
+
if (_menuOpen) { _menuOpen = false; menu?.classList.remove('show'); }
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
(function init() {
|
|
475
|
+
bindEvents();
|
|
476
|
+
loadModels();
|
|
477
|
+
window.addEventListener('storage', (e) => {
|
|
478
|
+
if (e.key === '__foxclaw_model_changed__') loadModels();
|
|
479
|
+
});
|
|
480
|
+
setInterval(() => {
|
|
481
|
+
if (_menuOpen) loadModels();
|
|
482
|
+
}, 5000);
|
|
483
|
+
})();
|