AI Agent Context
elements/agent-contextFreeComponent
Display and optionally edit agent context data with type indicators, nested object support, and collapsible sections. Visualizes user/team context for AI agents.
Install it
npx shadcn@latest add https://www.tryelements.dev/r/agent-context.jsonSource
1"use client";23import * as React from "react";45import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";6import {7 Braces,8 Check,9 ChevronDown,10 ChevronRight,11 Database,12 Hash,13 List,14 Pencil,15 ToggleLeft,16 Type,17 X,18} from "lucide-react";1920import { cn } from "@/lib/utils";2122type ValueType = "string" | "number" | "boolean" | "object" | "array" | "null";2324interface AiAgentContextContextValue {25 editable: boolean;26 onChange?: (key: string, value: unknown) => void;27}2829const AiAgentContextContext =30 React.createContext<AiAgentContextContextValue | null>(null);3132function useAgentContextContext() {33 const context = React.useContext(AiAgentContextContext);34 if (!context) {35 throw new Error(36 "AiAgentContext components must be used within <AiAgentContext>",37 );38 }39 return context;40}4142function getValueType(value: unknown): ValueType {43 if (value === null) return "null";44 if (Array.isArray(value)) return "array";45 return typeof value as ValueType;46}4748interface AiAgentContextProps {49 context: Record<string, unknown>;50 title?: string;51 editable?: boolean;52 onChange?: (key: string, value: unknown) => void;53 children?: React.ReactNode;54 className?: string;55}5657function AiAgentContext({58 context,59 title,60 editable = false,61 onChange,62 children,63 className,64}: AiAgentContextProps) {65 const contextValue = React.useMemo(66 () => ({ editable, onChange }),67 [editable, onChange],68 );6970 return (71 <AiAgentContextContext.Provider value={contextValue}>72 <div73 data-slot="ai-agent-context"74 className={cn(75 "rounded-lg border border-border bg-card text-card-foreground",76 className,77 )}78 >79 {children || (80 <>81 <AiAgentContextHeader>{title}</AiAgentContextHeader>82 <AiAgentContextContent context={context} />83 </>84 )}85 </div>86 </AiAgentContextContext.Provider>87 );88}8990interface AiAgentContextHeaderProps {91 children?: React.ReactNode;92 className?: string;93}9495function AiAgentContextHeader({96 children,97 className,98}: AiAgentContextHeaderProps) {99 return (100 <div101 data-slot="ai-agent-context-header"102 className={cn(103 "flex items-center gap-2 border-b border-border px-4 py-3",104 className,105 )}106 >107 <div className="flex size-8 shrink-0 items-center justify-center rounded-md bg-muted">108 <Database className="size-4 text-muted-foreground" />109 </div>110// … truncated
What it pulls in
npm packages
Files it writes
More from elements
All 359 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Ably Logoably-logo | elements | Components | Free | no deps | |
| AI Agent Rosteragent-roster | elements | Components | Free | 1 dep | |
| AI Agent Statusagent-status | elements | Components | Free | 1 dep | |
| Algolia Logoalgolia-logo | elements | Components | Free | no deps | |
| Amp Logoamp-logo | elements | Components | Free | no deps | |
| Anthropic Logoanthropic-logo | elements | Components | Free | no deps | |
| Antigravity Logoantigravity-logo | elements | Components | Free | no deps | |
| API Response Viewerapi-response-viewer | elements | Components | Free | no deps |
