@beeos-ai/device-agent 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pi/extensions/android-tools.ts +139 -0
- package/.pi/skills/.gitkeep +0 -0
- package/.pi/skills/ground-mobile-fallback/SKILL.md +50 -0
- package/LICENSE +201 -0
- package/dist/action/handler.d.ts +9 -0
- package/dist/action/handler.js +124 -0
- package/dist/action/handler.js.map +1 -0
- package/dist/adapters/agent-gateway-client.d.ts +256 -0
- package/dist/adapters/agent-gateway-client.js +332 -0
- package/dist/adapters/agent-gateway-client.js.map +1 -0
- package/dist/adapters/agentcore-inner-loop.d.ts +29 -0
- package/dist/adapters/agentcore-inner-loop.js +72 -0
- package/dist/adapters/agentcore-inner-loop.js.map +1 -0
- package/dist/adapters/agentcore-pi.d.ts +215 -0
- package/dist/adapters/agentcore-pi.js +464 -0
- package/dist/adapters/agentcore-pi.js.map +1 -0
- package/dist/adapters/agentcore-runner.d.ts +70 -0
- package/dist/adapters/agentcore-runner.js +255 -0
- package/dist/adapters/agentcore-runner.js.map +1 -0
- package/dist/adapters/device-android-adb.d.ts +41 -0
- package/dist/adapters/device-android-adb.js +279 -0
- package/dist/adapters/device-android-adb.js.map +1 -0
- package/dist/adapters/device-desktop.d.ts +37 -0
- package/dist/adapters/device-desktop.js +101 -0
- package/dist/adapters/device-desktop.js.map +1 -0
- package/dist/adapters/identity-file.d.ts +30 -0
- package/dist/adapters/identity-file.js +50 -0
- package/dist/adapters/identity-file.js.map +1 -0
- package/dist/adapters/transport-bridge-ws.d.ts +39 -0
- package/dist/adapters/transport-bridge-ws.js +49 -0
- package/dist/adapters/transport-bridge-ws.js.map +1 -0
- package/dist/adapters/vlm-inner-loop.d.ts +88 -0
- package/dist/adapters/vlm-inner-loop.js +199 -0
- package/dist/adapters/vlm-inner-loop.js.map +1 -0
- package/dist/agent-runtime/adapters/base.d.ts +145 -0
- package/dist/agent-runtime/adapters/base.js +29 -0
- package/dist/agent-runtime/adapters/base.js.map +1 -0
- package/dist/agent-runtime/adapters/index.d.ts +17 -0
- package/dist/agent-runtime/adapters/index.js +17 -0
- package/dist/agent-runtime/adapters/index.js.map +1 -0
- package/dist/agent-runtime/adapters/mock.d.ts +44 -0
- package/dist/agent-runtime/adapters/mock.js +54 -0
- package/dist/agent-runtime/adapters/mock.js.map +1 -0
- package/dist/agent-runtime/adapters/openai.d.ts +63 -0
- package/dist/agent-runtime/adapters/openai.js +302 -0
- package/dist/agent-runtime/adapters/openai.js.map +1 -0
- package/dist/agent-runtime/adapters/registry.d.ts +49 -0
- package/dist/agent-runtime/adapters/registry.js +129 -0
- package/dist/agent-runtime/adapters/registry.js.map +1 -0
- package/dist/agent-runtime/adapters/ui-tars.d.ts +13 -0
- package/dist/agent-runtime/adapters/ui-tars.js +22 -0
- package/dist/agent-runtime/adapters/ui-tars.js.map +1 -0
- package/dist/agent-runtime/agent-runner.d.ts +149 -0
- package/dist/agent-runtime/agent-runner.js +356 -0
- package/dist/agent-runtime/agent-runner.js.map +1 -0
- package/dist/agent-runtime/core.d.ts +170 -0
- package/dist/agent-runtime/core.js +624 -0
- package/dist/agent-runtime/core.js.map +1 -0
- package/dist/agent-runtime/index.d.ts +16 -0
- package/dist/agent-runtime/index.js +17 -0
- package/dist/agent-runtime/index.js.map +1 -0
- package/dist/agent-runtime/plan-executor.d.ts +118 -0
- package/dist/agent-runtime/plan-executor.js +501 -0
- package/dist/agent-runtime/plan-executor.js.map +1 -0
- package/dist/agent-runtime/planner/base.d.ts +128 -0
- package/dist/agent-runtime/planner/base.js +157 -0
- package/dist/agent-runtime/planner/base.js.map +1 -0
- package/dist/agent-runtime/planner/llm-planner.d.ts +58 -0
- package/dist/agent-runtime/planner/llm-planner.js +112 -0
- package/dist/agent-runtime/planner/llm-planner.js.map +1 -0
- package/dist/agent-runtime/planner/noop-planner.d.ts +13 -0
- package/dist/agent-runtime/planner/noop-planner.js +30 -0
- package/dist/agent-runtime/planner/noop-planner.js.map +1 -0
- package/dist/agent-runtime/planner/prompts.d.ts +33 -0
- package/dist/agent-runtime/planner/prompts.js +165 -0
- package/dist/agent-runtime/planner/prompts.js.map +1 -0
- package/dist/agent-runtime/reflection.d.ts +81 -0
- package/dist/agent-runtime/reflection.js +189 -0
- package/dist/agent-runtime/reflection.js.map +1 -0
- package/dist/agent-runtime/reflectors/action-reflector.d.ts +97 -0
- package/dist/agent-runtime/reflectors/action-reflector.js +233 -0
- package/dist/agent-runtime/reflectors/action-reflector.js.map +1 -0
- package/dist/agent-runtime/reflectors/policy.d.ts +53 -0
- package/dist/agent-runtime/reflectors/policy.js +106 -0
- package/dist/agent-runtime/reflectors/policy.js.map +1 -0
- package/dist/agent-runtime/reflectors/trajectory-reflector.d.ts +94 -0
- package/dist/agent-runtime/reflectors/trajectory-reflector.js +223 -0
- package/dist/agent-runtime/reflectors/trajectory-reflector.js.map +1 -0
- package/dist/agent-runtime/skills/embedding.d.ts +53 -0
- package/dist/agent-runtime/skills/embedding.js +134 -0
- package/dist/agent-runtime/skills/embedding.js.map +1 -0
- package/dist/agent-runtime/skills/fs-store.d.ts +88 -0
- package/dist/agent-runtime/skills/fs-store.js +483 -0
- package/dist/agent-runtime/skills/fs-store.js.map +1 -0
- package/dist/agent-runtime/skills/index.d.ts +10 -0
- package/dist/agent-runtime/skills/index.js +10 -0
- package/dist/agent-runtime/skills/index.js.map +1 -0
- package/dist/agent-runtime/skills/matcher-evolver.d.ts +88 -0
- package/dist/agent-runtime/skills/matcher-evolver.js +110 -0
- package/dist/agent-runtime/skills/matcher-evolver.js.map +1 -0
- package/dist/agent-runtime/skills/memory-store.d.ts +23 -0
- package/dist/agent-runtime/skills/memory-store.js +94 -0
- package/dist/agent-runtime/skills/memory-store.js.map +1 -0
- package/dist/agent-runtime/skills/normalise.d.ts +40 -0
- package/dist/agent-runtime/skills/normalise.js +152 -0
- package/dist/agent-runtime/skills/normalise.js.map +1 -0
- package/dist/agent-runtime/skills/replay.d.ts +46 -0
- package/dist/agent-runtime/skills/replay.js +106 -0
- package/dist/agent-runtime/skills/replay.js.map +1 -0
- package/dist/agent-runtime/skills/sqlite-store.d.ts +60 -0
- package/dist/agent-runtime/skills/sqlite-store.js +234 -0
- package/dist/agent-runtime/skills/sqlite-store.js.map +1 -0
- package/dist/agent-runtime/skills/types.d.ts +99 -0
- package/dist/agent-runtime/skills/types.js +14 -0
- package/dist/agent-runtime/skills/types.js.map +1 -0
- package/dist/agent.d.ts +110 -0
- package/dist/agent.js +162 -0
- package/dist/agent.js.map +1 -0
- package/dist/api.d.ts +27 -0
- package/dist/api.js +48 -0
- package/dist/api.js.map +1 -0
- package/dist/app/agent-host.d.ts +59 -0
- package/dist/app/agent-host.js +263 -0
- package/dist/app/agent-host.js.map +1 -0
- package/dist/app/device-manager.d.ts +28 -0
- package/dist/app/device-manager.js +64 -0
- package/dist/app/device-manager.js.map +1 -0
- package/dist/app/message-store.d.ts +55 -0
- package/dist/app/message-store.js +99 -0
- package/dist/app/message-store.js.map +1 -0
- package/dist/app/session-manager.d.ts +132 -0
- package/dist/app/session-manager.js +350 -0
- package/dist/app/session-manager.js.map +1 -0
- package/dist/bootstrap.d.ts +94 -0
- package/dist/bootstrap.js +459 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/chat.d.ts +16 -0
- package/dist/chat.js +175 -0
- package/dist/chat.js.map +1 -0
- package/dist/config/loader.d.ts +77 -0
- package/dist/config/loader.js +292 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +162 -0
- package/dist/config/schema.js +243 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/actions.d.ts +60 -0
- package/dist/core/actions.js +120 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/errors.d.ts +8 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/screen.d.ts +7 -0
- package/dist/core/screen.js +8 -0
- package/dist/core/screen.js.map +1 -0
- package/dist/core/session.d.ts +42 -0
- package/dist/core/session.js +29 -0
- package/dist/core/session.js.map +1 -0
- package/dist/debug/dump-system-prompt.d.ts +1 -0
- package/dist/debug/dump-system-prompt.js +34 -0
- package/dist/debug/dump-system-prompt.js.map +1 -0
- package/dist/device/android.d.ts +25 -0
- package/dist/device/android.js +231 -0
- package/dist/device/android.js.map +1 -0
- package/dist/device/apps.d.ts +3 -0
- package/dist/device/apps.js +77 -0
- package/dist/device/apps.js.map +1 -0
- package/dist/device/base.d.ts +20 -0
- package/dist/device/base.js +2 -0
- package/dist/device/base.js.map +1 -0
- package/dist/device/ui-xml.d.ts +29 -0
- package/dist/device/ui-xml.js +194 -0
- package/dist/device/ui-xml.js.map +1 -0
- package/dist/fleet/adapters/process/node-process-manager.d.ts +157 -0
- package/dist/fleet/adapters/process/node-process-manager.js +664 -0
- package/dist/fleet/adapters/process/node-process-manager.js.map +1 -0
- package/dist/fleet/adapters/sources/local-adb.d.ts +105 -0
- package/dist/fleet/adapters/sources/local-adb.js +353 -0
- package/dist/fleet/adapters/sources/local-adb.js.map +1 -0
- package/dist/fleet/adapters/sources/remote-adb.d.ts +97 -0
- package/dist/fleet/adapters/sources/remote-adb.js +138 -0
- package/dist/fleet/adapters/sources/remote-adb.js.map +1 -0
- package/dist/fleet/adapters/state/beeos-cli-store.d.ts +72 -0
- package/dist/fleet/adapters/state/beeos-cli-store.js +250 -0
- package/dist/fleet/adapters/state/beeos-cli-store.js.map +1 -0
- package/dist/fleet/adapters/state/port-allocator.d.ts +43 -0
- package/dist/fleet/adapters/state/port-allocator.js +173 -0
- package/dist/fleet/adapters/state/port-allocator.js.map +1 -0
- package/dist/fleet/domain/device.d.ts +138 -0
- package/dist/fleet/domain/device.js +49 -0
- package/dist/fleet/domain/device.js.map +1 -0
- package/dist/fleet/domain/events.d.ts +102 -0
- package/dist/fleet/domain/events.js +15 -0
- package/dist/fleet/domain/events.js.map +1 -0
- package/dist/fleet/domain/fsm.d.ts +122 -0
- package/dist/fleet/domain/fsm.js +475 -0
- package/dist/fleet/domain/fsm.js.map +1 -0
- package/dist/fleet/http/status-client.d.ts +31 -0
- package/dist/fleet/http/status-client.js +115 -0
- package/dist/fleet/http/status-client.js.map +1 -0
- package/dist/fleet/http/status-server.d.ts +64 -0
- package/dist/fleet/http/status-server.js +200 -0
- package/dist/fleet/http/status-server.js.map +1 -0
- package/dist/fleet/index.d.ts +27 -0
- package/dist/fleet/index.js +17 -0
- package/dist/fleet/index.js.map +1 -0
- package/dist/fleet/installer/index.d.ts +12 -0
- package/dist/fleet/installer/index.js +13 -0
- package/dist/fleet/installer/index.js.map +1 -0
- package/dist/fleet/installer/launchd-mac.d.ts +73 -0
- package/dist/fleet/installer/launchd-mac.js +291 -0
- package/dist/fleet/installer/launchd-mac.js.map +1 -0
- package/dist/fleet/installer/service-spec.d.ts +70 -0
- package/dist/fleet/installer/service-spec.js +43 -0
- package/dist/fleet/installer/service-spec.js.map +1 -0
- package/dist/fleet/installer/spawn-env.d.ts +45 -0
- package/dist/fleet/installer/spawn-env.js +224 -0
- package/dist/fleet/installer/spawn-env.js.map +1 -0
- package/dist/fleet/ports/clock.d.ts +19 -0
- package/dist/fleet/ports/clock.js +26 -0
- package/dist/fleet/ports/clock.js.map +1 -0
- package/dist/fleet/ports/device-source.d.ts +28 -0
- package/dist/fleet/ports/device-source.js +18 -0
- package/dist/fleet/ports/device-source.js.map +1 -0
- package/dist/fleet/ports/process-manager.d.ts +110 -0
- package/dist/fleet/ports/process-manager.js +27 -0
- package/dist/fleet/ports/process-manager.js.map +1 -0
- package/dist/fleet/ports/state-registry.d.ts +49 -0
- package/dist/fleet/ports/state-registry.js +12 -0
- package/dist/fleet/ports/state-registry.js.map +1 -0
- package/dist/fleet/supervisor.d.ts +107 -0
- package/dist/fleet/supervisor.js +508 -0
- package/dist/fleet/supervisor.js.map +1 -0
- package/dist/grounding/grounder.d.ts +46 -0
- package/dist/grounding/grounder.js +82 -0
- package/dist/grounding/grounder.js.map +1 -0
- package/dist/inbound/acp/handlers/device.d.ts +43 -0
- package/dist/inbound/acp/handlers/device.js +153 -0
- package/dist/inbound/acp/handlers/device.js.map +1 -0
- package/dist/inbound/acp/handlers/initialize.d.ts +71 -0
- package/dist/inbound/acp/handlers/initialize.js +53 -0
- package/dist/inbound/acp/handlers/initialize.js.map +1 -0
- package/dist/inbound/acp/handlers/models.d.ts +16 -0
- package/dist/inbound/acp/handlers/models.js +23 -0
- package/dist/inbound/acp/handlers/models.js.map +1 -0
- package/dist/inbound/acp/handlers/session.d.ts +51 -0
- package/dist/inbound/acp/handlers/session.js +61 -0
- package/dist/inbound/acp/handlers/session.js.map +1 -0
- package/dist/inbound/acp/handlers/skills.d.ts +8 -0
- package/dist/inbound/acp/handlers/skills.js +9 -0
- package/dist/inbound/acp/handlers/skills.js.map +1 -0
- package/dist/inbound/acp/notifier.d.ts +35 -0
- package/dist/inbound/acp/notifier.js +45 -0
- package/dist/inbound/acp/notifier.js.map +1 -0
- package/dist/inbound/acp/router.d.ts +67 -0
- package/dist/inbound/acp/router.js +179 -0
- package/dist/inbound/acp/router.js.map +1 -0
- package/dist/inbound/cli/fleet-command.d.ts +34 -0
- package/dist/inbound/cli/fleet-command.js +792 -0
- package/dist/inbound/cli/fleet-command.js.map +1 -0
- package/dist/inbound/cli/main.d.ts +38 -0
- package/dist/inbound/cli/main.js +364 -0
- package/dist/inbound/cli/main.js.map +1 -0
- package/dist/inbound/cli/run-command.d.ts +101 -0
- package/dist/inbound/cli/run-command.js +405 -0
- package/dist/inbound/cli/run-command.js.map +1 -0
- package/dist/inbound/cli/skills-command.d.ts +39 -0
- package/dist/inbound/cli/skills-command.js +333 -0
- package/dist/inbound/cli/skills-command.js.map +1 -0
- package/dist/inbound/http/server.d.ts +7 -0
- package/dist/inbound/http/server.js +8 -0
- package/dist/inbound/http/server.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/index.d.ts +37 -0
- package/dist/logger/index.js +84 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/mcp-client/autospawn.d.ts +67 -0
- package/dist/mcp-client/autospawn.js +173 -0
- package/dist/mcp-client/autospawn.js.map +1 -0
- package/dist/mcp-client/client.d.ts +78 -0
- package/dist/mcp-client/client.js +168 -0
- package/dist/mcp-client/client.js.map +1 -0
- package/dist/mcp-client/index.d.ts +7 -0
- package/dist/mcp-client/index.js +4 -0
- package/dist/mcp-client/index.js.map +1 -0
- package/dist/mcp-client/inproc.d.ts +47 -0
- package/dist/mcp-client/inproc.js +229 -0
- package/dist/mcp-client/inproc.js.map +1 -0
- package/dist/mcp-client/runtime.d.ts +34 -0
- package/dist/mcp-client/runtime.js +15 -0
- package/dist/mcp-client/runtime.js.map +1 -0
- package/dist/model/adapters/autoglm.d.ts +31 -0
- package/dist/model/adapters/autoglm.js +409 -0
- package/dist/model/adapters/autoglm.js.map +1 -0
- package/dist/model/adapters/base.d.ts +13 -0
- package/dist/model/adapters/base.js +27 -0
- package/dist/model/adapters/base.js.map +1 -0
- package/dist/model/adapters/guiowl.d.ts +1 -0
- package/dist/model/adapters/guiowl.js +253 -0
- package/dist/model/adapters/guiowl.js.map +1 -0
- package/dist/model/adapters/index.d.ts +6 -0
- package/dist/model/adapters/index.js +8 -0
- package/dist/model/adapters/index.js.map +1 -0
- package/dist/model/adapters/maiui.d.ts +1 -0
- package/dist/model/adapters/maiui.js +117 -0
- package/dist/model/adapters/maiui.js.map +1 -0
- package/dist/model/adapters/qwenvl.d.ts +1 -0
- package/dist/model/adapters/qwenvl.js +108 -0
- package/dist/model/adapters/qwenvl.js.map +1 -0
- package/dist/model/adapters/showui.d.ts +1 -0
- package/dist/model/adapters/showui.js +132 -0
- package/dist/model/adapters/showui.js.map +1 -0
- package/dist/model/adapters/tool-call.d.ts +6 -0
- package/dist/model/adapters/tool-call.js +102 -0
- package/dist/model/adapters/tool-call.js.map +1 -0
- package/dist/model/adapters/uitars.d.ts +1 -0
- package/dist/model/adapters/uitars.js +180 -0
- package/dist/model/adapters/uitars.js.map +1 -0
- package/dist/model/base.d.ts +32 -0
- package/dist/model/base.js +2 -0
- package/dist/model/base.js.map +1 -0
- package/dist/model/client.d.ts +26 -0
- package/dist/model/client.js +300 -0
- package/dist/model/client.js.map +1 -0
- package/dist/model/image/compress.d.ts +53 -0
- package/dist/model/image/compress.js +89 -0
- package/dist/model/image/compress.js.map +1 -0
- package/dist/model/image/transport.d.ts +134 -0
- package/dist/model/image/transport.js +154 -0
- package/dist/model/image/transport.js.map +1 -0
- package/dist/orchestrator-system-prompt.d.ts +6 -0
- package/dist/orchestrator-system-prompt.js +81 -0
- package/dist/orchestrator-system-prompt.js.map +1 -0
- package/dist/pi-context.d.ts +82 -0
- package/dist/pi-context.js +62 -0
- package/dist/pi-context.js.map +1 -0
- package/dist/pi-local-skills.d.ts +17 -0
- package/dist/pi-local-skills.js +24 -0
- package/dist/pi-local-skills.js.map +1 -0
- package/dist/plugins/acp/index.d.ts +46 -0
- package/dist/plugins/acp/index.js +111 -0
- package/dist/plugins/acp/index.js.map +1 -0
- package/dist/plugins/agent-sync/index.d.ts +40 -0
- package/dist/plugins/agent-sync/index.js +98 -0
- package/dist/plugins/agent-sync/index.js.map +1 -0
- package/dist/plugins/http-debug/index.d.ts +30 -0
- package/dist/plugins/http-debug/index.js +64 -0
- package/dist/plugins/http-debug/index.js.map +1 -0
- package/dist/plugins/http-debug/server.d.ts +92 -0
- package/dist/plugins/http-debug/server.js +464 -0
- package/dist/plugins/http-debug/server.js.map +1 -0
- package/dist/ports/agent-core.d.ts +158 -0
- package/dist/ports/agent-core.js +2 -0
- package/dist/ports/agent-core.js.map +1 -0
- package/dist/ports/agent-host.d.ts +125 -0
- package/dist/ports/agent-host.js +23 -0
- package/dist/ports/agent-host.js.map +1 -0
- package/dist/ports/device.d.ts +53 -0
- package/dist/ports/device.js +13 -0
- package/dist/ports/device.js.map +1 -0
- package/dist/ports/identity.d.ts +22 -0
- package/dist/ports/identity.js +9 -0
- package/dist/ports/identity.js.map +1 -0
- package/dist/ports/plugin.d.ts +62 -0
- package/dist/ports/plugin.js +35 -0
- package/dist/ports/plugin.js.map +1 -0
- package/dist/ports/transport.d.ts +32 -0
- package/dist/ports/transport.js +12 -0
- package/dist/ports/transport.js.map +1 -0
- package/dist/ports/vlm.d.ts +59 -0
- package/dist/ports/vlm.js +14 -0
- package/dist/ports/vlm.js.map +1 -0
- package/dist/test-lan-autoglm.d.ts +7 -0
- package/dist/test-lan-autoglm.js +46 -0
- package/dist/test-lan-autoglm.js.map +1 -0
- package/dist/test-mem-breakdown.d.ts +1 -0
- package/dist/test-mem-breakdown.js +103 -0
- package/dist/test-mem-breakdown.js.map +1 -0
- package/dist/test-mem.d.ts +1 -0
- package/dist/test-mem.js +60 -0
- package/dist/test-mem.js.map +1 -0
- package/dist/test-mobile-use.d.ts +1 -0
- package/dist/test-mobile-use.js +18 -0
- package/dist/test-mobile-use.js.map +1 -0
- package/dist/test-screenshot-loop.d.ts +1 -0
- package/dist/test-screenshot-loop.js +43 -0
- package/dist/test-screenshot-loop.js.map +1 -0
- package/dist/test-screenshot.d.ts +1 -0
- package/dist/test-screenshot.js +10 -0
- package/dist/test-screenshot.js.map +1 -0
- package/dist/test-ui-xml-dump.d.ts +15 -0
- package/dist/test-ui-xml-dump.js +49 -0
- package/dist/test-ui-xml-dump.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageTransport — strategy abstraction for delivering a compressed VLM
|
|
3
|
+
* image to the model.
|
|
4
|
+
*
|
|
5
|
+
* bytes ──▶ Transport ──▶ ImageRef
|
|
6
|
+
*
|
|
7
|
+
* Two concrete strategies live in the codebase:
|
|
8
|
+
* - `DataUrlTransport` (Phase A) → inline `data:<mime>;base64,...`
|
|
9
|
+
* - `HttpUrlTransport` (Phase B) → presign + PUT to S3, return signed
|
|
10
|
+
* GET URL
|
|
11
|
+
*
|
|
12
|
+
* `FallbackTransport` composes any two strategies so production traffic
|
|
13
|
+
* can be configured to "prefer http-url, gracefully degrade to data-url
|
|
14
|
+
* on transient upload failure" — keeping a hard correctness floor while
|
|
15
|
+
* still gaining the body-size win when everything is healthy.
|
|
16
|
+
*/
|
|
17
|
+
import { presignFileUpload, putPresignedBytes, } from "../../adapters/agent-gateway-client.js";
|
|
18
|
+
/**
|
|
19
|
+
* Inline-base64 transport. Always succeeds (modulo OOM); the body bloat
|
|
20
|
+
* is bounded only by the input bytes — pair this with `compressForVlm`
|
|
21
|
+
* upstream to stay below ARouter's 5MB body cap.
|
|
22
|
+
*/
|
|
23
|
+
export class DataUrlTransport {
|
|
24
|
+
name = "data-url";
|
|
25
|
+
async send(bytes, mime) {
|
|
26
|
+
const url = `data:${mime};base64,${bytes.toString("base64")}`;
|
|
27
|
+
return { kind: "data-url", url, mime };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Adapter implementation of `HttpUrlFileClient` that hits the live
|
|
32
|
+
* Agent Gateway over HTTP/1.1 with Ed25519 auth. Suitable for
|
|
33
|
+
* production wiring; tests should pass a mock `HttpUrlFileClient`.
|
|
34
|
+
*/
|
|
35
|
+
export class AgentGatewayFileClient {
|
|
36
|
+
opts;
|
|
37
|
+
constructor(opts) {
|
|
38
|
+
this.opts = opts;
|
|
39
|
+
}
|
|
40
|
+
presignFileUpload(args) {
|
|
41
|
+
return presignFileUpload({
|
|
42
|
+
agentGatewayUrl: this.opts.agentGatewayUrl,
|
|
43
|
+
identity: this.opts.identity,
|
|
44
|
+
fileName: args.fileName,
|
|
45
|
+
mimeType: args.mimeType,
|
|
46
|
+
timeoutMs: this.opts.timeoutMs,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
putPresignedBytes(args) {
|
|
50
|
+
return putPresignedBytes({
|
|
51
|
+
uploadUrl: args.uploadUrl,
|
|
52
|
+
bytes: args.bytes,
|
|
53
|
+
mimeType: args.mimeType,
|
|
54
|
+
timeoutMs: this.opts.timeoutMs,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resource-link transport — pre-signs an S3/MinIO PUT URL via Agent
|
|
60
|
+
* Gateway, uploads the (already-compressed) image bytes, and returns
|
|
61
|
+
* the paired pre-signed GET URL as an `kind: "http-url"` `ImageRef`.
|
|
62
|
+
*
|
|
63
|
+
* Why this exists:
|
|
64
|
+
*
|
|
65
|
+
* - ARouter / Cloudfront / nginx in front of `llama.cpp` cap request
|
|
66
|
+
* bodies at ≈5 MB. A raw 1080×1920 PNG screenshot base64-encoded
|
|
67
|
+
* in a chat-completion message routinely overflows that cap, so
|
|
68
|
+
* the only robust path for production traffic is to ship a URL,
|
|
69
|
+
* not bytes.
|
|
70
|
+
* - `llama.cpp`'s vision server fetches `image_url`s natively
|
|
71
|
+
* (subject to its own ≈10 MB / 10 s download caps), making this a
|
|
72
|
+
* transport-only change — no model-side adapter rewrite required.
|
|
73
|
+
*
|
|
74
|
+
* Errors:
|
|
75
|
+
* - Both steps surface `AgentGatewayError`. Compose with
|
|
76
|
+
* `FallbackTransport(http, data)` if the caller wants a graceful
|
|
77
|
+
* degradation to inline base64 on transient upload failure.
|
|
78
|
+
*
|
|
79
|
+
* Body sigv4 caveat: the `Content-Type` MUST equal what was passed at
|
|
80
|
+
* presign time, otherwise S3 returns 403 (signature mismatch). We
|
|
81
|
+
* forward `mime` to both calls so this is automatic.
|
|
82
|
+
*/
|
|
83
|
+
export class HttpUrlTransport {
|
|
84
|
+
client;
|
|
85
|
+
name = "http-url";
|
|
86
|
+
keyPrefix;
|
|
87
|
+
randomUUID;
|
|
88
|
+
now;
|
|
89
|
+
constructor(client, opts = {}) {
|
|
90
|
+
this.client = client;
|
|
91
|
+
this.keyPrefix = opts.keyPrefix ?? "vlm-screenshots/";
|
|
92
|
+
this.randomUUID = opts.randomUUID ?? (() => globalThis.crypto.randomUUID());
|
|
93
|
+
this.now = opts.now ?? (() => Date.now());
|
|
94
|
+
}
|
|
95
|
+
async send(bytes, mime) {
|
|
96
|
+
const ext = mime === "image/png" ? "png" : "jpg";
|
|
97
|
+
const fileName = `${this.keyPrefix}${this.now()}-${this.randomUUID()}.${ext}`;
|
|
98
|
+
const presigned = await this.client.presignFileUpload({ fileName, mimeType: mime });
|
|
99
|
+
if (!presigned.uploadUrl) {
|
|
100
|
+
throw new Error("HttpUrlTransport: presign returned empty uploadUrl");
|
|
101
|
+
}
|
|
102
|
+
await this.client.putPresignedBytes({
|
|
103
|
+
uploadUrl: presigned.uploadUrl,
|
|
104
|
+
bytes,
|
|
105
|
+
mimeType: mime,
|
|
106
|
+
});
|
|
107
|
+
if (!presigned.downloadUrl) {
|
|
108
|
+
// Local dev (LocalStore) returns no presigned GET URL. We refuse
|
|
109
|
+
// to silently lie here — the caller should compose with a
|
|
110
|
+
// `FallbackTransport(http, data)` to recover.
|
|
111
|
+
throw new Error("HttpUrlTransport: backend did not return a downloadUrl (LocalStore mode)");
|
|
112
|
+
}
|
|
113
|
+
return { kind: "http-url", url: presigned.downloadUrl, mime };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const noopLogger = {
|
|
117
|
+
warn() {
|
|
118
|
+
/* no-op */
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Try `primary`; if it throws, log and fall back to `fallback`. The
|
|
123
|
+
* second transport's failure propagates to the caller — we never silently
|
|
124
|
+
* swallow a degraded-mode error.
|
|
125
|
+
*/
|
|
126
|
+
export class FallbackTransport {
|
|
127
|
+
primary;
|
|
128
|
+
fallback;
|
|
129
|
+
name;
|
|
130
|
+
logger;
|
|
131
|
+
onFallback;
|
|
132
|
+
constructor(primary, fallback, opts = {}) {
|
|
133
|
+
this.primary = primary;
|
|
134
|
+
this.fallback = fallback;
|
|
135
|
+
this.name = `fallback(${primary.name}->${fallback.name})`;
|
|
136
|
+
this.logger = opts.logger ?? noopLogger;
|
|
137
|
+
this.onFallback = opts.onFallback;
|
|
138
|
+
}
|
|
139
|
+
async send(bytes, mime) {
|
|
140
|
+
try {
|
|
141
|
+
return await this.primary.send(bytes, mime);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
this.logger.warn("image transport fell back", {
|
|
145
|
+
primary: this.primary.name,
|
|
146
|
+
fallback: this.fallback.name,
|
|
147
|
+
error: err instanceof Error ? err.message : String(err),
|
|
148
|
+
});
|
|
149
|
+
this.onFallback?.(err);
|
|
150
|
+
return await this.fallback.send(bytes, mime);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/model/image/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,wCAAwC,CAAC;AAWhD;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,IAAI,GAAG,UAAU,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,IAAe;QACvC,MAAM,GAAG,GAAG,QAAQ,IAAI,WAAW,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC;CACF;AA6BD;;;;GAIG;AACH,MAAM,OAAO,sBAAsB;IAEd;IADnB,YACmB,IAIhB;QAJgB,SAAI,GAAJ,IAAI,CAIpB;IACA,CAAC;IAEJ,iBAAiB,CAAC,IAA4C;QAC5D,OAAO,iBAAiB,CAAC;YACvB,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe;YAC1C,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAC5B,QAAQ,EAAE,IAAI,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AAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;gBAC5C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;gBAC5B,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aACxD,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outer orchestrator system prompts (pi-coding-agent).
|
|
3
|
+
* Per-tool details live in tool `description` / schema, not here.
|
|
4
|
+
* Select via ORCH_LANG env var: "cn" (default) | "en".
|
|
5
|
+
*/
|
|
6
|
+
const CN = `\
|
|
7
|
+
# Android 手机自动化编排 Agent
|
|
8
|
+
|
|
9
|
+
> 工具的参数、限制、返回格式在 \`tools\` 载荷里定义,本提示词只讲**策略**。
|
|
10
|
+
|
|
11
|
+
## 工具选择
|
|
12
|
+
|
|
13
|
+
| 工具 | 适用场景 |
|
|
14
|
+
|------|----------|
|
|
15
|
+
| \`mobile_use\` | **首选**。大多数任务直接交给它;内部跑 VLM 截图→推理→执行闭环,自主完成多步操作。 |
|
|
16
|
+
| \`ground\` | 需要**精确像素坐标**时:补救 \`mobile_use\` 误触,或配合 adb 手动执行点击。 |
|
|
17
|
+
| \`ui_xml\` | 需要**查看控件树**(resource-id / bounds / clickable)时:调试或确认当前页面状态。 |
|
|
18
|
+
|
|
19
|
+
## 调用规则
|
|
20
|
+
|
|
21
|
+
**\`mobile_use\`**
|
|
22
|
+
- 指令写完整、写具体:界面原文、应用名、需要输入的文字(注明"原样输入、不改写")。
|
|
23
|
+
- 单次调用完成一个连贯子任务;跨 App 的长流程可拆成多次顺序调用。
|
|
24
|
+
- 用 \`max_steps\` 控制步数:**每次调用必须在工具参数里显式传入**(Schema 必填);简单操作 5–10,复杂流程 20–30。
|
|
25
|
+
- 失败后先分析原因(设备状态、参数、当前界面),不要用相同参数盲目重试。
|
|
26
|
+
|
|
27
|
+
**\`ground\` / \`ui_xml\`**
|
|
28
|
+
- 典型组合:\`ui_xml\` 找到 resource-id → \`ground\` 定位像素 → adb 执行。
|
|
29
|
+
- 不能替代 \`mobile_use\` 主路径,只在需要原子级精度时介入。
|
|
30
|
+
|
|
31
|
+
## 多轮对话
|
|
32
|
+
|
|
33
|
+
记住之前的结论和已执行操作,不必每轮从零确认,除非用户改需求或上下文已变。
|
|
34
|
+
|
|
35
|
+
## 任务结束
|
|
36
|
+
|
|
37
|
+
用一两句话总结结果,用中文回复。
|
|
38
|
+
|
|
39
|
+
## 交流
|
|
40
|
+
|
|
41
|
+
用户问你是否具备某工具(如 \`mobile_use\`)时,明确回答可否并一句话说明用途;禁止仅用「hi」等无信息回复。
|
|
42
|
+
`;
|
|
43
|
+
const EN = `\
|
|
44
|
+
# Android device orchestration agent
|
|
45
|
+
|
|
46
|
+
> Tool parameters, limits, and return formats are in the \`tools\` payload. This prompt covers **strategy only**.
|
|
47
|
+
|
|
48
|
+
## Tool selection
|
|
49
|
+
|
|
50
|
+
| Tool | When to use |
|
|
51
|
+
|------|-------------|
|
|
52
|
+
| \`mobile_use\` | **Default.** Handles most tasks; runs a VLM screenshot→reason→act loop autonomously. |
|
|
53
|
+
| \`ground\` | When you need **exact pixel coords**: recover from a mis-tap, or feed coords to adb manually. |
|
|
54
|
+
| \`ui_xml\` | When you need the **view hierarchy** (resource-id / bounds / clickable): debug or verify screen state. |
|
|
55
|
+
|
|
56
|
+
## Calling rules
|
|
57
|
+
|
|
58
|
+
**\`mobile_use\`**
|
|
59
|
+
- Write instructions in full: exact on-screen labels, app names, verbatim text to type (note "paste verbatim, no paraphrase").
|
|
60
|
+
- One call = one coherent subtask; split cross-app flows into sequential calls.
|
|
61
|
+
- \`max_steps\` is **required on every call** (tool schema); use 5–10 for simple actions, 20–30 for complex flows.
|
|
62
|
+
- On failure: diagnose first (device state, args, current screen). Do not retry with the same call.
|
|
63
|
+
|
|
64
|
+
**\`ground\` / \`ui_xml\`**
|
|
65
|
+
- Typical pattern: \`ui_xml\` → find resource-id → \`ground\` → pixel coords → adb tap.
|
|
66
|
+
- These are atomic helpers, not replacements for the \`mobile_use\` main path.
|
|
67
|
+
|
|
68
|
+
## Multi-turn
|
|
69
|
+
|
|
70
|
+
Retain prior conclusions and actions; do not re-confirm from scratch unless intent or context changed.
|
|
71
|
+
|
|
72
|
+
## Task completion
|
|
73
|
+
|
|
74
|
+
Summarize in one or two sentences; match the user's language.
|
|
75
|
+
|
|
76
|
+
## Communication
|
|
77
|
+
|
|
78
|
+
If asked whether you can use a tool (e.g. \`mobile_use\`), answer clearly (yes/no) and one sentence on what it does; do not reply with meaningless fillers like "hi" only.
|
|
79
|
+
`;
|
|
80
|
+
export const ORCHESTRATOR_SYSTEM_PROMPT = (process.env.ORCH_LANG ?? "cn") === "en" ? EN : CN;
|
|
81
|
+
//# sourceMappingURL=orchestrator-system-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator-system-prompt.js","sourceRoot":"","sources":["../src/orchestrator-system-prompt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCV,CAAC;AAEF,MAAM,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCV,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi extension context — process-wide service locator that bridges
|
|
3
|
+
* `PiOrchestratorAgent` (which knows about the sibling `device-mcp-server`,
|
|
4
|
+
* `config.grounder`, and the `mobile_use` runner) and the
|
|
5
|
+
* `.pi/extensions/*.ts` files that pi-coding-agent loads on startup.
|
|
6
|
+
*
|
|
7
|
+
* Why a singleton?
|
|
8
|
+
*
|
|
9
|
+
* pi-coding-agent's `ExtensionContext` (the value passed to
|
|
10
|
+
* `pi.registerTool({ execute })`) is a fixed shape we don't control — it
|
|
11
|
+
* holds the session id, abort signal, and update sink, but no slot for
|
|
12
|
+
* custom dependency injection. Without this module the only way to reach
|
|
13
|
+
* a screenshot from inside an extension was to read `process.env`
|
|
14
|
+
* and `new AndroidDevice(...)`, which (a) bypasses the sibling
|
|
15
|
+
* `device-mcp-server` (so ACP-driven device switches and out-of-process
|
|
16
|
+
* sandboxes are invisible) and (b) bypasses `config.grounder` /
|
|
17
|
+
* `config.mobileUse` (so user-supplied URLs and API keys silently lose).
|
|
18
|
+
*
|
|
19
|
+
* The singleton is **scoped to the lifetime of the active
|
|
20
|
+
* `PiOrchestratorAgent` session**: the adapter calls
|
|
21
|
+
* `setPiExtensionContext(ctx)` immediately before constructing the pi
|
|
22
|
+
* session (so `loader.reload()` and the first `prompt()` see a hot
|
|
23
|
+
* context) and `setPiExtensionContext(null)` on `dispose()`.
|
|
24
|
+
*
|
|
25
|
+
* Tests and harness scripts that call extensions outside of a pi session
|
|
26
|
+
* must call `setPiExtensionContext(...)` themselves; otherwise
|
|
27
|
+
* `getPiExtensionContext()` throws so we don't silently fall back to env
|
|
28
|
+
* defaults.
|
|
29
|
+
*/
|
|
30
|
+
import type { IMcpRuntime } from "./mcp-client/runtime.js";
|
|
31
|
+
import type { IGrounder } from "./grounding/grounder.js";
|
|
32
|
+
export type { IGrounder };
|
|
33
|
+
export interface PiExtensionContext {
|
|
34
|
+
/**
|
|
35
|
+
* Active MCP runtime — typically the sibling `device-mcp-server` HTTP
|
|
36
|
+
* client. Implementations should re-resolve from the bootstrap layer on
|
|
37
|
+
* every call so an ACP `device/select` (or autospawn restart) is
|
|
38
|
+
* reflected immediately on the next tool call.
|
|
39
|
+
*/
|
|
40
|
+
getMcpClient(): IMcpRuntime;
|
|
41
|
+
/**
|
|
42
|
+
* Visual grounder configured from the outer agent's `config.grounder`.
|
|
43
|
+
* Re-built lazily on first access so the underlying HTTP client is
|
|
44
|
+
* shared across `ground` invocations within the same session.
|
|
45
|
+
*/
|
|
46
|
+
getGrounder(): IGrounder;
|
|
47
|
+
/**
|
|
48
|
+
* Run the inner mobile_use VLM loop end-to-end. Returns the final
|
|
49
|
+
* agent message (the same string the legacy `mobileUse(task, maxSteps)`
|
|
50
|
+
* helper returned). Implementations route through `AgentLoop` over the
|
|
51
|
+
* sibling MCP server so step/text callbacks reach the outer host.
|
|
52
|
+
*/
|
|
53
|
+
runMobileUse(task: string, maxSteps: number, abortSignal?: AbortSignal): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Dump the current UI XML, optionally filtered by substring (matches
|
|
56
|
+
* text / resource-id / content-desc / class name, case-insensitive).
|
|
57
|
+
* Implementations call `mcp.uiDump({ format: "raw" })` and pass the
|
|
58
|
+
* result through `formatUiXmlToolOutput`.
|
|
59
|
+
*/
|
|
60
|
+
getUiXml(query?: string): Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Install (or clear, when `ctx` is `null`) the context that
|
|
64
|
+
* `getPiExtensionContext()` resolves. `PiOrchestratorAgent` calls this
|
|
65
|
+
* before booting the pi session and clears it on dispose.
|
|
66
|
+
*
|
|
67
|
+
* Tests / harness scripts that exercise extensions in isolation must
|
|
68
|
+
* `setPiExtensionContext(stub)` first and clear it on teardown to keep
|
|
69
|
+
* other tests deterministic.
|
|
70
|
+
*/
|
|
71
|
+
export declare function setPiExtensionContext(ctx: PiExtensionContext | null): void;
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the active context. Throws when no `PiOrchestratorAgent`
|
|
74
|
+
* session is in flight — extensions are designed to run inside a pi
|
|
75
|
+
* session and should never be invoked from cold storage.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getPiExtensionContext(): PiExtensionContext;
|
|
78
|
+
/**
|
|
79
|
+
* Inspect-without-throw helper. Returns the active context or `null`.
|
|
80
|
+
* Exposed mainly for diagnostics / debug routes.
|
|
81
|
+
*/
|
|
82
|
+
export declare function peekPiExtensionContext(): PiExtensionContext | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi extension context — process-wide service locator that bridges
|
|
3
|
+
* `PiOrchestratorAgent` (which knows about the sibling `device-mcp-server`,
|
|
4
|
+
* `config.grounder`, and the `mobile_use` runner) and the
|
|
5
|
+
* `.pi/extensions/*.ts` files that pi-coding-agent loads on startup.
|
|
6
|
+
*
|
|
7
|
+
* Why a singleton?
|
|
8
|
+
*
|
|
9
|
+
* pi-coding-agent's `ExtensionContext` (the value passed to
|
|
10
|
+
* `pi.registerTool({ execute })`) is a fixed shape we don't control — it
|
|
11
|
+
* holds the session id, abort signal, and update sink, but no slot for
|
|
12
|
+
* custom dependency injection. Without this module the only way to reach
|
|
13
|
+
* a screenshot from inside an extension was to read `process.env`
|
|
14
|
+
* and `new AndroidDevice(...)`, which (a) bypasses the sibling
|
|
15
|
+
* `device-mcp-server` (so ACP-driven device switches and out-of-process
|
|
16
|
+
* sandboxes are invisible) and (b) bypasses `config.grounder` /
|
|
17
|
+
* `config.mobileUse` (so user-supplied URLs and API keys silently lose).
|
|
18
|
+
*
|
|
19
|
+
* The singleton is **scoped to the lifetime of the active
|
|
20
|
+
* `PiOrchestratorAgent` session**: the adapter calls
|
|
21
|
+
* `setPiExtensionContext(ctx)` immediately before constructing the pi
|
|
22
|
+
* session (so `loader.reload()` and the first `prompt()` see a hot
|
|
23
|
+
* context) and `setPiExtensionContext(null)` on `dispose()`.
|
|
24
|
+
*
|
|
25
|
+
* Tests and harness scripts that call extensions outside of a pi session
|
|
26
|
+
* must call `setPiExtensionContext(...)` themselves; otherwise
|
|
27
|
+
* `getPiExtensionContext()` throws so we don't silently fall back to env
|
|
28
|
+
* defaults.
|
|
29
|
+
*/
|
|
30
|
+
let active = null;
|
|
31
|
+
/**
|
|
32
|
+
* Install (or clear, when `ctx` is `null`) the context that
|
|
33
|
+
* `getPiExtensionContext()` resolves. `PiOrchestratorAgent` calls this
|
|
34
|
+
* before booting the pi session and clears it on dispose.
|
|
35
|
+
*
|
|
36
|
+
* Tests / harness scripts that exercise extensions in isolation must
|
|
37
|
+
* `setPiExtensionContext(stub)` first and clear it on teardown to keep
|
|
38
|
+
* other tests deterministic.
|
|
39
|
+
*/
|
|
40
|
+
export function setPiExtensionContext(ctx) {
|
|
41
|
+
active = ctx;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the active context. Throws when no `PiOrchestratorAgent`
|
|
45
|
+
* session is in flight — extensions are designed to run inside a pi
|
|
46
|
+
* session and should never be invoked from cold storage.
|
|
47
|
+
*/
|
|
48
|
+
export function getPiExtensionContext() {
|
|
49
|
+
if (!active) {
|
|
50
|
+
throw new Error("PiExtensionContext is not set — pi extensions must run inside a PiOrchestratorAgent session " +
|
|
51
|
+
"(or call setPiExtensionContext() in tests).");
|
|
52
|
+
}
|
|
53
|
+
return active;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Inspect-without-throw helper. Returns the active context or `null`.
|
|
57
|
+
* Exposed mainly for diagnostics / debug routes.
|
|
58
|
+
*/
|
|
59
|
+
export function peekPiExtensionContext() {
|
|
60
|
+
return active;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=pi-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-context.js","sourceRoot":"","sources":["../src/pi-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AA4CH,IAAI,MAAM,GAA8B,IAAI,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAA8B;IAClE,MAAM,GAAG,GAAG,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,8FAA8F;YAC5F,6CAA6C,CAChD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ResourceDiagnostic, Skill } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
/**
|
|
3
|
+
* Pi 默认会从 package manager 收录 ~/.agents/skills、~/.pi/agent/skills、项目 .pi/skills 等。
|
|
4
|
+
* 这里关闭自动收录(noSkills),只把 `<projectRoot>/.pi/skills` 作为唯一 skill 根目录;
|
|
5
|
+
* skillsOverride 再兜底过滤,避免 CLI 临时路径混进上下文。
|
|
6
|
+
*/
|
|
7
|
+
export declare function projectPiSkillsLoaderOptions(projectRoot: string): {
|
|
8
|
+
noSkills: true;
|
|
9
|
+
additionalSkillPaths: string[];
|
|
10
|
+
skillsOverride: (current: {
|
|
11
|
+
skills: Skill[];
|
|
12
|
+
diagnostics: ResourceDiagnostic[];
|
|
13
|
+
}) => {
|
|
14
|
+
skills: Skill[];
|
|
15
|
+
diagnostics: ResourceDiagnostic[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve, sep } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Pi 默认会从 package manager 收录 ~/.agents/skills、~/.pi/agent/skills、项目 .pi/skills 等。
|
|
5
|
+
* 这里关闭自动收录(noSkills),只把 `<projectRoot>/.pi/skills` 作为唯一 skill 根目录;
|
|
6
|
+
* skillsOverride 再兜底过滤,避免 CLI 临时路径混进上下文。
|
|
7
|
+
*/
|
|
8
|
+
export function projectPiSkillsLoaderOptions(projectRoot) {
|
|
9
|
+
const skillsDir = resolve(projectRoot, ".pi", "skills");
|
|
10
|
+
const additionalSkillPaths = existsSync(skillsDir) ? [skillsDir] : [];
|
|
11
|
+
const prefix = skillsDir.endsWith(sep) ? skillsDir : `${skillsDir}${sep}`;
|
|
12
|
+
return {
|
|
13
|
+
noSkills: true,
|
|
14
|
+
additionalSkillPaths,
|
|
15
|
+
skillsOverride: (current) => ({
|
|
16
|
+
skills: current.skills.filter((s) => {
|
|
17
|
+
const norm = resolve(s.filePath);
|
|
18
|
+
return norm === skillsDir || norm.startsWith(prefix);
|
|
19
|
+
}),
|
|
20
|
+
diagnostics: current.diagnostics,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=pi-local-skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-local-skills.js","sourceRoot":"","sources":["../src/pi-local-skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGzC;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,WAAmB;IAQ9D,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;IAE1E,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,oBAAoB;QACpB,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC5B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;gBACjC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACvD,CAAC,CAAC;YACF,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin — acp.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the device-agent's `AgentHost` to the BeeOS platform via the
|
|
5
|
+
* Agent Control Protocol (ACP) over a WebSocket transport.
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Construct `SessionManager` (subscribes to host events).
|
|
9
|
+
* - Wire ACP handlers (`session/*`, `device/*`, `models/list`, `skills/list`).
|
|
10
|
+
* - Open the Bridge WebSocket, bind the router, fan `session/update`
|
|
11
|
+
* notifications back through the transport.
|
|
12
|
+
*
|
|
13
|
+
* Disabled when `--standalone` (no remote control plane) or `--no-acp`
|
|
14
|
+
* is passed; in that mode only the http-debug plugin is useful.
|
|
15
|
+
*/
|
|
16
|
+
import type { IMcpRuntime } from "../../mcp-client/runtime.js";
|
|
17
|
+
import type { IBridgeTransport } from "../../ports/transport.js";
|
|
18
|
+
import type { AgentPlugin, PluginContext } from "../../ports/plugin.js";
|
|
19
|
+
export interface AcpPluginOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Lazy MCP-runtime resolver. Invoked once per ACP `device/*` request so
|
|
22
|
+
* autospawn restarts / device hot-swaps are transparent to the handlers.
|
|
23
|
+
* Production callers pass through the same `mcpProvider` that the agent
|
|
24
|
+
* core consumes.
|
|
25
|
+
*/
|
|
26
|
+
mcpProvider: () => IMcpRuntime;
|
|
27
|
+
/** Ed25519 identity for the Bridge handshake. */
|
|
28
|
+
keypair: {
|
|
29
|
+
publicKey: Uint8Array;
|
|
30
|
+
privateKey: Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
/** Optional pre-built transport (used by tests for mock injection). */
|
|
33
|
+
transportOverride?: IBridgeTransport;
|
|
34
|
+
}
|
|
35
|
+
export declare class AcpPlugin implements AgentPlugin {
|
|
36
|
+
private readonly opts;
|
|
37
|
+
readonly name = "acp";
|
|
38
|
+
private ctx?;
|
|
39
|
+
private transport;
|
|
40
|
+
private sessions;
|
|
41
|
+
private unbind;
|
|
42
|
+
constructor(opts: AcpPluginOptions);
|
|
43
|
+
init(ctx: PluginContext): Promise<void>;
|
|
44
|
+
start(): Promise<void>;
|
|
45
|
+
stop(): Promise<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin — acp.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the device-agent's `AgentHost` to the BeeOS platform via the
|
|
5
|
+
* Agent Control Protocol (ACP) over a WebSocket transport.
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Construct `SessionManager` (subscribes to host events).
|
|
9
|
+
* - Wire ACP handlers (`session/*`, `device/*`, `models/list`, `skills/list`).
|
|
10
|
+
* - Open the Bridge WebSocket, bind the router, fan `session/update`
|
|
11
|
+
* notifications back through the transport.
|
|
12
|
+
*
|
|
13
|
+
* Disabled when `--standalone` (no remote control plane) or `--no-acp`
|
|
14
|
+
* is passed; in that mode only the http-debug plugin is useful.
|
|
15
|
+
*/
|
|
16
|
+
import { BridgeWsTransport } from "../../adapters/transport-bridge-ws.js";
|
|
17
|
+
import { MessageStore } from "../../app/message-store.js";
|
|
18
|
+
import { SessionManager } from "../../app/session-manager.js";
|
|
19
|
+
import { AcpDeviceHandlers } from "../../inbound/acp/handlers/device.js";
|
|
20
|
+
import { AcpSessionHandlers } from "../../inbound/acp/handlers/session.js";
|
|
21
|
+
import { AcpRouter, bindRouterToTransport } from "../../inbound/acp/router.js";
|
|
22
|
+
import { TransportSessionNotifier } from "../../inbound/acp/notifier.js";
|
|
23
|
+
export class AcpPlugin {
|
|
24
|
+
opts;
|
|
25
|
+
name = "acp";
|
|
26
|
+
ctx;
|
|
27
|
+
transport = null;
|
|
28
|
+
sessions = null;
|
|
29
|
+
unbind = null;
|
|
30
|
+
constructor(opts) {
|
|
31
|
+
this.opts = opts;
|
|
32
|
+
}
|
|
33
|
+
async init(ctx) {
|
|
34
|
+
this.ctx = ctx;
|
|
35
|
+
const { config, log, host } = ctx;
|
|
36
|
+
if (config.disableAcp) {
|
|
37
|
+
log.info("acp: disabled by --no-acp / disableAcp config");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!config.bridgeUrl) {
|
|
41
|
+
log.warn("acp: bridgeUrl unset, plugin will not start");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const transport = this.opts.transportOverride ??
|
|
45
|
+
new BridgeWsTransport({
|
|
46
|
+
bridgeUrl: config.bridgeUrl,
|
|
47
|
+
service: config.bridgeService,
|
|
48
|
+
privateKey: this.opts.keypair.privateKey,
|
|
49
|
+
publicKey: this.opts.keypair.publicKey,
|
|
50
|
+
});
|
|
51
|
+
transport.on("connected", () => log.info("acp: bridge connected"));
|
|
52
|
+
transport.on("disconnected", (reason) => log.warn({ reason }, "acp: bridge disconnected"));
|
|
53
|
+
transport.on("error", (err) => log.error({ err: err.message }, "acp: bridge transport error"));
|
|
54
|
+
const notifier = new TransportSessionNotifier(transport);
|
|
55
|
+
const messageStore = new MessageStore();
|
|
56
|
+
const sessions = new SessionManager({
|
|
57
|
+
host,
|
|
58
|
+
messageStore,
|
|
59
|
+
notifier,
|
|
60
|
+
// `Config.sessionTimeoutMs` is the single source of truth for idle GC.
|
|
61
|
+
// 0 disables the threshold check (effectively keeps sessions forever
|
|
62
|
+
// until `maxSessions` LRU eviction kicks in) — it's surfaced in the
|
|
63
|
+
// schema so kiosk deployments can pin a deterministic value.
|
|
64
|
+
sessionTtlMs: config.sessionTimeoutMs > 0 ? config.sessionTimeoutMs : undefined,
|
|
65
|
+
onSetModel: async (provider, model) => {
|
|
66
|
+
try {
|
|
67
|
+
await host.agent.setModel(provider, model);
|
|
68
|
+
log.info({ provider, model }, "acp: agent model switched");
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
log.warn({ err: e.message, provider, model }, "acp: setModel failed");
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const router = new AcpRouter({
|
|
76
|
+
device: new AcpDeviceHandlers(this.opts.mcpProvider),
|
|
77
|
+
session: new AcpSessionHandlers(sessions),
|
|
78
|
+
log: ({ method, error }) => {
|
|
79
|
+
if (error)
|
|
80
|
+
log.warn({ method, err: error.message }, "acp handler error");
|
|
81
|
+
else
|
|
82
|
+
log.debug({ method }, "acp request");
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
this.transport = transport;
|
|
86
|
+
this.sessions = sessions;
|
|
87
|
+
this.unbind = bindRouterToTransport(router, transport);
|
|
88
|
+
}
|
|
89
|
+
async start() {
|
|
90
|
+
if (!this.transport)
|
|
91
|
+
return;
|
|
92
|
+
await this.transport.connect();
|
|
93
|
+
}
|
|
94
|
+
async stop() {
|
|
95
|
+
if (this.sessions) {
|
|
96
|
+
this.sessions.detach();
|
|
97
|
+
this.sessions = null;
|
|
98
|
+
}
|
|
99
|
+
if (this.unbind) {
|
|
100
|
+
try {
|
|
101
|
+
await this.unbind();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
/* ignore */
|
|
105
|
+
}
|
|
106
|
+
this.unbind = null;
|
|
107
|
+
}
|
|
108
|
+
this.transport = null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/acp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAmBzE,MAAM,OAAO,SAAS;IAOS;IANpB,IAAI,GAAG,KAAK,CAAC;IACd,GAAG,CAAiB;IACpB,SAAS,GAA4B,IAAI,CAAC;IAC1C,QAAQ,GAA0B,IAAI,CAAC;IACvC,MAAM,GAAiC,IAAI,CAAC;IAEpD,YAA6B,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAEvD,KAAK,CAAC,IAAI,CAAC,GAAkB;QAC3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;QAElC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;YAC1D,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,6CAA6C,CAA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AC,MAAM,EAAE,CAAC;YACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin — agent-sync.
|
|
3
|
+
*
|
|
4
|
+
* Posts a single `POST /api/v1/agents/sync` to Agent Gateway during
|
|
5
|
+
* `start()` so the device-agent appears in the platform's Agents
|
|
6
|
+
* directory and is discoverable via A2A.
|
|
7
|
+
*
|
|
8
|
+
* Failure is non-fatal — sync errors only emit a warning, the device
|
|
9
|
+
* still serves ACP normally. This keeps ground-truth agent metadata
|
|
10
|
+
* close to the binary that hosts the actual capabilities, while
|
|
11
|
+
* allowing development setups (no AGW reachability, no key file)
|
|
12
|
+
* to keep working.
|
|
13
|
+
*
|
|
14
|
+
* Resync semantics:
|
|
15
|
+
* - one shot at start (parity with the legacy `main.ts` behavior)
|
|
16
|
+
* - if `BEEOS_AGENT_SYNC_INTERVAL_MS` (or the constructor option) is
|
|
17
|
+
* set to a positive number, we re-post on that cadence; default off
|
|
18
|
+
*/
|
|
19
|
+
import { type AgentDeclarationInput, type AgentGatewayIdentity } from "../../adapters/agent-gateway-client.js";
|
|
20
|
+
import type { AgentPlugin, PluginContext } from "../../ports/plugin.js";
|
|
21
|
+
export interface AgentSyncOptions {
|
|
22
|
+
/** Build the AgentDeclaration on demand (called every sync cycle). */
|
|
23
|
+
buildDeclarations: () => Promise<AgentDeclarationInput[]>;
|
|
24
|
+
/** Resolve the Ed25519 identity each sync cycle (pulled from FileIdentity). */
|
|
25
|
+
loadIdentity: () => Promise<AgentGatewayIdentity | null>;
|
|
26
|
+
/** Cadence for periodic resyncs. 0 / undefined = single shot. */
|
|
27
|
+
intervalMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class AgentSyncPlugin implements AgentPlugin {
|
|
30
|
+
private readonly opts;
|
|
31
|
+
readonly name = "agent-sync";
|
|
32
|
+
private ctx?;
|
|
33
|
+
private timer;
|
|
34
|
+
private stopped;
|
|
35
|
+
constructor(opts: AgentSyncOptions);
|
|
36
|
+
init(ctx: PluginContext): void;
|
|
37
|
+
start(): Promise<void>;
|
|
38
|
+
stop(): Promise<void>;
|
|
39
|
+
private runOnce;
|
|
40
|
+
}
|