@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,18 @@
|
|
|
1
|
+
import { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
import type { MessageBus } from '../../bus/index.js';
|
|
3
|
+
declare const SendMediaSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
4
|
+
filePath: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
5
|
+
mediaType: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TEnum<{
|
|
6
|
+
photo: "photo";
|
|
7
|
+
video: "video";
|
|
8
|
+
audio: "audio";
|
|
9
|
+
document: "document";
|
|
10
|
+
}>>;
|
|
11
|
+
caption: import("@sinclair/typebox/build/cjs/index.js").TOptional<import("@sinclair/typebox/build/cjs/index.js").TString>;
|
|
12
|
+
}>;
|
|
13
|
+
interface MessageContext {
|
|
14
|
+
channel: string;
|
|
15
|
+
chatId: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function createSendMediaTool(bus: MessageBus, getContext: () => MessageContext | null): AgentTool<typeof SendMediaSchema, {}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Send media tool - allows sending local files as media
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
const SendMediaSchema = Type.Object({
|
|
5
|
+
filePath: Type.String({ description: 'Local file path to send' }),
|
|
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 (auto-detected if not specified)' })),
|
|
12
|
+
caption: Type.Optional(Type.String({ description: 'Caption for the media' })),
|
|
13
|
+
});
|
|
14
|
+
// Detect media type from file extension
|
|
15
|
+
function detectMediaType(filePath) {
|
|
16
|
+
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
17
|
+
const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
|
|
18
|
+
const videoExts = ['mp4', 'mov', 'avi', 'webm', 'mkv'];
|
|
19
|
+
const audioExts = ['mp3', 'wav', 'ogg', 'm4a', 'flac'];
|
|
20
|
+
if (imageExts.includes(ext || ''))
|
|
21
|
+
return 'photo';
|
|
22
|
+
if (videoExts.includes(ext || ''))
|
|
23
|
+
return 'video';
|
|
24
|
+
if (audioExts.includes(ext || ''))
|
|
25
|
+
return 'audio';
|
|
26
|
+
return 'document';
|
|
27
|
+
}
|
|
28
|
+
// Detect MIME type from file extension
|
|
29
|
+
function detectMimeType(filePath) {
|
|
30
|
+
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
31
|
+
const mimeMap = {
|
|
32
|
+
jpg: 'image/jpeg',
|
|
33
|
+
jpeg: 'image/jpeg',
|
|
34
|
+
png: 'image/png',
|
|
35
|
+
gif: 'image/gif',
|
|
36
|
+
webp: 'image/webp',
|
|
37
|
+
bmp: 'image/bmp',
|
|
38
|
+
svg: 'image/svg+xml',
|
|
39
|
+
mp4: 'video/mp4',
|
|
40
|
+
mov: 'video/quicktime',
|
|
41
|
+
avi: 'video/x-msvideo',
|
|
42
|
+
webm: 'video/webm',
|
|
43
|
+
mp3: 'audio/mpeg',
|
|
44
|
+
wav: 'audio/wav',
|
|
45
|
+
ogg: 'audio/ogg',
|
|
46
|
+
m4a: 'audio/mp4',
|
|
47
|
+
flac: 'audio/flac',
|
|
48
|
+
pdf: 'application/pdf',
|
|
49
|
+
doc: 'application/msword',
|
|
50
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
51
|
+
txt: 'text/plain',
|
|
52
|
+
zip: 'application/zip',
|
|
53
|
+
rar: 'application/x-rar-compressed',
|
|
54
|
+
};
|
|
55
|
+
return mimeMap[ext || ''] || 'application/octet-stream';
|
|
56
|
+
}
|
|
57
|
+
export function createSendMediaTool(bus, getContext) {
|
|
58
|
+
return {
|
|
59
|
+
name: 'send_media',
|
|
60
|
+
description: 'Send a media file (photo, video, audio, document) from local filesystem to the current conversation.',
|
|
61
|
+
parameters: SendMediaSchema,
|
|
62
|
+
label: '📎 Send Media',
|
|
63
|
+
async execute(toolCallId, params, _signal) {
|
|
64
|
+
const ctx = getContext();
|
|
65
|
+
if (!ctx) {
|
|
66
|
+
return {
|
|
67
|
+
content: [{ type: 'text', text: 'Error: No active conversation context' }],
|
|
68
|
+
details: {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
// Read the local file
|
|
73
|
+
const fileBuffer = await readFile(params.filePath);
|
|
74
|
+
const base64 = fileBuffer.toString('base64');
|
|
75
|
+
const mimeType = detectMimeType(params.filePath);
|
|
76
|
+
// Determine media type
|
|
77
|
+
const mediaType = params.mediaType || detectMediaType(params.filePath);
|
|
78
|
+
// Create data URL
|
|
79
|
+
const dataUrl = `data:${mimeType};base64,${base64}`;
|
|
80
|
+
const msg = {
|
|
81
|
+
channel: ctx.channel,
|
|
82
|
+
chat_id: ctx.chatId,
|
|
83
|
+
content: params.caption || '',
|
|
84
|
+
mediaUrl: dataUrl,
|
|
85
|
+
mediaType,
|
|
86
|
+
};
|
|
87
|
+
await bus.publishOutbound(msg);
|
|
88
|
+
const fileName = params.filePath.split('/').pop() || params.filePath;
|
|
89
|
+
return {
|
|
90
|
+
content: [{ type: 'text', text: `✅ Media sent: ${fileName} (${mediaType})` }],
|
|
91
|
+
details: { filePath: params.filePath, mediaType },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: 'text', text: `Error sending media: ${errorMessage}` }],
|
|
98
|
+
details: { error: errorMessage },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=send-media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-media.js","sourceRoot":"","sources":["../../../src/agent/tools/send-media.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACjE,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,UAAU;KACrB,EAAE,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,uBAAuB,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,QAAQ,WAAW,MAAM,EAAE,CAAC;gBAEpD,MAAM,GAAG,GAAoB;oBAC3B,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,OAAO,EAAE,GAAG,CAAC,MAAM;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;oBAC7B,QAAQ,EAAE,OAAO;oBACjB,SAAS;iBACV,CAAC;gBAEF,MAAM,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;gBAE/B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC;gBACrE,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,QAAQ,KAAK,SAAS,GAAG,EAAE,CAAC;oBAC7E,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE;iBAClD,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5E,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,wBAAwB,YAAY,EAAE,EAAE,CAAC;oBACzE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE;iBACjC,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
declare const ShellSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
3
|
+
command: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
4
|
+
}>;
|
|
5
|
+
export interface ShellDetails {
|
|
6
|
+
exitCode: number | null;
|
|
7
|
+
timedOut: boolean;
|
|
8
|
+
truncated: boolean;
|
|
9
|
+
truncatedBy?: 'lines' | 'bytes';
|
|
10
|
+
outputBytes?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function createShellTool(cwd: string): AgentTool<typeof ShellSchema, ShellDetails>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Shell tool - executes commands with output truncation
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { checkShellSafety } from '../prompt/safety.js';
|
|
5
|
+
const MAX_SHELL_TIMEOUT = 300;
|
|
6
|
+
const DEFAULT_MAX_BYTES = 50 * 1024;
|
|
7
|
+
const DEFAULT_MAX_LINES = 2000;
|
|
8
|
+
const ShellSchema = Type.Object({
|
|
9
|
+
command: Type.String({ description: 'Shell command to execute' }),
|
|
10
|
+
});
|
|
11
|
+
function formatSize(bytes) {
|
|
12
|
+
if (bytes < 1024)
|
|
13
|
+
return `${bytes}B`;
|
|
14
|
+
if (bytes < 1024 * 1024)
|
|
15
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
16
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
17
|
+
}
|
|
18
|
+
function truncateTail(content, maxLines = DEFAULT_MAX_LINES, maxBytes = DEFAULT_MAX_BYTES) {
|
|
19
|
+
const totalBytes = Buffer.byteLength(content, 'utf-8');
|
|
20
|
+
const lines = content.split('\n');
|
|
21
|
+
const totalLines = lines.length;
|
|
22
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
23
|
+
return { content, truncated: false, truncatedBy: null, totalLines, totalBytes, outputLines: totalLines, outputBytes: totalBytes };
|
|
24
|
+
}
|
|
25
|
+
const outputLinesArr = [];
|
|
26
|
+
let outputBytesCount = 0;
|
|
27
|
+
let truncatedBy = 'lines';
|
|
28
|
+
for (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {
|
|
29
|
+
const line = lines[i];
|
|
30
|
+
const lineBytes = Buffer.byteLength(line, 'utf-8') + (outputLinesArr.length > 0 ? 1 : 0);
|
|
31
|
+
if (outputBytesCount + lineBytes > maxBytes) {
|
|
32
|
+
truncatedBy = 'bytes';
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
outputLinesArr.unshift(line);
|
|
36
|
+
outputBytesCount += lineBytes;
|
|
37
|
+
}
|
|
38
|
+
return { content: outputLinesArr.join('\n'), truncated: true, truncatedBy, totalLines, totalBytes, outputLines: outputLinesArr.length, outputBytes: outputBytesCount };
|
|
39
|
+
}
|
|
40
|
+
export function createShellTool(cwd) {
|
|
41
|
+
return {
|
|
42
|
+
name: 'shell',
|
|
43
|
+
description: 'Execute shell command.',
|
|
44
|
+
parameters: ShellSchema,
|
|
45
|
+
label: '💻 Shell',
|
|
46
|
+
async execute(toolCallId, params, _signal) {
|
|
47
|
+
const safety = checkShellSafety(params.command);
|
|
48
|
+
if (!safety.allowed) {
|
|
49
|
+
return {
|
|
50
|
+
content: [{ type: 'text', text: `🚫 ${safety.message}` }],
|
|
51
|
+
details: { exitCode: null, timedOut: false, truncated: false },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const _startTime = Date.now();
|
|
56
|
+
let output = '';
|
|
57
|
+
let errorOutput = '';
|
|
58
|
+
let timedOut = false;
|
|
59
|
+
let _tempFile = null;
|
|
60
|
+
let tempStream = null;
|
|
61
|
+
const useTempFile = false; // Disabled - stream directly
|
|
62
|
+
const timeout = setTimeout(() => {
|
|
63
|
+
timedOut = true;
|
|
64
|
+
proc.kill('SIGKILL');
|
|
65
|
+
}, MAX_SHELL_TIMEOUT * 1000);
|
|
66
|
+
const proc = spawn(params.command, [], {
|
|
67
|
+
shell: true,
|
|
68
|
+
cwd,
|
|
69
|
+
env: { ...process.env, COLUMNS: '200' },
|
|
70
|
+
});
|
|
71
|
+
proc.stdout?.on('data', (data) => {
|
|
72
|
+
const text = data.toString();
|
|
73
|
+
if (!useTempFile)
|
|
74
|
+
output += text;
|
|
75
|
+
});
|
|
76
|
+
proc.stderr?.on('data', (data) => {
|
|
77
|
+
const text = data.toString();
|
|
78
|
+
errorOutput += text;
|
|
79
|
+
});
|
|
80
|
+
proc.on('close', (code) => {
|
|
81
|
+
clearTimeout(timeout);
|
|
82
|
+
tempStream?.end();
|
|
83
|
+
const fullOutput = errorOutput + output;
|
|
84
|
+
const truncation = truncateTail(fullOutput);
|
|
85
|
+
let resultText = truncation.content;
|
|
86
|
+
if (timedOut) {
|
|
87
|
+
resultText = `⏱️ Command timed out after ${MAX_SHELL_TIMEOUT}s\n` + resultText;
|
|
88
|
+
}
|
|
89
|
+
if (truncation.truncated) {
|
|
90
|
+
resultText += `\n\n[Output truncated: ${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}]`;
|
|
91
|
+
}
|
|
92
|
+
resolve({
|
|
93
|
+
content: [{ type: 'text', text: resultText }],
|
|
94
|
+
details: {
|
|
95
|
+
exitCode: code,
|
|
96
|
+
timedOut,
|
|
97
|
+
truncated: truncation.truncated,
|
|
98
|
+
truncatedBy: truncation.truncatedBy,
|
|
99
|
+
outputBytes: truncation.outputBytes,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
proc.on('error', (err) => {
|
|
104
|
+
clearTimeout(timeout);
|
|
105
|
+
resolve({
|
|
106
|
+
content: [{ type: 'text', text: `Error: ${err.message}` }],
|
|
107
|
+
details: { exitCode: null, timedOut: false, truncated: false },
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../src/agent/tools/shell.ts"],"names":[],"m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AE;oBACvB,YAAY,CAAC,OAAO,CAAC,CAAC;oBACtB,OAAO,CAAC;wBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;wBAC1D,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;qBAC/D,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_LINES = 2000;
|
|
2
|
+
export declare const DEFAULT_MAX_BYTES: number;
|
|
3
|
+
export declare const GREP_MAX_LINE_LENGTH = 500;
|
|
4
|
+
export interface TruncationResult {
|
|
5
|
+
content: string;
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
truncatedBy: "lines" | "bytes" | null;
|
|
8
|
+
totalLines: number;
|
|
9
|
+
totalBytes: number;
|
|
10
|
+
outputLines: number;
|
|
11
|
+
outputBytes: number;
|
|
12
|
+
lastLinePartial: boolean;
|
|
13
|
+
firstLineExceedsLimit: boolean;
|
|
14
|
+
maxLines: number;
|
|
15
|
+
maxBytes: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TruncationOptions {
|
|
18
|
+
maxLines?: number;
|
|
19
|
+
maxBytes?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function formatSize(bytes: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Truncate from head - keep beginning of content
|
|
24
|
+
*/
|
|
25
|
+
export declare function truncateHead(content: string, options?: TruncationOptions): TruncationResult;
|
|
26
|
+
/**
|
|
27
|
+
* Truncate from tail - keep end of content (like tail command)
|
|
28
|
+
*/
|
|
29
|
+
export declare function truncateTail(content: string, options?: TruncationOptions): TruncationResult;
|
|
30
|
+
/**
|
|
31
|
+
* Truncate long lines to max length
|
|
32
|
+
*/
|
|
33
|
+
export declare function truncateLine(content: string, maxLen?: number): {
|
|
34
|
+
text: string;
|
|
35
|
+
wasTruncated: boolean;
|
|
36
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Truncation utilities - limits output to max lines/bytes
|
|
2
|
+
export const DEFAULT_MAX_LINES = 2000;
|
|
3
|
+
export const DEFAULT_MAX_BYTES = 50 * 1024;
|
|
4
|
+
export const GREP_MAX_LINE_LENGTH = 500;
|
|
5
|
+
export function formatSize(bytes) {
|
|
6
|
+
if (bytes < 1024)
|
|
7
|
+
return `${bytes}B`;
|
|
8
|
+
if (bytes < 1024 * 1024)
|
|
9
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
10
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Truncate from head - keep beginning of content
|
|
14
|
+
*/
|
|
15
|
+
export function truncateHead(content, options = {}) {
|
|
16
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
17
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
18
|
+
const totalBytes = Buffer.byteLength(content, 'utf-8');
|
|
19
|
+
const lines = content.split('\n');
|
|
20
|
+
const totalLines = lines.length;
|
|
21
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
22
|
+
return result(content, false, null, totalLines, totalBytes);
|
|
23
|
+
}
|
|
24
|
+
// Check first line
|
|
25
|
+
if (Buffer.byteLength(lines[0], 'utf-8') > maxBytes) {
|
|
26
|
+
return result('', true, 'bytes', totalLines, totalBytes, 0, 0, false, true);
|
|
27
|
+
}
|
|
28
|
+
// Collect lines within limits
|
|
29
|
+
const output = [];
|
|
30
|
+
let bytes = 0;
|
|
31
|
+
let truncatedBy = 'lines';
|
|
32
|
+
for (let i = 0; i < lines.length && i < maxLines; i++) {
|
|
33
|
+
const lineLen = Buffer.byteLength(lines[i], 'utf-8') + (i > 0 ? 1 : 0);
|
|
34
|
+
if (bytes + lineLen > maxBytes) {
|
|
35
|
+
truncatedBy = 'bytes';
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
output.push(lines[i]);
|
|
39
|
+
bytes += lineLen;
|
|
40
|
+
}
|
|
41
|
+
return result(output.join('\n'), true, truncatedBy, totalLines, totalBytes, output.length, bytes);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Truncate from tail - keep end of content (like tail command)
|
|
45
|
+
*/
|
|
46
|
+
export function truncateTail(content, options = {}) {
|
|
47
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
48
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
49
|
+
const totalBytes = Buffer.byteLength(content, 'utf-8');
|
|
50
|
+
const lines = content.split('\n');
|
|
51
|
+
const totalLines = lines.length;
|
|
52
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
53
|
+
return result(content, false, null, totalLines, totalBytes);
|
|
54
|
+
}
|
|
55
|
+
// Start from end
|
|
56
|
+
const output = [];
|
|
57
|
+
let bytes = 0;
|
|
58
|
+
let lastLinePartial = false;
|
|
59
|
+
for (let i = Math.max(0, totalLines - maxLines); i < totalLines; i++) {
|
|
60
|
+
const line = lines[i];
|
|
61
|
+
const lineLen = Buffer.byteLength(line, 'utf-8') + (output.length > 0 ? 1 : 0);
|
|
62
|
+
if (bytes + lineLen > maxBytes) {
|
|
63
|
+
if (output.length === 0 && lineLen > maxBytes) {
|
|
64
|
+
// First line itself exceeds limit - truncate it
|
|
65
|
+
const truncated = line.slice(0, Math.floor(maxBytes * 0.9));
|
|
66
|
+
output.push(truncated);
|
|
67
|
+
lastLinePartial = true;
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
output.push(line);
|
|
72
|
+
bytes += lineLen;
|
|
73
|
+
}
|
|
74
|
+
return result(output.join('\n'), true, 'lines', totalLines, totalBytes, output.length, bytes, lastLinePartial);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Truncate long lines to max length
|
|
78
|
+
*/
|
|
79
|
+
export function truncateLine(content, maxLen = GREP_MAX_LINE_LENGTH) {
|
|
80
|
+
const truncated = content.length > maxLen ? content.slice(0, maxLen) + '...' : content;
|
|
81
|
+
return { text: truncated, wasTruncated: content.length > maxLen };
|
|
82
|
+
}
|
|
83
|
+
function result(content, truncated, truncatedBy, totalLines, totalBytes, outputLines = totalLines, outputBytes = totalBytes, lastLinePartial = false, firstLineExceedsLimit = false) {
|
|
84
|
+
return {
|
|
85
|
+
content,
|
|
86
|
+
truncated,
|
|
87
|
+
truncatedBy,
|
|
88
|
+
totalLines,
|
|
89
|
+
totalBytes,
|
|
90
|
+
outputLines,
|
|
91
|
+
outputBytes,
|
|
92
|
+
maxLines: DEFAULT_MAX_LINES,
|
|
93
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
94
|
+
lastLinePartial,
|
|
95
|
+
firstLineExceedsLimit,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=truncate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../src/agent/tools/truncate.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAqBxC,MAAM,UAAU,UAAU,CAAC,KAAa;IACvC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,GAAG,CAAC;IACrC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;I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AAK,CAAC,CAAC,CAAC,OAAO,CAAC;IACvF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;AACnE,CAAC;AAED,SAAS,MAAM,CACd,OAAe,EACf,SAAkB,EAClB,WAAqC,EACrC,UAAkB,EAClB,UAAkB,EAClB,WAAW,GAAG,UAAU,EACxB,WAAW,GAAG,UAAU,EACxB,eAAe,GAAG,KAAK,EACvB,qBAAqB,GAAG,KAAK;IAE7B,OAAO;QACN,OAAO;QACP,SAAS;QACT,WAAW;QACX,UAAU;QACV,UAAU;QACV,WAAW;QACX,WAAW;QACX,QAAQ,EAAE,iBAAiB;QAC3B,QAAQ,EAAE,iBAAiB;QAC3B,eAAe;QACf,qBAAqB;KACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
declare const WebSearchSchema: import("@sinclair/typebox/build/cjs").TObject<{
|
|
3
|
+
query: import("@sinclair/typebox/build/cjs").TString;
|
|
4
|
+
count: import("@sinclair/typebox/build/cjs").TOptional<import("@sinclair/typebox/build/cjs").TNumber>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function createWebSearchTool(apiKey?: string): AgentTool<typeof WebSearchSchema, {
|
|
7
|
+
results: any[];
|
|
8
|
+
}>;
|
|
9
|
+
declare const WebFetchSchema: import("@sinclair/typebox/build/cjs").TObject<{
|
|
10
|
+
url: import("@sinclair/typebox/build/cjs").TString;
|
|
11
|
+
maxChars: import("@sinclair/typebox/build/cjs").TOptional<import("@sinclair/typebox/build/cjs").TNumber>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const webFetchTool: AgentTool<typeof WebFetchSchema, {}>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Web search and fetch tools
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Web Search Tool
|
|
5
|
+
// =============================================================================
|
|
6
|
+
const WebSearchSchema = Type.Object({
|
|
7
|
+
query: Type.String({ description: 'The search query' }),
|
|
8
|
+
count: Type.Optional(Type.Number({ description: 'Number of results (default: 5)' })),
|
|
9
|
+
});
|
|
10
|
+
export function createWebSearchTool(apiKey) {
|
|
11
|
+
return {
|
|
12
|
+
name: 'web_search',
|
|
13
|
+
description: 'Search the web using Brave Search API.',
|
|
14
|
+
parameters: WebSearchSchema,
|
|
15
|
+
label: '🔍 Web Search',
|
|
16
|
+
async execute(toolCallId, params, signal) {
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
return {
|
|
19
|
+
content: [{ type: 'text', text: 'Error: Brave Search API key not configured' }],
|
|
20
|
+
details: { results: [] },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const count = params.count || 5;
|
|
25
|
+
const url = `https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(params.query)}&count=${count}`;
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
headers: {
|
|
28
|
+
'X-Subscription-Token': apiKey,
|
|
29
|
+
'Accept': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
signal,
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
|
35
|
+
}
|
|
36
|
+
const data = (await response.json());
|
|
37
|
+
const results = data.web?.results || [];
|
|
38
|
+
const formatted = results
|
|
39
|
+
.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}\n ${r.description?.substring(0, 200)}...`)
|
|
40
|
+
.join('\n\n');
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: 'text', text: formatted || 'No results found' }],
|
|
43
|
+
details: { results },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
text: `Search error: ${error instanceof Error ? error.message : String(error)}`,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
details: { results: [] },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// =============================================================================
|
|
61
|
+
// Web Fetch Tool
|
|
62
|
+
// =============================================================================
|
|
63
|
+
const WebFetchSchema = Type.Object({
|
|
64
|
+
url: Type.String({ description: 'The URL to fetch' }),
|
|
65
|
+
maxChars: Type.Optional(Type.Number({ description: 'Maximum characters to return (default: 10000)' })),
|
|
66
|
+
});
|
|
67
|
+
export const webFetchTool = {
|
|
68
|
+
name: 'web_fetch',
|
|
69
|
+
description: 'Fetch and extract readable content from a URL.',
|
|
70
|
+
parameters: WebFetchSchema,
|
|
71
|
+
label: '🌐 Web Fetch',
|
|
72
|
+
async execute(toolCallId, params, signal) {
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(params.url, { signal });
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`HTTP ${response.status}`);
|
|
77
|
+
}
|
|
78
|
+
const html = await response.text();
|
|
79
|
+
const maxChars = params.maxChars || 10000;
|
|
80
|
+
// Simple HTML to text conversion
|
|
81
|
+
let text = html
|
|
82
|
+
.replace(/<script[^\u003e]*\u003e[\s\S]*?\u003c\/script\u003e/gi, '')
|
|
83
|
+
.replace(/<style[^\u003e]*\u003e[\s\S]*?\u003c\/style\u003e/gi, '')
|
|
84
|
+
.replace(/\u003c[^\u003e]+\u003e/g, ' ')
|
|
85
|
+
.replace(/\n\s*\n+/g, '\n')
|
|
86
|
+
.replace(/\s+/g, ' ')
|
|
87
|
+
.trim();
|
|
88
|
+
if (text.length > maxChars) {
|
|
89
|
+
text = text.substring(0, maxChars) + '\n\n[truncated...]';
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
content: [{ type: 'text', text }],
|
|
93
|
+
details: {},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
content: [
|
|
99
|
+
{
|
|
100
|
+
type: 'text',
|
|
101
|
+
text: `Fetch error: ${error instanceof Error ? error.message : String(error)}`,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
details: {},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../../src/agent/tools/web.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAGtD,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAChF,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IACvD,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC,CAAC;CACrF,CAAC,CAAC;AAEH,MAAM,UAAU,mBAAmB,CAAC,MAAe;IACjD,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,wCAAwC;QACrD,UAAU,EAAE,eAAe;QAC3B,KAAK,EAAE,eAAe;QAEtB,KAAK,CAAC,OAAO,CACX,UAAkB,EAClB,MAAsC,EACtC,MAAoB;YAEpB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,4CAA4C,EAAE,CAAC;oBAC/E,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;iBACzB,CAAC;YACJ,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,MAAM,CA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E,GAAG,CAAC;iBACvC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;iBAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;iBACpB,IAAI,EAAE,CAAC;YAEV,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;gBAC3B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,oBAAoB,CAAC;YAC5D,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBACjC,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,gBAAgB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;qBAC/E;iBACF;gBACD,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentTool } from '@mariozechner/pi-agent-core';
|
|
2
|
+
declare const WriteFileSchema: import("@sinclair/typebox/build/cjs/index.js").TObject<{
|
|
3
|
+
path: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
4
|
+
content: import("@sinclair/typebox/build/cjs/index.js").TString;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const writeFileTool: AgentTool<typeof WriteFileSchema, {}>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Write file tool
|
|
2
|
+
import { Type } from '@sinclair/typebox';
|
|
3
|
+
import { writeFile, mkdir } from 'fs/promises';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import { checkFileSafety } from '../prompt/safety.js';
|
|
6
|
+
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
7
|
+
const WriteFileSchema = Type.Object({
|
|
8
|
+
path: Type.String({ description: 'File path to write' }),
|
|
9
|
+
content: Type.String({ description: 'Content to write' }),
|
|
10
|
+
});
|
|
11
|
+
export const writeFileTool = {
|
|
12
|
+
name: 'write_file',
|
|
13
|
+
description: 'Create or overwrite a file.',
|
|
14
|
+
parameters: WriteFileSchema,
|
|
15
|
+
label: '📝 Write',
|
|
16
|
+
async execute(toolCallId, params, _signal) {
|
|
17
|
+
try {
|
|
18
|
+
const safety = checkFileSafety('write', params.path);
|
|
19
|
+
if (!safety.allowed) {
|
|
20
|
+
return { content: [{ type: 'text', text: `🚫 ${safety.message}` }], details: {} };
|
|
21
|
+
}
|
|
22
|
+
const contentBytes = Buffer.byteLength(params.content, 'utf-8');
|
|
23
|
+
if (contentBytes > MAX_FILE_SIZE) {
|
|
24
|
+
return { content: [{ type: 'text', text: `🚫 File too large: ${contentBytes} bytes` }], details: {} };
|
|
25
|
+
}
|
|
26
|
+
await mkdir(dirname(params.path), { recursive: true });
|
|
27
|
+
await writeFile(params.path, params.content, 'utf-8');
|
|
28
|
+
return { content: [{ type: 'text', text: `File written: ${params.path}` }], details: { size: contentBytes } };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` }], details: {} };
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/agent/tools/write.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/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I,EAAE,CAAC,CAAC;YACvD,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC;QAChH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAChI,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentMessage as BaseAgentMessage } from '@mariozechner/pi-agent-core';
|
|
2
|
+
export type { BaseAgentMessage };
|
|
3
|
+
export interface AgentConfig {
|
|
4
|
+
workspace: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
systemPrompt?: string;
|
|
7
|
+
}
|
|
8
|
+
export type { AgentMessage } from '@mariozechner/pi-agent-core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":""}
|