create-claude-code-visualizer 0.1.0
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/index.js +393 -0
- package/package.json +31 -0
- package/templates/CLAUDE.md +108 -0
- package/templates/app/.env.local.example +14 -0
- package/templates/app/ecosystem.config.js +29 -0
- package/templates/app/next-env.d.ts +6 -0
- package/templates/app/next.config.ts +16 -0
- package/templates/app/package-lock.json +4581 -0
- package/templates/app/package.json +38 -0
- package/templates/app/postcss.config.js +5 -0
- package/templates/app/src/app/agents/[slug]/chat/loading.tsx +26 -0
- package/templates/app/src/app/agents/[slug]/chat/page.tsx +579 -0
- package/templates/app/src/app/agents/[slug]/loading.tsx +19 -0
- package/templates/app/src/app/agents/page.tsx +8 -0
- package/templates/app/src/app/api/agents/[slug]/capabilities/route.ts +11 -0
- package/templates/app/src/app/api/agents/[slug]/route.ts +57 -0
- package/templates/app/src/app/api/agents/route.ts +28 -0
- package/templates/app/src/app/api/ai/generate-agent/route.ts +87 -0
- package/templates/app/src/app/api/ai/improve-claude-md/route.ts +78 -0
- package/templates/app/src/app/api/ai/suggestions/route.ts +64 -0
- package/templates/app/src/app/api/ai/title/route.ts +88 -0
- package/templates/app/src/app/api/auth/role/route.ts +17 -0
- package/templates/app/src/app/api/commands/[slug]/route.ts +61 -0
- package/templates/app/src/app/api/commands/route.ts +6 -0
- package/templates/app/src/app/api/governance/costs/route.ts +117 -0
- package/templates/app/src/app/api/governance/sessions/route.ts +335 -0
- package/templates/app/src/app/api/notifications/route.ts +62 -0
- package/templates/app/src/app/api/preferences/route.ts +44 -0
- package/templates/app/src/app/api/runs/[id]/approve/route.ts +38 -0
- package/templates/app/src/app/api/runs/[id]/events/route.ts +28 -0
- package/templates/app/src/app/api/runs/[id]/metadata/route.ts +30 -0
- package/templates/app/src/app/api/runs/[id]/route.ts +21 -0
- package/templates/app/src/app/api/runs/[id]/start/route.ts +61 -0
- package/templates/app/src/app/api/runs/[id]/stop/route.ts +16 -0
- package/templates/app/src/app/api/runs/[id]/stream/route.ts +201 -0
- package/templates/app/src/app/api/runs/route.ts +95 -0
- package/templates/app/src/app/api/schedules/[id]/route.ts +81 -0
- package/templates/app/src/app/api/schedules/route.ts +75 -0
- package/templates/app/src/app/api/settings/access-logs/route.ts +33 -0
- package/templates/app/src/app/api/settings/claude-md/route.ts +44 -0
- package/templates/app/src/app/api/settings/env-keys/route.ts +271 -0
- package/templates/app/src/app/api/settings/users/route.ts +108 -0
- package/templates/app/src/app/api/skills/[slug]/route.ts +43 -0
- package/templates/app/src/app/api/skills/route.ts +6 -0
- package/templates/app/src/app/api/tools/route.ts +65 -0
- package/templates/app/src/app/api/uploads/cleanup/route.ts +29 -0
- package/templates/app/src/app/api/uploads/route.ts +77 -0
- package/templates/app/src/app/auth/callback/route.ts +19 -0
- package/templates/app/src/app/globals.css +115 -0
- package/templates/app/src/app/layout.tsx +24 -0
- package/templates/app/src/app/loading.tsx +16 -0
- package/templates/app/src/app/login/page.tsx +64 -0
- package/templates/app/src/app/not-authorized/page.tsx +33 -0
- package/templates/app/src/app/runs/page.tsx +55 -0
- package/templates/app/src/app/schedules/page.tsx +110 -0
- package/templates/app/src/app/settings/page.tsx +1294 -0
- package/templates/app/src/app/skills/page.tsx +7 -0
- package/templates/app/src/components/agent-card.tsx +58 -0
- package/templates/app/src/components/agent-grid.tsx +90 -0
- package/templates/app/src/components/auth/auth-context.tsx +79 -0
- package/templates/app/src/components/chat-thread.tsx +50 -0
- package/templates/app/src/components/chat-view.tsx +670 -0
- package/templates/app/src/components/commands-browser.tsx +349 -0
- package/templates/app/src/components/create-agent-modal.tsx +388 -0
- package/templates/app/src/components/governance-dashboard.tsx +397 -0
- package/templates/app/src/components/icons.tsx +401 -0
- package/templates/app/src/components/layout/agent-sidebar.tsx +504 -0
- package/templates/app/src/components/layout/app-shell.tsx +29 -0
- package/templates/app/src/components/layout/nav.tsx +87 -0
- package/templates/app/src/components/layout/overview-inner.tsx +14 -0
- package/templates/app/src/components/layout/profile-menu.tsx +95 -0
- package/templates/app/src/components/layout/sidebar.tsx +30 -0
- package/templates/app/src/components/markdown.tsx +57 -0
- package/templates/app/src/components/message-bar.tsx +161 -0
- package/templates/app/src/components/notifications/notification-bell.tsx +104 -0
- package/templates/app/src/components/notifications/notification-panel.tsx +116 -0
- package/templates/app/src/components/overview/overview-content.tsx +287 -0
- package/templates/app/src/components/overview/overview-context.tsx +88 -0
- package/templates/app/src/components/preferences-modal.tsx +112 -0
- package/templates/app/src/components/run-form.tsx +73 -0
- package/templates/app/src/components/run-history-table.tsx +226 -0
- package/templates/app/src/components/run-output.tsx +187 -0
- package/templates/app/src/components/schedule-form.tsx +148 -0
- package/templates/app/src/components/skills-browser.tsx +338 -0
- package/templates/app/src/components/tool-tooltip.tsx +82 -0
- package/templates/app/src/hooks/use-sse.ts +115 -0
- package/templates/app/src/instrumentation.ts +9 -0
- package/templates/app/src/lib/agent-cache.ts +19 -0
- package/templates/app/src/lib/agent-runner.ts +411 -0
- package/templates/app/src/lib/agents.ts +168 -0
- package/templates/app/src/lib/ai.ts +40 -0
- package/templates/app/src/lib/approval-store.ts +70 -0
- package/templates/app/src/lib/auth-guard.ts +116 -0
- package/templates/app/src/lib/capabilities.ts +191 -0
- package/templates/app/src/lib/line-diff.ts +96 -0
- package/templates/app/src/lib/queue.ts +22 -0
- package/templates/app/src/lib/redis.ts +12 -0
- package/templates/app/src/lib/role-permissions.ts +166 -0
- package/templates/app/src/lib/run-agent.ts +442 -0
- package/templates/app/src/lib/supabase-browser.ts +8 -0
- package/templates/app/src/lib/supabase-middleware.ts +63 -0
- package/templates/app/src/lib/supabase-server.ts +28 -0
- package/templates/app/src/lib/supabase.ts +6 -0
- package/templates/app/src/lib/tool-descriptions.ts +29 -0
- package/templates/app/src/lib/types.ts +73 -0
- package/templates/app/src/lib/typewriter-animation.ts +159 -0
- package/templates/app/src/middleware.ts +13 -0
- package/templates/app/tsconfig.json +21 -0
- package/templates/app/uploads/.gitkeep +0 -0
- package/templates/app/worker/index.ts +342 -0
- package/templates/claude/agents/ai-trends-scout.md +66 -0
- package/templates/claude/commands/add-to-todos.md +56 -0
- package/templates/claude/commands/check-todos.md +56 -0
- package/templates/claude/hooks/auto-approve-safe.sh +34 -0
- package/templates/claude/hooks/auto-format.sh +25 -0
- package/templates/claude/hooks/block-destructive.sh +32 -0
- package/templates/claude/hooks/compaction-preserver.sh +16 -0
- package/templates/claude/hooks/notify.sh +26 -0
- package/templates/claude/settings.local.json +66 -0
- package/templates/claude/skills/frontend-design/SKILL.md +127 -0
- package/templates/claude/skills/frontend-design/reference/color-and-contrast.md +132 -0
- package/templates/claude/skills/frontend-design/reference/interaction-design.md +123 -0
- package/templates/claude/skills/frontend-design/reference/motion-design.md +99 -0
- package/templates/claude/skills/frontend-design/reference/responsive-design.md +114 -0
- package/templates/claude/skills/frontend-design/reference/spatial-design.md +100 -0
- package/templates/claude/skills/frontend-design/reference/typography.md +131 -0
- package/templates/claude/skills/frontend-design/reference/ux-writing.md +107 -0
- package/templates/claude/skills/gws-admin-reports/SKILL.md +57 -0
- package/templates/claude/skills/gws-calendar/SKILL.md +108 -0
- package/templates/claude/skills/gws-calendar-agenda/SKILL.md +52 -0
- package/templates/claude/skills/gws-calendar-insert/SKILL.md +55 -0
- package/templates/claude/skills/gws-chat/SKILL.md +73 -0
- package/templates/claude/skills/gws-chat-send/SKILL.md +49 -0
- package/templates/claude/skills/gws-classroom/SKILL.md +75 -0
- package/templates/claude/skills/gws-docs/SKILL.md +48 -0
- package/templates/claude/skills/gws-docs-write/SKILL.md +49 -0
- package/templates/claude/skills/gws-drive/SKILL.md +137 -0
- package/templates/claude/skills/gws-drive-upload/SKILL.md +52 -0
- package/templates/claude/skills/gws-events/SKILL.md +67 -0
- package/templates/claude/skills/gws-events-renew/SKILL.md +48 -0
- package/templates/claude/skills/gws-events-subscribe/SKILL.md +59 -0
- package/templates/claude/skills/gws-forms/SKILL.md +45 -0
- package/templates/claude/skills/gws-gmail/SKILL.md +59 -0
- package/templates/claude/skills/gws-gmail-forward/SKILL.md +53 -0
- package/templates/claude/skills/gws-gmail-reply/SKILL.md +56 -0
- package/templates/claude/skills/gws-gmail-reply-all/SKILL.md +60 -0
- package/templates/claude/skills/gws-gmail-send/SKILL.md +55 -0
- package/templates/claude/skills/gws-gmail-triage/SKILL.md +50 -0
- package/templates/claude/skills/gws-gmail-watch/SKILL.md +58 -0
- package/templates/claude/skills/gws-keep/SKILL.md +48 -0
- package/templates/claude/skills/gws-meet/SKILL.md +51 -0
- package/templates/claude/skills/gws-modelarmor/SKILL.md +42 -0
- package/templates/claude/skills/gws-modelarmor-create-template/SKILL.md +53 -0
- package/templates/claude/skills/gws-modelarmor-sanitize-prompt/SKILL.md +48 -0
- package/templates/claude/skills/gws-modelarmor-sanitize-response/SKILL.md +48 -0
- package/templates/claude/skills/gws-people/SKILL.md +67 -0
- package/templates/claude/skills/gws-shared/SKILL.md +66 -0
- package/templates/claude/skills/gws-sheets/SKILL.md +53 -0
- package/templates/claude/skills/gws-sheets-append/SKILL.md +51 -0
- package/templates/claude/skills/gws-sheets-read/SKILL.md +47 -0
- package/templates/claude/skills/gws-slides/SKILL.md +43 -0
- package/templates/claude/skills/gws-tasks/SKILL.md +56 -0
- package/templates/claude/skills/gws-workflow/SKILL.md +44 -0
- package/templates/claude/skills/gws-workflow-email-to-task/SKILL.md +47 -0
- package/templates/claude/skills/gws-workflow-file-announce/SKILL.md +50 -0
- package/templates/claude/skills/gws-workflow-meeting-prep/SKILL.md +47 -0
- package/templates/claude/skills/gws-workflow-standup-report/SKILL.md +46 -0
- package/templates/claude/skills/gws-workflow-weekly-digest/SKILL.md +46 -0
- package/templates/claude/skills/persona-content-creator/SKILL.md +33 -0
- package/templates/claude/skills/persona-customer-support/SKILL.md +34 -0
- package/templates/claude/skills/persona-event-coordinator/SKILL.md +35 -0
- package/templates/claude/skills/persona-exec-assistant/SKILL.md +35 -0
- package/templates/claude/skills/persona-hr-coordinator/SKILL.md +33 -0
- package/templates/claude/skills/persona-it-admin/SKILL.md +30 -0
- package/templates/claude/skills/persona-project-manager/SKILL.md +35 -0
- package/templates/claude/skills/persona-researcher/SKILL.md +33 -0
- package/templates/claude/skills/persona-sales-ops/SKILL.md +35 -0
- package/templates/claude/skills/persona-team-lead/SKILL.md +36 -0
- package/templates/claude/skills/recipe-backup-sheet-as-csv/SKILL.md +25 -0
- package/templates/claude/skills/recipe-batch-invite-to-event/SKILL.md +25 -0
- package/templates/claude/skills/recipe-block-focus-time/SKILL.md +24 -0
- package/templates/claude/skills/recipe-bulk-download-folder/SKILL.md +25 -0
- package/templates/claude/skills/recipe-collect-form-responses/SKILL.md +25 -0
- package/templates/claude/skills/recipe-compare-sheet-tabs/SKILL.md +25 -0
- package/templates/claude/skills/recipe-copy-sheet-for-new-month/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-classroom-course/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-doc-from-template/SKILL.md +29 -0
- package/templates/claude/skills/recipe-create-events-from-sheet/SKILL.md +24 -0
- package/templates/claude/skills/recipe-create-expense-tracker/SKILL.md +26 -0
- package/templates/claude/skills/recipe-create-feedback-form/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-gmail-filter/SKILL.md +26 -0
- package/templates/claude/skills/recipe-create-meet-space/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-presentation/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-shared-drive/SKILL.md +25 -0
- package/templates/claude/skills/recipe-create-task-list/SKILL.md +26 -0
- package/templates/claude/skills/recipe-create-vacation-responder/SKILL.md +25 -0
- package/templates/claude/skills/recipe-draft-email-from-doc/SKILL.md +25 -0
- package/templates/claude/skills/recipe-email-drive-link/SKILL.md +25 -0
- package/templates/claude/skills/recipe-find-free-time/SKILL.md +25 -0
- package/templates/claude/skills/recipe-find-large-files/SKILL.md +24 -0
- package/templates/claude/skills/recipe-forward-labeled-emails/SKILL.md +27 -0
- package/templates/claude/skills/recipe-generate-report-from-sheet/SKILL.md +34 -0
- package/templates/claude/skills/recipe-label-and-archive-emails/SKILL.md +25 -0
- package/templates/claude/skills/recipe-log-deal-update/SKILL.md +25 -0
- package/templates/claude/skills/recipe-organize-drive-folder/SKILL.md +26 -0
- package/templates/claude/skills/recipe-plan-weekly-schedule/SKILL.md +26 -0
- package/templates/claude/skills/recipe-post-mortem-setup/SKILL.md +25 -0
- package/templates/claude/skills/recipe-reschedule-meeting/SKILL.md +25 -0
- package/templates/claude/skills/recipe-review-meet-participants/SKILL.md +25 -0
- package/templates/claude/skills/recipe-review-overdue-tasks/SKILL.md +25 -0
- package/templates/claude/skills/recipe-save-email-attachments/SKILL.md +26 -0
- package/templates/claude/skills/recipe-save-email-to-doc/SKILL.md +29 -0
- package/templates/claude/skills/recipe-schedule-recurring-event/SKILL.md +24 -0
- package/templates/claude/skills/recipe-send-team-announcement/SKILL.md +24 -0
- package/templates/claude/skills/recipe-share-doc-and-notify/SKILL.md +25 -0
- package/templates/claude/skills/recipe-share-event-materials/SKILL.md +25 -0
- package/templates/claude/skills/recipe-share-folder-with-team/SKILL.md +26 -0
- package/templates/claude/skills/recipe-sync-contacts-to-sheet/SKILL.md +25 -0
- package/templates/claude/skills/recipe-watch-drive-changes/SKILL.md +25 -0
- package/templates/mcp.json +12 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import type { AgentMeta } from "@/lib/types";
|
|
5
|
+
import { ChevronRightIcon } from "@/components/icons";
|
|
6
|
+
|
|
7
|
+
/** Tiny color dot derived from agent's assigned color */
|
|
8
|
+
function ColorDot({ color }: { color?: string }) {
|
|
9
|
+
if (!color) return null;
|
|
10
|
+
return (
|
|
11
|
+
<span
|
|
12
|
+
className="h-2 w-2 rounded-full shrink-0"
|
|
13
|
+
style={{ backgroundColor: color }}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function AgentCard({ agent }: { agent: AgentMeta }) {
|
|
19
|
+
return (
|
|
20
|
+
<Link
|
|
21
|
+
href={`/agents/${agent.slug}/chat`}
|
|
22
|
+
className="group flex items-center gap-3 px-3 py-2.5 rounded-md transition-colors hover:bg-[var(--bg-hover)]"
|
|
23
|
+
>
|
|
24
|
+
{/* Emoji or color dot */}
|
|
25
|
+
<span className="text-base shrink-0 w-6 text-center">
|
|
26
|
+
{agent.emoji || <ColorDot color={agent.color} />}
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
{/* Name + description */}
|
|
30
|
+
<div className="min-w-0 flex-1">
|
|
31
|
+
<div className="flex items-center gap-2">
|
|
32
|
+
<span className="text-[13px] font-medium text-[var(--text-primary)] truncate">
|
|
33
|
+
{agent.name}
|
|
34
|
+
</span>
|
|
35
|
+
<ColorDot color={agent.color} />
|
|
36
|
+
</div>
|
|
37
|
+
{agent.description && (
|
|
38
|
+
<p className="text-[12px] text-[var(--text-tertiary)] truncate mt-0.5">
|
|
39
|
+
{agent.description}
|
|
40
|
+
</p>
|
|
41
|
+
)}
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
{/* Tool count */}
|
|
45
|
+
{agent.tools.length > 0 && (
|
|
46
|
+
<span className="text-[11px] text-[var(--text-muted)] tabular-nums shrink-0">
|
|
47
|
+
{agent.tools.length} tools
|
|
48
|
+
</span>
|
|
49
|
+
)}
|
|
50
|
+
|
|
51
|
+
{/* Chevron */}
|
|
52
|
+
<ChevronRightIcon
|
|
53
|
+
size={14}
|
|
54
|
+
className="text-[var(--text-muted)] opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
|
|
55
|
+
/>
|
|
56
|
+
</Link>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { AgentCard } from "@/components/agent-card";
|
|
6
|
+
import { CreateAgentModal } from "@/components/create-agent-modal";
|
|
7
|
+
import { setAgentCache } from "@/lib/agent-cache";
|
|
8
|
+
import type { AgentMeta } from "@/lib/types";
|
|
9
|
+
import { PlusIcon } from "@/components/icons";
|
|
10
|
+
|
|
11
|
+
export function AgentGrid({ agents: initialAgents }: { agents: AgentMeta[] }) {
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
const [agents, setAgents] = useState(initialAgents);
|
|
14
|
+
const [showCreate, setShowCreate] = useState(false);
|
|
15
|
+
|
|
16
|
+
// Seed client-side cache
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setAgentCache(agents);
|
|
19
|
+
}, [agents]);
|
|
20
|
+
|
|
21
|
+
// Prefetch agent routes
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
for (const agent of agents) {
|
|
24
|
+
router.prefetch(`/agents/${agent.slug}`);
|
|
25
|
+
router.prefetch(`/agents/${agent.slug}/chat`);
|
|
26
|
+
}
|
|
27
|
+
}, [agents, router]);
|
|
28
|
+
|
|
29
|
+
const refreshAgents = () => {
|
|
30
|
+
fetch("/api/agents")
|
|
31
|
+
.then((r) => r.json())
|
|
32
|
+
.then((data: AgentMeta[]) => {
|
|
33
|
+
const specialists = data.filter((a) => a.slug !== "main");
|
|
34
|
+
setAgents(specialists);
|
|
35
|
+
setAgentCache(specialists);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Listen for agent list changes
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const handler = () => refreshAgents();
|
|
42
|
+
window.addEventListener("agents-updated", handler);
|
|
43
|
+
return () => window.removeEventListener("agents-updated", handler);
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div>
|
|
48
|
+
<div className="flex items-center justify-between mb-1">
|
|
49
|
+
<h2 className="text-[11px] font-medium uppercase tracking-wider text-[var(--text-tertiary)]">
|
|
50
|
+
Specialist Agents
|
|
51
|
+
</h2>
|
|
52
|
+
<button
|
|
53
|
+
onClick={() => setShowCreate(true)}
|
|
54
|
+
className="flex items-center gap-1.5 rounded-md px-2 py-1 text-[12px] text-[var(--text-tertiary)] hover:text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] transition-colors"
|
|
55
|
+
>
|
|
56
|
+
<PlusIcon size={14} />
|
|
57
|
+
New agent
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
{/* Agent list — no cards, just rows with subtle separators */}
|
|
62
|
+
<div className="border border-[var(--border-subtle)] rounded-lg divide-y divide-[var(--border-subtle)]">
|
|
63
|
+
{agents.map((agent) => (
|
|
64
|
+
<AgentCard key={agent.slug} agent={agent} />
|
|
65
|
+
))}
|
|
66
|
+
|
|
67
|
+
{agents.length === 0 && (
|
|
68
|
+
<div className="px-4 py-8 text-center">
|
|
69
|
+
<p className="text-[13px] text-[var(--text-tertiary)]">No agents yet</p>
|
|
70
|
+
<button
|
|
71
|
+
onClick={() => setShowCreate(true)}
|
|
72
|
+
className="mt-2 text-[13px] text-[var(--accent-text)] hover:text-[var(--accent-hover)] transition-colors"
|
|
73
|
+
>
|
|
74
|
+
Create your first agent
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<CreateAgentModal
|
|
81
|
+
open={showCreate}
|
|
82
|
+
onClose={() => setShowCreate(false)}
|
|
83
|
+
onCreated={() => {
|
|
84
|
+
refreshAgents();
|
|
85
|
+
window.dispatchEvent(new Event("agents-updated"));
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { createClient } from "@/lib/supabase-browser";
|
|
5
|
+
import type { User } from "@supabase/supabase-js";
|
|
6
|
+
|
|
7
|
+
export type Role = "admin" | "operator" | "viewer";
|
|
8
|
+
|
|
9
|
+
interface AuthContextValue {
|
|
10
|
+
user: User | null;
|
|
11
|
+
role: Role | null;
|
|
12
|
+
loading: boolean;
|
|
13
|
+
signOut: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const AuthContext = createContext<AuthContextValue>({
|
|
17
|
+
user: null,
|
|
18
|
+
role: null,
|
|
19
|
+
loading: true,
|
|
20
|
+
signOut: async () => {},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
24
|
+
const [user, setUser] = useState<User | null>(null);
|
|
25
|
+
const [role, setRole] = useState<Role | null>(null);
|
|
26
|
+
const [loading, setLoading] = useState(true);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const supabase = createClient();
|
|
30
|
+
|
|
31
|
+
// Get initial session
|
|
32
|
+
supabase.auth.getUser().then(({ data: { user } }) => {
|
|
33
|
+
setUser(user);
|
|
34
|
+
if (user) {
|
|
35
|
+
fetch("/api/auth/role")
|
|
36
|
+
.then((r) => r.json())
|
|
37
|
+
.then((data) => setRole(data.role))
|
|
38
|
+
.catch(() => {})
|
|
39
|
+
.finally(() => setLoading(false));
|
|
40
|
+
} else {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Listen for auth changes
|
|
46
|
+
const {
|
|
47
|
+
data: { subscription },
|
|
48
|
+
} = supabase.auth.onAuthStateChange((_event, session) => {
|
|
49
|
+
setUser(session?.user ?? null);
|
|
50
|
+
if (session?.user) {
|
|
51
|
+
fetch("/api/auth/role")
|
|
52
|
+
.then((r) => r.json())
|
|
53
|
+
.then((data) => setRole(data.role))
|
|
54
|
+
.catch(() => {});
|
|
55
|
+
} else {
|
|
56
|
+
setRole(null);
|
|
57
|
+
}
|
|
58
|
+
setLoading(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return () => subscription.unsubscribe();
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
async function signOut() {
|
|
65
|
+
const supabase = createClient();
|
|
66
|
+
await supabase.auth.signOut();
|
|
67
|
+
window.location.href = "/login";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<AuthContext.Provider value={{ user, role, loading, signOut }}>
|
|
72
|
+
{children}
|
|
73
|
+
</AuthContext.Provider>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function useAuth() {
|
|
78
|
+
return useContext(AuthContext);
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { AgentRun } from "@/lib/types";
|
|
4
|
+
|
|
5
|
+
function formatDuration(ms: number): string {
|
|
6
|
+
if (ms < 1000) return `${ms}ms`;
|
|
7
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function ChatThread({ runs }: { runs: AgentRun[] }) {
|
|
11
|
+
if (runs.length === 0) return null;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div className="space-y-4">
|
|
15
|
+
{runs.map((run) => (
|
|
16
|
+
<div key={run.id} className="space-y-2">
|
|
17
|
+
{/* User prompt */}
|
|
18
|
+
<div className="flex justify-end">
|
|
19
|
+
<div className="max-w-[75%] rounded-lg bg-[var(--bg-elevated)] px-4 py-2.5">
|
|
20
|
+
<p className="text-[13px] text-[var(--text-primary)] whitespace-pre-wrap">{run.prompt}</p>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
{/* Agent response */}
|
|
25
|
+
<div className="max-w-[90%]">
|
|
26
|
+
{run.status === "completed" && run.output ? (
|
|
27
|
+
<p className="text-[13px] text-[var(--text-secondary)] whitespace-pre-wrap break-words leading-relaxed">
|
|
28
|
+
{run.output}
|
|
29
|
+
</p>
|
|
30
|
+
) : run.status === "failed" ? (
|
|
31
|
+
<p className="text-[13px] text-red-400">
|
|
32
|
+
Failed: {run.error || "Unknown error"}
|
|
33
|
+
</p>
|
|
34
|
+
) : (
|
|
35
|
+
<p className="text-[13px] text-[var(--text-muted)] italic">
|
|
36
|
+
{run.status === "running" ? "Running..." : "Queued"}
|
|
37
|
+
</p>
|
|
38
|
+
)}
|
|
39
|
+
{run.status === "completed" && (
|
|
40
|
+
<div className="mt-1 flex gap-3 text-[10px] text-[var(--text-muted)] tabular-nums">
|
|
41
|
+
{run.cost_usd != null && <span>${run.cost_usd.toFixed(4)}</span>}
|
|
42
|
+
{run.duration_ms != null && <span>{formatDuration(run.duration_ms)}</span>}
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
))}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|