create-donghanh 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/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "create-donghanh",
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a donghanh project — conversational UI with JSX",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "create-donghanh": "src/index.ts"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "templates"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/rezzahub/donghanh",
17
+ "directory": "create-donghanh"
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import readline from "node:readline";
5
+
6
+ const TEMPLATES = ["minimal", "trello"] as const;
7
+ type Template = (typeof TEMPLATES)[number];
8
+
9
+ const DESCRIPTIONS: Record<Template, string> = {
10
+ minimal: "Hello world with D1 SQLite — 2 operations",
11
+ trello: "Mini Trello with boards, cards, members — 6 operations",
12
+ };
13
+
14
+ async function prompt(question: string): Promise<string> {
15
+ const rl = readline.createInterface({
16
+ input: process.stdin,
17
+ output: process.stdout,
18
+ });
19
+ return new Promise((resolve) => {
20
+ rl.question(question, (answer) => {
21
+ rl.close();
22
+ resolve(answer.trim());
23
+ });
24
+ });
25
+ }
26
+
27
+ function copyDir(src: string, dest: string, replacements: [string, string][]) {
28
+ fs.mkdirSync(dest, { recursive: true });
29
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
30
+ const srcPath = path.join(src, entry.name);
31
+ const destPath = path.join(dest, entry.name);
32
+ if (entry.isDirectory()) {
33
+ copyDir(srcPath, destPath, replacements);
34
+ } else {
35
+ let content = fs.readFileSync(srcPath, "utf-8");
36
+ for (const [from, to] of replacements) {
37
+ content = content.replaceAll(from, to);
38
+ }
39
+ fs.writeFileSync(destPath, content);
40
+ }
41
+ }
42
+ }
43
+
44
+ async function main() {
45
+ const args = process.argv.slice(2);
46
+ let target = args[0];
47
+ let template: Template | undefined;
48
+
49
+ // Parse --template / -t flag
50
+ const tIdx = args.indexOf("--template");
51
+ const tShortIdx = args.indexOf("-t");
52
+ const flagIdx = tIdx !== -1 ? tIdx : tShortIdx;
53
+ if (flagIdx !== -1 && args[flagIdx + 1]) {
54
+ template = args[flagIdx + 1] as Template;
55
+ // Remove flag and value from args
56
+ if (!target || target.startsWith("-")) {
57
+ target = undefined;
58
+ }
59
+ }
60
+
61
+ console.log();
62
+ console.log(" \x1b[1m@donghanh\x1b[0m — Conversational UI Framework");
63
+ console.log();
64
+
65
+ // Prompt for target if not given
66
+ if (!target || target.startsWith("-")) {
67
+ target = await prompt(" Project name: ");
68
+ if (!target) {
69
+ console.log(" Cancelled.");
70
+ process.exit(0);
71
+ }
72
+ }
73
+
74
+ // Prompt for template if not given
75
+ if (!template || !TEMPLATES.includes(template)) {
76
+ console.log();
77
+ console.log(" Templates:");
78
+ for (let i = 0; i < TEMPLATES.length; i++) {
79
+ console.log(
80
+ ` \x1b[1m${i + 1}\x1b[0m) ${TEMPLATES[i]} — ${DESCRIPTIONS[TEMPLATES[i]]}`,
81
+ );
82
+ }
83
+ console.log();
84
+ const choice = await prompt(" Select template (1-2): ");
85
+ const idx = Number.parseInt(choice, 10) - 1;
86
+ template = TEMPLATES[idx] ?? "minimal";
87
+ }
88
+
89
+ const destDir = path.resolve(target);
90
+ if (fs.existsSync(destDir)) {
91
+ console.log(
92
+ ` \x1b[31mError:\x1b[0m Directory "${target}" already exists.`,
93
+ );
94
+ process.exit(1);
95
+ }
96
+
97
+ // Find templates directory
98
+ const templatesDir = path.join(
99
+ path.dirname(new URL(import.meta.url).pathname),
100
+ "..",
101
+ "templates",
102
+ );
103
+ const srcDir = path.join(templatesDir, template);
104
+
105
+ if (!fs.existsSync(srcDir)) {
106
+ console.log(` \x1b[31mError:\x1b[0m Template "${template}" not found.`);
107
+ process.exit(1);
108
+ }
109
+
110
+ // Copy template with name replacement
111
+ const appName = path.basename(target);
112
+ copyDir(srcDir, destDir, [
113
+ ["my-donghanh-app", appName],
114
+ ["my-trello-app", appName],
115
+ ["my-donghanh-app-db", `${appName}-db`],
116
+ ["my-trello-db", `${appName}-db`],
117
+ ]);
118
+
119
+ console.log();
120
+ console.log(
121
+ ` \x1b[32m✓\x1b[0m Created \x1b[1m${appName}\x1b[0m from \x1b[1m${template}\x1b[0m template`,
122
+ );
123
+ console.log();
124
+ console.log(" Next steps:");
125
+ console.log(` cd ${target}`);
126
+ console.log(" bun install");
127
+ console.log(" bun run db:init # initialize D1 database");
128
+ console.log(" bun run dev # start dev server");
129
+ console.log();
130
+ }
131
+
132
+ main().catch(console.error);
@@ -0,0 +1,5 @@
1
+ {
2
+ "formatter": { "indentStyle": "space", "indentWidth": 2 },
3
+ "linter": { "enabled": true, "rules": { "recommended": true } },
4
+ "assist": { "actions": { "source": { "organizeImports": "on" } } }
5
+ }
@@ -0,0 +1,22 @@
1
+ import type { Executor } from "@donghanh/core";
2
+
3
+ const queries: Record<string, (db: D1Database, vars: Record<string, unknown>) => Promise<unknown>> = {
4
+ "list-items": async (db) => {
5
+ const { results } = await db.prepare("SELECT * FROM items ORDER BY created_at DESC").all();
6
+ return { items: results };
7
+ },
8
+ "add-item": async (db, vars) => {
9
+ const { name } = vars as { name: string };
10
+ await db.prepare("INSERT INTO items (name) VALUES (?)").bind(name).run();
11
+ const { results } = await db.prepare("SELECT * FROM items ORDER BY created_at DESC").all();
12
+ return { items: results };
13
+ },
14
+ };
15
+
16
+ export function createExecutor(db: D1Database): Executor {
17
+ return async (operationId, variables) => {
18
+ const query = queries[operationId];
19
+ if (!query) throw new Error(`Unknown operation: ${operationId}`);
20
+ return query(db, variables);
21
+ };
22
+ }
@@ -0,0 +1,33 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data {
6
+ items: { id: number; name: string; created_at: string }[];
7
+ }
8
+
9
+ function AddItem({ data }: OperationProps<Data>) {
10
+ return (
11
+ <Brief>
12
+ Item added! You now have {data.items.length} item(s).
13
+ <Display data={data.items} />
14
+ <Action operation="add-item" label="Add another" />
15
+ <Action operation="list-items" label="View all" />
16
+ </Brief>
17
+ );
18
+ }
19
+
20
+ export default registerOperation(AddItem, {
21
+ id: "add-item",
22
+ type: "mutation",
23
+ description: "Add a new item",
24
+ instruction: "Add an item by name.",
25
+ input: {
26
+ type: "object",
27
+ required: ["name"],
28
+ properties: {
29
+ name: { type: "string", description: "Name of the item" },
30
+ },
31
+ },
32
+ responseKey: "addItem",
33
+ });
@@ -0,0 +1,7 @@
1
+ import ListItems from "./list-items";
2
+ import AddItem from "./add-item";
3
+
4
+ export const operations = {
5
+ "list-items": ListItems,
6
+ "add-item": AddItem,
7
+ } as const;
@@ -0,0 +1,27 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data {
6
+ items: { id: number; name: string; created_at: string }[];
7
+ }
8
+
9
+ function ListItems({ data }: OperationProps<Data>) {
10
+ const count = data.items.length;
11
+ return (
12
+ <Brief>
13
+ {count === 0 ? "No items yet." : `You have ${count} item(s).`}
14
+ <Display data={data.items} />
15
+ <Action operation="add-item" label="Add an item" />
16
+ </Brief>
17
+ );
18
+ }
19
+
20
+ export default registerOperation(ListItems, {
21
+ id: "list-items",
22
+ type: "query",
23
+ description: "List all items",
24
+ instruction: "Call this to see all items.",
25
+ input: {},
26
+ responseKey: "listItems",
27
+ });
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "my-donghanh-app",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "wrangler dev",
8
+ "deploy": "wrangler deploy"
9
+ },
10
+ "dependencies": {
11
+ "@donghanh/core": "^0.1.0",
12
+ "@donghanh/hono": "^0.1.0",
13
+ "hono": "^4.7.0"
14
+ },
15
+ "devDependencies": {
16
+ "wrangler": "^4.0.0",
17
+ "typescript": "^5.8.0"
18
+ }
19
+ }
@@ -0,0 +1,5 @@
1
+ CREATE TABLE IF NOT EXISTS items (
2
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
3
+ name TEXT NOT NULL,
4
+ created_at TEXT DEFAULT (datetime('now'))
5
+ );
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["esnext"],
5
+ "skipLibCheck": true,
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "bundler",
10
+ "jsx": "react-jsx",
11
+ "jsxImportSource": "@donghanh/core"
12
+ },
13
+ "include": ["**/*.ts", "**/*.tsx"]
14
+ }
@@ -0,0 +1,28 @@
1
+ import { Hono } from "hono";
2
+ import { gptRoutes } from "@donghanh/hono";
3
+ import { buildRegistry, App } from "@donghanh/core";
4
+ import { operations } from "./operations";
5
+ import { createExecutor } from "./executor";
6
+
7
+ type Env = { Bindings: { DB: D1Database } };
8
+
9
+ const app = new Hono<Env>();
10
+
11
+ const appNode = App({ operations });
12
+ const registry = buildRegistry(appNode);
13
+
14
+ app.route("/api", gptRoutes({
15
+ registry,
16
+ executor: (opId, vars, ctx) => createExecutor((ctx as any).db)(opId, vars, ctx),
17
+ authenticate: async (request) => ({ userId: "anonymous" }),
18
+ }));
19
+
20
+ // Inject D1 binding into executor context
21
+ app.use("/api/*", async (c, next) => {
22
+ (c as any).db = c.env.DB;
23
+ await next();
24
+ });
25
+
26
+ app.get("/", (c) => c.text("donghanh app running. Try GET /api/operations"));
27
+
28
+ export default app;
@@ -0,0 +1,9 @@
1
+ name = "my-donghanh-app"
2
+ main = "worker.ts"
3
+ compatibility_date = "2024-12-01"
4
+ compatibility_flags = ["nodejs_compat"]
5
+
6
+ [[d1_databases]]
7
+ binding = "DB"
8
+ database_name = "my-donghanh-app-db"
9
+ database_id = "local"
@@ -0,0 +1,5 @@
1
+ {
2
+ "formatter": { "indentStyle": "space", "indentWidth": 2 },
3
+ "linter": { "enabled": true, "rules": { "recommended": true } },
4
+ "assist": { "actions": { "source": { "organizeImports": "on" } } }
5
+ }
@@ -0,0 +1,78 @@
1
+ function uid() {
2
+ return crypto.randomUUID().slice(0, 8);
3
+ }
4
+
5
+ export async function listBoards(db: D1Database, userId: string) {
6
+ const { results } = await db
7
+ .prepare(
8
+ `SELECT b.*, COUNT(DISTINCT c.id) as card_count, COUNT(DISTINCT m.id) as member_count
9
+ FROM boards b
10
+ LEFT JOIN cards c ON c.board_id = b.id
11
+ LEFT JOIN members m ON m.board_id = b.id
12
+ GROUP BY b.id ORDER BY b.created_at DESC`,
13
+ )
14
+ .all();
15
+ return { boards: results };
16
+ }
17
+
18
+ export async function boardDetail(db: D1Database, boardId: string) {
19
+ const board = await db.prepare("SELECT * FROM boards WHERE id = ?").bind(boardId).first();
20
+ if (!board) throw new Error("Board not found");
21
+
22
+ const { results: columns } = await db
23
+ .prepare("SELECT * FROM columns WHERE board_id = ? ORDER BY position")
24
+ .bind(boardId)
25
+ .all();
26
+
27
+ const { results: cards } = await db
28
+ .prepare("SELECT * FROM cards WHERE board_id = ? ORDER BY position")
29
+ .bind(boardId)
30
+ .all();
31
+
32
+ const { results: members } = await db
33
+ .prepare("SELECT * FROM members WHERE board_id = ? ORDER BY added_at")
34
+ .bind(boardId)
35
+ .all();
36
+
37
+ // Group cards by column
38
+ const columnMap = columns.map((col: any) => ({
39
+ ...col,
40
+ cards: cards.filter((c: any) => c.column_id === col.id),
41
+ }));
42
+
43
+ return { board, columns: columnMap, members };
44
+ }
45
+
46
+ export async function createBoard(db: D1Database, name: string, userId: string) {
47
+ const id = uid();
48
+ await db.prepare("INSERT INTO boards (id, name, created_by) VALUES (?, ?, ?)").bind(id, name, userId).run();
49
+ // Default columns
50
+ const cols = ["To Do", "In Progress", "Done"];
51
+ for (let i = 0; i < cols.length; i++) {
52
+ await db.prepare("INSERT INTO columns (id, board_id, name, position) VALUES (?, ?, ?, ?)").bind(uid(), id, cols[i], i).run();
53
+ }
54
+ // Add creator as member
55
+ await db.prepare("INSERT INTO members (id, board_id, name, user_id) VALUES (?, ?, ?, ?)").bind(uid(), id, "You", userId).run();
56
+ return boardDetail(db, id);
57
+ }
58
+
59
+ export async function addCard(db: D1Database, boardId: string, columnId: string, title: string) {
60
+ const id = uid();
61
+ const pos = await db.prepare("SELECT COUNT(*) as c FROM cards WHERE column_id = ?").bind(columnId).first<{ c: number }>();
62
+ await db.prepare("INSERT INTO cards (id, column_id, board_id, title, position) VALUES (?, ?, ?, ?, ?)").bind(id, columnId, boardId, title, pos?.c ?? 0).run();
63
+ return boardDetail(db, boardId);
64
+ }
65
+
66
+ export async function moveCard(db: D1Database, cardId: string, toColumnId: string) {
67
+ const card = await db.prepare("SELECT board_id FROM cards WHERE id = ?").bind(cardId).first<{ board_id: string }>();
68
+ if (!card) throw new Error("Card not found");
69
+ const pos = await db.prepare("SELECT COUNT(*) as c FROM cards WHERE column_id = ?").bind(toColumnId).first<{ c: number }>();
70
+ await db.prepare("UPDATE cards SET column_id = ?, position = ? WHERE id = ?").bind(toColumnId, pos?.c ?? 0, cardId).run();
71
+ return boardDetail(db, card.board_id);
72
+ }
73
+
74
+ export async function addMember(db: D1Database, boardId: string, name: string) {
75
+ const id = uid();
76
+ await db.prepare("INSERT INTO members (id, board_id, name) VALUES (?, ?, ?)").bind(id, boardId, name).run();
77
+ return boardDetail(db, boardId);
78
+ }
@@ -0,0 +1,19 @@
1
+ import type { Executor } from "@donghanh/core";
2
+ import * as queries from "./db";
3
+
4
+ export function createExecutor(db: D1Database): Executor {
5
+ const ops: Record<string, (vars: Record<string, unknown>, userId: string) => Promise<unknown>> = {
6
+ "list-boards": (_, userId) => queries.listBoards(db, userId),
7
+ "board-detail": (v) => queries.boardDetail(db, v.boardId as string),
8
+ "create-board": (v, userId) => queries.createBoard(db, v.name as string, userId),
9
+ "add-card": (v) => queries.addCard(db, v.boardId as string, v.columnId as string, v.title as string),
10
+ "move-card": (v) => queries.moveCard(db, v.cardId as string, v.toColumnId as string),
11
+ "add-member": (v) => queries.addMember(db, v.boardId as string, v.name as string),
12
+ };
13
+
14
+ return async (operationId, variables, context) => {
15
+ const op = ops[operationId];
16
+ if (!op) throw new Error(`Unknown operation: ${operationId}`);
17
+ return op(variables, context.userId);
18
+ };
19
+ }
@@ -0,0 +1,33 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data { board: { id: string; name: string }; columns: { id: string; name: string; cards: { id: string; title: string }[] }[] }
6
+
7
+ function AddCard({ data }: OperationProps<Data>) {
8
+ return (
9
+ <Brief>
10
+ Card added to {data.board.name}.
11
+ <Display data={data.columns.map(col => ({ column: col.name, cards: col.cards.map(c => c.title) }))} />
12
+ <Action operation="add-card" label="Add another card" variables={{ boardId: data.board.id }} />
13
+ <Action operation="board-detail" label="View board" variables={{ boardId: data.board.id }} />
14
+ </Brief>
15
+ );
16
+ }
17
+
18
+ export default registerOperation(AddCard, {
19
+ id: "add-card",
20
+ type: "mutation",
21
+ description: "Add a card to a column",
22
+ instruction: "Adds a card to the specified column.",
23
+ input: {
24
+ type: "object",
25
+ required: ["boardId", "columnId", "title"],
26
+ properties: {
27
+ boardId: { type: "string" },
28
+ columnId: { type: "string", description: "Target column ID" },
29
+ title: { type: "string", description: "Card title" },
30
+ },
31
+ },
32
+ responseKey: "addCard",
33
+ });
@@ -0,0 +1,32 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data { board: { id: string; name: string }; members: { id: string; name: string }[] }
6
+
7
+ function AddMember({ data }: OperationProps<Data>) {
8
+ return (
9
+ <Brief>
10
+ Member added to {data.board.name}. Now {data.members.length} member(s).
11
+ <Display data={data.members.map(m => m.name)} />
12
+ <Action operation="add-member" label="Add another member" variables={{ boardId: data.board.id }} />
13
+ <Action operation="board-detail" label="View board" variables={{ boardId: data.board.id }} />
14
+ </Brief>
15
+ );
16
+ }
17
+
18
+ export default registerOperation(AddMember, {
19
+ id: "add-member",
20
+ type: "mutation",
21
+ description: "Add a member to a board",
22
+ instruction: "Adds a member by name to the board.",
23
+ input: {
24
+ type: "object",
25
+ required: ["boardId", "name"],
26
+ properties: {
27
+ boardId: { type: "string" },
28
+ name: { type: "string", description: "Member name" },
29
+ },
30
+ },
31
+ responseKey: "addMember",
32
+ });
@@ -0,0 +1,37 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Column { id: string; name: string; cards: { id: string; title: string }[] }
6
+ interface Member { id: string; name: string }
7
+ interface Data { board: { id: string; name: string }; columns: Column[]; members: Member[] }
8
+
9
+ function BoardDetail({ data }: OperationProps<Data>) {
10
+ const { board, columns, members } = data;
11
+ return (
12
+ <Brief>
13
+ Board: {board.name} ({members.length} members)
14
+ <Display data={columns.map(col => ({
15
+ column: col.name,
16
+ cards: col.cards.map(c => c.title),
17
+ }))} />
18
+ {columns.map(col => (
19
+ <Action key={col.id} operation="add-card" label={`Add card to ${col.name}`} variables={{ boardId: board.id, columnId: col.id }} />
20
+ ))}
21
+ <Action operation="add-member" label="Add member" variables={{ boardId: board.id }} />
22
+ </Brief>
23
+ );
24
+ }
25
+
26
+ export default registerOperation(BoardDetail, {
27
+ id: "board-detail",
28
+ type: "query",
29
+ description: "View board columns, cards, and members",
30
+ instruction: "Shows the full board with all columns and cards.",
31
+ input: {
32
+ type: "object",
33
+ required: ["boardId"],
34
+ properties: { boardId: { type: "string" } },
35
+ },
36
+ responseKey: "boardDetail",
37
+ });
@@ -0,0 +1,28 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data { board: { id: string; name: string }; columns: { id: string; name: string }[] }
6
+
7
+ function CreateBoard({ data }: OperationProps<Data>) {
8
+ return (
9
+ <Brief>
10
+ Board "{data.board.name}" created with columns: {data.columns.map(c => c.name).join(", ")}.
11
+ <Action operation="add-card" label="Add first card" variables={{ boardId: data.board.id, columnId: data.columns[0]?.id }} />
12
+ <Action operation="add-member" label="Invite someone" variables={{ boardId: data.board.id }} />
13
+ </Brief>
14
+ );
15
+ }
16
+
17
+ export default registerOperation(CreateBoard, {
18
+ id: "create-board",
19
+ type: "mutation",
20
+ description: "Create a new board with default columns",
21
+ instruction: "Creates a board with To Do, In Progress, Done columns.",
22
+ input: {
23
+ type: "object",
24
+ required: ["name"],
25
+ properties: { name: { type: "string", description: "Board name" } },
26
+ },
27
+ responseKey: "createBoard",
28
+ });
@@ -0,0 +1,15 @@
1
+ import AddCard from "./add-card";
2
+ import AddMember from "./add-member";
3
+ import BoardDetail from "./board-detail";
4
+ import CreateBoard from "./create-board";
5
+ import ListBoards from "./list-boards";
6
+ import MoveCard from "./move-card";
7
+
8
+ export const operations = {
9
+ "list-boards": ListBoards,
10
+ "board-detail": BoardDetail,
11
+ "create-board": CreateBoard,
12
+ "add-card": AddCard,
13
+ "move-card": MoveCard,
14
+ "add-member": AddMember,
15
+ } as const;
@@ -0,0 +1,36 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Board { id: string; name: string; card_count: number; member_count: number }
6
+ interface Data { boards: Board[] }
7
+
8
+ function ListBoards({ data }: OperationProps<Data>) {
9
+ if (data.boards.length === 0) {
10
+ return (
11
+ <Brief>
12
+ No boards yet.
13
+ <Action operation="create-board" label="Create your first board" />
14
+ </Brief>
15
+ );
16
+ }
17
+ return (
18
+ <Brief>
19
+ You have {data.boards.length} board(s).
20
+ <Display data={data.boards.map(b => `${b.name} (${b.card_count} cards, ${b.member_count} members)`)} />
21
+ {data.boards.map(b => (
22
+ <Action key={b.id} operation="board-detail" label={`View ${b.name}`} variables={{ boardId: b.id }} />
23
+ ))}
24
+ <Action operation="create-board" label="Create new board" />
25
+ </Brief>
26
+ );
27
+ }
28
+
29
+ export default registerOperation(ListBoards, {
30
+ id: "list-boards",
31
+ type: "query",
32
+ description: "List all boards",
33
+ instruction: "Call this first to see available boards.",
34
+ input: {},
35
+ responseKey: "listBoards",
36
+ });
@@ -0,0 +1,31 @@
1
+ /** @jsxImportSource @donghanh/core */
2
+ import { Action, Brief, Display, registerOperation } from "@donghanh/core";
3
+ import type { OperationProps } from "@donghanh/core";
4
+
5
+ interface Data { board: { id: string; name: string }; columns: { id: string; name: string; cards: { id: string; title: string }[] }[] }
6
+
7
+ function MoveCard({ data }: OperationProps<Data>) {
8
+ return (
9
+ <Brief>
10
+ Card moved.
11
+ <Display data={data.columns.map(col => ({ column: col.name, cards: col.cards.map(c => c.title) }))} />
12
+ <Action operation="board-detail" label="View board" variables={{ boardId: data.board.id }} />
13
+ </Brief>
14
+ );
15
+ }
16
+
17
+ export default registerOperation(MoveCard, {
18
+ id: "move-card",
19
+ type: "mutation",
20
+ description: "Move a card to another column",
21
+ instruction: "Moves a card from its current column to the target column.",
22
+ input: {
23
+ type: "object",
24
+ required: ["cardId", "toColumnId"],
25
+ properties: {
26
+ cardId: { type: "string" },
27
+ toColumnId: { type: "string", description: "Target column ID" },
28
+ },
29
+ },
30
+ responseKey: "moveCard",
31
+ });
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "my-trello-app",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "wrangler dev",
8
+ "deploy": "wrangler deploy",
9
+ "db:init": "wrangler d1 execute my-trello-db --local --file=schema.sql"
10
+ },
11
+ "dependencies": {
12
+ "@donghanh/core": "^0.1.0",
13
+ "@donghanh/hono": "^0.1.0",
14
+ "hono": "^4.7.0"
15
+ },
16
+ "devDependencies": {
17
+ "wrangler": "^4.0.0",
18
+ "typescript": "^5.8.0"
19
+ }
20
+ }
@@ -0,0 +1,30 @@
1
+ CREATE TABLE IF NOT EXISTS boards (
2
+ id TEXT PRIMARY KEY,
3
+ name TEXT NOT NULL,
4
+ created_by TEXT NOT NULL,
5
+ created_at TEXT DEFAULT (datetime('now'))
6
+ );
7
+
8
+ CREATE TABLE IF NOT EXISTS columns (
9
+ id TEXT PRIMARY KEY,
10
+ board_id TEXT NOT NULL REFERENCES boards(id),
11
+ name TEXT NOT NULL,
12
+ position INTEGER NOT NULL DEFAULT 0
13
+ );
14
+
15
+ CREATE TABLE IF NOT EXISTS cards (
16
+ id TEXT PRIMARY KEY,
17
+ column_id TEXT NOT NULL REFERENCES columns(id),
18
+ board_id TEXT NOT NULL REFERENCES boards(id),
19
+ title TEXT NOT NULL,
20
+ position INTEGER NOT NULL DEFAULT 0,
21
+ created_at TEXT DEFAULT (datetime('now'))
22
+ );
23
+
24
+ CREATE TABLE IF NOT EXISTS members (
25
+ id TEXT PRIMARY KEY,
26
+ board_id TEXT NOT NULL REFERENCES boards(id),
27
+ name TEXT NOT NULL,
28
+ user_id TEXT,
29
+ added_at TEXT DEFAULT (datetime('now'))
30
+ );
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["esnext"],
5
+ "skipLibCheck": true,
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "bundler",
10
+ "jsx": "react-jsx",
11
+ "jsxImportSource": "@donghanh/core"
12
+ },
13
+ "include": ["**/*.ts", "**/*.tsx"]
14
+ }
@@ -0,0 +1,36 @@
1
+ import { App, buildRegistry } from "@donghanh/core";
2
+ import { gptRoutes } from "@donghanh/hono";
3
+ import { Hono } from "hono";
4
+ import { createExecutor } from "./executor";
5
+ import { operations } from "./operations";
6
+
7
+ type Env = { Bindings: { DB: D1Database } };
8
+
9
+ const appNode = App({ operations });
10
+ const registry = buildRegistry(appNode);
11
+
12
+ const app = new Hono<Env>();
13
+
14
+ app.route(
15
+ "/api",
16
+ gptRoutes({
17
+ registry,
18
+ executor: async (opId, vars, ctx) => {
19
+ const db = (ctx as any).db as D1Database;
20
+ return createExecutor(db)(opId, vars, ctx);
21
+ },
22
+ authenticate: async () => ({ userId: "anonymous" }),
23
+ }),
24
+ );
25
+
26
+ // Middleware to pass D1 to executor context
27
+ app.use("/api/*", async (c, next) => {
28
+ (c as any).db = c.env.DB;
29
+ await next();
30
+ });
31
+
32
+ app.get("/", (c) =>
33
+ c.text("Mini Trello running. Try GET /api/operations"),
34
+ );
35
+
36
+ export default app;
@@ -0,0 +1,9 @@
1
+ name = "my-trello-app"
2
+ main = "worker.ts"
3
+ compatibility_date = "2024-12-01"
4
+ compatibility_flags = ["nodejs_compat"]
5
+
6
+ [[d1_databases]]
7
+ binding = "DB"
8
+ database_name = "my-trello-db"
9
+ database_id = "local"