connectonion 0.6.1__py3-none-any.whl → 0.6.3__py3-none-any.whl
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.
- connectonion/__init__.py +46 -9
- connectonion/cli/__init__.py +11 -1
- connectonion/cli/browser_agent/__init__.py +11 -1
- connectonion/cli/browser_agent/browser.py +95 -142
- connectonion/cli/browser_agent/element_finder.py +147 -0
- connectonion/cli/browser_agent/highlight_screenshot.py +182 -0
- connectonion/cli/browser_agent/prompt.md +188 -105
- connectonion/cli/browser_agent/prompts/element_matcher.md +59 -0
- connectonion/cli/browser_agent/prompts/form_filler.md +19 -0
- connectonion/cli/browser_agent/prompts/scroll_strategy.md +36 -0
- connectonion/cli/browser_agent/scripts/extract_elements.js +126 -0
- connectonion/cli/browser_agent/scroll.py +145 -0
- connectonion/cli/co_ai/__init__.py +6 -0
- connectonion/cli/co_ai/agent.py +87 -0
- connectonion/cli/co_ai/agents/__init__.py +5 -0
- connectonion/cli/co_ai/agents/registry.py +57 -0
- connectonion/cli/co_ai/commands/__init__.py +45 -0
- connectonion/cli/co_ai/commands/compact.py +173 -0
- connectonion/cli/co_ai/commands/cost.py +77 -0
- connectonion/cli/co_ai/commands/export.py +60 -0
- connectonion/cli/co_ai/commands/help.py +80 -0
- connectonion/cli/co_ai/commands/init.py +101 -0
- connectonion/cli/co_ai/commands/sessions.py +55 -0
- connectonion/cli/co_ai/commands/tasks.py +63 -0
- connectonion/cli/co_ai/commands/undo.py +103 -0
- connectonion/cli/co_ai/context.py +127 -0
- connectonion/cli/co_ai/main.py +52 -0
- connectonion/cli/co_ai/plugins/__init__.py +6 -0
- connectonion/cli/co_ai/plugins/reminder.py +76 -0
- connectonion/cli/co_ai/plugins/shell_approval.py +105 -0
- connectonion/cli/co_ai/prompts/agents/explore.md +79 -0
- connectonion/cli/co_ai/prompts/agents/plan.md +60 -0
- connectonion/cli/co_ai/prompts/assembler.py +303 -0
- connectonion/cli/{docs/co-vibecoding-principles-docs-contexts-all-in-one.md → co_ai/prompts/connectonion/README.md} +26 -0
- connectonion/cli/co_ai/prompts/connectonion/api.md +457 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/README.md +805 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/auth.md +46 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/browser.md +235 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/copy.md +184 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/create.md +335 -0
- connectonion/cli/co_ai/prompts/connectonion/cli/init.md +431 -0
- connectonion/cli/co_ai/prompts/connectonion/co-directory-structure.md +214 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/agent.md +1078 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/events.md +816 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/llm_do.md +256 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/max_iterations.md +362 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/models.md +641 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/plugins.md +100 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/prompts.md +122 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/tools.md +512 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/transcribe.md +156 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/trust.md +291 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/README.md +18 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/auto_debug.md +1026 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/console.md +129 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/eval-format.md +178 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/eval.md +230 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/exceptions.md +307 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/log.md +117 -0
- connectonion/cli/co_ai/prompts/connectonion/debug/xray.md +215 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/001-choosing-input-method.md +202 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/002-choosing-llm-function-name.md +202 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/003-choosing-trust-keyword.md +141 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/004-cli-create-flow.md +117 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/005-designing-agent-network-protocol.md +503 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/006-agent-address-format.md +305 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/007-authentication-backend-design.md +240 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/008-naming-is-hard.md +228 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/009-why-connect-function.md +167 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/010-cli-ux-progressive-disclosure.md +176 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/011-global-config-identity-management.md +357 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/012-tool-execution-separation.md +259 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/013-debug-and-logging-design.md +253 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/014-hook-system-design.md +510 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/015-interactive-auto-debug-design.md +837 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/016-why-no-zero-knowledge-proofs.md +358 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/017-session-logging-and-eval-format.md +120 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/018-event-api-naming.md +274 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/019-agent-lifecycle-design.md +655 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/020-trust-system-and-network-architecture.md +503 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/021-task-storage-jsonl-design.md +496 -0
- connectonion/cli/co_ai/prompts/connectonion/design-decisions/022-raw-asgi-implementation.md +273 -0
- connectonion/cli/co_ai/prompts/connectonion/examples/agent_reasoning.md +62 -0
- connectonion/cli/co_ai/prompts/connectonion/examples/atomic_tools.md +24 -0
- connectonion/cli/co_ai/prompts/connectonion/examples/load_guide.md +18 -0
- connectonion/cli/co_ai/prompts/connectonion/examples.md +0 -0
- connectonion/cli/co_ai/prompts/connectonion/hook-system-options.md +364 -0
- connectonion/cli/co_ai/prompts/connectonion/index.md +162 -0
- connectonion/cli/co_ai/prompts/connectonion/integrations/README.md +12 -0
- connectonion/cli/co_ai/prompts/connectonion/integrations/auth.md +450 -0
- connectonion/cli/co_ai/prompts/connectonion/integrations/google.md +431 -0
- connectonion/cli/co_ai/prompts/connectonion/integrations/microsoft.md +370 -0
- connectonion/cli/co_ai/prompts/connectonion/network/README.md +14 -0
- connectonion/cli/co_ai/prompts/connectonion/network/connect.md +543 -0
- connectonion/cli/co_ai/prompts/connectonion/network/connection.md +538 -0
- connectonion/cli/co_ai/prompts/connectonion/network/deploy.md +123 -0
- connectonion/cli/co_ai/prompts/connectonion/network/host.md +1049 -0
- connectonion/cli/co_ai/prompts/connectonion/network/protocol/agent-relay-protocol.md +495 -0
- connectonion/cli/co_ai/prompts/connectonion/network/protocol/announce-message.md +115 -0
- connectonion/cli/co_ai/prompts/connectonion/principles.md +124 -0
- connectonion/cli/co_ai/prompts/connectonion/quickstart.md +261 -0
- connectonion/cli/co_ai/prompts/connectonion/roadmap.md +81 -0
- connectonion/cli/co_ai/prompts/connectonion/templates/README.md +77 -0
- connectonion/cli/co_ai/prompts/connectonion/templates/meta-agent.md +152 -0
- connectonion/cli/co_ai/prompts/connectonion/templates/minimal.md +105 -0
- connectonion/cli/co_ai/prompts/connectonion/templates/playwright.md +130 -0
- connectonion/cli/co_ai/prompts/connectonion/templates/web-research.md +144 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/README.md +95 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/chat.md +181 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/divider.md +63 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/dropdown.md +83 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/footer.md +44 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/fuzzy.md +68 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/input.md +84 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/keys.md +77 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/pick.md +71 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/providers.md +89 -0
- connectonion/cli/co_ai/prompts/connectonion/tui/status_bar.md +67 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/README.md +156 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/calendar_plugin.md +68 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/eval.md +89 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/gmail_plugin.md +68 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/image_result_formatter.md +74 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/re_act.md +86 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_plugins/shell_approval.md +69 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/README.md +81 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/diff_writer.md +138 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/get_emails.md +499 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/gmail.md +135 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/google_calendar.md +106 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/memory.md +486 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/microsoft_calendar.md +106 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/outlook.md +120 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/send_email.md +403 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/shell.md +95 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/slash_command.md +96 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/terminal.md +97 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/todo_list.md +252 -0
- connectonion/cli/co_ai/prompts/connectonion/useful_tools/web_fetch.md +130 -0
- connectonion/cli/co_ai/prompts/connectonion/vibe-coding-guide.md +97 -0
- connectonion/cli/co_ai/prompts/connectonion/windows-support.md +258 -0
- connectonion/cli/co_ai/prompts/main.md +247 -0
- connectonion/cli/co_ai/prompts/reminders/plan_mode.md +34 -0
- connectonion/cli/co_ai/prompts/summarization.md +55 -0
- connectonion/cli/co_ai/prompts/tools/ask_user.md +61 -0
- connectonion/cli/co_ai/prompts/tools/background.md +57 -0
- connectonion/cli/co_ai/prompts/tools/edit.md +90 -0
- connectonion/cli/co_ai/prompts/tools/glob.md +52 -0
- connectonion/cli/co_ai/prompts/tools/grep.md +55 -0
- connectonion/cli/co_ai/prompts/tools/plan_mode.md +80 -0
- connectonion/cli/co_ai/prompts/tools/read.md +40 -0
- connectonion/cli/co_ai/prompts/tools/shell.md +67 -0
- connectonion/cli/co_ai/prompts/tools/task.md +51 -0
- connectonion/cli/co_ai/prompts/tools/todo.md +139 -0
- connectonion/cli/co_ai/prompts/tools/write.md +47 -0
- connectonion/cli/co_ai/prompts/workflow.md +89 -0
- connectonion/cli/co_ai/reminders.py +159 -0
- connectonion/cli/co_ai/sessions.py +110 -0
- connectonion/cli/co_ai/skills/__init__.py +37 -0
- connectonion/cli/co_ai/skills/builtin/commit/SKILL.md +63 -0
- connectonion/cli/co_ai/skills/builtin/review-pr/SKILL.md +76 -0
- connectonion/cli/co_ai/skills/loader.py +166 -0
- connectonion/cli/co_ai/skills/tool.py +46 -0
- connectonion/cli/co_ai/tools/__init__.py +92 -0
- connectonion/cli/co_ai/tools/ask_user.py +35 -0
- connectonion/cli/co_ai/tools/background.py +201 -0
- connectonion/cli/co_ai/tools/diff_writer.py +291 -0
- connectonion/cli/co_ai/tools/edit.py +89 -0
- connectonion/cli/co_ai/tools/glob.py +84 -0
- connectonion/cli/co_ai/tools/grep.py +158 -0
- connectonion/cli/co_ai/tools/load_guide.py +23 -0
- connectonion/cli/co_ai/tools/multi_edit.py +116 -0
- connectonion/cli/co_ai/tools/plan_mode.py +172 -0
- connectonion/cli/co_ai/tools/read.py +67 -0
- connectonion/cli/co_ai/tools/task.py +59 -0
- connectonion/cli/co_ai/tools/todo_list.py +159 -0
- connectonion/cli/co_ai/tools/write.py +126 -0
- connectonion/cli/commands/__init__.py +11 -1
- connectonion/cli/commands/ai_commands.py +34 -0
- connectonion/cli/commands/copy_commands.py +55 -6
- connectonion/cli/commands/create.py +20 -17
- connectonion/cli/commands/init.py +19 -22
- connectonion/cli/commands/project_cmd_lib.py +15 -0
- connectonion/cli/main.py +11 -0
- connectonion/console.py +15 -1
- connectonion/core/__init__.py +10 -1
- connectonion/core/agent.py +37 -16
- connectonion/core/exceptions.py +74 -0
- connectonion/core/llm.py +54 -6
- connectonion/core/tool_executor.py +32 -31
- connectonion/core/tool_factory.py +47 -10
- connectonion/debug/__init__.py +10 -1
- connectonion/debug/debug_explainer/__init__.py +10 -1
- connectonion/debug/execution_analyzer/__init__.py +10 -1
- connectonion/debug/execution_analyzer/execution_analysis.py +5 -2
- connectonion/debug/runtime_inspector/__init__.py +10 -1
- connectonion/docs/.package-ignore +6 -0
- connectonion/docs/README.md +2036 -0
- connectonion/docs/api.md +457 -0
- connectonion/docs/archive/001-ai-agent-is-just-prompt-plus-function.md +249 -0
- connectonion/docs/archive/README.md +53 -0
- connectonion/docs/archive/archive/consolidation-plan.md +72 -0
- connectonion/docs/archive/archive/core-principles-extracted.md +239 -0
- connectonion/docs/archive/archive/master-principles.md +222 -0
- connectonion/docs/archive/archive/principles.md +293 -0
- connectonion/docs/archive/archive/simplicity-principles.md +221 -0
- connectonion/docs/archive/attack-defense-insights.md +410 -0
- connectonion/docs/archive/business-model.md +305 -0
- connectonion/docs/archive/core-principles-unified.md +190 -0
- connectonion/docs/archive/discussion-journey.md +178 -0
- connectonion/docs/archive/economic-analysis.md +323 -0
- connectonion/docs/archive/features/01-share-and-find.md +256 -0
- connectonion/docs/archive/features/02-agent-authentication.md +93 -0
- connectonion/docs/archive/features/03-test-before-trust.md +71 -0
- connectonion/docs/archive/features/06-reliability-and-offline.md +197 -0
- connectonion/docs/archive/features/README.md +46 -0
- connectonion/docs/archive/features-roadmap.md +247 -0
- connectonion/docs/archive/mcp-comparison-insights.md +215 -0
- connectonion/docs/archive/migration-strategy.md +571 -0
- connectonion/docs/archive/mini-whitepaper.md +293 -0
- connectonion/docs/archive/network-protocol.md +394 -0
- connectonion/docs/archive/semantic-revolution.md +367 -0
- connectonion/docs/archive/technical-architecture.md +453 -0
- connectonion/docs/archive/the-semantic-insight.md +207 -0
- connectonion/docs/archive/threat-model.md +164 -0
- connectonion/docs/cli/README.md +805 -0
- connectonion/docs/cli/auth.md +46 -0
- connectonion/docs/cli/browser.md +235 -0
- connectonion/docs/cli/copy.md +232 -0
- connectonion/docs/cli/create.md +335 -0
- connectonion/docs/cli/init.md +431 -0
- connectonion/docs/co-directory-structure.md +214 -0
- connectonion/docs/concepts/agent.md +1078 -0
- connectonion/docs/concepts/events.md +699 -0
- connectonion/docs/concepts/llm_do.md +256 -0
- connectonion/docs/concepts/max_iterations.md +362 -0
- connectonion/docs/concepts/models.md +641 -0
- connectonion/docs/concepts/plugins.md +100 -0
- connectonion/docs/concepts/prompts.md +122 -0
- connectonion/docs/concepts/session.md +428 -0
- connectonion/docs/concepts/tools.md +512 -0
- connectonion/docs/concepts/transcribe.md +156 -0
- connectonion/docs/concepts/trust.md +291 -0
- connectonion/docs/connectonion.md +1256 -0
- connectonion/docs/debug/README.md +18 -0
- connectonion/docs/debug/auto_debug.md +1026 -0
- connectonion/docs/debug/console.md +129 -0
- connectonion/docs/debug/eval-format.md +178 -0
- connectonion/docs/debug/eval.md +230 -0
- connectonion/docs/debug/exceptions.md +307 -0
- connectonion/docs/debug/log.md +117 -0
- connectonion/docs/debug/xray.md +215 -0
- connectonion/docs/design-decisions/001-choosing-input-method.md +202 -0
- connectonion/docs/design-decisions/002-choosing-llm-function-name.md +202 -0
- connectonion/docs/design-decisions/003-choosing-trust-keyword.md +141 -0
- connectonion/docs/design-decisions/004-cli-create-flow.md +117 -0
- connectonion/docs/design-decisions/005-designing-agent-network-protocol.md +503 -0
- connectonion/docs/design-decisions/006-agent-address-format.md +305 -0
- connectonion/docs/design-decisions/007-authentication-backend-design.md +240 -0
- connectonion/docs/design-decisions/008-naming-is-hard.md +228 -0
- connectonion/docs/design-decisions/009-why-connect-function.md +167 -0
- connectonion/docs/design-decisions/010-cli-ux-progressive-disclosure.md +176 -0
- connectonion/docs/design-decisions/011-global-config-identity-management.md +357 -0
- connectonion/docs/design-decisions/012-tool-execution-separation.md +259 -0
- connectonion/docs/design-decisions/013-debug-and-logging-design.md +253 -0
- connectonion/docs/design-decisions/014-hook-system-design.md +510 -0
- connectonion/docs/design-decisions/015-interactive-auto-debug-design.md +837 -0
- connectonion/docs/design-decisions/016-why-no-zero-knowledge-proofs.md +358 -0
- connectonion/docs/design-decisions/017-session-logging-and-eval-format.md +120 -0
- connectonion/docs/design-decisions/018-event-api-naming.md +274 -0
- connectonion/docs/design-decisions/019-agent-lifecycle-design.md +655 -0
- connectonion/docs/design-decisions/020-trust-system-and-network-architecture.md +503 -0
- connectonion/docs/design-decisions/021-task-storage-jsonl-design.md +496 -0
- connectonion/docs/design-decisions/022-raw-asgi-implementation.md +273 -0
- connectonion/docs/examples.md +0 -0
- connectonion/docs/hook-system-options.md +364 -0
- connectonion/docs/integrations/README.md +12 -0
- connectonion/docs/integrations/auth.md +450 -0
- connectonion/docs/integrations/google.md +431 -0
- connectonion/docs/integrations/microsoft.md +370 -0
- connectonion/docs/network/README.md +14 -0
- connectonion/docs/network/connect.md +629 -0
- connectonion/docs/network/deploy.md +124 -0
- connectonion/docs/network/host.md +1087 -0
- connectonion/docs/network/io.md +538 -0
- connectonion/docs/network/protocol/agent-relay-protocol.md +495 -0
- connectonion/docs/network/protocol/announce-message.md +115 -0
- connectonion/docs/principles.md +124 -0
- connectonion/docs/quickstart.md +261 -0
- connectonion/docs/roadmap.md +81 -0
- connectonion/docs/templates/README.md +77 -0
- connectonion/docs/templates/meta-agent.md +152 -0
- connectonion/docs/templates/minimal.md +105 -0
- connectonion/docs/templates/playwright.md +130 -0
- connectonion/docs/templates/web-research.md +144 -0
- connectonion/docs/tui/README.md +95 -0
- connectonion/docs/tui/chat.md +181 -0
- connectonion/docs/tui/divider.md +63 -0
- connectonion/docs/tui/dropdown.md +83 -0
- connectonion/docs/tui/footer.md +44 -0
- connectonion/docs/tui/fuzzy.md +68 -0
- connectonion/docs/tui/input.md +84 -0
- connectonion/docs/tui/keys.md +77 -0
- connectonion/docs/tui/pick.md +71 -0
- connectonion/docs/tui/providers.md +89 -0
- connectonion/docs/tui/status_bar.md +67 -0
- connectonion/docs/useful_plugins/README.md +160 -0
- connectonion/docs/useful_plugins/calendar_plugin.md +68 -0
- connectonion/docs/useful_plugins/eval.md +89 -0
- connectonion/docs/useful_plugins/gmail_plugin.md +68 -0
- connectonion/docs/useful_plugins/image_result_formatter.md +74 -0
- connectonion/docs/useful_plugins/re_act.md +86 -0
- connectonion/docs/useful_plugins/shell_approval.md +69 -0
- connectonion/docs/useful_plugins/system_reminder.md +210 -0
- connectonion/docs/useful_prompts/README.md +127 -0
- connectonion/docs/useful_prompts/coding_agent.md +214 -0
- connectonion/docs/useful_tools/README.md +81 -0
- connectonion/docs/useful_tools/ask_user.md +103 -0
- connectonion/docs/useful_tools/diff_writer.md +158 -0
- connectonion/docs/useful_tools/get_emails.md +519 -0
- connectonion/docs/useful_tools/gmail.md +155 -0
- connectonion/docs/useful_tools/google_calendar.md +126 -0
- connectonion/docs/useful_tools/memory.md +506 -0
- connectonion/docs/useful_tools/microsoft_calendar.md +126 -0
- connectonion/docs/useful_tools/outlook.md +140 -0
- connectonion/docs/useful_tools/send_email.md +423 -0
- connectonion/docs/useful_tools/shell.md +115 -0
- connectonion/docs/useful_tools/slash_command.md +116 -0
- connectonion/docs/useful_tools/terminal.md +115 -0
- connectonion/docs/useful_tools/todo_list.md +272 -0
- connectonion/docs/useful_tools/web_fetch.md +150 -0
- connectonion/docs/vibe-coding-guide.md +97 -0
- connectonion/docs/windows-support.md +258 -0
- connectonion/logger.py +3 -3
- connectonion/network/__init__.py +19 -6
- connectonion/network/asgi/__init__.py +81 -0
- connectonion/network/asgi/http.py +205 -0
- connectonion/network/asgi/websocket.py +217 -0
- connectonion/network/connect.py +232 -185
- connectonion/network/host/__init__.py +59 -0
- connectonion/network/host/auth.py +191 -0
- connectonion/network/host/routes.py +135 -0
- connectonion/network/host/server.py +289 -0
- connectonion/network/host/session.py +78 -0
- connectonion/network/io/__init__.py +21 -0
- connectonion/network/{connection.py → io/base.py} +17 -42
- connectonion/network/io/websocket.py +55 -0
- connectonion/network/relay.py +37 -16
- connectonion/network/trust/__init__.py +30 -0
- connectonion/network/trust/factory.py +138 -0
- connectonion/network/{trust_agents.py → trust/prompts.py} +3 -3
- connectonion/network/{trust_functions.py → trust/tools.py} +2 -2
- connectonion/prompt_files/__init__.py +11 -1
- connectonion/prompt_files/react_acknowledge.md +26 -0
- connectonion/prompts.py +10 -1
- connectonion/tui/chat.py +10 -1
- connectonion/tui/divider.py +10 -1
- connectonion/tui/dropdown.py +10 -1
- connectonion/tui/footer.py +8 -0
- connectonion/tui/fuzzy.py +11 -1
- connectonion/tui/input.py +118 -70
- connectonion/tui/keys.py +133 -6
- connectonion/tui/providers.py +11 -1
- connectonion/tui/status_bar.py +10 -1
- connectonion/useful_events_handlers/__init__.py +8 -0
- connectonion/useful_events_handlers/reflect.py +19 -4
- connectonion/useful_plugins/__init__.py +2 -1
- connectonion/useful_plugins/eval.py +2 -2
- connectonion/useful_plugins/gmail_plugin.py +3 -3
- connectonion/useful_plugins/image_result_formatter.py +3 -3
- connectonion/useful_plugins/re_act.py +114 -28
- connectonion/useful_plugins/shell_approval.py +2 -2
- connectonion/useful_plugins/system_reminder.py +103 -0
- connectonion/useful_plugins/ui_stream.py +18 -133
- connectonion/useful_prompts/README.md +61 -0
- connectonion/useful_prompts/__init__.py +45 -0
- connectonion/useful_prompts/coding_agent/README.md +106 -0
- connectonion/useful_prompts/coding_agent/assembler.py +123 -0
- connectonion/useful_prompts/coding_agent/prompts/main.md +227 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/ask_user.md +61 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/background.md +57 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/edit.md +90 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/glob.md +52 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/grep.md +55 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/plan_mode.md +80 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/read.md +40 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/shell.md +67 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/task.md +51 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/todo.md +139 -0
- connectonion/useful_prompts/coding_agent/prompts/tools/write.md +48 -0
- connectonion/useful_prompts/system-reminders/security-warning.md +14 -0
- connectonion/useful_prompts/system-reminders/test-reminder.md +11 -0
- connectonion/useful_tools/__init__.py +31 -4
- connectonion/useful_tools/ask_user.py +35 -0
- connectonion/useful_tools/bash.py +69 -0
- connectonion/useful_tools/diff_writer.py +186 -94
- connectonion/useful_tools/edit.py +102 -0
- connectonion/useful_tools/glob_files.py +97 -0
- connectonion/useful_tools/grep_files.py +171 -0
- connectonion/useful_tools/multi_edit.py +116 -0
- connectonion/useful_tools/read_file.py +73 -0
- connectonion/useful_tools/shell.py +50 -45
- connectonion/useful_tools/write_file.py +129 -0
- {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/METADATA +10 -3
- connectonion-0.6.3.dist-info/RECORD +469 -0
- connectonion/cli/browser_agent/scroll_strategies.py +0 -276
- connectonion/network/asgi.py +0 -407
- connectonion/network/host.py +0 -616
- connectonion/network/trust.py +0 -166
- connectonion-0.6.1.dist-info/RECORD +0 -123
- /connectonion/cli/{docs → co_ai/prompts/connectonion}/connectonion.md +0 -0
- {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/WHEEL +0 -0
- {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Purpose: Universal scrolling strategies with AI-powered selection and screenshot-based verification
|
|
3
|
-
LLM-Note:
|
|
4
|
-
Dependencies: imports from [typing, pydantic, connectonion.llm_do, PIL.Image, os, time] | imported by [web_automation.py] | tested by [tests/test_final_scroll.py]
|
|
5
|
-
Data flow: receives page: Page, take_screenshot: Callable, times: int, description: str from web_automation.scroll() → scroll_with_verification() orchestrates 3 strategies → ai_scroll_strategy() calls llm_do(HTML+scrollable_elements→ScrollStrategy, gpt-4o) → element_scroll_strategy()/page_scroll_strategy() fallbacks → page.evaluate(javascript) executes scroll → screenshots_are_different() compares PIL Images with 1% pixel threshold → returns success/failure string
|
|
6
|
-
State/Effects: calls page.evaluate() multiple times (mutates DOM scroll positions) | take_screenshot() writes PNG files to screenshots/*.png | time.sleep(1-1.2) between scroll iterations | AI calls to gpt-4o with temperature=0.1 for strategy generation
|
|
7
|
-
Integration: exposes scroll_with_verification() as main entry point from WebAutomation.scroll() | exposes scroll_page(), scroll_element() as standalone utilities | ScrollStrategy Pydantic model defines AI output schema (javascript: str, explanation: str) | screenshots_are_different() uses PIL for pixel-level comparison
|
|
8
|
-
Performance: ai_scroll_strategy() calls llm_do() once per scroll session (100-500ms) | analyzes first 5000 chars of HTML | finds up to 3 scrollable elements | executes JS times iterations with 1.2s delays | element/page strategies are synchronous JS execution (fast) | PIL screenshot comparison ~50-100ms
|
|
9
|
-
Errors: returns descriptive strings (not exceptions) - "All scroll strategies failed", "Browser not open" | screenshot comparison failure returns True (assumes different) to continue | page.evaluate() exceptions caught and next strategy tried | prints debug output to stdout
|
|
10
|
-
⚠️ Strategy order: AI-first may be slower but more accurate for complex sites (Gmail) - reorder if speed critical
|
|
11
|
-
⚠️ Screenshot verification: 1% threshold may need tuning for high-resolution displays or subtle animations
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from typing import Callable, List, Tuple
|
|
15
|
-
from pydantic import BaseModel
|
|
16
|
-
from connectonion import llm_do
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class ScrollStrategy(BaseModel):
|
|
20
|
-
"""AI-generated scroll strategy."""
|
|
21
|
-
javascript: str
|
|
22
|
-
explanation: str
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def scroll_with_verification(
|
|
26
|
-
page,
|
|
27
|
-
take_screenshot: Callable,
|
|
28
|
-
times: int = 5,
|
|
29
|
-
description: str = "the main content area"
|
|
30
|
-
) -> str:
|
|
31
|
-
"""Universal scroll with automatic strategy selection and fallback.
|
|
32
|
-
|
|
33
|
-
Tries multiple strategies in order until one works:
|
|
34
|
-
1. AI-generated strategy (default)
|
|
35
|
-
2. Element scrolling
|
|
36
|
-
3. Page scrolling
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
page: Playwright page object
|
|
40
|
-
take_screenshot: Function to take screenshots
|
|
41
|
-
times: Number of scroll iterations
|
|
42
|
-
description: What to scroll (natural language)
|
|
43
|
-
|
|
44
|
-
Returns:
|
|
45
|
-
Status message with successful strategy
|
|
46
|
-
"""
|
|
47
|
-
if not page:
|
|
48
|
-
return "Browser not open"
|
|
49
|
-
|
|
50
|
-
print(f"\n📜 Starting universal scroll for: '{description}'")
|
|
51
|
-
|
|
52
|
-
import time
|
|
53
|
-
timestamp = int(time.time())
|
|
54
|
-
before_file = f"scroll_before_{timestamp}.png"
|
|
55
|
-
after_file = f"scroll_after_{timestamp}.png"
|
|
56
|
-
|
|
57
|
-
# Take before screenshot
|
|
58
|
-
take_screenshot(before_file)
|
|
59
|
-
|
|
60
|
-
strategies = [
|
|
61
|
-
("AI-generated strategy", lambda: ai_scroll_strategy(page, times, description)),
|
|
62
|
-
("Element scrolling", lambda: element_scroll_strategy(page, times)),
|
|
63
|
-
("Page scrolling", lambda: page_scroll_strategy(page, times))
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
for strategy_name, strategy_func in strategies:
|
|
67
|
-
print(f"\n Trying: {strategy_name}...")
|
|
68
|
-
|
|
69
|
-
try:
|
|
70
|
-
strategy_func()
|
|
71
|
-
time.sleep(1)
|
|
72
|
-
|
|
73
|
-
# Take after screenshot
|
|
74
|
-
take_screenshot(after_file)
|
|
75
|
-
|
|
76
|
-
# Verify scroll worked
|
|
77
|
-
if screenshots_are_different(before_file, after_file):
|
|
78
|
-
print(f" ✅ {strategy_name} WORKED! Content changed.")
|
|
79
|
-
return f"Scroll successful using {strategy_name}. Check {before_file} vs {after_file}"
|
|
80
|
-
else:
|
|
81
|
-
print(f" ⚠️ {strategy_name} didn't change content. Trying next...")
|
|
82
|
-
before_file = after_file
|
|
83
|
-
after_file = f"scroll_after_{timestamp}_next.png"
|
|
84
|
-
|
|
85
|
-
except Exception as e:
|
|
86
|
-
print(f" ❌ {strategy_name} failed: {e}")
|
|
87
|
-
continue
|
|
88
|
-
|
|
89
|
-
return "All scroll strategies failed. No visible content change."
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def screenshots_are_different(file1: str, file2: str) -> bool:
|
|
93
|
-
"""Compare screenshots to verify content changed.
|
|
94
|
-
|
|
95
|
-
Args:
|
|
96
|
-
file1: First screenshot filename
|
|
97
|
-
file2: Second screenshot filename
|
|
98
|
-
|
|
99
|
-
Returns:
|
|
100
|
-
True if screenshots are different
|
|
101
|
-
"""
|
|
102
|
-
try:
|
|
103
|
-
from PIL import Image
|
|
104
|
-
import os
|
|
105
|
-
|
|
106
|
-
path1 = os.path.join("screenshots", file1)
|
|
107
|
-
path2 = os.path.join("screenshots", file2)
|
|
108
|
-
|
|
109
|
-
img1 = Image.open(path1).convert('RGB')
|
|
110
|
-
img2 = Image.open(path2).convert('RGB')
|
|
111
|
-
|
|
112
|
-
# Calculate pixel difference
|
|
113
|
-
diff = sum(
|
|
114
|
-
abs(a - b)
|
|
115
|
-
for pixel1, pixel2 in zip(img1.getdata(), img2.getdata())
|
|
116
|
-
for a, b in zip(pixel1, pixel2)
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
# 1% threshold
|
|
120
|
-
threshold = img1.size[0] * img1.size[1] * 3 * 0.01
|
|
121
|
-
|
|
122
|
-
is_different = diff > threshold
|
|
123
|
-
print(f" Screenshot diff: {diff:.0f} (threshold: {threshold:.0f}) - {'DIFFERENT' if is_different else 'SAME'}")
|
|
124
|
-
|
|
125
|
-
return is_different
|
|
126
|
-
|
|
127
|
-
except Exception as e:
|
|
128
|
-
print(f" Warning: Screenshot comparison failed: {e}")
|
|
129
|
-
return True # Assume different if comparison fails
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def ai_scroll_strategy(page, times: int, description: str):
|
|
133
|
-
"""AI-generated scroll strategy.
|
|
134
|
-
|
|
135
|
-
Analyzes page structure and generates custom JavaScript.
|
|
136
|
-
"""
|
|
137
|
-
# Find scrollable elements
|
|
138
|
-
scrollable_elements = page.evaluate("""
|
|
139
|
-
(() => {
|
|
140
|
-
const scrollable = [];
|
|
141
|
-
document.querySelectorAll('*').forEach(el => {
|
|
142
|
-
const style = window.getComputedStyle(el);
|
|
143
|
-
if ((style.overflow === 'auto' || style.overflowY === 'scroll') &&
|
|
144
|
-
el.scrollHeight > el.clientHeight) {
|
|
145
|
-
scrollable.push({
|
|
146
|
-
tag: el.tagName,
|
|
147
|
-
classes: el.className,
|
|
148
|
-
id: el.id
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
return scrollable;
|
|
153
|
-
})()
|
|
154
|
-
""")
|
|
155
|
-
|
|
156
|
-
# Get simplified HTML
|
|
157
|
-
simplified_html = page.evaluate("""
|
|
158
|
-
(() => {
|
|
159
|
-
const clone = document.body.cloneNode(true);
|
|
160
|
-
clone.querySelectorAll('script, style, img, svg').forEach(el => el.remove());
|
|
161
|
-
return clone.innerHTML.substring(0, 5000);
|
|
162
|
-
})()
|
|
163
|
-
""")
|
|
164
|
-
|
|
165
|
-
# Generate scroll strategy using AI
|
|
166
|
-
strategy = llm_do(
|
|
167
|
-
f"""Generate JavaScript to scroll "{description}".
|
|
168
|
-
|
|
169
|
-
Scrollable elements: {scrollable_elements[:3]}
|
|
170
|
-
HTML structure: {simplified_html}
|
|
171
|
-
|
|
172
|
-
Return IIFE that scrolls the correct element:
|
|
173
|
-
(() => {{
|
|
174
|
-
const el = document.querySelector('.selector');
|
|
175
|
-
if (el) el.scrollTop += 1000;
|
|
176
|
-
return {{success: true}};
|
|
177
|
-
}})()
|
|
178
|
-
""",
|
|
179
|
-
output=ScrollStrategy,
|
|
180
|
-
model="gpt-4o",
|
|
181
|
-
temperature=0.1
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
print(f" AI generated: {strategy.explanation}")
|
|
185
|
-
|
|
186
|
-
# Execute scroll
|
|
187
|
-
import time
|
|
188
|
-
for i in range(times):
|
|
189
|
-
page.evaluate(strategy.javascript)
|
|
190
|
-
time.sleep(1.2)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
def element_scroll_strategy(page, times: int):
|
|
194
|
-
"""Scroll first scrollable element found."""
|
|
195
|
-
import time
|
|
196
|
-
for i in range(times):
|
|
197
|
-
page.evaluate("""
|
|
198
|
-
(() => {
|
|
199
|
-
const el = Array.from(document.querySelectorAll('*')).find(e => {
|
|
200
|
-
const s = window.getComputedStyle(e);
|
|
201
|
-
return (s.overflow === 'auto' || s.overflowY === 'scroll') &&
|
|
202
|
-
e.scrollHeight > e.clientHeight;
|
|
203
|
-
});
|
|
204
|
-
if (el) el.scrollTop += 1000;
|
|
205
|
-
})()
|
|
206
|
-
""")
|
|
207
|
-
time.sleep(1)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def page_scroll_strategy(page, times: int):
|
|
211
|
-
"""Scroll the page window."""
|
|
212
|
-
import time
|
|
213
|
-
for i in range(times):
|
|
214
|
-
page.evaluate("window.scrollBy(0, 1000)")
|
|
215
|
-
time.sleep(1)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
# Additional scroll helpers that can be called directly
|
|
219
|
-
def scroll_page(page, direction: str = "down", amount: int = 1000) -> str:
|
|
220
|
-
"""Scroll the page in a specific direction.
|
|
221
|
-
|
|
222
|
-
Args:
|
|
223
|
-
page: Playwright page object
|
|
224
|
-
direction: "down", "up", "top", or "bottom"
|
|
225
|
-
amount: Pixels to scroll
|
|
226
|
-
|
|
227
|
-
Returns:
|
|
228
|
-
Status message
|
|
229
|
-
"""
|
|
230
|
-
if not page:
|
|
231
|
-
return "Browser not open"
|
|
232
|
-
|
|
233
|
-
if direction == "bottom":
|
|
234
|
-
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
|
|
235
|
-
return "Scrolled to bottom of page"
|
|
236
|
-
elif direction == "top":
|
|
237
|
-
page.evaluate("window.scrollTo(0, 0)")
|
|
238
|
-
return "Scrolled to top of page"
|
|
239
|
-
elif direction == "down":
|
|
240
|
-
page.evaluate(f"window.scrollBy(0, {amount})")
|
|
241
|
-
return f"Scrolled down {amount} pixels"
|
|
242
|
-
elif direction == "up":
|
|
243
|
-
page.evaluate(f"window.scrollBy(0, -{amount})")
|
|
244
|
-
return f"Scrolled up {amount} pixels"
|
|
245
|
-
else:
|
|
246
|
-
return f"Unknown direction: {direction}"
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
def scroll_element(page, selector: str, amount: int = 1000) -> str:
|
|
250
|
-
"""Scroll a specific element by CSS selector.
|
|
251
|
-
|
|
252
|
-
Args:
|
|
253
|
-
page: Playwright page object
|
|
254
|
-
selector: CSS selector for the element
|
|
255
|
-
amount: Pixels to scroll
|
|
256
|
-
|
|
257
|
-
Returns:
|
|
258
|
-
Status message
|
|
259
|
-
"""
|
|
260
|
-
if not page:
|
|
261
|
-
return "Browser not open"
|
|
262
|
-
|
|
263
|
-
result = page.evaluate(f"""
|
|
264
|
-
(() => {{
|
|
265
|
-
const element = document.querySelector('{selector}');
|
|
266
|
-
if (!element) return 'Element not found: {selector}';
|
|
267
|
-
|
|
268
|
-
const beforeScroll = element.scrollTop;
|
|
269
|
-
element.scrollTop += {amount};
|
|
270
|
-
const afterScroll = element.scrollTop;
|
|
271
|
-
|
|
272
|
-
return `Scrolled from ${{beforeScroll}}px to ${{afterScroll}}px (delta: ${{afterScroll - beforeScroll}}px)`;
|
|
273
|
-
}})()
|
|
274
|
-
""")
|
|
275
|
-
|
|
276
|
-
return result
|
connectonion/network/asgi.py
DELETED
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
"""Raw ASGI utilities for HTTP/WebSocket handling.
|
|
2
|
-
|
|
3
|
-
This module contains the protocol-level code for handling HTTP and WebSocket
|
|
4
|
-
requests. Separated from host.py for better testing and smaller file size.
|
|
5
|
-
|
|
6
|
-
Design decision: Raw ASGI instead of Starlette/FastAPI for full protocol control.
|
|
7
|
-
See: docs/design-decisions/022-raw-asgi-implementation.md
|
|
8
|
-
"""
|
|
9
|
-
import asyncio
|
|
10
|
-
import hmac
|
|
11
|
-
import json
|
|
12
|
-
import os
|
|
13
|
-
import queue
|
|
14
|
-
import threading
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
from typing import Any, Dict
|
|
17
|
-
|
|
18
|
-
from pydantic import BaseModel
|
|
19
|
-
|
|
20
|
-
from .connection import Connection
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class AsyncToSyncConnection(Connection):
|
|
24
|
-
"""Bridge async WebSocket to sync Connection interface.
|
|
25
|
-
|
|
26
|
-
Uses queues to communicate between async WebSocket handler and sync agent code.
|
|
27
|
-
The agent runs in a thread, sending/receiving via queues.
|
|
28
|
-
The async handler pumps messages between WebSocket and queues.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
def __init__(self):
|
|
32
|
-
self._outgoing: queue.Queue[Dict[str, Any]] = queue.Queue()
|
|
33
|
-
self._incoming: queue.Queue[Dict[str, Any]] = queue.Queue()
|
|
34
|
-
self._closed = False
|
|
35
|
-
|
|
36
|
-
def send(self, event: Dict[str, Any]) -> None:
|
|
37
|
-
"""Queue event to be sent to client."""
|
|
38
|
-
if not self._closed:
|
|
39
|
-
self._outgoing.put(event)
|
|
40
|
-
|
|
41
|
-
def receive(self) -> Dict[str, Any]:
|
|
42
|
-
"""Block until response from client."""
|
|
43
|
-
return self._incoming.get()
|
|
44
|
-
|
|
45
|
-
def close(self):
|
|
46
|
-
"""Mark connection as closed."""
|
|
47
|
-
self._closed = True
|
|
48
|
-
# Unblock any waiting receive
|
|
49
|
-
self._incoming.put({"type": "connection_closed"})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def _json_default(obj):
|
|
53
|
-
"""Handle non-serializable objects like Pydantic models.
|
|
54
|
-
|
|
55
|
-
This enables native JSON serialization for Pydantic BaseModel instances
|
|
56
|
-
nested in API response dicts, following FastAPI's pattern.
|
|
57
|
-
"""
|
|
58
|
-
if isinstance(obj, BaseModel):
|
|
59
|
-
return obj.model_dump()
|
|
60
|
-
raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
async def read_body(receive) -> bytes:
|
|
64
|
-
"""Read complete request body from ASGI receive."""
|
|
65
|
-
body = b""
|
|
66
|
-
while True:
|
|
67
|
-
m = await receive()
|
|
68
|
-
body += m.get("body", b"")
|
|
69
|
-
if not m.get("more_body"):
|
|
70
|
-
break
|
|
71
|
-
return body
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# CORS headers for cross-origin requests (e.g., frontend at o.openonion.ai
|
|
75
|
-
# calling deployed agents at *.agents.openonion.ai)
|
|
76
|
-
CORS_HEADERS = [
|
|
77
|
-
[b"access-control-allow-origin", b"*"],
|
|
78
|
-
[b"access-control-allow-methods", b"GET, POST, OPTIONS"],
|
|
79
|
-
[b"access-control-allow-headers", b"authorization, content-type"],
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
async def send_json(send, data: dict, status: int = 200):
|
|
84
|
-
"""Send JSON response via ASGI send."""
|
|
85
|
-
body = json.dumps(data, default=_json_default).encode()
|
|
86
|
-
headers = [[b"content-type", b"application/json"]] + CORS_HEADERS
|
|
87
|
-
await send({"type": "http.response.start", "status": status, "headers": headers})
|
|
88
|
-
await send({"type": "http.response.body", "body": body})
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
async def send_html(send, html: bytes, status: int = 200):
|
|
92
|
-
"""Send HTML response via ASGI send."""
|
|
93
|
-
await send({
|
|
94
|
-
"type": "http.response.start",
|
|
95
|
-
"status": status,
|
|
96
|
-
"headers": [[b"content-type", b"text/html; charset=utf-8"]],
|
|
97
|
-
})
|
|
98
|
-
await send({"type": "http.response.body", "body": html})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
async def send_text(send, text: str, status: int = 200):
|
|
102
|
-
"""Send plain text response via ASGI send."""
|
|
103
|
-
headers = [[b"content-type", b"text/plain; charset=utf-8"]] + CORS_HEADERS
|
|
104
|
-
await send({"type": "http.response.start", "status": status, "headers": headers})
|
|
105
|
-
await send({"type": "http.response.body", "body": text.encode()})
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
async def handle_http(
|
|
109
|
-
scope,
|
|
110
|
-
receive,
|
|
111
|
-
send,
|
|
112
|
-
*,
|
|
113
|
-
handlers: dict,
|
|
114
|
-
storage,
|
|
115
|
-
trust: str,
|
|
116
|
-
result_ttl: int,
|
|
117
|
-
start_time: float,
|
|
118
|
-
blacklist: list | None = None,
|
|
119
|
-
whitelist: list | None = None,
|
|
120
|
-
):
|
|
121
|
-
"""Route HTTP requests to handlers.
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
scope: ASGI scope dict (method, path, headers, etc.)
|
|
125
|
-
receive: ASGI receive callable
|
|
126
|
-
send: ASGI send callable
|
|
127
|
-
handlers: Dict of handler functions (input, session, sessions, health, info, auth)
|
|
128
|
-
storage: SessionStorage instance
|
|
129
|
-
trust: Trust level (open/careful/strict)
|
|
130
|
-
result_ttl: How long to keep results in seconds
|
|
131
|
-
start_time: Server start time
|
|
132
|
-
blacklist: Blocked identities
|
|
133
|
-
whitelist: Allowed identities
|
|
134
|
-
"""
|
|
135
|
-
method, path = scope["method"], scope["path"]
|
|
136
|
-
|
|
137
|
-
# Handle CORS preflight requests
|
|
138
|
-
if method == "OPTIONS":
|
|
139
|
-
headers = CORS_HEADERS + [[b"content-length", b"0"]]
|
|
140
|
-
await send({"type": "http.response.start", "status": 204, "headers": headers})
|
|
141
|
-
await send({"type": "http.response.body", "body": b""})
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
# Admin endpoints require API key auth
|
|
145
|
-
if path.startswith("/admin"):
|
|
146
|
-
headers = dict(scope.get("headers", []))
|
|
147
|
-
auth = headers.get(b"authorization", b"").decode()
|
|
148
|
-
expected = os.environ.get("OPENONION_API_KEY", "")
|
|
149
|
-
if not expected or not auth.startswith("Bearer ") or not hmac.compare_digest(auth[7:], expected):
|
|
150
|
-
await send_json(send, {"error": "unauthorized"}, 401)
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
if method == "GET" and path == "/admin/logs":
|
|
154
|
-
result = handlers["admin_logs"]()
|
|
155
|
-
if "error" in result:
|
|
156
|
-
await send_json(send, result, 404)
|
|
157
|
-
else:
|
|
158
|
-
await send_text(send, result["content"])
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
if method == "GET" and path == "/admin/sessions":
|
|
162
|
-
await send_json(send, handlers["admin_sessions"]())
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
await send_json(send, {"error": "not found"}, 404)
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
if method == "POST" and path == "/input":
|
|
169
|
-
body = await read_body(receive)
|
|
170
|
-
try:
|
|
171
|
-
data = json.loads(body) if body else {}
|
|
172
|
-
except json.JSONDecodeError:
|
|
173
|
-
await send_json(send, {"error": "Invalid JSON"}, 400)
|
|
174
|
-
return
|
|
175
|
-
|
|
176
|
-
prompt, identity, sig_valid, err = handlers["auth"](
|
|
177
|
-
data, trust, blacklist=blacklist, whitelist=whitelist
|
|
178
|
-
)
|
|
179
|
-
if err:
|
|
180
|
-
status = 401 if err.startswith("unauthorized") else 403 if err.startswith("forbidden") else 400
|
|
181
|
-
await send_json(send, {"error": err}, status)
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
# Extract session for conversation continuation
|
|
185
|
-
session = data.get("session")
|
|
186
|
-
result = handlers["input"](storage, prompt, result_ttl, session)
|
|
187
|
-
await send_json(send, result)
|
|
188
|
-
|
|
189
|
-
elif method == "GET" and path.startswith("/sessions/"):
|
|
190
|
-
result = handlers["session"](storage, path[10:])
|
|
191
|
-
await send_json(send, result or {"error": "not found"}, 404 if not result else 200)
|
|
192
|
-
|
|
193
|
-
elif method == "GET" and path == "/sessions":
|
|
194
|
-
await send_json(send, handlers["sessions"](storage))
|
|
195
|
-
|
|
196
|
-
elif method == "GET" and path == "/health":
|
|
197
|
-
await send_json(send, handlers["health"](start_time))
|
|
198
|
-
|
|
199
|
-
elif method == "GET" and path == "/info":
|
|
200
|
-
await send_json(send, handlers["info"](trust))
|
|
201
|
-
|
|
202
|
-
elif method == "GET" and path == "/docs":
|
|
203
|
-
# Serve static docs page
|
|
204
|
-
try:
|
|
205
|
-
base = Path(__file__).resolve().parent
|
|
206
|
-
html_path = base / "static" / "docs.html"
|
|
207
|
-
html = html_path.read_bytes()
|
|
208
|
-
except Exception:
|
|
209
|
-
html = b"<html><body><h1>ConnectOnion Docs</h1><p>Docs not found.</p></body></html>"
|
|
210
|
-
await send_html(send, html)
|
|
211
|
-
|
|
212
|
-
else:
|
|
213
|
-
await send_json(send, {"error": "not found"}, 404)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
async def handle_websocket(
|
|
217
|
-
scope,
|
|
218
|
-
receive,
|
|
219
|
-
send,
|
|
220
|
-
*,
|
|
221
|
-
handlers: dict,
|
|
222
|
-
trust: str,
|
|
223
|
-
blacklist: list | None = None,
|
|
224
|
-
whitelist: list | None = None,
|
|
225
|
-
):
|
|
226
|
-
"""Handle WebSocket connections at /ws.
|
|
227
|
-
|
|
228
|
-
Supports bidirectional communication via Connection interface:
|
|
229
|
-
- Agent sends events via connection.log() / connection.send()
|
|
230
|
-
- Agent requests approval via connection.request_approval()
|
|
231
|
-
- Client responds to approval requests
|
|
232
|
-
|
|
233
|
-
Args:
|
|
234
|
-
scope: ASGI scope dict
|
|
235
|
-
receive: ASGI receive callable
|
|
236
|
-
send: ASGI send callable
|
|
237
|
-
handlers: Dict with 'ws_input' and 'auth' handlers
|
|
238
|
-
trust: Trust level
|
|
239
|
-
blacklist: Blocked identities
|
|
240
|
-
whitelist: Allowed identities
|
|
241
|
-
"""
|
|
242
|
-
if scope["path"] != "/ws":
|
|
243
|
-
await send({"type": "websocket.close", "code": 4004})
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
await send({"type": "websocket.accept"})
|
|
247
|
-
|
|
248
|
-
while True:
|
|
249
|
-
msg = await receive()
|
|
250
|
-
if msg["type"] == "websocket.disconnect":
|
|
251
|
-
break
|
|
252
|
-
if msg["type"] == "websocket.receive":
|
|
253
|
-
try:
|
|
254
|
-
data = json.loads(msg.get("text", "{}"))
|
|
255
|
-
except json.JSONDecodeError:
|
|
256
|
-
await send({"type": "websocket.send",
|
|
257
|
-
"text": json.dumps({"type": "ERROR", "message": "Invalid JSON"})})
|
|
258
|
-
continue
|
|
259
|
-
|
|
260
|
-
if data.get("type") == "INPUT":
|
|
261
|
-
prompt, identity, sig_valid, err = handlers["auth"](
|
|
262
|
-
data, trust, blacklist=blacklist, whitelist=whitelist
|
|
263
|
-
)
|
|
264
|
-
if err:
|
|
265
|
-
await send({"type": "websocket.send",
|
|
266
|
-
"text": json.dumps({"type": "ERROR", "message": err})})
|
|
267
|
-
continue
|
|
268
|
-
if not prompt:
|
|
269
|
-
await send({"type": "websocket.send",
|
|
270
|
-
"text": json.dumps({"type": "ERROR", "message": "prompt required"})})
|
|
271
|
-
continue
|
|
272
|
-
|
|
273
|
-
# Create connection for bidirectional communication
|
|
274
|
-
connection = AsyncToSyncConnection()
|
|
275
|
-
agent_done = threading.Event()
|
|
276
|
-
result_holder = [None]
|
|
277
|
-
|
|
278
|
-
def run_agent():
|
|
279
|
-
result_holder[0] = handlers["ws_input"](prompt, connection)
|
|
280
|
-
agent_done.set()
|
|
281
|
-
|
|
282
|
-
# Start agent in thread
|
|
283
|
-
agent_thread = threading.Thread(target=run_agent, daemon=True)
|
|
284
|
-
agent_thread.start()
|
|
285
|
-
|
|
286
|
-
# Pump messages between WebSocket and connection
|
|
287
|
-
await _pump_messages(receive, send, connection, agent_done)
|
|
288
|
-
|
|
289
|
-
# Send final result
|
|
290
|
-
await send({"type": "websocket.send",
|
|
291
|
-
"text": json.dumps({"type": "OUTPUT", "result": result_holder[0]})})
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
async def _pump_messages(ws_receive, ws_send, connection: AsyncToSyncConnection, agent_done: threading.Event):
|
|
295
|
-
"""Pump messages between WebSocket and connection queues.
|
|
296
|
-
|
|
297
|
-
Runs until agent completes. Handles:
|
|
298
|
-
- Outgoing: connection._outgoing queue → WebSocket
|
|
299
|
-
- Incoming: WebSocket → connection._incoming queue (for approval responses)
|
|
300
|
-
"""
|
|
301
|
-
loop = asyncio.get_event_loop()
|
|
302
|
-
|
|
303
|
-
async def send_outgoing():
|
|
304
|
-
"""Send outgoing messages from connection to WebSocket."""
|
|
305
|
-
while not agent_done.is_set():
|
|
306
|
-
# Use run_in_executor for blocking queue.get
|
|
307
|
-
try:
|
|
308
|
-
event = await loop.run_in_executor(
|
|
309
|
-
None, lambda: connection._outgoing.get(timeout=0.05)
|
|
310
|
-
)
|
|
311
|
-
await ws_send({"type": "websocket.send", "text": json.dumps(event)})
|
|
312
|
-
except queue.Empty:
|
|
313
|
-
pass
|
|
314
|
-
|
|
315
|
-
# Drain remaining
|
|
316
|
-
while True:
|
|
317
|
-
try:
|
|
318
|
-
event = connection._outgoing.get_nowait()
|
|
319
|
-
await ws_send({"type": "websocket.send", "text": json.dumps(event)})
|
|
320
|
-
except queue.Empty:
|
|
321
|
-
break
|
|
322
|
-
|
|
323
|
-
async def receive_incoming():
|
|
324
|
-
"""Receive incoming messages from WebSocket to connection."""
|
|
325
|
-
while not agent_done.is_set():
|
|
326
|
-
try:
|
|
327
|
-
msg = await asyncio.wait_for(ws_receive(), timeout=0.1)
|
|
328
|
-
if msg["type"] == "websocket.receive":
|
|
329
|
-
try:
|
|
330
|
-
data = json.loads(msg.get("text", "{}"))
|
|
331
|
-
connection._incoming.put(data)
|
|
332
|
-
except json.JSONDecodeError:
|
|
333
|
-
pass
|
|
334
|
-
elif msg["type"] == "websocket.disconnect":
|
|
335
|
-
connection.close()
|
|
336
|
-
break
|
|
337
|
-
except asyncio.TimeoutError:
|
|
338
|
-
continue
|
|
339
|
-
|
|
340
|
-
# Run both tasks concurrently
|
|
341
|
-
send_task = asyncio.create_task(send_outgoing())
|
|
342
|
-
recv_task = asyncio.create_task(receive_incoming())
|
|
343
|
-
|
|
344
|
-
# Wait for agent to complete
|
|
345
|
-
while not agent_done.is_set():
|
|
346
|
-
await asyncio.sleep(0.05)
|
|
347
|
-
|
|
348
|
-
# Cancel receive task and wait for send to finish draining
|
|
349
|
-
recv_task.cancel()
|
|
350
|
-
try:
|
|
351
|
-
await recv_task
|
|
352
|
-
except asyncio.CancelledError:
|
|
353
|
-
pass
|
|
354
|
-
await send_task
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
def create_app(
|
|
358
|
-
*,
|
|
359
|
-
handlers: dict,
|
|
360
|
-
storage,
|
|
361
|
-
trust: str = "careful",
|
|
362
|
-
result_ttl: int = 86400,
|
|
363
|
-
blacklist: list | None = None,
|
|
364
|
-
whitelist: list | None = None,
|
|
365
|
-
):
|
|
366
|
-
"""Create ASGI application.
|
|
367
|
-
|
|
368
|
-
Args:
|
|
369
|
-
handlers: Dict of handler functions
|
|
370
|
-
storage: SessionStorage instance
|
|
371
|
-
trust: Trust level (open/careful/strict)
|
|
372
|
-
result_ttl: How long to keep results in seconds
|
|
373
|
-
blacklist: Blocked identities
|
|
374
|
-
whitelist: Allowed identities
|
|
375
|
-
|
|
376
|
-
Returns:
|
|
377
|
-
ASGI application callable
|
|
378
|
-
"""
|
|
379
|
-
import time
|
|
380
|
-
start_time = time.time()
|
|
381
|
-
|
|
382
|
-
async def app(scope, receive, send):
|
|
383
|
-
if scope["type"] == "http":
|
|
384
|
-
await handle_http(
|
|
385
|
-
scope,
|
|
386
|
-
receive,
|
|
387
|
-
send,
|
|
388
|
-
handlers=handlers,
|
|
389
|
-
storage=storage,
|
|
390
|
-
trust=trust,
|
|
391
|
-
result_ttl=result_ttl,
|
|
392
|
-
start_time=start_time,
|
|
393
|
-
blacklist=blacklist,
|
|
394
|
-
whitelist=whitelist,
|
|
395
|
-
)
|
|
396
|
-
elif scope["type"] == "websocket":
|
|
397
|
-
await handle_websocket(
|
|
398
|
-
scope,
|
|
399
|
-
receive,
|
|
400
|
-
send,
|
|
401
|
-
handlers=handlers,
|
|
402
|
-
trust=trust,
|
|
403
|
-
blacklist=blacklist,
|
|
404
|
-
whitelist=whitelist,
|
|
405
|
-
)
|
|
406
|
-
|
|
407
|
-
return app
|