codeblog-app 2.2.6 → 2.3.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 (69) hide show
  1. package/package.json +8 -71
  2. package/drizzle/0000_init.sql +0 -34
  3. package/drizzle/meta/_journal.json +0 -13
  4. package/drizzle.config.ts +0 -10
  5. package/src/ai/__tests__/chat.test.ts +0 -179
  6. package/src/ai/__tests__/provider.test.ts +0 -198
  7. package/src/ai/__tests__/tools.test.ts +0 -93
  8. package/src/ai/chat.ts +0 -224
  9. package/src/ai/configure.ts +0 -134
  10. package/src/ai/provider.ts +0 -302
  11. package/src/ai/tools.ts +0 -114
  12. package/src/auth/index.ts +0 -47
  13. package/src/auth/oauth.ts +0 -108
  14. package/src/cli/__tests__/commands.test.ts +0 -225
  15. package/src/cli/cmd/agent.ts +0 -97
  16. package/src/cli/cmd/chat.ts +0 -190
  17. package/src/cli/cmd/comment.ts +0 -67
  18. package/src/cli/cmd/config.ts +0 -153
  19. package/src/cli/cmd/feed.ts +0 -53
  20. package/src/cli/cmd/forum.ts +0 -106
  21. package/src/cli/cmd/login.ts +0 -45
  22. package/src/cli/cmd/logout.ts +0 -12
  23. package/src/cli/cmd/me.ts +0 -188
  24. package/src/cli/cmd/post.ts +0 -25
  25. package/src/cli/cmd/publish.ts +0 -64
  26. package/src/cli/cmd/scan.ts +0 -78
  27. package/src/cli/cmd/search.ts +0 -35
  28. package/src/cli/cmd/setup.ts +0 -352
  29. package/src/cli/cmd/tui.ts +0 -20
  30. package/src/cli/cmd/uninstall.ts +0 -281
  31. package/src/cli/cmd/update.ts +0 -123
  32. package/src/cli/cmd/vote.ts +0 -50
  33. package/src/cli/cmd/whoami.ts +0 -18
  34. package/src/cli/mcp-print.ts +0 -6
  35. package/src/cli/ui.ts +0 -250
  36. package/src/config/index.ts +0 -55
  37. package/src/flag/index.ts +0 -23
  38. package/src/global/index.ts +0 -38
  39. package/src/id/index.ts +0 -20
  40. package/src/index.ts +0 -200
  41. package/src/mcp/__tests__/client.test.ts +0 -149
  42. package/src/mcp/__tests__/e2e.ts +0 -327
  43. package/src/mcp/__tests__/integration.ts +0 -148
  44. package/src/mcp/client.ts +0 -148
  45. package/src/server/index.ts +0 -48
  46. package/src/storage/chat.ts +0 -71
  47. package/src/storage/db.ts +0 -85
  48. package/src/storage/schema.sql.ts +0 -39
  49. package/src/storage/schema.ts +0 -1
  50. package/src/tui/app.tsx +0 -184
  51. package/src/tui/commands.ts +0 -186
  52. package/src/tui/context/exit.tsx +0 -15
  53. package/src/tui/context/helper.tsx +0 -25
  54. package/src/tui/context/route.tsx +0 -24
  55. package/src/tui/context/theme.tsx +0 -470
  56. package/src/tui/routes/home.tsx +0 -660
  57. package/src/tui/routes/model.tsx +0 -210
  58. package/src/tui/routes/notifications.tsx +0 -87
  59. package/src/tui/routes/post.tsx +0 -102
  60. package/src/tui/routes/search.tsx +0 -105
  61. package/src/tui/routes/setup.tsx +0 -255
  62. package/src/tui/routes/trending.tsx +0 -107
  63. package/src/util/__tests__/context.test.ts +0 -31
  64. package/src/util/__tests__/lazy.test.ts +0 -37
  65. package/src/util/context.ts +0 -23
  66. package/src/util/error.ts +0 -46
  67. package/src/util/lazy.ts +0 -18
  68. package/src/util/log.ts +0 -142
  69. package/tsconfig.json +0 -11
package/src/tui/app.tsx DELETED
@@ -1,184 +0,0 @@
1
- import { render, useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
2
- import { Switch, Match, onMount, createSignal, Show } from "solid-js"
3
- import { RouteProvider, useRoute } from "./context/route"
4
- import { ExitProvider, useExit } from "./context/exit"
5
- import { ThemeProvider, useTheme } from "./context/theme"
6
- import { Home } from "./routes/home"
7
- import { ThemePicker } from "./routes/setup"
8
- import { ModelPicker } from "./routes/model"
9
- import { Post } from "./routes/post"
10
- import { Search } from "./routes/search"
11
- import { Trending } from "./routes/trending"
12
- import { Notifications } from "./routes/notifications"
13
-
14
- import pkg from "../../package.json"
15
- const VERSION = pkg.version
16
-
17
- export function tui(input: { onExit?: () => Promise<void> }) {
18
- return new Promise<void>(async (resolve) => {
19
- render(
20
- () => (
21
- <ExitProvider onExit={async () => { await input.onExit?.(); resolve() }}>
22
- <ThemeProvider>
23
- <RouteProvider>
24
- <App />
25
- </RouteProvider>
26
- </ThemeProvider>
27
- </ExitProvider>
28
- ),
29
- {
30
- targetFps: 30,
31
- exitOnCtrlC: false,
32
- autoFocus: false,
33
- openConsoleOnError: false,
34
- },
35
- )
36
- })
37
- }
38
-
39
- function App() {
40
- const route = useRoute()
41
- const exit = useExit()
42
- const theme = useTheme()
43
- const dimensions = useTerminalDimensions()
44
- const renderer = useRenderer()
45
- const [loggedIn, setLoggedIn] = createSignal(false)
46
- const [username, setUsername] = createSignal("")
47
- const [activeAgent, setActiveAgent] = createSignal("")
48
- const [hasAI, setHasAI] = createSignal(false)
49
- const [aiProvider, setAiProvider] = createSignal("")
50
- const [modelName, setModelName] = createSignal("")
51
-
52
- async function refreshAI() {
53
- try {
54
- const { AIProvider } = await import("../ai/provider")
55
- const has = await AIProvider.hasAnyKey()
56
- setHasAI(has)
57
- if (has) {
58
- const { Config } = await import("../config")
59
- const cfg = await Config.load()
60
- const model = cfg.model || AIProvider.DEFAULT_MODEL
61
- setModelName(model)
62
- const info = AIProvider.BUILTIN_MODELS[model]
63
- setAiProvider(info?.providerID || model.split("/")[0] || "ai")
64
- }
65
- } catch {}
66
- }
67
-
68
- onMount(async () => {
69
- renderer.setTerminalTitle("CodeBlog")
70
-
71
- // Check auth status
72
- try {
73
- const { Auth } = await import("../auth")
74
- const authenticated = await Auth.authenticated()
75
- setLoggedIn(authenticated)
76
- if (authenticated) {
77
- const token = await Auth.get()
78
- if (token?.username) setUsername(token.username)
79
- }
80
- } catch {}
81
-
82
- // Get active agent
83
- try {
84
- const { Config } = await import("../config")
85
- const cfg = await Config.load()
86
- if (cfg.activeAgent) {
87
- setActiveAgent(cfg.activeAgent)
88
- } else if (loggedIn()) {
89
- // If logged in but no activeAgent cached, fetch from API
90
- const { Auth } = await import("../auth")
91
- const tok = await Auth.get()
92
- if (tok?.type === "apikey" && tok.value) {
93
- try {
94
- const base = await Config.url()
95
- const res = await fetch(`${base}/api/v1/agents/me`, {
96
- headers: { Authorization: `Bearer ${tok.value}` },
97
- })
98
- if (res.ok) {
99
- const data = await res.json() as { agent?: { name?: string } }
100
- if (data.agent?.name) {
101
- setActiveAgent(data.agent.name)
102
- await Config.save({ activeAgent: data.agent.name })
103
- }
104
- }
105
- } catch {}
106
- }
107
- }
108
- } catch {}
109
-
110
- await refreshAI()
111
- })
112
-
113
- useKeyboard((evt) => {
114
- if (evt.ctrl && evt.name === "c") {
115
- exit()
116
- evt.preventDefault()
117
- return
118
- }
119
-
120
- // Back navigation from sub-pages
121
- if (evt.name === "escape" && route.data.type !== "home") {
122
- route.navigate({ type: "home" })
123
- evt.preventDefault()
124
- return
125
- }
126
- })
127
-
128
- return (
129
- <box flexDirection="column" width={dimensions().width} height={dimensions().height}>
130
- <Switch>
131
- <Match when={route.data.type === "home"}>
132
- <Home
133
- loggedIn={loggedIn()}
134
- username={username()}
135
- activeAgent={activeAgent()}
136
- hasAI={hasAI()}
137
- aiProvider={aiProvider()}
138
- modelName={modelName()}
139
- onLogin={async () => {
140
- try {
141
- const { OAuth } = await import("../auth/oauth")
142
- await OAuth.login()
143
- const { Auth } = await import("../auth")
144
- setLoggedIn(true)
145
- const token = await Auth.get()
146
- if (token?.username) setUsername(token.username)
147
- } catch {}
148
- }}
149
- onLogout={() => { setLoggedIn(false); setUsername("") }}
150
- onAIConfigured={refreshAI}
151
- />
152
- </Match>
153
- <Match when={route.data.type === "theme"}>
154
- <ThemePicker onDone={() => route.navigate({ type: "home" })} />
155
- </Match>
156
- <Match when={route.data.type === "model"}>
157
- <ModelPicker onDone={async (model) => {
158
- if (model) setModelName(model)
159
- await refreshAI()
160
- route.navigate({ type: "home" })
161
- }} />
162
- </Match>
163
- <Match when={route.data.type === "post"}>
164
- <Post />
165
- </Match>
166
- <Match when={route.data.type === "search"}>
167
- <Search />
168
- </Match>
169
- <Match when={route.data.type === "trending"}>
170
- <Trending />
171
- </Match>
172
- <Match when={route.data.type === "notifications"}>
173
- <Notifications />
174
- </Match>
175
- </Switch>
176
-
177
- {/* Status bar — only version */}
178
- <box paddingLeft={2} paddingRight={2} flexShrink={0} flexDirection="row" gap={2}>
179
- <box flexGrow={1} />
180
- <text fg={theme.colors.textMuted}>v{VERSION}</text>
181
- </box>
182
- </box>
183
- )
184
- }
@@ -1,186 +0,0 @@
1
- // Slash command definitions for the TUI home screen
2
-
3
- export interface CmdDef {
4
- name: string
5
- description: string
6
- needsAI?: boolean
7
- action: (parts: string[]) => void | Promise<void>
8
- }
9
-
10
- export interface CommandDeps {
11
- showMsg: (text: string, color?: string) => void
12
- navigate: (route: any) => void
13
- exit: () => void
14
- onLogin: () => Promise<void>
15
- onLogout: () => void
16
- clearChat: () => void
17
- startAIConfig: () => void
18
- setMode: (mode: "dark" | "light") => void
19
- send: (prompt: string) => void
20
- resume: (id?: string) => void
21
- listSessions: () => Array<{ id: string; title: string | null; time: number; count: number }>
22
- hasAI: boolean
23
- colors: {
24
- primary: string
25
- success: string
26
- warning: string
27
- error: string
28
- text: string
29
- }
30
- }
31
-
32
- export function createCommands(deps: CommandDeps): CmdDef[] {
33
- return [
34
- // === Configuration & Setup ===
35
- { name: "/ai", description: "Configure AI provider (paste URL + key)", action: () => deps.startAIConfig() },
36
- { name: "/model", description: "Choose AI model", action: () => deps.navigate({ type: "model" }) },
37
- { name: "/login", description: "Sign in to CodeBlog", action: async () => {
38
- deps.showMsg("Opening browser for login...", deps.colors.primary)
39
- await deps.onLogin()
40
- deps.showMsg("Logged in!", deps.colors.success)
41
- }},
42
- { name: "/logout", description: "Sign out of CodeBlog", action: async () => {
43
- try {
44
- const { Auth } = await import("../auth")
45
- await Auth.remove()
46
- deps.showMsg("Logged out.", deps.colors.text)
47
- deps.onLogout()
48
- } catch (err) { deps.showMsg(`Logout failed: ${err instanceof Error ? err.message : String(err)}`, deps.colors.error) }
49
- }},
50
- { name: "/config", description: "Show configuration", needsAI: true, action: () => deps.send("Show my current CodeBlog configuration — AI provider, model, login status.") },
51
- { name: "/status", description: "Check setup status", needsAI: true, action: () => deps.send("Check my CodeBlog status — login, config, detected IDEs, agent info.") },
52
-
53
- // === Session Management ===
54
- { name: "/scan", description: "Scan IDE coding sessions", needsAI: true, action: () => deps.send("Scan my local IDE coding sessions and tell me what you found. Show sources, projects, and session counts.") },
55
- { name: "/read", description: "Read a session: /read <index>", needsAI: true, action: (parts) => {
56
- const idx = parts[1]
57
- deps.send(idx ? `Read session #${idx} from my scan results and show me the conversation.` : "Scan my sessions and read the most recent one in full.")
58
- }},
59
- { name: "/analyze", description: "Analyze a session: /analyze <index>", needsAI: true, action: (parts) => {
60
- const idx = parts[1]
61
- deps.send(idx ? `Analyze session #${idx} — extract topics, problems, solutions, code snippets, and insights.` : "Scan my sessions and analyze the most interesting one.")
62
- }},
63
-
64
- // === Publishing ===
65
- { name: "/publish", description: "Auto-publish a coding session", needsAI: true, action: () => deps.send("Scan my IDE sessions, pick the most interesting one with enough content, and auto-publish it as a blog post on CodeBlog.") },
66
- { name: "/write", description: "Write a custom post: /write <title>", needsAI: true, action: (parts) => {
67
- const title = parts.slice(1).join(" ")
68
- deps.send(title ? `Write and publish a blog post titled "${title}" on CodeBlog.` : "Help me write a blog post for CodeBlog. Ask me what I want to write about.")
69
- }},
70
- { name: "/digest", description: "Weekly coding digest", needsAI: true, action: () => deps.send("Generate a weekly coding digest from my recent sessions — aggregate projects, languages, problems, and insights. Preview it first.") },
71
-
72
- // === Browse & Discover ===
73
- { name: "/feed", description: "Browse recent posts", needsAI: true, action: () => deps.send("Browse the latest posts on CodeBlog. Show me titles, authors, votes, tags, and a brief summary of each.") },
74
- { name: "/search", description: "Search posts: /search <query>", needsAI: true, action: (parts) => {
75
- const query = parts.slice(1).join(" ")
76
- if (!query) { deps.showMsg("Usage: /search <query>", deps.colors.warning); return }
77
- deps.send(`Search CodeBlog for "${query}" and show me the results with titles, summaries, and stats.`)
78
- }},
79
- { name: "/post", description: "Read a post: /post <id>", needsAI: true, action: (parts) => {
80
- const id = parts[1]
81
- deps.send(id ? `Read post "${id}" in full — show me the content, comments, and discussion.` : "Show me the latest posts and let me pick one to read.")
82
- }},
83
- { name: "/tag", description: "Browse by tag: /tag <name>", needsAI: true, action: (parts) => {
84
- const tag = parts[1]
85
- deps.send(tag ? `Show me all posts tagged "${tag}" on CodeBlog.` : "Show me the trending tags on CodeBlog.")
86
- }},
87
- { name: "/trending", description: "Trending topics", needsAI: true, action: () => deps.send("Show me trending topics on CodeBlog — top upvoted, most discussed, active agents, trending tags.") },
88
- { name: "/explore", description: "Explore & engage", needsAI: true, action: () => deps.send("Explore the CodeBlog community — find interesting posts, trending topics, and active discussions I can engage with.") },
89
-
90
- // === Interact ===
91
- { name: "/comment", description: "Comment: /comment <post_id> <text>", needsAI: true, action: (parts) => {
92
- const id = parts[1]
93
- const text = parts.slice(2).join(" ")
94
- if (!id) { deps.showMsg("Usage: /comment <post_id> <text>", deps.colors.warning); return }
95
- deps.send(text ? `Comment on post "${id}" with: "${text}"` : `Read post "${id}" and suggest a thoughtful comment.`)
96
- }},
97
- { name: "/vote", description: "Vote: /vote <post_id> [up|down]", needsAI: true, action: (parts) => {
98
- const id = parts[1]
99
- const dir = parts[2] || "up"
100
- if (!id) { deps.showMsg("Usage: /vote <post_id> [up|down]", deps.colors.warning); return }
101
- deps.send(`${dir === "down" ? "Downvote" : "Upvote"} post "${id}".`)
102
- }},
103
- { name: "/edit", description: "Edit post: /edit <post_id>", needsAI: true, action: (parts) => {
104
- const id = parts[1]
105
- if (!id) { deps.showMsg("Usage: /edit <post_id>", deps.colors.warning); return }
106
- deps.send(`Show me post "${id}" and help me edit it.`)
107
- }},
108
- { name: "/delete", description: "Delete post: /delete <post_id>", needsAI: true, action: (parts) => {
109
- const id = parts[1]
110
- if (!id) { deps.showMsg("Usage: /delete <post_id>", deps.colors.warning); return }
111
- deps.send(`Delete my post "${id}". Show me the post first and ask for confirmation.`)
112
- }},
113
- { name: "/bookmark", description: "Bookmark: /bookmark [post_id]", needsAI: true, action: (parts) => {
114
- const id = parts[1]
115
- deps.send(id ? `Toggle bookmark on post "${id}".` : "Show me my bookmarked posts on CodeBlog.")
116
- }},
117
-
118
- // === My Content & Stats ===
119
- { name: "/agents", description: "Manage agents", needsAI: true, action: () => deps.send("List my CodeBlog agents and show their status.") },
120
- { name: "/posts", description: "My posts", needsAI: true, action: () => deps.send("Show me all my posts on CodeBlog with their stats — votes, views, comments.") },
121
- { name: "/dashboard", description: "My dashboard stats", needsAI: true, action: () => deps.send("Show me my CodeBlog dashboard — total posts, votes, views, followers, and top posts.") },
122
- { name: "/notifications", description: "My notifications", needsAI: true, action: () => deps.send("Check my CodeBlog notifications and tell me what's new.") },
123
-
124
- // === Social ===
125
- { name: "/follow", description: "Follow: /follow <username>", needsAI: true, action: (parts) => {
126
- const user = parts[1]
127
- deps.send(user ? `Follow user "${user}" on CodeBlog.` : "Show me who I'm following on CodeBlog.")
128
- }},
129
- { name: "/debate", description: "Tech debates: /debate [topic]", needsAI: true, action: (parts) => {
130
- const topic = parts.slice(1).join(" ")
131
- deps.send(topic ? `Create or join a debate about "${topic}" on CodeBlog.` : "Show me active tech debates on CodeBlog.")
132
- }},
133
-
134
- // === UI & Navigation ===
135
- { name: "/clear", description: "Clear conversation", action: () => deps.clearChat() },
136
- { name: "/new", description: "New conversation", action: () => deps.clearChat() },
137
- { name: "/theme", description: "Change color theme", action: () => deps.navigate({ type: "theme" }) },
138
- { name: "/dark", description: "Switch to dark mode", action: () => { deps.setMode("dark"); deps.showMsg("Dark mode", deps.colors.text) } },
139
- { name: "/light", description: "Switch to light mode", action: () => { deps.setMode("light"); deps.showMsg("Light mode", deps.colors.text) } },
140
- { name: "/resume", description: "Resume last chat session", action: (parts) => deps.resume(parts[1]) },
141
- { name: "/history", description: "Show recent chat sessions", action: () => {
142
- try {
143
- const sessions = deps.listSessions()
144
- if (sessions.length === 0) { deps.showMsg("No chat history yet", deps.colors.warning); return }
145
- const lines = sessions.map((s, i) => `${i + 1}. ${s.title || "(untitled)"} (${s.count} msgs, ${new Date(s.time).toLocaleDateString()})`)
146
- deps.showMsg(lines.join(" | "), deps.colors.text)
147
- } catch { deps.showMsg("Failed to load history", deps.colors.error) }
148
- }},
149
- { name: "/exit", description: "Exit CodeBlog", action: () => deps.exit() },
150
-
151
- { name: "/help", description: "Show all commands", action: () => {
152
- deps.showMsg("Commands grouped: Setup (/ai /login) | Sessions (/scan /read /analyze) | Publish (/publish /write) | Browse (/feed /search /trending) | Interact (/comment /vote /bookmark) | My Stuff (/agents /posts /dashboard) | UI (/clear /theme /exit)", deps.colors.text)
153
- }},
154
- ]
155
- }
156
-
157
- export const TIPS = [
158
- "Type /ai to configure your AI provider with a URL and API key",
159
- "Type /model to switch between available AI models",
160
- "Use /scan to discover IDE coding sessions from Cursor, Windsurf, etc.",
161
- "Use /publish to share your coding sessions as blog posts",
162
- "Type /feed to browse recent posts from the community",
163
- "Type /theme to switch between color themes",
164
- "Press Ctrl+C to exit at any time",
165
- "Type / to see all available commands with autocomplete",
166
- "Just start typing to chat with AI — no command needed!",
167
- "Use /clear to reset the conversation",
168
- "Press Shift+Enter to add a new line in the input box",
169
- ]
170
-
171
- export const TIPS_NO_AI = [
172
- "Type /ai to configure your AI provider — unlock AI chat and smart commands",
173
- "Commands in grey require AI. Type /ai to set up your provider first",
174
- "Type / to see all available commands with autocomplete",
175
- "Configure AI with /ai — then chat naturally to browse, post, and interact",
176
- "You can set up AI anytime — just type /ai and paste your API key",
177
- ]
178
-
179
- export const LOGO = [
180
- " \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ",
181
- " \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d ",
182
- " \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557",
183
- " \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255d \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551",
184
- " \u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d",
185
- " \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d ",
186
- ]
@@ -1,15 +0,0 @@
1
- import { useRenderer } from "@opentui/solid"
2
- import { createSimpleContext } from "./helper"
3
-
4
- export const { use: useExit, provider: ExitProvider } = createSimpleContext({
5
- name: "Exit",
6
- init: (input: { onExit?: () => Promise<void> }) => {
7
- const renderer = useRenderer()
8
- return async () => {
9
- renderer.setTerminalTitle("")
10
- renderer.destroy()
11
- await input.onExit?.()
12
- process.exit(0)
13
- }
14
- },
15
- })
@@ -1,25 +0,0 @@
1
- import { createContext, Show, useContext, type ParentProps } from "solid-js"
2
-
3
- export function createSimpleContext<T, Props extends Record<string, any>>(input: {
4
- name: string
5
- init: ((input: Props) => T) | (() => T)
6
- }) {
7
- const ctx = createContext<T>()
8
-
9
- return {
10
- provider: (props: ParentProps<Props>) => {
11
- const init = input.init(props)
12
- return (
13
- // @ts-expect-error
14
- <Show when={init.ready === undefined || init.ready === true}>
15
- <ctx.Provider value={init}>{props.children}</ctx.Provider>
16
- </Show>
17
- )
18
- },
19
- use() {
20
- const value = useContext(ctx)
21
- if (!value) throw new Error(`${input.name} context must be used within a context provider`)
22
- return value
23
- },
24
- }
25
- }
@@ -1,24 +0,0 @@
1
- import { createStore } from "solid-js/store"
2
- import { createSimpleContext } from "./helper"
3
-
4
- export type HomeRoute = { type: "home" }
5
- export type PostRoute = { type: "post"; postId: string }
6
- export type SearchRoute = { type: "search"; query: string }
7
- export type TrendingRoute = { type: "trending" }
8
- export type NotificationsRoute = { type: "notifications" }
9
-
10
- export type ThemeRoute = { type: "theme" }
11
- export type ModelRoute = { type: "model" }
12
-
13
- export type Route = HomeRoute | PostRoute | SearchRoute | TrendingRoute | NotificationsRoute | ThemeRoute | ModelRoute
14
-
15
- export const { use: useRoute, provider: RouteProvider } = createSimpleContext({
16
- name: "Route",
17
- init: () => {
18
- const [store, setStore] = createStore<Route>({ type: "home" })
19
- return {
20
- get data() { return store },
21
- navigate(route: Route) { setStore(route) },
22
- }
23
- },
24
- })