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
|
@@ -0,0 +1,912 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: web-search
|
|
3
|
+
description: Implement web search capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to search for real-time information from the web, retrieve up-to-date content beyond the knowledge cutoff, or find the latest news and data. Returns structured search results with URLs, snippets, and metadata.
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Web Search Skill
|
|
8
|
+
|
|
9
|
+
This skill guides the implementation of web search functionality using the z-ai-web-dev-sdk package, enabling applications to search the web and retrieve current information.
|
|
10
|
+
|
|
11
|
+
## Installation Path
|
|
12
|
+
|
|
13
|
+
**Recommended Location**: `{project_path}/skills/web-search`
|
|
14
|
+
|
|
15
|
+
Extract this skill package to the above path in your project.
|
|
16
|
+
|
|
17
|
+
**Reference Scripts**: Example test scripts are available in the `{project_path}/skills/web-search/scripts/` directory for quick testing and reference. See `{project_path}/skills/web-search/scripts/web_search.ts` for a working example.
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
The Web Search skill allows you to build applications that can search the internet, retrieve current information, and access real-time data from web sources.
|
|
22
|
+
|
|
23
|
+
**IMPORTANT**: z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code.
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
The z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below.
|
|
28
|
+
|
|
29
|
+
## CLI Usage (For Simple Tasks)
|
|
30
|
+
|
|
31
|
+
For simple web search queries, you can use the z-ai CLI instead of writing code. This is ideal for quick information retrieval, testing search functionality, or command-line automation.
|
|
32
|
+
|
|
33
|
+
### Basic Web Search
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Simple search query
|
|
37
|
+
z-ai function --name "web_search" --args '{"query": "artificial intelligence"}'
|
|
38
|
+
|
|
39
|
+
# Using short options
|
|
40
|
+
z-ai function -n web_search -a '{"query": "latest tech news"}'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Search with Custom Parameters
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Limit number of results
|
|
47
|
+
z-ai function \
|
|
48
|
+
-n web_search \
|
|
49
|
+
-a '{"query": "machine learning", "num": 5}'
|
|
50
|
+
|
|
51
|
+
# Search with recency filter (results from last N days)
|
|
52
|
+
z-ai function \
|
|
53
|
+
-n web_search \
|
|
54
|
+
-a '{"query": "cryptocurrency news", "num": 10, "recency_days": 7}'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Save Search Results
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Save results to JSON file
|
|
61
|
+
z-ai function \
|
|
62
|
+
-n web_search \
|
|
63
|
+
-a '{"query": "climate change research", "num": 5}' \
|
|
64
|
+
-o search_results.json
|
|
65
|
+
|
|
66
|
+
# Recent news with file output
|
|
67
|
+
z-ai function \
|
|
68
|
+
-n web_search \
|
|
69
|
+
-a '{"query": "AI breakthroughs", "num": 3, "recency_days": 1}' \
|
|
70
|
+
-o ai_news.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Advanced Search Examples
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Search for specific topics
|
|
77
|
+
z-ai function \
|
|
78
|
+
-n web_search \
|
|
79
|
+
-a '{"query": "quantum computing applications", "num": 8}' \
|
|
80
|
+
-o quantum.json
|
|
81
|
+
|
|
82
|
+
# Find recent scientific papers
|
|
83
|
+
z-ai function \
|
|
84
|
+
-n web_search \
|
|
85
|
+
-a '{"query": "genomics research", "num": 5, "recency_days": 30}' \
|
|
86
|
+
-o genomics.json
|
|
87
|
+
|
|
88
|
+
# Technology news from last 24 hours
|
|
89
|
+
z-ai function \
|
|
90
|
+
-n web_search \
|
|
91
|
+
-a '{"query": "tech industry updates", "recency_days": 1}' \
|
|
92
|
+
-o today_tech.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### CLI Parameters
|
|
96
|
+
|
|
97
|
+
- `--name, -n`: **Required** - Function name (use "web_search")
|
|
98
|
+
- `--args, -a`: **Required** - JSON arguments object with:
|
|
99
|
+
- `query` (string, required): Search keywords
|
|
100
|
+
- `num` (number, optional): Number of results (default: 10)
|
|
101
|
+
- `recency_days` (number, optional): Filter results from last N days
|
|
102
|
+
- `--output, -o <path>`: Optional - Output file path (JSON format)
|
|
103
|
+
|
|
104
|
+
### Search Result Structure
|
|
105
|
+
|
|
106
|
+
Each result contains:
|
|
107
|
+
- `url`: Full URL of the result
|
|
108
|
+
- `name`: Title of the page
|
|
109
|
+
- `snippet`: Preview text/description
|
|
110
|
+
- `host_name`: Domain name
|
|
111
|
+
- `rank`: Result ranking
|
|
112
|
+
- `date`: Publication/update date
|
|
113
|
+
- `favicon`: Favicon URL
|
|
114
|
+
|
|
115
|
+
### When to Use CLI vs SDK
|
|
116
|
+
|
|
117
|
+
**Use CLI for:**
|
|
118
|
+
- Quick information lookups
|
|
119
|
+
- Testing search queries
|
|
120
|
+
- Simple automation scripts
|
|
121
|
+
- One-off research tasks
|
|
122
|
+
|
|
123
|
+
**Use SDK for:**
|
|
124
|
+
- Dynamic search in applications
|
|
125
|
+
- Multi-step search workflows
|
|
126
|
+
- Custom result processing and filtering
|
|
127
|
+
- Production applications with complex logic
|
|
128
|
+
|
|
129
|
+
## Search Result Type
|
|
130
|
+
|
|
131
|
+
Each search result is a `SearchFunctionResultItem` with the following structure:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface SearchFunctionResultItem {
|
|
135
|
+
url: string; // Full URL of the result
|
|
136
|
+
name: string; // Title of the page
|
|
137
|
+
snippet: string; // Preview text/description
|
|
138
|
+
host_name: string; // Domain name
|
|
139
|
+
rank: number; // Result ranking
|
|
140
|
+
date: string; // Publication/update date
|
|
141
|
+
favicon: string; // Favicon URL
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Basic Web Search
|
|
146
|
+
|
|
147
|
+
### Simple Search Query
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
151
|
+
|
|
152
|
+
async function searchWeb(query) {
|
|
153
|
+
const zai = await ZAI.create();
|
|
154
|
+
|
|
155
|
+
const results = await zai.functions.invoke('web_search', {
|
|
156
|
+
query: query,
|
|
157
|
+
num: 10
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return results;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Usage
|
|
164
|
+
const searchResults = await searchWeb('What is the capital of France?');
|
|
165
|
+
console.log('Search Results:', searchResults);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Search with Custom Result Count
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
172
|
+
|
|
173
|
+
async function searchWithLimit(query, numberOfResults) {
|
|
174
|
+
const zai = await ZAI.create();
|
|
175
|
+
|
|
176
|
+
const results = await zai.functions.invoke('web_search', {
|
|
177
|
+
query: query,
|
|
178
|
+
num: numberOfResults
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return results;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Usage - Get top 5 results
|
|
185
|
+
const topResults = await searchWithLimit('artificial intelligence news', 5);
|
|
186
|
+
|
|
187
|
+
// Usage - Get top 20 results
|
|
188
|
+
const moreResults = await searchWithLimit('JavaScript frameworks', 20);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Formatted Search Results
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
195
|
+
|
|
196
|
+
async function getFormattedResults(query) {
|
|
197
|
+
const zai = await ZAI.create();
|
|
198
|
+
|
|
199
|
+
const results = await zai.functions.invoke('web_search', {
|
|
200
|
+
query: query,
|
|
201
|
+
num: 10
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Format results for display
|
|
205
|
+
const formatted = results.map((item, index) => ({
|
|
206
|
+
position: index + 1,
|
|
207
|
+
title: item.name,
|
|
208
|
+
url: item.url,
|
|
209
|
+
description: item.snippet,
|
|
210
|
+
domain: item.host_name,
|
|
211
|
+
publishDate: item.date
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
return formatted;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Usage
|
|
218
|
+
const results = await getFormattedResults('climate change solutions');
|
|
219
|
+
results.forEach(result => {
|
|
220
|
+
console.log(`${result.position}. ${result.title}`);
|
|
221
|
+
console.log(` ${result.url}`);
|
|
222
|
+
console.log(` ${result.description}`);
|
|
223
|
+
console.log('');
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Advanced Use Cases
|
|
228
|
+
|
|
229
|
+
### Search with Result Processing
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
233
|
+
|
|
234
|
+
class SearchProcessor {
|
|
235
|
+
constructor() {
|
|
236
|
+
this.zai = null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async initialize() {
|
|
240
|
+
this.zai = await ZAI.create();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async search(query, options = {}) {
|
|
244
|
+
const {
|
|
245
|
+
num = 10,
|
|
246
|
+
filterDomain = null,
|
|
247
|
+
minSnippetLength = 0
|
|
248
|
+
} = options;
|
|
249
|
+
|
|
250
|
+
const results = await this.zai.functions.invoke('web_search', {
|
|
251
|
+
query: query,
|
|
252
|
+
num: num
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Filter results
|
|
256
|
+
let filtered = results;
|
|
257
|
+
|
|
258
|
+
if (filterDomain) {
|
|
259
|
+
filtered = filtered.filter(item =>
|
|
260
|
+
item.host_name.includes(filterDomain)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (minSnippetLength > 0) {
|
|
265
|
+
filtered = filtered.filter(item =>
|
|
266
|
+
item.snippet.length >= minSnippetLength
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return filtered;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
extractDomains(results) {
|
|
274
|
+
return [...new Set(results.map(item => item.host_name))];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
groupByDomain(results) {
|
|
278
|
+
const grouped = {};
|
|
279
|
+
|
|
280
|
+
results.forEach(item => {
|
|
281
|
+
if (!grouped[item.host_name]) {
|
|
282
|
+
grouped[item.host_name] = [];
|
|
283
|
+
}
|
|
284
|
+
grouped[item.host_name].push(item);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
return grouped;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
sortByDate(results, ascending = false) {
|
|
291
|
+
return results.sort((a, b) => {
|
|
292
|
+
const dateA = new Date(a.date);
|
|
293
|
+
const dateB = new Date(b.date);
|
|
294
|
+
return ascending ? dateA - dateB : dateB - dateA;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Usage
|
|
300
|
+
const processor = new SearchProcessor();
|
|
301
|
+
await processor.initialize();
|
|
302
|
+
|
|
303
|
+
const results = await processor.search('machine learning tutorials', {
|
|
304
|
+
num: 15,
|
|
305
|
+
minSnippetLength: 50
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
console.log('Domains found:', processor.extractDomains(results));
|
|
309
|
+
console.log('Grouped by domain:', processor.groupByDomain(results));
|
|
310
|
+
console.log('Sorted by date:', processor.sortByDate(results));
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### News Search
|
|
314
|
+
|
|
315
|
+
```javascript
|
|
316
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
317
|
+
|
|
318
|
+
async function searchNews(topic, timeframe = 'recent') {
|
|
319
|
+
const zai = await ZAI.create();
|
|
320
|
+
|
|
321
|
+
// Add time-based keywords to query
|
|
322
|
+
const timeKeywords = {
|
|
323
|
+
recent: 'latest news',
|
|
324
|
+
today: 'today news',
|
|
325
|
+
week: 'this week news',
|
|
326
|
+
month: 'this month news'
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const query = `${topic} ${timeKeywords[timeframe] || timeKeywords.recent}`;
|
|
330
|
+
|
|
331
|
+
const results = await zai.functions.invoke('web_search', {
|
|
332
|
+
query: query,
|
|
333
|
+
num: 10
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Sort by date (most recent first)
|
|
337
|
+
const sortedResults = results.sort((a, b) => {
|
|
338
|
+
return new Date(b.date) - new Date(a.date);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return sortedResults;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Usage
|
|
345
|
+
const aiNews = await searchNews('artificial intelligence', 'today');
|
|
346
|
+
const techNews = await searchNews('technology', 'week');
|
|
347
|
+
|
|
348
|
+
console.log('Latest AI News:');
|
|
349
|
+
aiNews.forEach(item => {
|
|
350
|
+
console.log(`${item.name} (${item.date})`);
|
|
351
|
+
console.log(`${item.snippet}\n`);
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Research Assistant
|
|
356
|
+
|
|
357
|
+
```javascript
|
|
358
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
359
|
+
|
|
360
|
+
class ResearchAssistant {
|
|
361
|
+
constructor() {
|
|
362
|
+
this.zai = null;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async initialize() {
|
|
366
|
+
this.zai = await ZAI.create();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async researchTopic(topic, depth = 'standard') {
|
|
370
|
+
const numResults = {
|
|
371
|
+
quick: 5,
|
|
372
|
+
standard: 10,
|
|
373
|
+
deep: 20
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const results = await this.zai.functions.invoke('web_search', {
|
|
377
|
+
query: topic,
|
|
378
|
+
num: numResults[depth] || 10
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Analyze results
|
|
382
|
+
const analysis = {
|
|
383
|
+
topic: topic,
|
|
384
|
+
totalResults: results.length,
|
|
385
|
+
sources: this.extractDomains(results),
|
|
386
|
+
topResults: results.slice(0, 5).map(r => ({
|
|
387
|
+
title: r.name,
|
|
388
|
+
url: r.url,
|
|
389
|
+
summary: r.snippet
|
|
390
|
+
})),
|
|
391
|
+
dateRange: this.getDateRange(results)
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
return analysis;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
extractDomains(results) {
|
|
398
|
+
const domains = {};
|
|
399
|
+
results.forEach(item => {
|
|
400
|
+
domains[item.host_name] = (domains[item.host_name] || 0) + 1;
|
|
401
|
+
});
|
|
402
|
+
return domains;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
getDateRange(results) {
|
|
406
|
+
const dates = results
|
|
407
|
+
.map(r => new Date(r.date))
|
|
408
|
+
.filter(d => !isNaN(d));
|
|
409
|
+
|
|
410
|
+
if (dates.length === 0) return null;
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
earliest: new Date(Math.min(...dates)),
|
|
414
|
+
latest: new Date(Math.max(...dates))
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async compareTopics(topic1, topic2) {
|
|
419
|
+
const [results1, results2] = await Promise.all([
|
|
420
|
+
this.zai.functions.invoke('web_search', { query: topic1, num: 10 }),
|
|
421
|
+
this.zai.functions.invoke('web_search', { query: topic2, num: 10 })
|
|
422
|
+
]);
|
|
423
|
+
|
|
424
|
+
const domains1 = new Set(results1.map(r => r.host_name));
|
|
425
|
+
const domains2 = new Set(results2.map(r => r.host_name));
|
|
426
|
+
|
|
427
|
+
const commonDomains = [...domains1].filter(d => domains2.has(d));
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
topic1: {
|
|
431
|
+
name: topic1,
|
|
432
|
+
results: results1.length,
|
|
433
|
+
uniqueDomains: domains1.size
|
|
434
|
+
},
|
|
435
|
+
topic2: {
|
|
436
|
+
name: topic2,
|
|
437
|
+
results: results2.length,
|
|
438
|
+
uniqueDomains: domains2.size
|
|
439
|
+
},
|
|
440
|
+
commonDomains: commonDomains
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Usage
|
|
446
|
+
const assistant = new ResearchAssistant();
|
|
447
|
+
await assistant.initialize();
|
|
448
|
+
|
|
449
|
+
const research = await assistant.researchTopic('quantum computing', 'deep');
|
|
450
|
+
console.log('Research Analysis:', research);
|
|
451
|
+
|
|
452
|
+
const comparison = await assistant.compareTopics(
|
|
453
|
+
'renewable energy',
|
|
454
|
+
'solar power'
|
|
455
|
+
);
|
|
456
|
+
console.log('Topic Comparison:', comparison);
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Search Result Validation
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
463
|
+
|
|
464
|
+
async function validateSearchResults(query) {
|
|
465
|
+
const zai = await ZAI.create();
|
|
466
|
+
|
|
467
|
+
const results = await zai.functions.invoke('web_search', {
|
|
468
|
+
query: query,
|
|
469
|
+
num: 10
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// Validate and score results
|
|
473
|
+
const validated = results.map(item => {
|
|
474
|
+
let score = 0;
|
|
475
|
+
let flags = [];
|
|
476
|
+
|
|
477
|
+
// Check snippet quality
|
|
478
|
+
if (item.snippet && item.snippet.length > 50) {
|
|
479
|
+
score += 20;
|
|
480
|
+
} else {
|
|
481
|
+
flags.push('short_snippet');
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Check date availability
|
|
485
|
+
if (item.date && item.date !== 'N/A') {
|
|
486
|
+
score += 20;
|
|
487
|
+
} else {
|
|
488
|
+
flags.push('no_date');
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// Check URL validity
|
|
492
|
+
try {
|
|
493
|
+
new URL(item.url);
|
|
494
|
+
score += 20;
|
|
495
|
+
} catch (e) {
|
|
496
|
+
flags.push('invalid_url');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Check domain quality (not perfect, but basic check)
|
|
500
|
+
if (!item.host_name.includes('spam') &&
|
|
501
|
+
!item.host_name.includes('ads')) {
|
|
502
|
+
score += 20;
|
|
503
|
+
} else {
|
|
504
|
+
flags.push('suspicious_domain');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Check title quality
|
|
508
|
+
if (item.name && item.name.length > 10) {
|
|
509
|
+
score += 20;
|
|
510
|
+
} else {
|
|
511
|
+
flags.push('short_title');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return {
|
|
515
|
+
...item,
|
|
516
|
+
qualityScore: score,
|
|
517
|
+
validationFlags: flags,
|
|
518
|
+
isHighQuality: score >= 80
|
|
519
|
+
};
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// Sort by quality score
|
|
523
|
+
return validated.sort((a, b) => b.qualityScore - a.qualityScore);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Usage
|
|
527
|
+
const validated = await validateSearchResults('best programming practices');
|
|
528
|
+
console.log('High quality results:',
|
|
529
|
+
validated.filter(r => r.isHighQuality).length
|
|
530
|
+
);
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## Best Practices
|
|
534
|
+
|
|
535
|
+
### 1. Query Optimization
|
|
536
|
+
|
|
537
|
+
```javascript
|
|
538
|
+
// Bad: Too vague
|
|
539
|
+
const bad = await searchWeb('information');
|
|
540
|
+
|
|
541
|
+
// Good: Specific and targeted
|
|
542
|
+
const good = await searchWeb('JavaScript async/await best practices 2024');
|
|
543
|
+
|
|
544
|
+
// Good: Include context
|
|
545
|
+
const goodWithContext = await searchWeb('React hooks tutorial for beginners');
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### 2. Error Handling
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
552
|
+
|
|
553
|
+
async function safeSearch(query, retries = 3) {
|
|
554
|
+
let lastError;
|
|
555
|
+
|
|
556
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
557
|
+
try {
|
|
558
|
+
const zai = await ZAI.create();
|
|
559
|
+
|
|
560
|
+
const results = await zai.functions.invoke('web_search', {
|
|
561
|
+
query: query,
|
|
562
|
+
num: 10
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
if (!Array.isArray(results) || results.length === 0) {
|
|
566
|
+
throw new Error('No results found or invalid response');
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return {
|
|
570
|
+
success: true,
|
|
571
|
+
results: results,
|
|
572
|
+
attempts: attempt
|
|
573
|
+
};
|
|
574
|
+
} catch (error) {
|
|
575
|
+
lastError = error;
|
|
576
|
+
console.error(`Attempt ${attempt} failed:`, error.message);
|
|
577
|
+
|
|
578
|
+
if (attempt < retries) {
|
|
579
|
+
// Wait before retry (exponential backoff)
|
|
580
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return {
|
|
586
|
+
success: false,
|
|
587
|
+
error: lastError.message,
|
|
588
|
+
attempts: retries
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### 3. Result Caching
|
|
594
|
+
|
|
595
|
+
```javascript
|
|
596
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
597
|
+
|
|
598
|
+
class CachedSearch {
|
|
599
|
+
constructor(cacheDuration = 3600000) { // 1 hour default
|
|
600
|
+
this.cache = new Map();
|
|
601
|
+
this.cacheDuration = cacheDuration;
|
|
602
|
+
this.zai = null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
async initialize() {
|
|
606
|
+
this.zai = await ZAI.create();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
getCacheKey(query, num) {
|
|
610
|
+
return `${query}_${num}`;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
async search(query, num = 10) {
|
|
614
|
+
const cacheKey = this.getCacheKey(query, num);
|
|
615
|
+
const cached = this.cache.get(cacheKey);
|
|
616
|
+
|
|
617
|
+
// Check if cached and not expired
|
|
618
|
+
if (cached && Date.now() - cached.timestamp < this.cacheDuration) {
|
|
619
|
+
console.log('Returning cached results');
|
|
620
|
+
return {
|
|
621
|
+
...cached.data,
|
|
622
|
+
cached: true
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Perform fresh search
|
|
627
|
+
const results = await this.zai.functions.invoke('web_search', {
|
|
628
|
+
query: query,
|
|
629
|
+
num: num
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// Cache results
|
|
633
|
+
this.cache.set(cacheKey, {
|
|
634
|
+
data: results,
|
|
635
|
+
timestamp: Date.now()
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
return {
|
|
639
|
+
results: results,
|
|
640
|
+
cached: false
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
clearCache() {
|
|
645
|
+
this.cache.clear();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
getCacheSize() {
|
|
649
|
+
return this.cache.size;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Usage
|
|
654
|
+
const search = new CachedSearch(1800000); // 30 minutes cache
|
|
655
|
+
await search.initialize();
|
|
656
|
+
|
|
657
|
+
const result1 = await search.search('TypeScript tutorial');
|
|
658
|
+
console.log('Cached:', result1.cached); // false
|
|
659
|
+
|
|
660
|
+
const result2 = await search.search('TypeScript tutorial');
|
|
661
|
+
console.log('Cached:', result2.cached); // true
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### 4. Rate Limiting
|
|
665
|
+
|
|
666
|
+
```javascript
|
|
667
|
+
class RateLimitedSearch {
|
|
668
|
+
constructor(requestsPerMinute = 60) {
|
|
669
|
+
this.zai = null;
|
|
670
|
+
this.requestsPerMinute = requestsPerMinute;
|
|
671
|
+
this.requests = [];
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
async initialize() {
|
|
675
|
+
this.zai = await ZAI.create();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
async search(query, num = 10) {
|
|
679
|
+
await this.checkRateLimit();
|
|
680
|
+
|
|
681
|
+
const results = await this.zai.functions.invoke('web_search', {
|
|
682
|
+
query: query,
|
|
683
|
+
num: num
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
this.requests.push(Date.now());
|
|
687
|
+
return results;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
async checkRateLimit() {
|
|
691
|
+
const now = Date.now();
|
|
692
|
+
const oneMinuteAgo = now - 60000;
|
|
693
|
+
|
|
694
|
+
// Remove requests older than 1 minute
|
|
695
|
+
this.requests = this.requests.filter(time => time > oneMinuteAgo);
|
|
696
|
+
|
|
697
|
+
if (this.requests.length >= this.requestsPerMinute) {
|
|
698
|
+
const oldestRequest = this.requests[0];
|
|
699
|
+
const waitTime = 60000 - (now - oldestRequest);
|
|
700
|
+
|
|
701
|
+
console.log(`Rate limit reached. Waiting ${waitTime}ms`);
|
|
702
|
+
await new Promise(resolve => setTimeout(resolve, waitTime));
|
|
703
|
+
|
|
704
|
+
// Recheck after waiting
|
|
705
|
+
return this.checkRateLimit();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
## Common Use Cases
|
|
712
|
+
|
|
713
|
+
1. **Real-time Information Retrieval**: Get current news, stock prices, weather
|
|
714
|
+
2. **Research & Analysis**: Gather information on specific topics
|
|
715
|
+
3. **Content Discovery**: Find articles, tutorials, documentation
|
|
716
|
+
4. **Competitive Analysis**: Research competitors and market trends
|
|
717
|
+
5. **Fact Checking**: Verify information against web sources
|
|
718
|
+
6. **SEO & Content Research**: Analyze search results for content strategy
|
|
719
|
+
7. **News Aggregation**: Collect news from various sources
|
|
720
|
+
8. **Academic Research**: Find papers, studies, and academic content
|
|
721
|
+
|
|
722
|
+
## Integration Examples
|
|
723
|
+
|
|
724
|
+
### Express.js Search API
|
|
725
|
+
|
|
726
|
+
```javascript
|
|
727
|
+
import express from 'express';
|
|
728
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
729
|
+
|
|
730
|
+
const app = express();
|
|
731
|
+
app.use(express.json());
|
|
732
|
+
|
|
733
|
+
let zaiInstance;
|
|
734
|
+
|
|
735
|
+
async function initZAI() {
|
|
736
|
+
zaiInstance = await ZAI.create();
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
app.get('/api/search', async (req, res) => {
|
|
740
|
+
try {
|
|
741
|
+
const { q: query, num = 10 } = req.query;
|
|
742
|
+
|
|
743
|
+
if (!query) {
|
|
744
|
+
return res.status(400).json({ error: 'Query parameter "q" is required' });
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const numResults = Math.min(parseInt(num) || 10, 20);
|
|
748
|
+
|
|
749
|
+
const results = await zaiInstance.functions.invoke('web_search', {
|
|
750
|
+
query: query,
|
|
751
|
+
num: numResults
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
res.json({
|
|
755
|
+
success: true,
|
|
756
|
+
query: query,
|
|
757
|
+
totalResults: results.length,
|
|
758
|
+
results: results
|
|
759
|
+
});
|
|
760
|
+
} catch (error) {
|
|
761
|
+
res.status(500).json({
|
|
762
|
+
success: false,
|
|
763
|
+
error: error.message
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
app.get('/api/search/news', async (req, res) => {
|
|
769
|
+
try {
|
|
770
|
+
const { topic, timeframe = 'recent' } = req.query;
|
|
771
|
+
|
|
772
|
+
if (!topic) {
|
|
773
|
+
return res.status(400).json({ error: 'Topic parameter is required' });
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const timeKeywords = {
|
|
777
|
+
recent: 'latest news',
|
|
778
|
+
today: 'today news',
|
|
779
|
+
week: 'this week news'
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
const query = `${topic} ${timeKeywords[timeframe] || timeKeywords.recent}`;
|
|
783
|
+
|
|
784
|
+
const results = await zaiInstance.functions.invoke('web_search', {
|
|
785
|
+
query: query,
|
|
786
|
+
num: 15
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
// Sort by date
|
|
790
|
+
const sortedResults = results.sort((a, b) => {
|
|
791
|
+
return new Date(b.date) - new Date(a.date);
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
res.json({
|
|
795
|
+
success: true,
|
|
796
|
+
topic: topic,
|
|
797
|
+
timeframe: timeframe,
|
|
798
|
+
results: sortedResults
|
|
799
|
+
});
|
|
800
|
+
} catch (error) {
|
|
801
|
+
res.status(500).json({
|
|
802
|
+
success: false,
|
|
803
|
+
error: error.message
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
initZAI().then(() => {
|
|
809
|
+
app.listen(3000, () => {
|
|
810
|
+
console.log('Search API running on port 3000');
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
### Search with AI Summary
|
|
816
|
+
|
|
817
|
+
```javascript
|
|
818
|
+
import ZAI from 'z-ai-web-dev-sdk';
|
|
819
|
+
|
|
820
|
+
async function searchAndSummarize(query) {
|
|
821
|
+
const zai = await ZAI.create();
|
|
822
|
+
|
|
823
|
+
// Step 1: Search the web
|
|
824
|
+
const searchResults = await zai.functions.invoke('web_search', {
|
|
825
|
+
query: query,
|
|
826
|
+
num: 10
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// Step 2: Create summary using chat completions
|
|
830
|
+
const searchContext = searchResults
|
|
831
|
+
.slice(0, 5)
|
|
832
|
+
.map((r, i) => `${i + 1}. ${r.name}\n${r.snippet}`)
|
|
833
|
+
.join('\n\n');
|
|
834
|
+
|
|
835
|
+
const completion = await zai.chat.completions.create({
|
|
836
|
+
messages: [
|
|
837
|
+
{
|
|
838
|
+
role: 'assistant',
|
|
839
|
+
content: 'You are a research assistant. Summarize search results clearly and concisely.'
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
role: 'user',
|
|
843
|
+
content: `Query: "${query}"\n\nSearch Results:\n${searchContext}\n\nProvide a comprehensive summary of these results.`
|
|
844
|
+
}
|
|
845
|
+
],
|
|
846
|
+
thinking: { type: 'disabled' }
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
const summary = completion.choices[0]?.message?.content;
|
|
850
|
+
|
|
851
|
+
return {
|
|
852
|
+
query: query,
|
|
853
|
+
summary: summary,
|
|
854
|
+
sources: searchResults.slice(0, 5).map(r => ({
|
|
855
|
+
title: r.name,
|
|
856
|
+
url: r.url
|
|
857
|
+
})),
|
|
858
|
+
totalResults: searchResults.length
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Usage
|
|
863
|
+
const result = await searchAndSummarize('benefits of renewable energy');
|
|
864
|
+
console.log('Summary:', result.summary);
|
|
865
|
+
console.log('Sources:', result.sources);
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
## Troubleshooting
|
|
869
|
+
|
|
870
|
+
**Issue**: "SDK must be used in backend"
|
|
871
|
+
- **Solution**: Ensure z-ai-web-dev-sdk is only imported and used in server-side code
|
|
872
|
+
|
|
873
|
+
**Issue**: Empty or no results returned
|
|
874
|
+
- **Solution**: Try different query terms, check internet connectivity, verify API status
|
|
875
|
+
|
|
876
|
+
**Issue**: Unexpected response format
|
|
877
|
+
- **Solution**: Verify the response is an array, check for API changes, add type validation
|
|
878
|
+
|
|
879
|
+
**Issue**: Rate limiting errors
|
|
880
|
+
- **Solution**: Implement request throttling, add delays between searches, use caching
|
|
881
|
+
|
|
882
|
+
**Issue**: Low quality search results
|
|
883
|
+
- **Solution**: Refine query terms, filter results by domain or date, validate result quality
|
|
884
|
+
|
|
885
|
+
## Performance Tips
|
|
886
|
+
|
|
887
|
+
1. **Reuse SDK Instance**: Create ZAI instance once and reuse across searches
|
|
888
|
+
2. **Implement Caching**: Cache search results to reduce API calls
|
|
889
|
+
3. **Optimize Query Terms**: Use specific, targeted queries for better results
|
|
890
|
+
4. **Limit Result Count**: Request only the number of results you need
|
|
891
|
+
5. **Parallel Searches**: Use Promise.all for multiple independent searches
|
|
892
|
+
6. **Result Filtering**: Filter results on client side when possible
|
|
893
|
+
|
|
894
|
+
## Security Considerations
|
|
895
|
+
|
|
896
|
+
1. **Input Validation**: Sanitize and validate user search queries
|
|
897
|
+
2. **Rate Limiting**: Implement rate limits to prevent abuse
|
|
898
|
+
3. **API Key Protection**: Never expose SDK credentials in client-side code
|
|
899
|
+
4. **Result Filtering**: Filter potentially harmful or inappropriate content
|
|
900
|
+
5. **URL Validation**: Validate URLs before redirecting users
|
|
901
|
+
6. **Privacy**: Don't log sensitive user search queries
|
|
902
|
+
|
|
903
|
+
## Remember
|
|
904
|
+
|
|
905
|
+
- Always use z-ai-web-dev-sdk in backend code only
|
|
906
|
+
- The SDK is already installed - import as shown in examples
|
|
907
|
+
- Search results are returned as an array of SearchFunctionResultItem objects
|
|
908
|
+
- Implement proper error handling and retries for production
|
|
909
|
+
- Cache results when appropriate to reduce API calls
|
|
910
|
+
- Use specific query terms for better search results
|
|
911
|
+
- Validate and filter results before displaying to users
|
|
912
|
+
- Check `scripts/web_search.ts` for a quick start example
|