@agent-native/core 0.93.0 → 0.94.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/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +25 -0
- package/corpus/core/docs/content/a2a-protocol.mdx +21 -5
- package/corpus/core/docs/content/actions.mdx +9 -23
- package/corpus/core/docs/content/agent-mentions.mdx +31 -29
- package/corpus/core/docs/content/agent-native-toolkit.mdx +15 -6
- package/corpus/core/docs/content/agent-surfaces.mdx +9 -13
- package/corpus/core/docs/content/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/authentication.mdx +10 -3
- package/corpus/core/docs/content/automation-connectors.mdx +82 -39
- package/corpus/core/docs/content/automations.mdx +17 -3
- package/corpus/core/docs/content/blueprint-installer.mdx +11 -4
- package/corpus/core/docs/content/cli-adapters.mdx +9 -6
- package/corpus/core/docs/content/client.mdx +16 -0
- package/corpus/core/docs/content/cloneable-saas.mdx +14 -11
- package/corpus/core/docs/content/code-agents-ui.mdx +65 -0
- package/corpus/core/docs/content/components.mdx +30 -14
- package/corpus/core/docs/content/context-awareness.mdx +27 -15
- package/corpus/core/docs/content/creating-templates.mdx +15 -9
- package/corpus/core/docs/content/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/data-programs.mdx +1 -1
- package/corpus/core/docs/content/database.mdx +17 -5
- package/corpus/core/docs/content/deployment.mdx +19 -18
- package/corpus/core/docs/content/dispatch.mdx +6 -2
- package/corpus/core/docs/content/drop-in-agent.mdx +10 -4
- package/corpus/core/docs/content/durable-background-runs.mdx +9 -5
- package/corpus/core/docs/content/durable-resume.mdx +9 -4
- package/corpus/core/docs/content/embedding-sdk.mdx +26 -8
- package/corpus/core/docs/content/evals.mdx +3 -5
- package/corpus/core/docs/content/extensions.mdx +22 -9
- package/corpus/core/docs/content/external-agents.mdx +25 -34
- package/corpus/core/docs/content/faq.mdx +8 -0
- package/corpus/core/docs/content/file-uploads.mdx +12 -3
- package/corpus/core/docs/content/frames.mdx +16 -0
- package/corpus/core/docs/content/generative-ui.mdx +1 -1
- package/corpus/core/docs/content/getting-started.mdx +34 -21
- package/corpus/core/docs/content/harness-agents.mdx +8 -4
- package/corpus/core/docs/content/human-approval.mdx +8 -3
- package/corpus/core/docs/content/internationalization.mdx +9 -4
- package/corpus/core/docs/content/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/local-file-mode.mdx +14 -8
- package/corpus/core/docs/content/locales/ar-SA/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/ar-SA/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/ar-SA/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/ar-SA/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/ar-SA/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/ar-SA/components.mdx +11 -1
- package/corpus/core/docs/content/locales/ar-SA/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/ar-SA/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/ar-SA/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/ar-SA/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/ar-SA/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/ar-SA/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/ar-SA/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/ar-SA/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/ar-SA/server.mdx +17 -10
- package/corpus/core/docs/content/locales/ar-SA/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/ar-SA/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/ar-SA/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/ar-SA/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/ar-SA/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/ar-SA/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/ar-SA/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/ar-SA/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/ar-SA/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/ar-SA/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/ar-SA/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/ar-SA/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/ar-SA/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/de-DE/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/de-DE/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/de-DE/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/de-DE/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/de-DE/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/de-DE/components.mdx +11 -1
- package/corpus/core/docs/content/locales/de-DE/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/de-DE/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/de-DE/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/de-DE/external-agents.mdx +3 -7
- package/corpus/core/docs/content/locales/de-DE/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/de-DE/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/de-DE/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/de-DE/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/de-DE/server.mdx +18 -10
- package/corpus/core/docs/content/locales/de-DE/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/de-DE/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/de-DE/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/de-DE/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/de-DE/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/de-DE/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/de-DE/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/de-DE/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/de-DE/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/de-DE/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/de-DE/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/de-DE/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/de-DE/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/es-ES/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/es-ES/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/es-ES/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/es-ES/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/es-ES/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/es-ES/components.mdx +11 -1
- package/corpus/core/docs/content/locales/es-ES/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/es-ES/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/es-ES/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/es-ES/external-agents.mdx +3 -7
- package/corpus/core/docs/content/locales/es-ES/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/es-ES/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/es-ES/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/es-ES/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/es-ES/server.mdx +17 -10
- package/corpus/core/docs/content/locales/es-ES/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/es-ES/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/es-ES/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/es-ES/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/es-ES/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/es-ES/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/es-ES/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/es-ES/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/es-ES/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/es-ES/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/es-ES/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/es-ES/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/es-ES/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/fr-FR/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/fr-FR/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/fr-FR/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/fr-FR/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/fr-FR/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/fr-FR/components.mdx +11 -1
- package/corpus/core/docs/content/locales/fr-FR/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/fr-FR/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/fr-FR/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/fr-FR/external-agents.mdx +3 -7
- package/corpus/core/docs/content/locales/fr-FR/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/fr-FR/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/fr-FR/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/fr-FR/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/fr-FR/server.mdx +17 -10
- package/corpus/core/docs/content/locales/fr-FR/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/fr-FR/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/fr-FR/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/fr-FR/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/fr-FR/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/fr-FR/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/fr-FR/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/fr-FR/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/fr-FR/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/fr-FR/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/fr-FR/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/fr-FR/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/fr-FR/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/hi-IN/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/hi-IN/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/hi-IN/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/hi-IN/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/hi-IN/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/hi-IN/components.mdx +11 -1
- package/corpus/core/docs/content/locales/hi-IN/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/hi-IN/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/hi-IN/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/hi-IN/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/hi-IN/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/hi-IN/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/hi-IN/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/hi-IN/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/hi-IN/server.mdx +17 -10
- package/corpus/core/docs/content/locales/hi-IN/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/hi-IN/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/hi-IN/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/hi-IN/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/hi-IN/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/hi-IN/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/hi-IN/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/hi-IN/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/hi-IN/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/hi-IN/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/hi-IN/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/hi-IN/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/hi-IN/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/ja-JP/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/ja-JP/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/ja-JP/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/ja-JP/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/ja-JP/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/ja-JP/components.mdx +11 -1
- package/corpus/core/docs/content/locales/ja-JP/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/ja-JP/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/ja-JP/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/ja-JP/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/ja-JP/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/ja-JP/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/ja-JP/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/ja-JP/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/ja-JP/server.mdx +17 -10
- package/corpus/core/docs/content/locales/ja-JP/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/ja-JP/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/ja-JP/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/ja-JP/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/ja-JP/template-clips.mdx +3 -4
- package/corpus/core/docs/content/locales/ja-JP/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/ja-JP/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/ja-JP/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/ja-JP/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/ja-JP/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/ja-JP/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/ja-JP/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/ja-JP/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/ko-KR/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/ko-KR/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/ko-KR/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/ko-KR/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/ko-KR/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/ko-KR/components.mdx +11 -1
- package/corpus/core/docs/content/locales/ko-KR/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/ko-KR/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/ko-KR/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/ko-KR/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/ko-KR/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/ko-KR/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/ko-KR/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/ko-KR/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/ko-KR/server.mdx +17 -10
- package/corpus/core/docs/content/locales/ko-KR/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/ko-KR/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/ko-KR/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/ko-KR/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/ko-KR/template-clips.mdx +3 -4
- package/corpus/core/docs/content/locales/ko-KR/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/ko-KR/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/ko-KR/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/ko-KR/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/ko-KR/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/ko-KR/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/ko-KR/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/ko-KR/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/pt-BR/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/pt-BR/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/pt-BR/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/pt-BR/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/pt-BR/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/pt-BR/components.mdx +11 -1
- package/corpus/core/docs/content/locales/pt-BR/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/pt-BR/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/pt-BR/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/pt-BR/external-agents.mdx +3 -7
- package/corpus/core/docs/content/locales/pt-BR/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/pt-BR/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/pt-BR/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/pt-BR/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/pt-BR/server.mdx +17 -10
- package/corpus/core/docs/content/locales/pt-BR/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/pt-BR/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/pt-BR/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/pt-BR/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/pt-BR/template-clips.mdx +3 -3
- package/corpus/core/docs/content/locales/pt-BR/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/pt-BR/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/pt-BR/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/pt-BR/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/pt-BR/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/pt-BR/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/pt-BR/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/pt-BR/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/zh-CN/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/zh-CN/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/zh-CN/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/zh-CN/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/zh-CN/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/zh-CN/components.mdx +11 -1
- package/corpus/core/docs/content/locales/zh-CN/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/zh-CN/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/zh-CN/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-CN/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/zh-CN/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/zh-CN/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/zh-CN/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/zh-CN/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/zh-CN/server.mdx +16 -10
- package/corpus/core/docs/content/locales/zh-CN/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/zh-CN/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/zh-CN/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/zh-CN/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/zh-CN/template-clips.mdx +3 -4
- package/corpus/core/docs/content/locales/zh-CN/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/zh-CN/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/zh-CN/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-CN/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/zh-CN/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/zh-CN/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/zh-CN/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/zh-CN/workspace.mdx +19 -18
- package/corpus/core/docs/content/locales/zh-TW/actions.mdx +2 -2
- package/corpus/core/docs/content/locales/zh-TW/agent-native-toolkit.mdx +2 -2
- package/corpus/core/docs/content/locales/zh-TW/agent-surfaces.mdx +8 -10
- package/corpus/core/docs/content/locales/zh-TW/agent-teams.mdx +1 -0
- package/corpus/core/docs/content/locales/zh-TW/authentication.mdx +1 -1
- package/corpus/core/docs/content/locales/zh-TW/components.mdx +11 -1
- package/corpus/core/docs/content/locales/zh-TW/creating-templates.mdx +3 -7
- package/corpus/core/docs/content/locales/zh-TW/cross-app-sso.mdx +16 -6
- package/corpus/core/docs/content/locales/zh-TW/deployment.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-TW/external-agents.mdx +2 -7
- package/corpus/core/docs/content/locales/zh-TW/key-concepts.mdx +13 -20
- package/corpus/core/docs/content/locales/zh-TW/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/locales/zh-TW/notifications.mdx +18 -10
- package/corpus/core/docs/content/locales/zh-TW/processors.mdx +11 -5
- package/corpus/core/docs/content/locales/zh-TW/server.mdx +16 -10
- package/corpus/core/docs/content/locales/zh-TW/sharing.mdx +10 -10
- package/corpus/core/docs/content/locales/zh-TW/skills-guide.mdx +34 -17
- package/corpus/core/docs/content/locales/zh-TW/template-assets.mdx +16 -13
- package/corpus/core/docs/content/locales/zh-TW/template-brain.mdx +3 -1
- package/corpus/core/docs/content/locales/zh-TW/template-clips.mdx +3 -4
- package/corpus/core/docs/content/locales/zh-TW/template-design.mdx +3 -1
- package/corpus/core/docs/content/locales/zh-TW/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/locales/zh-TW/template-mail.mdx +8 -0
- package/corpus/core/docs/content/locales/zh-TW/tracking.mdx +9 -6
- package/corpus/core/docs/content/locales/zh-TW/using-your-agent.mdx +0 -7
- package/corpus/core/docs/content/locales/zh-TW/voice-input.mdx +6 -0
- package/corpus/core/docs/content/locales/zh-TW/workspace-connections.mdx +9 -2
- package/corpus/core/docs/content/locales/zh-TW/workspace.mdx +19 -18
- package/corpus/core/docs/content/mcp-apps.mdx +14 -32
- package/corpus/core/docs/content/mcp-clients.mdx +48 -54
- package/corpus/core/docs/content/mcp-protocol.mdx +25 -10
- package/corpus/core/docs/content/messaging.mdx +19 -11
- package/corpus/core/docs/content/multi-app-workspace.mdx +11 -96
- package/corpus/core/docs/content/multi-tenancy.mdx +5 -5
- package/corpus/core/docs/content/native-chat-ui.mdx +4 -4
- package/corpus/core/docs/content/notifications.mdx +19 -12
- package/corpus/core/docs/content/observability.mdx +2 -4
- package/corpus/core/docs/content/observational-memory.mdx +7 -3
- package/corpus/core/docs/content/onboarding.mdx +9 -2
- package/corpus/core/docs/content/plan-plugin.mdx +10 -2
- package/corpus/core/docs/content/pr-visual-recap.mdx +1 -1
- package/corpus/core/docs/content/processors.mdx +11 -5
- package/corpus/core/docs/content/pure-agent-apps.mdx +5 -1
- package/corpus/core/docs/content/real-time-collaboration.mdx +30 -67
- package/corpus/core/docs/content/recurring-jobs.mdx +8 -6
- package/corpus/core/docs/content/routing.mdx +3 -4
- package/corpus/core/docs/content/sandbox-adapters.mdx +30 -53
- package/corpus/core/docs/content/security.mdx +8 -0
- package/corpus/core/docs/content/server.mdx +17 -10
- package/corpus/core/docs/content/sharing.mdx +10 -10
- package/corpus/core/docs/content/skills-guide.mdx +35 -16
- package/corpus/core/docs/content/template-analytics.mdx +11 -8
- package/corpus/core/docs/content/template-assets.mdx +16 -13
- package/corpus/core/docs/content/template-brain.mdx +3 -1
- package/corpus/core/docs/content/template-calendar.mdx +12 -4
- package/corpus/core/docs/content/template-chat.mdx +4 -4
- package/corpus/core/docs/content/template-clips.mdx +3 -3
- package/corpus/core/docs/content/template-content.mdx +23 -18
- package/corpus/core/docs/content/template-design.mdx +3 -1
- package/corpus/core/docs/content/template-dispatch.mdx +5 -1
- package/corpus/core/docs/content/template-mail.mdx +14 -2
- package/corpus/core/docs/content/template-plan.mdx +22 -15
- package/corpus/core/docs/content/template-slides.mdx +11 -3
- package/corpus/core/docs/content/toolkit-agent-ux.mdx +46 -3
- package/corpus/core/docs/content/toolkit-collaboration.mdx +58 -4
- package/corpus/core/docs/content/toolkit-command-navigation.mdx +8 -2
- package/corpus/core/docs/content/toolkit-comments-review.mdx +10 -2
- package/corpus/core/docs/content/toolkit-history.mdx +8 -3
- package/corpus/core/docs/content/toolkit-observability.mdx +48 -2
- package/corpus/core/docs/content/toolkit-org-team.mdx +8 -2
- package/corpus/core/docs/content/toolkit-resources.mdx +45 -2
- package/corpus/core/docs/content/toolkit-settings.mdx +8 -2
- package/corpus/core/docs/content/toolkit-setup-connections.mdx +7 -2
- package/corpus/core/docs/content/toolkit-sharing.mdx +46 -3
- package/corpus/core/docs/content/toolkit-ui.mdx +82 -11
- package/corpus/core/docs/content/tracking.mdx +10 -8
- package/corpus/core/docs/content/using-your-agent.mdx +0 -12
- package/corpus/core/docs/content/voice-input.mdx +7 -1
- package/corpus/core/docs/content/what-is-agent-native.mdx +7 -8
- package/corpus/core/docs/content/workspace-connections.mdx +16 -23
- package/corpus/core/docs/content/workspace-management.mdx +16 -4
- package/corpus/core/docs/content/workspace.mdx +19 -18
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/context-xray/tokenize.ts +6 -1
- package/corpus/core/src/agent/engine/ai-sdk-engine.ts +9 -5
- package/corpus/core/src/agent/engine/anthropic-engine.ts +2 -4
- package/corpus/core/src/agent/engine/builder-engine.ts +5 -7
- package/corpus/core/src/agent/engine/index.ts +1 -0
- package/corpus/core/src/agent/engine/registry.ts +40 -0
- package/corpus/core/src/agent/harness/ai-sdk-adapter.ts +6 -1
- package/corpus/core/src/agent/harness/background.ts +96 -19
- package/corpus/core/src/agent/harness/index.ts +11 -0
- package/corpus/core/src/agent/harness/lifecycle.ts +498 -0
- package/corpus/core/src/agent/harness/runner.ts +38 -0
- package/corpus/core/src/agent/harness/store.ts +22 -3
- package/corpus/core/src/agent/model-config.ts +4 -1
- package/corpus/core/src/agent/production-agent.ts +190 -6
- package/corpus/core/src/agent/run-manager.ts +5 -1
- package/corpus/core/src/application-state/index.ts +1 -0
- package/corpus/core/src/application-state/store.ts +32 -0
- package/corpus/core/src/cli/code-agent-connector.ts +263 -8
- package/corpus/core/src/cli/code-agent-executor.ts +15 -1
- package/corpus/core/src/client/AgentPanel.tsx +41 -38
- package/corpus/core/src/client/AssistantChat.tsx +53 -5
- package/corpus/core/src/client/MultiTabAssistantChat.tsx +33 -40
- package/corpus/core/src/client/appearance.ts +8 -5
- package/corpus/core/src/client/chat/connectors.ts +293 -29
- package/corpus/core/src/client/chat/message-components.tsx +23 -1
- package/corpus/core/src/client/chat/runtime.ts +126 -25
- package/corpus/core/src/client/chat/tool-call-display.tsx +45 -4
- package/corpus/core/src/client/composer/RealtimeVoiceMode.tsx +294 -0
- package/corpus/core/src/client/composer/TiptapComposer.tsx +21 -20
- package/corpus/core/src/client/composer/VoiceButton.tsx +20 -0
- package/corpus/core/src/client/composer/index.ts +22 -0
- package/corpus/core/src/client/composer/useRealtimeVoiceMode.tsx +640 -0
- package/corpus/core/src/client/guided-questions.tsx +12 -3
- package/corpus/core/src/client/index.ts +18 -0
- package/corpus/core/src/client/settings/DemoModeSection.tsx +4 -3
- package/corpus/core/src/client/settings/SettingsPanel.tsx +4 -0
- package/corpus/core/src/client/settings/SettingsTabsPage.tsx +95 -37
- package/corpus/core/src/client/use-chat-models.ts +17 -17
- package/corpus/core/src/client/use-db-sync.ts +108 -7
- package/corpus/core/src/code-agents/background-controller.ts +18 -0
- package/corpus/core/src/collab/ydoc-manager.ts +41 -6
- package/corpus/core/src/db/migrations.ts +17 -1
- package/corpus/core/src/demo/fetch-interceptor.ts +16 -11
- package/corpus/core/src/integrations/adapters/slack.ts +41 -2
- package/corpus/core/src/integrations/awaiting-input-store.ts +130 -0
- package/corpus/core/src/integrations/computer-supervision-store.ts +423 -0
- package/corpus/core/src/integrations/computer-supervision.ts +213 -0
- package/corpus/core/src/integrations/index.ts +29 -1
- package/corpus/core/src/integrations/plugin.ts +231 -2
- package/corpus/core/src/integrations/remote-commands-store.ts +334 -3
- package/corpus/core/src/integrations/remote-devices-store.ts +68 -9
- package/corpus/core/src/integrations/remote-json-safety.ts +127 -0
- package/corpus/core/src/integrations/remote-run-events-store.ts +104 -19
- package/corpus/core/src/integrations/remote-types.ts +66 -3
- package/corpus/core/src/integrations/webhook-handler.ts +161 -2
- package/corpus/core/src/localization/default-messages.ts +28 -0
- package/corpus/core/src/mcp-client/config.ts +48 -2
- package/corpus/core/src/mcp-client/index.ts +35 -2
- package/corpus/core/src/mcp-client/tool-policy.ts +182 -0
- package/corpus/core/src/secrets/register-framework-secrets.ts +27 -4
- package/corpus/core/src/server/agent-chat-plugin.ts +62 -8
- package/corpus/core/src/server/index.ts +16 -0
- package/corpus/core/src/server/realtime-voice.ts +590 -0
- package/corpus/core/src/shared/reasoning-effort.ts +61 -19
- package/corpus/core/src/styles/agent-conversation.css +17 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
- package/corpus/templates/brain/app/lib/settings-navigation.ts +22 -0
- package/corpus/templates/brain/app/routes/settings.tsx +367 -252
- package/corpus/templates/brain/changelog/2026-07-10-brain-settings-now-separate-assistant-behavior-publishing-re.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-10-organization-settings-now-opens-directly-from-the-workspace-.md +6 -0
- package/corpus/templates/calendar/.agents/skills/event-management/SKILL.md +36 -4
- package/corpus/templates/calendar/AGENTS.md +4 -0
- package/corpus/templates/calendar/actions/create-event.ts +7 -19
- package/corpus/templates/calendar/actions/delete-event.ts +10 -3
- package/corpus/templates/calendar/actions/rsvp-event.ts +1 -1
- package/corpus/templates/calendar/actions/update-event.ts +4 -3
- package/corpus/templates/calendar/app/components/calendar/CreateEventDialog.tsx +100 -13
- package/corpus/templates/calendar/app/components/calendar/DayView.tsx +12 -4
- package/corpus/templates/calendar/app/components/calendar/EventDetailPanel.tsx +3 -3
- package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +86 -8
- package/corpus/templates/calendar/app/components/calendar/EventDialog.tsx +3 -1
- package/corpus/templates/calendar/app/components/calendar/WeekView.tsx +12 -4
- package/corpus/templates/calendar/app/hooks/use-events.ts +1 -0
- package/corpus/templates/calendar/app/lib/event-account-selection.ts +36 -0
- package/corpus/templates/calendar/app/lib/event-form-initialization.ts +21 -0
- package/corpus/templates/calendar/app/lib/event-mutation-inputs.ts +18 -0
- package/corpus/templates/calendar/app/pages/CalendarView.tsx +119 -26
- package/corpus/templates/calendar/changelog/2026-07-10-choose-which-connected-google-account-receives-a-new-event-w.md +6 -0
- package/corpus/templates/calendar/server/db/schema.ts +2 -0
- package/corpus/templates/calendar/server/handlers/bookings.ts +43 -6
- package/corpus/templates/calendar/server/handlers/events.ts +28 -9
- package/corpus/templates/calendar/server/lib/google-calendar.ts +66 -38
- package/corpus/templates/calendar/server/plugins/db.ts +5 -0
- package/corpus/templates/clips/.agents/skills/ai-video-tools/SKILL.md +12 -3
- package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +1 -1
- package/corpus/templates/clips/AGENTS.md +4 -2
- package/corpus/templates/clips/actions/regenerate-title.ts +53 -7
- package/corpus/templates/clips/actions/request-transcript.ts +152 -41
- package/corpus/templates/clips/actions/save-browser-transcript.ts +11 -9
- package/corpus/templates/clips/app/components/player/comments-panel.tsx +101 -53
- package/corpus/templates/clips/app/components/player/playback-comment-overlay.tsx +102 -0
- package/corpus/templates/clips/app/components/player/video-player.tsx +10 -1
- package/corpus/templates/clips/app/hooks/use-auto-title.ts +14 -0
- package/corpus/templates/clips/app/routes/embed.$shareId.tsx +2 -0
- package/corpus/templates/clips/changelog/2026-07-10-comment-replies-now-open-inline-and-focus-immediately-while-.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-dismissed-upload-warnings-now-keep-recordings-in-clip-drafts.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-dragging-the-meeting-recorder-no-longer-opens-the-expanded.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-finishing-meeting-notes-no-longer-opens-your-browser.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-meeting-recordings-now-keep-microphone-audio-and-recover-tra.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-recording-pause-and-resume-controls-now-respond-reliably-on-.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-starting-and-joining-a-meeting-now-closes-the-desktop-popover.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-timestamped-comments-now-appear-over-the-video-as-playback-r.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-transcript-backed-titles-and-summaries-now-finish-after-recording.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-10-zoom-meetings-now-open-directly-in-the-desktop-app.md +6 -0
- package/corpus/templates/clips/chrome-extension/src/overlay.ts +49 -7
- package/corpus/templates/clips/desktop/src/app.tsx +70 -42
- package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +8 -14
- package/corpus/templates/clips/desktop/src/lib/meeting-join-url.ts +33 -0
- package/corpus/templates/clips/desktop/src/lib/pause-transition.ts +79 -0
- package/corpus/templates/clips/desktop/src/lib/pill-interaction.ts +19 -0
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +90 -39
- package/corpus/templates/clips/desktop/src/lib/transcription-engine.ts +3 -2
- package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +3 -2
- package/corpus/templates/clips/desktop/src/overlays/recording-pill.tsx +32 -6
- package/corpus/templates/clips/desktop/src/overlays/toolbar.tsx +50 -5
- package/corpus/templates/clips/desktop/src/styles.css +11 -19
- package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +2 -1
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +121 -4
- package/corpus/templates/clips/desktop/src-tauri/src/native_speech.rs +97 -17
- package/corpus/templates/clips/desktop/src-tauri/src/whisper_speech.rs +80 -5
- package/corpus/templates/clips/desktop/src-tauri/tauri.conf.json +1 -1
- package/corpus/templates/clips/vitest.config.ts +23 -0
- package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +28 -9
- package/corpus/templates/content/changelog/2026-07-10-open-documents-no-longer-make-constant-background-requests-w.md +6 -0
- package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +21 -4
- package/corpus/templates/design/AGENTS.md +7 -0
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +132 -7
- package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +73 -18
- package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +6 -1
- package/corpus/templates/design/app/components/design/multi-screen/frame-geometry.ts +135 -5
- package/corpus/templates/design/app/lib/clipboard-content-lineage.ts +64 -0
- package/corpus/templates/design/app/lib/design-clipboard-managed-styles.ts +247 -0
- package/corpus/templates/design/app/lib/design-clipboard.ts +60 -3
- package/corpus/templates/design/app/lib/design-import.ts +31 -3
- package/corpus/templates/design/app/pages/design-editor/latest-write-queue.ts +56 -0
- package/corpus/templates/design/app/pages/design-editor/performance-buffer-guard.ts +80 -0
- package/corpus/templates/design/changelog/2026-07-10-concurrent-agent-and-artboard-edits-no-longer-show-misleadin.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-designs-with-html-examples-inside-alpine-attributes-or-comme.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-interactive-designs-no-longer-appear-blank-in-the-canvas-whe.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-long-overview-editing-sessions-lots-of-pan-zoom-screen-switc.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-rapid-breakpoint-and-edit-scope-changes-no-longer-jump-back-.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-responsive-breakpoint-previews-stay-visible-while-panning-ac.md +6 -0
- package/corpus/templates/design/changelog/2026-07-10-rich-design-clipboard-markers-are-now-accepted-only-from-the.md +6 -0
- package/corpus/templates/design/e2e/helpers.ts +16 -5
- package/corpus/templates/design/server/source-workspace.ts +28 -2
- package/corpus/templates/design/shared/html-integrity.ts +119 -24
- package/corpus/templates/dispatch/AGENTS.md +10 -2
- package/corpus/templates/dispatch/actions/view-screen.ts +11 -0
- package/corpus/templates/dispatch/app/hooks/use-navigation-state.ts +13 -0
- package/corpus/templates/dispatch/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/dispatch/app/i18n-data.ts +37 -1
- package/corpus/templates/dispatch/app/routes/operations.tsx +1 -0
- package/corpus/templates/dispatch/changelog/2026-07-10-dispatch-now-has-a-cleaner-chat-history-and-quieter-sidebar-.md +6 -0
- package/corpus/templates/dispatch/changelog/2026-07-10-operations-console-brings-agent-monitoring-and-database-inspection-tog.md +6 -0
- package/corpus/templates/mail/actions/get-integration-statuses.ts +36 -0
- package/corpus/templates/mail/app/components/email/EmailThread.tsx +3 -2
- package/corpus/templates/mail/app/components/email/IntegrationsSidebar.tsx +3 -3
- package/corpus/templates/mail/app/hooks/use-apollo.ts +5 -71
- package/corpus/templates/mail/app/hooks/use-draft-queue.ts +1 -1
- package/corpus/templates/mail/app/hooks/use-integrations.ts +51 -48
- package/corpus/templates/mail/app/lib/integration-status.ts +31 -0
- package/corpus/templates/mail/app/lib/sync-invalidation.ts +5 -0
- package/corpus/templates/mail/app/pages/SettingsPage.tsx +3 -0
- package/corpus/templates/mail/app/root.tsx +22 -12
- package/corpus/templates/mail/changelog/2026-07-10-email-content-backgrounds-now-blend-cleanly-with-dark-mode.md +6 -0
- package/corpus/templates/mail/changelog/2026-07-10-mail-settings-now-group-drafting-automation-and-connected-se.md +6 -0
- package/corpus/templates/mail/changelog/2026-07-10-organization-settings-now-opens-directly-from-the-workspace-.md +6 -0
- package/dist/agent/context-xray/tokenize.d.ts.map +1 -1
- package/dist/agent/context-xray/tokenize.js +6 -1
- package/dist/agent/context-xray/tokenize.js.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.js +8 -3
- package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
- package/dist/agent/engine/anthropic-engine.js +2 -4
- package/dist/agent/engine/anthropic-engine.js.map +1 -1
- package/dist/agent/engine/builder-engine.d.ts +1 -1
- package/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builder-engine.js +2 -3
- package/dist/agent/engine/builder-engine.js.map +1 -1
- package/dist/agent/engine/index.d.ts +1 -1
- package/dist/agent/engine/index.d.ts.map +1 -1
- package/dist/agent/engine/index.js +1 -1
- package/dist/agent/engine/index.js.map +1 -1
- package/dist/agent/engine/registry.d.ts +13 -0
- package/dist/agent/engine/registry.d.ts.map +1 -1
- package/dist/agent/engine/registry.js +33 -0
- package/dist/agent/engine/registry.js.map +1 -1
- package/dist/agent/harness/ai-sdk-adapter.d.ts.map +1 -1
- package/dist/agent/harness/ai-sdk-adapter.js +3 -1
- package/dist/agent/harness/ai-sdk-adapter.js.map +1 -1
- package/dist/agent/harness/background.d.ts +9 -9
- package/dist/agent/harness/background.d.ts.map +1 -1
- package/dist/agent/harness/background.js +77 -19
- package/dist/agent/harness/background.js.map +1 -1
- package/dist/agent/harness/index.d.ts +1 -0
- package/dist/agent/harness/index.d.ts.map +1 -1
- package/dist/agent/harness/index.js +1 -0
- package/dist/agent/harness/index.js.map +1 -1
- package/dist/agent/harness/lifecycle.d.ts +45 -0
- package/dist/agent/harness/lifecycle.d.ts.map +1 -0
- package/dist/agent/harness/lifecycle.js +318 -0
- package/dist/agent/harness/lifecycle.js.map +1 -0
- package/dist/agent/harness/runner.d.ts.map +1 -1
- package/dist/agent/harness/runner.js +29 -1
- package/dist/agent/harness/runner.js.map +1 -1
- package/dist/agent/harness/store.d.ts +2 -0
- package/dist/agent/harness/store.d.ts.map +1 -1
- package/dist/agent/harness/store.js +17 -3
- package/dist/agent/harness/store.js.map +1 -1
- package/dist/agent/model-config.d.ts +2 -2
- package/dist/agent/model-config.d.ts.map +1 -1
- package/dist/agent/model-config.js +4 -1
- package/dist/agent/model-config.js.map +1 -1
- package/dist/agent/production-agent.d.ts +38 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +135 -4
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/application-state/index.d.ts +1 -1
- package/dist/application-state/index.d.ts.map +1 -1
- package/dist/application-state/index.js +1 -1
- package/dist/application-state/index.js.map +1 -1
- package/dist/application-state/store.d.ts +6 -0
- package/dist/application-state/store.d.ts.map +1 -1
- package/dist/application-state/store.js +31 -0
- package/dist/application-state/store.js.map +1 -1
- package/dist/cli/code-agent-connector.d.ts +9 -0
- package/dist/cli/code-agent-connector.d.ts.map +1 -1
- package/dist/cli/code-agent-connector.js +212 -10
- package/dist/cli/code-agent-connector.js.map +1 -1
- package/dist/cli/code-agent-executor.d.ts +2 -0
- package/dist/cli/code-agent-executor.d.ts.map +1 -1
- package/dist/cli/code-agent-executor.js +8 -1
- package/dist/cli/code-agent-executor.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +6 -5
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts +6 -0
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +34 -4
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +16 -37
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/appearance.d.ts +4 -2
- package/dist/client/appearance.d.ts.map +1 -1
- package/dist/client/appearance.js +8 -5
- package/dist/client/appearance.js.map +1 -1
- package/dist/client/chat/connectors.d.ts.map +1 -1
- package/dist/client/chat/connectors.js +206 -28
- package/dist/client/chat/connectors.js.map +1 -1
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +17 -1
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat/runtime.d.ts.map +1 -1
- package/dist/client/chat/runtime.js +84 -24
- package/dist/client/chat/runtime.js.map +1 -1
- package/dist/client/chat/tool-call-display.d.ts +8 -1
- package/dist/client/chat/tool-call-display.d.ts.map +1 -1
- package/dist/client/chat/tool-call-display.js +21 -3
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/client/composer/RealtimeVoiceMode.d.ts +54 -0
- package/dist/client/composer/RealtimeVoiceMode.d.ts.map +1 -0
- package/dist/client/composer/RealtimeVoiceMode.js +63 -0
- package/dist/client/composer/RealtimeVoiceMode.js.map +1 -0
- package/dist/client/composer/TiptapComposer.d.ts +1 -0
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +17 -20
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/VoiceButton.d.ts.map +1 -1
- package/dist/client/composer/VoiceButton.js +9 -0
- package/dist/client/composer/VoiceButton.js.map +1 -1
- package/dist/client/composer/index.d.ts +2 -0
- package/dist/client/composer/index.d.ts.map +1 -1
- package/dist/client/composer/index.js +2 -0
- package/dist/client/composer/index.js.map +1 -1
- package/dist/client/composer/useRealtimeVoiceMode.d.ts +56 -0
- package/dist/client/composer/useRealtimeVoiceMode.d.ts.map +1 -0
- package/dist/client/composer/useRealtimeVoiceMode.js +492 -0
- package/dist/client/composer/useRealtimeVoiceMode.js.map +1 -0
- package/dist/client/guided-questions.d.ts.map +1 -1
- package/dist/client/guided-questions.js +7 -2
- package/dist/client/guided-questions.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/settings/DemoModeSection.d.ts.map +1 -1
- package/dist/client/settings/DemoModeSection.js +4 -3
- package/dist/client/settings/DemoModeSection.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +4 -0
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/SettingsTabsPage.d.ts +10 -3
- package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
- package/dist/client/settings/SettingsTabsPage.js +49 -11
- package/dist/client/settings/SettingsTabsPage.js.map +1 -1
- package/dist/client/use-chat-models.d.ts.map +1 -1
- package/dist/client/use-chat-models.js +6 -14
- package/dist/client/use-chat-models.js.map +1 -1
- package/dist/client/use-db-sync.d.ts.map +1 -1
- package/dist/client/use-db-sync.js +87 -7
- package/dist/client/use-db-sync.js.map +1 -1
- package/dist/code-agents/background-controller.d.ts +1 -1
- package/dist/code-agents/background-controller.d.ts.map +1 -1
- package/dist/code-agents/background-controller.js +17 -1
- package/dist/code-agents/background-controller.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/collab/ydoc-manager.d.ts +9 -1
- package/dist/collab/ydoc-manager.d.ts.map +1 -1
- package/dist/collab/ydoc-manager.js +30 -6
- package/dist/collab/ydoc-manager.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +4 -2
- package/dist/db/migrations.js.map +1 -1
- package/dist/demo/fetch-interceptor.d.ts +5 -1
- package/dist/demo/fetch-interceptor.d.ts.map +1 -1
- package/dist/demo/fetch-interceptor.js +16 -12
- package/dist/demo/fetch-interceptor.js.map +1 -1
- package/dist/integrations/adapters/slack.d.ts +2 -0
- package/dist/integrations/adapters/slack.d.ts.map +1 -1
- package/dist/integrations/adapters/slack.js +38 -2
- package/dist/integrations/adapters/slack.js.map +1 -1
- package/dist/integrations/awaiting-input-store.d.ts +27 -0
- package/dist/integrations/awaiting-input-store.d.ts.map +1 -0
- package/dist/integrations/awaiting-input-store.js +112 -0
- package/dist/integrations/awaiting-input-store.js.map +1 -0
- package/dist/integrations/computer-supervision-store.d.ts +65 -0
- package/dist/integrations/computer-supervision-store.d.ts.map +1 -0
- package/dist/integrations/computer-supervision-store.js +296 -0
- package/dist/integrations/computer-supervision-store.js.map +1 -0
- package/dist/integrations/computer-supervision.d.ts +11 -0
- package/dist/integrations/computer-supervision.d.ts.map +1 -0
- package/dist/integrations/computer-supervision.js +160 -0
- package/dist/integrations/computer-supervision.js.map +1 -0
- package/dist/integrations/index.d.ts +6 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +5 -2
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +205 -3
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/remote-commands-store.d.ts +15 -1
- package/dist/integrations/remote-commands-store.d.ts.map +1 -1
- package/dist/integrations/remote-commands-store.js +273 -3
- package/dist/integrations/remote-commands-store.js.map +1 -1
- package/dist/integrations/remote-devices-store.d.ts +4 -3
- package/dist/integrations/remote-devices-store.d.ts.map +1 -1
- package/dist/integrations/remote-devices-store.js +49 -2
- package/dist/integrations/remote-devices-store.js.map +1 -1
- package/dist/integrations/remote-json-safety.d.ts +6 -0
- package/dist/integrations/remote-json-safety.d.ts.map +1 -0
- package/dist/integrations/remote-json-safety.js +114 -0
- package/dist/integrations/remote-json-safety.js.map +1 -0
- package/dist/integrations/remote-run-events-store.d.ts +11 -1
- package/dist/integrations/remote-run-events-store.d.ts.map +1 -1
- package/dist/integrations/remote-run-events-store.js +85 -17
- package/dist/integrations/remote-run-events-store.js.map +1 -1
- package/dist/integrations/remote-types.d.ts +54 -3
- package/dist/integrations/remote-types.d.ts.map +1 -1
- package/dist/integrations/remote-types.js.map +1 -1
- package/dist/integrations/webhook-handler.d.ts.map +1 -1
- package/dist/integrations/webhook-handler.js +133 -4
- package/dist/integrations/webhook-handler.js.map +1 -1
- package/dist/localization/default-messages.d.ts +26 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +26 -0
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/mcp-client/config.d.ts.map +1 -1
- package/dist/mcp-client/config.js +44 -3
- package/dist/mcp-client/config.js.map +1 -1
- package/dist/mcp-client/index.d.ts +6 -1
- package/dist/mcp-client/index.d.ts.map +1 -1
- package/dist/mcp-client/index.js +11 -3
- package/dist/mcp-client/index.js.map +1 -1
- package/dist/mcp-client/tool-policy.d.ts +24 -0
- package/dist/mcp-client/tool-policy.d.ts.map +1 -0
- package/dist/mcp-client/tool-policy.js +139 -0
- package/dist/mcp-client/tool-policy.js.map +1 -0
- package/dist/observability/routes.d.ts +5 -5
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/secrets/register-framework-secrets.d.ts +3 -4
- package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
- package/dist/secrets/register-framework-secrets.js +25 -4
- package/dist/secrets/register-framework-secrets.js.map +1 -1
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +53 -6
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/realtime-voice.d.ts +53 -0
- package/dist/server/realtime-voice.d.ts.map +1 -0
- package/dist/server/realtime-voice.js +404 -0
- package/dist/server/realtime-voice.js.map +1 -0
- package/dist/shared/reasoning-effort.d.ts +20 -0
- package/dist/shared/reasoning-effort.d.ts.map +1 -1
- package/dist/shared/reasoning-effort.js +52 -18
- package/dist/shared/reasoning-effort.js.map +1 -1
- package/dist/styles/agent-conversation.css +17 -0
- package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
- package/docs/content/a2a-protocol.mdx +21 -5
- package/docs/content/actions.mdx +9 -23
- package/docs/content/agent-mentions.mdx +31 -29
- package/docs/content/agent-native-toolkit.mdx +15 -6
- package/docs/content/agent-surfaces.mdx +9 -13
- package/docs/content/agent-teams.mdx +1 -0
- package/docs/content/authentication.mdx +10 -3
- package/docs/content/automation-connectors.mdx +82 -39
- package/docs/content/automations.mdx +17 -3
- package/docs/content/blueprint-installer.mdx +11 -4
- package/docs/content/cli-adapters.mdx +9 -6
- package/docs/content/client.mdx +16 -0
- package/docs/content/cloneable-saas.mdx +14 -11
- package/docs/content/code-agents-ui.mdx +65 -0
- package/docs/content/components.mdx +30 -14
- package/docs/content/context-awareness.mdx +27 -15
- package/docs/content/creating-templates.mdx +15 -9
- package/docs/content/cross-app-sso.mdx +16 -6
- package/docs/content/data-programs.mdx +1 -1
- package/docs/content/database.mdx +17 -5
- package/docs/content/deployment.mdx +19 -18
- package/docs/content/dispatch.mdx +6 -2
- package/docs/content/drop-in-agent.mdx +10 -4
- package/docs/content/durable-background-runs.mdx +9 -5
- package/docs/content/durable-resume.mdx +9 -4
- package/docs/content/embedding-sdk.mdx +26 -8
- package/docs/content/evals.mdx +3 -5
- package/docs/content/extensions.mdx +22 -9
- package/docs/content/external-agents.mdx +25 -34
- package/docs/content/faq.mdx +8 -0
- package/docs/content/file-uploads.mdx +12 -3
- package/docs/content/frames.mdx +16 -0
- package/docs/content/generative-ui.mdx +1 -1
- package/docs/content/getting-started.mdx +34 -21
- package/docs/content/harness-agents.mdx +8 -4
- package/docs/content/human-approval.mdx +8 -3
- package/docs/content/internationalization.mdx +9 -4
- package/docs/content/key-concepts.mdx +13 -20
- package/docs/content/local-file-mode.mdx +14 -8
- package/docs/content/locales/ar-SA/actions.mdx +2 -2
- package/docs/content/locales/ar-SA/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/ar-SA/agent-surfaces.mdx +8 -10
- package/docs/content/locales/ar-SA/agent-teams.mdx +1 -0
- package/docs/content/locales/ar-SA/authentication.mdx +1 -1
- package/docs/content/locales/ar-SA/components.mdx +11 -1
- package/docs/content/locales/ar-SA/creating-templates.mdx +3 -7
- package/docs/content/locales/ar-SA/cross-app-sso.mdx +16 -6
- package/docs/content/locales/ar-SA/deployment.mdx +8 -0
- package/docs/content/locales/ar-SA/external-agents.mdx +2 -7
- package/docs/content/locales/ar-SA/key-concepts.mdx +13 -20
- package/docs/content/locales/ar-SA/multi-tenancy.mdx +5 -5
- package/docs/content/locales/ar-SA/notifications.mdx +18 -10
- package/docs/content/locales/ar-SA/processors.mdx +11 -5
- package/docs/content/locales/ar-SA/server.mdx +17 -10
- package/docs/content/locales/ar-SA/sharing.mdx +10 -10
- package/docs/content/locales/ar-SA/skills-guide.mdx +34 -17
- package/docs/content/locales/ar-SA/template-assets.mdx +16 -13
- package/docs/content/locales/ar-SA/template-brain.mdx +3 -1
- package/docs/content/locales/ar-SA/template-clips.mdx +3 -3
- package/docs/content/locales/ar-SA/template-design.mdx +3 -1
- package/docs/content/locales/ar-SA/template-dispatch.mdx +5 -1
- package/docs/content/locales/ar-SA/template-mail.mdx +8 -0
- package/docs/content/locales/ar-SA/tracking.mdx +9 -6
- package/docs/content/locales/ar-SA/using-your-agent.mdx +0 -7
- package/docs/content/locales/ar-SA/voice-input.mdx +6 -0
- package/docs/content/locales/ar-SA/workspace-connections.mdx +9 -2
- package/docs/content/locales/ar-SA/workspace.mdx +19 -18
- package/docs/content/locales/de-DE/actions.mdx +2 -2
- package/docs/content/locales/de-DE/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/de-DE/agent-surfaces.mdx +8 -10
- package/docs/content/locales/de-DE/agent-teams.mdx +1 -0
- package/docs/content/locales/de-DE/authentication.mdx +1 -1
- package/docs/content/locales/de-DE/components.mdx +11 -1
- package/docs/content/locales/de-DE/creating-templates.mdx +3 -7
- package/docs/content/locales/de-DE/cross-app-sso.mdx +16 -6
- package/docs/content/locales/de-DE/deployment.mdx +8 -0
- package/docs/content/locales/de-DE/external-agents.mdx +3 -7
- package/docs/content/locales/de-DE/key-concepts.mdx +13 -20
- package/docs/content/locales/de-DE/multi-tenancy.mdx +5 -5
- package/docs/content/locales/de-DE/notifications.mdx +18 -10
- package/docs/content/locales/de-DE/processors.mdx +11 -5
- package/docs/content/locales/de-DE/server.mdx +18 -10
- package/docs/content/locales/de-DE/sharing.mdx +10 -10
- package/docs/content/locales/de-DE/skills-guide.mdx +34 -17
- package/docs/content/locales/de-DE/template-assets.mdx +16 -13
- package/docs/content/locales/de-DE/template-brain.mdx +3 -1
- package/docs/content/locales/de-DE/template-clips.mdx +3 -3
- package/docs/content/locales/de-DE/template-design.mdx +3 -1
- package/docs/content/locales/de-DE/template-dispatch.mdx +5 -1
- package/docs/content/locales/de-DE/template-mail.mdx +8 -0
- package/docs/content/locales/de-DE/tracking.mdx +9 -6
- package/docs/content/locales/de-DE/using-your-agent.mdx +0 -7
- package/docs/content/locales/de-DE/voice-input.mdx +6 -0
- package/docs/content/locales/de-DE/workspace-connections.mdx +9 -2
- package/docs/content/locales/de-DE/workspace.mdx +19 -18
- package/docs/content/locales/es-ES/actions.mdx +2 -2
- package/docs/content/locales/es-ES/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/es-ES/agent-surfaces.mdx +8 -10
- package/docs/content/locales/es-ES/agent-teams.mdx +1 -0
- package/docs/content/locales/es-ES/authentication.mdx +1 -1
- package/docs/content/locales/es-ES/components.mdx +11 -1
- package/docs/content/locales/es-ES/creating-templates.mdx +3 -7
- package/docs/content/locales/es-ES/cross-app-sso.mdx +16 -6
- package/docs/content/locales/es-ES/deployment.mdx +8 -0
- package/docs/content/locales/es-ES/external-agents.mdx +3 -7
- package/docs/content/locales/es-ES/key-concepts.mdx +13 -20
- package/docs/content/locales/es-ES/multi-tenancy.mdx +5 -5
- package/docs/content/locales/es-ES/notifications.mdx +18 -10
- package/docs/content/locales/es-ES/processors.mdx +11 -5
- package/docs/content/locales/es-ES/server.mdx +17 -10
- package/docs/content/locales/es-ES/sharing.mdx +10 -10
- package/docs/content/locales/es-ES/skills-guide.mdx +34 -17
- package/docs/content/locales/es-ES/template-assets.mdx +16 -13
- package/docs/content/locales/es-ES/template-brain.mdx +3 -1
- package/docs/content/locales/es-ES/template-clips.mdx +3 -3
- package/docs/content/locales/es-ES/template-design.mdx +3 -1
- package/docs/content/locales/es-ES/template-dispatch.mdx +5 -1
- package/docs/content/locales/es-ES/template-mail.mdx +8 -0
- package/docs/content/locales/es-ES/tracking.mdx +9 -6
- package/docs/content/locales/es-ES/using-your-agent.mdx +0 -7
- package/docs/content/locales/es-ES/voice-input.mdx +6 -0
- package/docs/content/locales/es-ES/workspace-connections.mdx +9 -2
- package/docs/content/locales/es-ES/workspace.mdx +19 -18
- package/docs/content/locales/fr-FR/actions.mdx +2 -2
- package/docs/content/locales/fr-FR/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/fr-FR/agent-surfaces.mdx +8 -10
- package/docs/content/locales/fr-FR/agent-teams.mdx +1 -0
- package/docs/content/locales/fr-FR/authentication.mdx +1 -1
- package/docs/content/locales/fr-FR/components.mdx +11 -1
- package/docs/content/locales/fr-FR/creating-templates.mdx +3 -7
- package/docs/content/locales/fr-FR/cross-app-sso.mdx +16 -6
- package/docs/content/locales/fr-FR/deployment.mdx +8 -0
- package/docs/content/locales/fr-FR/external-agents.mdx +3 -7
- package/docs/content/locales/fr-FR/key-concepts.mdx +13 -20
- package/docs/content/locales/fr-FR/multi-tenancy.mdx +5 -5
- package/docs/content/locales/fr-FR/notifications.mdx +18 -10
- package/docs/content/locales/fr-FR/processors.mdx +11 -5
- package/docs/content/locales/fr-FR/server.mdx +17 -10
- package/docs/content/locales/fr-FR/sharing.mdx +10 -10
- package/docs/content/locales/fr-FR/skills-guide.mdx +34 -17
- package/docs/content/locales/fr-FR/template-assets.mdx +16 -13
- package/docs/content/locales/fr-FR/template-brain.mdx +3 -1
- package/docs/content/locales/fr-FR/template-clips.mdx +3 -3
- package/docs/content/locales/fr-FR/template-design.mdx +3 -1
- package/docs/content/locales/fr-FR/template-dispatch.mdx +5 -1
- package/docs/content/locales/fr-FR/template-mail.mdx +8 -0
- package/docs/content/locales/fr-FR/tracking.mdx +9 -6
- package/docs/content/locales/fr-FR/using-your-agent.mdx +0 -7
- package/docs/content/locales/fr-FR/voice-input.mdx +6 -0
- package/docs/content/locales/fr-FR/workspace-connections.mdx +9 -2
- package/docs/content/locales/fr-FR/workspace.mdx +19 -18
- package/docs/content/locales/hi-IN/actions.mdx +2 -2
- package/docs/content/locales/hi-IN/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/hi-IN/agent-surfaces.mdx +8 -10
- package/docs/content/locales/hi-IN/agent-teams.mdx +1 -0
- package/docs/content/locales/hi-IN/authentication.mdx +1 -1
- package/docs/content/locales/hi-IN/components.mdx +11 -1
- package/docs/content/locales/hi-IN/creating-templates.mdx +3 -7
- package/docs/content/locales/hi-IN/cross-app-sso.mdx +16 -6
- package/docs/content/locales/hi-IN/deployment.mdx +8 -0
- package/docs/content/locales/hi-IN/external-agents.mdx +2 -7
- package/docs/content/locales/hi-IN/key-concepts.mdx +13 -20
- package/docs/content/locales/hi-IN/multi-tenancy.mdx +5 -5
- package/docs/content/locales/hi-IN/notifications.mdx +18 -10
- package/docs/content/locales/hi-IN/processors.mdx +11 -5
- package/docs/content/locales/hi-IN/server.mdx +17 -10
- package/docs/content/locales/hi-IN/sharing.mdx +10 -10
- package/docs/content/locales/hi-IN/skills-guide.mdx +34 -17
- package/docs/content/locales/hi-IN/template-assets.mdx +16 -13
- package/docs/content/locales/hi-IN/template-brain.mdx +3 -1
- package/docs/content/locales/hi-IN/template-clips.mdx +3 -3
- package/docs/content/locales/hi-IN/template-design.mdx +3 -1
- package/docs/content/locales/hi-IN/template-dispatch.mdx +5 -1
- package/docs/content/locales/hi-IN/template-mail.mdx +8 -0
- package/docs/content/locales/hi-IN/tracking.mdx +9 -6
- package/docs/content/locales/hi-IN/using-your-agent.mdx +0 -7
- package/docs/content/locales/hi-IN/voice-input.mdx +6 -0
- package/docs/content/locales/hi-IN/workspace-connections.mdx +9 -2
- package/docs/content/locales/hi-IN/workspace.mdx +19 -18
- package/docs/content/locales/ja-JP/actions.mdx +2 -2
- package/docs/content/locales/ja-JP/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/ja-JP/agent-surfaces.mdx +8 -10
- package/docs/content/locales/ja-JP/agent-teams.mdx +1 -0
- package/docs/content/locales/ja-JP/authentication.mdx +1 -1
- package/docs/content/locales/ja-JP/components.mdx +11 -1
- package/docs/content/locales/ja-JP/creating-templates.mdx +3 -7
- package/docs/content/locales/ja-JP/cross-app-sso.mdx +16 -6
- package/docs/content/locales/ja-JP/deployment.mdx +8 -0
- package/docs/content/locales/ja-JP/external-agents.mdx +2 -7
- package/docs/content/locales/ja-JP/key-concepts.mdx +13 -20
- package/docs/content/locales/ja-JP/multi-tenancy.mdx +5 -5
- package/docs/content/locales/ja-JP/notifications.mdx +18 -10
- package/docs/content/locales/ja-JP/processors.mdx +11 -5
- package/docs/content/locales/ja-JP/server.mdx +17 -10
- package/docs/content/locales/ja-JP/sharing.mdx +10 -10
- package/docs/content/locales/ja-JP/skills-guide.mdx +34 -17
- package/docs/content/locales/ja-JP/template-assets.mdx +16 -13
- package/docs/content/locales/ja-JP/template-brain.mdx +3 -1
- package/docs/content/locales/ja-JP/template-clips.mdx +3 -4
- package/docs/content/locales/ja-JP/template-design.mdx +3 -1
- package/docs/content/locales/ja-JP/template-dispatch.mdx +5 -1
- package/docs/content/locales/ja-JP/template-mail.mdx +8 -0
- package/docs/content/locales/ja-JP/tracking.mdx +9 -6
- package/docs/content/locales/ja-JP/using-your-agent.mdx +0 -7
- package/docs/content/locales/ja-JP/voice-input.mdx +6 -0
- package/docs/content/locales/ja-JP/workspace-connections.mdx +9 -2
- package/docs/content/locales/ja-JP/workspace.mdx +19 -18
- package/docs/content/locales/ko-KR/actions.mdx +2 -2
- package/docs/content/locales/ko-KR/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/ko-KR/agent-surfaces.mdx +8 -10
- package/docs/content/locales/ko-KR/agent-teams.mdx +1 -0
- package/docs/content/locales/ko-KR/authentication.mdx +1 -1
- package/docs/content/locales/ko-KR/components.mdx +11 -1
- package/docs/content/locales/ko-KR/creating-templates.mdx +3 -7
- package/docs/content/locales/ko-KR/cross-app-sso.mdx +16 -6
- package/docs/content/locales/ko-KR/deployment.mdx +8 -0
- package/docs/content/locales/ko-KR/external-agents.mdx +2 -7
- package/docs/content/locales/ko-KR/key-concepts.mdx +13 -20
- package/docs/content/locales/ko-KR/multi-tenancy.mdx +5 -5
- package/docs/content/locales/ko-KR/notifications.mdx +18 -10
- package/docs/content/locales/ko-KR/processors.mdx +11 -5
- package/docs/content/locales/ko-KR/server.mdx +17 -10
- package/docs/content/locales/ko-KR/sharing.mdx +10 -10
- package/docs/content/locales/ko-KR/skills-guide.mdx +34 -17
- package/docs/content/locales/ko-KR/template-assets.mdx +16 -13
- package/docs/content/locales/ko-KR/template-brain.mdx +3 -1
- package/docs/content/locales/ko-KR/template-clips.mdx +3 -4
- package/docs/content/locales/ko-KR/template-design.mdx +3 -1
- package/docs/content/locales/ko-KR/template-dispatch.mdx +5 -1
- package/docs/content/locales/ko-KR/template-mail.mdx +8 -0
- package/docs/content/locales/ko-KR/tracking.mdx +9 -6
- package/docs/content/locales/ko-KR/using-your-agent.mdx +0 -7
- package/docs/content/locales/ko-KR/voice-input.mdx +6 -0
- package/docs/content/locales/ko-KR/workspace-connections.mdx +9 -2
- package/docs/content/locales/ko-KR/workspace.mdx +19 -18
- package/docs/content/locales/pt-BR/actions.mdx +2 -2
- package/docs/content/locales/pt-BR/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/pt-BR/agent-surfaces.mdx +8 -10
- package/docs/content/locales/pt-BR/agent-teams.mdx +1 -0
- package/docs/content/locales/pt-BR/authentication.mdx +1 -1
- package/docs/content/locales/pt-BR/components.mdx +11 -1
- package/docs/content/locales/pt-BR/creating-templates.mdx +3 -7
- package/docs/content/locales/pt-BR/cross-app-sso.mdx +16 -6
- package/docs/content/locales/pt-BR/deployment.mdx +8 -0
- package/docs/content/locales/pt-BR/external-agents.mdx +3 -7
- package/docs/content/locales/pt-BR/key-concepts.mdx +13 -20
- package/docs/content/locales/pt-BR/multi-tenancy.mdx +5 -5
- package/docs/content/locales/pt-BR/notifications.mdx +18 -10
- package/docs/content/locales/pt-BR/processors.mdx +11 -5
- package/docs/content/locales/pt-BR/server.mdx +17 -10
- package/docs/content/locales/pt-BR/sharing.mdx +10 -10
- package/docs/content/locales/pt-BR/skills-guide.mdx +34 -17
- package/docs/content/locales/pt-BR/template-assets.mdx +16 -13
- package/docs/content/locales/pt-BR/template-brain.mdx +3 -1
- package/docs/content/locales/pt-BR/template-clips.mdx +3 -3
- package/docs/content/locales/pt-BR/template-design.mdx +3 -1
- package/docs/content/locales/pt-BR/template-dispatch.mdx +5 -1
- package/docs/content/locales/pt-BR/template-mail.mdx +8 -0
- package/docs/content/locales/pt-BR/tracking.mdx +9 -6
- package/docs/content/locales/pt-BR/using-your-agent.mdx +0 -7
- package/docs/content/locales/pt-BR/voice-input.mdx +6 -0
- package/docs/content/locales/pt-BR/workspace-connections.mdx +9 -2
- package/docs/content/locales/pt-BR/workspace.mdx +19 -18
- package/docs/content/locales/zh-CN/actions.mdx +2 -2
- package/docs/content/locales/zh-CN/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/zh-CN/agent-surfaces.mdx +8 -10
- package/docs/content/locales/zh-CN/agent-teams.mdx +1 -0
- package/docs/content/locales/zh-CN/authentication.mdx +1 -1
- package/docs/content/locales/zh-CN/components.mdx +11 -1
- package/docs/content/locales/zh-CN/creating-templates.mdx +3 -7
- package/docs/content/locales/zh-CN/cross-app-sso.mdx +16 -6
- package/docs/content/locales/zh-CN/deployment.mdx +8 -0
- package/docs/content/locales/zh-CN/external-agents.mdx +2 -7
- package/docs/content/locales/zh-CN/key-concepts.mdx +13 -20
- package/docs/content/locales/zh-CN/multi-tenancy.mdx +5 -5
- package/docs/content/locales/zh-CN/notifications.mdx +18 -10
- package/docs/content/locales/zh-CN/processors.mdx +11 -5
- package/docs/content/locales/zh-CN/server.mdx +16 -10
- package/docs/content/locales/zh-CN/sharing.mdx +10 -10
- package/docs/content/locales/zh-CN/skills-guide.mdx +34 -17
- package/docs/content/locales/zh-CN/template-assets.mdx +16 -13
- package/docs/content/locales/zh-CN/template-brain.mdx +3 -1
- package/docs/content/locales/zh-CN/template-clips.mdx +3 -4
- package/docs/content/locales/zh-CN/template-design.mdx +3 -1
- package/docs/content/locales/zh-CN/template-dispatch.mdx +5 -1
- package/docs/content/locales/zh-CN/template-mail.mdx +8 -0
- package/docs/content/locales/zh-CN/tracking.mdx +9 -6
- package/docs/content/locales/zh-CN/using-your-agent.mdx +0 -7
- package/docs/content/locales/zh-CN/voice-input.mdx +6 -0
- package/docs/content/locales/zh-CN/workspace-connections.mdx +9 -2
- package/docs/content/locales/zh-CN/workspace.mdx +19 -18
- package/docs/content/locales/zh-TW/actions.mdx +2 -2
- package/docs/content/locales/zh-TW/agent-native-toolkit.mdx +2 -2
- package/docs/content/locales/zh-TW/agent-surfaces.mdx +8 -10
- package/docs/content/locales/zh-TW/agent-teams.mdx +1 -0
- package/docs/content/locales/zh-TW/authentication.mdx +1 -1
- package/docs/content/locales/zh-TW/components.mdx +11 -1
- package/docs/content/locales/zh-TW/creating-templates.mdx +3 -7
- package/docs/content/locales/zh-TW/cross-app-sso.mdx +16 -6
- package/docs/content/locales/zh-TW/deployment.mdx +8 -0
- package/docs/content/locales/zh-TW/external-agents.mdx +2 -7
- package/docs/content/locales/zh-TW/key-concepts.mdx +13 -20
- package/docs/content/locales/zh-TW/multi-tenancy.mdx +5 -5
- package/docs/content/locales/zh-TW/notifications.mdx +18 -10
- package/docs/content/locales/zh-TW/processors.mdx +11 -5
- package/docs/content/locales/zh-TW/server.mdx +16 -10
- package/docs/content/locales/zh-TW/sharing.mdx +10 -10
- package/docs/content/locales/zh-TW/skills-guide.mdx +34 -17
- package/docs/content/locales/zh-TW/template-assets.mdx +16 -13
- package/docs/content/locales/zh-TW/template-brain.mdx +3 -1
- package/docs/content/locales/zh-TW/template-clips.mdx +3 -4
- package/docs/content/locales/zh-TW/template-design.mdx +3 -1
- package/docs/content/locales/zh-TW/template-dispatch.mdx +5 -1
- package/docs/content/locales/zh-TW/template-mail.mdx +8 -0
- package/docs/content/locales/zh-TW/tracking.mdx +9 -6
- package/docs/content/locales/zh-TW/using-your-agent.mdx +0 -7
- package/docs/content/locales/zh-TW/voice-input.mdx +6 -0
- package/docs/content/locales/zh-TW/workspace-connections.mdx +9 -2
- package/docs/content/locales/zh-TW/workspace.mdx +19 -18
- package/docs/content/mcp-apps.mdx +14 -32
- package/docs/content/mcp-clients.mdx +48 -54
- package/docs/content/mcp-protocol.mdx +25 -10
- package/docs/content/messaging.mdx +19 -11
- package/docs/content/multi-app-workspace.mdx +11 -96
- package/docs/content/multi-tenancy.mdx +5 -5
- package/docs/content/native-chat-ui.mdx +4 -4
- package/docs/content/notifications.mdx +19 -12
- package/docs/content/observability.mdx +2 -4
- package/docs/content/observational-memory.mdx +7 -3
- package/docs/content/onboarding.mdx +9 -2
- package/docs/content/plan-plugin.mdx +10 -2
- package/docs/content/pr-visual-recap.mdx +1 -1
- package/docs/content/processors.mdx +11 -5
- package/docs/content/pure-agent-apps.mdx +5 -1
- package/docs/content/real-time-collaboration.mdx +30 -67
- package/docs/content/recurring-jobs.mdx +8 -6
- package/docs/content/routing.mdx +3 -4
- package/docs/content/sandbox-adapters.mdx +30 -53
- package/docs/content/security.mdx +8 -0
- package/docs/content/server.mdx +17 -10
- package/docs/content/sharing.mdx +10 -10
- package/docs/content/skills-guide.mdx +35 -16
- package/docs/content/template-analytics.mdx +11 -8
- package/docs/content/template-assets.mdx +16 -13
- package/docs/content/template-brain.mdx +3 -1
- package/docs/content/template-calendar.mdx +12 -4
- package/docs/content/template-chat.mdx +4 -4
- package/docs/content/template-clips.mdx +3 -3
- package/docs/content/template-content.mdx +23 -18
- package/docs/content/template-design.mdx +3 -1
- package/docs/content/template-dispatch.mdx +5 -1
- package/docs/content/template-mail.mdx +14 -2
- package/docs/content/template-plan.mdx +22 -15
- package/docs/content/template-slides.mdx +11 -3
- package/docs/content/toolkit-agent-ux.mdx +46 -3
- package/docs/content/toolkit-collaboration.mdx +58 -4
- package/docs/content/toolkit-command-navigation.mdx +8 -2
- package/docs/content/toolkit-comments-review.mdx +10 -2
- package/docs/content/toolkit-history.mdx +8 -3
- package/docs/content/toolkit-observability.mdx +48 -2
- package/docs/content/toolkit-org-team.mdx +8 -2
- package/docs/content/toolkit-resources.mdx +45 -2
- package/docs/content/toolkit-settings.mdx +8 -2
- package/docs/content/toolkit-setup-connections.mdx +7 -2
- package/docs/content/toolkit-sharing.mdx +46 -3
- package/docs/content/toolkit-ui.mdx +82 -11
- package/docs/content/tracking.mdx +10 -8
- package/docs/content/using-your-agent.mdx +0 -12
- package/docs/content/voice-input.mdx +7 -1
- package/docs/content/what-is-agent-native.mdx +7 -8
- package/docs/content/workspace-connections.mdx +16 -23
- package/docs/content/workspace-management.mdx +16 -4
- package/docs/content/workspace.mdx +19 -18
- package/package.json +1 -1
- package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
- package/corpus/core/docs/content/locales/ar-SA/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/de-DE/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/es-ES/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/fr-FR/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/hi-IN/migration-workbench.mdx +0 -74
- package/corpus/core/docs/content/locales/ja-JP/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/ko-KR/migration-workbench.mdx +0 -74
- package/corpus/core/docs/content/locales/pt-BR/migration-workbench.mdx +0 -76
- package/corpus/core/docs/content/locales/zh-CN/migration-workbench.mdx +0 -74
- package/corpus/core/docs/content/locales/zh-TW/migration-workbench.mdx +0 -74
- package/corpus/core/docs/content/migration-workbench.mdx +0 -74
- package/corpus/core/docs/content/toolkit-app-adapters.mdx +0 -55
- package/corpus/core/docs/content/toolkit-collaboration-ui.mdx +0 -60
- package/corpus/core/docs/content/toolkit-sharing-ui.mdx +0 -45
- package/corpus/core/docs/content/toolkit-shell-hooks.mdx +0 -36
- package/docs/content/locales/ar-SA/migration-workbench.mdx +0 -76
- package/docs/content/locales/de-DE/migration-workbench.mdx +0 -76
- package/docs/content/locales/es-ES/migration-workbench.mdx +0 -76
- package/docs/content/locales/fr-FR/migration-workbench.mdx +0 -76
- package/docs/content/locales/hi-IN/migration-workbench.mdx +0 -74
- package/docs/content/locales/ja-JP/migration-workbench.mdx +0 -76
- package/docs/content/locales/ko-KR/migration-workbench.mdx +0 -74
- package/docs/content/locales/pt-BR/migration-workbench.mdx +0 -76
- package/docs/content/locales/zh-CN/migration-workbench.mdx +0 -74
- package/docs/content/locales/zh-TW/migration-workbench.mdx +0 -74
- package/docs/content/migration-workbench.mdx +0 -74
- package/docs/content/toolkit-app-adapters.mdx +0 -55
- package/docs/content/toolkit-collaboration-ui.mdx +0 -60
- package/docs/content/toolkit-sharing-ui.mdx +0 -45
- package/docs/content/toolkit-shell-hooks.mdx +0 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-controller.js","sourceRoot":"","sources":["../../src/code-agents/background-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,G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,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK;QACL,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,kBAAkB,KAAK,EAAE;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import {\n executeExistingCodeAgentRun,\n executePendingCodeAgentApproval,\n} from \"../cli/code-agent-executor.js\";\nimport {\n appendCodeAgentTranscriptEvent,\n getCodeAgentRunRecord,\n isActiveCodeAgentRun,\n queueCodeAgentFollowUp,\n updateCodeAgentRunRecord,\n type CodeAgentFollowUpMode,\n type CodeAgentPermissionMode,\n} from \"../cli/code-agent-runs.js\";\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport {\n getBackgroundAgentRun,\n listBackgroundAgentRuns,\n listBackgroundAgentTranscriptEvents,\n toBackgroundAgentRun,\n type BackgroundAgentRun,\n type BackgroundAgentTranscriptEvent,\n type ListBackgroundAgentRunsOptions,\n} from \"./background-run.js\";\nimport type { AgentPromptAttachment } from \"./prompt-attachments.js\";\n\nexport type BackgroundAgentControlCommand =\n | \"approve\"\n | \"resume\"\n | \"retry\"\n | \"stop\";\n\nexport interface BackgroundAgentControlInput {\n runId: string;\n command: BackgroundAgentControlCommand;\n stdout?: NodeJS.WritableStream;\n}\n\nexport interface BackgroundAgentFollowUpInput {\n runId: string;\n prompt: string;\n mode?: CodeAgentFollowUpMode;\n permissionMode?: CodeAgentPermissionMode;\n model?: string;\n reasoningEffort?: ReasoningEffort;\n source?: string;\n metadata?: Record<string, unknown>;\n stdout?: NodeJS.WritableStream;\n}\n\nexport interface BackgroundAgentControlResult {\n ok: boolean;\n runId: string;\n run: BackgroundAgentRun | null;\n queued?: boolean;\n message?: string;\n error?: string;\n}\n\nexport interface BackgroundAgentController {\n list(\n options?: ListBackgroundAgentRunsOptions,\n ): Promise<BackgroundAgentRun[]> | BackgroundAgentRun[];\n get(\n runId: string,\n ): Promise<BackgroundAgentRun | null> | BackgroundAgentRun | null;\n transcript(\n runId: string,\n ):\n | Promise<BackgroundAgentTranscriptEvent[]>\n | BackgroundAgentTranscriptEvent[];\n sendFollowUp(\n input: BackgroundAgentFollowUpInput,\n ): Promise<BackgroundAgentControlResult>;\n control(\n input: BackgroundAgentControlInput,\n ): Promise<BackgroundAgentControlResult>;\n}\n\nexport function createCompositeBackgroundAgentController(\n controllers: BackgroundAgentController[],\n): BackgroundAgentController {\n const resolveControllerForRun = async (\n runId: string,\n ): Promise<{\n controller: BackgroundAgentController;\n run: BackgroundAgentRun;\n } | null> => {\n for (const controller of controllers) {\n const run = await Promise.resolve(controller.get(runId));\n if (run) return { controller, run };\n }\n return null;\n };\n\n return {\n async list(options?: ListBackgroundAgentRunsOptions) {\n const groups = await Promise.all(\n controllers.map((controller) =>\n Promise.resolve(controller.list(options)).catch(() => []),\n ),\n );\n return groups\n .flat()\n .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));\n },\n async get(runId: string) {\n return (await resolveControllerForRun(runId))?.run ?? null;\n },\n async transcript(runId: string) {\n const match = await resolveControllerForRun(runId);\n if (!match) return [];\n return Promise.resolve(match.controller.transcript(runId));\n },\n async sendFollowUp(input: BackgroundAgentFollowUpInput) {\n const match = await resolveControllerForRun(input.runId);\n if (!match) return missingRunResult(input.runId);\n return match.controller.sendFollowUp(input);\n },\n async control(input: BackgroundAgentControlInput) {\n const match = await resolveControllerForRun(input.runId);\n if (!match) return missingRunResult(input.runId);\n return match.controller.control(input);\n },\n };\n}\n\nexport function createLocalCodeBackgroundAgentController(): BackgroundAgentController {\n return {\n list: listBackgroundAgentRuns,\n get: getBackgroundAgentRun,\n transcript: listBackgroundAgentTranscriptEvents,\n sendFollowUp: sendLocalCodeBackgroundAgentFollowUp,\n control: controlLocalCodeBackgroundAgentRun,\n };\n}\n\nexport const localCodeBackgroundAgentController =\n createLocalCodeBackgroundAgentController();\n\nasync function sendLocalCodeBackgroundAgentFollowUp(\n input: BackgroundAgentFollowUpInput,\n): Promise<BackgroundAgentControlResult> {\n const run = getCodeAgentRunRecord(input.runId);\n if (!run) {\n return missingRunResult(input.runId);\n }\n\n const prompt = input.prompt.trim();\n if (!prompt) {\n return {\n ok: false,\n runId: input.runId,\n run: toBackgroundAgentRun(run),\n error: \"Follow-up prompt is required.\",\n };\n }\n\n const activeRun = input.permissionMode\n ? (updateCodeAgentRunRecord(run.id, {\n permissionMode: input.permissionMode,\n }) ?? run)\n : run;\n const mode = input.mode ?? \"immediate\";\n const shouldQueue =\n activeRun.status === \"queued\" || isActiveCodeAgentRun(activeRun);\n const event = appendCodeAgentTranscriptEvent({\n runId: activeRun.id,\n kind: \"user\",\n message: prompt,\n metadata: {\n ...(input.metadata ?? {}),\n source: input.source ?? \"background-agent-controller\",\n permissionMode: input.permissionMode,\n followUpMode: mode,\n delivery: shouldQueue ? mode : \"run-now\",\n },\n });\n const attachments = promptAttachmentsFromMetadata(\n input.metadata?.attachments,\n );\n\n if (shouldQueue) {\n queueCodeAgentFollowUp({\n runId: activeRun.id,\n prompt,\n mode,\n eventId: event.id,\n permissionMode: input.permissionMode,\n source: input.source ?? \"background-agent-controller\",\n createdAt: event.createdAt,\n attachments,\n });\n return {\n ok: true,\n runId: activeRun.id,\n run: currentBackgroundRun(activeRun.id),\n queued: true,\n message: \"Follow-up queued for the active Agent-Native Code run.\",\n };\n }\n\n const updated = await executeExistingCodeAgentRun(activeRun.id, {\n prompt,\n appendUserEvent: false,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n attachments,\n stdout: input.stdout,\n });\n return {\n ok: Boolean(updated),\n runId: activeRun.id,\n run: updated\n ? toBackgroundAgentRun(updated)\n : currentBackgroundRun(activeRun.id),\n queued: false,\n message: updated\n ? \"Follow-up executed for the Agent-Native Code run.\"\n : undefined,\n error: updated ? undefined : `Run not found: ${activeRun.id}`,\n };\n}\n\nasync function controlLocalCodeBackgroundAgentRun(\n input: BackgroundAgentControlInput,\n): Promise<BackgroundAgentControlResult> {\n const run = getCodeAgentRunRecord(input.runId);\n if (!run) {\n return missingRunResult(input.runId);\n }\n\n switch (input.command) {\n case \"approve\": {\n const approved = await executePendingCodeAgentApproval(run.id, {\n stdout: input.stdout,\n });\n return {\n ok: Boolean(approved),\n runId: run.id,\n run: approved\n ? toBackgroundAgentRun(approved)\n : currentBackgroundRun(run.id),\n message: approved\n ? \"Pending approval executed for the Agent-Native Code run.\"\n : undefined,\n error: approved ? undefined : `Run not found: ${run.id}`,\n };\n }\n case \"resume\":\n case \"retry\": {\n // A control action must return immediately — awaiting\n // executeExistingCodeAgentRun() runs the entire code session\n // (potentially minutes), which times out the HTTP/IPC caller.\n // Kick the run off in the background; progress is surfaced via the\n // transcript/poll, exactly like the initial run start.\n void executeExistingCodeAgentRun(run.id, {\n stdout: input.stdout,\n }).catch((err) => {\n appendCodeAgentTranscriptEvent({\n runId: run.id,\n kind: \"status\",\n message: `Background ${input.command} failed: ${\n err instanceof Error ? err.message : String(err)\n }`,\n metadata: {\n source: \"background-agent-controller\",\n command: input.command,\n failed: true,\n },\n });\n });\n return {\n ok: true,\n runId: run.id,\n run: currentBackgroundRun(run.id),\n message:\n input.command === \"resume\"\n ? \"Agent-Native Code run resuming in the background.\"\n : \"Agent-Native Code run retrying in the background.\",\n };\n }\n case \"stop\":\n return stopLocalCodeBackgroundAgentRun(run.id);\n default: {\n const exhaustive: never = input.command;\n return {\n ok: false,\n runId: run.id,\n run: currentBackgroundRun(run.id),\n error: `Unsupported control command: ${String(exhaustive)}`,\n };\n }\n }\n}\n\nfunction stopLocalCodeBackgroundAgentRun(\n runId: string,\n): BackgroundAgentControlResult {\n const run = getCodeAgentRunRecord(runId);\n if (!run) {\n return missingRunResult(runId);\n }\n\n if (run.status === \"completed\" || run.status === \"errored\") {\n return {\n ok: true,\n runId,\n run: toBackgroundAgentRun(run),\n message: \"Agent-Native Code run is already finished.\",\n };\n }\n\n appendCodeAgentTranscriptEvent({\n runId,\n kind: \"status\",\n message:\n \"Stop requested for Agent-Native Code run. No process signal was sent.\",\n metadata: {\n source: \"background-agent-controller\",\n stoppedWithoutSignal: true,\n },\n });\n const updated = updateCodeAgentRunRecord(runId, {\n status: \"paused\",\n phase: \"stopped\",\n progress: {\n label: \"Stopped\",\n completed: 0,\n total: 1,\n percent: 0,\n },\n metadata: {\n runnerState: \"stopped\",\n stoppedAt: new Date().toISOString(),\n stoppedBy: \"background-agent-controller\",\n stopSignalSent: false,\n },\n });\n\n return {\n ok: Boolean(updated),\n runId,\n run: updated ? toBackgroundAgentRun(updated) : null,\n message: updated\n ? \"Agent-Native Code run marked stopped without signaling a process.\"\n : undefined,\n error: updated ? undefined : `Run not found: ${runId}`,\n };\n}\n\nfunction promptAttachmentsFromMetadata(\n value: unknown,\n): AgentPromptAttachment[] {\n if (!Array.isArray(value)) return [];\n return value\n .filter((item): item is Record<string, unknown> =>\n Boolean(item && typeof item === \"object\" && !Array.isArray(item)),\n )\n .map((item) => ({\n name: typeof item.name === \"string\" && item.name ? item.name : \"file\",\n ...(typeof item.type === \"string\" ? { type: item.type } : {}),\n ...(typeof item.size === \"number\" ? { size: item.size } : {}),\n ...(typeof item.text === \"string\" ? { text: item.text } : {}),\n ...(typeof item.dataUrl === \"string\" ? { dataUrl: item.dataUrl } : {}),\n }));\n}\n\nfunction currentBackgroundRun(runId: string): BackgroundAgentRun | null {\n const run = getCodeAgentRunRecord(runId);\n return run ? toBackgroundAgentRun(run) : null;\n}\n\nfunction missingRunResult(runId: string): BackgroundAgentControlResult {\n return {\n ok: false,\n runId,\n run: null,\n error: `Run not found: ${runId}`,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"background-controller.js","sourceRoot":"","sources":["../../src/code-agents/background-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,GAGzB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,mCAAmC,EACnC,oBAAoB,GAIrB,MAAM,qBAAqB,CAAC;AAyD7B,MAAM,UAAU,wCAAwC,CACtD,WAAwC;IAExC,MAAM,uBAAuB,GAAG,KAAK,EACnC,KAAa,EAIL,EAAE;QACV,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACzD,IAAI,GAAG;gBAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;I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C,IAAI,CAAC,CAAC,CAAC,MAAM;QACrE,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK;QACL,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,kBAAkB,KAAK,EAAE;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import {\n executeDenyCodeAgentApproval,\n executeExistingCodeAgentRun,\n executePendingCodeAgentApproval,\n} from \"../cli/code-agent-executor.js\";\nimport {\n appendCodeAgentTranscriptEvent,\n getCodeAgentRunRecord,\n isActiveCodeAgentRun,\n queueCodeAgentFollowUp,\n updateCodeAgentRunRecord,\n type CodeAgentFollowUpMode,\n type CodeAgentPermissionMode,\n} from \"../cli/code-agent-runs.js\";\nimport type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport {\n getBackgroundAgentRun,\n listBackgroundAgentRuns,\n listBackgroundAgentTranscriptEvents,\n toBackgroundAgentRun,\n type BackgroundAgentRun,\n type BackgroundAgentTranscriptEvent,\n type ListBackgroundAgentRunsOptions,\n} from \"./background-run.js\";\nimport type { AgentPromptAttachment } from \"./prompt-attachments.js\";\n\nexport type BackgroundAgentControlCommand =\n | \"approve\"\n | \"deny\"\n | \"resume\"\n | \"retry\"\n | \"stop\";\n\nexport interface BackgroundAgentControlInput {\n runId: string;\n command: BackgroundAgentControlCommand;\n stdout?: NodeJS.WritableStream;\n}\n\nexport interface BackgroundAgentFollowUpInput {\n runId: string;\n prompt: string;\n mode?: CodeAgentFollowUpMode;\n permissionMode?: CodeAgentPermissionMode;\n model?: string;\n reasoningEffort?: ReasoningEffort;\n source?: string;\n metadata?: Record<string, unknown>;\n stdout?: NodeJS.WritableStream;\n}\n\nexport interface BackgroundAgentControlResult {\n ok: boolean;\n runId: string;\n run: BackgroundAgentRun | null;\n queued?: boolean;\n message?: string;\n error?: string;\n}\n\nexport interface BackgroundAgentController {\n list(\n options?: ListBackgroundAgentRunsOptions,\n ): Promise<BackgroundAgentRun[]> | BackgroundAgentRun[];\n get(\n runId: string,\n ): Promise<BackgroundAgentRun | null> | BackgroundAgentRun | null;\n transcript(\n runId: string,\n ):\n | Promise<BackgroundAgentTranscriptEvent[]>\n | BackgroundAgentTranscriptEvent[];\n sendFollowUp(\n input: BackgroundAgentFollowUpInput,\n ): Promise<BackgroundAgentControlResult>;\n control(\n input: BackgroundAgentControlInput,\n ): Promise<BackgroundAgentControlResult>;\n}\n\nexport function createCompositeBackgroundAgentController(\n controllers: BackgroundAgentController[],\n): BackgroundAgentController {\n const resolveControllerForRun = async (\n runId: string,\n ): Promise<{\n controller: BackgroundAgentController;\n run: BackgroundAgentRun;\n } | null> => {\n for (const controller of controllers) {\n const run = await Promise.resolve(controller.get(runId));\n if (run) return { controller, run };\n }\n return null;\n };\n\n return {\n async list(options?: ListBackgroundAgentRunsOptions) {\n const groups = await Promise.all(\n controllers.map((controller) =>\n Promise.resolve(controller.list(options)).catch(() => []),\n ),\n );\n return groups\n .flat()\n .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));\n },\n async get(runId: string) {\n return (await resolveControllerForRun(runId))?.run ?? null;\n },\n async transcript(runId: string) {\n const match = await resolveControllerForRun(runId);\n if (!match) return [];\n return Promise.resolve(match.controller.transcript(runId));\n },\n async sendFollowUp(input: BackgroundAgentFollowUpInput) {\n const match = await resolveControllerForRun(input.runId);\n if (!match) return missingRunResult(input.runId);\n return match.controller.sendFollowUp(input);\n },\n async control(input: BackgroundAgentControlInput) {\n const match = await resolveControllerForRun(input.runId);\n if (!match) return missingRunResult(input.runId);\n return match.controller.control(input);\n },\n };\n}\n\nexport function createLocalCodeBackgroundAgentController(): BackgroundAgentController {\n return {\n list: listBackgroundAgentRuns,\n get: getBackgroundAgentRun,\n transcript: listBackgroundAgentTranscriptEvents,\n sendFollowUp: sendLocalCodeBackgroundAgentFollowUp,\n control: controlLocalCodeBackgroundAgentRun,\n };\n}\n\nexport const localCodeBackgroundAgentController =\n createLocalCodeBackgroundAgentController();\n\nasync function sendLocalCodeBackgroundAgentFollowUp(\n input: BackgroundAgentFollowUpInput,\n): Promise<BackgroundAgentControlResult> {\n const run = getCodeAgentRunRecord(input.runId);\n if (!run) {\n return missingRunResult(input.runId);\n }\n\n const prompt = input.prompt.trim();\n if (!prompt) {\n return {\n ok: false,\n runId: input.runId,\n run: toBackgroundAgentRun(run),\n error: \"Follow-up prompt is required.\",\n };\n }\n\n const activeRun = input.permissionMode\n ? (updateCodeAgentRunRecord(run.id, {\n permissionMode: input.permissionMode,\n }) ?? run)\n : run;\n const mode = input.mode ?? \"immediate\";\n const shouldQueue =\n activeRun.status === \"queued\" || isActiveCodeAgentRun(activeRun);\n const event = appendCodeAgentTranscriptEvent({\n runId: activeRun.id,\n kind: \"user\",\n message: prompt,\n metadata: {\n ...(input.metadata ?? {}),\n source: input.source ?? \"background-agent-controller\",\n permissionMode: input.permissionMode,\n followUpMode: mode,\n delivery: shouldQueue ? mode : \"run-now\",\n },\n });\n const attachments = promptAttachmentsFromMetadata(\n input.metadata?.attachments,\n );\n\n if (shouldQueue) {\n queueCodeAgentFollowUp({\n runId: activeRun.id,\n prompt,\n mode,\n eventId: event.id,\n permissionMode: input.permissionMode,\n source: input.source ?? \"background-agent-controller\",\n createdAt: event.createdAt,\n attachments,\n });\n return {\n ok: true,\n runId: activeRun.id,\n run: currentBackgroundRun(activeRun.id),\n queued: true,\n message: \"Follow-up queued for the active Agent-Native Code run.\",\n };\n }\n\n const updated = await executeExistingCodeAgentRun(activeRun.id, {\n prompt,\n appendUserEvent: false,\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n attachments,\n stdout: input.stdout,\n });\n return {\n ok: Boolean(updated),\n runId: activeRun.id,\n run: updated\n ? toBackgroundAgentRun(updated)\n : currentBackgroundRun(activeRun.id),\n queued: false,\n message: updated\n ? \"Follow-up executed for the Agent-Native Code run.\"\n : undefined,\n error: updated ? undefined : `Run not found: ${activeRun.id}`,\n };\n}\n\nasync function controlLocalCodeBackgroundAgentRun(\n input: BackgroundAgentControlInput,\n): Promise<BackgroundAgentControlResult> {\n const run = getCodeAgentRunRecord(input.runId);\n if (!run) {\n return missingRunResult(input.runId);\n }\n\n switch (input.command) {\n case \"approve\": {\n const approved = await executePendingCodeAgentApproval(run.id, {\n stdout: input.stdout,\n });\n return {\n ok: Boolean(approved),\n runId: run.id,\n run: approved\n ? toBackgroundAgentRun(approved)\n : currentBackgroundRun(run.id),\n message: approved\n ? \"Pending approval executed for the Agent-Native Code run.\"\n : undefined,\n error: approved ? undefined : `Run not found: ${run.id}`,\n };\n }\n case \"deny\": {\n const denied = await executeDenyCodeAgentApproval(run.id, {\n stdout: input.stdout,\n });\n return {\n ok: Boolean(denied),\n runId: run.id,\n run: denied\n ? toBackgroundAgentRun(denied)\n : currentBackgroundRun(run.id),\n message: denied\n ? \"Pending approval denied for the Agent-Native Code run.\"\n : undefined,\n error: denied ? undefined : `Run not found: ${run.id}`,\n };\n }\n case \"resume\":\n case \"retry\": {\n // A control action must return immediately — awaiting\n // executeExistingCodeAgentRun() runs the entire code session\n // (potentially minutes), which times out the HTTP/IPC caller.\n // Kick the run off in the background; progress is surfaced via the\n // transcript/poll, exactly like the initial run start.\n void executeExistingCodeAgentRun(run.id, {\n stdout: input.stdout,\n }).catch((err) => {\n appendCodeAgentTranscriptEvent({\n runId: run.id,\n kind: \"status\",\n message: `Background ${input.command} failed: ${\n err instanceof Error ? err.message : String(err)\n }`,\n metadata: {\n source: \"background-agent-controller\",\n command: input.command,\n failed: true,\n },\n });\n });\n return {\n ok: true,\n runId: run.id,\n run: currentBackgroundRun(run.id),\n message:\n input.command === \"resume\"\n ? \"Agent-Native Code run resuming in the background.\"\n : \"Agent-Native Code run retrying in the background.\",\n };\n }\n case \"stop\":\n return stopLocalCodeBackgroundAgentRun(run.id);\n default: {\n const exhaustive: never = input.command;\n return {\n ok: false,\n runId: run.id,\n run: currentBackgroundRun(run.id),\n error: `Unsupported control command: ${String(exhaustive)}`,\n };\n }\n }\n}\n\nfunction stopLocalCodeBackgroundAgentRun(\n runId: string,\n): BackgroundAgentControlResult {\n const run = getCodeAgentRunRecord(runId);\n if (!run) {\n return missingRunResult(runId);\n }\n\n if (run.status === \"completed\" || run.status === \"errored\") {\n return {\n ok: true,\n runId,\n run: toBackgroundAgentRun(run),\n message: \"Agent-Native Code run is already finished.\",\n };\n }\n\n appendCodeAgentTranscriptEvent({\n runId,\n kind: \"status\",\n message:\n \"Stop requested for Agent-Native Code run. No process signal was sent.\",\n metadata: {\n source: \"background-agent-controller\",\n stoppedWithoutSignal: true,\n },\n });\n const updated = updateCodeAgentRunRecord(runId, {\n status: \"paused\",\n phase: \"stopped\",\n progress: {\n label: \"Stopped\",\n completed: 0,\n total: 1,\n percent: 0,\n },\n metadata: {\n runnerState: \"stopped\",\n stoppedAt: new Date().toISOString(),\n stoppedBy: \"background-agent-controller\",\n stopSignalSent: false,\n },\n });\n\n return {\n ok: Boolean(updated),\n runId,\n run: updated ? toBackgroundAgentRun(updated) : null,\n message: updated\n ? \"Agent-Native Code run marked stopped without signaling a process.\"\n : undefined,\n error: updated ? undefined : `Run not found: ${runId}`,\n };\n}\n\nfunction promptAttachmentsFromMetadata(\n value: unknown,\n): AgentPromptAttachment[] {\n if (!Array.isArray(value)) return [];\n return value\n .filter((item): item is Record<string, unknown> =>\n Boolean(item && typeof item === \"object\" && !Array.isArray(item)),\n )\n .map((item) => ({\n name: typeof item.name === \"string\" && item.name ? item.name : \"file\",\n ...(typeof item.type === \"string\" ? { type: item.type } : {}),\n ...(typeof item.size === \"number\" ? { size: item.size } : {}),\n ...(typeof item.text === \"string\" ? { text: item.text } : {}),\n ...(typeof item.dataUrl === \"string\" ? { dataUrl: item.dataUrl } : {}),\n }));\n}\n\nfunction currentBackgroundRun(runId: string): BackgroundAgentRun | null {\n const run = getCodeAgentRunRecord(runId);\n return run ? toBackgroundAgentRun(run) : null;\n}\n\nfunction missingRunResult(runId: string): BackgroundAgentControlResult {\n return {\n ok: false,\n runId,\n run: null,\n error: `Run not found: ${runId}`,\n };\n}\n"]}
|
package/dist/collab/routes.d.ts
CHANGED
|
@@ -26,8 +26,8 @@ export declare const getCollabState: import("h3").EventHandlerWithFetch<import("
|
|
|
26
26
|
* Body: { update: string (base64), requestSource?: string }
|
|
27
27
|
*/
|
|
28
28
|
export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
29
|
-
error: string;
|
|
30
29
|
ok?: undefined;
|
|
30
|
+
error: string;
|
|
31
31
|
} | {
|
|
32
32
|
error?: undefined;
|
|
33
33
|
ok: boolean;
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* Body: { json: any, fieldName?: string, type?: "map"|"array", requestSource?: string }
|
|
14
14
|
*/
|
|
15
15
|
export declare const postCollabJson: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
16
|
-
ok?: undefined;
|
|
17
16
|
error: string;
|
|
17
|
+
ok?: undefined;
|
|
18
18
|
} | {
|
|
19
19
|
error?: undefined;
|
|
20
20
|
ok: boolean;
|
|
@@ -41,7 +41,15 @@ export declare function applyUpdate(docId: string, update: Uint8Array, requestSo
|
|
|
41
41
|
*
|
|
42
42
|
* Returns the text snapshot after the update.
|
|
43
43
|
*/
|
|
44
|
-
export declare function applyText(docId: string, newText: string, fieldName?: string, requestSource?: string
|
|
44
|
+
export declare function applyText(docId: string, newText: string, fieldName?: string, requestSource?: string, options?: {
|
|
45
|
+
/**
|
|
46
|
+
* Validate the fully converged text after cross-process Yjs updates have
|
|
47
|
+
* merged, but before the state is persisted or broadcast. A rejected
|
|
48
|
+
* candidate is discarded from this process's cache so the next read
|
|
49
|
+
* reloads the last durable state instead of leaking an uncommitted merge.
|
|
50
|
+
*/
|
|
51
|
+
validateSnapshot?: (snapshot: string) => void;
|
|
52
|
+
}): Promise<string>;
|
|
45
53
|
/**
|
|
46
54
|
* Search-and-replace text within a Y.XmlFragment (ProseMirror tree).
|
|
47
55
|
* Produces minimal Yjs operations for cursor-preserving updates.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ydoc-manager.d.ts","sourceRoot":"","sources":["../../src/collab/ydoc-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAGzB,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,kBAAkB,CAAC;AAmC1B;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,E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
@@ -137,7 +137,7 @@ function buildStateToStore(doc, storedByteCount) {
|
|
|
137
137
|
* from OTHER processes. Within this process, the in-memory doc is already
|
|
138
138
|
* up-to-date because mutations are serialized by withDocWriteLock.
|
|
139
139
|
*/
|
|
140
|
-
async function persistMergedState(docId, doc, getTextSnapshot) {
|
|
140
|
+
async function persistMergedState(docId, doc, getTextSnapshot, validateTextSnapshot) {
|
|
141
141
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
142
142
|
// One DB read per persist attempt. On first attempt this is the only read
|
|
143
143
|
// on the write path (previously there was an unconditional second read
|
|
@@ -148,12 +148,16 @@ async function persistMergedState(docId, doc, getTextSnapshot) {
|
|
|
148
148
|
Y.applyUpdate(doc, latest.state);
|
|
149
149
|
}
|
|
150
150
|
const stateToStore = buildStateToStore(doc, latest?.state?.length ?? 0);
|
|
151
|
-
const
|
|
151
|
+
const textSnapshot = getTextSnapshot();
|
|
152
|
+
validateTextSnapshot?.(textSnapshot);
|
|
153
|
+
const saved = await trySaveYDocState(docId, stateToStore, textSnapshot, latest?.version ?? null);
|
|
152
154
|
if (saved)
|
|
153
155
|
return;
|
|
154
156
|
}
|
|
155
157
|
// All CAS attempts failed — fall back to unconditional save.
|
|
156
|
-
|
|
158
|
+
const textSnapshot = getTextSnapshot();
|
|
159
|
+
validateTextSnapshot?.(textSnapshot);
|
|
160
|
+
await saveYDocState(docId, Y.encodeStateAsUpdate(doc), textSnapshot);
|
|
157
161
|
}
|
|
158
162
|
/**
|
|
159
163
|
* Get or load a Yjs document by ID. Creates a new empty doc if none exists.
|
|
@@ -213,15 +217,35 @@ export async function applyUpdate(docId, update, requestSource) {
|
|
|
213
217
|
*
|
|
214
218
|
* Returns the text snapshot after the update.
|
|
215
219
|
*/
|
|
216
|
-
export async function applyText(docId, newText, fieldName = DEFAULT_FIELD, requestSource) {
|
|
220
|
+
export async function applyText(docId, newText, fieldName = DEFAULT_FIELD, requestSource, options = {}) {
|
|
217
221
|
return withDocWriteLock(docId, async () => {
|
|
218
222
|
const doc = await getDoc(docId);
|
|
219
223
|
const oldText = doc.getText(fieldName).toString();
|
|
220
224
|
const update = applyTextToYDoc(doc, fieldName, newText, "server");
|
|
221
225
|
if (update.length === 0) {
|
|
222
|
-
|
|
226
|
+
const snapshot = doc.getText(fieldName).toString();
|
|
227
|
+
try {
|
|
228
|
+
options.validateSnapshot?.(snapshot);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
releaseDoc(docId);
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
return snapshot;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
await persistMergedState(docId, doc, () => doc.getText(fieldName).toString(), options.validateSnapshot);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (options.validateSnapshot) {
|
|
241
|
+
// The target diff and any cross-process state merged during the CAS
|
|
242
|
+
// read now live only in this cached Y.Doc. Destroy it before throwing:
|
|
243
|
+
// neither the rejected update nor a compensating rollback should ever
|
|
244
|
+
// be persisted/emitted to connected clients.
|
|
245
|
+
releaseDoc(docId);
|
|
246
|
+
}
|
|
247
|
+
throw error;
|
|
223
248
|
}
|
|
224
|
-
await persistMergedState(docId, doc, () => doc.getText(fieldName).toString());
|
|
225
249
|
emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);
|
|
226
250
|
touchAgentPresence(docId, requestSource, {
|
|
227
251
|
descriptor: computeTextEditDescriptor(oldText, newText),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ydoc-manager.js","sourceRoot":"","sources":["../../src/collab/ydoc-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,aAAa,EACb,cAAc,EACd,UAAU,EACV,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAC1B,O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AAa,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,CAAC,iBAAiB;QAE9D,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/D,MAAM,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAExD,gBAAgB;QAChB,aAAa,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Server-side Yjs document manager with LRU caching and SQL persistence.\n *\n * Performance notes:\n * - `getDoc()` loads from the DB once on cache miss; subsequent calls return\n * the cached Y.Doc directly with no DB I/O.\n * - Mutations no longer call `applyStoredState()` unconditionally on every\n * write. The defensive re-read from the DB happens only inside\n * `persistMergedState` (needed for the CAS version read), not as a\n * separate SELECT before applying the new update. This removes the\n * redundant double-read that the previous implementation performed on\n * every write even on a hot cache.\n * - Compaction: when the stored blob is >4x the freshly encoded state, the\n * GC'd encoding is stored instead (removes accumulated Yjs tombstones,\n * preventing unbounded blob growth without any background jobs).\n */\n\nimport * as Y from \"yjs\";\n\nimport { emitCollabUpdate } from \"./emitter.js\";\nimport {\n applyJsonDiff,\n applyJsonPatch,\n yDocToJson,\n initYDocWithJson,\n type PatchOp,\n} from \"./json-to-yjs.js\";\nimport {\n loadYDocRecord,\n loadYDocState,\n saveYDocState,\n trySaveYDocState,\n} from \"./storage.js\";\nimport { uint8ArrayToBase64 } from \"./storage.js\";\nimport { applyTextToYDoc, initYDocWithText } from \"./text-to-yjs.js\";\nimport { searchAndReplaceInYXml, extractTextFromYXml } from \"./xml-ops.js\";\n\nconst DEFAULT_FIELD = \"content\";\nconst MAX_CACHE = 50;\n\n/**\n * Auto-presence: any agent-sourced write produces visible presence and\n * lingering edit attribution without the calling action having to wire\n * agentEnterDocument/agentLeaveDocument itself. Dynamic import avoids a\n * static cycle (agent-presence.ts imports searchAndReplace from this module).\n */\nfunction touchAgentPresence(\n docId: string,\n requestSource: string | undefined,\n edit: { descriptor: Record<string, unknown>; label?: string } | null,\n): void {\n if (requestSource !== \"agent\") return;\n import(\"./agent-presence.js\")\n .then((mod) => {\n mod.agentTouchDocument(docId, edit ? { edit: edit as any } : undefined);\n })\n .catch(() => {\n // Presence is best-effort; never fail the write for it.\n });\n}\n\n/**\n * Compute a small \"what changed\" descriptor from a text diff by trimming the\n * common prefix/suffix. Used for lingering edit highlights client-side.\n */\nexport function computeTextEditDescriptor(\n oldText: string,\n newText: string,\n): { kind: \"text\"; quote: string } | { kind: \"doc\" } {\n let start = 0;\n const maxStart = Math.min(oldText.length, newText.length);\n while (start < maxStart && oldText[start] === newText[start]) start++;\n\n let endOld = oldText.length;\n let endNew = newText.length;\n while (\n endOld > start &&\n endNew > start &&\n oldText[endOld - 1] === newText[endNew - 1]\n ) {\n endOld--;\n endNew--;\n }\n\n const inserted = newText.slice(start, endNew).trim();\n if (inserted.length > 0) {\n return { kind: \"text\", quote: inserted.slice(0, 120) };\n }\n return { kind: \"doc\" };\n}\n\n/**\n * Compaction ratio threshold. When the stored state byte count exceeds\n * COMPACTION_RATIO × the freshly encoded state, write the compact form\n * (strips accumulated tombstones). A value of 4 means: compact when the\n * stored blob is 4× larger than necessary.\n */\nconst COMPACTION_RATIO = 4;\n\ninterface CacheEntry {\n doc: Y.Doc;\n lastAccess: number;\n}\n\nconst _cache = new Map<string, CacheEntry>();\nconst _writeLocks = new Map<string, Promise<void>>();\n// Coalesces concurrent cache-miss loads for the same docId. Without this, two\n// simultaneous getDoc() callers both miss the cache, both build a Y.Doc and\n// apply stored state, and the second _cache.set silently orphans the first\n// doc (a memory leak that grows with concurrent read traffic).\nconst _loadLocks = new Map<string, Promise<Y.Doc>>();\n\nfunction evictIfNeeded(): void {\n if (_cache.size <= MAX_CACHE) return;\n // Evict least-recently-accessed entry\n let oldest: string | null = null;\n let oldestTime = Infinity;\n for (const [id, entry] of _cache) {\n if (entry.lastAccess < oldestTime) {\n oldestTime = entry.lastAccess;\n oldest = id;\n }\n }\n if (oldest) {\n const entry = _cache.get(oldest);\n entry?.doc.destroy();\n _cache.delete(oldest);\n }\n}\n\nasync function withDocWriteLock<T>(\n docId: string,\n fn: () => Promise<T>,\n): Promise<T> {\n const previous = _writeLocks.get(docId) ?? Promise.resolve();\n let release!: () => void;\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const chained = previous.catch(() => {}).then(() => current);\n _writeLocks.set(docId, chained);\n\n await previous.catch(() => {});\n try {\n return await fn();\n } finally {\n release();\n if (_writeLocks.get(docId) === chained) {\n _writeLocks.delete(docId);\n }\n }\n}\n\n/**\n * Build state to persist. If the stored blob is significantly larger than\n * the freshly encoded state, store the compact (GC'd) form instead to\n * prevent unbounded blob growth from accumulated tombstones.\n */\nfunction buildStateToStore(doc: Y.Doc, storedByteCount: number): Uint8Array {\n const encoded = Y.encodeStateAsUpdate(doc);\n if (\n storedByteCount > 0 &&\n storedByteCount > encoded.length * COMPACTION_RATIO\n ) {\n // Stored blob is much larger than needed — return the GC'd encoding.\n return encoded;\n }\n return encoded;\n}\n\n/**\n * Persist the merged doc state with CAS retry on conflict.\n *\n * REMOVED: the unconditional `applyStoredState()` that was called on every\n * write path before this function. The only DB read is the `loadYDocRecord`\n * call here — needed to get the CAS version and merge any concurrent writes\n * from OTHER processes. Within this process, the in-memory doc is already\n * up-to-date because mutations are serialized by withDocWriteLock.\n */\nasync function persistMergedState(\n docId: string,\n doc: Y.Doc,\n getTextSnapshot: () => string,\n): Promise<void> {\n for (let attempt = 0; attempt < 5; attempt++) {\n // One DB read per persist attempt. On first attempt this is the only read\n // on the write path (previously there was an unconditional second read\n // before the update was applied). On retry attempts it re-reads to get the\n // latest version after a CAS conflict.\n const latest = await loadYDocRecord(docId);\n if (latest?.state && latest.state.length > 0) {\n Y.applyUpdate(doc, latest.state);\n }\n\n const stateToStore = buildStateToStore(doc, latest?.state?.length ?? 0);\n const saved = await trySaveYDocState(\n docId,\n stateToStore,\n getTextSnapshot(),\n latest?.version ?? null,\n );\n if (saved) return;\n }\n\n // All CAS attempts failed — fall back to unconditional save.\n await saveYDocState(docId, Y.encodeStateAsUpdate(doc), getTextSnapshot());\n}\n\n/**\n * Get or load a Yjs document by ID. Creates a new empty doc if none exists.\n */\nexport async function getDoc(docId: string): Promise<Y.Doc> {\n const cached = _cache.get(docId);\n if (cached) {\n cached.lastAccess = Date.now();\n return cached.doc;\n }\n\n const inFlight = _loadLocks.get(docId);\n if (inFlight) return inFlight;\n\n const load = (async () => {\n // Re-check the cache: a concurrent writer (or loader) may have populated it\n // between our miss above and acquiring this load slot.\n const reCached = _cache.get(docId);\n if (reCached) {\n reCached.lastAccess = Date.now();\n return reCached.doc;\n }\n\n const doc = new Y.Doc();\n const stored = await loadYDocState(docId);\n if (stored && stored.length > 0) {\n Y.applyUpdate(doc, stored);\n }\n\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n return doc;\n })();\n\n _loadLocks.set(docId, load);\n try {\n return await load;\n } finally {\n _loadLocks.delete(docId);\n }\n}\n\n/**\n * Apply a binary Yjs update (from a client) to a document.\n * Persists the result and emits a change event.\n */\nexport async function applyUpdate(\n docId: string,\n update: Uint8Array,\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n // The cached doc is already up-to-date from the initial load or a previous\n // write in this process. No redundant applyStoredState() here — cross-\n // process writes are merged inside persistMergedState when needed.\n Y.applyUpdate(doc, update);\n\n await persistMergedState(docId, doc, () =>\n doc.getText(DEFAULT_FIELD).toString(),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n });\n}\n\n/**\n * Apply a text change to a document. Computes the minimal diff and\n * converts it to Yjs operations.\n *\n * Returns the text snapshot after the update.\n */\nexport async function applyText(\n docId: string,\n newText: string,\n fieldName: string = DEFAULT_FIELD,\n requestSource?: string,\n): Promise<string> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const oldText = doc.getText(fieldName).toString();\n const update = applyTextToYDoc(doc, fieldName, newText, \"server\");\n\n if (update.length === 0) {\n return doc.getText(fieldName).toString();\n }\n\n await persistMergedState(docId, doc, () =>\n doc.getText(fieldName).toString(),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: computeTextEditDescriptor(oldText, newText),\n });\n return doc.getText(fieldName).toString();\n });\n}\n\n/**\n * Search-and-replace text within a Y.XmlFragment (ProseMirror tree).\n * Produces minimal Yjs operations for cursor-preserving updates.\n *\n * Returns whether the text was found and the binary update.\n */\nexport async function searchAndReplace(\n docId: string,\n find: string,\n replace: string,\n requestSource?: string,\n): Promise<{ found: boolean; update: Uint8Array }> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const fragment = doc.getXmlFragment(\"default\");\n\n // Capture the update produced by the transaction\n let update: Uint8Array = new Uint8Array(0);\n const handler = (u: Uint8Array) => {\n update = u;\n };\n doc.on(\"update\", handler);\n\n let found = false;\n doc.transact(() => {\n found = searchAndReplaceInYXml(fragment, find, replace);\n }, \"agent\");\n\n doc.off(\"update\", handler);\n\n if (!found || update.length === 0) {\n return { found: false, update: new Uint8Array(0) };\n }\n\n await persistMergedState(docId, doc, () => extractTextFromYXml(fragment));\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: {\n kind: \"text\",\n quote: (replace || find).slice(0, 120),\n },\n });\n\n return { found: true, update };\n });\n}\n\n/**\n * Get the current text content of a document field.\n */\nexport async function getText(\n docId: string,\n fieldName: string = DEFAULT_FIELD,\n): Promise<string> {\n const doc = await getDoc(docId);\n return doc.getText(fieldName).toString();\n}\n\n/**\n * Get the full document state as a Uint8Array.\n */\nexport async function getState(docId: string): Promise<Uint8Array> {\n const doc = await getDoc(docId);\n return Y.encodeStateAsUpdate(doc);\n}\n\n/**\n * Get an incremental update relative to a client's state vector.\n */\nexport async function getIncUpdate(\n docId: string,\n clientStateVector: Uint8Array,\n): Promise<Uint8Array> {\n const doc = await getDoc(docId);\n return Y.encodeStateAsUpdate(doc, clientStateVector);\n}\n\n/**\n * Seed a document from existing text content (for migration).\n * Only seeds if no collab state exists yet.\n */\nexport async function seedFromText(\n docId: string,\n text: string,\n fieldName: string = DEFAULT_FIELD,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const existing = await loadYDocState(docId);\n if (existing && existing.length > 0) return; // Already seeded\n\n const { doc, state } = initYDocWithText(fieldName, text);\n await saveYDocState(docId, state, text);\n\n // Cache the doc\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n });\n}\n\n// ─── Structured JSON Operations ─────────────────────────────────────\n\n/**\n * Apply a full JSON update to a document. Computes the minimal diff\n * and converts it to Yjs operations on Y.Map/Y.Array.\n */\nexport async function applyJson(\n docId: string,\n newJson: any,\n fieldName: string = \"data\",\n _type: \"map\" | \"array\" = \"map\",\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const update = applyJsonDiff(doc, fieldName, newJson, \"server\");\n\n if (update.length === 0) return;\n\n // Snapshot the doc's actual post-merge state, not the caller-supplied\n // `newJson` — persistMergedState may re-apply newer DB state to resolve\n // concurrent writes, so `newJson` can be stale. Matches applyPatchOps.\n await persistMergedState(docId, doc, () =>\n JSON.stringify(yDocToJson(doc, fieldName)),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, { descriptor: { kind: \"doc\" } });\n });\n}\n\n/**\n * Apply surgical JSON patch operations to a document.\n */\nexport async function applyPatchOps(\n docId: string,\n ops: PatchOp[],\n fieldName: string = \"data\",\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const update = applyJsonPatch(doc, fieldName, ops, \"server\");\n\n if (update.length === 0) return;\n\n await persistMergedState(docId, doc, () =>\n JSON.stringify(yDocToJson(doc, fieldName)),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: {\n kind: \"paths\",\n paths: ops.slice(0, 5).map((op) => op.path),\n },\n });\n });\n}\n\n/**\n * Get the current JSON state of a document field.\n */\nexport async function getJson(\n docId: string,\n fieldName: string = \"data\",\n): Promise<any> {\n const doc = await getDoc(docId);\n return yDocToJson(doc, fieldName);\n}\n\n/**\n * Seed a document from existing JSON content (for migration).\n * Only seeds if no collab state exists yet.\n */\nexport async function seedFromJson(\n docId: string,\n json: any,\n fieldName: string = \"data\",\n type: \"map\" | \"array\" = \"map\",\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const existing = await loadYDocState(docId);\n if (existing && existing.length > 0) return; // Already seeded\n\n const { doc, state } = initYDocWithJson(fieldName, json, type);\n await saveYDocState(docId, state, JSON.stringify(json));\n\n // Cache the doc\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n });\n}\n\n/**\n * Release a document from the in-memory cache.\n */\nexport function releaseDoc(docId: string): void {\n const entry = _cache.get(docId);\n if (entry) {\n entry.doc.destroy();\n _cache.delete(docId);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ydoc-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K,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAExD,gBAAgB;QAChB,aAAa,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Server-side Yjs document manager with LRU caching and SQL persistence.\n *\n * Performance notes:\n * - `getDoc()` loads from the DB once on cache miss; subsequent calls return\n * the cached Y.Doc directly with no DB I/O.\n * - Mutations no longer call `applyStoredState()` unconditionally on every\n * write. The defensive re-read from the DB happens only inside\n * `persistMergedState` (needed for the CAS version read), not as a\n * separate SELECT before applying the new update. This removes the\n * redundant double-read that the previous implementation performed on\n * every write even on a hot cache.\n * - Compaction: when the stored blob is >4x the freshly encoded state, the\n * GC'd encoding is stored instead (removes accumulated Yjs tombstones,\n * preventing unbounded blob growth without any background jobs).\n */\n\nimport * as Y from \"yjs\";\n\nimport { emitCollabUpdate } from \"./emitter.js\";\nimport {\n applyJsonDiff,\n applyJsonPatch,\n yDocToJson,\n initYDocWithJson,\n type PatchOp,\n} from \"./json-to-yjs.js\";\nimport {\n loadYDocRecord,\n loadYDocState,\n saveYDocState,\n trySaveYDocState,\n} from \"./storage.js\";\nimport { uint8ArrayToBase64 } from \"./storage.js\";\nimport { applyTextToYDoc, initYDocWithText } from \"./text-to-yjs.js\";\nimport { searchAndReplaceInYXml, extractTextFromYXml } from \"./xml-ops.js\";\n\nconst DEFAULT_FIELD = \"content\";\nconst MAX_CACHE = 50;\n\n/**\n * Auto-presence: any agent-sourced write produces visible presence and\n * lingering edit attribution without the calling action having to wire\n * agentEnterDocument/agentLeaveDocument itself. Dynamic import avoids a\n * static cycle (agent-presence.ts imports searchAndReplace from this module).\n */\nfunction touchAgentPresence(\n docId: string,\n requestSource: string | undefined,\n edit: { descriptor: Record<string, unknown>; label?: string } | null,\n): void {\n if (requestSource !== \"agent\") return;\n import(\"./agent-presence.js\")\n .then((mod) => {\n mod.agentTouchDocument(docId, edit ? { edit: edit as any } : undefined);\n })\n .catch(() => {\n // Presence is best-effort; never fail the write for it.\n });\n}\n\n/**\n * Compute a small \"what changed\" descriptor from a text diff by trimming the\n * common prefix/suffix. Used for lingering edit highlights client-side.\n */\nexport function computeTextEditDescriptor(\n oldText: string,\n newText: string,\n): { kind: \"text\"; quote: string } | { kind: \"doc\" } {\n let start = 0;\n const maxStart = Math.min(oldText.length, newText.length);\n while (start < maxStart && oldText[start] === newText[start]) start++;\n\n let endOld = oldText.length;\n let endNew = newText.length;\n while (\n endOld > start &&\n endNew > start &&\n oldText[endOld - 1] === newText[endNew - 1]\n ) {\n endOld--;\n endNew--;\n }\n\n const inserted = newText.slice(start, endNew).trim();\n if (inserted.length > 0) {\n return { kind: \"text\", quote: inserted.slice(0, 120) };\n }\n return { kind: \"doc\" };\n}\n\n/**\n * Compaction ratio threshold. When the stored state byte count exceeds\n * COMPACTION_RATIO × the freshly encoded state, write the compact form\n * (strips accumulated tombstones). A value of 4 means: compact when the\n * stored blob is 4× larger than necessary.\n */\nconst COMPACTION_RATIO = 4;\n\ninterface CacheEntry {\n doc: Y.Doc;\n lastAccess: number;\n}\n\nconst _cache = new Map<string, CacheEntry>();\nconst _writeLocks = new Map<string, Promise<void>>();\n// Coalesces concurrent cache-miss loads for the same docId. Without this, two\n// simultaneous getDoc() callers both miss the cache, both build a Y.Doc and\n// apply stored state, and the second _cache.set silently orphans the first\n// doc (a memory leak that grows with concurrent read traffic).\nconst _loadLocks = new Map<string, Promise<Y.Doc>>();\n\nfunction evictIfNeeded(): void {\n if (_cache.size <= MAX_CACHE) return;\n // Evict least-recently-accessed entry\n let oldest: string | null = null;\n let oldestTime = Infinity;\n for (const [id, entry] of _cache) {\n if (entry.lastAccess < oldestTime) {\n oldestTime = entry.lastAccess;\n oldest = id;\n }\n }\n if (oldest) {\n const entry = _cache.get(oldest);\n entry?.doc.destroy();\n _cache.delete(oldest);\n }\n}\n\nasync function withDocWriteLock<T>(\n docId: string,\n fn: () => Promise<T>,\n): Promise<T> {\n const previous = _writeLocks.get(docId) ?? Promise.resolve();\n let release!: () => void;\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const chained = previous.catch(() => {}).then(() => current);\n _writeLocks.set(docId, chained);\n\n await previous.catch(() => {});\n try {\n return await fn();\n } finally {\n release();\n if (_writeLocks.get(docId) === chained) {\n _writeLocks.delete(docId);\n }\n }\n}\n\n/**\n * Build state to persist. If the stored blob is significantly larger than\n * the freshly encoded state, store the compact (GC'd) form instead to\n * prevent unbounded blob growth from accumulated tombstones.\n */\nfunction buildStateToStore(doc: Y.Doc, storedByteCount: number): Uint8Array {\n const encoded = Y.encodeStateAsUpdate(doc);\n if (\n storedByteCount > 0 &&\n storedByteCount > encoded.length * COMPACTION_RATIO\n ) {\n // Stored blob is much larger than needed — return the GC'd encoding.\n return encoded;\n }\n return encoded;\n}\n\n/**\n * Persist the merged doc state with CAS retry on conflict.\n *\n * REMOVED: the unconditional `applyStoredState()` that was called on every\n * write path before this function. The only DB read is the `loadYDocRecord`\n * call here — needed to get the CAS version and merge any concurrent writes\n * from OTHER processes. Within this process, the in-memory doc is already\n * up-to-date because mutations are serialized by withDocWriteLock.\n */\nasync function persistMergedState(\n docId: string,\n doc: Y.Doc,\n getTextSnapshot: () => string,\n validateTextSnapshot?: (snapshot: string) => void,\n): Promise<void> {\n for (let attempt = 0; attempt < 5; attempt++) {\n // One DB read per persist attempt. On first attempt this is the only read\n // on the write path (previously there was an unconditional second read\n // before the update was applied). On retry attempts it re-reads to get the\n // latest version after a CAS conflict.\n const latest = await loadYDocRecord(docId);\n if (latest?.state && latest.state.length > 0) {\n Y.applyUpdate(doc, latest.state);\n }\n\n const stateToStore = buildStateToStore(doc, latest?.state?.length ?? 0);\n const textSnapshot = getTextSnapshot();\n validateTextSnapshot?.(textSnapshot);\n const saved = await trySaveYDocState(\n docId,\n stateToStore,\n textSnapshot,\n latest?.version ?? null,\n );\n if (saved) return;\n }\n\n // All CAS attempts failed — fall back to unconditional save.\n const textSnapshot = getTextSnapshot();\n validateTextSnapshot?.(textSnapshot);\n await saveYDocState(docId, Y.encodeStateAsUpdate(doc), textSnapshot);\n}\n\n/**\n * Get or load a Yjs document by ID. Creates a new empty doc if none exists.\n */\nexport async function getDoc(docId: string): Promise<Y.Doc> {\n const cached = _cache.get(docId);\n if (cached) {\n cached.lastAccess = Date.now();\n return cached.doc;\n }\n\n const inFlight = _loadLocks.get(docId);\n if (inFlight) return inFlight;\n\n const load = (async () => {\n // Re-check the cache: a concurrent writer (or loader) may have populated it\n // between our miss above and acquiring this load slot.\n const reCached = _cache.get(docId);\n if (reCached) {\n reCached.lastAccess = Date.now();\n return reCached.doc;\n }\n\n const doc = new Y.Doc();\n const stored = await loadYDocState(docId);\n if (stored && stored.length > 0) {\n Y.applyUpdate(doc, stored);\n }\n\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n return doc;\n })();\n\n _loadLocks.set(docId, load);\n try {\n return await load;\n } finally {\n _loadLocks.delete(docId);\n }\n}\n\n/**\n * Apply a binary Yjs update (from a client) to a document.\n * Persists the result and emits a change event.\n */\nexport async function applyUpdate(\n docId: string,\n update: Uint8Array,\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n // The cached doc is already up-to-date from the initial load or a previous\n // write in this process. No redundant applyStoredState() here — cross-\n // process writes are merged inside persistMergedState when needed.\n Y.applyUpdate(doc, update);\n\n await persistMergedState(docId, doc, () =>\n doc.getText(DEFAULT_FIELD).toString(),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n });\n}\n\n/**\n * Apply a text change to a document. Computes the minimal diff and\n * converts it to Yjs operations.\n *\n * Returns the text snapshot after the update.\n */\nexport async function applyText(\n docId: string,\n newText: string,\n fieldName: string = DEFAULT_FIELD,\n requestSource?: string,\n options: {\n /**\n * Validate the fully converged text after cross-process Yjs updates have\n * merged, but before the state is persisted or broadcast. A rejected\n * candidate is discarded from this process's cache so the next read\n * reloads the last durable state instead of leaking an uncommitted merge.\n */\n validateSnapshot?: (snapshot: string) => void;\n } = {},\n): Promise<string> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const oldText = doc.getText(fieldName).toString();\n const update = applyTextToYDoc(doc, fieldName, newText, \"server\");\n\n if (update.length === 0) {\n const snapshot = doc.getText(fieldName).toString();\n try {\n options.validateSnapshot?.(snapshot);\n } catch (error) {\n releaseDoc(docId);\n throw error;\n }\n return snapshot;\n }\n\n try {\n await persistMergedState(\n docId,\n doc,\n () => doc.getText(fieldName).toString(),\n options.validateSnapshot,\n );\n } catch (error) {\n if (options.validateSnapshot) {\n // The target diff and any cross-process state merged during the CAS\n // read now live only in this cached Y.Doc. Destroy it before throwing:\n // neither the rejected update nor a compensating rollback should ever\n // be persisted/emitted to connected clients.\n releaseDoc(docId);\n }\n throw error;\n }\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: computeTextEditDescriptor(oldText, newText),\n });\n return doc.getText(fieldName).toString();\n });\n}\n\n/**\n * Search-and-replace text within a Y.XmlFragment (ProseMirror tree).\n * Produces minimal Yjs operations for cursor-preserving updates.\n *\n * Returns whether the text was found and the binary update.\n */\nexport async function searchAndReplace(\n docId: string,\n find: string,\n replace: string,\n requestSource?: string,\n): Promise<{ found: boolean; update: Uint8Array }> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const fragment = doc.getXmlFragment(\"default\");\n\n // Capture the update produced by the transaction\n let update: Uint8Array = new Uint8Array(0);\n const handler = (u: Uint8Array) => {\n update = u;\n };\n doc.on(\"update\", handler);\n\n let found = false;\n doc.transact(() => {\n found = searchAndReplaceInYXml(fragment, find, replace);\n }, \"agent\");\n\n doc.off(\"update\", handler);\n\n if (!found || update.length === 0) {\n return { found: false, update: new Uint8Array(0) };\n }\n\n await persistMergedState(docId, doc, () => extractTextFromYXml(fragment));\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: {\n kind: \"text\",\n quote: (replace || find).slice(0, 120),\n },\n });\n\n return { found: true, update };\n });\n}\n\n/**\n * Get the current text content of a document field.\n */\nexport async function getText(\n docId: string,\n fieldName: string = DEFAULT_FIELD,\n): Promise<string> {\n const doc = await getDoc(docId);\n return doc.getText(fieldName).toString();\n}\n\n/**\n * Get the full document state as a Uint8Array.\n */\nexport async function getState(docId: string): Promise<Uint8Array> {\n const doc = await getDoc(docId);\n return Y.encodeStateAsUpdate(doc);\n}\n\n/**\n * Get an incremental update relative to a client's state vector.\n */\nexport async function getIncUpdate(\n docId: string,\n clientStateVector: Uint8Array,\n): Promise<Uint8Array> {\n const doc = await getDoc(docId);\n return Y.encodeStateAsUpdate(doc, clientStateVector);\n}\n\n/**\n * Seed a document from existing text content (for migration).\n * Only seeds if no collab state exists yet.\n */\nexport async function seedFromText(\n docId: string,\n text: string,\n fieldName: string = DEFAULT_FIELD,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const existing = await loadYDocState(docId);\n if (existing && existing.length > 0) return; // Already seeded\n\n const { doc, state } = initYDocWithText(fieldName, text);\n await saveYDocState(docId, state, text);\n\n // Cache the doc\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n });\n}\n\n// ─── Structured JSON Operations ─────────────────────────────────────\n\n/**\n * Apply a full JSON update to a document. Computes the minimal diff\n * and converts it to Yjs operations on Y.Map/Y.Array.\n */\nexport async function applyJson(\n docId: string,\n newJson: any,\n fieldName: string = \"data\",\n _type: \"map\" | \"array\" = \"map\",\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const update = applyJsonDiff(doc, fieldName, newJson, \"server\");\n\n if (update.length === 0) return;\n\n // Snapshot the doc's actual post-merge state, not the caller-supplied\n // `newJson` — persistMergedState may re-apply newer DB state to resolve\n // concurrent writes, so `newJson` can be stale. Matches applyPatchOps.\n await persistMergedState(docId, doc, () =>\n JSON.stringify(yDocToJson(doc, fieldName)),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, { descriptor: { kind: \"doc\" } });\n });\n}\n\n/**\n * Apply surgical JSON patch operations to a document.\n */\nexport async function applyPatchOps(\n docId: string,\n ops: PatchOp[],\n fieldName: string = \"data\",\n requestSource?: string,\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const doc = await getDoc(docId);\n const update = applyJsonPatch(doc, fieldName, ops, \"server\");\n\n if (update.length === 0) return;\n\n await persistMergedState(docId, doc, () =>\n JSON.stringify(yDocToJson(doc, fieldName)),\n );\n\n emitCollabUpdate(docId, uint8ArrayToBase64(update), requestSource);\n touchAgentPresence(docId, requestSource, {\n descriptor: {\n kind: \"paths\",\n paths: ops.slice(0, 5).map((op) => op.path),\n },\n });\n });\n}\n\n/**\n * Get the current JSON state of a document field.\n */\nexport async function getJson(\n docId: string,\n fieldName: string = \"data\",\n): Promise<any> {\n const doc = await getDoc(docId);\n return yDocToJson(doc, fieldName);\n}\n\n/**\n * Seed a document from existing JSON content (for migration).\n * Only seeds if no collab state exists yet.\n */\nexport async function seedFromJson(\n docId: string,\n json: any,\n fieldName: string = \"data\",\n type: \"map\" | \"array\" = \"map\",\n): Promise<void> {\n return withDocWriteLock(docId, async () => {\n const existing = await loadYDocState(docId);\n if (existing && existing.length > 0) return; // Already seeded\n\n const { doc, state } = initYDocWithJson(fieldName, json, type);\n await saveYDocState(docId, state, JSON.stringify(json));\n\n // Cache the doc\n evictIfNeeded();\n _cache.set(docId, { doc, lastAccess: Date.now() });\n });\n}\n\n/**\n * Release a document from the in-memory cache.\n */\nexport function releaseDoc(docId: string): void {\n const entry = _cache.get(docId);\n if (entry) {\n entry.doc.destroy();\n _cache.delete(docId);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AA2EA,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AA4B9D;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAK5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CASvD;AAmDD,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;;;;OAYG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,YAAY,CAAC;IAClB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,KAAK,CAAC,cAAc,CAAC,EACjC,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAsYhB"}
|
package/dist/db/migrations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDbExec, createDbExec, isPostgres, getDialect, getMigrationDatabaseUrl, retrySqliteBusy, } from "./client.js";
|
|
1
|
+
import { getDbExec, createDbExec, isPostgres, getDialect, getMigrationDatabaseUrl, getCloudflareD1Binding, retrySqliteBusy, } from "./client.js";
|
|
2
2
|
// ---------------------------------------------------------------------------
|
|
3
3
|
// Shared direct-endpoint exec across concurrent migration runners per boot.
|
|
4
4
|
//
|
|
@@ -244,7 +244,9 @@ export function runMigrations(migrations, options) {
|
|
|
244
244
|
return async () => {
|
|
245
245
|
try {
|
|
246
246
|
// Check for Cloudflare D1 binding (only if DATABASE_URL not set)
|
|
247
|
-
const d1 = getDialect() === "d1"
|
|
247
|
+
const d1 = getDialect() === "d1"
|
|
248
|
+
? getCloudflareD1Binding()
|
|
249
|
+
: null;
|
|
248
250
|
if (d1) {
|
|
249
251
|
await d1
|
|
250
252
|
.prepare(`CREATE TABLE IF NOT EXISTS ${table} (version INTEGER PRIMARY KEY)`)
|