create-donghanh 0.3.1 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-donghanh",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Scaffold a donghanh project — conversational UI with JSX",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1 @@
1
+ BETTER_AUTH_SECRET=dev-secret-change-me-in-production
@@ -1,6 +1,6 @@
1
1
  # Kanban GPT
2
2
 
3
- A kanban board powered by [@donghanh](https://github.com/rezzahub/donghanh) with GPT Store integration.
3
+ A kanban board powered by [@donghanh](https://github.com/rezzahub/donghanh). Ships with three adapters sharing the same operations: GPT Store (GPT Actions), ChatGPT Apps SDK (MCP), and self-hosted chat.
4
4
 
5
5
  ## Setup
6
6
 
@@ -8,7 +8,7 @@ A kanban board powered by [@donghanh](https://github.com/rezzahub/donghanh) with
8
8
  bun install
9
9
  npx wrangler d1 create my-kanban-db
10
10
  # Copy the database_id into wrangler.toml
11
- npx drizzle-kit push
11
+ bun run db:init
12
12
  npx wrangler secret put BETTER_AUTH_SECRET
13
13
  bun run dev
14
14
  ```
@@ -24,7 +24,7 @@ bun run dev
24
24
  | `move-card` | mutation | Move card between columns |
25
25
  | `add-member` | mutation | Add member to board |
26
26
 
27
- ## GPT Store Setup
27
+ ## GPT Store setup
28
28
 
29
29
  1. Create a GPT Action in the [ChatGPT GPT Store editor](https://chatgpt.com/gpts/editor)
30
30
  2. Set the API server URL to your deployed worker URL
@@ -38,8 +38,29 @@ bun run dev
38
38
  npx wrangler secret put GPT_OAUTH_CLIENT_SECRET
39
39
  ```
40
40
 
41
+ ## ChatGPT Apps SDK (MCP) setup
42
+
43
+ The worker exposes an MCP server at `/mcp` for use as a ChatGPT connector.
44
+
45
+ 1. Update `donghanh.config.ts` with your deployed HTTPS URL and Better Auth issuer.
46
+ 2. Build widgets:
47
+ ```bash
48
+ bun run widgets
49
+ ```
50
+ This regenerates `manifest/manifest.js` — the worker imports it at build time. A placeholder ships so the worker compiles before the first build.
51
+ 3. Deploy:
52
+ ```bash
53
+ npx wrangler deploy
54
+ ```
55
+ 4. In ChatGPT: **Settings → Apps & Connectors → Advanced settings** → enable **Developer Mode**.
56
+ 5. **Settings → Connectors → Create** → paste `https://your-worker.dev/mcp`.
57
+ 6. Open a chat, click **+** → **More** → select the connector.
58
+
59
+ The `widgets/task-card.tsx` entry renders the default `DongHanhWidget` — customize it by editing that file and re-running `bun run widgets`.
60
+
41
61
  ## Deploy
42
62
 
43
63
  ```bash
64
+ bun run widgets # build widget manifest first
44
65
  npx wrangler deploy
45
66
  ```
@@ -1,13 +1,19 @@
1
1
  import { betterAuth } from "better-auth";
2
2
  import { drizzleAdapter } from "better-auth/adapters/drizzle";
3
3
  import { bearer } from "better-auth/plugins";
4
- import { db } from "./db";
4
+ import { drizzle } from "drizzle-orm/d1";
5
+ import * as schema from "./db/schema";
5
6
  import { getEnv } from "./env";
6
7
 
7
8
  function createAuth() {
8
9
  const env = getEnv();
10
+ const authDb = drizzle(env.DB, { schema });
9
11
  return betterAuth({
10
- database: drizzleAdapter(db, { provider: "sqlite", usePlural: true }),
12
+ database: drizzleAdapter(authDb, {
13
+ provider: "sqlite",
14
+ usePlural: true,
15
+ schema,
16
+ }),
11
17
  plugins: [bearer()],
12
18
  emailAndPassword: {
13
19
  enabled: true,
@@ -1,5 +1,57 @@
1
1
  import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
2
 
3
+ // ── Better Auth tables ──
4
+
5
+ export const users = sqliteTable("users", {
6
+ id: text("id").primaryKey(),
7
+ name: text("name").notNull(),
8
+ email: text("email").notNull().unique(),
9
+ emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),
10
+ image: text("image"),
11
+ createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
12
+ updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
13
+ });
14
+
15
+ export const sessions = sqliteTable("sessions", {
16
+ id: text("id").primaryKey(),
17
+ userId: text("user_id")
18
+ .notNull()
19
+ .references(() => users.id),
20
+ token: text("token").notNull().unique(),
21
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
22
+ ipAddress: text("ip_address"),
23
+ userAgent: text("user_agent"),
24
+ createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
25
+ updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
26
+ });
27
+
28
+ export const accounts = sqliteTable("accounts", {
29
+ id: text("id").primaryKey(),
30
+ userId: text("user_id")
31
+ .notNull()
32
+ .references(() => users.id),
33
+ accountId: text("account_id").notNull(),
34
+ providerId: text("provider_id").notNull(),
35
+ accessToken: text("access_token"),
36
+ refreshToken: text("refresh_token"),
37
+ accessTokenExpiresAt: integer("access_token_expires_at", { mode: "timestamp" }),
38
+ refreshTokenExpiresAt: integer("refresh_token_expires_at", { mode: "timestamp" }),
39
+ scope: text("scope"),
40
+ idToken: text("id_token"),
41
+ password: text("password"),
42
+ createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
43
+ updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
44
+ });
45
+
46
+ export const verifications = sqliteTable("verifications", {
47
+ id: text("id").primaryKey(),
48
+ identifier: text("identifier").notNull(),
49
+ value: text("value").notNull(),
50
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
51
+ createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
52
+ updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()),
53
+ });
54
+
3
55
  // ── App tables ──
4
56
 
5
57
  export const boards = sqliteTable("boards", {
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from "@donghanh/config";
2
+
3
+ export default defineConfig({
4
+ operations: "./operations/**/*.tsx",
5
+ widgets: {
6
+ "task-card": "./widgets/task-card.tsx",
7
+ },
8
+ server: {
9
+ // Replace with your deployed HTTPS URL for the MCP server.
10
+ resource: "https://example.com",
11
+ // Replace with your OAuth authorization server (Better Auth by default).
12
+ authorizationServers: ["https://example.com"],
13
+ scopes: [],
14
+ widgetDomain: "https://example.com",
15
+ csp: {
16
+ connectDomains: [],
17
+ resourceDomains: ["https://persistent.oaistatic.com"],
18
+ },
19
+ },
20
+ });
@@ -3,6 +3,7 @@ import * as queries from "./db/queries";
3
3
 
4
4
  export const executor: Executor = async (operationId, variables, context) => {
5
5
  const v = variables as Record<string, string>;
6
+ if (!context.userId) throw new Error("Unauthenticated");
6
7
  const userId = context.userId;
7
8
 
8
9
  switch (operationId) {
@@ -0,0 +1,2 @@
1
+ import type { WidgetConfig } from "@donghanh/hono";
2
+ export declare const widgets: Record<string, WidgetConfig>;
@@ -0,0 +1,2 @@
1
+ // Placeholder — regenerated by `bun run widgets`.
2
+ export const widgets = {};
@@ -30,4 +30,5 @@ export default registerOperation(AddCard, {
30
30
  },
31
31
  },
32
32
  responseKey: "addCard",
33
+ widget: "task-card",
33
34
  });
@@ -29,4 +29,5 @@ export default registerOperation(AddMember, {
29
29
  },
30
30
  },
31
31
  responseKey: "addMember",
32
+ widget: "task-card",
32
33
  });
@@ -34,4 +34,5 @@ export default registerOperation(BoardDetail, {
34
34
  properties: { boardId: { type: "string" } },
35
35
  },
36
36
  responseKey: "boardDetail",
37
+ widget: "task-card",
37
38
  });
@@ -25,4 +25,5 @@ export default registerOperation(CreateBoard, {
25
25
  properties: { name: { type: "string", description: "Board name" } },
26
26
  },
27
27
  responseKey: "createBoard",
28
+ widget: "task-card",
28
29
  });
@@ -33,4 +33,5 @@ export default registerOperation(ListBoards, {
33
33
  instruction: "Call this first to see available boards.",
34
34
  input: {},
35
35
  responseKey: "listBoards",
36
+ widget: "task-card",
36
37
  });
@@ -28,4 +28,5 @@ export default registerOperation(MoveCard, {
28
28
  },
29
29
  },
30
30
  responseKey: "moveCard",
31
+ widget: "task-card",
31
32
  });
@@ -7,20 +7,29 @@
7
7
  "dev": "wrangler dev",
8
8
  "deploy": "wrangler deploy",
9
9
  "db:init": "wrangler d1 execute my-kanban-db --local --file=schema.sql",
10
- "db:generate": "drizzle-kit generate"
10
+ "db:generate": "drizzle-kit generate",
11
+ "widgets": "vite build"
11
12
  },
12
13
  "dependencies": {
13
- "@donghanh/core": "^0.1.1",
14
- "@donghanh/hono": "^0.1.1",
14
+ "@donghanh/core": "^0.2.0",
15
+ "@donghanh/hono": "^0.2.0",
16
+ "@donghanh/config": "^0.1.0",
17
+ "@donghanh/widget": "^0.1.0",
15
18
  "better-auth": "^1.4.0",
16
19
  "drizzle-orm": "^0.45.0",
17
- "hono": "^4.7.0"
20
+ "hono": "^4.7.0",
21
+ "react": "^19.0.0",
22
+ "react-dom": "^19.0.0"
18
23
  },
19
24
  "devDependencies": {
20
25
  "@cloudflare/workers-types": "^4.0.0",
26
+ "@donghanh/widget-vite": "^0.1.0",
21
27
  "@types/node": "^22.0.0",
28
+ "@types/react": "^19.0.0",
29
+ "@types/react-dom": "^19.0.0",
22
30
  "better-sqlite3": "^11.0.0",
23
31
  "drizzle-kit": "^0.31.0",
32
+ "vite": "^7.0.0",
24
33
  "wrangler": "^4.0.0",
25
34
  "typescript": "^5.8.0"
26
35
  }
@@ -1,3 +1,51 @@
1
+ -- Better Auth tables
2
+ CREATE TABLE IF NOT EXISTS users (
3
+ id TEXT PRIMARY KEY,
4
+ name TEXT NOT NULL,
5
+ email TEXT NOT NULL UNIQUE,
6
+ email_verified INTEGER NOT NULL DEFAULT 0,
7
+ image TEXT,
8
+ created_at INTEGER,
9
+ updated_at INTEGER
10
+ );
11
+
12
+ CREATE TABLE IF NOT EXISTS sessions (
13
+ id TEXT PRIMARY KEY,
14
+ user_id TEXT NOT NULL REFERENCES users(id),
15
+ token TEXT NOT NULL UNIQUE,
16
+ expires_at INTEGER NOT NULL,
17
+ ip_address TEXT,
18
+ user_agent TEXT,
19
+ created_at INTEGER,
20
+ updated_at INTEGER
21
+ );
22
+
23
+ CREATE TABLE IF NOT EXISTS accounts (
24
+ id TEXT PRIMARY KEY,
25
+ user_id TEXT NOT NULL REFERENCES users(id),
26
+ account_id TEXT NOT NULL,
27
+ provider_id TEXT NOT NULL,
28
+ access_token TEXT,
29
+ refresh_token TEXT,
30
+ access_token_expires_at INTEGER,
31
+ refresh_token_expires_at INTEGER,
32
+ scope TEXT,
33
+ id_token TEXT,
34
+ password TEXT,
35
+ created_at INTEGER,
36
+ updated_at INTEGER
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS verifications (
40
+ id TEXT PRIMARY KEY,
41
+ identifier TEXT NOT NULL,
42
+ value TEXT NOT NULL,
43
+ expires_at INTEGER NOT NULL,
44
+ created_at INTEGER,
45
+ updated_at INTEGER
46
+ );
47
+
48
+ -- App tables
1
49
  CREATE TABLE IF NOT EXISTS boards (
2
50
  id TEXT PRIMARY KEY,
3
51
  name TEXT NOT NULL,
@@ -11,6 +11,6 @@
11
11
  "jsx": "react-jsx",
12
12
  "jsxImportSource": "@donghanh/core"
13
13
  },
14
- "include": ["**/*.ts", "**/*.tsx"],
15
- "exclude": ["node_modules"]
14
+ "include": ["**/*.ts", "operations/**/*.tsx"],
15
+ "exclude": ["node_modules", "widgets", "dist", "manifest", "vite.config.ts"]
16
16
  }
@@ -0,0 +1,18 @@
1
+ import { donghanhWidgets } from "@donghanh/widget-vite";
2
+ import { defineConfig } from "vite";
3
+ import config from "./donghanh.config";
4
+
5
+ export default defineConfig({
6
+ build: {
7
+ outDir: "manifest",
8
+ emptyOutDir: false,
9
+ },
10
+ plugins: [
11
+ donghanhWidgets({
12
+ entries: config.widgets ?? {},
13
+ outDir: "manifest",
14
+ domain: config.server?.widgetDomain,
15
+ csp: config.server?.csp,
16
+ }),
17
+ ],
18
+ });
@@ -0,0 +1,5 @@
1
+ import { DongHanhWidget } from "@donghanh/widget";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ const root = document.getElementById("root");
5
+ if (root) createRoot(root).render(<DongHanhWidget appName="task-card" />);
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "types": ["@donghanh/widget"],
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "module": "esnext",
10
+ "moduleResolution": "bundler",
11
+ "jsx": "react-jsx"
12
+ },
13
+ "include": ["**/*.ts", "**/*.tsx"]
14
+ }
@@ -1,7 +1,8 @@
1
1
  import { App, buildRegistry } from "@donghanh/core";
2
- import { gptRoutes } from "@donghanh/hono";
2
+ import { type Authenticate, gptRoutes, mcpRoutes } from "@donghanh/hono";
3
3
  import { Hono } from "hono";
4
4
  import { auth } from "./auth";
5
+ import dhConfig from "./donghanh.config";
5
6
  import { type Env, setEnv } from "./env";
6
7
  import { executor } from "./executor";
7
8
  import { oauthAuthorize } from "./oauth/authorize";
@@ -9,9 +10,31 @@ import { oauthCode } from "./oauth/code";
9
10
  import { oauthToken } from "./oauth/token";
10
11
  import { operations } from "./operations";
11
12
 
13
+ // Widget manifest is regenerated by `bun run widgets` (vite build).
14
+ // A placeholder with `{}` ships so this import always resolves.
15
+ import { widgets } from "./manifest/manifest.js";
16
+
12
17
  const appNode = App({ operations });
13
18
  const registry = buildRegistry(appNode);
14
19
 
20
+ const authenticate: Authenticate = async (request) => {
21
+ const authHeader = request.headers.get("Authorization");
22
+ if (!authHeader?.startsWith("Bearer ")) {
23
+ return {
24
+ error: Response.json({ error: "Unauthorized" }, { status: 401 }),
25
+ };
26
+ }
27
+ const token = authHeader.slice(7);
28
+ const ctx = await auth.$context;
29
+ const result = await ctx.internalAdapter.findSession(token).catch(() => null);
30
+ if (!result) {
31
+ return {
32
+ error: Response.json({ error: "Session expired" }, { status: 401 }),
33
+ };
34
+ }
35
+ return { userId: result.user.id };
36
+ };
37
+
15
38
  const app = new Hono<{ Bindings: Env }>();
16
39
 
17
40
  // Inject env bindings on each request
@@ -21,28 +44,19 @@ app.use("/*", async (c, next) => {
21
44
  });
22
45
 
23
46
  // GPT Store operations
47
+ app.route("/api", gptRoutes({ registry, executor, authenticate }));
48
+
49
+ // ChatGPT Apps SDK (MCP)
24
50
  app.route(
25
- "/api",
26
- gptRoutes({
51
+ "/",
52
+ mcpRoutes({
27
53
  registry,
28
54
  executor,
29
- authenticate: async (request) => {
30
- const authHeader = request.headers.get("Authorization");
31
- if (!authHeader?.startsWith("Bearer ")) {
32
- return {
33
- error: Response.json({ error: "Unauthorized" }, { status: 401 }),
34
- };
35
- }
36
- const token = authHeader.slice(7);
37
- const ctx = await auth.$context;
38
- const result = await ctx.internalAdapter.findSession(token);
39
- if (!result) {
40
- return {
41
- error: Response.json({ error: "Session expired" }, { status: 401 }),
42
- };
43
- }
44
- return { userId: result.user.id };
45
- },
55
+ authenticate,
56
+ resource: dhConfig.server?.resource ?? "https://example.com",
57
+ authorizationServers: dhConfig.server?.authorizationServers ?? [],
58
+ scopes: dhConfig.server?.scopes,
59
+ widgets,
46
60
  }),
47
61
  );
48
62
 
@@ -55,7 +69,7 @@ app.post("/oauth/code", (c) => oauthCode(c));
55
69
  app.post("/oauth/token", (c) => oauthToken(c));
56
70
 
57
71
  app.get("/", (c) =>
58
- c.text("Kanban GPT running. Try GET /api/operations"),
72
+ c.text("Kanban running. Try GET /api/operations or POST /mcp"),
59
73
  );
60
74
 
61
75
  export default app;