botmancers 0.3.0 → 0.4.2
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/CHANGELOG.md +79 -1
- package/README.md +162 -21
- package/app/.next/BUILD_ID +1 -1
- package/app/.next/app-path-routes-manifest.json +20 -1
- package/app/.next/build-manifest.json +3 -3
- package/app/.next/prerender-manifest.json +32 -4
- package/app/.next/required-server-files.json +2 -2
- package/app/.next/routes-manifest.json +143 -0
- package/app/.next/server/app/_global-error/page.js +1 -1
- package/app/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/app/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error.html +1 -1
- package/app/.next/server/app/_global-error.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/app/.next/server/app/_not-found/page.js +1 -1
- package/app/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_not-found.html +1 -1
- package/app/.next/server/app/_not-found.rsc +2 -2
- package/app/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/api/agent-deck/decks/route.js +2 -2
- package/app/.next/server/app/api/agent-deck/decks/route.js.nft.json +1 -1
- package/app/.next/server/app/api/agent-deck/settings/route.js +2 -2
- package/app/.next/server/app/api/agent-deck/settings/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/[id]/config/route.js +2 -2
- package/app/.next/server/app/api/bots/[id]/config/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js +9 -0
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route.js +9 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route.js.nft.json +1 -0
- package/app/.next/server/app/api/bots/[id]/sessions/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/bots/[id]/skill/route.js +2 -2
- package/app/.next/server/app/api/bots/[id]/skill/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/availability/route.js +1 -1
- package/app/.next/server/app/api/bots/availability/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/delete-preview/route.js +3 -3
- package/app/.next/server/app/api/bots/delete-preview/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/import/route.js +2 -2
- package/app/.next/server/app/api/bots/import/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/manage/route.js +2 -2
- package/app/.next/server/app/api/bots/manage/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/name-migrations/route.js +2 -2
- package/app/.next/server/app/api/bots/name-migrations/route.js.nft.json +1 -1
- package/app/.next/server/app/api/bots/route.js +6 -6
- package/app/.next/server/app/api/bots/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/approve/route.js +2 -2
- package/app/.next/server/app/api/conversations/[id]/approve/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/deny/route.js +2 -2
- package/app/.next/server/app/api/conversations/[id]/deny/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/draft/route.js +2 -2
- package/app/.next/server/app/api/conversations/[id]/draft/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js +2 -2
- package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/messages/route.js +6 -6
- package/app/.next/server/app/api/conversations/[id]/messages/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/route.js +2 -2
- package/app/.next/server/app/api/conversations/[id]/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/[id]/stop/route.js +3 -3
- package/app/.next/server/app/api/conversations/[id]/stop/route.js.nft.json +1 -1
- package/app/.next/server/app/api/conversations/route.js +2 -2
- package/app/.next/server/app/api/conversations/route.js.nft.json +1 -1
- package/app/.next/server/app/api/exchanges/[id]/cancel/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/exchanges/[id]/cancel/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/exchanges/[id]/cancel/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/exchanges/[id]/cancel/route.js +11 -0
- package/app/.next/server/app/api/exchanges/[id]/cancel/route.js.nft.json +1 -0
- package/app/.next/server/app/api/exchanges/[id]/cancel/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/exchanges/[id]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/exchanges/[id]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/exchanges/[id]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/exchanges/[id]/route.js +11 -0
- package/app/.next/server/app/api/exchanges/[id]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/exchanges/[id]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/exchanges/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/exchanges/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/exchanges/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/exchanges/route.js +12 -0
- package/app/.next/server/app/api/exchanges/route.js.nft.json +1 -0
- package/app/.next/server/app/api/exchanges/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/files/[name]/route.js +1 -1
- package/app/.next/server/app/api/files/[name]/route.js.nft.json +1 -1
- package/app/.next/server/app/api/groups/route.js +2 -2
- package/app/.next/server/app/api/groups/route.js.nft.json +1 -1
- package/app/.next/server/app/api/health/route.js.nft.json +1 -1
- package/app/.next/server/app/api/import-capabilities/route.js +1 -1
- package/app/.next/server/app/api/import-capabilities/route.js.nft.json +1 -1
- package/app/.next/server/app/api/marketplace-handoff/route.js +1 -1
- package/app/.next/server/app/api/marketplace-handoff/route.js.nft.json +1 -1
- package/app/.next/server/app/api/marketplace-handoff/status/route.js +1 -1
- package/app/.next/server/app/api/marketplace-handoff/status/route.js.nft.json +1 -1
- package/app/.next/server/app/api/mcp/route.js +2 -2
- package/app/.next/server/app/api/mcp/route.js.nft.json +1 -1
- package/app/.next/server/app/api/messages/[id]/between/route.js +2 -2
- package/app/.next/server/app/api/messages/[id]/between/route.js.nft.json +1 -1
- package/app/.next/server/app/api/service-grants/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/service-grants/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/service-grants/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/service-grants/route.js +9 -0
- package/app/.next/server/app/api/service-grants/route.js.nft.json +1 -0
- package/app/.next/server/app/api/service-grants/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js +4 -3
- package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js.nft.json +1 -1
- package/app/.next/server/app/api/v0/agents/[agentId]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/agents/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/agents/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/agents/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/agents/route.js +11 -0
- package/app/.next/server/app/api/v0/agents/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/agents/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/capabilities/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/capabilities/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/capabilities/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/capabilities/route.js +11 -0
- package/app/.next/server/app/api/v0/capabilities/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/capabilities/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/conversations/[id]/route.js +4 -3
- package/app/.next/server/app/api/v0/conversations/[id]/route.js.nft.json +1 -1
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js +11 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route.js +11 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/exchanges/[id]/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/exchanges/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/exchanges/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/exchanges/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/exchanges/route.js +11 -0
- package/app/.next/server/app/api/v0/exchanges/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/exchanges/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/v0/mcp/route.js +5 -3
- package/app/.next/server/app/api/v0/mcp/route.js.nft.json +1 -1
- package/app/.next/server/app/api/v0/requests/[id]/route.js +4 -3
- package/app/.next/server/app/api/v0/requests/[id]/route.js.nft.json +1 -1
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route/app-paths-manifest.json +3 -0
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route/build-manifest.json +12 -0
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route/server-reference-manifest.json +4 -0
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js +11 -0
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js.nft.json +1 -0
- package/app/.next/server/app/api/v0/sessions/[ref]/messages/route_client-reference-manifest.js +3 -0
- package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js +5 -5
- package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js.nft.json +1 -1
- package/app/.next/server/app/api/wakes/[id]/decision/route.js +5 -5
- package/app/.next/server/app/api/wakes/[id]/decision/route.js.nft.json +1 -1
- package/app/.next/server/app/api/wakes/[id]/retry/route.js +5 -5
- package/app/.next/server/app/api/wakes/[id]/retry/route.js.nft.json +1 -1
- package/app/.next/server/app/bots/[id]/config/page.js +1 -1
- package/app/.next/server/app/bots/[id]/config/page.js.nft.json +1 -1
- package/app/.next/server/app/bots/[id]/config/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/exchanges/page/app-paths-manifest.json +3 -0
- package/app/.next/server/app/exchanges/page/build-manifest.json +20 -0
- package/app/.next/server/app/exchanges/page/next-font-manifest.json +11 -0
- package/app/.next/server/app/exchanges/page/react-loadable-manifest.json +1 -0
- package/app/.next/server/app/exchanges/page/server-reference-manifest.json +4 -0
- package/app/.next/server/app/exchanges/page.js +13 -0
- package/app/.next/server/app/exchanges/page.js.nft.json +1 -0
- package/app/.next/server/app/exchanges/page_client-reference-manifest.js +3 -0
- package/app/.next/server/app/exchanges.html +1 -0
- package/app/.next/server/app/exchanges.meta +34 -0
- package/app/.next/server/app/exchanges.rsc +22 -0
- package/app/.next/server/app/exchanges.segments/_full.segment.rsc +22 -0
- package/app/.next/server/app/exchanges.segments/_tree.segment.rsc +4 -0
- package/app/.next/server/app/exchanges.segments/exchanges/__PAGE__.segment.rsc +26 -0
- package/app/.next/server/app/index.html +1 -1
- package/app/.next/server/app/index.rsc +3 -3
- package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
- package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
- package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/page.js +1 -1
- package/app/.next/server/app/page.js.nft.json +1 -1
- package/app/.next/server/app/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/settings/page.js +1 -1
- package/app/.next/server/app/settings/page.js.nft.json +1 -1
- package/app/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/settings.html +1 -1
- package/app/.next/server/app/settings.rsc +2 -2
- package/app/.next/server/app/settings.segments/_full.segment.rsc +2 -2
- package/app/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
- package/app/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +2 -2
- package/app/.next/server/app/threads/[id]/page/app-paths-manifest.json +3 -0
- package/app/.next/server/app/threads/[id]/page/build-manifest.json +20 -0
- package/app/.next/server/app/threads/[id]/page/next-font-manifest.json +11 -0
- package/app/.next/server/app/threads/[id]/page/react-loadable-manifest.json +1 -0
- package/app/.next/server/app/threads/[id]/page/server-reference-manifest.json +4 -0
- package/app/.next/server/app/threads/[id]/page.js +13 -0
- package/app/.next/server/app/threads/[id]/page.js.nft.json +1 -0
- package/app/.next/server/app/threads/[id]/page_client-reference-manifest.js +3 -0
- package/app/.next/server/app-paths-manifest.json +20 -1
- package/app/.next/server/chunks/0ivl_api_v0_agents_[agentId]_conversations_[conversationId]_route_actions_0lvijtu.js +3 -0
- package/app/.next/server/chunks/1oeh_server_app_api_v0_agents_[agentId]_conversations_route_actions_0ko3117.js +3 -0
- package/app/.next/server/chunks/1oeh_server_app_api_v0_agents_[agentId]_sessions_[ref]_route_actions_0o7q3vt.js +3 -0
- package/app/.next/server/chunks/{[externals]__18bqksw._.js → [externals]__06lqs5i._.js} +1 -1
- package/app/.next/server/chunks/{[root-of-the-server]__1vxmbdl._.js → [root-of-the-server]__0-45blq._.js} +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__0ab4e_k._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__0izjfmr._.js +285 -53
- package/app/.next/server/chunks/{[root-of-the-server]__07l_rgn._.js → [root-of-the-server]__0j0i8xz._.js} +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__0wtzcge._.js +3 -0
- package/app/.next/server/chunks/{[root-of-the-server]__19hjzs0._.js → [root-of-the-server]__15hknun._.js} +1 -1
- package/app/.next/server/chunks/{[root-of-the-server]__08i4wq6._.js → [root-of-the-server]__16ikszu._.js} +1 -1
- package/app/.next/server/chunks/{[root-of-the-server]__1khwkvb._.js → [root-of-the-server]__1c3e2ds._.js} +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__1kvvdpx._.js +2 -2
- package/app/.next/server/chunks/[root-of-the-server]__1qoa704._.js +2 -2
- package/app/.next/server/chunks/[root-of-the-server]__1slu7d7._.js +7 -0
- package/app/.next/server/chunks/_06rti77._.js +30 -0
- package/app/.next/server/chunks/_09k38l1._.js +3 -0
- package/app/.next/server/chunks/_0dlg5kj._.js +30 -0
- package/app/.next/server/chunks/_0dyculb._.js +30 -0
- package/app/.next/server/chunks/_0eig2jc._.js +30 -0
- package/app/.next/server/chunks/_0ggf7vy._.js +1 -1
- package/app/.next/server/chunks/_0kghtb6._.js +3 -0
- package/app/.next/server/chunks/_0th2j4w._.js +1 -1
- package/app/.next/server/chunks/_0uz7r06._.js +30 -0
- package/app/.next/server/chunks/_0x05ts4._.js +3 -0
- package/app/.next/server/chunks/_0y3geoj._.js +30 -0
- package/app/.next/server/chunks/_1-5mthb._.js +1 -1
- package/app/.next/server/chunks/_12tq5uv._.js +30 -0
- package/app/.next/server/chunks/_147-4gl._.js +3 -0
- package/app/.next/server/chunks/_14ky6a2._.js +30 -0
- package/app/.next/server/chunks/_16kbxdt._.js +30 -0
- package/app/.next/server/chunks/_1963m2f._.js +30 -0
- package/app/.next/server/chunks/_1_34_h3._.js +30 -0
- package/app/.next/server/chunks/_1cc-2mx._.js +3 -0
- package/app/.next/server/chunks/_1inyx08._.js +1 -1
- package/app/.next/server/chunks/_1nurj3f._.js +30 -0
- package/app/.next/server/chunks/_1p2rf_n._.js +30 -0
- package/app/.next/server/chunks/_1u6tw78._.js +30 -0
- package/app/.next/server/chunks/_20azcus._.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_sessions_[ref]_route_actions_02gp9-5.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_sessions_route_actions_1s_wxg4.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_exchanges_[id]_cancel_route_actions_0lh0fl4.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_exchanges_[id]_route_actions_1w4jhin.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_exchanges_route_actions_028wchg.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_service-grants_route_actions_1459xk1.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_agents_[agentId]_route_actions_127sxvv.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_agents_[agentId]_sessions_route_actions_0pm6tcu.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_agents_route_actions_00azkhd.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_capabilities_route_actions_0d-eefd.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_exchanges_[id]_cancel_route_actions_1hb2q7i.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_exchanges_[id]_route_actions_098f50-.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_exchanges_route_actions_1ftmhhm.js +3 -0
- package/app/.next/server/chunks/_next-internal_server_app_api_v0_sessions_[ref]_messages_route_actions_1-rgf_k.js +3 -0
- package/app/.next/server/chunks/lib_0kik6bx._.js +1 -1
- package/app/.next/server/chunks/lib_0pe3tiv._.js +1 -1
- package/app/.next/server/chunks/lib_0t3s3rj._.js +30 -0
- package/app/.next/server/chunks/lib_0zxi6rx._.js +148 -0
- package/app/.next/server/chunks/lib_12udr7g._.js +148 -0
- package/app/.next/server/chunks/lib_service-api-http_ts_0xzqhny._.js +25 -0
- package/app/.next/server/chunks/lib_session-catalog_ts_1i7f38f._.js +30 -0
- package/app/.next/server/chunks/ssr/{[root-of-the-server]__0sq4frf._.js → [root-of-the-server]__03186rx._.js} +1 -1
- package/app/.next/server/chunks/ssr/[root-of-the-server]__03xw2d9._.js +3 -0
- package/app/.next/server/chunks/ssr/{[root-of-the-server]__1x7o-fe._.js → [root-of-the-server]__0zzcbqg._.js} +1 -1
- package/app/.next/server/chunks/ssr/{[root-of-the-server]__029oxo_._.js → [root-of-the-server]__1feicqq._.js} +1 -1
- package/app/.next/server/chunks/ssr/[root-of-the-server]__1t063pe._.js +3 -0
- package/app/.next/server/chunks/ssr/_00ysoah._.js +3 -0
- package/app/.next/server/chunks/ssr/_157wnb_._.js +3 -0
- package/app/.next/server/chunks/ssr/_1o94bnv._.js +1 -1
- package/app/.next/server/chunks/ssr/_next-internal_server_app_exchanges_page_actions_0hcso2x.js +3 -0
- package/app/.next/server/chunks/ssr/_next-internal_server_app_threads_[id]_page_actions_1fte2n3.js +3 -0
- package/app/.next/server/chunks/ssr/app_1-nwnha._.js +3 -0
- package/app/.next/server/chunks/ssr/app_bots_[id]_config_page_tsx_1e0uue9._.js +3 -0
- package/app/.next/server/chunks/ssr/app_components_AgentDeckRuntime_tsx_024janf._.js +3 -0
- package/app/.next/server/chunks/ssr/node_modules_1nkgb45._.js +23 -0
- package/app/.next/server/chunks/ssr/node_modules_next_0x3i8za._.js +131 -0
- package/app/.next/server/middleware-build-manifest.js +3 -3
- package/app/.next/server/middleware.js +1 -1
- package/app/.next/server/next-font-manifest.js +1 -1
- package/app/.next/server/next-font-manifest.json +8 -0
- package/app/.next/server/pages/404.html +1 -1
- package/app/.next/server/pages/500.html +1 -1
- package/app/.next/server/prefetch-hints.json +14 -0
- package/app/.next/server/server-reference-manifest.js +1 -1
- package/app/.next/server/server-reference-manifest.json +1 -1
- package/app/.next/static/chunks/1i5xroz391zkb.js +1 -0
- package/app/.next/static/chunks/{3zqbpbm93yqzh.css → 1vz50l951sr9e.css} +1 -1
- package/app/.next/static/chunks/24ggj819yt3y6.js +1 -0
- package/app/.next/static/chunks/2_8lcalraul5s.js +3 -0
- package/app/.next/static/chunks/30i0-l04mmdvk.js +1 -0
- package/app/BUILD_INFO.json +2 -2
- package/app/package.json +1 -1
- package/app/server.js +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +33 -5
- package/dist/clients.d.ts +86 -0
- package/dist/clients.js +635 -0
- package/dist/config.js +2 -2
- package/dist/contract.d.ts +6 -1
- package/dist/contract.js +28 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/managed.js +7 -0
- package/dist/product.d.ts +2 -0
- package/dist/product.js +6 -0
- package/dist/server.js +5 -4
- package/dist/upstream.js +21 -7
- package/package.json +7 -6
- package/schemas/botmancers.mcp.v2.tools.json +2981 -0
- package/skills/botmancers-collaboration/SKILL.md +99 -0
- package/skills/botmancers-collaboration/references/workflows.md +209 -0
- package/app/.next/server/chunks/[root-of-the-server]__09d-yrq._.js +0 -3
- package/app/.next/server/chunks/[root-of-the-server]__0za34e1._.js +0 -7
- package/app/.next/server/chunks/[root-of-the-server]__1fjpie4._.js +0 -3
- package/app/.next/server/chunks/[root-of-the-server]__1qanlbg._.js +0 -3
- package/app/.next/server/chunks/[root-of-the-server]__20wve4_._.js +0 -3
- package/app/.next/server/chunks/lib_051fv4x._.js +0 -111
- package/app/.next/server/chunks/lib_07adeq3._.js +0 -111
- package/app/.next/server/chunks/ssr/_0k_7i66._.js +0 -131
- package/app/.next/server/chunks/ssr/_1flnty7._.js +0 -23
- package/app/.next/server/chunks/ssr/node_modules_@swc_helpers_cjs__interop_require_default_cjs_1ztp13a._.js +0 -3
- package/app/.next/static/chunks/0qbtymorcz-l9.js +0 -3
- /package/app/.next/static/{u4r8RPgEfpxk-DGXeKV6g → ewp56HqU5-d9bpFog3bli}/_buildManifest.js +0 -0
- /package/app/.next/static/{u4r8RPgEfpxk-DGXeKV6g → ewp56HqU5-d9bpFog3bli}/_clientMiddlewareManifest.js +0 -0
- /package/app/.next/static/{u4r8RPgEfpxk-DGXeKV6g → ewp56HqU5-d9bpFog3bli}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",()=>require("better-sqlite3-90e2652d1716b047"))},62294,64974,11626,35613,30098,e=>{"use strict";var
|
|
1
|
+
module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",()=>require("better-sqlite3-90e2652d1716b047"))},62294,64974,11626,35613,30098,e=>{"use strict";let t;var n=e.i(85148),i=e.i(22734),r=e.i(14747),a=e.i(54799),s=e.i(62349),o=e.i(16979);let E=Object.freeze(["conversation","implementation","review","revision"]),d=Object.freeze(["readonly","edit"]);Object.freeze(["ui","api","wake","continuation","exchange"]);let _=Object.freeze({conversation:"readonly",implementation:"edit",review:"readonly",revision:"edit"});function c(e){return"string"==typeof e&&E.includes(e)}function u(e,t){return{ok:!1,code:e,reason:t}}function T(e){var t,n,i,r;if(!c(e.executionKind))return u("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.executionKind))}.`);let a=e.executionKind,s=(t=e.entryPoint,n=a,i=e.wakeSyntax,r=!0===e.resumesWorkRequest,"ui"===t||"api"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A direct message runs as a read-only conversation turn, not ${n}.`}:"direct_message_conversation":"continuation"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A coordinator continuation runs as a read-only conversation turn, not ${n}.`}:"coordinator_continuation":"exchange"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A session exchange runs as a read-only conversation turn, not ${n}.`}:"session_exchange_conversation":"wake"!==t?{code:"unsupported_authority",reason:"Unknown policy entry point."}:"legacy"===i?"conversation"!==n?{code:"unsupported_authority",reason:`A legacy WAKE directive runs as a conversation turn, not ${n}.`}:"legacy_wake_conversation":"structured"!==i?{code:"unsupported_authority",reason:"Unknown Wake syntax."}:"revision"===n!==r?{code:"unsupported_authority",reason:"revision"===n?"A revision names the Work Request it resumes.":"Only a revision resumes a Work Request."}:"structured_wake");return"string"!=typeof s?u(s.code,s.reason):{ok:!0,policy:Object.freeze({policy_version:1,execution_kind:a,tool_profile:_[a],entry_point:e.entryPoint,rule:s})}}let l=new Set(["policy_version","execution_kind","tool_profile","entry_point","rule"]);function N(e){if(!e||"object"!=typeof e||Array.isArray(e))return u("malformed_policy","The execution policy snapshot is missing.");let t=Object.keys(e);if(t.length!==l.size||t.some(e=>!l.has(e)))return u("malformed_policy","The execution policy snapshot has unexpected fields.");if(1!==e.policy_version)return u("malformed_policy","Unsupported execution policy version.");if(!c(e.execution_kind))return u("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.execution_kind))}.`);if(!d.includes(e.tool_profile))return u("unsupported_authority",`Unsupported tool profile ${JSON.stringify(String(e.tool_profile))}.`);if(_[e.execution_kind]!==e.tool_profile)return u("unsupported_authority",`Execution kind ${e.execution_kind} requires the ${_[e.execution_kind]} tool profile.`);let n={direct_message_conversation:{entry:["ui","api"],kinds:["conversation"]},legacy_wake_conversation:{entry:["wake"],kinds:["conversation"]},coordinator_continuation:{entry:["continuation"],kinds:["conversation"]},session_exchange_conversation:{entry:["exchange"],kinds:["conversation"]},structured_wake:{entry:["wake"],kinds:[...E]}},i="string"==typeof e.rule?n[e.rule]:void 0;return i&&i.entry.includes(e.entry_point)?i.kinds.includes(e.execution_kind)?{ok:!0,policy:Object.freeze({...e})}:u("unsupported_authority",`Rule ${e.rule} does not grant ${e.execution_kind}.`):u("malformed_policy","The execution policy rule does not match its entry point.")}e.s(["TOOL_PROFILE_FOR_KIND",0,_,"authorizeWorkRequest",0,function(e){let t;if(!c(e.execution_kind))return u("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.execution_kind))}.`);try{t="string"==typeof e.policy_snapshot?JSON.parse(e.policy_snapshot):null}catch{return u("malformed_policy","The policy snapshot is not valid JSON.")}let n=N(t&&"object"==typeof t&&!Array.isArray(t)?t.execution_policy:void 0);return n.ok?n.policy.execution_kind!==e.execution_kind||n.policy.tool_profile!==e.tool_profile?u("unsupported_authority","The Work Request authority does not match its policy snapshot."):t.tool_profile!==e.tool_profile?u("malformed_policy","The policy snapshot tool profile does not match the Work Request."):n:n},"isExecutionKind",0,c,"selectExecutionPolicy",0,T,"validateExecutionPolicy",0,N],64974);let p=Object.freeze({max_attempts:1,base_delay_ms:1e3,max_delay_ms:6e4,attempt_timeout_ms:null});function R(e){if(void 0===e||!/^\d+$/.test(e.trim()))return null;let t=Number(e.trim());return Number.isSafeInteger(t)&&t>0?t:null}function O(e=process.env){let t=R(e.BOTMANCERS_RETRY_MAX_ATTEMPTS),n=R(e.BOTMANCERS_RETRY_BASE_DELAY_MS)??p.base_delay_ms,i=R(e.BOTMANCERS_RETRY_MAX_DELAY_MS)??p.max_delay_ms,r=m({max_attempts:null===t?p.max_attempts:Math.min(t,10),base_delay_ms:n,max_delay_ms:Math.max(i,n),attempt_timeout_ms:R(e.BOTMANCERS_ATTEMPT_TIMEOUT_MS)});return{deadlineMs:R(e.BOTMANCERS_REQUEST_DEADLINE_MS),retryPolicy:r.ok?r.policy:{...p}}}function m(e){if(!e||"object"!=typeof e||Array.isArray(e))return{ok:!1,reason:"A retry policy is an object."};let t=e=>"number"==typeof e&&Number.isSafeInteger(e);if(!t(e.max_attempts)||e.max_attempts<1||e.max_attempts>10)return{ok:!1,reason:"max_attempts must be an integer from 1 to 10."};if(!t(e.base_delay_ms)||e.base_delay_ms<0)return{ok:!1,reason:"base_delay_ms must be a non-negative integer."};if(!t(e.max_delay_ms)||e.max_delay_ms<e.base_delay_ms)return{ok:!1,reason:"max_delay_ms must be an integer no smaller than base_delay_ms."};let n=e.attempt_timeout_ms??null;return null!==n&&(!t(n)||n<1)?{ok:!1,reason:"attempt_timeout_ms must be a positive integer or null."}:{ok:!0,policy:{max_attempts:e.max_attempts,base_delay_ms:e.base_delay_ms,max_delay_ms:e.max_delay_ms,attempt_timeout_ms:n}}}let L=["agent_deck_token_missing","agent_deck_unauthorized","agent_deck_forbidden"],g={unavailable:"retryable",runtime_failed:"retryable",timed_out:"retryable",launch_failed:"terminal",unsupported_authority:"terminal",result_contract:"terminal",cancelled:"terminal",session_mismatch:"manual_attention"};e.s(["DEFAULT_RETRY_POLICY",0,p,"attemptDeadline",0,function(e,t,n){let i=null===e.attempt_timeout_ms?null:n+e.attempt_timeout_ms;return null===i?t:null===t?i:Math.min(i,t)},"classifyFailure",0,function(e,t=null){return t&&L.includes(t)?"manual_attention":g[e??"runtime_failed"]??"terminal"},"decideRetry",0,function(e){var t;let n;if("terminal"===e.disposition)return{action:"fail",disposition:"terminal"};let i=e.attemptCount<e.policy.max_attempts;if("manual_attention"===e.disposition)return i?{action:"attention"}:{action:"fail",disposition:"terminal"};if(!i)return{action:"exhausted"};let r=e.attemptCount,a=(t=e.policy,n=Math.max(0,r-1),Math.min(t.max_delay_ms,t.base_delay_ms*2**Math.min(n,30))),s=e.now+a;return null!==e.deadlineAt&&s>=e.deadlineAt?{action:"deadline"}:{action:"retry",nextEligibleAt:s,delayMs:a,retry:r}},"requestControlDefaultsFromEnv",0,O,"storedRetryPolicy",0,function(e){if(!e)return{...p};try{let t=m(JSON.parse(e));return t.ok?t.policy:{...p}}catch{return{...p}}},"validateRetryPolicy",0,m],11626);let I=["queued","extracting","delivering","completed","failed","cancelled"],S=["completed","failed","cancelled"],A={queued:["extracting","failed","cancelled"],extracting:["delivering","completed","failed","cancelled"],delivering:["completed","failed","cancelled"],completed:[],failed:[],cancelled:[]},v=Object.freeze({instructionChars:4e3,packetChars:16e3,packetObjectiveChars:2e3,packetListItems:20,packetItemChars:500,answerChars:16e3,replyChars:16e3,extractionOutputChars:32e3,promptChars:24e3}),k=["queued","blocked","running","waiting","completed","failed","cancelled"],f=["completed","failed","cancelled"],q={queued:["running","blocked","cancelled","failed"],blocked:["queued","cancelled","failed"],running:["waiting","queued","completed","failed","cancelled"],waiting:["running","queued","cancelled","failed"],completed:[],failed:[],cancelled:[]},h=["dispatcher","ui_message","ui_continuation"];class C extends Error{code;constructor(e,t){super(t),this.code=e}}let w=f.map(e=>`'${e}'`).join(", "),D=k.map(e=>`'${e}'`).join(", "),y=[{version:1,name:"core_engine_tables",up:e=>{e.exec(`
|
|
2
2
|
CREATE TABLE work_request_transitions (
|
|
3
3
|
from_state TEXT NOT NULL,
|
|
4
4
|
to_state TEXT NOT NULL,
|
|
@@ -22,7 +22,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
22
22
|
idempotency_key TEXT NOT NULL CHECK (length(idempotency_key) > 0),
|
|
23
23
|
request_hash TEXT NOT NULL,
|
|
24
24
|
policy_snapshot TEXT NOT NULL,
|
|
25
|
-
state TEXT NOT NULL CHECK (state IN (${
|
|
25
|
+
state TEXT NOT NULL CHECK (state IN (${D})),
|
|
26
26
|
state_reason TEXT,
|
|
27
27
|
result TEXT,
|
|
28
28
|
error_code TEXT,
|
|
@@ -32,7 +32,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
32
32
|
created_at INTEGER NOT NULL,
|
|
33
33
|
updated_at INTEGER NOT NULL,
|
|
34
34
|
terminal_at INTEGER,
|
|
35
|
-
CHECK ((state IN (${
|
|
35
|
+
CHECK ((state IN (${w})) = (terminal_at IS NOT NULL)),
|
|
36
36
|
FOREIGN KEY (source_conversation_id) REFERENCES conversations(id),
|
|
37
37
|
FOREIGN KEY (target_agent_id) REFERENCES bots(id),
|
|
38
38
|
FOREIGN KEY (parent_request_id) REFERENCES work_requests(id),
|
|
@@ -146,7 +146,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
146
146
|
END;
|
|
147
147
|
|
|
148
148
|
CREATE TRIGGER trg_work_requests_terminal BEFORE UPDATE ON work_requests
|
|
149
|
-
WHEN OLD.state IN (${
|
|
149
|
+
WHEN OLD.state IN (${w})
|
|
150
150
|
BEGIN
|
|
151
151
|
SELECT RAISE(ABORT, 'terminal work_requests are immutable');
|
|
152
152
|
END;
|
|
@@ -218,7 +218,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
218
218
|
BEGIN
|
|
219
219
|
SELECT RAISE(ABORT, 'engine_events are append-only');
|
|
220
220
|
END;
|
|
221
|
-
`);let t=e.prepare("INSERT INTO work_request_transitions (from_state, to_state) VALUES (?, ?)");for(let e of
|
|
221
|
+
`);let t=e.prepare("INSERT INTO work_request_transitions (from_state, to_state) VALUES (?, ?)");for(let e of k)for(let n of q[e])t.run(e,n)}},{version:2,name:"core_engine_referential_integrity",up:e=>{e.exec(`
|
|
222
222
|
-- Foreign keys (delete side): RESTRICT. A referenced row cannot be
|
|
223
223
|
-- deleted while anything still points at it; deleteEngineRecords
|
|
224
224
|
-- removes dependants first, in one transaction.
|
|
@@ -304,7 +304,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
304
304
|
AND (b.request_id IS NULL OR br.root_request_id = r.root_request_id)
|
|
305
305
|
);
|
|
306
306
|
END;
|
|
307
|
-
`)}},{version:3,name:"core_engine_hardening",up:e=>{let t=
|
|
307
|
+
`)}},{version:3,name:"core_engine_hardening",up:e=>{let t=k.flatMap(e=>q[e].map(t=>`'${e}>${t}'`)).join(", ");e.exec(`
|
|
308
308
|
-- The lifecycle allowlist lives in the trigger itself, so no data
|
|
309
309
|
-- write can widen or break it. work_request_transitions stays as a
|
|
310
310
|
-- readable copy and is locked against writes.
|
|
@@ -502,7 +502,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
502
502
|
'request_waiting', 'request_completed', 'request_failed', 'request_cancelled',
|
|
503
503
|
'question', 'result', 'artifact'
|
|
504
504
|
)),
|
|
505
|
-
state TEXT CHECK (state IN (${
|
|
505
|
+
state TEXT CHECK (state IN (${D})),
|
|
506
506
|
text TEXT NOT NULL,
|
|
507
507
|
data TEXT NOT NULL,
|
|
508
508
|
sort_at INTEGER NOT NULL,
|
|
@@ -715,7 +715,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
715
715
|
'finalization_preparing', 'finalization_committed', 'finalization_blocked',
|
|
716
716
|
'finalization_failed', 'finalization_canceled', 'finalization_rejected'
|
|
717
717
|
)),
|
|
718
|
-
state TEXT CHECK (state IN (${
|
|
718
|
+
state TEXT CHECK (state IN (${D})),
|
|
719
719
|
text TEXT NOT NULL,
|
|
720
720
|
data TEXT NOT NULL,
|
|
721
721
|
sort_at INTEGER NOT NULL,
|
|
@@ -860,7 +860,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
860
860
|
'finalization_failed', 'finalization_canceled', 'finalization_rejected',
|
|
861
861
|
'request_cancel_requested', 'request_timed_out', 'request_retry_scheduled', 'request_retries_exhausted'
|
|
862
862
|
)),
|
|
863
|
-
state TEXT CHECK (state IN (${
|
|
863
|
+
state TEXT CHECK (state IN (${D})),
|
|
864
864
|
text TEXT NOT NULL,
|
|
865
865
|
data TEXT NOT NULL,
|
|
866
866
|
sort_at INTEGER NOT NULL,
|
|
@@ -981,7 +981,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
981
981
|
'request_cancel_requested', 'request_timed_out', 'request_retry_scheduled', 'request_retries_exhausted',
|
|
982
982
|
'wake_rejected', 'lineage_stopped'
|
|
983
983
|
)),
|
|
984
|
-
state TEXT CHECK (state IN (${
|
|
984
|
+
state TEXT CHECK (state IN (${D})),
|
|
985
985
|
text TEXT NOT NULL,
|
|
986
986
|
data TEXT NOT NULL,
|
|
987
987
|
sort_at INTEGER NOT NULL,
|
|
@@ -1012,14 +1012,14 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1012
1012
|
SELECT id, parent_request_id, root_request_id, wake_event_id, requester_kind, requester_id, policy_snapshot, state,
|
|
1013
1013
|
target_agent_id, execution_kind, legacy_agent_request_id, created_at
|
|
1014
1014
|
FROM work_requests ORDER BY created_at ASC, rowid ASC
|
|
1015
|
-
`).all(),n=new Map(t.map(e=>[e.id,e])),
|
|
1015
|
+
`).all(),n=new Map(t.map(e=>[e.id,e])),i=e=>{try{let t=JSON.parse(e.policy_snapshot);return t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch{return{}}},r=new Map,s=e=>{let t=r.get(e.id);if(void 0!==t)return t;let i=[],a=new Set,s=e,o=!1;for(;s&&!a.has(s.id)&&s.root_request_id===e.root_request_id;){let t=r.get(s.id);if(void 0!==t){o=t;break}if(a.add(s.id),i.push(s),null===s.parent_request_id){o=s.id===e.root_request_id;break}s=n.get(s.parent_request_id)}for(let e of i)r.set(e.id,o);return o},o=new Map,E=e=>{let t=o.get(e.id);if(void 0!==t)return t;let r=0,a=e.parent_request_id?n.get(e.parent_request_id):void 0;if(a){let t=E(a),n=i(e);r=e.wake_event_id?t+1:"coordinator_continuation"===n.source&&"result"===n.continues?Math.max(t-1,0):t}return o.set(e.id,r),r},d=e.prepare("UPDATE work_requests SET wake_depth = ?, root_principal_kind = ?, root_principal_id = ? WHERE id = ?"),_=e.prepare(`
|
|
1016
1016
|
INSERT INTO wake_safety_decisions (
|
|
1017
1017
|
id, request_id, sequence, wake_id, principal_type, principal_kind, principal_id, target_agent_id, execution_kind,
|
|
1018
1018
|
decision, reason_code, grant_rule, grant_id, policy_snapshot, created_at
|
|
1019
1019
|
) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, 'allowed', NULL, 'pre_safety_migration', NULL, ?, ?)
|
|
1020
|
-
`);for(let
|
|
1020
|
+
`);for(let r of(e.exec("DROP TRIGGER trg_work_requests_terminal"),t)){let e=n.get(r.root_request_id),t=!!e&&s(r),o=t?E(r):0,c=t&&e?{kind:e.requester_kind,id:e.requester_id}:{kind:"unknown",id:"unknown"};if(d.run(o,c.kind,c.id,r.id),null===r.legacy_agent_request_id&&["queued","running","waiting"].includes(r.state)){let e=i(r),t="wake"===e.source?"agent_principal":"coordinator_continuation"===e.source?"engine":"api"===e.surface?"api_principal":"human_owner";_.run((0,a.randomUUID)(),r.id,r.wake_event_id,t,r.requester_kind,r.requester_id,r.target_agent_id,r.execution_kind,JSON.stringify({safety_version:1,migrated:!0,root_principal:c,wake_depth:o,grant_rule:"pre_safety_migration"}),r.created_at)}}e.exec(`
|
|
1021
1021
|
CREATE TRIGGER trg_work_requests_terminal BEFORE UPDATE ON work_requests
|
|
1022
|
-
WHEN OLD.state IN (${
|
|
1022
|
+
WHEN OLD.state IN (${w})
|
|
1023
1023
|
BEGIN
|
|
1024
1024
|
SELECT RAISE(ABORT, 'terminal work_requests are immutable');
|
|
1025
1025
|
END;
|
|
@@ -1031,7 +1031,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1031
1031
|
BEGIN
|
|
1032
1032
|
SELECT RAISE(ABORT, 'work_requests wake depth and root principal are immutable');
|
|
1033
1033
|
END;
|
|
1034
|
-
`)}},{version:14,name:"retire_legacy_agent_requests",up:e=>{!function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("agent_requests"))return;let n=t("agent_request_events"),
|
|
1034
|
+
`)}},{version:14,name:"retire_legacy_agent_requests",up:e=>{!function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("agent_requests"))return;let n=t("agent_request_events"),i=e.prepare(`
|
|
1035
1035
|
SELECT r.*, m.content AS content FROM agent_requests r
|
|
1036
1036
|
JOIN conversations c ON c.id = r.conversation_id
|
|
1037
1037
|
JOIN bots b ON b.id = r.target_bot_id
|
|
@@ -1040,14 +1040,14 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1040
1040
|
AND r.principal_kind IN ('person', 'bot', 'service')
|
|
1041
1041
|
AND NOT EXISTS (SELECT 1 FROM work_requests w WHERE w.legacy_agent_request_id = r.id)
|
|
1042
1042
|
ORDER BY r.created_at ASC, r.rowid ASC
|
|
1043
|
-
`).all(),
|
|
1043
|
+
`).all(),r=e.prepare("SELECT 1 FROM work_requests WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?"),s=n?e.prepare("SELECT type, data, created_at FROM agent_request_events WHERE request_id = ? ORDER BY created_at ASC, rowid ASC"):null,o=e.prepare(`
|
|
1044
1044
|
INSERT INTO work_requests (
|
|
1045
1045
|
id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
|
|
1046
1046
|
intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
|
|
1047
1047
|
idempotency_key, request_hash, policy_snapshot, state, state_reason, result, error_code, error_message,
|
|
1048
1048
|
version, legacy_agent_request_id, created_at, updated_at, terminal_at, root_principal_kind, root_principal_id
|
|
1049
1049
|
) VALUES (?, ?, ?, ?, ?, ?, ?, 'conversation', 'readonly', NULL, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?)
|
|
1050
|
-
`),
|
|
1050
|
+
`),E=e.prepare("INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at) VALUES (?, ?, ?, NULL, ?, ?, ?)"),d=Date.now();for(let e of i){if(r.get(e.principal_kind,e.principal_id,e.idempotency_key))continue;let t=(0,a.randomUUID)(),n=W({sourceConversationId:e.conversation_id,sourceEventId:e.accepted_message_id,targetAgentId:e.target_bot_id,intent:e.content,executionKind:"conversation",toolProfile:"readonly"}),i="accepted"===e.state||"dispatched"===e.state,_=JSON.stringify({tool_profile:"readonly",source:"legacy_agent_requests",legacy_operation:e.operation,legacy_runtime:e.runtime,...i?{legacy_state:e.state}:{}}),c=i?Math.max(d,e.updated_at):e.updated_at;o.run(t,e.conversation_id,e.accepted_message_id,e.principal_kind,e.principal_id,e.target_bot_id,e.content,t,e.idempotency_key,n,_,i?"failed":e.state,i?x:null,"completed"===e.state?JSON.stringify({reply_message_id:e.reply_message_id}):null,i?x:"failed"===e.state?e.failure_code:null,i?X:"failed"===e.state?e.failure_message:null,e.id,e.created_at,c,c,e.principal_kind,e.principal_id);let u=0;for(let n of s?.all(e.id)??[])E.run((0,a.randomUUID)(),t,++u,n.type,n.data,n.created_at);i&&E.run((0,a.randomUUID)(),t,++u,"state_changed",JSON.stringify({from:"accepted"===e.state?"queued":"running",to:"failed",reason:x}),c),E.run((0,a.randomUUID)(),t,++u,"backfilled",JSON.stringify({legacy_agent_request_id:e.id}),c)}(function(e){let t=e.prepare(`
|
|
1051
1051
|
SELECT w.id AS request_id, r.principal_kind, r.principal_id, r.idempotency_key, r.payload_hash,
|
|
1052
1052
|
r.conversation_id, r.target_bot_id, r.accepted_message_id, r.created_at, m.content AS content
|
|
1053
1053
|
FROM work_requests w
|
|
@@ -1063,7 +1063,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1063
1063
|
requester_kind, requester_id, idempotency_key, request_hash, surface,
|
|
1064
1064
|
conversation_id, source_event_id, work_request_ids, created_at
|
|
1065
1065
|
) VALUES (?, ?, ?, ?, 'api', ?, ?, ?, ?)
|
|
1066
|
-
`);for(let e of t){let t=[e.conversation_id,null].map(t=>[e.target_bot_id,t,e.content]).find(t=>
|
|
1066
|
+
`);for(let e of t){let t=[e.conversation_id,null].map(t=>[e.target_bot_id,t,e.content]).find(t=>Y(JSON.stringify(t))===e.payload_hash);t&&n.run(e.principal_kind,e.principal_id,e.idempotency_key,Y(JSON.stringify(["api",t])),e.conversation_id,e.accepted_message_id,JSON.stringify([e.request_id]),e.created_at)}})(e),t("legacy_agent_requests_archive")?e.exec("INSERT INTO legacy_agent_requests_archive SELECT * FROM agent_requests; DROP TABLE agent_requests;"):e.exec("ALTER TABLE agent_requests RENAME TO legacy_agent_requests_archive"),n&&(t("legacy_agent_request_events_archive")?e.exec("INSERT INTO legacy_agent_request_events_archive SELECT * FROM agent_request_events; DROP TABLE agent_request_events;"):e.exec("ALTER TABLE agent_request_events RENAME TO legacy_agent_request_events_archive"))}(e)}},{version:15,name:"ui_turns_on_work_requests",up:e=>{e.exec(`
|
|
1067
1067
|
ALTER TABLE work_requests ADD COLUMN executor TEXT NOT NULL DEFAULT 'dispatcher'
|
|
1068
1068
|
CHECK (executor IN ('dispatcher', 'ui_message', 'ui_continuation'));
|
|
1069
1069
|
CREATE INDEX idx_work_requests_executor ON work_requests(executor, state, created_at);
|
|
@@ -1085,27 +1085,27 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1085
1085
|
PRIMARY KEY (conversation_id, user_message_id),
|
|
1086
1086
|
FOREIGN KEY (conversation_id) REFERENCES conversations(id)
|
|
1087
1087
|
);
|
|
1088
|
-
`),function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("processing_queue"))return;let n=new Set(e.prepare("PRAGMA table_info(processing_queue)").all().map(e=>e.name)).has("work_request_id")?"q.work_request_id":"NULL",
|
|
1088
|
+
`),function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("processing_queue"))return;let n=new Set(e.prepare("PRAGMA table_info(processing_queue)").all().map(e=>e.name)).has("work_request_id")?"q.work_request_id":"NULL",i=e.prepare(`
|
|
1089
1089
|
SELECT q.id, q.conversation_id, q.bot_id, q.status, ${n} AS work_request_id, q.created_at, q.started_at, q.completed_at
|
|
1090
1090
|
FROM processing_queue q
|
|
1091
1091
|
JOIN conversations c ON c.id = q.conversation_id
|
|
1092
1092
|
JOIN bots b ON b.id = q.bot_id
|
|
1093
1093
|
ORDER BY q.created_at ASC, q.rowid ASC
|
|
1094
|
-
`).all(),
|
|
1094
|
+
`).all(),r=e.prepare("SELECT * FROM work_requests WHERE id = ?"),s=e.prepare(`
|
|
1095
1095
|
UPDATE work_requests SET state = ?, state_reason = ?, version = version + 1, updated_at = ?,
|
|
1096
1096
|
error_code = ?, error_message = ?, terminal_at = ?, executor = 'ui_message'
|
|
1097
1097
|
WHERE id = ?
|
|
1098
1098
|
`),o=e.prepare(`
|
|
1099
1099
|
INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at)
|
|
1100
1100
|
SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, NULL, ?, ?, ? FROM engine_events WHERE request_id = ?
|
|
1101
|
-
`),
|
|
1101
|
+
`),E=(e,t,n,i)=>o.run((0,a.randomUUID)(),e,t,JSON.stringify(n),i,e),d=e.prepare("SELECT id FROM messages WHERE conversation_id = ? AND created_at <= ? ORDER BY created_at DESC, rowid DESC LIMIT 1"),_=e.prepare(`
|
|
1102
1102
|
INSERT INTO work_requests (
|
|
1103
1103
|
id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
|
|
1104
1104
|
intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
|
|
1105
1105
|
idempotency_key, request_hash, policy_snapshot, state, version, created_at, updated_at,
|
|
1106
1106
|
wake_depth, root_principal_kind, root_principal_id, executor
|
|
1107
1107
|
) VALUES (?, ?, ?, ?, ?, ?, ?, 'conversation', 'readonly', NULL, ?, NULL, 0, ?, ?, ?, 'queued', 0, ?, ?, 0, ?, ?, 'ui_continuation')
|
|
1108
|
-
`),
|
|
1108
|
+
`),c=H(!1),u=0;for(let t of i){if(t.work_request_id){let n=r.get(t.work_request_id);if(!n||"queued"!==n.state)continue;let i=t.started_at??t.created_at,a=Math.max(t.completed_at??i,i);if("pending"===t.status)e.prepare("UPDATE work_requests SET executor = 'ui_message' WHERE id = ?").run(n.id);else if("completed"===t.status||"failed"===t.status)s.run("running",null,i,null,null,null,n.id),E(n.id,"state_changed",{from:"queued",to:"running",reason:null,legacy_queue_id:t.id},i),s.run(t.status,"legacy_queue_turn",a,"failed"===t.status?"ui_turn_failed":null,"failed"===t.status?"The UI turn failed in the retired processing queue.":null,a,n.id),E(n.id,"state_changed",{from:"running",to:t.status,reason:"legacy_queue_turn",legacy_queue_id:t.id},a);else{let e=Math.max(Date.now(),i);s.run("running",null,i,null,null,null,n.id),E(n.id,"state_changed",{from:"queued",to:"running",reason:null,legacy_queue_id:t.id},i),s.run("failed",B,e,B,M,e,n.id),E(n.id,"state_changed",{from:"running",to:"failed",reason:B,error_code:B,legacy_queue_id:t.id},e)}u++;continue}if("pending"!==t.status)continue;let n=(0,a.randomUUID)(),i=d.get(t.conversation_id,t.created_at)?.id??t.conversation_id,o={source:"legacy_processing_queue",legacy_queue_id:t.id},T=W({sourceConversationId:t.conversation_id,sourceEventId:i,targetAgentId:t.bot_id,intent:"turn",executionKind:"conversation",toolProfile:"readonly",policy:{...o,execution_policy:c}});_.run(n,t.conversation_id,i,G.kind,G.id,t.bot_id,"turn",n,`legacy-queue:${t.id}`,T,JSON.stringify({...o,execution_policy:c,tool_profile:"readonly"}),t.created_at,t.created_at,G.kind,G.id),E(n,"accepted",{state:"queued",execution_kind:"conversation",tool_profile:"readonly"},t.created_at),E(n,"backfilled",{legacy_queue_id:t.id},t.created_at),u++}u+=e.prepare(`
|
|
1109
1109
|
UPDATE work_requests SET executor = 'ui_message'
|
|
1110
1110
|
WHERE state = 'queued' AND executor = 'dispatcher' AND legacy_agent_request_id IS NULL
|
|
1111
1111
|
AND parent_request_id IS NULL AND wake_event_id IS NULL
|
|
@@ -1116,56 +1116,263 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1116
1116
|
WHERE i.surface = 'ui' AND r.value = work_requests.id
|
|
1117
1117
|
)
|
|
1118
1118
|
)
|
|
1119
|
-
`).run().changes,t("legacy_processing_queue_archive")?e.exec("INSERT INTO legacy_processing_queue_archive SELECT * FROM processing_queue; DROP TABLE processing_queue;"):e.exec("ALTER TABLE processing_queue RENAME TO legacy_processing_queue_archive")}(e)}}
|
|
1119
|
+
`).run().changes,t("legacy_processing_queue_archive")?e.exec("INSERT INTO legacy_processing_queue_archive SELECT * FROM processing_queue; DROP TABLE processing_queue;"):e.exec("ALTER TABLE processing_queue RENAME TO legacy_processing_queue_archive")}(e)}},{version:16,name:"session_exchanges",up:e=>{let t=I.flatMap(e=>A[e].map(t=>`'${e}>${t}'`)).join(", "),n=I.map(e=>`'${e}'`).join(", "),i=S.map(e=>`'${e}'`).join(", ");e.exec(`
|
|
1120
|
+
-- One row per owner-requested exchange against one selected Session
|
|
1121
|
+
-- Binding. It names Botmancers rows only (binding, Work Requests,
|
|
1122
|
+
-- Attempts, messages): never a provider session id or credential.
|
|
1123
|
+
-- Hop Work Requests run through the dispatcher; the exchange state
|
|
1124
|
+
-- advances from their durable outcome.
|
|
1125
|
+
CREATE TABLE session_exchanges (
|
|
1126
|
+
id TEXT PRIMARY KEY,
|
|
1127
|
+
requester_kind TEXT NOT NULL CHECK (requester_kind IN ('person', 'bot', 'service')),
|
|
1128
|
+
requester_id TEXT NOT NULL,
|
|
1129
|
+
idempotency_key TEXT NOT NULL CHECK (length(idempotency_key) > 0),
|
|
1130
|
+
request_hash TEXT NOT NULL,
|
|
1131
|
+
mode TEXT NOT NULL CHECK (mode IN ('ask', 'continue')),
|
|
1132
|
+
origin_conversation_id TEXT NOT NULL,
|
|
1133
|
+
source_agent_id TEXT NOT NULL,
|
|
1134
|
+
source_binding_id TEXT NOT NULL,
|
|
1135
|
+
destination_agent_id TEXT,
|
|
1136
|
+
destination_conversation_id TEXT,
|
|
1137
|
+
destination_binding_id TEXT,
|
|
1138
|
+
instruction TEXT NOT NULL CHECK (length(instruction) BETWEEN 1 AND ${v.instructionChars}),
|
|
1139
|
+
state TEXT NOT NULL CHECK (state IN (${n})),
|
|
1140
|
+
source_request_id TEXT,
|
|
1141
|
+
source_attempt_id TEXT,
|
|
1142
|
+
destination_request_id TEXT,
|
|
1143
|
+
destination_attempt_id TEXT,
|
|
1144
|
+
answer_message_id TEXT,
|
|
1145
|
+
packet TEXT CHECK (packet IS NULL OR length(packet) <= ${v.packetChars}),
|
|
1146
|
+
failure_code TEXT,
|
|
1147
|
+
failure_message TEXT,
|
|
1148
|
+
cancel_requested_at INTEGER,
|
|
1149
|
+
cancel_requested_by TEXT,
|
|
1150
|
+
cancel_reason TEXT,
|
|
1151
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
1152
|
+
created_at INTEGER NOT NULL,
|
|
1153
|
+
updated_at INTEGER NOT NULL,
|
|
1154
|
+
terminal_at INTEGER,
|
|
1155
|
+
UNIQUE (requester_kind, requester_id, idempotency_key),
|
|
1156
|
+
CHECK ((state IN (${i})) = (terminal_at IS NOT NULL)),
|
|
1157
|
+
CHECK (state <> 'failed' OR failure_code IS NOT NULL),
|
|
1158
|
+
CHECK ((mode = 'continue') = (destination_agent_id IS NOT NULL AND destination_conversation_id IS NOT NULL)),
|
|
1159
|
+
CHECK (destination_agent_id IS NULL OR destination_agent_id <> source_agent_id),
|
|
1160
|
+
CHECK (mode = 'continue' OR (packet IS NULL AND destination_request_id IS NULL AND destination_binding_id IS NULL)),
|
|
1161
|
+
CHECK (mode = 'ask' OR answer_message_id IS NULL),
|
|
1162
|
+
CHECK (state = 'queued' OR state = 'failed' OR state = 'cancelled' OR source_request_id IS NOT NULL),
|
|
1163
|
+
CHECK (state <> 'delivering' OR (packet IS NOT NULL AND destination_request_id IS NOT NULL)),
|
|
1164
|
+
FOREIGN KEY (origin_conversation_id) REFERENCES conversations(id),
|
|
1165
|
+
FOREIGN KEY (source_agent_id) REFERENCES bots(id),
|
|
1166
|
+
FOREIGN KEY (source_binding_id) REFERENCES session_bindings(id),
|
|
1167
|
+
FOREIGN KEY (destination_agent_id) REFERENCES bots(id),
|
|
1168
|
+
FOREIGN KEY (destination_conversation_id) REFERENCES conversations(id),
|
|
1169
|
+
FOREIGN KEY (destination_binding_id) REFERENCES session_bindings(id),
|
|
1170
|
+
FOREIGN KEY (source_request_id) REFERENCES work_requests(id),
|
|
1171
|
+
FOREIGN KEY (source_attempt_id) REFERENCES work_attempts(id),
|
|
1172
|
+
FOREIGN KEY (destination_request_id) REFERENCES work_requests(id),
|
|
1173
|
+
FOREIGN KEY (destination_attempt_id) REFERENCES work_attempts(id),
|
|
1174
|
+
FOREIGN KEY (answer_message_id) REFERENCES messages(id)
|
|
1175
|
+
);
|
|
1176
|
+
CREATE INDEX idx_session_exchanges_open ON session_exchanges(created_at) WHERE terminal_at IS NULL;
|
|
1177
|
+
CREATE INDEX idx_session_exchanges_binding ON session_exchanges(source_binding_id);
|
|
1178
|
+
CREATE UNIQUE INDEX idx_session_exchanges_source_request ON session_exchanges(source_request_id) WHERE source_request_id IS NOT NULL;
|
|
1179
|
+
CREATE UNIQUE INDEX idx_session_exchanges_destination_request ON session_exchanges(destination_request_id) WHERE destination_request_id IS NOT NULL;
|
|
1180
|
+
|
|
1181
|
+
CREATE TABLE session_exchange_events (
|
|
1182
|
+
id TEXT PRIMARY KEY,
|
|
1183
|
+
exchange_id TEXT NOT NULL,
|
|
1184
|
+
sequence INTEGER NOT NULL CHECK (sequence >= 1),
|
|
1185
|
+
type TEXT NOT NULL CHECK (length(type) > 0),
|
|
1186
|
+
data TEXT,
|
|
1187
|
+
created_at INTEGER NOT NULL,
|
|
1188
|
+
UNIQUE (exchange_id, sequence),
|
|
1189
|
+
FOREIGN KEY (exchange_id) REFERENCES session_exchanges(id)
|
|
1190
|
+
);
|
|
1191
|
+
|
|
1192
|
+
CREATE TRIGGER trg_session_exchanges_fk BEFORE INSERT ON session_exchanges
|
|
1193
|
+
BEGIN
|
|
1194
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.origin_conversation_id')
|
|
1195
|
+
WHERE NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.origin_conversation_id);
|
|
1196
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_agent_id')
|
|
1197
|
+
WHERE NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.source_agent_id);
|
|
1198
|
+
SELECT RAISE(ABORT, 'session exchange source binding does not belong to its source agent')
|
|
1199
|
+
WHERE NOT EXISTS (SELECT 1 FROM session_bindings WHERE id = NEW.source_binding_id AND agent_id = NEW.source_agent_id);
|
|
1200
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_agent_id')
|
|
1201
|
+
WHERE NEW.destination_agent_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.destination_agent_id);
|
|
1202
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_conversation_id')
|
|
1203
|
+
WHERE NEW.destination_conversation_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.destination_conversation_id);
|
|
1204
|
+
SELECT RAISE(ABORT, 'a session exchange starts queued')
|
|
1205
|
+
WHERE NEW.state <> 'queued';
|
|
1206
|
+
END;
|
|
1207
|
+
|
|
1208
|
+
-- Identity, target, and instruction are fixed at creation.
|
|
1209
|
+
CREATE TRIGGER trg_session_exchanges_immutable BEFORE UPDATE OF
|
|
1210
|
+
id, requester_kind, requester_id, idempotency_key, request_hash, mode, origin_conversation_id,
|
|
1211
|
+
source_agent_id, source_binding_id, destination_agent_id, destination_conversation_id, instruction, created_at
|
|
1212
|
+
ON session_exchanges
|
|
1213
|
+
BEGIN
|
|
1214
|
+
SELECT RAISE(ABORT, 'session_exchanges identity and target are immutable');
|
|
1215
|
+
END;
|
|
1216
|
+
|
|
1217
|
+
CREATE TRIGGER trg_session_exchanges_transition BEFORE UPDATE OF state ON session_exchanges
|
|
1218
|
+
WHEN NEW.state <> OLD.state
|
|
1219
|
+
BEGIN
|
|
1220
|
+
SELECT RAISE(ABORT, 'invalid session_exchanges state transition')
|
|
1221
|
+
WHERE (OLD.state || '>' || NEW.state) NOT IN (${t})
|
|
1222
|
+
OR (OLD.mode = 'ask' AND NEW.state = 'delivering')
|
|
1223
|
+
OR (OLD.mode = 'continue' AND OLD.state = 'extracting' AND NEW.state = 'completed');
|
|
1224
|
+
END;
|
|
1225
|
+
|
|
1226
|
+
CREATE TRIGGER trg_session_exchanges_terminal BEFORE UPDATE ON session_exchanges
|
|
1227
|
+
WHEN OLD.state IN (${i})
|
|
1228
|
+
BEGIN
|
|
1229
|
+
SELECT RAISE(ABORT, 'terminal session_exchanges are immutable');
|
|
1230
|
+
END;
|
|
1231
|
+
|
|
1232
|
+
-- Causal references, the packet, and the cancellation intent are
|
|
1233
|
+
-- recorded once; a set reference must name an existing row.
|
|
1234
|
+
CREATE TRIGGER trg_session_exchanges_set_once BEFORE UPDATE ON session_exchanges
|
|
1235
|
+
BEGIN
|
|
1236
|
+
SELECT RAISE(ABORT, 'session_exchanges references are set once')
|
|
1237
|
+
WHERE (OLD.source_request_id IS NOT NULL AND NEW.source_request_id IS NOT OLD.source_request_id)
|
|
1238
|
+
OR (OLD.source_attempt_id IS NOT NULL AND NEW.source_attempt_id IS NOT OLD.source_attempt_id)
|
|
1239
|
+
OR (OLD.destination_request_id IS NOT NULL AND NEW.destination_request_id IS NOT OLD.destination_request_id)
|
|
1240
|
+
OR (OLD.destination_attempt_id IS NOT NULL AND NEW.destination_attempt_id IS NOT OLD.destination_attempt_id)
|
|
1241
|
+
OR (OLD.destination_binding_id IS NOT NULL AND NEW.destination_binding_id IS NOT OLD.destination_binding_id)
|
|
1242
|
+
OR (OLD.answer_message_id IS NOT NULL AND NEW.answer_message_id IS NOT OLD.answer_message_id)
|
|
1243
|
+
OR (OLD.packet IS NOT NULL AND NEW.packet IS NOT OLD.packet)
|
|
1244
|
+
OR (OLD.cancel_requested_at IS NOT NULL AND (NEW.cancel_requested_at IS NOT OLD.cancel_requested_at
|
|
1245
|
+
OR NEW.cancel_requested_by IS NOT OLD.cancel_requested_by OR NEW.cancel_reason IS NOT OLD.cancel_reason));
|
|
1246
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_request_id')
|
|
1247
|
+
WHERE NEW.source_request_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.source_request_id AND target_agent_id = NEW.source_agent_id);
|
|
1248
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_attempt_id')
|
|
1249
|
+
WHERE NEW.source_attempt_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.source_attempt_id AND request_id = NEW.source_request_id);
|
|
1250
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_request_id')
|
|
1251
|
+
WHERE NEW.destination_request_id IS NOT NULL AND NOT EXISTS (
|
|
1252
|
+
SELECT 1 FROM work_requests WHERE id = NEW.destination_request_id AND target_agent_id = NEW.destination_agent_id
|
|
1253
|
+
AND source_conversation_id = NEW.destination_conversation_id);
|
|
1254
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_attempt_id')
|
|
1255
|
+
WHERE NEW.destination_attempt_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.destination_attempt_id AND request_id = NEW.destination_request_id);
|
|
1256
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_binding_id')
|
|
1257
|
+
WHERE NEW.destination_binding_id IS NOT NULL AND NOT EXISTS (
|
|
1258
|
+
SELECT 1 FROM session_bindings WHERE id = NEW.destination_binding_id AND agent_id = NEW.destination_agent_id
|
|
1259
|
+
AND request_id = NEW.destination_request_id AND id <> NEW.source_binding_id);
|
|
1260
|
+
-- The answer is the source Agent's message in the origin
|
|
1261
|
+
-- conversation, produced by the source hop request.
|
|
1262
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.answer_message_id')
|
|
1263
|
+
WHERE NEW.answer_message_id IS NOT NULL AND NOT EXISTS (
|
|
1264
|
+
SELECT 1 FROM messages WHERE id = NEW.answer_message_id AND conversation_id = NEW.origin_conversation_id
|
|
1265
|
+
AND sender_type = 'bot' AND sender_id = NEW.source_agent_id
|
|
1266
|
+
AND NEW.source_request_id IS NOT NULL AND request_id = NEW.source_request_id);
|
|
1267
|
+
END;
|
|
1268
|
+
|
|
1269
|
+
CREATE TRIGGER trg_session_exchange_events_fk BEFORE INSERT ON session_exchange_events
|
|
1270
|
+
BEGIN
|
|
1271
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchange_events.exchange_id')
|
|
1272
|
+
WHERE NOT EXISTS (SELECT 1 FROM session_exchanges WHERE id = NEW.exchange_id);
|
|
1273
|
+
END;
|
|
1274
|
+
CREATE TRIGGER trg_session_exchange_events_append_only BEFORE UPDATE ON session_exchange_events
|
|
1275
|
+
BEGIN
|
|
1276
|
+
SELECT RAISE(ABORT, 'session_exchange_events are append-only');
|
|
1277
|
+
END;
|
|
1278
|
+
-- Removed only with their exchange, by the aggregate cleanup
|
|
1279
|
+
-- (deleteSessionExchanges), under the same purge authority as
|
|
1280
|
+
-- engine events.
|
|
1281
|
+
CREATE TRIGGER trg_session_exchange_events_no_delete BEFORE DELETE ON session_exchange_events
|
|
1282
|
+
BEGIN
|
|
1283
|
+
SELECT RAISE(ABORT, 'session_exchange_events are append-only')
|
|
1284
|
+
WHERE NOT engine_event_purge_authorized(OLD.exchange_id);
|
|
1285
|
+
END;
|
|
1286
|
+
CREATE TRIGGER trg_session_exchanges_restrict BEFORE DELETE ON session_exchanges
|
|
1287
|
+
BEGIN
|
|
1288
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchange_events.exchange_id')
|
|
1289
|
+
WHERE EXISTS (SELECT 1 FROM session_exchange_events WHERE exchange_id = OLD.id);
|
|
1290
|
+
END;
|
|
1291
|
+
|
|
1292
|
+
-- Foreign keys (delete side): RESTRICT, as for the engine tables.
|
|
1293
|
+
CREATE TRIGGER trg_conversations_exchange_restrict BEFORE DELETE ON conversations
|
|
1294
|
+
BEGIN
|
|
1295
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.conversation')
|
|
1296
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE origin_conversation_id = OLD.id OR destination_conversation_id = OLD.id);
|
|
1297
|
+
END;
|
|
1298
|
+
CREATE TRIGGER trg_bots_exchange_restrict BEFORE DELETE ON bots
|
|
1299
|
+
BEGIN
|
|
1300
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.agent')
|
|
1301
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_agent_id = OLD.id OR destination_agent_id = OLD.id);
|
|
1302
|
+
END;
|
|
1303
|
+
CREATE TRIGGER trg_session_bindings_exchange_restrict BEFORE DELETE ON session_bindings
|
|
1304
|
+
BEGIN
|
|
1305
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.binding')
|
|
1306
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_binding_id = OLD.id OR destination_binding_id = OLD.id);
|
|
1307
|
+
END;
|
|
1308
|
+
CREATE TRIGGER trg_work_requests_exchange_restrict BEFORE DELETE ON work_requests
|
|
1309
|
+
BEGIN
|
|
1310
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.request')
|
|
1311
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_request_id = OLD.id OR destination_request_id = OLD.id);
|
|
1312
|
+
END;
|
|
1313
|
+
CREATE TRIGGER trg_messages_exchange_restrict BEFORE DELETE ON messages
|
|
1314
|
+
BEGIN
|
|
1315
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.answer_message_id')
|
|
1316
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE answer_message_id = OLD.id);
|
|
1317
|
+
END;
|
|
1318
|
+
CREATE TRIGGER trg_work_attempts_exchange_restrict BEFORE DELETE ON work_attempts
|
|
1319
|
+
BEGIN
|
|
1320
|
+
SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.attempt')
|
|
1321
|
+
WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_attempt_id = OLD.id OR destination_attempt_id = OLD.id);
|
|
1322
|
+
END;
|
|
1323
|
+
`)}}],U=new WeakMap;function b(e){let t=U.get(e);if(!t){t=new Set,U.set(e,t);let n=t;e.function("engine_event_purge_authorized",{deterministic:!1},e=>"string"==typeof e&&n.has(e)?1:0)}return t}function F(e,t={}){b(e),e.exec(`
|
|
1120
1324
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
1121
1325
|
version INTEGER PRIMARY KEY,
|
|
1122
1326
|
name TEXT NOT NULL,
|
|
1123
1327
|
applied_at INTEGER NOT NULL
|
|
1124
1328
|
);
|
|
1125
|
-
`);let n=e.prepare("SELECT 1 FROM schema_migrations WHERE version = ?"),
|
|
1329
|
+
`);let n=e.prepare("SELECT 1 FROM schema_migrations WHERE version = ?"),i=e.prepare("INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)");for(let r of y){if(void 0!==t.through&&r.version>t.through)return;e.transaction(()=>{n.get(r.version)||(r.up(e),i.run(r.version,r.name,Date.now()))}).immediate()}}function W(e){return Y(JSON.stringify([e.sourceConversationId,e.sourceEventId,e.targetAgentId,e.intent,e.executionKind,e.toolProfile,e.parentRequestId??null,e.wakeEventId??null,e.policy??null]))}y[y.length-1].version;let x="legacy_interrupted",X="Accepted before NOT-465 by the retired agent_requests dispatcher; it never reached a terminal state.",G=Object.freeze({kind:"service",id:"botmancers-ui-turns"});function H(e){let t=T(e?{entryPoint:"wake",executionKind:"conversation",wakeSyntax:"legacy"}:{entryPoint:"ui",executionKind:"conversation"});if(!t.ok)throw new C("invalid_input",t.reason);return t.policy}let B="ui_turn_interrupted",M="The UI turn was interrupted before it finished; it is not run again.";function K(e){return"string"==typeof e&&e.trim().length>0}function Y(e){return(0,a.createHash)("sha256").update(e).digest("hex")}function P(e){return null==e?null:JSON.stringify(e)}function $(e){b(e);let t=e.prepare("SELECT * FROM work_requests WHERE id = ?"),n=e.prepare("SELECT * FROM work_requests WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?"),i=e.prepare("SELECT * FROM work_attempts WHERE id = ?"),r=e.prepare(`
|
|
1126
1330
|
INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at)
|
|
1127
1331
|
SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, ?, ?, ?, ? FROM engine_events WHERE request_id = ?
|
|
1128
|
-
`),s=e.prepare("SELECT * FROM engine_events WHERE id = ?"),o=e.prepare("SELECT * FROM session_bindings WHERE id = ?");function
|
|
1332
|
+
`),s=e.prepare("SELECT * FROM engine_events WHERE id = ?"),o=e.prepare("SELECT * FROM session_bindings WHERE id = ?");function E(e){let n=t.get(e);if(!n)throw new C("not_found",`No work request ${e}.`);return n}function d(e){let t=i.get(e);if(!t)throw new C("not_found",`No attempt ${e}.`);return t}function u(e,t,n,i,o){let E=(0,a.randomUUID)();return r.run(E,e,i,t,P(n),o,e),s.get(E)}let T={transaction:t=>e.transaction(t).immediate(),createOrGetWorkRequest(i){if(!K(i.sourceConversationId))throw new C("invalid_input","sourceConversationId is required.");if(!K(i.sourceEventId))throw new C("invalid_input","sourceEventId is required.");if(!i.requester||!["person","bot","service"].includes(i.requester.kind)||!K(i.requester.id))throw new C("invalid_input","A requester principal is required.");if(!K(i.targetAgentId))throw new C("invalid_input","targetAgentId is required.");if("string"!=typeof i.intent)throw new C("invalid_input","intent is required.");if(!c(i.executionKind))throw new C("invalid_input","Unknown execution kind.");if(_[i.executionKind]!==i.toolProfile)throw new C("invalid_input",`Execution kind ${i.executionKind} requires the ${_[i.executionKind]} tool profile.`);if(i.policy&&Object.prototype.hasOwnProperty.call(i.policy,"execution_policy"))throw new C("invalid_input","The execution policy is passed as executionPolicy, never inside policy.");if(void 0!==i.executionPolicy){let e=N(i.executionPolicy);if(!e.ok)throw new C("invalid_input",e.reason);if(e.policy.execution_kind!==i.executionKind||e.policy.tool_profile!==i.toolProfile)throw new C("invalid_input","The execution policy does not match the requested execution kind and tool profile.")}if(!K(i.idempotencyKey))throw new C("invalid_input","idempotencyKey is required.");if(void 0!==i.executor&&!h.includes(i.executor))throw new C("invalid_input","Unknown request executor.");if(i.initialState&&"queued"!==i.initialState&&"blocked"!==i.initialState)throw new C("invalid_input","A work request starts queued or blocked.");if(void 0!==i.deadlineAt&&null!==i.deadlineAt&&!Number.isSafeInteger(i.deadlineAt))throw new C("invalid_input","deadlineAt must be an epoch millisecond integer.");if(void 0!==i.retryPolicy){let e=m(i.retryPolicy);if(!e.ok)throw new C("invalid_input",e.reason)}let r=i.executionPolicy?{...i.policy??{},execution_policy:i.executionPolicy}:i.policy,s=W({...i,policy:r});return e.transaction(()=>{let o=n.get(i.requester.kind,i.requester.id,i.idempotencyKey);if(o){if(o.request_hash!==s)throw new C("idempotency_conflict","The idempotency key was already used with a different request.");return{request:o,created:!1}}let d=i.now??Date.now(),_=(0,a.randomUUID)(),c=_,l=0,N=0,p=i.rootPrincipal??i.requester;if(i.parentRequestId){let e=t.get(i.parentRequestId);if(!e)throw new C("not_found","Parent work request not found.");c=e.root_request_id,l=e.depth+1,N=i.wakeEventId?e.wake_depth+1:e.wake_depth,p={kind:e.root_principal_kind??"unknown",id:e.root_principal_id??"unknown"}}void 0!==i.wakeDepth&&(N=i.wakeDepth);let R=i.initialState??"queued",m=JSON.stringify({...r??{},...i.safetySnapshot??{},tool_profile:i.toolProfile}),L=O(),g=i.retryPolicy??L.retryPolicy,I=void 0!==i.deadlineAt?i.deadlineAt:null===L.deadlineMs?null:d+L.deadlineMs;return e.prepare(`
|
|
1129
1333
|
INSERT INTO work_requests (
|
|
1130
1334
|
id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
|
|
1131
1335
|
intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
|
|
1132
1336
|
idempotency_key, request_hash, policy_snapshot, state, state_reason, version, created_at, updated_at,
|
|
1133
1337
|
deadline_at, retry_policy, wake_depth, root_principal_kind, root_principal_id, executor
|
|
1134
1338
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1135
|
-
`).run(
|
|
1339
|
+
`).run(_,i.sourceConversationId,i.sourceEventId,i.requester.kind,i.requester.id,i.targetAgentId,i.intent,i.executionKind,i.toolProfile,i.parentRequestId??null,c,i.wakeEventId??null,l,i.idempotencyKey,s,m,R,i.stateReason??null,d,d,I,JSON.stringify(g),N,p.kind,p.id,i.executor??"dispatcher"),u(_,"accepted",{state:R,execution_kind:i.executionKind,tool_profile:i.toolProfile,deadline_at:I,retry_policy:g},null,d),i.executionPolicy&&u(_,"policy_selected",{...i.executionPolicy},null,d),"blocked"===R&&u(_,"state_changed",{from:"queued",to:"blocked",reason:i.stateReason??null},null,d),i.safety&&T.recordSafetyDecision(_,{...i.safety,now:i.safety.now??d}),{request:E(_),created:!0}}).immediate()},getWorkRequest:e=>t.get(e),recordSafetyDecision(t,n){if(!["human_owner","api_principal","agent_principal","engine"].includes(n.principalType))throw new C("invalid_input","A categorized principal is required.");if(!K(n.principal?.kind)||!K(n.principal?.id))throw new C("invalid_input","A principal is required.");if(!["allowed","blocked","denied"].includes(n.decision))throw new C("invalid_input","Unknown safety decision.");if("allowed"===n.decision&&!K(n.grantRule))throw new C("invalid_input","An allowed decision names its grant rule.");return e.transaction(()=>{let i=E(t),r=(0,a.randomUUID)();return e.prepare(`
|
|
1136
1340
|
INSERT INTO wake_safety_decisions (
|
|
1137
1341
|
id, request_id, sequence, wake_id, principal_type, principal_kind, principal_id, target_agent_id, execution_kind,
|
|
1138
1342
|
decision, reason_code, grant_rule, grant_id, policy_snapshot, created_at
|
|
1139
1343
|
) SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM wake_safety_decisions WHERE request_id = ?
|
|
1140
|
-
`).run(
|
|
1344
|
+
`).run(r,t,n.wakeId??null,n.principalType,n.principal.kind,n.principal.id,i.target_agent_id,i.execution_kind,n.decision,n.reasonCode??null,n.grantRule??null,n.grantId??null,JSON.stringify(n.snapshot),n.now??Date.now(),t),e.prepare("SELECT * FROM wake_safety_decisions WHERE id = ?").get(r)}).immediate()},listSafetyDecisions:t=>e.prepare("SELECT * FROM wake_safety_decisions WHERE request_id = ? ORDER BY sequence ASC").all(t),latestSafetyDecision:t=>e.prepare("SELECT * FROM wake_safety_decisions WHERE request_id = ? ORDER BY sequence DESC LIMIT 1").get(t),transitionWorkRequest(t,n){if(!q[n.from]?.includes(n.to))throw new C("invalid_transition",`Cannot move a work request from ${n.from} to ${n.to}.`);let i=f.includes(n.to);return e.transaction(()=>{let r=E(t),a=n.now??Date.now();if(1!==e.prepare(`
|
|
1141
1345
|
UPDATE work_requests SET
|
|
1142
1346
|
state = ?, state_reason = ?, version = version + 1, updated_at = ?,
|
|
1143
1347
|
result = ?, error_code = ?, error_message = ?, terminal_at = ?
|
|
1144
1348
|
WHERE id = ? AND state = ? AND (? IS NULL OR version = ?)
|
|
1145
|
-
`).run(n.to,n.reason??null,a,
|
|
1349
|
+
`).run(n.to,n.reason??null,a,i?P(n.result):null,i?n.errorCode??null:null,i?n.errorMessage??null:null,i?a:null,t,n.from,n.expectedVersion??null,n.expectedVersion??null).changes)throw new C("stale_state",`Work request ${t} is ${r.state} at version ${r.version}, not ${n.from}${void 0===n.expectedVersion?"":` at version ${n.expectedVersion}`}.`);return u(t,"state_changed",{...n.data??{},from:n.from,to:n.to,reason:n.reason??null,...n.errorCode?{error_code:n.errorCode}:{}},null,a),i&&null===r.legacy_agent_request_id&&"dispatcher"===r.executor&&e.prepare("INSERT OR IGNORE INTO terminal_followups (request_id, created_at) VALUES (?, ?)").run(t,a),E(t)}).immediate()},reblockWorkRequest:(t,n)=>e.transaction(()=>{let i=n.now??Date.now();if(1!==e.prepare("UPDATE work_requests SET state_reason = ?, version = version + 1, updated_at = ? WHERE id = ? AND state = 'blocked'").run(n.reason,i,t).changes)throw new C("stale_state",`Work request ${t} is not blocked.`);return u(t,n.type,n.data??{},null,i),E(t)}).immediate(),appendEvent(t,n){if(!K(n.type))throw new C("invalid_input","Event type is required.");return e.transaction(()=>{if(E(t),n.attemptId&&d(n.attemptId).request_id!==t)throw new C("invalid_input","The attempt belongs to another request.");return u(t,n.type,n.data,n.attemptId??null,n.now??Date.now())}).immediate()},listEvents:t=>e.prepare("SELECT * FROM engine_events WHERE request_id = ? ORDER BY sequence ASC").all(t),createAttempt(t,n){if("launch"!==n.kind&&"resume"!==n.kind)throw new C("invalid_input","Unknown attempt kind.");if(!K(n.adapter))throw new C("invalid_input","adapter is required.");if("resume"===n.kind&&!n.resumedSessionBindingId)throw new C("invalid_input","A resume attempt names the session binding it resumes.");if("launch"===n.kind&&n.resumedSessionBindingId)throw new C("invalid_input","A launch attempt does not resume a session binding.");let i="string"==typeof n.launchSnapshot?n.launchSnapshot:JSON.stringify(n.launchSnapshot);if("string"!=typeof i||0===i.length)throw new C("invalid_input","A launch snapshot is required.");return e.transaction(()=>{let r=E(t);if("running"!==r.state)throw new C("attempt_conflict",`Attempts start only on running requests (request is ${r.state}).`);if(n.toolProfile!==r.tool_profile)throw new C("invalid_input",`The attempt tool profile must be ${r.tool_profile}.`);if(e.prepare("SELECT id FROM work_attempts WHERE request_id = ? AND finished_at IS NULL").get(t))throw new C("attempt_conflict","The request already has an open attempt.");if(n.resumedSessionBindingId){let e=o.get(n.resumedSessionBindingId);if(!e)throw new C("not_found","Session binding not found.");if(null!==e.released_at)throw new C("session_mismatch","The session binding was released.");if(e.agent_id!==r.target_agent_id||e.adapter!==n.adapter)throw new C("session_mismatch","The session binding belongs to another Agent or adapter.");if(null!==e.conversation_id&&e.conversation_id!==r.source_conversation_id)throw new C("session_mismatch","The session binding belongs to another conversation.");if(null!==e.request_id&&E(e.request_id).root_request_id!==r.root_request_id)throw new C("session_mismatch","The session binding belongs to an unrelated work request.")}let s=n.now??Date.now(),_=(0,a.randomUUID)(),c=e.prepare("SELECT COALESCE(MAX(attempt_number), 0) + 1 AS n FROM work_attempts WHERE request_id = ?").get(t);return e.prepare(`
|
|
1146
1350
|
INSERT INTO work_attempts (
|
|
1147
1351
|
id, request_id, attempt_number, kind, adapter, tool_profile, launch_snapshot, launch_snapshot_hash,
|
|
1148
1352
|
resumed_session_binding_id, external_run_id, external_session_id, started_at
|
|
1149
1353
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1150
|
-
`).run(_,t,
|
|
1354
|
+
`).run(_,t,c.n,n.kind,n.adapter,n.toolProfile,i,Y(i),n.resumedSessionBindingId??null,n.externalRunId??null,n.externalSessionId??null,s),u(t,"attempt_started",{attempt_number:c.n,kind:n.kind,adapter:n.adapter},_,s),d(_)}).immediate()},recordAttemptExternalIds:(t,n)=>e.transaction(()=>{let i=d(t);if(null!==i.finished_at)throw new C("attempt_conflict","The attempt is already finished.");return e.prepare("UPDATE work_attempts SET external_run_id = ?, external_session_id = ? WHERE id = ?").run(void 0===n.externalRunId?i.external_run_id:n.externalRunId,void 0===n.externalSessionId?i.external_session_id:n.externalSessionId,t),d(t)}).immediate(),finishAttempt(t,n){if(!["succeeded","failed","cancelled","interrupted","timed_out"].includes(n.outcome))throw new C("invalid_input","Unknown attempt outcome.");return e.transaction(()=>{let i=d(t);if(null!==i.finished_at)throw new C("attempt_conflict","The attempt is already finished.");let r=n.now??Date.now();return e.prepare(`
|
|
1151
1355
|
UPDATE work_attempts SET outcome = ?, output = ?, error_category = ?, error_message = ?, artifacts = ?,
|
|
1152
1356
|
external_run_id = ?, external_session_id = ?, finished_at = ?
|
|
1153
1357
|
WHERE id = ? AND finished_at IS NULL
|
|
1154
|
-
`).run(n.outcome,n.output??null,n.errorCategory??null,n.errorMessage??null,JSON.stringify(n.artifacts??[]),void 0===n.externalRunId?
|
|
1358
|
+
`).run(n.outcome,n.output??null,n.errorCategory??null,n.errorMessage??null,JSON.stringify(n.artifacts??[]),void 0===n.externalRunId?i.external_run_id:n.externalRunId,void 0===n.externalSessionId?i.external_session_id:n.externalSessionId,r,t),u(i.request_id,"attempt_finished",{attempt_number:i.attempt_number,outcome:n.outcome,error_category:n.errorCategory??null},t,r),d(t)}).immediate()},getAttempt:e=>i.get(e),listAttempts:t=>e.prepare("SELECT * FROM work_attempts WHERE request_id = ? ORDER BY attempt_number ASC").all(t),bindSession(t){if(!K(t.agentId))throw new C("invalid_input","agentId is required.");if(!K(t.adapter))throw new C("invalid_input","adapter is required.");if(!K(t.externalSessionId))throw new C("invalid_input","externalSessionId is required.");if(!t.conversationId&&!t.requestId)throw new C("invalid_input","A session binding is scoped to a conversation or work request.");return e.transaction(()=>{let n=t.now??Date.now();if(!e.prepare("SELECT 1 FROM bots WHERE id = ?").get(t.agentId))throw new C("not_found",`No agent ${t.agentId}.`);if(t.requestId){let e=E(t.requestId);if(e.target_agent_id!==t.agentId)throw new C("session_mismatch","The work request targets another Agent.");if(t.conversationId&&e.source_conversation_id!==t.conversationId)throw new C("session_mismatch","The work request belongs to another conversation.")}if(t.sourceAttemptId){let e=d(t.sourceAttemptId),n=E(e.request_id);if(e.adapter!==t.adapter||n.target_agent_id!==t.agentId)throw new C("session_mismatch","The source attempt ran another Agent or adapter.");if(t.requestId&&e.request_id!==t.requestId)throw new C("session_mismatch","The source attempt belongs to another work request.");if(t.conversationId&&n.source_conversation_id!==t.conversationId)throw new C("session_mismatch","The source attempt belongs to another conversation.")}e.prepare(`
|
|
1155
1359
|
UPDATE session_bindings SET released_at = ?
|
|
1156
1360
|
WHERE agent_id = ? AND adapter = ? AND IFNULL(conversation_id, '') = ? AND IFNULL(request_id, '') = ?
|
|
1157
1361
|
AND released_at IS NULL
|
|
1158
|
-
`).run(n,t.agentId,t.adapter,t.conversationId??"",t.requestId??"");let
|
|
1362
|
+
`).run(n,t.agentId,t.adapter,t.conversationId??"",t.requestId??"");let i=(0,a.randomUUID)();return e.prepare(`
|
|
1159
1363
|
INSERT INTO session_bindings (id, agent_id, adapter, conversation_id, request_id, external_session_id, source_attempt_id, created_at)
|
|
1160
1364
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
1161
|
-
`).run(
|
|
1365
|
+
`).run(i,t.agentId,t.adapter,t.conversationId??null,t.requestId??null,t.externalSessionId,t.sourceAttemptId??null,n),t.requestId&&u(t.requestId,"session_bound",{binding_id:i,adapter:t.adapter},t.sourceAttemptId??null,n),o.get(i)}).immediate()},getActiveSessionBinding:t=>e.prepare(`
|
|
1162
1366
|
SELECT * FROM session_bindings
|
|
1163
1367
|
WHERE agent_id = ? AND adapter = ? AND IFNULL(conversation_id, '') = ? AND IFNULL(request_id, '') = ?
|
|
1164
1368
|
AND released_at IS NULL
|
|
1165
|
-
`).get(t.agentId,t.adapter,t.conversationId??"",t.requestId??"")};return T}function
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1369
|
+
`).get(t.agentId,t.adapter,t.conversationId??"",t.requestId??"")};return T}function z(e,t){let n=(t,...n)=>e.prepare(t).all(...n).map(e=>e.id),i=new Set(n(t.requests,t.arg)),r=new Set,a=new Set(n(t.bindings,t.arg)),s=new Set,o=(e,t)=>{let n=!1;for(let i of t)e.has(i)||(e.add(i),n=!0);return n},E=e=>JSON.stringify([...e]),d="(SELECT value FROM json_each(?))";for(;;){let e=o(r,n(`SELECT id FROM session_exchanges WHERE (${t.exchanges})
|
|
1370
|
+
OR source_request_id IN ${d} OR destination_request_id IN ${d} OR source_attempt_id IN ${d}
|
|
1371
|
+
OR destination_attempt_id IN ${d} OR source_binding_id IN ${d} OR destination_binding_id IN ${d}`,t.arg,t.arg,E(i),E(i),E(s),E(s),E(a),E(a))),_=o(i,n(`SELECT source_request_id AS id FROM session_exchanges WHERE id IN ${d} AND source_request_id IS NOT NULL
|
|
1372
|
+
UNION SELECT destination_request_id AS id FROM session_exchanges WHERE id IN ${d} AND destination_request_id IS NOT NULL`,E(r),E(r))),c=o(i,n(`SELECT id FROM work_requests WHERE parent_request_id IN ${d} OR root_request_id IN ${d}`,E(i),E(i))),u=o(i,n(`SELECT request_id AS id FROM work_attempts WHERE id IN ${d}`,E(s))),T=o(s,n(`SELECT id FROM work_attempts WHERE request_id IN ${d} OR resumed_session_binding_id IN ${d}`,E(i),E(a))),l=o(a,n(`SELECT id FROM session_bindings WHERE request_id IN ${d} OR source_attempt_id IN ${d}`,E(i),E(s)));if(!e&&!_&&!c&&!u&&!T&&!l)break}(function(e,t,...n){let i=e.prepare(`SELECT id FROM session_exchanges WHERE ${t}`).all(...n).map(e=>e.id);if(0===i.length)return;let r=b(e);for(let e of i)r.add(e);try{e.prepare("DELETE FROM session_exchange_events WHERE exchange_id IN (SELECT value FROM json_each(?))").run(JSON.stringify(i))}finally{r.clear()}e.prepare("DELETE FROM session_exchanges WHERE id IN (SELECT value FROM json_each(?))").run(JSON.stringify(i))})(e,`id IN ${d}`,E(r)),e.prepare(`DELETE FROM conversation_events WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM finalizations WHERE implementation_request_id IN ${d} OR review_request_id IN ${d} OR decision_request_id IN ${d}`).run(E(i),E(i),E(i)),e.prepare(`DELETE FROM candidate_manifests WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM attempt_finalization_baselines WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM conversation_projection_cursors WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM wake_safety_decisions WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM dispatch_leases WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM attempt_launch_intents WHERE request_id IN ${d}`).run(E(i)),e.prepare(`DELETE FROM dispatch_attention WHERE request_id IN ${d}`).run(E(i));let _=b(e);for(let e of i)_.add(e);try{e.prepare(`DELETE FROM engine_events WHERE request_id IN ${d}`).run(E(i))}finally{_.clear()}for(;s.size>0||a.size>0;){let t=n(`SELECT id FROM session_bindings WHERE id IN ${d}
|
|
1373
|
+
AND NOT EXISTS (SELECT 1 FROM work_attempts a WHERE a.resumed_session_binding_id = session_bindings.id)`,E(a));for(let n of t)e.prepare("DELETE FROM session_bindings WHERE id = ?").run(n),a.delete(n);let i=n(`SELECT id FROM work_attempts WHERE id IN ${d}
|
|
1374
|
+
AND NOT EXISTS (SELECT 1 FROM session_bindings b WHERE b.source_attempt_id = work_attempts.id)`,E(s));for(let t of i)e.prepare("DELETE FROM work_attempts WHERE id = ?").run(t),s.delete(t);if(0===t.length&&0===i.length)throw Error("Engine records could not be removed: unexpected attempt/binding reference cycle.")}for(let t of(e.prepare(`DELETE FROM conversation_events WHERE request_id IS NULL AND wake_id IN (SELECT id FROM wakes WHERE work_request_id IN ${d} OR parent_request_id IN ${d} OR root_request_id IN ${d})`).run(E(i),E(i),E(i)),e.prepare(`DELETE FROM wakes WHERE work_request_id IN ${d} OR parent_request_id IN ${d} OR root_request_id IN ${d}`).run(E(i),E(i),E(i)),e.prepare(`DELETE FROM terminal_followups WHERE request_id IN ${d}`).run(E(i)),n(`SELECT id FROM work_requests WHERE id IN ${d} ORDER BY depth DESC`,E(i))))e.prepare("DELETE FROM work_requests WHERE id = ?").run(t)}function j(e,t){e.prepare("DELETE FROM conversation_intakes WHERE conversation_id = ?").run(t),e.prepare("DELETE FROM delegation_chains WHERE conversation_id = ?").run(t),e.prepare("DELETE FROM conversation_events WHERE conversation_id = ? AND request_id IS NULL").run(t),e.prepare("DELETE FROM wakes WHERE source_conversation_id = ?").run(t),z(e,{requests:"SELECT id FROM work_requests WHERE source_conversation_id = ?",bindings:"SELECT id FROM session_bindings WHERE conversation_id = ?",exchanges:"origin_conversation_id = ? OR destination_conversation_id = ?",arg:t})}function J(e,t){e.prepare(`DELETE FROM conversation_events WHERE request_id IS NULL AND wake_id IN (
|
|
1375
|
+
SELECT id FROM wakes WHERE target_agent_id = ? OR (requester_agent_id = ? AND work_request_id IS NULL))`).run(t,t),e.prepare("DELETE FROM wakes WHERE target_agent_id = ? OR (requester_agent_id = ? AND work_request_id IS NULL)").run(t,t),e.prepare("DELETE FROM wake_grants WHERE caller_agent_id = ? OR target_agent_id = ?").run(t,t),z(e,{requests:"SELECT id FROM work_requests WHERE target_agent_id = ?",bindings:"SELECT id FROM session_bindings WHERE agent_id = ?",exchanges:"source_agent_id = ? OR destination_agent_id = ?",arg:t})}function V(e){if(!e)return{};try{let t=JSON.parse(e);return t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch{return{}}}function Q(e){return"string"==typeof e&&e.length>0?e:null}function Z(e,t){return t?`${e}: ${t}`:e}function ee(e,t,n,i){let r="grant_required"===t,a=r?"needs your approval for edit work":n;return{kind:"wake_blocked",attemptId:null,text:a?`Wake blocked: ${e} — ${a}`:`Wake blocked: ${e}`,data:{...i,target_name:e,reason_code:t,reason:n,actions:r?["allow","deny"]:[]}}}e.s(["EXCHANGE_LIMITS",0,v,"EXCHANGE_STATES",0,I,"EXCHANGE_TERMINAL_STATES",0,S,"EXCHANGE_TRANSITIONS",0,A,"EngineStoreError",0,C,"TERMINAL_STATES",0,f,"UI_TURN_INTERRUPTED",0,B,"UI_TURN_INTERRUPTED_MESSAGE",0,M,"UI_TURN_REQUESTER",0,G,"createEngineStore",0,$,"deleteEngineRecordsForAgent",0,J,"deleteEngineRecordsForConversation",0,j,"migrateEngineSchema",0,F,"uiTurnExecutionPolicy",0,H],35613);let et=/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/,en=/^[a-z][a-z0-9_.:-]{0,63}$/;function ei(e){return null==e||""===e?null:et.test(e)?e:"[invalid]"}function er(e,t){return e&&en.test(e)?e:t}let ea="agent_name_conflict";function es(e){return String(e??"").trim()}function eo(e){return es(e).normalize("NFC").toLowerCase().normalize("NFC")}function eE(e){return`An Agent named "${es(e)}" already exists. Agent names must be unique, ignoring case and surrounding spaces.`}class ed extends Error{code=ea;requestedName;conflictingAgentId;constructor(e,t){super(eE(e)),this.name="AgentNameConflictError",this.requestedName=es(e),this.conflictingAgentId=t}}function e_(e){let t=[...e].sort((e,t)=>e.created_at-t.created_at||(e.id<t.id?-1:+(e.id>t.id))),n=new Map,i=[],r=[];for(let e of t){let t=eo(e.name);if(n.has(t)){i.push(e);continue}n.set(t,e.id),e.name_key!==t&&r.push({id:e.id,name:e.name,name_key:t})}let a=[];for(let e of i){let t=eo(e.name),i=es(e.name)||"Agent",s=2;for(;n.has(eo(`${i}-${s}`));)s++;let o=`${i}-${s}`,E=eo(o);n.set(E,e.id),r.push({id:e.id,name:o,name_key:E}),a.push({bot_id:e.id,previous_name:e.name,new_name:o,name_key:t,kept_bot_id:n.get(t)})}return{updates:r,renames:a}}e.s(["AgentNameConflictError",0,ed,"agentDisplayName",0,es,"agentNameConflictBody",0,function(e,t="name"){return{error:e.message,code:ea,field:t,name:e.requestedName,conflicting_agent_id:e.conflictingAgentId}},"agentNameConflictMessage",0,eE,"agentNameKey",0,eo,"planNameMigration",0,e_],30098);let ec=(0,e.i(52036).dbPath)();":memory:"!==ec&&i.default.mkdirSync(r.default.dirname(r.default.resolve(ec)),{recursive:!0});let eu=new n.default(ec);eu.pragma("journal_mode = WAL"),eu.exec(`
|
|
1169
1376
|
CREATE TABLE IF NOT EXISTS bots (
|
|
1170
1377
|
id TEXT PRIMARY KEY,
|
|
1171
1378
|
name TEXT NOT NULL,
|
|
@@ -1315,7 +1522,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1315
1522
|
ON approval_requests(conversation_id, code);
|
|
1316
1523
|
CREATE INDEX IF NOT EXISTS idx_approval_requests_conversation
|
|
1317
1524
|
ON approval_requests(conversation_id, status, created_at);
|
|
1318
|
-
`);let
|
|
1525
|
+
`);let eT=["#C6F54A","#F0A05A","#E85D75","#C9A0FF","#F2E36B"],el="9e363764-e0d5-4fff-8ebd-ccbc46ba0ba5",eN="5fbe32c2-79cb-452e-9d9b-f8c9eb63b99b",ep=eu.prepare("PRAGMA table_info(bots)").all();ep.some(e=>"color"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN color TEXT"),ep.some(e=>"pinned"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0"),ep.some(e=>"last_seen"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN last_seen INTEGER"),ep.some(e=>"unread"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN unread INTEGER NOT NULL DEFAULT 0"),ep.some(e=>"hidden"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0"),ep.some(e=>"source_provider"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN source_provider TEXT"),ep.some(e=>"template_id"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN template_id TEXT"),ep.some(e=>"template_url"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN template_url TEXT"),ep.some(e=>"import_schema_version"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN import_schema_version TEXT"),ep.some(e=>"import_operation_id"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN import_operation_id TEXT"),ep.some(e=>"import_timestamp"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN import_timestamp INTEGER"),ep.some(e=>"hermes_profile"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN hermes_profile TEXT"),ep.some(e=>"persistent_runtime"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN persistent_runtime TEXT NOT NULL DEFAULT 'hermes'"),ep.some(e=>"coding_runtime"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN coding_runtime TEXT"),ep.some(e=>"deck_name"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN deck_name TEXT"),ep.some(e=>"working_directory"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN working_directory TEXT"),ep.some(e=>"runtime"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN runtime TEXT"),ep.some(e=>"agent_client"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN agent_client TEXT"),ep.some(e=>"deck_id"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN deck_id TEXT"),ep.some(e=>"needs_deck_reselection"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN needs_deck_reselection INTEGER NOT NULL DEFAULT 0"),ep.some(e=>"agent"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN agent TEXT"),ep.some(e=>"needs_deck_selection"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN needs_deck_selection INTEGER NOT NULL DEFAULT 0");{let e=eu.prepare("SELECT id, agent, runtime, agent_client, persistent_runtime, coding_runtime, deck_id, deck_name, working_directory, needs_deck_reselection, needs_deck_selection FROM bots WHERE agent IS NULL").all(),t=eu.prepare("UPDATE bots SET agent = ?, deck_id = ?, deck_name = ?, working_directory = ?, needs_deck_selection = ? WHERE id = ?");eu.transaction(e=>{for(let n of e){let e=(0,s.migrateLegacyAgentFields)(n);t.run(e.agent,e.deck_id,e.deck_name,e.working_directory,+!!e.needs_deck_selection,n.id)}})(e)}ep.some(e=>"avatar_color"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN avatar_color TEXT"),ep.some(e=>"avatar_eyes"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN avatar_eyes TEXT"),ep.some(e=>"avatar_hands"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN avatar_hands TEXT"),ep.some(e=>"avatar_accessory"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN avatar_accessory TEXT"),ep.some(e=>"name_key"===e.name)||eu.exec("ALTER TABLE bots ADD COLUMN name_key TEXT"),eu.exec(`
|
|
1319
1526
|
CREATE TABLE IF NOT EXISTS agent_name_migrations (
|
|
1320
1527
|
id TEXT PRIMARY KEY,
|
|
1321
1528
|
bot_id TEXT NOT NULL,
|
|
@@ -1326,10 +1533,10 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1326
1533
|
reason TEXT NOT NULL,
|
|
1327
1534
|
created_at INTEGER NOT NULL
|
|
1328
1535
|
);
|
|
1329
|
-
`),
|
|
1536
|
+
`),eu.transaction(()=>{let e=e_(eu.prepare("SELECT id, name, created_at, name_key FROM bots").all());if(0===e.updates.length)return;let t=eu.prepare("UPDATE bots SET name_key = NULL WHERE id = ?");for(let n of e.updates)t.run(n.id);let n=eu.prepare("UPDATE bots SET name = ?, name_key = ? WHERE id = ?");for(let t of e.updates)n.run(t.name,t.name_key,t.id);let i=eu.prepare("INSERT INTO agent_name_migrations (id, bot_id, previous_name, new_name, name_key, kept_bot_id, reason, created_at) VALUES (?, ?, ?, ?, ?, ?, 'duplicate_name', ?)"),r=Date.now();for(let t of e.renames)i.run((0,a.randomUUID)(),t.bot_id,t.previous_name,t.new_name,t.name_key,t.kept_bot_id,r),console.warn(`[botmancers] Agent ${t.bot_id} renamed "${t.previous_name}" -> "${t.new_name}": name already used by Agent ${t.kept_bot_id}.`)})(),eu.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_bots_name_key ON bots(name_key)"),eu.exec(`
|
|
1330
1537
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_bots_import_operation
|
|
1331
1538
|
ON bots(import_operation_id) WHERE import_operation_id IS NOT NULL
|
|
1332
|
-
`),
|
|
1539
|
+
`),eu.prepare("UPDATE bots SET color = ? WHERE id = ?").run(eT[0],el),eu.prepare("UPDATE bots SET color = ? WHERE id = ?").run(eT[1],eN);let eR=eu.prepare("SELECT id FROM bots WHERE id NOT IN (?, ?) ORDER BY created_at ASC").all(el,eN),eO=eu.prepare("UPDATE bots SET color = ? WHERE id = ?");function em(e,t){let n=es(e),i=eo(n),r=eu.prepare("SELECT id FROM bots WHERE name_key = ?").get(i);if(r&&r.id!==t)throw new ed(n,r.id);return{name:n,name_key:i}}function eL(e,t){try{return t()}catch(t){if(t instanceof Error&&/UNIQUE constraint failed: bots\.name_key/.test(t.message)){let t=eu.prepare("SELECT id FROM bots WHERE name_key = ?").get(eo(e));throw new ed(e,t?.id??null)}throw t}}function eg(){return eT[eu.prepare("SELECT COUNT(*) AS n FROM bots").get().n%eT.length]}eR.forEach((e,t)=>{eO.run(eT[(t+2)%eT.length],e.id)});let eI=eu.prepare("PRAGMA table_info(messages)").all();eI.some(e=>"handoff_targets"===e.name)||eu.exec("ALTER TABLE messages ADD COLUMN handoff_targets TEXT"),eu.prepare("PRAGMA table_info(groups)").all().some(e=>"owner_bot_id"===e.name)||eu.exec("ALTER TABLE groups ADD COLUMN owner_bot_id TEXT"),eu.prepare("PRAGMA table_info(launch_snapshots)").all().some(e=>"transport"===e.name)||eu.exec("ALTER TABLE launch_snapshots ADD COLUMN transport TEXT NOT NULL DEFAULT 'hermes-gateway'");let eS=eu.prepare("PRAGMA table_info(conversations)").all();eS.some(e=>"origin_kind"===e.name)||eu.exec("ALTER TABLE conversations ADD COLUMN origin_kind TEXT"),eS.some(e=>"origin_id"===e.name)||eu.exec("ALTER TABLE conversations ADD COLUMN origin_id TEXT"),eI.some(e=>"sender_kind"===e.name)||eu.exec("ALTER TABLE messages ADD COLUMN sender_kind TEXT"),eI.some(e=>"request_id"===e.name)||eu.exec("ALTER TABLE messages ADD COLUMN request_id TEXT"),eu.exec(`
|
|
1333
1540
|
CREATE TABLE IF NOT EXISTS conversation_participants (
|
|
1334
1541
|
conversation_id TEXT NOT NULL,
|
|
1335
1542
|
participant_kind TEXT NOT NULL,
|
|
@@ -1338,7 +1545,7 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1338
1545
|
PRIMARY KEY (conversation_id, participant_kind, participant_id),
|
|
1339
1546
|
FOREIGN KEY (conversation_id) REFERENCES conversations(id)
|
|
1340
1547
|
);
|
|
1341
|
-
`),
|
|
1548
|
+
`),F(eu);let eA=$(eu),ev=function(e){let t=e.prepare("SELECT * FROM work_requests WHERE id = ?"),n=e.prepare("SELECT * FROM work_attempts WHERE id = ?"),i=e.prepare("SELECT * FROM engine_events WHERE request_id = ? ORDER BY sequence ASC"),r=e.prepare("SELECT sequence FROM conversation_projection_cursors WHERE request_id = ?"),a=e.prepare(`
|
|
1342
1549
|
INSERT INTO conversation_projection_cursors (request_id, sequence) VALUES (?, ?)
|
|
1343
1550
|
ON CONFLICT (request_id) DO UPDATE SET sequence = excluded.sequence WHERE excluded.sequence > sequence
|
|
1344
1551
|
`),s=e.prepare(`
|
|
@@ -1346,41 +1553,66 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1346
1553
|
id, conversation_id, engine_event_id, part, request_id, request_sequence, attempt_id, wake_id,
|
|
1347
1554
|
kind, state, text, data, sort_at, request_created_at, created_at
|
|
1348
1555
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1349
|
-
`);function o(e){return e?n.get(e):void 0}function
|
|
1556
|
+
`);function o(e){return e?n.get(e):void 0}function E(n){return e.transaction(()=>{let e=t.get(n);if(!e)return 0;let E=r.get(n)?.sequence??0,d=i.all(n),_=d.length>0?d[d.length-1].sequence:0;if(_<=E)return 0;let c={state:null,lastFinished:null},u=0,T=0;for(let t of d){u=Math.max(u,t.created_at);let n={...c};!function(e,t){let n=V(t.data);"accepted"===t.type&&Q(n.state)&&(e.state=n.state),"state_changed"===t.type&&Q(n.to)&&(e.state=n.to),"attempt_finished"===t.type&&t.attempt_id&&(e.lastFinished={attemptId:t.attempt_id,outcome:Q(n.outcome)})}(c,t),t.sequence<=E||null!==e.legacy_agent_request_id||(function(e,t,n){let i=V(e.data),r=V(t.policy_snapshot),a=null!==t.wake_event_id,s=Q(r.target_name_snapshot)??t.target_agent_id,E={target_agent_id:t.target_agent_id,execution_kind:t.execution_kind,tool_profile:t.tool_profile};switch(e.type){case"accepted":if("blocked"===i.state)return[];if(a)return[{kind:"wake_accepted",attemptId:null,text:`Wake accepted: ${s} (${t.execution_kind})`,data:{...E,target_name:s,requester_kind:t.requester_kind,requester_id:t.requester_id,parent_request_id:t.parent_request_id,depth:t.depth,wake_depth:t.wake_depth,grant_rule:Q(r.grant_rule),grant_id:Q(r.grant_id)}}];return[{kind:"request_queued",attemptId:null,text:"Queued",data:{...E,requester_kind:t.requester_kind,requester_id:t.requester_id}}];case"state_changed":{let e=Q(i.to),r=Q(i.from),d=Q(i.reason);switch(e){case"blocked":if(a&&"queued"===r&&"blocked"===n.state){let e=function(e){if(!e)return{code:null,reason:null};let t=/^([a-z_]+): ([\s\S]*)$/.exec(e);return t?{code:t[1],reason:t[2]}:{code:null,reason:e}}(d);return[ee(s,e.code,e.reason,E)]}return[{kind:"request_blocked",attemptId:null,text:Z("Blocked",d),data:{from:r,reason:d}}];case"queued":if("retry_scheduled"===d){let e="number"==typeof i.attempt_count?i.attempt_count:null,t="number"==typeof i.max_attempts?i.max_attempts:null;return[{kind:"request_retry_scheduled",attemptId:n.lastFinished?.attemptId??null,text:!0===i.manual?`Retry requested${null!==e&&null!==t?` (Attempt ${e+1} of ${t})`:""}`:`Retry scheduled${null!==e&&null!==t?` (Attempt ${e+1} of ${t})`:""}${"number"==typeof i.delay_ms?` in ${i.delay_ms} ms`:""}`,data:{from:r,reason:d,manual:!0===i.manual,attempt_count:e,max_attempts:t,next_eligible_at:i.next_eligible_at??null,delay_ms:i.delay_ms??null,category:i.category??null,outcome:n.lastFinished?.outcome??null}}]}if(a&&"blocked"===r&&("grant_approved"===d||"target_available"===d))return[{kind:"wake_accepted",attemptId:null,text:`Wake accepted: ${s} (${t.execution_kind})`,data:{...E,target_name:s,requester_kind:t.requester_kind,requester_id:t.requester_id,parent_request_id:t.parent_request_id,depth:t.depth,wake_depth:t.wake_depth,reason:d,grant_rule:i.grant_rule??null,grant_id:i.grant_id??null}}];return[{kind:"request_queued",attemptId:null,text:Z("Queued again",d),data:{from:r,reason:d}}];case"running":return[{kind:"request_running",attemptId:null,text:"Running",data:{phase:"dispatched",from:r}}];case"waiting":return[{kind:"request_waiting",attemptId:null,text:Z("Waiting",d),data:{from:r,reason:d}}];case"completed":{let e=n.lastFinished,i=e?.outcome==="succeeded",r=[{kind:"request_completed",attemptId:e?.attemptId??null,text:i?"Completed":"Completed without a successful Attempt outcome",data:{success:i,outcome:e?.outcome??null}}];if(i&&e){let n=o(e.attemptId),i=V(t.result);r.push({kind:"result",attemptId:e.attemptId,text:n?.output??"Result recorded",data:{reply_message_id:Q(i.reply_message_id),has_output:"string"==typeof n?.output}})}return r}case"failed":case"cancelled":{let a=n.lastFinished,s=t.error_code??Q(i.error_code),o=t.error_message;if("failed"===e&&"timed_out"===d)return[{kind:"request_timed_out",attemptId:a?.attemptId??null,text:"Timed out: the request passed its deadline",data:{success:!1,error_code:s,reason:d,deadline_at:i.deadline_at??null,from:r,outcome:a?.outcome??null}}];if("failed"===e&&"retries_exhausted"===d)return[{kind:"request_retries_exhausted",attemptId:a?.attemptId??null,text:Z(`Retries exhausted after ${i.attempt_count??"?"} of ${i.max_attempts??"?"} Attempts`,o??s),data:{success:!1,error_code:s,error_message:o,reason:d,attempt_count:i.attempt_count??null,max_attempts:i.max_attempts??null,outcome:a?.outcome??null}}];return[{kind:"failed"===e?"request_failed":"request_cancelled",attemptId:a?.attemptId??null,text:"failed"===e?Z("Failed",o??s):"cancel_requested"===d?Z("Cancelled",t.cancel_reason):"grant_denied"===d?"Cancelled: owner denied edit Wake":Z("Cancelled",d??o),data:{success:!1,error_code:s,error_message:o,reason:d,outcome:a?.outcome??null}}]}default:return[]}}case"runtime_started":{let t=Q(i.adapter);return[{kind:"request_running",attemptId:e.attempt_id,text:t?`Running on ${t}`:"Running",data:{phase:"runtime_started",adapter:t,external_run_id:Q(i.external_run_id),success:!1}}]}case"wake_reblocked":return[ee(s,Q(i.reason_code),Q(i.reason),E)];case"dispatch_deferred":return[{kind:"request_queued",attemptId:null,text:"Queued: waiting for capacity",data:{waiting_for:"capacity",limit:Q(i.reason),active_global:i.active_global??null,active_target:i.active_target??null,max_global:i.max_global??null,max_per_target:i.max_per_target??null}}];case"lineage_stopped":return[{kind:"lineage_stopped",attemptId:null,text:"continuation_budget_exhausted"===i.reason?`Stopped: coordinator continuation limit ${i.limit??"?"} reached`:Z("Stopped",Q(i.reason)),data:i}];case"cancel_requested":{let e=Q(i.reason);return[{kind:"request_cancel_requested",attemptId:null,text:Z("Cancel requested",e),data:{by:Q(i.by),reason:e,state:Q(i.state)}}]}case"question":{let t=Q(i.question)??"";return[{kind:"question",attemptId:e.attempt_id,text:t,data:{question:t}}]}case"attempt_finished":{let t=o(e.attempt_id);if(!t)return[];let n=[];try{let e=JSON.parse(t.artifacts);Array.isArray(e)&&(n=e)}catch{}return n.filter(e=>!(e&&"object"==typeof e&&"candidate_manifest"===e.kind)).map(e=>{let n=e&&"object"==typeof e?e:{ref:String(e)},i=Q(n.kind)??"artifact",r=Q(n.ref)??"";return{kind:"artifact",attemptId:t.id,text:`Artifact (${i}): ${r}`,data:{artifact_kind:i,ref:r,outcome:t.outcome}}})}case"candidate_manifest_recorded":{let t=Q(i.manifest_digest),n="number"==typeof i.file_count?i.file_count:0;return[{kind:"artifact",attemptId:e.attempt_id,text:`Candidate manifest ${t}: ${n} ${1===n?"file":"files"} on base ${Q(i.base_commit)}`,data:{artifact_kind:"candidate_manifest",ref:t,...i}}]}case"candidate_manifest_unavailable":return[{kind:"finalization_blocked",attemptId:e.attempt_id,text:Z("Not finalizable",Q(i.reason_code)),data:{phase:"candidate",...i}}];case"finalization_preparing":return[{kind:"finalization_preparing",attemptId:e.attempt_id,text:`Finalization preparing: manifest ${Q(i.manifest_digest)} (${i.file_count??0} files), review ${Q(i.review_request_id)}`,data:i}];case"finalization_retry_pending":return[{kind:"finalization_preparing",attemptId:e.attempt_id,text:Z("Finalization waiting to retry",Q(i.reason_code)),data:{retry:!0,...i}}];case"finalization_committed":return[{kind:"finalization_committed",attemptId:e.attempt_id,text:`Finalization committed: commit ${Q(i.commit)} (tree ${Q(i.tree)}, manifest ${Q(i.result_manifest_digest)??Q(i.manifest_digest)})`,data:{success:!0,...i}}];case"finalization_blocked":case"finalization_failed":case"finalization_canceled":{let t="finalization_blocked"===e.type?"blocked":"finalization_failed"===e.type?"failed":"canceled";return[{kind:e.type,attemptId:e.attempt_id,text:Z(`Finalization ${t}`,Q(i.reason_code)),data:{success:!1,...i}}]}case"finalization_rejected":return[{kind:"finalization_rejected",attemptId:null,text:Z("Finalization not started",Q(i.reason_code)),data:i}];default:return[]}})(t,e,n).forEach((n,i)=>{T+=s.run(`${t.id}:${i}`,e.source_conversation_id,t.id,i,e.id,t.sequence,n.attemptId,e.wake_event_id,n.kind,c.state,n.text,JSON.stringify(n.data),u,e.created_at,t.created_at).changes})}return a.run(n,_),T}).immediate()}function d(t){return e.transaction(()=>e.prepare("SELECT id FROM work_requests WHERE source_conversation_id = ? ORDER BY created_at ASC, id ASC").all(t).reduce((e,t)=>e+E(t.id),0)+function(t){let n=e.prepare(`
|
|
1350
1557
|
SELECT w.* FROM wakes w
|
|
1351
1558
|
WHERE w.source_conversation_id = ? AND w.status = 'rejected'
|
|
1352
1559
|
AND NOT EXISTS (SELECT 1 FROM conversation_events e WHERE e.id = 'wake:' || w.id || ':0')
|
|
1353
1560
|
ORDER BY w.created_at ASC, w.position ASC
|
|
1354
|
-
`).all(t),
|
|
1561
|
+
`).all(t),i=0;for(let e of n){let t={wake_id:e.id,target_name:e.target_name_snapshot??e.requested_target,target_agent_id:e.target_agent_id,execution_kind:e.execution_kind,requester_agent_id:e.requester_agent_id,parent_request_id:e.parent_request_id,reason_code:e.reason_code,reason:e.reason,limit:e.limit_value,observed:e.observed_value,work_request_id:null};i+=s.run(`wake:${e.id}:0`,e.source_conversation_id,null,0,null,0,null,e.id,"wake_rejected",null,function(e){let t=e.target_name_snapshot??e.requested_target??"an unnamed target";switch(e.reason_code){case"untracked_lineage":return"Wake not started: its source turn is not tracked work";case"depth_exceeded":return`Wake not started: ${t} — depth limit ${e.limit_value??"?"} reached`;case"root_budget_exhausted":return`Wake not started: ${t} — this work already used ${e.observed_value??e.limit_value??"?"} Wakes`;default:return e.reason?`Wake not started: ${t} — ${e.reason}`:`Wake not started: ${t}`}}(e),JSON.stringify(t),e.updated_at,e.created_at,e.updated_at).changes}return i}(t)).immediate()}function _(t){return e.prepare(`
|
|
1355
1562
|
SELECT * FROM conversation_events WHERE conversation_id = ?
|
|
1356
1563
|
ORDER BY sort_at ASC, request_created_at ASC, COALESCE(request_id, wake_id) ASC, request_sequence ASC, part ASC
|
|
1357
|
-
`).all(t)}return{projectRequest:
|
|
1564
|
+
`).all(t)}return{projectRequest:E,projectConversation:d,projectEvent:function(e){return E(e.request_id)},listConversationEventRows:_,listConversationEvents:function(e){return d(e),_(e).map((e,t)=>({eventId:e.id,seq:t+1,kind:e.kind,requestId:e.request_id,requestSequence:e.request_sequence,attemptId:e.attempt_id,wakeId:e.wake_id,engineEventId:e.engine_event_id,state:e.state,text:e.text,data:V(e.data),createdAt:e.created_at}))}}}(eu),ek=(eu.exec(`
|
|
1565
|
+
CREATE TABLE IF NOT EXISTS service_audit_events (
|
|
1566
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1567
|
+
at INTEGER NOT NULL,
|
|
1568
|
+
principal TEXT NOT NULL CHECK (length(principal) BETWEEN 1 AND 200),
|
|
1569
|
+
operation TEXT NOT NULL CHECK (length(operation) BETWEEN 1 AND 64),
|
|
1570
|
+
capability TEXT NOT NULL CHECK (length(capability) BETWEEN 1 AND 64),
|
|
1571
|
+
target_kind TEXT NOT NULL CHECK (target_kind IN ('grants', 'agent', 'session', 'conversation', 'exchange', 'request')),
|
|
1572
|
+
target_ref TEXT CHECK (target_ref IS NULL OR length(target_ref) <= 128),
|
|
1573
|
+
agent_id TEXT CHECK (agent_id IS NULL OR length(agent_id) <= 128),
|
|
1574
|
+
outcome TEXT NOT NULL CHECK (outcome IN ('allowed', 'denied', 'rejected', 'error')),
|
|
1575
|
+
code TEXT CHECK (code IS NULL OR length(code) <= 64)
|
|
1576
|
+
);
|
|
1577
|
+
CREATE INDEX IF NOT EXISTS idx_service_audit_principal ON service_audit_events(principal, id);
|
|
1578
|
+
CREATE TRIGGER IF NOT EXISTS trg_service_audit_no_update BEFORE UPDATE ON service_audit_events
|
|
1579
|
+
BEGIN
|
|
1580
|
+
SELECT RAISE(ABORT, 'service_audit_events are append-only');
|
|
1581
|
+
END;
|
|
1582
|
+
CREATE TRIGGER IF NOT EXISTS trg_service_audit_no_delete BEFORE DELETE ON service_audit_events
|
|
1583
|
+
BEGIN
|
|
1584
|
+
SELECT RAISE(ABORT, 'service_audit_events are append-only');
|
|
1585
|
+
END;
|
|
1586
|
+
`),t=eu.prepare(`
|
|
1587
|
+
INSERT INTO service_audit_events (at, principal, operation, capability, target_kind, target_ref, agent_id, outcome, code)
|
|
1588
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1589
|
+
`),{append(e){let n=`${e.principal.kind}:${ei(e.principal.id)??"[invalid]"}`;t.run(e.at??Date.now(),n.slice(0,200),er(e.operation,"unknown"),er(e.capability,"none"),e.targetKind,ei(e.targetRef),ei(e.agentId),e.outcome,e.code?er(e.code,"unknown"):null)},list(e={}){let t=Math.min(Math.max(1,e.limit??50),500);return e.principal?eu.prepare("SELECT * FROM service_audit_events WHERE principal = ? ORDER BY id DESC LIMIT ?").all(e.principal,t):eu.prepare("SELECT * FROM service_audit_events ORDER BY id DESC LIMIT ?").all(t)}}),ef={kind:"person",id:"local-owner"},eq=eu.prepare("INSERT OR IGNORE INTO conversation_participants (conversation_id, participant_kind, participant_id, joined_at) VALUES (?, ?, ?, ?)");function eh(e,t,n){for(let i of(eu.prepare("UPDATE conversations SET origin_kind = ?, origin_id = ? WHERE id = ? AND origin_kind IS NULL").run(ef.kind,ef.id,e),eq.run(e,ef.kind,ef.id,n),t))eq.run(e,"bot",i,n)}eu.transaction(()=>{eu.exec("UPDATE messages SET sender_kind = 'person' WHERE sender_kind IS NULL AND sender_type = 'user'"),eu.exec("UPDATE messages SET sender_kind = 'bot' WHERE sender_kind IS NULL AND sender_type = 'bot'");let e=eu.prepare("SELECT id, type, bot_id, group_id, created_at FROM conversations WHERE origin_kind IS NULL AND type IN ('bot', 'group')").all(),t=eu.prepare("SELECT bot_id FROM group_members WHERE group_id = ?");for(let n of e){let e="bot"===n.type?n.bot_id?[n.bot_id]:[]:n.group_id?t.all(n.group_id).map(e=>e.bot_id):[];eh(n.id,e,n.created_at)}})();let eC={create:(e,t)=>{let n=em(e.name),i={id:t?.id||(0,a.randomUUID)(),...e,...n,color:eg(),created_at:t?.created_at??Date.now()};i.agent=i.agent||s.DEFAULT_AGENT,i.deck_id=i.deck_id||null,i.needs_deck_selection=!i.deck_id||i.needs_deck_selection?1:0,eL(i.name,()=>eu.prepare("INSERT INTO bots (id, name, name_key, title, description, avatar, color, hermes_profile, agent, deck_id, deck_name, working_directory, needs_deck_selection, avatar_color, avatar_eyes, avatar_hands, avatar_accessory, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(i.id,i.name,i.name_key,i.title,i.description,i.avatar||null,i.color,i.hermes_profile||null,i.agent,i.deck_id,i.deck_name||null,i.working_directory||null,i.needs_deck_selection,i.avatar_color||null,i.avatar_eyes||null,i.avatar_hands||null,i.avatar_accessory||null,i.created_at));let r=(0,a.randomUUID)();return eu.prepare("INSERT INTO conversations (id, type, bot_id, created_at) VALUES (?, ?, ?, ?)").run(r,"bot",i.id,i.created_at),eh(r,[i.id],i.created_at),i},createFromImport:(e,t)=>{let n=em(e.name),i={id:(0,a.randomUUID)(),...e,...n,color:eg(),created_at:Date.now(),agent:s.DEFAULT_AGENT,deck_id:null,deck_name:null,working_directory:null,needs_deck_selection:1,source_provider:t.source_provider,template_id:t.template_id,template_url:t.template_url,import_schema_version:t.import_schema_version,import_operation_id:t.import_operation_id,import_timestamp:t.import_timestamp};eL(i.name,()=>eu.prepare(`INSERT INTO bots (
|
|
1358
1590
|
id, name, name_key, title, description, avatar, color, created_at,
|
|
1359
1591
|
source_provider, template_id, template_url, import_schema_version,
|
|
1360
1592
|
import_operation_id, import_timestamp,
|
|
1361
1593
|
agent, deck_id, deck_name, working_directory,
|
|
1362
1594
|
needs_deck_selection
|
|
1363
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(
|
|
1595
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(i.id,i.name,i.name_key,i.title,i.description,i.avatar||null,i.color,i.created_at,i.source_provider,i.template_id,i.template_url,i.import_schema_version,i.import_operation_id,i.import_timestamp,i.agent,i.deck_id,i.deck_name,i.working_directory,i.needs_deck_selection));let r=(0,a.randomUUID)();return eu.prepare("INSERT INTO conversations (id, type, bot_id, created_at) VALUES (?, ?, ?, ?)").run(r,"bot",i.id,i.created_at),eh(r,[i.id],i.created_at),i},getByImportOperationId:e=>eu.prepare("SELECT * FROM bots WHERE import_operation_id = ?").get(e),getAll:()=>eu.prepare("SELECT * FROM bots ORDER BY created_at DESC").all(),getById:e=>eu.prepare("SELECT * FROM bots WHERE id = ?").get(e),setAvatar:(e,t)=>{eu.prepare("UPDATE bots SET avatar = ? WHERE id = ?").run(t,e)},getByName:e=>{let t=eo(e);if(t)return eu.prepare("SELECT * FROM bots WHERE name_key = ?").get(t)},updateIdentity:(e,t,n,i)=>{let r=em(t,e);eL(r.name,()=>eu.prepare("UPDATE bots SET name = ?, name_key = ?, title = ?, description = ? WHERE id = ?").run(r.name,r.name_key,n,i,e))},setPinned:(e,t)=>{eu.prepare("UPDATE bots SET pinned = ? WHERE id = ?").run(+!!t,e)},setHidden:(e,t)=>{eu.prepare("UPDATE bots SET hidden = ? WHERE id = ?").run(+!!t,e)},setHermesProfile:(e,t)=>{let n=t&&t.trim()?t.trim():null;eu.prepare("UPDATE bots SET hermes_profile = ? WHERE id = ?").run(n,e)},updateAgentSelection:(e,t)=>{let n=eC.getById(e);if(!n)return;let i=(0,s.applyAgentUpdate)(n,t);eu.prepare("UPDATE bots SET agent = ?, deck_id = ?, deck_name = ?, working_directory = ?, needs_deck_selection = ? WHERE id = ?").run(i.agent,i.deck_id,i.deck_name,i.working_directory,+!!i.needs_deck_selection,e)},updateAvatarConfig:(e,t)=>{let n=eC.getById(e);if(!n)return;let i=(e,t)=>void 0===e?t||null:e&&String(e).trim()?String(e).trim():null;eu.prepare("UPDATE bots SET avatar_color = ?, avatar_eyes = ?, avatar_hands = ?, avatar_accessory = ? WHERE id = ?").run(i(t.avatar_color,n.avatar_color),i(t.avatar_eyes,n.avatar_eyes),i(t.avatar_hands,n.avatar_hands),i(t.avatar_accessory,n.avatar_accessory),e)},touchSeen:()=>{eu.prepare("UPDATE bots SET last_seen = ?").run(Date.now())},markUnread:e=>{eu.prepare("UPDATE bots SET unread = 1 WHERE id = ?").run(e)},markRead:e=>{eu.prepare("UPDATE bots SET unread = 0 WHERE id = ?").run(e)},remove:e=>{eC.removeMany([e])},deletionPreview:e=>{var t;let n=new Set(e),i=[],r=[],a=[],s=new Set(eD());for(let t of e){let e=eC.getById(t);if(!e){r.push(t);continue}i.push({id:e.id,name:e.name}),(0,o.isChiefOfStaffName)(e.name)?a.push({id:e.id,name:e.name,reason:"chief"}):s.has(e.id)&&a.push({id:e.id,name:e.name,reason:"active"})}return{agents:i,groups:0===(t=n).size?[]:eu.prepare(`SELECT DISTINCT g.id, g.name, g.owner_bot_id, g.created_at FROM groups g
|
|
1364
1596
|
JOIN group_members gm ON gm.group_id = g.id
|
|
1365
1597
|
WHERE gm.bot_id IN (${[...t].map(()=>"?").join(", ")})
|
|
1366
|
-
ORDER BY g.created_at ASC, g.id ASC`).all(...t).map(e=>{let n=
|
|
1367
|
-
WHERE gm.group_id = ? ORDER BY b.created_at ASC, b.id ASC`).all(e.id).filter(e=>!t.has(e.id));return n.length<2?{id:e.id,name:e.name,outcome:"removed",remaining:n.length,newOwner:null}:e.owner_bot_id&&t.has(e.owner_bot_id)?{id:e.id,name:e.name,outcome:"reassigned",remaining:n.length,newOwner:n[0]}:{id:e.id,name:e.name,outcome:"shrunk",remaining:n.length,newOwner:null}}),missing:
|
|
1598
|
+
ORDER BY g.created_at ASC, g.id ASC`).all(...t).map(e=>{let n=eu.prepare(`SELECT b.id, b.name FROM bots b JOIN group_members gm ON gm.bot_id = b.id
|
|
1599
|
+
WHERE gm.group_id = ? ORDER BY b.created_at ASC, b.id ASC`).all(e.id).filter(e=>!t.has(e.id));return n.length<2?{id:e.id,name:e.name,outcome:"removed",remaining:n.length,newOwner:null}:e.owner_bot_id&&t.has(e.owner_bot_id)?{id:e.id,name:e.name,outcome:"reassigned",remaining:n.length,newOwner:n[0]}:{id:e.id,name:e.name,outcome:"shrunk",remaining:n.length,newOwner:null}}),missing:r,blocked:a}},removeMany:(e,t)=>eu.transaction(()=>{let n=eC.deletionPreview(e);if(n.missing.length>0||n.blocked.length>0)throw new ew(n);let i=new Set(e);for(let e of n.groups){if("removed"===e.outcome){var r=e.id;for(let e of eu.prepare("SELECT id FROM conversations WHERE group_id = ?").all(r))eb(e.id);eu.prepare("DELETE FROM group_members WHERE group_id = ?").run(r),eu.prepare("DELETE FROM groups WHERE id = ?").run(r);continue}let t=eu.prepare("SELECT id FROM conversations WHERE group_id = ?").all(e.id).map(e=>e.id);for(let n of i)for(let i of(eu.prepare("DELETE FROM group_members WHERE group_id = ? AND bot_id = ?").run(e.id,n),t))eu.prepare("DELETE FROM conversation_participants WHERE conversation_id = ? AND participant_kind = 'bot' AND participant_id = ?").run(i,n);e.newOwner&&eu.prepare("UPDATE groups SET owner_bot_id = ? WHERE id = ?").run(e.newOwner.id,e.id)}for(let n of e){for(let e of eu.prepare("SELECT id FROM conversations WHERE bot_id = ?").all(n))eb(e.id);J(eu,n),eU("bot_id",n),eu.prepare("DELETE FROM launch_snapshots WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM group_members WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM conversation_participants WHERE participant_kind = 'bot' AND participant_id = ? AND conversation_id IN (SELECT id FROM conversations WHERE type = 'group')").run(n),eu.prepare("DELETE FROM memories WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM one_shots WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM routines WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM pending_questions WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM approval_requests WHERE bot_id = ?").run(n),eu.prepare("DELETE FROM wake_targets WHERE target_bot_id = ?").run(n),eu.prepare("DELETE FROM bots WHERE id = ?").run(n),t?.onAgentDeleted?.(n)}return n})(),managementRows:()=>{let e=eu.prepare("SELECT * FROM bots ORDER BY created_at DESC, id ASC").all(),t=new Set(eD()),n=new Map,i=e=>{for(let t of e)t.id&&t.at&&(n.get(t.id)??0)<t.at&&n.set(t.id,t.at)};return i(eu.prepare("SELECT c.bot_id AS id, MAX(m.created_at) AS at FROM messages m JOIN conversations c ON c.id = m.conversation_id WHERE c.type = 'bot' GROUP BY c.bot_id").all()),i(eu.prepare("SELECT sender_id AS id, MAX(created_at) AS at FROM messages WHERE sender_type = 'bot' AND sender_id IS NOT NULL GROUP BY sender_id").all()),e.map(e=>({bot:e,last_activity:n.get(e.id)??null,blocked:(0,o.isChiefOfStaffName)(e.name)?"chief":t.has(e.id)?"active":null}))}};class ew extends Error{preview;constructor(e){super(e.missing.length>0?"Agent not found":"Some agents cannot be deleted"),this.preview=e}}function eD(){return eu.prepare(`
|
|
1368
1600
|
SELECT DISTINCT target_agent_id AS bot_id FROM work_requests
|
|
1369
1601
|
WHERE (executor <> 'dispatcher' AND state IN ('queued', 'running'))
|
|
1370
1602
|
OR (executor = 'dispatcher' AND state = 'running' AND json_extract(policy_snapshot, '$.surface') = 'ui')
|
|
1371
|
-
`).all().map(e=>e.bot_id)}function
|
|
1603
|
+
`).all().map(e=>e.bot_id)}function ey(){return new Set(eu.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('legacy_agent_requests_archive', 'legacy_agent_request_events_archive', 'legacy_processing_queue_archive')").all().map(e=>e.name))}function eU(e,t){ey().has("legacy_processing_queue_archive")&&eu.prepare(`DELETE FROM legacy_processing_queue_archive WHERE ${e} = ?`).run(t)}function eb(e){let t;j(eu,e),eu.prepare("DELETE FROM draft_actions WHERE message_id IN (SELECT id FROM messages WHERE conversation_id = ?)").run(e),t=ey(),eU("conversation_id",e),t.has("legacy_agent_request_events_archive")&&t.has("legacy_agent_requests_archive")&&eu.prepare("DELETE FROM legacy_agent_request_events_archive WHERE request_id IN (SELECT id FROM legacy_agent_requests_archive WHERE conversation_id = ?)").run(e),t.has("legacy_agent_requests_archive")&&eu.prepare("DELETE FROM legacy_agent_requests_archive WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM messages WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM pending_questions WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM approvals WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM approval_requests WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM one_shots WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM routines WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM wake_targets WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM conversation_participants WHERE conversation_id = ?").run(e),eu.prepare("DELETE FROM conversations WHERE id = ?").run(e)}let eF={getByBotId:e=>eu.prepare("SELECT * FROM conversations WHERE bot_id = ?").get(e),getByGroupId:e=>eu.prepare("SELECT * FROM conversations WHERE group_id = ?").get(e),getById:e=>eu.prepare("SELECT * FROM conversations WHERE id = ?").get(e),getUiById:e=>eu.prepare("SELECT * FROM conversations WHERE id = ? AND type != 'agent'").get(e)},eW={create:(e,t,n,i,r)=>{let s={id:(0,a.randomUUID)(),conversation_id:e,sender_type:t,sender_id:i,sender_kind:"bot"===t?"bot":ef.kind,content:n,handoff_targets:r&&r.length>0?JSON.stringify(r):null,created_at:Date.now()};if(eu.prepare("INSERT INTO messages (id, conversation_id, sender_type, sender_id, sender_kind, content, handoff_targets, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(s.id,s.conversation_id,s.sender_type,s.sender_id||null,s.sender_kind,s.content,s.handoff_targets||null,s.created_at),"bot"===t){i&&eC.markUnread(i);let t=eu.prepare("SELECT bot_id FROM conversations WHERE id = ? AND type = ?").get(e,"bot");t?.bot_id&&t.bot_id!==i&&eC.markUnread(t.bot_id)}return s},getById:e=>eu.prepare("SELECT * FROM messages WHERE id = ?").get(e),replaceContent:(e,t)=>{eu.prepare("UPDATE messages SET content = ? WHERE id = ?").run(t,e)},getByConversation:e=>eu.prepare("SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at ASC").all(e),getBetween:(e,t)=>{let n=eW.getById(e),i=eW.getById(t);if(!n||!i||n.conversation_id!==i.conversation_id)return null;let r=eu.prepare("SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at ASC, rowid ASC").all(n.conversation_id),a=r.findIndex(t=>t.id===e),s=r.findIndex(e=>e.id===t);if(a<0||s<0)return null;let[o,E]=a<s?[a,s]:[s,a];return r.slice(o+1,E)},latestFromBot:e=>{let t=eF.getByBotId(e);for(let n of eu.prepare(`SELECT content, conversation_id, created_at FROM messages
|
|
1372
1604
|
WHERE sender_type = 'bot' AND sender_id = ?
|
|
1373
1605
|
ORDER BY created_at DESC, rowid DESC
|
|
1374
|
-
LIMIT 20`).all(e)){if(t&&n.conversation_id!==t.id)continue;let e=
|
|
1606
|
+
LIMIT 20`).all(e)){if(t&&n.conversation_id!==t.id)continue;let e=eu.prepare(`SELECT content FROM messages
|
|
1375
1607
|
WHERE conversation_id = ? AND created_at < ?
|
|
1376
1608
|
ORDER BY created_at DESC, rowid DESC
|
|
1377
|
-
LIMIT 1`).get(n.conversation_id,n.created_at);if(!(e&&e.content.startsWith("[From ")))return n.content}return""},priorSentenceForHandoff:e=>{if(!e.handoff_targets)return null;let t=[];try{let n=JSON.parse(e.handoff_targets);if(!Array.isArray(n))return null;t=n.map(e=>String(e))}catch{return null}let n=
|
|
1609
|
+
LIMIT 1`).get(n.conversation_id,n.created_at);if(!(e&&e.content.startsWith("[From ")))return n.content}return""},priorSentenceForHandoff:e=>{if(!e.handoff_targets)return null;let t=[];try{let n=JSON.parse(e.handoff_targets);if(!Array.isArray(n))return null;t=n.map(e=>String(e))}catch{return null}let n=eu.prepare(`
|
|
1378
1610
|
SELECT m.conversation_id AS conversation_id, c.type AS type, c.bot_id AS bot_id
|
|
1379
1611
|
FROM messages m
|
|
1380
1612
|
JOIN conversations c ON c.id = m.conversation_id
|
|
1381
1613
|
WHERE m.content = ? AND m.handoff_targets = ?
|
|
1382
1614
|
ORDER BY m.created_at ASC
|
|
1383
|
-
`).all(e.content,e.handoff_targets).find(e=>"group"===e.type||!e.bot_id||!t.includes(e.bot_id)),
|
|
1615
|
+
`).all(e.content,e.handoff_targets).find(e=>"group"===e.type||!e.bot_id||!t.includes(e.bot_id)),i=n?.conversation_id||e.conversation_id,r=eW.getByConversation(i),a=[...r].reverse().find(t=>"user"===t.sender_type&&t.content===e.content&&t.handoff_targets===e.handoff_targets),s=a?a.created_at:e.created_at;for(let e=r.length-1;e>=0;e--){let t=r[e];if(a&&t.id===a.id||t.created_at>s||"bot"!==t.sender_type)continue;let n=(t.content||"").trim();if(n)return n}return null}},ex={get:(e,t)=>eu.prepare("SELECT * FROM approvals WHERE conversation_id = ? AND code = ?").get(e,t),recordPending:(e,t,n)=>(eu.prepare("INSERT OR IGNORE INTO approvals (conversation_id, code, message_id, status, created_at) VALUES (?, ?, ?, ?, ?)").run(e,t,n||null,"pending",Date.now()),ex.get(e,t)),resolve:(e,t,n)=>Number(eu.prepare("UPDATE approvals SET status = ?, resolved_at = ? WHERE conversation_id = ? AND code = ? AND status = 'pending'").run(n,Date.now(),e,t).changes)>0},eX=20;function eG(e){let t=eo(e);if(!t)return{ok:!1,reason:"not_found",requested:String(e??"")};let n=eu.prepare("SELECT id, name FROM bots WHERE name_key = ? LIMIT 2").all(t);return 0===n.length?{ok:!1,reason:"not_found",requested:e}:n.length>1?{ok:!1,reason:"ambiguous",requested:e}:{ok:!0,agentId:n[0].id,displayName:n[0].name}}eu.exec(`
|
|
1384
1616
|
CREATE TABLE IF NOT EXISTS wake_targets (
|
|
1385
1617
|
id TEXT PRIMARY KEY,
|
|
1386
1618
|
conversation_id TEXT NOT NULL,
|
|
@@ -1398,17 +1630,17 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1398
1630
|
ON wake_targets(conversation_id, created_at);
|
|
1399
1631
|
CREATE INDEX IF NOT EXISTS idx_wake_targets_target
|
|
1400
1632
|
ON wake_targets(target_bot_id, created_at);
|
|
1401
|
-
`),
|
|
1633
|
+
`),eu.exec(`
|
|
1402
1634
|
CREATE TABLE IF NOT EXISTS workspace_settings (
|
|
1403
1635
|
key TEXT PRIMARY KEY,
|
|
1404
1636
|
value TEXT NOT NULL,
|
|
1405
1637
|
updated_at INTEGER NOT NULL
|
|
1406
1638
|
);
|
|
1407
|
-
`),e.s(["BotDeletionError",0,
|
|
1639
|
+
`),e.s(["BotDeletionError",0,ew,"UI_OWNER_PRINCIPAL",0,ef,"agentNameMigrations",0,{list:()=>eu.prepare("SELECT * FROM agent_name_migrations ORDER BY created_at ASC, rowid ASC").all()},"approvals",0,ex,"bots",0,eC,"conversations",0,eF,"default",0,eu,"draftActions",0,{get:e=>eu.prepare("SELECT * FROM draft_actions WHERE message_id = ?").get(e),record:(e,t,n)=>Number(eu.prepare("INSERT OR IGNORE INTO draft_actions (message_id, status, recipient, acted_at) VALUES (?, ?, ?, ?)").run(e,t,n||null,Date.now()).changes)>0},"engine",0,eA,"groups",0,{create:(e,t,n,i)=>{let r=n&&t.includes(n)?n:t[0],s={id:(0,a.randomUUID)(),name:e,owner_bot_id:r,created_at:i?.created_at??Date.now()},o=eu.prepare("INSERT INTO groups (id, name, owner_bot_id, created_at) VALUES (?, ?, ?, ?)"),E=eu.prepare("INSERT INTO group_members (group_id, bot_id) VALUES (?, ?)"),d=eu.prepare("INSERT INTO conversations (id, type, group_id, created_at) VALUES (?, ?, ?, ?)");return eu.transaction(()=>{for(let e of(o.run(s.id,s.name,s.owner_bot_id||null,s.created_at),t))E.run(s.id,e);let e=(0,a.randomUUID)();d.run(e,"group",s.id,s.created_at),eh(e,t,s.created_at)})(),s},getAll:()=>eu.prepare("SELECT * FROM groups ORDER BY created_at DESC").all(),getById:e=>eu.prepare("SELECT * FROM groups WHERE id = ?").get(e),rename:(e,t)=>{eu.prepare("UPDATE groups SET name = ? WHERE id = ?").run(t,e)},getMembers:e=>eu.prepare(`
|
|
1408
1640
|
SELECT b.* FROM bots b
|
|
1409
1641
|
JOIN group_members gm ON b.id = gm.bot_id
|
|
1410
1642
|
WHERE gm.group_id = ?
|
|
1411
|
-
`).all(e)},"launchSnapshots",0,{record:(e,t,n,r
|
|
1643
|
+
`).all(e)},"launchSnapshots",0,{record:(e,t,n,i,r="hermes-gateway")=>{eu.prepare("INSERT OR IGNORE INTO launch_snapshots (id, bot_id, created_at, hash, snapshot, transport) VALUES (?, ?, ?, ?, ?, ?)").run(e,t,Date.now(),n,i,r)},listByBot:e=>eu.prepare("SELECT * FROM launch_snapshots WHERE bot_id = ? ORDER BY created_at DESC, rowid DESC").all(e)},"mcpServers",0,{create:(e,t,n)=>{let i={id:(0,a.randomUUID)(),name:e,command:t,args:JSON.stringify(n),created_at:Date.now()};return eu.prepare("INSERT INTO mcp_servers (id, name, command, args, created_at) VALUES (?, ?, ?, ?, ?)").run(i.id,i.name,i.command,i.args,i.created_at),i},list:()=>eu.prepare("SELECT * FROM mcp_servers ORDER BY created_at ASC").all()},"memories",0,{rememberStatement:(e,t)=>{var n;let i;if(!e||!(i=t.trim())||/[??]\s*$/.test(i)||/^\[mcp\]/i.test(i)||/^\[tool (?:call|result)\]/i.test(i)||/^\[Handing off to\b/i.test(i)||/^\[From [^\]]+\]/i.test(i)||/^Peer handoff:/i.test(i)||/reply with exactly\b/i.test(i)||(n=i,/^(who|what|when|where|why|how|which|whose|whom)\b/i.test(n)?!/^(what|how|why|where|when|who)\s+i\b/i.test(n):!!(/^(do|does|did|can|could|would|will|should|shall|is|are|am|was|were|have|has)\s+(you|i|we|they|he|she|it|there|the|a|an|my|your|our)\b/i.test(n)||/^(tell me|please tell)\b/i.test(n))))return;let r=t.trim();eu.prepare("INSERT INTO memories (id, bot_id, fact, created_at) VALUES (?, ?, ?, ?)").run((0,a.randomUUID)(),e,r,Date.now()),eu.prepare(`
|
|
1412
1644
|
DELETE FROM memories
|
|
1413
1645
|
WHERE bot_id = ?
|
|
1414
1646
|
AND id NOT IN (
|
|
@@ -1419,6 +1651,6 @@ module.exports=[85148,(e,t,n)=>{t.exports=e.x("better-sqlite3-90e2652d1716b047",
|
|
|
1419
1651
|
LIMIT ?
|
|
1420
1652
|
)
|
|
1421
1653
|
)
|
|
1422
|
-
`).run(e,e,
|
|
1654
|
+
`).run(e,e,eX)},latestFacts:(e,t=eX)=>{let n=t>0?Math.min(t,eX):eX;return eu.prepare("SELECT fact FROM memories WHERE bot_id = ? ORDER BY created_at DESC, rowid DESC LIMIT ?").all(e,n).map(e=>e.fact).reverse()}},"messages",0,eW,"oneShots",0,{create:(e,t,n)=>{let i={id:(0,a.randomUUID)(),conversation_id:e,bot_id:t,due_at:n,fired:0,created_at:Date.now()};return eu.prepare("INSERT INTO one_shots (id, conversation_id, bot_id, due_at, fired, created_at) VALUES (?, ?, ?, ?, 0, ?)").run(i.id,i.conversation_id,i.bot_id,i.due_at,i.created_at),i},pending:e=>eu.prepare("SELECT * FROM one_shots WHERE conversation_id = ? AND fired = 0 ORDER BY due_at ASC LIMIT 1").get(e),unfired:()=>eu.prepare("SELECT * FROM one_shots WHERE fired = 0 ORDER BY due_at ASC").all(),claim:e=>1===eu.prepare("UPDATE one_shots SET fired = 1 WHERE id = ? AND fired = 0").run(e).changes},"projector",0,ev,"resolveWakeTarget",0,eG,"routines",0,{create:(e,t,n,i,r)=>{let s={id:(0,a.randomUUID)(),conversation_id:e,bot_id:t,word:n,next_due_at:i,every_ms:r,created_at:Date.now()};return eu.prepare("INSERT INTO routines (id, conversation_id, bot_id, word, next_due_at, every_ms, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)").run(s.id,s.conversation_id,s.bot_id,s.word,s.next_due_at,s.every_ms,s.created_at),s},forConversation:e=>eu.prepare("SELECT * FROM routines WHERE conversation_id = ? ORDER BY created_at ASC LIMIT 1").get(e),all:()=>eu.prepare("SELECT * FROM routines ORDER BY next_due_at ASC").all(),postIfDue:(e,t)=>eu.transaction(()=>{let n=eu.prepare("SELECT * FROM routines WHERE id = ?").get(e);return!!n&&!(n.next_due_at>t)&&1===eu.prepare("UPDATE routines SET next_due_at = next_due_at + every_ms WHERE id = ? AND next_due_at = ?").run(e,n.next_due_at).changes&&(eW.create(n.conversation_id,"bot","[routine]\n"+n.word,n.bot_id),!0)})()},"serviceAudit",0,ek,"wakeTargets",0,{accept:e=>{let t=eG(e.requestedTarget);if(!t.ok)return t;let n={id:(0,a.randomUUID)(),conversation_id:e.conversationId,source_bot_id:e.sourceBotId??null,source_message_id:e.sourceMessageId??null,requested_target:e.requestedTarget,target_bot_id:t.agentId,target_name_snapshot:t.displayName,created_at:Date.now()};return eu.prepare("INSERT INTO wake_targets (id, conversation_id, source_bot_id, source_message_id, requested_target, target_bot_id, target_name_snapshot, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(n.id,n.conversation_id,n.source_bot_id,n.source_message_id,n.requested_target,n.target_bot_id,n.target_name_snapshot,n.created_at),{ok:!0,wake:n}},listByConversation:e=>eu.prepare("SELECT * FROM wake_targets WHERE conversation_id = ? ORDER BY created_at ASC, rowid ASC").all(e)},"workspaceSettings",0,{get:e=>{let t=eu.prepare("SELECT value FROM workspace_settings WHERE key = ?").get(e);return t?t.value:null},set:(e,t)=>{eu.prepare("INSERT INTO workspace_settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at").run(e,t,Date.now())},clearForTests:()=>{eu.prepare("DELETE FROM workspace_settings").run()}}],62294)}];
|
|
1423
1655
|
|
|
1424
1656
|
//# sourceMappingURL=%5Broot-of-the-server%5D__0izjfmr._.js.map
|