@agent-native/core 0.5.0-dev.b51eaae → 0.6.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/README.md +15 -43
- package/dist/a2a/agent-card.d.ts.map +1 -1
- package/dist/a2a/agent-card.js +12 -1
- package/dist/a2a/agent-card.js.map +1 -1
- package/dist/a2a/client.d.ts +11 -0
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +38 -1
- package/dist/a2a/client.js.map +1 -1
- package/dist/a2a/index.d.ts +1 -1
- package/dist/a2a/index.d.ts.map +1 -1
- package/dist/a2a/index.js +1 -1
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/server.d.ts +4 -0
- package/dist/a2a/server.d.ts.map +1 -1
- package/dist/a2a/server.js +53 -8
- package/dist/a2a/server.js.map +1 -1
- package/dist/a2a/types.d.ts +1 -0
- package/dist/a2a/types.d.ts.map +1 -1
- package/dist/action.d.ts +64 -30
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +224 -27
- package/dist/action.js.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.d.ts +24 -0
- package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -0
- package/dist/agent/engine/ai-sdk-engine.js +302 -0
- package/dist/agent/engine/ai-sdk-engine.js.map +1 -0
- package/dist/agent/engine/anthropic-engine.d.ts +24 -0
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -0
- package/dist/agent/engine/anthropic-engine.js +169 -0
- package/dist/agent/engine/anthropic-engine.js.map +1 -0
- package/dist/agent/engine/builtin.d.ts +12 -0
- package/dist/agent/engine/builtin.d.ts.map +1 -0
- package/dist/agent/engine/builtin.js +72 -0
- package/dist/agent/engine/builtin.js.map +1 -0
- package/dist/agent/engine/index.d.ts +9 -0
- package/dist/agent/engine/index.d.ts.map +1 -0
- package/dist/agent/engine/index.js +8 -0
- package/dist/agent/engine/index.js.map +1 -0
- package/dist/agent/engine/registry.d.ts +61 -0
- package/dist/agent/engine/registry.d.ts.map +1 -0
- package/dist/agent/engine/registry.js +101 -0
- package/dist/agent/engine/registry.js.map +1 -0
- package/dist/agent/engine/translate-ai-sdk.d.ts +20 -0
- package/dist/agent/engine/translate-ai-sdk.d.ts.map +1 -0
- package/dist/agent/engine/translate-ai-sdk.js +174 -0
- package/dist/agent/engine/translate-ai-sdk.js.map +1 -0
- package/dist/agent/engine/translate-anthropic.d.ts +23 -0
- package/dist/agent/engine/translate-anthropic.d.ts.map +1 -0
- package/dist/agent/engine/translate-anthropic.js +140 -0
- package/dist/agent/engine/translate-anthropic.js.map +1 -0
- package/dist/agent/engine/types.d.ts +168 -0
- package/dist/agent/engine/types.d.ts.map +1 -0
- package/dist/agent/engine/types.js +13 -0
- package/dist/agent/engine/types.js.map +1 -0
- package/dist/agent/production-agent.d.ts +48 -2
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +216 -76
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +1 -1
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +15 -9
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +5 -5
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/thread-data-builder.d.ts +1 -0
- package/dist/agent/thread-data-builder.d.ts.map +1 -1
- package/dist/agent/thread-data-builder.js +4 -1
- package/dist/agent/thread-data-builder.js.map +1 -1
- package/dist/agent/types.d.ts +22 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/application-state/handlers.d.ts +8 -8
- package/dist/application-state/handlers.d.ts.map +1 -1
- package/dist/application-state/handlers.js +3 -2
- package/dist/application-state/handlers.js.map +1 -1
- package/dist/application-state/script-helpers.d.ts.map +1 -1
- package/dist/application-state/script-helpers.js +47 -9
- package/dist/application-state/script-helpers.js.map +1 -1
- package/dist/chat-threads/store.d.ts +14 -0
- package/dist/chat-threads/store.d.ts.map +1 -1
- package/dist/chat-threads/store.js +32 -0
- package/dist/chat-threads/store.js.map +1 -1
- package/dist/cli/create.d.ts +8 -2
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +287 -32
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/index.js +19 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/client/AgentPanel.d.ts +5 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +407 -111
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AgentTaskCard.d.ts +12 -0
- package/dist/client/AgentTaskCard.d.ts.map +1 -0
- package/dist/client/AgentTaskCard.js +146 -0
- package/dist/client/AgentTaskCard.js.map +1 -0
- package/dist/client/AssistantChat.d.ts +13 -2
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +344 -122
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts +7 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +345 -63
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/PoweredByBadge.js +2 -2
- package/dist/client/PoweredByBadge.js.map +1 -1
- package/dist/client/Turnstile.d.ts.map +1 -1
- package/dist/client/Turnstile.js +2 -3
- package/dist/client/Turnstile.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +63 -2
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-chat.d.ts +14 -1
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +4 -2
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/components/CodeAgentIndicator.d.ts +14 -0
- package/dist/client/components/CodeAgentIndicator.d.ts.map +1 -0
- package/dist/client/components/CodeAgentIndicator.js +29 -0
- package/dist/client/components/CodeAgentIndicator.js.map +1 -0
- package/dist/client/composer/MentionPopover.d.ts +4 -1
- package/dist/client/composer/MentionPopover.d.ts.map +1 -1
- package/dist/client/composer/MentionPopover.js +36 -6
- package/dist/client/composer/MentionPopover.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts +8 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +146 -16
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/index.d.ts +1 -1
- package/dist/client/composer/index.d.ts.map +1 -1
- package/dist/client/composer/types.d.ts +5 -0
- package/dist/client/composer/types.d.ts.map +1 -1
- package/dist/client/composer/use-mention-search.d.ts.map +1 -1
- package/dist/client/composer/use-mention-search.js +46 -13
- package/dist/client/composer/use-mention-search.js.map +1 -1
- package/dist/client/frame-protocol.d.ts +54 -0
- package/dist/client/frame-protocol.d.ts.map +1 -0
- package/dist/client/frame-protocol.js +9 -0
- package/dist/client/frame-protocol.js.map +1 -0
- package/dist/client/frame.d.ts +56 -0
- package/dist/client/frame.d.ts.map +1 -0
- package/dist/client/{harness.js → frame.js} +49 -26
- package/dist/client/frame.js.map +1 -0
- package/dist/client/index.d.ts +7 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -3
- package/dist/client/index.js.map +1 -1
- package/dist/client/integrations/IntegrationCard.d.ts +6 -0
- package/dist/client/integrations/IntegrationCard.d.ts.map +1 -0
- package/dist/client/integrations/IntegrationCard.js +45 -0
- package/dist/client/integrations/IntegrationCard.js.map +1 -0
- package/dist/client/integrations/IntegrationsPanel.d.ts +2 -0
- package/dist/client/integrations/IntegrationsPanel.d.ts.map +1 -0
- package/dist/client/integrations/IntegrationsPanel.js +149 -0
- package/dist/client/integrations/IntegrationsPanel.js.map +1 -0
- package/dist/client/integrations/index.d.ts +4 -0
- package/dist/client/integrations/index.d.ts.map +1 -0
- package/dist/client/integrations/index.js +3 -0
- package/dist/client/integrations/index.js.map +1 -0
- package/dist/client/integrations/useIntegrationStatus.d.ts +15 -0
- package/dist/client/integrations/useIntegrationStatus.d.ts.map +1 -0
- package/dist/client/integrations/useIntegrationStatus.js +37 -0
- package/dist/client/integrations/useIntegrationStatus.js.map +1 -0
- package/dist/client/org/InvitationBanner.d.ts +9 -0
- package/dist/client/org/InvitationBanner.d.ts.map +1 -0
- package/dist/client/org/InvitationBanner.js +17 -0
- package/dist/client/org/InvitationBanner.js.map +1 -0
- package/dist/client/org/OrgSwitcher.d.ts +14 -0
- package/dist/client/org/OrgSwitcher.d.ts.map +1 -0
- package/dist/client/org/OrgSwitcher.js +51 -0
- package/dist/client/org/OrgSwitcher.js.map +1 -0
- package/dist/client/org/TeamPage.d.ts +23 -0
- package/dist/client/org/TeamPage.d.ts.map +1 -0
- package/dist/client/org/TeamPage.js +145 -0
- package/dist/client/org/TeamPage.js.map +1 -0
- package/dist/client/org/hooks.d.ts +14 -0
- package/dist/client/org/hooks.d.ts.map +1 -0
- package/dist/client/org/hooks.js +101 -0
- package/dist/client/org/hooks.js.map +1 -0
- package/dist/client/org/index.d.ts +6 -0
- package/dist/client/org/index.d.ts.map +1 -0
- package/dist/client/org/index.js +6 -0
- package/dist/client/org/index.js.map +1 -0
- package/dist/client/resources/ResourceEditor.d.ts +8 -1
- package/dist/client/resources/ResourceEditor.d.ts.map +1 -1
- package/dist/client/resources/ResourceEditor.js +94 -13
- package/dist/client/resources/ResourceEditor.js.map +1 -1
- package/dist/client/resources/ResourceTree.d.ts +5 -1
- package/dist/client/resources/ResourceTree.d.ts.map +1 -1
- package/dist/client/resources/ResourceTree.js +18 -3
- package/dist/client/resources/ResourceTree.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +135 -110
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/use-resources.d.ts +10 -0
- package/dist/client/resources/use-resources.d.ts.map +1 -1
- package/dist/client/resources/use-resources.js +2 -2
- package/dist/client/resources/use-resources.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +9 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +36 -3
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/client/terminal/AgentTerminal.d.ts +4 -4
- package/dist/client/terminal/AgentTerminal.d.ts.map +1 -1
- package/dist/client/terminal/AgentTerminal.js +14 -14
- package/dist/client/terminal/AgentTerminal.js.map +1 -1
- package/dist/client/use-action.d.ts +51 -0
- package/dist/client/use-action.d.ts.map +1 -0
- package/dist/client/use-action.js +102 -0
- package/dist/client/use-action.js.map +1 -0
- package/dist/client/use-avatar.d.ts +15 -0
- package/dist/client/use-avatar.d.ts.map +1 -0
- package/dist/client/use-avatar.js +116 -0
- package/dist/client/use-avatar.js.map +1 -0
- package/dist/client/use-chat-threads.d.ts +1 -1
- package/dist/client/use-chat-threads.d.ts.map +1 -1
- package/dist/client/use-chat-threads.js +34 -18
- package/dist/client/use-chat-threads.js.map +1 -1
- package/dist/client/use-dev-mode.d.ts.map +1 -1
- package/dist/client/use-dev-mode.js +2 -0
- package/dist/client/use-dev-mode.js.map +1 -1
- package/dist/client/use-send-to-agent-chat.d.ts +7 -4
- package/dist/client/use-send-to-agent-chat.d.ts.map +1 -1
- package/dist/client/use-send-to-agent-chat.js +31 -10
- package/dist/client/use-send-to-agent-chat.js.map +1 -1
- package/dist/collab/awareness.d.ts +41 -0
- package/dist/collab/awareness.d.ts.map +1 -0
- package/dist/collab/awareness.js +82 -0
- package/dist/collab/awareness.js.map +1 -0
- package/dist/collab/client.d.ts +49 -0
- package/dist/collab/client.d.ts.map +1 -0
- package/dist/collab/client.js +250 -0
- package/dist/collab/client.js.map +1 -0
- package/dist/collab/emitter.d.ts +12 -0
- package/dist/collab/emitter.d.ts.map +1 -0
- package/dist/collab/emitter.js +16 -0
- package/dist/collab/emitter.js.map +1 -0
- package/dist/collab/index.d.ts +7 -0
- package/dist/collab/index.d.ts.map +1 -0
- package/dist/collab/index.js +14 -0
- package/dist/collab/index.js.map +1 -0
- package/dist/collab/routes.d.ts +69 -0
- package/dist/collab/routes.d.ts.map +1 -0
- package/dist/collab/routes.js +98 -0
- package/dist/collab/routes.js.map +1 -0
- package/dist/collab/storage.d.ts +18 -0
- package/dist/collab/storage.d.ts.map +1 -0
- package/dist/collab/storage.js +94 -0
- package/dist/collab/storage.js.map +1 -0
- package/dist/collab/text-to-yjs.d.ts +23 -0
- package/dist/collab/text-to-yjs.d.ts.map +1 -0
- package/dist/collab/text-to-yjs.js +63 -0
- package/dist/collab/text-to-yjs.js.map +1 -0
- package/dist/collab/xml-ops.d.ts +20 -0
- package/dist/collab/xml-ops.d.ts.map +1 -0
- package/dist/collab/xml-ops.js +59 -0
- package/dist/collab/xml-ops.js.map +1 -0
- package/dist/collab/ydoc-manager.d.ts +52 -0
- package/dist/collab/ydoc-manager.d.ts.map +1 -0
- package/dist/collab/ydoc-manager.js +154 -0
- package/dist/collab/ydoc-manager.js.map +1 -0
- package/dist/db/client.d.ts +10 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +43 -2
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts +9 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +45 -20
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/schema.d.ts +8 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +13 -2
- package/dist/db/schema.js.map +1 -1
- package/dist/deploy/build.js +607 -42
- package/dist/deploy/build.js.map +1 -1
- package/dist/deploy/route-discovery.d.ts +17 -4
- package/dist/deploy/route-discovery.d.ts.map +1 -1
- package/dist/deploy/route-discovery.js +117 -35
- package/dist/deploy/route-discovery.js.map +1 -1
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +4 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/integrations/adapters/slack.d.ts +10 -0
- package/dist/integrations/adapters/slack.d.ts.map +1 -0
- package/dist/integrations/adapters/slack.js +215 -0
- package/dist/integrations/adapters/slack.js.map +1 -0
- package/dist/integrations/adapters/telegram.d.ts +12 -0
- package/dist/integrations/adapters/telegram.d.ts.map +1 -0
- package/dist/integrations/adapters/telegram.js +184 -0
- package/dist/integrations/adapters/telegram.js.map +1 -0
- package/dist/integrations/adapters/whatsapp.d.ts +14 -0
- package/dist/integrations/adapters/whatsapp.d.ts.map +1 -0
- package/dist/integrations/adapters/whatsapp.js +205 -0
- package/dist/integrations/adapters/whatsapp.js.map +1 -0
- package/dist/integrations/config-store.d.ts +24 -0
- package/dist/integrations/config-store.d.ts.map +1 -0
- package/dist/integrations/config-store.js +92 -0
- package/dist/integrations/config-store.js.map +1 -0
- package/dist/integrations/index.d.ts +8 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +10 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/plugin.d.ts +20 -0
- package/dist/integrations/plugin.d.ts.map +1 -0
- package/dist/integrations/plugin.js +213 -0
- package/dist/integrations/plugin.js.map +1 -0
- package/dist/integrations/thread-mapping-store.d.ts +25 -0
- package/dist/integrations/thread-mapping-store.d.ts.map +1 -0
- package/dist/integrations/thread-mapping-store.js +95 -0
- package/dist/integrations/thread-mapping-store.js.map +1 -0
- package/dist/integrations/types.d.ts +111 -0
- package/dist/integrations/types.d.ts.map +1 -0
- package/dist/integrations/types.js +2 -0
- package/dist/integrations/types.js.map +1 -0
- package/dist/integrations/webhook-handler.d.ts +31 -0
- package/dist/integrations/webhook-handler.d.ts.map +1 -0
- package/dist/integrations/webhook-handler.js +210 -0
- package/dist/integrations/webhook-handler.js.map +1 -0
- package/dist/jobs/cron.d.ts +14 -0
- package/dist/jobs/cron.d.ts.map +1 -0
- package/dist/jobs/cron.js +100 -0
- package/dist/jobs/cron.js.map +1 -0
- package/dist/jobs/index.d.ts +4 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +4 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/scheduler.d.ts +29 -0
- package/dist/jobs/scheduler.d.ts.map +1 -0
- package/dist/jobs/scheduler.js +205 -0
- package/dist/jobs/scheduler.js.map +1 -0
- package/dist/jobs/tools.d.ts +3 -0
- package/dist/jobs/tools.d.ts.map +1 -0
- package/dist/jobs/tools.js +192 -0
- package/dist/jobs/tools.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +26 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +182 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/oauth-tokens/index.d.ts +1 -1
- package/dist/oauth-tokens/index.d.ts.map +1 -1
- package/dist/oauth-tokens/index.js +1 -1
- package/dist/oauth-tokens/index.js.map +1 -1
- package/dist/oauth-tokens/store.d.ts +5 -0
- package/dist/oauth-tokens/store.d.ts.map +1 -1
- package/dist/oauth-tokens/store.js +30 -7
- package/dist/oauth-tokens/store.js.map +1 -1
- package/dist/org/context.d.ts +11 -0
- package/dist/org/context.d.ts.map +1 -0
- package/dist/org/context.js +61 -0
- package/dist/org/context.js.map +1 -0
- package/dist/org/handlers.d.ts +66 -0
- package/dist/org/handlers.d.ts.map +1 -0
- package/dist/org/handlers.js +306 -0
- package/dist/org/handlers.js.map +1 -0
- package/dist/org/index.d.ts +7 -0
- package/dist/org/index.d.ts.map +1 -0
- package/dist/org/index.js +11 -0
- package/dist/org/index.js.map +1 -0
- package/dist/org/migrations.d.ts +10 -0
- package/dist/org/migrations.d.ts.map +1 -0
- package/dist/org/migrations.js +39 -0
- package/dist/org/migrations.js.map +1 -0
- package/dist/org/plugin.d.ts +26 -0
- package/dist/org/plugin.d.ts.map +1 -0
- package/dist/org/plugin.js +94 -0
- package/dist/org/plugin.js.map +1 -0
- package/dist/org/schema.d.ts +301 -0
- package/dist/org/schema.d.ts.map +1 -0
- package/dist/org/schema.js +23 -0
- package/dist/org/schema.js.map +1 -0
- package/dist/org/types.d.ts +42 -0
- package/dist/org/types.d.ts.map +1 -0
- package/dist/org/types.js +5 -0
- package/dist/org/types.js.map +1 -0
- package/dist/resources/handlers.d.ts +10 -1
- package/dist/resources/handlers.d.ts.map +1 -1
- package/dist/resources/handlers.js +82 -9
- package/dist/resources/handlers.js.map +1 -1
- package/dist/resources/store.d.ts +5 -0
- package/dist/resources/store.d.ts.map +1 -1
- package/dist/resources/store.js +44 -0
- package/dist/resources/store.js.map +1 -1
- package/dist/scripts/agent-engines/list-agent-engines.d.ts +7 -0
- package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -0
- package/dist/scripts/agent-engines/list-agent-engines.js +42 -0
- package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -0
- package/dist/scripts/agent-engines/set-agent-engine.d.ts +7 -0
- package/dist/scripts/agent-engines/set-agent-engine.d.ts.map +1 -0
- package/dist/scripts/agent-engines/set-agent-engine.js +57 -0
- package/dist/scripts/agent-engines/set-agent-engine.js.map +1 -0
- package/dist/scripts/agent-engines/test-agent-engine.d.ts +7 -0
- package/dist/scripts/agent-engines/test-agent-engine.d.ts.map +1 -0
- package/dist/scripts/agent-engines/test-agent-engine.js +102 -0
- package/dist/scripts/agent-engines/test-agent-engine.js.map +1 -0
- package/dist/scripts/call-agent.d.ts +1 -1
- package/dist/scripts/call-agent.d.ts.map +1 -1
- package/dist/scripts/call-agent.js +10 -6
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/scripts/chat/index.d.ts +2 -0
- package/dist/scripts/chat/index.d.ts.map +1 -0
- package/dist/scripts/chat/index.js +5 -0
- package/dist/scripts/chat/index.js.map +1 -0
- package/dist/scripts/chat/open-chat.d.ts +11 -0
- package/dist/scripts/chat/open-chat.d.ts.map +1 -0
- package/dist/scripts/chat/open-chat.js +48 -0
- package/dist/scripts/chat/open-chat.js.map +1 -0
- package/dist/scripts/chat/search-chats.d.ts +10 -0
- package/dist/scripts/chat/search-chats.d.ts.map +1 -0
- package/dist/scripts/chat/search-chats.js +89 -0
- package/dist/scripts/chat/search-chats.js.map +1 -0
- package/dist/scripts/core-scripts.d.ts.map +1 -1
- package/dist/scripts/core-scripts.js +2 -0
- package/dist/scripts/core-scripts.js.map +1 -1
- package/dist/scripts/db/check-scoping.d.ts +14 -0
- package/dist/scripts/db/check-scoping.d.ts.map +1 -0
- package/dist/scripts/db/check-scoping.js +174 -0
- package/dist/scripts/db/check-scoping.js.map +1 -0
- package/dist/scripts/db/exec.d.ts +3 -2
- package/dist/scripts/db/exec.d.ts.map +1 -1
- package/dist/scripts/db/exec.js +35 -19
- package/dist/scripts/db/exec.js.map +1 -1
- package/dist/scripts/db/index.d.ts.map +1 -1
- package/dist/scripts/db/index.js +2 -0
- package/dist/scripts/db/index.js.map +1 -1
- package/dist/scripts/db/patch.d.ts +50 -0
- package/dist/scripts/db/patch.d.ts.map +1 -0
- package/dist/scripts/db/patch.js +392 -0
- package/dist/scripts/db/patch.js.map +1 -0
- package/dist/scripts/db/scoping.d.ts +8 -2
- package/dist/scripts/db/scoping.d.ts.map +1 -1
- package/dist/scripts/db/scoping.js +64 -46
- package/dist/scripts/db/scoping.js.map +1 -1
- package/dist/scripts/dev/index.d.ts.map +1 -1
- package/dist/scripts/dev/index.js +64 -1
- package/dist/scripts/dev/index.js.map +1 -1
- package/dist/scripts/parse-args.d.ts +14 -0
- package/dist/scripts/parse-args.d.ts.map +1 -0
- package/dist/scripts/parse-args.js +45 -0
- package/dist/scripts/parse-args.js.map +1 -0
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +10 -2
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/utils.d.ts +1 -9
- package/dist/scripts/utils.d.ts.map +1 -1
- package/dist/scripts/utils.js +2 -40
- package/dist/scripts/utils.js.map +1 -1
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +84 -16
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/action-routes.d.ts +15 -0
- package/dist/server/action-routes.d.ts.map +1 -0
- package/dist/server/action-routes.js +105 -0
- package/dist/server/action-routes.js.map +1 -0
- package/dist/server/agent-chat-plugin.d.ts +20 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +1149 -256
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-discovery.d.ts +8 -3
- package/dist/server/agent-discovery.d.ts.map +1 -1
- package/dist/server/agent-discovery.js +69 -8
- package/dist/server/agent-discovery.js.map +1 -1
- package/dist/server/agent-teams.d.ts +70 -0
- package/dist/server/agent-teams.d.ts.map +1 -0
- package/dist/server/agent-teams.js +367 -0
- package/dist/server/agent-teams.js.map +1 -0
- package/dist/server/agents-bundle.d.ts +87 -0
- package/dist/server/agents-bundle.d.ts.map +1 -0
- package/dist/server/agents-bundle.js +231 -0
- package/dist/server/agents-bundle.js.map +1 -0
- package/dist/server/auth-plugin.d.ts +3 -3
- package/dist/server/auth-plugin.d.ts.map +1 -1
- package/dist/server/auth-plugin.js +9 -10
- package/dist/server/auth-plugin.js.map +1 -1
- package/dist/server/auth.d.ts +54 -33
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +529 -611
- package/dist/server/auth.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts +72 -0
- package/dist/server/better-auth-instance.d.ts.map +1 -0
- package/dist/server/better-auth-instance.js +144 -0
- package/dist/server/better-auth-instance.js.map +1 -0
- package/dist/server/collab-plugin.d.ts +29 -0
- package/dist/server/collab-plugin.d.ts.map +1 -0
- package/dist/server/collab-plugin.js +85 -0
- package/dist/server/collab-plugin.js.map +1 -0
- package/dist/server/core-routes-plugin.d.ts +0 -3
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +97 -27
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/create-server.d.ts +1 -1
- package/dist/server/create-server.d.ts.map +1 -1
- package/dist/server/create-server.js +39 -16
- package/dist/server/create-server.js.map +1 -1
- package/dist/server/framework-request-handler.d.ts +47 -0
- package/dist/server/framework-request-handler.d.ts.map +1 -0
- package/dist/server/framework-request-handler.js +168 -0
- package/dist/server/framework-request-handler.js.map +1 -0
- package/dist/server/google-auth-plugin.d.ts +4 -0
- package/dist/server/google-auth-plugin.d.ts.map +1 -1
- package/dist/server/google-auth-plugin.js +13 -12
- package/dist/server/google-auth-plugin.js.map +1 -1
- package/dist/server/google-oauth.d.ts +3 -3
- package/dist/server/google-oauth.d.ts.map +1 -1
- package/dist/server/google-oauth.js +40 -18
- package/dist/server/google-oauth.js.map +1 -1
- package/dist/server/h3-helpers.d.ts +23 -0
- package/dist/server/h3-helpers.d.ts.map +1 -0
- package/dist/server/h3-helpers.js +37 -0
- package/dist/server/h3-helpers.js.map +1 -0
- package/dist/server/index.d.ts +9 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +12 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/local-migration.d.ts +32 -0
- package/dist/server/local-migration.d.ts.map +1 -0
- package/dist/server/local-migration.js +205 -0
- package/dist/server/local-migration.js.map +1 -0
- package/dist/server/oauth-helpers.d.ts +4 -6
- package/dist/server/oauth-helpers.d.ts.map +1 -1
- package/dist/server/oauth-helpers.js +6 -8
- package/dist/server/oauth-helpers.js.map +1 -1
- package/dist/server/onboarding-html.d.ts +24 -0
- package/dist/server/onboarding-html.d.ts.map +1 -0
- package/dist/server/onboarding-html.js +347 -0
- package/dist/server/onboarding-html.js.map +1 -0
- package/dist/server/poll.d.ts +7 -2
- package/dist/server/poll.d.ts.map +1 -1
- package/dist/server/poll.js +48 -1
- package/dist/server/poll.js.map +1 -1
- package/dist/server/resources-plugin.d.ts.map +1 -1
- package/dist/server/resources-plugin.js +4 -3
- package/dist/server/resources-plugin.js.map +1 -1
- package/dist/server/schema-prompt.d.ts +16 -0
- package/dist/server/schema-prompt.d.ts.map +1 -0
- package/dist/server/schema-prompt.js +275 -0
- package/dist/server/schema-prompt.js.map +1 -0
- package/dist/server/sse.d.ts +3 -20
- package/dist/server/sse.d.ts.map +1 -1
- package/dist/server/sse.js +1 -29
- package/dist/server/sse.js.map +1 -1
- package/dist/server/ssr-handler.d.ts +6 -0
- package/dist/server/ssr-handler.d.ts.map +1 -0
- package/dist/server/ssr-handler.js +55 -0
- package/dist/server/ssr-handler.js.map +1 -0
- package/dist/settings/handlers.d.ts +3 -3
- package/dist/settings/handlers.d.ts.map +1 -1
- package/dist/settings/handlers.js +2 -1
- package/dist/settings/handlers.js.map +1 -1
- package/dist/settings/index.d.ts +1 -0
- package/dist/settings/index.d.ts.map +1 -1
- package/dist/settings/index.js +2 -0
- package/dist/settings/index.js.map +1 -1
- package/dist/settings/org-settings.d.ts +22 -0
- package/dist/settings/org-settings.d.ts.map +1 -0
- package/dist/settings/org-settings.js +45 -0
- package/dist/settings/org-settings.js.map +1 -0
- package/dist/shared/agent-chat.d.ts +5 -5
- package/dist/shared/agent-chat.d.ts.map +1 -1
- package/dist/shared/agent-chat.js +8 -8
- package/dist/shared/agent-chat.js.map +1 -1
- package/dist/shared/agent-env.d.ts +1 -1
- package/dist/shared/agent-env.js +1 -1
- package/dist/shared/runtime.d.ts +14 -0
- package/dist/shared/runtime.d.ts.map +1 -0
- package/dist/shared/runtime.js +25 -0
- package/dist/shared/runtime.js.map +1 -0
- package/dist/templates/default/.agents/skills/actions/SKILL.md +142 -0
- package/dist/templates/default/.agents/skills/agent-engines/SKILL.md +127 -0
- package/dist/templates/default/.agents/skills/capture-learnings/SKILL.md +50 -0
- package/dist/templates/default/.agents/skills/create-skill/SKILL.md +167 -0
- package/dist/templates/default/.agents/skills/delegate-to-agent/SKILL.md +90 -0
- package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +69 -0
- package/dist/templates/default/.agents/skills/real-time-collab/SKILL.md +183 -0
- package/dist/templates/default/.agents/skills/real-time-sync/SKILL.md +112 -0
- package/dist/templates/default/.agents/skills/security/SKILL.md +108 -0
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +79 -0
- package/dist/templates/default/.claude/settings.json +100 -0
- package/dist/templates/default/.env.example +5 -0
- package/dist/templates/default/.prettierrc +5 -0
- package/dist/templates/default/AGENTS.md +110 -0
- package/dist/templates/default/DEVELOPING.md +117 -0
- package/dist/templates/default/_gitignore +37 -0
- package/dist/templates/default/actions/hello.ts +20 -0
- package/dist/templates/default/actions/navigate.ts +53 -0
- package/dist/templates/default/actions/run.ts +2 -0
- package/dist/templates/default/actions/view-screen.ts +39 -0
- package/dist/templates/default/app/entry.client.tsx +4 -0
- package/dist/templates/default/app/entry.server.tsx +56 -0
- package/dist/templates/default/app/global.css +95 -0
- package/dist/templates/default/app/lib/utils.ts +1 -0
- package/dist/templates/default/app/root.tsx +107 -0
- package/dist/templates/default/app/routes/_index.tsx +62 -0
- package/dist/templates/default/app/routes.ts +4 -0
- package/dist/templates/default/app/vite-env.d.ts +6 -0
- package/dist/templates/default/components.json +20 -0
- package/dist/templates/default/data/.gitkeep +0 -0
- package/dist/templates/default/data/sync-config.json +1 -0
- package/dist/templates/default/learnings.defaults.md +5 -0
- package/dist/templates/default/learnings.md +0 -0
- package/dist/templates/default/package.json +46 -0
- package/dist/templates/default/postcss.config.js +6 -0
- package/dist/templates/default/public/icon-180.svg +4 -0
- package/dist/templates/default/public/icon-192.svg +4 -0
- package/dist/templates/default/public/icon-512.svg +4 -0
- package/dist/templates/default/public/manifest.json +13 -0
- package/dist/templates/default/react-router.config.ts +6 -0
- package/dist/templates/default/server/middleware/auth.ts +15 -0
- package/dist/templates/default/server/plugins/.gitkeep +0 -0
- package/dist/templates/default/server/routes/[...page].get.ts +5 -0
- package/dist/templates/default/server/routes/api/hello.get.ts +5 -0
- package/dist/templates/default/shared/api.ts +6 -0
- package/dist/templates/default/ssr-entry.ts +20 -0
- package/dist/templates/default/tailwind.config.ts +7 -0
- package/dist/templates/default/tsconfig.json +11 -0
- package/dist/templates/default/vite.config.ts +6 -0
- package/dist/templates/templates/default/.agents/skills/actions/SKILL.md +142 -0
- package/dist/templates/templates/default/.agents/skills/agent-engines/SKILL.md +127 -0
- package/dist/templates/templates/default/.agents/skills/capture-learnings/SKILL.md +50 -0
- package/dist/templates/templates/default/.agents/skills/create-skill/SKILL.md +167 -0
- package/dist/templates/templates/default/.agents/skills/delegate-to-agent/SKILL.md +90 -0
- package/dist/templates/templates/default/.agents/skills/frontend-design/SKILL.md +69 -0
- package/dist/templates/templates/default/.agents/skills/real-time-collab/SKILL.md +183 -0
- package/dist/templates/templates/default/.agents/skills/real-time-sync/SKILL.md +112 -0
- package/dist/templates/templates/default/.agents/skills/security/SKILL.md +108 -0
- package/dist/templates/templates/default/.agents/skills/self-modifying-code/SKILL.md +79 -0
- package/dist/templates/templates/default/.agents/skills/storing-data/SKILL.md +110 -0
- package/dist/templates/templates/default/.claude/settings.json +100 -0
- package/dist/templates/templates/default/.env.example +5 -0
- package/dist/templates/templates/default/.ignore +0 -0
- package/dist/templates/templates/default/.prettierrc +5 -0
- package/dist/templates/templates/default/AGENTS.md +110 -0
- package/dist/templates/templates/default/DEVELOPING.md +117 -0
- package/dist/templates/templates/default/_gitignore +37 -0
- package/dist/templates/templates/default/actions/hello.ts +20 -0
- package/dist/templates/templates/default/actions/navigate.ts +53 -0
- package/dist/templates/templates/default/actions/run.ts +2 -0
- package/dist/templates/templates/default/actions/view-screen.ts +39 -0
- package/dist/templates/templates/default/app/entry.client.tsx +4 -0
- package/dist/templates/templates/default/app/entry.server.tsx +56 -0
- package/dist/templates/templates/default/app/global.css +95 -0
- package/dist/templates/templates/default/app/lib/utils.ts +1 -0
- package/dist/templates/templates/default/app/root.tsx +107 -0
- package/dist/templates/templates/default/app/routes/_index.tsx +62 -0
- package/dist/templates/templates/default/app/routes.ts +4 -0
- package/dist/templates/templates/default/app/vite-env.d.ts +6 -0
- package/dist/templates/templates/default/components.json +20 -0
- package/dist/templates/templates/default/data/.gitkeep +0 -0
- package/dist/templates/templates/default/data/sync-config.json +1 -0
- package/dist/templates/templates/default/learnings.defaults.md +5 -0
- package/dist/templates/templates/default/learnings.md +0 -0
- package/dist/templates/templates/default/package.json +46 -0
- package/dist/templates/templates/default/postcss.config.js +6 -0
- package/dist/templates/templates/default/public/icon-180.svg +4 -0
- package/dist/templates/templates/default/public/icon-192.svg +4 -0
- package/dist/templates/templates/default/public/icon-512.svg +4 -0
- package/dist/templates/templates/default/public/manifest.json +13 -0
- package/dist/templates/templates/default/react-router.config.ts +6 -0
- package/dist/templates/templates/default/server/middleware/auth.ts +15 -0
- package/dist/templates/templates/default/server/plugins/.gitkeep +0 -0
- package/dist/templates/templates/default/server/routes/[...page].get.ts +5 -0
- package/dist/templates/templates/default/server/routes/api/hello.get.ts +5 -0
- package/dist/templates/templates/default/shared/api.ts +6 -0
- package/dist/templates/templates/default/ssr-entry.ts +20 -0
- package/dist/templates/templates/default/tailwind.config.ts +7 -0
- package/dist/templates/templates/default/tsconfig.json +11 -0
- package/dist/templates/templates/default/vite.config.ts +6 -0
- package/dist/terminal/cli-registry.d.ts +1 -1
- package/dist/terminal/cli-registry.d.ts.map +1 -1
- package/dist/terminal/cli-registry.js +7 -7
- package/dist/terminal/cli-registry.js.map +1 -1
- package/dist/terminal/pty-server.d.ts +1 -1
- package/dist/terminal/pty-server.d.ts.map +1 -1
- package/dist/terminal/pty-server.js +34 -12
- package/dist/terminal/pty-server.js.map +1 -1
- package/dist/terminal/terminal-plugin.d.ts +0 -9
- package/dist/terminal/terminal-plugin.d.ts.map +1 -1
- package/dist/terminal/terminal-plugin.js +57 -14
- package/dist/terminal/terminal-plugin.js.map +1 -1
- package/dist/usage/store.d.ts +29 -0
- package/dist/usage/store.d.ts.map +1 -0
- package/dist/usage/store.js +102 -0
- package/dist/usage/store.js.map +1 -0
- package/dist/vite/action-types-plugin.d.ts +13 -0
- package/dist/vite/action-types-plugin.d.ts.map +1 -0
- package/dist/vite/action-types-plugin.js +132 -0
- package/dist/vite/action-types-plugin.js.map +1 -0
- package/dist/vite/agents-bundle-plugin.d.ts +3 -0
- package/dist/vite/agents-bundle-plugin.d.ts.map +1 -0
- package/dist/vite/agents-bundle-plugin.js +87 -0
- package/dist/vite/agents-bundle-plugin.js.map +1 -0
- package/dist/vite/client.d.ts +5 -0
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +222 -37
- package/dist/vite/client.js.map +1 -1
- package/dist/vite/index.d.ts +2 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +2 -1
- package/dist/vite/index.js.map +1 -1
- package/package.json +68 -20
- package/src/templates/default/.agents/skills/actions/SKILL.md +12 -6
- package/src/templates/default/.agents/skills/agent-engines/SKILL.md +127 -0
- package/src/templates/default/.agents/skills/real-time-collab/SKILL.md +183 -0
- package/src/templates/default/.agents/skills/security/SKILL.md +108 -0
- package/src/templates/default/.agents/skills/storing-data/SKILL.md +110 -0
- package/src/templates/default/.claude/settings.json +13 -0
- package/src/templates/default/AGENTS.md +25 -9
- package/src/templates/default/actions/view-screen.ts +1 -1
- package/src/templates/default/package.json +2 -2
- package/src/templates/default/server/middleware/auth.ts +15 -0
- package/src/templates/default/server/routes/[...page].get.ts +2 -9
- package/src/templates/default/ssr-entry.ts +20 -0
- package/dist/adapters/convex/adapter.d.ts +0 -24
- package/dist/adapters/convex/adapter.d.ts.map +0 -1
- package/dist/adapters/convex/adapter.js +0 -125
- package/dist/adapters/convex/adapter.js.map +0 -1
- package/dist/adapters/convex/index.d.ts +0 -4
- package/dist/adapters/convex/index.d.ts.map +0 -1
- package/dist/adapters/convex/index.js +0 -3
- package/dist/adapters/convex/index.js.map +0 -1
- package/dist/adapters/drizzle/adapter.d.ts +0 -36
- package/dist/adapters/drizzle/adapter.d.ts.map +0 -1
- package/dist/adapters/drizzle/adapter.js +0 -210
- package/dist/adapters/drizzle/adapter.js.map +0 -1
- package/dist/adapters/drizzle/index.d.ts +0 -3
- package/dist/adapters/drizzle/index.d.ts.map +0 -1
- package/dist/adapters/drizzle/index.js +0 -3
- package/dist/adapters/drizzle/index.js.map +0 -1
- package/dist/adapters/drizzle/schema.d.ts +0 -146
- package/dist/adapters/drizzle/schema.d.ts.map +0 -1
- package/dist/adapters/drizzle/schema.js +0 -20
- package/dist/adapters/drizzle/schema.js.map +0 -1
- package/dist/adapters/firestore/adapter.d.ts +0 -48
- package/dist/adapters/firestore/adapter.d.ts.map +0 -1
- package/dist/adapters/firestore/adapter.js +0 -62
- package/dist/adapters/firestore/adapter.js.map +0 -1
- package/dist/adapters/firestore/index.d.ts +0 -4
- package/dist/adapters/firestore/index.d.ts.map +0 -1
- package/dist/adapters/firestore/index.js +0 -3
- package/dist/adapters/firestore/index.js.map +0 -1
- package/dist/adapters/supabase/adapter.d.ts +0 -43
- package/dist/adapters/supabase/adapter.d.ts.map +0 -1
- package/dist/adapters/supabase/adapter.js +0 -137
- package/dist/adapters/supabase/adapter.js.map +0 -1
- package/dist/adapters/supabase/index.d.ts +0 -3
- package/dist/adapters/supabase/index.d.ts.map +0 -1
- package/dist/adapters/supabase/index.js +0 -3
- package/dist/adapters/supabase/index.js.map +0 -1
- package/dist/adapters/sync/config.d.ts +0 -40
- package/dist/adapters/sync/config.d.ts.map +0 -1
- package/dist/adapters/sync/config.js +0 -209
- package/dist/adapters/sync/config.js.map +0 -1
- package/dist/adapters/sync/create-file-sync.d.ts +0 -32
- package/dist/adapters/sync/create-file-sync.d.ts.map +0 -1
- package/dist/adapters/sync/create-file-sync.js +0 -218
- package/dist/adapters/sync/create-file-sync.js.map +0 -1
- package/dist/adapters/sync/file-sync.d.ts +0 -94
- package/dist/adapters/sync/file-sync.d.ts.map +0 -1
- package/dist/adapters/sync/file-sync.js +0 -671
- package/dist/adapters/sync/file-sync.js.map +0 -1
- package/dist/adapters/sync/index.d.ts +0 -6
- package/dist/adapters/sync/index.d.ts.map +0 -1
- package/dist/adapters/sync/index.js +0 -6
- package/dist/adapters/sync/index.js.map +0 -1
- package/dist/adapters/sync/merge.d.ts +0 -21
- package/dist/adapters/sync/merge.d.ts.map +0 -1
- package/dist/adapters/sync/merge.js +0 -132
- package/dist/adapters/sync/merge.js.map +0 -1
- package/dist/adapters/sync/types.d.ts +0 -62
- package/dist/adapters/sync/types.d.ts.map +0 -1
- package/dist/adapters/sync/types.js +0 -23
- package/dist/adapters/sync/types.js.map +0 -1
- package/dist/client/harness.d.ts +0 -48
- package/dist/client/harness.d.ts.map +0 -1
- package/dist/client/harness.js.map +0 -1
- package/dist/client/use-file-sync-status.d.ts +0 -21
- package/dist/client/use-file-sync-status.d.ts.map +0 -1
- package/dist/client/use-file-sync-status.js +0 -65
- package/dist/client/use-file-sync-status.js.map +0 -1
- package/dist/server/default-watcher.d.ts +0 -23
- package/dist/server/default-watcher.d.ts.map +0 -1
- package/dist/server/default-watcher.js +0 -57
- package/dist/server/default-watcher.js.map +0 -1
- package/dist/server/file-sync-plugin.d.ts +0 -7
- package/dist/server/file-sync-plugin.d.ts.map +0 -1
- package/dist/server/file-sync-plugin.js +0 -38
- package/dist/server/file-sync-plugin.js.map +0 -1
- package/dist/vite/dev-api-server.d.ts +0 -10
- package/dist/vite/dev-api-server.d.ts.map +0 -1
- package/dist/vite/dev-api-server.js +0 -243
- package/dist/vite/dev-api-server.js.map +0 -1
- /package/{src/templates/default/.agents/skills/files-as-database → dist/templates/default/.agents/skills/storing-data}/SKILL.md +0 -0
- /package/{src/templates/default/application-state/.gitkeep → dist/templates/default/.ignore} +0 -0
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getH3App } from "./framework-request-handler.js";
|
|
2
|
+
import { createProductionAgentHandler, runAgentLoop, actionsToEngineTools, getActiveRunForThreadAsync, abortRun, subscribeToRun, } from "../agent/production-agent.js";
|
|
3
|
+
import { resolveEngine, createAnthropicEngine } from "../agent/engine/index.js";
|
|
4
|
+
import { discoverAgents } from "./agent-discovery.js";
|
|
5
|
+
import { loadSchemaPromptBlock } from "./schema-prompt.js";
|
|
2
6
|
import { buildAssistantMessage, extractThreadMeta, } from "../agent/thread-data-builder.js";
|
|
3
|
-
import { defineEventHandler,
|
|
7
|
+
import { defineEventHandler, setResponseStatus, setResponseHeader, getMethod, getQuery, } from "h3";
|
|
4
8
|
import { getSession } from "./auth.js";
|
|
5
9
|
import { createThread, getThread, listThreads, searchThreads, updateThreadData, deleteThread, } from "../chat-threads/store.js";
|
|
6
10
|
import { resourceListAccessible, resourceList, resourceGet, resourceGetByPath, ensurePersonalDefaults, SHARED_OWNER, } from "../resources/store.js";
|
|
7
|
-
import fs from "node:fs";
|
|
8
11
|
import nodePath from "node:path";
|
|
12
|
+
import { readBody } from "./h3-helpers.js";
|
|
13
|
+
// Lazy fs — loaded via dynamic import() on first use.
|
|
14
|
+
// This avoids require() which bundlers convert to createRequire(import.meta.url)
|
|
15
|
+
// that crashes on CF Workers where import.meta.url is undefined.
|
|
16
|
+
let _fs;
|
|
17
|
+
async function lazyFs() {
|
|
18
|
+
if (!_fs) {
|
|
19
|
+
_fs = await import("node:fs");
|
|
20
|
+
}
|
|
21
|
+
return _fs;
|
|
22
|
+
}
|
|
9
23
|
/**
|
|
10
24
|
* Wraps a core CLI script (that writes to console.log) as a ActionEntry
|
|
11
25
|
* by capturing stdout.
|
|
@@ -157,16 +171,88 @@ async function createResourceScriptEntries() {
|
|
|
157
171
|
return {};
|
|
158
172
|
}
|
|
159
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Creates chat management ActionEntries (search-chats, open-chat).
|
|
176
|
+
*/
|
|
177
|
+
async function createChatScriptEntries() {
|
|
178
|
+
try {
|
|
179
|
+
const [searchMod, openMod] = await Promise.all([
|
|
180
|
+
import("../scripts/chat/search-chats.js"),
|
|
181
|
+
import("../scripts/chat/open-chat.js"),
|
|
182
|
+
]);
|
|
183
|
+
return {
|
|
184
|
+
"search-chats": wrapCliScript({
|
|
185
|
+
description: "Search or list past agent chat threads. Use this to find previous conversations by keyword.",
|
|
186
|
+
parameters: {
|
|
187
|
+
type: "object",
|
|
188
|
+
properties: {
|
|
189
|
+
query: {
|
|
190
|
+
type: "string",
|
|
191
|
+
description: "Search term to find chats by title, preview, or content",
|
|
192
|
+
},
|
|
193
|
+
limit: {
|
|
194
|
+
type: "string",
|
|
195
|
+
description: "Max number of results (default: 20)",
|
|
196
|
+
},
|
|
197
|
+
format: {
|
|
198
|
+
type: "string",
|
|
199
|
+
description: "Output format",
|
|
200
|
+
enum: ["json", "text"],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
}, searchMod.default),
|
|
205
|
+
"open-chat": wrapCliScript({
|
|
206
|
+
description: "Open a chat thread in the UI as a new tab and focus it. Use search-chats first to find the thread ID.",
|
|
207
|
+
parameters: {
|
|
208
|
+
type: "object",
|
|
209
|
+
properties: {
|
|
210
|
+
id: {
|
|
211
|
+
type: "string",
|
|
212
|
+
description: "The chat thread ID to open",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
required: ["id"],
|
|
216
|
+
},
|
|
217
|
+
}, openMod.default),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Creates agent engine management tools (list-agent-engines, set-agent-engine,
|
|
226
|
+
* test-agent-engine). Let the agent inspect and configure the active LLM engine.
|
|
227
|
+
*/
|
|
228
|
+
async function createAgentEngineScriptEntries() {
|
|
229
|
+
try {
|
|
230
|
+
const [listMod, setMod, testMod] = await Promise.all([
|
|
231
|
+
import("../scripts/agent-engines/list-agent-engines.js"),
|
|
232
|
+
import("../scripts/agent-engines/set-agent-engine.js"),
|
|
233
|
+
import("../scripts/agent-engines/test-agent-engine.js"),
|
|
234
|
+
]);
|
|
235
|
+
return {
|
|
236
|
+
"list-agent-engines": { tool: listMod.tool, run: listMod.run },
|
|
237
|
+
"set-agent-engine": { tool: setMod.tool, run: setMod.run },
|
|
238
|
+
"test-agent-engine": { tool: testMod.tool, run: testMod.run },
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return {};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
160
245
|
/**
|
|
161
246
|
* Creates the call-agent ActionEntry for cross-agent A2A communication.
|
|
247
|
+
* Binds selfAppId so the agent cannot call itself via call-agent.
|
|
162
248
|
*/
|
|
163
|
-
async function createCallAgentScriptEntry() {
|
|
249
|
+
async function createCallAgentScriptEntry(selfAppId) {
|
|
164
250
|
try {
|
|
165
251
|
const mod = await import("../scripts/call-agent.js");
|
|
166
252
|
return {
|
|
167
253
|
"call-agent": {
|
|
168
254
|
tool: mod.tool,
|
|
169
|
-
run: mod.run,
|
|
255
|
+
run: (args, context) => mod.run(args, context, selfAppId),
|
|
170
256
|
},
|
|
171
257
|
};
|
|
172
258
|
}
|
|
@@ -174,6 +260,185 @@ async function createCallAgentScriptEntry() {
|
|
|
174
260
|
return {};
|
|
175
261
|
}
|
|
176
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Creates agent team orchestration tools (spawn-task, task-status, read-task-result).
|
|
265
|
+
* These let the main agent spawn sub-agents and coordinate work.
|
|
266
|
+
*/
|
|
267
|
+
function createTeamTools(deps) {
|
|
268
|
+
return {
|
|
269
|
+
"spawn-task": {
|
|
270
|
+
tool: {
|
|
271
|
+
description: "Spawn a sub-agent to handle a task in the background. The sub-agent runs independently with its own conversation thread. Use this to delegate work so the main chat stays free for new requests. A live preview card will appear in the chat showing the sub-agent's progress.",
|
|
272
|
+
parameters: {
|
|
273
|
+
type: "object",
|
|
274
|
+
properties: {
|
|
275
|
+
task: {
|
|
276
|
+
type: "string",
|
|
277
|
+
description: "Clear description of what the sub-agent should accomplish",
|
|
278
|
+
},
|
|
279
|
+
instructions: {
|
|
280
|
+
type: "string",
|
|
281
|
+
description: "Optional additional instructions or context for the sub-agent",
|
|
282
|
+
},
|
|
283
|
+
name: {
|
|
284
|
+
type: "string",
|
|
285
|
+
description: "Short name for the sub-agent tab (e.g. 'Research', 'Draft email'). If omitted, derived from the task.",
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
required: ["task"],
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
run: async (args) => {
|
|
292
|
+
// Capture the send function NOW (at spawn time) so that
|
|
293
|
+
// concurrent runs don't clobber each other's send reference.
|
|
294
|
+
const capturedSend = deps.getSend();
|
|
295
|
+
const { spawnTask } = await import("./agent-teams.js");
|
|
296
|
+
// Filter out team orchestration tools so sub-agents can't spawn sub-agents
|
|
297
|
+
const teamToolNames = new Set([
|
|
298
|
+
"spawn-task",
|
|
299
|
+
"task-status",
|
|
300
|
+
"read-task-result",
|
|
301
|
+
"send-to-task",
|
|
302
|
+
"list-tasks",
|
|
303
|
+
]);
|
|
304
|
+
const subAgentActions = Object.fromEntries(Object.entries(deps.getActions()).filter(([name]) => !teamToolNames.has(name)));
|
|
305
|
+
const task = await spawnTask({
|
|
306
|
+
description: args.task,
|
|
307
|
+
instructions: args.instructions,
|
|
308
|
+
ownerEmail: deps.getOwner(),
|
|
309
|
+
systemPrompt: deps.getSystemPrompt(),
|
|
310
|
+
actions: subAgentActions,
|
|
311
|
+
engine: deps.getEngine(),
|
|
312
|
+
model: deps.getModel(),
|
|
313
|
+
parentThreadId: deps.getParentThreadId(),
|
|
314
|
+
parentSend: (event) => {
|
|
315
|
+
if (capturedSend)
|
|
316
|
+
capturedSend(event);
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
return JSON.stringify({
|
|
320
|
+
taskId: task.taskId,
|
|
321
|
+
threadId: task.threadId,
|
|
322
|
+
status: task.status,
|
|
323
|
+
description: task.description,
|
|
324
|
+
name: args.name || "",
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
"task-status": {
|
|
329
|
+
tool: {
|
|
330
|
+
description: "Check the status of a sub-agent task. Returns current status, preview of output, and current step.",
|
|
331
|
+
parameters: {
|
|
332
|
+
type: "object",
|
|
333
|
+
properties: {
|
|
334
|
+
taskId: {
|
|
335
|
+
type: "string",
|
|
336
|
+
description: "The task ID returned by spawn-task",
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
required: ["taskId"],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
run: async (args) => {
|
|
343
|
+
const { getTask } = await import("./agent-teams.js");
|
|
344
|
+
const task = await getTask(args.taskId);
|
|
345
|
+
if (!task)
|
|
346
|
+
return JSON.stringify({ error: "Task not found" });
|
|
347
|
+
return JSON.stringify({
|
|
348
|
+
taskId: task.taskId,
|
|
349
|
+
threadId: task.threadId,
|
|
350
|
+
status: task.status,
|
|
351
|
+
description: task.description,
|
|
352
|
+
preview: task.preview,
|
|
353
|
+
currentStep: task.currentStep,
|
|
354
|
+
summary: task.summary,
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
"read-task-result": {
|
|
359
|
+
tool: {
|
|
360
|
+
description: "Read the result of a completed sub-agent task. Returns the full output summary.",
|
|
361
|
+
parameters: {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
taskId: {
|
|
365
|
+
type: "string",
|
|
366
|
+
description: "The task ID returned by spawn-task",
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
required: ["taskId"],
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
run: async (args) => {
|
|
373
|
+
const { getTask } = await import("./agent-teams.js");
|
|
374
|
+
const task = await getTask(args.taskId);
|
|
375
|
+
if (!task)
|
|
376
|
+
return JSON.stringify({ error: "Task not found" });
|
|
377
|
+
if (task.status === "running") {
|
|
378
|
+
return JSON.stringify({
|
|
379
|
+
status: "running",
|
|
380
|
+
preview: task.preview,
|
|
381
|
+
message: "Task is still running. Check back later.",
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
return JSON.stringify({
|
|
385
|
+
taskId: task.taskId,
|
|
386
|
+
status: task.status,
|
|
387
|
+
summary: task.summary,
|
|
388
|
+
preview: task.preview,
|
|
389
|
+
});
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
"send-to-task": {
|
|
393
|
+
tool: {
|
|
394
|
+
description: "Send a message or update to a running sub-agent. Use this to redirect, add context, or give feedback to a sub-agent while it's working.",
|
|
395
|
+
parameters: {
|
|
396
|
+
type: "object",
|
|
397
|
+
properties: {
|
|
398
|
+
taskId: {
|
|
399
|
+
type: "string",
|
|
400
|
+
description: "The task ID returned by spawn-task",
|
|
401
|
+
},
|
|
402
|
+
message: {
|
|
403
|
+
type: "string",
|
|
404
|
+
description: "Message to send to the sub-agent",
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
required: ["taskId", "message"],
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
run: async (args) => {
|
|
411
|
+
const { sendToTask } = await import("./agent-teams.js");
|
|
412
|
+
const result = await sendToTask(args.taskId, args.message);
|
|
413
|
+
return JSON.stringify(result);
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
"list-tasks": {
|
|
417
|
+
tool: {
|
|
418
|
+
description: "List all sub-agent tasks and their current status. Use this to see what's running, completed, or failed.",
|
|
419
|
+
parameters: {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: {},
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
run: async () => {
|
|
425
|
+
const { listTasks } = await import("./agent-teams.js");
|
|
426
|
+
const tasks = await listTasks();
|
|
427
|
+
if (tasks.length === 0) {
|
|
428
|
+
return "No sub-agent tasks.";
|
|
429
|
+
}
|
|
430
|
+
return JSON.stringify(tasks.map((t) => ({
|
|
431
|
+
taskId: t.taskId,
|
|
432
|
+
threadId: t.threadId,
|
|
433
|
+
description: t.description,
|
|
434
|
+
status: t.status,
|
|
435
|
+
currentStep: t.currentStep,
|
|
436
|
+
hasResult: t.summary.length > 0,
|
|
437
|
+
})), null, 2);
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
177
442
|
/**
|
|
178
443
|
* Framework-level instructions injected into every agent's system prompt.
|
|
179
444
|
* This is the single source of truth for the core philosophy, rules, and patterns.
|
|
@@ -187,7 +452,7 @@ const FRAMEWORK_CORE = `
|
|
|
187
452
|
### Core Rules
|
|
188
453
|
|
|
189
454
|
1. **Data lives in SQL** — All app state is in a SQL database (could be SQLite, Postgres, Turso, or Cloudflare D1 — never assume which). Use the available database tools.
|
|
190
|
-
2. **Context awareness** —
|
|
455
|
+
2. **Context awareness** — The user's current screen state is automatically included in each message as a \`<current-screen>\` block. Use it to understand what the user is looking at. You can still call \`view-screen\` for a more detailed snapshot if needed, but you should NOT need to call it before every action.
|
|
191
456
|
3. **Navigate the UI** — Use the \`navigate\` tool to switch views, open items, or focus elements for the user.
|
|
192
457
|
4. **Application state** — Ephemeral UI state (drafts, selections, navigation) lives in \`application_state\`. Use \`readAppState\`/\`writeAppState\` to read and write it. When you write state, the UI updates automatically.
|
|
193
458
|
5. **Resources for memory** — Use the Resources system for persistent notes and context. Update LEARNINGS.md when you learn user preferences or corrections. Update the shared AGENTS.md for instructions that should apply to all users.
|
|
@@ -204,6 +469,80 @@ When the user gives instructions that should apply to all users/sessions, update
|
|
|
204
469
|
### Navigation Rule
|
|
205
470
|
|
|
206
471
|
When the user says "show me", "go to", "open", "switch to", or similar navigation language, ALWAYS use the \`navigate\` action to update the UI. The user expects to SEE the result in the main app, not just read it in chat. Navigate first, then fetch/display data.
|
|
472
|
+
|
|
473
|
+
### Chat History
|
|
474
|
+
|
|
475
|
+
You can search and restore previous chat conversations:
|
|
476
|
+
- \`search-chats\` — Search or list past chat threads by keyword
|
|
477
|
+
- \`open-chat\` — Open a chat thread in the UI as a new tab and focus it
|
|
478
|
+
|
|
479
|
+
When the user asks to find a previous conversation, use \`search-chats\` first to find matching threads, then \`open-chat\` to restore the one they want.
|
|
480
|
+
|
|
481
|
+
### Agent Teams — Orchestration
|
|
482
|
+
|
|
483
|
+
You are an orchestrator. For complex or multi-step tasks, delegate to sub-agents:
|
|
484
|
+
- \`spawn-task\` — Spawn a sub-agent for a task. It runs in its own thread while you stay available. A live preview card appears in the chat.
|
|
485
|
+
- \`task-status\` — Check the progress of a running sub-agent.
|
|
486
|
+
- \`read-task-result\` — Read the result when a sub-agent finishes.
|
|
487
|
+
|
|
488
|
+
**When to delegate vs do directly:**
|
|
489
|
+
- **Delegate** when the task involves multiple tool calls, research, content generation, or anything that takes more than a few seconds. Examples: "create a deck about X", "analyze the data and write a report", "look up Y and draft an email about it".
|
|
490
|
+
- **Do directly** for quick single-step tasks like navigation, reading state, or answering simple questions.
|
|
491
|
+
- **Spawn multiple sub-agents** when the user asks for multiple independent things — they'll run in parallel.
|
|
492
|
+
|
|
493
|
+
**How to orchestrate:**
|
|
494
|
+
1. When the user asks for something complex, spawn a sub-agent with a clear task description.
|
|
495
|
+
2. Tell the user what you've started ("I'm having a sub-agent research that for you").
|
|
496
|
+
3. You can keep chatting — sub-agents run independently.
|
|
497
|
+
4. Use \`read-task-result\` to check results when needed, or the user can see live progress in the card.
|
|
498
|
+
5. If the user's request has multiple steps, you can spawn one sub-agent per step, or chain them.
|
|
499
|
+
|
|
500
|
+
Sub-agents have access to all template tools but **cannot spawn sub-agents themselves** — only you (the orchestrator) can do that. Give the sub-agent a specific, actionable task description — it will figure out which tools to use.
|
|
501
|
+
|
|
502
|
+
### Recurring Jobs
|
|
503
|
+
|
|
504
|
+
You can create recurring jobs that run on a cron schedule. Jobs are resource files under \`jobs/\`. Each job has a cron schedule and instructions that the agent executes automatically.
|
|
505
|
+
|
|
506
|
+
- \`create-job\` — Create a new recurring job with a cron schedule and instructions
|
|
507
|
+
- \`list-jobs\` — List all recurring jobs and their status (schedule, last run, next run, errors)
|
|
508
|
+
- \`update-job\` — Update a job's schedule, instructions, or toggle enabled/disabled
|
|
509
|
+
- Delete a job with \`resource-delete --path jobs/<name>.md\`
|
|
510
|
+
|
|
511
|
+
When the user asks for something recurring ("every morning", "daily at 9am", "weekly on Mondays"), create a job. Convert natural language to 5-field cron format:
|
|
512
|
+
- "every morning" / "daily at 9am" → \`0 9 * * *\`
|
|
513
|
+
- "every weekday at 9am" → \`0 9 * * 1-5\`
|
|
514
|
+
- "every hour" → \`0 * * * *\`
|
|
515
|
+
- "every 30 minutes" → \`*/30 * * * *\`
|
|
516
|
+
- "every monday at 9am" → \`0 9 * * 1\`
|
|
517
|
+
- "twice a day" / "morning and evening" → \`0 9,17 * * *\`
|
|
518
|
+
|
|
519
|
+
Job instructions should be self-contained — include which actions to call, what conditions to check, and what to do with results. The agent executing the job has access to all the same tools you do.
|
|
520
|
+
|
|
521
|
+
### call-agent — External Apps Only
|
|
522
|
+
|
|
523
|
+
The \`call-agent\` tool sends a message to a DIFFERENT, separately-deployed app's agent (A2A protocol). It is **not** for calling actions within the current app.
|
|
524
|
+
|
|
525
|
+
**NEVER use \`call-agent\` to:**
|
|
526
|
+
- Call your own app by name (if you are the "macros" agent, never do \`call-agent(agent="macros")\`)
|
|
527
|
+
- Perform tasks you can accomplish with your own registered tools
|
|
528
|
+
- Wrap your own actions in an A2A round-trip
|
|
529
|
+
|
|
530
|
+
**ONLY use \`call-agent\` when:**
|
|
531
|
+
- The user explicitly asks you to communicate with a different app (e.g., "ask the mail agent to...")
|
|
532
|
+
- You need data that only another deployed app can provide
|
|
533
|
+
- You are coordinating across genuinely separate apps
|
|
534
|
+
|
|
535
|
+
If \`call-agent\` returns an error saying the agent is yourself — stop and use your own tools instead.
|
|
536
|
+
|
|
537
|
+
### Auto-Memory
|
|
538
|
+
|
|
539
|
+
Proactively update \`LEARNINGS.md\` when you learn something important during conversations:
|
|
540
|
+
- User corrects your approach → capture the correct way
|
|
541
|
+
- User shares preferences (tone, style, workflow) → capture them
|
|
542
|
+
- You discover a non-obvious pattern or gotcha → capture it
|
|
543
|
+
- User provides personal context (contacts, team info, domain knowledge) → capture it
|
|
544
|
+
|
|
545
|
+
**Don't ask permission — just save it.** Keep entries concise (one line each, grouped by category). Don't save things that are obvious from reading the code or that are temporary.
|
|
207
546
|
`;
|
|
208
547
|
const PROD_FRAMEWORK_PROMPT = `## Agent-Native Framework — Production Mode
|
|
209
548
|
|
|
@@ -212,6 +551,21 @@ You are an AI agent in an agent-native application, running in **production mode
|
|
|
212
551
|
The agent and the UI are equal partners — everything the UI can do, you can do via your tools, and vice versa. They share the same SQL database and stay in sync automatically.
|
|
213
552
|
|
|
214
553
|
**In production mode, you operate through registered actions exposed as tools.** These are your capabilities — use them to read data, take actions, and help the user. You cannot edit source code or access the filesystem directly. Your tools are the app's API.
|
|
554
|
+
|
|
555
|
+
### Code Changes Not Available
|
|
556
|
+
|
|
557
|
+
When the user asks you to change the UI, modify code, add features, fix bugs in the app itself, change styles, or do anything that requires editing source files — you MUST respond with this exact message (replacing APP_NAME with the current app name from the URL hostname):
|
|
558
|
+
|
|
559
|
+
> This app is running in hosted mode and I can't make code changes here. To customize this app:
|
|
560
|
+
>
|
|
561
|
+
> **Option 1:** Connect to [Builder.io](https://www.builder.io/m/agent-native) for a full development environment
|
|
562
|
+
>
|
|
563
|
+
> **Option 2:** Clone and run locally:
|
|
564
|
+
> \`\`\`
|
|
565
|
+
> npx agent-native create APP_NAME
|
|
566
|
+
> \`\`\`
|
|
567
|
+
|
|
568
|
+
Do NOT attempt to work around this limitation. Do NOT say "I can't do that" without providing the options above. Always include both the Builder.io link and the CLI command.
|
|
215
569
|
${FRAMEWORK_CORE}`;
|
|
216
570
|
const DEV_FRAMEWORK_PROMPT = `## Agent-Native Framework — Development Mode
|
|
217
571
|
|
|
@@ -219,7 +573,17 @@ You are an AI agent in an agent-native application, running in **development mod
|
|
|
219
573
|
|
|
220
574
|
The agent and the UI are equal partners — everything the UI can do, you can do via tools/scripts, and vice versa. They share the same SQL database and stay in sync automatically.
|
|
221
575
|
|
|
222
|
-
**In development mode, you have
|
|
576
|
+
**In development mode, you have UNRESTRICTED access.** You can:
|
|
577
|
+
- Run ANY shell command via the \`shell\` tool (bash, node, curl, pnpm, etc.)
|
|
578
|
+
- Execute arbitrary code: \`shell({ command: 'node -e "console.log(1+1)"' })\`
|
|
579
|
+
- Read/write any file on the filesystem
|
|
580
|
+
- Query and modify the database
|
|
581
|
+
- Call external APIs (via shell with curl, or via scripts)
|
|
582
|
+
- Edit source code, install packages, modify the app
|
|
583
|
+
|
|
584
|
+
**There are NO restrictions in dev mode.** If a dedicated tool/action doesn't exist for what you need, use \`shell\` to run any command. For example: \`shell({ command: 'curl -s https://api.example.com/data' })\`
|
|
585
|
+
|
|
586
|
+
**Template-specific actions are invoked via shell, NOT as direct tools.** In dev mode, the only tools registered as native tool calls are framework-level utilities (shell, file ops, resources, chat, teams, jobs). Anything from the template's \`actions/\` directory must be run through shell: \`shell({ command: 'pnpm action <name> --arg value' })\`. The "Available Actions" section below shows the exact CLI syntax for each one — copy that command verbatim and pass it to \`shell\`. Do not try to call template actions by name as if they were tools; they will not appear in your tool list.
|
|
223
587
|
|
|
224
588
|
When editing code, follow the agent-native architecture:
|
|
225
589
|
- Every feature needs all four areas: UI + scripts + skills/instructions + application-state sync
|
|
@@ -229,59 +593,177 @@ When editing code, follow the agent-native architecture:
|
|
|
229
593
|
${FRAMEWORK_CORE}`;
|
|
230
594
|
const DEFAULT_SYSTEM_PROMPT = PROD_FRAMEWORK_PROMPT;
|
|
231
595
|
/**
|
|
232
|
-
* Pre-load
|
|
233
|
-
*
|
|
596
|
+
* Pre-load the agent's context: AGENTS.md (template instructions), the skills
|
|
597
|
+
* index, and LEARNINGS.md (user notes). These all get appended to the system
|
|
598
|
+
* prompt so the agent has everything it needs from the first turn — no tool
|
|
599
|
+
* calls required to figure out "what is this app".
|
|
600
|
+
*
|
|
601
|
+
* Three sources are layered:
|
|
602
|
+
*
|
|
603
|
+
* 1. `<template>` — AGENTS.md + skills index from the `virtual:agents-bundle`
|
|
604
|
+
* module (inlined at build time by the Vite plugin, falls back to a
|
|
605
|
+
* filesystem read from `process.cwd()` in dev). Canonical source for
|
|
606
|
+
* "what is this app, what can it do, what skills are available".
|
|
607
|
+
* 2. `<shared>` — LEARNINGS.md from the SQL shared scope. Team-level notes.
|
|
608
|
+
* 3. `<personal>` — LEARNINGS.md from the SQL personal scope. The current
|
|
609
|
+
* user's own notes.
|
|
610
|
+
*
|
|
611
|
+
* Each source is read independently — no copying between them. Editing
|
|
612
|
+
* AGENTS.md and restarting the server is all it takes; Vite HMR invalidates
|
|
613
|
+
* the bundle in dev so changes land instantly.
|
|
234
614
|
*/
|
|
235
615
|
async function loadResourcesForPrompt(owner) {
|
|
236
616
|
await ensurePersonalDefaults(owner);
|
|
237
|
-
const resourceNames = ["AGENTS.md", "LEARNINGS.md"];
|
|
238
617
|
const sections = [];
|
|
239
|
-
|
|
240
|
-
|
|
618
|
+
// 1. Template AGENTS.md + skills index — from the virtual bundle.
|
|
619
|
+
try {
|
|
620
|
+
const { loadAgentsBundle, generateSkillsPromptBlock } = await import("./agents-bundle.js");
|
|
621
|
+
const bundle = await loadAgentsBundle();
|
|
622
|
+
if (bundle.agentsMd.trim()) {
|
|
623
|
+
sections.push(`<resource name="AGENTS.md" scope="template">\n${bundle.agentsMd.trim()}\n</resource>`);
|
|
624
|
+
}
|
|
625
|
+
const skillsBlock = generateSkillsPromptBlock(bundle);
|
|
626
|
+
if (skillsBlock)
|
|
627
|
+
sections.push(skillsBlock);
|
|
628
|
+
}
|
|
629
|
+
catch { }
|
|
630
|
+
// LEARNINGS.md from SQL (template-level instructions are in AGENTS.md above).
|
|
631
|
+
// 2. Shared SQL scope
|
|
632
|
+
try {
|
|
633
|
+
const shared = await resourceGetByPath(SHARED_OWNER, "LEARNINGS.md");
|
|
634
|
+
if (shared?.content?.trim()) {
|
|
635
|
+
sections.push(`<resource name="LEARNINGS.md" scope="shared">\n${shared.content.trim()}\n</resource>`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
catch { }
|
|
639
|
+
// 3. Personal SQL scope (skip if owner is the shared sentinel)
|
|
640
|
+
if (owner !== SHARED_OWNER) {
|
|
241
641
|
try {
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
sections.push(`<resource name="
|
|
642
|
+
const personal = await resourceGetByPath(owner, "LEARNINGS.md");
|
|
643
|
+
if (personal?.content?.trim()) {
|
|
644
|
+
sections.push(`<resource name="LEARNINGS.md" scope="personal">\n${personal.content.trim()}\n</resource>`);
|
|
245
645
|
}
|
|
246
646
|
}
|
|
247
647
|
catch { }
|
|
248
|
-
// Read personal (skip if owner is the shared sentinel)
|
|
249
|
-
if (owner !== SHARED_OWNER) {
|
|
250
|
-
try {
|
|
251
|
-
const personal = await resourceGetByPath(owner, name);
|
|
252
|
-
if (personal?.content?.trim()) {
|
|
253
|
-
sections.push(`<resource name="${name}" scope="personal">\n${personal.content.trim()}\n</resource>`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
catch { }
|
|
257
|
-
}
|
|
258
648
|
}
|
|
259
649
|
if (sections.length === 0)
|
|
260
650
|
return "";
|
|
261
651
|
return ("\n\nThe following resources contain template-specific instructions and user context. Use the information in them to help the user.\n\n" +
|
|
262
652
|
sections.join("\n\n"));
|
|
263
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Build the per-request SQL-schema context block. Reads AGENT_ORG_ID live
|
|
656
|
+
* from the environment so scheduler/A2A/HTTP call sites all see whatever
|
|
657
|
+
* org was just resolved for this request.
|
|
658
|
+
*/
|
|
659
|
+
async function buildSchemaBlock(owner, hasRawDbTools) {
|
|
660
|
+
try {
|
|
661
|
+
return await loadSchemaPromptBlock({
|
|
662
|
+
owner,
|
|
663
|
+
orgId: process.env.AGENT_ORG_ID ?? null,
|
|
664
|
+
hasRawDbTools,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
return "";
|
|
669
|
+
}
|
|
670
|
+
}
|
|
264
671
|
/** @deprecated Kept for backward compat — dev prompt is now part of DEV_FRAMEWORK_PROMPT */
|
|
265
672
|
const DEFAULT_DEV_PROMPT = "";
|
|
266
673
|
/**
|
|
267
674
|
* Generates a system prompt section describing registered template actions.
|
|
268
675
|
* This helps the agent prefer template-specific actions over raw db-query/db-exec.
|
|
676
|
+
*
|
|
677
|
+
* Two output modes:
|
|
678
|
+
*
|
|
679
|
+
* - `"tool"` — used in production, where template actions are registered
|
|
680
|
+
* as native Anthropic tools. Output reads `name(arg*: type; ...) — desc`.
|
|
681
|
+
* - `"cli"` — used in dev, where template actions are NOT registered as
|
|
682
|
+
* native tools and must be invoked via `shell(command="pnpm action ...")`.
|
|
683
|
+
* Output reads `pnpm action name --arg <type> [--opt <type>] — desc`.
|
|
269
684
|
*/
|
|
270
|
-
function generateActionsPrompt(registry) {
|
|
685
|
+
function generateActionsPrompt(registry, mode = "tool") {
|
|
271
686
|
if (!registry || Object.keys(registry).length === 0)
|
|
272
687
|
return "";
|
|
273
688
|
const lines = Object.entries(registry).map(([name, entry]) => {
|
|
274
689
|
const desc = entry.tool.description;
|
|
275
690
|
const params = entry.tool.parameters?.properties;
|
|
691
|
+
const requiredFields = new Set(entry.tool.parameters?.required ?? []);
|
|
692
|
+
if (mode === "cli") {
|
|
693
|
+
// CLI mode: emit `pnpm action <name> --required <type> [--optional <type>]`
|
|
694
|
+
if (!params || Object.keys(params).length === 0) {
|
|
695
|
+
return `- \`pnpm action ${name}\` — ${desc}`;
|
|
696
|
+
}
|
|
697
|
+
const entries = Object.entries(params);
|
|
698
|
+
// Required first (alphabetical), then optional (alphabetical)
|
|
699
|
+
entries.sort(([a], [b]) => {
|
|
700
|
+
const ar = requiredFields.has(a) ? 0 : 1;
|
|
701
|
+
const br = requiredFields.has(b) ? 0 : 1;
|
|
702
|
+
if (ar !== br)
|
|
703
|
+
return ar - br;
|
|
704
|
+
return a.localeCompare(b);
|
|
705
|
+
});
|
|
706
|
+
const required = [];
|
|
707
|
+
const optional = [];
|
|
708
|
+
const requiredNames = [];
|
|
709
|
+
for (const [k, v] of entries) {
|
|
710
|
+
const type = v.type ?? "any";
|
|
711
|
+
const flag = `--${k} <${type}>`;
|
|
712
|
+
if (requiredFields.has(k)) {
|
|
713
|
+
required.push(flag);
|
|
714
|
+
requiredNames.push(`--${k}`);
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
optional.push(`[${flag}]`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
const cmd = ["pnpm action " + name, ...required, ...optional].join(" ");
|
|
721
|
+
const requiredNote = requiredNames.length > 0
|
|
722
|
+
? ` Required: ${requiredNames.join(", ")}.`
|
|
723
|
+
: "";
|
|
724
|
+
return `- \`${cmd}\` — ${desc}.${requiredNote}`;
|
|
725
|
+
}
|
|
726
|
+
// tool mode (production / native tool calls)
|
|
276
727
|
if (params) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
728
|
+
// Order required params first, then optional. Mark required with "*"
|
|
729
|
+
// and include type + description so the agent knows exactly how to call.
|
|
730
|
+
const entries = Object.entries(params);
|
|
731
|
+
entries.sort(([a], [b]) => {
|
|
732
|
+
const ar = requiredFields.has(a) ? 0 : 1;
|
|
733
|
+
const br = requiredFields.has(b) ? 0 : 1;
|
|
734
|
+
if (ar !== br)
|
|
735
|
+
return ar - br;
|
|
736
|
+
return a.localeCompare(b);
|
|
737
|
+
});
|
|
738
|
+
const paramList = entries
|
|
739
|
+
.map(([k, v]) => {
|
|
740
|
+
const isRequired = requiredFields.has(k);
|
|
741
|
+
const type = v.type ?? "any";
|
|
742
|
+
const marker = isRequired ? "*" : "?";
|
|
743
|
+
const descPart = v.description ? ` — ${v.description}` : "";
|
|
744
|
+
return `${k}${marker}: ${type}${descPart}`;
|
|
745
|
+
})
|
|
746
|
+
.join("; ");
|
|
747
|
+
return `- \`${name}\`(${paramList}) — ${desc}`;
|
|
281
748
|
}
|
|
282
|
-
return `- \`${name}\` — ${desc}`;
|
|
749
|
+
return `- \`${name}\`() — ${desc}`;
|
|
283
750
|
});
|
|
284
|
-
|
|
751
|
+
if (mode === "cli") {
|
|
752
|
+
return `\n\n## Available Actions
|
|
753
|
+
|
|
754
|
+
**These template actions are NOT exposed as direct tools in dev mode. To run any of them, use the \`shell\` tool with the exact command shown below.** Example: \`shell(command="pnpm action add-slide --deckId abc --content 'Hello'")\`.
|
|
755
|
+
|
|
756
|
+
Do NOT try to call these by name as if they were tools — they will not exist in your tool list. Always go through \`shell\`.
|
|
757
|
+
|
|
758
|
+
${lines.join("\n")}`;
|
|
759
|
+
}
|
|
760
|
+
return `\n\n## Available Actions
|
|
761
|
+
|
|
762
|
+
**Use these actions directly to accomplish tasks. Do NOT use \`db-schema\`, \`search-files\`, or \`shell\` to explore the app — these actions already connect to the correct database and services.**
|
|
763
|
+
|
|
764
|
+
Parameter notation: \`name*\` = required, \`name?\` = optional. Always pass the tool's parameters as a JSON object to the tool_use call — never via shell or string-concatenated CLI flags.
|
|
765
|
+
|
|
766
|
+
${lines.join("\n")}`;
|
|
285
767
|
}
|
|
286
768
|
/**
|
|
287
769
|
* Creates a Nitro plugin that mounts the agent chat endpoint.
|
|
@@ -292,7 +774,7 @@ function generateActionsPrompt(registry) {
|
|
|
292
774
|
* Usage in templates:
|
|
293
775
|
* ```ts
|
|
294
776
|
* // server/plugins/agent-chat.ts
|
|
295
|
-
* import { createAgentChatPlugin } from "@agent-native/core/server";
|
|
777
|
+
* import { readBody, createAgentChatPlugin } from "@agent-native/core/server";
|
|
296
778
|
* import { scriptRegistry } from "../../scripts/registry.js";
|
|
297
779
|
*
|
|
298
780
|
* export default createAgentChatPlugin({
|
|
@@ -301,7 +783,7 @@ function generateActionsPrompt(registry) {
|
|
|
301
783
|
* });
|
|
302
784
|
* ```
|
|
303
785
|
*/
|
|
304
|
-
function collectFiles(dir, prefix, depth, results) {
|
|
786
|
+
async function collectFiles(dir, prefix, depth, results) {
|
|
305
787
|
if (depth > 4 || results.length >= 500)
|
|
306
788
|
return;
|
|
307
789
|
const skip = new Set([
|
|
@@ -316,6 +798,7 @@ function collectFiles(dir, prefix, depth, results) {
|
|
|
316
798
|
]);
|
|
317
799
|
let entries;
|
|
318
800
|
try {
|
|
801
|
+
const fs = await lazyFs();
|
|
319
802
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
320
803
|
}
|
|
321
804
|
catch {
|
|
@@ -334,7 +817,7 @@ function collectFiles(dir, prefix, depth, results) {
|
|
|
334
817
|
type: isDir ? "folder" : "file",
|
|
335
818
|
});
|
|
336
819
|
if (isDir)
|
|
337
|
-
collectFiles(nodePath.join(dir, entry.name), relPath, depth + 1, results);
|
|
820
|
+
await collectFiles(nodePath.join(dir, entry.name), relPath, depth + 1, results);
|
|
338
821
|
}
|
|
339
822
|
}
|
|
340
823
|
function parseSkillFrontmatter(content) {
|
|
@@ -358,6 +841,11 @@ function isLocalhost(event) {
|
|
|
358
841
|
}
|
|
359
842
|
export function createAgentChatPlugin(options) {
|
|
360
843
|
return async (nitroApp) => {
|
|
844
|
+
// Wait for default framework plugins (auth, core-routes, integrations, ...)
|
|
845
|
+
// to finish mounting their middleware before we register our own. Without
|
|
846
|
+
// this, requests can race ahead of the bootstrap and hit the SSR catch-all.
|
|
847
|
+
const { awaitBootstrap } = await import("./framework-request-handler.js");
|
|
848
|
+
await awaitBootstrap(nitroApp);
|
|
361
849
|
const env = process.env.NODE_ENV;
|
|
362
850
|
// AGENT_MODE=production forces production agent constraints even in dev
|
|
363
851
|
const canToggle = (env === "development" || env === "test") &&
|
|
@@ -368,18 +856,163 @@ export function createAgentChatPlugin(options) {
|
|
|
368
856
|
const templateScripts = typeof rawActions === "function"
|
|
369
857
|
? await rawActions()
|
|
370
858
|
: (rawActions ?? {});
|
|
371
|
-
// Resource and cross-agent scripts are available in both prod and dev modes
|
|
859
|
+
// Resource, chat, and cross-agent scripts are available in both prod and dev modes
|
|
372
860
|
const resourceScripts = await createResourceScriptEntries();
|
|
373
|
-
const
|
|
861
|
+
const engineScripts = await createAgentEngineScriptEntries();
|
|
862
|
+
const chatScripts = {
|
|
863
|
+
...(await createChatScriptEntries()),
|
|
864
|
+
...engineScripts,
|
|
865
|
+
};
|
|
866
|
+
const callAgentScript = await createCallAgentScriptEntry(options?.appId);
|
|
374
867
|
// Auto-mount A2A protocol endpoints so every app is discoverable
|
|
375
868
|
// and callable by other agents via the standard protocol.
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
869
|
+
// In dev mode, include dev scripts (filesystem-discovered) so the A2A agent
|
|
870
|
+
// has access to the same tools as the interactive agent.
|
|
871
|
+
let devScriptsForA2A = {};
|
|
872
|
+
let discoveredActions = {};
|
|
873
|
+
if (canToggle) {
|
|
874
|
+
try {
|
|
875
|
+
const { createDevScriptRegistry } = await import("../scripts/dev/index.js");
|
|
876
|
+
devScriptsForA2A = await createDevScriptRegistry();
|
|
877
|
+
}
|
|
878
|
+
catch { }
|
|
879
|
+
// Auto-discover template action files and register as shell-based tools.
|
|
880
|
+
// This ensures templates without a custom agent-chat plugin (e.g., analytics)
|
|
881
|
+
// still have their domain actions available as tools.
|
|
882
|
+
try {
|
|
883
|
+
const fs = await import("fs");
|
|
884
|
+
const pathMod = await import("path");
|
|
885
|
+
const cwd = process.cwd();
|
|
886
|
+
const skipFiles = new Set([
|
|
887
|
+
"helpers",
|
|
888
|
+
"run",
|
|
889
|
+
"registry",
|
|
890
|
+
"_utils",
|
|
891
|
+
"db-connect",
|
|
892
|
+
"db-status",
|
|
893
|
+
]);
|
|
894
|
+
for (const dir of ["actions", "scripts"]) {
|
|
895
|
+
const actionsDir = pathMod.join(cwd, dir);
|
|
896
|
+
const _fs = await lazyFs();
|
|
897
|
+
if (!_fs.existsSync(actionsDir))
|
|
898
|
+
continue;
|
|
899
|
+
const files = _fs
|
|
900
|
+
.readdirSync(actionsDir)
|
|
901
|
+
.filter((f) => f.endsWith(".ts") &&
|
|
902
|
+
!f.startsWith("_") &&
|
|
903
|
+
!skipFiles.has(f.replace(/\.ts$/, "")));
|
|
904
|
+
for (const file of files) {
|
|
905
|
+
const name = file.replace(/\.ts$/, "");
|
|
906
|
+
if (templateScripts[name] || devScriptsForA2A[name])
|
|
907
|
+
continue;
|
|
908
|
+
// Try to load the action module directly so we get the real
|
|
909
|
+
// run function (not a shell wrapper). This makes HTTP endpoints
|
|
910
|
+
// work correctly. Only fall back to shell wrapper if the import
|
|
911
|
+
// fails (e.g., CLI-style scripts that throw at top level).
|
|
912
|
+
const filePath = pathMod.join(actionsDir, file);
|
|
913
|
+
try {
|
|
914
|
+
const mod = await import(/* @vite-ignore */ filePath);
|
|
915
|
+
const def = mod.default && typeof mod.default === "object"
|
|
916
|
+
? mod.default
|
|
917
|
+
: mod;
|
|
918
|
+
if (def?.tool && typeof def.run === "function") {
|
|
919
|
+
discoveredActions[name] = {
|
|
920
|
+
tool: def.tool,
|
|
921
|
+
run: def.run,
|
|
922
|
+
...(def.http !== undefined ? { http: def.http } : {}),
|
|
923
|
+
};
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
catch {
|
|
928
|
+
// Fall through to shell wrapper for CLI-style scripts
|
|
929
|
+
// (and .ts files Node can't parse natively).
|
|
930
|
+
}
|
|
931
|
+
// Static-parse the source for `http: false` or
|
|
932
|
+
// `http: { method: "GET" }` so the shell-wrapper fallback still
|
|
933
|
+
// mounts HTTP routes with the correct method. We can't load the
|
|
934
|
+
// .ts module to read the real defineAction object in this Node
|
|
935
|
+
// context, so this regex sniff is the best we can do until the
|
|
936
|
+
// discovery is moved into a Vite-aware codepath.
|
|
937
|
+
let httpConfig;
|
|
938
|
+
try {
|
|
939
|
+
const src = _fs.readFileSync(filePath, "utf-8");
|
|
940
|
+
if (/\bhttp\s*:\s*false\b/.test(src)) {
|
|
941
|
+
httpConfig = false;
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
const httpStart = src.search(/\bhttp\s*:\s*\{/);
|
|
945
|
+
if (httpStart >= 0) {
|
|
946
|
+
const window = src.slice(httpStart, httpStart + 200);
|
|
947
|
+
const m = window.match(/method\s*:\s*['"`](GET|POST|PUT|DELETE)['"`]/);
|
|
948
|
+
const p = window.match(/path\s*:\s*['"`]([^'"`]+)['"`]/);
|
|
949
|
+
if (m || p) {
|
|
950
|
+
httpConfig = {
|
|
951
|
+
...(m
|
|
952
|
+
? {
|
|
953
|
+
method: m[1],
|
|
954
|
+
}
|
|
955
|
+
: {}),
|
|
956
|
+
...(p ? { path: p[1] } : {}),
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
catch {
|
|
963
|
+
// File read failed — leave httpConfig undefined (default POST)
|
|
964
|
+
}
|
|
965
|
+
// Fallback: shell-based wrapper for CLI-style scripts
|
|
966
|
+
discoveredActions[name] = {
|
|
967
|
+
tool: {
|
|
968
|
+
description: `Run the ${name} action. Use: pnpm action ${name} --arg=value`,
|
|
969
|
+
parameters: {
|
|
970
|
+
type: "object",
|
|
971
|
+
properties: {
|
|
972
|
+
args: {
|
|
973
|
+
type: "string",
|
|
974
|
+
description: "CLI arguments as a string (e.g., --metrics=sessions --days=7)",
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
},
|
|
978
|
+
},
|
|
979
|
+
run: async (input) => {
|
|
980
|
+
const shellEntry = devScriptsForA2A["shell"];
|
|
981
|
+
if (!shellEntry)
|
|
982
|
+
return "Error: shell not available";
|
|
983
|
+
return shellEntry.run({
|
|
984
|
+
command: `pnpm action ${name} ${input.args || ""}`.trim(),
|
|
985
|
+
});
|
|
986
|
+
},
|
|
987
|
+
...(httpConfig !== undefined ? { http: httpConfig } : {}),
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
if (Object.keys(discoveredActions).length > 0 && process.env.DEBUG)
|
|
992
|
+
console.log(`[agent-chat] Auto-discovered ${Object.keys(discoveredActions).length} action(s): ${Object.keys(discoveredActions).join(", ")}`);
|
|
993
|
+
}
|
|
994
|
+
catch { }
|
|
995
|
+
}
|
|
996
|
+
// In dev mode, template actions (templateScripts and discoveredActions) are
|
|
997
|
+
// NOT registered as native tools — the agent invokes them via shell instead.
|
|
998
|
+
// This avoids degenerate empty-object tool calls that Anthropic models
|
|
999
|
+
// sometimes emit for actions with complex schemas. Production keeps the
|
|
1000
|
+
// native registration since it has no shell access.
|
|
1001
|
+
const allScripts = canToggle
|
|
1002
|
+
? {
|
|
1003
|
+
...resourceScripts,
|
|
1004
|
+
...chatScripts,
|
|
1005
|
+
...callAgentScript,
|
|
1006
|
+
...devScriptsForA2A,
|
|
1007
|
+
}
|
|
1008
|
+
: {
|
|
1009
|
+
...discoveredActions,
|
|
1010
|
+
...templateScripts,
|
|
1011
|
+
...resourceScripts,
|
|
1012
|
+
...chatScripts,
|
|
1013
|
+
...callAgentScript,
|
|
1014
|
+
...devScriptsForA2A,
|
|
1015
|
+
};
|
|
383
1016
|
const { mountA2A } = await import("../a2a/server.js");
|
|
384
1017
|
mountA2A(nitroApp, {
|
|
385
1018
|
name: options?.appId
|
|
@@ -394,12 +1027,9 @@ export function createAgentChatPlugin(options) {
|
|
|
394
1027
|
streaming: true,
|
|
395
1028
|
handler: async function* (message, context) {
|
|
396
1029
|
// Resolve the caller's identity for user-scoped data access.
|
|
397
|
-
// Dev: use most recent session from local DB (single user, no verification).
|
|
398
|
-
// Prod: verify Google OAuth token from caller, check email domain.
|
|
399
1030
|
const isDev = process.env.NODE_ENV !== "production";
|
|
400
1031
|
let userEmail;
|
|
401
1032
|
if (isDev) {
|
|
402
|
-
// Dev mode: trust the caller's claimed email, or auto-detect from local sessions
|
|
403
1033
|
userEmail = context.metadata?.userEmail || undefined;
|
|
404
1034
|
if (!userEmail) {
|
|
405
1035
|
try {
|
|
@@ -416,7 +1046,6 @@ export function createAgentChatPlugin(options) {
|
|
|
416
1046
|
}
|
|
417
1047
|
}
|
|
418
1048
|
else {
|
|
419
|
-
// Prod mode: verify identity via Google OAuth token
|
|
420
1049
|
const googleToken = context.metadata?.googleToken;
|
|
421
1050
|
if (googleToken) {
|
|
422
1051
|
try {
|
|
@@ -447,109 +1076,156 @@ export function createAgentChatPlugin(options) {
|
|
|
447
1076
|
};
|
|
448
1077
|
return;
|
|
449
1078
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
},
|
|
460
|
-
],
|
|
461
|
-
};
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
const client = new Anthropic({ apiKey });
|
|
465
|
-
const model = options?.model ?? "claude-sonnet-4-6";
|
|
466
|
-
// Load shared AGENTS.md resource so the agent knows how to use its tools
|
|
1079
|
+
// Use the SAME agent setup as the interactive chat — identical tools,
|
|
1080
|
+
// prompt, and capabilities. The A2A agent IS the app's agent.
|
|
1081
|
+
const a2aEngine = await resolveEngine({
|
|
1082
|
+
engineOption: options?.engine,
|
|
1083
|
+
apiKey: options?.apiKey,
|
|
1084
|
+
});
|
|
1085
|
+
// Use the same handler (dev or prod) that the interactive chat uses
|
|
1086
|
+
const handler = canToggle && devHandler ? devHandler : prodHandler;
|
|
1087
|
+
// Build the same system prompt the interactive agent uses
|
|
467
1088
|
const owner = userEmail || "local@localhost";
|
|
468
1089
|
const resources = await loadResourcesForPrompt(owner);
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const
|
|
1090
|
+
const schemaBlock = await buildSchemaBlock(owner, canToggle);
|
|
1091
|
+
const systemPrompt = canToggle
|
|
1092
|
+
? devPrompt + resources + schemaBlock
|
|
1093
|
+
: basePrompt + resources + schemaBlock;
|
|
1094
|
+
const model = options?.model ??
|
|
1095
|
+
(canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
|
|
1096
|
+
// Build tools — same as interactive handler but WITHOUT call-agent
|
|
1097
|
+
// to prevent infinite recursive A2A loops (agent calling itself).
|
|
1098
|
+
// In dev mode, template actions are invoked via shell (not native tools),
|
|
1099
|
+
// so they're omitted from the tool registry — see allScripts comment.
|
|
1100
|
+
const a2aActions = canToggle
|
|
1101
|
+
? {
|
|
1102
|
+
...resourceScripts,
|
|
1103
|
+
...chatScripts,
|
|
1104
|
+
...devScriptsForA2A,
|
|
1105
|
+
}
|
|
1106
|
+
: {
|
|
1107
|
+
...templateScripts,
|
|
1108
|
+
...resourceScripts,
|
|
1109
|
+
...chatScripts,
|
|
1110
|
+
};
|
|
1111
|
+
const a2aTools = actionsToEngineTools(a2aActions);
|
|
1112
|
+
const a2aMessages = [
|
|
1113
|
+
{ role: "user", content: [{ type: "text", text }] },
|
|
1114
|
+
];
|
|
1115
|
+
// Run the SAME agent loop, collect text events, yield as A2A messages
|
|
480
1116
|
let accumulatedText = "";
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
event.delta?.type === "text_delta") {
|
|
494
|
-
accumulatedText += event.delta.text;
|
|
495
|
-
yield {
|
|
496
|
-
role: "agent",
|
|
497
|
-
parts: [{ type: "text", text: accumulatedText }],
|
|
498
|
-
};
|
|
1117
|
+
const controller = new AbortController();
|
|
1118
|
+
console.log(`[A2A] Starting agent loop: ${a2aTools.length} tools, prompt ${systemPrompt.length} chars`);
|
|
1119
|
+
await runAgentLoop({
|
|
1120
|
+
engine: a2aEngine,
|
|
1121
|
+
model,
|
|
1122
|
+
systemPrompt,
|
|
1123
|
+
tools: a2aTools,
|
|
1124
|
+
messages: a2aMessages,
|
|
1125
|
+
actions: a2aActions,
|
|
1126
|
+
send: (event) => {
|
|
1127
|
+
if (event.type === "text") {
|
|
1128
|
+
accumulatedText += event.text;
|
|
499
1129
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const finalMessage = await apiStream.finalMessage();
|
|
503
|
-
const toolUseBlocks = finalMessage.content.filter((b) => b.type === "tool_use");
|
|
504
|
-
if (toolUseBlocks.length === 0 ||
|
|
505
|
-
finalMessage.stop_reason !== "tool_use") {
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
// Execute tools and continue the loop
|
|
509
|
-
msgs.push({ role: "assistant", content: finalMessage.content });
|
|
510
|
-
const toolResults = [];
|
|
511
|
-
for (const tb of toolUseBlocks) {
|
|
512
|
-
const script = allScripts[tb.name];
|
|
513
|
-
let result = `Unknown tool: ${tb.name}`;
|
|
514
|
-
if (script) {
|
|
515
|
-
try {
|
|
516
|
-
result = await script.run(tb.input);
|
|
517
|
-
}
|
|
518
|
-
catch (err) {
|
|
519
|
-
result = `Error: ${err?.message}`;
|
|
520
|
-
}
|
|
1130
|
+
else if (event.type === "tool_start") {
|
|
1131
|
+
console.log(`[A2A] Tool call: ${event.tool}`);
|
|
521
1132
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
1133
|
+
else if (event.type === "error") {
|
|
1134
|
+
console.error(`[A2A] Error: ${event.error}`);
|
|
1135
|
+
}
|
|
1136
|
+
else if (event.type === "done") {
|
|
1137
|
+
console.log(`[A2A] Done. Response: ${accumulatedText.length} chars`);
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
signal: controller.signal,
|
|
1141
|
+
});
|
|
1142
|
+
console.log(`[A2A] Loop complete. Text: ${accumulatedText.slice(0, 100)}...`);
|
|
1143
|
+
// Yield the final accumulated text
|
|
1144
|
+
yield {
|
|
1145
|
+
role: "agent",
|
|
1146
|
+
parts: [
|
|
1147
|
+
{
|
|
1148
|
+
type: "text",
|
|
1149
|
+
text: accumulatedText || "(no response)",
|
|
1150
|
+
},
|
|
1151
|
+
],
|
|
1152
|
+
};
|
|
537
1153
|
},
|
|
538
1154
|
});
|
|
539
1155
|
// Generate an "Available Actions" section from template-specific actions
|
|
540
|
-
// so the agent knows to use them instead of raw SQL
|
|
541
|
-
|
|
1156
|
+
// so the agent knows to use them instead of raw SQL.
|
|
1157
|
+
//
|
|
1158
|
+
// Production: actions are native tools — emit `name(arg*: type) — desc`
|
|
1159
|
+
// Dev: actions are invoked via shell — emit `pnpm action name --arg <type>`
|
|
1160
|
+
// and include discoveredActions too, since those are also missing
|
|
1161
|
+
// from the dev tool registry.
|
|
1162
|
+
const prodActionsPrompt = generateActionsPrompt(templateScripts, "tool");
|
|
1163
|
+
const devActionsPrompt = generateActionsPrompt({ ...discoveredActions, ...templateScripts }, "cli");
|
|
542
1164
|
// Build system prompts — dynamic functions that pre-load resources per-request.
|
|
543
1165
|
// Production gets PROD_FRAMEWORK_PROMPT, dev gets DEV_FRAMEWORK_PROMPT.
|
|
544
1166
|
// Custom systemPrompt from options overrides the framework default entirely.
|
|
545
|
-
const prodPrompt = (options?.systemPrompt ?? PROD_FRAMEWORK_PROMPT) +
|
|
1167
|
+
const prodPrompt = (options?.systemPrompt ?? PROD_FRAMEWORK_PROMPT) + prodActionsPrompt;
|
|
546
1168
|
const devPrompt = (options?.devSystemPrompt
|
|
547
1169
|
? options.devSystemPrompt +
|
|
548
1170
|
(options?.systemPrompt ?? PROD_FRAMEWORK_PROMPT)
|
|
549
|
-
: DEV_FRAMEWORK_PROMPT) +
|
|
1171
|
+
: DEV_FRAMEWORK_PROMPT) + devActionsPrompt;
|
|
550
1172
|
// Keep legacy names for the composition below
|
|
551
1173
|
const basePrompt = prodPrompt;
|
|
552
1174
|
const devPrefix = options?.devSystemPrompt ?? DEFAULT_DEV_PROMPT;
|
|
1175
|
+
// Mount MCP remote server — same action registry as A2A + agent chat
|
|
1176
|
+
const { mountMCP } = await import("../mcp/server.js");
|
|
1177
|
+
mountMCP(nitroApp, {
|
|
1178
|
+
name: options?.appId
|
|
1179
|
+
? options.appId.charAt(0).toUpperCase() + options.appId.slice(1)
|
|
1180
|
+
: "Agent",
|
|
1181
|
+
description: `Agent-native ${options?.appId ?? "app"} agent`,
|
|
1182
|
+
actions: allScripts,
|
|
1183
|
+
askAgent: async (message) => {
|
|
1184
|
+
const mcpEngine = await resolveEngine({
|
|
1185
|
+
engineOption: options?.engine,
|
|
1186
|
+
apiKey: options?.apiKey,
|
|
1187
|
+
});
|
|
1188
|
+
const model = options?.model ??
|
|
1189
|
+
(canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
|
|
1190
|
+
// Same actions as A2A — without call-agent to prevent loops.
|
|
1191
|
+
// In dev mode, template actions go through shell, not native tools.
|
|
1192
|
+
const mcpActions = canToggle
|
|
1193
|
+
? {
|
|
1194
|
+
...resourceScripts,
|
|
1195
|
+
...chatScripts,
|
|
1196
|
+
...devScriptsForA2A,
|
|
1197
|
+
}
|
|
1198
|
+
: {
|
|
1199
|
+
...templateScripts,
|
|
1200
|
+
...resourceScripts,
|
|
1201
|
+
...chatScripts,
|
|
1202
|
+
};
|
|
1203
|
+
const mcpTools = actionsToEngineTools(mcpActions);
|
|
1204
|
+
const resources = await loadResourcesForPrompt("local@localhost");
|
|
1205
|
+
const schemaBlock = await buildSchemaBlock("local@localhost", canToggle);
|
|
1206
|
+
const systemPrompt = canToggle
|
|
1207
|
+
? devPrompt + resources + schemaBlock
|
|
1208
|
+
: basePrompt + resources + schemaBlock;
|
|
1209
|
+
let accumulatedText = "";
|
|
1210
|
+
const controller = new AbortController();
|
|
1211
|
+
await runAgentLoop({
|
|
1212
|
+
engine: mcpEngine,
|
|
1213
|
+
model,
|
|
1214
|
+
systemPrompt,
|
|
1215
|
+
tools: mcpTools,
|
|
1216
|
+
messages: [
|
|
1217
|
+
{ role: "user", content: [{ type: "text", text: message }] },
|
|
1218
|
+
],
|
|
1219
|
+
actions: mcpActions,
|
|
1220
|
+
send: (event) => {
|
|
1221
|
+
if (event.type === "text")
|
|
1222
|
+
accumulatedText += event.text;
|
|
1223
|
+
},
|
|
1224
|
+
signal: controller.signal,
|
|
1225
|
+
});
|
|
1226
|
+
return accumulatedText || "(no response)";
|
|
1227
|
+
},
|
|
1228
|
+
});
|
|
553
1229
|
// Resolve owner from the H3 event's session — matches how resources are created
|
|
554
1230
|
const getOwnerFromEvent = async (event) => {
|
|
555
1231
|
try {
|
|
@@ -560,6 +1236,20 @@ export function createAgentChatPlugin(options) {
|
|
|
560
1236
|
return "local@localhost";
|
|
561
1237
|
}
|
|
562
1238
|
};
|
|
1239
|
+
// Auto-mount template actions as HTTP endpoints under /_agent-native/actions/
|
|
1240
|
+
// Include engine management scripts so the UI can call list/set/test-agent-engine.
|
|
1241
|
+
const httpActions = {
|
|
1242
|
+
...discoveredActions,
|
|
1243
|
+
...templateScripts,
|
|
1244
|
+
...engineScripts,
|
|
1245
|
+
};
|
|
1246
|
+
if (Object.keys(httpActions).length > 0) {
|
|
1247
|
+
const { mountActionRoutes } = await import("./action-routes.js");
|
|
1248
|
+
mountActionRoutes(nitroApp, httpActions, {
|
|
1249
|
+
getOwnerFromEvent,
|
|
1250
|
+
resolveOrgId: options?.resolveOrgId,
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
563
1253
|
// Callback to persist agent response when run finishes (even if client disconnected).
|
|
564
1254
|
// Reconstructs the assistant message from buffered events and appends to thread_data.
|
|
565
1255
|
const onRunComplete = async (run, threadId) => {
|
|
@@ -588,12 +1278,24 @@ export function createAgentChatPlugin(options) {
|
|
|
588
1278
|
if (!Array.isArray(repo.messages))
|
|
589
1279
|
repo.messages = [];
|
|
590
1280
|
const lastMsg = repo.messages[repo.messages.length - 1];
|
|
591
|
-
|
|
1281
|
+
// Check both wrapped ({ message: { role } }) and unwrapped ({ role }) formats
|
|
1282
|
+
const lastRole = lastMsg?.message?.role ?? lastMsg?.role;
|
|
1283
|
+
if (lastRole === "assistant") {
|
|
592
1284
|
// Frontend already saved the assistant response — just bump timestamp
|
|
593
1285
|
await updateThreadData(threadId, thread.threadData, thread.title, thread.preview, thread.messageCount);
|
|
594
1286
|
return;
|
|
595
1287
|
}
|
|
596
|
-
repo
|
|
1288
|
+
// Determine if repo uses wrapped format ({ message, parentId }) or flat format
|
|
1289
|
+
const isWrapped = lastMsg && "message" in lastMsg;
|
|
1290
|
+
if (isWrapped) {
|
|
1291
|
+
const parentId = repo.messages.length > 0
|
|
1292
|
+
? (repo.messages[repo.messages.length - 1].message?.id ?? null)
|
|
1293
|
+
: null;
|
|
1294
|
+
repo.messages.push({ message: assistantMsg, parentId });
|
|
1295
|
+
}
|
|
1296
|
+
else {
|
|
1297
|
+
repo.messages.push(assistantMsg);
|
|
1298
|
+
}
|
|
597
1299
|
const meta = extractThreadMeta(repo);
|
|
598
1300
|
await updateThreadData(threadId, JSON.stringify(repo), meta.title || thread.title, meta.preview || thread.preview, repo.messages.length);
|
|
599
1301
|
}
|
|
@@ -601,38 +1303,128 @@ export function createAgentChatPlugin(options) {
|
|
|
601
1303
|
// Best-effort — don't break cleanup
|
|
602
1304
|
}
|
|
603
1305
|
};
|
|
604
|
-
//
|
|
1306
|
+
// ─── Agent Teams: per-run send reference ─────────────────────────
|
|
1307
|
+
// Team tools need to emit events to the parent chat's SSE stream.
|
|
1308
|
+
// Each run gets its own send function, keyed by threadId so concurrent
|
|
1309
|
+
// requests for different threads don't clobber each other.
|
|
1310
|
+
const _runSendByThread = new Map();
|
|
1311
|
+
let _currentRunOwner = "local@localhost";
|
|
1312
|
+
let _currentRunThreadId = "";
|
|
1313
|
+
let _currentRunSystemPrompt = basePrompt;
|
|
1314
|
+
// Default to Haiku in production mode to manage costs for hosted apps
|
|
1315
|
+
const resolvedModel = options?.model ??
|
|
1316
|
+
(canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
|
|
1317
|
+
const teamTools = createTeamTools({
|
|
1318
|
+
getOwner: () => _currentRunOwner,
|
|
1319
|
+
getSystemPrompt: () => _currentRunSystemPrompt,
|
|
1320
|
+
getActions: () => canToggle
|
|
1321
|
+
? {
|
|
1322
|
+
// Sub-agents spawned in dev mode also invoke template actions
|
|
1323
|
+
// via shell, so omit them from the native tool registry.
|
|
1324
|
+
...resourceScripts,
|
|
1325
|
+
...chatScripts,
|
|
1326
|
+
...devScriptsForA2A,
|
|
1327
|
+
}
|
|
1328
|
+
: {
|
|
1329
|
+
...templateScripts,
|
|
1330
|
+
...resourceScripts,
|
|
1331
|
+
...chatScripts,
|
|
1332
|
+
},
|
|
1333
|
+
getEngine: () => createAnthropicEngine({
|
|
1334
|
+
apiKey: options?.apiKey ?? process.env.ANTHROPIC_API_KEY,
|
|
1335
|
+
}),
|
|
1336
|
+
getModel: () => resolvedModel,
|
|
1337
|
+
getParentThreadId: () => _currentRunThreadId,
|
|
1338
|
+
getSend: () => {
|
|
1339
|
+
// Return the send for the current run's thread
|
|
1340
|
+
const send = _runSendByThread.get(_currentRunThreadId);
|
|
1341
|
+
return send ?? null;
|
|
1342
|
+
},
|
|
1343
|
+
});
|
|
1344
|
+
// Hook into the run lifecycle to set/clear the send reference.
|
|
1345
|
+
// Job management tools (create-job, list-jobs, update-job)
|
|
1346
|
+
let jobTools = {};
|
|
1347
|
+
try {
|
|
1348
|
+
const { createJobTools } = await import("../jobs/tools.js");
|
|
1349
|
+
jobTools = createJobTools();
|
|
1350
|
+
}
|
|
1351
|
+
catch { }
|
|
1352
|
+
const prodActions = {
|
|
1353
|
+
...templateScripts,
|
|
1354
|
+
...resourceScripts,
|
|
1355
|
+
...chatScripts,
|
|
1356
|
+
...callAgentScript,
|
|
1357
|
+
...teamTools,
|
|
1358
|
+
...jobTools,
|
|
1359
|
+
};
|
|
1360
|
+
// Always build the production handler (includes resource tools + call-agent + team tools)
|
|
1361
|
+
// In production mode (!canToggle), enable usage tracking and limits
|
|
1362
|
+
const isHostedProd = !canToggle;
|
|
605
1363
|
const prodHandler = createProductionAgentHandler({
|
|
606
|
-
actions:
|
|
1364
|
+
actions: prodActions,
|
|
607
1365
|
systemPrompt: async (event) => {
|
|
608
1366
|
const owner = await getOwnerFromEvent(event);
|
|
1367
|
+
_currentRunOwner = owner;
|
|
609
1368
|
const resources = await loadResourcesForPrompt(owner);
|
|
610
|
-
|
|
1369
|
+
const schemaBlock = await buildSchemaBlock(owner, false);
|
|
1370
|
+
_currentRunSystemPrompt = basePrompt + resources + schemaBlock;
|
|
1371
|
+
return _currentRunSystemPrompt;
|
|
611
1372
|
},
|
|
612
|
-
model: options?.model
|
|
1373
|
+
model: options?.model ??
|
|
1374
|
+
(isHostedProd ? "claude-haiku-4-5-20251001" : undefined),
|
|
613
1375
|
apiKey: options?.apiKey,
|
|
614
|
-
|
|
1376
|
+
onRunStart: (send, threadId) => {
|
|
1377
|
+
_runSendByThread.set(threadId, send);
|
|
1378
|
+
_currentRunThreadId = threadId;
|
|
1379
|
+
},
|
|
1380
|
+
onRunComplete: async (run, threadId) => {
|
|
1381
|
+
if (threadId)
|
|
1382
|
+
_runSendByThread.delete(threadId);
|
|
1383
|
+
await onRunComplete(run, threadId);
|
|
1384
|
+
},
|
|
1385
|
+
// Usage tracking for hosted production deployments
|
|
1386
|
+
trackUsage: isHostedProd,
|
|
1387
|
+
resolveOwnerEmail: isHostedProd ? getOwnerFromEvent : undefined,
|
|
615
1388
|
});
|
|
616
1389
|
// Build the dev handler (with filesystem/shell/db tools) if environment allows toggling
|
|
617
1390
|
let devHandler = null;
|
|
618
1391
|
if (canToggle) {
|
|
619
1392
|
const { createDevScriptRegistry } = await import("../scripts/dev/index.js");
|
|
1393
|
+
// Dev mode: template actions (templateScripts and discoveredActions) are
|
|
1394
|
+
// intentionally OMITTED from the native tool registry. The agent invokes
|
|
1395
|
+
// them via `shell(command="pnpm action <name> ...")` instead. This mirrors
|
|
1396
|
+
// how Claude Code works locally and dramatically reduces the rate of
|
|
1397
|
+
// degenerate empty-object tool calls. The CLI syntax for each action is
|
|
1398
|
+
// listed in the dev system prompt's "Available Actions" section.
|
|
620
1399
|
const devActions = {
|
|
621
|
-
...templateScripts,
|
|
622
1400
|
...resourceScripts,
|
|
1401
|
+
...chatScripts,
|
|
623
1402
|
...callAgentScript,
|
|
1403
|
+
...teamTools,
|
|
1404
|
+
...jobTools,
|
|
624
1405
|
...(await createDevScriptRegistry()),
|
|
625
1406
|
};
|
|
626
1407
|
devHandler = createProductionAgentHandler({
|
|
627
1408
|
actions: devActions,
|
|
628
1409
|
systemPrompt: async (event) => {
|
|
629
1410
|
const owner = await getOwnerFromEvent(event);
|
|
1411
|
+
_currentRunOwner = owner;
|
|
630
1412
|
const resources = await loadResourcesForPrompt(owner);
|
|
631
|
-
|
|
1413
|
+
const schemaBlock = await buildSchemaBlock(owner, true);
|
|
1414
|
+
_currentRunSystemPrompt = devPrompt + resources + schemaBlock;
|
|
1415
|
+
return _currentRunSystemPrompt;
|
|
632
1416
|
},
|
|
633
1417
|
model: options?.model,
|
|
634
1418
|
apiKey: options?.apiKey,
|
|
635
|
-
|
|
1419
|
+
onRunStart: (send, threadId) => {
|
|
1420
|
+
_runSendByThread.set(threadId, send);
|
|
1421
|
+
_currentRunThreadId = threadId;
|
|
1422
|
+
},
|
|
1423
|
+
onRunComplete: async (run, threadId) => {
|
|
1424
|
+
if (threadId)
|
|
1425
|
+
_runSendByThread.delete(threadId);
|
|
1426
|
+
await onRunComplete(run, threadId);
|
|
1427
|
+
},
|
|
636
1428
|
});
|
|
637
1429
|
}
|
|
638
1430
|
// Resolve mention providers
|
|
@@ -643,7 +1435,7 @@ export function createAgentChatPlugin(options) {
|
|
|
643
1435
|
// Mutable mode flag — starts in dev if environment allows
|
|
644
1436
|
let currentDevMode = canToggle;
|
|
645
1437
|
// Mount mode endpoint — GET returns current mode, POST toggles it (localhost only)
|
|
646
|
-
nitroApp.
|
|
1438
|
+
getH3App(nitroApp).use(`${routePath}/mode`, defineEventHandler(async (event) => {
|
|
647
1439
|
if (getMethod(event) === "POST") {
|
|
648
1440
|
if (!canToggle) {
|
|
649
1441
|
setResponseStatus(event, 403);
|
|
@@ -666,7 +1458,7 @@ export function createAgentChatPlugin(options) {
|
|
|
666
1458
|
}));
|
|
667
1459
|
// Mount save-key BEFORE the prefix handler so it isn't shadowed
|
|
668
1460
|
// Only functional in Node.js environments (writes to .env file)
|
|
669
|
-
nitroApp.
|
|
1461
|
+
getH3App(nitroApp).use(`${routePath}/save-key`, defineEventHandler(async (event) => {
|
|
670
1462
|
if (getMethod(event) !== "POST") {
|
|
671
1463
|
setResponseStatus(event, 405);
|
|
672
1464
|
return { error: "Method not allowed" };
|
|
@@ -682,7 +1474,7 @@ export function createAgentChatPlugin(options) {
|
|
|
682
1474
|
const path = await import("path");
|
|
683
1475
|
const { upsertEnvFile } = await import("./create-server.js");
|
|
684
1476
|
const envPath = path.join(process.cwd(), ".env");
|
|
685
|
-
upsertEnvFile(envPath, [
|
|
1477
|
+
await upsertEnvFile(envPath, [
|
|
686
1478
|
{ key: "ANTHROPIC_API_KEY", value: trimmedKey },
|
|
687
1479
|
]);
|
|
688
1480
|
}
|
|
@@ -694,7 +1486,7 @@ export function createAgentChatPlugin(options) {
|
|
|
694
1486
|
return { ok: true };
|
|
695
1487
|
}));
|
|
696
1488
|
// Mount file search endpoint
|
|
697
|
-
nitroApp.
|
|
1489
|
+
getH3App(nitroApp).use(`${routePath}/files`, defineEventHandler(async (event) => {
|
|
698
1490
|
if (getMethod(event) !== "GET") {
|
|
699
1491
|
setResponseStatus(event, 405);
|
|
700
1492
|
return { error: "Method not allowed" };
|
|
@@ -707,7 +1499,7 @@ export function createAgentChatPlugin(options) {
|
|
|
707
1499
|
if (currentDevMode) {
|
|
708
1500
|
const codebaseFiles = [];
|
|
709
1501
|
try {
|
|
710
|
-
collectFiles(process.cwd(), "", 0, codebaseFiles);
|
|
1502
|
+
await collectFiles(process.cwd(), "", 0, codebaseFiles);
|
|
711
1503
|
}
|
|
712
1504
|
catch {
|
|
713
1505
|
// Filesystem access failed — skip
|
|
@@ -751,7 +1543,7 @@ export function createAgentChatPlugin(options) {
|
|
|
751
1543
|
return { files: filtered.slice(0, 30) };
|
|
752
1544
|
}));
|
|
753
1545
|
// Mount skills listing endpoint
|
|
754
|
-
nitroApp.
|
|
1546
|
+
getH3App(nitroApp).use(`${routePath}/skills`, defineEventHandler(async (event) => {
|
|
755
1547
|
if (getMethod(event) !== "GET") {
|
|
756
1548
|
setResponseStatus(event, 405);
|
|
757
1549
|
return { error: "Method not allowed" };
|
|
@@ -761,8 +1553,9 @@ export function createAgentChatPlugin(options) {
|
|
|
761
1553
|
// In dev mode, scan .agents/skills/ directory
|
|
762
1554
|
if (currentDevMode) {
|
|
763
1555
|
try {
|
|
1556
|
+
const _fs = await lazyFs();
|
|
764
1557
|
const skillsDir = nodePath.join(process.cwd(), ".agents", "skills");
|
|
765
|
-
const entries =
|
|
1558
|
+
const entries = _fs.readdirSync(skillsDir, {
|
|
766
1559
|
withFileTypes: true,
|
|
767
1560
|
});
|
|
768
1561
|
for (const entry of entries) {
|
|
@@ -772,7 +1565,7 @@ export function createAgentChatPlugin(options) {
|
|
|
772
1565
|
if (entry.isDirectory()) {
|
|
773
1566
|
// Subdirectory layout: .agents/skills/<name>/SKILL.md
|
|
774
1567
|
const candidate = nodePath.join(skillsDir, entry.name, "SKILL.md");
|
|
775
|
-
if (!
|
|
1568
|
+
if (!_fs.existsSync(candidate))
|
|
776
1569
|
continue;
|
|
777
1570
|
skillFilePath = candidate;
|
|
778
1571
|
skillRelPath = `.agents/skills/${entry.name}/SKILL.md`;
|
|
@@ -786,7 +1579,7 @@ export function createAgentChatPlugin(options) {
|
|
|
786
1579
|
continue;
|
|
787
1580
|
}
|
|
788
1581
|
try {
|
|
789
|
-
const content =
|
|
1582
|
+
const content = _fs.readFileSync(skillFilePath, "utf-8");
|
|
790
1583
|
const fm = parseSkillFrontmatter(content);
|
|
791
1584
|
const skillName = fm.name || entry.name.replace(/\.md$/, "");
|
|
792
1585
|
if (!seenNames.has(skillName)) {
|
|
@@ -851,107 +1644,144 @@ export function createAgentChatPlugin(options) {
|
|
|
851
1644
|
return result;
|
|
852
1645
|
}));
|
|
853
1646
|
// Mount unified mentions endpoint (files + resources + custom providers)
|
|
854
|
-
nitroApp.
|
|
1647
|
+
getH3App(nitroApp).use(`${routePath}/mentions`, defineEventHandler(async (event) => {
|
|
855
1648
|
if (getMethod(event) !== "GET") {
|
|
856
1649
|
setResponseStatus(event, 405);
|
|
857
1650
|
return { error: "Method not allowed" };
|
|
858
1651
|
}
|
|
859
1652
|
const query = getQuery(event);
|
|
860
1653
|
const q = typeof query.q === "string" ? query.q.toLowerCase() : "";
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1654
|
+
const matchesQuery = (item) => !q ||
|
|
1655
|
+
item.label.toLowerCase().includes(q) ||
|
|
1656
|
+
(item.description?.toLowerCase().includes(q) ?? false);
|
|
1657
|
+
const enc = new TextEncoder();
|
|
1658
|
+
// Stream NDJSON — each source flushes its batch as soon as it's ready.
|
|
1659
|
+
setResponseHeader(event, "Content-Type", "application/x-ndjson");
|
|
1660
|
+
setResponseHeader(event, "Cache-Control", "no-cache");
|
|
1661
|
+
const stream = new ReadableStream({
|
|
1662
|
+
async start(controller) {
|
|
1663
|
+
const MAX_RESULTS = 50;
|
|
1664
|
+
let totalSent = 0;
|
|
1665
|
+
let cancelled = false;
|
|
1666
|
+
const flush = (batch) => {
|
|
1667
|
+
if (cancelled)
|
|
1668
|
+
return;
|
|
1669
|
+
const filtered = batch.filter(matchesQuery);
|
|
1670
|
+
if (filtered.length === 0)
|
|
1671
|
+
return;
|
|
1672
|
+
const remaining = MAX_RESULTS - totalSent;
|
|
1673
|
+
const toSend = filtered.slice(0, remaining);
|
|
1674
|
+
if (toSend.length > 0) {
|
|
1675
|
+
totalSent += toSend.length;
|
|
1676
|
+
try {
|
|
1677
|
+
controller.enqueue(enc.encode(JSON.stringify({ items: toSend }) + "\n"));
|
|
1678
|
+
}
|
|
1679
|
+
catch {
|
|
1680
|
+
// Stream was closed by client
|
|
1681
|
+
cancelled = true;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
// All sources run in parallel; each flushes independently.
|
|
1686
|
+
const sources = [];
|
|
1687
|
+
// 1. Resources from SQL (fast — flush first)
|
|
1688
|
+
sources.push((async () => {
|
|
1689
|
+
try {
|
|
1690
|
+
const resources = currentDevMode
|
|
1691
|
+
? await resourceListAccessible("local@localhost")
|
|
1692
|
+
: await resourceList(SHARED_OWNER);
|
|
1693
|
+
flush(resources.map((r) => {
|
|
1694
|
+
const isShared = r.owner === SHARED_OWNER;
|
|
1695
|
+
return {
|
|
1696
|
+
id: `resource:${r.path}`,
|
|
1697
|
+
label: r.path.split("/").pop() || r.path,
|
|
1698
|
+
description: r.path,
|
|
1699
|
+
icon: "file",
|
|
1700
|
+
source: isShared
|
|
1701
|
+
? "resource:shared"
|
|
1702
|
+
: "resource:private",
|
|
1703
|
+
refType: "file",
|
|
1704
|
+
refPath: r.path,
|
|
1705
|
+
section: "Files",
|
|
1706
|
+
};
|
|
1707
|
+
}));
|
|
1708
|
+
}
|
|
1709
|
+
catch { }
|
|
1710
|
+
})());
|
|
1711
|
+
// 2. Codebase files (dev mode only — can be slow on large repos)
|
|
1712
|
+
if (currentDevMode) {
|
|
1713
|
+
sources.push((async () => {
|
|
1714
|
+
const codebaseFiles = [];
|
|
1715
|
+
try {
|
|
1716
|
+
await collectFiles(process.cwd(), "", 0, codebaseFiles);
|
|
1717
|
+
}
|
|
1718
|
+
catch { }
|
|
1719
|
+
flush(codebaseFiles.map((f) => ({
|
|
1720
|
+
id: `codebase:${f.path}`,
|
|
1721
|
+
label: f.name,
|
|
1722
|
+
description: f.path !== f.name ? f.path : undefined,
|
|
1723
|
+
icon: f.type,
|
|
1724
|
+
source: "codebase",
|
|
1725
|
+
refType: "file",
|
|
1726
|
+
refPath: f.path,
|
|
1727
|
+
section: "Files",
|
|
1728
|
+
})));
|
|
1729
|
+
})());
|
|
1730
|
+
}
|
|
1731
|
+
// 3. Custom mention providers (each flushes independently)
|
|
1732
|
+
for (const [key, provider] of Object.entries(mentionProviders)) {
|
|
1733
|
+
sources.push((async () => {
|
|
1734
|
+
try {
|
|
1735
|
+
const providerItems = await provider.search(q, event);
|
|
1736
|
+
flush(providerItems.map((item) => ({
|
|
1737
|
+
id: item.id,
|
|
1738
|
+
label: item.label,
|
|
1739
|
+
description: item.description,
|
|
1740
|
+
icon: item.icon || provider.icon || "file",
|
|
1741
|
+
source: key,
|
|
1742
|
+
refType: item.refType,
|
|
1743
|
+
refPath: item.refPath,
|
|
1744
|
+
refId: item.refId,
|
|
1745
|
+
section: provider.label,
|
|
1746
|
+
})));
|
|
1747
|
+
}
|
|
1748
|
+
catch (e) {
|
|
1749
|
+
console.error(`[agent-native] Mention provider "${key}" failed:`, e);
|
|
1750
|
+
}
|
|
1751
|
+
})());
|
|
1752
|
+
}
|
|
1753
|
+
// 4. Peer agent discovery (network call — often slowest)
|
|
1754
|
+
sources.push((async () => {
|
|
1755
|
+
try {
|
|
1756
|
+
const agents = await discoverAgents(options?.appId);
|
|
1757
|
+
flush(agents.map((agent) => ({
|
|
1758
|
+
id: `agent:${agent.id}`,
|
|
1759
|
+
label: agent.name,
|
|
1760
|
+
description: agent.description,
|
|
1761
|
+
icon: "agent",
|
|
1762
|
+
source: "agent",
|
|
1763
|
+
refType: "agent",
|
|
1764
|
+
refPath: agent.url,
|
|
1765
|
+
refId: agent.id,
|
|
1766
|
+
section: "Agents",
|
|
1767
|
+
})));
|
|
1768
|
+
}
|
|
1769
|
+
catch (e) {
|
|
1770
|
+
console.error("[agent-native] Agent discovery failed:", e);
|
|
1771
|
+
}
|
|
1772
|
+
})());
|
|
1773
|
+
await Promise.all(sources);
|
|
1774
|
+
if (!cancelled)
|
|
1775
|
+
controller.close();
|
|
1776
|
+
},
|
|
1777
|
+
cancel() {
|
|
1778
|
+
// Client disconnected — stop enqueuing
|
|
1779
|
+
},
|
|
1780
|
+
});
|
|
1781
|
+
return stream;
|
|
952
1782
|
}));
|
|
953
1783
|
// ─── Generate thread title ──────────────────────────────────────────
|
|
954
|
-
nitroApp.
|
|
1784
|
+
getH3App(nitroApp).use(`${routePath}/generate-title`, defineEventHandler(async (event) => {
|
|
955
1785
|
if (getMethod(event) !== "POST") {
|
|
956
1786
|
setResponseStatus(event, 405);
|
|
957
1787
|
return { error: "Method not allowed" };
|
|
@@ -963,10 +1793,12 @@ export function createAgentChatPlugin(options) {
|
|
|
963
1793
|
setResponseStatus(event, 400);
|
|
964
1794
|
return { error: "message is required" };
|
|
965
1795
|
}
|
|
1796
|
+
// Strip mention markup: @[Name|type] → @Name
|
|
1797
|
+
const cleanMessage = message.replace(/@\[([^\]|]+)\|[^\]]*\]/g, "@$1");
|
|
966
1798
|
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
967
1799
|
if (!apiKey) {
|
|
968
1800
|
// Fallback: truncate the message
|
|
969
|
-
return { title:
|
|
1801
|
+
return { title: cleanMessage.trim().slice(0, 60) };
|
|
970
1802
|
}
|
|
971
1803
|
try {
|
|
972
1804
|
const res = await fetch("https://api.anthropic.com/v1/messages", {
|
|
@@ -982,38 +1814,42 @@ export function createAgentChatPlugin(options) {
|
|
|
982
1814
|
messages: [
|
|
983
1815
|
{
|
|
984
1816
|
role: "user",
|
|
985
|
-
content: `Generate a very short title (3-6 words, no quotes) for a chat that starts with this message:\n\n${
|
|
1817
|
+
content: `Generate a very short title (3-6 words, no quotes) for a chat that starts with this message:\n\n${cleanMessage.slice(0, 500)}`,
|
|
986
1818
|
},
|
|
987
1819
|
],
|
|
988
1820
|
}),
|
|
989
1821
|
});
|
|
990
1822
|
if (!res.ok) {
|
|
991
|
-
return { title:
|
|
1823
|
+
return { title: cleanMessage.trim().slice(0, 60) };
|
|
992
1824
|
}
|
|
993
1825
|
const data = (await res.json());
|
|
994
1826
|
const text = data.content?.[0]?.text?.trim();
|
|
995
|
-
return { title: text ||
|
|
1827
|
+
return { title: text || cleanMessage.trim().slice(0, 60) };
|
|
996
1828
|
}
|
|
997
1829
|
catch {
|
|
998
|
-
return { title:
|
|
1830
|
+
return { title: cleanMessage.trim().slice(0, 60) };
|
|
999
1831
|
}
|
|
1000
1832
|
}));
|
|
1001
1833
|
// ─── Run management endpoints (for hot-reload resilience) ─────────────
|
|
1002
1834
|
// GET /runs/active?threadId=X — check if there's an active run for a thread
|
|
1003
|
-
nitroApp.
|
|
1835
|
+
getH3App(nitroApp).use(`${routePath}/runs`, defineEventHandler(async (event) => {
|
|
1004
1836
|
// Auth check — ensure the user is authenticated
|
|
1005
1837
|
await getOwnerFromEvent(event);
|
|
1006
1838
|
const method = getMethod(event);
|
|
1007
1839
|
const url = event.node?.req?.url || event.path || "";
|
|
1008
1840
|
// Route: POST /runs/:id/abort
|
|
1009
|
-
|
|
1841
|
+
// Match both full URL (/runs/{id}/abort) and h3 prefix-stripped (/{id}/abort)
|
|
1842
|
+
const abortMatch = url.match(/\/runs\/([^/?]+)\/abort/) ||
|
|
1843
|
+
url.match(/^\/([^/?]+)\/abort/);
|
|
1010
1844
|
if (abortMatch && method === "POST") {
|
|
1011
1845
|
const runId = decodeURIComponent(abortMatch[1]);
|
|
1012
1846
|
abortRun(runId); // Aborts in-memory + marks aborted in SQL
|
|
1013
1847
|
return { ok: true };
|
|
1014
1848
|
}
|
|
1015
1849
|
// Route: GET /runs/:id/events?after=N
|
|
1016
|
-
|
|
1850
|
+
// Match both full URL (/runs/{id}/events) and h3 prefix-stripped (/{id}/events)
|
|
1851
|
+
const eventsMatch = url.match(/\/runs\/([^/?]+)\/events/) ||
|
|
1852
|
+
url.match(/^\/([^/?]+)\/events/);
|
|
1017
1853
|
if (eventsMatch && method === "GET") {
|
|
1018
1854
|
const runId = decodeURIComponent(eventsMatch[1]);
|
|
1019
1855
|
const query = getQuery(event);
|
|
@@ -1054,7 +1890,7 @@ export function createAgentChatPlugin(options) {
|
|
|
1054
1890
|
// ─── Thread management endpoints ──────────────────────────────────────
|
|
1055
1891
|
// Single handler for /threads and /threads/:id — h3's use() does prefix
|
|
1056
1892
|
// matching so we can't reliably split them into separate handlers.
|
|
1057
|
-
nitroApp.
|
|
1893
|
+
getH3App(nitroApp).use(`${routePath}/threads`, defineEventHandler(async (event) => {
|
|
1058
1894
|
const owner = await getOwnerFromEvent(event);
|
|
1059
1895
|
const method = getMethod(event);
|
|
1060
1896
|
// Determine if this is a specific-thread request.
|
|
@@ -1116,6 +1952,7 @@ export function createAgentChatPlugin(options) {
|
|
|
1116
1952
|
if (method === "POST") {
|
|
1117
1953
|
const body = await readBody(event);
|
|
1118
1954
|
const thread = await createThread(owner, {
|
|
1955
|
+
id: body?.id,
|
|
1119
1956
|
title: body?.title ?? "",
|
|
1120
1957
|
});
|
|
1121
1958
|
return thread;
|
|
@@ -1127,7 +1964,7 @@ export function createAgentChatPlugin(options) {
|
|
|
1127
1964
|
// This is mounted last because h3's use() is prefix-based, meaning /_agent-native/agent-chat
|
|
1128
1965
|
// also matches /_agent-native/agent-chat/threads/... — we skip sub-path requests here so the
|
|
1129
1966
|
// earlier-mounted handlers (mode, save-key, files, skills, mentions, threads) handle them.
|
|
1130
|
-
nitroApp.
|
|
1967
|
+
getH3App(nitroApp).use(routePath, defineEventHandler(async (event) => {
|
|
1131
1968
|
// Skip sub-path requests — they're handled by earlier-mounted handlers
|
|
1132
1969
|
const url = event.node?.req?.url || event.path || "";
|
|
1133
1970
|
const afterBase = url.slice(url.indexOf(routePath) + routePath.length);
|
|
@@ -1141,9 +1978,65 @@ export function createAgentChatPlugin(options) {
|
|
|
1141
1978
|
// created by users who authenticated via OAuth (e.g., Gmail).
|
|
1142
1979
|
const owner = await getOwnerFromEvent(event);
|
|
1143
1980
|
process.env.AGENT_USER_EMAIL = owner;
|
|
1981
|
+
// Set AGENT_ORG_ID so db-query/db-exec scope by org_id when applicable.
|
|
1982
|
+
// Priority: explicit resolveOrgId callback > session.orgId from Better Auth
|
|
1983
|
+
let resolvedOrgId = null;
|
|
1984
|
+
if (options?.resolveOrgId) {
|
|
1985
|
+
resolvedOrgId = await options.resolveOrgId(event);
|
|
1986
|
+
}
|
|
1987
|
+
else {
|
|
1988
|
+
try {
|
|
1989
|
+
const session = await getSession(event);
|
|
1990
|
+
resolvedOrgId = session?.orgId ?? null;
|
|
1991
|
+
}
|
|
1992
|
+
catch {
|
|
1993
|
+
// Session not available
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
if (resolvedOrgId) {
|
|
1997
|
+
process.env.AGENT_ORG_ID = resolvedOrgId;
|
|
1998
|
+
}
|
|
1999
|
+
else {
|
|
2000
|
+
delete process.env.AGENT_ORG_ID;
|
|
2001
|
+
}
|
|
1144
2002
|
const handler = currentDevMode && devHandler ? devHandler : prodHandler;
|
|
1145
2003
|
return handler(event);
|
|
1146
2004
|
}));
|
|
2005
|
+
// ─── Recurring Jobs Scheduler ──────────────────────────────────────
|
|
2006
|
+
// Poll every 60 seconds for due recurring jobs and execute them.
|
|
2007
|
+
// Uses setInterval so it works in all deployment environments without
|
|
2008
|
+
// requiring Nitro experimental tasks configuration.
|
|
2009
|
+
try {
|
|
2010
|
+
const { processRecurringJobs } = await import("../jobs/scheduler.js");
|
|
2011
|
+
const schedulerDeps = {
|
|
2012
|
+
getActions: () => ({
|
|
2013
|
+
...templateScripts,
|
|
2014
|
+
...resourceScripts,
|
|
2015
|
+
...chatScripts,
|
|
2016
|
+
...jobTools,
|
|
2017
|
+
}),
|
|
2018
|
+
getSystemPrompt: async (owner) => {
|
|
2019
|
+
const resources = await loadResourcesForPrompt(owner);
|
|
2020
|
+
const schemaBlock = await buildSchemaBlock(owner, false);
|
|
2021
|
+
return basePrompt + resources + schemaBlock;
|
|
2022
|
+
},
|
|
2023
|
+
apiKey: options?.apiKey ?? process.env.ANTHROPIC_API_KEY,
|
|
2024
|
+
model: resolvedModel,
|
|
2025
|
+
};
|
|
2026
|
+
// Start after a 10-second delay to let the server fully initialize
|
|
2027
|
+
setTimeout(() => {
|
|
2028
|
+
setInterval(() => {
|
|
2029
|
+
processRecurringJobs(schedulerDeps).catch((err) => {
|
|
2030
|
+
console.error("[recurring-jobs] Scheduler error:", err?.message);
|
|
2031
|
+
});
|
|
2032
|
+
}, 60_000);
|
|
2033
|
+
if (process.env.DEBUG)
|
|
2034
|
+
console.log("[recurring-jobs] Scheduler started (60s interval)");
|
|
2035
|
+
}, 10_000);
|
|
2036
|
+
}
|
|
2037
|
+
catch (err) {
|
|
2038
|
+
// Jobs module not available — skip silently
|
|
2039
|
+
}
|
|
1147
2040
|
};
|
|
1148
2041
|
}
|
|
1149
2042
|
/**
|