@vercel/geistdocs 2.5.0 → 2.6.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/dist/cli/index.js +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +13 -0
- package/dist/internal/provider-client.js +1 -1
- package/dist/internal/webmcp-client.d.ts +3 -4
- package/dist/internal/webmcp-client.d.ts.map +1 -1
- package/dist/internal/webmcp-client.js +9 -12
- package/dist/internal/webmcp.d.ts +2 -6
- package/dist/internal/webmcp.d.ts.map +1 -1
- package/dist/internal/webmcp.js +28 -79
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +10 -2
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/agents.js +2 -0
- package/dist/routes/discovery.d.ts +3 -2
- package/dist/routes/discovery.d.ts.map +1 -1
- package/dist/routes/discovery.js +49 -1
- package/dist/routes/mcp.d.ts +7 -2
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +101 -1
- package/dist/routes/openapi.d.ts +64 -0
- package/dist/routes/openapi.d.ts.map +1 -0
- package/dist/routes/openapi.js +481 -0
- package/docs/agents.md +1 -1
- package/docs/llms.txt +60 -27
- package/docs/manifest.json +1 -1
- package/docs/pages/agent-readiness.md +30 -0
- package/docs/pages/configuration.md +1 -0
- package/docs/pages/migration.md +1 -0
- package/docs/pages/webmcp.md +27 -26
- package/package.json +9 -3
- package/template/AGENTS.md +1 -1
- package/template/app/[lang]/openapi.json/route.ts +6 -0
- package/template/app/api/mcp/route.ts +7 -0
- package/template/content/docs/agent-readiness.mdx +30 -0
- package/template/content/docs/configuration.mdx +1 -0
- package/template/content/docs/migration.mdx +1 -0
- package/template/content/docs/webmcp.mdx +27 -26
- package/template/geistdocs.tsx +3 -0
- package/template/lib/geistdocs/config.tsx +1 -0
- package/template/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -4,4 +4,4 @@ import{Option as Rn,program as A}from"commander";import{access as Ke,copyFile as
|
|
|
4
4
|
`);throw new AggregateError(i,`Mixedbread search sync did not complete:
|
|
5
5
|
${a}`)}return r},Ft=async({client:e,file:t,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})=>{let s=t,o=Date.now()+r;for(;s.status==="pending"||s.status==="in_progress";){if(Date.now()>=o)throw new Error(`Mixedbread timed out while indexing file ${t.id}.`);await i(n),s=await e.retrieveStoreFile(t.id)}if(s.status!=="completed")throw new Error(`Mixedbread failed to index file ${t.id} (${s.status}).`);return s},Dt=async({client:e,desired:t,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})=>{let s=await e.uploadFile({content:t.document.content,filename:`${U(t.document.id).slice(0,32)}.md`}),o;try{o=await e.createStoreFile({externalId:t.externalId,fileId:s,metadata:{...t.metadata,[g.rawFileId]:s}})}catch(a){try{await e.deleteFile(s)}catch(d){throw new AggregateError([a,d],`Mixedbread failed to attach and clean up raw file ${s}.`)}throw a}return Ft({client:e,file:o,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})},Ie=async({client:e,concurrency:t=St,manifest:n,pollIntervalMs:r=_t,pollTimeoutMs:i=Tt,revision:s,revisionAncestors:o=[],revisionTimestamp:a,sleep:d=Rt})=>{let c=_e(n);if(c.provider!=="mixedbread")return{deleted:0,skipped:c.documents.length,uploaded:0};let u=c.siteId?.trim();if(!u)throw new Error("Mixedbread retrieval requires a non-empty siteId in geistdocs.tsx.");if(c.documents.length===0)throw new Error("The Geistdocs search export is empty. Refusing to remove indexed documents.");let l=c.documents.map(p=>At(p,u,s,o,a)),m=new Map(l.map(p=>[p.document.id,p])),h=(await be(e)).flatMap(p=>{let y=q(p.metadata);return y?.siteId===u?[{file:p,metadata:y}]:[]}),x=new Map,P=new Set;for(let p of h){W(p.metadata,s,a)&&P.add(p.metadata.documentId);let y=m.get(p.metadata.documentId);y&&p.metadata.contentHash===y.hash&&p.file.status==="completed"&&!x.has(p.metadata.documentId)&&x.set(p.metadata.documentId,p)}let _=l.filter(p=>!(x.has(p.document.id)||P.has(p.document.id)));await Ee(_,t,p=>Dt({client:e,desired:p,pollIntervalMs:r,pollTimeoutMs:i,sleep:d}));let b=(await be(e)).flatMap(p=>{let y=q(p.metadata);return y?.siteId===u?[{file:p,metadata:y}]:[]}),D=new Set(b.filter(({metadata:p})=>W(p,s,a)).map(({metadata:p})=>p.documentId)),ie=new Set;for(let p of l){if(D.has(p.document.id))continue;let ae=b.filter(({file:V,metadata:k})=>V.status==="completed"&&k.documentId===p.document.id&&k.contentHash===p.hash).sort((V,k)=>V.file.id.localeCompare(k.file.id))[0];ae&&ie.add(ae.file.id)}let oe=b.filter(({file:p,metadata:y})=>p.status!=="pending"&&p.status!=="in_progress"&&!W(y,s,a)&&Mt({currentRevision:s,currentRevisionAncestors:o,currentRevisionTimestamp:a,desired:m.get(y.documentId),metadata:y})&&!ie.has(p.id));return await Ee(oe,t,async({file:p,metadata:y})=>{await e.deleteFile(y.rawFileId??p.id),await e.deleteStoreFile(p.id)}),{deleted:oe.length,skipped:l.length-_.length,uploaded:_.length}};var Ot=50,$t=e=>`vercel integration add mixedbread --name docs-${e||"your-site-id"} --environment production`,ve=(e,t)=>kt("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim(),Nt=e=>{let t=process.env.VERCEL_GIT_COMMIT_SHA?.trim(),n=[];try{n=ve(e,["rev-list",`--max-count=${Ot+1}`,t||"HEAD"]).split(`
|
|
6
6
|
`).filter(Boolean)}catch{n=[]}let r=t||n[0],i;for(let s of Array.from(new Set([r,"HEAD"].filter(Boolean))))try{let o=Number(ve(e,["show","-s","--format=%ct",s]));if(Number.isFinite(o)){i=o;break}}catch{}return{revision:r,revisionAncestors:n.filter(s=>s!==r),revisionTimestamp:i}},Pe=async({allowNonProduction:e=!1,dir:t=".next"}={})=>{let n=process.cwd();Ct.loadEnvConfig(n,!1);let r=process.env.MXBAI_API_KEY?.trim(),i=process.env.MXBAI_STORE_ID?.trim();if(process.env.VERCEL_ENV!=="production"&&!e){console.log("Geistdocs search sync skipped: this is not a production Vercel build.");return}if(!!r!=!!i)throw new Error("Mixedbread is partially configured. Set both MXBAI_API_KEY and MXBAI_STORE_ID.");let s;try{s=await Te({cwd:n,outputDirectory:t})}catch(a){if(!(r||i)){console.log("Geistdocs search sync skipped: no Mixedbread credentials or static search export were found.");return}throw a}if(s.provider!=="mixedbread"){console.log("Geistdocs search sync skipped: Ask AI uses local retrieval.");return}if(!(r&&i))throw new Error(["Mixedbread retrieval is enabled, but MXBAI_API_KEY or MXBAI_STORE_ID is missing.","From the root of this site's repository, linked to the correct Vercel project, run:",$t(s.siteId)].join(`
|
|
7
|
-
`));let o=await Ie({client:we({apiBaseUrl:process.env.MXBAI_BASE_URL,apiKey:r,storeId:i}),manifest:s,...Nt(n)});console.log(`Geistdocs search sync complete: ${o.uploaded} uploaded, ${o.deleted} deleted, ${o.skipped} unchanged.`)};import{readFileSync as Gt,writeFileSync as Ut}from"fs";import{mkdir as Lt,readFile as Z,writeFile as jt}from"fs/promises";import{dirname as Bt,extname as Vt,relative as Fe,resolve as j}from"path";import{intro as Jt,isCancel as Ht,log as I,multiselect as Xt,outro as L,spinner as Kt}from"@clack/prompts";import{glob as Yt}from"glob";import{Node as F,Project as qt,SyntaxKind as zt}from"ts-morph";var Wt="geistdocs.tsx",Qt="content/docs/**/*.mdx",ee=".translation-cache.json",Q=8,Ae=()=>({version:1,entries:{}}),Zt=async e=>{let t=await Z(e),{createHash:n}=await import("crypto");return n("sha256").update(t).digest("hex")},en=e=>{let t=j(process.cwd(),e);return Gt(t,"utf8")},Me=e=>F.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(F.isPropertyAssignment(t)){let n=t.getNameNode();if(F.isIdentifier(n)||F.isStringLiteral(n))return[n.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],tn=e=>{try{let t=new qt({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),n=en(e),s=t.createSourceFile(e,n,{overwrite:!0}).getVariableDeclarations().find(a=>a.getName()==="translations")?.getInitializer();if(!s)return[];if(F.isObjectLiteralExpression(s))return Me(s);let o=s.getFirstDescendantByKind(zt.ObjectLiteralExpression);return o?Me(o):[]}catch(t){let n=t instanceof Error?t.message:`${t}`;return I.warn(`Failed to read locales from ${e}: ${n}`),[]}},nn=async()=>{let e=await Xt({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ht(e)&&(L("Translation cancelled"),process.exit(0)),e},rn=async e=>(await Yt(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),sn=async()=>{let e=j(process.cwd(),ee);try{let t=await Z(e,"utf8"),n=JSON.parse(t);return n.version!==1||!n.entries?Ae():{version:1,entries:n.entries}}catch{return Ae()}},Re=e=>{let t=j(process.cwd(),ee),n=JSON.stringify(e,null,2);Ut(t,n,"utf8")},on=async e=>{let t=await Promise.all(e.map(async n=>[n,await Zt(n)]));return Object.fromEntries(t)},an=(e,t)=>{let n=Vt(e);return`${e.slice(0,-n.length)}.${t}${n}`},De=(e,t)=>`${Fe(process.cwd(),e)}::${t}`,cn=(e,t,n,r,i=!1)=>{let s=[],o=0;for(let a of t){let d=n[a];for(let c of e){let u=an(a,c),l=De(a,c),m=r.entries[l];if(!i&&m?.hash===d){o+=1;continue}s.push({locale:c,sourceFile:a,sourceHash:d,targetFile:u})}}return{tasks:s,skippedCount:o}},dn=async e=>{await Lt(Bt(e),{recursive:!0})},ln=async(e,t,n)=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:n})});if(!r.ok){let s=await r.text();throw new Error(`API request failed (${r.status}): ${s}`)}let i=await r.json();if(!i.translation)throw new Error("API response did not include a translation");return i.translation},pn=async(e,t,n)=>{let r=await Z(e.sourceFile,"utf8"),i=await ln(t,r,e.locale);await dn(e.targetFile),await jt(e.targetFile,i,"utf8"),n.entries[De(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},ke=async(e,t)=>{Jt("Translate MDX content");let n=e??Qt,r=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",i=tn(t.config??Wt),s=await rn(n);s.length===0&&(I.error(`No MDX files found matching pattern: ${n}`),L("Translation cancelled"),process.exit(1)),I.info(`Found ${s.length} MDX file(s) matching pattern`),i.length===0&&(i=await nn());let o=j(process.cwd(),ee),a=await sn();await Re(a),I.info(`Using cache: ${o}`);let d=await on(s),{tasks:c,skippedCount:u}=cn(i,s,d,a,t.force);if(c.length===0){I.success("All translations are up to date!"),L(`Skipped ${u} file(s) (unchanged)`);return}let l=[];for(let h=0;h<c.length;h+=Q)l.push(c.slice(h,h+Q));I.info(`Processing ${c.length} translation(s) in ${l.length} batch(es) of up to ${Q}`),u>0&&I.info(`Skipped ${u} translation(s) (unchanged)`);let m=Kt();m.start("Translating content...");let f=0;for(let h of l)await Promise.all(h.map(async x=>{await pn(x,r,a),f+=1,m.message(`Translated ${f}/${c.length}: ${Fe(process.cwd(),x.targetFile)}`)})),await Re(a);m.stop("Translation complete!"),L(`Created/updated ${c.length} file(s)`)};import{access as un,copyFile as gn,mkdir as Ne,rm as re}from"fs/promises";import{dirname as mn,join as v}from"path";import{intro as fn,log as w,outro as B,spinner as Ge}from"@clack/prompts";import{glob as hn}from"glob";var wn=["**/*"],yn=["content/docs/**"],te=".geistdocs-tmp",xn=async(e,t)=>{let n=v(e,t);await re(n,{recursive:!0,force:!0}),await Ne(n,{recursive:!0})},ne=async e=>await re(e,{recursive:!0,force:!0}),Ce=async(e,t,n)=>(await hn(e,{cwd:n,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),bn=async e=>{try{return await un(e),!0}catch{return!1}},En=async(e,t,n)=>{let r=v(t,e),i=v(n,e);return await bn(r)?(await gn(r,i),{success:!0}):{success:!1,error:`Source file not found: ${r}`}},Sn=async(e,t)=>{let n=v(t,e);return await re(n,{force:!0}),{success:!0}},Oe=20,$e=async(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=n){let s=e.slice(i,i+n),o=await Promise.all(s.map(t));r.push(...o)}return r},_n=async(e,t,n,r,i)=>{let s={success:[],deleted:[],failed:[]},o=[...new Set(e.map(d=>mn(v(r,d))))];i.message(`Creating ${o.length} directories...`),await Promise.all(o.map(d=>Ne(d,{recursive:!0}))),i.message(`Updating ${e.length} files...`);let a=await $e(e,async d=>{let c=await En(d,n,r);return{file:d,...c}},Oe);for(let{file:d,success:c,error:u}of a)c?s.success.push(d):s.failed.push({file:d,error:u??"Unknown error"});if(t.length>0){i.message(`Deleting ${t.length} files...`);let d=await $e(t,async c=>{try{return await Sn(c,r),{file:c,success:!0}}catch(u){let l=u instanceof Error?u.message:`${u}`;return{file:c,success:!1,error:l}}},Oe);for(let c of d)c.success?s.deleted.push(c.file):s.failed.push({file:c.file,error:c.error})}return s},Tn=e=>{if(e.success.length>0){w.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)w.info(` \u2713 ${t}`)}if(e.deleted.length>0){w.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)w.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){w.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:n}of e.failed)w.error(` \u2717 ${t}: ${n}`)}},In=e=>e.includes("canary")?"canary":"latest",vn=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(S)}`);if(!t.ok)throw new Error(`Failed to resolve ${S}@${e}`);let r=(await t.json())["dist-tags"]?.[e];if(!r)throw new Error(`Could not find dist-tag ${e} for ${S}`);return r},Pn=async e=>{let t=await M(e),n=J(t,S);if(!n)return{currentVersion:n,nextVersion:void 0,updated:!1};let r=In(n),i=await vn(r);return n===i?{currentVersion:n,nextVersion:i,updateTag:r,updated:!1}:($(t,S,i),await O(e,t),{currentVersion:n,nextVersion:i,updateTag:r,updated:!0})},An=async(e,t,n)=>{let r=await M(e);if(!le(r,S))return!1;t&&t.length>0&&w.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),n?.sync&&w.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:i,nextVersion:s,updateTag:o,updated:a}=await Pn(e);if(!a)return w.success(i?`@vercel/geistdocs is already at ${s} (${o}).`:"No package version update was needed."),B("Package-based site is already up to date."),!0;w.info(`Bumping ${S} from ${i} to ${s} (${o})`);let d=Ge();return d.start("Installing updated package version..."),await T("pnpm",["install"],{cwd:e}),d.stop("Package update complete!"),B("Please review and test the upgraded package version."),!0},Mn=async(e,t,n,r,i)=>{let s=v(e,te),o=Ge(),a=i?.sync?s:t;o.start("Preparing template snapshot..."),i?.sync&&(await xn(e,te),await N(s)),o.message("Scanning for files...");let d=await Ce(n,r,a),c=[];if(i?.sync){o.message("Comparing with local files...");let l=await Ce(n,r,e),m=new Set(d);c=l.filter(f=>!m.has(f))}if(o.stop(`Found ${d.length} files to update`),d.length===0&&c.length===0){w.warn("No files matched the patterns. Nothing to update."),i?.sync&&await ne(s),B("Update cancelled.");return}w.info(`Patterns: ${n.length}`),w.info(`Files to update: ${d.length}`),i?.sync&&w.info(`Files to delete: ${c.length}`),o.start("Updating files...");let u=await _n(d,c,a,e,o);i?.sync&&(o.message("Cleaning up..."),await ne(s)),o.stop("Update complete!"),Tn(u),B("Please review and test the changes carefully.")},Ue=async(e,t)=>{let n=process.cwd(),r=H(),i=e&&e.length>0?e:wn,s=e&&e.length>0?[]:yn;try{if(fn("Let's update your Geistdocs project!"),await An(n,e,t))return;w.info("Template source: bundled package snapshot"),e&&e.length>0&&w.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&w.info("Sync mode enabled: will delete files removed from template"),await Mn(n,r,i,s,t)}catch(o){let a=o instanceof Error?o.message:`${o}`;try{await ne(v(n,te))}catch{}w.error(`Failed to update project: ${a}`),process.exit(1)}};A.name("geistdocs").description("CLI for Geistdocs projects").version("2.5.0","-v, --version","Output the current version");A.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").addOption(new Rn("--brand <brand>","Navbar brand").choices(["vercel","labs"]).default("vercel")).option("--disable-git","Disable git initialization").action(he);A.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(Ue);A.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(ke);var Fn=A.command("search").description("Manage the external search index used by Ask AI");Fn.command("sync").description("Sync the latest static docs export to Mixedbread").option("--dir <path>","Next.js output directory",".next").option("--allow-non-production","Run outside a production Vercel build").action(Pe);await A.parseAsync(process.argv).catch(e=>{console.error(e instanceof Error?e.message:e),process.exitCode=1});
|
|
7
|
+
`));let o=await Ie({client:we({apiBaseUrl:process.env.MXBAI_BASE_URL,apiKey:r,storeId:i}),manifest:s,...Nt(n)});console.log(`Geistdocs search sync complete: ${o.uploaded} uploaded, ${o.deleted} deleted, ${o.skipped} unchanged.`)};import{readFileSync as Gt,writeFileSync as Ut}from"fs";import{mkdir as Lt,readFile as Z,writeFile as jt}from"fs/promises";import{dirname as Bt,extname as Vt,relative as Fe,resolve as j}from"path";import{intro as Jt,isCancel as Ht,log as I,multiselect as Xt,outro as L,spinner as Kt}from"@clack/prompts";import{glob as Yt}from"glob";import{Node as F,Project as qt,SyntaxKind as zt}from"ts-morph";var Wt="geistdocs.tsx",Qt="content/docs/**/*.mdx",ee=".translation-cache.json",Q=8,Ae=()=>({version:1,entries:{}}),Zt=async e=>{let t=await Z(e),{createHash:n}=await import("crypto");return n("sha256").update(t).digest("hex")},en=e=>{let t=j(process.cwd(),e);return Gt(t,"utf8")},Me=e=>F.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(F.isPropertyAssignment(t)){let n=t.getNameNode();if(F.isIdentifier(n)||F.isStringLiteral(n))return[n.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],tn=e=>{try{let t=new qt({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),n=en(e),s=t.createSourceFile(e,n,{overwrite:!0}).getVariableDeclarations().find(a=>a.getName()==="translations")?.getInitializer();if(!s)return[];if(F.isObjectLiteralExpression(s))return Me(s);let o=s.getFirstDescendantByKind(zt.ObjectLiteralExpression);return o?Me(o):[]}catch(t){let n=t instanceof Error?t.message:`${t}`;return I.warn(`Failed to read locales from ${e}: ${n}`),[]}},nn=async()=>{let e=await Xt({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ht(e)&&(L("Translation cancelled"),process.exit(0)),e},rn=async e=>(await Yt(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),sn=async()=>{let e=j(process.cwd(),ee);try{let t=await Z(e,"utf8"),n=JSON.parse(t);return n.version!==1||!n.entries?Ae():{version:1,entries:n.entries}}catch{return Ae()}},Re=e=>{let t=j(process.cwd(),ee),n=JSON.stringify(e,null,2);Ut(t,n,"utf8")},on=async e=>{let t=await Promise.all(e.map(async n=>[n,await Zt(n)]));return Object.fromEntries(t)},an=(e,t)=>{let n=Vt(e);return`${e.slice(0,-n.length)}.${t}${n}`},De=(e,t)=>`${Fe(process.cwd(),e)}::${t}`,cn=(e,t,n,r,i=!1)=>{let s=[],o=0;for(let a of t){let d=n[a];for(let c of e){let u=an(a,c),l=De(a,c),m=r.entries[l];if(!i&&m?.hash===d){o+=1;continue}s.push({locale:c,sourceFile:a,sourceHash:d,targetFile:u})}}return{tasks:s,skippedCount:o}},dn=async e=>{await Lt(Bt(e),{recursive:!0})},ln=async(e,t,n)=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:n})});if(!r.ok){let s=await r.text();throw new Error(`API request failed (${r.status}): ${s}`)}let i=await r.json();if(!i.translation)throw new Error("API response did not include a translation");return i.translation},pn=async(e,t,n)=>{let r=await Z(e.sourceFile,"utf8"),i=await ln(t,r,e.locale);await dn(e.targetFile),await jt(e.targetFile,i,"utf8"),n.entries[De(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},ke=async(e,t)=>{Jt("Translate MDX content");let n=e??Qt,r=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",i=tn(t.config??Wt),s=await rn(n);s.length===0&&(I.error(`No MDX files found matching pattern: ${n}`),L("Translation cancelled"),process.exit(1)),I.info(`Found ${s.length} MDX file(s) matching pattern`),i.length===0&&(i=await nn());let o=j(process.cwd(),ee),a=await sn();await Re(a),I.info(`Using cache: ${o}`);let d=await on(s),{tasks:c,skippedCount:u}=cn(i,s,d,a,t.force);if(c.length===0){I.success("All translations are up to date!"),L(`Skipped ${u} file(s) (unchanged)`);return}let l=[];for(let h=0;h<c.length;h+=Q)l.push(c.slice(h,h+Q));I.info(`Processing ${c.length} translation(s) in ${l.length} batch(es) of up to ${Q}`),u>0&&I.info(`Skipped ${u} translation(s) (unchanged)`);let m=Kt();m.start("Translating content...");let f=0;for(let h of l)await Promise.all(h.map(async x=>{await pn(x,r,a),f+=1,m.message(`Translated ${f}/${c.length}: ${Fe(process.cwd(),x.targetFile)}`)})),await Re(a);m.stop("Translation complete!"),L(`Created/updated ${c.length} file(s)`)};import{access as un,copyFile as gn,mkdir as Ne,rm as re}from"fs/promises";import{dirname as mn,join as v}from"path";import{intro as fn,log as w,outro as B,spinner as Ge}from"@clack/prompts";import{glob as hn}from"glob";var wn=["**/*"],yn=["content/docs/**"],te=".geistdocs-tmp",xn=async(e,t)=>{let n=v(e,t);await re(n,{recursive:!0,force:!0}),await Ne(n,{recursive:!0})},ne=async e=>await re(e,{recursive:!0,force:!0}),Ce=async(e,t,n)=>(await hn(e,{cwd:n,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),bn=async e=>{try{return await un(e),!0}catch{return!1}},En=async(e,t,n)=>{let r=v(t,e),i=v(n,e);return await bn(r)?(await gn(r,i),{success:!0}):{success:!1,error:`Source file not found: ${r}`}},Sn=async(e,t)=>{let n=v(t,e);return await re(n,{force:!0}),{success:!0}},Oe=20,$e=async(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=n){let s=e.slice(i,i+n),o=await Promise.all(s.map(t));r.push(...o)}return r},_n=async(e,t,n,r,i)=>{let s={success:[],deleted:[],failed:[]},o=[...new Set(e.map(d=>mn(v(r,d))))];i.message(`Creating ${o.length} directories...`),await Promise.all(o.map(d=>Ne(d,{recursive:!0}))),i.message(`Updating ${e.length} files...`);let a=await $e(e,async d=>{let c=await En(d,n,r);return{file:d,...c}},Oe);for(let{file:d,success:c,error:u}of a)c?s.success.push(d):s.failed.push({file:d,error:u??"Unknown error"});if(t.length>0){i.message(`Deleting ${t.length} files...`);let d=await $e(t,async c=>{try{return await Sn(c,r),{file:c,success:!0}}catch(u){let l=u instanceof Error?u.message:`${u}`;return{file:c,success:!1,error:l}}},Oe);for(let c of d)c.success?s.deleted.push(c.file):s.failed.push({file:c.file,error:c.error})}return s},Tn=e=>{if(e.success.length>0){w.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)w.info(` \u2713 ${t}`)}if(e.deleted.length>0){w.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)w.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){w.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:n}of e.failed)w.error(` \u2717 ${t}: ${n}`)}},In=e=>e.includes("canary")?"canary":"latest",vn=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(S)}`);if(!t.ok)throw new Error(`Failed to resolve ${S}@${e}`);let r=(await t.json())["dist-tags"]?.[e];if(!r)throw new Error(`Could not find dist-tag ${e} for ${S}`);return r},Pn=async e=>{let t=await M(e),n=J(t,S);if(!n)return{currentVersion:n,nextVersion:void 0,updated:!1};let r=In(n),i=await vn(r);return n===i?{currentVersion:n,nextVersion:i,updateTag:r,updated:!1}:($(t,S,i),await O(e,t),{currentVersion:n,nextVersion:i,updateTag:r,updated:!0})},An=async(e,t,n)=>{let r=await M(e);if(!le(r,S))return!1;t&&t.length>0&&w.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),n?.sync&&w.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:i,nextVersion:s,updateTag:o,updated:a}=await Pn(e);if(!a)return w.success(i?`@vercel/geistdocs is already at ${s} (${o}).`:"No package version update was needed."),B("Package-based site is already up to date."),!0;w.info(`Bumping ${S} from ${i} to ${s} (${o})`);let d=Ge();return d.start("Installing updated package version..."),await T("pnpm",["install"],{cwd:e}),d.stop("Package update complete!"),B("Please review and test the upgraded package version."),!0},Mn=async(e,t,n,r,i)=>{let s=v(e,te),o=Ge(),a=i?.sync?s:t;o.start("Preparing template snapshot..."),i?.sync&&(await xn(e,te),await N(s)),o.message("Scanning for files...");let d=await Ce(n,r,a),c=[];if(i?.sync){o.message("Comparing with local files...");let l=await Ce(n,r,e),m=new Set(d);c=l.filter(f=>!m.has(f))}if(o.stop(`Found ${d.length} files to update`),d.length===0&&c.length===0){w.warn("No files matched the patterns. Nothing to update."),i?.sync&&await ne(s),B("Update cancelled.");return}w.info(`Patterns: ${n.length}`),w.info(`Files to update: ${d.length}`),i?.sync&&w.info(`Files to delete: ${c.length}`),o.start("Updating files...");let u=await _n(d,c,a,e,o);i?.sync&&(o.message("Cleaning up..."),await ne(s)),o.stop("Update complete!"),Tn(u),B("Please review and test the changes carefully.")},Ue=async(e,t)=>{let n=process.cwd(),r=H(),i=e&&e.length>0?e:wn,s=e&&e.length>0?[]:yn;try{if(fn("Let's update your Geistdocs project!"),await An(n,e,t))return;w.info("Template source: bundled package snapshot"),e&&e.length>0&&w.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&w.info("Sync mode enabled: will delete files removed from template"),await Mn(n,r,i,s,t)}catch(o){let a=o instanceof Error?o.message:`${o}`;try{await ne(v(n,te))}catch{}w.error(`Failed to update project: ${a}`),process.exit(1)}};A.name("geistdocs").description("CLI for Geistdocs projects").version("2.6.0","-v, --version","Output the current version");A.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").addOption(new Rn("--brand <brand>","Navbar brand").choices(["vercel","labs"]).default("vercel")).option("--disable-git","Disable git initialization").action(he);A.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(Ue);A.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(ke);var Fn=A.command("search").description("Manage the external search index used by Ask AI");Fn.command("sync").description("Sync the latest static docs export to Mixedbread").option("--dir <path>","Next.js output directory",".next").option("--allow-non-production","Run outside a production Vercel build").action(Pe);await A.parseAsync(process.argv).catch(e=>{console.error(e instanceof Error?e.message:e),process.exitCode=1});
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
export declare const normalizeBasePath: (basePath: string | undefined) => string;
|
|
3
3
|
/** Convert an app-local path to the URL exposed by a Next.js base-path app. */
|
|
4
4
|
export declare const getPublicPath: (href: string, basePath: string | undefined) => string;
|
|
5
|
+
/** Convert a public path that may carry the base path back to its app-local form. */
|
|
6
|
+
export declare const stripBasePath: (href: string, basePath: string | undefined) => string;
|
|
5
7
|
/** Keep public paths stable while adding a base path to app-local paths. */
|
|
6
8
|
export declare const withBasePath: (href: string, basePath: string | undefined) => string;
|
|
7
9
|
export interface GeistdocsNavLink {
|
|
@@ -105,9 +107,16 @@ export interface GeistdocsAgentApiConfig {
|
|
|
105
107
|
authDocsUrl?: string;
|
|
106
108
|
errorsUrl?: string;
|
|
107
109
|
openApiSpecs?: GeistdocsAgentOpenApiSpecConfig[];
|
|
110
|
+
/** OpenAPI document for the product's own API, hosted anywhere. */
|
|
108
111
|
openApiUrl?: string;
|
|
109
112
|
rateLimitsUrl?: string;
|
|
110
113
|
scopesDocsUrl?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Root-relative path where the site serves the OpenAPI document generated
|
|
116
|
+
* by `createOpenApiRoute`, which describes the documentation site's own
|
|
117
|
+
* search, chat, and Markdown endpoints rather than the product API.
|
|
118
|
+
*/
|
|
119
|
+
siteOpenApiUrl?: string;
|
|
111
120
|
}
|
|
112
121
|
export interface GeistdocsAgentOpenApiSpecConfig {
|
|
113
122
|
description?: string;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,GAAG,SAAS,WAO7D,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,WAoBvE,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS,WAWtE,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uCAAuC;AACvC,MAAM,WAAW,wBAAwB;IACvC,Q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C,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,MAAM,CAAC,EAAE,sBAAsB,CAAC;CACjC;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,eAAe,EAAE,QAAQ,CAAC,KAAG,CAAW,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -23,6 +23,19 @@ export const getPublicPath = (href, basePath) => {
|
|
|
23
23
|
}
|
|
24
24
|
return `${normalizedBasePath}${href}`;
|
|
25
25
|
};
|
|
26
|
+
/** Convert a public path that may carry the base path back to its app-local form. */
|
|
27
|
+
export const stripBasePath = (href, basePath) => {
|
|
28
|
+
const normalizedBasePath = normalizeBasePath(basePath);
|
|
29
|
+
if (!normalizedBasePath) {
|
|
30
|
+
return href;
|
|
31
|
+
}
|
|
32
|
+
if (href === normalizedBasePath) {
|
|
33
|
+
return "/";
|
|
34
|
+
}
|
|
35
|
+
return href.startsWith(`${normalizedBasePath}/`)
|
|
36
|
+
? href.slice(normalizedBasePath.length)
|
|
37
|
+
: href;
|
|
38
|
+
};
|
|
26
39
|
/** Keep public paths stable while adding a base path to app-local paths. */
|
|
27
40
|
export const withBasePath = (href, basePath) => {
|
|
28
41
|
const normalizedBasePath = normalizeBasePath(basePath);
|
|
@@ -46,6 +46,6 @@ const GeistdocsProviderInner = ({ config, search, theme: _theme, lang, ...props
|
|
|
46
46
|
return (_jsxs("div", { className: cn("@container transition-[padding-right] duration-150 ease-[cubic-bezier(0.175,0.885,0.32,1.1)] motion-reduce:transition-none", enabled && isOpen && !isMobile ? "pr-[400px]!" : null), "data-geistdocs-container": true, children: [_jsx(RootProvider, { i18n: i18nProvider(lang ?? i18n.defaultLanguage), search: {
|
|
47
47
|
SearchDialog: SearchDialogComponent,
|
|
48
48
|
...search,
|
|
49
|
-
}, theme: { enabled: false }, ...props }), _jsx(GeistdocsWebMCP, { config: config
|
|
49
|
+
}, theme: { enabled: false }, ...props }), _jsx(GeistdocsWebMCP, { config: config }), _jsx(Toasts, {}), hasBeenOpened ? (_jsx(Suspense, { fallback: isOpen ? (_jsx(ChatLoadingSkeleton, { isMobile: isMobile, title: config.title })) : null, children: _jsx(GeistdocsChatShell, {}) })) : null] }));
|
|
50
50
|
};
|
|
51
51
|
export const GeistdocsProvider = (props) => (_jsx(GeistProvider, { storageKey: "geistdocs-theme", withScript: false, children: _jsx(GeistdocsConfigProvider, { config: props.config, children: _jsx(GeistdocsChatProvider, { config: props.config, children: _jsx(GeistdocsProviderInner, { ...props }) }) }) }));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const GeistdocsWebMCP: ({ config
|
|
1
|
+
import { type GeistdocsConfig } from "../config";
|
|
2
|
+
export declare const GeistdocsWebMCP: ({ config }: {
|
|
3
3
|
config: GeistdocsConfig;
|
|
4
|
-
|
|
5
|
-
}) => null;
|
|
4
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
6
5
|
//# sourceMappingURL=webmcp-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webmcp-client.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp-client.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webmcp-client.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp-client.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAOhE,eAAO,MAAM,eAAe,GAAI,YAAY;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,mDAqBtE,CAAC"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import Script from "next/script";
|
|
2
4
|
import { useEffect } from "react";
|
|
5
|
+
import { getPublicPath } from "../config";
|
|
3
6
|
import { createWebMCPTools, registerWebMCPTools, } from "./webmcp";
|
|
4
|
-
export const GeistdocsWebMCP = ({ config
|
|
7
|
+
export const GeistdocsWebMCP = ({ config }) => {
|
|
8
|
+
const enabled = config.webmcp?.enabled;
|
|
5
9
|
useEffect(() => {
|
|
6
10
|
const context = document
|
|
7
11
|
.modelContext;
|
|
8
|
-
if (!(
|
|
12
|
+
if (!(enabled && context?.registerTool)) {
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
location: window.location,
|
|
15
|
-
});
|
|
16
|
-
return registerWebMCPTools(context, tools, (error) => {
|
|
17
|
-
console.warn("Geistdocs WebMCP registration failed:", error);
|
|
18
|
-
});
|
|
19
|
-
}, [config, lang]);
|
|
20
|
-
return null;
|
|
15
|
+
return registerWebMCPTools(context, createWebMCPTools({ location: window.location }), (error) => console.warn("Geistdocs WebMCP registration failed:", error));
|
|
16
|
+
}, [enabled]);
|
|
17
|
+
return enabled ? (_jsx(Script, { id: "geistdocs-webmcp", src: `${getPublicPath("/api/mcp", config.basePath)}?webmcp-script` })) : null;
|
|
21
18
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type GeistdocsConfig } from "../config.js";
|
|
2
1
|
interface ToolExecutionContext {
|
|
3
2
|
signal?: AbortSignal;
|
|
4
3
|
}
|
|
@@ -17,14 +16,11 @@ export interface WebMCPContext {
|
|
|
17
16
|
signal: AbortSignal;
|
|
18
17
|
}) => Promise<void>;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
config: GeistdocsConfig;
|
|
19
|
+
export declare const createWebMCPTools: ({ fetcher, location, requestTimeoutMs, }: {
|
|
22
20
|
fetcher?: typeof fetch;
|
|
23
|
-
lang?: string;
|
|
24
21
|
location: Pick<Location, "href">;
|
|
25
22
|
requestTimeoutMs?: number;
|
|
26
|
-
}
|
|
27
|
-
export declare const createWebMCPTools: ({ config, fetcher, lang, location, requestTimeoutMs, }: WebMCPOptions) => WebMCPTool[];
|
|
23
|
+
}) => WebMCPTool[];
|
|
28
24
|
export declare const registerWebMCPTools: (context: WebMCPContext, tools: WebMCPTool[], onError: (error: unknown) => void) => () => void;
|
|
29
25
|
export {};
|
|
30
26
|
//# sourceMappingURL=webmcp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webmcp.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"webmcp.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,UAAU,UAAU;IAClB,WAAW,EAAE;QAAE,YAAY,EAAE,OAAO,CAAC;QAAC,oBAAoB,EAAE,OAAO,CAAA;KAAE,CAAC;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,CACP,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,CACZ,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,GAAI,0CAI/B;IACD,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,UAAU,EAkCb,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,EACtB,OAAO,UAAU,EAAE,EACnB,SAAS,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,eAoBlC,CAAC"}
|
package/dist/internal/webmcp.js
CHANGED
|
@@ -1,84 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: "search_docs",
|
|
11
|
-
description: `Search ${config.title} documentation in the current language. Returns matching titles, excerpts, and page URLs.`,
|
|
12
|
-
annotations,
|
|
13
|
-
inputSchema: {
|
|
14
|
-
type: "object",
|
|
15
|
-
properties: { query: { type: "string", minLength: 1, maxLength: 500 } },
|
|
16
|
-
required: ["query"],
|
|
17
|
-
additionalProperties: false,
|
|
18
|
-
},
|
|
19
|
-
execute: async (input, { signal } = {}) => {
|
|
20
|
-
if (typeof input.query !== "string" ||
|
|
21
|
-
!input.query.trim() ||
|
|
22
|
-
input.query.length > 500) {
|
|
23
|
-
throw new Error("query must contain between 1 and 500 characters.");
|
|
24
|
-
}
|
|
25
|
-
const url = new URL(getPublicPath("/api/search", config.basePath), location.href);
|
|
26
|
-
url.searchParams.set("query", input.query.trim());
|
|
27
|
-
url.searchParams.set("locale", lang ?? config.defaultLanguage ?? "en");
|
|
28
|
-
const response = await fetcher(url, {
|
|
29
|
-
signal: getRequestSignal(signal),
|
|
30
|
-
redirect: "error",
|
|
31
|
-
});
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
throw new Error(`Documentation search failed (${response.status}).`);
|
|
34
|
-
}
|
|
35
|
-
const results = await response.json();
|
|
36
|
-
if (!Array.isArray(results)) {
|
|
37
|
-
throw new Error("Documentation search returned an invalid response.");
|
|
38
|
-
}
|
|
39
|
-
return JSON.stringify(results.map((result) => {
|
|
40
|
-
if (typeof result !== "object" ||
|
|
41
|
-
result === null ||
|
|
42
|
-
!("url" in result) ||
|
|
43
|
-
typeof result.url !== "string") {
|
|
44
|
-
throw new Error("Documentation search returned an invalid result.");
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
...result,
|
|
48
|
-
url: withBasePath(result.url, config.basePath),
|
|
49
|
-
};
|
|
50
|
-
}));
|
|
51
|
-
},
|
|
1
|
+
export const createWebMCPTools = ({ fetcher = fetch, location, requestTimeoutMs = 15_000, }) => [
|
|
2
|
+
{
|
|
3
|
+
name: "read_current_page",
|
|
4
|
+
description: "Read the current documentation page as Markdown. Navigate to a documentation page before calling this tool.",
|
|
5
|
+
annotations: { readOnlyHint: true, untrustedContentHint: true },
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {},
|
|
9
|
+
additionalProperties: false,
|
|
52
10
|
},
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
throw new Error(`Documentation page could not be read (${response.status}).`);
|
|
73
|
-
}
|
|
74
|
-
if (!response.headers.get("content-type")?.includes("text/markdown")) {
|
|
75
|
-
throw new Error("The current page does not provide documentation Markdown.");
|
|
76
|
-
}
|
|
77
|
-
return response.text();
|
|
78
|
-
},
|
|
11
|
+
execute: async (_input, { signal } = {}) => {
|
|
12
|
+
const url = new URL(location.href);
|
|
13
|
+
url.hash = "";
|
|
14
|
+
url.search = "";
|
|
15
|
+
const deadline = AbortSignal.timeout(requestTimeoutMs);
|
|
16
|
+
const response = await fetcher(url, {
|
|
17
|
+
headers: { Accept: "text/markdown" },
|
|
18
|
+
redirect: "error",
|
|
19
|
+
signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(`Documentation page could not be read (${response.status}).`);
|
|
23
|
+
}
|
|
24
|
+
if (!response.headers.get("content-type")?.includes("text/markdown")) {
|
|
25
|
+
throw new Error("The current page does not provide documentation Markdown.");
|
|
26
|
+
}
|
|
27
|
+
return response.text();
|
|
79
28
|
},
|
|
80
|
-
|
|
81
|
-
|
|
29
|
+
},
|
|
30
|
+
];
|
|
82
31
|
export const registerWebMCPTools = (context, tools, onError) => {
|
|
83
32
|
const controller = new AbortController();
|
|
84
33
|
const register = async () => {
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,UAAU,CAAC;AASlB,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,IAAI,CAAC;AAET,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,eAAe,CAAC;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CA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QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC;IACnE,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC1C,oBAAoB,CAAC,EAAE,CACrB,KAAK,EAAE,yBAAyB,KAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;CAC9C;AAqKD,eAAO,MAAM,WAAW,GAAI,gIASzB,kBAAkB,MA6VL,SAAS,WAAW,EAAE,SAAS,cAAc,sBA0D5D,CAAC"}
|
package/dist/proxy.js
CHANGED
|
@@ -2,7 +2,7 @@ import { applyMarkdownHeaders, createNotFoundResponse, } from "@vercel/agent-rea
|
|
|
2
2
|
import { defineI18n } from "fumadocs-core/i18n";
|
|
3
3
|
import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
|
|
4
4
|
import { NextResponse, } from "next/server";
|
|
5
|
-
import { getPublicPath, normalizeBasePath, } from "./config";
|
|
5
|
+
import { getPublicPath, normalizeBasePath, stripBasePath, } from "./config";
|
|
6
6
|
import { matchesAppRoute, parseAppRouteManifest, } from "./internal/app-route-manifest";
|
|
7
7
|
import { getMarkdownDecision } from "./internal/markdown-negotiation";
|
|
8
8
|
import { renderNotFoundMarkdown } from "./internal/not-found";
|
|
@@ -23,6 +23,7 @@ const PACKAGE_ROUTE_PATHS = new Set([
|
|
|
23
23
|
"/.well-known/mcp.json",
|
|
24
24
|
"/agents.md",
|
|
25
25
|
"/llms.txt",
|
|
26
|
+
"/openapi.json",
|
|
26
27
|
"/rss.xml",
|
|
27
28
|
"/sitemap.md",
|
|
28
29
|
]);
|
|
@@ -139,6 +140,13 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
139
140
|
hideLocale: "default-locale",
|
|
140
141
|
});
|
|
141
142
|
const configuredBasePath = normalizeBasePath(config.basePath);
|
|
143
|
+
// The site OpenAPI document can be mounted at a custom path; like the other
|
|
144
|
+
// package routes it must never be captured by a Markdown mapping.
|
|
145
|
+
const packageRoutePaths = new Set(PACKAGE_ROUTE_PATHS);
|
|
146
|
+
const siteOpenApiPath = config.agent?.api?.siteOpenApiUrl;
|
|
147
|
+
if (siteOpenApiPath) {
|
|
148
|
+
packageRoutePaths.add(stripBasePath(siteOpenApiPath, configuredBasePath));
|
|
149
|
+
}
|
|
142
150
|
const internationalizer = createI18nMiddleware({
|
|
143
151
|
...i18n,
|
|
144
152
|
format: (locale, path) => getPublicPath(`/${locale}${path}`, configuredBasePath),
|
|
@@ -249,7 +257,7 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
249
257
|
}
|
|
250
258
|
const localized = getLocalizedPathname(pathname, languages, defaultLanguage);
|
|
251
259
|
if ((localized.hasLanguagePrefix && localized.language === defaultLanguage) ||
|
|
252
|
-
|
|
260
|
+
packageRoutePaths.has(localized.pathname)) {
|
|
253
261
|
return null;
|
|
254
262
|
}
|
|
255
263
|
const extensionResponse = await handleMarkdownExtensionRequest(request, context, proxyContext, localized.pathname, localized.language, pathname);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,WAAW,CAAC;AASnB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,IAAI,CACV,eAAe,EACb,OAAO,GACP,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,CACb,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,KAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,WAAW,CAAC;AASnB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,IAAI,CACV,eAAe,EACb,OAAO,GACP,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,CACb,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,KAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;AA4TD,eAAO,MAAM,iBAAiB,GAAI,wBAG/B,wBAAwB;mBAId,WAAW,eACR;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;CA2BtD,CAAC"}
|
package/dist/routes/agents.js
CHANGED
|
@@ -95,6 +95,8 @@ const getApiLinks = (api, config, origin) => [
|
|
|
95
95
|
renderLink("Rate limits", toSiteUrl(config, origin, api.rateLimitsUrl)),
|
|
96
96
|
api?.errorsUrl &&
|
|
97
97
|
renderLink("Error handling", toSiteUrl(config, origin, api.errorsUrl)),
|
|
98
|
+
api?.siteOpenApiUrl &&
|
|
99
|
+
renderLink("Documentation site API (OpenAPI)", toSiteUrl(config, origin, api.siteOpenApiUrl), "HTTP endpoints of this documentation site itself, not the product API"),
|
|
98
100
|
].filter((link) => Boolean(link));
|
|
99
101
|
const renderApiSection = (api, config, origin) => {
|
|
100
102
|
const links = getApiLinks(api, config, origin);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type GeistdocsConfig } from "../config";
|
|
1
|
+
import { type GeistdocsConfig } from "../config.js";
|
|
2
2
|
type DiscoveryConfig = Pick<GeistdocsConfig, "agent">;
|
|
3
3
|
export declare const getDiscoveryLanguages: (config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">) => string[];
|
|
4
4
|
export declare const toAbsoluteUrl: ({ basePath, href, origin, }: {
|
|
@@ -12,7 +12,8 @@ export declare const toPublicUrl: ({ basePath, href, origin, }: {
|
|
|
12
12
|
origin: string;
|
|
13
13
|
}) => string;
|
|
14
14
|
export declare const toSiteUrl: (config: Pick<GeistdocsConfig, "basePath">, origin: string, href: string) => string;
|
|
15
|
-
|
|
15
|
+
type SiteOpenApiPathConfig = Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "translations">;
|
|
16
|
+
export declare const validateAgentDiscoveryConfig: (config: DiscoveryConfig & SiteOpenApiPathConfig) => void;
|
|
16
17
|
export declare const validateMcpManifestConfig: (config: DiscoveryConfig) => void;
|
|
17
18
|
export {};
|
|
18
19
|
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/routes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/routes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;AAEtB,KAAK,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAgBtD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,aAMlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,6BAI3B;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,6BAIzB;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,QAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,EACzC,QAAQ,MAAM,EACd,MAAM,MAAM,WACiD,CAAC;AAiChE,KAAK,qBAAqB,GAAG,IAAI,CAC/B,eAAe,EACf,UAAU,GAAG,iBAAiB,GAAG,cAAc,CAChD,CAAC;AA4CF,eAAO,MAAM,4BAA4B,GACvC,QAAQ,eAAe,GAAG,qBAAqB,SAmBhD,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,eAAe,SAahE,CAAC"}
|
package/dist/routes/discovery.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { getPublicPath, withBasePath } from "../config";
|
|
1
|
+
import { getPublicPath, stripBasePath, withBasePath, } from "../config.js";
|
|
2
2
|
const ABSOLUTE_URL_PATTERN = /^[a-z][a-z\d+.-]*:/i;
|
|
3
|
+
const QUERY_OR_FRAGMENT_PATTERN = /[?#]/;
|
|
4
|
+
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
5
|
+
const MARKDOWN_EXTENSION_PATTERN = /\.mdx?$/i;
|
|
6
|
+
/** Paths the OpenAPI document already describes; the document cannot live at one of them. */
|
|
7
|
+
const RESERVED_SITE_PATHS = new Set([
|
|
8
|
+
"/.well-known/mcp.json",
|
|
9
|
+
"/agents.md",
|
|
10
|
+
"/api/chat",
|
|
11
|
+
"/api/search",
|
|
12
|
+
"/llms.txt",
|
|
13
|
+
"/sitemap.md",
|
|
14
|
+
]);
|
|
3
15
|
export const getDiscoveryLanguages = (config) => {
|
|
4
16
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
5
17
|
const languages = Object.keys(config.translations ?? {});
|
|
@@ -42,11 +54,47 @@ const assertDiscoveryUrl = (value, field) => {
|
|
|
42
54
|
throw new Error(`${field} must use http or https.`);
|
|
43
55
|
}
|
|
44
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* The site OpenAPI path is matched against language-stripped request
|
|
59
|
+
* pathnames by the proxy and echoed as the document's own path, so only a
|
|
60
|
+
* plain, language-neutral route path that a request can carry is accepted.
|
|
61
|
+
*/
|
|
62
|
+
const assertSiteOpenApiPath = (value, { basePath, ...languagesConfig }) => {
|
|
63
|
+
const field = "agent.api.siteOpenApiUrl";
|
|
64
|
+
if (ABSOLUTE_URL_PATTERN.test(value)) {
|
|
65
|
+
throw new Error(`${field} must be a root-relative path.`);
|
|
66
|
+
}
|
|
67
|
+
assertDiscoveryUrl(value, field);
|
|
68
|
+
if (QUERY_OR_FRAGMENT_PATTERN.test(value)) {
|
|
69
|
+
throw new Error(`${field} must not include a query string or fragment.`);
|
|
70
|
+
}
|
|
71
|
+
const appLocalPath = stripBasePath(value, basePath);
|
|
72
|
+
if (appLocalPath === "/") {
|
|
73
|
+
throw new Error(`${field} must not be the site root.`);
|
|
74
|
+
}
|
|
75
|
+
if (TRAILING_SLASH_PATTERN.test(value)) {
|
|
76
|
+
throw new Error(`${field} must not end with a slash.`);
|
|
77
|
+
}
|
|
78
|
+
if (RESERVED_SITE_PATHS.has(appLocalPath)) {
|
|
79
|
+
throw new Error(`${field} must not be a path the document already describes (${appLocalPath}).`);
|
|
80
|
+
}
|
|
81
|
+
// `.md` and `.mdx` URLs are page-level Markdown everywhere else on the site.
|
|
82
|
+
if (MARKDOWN_EXTENSION_PATTERN.test(appLocalPath)) {
|
|
83
|
+
throw new Error(`${field} must not end with .md or .mdx.`);
|
|
84
|
+
}
|
|
85
|
+
const firstSegment = appLocalPath.split("/")[1];
|
|
86
|
+
if (getDiscoveryLanguages(languagesConfig).includes(firstSegment)) {
|
|
87
|
+
throw new Error(`${field} must not start with a language prefix (/${firstSegment}); the document is served for every language.`);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
45
90
|
export const validateAgentDiscoveryConfig = (config) => {
|
|
46
91
|
if (!config.agent || config.agent.enabled === false) {
|
|
47
92
|
return;
|
|
48
93
|
}
|
|
49
94
|
const api = config.agent?.api;
|
|
95
|
+
if (api?.siteOpenApiUrl !== undefined) {
|
|
96
|
+
assertSiteOpenApiPath(api.siteOpenApiUrl, config);
|
|
97
|
+
}
|
|
50
98
|
api?.openApiSpecs?.forEach((spec, index) => {
|
|
51
99
|
if (spec.label.trim() === "") {
|
|
52
100
|
throw new Error(`agent.api.openApiSpecs[${index}].label must not be empty.`);
|
package/dist/routes/mcp.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
1
|
+
import { NextRequest } from "next/server.js";
|
|
2
|
+
import { type GeistdocsConfig } from "../config.js";
|
|
3
|
+
export interface CreateMcpRouteOptions {
|
|
4
|
+
config: Pick<GeistdocsConfig, "title" | "basePath" | "defaultLanguage" | "translations" | "webmcp">;
|
|
5
|
+
search: (request: NextRequest) => Response | Promise<Response>;
|
|
6
|
+
}
|
|
7
|
+
export declare const createMcpRoute: ({ config, search }: CreateMcpRouteOptions) => (request: Request) => Promise<Response>;
|
|
3
8
|
export interface GeistdocsMcpManifestServer {
|
|
4
9
|
description?: string;
|
|
5
10
|
name: string;
|
package/dist/routes/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/routes/mcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/routes/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,cAAc,CAAC;AAOtB,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,IAAI,CACV,eAAe,EACf,OAAO,GAAG,UAAU,GAAG,iBAAiB,GAAG,cAAc,GAAG,QAAQ,CACrE,CAAC;IACF,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChE;AAyBD,eAAO,MAAM,cAAc,GAAI,oBAAoB,qBAAqB,MAQxD,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAmFlD,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,0BAA0B,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,IAAI,CACV,eAAe,EACf,OAAO,GAAG,UAAU,GAAG,iBAAiB,GAAG,OAAO,GAAG,cAAc,CACpE,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAC9B,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;CAC3D;AAoBD,eAAO,MAAM,sBAAsB,GAAI,wBAGpC,6BAA6B;mBAGF,WAAW;;;;;CAuBxC,CAAC"}
|