@amodalai/runtime 0.1.26 → 0.2.1
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/dist/src/__fixtures__/README.md +88 -0
- package/dist/src/__fixtures__/e2e.test.js +211 -0
- package/dist/src/__fixtures__/e2e.test.js.map +1 -0
- package/dist/src/__fixtures__/smoke-agent/amodal.json +11 -0
- package/dist/src/__fixtures__/smoke-agent/automations/delivery-callback-test.json +9 -0
- package/dist/src/__fixtures__/smoke-agent/automations/test-auto.md +5 -0
- package/dist/src/__fixtures__/smoke-agent/connections/mock-api/access.json +11 -0
- package/dist/src/__fixtures__/smoke-agent/connections/mock-api/spec.json +4 -0
- package/dist/src/__fixtures__/smoke-agent/connections/mock-api/surface.md +9 -0
- package/dist/src/__fixtures__/smoke-agent/connections/mock-mcp/access.json +3 -0
- package/dist/src/__fixtures__/smoke-agent/connections/mock-mcp/spec.json +8 -0
- package/dist/src/__fixtures__/smoke-agent/evals/basic-eval.md +12 -0
- package/dist/src/__fixtures__/smoke-agent/knowledge/test-knowledge.md +3 -0
- package/dist/src/__fixtures__/smoke-agent/skills/test-skill/SKILL.md +11 -0
- package/dist/src/__fixtures__/smoke-agent/stores/test-items.json +11 -0
- package/dist/src/__fixtures__/smoke-agent/tools/echo_tool/handler.d.ts +18 -0
- package/dist/src/__fixtures__/smoke-agent/tools/echo_tool/handler.js +22 -0
- package/dist/src/__fixtures__/smoke-agent/tools/echo_tool/handler.js.map +1 -0
- package/dist/src/__fixtures__/smoke-agent/tools/echo_tool/tool.json +17 -0
- package/dist/src/__fixtures__/smoke.test.js +1404 -0
- package/dist/src/__fixtures__/smoke.test.js.map +1 -0
- package/dist/src/__fixtures__/test-env.d.ts +27 -0
- package/dist/src/__fixtures__/test-env.js +64 -0
- package/dist/src/__fixtures__/test-env.js.map +1 -0
- package/dist/src/__fixtures__/test-helpers.d.ts +30 -0
- package/dist/src/__fixtures__/test-helpers.js +120 -0
- package/dist/src/__fixtures__/test-helpers.js.map +1 -0
- package/dist/src/__tests__/test-providers.d.ts +40 -0
- package/dist/src/__tests__/test-providers.js +61 -0
- package/dist/src/__tests__/test-providers.js.map +1 -0
- package/dist/src/agent/agent-types.d.ts +22 -0
- package/dist/src/agent/agent-types.js.map +1 -1
- package/dist/src/agent/automation-bridge.d.ts +9 -0
- package/dist/src/agent/automation-bridge.js +26 -0
- package/dist/src/agent/automation-bridge.js.map +1 -1
- package/dist/src/agent/automation-bridge.test.js +63 -0
- package/dist/src/agent/automation-bridge.test.js.map +1 -1
- package/dist/src/agent/local-server.d.ts +1 -8
- package/dist/src/agent/local-server.js +398 -163
- package/dist/src/agent/local-server.js.map +1 -1
- package/dist/src/agent/local-server.test.js +14 -8
- package/dist/src/agent/local-server.test.js.map +1 -1
- package/dist/src/agent/loop-types.d.ts +254 -0
- package/dist/src/agent/loop-types.js +24 -0
- package/dist/src/agent/loop-types.js.map +1 -0
- package/dist/src/agent/loop.d.ts +31 -0
- package/dist/src/agent/loop.js +152 -0
- package/dist/src/agent/loop.js.map +1 -0
- package/dist/src/agent/loop.test.js +1594 -0
- package/dist/src/agent/loop.test.js.map +1 -0
- package/dist/src/agent/mcp-config.d.ts +28 -0
- package/dist/src/agent/mcp-config.js +57 -0
- package/dist/src/agent/mcp-config.js.map +1 -0
- package/dist/src/agent/page-builder.js +6 -1
- package/dist/src/agent/page-builder.js.map +1 -1
- package/dist/src/agent/proactive/delivery-router.d.ts +68 -0
- package/dist/src/agent/proactive/delivery-router.js +337 -0
- package/dist/src/agent/proactive/delivery-router.js.map +1 -0
- package/dist/src/agent/{stores-e2e.test.d.ts → proactive/delivery-router.test.d.ts} +1 -1
- package/dist/src/agent/proactive/delivery-router.test.js +455 -0
- package/dist/src/agent/proactive/delivery-router.test.js.map +1 -0
- package/dist/src/agent/proactive/proactive-runner.d.ts +46 -8
- package/dist/src/agent/proactive/proactive-runner.js +67 -37
- package/dist/src/agent/proactive/proactive-runner.js.map +1 -1
- package/dist/src/agent/proactive/proactive-runner.test.d.ts +1 -1
- package/dist/src/agent/proactive/proactive-runner.test.js +73 -87
- package/dist/src/agent/proactive/proactive-runner.test.js.map +1 -1
- package/dist/src/agent/routes/admin-chat-abort.test.d.ts +6 -0
- package/dist/src/agent/routes/admin-chat-abort.test.js +206 -0
- package/dist/src/agent/routes/admin-chat-abort.test.js.map +1 -0
- package/dist/src/agent/routes/admin-chat.d.ts +15 -3
- package/dist/src/agent/routes/admin-chat.js +61 -18
- package/dist/src/agent/routes/admin-chat.js.map +1 -1
- package/dist/src/agent/routes/automations.js +5 -6
- package/dist/src/agent/routes/automations.js.map +1 -1
- package/dist/src/agent/routes/evals.d.ts +3 -2
- package/dist/src/agent/routes/evals.js +25 -12
- package/dist/src/agent/routes/evals.js.map +1 -1
- package/dist/src/agent/routes/files.js +7 -9
- package/dist/src/agent/routes/files.js.map +1 -1
- package/dist/src/agent/routes/inspect.d.ts +6 -2
- package/dist/src/agent/routes/inspect.js +31 -17
- package/dist/src/agent/routes/inspect.js.map +1 -1
- package/dist/src/agent/routes/inspect.test.js +18 -42
- package/dist/src/agent/routes/inspect.test.js.map +1 -1
- package/dist/src/agent/routes/stores.js +9 -12
- package/dist/src/agent/routes/stores.js.map +1 -1
- package/dist/src/agent/routes/task.d.ts +15 -3
- package/dist/src/agent/routes/task.js +16 -7
- package/dist/src/agent/routes/task.js.map +1 -1
- package/dist/src/agent/routes/task.test.d.ts +1 -1
- package/dist/src/agent/routes/task.test.js +68 -53
- package/dist/src/agent/routes/task.test.js.map +1 -1
- package/dist/src/agent/routes/webhooks.js +12 -3
- package/dist/src/agent/routes/webhooks.js.map +1 -1
- package/dist/src/agent/snapshot-server.d.ts +2 -22
- package/dist/src/agent/snapshot-server.js +48 -27
- package/dist/src/agent/snapshot-server.js.map +1 -1
- package/dist/src/agent/states/compacting.d.ts +14 -0
- package/dist/src/agent/states/compacting.js +260 -0
- package/dist/src/agent/states/compacting.js.map +1 -0
- package/dist/src/agent/states/confirming.d.ts +10 -0
- package/dist/src/agent/states/confirming.js +79 -0
- package/dist/src/agent/states/confirming.js.map +1 -0
- package/dist/src/agent/states/dispatching.d.ts +18 -0
- package/dist/src/agent/states/dispatching.js +285 -0
- package/dist/src/agent/states/dispatching.js.map +1 -0
- package/dist/src/agent/states/executing.d.ts +21 -0
- package/dist/src/agent/states/executing.js +452 -0
- package/dist/src/agent/states/executing.js.map +1 -0
- package/dist/src/agent/states/streaming.d.ts +10 -0
- package/dist/src/agent/states/streaming.js +169 -0
- package/dist/src/agent/states/streaming.js.map +1 -0
- package/dist/src/agent/states/thinking.d.ts +13 -0
- package/dist/src/agent/states/thinking.js +450 -0
- package/dist/src/agent/states/thinking.js.map +1 -0
- package/dist/src/agent/token-estimate.d.ts +31 -0
- package/dist/src/agent/token-estimate.js +34 -0
- package/dist/src/agent/token-estimate.js.map +1 -0
- package/dist/src/agent/token-estimate.test.d.ts +6 -0
- package/dist/src/agent/token-estimate.test.js +44 -0
- package/dist/src/agent/token-estimate.test.js.map +1 -0
- package/dist/src/agent/tool-executor-local.js +9 -18
- package/dist/src/agent/tool-executor-local.js.map +1 -1
- package/dist/src/agent/tool-executor-local.test.js +3 -5
- package/dist/src/agent/tool-executor-local.test.js.map +1 -1
- package/dist/src/api/create-agent.d.ts +15 -0
- package/dist/src/api/create-agent.js +134 -0
- package/dist/src/api/create-agent.js.map +1 -0
- package/dist/src/api/types.d.ts +66 -0
- package/dist/src/api/types.js +7 -0
- package/dist/src/api/types.js.map +1 -0
- package/dist/src/context/compiler.d.ts +13 -0
- package/dist/src/context/compiler.js +358 -0
- package/dist/src/context/compiler.js.map +1 -0
- package/dist/src/context/compiler.test.d.ts +6 -0
- package/dist/src/context/compiler.test.js +532 -0
- package/dist/src/context/compiler.test.js.map +1 -0
- package/dist/src/context/types.d.ts +110 -0
- package/dist/src/context/types.js +7 -0
- package/dist/src/context/types.js.map +1 -0
- package/dist/src/env-ref.d.ts +13 -0
- package/dist/src/env-ref.js +31 -0
- package/dist/src/env-ref.js.map +1 -0
- package/dist/src/env-ref.test.d.ts +6 -0
- package/dist/src/env-ref.test.js +34 -0
- package/dist/src/env-ref.test.js.map +1 -0
- package/dist/src/errors.d.ts +15 -0
- package/dist/src/errors.js +22 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/errors.test.js +2 -2
- package/dist/src/errors.test.js.map +1 -1
- package/dist/src/events/event-bus.d.ts +54 -0
- package/dist/src/events/event-bus.js +84 -0
- package/dist/src/events/event-bus.js.map +1 -0
- package/dist/src/events/event-bus.test.d.ts +6 -0
- package/dist/src/events/event-bus.test.js +112 -0
- package/dist/src/events/event-bus.test.js.map +1 -0
- package/dist/src/events/events-route.d.ts +36 -0
- package/dist/src/events/events-route.js +80 -0
- package/dist/src/events/events-route.js.map +1 -0
- package/dist/src/events/events-route.test.d.ts +6 -0
- package/dist/src/events/events-route.test.js +134 -0
- package/dist/src/events/events-route.test.js.map +1 -0
- package/dist/src/events/store-event-wrapper.d.ts +19 -0
- package/dist/src/events/store-event-wrapper.js +57 -0
- package/dist/src/events/store-event-wrapper.js.map +1 -0
- package/dist/src/events/store-event-wrapper.test.d.ts +6 -0
- package/dist/src/events/store-event-wrapper.test.js +91 -0
- package/dist/src/events/store-event-wrapper.test.js.map +1 -0
- package/dist/src/index.d.ts +33 -6
- package/dist/src/index.js +35 -21
- package/dist/src/index.js.map +1 -1
- package/dist/src/middleware/auth.d.ts +0 -2
- package/dist/src/middleware/auth.js.map +1 -1
- package/dist/src/providers/create-provider.d.ts +23 -0
- package/dist/src/providers/create-provider.js +185 -0
- package/dist/src/providers/create-provider.js.map +1 -0
- package/dist/src/providers/create-provider.test.d.ts +6 -0
- package/dist/src/providers/create-provider.test.js +95 -0
- package/dist/src/providers/create-provider.test.js.map +1 -0
- package/dist/src/providers/failover.d.ts +38 -0
- package/dist/src/providers/failover.js +147 -0
- package/dist/src/providers/failover.js.map +1 -0
- package/dist/src/providers/failover.test.d.ts +6 -0
- package/dist/src/providers/failover.test.js +169 -0
- package/dist/src/providers/failover.test.js.map +1 -0
- package/dist/src/providers/search-provider.d.ts +64 -0
- package/dist/src/providers/search-provider.js +174 -0
- package/dist/src/providers/search-provider.js.map +1 -0
- package/dist/src/providers/types.d.ts +118 -0
- package/dist/src/providers/types.js +7 -0
- package/dist/src/providers/types.js.map +1 -0
- package/dist/src/routes/ai-stream.d.ts +28 -10
- package/dist/src/routes/ai-stream.js +85 -41
- package/dist/src/routes/ai-stream.js.map +1 -1
- package/dist/src/routes/chat-new.test.d.ts +6 -0
- package/dist/src/routes/chat-new.test.js +107 -0
- package/dist/src/routes/chat-new.test.js.map +1 -0
- package/dist/src/routes/chat-stream-new.test.d.ts +6 -0
- package/dist/src/routes/chat-stream-new.test.js +135 -0
- package/dist/src/routes/chat-stream-new.test.js.map +1 -0
- package/dist/src/routes/chat-stream.d.ts +20 -4
- package/dist/src/routes/chat-stream.js +49 -29
- package/dist/src/routes/chat-stream.js.map +1 -1
- package/dist/src/routes/chat.d.ts +19 -4
- package/dist/src/routes/chat.js +62 -23
- package/dist/src/routes/chat.js.map +1 -1
- package/dist/src/routes/health.d.ts +3 -2
- package/dist/src/routes/health.js.map +1 -1
- package/dist/src/routes/route-helpers.d.ts +50 -0
- package/dist/src/routes/route-helpers.js +80 -0
- package/dist/src/routes/route-helpers.js.map +1 -0
- package/dist/src/routes/session-resolver.d.ts +77 -0
- package/dist/src/routes/session-resolver.js +109 -0
- package/dist/src/routes/session-resolver.js.map +1 -0
- package/dist/src/routes/session-resolver.test.d.ts +6 -0
- package/dist/src/routes/session-resolver.test.js +207 -0
- package/dist/src/routes/session-resolver.test.js.map +1 -0
- package/dist/src/routes/webhooks.d.ts +3 -1
- package/dist/src/routes/webhooks.js +12 -4
- package/dist/src/routes/webhooks.js.map +1 -1
- package/dist/src/security/permission-checker.d.ts +80 -0
- package/dist/src/security/permission-checker.js +75 -0
- package/dist/src/security/permission-checker.js.map +1 -0
- package/dist/src/security/permission-checker.test.d.ts +6 -0
- package/dist/src/security/permission-checker.test.js +208 -0
- package/dist/src/security/permission-checker.test.js.map +1 -0
- package/dist/src/server.d.ts +18 -11
- package/dist/src/server.js +46 -46
- package/dist/src/server.js.map +1 -1
- package/dist/src/server.test.d.ts +1 -1
- package/dist/src/server.test.js +6 -144
- package/dist/src/server.test.js.map +1 -1
- package/dist/src/session/drizzle-session-store.d.ts +56 -0
- package/dist/src/session/drizzle-session-store.js +203 -0
- package/dist/src/session/drizzle-session-store.js.map +1 -0
- package/dist/src/session/manager.d.ts +101 -0
- package/dist/src/session/manager.js +394 -0
- package/dist/src/session/manager.js.map +1 -0
- package/dist/src/session/manager.test.d.ts +6 -0
- package/dist/src/session/manager.test.js +309 -0
- package/dist/src/session/manager.test.js.map +1 -0
- package/dist/src/session/pglite-session-store.d.ts +23 -0
- package/dist/src/session/pglite-session-store.js +70 -0
- package/dist/src/session/pglite-session-store.js.map +1 -0
- package/dist/src/session/postgres-session-store.d.ts +44 -0
- package/dist/src/session/postgres-session-store.js +138 -0
- package/dist/src/session/postgres-session-store.js.map +1 -0
- package/dist/src/session/session-builder.d.ts +69 -0
- package/dist/src/session/session-builder.js +384 -0
- package/dist/src/session/session-builder.js.map +1 -0
- package/dist/src/session/session-builder.test.d.ts +6 -0
- package/dist/src/session/session-builder.test.js +350 -0
- package/dist/src/session/session-builder.test.js.map +1 -0
- package/dist/src/session/session-store-selector.d.ts +49 -0
- package/dist/src/session/session-store-selector.js +60 -0
- package/dist/src/session/session-store-selector.js.map +1 -0
- package/dist/src/session/session-store-selector.test.d.ts +6 -0
- package/dist/src/session/session-store-selector.test.js +79 -0
- package/dist/src/session/session-store-selector.test.js.map +1 -0
- package/dist/src/session/store.d.ts +171 -0
- package/dist/src/session/store.js +155 -0
- package/dist/src/session/store.js.map +1 -0
- package/dist/src/session/store.test.d.ts +6 -0
- package/dist/src/session/store.test.js +423 -0
- package/dist/src/session/store.test.js.map +1 -0
- package/dist/src/session/stream-hooks.d.ts +39 -0
- package/dist/src/session/stream-hooks.js +7 -0
- package/dist/src/session/stream-hooks.js.map +1 -0
- package/dist/src/session/tool-context-factory.d.ts +61 -0
- package/dist/src/session/tool-context-factory.js +189 -0
- package/dist/src/session/tool-context-factory.js.map +1 -0
- package/dist/src/session/tool-context-factory.test.d.ts +6 -0
- package/dist/src/session/tool-context-factory.test.js +284 -0
- package/dist/src/session/tool-context-factory.test.js.map +1 -0
- package/dist/src/session/types.d.ts +195 -0
- package/dist/src/session/types.js +7 -0
- package/dist/src/session/types.js.map +1 -0
- package/dist/src/stores/drizzle-store-backend.d.ts +49 -0
- package/dist/src/stores/drizzle-store-backend.js +306 -0
- package/dist/src/stores/drizzle-store-backend.js.map +1 -0
- package/dist/src/stores/drizzle-store-backend.test.d.ts +6 -0
- package/dist/src/stores/drizzle-store-backend.test.js +215 -0
- package/dist/src/stores/drizzle-store-backend.test.js.map +1 -0
- package/dist/src/stores/index.d.ts +4 -0
- package/dist/src/stores/index.js +2 -0
- package/dist/src/stores/index.js.map +1 -1
- package/dist/src/stores/pglite-store-backend.d.ts +16 -19
- package/dist/src/stores/pglite-store-backend.js +85 -239
- package/dist/src/stores/pglite-store-backend.js.map +1 -1
- package/dist/src/stores/postgres-store-backend.d.ts +30 -0
- package/dist/src/stores/postgres-store-backend.js +100 -0
- package/dist/src/stores/postgres-store-backend.js.map +1 -0
- package/dist/src/stores/schema.d.ts +457 -0
- package/dist/src/stores/schema.js +59 -0
- package/dist/src/stores/schema.js.map +1 -0
- package/dist/src/tools/admin-file-tools.d.ts +42 -0
- package/dist/src/tools/admin-file-tools.js +714 -0
- package/dist/src/tools/admin-file-tools.js.map +1 -0
- package/dist/src/tools/admin-file-tools.test.d.ts +6 -0
- package/dist/src/tools/admin-file-tools.test.js +521 -0
- package/dist/src/tools/admin-file-tools.test.js.map +1 -0
- package/dist/src/tools/custom-tool-adapter.d.ts +41 -0
- package/dist/src/tools/custom-tool-adapter.js +190 -0
- package/dist/src/tools/custom-tool-adapter.js.map +1 -0
- package/dist/src/tools/custom-tool-adapter.test.d.ts +6 -0
- package/dist/src/tools/custom-tool-adapter.test.js +243 -0
- package/dist/src/tools/custom-tool-adapter.test.js.map +1 -0
- package/dist/src/tools/dispatch-tool.d.ts +52 -0
- package/dist/src/tools/dispatch-tool.js +71 -0
- package/dist/src/tools/dispatch-tool.js.map +1 -0
- package/dist/src/tools/dispatch-tool.test.d.ts +6 -0
- package/dist/src/tools/dispatch-tool.test.js +75 -0
- package/dist/src/tools/dispatch-tool.test.js.map +1 -0
- package/dist/src/tools/fetch-url-tool.d.ts +23 -0
- package/dist/src/tools/fetch-url-tool.js +333 -0
- package/dist/src/tools/fetch-url-tool.js.map +1 -0
- package/dist/src/tools/fetch-url-tool.test.d.ts +6 -0
- package/dist/src/tools/fetch-url-tool.test.js +228 -0
- package/dist/src/tools/fetch-url-tool.test.js.map +1 -0
- package/dist/src/tools/mcp-tool-adapter.d.ts +18 -0
- package/dist/src/tools/mcp-tool-adapter.js +135 -0
- package/dist/src/tools/mcp-tool-adapter.js.map +1 -0
- package/dist/src/tools/mcp-tool-adapter.test.d.ts +6 -0
- package/dist/src/tools/mcp-tool-adapter.test.js +226 -0
- package/dist/src/tools/mcp-tool-adapter.test.js.map +1 -0
- package/dist/src/tools/registry.d.ts +25 -0
- package/dist/src/tools/registry.js +72 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/dist/src/tools/registry.test.d.ts +6 -0
- package/dist/src/tools/registry.test.js +120 -0
- package/dist/src/tools/registry.test.js.map +1 -0
- package/dist/src/tools/request-tool.d.ts +42 -0
- package/dist/src/tools/request-tool.js +190 -0
- package/dist/src/tools/request-tool.js.map +1 -0
- package/dist/src/tools/request-tool.test.d.ts +6 -0
- package/dist/src/tools/request-tool.test.js +253 -0
- package/dist/src/tools/request-tool.test.js.map +1 -0
- package/dist/src/tools/store-tools.d.ts +29 -0
- package/dist/src/tools/store-tools.js +224 -0
- package/dist/src/tools/store-tools.js.map +1 -0
- package/dist/src/tools/store-tools.test.d.ts +6 -0
- package/dist/src/tools/store-tools.test.js +215 -0
- package/dist/src/tools/store-tools.test.js.map +1 -0
- package/dist/src/tools/types.d.ts +129 -0
- package/dist/src/tools/types.js +7 -0
- package/dist/src/tools/types.js.map +1 -0
- package/dist/src/tools/web-search-tool.d.ts +31 -0
- package/dist/src/tools/web-search-tool.js +170 -0
- package/dist/src/tools/web-search-tool.js.map +1 -0
- package/dist/src/tools/web-search-tool.test.d.ts +6 -0
- package/dist/src/tools/web-search-tool.test.js +153 -0
- package/dist/src/tools/web-search-tool.test.js.map +1 -0
- package/dist/src/tools/web-tools-shared.d.ts +21 -0
- package/dist/src/tools/web-tools-shared.js +32 -0
- package/dist/src/tools/web-tools-shared.js.map +1 -0
- package/dist/src/types.d.ts +40 -12
- package/dist/src/types.js +16 -2
- package/dist/src/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -4
- package/dist/src/__tests__/sse-contract.test.js +0 -464
- package/dist/src/__tests__/sse-contract.test.js.map +0 -1
- package/dist/src/__tests__/tools.test.js +0 -583
- package/dist/src/__tests__/tools.test.js.map +0 -1
- package/dist/src/agent/agent-runner.d.ts +0 -33
- package/dist/src/agent/agent-runner.js +0 -1040
- package/dist/src/agent/agent-runner.js.map +0 -1
- package/dist/src/agent/custom-tools-e2e.test.d.ts +0 -6
- package/dist/src/agent/custom-tools-e2e.test.js +0 -566
- package/dist/src/agent/custom-tools-e2e.test.js.map +0 -1
- package/dist/src/agent/request-helper.d.ts +0 -16
- package/dist/src/agent/request-helper.js +0 -96
- package/dist/src/agent/request-helper.js.map +0 -1
- package/dist/src/agent/session-store.d.ts +0 -62
- package/dist/src/agent/session-store.js +0 -151
- package/dist/src/agent/session-store.js.map +0 -1
- package/dist/src/agent/stores-e2e.test.js +0 -433
- package/dist/src/agent/stores-e2e.test.js.map +0 -1
- package/dist/src/agent/tool-context-builder.d.ts +0 -11
- package/dist/src/agent/tool-context-builder.js +0 -102
- package/dist/src/agent/tool-context-builder.js.map +0 -1
- package/dist/src/agent/tool-context-builder.test.d.ts +0 -6
- package/dist/src/agent/tool-context-builder.test.js +0 -152
- package/dist/src/agent/tool-context-builder.test.js.map +0 -1
- package/dist/src/agent/write-repo-file.test.js +0 -270
- package/dist/src/agent/write-repo-file.test.js.map +0 -1
- package/dist/src/cron/heartbeat-runner.d.ts +0 -21
- package/dist/src/cron/heartbeat-runner.js +0 -79
- package/dist/src/cron/heartbeat-runner.js.map +0 -1
- package/dist/src/cron/heartbeat-runner.test.d.ts +0 -6
- package/dist/src/cron/heartbeat-runner.test.js +0 -120
- package/dist/src/cron/heartbeat-runner.test.js.map +0 -1
- package/dist/src/cron/heartbeat-scheduler.d.ts +0 -26
- package/dist/src/cron/heartbeat-scheduler.js +0 -55
- package/dist/src/cron/heartbeat-scheduler.js.map +0 -1
- package/dist/src/cron/heartbeat-scheduler.test.d.ts +0 -6
- package/dist/src/cron/heartbeat-scheduler.test.js +0 -61
- package/dist/src/cron/heartbeat-scheduler.test.js.map +0 -1
- package/dist/src/routes/ai-stream.test.d.ts +0 -6
- package/dist/src/routes/ai-stream.test.js +0 -586
- package/dist/src/routes/ai-stream.test.js.map +0 -1
- package/dist/src/routes/ask-user-response.d.ts +0 -30
- package/dist/src/routes/ask-user-response.js +0 -61
- package/dist/src/routes/ask-user-response.js.map +0 -1
- package/dist/src/routes/ask-user-response.test.d.ts +0 -6
- package/dist/src/routes/ask-user-response.test.js +0 -88
- package/dist/src/routes/ask-user-response.test.js.map +0 -1
- package/dist/src/routes/chat-stream.test.d.ts +0 -6
- package/dist/src/routes/chat-stream.test.js +0 -155
- package/dist/src/routes/chat-stream.test.js.map +0 -1
- package/dist/src/routes/chat.test.d.ts +0 -6
- package/dist/src/routes/chat.test.js +0 -99
- package/dist/src/routes/chat.test.js.map +0 -1
- package/dist/src/routes/widget-actions.d.ts +0 -49
- package/dist/src/routes/widget-actions.js +0 -78
- package/dist/src/routes/widget-actions.js.map +0 -1
- package/dist/src/session/admin-file-tools.d.ts +0 -136
- package/dist/src/session/admin-file-tools.js +0 -240
- package/dist/src/session/admin-file-tools.js.map +0 -1
- package/dist/src/session/custom-tool-adapter.d.ts +0 -74
- package/dist/src/session/custom-tool-adapter.js +0 -180
- package/dist/src/session/custom-tool-adapter.js.map +0 -1
- package/dist/src/session/history-converter.d.ts +0 -21
- package/dist/src/session/history-converter.js +0 -59
- package/dist/src/session/history-converter.js.map +0 -1
- package/dist/src/session/history-converter.test.d.ts +0 -6
- package/dist/src/session/history-converter.test.js +0 -130
- package/dist/src/session/history-converter.test.js.map +0 -1
- package/dist/src/session/session-manager.d.ts +0 -219
- package/dist/src/session/session-manager.js +0 -915
- package/dist/src/session/session-manager.js.map +0 -1
- package/dist/src/session/session-manager.test.d.ts +0 -6
- package/dist/src/session/session-manager.test.js +0 -455
- package/dist/src/session/session-manager.test.js.map +0 -1
- package/dist/src/session/session-runner.d.ts +0 -45
- package/dist/src/session/session-runner.js +0 -719
- package/dist/src/session/session-runner.js.map +0 -1
- package/dist/src/session/session-runner.test.d.ts +0 -6
- package/dist/src/session/session-runner.test.js +0 -834
- package/dist/src/session/session-runner.test.js.map +0 -1
- /package/dist/src/{__tests__/sse-contract.test.d.ts → __fixtures__/e2e.test.d.ts} +0 -0
- /package/dist/src/{__tests__/tools.test.d.ts → __fixtures__/smoke.test.d.ts} +0 -0
- /package/dist/src/agent/{write-repo-file.test.d.ts → loop.test.d.ts} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Dispatch tool.
|
|
8
|
+
*
|
|
9
|
+
* Allows the model to delegate a sub-task to a child agent with a
|
|
10
|
+
* subset of tools. The EXECUTING state handler intercepts this tool
|
|
11
|
+
* by name and transitions to DISPATCHING — the execute() function
|
|
12
|
+
* here is a safety net that should never be reached.
|
|
13
|
+
*
|
|
14
|
+
* Circular dependency avoidance: this file does NOT import from
|
|
15
|
+
* the agent loop. The dispatch tool is just a schema definition.
|
|
16
|
+
* The actual child agent execution lives in states/dispatching.ts.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { ToolExecutionError } from '../errors.js';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Constants
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
export const DISPATCH_TOOL_NAME = 'dispatch_task';
|
|
24
|
+
const DEFAULT_CHILD_MAX_TURNS = 10;
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Schema
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const DispatchParamsSchema = z.object({
|
|
29
|
+
/** Name for the child agent (used in SSE events and logging) */
|
|
30
|
+
agent_name: z.string().describe('A short descriptive name for the sub-agent (e.g. "data-fetcher", "entity-profiler")'),
|
|
31
|
+
/** Which tools the child agent can use (must be a subset of available tools) */
|
|
32
|
+
tools: z.array(z.string()).describe('List of tool names the child agent can use'),
|
|
33
|
+
/** The task prompt for the child agent */
|
|
34
|
+
prompt: z.string().describe('The task description for the child agent to complete'),
|
|
35
|
+
/** Max turns for the child agent (default: 10) */
|
|
36
|
+
max_turns: z.number().int().positive().optional().describe('Maximum number of LLM turns the child agent can take'),
|
|
37
|
+
});
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// Tool definition
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
/**
|
|
42
|
+
* Create the dispatch_task tool definition.
|
|
43
|
+
*
|
|
44
|
+
* The tool is intercepted by the EXECUTING state handler before execute()
|
|
45
|
+
* is called. The EXECUTING handler reads the args, strips dispatch_task
|
|
46
|
+
* from the child's tool list (preventing recursion), and transitions to
|
|
47
|
+
* DISPATCHING state.
|
|
48
|
+
*/
|
|
49
|
+
export function createDispatchTool() {
|
|
50
|
+
return {
|
|
51
|
+
description: `Delegate a sub-task to a child agent that runs independently with its own tool set. Use this when a task can be broken into parallel or sequential sub-tasks, each requiring specific tools. The child agent completes its task and returns a text summary.
|
|
52
|
+
|
|
53
|
+
The child agent has access only to the tools you specify — choose the minimum set needed. The child cannot dispatch further sub-agents.
|
|
54
|
+
|
|
55
|
+
Use dispatch_task when:
|
|
56
|
+
- A task involves multiple independent data-gathering steps
|
|
57
|
+
- You need to query different connections in parallel
|
|
58
|
+
- A sub-task is self-contained and doesn't need conversation context`,
|
|
59
|
+
parameters: DispatchParamsSchema,
|
|
60
|
+
readOnly: false,
|
|
61
|
+
metadata: { category: 'system' },
|
|
62
|
+
async execute() {
|
|
63
|
+
// The EXECUTING state handler intercepts dispatch_task by name and
|
|
64
|
+
// transitions to DISPATCHING. If execute() is called directly, the
|
|
65
|
+
// interception was bypassed — this is a bug.
|
|
66
|
+
throw new ToolExecutionError('dispatch_task must be intercepted by the EXECUTING state handler — direct execution is not supported', { toolName: DISPATCH_TOOL_NAME, callId: 'unknown', context: {} });
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export { DEFAULT_CHILD_MAX_TURNS };
|
|
71
|
+
//# sourceMappingURL=dispatch-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-tool.js","sourceRoot":"","sources":["../../../src/tools/dispatch-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAEhD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAElD,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,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S } from './dispatch-tool.js';
|
|
8
|
+
import { ToolExecutionError } from '../errors.js';
|
|
9
|
+
describe('dispatch-tool', () => {
|
|
10
|
+
it('has the correct tool name constant', () => {
|
|
11
|
+
expect(DISPATCH_TOOL_NAME).toBe('dispatch_task');
|
|
12
|
+
});
|
|
13
|
+
it('has a sensible default child max turns', () => {
|
|
14
|
+
expect(DEFAULT_CHILD_MAX_TURNS).toBe(10);
|
|
15
|
+
});
|
|
16
|
+
it('creates a tool definition with Zod schema', () => {
|
|
17
|
+
const tool = createDispatchTool();
|
|
18
|
+
expect(tool.description).toContain('child agent');
|
|
19
|
+
expect(tool.readOnly).toBe(false);
|
|
20
|
+
expect(tool.metadata?.category).toBe('system');
|
|
21
|
+
// Zod schema should have safeParse
|
|
22
|
+
expect('safeParse' in tool.parameters).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('validates correct parameters', () => {
|
|
25
|
+
const tool = createDispatchTool();
|
|
26
|
+
const schema = tool.parameters;
|
|
27
|
+
if ('safeParse' in schema) {
|
|
28
|
+
const result = schema.safeParse({
|
|
29
|
+
agent_name: 'data-fetcher',
|
|
30
|
+
tools: ['request', 'query_store'],
|
|
31
|
+
prompt: 'Fetch the latest metrics',
|
|
32
|
+
});
|
|
33
|
+
expect(result.success).toBe(true);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it('validates parameters with optional max_turns', () => {
|
|
37
|
+
const tool = createDispatchTool();
|
|
38
|
+
const schema = tool.parameters;
|
|
39
|
+
if ('safeParse' in schema) {
|
|
40
|
+
const result = schema.safeParse({
|
|
41
|
+
agent_name: 'profiler',
|
|
42
|
+
tools: ['request'],
|
|
43
|
+
prompt: 'Profile the entity',
|
|
44
|
+
max_turns: 5,
|
|
45
|
+
});
|
|
46
|
+
expect(result.success).toBe(true);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
it('rejects missing required fields', () => {
|
|
50
|
+
const tool = createDispatchTool();
|
|
51
|
+
const schema = tool.parameters;
|
|
52
|
+
if ('safeParse' in schema) {
|
|
53
|
+
const result = schema.safeParse({ agent_name: 'test' });
|
|
54
|
+
expect(result.success).toBe(false);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
it('rejects invalid max_turns', () => {
|
|
58
|
+
const tool = createDispatchTool();
|
|
59
|
+
const schema = tool.parameters;
|
|
60
|
+
if ('safeParse' in schema) {
|
|
61
|
+
const result = schema.safeParse({
|
|
62
|
+
agent_name: 'test',
|
|
63
|
+
tools: [],
|
|
64
|
+
prompt: 'do thing',
|
|
65
|
+
max_turns: -1,
|
|
66
|
+
});
|
|
67
|
+
expect(result.success).toBe(false);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
it('execute throws ToolExecutionError (should never be called directly)', async () => {
|
|
71
|
+
const tool = createDispatchTool();
|
|
72
|
+
await expect(tool.execute({}, {})).rejects.toThrow(ToolExecutionError);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=dispatch-tool.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-tool.test.js","sourceRoot":"","sources":["../../../src/tools/dispatch-tool.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAC,kBAAkB,EAAE,kBAAkB,EAAE,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAEhD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,uBAAuB,CAAC,CA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EAAE,EAAE,EAAW,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { FETCH_URL_TOOL_NAME } from '@amodalai/core';
|
|
8
|
+
import type { ToolDefinition } from './types.js';
|
|
9
|
+
export { FETCH_URL_TOOL_NAME };
|
|
10
|
+
declare const FetchUrlParamsSchema: z.ZodObject<{
|
|
11
|
+
url: z.ZodString;
|
|
12
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
url: string;
|
|
15
|
+
prompt?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
url: string;
|
|
18
|
+
prompt?: string | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
type FetchUrlParams = z.infer<typeof FetchUrlParamsSchema>;
|
|
21
|
+
/** Reset rate-limit state (test helper). */
|
|
22
|
+
export declare function resetRateLimitForTesting(): void;
|
|
23
|
+
export declare function createFetchUrlTool(): ToolDefinition<FetchUrlParams>;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* fetch_url tool — grounded URL fetch via Gemini urlContext, with a local
|
|
8
|
+
* fetch + Readability fallback for internal URLs or Gemini failures.
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. If the URL targets a private network (localhost / RFC1918 / .local)
|
|
12
|
+
* OR `ctx.searchProvider` is unavailable, run the local fallback.
|
|
13
|
+
* 2. Otherwise try Gemini urlContext first. If that fails or returns
|
|
14
|
+
* empty content, fall through to the local fallback.
|
|
15
|
+
* 3. Local fallback uses linkedom + Mozilla Readability to extract the
|
|
16
|
+
* main content, then returns it as text/markdown.
|
|
17
|
+
*
|
|
18
|
+
* Per-hostname rate limiting: 10 requests / 60 seconds, in-memory.
|
|
19
|
+
*/
|
|
20
|
+
import { Readability } from '@mozilla/readability';
|
|
21
|
+
import { parseHTML } from 'linkedom';
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import { FETCH_URL_TOOL_NAME } from '@amodalai/core';
|
|
24
|
+
import { log } from '../logger.js';
|
|
25
|
+
import { ToolExecutionError } from '../errors.js';
|
|
26
|
+
import { truncateToTokens, MAX_WEB_TOOL_RESULT_TOKENS } from './web-tools-shared.js';
|
|
27
|
+
export { FETCH_URL_TOOL_NAME };
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Constants
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/** Timeout for the local fetch fallback (ms). */
|
|
32
|
+
const LOCAL_FETCH_TIMEOUT_MS = 10_000;
|
|
33
|
+
/** Max response body size for the local fetch fallback (bytes). */
|
|
34
|
+
const LOCAL_FETCH_MAX_BYTES = 1_000_000;
|
|
35
|
+
/** Rate-limit window size (ms). */
|
|
36
|
+
const RATE_LIMIT_WINDOW_MS = 60_000;
|
|
37
|
+
/** Max requests per hostname per window. */
|
|
38
|
+
const RATE_LIMIT_MAX_REQUESTS = 10;
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Internal error type for the local fetch path
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Internal signaling error thrown by `fetchLocally()`. Always caught and
|
|
44
|
+
* re-wrapped in `ToolExecutionError` at the tool boundary — it never escapes
|
|
45
|
+
* the module. Carrying the hostname/status/size on the error lets the
|
|
46
|
+
* wrapping layer include that context in the structured error response.
|
|
47
|
+
*/
|
|
48
|
+
class LocalFetchError extends Error {
|
|
49
|
+
context;
|
|
50
|
+
constructor(message, context) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'LocalFetchError';
|
|
53
|
+
this.context = context;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Params schema
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
const FetchUrlParamsSchema = z.object({
|
|
60
|
+
url: z
|
|
61
|
+
.string()
|
|
62
|
+
.url()
|
|
63
|
+
.describe('Absolute URL to fetch. Must be http:// or https://.'),
|
|
64
|
+
prompt: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('Optional extraction prompt: what specifically to pull from the page. When omitted, the full page is rendered as markdown.'),
|
|
68
|
+
});
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// Rate limiter (per-hostname sliding window)
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
const hostRequestTimestamps = new Map();
|
|
73
|
+
function checkRateLimit(hostname) {
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
const cutoff = now - RATE_LIMIT_WINDOW_MS;
|
|
76
|
+
const timestamps = (hostRequestTimestamps.get(hostname) ?? []).filter((t) => t > cutoff);
|
|
77
|
+
if (timestamps.length >= RATE_LIMIT_MAX_REQUESTS) {
|
|
78
|
+
const oldest = timestamps[0] ?? now;
|
|
79
|
+
return { ok: false, retryAtMs: oldest + RATE_LIMIT_WINDOW_MS };
|
|
80
|
+
}
|
|
81
|
+
timestamps.push(now);
|
|
82
|
+
hostRequestTimestamps.set(hostname, timestamps);
|
|
83
|
+
return { ok: true };
|
|
84
|
+
}
|
|
85
|
+
/** Reset rate-limit state (test helper). */
|
|
86
|
+
export function resetRateLimitForTesting() {
|
|
87
|
+
hostRequestTimestamps.clear();
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Private network detection
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
const PRIVATE_IPV4_PREFIXES = ['10.', '192.168.'];
|
|
93
|
+
function isPrivateNetworkHost(hostname) {
|
|
94
|
+
const lower = hostname.toLowerCase();
|
|
95
|
+
if (lower === 'localhost' || lower.endsWith('.local') || lower.endsWith('.localhost')) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (lower === '127.0.0.1' || lower === '::1' || lower === '[::1]') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (lower.startsWith('127.'))
|
|
102
|
+
return true;
|
|
103
|
+
for (const prefix of PRIVATE_IPV4_PREFIXES) {
|
|
104
|
+
if (lower.startsWith(prefix))
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
// 172.16.0.0 – 172.31.255.255
|
|
108
|
+
if (lower.startsWith('172.')) {
|
|
109
|
+
const parts = lower.split('.');
|
|
110
|
+
const second = parts[1];
|
|
111
|
+
if (second !== undefined) {
|
|
112
|
+
const n = Number(second);
|
|
113
|
+
if (Number.isInteger(n) && n >= 16 && n <= 31)
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Local fetch + Readability fallback
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
async function fetchLocally(url, signal) {
|
|
123
|
+
const combinedSignal = AbortSignal.any([signal, AbortSignal.timeout(LOCAL_FETCH_TIMEOUT_MS)]);
|
|
124
|
+
const response = await fetch(url, {
|
|
125
|
+
signal: combinedSignal,
|
|
126
|
+
headers: {
|
|
127
|
+
'User-Agent': 'Amodal/fetch_url',
|
|
128
|
+
'Accept': 'text/html,application/xhtml+xml,text/plain;q=0.9,*/*;q=0.5',
|
|
129
|
+
},
|
|
130
|
+
redirect: 'follow',
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
throw new LocalFetchError(`HTTP ${String(response.status)} ${response.statusText}`, {
|
|
134
|
+
url,
|
|
135
|
+
status: response.status,
|
|
136
|
+
statusText: response.statusText,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Enforce size limit while reading. `content-length` can be absent
|
|
140
|
+
// (chunked responses), so we also stream-check via the returned bytes.
|
|
141
|
+
const contentLength = response.headers.get('content-length');
|
|
142
|
+
if (contentLength !== null) {
|
|
143
|
+
const declared = Number(contentLength);
|
|
144
|
+
if (Number.isFinite(declared) && declared > LOCAL_FETCH_MAX_BYTES) {
|
|
145
|
+
throw new LocalFetchError(`Response too large: ${String(declared)} bytes (limit ${String(LOCAL_FETCH_MAX_BYTES)})`, { url, declaredBytes: declared, limit: LOCAL_FETCH_MAX_BYTES });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const buffer = await response.arrayBuffer();
|
|
149
|
+
if (buffer.byteLength > LOCAL_FETCH_MAX_BYTES) {
|
|
150
|
+
throw new LocalFetchError(`Response too large: ${String(buffer.byteLength)} bytes (limit ${String(LOCAL_FETCH_MAX_BYTES)})`, { url, actualBytes: buffer.byteLength, limit: LOCAL_FETCH_MAX_BYTES });
|
|
151
|
+
}
|
|
152
|
+
const html = new TextDecoder('utf-8', { fatal: false }).decode(buffer);
|
|
153
|
+
return extractWithReadability(html, url);
|
|
154
|
+
}
|
|
155
|
+
function extractWithReadability(html, url) {
|
|
156
|
+
const { document } = parseHTML(html);
|
|
157
|
+
// linkedom returns a linkedom-typed `Document`; Readability declares the
|
|
158
|
+
// DOM-lib `Document` type. They are structurally compatible at runtime.
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- linkedom→DOM boundary for Readability
|
|
160
|
+
const article = new Readability(document).parse();
|
|
161
|
+
if (article?.textContent && article.textContent.trim().length > 0) {
|
|
162
|
+
const title = article.title ? `# ${article.title}\n\n` : '';
|
|
163
|
+
return `${title}${article.textContent.trim()}\n\n_Source: ${url}_`;
|
|
164
|
+
}
|
|
165
|
+
// Readability couldn't extract — fall back to walking the parsed DOM.
|
|
166
|
+
// We use the DOM's own structure (via linkedom) instead of regex-based
|
|
167
|
+
// tag stripping, which is both safer and simpler: scripts/styles are
|
|
168
|
+
// removed structurally, entities are already decoded by the parser, and
|
|
169
|
+
// there is no risk of partial-match reinjection. This path runs only
|
|
170
|
+
// when Readability returns nothing useful.
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- linkedom's Document types are loose
|
|
172
|
+
const doc = document;
|
|
173
|
+
// Remove non-content elements whose textContent would otherwise be
|
|
174
|
+
// concatenated into the output (scripts, styles, embedded templates).
|
|
175
|
+
const nonContent = doc.querySelectorAll('script, style, noscript, template');
|
|
176
|
+
for (const el of nonContent) {
|
|
177
|
+
el.remove();
|
|
178
|
+
}
|
|
179
|
+
const rawText = doc.body?.textContent ?? doc.textContent ?? '';
|
|
180
|
+
const text = rawText.replace(/\s+/g, ' ').trim();
|
|
181
|
+
return `${text}\n\n_Source: ${url}_`;
|
|
182
|
+
}
|
|
183
|
+
function parseAndClassify(rawUrl) {
|
|
184
|
+
// URL constructor throws on malformed input — validated upstream by Zod,
|
|
185
|
+
// but we re-parse here to extract hostname.
|
|
186
|
+
const parsed = new URL(rawUrl);
|
|
187
|
+
return {
|
|
188
|
+
hostname: parsed.hostname,
|
|
189
|
+
isPrivate: isPrivateNetworkHost(parsed.hostname),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// Primary path (Gemini urlContext)
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
async function fetchViaSearchProvider(provider, url, userPrompt, signal) {
|
|
196
|
+
const result = await provider.fetchUrl(url, {
|
|
197
|
+
...(userPrompt ? { prompt: userPrompt } : {}),
|
|
198
|
+
signal,
|
|
199
|
+
});
|
|
200
|
+
return result.text;
|
|
201
|
+
}
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
// Factory
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
export function createFetchUrlTool() {
|
|
206
|
+
return {
|
|
207
|
+
description: `Fetch the content of a specific URL. Returns the page content as markdown. Use when you need the actual content of a web page, documentation, or API response you already know the URL for.
|
|
208
|
+
|
|
209
|
+
When to use:
|
|
210
|
+
- You have a specific URL the user referenced or web_search surfaced
|
|
211
|
+
- You need the full content of a documentation page or article
|
|
212
|
+
- Retrieving a raw text or JSON resource
|
|
213
|
+
|
|
214
|
+
When NOT to use:
|
|
215
|
+
- Searching — use web_search
|
|
216
|
+
- Hitting a configured API connection — use the request tool
|
|
217
|
+
- The URL is a user-protected resource (auth/cookies required)`,
|
|
218
|
+
parameters: FetchUrlParamsSchema,
|
|
219
|
+
readOnly: true,
|
|
220
|
+
metadata: { category: 'system' },
|
|
221
|
+
async execute(params, ctx) {
|
|
222
|
+
const started = Date.now();
|
|
223
|
+
const { url, prompt } = params;
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = parseAndClassify(url);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
return {
|
|
230
|
+
status: 'error',
|
|
231
|
+
content: `Invalid URL: ${err instanceof Error ? err.message : 'parse failed'}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const protocol = new URL(url).protocol;
|
|
235
|
+
if (protocol !== 'http:' && protocol !== 'https:') {
|
|
236
|
+
return {
|
|
237
|
+
status: 'error',
|
|
238
|
+
content: `Only http:// and https:// URLs are supported (got ${protocol}).`,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// Rate limit check
|
|
242
|
+
const limitCheck = checkRateLimit(parsed.hostname);
|
|
243
|
+
if (!limitCheck.ok) {
|
|
244
|
+
const retryInSec = Math.max(1, Math.ceil(((limitCheck.retryAtMs ?? Date.now()) - Date.now()) / 1000));
|
|
245
|
+
log.warn('fetch_url_rate_limited', {
|
|
246
|
+
session: ctx.sessionId,
|
|
247
|
+
hostname: parsed.hostname,
|
|
248
|
+
retry_in_sec: retryInSec,
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
status: 'error',
|
|
252
|
+
content: `Rate limited for ${parsed.hostname}. Try again in ${String(retryInSec)}s.`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
// Decide path. The condition narrows `ctx.searchProvider` inside the
|
|
256
|
+
// primary branch so we can use it without a non-null assertion.
|
|
257
|
+
let usedFallback = false;
|
|
258
|
+
let text;
|
|
259
|
+
if (!parsed.isPrivate && ctx.searchProvider) {
|
|
260
|
+
const provider = ctx.searchProvider;
|
|
261
|
+
try {
|
|
262
|
+
text = await fetchViaSearchProvider(provider, url, prompt, ctx.signal);
|
|
263
|
+
// Empty response from Gemini → try local
|
|
264
|
+
if (!text || text.trim().length === 0) {
|
|
265
|
+
text = await fetchLocally(url, ctx.signal);
|
|
266
|
+
usedFallback = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (primaryErr) {
|
|
270
|
+
log.warn('fetch_url_primary_failed', {
|
|
271
|
+
session: ctx.sessionId,
|
|
272
|
+
hostname: parsed.hostname,
|
|
273
|
+
error: primaryErr instanceof Error ? primaryErr.message : String(primaryErr),
|
|
274
|
+
});
|
|
275
|
+
try {
|
|
276
|
+
text = await fetchLocally(url, ctx.signal);
|
|
277
|
+
usedFallback = true;
|
|
278
|
+
}
|
|
279
|
+
catch (fallbackErr) {
|
|
280
|
+
log.error('fetch_url_failed', {
|
|
281
|
+
session: ctx.sessionId,
|
|
282
|
+
hostname: parsed.hostname,
|
|
283
|
+
duration_ms: Date.now() - started,
|
|
284
|
+
path: 'fallback',
|
|
285
|
+
error: fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr),
|
|
286
|
+
});
|
|
287
|
+
throw new ToolExecutionError('fetch_url failed (primary + fallback)', {
|
|
288
|
+
toolName: FETCH_URL_TOOL_NAME,
|
|
289
|
+
callId: ctx.sessionId,
|
|
290
|
+
cause: fallbackErr,
|
|
291
|
+
context: { primaryError: primaryErr instanceof Error ? primaryErr.message : String(primaryErr) },
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
// Private network or no searchProvider configured — local only.
|
|
298
|
+
try {
|
|
299
|
+
text = await fetchLocally(url, ctx.signal);
|
|
300
|
+
usedFallback = true;
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
log.error('fetch_url_failed', {
|
|
304
|
+
session: ctx.sessionId,
|
|
305
|
+
hostname: parsed.hostname,
|
|
306
|
+
duration_ms: Date.now() - started,
|
|
307
|
+
path: 'local',
|
|
308
|
+
error: err instanceof Error ? err.message : String(err),
|
|
309
|
+
});
|
|
310
|
+
throw new ToolExecutionError('fetch_url failed (local fetch)', {
|
|
311
|
+
toolName: FETCH_URL_TOOL_NAME,
|
|
312
|
+
callId: ctx.sessionId,
|
|
313
|
+
cause: err,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const content = truncateToTokens(text, MAX_WEB_TOOL_RESULT_TOKENS);
|
|
318
|
+
log.info('fetch_url', {
|
|
319
|
+
session: ctx.sessionId,
|
|
320
|
+
hostname: parsed.hostname,
|
|
321
|
+
duration_ms: Date.now() - started,
|
|
322
|
+
bytes: text.length,
|
|
323
|
+
used_fallback: usedFallback,
|
|
324
|
+
});
|
|
325
|
+
return {
|
|
326
|
+
status: 'ok',
|
|
327
|
+
content,
|
|
328
|
+
used_fallback: usedFallback,
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
//# sourceMappingURL=fetch-url-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-url-tool.js","sourceRoot":"","sources":["../../../src/tools/fetch-url-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,WAAW,EAAC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