@xopcai/xopcbot 0.1.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/README.md +132 -0
- package/README.zh-CN.md +130 -0
- package/dist/__tests__/core.test.d.ts +1 -0
- package/dist/__tests__/core.test.js +72 -0
- package/dist/__tests__/core.test.js.map +1 -0
- package/dist/agent/fallback/__tests__/index.test.d.ts +1 -0
- package/dist/agent/fallback/__tests__/index.test.js +111 -0
- package/dist/agent/fallback/__tests__/index.test.js.map +1 -0
- package/dist/agent/fallback/candidates.d.ts +23 -0
- package/dist/agent/fallback/candidates.js +62 -0
- package/dist/agent/fallback/candidates.js.map +1 -0
- package/dist/agent/fallback/error.d.ts +22 -0
- package/dist/agent/fallback/error.js +27 -0
- package/dist/agent/fallback/error.js.map +1 -0
- package/dist/agent/fallback/index.d.ts +6 -0
- package/dist/agent/fallback/index.js +5 -0
- package/dist/agent/fallback/index.js.map +1 -0
- package/dist/agent/fallback/reason.d.ts +7 -0
- package/dist/agent/fallback/reason.js +78 -0
- package/dist/agent/fallback/reason.js.map +1 -0
- package/dist/agent/fallback/runner.d.ts +22 -0
- package/dist/agent/fallback/runner.js +34 -0
- package/dist/agent/fallback/runner.js.map +1 -0
- package/dist/agent/helpers.d.ts +38 -0
- package/dist/agent/helpers.js +122 -0
- package/dist/agent/helpers.js.map +1 -0
- package/dist/agent/index.d.ts +7 -0
- package/dist/agent/index.js +7 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/memory/compaction.d.ts +63 -0
- package/dist/agent/memory/compaction.js +233 -0
- package/dist/agent/memory/compaction.js.map +1 -0
- package/dist/agent/memory/window.d.ts +29 -0
- package/dist/agent/memory/window.js +64 -0
- package/dist/agent/memory/window.js.map +1 -0
- package/dist/agent/model-manager.d.ts +80 -0
- package/dist/agent/model-manager.js +213 -0
- package/dist/agent/model-manager.js.map +1 -0
- package/dist/agent/prompt/heartbeat.d.ts +97 -0
- package/dist/agent/prompt/heartbeat.js +313 -0
- package/dist/agent/prompt/heartbeat.js.map +1 -0
- package/dist/agent/prompt/index.d.ts +65 -0
- package/dist/agent/prompt/index.js +215 -0
- package/dist/agent/prompt/index.js.map +1 -0
- package/dist/agent/prompt/memory/index.d.ts +37 -0
- package/dist/agent/prompt/memory/index.js +241 -0
- package/dist/agent/prompt/memory/index.js.map +1 -0
- package/dist/agent/prompt/modes.d.ts +44 -0
- package/dist/agent/prompt/modes.js +167 -0
- package/dist/agent/prompt/modes.js.map +1 -0
- package/dist/agent/prompt/safety.d.ts +88 -0
- package/dist/agent/prompt/safety.js +290 -0
- package/dist/agent/prompt/safety.js.map +1 -0
- package/dist/agent/service.d.ts +91 -0
- package/dist/agent/service.js +641 -0
- package/dist/agent/service.js.map +1 -0
- package/dist/agent/session-tracker.d.ts +73 -0
- package/dist/agent/session-tracker.js +137 -0
- package/dist/agent/session-tracker.js.map +1 -0
- package/dist/agent/skills/__tests__/test-framework.test.d.ts +4 -0
- package/dist/agent/skills/__tests__/test-framework.test.js +343 -0
- package/dist/agent/skills/__tests__/test-framework.test.js.map +1 -0
- package/dist/agent/skills/config.d.ts +58 -0
- package/dist/agent/skills/config.js +212 -0
- package/dist/agent/skills/config.js.map +1 -0
- package/dist/agent/skills/index.d.ts +25 -0
- package/dist/agent/skills/index.js +349 -0
- package/dist/agent/skills/index.js.map +1 -0
- package/dist/agent/skills/installer.d.ts +38 -0
- package/dist/agent/skills/installer.js +352 -0
- package/dist/agent/skills/installer.js.map +1 -0
- package/dist/agent/skills/scanner.d.ts +32 -0
- package/dist/agent/skills/scanner.js +265 -0
- package/dist/agent/skills/scanner.js.map +1 -0
- package/dist/agent/skills/test-framework.d.ts +107 -0
- package/dist/agent/skills/test-framework.js +607 -0
- package/dist/agent/skills/test-framework.js.map +1 -0
- package/dist/agent/skills/types.d.ts +181 -0
- package/dist/agent/skills/types.js +7 -0
- package/dist/agent/skills/types.js.map +1 -0
- package/dist/agent/skills/watcher.d.ts +37 -0
- package/dist/agent/skills/watcher.js +124 -0
- package/dist/agent/skills/watcher.js.map +1 -0
- package/dist/agent/tools/communication.d.ts +18 -0
- package/dist/agent/tools/communication.js +56 -0
- package/dist/agent/tools/communication.js.map +1 -0
- package/dist/agent/tools/edit-diff.d.ts +21 -0
- package/dist/agent/tools/edit-diff.js +69 -0
- package/dist/agent/tools/edit-diff.js.map +1 -0
- package/dist/agent/tools/edit.d.ts +13 -0
- package/dist/agent/tools/edit.js +65 -0
- package/dist/agent/tools/edit.js.map +1 -0
- package/dist/agent/tools/find.d.ts +24 -0
- package/dist/agent/tools/find.js +99 -0
- package/dist/agent/tools/find.js.map +1 -0
- package/dist/agent/tools/grep.d.ts +33 -0
- package/dist/agent/tools/grep.js +183 -0
- package/dist/agent/tools/grep.js.map +1 -0
- package/dist/agent/tools/index.d.ts +13 -0
- package/dist/agent/tools/index.js +18 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/list-dir.d.ts +6 -0
- package/dist/agent/tools/list-dir.js +37 -0
- package/dist/agent/tools/list-dir.js.map +1 -0
- package/dist/agent/tools/memory-tool.d.ts +14 -0
- package/dist/agent/tools/memory-tool.js +81 -0
- package/dist/agent/tools/memory-tool.js.map +1 -0
- package/dist/agent/tools/path-utils.d.ts +4 -0
- package/dist/agent/tools/path-utils.js +13 -0
- package/dist/agent/tools/path-utils.js.map +1 -0
- package/dist/agent/tools/read.d.ts +7 -0
- package/dist/agent/tools/read.js +47 -0
- package/dist/agent/tools/read.js.map +1 -0
- package/dist/agent/tools/send-media.d.ts +18 -0
- package/dist/agent/tools/send-media.js +104 -0
- package/dist/agent/tools/send-media.js.map +1 -0
- package/dist/agent/tools/shell.d.ts +13 -0
- package/dist/agent/tools/shell.js +114 -0
- package/dist/agent/tools/shell.js.map +1 -0
- package/dist/agent/tools/truncate.d.ts +36 -0
- package/dist/agent/tools/truncate.js +98 -0
- package/dist/agent/tools/truncate.js.map +1 -0
- package/dist/agent/tools/web.d.ts +14 -0
- package/dist/agent/tools/web.js +109 -0
- package/dist/agent/tools/web.js.map +1 -0
- package/dist/agent/tools/write.d.ts +7 -0
- package/dist/agent/tools/write.js +35 -0
- package/dist/agent/tools/write.js.map +1 -0
- package/dist/agent/types.d.ts +8 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent/typing.d.ts +9 -0
- package/dist/agent/typing.js +32 -0
- package/dist/agent/typing.js.map +1 -0
- package/dist/auth/index.d.ts +12 -0
- package/dist/auth/index.js +14 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth/anthropic.d.ts +7 -0
- package/dist/auth/oauth/anthropic.js +89 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/github-copilot.d.ts +8 -0
- package/dist/auth/oauth/github-copilot.js +35 -0
- package/dist/auth/oauth/github-copilot.js.map +1 -0
- package/dist/auth/oauth/google-antigravity.d.ts +7 -0
- package/dist/auth/oauth/google-antigravity.js +27 -0
- package/dist/auth/oauth/google-antigravity.js.map +1 -0
- package/dist/auth/oauth/google-gemini-cli.d.ts +7 -0
- package/dist/auth/oauth/google-gemini-cli.js +28 -0
- package/dist/auth/oauth/google-gemini-cli.js.map +1 -0
- package/dist/auth/oauth/index.d.ts +14 -0
- package/dist/auth/oauth/index.js +15 -0
- package/dist/auth/oauth/index.js.map +1 -0
- package/dist/auth/oauth/kimi.d.ts +8 -0
- package/dist/auth/oauth/kimi.js +104 -0
- package/dist/auth/oauth/kimi.js.map +1 -0
- package/dist/auth/oauth/minimax.d.ts +8 -0
- package/dist/auth/oauth/minimax.js +109 -0
- package/dist/auth/oauth/minimax.js.map +1 -0
- package/dist/auth/oauth/openai-codex.d.ts +7 -0
- package/dist/auth/oauth/openai-codex.js +33 -0
- package/dist/auth/oauth/openai-codex.js.map +1 -0
- package/dist/auth/oauth/pkce.d.ts +8 -0
- package/dist/auth/oauth/pkce.js +22 -0
- package/dist/auth/oauth/pkce.js.map +1 -0
- package/dist/auth/oauth/qwen.d.ts +7 -0
- package/dist/auth/oauth/qwen.js +114 -0
- package/dist/auth/oauth/qwen.js.map +1 -0
- package/dist/auth/oauth/types.d.ts +46 -0
- package/dist/auth/oauth/types.js +7 -0
- package/dist/auth/oauth/types.js.map +1 -0
- package/dist/auth/profiles/index.d.ts +16 -0
- package/dist/auth/profiles/index.js +17 -0
- package/dist/auth/profiles/index.js.map +1 -0
- package/dist/auth/profiles/oauth.d.ts +12 -0
- package/dist/auth/profiles/oauth.js +106 -0
- package/dist/auth/profiles/oauth.js.map +1 -0
- package/dist/auth/profiles/order.d.ts +19 -0
- package/dist/auth/profiles/order.js +63 -0
- package/dist/auth/profiles/order.js.map +1 -0
- package/dist/auth/profiles/profiles.d.ts +27 -0
- package/dist/auth/profiles/profiles.js +110 -0
- package/dist/auth/profiles/profiles.js.map +1 -0
- package/dist/auth/profiles/store.d.ts +17 -0
- package/dist/auth/profiles/store.js +234 -0
- package/dist/auth/profiles/store.js.map +1 -0
- package/dist/auth/profiles/types.d.ts +64 -0
- package/dist/auth/profiles/types.js +7 -0
- package/dist/auth/profiles/types.js.map +1 -0
- package/dist/auth/profiles/usage.d.ts +24 -0
- package/dist/auth/profiles/usage.js +99 -0
- package/dist/auth/profiles/usage.js.map +1 -0
- package/dist/auth/storage.d.ts +99 -0
- package/dist/auth/storage.js +315 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/bus/index.d.ts +3 -0
- package/dist/bus/index.js +2 -0
- package/dist/bus/index.js.map +1 -0
- package/dist/bus/queue.d.ts +20 -0
- package/dist/bus/queue.js +57 -0
- package/dist/bus/queue.js.map +1 -0
- package/dist/channels/__tests__/access-control.test.d.ts +4 -0
- package/dist/channels/__tests__/access-control.test.js +310 -0
- package/dist/channels/__tests__/access-control.test.js.map +1 -0
- package/dist/channels/__tests__/draft-stream.test.d.ts +4 -0
- package/dist/channels/__tests__/draft-stream.test.js +243 -0
- package/dist/channels/__tests__/draft-stream.test.js.map +1 -0
- package/dist/channels/__tests__/format.test.d.ts +4 -0
- package/dist/channels/__tests__/format.test.js +146 -0
- package/dist/channels/__tests__/format.test.js.map +1 -0
- package/dist/channels/__tests__/manager.test.d.ts +6 -0
- package/dist/channels/__tests__/manager.test.js +34 -0
- package/dist/channels/__tests__/manager.test.js.map +1 -0
- package/dist/channels/__tests__/typing-controller.test.d.ts +4 -0
- package/dist/channels/__tests__/typing-controller.test.js +109 -0
- package/dist/channels/__tests__/typing-controller.test.js.map +1 -0
- package/dist/channels/__tests__/update-offset-store.test.d.ts +7 -0
- package/dist/channels/__tests__/update-offset-store.test.js +35 -0
- package/dist/channels/__tests__/update-offset-store.test.js.map +1 -0
- package/dist/channels/access-control.d.ts +93 -0
- package/dist/channels/access-control.js +201 -0
- package/dist/channels/access-control.js.map +1 -0
- package/dist/channels/draft-stream.d.ts +55 -0
- package/dist/channels/draft-stream.js +211 -0
- package/dist/channels/draft-stream.js.map +1 -0
- package/dist/channels/format.d.ts +38 -0
- package/dist/channels/format.js +187 -0
- package/dist/channels/format.js.map +1 -0
- package/dist/channels/index.d.ts +22 -0
- package/dist/channels/index.js +23 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/manager.d.ts +30 -0
- package/dist/channels/manager.js +125 -0
- package/dist/channels/manager.js.map +1 -0
- package/dist/channels/telegram/__tests__/index.test.d.ts +4 -0
- package/dist/channels/telegram/__tests__/index.test.js +153 -0
- package/dist/channels/telegram/__tests__/index.test.js.map +1 -0
- package/dist/channels/telegram/__tests__/inline-keyboards.test.d.ts +4 -0
- package/dist/channels/telegram/__tests__/inline-keyboards.test.js +99 -0
- package/dist/channels/telegram/__tests__/inline-keyboards.test.js.map +1 -0
- package/dist/channels/telegram/client.d.ts +48 -0
- package/dist/channels/telegram/client.js +177 -0
- package/dist/channels/telegram/client.js.map +1 -0
- package/dist/channels/telegram/command-handler.d.ts +28 -0
- package/dist/channels/telegram/command-handler.js +209 -0
- package/dist/channels/telegram/command-handler.js.map +1 -0
- package/dist/channels/telegram/index.d.ts +8 -0
- package/dist/channels/telegram/index.js +9 -0
- package/dist/channels/telegram/index.js.map +1 -0
- package/dist/channels/telegram/inline-keyboards.d.ts +20 -0
- package/dist/channels/telegram/inline-keyboards.js +38 -0
- package/dist/channels/telegram/inline-keyboards.js.map +1 -0
- package/dist/channels/telegram/plugin.d.ts +33 -0
- package/dist/channels/telegram/plugin.js +640 -0
- package/dist/channels/telegram/plugin.js.map +1 -0
- package/dist/channels/telegram/webhook.d.ts +31 -0
- package/dist/channels/telegram/webhook.js +129 -0
- package/dist/channels/telegram/webhook.js.map +1 -0
- package/dist/channels/types.d.ts +186 -0
- package/dist/channels/types.js +7 -0
- package/dist/channels/types.js.map +1 -0
- package/dist/channels/typing-controller.d.ts +47 -0
- package/dist/channels/typing-controller.js +117 -0
- package/dist/channels/typing-controller.js.map +1 -0
- package/dist/channels/update-offset-store.d.ts +37 -0
- package/dist/channels/update-offset-store.js +165 -0
- package/dist/channels/update-offset-store.js.map +1 -0
- package/dist/channels/whatsapp/index.d.ts +4 -0
- package/dist/channels/whatsapp/index.js +5 -0
- package/dist/channels/whatsapp/index.js.map +1 -0
- package/dist/channels/whatsapp/plugin.d.ts +27 -0
- package/dist/channels/whatsapp/plugin.js +66 -0
- package/dist/channels/whatsapp/plugin.js.map +1 -0
- package/dist/cli/__tests__/registry.test.d.ts +1 -0
- package/dist/cli/__tests__/registry.test.js +366 -0
- package/dist/cli/__tests__/registry.test.js.map +1 -0
- package/dist/cli/commands/agent.d.ts +1 -0
- package/dist/cli/commands/agent.js +216 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +6 -0
- package/dist/cli/commands/auth.js +440 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/config.d.ts +1 -0
- package/dist/cli/commands/config.js +135 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/configure.d.ts +1 -0
- package/dist/cli/commands/configure.js +173 -0
- package/dist/cli/commands/configure.js.map +1 -0
- package/dist/cli/commands/cron.d.ts +1 -0
- package/dist/cli/commands/cron.js +81 -0
- package/dist/cli/commands/cron.js.map +1 -0
- package/dist/cli/commands/gateway.d.ts +1 -0
- package/dist/cli/commands/gateway.js +91 -0
- package/dist/cli/commands/gateway.js.map +1 -0
- package/dist/cli/commands/index.d.ts +0 -0
- package/dist/cli/commands/index.js +2 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/models.d.ts +1 -0
- package/dist/cli/commands/models.js +79 -0
- package/dist/cli/commands/models.js.map +1 -0
- package/dist/cli/commands/onboard.d.ts +1 -0
- package/dist/cli/commands/onboard.js +621 -0
- package/dist/cli/commands/onboard.js.map +1 -0
- package/dist/cli/commands/plugin.d.ts +1 -0
- package/dist/cli/commands/plugin.js +341 -0
- package/dist/cli/commands/plugin.js.map +1 -0
- package/dist/cli/commands/session.d.ts +1 -0
- package/dist/cli/commands/session.js +450 -0
- package/dist/cli/commands/session.js.map +1 -0
- package/dist/cli/commands/skills-test.d.ts +9 -0
- package/dist/cli/commands/skills-test.js +195 -0
- package/dist/cli/commands/skills-test.js.map +1 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +385 -0
- package/dist/cli/commands/skills.js.map +1 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.js +40 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/registry.d.ts +43 -0
- package/dist/cli/registry.js +82 -0
- package/dist/cli/registry.js.map +1 -0
- package/dist/cli/templates.d.ts +19 -0
- package/dist/cli/templates.js +191 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/utils/colors.d.ts +13 -0
- package/dist/cli/utils/colors.js +16 -0
- package/dist/cli/utils/colors.js.map +1 -0
- package/dist/config/__tests__/diff.test.d.ts +1 -0
- package/dist/config/__tests__/diff.test.js +192 -0
- package/dist/config/__tests__/diff.test.js.map +1 -0
- package/dist/config/__tests__/loader.test.d.ts +1 -0
- package/dist/config/__tests__/loader.test.js +356 -0
- package/dist/config/__tests__/loader.test.js.map +1 -0
- package/dist/config/__tests__/paths.test.d.ts +1 -0
- package/dist/config/__tests__/paths.test.js +192 -0
- package/dist/config/__tests__/paths.test.js.map +1 -0
- package/dist/config/__tests__/reload.test.d.ts +1 -0
- package/dist/config/__tests__/reload.test.js +374 -0
- package/dist/config/__tests__/reload.test.js.map +1 -0
- package/dist/config/__tests__/rules.test.d.ts +1 -0
- package/dist/config/__tests__/rules.test.js +204 -0
- package/dist/config/__tests__/rules.test.js.map +1 -0
- package/dist/config/__tests__/schema.test.d.ts +1 -0
- package/dist/config/__tests__/schema.test.js +672 -0
- package/dist/config/__tests__/schema.test.js.map +1 -0
- package/dist/config/diff.d.ts +7 -0
- package/dist/config/diff.js +46 -0
- package/dist/config/diff.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.js +81 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/paths.d.ts +35 -0
- package/dist/config/paths.js +79 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/reload.d.ts +78 -0
- package/dist/config/reload.js +190 -0
- package/dist/config/reload.js.map +1 -0
- package/dist/config/rules.d.ts +42 -0
- package/dist/config/rules.js +114 -0
- package/dist/config/rules.js.map +1 -0
- package/dist/config/schema.d.ts +1340 -0
- package/dist/config/schema.js +611 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/cron/executor.d.ts +54 -0
- package/dist/cron/executor.js +364 -0
- package/dist/cron/executor.js.map +1 -0
- package/dist/cron/index.d.ts +5 -0
- package/dist/cron/index.js +6 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron/persistence.d.ts +61 -0
- package/dist/cron/persistence.js +188 -0
- package/dist/cron/persistence.js.map +1 -0
- package/dist/cron/service.d.ts +94 -0
- package/dist/cron/service.js +382 -0
- package/dist/cron/service.js.map +1 -0
- package/dist/cron/types.d.ts +119 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/cron/validation.d.ts +144 -0
- package/dist/cron/validation.js +113 -0
- package/dist/cron/validation.js.map +1 -0
- package/dist/errors/__tests__/index.test.d.ts +1 -0
- package/dist/errors/__tests__/index.test.js +301 -0
- package/dist/errors/__tests__/index.test.js.map +1 -0
- package/dist/errors/index.d.ts +114 -0
- package/dist/errors/index.js +278 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/gateway/hono/app.d.ts +7 -0
- package/dist/gateway/hono/app.js +668 -0
- package/dist/gateway/hono/app.js.map +1 -0
- package/dist/gateway/hono/index.d.ts +2 -0
- package/dist/gateway/hono/index.js +3 -0
- package/dist/gateway/hono/index.js.map +1 -0
- package/dist/gateway/hono/middleware/auth.d.ts +18 -0
- package/dist/gateway/hono/middleware/auth.js +79 -0
- package/dist/gateway/hono/middleware/auth.js.map +1 -0
- package/dist/gateway/hono/middleware/logger.d.ts +1 -0
- package/dist/gateway/hono/middleware/logger.js +17 -0
- package/dist/gateway/hono/middleware/logger.js.map +1 -0
- package/dist/gateway/hono/sse.d.ts +55 -0
- package/dist/gateway/hono/sse.js +224 -0
- package/dist/gateway/hono/sse.js.map +1 -0
- package/dist/gateway/index.d.ts +4 -0
- package/dist/gateway/index.js +5 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/protocol.d.ts +28 -0
- package/dist/gateway/protocol.js +14 -0
- package/dist/gateway/protocol.js.map +1 -0
- package/dist/gateway/server.d.ts +19 -0
- package/dist/gateway/server.js +64 -0
- package/dist/gateway/server.js.map +1 -0
- package/dist/gateway/service.d.ts +265 -0
- package/dist/gateway/service.js +621 -0
- package/dist/gateway/service.js.map +1 -0
- package/dist/gateway/static/root/assets/main-CfIxL-cL.js +2105 -0
- package/dist/gateway/static/root/assets/main-CfIxL-cL.js.map +1 -0
- package/dist/gateway/static/root/assets/main-DndcTCgX.css +1 -0
- package/dist/gateway/static/root/index.html +116 -0
- package/dist/heartbeat/index.d.ts +1 -0
- package/dist/heartbeat/index.js +2 -0
- package/dist/heartbeat/index.js.map +1 -0
- package/dist/heartbeat/service.d.ts +19 -0
- package/dist/heartbeat/service.js +61 -0
- package/dist/heartbeat/service.js.map +1 -0
- package/dist/plugin-sdk/index.d.ts +21 -0
- package/dist/plugin-sdk/index.js +12 -0
- package/dist/plugin-sdk/index.js.map +1 -0
- package/dist/plugins/__tests__/api.test.d.ts +1 -0
- package/dist/plugins/__tests__/api.test.js +164 -0
- package/dist/plugins/__tests__/api.test.js.map +1 -0
- package/dist/plugins/__tests__/hooks.test.d.ts +1 -0
- package/dist/plugins/__tests__/hooks.test.js +159 -0
- package/dist/plugins/__tests__/hooks.test.js.map +1 -0
- package/dist/plugins/__tests__/loader.test.d.ts +1 -0
- package/dist/plugins/__tests__/loader.test.js +120 -0
- package/dist/plugins/__tests__/loader.test.js.map +1 -0
- package/dist/plugins/api.d.ts +41 -0
- package/dist/plugins/api.js +131 -0
- package/dist/plugins/api.js.map +1 -0
- package/dist/plugins/hooks.d.ts +153 -0
- package/dist/plugins/hooks.js +172 -0
- package/dist/plugins/hooks.js.map +1 -0
- package/dist/plugins/index.d.ts +11 -0
- package/dist/plugins/index.js +16 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/install.d.ts +59 -0
- package/dist/plugins/install.js +324 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +84 -0
- package/dist/plugins/loader.js +545 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/types.d.ts +190 -0
- package/dist/plugins/types.js +7 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/providers/__tests__/registry.test.d.ts +1 -0
- package/dist/providers/__tests__/registry.test.js +110 -0
- package/dist/providers/__tests__/registry.test.js.map +1 -0
- package/dist/providers/api-strategies.d.ts +15 -0
- package/dist/providers/api-strategies.js +96 -0
- package/dist/providers/api-strategies.js.map +1 -0
- package/dist/providers/auto-discovery.d.ts +84 -0
- package/dist/providers/auto-discovery.js +236 -0
- package/dist/providers/auto-discovery.js.map +1 -0
- package/dist/providers/config.d.ts +25 -0
- package/dist/providers/config.js +42 -0
- package/dist/providers/config.js.map +1 -0
- package/dist/providers/index.d.ts +25 -0
- package/dist/providers/index.js +55 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/model-catalog.d.ts +205 -0
- package/dist/providers/model-catalog.js +1071 -0
- package/dist/providers/model-catalog.js.map +1 -0
- package/dist/providers/models-dev-data.d.ts +11 -0
- package/dist/providers/models-dev-data.js +1035 -0
- package/dist/providers/models-dev-data.js.map +1 -0
- package/dist/providers/models-dev.d.ts +30 -0
- package/dist/providers/models-dev.js +42 -0
- package/dist/providers/models-dev.js.map +1 -0
- package/dist/providers/pi-ai.d.ts +62 -0
- package/dist/providers/pi-ai.js +221 -0
- package/dist/providers/pi-ai.js.map +1 -0
- package/dist/providers/provider-catalog.d.ts +173 -0
- package/dist/providers/provider-catalog.js +834 -0
- package/dist/providers/provider-catalog.js.map +1 -0
- package/dist/providers/registry.d.ts +155 -0
- package/dist/providers/registry.js +524 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/types.d.ts +95 -0
- package/dist/providers/types.js +7 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/session/chat-manager.d.ts +49 -0
- package/dist/session/chat-manager.js +167 -0
- package/dist/session/chat-manager.js.map +1 -0
- package/dist/session/chat-types.d.ts +53 -0
- package/dist/session/chat-types.js +63 -0
- package/dist/session/chat-types.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +103 -0
- package/dist/session/manager.js +200 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/store.d.ts +114 -0
- package/dist/session/store.js +687 -0
- package/dist/session/store.js.map +1 -0
- package/dist/session/types.d.ts +88 -0
- package/dist/session/types.js +10 -0
- package/dist/session/types.js.map +1 -0
- package/dist/types/index.d.ts +177 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/providers.d.ts +67 -0
- package/dist/types/providers.js +7 -0
- package/dist/types/providers.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +17 -0
- package/dist/utils/frontmatter.js +104 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/helpers.d.ts +5 -0
- package/dist/utils/helpers.js +36 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/log-store.d.ts +78 -0
- package/dist/utils/log-store.js +432 -0
- package/dist/utils/log-store.js.map +1 -0
- package/dist/utils/logger.d.ts +127 -0
- package/dist/utils/logger.js +481 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logger.types.d.ts +152 -0
- package/dist/utils/logger.types.js +30 -0
- package/dist/utils/logger.types.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill System Types
|
|
3
|
+
*
|
|
4
|
+
* Inspired by openclaw's skill architecture
|
|
5
|
+
*/
|
|
6
|
+
export type SkillInstallKind = 'pnpm' | 'npm' | 'yarn' | 'bun' | 'brew' | 'go' | 'uv' | 'download';
|
|
7
|
+
export interface SkillInstallSpec {
|
|
8
|
+
/** Unique identifier for this install spec */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Installation method */
|
|
11
|
+
kind: SkillInstallKind;
|
|
12
|
+
/** Package name (for node/uv) */
|
|
13
|
+
package?: string;
|
|
14
|
+
/** Formula name (for brew) */
|
|
15
|
+
formula?: string;
|
|
16
|
+
/** Go module path (for go) */
|
|
17
|
+
module?: string;
|
|
18
|
+
/** Download URL (for download) */
|
|
19
|
+
url?: string;
|
|
20
|
+
/** Expected binaries after installation */
|
|
21
|
+
bins?: string[];
|
|
22
|
+
/** Human-readable label */
|
|
23
|
+
label?: string;
|
|
24
|
+
/** Platform restrictions */
|
|
25
|
+
os?: Array<'darwin' | 'linux' | 'win32'>;
|
|
26
|
+
}
|
|
27
|
+
export interface SkillRequires {
|
|
28
|
+
/** Required binaries */
|
|
29
|
+
bins?: string[];
|
|
30
|
+
/** Required environment variables */
|
|
31
|
+
env?: string[];
|
|
32
|
+
/** Any of these binaries (OR condition) */
|
|
33
|
+
anyBins?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface SkillMetadata {
|
|
36
|
+
/** Skill name (from frontmatter) */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Skill description (from frontmatter) */
|
|
39
|
+
description: string;
|
|
40
|
+
/** Emoji icon for UI */
|
|
41
|
+
emoji?: string;
|
|
42
|
+
/** Homepage URL */
|
|
43
|
+
homepage?: string;
|
|
44
|
+
/** Platform restrictions */
|
|
45
|
+
os?: Array<'darwin' | 'linux' | 'win32'>;
|
|
46
|
+
/** Requirements */
|
|
47
|
+
requires?: SkillRequires;
|
|
48
|
+
/** Installation specs */
|
|
49
|
+
install?: SkillInstallSpec[];
|
|
50
|
+
/** OpenClaw compatibility metadata */
|
|
51
|
+
openclaw?: {
|
|
52
|
+
emoji?: string;
|
|
53
|
+
requires?: SkillRequires;
|
|
54
|
+
install?: SkillInstallSpec[];
|
|
55
|
+
os?: Array<'darwin' | 'linux' | 'win32'>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface SkillConfig {
|
|
59
|
+
/** Whether the skill is enabled */
|
|
60
|
+
enabled?: boolean;
|
|
61
|
+
/** API key for the skill */
|
|
62
|
+
apiKey?: string;
|
|
63
|
+
/** Environment variables */
|
|
64
|
+
env?: Record<string, string>;
|
|
65
|
+
/** Custom configuration */
|
|
66
|
+
config?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
export interface SkillsLoadConfig {
|
|
69
|
+
/** Additional skill folders to scan */
|
|
70
|
+
extraDirs?: string[];
|
|
71
|
+
/** Watch skill folders for changes */
|
|
72
|
+
watch?: boolean;
|
|
73
|
+
/** Debounce for the skills watcher (ms) */
|
|
74
|
+
watchDebounceMs?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface SkillsInstallConfig {
|
|
77
|
+
/** Prefer brew for package installation */
|
|
78
|
+
preferBrew?: boolean;
|
|
79
|
+
/** Node package manager preference */
|
|
80
|
+
nodeManager?: 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
81
|
+
}
|
|
82
|
+
export interface SkillsLimitsConfig {
|
|
83
|
+
/** Max number of immediate child directories to consider */
|
|
84
|
+
maxCandidatesPerRoot?: number;
|
|
85
|
+
/** Max number of skills to load per source */
|
|
86
|
+
maxSkillsLoadedPerSource?: number;
|
|
87
|
+
/** Max number of skills to include in prompt */
|
|
88
|
+
maxSkillsInPrompt?: number;
|
|
89
|
+
/** Max characters for skills prompt */
|
|
90
|
+
maxSkillsPromptChars?: number;
|
|
91
|
+
/** Max size (bytes) for SKILL.md file */
|
|
92
|
+
maxSkillFileBytes?: number;
|
|
93
|
+
}
|
|
94
|
+
export interface SkillsConfig {
|
|
95
|
+
/** Bundled skill allowlist */
|
|
96
|
+
allowBundled?: string[];
|
|
97
|
+
/** Load configuration */
|
|
98
|
+
load?: SkillsLoadConfig;
|
|
99
|
+
/** Install configuration */
|
|
100
|
+
install?: SkillsInstallConfig;
|
|
101
|
+
/** Limits configuration */
|
|
102
|
+
limits?: SkillsLimitsConfig;
|
|
103
|
+
/** Per-skill configuration */
|
|
104
|
+
entries?: Record<string, SkillConfig>;
|
|
105
|
+
}
|
|
106
|
+
export interface Skill {
|
|
107
|
+
/** Skill name */
|
|
108
|
+
name: string;
|
|
109
|
+
/** Skill description */
|
|
110
|
+
description: string;
|
|
111
|
+
/** Path to SKILL.md file */
|
|
112
|
+
filePath: string;
|
|
113
|
+
/** Base directory of the skill */
|
|
114
|
+
baseDir: string;
|
|
115
|
+
/** Source of the skill */
|
|
116
|
+
source: 'builtin' | 'workspace' | 'global' | 'extra';
|
|
117
|
+
/** Disable model invocation for this skill */
|
|
118
|
+
disableModelInvocation: boolean;
|
|
119
|
+
/** Parsed metadata */
|
|
120
|
+
metadata: SkillMetadata;
|
|
121
|
+
/** Raw content of SKILL.md */
|
|
122
|
+
content: string;
|
|
123
|
+
}
|
|
124
|
+
export interface SkillEntry {
|
|
125
|
+
skill: Skill;
|
|
126
|
+
metadata: SkillMetadata;
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
config?: SkillConfig;
|
|
129
|
+
}
|
|
130
|
+
export interface SkillEligibilityContext {
|
|
131
|
+
/** Current platform */
|
|
132
|
+
platform: string;
|
|
133
|
+
/** Available binaries */
|
|
134
|
+
hasBin: (bin: string) => boolean;
|
|
135
|
+
/** Has any of these binaries */
|
|
136
|
+
hasAnyBin: (bins: string[]) => boolean;
|
|
137
|
+
/** Remote node context */
|
|
138
|
+
remote?: {
|
|
139
|
+
platforms: string[];
|
|
140
|
+
hasBin: (bin: string) => boolean;
|
|
141
|
+
hasAnyBin: (bins: string[]) => boolean;
|
|
142
|
+
note?: string;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export interface SkillInstallRequest {
|
|
146
|
+
workspaceDir: string;
|
|
147
|
+
skillName: string;
|
|
148
|
+
installId: string;
|
|
149
|
+
timeoutMs?: number;
|
|
150
|
+
}
|
|
151
|
+
export interface SkillInstallResult {
|
|
152
|
+
/** Whether installation succeeded */
|
|
153
|
+
ok: boolean;
|
|
154
|
+
/** Human-readable message */
|
|
155
|
+
message: string;
|
|
156
|
+
/** stdout from install command */
|
|
157
|
+
stdout: string;
|
|
158
|
+
/** stderr from install command */
|
|
159
|
+
stderr: string;
|
|
160
|
+
/** Exit code */
|
|
161
|
+
code: number | null;
|
|
162
|
+
/** Warnings (e.g., security scan findings) */
|
|
163
|
+
warnings?: string[];
|
|
164
|
+
}
|
|
165
|
+
export interface LoadSkillsResult {
|
|
166
|
+
skills: Skill[];
|
|
167
|
+
prompt: string;
|
|
168
|
+
diagnostics: SkillDiagnostic[];
|
|
169
|
+
}
|
|
170
|
+
export interface SkillDiagnostic {
|
|
171
|
+
type: 'warning' | 'collision' | 'error';
|
|
172
|
+
skillName?: string;
|
|
173
|
+
message: string;
|
|
174
|
+
path?: string;
|
|
175
|
+
}
|
|
176
|
+
export interface SkillSnapshot {
|
|
177
|
+
version: string;
|
|
178
|
+
skills: SkillEntry[];
|
|
179
|
+
loadedAt: number;
|
|
180
|
+
workspaceDir: string;
|
|
181
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agent/skills/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill Watcher
|
|
3
|
+
*
|
|
4
|
+
* Watches skill directories for changes and triggers reloads.
|
|
5
|
+
* Inspired by openclaw's skills refresh system
|
|
6
|
+
*/
|
|
7
|
+
import type { SkillLoader } from './index.js';
|
|
8
|
+
export interface SkillWatcherOptions {
|
|
9
|
+
/** Debounce time in milliseconds */
|
|
10
|
+
debounceMs?: number;
|
|
11
|
+
/** Watch these directories */
|
|
12
|
+
watchDirs: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface SkillWatcher {
|
|
15
|
+
/** Start watching */
|
|
16
|
+
start: () => void;
|
|
17
|
+
/** Stop watching */
|
|
18
|
+
stop: () => void;
|
|
19
|
+
/** Check if watching is active */
|
|
20
|
+
isWatching: () => boolean;
|
|
21
|
+
/** Get last refresh time */
|
|
22
|
+
getLastRefreshTime: () => number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a skill watcher
|
|
26
|
+
*/
|
|
27
|
+
export declare function createSkillWatcher(loader: SkillLoader, options: SkillWatcherOptions): SkillWatcher;
|
|
28
|
+
/**
|
|
29
|
+
* Create a skill watcher from loader configuration
|
|
30
|
+
*/
|
|
31
|
+
export declare function createWatcherFromLoader(loader: SkillLoader, options: {
|
|
32
|
+
workspaceDir?: string;
|
|
33
|
+
builtinDir?: string;
|
|
34
|
+
globalDirs?: string[];
|
|
35
|
+
extraDirs?: string[];
|
|
36
|
+
debounceMs?: number;
|
|
37
|
+
}): SkillWatcher | null;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill Watcher
|
|
3
|
+
*
|
|
4
|
+
* Watches skill directories for changes and triggers reloads.
|
|
5
|
+
* Inspired by openclaw's skills refresh system
|
|
6
|
+
*/
|
|
7
|
+
import { watch } from 'fs';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { createLogger } from '../../utils/logger.js';
|
|
10
|
+
const log = createLogger('SkillWatcher');
|
|
11
|
+
/**
|
|
12
|
+
* Create a debounced reload function
|
|
13
|
+
*/
|
|
14
|
+
function createDebouncedReload(loader, debounceMs) {
|
|
15
|
+
let timeout = null;
|
|
16
|
+
let pendingReload = false;
|
|
17
|
+
return () => {
|
|
18
|
+
if (timeout) {
|
|
19
|
+
pendingReload = true;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
timeout = setTimeout(() => {
|
|
23
|
+
timeout = null;
|
|
24
|
+
if (pendingReload) {
|
|
25
|
+
pendingReload = false;
|
|
26
|
+
loader.reload();
|
|
27
|
+
log.info('Skills reloaded after directory changes');
|
|
28
|
+
}
|
|
29
|
+
}, debounceMs);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a skill watcher
|
|
34
|
+
*/
|
|
35
|
+
export function createSkillWatcher(loader, options) {
|
|
36
|
+
const { watchDirs, debounceMs = 1000 } = options;
|
|
37
|
+
const watchers = [];
|
|
38
|
+
const debouncedReload = createDebouncedReload(loader, debounceMs);
|
|
39
|
+
let isWatching = false;
|
|
40
|
+
let lastRefreshTime = Date.now();
|
|
41
|
+
function watchDirectory(dir) {
|
|
42
|
+
try {
|
|
43
|
+
const watcher = watch(dir, { recursive: true }, (eventType, filename) => {
|
|
44
|
+
if (!filename)
|
|
45
|
+
return;
|
|
46
|
+
// Only care about SKILL.md files
|
|
47
|
+
if (filename.toLowerCase() === 'skill.md') {
|
|
48
|
+
log.debug({ eventType, filename, dir }, 'Skill file changed');
|
|
49
|
+
lastRefreshTime = Date.now();
|
|
50
|
+
debouncedReload();
|
|
51
|
+
}
|
|
52
|
+
// Also watch for new directories (potential new skills)
|
|
53
|
+
if (eventType === 'rename') {
|
|
54
|
+
log.debug({ eventType, filename, dir }, 'Directory changed, may be new skill');
|
|
55
|
+
lastRefreshTime = Date.now();
|
|
56
|
+
debouncedReload();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
watchers.push({ watcher, dir });
|
|
60
|
+
log.info({ dir }, 'Watching skill directory');
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
log.warn({ dir, error: err }, 'Failed to watch skill directory');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
start: () => {
|
|
68
|
+
if (isWatching) {
|
|
69
|
+
log.warn('Watcher already started');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const dir of watchDirs) {
|
|
73
|
+
watchDirectory(dir);
|
|
74
|
+
}
|
|
75
|
+
isWatching = true;
|
|
76
|
+
log.info({ dirs: watchDirs }, 'Skill watcher started');
|
|
77
|
+
},
|
|
78
|
+
stop: () => {
|
|
79
|
+
if (!isWatching) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const { watcher } of watchers) {
|
|
83
|
+
watcher.close();
|
|
84
|
+
}
|
|
85
|
+
watchers.length = 0;
|
|
86
|
+
isWatching = false;
|
|
87
|
+
log.info('Skill watcher stopped');
|
|
88
|
+
},
|
|
89
|
+
isWatching: () => isWatching,
|
|
90
|
+
getLastRefreshTime: () => lastRefreshTime,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a skill watcher from loader configuration
|
|
95
|
+
*/
|
|
96
|
+
export function createWatcherFromLoader(loader, options) {
|
|
97
|
+
const watchDirs = [];
|
|
98
|
+
// Add workspace skills directory
|
|
99
|
+
if (options.workspaceDir) {
|
|
100
|
+
const workspaceSkillsDir = join(options.workspaceDir, 'skills');
|
|
101
|
+
watchDirs.push(workspaceSkillsDir);
|
|
102
|
+
}
|
|
103
|
+
// Add builtin directory
|
|
104
|
+
if (options.builtinDir) {
|
|
105
|
+
watchDirs.push(options.builtinDir);
|
|
106
|
+
}
|
|
107
|
+
// Add global directories
|
|
108
|
+
if (options.globalDirs) {
|
|
109
|
+
watchDirs.push(...options.globalDirs);
|
|
110
|
+
}
|
|
111
|
+
// Add extra directories
|
|
112
|
+
if (options.extraDirs) {
|
|
113
|
+
watchDirs.push(...options.extraDirs);
|
|
114
|
+
}
|
|
115
|
+
if (watchDirs.length === 0) {
|
|
116
|
+
log.warn('No directories to watch');
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return createSkillWatcher(loader, {
|
|
120
|
+
watchDirs,
|
|
121
|
+
debounceMs: options.debounceMs ?? 1000,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=watcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../../src/agent/skills/watcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,MAAM,GAAG,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAoBzC;;GAEG;AACH,SAAS,qBAAqB,CAC5B,MAAmB,EACnB,UAAkB;IAElB,IAAI,OAAO,GAA0B,IAAI,CAAC;IAC1C,IAAI,aAAa,GAAG,KAAK,CAAC;IAE1B,OAAO,GAAG,EAAE;QACV,IAAI,OAAO,EAAE,CAAC;YACZ,aAAa,GAAG,IAA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AC,UAAU;QAE5B,kBAAkB,EAAE,GAAG,EAAE,CAAC,eAAe;KAC1C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAmB,EACnB,OAMC;IAED,MAAM,SAAS,GAAa,EAAE,CAAC;IAE/B,iCAAiC;IACjC,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAChE,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,yBAAyB;IACzB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,wBAAwB;IACxB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,EAAE;QAChC,SAAS;QACT,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAI;KACvC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
import type { MessageBus } from '../../bus/index.js';
|
|
3
|
+
declare const MessageSendSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
4
|
+
content: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
5
|
+
mediaUrl: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TString>;
|
|
6
|
+
mediaType: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TEnum<{
|
|
7
|
+
photo: "photo";
|
|
8
|
+
video: "video";
|
|
9
|
+
audio: "audio";
|
|
10
|
+
document: "document";
|
|
11
|
+
}>>;
|
|
12
|
+
}>;
|
|
13
|
+
interface MessageContext {
|
|
14
|
+
channel: string;
|
|
15
|
+
chatId: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function createMessageTool(bus: MessageBus, getContext: () => MessageContext | null): AgentTool<typeof MessageSendSchema, {}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Message tool
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
const MessageSendSchema = Type.Object({
|
|
4
|
+
content: Type.String({ description: 'The message content to send' }),
|
|
5
|
+
mediaUrl: Type.Optional(Type.String({ description: 'URL of the media to send (photo, video, audio, document)' })),
|
|
6
|
+
mediaType: Type.Optional(Type.Enum({
|
|
7
|
+
photo: 'photo',
|
|
8
|
+
video: 'video',
|
|
9
|
+
audio: 'audio',
|
|
10
|
+
document: 'document',
|
|
11
|
+
}, { description: 'Type of media to send' })),
|
|
12
|
+
});
|
|
13
|
+
export function createMessageTool(bus, getContext) {
|
|
14
|
+
return {
|
|
15
|
+
name: 'send_message',
|
|
16
|
+
description: 'Send a message to the current conversation.',
|
|
17
|
+
parameters: MessageSendSchema,
|
|
18
|
+
label: '💬 Send Message',
|
|
19
|
+
async execute(toolCallId, params, _signal) {
|
|
20
|
+
const ctx = getContext();
|
|
21
|
+
if (!ctx) {
|
|
22
|
+
return {
|
|
23
|
+
content: [{ type: 'text', text: 'Error: No active conversation context' }],
|
|
24
|
+
details: {},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const msg = {
|
|
29
|
+
channel: ctx.channel,
|
|
30
|
+
chat_id: ctx.chatId,
|
|
31
|
+
content: params.content,
|
|
32
|
+
mediaUrl: params.mediaUrl,
|
|
33
|
+
mediaType: params.mediaType,
|
|
34
|
+
};
|
|
35
|
+
await bus.publishOutbound(msg);
|
|
36
|
+
const mediaInfo = params.mediaUrl ? ` (with ${params.mediaType || 'media'})` : '';
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: 'text', text: `Message sent successfully${mediaInfo}` }],
|
|
39
|
+
details: {},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Send error: ${error instanceof Error ? error.message : String(error)}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
details: {},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=communication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"communication.js","sourceRoot":"","sources":["../../../src/agent/tools/communication.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAItD,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;IACpE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0DAA0D,EAAE,CAAC,CAAC;IACjH,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE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AM;4BACZ,IAAI,EAAE,eAAe,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;yBAC9E;qBACF;oBACD,OAAO,EAAE,EAAE;iBACZ,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function detectLineEnding(content: string): '\r\n' | '\n';
|
|
2
|
+
export declare function normalizeToLF(text: string): string;
|
|
3
|
+
export declare function restoreLineEndings(text: string, ending: '\r\n' | '\n'): string;
|
|
4
|
+
export declare function normalizeForFuzzyMatch(text: string): string;
|
|
5
|
+
export interface FuzzyMatchResult {
|
|
6
|
+
found: boolean;
|
|
7
|
+
index: number;
|
|
8
|
+
matchLength: number;
|
|
9
|
+
usedFuzzyMatch: boolean;
|
|
10
|
+
originalText: string;
|
|
11
|
+
matchedText: string;
|
|
12
|
+
contentForReplacement: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function fuzzyFindText(original: string, search: string, options?: {
|
|
15
|
+
ignoreWhitespace?: boolean;
|
|
16
|
+
ignoreCase?: boolean;
|
|
17
|
+
}): FuzzyMatchResult;
|
|
18
|
+
export declare function stripBom(text: string): string;
|
|
19
|
+
export declare function generateDiffString(oldText: string, newText: string, filePath: string, options?: {
|
|
20
|
+
contextLines?: number;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Diff utilities for edit tool
|
|
2
|
+
export function detectLineEnding(content) {
|
|
3
|
+
const crlfIdx = content.indexOf('\r\n');
|
|
4
|
+
const lfIdx = content.indexOf('\n');
|
|
5
|
+
if (lfIdx === -1)
|
|
6
|
+
return '\n';
|
|
7
|
+
if (crlfIdx === -1)
|
|
8
|
+
return '\n';
|
|
9
|
+
return crlfIdx < lfIdx ? '\r\n' : '\n';
|
|
10
|
+
}
|
|
11
|
+
export function normalizeToLF(text) {
|
|
12
|
+
return text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
13
|
+
}
|
|
14
|
+
export function restoreLineEndings(text, ending) {
|
|
15
|
+
return ending === '\r\n' ? text.replace(/\n/g, '\r\n') : text;
|
|
16
|
+
}
|
|
17
|
+
export function normalizeForFuzzyMatch(text) {
|
|
18
|
+
return text
|
|
19
|
+
.split('\n').map(line => line.trimEnd()).join('\n')
|
|
20
|
+
.replace(/[\u2018\u2019\u201A\u201B]/g, "'")
|
|
21
|
+
.replace(/[\u201C\u201D\u201E\u201F]/g, '"')
|
|
22
|
+
.replace(/[\u2010\u2011\u2012\u2013\u2014\u2015\u2212]/g, '-')
|
|
23
|
+
.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, ' ');
|
|
24
|
+
}
|
|
25
|
+
export function fuzzyFindText(original, search, options = {}) {
|
|
26
|
+
const { ignoreWhitespace = true, ignoreCase = false } = options;
|
|
27
|
+
// Exact match first
|
|
28
|
+
const exactIdx = ignoreCase
|
|
29
|
+
? original.toLowerCase().indexOf(search.toLowerCase())
|
|
30
|
+
: original.indexOf(search);
|
|
31
|
+
if (exactIdx !== -1) {
|
|
32
|
+
return { found: true, index: exactIdx, matchLength: search.length, usedFuzzyMatch: false, originalText: search, matchedText: search, contentForReplacement: original };
|
|
33
|
+
}
|
|
34
|
+
// Fuzzy match
|
|
35
|
+
const normalizedOriginal = ignoreWhitespace ? normalizeForFuzzyMatch(original) : original;
|
|
36
|
+
const normalizedSearch = ignoreWhitespace ? normalizeForFuzzyMatch(search) : search;
|
|
37
|
+
const fuzzyIdx = ignoreCase
|
|
38
|
+
? normalizedOriginal.toLowerCase().indexOf(normalizedSearch.toLowerCase())
|
|
39
|
+
: normalizedOriginal.indexOf(normalizedSearch);
|
|
40
|
+
if (fuzzyIdx !== -1) {
|
|
41
|
+
return { found: true, index: fuzzyIdx, matchLength: search.length, usedFuzzyMatch: true, originalText: search, matchedText: search, contentForReplacement: original };
|
|
42
|
+
}
|
|
43
|
+
return { found: false, index: -1, matchLength: 0, usedFuzzyMatch: false, originalText: search, matchedText: '', contentForReplacement: '' };
|
|
44
|
+
}
|
|
45
|
+
export function stripBom(text) {
|
|
46
|
+
return text.replace(/^\uFEFF/, '');
|
|
47
|
+
}
|
|
48
|
+
export function generateDiffString(oldText, newText, filePath, options = {}) {
|
|
49
|
+
const oldLines = oldText.split('\n');
|
|
50
|
+
const newLines = newText.split('\n');
|
|
51
|
+
const _contextLines = options.contextLines ?? 0;
|
|
52
|
+
let diff = `--- ${filePath}\n+++ ${filePath}\n`;
|
|
53
|
+
// Simple diff: show before/after
|
|
54
|
+
if (oldLines.length === 0) {
|
|
55
|
+
diff += '@@ -0,0 +1,' + newLines.length + ' @@\n';
|
|
56
|
+
newLines.forEach((line, _i) => diff += '+' + line + '\n');
|
|
57
|
+
}
|
|
58
|
+
else if (newLines.length === 0) {
|
|
59
|
+
diff += '@@ -1,' + oldLines.length + ' +0,0 @@\n';
|
|
60
|
+
oldLines.forEach((line) => diff += '-' + line + '\n');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
diff += '@@ -1,' + oldLines.length + ' +1,' + newLines.length + ' @@\n';
|
|
64
|
+
oldLines.forEach((line) => diff += '-' + line + '\n');
|
|
65
|
+
newLines.forEach((line) => diff += '+' + line + '\n');
|
|
66
|
+
}
|
|
67
|
+
return diff;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=edit-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/agent/tools/edit-diff.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAA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O,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
declare const EditFileSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
3
|
+
path: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
4
|
+
oldText: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
5
|
+
newText: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
6
|
+
}>;
|
|
7
|
+
export interface EditToolDetails {
|
|
8
|
+
diff?: string;
|
|
9
|
+
firstChangedLine?: number;
|
|
10
|
+
fuzzyMatchUsed?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const editFileTool: AgentTool<typeof EditFileSchema, EditToolDetails>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Edit file tool
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { readFile, writeFile, stat } from 'fs/promises';
|
|
4
|
+
import { normalize } from 'path';
|
|
5
|
+
import { checkFileSafety } from '../prompt/safety.js';
|
|
6
|
+
import { normalizeToLF, restoreLineEndings, normalizeForFuzzyMatch, fuzzyFindText, stripBom, generateDiffString } from './edit-diff.js';
|
|
7
|
+
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
8
|
+
const EditFileSchema = Type.Object({
|
|
9
|
+
path: Type.String({ description: 'File path to edit' }),
|
|
10
|
+
oldText: Type.String({ description: 'Text to replace' }),
|
|
11
|
+
newText: Type.String({ description: 'Replacement text' }),
|
|
12
|
+
});
|
|
13
|
+
export const editFileTool = {
|
|
14
|
+
name: 'edit_file',
|
|
15
|
+
description: 'Edit file by replacing text.',
|
|
16
|
+
parameters: EditFileSchema,
|
|
17
|
+
label: '✏️ Edit',
|
|
18
|
+
async execute(toolCallId, params, _signal) {
|
|
19
|
+
try {
|
|
20
|
+
const safety = checkFileSafety('write', params.path);
|
|
21
|
+
if (!safety.allowed)
|
|
22
|
+
return { content: [{ type: 'text', text: `🚫 ${safety.message}` }], details: {} };
|
|
23
|
+
const normalized = normalize(params.path);
|
|
24
|
+
const stats = await stat(normalized);
|
|
25
|
+
if (stats.size > MAX_FILE_SIZE)
|
|
26
|
+
return { content: [{ type: 'text', text: `🚫 File too large` }], details: {} };
|
|
27
|
+
const rawContent = await readFile(normalized, 'utf-8');
|
|
28
|
+
const content = stripBom(rawContent);
|
|
29
|
+
const lineEnding = detectLineEnding(rawContent);
|
|
30
|
+
const normalizedContent = normalizeToLF(content);
|
|
31
|
+
const normalizedOldText = normalizeToLF(params.oldText);
|
|
32
|
+
const normalizedNewText = normalizeToLF(params.newText);
|
|
33
|
+
const matchResult = fuzzyFindText(normalizedContent, normalizedOldText);
|
|
34
|
+
if (!matchResult.found)
|
|
35
|
+
return { content: [{ type: 'text', text: `Error: oldText not found` }], details: {} };
|
|
36
|
+
const fuzzyContent = normalizeForFuzzyMatch(normalizedContent);
|
|
37
|
+
const fuzzyOldText = normalizeForFuzzyMatch(normalizedOldText);
|
|
38
|
+
const occurrences = fuzzyContent.split(fuzzyOldText).length - 1;
|
|
39
|
+
if (occurrences > 1)
|
|
40
|
+
return { content: [{ type: 'text', text: `Error: ${occurrences} occurrences found, text must be unique` }], details: {} };
|
|
41
|
+
const baseContent = matchResult.contentForReplacement;
|
|
42
|
+
const newContent = baseContent.substring(0, matchResult.index) + normalizedNewText + baseContent.substring(matchResult.index + matchResult.matchLength);
|
|
43
|
+
const finalContent = restoreLineEndings(newContent, lineEnding);
|
|
44
|
+
const originalWithReplacement = restoreLineEndings(baseContent, lineEnding);
|
|
45
|
+
if (originalWithReplacement === finalContent)
|
|
46
|
+
return { content: [{ type: 'text', text: `Error: No changes` }], details: {} };
|
|
47
|
+
const diffResult = generateDiffString(originalWithReplacement, finalContent, params.path);
|
|
48
|
+
await writeFile(params.path, finalContent, 'utf-8');
|
|
49
|
+
return { content: [{ type: 'text', text: `File edited: ${params.path}` }], details: { diff: diffResult, fuzzyMatchUsed: matchResult.usedFuzzyMatch } };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` }], details: {} };
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
function detectLineEnding(content) {
|
|
57
|
+
const crlfIdx = content.indexOf('\r\n');
|
|
58
|
+
const lfIdx = content.indexOf('\n');
|
|
59
|
+
if (lfIdx === -1)
|
|
60
|
+
return '\n';
|
|
61
|
+
if (crlfIdx === -1)
|
|
62
|
+
return '\n';
|
|
63
|
+
return crlfIdx < lfIdx ? '\r\n' : '\n';
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/agent/tools/edit.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,aAAa,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAExI,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAA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typebox';
|
|
2
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
3
|
+
import { type TruncationResult } from './truncate.js';
|
|
4
|
+
declare const findSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
5
|
+
pattern: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
6
|
+
path: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TString>;
|
|
7
|
+
limit: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TNumber>;
|
|
8
|
+
}>;
|
|
9
|
+
export type FindToolInput = Static<typeof findSchema>;
|
|
10
|
+
export interface FindToolDetails {
|
|
11
|
+
truncation?: TruncationResult;
|
|
12
|
+
resultLimitReached?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Find tool - Search for files by glob pattern
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFindTool(cwd: string): AgentTool<typeof findSchema>;
|
|
18
|
+
/** Default find tool using process.cwd() */
|
|
19
|
+
export declare const findTool: AgentTool<import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
20
|
+
pattern: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
21
|
+
path: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TString>;
|
|
22
|
+
limit: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TNumber>;
|
|
23
|
+
}>, any>;
|
|
24
|
+
export {};
|