Skip to content

Commit 2af0a46

Browse files
authored
[DOC] Agentic Search Guide (#5881)
Adding agentic search guide
1 parent 3b7b009 commit 2af0a46

File tree

8 files changed

+587
-24
lines changed

8 files changed

+587
-24
lines changed

docs/docs.trychroma.com/components/markdoc/code-block.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import CodeBlockHeader from "@/components/markdoc/code-block-header";
99

1010
import "highlight.js/styles/atom-one-dark.css";
1111

12+
export interface CodeBlockProps {
13+
content: React.ReactNode;
14+
language: string;
15+
showHeader: boolean;
16+
className?: string;
17+
}
18+
1219
const rehypeRemovePre = () => {
1320
return (tree: any) => {
1421
visit(tree, "element", (node) => {
@@ -25,12 +32,12 @@ const rehypeRemovePre = () => {
2532
};
2633
};
2734

28-
const CodeBlock: React.FC<{
29-
content: React.ReactNode;
30-
language: string;
31-
showHeader: boolean;
32-
className?: string;
33-
}> = async ({ content, language, showHeader = true, className }) => {
35+
const CodeBlock: React.FC<CodeBlockProps> = async ({
36+
content,
37+
language,
38+
showHeader = true,
39+
className,
40+
}) => {
3441
if (typeof content !== "string") {
3542
throw new Error("CodeBlock children must be a string.");
3643
}
@@ -60,5 +67,6 @@ const CodeBlock: React.FC<{
6067
</div>
6168
);
6269
};
70+
CodeBlock.displayName = "CodeBlock";
6371

6472
export default CodeBlock;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import CodeBlock, { CodeBlockProps } from "@/components/markdoc/code-block";
3+
4+
function isCodeBlockElement(
5+
node: React.ReactNode,
6+
): node is React.ReactElement<CodeBlockProps> {
7+
if (!React.isValidElement(node)) return false;
8+
9+
if (node.type === CodeBlock) return true;
10+
const t = node.type as any;
11+
return (
12+
typeof t === "function" &&
13+
(t.displayName === "CodeBlock" || t.name === "CodeBlock")
14+
);
15+
}
16+
17+
function injectIntoCodeBlock(
18+
node: React.ReactNode,
19+
className: string,
20+
): React.ReactNode {
21+
return React.Children.map(node, (child) => {
22+
if (!React.isValidElement(child)) return child;
23+
24+
if (isCodeBlockElement(child)) {
25+
const prev = child.props.className ?? "";
26+
return React.cloneElement<Partial<CodeBlockProps>>(child, {
27+
className,
28+
});
29+
}
30+
31+
return child;
32+
});
33+
}
34+
35+
const CollapsibleCodeBlock: React.FC<{ children: React.ReactNode }> = ({
36+
children,
37+
}) => {
38+
const className = "max-h-64 overflow-y-auto";
39+
const enhanced = injectIntoCodeBlock(children, className);
40+
41+
return <div className="bg-black">{enhanced}</div>;
42+
};
43+
44+
export default CollapsibleCodeBlock;

docs/docs.trychroma.com/components/markdoc/steps.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export const Step: React.FC<{ children: React.ReactNode; title?: string }> = ({
3131
title,
3232
}) => {
3333
return (
34-
<div className="flex flex-col gap-1">
35-
{title && <p className="text-lg font-bold">{title}</p>}
36-
<div>{children}</div>
34+
<div className="flex flex-col gap-0 my-0">
35+
{title && <p className="font-bold my-0">{title}</p>}
36+
<div className="my-0">{children}</div>
3737
</div>
3838
);
3939
};

docs/docs.trychroma.com/components/markdoc/tabbed-use-case-code-block.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { tabLabelStyle } from "@/components/markdoc/code-block-header";
33
import { capitalize, cn } from "@/lib/utils";
44
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
55
import { TabProps } from "@/components/markdoc/tabs";
6-
import CodeBlock from "@/components/markdoc/code-block";
6+
import CodeBlock, { CodeBlockProps } from "@/components/markdoc/code-block";
77
import CopyButton from "@/components/markdoc/copy-button";
88

99
const TabbedUseCaseCodeBlock: React.FC<{
1010
language: string;
1111
children: ReactElement<TabProps>[];
12+
scrollable?: boolean;
1213
}> = ({ language, children }) => {
1314
return (
1415
<Tabs defaultValue={children[0].props.label} className="flex flex-col">
@@ -44,19 +45,23 @@ const TabbedUseCaseCodeBlock: React.FC<{
4445
))}
4546
</div>
4647
</div>
47-
{children.map((tab) => (
48+
{children
49+
.filter((tab) => tab.props.children.type === CodeBlock)
50+
.map((tab) => (
4851
<TabsContent
4952
key={`${tab.props.label}-content`}
5053
value={tab.props.label}
5154
className="m-0"
5255
>
53-
{tab.props.children.type === CodeBlock
54-
? React.cloneElement(tab, {
55-
children: React.cloneElement(tab.props.children, {
56-
showHeader: false,
57-
}),
58-
})
59-
: tab}
56+
{React.cloneElement<Partial<{ children: ReactElement }>>(tab, {
57+
children: React.cloneElement<Partial<CodeBlockProps>>(
58+
tab.props.children,
59+
{
60+
showHeader: false,
61+
className: "max-h-64 overflow-y-auto",
62+
},
63+
),
64+
})}
6065
</TabsContent>
6166
))}
6267
</Tabs>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import TabbedUseCaseCodeBlock from "@/components/markdoc/tabbed-use-case-code-block";
3+
import Tab from "@/components/markdoc/tabs";
4+
import CodeBlock from "@/components/markdoc/code-block";
5+
6+
const TypescriptInstallation: React.FC<{ packages: string }> = ({
7+
packages,
8+
}) => {
9+
return (
10+
<TabbedUseCaseCodeBlock language="Terminal">
11+
<Tab label="npm">
12+
<CodeBlock
13+
content={`npm install ${packages}`}
14+
language="terminal"
15+
showHeader={false}
16+
/>
17+
</Tab>
18+
<Tab label="pnpm">
19+
<CodeBlock
20+
content={`pnpm add ${packages}`}
21+
language="terminal"
22+
showHeader={false}
23+
/>
24+
</Tab>
25+
<Tab label="yarn">
26+
<CodeBlock
27+
content={`yarn add ${packages}`}
28+
language="terminal"
29+
showHeader={false}
30+
/>
31+
</Tab>
32+
<Tab label="bun">
33+
<CodeBlock
34+
content={`bun add ${packages}`}
35+
language="terminal"
36+
showHeader={false}
37+
/>
38+
</Tab>
39+
</TabbedUseCaseCodeBlock>
40+
);
41+
};
42+
43+
export default TypescriptInstallation;

docs/docs.trychroma.com/markdoc/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import ComboboxSteps, {
2626
import Steps, { Step } from "@/components/markdoc/steps";
2727
import ImageHoverText from "@/components/markdoc/image-hover-text";
2828
import PythonInstallation from "@/components/markdoc/python-installation";
29+
import CollapsibleCodeBlock from "@/components/markdoc/collapsible-code-block";
2930

3031
interface MarkDocConfig extends Config {
3132
components?: Record<string, React.FC<any>>;
@@ -85,6 +86,9 @@ const markdocConfig: MarkDocConfig = {
8586
type: String,
8687
required: true,
8788
},
89+
scrollable: {
90+
type: Boolean,
91+
},
8892
},
8993
},
9094
Tab: {
@@ -244,6 +248,10 @@ const markdocConfig: MarkDocConfig = {
244248
},
245249
},
246250
},
251+
CollapsibleCodeBlock: {
252+
render: "CollapsibleCodeBlock",
253+
selfClosing: false,
254+
},
247255
},
248256
components: {
249257
InlineCode,
@@ -273,6 +281,7 @@ const markdocConfig: MarkDocConfig = {
273281
Step,
274282
ImageHoverText,
275283
PythonInstallation,
284+
CollapsibleCodeBlock,
276285
},
277286
};
278287

0 commit comments

Comments
 (0)