@indent-com/nexus-sdk 0.1.1 → 0.1.2

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,12 +1,11 @@
1
1
  {
2
2
  "name": "@indent-com/nexus-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Build Indent apps: server entrypoints, a database, and a React UI.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
7
7
  "files": [
8
- "dist",
9
- "template"
8
+ "dist"
10
9
  ],
11
10
  "bin": {
12
11
  "nexus-sdk": "./dist/cli.js"
@@ -1,66 +0,0 @@
1
- ---
2
- name: building-nexus-apps
3
- description:
4
- Build, run and check this Indent app, from the outcome a person asks for to a page that works.
5
- Use when you change its server code, migrations or UI, or test it with indent app dev.
6
- ---
7
-
8
- # Building Nexus apps
9
-
10
- The app has three parts:
11
-
12
- - `server/`: queries and mutations, and the functions they call. A query is a read and a
13
- mutation is a change; each answers at `/api/<file>/<export>`.
14
- - `migrations/`: the SQLite schema, as numbered SQL files.
15
- - `ui/`: a React app styled with Tailwind. It imports queries and mutations from `server/`.
16
-
17
- The API reference is the SDK's declarations in `node_modules/@indent-com/nexus-sdk/dist/`:
18
- `index.d.ts` for server code, `react.d.ts` and `client.d.ts` for the UI. Server code calls
19
- integrations through globals such as `MCP_Linear["acme"]`, typed in the `integrations.d.ts`
20
- that `indent app types` and `indent app dev` write.
21
-
22
- - [local-testing.md](local-testing.md): start `indent app dev`, call entrypoints, read the
23
- database, time calls, check the UI. Read it before running anything.
24
- - [gotchas.md](gotchas.md): known problems and their workarounds. Read it before debugging.
25
-
26
- ## The loop
27
-
28
- 1. **Outcome.** Restate what the person wants in one sentence. Ask only if two readings lead to
29
- different apps.
30
- 2. **Source of truth.** Find the existing definition of every number before writing code, such as
31
- a query, a report or a number someone already trusts. Copy it; don't reinvent a metric.
32
- 3. **Build a page in a loop.** Write a query and call it with curl to see its JSON. Write the
33
- component that shows it. Open the page and take a screenshot.
34
- 4. **Check.** Call every entrypoint with curl, read the database, and time each call against the
35
- 30 s limit ([local-testing.md](local-testing.md)).
36
- 5. **Reconcile.** Reproduce a number someone already trusts, exactly, from an independent source.
37
- If it doesn't match, find out why before you show it.
38
- 6. **Screenshots.** Light and dark. Look at them, and fix what looks off.
39
-
40
- ## Rules
41
-
42
- - **Explicit caching.** Either `cache.get` with a stated `freshFor`, or a `refresh` mutation that
43
- writes rows to the app's database and queries that read them. The UI shows when the data was
44
- loaded. Never serve stale data silently.
45
- - **Long work runs in the backend.** Never a browser loop that calls a mutation until it's done.
46
- Every call has 30 s. Work that can't fit belongs in a workflow, and `workflow` and `onSchedule`
47
- don't run in `indent app dev` yet.
48
- - **No text-packing.** Don't pack rows into strings to get past an integration's size limit.
49
- Treat integration results as typed data.
50
- - **No personal installations.** Never point the app at one person's installation: every viewer
51
- would read that person's data. Use `.me` for the viewer's own account, or an organization
52
- installation.
53
- - **Say the basis of every number**: which days and time zone, and what is excluded. Label
54
- estimates.
55
- - **A finished UI.** Stat tiles for headline numbers, real charts, loading, empty and error
56
- states for every read, and dark mode. Start from `ui/src/components.tsx` and Tailwind.
57
- - **Test writes on your own objects.** Read freely; write only to something you created for the
58
- test, then clean it up.
59
-
60
- ## Done means
61
-
62
- - Every entrypoint called with curl, inputs and outputs as expected, each under 30 s cold.
63
- - The database holds what you expect (`indent app db`).
64
- - Every number's basis stated, and at least one reconciled against an independent source.
65
- - Light and dark screenshots that you looked at.
66
- - `npm run typecheck` passes, after `indent app dev` wrote `integrations.d.ts`.
@@ -1,40 +0,0 @@
1
- # Gotchas
2
-
3
- Each entry: what you see, then what to do.
4
-
5
- ## Integrations
6
-
7
- - **App code gets only a preview of a SQL result.** `run_query` returns at most 20 rows and
8
- 16,000 bytes, each cell clipped to 2,048 bytes. Aggregate in SQL so the result is small, or
9
- load in chunks into the app's database.
10
- - **SQL values decode loosely.** Numerics come back as strings and small JSON cells as objects.
11
- Convert each column yourself (`Number(row.usd)`). `run_query` takes no bind parameters, so
12
- check every value you put into SQL.
13
- - **Some column aliases fail unquoted**, such as `month` and `day`. Quote them: `AS "month"`.
14
- - **MCP results are text.** Many tools return JSON in `content` with no `structuredContent`.
15
- Decode with `structuredContent ?? JSON.parse(content[0].text)` and check `isError` first.
16
- - **Literal-union parameters fail only at runtime.** A wrong enum value typechecks and fails with
17
- `invalid_arguments`. Call each new tool once with curl before building on it.
18
- - **64 integration calls in flight per connection**, across every call running at once; the 65th
19
- throws. Fan out with `map` (5 at a time by default), not `Promise.all` over a list.
20
- - **`.me` is undefined in the emulator.** Apps that need the viewer's own account can't be tested
21
- locally yet.
22
- - **Secrets come from an untyped `process.env`**, and a missing one is `undefined`, not an error.
23
- Check and throw.
24
-
25
- ## Runtime and emulator
26
-
27
- - **`workflow` and `onSchedule` are stubs** in `indent app dev`: they return `{}` and never run.
28
- - **Connections drop after idle.** After about 16 minutes idle, calls can fail with a lost
29
- connection or 500s. Restart the dev server. The first call after a restart can be slow.
30
- - **Server code has no IANA time zones.** Most of `Intl` is excluded. Prefer a time field the
31
- integration already computes; otherwise convert by hand and test daylight saving time.
32
- - **Optional inputs and `undefined`** may not work. Use `null` or a required field.
33
- - **Tuple types aren't JSON types.** An entrypoint whose output contains a tuple fails to build.
34
- Return objects or plain arrays.
35
-
36
- ## Build
37
-
38
- - **The UI can import server types but not values.** Repeat a constant in `ui/src`, or return it
39
- from a query.
40
- - **Each dev server uses about 1 GB.** Stop the ones you are done with.
@@ -1,88 +0,0 @@
1
- # Local testing
2
-
3
- `indent app dev` runs the app from local code: the UI, queries, mutations and a SQLite database
4
- built from the migrations. Integration calls go to Indent as the signed-in person. Sign in once
5
- with `indent auth login`.
6
-
7
- ## Start
8
-
9
- From the app's folder, on a port of its own:
10
-
11
- ```sh
12
- indent app dev --port 5173
13
- ```
14
-
15
- The first start downloads the runtime, writes `integrations.d.ts` and builds. It's ready when it
16
- prints:
17
-
18
- ```
19
- DB <path>/local.sqlite
20
- UI http://localhost:5173
21
- API http://localhost:5173/api/<file>/<export>
22
- Built 2 queries and mutations
23
- ```
24
-
25
- An agent should run it detached, with its output in a log file, and stop it by its process
26
- group. `pkill -f "app dev"` from the agent's own shell also matches that shell.
27
-
28
- ## Call
29
-
30
- A query is a GET with the input as JSON in `input`; a mutation is a POST with a JSON body.
31
- `<file>` is the file in `server/` without `.ts`.
32
-
33
- ```sh
34
- curl -s localhost:5173/api/notes/notes
35
- curl -sG localhost:5173/api/<file>/<query> --data-urlencode 'input={"days":7}'
36
- curl -s -X POST localhost:5173/api/notes/addNote \
37
- -H 'content-type: application/json' -d '{"text":"Hello"}'
38
- ```
39
-
40
- - 200 with the bare return value.
41
- - 400 `invalid_input` when the input doesn't match the type, including extra properties.
42
- - 404 for an unknown export, 405 for the wrong verb.
43
- - Failures are `{"error":{"name","message","code"?}}`.
44
-
45
- ## Database
46
-
47
- From the app's folder, one statement per call:
48
-
49
- ```sh
50
- indent app db "SELECT count(*) AS n FROM notes"
51
- ```
52
-
53
- It refuses when the migrations are newer than the database; start `indent app dev` first.
54
-
55
- ## Logs
56
-
57
- The dev server prints one line per call, plus anything server code logs:
58
-
59
- ```
60
- POST /api/notes/addNote 200 12ms
61
- ```
62
-
63
- ## The 30 s limit
64
-
65
- Every deployed call has 30 s. Time each entrypoint cold (first call after start, empty database
66
- and cache) and warm, and leave margin:
67
-
68
- ```sh
69
- curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' -X POST \
70
- localhost:5173/api/<file>/<mutation> -H 'content-type: application/json' -d '{}'
71
- ```
72
-
73
- To fit, run independent integration calls in parallel with `map`, page with `paginate` and a
74
- `limit`, sync incrementally with cursors stored in the database, and aggregate in the source's
75
- SQL. Don't split the work across browser calls.
76
-
77
- ## Browser
78
-
79
- Screenshot every page in light and dark with a headless browser, and look at the images. For dark
80
- mode, emulate `prefers-color-scheme: dark`. Check that the numbers on the page match the curl
81
- output, that text doesn't overflow at 1440 px, and that dark mode has no unreadable colors.
82
-
83
- ## Test data
84
-
85
- - Read freely.
86
- - Write to an external system only on an object you created for the test, then delete it.
87
- - Never change other people's data.
88
- - Prefer writes that set a value to writes that add one, so a retry is safe.
@@ -1,16 +0,0 @@
1
- # AGENTS.md
2
-
3
- This is an Indent app. Read the building-nexus-apps skill in
4
- [.agents/skills/building-nexus-apps](.agents/skills/building-nexus-apps/SKILL.md) before you change
5
- it: `SKILL.md`, then `local-testing.md` and `gotchas.md`. The API reference is the SDK's type
6
- declarations in `node_modules/@indent-com/nexus-sdk/dist/`.
7
-
8
- - Get data only from queries and mutations imported from `server/`. The UI never calls
9
- `fetch`; server code does.
10
- - Read with `useCall`, and show when the data is from with its `at`.
11
- - Do the gathering and counting in queries, and send the UI only what it shows.
12
- - Give each part of a page its own query, so parts load and fail independently.
13
- - Show every read's loading, empty and error states.
14
- - Change the schema with a new file in `migrations/`; never edit one that has run.
15
- - Before you finish, call every query and mutation you touched with curl, run
16
- `npm run typecheck`, and look at a screenshot of the page.
@@ -1,25 +0,0 @@
1
- # Notes
2
-
3
- An Indent app: a page of notes kept in the app's own SQLite database.
4
-
5
- - `server/notes.ts`: the `notes` query and the `addNote` mutation.
6
- - `migrations/`: the database's schema, as numbered SQL files.
7
- - `ui/`: the page, a React app styled with Tailwind.
8
-
9
- ## Commands
10
-
11
- ```sh
12
- indent app dev # serve the page and the API at http://localhost:5173
13
- indent app db "SELECT * FROM notes"
14
- indent app types # write integrations.d.ts after you add an integration
15
- indent app build # typecheck and bundle into dist/
16
- npm run typecheck
17
- ```
18
-
19
- With `indent app dev` running, call the query and the mutation:
20
-
21
- ```sh
22
- curl -s localhost:5173/api/notes/notes
23
- curl -s -X POST localhost:5173/api/notes/addNote \
24
- -H 'content-type: application/json' -d '{"text":"Hello"}'
25
- ```
@@ -1,4 +0,0 @@
1
- dist/
2
- node_modules/
3
- .env
4
- integrations.d.ts
@@ -1,5 +0,0 @@
1
- CREATE TABLE notes (
2
- id INTEGER PRIMARY KEY,
3
- text TEXT NOT NULL,
4
- created_at TEXT NOT NULL
5
- );
@@ -1,24 +0,0 @@
1
- {
2
- "name": "app",
3
- "private": true,
4
- "type": "module",
5
- "scripts": {
6
- "typecheck": "tsc -p tsconfig.json"
7
- },
8
- "dependencies": {
9
- "@indent-com/nexus-sdk": "^0.1.0",
10
- "react": "^19.3.0",
11
- "react-dom": "^19.3.0",
12
- "vite": "^8.3.3"
13
- },
14
- "devDependencies": {
15
- "@tailwindcss/vite": "^4.3.0",
16
- "@types/react": "^19.3.0",
17
- "@types/react-dom": "^19.3.0",
18
- "tailwindcss": "^4.3.0",
19
- "typescript": "^6.0.3"
20
- },
21
- "allowScripts": {
22
- "esbuild": true
23
- }
24
- }
@@ -1,2 +0,0 @@
1
- allowBuilds:
2
- esbuild: true
@@ -1,19 +0,0 @@
1
- import { db, mutation, query, sql, ToolError } from "@indent-com/nexus-sdk";
2
-
3
- export type Note = { id: number; text: string; created_at: string };
4
-
5
- export const notes = query(async (_: {}) => {
6
- const [{ rows }] = await db.execute(
7
- sql<Note>`SELECT id, text, created_at FROM notes ORDER BY id DESC LIMIT 50`,
8
- );
9
- return rows;
10
- });
11
-
12
- export const addNote = mutation(async ({ text }: { text: string }) => {
13
- const trimmed = text.trim();
14
- if (trimmed === "") throw new ToolError("invalid_arguments", "Write something first");
15
- const [{ rows }] = await db.execute(sql<Note>`
16
- INSERT INTO notes (text, created_at) VALUES (${trimmed}, ${new Date().toISOString()})
17
- RETURNING id, text, created_at`);
18
- return rows[0]!;
19
- });
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "target": "es2023",
5
- "module": "esnext",
6
- "moduleResolution": "bundler",
7
- "jsx": "react-jsx",
8
- "lib": ["es2024", "dom", "dom.iterable"],
9
- "skipLibCheck": true,
10
- "noEmit": true,
11
- "allowImportingTsExtensions": true,
12
- "types": []
13
- },
14
- "include": ["server", "ui/src", "*.d.ts"]
15
- }
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Notes</title>
6
- <link rel="stylesheet" href="/src/style.css" />
7
- </head>
8
- <body>
9
- <div id="root"></div>
10
- <script type="module" src="/src/main.tsx"></script>
11
- </body>
12
- </html>
@@ -1,84 +0,0 @@
1
- import { useCall } from "@indent-com/nexus-sdk/react";
2
- import { useState, type FormEvent } from "react";
3
- import { addNote, notes } from "../../server/notes";
4
- import { Button, Card, Empty, ErrorBanner, Skeleton } from "./components";
5
-
6
- const time = (at: string) =>
7
- new Date(at).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
8
-
9
- export function App() {
10
- const reading = useCall(notes, {});
11
-
12
- return (
13
- <div className="min-h-screen bg-neutral-50 text-neutral-900 dark:bg-neutral-950 dark:text-neutral-100">
14
- <main className="mx-auto max-w-2xl px-6 py-12">
15
- <header className="mb-6">
16
- <h1 className="text-2xl font-semibold tracking-tight">Notes</h1>
17
- <p className="mt-1 text-sm text-neutral-500">
18
- Stored in this app's own database
19
- {reading.at && <> · updated {time(reading.at)}</>}
20
- </p>
21
- </header>
22
- <NewNote />
23
- {reading.error && <ErrorBanner className="mt-6">{reading.error.message}</ErrorBanner>}
24
- <Card className="mt-6">
25
- {reading.data === undefined ? (
26
- !reading.error && (
27
- <div className="space-y-3 p-5">
28
- <Skeleton className="h-5 w-2/3" />
29
- <Skeleton className="h-5 w-1/2" />
30
- <Skeleton className="h-5 w-3/5" />
31
- </div>
32
- )
33
- ) : reading.data.length === 0 ? (
34
- <Empty title="No notes yet">Write one above to save it.</Empty>
35
- ) : (
36
- <ul className="divide-y divide-neutral-200 dark:divide-neutral-800">
37
- {reading.data.map((note) => (
38
- <li key={note.id} className="flex items-baseline justify-between gap-4 px-5 py-3">
39
- <span className="min-w-0 break-words">{note.text}</span>
40
- <span className="shrink-0 text-xs text-neutral-500">{time(note.created_at)}</span>
41
- </li>
42
- ))}
43
- </ul>
44
- )}
45
- </Card>
46
- </main>
47
- </div>
48
- );
49
- }
50
-
51
- function NewNote() {
52
- const [text, setText] = useState("");
53
- const [saving, setSaving] = useState(false);
54
- const [error, setError] = useState<string>();
55
-
56
- async function submit(event: FormEvent) {
57
- event.preventDefault();
58
- setSaving(true);
59
- setError(undefined);
60
- try {
61
- await addNote({ text });
62
- setText("");
63
- } catch (failure) {
64
- setError(failure instanceof Error ? failure.message : String(failure));
65
- } finally {
66
- setSaving(false);
67
- }
68
- }
69
-
70
- return (
71
- <form onSubmit={(event) => void submit(event)}>
72
- <div className="flex gap-2">
73
- <input
74
- className="h-9 min-w-0 flex-1 rounded-lg border border-neutral-300 bg-white px-3 text-sm outline-none focus:border-neutral-500 dark:border-neutral-700 dark:bg-neutral-900"
75
- placeholder="Write a note"
76
- value={text}
77
- onChange={(event) => setText(event.target.value)}
78
- />
79
- <Button disabled={saving || text.trim() === ""}>{saving ? "Saving…" : "Add"}</Button>
80
- </div>
81
- {error && <ErrorBanner className="mt-3">{error}</ErrorBanner>}
82
- </form>
83
- );
84
- }
@@ -1,44 +0,0 @@
1
- import type { ComponentProps, ReactNode } from "react";
2
-
3
- export function Card({ className = "", ...props }: ComponentProps<"div">) {
4
- return (
5
- <div
6
- className={`rounded-xl border border-neutral-200 bg-white shadow-sm dark:border-neutral-800 dark:bg-neutral-900 ${className}`}
7
- {...props}
8
- />
9
- );
10
- }
11
-
12
- export function Button({ className = "", ...props }: ComponentProps<"button">) {
13
- return (
14
- <button
15
- className={`h-9 rounded-lg bg-neutral-900 px-4 text-sm font-medium text-white hover:bg-neutral-700 disabled:opacity-40 dark:bg-neutral-100 dark:text-neutral-900 dark:hover:bg-neutral-300 ${className}`}
16
- {...props}
17
- />
18
- );
19
- }
20
-
21
- export function Skeleton({ className = "" }: { className?: string }) {
22
- return (
23
- <div className={`animate-pulse rounded-md bg-neutral-200 dark:bg-neutral-800 ${className}`} />
24
- );
25
- }
26
-
27
- export function Empty({ title, children }: { title: ReactNode; children?: ReactNode }) {
28
- return (
29
- <div className="px-6 py-12 text-center">
30
- <p className="font-medium">{title}</p>
31
- {children && <p className="mt-1 text-sm text-neutral-500">{children}</p>}
32
- </div>
33
- );
34
- }
35
-
36
- export function ErrorBanner({ className = "", ...props }: ComponentProps<"div">) {
37
- return (
38
- <div
39
- role="alert"
40
- className={`rounded-lg bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-950 dark:text-red-300 ${className}`}
41
- {...props}
42
- />
43
- );
44
- }
@@ -1,4 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
- import { App } from "./App";
3
-
4
- createRoot(document.getElementById("root")!).render(<App />);
@@ -1,5 +0,0 @@
1
- @import "tailwindcss";
2
-
3
- :root {
4
- color-scheme: light dark;
5
- }
@@ -1,4 +0,0 @@
1
- import tailwindcss from "@tailwindcss/vite";
2
- import { defineConfig } from "vite";
3
-
4
- export default defineConfig({ plugins: [tailwindcss()] });