@vercel/geistdocs 1.25.1-canary.47f1ad5 → 1.25.1-canary.498144e
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/components/callout.d.ts.map +1 -1
- package/dist/components/callout.js +1 -1
- package/dist/components/code-block-tabs.js +1 -1
- package/dist/components/code-block.d.ts.map +1 -1
- package/dist/components/code-block.js +1 -1
- package/dist/components/copy-prompt.js +1 -1
- package/dist/components/image.d.ts +19 -0
- package/dist/components/image.d.ts.map +1 -0
- package/dist/components/image.js +9 -0
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +3 -2
- package/dist/internal/chat/activity.d.ts +20 -0
- package/dist/internal/chat/activity.d.ts.map +1 -0
- package/dist/internal/chat/activity.js +43 -0
- package/dist/internal/chat/context.d.ts +2 -0
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +24 -3
- package/dist/internal/chat/loading-skeleton.d.ts +7 -0
- package/dist/internal/chat/loading-skeleton.d.ts.map +1 -0
- package/dist/internal/chat/loading-skeleton.js +46 -0
- package/dist/internal/chat/message-metadata.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.js +15 -30
- package/dist/internal/chat/message-sources.d.ts +3 -0
- package/dist/internal/chat/message-sources.d.ts.map +1 -0
- package/dist/internal/chat/message-sources.js +23 -0
- package/dist/internal/chat/message.d.ts.map +1 -1
- package/dist/internal/chat/message.js +59 -5
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +16 -16
- package/dist/internal/chat/source-chunks.d.ts +9 -0
- package/dist/internal/chat/source-chunks.d.ts.map +1 -0
- package/dist/internal/chat/source-chunks.js +7 -0
- package/dist/internal/chat/sources.d.ts +1 -1
- package/dist/internal/chat/sources.d.ts.map +1 -1
- package/dist/internal/chat/sources.js +7 -1
- package/dist/internal/link-href.d.ts +13 -0
- package/dist/internal/link-href.d.ts.map +1 -0
- package/dist/internal/link-href.js +51 -0
- package/dist/internal/mousedown-navigation-utils.d.ts +5 -0
- package/dist/internal/mousedown-navigation-utils.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation-utils.js +95 -0
- package/dist/internal/mousedown-navigation.d.ts +10 -0
- package/dist/internal/mousedown-navigation.d.ts.map +1 -0
- package/dist/internal/mousedown-navigation.js +42 -0
- package/dist/internal/navbar/navbar-shell.d.ts.map +1 -1
- package/dist/internal/navbar/navbar-shell.js +2 -1
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +4 -21
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +28 -4
- package/dist/internal/search.js +1 -1
- package/dist/internal/sidebar-tree.d.ts.map +1 -1
- package/dist/internal/sidebar-tree.js +6 -1
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +15 -14
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mdx.js +4 -4
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +17 -9
- package/dist/routes/chat.d.ts +1 -1
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +31 -14
- package/dist/routes/llms.d.ts +1 -1
- package/dist/routes/llms.d.ts.map +1 -1
- package/dist/routes/llms.js +12 -2
- package/dist/source.d.ts +6 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +1 -0
- package/dist/versions.js +2 -2
- package/docs/agents.md +4 -3
- package/docs/llms.txt +260 -31
- package/docs/manifest.json +12 -3
- package/docs/pages/ask-ai.md +2 -2
- package/docs/pages/deployment.md +30 -5
- package/docs/pages/getting-started.md +38 -12
- package/docs/pages/guides/nested-navigation.md +1 -1
- package/docs/pages/md.md +1 -1
- package/docs/pages/migration-2.md +106 -0
- package/docs/pages/migration.md +5 -2
- package/docs/pages/syntax.md +69 -5
- package/docs/sitemap.md +3 -2
- package/package.json +8 -5
- package/template/content/docs/ask-ai.cn.mdx +2 -2
- package/template/content/docs/ask-ai.mdx +2 -2
- package/template/content/docs/deployment.mdx +31 -6
- package/template/content/docs/getting-started.mdx +39 -13
- package/template/content/docs/guides/nested-navigation.mdx +1 -1
- package/template/content/docs/md.mdx +1 -1
- package/template/content/docs/meta.json +1 -0
- package/template/content/docs/migration-2.mdx +106 -0
- package/template/content/docs/migration.mdx +5 -1
- package/template/content/docs/syntax.mdx +70 -5
- package/template/next.config.ts +9 -0
- package/template/package.json +4 -4
- package/theme.css +0 -4
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.25.1-canary.47f1ad5","-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.25.1-canary.498144e","-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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9E,UAAU,qBAAsB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,
|
|
1
|
+
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/components/callout.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9E,UAAU,qBAAsB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG;IACzD,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,4CASlE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,sDAM9B,qBAAqB,4CAcvB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,yBAAyB,cAAc,CAAC,GAAG,CAAC,4CAExE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,yBAGhC,cAAc,CAAC,KAAK,CAAC,4CAEvB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from "@vercel/geistcn/utils";
|
|
3
3
|
import { IconInformation } from "@vercel/geistcn-assets/icons";
|
|
4
|
-
export const Callout = ({ children, title, ...props }) => (_jsxs(CalloutContainer, { ...props, children: [title ? _jsx(CalloutTitle, { children: title }) : null, _jsx(CalloutDescription, { children: children })] }));
|
|
4
|
+
export const Callout = ({ children, title, ...props }) => (_jsxs(CalloutContainer, { ...props, children: [title ? _jsx(CalloutTitle, { children: title }) : null, _jsx(CalloutDescription, { className: title ? "[&:has(>p:first-child)]:mt-[7px]" : undefined, children: children })] }));
|
|
5
5
|
export const CalloutContainer = ({ children, className, icon, type: _type, ...props }) => (_jsxs("div", { className: cn("my-4 flex items-start justify-start gap-3 rounded-[6px] bg-gray-100 px-4 py-3 font-normal text-copy-14 **:leading-[150%] [&_code]:text-[12px]!", "[&_ul]:list-none [&_ul]:pl-0! [&_ul_li]:relative [&_ul_li]:pl-6! [&_ul_li]:before:absolute [&_ul_li]:before:top-[0.6em] [&_ul_li]:before:left-0 [&_ul_li]:before:size-[5px] [&_ul_li]:before:rounded-full [&_ul_li]:before:bg-gray-600 [&_ul_li]:before:content-['']", className), ...props, children: [icon ?? (_jsx(IconInformation, { className: "mt-0.5 size-4 flex-none", color: "gray-900" })), _jsx("div", { className: "min-w-0 flex-1", children: children })] }));
|
|
6
6
|
export const CalloutTitle = ({ className, ...props }) => (_jsx("p", { className: cn("my-0! font-medium", className), ...props }));
|
|
7
7
|
export const CalloutDescription = ({ className, ...props }) => (_jsx("div", { className: cn("prose-no-margin", className), ...props }));
|
|
@@ -26,7 +26,7 @@ export const CodeBlockTabs = ({ compact = false, ...props }) => {
|
|
|
26
26
|
}
|
|
27
27
|
const selectedLabel = options.find((option) => option.value === value)?.label ??
|
|
28
28
|
options[0]?.label;
|
|
29
|
-
return (_jsxs("div", { className: "relative [&_[role=tablist]]:hidden", children: [_jsxs("div", { className: "group absolute top-
|
|
29
|
+
return (_jsxs("div", { className: "not-prose relative [&_[role=tablist]]:hidden", children: [_jsxs("div", { className: "group absolute top-1.5 right-12 z-2 h-7", children: [_jsxs("div", { "aria-hidden": "true", className: "flex h-full cursor-pointer items-center gap-1 whitespace-nowrap rounded-md border-none bg-background-200 px-2 py-0 font-sans text-gray-900 text-label-13 leading-none transition-colors duration-200 group-focus-within:shadow-[var(--ds-focus-ring)] group-hover:bg-gray-200", children: [_jsx("span", { children: selectedLabel }), _jsx(IconChevronDown, { size: 16 })] }), _jsx("select", { "aria-label": "Code language", className: "absolute inset-0 cursor-pointer bg-gray-100 opacity-0 outline-hidden", onChange: (event) => setValue(event.target.value), value: value, children: options.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] }), tabs] }));
|
|
30
30
|
};
|
|
31
31
|
export const CompactCodeBlockTabs = (props) => _jsx(CodeBlockTabs, { ...props, compact: true });
|
|
32
32
|
export const CodeBlockTab = (props) => (_jsx(TabsContent, { ...props, className: cn("[&>div]:mb-0", props.className) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/components/code-block.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,UAAU,cAAc;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuBD,eAAO,MAAM,SAAS,GAAI,mEAKvB,cAAc,
|
|
1
|
+
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/components/code-block.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,UAAU,cAAc;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuBD,eAAO,MAAM,SAAS,GAAI,mEAKvB,cAAc,4CA0ChB,CAAC"}
|
|
@@ -25,5 +25,5 @@ export const CodeBlock = ({ children, className, "data-line-numbers": lineNumber
|
|
|
25
25
|
const code = isValidElement(children)
|
|
26
26
|
? children.props.children
|
|
27
27
|
: children;
|
|
28
|
-
return (_jsx(CodeBlockServer, { className: cn("[&_code]:min-w-full [&_code]:border-0 [&_code]:bg-transparent [&_code]:p-0", "[&_:is(.line,.highlighted-line)]:relative [&_:is(.line,.highlighted-line)]:inline-block [&_:is(.line,.highlighted-line)]:h-5 [&_:is(.line,.highlighted-line)]:w-max [&_:is(.line,.highlighted-line)]:min-w-full [&_:is(.line,.highlighted-line)]:px-5!", "[&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:border-l-0! [&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:bg-blue-300! [&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:shadow-[inset_2px_0_0_0_var(--ds-blue-900)]", "[&_.line[data-active=true]]:bg-amber-300! [&_.line[data-active=true]]:shadow-[inset_2px_0_0_0_var(--ds-amber-900)]", "[&_:is([data-added=true],.line.diff.add)]:bg-green-300! [&_:is([data-added=true],.line.diff.add)]:shadow-[inset_2px_0_0_0_var(--ds-green-900)]", "[&_:is([data-removed=true],.line.diff.remove)]:bg-red-300! [&_:is([data-removed=true],.line.diff.remove)]:opacity-100! [&_:is([data-removed=true],.line.diff.remove)]:shadow-[inset_2px_0_0_0_var(--ds-red-900)]", "[&_:is(.line.diff.add,.line.diff.remove)::before]:content-none!", "[&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:pointer-events-none [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:absolute [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:inset-0 [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:pl-2 [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:font-medium", "[&_:is([data-added=true],.line.diff.add)::after]:text-green-900 [&_:is([data-added=true],.line.diff.add)::after]:content-['+']", "[&_:is([data-removed=true],.line.diff.remove)::after]:text-red-900 [&_:is([data-removed=true],.line.diff.remove)::after]:content-['-']", lineNumbers !== undefined && "line-numbers", frameworkTitle && "[&_[data-section=tabs]>div:first-child]:hidden", className), filename: frameworkTitle?.title ?? title, headerActions: frameworkTitle ? (_jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 text-gray-900 text-label-13", children: [_jsx("span", { className: "flex w-4 shrink-0 items-center", children: frameworkTitle.icon }), _jsx("span", { className: "truncate", children: frameworkTitle.title })] })) : undefined, hideLineNumbers: lineNumbers === undefined, children: code }));
|
|
28
|
+
return (_jsx(CodeBlockServer, { className: cn("not-prose", "[&_code]:min-w-full [&_code]:border-0 [&_code]:bg-transparent [&_code]:p-0", "[&>[data-section=tabs]]:h-(--ds-size-large)! [&>[data-section=tabs]]:pr-[5px]!", "[&>[data-section=tabs]_button[aria-label^=Copy]]:size-7!", "[&_:is(.line,.highlighted-line)]:relative [&_:is(.line,.highlighted-line)]:inline-block [&_:is(.line,.highlighted-line)]:h-5 [&_:is(.line,.highlighted-line)]:w-max [&_:is(.line,.highlighted-line)]:min-w-full [&_:is(.line,.highlighted-line)]:px-5!", "[&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:border-l-0! [&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:bg-blue-300! [&_:is(.highlighted-line,.line.highlighted,[data-highlighted=true])]:shadow-[inset_2px_0_0_0_var(--ds-blue-900)]", "[&_.line[data-active=true]]:bg-amber-300! [&_.line[data-active=true]]:shadow-[inset_2px_0_0_0_var(--ds-amber-900)]", "[&_:is([data-added=true],.line.diff.add)]:bg-green-300! [&_:is([data-added=true],.line.diff.add)]:shadow-[inset_2px_0_0_0_var(--ds-green-900)]", "[&_:is([data-removed=true],.line.diff.remove)]:bg-red-300! [&_:is([data-removed=true],.line.diff.remove)]:opacity-100! [&_:is([data-removed=true],.line.diff.remove)]:shadow-[inset_2px_0_0_0_var(--ds-red-900)]", "[&_:is(.line.diff.add,.line.diff.remove)::before]:content-none!", "[&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:pointer-events-none [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:absolute [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:inset-0 [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:pl-2 [&_:is([data-added=true],[data-removed=true],.line.diff.add,.line.diff.remove)::after]:font-medium", "[&_:is([data-added=true],.line.diff.add)::after]:text-green-900 [&_:is([data-added=true],.line.diff.add)::after]:content-['+']", "[&_:is([data-removed=true],.line.diff.remove)::after]:text-red-900 [&_:is([data-removed=true],.line.diff.remove)::after]:content-['-']", lineNumbers !== undefined && "line-numbers", frameworkTitle && "[&_[data-section=tabs]>div:first-child]:hidden", className), filename: frameworkTitle?.title ?? title, headerActions: frameworkTitle ? (_jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 text-gray-900 text-label-13", children: [_jsx("span", { className: "flex w-4 shrink-0 items-center", children: frameworkTitle.icon }), _jsx("span", { className: "truncate", children: frameworkTitle.title })] })) : undefined, hideLineNumbers: lineNumbers === undefined, children: code }));
|
|
29
29
|
};
|
|
@@ -49,7 +49,7 @@ export const CopyPrompt = ({ children, className, collapsible = false, projectOn
|
|
|
49
49
|
]),
|
|
50
50
|
{ icon: _jsx(CursorLogo, {}), label: "Open in Cursor", platform: "Cursor" },
|
|
51
51
|
];
|
|
52
|
-
return (_jsx("div", { className: cn("not-prose my-4 mb-10 hidden w-full md:block", className), children: _jsxs("div", { className: "rounded-md border border-gray-400 bg-background-100", children: [_jsx("div", { className: "
|
|
52
|
+
return (_jsx("div", { className: cn("not-prose my-4 mb-10 hidden w-full md:block", className), children: _jsxs("div", { className: "rounded-md border border-gray-400 bg-background-100", children: [_jsx("div", { className: "flex h-(--ds-size-large) items-center rounded-t-md border-gray-400 border-b bg-background-200 py-0 pr-[5px] pl-4", children: _jsxs("div", { className: "flex w-full items-center justify-between gap-4", children: [_jsx("div", { className: "flex items-center gap-2 text-gray-900 text-label-13", children: title }), _jsxs("div", { className: "inline-flex shrink-0 overflow-hidden rounded-md border border-gray-400 bg-background-100", children: [_jsxs("button", { className: "inline-flex h-7 items-center gap-1.5 px-3 font-medium text-sm transition-colors hover:bg-gray-100 hover:text-gray-1000 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-gray-600/50", onClick: copy, type: "button", children: [_jsxs("span", { className: "relative size-4", children: [_jsx(CopyPromptIcon, { className: cn("absolute inset-0 transition-[transform,opacity] duration-200", isCopied ? "scale-75 opacity-0" : "scale-100 opacity-100") }), _jsx(IconCheck, { className: cn("absolute inset-0 size-4 transition-[transform,opacity] duration-200", isCopied ? "scale-100 opacity-100" : "scale-75 opacity-0") })] }), _jsx("span", { children: "Copy" })] }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { "aria-label": "Copy prompt actions", className: "inline-flex size-7 items-center justify-center border-gray-400 border-l transition-colors hover:bg-gray-100 hover:text-gray-1000 focus-visible:shadow-[inset_0_0_0_2px_var(--ds-focus-color)] focus-visible:outline-none", type: "button", children: _jsx(IconChevronDown, { className: "size-4" }) }) }), _jsx(DropdownMenuContent, { align: "end", className: "w-60", children: menuItems.map((item, index) => (_jsxs("div", { children: [index === 1 ? _jsx(DropdownMenuSeparator, {}) : null, _jsxs(DropdownMenuItem, { onClick: () => openPlatform(item.platform), children: [item.icon, _jsx("span", { className: "flex-1", children: item.label }), _jsx(IconExternal, { className: "size-4" })] })] }, item.platform))) })] })] })] }) }), _jsxs("div", { className: "relative isolate rounded-b-md bg-background-100 p-4 pb-5", children: [_jsxs("div", { className: "relative overflow-hidden", children: [_jsx("div", { className: cn("break-words text-gray-900 text-sm leading-relaxed [&_a]:font-normal [&_a]:text-gray-1000 [&_a]:no-underline hover:[&_a]:underline [&_code]:rounded [&_code]:bg-gray-100 [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.9em]", collapsible && !isExpanded ? "line-clamp-2" : ""), children: children ?? text }), collapsible && !isExpanded ? (_jsx("div", { className: "pointer-events-none absolute inset-0 bg-linear-to-b from-transparent via-transparent to-background-100" })) : null] }), collapsible ? (_jsx("div", { className: "absolute left-1/2 -translate-x-1/2 translate-y-1/5", children: _jsxs(Button, { className: "mt-0 h-7 rounded-full bg-background-100 px-2 text-gray-900 text-xs shadow-(--ds-shadow-border-medium) hover:text-gray-1000 [&>span]:inline-flex [&>span]:items-center [&>span]:gap-1", onClick: () => setIsExpanded((current) => !current), size: "small", typeName: "button", variant: "secondary", children: [isExpanded ? (_jsx(IconChevronUp, { className: "size-3.5" })) : (_jsx(IconChevronDown, { className: "size-3.5" })), isExpanded ? "Show less" : "Show more"] }) })) : null] })] }) }));
|
|
53
53
|
};
|
|
54
54
|
const CopyPromptIcon = ({ className }) => (_jsxs("svg", { "aria-hidden": true, className: className, fill: "none", height: "16", viewBox: "0 0 16 16", width: "16", children: [_jsx("title", { children: "Copy prompt" }), _jsx("path", { d: "M6.75 14a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m3.75 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m3.75 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m-7.5-3.25a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m7.5 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5M8.25.5C9.22.5 10 1.28 10 2.25V3H8.5v-.75A.25.25 0 0 0 8.25 2h-5.5a.25.25 0 0 0-.25.25v7.5c0 .14.11.25.25.25H4.5v1.5H2.75C1.78 11.5 1 10.72 1 9.75v-7.5C1 1.28 1.78.5 2.75.5zm-1.5 7.25a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m7.5 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5M6.75 4.5a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m3.75 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m3.75 0a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5", fill: "currentColor" })] }));
|
|
55
55
|
const V0Logo = () => (_jsxs("svg", { "aria-hidden": true, className: "size-4", fill: "none", viewBox: "0 0 16 16", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("title", { children: "v0" }), _jsx("path", { d: "M6.1 9.46V5.52h1.52v5.03c0 .59-.48 1.07-1.07 1.07-.28 0-.56-.11-.76-.31L0 5.52h2.15zM16 10.1h-1.52V6.6l-3.5 3.5h3.5v1.52h-3.96a2.14 2.14 0 0 1-2.14-2.14V5.52H9.9v3.5l3.5-3.5H9.9V4h3.96C15.04 4 16 4.96 16 6.14z", fill: "currentColor" })] }));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ImageProps as GeistImageProps } from "@vercel/geistcn/components/image";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
type ImageSource = {
|
|
4
|
+
src: string;
|
|
5
|
+
srcDark?: never;
|
|
6
|
+
srcLight?: never;
|
|
7
|
+
} | {
|
|
8
|
+
src?: never;
|
|
9
|
+
srcDark: string;
|
|
10
|
+
srcLight: string;
|
|
11
|
+
};
|
|
12
|
+
export type ImageProps = Omit<GeistImageProps, "srcDark" | "srcLight"> & ImageSource & {
|
|
13
|
+
caption?: ReactNode;
|
|
14
|
+
figureClassName?: string;
|
|
15
|
+
};
|
|
16
|
+
/** A non-interactive documentation image with an optional caption. */
|
|
17
|
+
export declare const Image: ({ caption, className, figureClassName, src, srcDark, srcLight, ...props }: ImageProps) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/components/image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,IAAI,eAAe,EACnC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,KAAK,WAAW,GACZ;IACE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,UAAU,CAAC,GACpE,WAAW,GAAG;IACZ,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEJ,sEAAsE;AACtE,eAAO,MAAM,KAAK,GAAI,2EAQnB,UAAU,4CA2BZ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Image as GeistImage, } from "@vercel/geistcn/components/image";
|
|
3
|
+
import { cn } from "@vercel/geistcn/utils";
|
|
4
|
+
/** A non-interactive documentation image with an optional caption. */
|
|
5
|
+
export const Image = ({ caption, className, figureClassName, src, srcDark, srcLight, ...props }) => {
|
|
6
|
+
const lightSource = srcLight ?? src;
|
|
7
|
+
const darkSource = srcDark ?? src;
|
|
8
|
+
return (_jsxs("figure", { className: cn("not-prose my-8 flex w-full max-w-full flex-col items-stretch justify-start gap-4", figureClassName), children: [_jsx(GeistImage, { className: cn("m-0 w-full rounded-lg border border-gray-400 bg-background-100 object-contain shadow-[var(--ds-shadow-small)]", className), srcDark: darkSource, srcLight: lightSource, ...props }), caption ? (_jsx("figcaption", { className: "mx-auto max-w-[640px] text-center text-copy-14 text-gray-900 max-[600px]:px-4", children: caption })) : null] }));
|
|
9
|
+
};
|
package/dist/controls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../src/controls.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAS5D,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,4CAqBrE,CAAC;AAEF,eAAO,MAAM,WAAW,+CA0CvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sDA+B5B,CAAC;AAEF,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CAChD;AAED,eAAO,MAAM,WAAW,GAAI,0DAOzB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../src/controls.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAS5D,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,4CAqBrE,CAAC;AAEF,eAAO,MAAM,WAAW,+CA0CvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sDA+B5B,CAAC;AAEF,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CAChD;AAED,eAAO,MAAM,WAAW,GAAI,0DAOzB,gBAAgB,mDA+BlB,CAAC"}
|
package/dist/controls.js
CHANGED
|
@@ -39,16 +39,17 @@ export const LanguageSelector = () => {
|
|
|
39
39
|
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "aria-label": "Select Language", className: "flex items-center justify-center rounded-md p-2 hover:bg-gray-alpha-100 focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:outline-none active:bg-gray-alpha-300", children: [_jsx(IconLanguages, { className: "size-4.5" }), _jsx("span", { className: "sr-only", children: "Select Language" })] }), _jsx(DropdownMenuContent, { align: "end", children: locales.map((lang) => (_jsxs(DropdownMenuItem, { className: "flex cursor-pointer items-center justify-between", disabled: locale === lang.locale, onClick: () => onChange?.(lang.locale), children: [lang.name, locale === lang.locale && _jsx(IconCheck, { className: "size-4" })] }, lang.locale))) })] }));
|
|
40
40
|
};
|
|
41
41
|
export const AskAIButton = ({ children, className, prompt, size = "small", variant = "secondary", ...props }) => {
|
|
42
|
-
const { enabled, isOpen, setIsOpen, setPrompt } = useGeistdocsChat();
|
|
42
|
+
const { enabled, isOpen, preloadChat, setIsOpen, setPrompt } = useGeistdocsChat();
|
|
43
43
|
if (!enabled) {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
46
|
return (_jsx(Button, { className: cn("shrink-0", className), onClick: () => {
|
|
47
|
+
preloadChat();
|
|
47
48
|
if (prompt) {
|
|
48
49
|
setPrompt(prompt);
|
|
49
50
|
setIsOpen(true);
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
53
|
setIsOpen(!isOpen);
|
|
53
|
-
}, size: size, typeName: "button", variant: variant, ...props, children: children ?? _jsx("span", { children: "Ask AI" }) }));
|
|
54
|
+
}, onFocus: preloadChat, onMouseEnter: preloadChat, size: size, typeName: "button", variant: variant, ...props, children: children ?? _jsx("span", { children: "Ask AI" }) }));
|
|
54
55
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ChatStatus, type UIMessage } from "ai";
|
|
2
|
+
export interface MessageActivity {
|
|
3
|
+
kind: "searching" | "thinking" | "tool";
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const isChatInProgress: (status: ChatStatus) => boolean;
|
|
7
|
+
export declare const isActiveAssistantMessage: ({ index, messages, status, }: {
|
|
8
|
+
index: number;
|
|
9
|
+
messages: UIMessage[];
|
|
10
|
+
status: ChatStatus;
|
|
11
|
+
}) => boolean;
|
|
12
|
+
export declare const shouldShowPendingActivity: ({ messages, status, }: {
|
|
13
|
+
messages: UIMessage[];
|
|
14
|
+
status: ChatStatus;
|
|
15
|
+
}) => boolean;
|
|
16
|
+
export declare const getMessageActivity: ({ inProgress, parts, }: {
|
|
17
|
+
inProgress: boolean;
|
|
18
|
+
parts: UIMessage["parts"];
|
|
19
|
+
}) => MessageActivity | null;
|
|
20
|
+
//# sourceMappingURL=activity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/activity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA6B,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAKhF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AASD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,UAAU,KAAG,OACJ,CAAC;AAEnD,eAAO,MAAM,wBAAwB,GAAI,8BAItC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;CACpB,KAAG,OAGmC,CAAC;AAExC,eAAO,MAAM,yBAAyB,GAAI,uBAGvC;IACD,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;CACpB,KAAG,OAC+D,CAAC;AAUpE,eAAO,MAAM,kBAAkB,GAAI,wBAGhC;IACD,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC3B,KAAG,eAAe,GAAG,IAsCrB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getToolName, isToolUIPart } from "ai";
|
|
2
|
+
import { getMessageSources } from "./message-sources";
|
|
3
|
+
const WORD_SEPARATOR_PATTERN = /[_-]+/g;
|
|
4
|
+
const isVisibleTextPart = (part) => part.type === "text" && part.text.trim().length > 0;
|
|
5
|
+
export const isChatInProgress = (status) => status === "submitted" || status === "streaming";
|
|
6
|
+
export const isActiveAssistantMessage = ({ index, messages, status, }) => isChatInProgress(status) &&
|
|
7
|
+
index === messages.length - 1 &&
|
|
8
|
+
messages[index]?.role === "assistant";
|
|
9
|
+
export const shouldShowPendingActivity = ({ messages, status, }) => isChatInProgress(status) && messages.at(-1)?.role !== "assistant";
|
|
10
|
+
const getToolActivityLabel = (part) => {
|
|
11
|
+
const name = getToolName(part).replace(WORD_SEPARATOR_PATTERN, " ").trim();
|
|
12
|
+
return name ? `Running ${name}...` : "Working...";
|
|
13
|
+
};
|
|
14
|
+
export const getMessageActivity = ({ inProgress, parts, }) => {
|
|
15
|
+
if (!inProgress) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const lastPart = parts
|
|
19
|
+
.filter((part) => isVisibleTextPart(part) ||
|
|
20
|
+
part.type === "reasoning" ||
|
|
21
|
+
isToolUIPart(part))
|
|
22
|
+
.at(-1);
|
|
23
|
+
const hasTextPart = parts.some(isVisibleTextPart);
|
|
24
|
+
const hasSources = getMessageSources(parts).length > 0;
|
|
25
|
+
if (!lastPart) {
|
|
26
|
+
return hasSources
|
|
27
|
+
? { kind: "searching", label: "Searching..." }
|
|
28
|
+
: { kind: "thinking" };
|
|
29
|
+
}
|
|
30
|
+
if (lastPart.type === "reasoning") {
|
|
31
|
+
return { kind: "thinking", label: "Thinking..." };
|
|
32
|
+
}
|
|
33
|
+
if (hasSources && !hasTextPart) {
|
|
34
|
+
return { kind: "searching", label: "Searching..." };
|
|
35
|
+
}
|
|
36
|
+
if (isToolUIPart(lastPart)) {
|
|
37
|
+
return {
|
|
38
|
+
kind: "tool",
|
|
39
|
+
label: getToolActivityLabel(lastPart),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
@@ -3,7 +3,9 @@ interface GeistdocsChatContextValue {
|
|
|
3
3
|
basePath?: string;
|
|
4
4
|
enabled: boolean;
|
|
5
5
|
footer?: React.ReactNode;
|
|
6
|
+
hasBeenOpened: boolean;
|
|
6
7
|
isOpen: boolean;
|
|
8
|
+
preloadChat: () => void;
|
|
7
9
|
prompt: string;
|
|
8
10
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
9
11
|
setPrompt: React.Dispatch<React.SetStateAction<string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,UAAU,yBAAyB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,eAAO,MAAM,gBAAgB,iCAQ5B,CAAC;AAEF,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,qBAAqB,GAAI,uBAGnC,0BAA0B,4CAyD5B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
4
4
|
const CHAT_OPEN_STORAGE_KEY = "geistdocs:chat-open";
|
|
5
5
|
const GeistdocsChatContext = createContext(null);
|
|
6
6
|
export const useGeistdocsChat = () => {
|
|
@@ -12,13 +12,24 @@ export const useGeistdocsChat = () => {
|
|
|
12
12
|
};
|
|
13
13
|
export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
14
14
|
const [isOpen, setIsOpen] = useState(false);
|
|
15
|
+
const [hasBeenOpened, setHasBeenOpened] = useState(false);
|
|
15
16
|
const [prompt, setPrompt] = useState("");
|
|
17
|
+
const preloadChat = useCallback(() => setHasBeenOpened(true), []);
|
|
16
18
|
useEffect(() => {
|
|
17
19
|
const stored = window.localStorage.getItem(CHAT_OPEN_STORAGE_KEY);
|
|
18
20
|
if (stored !== null) {
|
|
19
|
-
|
|
21
|
+
const open = stored === "true";
|
|
22
|
+
setIsOpen(open);
|
|
23
|
+
if (open) {
|
|
24
|
+
setHasBeenOpened(true);
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
}, []);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (isOpen) {
|
|
30
|
+
setHasBeenOpened(true);
|
|
31
|
+
}
|
|
32
|
+
}, [isOpen]);
|
|
22
33
|
useEffect(() => {
|
|
23
34
|
window.localStorage.setItem(CHAT_OPEN_STORAGE_KEY, String(isOpen));
|
|
24
35
|
}, [isOpen]);
|
|
@@ -26,12 +37,22 @@ export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
|
26
37
|
basePath: config.basePath,
|
|
27
38
|
footer: config.ai?.footer,
|
|
28
39
|
enabled: config.ai?.enabled !== false,
|
|
40
|
+
hasBeenOpened,
|
|
29
41
|
isOpen,
|
|
42
|
+
preloadChat,
|
|
30
43
|
prompt,
|
|
31
44
|
setIsOpen,
|
|
32
45
|
setPrompt,
|
|
33
46
|
suggestions: config.ai?.suggestions ?? [],
|
|
34
47
|
title: config.title,
|
|
35
|
-
}), [
|
|
48
|
+
}), [
|
|
49
|
+
config.ai,
|
|
50
|
+
config.basePath,
|
|
51
|
+
config.title,
|
|
52
|
+
hasBeenOpened,
|
|
53
|
+
isOpen,
|
|
54
|
+
preloadChat,
|
|
55
|
+
prompt,
|
|
56
|
+
]);
|
|
36
57
|
return (_jsx(GeistdocsChatContext.Provider, { value: value, children: children }));
|
|
37
58
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ChatConversationSkeleton: () => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const ChatEmptySkeleton: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const ChatLoadingSkeleton: ({ isMobile, title, }: {
|
|
4
|
+
isMobile: boolean;
|
|
5
|
+
title: string;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=loading-skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loading-skeleton.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/loading-skeleton.tsx"],"names":[],"mappings":"AAsCA,eAAO,MAAM,wBAAwB,+CAyCpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,+CAsB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,sBAGjC;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,4CAmBA,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Skeleton } from "@vercel/geistcn/components/skeleton";
|
|
4
|
+
import { cn } from "@vercel/geistcn/utils";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
const getMessageCount = async (title) => {
|
|
7
|
+
const name = title.replaceAll(" ", "").toLowerCase();
|
|
8
|
+
if ("databases" in indexedDB) {
|
|
9
|
+
const databases = await indexedDB.databases();
|
|
10
|
+
if (!databases.some((database) => database.name === name)) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const request = indexedDB.open(name);
|
|
16
|
+
request.onerror = () => resolve(0);
|
|
17
|
+
request.onupgradeneeded = () => {
|
|
18
|
+
request.transaction?.abort();
|
|
19
|
+
resolve(0);
|
|
20
|
+
};
|
|
21
|
+
request.onsuccess = () => {
|
|
22
|
+
const database = request.result;
|
|
23
|
+
if (!database.objectStoreNames.contains("messages")) {
|
|
24
|
+
database.close();
|
|
25
|
+
resolve(0);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const transaction = database.transaction("messages", "readonly");
|
|
29
|
+
const count = transaction.objectStore("messages").count();
|
|
30
|
+
count.onerror = () => resolve(0);
|
|
31
|
+
count.onsuccess = () => resolve(count.result);
|
|
32
|
+
transaction.oncomplete = () => database.close();
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const ChatConversationSkeleton = () => (_jsxs("div", { className: "relative flex flex-1 flex-col justify-start gap-7 overflow-hidden px-4 pt-12 pb-4", children: [_jsxs("div", { className: "relative mr-2 ml-auto w-[260px]", children: [_jsx("div", { className: "relative min-h-10 animate-pulse rounded-[10px] bg-gray-200" }), _jsx("svg", { "aria-hidden": "true", className: "absolute right-[2.5px] -bottom-[0.5px] z-10 translate-x-1/2 fill-gray-200/80", height: "14", viewBox: "0 0 18 14", width: "18", children: _jsx("path", { d: "M0.866025 8.80383L11.2583 0.803833C11.2583 0.803833 12.0621 9.5 17.2583 13.1961C12.0621 13.1961 0.866025 8.80383 0.866025 8.80383Z" }) })] }), _jsx(Skeleton, { height: 25, width: "20%" }), _jsxs("div", { className: "flex shrink-0 flex-col gap-4", children: [_jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "50%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "83%" }), _jsx(Skeleton, { height: 20, width: "66%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "50%" })] }), _jsxs("div", { className: "w-[80%] flex-1 space-y-2", children: [_jsx(Skeleton, { height: 20, width: "66%" }), _jsx(Skeleton, { height: 20, width: "100%" }), _jsx(Skeleton, { height: 20, width: "75%" }), _jsx(Skeleton, { height: 20, width: "33%" })] })] }), _jsx("div", { className: "absolute inset-x-0 bottom-0 h-52 bg-gradient-to-t from-background-100 via-background-100 to-transparent" })] }));
|
|
37
|
+
export const ChatEmptySkeleton = () => (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "flex h-16 shrink-0 items-center justify-between px-3.5 py-2", children: [_jsx(Skeleton, { height: 20, width: 56 }), _jsx("div", { className: "flex items-center gap-1", children: [0, 1, 2, 3].map((item) => (_jsx(Skeleton, { height: 32, rounded: true, width: 32 }, item))) })] }), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col justify-end", children: [_jsxs("div", { className: "flex flex-col gap-2 px-4 pt-4", children: [[0, 1, 2, 3].map((item) => (_jsx(Skeleton, { block: true, height: 36, width: "100%" }, item))), _jsx(Skeleton, { className: "mt-3 mb-2 ml-2", height: 16, width: "72%" })] }), _jsx("div", { className: "p-4", children: _jsx(Skeleton, { block: true, className: "rounded-[12px]", height: 88, width: "100%" }) })] })] }));
|
|
38
|
+
export const ChatLoadingSkeleton = ({ isMobile, title, }) => {
|
|
39
|
+
const [conversation, setConversation] = useState(false);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
getMessageCount(title).then((count) => setConversation(count > 0));
|
|
42
|
+
}, [title]);
|
|
43
|
+
return (_jsx("div", { className: cn("fixed z-45 flex flex-col bg-background-100", isMobile
|
|
44
|
+
? "inset-x-0 bottom-0 h-[80dvh] rounded-t-xl"
|
|
45
|
+
: "inset-y-0 right-0 w-[400px] border-l"), children: conversation ? _jsx(ChatConversationSkeleton, {}) : _jsx(ChatEmptySkeleton, {}) }));
|
|
46
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-metadata.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-metadata.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"message-metadata.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-metadata.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAMlD,UAAU,oBAAoB;IAC5B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC3B;AAQD,eAAO,MAAM,eAAe,GAAI,wBAG7B,oBAAoB,mDA0DtB,CAAC"}
|
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { IconBookmark, IconChevronDown } from "@vercel/geistcn-assets/icons";
|
|
4
|
-
import {
|
|
4
|
+
import { isToolUIPart } from "ai";
|
|
5
|
+
import { getMessageActivity } from "./activity";
|
|
5
6
|
import { DotsSpinner } from "./dots-spinner";
|
|
7
|
+
import { getMessageSources } from "./message-sources";
|
|
6
8
|
import { Source, Sources, SourcesContent, SourcesTrigger } from "./sources";
|
|
7
|
-
const WORD_SEPARATOR_PATTERN = /[_-]+/g;
|
|
8
9
|
const LoadingContainer = ({ children }) => (_jsx("div", { className: "h-12 animate-pulse pt-2 text-gray-900 text-sm", children: children }));
|
|
9
|
-
const getToolActivityLabel = (part) => {
|
|
10
|
-
const name = getToolName(part).replace(WORD_SEPARATOR_PATTERN, " ").trim();
|
|
11
|
-
return name ? `Running ${name}...` : "Working...";
|
|
12
|
-
};
|
|
13
10
|
export const MessageMetadata = ({ parts, inProgress, }) => {
|
|
11
|
+
const activity = getMessageActivity({ inProgress, parts });
|
|
12
|
+
if (activity) {
|
|
13
|
+
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " ", activity.label] }));
|
|
14
|
+
}
|
|
14
15
|
const lastPart = parts
|
|
15
|
-
.filter((part) => part.type === "text" ||
|
|
16
|
+
.filter((part) => part.type === "text" || isToolUIPart(part))
|
|
16
17
|
.at(-1);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (lastPart.type === "reasoning" &&
|
|
21
|
-
lastPart.state !== "done" &&
|
|
22
|
-
inProgress) {
|
|
23
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " Thinking..."] }));
|
|
24
|
-
}
|
|
25
|
-
const tool = isToolUIPart(lastPart) ? lastPart : null;
|
|
26
|
-
const hasTextPart = parts.some((part) => part.type === "text");
|
|
27
|
-
const sources = Array.from(new Map(parts
|
|
28
|
-
.filter((part) => part.type === "source-url")
|
|
29
|
-
.map((part) => [part.url, part])).values());
|
|
30
|
-
if (sources.length > 0 && !hasTextPart && inProgress) {
|
|
31
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " Searching..."] }));
|
|
32
|
-
}
|
|
33
|
-
if (tool &&
|
|
34
|
-
inProgress &&
|
|
35
|
-
(tool.state === "input-streaming" || tool.state === "input-available")) {
|
|
36
|
-
return (_jsxs(LoadingContainer, { children: [_jsx(DotsSpinner, {}), " ", getToolActivityLabel(tool)] }));
|
|
37
|
-
}
|
|
38
|
-
if (sources.length > 0 && !(tool && inProgress)) {
|
|
18
|
+
const tool = lastPart && isToolUIPart(lastPart) ? lastPart : null;
|
|
19
|
+
const sources = getMessageSources(parts);
|
|
20
|
+
if (sources.length > 0) {
|
|
39
21
|
return (_jsxs(Sources, { className: "mb-4", children: [_jsxs(SourcesTrigger, { className: "w-full max-w-fit cursor-pointer justify-between gap-2 py-1 pr-3 pl-0 text-left", count: sources.length, children: [_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(IconBookmark, { className: "size-4", color: "gray-900" }), _jsxs("p", { className: "text-gray-900 text-xs", children: ["Used ", sources.length, " source", sources.length === 1 ? "" : "s"] })] }), _jsx(IconChevronDown, { className: "size-4 transition-transform duration-200 group-data-[state=open]:rotate-180", color: "gray-900" })] }), _jsx(SourcesContent, { children: _jsx("ul", { className: "mt-1.5 list-disc pl-4", children: sources.map((source) => (_jsx("li", { className: "my-1.5", children: _jsx(Source, { href: source.url, title: source.title }) }, source.url))) }) })] }));
|
|
40
22
|
}
|
|
41
|
-
if (!tool
|
|
23
|
+
if (!tool) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (tool.state === "output-available") {
|
|
42
27
|
return null;
|
|
43
28
|
}
|
|
44
29
|
return _jsx("div", { className: "h-12" });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-sources.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAgBxE,eAAO,MAAM,iBAAiB,GAC5B,OAAO,SAAS,CAAC,OAAO,CAAC,KACxB,eAAe,EAuBf,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isToolUIPart } from "ai";
|
|
2
|
+
const isToolSource = (value) => typeof value === "object" &&
|
|
3
|
+
value !== null &&
|
|
4
|
+
"documentUri" in value &&
|
|
5
|
+
typeof value.documentUri === "string" &&
|
|
6
|
+
"documentTitle" in value &&
|
|
7
|
+
typeof value.documentTitle === "string";
|
|
8
|
+
export const getMessageSources = (parts) => Array.from(new Map([
|
|
9
|
+
...parts.filter((part) => part.type === "source-url"),
|
|
10
|
+
...parts
|
|
11
|
+
.filter((part) => isToolUIPart(part) && part.state === "output-available")
|
|
12
|
+
.flatMap((part) => {
|
|
13
|
+
if (!Array.isArray(part.output)) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return part.output.filter(isToolSource).map((source, index) => ({
|
|
17
|
+
type: "source-url",
|
|
18
|
+
sourceId: `tool-${part.toolCallId}-${source.chunkIndex ?? index}-${source.documentUri}`,
|
|
19
|
+
url: source.documentUri,
|
|
20
|
+
title: source.documentTitle,
|
|
21
|
+
}));
|
|
22
|
+
}),
|
|
23
|
+
].map((source) => [source.url, source])).values());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAEL,UAAU,EAEX,MAAM,YAAY,CAAC;AAyLpB,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAC1D,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,+BAA+B,YAAY,4CASlE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAEjE,eAAO,MAAM,cAAc,GAAI,mCAI5B,mBAAmB,4CAqBrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,UAAU,CAAC,CAAC;AAErE,eAAO,MAAM,eAAe,gEACA,oBAAoB,6CAa/C,CAAC"}
|