@agent-native/core 0.113.0 → 0.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-native.eject.json +164 -0
- package/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +11 -0
- package/corpus/core/README.md +61 -174
- package/corpus/core/agent-native.eject.json +164 -0
- package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
- package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
- package/corpus/core/package.json +15 -2
- package/corpus/core/src/cli/eject.ts +1594 -0
- package/corpus/core/src/cli/index.ts +16 -0
- package/corpus/core/src/client/index.ts +4 -0
- package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
- package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
- package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
- package/corpus/core/src/client/resources/index.ts +19 -0
- package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
- package/corpus/core/src/client/resources/runtime.ts +1 -0
- package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
- package/corpus/core/src/client/setup-connections/index.ts +1 -0
- package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
- package/corpus/core/src/connections/catalog.ts +41 -24
- package/corpus/core/src/connections/index.ts +1 -0
- package/corpus/core/src/connections/runtime.ts +1 -0
- package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
- package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
- package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
- package/corpus/core/src/eject/workspace-connections.ts +92 -0
- package/corpus/core/src/index.ts +1 -0
- package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
- package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
- package/corpus/core/src/integrations/index.ts +5 -1
- package/corpus/core/src/integrations/plugin.ts +34 -12
- package/corpus/core/src/integrations/runtime.ts +1 -0
- package/corpus/core/src/integrations/types.ts +3 -1
- package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
- package/corpus/core/src/package-lifecycle/index.ts +1 -0
- package/corpus/core/src/provider-api/index.ts +46 -12
- package/corpus/core/src/provider-api/runtime.ts +1 -0
- package/corpus/core/src/setup-connections/index.ts +1 -0
- package/corpus/core/src/shared/merge-by-id.ts +14 -0
- package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/default/AGENTS.md +6 -5
- package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/headless/AGENTS.md +5 -4
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -4
- package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -4
- package/corpus/core/src/vite/client.ts +25 -2
- package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
- package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
- package/corpus/templates/brain/app/routes/_index.tsx +8 -0
- package/corpus/templates/brain/app/routes.ts +1 -0
- package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
- package/corpus/templates/brain/server/db/schema.ts +3 -0
- package/corpus/templates/brain/server/lib/brain.ts +41 -2
- package/corpus/templates/brain/server/lib/connectors.ts +379 -113
- package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
- package/corpus/templates/brain/server/plugins/db.ts +10 -0
- package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
- package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/chat/AGENTS.md +3 -2
- package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/corpus/toolkit/CHANGELOG.md +6 -0
- package/corpus/toolkit/agent-native.eject.json +411 -0
- package/corpus/toolkit/package.json +5 -2
- package/dist/cli/eject.d.ts +21 -0
- package/dist/cli/eject.d.ts.map +1 -0
- package/dist/cli/eject.js +1145 -0
- package/dist/cli/eject.js.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.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/resources/McpConnectionSuggestion.d.ts +4 -3
- package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
- package/dist/client/resources/McpConnectionSuggestion.js +3 -3
- package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
- package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.js +2 -2
- package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts +4 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +9 -7
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/resources/index.d.ts +3 -0
- package/dist/client/resources/index.d.ts.map +1 -1
- package/dist/client/resources/index.js +3 -0
- package/dist/client/resources/index.js.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
- package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
- package/dist/client/resources/mcp-integration-catalog.js +6 -2
- package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
- package/dist/client/resources/runtime.d.ts +2 -0
- package/dist/client/resources/runtime.d.ts.map +1 -0
- package/dist/client/resources/runtime.js +2 -0
- package/dist/client/resources/runtime.js.map +1 -0
- package/dist/client/setup-connections/catalog.d.ts +2 -0
- package/dist/client/setup-connections/catalog.d.ts.map +1 -0
- package/dist/client/setup-connections/catalog.js +7 -0
- package/dist/client/setup-connections/catalog.js.map +1 -0
- package/dist/client/setup-connections/index.d.ts +1 -0
- package/dist/client/setup-connections/index.d.ts.map +1 -1
- package/dist/client/setup-connections/index.js +1 -0
- package/dist/client/setup-connections/index.js.map +1 -1
- package/dist/client/setup-connections/runtime.d.ts +2 -0
- package/dist/client/setup-connections/runtime.d.ts.map +1 -0
- package/dist/client/setup-connections/runtime.js +2 -0
- package/dist/client/setup-connections/runtime.js.map +1 -0
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/connections/catalog.d.ts +5 -3
- package/dist/connections/catalog.d.ts.map +1 -1
- package/dist/connections/catalog.js +16 -8
- package/dist/connections/catalog.js.map +1 -1
- package/dist/connections/index.d.ts +1 -1
- package/dist/connections/index.d.ts.map +1 -1
- package/dist/connections/index.js +1 -1
- package/dist/connections/index.js.map +1 -1
- package/dist/connections/runtime.d.ts +2 -0
- package/dist/connections/runtime.d.ts.map +1 -0
- package/dist/connections/runtime.js +2 -0
- package/dist/connections/runtime.js.map +1 -0
- package/dist/eject/provider-api-definitions.d.ts +34 -0
- package/dist/eject/provider-api-definitions.d.ts.map +1 -0
- package/dist/eject/provider-api-definitions.js +88 -0
- package/dist/eject/provider-api-definitions.js.map +1 -0
- package/dist/eject/remote-mcp-presets.d.ts +17 -0
- package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
- package/dist/eject/remote-mcp-presets.js +81 -0
- package/dist/eject/remote-mcp-presets.js.map +1 -0
- package/dist/eject/setup-readiness-ui.d.ts +7 -0
- package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
- package/dist/eject/setup-readiness-ui.js +13 -0
- package/dist/eject/setup-readiness-ui.js.map +1 -0
- package/dist/eject/workspace-connections.d.ts +11 -0
- package/dist/eject/workspace-connections.d.ts.map +1 -0
- package/dist/eject/workspace-connections.js +47 -0
- package/dist/eject/workspace-connections.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/adapter-overrides.d.ts +3 -0
- package/dist/integrations/adapter-overrides.d.ts.map +1 -0
- package/dist/integrations/adapter-overrides.js +7 -0
- package/dist/integrations/adapter-overrides.js.map +1 -0
- package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
- package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
- package/dist/integrations/eject/messaging-adapters.js +49 -0
- package/dist/integrations/eject/messaging-adapters.js.map +1 -0
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +2 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/plugin.d.ts +32 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +19 -12
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/runtime.d.ts +2 -0
- package/dist/integrations/runtime.d.ts.map +1 -0
- package/dist/integrations/runtime.js +2 -0
- package/dist/integrations/runtime.js.map +1 -0
- package/dist/integrations/types.d.ts +3 -1
- package/dist/integrations/types.d.ts.map +1 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
- package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
- package/dist/package-lifecycle/eject-manifest.js +219 -0
- package/dist/package-lifecycle/eject-manifest.js.map +1 -0
- package/dist/package-lifecycle/index.d.ts +1 -0
- package/dist/package-lifecycle/index.d.ts.map +1 -1
- package/dist/package-lifecycle/index.js +1 -0
- package/dist/package-lifecycle/index.js.map +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +4 -4
- package/dist/provider-api/actions/provider-api.d.ts +8 -8
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/provider-api/index.d.ts +6 -2
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +25 -12
- package/dist/provider-api/index.js.map +1 -1
- package/dist/provider-api/runtime.d.ts +2 -0
- package/dist/provider-api/runtime.d.ts.map +1 -0
- package/dist/provider-api/runtime.js +2 -0
- package/dist/provider-api/runtime.js.map +1 -0
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/setup-connections/index.d.ts +1 -1
- package/dist/setup-connections/index.d.ts.map +1 -1
- package/dist/setup-connections/index.js +1 -1
- package/dist/setup-connections/index.js.map +1 -1
- package/dist/shared/merge-by-id.d.ts +5 -0
- package/dist/shared/merge-by-id.d.ts.map +1 -0
- package/dist/shared/merge-by-id.js +7 -0
- package/dist/shared/merge-by-id.js.map +1 -0
- package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/chat/AGENTS.md +3 -2
- package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/default/AGENTS.md +6 -5
- package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/headless/AGENTS.md +5 -4
- package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/dist/templates/workspace-core/AGENTS.md +4 -4
- package/dist/templates/workspace-root/AGENTS.md +4 -4
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +22 -2
- package/dist/vite/client.js.map +1 -1
- package/docs/content/agent-native-toolkit.mdx +38 -0
- package/docs/content/package-lifecycle.mdx +54 -4
- package/package.json +15 -2
- package/src/a2a/agent-card.ts +83 -0
- package/src/a2a/artifact-response.ts +1648 -0
- package/src/a2a/auth-policy.ts +66 -0
- package/src/a2a/caller-auth.ts +102 -0
- package/src/a2a/client.ts +876 -0
- package/src/a2a/correlation.ts +50 -0
- package/src/a2a/handlers.ts +1285 -0
- package/src/a2a/index.ts +50 -0
- package/src/a2a/invoke.ts +348 -0
- package/src/a2a/response-text.ts +53 -0
- package/src/a2a/server.ts +586 -0
- package/src/a2a/task-store.ts +917 -0
- package/src/a2a/types.ts +221 -0
- package/src/a2a-claims.ts +52 -0
- package/src/action-change-marker.ts +74 -0
- package/src/action-ui.ts +38 -0
- package/src/action.ts +1406 -0
- package/src/adapters/cli/index.ts +6 -0
- package/src/adapters/cli/registry.ts +73 -0
- package/src/adapters/cli/shell-adapter.ts +92 -0
- package/src/adapters/cli/types.ts +27 -0
- package/src/agent/action-continuation-guidance.ts +38 -0
- package/src/agent/app-model-defaults.ts +201 -0
- package/src/agent/context-xray/actions/context-evict.ts +56 -0
- package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
- package/src/agent/context-xray/actions/context-pin.ts +56 -0
- package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
- package/src/agent/context-xray/actions/context-report.ts +75 -0
- package/src/agent/context-xray/actions/context-restore.ts +51 -0
- package/src/agent/context-xray/actions/errors.ts +40 -0
- package/src/agent/context-xray/apply-directives.ts +137 -0
- package/src/agent/context-xray/directives-store.ts +178 -0
- package/src/agent/context-xray/identity.ts +37 -0
- package/src/agent/context-xray/manifest.ts +284 -0
- package/src/agent/context-xray/migrations.ts +32 -0
- package/src/agent/context-xray/plugin.ts +23 -0
- package/src/agent/context-xray/schema.ts +17 -0
- package/src/agent/context-xray/segments.ts +194 -0
- package/src/agent/context-xray/tokenize.ts +93 -0
- package/src/agent/default-model.ts +5 -0
- package/src/agent/durable-background.ts +547 -0
- package/src/agent/engine/ai-sdk-engine.ts +565 -0
- package/src/agent/engine/anthropic-engine.ts +320 -0
- package/src/agent/engine/builder-engine.ts +1110 -0
- package/src/agent/engine/builder-gateway-headers.ts +44 -0
- package/src/agent/engine/builtin.ts +122 -0
- package/src/agent/engine/context-directives-transform.ts +73 -0
- package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
- package/src/agent/engine/credential-errors.ts +69 -0
- package/src/agent/engine/index.ts +54 -0
- package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
- package/src/agent/engine/output-tokens.ts +181 -0
- package/src/agent/engine/provider-env-vars.ts +69 -0
- package/src/agent/engine/registry.ts +853 -0
- package/src/agent/engine/tool-call-journal-seed.ts +85 -0
- package/src/agent/engine/translate-ai-sdk.ts +407 -0
- package/src/agent/engine/translate-anthropic.ts +611 -0
- package/src/agent/engine/types.ts +310 -0
- package/src/agent/harness/acp-adapter.ts +893 -0
- package/src/agent/harness/acp-builtin.ts +70 -0
- package/src/agent/harness/ai-sdk-adapter.ts +509 -0
- package/src/agent/harness/background.ts +365 -0
- package/src/agent/harness/builtin.ts +50 -0
- package/src/agent/harness/index.ts +86 -0
- package/src/agent/harness/lifecycle.ts +498 -0
- package/src/agent/harness/registry.ts +97 -0
- package/src/agent/harness/runner.ts +182 -0
- package/src/agent/harness/store.ts +466 -0
- package/src/agent/harness/translate.ts +130 -0
- package/src/agent/harness/types.ts +129 -0
- package/src/agent/index.ts +32 -0
- package/src/agent/loop-settings.ts +186 -0
- package/src/agent/model-config.ts +363 -0
- package/src/agent/observational-memory/compactor.ts +78 -0
- package/src/agent/observational-memory/config.ts +78 -0
- package/src/agent/observational-memory/index.ts +79 -0
- package/src/agent/observational-memory/internal-run.ts +89 -0
- package/src/agent/observational-memory/message-text.ts +49 -0
- package/src/agent/observational-memory/migrations.ts +44 -0
- package/src/agent/observational-memory/observer.ts +128 -0
- package/src/agent/observational-memory/plugin.ts +35 -0
- package/src/agent/observational-memory/prompts.ts +53 -0
- package/src/agent/observational-memory/read.ts +131 -0
- package/src/agent/observational-memory/reflector.ts +119 -0
- package/src/agent/observational-memory/schema.ts +48 -0
- package/src/agent/observational-memory/store.ts +275 -0
- package/src/agent/observational-memory/types.ts +65 -0
- package/src/agent/processors.ts +209 -0
- package/src/agent/production-agent.ts +8254 -0
- package/src/agent/run-loop-with-resume.ts +394 -0
- package/src/agent/run-manager.ts +1825 -0
- package/src/agent/run-ownership.ts +75 -0
- package/src/agent/run-store.ts +2601 -0
- package/src/agent/runtime-context.ts +169 -0
- package/src/agent/thread-data-builder.ts +1584 -0
- package/src/agent/tool-call-journal.ts +368 -0
- package/src/agent/tool-error-redaction.ts +52 -0
- package/src/agent/tool-result-images.ts +178 -0
- package/src/agent/tool-search.ts +376 -0
- package/src/agent/types.ts +372 -0
- package/src/agent-native/index.ts +198 -0
- package/src/agent-web/config.ts +253 -0
- package/src/agent-web/generator.ts +382 -0
- package/src/agent-web/index.ts +36 -0
- package/src/appearance/actions/change-appearance.ts +35 -0
- package/src/application-state/emitter.ts +81 -0
- package/src/application-state/handlers.ts +121 -0
- package/src/application-state/index.ts +44 -0
- package/src/application-state/script-helpers.ts +155 -0
- package/src/application-state/store.ts +274 -0
- package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
- package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
- package/src/assets/branding/agent-native.icon/icon.json +49 -0
- package/src/assets/branding/favicon.png +0 -0
- package/src/assets/branding/favicon.svg +1 -0
- package/src/assets/branding/icon-on-dark.svg +10 -0
- package/src/assets/branding/icon-on-light.svg +10 -0
- package/src/assets/branding/mac-app-icon.svg +1 -0
- package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
- package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
- package/src/assets/branding/tray-icon.svg +6 -0
- package/src/assets/branding/wordmark-on-dark.svg +21 -0
- package/src/assets/branding/wordmark-on-light.svg +21 -0
- package/src/assets/fonts/LICENSE_LIBERATION +96 -0
- package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
- package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
- package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
- package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
- package/src/audit/actions/export-audit-events.ts +162 -0
- package/src/audit/actions/get-audit-event.ts +24 -0
- package/src/audit/actions/list-audit-events.ts +66 -0
- package/src/audit/cleanup-job.ts +100 -0
- package/src/audit/config.ts +90 -0
- package/src/audit/index.ts +43 -0
- package/src/audit/record.ts +180 -0
- package/src/audit/redact.ts +109 -0
- package/src/audit/store.ts +346 -0
- package/src/audit/types.ts +141 -0
- package/src/automation/index.ts +802 -0
- package/src/brand-kit/brand-signals.ts +124 -0
- package/src/brand-kit/fig/index.ts +64 -0
- package/src/brand-kit/index.ts +72 -0
- package/src/brand-kit/types.ts +113 -0
- package/src/browser-sessions/actions.ts +302 -0
- package/src/browser-sessions/routes.ts +234 -0
- package/src/browser-sessions/store.ts +679 -0
- package/src/browser-sessions/types.ts +84 -0
- package/src/changelog/parse.ts +328 -0
- package/src/chat-threads/emitter.ts +22 -0
- package/src/chat-threads/schema.ts +43 -0
- package/src/chat-threads/store.ts +1311 -0
- package/src/checkpoints/index.ts +15 -0
- package/src/checkpoints/service.ts +142 -0
- package/src/checkpoints/store.ts +153 -0
- package/src/cli/add.ts +425 -0
- package/src/cli/agent.ts +424 -0
- package/src/cli/agents.ts +122 -0
- package/src/cli/app-skill.ts +1455 -0
- package/src/cli/atomic-json-file.ts +324 -0
- package/src/cli/audit-agent-web.ts +324 -0
- package/src/cli/changelog.ts +199 -0
- package/src/cli/claude-code-participant.ts +515 -0
- package/src/cli/code-agent-commands.ts +270 -0
- package/src/cli/code-agent-connector.ts +1109 -0
- package/src/cli/code-agent-executor.ts +1970 -0
- package/src/cli/code-agent-output-smoother.ts +140 -0
- package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
- package/src/cli/code-agent-runs.ts +548 -0
- package/src/cli/code.ts +1805 -0
- package/src/cli/codex-cli-participant.ts +496 -0
- package/src/cli/connect.ts +2714 -0
- package/src/cli/content-local.ts +442 -0
- package/src/cli/context-xray-local.ts +2193 -0
- package/src/cli/create-workspace.ts +30 -0
- package/src/cli/create.ts +2247 -0
- package/src/cli/deploy-build.ts +50 -0
- package/src/cli/design-connect.ts +3187 -0
- package/src/cli/doctor.ts +472 -0
- package/src/cli/eject.ts +1594 -0
- package/src/cli/eval.ts +134 -0
- package/src/cli/gateway-helpers.ts +70 -0
- package/src/cli/index.ts +1217 -0
- package/src/cli/info.ts +105 -0
- package/src/cli/invoke.ts +288 -0
- package/src/cli/mcp-config-writers.ts +857 -0
- package/src/cli/mcp.ts +594 -0
- package/src/cli/migrate.ts +1813 -0
- package/src/cli/migration-codemod.ts +646 -0
- package/src/cli/multi-frontier-runs.ts +1952 -0
- package/src/cli/package-lifecycle.ts +823 -0
- package/src/cli/plan-blocks.ts +143 -0
- package/src/cli/plan-local.ts +3189 -0
- package/src/cli/plan-publish-store.ts +138 -0
- package/src/cli/pr-visual-recap-workflow.ts +2 -0
- package/src/cli/recap.ts +5 -0
- package/src/cli/setup-agents.ts +120 -0
- package/src/cli/skills-content/assets-skill.ts +83 -0
- package/src/cli/skills-content/canvas.ts +153 -0
- package/src/cli/skills-content/connection.ts +52 -0
- package/src/cli/skills-content/content-skill.ts +120 -0
- package/src/cli/skills-content/design-exploration-skill.ts +118 -0
- package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
- package/src/cli/skills-content/document-quality.ts +196 -0
- package/src/cli/skills-content/exemplar.ts +69 -0
- package/src/cli/skills-content/help.ts +77 -0
- package/src/cli/skills-content/index.ts +22 -0
- package/src/cli/skills-content/local-files.ts +100 -0
- package/src/cli/skills-content/plan-setup-auth.ts +80 -0
- package/src/cli/skills-content/visual-plan-skill.ts +493 -0
- package/src/cli/skills-content/visual-recap-skill.ts +553 -0
- package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
- package/src/cli/skills-content/wireframe.ts +349 -0
- package/src/cli/skills.ts +4340 -0
- package/src/cli/sync-builder-starter-manifest.ts +631 -0
- package/src/cli/telemetry.ts +136 -0
- package/src/cli/templates-meta.ts +269 -0
- package/src/cli/upgrade.ts +956 -0
- package/src/cli/visualize-repo.ts +715 -0
- package/src/cli/workspace-dev.ts +1486 -0
- package/src/cli/workspacify.ts +258 -0
- package/src/client/AgentAskPopover.tsx +89 -0
- package/src/client/AgentChatHome.tsx +66 -0
- package/src/client/AgentNative.tsx +161 -0
- package/src/client/AgentNativeEmbedded.tsx +288 -0
- package/src/client/AgentNativeFrame.tsx +151 -0
- package/src/client/AgentPanel.tsx +3437 -0
- package/src/client/AgentTaskCard.tsx +273 -0
- package/src/client/AppearancePicker.tsx +79 -0
- package/src/client/AssistantChat.tsx +5793 -0
- package/src/client/ClientOnly.tsx +22 -0
- package/src/client/CommandMenu.tsx +726 -0
- package/src/client/ConnectBuilderCard.tsx +390 -0
- package/src/client/DefaultSpinner.tsx +47 -0
- package/src/client/ErrorBoundary.tsx +359 -0
- package/src/client/ErrorReportActions.tsx +69 -0
- package/src/client/FeedbackButton.tsx +553 -0
- package/src/client/HighlightedCodeBlock.tsx +173 -0
- package/src/client/IframeEmbed.tsx +151 -0
- package/src/client/KeepTabOpenNotice.tsx +181 -0
- package/src/client/MultiTabAssistantChat.tsx +2576 -0
- package/src/client/NewWorkspaceAppFlow.tsx +525 -0
- package/src/client/PoweredByBadge.tsx +284 -0
- package/src/client/RunStuckBanner.tsx +431 -0
- package/src/client/StarfieldBackground.tsx +466 -0
- package/src/client/Turnstile.tsx +125 -0
- package/src/client/active-run-state.ts +139 -0
- package/src/client/agent-chat/index.ts +279 -0
- package/src/client/agent-chat-adapter.ts +3692 -0
- package/src/client/agent-chat.ts +1233 -0
- package/src/client/agent-engine-key.ts +122 -0
- package/src/client/agent-page/AgentContextTab.tsx +487 -0
- package/src/client/agent-page/AgentEmptyState.tsx +44 -0
- package/src/client/agent-page/AgentJobsTab.tsx +441 -0
- package/src/client/agent-page/AgentTabFrame.tsx +39 -0
- package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
- package/src/client/agent-page/types.ts +18 -0
- package/src/client/agent-page/use-jobs.ts +150 -0
- package/src/client/agent-sidebar-state.ts +166 -0
- package/src/client/analytics/index.ts +40 -0
- package/src/client/analytics-session.ts +70 -0
- package/src/client/analytics.ts +1757 -0
- package/src/client/api-path.ts +124 -0
- package/src/client/app-providers.tsx +230 -0
- package/src/client/appearance.ts +130 -0
- package/src/client/application-state.ts +154 -0
- package/src/client/assistant-ui-recovery.tsx +205 -0
- package/src/client/automation/index.ts +4 -0
- package/src/client/automation.ts +22 -0
- package/src/client/blocks/AiEditableField.tsx +30 -0
- package/src/client/blocks/BlockView.tsx +145 -0
- package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
- package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
- package/src/client/blocks/agent.ts +95 -0
- package/src/client/blocks/code-block-direction.ts +21 -0
- package/src/client/blocks/index.ts +308 -0
- package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
- package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
- package/src/client/blocks/library/DataModelBlock.tsx +775 -0
- package/src/client/blocks/library/DiffBlock.tsx +1854 -0
- package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
- package/src/client/blocks/library/HighlightedCode.tsx +260 -0
- package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
- package/src/client/blocks/library/MermaidBlock.tsx +362 -0
- package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
- package/src/client/blocks/library/annotated-code.config.ts +101 -0
- package/src/client/blocks/library/annotation-rail.tsx +1020 -0
- package/src/client/blocks/library/api-endpoint.config.ts +207 -0
- package/src/client/blocks/library/block-copy.ts +399 -0
- package/src/client/blocks/library/callout.config.ts +57 -0
- package/src/client/blocks/library/callout.tsx +149 -0
- package/src/client/blocks/library/checklist.config.ts +56 -0
- package/src/client/blocks/library/checklist.tsx +208 -0
- package/src/client/blocks/library/code-filename-label.tsx +59 -0
- package/src/client/blocks/library/code-highlight.tsx +178 -0
- package/src/client/blocks/library/code-tabs.config.ts +70 -0
- package/src/client/blocks/library/code-tabs.tsx +606 -0
- package/src/client/blocks/library/code.config.ts +69 -0
- package/src/client/blocks/library/code.tsx +440 -0
- package/src/client/blocks/library/columns.config.ts +85 -0
- package/src/client/blocks/library/columns.tsx +334 -0
- package/src/client/blocks/library/data-model.config.ts +152 -0
- package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
- package/src/client/blocks/library/diagram.config.ts +222 -0
- package/src/client/blocks/library/diagram.tsx +958 -0
- package/src/client/blocks/library/diff.config.ts +115 -0
- package/src/client/blocks/library/file-tree.config.ts +92 -0
- package/src/client/blocks/library/html.config.ts +79 -0
- package/src/client/blocks/library/html.tsx +258 -0
- package/src/client/blocks/library/json-explorer.config.ts +74 -0
- package/src/client/blocks/library/mermaid.config.ts +49 -0
- package/src/client/blocks/library/narrow-container.tsx +37 -0
- package/src/client/blocks/library/openapi-spec.config.ts +66 -0
- package/src/client/blocks/library/question-form.config.ts +127 -0
- package/src/client/blocks/library/question-form.tsx +944 -0
- package/src/client/blocks/library/sanitize-html.ts +343 -0
- package/src/client/blocks/library/server-specs.ts +338 -0
- package/src/client/blocks/library/specs.tsx +308 -0
- package/src/client/blocks/library/table.config.ts +61 -0
- package/src/client/blocks/library/table.tsx +449 -0
- package/src/client/blocks/library/tabs.config.ts +96 -0
- package/src/client/blocks/library/tabs.tsx +665 -0
- package/src/client/blocks/library/wireframe-icons.ts +210 -0
- package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
- package/src/client/blocks/library/wireframe.config.ts +539 -0
- package/src/client/blocks/library/wireframe.tsx +535 -0
- package/src/client/blocks/mdx.ts +364 -0
- package/src/client/blocks/provider.tsx +51 -0
- package/src/client/blocks/registry.ts +83 -0
- package/src/client/blocks/schema-form/introspect.ts +201 -0
- package/src/client/blocks/server.ts +170 -0
- package/src/client/blocks/types.ts +415 -0
- package/src/client/browser-session-bridge.ts +548 -0
- package/src/client/browser-tab-id.ts +36 -0
- package/src/client/builder-frame.ts +194 -0
- package/src/client/builder-mark.tsx +21 -0
- package/src/client/changelog/Changelog.tsx +333 -0
- package/src/client/changelog/index.ts +1 -0
- package/src/client/chat/ChatHistoryList.tsx +7 -0
- package/src/client/chat/attachment-adapters.ts +426 -0
- package/src/client/chat/connectors.ts +1579 -0
- package/src/client/chat/index.ts +160 -0
- package/src/client/chat/markdown-renderer.tsx +693 -0
- package/src/client/chat/message-components.tsx +1326 -0
- package/src/client/chat/repo-helpers.ts +281 -0
- package/src/client/chat/run-recovery.tsx +994 -0
- package/src/client/chat/runtime.ts +1810 -0
- package/src/client/chat/tool-call-display.tsx +1270 -0
- package/src/client/chat/tool-render-registry.tsx +144 -0
- package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
- package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
- package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
- package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
- package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
- package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
- package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
- package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
- package/src/client/chat/widgets/data-widget-types.ts +1 -0
- package/src/client/chat/widgets/inline-extension-result.ts +86 -0
- package/src/client/chat-model-groups.ts +171 -0
- package/src/client/chat-thread-url.ts +11 -0
- package/src/client/chat-view-transition.ts +213 -0
- package/src/client/client-action.ts +21 -0
- package/src/client/client-bootstrap.ts +7 -0
- package/src/client/client-surface.ts +41 -0
- package/src/client/clipboard.ts +89 -0
- package/src/client/code-agent-chat-adapter.ts +537 -0
- package/src/client/collab/index.ts +60 -0
- package/src/client/command-navigation/index.ts +15 -0
- package/src/client/comments-review/index.ts +1 -0
- package/src/client/components/AgentPresenceChip.tsx +4 -0
- package/src/client/components/ApiKeySettings.tsx +309 -0
- package/src/client/components/CodeAgentIndicator.tsx +59 -0
- package/src/client/components/CodeRequiredDialog.tsx +470 -0
- package/src/client/components/LiveCursorOverlay.tsx +5 -0
- package/src/client/components/MissingKeyCard.tsx +61 -0
- package/src/client/components/PresenceBar.tsx +4 -0
- package/src/client/components/RecentEditHighlights.tsx +4 -0
- package/src/client/components/RemoteSelectionRings.tsx +5 -0
- package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
- package/src/client/components/ui/dialog.tsx +1 -0
- package/src/client/components/ui/dropdown-menu.tsx +1 -0
- package/src/client/components/ui/hover-card.tsx +1 -0
- package/src/client/components/ui/message-scroller.tsx +131 -0
- package/src/client/components/ui/popover.tsx +1 -0
- package/src/client/components/ui/sheet.tsx +1 -0
- package/src/client/components/ui/tooltip.tsx +1 -0
- package/src/client/composer/index.ts +11 -0
- package/src/client/composer/runtime-adapters.tsx +123 -0
- package/src/client/composer/use-mention-search.ts +7 -0
- package/src/client/composer/wired-components.tsx +53 -0
- package/src/client/context-xray/ContextMeter.tsx +124 -0
- package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
- package/src/client/context-xray/ContextTreemap.tsx +24 -0
- package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
- package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
- package/src/client/context-xray/format.ts +27 -0
- package/src/client/conversation/AgentConversation.tsx +555 -0
- package/src/client/conversation/code-agent-transcript.ts +283 -0
- package/src/client/conversation/index.ts +22 -0
- package/src/client/conversation/types.ts +85 -0
- package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
- package/src/client/create-query-client.ts +86 -0
- package/src/client/db-admin/DataGrid.tsx +551 -0
- package/src/client/db-admin/DbAdminPage.tsx +218 -0
- package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
- package/src/client/db-admin/EditableCell.tsx +451 -0
- package/src/client/db-admin/FilterBar.tsx +203 -0
- package/src/client/db-admin/ResultsGrid.tsx +114 -0
- package/src/client/db-admin/RowSidePanel.tsx +337 -0
- package/src/client/db-admin/SqlEditor.tsx +840 -0
- package/src/client/db-admin/TableBrowser.tsx +212 -0
- package/src/client/db-admin/TableEditor.tsx +760 -0
- package/src/client/db-admin/cell-format.ts +246 -0
- package/src/client/db-admin/changeset.ts +296 -0
- package/src/client/db-admin/export-utils.ts +78 -0
- package/src/client/db-admin/index.ts +33 -0
- package/src/client/db-admin/sql-storage.ts +134 -0
- package/src/client/db-admin/storage.ts +68 -0
- package/src/client/db-admin/useAgentSync.ts +226 -0
- package/src/client/db-admin/useDbAdmin.ts +294 -0
- package/src/client/dev-overlay/DevOverlay.tsx +576 -0
- package/src/client/dev-overlay/builtins.ts +40 -0
- package/src/client/dev-overlay/index.ts +23 -0
- package/src/client/dev-overlay/registry.ts +67 -0
- package/src/client/dev-overlay/types.ts +64 -0
- package/src/client/dev-overlay/use-dev-option.ts +78 -0
- package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
- package/src/client/dynamic-suggestions.ts +455 -0
- package/src/client/embed-auth.ts +544 -0
- package/src/client/embed.ts +54 -0
- package/src/client/error-capture.ts +690 -0
- package/src/client/error-format.ts +211 -0
- package/src/client/error-reporting.ts +100 -0
- package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
- package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
- package/src/client/extensions/EmbeddedExtension.tsx +604 -0
- package/src/client/extensions/ExtensionEditor.tsx +450 -0
- package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
- package/src/client/extensions/ExtensionSlot.tsx +345 -0
- package/src/client/extensions/ExtensionViewer.tsx +1502 -0
- package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
- package/src/client/extensions/ExtensionsListPage.tsx +432 -0
- package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
- package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
- package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
- package/src/client/extensions/delete-extension.ts +76 -0
- package/src/client/extensions/extension-load-error.ts +26 -0
- package/src/client/extensions/extension-order.ts +49 -0
- package/src/client/extensions/extension-popularity.ts +61 -0
- package/src/client/extensions/iframe-bridge.ts +377 -0
- package/src/client/extensions/index.ts +84 -0
- package/src/client/extensions/portable-extension.ts +712 -0
- package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
- package/src/client/feature-flags/helpers.ts +77 -0
- package/src/client/feature-flags/index.ts +13 -0
- package/src/client/feature-flags/types.ts +29 -0
- package/src/client/feature-flags/use-feature-flag.ts +26 -0
- package/src/client/feedback-context.ts +90 -0
- package/src/client/frame-protocol.ts +168 -0
- package/src/client/frame.ts +329 -0
- package/src/client/guided-questions.tsx +1152 -0
- package/src/client/history/VersionHistoryPanel.tsx +175 -0
- package/src/client/history/index.ts +21 -0
- package/src/client/history/use-history.ts +114 -0
- package/src/client/hooks/index.ts +46 -0
- package/src/client/host/index.ts +170 -0
- package/src/client/host-bridge.ts +1272 -0
- package/src/client/host-tools.ts +190 -0
- package/src/client/i18n.tsx +798 -0
- package/src/client/index.ts +370 -0
- package/src/client/integrations/IntegrationCard.tsx +186 -0
- package/src/client/integrations/IntegrationsPanel.tsx +633 -0
- package/src/client/integrations/api.ts +295 -0
- package/src/client/integrations/index.ts +29 -0
- package/src/client/integrations/useIntegrationStatus.ts +52 -0
- package/src/client/mcp-app-host.ts +720 -0
- package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
- package/src/client/navigation/index.ts +54 -0
- package/src/client/notifications/NotificationsBell.tsx +383 -0
- package/src/client/notifications/index.ts +1 -0
- package/src/client/observability/ObservabilityDashboard.tsx +890 -0
- package/src/client/observability/ThumbsFeedback.tsx +160 -0
- package/src/client/observability/index.ts +20 -0
- package/src/client/observability/useObservability.ts +266 -0
- package/src/client/onboarding/OnboardingBanner.tsx +73 -0
- package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
- package/src/client/onboarding/SetupButton.tsx +64 -0
- package/src/client/onboarding/index.ts +25 -0
- package/src/client/onboarding/use-onboarding.ts +164 -0
- package/src/client/onboarding/use-preview-mode.ts +40 -0
- package/src/client/org/InvitationBanner.tsx +148 -0
- package/src/client/org/OrgSwitcher.tsx +754 -0
- package/src/client/org/RequireActiveOrg.tsx +337 -0
- package/src/client/org/TeamPage.tsx +1432 -0
- package/src/client/org/hooks.ts +359 -0
- package/src/client/org/index.ts +70 -0
- package/src/client/org/workspace-app-links.ts +367 -0
- package/src/client/org-team/index.ts +1 -0
- package/src/client/progress/RunsTray.tsx +680 -0
- package/src/client/progress/index.ts +1 -0
- package/src/client/require-session.tsx +142 -0
- package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
- package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
- package/src/client/resources/McpIntegrationDialog.tsx +808 -0
- package/src/client/resources/McpServerDetail.tsx +230 -0
- package/src/client/resources/ResourceEditor.tsx +872 -0
- package/src/client/resources/ResourceTree.tsx +860 -0
- package/src/client/resources/ResourcesPanel.tsx +1960 -0
- package/src/client/resources/index.ts +25 -0
- package/src/client/resources/mcp-integration-catalog.ts +771 -0
- package/src/client/resources/mcp-integration-logos.ts +108 -0
- package/src/client/resources/runtime.ts +1 -0
- package/src/client/resources/use-builtin-capabilities.ts +113 -0
- package/src/client/resources/use-mcp-servers.ts +217 -0
- package/src/client/resources/use-resources.ts +402 -0
- package/src/client/review/ReviewCommentComposer.tsx +123 -0
- package/src/client/review/ReviewStatusBadge.tsx +39 -0
- package/src/client/review/ReviewThreadPanel.tsx +625 -0
- package/src/client/review/index.ts +38 -0
- package/src/client/review/use-review.ts +186 -0
- package/src/client/route-chunk-recovery/index.ts +1 -0
- package/src/client/route-chunk-recovery.ts +331 -0
- package/src/client/route-state.ts +455 -0
- package/src/client/route-warmup.tsx +543 -0
- package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
- package/src/client/session-replay.ts +3417 -0
- package/src/client/settings/AgentsSection.tsx +441 -0
- package/src/client/settings/AutomationsSection.tsx +516 -0
- package/src/client/settings/BackgroundAgentSection.tsx +189 -0
- package/src/client/settings/BrowserSection.tsx +110 -0
- package/src/client/settings/DemoModeSection.tsx +48 -0
- package/src/client/settings/SecretsSection.tsx +875 -0
- package/src/client/settings/SettingsPanel.tsx +3162 -0
- package/src/client/settings/SettingsSection.tsx +283 -0
- package/src/client/settings/SettingsTabsPage.tsx +592 -0
- package/src/client/settings/UsageSection.tsx +401 -0
- package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
- package/src/client/settings/agent-settings-search.ts +220 -0
- package/src/client/settings/index.ts +27 -0
- package/src/client/settings/useBuilderStatus.ts +1055 -0
- package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
- package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
- package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
- package/src/client/setup-connections/catalog.ts +6 -0
- package/src/client/setup-connections/index.ts +47 -0
- package/src/client/setup-connections/runtime.ts +1 -0
- package/src/client/sharing/ShareButton.tsx +1748 -0
- package/src/client/sharing/ShareDialog.tsx +846 -0
- package/src/client/sharing/VisibilityBadge.tsx +4 -0
- package/src/client/sharing/index.ts +2 -0
- package/src/client/sse-event-processor.ts +2002 -0
- package/src/client/terminal/AgentTerminal.tsx +488 -0
- package/src/client/terminal/index.ts +7 -0
- package/src/client/theme.ts +27 -0
- package/src/client/tombstone/agent-presence-chip.ts +17 -0
- package/src/client/tombstone/editor.ts +265 -0
- package/src/client/tombstone/live-cursor-overlay.ts +21 -0
- package/src/client/tombstone/presence-bar.ts +17 -0
- package/src/client/tombstone/recent-edit-highlights.ts +17 -0
- package/src/client/tombstone/remote-selection-rings.ts +21 -0
- package/src/client/tombstone/rich-markdown-editor.ts +265 -0
- package/src/client/tombstone/ui-dialog.ts +49 -0
- package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
- package/src/client/tombstone/ui-hover-card.ts +21 -0
- package/src/client/tombstone/ui-popover.ts +25 -0
- package/src/client/tombstone/ui-sheet.ts +49 -0
- package/src/client/tombstone/ui-tooltip.ts +29 -0
- package/src/client/tombstone/visual-style-controls.ts +61 -0
- package/src/client/tool-cells/BashCell.tsx +164 -0
- package/src/client/tool-cells/EditCell.tsx +303 -0
- package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
- package/src/client/tool-cells/WriteCell.tsx +145 -0
- package/src/client/tool-cells/index.ts +7 -0
- package/src/client/tool-display.ts +41 -0
- package/src/client/track.ts +57 -0
- package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
- package/src/client/transcription/use-live-transcription.ts +292 -0
- package/src/client/ui/index.ts +55 -0
- package/src/client/uploads/index.ts +6 -0
- package/src/client/uploads/upload-editor-image.ts +79 -0
- package/src/client/uploads/use-upload-resource.ts +24 -0
- package/src/client/url-scrub.ts +51 -0
- package/src/client/use-action.ts +766 -0
- package/src/client/use-agent-chat-context.ts +63 -0
- package/src/client/use-agent-chat-home-handoff.ts +207 -0
- package/src/client/use-agent-chat.ts +53 -0
- package/src/client/use-agent-engine-configured.ts +211 -0
- package/src/client/use-avatar.ts +127 -0
- package/src/client/use-change-version.ts +150 -0
- package/src/client/use-chat-models.ts +252 -0
- package/src/client/use-chat-threads.ts +1262 -0
- package/src/client/use-db-sync.ts +1112 -0
- package/src/client/use-demo-mode-status.ts +30 -0
- package/src/client/use-dev-mode.ts +177 -0
- package/src/client/use-external-value.ts +40 -0
- package/src/client/use-pausing-interval.ts +65 -0
- package/src/client/use-pinch-zoom.ts +202 -0
- package/src/client/use-run-stuck-detection.ts +427 -0
- package/src/client/use-send-to-agent-chat.ts +85 -0
- package/src/client/use-session.ts +114 -0
- package/src/client/utils.ts +7 -0
- package/src/client/visual-style-controls.tsx +1 -0
- package/src/client/vite-dev-recovery-script.ts +226 -0
- package/src/client/voice-provider-status.ts +44 -0
- package/src/client/widgets/index.ts +41 -0
- package/src/code-agents/background-controller.ts +398 -0
- package/src/code-agents/background-run.ts +156 -0
- package/src/code-agents/index.ts +95 -0
- package/src/code-agents/prompt-attachments.ts +39 -0
- package/src/code-agents/transcript-normalizer.ts +750 -0
- package/src/code-agents/transcript-order.ts +73 -0
- package/src/coding-tools/index.ts +742 -0
- package/src/coding-tools/run-code.ts +1662 -0
- package/src/coding-tools/sandbox/adapter.ts +82 -0
- package/src/coding-tools/sandbox/background.ts +406 -0
- package/src/coding-tools/sandbox/executions-store.ts +517 -0
- package/src/coding-tools/sandbox/index.ts +132 -0
- package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
- package/src/collab/agent-identity.ts +5 -0
- package/src/collab/agent-presence.ts +341 -0
- package/src/collab/awareness-store.ts +196 -0
- package/src/collab/awareness.ts +317 -0
- package/src/collab/client-struct.ts +366 -0
- package/src/collab/client.ts +1205 -0
- package/src/collab/emitter.ts +31 -0
- package/src/collab/follow-mode.ts +107 -0
- package/src/collab/index.ts +151 -0
- package/src/collab/json-to-yjs.ts +504 -0
- package/src/collab/presence.ts +207 -0
- package/src/collab/recent-edits.ts +215 -0
- package/src/collab/routes.ts +191 -0
- package/src/collab/storage.ts +228 -0
- package/src/collab/struct-routes.ts +133 -0
- package/src/collab/text-to-yjs.ts +79 -0
- package/src/collab/undo.ts +432 -0
- package/src/collab/xml-ops.ts +68 -0
- package/src/collab/ydoc-manager.ts +544 -0
- package/src/command-navigation/actions.ts +100 -0
- package/src/command-navigation/index.ts +12 -0
- package/src/comments-review/index.ts +1 -0
- package/src/connections/catalog.ts +451 -0
- package/src/connections/index.ts +48 -0
- package/src/connections/reader.ts +911 -0
- package/src/connections/runtime.ts +1 -0
- package/src/credentials/index.ts +187 -0
- package/src/data-programs/actions.ts +335 -0
- package/src/data-programs/contract.ts +284 -0
- package/src/data-programs/execute.ts +693 -0
- package/src/data-programs/index.ts +72 -0
- package/src/data-programs/schema.ts +148 -0
- package/src/data-programs/store.ts +755 -0
- package/src/data-widgets/index.ts +376 -0
- package/src/db/client.ts +1627 -0
- package/src/db/create-get-db.ts +579 -0
- package/src/db/ddl-guard.ts +302 -0
- package/src/db/drizzle-config.ts +190 -0
- package/src/db/ensure-additive-columns.ts +430 -0
- package/src/db/index.ts +57 -0
- package/src/db/migrations.ts +691 -0
- package/src/db/request-telemetry.ts +154 -0
- package/src/db/runtime-diagnostics.ts +331 -0
- package/src/db/schema.ts +121 -0
- package/src/db/widen-columns.ts +75 -0
- package/src/db-admin/agent-tools.ts +202 -0
- package/src/db-admin/index.ts +26 -0
- package/src/db-admin/operations.ts +803 -0
- package/src/db-admin/routes.ts +174 -0
- package/src/db-admin/types.ts +110 -0
- package/src/demo/browser-state.ts +47 -0
- package/src/demo/fetch-interceptor.ts +175 -0
- package/src/demo/redact.ts +575 -0
- package/src/deploy/build.ts +3935 -0
- package/src/deploy/immutable-assets.ts +65 -0
- package/src/deploy/route-discovery.ts +458 -0
- package/src/deploy/workspace-core.ts +282 -0
- package/src/deploy/workspace-deploy.ts +1488 -0
- package/src/eject/provider-api-definitions.ts +193 -0
- package/src/eject/remote-mcp-presets.ts +137 -0
- package/src/eject/setup-readiness-ui.tsx +29 -0
- package/src/eject/workspace-connections.ts +92 -0
- package/src/embedding/agent.ts +159 -0
- package/src/embedding/bridge.ts +297 -0
- package/src/embedding/index.ts +43 -0
- package/src/embedding/protocol.ts +185 -0
- package/src/embedding/react.tsx +319 -0
- package/src/embeddings/index.ts +233 -0
- package/src/eval/agent-runner.ts +210 -0
- package/src/eval/define-eval.ts +55 -0
- package/src/eval/index.ts +49 -0
- package/src/eval/report.ts +75 -0
- package/src/eval/runner.ts +369 -0
- package/src/eval/scorer.ts +244 -0
- package/src/eval/types.ts +188 -0
- package/src/event-bus/bus.ts +140 -0
- package/src/event-bus/index.ts +3 -0
- package/src/event-bus/registry.ts +79 -0
- package/src/event-bus/types.ts +29 -0
- package/src/extensions/actions.ts +1636 -0
- package/src/extensions/change-marker.ts +54 -0
- package/src/extensions/content-patch.ts +468 -0
- package/src/extensions/fetch-tool.ts +461 -0
- package/src/extensions/html-shell.ts +803 -0
- package/src/extensions/local.ts +462 -0
- package/src/extensions/path.ts +40 -0
- package/src/extensions/proxy-security.ts +171 -0
- package/src/extensions/routes.ts +1080 -0
- package/src/extensions/schema.ts +269 -0
- package/src/extensions/session-replay-iframe.ts +131 -0
- package/src/extensions/slots/routes.ts +126 -0
- package/src/extensions/slots/schema.ts +87 -0
- package/src/extensions/slots/store.ts +450 -0
- package/src/extensions/store.ts +1347 -0
- package/src/extensions/theme.ts +114 -0
- package/src/extensions/url-safety.ts +316 -0
- package/src/extensions/web-content.ts +663 -0
- package/src/extensions/web-search-tool.ts +437 -0
- package/src/feature-flags/a2a-action-route.ts +56 -0
- package/src/feature-flags/actions/get-feature-flags.ts +24 -0
- package/src/feature-flags/actions/list-feature-flags.ts +69 -0
- package/src/feature-flags/actions/set-feature-flag.ts +89 -0
- package/src/feature-flags/index.ts +21 -0
- package/src/feature-flags/permissions.ts +53 -0
- package/src/feature-flags/plugin.ts +44 -0
- package/src/feature-flags/registry.ts +96 -0
- package/src/feature-flags/store.ts +176 -0
- package/src/file-upload/actions/upload-image.ts +213 -0
- package/src/file-upload/builder.ts +431 -0
- package/src/file-upload/index.ts +24 -0
- package/src/file-upload/pre-upload-attachments.ts +305 -0
- package/src/file-upload/registry.ts +125 -0
- package/src/file-upload/types.ts +89 -0
- package/src/guards/db-tool-scoping.ts +129 -0
- package/src/guards/index.ts +23 -0
- package/src/guards/no-drizzle-push.ts +116 -0
- package/src/guards/no-env-credentials.ts +229 -0
- package/src/guards/no-env-mutation.ts +114 -0
- package/src/guards/no-localhost-fallback.ts +124 -0
- package/src/guards/no-unscoped-credentials.ts +227 -0
- package/src/guards/no-unscoped-queries.ts +834 -0
- package/src/guards/scan-utils.ts +105 -0
- package/src/guards/types.ts +30 -0
- package/src/history/actions/create-resource-version.ts +92 -0
- package/src/history/actions/get-resource-version.ts +60 -0
- package/src/history/actions/list-resource-history.ts +53 -0
- package/src/history/actions/list-resource-versions.ts +43 -0
- package/src/history/actions/restore-resource-version.ts +96 -0
- package/src/history/index.ts +26 -0
- package/src/history/registry.ts +111 -0
- package/src/history/store.ts +379 -0
- package/src/history/types.ts +69 -0
- package/src/index.browser.ts +155 -0
- package/src/index.ts +408 -0
- package/src/ingestion/docx.ts +158 -0
- package/src/ingestion/figma-node-to-html.ts +1860 -0
- package/src/ingestion/figma.ts +548 -0
- package/src/ingestion/index.ts +107 -0
- package/src/ingestion/media.ts +264 -0
- package/src/ingestion/notion.ts +121 -0
- package/src/ingestion/office.ts +213 -0
- package/src/ingestion/orchestration.ts +160 -0
- package/src/ingestion/pptx.ts +331 -0
- package/src/ingestion/selection.ts +81 -0
- package/src/ingestion/website.ts +151 -0
- package/src/integrations/a2a-continuation-marker.ts +2 -0
- package/src/integrations/a2a-continuation-processor.ts +888 -0
- package/src/integrations/a2a-continuations-store.ts +643 -0
- package/src/integrations/adapter-overrides.ts +12 -0
- package/src/integrations/adapters/discord.ts +364 -0
- package/src/integrations/adapters/email.ts +1164 -0
- package/src/integrations/adapters/google-docs.ts +371 -0
- package/src/integrations/adapters/index.ts +29 -0
- package/src/integrations/adapters/microsoft-teams.ts +413 -0
- package/src/integrations/adapters/slack.ts +1914 -0
- package/src/integrations/adapters/telegram.ts +386 -0
- package/src/integrations/adapters/whatsapp.ts +358 -0
- package/src/integrations/awaiting-input-store.ts +130 -0
- package/src/integrations/catalog.ts +571 -0
- package/src/integrations/computer-supervision-store.ts +423 -0
- package/src/integrations/computer-supervision.ts +213 -0
- package/src/integrations/config-store.ts +131 -0
- package/src/integrations/controls-store.ts +187 -0
- package/src/integrations/eject/messaging-adapters.ts +85 -0
- package/src/integrations/google-docs-poller.ts +671 -0
- package/src/integrations/identity-links-store.ts +210 -0
- package/src/integrations/identity.ts +196 -0
- package/src/integrations/index.ts +220 -0
- package/src/integrations/installations-store.ts +677 -0
- package/src/integrations/integration-memory.ts +187 -0
- package/src/integrations/internal-token.ts +106 -0
- package/src/integrations/pending-tasks-retry-job.ts +286 -0
- package/src/integrations/pending-tasks-store.ts +468 -0
- package/src/integrations/plugin.ts +3048 -0
- package/src/integrations/remote-commands-store.ts +690 -0
- package/src/integrations/remote-devices-store.ts +492 -0
- package/src/integrations/remote-json-safety.ts +127 -0
- package/src/integrations/remote-push-delivery-job.ts +48 -0
- package/src/integrations/remote-push-delivery.ts +370 -0
- package/src/integrations/remote-push-store.ts +664 -0
- package/src/integrations/remote-retry-job.ts +55 -0
- package/src/integrations/remote-run-events-store.ts +222 -0
- package/src/integrations/remote-types.ts +186 -0
- package/src/integrations/runtime.ts +1 -0
- package/src/integrations/scope-store.ts +498 -0
- package/src/integrations/slack-manifest.ts +78 -0
- package/src/integrations/slack-oauth.ts +344 -0
- package/src/integrations/task-queue-stats.ts +144 -0
- package/src/integrations/thread-mapping-store.ts +134 -0
- package/src/integrations/types.ts +485 -0
- package/src/integrations/usage-budget-store.ts +906 -0
- package/src/integrations/webhook-delivery.ts +55 -0
- package/src/integrations/webhook-handler.ts +1939 -0
- package/src/jobs/actions/list-recurring-jobs.ts +105 -0
- package/src/jobs/actions/manage-recurring-job.ts +85 -0
- package/src/jobs/cron.ts +126 -0
- package/src/jobs/index.ts +9 -0
- package/src/jobs/scheduler.ts +703 -0
- package/src/jobs/tools.ts +367 -0
- package/src/local-artifacts/index.ts +1372 -0
- package/src/localization/actions/get-localization-preference.ts +24 -0
- package/src/localization/actions/set-localization-preference.ts +32 -0
- package/src/localization/default-messages.ts +1009 -0
- package/src/localization/index.ts +2 -0
- package/src/localization/server.ts +131 -0
- package/src/localization/shared.ts +208 -0
- package/src/mcp/actions/call-mcp-tool.ts +19 -0
- package/src/mcp/actions/create-org-service-token.ts +87 -0
- package/src/mcp/actions/list-mcp-tools.ts +18 -0
- package/src/mcp/actions/list-org-service-tokens.ts +44 -0
- package/src/mcp/actions/revoke-org-service-token.ts +30 -0
- package/src/mcp/actions/service-token-access.ts +121 -0
- package/src/mcp/ask-app-inline-tasks.ts +125 -0
- package/src/mcp/build-server.ts +2356 -0
- package/src/mcp/builtin-tools.ts +1506 -0
- package/src/mcp/connect-route.ts +1460 -0
- package/src/mcp/connect-store.ts +680 -0
- package/src/mcp/embed-app.ts +2051 -0
- package/src/mcp/embed-route.ts +84 -0
- package/src/mcp/external-agent-policy.ts +18 -0
- package/src/mcp/index.ts +47 -0
- package/src/mcp/oauth-route.ts +1016 -0
- package/src/mcp/oauth-store.ts +581 -0
- package/src/mcp/oauth-token.ts +227 -0
- package/src/mcp/org-directory.ts +343 -0
- package/src/mcp/route-paths.ts +34 -0
- package/src/mcp/screen-memory-stdio.ts +290 -0
- package/src/mcp/server.ts +507 -0
- package/src/mcp/stdio.ts +328 -0
- package/src/mcp/workspace-resolve.ts +261 -0
- package/src/mcp-client/app-api.ts +136 -0
- package/src/mcp-client/app-result.ts +64 -0
- package/src/mcp-client/builtin-capabilities.ts +146 -0
- package/src/mcp-client/builtin-store.ts +93 -0
- package/src/mcp-client/config.ts +281 -0
- package/src/mcp-client/errors.ts +54 -0
- package/src/mcp-client/hub-client.ts +172 -0
- package/src/mcp-client/hub-routes.ts +198 -0
- package/src/mcp-client/index.ts +504 -0
- package/src/mcp-client/manager.ts +968 -0
- package/src/mcp-client/oauth-client.ts +462 -0
- package/src/mcp-client/oauth-routes.ts +307 -0
- package/src/mcp-client/remote-store.ts +674 -0
- package/src/mcp-client/remote-url.ts +97 -0
- package/src/mcp-client/routes.ts +1093 -0
- package/src/mcp-client/screen-memory-local.ts +461 -0
- package/src/mcp-client/tool-policy.ts +182 -0
- package/src/mcp-client/visibility.ts +56 -0
- package/src/mcp-client/workspace-servers.ts +379 -0
- package/src/navigation/index.ts +170 -0
- package/src/notifications/actions.ts +151 -0
- package/src/notifications/channels.ts +410 -0
- package/src/notifications/index.ts +22 -0
- package/src/notifications/registry.ts +216 -0
- package/src/notifications/routes.ts +106 -0
- package/src/notifications/store.ts +236 -0
- package/src/notifications/types.ts +52 -0
- package/src/oauth-tokens/google-refresh.ts +175 -0
- package/src/oauth-tokens/index.ts +15 -0
- package/src/oauth-tokens/store.ts +384 -0
- package/src/observability/cleanup-job.ts +124 -0
- package/src/observability/evals.ts +507 -0
- package/src/observability/experiments.ts +359 -0
- package/src/observability/feedback.ts +332 -0
- package/src/observability/hosted-model-experiment.ts +118 -0
- package/src/observability/index.ts +62 -0
- package/src/observability/plugin.ts +31 -0
- package/src/observability/routes.ts +431 -0
- package/src/observability/sentiment.ts +261 -0
- package/src/observability/store.ts +1347 -0
- package/src/observability/traces.ts +789 -0
- package/src/observability/tracing.ts +157 -0
- package/src/observability/tracking-identity.ts +55 -0
- package/src/observability/types.ts +211 -0
- package/src/onboarding/default-steps.ts +428 -0
- package/src/onboarding/index.ts +22 -0
- package/src/onboarding/plugin.ts +262 -0
- package/src/onboarding/registry.ts +47 -0
- package/src/onboarding/types.ts +96 -0
- package/src/org/accept-pending.ts +98 -0
- package/src/org/auto-join-domain.ts +113 -0
- package/src/org/context.ts +614 -0
- package/src/org/free-email-providers.ts +124 -0
- package/src/org/handlers.ts +1153 -0
- package/src/org/index.ts +63 -0
- package/src/org/migrations.ts +105 -0
- package/src/org/permissions.ts +30 -0
- package/src/org/plugin.ts +255 -0
- package/src/org/schema.ts +28 -0
- package/src/org/types.ts +57 -0
- package/src/org-team/index.ts +1 -0
- package/src/package-lifecycle/deprecated-imports.ts +179 -0
- package/src/package-lifecycle/eject-manifest.ts +345 -0
- package/src/package-lifecycle/index.ts +7 -0
- package/src/package-lifecycle/manifest.ts +120 -0
- package/src/package-lifecycle/migration-manifest.ts +159 -0
- package/src/package-lifecycle/migration-message.ts +6 -0
- package/src/package-lifecycle/tombstone.ts +58 -0
- package/src/package-lifecycle/upgrade-error.ts +37 -0
- package/src/private-blob/index.ts +18 -0
- package/src/private-blob/registry.ts +242 -0
- package/src/private-blob/types.ts +55 -0
- package/src/progress/actions.ts +179 -0
- package/src/progress/index.ts +16 -0
- package/src/progress/registry.ts +127 -0
- package/src/progress/routes.ts +89 -0
- package/src/progress/store.ts +353 -0
- package/src/progress/types.ts +59 -0
- package/src/provider-api/actions/custom-provider-registration.ts +197 -0
- package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
- package/src/provider-api/actions/github-repo-files.ts +266 -0
- package/src/provider-api/actions/list-staged-datasets.ts +5 -0
- package/src/provider-api/actions/provider-api-audit.ts +88 -0
- package/src/provider-api/actions/provider-api.ts +460 -0
- package/src/provider-api/actions/query-staged-dataset.ts +5 -0
- package/src/provider-api/actions/staged-datasets.ts +359 -0
- package/src/provider-api/corpus-jobs-store.ts +522 -0
- package/src/provider-api/corpus-jobs.ts +1817 -0
- package/src/provider-api/custom-registry.ts +456 -0
- package/src/provider-api/github-repo.ts +675 -0
- package/src/provider-api/gong.ts +108 -0
- package/src/provider-api/index.ts +5444 -0
- package/src/provider-api/quota-governor.ts +562 -0
- package/src/provider-api/runtime.ts +1 -0
- package/src/provider-api/staged-datasets-aggregate.ts +304 -0
- package/src/provider-api/staged-datasets-store.ts +441 -0
- package/src/provider-api/staging.ts +483 -0
- package/src/resources/agents.ts +65 -0
- package/src/resources/emitter.ts +54 -0
- package/src/resources/handlers.ts +728 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/metadata.ts +252 -0
- package/src/resources/script-helpers.ts +160 -0
- package/src/resources/store.ts +1618 -0
- package/src/review/actions/consume-review-feedback.ts +48 -0
- package/src/review/actions/create-review-comment.ts +108 -0
- package/src/review/actions/delete-review-comment.ts +67 -0
- package/src/review/actions/get-review-feedback.ts +49 -0
- package/src/review/actions/list-review-comments.ts +87 -0
- package/src/review/actions/reply-review-comment.ts +118 -0
- package/src/review/actions/resolve-review-thread.ts +94 -0
- package/src/review/actions/send-review-thread-to-agent.ts +62 -0
- package/src/review/actions/set-review-status.ts +58 -0
- package/src/review/identity.ts +101 -0
- package/src/review/index.ts +45 -0
- package/src/review/mentions.ts +44 -0
- package/src/review/registry.ts +111 -0
- package/src/review/store.ts +997 -0
- package/src/review/types.ts +101 -0
- package/src/router/index.ts +24 -0
- package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
- package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
- package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
- package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
- package/src/scripts/call-agent.ts +792 -0
- package/src/scripts/chat/index.ts +8 -0
- package/src/scripts/chat/open-chat.ts +56 -0
- package/src/scripts/chat/search-chats.ts +121 -0
- package/src/scripts/core-scripts.ts +22 -0
- package/src/scripts/db/check-scoping.ts +212 -0
- package/src/scripts/db/exec.ts +791 -0
- package/src/scripts/db/index.ts +19 -0
- package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
- package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
- package/src/scripts/db/migrate-user-api-keys.ts +257 -0
- package/src/scripts/db/patch.ts +820 -0
- package/src/scripts/db/query.ts +299 -0
- package/src/scripts/db/reset-dev-owner.ts +285 -0
- package/src/scripts/db/safety.ts +286 -0
- package/src/scripts/db/schema.ts +364 -0
- package/src/scripts/db/scoping.ts +341 -0
- package/src/scripts/db/sqlite-client.ts +78 -0
- package/src/scripts/db/tool-mode.ts +23 -0
- package/src/scripts/db/tool-schemas.ts +31 -0
- package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
- package/src/scripts/dev/index.ts +296 -0
- package/src/scripts/dev/list-files.ts +119 -0
- package/src/scripts/dev/read-file.ts +77 -0
- package/src/scripts/dev/search-files.ts +151 -0
- package/src/scripts/dev/shell.ts +111 -0
- package/src/scripts/dev/write-file.ts +56 -0
- package/src/scripts/dev-session.ts +96 -0
- package/src/scripts/docs/index.ts +8 -0
- package/src/scripts/docs/search.ts +274 -0
- package/src/scripts/docs/source-search.ts +363 -0
- package/src/scripts/index.ts +15 -0
- package/src/scripts/manage-agent-loop-settings.ts +84 -0
- package/src/scripts/parse-args.ts +46 -0
- package/src/scripts/resources/delete-memory.ts +67 -0
- package/src/scripts/resources/delete.ts +69 -0
- package/src/scripts/resources/effective.ts +71 -0
- package/src/scripts/resources/index.ts +18 -0
- package/src/scripts/resources/list.ts +103 -0
- package/src/scripts/resources/migrate-learnings.ts +40 -0
- package/src/scripts/resources/read.ts +107 -0
- package/src/scripts/resources/save-memory.ts +99 -0
- package/src/scripts/resources/write.ts +158 -0
- package/src/scripts/runner.ts +339 -0
- package/src/scripts/utils.ts +130 -0
- package/src/search/index.ts +413 -0
- package/src/search-utils/index.ts +112 -0
- package/src/secrets/crypto.ts +228 -0
- package/src/secrets/index.ts +65 -0
- package/src/secrets/onboarding.ts +101 -0
- package/src/secrets/register-framework-secrets.ts +228 -0
- package/src/secrets/register.ts +129 -0
- package/src/secrets/routes.ts +697 -0
- package/src/secrets/schema.ts +52 -0
- package/src/secrets/storage.ts +561 -0
- package/src/secrets/substitution.ts +305 -0
- package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
- package/src/server/action-change.ts +66 -0
- package/src/server/action-discovery.ts +774 -0
- package/src/server/action-routes.ts +608 -0
- package/src/server/agent-access.ts +72 -0
- package/src/server/agent-chat/action-filters-a2a.ts +339 -0
- package/src/server/agent-chat/browser-team-tools.ts +510 -0
- package/src/server/agent-chat/context-tools.ts +599 -0
- package/src/server/agent-chat/framework-prompts.ts +467 -0
- package/src/server/agent-chat/lazy-fs.ts +11 -0
- package/src/server/agent-chat/mcp-glue.ts +91 -0
- package/src/server/agent-chat/plugin-options.ts +379 -0
- package/src/server/agent-chat/process-run-failure.ts +62 -0
- package/src/server/agent-chat/prompt-resources.ts +1004 -0
- package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
- package/src/server/agent-chat/request-surface.ts +71 -0
- package/src/server/agent-chat/run-code-tools.ts +67 -0
- package/src/server/agent-chat/script-entries.ts +796 -0
- package/src/server/agent-chat/shared-thread.ts +301 -0
- package/src/server/agent-chat/skill-frontmatter.ts +41 -0
- package/src/server/agent-chat-plugin.ts +5930 -0
- package/src/server/agent-discovery.ts +706 -0
- package/src/server/agent-engine-api-key-route.ts +236 -0
- package/src/server/agent-run-context.ts +204 -0
- package/src/server/agent-teams-run-queue.ts +344 -0
- package/src/server/agent-teams.ts +2257 -0
- package/src/server/agents-bundle.ts +464 -0
- package/src/server/analytics.ts +105 -0
- package/src/server/app-base-path.ts +79 -0
- package/src/server/app-name.ts +53 -0
- package/src/server/app-url.ts +184 -0
- package/src/server/attachment-actions.ts +276 -0
- package/src/server/attribution.ts +214 -0
- package/src/server/auth-marketing.ts +260 -0
- package/src/server/auth-plugin.ts +27 -0
- package/src/server/auth.ts +3803 -0
- package/src/server/better-auth-instance.ts +1197 -0
- package/src/server/builder-browser.ts +1701 -0
- package/src/server/builder-design-systems.ts +668 -0
- package/src/server/builder-space.ts +176 -0
- package/src/server/captcha.ts +63 -0
- package/src/server/capture-error.ts +64 -0
- package/src/server/cli-capture.ts +141 -0
- package/src/server/collab-plugin.ts +391 -0
- package/src/server/complete-text.ts +231 -0
- package/src/server/cookie-namespace.ts +159 -0
- package/src/server/core-routes-plugin.ts +4122 -0
- package/src/server/cors-origins.ts +60 -0
- package/src/server/create-server.ts +268 -0
- package/src/server/credential-provider.ts +1202 -0
- package/src/server/csrf.ts +229 -0
- package/src/server/date-utils.ts +42 -0
- package/src/server/deep-link.ts +119 -0
- package/src/server/derived-secret.ts +32 -0
- package/src/server/design-token-utils.ts +1032 -0
- package/src/server/desktop-sso.ts +83 -0
- package/src/server/edge.ts +69 -0
- package/src/server/email-actions.ts +218 -0
- package/src/server/email-template.ts +192 -0
- package/src/server/email-templates.ts +148 -0
- package/src/server/email.ts +219 -0
- package/src/server/embed-route.ts +283 -0
- package/src/server/embed-session.ts +805 -0
- package/src/server/embedded.ts +252 -0
- package/src/server/entry-server.tsx +154 -0
- package/src/server/framework-request-handler.ts +848 -0
- package/src/server/fusion-app.ts +447 -0
- package/src/server/google-auth-mode.ts +34 -0
- package/src/server/google-auth-plugin.ts +496 -0
- package/src/server/google-oauth-credentials.ts +128 -0
- package/src/server/google-oauth.ts +972 -0
- package/src/server/google-realtime-session.ts +182 -0
- package/src/server/h3-helpers.ts +174 -0
- package/src/server/http-response-telemetry.ts +396 -0
- package/src/server/identity-sso-store.ts +304 -0
- package/src/server/identity-sso.ts +514 -0
- package/src/server/index.ts +593 -0
- package/src/server/missing-key.ts +36 -0
- package/src/server/oauth-helpers.ts +44 -0
- package/src/server/oauth-public-origin.ts +44 -0
- package/src/server/oauth-return-url.ts +120 -0
- package/src/server/og-fonts-data.ts +15 -0
- package/src/server/og-fonts.ts +75 -0
- package/src/server/onboarding-html.ts +4040 -0
- package/src/server/open-route.ts +311 -0
- package/src/server/org-admin.ts +28 -0
- package/src/server/poll-events.ts +88 -0
- package/src/server/poll.ts +1224 -0
- package/src/server/prompts/framework-core-compact.ts +107 -0
- package/src/server/prompts/framework-core.ts +143 -0
- package/src/server/prompts/index.ts +16 -0
- package/src/server/prompts/model-overlays.ts +54 -0
- package/src/server/prompts/shared-rules.ts +104 -0
- package/src/server/realtime-voice.ts +967 -0
- package/src/server/recap-image-route.ts +242 -0
- package/src/server/recap-image-store.ts +185 -0
- package/src/server/request-context.ts +416 -0
- package/src/server/request-origin.ts +67 -0
- package/src/server/resources-plugin.ts +119 -0
- package/src/server/schema-prompt.ts +429 -0
- package/src/server/scoped-key-storage.ts +223 -0
- package/src/server/security-headers.ts +170 -0
- package/src/server/self-dispatch.ts +224 -0
- package/src/server/sentry-config.ts +73 -0
- package/src/server/sentry-plugin.ts +138 -0
- package/src/server/sentry.ts +444 -0
- package/src/server/short-lived-token.ts +170 -0
- package/src/server/social-og-image.ts +454 -0
- package/src/server/sse.ts +102 -0
- package/src/server/ssr-handler.ts +466 -0
- package/src/server/transcribe-voice.ts +1076 -0
- package/src/server/voice-providers-status.ts +118 -0
- package/src/server/workspace-oauth.ts +31 -0
- package/src/server/workspace-provider-oauth.ts +970 -0
- package/src/session-replay-iframe-protocol.ts +58 -0
- package/src/settings/handlers.ts +44 -0
- package/src/settings/index.ts +34 -0
- package/src/settings/org-settings.ts +83 -0
- package/src/settings/script-helpers.ts +24 -0
- package/src/settings/store.ts +247 -0
- package/src/settings/user-settings.ts +47 -0
- package/src/setup-connections/index.ts +90 -0
- package/src/setup-connections/onboarding.ts +47 -0
- package/src/shared/agent-access.ts +112 -0
- package/src/shared/agent-chat.ts +124 -0
- package/src/shared/agent-env.ts +46 -0
- package/src/shared/agent-readable-resource.ts +111 -0
- package/src/shared/agent-sidebar-url.ts +39 -0
- package/src/shared/cache-control.ts +25 -0
- package/src/shared/cloudflare-globals.d.ts +34 -0
- package/src/shared/context-xray.ts +172 -0
- package/src/shared/embed-auth.ts +6 -0
- package/src/shared/index.ts +83 -0
- package/src/shared/llm-connection.ts +42 -0
- package/src/shared/markdown-block-split.ts +129 -0
- package/src/shared/mcp-connect-content.ts +130 -0
- package/src/shared/mcp-embed-headers.ts +175 -0
- package/src/shared/mcp-integration-config.ts +101 -0
- package/src/shared/merge-by-id.ts +14 -0
- package/src/shared/oauth-state.ts +39 -0
- package/src/shared/reasoning-effort.ts +228 -0
- package/src/shared/route-warmup-config.ts +128 -0
- package/src/shared/runtime.ts +31 -0
- package/src/shared/social-meta.ts +82 -0
- package/src/shared/streaming-text-smoothing.ts +184 -0
- package/src/shared/truncate.ts +13 -0
- package/src/shared/workspace-app-audience.ts +177 -0
- package/src/shared/workspace-app-id.ts +54 -0
- package/src/sharing/access.ts +585 -0
- package/src/sharing/actions/create-agent-resource-link.ts +91 -0
- package/src/sharing/actions/extension-change.ts +22 -0
- package/src/sharing/actions/list-resource-shares.ts +93 -0
- package/src/sharing/actions/set-resource-visibility.ts +91 -0
- package/src/sharing/actions/share-resource.ts +322 -0
- package/src/sharing/actions/unshare-resource.ts +72 -0
- package/src/sharing/index.ts +35 -0
- package/src/sharing/registry.ts +201 -0
- package/src/sharing/schema.ts +99 -0
- package/src/styles/agent-conversation.css +766 -0
- package/src/styles/agent-native.css +938 -0
- package/src/styles/blocks.css +1717 -0
- package/src/styles/chat-history-list.css +1 -0
- package/src/styles/rich-markdown-editor.css +1 -0
- package/src/tailwind.preset.ts +140 -0
- package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/chat/AGENTS.md +3 -2
- package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/default/AGENTS.md +6 -5
- package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/headless/AGENTS.md +5 -4
- package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
- package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
- package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
- package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
- package/src/templates/workspace-core/AGENTS.md +4 -4
- package/src/templates/workspace-root/AGENTS.md +4 -4
- package/src/terminal/cli-registry.ts +57 -0
- package/src/terminal/index.ts +22 -0
- package/src/terminal/pty-server.ts +389 -0
- package/src/terminal/terminal-plugin.ts +265 -0
- package/src/testing.ts +23 -0
- package/src/tracking/index.ts +10 -0
- package/src/tracking/providers.ts +422 -0
- package/src/tracking/registry.ts +102 -0
- package/src/tracking/route.ts +108 -0
- package/src/tracking/types.ts +16 -0
- package/src/transcription/builder-transcription.ts +118 -0
- package/src/triggers/actions/list-automations.ts +99 -0
- package/src/triggers/actions/manage-automation.ts +78 -0
- package/src/triggers/actions.ts +333 -0
- package/src/triggers/condition-evaluator.ts +163 -0
- package/src/triggers/dispatcher.ts +536 -0
- package/src/triggers/index.ts +13 -0
- package/src/triggers/routes.ts +322 -0
- package/src/triggers/types.ts +42 -0
- package/src/types/pglite.d.ts +26 -0
- package/src/usage/store.ts +698 -0
- package/src/vite/action-types-plugin.ts +481 -0
- package/src/vite/agent-web-plugin.ts +78 -0
- package/src/vite/agents-bundle-plugin.ts +185 -0
- package/src/vite/client.ts +3039 -0
- package/src/vite/index.ts +21 -0
- package/src/voice/index.ts +18 -0
- package/src/voice/voice-cleanup-prompt.ts +38 -0
- package/src/voice/voice-context.ts +217 -0
- package/src/voice/voice-replacements.ts +75 -0
- package/src/workspace-connections/credentials.ts +603 -0
- package/src/workspace-connections/index.ts +72 -0
- package/src/workspace-connections/lifecycle.ts +43 -0
- package/src/workspace-connections/store.ts +1943 -0
- package/src/workspace-files/index.ts +18 -0
- package/src/workspace-files/store.ts +339 -0
- package/src/workspace-files/tool.ts +266 -0
|
@@ -0,0 +1,1757 @@
|
|
|
1
|
+
import * as amplitude from "@amplitude/analytics-browser";
|
|
2
|
+
import * as Sentry from "@sentry/browser";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
llmConnectionTrackingProperties,
|
|
6
|
+
type LlmConnectionStatus,
|
|
7
|
+
} from "../shared/llm-connection.js";
|
|
8
|
+
import {
|
|
9
|
+
getOrCreateAnalyticsAnonymousId,
|
|
10
|
+
getOrCreateAnalyticsSessionId,
|
|
11
|
+
} from "./analytics-session.js";
|
|
12
|
+
import { agentNativePath } from "./api-path.js";
|
|
13
|
+
import {
|
|
14
|
+
installErrorCapture,
|
|
15
|
+
type CapturedExceptionEvent,
|
|
16
|
+
} from "./error-capture.js";
|
|
17
|
+
import type {
|
|
18
|
+
SessionReplayOptions,
|
|
19
|
+
SessionReplayStartResult,
|
|
20
|
+
} from "./session-replay.js";
|
|
21
|
+
import { scrubUrl } from "./url-scrub.js";
|
|
22
|
+
export { scrubUrl } from "./url-scrub.js";
|
|
23
|
+
export {
|
|
24
|
+
addErrorBreadcrumb,
|
|
25
|
+
captureException,
|
|
26
|
+
captureMessage,
|
|
27
|
+
isErrorCaptureInstalled,
|
|
28
|
+
type CaptureExceptionContext,
|
|
29
|
+
type CapturedExceptionEvent,
|
|
30
|
+
type ExceptionBreadcrumb,
|
|
31
|
+
type ExceptionLevel,
|
|
32
|
+
} from "./error-capture.js";
|
|
33
|
+
export type {
|
|
34
|
+
SessionReplayConsoleOptions,
|
|
35
|
+
SessionReplayNetworkOptions,
|
|
36
|
+
SessionReplayOptions,
|
|
37
|
+
SessionReplayStartResult,
|
|
38
|
+
SessionReplayContext,
|
|
39
|
+
SessionReplayLinkOptions,
|
|
40
|
+
SessionReplayUrlMatcher,
|
|
41
|
+
} from "./session-replay.js";
|
|
42
|
+
export {
|
|
43
|
+
getSessionReplayContext,
|
|
44
|
+
getSessionReplayUrl,
|
|
45
|
+
} from "./session-replay.js";
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
gtag?: (...args: any[]) => void;
|
|
50
|
+
__AGENT_NATIVE_CONFIG__?: {
|
|
51
|
+
sentryDsn?: string;
|
|
52
|
+
sentryEnvironment?: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type GetDefaultProps = (
|
|
58
|
+
name: string,
|
|
59
|
+
properties: Record<string, unknown>,
|
|
60
|
+
) => Record<string, unknown>;
|
|
61
|
+
|
|
62
|
+
type PageviewTrackingState = {
|
|
63
|
+
installed: boolean;
|
|
64
|
+
lastPageviewKey: string | null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type AgentChatTrackingState = {
|
|
68
|
+
seen: Map<string, number>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* First-party, Sentry-style error capture configuration. Pass `true`/`false`
|
|
73
|
+
* to force on/off, or an options object to tune it. When omitted, error
|
|
74
|
+
* capture auto-enables whenever a first-party analytics public key is
|
|
75
|
+
* configured (mirroring pageview + session-replay auto-enable).
|
|
76
|
+
*/
|
|
77
|
+
export type ErrorCaptureConfigOptions = {
|
|
78
|
+
/** Build/release identifier attached to every captured exception. */
|
|
79
|
+
release?: string;
|
|
80
|
+
/** Deployment environment (e.g. "production"). Defaults to Vite MODE. */
|
|
81
|
+
environment?: string;
|
|
82
|
+
/** Auto-capture `window.onerror`. Defaults to true. */
|
|
83
|
+
captureGlobalErrors?: boolean;
|
|
84
|
+
/** Auto-capture `unhandledrejection`. Defaults to true. */
|
|
85
|
+
captureUnhandledRejections?: boolean;
|
|
86
|
+
/** Breadcrumb ring-buffer size. Defaults to 20. */
|
|
87
|
+
maxBreadcrumbs?: number;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type ConfigureTrackingOptions = {
|
|
91
|
+
/**
|
|
92
|
+
* Agent Native first-party analytics public key. This mirrors hosted
|
|
93
|
+
* analytics SDKs where consumers pass the key at setup time instead of
|
|
94
|
+
* relying on build-time environment variables.
|
|
95
|
+
*/
|
|
96
|
+
key?: string;
|
|
97
|
+
/** Alias for `key`, matching the replay ingest payload name. */
|
|
98
|
+
publicKey?: string;
|
|
99
|
+
/** First-party analytics track endpoint. */
|
|
100
|
+
endpoint?: string;
|
|
101
|
+
getDefaultProps?: GetDefaultProps;
|
|
102
|
+
/**
|
|
103
|
+
* Disable content-capturing analytics such as interaction autocapture and
|
|
104
|
+
* session replay while retaining pageviews, explicit events, and Sentry.
|
|
105
|
+
*/
|
|
106
|
+
contentCapture?: boolean;
|
|
107
|
+
/** Resolve content capture synchronously for each browser pathname. */
|
|
108
|
+
contentCaptureForPath?: (pathname: string) => boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Whether tracking may read the authenticated agent-engine status endpoint.
|
|
111
|
+
* Disable this on anonymous/public routes to avoid an expected 401 request.
|
|
112
|
+
*/
|
|
113
|
+
llmConnectionStatus?: boolean;
|
|
114
|
+
/** Disable framework auth refresh when the host owns identity/session state. */
|
|
115
|
+
authSessionRefresh?: boolean;
|
|
116
|
+
/** Disable automatic history/pageview events when the host emits its own. */
|
|
117
|
+
pageviewTracking?: boolean;
|
|
118
|
+
sessionReplay?: boolean | SessionReplayOptions;
|
|
119
|
+
/**
|
|
120
|
+
* First-party, Sentry-style error capture. Auto-captures uncaught errors
|
|
121
|
+
* and unhandled rejections and exposes `captureException`/`captureMessage`.
|
|
122
|
+
* Auto-enables when a public key is present; pass `false` to disable.
|
|
123
|
+
*/
|
|
124
|
+
errorCapture?: boolean | ErrorCaptureConfigOptions;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type TrackingIdentityUser = {
|
|
128
|
+
id?: string;
|
|
129
|
+
email?: string;
|
|
130
|
+
username?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
type TrackingIdentity = {
|
|
134
|
+
userId?: string;
|
|
135
|
+
userEmail?: string;
|
|
136
|
+
userName?: string;
|
|
137
|
+
orgId?: string | null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
let _getDefaultProps: GetDefaultProps | null = null;
|
|
141
|
+
let _agentNativeAnalyticsPublicKey: string | null = null;
|
|
142
|
+
let _agentNativeAnalyticsEndpoint: string | null = null;
|
|
143
|
+
let _amplitudeInitialized = false;
|
|
144
|
+
let _sentryInitialized = false;
|
|
145
|
+
let _llmConnectionStatus: LlmConnectionStatus | null = null;
|
|
146
|
+
let _llmConnectionRefresh: Promise<void> | null = null;
|
|
147
|
+
let _llmConnectionRefreshInstalled = false;
|
|
148
|
+
let _trackingIdentity: TrackingIdentity | null = null;
|
|
149
|
+
let _trackingIdentityResolved = false;
|
|
150
|
+
let _trackingSessionRefresh: Promise<void> | null = null;
|
|
151
|
+
let _trackingSessionRefreshInstalled = false;
|
|
152
|
+
let _sessionReplayOptions: SessionReplayOptions | null = null;
|
|
153
|
+
let _sessionReplayIdentitySnapshot: TrackingIdentity | null = null;
|
|
154
|
+
let _sessionReplayStartPromise: Promise<SessionReplayStartResult | null> | null =
|
|
155
|
+
null;
|
|
156
|
+
let _errorCaptureInstalled = false;
|
|
157
|
+
let _errorCaptureDisposer: (() => void) | null = null;
|
|
158
|
+
let _sessionReplayModuleForCapture:
|
|
159
|
+
| typeof import("./session-replay.js")
|
|
160
|
+
| null = null;
|
|
161
|
+
let _trackingContentCaptureEnabled = true;
|
|
162
|
+
let _contentCaptureForPath: ((pathname: string) => boolean) | null = null;
|
|
163
|
+
// Buffer for setSentryUser calls made before Sentry has initialized.
|
|
164
|
+
// `undefined` means "no pending update"; `null` means "pending clear".
|
|
165
|
+
let _pendingSentryUser: TrackingIdentityUser | null | undefined = undefined;
|
|
166
|
+
let _pendingSentryOrgId: string | null | undefined = undefined;
|
|
167
|
+
|
|
168
|
+
const AGENT_NATIVE_ANALYTICS_DEFAULT_ENDPOINT =
|
|
169
|
+
"https://analytics.agent-native.com/track";
|
|
170
|
+
/**
|
|
171
|
+
* Dedicated first-party analytics event name for captured exceptions. The
|
|
172
|
+
* analytics server ingest forks events with this name into the error-capture
|
|
173
|
+
* tables (error_issues / error_events) while still recording them in
|
|
174
|
+
* analytics_events for alerting. Keep in sync with the template server ingest.
|
|
175
|
+
*/
|
|
176
|
+
export const AGENT_NATIVE_EXCEPTION_EVENT_NAME = "$exception";
|
|
177
|
+
const PAGEVIEW_TRACKING_STATE_KEY = Symbol.for(
|
|
178
|
+
"agent-native.client.pageviewTracking",
|
|
179
|
+
);
|
|
180
|
+
const AGENT_CHAT_TRACKING_STATE_KEY = Symbol.for(
|
|
181
|
+
"agent-native.client.agentChatTracking",
|
|
182
|
+
);
|
|
183
|
+
const AGENT_CHAT_LIFECYCLE_DEDUPE_TTL_MS = 10 * 60 * 1_000;
|
|
184
|
+
const MAX_AGENT_CHAT_LIFECYCLE_DEDUPE_KEYS = 1_000;
|
|
185
|
+
|
|
186
|
+
const LLM_CONNECTION_STORAGE_KEY = "agent-native.llm_connection_status";
|
|
187
|
+
const LLM_CONNECTION_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
188
|
+
|
|
189
|
+
// First-touch referral attribution (viral attribution). Captured once on the
|
|
190
|
+
// visitor's first page load and persisted across the signup boundary so the
|
|
191
|
+
// server-side `signup` event can record where the user came from. First-write
|
|
192
|
+
// wins — an existing value is never overwritten.
|
|
193
|
+
const FIRST_TOUCH_STORAGE_KEY = "an_attribution";
|
|
194
|
+
const FIRST_TOUCH_COOKIE_NAME = "an_ft";
|
|
195
|
+
// 30 days, matching the session cookie lifetime — long enough to bridge a
|
|
196
|
+
// "land today, sign up next week" path without retaining attribution forever.
|
|
197
|
+
const FIRST_TOUCH_COOKIE_MAX_AGE_SECONDS = 2592000;
|
|
198
|
+
const FIRST_TOUCH_MAX_FIELD_LENGTH = 120;
|
|
199
|
+
// Keep the serialized cookie well under the ~4KB browser cap; we bail rather
|
|
200
|
+
// than write a runaway cookie if some field combination blows past this.
|
|
201
|
+
const FIRST_TOUCH_MAX_COOKIE_BYTES = 1500;
|
|
202
|
+
const FIRST_TOUCH_QUERY_FIELDS = [
|
|
203
|
+
"ref",
|
|
204
|
+
"via",
|
|
205
|
+
"utm_source",
|
|
206
|
+
"utm_medium",
|
|
207
|
+
"utm_campaign",
|
|
208
|
+
"utm_content",
|
|
209
|
+
"utm_term",
|
|
210
|
+
] as const;
|
|
211
|
+
|
|
212
|
+
let _firstTouchCaptured = false;
|
|
213
|
+
|
|
214
|
+
export interface FirstTouchAttribution {
|
|
215
|
+
ref?: string;
|
|
216
|
+
via?: string;
|
|
217
|
+
utm_source?: string;
|
|
218
|
+
utm_medium?: string;
|
|
219
|
+
utm_campaign?: string;
|
|
220
|
+
utm_content?: string;
|
|
221
|
+
utm_term?: string;
|
|
222
|
+
landing_path?: string;
|
|
223
|
+
landing_referrer?: string;
|
|
224
|
+
landed_at?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function safeStorageGet(key: string): string | null {
|
|
228
|
+
try {
|
|
229
|
+
return window.localStorage.getItem(key);
|
|
230
|
+
} catch {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function safeStorageSet(key: string, value: string): void {
|
|
236
|
+
try {
|
|
237
|
+
window.localStorage.setItem(key, value);
|
|
238
|
+
} catch {
|
|
239
|
+
// private browsing / storage disabled — best-effort
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function readCachedLlmConnectionStatus(): LlmConnectionStatus | null {
|
|
244
|
+
if (typeof window === "undefined") return null;
|
|
245
|
+
const raw = safeStorageGet(LLM_CONNECTION_STORAGE_KEY);
|
|
246
|
+
if (!raw) return null;
|
|
247
|
+
try {
|
|
248
|
+
const parsed = JSON.parse(raw) as LlmConnectionStatus & {
|
|
249
|
+
cachedAt?: number;
|
|
250
|
+
};
|
|
251
|
+
if (
|
|
252
|
+
typeof parsed.cachedAt !== "number" ||
|
|
253
|
+
Date.now() - parsed.cachedAt > LLM_CONNECTION_CACHE_TTL_MS
|
|
254
|
+
) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
configured: parsed.configured,
|
|
259
|
+
engine: parsed.engine,
|
|
260
|
+
model: parsed.model,
|
|
261
|
+
source: parsed.source,
|
|
262
|
+
envVar: parsed.envVar,
|
|
263
|
+
};
|
|
264
|
+
} catch {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function cacheLlmConnectionStatus(status: LlmConnectionStatus): void {
|
|
270
|
+
if (typeof window === "undefined") return;
|
|
271
|
+
safeStorageSet(
|
|
272
|
+
LLM_CONNECTION_STORAGE_KEY,
|
|
273
|
+
JSON.stringify({ ...status, cachedAt: Date.now() }),
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function normalizeAgentEngineStatus(data: unknown): LlmConnectionStatus {
|
|
278
|
+
const value = data as Record<string, unknown> | null;
|
|
279
|
+
if (!value || value.configured !== true) {
|
|
280
|
+
return { configured: false };
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
configured: true,
|
|
284
|
+
engine: typeof value.engine === "string" ? value.engine : null,
|
|
285
|
+
model: typeof value.model === "string" ? value.model : null,
|
|
286
|
+
source: typeof value.source === "string" ? value.source : null,
|
|
287
|
+
envVar: typeof value.envVar === "string" ? value.envVar : null,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function refreshLlmConnectionStatus(): Promise<void> {
|
|
292
|
+
if (typeof window === "undefined" || typeof fetch !== "function") {
|
|
293
|
+
return Promise.resolve();
|
|
294
|
+
}
|
|
295
|
+
if (_llmConnectionRefresh) return _llmConnectionRefresh;
|
|
296
|
+
let request: Promise<Response>;
|
|
297
|
+
try {
|
|
298
|
+
request = fetch(agentNativePath("/_agent-native/agent-engine/status"));
|
|
299
|
+
} catch {
|
|
300
|
+
return Promise.resolve();
|
|
301
|
+
}
|
|
302
|
+
_llmConnectionRefresh = request
|
|
303
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
304
|
+
.then((data) => {
|
|
305
|
+
_llmConnectionStatus = normalizeAgentEngineStatus(data);
|
|
306
|
+
cacheLlmConnectionStatus(_llmConnectionStatus);
|
|
307
|
+
})
|
|
308
|
+
.catch(() => {
|
|
309
|
+
if (!_llmConnectionStatus) {
|
|
310
|
+
_llmConnectionStatus = readCachedLlmConnectionStatus();
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
.finally(() => {
|
|
314
|
+
_llmConnectionRefresh = null;
|
|
315
|
+
});
|
|
316
|
+
return _llmConnectionRefresh;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function installLlmConnectionRefresh(): void {
|
|
320
|
+
if (typeof window === "undefined" || _llmConnectionRefreshInstalled) return;
|
|
321
|
+
_llmConnectionRefreshInstalled = true;
|
|
322
|
+
_llmConnectionStatus = readCachedLlmConnectionStatus();
|
|
323
|
+
void refreshLlmConnectionStatus();
|
|
324
|
+
window.addEventListener("focus", () => {
|
|
325
|
+
void refreshLlmConnectionStatus();
|
|
326
|
+
});
|
|
327
|
+
window.addEventListener("agent-engine:configured-changed", () => {
|
|
328
|
+
void refreshLlmConnectionStatus();
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function readTrackingString(value: unknown): string | undefined {
|
|
333
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function stopSessionReplayForAuthClear(
|
|
337
|
+
previousIdentity: TrackingIdentity | null,
|
|
338
|
+
): void {
|
|
339
|
+
if (!_sessionReplayOptions?.requireSignedInUser) {
|
|
340
|
+
_sessionReplayIdentitySnapshot = null;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!previousIdentity?.userEmail) return;
|
|
344
|
+
_sessionReplayIdentitySnapshot = previousIdentity;
|
|
345
|
+
void import("./session-replay.js")
|
|
346
|
+
.then((mod) => mod.stopSessionReplay("auth-cleared"))
|
|
347
|
+
.catch(() => {
|
|
348
|
+
// Auth clearing should never fail because replay cleanup failed.
|
|
349
|
+
})
|
|
350
|
+
.finally(() => {
|
|
351
|
+
if (_sessionReplayIdentitySnapshot === previousIdentity) {
|
|
352
|
+
_sessionReplayIdentitySnapshot = null;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function clearTrackingIdentity(): void {
|
|
358
|
+
const previousIdentity = _trackingIdentity;
|
|
359
|
+
stopSessionReplayForAuthClear(previousIdentity);
|
|
360
|
+
_trackingIdentity = null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function setTrackingIdentityFromSession(data: unknown): void {
|
|
364
|
+
const session = data as Record<string, unknown> | null;
|
|
365
|
+
if (!session || typeof session !== "object" || session.error) {
|
|
366
|
+
clearTrackingIdentity();
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const email = readTrackingString(session.email);
|
|
370
|
+
const authUserId = readTrackingString(session.userId);
|
|
371
|
+
const userId = email || authUserId;
|
|
372
|
+
if (!userId) {
|
|
373
|
+
clearTrackingIdentity();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const userName = readTrackingString(session.name);
|
|
377
|
+
_trackingIdentity = {
|
|
378
|
+
userId,
|
|
379
|
+
...(email ? { userEmail: email } : {}),
|
|
380
|
+
...(userName ? { userName } : {}),
|
|
381
|
+
orgId: readTrackingString(session.orgId) ?? null,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function refreshTrackingAuthSession(): Promise<void> {
|
|
386
|
+
if (typeof window === "undefined" || typeof fetch !== "function") {
|
|
387
|
+
_trackingIdentityResolved = true;
|
|
388
|
+
return Promise.resolve();
|
|
389
|
+
}
|
|
390
|
+
if (_trackingSessionRefresh) return _trackingSessionRefresh;
|
|
391
|
+
_trackingSessionRefresh = fetch(
|
|
392
|
+
agentNativePath("/_agent-native/auth/session"),
|
|
393
|
+
)
|
|
394
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
395
|
+
.then((data) => {
|
|
396
|
+
setTrackingIdentityFromSession(data);
|
|
397
|
+
})
|
|
398
|
+
.catch(() => {
|
|
399
|
+
clearTrackingIdentity();
|
|
400
|
+
})
|
|
401
|
+
.finally(() => {
|
|
402
|
+
_trackingIdentityResolved = true;
|
|
403
|
+
_trackingSessionRefresh = null;
|
|
404
|
+
});
|
|
405
|
+
return _trackingSessionRefresh;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function installTrackingAuthSessionRefresh(): void {
|
|
409
|
+
if (typeof window === "undefined" || _trackingSessionRefreshInstalled) return;
|
|
410
|
+
_trackingSessionRefreshInstalled = true;
|
|
411
|
+
void refreshTrackingAuthSession();
|
|
412
|
+
window.addEventListener("focus", () => {
|
|
413
|
+
void refreshTrackingAuthSession();
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function applyTrackingIdentity(
|
|
418
|
+
properties: Record<string, unknown>,
|
|
419
|
+
identity: TrackingIdentity | null = _trackingIdentity,
|
|
420
|
+
): Record<string, unknown> {
|
|
421
|
+
if (!identity) return properties;
|
|
422
|
+
let next = properties;
|
|
423
|
+
const assign = (key: string, value: unknown) => {
|
|
424
|
+
if (value !== undefined && value !== null && next[key] === undefined) {
|
|
425
|
+
if (next === properties) next = { ...properties };
|
|
426
|
+
next[key] = value;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
assign("userId", identity.userId);
|
|
430
|
+
assign("userEmail", identity.userEmail);
|
|
431
|
+
assign("userName", identity.userName);
|
|
432
|
+
assign("orgId", identity.orgId);
|
|
433
|
+
return next;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function getOrCreateAnonymousId(): string | undefined {
|
|
437
|
+
return getOrCreateAnalyticsAnonymousId();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export function getAnalyticsAnonymousId(): string | undefined {
|
|
441
|
+
return getOrCreateAnonymousId();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function getOrCreateSessionId(): string | undefined {
|
|
445
|
+
return getOrCreateAnalyticsSessionId();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export function getAnalyticsSessionId(): string | undefined {
|
|
449
|
+
return getOrCreateSessionId();
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function truncateFirstTouchField(value: string | null | undefined): string {
|
|
453
|
+
if (!value) return "";
|
|
454
|
+
const trimmed = value.trim();
|
|
455
|
+
if (!trimmed) return "";
|
|
456
|
+
return trimmed.slice(0, FIRST_TOUCH_MAX_FIELD_LENGTH);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Extract just the host of a referrer URL — never the full URL or query
|
|
461
|
+
* string (those can carry tokens). Returns "" when there's no usable host or
|
|
462
|
+
* the referrer is same-origin (a same-site navigation isn't a referral).
|
|
463
|
+
*/
|
|
464
|
+
function scrubReferrerHost(referrer: string | undefined): string {
|
|
465
|
+
if (!referrer) return "";
|
|
466
|
+
try {
|
|
467
|
+
const url = new URL(referrer);
|
|
468
|
+
const host = url.host;
|
|
469
|
+
if (!host) return "";
|
|
470
|
+
if (
|
|
471
|
+
typeof window !== "undefined" &&
|
|
472
|
+
host.toLowerCase() === window.location.host.toLowerCase()
|
|
473
|
+
) {
|
|
474
|
+
return "";
|
|
475
|
+
}
|
|
476
|
+
return truncateFirstTouchField(host);
|
|
477
|
+
} catch {
|
|
478
|
+
return "";
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function buildFirstTouchAttribution(): FirstTouchAttribution {
|
|
483
|
+
const attribution: FirstTouchAttribution = {};
|
|
484
|
+
let params: URLSearchParams | null = null;
|
|
485
|
+
try {
|
|
486
|
+
params = new URLSearchParams(window.location.search);
|
|
487
|
+
} catch {
|
|
488
|
+
params = null;
|
|
489
|
+
}
|
|
490
|
+
if (params) {
|
|
491
|
+
for (const field of FIRST_TOUCH_QUERY_FIELDS) {
|
|
492
|
+
const value = truncateFirstTouchField(params.get(field));
|
|
493
|
+
if (value) attribution[field] = value;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const landingPath = truncateFirstTouchField(window.location.pathname);
|
|
497
|
+
if (landingPath) attribution.landing_path = landingPath;
|
|
498
|
+
const landingReferrer =
|
|
499
|
+
typeof document !== "undefined" ? scrubReferrerHost(document.referrer) : "";
|
|
500
|
+
if (landingReferrer) attribution.landing_referrer = landingReferrer;
|
|
501
|
+
attribution.landed_at = new Date().toISOString();
|
|
502
|
+
return attribution;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function readFirstTouchCookie(): string | null {
|
|
506
|
+
if (typeof document === "undefined") return null;
|
|
507
|
+
try {
|
|
508
|
+
const cookies = document.cookie ? document.cookie.split(";") : [];
|
|
509
|
+
for (const part of cookies) {
|
|
510
|
+
const eq = part.indexOf("=");
|
|
511
|
+
if (eq === -1) continue;
|
|
512
|
+
const name = part.slice(0, eq).trim();
|
|
513
|
+
if (name === FIRST_TOUCH_COOKIE_NAME) {
|
|
514
|
+
return part.slice(eq + 1).trim();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} catch {
|
|
518
|
+
// document.cookie can throw in sandboxed iframes — best-effort.
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function writeFirstTouchCookie(encodedValue: string): void {
|
|
524
|
+
if (typeof document === "undefined") return;
|
|
525
|
+
// Non-sensitive, written by client JS, so no HttpOnly. SameSite=Lax keeps it
|
|
526
|
+
// on top-level navigations (which is how share links arrive) without leaking
|
|
527
|
+
// it to cross-site subresource requests.
|
|
528
|
+
const cookie =
|
|
529
|
+
`${FIRST_TOUCH_COOKIE_NAME}=${encodedValue}; path=/; ` +
|
|
530
|
+
`max-age=${FIRST_TOUCH_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;
|
|
531
|
+
if (cookie.length > FIRST_TOUCH_MAX_COOKIE_BYTES) return;
|
|
532
|
+
try {
|
|
533
|
+
document.cookie = cookie;
|
|
534
|
+
} catch {
|
|
535
|
+
// best-effort
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Capture the visitor's first-touch referral attribution exactly once. Reads
|
|
541
|
+
* the current URL query params + landing info and, IF no attribution is
|
|
542
|
+
* already stored (first-write-wins), persists it to both `localStorage`
|
|
543
|
+
* (`an_attribution`) and the first-party `an_ft` cookie. Fully defensive and
|
|
544
|
+
* SSR-safe — any failure is swallowed so it can never break app boot.
|
|
545
|
+
*/
|
|
546
|
+
function captureFirstTouchAttribution(): void {
|
|
547
|
+
if (_firstTouchCaptured) return;
|
|
548
|
+
_firstTouchCaptured = true;
|
|
549
|
+
if (typeof window === "undefined") return;
|
|
550
|
+
try {
|
|
551
|
+
const existing = safeStorageGet(FIRST_TOUCH_STORAGE_KEY);
|
|
552
|
+
if (existing) {
|
|
553
|
+
// Already captured in a prior visit. Backfill the cookie if it expired
|
|
554
|
+
// or was cleared so the signup boundary still sees first-touch data, but
|
|
555
|
+
// never overwrite the stored value itself (first-write-wins).
|
|
556
|
+
if (!readFirstTouchCookie()) {
|
|
557
|
+
try {
|
|
558
|
+
writeFirstTouchCookie(encodeURIComponent(existing));
|
|
559
|
+
} catch {
|
|
560
|
+
// ignore
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const attribution = buildFirstTouchAttribution();
|
|
566
|
+
const json = JSON.stringify(attribution);
|
|
567
|
+
safeStorageSet(FIRST_TOUCH_STORAGE_KEY, json);
|
|
568
|
+
writeFirstTouchCookie(encodeURIComponent(json));
|
|
569
|
+
} catch {
|
|
570
|
+
// Attribution is best-effort telemetry; never let it break boot.
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Return the parsed first-touch referral attribution captured for this
|
|
576
|
+
* visitor, or `null` when none is stored. Reads from `localStorage`
|
|
577
|
+
* (`an_attribution`). SSR-safe and defensive.
|
|
578
|
+
*/
|
|
579
|
+
export function getFirstTouchAttribution(): FirstTouchAttribution | null {
|
|
580
|
+
if (typeof window === "undefined") return null;
|
|
581
|
+
try {
|
|
582
|
+
const raw = safeStorageGet(FIRST_TOUCH_STORAGE_KEY);
|
|
583
|
+
if (!raw) return null;
|
|
584
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
585
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
return parsed as FirstTouchAttribution;
|
|
589
|
+
} catch {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function isLocalAnalyticsHostname(hostname: string | undefined): boolean {
|
|
595
|
+
const h = (hostname || "").toLowerCase();
|
|
596
|
+
return (
|
|
597
|
+
h === "localhost" ||
|
|
598
|
+
h === "127.0.0.1" ||
|
|
599
|
+
h === "::1" ||
|
|
600
|
+
h === "[::1]" ||
|
|
601
|
+
h.endsWith(".localhost") ||
|
|
602
|
+
h.endsWith(".local")
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function ensureAmplitude(): boolean {
|
|
607
|
+
if (_amplitudeInitialized) return true;
|
|
608
|
+
const key = (import.meta.env as Record<string, string | undefined>)
|
|
609
|
+
?.VITE_AMPLITUDE_API_KEY;
|
|
610
|
+
if (!key) return false;
|
|
611
|
+
// Standard pageviews and explicit events are emitted below. Keep SDK-level
|
|
612
|
+
// DOM/network autocapture off so rendered user content is never collected as
|
|
613
|
+
// an implicit analytics side effect.
|
|
614
|
+
amplitude.init(key, { autocapture: false });
|
|
615
|
+
_amplitudeInitialized = true;
|
|
616
|
+
return true;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function hasOnlySourcelessFrames(value: {
|
|
620
|
+
stacktrace?: {
|
|
621
|
+
frames?: Array<{
|
|
622
|
+
filename?: unknown;
|
|
623
|
+
abs_path?: unknown;
|
|
624
|
+
function?: unknown;
|
|
625
|
+
}>;
|
|
626
|
+
};
|
|
627
|
+
}): boolean {
|
|
628
|
+
const frames = value.stacktrace?.frames ?? [];
|
|
629
|
+
return (
|
|
630
|
+
frames.length === 0 ||
|
|
631
|
+
frames.every((frame) => {
|
|
632
|
+
const filename = String(frame.filename ?? frame.abs_path ?? "")
|
|
633
|
+
.trim()
|
|
634
|
+
.toLowerCase();
|
|
635
|
+
const functionName = String(frame.function ?? "").trim();
|
|
636
|
+
return (
|
|
637
|
+
!functionName &&
|
|
638
|
+
(!filename || filename === "undefined" || filename === "<anonymous>")
|
|
639
|
+
);
|
|
640
|
+
})
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function isAgentNativeDocsUrl(url: string): boolean {
|
|
645
|
+
if (!url) return false;
|
|
646
|
+
try {
|
|
647
|
+
const parsed = new URL(url);
|
|
648
|
+
return (
|
|
649
|
+
parsed.hostname === "www.agent-native.com" ||
|
|
650
|
+
parsed.hostname === "agent-native.com"
|
|
651
|
+
);
|
|
652
|
+
} catch {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function isSessionReplayUrl(url: string): boolean {
|
|
658
|
+
if (!url) return false;
|
|
659
|
+
try {
|
|
660
|
+
const parsed = new URL(url);
|
|
661
|
+
return /^\/sessions\/[^/]+\/?$/.test(parsed.pathname);
|
|
662
|
+
} catch {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function shouldDropBrowserSentryNoise(event: Sentry.Event): boolean {
|
|
668
|
+
const exceptionValues = event.exception?.values ?? [];
|
|
669
|
+
const taggedUrl =
|
|
670
|
+
typeof event.tags?.url === "string" ? event.tags.url : undefined;
|
|
671
|
+
const requestUrl = (event.request?.url ?? taggedUrl ?? "").toLowerCase();
|
|
672
|
+
const isDocsPage = isAgentNativeDocsUrl(requestUrl);
|
|
673
|
+
// A server-owned run can emit an expected run_timeout while handing off to
|
|
674
|
+
// its continuation. AssistantChat retries these transitions automatically;
|
|
675
|
+
// only locally timed-out or ultimately unrecoverable runs should create a
|
|
676
|
+
// Sentry issue. Keep this scoped to the explicit chat tags so real provider
|
|
677
|
+
// and network timeout errors remain visible.
|
|
678
|
+
if (
|
|
679
|
+
event.tags?.context === "agent-native-chat" &&
|
|
680
|
+
event.tags?.errorCode === "run_timeout" &&
|
|
681
|
+
event.tags?.reconnectTimedOut === "false" &&
|
|
682
|
+
event.tags?.reconnectTerminalReason === "run_timeout"
|
|
683
|
+
) {
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
// rrweb 2.1.0 replays recorded media interactions with `void media.play()`.
|
|
687
|
+
// Browsers may reject that promise when the recorded media was unmuted and
|
|
688
|
+
// no user activation is still active, which becomes a source-less unhandled
|
|
689
|
+
// rejection even though the replay player keeps working. Keep this scoped to
|
|
690
|
+
// the replay detail route and the exact browser autoplay-policy message.
|
|
691
|
+
if (
|
|
692
|
+
isSessionReplayUrl(requestUrl) &&
|
|
693
|
+
exceptionValues.some((value) => {
|
|
694
|
+
const exceptionValue = String(value.value ?? "")
|
|
695
|
+
.trim()
|
|
696
|
+
.toLowerCase();
|
|
697
|
+
return (
|
|
698
|
+
exceptionValue.includes("notallowederror: play() failed") &&
|
|
699
|
+
exceptionValue.includes("user didn't interact with the document first")
|
|
700
|
+
);
|
|
701
|
+
})
|
|
702
|
+
) {
|
|
703
|
+
return true;
|
|
704
|
+
}
|
|
705
|
+
// AgentAutoContinueSignal is a control-flow sentinel thrown to bubble
|
|
706
|
+
// out of the SSE stream parser when the agent run needs to be
|
|
707
|
+
// auto-continued. It's caught by the chat adapter and is never a real
|
|
708
|
+
// error. Drop it unconditionally — capturing it as a Sentry exception
|
|
709
|
+
// pollutes the issue list with sentinels that have no actionable stack.
|
|
710
|
+
if (
|
|
711
|
+
exceptionValues.some((value) => value.type === "AgentAutoContinueSignal")
|
|
712
|
+
) {
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
715
|
+
// Browser-side access control rejections usually mean a tab outlived the
|
|
716
|
+
// session or hit a protected route while signed out. The server Sentry setup
|
|
717
|
+
// already drops these bare auth errors; mirror that here for client-captured
|
|
718
|
+
// route/query failures.
|
|
719
|
+
if (
|
|
720
|
+
exceptionValues.some((value) => {
|
|
721
|
+
const exceptionType = String(value.type ?? "")
|
|
722
|
+
.trim()
|
|
723
|
+
.toLowerCase();
|
|
724
|
+
const exceptionValue = String(value.value ?? "")
|
|
725
|
+
.trim()
|
|
726
|
+
.toLowerCase();
|
|
727
|
+
return (
|
|
728
|
+
exceptionType === "unauthorizederror" ||
|
|
729
|
+
exceptionType === "unauthenticatederror" ||
|
|
730
|
+
exceptionValue === "unauthorized" ||
|
|
731
|
+
exceptionValue === "unauthenticated"
|
|
732
|
+
);
|
|
733
|
+
})
|
|
734
|
+
) {
|
|
735
|
+
return true;
|
|
736
|
+
}
|
|
737
|
+
// Safari occasionally reports a source-less global `EmptyRanges` reference
|
|
738
|
+
// error while browsing public pages. There is no script URL or function to
|
|
739
|
+
// map back to our bundle, so keep the filter narrow and only drop it when
|
|
740
|
+
// every frame is missing/undefined.
|
|
741
|
+
if (
|
|
742
|
+
exceptionValues.some((value) => {
|
|
743
|
+
const exceptionType = String(value.type ?? "")
|
|
744
|
+
.trim()
|
|
745
|
+
.toLowerCase();
|
|
746
|
+
const exceptionValue = String(value.value ?? "")
|
|
747
|
+
.trim()
|
|
748
|
+
.toLowerCase();
|
|
749
|
+
if (
|
|
750
|
+
exceptionType !== "referenceerror" ||
|
|
751
|
+
!exceptionValue.includes("emptyranges")
|
|
752
|
+
) {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
return hasOnlySourcelessFrames(value);
|
|
756
|
+
})
|
|
757
|
+
) {
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
if (
|
|
761
|
+
isDocsPage &&
|
|
762
|
+
exceptionValues.some((value) => {
|
|
763
|
+
const exceptionValue = String(value.value ?? "").toLowerCase();
|
|
764
|
+
return exceptionValue.includes(
|
|
765
|
+
"window.webkit.messagehandlers.scrolleventhandler.postmessage",
|
|
766
|
+
);
|
|
767
|
+
})
|
|
768
|
+
) {
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
if (
|
|
772
|
+
isDocsPage &&
|
|
773
|
+
exceptionValues.some((value) => {
|
|
774
|
+
const exceptionType = String(value.type ?? "")
|
|
775
|
+
.trim()
|
|
776
|
+
.toLowerCase();
|
|
777
|
+
const exceptionValue = String(value.value ?? "")
|
|
778
|
+
.trim()
|
|
779
|
+
.toLowerCase();
|
|
780
|
+
return (
|
|
781
|
+
exceptionType === "rangeerror" &&
|
|
782
|
+
exceptionValue.includes("maximum call stack") &&
|
|
783
|
+
hasOnlySourcelessFrames(value)
|
|
784
|
+
);
|
|
785
|
+
})
|
|
786
|
+
) {
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
// Exact user/navigation aborts are expected browser behavior. Keep other
|
|
790
|
+
// AbortError shapes visible unless they match this common non-bug message.
|
|
791
|
+
if (
|
|
792
|
+
exceptionValues.some((value) => {
|
|
793
|
+
const exceptionType = String(value.type ?? "")
|
|
794
|
+
.trim()
|
|
795
|
+
.toLowerCase();
|
|
796
|
+
const exceptionValue = String(value.value ?? "")
|
|
797
|
+
.trim()
|
|
798
|
+
.toLowerCase();
|
|
799
|
+
return (
|
|
800
|
+
exceptionValue === "the user aborted a request." ||
|
|
801
|
+
exceptionValue === "signal is aborted without reason" ||
|
|
802
|
+
exceptionValue === "aborterror: the user aborted a request." ||
|
|
803
|
+
exceptionValue === "aborterror: signal is aborted without reason" ||
|
|
804
|
+
(exceptionType === "aborterror" &&
|
|
805
|
+
(exceptionValue.includes("the user aborted a request") ||
|
|
806
|
+
exceptionValue.includes("signal is aborted without reason")))
|
|
807
|
+
);
|
|
808
|
+
})
|
|
809
|
+
) {
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
const exceptionText = exceptionValues
|
|
813
|
+
.map((value) => `${value.type ?? ""} ${value.value ?? ""}`)
|
|
814
|
+
.join(" ")
|
|
815
|
+
.toLowerCase();
|
|
816
|
+
const breadcrumbText = (event.breadcrumbs ?? [])
|
|
817
|
+
.map((crumb) => {
|
|
818
|
+
const data = crumb.data as Record<string, unknown> | undefined;
|
|
819
|
+
return [
|
|
820
|
+
crumb.category,
|
|
821
|
+
crumb.message,
|
|
822
|
+
typeof data?.url === "string" ? data.url : "",
|
|
823
|
+
].join(" ");
|
|
824
|
+
})
|
|
825
|
+
.join(" ")
|
|
826
|
+
.toLowerCase();
|
|
827
|
+
const combined = `${exceptionText} ${requestUrl} ${breadcrumbText}`;
|
|
828
|
+
return (
|
|
829
|
+
combined.includes("api2.amplitude.com") &&
|
|
830
|
+
(combined.includes("failed to fetch") ||
|
|
831
|
+
combined.includes("networkerror") ||
|
|
832
|
+
combined.includes("load failed"))
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function firstNonEmpty(...values: Array<string | undefined>): string {
|
|
837
|
+
for (const value of values) {
|
|
838
|
+
const trimmed = value?.trim();
|
|
839
|
+
if (trimmed) return trimmed;
|
|
840
|
+
}
|
|
841
|
+
return "";
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function resolveClientSentryDsnFromKeyProject(
|
|
845
|
+
env: Record<string, string | undefined>,
|
|
846
|
+
): string | undefined {
|
|
847
|
+
const key = firstNonEmpty(env.VITE_SENTRY_CLIENT_KEY);
|
|
848
|
+
const projectId = firstNonEmpty(env.VITE_SENTRY_PROJECT_ID);
|
|
849
|
+
const host = firstNonEmpty(env.VITE_SENTRY_INGEST_HOST);
|
|
850
|
+
if (!key || !projectId || !host) return undefined;
|
|
851
|
+
return `https://${key}@${host}/${projectId}`;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function getClientSentryDsn(): string | undefined {
|
|
855
|
+
const env = (import.meta.env as Record<string, string | undefined>) ?? {};
|
|
856
|
+
return (
|
|
857
|
+
env.VITE_SENTRY_CLIENT_DSN ||
|
|
858
|
+
env.VITE_SENTRY_DSN ||
|
|
859
|
+
window.__AGENT_NATIVE_CONFIG__?.sentryDsn ||
|
|
860
|
+
resolveClientSentryDsnFromKeyProject(env)
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function ensureSentry(): void {
|
|
865
|
+
if (_sentryInitialized) return;
|
|
866
|
+
const dsn = getClientSentryDsn();
|
|
867
|
+
if (!dsn) return;
|
|
868
|
+
Sentry.init({
|
|
869
|
+
dsn,
|
|
870
|
+
environment:
|
|
871
|
+
window.__AGENT_NATIVE_CONFIG__?.sentryEnvironment ||
|
|
872
|
+
(import.meta.env as Record<string, string | undefined>)?.MODE ||
|
|
873
|
+
"production",
|
|
874
|
+
beforeSend(event) {
|
|
875
|
+
if (shouldDropBrowserSentryNoise(event)) {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
// Strip sensitive query params from the request URL. React Router
|
|
879
|
+
// history can include share tokens, ?signin=1, password reset codes,
|
|
880
|
+
// public-share password params (audit F-07), etc.
|
|
881
|
+
if (event.request?.url) {
|
|
882
|
+
event.request.url = scrubUrl(event.request.url);
|
|
883
|
+
}
|
|
884
|
+
// Clean the same params from breadcrumb URLs (Sentry captures
|
|
885
|
+
// history.pushState breadcrumbs by default).
|
|
886
|
+
if (Array.isArray(event.breadcrumbs)) {
|
|
887
|
+
for (const crumb of event.breadcrumbs) {
|
|
888
|
+
if (crumb && typeof crumb === "object" && "data" in crumb) {
|
|
889
|
+
const data = crumb.data as Record<string, unknown> | undefined;
|
|
890
|
+
if (data && typeof data.url === "string") {
|
|
891
|
+
data.url = scrubUrl(data.url);
|
|
892
|
+
}
|
|
893
|
+
if (data && typeof data.from === "string") {
|
|
894
|
+
data.from = scrubUrl(data.from);
|
|
895
|
+
}
|
|
896
|
+
if (data && typeof data.to === "string") {
|
|
897
|
+
data.to = scrubUrl(data.to);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
return event;
|
|
903
|
+
},
|
|
904
|
+
});
|
|
905
|
+
Sentry.setTag("runtime", "browser");
|
|
906
|
+
_sentryInitialized = true;
|
|
907
|
+
// Flush any user/tag that was set before init.
|
|
908
|
+
if (_pendingSentryUser !== undefined) {
|
|
909
|
+
Sentry.setUser(_pendingSentryUser);
|
|
910
|
+
_pendingSentryUser = undefined;
|
|
911
|
+
}
|
|
912
|
+
if (_pendingSentryOrgId !== undefined) {
|
|
913
|
+
Sentry.setTag("orgId", _pendingSentryOrgId);
|
|
914
|
+
_pendingSentryOrgId = undefined;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Attach the current user to Sentry events from the browser. Pass `null` to
|
|
920
|
+
* clear (e.g. on logout). If Sentry isn't initialized yet, the value is
|
|
921
|
+
* buffered and applied once `ensureSentry()` runs.
|
|
922
|
+
*
|
|
923
|
+
* Pass `orgId` to also tag events with the active organization ID — useful
|
|
924
|
+
* for filtering Sentry by tenant.
|
|
925
|
+
*/
|
|
926
|
+
export function setSentryUser(
|
|
927
|
+
user: TrackingIdentityUser | null,
|
|
928
|
+
orgId?: string | null,
|
|
929
|
+
): void {
|
|
930
|
+
let shouldRetryReplay = false;
|
|
931
|
+
if (user) {
|
|
932
|
+
const userId = user.email || user.id;
|
|
933
|
+
if (userId) {
|
|
934
|
+
_trackingIdentity = {
|
|
935
|
+
userId,
|
|
936
|
+
...(user.email ? { userEmail: user.email } : {}),
|
|
937
|
+
...(user.username ? { userName: user.username } : {}),
|
|
938
|
+
orgId: orgId ?? null,
|
|
939
|
+
};
|
|
940
|
+
} else {
|
|
941
|
+
clearTrackingIdentity();
|
|
942
|
+
}
|
|
943
|
+
shouldRetryReplay = Boolean(user.email);
|
|
944
|
+
} else {
|
|
945
|
+
clearTrackingIdentity();
|
|
946
|
+
}
|
|
947
|
+
_trackingIdentityResolved = true;
|
|
948
|
+
if (
|
|
949
|
+
shouldRetryReplay &&
|
|
950
|
+
_trackingContentCaptureEnabled &&
|
|
951
|
+
_sessionReplayOptions?.requireSignedInUser
|
|
952
|
+
) {
|
|
953
|
+
void startConfiguredSessionReplay(_sessionReplayOptions);
|
|
954
|
+
}
|
|
955
|
+
if (_sentryInitialized) {
|
|
956
|
+
Sentry.setUser(user);
|
|
957
|
+
if (orgId !== undefined) {
|
|
958
|
+
Sentry.setTag("orgId", orgId ?? null);
|
|
959
|
+
}
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
_pendingSentryUser = user;
|
|
963
|
+
if (orgId !== undefined) {
|
|
964
|
+
_pendingSentryOrgId = orgId ?? null;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/** Neutral alias for hosts that own identity outside Sentry. */
|
|
969
|
+
export function setTrackingIdentity(
|
|
970
|
+
user: TrackingIdentityUser | null,
|
|
971
|
+
orgId?: string | null,
|
|
972
|
+
): void {
|
|
973
|
+
setSentryUser(user, orgId);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
export interface ClientCaptureContext {
|
|
977
|
+
/** Searchable Sentry tags (low-cardinality strings only). */
|
|
978
|
+
tags?: Record<string, string | undefined>;
|
|
979
|
+
/**
|
|
980
|
+
* High-cardinality / structured payload — not searchable but visible in
|
|
981
|
+
* the Sentry event detail (file sizes, request URLs, response body
|
|
982
|
+
* tails, etc.).
|
|
983
|
+
*/
|
|
984
|
+
extra?: Record<string, unknown>;
|
|
985
|
+
/**
|
|
986
|
+
* Grouped contexts shown as separate cards in the Sentry event UI.
|
|
987
|
+
*/
|
|
988
|
+
contexts?: Record<string, Record<string, unknown>>;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Capture an exception to Sentry from browser code without forcing the
|
|
993
|
+
* caller to depend on `@sentry/browser` directly.
|
|
994
|
+
*
|
|
995
|
+
* Templates can route a thrown Error through here on a known failure path
|
|
996
|
+
* (chunk-upload 500, thumbnail upload, etc.) to attach searchable tags and
|
|
997
|
+
* structured extra context. No-ops gracefully when Sentry isn't
|
|
998
|
+
* initialized — never throws back into the caller, so a Sentry hiccup
|
|
999
|
+
* can't mask the original error.
|
|
1000
|
+
*/
|
|
1001
|
+
export function captureClientException(
|
|
1002
|
+
error: unknown,
|
|
1003
|
+
context: ClientCaptureContext = {},
|
|
1004
|
+
): string | undefined {
|
|
1005
|
+
if (typeof window === "undefined") return undefined;
|
|
1006
|
+
try {
|
|
1007
|
+
ensureSentry();
|
|
1008
|
+
return Sentry.withScope((scope) => {
|
|
1009
|
+
if (context.tags) {
|
|
1010
|
+
for (const [k, v] of Object.entries(context.tags)) {
|
|
1011
|
+
if (typeof v === "string") scope.setTag(k, v);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
if (context.extra) {
|
|
1015
|
+
for (const [k, v] of Object.entries(context.extra)) {
|
|
1016
|
+
if (v !== undefined) scope.setExtra(k, v);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (context.contexts) {
|
|
1020
|
+
for (const [k, v] of Object.entries(context.contexts)) {
|
|
1021
|
+
scope.setContext(k, v);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return Sentry.captureException(error);
|
|
1025
|
+
});
|
|
1026
|
+
} catch {
|
|
1027
|
+
return undefined;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Public browser-side error capture utility, mirroring `trackEvent()`:
|
|
1033
|
+
* templates can call `captureError(err, { tags, extra, contexts })` without
|
|
1034
|
+
* depending on Sentry directly. Sentry receives the event when a browser DSN
|
|
1035
|
+
* is configured; otherwise this is a quiet no-op.
|
|
1036
|
+
*/
|
|
1037
|
+
export function captureError(
|
|
1038
|
+
error: unknown,
|
|
1039
|
+
context: ClientCaptureContext = {},
|
|
1040
|
+
): string | undefined {
|
|
1041
|
+
return captureClientException(error, context);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function getPageviewTrackingState(): PageviewTrackingState {
|
|
1045
|
+
const g = globalThis as typeof globalThis & {
|
|
1046
|
+
[PAGEVIEW_TRACKING_STATE_KEY]?: PageviewTrackingState;
|
|
1047
|
+
};
|
|
1048
|
+
if (!g[PAGEVIEW_TRACKING_STATE_KEY]) {
|
|
1049
|
+
g[PAGEVIEW_TRACKING_STATE_KEY] = {
|
|
1050
|
+
installed: false,
|
|
1051
|
+
lastPageviewKey: null,
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
return g[PAGEVIEW_TRACKING_STATE_KEY];
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function getAgentChatTrackingState(): AgentChatTrackingState {
|
|
1058
|
+
const g = globalThis as typeof globalThis & {
|
|
1059
|
+
[AGENT_CHAT_TRACKING_STATE_KEY]?: AgentChatTrackingState;
|
|
1060
|
+
};
|
|
1061
|
+
if (!g[AGENT_CHAT_TRACKING_STATE_KEY]) {
|
|
1062
|
+
g[AGENT_CHAT_TRACKING_STATE_KEY] = { seen: new Map() };
|
|
1063
|
+
}
|
|
1064
|
+
return g[AGENT_CHAT_TRACKING_STATE_KEY];
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
export type AgentChatLifecycleEvent = {
|
|
1068
|
+
phase: "surface-mounted" | "run-observed" | "run-stopped";
|
|
1069
|
+
surface?: string;
|
|
1070
|
+
threadId?: string;
|
|
1071
|
+
runId?: string;
|
|
1072
|
+
tabId?: string;
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Record a content-free, browser-session-linked chat lifecycle marker and add
|
|
1077
|
+
* the same marker to session replay when replay is configured. The bounded
|
|
1078
|
+
* global de-dupe survives React Strict Mode remounts without retaining keys
|
|
1079
|
+
* forever.
|
|
1080
|
+
*/
|
|
1081
|
+
export function trackAgentChatLifecycle(input: AgentChatLifecycleEvent): void {
|
|
1082
|
+
if (typeof window === "undefined") return;
|
|
1083
|
+
const surface = input.surface?.trim() || "app";
|
|
1084
|
+
const dedupeKey = [
|
|
1085
|
+
input.phase,
|
|
1086
|
+
surface,
|
|
1087
|
+
input.threadId ?? "",
|
|
1088
|
+
input.runId ?? "",
|
|
1089
|
+
input.tabId ?? "",
|
|
1090
|
+
].join(":");
|
|
1091
|
+
const state = getAgentChatTrackingState();
|
|
1092
|
+
const now = Date.now();
|
|
1093
|
+
for (const [key, seenAt] of state.seen) {
|
|
1094
|
+
if (now - seenAt >= AGENT_CHAT_LIFECYCLE_DEDUPE_TTL_MS) {
|
|
1095
|
+
state.seen.delete(key);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
if (state.seen.has(dedupeKey)) return;
|
|
1099
|
+
state.seen.set(dedupeKey, now);
|
|
1100
|
+
while (state.seen.size > MAX_AGENT_CHAT_LIFECYCLE_DEDUPE_KEYS) {
|
|
1101
|
+
const oldestKey = state.seen.keys().next().value;
|
|
1102
|
+
if (oldestKey === undefined) break;
|
|
1103
|
+
state.seen.delete(oldestKey);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
void (async () => {
|
|
1107
|
+
const replayResult =
|
|
1108
|
+
_sessionReplayOptions && _trackingContentCaptureEnabled
|
|
1109
|
+
? await startConfiguredSessionReplay(_sessionReplayOptions)
|
|
1110
|
+
: null;
|
|
1111
|
+
const properties = {
|
|
1112
|
+
phase: input.phase,
|
|
1113
|
+
chat_surface: surface,
|
|
1114
|
+
...(input.threadId ? { thread_id: input.threadId } : {}),
|
|
1115
|
+
...(input.runId ? { run_id: input.runId } : {}),
|
|
1116
|
+
...(input.tabId ? { chat_tab_id: input.tabId } : {}),
|
|
1117
|
+
replay_status: replayResult?.started
|
|
1118
|
+
? "active"
|
|
1119
|
+
: (replayResult?.reason ?? "not-configured"),
|
|
1120
|
+
};
|
|
1121
|
+
trackEvent("agent_chat_lifecycle", properties);
|
|
1122
|
+
_sessionReplayModuleForCapture?.emitSessionReplayAgentChatEvent?.({
|
|
1123
|
+
phase: input.phase,
|
|
1124
|
+
surface,
|
|
1125
|
+
...(input.threadId ? { threadId: input.threadId } : {}),
|
|
1126
|
+
...(input.runId ? { runId: input.runId } : {}),
|
|
1127
|
+
...(input.tabId ? { tabId: input.tabId } : {}),
|
|
1128
|
+
});
|
|
1129
|
+
})();
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
export function configureTracking(options: ConfigureTrackingOptions): void {
|
|
1133
|
+
const publicKey = options.key || options.publicKey;
|
|
1134
|
+
if (publicKey) {
|
|
1135
|
+
_agentNativeAnalyticsPublicKey = publicKey;
|
|
1136
|
+
}
|
|
1137
|
+
if (options.endpoint) {
|
|
1138
|
+
_agentNativeAnalyticsEndpoint = options.endpoint;
|
|
1139
|
+
}
|
|
1140
|
+
if (options.getDefaultProps) {
|
|
1141
|
+
_getDefaultProps = options.getDefaultProps;
|
|
1142
|
+
}
|
|
1143
|
+
_contentCaptureForPath = options.contentCaptureForPath ?? null;
|
|
1144
|
+
_trackingContentCaptureEnabled =
|
|
1145
|
+
_contentCaptureForPath && typeof window !== "undefined"
|
|
1146
|
+
? _contentCaptureForPath(window.location.pathname)
|
|
1147
|
+
: options.contentCapture !== false;
|
|
1148
|
+
if (typeof window !== "undefined") {
|
|
1149
|
+
ensureSentry();
|
|
1150
|
+
ensureAmplitude();
|
|
1151
|
+
captureFirstTouchAttribution();
|
|
1152
|
+
if (options.llmConnectionStatus !== false) {
|
|
1153
|
+
installLlmConnectionRefresh();
|
|
1154
|
+
}
|
|
1155
|
+
if (options.authSessionRefresh !== false) {
|
|
1156
|
+
installTrackingAuthSessionRefresh();
|
|
1157
|
+
}
|
|
1158
|
+
if (options.pageviewTracking !== false) {
|
|
1159
|
+
installPageviewTracking();
|
|
1160
|
+
}
|
|
1161
|
+
maybeInstallSessionReplay(
|
|
1162
|
+
options.sessionReplay,
|
|
1163
|
+
{
|
|
1164
|
+
endpoint: options.endpoint,
|
|
1165
|
+
publicKey,
|
|
1166
|
+
},
|
|
1167
|
+
_trackingContentCaptureEnabled,
|
|
1168
|
+
);
|
|
1169
|
+
maybeInstallErrorCapture(options.errorCapture);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
export function setTrackingContentCaptureEnabled(enabled: boolean): void {
|
|
1174
|
+
if (_trackingContentCaptureEnabled === enabled) return;
|
|
1175
|
+
_trackingContentCaptureEnabled = enabled;
|
|
1176
|
+
if (enabled) {
|
|
1177
|
+
if (_sessionReplayOptions) {
|
|
1178
|
+
void startConfiguredSessionReplay(_sessionReplayOptions);
|
|
1179
|
+
}
|
|
1180
|
+
} else {
|
|
1181
|
+
void stopSessionReplay("content-capture-disabled");
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function syncTrackingContentCaptureForLocation(): void {
|
|
1186
|
+
if (!_contentCaptureForPath) return;
|
|
1187
|
+
setTrackingContentCaptureEnabled(
|
|
1188
|
+
_contentCaptureForPath(window.location.pathname),
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Lazily load the session-replay module so error capture can read the active
|
|
1194
|
+
* replay id and surface manual captures on the replay timeline without a
|
|
1195
|
+
* static import (which would create an analytics <-> session-replay import
|
|
1196
|
+
* cycle and pull the replay module into the analytics chunk eagerly).
|
|
1197
|
+
*/
|
|
1198
|
+
function loadSessionReplayModuleForCapture(): void {
|
|
1199
|
+
if (_sessionReplayModuleForCapture) return;
|
|
1200
|
+
import("./session-replay.js")
|
|
1201
|
+
.then((mod) => {
|
|
1202
|
+
_sessionReplayModuleForCapture = mod;
|
|
1203
|
+
})
|
|
1204
|
+
.catch(() => {
|
|
1205
|
+
// Session linkage is best-effort; capture still works without it.
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
function errorCaptureSessionContext(): {
|
|
1210
|
+
sessionId?: string;
|
|
1211
|
+
anonymousId?: string;
|
|
1212
|
+
replayId?: string;
|
|
1213
|
+
} {
|
|
1214
|
+
return {
|
|
1215
|
+
sessionId: getOrCreateSessionId(),
|
|
1216
|
+
anonymousId: getOrCreateAnonymousId(),
|
|
1217
|
+
replayId:
|
|
1218
|
+
_sessionReplayModuleForCapture?.getSessionReplayId?.() ?? undefined,
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
function exceptionEventProperties(
|
|
1223
|
+
event: CapturedExceptionEvent,
|
|
1224
|
+
): Record<string, unknown> {
|
|
1225
|
+
return {
|
|
1226
|
+
exceptionType: event.type,
|
|
1227
|
+
exceptionMessage: event.message,
|
|
1228
|
+
...(event.stack ? { exceptionStack: event.stack } : {}),
|
|
1229
|
+
handled: event.handled,
|
|
1230
|
+
level: event.level,
|
|
1231
|
+
occurredAt: event.occurredAt,
|
|
1232
|
+
...(event.url ? { errorUrl: event.url } : {}),
|
|
1233
|
+
...(event.release ? { release: event.release } : {}),
|
|
1234
|
+
...(event.environment ? { environment: event.environment } : {}),
|
|
1235
|
+
...(event.sessionReplayId
|
|
1236
|
+
? { sessionReplayId: event.sessionReplayId }
|
|
1237
|
+
: {}),
|
|
1238
|
+
...(event.breadcrumbs?.length ? { breadcrumbs: event.breadcrumbs } : {}),
|
|
1239
|
+
...(event.tags ? { exceptionTags: event.tags } : {}),
|
|
1240
|
+
...(event.extra ? { exceptionExtra: event.extra } : {}),
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
function sendExceptionEvent(event: CapturedExceptionEvent): void {
|
|
1245
|
+
// Route through the existing first-party analytics ingest as a dedicated
|
|
1246
|
+
// `$exception` event. This reuses the public-key auth + sendBeacon/keepalive
|
|
1247
|
+
// transport; the server forks it into error_issues/error_events and still
|
|
1248
|
+
// records it in analytics_events for alerting.
|
|
1249
|
+
trackEvent(
|
|
1250
|
+
AGENT_NATIVE_EXCEPTION_EVENT_NAME,
|
|
1251
|
+
exceptionEventProperties(event),
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
function emitExceptionToReplay(event: CapturedExceptionEvent): void {
|
|
1256
|
+
_sessionReplayModuleForCapture?.emitSessionReplayException?.({
|
|
1257
|
+
type: event.type,
|
|
1258
|
+
message: event.message,
|
|
1259
|
+
level: event.level,
|
|
1260
|
+
...(event.stack ? { stack: event.stack } : {}),
|
|
1261
|
+
...(event.url ? { url: event.url } : {}),
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
function errorCaptureAutoEnabled(): boolean {
|
|
1266
|
+
const publicKey =
|
|
1267
|
+
_agentNativeAnalyticsPublicKey ||
|
|
1268
|
+
(import.meta.env as Record<string, string | undefined>)
|
|
1269
|
+
?.VITE_AGENT_NATIVE_ANALYTICS_PUBLIC_KEY;
|
|
1270
|
+
return !!publicKey;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function maybeInstallErrorCapture(
|
|
1274
|
+
config: boolean | ErrorCaptureConfigOptions | undefined,
|
|
1275
|
+
): void {
|
|
1276
|
+
if (typeof window === "undefined") return;
|
|
1277
|
+
if (config === false) {
|
|
1278
|
+
_errorCaptureDisposer?.();
|
|
1279
|
+
_errorCaptureDisposer = null;
|
|
1280
|
+
_errorCaptureInstalled = false;
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
if (_errorCaptureInstalled && config === undefined) return;
|
|
1284
|
+
const enabled = config === undefined ? errorCaptureAutoEnabled() : true;
|
|
1285
|
+
if (!enabled) return;
|
|
1286
|
+
const options = typeof config === "object" ? config : {};
|
|
1287
|
+
loadSessionReplayModuleForCapture();
|
|
1288
|
+
_errorCaptureDisposer = installErrorCapture({
|
|
1289
|
+
send: sendExceptionEvent,
|
|
1290
|
+
getSessionContext: errorCaptureSessionContext,
|
|
1291
|
+
emitReplayEvent: emitExceptionToReplay,
|
|
1292
|
+
environment:
|
|
1293
|
+
options.environment ||
|
|
1294
|
+
(import.meta.env as Record<string, string | undefined>)?.MODE,
|
|
1295
|
+
...(options.release ? { release: options.release } : {}),
|
|
1296
|
+
...(options.captureGlobalErrors !== undefined
|
|
1297
|
+
? { captureGlobalErrors: options.captureGlobalErrors }
|
|
1298
|
+
: {}),
|
|
1299
|
+
...(options.captureUnhandledRejections !== undefined
|
|
1300
|
+
? { captureUnhandledRejections: options.captureUnhandledRejections }
|
|
1301
|
+
: {}),
|
|
1302
|
+
...(options.maxBreadcrumbs !== undefined
|
|
1303
|
+
? { maxBreadcrumbs: options.maxBreadcrumbs }
|
|
1304
|
+
: {}),
|
|
1305
|
+
});
|
|
1306
|
+
_errorCaptureInstalled = true;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
function sessionReplayEnabledFromEnv(): boolean {
|
|
1310
|
+
const env = (import.meta.env as Record<string, string | undefined>) ?? {};
|
|
1311
|
+
const value =
|
|
1312
|
+
env.VITE_AGENT_NATIVE_SESSION_REPLAY_ENABLED ||
|
|
1313
|
+
env.VITE_SESSION_REPLAY_ENABLED;
|
|
1314
|
+
return /^(1|true|yes|on)$/i.test((value ?? "").trim());
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function sessionReplayRequiresSignedInUserFromEnv(): boolean | undefined {
|
|
1318
|
+
const env = (import.meta.env as Record<string, string | undefined>) ?? {};
|
|
1319
|
+
const value =
|
|
1320
|
+
env.VITE_AGENT_NATIVE_SESSION_REPLAY_REQUIRE_AUTH ||
|
|
1321
|
+
env.VITE_SESSION_REPLAY_REQUIRE_AUTH;
|
|
1322
|
+
const normalized = (value ?? "").trim();
|
|
1323
|
+
if (!normalized) return undefined;
|
|
1324
|
+
if (/^(1|true|yes|on)$/i.test(normalized)) return true;
|
|
1325
|
+
if (/^(0|false|no|off)$/i.test(normalized)) return false;
|
|
1326
|
+
return undefined;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function configuredSessionReplayOptions(
|
|
1330
|
+
config: boolean | SessionReplayOptions | undefined,
|
|
1331
|
+
tracking: { endpoint?: string; publicKey?: string } = {},
|
|
1332
|
+
): SessionReplayOptions | null {
|
|
1333
|
+
const env = (import.meta.env as Record<string, string | undefined>) ?? {};
|
|
1334
|
+
const publicKey =
|
|
1335
|
+
tracking.publicKey ||
|
|
1336
|
+
_agentNativeAnalyticsPublicKey ||
|
|
1337
|
+
env.VITE_AGENT_NATIVE_ANALYTICS_PUBLIC_KEY;
|
|
1338
|
+
const trackingEndpoint =
|
|
1339
|
+
tracking.endpoint ||
|
|
1340
|
+
_agentNativeAnalyticsEndpoint ||
|
|
1341
|
+
env.VITE_AGENT_NATIVE_ANALYTICS_ENDPOINT ||
|
|
1342
|
+
(publicKey ? AGENT_NATIVE_ANALYTICS_DEFAULT_ENDPOINT : undefined);
|
|
1343
|
+
const endpoint = trackingEndpoint
|
|
1344
|
+
? replayEndpointFromTrackingEndpoint(trackingEndpoint)
|
|
1345
|
+
: undefined;
|
|
1346
|
+
const withTrackingDefaults = (
|
|
1347
|
+
options: SessionReplayOptions,
|
|
1348
|
+
): SessionReplayOptions => {
|
|
1349
|
+
const extraProperties = replayExtraPropertiesWithDefaults(
|
|
1350
|
+
options.extraProperties,
|
|
1351
|
+
);
|
|
1352
|
+
return {
|
|
1353
|
+
...(publicKey && !options.publicKey ? { publicKey } : {}),
|
|
1354
|
+
...(endpoint && !options.endpoint ? { endpoint } : {}),
|
|
1355
|
+
...options,
|
|
1356
|
+
onUploadRejected:
|
|
1357
|
+
options.onUploadRejected ??
|
|
1358
|
+
((details) => {
|
|
1359
|
+
trackEvent("session replay upload rejected", {
|
|
1360
|
+
status: details.status,
|
|
1361
|
+
restart_attempted: details.restartAttempted,
|
|
1362
|
+
restart_succeeded: details.restartSucceeded,
|
|
1363
|
+
...(details.restartReason
|
|
1364
|
+
? { restart_reason: details.restartReason }
|
|
1365
|
+
: {}),
|
|
1366
|
+
});
|
|
1367
|
+
}),
|
|
1368
|
+
requireSignedInUser:
|
|
1369
|
+
options.requireSignedInUser ??
|
|
1370
|
+
sessionReplayRequiresSignedInUserFromEnv() ??
|
|
1371
|
+
true,
|
|
1372
|
+
...(extraProperties ? { extraProperties } : {}),
|
|
1373
|
+
};
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
if (config === false) return null;
|
|
1377
|
+
if (config === true) return withTrackingDefaults({});
|
|
1378
|
+
if (config && typeof config === "object") {
|
|
1379
|
+
if (config.enabled === false) return null;
|
|
1380
|
+
return withTrackingDefaults(config);
|
|
1381
|
+
}
|
|
1382
|
+
const autoEnabledByAnalyticsKey =
|
|
1383
|
+
!!publicKey &&
|
|
1384
|
+
(typeof window === "undefined" ||
|
|
1385
|
+
!isLocalAnalyticsHostname(window.location.hostname));
|
|
1386
|
+
return sessionReplayEnabledFromEnv() || autoEnabledByAnalyticsKey
|
|
1387
|
+
? withTrackingDefaults({})
|
|
1388
|
+
: null;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function replayExtraPropertiesWithDefaults(
|
|
1392
|
+
source: SessionReplayOptions["extraProperties"],
|
|
1393
|
+
): SessionReplayOptions["extraProperties"] {
|
|
1394
|
+
return () => {
|
|
1395
|
+
const rawProps =
|
|
1396
|
+
typeof source === "function"
|
|
1397
|
+
? source()
|
|
1398
|
+
: source && typeof source === "object"
|
|
1399
|
+
? source
|
|
1400
|
+
: {};
|
|
1401
|
+
const props = rawProps && typeof rawProps === "object" ? rawProps : {};
|
|
1402
|
+
const withDefaults = _getDefaultProps?.("session_replay", props) ?? props;
|
|
1403
|
+
return applyTrackingIdentity(
|
|
1404
|
+
withDefaults,
|
|
1405
|
+
_trackingIdentity ?? _sessionReplayIdentitySnapshot,
|
|
1406
|
+
);
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
function replayEndpointFromTrackingEndpoint(value: string): string | undefined {
|
|
1411
|
+
try {
|
|
1412
|
+
const url = new URL(value);
|
|
1413
|
+
if (url.pathname.endsWith("/api/analytics/track")) {
|
|
1414
|
+
url.pathname = url.pathname.replace(
|
|
1415
|
+
/\/api\/analytics\/track$/,
|
|
1416
|
+
"/api/analytics/replay",
|
|
1417
|
+
);
|
|
1418
|
+
return url.toString();
|
|
1419
|
+
}
|
|
1420
|
+
if (url.pathname.endsWith("/track")) {
|
|
1421
|
+
url.pathname = url.pathname.replace(/\/track$/, "/api/analytics/replay");
|
|
1422
|
+
return url.toString();
|
|
1423
|
+
}
|
|
1424
|
+
} catch {
|
|
1425
|
+
// Fall through to relative-path handling below.
|
|
1426
|
+
}
|
|
1427
|
+
if (value.endsWith("/api/analytics/track")) {
|
|
1428
|
+
return value.replace(/\/api\/analytics\/track$/, "/api/analytics/replay");
|
|
1429
|
+
}
|
|
1430
|
+
if (value.endsWith("/track")) {
|
|
1431
|
+
return value.replace(/\/track$/, "/api/analytics/replay");
|
|
1432
|
+
}
|
|
1433
|
+
return undefined;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
function maybeInstallSessionReplay(
|
|
1437
|
+
config: boolean | SessionReplayOptions | undefined,
|
|
1438
|
+
tracking?: { endpoint?: string; publicKey?: string },
|
|
1439
|
+
start = true,
|
|
1440
|
+
): void {
|
|
1441
|
+
if (typeof window === "undefined") return;
|
|
1442
|
+
const options = configuredSessionReplayOptions(config, tracking);
|
|
1443
|
+
_sessionReplayOptions = options;
|
|
1444
|
+
if (!options || !start) return;
|
|
1445
|
+
void startConfiguredSessionReplay(options);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
async function waitForSessionReplayAuthIfRequired(
|
|
1449
|
+
options: SessionReplayOptions,
|
|
1450
|
+
): Promise<boolean> {
|
|
1451
|
+
if (!options.requireSignedInUser) return true;
|
|
1452
|
+
if (_trackingIdentity?.userEmail) return true;
|
|
1453
|
+
try {
|
|
1454
|
+
if (_trackingSessionRefresh) {
|
|
1455
|
+
await _trackingSessionRefresh;
|
|
1456
|
+
} else if (!_trackingIdentityResolved) {
|
|
1457
|
+
await refreshTrackingAuthSession();
|
|
1458
|
+
}
|
|
1459
|
+
} catch {
|
|
1460
|
+
// best-effort; missing identity below keeps replay off
|
|
1461
|
+
}
|
|
1462
|
+
return !!_trackingIdentity?.userEmail;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
async function startConfiguredSessionReplay(
|
|
1466
|
+
options: SessionReplayOptions,
|
|
1467
|
+
): Promise<SessionReplayStartResult | null> {
|
|
1468
|
+
if (_sessionReplayStartPromise) return _sessionReplayStartPromise;
|
|
1469
|
+
_sessionReplayStartPromise = (async () => {
|
|
1470
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1471
|
+
return { started: false, reason: "disabled" as const };
|
|
1472
|
+
}
|
|
1473
|
+
if (!(await waitForSessionReplayAuthIfRequired(options))) {
|
|
1474
|
+
return { started: false, reason: "missing-user-id" as const };
|
|
1475
|
+
}
|
|
1476
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1477
|
+
return { started: false, reason: "disabled" as const };
|
|
1478
|
+
}
|
|
1479
|
+
const mod = await import("./session-replay.js");
|
|
1480
|
+
_sessionReplayModuleForCapture = mod;
|
|
1481
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1482
|
+
return { started: false, reason: "disabled" as const };
|
|
1483
|
+
}
|
|
1484
|
+
return mod.startSessionReplay({
|
|
1485
|
+
...options,
|
|
1486
|
+
shouldStart: () =>
|
|
1487
|
+
_trackingContentCaptureEnabled && (options.shouldStart?.() ?? true),
|
|
1488
|
+
});
|
|
1489
|
+
})()
|
|
1490
|
+
.catch(() => ({ started: false, reason: "import-failed" as const }))
|
|
1491
|
+
.finally(() => {
|
|
1492
|
+
_sessionReplayStartPromise = null;
|
|
1493
|
+
});
|
|
1494
|
+
return _sessionReplayStartPromise;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
export async function startSessionReplay(
|
|
1498
|
+
options: SessionReplayOptions = {},
|
|
1499
|
+
): Promise<SessionReplayStartResult> {
|
|
1500
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1501
|
+
return { started: false, reason: "disabled" };
|
|
1502
|
+
}
|
|
1503
|
+
const configured = configuredSessionReplayOptions(options) ?? options;
|
|
1504
|
+
if (!(await waitForSessionReplayAuthIfRequired(configured))) {
|
|
1505
|
+
return { started: false, reason: "missing-user-id" };
|
|
1506
|
+
}
|
|
1507
|
+
const mod = await import("./session-replay.js");
|
|
1508
|
+
_sessionReplayModuleForCapture = mod;
|
|
1509
|
+
return mod.startSessionReplay({
|
|
1510
|
+
...configured,
|
|
1511
|
+
shouldStart: () =>
|
|
1512
|
+
_trackingContentCaptureEnabled && (configured.shouldStart?.() ?? true),
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
export async function maybeStartSessionReplay(
|
|
1517
|
+
options: SessionReplayOptions = {},
|
|
1518
|
+
): Promise<SessionReplayStartResult> {
|
|
1519
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1520
|
+
return { started: false, reason: "disabled" };
|
|
1521
|
+
}
|
|
1522
|
+
const configured = configuredSessionReplayOptions(options) ?? options;
|
|
1523
|
+
if (!(await waitForSessionReplayAuthIfRequired(configured))) {
|
|
1524
|
+
return { started: false, reason: "missing-user-id" };
|
|
1525
|
+
}
|
|
1526
|
+
const mod = await import("./session-replay.js");
|
|
1527
|
+
return mod.maybeStartSessionReplay({
|
|
1528
|
+
...configured,
|
|
1529
|
+
shouldStart: () =>
|
|
1530
|
+
_trackingContentCaptureEnabled && (configured.shouldStart?.() ?? true),
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
export async function stopSessionReplay(reason = "manual"): Promise<void> {
|
|
1535
|
+
const mod = await import("./session-replay.js");
|
|
1536
|
+
await mod.stopSessionReplay(reason);
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
function inferTemplateName(properties: Record<string, unknown>): string | null {
|
|
1540
|
+
const envTemplate =
|
|
1541
|
+
(import.meta.env as Record<string, string | undefined>)
|
|
1542
|
+
?.VITE_AGENT_NATIVE_TEMPLATE ||
|
|
1543
|
+
(import.meta.env as Record<string, string | undefined>)?.VITE_APP_TEMPLATE;
|
|
1544
|
+
if (envTemplate) return envTemplate;
|
|
1545
|
+
|
|
1546
|
+
const app = typeof properties.app === "string" ? properties.app.trim() : "";
|
|
1547
|
+
if (!app || app === "localhost") return null;
|
|
1548
|
+
if (app.startsWith("agent-native-")) {
|
|
1549
|
+
return app.slice("agent-native-".length);
|
|
1550
|
+
}
|
|
1551
|
+
return app;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
function resolveProps(
|
|
1555
|
+
name: string,
|
|
1556
|
+
params?: Record<string, unknown>,
|
|
1557
|
+
): Record<string, unknown> {
|
|
1558
|
+
if (typeof window === "undefined") return { ...params };
|
|
1559
|
+
const base: Record<string, unknown> = {
|
|
1560
|
+
url: window.location.origin + window.location.pathname,
|
|
1561
|
+
app: window.location.hostname.split(".")[0] || "localhost",
|
|
1562
|
+
...params,
|
|
1563
|
+
};
|
|
1564
|
+
const props = _getDefaultProps ? _getDefaultProps(name, base) : base;
|
|
1565
|
+
let withTemplate = props;
|
|
1566
|
+
if (withTemplate.template === undefined) {
|
|
1567
|
+
const template = inferTemplateName(props);
|
|
1568
|
+
if (template) {
|
|
1569
|
+
withTemplate = { ...props, template };
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
const llmProps = llmConnectionTrackingProperties(_llmConnectionStatus);
|
|
1573
|
+
const enriched = { ...withTemplate };
|
|
1574
|
+
for (const [key, value] of Object.entries(llmProps)) {
|
|
1575
|
+
if (enriched[key] === undefined) enriched[key] = value;
|
|
1576
|
+
}
|
|
1577
|
+
const replayProps = sessionReplayTrackingProperties();
|
|
1578
|
+
for (const [key, value] of Object.entries(replayProps)) {
|
|
1579
|
+
if (enriched[key] === undefined) enriched[key] = value;
|
|
1580
|
+
}
|
|
1581
|
+
return applyTrackingIdentity(enriched);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
function sessionReplayTrackingProperties(): Record<string, unknown> {
|
|
1585
|
+
const module = _sessionReplayModuleForCapture;
|
|
1586
|
+
if (!module) return {};
|
|
1587
|
+
const context = module.getSessionReplayContext?.();
|
|
1588
|
+
if (!context?.active) return {};
|
|
1589
|
+
const occurredAt = new Date().toISOString();
|
|
1590
|
+
return {
|
|
1591
|
+
sessionReplayId: context.replayId,
|
|
1592
|
+
sessionReplayStartedAt: context.startedAt,
|
|
1593
|
+
sessionReplayAt: occurredAt,
|
|
1594
|
+
...(module.getSessionReplayUrl
|
|
1595
|
+
? {
|
|
1596
|
+
sessionReplayUrl: module.getSessionReplayUrl({ at: occurredAt }),
|
|
1597
|
+
}
|
|
1598
|
+
: {}),
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
function pageviewKey(): string {
|
|
1603
|
+
return window.location.href;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
function pageviewProperties(reason: string): Record<string, unknown> {
|
|
1607
|
+
const properties: Record<string, unknown> = {
|
|
1608
|
+
url: !_trackingContentCaptureEnabled
|
|
1609
|
+
? window.location.origin + window.location.pathname
|
|
1610
|
+
: scrubUrl(window.location.href),
|
|
1611
|
+
path: window.location.pathname,
|
|
1612
|
+
hostname: window.location.hostname,
|
|
1613
|
+
navigation_type: reason,
|
|
1614
|
+
};
|
|
1615
|
+
if (_trackingContentCaptureEnabled && window.location.search) {
|
|
1616
|
+
properties.search = scrubUrl(window.location.search);
|
|
1617
|
+
}
|
|
1618
|
+
if (_trackingContentCaptureEnabled && typeof document !== "undefined") {
|
|
1619
|
+
if (document.referrer) {
|
|
1620
|
+
properties.referrer = scrubUrl(document.referrer);
|
|
1621
|
+
}
|
|
1622
|
+
if (document.title) {
|
|
1623
|
+
properties.title = document.title;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return properties;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
function emitPageview(reason: string): void {
|
|
1630
|
+
if (isLocalAnalyticsHostname(window.location.hostname)) return;
|
|
1631
|
+
const state = getPageviewTrackingState();
|
|
1632
|
+
const key = pageviewKey();
|
|
1633
|
+
if (state.lastPageviewKey === key) return;
|
|
1634
|
+
state.lastPageviewKey = key;
|
|
1635
|
+
trackEvent("pageview", pageviewProperties(reason));
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
function schedulePageview(reason: string): void {
|
|
1639
|
+
if (!_trackingContentCaptureEnabled) {
|
|
1640
|
+
void stopSessionReplay("local-plan-privacy");
|
|
1641
|
+
}
|
|
1642
|
+
const run = () => emitPageview(reason);
|
|
1643
|
+
const pendingStartupContext: Array<Promise<void>> = [];
|
|
1644
|
+
if (_llmConnectionRefresh && !_llmConnectionStatus) {
|
|
1645
|
+
pendingStartupContext.push(_llmConnectionRefresh);
|
|
1646
|
+
}
|
|
1647
|
+
if (_trackingSessionRefresh && !_trackingIdentityResolved) {
|
|
1648
|
+
pendingStartupContext.push(_trackingSessionRefresh);
|
|
1649
|
+
}
|
|
1650
|
+
if (pendingStartupContext.length > 0) {
|
|
1651
|
+
const timeout = new Promise<void>((resolve) =>
|
|
1652
|
+
window.setTimeout(resolve, 250),
|
|
1653
|
+
);
|
|
1654
|
+
Promise.race([Promise.allSettled(pendingStartupContext), timeout]).finally(
|
|
1655
|
+
run,
|
|
1656
|
+
);
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
if (typeof queueMicrotask === "function") {
|
|
1660
|
+
queueMicrotask(run);
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
window.setTimeout(run, 0);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
function installPageviewTracking(): void {
|
|
1667
|
+
const state = getPageviewTrackingState();
|
|
1668
|
+
if (state.installed) return;
|
|
1669
|
+
state.installed = true;
|
|
1670
|
+
|
|
1671
|
+
schedulePageview("load");
|
|
1672
|
+
|
|
1673
|
+
const originalPushState = window.history.pushState;
|
|
1674
|
+
const originalReplaceState = window.history.replaceState;
|
|
1675
|
+
|
|
1676
|
+
window.history.pushState = function pushState(...args) {
|
|
1677
|
+
const result = originalPushState.apply(this, args);
|
|
1678
|
+
syncTrackingContentCaptureForLocation();
|
|
1679
|
+
schedulePageview("pushState");
|
|
1680
|
+
return result;
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
window.history.replaceState = function replaceState(...args) {
|
|
1684
|
+
const result = originalReplaceState.apply(this, args);
|
|
1685
|
+
syncTrackingContentCaptureForLocation();
|
|
1686
|
+
schedulePageview("replaceState");
|
|
1687
|
+
return result;
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
window.addEventListener("popstate", () => {
|
|
1691
|
+
syncTrackingContentCaptureForLocation();
|
|
1692
|
+
schedulePageview("popstate");
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
function sendAgentNativeAnalytics(
|
|
1697
|
+
name: string,
|
|
1698
|
+
properties: Record<string, unknown>,
|
|
1699
|
+
): void {
|
|
1700
|
+
if (isLocalAnalyticsHostname(window.location.hostname)) return;
|
|
1701
|
+
|
|
1702
|
+
const publicKey =
|
|
1703
|
+
_agentNativeAnalyticsPublicKey ||
|
|
1704
|
+
(import.meta.env as Record<string, string | undefined>)
|
|
1705
|
+
?.VITE_AGENT_NATIVE_ANALYTICS_PUBLIC_KEY;
|
|
1706
|
+
if (!publicKey) return;
|
|
1707
|
+
|
|
1708
|
+
const endpoint =
|
|
1709
|
+
_agentNativeAnalyticsEndpoint ||
|
|
1710
|
+
(import.meta.env as Record<string, string | undefined>)
|
|
1711
|
+
?.VITE_AGENT_NATIVE_ANALYTICS_ENDPOINT ||
|
|
1712
|
+
AGENT_NATIVE_ANALYTICS_DEFAULT_ENDPOINT;
|
|
1713
|
+
const userId =
|
|
1714
|
+
typeof properties.userId === "string" ? properties.userId : undefined;
|
|
1715
|
+
const body = JSON.stringify({
|
|
1716
|
+
publicKey,
|
|
1717
|
+
event: name,
|
|
1718
|
+
properties,
|
|
1719
|
+
userId,
|
|
1720
|
+
anonymousId: getOrCreateAnonymousId(),
|
|
1721
|
+
sessionId: getOrCreateSessionId(),
|
|
1722
|
+
timestamp: new Date().toISOString(),
|
|
1723
|
+
});
|
|
1724
|
+
|
|
1725
|
+
try {
|
|
1726
|
+
if (navigator.sendBeacon) {
|
|
1727
|
+
const sent = navigator.sendBeacon(endpoint, body);
|
|
1728
|
+
if (sent) return;
|
|
1729
|
+
}
|
|
1730
|
+
fetch(endpoint, {
|
|
1731
|
+
method: "POST",
|
|
1732
|
+
body,
|
|
1733
|
+
keepalive: true,
|
|
1734
|
+
headers: { "Content-Type": "text/plain;charset=UTF-8" },
|
|
1735
|
+
}).catch(() => {});
|
|
1736
|
+
} catch {
|
|
1737
|
+
// best-effort
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
export function trackEvent(
|
|
1742
|
+
name: string,
|
|
1743
|
+
params?: Record<string, unknown>,
|
|
1744
|
+
): void {
|
|
1745
|
+
if (typeof window === "undefined") return;
|
|
1746
|
+
ensureSentry();
|
|
1747
|
+
const props = resolveProps(name, params);
|
|
1748
|
+
window.gtag?.("event", name.replace(/\s+/g, "_"), props);
|
|
1749
|
+
if (ensureAmplitude()) {
|
|
1750
|
+
amplitude.track(name, props);
|
|
1751
|
+
}
|
|
1752
|
+
sendAgentNativeAnalytics(name, props);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
export function trackSessionStatus(signedIn: boolean): void {
|
|
1756
|
+
trackEvent("session status", { signed_in: signedIn });
|
|
1757
|
+
}
|