@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,1233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Chat Bridge (browser)
|
|
3
|
+
*
|
|
4
|
+
* Sends structured messages to the agent chat from UI interactions.
|
|
5
|
+
* Messages are sent via postMessage to the parent window (or self if top-level).
|
|
6
|
+
* Builder frames are special: code requests go to Builder, but content prompts
|
|
7
|
+
* stay inside the embedded app so its own AgentSidebar can receive them.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ReasoningEffort } from "../shared/reasoning-effort.js";
|
|
11
|
+
import { agentNativePath } from "./api-path.js";
|
|
12
|
+
import {
|
|
13
|
+
isInBuilderFrame,
|
|
14
|
+
isTrustedBuilderMessage,
|
|
15
|
+
sendToBuilderChat,
|
|
16
|
+
} from "./builder-frame.js";
|
|
17
|
+
import {
|
|
18
|
+
isEmbedAuthActive,
|
|
19
|
+
isEmbedMcpChatBridgeActive,
|
|
20
|
+
markEmbedMcpChatBridgeActive,
|
|
21
|
+
readEmbedMcpChatBridgeFlagFromUrl,
|
|
22
|
+
} from "./embed-auth.js";
|
|
23
|
+
import {
|
|
24
|
+
getFramePostMessageTargetOrigin,
|
|
25
|
+
isTrustedFrameMessage,
|
|
26
|
+
} from "./frame.js";
|
|
27
|
+
import { sendMcpAppHostMessage } from "./mcp-app-host.js";
|
|
28
|
+
|
|
29
|
+
export type AgentChatRequestMode = "act" | "plan";
|
|
30
|
+
|
|
31
|
+
export interface AgentChatMessage {
|
|
32
|
+
/** The visible prompt message sent to the chat */
|
|
33
|
+
message: string;
|
|
34
|
+
/** Hidden context appended to the message (not shown in chat UI) */
|
|
35
|
+
context?: string;
|
|
36
|
+
/** true = auto-submit, false = prefill only, omit = use project setting */
|
|
37
|
+
submit?: boolean;
|
|
38
|
+
/** Optional project slug for structured context */
|
|
39
|
+
projectSlug?: string;
|
|
40
|
+
/** Optional preset name for downstream consumers */
|
|
41
|
+
preset?: string;
|
|
42
|
+
/** Optional reference image paths */
|
|
43
|
+
referenceImagePaths?: string[];
|
|
44
|
+
/** Optional uploaded reference images */
|
|
45
|
+
uploadedReferenceImages?: string[];
|
|
46
|
+
/** Optional image data URLs to include in the submitted chat message */
|
|
47
|
+
images?: string[];
|
|
48
|
+
/** Stable tab identifier — auto-generated if omitted */
|
|
49
|
+
tabId?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Message routing type:
|
|
52
|
+
* - "content" (default): stays in the embedded app agent for content/data operations
|
|
53
|
+
* - "code": routes to the code editing frame (Agent Native Desktop or Builder.io)
|
|
54
|
+
*
|
|
55
|
+
* When type is "code" and no frame is connected, a dialog is shown.
|
|
56
|
+
* `requiresCode: true` is treated as `type: "code"` for backward compatibility.
|
|
57
|
+
*/
|
|
58
|
+
type?: "content" | "code";
|
|
59
|
+
/** @deprecated Use `type: "code"` instead. If true, treated as `type: "code"`. */
|
|
60
|
+
requiresCode?: boolean;
|
|
61
|
+
/** Model preference for this sub-agent (e.g. "claude-haiku-4-5"). Uses default if omitted */
|
|
62
|
+
model?: string;
|
|
63
|
+
/** Engine preference paired with model for cross-provider switches. */
|
|
64
|
+
engine?: string;
|
|
65
|
+
/** Reasoning effort preference paired with model. */
|
|
66
|
+
effort?: ReasoningEffort;
|
|
67
|
+
/**
|
|
68
|
+
* Execution mode for this submitted turn. When omitted, sendToAgentChat
|
|
69
|
+
* snapshots the current AgentPanel mode from localStorage when available.
|
|
70
|
+
*/
|
|
71
|
+
mode?: AgentChatRequestMode;
|
|
72
|
+
/** @deprecated Use `mode` instead. */
|
|
73
|
+
requestMode?: AgentChatRequestMode;
|
|
74
|
+
/** Scoped system prompt additions for this sub-agent */
|
|
75
|
+
instructions?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Message delivery target. Auto-submitted MCP App messages normally relay to
|
|
78
|
+
* the host chat; use "local" when a control explicitly targets this app's
|
|
79
|
+
* own AgentSidebar.
|
|
80
|
+
*/
|
|
81
|
+
chatTarget?: "auto" | "local";
|
|
82
|
+
/**
|
|
83
|
+
* Whether to open the agent sidebar if it's currently hidden.
|
|
84
|
+
* Defaults to true — submitting a chat should make the response visible.
|
|
85
|
+
* Pass `false` for background/silent sends that shouldn't pop the UI open.
|
|
86
|
+
*/
|
|
87
|
+
openSidebar?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* When true, opens a new chat tab before sending the message.
|
|
90
|
+
* Use for creation requests (create tool, dashboard, etc.) that deserve
|
|
91
|
+
* their own isolated thread rather than cluttering an existing conversation.
|
|
92
|
+
*/
|
|
93
|
+
newTab?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* When true with newTab, creates the tab in the background without
|
|
96
|
+
* focusing it or opening the sidebar. The message runs silently.
|
|
97
|
+
*/
|
|
98
|
+
background?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Stable id used to deduplicate a submit and correlate it with
|
|
101
|
+
* {@link AGENT_CHAT_SUBMIT_RESULT_EVENT}. Auto-generated if omitted.
|
|
102
|
+
*/
|
|
103
|
+
submitMessageId?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface AgentChatContextItem {
|
|
107
|
+
/** Stable key used to replace an existing context nugget. */
|
|
108
|
+
key: string;
|
|
109
|
+
/** Short label shown in the composer context chip. */
|
|
110
|
+
title: string;
|
|
111
|
+
/** Hidden context included with the next submitted prompt. */
|
|
112
|
+
context: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface AgentChatContextSetOptions extends AgentChatContextItem {
|
|
116
|
+
/**
|
|
117
|
+
* Whether to open the agent sidebar if it's currently hidden.
|
|
118
|
+
* Defaults to true so the user can see the staged context.
|
|
119
|
+
*/
|
|
120
|
+
openSidebar?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether to move keyboard focus into the composer when staging the item.
|
|
123
|
+
* Defaults to true. Pass `false` for context that mirrors ambient UI state
|
|
124
|
+
* (e.g. a canvas element selection) so staging never steals focus from an
|
|
125
|
+
* unrelated editor — such as an inline text editor in a design canvas.
|
|
126
|
+
*/
|
|
127
|
+
focus?: boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @deprecated Use `AgentChatContextSetOptions` instead. */
|
|
131
|
+
export type AgentChatContextMessage = AgentChatContextSetOptions;
|
|
132
|
+
|
|
133
|
+
export interface AgentChatContextState {
|
|
134
|
+
items: AgentChatContextItem[];
|
|
135
|
+
updatedAt: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface AgentChatOpenThreadRequest {
|
|
139
|
+
threadId: string;
|
|
140
|
+
newThread?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Open only while this thread is still active (or no thread is active).
|
|
143
|
+
* This lets transient surfaces restore their own chat without stealing a
|
|
144
|
+
* thread the user selected in the meantime.
|
|
145
|
+
*/
|
|
146
|
+
onlyIfActiveThreadId?: string;
|
|
147
|
+
openRequestId?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface AgentChatOpenTaskRequest {
|
|
151
|
+
threadId: string;
|
|
152
|
+
parentThreadId?: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
name?: string;
|
|
155
|
+
openRequestId?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type BufferedAgentChatOpenRequest = {
|
|
159
|
+
id: string;
|
|
160
|
+
eventType: "agent-chat:open-thread" | "agent-task-open";
|
|
161
|
+
detail: AgentChatOpenThreadRequest | AgentChatOpenTaskRequest;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export interface AgentComposerReference {
|
|
165
|
+
label: string;
|
|
166
|
+
icon?: string;
|
|
167
|
+
source?: string;
|
|
168
|
+
refType: string;
|
|
169
|
+
refId?: string | null;
|
|
170
|
+
refPath?: string | null;
|
|
171
|
+
/** Stable composer slot this reference occupies. Slot references replace older values. */
|
|
172
|
+
slotKey?: string;
|
|
173
|
+
/** Short label shown before the selected value in the composer chip. */
|
|
174
|
+
slotLabel?: string;
|
|
175
|
+
/** Additional app-defined data used by the client for filtering and grouping. */
|
|
176
|
+
metadata?: Record<string, unknown>;
|
|
177
|
+
/** Slots to remove when this reference is inserted or removed. */
|
|
178
|
+
clearsSlots?: string[];
|
|
179
|
+
/** Additional references to insert before this one. */
|
|
180
|
+
relatedReferences?: AgentComposerReference[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface AgentComposerReferenceInsertOptions {
|
|
184
|
+
/**
|
|
185
|
+
* Whether to open the agent sidebar before inserting the reference.
|
|
186
|
+
* Defaults to false so contextual auto-tags can stay quiet.
|
|
187
|
+
*/
|
|
188
|
+
openSidebar?: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface AgentComposerReferenceInsertPayload extends AgentComposerReference {
|
|
192
|
+
insertMessageId: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface AgentChatContextMutationOptions {
|
|
196
|
+
/**
|
|
197
|
+
* Whether to open the agent sidebar if it's currently hidden.
|
|
198
|
+
* Defaults to true for set/add and false for remove/clear.
|
|
199
|
+
*/
|
|
200
|
+
openSidebar?: boolean;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface AgentChatContextRemoveOptions extends AgentChatContextMutationOptions {
|
|
204
|
+
/** Stable key of the staged context nugget to remove. */
|
|
205
|
+
key: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const AGENT_CHAT_MESSAGE_TYPE = "agentNative.submitChat";
|
|
209
|
+
const AGENT_CHAT_CONTEXT_STATE_KEY = "agent-chat-context";
|
|
210
|
+
const AGENT_CHAT_EXEC_MODE_KEY = "agent-native-exec-mode";
|
|
211
|
+
export const AGENT_CHAT_CONTEXT_CHANGED_EVENT =
|
|
212
|
+
"agentNative.chatContextChanged";
|
|
213
|
+
export const AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE = "agentNative.setChatContext";
|
|
214
|
+
export const AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE =
|
|
215
|
+
"agentNative.removeChatContext";
|
|
216
|
+
export const AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE =
|
|
217
|
+
"agentNative.clearChatContext";
|
|
218
|
+
export const AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE =
|
|
219
|
+
"agentNative.insertComposerReference";
|
|
220
|
+
export const AGENT_CHAT_INSERT_REFERENCE_EVENT =
|
|
221
|
+
"agentNative:insert-composer-reference";
|
|
222
|
+
const AGENT_PANEL_PREPARE_EVENT = "agent-panel:prepare";
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Fired once a submitted turn's fate is known: `delivered: true` once the
|
|
226
|
+
* receiving AssistantChat has actually committed the turn (added it to the
|
|
227
|
+
* visible thread, independent of whether the agent's response later
|
|
228
|
+
* succeeds), or `delivered: false` when it was rejected before ever
|
|
229
|
+
* appearing — e.g. no LLM/agent engine configured. Callers that must know
|
|
230
|
+
* whether their submit truly landed (rather than fire-and-forget) should use
|
|
231
|
+
* {@link sendToAgentChatAndConfirm} instead of listening for this directly.
|
|
232
|
+
*/
|
|
233
|
+
export const AGENT_CHAT_SUBMIT_RESULT_EVENT = "agentNative.chatSubmitResult";
|
|
234
|
+
|
|
235
|
+
export interface AgentChatSubmitResult {
|
|
236
|
+
submitMessageId: string;
|
|
237
|
+
delivered: boolean;
|
|
238
|
+
reason?: string;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Report a submit's definitive outcome so `sendToAgentChatAndConfirm` (or any
|
|
242
|
+
* other correlated listener) can resolve. No-ops without a submitMessageId or
|
|
243
|
+
* a window (SSR). */
|
|
244
|
+
export function reportAgentChatSubmitResult(
|
|
245
|
+
submitMessageId: string | undefined,
|
|
246
|
+
delivered: boolean,
|
|
247
|
+
reason?: string,
|
|
248
|
+
): void {
|
|
249
|
+
if (
|
|
250
|
+
!submitMessageId ||
|
|
251
|
+
cancelledSubmitIds.has(submitMessageId) ||
|
|
252
|
+
typeof window === "undefined"
|
|
253
|
+
) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
window.dispatchEvent(
|
|
257
|
+
new CustomEvent<AgentChatSubmitResult>(AGENT_CHAT_SUBMIT_RESULT_EVENT, {
|
|
258
|
+
detail: { submitMessageId, delivered, reason },
|
|
259
|
+
}),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let agentChatContextState: AgentChatContextState = {
|
|
264
|
+
items: [],
|
|
265
|
+
updatedAt: 0,
|
|
266
|
+
};
|
|
267
|
+
const agentChatContextListeners = new Set<() => void>();
|
|
268
|
+
let agentChatContextNotifyQueued = false;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Listen for chatRunning messages from the frame (postMessage)
|
|
272
|
+
* and re-dispatch as a CustomEvent so hooks like useAgentChatGenerating() work.
|
|
273
|
+
*/
|
|
274
|
+
if (typeof window !== "undefined") {
|
|
275
|
+
window.addEventListener("message", (event) => {
|
|
276
|
+
if (!isTrustedFrameMessage(event) && !isTrustedBuilderMessage(event)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (
|
|
280
|
+
event.data?.type === "agentNative.chatRunning" ||
|
|
281
|
+
event.data?.type === "builder.chatRunning"
|
|
282
|
+
) {
|
|
283
|
+
window.dispatchEvent(
|
|
284
|
+
new CustomEvent("agentNative.chatRunning", {
|
|
285
|
+
detail: event.data.detail ?? event.data.data,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Generate a unique tab ID */
|
|
293
|
+
export function generateTabId(): string {
|
|
294
|
+
return `chat-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Unique id for one submitted message, used to dedup live + replayed sends. */
|
|
298
|
+
function generateSubmitMessageId(): string {
|
|
299
|
+
return `submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Self-submit buffer: same-window sends post to `window` itself, but the
|
|
303
|
+
// receiver is lazy-loaded and may not be listening yet. Buffer each submit so
|
|
304
|
+
// the panel can replay it on mount; claimAgentChatSubmit dedups by id so a
|
|
305
|
+
// submit received both live and replayed is delivered exactly once.
|
|
306
|
+
interface BufferedSelfSubmit {
|
|
307
|
+
id: string;
|
|
308
|
+
data: Record<string, unknown>;
|
|
309
|
+
at: number;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const SELF_SUBMIT_BUFFER_TTL_MS = 8000;
|
|
313
|
+
const bufferedSelfSubmits: BufferedSelfSubmit[] = [];
|
|
314
|
+
const claimedSubmitIds = new Set<string>();
|
|
315
|
+
const cancelledSubmitIds = new Set<string>();
|
|
316
|
+
|
|
317
|
+
interface BufferedOpenRequest extends BufferedAgentChatOpenRequest {
|
|
318
|
+
at: number;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const OPEN_REQUEST_BUFFER_TTL_MS = 8000;
|
|
322
|
+
const bufferedOpenRequests: BufferedOpenRequest[] = [];
|
|
323
|
+
const claimedOpenRequestIds = new Set<string>();
|
|
324
|
+
|
|
325
|
+
function pruneSelfSubmitBuffer(now: number): void {
|
|
326
|
+
for (let i = bufferedSelfSubmits.length - 1; i >= 0; i -= 1) {
|
|
327
|
+
if (now - bufferedSelfSubmits[i].at > SELF_SUBMIT_BUFFER_TTL_MS) {
|
|
328
|
+
const [removed] = bufferedSelfSubmits.splice(i, 1);
|
|
329
|
+
if (removed) claimedSubmitIds.delete(removed.id);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function bufferSelfSubmit(data: Record<string, unknown>): void {
|
|
335
|
+
const id =
|
|
336
|
+
typeof data.submitMessageId === "string" ? data.submitMessageId : undefined;
|
|
337
|
+
if (!id) return;
|
|
338
|
+
const now = Date.now();
|
|
339
|
+
pruneSelfSubmitBuffer(now);
|
|
340
|
+
bufferedSelfSubmits.push({ id, data, at: now });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Permanently tombstone a submit for this page lifetime and remove its
|
|
345
|
+
* cold-start replay. A confirmation timeout must be terminal: callers may
|
|
346
|
+
* retry while preserving their own state, so the original submit cannot be
|
|
347
|
+
* allowed to appear later when a lazy panel or thread ref finally mounts.
|
|
348
|
+
*/
|
|
349
|
+
export function cancelAgentChatSubmit(id: string | undefined): void {
|
|
350
|
+
if (!id) return;
|
|
351
|
+
cancelledSubmitIds.add(id);
|
|
352
|
+
claimedSubmitIds.add(id);
|
|
353
|
+
for (let index = bufferedSelfSubmits.length - 1; index >= 0; index -= 1) {
|
|
354
|
+
if (bufferedSelfSubmits[index]?.id === id) {
|
|
355
|
+
bufferedSelfSubmits.splice(index, 1);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Whether a confirmed-submit timeout has made this delivery terminal. */
|
|
361
|
+
export function isAgentChatSubmitCancelled(id: string | undefined): boolean {
|
|
362
|
+
return Boolean(id && cancelledSubmitIds.has(id));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function pruneOpenRequestBuffer(now: number): void {
|
|
366
|
+
for (let i = bufferedOpenRequests.length - 1; i >= 0; i -= 1) {
|
|
367
|
+
if (now - bufferedOpenRequests[i].at > OPEN_REQUEST_BUFFER_TTL_MS) {
|
|
368
|
+
const [removed] = bufferedOpenRequests.splice(i, 1);
|
|
369
|
+
if (removed) claimedOpenRequestIds.delete(removed.id);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function bufferOpenRequest(
|
|
375
|
+
eventType: BufferedAgentChatOpenRequest["eventType"],
|
|
376
|
+
detail: AgentChatOpenThreadRequest | AgentChatOpenTaskRequest,
|
|
377
|
+
): BufferedOpenRequest {
|
|
378
|
+
const now = Date.now();
|
|
379
|
+
pruneOpenRequestBuffer(now);
|
|
380
|
+
const id = `open-${now}-${Math.random().toString(36).slice(2, 8)}`;
|
|
381
|
+
const entry: BufferedOpenRequest = {
|
|
382
|
+
id,
|
|
383
|
+
eventType,
|
|
384
|
+
detail: { ...detail, openRequestId: id },
|
|
385
|
+
at: now,
|
|
386
|
+
};
|
|
387
|
+
bufferedOpenRequests.push(entry);
|
|
388
|
+
return entry;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Unclaimed self-submit payloads, for the panel to replay once it mounts. */
|
|
392
|
+
export function drainBufferedAgentChatSubmits(): Array<
|
|
393
|
+
Record<string, unknown>
|
|
394
|
+
> {
|
|
395
|
+
pruneSelfSubmitBuffer(Date.now());
|
|
396
|
+
return bufferedSelfSubmits
|
|
397
|
+
.filter((entry) => !claimedSubmitIds.has(entry.id))
|
|
398
|
+
.map((entry) => entry.data);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Claim a submit; false if already handled. Idless submits always pass. */
|
|
402
|
+
export function claimAgentChatSubmit(id: string | undefined): boolean {
|
|
403
|
+
if (!id) return true;
|
|
404
|
+
if (cancelledSubmitIds.has(id)) return false;
|
|
405
|
+
if (claimedSubmitIds.has(id)) return false;
|
|
406
|
+
claimedSubmitIds.add(id);
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** Unclaimed open-thread/task requests, for the panel to replay once it mounts. */
|
|
411
|
+
export function drainBufferedAgentChatOpenRequests(): BufferedAgentChatOpenRequest[] {
|
|
412
|
+
pruneOpenRequestBuffer(Date.now());
|
|
413
|
+
return bufferedOpenRequests
|
|
414
|
+
.filter((entry) => !claimedOpenRequestIds.has(entry.id))
|
|
415
|
+
.map(({ id, eventType, detail }) => ({ id, eventType, detail }));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Claim an open-thread/task request; false if already handled. Idless events pass. */
|
|
419
|
+
export function claimAgentChatOpenRequest(id: unknown): boolean {
|
|
420
|
+
if (typeof id !== "string" || !id) return true;
|
|
421
|
+
if (claimedOpenRequestIds.has(id)) return false;
|
|
422
|
+
claimedOpenRequestIds.add(id);
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Test-only: reset the self-submit buffer and claim set. */
|
|
427
|
+
export function _resetAgentChatSubmitBufferForTests(): void {
|
|
428
|
+
bufferedSelfSubmits.length = 0;
|
|
429
|
+
claimedSubmitIds.clear();
|
|
430
|
+
cancelledSubmitIds.clear();
|
|
431
|
+
bufferedOpenRequests.length = 0;
|
|
432
|
+
claimedOpenRequestIds.clear();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export function normalizeAgentChatContextItem(
|
|
436
|
+
item: unknown,
|
|
437
|
+
): AgentChatContextItem | null {
|
|
438
|
+
if (typeof item !== "object" || item === null) return null;
|
|
439
|
+
const candidate = item as Partial<AgentChatContextItem>;
|
|
440
|
+
if (
|
|
441
|
+
typeof candidate.key !== "string" ||
|
|
442
|
+
typeof candidate.context !== "string" ||
|
|
443
|
+
typeof candidate.title !== "string"
|
|
444
|
+
) {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
const key = candidate.key.trim();
|
|
448
|
+
const context = candidate.context.trim();
|
|
449
|
+
if (!key || !context) return null;
|
|
450
|
+
return {
|
|
451
|
+
key,
|
|
452
|
+
title: candidate.title.trim() || key,
|
|
453
|
+
context,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export function normalizeAgentChatContextItems(
|
|
458
|
+
items: unknown,
|
|
459
|
+
): AgentChatContextItem[] {
|
|
460
|
+
if (!Array.isArray(items)) return [];
|
|
461
|
+
const deduped = new Map<string, AgentChatContextItem>();
|
|
462
|
+
for (const rawItem of items) {
|
|
463
|
+
const item = normalizeAgentChatContextItem(rawItem);
|
|
464
|
+
if (!item) continue;
|
|
465
|
+
deduped.set(item.key, item);
|
|
466
|
+
}
|
|
467
|
+
return [...deduped.values()];
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function normalizeAgentChatContextState(
|
|
471
|
+
value: unknown,
|
|
472
|
+
): AgentChatContextState | null {
|
|
473
|
+
if (!value || typeof value !== "object") return null;
|
|
474
|
+
const raw = value as {
|
|
475
|
+
value?: unknown;
|
|
476
|
+
items?: unknown;
|
|
477
|
+
updatedAt?: unknown;
|
|
478
|
+
};
|
|
479
|
+
const candidate =
|
|
480
|
+
raw.value && typeof raw.value === "object"
|
|
481
|
+
? (raw.value as { items?: unknown; updatedAt?: unknown })
|
|
482
|
+
: raw;
|
|
483
|
+
const items = normalizeAgentChatContextItems(candidate.items);
|
|
484
|
+
return {
|
|
485
|
+
items,
|
|
486
|
+
updatedAt:
|
|
487
|
+
typeof candidate.updatedAt === "number" ? candidate.updatedAt : 0,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function withReplacedAgentChatContextItem(
|
|
492
|
+
items: readonly AgentChatContextItem[],
|
|
493
|
+
item: AgentChatContextItem,
|
|
494
|
+
): AgentChatContextItem[] {
|
|
495
|
+
const index = items.findIndex((current) => current.key === item.key);
|
|
496
|
+
if (index === -1) return [...items, item];
|
|
497
|
+
return items.map((current, currentIndex) =>
|
|
498
|
+
currentIndex === index ? item : current,
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function notifyAgentChatContextListeners(): void {
|
|
503
|
+
if (agentChatContextNotifyQueued) return;
|
|
504
|
+
agentChatContextNotifyQueued = true;
|
|
505
|
+
const notify = () => {
|
|
506
|
+
agentChatContextNotifyQueued = false;
|
|
507
|
+
for (const listener of Array.from(agentChatContextListeners)) listener();
|
|
508
|
+
};
|
|
509
|
+
if (typeof queueMicrotask === "function") {
|
|
510
|
+
queueMicrotask(notify);
|
|
511
|
+
} else {
|
|
512
|
+
setTimeout(notify, 0);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function persistAgentChatContextState(state: AgentChatContextState): void {
|
|
517
|
+
if (typeof window === "undefined" || typeof fetch !== "function") return;
|
|
518
|
+
fetch(
|
|
519
|
+
agentNativePath(
|
|
520
|
+
`/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,
|
|
521
|
+
),
|
|
522
|
+
{
|
|
523
|
+
method: "PUT",
|
|
524
|
+
keepalive: true,
|
|
525
|
+
headers: { "Content-Type": "application/json" },
|
|
526
|
+
body: JSON.stringify(state),
|
|
527
|
+
},
|
|
528
|
+
).catch(() => {});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export function publishAgentChatContextItems(
|
|
532
|
+
items: readonly AgentChatContextItem[],
|
|
533
|
+
options?: { persist?: boolean; updatedAt?: number },
|
|
534
|
+
): AgentChatContextState {
|
|
535
|
+
const next: AgentChatContextState = {
|
|
536
|
+
items: normalizeAgentChatContextItems([...items]),
|
|
537
|
+
updatedAt: options?.updatedAt ?? Date.now(),
|
|
538
|
+
};
|
|
539
|
+
if (next.updatedAt < agentChatContextState.updatedAt) {
|
|
540
|
+
return agentChatContextState;
|
|
541
|
+
}
|
|
542
|
+
agentChatContextState = next;
|
|
543
|
+
notifyAgentChatContextListeners();
|
|
544
|
+
if (typeof window !== "undefined") {
|
|
545
|
+
window.dispatchEvent(
|
|
546
|
+
new CustomEvent(AGENT_CHAT_CONTEXT_CHANGED_EVENT, {
|
|
547
|
+
detail: next,
|
|
548
|
+
}),
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
if (options?.persist !== false) {
|
|
552
|
+
persistAgentChatContextState(next);
|
|
553
|
+
}
|
|
554
|
+
return next;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export function getAgentChatContextState(): AgentChatContextState {
|
|
558
|
+
return agentChatContextState;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export function listAgentChatContext(): AgentChatContextItem[] {
|
|
562
|
+
return [...agentChatContextState.items];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function subscribeAgentChatContext(listener: () => void): () => void {
|
|
566
|
+
agentChatContextListeners.add(listener);
|
|
567
|
+
return () => {
|
|
568
|
+
agentChatContextListeners.delete(listener);
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export async function refreshAgentChatContext(): Promise<AgentChatContextState> {
|
|
573
|
+
if (typeof window === "undefined" || typeof fetch !== "function") {
|
|
574
|
+
return agentChatContextState;
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
const res = await fetch(
|
|
578
|
+
agentNativePath(
|
|
579
|
+
`/_agent-native/application-state/${AGENT_CHAT_CONTEXT_STATE_KEY}`,
|
|
580
|
+
),
|
|
581
|
+
);
|
|
582
|
+
if (!res.ok || res.status === 204) return agentChatContextState;
|
|
583
|
+
const text = await res.text();
|
|
584
|
+
if (!text) return agentChatContextState;
|
|
585
|
+
const state = normalizeAgentChatContextState(JSON.parse(text));
|
|
586
|
+
if (!state) return agentChatContextState;
|
|
587
|
+
return publishAgentChatContextItems(state.items, {
|
|
588
|
+
persist: false,
|
|
589
|
+
updatedAt: state.updatedAt,
|
|
590
|
+
});
|
|
591
|
+
} catch {
|
|
592
|
+
return agentChatContextState;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function formatAgentChatContextItemsForPrompt(
|
|
597
|
+
items: readonly AgentChatContextItem[],
|
|
598
|
+
): string {
|
|
599
|
+
return items
|
|
600
|
+
.map(normalizeAgentChatContextItem)
|
|
601
|
+
.filter((item): item is AgentChatContextItem => item !== null)
|
|
602
|
+
.map((item) => [`## ${item.title}`, item.context].join("\n"))
|
|
603
|
+
.join("\n\n");
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function appendAgentChatContextToMessage(
|
|
607
|
+
message: string,
|
|
608
|
+
context: string,
|
|
609
|
+
): string {
|
|
610
|
+
const trimmedContext = context.trim();
|
|
611
|
+
if (!trimmedContext) return message;
|
|
612
|
+
return `${message.trim()}\n\n<context>\n${trimmedContext}\n</context>`;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function normalizeStringArray(value: unknown): string[] | undefined {
|
|
616
|
+
if (!Array.isArray(value)) return undefined;
|
|
617
|
+
const normalized = value
|
|
618
|
+
.filter((item): item is string => typeof item === "string")
|
|
619
|
+
.map((item) => item.trim())
|
|
620
|
+
.filter(Boolean);
|
|
621
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function normalizeMetadata(
|
|
625
|
+
value: unknown,
|
|
626
|
+
): Record<string, unknown> | undefined {
|
|
627
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
628
|
+
return undefined;
|
|
629
|
+
}
|
|
630
|
+
return value as Record<string, unknown>;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function normalizeAgentComposerReferenceInternal(
|
|
634
|
+
value: unknown,
|
|
635
|
+
depth: number,
|
|
636
|
+
): AgentComposerReference | null {
|
|
637
|
+
if (typeof value !== "object" || value === null) return null;
|
|
638
|
+
const candidate = value as Partial<AgentComposerReference>;
|
|
639
|
+
const label =
|
|
640
|
+
typeof candidate.label === "string" ? candidate.label.trim() : "";
|
|
641
|
+
const refType =
|
|
642
|
+
typeof candidate.refType === "string" ? candidate.refType.trim() : "";
|
|
643
|
+
if (!label || !refType) return null;
|
|
644
|
+
const normalized: AgentComposerReference = {
|
|
645
|
+
label,
|
|
646
|
+
icon:
|
|
647
|
+
typeof candidate.icon === "string" && candidate.icon.trim()
|
|
648
|
+
? candidate.icon.trim()
|
|
649
|
+
: undefined,
|
|
650
|
+
source:
|
|
651
|
+
typeof candidate.source === "string" && candidate.source.trim()
|
|
652
|
+
? candidate.source.trim()
|
|
653
|
+
: undefined,
|
|
654
|
+
refType,
|
|
655
|
+
refId:
|
|
656
|
+
typeof candidate.refId === "string" && candidate.refId.trim()
|
|
657
|
+
? candidate.refId.trim()
|
|
658
|
+
: null,
|
|
659
|
+
refPath:
|
|
660
|
+
typeof candidate.refPath === "string" && candidate.refPath.trim()
|
|
661
|
+
? candidate.refPath.trim()
|
|
662
|
+
: null,
|
|
663
|
+
};
|
|
664
|
+
const slotKey =
|
|
665
|
+
typeof candidate.slotKey === "string" ? candidate.slotKey.trim() : "";
|
|
666
|
+
if (slotKey) normalized.slotKey = slotKey;
|
|
667
|
+
const slotLabel =
|
|
668
|
+
typeof candidate.slotLabel === "string" ? candidate.slotLabel.trim() : "";
|
|
669
|
+
if (slotLabel) normalized.slotLabel = slotLabel;
|
|
670
|
+
const metadata = normalizeMetadata(candidate.metadata);
|
|
671
|
+
if (metadata) normalized.metadata = metadata;
|
|
672
|
+
const clearsSlots = normalizeStringArray(candidate.clearsSlots);
|
|
673
|
+
if (clearsSlots) normalized.clearsSlots = clearsSlots;
|
|
674
|
+
if (depth < 3 && Array.isArray(candidate.relatedReferences)) {
|
|
675
|
+
const relatedReferences = candidate.relatedReferences
|
|
676
|
+
.map((item) => normalizeAgentComposerReferenceInternal(item, depth + 1))
|
|
677
|
+
.filter((item): item is AgentComposerReference => item !== null);
|
|
678
|
+
if (relatedReferences.length > 0) {
|
|
679
|
+
normalized.relatedReferences = relatedReferences;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return normalized;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
export function normalizeAgentComposerReference(
|
|
686
|
+
value: unknown,
|
|
687
|
+
): AgentComposerReference | null {
|
|
688
|
+
return normalizeAgentComposerReferenceInternal(value, 0);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function postAgentChatContextMessage(
|
|
692
|
+
type:
|
|
693
|
+
| typeof AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE
|
|
694
|
+
| typeof AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE
|
|
695
|
+
| typeof AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,
|
|
696
|
+
data: unknown,
|
|
697
|
+
options: { openSidebar: boolean },
|
|
698
|
+
): void {
|
|
699
|
+
if (typeof window === "undefined") return;
|
|
700
|
+
|
|
701
|
+
const shouldForwardOpenSidebar =
|
|
702
|
+
(type === AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&
|
|
703
|
+
options.openSidebar === false) ||
|
|
704
|
+
(type !== AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE &&
|
|
705
|
+
options.openSidebar === true);
|
|
706
|
+
const payloadData =
|
|
707
|
+
shouldForwardOpenSidebar && typeof data === "object" && data !== null
|
|
708
|
+
? {
|
|
709
|
+
...(data as Record<string, unknown>),
|
|
710
|
+
openSidebar: options.openSidebar,
|
|
711
|
+
}
|
|
712
|
+
: data;
|
|
713
|
+
const payload = { type, data: payloadData };
|
|
714
|
+
const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();
|
|
715
|
+
const target = targetSelf
|
|
716
|
+
? window
|
|
717
|
+
: window.parent !== window
|
|
718
|
+
? window.parent
|
|
719
|
+
: window;
|
|
720
|
+
const targetOrigin = targetSelf
|
|
721
|
+
? window.location.origin
|
|
722
|
+
: getFramePostMessageTargetOrigin() || window.location.origin;
|
|
723
|
+
|
|
724
|
+
if (options.openSidebar) {
|
|
725
|
+
window.dispatchEvent(
|
|
726
|
+
new CustomEvent("agent-panel:set-mode", {
|
|
727
|
+
detail: { mode: "chat" },
|
|
728
|
+
}),
|
|
729
|
+
);
|
|
730
|
+
window.dispatchEvent(new CustomEvent("agent-panel:open"));
|
|
731
|
+
} else {
|
|
732
|
+
window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const postToTarget = () => target.postMessage(payload, targetOrigin);
|
|
736
|
+
if (target === window) {
|
|
737
|
+
setTimeout(postToTarget, 0);
|
|
738
|
+
} else {
|
|
739
|
+
postToTarget();
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function postAgentChatReferenceMessage(
|
|
744
|
+
payload: AgentComposerReferenceInsertPayload,
|
|
745
|
+
options: { openSidebar: boolean },
|
|
746
|
+
): void {
|
|
747
|
+
if (typeof window === "undefined") return;
|
|
748
|
+
|
|
749
|
+
const message = {
|
|
750
|
+
type: AGENT_CHAT_INSERT_REFERENCE_MESSAGE_TYPE,
|
|
751
|
+
data: payload,
|
|
752
|
+
};
|
|
753
|
+
const targetSelf = isInBuilderFrame() || isDirectMcpAppEmbedSession();
|
|
754
|
+
const target = targetSelf
|
|
755
|
+
? window
|
|
756
|
+
: window.parent !== window
|
|
757
|
+
? window.parent
|
|
758
|
+
: window;
|
|
759
|
+
const targetOrigin = targetSelf
|
|
760
|
+
? window.location.origin
|
|
761
|
+
: getFramePostMessageTargetOrigin() || window.location.origin;
|
|
762
|
+
|
|
763
|
+
if (options.openSidebar) {
|
|
764
|
+
window.dispatchEvent(
|
|
765
|
+
new CustomEvent("agent-panel:set-mode", {
|
|
766
|
+
detail: { mode: "chat" },
|
|
767
|
+
}),
|
|
768
|
+
);
|
|
769
|
+
window.dispatchEvent(new CustomEvent("agent-panel:open"));
|
|
770
|
+
} else {
|
|
771
|
+
window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
window.dispatchEvent(
|
|
775
|
+
new CustomEvent(AGENT_CHAT_INSERT_REFERENCE_EVENT, {
|
|
776
|
+
detail: payload,
|
|
777
|
+
}),
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
const postToTarget = () => target.postMessage(message, targetOrigin);
|
|
781
|
+
if (target === window) {
|
|
782
|
+
setTimeout(postToTarget, 0);
|
|
783
|
+
} else {
|
|
784
|
+
postToTarget();
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function openAgentPanelForChat(): void {
|
|
789
|
+
if (typeof window === "undefined") return;
|
|
790
|
+
window.dispatchEvent(
|
|
791
|
+
new CustomEvent("agent-panel:set-mode", {
|
|
792
|
+
detail: { mode: "chat" },
|
|
793
|
+
}),
|
|
794
|
+
);
|
|
795
|
+
window.dispatchEvent(new CustomEvent("agent-panel:open"));
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function dispatchBufferedOpenRequest(entry: BufferedOpenRequest): void {
|
|
799
|
+
if (typeof window === "undefined") return;
|
|
800
|
+
const dispatch = () => {
|
|
801
|
+
window.dispatchEvent(
|
|
802
|
+
new CustomEvent(entry.eventType, { detail: entry.detail }),
|
|
803
|
+
);
|
|
804
|
+
};
|
|
805
|
+
setTimeout(dispatch, 0);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
export function requestAgentChatThreadOpen(
|
|
809
|
+
detail: AgentChatOpenThreadRequest,
|
|
810
|
+
): void {
|
|
811
|
+
if (typeof window === "undefined" || !detail.threadId.trim()) return;
|
|
812
|
+
openAgentPanelForChat();
|
|
813
|
+
dispatchBufferedOpenRequest(
|
|
814
|
+
bufferOpenRequest("agent-chat:open-thread", {
|
|
815
|
+
...detail,
|
|
816
|
+
threadId: detail.threadId.trim(),
|
|
817
|
+
}),
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export function requestAgentTaskOpen(detail: AgentChatOpenTaskRequest): void {
|
|
822
|
+
if (typeof window === "undefined" || !detail.threadId.trim()) return;
|
|
823
|
+
openAgentPanelForChat();
|
|
824
|
+
const parentThreadId = detail.parentThreadId?.trim();
|
|
825
|
+
dispatchBufferedOpenRequest(
|
|
826
|
+
bufferOpenRequest("agent-task-open", {
|
|
827
|
+
...detail,
|
|
828
|
+
threadId: detail.threadId.trim(),
|
|
829
|
+
...(parentThreadId ? { parentThreadId } : {}),
|
|
830
|
+
}),
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function isMcpAppChatBridgeEnabled(): boolean {
|
|
835
|
+
if (typeof window === "undefined" || window.parent === window) return false;
|
|
836
|
+
if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();
|
|
837
|
+
return isEmbedMcpChatBridgeActive() && isEmbedAuthActive();
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function isDirectMcpAppEmbedSession(): boolean {
|
|
841
|
+
if (typeof window === "undefined" || window.parent === window) return false;
|
|
842
|
+
if (readEmbedMcpChatBridgeFlagFromUrl()) markEmbedMcpChatBridgeActive();
|
|
843
|
+
return isEmbedAuthActive() && !isEmbedMcpChatBridgeActive();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function dispatchAgentChatRunning(isRunning: boolean): void {
|
|
847
|
+
if (typeof window === "undefined") return;
|
|
848
|
+
window.dispatchEvent(
|
|
849
|
+
new CustomEvent("agentNative.chatRunning", {
|
|
850
|
+
detail: { isRunning },
|
|
851
|
+
}),
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function normalizeAgentChatRequestMode(
|
|
856
|
+
value: unknown,
|
|
857
|
+
): AgentChatRequestMode | undefined {
|
|
858
|
+
return value === "act" || value === "plan" ? value : undefined;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** A normalized `agentNative.submitChat` payload — decode via {@link parseSubmitChatMessage}. */
|
|
862
|
+
export interface ParsedSubmitChat {
|
|
863
|
+
/** Visible prompt text (non-empty). */
|
|
864
|
+
message: string;
|
|
865
|
+
context?: string;
|
|
866
|
+
/** Submit (true) or prefill only (false); defaults to true. */
|
|
867
|
+
submit: boolean;
|
|
868
|
+
openSidebar?: boolean;
|
|
869
|
+
model?: string;
|
|
870
|
+
/** Raw effort hint; the receiver validates it against the model. */
|
|
871
|
+
effort?: unknown;
|
|
872
|
+
newTab?: boolean;
|
|
873
|
+
background?: boolean;
|
|
874
|
+
tabId?: string;
|
|
875
|
+
images?: string[];
|
|
876
|
+
/** Mode as sent; the receiver falls back to its exec mode when undefined. */
|
|
877
|
+
requestMode?: AgentChatRequestMode;
|
|
878
|
+
/** Id used to dedup the live post against a cold-start replay. */
|
|
879
|
+
submitMessageId?: string;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/** Decode a `message` event into a submit payload, or null if it isn't one / has no text. */
|
|
883
|
+
export function parseSubmitChatMessage(
|
|
884
|
+
event: MessageEvent,
|
|
885
|
+
): ParsedSubmitChat | null {
|
|
886
|
+
const envelope =
|
|
887
|
+
event.data && typeof event.data === "object"
|
|
888
|
+
? (event.data as { type?: unknown; data?: unknown })
|
|
889
|
+
: null;
|
|
890
|
+
if (!envelope || envelope.type !== AGENT_CHAT_MESSAGE_TYPE) return null;
|
|
891
|
+
const raw =
|
|
892
|
+
envelope.data && typeof envelope.data === "object"
|
|
893
|
+
? (envelope.data as Record<string, unknown>)
|
|
894
|
+
: null;
|
|
895
|
+
if (!raw) return null;
|
|
896
|
+
const message = typeof raw.message === "string" ? raw.message : "";
|
|
897
|
+
if (!message) return null;
|
|
898
|
+
const images = Array.isArray(raw.images)
|
|
899
|
+
? raw.images.filter(
|
|
900
|
+
(image): image is string =>
|
|
901
|
+
typeof image === "string" && image.length > 0,
|
|
902
|
+
)
|
|
903
|
+
: undefined;
|
|
904
|
+
return {
|
|
905
|
+
message,
|
|
906
|
+
context: typeof raw.context === "string" ? raw.context : undefined,
|
|
907
|
+
submit: raw.submit !== false,
|
|
908
|
+
openSidebar:
|
|
909
|
+
typeof raw.openSidebar === "boolean" ? raw.openSidebar : undefined,
|
|
910
|
+
model: typeof raw.model === "string" ? raw.model : undefined,
|
|
911
|
+
effort: raw.effort,
|
|
912
|
+
newTab: typeof raw.newTab === "boolean" ? raw.newTab : undefined,
|
|
913
|
+
background:
|
|
914
|
+
typeof raw.background === "boolean" ? raw.background : undefined,
|
|
915
|
+
tabId: typeof raw.tabId === "string" ? raw.tabId : undefined,
|
|
916
|
+
images,
|
|
917
|
+
requestMode: normalizeAgentChatRequestMode(raw.requestMode ?? raw.mode),
|
|
918
|
+
submitMessageId:
|
|
919
|
+
typeof raw.submitMessageId === "string" ? raw.submitMessageId : undefined,
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function normalizeStoredAgentChatExecMode(
|
|
924
|
+
value: string | null,
|
|
925
|
+
): AgentChatRequestMode | undefined {
|
|
926
|
+
if (value === "plan") return "plan";
|
|
927
|
+
if (value === "build" || value === "act") return "act";
|
|
928
|
+
return undefined;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function readStoredAgentChatRequestMode(): AgentChatRequestMode | undefined {
|
|
932
|
+
if (typeof window === "undefined") return undefined;
|
|
933
|
+
try {
|
|
934
|
+
const storage = window.localStorage;
|
|
935
|
+
const saved = normalizeStoredAgentChatExecMode(
|
|
936
|
+
storage.getItem(AGENT_CHAT_EXEC_MODE_KEY),
|
|
937
|
+
);
|
|
938
|
+
if (saved) return saved;
|
|
939
|
+
const scopedModes: AgentChatRequestMode[] = [];
|
|
940
|
+
for (let index = 0; index < storage.length; index += 1) {
|
|
941
|
+
const key = storage.key(index);
|
|
942
|
+
if (!key?.startsWith(`${AGENT_CHAT_EXEC_MODE_KEY}:`)) continue;
|
|
943
|
+
const scopedSaved = normalizeStoredAgentChatExecMode(
|
|
944
|
+
storage.getItem(key),
|
|
945
|
+
);
|
|
946
|
+
if (scopedSaved) scopedModes.push(scopedSaved);
|
|
947
|
+
}
|
|
948
|
+
if (scopedModes.length === 1) return scopedModes[0];
|
|
949
|
+
} catch {}
|
|
950
|
+
return undefined;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Send a message to the agent chat via postMessage.
|
|
955
|
+
* Returns the stable tabId for tracking this chat run.
|
|
956
|
+
*/
|
|
957
|
+
export function sendToAgentChat(opts: AgentChatMessage): string {
|
|
958
|
+
const tabId = opts.tabId ?? generateTabId();
|
|
959
|
+
const isCodeRequest = opts.type === "code" || opts.requiresCode === true;
|
|
960
|
+
const localChatTarget = opts.chatTarget === "local";
|
|
961
|
+
const requestMode =
|
|
962
|
+
normalizeAgentChatRequestMode(opts.requestMode ?? opts.mode) ??
|
|
963
|
+
readStoredAgentChatRequestMode();
|
|
964
|
+
if (isCodeRequest && isInBuilderFrame()) {
|
|
965
|
+
sendToBuilderChat({
|
|
966
|
+
message: opts.message,
|
|
967
|
+
context: opts.context,
|
|
968
|
+
submit: opts.submit,
|
|
969
|
+
...(requestMode ? { mode: requestMode, requestMode } : {}),
|
|
970
|
+
});
|
|
971
|
+
return tabId;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const submitMessageId = opts.submitMessageId ?? generateSubmitMessageId();
|
|
975
|
+
const payload = {
|
|
976
|
+
type: AGENT_CHAT_MESSAGE_TYPE,
|
|
977
|
+
data: {
|
|
978
|
+
...opts,
|
|
979
|
+
tabId,
|
|
980
|
+
submitMessageId,
|
|
981
|
+
...(requestMode ? { mode: requestMode, requestMode } : {}),
|
|
982
|
+
},
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
if (
|
|
986
|
+
opts.submit !== false &&
|
|
987
|
+
!localChatTarget &&
|
|
988
|
+
isMcpAppChatBridgeEnabled()
|
|
989
|
+
) {
|
|
990
|
+
const directHostMessage = sendMcpAppHostMessage({
|
|
991
|
+
message: opts.message,
|
|
992
|
+
context: opts.context,
|
|
993
|
+
...(requestMode ? { mode: requestMode, requestMode } : {}),
|
|
994
|
+
});
|
|
995
|
+
if (directHostMessage) {
|
|
996
|
+
void Promise.resolve(directHostMessage)
|
|
997
|
+
.then((ok) => {
|
|
998
|
+
if (!ok) {
|
|
999
|
+
window.parent.postMessage(
|
|
1000
|
+
payload,
|
|
1001
|
+
getFramePostMessageTargetOrigin() || "*",
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
})
|
|
1005
|
+
.finally(() => {
|
|
1006
|
+
dispatchAgentChatRunning(false);
|
|
1007
|
+
});
|
|
1008
|
+
return tabId;
|
|
1009
|
+
}
|
|
1010
|
+
window.parent.postMessage(
|
|
1011
|
+
payload,
|
|
1012
|
+
getFramePostMessageTargetOrigin() || "*",
|
|
1013
|
+
);
|
|
1014
|
+
return tabId;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
const shouldOpenSidebar = opts.openSidebar !== false && !opts.background;
|
|
1018
|
+
|
|
1019
|
+
const targetSelf =
|
|
1020
|
+
!isCodeRequest &&
|
|
1021
|
+
(localChatTarget || isInBuilderFrame() || isDirectMcpAppEmbedSession());
|
|
1022
|
+
const target = targetSelf
|
|
1023
|
+
? window
|
|
1024
|
+
: window.parent !== window
|
|
1025
|
+
? window.parent
|
|
1026
|
+
: window;
|
|
1027
|
+
const targetOrigin = targetSelf
|
|
1028
|
+
? window.location.origin
|
|
1029
|
+
: getFramePostMessageTargetOrigin() || window.location.origin;
|
|
1030
|
+
if (shouldOpenSidebar) {
|
|
1031
|
+
window.dispatchEvent(
|
|
1032
|
+
new CustomEvent("agent-panel:set-mode", {
|
|
1033
|
+
detail: { mode: "chat" },
|
|
1034
|
+
}),
|
|
1035
|
+
);
|
|
1036
|
+
window.dispatchEvent(new CustomEvent("agent-panel:open"));
|
|
1037
|
+
} else if (!isCodeRequest) {
|
|
1038
|
+
window.dispatchEvent(new CustomEvent(AGENT_PANEL_PREPARE_EVENT));
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
const postToTarget = () => target.postMessage(payload, targetOrigin);
|
|
1042
|
+
|
|
1043
|
+
// Same-window: defer one tick so a sidebar mounting now can attach its
|
|
1044
|
+
// listener, and buffer the submit so the lazy panel can replay it if it
|
|
1045
|
+
// mounts later. The live post and the replay dedup by submitMessageId.
|
|
1046
|
+
if (!isCodeRequest && target === window) {
|
|
1047
|
+
bufferSelfSubmit(payload.data);
|
|
1048
|
+
setTimeout(postToTarget, 0);
|
|
1049
|
+
} else {
|
|
1050
|
+
postToTarget();
|
|
1051
|
+
}
|
|
1052
|
+
return tabId;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Must exceed SELF_SUBMIT_BUFFER_TTL_MS. Otherwise confirmation can time out
|
|
1056
|
+
// while its replay is still eligible to mount and deliver later.
|
|
1057
|
+
const DEFAULT_SUBMIT_CONFIRM_TIMEOUT_MS = SELF_SUBMIT_BUFFER_TTL_MS + 2000;
|
|
1058
|
+
|
|
1059
|
+
export interface SendToAgentChatAndConfirmResult {
|
|
1060
|
+
tabId: string;
|
|
1061
|
+
/** True once the message actually became a visible turn in the chat. */
|
|
1062
|
+
delivered: boolean;
|
|
1063
|
+
/** Set when `delivered` is false: "missing-engine", "timeout", etc. */
|
|
1064
|
+
reason?: string;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Like {@link sendToAgentChat}, but resolves once the submit's fate is known
|
|
1069
|
+
* instead of firing and forgetting. Use this whenever the caller must decide
|
|
1070
|
+
* whether to keep/restore its own state on failure (e.g. a draw/annotate
|
|
1071
|
+
* overlay that should not discard the user's work unless the message actually
|
|
1072
|
+
* reached the chat) — see the `AGENT_CHAT_SUBMIT_RESULT_EVENT` contract.
|
|
1073
|
+
* This acknowledgement is intentionally limited to submitted, non-code
|
|
1074
|
+
* messages with `chatTarget: "local"`; parent-frame and MCP host chats use
|
|
1075
|
+
* different delivery protocols and return `unsupported-target` here.
|
|
1076
|
+
*
|
|
1077
|
+
* Resolves `delivered: false` if the receiving chat explicitly rejects the
|
|
1078
|
+
* submit (e.g. no LLM/agent engine configured) OR if no result arrives within
|
|
1079
|
+
* `timeoutMs` — a silently-stuck submit (panel never mounts, thread never
|
|
1080
|
+
* gets a ref, message type not handled by this build) must fail the same way
|
|
1081
|
+
* an explicit rejection does, since the caller cannot otherwise tell the
|
|
1082
|
+
* difference between "still in flight" and "dropped."
|
|
1083
|
+
*/
|
|
1084
|
+
export function sendToAgentChatAndConfirm(
|
|
1085
|
+
opts: Omit<AgentChatMessage, "submitMessageId">,
|
|
1086
|
+
options?: { timeoutMs?: number },
|
|
1087
|
+
): Promise<SendToAgentChatAndConfirmResult> {
|
|
1088
|
+
const tabId = opts.tabId ?? generateTabId();
|
|
1089
|
+
if (typeof window === "undefined") {
|
|
1090
|
+
return Promise.resolve({ tabId, delivered: false, reason: "no-window" });
|
|
1091
|
+
}
|
|
1092
|
+
// Confirmation is deliberately a same-window/local-chat contract. Parent
|
|
1093
|
+
// frames, Builder code chat, and MCP host relays have independent protocols
|
|
1094
|
+
// and cannot answer this window-local CustomEvent acknowledgement.
|
|
1095
|
+
if (
|
|
1096
|
+
opts.chatTarget !== "local" ||
|
|
1097
|
+
opts.type === "code" ||
|
|
1098
|
+
opts.requiresCode === true ||
|
|
1099
|
+
opts.submit === false
|
|
1100
|
+
) {
|
|
1101
|
+
return Promise.resolve({
|
|
1102
|
+
tabId,
|
|
1103
|
+
delivered: false,
|
|
1104
|
+
reason: "unsupported-target",
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
const submitMessageId = generateSubmitMessageId();
|
|
1109
|
+
const timeoutMs = Math.max(
|
|
1110
|
+
0,
|
|
1111
|
+
options?.timeoutMs ?? DEFAULT_SUBMIT_CONFIRM_TIMEOUT_MS,
|
|
1112
|
+
);
|
|
1113
|
+
|
|
1114
|
+
return new Promise<SendToAgentChatAndConfirmResult>((resolve) => {
|
|
1115
|
+
let settled = false;
|
|
1116
|
+
let timer: number | undefined;
|
|
1117
|
+
const cleanup = () => {
|
|
1118
|
+
window.removeEventListener(
|
|
1119
|
+
AGENT_CHAT_SUBMIT_RESULT_EVENT,
|
|
1120
|
+
onResult as EventListener,
|
|
1121
|
+
);
|
|
1122
|
+
if (timer !== undefined) window.clearTimeout(timer);
|
|
1123
|
+
};
|
|
1124
|
+
const finish = (delivered: boolean, reason?: string, cancel = false) => {
|
|
1125
|
+
if (settled) return;
|
|
1126
|
+
settled = true;
|
|
1127
|
+
if (cancel) cancelAgentChatSubmit(submitMessageId);
|
|
1128
|
+
cleanup();
|
|
1129
|
+
resolve({ tabId, delivered, reason });
|
|
1130
|
+
};
|
|
1131
|
+
const onResult = (event: Event) => {
|
|
1132
|
+
const detail = (event as CustomEvent<AgentChatSubmitResult>).detail;
|
|
1133
|
+
if (!detail || detail.submitMessageId !== submitMessageId) return;
|
|
1134
|
+
finish(detail.delivered, detail.reason);
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
window.addEventListener(
|
|
1138
|
+
AGENT_CHAT_SUBMIT_RESULT_EVENT,
|
|
1139
|
+
onResult as EventListener,
|
|
1140
|
+
);
|
|
1141
|
+
timer = window.setTimeout(() => finish(false, "timeout", true), timeoutMs);
|
|
1142
|
+
try {
|
|
1143
|
+
sendToAgentChat({ ...opts, tabId, submitMessageId });
|
|
1144
|
+
} catch {
|
|
1145
|
+
finish(false, "send-failed", true);
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Add or replace a keyed context nugget in the active agent chat composer.
|
|
1152
|
+
* The context is not submitted until the user sends the prompt.
|
|
1153
|
+
*/
|
|
1154
|
+
export function setAgentChatContextItem(
|
|
1155
|
+
opts: AgentChatContextSetOptions,
|
|
1156
|
+
): void {
|
|
1157
|
+
const item = normalizeAgentChatContextItem(opts);
|
|
1158
|
+
if (!item || typeof window === "undefined") return;
|
|
1159
|
+
|
|
1160
|
+
publishAgentChatContextItems(
|
|
1161
|
+
withReplacedAgentChatContextItem(agentChatContextState.items, item),
|
|
1162
|
+
);
|
|
1163
|
+
// Forward an explicit `focus: false` so the receiving composer can stage the
|
|
1164
|
+
// chip without stealing focus. Focus stays enabled by default (field omitted)
|
|
1165
|
+
// for every existing caller.
|
|
1166
|
+
const messageData = opts.focus === false ? { ...item, focus: false } : item;
|
|
1167
|
+
postAgentChatContextMessage(
|
|
1168
|
+
AGENT_CHAT_SET_CONTEXT_MESSAGE_TYPE,
|
|
1169
|
+
messageData,
|
|
1170
|
+
{
|
|
1171
|
+
openSidebar: opts.openSidebar !== false,
|
|
1172
|
+
},
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/** @deprecated Use `setAgentChatContextItem` instead. */
|
|
1177
|
+
export const setContextToAgentChat = setAgentChatContextItem;
|
|
1178
|
+
|
|
1179
|
+
/** @deprecated Use `setAgentChatContextItem` instead. */
|
|
1180
|
+
export const addContextToAgentChat = setAgentChatContextItem;
|
|
1181
|
+
|
|
1182
|
+
export function insertAgentComposerReference(
|
|
1183
|
+
ref: AgentComposerReference,
|
|
1184
|
+
options: AgentComposerReferenceInsertOptions = {},
|
|
1185
|
+
): void {
|
|
1186
|
+
const normalized = normalizeAgentComposerReference(ref);
|
|
1187
|
+
if (!normalized || typeof window === "undefined") return;
|
|
1188
|
+
postAgentChatReferenceMessage(
|
|
1189
|
+
{
|
|
1190
|
+
...normalized,
|
|
1191
|
+
insertMessageId: `reference-${Date.now()}-${Math.random()
|
|
1192
|
+
.toString(36)
|
|
1193
|
+
.slice(2, 8)}`,
|
|
1194
|
+
},
|
|
1195
|
+
{ openSidebar: options.openSidebar === true },
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
export function removeAgentChatContextItem(
|
|
1200
|
+
keyOrOpts: string | AgentChatContextRemoveOptions,
|
|
1201
|
+
): void {
|
|
1202
|
+
const key =
|
|
1203
|
+
typeof keyOrOpts === "string" ? keyOrOpts.trim() : keyOrOpts.key.trim();
|
|
1204
|
+
if (!key || typeof window === "undefined") return;
|
|
1205
|
+
const openSidebar =
|
|
1206
|
+
typeof keyOrOpts === "string" ? false : keyOrOpts.openSidebar === true;
|
|
1207
|
+
|
|
1208
|
+
publishAgentChatContextItems(
|
|
1209
|
+
agentChatContextState.items.filter((item) => item.key !== key),
|
|
1210
|
+
);
|
|
1211
|
+
postAgentChatContextMessage(
|
|
1212
|
+
AGENT_CHAT_REMOVE_CONTEXT_MESSAGE_TYPE,
|
|
1213
|
+
{ key },
|
|
1214
|
+
{ openSidebar },
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
export function clearAgentChatContext(
|
|
1219
|
+
opts: AgentChatContextMutationOptions = {},
|
|
1220
|
+
): void {
|
|
1221
|
+
if (typeof window === "undefined") return;
|
|
1222
|
+
publishAgentChatContextItems([]);
|
|
1223
|
+
postAgentChatContextMessage(
|
|
1224
|
+
AGENT_CHAT_CLEAR_CONTEXT_MESSAGE_TYPE,
|
|
1225
|
+
{},
|
|
1226
|
+
{ openSidebar: opts.openSidebar === true },
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
export function _resetAgentChatContextForTests(): void {
|
|
1231
|
+
agentChatContextState = { items: [], updatedAt: 0 };
|
|
1232
|
+
notifyAgentChatContextListeners();
|
|
1233
|
+
}
|