@elizaos/agent 0.25.8 → 2.0.0-alpha.83
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/LICENSE +1 -1
- package/package.json +994 -34
- package/packages/agent/src/actions/emote.d.ts +14 -0
- package/packages/agent/src/actions/emote.d.ts.map +1 -0
- package/packages/agent/src/actions/emote.js +91 -0
- package/packages/agent/src/actions/restart.d.ts +19 -0
- package/packages/agent/src/actions/restart.d.ts.map +1 -0
- package/packages/agent/src/actions/restart.js +86 -0
- package/packages/agent/src/actions/send-message.d.ts +3 -0
- package/packages/agent/src/actions/send-message.d.ts.map +1 -0
- package/packages/agent/src/actions/send-message.js +144 -0
- package/packages/agent/src/actions/stream-control.d.ts +15 -0
- package/packages/agent/src/actions/stream-control.d.ts.map +1 -0
- package/packages/agent/src/actions/stream-control.js +357 -0
- package/packages/agent/src/actions/switch-stream-source.d.ts +16 -0
- package/packages/agent/src/actions/switch-stream-source.d.ts.map +1 -0
- package/packages/agent/src/actions/switch-stream-source.js +94 -0
- package/packages/agent/src/actions/terminal.d.ts +14 -0
- package/packages/agent/src/actions/terminal.d.ts.map +1 -0
- package/packages/agent/src/actions/terminal.js +154 -0
- package/packages/agent/src/api/agent-admin-routes.d.ts +38 -0
- package/packages/agent/src/api/agent-admin-routes.d.ts.map +1 -0
- package/packages/agent/src/api/agent-admin-routes.js +93 -0
- package/packages/agent/src/api/agent-lifecycle-routes.d.ts +16 -0
- package/packages/agent/src/api/agent-lifecycle-routes.d.ts.map +1 -0
- package/packages/agent/src/api/agent-lifecycle-routes.js +80 -0
- package/packages/agent/src/api/agent-model.d.ts +12 -0
- package/packages/agent/src/api/agent-model.d.ts.map +1 -0
- package/packages/agent/src/api/agent-model.js +123 -0
- package/packages/agent/src/api/agent-transfer-routes.d.ts +16 -0
- package/packages/agent/src/api/agent-transfer-routes.d.ts.map +1 -0
- package/packages/agent/src/api/agent-transfer-routes.js +124 -0
- package/packages/agent/src/api/apps-routes.d.ts +19 -0
- package/packages/agent/src/api/apps-routes.d.ts.map +1 -0
- package/packages/agent/src/api/apps-routes.js +128 -0
- package/packages/agent/src/api/auth-routes.d.ts +11 -0
- package/packages/agent/src/api/auth-routes.d.ts.map +1 -0
- package/packages/agent/src/api/auth-routes.js +54 -0
- package/packages/agent/src/api/bsc-trade.d.ts +34 -0
- package/packages/agent/src/api/bsc-trade.d.ts.map +1 -0
- package/packages/agent/src/api/bsc-trade.js +567 -0
- package/packages/agent/src/api/bug-report-routes.d.ts +7 -0
- package/packages/agent/src/api/bug-report-routes.d.ts.map +1 -0
- package/packages/agent/src/api/bug-report-routes.js +124 -0
- package/packages/agent/src/api/character-routes.d.ts +50 -0
- package/packages/agent/src/api/character-routes.d.ts.map +1 -0
- package/packages/agent/src/api/character-routes.js +302 -0
- package/packages/agent/src/api/cloud-billing-routes.d.ts +14 -0
- package/packages/agent/src/api/cloud-billing-routes.d.ts.map +1 -0
- package/packages/agent/src/api/cloud-billing-routes.js +400 -0
- package/packages/agent/src/api/cloud-compat-routes.d.ts +15 -0
- package/packages/agent/src/api/cloud-compat-routes.d.ts.map +1 -0
- package/packages/agent/src/api/cloud-compat-routes.js +131 -0
- package/packages/agent/src/api/cloud-routes.d.ts +62 -0
- package/packages/agent/src/api/cloud-routes.d.ts.map +1 -0
- package/packages/agent/src/api/cloud-routes.js +339 -0
- package/packages/agent/src/api/cloud-status-routes.d.ts +15 -0
- package/packages/agent/src/api/cloud-status-routes.d.ts.map +1 -0
- package/packages/agent/src/api/cloud-status-routes.js +165 -0
- package/packages/agent/src/api/compat-utils.d.ts +49 -0
- package/packages/agent/src/api/compat-utils.d.ts.map +1 -0
- package/packages/agent/src/api/compat-utils.js +126 -0
- package/packages/agent/src/api/connector-health.d.ts +34 -0
- package/packages/agent/src/api/connector-health.d.ts.map +1 -0
- package/packages/agent/src/api/connector-health.js +109 -0
- package/packages/agent/src/api/coordinator-wiring.d.ts +46 -0
- package/packages/agent/src/api/coordinator-wiring.d.ts.map +1 -0
- package/packages/agent/src/api/coordinator-wiring.js +101 -0
- package/packages/agent/src/api/credit-detection.d.ts +9 -0
- package/packages/agent/src/api/credit-detection.d.ts.map +1 -0
- package/packages/agent/src/api/credit-detection.js +41 -0
- package/packages/agent/src/api/database.d.ts +33 -0
- package/packages/agent/src/api/database.d.ts.map +1 -0
- package/packages/agent/src/api/database.js +1019 -0
- package/packages/agent/src/api/diagnostics-routes.d.ts +46 -0
- package/packages/agent/src/api/diagnostics-routes.d.ts.map +1 -0
- package/packages/agent/src/api/diagnostics-routes.js +241 -0
- package/packages/agent/src/api/drop-service.d.ts +26 -0
- package/packages/agent/src/api/drop-service.d.ts.map +1 -0
- package/packages/agent/src/api/drop-service.js +134 -0
- package/packages/agent/src/api/early-logs.d.ts +29 -0
- package/packages/agent/src/api/early-logs.d.ts.map +1 -0
- package/packages/agent/src/api/early-logs.js +96 -0
- package/packages/agent/src/api/http-helpers.d.ts +50 -0
- package/packages/agent/src/api/http-helpers.d.ts.map +1 -0
- package/packages/agent/src/api/http-helpers.js +145 -0
- package/packages/agent/src/api/index.d.ts +61 -0
- package/packages/agent/src/api/index.d.ts.map +1 -0
- package/packages/agent/src/api/index.js +59 -0
- package/packages/agent/src/api/knowledge-routes.d.ts +23 -0
- package/packages/agent/src/api/knowledge-routes.d.ts.map +1 -0
- package/packages/agent/src/api/knowledge-routes.js +931 -0
- package/packages/agent/src/api/knowledge-service-loader.d.ts +51 -0
- package/packages/agent/src/api/knowledge-service-loader.d.ts.map +1 -0
- package/packages/agent/src/api/knowledge-service-loader.js +34 -0
- package/packages/agent/src/api/memory-bounds.d.ts +51 -0
- package/packages/agent/src/api/memory-bounds.d.ts.map +1 -0
- package/packages/agent/src/api/memory-bounds.js +81 -0
- package/packages/agent/src/api/memory-routes.d.ts +9 -0
- package/packages/agent/src/api/memory-routes.d.ts.map +1 -0
- package/packages/agent/src/api/memory-routes.js +241 -0
- package/packages/agent/src/api/merkle-tree.d.ts +90 -0
- package/packages/agent/src/api/merkle-tree.d.ts.map +1 -0
- package/packages/agent/src/api/merkle-tree.js +174 -0
- package/packages/agent/src/api/models-routes.d.ts +14 -0
- package/packages/agent/src/api/models-routes.d.ts.map +1 -0
- package/packages/agent/src/api/models-routes.js +37 -0
- package/packages/agent/src/api/nfa-routes.d.ts +5 -0
- package/packages/agent/src/api/nfa-routes.d.ts.map +1 -0
- package/packages/agent/src/api/nfa-routes.js +125 -0
- package/packages/agent/src/api/og-tracker.d.ts +28 -0
- package/packages/agent/src/api/og-tracker.d.ts.map +1 -0
- package/packages/agent/src/api/og-tracker.js +60 -0
- package/packages/agent/src/api/parse-action-block.d.ts +36 -0
- package/packages/agent/src/api/parse-action-block.d.ts.map +1 -0
- package/packages/agent/src/api/parse-action-block.js +110 -0
- package/packages/agent/src/api/permissions-routes.d.ts +32 -0
- package/packages/agent/src/api/permissions-routes.d.ts.map +1 -0
- package/packages/agent/src/api/permissions-routes.js +149 -0
- package/packages/agent/src/api/plugin-validation.d.ts +86 -0
- package/packages/agent/src/api/plugin-validation.d.ts.map +1 -0
- package/packages/agent/src/api/plugin-validation.js +259 -0
- package/packages/agent/src/api/provider-switch-config.d.ts +37 -0
- package/packages/agent/src/api/provider-switch-config.d.ts.map +1 -0
- package/packages/agent/src/api/provider-switch-config.js +317 -0
- package/packages/agent/src/api/registry-routes.d.ts +26 -0
- package/packages/agent/src/api/registry-routes.d.ts.map +1 -0
- package/packages/agent/src/api/registry-routes.js +90 -0
- package/packages/agent/src/api/registry-service.d.ts +77 -0
- package/packages/agent/src/api/registry-service.d.ts.map +1 -0
- package/packages/agent/src/api/registry-service.js +190 -0
- package/packages/agent/src/api/route-helpers.d.ts +16 -0
- package/packages/agent/src/api/route-helpers.d.ts.map +1 -0
- package/packages/agent/src/api/route-helpers.js +1 -0
- package/packages/agent/src/api/sandbox-routes.d.ts +12 -0
- package/packages/agent/src/api/sandbox-routes.d.ts.map +1 -0
- package/packages/agent/src/api/sandbox-routes.js +1334 -0
- package/packages/agent/src/api/server.d.ts +418 -0
- package/packages/agent/src/api/server.d.ts.map +1 -0
- package/packages/agent/src/api/server.js +13614 -0
- package/packages/agent/src/api/signal-routes.d.ts +39 -0
- package/packages/agent/src/api/signal-routes.d.ts.map +1 -0
- package/packages/agent/src/api/signal-routes.js +168 -0
- package/packages/agent/src/api/stream-persistence.d.ts +64 -0
- package/packages/agent/src/api/stream-persistence.d.ts.map +1 -0
- package/packages/agent/src/api/stream-persistence.js +231 -0
- package/packages/agent/src/api/stream-route-state.d.ts +50 -0
- package/packages/agent/src/api/stream-route-state.d.ts.map +1 -0
- package/packages/agent/src/api/stream-route-state.js +1 -0
- package/packages/agent/src/api/stream-routes.d.ts +45 -0
- package/packages/agent/src/api/stream-routes.d.ts.map +1 -0
- package/packages/agent/src/api/stream-routes.js +809 -0
- package/packages/agent/src/api/stream-voice-routes.d.ts +36 -0
- package/packages/agent/src/api/stream-voice-routes.d.ts.map +1 -0
- package/packages/agent/src/api/stream-voice-routes.js +133 -0
- package/packages/agent/src/api/streaming-text.d.ts +9 -0
- package/packages/agent/src/api/streaming-text.d.ts.map +1 -0
- package/packages/agent/src/api/streaming-text.js +85 -0
- package/packages/agent/src/api/streaming-types.d.ts +30 -0
- package/packages/agent/src/api/streaming-types.d.ts.map +1 -0
- package/packages/agent/src/api/streaming-types.js +1 -0
- package/packages/agent/src/api/subscription-routes.d.ts +20 -0
- package/packages/agent/src/api/subscription-routes.d.ts.map +1 -0
- package/packages/agent/src/api/subscription-routes.js +191 -0
- package/packages/agent/src/api/terminal-run-limits.d.ts +5 -0
- package/packages/agent/src/api/terminal-run-limits.d.ts.map +1 -0
- package/packages/agent/src/api/terminal-run-limits.js +22 -0
- package/packages/agent/src/api/training-backend-check.d.ts +8 -0
- package/packages/agent/src/api/training-backend-check.d.ts.map +1 -0
- package/packages/agent/src/api/training-backend-check.js +28 -0
- package/packages/agent/src/api/training-routes.d.ts +44 -0
- package/packages/agent/src/api/training-routes.d.ts.map +1 -0
- package/packages/agent/src/api/training-routes.js +195 -0
- package/packages/agent/src/api/training-service-like.d.ts +38 -0
- package/packages/agent/src/api/training-service-like.d.ts.map +1 -0
- package/packages/agent/src/api/training-service-like.js +1 -0
- package/packages/agent/src/api/trajectory-routes.d.ts +17 -0
- package/packages/agent/src/api/trajectory-routes.d.ts.map +1 -0
- package/packages/agent/src/api/trajectory-routes.js +405 -0
- package/packages/agent/src/api/trigger-routes.d.ts +72 -0
- package/packages/agent/src/api/trigger-routes.d.ts.map +1 -0
- package/packages/agent/src/api/trigger-routes.js +268 -0
- package/packages/agent/src/api/twitter-verify.d.ts +25 -0
- package/packages/agent/src/api/twitter-verify.d.ts.map +1 -0
- package/packages/agent/src/api/twitter-verify.js +168 -0
- package/packages/agent/src/api/tx-service.d.ts +47 -0
- package/packages/agent/src/api/tx-service.d.ts.map +1 -0
- package/packages/agent/src/api/tx-service.js +156 -0
- package/packages/agent/src/api/wallet-dex-prices.d.ts +43 -0
- package/packages/agent/src/api/wallet-dex-prices.d.ts.map +1 -0
- package/packages/agent/src/api/wallet-dex-prices.js +149 -0
- package/packages/agent/src/api/wallet-evm-balance.d.ts +65 -0
- package/packages/agent/src/api/wallet-evm-balance.d.ts.map +1 -0
- package/packages/agent/src/api/wallet-evm-balance.js +663 -0
- package/packages/agent/src/api/wallet-routes.d.ts +33 -0
- package/packages/agent/src/api/wallet-routes.d.ts.map +1 -0
- package/packages/agent/src/api/wallet-routes.js +292 -0
- package/packages/agent/src/api/wallet-rpc.d.ts +61 -0
- package/packages/agent/src/api/wallet-rpc.d.ts.map +1 -0
- package/packages/agent/src/api/wallet-rpc.js +367 -0
- package/packages/agent/src/api/wallet-trading-profile.d.ts +51 -0
- package/packages/agent/src/api/wallet-trading-profile.d.ts.map +1 -0
- package/packages/agent/src/api/wallet-trading-profile.js +547 -0
- package/packages/agent/src/api/wallet.d.ts +31 -0
- package/packages/agent/src/api/wallet.d.ts.map +1 -0
- package/packages/agent/src/api/wallet.js +513 -0
- package/packages/agent/src/api/whatsapp-routes.d.ts +39 -0
- package/packages/agent/src/api/whatsapp-routes.d.ts.map +1 -0
- package/packages/agent/src/api/whatsapp-routes.js +182 -0
- package/packages/agent/src/api/zip-utils.d.ts +8 -0
- package/packages/agent/src/api/zip-utils.d.ts.map +1 -0
- package/packages/agent/src/api/zip-utils.js +115 -0
- package/packages/agent/src/auth/anthropic.d.ts +25 -0
- package/packages/agent/src/auth/anthropic.d.ts.map +1 -0
- package/packages/agent/src/auth/anthropic.js +40 -0
- package/packages/agent/src/auth/apply-stealth.d.ts +8 -0
- package/packages/agent/src/auth/apply-stealth.d.ts.map +1 -0
- package/packages/agent/src/auth/apply-stealth.js +35 -0
- package/packages/agent/src/auth/claude-code-stealth.d.ts +2 -0
- package/packages/agent/src/auth/claude-code-stealth.d.ts.map +1 -0
- package/packages/agent/src/auth/claude-code-stealth.js +104 -0
- package/packages/agent/src/auth/credentials.d.ts +55 -0
- package/packages/agent/src/auth/credentials.d.ts.map +1 -0
- package/packages/agent/src/auth/credentials.js +182 -0
- package/packages/agent/src/auth/index.d.ts +7 -0
- package/packages/agent/src/auth/index.d.ts.map +1 -0
- package/packages/agent/src/auth/index.js +3 -0
- package/packages/agent/src/auth/openai-codex.d.ts +27 -0
- package/packages/agent/src/auth/openai-codex.d.ts.map +1 -0
- package/packages/agent/src/auth/openai-codex.js +72 -0
- package/packages/agent/src/auth/types.d.ts +18 -0
- package/packages/agent/src/auth/types.d.ts.map +1 -0
- package/packages/agent/src/auth/types.js +8 -0
- package/packages/agent/src/awareness/registry.d.ts +27 -0
- package/packages/agent/src/awareness/registry.d.ts.map +1 -0
- package/packages/agent/src/awareness/registry.js +161 -0
- package/packages/agent/src/benchmark-server.d.ts +2 -0
- package/packages/agent/src/benchmark-server.d.ts.map +1 -0
- package/packages/agent/src/benchmark-server.js +773 -0
- package/packages/agent/src/bin.d.ts +3 -0
- package/packages/agent/src/bin.d.ts.map +1 -0
- package/packages/agent/src/bin.js +6 -0
- package/packages/agent/src/cli/index.d.ts +2 -0
- package/packages/agent/src/cli/index.d.ts.map +1 -0
- package/packages/agent/src/cli/index.js +40 -0
- package/packages/agent/src/cli/parse-duration.d.ts +5 -0
- package/packages/agent/src/cli/parse-duration.d.ts.map +1 -0
- package/packages/agent/src/cli/parse-duration.js +27 -0
- package/packages/agent/src/cloud/auth.d.ts +19 -0
- package/packages/agent/src/cloud/auth.d.ts.map +1 -0
- package/packages/agent/src/cloud/auth.js +107 -0
- package/packages/agent/src/cloud/backup.d.ts +18 -0
- package/packages/agent/src/cloud/backup.d.ts.map +1 -0
- package/packages/agent/src/cloud/backup.js +42 -0
- package/packages/agent/src/cloud/base-url.d.ts +3 -0
- package/packages/agent/src/cloud/base-url.d.ts.map +1 -0
- package/packages/agent/src/cloud/base-url.js +40 -0
- package/packages/agent/src/cloud/bridge-client.d.ts +56 -0
- package/packages/agent/src/cloud/bridge-client.d.ts.map +1 -0
- package/packages/agent/src/cloud/bridge-client.js +190 -0
- package/packages/agent/src/cloud/cloud-manager.d.ts +32 -0
- package/packages/agent/src/cloud/cloud-manager.d.ts.map +1 -0
- package/packages/agent/src/cloud/cloud-manager.js +119 -0
- package/packages/agent/src/cloud/cloud-proxy.d.ts +20 -0
- package/packages/agent/src/cloud/cloud-proxy.d.ts.map +1 -0
- package/packages/agent/src/cloud/cloud-proxy.js +34 -0
- package/packages/agent/src/cloud/index.d.ts +7 -0
- package/packages/agent/src/cloud/index.d.ts.map +1 -0
- package/packages/agent/src/cloud/index.js +6 -0
- package/packages/agent/src/cloud/reconnect.d.ts +26 -0
- package/packages/agent/src/cloud/reconnect.d.ts.map +1 -0
- package/packages/agent/src/cloud/reconnect.js +86 -0
- package/packages/agent/src/cloud/validate-url.d.ts +2 -0
- package/packages/agent/src/cloud/validate-url.d.ts.map +1 -0
- package/packages/agent/src/cloud/validate-url.js +162 -0
- package/packages/agent/src/config/character-schema.d.ts +25 -0
- package/packages/agent/src/config/character-schema.d.ts.map +1 -0
- package/packages/agent/src/config/character-schema.js +39 -0
- package/packages/agent/src/config/config.d.ts +6 -0
- package/packages/agent/src/config/config.d.ts.map +1 -0
- package/packages/agent/src/config/config.js +118 -0
- package/packages/agent/src/config/env-vars.d.ts +3 -0
- package/packages/agent/src/config/env-vars.d.ts.map +1 -0
- package/packages/agent/src/config/env-vars.js +76 -0
- package/packages/agent/src/config/includes.d.ts +26 -0
- package/packages/agent/src/config/includes.d.ts.map +1 -0
- package/packages/agent/src/config/includes.js +148 -0
- package/packages/agent/src/config/index.d.ts +16 -0
- package/packages/agent/src/config/index.d.ts.map +1 -0
- package/packages/agent/src/config/index.js +15 -0
- package/packages/agent/src/config/object-utils.d.ts +2 -0
- package/packages/agent/src/config/object-utils.d.ts.map +1 -0
- package/packages/agent/src/config/object-utils.js +6 -0
- package/packages/agent/src/config/paths.d.ts +13 -0
- package/packages/agent/src/config/paths.d.ts.map +1 -0
- package/packages/agent/src/config/paths.js +67 -0
- package/packages/agent/src/config/plugin-auto-enable.d.ts +16 -0
- package/packages/agent/src/config/plugin-auto-enable.d.ts.map +1 -0
- package/packages/agent/src/config/plugin-auto-enable.js +384 -0
- package/packages/agent/src/config/schema.d.ts +87 -0
- package/packages/agent/src/config/schema.d.ts.map +1 -0
- package/packages/agent/src/config/schema.js +928 -0
- package/packages/agent/src/config/telegram-custom-commands.d.ts +25 -0
- package/packages/agent/src/config/telegram-custom-commands.d.ts.map +1 -0
- package/packages/agent/src/config/telegram-custom-commands.js +71 -0
- package/packages/agent/src/config/types.agent-defaults.d.ts +331 -0
- package/packages/agent/src/config/types.agent-defaults.d.ts.map +1 -0
- package/packages/agent/src/config/types.agent-defaults.js +1 -0
- package/packages/agent/src/config/types.agents.d.ts +110 -0
- package/packages/agent/src/config/types.agents.d.ts.map +1 -0
- package/packages/agent/src/config/types.agents.js +1 -0
- package/packages/agent/src/config/types.d.ts +8 -0
- package/packages/agent/src/config/types.d.ts.map +1 -0
- package/packages/agent/src/config/types.eliza.d.ts +636 -0
- package/packages/agent/src/config/types.eliza.d.ts.map +1 -0
- package/packages/agent/src/config/types.eliza.js +1 -0
- package/packages/agent/src/config/types.gateway.d.ts +216 -0
- package/packages/agent/src/config/types.gateway.d.ts.map +1 -0
- package/packages/agent/src/config/types.gateway.js +1 -0
- package/packages/agent/src/config/types.hooks.d.ts +107 -0
- package/packages/agent/src/config/types.hooks.d.ts.map +1 -0
- package/packages/agent/src/config/types.hooks.js +1 -0
- package/packages/agent/src/config/types.js +7 -0
- package/packages/agent/src/config/types.messages.d.ts +176 -0
- package/packages/agent/src/config/types.messages.d.ts.map +1 -0
- package/packages/agent/src/config/types.messages.js +1 -0
- package/packages/agent/src/config/types.tools.d.ts +400 -0
- package/packages/agent/src/config/types.tools.d.ts.map +1 -0
- package/packages/agent/src/config/types.tools.js +1 -0
- package/packages/agent/src/config/zod-schema.agent-runtime.d.ts +1062 -0
- package/packages/agent/src/config/zod-schema.agent-runtime.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.agent-runtime.js +721 -0
- package/packages/agent/src/config/zod-schema.core.d.ts +1021 -0
- package/packages/agent/src/config/zod-schema.core.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.core.js +694 -0
- package/packages/agent/src/config/zod-schema.d.ts +4817 -0
- package/packages/agent/src/config/zod-schema.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.hooks.d.ts +88 -0
- package/packages/agent/src/config/zod-schema.hooks.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.hooks.js +133 -0
- package/packages/agent/src/config/zod-schema.js +778 -0
- package/packages/agent/src/config/zod-schema.providers-core.d.ts +2976 -0
- package/packages/agent/src/config/zod-schema.providers-core.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.providers-core.js +1006 -0
- package/packages/agent/src/config/zod-schema.session.d.ts +183 -0
- package/packages/agent/src/config/zod-schema.session.d.ts.map +1 -0
- package/packages/agent/src/config/zod-schema.session.js +86 -0
- package/packages/agent/src/contracts/apps.d.ts +42 -0
- package/packages/agent/src/contracts/apps.d.ts.map +1 -0
- package/packages/agent/src/contracts/apps.js +4 -0
- package/packages/agent/src/contracts/awareness.d.ts +38 -0
- package/packages/agent/src/contracts/awareness.d.ts.map +1 -0
- package/packages/agent/src/contracts/awareness.js +7 -0
- package/packages/agent/src/contracts/config.d.ts +146 -0
- package/packages/agent/src/contracts/config.d.ts.map +1 -0
- package/packages/agent/src/contracts/config.js +4 -0
- package/packages/agent/src/contracts/drop.d.ts +20 -0
- package/packages/agent/src/contracts/drop.d.ts.map +1 -0
- package/packages/agent/src/contracts/drop.js +4 -0
- package/packages/agent/src/contracts/index.d.ts +9 -0
- package/packages/agent/src/contracts/index.d.ts.map +1 -0
- package/packages/agent/src/contracts/index.js +8 -0
- package/packages/agent/src/contracts/onboarding.d.ts +379 -0
- package/packages/agent/src/contracts/onboarding.d.ts.map +1 -0
- package/packages/agent/src/contracts/onboarding.js +290 -0
- package/packages/agent/src/contracts/permissions.d.ts +35 -0
- package/packages/agent/src/contracts/permissions.d.ts.map +1 -0
- package/packages/agent/src/contracts/permissions.js +4 -0
- package/packages/agent/src/contracts/verification.d.ts +9 -0
- package/packages/agent/src/contracts/verification.d.ts.map +1 -0
- package/packages/agent/src/contracts/verification.js +4 -0
- package/packages/agent/src/contracts/wallet.d.ts +409 -0
- package/packages/agent/src/contracts/wallet.d.ts.map +1 -0
- package/packages/agent/src/contracts/wallet.js +60 -0
- package/packages/agent/src/diagnostics/integration-observability.d.ts +40 -0
- package/packages/agent/src/diagnostics/integration-observability.d.ts.map +1 -0
- package/packages/agent/src/diagnostics/integration-observability.js +68 -0
- package/packages/agent/src/emotes/catalog.d.ts +31 -0
- package/packages/agent/src/emotes/catalog.d.ts.map +1 -0
- package/packages/agent/src/emotes/catalog.js +618 -0
- package/packages/agent/src/hooks/discovery.d.ts +13 -0
- package/packages/agent/src/hooks/discovery.d.ts.map +1 -0
- package/packages/agent/src/hooks/discovery.js +184 -0
- package/packages/agent/src/hooks/eligibility.d.ts +12 -0
- package/packages/agent/src/hooks/eligibility.d.ts.map +1 -0
- package/packages/agent/src/hooks/eligibility.js +100 -0
- package/packages/agent/src/hooks/index.d.ts +3 -0
- package/packages/agent/src/hooks/index.d.ts.map +1 -0
- package/packages/agent/src/hooks/index.js +2 -0
- package/packages/agent/src/hooks/loader.d.ts +34 -0
- package/packages/agent/src/hooks/loader.d.ts.map +1 -0
- package/packages/agent/src/hooks/loader.js +176 -0
- package/packages/agent/src/hooks/registry.d.ts +11 -0
- package/packages/agent/src/hooks/registry.d.ts.map +1 -0
- package/packages/agent/src/hooks/registry.js +58 -0
- package/packages/agent/src/hooks/types.d.ts +104 -0
- package/packages/agent/src/hooks/types.d.ts.map +1 -0
- package/packages/agent/src/hooks/types.js +8 -0
- package/packages/agent/src/index.d.ts +20 -0
- package/packages/agent/src/index.d.ts.map +1 -0
- package/packages/agent/src/index.js +19 -0
- package/packages/agent/src/onboarding-presets.d.ts +78 -0
- package/packages/agent/src/onboarding-presets.d.ts.map +1 -0
- package/packages/agent/src/onboarding-presets.js +1352 -0
- package/packages/agent/src/plugins/custom-rtmp/index.d.ts +12 -0
- package/packages/agent/src/plugins/custom-rtmp/index.d.ts.map +1 -0
- package/packages/agent/src/plugins/custom-rtmp/index.js +26 -0
- package/packages/agent/src/providers/admin-trust.d.ts +4 -0
- package/packages/agent/src/providers/admin-trust.d.ts.map +1 -0
- package/packages/agent/src/providers/admin-trust.js +53 -0
- package/packages/agent/src/providers/session-bridge.d.ts +24 -0
- package/packages/agent/src/providers/session-bridge.d.ts.map +1 -0
- package/packages/agent/src/providers/session-bridge.js +85 -0
- package/packages/agent/src/providers/session-utils.d.ts +20 -0
- package/packages/agent/src/providers/session-utils.d.ts.map +1 -0
- package/packages/agent/src/providers/session-utils.js +33 -0
- package/packages/agent/src/providers/simple-mode.d.ts +4 -0
- package/packages/agent/src/providers/simple-mode.d.ts.map +1 -0
- package/packages/agent/src/providers/simple-mode.js +85 -0
- package/packages/agent/src/providers/ui-catalog.d.ts +3 -0
- package/packages/agent/src/providers/ui-catalog.d.ts.map +1 -0
- package/packages/agent/src/providers/ui-catalog.js +123 -0
- package/packages/agent/src/providers/workspace-provider.d.ts +22 -0
- package/packages/agent/src/providers/workspace-provider.d.ts.map +1 -0
- package/packages/agent/src/providers/workspace-provider.js +167 -0
- package/packages/agent/src/providers/workspace.d.ts +54 -0
- package/packages/agent/src/providers/workspace.d.ts.map +1 -0
- package/packages/agent/src/providers/workspace.js +405 -0
- package/packages/agent/src/runtime/agent-event-service.d.ts +35 -0
- package/packages/agent/src/runtime/agent-event-service.d.ts.map +1 -0
- package/packages/agent/src/runtime/agent-event-service.js +16 -0
- package/packages/agent/src/runtime/cloud-onboarding.d.ts +55 -0
- package/packages/agent/src/runtime/cloud-onboarding.d.ts.map +1 -0
- package/packages/agent/src/runtime/cloud-onboarding.js +279 -0
- package/packages/agent/src/runtime/core-plugins.d.ts +14 -0
- package/packages/agent/src/runtime/core-plugins.d.ts.map +1 -0
- package/packages/agent/src/runtime/core-plugins.js +51 -0
- package/packages/agent/src/runtime/custom-actions.d.ts +40 -0
- package/packages/agent/src/runtime/custom-actions.d.ts.map +1 -0
- package/packages/agent/src/runtime/custom-actions.js +454 -0
- package/packages/agent/src/runtime/eliza-plugin.d.ts +16 -0
- package/packages/agent/src/runtime/eliza-plugin.d.ts.map +1 -0
- package/packages/agent/src/runtime/eliza-plugin.js +108 -0
- package/packages/agent/src/runtime/eliza.d.ts +205 -0
- package/packages/agent/src/runtime/eliza.d.ts.map +1 -0
- package/packages/agent/src/runtime/eliza.js +3935 -0
- package/packages/agent/src/runtime/embedding-presets.d.ts +19 -0
- package/packages/agent/src/runtime/embedding-presets.d.ts.map +1 -0
- package/packages/agent/src/runtime/embedding-presets.js +53 -0
- package/packages/agent/src/runtime/index.d.ts +9 -0
- package/packages/agent/src/runtime/index.d.ts.map +1 -0
- package/packages/agent/src/runtime/index.js +8 -0
- package/packages/agent/src/runtime/onboarding-names.d.ts +11 -0
- package/packages/agent/src/runtime/onboarding-names.d.ts.map +1 -0
- package/packages/agent/src/runtime/onboarding-names.js +74 -0
- package/packages/agent/src/runtime/release-plugin-policy.d.ts +20 -0
- package/packages/agent/src/runtime/release-plugin-policy.d.ts.map +1 -0
- package/packages/agent/src/runtime/release-plugin-policy.js +87 -0
- package/packages/agent/src/runtime/restart.d.ts +45 -0
- package/packages/agent/src/runtime/restart.d.ts.map +1 -0
- package/packages/agent/src/runtime/restart.js +45 -0
- package/packages/agent/src/runtime/trajectory-persistence.d.ts +214 -0
- package/packages/agent/src/runtime/trajectory-persistence.d.ts.map +1 -0
- package/packages/agent/src/runtime/trajectory-persistence.js +1957 -0
- package/packages/agent/src/runtime/version.d.ts +2 -0
- package/packages/agent/src/runtime/version.d.ts.map +1 -0
- package/packages/agent/src/runtime/version.js +5 -0
- package/packages/agent/src/security/audit-log.d.ts +49 -0
- package/packages/agent/src/security/audit-log.d.ts.map +1 -0
- package/packages/agent/src/security/audit-log.js +161 -0
- package/packages/agent/src/security/network-policy.d.ts +6 -0
- package/packages/agent/src/security/network-policy.d.ts.map +1 -0
- package/packages/agent/src/security/network-policy.js +85 -0
- package/packages/agent/src/server/index.d.ts +3 -0
- package/packages/agent/src/server/index.d.ts.map +1 -0
- package/packages/agent/src/server/index.js +1 -0
- package/packages/agent/src/services/agent-export.d.ts +100 -0
- package/packages/agent/src/services/agent-export.d.ts.map +1 -0
- package/packages/agent/src/services/agent-export.js +729 -0
- package/packages/agent/src/services/app-manager.d.ts +34 -0
- package/packages/agent/src/services/app-manager.d.ts.map +1 -0
- package/packages/agent/src/services/app-manager.js +425 -0
- package/packages/agent/src/services/browser-capture.d.ts +39 -0
- package/packages/agent/src/services/browser-capture.d.ts.map +1 -0
- package/packages/agent/src/services/browser-capture.js +162 -0
- package/packages/agent/src/services/coding-agent-context.d.ts +310 -0
- package/packages/agent/src/services/coding-agent-context.d.ts.map +1 -0
- package/packages/agent/src/services/coding-agent-context.js +281 -0
- package/packages/agent/src/services/fallback-training-service.d.ts +78 -0
- package/packages/agent/src/services/fallback-training-service.d.ts.map +1 -0
- package/packages/agent/src/services/fallback-training-service.js +126 -0
- package/packages/agent/src/services/index.d.ts +18 -0
- package/packages/agent/src/services/index.d.ts.map +1 -0
- package/packages/agent/src/services/index.js +17 -0
- package/packages/agent/src/services/mcp-marketplace.d.ts +89 -0
- package/packages/agent/src/services/mcp-marketplace.d.ts.map +1 -0
- package/packages/agent/src/services/mcp-marketplace.js +200 -0
- package/packages/agent/src/services/plugin-manager-types.d.ts +139 -0
- package/packages/agent/src/services/plugin-manager-types.d.ts.map +1 -0
- package/packages/agent/src/services/plugin-manager-types.js +18 -0
- package/packages/agent/src/services/privy-wallets.d.ts +18 -0
- package/packages/agent/src/services/privy-wallets.d.ts.map +1 -0
- package/packages/agent/src/services/privy-wallets.js +225 -0
- package/packages/agent/src/services/registry-client-app-meta.d.ts +6 -0
- package/packages/agent/src/services/registry-client-app-meta.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-app-meta.js +147 -0
- package/packages/agent/src/services/registry-client-endpoints.d.ts +7 -0
- package/packages/agent/src/services/registry-client-endpoints.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-endpoints.js +183 -0
- package/packages/agent/src/services/registry-client-local.d.ts +4 -0
- package/packages/agent/src/services/registry-client-local.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-local.js +377 -0
- package/packages/agent/src/services/registry-client-network.d.ts +9 -0
- package/packages/agent/src/services/registry-client-network.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-network.js +109 -0
- package/packages/agent/src/services/registry-client-queries.d.ts +15 -0
- package/packages/agent/src/services/registry-client-queries.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-queries.js +150 -0
- package/packages/agent/src/services/registry-client-types.d.ts +115 -0
- package/packages/agent/src/services/registry-client-types.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client-types.js +1 -0
- package/packages/agent/src/services/registry-client.d.ts +39 -0
- package/packages/agent/src/services/registry-client.d.ts.map +1 -0
- package/packages/agent/src/services/registry-client.js +249 -0
- package/packages/agent/src/services/remote-signing-service.d.ts +58 -0
- package/packages/agent/src/services/remote-signing-service.d.ts.map +1 -0
- package/packages/agent/src/services/remote-signing-service.js +185 -0
- package/packages/agent/src/services/sandbox-engine.d.ts +96 -0
- package/packages/agent/src/services/sandbox-engine.d.ts.map +1 -0
- package/packages/agent/src/services/sandbox-engine.js +604 -0
- package/packages/agent/src/services/sandbox-manager.d.ts +104 -0
- package/packages/agent/src/services/sandbox-manager.d.ts.map +1 -0
- package/packages/agent/src/services/sandbox-manager.js +353 -0
- package/packages/agent/src/services/self-updater.d.ts +21 -0
- package/packages/agent/src/services/self-updater.d.ts.map +1 -0
- package/packages/agent/src/services/self-updater.js +162 -0
- package/packages/agent/src/services/signal-pairing.d.ts +37 -0
- package/packages/agent/src/services/signal-pairing.d.ts.map +1 -0
- package/packages/agent/src/services/signal-pairing.js +124 -0
- package/packages/agent/src/services/signing-policy.d.ts +44 -0
- package/packages/agent/src/services/signing-policy.d.ts.map +1 -0
- package/packages/agent/src/services/signing-policy.js +165 -0
- package/packages/agent/src/services/skill-catalog-client.d.ts +47 -0
- package/packages/agent/src/services/skill-catalog-client.d.ts.map +1 -0
- package/packages/agent/src/services/skill-catalog-client.js +130 -0
- package/packages/agent/src/services/skill-marketplace.d.ts +42 -0
- package/packages/agent/src/services/skill-marketplace.d.ts.map +1 -0
- package/packages/agent/src/services/skill-marketplace.js +680 -0
- package/packages/agent/src/services/stream-manager.d.ts +121 -0
- package/packages/agent/src/services/stream-manager.d.ts.map +1 -0
- package/packages/agent/src/services/stream-manager.js +604 -0
- package/packages/agent/src/services/tts-stream-bridge.d.ts +83 -0
- package/packages/agent/src/services/tts-stream-bridge.d.ts.map +1 -0
- package/packages/agent/src/services/tts-stream-bridge.js +349 -0
- package/packages/agent/src/services/update-checker.d.ts +29 -0
- package/packages/agent/src/services/update-checker.d.ts.map +1 -0
- package/packages/agent/src/services/update-checker.js +134 -0
- package/packages/agent/src/services/version-compat.d.ts +99 -0
- package/packages/agent/src/services/version-compat.d.ts.map +1 -0
- package/packages/agent/src/services/version-compat.js +195 -0
- package/packages/agent/src/services/whatsapp-pairing.d.ts +41 -0
- package/packages/agent/src/services/whatsapp-pairing.d.ts.map +1 -0
- package/packages/agent/src/services/whatsapp-pairing.js +209 -0
- package/packages/agent/src/shared/ui-catalog-prompt.d.ts +52 -0
- package/packages/agent/src/shared/ui-catalog-prompt.d.ts.map +1 -0
- package/packages/agent/src/shared/ui-catalog-prompt.js +1028 -0
- package/packages/agent/src/test-support/process-helpers.d.ts +13 -0
- package/packages/agent/src/test-support/process-helpers.d.ts.map +1 -0
- package/packages/agent/src/test-support/process-helpers.js +23 -0
- package/packages/agent/src/test-support/route-test-helpers.d.ts +37 -0
- package/packages/agent/src/test-support/route-test-helpers.d.ts.map +1 -0
- package/packages/agent/src/test-support/route-test-helpers.js +54 -0
- package/packages/agent/src/test-support/test-helpers.d.ts +77 -0
- package/packages/agent/src/test-support/test-helpers.d.ts.map +1 -0
- package/packages/agent/src/test-support/test-helpers.js +210 -0
- package/packages/agent/src/testing/index.d.ts +4 -0
- package/packages/agent/src/testing/index.d.ts.map +1 -0
- package/packages/agent/src/testing/index.js +3 -0
- package/packages/agent/src/triggers/action.d.ts +3 -0
- package/packages/agent/src/triggers/action.d.ts.map +1 -0
- package/packages/agent/src/triggers/action.js +267 -0
- package/packages/agent/src/triggers/runtime.d.ts +24 -0
- package/packages/agent/src/triggers/runtime.d.ts.map +1 -0
- package/packages/agent/src/triggers/runtime.js +322 -0
- package/packages/agent/src/triggers/scheduling.d.ts +70 -0
- package/packages/agent/src/triggers/scheduling.d.ts.map +1 -0
- package/packages/agent/src/triggers/scheduling.js +355 -0
- package/packages/agent/src/triggers/types.d.ts +115 -0
- package/packages/agent/src/triggers/types.d.ts.map +1 -0
- package/packages/agent/src/triggers/types.js +1 -0
- package/packages/agent/src/utils/exec-safety.d.ts +2 -0
- package/packages/agent/src/utils/exec-safety.d.ts.map +1 -0
- package/packages/agent/src/utils/exec-safety.js +21 -0
- package/packages/agent/src/utils/number-parsing.d.ts +26 -0
- package/packages/agent/src/utils/number-parsing.d.ts.map +1 -0
- package/packages/agent/src/utils/number-parsing.js +52 -0
- package/packages/agent/src/utils/spoken-text.d.ts +2 -0
- package/packages/agent/src/utils/spoken-text.d.ts.map +1 -0
- package/packages/agent/src/utils/spoken-text.js +56 -0
- package/packages/agent/src/version-resolver.d.ts +3 -0
- package/packages/agent/src/version-resolver.d.ts.map +1 -0
- package/packages/agent/src/version-resolver.js +51 -0
- package/jest.config.js +0 -17
- package/src/__tests__/client-type-identification.test.ts +0 -59
- package/src/defaultCharacter.ts +0 -530
- package/src/index.ts +0 -865
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
2
|
+
import { request as requestHttp, } from "node:http";
|
|
3
|
+
import { request as requestHttps } from "node:https";
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
6
|
+
import { isBlockedPrivateOrLinkLocalIp, normalizeHostLike, } from "../security/network-policy";
|
|
7
|
+
import { parseClampedFloat, parsePositiveInteger, } from "../utils/number-parsing";
|
|
8
|
+
import { getKnowledgeService, } from "./knowledge-service-loader";
|
|
9
|
+
const FRAGMENT_COUNT_BATCH_SIZE = 500;
|
|
10
|
+
const KNOWLEDGE_UPLOAD_MAX_BODY_BYTES = 32 * 1_048_576; // 32 MB
|
|
11
|
+
const MAX_BULK_DOCUMENTS = 100;
|
|
12
|
+
const MAX_URL_IMPORT_BYTES = 10 * 1024 * 1024; // 10 MB
|
|
13
|
+
const MAX_YOUTUBE_WATCH_PAGE_BYTES = 2 * 1024 * 1024; // 2 MB
|
|
14
|
+
const MAX_YOUTUBE_TRANSCRIPT_BYTES = 10 * 1024 * 1024; // 10 MB
|
|
15
|
+
const URL_FETCH_TIMEOUT_MS = 15_000;
|
|
16
|
+
const BLOCKED_HOST_LITERALS = new Set([
|
|
17
|
+
"localhost",
|
|
18
|
+
"metadata.google.internal",
|
|
19
|
+
]);
|
|
20
|
+
function toSafeNumber(value, fallback) {
|
|
21
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
const parsed = Number(value);
|
|
26
|
+
if (Number.isFinite(parsed))
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
return fallback;
|
|
30
|
+
}
|
|
31
|
+
function hasUuidId(memory) {
|
|
32
|
+
return typeof memory.id === "string" && memory.id.length > 0;
|
|
33
|
+
}
|
|
34
|
+
function hasUuidIdAndCreatedAt(memory) {
|
|
35
|
+
return hasUuidId(memory) && typeof memory.createdAt === "number";
|
|
36
|
+
}
|
|
37
|
+
async function countKnowledgeFragmentsForDocument(knowledgeService, roomId, documentId) {
|
|
38
|
+
let offset = 0;
|
|
39
|
+
let fragmentCount = 0;
|
|
40
|
+
while (true) {
|
|
41
|
+
const knowledgeBatch = await knowledgeService.getMemories({
|
|
42
|
+
tableName: "knowledge",
|
|
43
|
+
roomId,
|
|
44
|
+
count: FRAGMENT_COUNT_BATCH_SIZE,
|
|
45
|
+
offset,
|
|
46
|
+
});
|
|
47
|
+
if (knowledgeBatch.length === 0) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
fragmentCount += knowledgeBatch.filter((memory) => {
|
|
51
|
+
const metadata = memory.metadata;
|
|
52
|
+
return metadata?.documentId === documentId;
|
|
53
|
+
}).length;
|
|
54
|
+
if (knowledgeBatch.length < FRAGMENT_COUNT_BATCH_SIZE) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
offset += FRAGMENT_COUNT_BATCH_SIZE;
|
|
58
|
+
}
|
|
59
|
+
return fragmentCount;
|
|
60
|
+
}
|
|
61
|
+
async function mapKnowledgeFragmentsByDocumentId(knowledgeService, roomId, documentIds) {
|
|
62
|
+
const fragmentCounts = new Map();
|
|
63
|
+
const trackedDocumentIds = new Set(documentIds);
|
|
64
|
+
for (const documentId of trackedDocumentIds) {
|
|
65
|
+
fragmentCounts.set(documentId, 0);
|
|
66
|
+
}
|
|
67
|
+
if (trackedDocumentIds.size === 0)
|
|
68
|
+
return fragmentCounts;
|
|
69
|
+
let offset = 0;
|
|
70
|
+
while (true) {
|
|
71
|
+
const knowledgeBatch = await knowledgeService.getMemories({
|
|
72
|
+
tableName: "knowledge",
|
|
73
|
+
roomId,
|
|
74
|
+
count: FRAGMENT_COUNT_BATCH_SIZE,
|
|
75
|
+
offset,
|
|
76
|
+
});
|
|
77
|
+
if (knowledgeBatch.length === 0) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
for (const memory of knowledgeBatch) {
|
|
81
|
+
const metadata = memory.metadata;
|
|
82
|
+
const documentId = metadata?.documentId;
|
|
83
|
+
if (typeof documentId === "string" &&
|
|
84
|
+
trackedDocumentIds.has(documentId)) {
|
|
85
|
+
const currentCount = fragmentCounts.get(documentId) ?? 0;
|
|
86
|
+
fragmentCounts.set(documentId, currentCount + 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (knowledgeBatch.length < FRAGMENT_COUNT_BATCH_SIZE) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
offset += FRAGMENT_COUNT_BATCH_SIZE;
|
|
93
|
+
}
|
|
94
|
+
return fragmentCounts;
|
|
95
|
+
}
|
|
96
|
+
async function listKnowledgeFragmentsForDocument(knowledgeService, roomId, documentId) {
|
|
97
|
+
let offset = 0;
|
|
98
|
+
const fragmentIds = [];
|
|
99
|
+
while (true) {
|
|
100
|
+
const knowledgeBatch = await knowledgeService.getMemories({
|
|
101
|
+
tableName: "knowledge",
|
|
102
|
+
roomId,
|
|
103
|
+
count: FRAGMENT_COUNT_BATCH_SIZE,
|
|
104
|
+
offset,
|
|
105
|
+
});
|
|
106
|
+
for (const memory of knowledgeBatch) {
|
|
107
|
+
const metadata = memory.metadata;
|
|
108
|
+
if (metadata?.documentId === documentId && hasUuidId(memory)) {
|
|
109
|
+
fragmentIds.push(memory.id);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (knowledgeBatch.length < FRAGMENT_COUNT_BATCH_SIZE) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
offset += FRAGMENT_COUNT_BATCH_SIZE;
|
|
116
|
+
}
|
|
117
|
+
return fragmentIds;
|
|
118
|
+
}
|
|
119
|
+
function isBlockedIp(ip) {
|
|
120
|
+
return isBlockedPrivateOrLinkLocalIp(ip);
|
|
121
|
+
}
|
|
122
|
+
function toRequestHeaders(headers) {
|
|
123
|
+
const normalized = {};
|
|
124
|
+
headers.forEach((value, key) => {
|
|
125
|
+
normalized[key] = value;
|
|
126
|
+
});
|
|
127
|
+
return normalized;
|
|
128
|
+
}
|
|
129
|
+
function responseFromIncomingMessage(response) {
|
|
130
|
+
const headers = new Headers();
|
|
131
|
+
for (const [key, value] of Object.entries(response.headers)) {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
for (const item of value)
|
|
134
|
+
headers.append(key, item);
|
|
135
|
+
}
|
|
136
|
+
else if (typeof value === "string") {
|
|
137
|
+
headers.set(key, value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const status = response.statusCode ?? 500;
|
|
141
|
+
const body = status === 204 || status === 205 || status === 304
|
|
142
|
+
? null
|
|
143
|
+
: Readable.toWeb(response);
|
|
144
|
+
return new Response(body, {
|
|
145
|
+
status,
|
|
146
|
+
statusText: response.statusMessage,
|
|
147
|
+
headers,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async function requestWithPinnedAddress(input) {
|
|
151
|
+
const { url, init, target, timeoutMs } = input;
|
|
152
|
+
if (init.body !== undefined && init.body !== null) {
|
|
153
|
+
throw new Error("URL fetch request body is not supported");
|
|
154
|
+
}
|
|
155
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
156
|
+
const headers = toRequestHeaders(new Headers(init.headers));
|
|
157
|
+
const requestFn = url.protocol === "https:" ? requestHttps : requestHttp;
|
|
158
|
+
const family = net.isIP(target.pinnedAddress) === 6 ? 6 : 4;
|
|
159
|
+
return await new Promise((resolve, reject) => {
|
|
160
|
+
let settled = false;
|
|
161
|
+
const signal = init.signal;
|
|
162
|
+
let timeoutHandle = null;
|
|
163
|
+
const settle = (callback) => {
|
|
164
|
+
if (settled)
|
|
165
|
+
return;
|
|
166
|
+
settled = true;
|
|
167
|
+
if (timeoutHandle !== null)
|
|
168
|
+
clearTimeout(timeoutHandle);
|
|
169
|
+
signal?.removeEventListener("abort", onAbort);
|
|
170
|
+
callback();
|
|
171
|
+
};
|
|
172
|
+
const onAbort = () => {
|
|
173
|
+
request.destroy(new DOMException("Aborted", "AbortError"));
|
|
174
|
+
};
|
|
175
|
+
const requestOptions = {
|
|
176
|
+
protocol: url.protocol,
|
|
177
|
+
hostname: target.hostname,
|
|
178
|
+
port: url.port ? Number(url.port) : undefined,
|
|
179
|
+
method,
|
|
180
|
+
path: `${url.pathname}${url.search}`,
|
|
181
|
+
headers,
|
|
182
|
+
lookup: (_hostname, _options, callback) => {
|
|
183
|
+
callback(null, target.pinnedAddress, family);
|
|
184
|
+
},
|
|
185
|
+
...(url.protocol === "https:"
|
|
186
|
+
? { servername: target.hostname }
|
|
187
|
+
: undefined),
|
|
188
|
+
};
|
|
189
|
+
const request = requestFn(requestOptions, (response) => {
|
|
190
|
+
settle(() => resolve(responseFromIncomingMessage(response)));
|
|
191
|
+
});
|
|
192
|
+
request.on("error", (error) => {
|
|
193
|
+
settle(() => reject(error));
|
|
194
|
+
});
|
|
195
|
+
if (signal) {
|
|
196
|
+
if (signal.aborted) {
|
|
197
|
+
onAbort();
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
timeoutHandle = setTimeout(() => {
|
|
204
|
+
request.destroy(new Error(`URL fetch timed out after ${timeoutMs}ms`));
|
|
205
|
+
}, timeoutMs);
|
|
206
|
+
request.end();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
let pinnedFetchImpl = requestWithPinnedAddress;
|
|
210
|
+
// Test hook for deterministic network simulation without sockets.
|
|
211
|
+
export function __setPinnedFetchImplForTests(impl) {
|
|
212
|
+
pinnedFetchImpl = impl ?? requestWithPinnedAddress;
|
|
213
|
+
}
|
|
214
|
+
async function resolveSafeUrlTarget(url) {
|
|
215
|
+
let parsed;
|
|
216
|
+
try {
|
|
217
|
+
parsed = new URL(url);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return { rejection: "Invalid URL format", target: null };
|
|
221
|
+
}
|
|
222
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
223
|
+
return {
|
|
224
|
+
rejection: "Only http:// and https:// URLs are allowed",
|
|
225
|
+
target: null,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const hostname = normalizeHostLike(parsed.hostname);
|
|
229
|
+
if (!hostname)
|
|
230
|
+
return { rejection: "URL hostname is required", target: null };
|
|
231
|
+
if (BLOCKED_HOST_LITERALS.has(hostname)) {
|
|
232
|
+
return {
|
|
233
|
+
rejection: `URL host "${hostname}" is blocked for security reasons`,
|
|
234
|
+
target: null,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (net.isIP(hostname)) {
|
|
238
|
+
if (isBlockedIp(hostname)) {
|
|
239
|
+
return {
|
|
240
|
+
rejection: `URL host "${hostname}" is blocked for security reasons`,
|
|
241
|
+
target: null,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
rejection: null,
|
|
246
|
+
target: {
|
|
247
|
+
parsed,
|
|
248
|
+
hostname,
|
|
249
|
+
pinnedAddress: hostname,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
let addresses;
|
|
254
|
+
try {
|
|
255
|
+
const resolved = await dnsLookup(hostname, { all: true });
|
|
256
|
+
addresses = Array.isArray(resolved) ? resolved : [resolved];
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return {
|
|
260
|
+
rejection: `Could not resolve URL host "${hostname}"`,
|
|
261
|
+
target: null,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
if (addresses.length === 0) {
|
|
265
|
+
return {
|
|
266
|
+
rejection: `Could not resolve URL host "${hostname}"`,
|
|
267
|
+
target: null,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
for (const entry of addresses) {
|
|
271
|
+
if (isBlockedIp(entry.address)) {
|
|
272
|
+
return {
|
|
273
|
+
rejection: `URL host "${hostname}" resolves to blocked address ${entry.address}`,
|
|
274
|
+
target: null,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
rejection: null,
|
|
280
|
+
target: {
|
|
281
|
+
parsed,
|
|
282
|
+
hostname,
|
|
283
|
+
pinnedAddress: addresses[0]?.address ?? "",
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async function fetchWithSafety(url, init, timeoutMs = URL_FETCH_TIMEOUT_MS) {
|
|
288
|
+
const { rejection, target } = await resolveSafeUrlTarget(url);
|
|
289
|
+
if (rejection || !target || !target.pinnedAddress) {
|
|
290
|
+
throw new Error(rejection ?? "URL validation failed");
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
return await pinnedFetchImpl({
|
|
294
|
+
url: target.parsed,
|
|
295
|
+
init,
|
|
296
|
+
target,
|
|
297
|
+
timeoutMs,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
if (isAbortError(error)) {
|
|
302
|
+
throw new Error(`URL fetch timed out after ${timeoutMs}ms`);
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function isYouTubeUrl(url) {
|
|
308
|
+
return /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)/.test(url);
|
|
309
|
+
}
|
|
310
|
+
function extractYouTubeVideoId(url) {
|
|
311
|
+
// Handle youtu.be/VIDEO_ID
|
|
312
|
+
const shortMatch = url.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);
|
|
313
|
+
if (shortMatch)
|
|
314
|
+
return shortMatch[1];
|
|
315
|
+
// Handle youtube.com/watch?v=VIDEO_ID
|
|
316
|
+
const watchMatch = url.match(/[?&]v=([a-zA-Z0-9_-]{11})/);
|
|
317
|
+
if (watchMatch)
|
|
318
|
+
return watchMatch[1];
|
|
319
|
+
// Handle youtube.com/embed/VIDEO_ID
|
|
320
|
+
const embedMatch = url.match(/\/embed\/([a-zA-Z0-9_-]{11})/);
|
|
321
|
+
if (embedMatch)
|
|
322
|
+
return embedMatch[1];
|
|
323
|
+
// Handle youtube.com/v/VIDEO_ID
|
|
324
|
+
const vMatch = url.match(/\/v\/([a-zA-Z0-9_-]{11})/);
|
|
325
|
+
if (vMatch)
|
|
326
|
+
return vMatch[1];
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
async function fetchYouTubeTranscript(videoId) {
|
|
330
|
+
// Fetch the video page to get transcript data
|
|
331
|
+
const watchUrl = `https://www.youtube.com/watch?v=${videoId}`;
|
|
332
|
+
const response = await fetchWithSafety(watchUrl, {
|
|
333
|
+
headers: {
|
|
334
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
335
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
if (!response.ok) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
const html = new TextDecoder().decode(await readResponseBodyWithLimit(response, MAX_YOUTUBE_WATCH_PAGE_BYTES));
|
|
342
|
+
// Extract the captions track URL from the page
|
|
343
|
+
const captionsMatch = html.match(/"captions":\s*\{[^}]*"playerCaptionsTracklistRenderer":\s*\{[^}]*"captionTracks":\s*\[([^\]]+)\]/);
|
|
344
|
+
if (!captionsMatch) {
|
|
345
|
+
// Try alternative pattern for newer YouTube format
|
|
346
|
+
const altMatch = html.match(/"captionTracks":\s*\[([^\]]+)\]/);
|
|
347
|
+
if (!altMatch) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Find the base URL for English captions (or first available)
|
|
352
|
+
const baseUrlMatch = html.match(/"baseUrl":\s*"(https:\/\/www\.youtube\.com\/api\/timedtext[^"]+)"/);
|
|
353
|
+
if (!baseUrlMatch) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
// Decode the URL (it's JSON-escaped)
|
|
357
|
+
const captionUrl = baseUrlMatch[1]
|
|
358
|
+
.replace(/\\u0026/g, "&")
|
|
359
|
+
.replace(/\\\//g, "/");
|
|
360
|
+
// Fetch the transcript
|
|
361
|
+
const transcriptResponse = await fetchWithSafety(captionUrl, {});
|
|
362
|
+
if (!transcriptResponse.ok) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
const transcriptXml = new TextDecoder().decode(await readResponseBodyWithLimit(transcriptResponse, MAX_YOUTUBE_TRANSCRIPT_BYTES));
|
|
366
|
+
// Parse the XML transcript
|
|
367
|
+
const textMatches = transcriptXml.matchAll(/<text[^>]*>([^<]*)<\/text>/g);
|
|
368
|
+
const segments = [];
|
|
369
|
+
for (const match of textMatches) {
|
|
370
|
+
// Decode HTML entities
|
|
371
|
+
const text = match[1]
|
|
372
|
+
.replace(/&/g, "&")
|
|
373
|
+
.replace(/</g, "<")
|
|
374
|
+
.replace(/>/g, ">")
|
|
375
|
+
.replace(/"/g, '"')
|
|
376
|
+
.replace(/'/g, "'")
|
|
377
|
+
.replace(/ /g, " ")
|
|
378
|
+
.trim();
|
|
379
|
+
if (text) {
|
|
380
|
+
segments.push(text);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (segments.length === 0) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
return segments.join(" ");
|
|
387
|
+
}
|
|
388
|
+
function readContentLengthHeader(response) {
|
|
389
|
+
const raw = response.headers.get("content-length");
|
|
390
|
+
if (!raw)
|
|
391
|
+
return null;
|
|
392
|
+
const parsed = Number.parseInt(raw, 10);
|
|
393
|
+
if (!Number.isFinite(parsed) || parsed < 0)
|
|
394
|
+
return null;
|
|
395
|
+
return parsed;
|
|
396
|
+
}
|
|
397
|
+
function isAbortError(error) {
|
|
398
|
+
return error instanceof DOMException
|
|
399
|
+
? error.name === "AbortError"
|
|
400
|
+
: error instanceof Error && error.name === "AbortError";
|
|
401
|
+
}
|
|
402
|
+
async function readResponseBodyWithLimit(response, maxBytes) {
|
|
403
|
+
const declaredLength = readContentLengthHeader(response);
|
|
404
|
+
if (declaredLength !== null && declaredLength > maxBytes) {
|
|
405
|
+
throw new Error(`URL content exceeds maximum size of ${maxBytes} bytes`);
|
|
406
|
+
}
|
|
407
|
+
if (!response.body) {
|
|
408
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
409
|
+
if (bytes.byteLength > maxBytes) {
|
|
410
|
+
throw new Error(`URL content exceeds maximum size of ${maxBytes} bytes`);
|
|
411
|
+
}
|
|
412
|
+
return bytes;
|
|
413
|
+
}
|
|
414
|
+
const reader = response.body.getReader();
|
|
415
|
+
const chunks = [];
|
|
416
|
+
let totalBytes = 0;
|
|
417
|
+
try {
|
|
418
|
+
while (true) {
|
|
419
|
+
const { done, value } = await reader.read();
|
|
420
|
+
if (done)
|
|
421
|
+
break;
|
|
422
|
+
if (!value)
|
|
423
|
+
continue;
|
|
424
|
+
totalBytes += value.byteLength;
|
|
425
|
+
if (totalBytes > maxBytes) {
|
|
426
|
+
throw new Error(`URL content exceeds maximum size of ${maxBytes} bytes`);
|
|
427
|
+
}
|
|
428
|
+
chunks.push(value);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
try {
|
|
433
|
+
await reader.cancel(err);
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
// Best effort cleanup; keep the original error.
|
|
437
|
+
}
|
|
438
|
+
throw err;
|
|
439
|
+
}
|
|
440
|
+
finally {
|
|
441
|
+
reader.releaseLock();
|
|
442
|
+
}
|
|
443
|
+
const output = new Uint8Array(totalBytes);
|
|
444
|
+
let offset = 0;
|
|
445
|
+
for (const chunk of chunks) {
|
|
446
|
+
output.set(chunk, offset);
|
|
447
|
+
offset += chunk.byteLength;
|
|
448
|
+
}
|
|
449
|
+
return output;
|
|
450
|
+
}
|
|
451
|
+
async function fetchUrlContent(url) {
|
|
452
|
+
// Check if it's a YouTube URL
|
|
453
|
+
if (isYouTubeUrl(url)) {
|
|
454
|
+
const videoId = extractYouTubeVideoId(url);
|
|
455
|
+
if (!videoId) {
|
|
456
|
+
throw new Error("Invalid YouTube URL: could not extract video ID");
|
|
457
|
+
}
|
|
458
|
+
const transcript = await fetchYouTubeTranscript(videoId);
|
|
459
|
+
if (!transcript) {
|
|
460
|
+
throw new Error("Could not fetch YouTube transcript. The video may not have captions available.");
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
content: transcript,
|
|
464
|
+
contentType: "text/plain",
|
|
465
|
+
filename: `youtube-${videoId}-transcript.txt`,
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
// Regular URL fetch
|
|
469
|
+
const response = await fetchWithSafety(url, {
|
|
470
|
+
redirect: "manual",
|
|
471
|
+
headers: {
|
|
472
|
+
"User-Agent": "Mozilla/5.0 (compatible; Eliza/1.0; +https://elizaos.ai)",
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
if (response.status >= 300 && response.status < 400) {
|
|
476
|
+
throw new Error("URL redirects are not allowed");
|
|
477
|
+
}
|
|
478
|
+
if (!response.ok) {
|
|
479
|
+
throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);
|
|
480
|
+
}
|
|
481
|
+
const contentType = response.headers.get("content-type") || "application/octet-stream";
|
|
482
|
+
const urlObj = new URL(url);
|
|
483
|
+
const pathSegments = urlObj.pathname.split("/");
|
|
484
|
+
const encodedFilename = pathSegments[pathSegments.length - 1] || "document";
|
|
485
|
+
const filename = decodeURIComponent(encodedFilename);
|
|
486
|
+
const buffer = await readResponseBodyWithLimit(response, MAX_URL_IMPORT_BYTES);
|
|
487
|
+
// For binary content, return as base64
|
|
488
|
+
const isBinary = contentType.startsWith("application/pdf") ||
|
|
489
|
+
contentType.startsWith("application/msword") ||
|
|
490
|
+
contentType.startsWith("application/vnd.openxmlformats-officedocument") ||
|
|
491
|
+
contentType.startsWith("image/");
|
|
492
|
+
if (isBinary) {
|
|
493
|
+
const base64 = Buffer.from(buffer).toString("base64");
|
|
494
|
+
return { content: base64, contentType, filename };
|
|
495
|
+
}
|
|
496
|
+
// For text content, return as string
|
|
497
|
+
const text = new TextDecoder().decode(buffer);
|
|
498
|
+
return { content: text, contentType, filename };
|
|
499
|
+
}
|
|
500
|
+
export async function handleKnowledgeRoutes(ctx) {
|
|
501
|
+
const { req, res, method, pathname, url, runtime, json, error, readJsonBody, } = ctx;
|
|
502
|
+
if (!pathname.startsWith("/api/knowledge"))
|
|
503
|
+
return false;
|
|
504
|
+
const { service: knowledgeService, reason } = await getKnowledgeService(runtime);
|
|
505
|
+
if (!knowledgeService) {
|
|
506
|
+
if (reason === "timeout") {
|
|
507
|
+
res.setHeader("Retry-After", "5");
|
|
508
|
+
error(res, "Knowledge service is still loading. Please retry shortly.", 503);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
error(res, "Knowledge service is not available. Agent may not be running.", 503);
|
|
512
|
+
}
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
if (!runtime?.agentId) {
|
|
516
|
+
error(res, "Agent runtime is not available", 503);
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
const agentId = runtime.agentId;
|
|
520
|
+
// ── GET /api/knowledge/stats ────────────────────────────────────────────
|
|
521
|
+
if (method === "GET" && pathname === "/api/knowledge/stats") {
|
|
522
|
+
const documentCount = await knowledgeService.countMemories({
|
|
523
|
+
tableName: "documents",
|
|
524
|
+
roomId: agentId,
|
|
525
|
+
unique: false,
|
|
526
|
+
});
|
|
527
|
+
const fragmentCount = await knowledgeService.countMemories({
|
|
528
|
+
tableName: "knowledge",
|
|
529
|
+
roomId: agentId,
|
|
530
|
+
unique: false,
|
|
531
|
+
});
|
|
532
|
+
json(res, {
|
|
533
|
+
documentCount,
|
|
534
|
+
fragmentCount,
|
|
535
|
+
agentId,
|
|
536
|
+
});
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
// ── GET /api/knowledge/documents ────────────────────────────────────────
|
|
540
|
+
if (method === "GET" && pathname === "/api/knowledge/documents") {
|
|
541
|
+
const limit = parsePositiveInteger(url.searchParams.get("limit"), 100);
|
|
542
|
+
const offset = parsePositiveInteger(url.searchParams.get("offset"), 0);
|
|
543
|
+
const documents = await knowledgeService.getMemories({
|
|
544
|
+
tableName: "documents",
|
|
545
|
+
roomId: agentId,
|
|
546
|
+
count: limit,
|
|
547
|
+
offset: offset > 0 ? offset : undefined,
|
|
548
|
+
});
|
|
549
|
+
const documentIds = documents.filter(hasUuidId).map((doc) => doc.id);
|
|
550
|
+
const fragmentCounts = await mapKnowledgeFragmentsByDocumentId(knowledgeService, agentId, documentIds);
|
|
551
|
+
// Clean up documents for response (remove embeddings, format metadata)
|
|
552
|
+
const cleanedDocuments = documents.map((doc) => {
|
|
553
|
+
const metadata = doc.metadata;
|
|
554
|
+
const documentId = hasUuidId(doc) ? doc.id : null;
|
|
555
|
+
return {
|
|
556
|
+
id: doc.id,
|
|
557
|
+
filename: metadata?.filename || metadata?.title || "Untitled",
|
|
558
|
+
contentType: metadata?.fileType || metadata?.contentType || "unknown",
|
|
559
|
+
fileSize: toSafeNumber(metadata?.fileSize, 0),
|
|
560
|
+
createdAt: toSafeNumber(doc.createdAt, 0),
|
|
561
|
+
fragmentCount: documentId !== null && fragmentCounts.has(documentId)
|
|
562
|
+
? (fragmentCounts.get(documentId) ?? 0)
|
|
563
|
+
: 0,
|
|
564
|
+
source: metadata?.source || "upload",
|
|
565
|
+
url: metadata?.url,
|
|
566
|
+
};
|
|
567
|
+
});
|
|
568
|
+
json(res, {
|
|
569
|
+
documents: cleanedDocuments,
|
|
570
|
+
total: cleanedDocuments.length,
|
|
571
|
+
limit,
|
|
572
|
+
offset: offset > 0 ? offset : 0,
|
|
573
|
+
});
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
// ── GET /api/knowledge/documents/:id ────────────────────────────────────
|
|
577
|
+
const docIdMatch = /^\/api\/knowledge\/documents\/([^/]+)$/.exec(pathname);
|
|
578
|
+
if (method === "GET" && docIdMatch) {
|
|
579
|
+
const documentId = decodeURIComponent(docIdMatch[1]);
|
|
580
|
+
const documents = await knowledgeService.getMemories({
|
|
581
|
+
tableName: "documents",
|
|
582
|
+
roomId: agentId,
|
|
583
|
+
count: 10000,
|
|
584
|
+
});
|
|
585
|
+
const document = documents.find((d) => d.id === documentId);
|
|
586
|
+
if (!document) {
|
|
587
|
+
error(res, "Document not found", 404);
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
// Get fragment count for this document
|
|
591
|
+
const fragmentCount = await countKnowledgeFragmentsForDocument(knowledgeService, agentId, documentId);
|
|
592
|
+
const metadata = document.metadata;
|
|
593
|
+
json(res, {
|
|
594
|
+
document: {
|
|
595
|
+
id: document.id,
|
|
596
|
+
filename: metadata?.filename || metadata?.title || "Untitled",
|
|
597
|
+
contentType: metadata?.fileType || metadata?.contentType || "unknown",
|
|
598
|
+
fileSize: toSafeNumber(metadata?.fileSize, 0),
|
|
599
|
+
createdAt: toSafeNumber(document.createdAt, 0),
|
|
600
|
+
fragmentCount,
|
|
601
|
+
source: metadata?.source || "upload",
|
|
602
|
+
url: metadata?.url,
|
|
603
|
+
content: document.content,
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
// ── DELETE /api/knowledge/documents/:id ─────────────────────────────────
|
|
609
|
+
if (method === "DELETE" && docIdMatch) {
|
|
610
|
+
const documentId = decodeURIComponent(docIdMatch[1]);
|
|
611
|
+
const fragmentIds = await listKnowledgeFragmentsForDocument(knowledgeService, agentId, documentId);
|
|
612
|
+
for (const fragmentId of fragmentIds) {
|
|
613
|
+
await knowledgeService.deleteMemory(fragmentId);
|
|
614
|
+
}
|
|
615
|
+
// Then delete the document itself
|
|
616
|
+
await knowledgeService.deleteMemory(documentId);
|
|
617
|
+
json(res, {
|
|
618
|
+
ok: true,
|
|
619
|
+
deletedFragments: fragmentIds.length,
|
|
620
|
+
});
|
|
621
|
+
return true;
|
|
622
|
+
}
|
|
623
|
+
async function addKnowledgeDocument(service, document) {
|
|
624
|
+
let content = document.content;
|
|
625
|
+
let contentType = document.contentType || "text/plain";
|
|
626
|
+
const warnings = [];
|
|
627
|
+
// Image files: the content is base64-encoded binary which can't be
|
|
628
|
+
// text-extracted. Convert to a text description for embedding.
|
|
629
|
+
if (contentType.startsWith("image/")) {
|
|
630
|
+
const includeDescriptions = document.metadata
|
|
631
|
+
?.includeImageDescriptions === true;
|
|
632
|
+
if (includeDescriptions && runtime) {
|
|
633
|
+
// Try to describe the image via the runtime's vision model
|
|
634
|
+
try {
|
|
635
|
+
const { ModelType } = await import("@elizaos/core");
|
|
636
|
+
const dataUri = `data:${contentType};base64,${content}`;
|
|
637
|
+
const description = await runtime.useModel(ModelType.IMAGE_DESCRIPTION, {
|
|
638
|
+
imageUrl: dataUri,
|
|
639
|
+
prompt: `Describe this image in detail for a knowledge base. Focus on text content, data, charts, and key visual elements. Image filename: ${document.filename}`,
|
|
640
|
+
});
|
|
641
|
+
const descText = typeof description === "string"
|
|
642
|
+
? description
|
|
643
|
+
: description.description ||
|
|
644
|
+
"Image uploaded";
|
|
645
|
+
content = `[Image: ${document.filename}]\n\n${descText}`;
|
|
646
|
+
contentType = "text/plain";
|
|
647
|
+
}
|
|
648
|
+
catch (err) {
|
|
649
|
+
// Vision failed — store as a reference entry
|
|
650
|
+
content = `[Image: ${document.filename}] — Image uploaded. Vision description unavailable.`;
|
|
651
|
+
contentType = "text/plain";
|
|
652
|
+
warnings.push(`Vision description failed for ${document.filename}: ${err instanceof Error ? err.message : String(err)}`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
// No vision requested — store as a reference entry
|
|
657
|
+
content = `[Image: ${document.filename}] — Image uploaded without text extraction.`;
|
|
658
|
+
contentType = "text/plain";
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
// MDX files: treat as markdown
|
|
662
|
+
if (document.filename?.endsWith(".mdx")) {
|
|
663
|
+
contentType = "text/markdown";
|
|
664
|
+
}
|
|
665
|
+
const result = await service.addKnowledge({
|
|
666
|
+
agentId,
|
|
667
|
+
worldId: agentId,
|
|
668
|
+
roomId: agentId,
|
|
669
|
+
entityId: agentId,
|
|
670
|
+
clientDocumentId: "", // Will be generated
|
|
671
|
+
contentType,
|
|
672
|
+
originalFilename: document.filename,
|
|
673
|
+
content,
|
|
674
|
+
metadata: document.metadata,
|
|
675
|
+
});
|
|
676
|
+
const warningsValue = result.warnings;
|
|
677
|
+
if (Array.isArray(warningsValue)) {
|
|
678
|
+
for (const w of warningsValue) {
|
|
679
|
+
if (typeof w === "string")
|
|
680
|
+
warnings.push(w);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return {
|
|
684
|
+
documentId: result.clientDocumentId,
|
|
685
|
+
fragmentCount: result.fragmentCount,
|
|
686
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
// ── POST /api/knowledge/documents ───────────────────────────────────────
|
|
690
|
+
// Upload document from base64 content or text
|
|
691
|
+
if (method === "POST" && pathname === "/api/knowledge/documents") {
|
|
692
|
+
const body = await readJsonBody(req, res, {
|
|
693
|
+
maxBytes: KNOWLEDGE_UPLOAD_MAX_BODY_BYTES,
|
|
694
|
+
});
|
|
695
|
+
if (!body)
|
|
696
|
+
return true;
|
|
697
|
+
if (!body.content || !body.filename) {
|
|
698
|
+
error(res, "content and filename are required");
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
701
|
+
const result = await addKnowledgeDocument(knowledgeService, body);
|
|
702
|
+
json(res, {
|
|
703
|
+
ok: true,
|
|
704
|
+
documentId: result.documentId,
|
|
705
|
+
fragmentCount: result.fragmentCount,
|
|
706
|
+
warnings: result.warnings,
|
|
707
|
+
});
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
// ── POST /api/knowledge/documents/bulk ──────────────────────────────────
|
|
711
|
+
if (method === "POST" && pathname === "/api/knowledge/documents/bulk") {
|
|
712
|
+
const body = await readJsonBody(req, res, {
|
|
713
|
+
maxBytes: KNOWLEDGE_UPLOAD_MAX_BODY_BYTES,
|
|
714
|
+
});
|
|
715
|
+
if (!body)
|
|
716
|
+
return true;
|
|
717
|
+
if (!Array.isArray(body.documents) || body.documents.length === 0) {
|
|
718
|
+
error(res, "documents array is required");
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
721
|
+
if (body.documents.length > MAX_BULK_DOCUMENTS) {
|
|
722
|
+
error(res, `documents array exceeds limit (${MAX_BULK_DOCUMENTS} per request)`);
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
const results = [];
|
|
726
|
+
for (const [index, document] of body.documents.entries()) {
|
|
727
|
+
const filename = document?.filename || `document-${index + 1}`;
|
|
728
|
+
if (typeof document?.content !== "string" ||
|
|
729
|
+
typeof document?.filename !== "string" ||
|
|
730
|
+
document.content.trim().length === 0 ||
|
|
731
|
+
document.filename.trim().length === 0) {
|
|
732
|
+
results.push({
|
|
733
|
+
index,
|
|
734
|
+
ok: false,
|
|
735
|
+
filename,
|
|
736
|
+
error: "content and filename must be non-empty strings",
|
|
737
|
+
});
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
const normalizedDocument = {
|
|
741
|
+
...document,
|
|
742
|
+
content: document.content,
|
|
743
|
+
filename: document.filename.trim(),
|
|
744
|
+
};
|
|
745
|
+
try {
|
|
746
|
+
const uploadResult = await addKnowledgeDocument(knowledgeService, normalizedDocument);
|
|
747
|
+
results.push({
|
|
748
|
+
index,
|
|
749
|
+
ok: true,
|
|
750
|
+
filename,
|
|
751
|
+
documentId: uploadResult.documentId,
|
|
752
|
+
fragmentCount: uploadResult.fragmentCount,
|
|
753
|
+
warnings: uploadResult.warnings,
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
catch (err) {
|
|
757
|
+
results.push({
|
|
758
|
+
index,
|
|
759
|
+
ok: false,
|
|
760
|
+
filename,
|
|
761
|
+
error: err instanceof Error ? err.message : "Failed to upload document",
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
const successCount = results.filter((item) => item.ok).length;
|
|
766
|
+
const failureCount = results.length - successCount;
|
|
767
|
+
json(res, {
|
|
768
|
+
ok: failureCount === 0,
|
|
769
|
+
total: results.length,
|
|
770
|
+
successCount,
|
|
771
|
+
failureCount,
|
|
772
|
+
results,
|
|
773
|
+
});
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
// ── POST /api/knowledge/documents/url ───────────────────────────────────
|
|
777
|
+
// Upload document from URL (including YouTube auto-transcription)
|
|
778
|
+
if (method === "POST" && pathname === "/api/knowledge/documents/url") {
|
|
779
|
+
const body = await readJsonBody(req, res);
|
|
780
|
+
if (!body)
|
|
781
|
+
return true;
|
|
782
|
+
if (!body.url?.trim()) {
|
|
783
|
+
error(res, "url is required");
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
const urlToFetch = body.url.trim();
|
|
787
|
+
// Fetch and process the URL content
|
|
788
|
+
let content;
|
|
789
|
+
let contentType;
|
|
790
|
+
let filename;
|
|
791
|
+
try {
|
|
792
|
+
({ content, contentType, filename } = await fetchUrlContent(urlToFetch));
|
|
793
|
+
}
|
|
794
|
+
catch (err) {
|
|
795
|
+
error(res, err instanceof Error ? err.message : "Failed to fetch URL content");
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
const result = await knowledgeService.addKnowledge({
|
|
799
|
+
agentId,
|
|
800
|
+
worldId: agentId,
|
|
801
|
+
roomId: agentId,
|
|
802
|
+
entityId: agentId,
|
|
803
|
+
clientDocumentId: "",
|
|
804
|
+
contentType,
|
|
805
|
+
originalFilename: filename,
|
|
806
|
+
content,
|
|
807
|
+
metadata: {
|
|
808
|
+
...body.metadata,
|
|
809
|
+
url: urlToFetch,
|
|
810
|
+
source: isYouTubeUrl(urlToFetch) ? "youtube" : "url",
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
json(res, {
|
|
814
|
+
ok: true,
|
|
815
|
+
documentId: result.clientDocumentId,
|
|
816
|
+
fragmentCount: result.fragmentCount,
|
|
817
|
+
filename,
|
|
818
|
+
contentType,
|
|
819
|
+
isYouTubeTranscript: isYouTubeUrl(urlToFetch),
|
|
820
|
+
});
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
// ── GET /api/knowledge/search ───────────────────────────────────────────
|
|
824
|
+
if (method === "GET" && pathname === "/api/knowledge/search") {
|
|
825
|
+
const query = url.searchParams.get("q");
|
|
826
|
+
if (!query?.trim()) {
|
|
827
|
+
error(res, "Search query (q) is required");
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
const threshold = parseClampedFloat(url.searchParams.get("threshold"), {
|
|
831
|
+
fallback: 0.3,
|
|
832
|
+
min: 0,
|
|
833
|
+
max: 1,
|
|
834
|
+
});
|
|
835
|
+
const limit = parsePositiveInteger(url.searchParams.get("limit"), 20);
|
|
836
|
+
// Create a mock message for the search
|
|
837
|
+
const searchMessage = {
|
|
838
|
+
id: crypto.randomUUID(),
|
|
839
|
+
entityId: agentId,
|
|
840
|
+
agentId,
|
|
841
|
+
roomId: agentId,
|
|
842
|
+
content: { text: query.trim() },
|
|
843
|
+
createdAt: Date.now(),
|
|
844
|
+
};
|
|
845
|
+
const results = await knowledgeService.getKnowledge(searchMessage, {
|
|
846
|
+
roomId: agentId,
|
|
847
|
+
});
|
|
848
|
+
// Filter by threshold and limit
|
|
849
|
+
const filteredResults = results
|
|
850
|
+
.filter((r) => (r.similarity ?? 0) >= threshold)
|
|
851
|
+
.slice(0, limit)
|
|
852
|
+
.map((r) => {
|
|
853
|
+
const meta = r.metadata;
|
|
854
|
+
return {
|
|
855
|
+
id: r.id,
|
|
856
|
+
text: r.content?.text || "",
|
|
857
|
+
similarity: r.similarity,
|
|
858
|
+
documentId: meta?.documentId,
|
|
859
|
+
documentTitle: meta?.filename || meta?.title || "",
|
|
860
|
+
position: meta?.position,
|
|
861
|
+
};
|
|
862
|
+
});
|
|
863
|
+
json(res, {
|
|
864
|
+
query: query.trim(),
|
|
865
|
+
threshold,
|
|
866
|
+
results: filteredResults,
|
|
867
|
+
count: filteredResults.length,
|
|
868
|
+
});
|
|
869
|
+
return true;
|
|
870
|
+
}
|
|
871
|
+
// ── GET /api/knowledge/fragments/:documentId ────────────────────────────
|
|
872
|
+
const fragmentsMatch = /^\/api\/knowledge\/fragments\/([^/]+)$/.exec(pathname);
|
|
873
|
+
if (method === "GET" && fragmentsMatch) {
|
|
874
|
+
const documentId = decodeURIComponent(fragmentsMatch[1]);
|
|
875
|
+
const allFragments = [];
|
|
876
|
+
let fragmentOffset = 0;
|
|
877
|
+
while (true) {
|
|
878
|
+
const fragmentBatch = await knowledgeService.getMemories({
|
|
879
|
+
tableName: "knowledge",
|
|
880
|
+
roomId: agentId,
|
|
881
|
+
count: FRAGMENT_COUNT_BATCH_SIZE,
|
|
882
|
+
offset: fragmentOffset,
|
|
883
|
+
});
|
|
884
|
+
if (fragmentBatch.length === 0) {
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
const matchingFragments = fragmentBatch.filter((fragment) => {
|
|
888
|
+
const metadata = fragment.metadata;
|
|
889
|
+
return metadata?.documentId === documentId;
|
|
890
|
+
});
|
|
891
|
+
for (const fragment of matchingFragments) {
|
|
892
|
+
if (!hasUuidIdAndCreatedAt(fragment)) {
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
const meta = fragment.metadata;
|
|
896
|
+
allFragments.push({
|
|
897
|
+
id: fragment.id,
|
|
898
|
+
text: fragment.content?.text || "",
|
|
899
|
+
position: meta?.position,
|
|
900
|
+
createdAt: fragment.createdAt,
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
if (fragmentBatch.length < FRAGMENT_COUNT_BATCH_SIZE) {
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
fragmentOffset += FRAGMENT_COUNT_BATCH_SIZE;
|
|
907
|
+
}
|
|
908
|
+
const documentFragments = allFragments
|
|
909
|
+
.sort((a, b) => {
|
|
910
|
+
const posA = typeof a.position === "number" ? a.position : 0;
|
|
911
|
+
const posB = typeof b.position === "number" ? b.position : 0;
|
|
912
|
+
return posA - posB;
|
|
913
|
+
})
|
|
914
|
+
.map((f) => {
|
|
915
|
+
return {
|
|
916
|
+
id: f.id,
|
|
917
|
+
text: f.text,
|
|
918
|
+
position: f.position,
|
|
919
|
+
createdAt: f.createdAt,
|
|
920
|
+
};
|
|
921
|
+
});
|
|
922
|
+
json(res, {
|
|
923
|
+
documentId,
|
|
924
|
+
fragments: documentFragments,
|
|
925
|
+
count: documentFragments.length,
|
|
926
|
+
});
|
|
927
|
+
return true;
|
|
928
|
+
}
|
|
929
|
+
// Route not matched within /api/knowledge prefix
|
|
930
|
+
return false;
|
|
931
|
+
}
|