feat: syntax highlighting with shiki and copy-to-clipboard for all docs code blocks

This commit is contained in:
Vectry
2026-02-10 04:01:59 +00:00
parent 42b5379ce1
commit 5b388484f8
14 changed files with 642 additions and 200 deletions

View File

@@ -1,4 +1,5 @@
import type { Metadata } from "next";
import { CodeBlock } from "@/components/code-block";
export const metadata: Metadata = {
title: "Python SDK",
@@ -6,21 +7,6 @@ export const metadata: Metadata = {
"Full reference for the AgentLens Python SDK: init(), @trace decorator, log_decision(), TraceContext, and configuration.",
};
function CodeBlock({ children, title }: { children: string; title?: string }) {
return (
<div className="rounded-xl overflow-hidden border border-neutral-800 bg-neutral-900/50 my-4">
{title && (
<div className="px-4 py-2.5 border-b border-neutral-800 text-xs text-neutral-500 font-mono">
{title}
</div>
)}
<pre className="p-4 overflow-x-auto text-sm leading-relaxed">
<code className="text-neutral-300">{children}</code>
</pre>
</div>
);
}
function ApiSection({
name,
signature,
@@ -113,7 +99,7 @@ export default function PythonSdkPage() {
</tbody>
</table>
</div>
<CodeBlock title="example.py">{`import agentlens
<CodeBlock title="example.py" language="python">{`import agentlens
agentlens.init(
api_key="al_key_abc123",
@@ -159,7 +145,7 @@ agentlens.init(
</tbody>
</table>
</div>
<CodeBlock title="decorator.py">{`from agentlens import trace
<CodeBlock title="decorator.py" language="python">{`from agentlens import trace
@trace(name="research-agent", tags=["research", "v2"])
async def research(topic: str) -> str:
@@ -219,7 +205,7 @@ def simple_agent(prompt: str) -> str:
</tbody>
</table>
</div>
<CodeBlock title="decisions.py">{`import agentlens
<CodeBlock title="decisions.py" language="python">{`import agentlens
from agentlens import trace
@trace(name="routing-agent")
@@ -245,7 +231,7 @@ async def route_request(user_input: str):
signature="agentlens.TraceContext"
description="Context manager for manual trace lifecycle control. Use this when the @trace decorator does not fit your workflow."
>
<CodeBlock title="context.py">{`import agentlens
<CodeBlock title="context.py" language="python">{`import agentlens
async def process_batch(items: list[str]):
for item in items:
@@ -275,7 +261,7 @@ async def process_batch(items: list[str]):
signature="agentlens.shutdown(timeout=10.0)"
description="Flush all pending traces and shut down the background sender. Call this before your application exits to avoid losing data."
>
<CodeBlock title="shutdown.py">{`import agentlens
<CodeBlock title="shutdown.py" language="python">{`import agentlens
import atexit
agentlens.init(api_key="...", endpoint="...")