myagent-ai 1.0.0
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/Dockerfile +30 -0
- package/README.md +333 -0
- package/agents/__init__.py +6 -0
- package/agents/__pycache__/main_agent.cpython-312.pyc +0 -0
- package/agents/base.py +115 -0
- package/agents/main_agent.py +695 -0
- package/agents/memory_agent.py +313 -0
- package/agents/tool_agent.py +248 -0
- package/chatbot/__init__.py +5 -0
- package/chatbot/base.py +124 -0
- package/chatbot/discord_bot.py +146 -0
- package/chatbot/feishu_bot.py +548 -0
- package/chatbot/manager.py +164 -0
- package/chatbot/qq_bot.py +189 -0
- package/chatbot/telegram_bot.py +167 -0
- package/chatbot/wechat_bot.py +558 -0
- package/communication/__init__.py +66 -0
- package/communication/channel.py +576 -0
- package/communication/crypto.py +347 -0
- package/communication/manager.py +397 -0
- package/communication/peer.py +156 -0
- package/config.py +464 -0
- package/core/__init__.py +10 -0
- package/core/config_broadcast.py +276 -0
- package/core/llm.py +878 -0
- package/core/logger.py +241 -0
- package/core/task_queue.py +362 -0
- package/core/utils.py +184 -0
- package/executor/__init__.py +4 -0
- package/executor/__pycache__/engine.cpython-312.pyc +0 -0
- package/executor/engine.py +1215 -0
- package/groups/__init__.py +15 -0
- package/groups/manager.py +724 -0
- package/knowledge/__init__.py +4 -0
- package/knowledge/rag.py +444 -0
- package/main.py +801 -0
- package/memory/__init__.py +4 -0
- package/memory/manager.py +840 -0
- package/organization/__init__.py +4 -0
- package/organization/manager.py +350 -0
- package/package.json +58 -0
- package/requirements.txt +59 -0
- package/setup.py +40 -0
- package/skills/ASR/LICENSE.txt +21 -0
- package/skills/ASR/SKILL.md +580 -0
- package/skills/ASR/scripts/asr.ts +27 -0
- package/skills/LLM/LICENSE.txt +21 -0
- package/skills/LLM/SKILL.md +856 -0
- package/skills/LLM/scripts/chat.ts +32 -0
- package/skills/TTS/LICENSE.txt +21 -0
- package/skills/TTS/SKILL.md +735 -0
- package/skills/TTS/tts.ts +25 -0
- package/skills/VLM/LICENSE.txt +21 -0
- package/skills/VLM/SKILL.md +588 -0
- package/skills/VLM/scripts/vlm.ts +57 -0
- package/skills/__init__.py +5 -0
- package/skills/agent-browser/SKILL.md +328 -0
- package/skills/ai-news-collectors/SKILL.md +157 -0
- package/skills/ai-news-collectors/_meta.json +6 -0
- package/skills/ai-news-collectors/references/sources.md +128 -0
- package/skills/aminer-open-academic/SKILL.md +312 -0
- package/skills/aminer-open-academic/_meta.json +6 -0
- package/skills/aminer-open-academic/evals/evals.json +46 -0
- package/skills/aminer-open-academic/references/api-catalog.md +1032 -0
- package/skills/aminer-open-academic/scripts/__pycache__/aminer_client.cpython-312.pyc +0 -0
- package/skills/aminer-open-academic/scripts/aminer_client.py +875 -0
- package/skills/auto-target-tracker/SKILL.md +317 -0
- package/skills/base.py +147 -0
- package/skills/blog-writer/2024-02-17-radical-transparency-sales.md +35 -0
- package/skills/blog-writer/2024-02-17-raycast-spotlight-superpowers.md +33 -0
- package/skills/blog-writer/2024-02-17-short-form-content-marketing.md +47 -0
- package/skills/blog-writer/2024-02-17-typing-speed-benefits.md +33 -0
- package/skills/blog-writer/2024-03-14-effective-ai-prompts.md +55 -0
- package/skills/blog-writer/2024-11-08-ai-revolutionizing-entry-level-sales.md +43 -0
- package/skills/blog-writer/2025-11-12-why-ai-art-is-useless.md +49 -0
- package/skills/blog-writer/README.md +2 -0
- package/skills/blog-writer/SKILL.md +158 -0
- package/skills/blog-writer/__pycache__/manage_examples.cpython-312.pyc +0 -0
- package/skills/blog-writer/_meta.json +6 -0
- package/skills/blog-writer/manage_examples.py +90 -0
- package/skills/blog-writer/style-guide.md +160 -0
- package/skills/browser_skill.py +146 -0
- package/skills/coding-agent/SKILL.md +120 -0
- package/skills/coding-agent/_meta.json +6 -0
- package/skills/coding-agent/criteria.md +48 -0
- package/skills/coding-agent/execution.md +42 -0
- package/skills/coding-agent/memory-template.md +38 -0
- package/skills/coding-agent/planning.md +31 -0
- package/skills/coding-agent/state.md +60 -0
- package/skills/coding-agent/verification.md +39 -0
- package/skills/content-strategy/SKILL.md +181 -0
- package/skills/content-strategy/_meta.json +6 -0
- package/skills/contentanalysis/ExtractWisdom/SKILL.md +229 -0
- package/skills/contentanalysis/ExtractWisdom/Workflows/Extract.md +60 -0
- package/skills/contentanalysis/SKILL.md +14 -0
- package/skills/docx/CHANGELOG.md +85 -0
- package/skills/docx/LICENSE.txt +30 -0
- package/skills/docx/SKILL.md +455 -0
- package/skills/docx/docx-js.md +681 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/docx/ooxml/scripts/__pycache__/pack.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/__pycache__/unpack.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/__pycache__/validate.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/pack.py +159 -0
- package/skills/docx/ooxml/scripts/unpack.py +29 -0
- package/skills/docx/ooxml/scripts/validate.py +69 -0
- package/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/base.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/docx.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/pptx.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/__pycache__/redlining.cpython-312.pyc +0 -0
- package/skills/docx/ooxml/scripts/validation/base.py +951 -0
- package/skills/docx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/docx/ooxml.md +615 -0
- package/skills/docx/scripts/__init__.py +1 -0
- package/skills/docx/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/add_toc_placeholders.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/document.cpython-312.pyc +0 -0
- package/skills/docx/scripts/__pycache__/utilities.cpython-312.pyc +0 -0
- package/skills/docx/scripts/add_toc_placeholders.py +220 -0
- package/skills/docx/scripts/document.py +1302 -0
- package/skills/docx/scripts/templates/comments.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/skills/docx/scripts/templates/people.xml +3 -0
- package/skills/docx/scripts/utilities.py +374 -0
- package/skills/dream-interpreter/SKILL.md +88 -0
- package/skills/dream-interpreter/assets/example_asset.txt +24 -0
- package/skills/dream-interpreter/references/api_reference.md +34 -0
- package/skills/dream-interpreter/references/interpretation-guide.md +83 -0
- package/skills/dream-interpreter/references/output-schema.md +65 -0
- package/skills/dream-interpreter/references/questioning-strategy.md +62 -0
- package/skills/dream-interpreter/references/visual-mapping.md +81 -0
- package/skills/dream-interpreter/scripts/__pycache__/example.cpython-312.pyc +0 -0
- package/skills/dream-interpreter/scripts/example.py +19 -0
- package/skills/dream-interpreter/skill.json +7 -0
- package/skills/file_skill.py +246 -0
- package/skills/finance/Finance_API_Doc.md +445 -0
- package/skills/finance/SKILL.md +53 -0
- package/skills/fullstack-dev/SKILL.md +205 -0
- package/skills/get-fortune-analysis/SKILL.md +370 -0
- package/skills/get-fortune-analysis/lunar_python.py +91 -0
- package/skills/gift-evaluator/SKILL.md +83 -0
- package/skills/gift-evaluator/__pycache__/html_tools.cpython-312.pyc +0 -0
- package/skills/gift-evaluator/html_tools.py +268 -0
- package/skills/image-edit/LICENSE.txt +21 -0
- package/skills/image-edit/SKILL.md +896 -0
- package/skills/image-edit/scripts/image-edit.ts +36 -0
- package/skills/image-generation/LICENSE.txt +21 -0
- package/skills/image-generation/SKILL.md +583 -0
- package/skills/image-generation/scripts/image-generation.ts +28 -0
- package/skills/image-understand/LICENSE.txt +21 -0
- package/skills/image-understand/SKILL.md +855 -0
- package/skills/image-understand/scripts/image-understand.ts +41 -0
- package/skills/interview-designer/README.md +70 -0
- package/skills/interview-designer/SKILL.md +53 -0
- package/skills/interview-designer/_meta.json +6 -0
- package/skills/interview-designer/references/design_rationale.md +43 -0
- package/skills/interview-designer/templates/interview_guide_template.md +62 -0
- package/skills/market-research-reports/SKILL.md +901 -0
- package/skills/market-research-reports/assets/FORMATTING_GUIDE.md +428 -0
- package/skills/market-research-reports/assets/market_report_template.tex +1380 -0
- package/skills/market-research-reports/assets/market_research.sty +564 -0
- package/skills/market-research-reports/references/data_analysis_patterns.md +548 -0
- package/skills/market-research-reports/references/report_structure_guide.md +999 -0
- package/skills/market-research-reports/references/visual_generation_guide.md +1077 -0
- package/skills/market-research-reports/scripts/__pycache__/generate_market_visuals.cpython-312.pyc +0 -0
- package/skills/market-research-reports/scripts/generate_market_visuals.py +529 -0
- package/skills/marketing-mode/README.md +49 -0
- package/skills/marketing-mode/SKILL.md +693 -0
- package/skills/marketing-mode/_meta.json +6 -0
- package/skills/marketing-mode/mode-prompt.md +39 -0
- package/skills/marketing-mode/skill.json +51 -0
- package/skills/mindfulness-meditation/SKILL.md +65 -0
- package/skills/mindfulness-meditation/_meta.json +6 -0
- package/skills/multi-search-engine/CHANGELOG.md +15 -0
- package/skills/multi-search-engine/CHANNELLOG.md +48 -0
- package/skills/multi-search-engine/SKILL.md +78 -0
- package/skills/multi-search-engine/_meta.json +6 -0
- package/skills/multi-search-engine/config.json +14 -0
- package/skills/multi-search-engine/metadata.json +7 -0
- package/skills/multi-search-engine/references/international-search.md +651 -0
- package/skills/pdf/LICENSE.txt +30 -0
- package/skills/pdf/SKILL.md +1534 -0
- package/skills/pdf/forms.md +205 -0
- package/skills/pdf/reference.md +765 -0
- package/skills/pdf/scripts/__pycache__/add_zai_metadata.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_bounding_boxes.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_bounding_boxes_test.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/check_fillable_fields.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/convert_pdf_to_images.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/create_validation_image.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/extract_form_field_info.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/fill_fillable_fields.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/fill_pdf_form_with_annotations.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/__pycache__/sanitize_code.cpython-312.pyc +0 -0
- package/skills/pdf/scripts/add_zai_metadata.py +172 -0
- package/skills/pdf/scripts/check_bounding_boxes.py +70 -0
- package/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
- package/skills/pdf/scripts/check_fillable_fields.py +12 -0
- package/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
- package/skills/pdf/scripts/create_validation_image.py +41 -0
- package/skills/pdf/scripts/extract_form_field_info.py +152 -0
- package/skills/pdf/scripts/fill_fillable_fields.py +114 -0
- package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
- package/skills/pdf/scripts/sanitize_code.py +110 -0
- package/skills/podcast-generate/LICENSE.txt +21 -0
- package/skills/podcast-generate/SKILL.md +198 -0
- package/skills/podcast-generate/generate.ts +661 -0
- package/skills/podcast-generate/package.json +30 -0
- package/skills/podcast-generate/readme.md +177 -0
- package/skills/podcast-generate/test_data/segments.jsonl +3 -0
- package/skills/podcast-generate/tsconfig.json +26 -0
- package/skills/pptx/LICENSE.txt +30 -0
- package/skills/pptx/SKILL.md +507 -0
- package/skills/pptx/html2pptx.md +625 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/pptx/ooxml/scripts/__pycache__/pack.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/__pycache__/unpack.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/__pycache__/validate.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/pack.py +159 -0
- package/skills/pptx/ooxml/scripts/unpack.py +29 -0
- package/skills/pptx/ooxml/scripts/validate.py +69 -0
- package/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/base.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/docx.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/pptx.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/__pycache__/redlining.cpython-312.pyc +0 -0
- package/skills/pptx/ooxml/scripts/validation/base.py +951 -0
- package/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/pptx/ooxml.md +427 -0
- package/skills/pptx/scripts/__pycache__/inventory.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/inventory.cpython-313.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/rearrange.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/replace.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/__pycache__/thumbnail.cpython-312.pyc +0 -0
- package/skills/pptx/scripts/html2pptx.js +1044 -0
- package/skills/pptx/scripts/inventory.py +1020 -0
- package/skills/pptx/scripts/rearrange.py +231 -0
- package/skills/pptx/scripts/replace.py +385 -0
- package/skills/pptx/scripts/thumbnail.py +450 -0
- package/skills/qingyan-research/SKILL.md +294 -0
- package/skills/qingyan-research/__pycache__/generate_html.cpython-312.pyc +0 -0
- package/skills/qingyan-research/generate_html.py +33 -0
- package/skills/registry.py +344 -0
- package/skills/search_skill.py +228 -0
- package/skills/seo-content-writer/SKILL.md +661 -0
- package/skills/seo-content-writer/_meta.json +6 -0
- package/skills/seo-content-writer/references/content-structure-templates.md +875 -0
- package/skills/seo-content-writer/references/title-formulas.md +339 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +485 -0
- package/skills/skill-creator/agents/analyzer.md +274 -0
- package/skills/skill-creator/agents/comparator.md +202 -0
- package/skills/skill-creator/agents/grader.md +223 -0
- package/skills/skill-creator/assets/eval_review.html +146 -0
- package/skills/skill-creator/eval-viewer/__pycache__/generate_review.cpython-312.pyc +0 -0
- package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/skills/skill-creator/references/schemas.md +430 -0
- package/skills/skill-creator/scripts/__init__.py +0 -0
- package/skills/skill-creator/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/aggregate_benchmark.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/generate_report.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/improve_description.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/package_skill.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/quick_validate.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/run_eval.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/run_loop.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/__pycache__/utils.cpython-312.pyc +0 -0
- package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/skills/skill-creator/scripts/generate_report.py +326 -0
- package/skills/skill-creator/scripts/improve_description.py +236 -0
- package/skills/skill-creator/scripts/package_skill.py +136 -0
- package/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/skills/skill-creator/scripts/run_eval.py +310 -0
- package/skills/skill-creator/scripts/run_loop.py +328 -0
- package/skills/skill-creator/scripts/utils.py +47 -0
- package/skills/skill-finder-cn/SKILL.md +66 -0
- package/skills/skill-finder-cn/_meta.json +6 -0
- package/skills/skill-finder-cn/package.json +5 -0
- package/skills/skill-finder-cn/scripts/search.sh +15 -0
- package/skills/skill-vetter/SKILL.md +137 -0
- package/skills/stock-analysis-skill/SKILL.md +156 -0
- package/skills/stock-analysis-skill/package.json +21 -0
- package/skills/stock-analysis-skill/src/analyzer.ts +264 -0
- package/skills/stock-analysis-skill/src/dataFetcher.ts +130 -0
- package/skills/stock-analysis-skill/src/dividend.ts +226 -0
- package/skills/stock-analysis-skill/src/index.ts +327 -0
- package/skills/stock-analysis-skill/src/rumorScanner.ts +200 -0
- package/skills/stock-analysis-skill/src/types.ts +167 -0
- package/skills/stock-analysis-skill/src/watchlist.ts +292 -0
- package/skills/stock-analysis-skill/tsconfig.json +15 -0
- package/skills/storyboard-manager/SKILL.md +532 -0
- package/skills/storyboard-manager/index.js +9 -0
- package/skills/storyboard-manager/package.json +11 -0
- package/skills/storyboard-manager/references/character_development.md +232 -0
- package/skills/storyboard-manager/references/story_structures.md +148 -0
- package/skills/storyboard-manager/scripts/__pycache__/consistency_checker.cpython-312.pyc +0 -0
- package/skills/storyboard-manager/scripts/__pycache__/timeline_tracker.cpython-312.pyc +0 -0
- package/skills/storyboard-manager/scripts/consistency_checker.py +391 -0
- package/skills/storyboard-manager/scripts/timeline_tracker.py +352 -0
- package/skills/system_skill.py +249 -0
- package/skills/ui-ux-pro-max/SKILL.md +43 -0
- package/skills/ui-ux-pro-max/_meta.json +6 -0
- package/skills/ui-ux-pro-max/assets/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/assets/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/assets/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/assets/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/assets/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/assets/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/assets/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/references/upstream-README.md +488 -0
- package/skills/ui-ux-pro-max/references/upstream-skill-content.md +288 -0
- package/skills/ui-ux-pro-max/scripts/__init__.py +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/search.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +1071 -0
- package/skills/ui-ux-pro-max/scripts/search.py +111 -0
- package/skills/video-generation/LICENSE.txt +21 -0
- package/skills/video-generation/SKILL.md +1082 -0
- package/skills/video-generation/scripts/video.ts +168 -0
- package/skills/video-understand/LICENSE.txt +21 -0
- package/skills/video-understand/SKILL.md +916 -0
- package/skills/video-understand/scripts/video-understand.ts +41 -0
- package/skills/visual-design-foundations/SKILL.md +318 -0
- package/skills/visual-design-foundations/references/color-systems.md +417 -0
- package/skills/visual-design-foundations/references/spacing-iconography.md +425 -0
- package/skills/visual-design-foundations/references/typography-systems.md +432 -0
- package/skills/web-reader/LICENSE.txt +21 -0
- package/skills/web-reader/SKILL.md +1140 -0
- package/skills/web-reader/scripts/web-reader.ts +37 -0
- package/skills/web-search/LICENSE.txt +21 -0
- package/skills/web-search/SKILL.md +912 -0
- package/skills/web-search/scripts/web_search.ts +44 -0
- package/skills/web-shader-extractor/SKILL.md +145 -0
- package/skills/web-shader-extractor/references/config-extraction.md +50 -0
- package/skills/web-shader-extractor/references/encoded-definitions.md +53 -0
- package/skills/web-shader-extractor/references/extraction-workflow.md +61 -0
- package/skills/web-shader-extractor/references/porting-strategy.md +164 -0
- package/skills/web-shader-extractor/references/shader-injection.md +126 -0
- package/skills/web-shader-extractor/references/shaders-com.md +190 -0
- package/skills/web-shader-extractor/references/tech-signatures.md +54 -0
- package/skills/web-shader-extractor/references/tsl-extraction.md +41 -0
- package/skills/web-shader-extractor/references/unicorn-studio.md +353 -0
- package/skills/web-shader-extractor/scripts/fetch-rendered-dom.mjs +153 -0
- package/skills/web-shader-extractor/scripts/scan-bundle.sh +76 -0
- package/skills/writing-plans/SKILL.md +116 -0
- package/skills/writing-plans/_meta.json +6 -0
- package/skills/xlsx/LICENSE.txt +30 -0
- package/skills/xlsx/SKILL.md +496 -0
- package/skills/xlsx/__pycache__/recalc.cpython-312.pyc +0 -0
- package/skills/xlsx/recalc.py +178 -0
- package/start.sh +36 -0
- package/web/__init__.py +1 -0
- package/web/__pycache__/api_server.cpython-312.pyc +0 -0
- package/web/api_server.py +2043 -0
- package/web/ui/chat.html +3235 -0
- package/web/ui/index.html +458 -0
package/main.py
ADDED
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
"""
|
|
2
|
+
main.py - MyAgent 主入口
|
|
3
|
+
==========================
|
|
4
|
+
本地桌面端执行型AI助手。
|
|
5
|
+
支持:
|
|
6
|
+
- 系统托盘后台运行 (pystray)
|
|
7
|
+
- 交互式命令行
|
|
8
|
+
- 多聊天平台接入
|
|
9
|
+
- Windows / macOS / Linux
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
import signal
|
|
17
|
+
import threading
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
# 确保项目根目录在 Python 路径中
|
|
21
|
+
PROJECT_ROOT = Path(__file__).parent.resolve()
|
|
22
|
+
if str(PROJECT_ROOT) not in sys.path:
|
|
23
|
+
sys.path.insert(0, str(PROJECT_ROOT))
|
|
24
|
+
|
|
25
|
+
from config import get_config, ConfigManager
|
|
26
|
+
from core.logger import setup_logger, get_logger
|
|
27
|
+
from core.llm import LLMClient, Message
|
|
28
|
+
from core.task_queue import TaskQueue
|
|
29
|
+
from memory.manager import MemoryManager
|
|
30
|
+
from executor.engine import ExecutionEngine
|
|
31
|
+
from skills.registry import SkillRegistry
|
|
32
|
+
from agents.main_agent import MainAgent
|
|
33
|
+
from agents.tool_agent import ToolAgent
|
|
34
|
+
from agents.memory_agent import MemoryAgent
|
|
35
|
+
from chatbot.base import ChatMessage, ChatResponse
|
|
36
|
+
from chatbot.manager import ChatBotManager
|
|
37
|
+
from core.utils import timestamp, detect_platform
|
|
38
|
+
from core.config_broadcast import ConfigBroadcaster
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ==============================================================================
|
|
42
|
+
# MyAgent 应用主类
|
|
43
|
+
# ==============================================================================
|
|
44
|
+
|
|
45
|
+
class MyAgentApp:
|
|
46
|
+
"""
|
|
47
|
+
MyAgent 应用主类。
|
|
48
|
+
|
|
49
|
+
管理:
|
|
50
|
+
- LLM 客户端
|
|
51
|
+
- 记忆系统
|
|
52
|
+
- 执行引擎
|
|
53
|
+
- 技能系统
|
|
54
|
+
- Agent 集群
|
|
55
|
+
- 聊天平台
|
|
56
|
+
- 系统托盘
|
|
57
|
+
- 任务队列
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(self):
|
|
61
|
+
self.config_mgr = get_config()
|
|
62
|
+
self.config = self.config_mgr.config
|
|
63
|
+
self.logger = None
|
|
64
|
+
self._running = False
|
|
65
|
+
|
|
66
|
+
# 核心组件
|
|
67
|
+
self.memory: MemoryManager | None = None
|
|
68
|
+
self.executor: ExecutionEngine | None = None
|
|
69
|
+
self.skill_registry: SkillRegistry | None = None
|
|
70
|
+
self.llm: LLMClient | None = None
|
|
71
|
+
self.task_queue: TaskQueue | None = None
|
|
72
|
+
|
|
73
|
+
# Agent
|
|
74
|
+
self.main_agent: MainAgent | None = None
|
|
75
|
+
self.tool_agent: ToolAgent | None = None
|
|
76
|
+
self.memory_agent: MemoryAgent | None = None
|
|
77
|
+
|
|
78
|
+
# 聊天平台
|
|
79
|
+
self.chat_manager: ChatBotManager | None = None
|
|
80
|
+
|
|
81
|
+
# 配置热加载广播器
|
|
82
|
+
self.config_broadcaster: ConfigBroadcaster | None = None
|
|
83
|
+
|
|
84
|
+
# 通信管理器 (Agent 间加密通信)
|
|
85
|
+
self.communication_manager = None
|
|
86
|
+
|
|
87
|
+
# 群聊管理器
|
|
88
|
+
self.group_manager = None
|
|
89
|
+
|
|
90
|
+
# 交互式会话
|
|
91
|
+
self._session_id = "cli_default"
|
|
92
|
+
|
|
93
|
+
async def initialize(self):
|
|
94
|
+
"""初始化所有组件"""
|
|
95
|
+
# 1. 日志
|
|
96
|
+
self.logger = setup_logger(
|
|
97
|
+
"myagent",
|
|
98
|
+
log_dir=str(self.config_mgr.logs_dir),
|
|
99
|
+
level=self.config.log_level,
|
|
100
|
+
)
|
|
101
|
+
self.logger.info("=" * 60)
|
|
102
|
+
self.logger.info("MyAgent 正在启动...")
|
|
103
|
+
self.logger.info(f"平台: {detect_platform()}")
|
|
104
|
+
self.logger.info(f"数据目录: {self.config_mgr.data_dir}")
|
|
105
|
+
self.logger.info("=" * 60)
|
|
106
|
+
|
|
107
|
+
# 2. LLM 客户端
|
|
108
|
+
llm_cfg = self.config.llm
|
|
109
|
+
self.llm = LLMClient(
|
|
110
|
+
provider=llm_cfg.provider,
|
|
111
|
+
api_key=llm_cfg.api_key,
|
|
112
|
+
base_url=llm_cfg.base_url,
|
|
113
|
+
model=llm_cfg.model,
|
|
114
|
+
temperature=llm_cfg.temperature,
|
|
115
|
+
max_tokens=llm_cfg.max_tokens,
|
|
116
|
+
timeout=llm_cfg.timeout,
|
|
117
|
+
max_retries=llm_cfg.max_retries,
|
|
118
|
+
anthropic_api_key=llm_cfg.anthropic_api_key,
|
|
119
|
+
)
|
|
120
|
+
self.logger.info(f"LLM: {llm_cfg.provider}/{llm_cfg.model}")
|
|
121
|
+
|
|
122
|
+
# 3. 记忆系统
|
|
123
|
+
mem_cfg = self.config.memory
|
|
124
|
+
self.memory = MemoryManager(db_path=mem_cfg.db_path)
|
|
125
|
+
self.memory.initialize()
|
|
126
|
+
mem_stats = self.memory.get_stats()
|
|
127
|
+
self.logger.info(f"记忆系统: {mem_stats['total_count']} 条记录")
|
|
128
|
+
|
|
129
|
+
# 4. 执行引擎
|
|
130
|
+
exe_cfg = self.config.executor
|
|
131
|
+
self.executor = ExecutionEngine(
|
|
132
|
+
timeout=exe_cfg.timeout,
|
|
133
|
+
max_retries=exe_cfg.max_retries,
|
|
134
|
+
auto_fix=exe_cfg.auto_fix,
|
|
135
|
+
max_output_length=exe_cfg.max_output_length,
|
|
136
|
+
)
|
|
137
|
+
self.logger.info(f"执行引擎: timeout={exe_cfg.timeout}s, auto_fix={exe_cfg.auto_fix}")
|
|
138
|
+
|
|
139
|
+
# 5. 技能系统
|
|
140
|
+
self.skill_registry = SkillRegistry()
|
|
141
|
+
# 注册内置技能
|
|
142
|
+
self._register_builtin_skills()
|
|
143
|
+
skills = self.skill_registry.list_skills()
|
|
144
|
+
self.logger.info(f"技能系统: {len(skills)} 个技能已注册 - {skills}")
|
|
145
|
+
|
|
146
|
+
# 6. 任务队列
|
|
147
|
+
self.task_queue = TaskQueue(max_workers=self.config.agent.max_parallel)
|
|
148
|
+
await self.task_queue.start()
|
|
149
|
+
self.logger.info(f"任务队列: workers={self.config.agent.max_parallel}")
|
|
150
|
+
|
|
151
|
+
# 7. 配置广播器
|
|
152
|
+
self.config_broadcaster = ConfigBroadcaster()
|
|
153
|
+
self.logger.info("配置广播器已初始化")
|
|
154
|
+
|
|
155
|
+
# 8. 通信管理器 (Agent 间加密通信)
|
|
156
|
+
try:
|
|
157
|
+
from communication.manager import CommunicationManager
|
|
158
|
+
comm_config = self.config.communication
|
|
159
|
+
self.communication_manager = CommunicationManager(
|
|
160
|
+
config=comm_config,
|
|
161
|
+
data_dir=str(self.config_mgr.data_dir),
|
|
162
|
+
)
|
|
163
|
+
self.communication_manager.initialize()
|
|
164
|
+
if comm_config.enabled:
|
|
165
|
+
await self.communication_manager.start()
|
|
166
|
+
self.logger.info(f"通信管理器: agent_id={self.communication_manager.agent_id}")
|
|
167
|
+
else:
|
|
168
|
+
self.logger.info("通信管理器: 已初始化但未启用")
|
|
169
|
+
except Exception as e:
|
|
170
|
+
self.logger.warning(f"通信管理器初始化失败: {e}")
|
|
171
|
+
self.communication_manager = None
|
|
172
|
+
|
|
173
|
+
# 8.5 群聊管理器
|
|
174
|
+
try:
|
|
175
|
+
from groups.manager import GroupManager
|
|
176
|
+
self.group_manager = GroupManager(
|
|
177
|
+
data_dir=str(self.config_mgr.data_dir),
|
|
178
|
+
)
|
|
179
|
+
self.group_manager.initialize()
|
|
180
|
+
self.logger.info(f"群聊管理器: {len(self.group_manager.list_groups())} 个群")
|
|
181
|
+
except Exception as e:
|
|
182
|
+
self.logger.warning(f"群聊管理器初始化失败: {e}")
|
|
183
|
+
self.group_manager = None
|
|
184
|
+
|
|
185
|
+
# 9. 创建 Agent
|
|
186
|
+
self.memory_agent = MemoryAgent(
|
|
187
|
+
llm=self.llm,
|
|
188
|
+
memory_manager=self.memory,
|
|
189
|
+
config=self.config,
|
|
190
|
+
config_broadcaster=self.config_broadcaster,
|
|
191
|
+
)
|
|
192
|
+
self.tool_agent = ToolAgent(
|
|
193
|
+
llm=self.llm,
|
|
194
|
+
memory_manager=self.memory,
|
|
195
|
+
executor=self.executor,
|
|
196
|
+
skill_registry=self.skill_registry,
|
|
197
|
+
task_queue=self.task_queue,
|
|
198
|
+
config=self.config,
|
|
199
|
+
config_broadcaster=self.config_broadcaster,
|
|
200
|
+
)
|
|
201
|
+
self.main_agent = MainAgent(
|
|
202
|
+
llm=self.llm,
|
|
203
|
+
memory_manager=self.memory,
|
|
204
|
+
executor=self.executor,
|
|
205
|
+
skill_registry=self.skill_registry,
|
|
206
|
+
task_queue=self.task_queue,
|
|
207
|
+
config=self.config,
|
|
208
|
+
tool_agent=self.tool_agent,
|
|
209
|
+
memory_agent=self.memory_agent,
|
|
210
|
+
config_broadcaster=self.config_broadcaster,
|
|
211
|
+
)
|
|
212
|
+
self.logger.info("Agent 集群已初始化 (主/工具/记忆)")
|
|
213
|
+
|
|
214
|
+
# 10. 聊天平台
|
|
215
|
+
enabled_platforms = self.config_mgr.get_enabled_platforms()
|
|
216
|
+
if enabled_platforms:
|
|
217
|
+
self.chat_manager = ChatBotManager()
|
|
218
|
+
self.chat_manager.setup_platforms(
|
|
219
|
+
enabled_platforms,
|
|
220
|
+
message_handler=self._handle_chat_message,
|
|
221
|
+
)
|
|
222
|
+
self.logger.info(f"聊天平台: {[p.platform for p in enabled_platforms]}")
|
|
223
|
+
else:
|
|
224
|
+
self.logger.info("聊天平台: 未配置(仅CLI模式)")
|
|
225
|
+
|
|
226
|
+
self._running = True
|
|
227
|
+
self.logger.info("✅ MyAgent 启动完成!")
|
|
228
|
+
|
|
229
|
+
def _register_builtin_skills(self):
|
|
230
|
+
"""注册内置技能"""
|
|
231
|
+
from skills.file_skill import (
|
|
232
|
+
FileReadSkill, FileWriteSkill, FileListSkill,
|
|
233
|
+
FileDeleteSkill, FileSearchSkill, FileMoveSkill,
|
|
234
|
+
)
|
|
235
|
+
from skills.search_skill import WebSearchSkill, WebReadSkill, URLReadSkill
|
|
236
|
+
from skills.system_skill import (
|
|
237
|
+
SystemInfoSkill, ProcessListSkill, CommandRunSkill,
|
|
238
|
+
EnvironmentGetSkill, PathExpandSkill,
|
|
239
|
+
)
|
|
240
|
+
from skills.browser_skill import (
|
|
241
|
+
BrowserOpenSkill, BrowserClickSkill, BrowserFillSkill,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
# 文件技能
|
|
245
|
+
for skill_cls in [
|
|
246
|
+
FileReadSkill, FileWriteSkill, FileListSkill,
|
|
247
|
+
FileDeleteSkill, FileSearchSkill, FileMoveSkill,
|
|
248
|
+
]:
|
|
249
|
+
self.skill_registry.register(skill_cls())
|
|
250
|
+
|
|
251
|
+
# 搜索技能
|
|
252
|
+
for skill_cls in [WebSearchSkill, WebReadSkill, URLReadSkill]:
|
|
253
|
+
self.skill_registry.register(skill_cls())
|
|
254
|
+
|
|
255
|
+
# 系统技能
|
|
256
|
+
for skill_cls in [
|
|
257
|
+
SystemInfoSkill, ProcessListSkill, CommandRunSkill,
|
|
258
|
+
EnvironmentGetSkill, PathExpandSkill,
|
|
259
|
+
]:
|
|
260
|
+
self.skill_registry.register(skill_cls())
|
|
261
|
+
|
|
262
|
+
# 浏览器技能
|
|
263
|
+
for skill_cls in [BrowserOpenSkill, BrowserClickSkill, BrowserFillSkill]:
|
|
264
|
+
self.skill_registry.register(skill_cls())
|
|
265
|
+
|
|
266
|
+
async def process_message(
|
|
267
|
+
self,
|
|
268
|
+
user_message: str,
|
|
269
|
+
session_id: str = "",
|
|
270
|
+
) -> str:
|
|
271
|
+
"""
|
|
272
|
+
处理用户消息并返回回复。
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
user_message: 用户消息
|
|
276
|
+
session_id: 会话 ID
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
助手回复文本
|
|
280
|
+
"""
|
|
281
|
+
if not self.main_agent:
|
|
282
|
+
return "⚠️ MyAgent 尚未初始化"
|
|
283
|
+
|
|
284
|
+
session_id = session_id or self._session_id
|
|
285
|
+
|
|
286
|
+
from agents.base import AgentContext
|
|
287
|
+
context = AgentContext(
|
|
288
|
+
session_id=session_id,
|
|
289
|
+
user_message=user_message,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
try:
|
|
293
|
+
result_context = await self.main_agent.process(context)
|
|
294
|
+
response = result_context.working_memory.get(
|
|
295
|
+
"final_response", "⚠️ 未能生成回复"
|
|
296
|
+
)
|
|
297
|
+
return response
|
|
298
|
+
except Exception as e:
|
|
299
|
+
self.logger.error(f"处理消息异常: {e}", exc_info=True)
|
|
300
|
+
return f"❌ 处理失败: {str(e)}"
|
|
301
|
+
|
|
302
|
+
async def _handle_chat_message(self, message: ChatMessage, bot):
|
|
303
|
+
"""
|
|
304
|
+
处理来自聊天平台的消息。
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
message: 聊天消息
|
|
308
|
+
bot: 发送消息的机器人实例
|
|
309
|
+
"""
|
|
310
|
+
# 生成会话 ID
|
|
311
|
+
session_id = bot._generate_session_id(message)
|
|
312
|
+
|
|
313
|
+
# 处理特殊命令
|
|
314
|
+
if message.text == "__cmd_clear__":
|
|
315
|
+
if self.memory:
|
|
316
|
+
self.memory.clear_conversation(session_id)
|
|
317
|
+
await bot.send_message(ChatResponse(
|
|
318
|
+
chat_id=message.chat_id,
|
|
319
|
+
text="🗑️ 对话历史已清除。",
|
|
320
|
+
))
|
|
321
|
+
return
|
|
322
|
+
|
|
323
|
+
# 处理消息
|
|
324
|
+
response_text = await self.process_message(message.text, session_id)
|
|
325
|
+
|
|
326
|
+
# 发送回复
|
|
327
|
+
await bot.send_message(ChatResponse(
|
|
328
|
+
chat_id=message.chat_id,
|
|
329
|
+
user_id=message.user_id,
|
|
330
|
+
text=response_text,
|
|
331
|
+
))
|
|
332
|
+
|
|
333
|
+
async def run_cli(self):
|
|
334
|
+
"""运行交互式命令行"""
|
|
335
|
+
if not self.main_agent:
|
|
336
|
+
await self.initialize()
|
|
337
|
+
|
|
338
|
+
print()
|
|
339
|
+
print("=" * 60)
|
|
340
|
+
print(" 🤖 MyAgent - 本地桌面端执行型AI助手")
|
|
341
|
+
print(f" LLM: {self.config.llm.provider}/{self.config.llm.model}")
|
|
342
|
+
print(f" 技能: {len(self.skill_registry.list_skills())} 个已注册")
|
|
343
|
+
print(f" 平台: {'CLI' + (' + ' + ','.join(self.chat_manager.get_active_platforms()) if self.chat_manager else '')}")
|
|
344
|
+
print(" 输入 'help' 查看命令 | 'quit' 退出")
|
|
345
|
+
print("=" * 60)
|
|
346
|
+
print()
|
|
347
|
+
|
|
348
|
+
while self._running:
|
|
349
|
+
try:
|
|
350
|
+
# 读取用户输入
|
|
351
|
+
user_input = input("👤 你: ").strip()
|
|
352
|
+
|
|
353
|
+
if not user_input:
|
|
354
|
+
continue
|
|
355
|
+
|
|
356
|
+
# 内置命令
|
|
357
|
+
if user_input.lower() in ("quit", "exit", "q"):
|
|
358
|
+
print("👋 再见!")
|
|
359
|
+
break
|
|
360
|
+
elif user_input.lower() == "help":
|
|
361
|
+
self._print_help()
|
|
362
|
+
continue
|
|
363
|
+
elif user_input.lower() == "status":
|
|
364
|
+
self._print_status()
|
|
365
|
+
continue
|
|
366
|
+
elif user_input.lower() == "skills":
|
|
367
|
+
self._print_skills()
|
|
368
|
+
continue
|
|
369
|
+
elif user_input.lower() == "memory":
|
|
370
|
+
self._print_memory_stats()
|
|
371
|
+
continue
|
|
372
|
+
elif user_input.lower() == "sessions":
|
|
373
|
+
self._print_sessions()
|
|
374
|
+
continue
|
|
375
|
+
elif user_input.lower().startswith("session "):
|
|
376
|
+
new_session = user_input[8:].strip()
|
|
377
|
+
if new_session:
|
|
378
|
+
self._session_id = new_session
|
|
379
|
+
print(f"📝 已切换到会话: {self._session_id}")
|
|
380
|
+
continue
|
|
381
|
+
elif user_input.lower() == "clear":
|
|
382
|
+
if self.memory:
|
|
383
|
+
self.memory.clear_conversation(self._session_id)
|
|
384
|
+
print("🗑️ 对话历史已清除")
|
|
385
|
+
continue
|
|
386
|
+
|
|
387
|
+
# 处理消息
|
|
388
|
+
print("⏳ 思考中...", end="", flush=True)
|
|
389
|
+
response = await self.process_message(user_input, self._session_id)
|
|
390
|
+
print(f"\r🤖 助手: {response}")
|
|
391
|
+
print()
|
|
392
|
+
|
|
393
|
+
except KeyboardInterrupt:
|
|
394
|
+
print("\n\n👋 再见!")
|
|
395
|
+
break
|
|
396
|
+
except EOFError:
|
|
397
|
+
break
|
|
398
|
+
except Exception as e:
|
|
399
|
+
print(f"\n❌ 错误: {e}")
|
|
400
|
+
print()
|
|
401
|
+
|
|
402
|
+
def _print_help(self):
|
|
403
|
+
print("""
|
|
404
|
+
📋 可用命令:
|
|
405
|
+
help - 显示帮助
|
|
406
|
+
status - 查看系统状态
|
|
407
|
+
skills - 列出所有技能
|
|
408
|
+
memory - 查看记忆统计
|
|
409
|
+
sessions - 查看会话列表
|
|
410
|
+
session <id> - 切换会话
|
|
411
|
+
clear - 清除当前对话历史
|
|
412
|
+
quit/exit - 退出
|
|
413
|
+
|
|
414
|
+
💡 使用方式:
|
|
415
|
+
直接输入自然语言描述你的需求。
|
|
416
|
+
示例:
|
|
417
|
+
- "帮我创建一个Python文件"
|
|
418
|
+
- "搜索一下最新的AI新闻"
|
|
419
|
+
- "查看系统信息"
|
|
420
|
+
- "!system_info" (直接调用技能)
|
|
421
|
+
""")
|
|
422
|
+
|
|
423
|
+
def _print_status(self):
|
|
424
|
+
print(f"""
|
|
425
|
+
📊 系统状态:
|
|
426
|
+
运行状态: {'✅ 运行中' if self._running else '❌ 已停止'}
|
|
427
|
+
LLM: {self.config.llm.provider}/{self.config.llm.model}
|
|
428
|
+
当前会话: {self._session_id}
|
|
429
|
+
执行引擎: timeout={self.config.executor.timeout}s
|
|
430
|
+
任务队列: {self.task_queue.get_stats() if self.task_queue else 'N/A'}
|
|
431
|
+
记忆: {self.memory.get_stats() if self.memory else 'N/A'}
|
|
432
|
+
聊天平台: {self.chat_manager.get_stats() if self.chat_manager else 'N/A'}
|
|
433
|
+
""")
|
|
434
|
+
|
|
435
|
+
def _print_skills(self):
|
|
436
|
+
print("\n🛠️ 已注册技能:")
|
|
437
|
+
if self.skill_registry:
|
|
438
|
+
for info in self.skill_registry.list_skills_info():
|
|
439
|
+
danger = " ⚠️" if info.get("dangerous") else ""
|
|
440
|
+
print(f" • {info['name']}: {info['description']}{danger}")
|
|
441
|
+
print()
|
|
442
|
+
|
|
443
|
+
def _print_memory_stats(self):
|
|
444
|
+
if self.memory:
|
|
445
|
+
stats = self.memory.get_stats()
|
|
446
|
+
print(f"\n🧠 记忆系统:")
|
|
447
|
+
print(f" 短期记忆: {stats.get('short_term_count', 0)} 条")
|
|
448
|
+
print(f" 工作记忆: {stats.get('working_count', 0)} 条")
|
|
449
|
+
print(f" 长期记忆: {stats.get('long_term_count', 0)} 条")
|
|
450
|
+
print(f" 总计: {stats.get('total_count', 0)} 条")
|
|
451
|
+
print(f" 会话数: {stats.get('session_count', 0)}")
|
|
452
|
+
print()
|
|
453
|
+
|
|
454
|
+
def _print_sessions(self):
|
|
455
|
+
# TODO: 从记忆系统中获取活跃会话列表
|
|
456
|
+
print(f"\n📂 当前会话: {self._session_id}")
|
|
457
|
+
print(" (提示: 使用 'session <名称>' 切换会话)")
|
|
458
|
+
print()
|
|
459
|
+
|
|
460
|
+
async def shutdown(self):
|
|
461
|
+
"""关闭所有组件"""
|
|
462
|
+
self.logger.info("MyAgent 正在关闭...")
|
|
463
|
+
self._running = False
|
|
464
|
+
|
|
465
|
+
if self.communication_manager:
|
|
466
|
+
await self.communication_manager.stop()
|
|
467
|
+
|
|
468
|
+
if self.chat_manager:
|
|
469
|
+
await self.chat_manager.stop_all()
|
|
470
|
+
|
|
471
|
+
if self.task_queue:
|
|
472
|
+
await self.task_queue.stop()
|
|
473
|
+
|
|
474
|
+
if self.memory:
|
|
475
|
+
self.memory.close()
|
|
476
|
+
|
|
477
|
+
self.logger.info("MyAgent 已关闭")
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
# ==============================================================================
|
|
481
|
+
# 系统托盘
|
|
482
|
+
# ==============================================================================
|
|
483
|
+
|
|
484
|
+
def create_tray_icon(app: MyAgentApp, web_port: int = 8765):
|
|
485
|
+
"""
|
|
486
|
+
创建系统托盘图标。
|
|
487
|
+
|
|
488
|
+
提供菜单:
|
|
489
|
+
- 打开管理后台
|
|
490
|
+
- 显示状态
|
|
491
|
+
- 打开日志
|
|
492
|
+
- 打开工作目录
|
|
493
|
+
- 设置开机自启
|
|
494
|
+
- 后台运行
|
|
495
|
+
- 退出
|
|
496
|
+
"""
|
|
497
|
+
try:
|
|
498
|
+
import pystray
|
|
499
|
+
from PIL import Image, ImageDraw
|
|
500
|
+
except ImportError:
|
|
501
|
+
return None
|
|
502
|
+
|
|
503
|
+
# 生成默认图标 (简单的机器人图标)
|
|
504
|
+
def create_icon_image():
|
|
505
|
+
img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
|
506
|
+
draw = ImageDraw.Draw(img)
|
|
507
|
+
# 画一个简单的圆形头像
|
|
508
|
+
draw.ellipse([8, 4, 56, 52], fill="#4A90D9")
|
|
509
|
+
# 画眼睛
|
|
510
|
+
draw.ellipse([20, 20, 30, 30], fill="white")
|
|
511
|
+
draw.ellipse([34, 20, 44, 30], fill="white")
|
|
512
|
+
draw.ellipse([23, 23, 27, 27], fill="#333")
|
|
513
|
+
draw.ellipse([37, 23, 41, 27], fill="#333")
|
|
514
|
+
# 画嘴巴
|
|
515
|
+
draw.arc([22, 28, 42, 42], 0, 180, fill="white", width=2)
|
|
516
|
+
return img
|
|
517
|
+
|
|
518
|
+
def open_web_ui(icon, item):
|
|
519
|
+
"""打开管理后台 Web UI"""
|
|
520
|
+
import webbrowser
|
|
521
|
+
url = f"http://127.0.0.1:{web_port}/ui/"
|
|
522
|
+
webbrowser.open(url)
|
|
523
|
+
|
|
524
|
+
def open_chat_ui(icon, item):
|
|
525
|
+
"""打开聊天界面"""
|
|
526
|
+
import webbrowser
|
|
527
|
+
url = f"http://127.0.0.1:{web_port}/ui/chat.html"
|
|
528
|
+
webbrowser.open(url)
|
|
529
|
+
|
|
530
|
+
def open_logs(icon, item):
|
|
531
|
+
import subprocess
|
|
532
|
+
import platform
|
|
533
|
+
log_dir = str(app.config_mgr.logs_dir)
|
|
534
|
+
system = platform.system()
|
|
535
|
+
if system == "Windows":
|
|
536
|
+
os.startfile(log_dir) # type: ignore
|
|
537
|
+
elif system == "Darwin":
|
|
538
|
+
subprocess.Popen(["open", log_dir])
|
|
539
|
+
else:
|
|
540
|
+
subprocess.Popen(["xdg-open", log_dir])
|
|
541
|
+
|
|
542
|
+
def open_workdir(icon, item):
|
|
543
|
+
import subprocess
|
|
544
|
+
import platform
|
|
545
|
+
wd = str(app.config_mgr.data_dir / "workspace")
|
|
546
|
+
Path(wd).mkdir(parents=True, exist_ok=True)
|
|
547
|
+
system = platform.system()
|
|
548
|
+
if system == "Windows":
|
|
549
|
+
os.startfile(wd) # type: ignore
|
|
550
|
+
elif system == "Darwin":
|
|
551
|
+
subprocess.Popen(["open", wd])
|
|
552
|
+
else:
|
|
553
|
+
subprocess.Popen(["xdg-open", wd])
|
|
554
|
+
|
|
555
|
+
def show_status(icon, item):
|
|
556
|
+
if app.main_agent:
|
|
557
|
+
stats = app.main_agent.get_stats()
|
|
558
|
+
print(f"\n📊 Agent 状态: {stats}")
|
|
559
|
+
if app.memory:
|
|
560
|
+
print(f"🧠 记忆: {app.memory.get_stats()}")
|
|
561
|
+
if app.task_queue:
|
|
562
|
+
print(f"📋 队列: {app.task_queue.get_stats()}")
|
|
563
|
+
|
|
564
|
+
def toggle_autostart(icon, item):
|
|
565
|
+
setup_auto_start(not item.checked)
|
|
566
|
+
|
|
567
|
+
def on_quit(icon, item):
|
|
568
|
+
icon.stop()
|
|
569
|
+
if app._running:
|
|
570
|
+
asyncio.run(app.shutdown())
|
|
571
|
+
|
|
572
|
+
icon_image = create_icon_image()
|
|
573
|
+
menu = pystray.Menu(
|
|
574
|
+
pystray.MenuItem("🤖 MyAgent - 运行中", None, enabled=False),
|
|
575
|
+
pystray.Menu.SEPARATOR,
|
|
576
|
+
pystray.MenuItem("🖥️ 打开管理后台", open_web_ui),
|
|
577
|
+
pystray.MenuItem("💬 打开聊天界面", open_chat_ui,
|
|
578
|
+
default=True), # 双击托盘图标打开
|
|
579
|
+
pystray.MenuItem("⚡ 执行模式", open_chat_ui),
|
|
580
|
+
pystray.MenuItem("📋 显示状态", show_status),
|
|
581
|
+
pystray.MenuItem("📁 打开工作目录", open_workdir),
|
|
582
|
+
pystray.MenuItem("📄 打开日志目录", open_logs),
|
|
583
|
+
pystray.Menu.SEPARATOR,
|
|
584
|
+
pystray.MenuItem("🔄 开机自启", toggle_autostart, checked=False),
|
|
585
|
+
pystray.Menu.SEPARATOR,
|
|
586
|
+
pystray.MenuItem("⏸️ 最小化到后台", None, enabled=False),
|
|
587
|
+
pystray.MenuItem("❌ 退出", on_quit),
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
return pystray.Icon("myagent", icon_image, "MyAgent AI 助手", menu)
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def run_with_tray(app: MyAgentApp, web_port: int = 8765):
|
|
594
|
+
"""在系统托盘中运行 MyAgent"""
|
|
595
|
+
tray = create_tray_icon(app, web_port)
|
|
596
|
+
if tray is None:
|
|
597
|
+
app.logger.warning("pystray 未安装,跳过系统托盘")
|
|
598
|
+
return
|
|
599
|
+
|
|
600
|
+
# 在后台线程运行托盘
|
|
601
|
+
tray_thread = threading.Thread(target=tray.run, daemon=True)
|
|
602
|
+
tray_thread.start()
|
|
603
|
+
app.logger.info(f"系统托盘已启动 (管理后台: http://127.0.0.1:{web_port}/ui/)")
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
# ==============================================================================
|
|
607
|
+
# 开机自启设置
|
|
608
|
+
# ==============================================================================
|
|
609
|
+
|
|
610
|
+
def setup_auto_start(enable: bool = True):
|
|
611
|
+
"""
|
|
612
|
+
设置开机自启。
|
|
613
|
+
|
|
614
|
+
Windows: 添加到启动文件夹
|
|
615
|
+
macOS: 使用 launchd (plist)
|
|
616
|
+
Linux: 使用 systemd user service
|
|
617
|
+
"""
|
|
618
|
+
import platform
|
|
619
|
+
system = platform.system()
|
|
620
|
+
|
|
621
|
+
try:
|
|
622
|
+
if system == "Windows":
|
|
623
|
+
_setup_autostart_windows(enable)
|
|
624
|
+
elif system == "Darwin":
|
|
625
|
+
_setup_autostart_macos(enable)
|
|
626
|
+
elif system == "Linux":
|
|
627
|
+
_setup_autostart_linux(enable)
|
|
628
|
+
except Exception as e:
|
|
629
|
+
print(f"⚠️ 设置开机自启失败: {e}")
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
def _setup_autostart_windows(enable: bool):
|
|
633
|
+
"""Windows: 启动文件夹快捷方式"""
|
|
634
|
+
import winreg
|
|
635
|
+
import os
|
|
636
|
+
|
|
637
|
+
key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
|
|
638
|
+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path, 0,
|
|
639
|
+
winreg.KEY_SET_VALUE)
|
|
640
|
+
|
|
641
|
+
if enable:
|
|
642
|
+
exe_path = os.path.abspath(sys.argv[0])
|
|
643
|
+
winreg.SetValueEx(key, "MyAgent", 0, winreg.REG_SZ, exe_path)
|
|
644
|
+
print("✅ 已设置 Windows 开机自启")
|
|
645
|
+
else:
|
|
646
|
+
try:
|
|
647
|
+
winreg.DeleteValue(key, "MyAgent")
|
|
648
|
+
print("✅ 已取消 Windows 开机自启")
|
|
649
|
+
except FileNotFoundError:
|
|
650
|
+
print("ℹ️ 未找到开机自启项")
|
|
651
|
+
|
|
652
|
+
winreg.CloseKey(key)
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def _setup_autostart_macos(enable: bool):
|
|
656
|
+
"""macOS: LaunchAgent plist"""
|
|
657
|
+
import plistlib
|
|
658
|
+
|
|
659
|
+
plist_dir = Path.home() / "Library" / "LaunchAgents"
|
|
660
|
+
plist_dir.mkdir(parents=True, exist_ok=True)
|
|
661
|
+
plist_path = plist_dir / "com.myagent.plist"
|
|
662
|
+
|
|
663
|
+
if enable:
|
|
664
|
+
plist_data = {
|
|
665
|
+
"Label": "com.myagent",
|
|
666
|
+
"ProgramArguments": [sys.executable, str(PROJECT_ROOT / "main.py"), "--tray"],
|
|
667
|
+
"RunAtLoad": True,
|
|
668
|
+
"KeepAlive": False,
|
|
669
|
+
}
|
|
670
|
+
with open(plist_path, "wb") as f:
|
|
671
|
+
plistlib.dump(plist_data, f)
|
|
672
|
+
print(f"✅ 已设置 macOS 开机自启: {plist_path}")
|
|
673
|
+
else:
|
|
674
|
+
if plist_path.exists():
|
|
675
|
+
plist_path.unlink()
|
|
676
|
+
print("✅ 已取消 macOS 开机自启")
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def _setup_autostart_linux(enable: bool):
|
|
680
|
+
"""Linux: systemd user service"""
|
|
681
|
+
service_dir = Path.home() / ".config" / "systemd" / "user"
|
|
682
|
+
service_dir.mkdir(parents=True, exist_ok=True)
|
|
683
|
+
service_path = service_dir / "myagent.service"
|
|
684
|
+
|
|
685
|
+
if enable:
|
|
686
|
+
service_content = f"""[Unit]
|
|
687
|
+
Description=MyAgent AI Assistant
|
|
688
|
+
After=network.target
|
|
689
|
+
|
|
690
|
+
[Service]
|
|
691
|
+
Type=simple
|
|
692
|
+
ExecStart={sys.executable} {PROJECT_ROOT / 'main.py'} --tray
|
|
693
|
+
WorkingDirectory={PROJECT_ROOT}
|
|
694
|
+
Restart=on-failure
|
|
695
|
+
|
|
696
|
+
[Install]
|
|
697
|
+
WantedBy=default.target
|
|
698
|
+
"""
|
|
699
|
+
with open(service_path, "w") as f:
|
|
700
|
+
f.write(service_content)
|
|
701
|
+
print(f"✅ 已创建 systemd service: {service_path}")
|
|
702
|
+
print(" 启用命令: systemctl --user enable myagent.service")
|
|
703
|
+
else:
|
|
704
|
+
if service_path.exists():
|
|
705
|
+
service_path.unlink()
|
|
706
|
+
print("✅ 已取消 Linux 开机自启")
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
# ==============================================================================
|
|
710
|
+
# 主函数
|
|
711
|
+
# ==============================================================================
|
|
712
|
+
|
|
713
|
+
def main():
|
|
714
|
+
"""主入口"""
|
|
715
|
+
import argparse
|
|
716
|
+
|
|
717
|
+
parser = argparse.ArgumentParser(description="MyAgent - 本地桌面端执行型AI助手")
|
|
718
|
+
parser.add_argument("--tray", action="store_true", help="以系统托盘模式运行")
|
|
719
|
+
parser.add_argument("--web", type=int, nargs="?", const=8765, default=None,
|
|
720
|
+
help="启动管理后台 Web UI (可选端口,默认8765)")
|
|
721
|
+
parser.add_argument("--port", type=int, default=8765, help="Web UI 端口")
|
|
722
|
+
parser.add_argument("--autostart", action="store_true", help="设置开机自启")
|
|
723
|
+
parser.add_argument("--no-autostart", action="store_true", help="取消开机自启")
|
|
724
|
+
parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
725
|
+
parser.add_argument("--debug", action="store_true", help="调试模式")
|
|
726
|
+
args = parser.parse_args()
|
|
727
|
+
|
|
728
|
+
# 配置
|
|
729
|
+
config_mgr = get_config()
|
|
730
|
+
if args.debug:
|
|
731
|
+
config_mgr.config.log_level = "DEBUG"
|
|
732
|
+
if args.config:
|
|
733
|
+
config_mgr._config_file = Path(args.config)
|
|
734
|
+
config_mgr.load()
|
|
735
|
+
|
|
736
|
+
# 开机自启
|
|
737
|
+
if args.autostart:
|
|
738
|
+
setup_auto_start(True)
|
|
739
|
+
return
|
|
740
|
+
if args.no_autostart:
|
|
741
|
+
setup_auto_start(False)
|
|
742
|
+
return
|
|
743
|
+
|
|
744
|
+
# 创建应用
|
|
745
|
+
app = MyAgentApp()
|
|
746
|
+
web_port = args.web if args.web else args.port if args.tray else None
|
|
747
|
+
|
|
748
|
+
# 信号处理
|
|
749
|
+
def signal_handler(sig, frame):
|
|
750
|
+
print("\n🛑 正在关闭...")
|
|
751
|
+
if app._running:
|
|
752
|
+
asyncio.run(app.shutdown())
|
|
753
|
+
sys.exit(0)
|
|
754
|
+
|
|
755
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
756
|
+
signal.signal(signal.SIGTERM, signal_handler)
|
|
757
|
+
|
|
758
|
+
# 启动
|
|
759
|
+
async def run():
|
|
760
|
+
await app.initialize()
|
|
761
|
+
|
|
762
|
+
# Web 管理后台
|
|
763
|
+
api_server = None
|
|
764
|
+
if web_port:
|
|
765
|
+
from web.api_server import ApiServer
|
|
766
|
+
api_server = ApiServer(app)
|
|
767
|
+
await api_server.start(port=web_port)
|
|
768
|
+
app.logger.info(f"管理后台: http://127.0.0.1:{web_port}/ui/")
|
|
769
|
+
|
|
770
|
+
# 系统托盘 (默认开启管理后台)
|
|
771
|
+
if args.tray or web_port:
|
|
772
|
+
run_with_tray(app, web_port)
|
|
773
|
+
|
|
774
|
+
# 启动聊天平台(后台)
|
|
775
|
+
if app.chat_manager:
|
|
776
|
+
asyncio.create_task(app.chat_manager.start_all())
|
|
777
|
+
|
|
778
|
+
if args.tray:
|
|
779
|
+
# 托盘模式: 后台等待
|
|
780
|
+
app.logger.info("后台运行中... (Ctrl+C 退出)")
|
|
781
|
+
while app._running:
|
|
782
|
+
await asyncio.sleep(1)
|
|
783
|
+
else:
|
|
784
|
+
# CLI 模式
|
|
785
|
+
await app.run_cli()
|
|
786
|
+
|
|
787
|
+
await app.shutdown()
|
|
788
|
+
if api_server:
|
|
789
|
+
await api_server.stop()
|
|
790
|
+
|
|
791
|
+
try:
|
|
792
|
+
asyncio.run(run())
|
|
793
|
+
except KeyboardInterrupt:
|
|
794
|
+
pass
|
|
795
|
+
finally:
|
|
796
|
+
if app._running:
|
|
797
|
+
asyncio.run(app.shutdown())
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
if __name__ == "__main__":
|
|
801
|
+
main()
|