@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,668 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { cors } from 'hono/cors';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { logger } from './middleware/logger.js';
|
|
7
|
+
import { auth } from './middleware/auth.js';
|
|
8
|
+
import { createAgentSSEHandler, createSendHandler, createEventsSSEHandler } from './sse.js';
|
|
9
|
+
import { createLogger } from '../../utils/logger.js';
|
|
10
|
+
import { queryLogs, getLogFiles, getLogLevels, getLogStats, getLogModules, LOG_DIR } from '../../utils/log-store.js';
|
|
11
|
+
import { getLocalModelsDevModels } from '../../providers/models-dev.js';
|
|
12
|
+
import { isProviderConfigured } from '../../agent/fallback/index.js';
|
|
13
|
+
const log = createLogger('HonoApp');
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const UI_STATIC_ROOT = join(__dirname, '../../gateway/static/root');
|
|
17
|
+
// MIME type mapping for static assets
|
|
18
|
+
const MIME_TYPES = {
|
|
19
|
+
js: 'application/javascript',
|
|
20
|
+
css: 'text/css',
|
|
21
|
+
json: 'application/json',
|
|
22
|
+
html: 'text/html',
|
|
23
|
+
svg: 'image/svg+xml',
|
|
24
|
+
png: 'image/png',
|
|
25
|
+
jpg: 'image/jpeg',
|
|
26
|
+
ico: 'image/x-icon',
|
|
27
|
+
};
|
|
28
|
+
// Serve a static file from UI static root
|
|
29
|
+
function serveStaticFile(relativePath) {
|
|
30
|
+
const filePath = `${UI_STATIC_ROOT}/${relativePath}`;
|
|
31
|
+
try {
|
|
32
|
+
const content = readFileSync(filePath);
|
|
33
|
+
const ext = relativePath.split('.').pop() || '';
|
|
34
|
+
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
|
35
|
+
return new Response(content, {
|
|
36
|
+
headers: { 'Content-Type': contentType },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function createHonoApp(config) {
|
|
44
|
+
const { service, token } = config;
|
|
45
|
+
const app = new Hono();
|
|
46
|
+
// CORS configuration
|
|
47
|
+
// Development: allow all origins by default
|
|
48
|
+
// Production: use config, default to denying all if not configured
|
|
49
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
50
|
+
const configuredOrigins = service.currentConfig.gateway.corsOrigins;
|
|
51
|
+
let corsOrigin;
|
|
52
|
+
if (isProduction) {
|
|
53
|
+
// Production: use configured origins, or '*' if explicitly allowed
|
|
54
|
+
corsOrigin = configuredOrigins && configuredOrigins.length > 0 ? configuredOrigins : '*';
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Development: allow all origins by default
|
|
58
|
+
corsOrigin = '*';
|
|
59
|
+
}
|
|
60
|
+
const CORS_OPTIONS = {
|
|
61
|
+
origin: corsOrigin,
|
|
62
|
+
allowMethods: ['GET', 'POST', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
63
|
+
allowHeaders: ['Content-Type', 'Authorization', 'Accept', 'X-Session-Id', 'Last-Event-ID'],
|
|
64
|
+
credentials: true,
|
|
65
|
+
maxAge: 86400,
|
|
66
|
+
};
|
|
67
|
+
// Global middleware
|
|
68
|
+
app.use(logger());
|
|
69
|
+
app.use(cors(CORS_OPTIONS));
|
|
70
|
+
// Health endpoint (no auth required)
|
|
71
|
+
app.get('/health', (c) => {
|
|
72
|
+
return c.json(service.getHealth());
|
|
73
|
+
});
|
|
74
|
+
// Root path - serve UI
|
|
75
|
+
app.get('/', (c) => {
|
|
76
|
+
const response = serveStaticFile('index.html');
|
|
77
|
+
if (response)
|
|
78
|
+
return response;
|
|
79
|
+
return c.text('UI not found', 404);
|
|
80
|
+
});
|
|
81
|
+
// API info (no auth required for basic info)
|
|
82
|
+
app.get('/api', (c) => {
|
|
83
|
+
return c.json({
|
|
84
|
+
service: 'xopcbot-gateway',
|
|
85
|
+
version: '0.1.0',
|
|
86
|
+
transport: 'streamable-http',
|
|
87
|
+
endpoints: [
|
|
88
|
+
'GET /health',
|
|
89
|
+
'GET /status',
|
|
90
|
+
'POST /api/agent (SSE stream / JSON)',
|
|
91
|
+
'POST /api/send',
|
|
92
|
+
'GET /api/events (SSE stream)',
|
|
93
|
+
'GET /api/channels/status',
|
|
94
|
+
'GET /api/config',
|
|
95
|
+
'PATCH /api/config',
|
|
96
|
+
'POST /api/config/reload',
|
|
97
|
+
'... /api/cron/*',
|
|
98
|
+
'... /api/sessions/*',
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
// Authenticated routes
|
|
103
|
+
const authenticated = new Hono();
|
|
104
|
+
authenticated.use(auth({ token }));
|
|
105
|
+
// Protected status endpoint
|
|
106
|
+
authenticated.get('/status', (c) => {
|
|
107
|
+
const health = service.getHealth();
|
|
108
|
+
return c.json({
|
|
109
|
+
status: health.status,
|
|
110
|
+
version: health.version,
|
|
111
|
+
channels: health.channels,
|
|
112
|
+
uptime: health.uptime,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
// ========== Core SSE API ==========
|
|
116
|
+
const sseConfig = {
|
|
117
|
+
service,
|
|
118
|
+
maxSseConnections: service.currentConfig.gateway.maxSseConnections,
|
|
119
|
+
};
|
|
120
|
+
// POST /api/agent — Agent message (SSE stream or JSON fallback)
|
|
121
|
+
authenticated.post('/api/agent', createAgentSSEHandler(sseConfig));
|
|
122
|
+
// POST /api/send — Send a message through a channel
|
|
123
|
+
authenticated.post('/api/send', createSendHandler(sseConfig));
|
|
124
|
+
// GET /api/events — Server-pushed event stream
|
|
125
|
+
authenticated.get('/api/events', createEventsSSEHandler(sseConfig));
|
|
126
|
+
// GET /api/channels/status
|
|
127
|
+
authenticated.get('/api/channels/status', (c) => {
|
|
128
|
+
const channels = service.getChannelsStatus();
|
|
129
|
+
return c.json({ ok: true, payload: { channels } });
|
|
130
|
+
});
|
|
131
|
+
// POST /api/config/reload
|
|
132
|
+
authenticated.post('/api/config/reload', async (c) => {
|
|
133
|
+
const result = await service.reloadConfig();
|
|
134
|
+
return c.json({ ok: true, payload: result });
|
|
135
|
+
});
|
|
136
|
+
// GET /api/config
|
|
137
|
+
authenticated.get('/api/config', (c) => {
|
|
138
|
+
const config = service.currentConfig;
|
|
139
|
+
const safeConfig = {
|
|
140
|
+
agents: {
|
|
141
|
+
defaults: {
|
|
142
|
+
model: config.agents?.defaults?.model,
|
|
143
|
+
maxTokens: config.agents?.defaults?.maxTokens,
|
|
144
|
+
temperature: config.agents?.defaults?.temperature,
|
|
145
|
+
maxToolIterations: config.agents?.defaults?.maxToolIterations,
|
|
146
|
+
workspace: config.agents?.defaults?.workspace,
|
|
147
|
+
compaction: config.agents?.defaults?.compaction,
|
|
148
|
+
pruning: config.agents?.defaults?.pruning,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
channels: {
|
|
152
|
+
telegram: {
|
|
153
|
+
enabled: config.channels?.telegram?.enabled,
|
|
154
|
+
token: config.channels?.telegram?.token || '',
|
|
155
|
+
allowFrom: config.channels?.telegram?.allowFrom || [],
|
|
156
|
+
apiRoot: config.channels?.telegram?.apiRoot || '',
|
|
157
|
+
debug: config.channels?.telegram?.debug || false,
|
|
158
|
+
},
|
|
159
|
+
whatsapp: {
|
|
160
|
+
enabled: config.channels?.whatsapp?.enabled,
|
|
161
|
+
bridgeUrl: config.channels?.whatsapp?.bridgeUrl || 'ws://localhost:3001',
|
|
162
|
+
allowFrom: config.channels?.whatsapp?.allowFrom || [],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
providers: {
|
|
166
|
+
openai: { apiKey: config.providers?.openai?.apiKey || '', baseUrl: config.providers?.openai?.baseUrl || '' },
|
|
167
|
+
anthropic: { apiKey: config.providers?.anthropic?.apiKey || '' },
|
|
168
|
+
google: { apiKey: config.providers?.google?.apiKey || '' },
|
|
169
|
+
qwen: { apiKey: config.providers?.qwen?.apiKey || '', baseUrl: config.providers?.qwen?.baseUrl || '' },
|
|
170
|
+
kimi: { apiKey: config.providers?.kimi?.apiKey || '', baseUrl: config.providers?.kimi?.baseUrl || '' },
|
|
171
|
+
minimax: { apiKey: config.providers?.minimax?.apiKey || '', baseUrl: config.providers?.minimax?.baseUrl || '' },
|
|
172
|
+
deepseek: { apiKey: config.providers?.deepseek?.apiKey || '', baseUrl: config.providers?.deepseek?.baseUrl || '' },
|
|
173
|
+
groq: { apiKey: config.providers?.groq?.apiKey || '', baseUrl: config.providers?.groq?.baseUrl || '' },
|
|
174
|
+
openrouter: { apiKey: config.providers?.openrouter?.apiKey || '', baseUrl: config.providers?.openrouter?.baseUrl || '' },
|
|
175
|
+
ollama: {
|
|
176
|
+
enabled: config.providers?.ollama?.enabled ?? true,
|
|
177
|
+
baseUrl: config.providers?.ollama?.baseUrl || 'http://127.0.0.1:11434/v1',
|
|
178
|
+
autoDiscovery: config.providers?.ollama?.autoDiscovery ?? true,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
gateway: {
|
|
182
|
+
host: config.gateway?.host,
|
|
183
|
+
port: config.gateway?.port,
|
|
184
|
+
heartbeat: {
|
|
185
|
+
enabled: config.gateway?.heartbeat?.enabled,
|
|
186
|
+
intervalMs: config.gateway?.heartbeat?.intervalMs,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
cron: { enabled: config.cron?.enabled },
|
|
190
|
+
};
|
|
191
|
+
return c.json({ ok: true, payload: { config: safeConfig } });
|
|
192
|
+
});
|
|
193
|
+
// PATCH /api/config - Update partial config
|
|
194
|
+
authenticated.patch('/api/config', async (c) => {
|
|
195
|
+
const body = await c.req.json();
|
|
196
|
+
// Merge updates into current config
|
|
197
|
+
const config = service.currentConfig;
|
|
198
|
+
// Update agent defaults
|
|
199
|
+
if (body.agents?.defaults) {
|
|
200
|
+
if (!config.agents)
|
|
201
|
+
config.agents = { defaults: { workspace: '~/.xopcbot/workspace', model: 'anthropic/claude-sonnet-4-5', maxTokens: 8192, temperature: 0.7, maxToolIterations: 20 } };
|
|
202
|
+
if (!config.agents.defaults)
|
|
203
|
+
config.agents.defaults = {};
|
|
204
|
+
if (body.agents.defaults.model !== undefined) {
|
|
205
|
+
config.agents.defaults.model = body.agents.defaults.model;
|
|
206
|
+
}
|
|
207
|
+
if (body.agents.defaults.maxTokens !== undefined) {
|
|
208
|
+
config.agents.defaults.maxTokens = body.agents.defaults.maxTokens;
|
|
209
|
+
}
|
|
210
|
+
if (body.agents.defaults.temperature !== undefined) {
|
|
211
|
+
config.agents.defaults.temperature = body.agents.defaults.temperature;
|
|
212
|
+
}
|
|
213
|
+
if (body.agents.defaults.maxToolIterations !== undefined) {
|
|
214
|
+
config.agents.defaults.maxToolIterations = body.agents.defaults.maxToolIterations;
|
|
215
|
+
}
|
|
216
|
+
if (body.agents.defaults.workspace !== undefined) {
|
|
217
|
+
config.agents.defaults.workspace = body.agents.defaults.workspace;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Update channels
|
|
221
|
+
if (body.channels?.telegram) {
|
|
222
|
+
if (!config.channels)
|
|
223
|
+
config.channels = { telegram: { enabled: false, token: '', allowFrom: [], debug: false, dmPolicy: 'pairing', groupPolicy: 'open' }, whatsapp: { enabled: false, bridgeUrl: 'ws://localhost:3001', allowFrom: [] } };
|
|
224
|
+
if (!config.channels.telegram)
|
|
225
|
+
config.channels.telegram = {};
|
|
226
|
+
if (body.channels.telegram.enabled !== undefined) {
|
|
227
|
+
config.channels.telegram.enabled = body.channels.telegram.enabled;
|
|
228
|
+
}
|
|
229
|
+
if (body.channels.telegram.token !== undefined) {
|
|
230
|
+
config.channels.telegram.token = body.channels.telegram.token;
|
|
231
|
+
}
|
|
232
|
+
if (body.channels.telegram.allowFrom !== undefined) {
|
|
233
|
+
config.channels.telegram.allowFrom = body.channels.telegram.allowFrom;
|
|
234
|
+
}
|
|
235
|
+
if (body.channels.telegram.apiRoot !== undefined) {
|
|
236
|
+
config.channels.telegram.apiRoot = body.channels.telegram.apiRoot;
|
|
237
|
+
}
|
|
238
|
+
if (body.channels.telegram.debug !== undefined) {
|
|
239
|
+
config.channels.telegram.debug = body.channels.telegram.debug;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (body.channels?.whatsapp) {
|
|
243
|
+
if (!config.channels)
|
|
244
|
+
config.channels = { telegram: { enabled: false, token: '', allowFrom: [], debug: false, dmPolicy: 'pairing', groupPolicy: 'open' }, whatsapp: { enabled: false, bridgeUrl: 'ws://localhost:3001', allowFrom: [] } };
|
|
245
|
+
if (!config.channels.whatsapp)
|
|
246
|
+
config.channels.whatsapp = {};
|
|
247
|
+
if (body.channels.whatsapp.enabled !== undefined) {
|
|
248
|
+
config.channels.whatsapp.enabled = body.channels.whatsapp.enabled;
|
|
249
|
+
}
|
|
250
|
+
if (body.channels.whatsapp.bridgeUrl !== undefined) {
|
|
251
|
+
config.channels.whatsapp.bridgeUrl = body.channels.whatsapp.bridgeUrl;
|
|
252
|
+
}
|
|
253
|
+
if (body.channels.whatsapp.allowFrom !== undefined) {
|
|
254
|
+
config.channels.whatsapp.allowFrom = body.channels.whatsapp.allowFrom;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Update gateway
|
|
258
|
+
if (body.gateway?.heartbeat?.enabled !== undefined) {
|
|
259
|
+
if (!config.gateway)
|
|
260
|
+
config.gateway = { host: '0.0.0.0', port: 18790, heartbeat: { enabled: true, intervalMs: 60000 }, maxSseConnections: 100, corsOrigins: ['*'] };
|
|
261
|
+
if (!config.gateway.heartbeat)
|
|
262
|
+
config.gateway.heartbeat = { enabled: true, intervalMs: 60000 };
|
|
263
|
+
config.gateway.heartbeat.enabled = body.gateway.heartbeat.enabled;
|
|
264
|
+
}
|
|
265
|
+
if (body.gateway?.heartbeat?.intervalMs !== undefined) {
|
|
266
|
+
if (!config.gateway)
|
|
267
|
+
config.gateway = { host: '0.0.0.0', port: 18790, heartbeat: { enabled: true, intervalMs: 60000 }, maxSseConnections: 100, corsOrigins: ['*'] };
|
|
268
|
+
if (!config.gateway.heartbeat)
|
|
269
|
+
config.gateway.heartbeat = { enabled: true, intervalMs: 60000 };
|
|
270
|
+
config.gateway.heartbeat.intervalMs = body.gateway.heartbeat.intervalMs;
|
|
271
|
+
}
|
|
272
|
+
// Update providers
|
|
273
|
+
if (body.providers) {
|
|
274
|
+
if (!config.providers)
|
|
275
|
+
config.providers = {};
|
|
276
|
+
const providerKeys = ['openai', 'anthropic', 'google', 'qwen', 'kimi', 'minimax', 'deepseek', 'groq', 'openrouter', 'ollama', 'moonshot', 'xai', 'bedrock'];
|
|
277
|
+
for (const key of providerKeys) {
|
|
278
|
+
if (body.providers[key]) {
|
|
279
|
+
if (!config.providers[key])
|
|
280
|
+
config.providers[key] = {};
|
|
281
|
+
if (body.providers[key].apiKey !== undefined) {
|
|
282
|
+
config.providers[key].apiKey = body.providers[key].apiKey;
|
|
283
|
+
}
|
|
284
|
+
if (body.providers[key].baseUrl !== undefined) {
|
|
285
|
+
config.providers[key].baseUrl = body.providers[key].baseUrl || undefined;
|
|
286
|
+
}
|
|
287
|
+
if (body.providers[key].enabled !== undefined) {
|
|
288
|
+
config.providers[key].enabled = body.providers[key].enabled;
|
|
289
|
+
}
|
|
290
|
+
if (body.providers[key].autoDiscovery !== undefined) {
|
|
291
|
+
config.providers[key].autoDiscovery = body.providers[key].autoDiscovery;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Save config
|
|
297
|
+
const result = await service.saveConfig(config);
|
|
298
|
+
if (!result.saved) {
|
|
299
|
+
return c.json({ ok: false, error: result.error }, 500);
|
|
300
|
+
}
|
|
301
|
+
return c.json({ ok: true, payload: { config } });
|
|
302
|
+
});
|
|
303
|
+
// GET /api/models - Get available models (only configured providers)
|
|
304
|
+
authenticated.get('/api/models', (c) => {
|
|
305
|
+
const config = service.currentConfig;
|
|
306
|
+
const localModels = getLocalModelsDevModels();
|
|
307
|
+
const models = [];
|
|
308
|
+
// Add models from configured providers
|
|
309
|
+
for (const [provider, providerModels] of localModels) {
|
|
310
|
+
// Only include models from configured providers (have API key or enabled)
|
|
311
|
+
if (!isProviderConfigured(config, provider))
|
|
312
|
+
continue;
|
|
313
|
+
for (const model of providerModels) {
|
|
314
|
+
models.push({
|
|
315
|
+
id: `${provider}/${model.id}`,
|
|
316
|
+
name: model.name || model.id,
|
|
317
|
+
provider: provider,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Add custom models from config.json provider overrides
|
|
322
|
+
const providers = config.providers;
|
|
323
|
+
if (providers) {
|
|
324
|
+
for (const [providerName, providerConfig] of Object.entries(providers)) {
|
|
325
|
+
// Skip if already added from localModels
|
|
326
|
+
if (localModels.has(providerName))
|
|
327
|
+
continue;
|
|
328
|
+
// Only include configured providers (have API key)
|
|
329
|
+
if (!isProviderConfigured(config, providerName))
|
|
330
|
+
continue;
|
|
331
|
+
// Add custom models defined in provider config
|
|
332
|
+
if (providerConfig?.models && Array.isArray(providerConfig.models)) {
|
|
333
|
+
for (const modelConfig of providerConfig.models) {
|
|
334
|
+
const modelId = typeof modelConfig === 'string' ? modelConfig : modelConfig.id;
|
|
335
|
+
const modelName = typeof modelConfig === 'string' ? modelConfig : modelConfig.name || modelConfig;
|
|
336
|
+
models.push({
|
|
337
|
+
id: `${providerName}/${modelId}`,
|
|
338
|
+
name: modelName,
|
|
339
|
+
provider: providerName,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Sort by provider then name
|
|
346
|
+
models.sort((a, b) => {
|
|
347
|
+
if (a.provider !== b.provider)
|
|
348
|
+
return a.provider.localeCompare(b.provider);
|
|
349
|
+
return a.name.localeCompare(b.name);
|
|
350
|
+
});
|
|
351
|
+
return c.json({ ok: true, payload: { models } });
|
|
352
|
+
});
|
|
353
|
+
// ========== Cron REST API (/api/cron) ==========
|
|
354
|
+
// GET /api/cron - List all jobs
|
|
355
|
+
authenticated.get('/api/cron', async (c) => {
|
|
356
|
+
const jobs = await service.cronServiceInstance.listJobs();
|
|
357
|
+
return c.json({ jobs });
|
|
358
|
+
});
|
|
359
|
+
// POST /api/cron - Add new job
|
|
360
|
+
authenticated.post('/api/cron', async (c) => {
|
|
361
|
+
const body = await c.req.json();
|
|
362
|
+
const { schedule, message, name, timezone, sessionTarget, model, delivery } = body;
|
|
363
|
+
if (!schedule || !message) {
|
|
364
|
+
return c.json({ error: 'Missing required fields: schedule, message' }, 400);
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
const result = await service.cronServiceInstance.addJob(schedule, message, {
|
|
368
|
+
name,
|
|
369
|
+
timezone,
|
|
370
|
+
sessionTarget,
|
|
371
|
+
model,
|
|
372
|
+
delivery,
|
|
373
|
+
});
|
|
374
|
+
return c.json(result, 201);
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
return c.json({ error: err instanceof Error ? err.message : 'Failed to add job' }, 400);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
// GET /api/cron/metrics - Get cron metrics (must be before /:id)
|
|
381
|
+
authenticated.get('/api/cron/metrics', async (c) => {
|
|
382
|
+
const metrics = await service.cronServiceInstance.getMetrics();
|
|
383
|
+
return c.json(metrics);
|
|
384
|
+
});
|
|
385
|
+
// GET /api/cron/:id - Get single job (must be after /metrics)
|
|
386
|
+
authenticated.get('/api/cron/:id', async (c) => {
|
|
387
|
+
const id = c.req.param('id');
|
|
388
|
+
const job = await service.cronServiceInstance.getJob(id);
|
|
389
|
+
if (!job) {
|
|
390
|
+
return c.json({ error: 'Job not found' }, 404);
|
|
391
|
+
}
|
|
392
|
+
return c.json({ job });
|
|
393
|
+
});
|
|
394
|
+
// POST /api/cron/:id/toggle - Toggle job enabled
|
|
395
|
+
authenticated.post('/api/cron/:id/toggle', async (c) => {
|
|
396
|
+
const id = c.req.param('id');
|
|
397
|
+
const body = await c.req.json();
|
|
398
|
+
const { enabled } = body;
|
|
399
|
+
if (typeof enabled !== 'boolean') {
|
|
400
|
+
return c.json({ error: 'Missing required field: enabled' }, 400);
|
|
401
|
+
}
|
|
402
|
+
const result = await service.cronServiceInstance.toggleJob(id, enabled);
|
|
403
|
+
return c.json({ toggled: result });
|
|
404
|
+
});
|
|
405
|
+
// POST /api/cron/:id/run - Trigger job manually
|
|
406
|
+
authenticated.post('/api/cron/:id/run', async (c) => {
|
|
407
|
+
const id = c.req.param('id');
|
|
408
|
+
try {
|
|
409
|
+
await service.cronServiceInstance.runJobNow(id);
|
|
410
|
+
return c.json({ triggered: true });
|
|
411
|
+
}
|
|
412
|
+
catch (err) {
|
|
413
|
+
return c.json({ error: err instanceof Error ? err.message : 'Failed to run job' }, 400);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
// GET /api/cron/:id/history - Get job execution history
|
|
417
|
+
authenticated.get('/api/cron/:id/history', async (c) => {
|
|
418
|
+
const id = c.req.param('id');
|
|
419
|
+
const limit = c.req.query('limit') ? parseInt(c.req.query('limit')) : 10;
|
|
420
|
+
const history = service.cronServiceInstance.getJobHistory(id, limit);
|
|
421
|
+
return c.json({ history });
|
|
422
|
+
});
|
|
423
|
+
// PATCH /api/cron/:id - Update job
|
|
424
|
+
authenticated.patch('/api/cron/:id', async (c) => {
|
|
425
|
+
const id = c.req.param('id');
|
|
426
|
+
const body = await c.req.json();
|
|
427
|
+
try {
|
|
428
|
+
const result = await service.cronServiceInstance.updateJob(id, body);
|
|
429
|
+
return c.json({ updated: result });
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
return c.json({ error: err instanceof Error ? err.message : 'Failed to update job' }, 400);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
// DELETE /api/cron/:id - Remove job
|
|
436
|
+
authenticated.delete('/api/cron/:id', async (c) => {
|
|
437
|
+
const id = c.req.param('id');
|
|
438
|
+
const result = await service.cronServiceInstance.removeJob(id);
|
|
439
|
+
return c.json({ removed: result });
|
|
440
|
+
});
|
|
441
|
+
// ========== Session REST API (/api/sessions) ==========
|
|
442
|
+
// POST /api/sessions - Create new session
|
|
443
|
+
authenticated.post('/api/sessions', async (c) => {
|
|
444
|
+
const body = await c.req.json().catch(() => ({}));
|
|
445
|
+
const channel = body.channel || 'gateway';
|
|
446
|
+
const chatId = body.chat_id || `chat_${Date.now()}`;
|
|
447
|
+
const sessionKey = `${channel}:${chatId}`;
|
|
448
|
+
await service.sessionManagerInstance.saveMessages(sessionKey, []);
|
|
449
|
+
const session = await service.getSession(sessionKey);
|
|
450
|
+
return c.json({ session }, 201);
|
|
451
|
+
});
|
|
452
|
+
// GET /api/sessions - List sessions
|
|
453
|
+
authenticated.get('/api/sessions', async (c) => {
|
|
454
|
+
const query = c.req.query();
|
|
455
|
+
const result = await service.listSessions({
|
|
456
|
+
status: query.status,
|
|
457
|
+
search: query.search,
|
|
458
|
+
limit: query.limit ? parseInt(query.limit) : undefined,
|
|
459
|
+
offset: query.offset ? parseInt(query.offset) : undefined,
|
|
460
|
+
});
|
|
461
|
+
return c.json(result);
|
|
462
|
+
});
|
|
463
|
+
// GET /api/sessions/stats - Get session stats (must be before /:key)
|
|
464
|
+
authenticated.get('/api/sessions/stats', async (c) => {
|
|
465
|
+
const result = await service.getSessionStats();
|
|
466
|
+
return c.json(result);
|
|
467
|
+
});
|
|
468
|
+
// GET /api/sessions/chat-ids - Get unique chat IDs from sessions (must be before /:key)
|
|
469
|
+
authenticated.get('/api/sessions/chat-ids', async (c) => {
|
|
470
|
+
const channel = c.req.query('channel');
|
|
471
|
+
const chatIds = await service.getSessionChatIds(channel || undefined);
|
|
472
|
+
return c.json({ ok: true, payload: { chatIds } });
|
|
473
|
+
});
|
|
474
|
+
// GET /api/sessions/:key - Get single session (must be after /stats and /chat-ids)
|
|
475
|
+
authenticated.get('/api/sessions/:key', async (c) => {
|
|
476
|
+
const key = c.req.param('key');
|
|
477
|
+
const session = await service.getSession(key);
|
|
478
|
+
if (!session) {
|
|
479
|
+
return c.json({ error: 'Session not found' }, 404);
|
|
480
|
+
}
|
|
481
|
+
return c.json({ session });
|
|
482
|
+
});
|
|
483
|
+
// GET /api/sessions/:key/export - Export session (must be before /:key)
|
|
484
|
+
authenticated.get('/api/sessions/:key/export', async (c) => {
|
|
485
|
+
const key = c.req.param('key');
|
|
486
|
+
const format = c.req.query('format') || 'json';
|
|
487
|
+
const result = await service.exportSession(key, format);
|
|
488
|
+
return c.json(result);
|
|
489
|
+
});
|
|
490
|
+
// DELETE /api/sessions/:key - Delete session
|
|
491
|
+
authenticated.delete('/api/sessions/:key', async (c) => {
|
|
492
|
+
const key = c.req.param('key');
|
|
493
|
+
const result = await service.deleteSession(key);
|
|
494
|
+
return c.json(result);
|
|
495
|
+
});
|
|
496
|
+
// POST /api/sessions/:key/archive - Archive session
|
|
497
|
+
authenticated.post('/api/sessions/:key/archive', async (c) => {
|
|
498
|
+
const key = c.req.param('key');
|
|
499
|
+
const result = await service.archiveSession(key);
|
|
500
|
+
return c.json(result);
|
|
501
|
+
});
|
|
502
|
+
// POST /api/sessions/:key/unarchive - Unarchive session
|
|
503
|
+
authenticated.post('/api/sessions/:key/unarchive', async (c) => {
|
|
504
|
+
const key = c.req.param('key');
|
|
505
|
+
const result = await service.unarchiveSession(key);
|
|
506
|
+
return c.json(result);
|
|
507
|
+
});
|
|
508
|
+
// POST /api/sessions/:key/pin - Pin session
|
|
509
|
+
authenticated.post('/api/sessions/:key/pin', async (c) => {
|
|
510
|
+
const key = c.req.param('key');
|
|
511
|
+
const result = await service.pinSession(key);
|
|
512
|
+
return c.json(result);
|
|
513
|
+
});
|
|
514
|
+
// POST /api/sessions/:key/unpin - Unpin session
|
|
515
|
+
authenticated.post('/api/sessions/:key/unpin', async (c) => {
|
|
516
|
+
const key = c.req.param('key');
|
|
517
|
+
const result = await service.unpinSession(key);
|
|
518
|
+
return c.json(result);
|
|
519
|
+
});
|
|
520
|
+
// POST /api/sessions/:key/rename - Rename session
|
|
521
|
+
authenticated.post('/api/sessions/:key/rename', async (c) => {
|
|
522
|
+
const key = c.req.param('key');
|
|
523
|
+
const body = await c.req.json();
|
|
524
|
+
const { name } = body;
|
|
525
|
+
const result = await service.renameSession(key, name);
|
|
526
|
+
return c.json(result);
|
|
527
|
+
});
|
|
528
|
+
// ========== Subagent REST API (/api/subagents) ==========
|
|
529
|
+
// GET /api/subagents - List subagent sessions
|
|
530
|
+
authenticated.get('/api/subagents', async (c) => {
|
|
531
|
+
const query = c.req.query();
|
|
532
|
+
const result = await service.listSubagents({
|
|
533
|
+
limit: query.limit ? parseInt(query.limit) : undefined,
|
|
534
|
+
offset: query.offset ? parseInt(query.offset) : undefined,
|
|
535
|
+
});
|
|
536
|
+
return c.json(result);
|
|
537
|
+
});
|
|
538
|
+
// GET /api/subagents/:key - Get subagent session detail
|
|
539
|
+
authenticated.get('/api/subagents/:key', async (c) => {
|
|
540
|
+
const key = c.req.param('key');
|
|
541
|
+
// Verify it's a subagent session
|
|
542
|
+
if (!key.startsWith('subagent:')) {
|
|
543
|
+
return c.json({ error: 'Not a subagent session' }, 400);
|
|
544
|
+
}
|
|
545
|
+
const session = await service.getSession(key);
|
|
546
|
+
if (!session) {
|
|
547
|
+
return c.json({ error: 'Subagent session not found' }, 404);
|
|
548
|
+
}
|
|
549
|
+
return c.json({ session });
|
|
550
|
+
});
|
|
551
|
+
// ========== Logs REST API (/api/logs) ==========
|
|
552
|
+
// GET /api/logs - Query logs with filters
|
|
553
|
+
authenticated.get('/api/logs', async (c) => {
|
|
554
|
+
const query = c.req.query();
|
|
555
|
+
const logs = await queryLogs({
|
|
556
|
+
levels: query.level ? query.level.split(',') : undefined,
|
|
557
|
+
from: query.from,
|
|
558
|
+
to: query.to,
|
|
559
|
+
q: query.q,
|
|
560
|
+
module: query.module,
|
|
561
|
+
limit: query.limit ? parseInt(query.limit) : 100,
|
|
562
|
+
offset: query.offset ? parseInt(query.offset) : 0,
|
|
563
|
+
});
|
|
564
|
+
return c.json({ logs, count: logs.length });
|
|
565
|
+
});
|
|
566
|
+
// GET /api/logs/files - List log files
|
|
567
|
+
authenticated.get('/api/logs/files', async (c) => {
|
|
568
|
+
const files = getLogFiles();
|
|
569
|
+
return c.json({ files });
|
|
570
|
+
});
|
|
571
|
+
// GET /api/logs/stats - Get log statistics
|
|
572
|
+
authenticated.get('/api/logs/stats', async (c) => {
|
|
573
|
+
const stats = getLogStats();
|
|
574
|
+
return c.json(stats);
|
|
575
|
+
});
|
|
576
|
+
// GET /api/logs/levels - Get available log levels
|
|
577
|
+
authenticated.get('/api/logs/levels', async (c) => {
|
|
578
|
+
return c.json({ levels: getLogLevels() });
|
|
579
|
+
});
|
|
580
|
+
// GET /api/logs/modules - Get available modules
|
|
581
|
+
authenticated.get('/api/logs/modules', async (c) => {
|
|
582
|
+
const modules = await getLogModules();
|
|
583
|
+
return c.json({ modules });
|
|
584
|
+
});
|
|
585
|
+
// GET /api/logs/dir - Get log directory path
|
|
586
|
+
authenticated.get('/api/logs/dir', async (c) => {
|
|
587
|
+
return c.json({ dir: LOG_DIR });
|
|
588
|
+
});
|
|
589
|
+
// ========== Plugin HTTP Routes ==========
|
|
590
|
+
const pluginRegistry = service.getPluginRegistry?.();
|
|
591
|
+
if (pluginRegistry) {
|
|
592
|
+
// Register plugin HTTP routes
|
|
593
|
+
const httpRoutes = pluginRegistry.httpRoutes;
|
|
594
|
+
for (const [path, handler] of httpRoutes) {
|
|
595
|
+
// POST handler
|
|
596
|
+
authenticated.post(path, async (c) => {
|
|
597
|
+
const req = {
|
|
598
|
+
method: c.req.method,
|
|
599
|
+
url: c.req.url,
|
|
600
|
+
headers: c.req.header(),
|
|
601
|
+
body: await c.req.json().catch(() => ({})),
|
|
602
|
+
};
|
|
603
|
+
const res = {
|
|
604
|
+
status: (code) => {
|
|
605
|
+
c.status(code);
|
|
606
|
+
return res;
|
|
607
|
+
},
|
|
608
|
+
json: (data) => c.json(data),
|
|
609
|
+
send: (data) => c.text(data),
|
|
610
|
+
};
|
|
611
|
+
await handler(req, res);
|
|
612
|
+
return c.text('');
|
|
613
|
+
});
|
|
614
|
+
// GET handler
|
|
615
|
+
authenticated.get(path, async (c) => {
|
|
616
|
+
const req = {
|
|
617
|
+
method: c.req.method,
|
|
618
|
+
url: c.req.url,
|
|
619
|
+
headers: c.req.header(),
|
|
620
|
+
};
|
|
621
|
+
const res = {
|
|
622
|
+
status: (code) => {
|
|
623
|
+
c.status(code);
|
|
624
|
+
return res;
|
|
625
|
+
},
|
|
626
|
+
json: (data) => c.json(data),
|
|
627
|
+
send: (data) => c.text(data),
|
|
628
|
+
};
|
|
629
|
+
await handler(req, res);
|
|
630
|
+
return c.text('');
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
// ========== Plugin Gateway Methods ==========
|
|
635
|
+
// POST /api/gateway/:method - Invoke a gateway method
|
|
636
|
+
authenticated.post('/api/gateway/:method', async (c) => {
|
|
637
|
+
const method = c.req.param('method');
|
|
638
|
+
const params = await c.req.json().catch(() => ({}));
|
|
639
|
+
try {
|
|
640
|
+
const result = await service.invokeGatewayMethod(method, params);
|
|
641
|
+
return c.json({ ok: true, result });
|
|
642
|
+
}
|
|
643
|
+
catch (err) {
|
|
644
|
+
return c.json({ ok: false, error: err instanceof Error ? err.message : 'Unknown error' }, 400);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
// Mount authenticated routes
|
|
648
|
+
app.route('/', authenticated);
|
|
649
|
+
// UI static files (served at root)
|
|
650
|
+
app.get('/assets/*', (c) => {
|
|
651
|
+
const path = c.req.path.replace('/assets/', '');
|
|
652
|
+
const response = serveStaticFile(`assets/${path}`);
|
|
653
|
+
if (response)
|
|
654
|
+
return response;
|
|
655
|
+
return c.text('Not found', 404);
|
|
656
|
+
});
|
|
657
|
+
// 404 handler
|
|
658
|
+
app.notFound((c) => {
|
|
659
|
+
return c.json({ error: 'Not found' }, 404);
|
|
660
|
+
});
|
|
661
|
+
// Error handler
|
|
662
|
+
app.onError((err, c) => {
|
|
663
|
+
log.error({ err }, 'Hono error');
|
|
664
|
+
return c.json({ error: 'Internal server error' }, 500);
|
|
665
|
+
});
|
|
666
|
+
return app;
|
|
667
|
+
}
|
|
668
|
+
//# sourceMappingURL=app.js.map
|