@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
|
@@ -1,834 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
-
* SPDX-License-Identifier: MIT
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
-
import { SSEEventType } from '../types.js';
|
|
8
|
-
// Use string constants to avoid importing the enum from core
|
|
9
|
-
const CONTENT = 'content';
|
|
10
|
-
const TOOL_CALL_REQUEST = 'tool_call_request';
|
|
11
|
-
const ERROR = 'error';
|
|
12
|
-
const AGENT_EXECUTION_STOPPED = 'agent_execution_stopped';
|
|
13
|
-
const ASK_USER = 'ask_user';
|
|
14
|
-
vi.mock('@amodalai/core', async (importOriginal) => {
|
|
15
|
-
const actual = await importOriginal();
|
|
16
|
-
return {
|
|
17
|
-
...actual,
|
|
18
|
-
GeminiEventType: {
|
|
19
|
-
Content: CONTENT,
|
|
20
|
-
ToolCallRequest: TOOL_CALL_REQUEST,
|
|
21
|
-
Error: ERROR,
|
|
22
|
-
AgentExecutionStopped: AGENT_EXECUTION_STOPPED,
|
|
23
|
-
},
|
|
24
|
-
ToolErrorType: {
|
|
25
|
-
STOP_EXECUTION: 'stop_execution',
|
|
26
|
-
},
|
|
27
|
-
MessageBusType: {
|
|
28
|
-
SUBAGENT_ACTIVITY: 'subagent-activity',
|
|
29
|
-
},
|
|
30
|
-
PRESENT_TOOL_NAME: 'present',
|
|
31
|
-
ACTIVATE_SKILL_TOOL_NAME: 'activate_skill',
|
|
32
|
-
ASK_USER_TOOL_NAME: ASK_USER,
|
|
33
|
-
SessionManager: vi.fn(),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
const { runMessage, streamMessage } = await import('./session-runner.js');
|
|
37
|
-
// Helper to create an async generator from an array of events
|
|
38
|
-
async function* makeStream(events) {
|
|
39
|
-
for (const event of events) {
|
|
40
|
-
yield event;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function createMockSession(streamEvents = []) {
|
|
44
|
-
const mockSchedule = vi.fn().mockResolvedValue([]);
|
|
45
|
-
const mockRecordCompletedToolCalls = vi.fn();
|
|
46
|
-
return {
|
|
47
|
-
session: {
|
|
48
|
-
id: 'sess-123',
|
|
49
|
-
config: {
|
|
50
|
-
getModel: vi.fn().mockReturnValue('test-model'),
|
|
51
|
-
shutdownAudit: vi.fn(),
|
|
52
|
-
getMessageBus: vi.fn().mockReturnValue({
|
|
53
|
-
subscribe: vi.fn(),
|
|
54
|
-
unsubscribe: vi.fn(),
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
geminiClient: {
|
|
58
|
-
sendMessageStream: vi.fn().mockReturnValue(makeStream(streamEvents)),
|
|
59
|
-
getCurrentSequenceModel: vi.fn().mockReturnValue('test-model'),
|
|
60
|
-
getChat: vi.fn().mockReturnValue({
|
|
61
|
-
recordCompletedToolCalls: mockRecordCompletedToolCalls,
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
scheduler: {
|
|
65
|
-
schedule: mockSchedule,
|
|
66
|
-
},
|
|
67
|
-
createdAt: Date.now(),
|
|
68
|
-
lastAccessedAt: Date.now(),
|
|
69
|
-
accumulatedMessages: [],
|
|
70
|
-
},
|
|
71
|
-
mockSchedule,
|
|
72
|
-
mockRecordCompletedToolCalls,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
describe('runMessage', () => {
|
|
76
|
-
let controller;
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
controller = new AbortController();
|
|
79
|
-
});
|
|
80
|
-
it('returns text response from content events', async () => {
|
|
81
|
-
const { session } = createMockSession([
|
|
82
|
-
{ type: CONTENT, value: 'Hello ' },
|
|
83
|
-
{ type: CONTENT, value: 'world!' },
|
|
84
|
-
]);
|
|
85
|
-
const result = await runMessage(session, 'hi', controller.signal);
|
|
86
|
-
expect(result.session_id).toBe('sess-123');
|
|
87
|
-
expect(result.response).toBe('Hello world!');
|
|
88
|
-
expect(result.tool_calls).toHaveLength(0);
|
|
89
|
-
});
|
|
90
|
-
it('handles tool calls and continues loop', async () => {
|
|
91
|
-
const toolCallEvent = {
|
|
92
|
-
type: TOOL_CALL_REQUEST,
|
|
93
|
-
value: {
|
|
94
|
-
callId: 'call-1',
|
|
95
|
-
name: 'get_info',
|
|
96
|
-
args: { id: '42' },
|
|
97
|
-
isClientInitiated: false,
|
|
98
|
-
prompt_id: 'p1',
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
// First call returns tool call, second returns text
|
|
102
|
-
let callCount = 0;
|
|
103
|
-
const { session, mockSchedule } = createMockSession();
|
|
104
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
105
|
-
callCount++;
|
|
106
|
-
if (callCount === 1) {
|
|
107
|
-
return makeStream([toolCallEvent]);
|
|
108
|
-
}
|
|
109
|
-
return makeStream([{ type: CONTENT, value: 'Result: done' }]);
|
|
110
|
-
});
|
|
111
|
-
mockSchedule.mockResolvedValue([
|
|
112
|
-
{
|
|
113
|
-
request: { callId: 'call-1', name: 'get_info' },
|
|
114
|
-
response: {
|
|
115
|
-
responseParts: [
|
|
116
|
-
{ functionResponse: { id: 'call-1', name: 'get_info', response: { result: 'ok' } } },
|
|
117
|
-
],
|
|
118
|
-
error: undefined,
|
|
119
|
-
errorType: undefined,
|
|
120
|
-
},
|
|
121
|
-
durationMs: 50,
|
|
122
|
-
},
|
|
123
|
-
]);
|
|
124
|
-
const result = await runMessage(session, 'do something', controller.signal);
|
|
125
|
-
expect(result.tool_calls).toHaveLength(1);
|
|
126
|
-
expect(result.tool_calls[0]?.tool_name).toBe('get_info');
|
|
127
|
-
expect(result.tool_calls[0]?.status).toBe('success');
|
|
128
|
-
expect(result.response).toBe('Result: done');
|
|
129
|
-
});
|
|
130
|
-
it('stops on AgentExecutionStopped event', async () => {
|
|
131
|
-
const { session } = createMockSession([
|
|
132
|
-
{ type: CONTENT, value: 'partial ' },
|
|
133
|
-
{
|
|
134
|
-
type: AGENT_EXECUTION_STOPPED,
|
|
135
|
-
value: { reason: 'done', systemMessage: 'Agent stopped' },
|
|
136
|
-
},
|
|
137
|
-
]);
|
|
138
|
-
const result = await runMessage(session, 'stop test', controller.signal);
|
|
139
|
-
expect(result.response).toBe('partial ');
|
|
140
|
-
});
|
|
141
|
-
it('throws on error events', async () => {
|
|
142
|
-
const { session } = createMockSession([
|
|
143
|
-
{
|
|
144
|
-
type: ERROR,
|
|
145
|
-
value: { error: { message: 'LLM error' } },
|
|
146
|
-
},
|
|
147
|
-
]);
|
|
148
|
-
await expect(runMessage(session, 'error test', controller.signal)).rejects.toThrow('LLM error');
|
|
149
|
-
});
|
|
150
|
-
it('reports error tool calls', async () => {
|
|
151
|
-
const toolCallEvent = {
|
|
152
|
-
type: TOOL_CALL_REQUEST,
|
|
153
|
-
value: {
|
|
154
|
-
callId: 'call-1',
|
|
155
|
-
name: 'failing_tool',
|
|
156
|
-
args: {},
|
|
157
|
-
isClientInitiated: false,
|
|
158
|
-
prompt_id: 'p1',
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
let callCount = 0;
|
|
162
|
-
const { session, mockSchedule } = createMockSession();
|
|
163
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
164
|
-
callCount++;
|
|
165
|
-
if (callCount === 1) {
|
|
166
|
-
return makeStream([toolCallEvent]);
|
|
167
|
-
}
|
|
168
|
-
return makeStream([{ type: CONTENT, value: 'after error' }]);
|
|
169
|
-
});
|
|
170
|
-
mockSchedule.mockResolvedValue([
|
|
171
|
-
{
|
|
172
|
-
request: { callId: 'call-1', name: 'failing_tool' },
|
|
173
|
-
response: {
|
|
174
|
-
responseParts: [
|
|
175
|
-
{ functionResponse: { id: 'call-1', name: 'failing_tool', response: { error: 'fail' } } },
|
|
176
|
-
],
|
|
177
|
-
error: new Error('tool failed'),
|
|
178
|
-
errorType: 'TOOL_EXECUTION_ERROR',
|
|
179
|
-
},
|
|
180
|
-
durationMs: 10,
|
|
181
|
-
},
|
|
182
|
-
]);
|
|
183
|
-
const result = await runMessage(session, 'error tool', controller.signal);
|
|
184
|
-
expect(result.tool_calls[0]?.status).toBe('error');
|
|
185
|
-
expect(result.tool_calls[0]?.error).toBe('tool failed');
|
|
186
|
-
});
|
|
187
|
-
it('stops on STOP_EXECUTION tool error type', async () => {
|
|
188
|
-
const toolCallEvent = {
|
|
189
|
-
type: TOOL_CALL_REQUEST,
|
|
190
|
-
value: {
|
|
191
|
-
callId: 'call-1',
|
|
192
|
-
name: 'stop_tool',
|
|
193
|
-
args: {},
|
|
194
|
-
isClientInitiated: false,
|
|
195
|
-
prompt_id: 'p1',
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
const { session, mockSchedule } = createMockSession();
|
|
199
|
-
session.geminiClient.sendMessageStream = vi
|
|
200
|
-
.fn()
|
|
201
|
-
.mockReturnValue(makeStream([toolCallEvent]));
|
|
202
|
-
mockSchedule.mockResolvedValue([
|
|
203
|
-
{
|
|
204
|
-
request: { callId: 'call-1', name: 'stop_tool' },
|
|
205
|
-
response: {
|
|
206
|
-
responseParts: [],
|
|
207
|
-
error: new Error('stopping'),
|
|
208
|
-
errorType: 'stop_execution',
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
]);
|
|
212
|
-
const result = await runMessage(session, 'stop', controller.signal);
|
|
213
|
-
expect(result.tool_calls).toHaveLength(1);
|
|
214
|
-
});
|
|
215
|
-
it('logs a single session_completed audit event on success', async () => {
|
|
216
|
-
const toolCallEvent = {
|
|
217
|
-
type: TOOL_CALL_REQUEST,
|
|
218
|
-
value: {
|
|
219
|
-
callId: 'call-1',
|
|
220
|
-
name: 'get_info',
|
|
221
|
-
args: { id: '42' },
|
|
222
|
-
isClientInitiated: false,
|
|
223
|
-
prompt_id: 'p1',
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
let callCount = 0;
|
|
227
|
-
const { session, mockSchedule } = createMockSession();
|
|
228
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
229
|
-
callCount++;
|
|
230
|
-
if (callCount === 1) {
|
|
231
|
-
return makeStream([toolCallEvent]);
|
|
232
|
-
}
|
|
233
|
-
return makeStream([{ type: CONTENT, value: 'Done' }]);
|
|
234
|
-
});
|
|
235
|
-
mockSchedule.mockResolvedValue([
|
|
236
|
-
{
|
|
237
|
-
request: { callId: 'call-1', name: 'get_info' },
|
|
238
|
-
response: {
|
|
239
|
-
responseParts: [
|
|
240
|
-
{ functionResponse: { id: 'call-1', name: 'get_info', response: { result: 'ok' } } },
|
|
241
|
-
],
|
|
242
|
-
error: undefined,
|
|
243
|
-
errorType: undefined,
|
|
244
|
-
},
|
|
245
|
-
durationMs: 50,
|
|
246
|
-
},
|
|
247
|
-
]);
|
|
248
|
-
const mockAuditLog = vi.fn();
|
|
249
|
-
const mockUsageReport = vi.fn();
|
|
250
|
-
const hooks = {
|
|
251
|
-
onAuditLog: mockAuditLog,
|
|
252
|
-
onUsageReport: mockUsageReport,
|
|
253
|
-
};
|
|
254
|
-
await runMessage(session, 'do something', controller.signal, hooks);
|
|
255
|
-
expect(mockAuditLog).toHaveBeenCalledOnce();
|
|
256
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
257
|
-
expect(entry['event']).toBe('session_completed');
|
|
258
|
-
expect(entry['resource_name']).toBe('sess-123');
|
|
259
|
-
const details = entry['details'];
|
|
260
|
-
expect(details['status']).toBe('completed');
|
|
261
|
-
expect(details['message']).toBe('do something');
|
|
262
|
-
expect(details['response']).toBe('Done');
|
|
263
|
-
expect(details['turns']).toBe(2);
|
|
264
|
-
const toolCalls = details['tool_calls'];
|
|
265
|
-
expect(toolCalls).toHaveLength(1);
|
|
266
|
-
expect(toolCalls[0]?.['tool_name']).toBe('get_info');
|
|
267
|
-
expect(toolCalls[0]?.['status']).toBe('success');
|
|
268
|
-
});
|
|
269
|
-
it('captures tool result text in audit log', async () => {
|
|
270
|
-
const toolCallEvent = {
|
|
271
|
-
type: TOOL_CALL_REQUEST,
|
|
272
|
-
value: {
|
|
273
|
-
callId: 'call-1',
|
|
274
|
-
name: 'shell_exec',
|
|
275
|
-
args: { command: 'curl http://api/devices' },
|
|
276
|
-
isClientInitiated: false,
|
|
277
|
-
prompt_id: 'p1',
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
let callCount = 0;
|
|
281
|
-
const { session, mockSchedule } = createMockSession();
|
|
282
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
283
|
-
callCount++;
|
|
284
|
-
if (callCount === 1) {
|
|
285
|
-
return makeStream([toolCallEvent]);
|
|
286
|
-
}
|
|
287
|
-
return makeStream([{ type: CONTENT, value: 'Got it' }]);
|
|
288
|
-
});
|
|
289
|
-
mockSchedule.mockResolvedValue([
|
|
290
|
-
{
|
|
291
|
-
request: { callId: 'call-1', name: 'shell_exec' },
|
|
292
|
-
response: {
|
|
293
|
-
responseParts: [
|
|
294
|
-
{ text: '{"devices": [{"id": "d1", "name": "sensor-001"}]}' },
|
|
295
|
-
],
|
|
296
|
-
error: undefined,
|
|
297
|
-
errorType: undefined,
|
|
298
|
-
},
|
|
299
|
-
durationMs: 120,
|
|
300
|
-
},
|
|
301
|
-
]);
|
|
302
|
-
const mockAuditLog = vi.fn();
|
|
303
|
-
const mockUsageReport = vi.fn();
|
|
304
|
-
const hooks = {
|
|
305
|
-
onAuditLog: mockAuditLog,
|
|
306
|
-
onUsageReport: mockUsageReport,
|
|
307
|
-
};
|
|
308
|
-
await runMessage(session, 'list devices', controller.signal, hooks);
|
|
309
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
310
|
-
const details = entry['details'];
|
|
311
|
-
const toolCalls = details['tool_calls'];
|
|
312
|
-
expect(toolCalls[0]?.['result']).toBe('{"devices": [{"id": "d1", "name": "sensor-001"}]}');
|
|
313
|
-
});
|
|
314
|
-
it('captures functionResponse result from task agents in audit log', async () => {
|
|
315
|
-
const toolCallEvent = {
|
|
316
|
-
type: TOOL_CALL_REQUEST,
|
|
317
|
-
value: {
|
|
318
|
-
callId: 'call-1',
|
|
319
|
-
name: 'environment_scanner',
|
|
320
|
-
args: {},
|
|
321
|
-
isClientInitiated: false,
|
|
322
|
-
prompt_id: 'p1',
|
|
323
|
-
},
|
|
324
|
-
};
|
|
325
|
-
let callCount = 0;
|
|
326
|
-
const { session, mockSchedule } = createMockSession();
|
|
327
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
328
|
-
callCount++;
|
|
329
|
-
if (callCount === 1) {
|
|
330
|
-
return makeStream([toolCallEvent]);
|
|
331
|
-
}
|
|
332
|
-
return makeStream([{ type: CONTENT, value: 'Scanned' }]);
|
|
333
|
-
});
|
|
334
|
-
mockSchedule.mockResolvedValue([
|
|
335
|
-
{
|
|
336
|
-
request: { callId: 'call-1', name: 'environment_scanner', args: {} },
|
|
337
|
-
response: {
|
|
338
|
-
responseParts: [
|
|
339
|
-
{
|
|
340
|
-
functionResponse: {
|
|
341
|
-
id: 'call-1',
|
|
342
|
-
name: 'environment_scanner',
|
|
343
|
-
response: { summary: 'No anomalies detected', devices_scanned: 42 },
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
],
|
|
347
|
-
error: undefined,
|
|
348
|
-
errorType: undefined,
|
|
349
|
-
},
|
|
350
|
-
durationMs: 20000,
|
|
351
|
-
},
|
|
352
|
-
]);
|
|
353
|
-
const mockAuditLog = vi.fn();
|
|
354
|
-
const mockUsageReport = vi.fn();
|
|
355
|
-
const hooks = {
|
|
356
|
-
onAuditLog: mockAuditLog,
|
|
357
|
-
onUsageReport: mockUsageReport,
|
|
358
|
-
};
|
|
359
|
-
await runMessage(session, 'scan environment', controller.signal, hooks);
|
|
360
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
361
|
-
const details = entry['details'];
|
|
362
|
-
const toolCalls = details['tool_calls'];
|
|
363
|
-
expect(toolCalls[0]?.['result']).toBe('{"summary":"No anomalies detected","devices_scanned":42}');
|
|
364
|
-
});
|
|
365
|
-
it('truncates long tool result text in audit log', async () => {
|
|
366
|
-
const toolCallEvent = {
|
|
367
|
-
type: TOOL_CALL_REQUEST,
|
|
368
|
-
value: {
|
|
369
|
-
callId: 'call-1',
|
|
370
|
-
name: 'shell_exec',
|
|
371
|
-
args: { command: 'curl http://api/big-response' },
|
|
372
|
-
isClientInitiated: false,
|
|
373
|
-
prompt_id: 'p1',
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
let callCount = 0;
|
|
377
|
-
const { session, mockSchedule } = createMockSession();
|
|
378
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
379
|
-
callCount++;
|
|
380
|
-
if (callCount === 1) {
|
|
381
|
-
return makeStream([toolCallEvent]);
|
|
382
|
-
}
|
|
383
|
-
return makeStream([{ type: CONTENT, value: 'Got it' }]);
|
|
384
|
-
});
|
|
385
|
-
const longText = 'x'.repeat(3000);
|
|
386
|
-
mockSchedule.mockResolvedValue([
|
|
387
|
-
{
|
|
388
|
-
request: { callId: 'call-1', name: 'shell_exec' },
|
|
389
|
-
response: {
|
|
390
|
-
responseParts: [{ text: longText }],
|
|
391
|
-
error: undefined,
|
|
392
|
-
errorType: undefined,
|
|
393
|
-
},
|
|
394
|
-
durationMs: 200,
|
|
395
|
-
},
|
|
396
|
-
]);
|
|
397
|
-
const mockAuditLog = vi.fn();
|
|
398
|
-
const mockUsageReport = vi.fn();
|
|
399
|
-
const hooks = {
|
|
400
|
-
onAuditLog: mockAuditLog,
|
|
401
|
-
onUsageReport: mockUsageReport,
|
|
402
|
-
};
|
|
403
|
-
await runMessage(session, 'big query', controller.signal, hooks);
|
|
404
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
405
|
-
const details = entry['details'];
|
|
406
|
-
const toolCalls = details['tool_calls'];
|
|
407
|
-
const result = toolCalls[0]?.['result'];
|
|
408
|
-
// Tool results are no longer truncated — full output is preserved
|
|
409
|
-
expect(result).toHaveLength(3000);
|
|
410
|
-
});
|
|
411
|
-
it('logs session_completed with error status on throw', async () => {
|
|
412
|
-
const { session } = createMockSession([
|
|
413
|
-
{
|
|
414
|
-
type: ERROR,
|
|
415
|
-
value: { error: { message: 'LLM error' } },
|
|
416
|
-
},
|
|
417
|
-
]);
|
|
418
|
-
const mockAuditLog = vi.fn();
|
|
419
|
-
const mockUsageReport = vi.fn();
|
|
420
|
-
const hooks = {
|
|
421
|
-
onAuditLog: mockAuditLog,
|
|
422
|
-
onUsageReport: mockUsageReport,
|
|
423
|
-
};
|
|
424
|
-
await expect(runMessage(session, 'fail', controller.signal, hooks)).rejects.toThrow('LLM error');
|
|
425
|
-
expect(mockAuditLog).toHaveBeenCalledOnce();
|
|
426
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
427
|
-
expect(entry['event']).toBe('session_completed');
|
|
428
|
-
const details = entry['details'];
|
|
429
|
-
expect(details['status']).toBe('error');
|
|
430
|
-
expect(details['error']).toBe('LLM error');
|
|
431
|
-
});
|
|
432
|
-
});
|
|
433
|
-
describe('streamMessage', () => {
|
|
434
|
-
let controller;
|
|
435
|
-
beforeEach(() => {
|
|
436
|
-
controller = new AbortController();
|
|
437
|
-
});
|
|
438
|
-
async function collectEvents(gen) {
|
|
439
|
-
const events = [];
|
|
440
|
-
for await (const event of gen) {
|
|
441
|
-
events.push(event);
|
|
442
|
-
}
|
|
443
|
-
return events;
|
|
444
|
-
}
|
|
445
|
-
it('yields init event first', async () => {
|
|
446
|
-
const { session } = createMockSession([
|
|
447
|
-
{ type: CONTENT, value: 'hi' },
|
|
448
|
-
]);
|
|
449
|
-
const events = await collectEvents(streamMessage(session, 'hello', controller.signal));
|
|
450
|
-
expect(events[0]?.['type']).toBe(SSEEventType.Init);
|
|
451
|
-
expect(events[0]?.['session_id']).toBe('sess-123');
|
|
452
|
-
});
|
|
453
|
-
it('yields text delta events', async () => {
|
|
454
|
-
const { session } = createMockSession([
|
|
455
|
-
{ type: CONTENT, value: 'Hello ' },
|
|
456
|
-
{ type: CONTENT, value: 'world!' },
|
|
457
|
-
]);
|
|
458
|
-
const events = await collectEvents(streamMessage(session, 'hi', controller.signal));
|
|
459
|
-
const textEvents = events.filter((e) => e['type'] === SSEEventType.TextDelta);
|
|
460
|
-
expect(textEvents).toHaveLength(2);
|
|
461
|
-
expect(textEvents[0]?.['content']).toBe('Hello ');
|
|
462
|
-
expect(textEvents[1]?.['content']).toBe('world!');
|
|
463
|
-
});
|
|
464
|
-
it('yields done event at the end', async () => {
|
|
465
|
-
const { session } = createMockSession([
|
|
466
|
-
{ type: CONTENT, value: 'done' },
|
|
467
|
-
]);
|
|
468
|
-
const events = await collectEvents(streamMessage(session, 'hi', controller.signal));
|
|
469
|
-
const lastEvent = events[events.length - 1];
|
|
470
|
-
expect(lastEvent?.['type']).toBe(SSEEventType.Done);
|
|
471
|
-
});
|
|
472
|
-
it('yields tool call start and result events', async () => {
|
|
473
|
-
const toolCallEvent = {
|
|
474
|
-
type: TOOL_CALL_REQUEST,
|
|
475
|
-
value: {
|
|
476
|
-
callId: 'call-1',
|
|
477
|
-
name: 'get_info',
|
|
478
|
-
args: { q: 'test' },
|
|
479
|
-
isClientInitiated: false,
|
|
480
|
-
prompt_id: 'p1',
|
|
481
|
-
},
|
|
482
|
-
};
|
|
483
|
-
let callCount = 0;
|
|
484
|
-
const { session, mockSchedule } = createMockSession();
|
|
485
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
486
|
-
callCount++;
|
|
487
|
-
if (callCount === 1) {
|
|
488
|
-
return makeStream([toolCallEvent]);
|
|
489
|
-
}
|
|
490
|
-
return makeStream([{ type: CONTENT, value: 'result' }]);
|
|
491
|
-
});
|
|
492
|
-
mockSchedule.mockResolvedValue([
|
|
493
|
-
{
|
|
494
|
-
request: { callId: 'call-1', name: 'get_info' },
|
|
495
|
-
response: {
|
|
496
|
-
responseParts: [
|
|
497
|
-
{ functionResponse: { id: 'call-1', name: 'get_info', response: {} } },
|
|
498
|
-
],
|
|
499
|
-
error: undefined,
|
|
500
|
-
errorType: undefined,
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
]);
|
|
504
|
-
const events = await collectEvents(streamMessage(session, 'do it', controller.signal));
|
|
505
|
-
const toolStart = events.find((e) => e['type'] === SSEEventType.ToolCallStart);
|
|
506
|
-
expect(toolStart).toBeDefined();
|
|
507
|
-
expect(toolStart?.['tool_name']).toBe('get_info');
|
|
508
|
-
const toolResult = events.find((e) => e['type'] === SSEEventType.ToolCallResult);
|
|
509
|
-
expect(toolResult).toBeDefined();
|
|
510
|
-
expect(toolResult?.['status']).toBe('success');
|
|
511
|
-
});
|
|
512
|
-
it('yields error event on LLM error', async () => {
|
|
513
|
-
const { session } = createMockSession([
|
|
514
|
-
{
|
|
515
|
-
type: ERROR,
|
|
516
|
-
value: { error: { message: 'boom' } },
|
|
517
|
-
},
|
|
518
|
-
]);
|
|
519
|
-
const events = await collectEvents(streamMessage(session, 'fail', controller.signal));
|
|
520
|
-
const errorEvent = events.find((e) => e['type'] === SSEEventType.Error);
|
|
521
|
-
expect(errorEvent).toBeDefined();
|
|
522
|
-
expect(errorEvent?.['message']).toBe('boom');
|
|
523
|
-
});
|
|
524
|
-
it('yields skill_activated event when activate_skill tool succeeds', async () => {
|
|
525
|
-
const toolCallEvent = {
|
|
526
|
-
type: TOOL_CALL_REQUEST,
|
|
527
|
-
value: {
|
|
528
|
-
callId: 'call-1',
|
|
529
|
-
name: 'activate_skill',
|
|
530
|
-
args: { name: 'triage' },
|
|
531
|
-
isClientInitiated: false,
|
|
532
|
-
prompt_id: 'p1',
|
|
533
|
-
},
|
|
534
|
-
};
|
|
535
|
-
let callCount = 0;
|
|
536
|
-
const { session, mockSchedule } = createMockSession();
|
|
537
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
538
|
-
callCount++;
|
|
539
|
-
if (callCount === 1) {
|
|
540
|
-
return makeStream([toolCallEvent]);
|
|
541
|
-
}
|
|
542
|
-
return makeStream([{ type: CONTENT, value: 'skill loaded' }]);
|
|
543
|
-
});
|
|
544
|
-
mockSchedule.mockResolvedValue([
|
|
545
|
-
{
|
|
546
|
-
request: { callId: 'call-1', name: 'activate_skill', args: { name: 'triage' } },
|
|
547
|
-
response: {
|
|
548
|
-
responseParts: [
|
|
549
|
-
{ functionResponse: { id: 'call-1', name: 'activate_skill', response: { result: 'ok' } } },
|
|
550
|
-
],
|
|
551
|
-
error: undefined,
|
|
552
|
-
errorType: undefined,
|
|
553
|
-
},
|
|
554
|
-
},
|
|
555
|
-
]);
|
|
556
|
-
const events = await collectEvents(streamMessage(session, 'triage please', controller.signal));
|
|
557
|
-
const skillEvent = events.find((e) => e['type'] === SSEEventType.SkillActivated);
|
|
558
|
-
expect(skillEvent).toBeDefined();
|
|
559
|
-
expect(skillEvent?.['skill_name']).toBe('triage');
|
|
560
|
-
});
|
|
561
|
-
it('logs a single session_completed audit event with tool calls and skills', async () => {
|
|
562
|
-
const toolCallEvent = {
|
|
563
|
-
type: TOOL_CALL_REQUEST,
|
|
564
|
-
value: {
|
|
565
|
-
callId: 'call-1',
|
|
566
|
-
name: 'activate_skill',
|
|
567
|
-
args: { name: 'triage' },
|
|
568
|
-
isClientInitiated: false,
|
|
569
|
-
prompt_id: 'p1',
|
|
570
|
-
},
|
|
571
|
-
};
|
|
572
|
-
let callCount = 0;
|
|
573
|
-
const { session, mockSchedule } = createMockSession();
|
|
574
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
575
|
-
callCount++;
|
|
576
|
-
if (callCount === 1) {
|
|
577
|
-
return makeStream([toolCallEvent]);
|
|
578
|
-
}
|
|
579
|
-
return makeStream([{ type: CONTENT, value: 'skill loaded' }]);
|
|
580
|
-
});
|
|
581
|
-
mockSchedule.mockResolvedValue([
|
|
582
|
-
{
|
|
583
|
-
request: { callId: 'call-1', name: 'activate_skill', args: { name: 'triage' } },
|
|
584
|
-
response: {
|
|
585
|
-
responseParts: [
|
|
586
|
-
{ functionResponse: { id: 'call-1', name: 'activate_skill', response: { result: 'ok' } } },
|
|
587
|
-
],
|
|
588
|
-
error: undefined,
|
|
589
|
-
errorType: undefined,
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
]);
|
|
593
|
-
const mockAuditLog = vi.fn();
|
|
594
|
-
const mockUsageReport = vi.fn();
|
|
595
|
-
const hooks = {
|
|
596
|
-
onAuditLog: mockAuditLog,
|
|
597
|
-
onUsageReport: mockUsageReport,
|
|
598
|
-
};
|
|
599
|
-
await collectEvents(streamMessage(session, 'triage please', controller.signal, hooks));
|
|
600
|
-
expect(mockAuditLog).toHaveBeenCalledOnce();
|
|
601
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
602
|
-
expect(entry['event']).toBe('session_completed');
|
|
603
|
-
expect(entry['resource_name']).toBe('sess-123');
|
|
604
|
-
const details = entry['details'];
|
|
605
|
-
expect(details['status']).toBe('completed');
|
|
606
|
-
expect(details['message']).toBe('triage please');
|
|
607
|
-
expect(details['response']).toBe('skill loaded');
|
|
608
|
-
expect(details['skills_activated']).toEqual(['triage']);
|
|
609
|
-
const toolCalls = details['tool_calls'];
|
|
610
|
-
expect(toolCalls).toHaveLength(1);
|
|
611
|
-
expect(toolCalls[0]?.['tool_name']).toBe('activate_skill');
|
|
612
|
-
});
|
|
613
|
-
it('captures tool result text in streamed audit log', async () => {
|
|
614
|
-
const toolCallEvent = {
|
|
615
|
-
type: TOOL_CALL_REQUEST,
|
|
616
|
-
value: {
|
|
617
|
-
callId: 'call-1',
|
|
618
|
-
name: 'shell_exec',
|
|
619
|
-
args: { command: 'curl http://api/alerts' },
|
|
620
|
-
isClientInitiated: false,
|
|
621
|
-
prompt_id: 'p1',
|
|
622
|
-
},
|
|
623
|
-
};
|
|
624
|
-
let callCount = 0;
|
|
625
|
-
const { session, mockSchedule } = createMockSession();
|
|
626
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
627
|
-
callCount++;
|
|
628
|
-
if (callCount === 1) {
|
|
629
|
-
return makeStream([toolCallEvent]);
|
|
630
|
-
}
|
|
631
|
-
return makeStream([{ type: CONTENT, value: 'Analyzed alerts' }]);
|
|
632
|
-
});
|
|
633
|
-
mockSchedule.mockResolvedValue([
|
|
634
|
-
{
|
|
635
|
-
request: { callId: 'call-1', name: 'shell_exec' },
|
|
636
|
-
response: {
|
|
637
|
-
responseParts: [
|
|
638
|
-
{ text: '{"alerts": [{"severity": "high", "message": "anomaly detected"}]}' },
|
|
639
|
-
],
|
|
640
|
-
error: undefined,
|
|
641
|
-
errorType: undefined,
|
|
642
|
-
},
|
|
643
|
-
durationMs: 80,
|
|
644
|
-
},
|
|
645
|
-
]);
|
|
646
|
-
const mockAuditLog = vi.fn();
|
|
647
|
-
const mockUsageReport = vi.fn();
|
|
648
|
-
const hooks = {
|
|
649
|
-
onAuditLog: mockAuditLog,
|
|
650
|
-
onUsageReport: mockUsageReport,
|
|
651
|
-
};
|
|
652
|
-
await collectEvents(streamMessage(session, 'check alerts', controller.signal, hooks));
|
|
653
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
654
|
-
const details = entry['details'];
|
|
655
|
-
const toolCalls = details['tool_calls'];
|
|
656
|
-
expect(toolCalls[0]?.['result']).toBe('{"alerts": [{"severity": "high", "message": "anomaly detected"}]}');
|
|
657
|
-
});
|
|
658
|
-
it('logs session_completed with error status on LLM error', async () => {
|
|
659
|
-
const { session } = createMockSession([
|
|
660
|
-
{
|
|
661
|
-
type: ERROR,
|
|
662
|
-
value: { error: { message: 'boom' } },
|
|
663
|
-
},
|
|
664
|
-
]);
|
|
665
|
-
const mockAuditLog = vi.fn();
|
|
666
|
-
const mockUsageReport = vi.fn();
|
|
667
|
-
const hooks = {
|
|
668
|
-
onAuditLog: mockAuditLog,
|
|
669
|
-
onUsageReport: mockUsageReport,
|
|
670
|
-
};
|
|
671
|
-
await collectEvents(streamMessage(session, 'fail', controller.signal, hooks));
|
|
672
|
-
expect(mockAuditLog).toHaveBeenCalledOnce();
|
|
673
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
674
|
-
expect(entry['event']).toBe('session_completed');
|
|
675
|
-
const details = entry['details'];
|
|
676
|
-
expect(details['status']).toBe('error');
|
|
677
|
-
expect(details['error']).toBe('boom');
|
|
678
|
-
});
|
|
679
|
-
it('logs session_completed with max_turns status', async () => {
|
|
680
|
-
const { session } = createMockSession();
|
|
681
|
-
// Always return a tool call to keep the loop going — must create fresh stream each time
|
|
682
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => makeStream([{
|
|
683
|
-
type: TOOL_CALL_REQUEST,
|
|
684
|
-
value: {
|
|
685
|
-
callId: 'call-1',
|
|
686
|
-
name: 'get_info',
|
|
687
|
-
args: {},
|
|
688
|
-
isClientInitiated: false,
|
|
689
|
-
prompt_id: 'p1',
|
|
690
|
-
},
|
|
691
|
-
}]));
|
|
692
|
-
session.scheduler.schedule = vi.fn().mockResolvedValue([
|
|
693
|
-
{
|
|
694
|
-
request: { callId: 'call-1', name: 'get_info' },
|
|
695
|
-
response: {
|
|
696
|
-
responseParts: [
|
|
697
|
-
{ functionResponse: { id: 'call-1', name: 'get_info', response: {} } },
|
|
698
|
-
],
|
|
699
|
-
error: undefined,
|
|
700
|
-
errorType: undefined,
|
|
701
|
-
},
|
|
702
|
-
},
|
|
703
|
-
]);
|
|
704
|
-
const mockAuditLog = vi.fn();
|
|
705
|
-
const mockUsageReport = vi.fn();
|
|
706
|
-
const hooks = {
|
|
707
|
-
onAuditLog: mockAuditLog,
|
|
708
|
-
onUsageReport: mockUsageReport,
|
|
709
|
-
};
|
|
710
|
-
await collectEvents(streamMessage(session, 'loop forever', controller.signal, hooks));
|
|
711
|
-
expect(mockAuditLog).toHaveBeenCalledOnce();
|
|
712
|
-
const entry = mockAuditLog.mock.calls[0][0];
|
|
713
|
-
expect(entry['event']).toBe('session_completed');
|
|
714
|
-
const details = entry['details'];
|
|
715
|
-
expect(details['status']).toBe('max_turns');
|
|
716
|
-
expect(details['error']).toBe('Maximum turns exceeded');
|
|
717
|
-
});
|
|
718
|
-
it('intercepts ask_user tool calls and yields ask_user event', async () => {
|
|
719
|
-
const askUserEvent = {
|
|
720
|
-
type: TOOL_CALL_REQUEST,
|
|
721
|
-
value: {
|
|
722
|
-
callId: 'ask-1',
|
|
723
|
-
name: ASK_USER,
|
|
724
|
-
args: {
|
|
725
|
-
questions: [
|
|
726
|
-
{ question: 'Which zone?', header: 'Zone', type: 'choice', options: [{ label: 'A', description: 'Zone A' }, { label: 'B', description: 'Zone B' }] },
|
|
727
|
-
],
|
|
728
|
-
},
|
|
729
|
-
isClientInitiated: false,
|
|
730
|
-
prompt_id: 'p1',
|
|
731
|
-
},
|
|
732
|
-
};
|
|
733
|
-
let callCount = 0;
|
|
734
|
-
const { session } = createMockSession();
|
|
735
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
736
|
-
callCount++;
|
|
737
|
-
if (callCount === 1) {
|
|
738
|
-
return makeStream([askUserEvent]);
|
|
739
|
-
}
|
|
740
|
-
return makeStream([{ type: CONTENT, value: 'Great, Zone A!' }]);
|
|
741
|
-
});
|
|
742
|
-
// Create a mock SessionManager that resolves the ask_user
|
|
743
|
-
const mockSessionManager = {
|
|
744
|
-
waitForAskUserResponse: vi.fn().mockResolvedValue({ '0': 'A' }),
|
|
745
|
-
resolveAskUser: vi.fn().mockReturnValue(true),
|
|
746
|
-
};
|
|
747
|
-
const events = await collectEvents(streamMessage(session, 'choose zone', controller.signal, undefined, mockSessionManager));
|
|
748
|
-
// Should have an ask_user event
|
|
749
|
-
const askEvent = events.find((e) => e['type'] === SSEEventType.AskUser);
|
|
750
|
-
expect(askEvent).toBeDefined();
|
|
751
|
-
expect(askEvent?.['ask_id']).toBe('ask-1');
|
|
752
|
-
expect(askEvent?.['questions']).toHaveLength(1);
|
|
753
|
-
// Should have tool_call_start and tool_call_result for ask_user
|
|
754
|
-
const toolStart = events.find((e) => e['type'] === SSEEventType.ToolCallStart && e['tool_name'] === ASK_USER);
|
|
755
|
-
expect(toolStart).toBeDefined();
|
|
756
|
-
const toolResult = events.find((e) => e['type'] === SSEEventType.ToolCallResult && e['tool_id'] === 'ask-1');
|
|
757
|
-
expect(toolResult).toBeDefined();
|
|
758
|
-
expect(toolResult?.['status']).toBe('success');
|
|
759
|
-
// Should continue with text response
|
|
760
|
-
const textEvents = events.filter((e) => e['type'] === SSEEventType.TextDelta);
|
|
761
|
-
expect(textEvents.length).toBeGreaterThan(0);
|
|
762
|
-
// waitForAskUserResponse should have been called
|
|
763
|
-
expect(mockSessionManager.waitForAskUserResponse).toHaveBeenCalledWith(session, 'ask-1', controller.signal);
|
|
764
|
-
});
|
|
765
|
-
it('handles ask_user timeout gracefully', async () => {
|
|
766
|
-
const askUserEvent = {
|
|
767
|
-
type: TOOL_CALL_REQUEST,
|
|
768
|
-
value: {
|
|
769
|
-
callId: 'ask-timeout',
|
|
770
|
-
name: ASK_USER,
|
|
771
|
-
args: {
|
|
772
|
-
questions: [{ question: 'Answer?', header: 'Q', type: 'text' }],
|
|
773
|
-
},
|
|
774
|
-
isClientInitiated: false,
|
|
775
|
-
prompt_id: 'p1',
|
|
776
|
-
},
|
|
777
|
-
};
|
|
778
|
-
let callCount = 0;
|
|
779
|
-
const { session } = createMockSession();
|
|
780
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
781
|
-
callCount++;
|
|
782
|
-
if (callCount === 1) {
|
|
783
|
-
return makeStream([askUserEvent]);
|
|
784
|
-
}
|
|
785
|
-
return makeStream([{ type: CONTENT, value: 'Timed out' }]);
|
|
786
|
-
});
|
|
787
|
-
const mockSessionManager = {
|
|
788
|
-
waitForAskUserResponse: vi.fn().mockRejectedValue(new Error('ask_user response timed out')),
|
|
789
|
-
};
|
|
790
|
-
const events = await collectEvents(streamMessage(session, 'question', controller.signal, undefined, mockSessionManager));
|
|
791
|
-
// Should have error result for the ask_user tool call
|
|
792
|
-
const toolResult = events.find((e) => e['type'] === SSEEventType.ToolCallResult && e['tool_id'] === 'ask-timeout');
|
|
793
|
-
expect(toolResult).toBeDefined();
|
|
794
|
-
expect(toolResult?.['status']).toBe('error');
|
|
795
|
-
expect(toolResult?.['error']).toBe('ask_user response timed out');
|
|
796
|
-
});
|
|
797
|
-
it('does not yield skill_activated when activate_skill tool fails', async () => {
|
|
798
|
-
const toolCallEvent = {
|
|
799
|
-
type: TOOL_CALL_REQUEST,
|
|
800
|
-
value: {
|
|
801
|
-
callId: 'call-1',
|
|
802
|
-
name: 'activate_skill',
|
|
803
|
-
args: { name: 'nonexistent' },
|
|
804
|
-
isClientInitiated: false,
|
|
805
|
-
prompt_id: 'p1',
|
|
806
|
-
},
|
|
807
|
-
};
|
|
808
|
-
let callCount = 0;
|
|
809
|
-
const { session, mockSchedule } = createMockSession();
|
|
810
|
-
session.geminiClient.sendMessageStream = vi.fn().mockImplementation(() => {
|
|
811
|
-
callCount++;
|
|
812
|
-
if (callCount === 1) {
|
|
813
|
-
return makeStream([toolCallEvent]);
|
|
814
|
-
}
|
|
815
|
-
return makeStream([{ type: CONTENT, value: 'failed' }]);
|
|
816
|
-
});
|
|
817
|
-
mockSchedule.mockResolvedValue([
|
|
818
|
-
{
|
|
819
|
-
request: { callId: 'call-1', name: 'activate_skill', args: { name: 'nonexistent' } },
|
|
820
|
-
response: {
|
|
821
|
-
responseParts: [
|
|
822
|
-
{ functionResponse: { id: 'call-1', name: 'activate_skill', response: { error: 'not found' } } },
|
|
823
|
-
],
|
|
824
|
-
error: new Error('Skill not found'),
|
|
825
|
-
errorType: 'TOOL_EXECUTION_ERROR',
|
|
826
|
-
},
|
|
827
|
-
},
|
|
828
|
-
]);
|
|
829
|
-
const events = await collectEvents(streamMessage(session, 'bad skill', controller.signal));
|
|
830
|
-
const skillEvent = events.find((e) => e['type'] === SSEEventType.SkillActivated);
|
|
831
|
-
expect(skillEvent).toBeUndefined();
|
|
832
|
-
});
|
|
833
|
-
});
|
|
834
|
-
//# sourceMappingURL=session-runner.test.js.map
|