diff --git a/.env.example b/.env.example index ed587847d..dd69756b2 100644 --- a/.env.example +++ b/.env.example @@ -4,13 +4,21 @@ # Values below are PUBLIC (they're shipped to the browser by Astro's # `envField`, and live behind rate limiting / allow-lists on the vendor side). -# Kapa Website Widget integration ID for the "Ask AI" button in the sidebar. -# If unset, docs falls back to the shared widget integration ID used in preview/prod. -# Get yours at: https://app.kapa.ai/admin (Integrations → Widget → Copy integration ID). -# The same value is passed to the widget as `data-website-id`. -# PUBLIC_KAPA_INTEGRATION_ID=f31c5644-dd65-4f49-9762-bf580062afa8 +# Kapa CUSTOM_FRONTEND integration ID for the custom "Ask AI" React chat +# (KapaChatLauncher / @kapaai/react-sdk). If unset, the custom chat launcher +# is omitted. Get yours at: https://app.kapa.ai (Integrations → custom frontend). +# Do not reuse this value for WebMCP — that needs a Website Widget integration. PUBLIC_KAPA_INTEGRATION_ID= +# Kapa Website Widget integration ID for WebMCP only. Emitted as +# data-website-id on the official widget script with data-webmcp-enabled=true +# so in-browser agents can call search_warp_knowledge_sources. If unset, the +# WebMCP script is omitted. The default floating Ask button stays hidden +# (data-button-hide); the custom sidebar Ask control remains the human entry +# point. Get yours at: https://app.kapa.ai (Integrations → Website Widget). +# Live Docs Bot example: "Docs Widget" (type WIDGET). +PUBLIC_KAPA_WEBSITE_WIDGET_INTEGRATION_ID= + # Optional Kapa project ID used to build internal conversation links in # "Create ticket" email drafts: # https://app.kapa.ai//conversations/ diff --git a/astro.config.mjs b/astro.config.mjs index a272cbf62..c85dc0854 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -37,6 +37,13 @@ export default defineConfig({ access: 'public', optional: true, }), + // Website Widget integration ID for WebMCP only (not the custom + // React chat frontend). Required by Kapa for data-webmcp-enabled. + PUBLIC_KAPA_WEBSITE_WIDGET_INTEGRATION_ID: envField.string({ + context: 'client', + access: 'public', + optional: true, + }), PUBLIC_KAPA_PROJECT_ID: envField.string({ context: 'client', access: 'public', diff --git a/package.json b/package.json index f664e07e5..d56eb55f6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "seo:audit": "node scripts/seo-audit.mjs", "test:heading-tocs": "node scripts/validate-heading-tocs.mjs", "test:heading-vars": "node --test src/plugins/heading-vars-core.test.mjs", + "test:kapa-webmcp": "node --test src/lib/kapa-webmcp.test.mjs", "test:homepage-json-ld": "node scripts/validate-homepage-json-ld.mjs", "postinstall": "patch-package" }, diff --git a/src/components/CustomHead.astro b/src/components/CustomHead.astro index fdee99342..59e284070 100644 --- a/src/components/CustomHead.astro +++ b/src/components/CustomHead.astro @@ -4,6 +4,7 @@ import Analytics from '@vercel/analytics/astro'; import SpeedInsights from '@vercel/speed-insights/astro'; import RudderStackAnalytics from './RudderStackAnalytics.astro'; import ArticleImageLightbox from './ArticleImageLightbox.astro'; +import KapaWebMcp from './KapaWebMcp.astro'; import { DOCS_ORIGIN } from '../lib/site.js'; // Note: `` (Astro View Transitions) is intentionally NOT @@ -189,6 +190,8 @@ const websiteJsonLd = JSON.stringify({ /> +{/* WebMCP page tool for in-browser agents; custom Ask chat stays separate. */} + diff --git a/src/components/KapaWebMcp.astro b/src/components/KapaWebMcp.astro new file mode 100644 index 000000000..e1c217b14 --- /dev/null +++ b/src/components/KapaWebMcp.astro @@ -0,0 +1,35 @@ +--- +/** + * Loads the Kapa Website Widget script solely so WebMCP can register the + * read-only `search_warp_knowledge_sources` page tool for in-browser agents. + * + * Uses the Website Widget integration (`PUBLIC_KAPA_WEBSITE_WIDGET_INTEGRATION_ID`), + * not the custom React frontend ID (`PUBLIC_KAPA_INTEGRATION_ID`). WebMCP only + * works with Website Widget integrations. + * + * Human chat stays on the custom React SDK surface (`KapaChatLauncher`). + * This script hides Kapa's default floating button and does not replace or + * duplicate the custom Ask launcher. + * + * @see https://docs.kapa.ai/integrations/website-widget/features/webmcp + * @see https://www.kapa.ai/blog/kapa-webmcp + */ +import { PUBLIC_KAPA_WEBSITE_WIDGET_INTEGRATION_ID } from 'astro:env/client'; +import { getKapaWebMcpScriptAttributes } from '../lib/kapa-webmcp.js'; + +const attrs = getKapaWebMcpScriptAttributes(PUBLIC_KAPA_WEBSITE_WIDGET_INTEGRATION_ID); +--- + +{ + attrs ? ( +