@agent-native/core 0.115.4 → 0.117.0
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/agent-native.eject.json +1 -0
- package/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +43 -0
- package/corpus/core/agent-native.eject.json +1 -0
- package/corpus/core/docs/AGENTS.md +1 -1
- package/corpus/core/docs/content/agent-mentions.mdx +2 -2
- package/corpus/core/docs/content/{workspace.mdx → agent-resources.mdx} +1 -7
- package/corpus/core/docs/content/agent-teams.mdx +4 -4
- package/corpus/core/docs/content/dispatch.mdx +10 -10
- package/corpus/core/docs/content/drop-in-agent.mdx +4 -4
- package/corpus/core/docs/content/external-agents.mdx +1 -1
- package/corpus/core/docs/content/frames.mdx +1 -1
- package/corpus/core/docs/content/integrations.mdx +13 -2
- package/corpus/core/docs/content/key-concepts.mdx +2 -2
- package/corpus/core/docs/content/mcp-clients.mdx +7 -1
- package/corpus/core/docs/content/multi-app-workspace.mdx +3 -3
- package/corpus/core/docs/content/real-time-collaboration.mdx +33 -15
- package/corpus/core/docs/content/recurring-jobs.mdx +7 -7
- package/corpus/core/docs/content/skills-guide.mdx +4 -4
- package/corpus/core/docs/content/template-brain.mdx +1 -1
- package/corpus/core/docs/content/toolkit-collaboration.mdx +1 -1
- package/corpus/core/docs/content/using-your-agent.mdx +1 -1
- package/corpus/core/docs/content/what-is-agent-native.mdx +4 -4
- package/corpus/core/docs/content/workspace-management.mdx +4 -4
- package/corpus/core/package.json +4 -1
- package/corpus/core/src/agent/production-agent.ts +13 -3
- package/corpus/core/src/cli/doctor.ts +6 -1
- package/corpus/core/src/client/AgentPanel.tsx +79 -41
- package/corpus/core/src/client/AssistantChat.tsx +71 -25
- package/corpus/core/src/client/FeedbackButton.tsx +33 -7
- package/corpus/core/src/client/MultiTabAssistantChat.tsx +6 -8
- package/corpus/core/src/client/agent-chat-adapter.ts +11 -2
- package/corpus/core/src/client/agent-page/AgentTabFrame.tsx +22 -3
- package/corpus/core/src/client/agent-page/AgentTabsPage.tsx +34 -19
- package/corpus/core/src/client/analytics.ts +7 -0
- package/corpus/core/src/client/chat/message-components.tsx +43 -16
- package/corpus/core/src/client/chat/tool-call-display.tsx +30 -18
- package/corpus/core/src/client/chat/tool-render-registry.tsx +2 -0
- package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +19 -2
- package/corpus/core/src/client/resources/ResourceTree.tsx +7 -10
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +33 -70
- package/corpus/core/src/client/resources/mcp-connection-resume.ts +107 -0
- package/corpus/core/src/client/resources/mcp-integration-catalog.ts +65 -12
- package/corpus/core/src/client/resources/mcp-integration-logos.ts +4 -0
- package/corpus/core/src/client/sse-event-processor.ts +50 -14
- package/corpus/core/src/client/use-db-sync.ts +370 -21
- package/corpus/core/src/collab/client.ts +26 -2
- package/corpus/core/src/connections/catalog.ts +7 -1
- package/corpus/core/src/db/ddl-guard.ts +49 -10
- package/corpus/core/src/deploy/build.ts +25 -2
- package/corpus/core/src/eject/remote-mcp-presets.ts +37 -5
- package/corpus/core/src/guards/explicit-collab-access.ts +229 -0
- package/corpus/core/src/guards/index.ts +1 -0
- package/corpus/core/src/localization/default-messages.ts +54 -5
- package/corpus/core/src/mcp/connect-route.ts +34 -51
- package/corpus/core/src/provider-api/index.ts +1 -1
- package/corpus/core/src/realtime-protocol.ts +92 -0
- package/corpus/core/src/server/collab-plugin.ts +137 -18
- package/corpus/core/src/server/core-routes-plugin.ts +7 -0
- package/corpus/core/src/server/index.ts +2 -0
- package/corpus/core/src/server/poll-events.ts +29 -8
- package/corpus/core/src/server/poll.ts +1123 -865
- package/corpus/core/src/server/realtime-token.ts +106 -0
- package/corpus/core/src/server/sentry-config.ts +40 -0
- package/corpus/core/src/server/short-lived-token.ts +156 -0
- package/corpus/core/src/server/sse.ts +15 -0
- package/corpus/core/src/server/ssr-handler.ts +9 -3
- package/corpus/core/src/styles/agent-native.css +40 -0
- package/corpus/core/src/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/core/src/templates/default/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/corpus/core/src/templates/default/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/core/src/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/corpus/core/src/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +12 -8
- package/corpus/templates/analytics/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/analytics/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/analytics/AGENTS.md +7 -2
- package/corpus/templates/analytics/actions/export-dashboard-panel-to-google-sheet.ts +144 -0
- package/corpus/templates/analytics/app/components/layout/Layout.tsx +7 -88
- package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +34 -37
- package/corpus/templates/analytics/app/global.css +0 -4
- package/corpus/templates/analytics/app/hooks/use-navigation-state.ts +2 -7
- package/corpus/templates/analytics/app/i18n-data.ts +107 -0
- package/corpus/templates/analytics/app/lib/data-source-status.ts +9 -0
- package/corpus/templates/analytics/app/lib/sql-query.ts +1 -2
- package/corpus/templates/analytics/app/pages/Ask.tsx +2 -7
- package/corpus/templates/analytics/app/pages/DataSources.tsx +48 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/SqlChartCard.tsx +59 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +2 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/report-panel-window.ts +3 -1
- package/corpus/templates/analytics/changelog/2026-07-22-clear-background-chat-progress.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-22-daily-dashboard-email-query-batches.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-22-export-table-panels-directly-to-google-sheets.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-22-recent-chats-can-expand-in-the-sidebar.md +6 -0
- package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +8 -8
- package/corpus/templates/analytics/server/lib/canonical-first-party-dashboard-repair.ts +31 -0
- package/corpus/templates/analytics/server/lib/dashboard-report-subscriptions.ts +3 -5
- package/corpus/templates/analytics/server/lib/dashboard-report.ts +12 -0
- package/corpus/templates/analytics/server/lib/first-party-dashboard-repair.ts +3 -5
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +150 -21
- package/corpus/templates/analytics/server/lib/google-sheets-export.ts +188 -0
- package/corpus/templates/analytics/server/lib/provider-api.ts +7 -2
- package/corpus/templates/analytics/server/plugins/collab.ts +6 -3
- package/corpus/templates/analytics/shared/sql-query-limits.ts +1 -0
- package/corpus/templates/assets/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/assets/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/corpus/templates/assets/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/assets/app/components/layout/Layout.tsx +1 -1
- package/corpus/templates/assets/app/components/layout/Sidebar.tsx +54 -62
- package/corpus/templates/assets/app/hooks/use-navigation-state.ts +2 -6
- package/corpus/templates/assets/app/routes/_index.tsx +8 -5
- package/corpus/templates/assets/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/assets/changelog/2026-07-22-recent-chats-expand-from-a-compact-list.md +6 -0
- package/corpus/templates/brain/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/brain/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/brain/actions/rotate-source-ingest-token.ts +77 -0
- package/corpus/templates/brain/app/components/layout/Layout.tsx +5 -1
- package/corpus/templates/brain/app/components/layout/Sidebar.tsx +38 -51
- package/corpus/templates/brain/app/hooks/use-navigation-state.ts +2 -9
- package/corpus/templates/brain/app/i18n-data.ts +120 -0
- package/corpus/templates/brain/app/routes/sources.tsx +156 -5
- package/corpus/templates/brain/changelog/2026-07-22-chat-runs-always-end-with-an-answer.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-22-clear-background-chat-progress.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-22-long-chat-titles-stay-inside-the-sidebar.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-22-new-clips-and-webhook-sources-now-show-their-secure-connecti.md +6 -0
- package/corpus/templates/brain/jobs/emit-netlify-brain-queue-cron.ts +125 -0
- package/corpus/templates/brain/netlify.toml +5 -1
- package/corpus/templates/brain/scripts/configure-prod-clips-source.ts +50 -0
- package/corpus/templates/brain/server/lib/capture-sanitization.ts +64 -6
- package/corpus/templates/brain/server/plugins/agent-chat.ts +4 -0
- package/corpus/templates/brain/server/plugins/brain-jobs.ts +1 -0
- package/corpus/templates/brain/server/routes/api/brain/queue/run.post.ts +55 -0
- package/corpus/templates/calendar/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/calendar/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/chat/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/chat/app/components/layout/Layout.tsx +1 -0
- package/corpus/templates/chat/app/components/layout/Sidebar.tsx +43 -67
- package/corpus/templates/chat/app/hooks/use-navigation-state.ts +2 -7
- package/corpus/templates/chat/app/routes/_index.tsx +8 -5
- package/corpus/templates/chat/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/corpus/templates/chat/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/chat/changelog/2026-07-22-recent-chats-are-easier-to-scan-and-expand.md +6 -0
- package/corpus/templates/clips/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/clips/AGENTS.md +9 -1
- package/corpus/templates/clips/actions/export-to-brain.ts +82 -6
- package/corpus/templates/clips/actions/request-transcript.ts +25 -14
- package/corpus/templates/clips/app/components/sharing/share-ui.tsx +12 -0
- package/corpus/templates/clips/app/i18n/en-US.ts +1 -0
- package/corpus/templates/clips/changelog/2026-07-22-clips-transcripts-now-retry-brain-export.md +5 -0
- package/corpus/templates/clips/changelog/2026-07-22-german-umlauts-and-other-non-ascii-characters-now-paste-corr.md +6 -0
- package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +26 -3
- package/corpus/templates/clips/jobs/emit-netlify-brain-export-cron.ts +118 -0
- package/corpus/templates/clips/netlify.toml +4 -1
- package/corpus/templates/clips/scripts/configure-prod-brain-export.ts +92 -0
- package/corpus/templates/clips/server/jobs/brain-export.ts +182 -0
- package/corpus/templates/clips/server/lib/brain-export-state.ts +42 -0
- package/corpus/templates/clips/server/lib/post-finalize-dispatch.ts +5 -1
- package/corpus/templates/clips/server/plugins/calendar-jobs.ts +2 -0
- package/corpus/templates/clips/server/register-secrets.ts +42 -0
- package/corpus/templates/clips/server/routes/api/_agent-native-background/post-finalize-worker.post.ts +10 -1
- package/corpus/templates/clips/server/routes/api/clips/brain-export/run.post.ts +45 -0
- package/corpus/templates/content/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/content/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +566 -299
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +14 -0
- package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +1 -1
- package/corpus/templates/content/app/i18n-data.ts +90 -0
- package/corpus/templates/content/server/plugins/collab.ts +1 -1
- package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/crm/actions/_crm-data-program-actions.ts +15 -0
- package/corpus/templates/crm/actions/get-crm-dashboard-panel.ts +2 -0
- package/corpus/templates/crm/actions/run.ts +2 -6
- package/corpus/templates/crm/actions/update-crm-record.ts +4 -2
- package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +6 -0
- package/corpus/templates/crm/changelog/2026-07-22-crm-field-validation-now-explains-which-fields-cannot-be-edi.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-22-fixed-hubspot-contact-syncs-missing-records-updated-after-th.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-22-fixed-pipeline-dashboard-panels-so-their-opportunity-data-lo.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/crm/server/crm/hubspot-adapter.ts +4 -1
- package/corpus/templates/design/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/design/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/design/server/plugins/collab.ts +11 -8
- package/corpus/templates/dispatch/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/forms/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/forms/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/forms/app/components/layout/Layout.tsx +1 -0
- package/corpus/templates/forms/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/forms/app/hooks/use-navigation-state.ts +2 -9
- package/corpus/templates/forms/app/root.tsx +1 -6
- package/corpus/templates/forms/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/macros/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/mail/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/mail/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/mail/app/components/layout/AppLayout.tsx +2 -2
- package/corpus/templates/plan/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/plan/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/plan/app/components/layout/Layout.tsx +5 -1
- package/corpus/templates/plan/app/components/layout/Sidebar.tsx +57 -72
- package/corpus/templates/plan/app/hooks/use-navigation-state.ts +2 -9
- package/corpus/templates/plan/app/lib/create-plan-routing.ts +2 -2
- package/corpus/templates/plan/app/pages/PlanChatPage.tsx +0 -1
- package/corpus/templates/plan/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/corpus/templates/plan/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/corpus/templates/plan/changelog/2026-07-22-recent-chats-and-sidebar-controls-are-more-compact.md +6 -0
- package/corpus/templates/plan/server/plugins/collab.ts +5 -2
- package/corpus/templates/slides/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/slides/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/slides/server/plugins/collab.ts +11 -8
- package/corpus/templates/tasks/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/corpus/templates/tasks/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/corpus/templates/tasks/app/components/layout/Sidebar.tsx +5 -22
- package/corpus/templates/tasks/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/corpus/toolkit/CHANGELOG.md +7 -0
- package/corpus/toolkit/README.md +12 -3
- package/corpus/toolkit/package.json +1 -1
- package/corpus/toolkit/src/chat-history/ChatHistoryRail.tsx +89 -0
- package/corpus/toolkit/src/chat-history/index.ts +5 -0
- package/corpus/toolkit/src/chat-history.css +59 -0
- package/corpus/toolkit/src/composer/RealtimeVoiceMode.tsx +106 -36
- package/corpus/toolkit/src/composer/VoiceButton.tsx +49 -0
- package/corpus/toolkit/src/composer/realtime-voice-audio-level.ts +2 -1
- package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +5 -3
- package/corpus/toolkit/src/styles.css +35 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +13 -3
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/cli/doctor.d.ts +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +5 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/client/AgentPanel.d.ts +1 -0
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +38 -18
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +55 -20
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/FeedbackButton.d.ts +4 -2
- package/dist/client/FeedbackButton.d.ts.map +1 -1
- package/dist/client/FeedbackButton.js +18 -2
- package/dist/client/FeedbackButton.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +2 -3
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +11 -3
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-page/AgentTabFrame.d.ts +3 -1
- package/dist/client/agent-page/AgentTabFrame.d.ts.map +1 -1
- package/dist/client/agent-page/AgentTabFrame.js +3 -2
- package/dist/client/agent-page/AgentTabFrame.js.map +1 -1
- package/dist/client/agent-page/AgentTabsPage.d.ts +2 -0
- package/dist/client/agent-page/AgentTabsPage.d.ts.map +1 -1
- package/dist/client/agent-page/AgentTabsPage.js +26 -15
- package/dist/client/agent-page/AgentTabsPage.js.map +1 -1
- package/dist/client/analytics.d.ts +10 -0
- package/dist/client/analytics.d.ts.map +1 -1
- package/dist/client/analytics.js.map +1 -1
- package/dist/client/chat/message-components.d.ts +6 -1
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +17 -11
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat/tool-call-display.d.ts +11 -1
- package/dist/client/chat/tool-call-display.d.ts.map +1 -1
- package/dist/client/chat/tool-call-display.js +16 -17
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/client/chat/tool-render-registry.d.ts +2 -0
- package/dist/client/chat/tool-render-registry.d.ts.map +1 -1
- package/dist/client/chat/tool-render-registry.js.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.js +15 -1
- package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
- package/dist/client/resources/ResourceTree.d.ts.map +1 -1
- package/dist/client/resources/ResourceTree.js +3 -3
- package/dist/client/resources/ResourceTree.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts +1 -0
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +34 -20
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/mcp-connection-resume.d.ts +11 -0
- package/dist/client/resources/mcp-connection-resume.d.ts.map +1 -0
- package/dist/client/resources/mcp-connection-resume.js +95 -0
- package/dist/client/resources/mcp-connection-resume.js.map +1 -0
- package/dist/client/resources/mcp-integration-catalog.d.ts +1 -0
- package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.js +63 -8
- package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
- package/dist/client/resources/mcp-integration-logos.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-logos.js +4 -0
- package/dist/client/resources/mcp-integration-logos.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +5 -0
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +39 -13
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/client/use-db-sync.d.ts +4 -3
- package/dist/client/use-db-sync.d.ts.map +1 -1
- package/dist/client/use-db-sync.js +332 -21
- package/dist/client/use-db-sync.js.map +1 -1
- package/dist/collab/client.d.ts.map +1 -1
- package/dist/collab/client.js +26 -2
- package/dist/collab/client.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +1 -1
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +7 -1
- package/dist/connections/catalog.js.map +1 -1
- package/dist/db/ddl-guard.d.ts +7 -2
- package/dist/db/ddl-guard.d.ts.map +1 -1
- package/dist/db/ddl-guard.js +21 -9
- package/dist/db/ddl-guard.js.map +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +25 -2
- package/dist/deploy/build.js.map +1 -1
- package/dist/eject/remote-mcp-presets.d.ts.map +1 -1
- package/dist/eject/remote-mcp-presets.js +33 -3
- package/dist/eject/remote-mcp-presets.js.map +1 -1
- package/dist/guards/explicit-collab-access.d.ts +8 -0
- package/dist/guards/explicit-collab-access.d.ts.map +1 -0
- package/dist/guards/explicit-collab-access.js +214 -0
- package/dist/guards/explicit-collab-access.js.map +1 -0
- package/dist/guards/index.d.ts +1 -0
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +1 -0
- package/dist/guards/index.js.map +1 -1
- package/dist/localization/default-messages.d.ts +43 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +48 -5
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/mcp/connect-route.d.ts.map +1 -1
- package/dist/mcp/connect-route.js +34 -48
- package/dist/mcp/connect-route.js.map +1 -1
- package/dist/observability/routes.d.ts +5 -5
- package/dist/provider-api/actions/custom-provider-registration.d.ts +7 -7
- package/dist/provider-api/actions/provider-api.d.ts +7 -7
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/provider-api/index.js +1 -1
- package/dist/provider-api/index.js.map +1 -1
- package/dist/realtime-protocol.d.ts +40 -0
- package/dist/realtime-protocol.d.ts.map +1 -0
- package/dist/realtime-protocol.js +69 -0
- package/dist/realtime-protocol.js.map +1 -0
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/secrets/routes.d.ts +3 -3
- package/dist/server/collab-plugin.d.ts +34 -3
- package/dist/server/collab-plugin.d.ts.map +1 -1
- package/dist/server/collab-plugin.js +65 -12
- package/dist/server/collab-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +3 -0
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/poll-events.d.ts +7 -1
- package/dist/server/poll-events.d.ts.map +1 -1
- package/dist/server/poll-events.js +24 -7
- package/dist/server/poll-events.js.map +1 -1
- package/dist/server/poll.d.ts +223 -42
- package/dist/server/poll.d.ts.map +1 -1
- package/dist/server/poll.js +849 -737
- package/dist/server/poll.js.map +1 -1
- package/dist/server/realtime-token.d.ts +34 -0
- package/dist/server/realtime-token.d.ts.map +1 -0
- package/dist/server/realtime-token.js +85 -0
- package/dist/server/realtime-token.js.map +1 -0
- package/dist/server/sentry-config.d.ts +12 -0
- package/dist/server/sentry-config.d.ts.map +1 -1
- package/dist/server/sentry-config.js +34 -0
- package/dist/server/sentry-config.js.map +1 -1
- package/dist/server/short-lived-token.d.ts +46 -0
- package/dist/server/short-lived-token.d.ts.map +1 -1
- package/dist/server/short-lived-token.js +104 -0
- package/dist/server/short-lived-token.js.map +1 -1
- package/dist/server/sse.d.ts +1 -1
- package/dist/server/sse.d.ts.map +1 -1
- package/dist/server/sse.js +4 -0
- package/dist/server/sse.js.map +1 -1
- package/dist/server/ssr-handler.d.ts.map +1 -1
- package/dist/server/ssr-handler.js +5 -3
- package/dist/server/ssr-handler.js.map +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/styles/agent-native.css +40 -0
- package/dist/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/dist/templates/chat/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/dist/templates/chat/app/components/layout/Layout.tsx +1 -0
- package/dist/templates/chat/app/components/layout/Sidebar.tsx +43 -67
- package/dist/templates/chat/app/hooks/use-navigation-state.ts +2 -7
- package/dist/templates/chat/app/routes/_index.tsx +8 -5
- package/dist/templates/chat/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/dist/templates/chat/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/dist/templates/chat/changelog/2026-07-22-recent-chats-are-easier-to-scan-and-expand.md +6 -0
- package/dist/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/dist/templates/default/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/dist/templates/default/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/dist/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/dist/templates/workspace-core/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/dist/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +12 -8
- package/docs/AGENTS.md +1 -1
- package/docs/content/agent-mentions.mdx +2 -2
- package/docs/content/{workspace.mdx → agent-resources.mdx} +1 -7
- package/docs/content/agent-teams.mdx +4 -4
- package/docs/content/dispatch.mdx +10 -10
- package/docs/content/drop-in-agent.mdx +4 -4
- package/docs/content/external-agents.mdx +1 -1
- package/docs/content/frames.mdx +1 -1
- package/docs/content/integrations.mdx +13 -2
- package/docs/content/key-concepts.mdx +2 -2
- package/docs/content/mcp-clients.mdx +7 -1
- package/docs/content/multi-app-workspace.mdx +3 -3
- package/docs/content/real-time-collaboration.mdx +33 -15
- package/docs/content/recurring-jobs.mdx +7 -7
- package/docs/content/skills-guide.mdx +4 -4
- package/docs/content/template-brain.mdx +1 -1
- package/docs/content/toolkit-collaboration.mdx +1 -1
- package/docs/content/using-your-agent.mdx +1 -1
- package/docs/content/what-is-agent-native.mdx +4 -4
- package/docs/content/workspace-management.mdx +4 -4
- package/package.json +6 -3
- package/src/agent/production-agent.ts +13 -3
- package/src/cli/doctor.ts +6 -1
- package/src/client/AgentPanel.tsx +79 -41
- package/src/client/AssistantChat.tsx +71 -25
- package/src/client/FeedbackButton.tsx +33 -7
- package/src/client/MultiTabAssistantChat.tsx +6 -8
- package/src/client/agent-chat-adapter.ts +11 -2
- package/src/client/agent-page/AgentTabFrame.tsx +22 -3
- package/src/client/agent-page/AgentTabsPage.tsx +34 -19
- package/src/client/analytics.ts +7 -0
- package/src/client/chat/message-components.tsx +43 -16
- package/src/client/chat/tool-call-display.tsx +30 -18
- package/src/client/chat/tool-render-registry.tsx +2 -0
- package/src/client/resources/McpConnectionSuggestion.tsx +19 -2
- package/src/client/resources/ResourceTree.tsx +7 -10
- package/src/client/resources/ResourcesPanel.tsx +33 -70
- package/src/client/resources/mcp-connection-resume.ts +107 -0
- package/src/client/resources/mcp-integration-catalog.ts +65 -12
- package/src/client/resources/mcp-integration-logos.ts +4 -0
- package/src/client/sse-event-processor.ts +50 -14
- package/src/client/use-db-sync.ts +370 -21
- package/src/collab/client.ts +26 -2
- package/src/connections/catalog.ts +7 -1
- package/src/db/ddl-guard.ts +49 -10
- package/src/deploy/build.ts +25 -2
- package/src/eject/remote-mcp-presets.ts +37 -5
- package/src/guards/explicit-collab-access.ts +229 -0
- package/src/guards/index.ts +1 -0
- package/src/localization/default-messages.ts +54 -5
- package/src/mcp/connect-route.ts +34 -51
- package/src/provider-api/index.ts +1 -1
- package/src/realtime-protocol.ts +92 -0
- package/src/server/collab-plugin.ts +137 -18
- package/src/server/core-routes-plugin.ts +7 -0
- package/src/server/index.ts +2 -0
- package/src/server/poll-events.ts +29 -8
- package/src/server/poll.ts +1123 -865
- package/src/server/realtime-token.ts +106 -0
- package/src/server/sentry-config.ts +40 -0
- package/src/server/short-lived-token.ts +156 -0
- package/src/server/sse.ts +15 -0
- package/src/server/ssr-handler.ts +9 -3
- package/src/styles/agent-native.css +40 -0
- package/src/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/src/templates/chat/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/src/templates/chat/app/components/layout/Layout.tsx +1 -0
- package/src/templates/chat/app/components/layout/Sidebar.tsx +43 -67
- package/src/templates/chat/app/hooks/use-navigation-state.ts +2 -7
- package/src/templates/chat/app/routes/_index.tsx +8 -5
- package/src/templates/chat/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
- package/src/templates/chat/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
- package/src/templates/chat/changelog/2026-07-22-recent-chats-are-easier-to-scan-and-expand.md +6 -0
- package/src/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/src/templates/default/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/src/templates/default/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/src/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +4 -1
- package/src/templates/workspace-core/.agents/skills/real-time-collab/SKILL.md +35 -13
- package/src/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +1 -1
- package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +12 -8
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realtime SSE wire protocol — shared by the server SSE handlers (framework
|
|
3
|
+
* in-process path + the hosted Realtime Gateway) and the client transport.
|
|
4
|
+
*
|
|
5
|
+
* Pure constants, types, and parsers only — NO h3/node/browser deps — so both
|
|
6
|
+
* the Node server and the browser client import it.
|
|
7
|
+
*
|
|
8
|
+
* Frame taxonomy:
|
|
9
|
+
* - CHANGE / batch frames ride the default (unnamed) SSE `message` event and
|
|
10
|
+
* are parsed by the client's existing `normalizeEventPayload`. Unchanged.
|
|
11
|
+
* - CONTROL frames (handshake, token rotation) ride NAMED SSE events, so
|
|
12
|
+
* `EventSource.addEventListener(name)` routes them separately and an older
|
|
13
|
+
* client that only reads `onmessage` silently ignores them (backward safe).
|
|
14
|
+
*/
|
|
15
|
+
export declare const REALTIME_PROTOCOL_VERSION = 1;
|
|
16
|
+
/** Named SSE event carrying the one-time handshake ({@link RealtimeHandshake}). */
|
|
17
|
+
export declare const REALTIME_SSE_HANDSHAKE_EVENT = "handshake";
|
|
18
|
+
/** Named SSE event carrying a rotated subscribe token ({@link RealtimeTokenFrame}). */
|
|
19
|
+
export declare const REALTIME_SSE_TOKEN_EVENT = "token";
|
|
20
|
+
/**
|
|
21
|
+
* Capability advertised by the hosted gateway: awareness/presence is NOT
|
|
22
|
+
* forwarded (it lives only on the in-process emitter, never in `sync_events`),
|
|
23
|
+
* so the collab client must keep its own presence cadence. The framework's
|
|
24
|
+
* in-process SSE path forwards awareness and therefore sends no handshake — the
|
|
25
|
+
* client treats an absent handshake as "all capabilities present."
|
|
26
|
+
*/
|
|
27
|
+
export declare const REALTIME_CAP_NO_AWARENESS = "no-awareness";
|
|
28
|
+
export interface RealtimeHandshake {
|
|
29
|
+
protocol: number;
|
|
30
|
+
capabilities: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface RealtimeTokenFrame {
|
|
33
|
+
token: string;
|
|
34
|
+
/** ISO expiry, informational; the client re-mints/rotates before this. */
|
|
35
|
+
expiresAt?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function buildHandshakeFrame(capabilities?: readonly string[]): RealtimeHandshake;
|
|
38
|
+
export declare function parseHandshakeFrame(data: string): RealtimeHandshake | null;
|
|
39
|
+
export declare function parseTokenFrame(data: string): RealtimeTokenFrame | null;
|
|
40
|
+
//# sourceMappingURL=realtime-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-protocol.d.ts","sourceRoot":"","sources":["../src/realtime-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,mFAAmF;AACnF,eAAO,MAAM,4BAA4B,cAAc,CAAC;AACxD,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CACjC,YAAY,GAAE,SAAS,MAAM,EAAO,GACnC,iBAAiB,CAKnB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAoB1E;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAkBvE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realtime SSE wire protocol — shared by the server SSE handlers (framework
|
|
3
|
+
* in-process path + the hosted Realtime Gateway) and the client transport.
|
|
4
|
+
*
|
|
5
|
+
* Pure constants, types, and parsers only — NO h3/node/browser deps — so both
|
|
6
|
+
* the Node server and the browser client import it.
|
|
7
|
+
*
|
|
8
|
+
* Frame taxonomy:
|
|
9
|
+
* - CHANGE / batch frames ride the default (unnamed) SSE `message` event and
|
|
10
|
+
* are parsed by the client's existing `normalizeEventPayload`. Unchanged.
|
|
11
|
+
* - CONTROL frames (handshake, token rotation) ride NAMED SSE events, so
|
|
12
|
+
* `EventSource.addEventListener(name)` routes them separately and an older
|
|
13
|
+
* client that only reads `onmessage` silently ignores them (backward safe).
|
|
14
|
+
*/
|
|
15
|
+
export const REALTIME_PROTOCOL_VERSION = 1;
|
|
16
|
+
/** Named SSE event carrying the one-time handshake ({@link RealtimeHandshake}). */
|
|
17
|
+
export const REALTIME_SSE_HANDSHAKE_EVENT = "handshake";
|
|
18
|
+
/** Named SSE event carrying a rotated subscribe token ({@link RealtimeTokenFrame}). */
|
|
19
|
+
export const REALTIME_SSE_TOKEN_EVENT = "token";
|
|
20
|
+
/**
|
|
21
|
+
* Capability advertised by the hosted gateway: awareness/presence is NOT
|
|
22
|
+
* forwarded (it lives only on the in-process emitter, never in `sync_events`),
|
|
23
|
+
* so the collab client must keep its own presence cadence. The framework's
|
|
24
|
+
* in-process SSE path forwards awareness and therefore sends no handshake — the
|
|
25
|
+
* client treats an absent handshake as "all capabilities present."
|
|
26
|
+
*/
|
|
27
|
+
export const REALTIME_CAP_NO_AWARENESS = "no-awareness";
|
|
28
|
+
export function buildHandshakeFrame(capabilities = []) {
|
|
29
|
+
return {
|
|
30
|
+
protocol: REALTIME_PROTOCOL_VERSION,
|
|
31
|
+
capabilities: [...capabilities],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function parseHandshakeFrame(data) {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(data);
|
|
37
|
+
if (parsed &&
|
|
38
|
+
typeof parsed === "object" &&
|
|
39
|
+
typeof parsed.protocol === "number" &&
|
|
40
|
+
Array.isArray(parsed.capabilities)) {
|
|
41
|
+
return {
|
|
42
|
+
protocol: parsed.protocol,
|
|
43
|
+
capabilities: parsed.capabilities.filter((c) => typeof c === "string"),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// fall through
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
export function parseTokenFrame(data) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(data);
|
|
55
|
+
if (parsed &&
|
|
56
|
+
typeof parsed === "object" &&
|
|
57
|
+
typeof parsed.token === "string") {
|
|
58
|
+
return {
|
|
59
|
+
token: parsed.token,
|
|
60
|
+
expiresAt: typeof parsed.expiresAt === "string" ? parsed.expiresAt : undefined,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// fall through
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=realtime-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-protocol.js","sourceRoot":"","sources":["../src/realtime-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,mFAAmF;AACnF,MAAM,CAAC,MAAM,4BAA4B,GAAG,WAAW,CAAC;AACxD,uFAAuF;AACvF,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,cAAc,CAAC;AAaxD,MAAM,UAAU,mBAAmB,CACjC,YAAY,GAAsB,EAAE;IAEpC,OAAO;QACL,QAAQ,EAAE,yBAAyB;QACnC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;KAChC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,IACE,MAAM;YACN,OAAO,MAAM,KAAK,QAAQ;YAC1B,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ;YACnC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAClC,CAAC;YACD,OAAO;gBACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CACtC,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CACnD;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,IACE,MAAM;YACN,OAAO,MAAM,KAAK,QAAQ;YAC1B,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAChC,CAAC;YACD,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,SAAS,EACP,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;aACtE,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * Realtime SSE wire protocol — shared by the server SSE handlers (framework\n * in-process path + the hosted Realtime Gateway) and the client transport.\n *\n * Pure constants, types, and parsers only — NO h3/node/browser deps — so both\n * the Node server and the browser client import it.\n *\n * Frame taxonomy:\n * - CHANGE / batch frames ride the default (unnamed) SSE `message` event and\n * are parsed by the client's existing `normalizeEventPayload`. Unchanged.\n * - CONTROL frames (handshake, token rotation) ride NAMED SSE events, so\n * `EventSource.addEventListener(name)` routes them separately and an older\n * client that only reads `onmessage` silently ignores them (backward safe).\n */\n\nexport const REALTIME_PROTOCOL_VERSION = 1;\n\n/** Named SSE event carrying the one-time handshake ({@link RealtimeHandshake}). */\nexport const REALTIME_SSE_HANDSHAKE_EVENT = \"handshake\";\n/** Named SSE event carrying a rotated subscribe token ({@link RealtimeTokenFrame}). */\nexport const REALTIME_SSE_TOKEN_EVENT = \"token\";\n\n/**\n * Capability advertised by the hosted gateway: awareness/presence is NOT\n * forwarded (it lives only on the in-process emitter, never in `sync_events`),\n * so the collab client must keep its own presence cadence. The framework's\n * in-process SSE path forwards awareness and therefore sends no handshake — the\n * client treats an absent handshake as \"all capabilities present.\"\n */\nexport const REALTIME_CAP_NO_AWARENESS = \"no-awareness\";\n\nexport interface RealtimeHandshake {\n protocol: number;\n capabilities: string[];\n}\n\nexport interface RealtimeTokenFrame {\n token: string;\n /** ISO expiry, informational; the client re-mints/rotates before this. */\n expiresAt?: string;\n}\n\nexport function buildHandshakeFrame(\n capabilities: readonly string[] = [],\n): RealtimeHandshake {\n return {\n protocol: REALTIME_PROTOCOL_VERSION,\n capabilities: [...capabilities],\n };\n}\n\nexport function parseHandshakeFrame(data: string): RealtimeHandshake | null {\n try {\n const parsed = JSON.parse(data);\n if (\n parsed &&\n typeof parsed === \"object\" &&\n typeof parsed.protocol === \"number\" &&\n Array.isArray(parsed.capabilities)\n ) {\n return {\n protocol: parsed.protocol,\n capabilities: parsed.capabilities.filter(\n (c: unknown): c is string => typeof c === \"string\",\n ),\n };\n }\n } catch {\n // fall through\n }\n return null;\n}\n\nexport function parseTokenFrame(data: string): RealtimeTokenFrame | null {\n try {\n const parsed = JSON.parse(data);\n if (\n parsed &&\n typeof parsed === \"object\" &&\n typeof parsed.token === \"string\"\n ) {\n return {\n token: parsed.token,\n expiresAt:\n typeof parsed.expiresAt === \"string\" ? parsed.expiresAt : undefined,\n };\n }\n } catch {\n // fall through\n }\n return null;\n}\n"]}
|
|
@@ -49,8 +49,8 @@ export declare function handleUpdateResource(event: any): Promise<import("./stor
|
|
|
49
49
|
}>;
|
|
50
50
|
/** DELETE /_agent-native/resources/:id — delete a resource */
|
|
51
51
|
export declare function handleDeleteResource(event: any): Promise<{
|
|
52
|
-
error: string;
|
|
53
52
|
ok?: undefined;
|
|
53
|
+
error: string;
|
|
54
54
|
} | {
|
|
55
55
|
error?: undefined;
|
|
56
56
|
ok: boolean;
|
package/dist/secrets/routes.d.ts
CHANGED
|
@@ -34,16 +34,16 @@ export declare function createListSecretsHandler(): import("h3").EventHandlerWit
|
|
|
34
34
|
/** POST /_agent-native/secrets/:key — write a secret. */
|
|
35
35
|
export declare function createWriteSecretHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
36
36
|
error: string;
|
|
37
|
-
status?: undefined;
|
|
38
37
|
ok?: undefined;
|
|
38
|
+
status?: undefined;
|
|
39
39
|
} | {
|
|
40
40
|
ok: boolean;
|
|
41
41
|
status: string;
|
|
42
42
|
error?: undefined;
|
|
43
43
|
} | {
|
|
44
|
+
ok?: undefined;
|
|
44
45
|
error: string;
|
|
45
46
|
removed?: undefined;
|
|
46
|
-
ok?: undefined;
|
|
47
47
|
} | {
|
|
48
48
|
ok: boolean;
|
|
49
49
|
removed: boolean;
|
|
@@ -54,9 +54,9 @@ export declare function createWriteSecretHandler(): import("h3").EventHandlerWit
|
|
|
54
54
|
* current stored value without changing anything. Useful for the "Test" button.
|
|
55
55
|
*/
|
|
56
56
|
export declare function createTestSecretHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
57
|
+
ok?: undefined;
|
|
57
58
|
error: string;
|
|
58
59
|
note?: undefined;
|
|
59
|
-
ok?: undefined;
|
|
60
60
|
} | {
|
|
61
61
|
ok: boolean;
|
|
62
62
|
note?: undefined;
|
|
@@ -5,10 +5,33 @@
|
|
|
5
5
|
* ```ts
|
|
6
6
|
* // server/plugins/collab.ts
|
|
7
7
|
* import { createCollabPlugin } from "@agent-native/core/server";
|
|
8
|
-
* export default createCollabPlugin({
|
|
8
|
+
* export default createCollabPlugin({
|
|
9
|
+
* table: "documents",
|
|
10
|
+
* contentColumn: "content",
|
|
11
|
+
* access: { mode: "resource", resourceType: "document" },
|
|
12
|
+
* });
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
11
15
|
type NitroPluginDef = (nitroApp: any) => void | Promise<void>;
|
|
16
|
+
export type CollabResourceIdResolver = (docId: string) => string | null | Promise<string | null>;
|
|
17
|
+
export type CollabAccess = {
|
|
18
|
+
mode: "resource";
|
|
19
|
+
/** The shareable resource type registered via `registerShareableResource`. */
|
|
20
|
+
resourceType: string;
|
|
21
|
+
/** Map a collab document id to its parent shareable resource id. */
|
|
22
|
+
resolveResourceId?: CollabResourceIdResolver;
|
|
23
|
+
} | {
|
|
24
|
+
/** Deliver collaboration events to every authenticated user. */
|
|
25
|
+
mode: "all-authenticated";
|
|
26
|
+
};
|
|
27
|
+
type NormalizedCollabAccess = {
|
|
28
|
+
mode: "resource";
|
|
29
|
+
resourceType: string;
|
|
30
|
+
resolveResourceId?: CollabResourceIdResolver;
|
|
31
|
+
} | {
|
|
32
|
+
mode: "all-authenticated";
|
|
33
|
+
explicit: boolean;
|
|
34
|
+
};
|
|
12
35
|
export interface CollabPluginOptions {
|
|
13
36
|
/** Table name containing document content. Default: "documents" */
|
|
14
37
|
table?: string;
|
|
@@ -27,18 +50,25 @@ export interface CollabPluginOptions {
|
|
|
27
50
|
contentType?: "text" | "json";
|
|
28
51
|
/** Column name for JSON content (used when contentType is "json"). */
|
|
29
52
|
jsonColumn?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Access policy for collaboration routes and event delivery.
|
|
55
|
+
* Use `resource` for registered shareable resources, or explicitly choose
|
|
56
|
+
* `all-authenticated` for deployment-wide collaboration.
|
|
57
|
+
*/
|
|
58
|
+
access?: CollabAccess;
|
|
30
59
|
/**
|
|
31
60
|
* The shareable resource type registered via `registerShareableResource`.
|
|
32
61
|
* Used to enforce access checks on collab routes.
|
|
33
|
-
*
|
|
62
|
+
* @deprecated Use `access: { mode: "resource", resourceType }`.
|
|
34
63
|
*/
|
|
35
64
|
resourceType?: string;
|
|
36
65
|
/**
|
|
37
66
|
* Map the collab document id to the shareable resource id. Many templates
|
|
38
67
|
* use route-specific collab ids (for example, one doc per slide inside a
|
|
39
68
|
* deck) while sharing is enforced at the parent resource level.
|
|
69
|
+
* @deprecated Use `access: { mode: "resource", resourceType, resolveResourceId }`.
|
|
40
70
|
*/
|
|
41
|
-
resolveResourceId?:
|
|
71
|
+
resolveResourceId?: CollabResourceIdResolver;
|
|
42
72
|
/**
|
|
43
73
|
* Maximum allowed body size in bytes for write operations
|
|
44
74
|
* (update/text/json/patch). Requests exceeding this are rejected with 413.
|
|
@@ -46,6 +76,7 @@ export interface CollabPluginOptions {
|
|
|
46
76
|
*/
|
|
47
77
|
maxPayloadBytes?: number;
|
|
48
78
|
}
|
|
79
|
+
export declare function normalizeCollabAccess(options: Pick<CollabPluginOptions, "access" | "resourceType" | "resolveResourceId">): NormalizedCollabAccess;
|
|
49
80
|
export declare function createCollabPlugin(options?: CollabPluginOptions): NitroPluginDef;
|
|
50
81
|
export {};
|
|
51
82
|
//# sourceMappingURL=collab-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collab-plugin.d.ts","sourceRoot":"","sources":["../../src/server/collab-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"collab-plugin.d.ts","sourceRoot":"","sources":["../../src/server/collab-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiCH,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAY9D,MAAM,MAAM,wBAAwB,GAAG,CACrC,KAAK,EAAE,MAAM,KACV,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE5C,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;CAC9C,GACD;IACE,gEAAgE;IAChE,IAAI,EAAE,mBAAmB,CAAC;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8
|
-
* export default createCollabPlugin({
|
|
8
|
+
* export default createCollabPlugin({
|
|
9
|
+
* table: "documents",
|
|
10
|
+
* contentColumn: "content",
|
|
11
|
+
* access: { mode: "resource", resourceType: "document" },
|
|
12
|
+
* });
|
|
9
13
|
* ```
|
|
10
14
|
*/
|
|
11
15
|
import { defineEventHandler, getMethod, setResponseStatus, } from "h3";
|
|
@@ -26,13 +30,68 @@ import { runWithRequestContext } from "./request-context.js";
|
|
|
26
30
|
/** Default maximum body size in bytes for collab write operations (2 MB). */
|
|
27
31
|
const DEFAULT_MAX_PAYLOAD_BYTES = 2 * 1024 * 1024;
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
* process. Avoids
|
|
31
|
-
*
|
|
33
|
+
* Tables whose implicit all-authenticated warning has already been logged in
|
|
34
|
+
* this process. Avoids duplicate warnings during hot reloads while still
|
|
35
|
+
* identifying every affected table.
|
|
32
36
|
*/
|
|
33
|
-
|
|
37
|
+
const COLLAB_WARNING_TABLES_KEY = "__agentNativeImplicitCollabAccessWarningTables__";
|
|
38
|
+
const collabWarningGlobal = globalThis;
|
|
39
|
+
const _unscoped_warning_tables = (collabWarningGlobal[COLLAB_WARNING_TABLES_KEY] ??= new Set());
|
|
40
|
+
export function normalizeCollabAccess(options) {
|
|
41
|
+
const hasLegacyAccess = options.resourceType !== undefined ||
|
|
42
|
+
options.resolveResourceId !== undefined;
|
|
43
|
+
if (options.access && hasLegacyAccess) {
|
|
44
|
+
throw new Error('createCollabPlugin cannot combine "access" with the deprecated root "resourceType" or "resolveResourceId" options. Move those fields into access.');
|
|
45
|
+
}
|
|
46
|
+
if (options.access?.mode === "resource") {
|
|
47
|
+
if (!options.access.resourceType.trim()) {
|
|
48
|
+
throw new Error('createCollabPlugin access mode "resource" requires a non-empty resourceType.');
|
|
49
|
+
}
|
|
50
|
+
return options.access;
|
|
51
|
+
}
|
|
52
|
+
if (options.access?.mode === "all-authenticated") {
|
|
53
|
+
return { mode: "all-authenticated", explicit: true };
|
|
54
|
+
}
|
|
55
|
+
if (options.access) {
|
|
56
|
+
throw new Error(`createCollabPlugin received an unsupported access mode: ${String(options.access.mode)}`);
|
|
57
|
+
}
|
|
58
|
+
if (options.resourceType !== undefined) {
|
|
59
|
+
if (!options.resourceType.trim()) {
|
|
60
|
+
throw new Error('createCollabPlugin "resourceType" must be a non-empty string when provided.');
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
mode: "resource",
|
|
64
|
+
resourceType: options.resourceType,
|
|
65
|
+
resolveResourceId: options.resolveResourceId,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (options.resolveResourceId !== undefined) {
|
|
69
|
+
throw new Error('createCollabPlugin "resolveResourceId" requires a non-empty "resourceType".');
|
|
70
|
+
}
|
|
71
|
+
return { mode: "all-authenticated", explicit: false };
|
|
72
|
+
}
|
|
73
|
+
function warnForImplicitAllAuthenticatedAccess(table) {
|
|
74
|
+
if (_unscoped_warning_tables.has(table))
|
|
75
|
+
return;
|
|
76
|
+
_unscoped_warning_tables.add(table);
|
|
77
|
+
console.warn(`[collab] WARNING: createCollabPlugin for table "${table}" does not declare an access policy. ` +
|
|
78
|
+
"Collab events will be delivered to ALL authenticated users on this deployment without document-level access scoping. " +
|
|
79
|
+
'Use access: { mode: "resource", resourceType: "..." } for access-scoped delivery, ' +
|
|
80
|
+
'or access: { mode: "all-authenticated" } to explicitly acknowledge deployment-wide delivery.');
|
|
81
|
+
}
|
|
34
82
|
export function createCollabPlugin(options = {}) {
|
|
35
|
-
const
|
|
83
|
+
const normalizedAccess = normalizeCollabAccess(options);
|
|
84
|
+
const { table = "documents", contentColumn = "content", idColumn = "id", autoSeed = true, maxPayloadBytes = DEFAULT_MAX_PAYLOAD_BYTES, } = options;
|
|
85
|
+
const resourceType = normalizedAccess.mode === "resource"
|
|
86
|
+
? normalizedAccess.resourceType
|
|
87
|
+
: undefined;
|
|
88
|
+
const resolveResourceId = normalizedAccess.mode === "resource"
|
|
89
|
+
? normalizedAccess.resolveResourceId
|
|
90
|
+
: undefined;
|
|
91
|
+
if (normalizedAccess.mode === "all-authenticated" &&
|
|
92
|
+
!normalizedAccess.explicit) {
|
|
93
|
+
warnForImplicitAllAuthenticatedAccess(table);
|
|
94
|
+
}
|
|
36
95
|
return async (nitroApp) => {
|
|
37
96
|
await awaitBootstrap(nitroApp);
|
|
38
97
|
const P = FRAMEWORK_ROUTE_PREFIX;
|
|
@@ -51,12 +110,6 @@ export function createCollabPlugin(options = {}) {
|
|
|
51
110
|
// who don't match owner/org — instead of only degrading them to the
|
|
52
111
|
// poll fallback.
|
|
53
112
|
// See also: SECURITY comment in poll.ts on canSeeChangeForUser.
|
|
54
|
-
if (!resourceType && !_unscoped_warning_logged) {
|
|
55
|
-
_unscoped_warning_logged = true;
|
|
56
|
-
console.warn("[collab] WARNING: createCollabPlugin called without resourceType. " +
|
|
57
|
-
"Collab events will be delivered to ALL authenticated users on this deployment " +
|
|
58
|
-
"without document-level access scoping. Set resourceType to enable access-scoped delivery.");
|
|
59
|
-
}
|
|
60
113
|
const collabEmitter = getCollabEmitter();
|
|
61
114
|
collabEmitter.on("collab", async (event) => {
|
|
62
115
|
if (!resourceType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collab-plugin.js","sourceRoot":"","sources":["../../src/server/collab-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,iBAAiB,GAElB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,aAAa,EAC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BAAsB;4BACxB,CAAC;wBACH,CAAC;6BAAM,CAAC;4BACN,MAAM,OAAO,GAAI,GAAG,CAAC,UAAU,CAAY,IAAI,EAAE,CAAC;4BAClD,MAAM,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;wBACrC,CAAC;oBACH,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,sDAAsD;gBACxD,CAAC;YACH,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Nitro plugin that mounts collaborative editing routes.\n *\n * Templates opt in with one line:\n * ```ts\n * // server/plugins/collab.ts\n * import { createCollabPlugin } from \"@agent-native/core/server\";\n * export default createCollabPlugin({ table: \"documents\", contentColumn: \"content\" });\n * ```\n */\n\nimport {\n defineEventHandler,\n getMethod,\n setResponseStatus,\n type H3Event,\n} from \"h3\";\n\nimport { postAwareness, getActiveUsers } from \"../collab/awareness.js\";\nimport { getCollabEmitter } from \"../collab/emitter.js\";\nimport {\n getCollabState,\n postCollabUpdate,\n postCollabText,\n postCollabSearchReplace,\n} from \"../collab/routes.js\";\nimport { hasCollabState } from \"../collab/storage.js\";\nimport {\n postCollabJson,\n getCollabJson,\n postCollabPatch,\n} from \"../collab/struct-routes.js\";\nimport { seedFromText, seedFromJson } from \"../collab/ydoc-manager.js\";\nimport { getDbExec } from \"../db/client.js\";\nimport { getOrgContext } from \"../org/context.js\";\nimport { resolveAccess, assertAccess } from \"../sharing/access.js\";\nimport { getSession } from \"./auth.js\";\nimport { FRAMEWORK_ROUTE_PREFIX } from \"./core-routes-plugin.js\";\nimport { getH3App, awaitBootstrap } from \"./framework-request-handler.js\";\nimport { recordChange } from \"./poll.js\";\nimport { runWithRequestContext } from \"./request-context.js\";\n\ntype NitroPluginDef = (nitroApp: any) => void | Promise<void>;\n\n/** Default maximum body size in bytes for collab write operations (2 MB). */\nconst DEFAULT_MAX_PAYLOAD_BYTES = 2 * 1024 * 1024;\n\ntype CollabAwarenessScope = {\n owner?: string;\n orgId?: string;\n resourceType?: string;\n resourceId?: string;\n};\n\n/**\n * Whether the no-resourceType warning has already been logged once per server\n * process. Avoids flooding logs on every request in templates that deliberately\n * have no sharing model.\n */\nlet _unscoped_warning_logged = false;\n\nexport interface CollabPluginOptions {\n /** Table name containing document content. Default: \"documents\" */\n table?: string;\n /** Column name for text content. Default: \"content\" */\n contentColumn?: string;\n /** Column name for the document ID. Default: \"id\" */\n idColumn?: string;\n /** Whether to auto-seed existing documents on startup. Default: true */\n autoSeed?: boolean;\n /**\n * Callback invoked after a collab update to sync the content column.\n * If not provided, the plugin auto-syncs using table/contentColumn/idColumn.\n */\n onContentSync?: (docId: string, text: string) => Promise<void>;\n /** Content type: \"text\" for Y.Text (default) or \"json\" for Y.Map/Y.Array. */\n contentType?: \"text\" | \"json\";\n /** Column name for JSON content (used when contentType is \"json\"). */\n jsonColumn?: string;\n /**\n * The shareable resource type registered via `registerShareableResource`.\n * Used to enforce access checks on collab routes.\n * Omit only for resources that are always public (no sharing model).\n */\n resourceType?: string;\n /**\n * Map the collab document id to the shareable resource id. Many templates\n * use route-specific collab ids (for example, one doc per slide inside a\n * deck) while sharing is enforced at the parent resource level.\n */\n resolveResourceId?: (docId: string) => string | null | Promise<string | null>;\n /**\n * Maximum allowed body size in bytes for write operations\n * (update/text/json/patch). Requests exceeding this are rejected with 413.\n * Default: 2097152 (2 MB).\n */\n maxPayloadBytes?: number;\n}\n\nexport function createCollabPlugin(\n options: CollabPluginOptions = {},\n): NitroPluginDef {\n const {\n table = \"documents\",\n contentColumn = \"content\",\n idColumn = \"id\",\n autoSeed = true,\n resourceType,\n resolveResourceId,\n maxPayloadBytes = DEFAULT_MAX_PAYLOAD_BYTES,\n } = options;\n\n return async (nitroApp: any) => {\n await awaitBootstrap(nitroApp);\n const P = FRAMEWORK_ROUTE_PREFIX;\n\n // Wire collab emitter → poll ring buffer so clients receive Yjs updates.\n // Security: when resourceType is configured, resolve the resource's\n // owner/org so getChangesSinceForUser can scope delivery. We use\n // resolveAccess to obtain the resource row — it already handles ownership,\n // visibility, and share rows. In addition to the owner/org tags we also\n // tag the event with `resourceType` + `resourceId` so the per-user\n // delivery filter (canSeeChangeForUser) can evaluate resource access\n // directly for non-owner sharees:\n // • tag the event with the resource owner's email and org (owner-scoped)\n // for backward compatibility with the conservative owner/org fast path.\n // • ALSO tag with resourceType/resourceId so canSeeChangeForUser can run\n // an access-aware (cached) check and push to explicit viewer+ sharees\n // who don't match owner/org — instead of only degrading them to the\n // poll fallback.\n // See also: SECURITY comment in poll.ts on canSeeChangeForUser.\n if (!resourceType && !_unscoped_warning_logged) {\n _unscoped_warning_logged = true;\n console.warn(\n \"[collab] WARNING: createCollabPlugin called without resourceType. \" +\n \"Collab events will be delivered to ALL authenticated users on this deployment \" +\n \"without document-level access scoping. Set resourceType to enable access-scoped delivery.\",\n );\n }\n\n const collabEmitter = getCollabEmitter();\n collabEmitter.on(\"collab\", async (event) => {\n if (!resourceType) {\n // No access model — broadcast to all authenticated users (no owner/orgId tag).\n recordChange(event);\n return;\n }\n\n // Resolve the resource to learn its owner/org so we can scope the event.\n const docId = event.docId as string | undefined;\n if (!docId) {\n recordChange(event);\n return;\n }\n\n try {\n const resourceId = resolveResourceId\n ? await resolveResourceId(docId)\n : docId;\n if (!resourceId) {\n // Cannot resolve resource — drop the event to avoid leaking to\n // unauthorized pollers. The client will catch up via state-vector.\n return;\n }\n\n // Load the resource row to get owner/org. resolveAccess fetches the\n // resource row internally; use getShareableResource to read it cheaply.\n const { requireShareableResource } =\n await import(\"../sharing/registry.js\");\n const reg = requireShareableResource(resourceType);\n const db = reg.getDb() as any;\n const { eq } = await import(\"drizzle-orm\");\n const [resource] = await db\n .select()\n .from(reg.resourceTable)\n .where(eq(reg.resourceTable.id, resourceId))\n .limit(1);\n\n if (!resource) {\n // Resource deleted — drop silently.\n return;\n }\n\n const ownerEmail =\n typeof resource.ownerEmail === \"string\"\n ? resource.ownerEmail\n : undefined;\n const orgId =\n typeof resource.orgId === \"string\" ? resource.orgId : undefined;\n\n // Tag the event with owner/org (backward-compat fast path) AND with\n // resourceType/resourceId so canSeeChangeForUser can run an\n // access-aware check for non-owner sharees (see poll.ts).\n recordChange({\n ...event,\n ...(ownerEmail ? { owner: ownerEmail } : {}),\n ...(orgId ? { orgId } : {}),\n resourceType,\n resourceId,\n });\n } catch {\n // If we fail to resolve the resource (DB not ready, etc.) we skip\n // the event rather than broadcasting it without scoping.\n }\n });\n\n // Mount collab routes — manual method dispatch since the path layout is\n // `/collab/:docId/<action>`. The framework strips the `/collab` mount\n // prefix from event.url.pathname before calling us, so we see e.g.\n // `/abc-123/state`.\n getH3App(nitroApp).use(\n `${P}/collab`,\n defineEventHandler(async (event: H3Event) => {\n const parts = (event.url?.pathname || \"\")\n .replace(/^\\/+/, \"\")\n .split(\"/\");\n const docId = parts[0] || \"\";\n const action = parts[1] || \"\";\n if (!docId) return;\n if (event.context) {\n event.context.params = { ...event.context.params, docId };\n }\n const method = getMethod(event);\n\n // Auth check — all collab routes require a session\n const session = await getSession(event).catch(() => null);\n if (!session?.email) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const orgCtx = await getOrgContext(event).catch(() => null);\n const userEmail = session.email;\n const orgId = orgCtx?.orgId ?? undefined;\n\n return runWithRequestContext({ userEmail, orgId }, async () => {\n // Access check — require at least viewer for reads, editor for writes.\n // Awareness routes (POST awareness / GET users) require the same\n // level as other reads so that knowledge of who is editing a doc\n // doesn't leak to users without access.\n if (resourceType) {\n const resourceId = resolveResourceId\n ? await resolveResourceId(docId)\n : docId;\n if (!resourceId) {\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n }\n const isWrite =\n (action === \"update\" && method === \"POST\") ||\n (action === \"text\" && method === \"POST\") ||\n (action === \"search-replace\" && method === \"POST\") ||\n (action === \"json\" && method === \"POST\") ||\n (action === \"patch\" && method === \"POST\");\n\n if (isWrite) {\n // assertAccess throws ForbiddenError (→ 403) if no editor access\n const access = await assertAccess(\n resourceType,\n resourceId,\n \"editor\",\n );\n const resource = access.resource as Record<string, unknown>;\n const awarenessScope: CollabAwarenessScope = {\n resourceType,\n resourceId,\n ...(typeof resource.ownerEmail === \"string\"\n ? { owner: resource.ownerEmail }\n : {}),\n ...(typeof resource.orgId === \"string\"\n ? { orgId: resource.orgId }\n : {}),\n };\n if (event.context) {\n event.context._collabAwarenessScope = awarenessScope;\n }\n } else {\n // resolveAccess returns null when no access; return 404 to avoid leaking existence\n const access = await resolveAccess(resourceType, resourceId);\n if (!access) {\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n }\n const resource = access.resource as Record<string, unknown>;\n const awarenessScope: CollabAwarenessScope = {\n resourceType,\n resourceId,\n ...(typeof resource.ownerEmail === \"string\"\n ? { owner: resource.ownerEmail }\n : {}),\n ...(typeof resource.orgId === \"string\"\n ? { orgId: resource.orgId }\n : {}),\n };\n if (event.context) {\n event.context._collabAwarenessScope = awarenessScope;\n }\n }\n }\n\n // Payload size limit for write operations\n const isWriteAction =\n (action === \"update\" && method === \"POST\") ||\n (action === \"text\" && method === \"POST\") ||\n (action === \"search-replace\" && method === \"POST\") ||\n (action === \"json\" && method === \"POST\") ||\n (action === \"patch\" && method === \"POST\");\n\n if (isWriteAction) {\n const contentLength = Number(\n event.headers?.get?.(\"content-length\") ?? NaN,\n );\n if (!isNaN(contentLength) && contentLength > maxPayloadBytes) {\n setResponseStatus(event, 413);\n return {\n error: `Payload too large. Maximum is ${maxPayloadBytes} bytes.`,\n };\n }\n // Store limit in context so route handlers can enforce it on the\n // parsed body when content-length is absent or spoofed.\n if (event.context) {\n event.context._collabMaxPayloadBytes = maxPayloadBytes;\n }\n }\n\n if (action === \"state\" && method === \"GET\")\n return getCollabState(event);\n if (action === \"update\" && method === \"POST\")\n return postCollabUpdate(event);\n if (action === \"text\" && method === \"POST\")\n return postCollabText(event);\n if (action === \"search-replace\" && method === \"POST\")\n return postCollabSearchReplace(event);\n if (action === \"json\" && method === \"POST\")\n return postCollabJson(event);\n if (action === \"json\" && method === \"GET\")\n return getCollabJson(event);\n if (action === \"patch\" && method === \"POST\")\n return postCollabPatch(event);\n if (action === \"awareness\" && method === \"POST\")\n return postAwareness(event);\n if (action === \"users\" && method === \"GET\")\n return getActiveUsers(event);\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n });\n }),\n );\n\n // Auto-seed existing documents into collab state\n if (autoSeed) {\n const isJson = options.contentType === \"json\";\n const seedColumn = isJson\n ? options.jsonColumn || contentColumn\n : contentColumn;\n\n // Run in background so it doesn't block startup\n setTimeout(async () => {\n try {\n const client = getDbExec();\n const { rows } = await client.execute(\n `SELECT ${idColumn}, ${seedColumn} FROM ${table}`,\n );\n for (const row of rows) {\n const docId = row[idColumn] as string;\n const exists = await hasCollabState(docId);\n if (exists) continue;\n\n if (isJson) {\n const raw = (row[seedColumn] as string) ?? \"{}\";\n try {\n const parsed = JSON.parse(raw);\n const inferredType: \"map\" | \"array\" = Array.isArray(parsed)\n ? \"array\"\n : \"map\";\n await seedFromJson(docId, parsed, \"data\", inferredType);\n } catch {\n // Invalid JSON — skip\n }\n } else {\n const content = (row[seedColumn] as string) ?? \"\";\n await seedFromText(docId, content);\n }\n }\n } catch {\n // Table may not exist yet on first boot — that's fine\n }\n }, 1000);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"collab-plugin.js","sourceRoot":"","sources":["../../src/server/collab-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,iBAAiB,GAElB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE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n * // server/plugins/collab.ts\n * import { createCollabPlugin } from \"@agent-native/core/server\";\n * export default createCollabPlugin({\n * table: \"documents\",\n * contentColumn: \"content\",\n * access: { mode: \"resource\", resourceType: \"document\" },\n * });\n * ```\n */\n\nimport {\n defineEventHandler,\n getMethod,\n setResponseStatus,\n type H3Event,\n} from \"h3\";\n\nimport { postAwareness, getActiveUsers } from \"../collab/awareness.js\";\nimport { getCollabEmitter } from \"../collab/emitter.js\";\nimport {\n getCollabState,\n postCollabUpdate,\n postCollabText,\n postCollabSearchReplace,\n} from \"../collab/routes.js\";\nimport { hasCollabState } from \"../collab/storage.js\";\nimport {\n postCollabJson,\n getCollabJson,\n postCollabPatch,\n} from \"../collab/struct-routes.js\";\nimport { seedFromText, seedFromJson } from \"../collab/ydoc-manager.js\";\nimport { getDbExec } from \"../db/client.js\";\nimport { getOrgContext } from \"../org/context.js\";\nimport { resolveAccess, assertAccess } from \"../sharing/access.js\";\nimport { getSession } from \"./auth.js\";\nimport { FRAMEWORK_ROUTE_PREFIX } from \"./core-routes-plugin.js\";\nimport { getH3App, awaitBootstrap } from \"./framework-request-handler.js\";\nimport { recordChange } from \"./poll.js\";\nimport { runWithRequestContext } from \"./request-context.js\";\n\ntype NitroPluginDef = (nitroApp: any) => void | Promise<void>;\n\n/** Default maximum body size in bytes for collab write operations (2 MB). */\nconst DEFAULT_MAX_PAYLOAD_BYTES = 2 * 1024 * 1024;\n\ntype CollabAwarenessScope = {\n owner?: string;\n orgId?: string;\n resourceType?: string;\n resourceId?: string;\n};\n\nexport type CollabResourceIdResolver = (\n docId: string,\n) => string | null | Promise<string | null>;\n\nexport type CollabAccess =\n | {\n mode: \"resource\";\n /** The shareable resource type registered via `registerShareableResource`. */\n resourceType: string;\n /** Map a collab document id to its parent shareable resource id. */\n resolveResourceId?: CollabResourceIdResolver;\n }\n | {\n /** Deliver collaboration events to every authenticated user. */\n mode: \"all-authenticated\";\n };\n\ntype NormalizedCollabAccess =\n | {\n mode: \"resource\";\n resourceType: string;\n resolveResourceId?: CollabResourceIdResolver;\n }\n | {\n mode: \"all-authenticated\";\n explicit: boolean;\n };\n\n/**\n * Tables whose implicit all-authenticated warning has already been logged in\n * this process. Avoids duplicate warnings during hot reloads while still\n * identifying every affected table.\n */\nconst COLLAB_WARNING_TABLES_KEY =\n \"__agentNativeImplicitCollabAccessWarningTables__\";\nconst collabWarningGlobal = globalThis as typeof globalThis & {\n [COLLAB_WARNING_TABLES_KEY]?: Set<string>;\n};\nconst _unscoped_warning_tables = (collabWarningGlobal[\n COLLAB_WARNING_TABLES_KEY\n] ??= new Set<string>());\n\nexport interface CollabPluginOptions {\n /** Table name containing document content. Default: \"documents\" */\n table?: string;\n /** Column name for text content. Default: \"content\" */\n contentColumn?: string;\n /** Column name for the document ID. Default: \"id\" */\n idColumn?: string;\n /** Whether to auto-seed existing documents on startup. Default: true */\n autoSeed?: boolean;\n /**\n * Callback invoked after a collab update to sync the content column.\n * If not provided, the plugin auto-syncs using table/contentColumn/idColumn.\n */\n onContentSync?: (docId: string, text: string) => Promise<void>;\n /** Content type: \"text\" for Y.Text (default) or \"json\" for Y.Map/Y.Array. */\n contentType?: \"text\" | \"json\";\n /** Column name for JSON content (used when contentType is \"json\"). */\n jsonColumn?: string;\n /**\n * Access policy for collaboration routes and event delivery.\n * Use `resource` for registered shareable resources, or explicitly choose\n * `all-authenticated` for deployment-wide collaboration.\n */\n access?: CollabAccess;\n /**\n * The shareable resource type registered via `registerShareableResource`.\n * Used to enforce access checks on collab routes.\n * @deprecated Use `access: { mode: \"resource\", resourceType }`.\n */\n resourceType?: string;\n /**\n * Map the collab document id to the shareable resource id. Many templates\n * use route-specific collab ids (for example, one doc per slide inside a\n * deck) while sharing is enforced at the parent resource level.\n * @deprecated Use `access: { mode: \"resource\", resourceType, resolveResourceId }`.\n */\n resolveResourceId?: CollabResourceIdResolver;\n /**\n * Maximum allowed body size in bytes for write operations\n * (update/text/json/patch). Requests exceeding this are rejected with 413.\n * Default: 2097152 (2 MB).\n */\n maxPayloadBytes?: number;\n}\n\nexport function normalizeCollabAccess(\n options: Pick<\n CollabPluginOptions,\n \"access\" | \"resourceType\" | \"resolveResourceId\"\n >,\n): NormalizedCollabAccess {\n const hasLegacyAccess =\n options.resourceType !== undefined ||\n options.resolveResourceId !== undefined;\n\n if (options.access && hasLegacyAccess) {\n throw new Error(\n 'createCollabPlugin cannot combine \"access\" with the deprecated root \"resourceType\" or \"resolveResourceId\" options. Move those fields into access.',\n );\n }\n\n if (options.access?.mode === \"resource\") {\n if (!options.access.resourceType.trim()) {\n throw new Error(\n 'createCollabPlugin access mode \"resource\" requires a non-empty resourceType.',\n );\n }\n return options.access;\n }\n\n if (options.access?.mode === \"all-authenticated\") {\n return { mode: \"all-authenticated\", explicit: true };\n }\n\n if (options.access) {\n throw new Error(\n `createCollabPlugin received an unsupported access mode: ${String((options.access as { mode?: unknown }).mode)}`,\n );\n }\n\n if (options.resourceType !== undefined) {\n if (!options.resourceType.trim()) {\n throw new Error(\n 'createCollabPlugin \"resourceType\" must be a non-empty string when provided.',\n );\n }\n return {\n mode: \"resource\",\n resourceType: options.resourceType,\n resolveResourceId: options.resolveResourceId,\n };\n }\n\n if (options.resolveResourceId !== undefined) {\n throw new Error(\n 'createCollabPlugin \"resolveResourceId\" requires a non-empty \"resourceType\".',\n );\n }\n\n return { mode: \"all-authenticated\", explicit: false };\n}\n\nfunction warnForImplicitAllAuthenticatedAccess(table: string): void {\n if (_unscoped_warning_tables.has(table)) return;\n _unscoped_warning_tables.add(table);\n console.warn(\n `[collab] WARNING: createCollabPlugin for table \"${table}\" does not declare an access policy. ` +\n \"Collab events will be delivered to ALL authenticated users on this deployment without document-level access scoping. \" +\n 'Use access: { mode: \"resource\", resourceType: \"...\" } for access-scoped delivery, ' +\n 'or access: { mode: \"all-authenticated\" } to explicitly acknowledge deployment-wide delivery.',\n );\n}\n\nexport function createCollabPlugin(\n options: CollabPluginOptions = {},\n): NitroPluginDef {\n const normalizedAccess = normalizeCollabAccess(options);\n const {\n table = \"documents\",\n contentColumn = \"content\",\n idColumn = \"id\",\n autoSeed = true,\n maxPayloadBytes = DEFAULT_MAX_PAYLOAD_BYTES,\n } = options;\n const resourceType =\n normalizedAccess.mode === \"resource\"\n ? normalizedAccess.resourceType\n : undefined;\n const resolveResourceId =\n normalizedAccess.mode === \"resource\"\n ? normalizedAccess.resolveResourceId\n : undefined;\n\n if (\n normalizedAccess.mode === \"all-authenticated\" &&\n !normalizedAccess.explicit\n ) {\n warnForImplicitAllAuthenticatedAccess(table);\n }\n\n return async (nitroApp: any) => {\n await awaitBootstrap(nitroApp);\n const P = FRAMEWORK_ROUTE_PREFIX;\n\n // Wire collab emitter → poll ring buffer so clients receive Yjs updates.\n // Security: when resourceType is configured, resolve the resource's\n // owner/org so getChangesSinceForUser can scope delivery. We use\n // resolveAccess to obtain the resource row — it already handles ownership,\n // visibility, and share rows. In addition to the owner/org tags we also\n // tag the event with `resourceType` + `resourceId` so the per-user\n // delivery filter (canSeeChangeForUser) can evaluate resource access\n // directly for non-owner sharees:\n // • tag the event with the resource owner's email and org (owner-scoped)\n // for backward compatibility with the conservative owner/org fast path.\n // • ALSO tag with resourceType/resourceId so canSeeChangeForUser can run\n // an access-aware (cached) check and push to explicit viewer+ sharees\n // who don't match owner/org — instead of only degrading them to the\n // poll fallback.\n // See also: SECURITY comment in poll.ts on canSeeChangeForUser.\n const collabEmitter = getCollabEmitter();\n collabEmitter.on(\"collab\", async (event) => {\n if (!resourceType) {\n // No access model — broadcast to all authenticated users (no owner/orgId tag).\n recordChange(event);\n return;\n }\n\n // Resolve the resource to learn its owner/org so we can scope the event.\n const docId = event.docId as string | undefined;\n if (!docId) {\n recordChange(event);\n return;\n }\n\n try {\n const resourceId = resolveResourceId\n ? await resolveResourceId(docId)\n : docId;\n if (!resourceId) {\n // Cannot resolve resource — drop the event to avoid leaking to\n // unauthorized pollers. The client will catch up via state-vector.\n return;\n }\n\n // Load the resource row to get owner/org. resolveAccess fetches the\n // resource row internally; use getShareableResource to read it cheaply.\n const { requireShareableResource } =\n await import(\"../sharing/registry.js\");\n const reg = requireShareableResource(resourceType);\n const db = reg.getDb() as any;\n const { eq } = await import(\"drizzle-orm\");\n const [resource] = await db\n .select()\n .from(reg.resourceTable)\n .where(eq(reg.resourceTable.id, resourceId))\n .limit(1);\n\n if (!resource) {\n // Resource deleted — drop silently.\n return;\n }\n\n const ownerEmail =\n typeof resource.ownerEmail === \"string\"\n ? resource.ownerEmail\n : undefined;\n const orgId =\n typeof resource.orgId === \"string\" ? resource.orgId : undefined;\n\n // Tag the event with owner/org (backward-compat fast path) AND with\n // resourceType/resourceId so canSeeChangeForUser can run an\n // access-aware check for non-owner sharees (see poll.ts).\n recordChange({\n ...event,\n ...(ownerEmail ? { owner: ownerEmail } : {}),\n ...(orgId ? { orgId } : {}),\n resourceType,\n resourceId,\n });\n } catch {\n // If we fail to resolve the resource (DB not ready, etc.) we skip\n // the event rather than broadcasting it without scoping.\n }\n });\n\n // Mount collab routes — manual method dispatch since the path layout is\n // `/collab/:docId/<action>`. The framework strips the `/collab` mount\n // prefix from event.url.pathname before calling us, so we see e.g.\n // `/abc-123/state`.\n getH3App(nitroApp).use(\n `${P}/collab`,\n defineEventHandler(async (event: H3Event) => {\n const parts = (event.url?.pathname || \"\")\n .replace(/^\\/+/, \"\")\n .split(\"/\");\n const docId = parts[0] || \"\";\n const action = parts[1] || \"\";\n if (!docId) return;\n if (event.context) {\n event.context.params = { ...event.context.params, docId };\n }\n const method = getMethod(event);\n\n // Auth check — all collab routes require a session\n const session = await getSession(event).catch(() => null);\n if (!session?.email) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const orgCtx = await getOrgContext(event).catch(() => null);\n const userEmail = session.email;\n const orgId = orgCtx?.orgId ?? undefined;\n\n return runWithRequestContext({ userEmail, orgId }, async () => {\n // Access check — require at least viewer for reads, editor for writes.\n // Awareness routes (POST awareness / GET users) require the same\n // level as other reads so that knowledge of who is editing a doc\n // doesn't leak to users without access.\n if (resourceType) {\n const resourceId = resolveResourceId\n ? await resolveResourceId(docId)\n : docId;\n if (!resourceId) {\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n }\n const isWrite =\n (action === \"update\" && method === \"POST\") ||\n (action === \"text\" && method === \"POST\") ||\n (action === \"search-replace\" && method === \"POST\") ||\n (action === \"json\" && method === \"POST\") ||\n (action === \"patch\" && method === \"POST\");\n\n if (isWrite) {\n // assertAccess throws ForbiddenError (→ 403) if no editor access\n const access = await assertAccess(\n resourceType,\n resourceId,\n \"editor\",\n );\n const resource = access.resource as Record<string, unknown>;\n const awarenessScope: CollabAwarenessScope = {\n resourceType,\n resourceId,\n ...(typeof resource.ownerEmail === \"string\"\n ? { owner: resource.ownerEmail }\n : {}),\n ...(typeof resource.orgId === \"string\"\n ? { orgId: resource.orgId }\n : {}),\n };\n if (event.context) {\n event.context._collabAwarenessScope = awarenessScope;\n }\n } else {\n // resolveAccess returns null when no access; return 404 to avoid leaking existence\n const access = await resolveAccess(resourceType, resourceId);\n if (!access) {\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n }\n const resource = access.resource as Record<string, unknown>;\n const awarenessScope: CollabAwarenessScope = {\n resourceType,\n resourceId,\n ...(typeof resource.ownerEmail === \"string\"\n ? { owner: resource.ownerEmail }\n : {}),\n ...(typeof resource.orgId === \"string\"\n ? { orgId: resource.orgId }\n : {}),\n };\n if (event.context) {\n event.context._collabAwarenessScope = awarenessScope;\n }\n }\n }\n\n // Payload size limit for write operations\n const isWriteAction =\n (action === \"update\" && method === \"POST\") ||\n (action === \"text\" && method === \"POST\") ||\n (action === \"search-replace\" && method === \"POST\") ||\n (action === \"json\" && method === \"POST\") ||\n (action === \"patch\" && method === \"POST\");\n\n if (isWriteAction) {\n const contentLength = Number(\n event.headers?.get?.(\"content-length\") ?? NaN,\n );\n if (!isNaN(contentLength) && contentLength > maxPayloadBytes) {\n setResponseStatus(event, 413);\n return {\n error: `Payload too large. Maximum is ${maxPayloadBytes} bytes.`,\n };\n }\n // Store limit in context so route handlers can enforce it on the\n // parsed body when content-length is absent or spoofed.\n if (event.context) {\n event.context._collabMaxPayloadBytes = maxPayloadBytes;\n }\n }\n\n if (action === \"state\" && method === \"GET\")\n return getCollabState(event);\n if (action === \"update\" && method === \"POST\")\n return postCollabUpdate(event);\n if (action === \"text\" && method === \"POST\")\n return postCollabText(event);\n if (action === \"search-replace\" && method === \"POST\")\n return postCollabSearchReplace(event);\n if (action === \"json\" && method === \"POST\")\n return postCollabJson(event);\n if (action === \"json\" && method === \"GET\")\n return getCollabJson(event);\n if (action === \"patch\" && method === \"POST\")\n return postCollabPatch(event);\n if (action === \"awareness\" && method === \"POST\")\n return postAwareness(event);\n if (action === \"users\" && method === \"GET\")\n return getActiveUsers(event);\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n });\n }),\n );\n\n // Auto-seed existing documents into collab state\n if (autoSeed) {\n const isJson = options.contentType === \"json\";\n const seedColumn = isJson\n ? options.jsonColumn || contentColumn\n : contentColumn;\n\n // Run in background so it doesn't block startup\n setTimeout(async () => {\n try {\n const client = getDbExec();\n const { rows } = await client.execute(\n `SELECT ${idColumn}, ${seedColumn} FROM ${table}`,\n );\n for (const row of rows) {\n const docId = row[idColumn] as string;\n const exists = await hasCollabState(docId);\n if (exists) continue;\n\n if (isJson) {\n const raw = (row[seedColumn] as string) ?? \"{}\";\n try {\n const parsed = JSON.parse(raw);\n const inferredType: \"map\" | \"array\" = Array.isArray(parsed)\n ? \"array\"\n : \"map\";\n await seedFromJson(docId, parsed, \"data\", inferredType);\n } catch {\n // Invalid JSON — skip\n }\n } else {\n const content = (row[seedColumn] as string) ?? \"\";\n await seedFromText(docId, content);\n }\n }\n } catch {\n // Table may not exist yet on first boot — that's fine\n }\n }, 1000);\n }\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-routes-plugin.d.ts","sourceRoot":"","sources":["../../src/server/core-routes-plugin.ts"],"names":[],"mappings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AC,EAAE,MAAM,CAAC;IAC9B,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;wCACoC;IACpC,eAAe,CAAC,EAAE,OAAO,iBAAiB,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IAChF;2DACuD;IACvD,wBAAwB,CAAC,EAAE,OAAO,iBAAiB,EAAE,gBAAgB,CAAC,0BAA0B,CAAC,CAAC;IAClG,qEAAqE;IACrE,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB;;;;OAIG;IACH,cAAc,CAAC,EAAE,6BAA6B,CAAC;CAChD;AAED,UAAU,2BAA2B;IACnC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAChD,mBAAmB,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC7C;AAED,KAAK,sBAAsB,GAAG,CAC5B,GAAG,EAAE,MAAM,KACR,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAE7C,wBAAsB,+BAA+B,CACnD,WAAW,GAAE,sBAAmC,GAC/C,OAAO,CAAC,2BAA2B,CAAC,CAgBtC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,uBAA4B,GACpC,cAAc,CAk7FhB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAAyC,CAAC"}
|
|
@@ -49,6 +49,7 @@ import { handleIdentitySso } from "./identity-sso.js";
|
|
|
49
49
|
import { createOpenRouteHandler } from "./open-route.js";
|
|
50
50
|
import { createPollEventsHandler } from "./poll-events.js";
|
|
51
51
|
import { createPollHandler } from "./poll.js";
|
|
52
|
+
import { createRealtimeTokenHandler } from "./realtime-token.js";
|
|
52
53
|
import { runWithRequestContext } from "./request-context.js";
|
|
53
54
|
import { findUnsupportedScopedKeyNames, saveKeyValuesToScopedSecrets, ScopedKeyStorageError, } from "./scoped-key-storage.js";
|
|
54
55
|
import { createTranscribeVoiceHandler } from "./transcribe-voice.js";
|
|
@@ -901,6 +902,8 @@ export function createCoreRoutesPlugin(options = {}) {
|
|
|
901
902
|
}));
|
|
902
903
|
// Polling
|
|
903
904
|
getH3App(nitroApp).use(`${P}/poll`, createPollHandler());
|
|
905
|
+
// Realtime subscribe-token mint (hosted gateway path)
|
|
906
|
+
getH3App(nitroApp).use(`${P}/realtime-token`, createRealtimeTokenHandler());
|
|
904
907
|
// SSE
|
|
905
908
|
if (!options.disableSSE) {
|
|
906
909
|
for (const route of resolveFrameworkSseRoutes(options.sseRoute)) {
|