@vercel/geistdocs 1.2.3-canary.1d733b2 → 1.2.3-canary.53ff3db

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.
Files changed (68) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/components/button-group.d.ts +2 -0
  3. package/dist/components/button-group.d.ts.map +1 -0
  4. package/dist/components/button-group.js +2 -0
  5. package/dist/components/button.d.ts +2 -0
  6. package/dist/components/button.d.ts.map +1 -0
  7. package/dist/components/button.js +2 -0
  8. package/dist/components/card.d.ts +2 -0
  9. package/dist/components/card.d.ts.map +1 -0
  10. package/dist/components/card.js +2 -0
  11. package/dist/components/collapsible.d.ts +2 -0
  12. package/dist/components/collapsible.d.ts.map +1 -0
  13. package/dist/components/collapsible.js +3 -0
  14. package/dist/components/dialog.d.ts +13 -0
  15. package/dist/components/dialog.d.ts.map +1 -0
  16. package/dist/components/dialog.js +35 -0
  17. package/dist/components/drawer.d.ts +2 -0
  18. package/dist/components/drawer.d.ts.map +1 -0
  19. package/dist/components/drawer.js +3 -0
  20. package/dist/components/dropdown-menu.d.ts +2 -0
  21. package/dist/components/dropdown-menu.d.ts.map +1 -0
  22. package/dist/components/dropdown-menu.js +3 -0
  23. package/dist/components/input-group.d.ts +2 -0
  24. package/dist/components/input-group.d.ts.map +1 -0
  25. package/dist/components/input-group.js +3 -0
  26. package/dist/components/input.d.ts +2 -0
  27. package/dist/components/input.d.ts.map +1 -0
  28. package/dist/components/input.js +2 -0
  29. package/dist/components/kbd.d.ts +2 -0
  30. package/dist/components/kbd.d.ts.map +1 -0
  31. package/dist/components/kbd.js +2 -0
  32. package/dist/components/navigation-menu.d.ts +2 -0
  33. package/dist/components/navigation-menu.d.ts.map +1 -0
  34. package/dist/components/navigation-menu.js +3 -0
  35. package/dist/components/popover.d.ts +2 -0
  36. package/dist/components/popover.d.ts.map +1 -0
  37. package/dist/components/popover.js +3 -0
  38. package/dist/components/scroll-area.d.ts +2 -0
  39. package/dist/components/scroll-area.d.ts.map +1 -0
  40. package/dist/components/scroll-area.js +3 -0
  41. package/dist/components/separator.d.ts +2 -0
  42. package/dist/components/separator.d.ts.map +1 -0
  43. package/dist/components/separator.js +3 -0
  44. package/dist/components/sheet.d.ts +2 -0
  45. package/dist/components/sheet.d.ts.map +1 -0
  46. package/dist/components/sheet.js +3 -0
  47. package/dist/components/sonner.d.ts +2 -0
  48. package/dist/components/sonner.d.ts.map +1 -0
  49. package/dist/components/sonner.js +3 -0
  50. package/dist/components/spinner.d.ts +2 -0
  51. package/dist/components/spinner.d.ts.map +1 -0
  52. package/dist/components/spinner.js +2 -0
  53. package/dist/components/textarea.d.ts +2 -0
  54. package/dist/components/textarea.d.ts.map +1 -0
  55. package/dist/components/textarea.js +2 -0
  56. package/dist/components/tooltip.d.ts +2 -0
  57. package/dist/components/tooltip.d.ts.map +1 -0
  58. package/dist/components/tooltip.js +3 -0
  59. package/dist/routes/chat.d.ts +7 -2
  60. package/dist/routes/chat.d.ts.map +1 -1
  61. package/dist/routes/chat.js +349 -63
  62. package/package.json +77 -1
  63. package/template/AGENTS.md +8 -0
  64. package/template/app/api/chat/route.ts +11 -0
  65. package/template/content/docs/ask-ai.mdx +37 -3
  66. package/template/content/docs/deployment.mdx +11 -0
  67. package/template/content/docs/env.mdx +36 -5
  68. package/template/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import{program as T}from"commander";import{access as ce,copyFile as le}from"fs/promises";import{join as pe}from"path";import{cancel as de,intro as ge,isCancel as ue,log as fe,outro as me,spinner as he,text as we}from"@clack/prompts";import{spawn as te}from"child_process";import{readFileSync as se}from"fs";import{cp as ne,readFile as ae,rename as re,writeFile as ie}from"fs/promises";import{join as $}from"path";import{fileURLToPath as oe}from"url";var g="@vercel/geistdocs",m=(e,t=[],s={})=>new Promise((n,a)=>{let r=te(e,t,{stdio:"inherit",...s});r.on("error",a),r.on("close",i=>{if(i===0){n();return}a(new Error(`Command failed with exit code ${i}: ${[e,...t].join(" ")}`))})}),A=["dependencies","devDependencies","optionalDependencies","peerDependencies"],_=()=>JSON.parse(se(new URL("../../package.json",import.meta.url),"utf8")).version,P=async e=>{let t=$(e,"package.json"),s=await ae(t,"utf8");return JSON.parse(s)},x=async(e,t)=>{let s=$(e,"package.json");await ie(s,`${JSON.stringify(t,null,2)}
3
- `,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({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 Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.2.3-canary.1d733b2","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.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(ee);T.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(q);T.parse(process.argv);
3
+ `,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({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 Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.2.3-canary.53ff3db","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.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(ee);T.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(q);T.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/button-group";
2
+ //# sourceMappingURL=button-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button-group.d.ts","sourceRoot":"","sources":["../../src/components/button-group.tsx"],"names":[],"mappings":"AACA,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/button-group";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/button";
2
+ //# sourceMappingURL=button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/components/button.tsx"],"names":[],"mappings":"AACA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/button";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/card";
2
+ //# sourceMappingURL=card.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/components/card.tsx"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/card";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/collapsible";
2
+ //# sourceMappingURL=collapsible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collapsible.d.ts","sourceRoot":"","sources":["../../src/components/collapsible.tsx"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/collapsible";
@@ -0,0 +1,13 @@
1
+ import { Dialog as DialogPrimitive } from "radix-ui";
2
+ import type { ComponentProps } from "react";
3
+ export declare function Dialog(props: ComponentProps<typeof DialogPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
+ export declare function DialogTrigger(props: ComponentProps<typeof DialogPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
5
+ export declare function DialogPortal(props: ComponentProps<typeof DialogPrimitive.Portal>): import("react/jsx-runtime").JSX.Element;
6
+ export declare function DialogClose(props: ComponentProps<typeof DialogPrimitive.Close>): import("react/jsx-runtime").JSX.Element;
7
+ export declare function DialogOverlay({ className, ...props }: ComponentProps<typeof DialogPrimitive.Overlay>): import("react/jsx-runtime").JSX.Element;
8
+ export declare function DialogContent({ className, children, ...props }: ComponentProps<typeof DialogPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
9
+ export declare function DialogHeader({ className, ...props }: ComponentProps<"div">): import("react/jsx-runtime").JSX.Element;
10
+ export declare function DialogFooter({ className, ...props }: ComponentProps<"div">): import("react/jsx-runtime").JSX.Element;
11
+ export declare function DialogTitle({ className, ...props }: ComponentProps<typeof DialogPrimitive.Title>): import("react/jsx-runtime").JSX.Element;
12
+ export declare function DialogDescription({ className, ...props }: ComponentProps<typeof DialogPrimitive.Description>): import("react/jsx-runtime").JSX.Element;
13
+ //# sourceMappingURL=dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/components/dialog.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,wBAAgB,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,2CAExE;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,OAAO,CAAC,2CAGtD;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,MAAM,CAAC,2CAGrD;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,KAAK,CAAC,2CAGpD;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,OAAO,CAAC,2CAWhD;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,OAAO,CAAC,2CAoBhD;AAED,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,2CAQ1E;AAED,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC,2CAW1E;AAED,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,KAAK,CAAC,2CAQ9C;AAED,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,OAAO,eAAe,CAAC,WAAW,CAAC,2CAQpD"}
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { XIcon } from "lucide-react";
4
+ import { Dialog as DialogPrimitive } from "radix-ui";
5
+ import { cn } from "../internal/cn";
6
+ export function Dialog(props) {
7
+ return _jsx(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
8
+ }
9
+ export function DialogTrigger(props) {
10
+ return _jsx(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
11
+ }
12
+ export function DialogPortal(props) {
13
+ return _jsx(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
14
+ }
15
+ export function DialogClose(props) {
16
+ return _jsx(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
17
+ }
18
+ export function DialogOverlay({ className, ...props }) {
19
+ return (_jsx(DialogPrimitive.Overlay, { className: cn("data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=open]:animate-in", className), "data-slot": "dialog-overlay", ...props }));
20
+ }
21
+ export function DialogContent({ className, children, ...props }) {
22
+ return (_jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Content, { className: cn("data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border bg-background-100 p-6 text-gray-1000 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=open]:animate-in sm:max-w-lg", className), "data-slot": "dialog-content", ...props, children: [children, _jsxs(DialogPrimitive.Close, { className: "absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background-100 transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-gray-600 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-gray-100", children: [_jsx(XIcon, { className: "size-4" }), _jsx("span", { className: "sr-only", children: "Close" })] })] })] }));
23
+ }
24
+ export function DialogHeader({ className, ...props }) {
25
+ return (_jsx("div", { className: cn("flex flex-col gap-2 text-center sm:text-left", className), "data-slot": "dialog-header", ...props }));
26
+ }
27
+ export function DialogFooter({ className, ...props }) {
28
+ return (_jsx("div", { className: cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className), "data-slot": "dialog-footer", ...props }));
29
+ }
30
+ export function DialogTitle({ className, ...props }) {
31
+ return (_jsx(DialogPrimitive.Title, { className: cn("font-semibold text-gray-1000", className), "data-slot": "dialog-title", ...props }));
32
+ }
33
+ export function DialogDescription({ className, ...props }) {
34
+ return (_jsx(DialogPrimitive.Description, { className: cn("text-gray-800 text-sm", className), "data-slot": "dialog-description", ...props }));
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/drawer";
2
+ //# sourceMappingURL=drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drawer.d.ts","sourceRoot":"","sources":["../../src/components/drawer.tsx"],"names":[],"mappings":"AAGA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/drawer";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/dropdown-menu";
2
+ //# sourceMappingURL=dropdown-menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropdown-menu.d.ts","sourceRoot":"","sources":["../../src/components/dropdown-menu.tsx"],"names":[],"mappings":"AAGA,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/dropdown-menu";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/input-group";
2
+ //# sourceMappingURL=input-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-group.d.ts","sourceRoot":"","sources":["../../src/components/input-group.tsx"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/input-group";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/input";
2
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/components/input.tsx"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/input";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/kbd";
2
+ //# sourceMappingURL=kbd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kbd.d.ts","sourceRoot":"","sources":["../../src/components/kbd.tsx"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/kbd";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/navigation-menu";
2
+ //# sourceMappingURL=navigation-menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation-menu.d.ts","sourceRoot":"","sources":["../../src/components/navigation-menu.tsx"],"names":[],"mappings":"AAGA,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/navigation-menu";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/popover";
2
+ //# sourceMappingURL=popover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popover.d.ts","sourceRoot":"","sources":["../../src/components/popover.tsx"],"names":[],"mappings":"AAGA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/popover";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/scroll-area";
2
+ //# sourceMappingURL=scroll-area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-area.d.ts","sourceRoot":"","sources":["../../src/components/scroll-area.tsx"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/scroll-area";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/separator";
2
+ //# sourceMappingURL=separator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"separator.d.ts","sourceRoot":"","sources":["../../src/components/separator.tsx"],"names":[],"mappings":"AAGA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/separator";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/sheet";
2
+ //# sourceMappingURL=sheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet.d.ts","sourceRoot":"","sources":["../../src/components/sheet.tsx"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/sheet";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/sonner";
2
+ //# sourceMappingURL=sonner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sonner.d.ts","sourceRoot":"","sources":["../../src/components/sonner.tsx"],"names":[],"mappings":"AAGA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/sonner";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/spinner";
2
+ //# sourceMappingURL=spinner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../src/components/spinner.tsx"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/spinner";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/textarea";
2
+ //# sourceMappingURL=textarea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/components/textarea.tsx"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
2
+ export * from "../internal/ui/textarea";
@@ -0,0 +1,2 @@
1
+ export * from "../internal/ui/tooltip";
2
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/components/tooltip.tsx"],"names":[],"mappings":"AAGA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ // biome-ignore lint/performance/noBarrelFile: Public package export shim.
3
+ export * from "../internal/ui/tooltip";
@@ -1,12 +1,17 @@
1
1
  import type { GeistdocsConfig } from "../config";
2
2
  import type { GeistdocsSourceBundle } from "../source";
3
3
  type SourceBundle = GeistdocsSourceBundle;
4
+ interface ChatProxyConfig {
5
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
6
+ url: string;
7
+ }
4
8
  interface CreateChatRouteOptions {
5
- config: Pick<GeistdocsConfig, "ai" | "defaultLanguage">;
9
+ config: Pick<GeistdocsConfig, "ai" | "basePath" | "defaultLanguage" | "translations">;
10
+ proxy?: ChatProxyConfig;
6
11
  source?: SourceBundle;
7
12
  sources?: SourceBundle[];
8
13
  }
9
- export declare const createChatRoute: ({ config, source, sources, }: CreateChatRouteOptions) => {
14
+ export declare const createChatRoute: ({ config, proxy, source, sources, }: CreateChatRouteOptions) => {
10
15
  POST: (req: Request) => Promise<Response>;
11
16
  maxDuration: 800;
12
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAwB1C,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,iBAAiB,CAAC,CAAC;IACxD,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AA6PD,eAAO,MAAM,eAAe,GAAI,8BAI7B,sBAAsB;gBAIE,OAAO;;CA+EjC,CAAC"}
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAyB1C,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,cAAc,CACvD,CAAC;IACF,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAiqBD,eAAO,MAAM,eAAe,GAAI,qCAK7B,sBAAsB;gBAIE,OAAO;;CAuHjC,CAAC"}
@@ -2,6 +2,305 @@ import { convertToModelMessages, createUIMessageStream, createUIMessageStreamRes
2
2
  import { initAdvancedSearch } from "fumadocs-core/search/server";
3
3
  import { z } from "zod";
4
4
  import { isPageVisibleForSurface } from "../internal/page-visibility";
5
+ const MAX_CONTEXT_CHARS = 1500;
6
+ const MAX_PROXY_RELATED_PAGES = 5;
7
+ const MAX_TOOL_RESULTS = 8;
8
+ const TRAILING_SLASH_PATTERN = /\/$/;
9
+ const normalizePathname = (value) => {
10
+ if (!value) {
11
+ return "/";
12
+ }
13
+ let pathname = value;
14
+ try {
15
+ pathname = new URL(value, "https://geistdocs.local").pathname;
16
+ }
17
+ catch {
18
+ pathname = value.split("?")[0]?.split("#")[0] ?? value;
19
+ }
20
+ if (!pathname.startsWith("/")) {
21
+ pathname = `/${pathname}`;
22
+ }
23
+ return pathname.length > 1
24
+ ? pathname.replace(TRAILING_SLASH_PATTERN, "")
25
+ : pathname;
26
+ };
27
+ const stripBasePath = (pathname, basePath) => {
28
+ const normalizedBasePath = normalizePathname(basePath);
29
+ if (normalizedBasePath === "/") {
30
+ return pathname;
31
+ }
32
+ if (pathname === normalizedBasePath) {
33
+ return "/";
34
+ }
35
+ if (pathname.startsWith(`${normalizedBasePath}/`)) {
36
+ return pathname.slice(normalizedBasePath.length) || "/";
37
+ }
38
+ return pathname;
39
+ };
40
+ const stripLanguagePrefix = (pathname, lang) => {
41
+ const prefix = `/${lang}`;
42
+ if (pathname === prefix) {
43
+ return "/";
44
+ }
45
+ if (pathname.startsWith(`${prefix}/`)) {
46
+ return pathname.slice(prefix.length) || "/";
47
+ }
48
+ return pathname;
49
+ };
50
+ const getLanguages = (config) => {
51
+ const defaultLanguage = config.defaultLanguage ?? "en";
52
+ const languages = Object.keys(config.translations ?? {});
53
+ return {
54
+ defaultLanguage,
55
+ languages: Array.from(new Set([defaultLanguage, ...languages])),
56
+ };
57
+ };
58
+ const getRequestLanguage = ({ basePath, currentRoute, defaultLanguage, languages, }) => {
59
+ const pathname = stripBasePath(normalizePathname(currentRoute), basePath);
60
+ const firstSegment = pathname.split("/").filter(Boolean)[0];
61
+ return firstSegment && languages.includes(firstSegment)
62
+ ? firstSegment
63
+ : defaultLanguage;
64
+ };
65
+ const getMessageText = (message) => message.parts
66
+ .filter((part) => part.type === "text")
67
+ .map((part) => part.text)
68
+ .join("\n");
69
+ const isPageContextMessage = (message) => message.metadata?.isPageContext;
70
+ const getPageData = (page) => page.data;
71
+ const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
72
+ const createSearchServer = (sources, lang) => {
73
+ const indexes = sources.flatMap((source) => source.source
74
+ .getPages(lang)
75
+ .filter((page) => isPageVisibleForSurface(page, "chat"))
76
+ .map((page) => {
77
+ const data = getPageData(page);
78
+ const structuredData = data.structuredData ??
79
+ { headings: [], contents: [] };
80
+ return {
81
+ title: data.title ?? page.url,
82
+ description: data.description ?? "",
83
+ url: page.url,
84
+ id: page.url,
85
+ structuredData,
86
+ };
87
+ }));
88
+ return initAdvancedSearch({ indexes });
89
+ };
90
+ const resolveSearchResult = ({ lang, sources, url, }) => {
91
+ const result = sources
92
+ .map((source) => source.source.getPageByHref(url, { language: lang }))
93
+ .find((entry) => entry?.page);
94
+ if (!result?.page) {
95
+ return null;
96
+ }
97
+ const { page } = result;
98
+ const data = getPageData(page);
99
+ return {
100
+ title: data.title ?? page.url,
101
+ description: data.description ?? "",
102
+ content: getStructuredContent(page),
103
+ slug: page.url,
104
+ };
105
+ };
106
+ const searchDocs = async ({ lang, limit, query, sources, }) => {
107
+ const searchServer = createSearchServer(sources, lang);
108
+ const results = await searchServer.search(query);
109
+ const seenSlugs = new Set();
110
+ return results
111
+ .map(({ url }) => resolveSearchResult({ lang, sources, url }))
112
+ .filter((doc) => Boolean(doc))
113
+ .filter((doc) => {
114
+ if (seenSlugs.has(doc.slug)) {
115
+ return false;
116
+ }
117
+ seenSlugs.add(doc.slug);
118
+ return true;
119
+ })
120
+ .slice(0, limit);
121
+ };
122
+ const formatDocForContext = (doc) => `**${doc.title}**\nURL: ${doc.slug}\n${doc.description || ""}\n\n${doc.content.slice(0, MAX_CONTEXT_CHARS)}${doc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`;
123
+ const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
124
+ const pathname = normalizePathname(currentRoute);
125
+ const withoutBasePath = stripBasePath(pathname, basePath);
126
+ const withoutLanguage = stripLanguagePrefix(withoutBasePath, lang);
127
+ return Array.from(new Set([pathname, withoutBasePath, withoutLanguage]));
128
+ };
129
+ const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
130
+ const candidates = getRouteCandidates({ basePath, currentRoute, lang });
131
+ for (const source of sources) {
132
+ for (const candidate of candidates) {
133
+ const result = source.source.getPageByHref(candidate, { language: lang });
134
+ if (result?.page && isPageVisibleForSurface(result.page, "chat")) {
135
+ return { page: result.page, source };
136
+ }
137
+ }
138
+ const page = source.source
139
+ .getPages(lang)
140
+ .filter((entry) => isPageVisibleForSurface(entry, "chat"))
141
+ .find((entry) => candidates.includes(normalizePathname(entry.url)));
142
+ if (page) {
143
+ return { page, source };
144
+ }
145
+ }
146
+ return null;
147
+ };
148
+ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, sources, }) => {
149
+ if (pageContext) {
150
+ return {
151
+ title: pageContext.title,
152
+ description: "",
153
+ content: pageContext.content,
154
+ slug: pageContext.url,
155
+ };
156
+ }
157
+ const result = findCurrentPage({ basePath, currentRoute, lang, sources });
158
+ if (!result) {
159
+ return null;
160
+ }
161
+ const data = getPageData(result.page);
162
+ return {
163
+ title: data.title ?? result.page.url,
164
+ description: data.description ?? "",
165
+ content: await result.source.getPageMarkdown(result.page),
166
+ slug: result.page.url,
167
+ };
168
+ };
169
+ const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
170
+ const createSourceChunks = (docs) => docs.map((doc, index) => ({
171
+ type: "source-url",
172
+ sourceId: `doc-${index}-${doc.slug}`,
173
+ url: doc.slug,
174
+ title: doc.title,
175
+ }));
176
+ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, }) => {
177
+ if (!isFirstUserMessage(actualMessages)) {
178
+ return { messages: actualMessages, sourceDocs: [] };
179
+ }
180
+ const lastMessage = actualMessages.at(-1);
181
+ if (lastMessage?.role !== "user") {
182
+ return { messages: actualMessages, sourceDocs: [] };
183
+ }
184
+ const userQuestion = getMessageText(lastMessage);
185
+ const lang = getRequestLanguage({
186
+ basePath: config.basePath,
187
+ currentRoute,
188
+ defaultLanguage,
189
+ languages,
190
+ });
191
+ const currentPageDoc = await getCurrentPageDoc({
192
+ basePath: config.basePath,
193
+ currentRoute,
194
+ lang,
195
+ pageContext,
196
+ sources: routeSources,
197
+ });
198
+ const relatedDocs = userQuestion.trim()
199
+ ? await searchDocs({
200
+ lang,
201
+ limit: MAX_PROXY_RELATED_PAGES,
202
+ query: userQuestion,
203
+ sources: routeSources,
204
+ })
205
+ : [];
206
+ const filteredRelatedDocs = relatedDocs.filter((doc) => doc.slug !== currentPageDoc?.slug);
207
+ const contextParts = [];
208
+ if (currentPageDoc) {
209
+ contextParts.push(`Here's the content from the current page:\n\n**Page:** ${currentPageDoc.title}\n**URL:** ${currentPageDoc.slug}\n\n---\n\n${currentPageDoc.content.slice(0, MAX_CONTEXT_CHARS)}${currentPageDoc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`);
210
+ }
211
+ if (filteredRelatedDocs.length > 0) {
212
+ contextParts.push(`Related documentation pages:\n\n${filteredRelatedDocs.map(formatDocForContext).join("\n\n---\n\n")}`);
213
+ }
214
+ if (contextParts.length === 0) {
215
+ return { messages: actualMessages, sourceDocs: [] };
216
+ }
217
+ return {
218
+ messages: [
219
+ ...actualMessages.slice(0, -1),
220
+ {
221
+ ...lastMessage,
222
+ parts: [
223
+ {
224
+ type: "text",
225
+ text: `${contextParts.join("\n\n---\n\n")}\n\n---\n\nUser question: ${userQuestion}`,
226
+ },
227
+ ],
228
+ },
229
+ ],
230
+ sourceDocs: [currentPageDoc, ...filteredRelatedDocs].filter((doc) => Boolean(doc)),
231
+ };
232
+ };
233
+ const resolveProxyHeaders = async (headers) => typeof headers === "function" ? await headers() : headers;
234
+ const getProxyRequestHeaders = async ({ proxy, req, }) => {
235
+ const headers = new Headers(await resolveProxyHeaders(proxy.headers));
236
+ const clientJa4 = req.headers.get("x-vercel-ja4-digest");
237
+ const clientIp = req.headers.get("x-forwarded-for");
238
+ headers.set("Content-Type", "application/json");
239
+ if (clientJa4 && !headers.has("x-client-ja4")) {
240
+ headers.set("x-client-ja4", clientJa4);
241
+ }
242
+ if (clientIp && !headers.has("x-client-ip")) {
243
+ headers.set("x-client-ip", clientIp);
244
+ }
245
+ return headers;
246
+ };
247
+ const parseSseChunk = (event) => {
248
+ const data = event
249
+ .split("\n")
250
+ .filter((line) => line.startsWith("data:"))
251
+ .map((line) => line.slice(5).trimStart())
252
+ .join("\n");
253
+ if (!data || data === "[DONE]") {
254
+ return null;
255
+ }
256
+ return JSON.parse(data);
257
+ };
258
+ const pipeUIMessageStreamToWriter = async ({ initialChunks, stream, writer, }) => {
259
+ const reader = stream.getReader();
260
+ const decoder = new TextDecoder();
261
+ let buffer = "";
262
+ let initialChunksWritten = false;
263
+ const writeInitialChunks = () => {
264
+ if (initialChunksWritten) {
265
+ return;
266
+ }
267
+ initialChunksWritten = true;
268
+ for (const chunk of initialChunks) {
269
+ writer.write(chunk);
270
+ }
271
+ };
272
+ const writeEvent = (event) => {
273
+ const chunk = parseSseChunk(event);
274
+ if (!chunk) {
275
+ return;
276
+ }
277
+ if (chunk.type === "start") {
278
+ writer.write(chunk);
279
+ writeInitialChunks();
280
+ return;
281
+ }
282
+ writeInitialChunks();
283
+ writer.write(chunk);
284
+ };
285
+ while (true) {
286
+ const { done, value } = await reader.read();
287
+ buffer += decoder.decode(value, { stream: !done }).replace(/\r\n/g, "\n");
288
+ let delimiterIndex = buffer.indexOf("\n\n");
289
+ while (delimiterIndex !== -1) {
290
+ const event = buffer.slice(0, delimiterIndex);
291
+ buffer = buffer.slice(delimiterIndex + 2);
292
+ writeEvent(event);
293
+ delimiterIndex = buffer.indexOf("\n\n");
294
+ }
295
+ if (done) {
296
+ break;
297
+ }
298
+ }
299
+ if (buffer.trim()) {
300
+ writeEvent(buffer);
301
+ }
302
+ writeInitialChunks();
303
+ };
5
304
  const createSystemPrompt = (currentRoute, config) => {
6
305
  const basePrompt = `# Role and objective
7
306
  You are a helpful assistant specializing in answering questions strictly. If information is unavailable, politely decline to answer. Your primary objective is to guide users through the happy path using the most relevant documentation or guides.
@@ -38,26 +337,6 @@ const createTools = (writer, sources, defaultLanguage) => {
38
337
  const log = (message) => {
39
338
  console.log(`[Geistdocs chat] ${message}`);
40
339
  };
41
- const createSearchServer = (lang) => {
42
- const indexes = sources.flatMap((source) => source.source
43
- .getPages(lang)
44
- .filter((page) => isPageVisibleForSurface(page, "chat"))
45
- .map((page) => {
46
- const data = page.data;
47
- const structuredData = data.structuredData ??
48
- { headings: [], contents: [] };
49
- return {
50
- title: data.title ?? page.url,
51
- description: data.description ?? "",
52
- url: page.url,
53
- id: page.url,
54
- structuredData,
55
- };
56
- }));
57
- return initAdvancedSearch({
58
- indexes,
59
- });
60
- };
61
340
  const search_docs = tool({
62
341
  description: "Search through documentation content by query",
63
342
  inputSchema: z.object({
@@ -71,41 +350,15 @@ const createTools = (writer, sources, defaultLanguage) => {
71
350
  execute: async ({ query, lang }) => {
72
351
  try {
73
352
  log(`Creating search server for language: ${lang}`);
74
- const searchServer = createSearchServer(lang);
75
- const results = await searchServer.search(query);
76
- if (results.length === 0) {
353
+ const trimmedResults = await searchDocs({
354
+ lang,
355
+ limit: MAX_TOOL_RESULTS,
356
+ query,
357
+ sources,
358
+ });
359
+ if (trimmedResults.length === 0) {
77
360
  return `No documentation found for query: "${query}"`;
78
361
  }
79
- const promiseResults = await Promise.all(results.map(({ url }) => {
80
- const result = sources
81
- .map((source) => ({
82
- result: source.source.getPageByHref(url, { language: lang }),
83
- source,
84
- }))
85
- .find(({ result }) => result?.page);
86
- if (!result?.result?.page) {
87
- return null;
88
- }
89
- const { page } = result.result;
90
- const data = page.data;
91
- return {
92
- title: data.title ?? page.url,
93
- description: data.description ?? "",
94
- content: JSON.stringify(data.structuredData?.contents ?? ""),
95
- slug: page.url,
96
- };
97
- }));
98
- const seenSlugs = new Set();
99
- const trimmedResults = promiseResults
100
- .filter((doc) => Boolean(doc))
101
- .filter((doc) => {
102
- if (!doc || seenSlugs.has(doc.slug)) {
103
- return false;
104
- }
105
- seenSlugs.add(doc.slug);
106
- return true;
107
- })
108
- .slice(0, 8);
109
362
  for (const [index, doc] of trimmedResults.entries()) {
110
363
  writer.write({
111
364
  type: "source-url",
@@ -115,7 +368,7 @@ const createTools = (writer, sources, defaultLanguage) => {
115
368
  });
116
369
  }
117
370
  const formattedResultsString = trimmedResults
118
- .map((doc) => `**${doc.title}**\nURL: ${doc.slug}\n${doc.description || ""}\n\n${doc.content.slice(0, 1500)}${doc.content.length > 1500 ? "..." : ""}\n\n---\n`)
371
+ .map((doc) => `${formatDocForContext(doc)}\n\n---\n`)
119
372
  .join("\n");
120
373
  return `Found ${trimmedResults.length} documentation pages for "${query}":\n\n${formattedResultsString}`;
121
374
  }
@@ -182,22 +435,55 @@ const resolveSources = (source, sources) => {
182
435
  }
183
436
  return resolvedSources;
184
437
  };
185
- export const createChatRoute = ({ config, source, sources, }) => {
186
- const defaultLanguage = config.defaultLanguage ?? "en";
438
+ export const createChatRoute = ({ config, proxy, source, sources, }) => {
439
+ const { defaultLanguage, languages } = getLanguages(config);
187
440
  const routeSources = resolveSources(source, sources);
188
441
  const POST = async (req) => {
189
442
  try {
190
443
  const { messages, currentRoute, pageContext } = await req.json();
191
- const actualMessages = messages.filter((message) => !message.metadata
192
- ?.isPageContext);
444
+ const actualMessages = messages.filter((message) => !isPageContextMessage(message));
445
+ if (proxy) {
446
+ const { messages: proxyMessages, sourceDocs } = await buildProxyMessages({
447
+ actualMessages,
448
+ config,
449
+ currentRoute,
450
+ defaultLanguage,
451
+ languages,
452
+ pageContext,
453
+ routeSources,
454
+ });
455
+ const stream = createUIMessageStream({
456
+ originalMessages: messages,
457
+ onError: () => "Something went wrong with your query.",
458
+ execute: async ({ writer }) => {
459
+ const response = await fetch(proxy.url, {
460
+ method: "POST",
461
+ body: JSON.stringify({
462
+ messages: proxyMessages,
463
+ platform: "vercel",
464
+ }),
465
+ headers: await getProxyRequestHeaders({ proxy, req }),
466
+ });
467
+ if (!response.ok) {
468
+ throw new Error(`Chat proxy returned ${response.status}: ${response.statusText}`);
469
+ }
470
+ if (!response.body) {
471
+ throw new Error("Chat proxy returned an empty response body");
472
+ }
473
+ await pipeUIMessageStreamToWriter({
474
+ initialChunks: createSourceChunks(sourceDocs),
475
+ stream: response.body,
476
+ writer,
477
+ });
478
+ },
479
+ });
480
+ return createUIMessageStreamResponse({ stream });
481
+ }
193
482
  let processedMessages = actualMessages;
194
483
  if (pageContext && actualMessages.length > 0) {
195
484
  const lastMessage = actualMessages.at(-1);
196
485
  if (lastMessage?.role === "user") {
197
- const userQuestion = lastMessage.parts
198
- .filter((part) => part.type === "text")
199
- .map((part) => part.text)
200
- .join("\n");
486
+ const userQuestion = getMessageText(lastMessage);
201
487
  processedMessages = [
202
488
  ...actualMessages.slice(0, -1),
203
489
  {
@@ -220,7 +506,7 @@ export const createChatRoute = ({ config, source, sources, }) => {
220
506
  messages: convertToModelMessages(processedMessages),
221
507
  stopWhen: stepCountIs(10),
222
508
  tools: createTools(writer, routeSources, defaultLanguage),
223
- system: createSystemPrompt(currentRoute, config),
509
+ system: createSystemPrompt(currentRoute ?? "/", config),
224
510
  prepareStep: ({ stepNumber }) => {
225
511
  if (stepNumber === 0) {
226
512
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vercel/geistdocs",
3
3
  "description": "Runtime and CLI for Geistdocs projects.",
4
- "version": "1.2.3-canary.1d733b2",
4
+ "version": "1.2.3-canary.53ff3db",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/vercel/geistdocs",
@@ -101,10 +101,22 @@
101
101
  "types": "./dist/shiki-theme.d.ts",
102
102
  "default": "./dist/shiki-theme.js"
103
103
  },
104
+ "./components/button": {
105
+ "types": "./dist/components/button.d.ts",
106
+ "default": "./dist/components/button.js"
107
+ },
108
+ "./components/button-group": {
109
+ "types": "./dist/components/button-group.d.ts",
110
+ "default": "./dist/components/button-group.js"
111
+ },
104
112
  "./components/callout": {
105
113
  "types": "./dist/components/callout.d.ts",
106
114
  "default": "./dist/components/callout.js"
107
115
  },
116
+ "./components/card": {
117
+ "types": "./dist/components/card.d.ts",
118
+ "default": "./dist/components/card.js"
119
+ },
108
120
  "./components/code-block": {
109
121
  "types": "./dist/components/code-block.d.ts",
110
122
  "default": "./dist/components/code-block.js"
@@ -113,10 +125,38 @@
113
125
  "types": "./dist/components/code-block-tabs.d.ts",
114
126
  "default": "./dist/components/code-block-tabs.js"
115
127
  },
128
+ "./components/collapsible": {
129
+ "types": "./dist/components/collapsible.d.ts",
130
+ "default": "./dist/components/collapsible.js"
131
+ },
116
132
  "./components/copy-prompt": {
117
133
  "types": "./dist/components/copy-prompt.d.ts",
118
134
  "default": "./dist/components/copy-prompt.js"
119
135
  },
136
+ "./components/dialog": {
137
+ "types": "./dist/components/dialog.d.ts",
138
+ "default": "./dist/components/dialog.js"
139
+ },
140
+ "./components/drawer": {
141
+ "types": "./dist/components/drawer.d.ts",
142
+ "default": "./dist/components/drawer.js"
143
+ },
144
+ "./components/dropdown-menu": {
145
+ "types": "./dist/components/dropdown-menu.d.ts",
146
+ "default": "./dist/components/dropdown-menu.js"
147
+ },
148
+ "./components/input": {
149
+ "types": "./dist/components/input.d.ts",
150
+ "default": "./dist/components/input.js"
151
+ },
152
+ "./components/input-group": {
153
+ "types": "./dist/components/input-group.d.ts",
154
+ "default": "./dist/components/input-group.js"
155
+ },
156
+ "./components/kbd": {
157
+ "types": "./dist/components/kbd.d.ts",
158
+ "default": "./dist/components/kbd.js"
159
+ },
120
160
  "./components/theme-aware-image": {
121
161
  "types": "./dist/components/theme-aware-image.d.ts",
122
162
  "default": "./dist/components/theme-aware-image.js"
@@ -125,6 +165,42 @@
125
165
  "types": "./dist/components/mermaid.d.ts",
126
166
  "default": "./dist/components/mermaid.js"
127
167
  },
168
+ "./components/navigation-menu": {
169
+ "types": "./dist/components/navigation-menu.d.ts",
170
+ "default": "./dist/components/navigation-menu.js"
171
+ },
172
+ "./components/popover": {
173
+ "types": "./dist/components/popover.d.ts",
174
+ "default": "./dist/components/popover.js"
175
+ },
176
+ "./components/scroll-area": {
177
+ "types": "./dist/components/scroll-area.d.ts",
178
+ "default": "./dist/components/scroll-area.js"
179
+ },
180
+ "./components/separator": {
181
+ "types": "./dist/components/separator.d.ts",
182
+ "default": "./dist/components/separator.js"
183
+ },
184
+ "./components/sheet": {
185
+ "types": "./dist/components/sheet.d.ts",
186
+ "default": "./dist/components/sheet.js"
187
+ },
188
+ "./components/sonner": {
189
+ "types": "./dist/components/sonner.d.ts",
190
+ "default": "./dist/components/sonner.js"
191
+ },
192
+ "./components/spinner": {
193
+ "types": "./dist/components/spinner.d.ts",
194
+ "default": "./dist/components/spinner.js"
195
+ },
196
+ "./components/textarea": {
197
+ "types": "./dist/components/textarea.d.ts",
198
+ "default": "./dist/components/textarea.js"
199
+ },
200
+ "./components/tooltip": {
201
+ "types": "./dist/components/tooltip.d.ts",
202
+ "default": "./dist/components/tooltip.js"
203
+ },
128
204
  "./components/video": {
129
205
  "types": "./dist/components/video.d.ts",
130
206
  "default": "./dist/components/video.js"
@@ -49,6 +49,14 @@ Use these instructions when an AI coding agent edits this project.
49
49
  - When adding custom proxy behavior, prefer `before`, `after`, and `markdownRoutes` options on `createProxy` instead of replacing the proxy.
50
50
  - Use explicit `markdownRoutes` for root-mounted docs or any site where homepage/app routes coexist with docs routes.
51
51
 
52
+ ## Ask AI and Vertex proxy guidelines
53
+
54
+ - Leave `GEISTDOCS_CHAT_PROXY_URL` unset to use the default AI Gateway path. In that mode, `app/api/chat/route.ts` calls `createChatRoute` without a `proxy` option and uses the local docs search tool during the AI SDK `streamText` loop.
55
+ - Set `GEISTDOCS_CHAT_PROXY_URL` only when Ask AI should route through the central Vertex-backed proxy. The value must include the `/vertex` route, such as `https://<geistdocs-platform-deployment>/vertex`.
56
+ - Do not add Vertex credentials to a Geistdocs site. The central platform proxy forwards the Vercel OIDC token in `x-vercel-trusted-oidc-idp-token`; the Vertex deployment should trust the platform Vercel project through Deployment Protection Trusted Sources.
57
+ - Use `GEISTDOCS_CHAT_PROXY_TOKEN` only for a custom proxy that requires bearer authentication. The default Geistdocs platform `/vertex` proxy does not require it.
58
+ - Keep `app/api/chat/route.ts` as a thin adapter around `createChatRoute`. Prefer configuring `GEISTDOCS_CHAT_PROXY_URL` and `GEISTDOCS_CHAT_PROXY_TOKEN` over forking the package chat route.
59
+
52
60
  ## Migration guidelines
53
61
 
54
62
  - When migrating from Fumadocs or a custom Geist docs site, inventory `source.config.ts`, route files, `middleware.ts` or `proxy.ts`, `public/llms.txt`, OG routes, Tailwind CSS setup, and required environment variables before editing.
@@ -2,7 +2,18 @@ import { createChatRoute } from "@vercel/geistdocs/routes/chat";
2
2
  import { config } from "@/lib/geistdocs/config";
3
3
  import { geistdocsSource } from "@/lib/geistdocs/source";
4
4
 
5
+ const chatProxyUrl = process.env.GEISTDOCS_CHAT_PROXY_URL;
6
+ const chatProxyToken = process.env.GEISTDOCS_CHAT_PROXY_TOKEN;
7
+
5
8
  export const { POST, maxDuration } = createChatRoute({
6
9
  config,
10
+ proxy: chatProxyUrl
11
+ ? {
12
+ url: chatProxyUrl,
13
+ headers: chatProxyToken
14
+ ? { Authorization: `Bearer ${chatProxyToken}` }
15
+ : undefined,
16
+ }
17
+ : undefined,
7
18
  sources: [geistdocsSource],
8
19
  });
@@ -43,17 +43,51 @@ Once open, users can:
43
43
  - View AI-powered search results from your docs
44
44
  - Get step-by-step guidance on complex topics
45
45
 
46
+ ## Choose an AI mode
47
+
48
+ Ask AI can run in the default AI Gateway mode or through a Vertex-backed proxy.
49
+
50
+ ### Default AI Gateway mode
51
+
52
+ Use the default mode when the Geistdocs site should call the Vercel AI Gateway directly.
53
+
54
+ 1. Leave `GEISTDOCS_CHAT_PROXY_URL` unset.
55
+ 2. Set `AI_GATEWAY_API_KEY` for local development. Vercel sets this automatically for deployments that have AI Gateway access.
56
+ 3. Keep `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` set to the site's production host, such as `docs.example.com` or `localhost:3000` for local development.
57
+
58
+ In this mode, Geistdocs uses the local `search_docs` tool during the AI SDK `streamText` loop.
59
+
60
+ ### Vertex-backed proxy mode
61
+
62
+ Use proxy mode when Ask AI should route model requests through a central Vertex-backed service instead of calling AI Gateway from each site.
63
+
64
+ 1. Deploy or use the central Geistdocs platform proxy that exposes `POST /vertex`.
65
+ 2. Configure the Vertex deployment to trust the Geistdocs platform Vercel project with Deployment Protection Trusted Sources.
66
+ 3. Set `GEISTDOCS_CHAT_PROXY_URL` on the Geistdocs site to the platform proxy URL, including `/vertex`:
67
+
68
+ ```txt
69
+ https://<geistdocs-platform-deployment>/vertex
70
+ ```
71
+
72
+ 4. Leave `GEISTDOCS_CHAT_PROXY_TOKEN` unset unless you are using a custom proxy that requires bearer authentication.
73
+
74
+ When `GEISTDOCS_CHAT_PROXY_URL` is set, Geistdocs searches local docs on the first user message, injects the current page and related docs into the final user message, forwards `{ messages, platform: "vercel" }` to the proxy, and streams the AI SDK UI stream response back to the browser.
75
+
76
+ The platform proxy forwards a Vercel OIDC token to Vertex in the `x-vercel-trusted-oidc-idp-token` header. The Vertex deployment should validate the caller through Trusted Sources; the Geistdocs site does not need a Vertex API key.
77
+
46
78
  ## Features
47
79
 
48
80
  ### Context-Aware Search
49
81
 
50
- The AI assistant includes a built-in `search_docs` tool that:
82
+ By default, the AI assistant includes a built-in `search_docs` tool that:
51
83
 
52
84
  1. Searches through your documentation content
53
85
  2. Finds relevant pages based on the user's question
54
86
  3. Shows source citations with links to the referenced pages
55
87
  4. Uses the content to provide accurate, contextual answers
56
88
 
89
+ When `GEISTDOCS_CHAT_PROXY_URL` is set, Geistdocs runs local documentation retrieval on the first user message before forwarding the request to the configured proxy. This gives proxy-backed services access to the current page and related local documentation without requiring them to read the site's source files directly.
90
+
57
91
  ### Persistent Chat History
58
92
 
59
93
  Conversations are automatically saved to the browser's IndexedDB, providing:
@@ -80,9 +114,9 @@ The chat interface adapts to different screen sizes:
80
114
 
81
115
  ## Configuration
82
116
 
83
- The environment variables `AI_GATEWAY_API_KEY` and `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` must be set, which you can read more about in the [Environment Variables](/docs/env) section.
117
+ The environment variables `AI_GATEWAY_API_KEY` and `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` must be set for the default AI Gateway mode. Set `GEISTDOCS_CHAT_PROXY_URL` to route Ask AI through a Vertex-backed proxy instead. You can read more in the [Environment Variables](/docs/env) section.
84
118
 
85
- The model used is `openai/gpt-4.1-mini` via the Vercel AI Gateway.
119
+ In default AI Gateway mode, Geistdocs uses `openai/gpt-4.1-mini` via the Vercel AI Gateway. In Vertex-backed proxy mode, the configured proxy controls the upstream model.
86
120
 
87
121
  ## Suggested Prompts
88
122
 
@@ -38,3 +38,14 @@ To deploy from the Vercel dashboard:
38
38
  - **Install Command**: `pnpm install` or `npm install`
39
39
  4. Add your environment variables (see [Environment Variables](/docs/env))
40
40
  5. Click "Deploy"
41
+
42
+ ## Deploy with Vertex-backed Ask AI
43
+
44
+ If your site routes Ask AI through the central Vertex-backed proxy, configure both the Geistdocs site and the Vertex deployment before testing production chat.
45
+
46
+ 1. Set `GEISTDOCS_CHAT_PROXY_URL` on the Geistdocs site to the platform proxy URL, including `/vertex`.
47
+ 2. Leave `GEISTDOCS_CHAT_PROXY_TOKEN` unset unless your proxy requires bearer authentication.
48
+ 3. Add the Geistdocs platform Vercel project as a Trusted Source in the Vertex deployment's Deployment Protection settings.
49
+ 4. Confirm the platform proxy can forward the Vercel OIDC token to Vertex in `x-vercel-trusted-oidc-idp-token`.
50
+
51
+ The Geistdocs site does not need Vertex credentials. The platform proxy authenticates to Vertex with Vercel OIDC and Trusted Sources.
@@ -2,7 +2,7 @@
2
2
  title: Environment Variables
3
3
  description: Learn about the environment variables used in Geistdocs
4
4
  type: reference
5
- summary: Environment variables required by Geistdocs for AI chat and production URL configuration.
5
+ summary: Environment variables required by Geistdocs for AI chat, proxy mode, and production URL configuration.
6
6
  prerequisites:
7
7
  - /docs/getting-started
8
8
  related:
@@ -10,18 +10,49 @@ related:
10
10
  - /docs/deployment
11
11
  ---
12
12
 
13
- Geistdocs has functionality that requires specific environment variables to be set.
13
+ Geistdocs uses environment variables to configure Ask AI, optional Vertex-backed proxy mode, and production URL behavior.
14
14
 
15
- <CopyPrompt text="Review this Geistdocs project and help me configure the required environment variables. Check whether AI_GATEWAY_API_KEY and NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL are needed for the features I enabled, then tell me where to set them locally and on Vercel.">
16
- Review this Geistdocs project and help me configure the required environment variables. Check whether `AI_GATEWAY_API_KEY` and `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` are needed for the features I enabled, then tell me where to set them locally and on Vercel.
15
+ <CopyPrompt text="Review this Geistdocs project and help me configure the required environment variables. Check whether AI_GATEWAY_API_KEY, GEISTDOCS_CHAT_PROXY_URL, and NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL are needed for the features I enabled, then tell me where to set them locally and on Vercel.">
16
+ Review this Geistdocs project and help me configure the required environment variables. Check whether `AI_GATEWAY_API_KEY`, `GEISTDOCS_CHAT_PROXY_URL`, and `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL` are needed for the features I enabled, then tell me where to set them locally and on Vercel.
17
17
  </CopyPrompt>
18
18
 
19
19
  ## `AI_GATEWAY_API_KEY`
20
20
 
21
- The API key for the AI gateway. This is used to power the AI chat functionality.
21
+ The API key for the AI Gateway. This is used to power the default local AI chat functionality when `GEISTDOCS_CHAT_PROXY_URL` is not set.
22
22
 
23
23
  <Callout>This is automatically set when deploying to Vercel.</Callout>
24
24
 
25
+ Leave `GEISTDOCS_CHAT_PROXY_URL` unset to use AI Gateway mode.
26
+
27
+ ## `GEISTDOCS_CHAT_PROXY_URL`
28
+
29
+ An optional URL for a chat proxy. When set, Geistdocs searches the local documentation on the first user message, injects the current page and related docs as context, and forwards the request to this proxy.
30
+
31
+ Use this when routing Ask AI through a central Vertex-backed service. The value should point at the Geistdocs platform proxy and include `/vertex`:
32
+
33
+ ```txt
34
+ https://<geistdocs-platform-deployment>/vertex
35
+ ```
36
+
37
+ When this variable is set, the site does not need `AI_GATEWAY_API_KEY` for Ask AI requests. The platform proxy calls Vertex and forwards a Vercel OIDC token in `x-vercel-trusted-oidc-idp-token` so the Vertex deployment can validate the caller through Deployment Protection Trusted Sources.
38
+
39
+ ## `GEISTDOCS_CHAT_PROXY_TOKEN`
40
+
41
+ An optional bearer token for the chat proxy. Only set this if your proxy requires an `Authorization` header.
42
+
43
+ The default Geistdocs platform `/vertex` proxy uses Vercel OIDC and Trusted Sources, so it does not require this token.
44
+
45
+ ## Vertex-backed proxy setup
46
+
47
+ To route Ask AI through Vertex:
48
+
49
+ 1. Use or deploy the central Geistdocs platform proxy with its `/vertex` route.
50
+ 2. In the Vertex deployment's Deployment Protection settings, add the Geistdocs platform Vercel project as a Trusted Source.
51
+ 3. In each Geistdocs site that should use Vertex, set `GEISTDOCS_CHAT_PROXY_URL` to the platform proxy URL, including `/vertex`.
52
+ 4. Leave `GEISTDOCS_CHAT_PROXY_TOKEN` unset unless you replace the platform proxy with a custom bearer-authenticated proxy.
53
+
54
+ The Vertex deployment does not need a Geistdocs-specific environment variable. Access is controlled by Trusted Sources and the OIDC token forwarded by the platform proxy.
55
+
25
56
  ## `NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL`
26
57
 
27
58
  The production URL of the Geistdocs site. This is automatically set when deploying to Vercel.
@@ -14,7 +14,7 @@
14
14
  "@ai-sdk/react": "^2.0.115",
15
15
  "@icons-pack/react-simple-icons": "^13.8.0",
16
16
  "@orama/tokenizers": "^3.1.16",
17
- "@vercel/geistdocs": "1.2.3-canary.1d733b2",
17
+ "@vercel/geistdocs": "1.2.3-canary.53ff3db",
18
18
  "@streamdown/cjk": "^1.0.1",
19
19
  "@streamdown/code": "^1.0.1",
20
20
  "@vercel/agent-readability": "^0.2.1",