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.
Files changed (220) hide show
  1. package/index.js +393 -0
  2. package/package.json +31 -0
  3. package/templates/CLAUDE.md +108 -0
  4. package/templates/app/.env.local.example +14 -0
  5. package/templates/app/ecosystem.config.js +29 -0
  6. package/templates/app/next-env.d.ts +6 -0
  7. package/templates/app/next.config.ts +16 -0
  8. package/templates/app/package-lock.json +4581 -0
  9. package/templates/app/package.json +38 -0
  10. package/templates/app/postcss.config.js +5 -0
  11. package/templates/app/src/app/agents/[slug]/chat/loading.tsx +26 -0
  12. package/templates/app/src/app/agents/[slug]/chat/page.tsx +579 -0
  13. package/templates/app/src/app/agents/[slug]/loading.tsx +19 -0
  14. package/templates/app/src/app/agents/page.tsx +8 -0
  15. package/templates/app/src/app/api/agents/[slug]/capabilities/route.ts +11 -0
  16. package/templates/app/src/app/api/agents/[slug]/route.ts +57 -0
  17. package/templates/app/src/app/api/agents/route.ts +28 -0
  18. package/templates/app/src/app/api/ai/generate-agent/route.ts +87 -0
  19. package/templates/app/src/app/api/ai/improve-claude-md/route.ts +78 -0
  20. package/templates/app/src/app/api/ai/suggestions/route.ts +64 -0
  21. package/templates/app/src/app/api/ai/title/route.ts +88 -0
  22. package/templates/app/src/app/api/auth/role/route.ts +17 -0
  23. package/templates/app/src/app/api/commands/[slug]/route.ts +61 -0
  24. package/templates/app/src/app/api/commands/route.ts +6 -0
  25. package/templates/app/src/app/api/governance/costs/route.ts +117 -0
  26. package/templates/app/src/app/api/governance/sessions/route.ts +335 -0
  27. package/templates/app/src/app/api/notifications/route.ts +62 -0
  28. package/templates/app/src/app/api/preferences/route.ts +44 -0
  29. package/templates/app/src/app/api/runs/[id]/approve/route.ts +38 -0
  30. package/templates/app/src/app/api/runs/[id]/events/route.ts +28 -0
  31. package/templates/app/src/app/api/runs/[id]/metadata/route.ts +30 -0
  32. package/templates/app/src/app/api/runs/[id]/route.ts +21 -0
  33. package/templates/app/src/app/api/runs/[id]/start/route.ts +61 -0
  34. package/templates/app/src/app/api/runs/[id]/stop/route.ts +16 -0
  35. package/templates/app/src/app/api/runs/[id]/stream/route.ts +201 -0
  36. package/templates/app/src/app/api/runs/route.ts +95 -0
  37. package/templates/app/src/app/api/schedules/[id]/route.ts +81 -0
  38. package/templates/app/src/app/api/schedules/route.ts +75 -0
  39. package/templates/app/src/app/api/settings/access-logs/route.ts +33 -0
  40. package/templates/app/src/app/api/settings/claude-md/route.ts +44 -0
  41. package/templates/app/src/app/api/settings/env-keys/route.ts +271 -0
  42. package/templates/app/src/app/api/settings/users/route.ts +108 -0
  43. package/templates/app/src/app/api/skills/[slug]/route.ts +43 -0
  44. package/templates/app/src/app/api/skills/route.ts +6 -0
  45. package/templates/app/src/app/api/tools/route.ts +65 -0
  46. package/templates/app/src/app/api/uploads/cleanup/route.ts +29 -0
  47. package/templates/app/src/app/api/uploads/route.ts +77 -0
  48. package/templates/app/src/app/auth/callback/route.ts +19 -0
  49. package/templates/app/src/app/globals.css +115 -0
  50. package/templates/app/src/app/layout.tsx +24 -0
  51. package/templates/app/src/app/loading.tsx +16 -0
  52. package/templates/app/src/app/login/page.tsx +64 -0
  53. package/templates/app/src/app/not-authorized/page.tsx +33 -0
  54. package/templates/app/src/app/runs/page.tsx +55 -0
  55. package/templates/app/src/app/schedules/page.tsx +110 -0
  56. package/templates/app/src/app/settings/page.tsx +1294 -0
  57. package/templates/app/src/app/skills/page.tsx +7 -0
  58. package/templates/app/src/components/agent-card.tsx +58 -0
  59. package/templates/app/src/components/agent-grid.tsx +90 -0
  60. package/templates/app/src/components/auth/auth-context.tsx +79 -0
  61. package/templates/app/src/components/chat-thread.tsx +50 -0
  62. package/templates/app/src/components/chat-view.tsx +670 -0
  63. package/templates/app/src/components/commands-browser.tsx +349 -0
  64. package/templates/app/src/components/create-agent-modal.tsx +388 -0
  65. package/templates/app/src/components/governance-dashboard.tsx +397 -0
  66. package/templates/app/src/components/icons.tsx +401 -0
  67. package/templates/app/src/components/layout/agent-sidebar.tsx +504 -0
  68. package/templates/app/src/components/layout/app-shell.tsx +29 -0
  69. package/templates/app/src/components/layout/nav.tsx +87 -0
  70. package/templates/app/src/components/layout/overview-inner.tsx +14 -0
  71. package/templates/app/src/components/layout/profile-menu.tsx +95 -0
  72. package/templates/app/src/components/layout/sidebar.tsx +30 -0
  73. package/templates/app/src/components/markdown.tsx +57 -0
  74. package/templates/app/src/components/message-bar.tsx +161 -0
  75. package/templates/app/src/components/notifications/notification-bell.tsx +104 -0
  76. package/templates/app/src/components/notifications/notification-panel.tsx +116 -0
  77. package/templates/app/src/components/overview/overview-content.tsx +287 -0
  78. package/templates/app/src/components/overview/overview-context.tsx +88 -0
  79. package/templates/app/src/components/preferences-modal.tsx +112 -0
  80. package/templates/app/src/components/run-form.tsx +73 -0
  81. package/templates/app/src/components/run-history-table.tsx +226 -0
  82. package/templates/app/src/components/run-output.tsx +187 -0
  83. package/templates/app/src/components/schedule-form.tsx +148 -0
  84. package/templates/app/src/components/skills-browser.tsx +338 -0
  85. package/templates/app/src/components/tool-tooltip.tsx +82 -0
  86. package/templates/app/src/hooks/use-sse.ts +115 -0
  87. package/templates/app/src/instrumentation.ts +9 -0
  88. package/templates/app/src/lib/agent-cache.ts +19 -0
  89. package/templates/app/src/lib/agent-runner.ts +411 -0
  90. package/templates/app/src/lib/agents.ts +168 -0
  91. package/templates/app/src/lib/ai.ts +40 -0
  92. package/templates/app/src/lib/approval-store.ts +70 -0
  93. package/templates/app/src/lib/auth-guard.ts +116 -0
  94. package/templates/app/src/lib/capabilities.ts +191 -0
  95. package/templates/app/src/lib/line-diff.ts +96 -0
  96. package/templates/app/src/lib/queue.ts +22 -0
  97. package/templates/app/src/lib/redis.ts +12 -0
  98. package/templates/app/src/lib/role-permissions.ts +166 -0
  99. package/templates/app/src/lib/run-agent.ts +442 -0
  100. package/templates/app/src/lib/supabase-browser.ts +8 -0
  101. package/templates/app/src/lib/supabase-middleware.ts +63 -0
  102. package/templates/app/src/lib/supabase-server.ts +28 -0
  103. package/templates/app/src/lib/supabase.ts +6 -0
  104. package/templates/app/src/lib/tool-descriptions.ts +29 -0
  105. package/templates/app/src/lib/types.ts +73 -0
  106. package/templates/app/src/lib/typewriter-animation.ts +159 -0
  107. package/templates/app/src/middleware.ts +13 -0
  108. package/templates/app/tsconfig.json +21 -0
  109. package/templates/app/uploads/.gitkeep +0 -0
  110. package/templates/app/worker/index.ts +342 -0
  111. package/templates/claude/agents/ai-trends-scout.md +66 -0
  112. package/templates/claude/commands/add-to-todos.md +56 -0
  113. package/templates/claude/commands/check-todos.md +56 -0
  114. package/templates/claude/hooks/auto-approve-safe.sh +34 -0
  115. package/templates/claude/hooks/auto-format.sh +25 -0
  116. package/templates/claude/hooks/block-destructive.sh +32 -0
  117. package/templates/claude/hooks/compaction-preserver.sh +16 -0
  118. package/templates/claude/hooks/notify.sh +26 -0
  119. package/templates/claude/settings.local.json +66 -0
  120. package/templates/claude/skills/frontend-design/SKILL.md +127 -0
  121. package/templates/claude/skills/frontend-design/reference/color-and-contrast.md +132 -0
  122. package/templates/claude/skills/frontend-design/reference/interaction-design.md +123 -0
  123. package/templates/claude/skills/frontend-design/reference/motion-design.md +99 -0
  124. package/templates/claude/skills/frontend-design/reference/responsive-design.md +114 -0
  125. package/templates/claude/skills/frontend-design/reference/spatial-design.md +100 -0
  126. package/templates/claude/skills/frontend-design/reference/typography.md +131 -0
  127. package/templates/claude/skills/frontend-design/reference/ux-writing.md +107 -0
  128. package/templates/claude/skills/gws-admin-reports/SKILL.md +57 -0
  129. package/templates/claude/skills/gws-calendar/SKILL.md +108 -0
  130. package/templates/claude/skills/gws-calendar-agenda/SKILL.md +52 -0
  131. package/templates/claude/skills/gws-calendar-insert/SKILL.md +55 -0
  132. package/templates/claude/skills/gws-chat/SKILL.md +73 -0
  133. package/templates/claude/skills/gws-chat-send/SKILL.md +49 -0
  134. package/templates/claude/skills/gws-classroom/SKILL.md +75 -0
  135. package/templates/claude/skills/gws-docs/SKILL.md +48 -0
  136. package/templates/claude/skills/gws-docs-write/SKILL.md +49 -0
  137. package/templates/claude/skills/gws-drive/SKILL.md +137 -0
  138. package/templates/claude/skills/gws-drive-upload/SKILL.md +52 -0
  139. package/templates/claude/skills/gws-events/SKILL.md +67 -0
  140. package/templates/claude/skills/gws-events-renew/SKILL.md +48 -0
  141. package/templates/claude/skills/gws-events-subscribe/SKILL.md +59 -0
  142. package/templates/claude/skills/gws-forms/SKILL.md +45 -0
  143. package/templates/claude/skills/gws-gmail/SKILL.md +59 -0
  144. package/templates/claude/skills/gws-gmail-forward/SKILL.md +53 -0
  145. package/templates/claude/skills/gws-gmail-reply/SKILL.md +56 -0
  146. package/templates/claude/skills/gws-gmail-reply-all/SKILL.md +60 -0
  147. package/templates/claude/skills/gws-gmail-send/SKILL.md +55 -0
  148. package/templates/claude/skills/gws-gmail-triage/SKILL.md +50 -0
  149. package/templates/claude/skills/gws-gmail-watch/SKILL.md +58 -0
  150. package/templates/claude/skills/gws-keep/SKILL.md +48 -0
  151. package/templates/claude/skills/gws-meet/SKILL.md +51 -0
  152. package/templates/claude/skills/gws-modelarmor/SKILL.md +42 -0
  153. package/templates/claude/skills/gws-modelarmor-create-template/SKILL.md +53 -0
  154. package/templates/claude/skills/gws-modelarmor-sanitize-prompt/SKILL.md +48 -0
  155. package/templates/claude/skills/gws-modelarmor-sanitize-response/SKILL.md +48 -0
  156. package/templates/claude/skills/gws-people/SKILL.md +67 -0
  157. package/templates/claude/skills/gws-shared/SKILL.md +66 -0
  158. package/templates/claude/skills/gws-sheets/SKILL.md +53 -0
  159. package/templates/claude/skills/gws-sheets-append/SKILL.md +51 -0
  160. package/templates/claude/skills/gws-sheets-read/SKILL.md +47 -0
  161. package/templates/claude/skills/gws-slides/SKILL.md +43 -0
  162. package/templates/claude/skills/gws-tasks/SKILL.md +56 -0
  163. package/templates/claude/skills/gws-workflow/SKILL.md +44 -0
  164. package/templates/claude/skills/gws-workflow-email-to-task/SKILL.md +47 -0
  165. package/templates/claude/skills/gws-workflow-file-announce/SKILL.md +50 -0
  166. package/templates/claude/skills/gws-workflow-meeting-prep/SKILL.md +47 -0
  167. package/templates/claude/skills/gws-workflow-standup-report/SKILL.md +46 -0
  168. package/templates/claude/skills/gws-workflow-weekly-digest/SKILL.md +46 -0
  169. package/templates/claude/skills/persona-content-creator/SKILL.md +33 -0
  170. package/templates/claude/skills/persona-customer-support/SKILL.md +34 -0
  171. package/templates/claude/skills/persona-event-coordinator/SKILL.md +35 -0
  172. package/templates/claude/skills/persona-exec-assistant/SKILL.md +35 -0
  173. package/templates/claude/skills/persona-hr-coordinator/SKILL.md +33 -0
  174. package/templates/claude/skills/persona-it-admin/SKILL.md +30 -0
  175. package/templates/claude/skills/persona-project-manager/SKILL.md +35 -0
  176. package/templates/claude/skills/persona-researcher/SKILL.md +33 -0
  177. package/templates/claude/skills/persona-sales-ops/SKILL.md +35 -0
  178. package/templates/claude/skills/persona-team-lead/SKILL.md +36 -0
  179. package/templates/claude/skills/recipe-backup-sheet-as-csv/SKILL.md +25 -0
  180. package/templates/claude/skills/recipe-batch-invite-to-event/SKILL.md +25 -0
  181. package/templates/claude/skills/recipe-block-focus-time/SKILL.md +24 -0
  182. package/templates/claude/skills/recipe-bulk-download-folder/SKILL.md +25 -0
  183. package/templates/claude/skills/recipe-collect-form-responses/SKILL.md +25 -0
  184. package/templates/claude/skills/recipe-compare-sheet-tabs/SKILL.md +25 -0
  185. package/templates/claude/skills/recipe-copy-sheet-for-new-month/SKILL.md +25 -0
  186. package/templates/claude/skills/recipe-create-classroom-course/SKILL.md +25 -0
  187. package/templates/claude/skills/recipe-create-doc-from-template/SKILL.md +29 -0
  188. package/templates/claude/skills/recipe-create-events-from-sheet/SKILL.md +24 -0
  189. package/templates/claude/skills/recipe-create-expense-tracker/SKILL.md +26 -0
  190. package/templates/claude/skills/recipe-create-feedback-form/SKILL.md +25 -0
  191. package/templates/claude/skills/recipe-create-gmail-filter/SKILL.md +26 -0
  192. package/templates/claude/skills/recipe-create-meet-space/SKILL.md +25 -0
  193. package/templates/claude/skills/recipe-create-presentation/SKILL.md +25 -0
  194. package/templates/claude/skills/recipe-create-shared-drive/SKILL.md +25 -0
  195. package/templates/claude/skills/recipe-create-task-list/SKILL.md +26 -0
  196. package/templates/claude/skills/recipe-create-vacation-responder/SKILL.md +25 -0
  197. package/templates/claude/skills/recipe-draft-email-from-doc/SKILL.md +25 -0
  198. package/templates/claude/skills/recipe-email-drive-link/SKILL.md +25 -0
  199. package/templates/claude/skills/recipe-find-free-time/SKILL.md +25 -0
  200. package/templates/claude/skills/recipe-find-large-files/SKILL.md +24 -0
  201. package/templates/claude/skills/recipe-forward-labeled-emails/SKILL.md +27 -0
  202. package/templates/claude/skills/recipe-generate-report-from-sheet/SKILL.md +34 -0
  203. package/templates/claude/skills/recipe-label-and-archive-emails/SKILL.md +25 -0
  204. package/templates/claude/skills/recipe-log-deal-update/SKILL.md +25 -0
  205. package/templates/claude/skills/recipe-organize-drive-folder/SKILL.md +26 -0
  206. package/templates/claude/skills/recipe-plan-weekly-schedule/SKILL.md +26 -0
  207. package/templates/claude/skills/recipe-post-mortem-setup/SKILL.md +25 -0
  208. package/templates/claude/skills/recipe-reschedule-meeting/SKILL.md +25 -0
  209. package/templates/claude/skills/recipe-review-meet-participants/SKILL.md +25 -0
  210. package/templates/claude/skills/recipe-review-overdue-tasks/SKILL.md +25 -0
  211. package/templates/claude/skills/recipe-save-email-attachments/SKILL.md +26 -0
  212. package/templates/claude/skills/recipe-save-email-to-doc/SKILL.md +29 -0
  213. package/templates/claude/skills/recipe-schedule-recurring-event/SKILL.md +24 -0
  214. package/templates/claude/skills/recipe-send-team-announcement/SKILL.md +24 -0
  215. package/templates/claude/skills/recipe-share-doc-and-notify/SKILL.md +25 -0
  216. package/templates/claude/skills/recipe-share-event-materials/SKILL.md +25 -0
  217. package/templates/claude/skills/recipe-share-folder-with-team/SKILL.md +26 -0
  218. package/templates/claude/skills/recipe-sync-contacts-to-sheet/SKILL.md +25 -0
  219. package/templates/claude/skills/recipe-watch-drive-changes/SKILL.md +25 -0
  220. package/templates/mcp.json +12 -0
@@ -0,0 +1,7 @@
1
+ "use client";
2
+
3
+ export default function SkillsPage() {
4
+ // This page is handled by the overview tab system.
5
+ // The OverviewProvider detects /skills and activates the skills tab.
6
+ return null;
7
+ }
@@ -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
+ }