@xagent-ai/cli 1.0.1
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/.eslintrc.js +25 -0
- package/.gitmodules +3 -0
- package/.prettierrc.json +8 -0
- package/CONTRIBUTING.md +167 -0
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/README_CN.md +280 -0
- package/dist/agents.d.ts +21 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +463 -0
- package/dist/agents.js.map +1 -0
- package/dist/ai-client.d.ts +83 -0
- package/dist/ai-client.d.ts.map +1 -0
- package/dist/ai-client.js +1280 -0
- package/dist/ai-client.js.map +1 -0
- package/dist/auth.d.ts +25 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +573 -0
- package/dist/auth.js.map +1 -0
- package/dist/cancellation.d.ts +46 -0
- package/dist/cancellation.d.ts.map +1 -0
- package/dist/cancellation.js +154 -0
- package/dist/cancellation.js.map +1 -0
- package/dist/checkpoint.d.ts +28 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +186 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +364 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +49 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +205 -0
- package/dist/config.js.map +1 -0
- package/dist/context-compressor.d.ts +51 -0
- package/dist/context-compressor.d.ts.map +1 -0
- package/dist/context-compressor.js +231 -0
- package/dist/context-compressor.js.map +1 -0
- package/dist/conversation.d.ts +34 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +221 -0
- package/dist/conversation.js.map +1 -0
- package/dist/gui-subagent/action-parser/actionParser.d.ts +19 -0
- package/dist/gui-subagent/action-parser/actionParser.d.ts.map +1 -0
- package/dist/gui-subagent/action-parser/actionParser.js +203 -0
- package/dist/gui-subagent/action-parser/actionParser.js.map +1 -0
- package/dist/gui-subagent/action-parser/constants.d.ts +8 -0
- package/dist/gui-subagent/action-parser/constants.d.ts.map +1 -0
- package/dist/gui-subagent/action-parser/constants.js +12 -0
- package/dist/gui-subagent/action-parser/constants.js.map +1 -0
- package/dist/gui-subagent/action-parser/index.d.ts +3 -0
- package/dist/gui-subagent/action-parser/index.d.ts.map +1 -0
- package/dist/gui-subagent/action-parser/index.js +6 -0
- package/dist/gui-subagent/action-parser/index.js.map +1 -0
- package/dist/gui-subagent/action-parser/types.d.ts +24 -0
- package/dist/gui-subagent/action-parser/types.d.ts.map +1 -0
- package/dist/gui-subagent/action-parser/types.js +12 -0
- package/dist/gui-subagent/action-parser/types.js.map +1 -0
- package/dist/gui-subagent/agent/gui-agent.d.ts +126 -0
- package/dist/gui-subagent/agent/gui-agent.d.ts.map +1 -0
- package/dist/gui-subagent/agent/gui-agent.js +820 -0
- package/dist/gui-subagent/agent/gui-agent.js.map +1 -0
- package/dist/gui-subagent/agent/index.d.ts +5 -0
- package/dist/gui-subagent/agent/index.d.ts.map +1 -0
- package/dist/gui-subagent/agent/index.js +5 -0
- package/dist/gui-subagent/agent/index.js.map +1 -0
- package/dist/gui-subagent/index.d.ts +43 -0
- package/dist/gui-subagent/index.d.ts.map +1 -0
- package/dist/gui-subagent/index.js +96 -0
- package/dist/gui-subagent/index.js.map +1 -0
- package/dist/gui-subagent/operator/base-operator.d.ts +108 -0
- package/dist/gui-subagent/operator/base-operator.d.ts.map +1 -0
- package/dist/gui-subagent/operator/base-operator.js +172 -0
- package/dist/gui-subagent/operator/base-operator.js.map +1 -0
- package/dist/gui-subagent/operator/browser-operator.d.ts +36 -0
- package/dist/gui-subagent/operator/browser-operator.d.ts.map +1 -0
- package/dist/gui-subagent/operator/browser-operator.js +306 -0
- package/dist/gui-subagent/operator/browser-operator.js.map +1 -0
- package/dist/gui-subagent/operator/computer-operator.d.ts +31 -0
- package/dist/gui-subagent/operator/computer-operator.d.ts.map +1 -0
- package/dist/gui-subagent/operator/computer-operator.js +441 -0
- package/dist/gui-subagent/operator/computer-operator.js.map +1 -0
- package/dist/gui-subagent/operator/desktop-operator.d.ts +55 -0
- package/dist/gui-subagent/operator/desktop-operator.d.ts.map +1 -0
- package/dist/gui-subagent/operator/desktop-operator.js +527 -0
- package/dist/gui-subagent/operator/desktop-operator.js.map +1 -0
- package/dist/gui-subagent/operator/index.d.ts +7 -0
- package/dist/gui-subagent/operator/index.d.ts.map +1 -0
- package/dist/gui-subagent/operator/index.js +6 -0
- package/dist/gui-subagent/operator/index.js.map +1 -0
- package/dist/gui-subagent/types/actions.d.ts +108 -0
- package/dist/gui-subagent/types/actions.d.ts.map +1 -0
- package/dist/gui-subagent/types/actions.js +39 -0
- package/dist/gui-subagent/types/actions.js.map +1 -0
- package/dist/gui-subagent/types/index.d.ts +6 -0
- package/dist/gui-subagent/types/index.d.ts.map +1 -0
- package/dist/gui-subagent/types/index.js +6 -0
- package/dist/gui-subagent/types/index.js.map +1 -0
- package/dist/gui-subagent/types/operator.d.ts +95 -0
- package/dist/gui-subagent/types/operator.d.ts.map +1 -0
- package/dist/gui-subagent/types/operator.js +16 -0
- package/dist/gui-subagent/types/operator.js.map +1 -0
- package/dist/gui-subagent/utils.d.ts +19 -0
- package/dist/gui-subagent/utils.d.ts.map +1 -0
- package/dist/gui-subagent/utils.js +42 -0
- package/dist/gui-subagent/utils.js.map +1 -0
- package/dist/hook.d.ts +73 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +156 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/input-history.d.ts +24 -0
- package/dist/input-history.d.ts.map +1 -0
- package/dist/input-history.js +94 -0
- package/dist/input-history.js.map +1 -0
- package/dist/input-processor.d.ts +31 -0
- package/dist/input-processor.d.ts.map +1 -0
- package/dist/input-processor.js +233 -0
- package/dist/input-processor.js.map +1 -0
- package/dist/keyboard-manager.d.ts +151 -0
- package/dist/keyboard-manager.d.ts.map +1 -0
- package/dist/keyboard-manager.js +396 -0
- package/dist/keyboard-manager.js.map +1 -0
- package/dist/logger.d.ts +75 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +339 -0
- package/dist/logger.js.map +1 -0
- package/dist/mcp.d.ts +57 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +483 -0
- package/dist/mcp.js.map +1 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +250 -0
- package/dist/memory.js.map +1 -0
- package/dist/print-system-prompt.d.ts +2 -0
- package/dist/print-system-prompt.d.ts.map +1 -0
- package/dist/print-system-prompt.js +40 -0
- package/dist/print-system-prompt.js.map +1 -0
- package/dist/session-manager.d.ts +41 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +234 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/session.d.ts +77 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +1081 -0
- package/dist/session.js.map +1 -0
- package/dist/skill-invoker.d.ts +177 -0
- package/dist/skill-invoker.d.ts.map +1 -0
- package/dist/skill-invoker.js +1643 -0
- package/dist/skill-invoker.js.map +1 -0
- package/dist/skill-loader.d.ts +76 -0
- package/dist/skill-loader.d.ts.map +1 -0
- package/dist/skill-loader.js +407 -0
- package/dist/skill-loader.js.map +1 -0
- package/dist/slash-commands.d.ts +60 -0
- package/dist/slash-commands.d.ts.map +1 -0
- package/dist/slash-commands.js +1021 -0
- package/dist/slash-commands.js.map +1 -0
- package/dist/smart-approval.d.ts +137 -0
- package/dist/smart-approval.d.ts.map +1 -0
- package/dist/smart-approval.js +512 -0
- package/dist/smart-approval.js.map +1 -0
- package/dist/system-prompt-generator.d.ts +35 -0
- package/dist/system-prompt-generator.d.ts.map +1 -0
- package/dist/system-prompt-generator.js +729 -0
- package/dist/system-prompt-generator.js.map +1 -0
- package/dist/test-boundary-conditions.d.ts.map +1 -0
- package/dist/test-boundary-conditions.js.map +1 -0
- package/dist/test-cancellation-fix.d.ts.map +1 -0
- package/dist/test-cancellation-fix.js.map +1 -0
- package/dist/test-input-history.d.ts.map +1 -0
- package/dist/test-input-history.js.map +1 -0
- package/dist/test-interaction-flow.d.ts.map +1 -0
- package/dist/test-interaction-flow.js.map +1 -0
- package/dist/test-quick.d.ts.map +1 -0
- package/dist/test-quick.js.map +1 -0
- package/dist/test-user-interaction.d.ts.map +1 -0
- package/dist/test-user-interaction.js.map +1 -0
- package/dist/theme.d.ts +353 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +383 -0
- package/dist/theme.js.map +1 -0
- package/dist/tools.d.ts +373 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +2906 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/dist/unified-session.d.ts +42 -0
- package/dist/unified-session.d.ts.map +1 -0
- package/dist/unified-session.js +271 -0
- package/dist/unified-session.js.map +1 -0
- package/dist/update.d.ts +30 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +211 -0
- package/dist/update.js.map +1 -0
- package/dist/workflow.d.ts +53 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +405 -0
- package/dist/workflow.js.map +1 -0
- package/docs/architecture/mcp-integration-guide.md +131 -0
- package/docs/architecture/overview.md +93 -0
- package/docs/architecture/tool-system-design.md +89 -0
- package/docs/cli/commands.md +189 -0
- package/docs/smart-mode.md +257 -0
- package/docs/third-party-models.md +449 -0
- package/package.json +85 -0
- package/scripts/init-skills-path.js +58 -0
- package/skills/.claude-plugin/marketplace.json +45 -0
- package/skills/README.md +94 -0
- package/skills/THIRD_PARTY_NOTICES.md +405 -0
- package/skills/skills/algorithmic-art/LICENSE.txt +202 -0
- package/skills/skills/algorithmic-art/SKILL.md +405 -0
- package/skills/skills/algorithmic-art/templates/generator_template.js +223 -0
- package/skills/skills/algorithmic-art/templates/viewer.html +599 -0
- package/skills/skills/brand-guidelines/LICENSE.txt +202 -0
- package/skills/skills/brand-guidelines/SKILL.md +73 -0
- package/skills/skills/canvas-design/LICENSE.txt +202 -0
- package/skills/skills/canvas-design/SKILL.md +130 -0
- package/skills/skills/canvas-design/canvas-fonts/ArsenalSC-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/ArsenalSC-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/BigShoulders-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/BigShoulders-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/BigShoulders-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Boldonse-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Boldonse-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/BricolageGrotesque-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/BricolageGrotesque-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/BricolageGrotesque-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/CrimsonPro-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/CrimsonPro-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/CrimsonPro-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/CrimsonPro-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/DMMono-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/DMMono-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/EricaOne-OFL.txt +94 -0
- package/skills/skills/canvas-design/canvas-fonts/EricaOne-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/GeistMono-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/GeistMono-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/GeistMono-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Gloock-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Gloock-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexMono-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexMono-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexMono-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexSerif-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexSerif-BoldItalic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexSerif-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/IBMPlexSerif-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSans-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSans-BoldItalic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSans-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSans-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSans-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSerif-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/InstrumentSerif-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Italiana-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Italiana-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/JetBrainsMono-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/JetBrainsMono-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/JetBrainsMono-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Jura-Light.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Jura-Medium.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Jura-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/LibreBaskerville-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/LibreBaskerville-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Lora-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Lora-BoldItalic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Lora-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Lora-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Lora-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/NationalPark-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/NationalPark-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/NationalPark-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/NothingYouCouldDo-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/NothingYouCouldDo-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Outfit-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Outfit-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Outfit-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/PixelifySans-Medium.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/PixelifySans-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/PoiretOne-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/PoiretOne-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/RedHatMono-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/RedHatMono-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/RedHatMono-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Silkscreen-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Silkscreen-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/SmoochSans-Medium.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/SmoochSans-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Tektur-Medium.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/Tektur-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/Tektur-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/WorkSans-Bold.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/WorkSans-BoldItalic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/WorkSans-Italic.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/WorkSans-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/WorkSans-Regular.ttf +0 -0
- package/skills/skills/canvas-design/canvas-fonts/YoungSerif-OFL.txt +93 -0
- package/skills/skills/canvas-design/canvas-fonts/YoungSerif-Regular.ttf +0 -0
- package/skills/skills/doc-coauthoring/SKILL.md +375 -0
- package/skills/skills/docx/LICENSE.txt +30 -0
- package/skills/skills/docx/SKILL.md +197 -0
- package/skills/skills/docx/docx-js.md +350 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/skills/docx/ooxml/scripts/pack.py +159 -0
- package/skills/skills/docx/ooxml/scripts/unpack.py +29 -0
- package/skills/skills/docx/ooxml/scripts/validate.py +69 -0
- package/skills/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/skills/docx/ooxml/scripts/validation/base.py +951 -0
- package/skills/skills/docx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/skills/docx/ooxml.md +610 -0
- package/skills/skills/docx/scripts/__init__.py +1 -0
- package/skills/skills/docx/scripts/document.py +1276 -0
- package/skills/skills/docx/scripts/templates/comments.xml +3 -0
- package/skills/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/skills/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/skills/skills/docx/scripts/templates/people.xml +3 -0
- package/skills/skills/docx/scripts/utilities.py +374 -0
- package/skills/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/skills/frontend-design/SKILL.md +42 -0
- package/skills/skills/internal-comms/LICENSE.txt +202 -0
- package/skills/skills/internal-comms/SKILL.md +32 -0
- package/skills/skills/internal-comms/examples/3p-updates.md +47 -0
- package/skills/skills/internal-comms/examples/company-newsletter.md +65 -0
- package/skills/skills/internal-comms/examples/faq-answers.md +30 -0
- package/skills/skills/internal-comms/examples/general-comms.md +16 -0
- package/skills/skills/mcp-builder/LICENSE.txt +202 -0
- package/skills/skills/mcp-builder/SKILL.md +236 -0
- package/skills/skills/mcp-builder/reference/evaluation.md +602 -0
- package/skills/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/skills/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/skills/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/skills/skills/mcp-builder/scripts/connections.py +151 -0
- package/skills/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/skills/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/skills/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/skills/skills/pdf/LICENSE.txt +30 -0
- package/skills/skills/pdf/SKILL.md +294 -0
- package/skills/skills/pdf/forms.md +205 -0
- package/skills/skills/pdf/reference.md +612 -0
- package/skills/skills/pdf/scripts/check_bounding_boxes.py +70 -0
- package/skills/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
- package/skills/skills/pdf/scripts/check_fillable_fields.py +12 -0
- package/skills/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
- package/skills/skills/pdf/scripts/create_validation_image.py +41 -0
- package/skills/skills/pdf/scripts/extract_form_field_info.py +152 -0
- package/skills/skills/pdf/scripts/fill_fillable_fields.py +114 -0
- package/skills/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
- package/skills/skills/pptx/LICENSE.txt +30 -0
- package/skills/skills/pptx/SKILL.md +484 -0
- package/skills/skills/pptx/html2pptx.md +625 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/skills/pptx/ooxml/scripts/pack.py +159 -0
- package/skills/skills/pptx/ooxml/scripts/unpack.py +29 -0
- package/skills/skills/pptx/ooxml/scripts/validate.py +69 -0
- package/skills/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
- package/skills/skills/pptx/ooxml/scripts/validation/base.py +951 -0
- package/skills/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
- package/skills/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
- package/skills/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
- package/skills/skills/pptx/ooxml.md +427 -0
- package/skills/skills/pptx/scripts/html2pptx.js +979 -0
- package/skills/skills/pptx/scripts/inventory.py +1020 -0
- package/skills/skills/pptx/scripts/rearrange.py +231 -0
- package/skills/skills/pptx/scripts/replace.py +385 -0
- package/skills/skills/pptx/scripts/thumbnail.py +450 -0
- package/skills/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skills/skill-creator/SKILL.md +356 -0
- package/skills/skills/skill-creator/references/output-patterns.md +82 -0
- package/skills/skills/skill-creator/references/workflows.md +28 -0
- package/skills/skills/skill-creator/scripts/init_skill.py +303 -0
- package/skills/skills/skill-creator/scripts/package_skill.py +110 -0
- package/skills/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/skills/skills/slack-gif-creator/LICENSE.txt +202 -0
- package/skills/skills/slack-gif-creator/SKILL.md +254 -0
- package/skills/skills/slack-gif-creator/core/easing.py +234 -0
- package/skills/skills/slack-gif-creator/core/frame_composer.py +176 -0
- package/skills/skills/slack-gif-creator/core/gif_builder.py +269 -0
- package/skills/skills/slack-gif-creator/core/validators.py +136 -0
- package/skills/skills/slack-gif-creator/requirements.txt +4 -0
- package/skills/skills/theme-factory/LICENSE.txt +202 -0
- package/skills/skills/theme-factory/SKILL.md +59 -0
- package/skills/skills/theme-factory/theme-showcase.pdf +0 -0
- package/skills/skills/theme-factory/themes/arctic-frost.md +19 -0
- package/skills/skills/theme-factory/themes/botanical-garden.md +19 -0
- package/skills/skills/theme-factory/themes/desert-rose.md +19 -0
- package/skills/skills/theme-factory/themes/forest-canopy.md +19 -0
- package/skills/skills/theme-factory/themes/golden-hour.md +19 -0
- package/skills/skills/theme-factory/themes/midnight-galaxy.md +19 -0
- package/skills/skills/theme-factory/themes/modern-minimalist.md +19 -0
- package/skills/skills/theme-factory/themes/ocean-depths.md +19 -0
- package/skills/skills/theme-factory/themes/sunset-boulevard.md +19 -0
- package/skills/skills/theme-factory/themes/tech-innovation.md +19 -0
- package/skills/skills/web-artifacts-builder/LICENSE.txt +202 -0
- package/skills/skills/web-artifacts-builder/SKILL.md +74 -0
- package/skills/skills/web-artifacts-builder/scripts/bundle-artifact.sh +54 -0
- package/skills/skills/web-artifacts-builder/scripts/init-artifact.sh +322 -0
- package/skills/skills/webapp-testing/LICENSE.txt +202 -0
- package/skills/skills/webapp-testing/SKILL.md +96 -0
- package/skills/skills/webapp-testing/examples/console_logging.py +35 -0
- package/skills/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/skills/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/skills/skills/webapp-testing/scripts/with_server.py +106 -0
- package/skills/skills/xlsx/LICENSE.txt +30 -0
- package/skills/skills/xlsx/SKILL.md +289 -0
- package/skills/skills/xlsx/recalc.py +178 -0
- package/skills/spec/agent-skills-spec.md +3 -0
- package/skills/template/SKILL.md +6 -0
- package/src/agents.ts +504 -0
- package/src/ai-client.ts +1456 -0
- package/src/auth.ts +648 -0
- package/src/cancellation.ts +176 -0
- package/src/checkpoint.ts +219 -0
- package/src/cli.ts +384 -0
- package/src/config.ts +248 -0
- package/src/context-compressor.ts +290 -0
- package/src/conversation.ts +288 -0
- package/src/gui-subagent/action-parser/actionParser.ts +312 -0
- package/src/gui-subagent/action-parser/constants.ts +12 -0
- package/src/gui-subagent/action-parser/index.ts +6 -0
- package/src/gui-subagent/action-parser/types.ts +31 -0
- package/src/gui-subagent/agent/gui-agent.ts +982 -0
- package/src/gui-subagent/agent/index.ts +5 -0
- package/src/gui-subagent/index.ts +139 -0
- package/src/gui-subagent/operator/base-operator.ts +246 -0
- package/src/gui-subagent/operator/computer-operator.ts +520 -0
- package/src/gui-subagent/operator/index.ts +7 -0
- package/src/gui-subagent/types/actions.ts +263 -0
- package/src/gui-subagent/types/index.ts +6 -0
- package/src/gui-subagent/types/operator.ts +106 -0
- package/src/gui-subagent/utils.ts +51 -0
- package/src/index.ts +18 -0
- package/src/input-processor.ts +282 -0
- package/src/logger.ts +438 -0
- package/src/mcp.ts +563 -0
- package/src/memory.ts +303 -0
- package/src/session-manager.ts +308 -0
- package/src/session.ts +1280 -0
- package/src/skill-invoker.ts +1888 -0
- package/src/skill-loader.ts +476 -0
- package/src/slash-commands.ts +1150 -0
- package/src/smart-approval.ts +595 -0
- package/src/system-prompt-generator.ts +786 -0
- package/src/theme.ts +455 -0
- package/src/tools.ts +3398 -0
- package/src/types.ts +198 -0
- package/src/update.ts +270 -0
- package/src/workflow.ts +508 -0
- package/tsconfig.json +22 -0
- package/vitest.config.ts +19 -0
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUI Agent for xagent
|
|
3
|
+
* Orchestrates desktop automation with AI-powered action execution
|
|
4
|
+
* Based on UI-TARS architecture with computer control only
|
|
5
|
+
*
|
|
6
|
+
* This implementation is aligned with packages/ui-tars/sdk/src/GUIAgent.ts
|
|
7
|
+
*/
|
|
8
|
+
import { sleep, asyncRetry } from '../utils.js';
|
|
9
|
+
import { actionParser } from '../action-parser/index.js';
|
|
10
|
+
import { colors, icons } from '../../theme.js';
|
|
11
|
+
import { getLogger } from '../../logger.js';
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to truncate long text
|
|
14
|
+
*/
|
|
15
|
+
function truncateText(text, maxLength = 200) {
|
|
16
|
+
if (!text)
|
|
17
|
+
return '';
|
|
18
|
+
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Helper function to indent multiline text
|
|
22
|
+
*/
|
|
23
|
+
function indentMultiline(text, indent) {
|
|
24
|
+
return text.split('\n').map(line => indent + line).join('\n');
|
|
25
|
+
}
|
|
26
|
+
const guiLogger = getLogger();
|
|
27
|
+
// UI-TARS Status Enum
|
|
28
|
+
export var GUIAgentStatus;
|
|
29
|
+
(function (GUIAgentStatus) {
|
|
30
|
+
GUIAgentStatus["INIT"] = "init";
|
|
31
|
+
GUIAgentStatus["RUNNING"] = "running";
|
|
32
|
+
GUIAgentStatus["PAUSE"] = "paused";
|
|
33
|
+
GUIAgentStatus["END"] = "end";
|
|
34
|
+
GUIAgentStatus["ERROR"] = "error";
|
|
35
|
+
GUIAgentStatus["USER_STOPPED"] = "user_stopped";
|
|
36
|
+
GUIAgentStatus["CALL_USER"] = "call_user";
|
|
37
|
+
})(GUIAgentStatus || (GUIAgentStatus = {}));
|
|
38
|
+
// UI-TARS constants (aligned with @ui-tars/shared/constants)
|
|
39
|
+
const MAX_LOOP_COUNT = 100;
|
|
40
|
+
const MAX_SNAPSHOT_ERR_CNT = 5;
|
|
41
|
+
const MAX_STEP_RETRIES = 3; // Max retries for a single action step before giving up
|
|
42
|
+
const IMAGE_PLACEHOLDER = '{{IMG_PLACEHOLDER_0}}';
|
|
43
|
+
export class GUIAgent {
|
|
44
|
+
operator;
|
|
45
|
+
model;
|
|
46
|
+
modelBaseUrl;
|
|
47
|
+
modelApiKey;
|
|
48
|
+
systemPrompt;
|
|
49
|
+
loopIntervalInMs;
|
|
50
|
+
maxLoopCount;
|
|
51
|
+
logger;
|
|
52
|
+
signal;
|
|
53
|
+
onData;
|
|
54
|
+
onError;
|
|
55
|
+
showAIDebugInfo;
|
|
56
|
+
retry;
|
|
57
|
+
isPaused = false;
|
|
58
|
+
resumePromise = null;
|
|
59
|
+
resolveResume = null;
|
|
60
|
+
isStopped = false;
|
|
61
|
+
constructor(config) {
|
|
62
|
+
this.operator = config.operator;
|
|
63
|
+
this.model = config.model || '';
|
|
64
|
+
this.modelBaseUrl = config.modelBaseUrl || '';
|
|
65
|
+
this.modelApiKey = config.modelApiKey || '';
|
|
66
|
+
this.loopIntervalInMs = config.loopIntervalInMs || 0;
|
|
67
|
+
this.maxLoopCount = config.maxLoopCount || MAX_LOOP_COUNT;
|
|
68
|
+
this.logger = config.logger || guiLogger;
|
|
69
|
+
this.signal = config.signal;
|
|
70
|
+
this.onData = config.onData;
|
|
71
|
+
this.onError = config.onError;
|
|
72
|
+
this.showAIDebugInfo = config.showAIDebugInfo ?? false;
|
|
73
|
+
this.retry = config.retry;
|
|
74
|
+
this.systemPrompt = config.systemPrompt || this.buildSystemPrompt();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Display conversation results with formatting similar to session.ts (simplified)
|
|
78
|
+
*/
|
|
79
|
+
displayConversationResult(conversation, iteration, indentLevel = 1) {
|
|
80
|
+
const indent = ' '.repeat(indentLevel);
|
|
81
|
+
const innerIndent = ' '.repeat(indentLevel + 1);
|
|
82
|
+
const maxWidth = process.stdout.columns || 80;
|
|
83
|
+
if (conversation.from === 'assistant') {
|
|
84
|
+
// Display assistant response (action)
|
|
85
|
+
const content = conversation.value || '';
|
|
86
|
+
const timing = conversation.timing;
|
|
87
|
+
// Simplified: show step number and action
|
|
88
|
+
const actionSummary = content.replace(/Thought:[\s\S]*?Action:\s*/i, '').trim();
|
|
89
|
+
const actionType = conversation.predictionParsed?.[0]?.action_type || 'action';
|
|
90
|
+
console.log(`${indent}${colors.primaryBright(`[${iteration}]`)} ${colors.textMuted(actionType)}${timing ? colors.textDim(` (${timing.cost}ms)`) : ''}`);
|
|
91
|
+
// Optionally show action details on next line if verbose
|
|
92
|
+
if (this.showAIDebugInfo && actionSummary) {
|
|
93
|
+
const truncatedSummary = actionSummary.length > 60 ? actionSummary.substring(0, 60) + '...' : actionSummary;
|
|
94
|
+
console.log(`${innerIndent}${colors.textMuted(truncatedSummary)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (conversation.from === 'human' && conversation.screenshotBase64) {
|
|
98
|
+
// Show minimal indicator for screenshot
|
|
99
|
+
if (this.showAIDebugInfo) {
|
|
100
|
+
const timing = conversation.timing;
|
|
101
|
+
console.log(`${indent}${colors.textMuted(`${icons.loading} screenshot${timing ? ` (${timing.cost}ms)` : ''}`)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Display status message
|
|
107
|
+
*/
|
|
108
|
+
displayStatus(data, iteration, indentLevel = 1) {
|
|
109
|
+
const indent = ' '.repeat(indentLevel);
|
|
110
|
+
const status = data.status;
|
|
111
|
+
switch (status) {
|
|
112
|
+
case GUIAgentStatus.RUNNING:
|
|
113
|
+
console.log(`${indent}${colors.info(`${icons.loading} Step ${iteration}: Running...`)}`);
|
|
114
|
+
break;
|
|
115
|
+
case GUIAgentStatus.END:
|
|
116
|
+
// Handled by caller
|
|
117
|
+
break;
|
|
118
|
+
case GUIAgentStatus.ERROR:
|
|
119
|
+
if (data.error) {
|
|
120
|
+
console.log(`${indent}${colors.error(`${icons.cross} ${data.error}`)}`);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case GUIAgentStatus.CALL_USER:
|
|
124
|
+
console.log(`${indent}${colors.warning(`${icons.warning} Needs user input`)}`);
|
|
125
|
+
break;
|
|
126
|
+
case GUIAgentStatus.USER_STOPPED:
|
|
127
|
+
console.log(`${indent}${colors.warning(`${icons.warning} Stopped`)}`);
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
buildSystemPrompt() {
|
|
134
|
+
return `You are a GUI agent. You are given a task and your action history, with screenshots. You need to perform the next action to complete the task.
|
|
135
|
+
|
|
136
|
+
## Output Format
|
|
137
|
+
\`
|
|
138
|
+
Thought: ...
|
|
139
|
+
Action: ...
|
|
140
|
+
\`
|
|
141
|
+
|
|
142
|
+
## Action Space
|
|
143
|
+
click(point='<point>x1 y1</point>')
|
|
144
|
+
left_double(point='<point>x1 y1</point>')
|
|
145
|
+
right_single(point='<point>x1 y1</point>')
|
|
146
|
+
drag(start_point='<point>x1 y1</point>', end_point='<point>x2 y2</point>')
|
|
147
|
+
hotkey(key='ctrl c') # Split keys with a space and use lowercase. Also, do not use more than 3 keys in one hotkey action.
|
|
148
|
+
type(content='xxx') # Use escape characters \', \", and \n in content part to ensure we can parse the content in normal python string format. If you want to submit your input, use \n at the end of content.
|
|
149
|
+
scroll(point='<point>x1 y1</point>', direction='down or up or right or left') # Show more information on the \`direction\` side.
|
|
150
|
+
open_url(url='https://xxx') # Open URL in browser
|
|
151
|
+
wait() #Sleep for 5s and take a screenshot to check for any changes.
|
|
152
|
+
finished(content='xxx') # Use escape characters \', \", and \n in content part to ensure we can parse the content in normal python string format.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## Note
|
|
158
|
+
- Use {language} in \`Thought\` part.
|
|
159
|
+
- Write a small plan and finally summarize your next action (with its target element) in one sentence in \`Thought\` part.
|
|
160
|
+
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
async initialize() {
|
|
164
|
+
await this.operator.doInitialize();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Run the GUI agent with a single instruction (UI-TARS style)
|
|
168
|
+
* All operations are determined by the GUI model
|
|
169
|
+
*/
|
|
170
|
+
async run(instruction) {
|
|
171
|
+
const data = {
|
|
172
|
+
status: GUIAgentStatus.INIT,
|
|
173
|
+
conversations: [
|
|
174
|
+
{
|
|
175
|
+
from: 'human',
|
|
176
|
+
value: instruction,
|
|
177
|
+
timing: {
|
|
178
|
+
start: Date.now(),
|
|
179
|
+
end: Date.now(),
|
|
180
|
+
cost: 0,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
// Initialize operator for initial screenshot
|
|
186
|
+
try {
|
|
187
|
+
await this.operator.doInitialize();
|
|
188
|
+
}
|
|
189
|
+
catch (initError) {
|
|
190
|
+
const errorMsg = initError instanceof Error ? initError.message : 'Unknown error';
|
|
191
|
+
this.logger.error(`[GUIAgent] Failed to initialize operator: ${errorMsg}`);
|
|
192
|
+
// Check if it's an RDP-related issue
|
|
193
|
+
if (errorMsg.includes('screen') || errorMsg.includes('capture') || errorMsg.includes('display')) {
|
|
194
|
+
data.status = GUIAgentStatus.ERROR;
|
|
195
|
+
data.error = 'Failed to initialize screen capture. This may be caused by:\n' +
|
|
196
|
+
' 1. Remote Desktop session disconnected or minimized\n' +
|
|
197
|
+
' 2. Display driver issues\n' +
|
|
198
|
+
'Suggestion: Ensure your display is active and try again.';
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
data.status = GUIAgentStatus.ERROR;
|
|
202
|
+
data.error = `Failed to initialize operator: ${errorMsg}`;
|
|
203
|
+
}
|
|
204
|
+
return data;
|
|
205
|
+
}
|
|
206
|
+
const currentTime = Date.now();
|
|
207
|
+
if (this.showAIDebugInfo) {
|
|
208
|
+
this.logger.debug('[GUIAgent] run:', {
|
|
209
|
+
systemPrompt: this.systemPrompt,
|
|
210
|
+
model: this.model,
|
|
211
|
+
maxLoopCount: this.maxLoopCount,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
let loopCnt = 0;
|
|
215
|
+
let snapshotErrCnt = 0;
|
|
216
|
+
// Start running agent
|
|
217
|
+
data.status = GUIAgentStatus.RUNNING;
|
|
218
|
+
data.systemPrompt = this.systemPrompt;
|
|
219
|
+
console.log(`${colors.primaryBright(`${icons.rocket} GUI Agent started`)}`);
|
|
220
|
+
console.log('');
|
|
221
|
+
await this.onData?.({ ...data, conversations: [] });
|
|
222
|
+
try {
|
|
223
|
+
// eslint-disable-next-line no-constant-condition
|
|
224
|
+
while (true) {
|
|
225
|
+
if (this.showAIDebugInfo) {
|
|
226
|
+
this.logger.debug('[GUIAgent] loopCnt:', loopCnt);
|
|
227
|
+
}
|
|
228
|
+
// Check pause status
|
|
229
|
+
if (this.isPaused && this.resumePromise) {
|
|
230
|
+
data.status = GUIAgentStatus.PAUSE;
|
|
231
|
+
await this.onData?.({ ...data, conversations: [] });
|
|
232
|
+
await this.resumePromise;
|
|
233
|
+
data.status = GUIAgentStatus.RUNNING;
|
|
234
|
+
await this.onData?.({ ...data, conversations: [] });
|
|
235
|
+
}
|
|
236
|
+
// Check stop or aborted status
|
|
237
|
+
if (this.isStopped ||
|
|
238
|
+
data.status !== GUIAgentStatus.RUNNING ||
|
|
239
|
+
this.signal?.aborted) {
|
|
240
|
+
if (this.signal?.aborted) {
|
|
241
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
// Check loop limit
|
|
246
|
+
if (loopCnt >= this.maxLoopCount) {
|
|
247
|
+
data.status = GUIAgentStatus.ERROR;
|
|
248
|
+
data.error = `Has reached max loop count: ${loopCnt}`;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
// Check screenshot error limit
|
|
252
|
+
if (snapshotErrCnt >= MAX_SNAPSHOT_ERR_CNT) {
|
|
253
|
+
data.status = GUIAgentStatus.ERROR;
|
|
254
|
+
data.error = 'Screenshot failed too many times. Stopping task.';
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
loopCnt += 1;
|
|
258
|
+
const start = Date.now();
|
|
259
|
+
// Take screenshot (single attempt - no retry to avoid infinite loops)
|
|
260
|
+
let snapshot;
|
|
261
|
+
try {
|
|
262
|
+
snapshot = await this.operator.doScreenshot();
|
|
263
|
+
}
|
|
264
|
+
catch (screenshotError) {
|
|
265
|
+
const errorMsg = screenshotError instanceof Error ? screenshotError.message : 'Unknown error';
|
|
266
|
+
this.logger.warn(`[GUIAgent] Screenshot exception: ${errorMsg}`);
|
|
267
|
+
snapshotErrCnt += 1;
|
|
268
|
+
data.status = GUIAgentStatus.ERROR;
|
|
269
|
+
data.error = `Screenshot failed ${snapshotErrCnt} times. Stopping task.`;
|
|
270
|
+
this.logger.error(`[GUIAgent] ${data.error}`);
|
|
271
|
+
await sleep(1000);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
// Check if screenshot returned failure status
|
|
275
|
+
if (snapshot.status === 'failed') {
|
|
276
|
+
const errorMsg = snapshot.errorMessage || 'Unknown error';
|
|
277
|
+
this.logger.warn(`[GUIAgent] Screenshot failed: ${errorMsg}`);
|
|
278
|
+
snapshotErrCnt += 1;
|
|
279
|
+
data.status = GUIAgentStatus.ERROR;
|
|
280
|
+
data.error = `Screenshot failed ${snapshotErrCnt} times. Stopping task.`;
|
|
281
|
+
this.logger.error(`[GUIAgent] ${data.error}`);
|
|
282
|
+
await sleep(1000);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
// Check abort immediately after screenshot
|
|
286
|
+
if (this.signal?.aborted) {
|
|
287
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
// Validate screenshot
|
|
291
|
+
const isValidImage = !!(snapshot?.base64);
|
|
292
|
+
if (!isValidImage) {
|
|
293
|
+
snapshotErrCnt += 1;
|
|
294
|
+
data.status = GUIAgentStatus.ERROR;
|
|
295
|
+
data.error = `Screenshot failed ${snapshotErrCnt} times. Stopping task.`;
|
|
296
|
+
this.logger.error(`[GUIAgent] ${data.error}`);
|
|
297
|
+
await sleep(1000);
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
// Reset error counter on successful screenshot
|
|
301
|
+
snapshotErrCnt = 0;
|
|
302
|
+
const end = Date.now();
|
|
303
|
+
// Get screen context
|
|
304
|
+
const screenContext = await this.operator.getScreenContext();
|
|
305
|
+
// Add screenshot to conversation
|
|
306
|
+
data.conversations.push({
|
|
307
|
+
from: 'human',
|
|
308
|
+
value: IMAGE_PLACEHOLDER,
|
|
309
|
+
screenshotBase64: snapshot.base64,
|
|
310
|
+
screenshotContext: {
|
|
311
|
+
size: {
|
|
312
|
+
width: screenContext.width,
|
|
313
|
+
height: screenContext.height,
|
|
314
|
+
},
|
|
315
|
+
scaleFactor: snapshot.scaleFactor ?? screenContext.scaleFactor,
|
|
316
|
+
},
|
|
317
|
+
timing: {
|
|
318
|
+
start,
|
|
319
|
+
end,
|
|
320
|
+
cost: end - start,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
await this.onData?.({
|
|
324
|
+
...data,
|
|
325
|
+
conversations: data.conversations.slice(-1),
|
|
326
|
+
});
|
|
327
|
+
// Display screenshot notification
|
|
328
|
+
const latestScreenshot = data.conversations[data.conversations.length - 1];
|
|
329
|
+
if (latestScreenshot && latestScreenshot.from === 'human' && latestScreenshot.screenshotBase64) {
|
|
330
|
+
this.displayConversationResult(latestScreenshot, loopCnt);
|
|
331
|
+
}
|
|
332
|
+
// Build messages for model
|
|
333
|
+
const messages = this.buildModelMessages(data.conversations, data.systemPrompt);
|
|
334
|
+
// Check abort before model call
|
|
335
|
+
if (this.signal?.aborted) {
|
|
336
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
// Invoke model with retry
|
|
340
|
+
let prediction;
|
|
341
|
+
let parsedPredictions;
|
|
342
|
+
try {
|
|
343
|
+
const modelResult = await asyncRetry(async (bail) => {
|
|
344
|
+
try {
|
|
345
|
+
const result = await this.callModelAPI(messages, screenContext);
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
if (error instanceof Error &&
|
|
350
|
+
(error.name === 'AbortError' ||
|
|
351
|
+
error.message?.includes('aborted'))) {
|
|
352
|
+
bail(error);
|
|
353
|
+
return { prediction: '', parsedPredictions: [] };
|
|
354
|
+
}
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
}, {
|
|
358
|
+
retries: this.retry?.model?.maxRetries ?? 0,
|
|
359
|
+
minTimeout: 1000 * 30,
|
|
360
|
+
onRetry: this.retry?.model?.onRetry,
|
|
361
|
+
});
|
|
362
|
+
prediction = modelResult.prediction;
|
|
363
|
+
parsedPredictions = modelResult.parsedPredictions;
|
|
364
|
+
}
|
|
365
|
+
catch (modelError) {
|
|
366
|
+
// Handle multimodal model API errors with specific error messages
|
|
367
|
+
data.status = GUIAgentStatus.ERROR;
|
|
368
|
+
const errorMsg = modelError instanceof Error ? modelError.message : String(modelError);
|
|
369
|
+
// Provide specific error message based on error type
|
|
370
|
+
if (errorMsg.includes('401') || errorMsg.includes('authentication') || errorMsg.includes('API key') || errorMsg.includes('api_key') || errorMsg.includes('Unauthorized') || errorMsg.includes('invalid_api_key')) {
|
|
371
|
+
data.error = '[Multimodal Model Authentication Failed] The guiSubagentApiKey configuration is invalid.\n' +
|
|
372
|
+
'Error details: HTTP 401 - API key is invalid or expired\n' +
|
|
373
|
+
'Suggested action: Please check the guiSubagentApiKey configuration in ~/.xagent/settings.json and ensure a valid API key is set';
|
|
374
|
+
}
|
|
375
|
+
else if (errorMsg.includes('429') || errorMsg.includes('rate limit') || errorMsg.includes('too many requests')) {
|
|
376
|
+
data.error = '[Multimodal Model Rate Limit Exceeded] API requests exceed rate limit.\n' +
|
|
377
|
+
'Error details: HTTP 429 - Too Many Requests\n' +
|
|
378
|
+
'Suggested action: Please retry later, or check your API account quota settings. Wait a few minutes before retrying';
|
|
379
|
+
}
|
|
380
|
+
else if (errorMsg.includes('network') || errorMsg.includes('fetch') || errorMsg.includes('connection') || errorMsg.includes('ECONNREFUSED')) {
|
|
381
|
+
data.error = '[Multimodal Model Network Error] Cannot connect to API service.\n' +
|
|
382
|
+
'Error details: Network connection failed. Possible causes:\n' +
|
|
383
|
+
' 1. Network connection is lost\n' +
|
|
384
|
+
' 2. The guiSubagentBaseUrl configuration is incorrect\n' +
|
|
385
|
+
' 3. API service endpoint is unreachable\n' +
|
|
386
|
+
'Suggested action: Please check the guiSubagentBaseUrl configuration in ~/.xagent/settings.json and ensure network connectivity';
|
|
387
|
+
}
|
|
388
|
+
else if (errorMsg.includes('404') || errorMsg.includes('not found') || errorMsg.includes('model not found') || errorMsg.includes('InvalidEndpointOrModel.NotFound')) {
|
|
389
|
+
// Extract model name
|
|
390
|
+
const modelMatch = errorMsg.match(/model[:\s]+([^\s,"]+)|"model[:"]+([^",}]+)/i);
|
|
391
|
+
const modelName = modelMatch ? (modelMatch[1] || modelMatch[2]) : 'Unknown';
|
|
392
|
+
data.error = '[Multimodal Model Configuration Error] The model specified in guiSubagentModel does not exist or is not accessible.\n' +
|
|
393
|
+
'Error details: HTTP 404 - Model or Endpoint not found\n' +
|
|
394
|
+
'Configured model name: ' + modelName + '\n' +
|
|
395
|
+
'Suggested action: Please check the guiSubagentModel configuration in ~/.xagent/settings.json, remove or replace with a valid model name';
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
data.error = '[Multimodal Model API Call Failed]\n' +
|
|
399
|
+
'Error details: ' + errorMsg + '\n' +
|
|
400
|
+
'Please check the following configuration items:\n' +
|
|
401
|
+
' - guiSubagentApiKey: API key\n' +
|
|
402
|
+
' - guiSubagentBaseUrl: API service URL\n' +
|
|
403
|
+
' - guiSubagentModel: Model name\n' +
|
|
404
|
+
'Config file location: ~/.xagent/settings.json';
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
// Check abort immediately after model call
|
|
409
|
+
if (this.signal?.aborted) {
|
|
410
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
if (!prediction) {
|
|
414
|
+
this.logger.warn('[GUIAgent] Warning: Empty response from model, retrying...');
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (this.showAIDebugInfo) {
|
|
418
|
+
this.logger.debug('[GUIAgent] Response:', prediction);
|
|
419
|
+
this.logger.debug('[GUIAgent] Parsed Predictions:', JSON.stringify(parsedPredictions));
|
|
420
|
+
}
|
|
421
|
+
const predictionSummary = this.getSummary(prediction);
|
|
422
|
+
data.conversations.push({
|
|
423
|
+
from: 'assistant',
|
|
424
|
+
value: predictionSummary,
|
|
425
|
+
timing: {
|
|
426
|
+
start,
|
|
427
|
+
end: Date.now(),
|
|
428
|
+
cost: Date.now() - start,
|
|
429
|
+
},
|
|
430
|
+
screenshotContext: {
|
|
431
|
+
size: {
|
|
432
|
+
width: screenContext.width,
|
|
433
|
+
height: screenContext.height,
|
|
434
|
+
},
|
|
435
|
+
scaleFactor: snapshot.scaleFactor ?? screenContext.scaleFactor,
|
|
436
|
+
},
|
|
437
|
+
predictionParsed: parsedPredictions,
|
|
438
|
+
});
|
|
439
|
+
await this.onData?.({
|
|
440
|
+
...data,
|
|
441
|
+
conversations: data.conversations.slice(-1),
|
|
442
|
+
});
|
|
443
|
+
// Display assistant response
|
|
444
|
+
const latestAssistant = data.conversations[data.conversations.length - 1];
|
|
445
|
+
if (latestAssistant && latestAssistant.from === 'assistant') {
|
|
446
|
+
this.displayConversationResult(latestAssistant, loopCnt);
|
|
447
|
+
}
|
|
448
|
+
// Check if we need to switch operator based on first action
|
|
449
|
+
// Execute actions
|
|
450
|
+
for (const parsedPrediction of parsedPredictions) {
|
|
451
|
+
const actionType = parsedPrediction.action_type;
|
|
452
|
+
if (this.showAIDebugInfo) {
|
|
453
|
+
this.logger.debug('[GUIAgent] Action:', actionType);
|
|
454
|
+
}
|
|
455
|
+
// Handle internal action spaces
|
|
456
|
+
if (actionType === 'error_env') {
|
|
457
|
+
data.status = GUIAgentStatus.ERROR;
|
|
458
|
+
data.error = 'Environment error';
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
else if (actionType === 'max_loop') {
|
|
462
|
+
data.status = GUIAgentStatus.ERROR;
|
|
463
|
+
data.error = 'Reached max loop';
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
// Execute action with retry
|
|
467
|
+
if (!this.signal?.aborted && !this.isStopped) {
|
|
468
|
+
let stepRetryCount = 0;
|
|
469
|
+
let stepSuccess = false;
|
|
470
|
+
let lastErrorMsg = '';
|
|
471
|
+
this.logger.debug(`[GUIAgent] Executing action: ${actionType}, loopCnt: ${loopCnt}`);
|
|
472
|
+
while (stepRetryCount < MAX_STEP_RETRIES && !stepSuccess) {
|
|
473
|
+
try {
|
|
474
|
+
const executeResult = await this.operator.doExecute({
|
|
475
|
+
prediction,
|
|
476
|
+
parsedPrediction,
|
|
477
|
+
screenWidth: screenContext.width,
|
|
478
|
+
screenHeight: screenContext.height,
|
|
479
|
+
scaleFactor: snapshot.scaleFactor ?? screenContext.scaleFactor,
|
|
480
|
+
factors: [1000, 1000], // Default factors
|
|
481
|
+
});
|
|
482
|
+
if (executeResult.status === 'end') {
|
|
483
|
+
// 'finished' action or explicit end
|
|
484
|
+
stepSuccess = true;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
// Any other status (success, failed, etc.) is considered success
|
|
488
|
+
stepSuccess = true;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
catch (executeError) {
|
|
492
|
+
stepRetryCount++;
|
|
493
|
+
lastErrorMsg = executeError instanceof Error ? executeError.message : 'Unknown error';
|
|
494
|
+
this.logger.warn(`[GUIAgent] Action failed ${stepRetryCount}/${MAX_STEP_RETRIES}: ${lastErrorMsg}`);
|
|
495
|
+
if (stepRetryCount < MAX_STEP_RETRIES) {
|
|
496
|
+
await sleep(1000);
|
|
497
|
+
// Take new screenshot for retry
|
|
498
|
+
const retrySnapshot = await this.operator.doScreenshot();
|
|
499
|
+
if (retrySnapshot?.base64) {
|
|
500
|
+
data.conversations.push({
|
|
501
|
+
from: 'human',
|
|
502
|
+
value: IMAGE_PLACEHOLDER,
|
|
503
|
+
screenshotBase64: retrySnapshot.base64,
|
|
504
|
+
screenshotContext: {
|
|
505
|
+
size: {
|
|
506
|
+
width: screenContext.width,
|
|
507
|
+
height: screenContext.height,
|
|
508
|
+
},
|
|
509
|
+
scaleFactor: retrySnapshot.scaleFactor ?? screenContext.scaleFactor,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (!stepSuccess) {
|
|
517
|
+
// All retries exhausted
|
|
518
|
+
this.logger.error(`[GUIAgent] Action failed after ${MAX_STEP_RETRIES} attempts: ${lastErrorMsg}`);
|
|
519
|
+
data.status = GUIAgentStatus.ERROR;
|
|
520
|
+
data.error = `Action failed after ${MAX_STEP_RETRIES} attempts: ${lastErrorMsg}`;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
// Check abort immediately after action execution
|
|
525
|
+
if (this.signal?.aborted) {
|
|
526
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
// Handle special action types
|
|
530
|
+
if (actionType === 'call_user') {
|
|
531
|
+
data.status = GUIAgentStatus.CALL_USER;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
else if (actionType === 'finished') {
|
|
535
|
+
data.status = GUIAgentStatus.END;
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
// Check abort after action loop
|
|
540
|
+
if (this.signal?.aborted) {
|
|
541
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
// Wait between iterations
|
|
545
|
+
if (this.loopIntervalInMs > 0) {
|
|
546
|
+
await sleep(this.loopIntervalInMs);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
this.logger.error('[GUIAgent] Catch error', error);
|
|
552
|
+
if (error instanceof Error &&
|
|
553
|
+
(error.name === 'AbortError' || error.message?.includes('aborted'))) {
|
|
554
|
+
data.status = GUIAgentStatus.USER_STOPPED;
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
data.status = GUIAgentStatus.ERROR;
|
|
558
|
+
data.error = error instanceof Error ? error.message : 'Unknown error';
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
finally {
|
|
562
|
+
// Save final status
|
|
563
|
+
const finalStatus = data.status;
|
|
564
|
+
const finalError = data.error;
|
|
565
|
+
// Output error immediately if task failed
|
|
566
|
+
if (finalStatus === GUIAgentStatus.ERROR && finalError) {
|
|
567
|
+
console.log(`\n${colors.error('ā')} ${finalError}\n`);
|
|
568
|
+
}
|
|
569
|
+
// Call onData callback if set
|
|
570
|
+
// Note: Use Promise.resolve().then() to avoid modifying data in callback
|
|
571
|
+
const onDataCallback = this.onData;
|
|
572
|
+
if (onDataCallback) {
|
|
573
|
+
Promise.resolve().then(() => onDataCallback({ ...data, conversations: [] }));
|
|
574
|
+
}
|
|
575
|
+
// Call onError callback if status is error
|
|
576
|
+
if (finalStatus === GUIAgentStatus.ERROR && this.onError) {
|
|
577
|
+
this.onError(new Error(finalError || 'Unknown error occurred'));
|
|
578
|
+
}
|
|
579
|
+
if (this.showAIDebugInfo) {
|
|
580
|
+
this.logger.debug('[GUIAgent] Final status:', {
|
|
581
|
+
status: finalStatus,
|
|
582
|
+
loopCnt,
|
|
583
|
+
totalConversations: data.conversations.length,
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
// Ensure the returned status is correct (reassign)
|
|
587
|
+
this.logger.debug(`[GUIAgent] Finally: finalStatus=${finalStatus}, finalError=${finalError}, data.status=${data.status}, data.error=${data.error}`);
|
|
588
|
+
// Log final status (only visible when showAIDebugInfo is enabled)
|
|
589
|
+
this.logger.debug(`[GUIAgent] Final status: ${finalStatus}${finalError ? `, Error: ${finalError}` : ''}, Steps: ${loopCnt}`);
|
|
590
|
+
data.status = finalStatus;
|
|
591
|
+
data.error = finalError;
|
|
592
|
+
}
|
|
593
|
+
return data;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Build messages for the model API
|
|
597
|
+
*/
|
|
598
|
+
buildModelMessages(conversations, systemPrompt) {
|
|
599
|
+
const messages = [];
|
|
600
|
+
// System prompt
|
|
601
|
+
messages.push({
|
|
602
|
+
role: 'system',
|
|
603
|
+
content: systemPrompt,
|
|
604
|
+
});
|
|
605
|
+
// Add conversation history
|
|
606
|
+
for (const conv of conversations) {
|
|
607
|
+
if (conv.from === 'human' && conv.screenshotBase64) {
|
|
608
|
+
messages.push({
|
|
609
|
+
role: 'user',
|
|
610
|
+
content: [
|
|
611
|
+
{ type: 'text', text: conv.value },
|
|
612
|
+
{
|
|
613
|
+
type: 'image_url',
|
|
614
|
+
image_url: {
|
|
615
|
+
url: `data:image/png;base64,${conv.screenshotBase64}`,
|
|
616
|
+
detail: 'high',
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
],
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
else if (conv.from === 'assistant') {
|
|
623
|
+
messages.push({
|
|
624
|
+
role: 'assistant',
|
|
625
|
+
content: conv.value,
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
messages.push({
|
|
630
|
+
role: 'user',
|
|
631
|
+
content: conv.value,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return messages;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Call the model API with debug logging
|
|
639
|
+
*/
|
|
640
|
+
async callModelAPI(messages, screenContext) {
|
|
641
|
+
const baseUrl = this.modelBaseUrl || process.env.MODEL_BASE_URL || 'https://api.openai.com/v1';
|
|
642
|
+
const apiKey = this.modelApiKey || process.env.MODEL_API_KEY || '';
|
|
643
|
+
const requestBody = {
|
|
644
|
+
model: this.model,
|
|
645
|
+
messages,
|
|
646
|
+
max_tokens: 1024,
|
|
647
|
+
temperature: 0.1,
|
|
648
|
+
};
|
|
649
|
+
// Debug output for model input
|
|
650
|
+
if (this.showAIDebugInfo) {
|
|
651
|
+
console.log('\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
652
|
+
console.log('ā GUI MODEL REQUEST DEBUG ā');
|
|
653
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
654
|
+
console.log(`š¦ Model: ${this.model}`);
|
|
655
|
+
console.log(`š Base URL: ${baseUrl}`);
|
|
656
|
+
console.log(`š¬ Messages: ${messages.length}`);
|
|
657
|
+
// Show system prompt if present
|
|
658
|
+
const systemMsg = messages.find((m) => m.role === 'system');
|
|
659
|
+
if (systemMsg) {
|
|
660
|
+
console.log('\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
661
|
+
console.log('ā š« SYSTEM ā');
|
|
662
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤');
|
|
663
|
+
const systemContent = typeof systemMsg.content === 'string'
|
|
664
|
+
? systemMsg.content
|
|
665
|
+
: JSON.stringify(systemMsg.content);
|
|
666
|
+
const lines = systemContent.split('\n').slice(0, 15);
|
|
667
|
+
for (const line of lines) {
|
|
668
|
+
console.log('ā ' + line.slice(0, 62));
|
|
669
|
+
}
|
|
670
|
+
if (systemContent.split('\n').length > 15) {
|
|
671
|
+
console.log('ā ... (truncated)');
|
|
672
|
+
}
|
|
673
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
674
|
+
}
|
|
675
|
+
// Show conversation messages
|
|
676
|
+
const roleColors = {
|
|
677
|
+
user: 'š¤ USER',
|
|
678
|
+
assistant: 'š¤ ASSISTANT',
|
|
679
|
+
};
|
|
680
|
+
for (let i = 0; i < messages.length; i++) {
|
|
681
|
+
const msg = messages[i];
|
|
682
|
+
if (msg.role === 'system')
|
|
683
|
+
continue;
|
|
684
|
+
const roleLabel = roleColors[msg.role] || `ā ${msg.role.toUpperCase()}`;
|
|
685
|
+
console.log(`\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
686
|
+
console.log(`ā ${roleLabel} (${i + 1}) ā`);
|
|
687
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤');
|
|
688
|
+
if (typeof msg.content === 'string') {
|
|
689
|
+
const lines = msg.content.split('\n').slice(0, 20);
|
|
690
|
+
for (const line of lines) {
|
|
691
|
+
console.log('ā ' + line.slice(0, 62));
|
|
692
|
+
}
|
|
693
|
+
if (msg.content.split('\n').length > 20) {
|
|
694
|
+
console.log('ā ... (truncated)');
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else if (Array.isArray(msg.content)) {
|
|
698
|
+
const hasImage = msg.content.some((c) => c.type === 'image_url');
|
|
699
|
+
console.log('ā š Content blocks: ' + msg.content.length);
|
|
700
|
+
if (hasImage) {
|
|
701
|
+
const imageBlock = msg.content.find((c) => c.type === 'image_url');
|
|
702
|
+
const imageSize = imageBlock?.image_url?.url?.length || 0;
|
|
703
|
+
console.log('ā š¼ļø Image size: ' + (imageSize / 1024).toFixed(2) + ' KB');
|
|
704
|
+
}
|
|
705
|
+
const textBlock = msg.content.find((c) => c.type === 'text');
|
|
706
|
+
if (textBlock?.text) {
|
|
707
|
+
const lines = textBlock.text.split('\n').slice(0, 10);
|
|
708
|
+
for (const line of lines) {
|
|
709
|
+
console.log('ā ' + line.slice(0, 62));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
714
|
+
}
|
|
715
|
+
console.log('\nš¤ Sending request to model API...\n');
|
|
716
|
+
}
|
|
717
|
+
let response;
|
|
718
|
+
try {
|
|
719
|
+
response = await fetch(`${baseUrl}/chat/completions`, {
|
|
720
|
+
method: 'POST',
|
|
721
|
+
headers: {
|
|
722
|
+
'Content-Type': 'application/json',
|
|
723
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
724
|
+
},
|
|
725
|
+
body: JSON.stringify(requestBody),
|
|
726
|
+
signal: this.signal,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
catch (fetchError) {
|
|
730
|
+
throw fetchError;
|
|
731
|
+
}
|
|
732
|
+
// Handle non-200 responses
|
|
733
|
+
if (!response.ok) {
|
|
734
|
+
const errorText = await response.text();
|
|
735
|
+
throw new Error(`Model API error: ${errorText}`);
|
|
736
|
+
}
|
|
737
|
+
const result = await response.json();
|
|
738
|
+
const content = result.choices?.[0]?.message?.content || '';
|
|
739
|
+
// Debug output for model response
|
|
740
|
+
if (this.showAIDebugInfo) {
|
|
741
|
+
console.log('\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
742
|
+
console.log('ā GUI MODEL RESPONSE DEBUG ā');
|
|
743
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
744
|
+
if (result.usage) {
|
|
745
|
+
console.log(`š Tokens: ${result.usage.prompt_tokens} (prompt) + ${result.usage.completion_tokens} (completion) = ${result.usage.total_tokens} (total)`);
|
|
746
|
+
}
|
|
747
|
+
console.log('\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
748
|
+
console.log('ā š¤ ASSISTANT ā');
|
|
749
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤');
|
|
750
|
+
console.log('ā š¬ CONTENT:');
|
|
751
|
+
console.log('ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
752
|
+
const lines = content.split('\n').slice(0, 30);
|
|
753
|
+
for (const line of lines) {
|
|
754
|
+
console.log('ā ' + line.slice(0, 62));
|
|
755
|
+
}
|
|
756
|
+
if (content.split('\n').length > 30) {
|
|
757
|
+
console.log(`ā ... (${content.split('\n').length - 30} more lines)`);
|
|
758
|
+
}
|
|
759
|
+
console.log('ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
760
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
761
|
+
console.log('\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
|
|
762
|
+
console.log('ā RESPONSE ENDED ā');
|
|
763
|
+
console.log('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n');
|
|
764
|
+
}
|
|
765
|
+
const { parsed: parsedPredictions } = actionParser({
|
|
766
|
+
prediction: content,
|
|
767
|
+
factor: [1000, 1000],
|
|
768
|
+
screenContext: {
|
|
769
|
+
width: screenContext.width,
|
|
770
|
+
height: screenContext.height,
|
|
771
|
+
},
|
|
772
|
+
});
|
|
773
|
+
return {
|
|
774
|
+
prediction: content,
|
|
775
|
+
parsedPredictions,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Get summary from prediction text
|
|
780
|
+
*/
|
|
781
|
+
getSummary(prediction) {
|
|
782
|
+
// Extract the action part as summary
|
|
783
|
+
const actionMatch = prediction.match(/Action[:ļ¼]\s*([\s\S]+)$/i);
|
|
784
|
+
if (actionMatch) {
|
|
785
|
+
return actionMatch[1].trim();
|
|
786
|
+
}
|
|
787
|
+
return prediction.slice(0, 200);
|
|
788
|
+
}
|
|
789
|
+
pause() {
|
|
790
|
+
this.isPaused = true;
|
|
791
|
+
this.resumePromise = new Promise((resolve) => {
|
|
792
|
+
this.resolveResume = resolve;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
resume() {
|
|
796
|
+
if (this.resolveResume) {
|
|
797
|
+
this.resolveResume();
|
|
798
|
+
this.resumePromise = null;
|
|
799
|
+
this.resolveResume = null;
|
|
800
|
+
}
|
|
801
|
+
this.isPaused = false;
|
|
802
|
+
}
|
|
803
|
+
stop() {
|
|
804
|
+
this.isStopped = true;
|
|
805
|
+
}
|
|
806
|
+
async cleanup() {
|
|
807
|
+
this.logger.debug('Cleaning up GUI Agent...');
|
|
808
|
+
await this.operator.cleanup();
|
|
809
|
+
// Cleanup cancellation listener if attached
|
|
810
|
+
const cancelHandler = this._cancelHandler;
|
|
811
|
+
const cancellationManager = this._cancellationManager;
|
|
812
|
+
if (cancelHandler && cancellationManager) {
|
|
813
|
+
cancellationManager.off('cancelled', cancelHandler);
|
|
814
|
+
this._cancelHandler = undefined;
|
|
815
|
+
this._cancellationManager = undefined;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
export { GUIAgentStatus as StatusEnum };
|
|
820
|
+
//# sourceMappingURL=gui-agent.js.map
|