diff --git a/README.md b/README.md index d717ecf3..bd2fb6a3 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Each kit includes configuration instructions, environment variables/lamatic-conf || | **🧑‍💼 Assistant Kits** | Create context-aware helpers for users, customers, and team members | | | [`/kits/assistant`](./kits/assistant) | | **Grammar Assistant** | A chrome extension to check grammar corrections across your selection. | Available | | [`/kits/assistant/grammar-extension`](./kits/assistant/grammar-extension) | +| **Legal Assistant** | A Next.js legal assistant chatbot that returns informational summaries, references, next steps, and a legal disclaimer. | Available | [![Live Demo](https://img.shields.io/badge/Live%20Demo-black?style=for-the-badge)](https://legal-drab-three.vercel.app/) | [`/kits/assistant/legal`](./kits/assistant/legal) | || | **💬 Embed Kits** | Seamlessly integrate AI agents into apps, websites, and workflows | | | [`/kits/embed`](./kits/embed) | | **Chatbot** | A Next.js starter kit for chatbot using Lamatic Flows. | Available | [![Live Demo](https://img.shields.io/badge/Live%20Demo-black?style=for-the-badge)](https://agent-kit-embedded-chat.vercel.app) | [`/kits/embed/chat`](./kits/embed/chat) | diff --git a/kits/assistant/legal/.env.example b/kits/assistant/legal/.env.example new file mode 100644 index 00000000..55981eda --- /dev/null +++ b/kits/assistant/legal/.env.example @@ -0,0 +1,4 @@ +ASSISTANT_LEGAL_ADVISOR="your-flow-id-here" +LAMATIC_API_URL="https://your-lamatic-api-url" +LAMATIC_PROJECT_ID="your-project-id" +LAMATIC_API_KEY="your-api-key" diff --git a/kits/assistant/legal/.gitignore b/kits/assistant/legal/.gitignore new file mode 100644 index 00000000..0742840b --- /dev/null +++ b/kits/assistant/legal/.gitignore @@ -0,0 +1,28 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules + +# next.js +/.next/ +/out/ + +# production +/build + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# env files +.env* +!.env.example + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/kits/assistant/legal/README.md b/kits/assistant/legal/README.md new file mode 100644 index 00000000..7d2df4a2 --- /dev/null +++ b/kits/assistant/legal/README.md @@ -0,0 +1,139 @@ +# Agent Kit Legal Assistant by Lamatic.ai + +**Agent Kit Legal Assistant** is a Next.js starter kit for a legal assistant chatbot built on Lamatic Flows. + +## What This Kit Does and the Problem It Solves + +Many users have legal questions but do not know where to begin, which legal area applies, or what next step to take. +This kit provides a structured legal-information assistant that can: +- Classify the likely legal area from a user question. +- Return informational summaries with context-aware references when available. +- Suggest practical next steps and follow-up questions. +- Always show a legal disclaimer so users understand it is not legal advice. + +It is designed to: +- Understand user legal questions with optional jurisdiction/context. +- Return an informational legal summary. +- Include references to statutes, case law, or source materials when available. +- Suggest practical next steps. +- Show a clear disclaimer that responses are not legal advice. + +## Important Disclaimer + +This project is for informational and educational use only. +It is not legal advice, does not create an attorney-client relationship, and should not replace consultation with a licensed attorney. +Do not submit confidential, privileged, or personally identifying information unless you have reviewed and accepted the data retention and logging policies of Lamatic and your configured model provider. + +## Prerequisites and Required Providers + +- Node.js 20.9+ +- npm 9+ +- Lamatic account and deployed flow +- Lamatic API key, project ID, and API URL +- LLM provider configured in Lamatic flow (for example OpenRouter/OpenAI, Anthropic, etc.) + +## Lamatic Setup (Pre and Post) + +Before running this project, build and deploy your legal flow in Lamatic, then wire its values into this kit. + +Pre: Build in Lamatic +1. Sign in at https://lamatic.ai +2. Create a project +3. Create a legal assistant flow +4. Deploy the flow +5. Export your flow files (`config.json`, `inputs.json`, `meta.json`, `README.md`) +6. Copy your project API values and flow ID + +Post: Wire into this repo +1. Create `.env.local` +2. Add Lamatic credentials and flow ID +3. Install and run locally + +## Required Environment Variables + +Create `.env.local`: + +```bash +ASSISTANT_LEGAL_ADVISOR="your-flow-id-here" +LAMATIC_API_URL="https://your-lamatic-api-url" +LAMATIC_PROJECT_ID="your-project-id" +LAMATIC_API_KEY="your-api-key" +``` + +## Setup and Run Instructions + +```bash +cd kits/assistant/legal +npm install +npm run dev +# Open http://localhost:3000 +``` + +## Live Preview + +https://legal-drab-three.vercel.app/ + +## Execution Paths + +- Client widget path: the bundled `flows/assistant-legal-advisor/config.json` uses a Chat Widget trigger and works with `components/legal-ask-widget.tsx`. +- Server orchestration path: `actions/orchestrate.ts#getLegalGuidance` expects an API Request trigger flow. Replace the bundled flow export with an API trigger flow if you want server-side `executeFlow` calls. + +## Usage Examples + +Try prompts like: +- "My landlord did not return my security deposit in Goa, India. What can I do?" +- "I was terminated without notice. What steps should I consider?" +- "A contractor did not complete agreed work after payment in Singapore. What are my options?" + +Expected behavior: +- Assistant returns an informational response with a disclaimer. +- Assistant asks for missing jurisdiction details when needed. +- Assistant suggests practical next steps without claiming to be a lawyer. + +## Screenshots or GIFs (Optional) + +![Legal Assistant UI](./public/legal-assistant-ui.png) + +## Flow Export Location + +Place your Lamatic export in: + +```text +kits/assistant/legal/flows/assistant-legal-advisor/ +``` + +If you use a chat-trigger flow, update the flow `domains` allowlist to your actual local and production origins before deployment. + +Expected files: +- `config.json` +- `inputs.json` +- `meta.json` +- `README.md` + +## Repo Structure + +```text +/actions + orchestrate.ts # Legal assistant flow execution and output mapping +/app + page.tsx # Legal assistant UI +/components + header.tsx # Top navigation +/lib + lamatic-client.ts # Lamatic SDK client +/flows + assistant-legal-advisor/ +/package.json +/config.json +/.env.example +``` + +## Contributing + +Follow the repository contribution guide in [CONTRIBUTING.md](../../../CONTRIBUTING.md). + +Please also follow the community [Code of Conduct](../../../CODE_OF_CONDUCT.md). + +## License + +MIT License. See [LICENSE](../../../LICENSE). diff --git a/kits/assistant/legal/actions/orchestrate.ts b/kits/assistant/legal/actions/orchestrate.ts new file mode 100644 index 00000000..880a999c --- /dev/null +++ b/kits/assistant/legal/actions/orchestrate.ts @@ -0,0 +1,217 @@ +"use server" + +import { getLamaticClient } from "@/lib/lamatic-client" +import { config } from "../orchestrate.js" +import { join } from "node:path" +import { access, readFile } from "node:fs/promises" + +const DEFAULT_DISCLAIMER = + "This response is for informational purposes only and is not legal advice. Consult a licensed attorney for advice specific to your situation." + +type LegalAssistantResult = { + answer: string + references: string[] + nextSteps: string[] + disclaimer: string +} + +type FlowNode = { + data?: { + nodeId?: string + } +} + +function toStringArray(value: unknown): string[] { + if (Array.isArray(value)) { + return value + .map((item) => (typeof item === "string" ? item.trim() : String(item).trim())) + .filter(Boolean) + } + + if (typeof value === "string") { + return value + .split("\n") + .map((item) => item.replace(/^[-*\d.\s]+/, "").trim()) + .filter(Boolean) + } + + return [] +} + +function extractAnswer(result: Record): string { + const candidates = [ + result.answer, + result.response, + result.summary, + result.legalSummary, + result.output, + ] + + for (const candidate of candidates) { + if (typeof candidate === "string" && candidate.trim()) { + return candidate.trim() + } + } + + return "" +} + +async function usesChatTriggerExport(): Promise { + try { + const candidates = [ + join(process.cwd(), "flows", "assistant-legal-advisor", "config.json"), + join(process.cwd(), "kits", "assistant", "legal", "flows", "assistant-legal-advisor", "config.json"), + ] + + let flowConfigPath: string | undefined + for (const path of candidates) { + try { + await access(path) + flowConfigPath = path + break + } catch { + // Try the next candidate path. + } + } + + if (!flowConfigPath) { + return false + } + const raw = await readFile(flowConfigPath, "utf-8") + const parsed = JSON.parse(raw) as { nodes?: FlowNode[] } + const nodes = Array.isArray(parsed.nodes) ? parsed.nodes : [] + return nodes.some((node) => node?.data?.nodeId === "chatTriggerNode") + } catch { + return false + } +} + +/** + * Server-side legal guidance orchestration. + * This path requires an API Request trigger flow. + * The bundled flows/assistant-legal-advisor export uses Chat Widget trigger + * and is intended for client-side widget usage. + */ +export async function getLegalGuidance( + question: string, + jurisdiction: string, + context: string, +): Promise<{ + success: boolean + data?: LegalAssistantResult + error?: string +}> { + try { + if (await usesChatTriggerExport()) { + throw new Error( + "This flow export uses Chat Widget trigger and is not compatible with executeFlow API calls in this kit. Deploy an API Request trigger flow and update ASSISTANT_LEGAL_ADVISOR.", + ) + } + + const sanitizedQuestion = question.trim() + const sanitizedJurisdiction = jurisdiction.trim() + const sanitizedContext = context.trim() + + if (!sanitizedQuestion) { + throw new Error("Question is required") + } + + const flows = config.flows + const firstFlowKey = Object.keys(flows)[0] + + if (!firstFlowKey) { + throw new Error("No workflows found in configuration") + } + + const flow = flows[firstFlowKey as keyof typeof flows] as (typeof flows)[keyof typeof flows] + + if (!flow.workflowId) { + throw new Error("Workflow not found in config") + } + + const inputAliases: Record = { + question: sanitizedQuestion, + query: sanitizedQuestion, + userQuery: sanitizedQuestion, + prompt: sanitizedQuestion, + jurisdiction: sanitizedJurisdiction, + region: sanitizedJurisdiction, + context: sanitizedContext, + additionalContext: sanitizedContext, + details: sanitizedContext, + } + + const workflowInput: Record = {} + + for (const key of Object.keys(flow.inputSchema || {})) { + const value = inputAliases[key] + if (value !== undefined && value !== "") { + workflowInput[key] = value + } + } + + if (Object.keys(workflowInput).length === 0) { + workflowInput.question = sanitizedQuestion + if (sanitizedJurisdiction) { + workflowInput.jurisdiction = sanitizedJurisdiction + } + if (sanitizedContext) { + workflowInput.context = sanitizedContext + } + } + + const lamaticClient = getLamaticClient() + const response = await lamaticClient.executeFlow(flow.workflowId, workflowInput) + + if (response?.status === "error") { + throw new Error(response?.message || "Lamatic flow returned an error") + } + + const result = (response?.result ?? {}) as Record + + const answer = extractAnswer(result) + if (!answer) { + throw new Error("No answer found in flow response") + } + + const references = toStringArray( + result.references ?? result.citations ?? result.sources ?? result.statutes ?? result.caseLaws, + ) + const nextSteps = toStringArray(result.nextSteps ?? result.recommendedActions ?? result.actions ?? result.steps) + + const disclaimer = + typeof result.disclaimer === "string" && result.disclaimer.trim() + ? result.disclaimer.trim() + : DEFAULT_DISCLAIMER + + return { + success: true, + data: { + answer, + references, + nextSteps, + disclaimer, + }, + } + } catch (error) { + let errorMessage = "Unknown error occurred" + + if (error instanceof Error) { + errorMessage = error.message + if (error.message.includes("fetch failed")) { + errorMessage = + "Network error: Unable to connect to Lamatic service. Check your internet and try again." + } else if (error.message.toLowerCase().includes("timed out")) { + errorMessage = + "Lamatic request timed out. Your flow may be configured as Chat Widget trigger or long-running sync flow. Use an API Request trigger or async flow/polling for this kit." + } else if (error.message.includes("API key")) { + errorMessage = "Authentication error: Check your Lamatic API configuration." + } + } + + return { + success: false, + error: errorMessage, + } + } +} diff --git a/kits/assistant/legal/app/globals.css b/kits/assistant/legal/app/globals.css new file mode 100644 index 00000000..5c24153b --- /dev/null +++ b/kits/assistant/legal/app/globals.css @@ -0,0 +1,124 @@ +/* stylelint-disable at-rule-no-unknown scss/at-rule-no-unknown */ +@import 'tailwindcss'; +@import 'tw-animate-css'; + +:root { + --background: oklch(1 0 0); + --foreground: oklch(0.145 0 0); + --card: oklch(1 0 0); + --card-foreground: oklch(0.145 0 0); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.145 0 0); + --primary: oklch(0.205 0 0); + --primary-foreground: oklch(0.985 0 0); + --secondary: oklch(0.97 0 0); + --secondary-foreground: oklch(0.205 0 0); + --muted: oklch(0.97 0 0); + --muted-foreground: oklch(0.556 0 0); + --accent: oklch(0.97 0 0); + --accent-foreground: oklch(0.205 0 0); + --destructive: oklch(0.577 0.245 27.325); + --destructive-foreground: oklch(0.985 0 0); + --border: oklch(0.922 0 0); + --input: oklch(0.922 0 0); + --ring: oklch(0.708 0 0); + --chart-1: oklch(0.646 0.222 41.116); + --chart-2: oklch(0.6 0.118 184.704); + --chart-3: oklch(0.398 0.07 227.392); + --chart-4: oklch(0.828 0.189 84.429); + --chart-5: oklch(0.769 0.188 70.08); + --radius: 0.625rem; + --sidebar: oklch(0.985 0 0); + --sidebar-foreground: oklch(0.145 0 0); + --sidebar-primary: oklch(0.205 0 0); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.97 0 0); + --sidebar-accent-foreground: oklch(0.205 0 0); + --sidebar-border: oklch(0.922 0 0); + --sidebar-ring: oklch(0.708 0 0); +} + +.dark { + --background: oklch(0.145 0 0); + --foreground: oklch(0.985 0 0); + --card: oklch(0.145 0 0); + --card-foreground: oklch(0.985 0 0); + --popover: oklch(0.145 0 0); + --popover-foreground: oklch(0.985 0 0); + --primary: oklch(0.985 0 0); + --primary-foreground: oklch(0.205 0 0); + --secondary: oklch(0.269 0 0); + --secondary-foreground: oklch(0.985 0 0); + --muted: oklch(0.269 0 0); + --muted-foreground: oklch(0.708 0 0); + --accent: oklch(0.269 0 0); + --accent-foreground: oklch(0.985 0 0); + --destructive: oklch(0.396 0.141 25.723); + --destructive-foreground: oklch(0.637 0.237 25.331); + --border: oklch(0.269 0 0); + --input: oklch(0.269 0 0); + --ring: oklch(0.439 0 0); + --chart-1: oklch(0.488 0.243 264.376); + --chart-2: oklch(0.696 0.17 162.48); + --chart-3: oklch(0.769 0.188 70.08); + --chart-4: oklch(0.627 0.265 303.9); + --chart-5: oklch(0.645 0.246 16.439); + --sidebar: oklch(0.205 0 0); + --sidebar-foreground: oklch(0.985 0 0); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.269 0 0); + --sidebar-accent-foreground: oklch(0.985 0 0); + --sidebar-border: oklch(0.269 0 0); + --sidebar-ring: oklch(0.439 0 0); +} + +@theme inline { + --font-sans: 'Geist', 'Geist Fallback'; + --font-mono: 'Geist Mono', 'Geist Mono Fallback'; + --color-background: var(--background); + --color-foreground: var(--foreground); + --color-card: var(--card); + --color-card-foreground: var(--card-foreground); + --color-popover: var(--popover); + --color-popover-foreground: var(--popover-foreground); + --color-primary: var(--primary); + --color-primary-foreground: var(--primary-foreground); + --color-secondary: var(--secondary); + --color-secondary-foreground: var(--secondary-foreground); + --color-muted: var(--muted); + --color-muted-foreground: var(--muted-foreground); + --color-accent: var(--accent); + --color-accent-foreground: var(--accent-foreground); + --color-destructive: var(--destructive); + --color-destructive-foreground: var(--destructive-foreground); + --color-border: var(--border); + --color-input: var(--input); + --color-ring: var(--ring); + --color-chart-1: var(--chart-1); + --color-chart-2: var(--chart-2); + --color-chart-3: var(--chart-3); + --color-chart-4: var(--chart-4); + --color-chart-5: var(--chart-5); + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + --color-sidebar: var(--sidebar); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-ring: var(--sidebar-ring); +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/kits/assistant/legal/app/layout.tsx b/kits/assistant/legal/app/layout.tsx new file mode 100644 index 00000000..d6d0fa31 --- /dev/null +++ b/kits/assistant/legal/app/layout.tsx @@ -0,0 +1,49 @@ +import type { Metadata } from "next" +import { Geist, Geist_Mono } from "next/font/google" +import { Analytics } from "@vercel/analytics/next" +import "./globals.css" + +const geist = Geist({ subsets: ["latin"], variable: "--font-geist-sans" }) +const geistMono = Geist_Mono({ subsets: ["latin"], variable: "--font-geist-mono" }) + +export const metadata: Metadata = { + title: "Lamatic Legal Assistant", + description: + "Legal assistant chatbot starter kit for informational legal summaries, references, and recommended next steps.", + icons: { + icon: [ + { + url: "/icon-light-32x32.png", + media: "(prefers-color-scheme: light)", + }, + { + url: "/icon-dark-32x32.png", + media: "(prefers-color-scheme: dark)", + }, + { + url: "/icon.svg", + type: "image/svg+xml", + }, + ], + apple: "/apple-icon.png", + }, +} + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode +}>) { + return ( + + + {children} + + + + ) +} diff --git a/kits/assistant/legal/app/page.tsx b/kits/assistant/legal/app/page.tsx new file mode 100644 index 00000000..b8ad8b67 --- /dev/null +++ b/kits/assistant/legal/app/page.tsx @@ -0,0 +1,75 @@ +import { Header } from "@/components/header" +import { LegalAskWidget } from "@/components/legal-ask-widget" +import { Card } from "@/components/ui/card" +import { existsSync, readFileSync } from "node:fs" +import { join } from "node:path" + +type TriggerNodeId = "askTriggerNode" | "chatTriggerNode" | "unknown" + +function getTriggerType(): TriggerNodeId { + try { + const candidates = [ + join(process.cwd(), "flows", "assistant-legal-advisor", "config.json"), + join(process.cwd(), "kits", "assistant", "legal", "flows", "assistant-legal-advisor", "config.json"), + ] + const flowPath = candidates.find((path) => existsSync(path)) + if (!flowPath) { + return "unknown" + } + const parsed = JSON.parse(readFileSync(flowPath, "utf-8")) as { + nodes?: Array<{ data?: { nodeId?: string } }> + } + const nodeId = parsed.nodes?.find((node) => node?.data?.nodeId?.includes("TriggerNode"))?.data?.nodeId + + if (nodeId === "askTriggerNode" || nodeId === "chatTriggerNode") { + return nodeId + } + return "unknown" + } catch { + return "unknown" + } +} + +export default function LegalAssistantPage() { + const flowId = process.env.ASSISTANT_LEGAL_ADVISOR ?? "" + const apiUrl = process.env.LAMATIC_API_URL ?? "" + const projectId = process.env.LAMATIC_PROJECT_ID ?? "" + const triggerType = getTriggerType() + + const missing = [ + !flowId ? "ASSISTANT_LEGAL_ADVISOR" : null, + !apiUrl ? "LAMATIC_API_URL" : null, + !projectId ? "LAMATIC_PROJECT_ID" : null, + ].filter(Boolean) as string[] + + return ( +
+
+ +
+ +
+ Important: This assistant provides legal information, not legal advice. Always consult a + licensed attorney before making legal decisions. +
+
+ +
+

Legal Assistant

+

+ This kit is configured to use the Lamatic Ask Widget with your deployed ask-trigger flow. +

+
+ + {missing.length > 0 ? ( + +

Missing required environment variables:

+

{missing.join(", ")}

+
+ ) : ( + + )} +
+
+ ) +} diff --git a/kits/assistant/legal/components.json b/kits/assistant/legal/components.json new file mode 100644 index 00000000..4ee62ee1 --- /dev/null +++ b/kits/assistant/legal/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": true, + "tsx": true, + "tailwind": { + "config": "", + "css": "app/globals.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} diff --git a/kits/assistant/legal/components/header.tsx b/kits/assistant/legal/components/header.tsx new file mode 100644 index 00000000..43304b04 --- /dev/null +++ b/kits/assistant/legal/components/header.tsx @@ -0,0 +1,47 @@ +import Link from "next/link" +import { FileText, Github } from "lucide-react" +import Image from "next/image" + +export function Header() { + return ( +
+
+ +
+ Lamatic Logo +

+ Lamatic + Legal Assistant +

+
+ +
+ + + Docs + + + + GitHub + +
+
+
+ ) +} diff --git a/kits/assistant/legal/components/legal-ask-widget.tsx b/kits/assistant/legal/components/legal-ask-widget.tsx new file mode 100644 index 00000000..0e64b8ad --- /dev/null +++ b/kits/assistant/legal/components/legal-ask-widget.tsx @@ -0,0 +1,165 @@ +"use client" + +import { useEffect, useState } from "react" +import { Card } from "@/components/ui/card" + +type LegalAskWidgetProps = { + flowId: string + apiUrl: string + projectId: string + triggerType: "askTriggerNode" | "chatTriggerNode" | "unknown" +} + +export function LegalAskWidget({ flowId, apiUrl, projectId, triggerType }: LegalAskWidgetProps) { + const [ready, setReady] = useState(false) + const [error, setError] = useState("") + const configError = + !flowId || !apiUrl || !projectId + ? "Missing Flow ID, API URL, or Project ID for Ask Widget initialization." + : triggerType === "unknown" + ? "Unable to detect flow trigger type from exported flow config." + : "" + const resolvedError = configError || error + const isReady = configError ? false : ready + + useEffect(() => { + if (configError) { + return + } + + const isAsk = triggerType === "askTriggerNode" + const rootId = isAsk ? "lamatic-ask-root" : "lamatic-chat-root" + const scriptSrc = isAsk + ? `https://widget.lamatic.ai/ask?projectId=${projectId}` + : `https://widget.lamatic.ai/chat-v2?projectId=${projectId}` + const scriptMarker = isAsk ? "ask" : "chat" + const configPath = isAsk ? "askConfig" : "chatConfig" + + const controller = new AbortController() + let script: HTMLScriptElement | null = null + let cancelled = false + let disposeScriptListeners = () => {} + + const init = async () => { + const headers: Record = { + "Content-Type": "application/json", + } + + if (projectId) { + headers["x-project-id"] = projectId + } + + const configResponse = await fetch(`${apiUrl}/${configPath}?workflowId=${flowId}`, { + method: "GET", + headers, + signal: controller.signal, + }) + + if (!configResponse.ok) { + throw new Error( + `Lamatic ${configPath} returned ${configResponse.status}. Verify flow ID, deployment status, and trigger type.`, + ) + } + + if (cancelled) { + return + } + + let root = document.getElementById(rootId) as HTMLDivElement | null + if (!root) { + root = document.createElement("div") + root.id = rootId + document.body.appendChild(root) + } + + root.dataset.apiUrl = apiUrl + root.dataset.flowId = flowId + root.dataset.projectId = projectId + + script = document.querySelector(`script[data-lamatic-widget-kind="${scriptMarker}"]`) as HTMLScriptElement | null + if (!script) { + script = document.createElement("script") + script.type = "module" + script.src = scriptSrc + script.dataset.lamaticWidgetKind = scriptMarker + document.body.appendChild(script) + } + + const handleLoad = () => { + script?.setAttribute("data-loaded", "true") + if (!cancelled) { + setReady(true) + setError("") + } + } + + const handleError = () => { + if (!cancelled) { + setError("Failed to load Lamatic widget script.") + setReady(false) + } + } + + script.addEventListener("load", handleLoad) + script.addEventListener("error", handleError) + + if (script.getAttribute("data-loaded") === "true" && !cancelled) { + setReady(true) + setError("") + } + + disposeScriptListeners = () => { + script?.removeEventListener("load", handleLoad) + script?.removeEventListener("error", handleError) + } + } + + init() + .catch((err: unknown) => { + if (err instanceof DOMException && err.name === "AbortError") { + return + } + if (!cancelled) { + setReady(false) + setError(err instanceof Error ? err.message : "Failed to initialize Lamatic widget.") + } + }) + + return () => { + cancelled = true + controller.abort() + disposeScriptListeners() + } + }, [flowId, apiUrl, projectId, triggerType, configError]) + + return ( + +

+ {triggerType === "askTriggerNode" + ? "Ask trigger detected. Click the Ask button to open Lamatic Ask Widget." + : triggerType === "chatTriggerNode" + ? "Chat trigger detected. The Lamatic Chat Widget should appear automatically." + : "Unable to detect the exported flow trigger type."} +

+ + {triggerType === "askTriggerNode" && ( + + )} + + {isReady ? ( +

Lamatic Widget loaded successfully.

+ ) : ( +

Loading Lamatic Widget...

+ )} + + {resolvedError &&

{resolvedError}

} +
+ ) +} diff --git a/kits/assistant/legal/components/theme-provider.tsx b/kits/assistant/legal/components/theme-provider.tsx new file mode 100644 index 00000000..55c2f6eb --- /dev/null +++ b/kits/assistant/legal/components/theme-provider.tsx @@ -0,0 +1,11 @@ +'use client' + +import * as React from 'react' +import { + ThemeProvider as NextThemesProvider, + type ThemeProviderProps, +} from 'next-themes' + +export function ThemeProvider({ children, ...props }: ThemeProviderProps) { + return {children} +} diff --git a/kits/assistant/legal/components/ui/accordion.tsx b/kits/assistant/legal/components/ui/accordion.tsx new file mode 100644 index 00000000..e538a33b --- /dev/null +++ b/kits/assistant/legal/components/ui/accordion.tsx @@ -0,0 +1,66 @@ +'use client' + +import * as React from 'react' +import * as AccordionPrimitive from '@radix-ui/react-accordion' +import { ChevronDownIcon } from 'lucide-react' + +import { cn } from '@/lib/utils' + +function Accordion({ + ...props +}: React.ComponentProps) { + return +} + +function AccordionItem({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AccordionTrigger({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + svg]:rotate-180', + className, + )} + {...props} + > + {children} + + + + ) +} + +function AccordionContent({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + +
{children}
+
+ ) +} + +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } diff --git a/kits/assistant/legal/components/ui/alert-dialog.tsx b/kits/assistant/legal/components/ui/alert-dialog.tsx new file mode 100644 index 00000000..97044526 --- /dev/null +++ b/kits/assistant/legal/components/ui/alert-dialog.tsx @@ -0,0 +1,157 @@ +'use client' + +import * as React from 'react' +import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog' + +import { cn } from '@/lib/utils' +import { buttonVariants } from '@/components/ui/button' + +function AlertDialog({ + ...props +}: React.ComponentProps) { + return +} + +function AlertDialogTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogPortal({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogContent({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + + ) +} + +function AlertDialogHeader({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDialogFooter({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogAction({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogCancel({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + AlertDialog, + AlertDialogPortal, + AlertDialogOverlay, + AlertDialogTrigger, + AlertDialogContent, + AlertDialogHeader, + AlertDialogFooter, + AlertDialogTitle, + AlertDialogDescription, + AlertDialogAction, + AlertDialogCancel, +} diff --git a/kits/assistant/legal/components/ui/alert.tsx b/kits/assistant/legal/components/ui/alert.tsx new file mode 100644 index 00000000..e6751abe --- /dev/null +++ b/kits/assistant/legal/components/ui/alert.tsx @@ -0,0 +1,66 @@ +import * as React from 'react' +import { cva, type VariantProps } from 'class-variance-authority' + +import { cn } from '@/lib/utils' + +const alertVariants = cva( + 'relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current', + { + variants: { + variant: { + default: 'bg-card text-card-foreground', + destructive: + 'text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +function Alert({ + className, + variant, + ...props +}: React.ComponentProps<'div'> & VariantProps) { + return ( +
+ ) +} + +function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +function AlertDescription({ + className, + ...props +}: React.ComponentProps<'div'>) { + return ( +
+ ) +} + +export { Alert, AlertTitle, AlertDescription } diff --git a/kits/assistant/legal/components/ui/aspect-ratio.tsx b/kits/assistant/legal/components/ui/aspect-ratio.tsx new file mode 100644 index 00000000..40bb1208 --- /dev/null +++ b/kits/assistant/legal/components/ui/aspect-ratio.tsx @@ -0,0 +1,11 @@ +'use client' + +import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio' + +function AspectRatio({ + ...props +}: React.ComponentProps) { + return +} + +export { AspectRatio } diff --git a/kits/assistant/legal/components/ui/avatar.tsx b/kits/assistant/legal/components/ui/avatar.tsx new file mode 100644 index 00000000..aa98465a --- /dev/null +++ b/kits/assistant/legal/components/ui/avatar.tsx @@ -0,0 +1,53 @@ +'use client' + +import * as React from 'react' +import * as AvatarPrimitive from '@radix-ui/react-avatar' + +import { cn } from '@/lib/utils' + +function Avatar({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AvatarImage({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AvatarFallback({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { Avatar, AvatarImage, AvatarFallback } diff --git a/kits/assistant/legal/components/ui/badge.tsx b/kits/assistant/legal/components/ui/badge.tsx new file mode 100644 index 00000000..fc4126b7 --- /dev/null +++ b/kits/assistant/legal/components/ui/badge.tsx @@ -0,0 +1,46 @@ +import * as React from 'react' +import { Slot } from '@radix-ui/react-slot' +import { cva, type VariantProps } from 'class-variance-authority' + +import { cn } from '@/lib/utils' + +const badgeVariants = cva( + 'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden', + { + variants: { + variant: { + default: + 'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90', + secondary: + 'border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90', + destructive: + 'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60', + outline: + 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground', + }, + }, + defaultVariants: { + variant: 'default', + }, + }, +) + +function Badge({ + className, + variant, + asChild = false, + ...props +}: React.ComponentProps<'span'> & + VariantProps & { asChild?: boolean }) { + const Comp = asChild ? Slot : 'span' + + return ( + + ) +} + +export { Badge, badgeVariants } diff --git a/kits/assistant/legal/components/ui/breadcrumb.tsx b/kits/assistant/legal/components/ui/breadcrumb.tsx new file mode 100644 index 00000000..1750ff26 --- /dev/null +++ b/kits/assistant/legal/components/ui/breadcrumb.tsx @@ -0,0 +1,109 @@ +import * as React from 'react' +import { Slot } from '@radix-ui/react-slot' +import { ChevronRight, MoreHorizontal } from 'lucide-react' + +import { cn } from '@/lib/utils' + +function Breadcrumb({ ...props }: React.ComponentProps<'nav'>) { + return