create-lumo-agent 0.0.0-stage → 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LumoAuth LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,158 @@
1
- # Temporary Holding Version
1
+ # create-lumo-agent
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/create-lumo-agent.svg)](https://www.npmjs.com/package/create-lumo-agent)
4
+
5
+ `create-lumo-agent` creates a small Next.js app that shows LumoAuth securing an AI agent. The app
6
+ has three parts:
7
+
8
+ - sign-in for people, with `@lumoauth/react`;
9
+ - an API route that acts as the agent and checks a permission before it works;
10
+ - a demo of human approval, in which a person approves on their phone before the agent does
11
+ something that cannot be undone.
12
+
13
+ It is part of the [LumoAuth JavaScript SDK](../../README.md).
14
+
15
+ ## Contents
16
+
17
+ - [Is this the right package?](#is-this-the-right-package)
18
+ - [Requirements](#requirements)
19
+ - [Quick start](#quick-start)
20
+ - [What you get](#what-you-get)
21
+ - [Configuration](#configuration)
22
+ - [CLI reference](#cli-reference)
23
+ - [Templates](#templates)
24
+ - [Troubleshooting](#troubleshooting)
25
+ - [Versioning](#versioning)
26
+ - [Related packages](#related-packages)
27
+ - [Licence](#licence)
28
+
29
+ ## Is this the right package?
30
+
31
+ | You want to… | Use |
32
+ |---|---|
33
+ | Start a new agent project from a working example | **This package** |
34
+ | Add agent identity, approvals or JIT permissions to existing Node code | [`@lumoauth/agent`](../agent/README.md) |
35
+ | Add sign-in to an existing React or Next.js app | [`@lumoauth/react`](../react/README.md) or [`@lumoauth/nextjs`](../nextjs/README.md) |
36
+
37
+ ## Requirements
38
+
39
+ - Node 18 or newer, with `npm`
40
+ - A LumoAuth organization. Sign up at [lumoauth.dev](https://lumoauth.dev).
41
+ - From the LumoAuth dashboard:
42
+ - your organization slug, such as `acme-corp`;
43
+ - a **public** OAuth client with PKCE. Register `http://localhost:3000/callback` as a redirect
44
+ URI, and add `http://localhost:3000` to its allowed origins;
45
+ - an AI agent, and an access token for it;
46
+ - for the approval demo, a user with the LumoAuth mobile app enrolled.
47
+
48
+ ## Quick start
49
+
50
+ ```bash
51
+ npx create-lumo-agent my-agent
52
+ cd my-agent
53
+ cp .env.example .env.local # then set LUMOAUTH_AGENT_TOKEN
54
+ npm run dev
55
+ ```
56
+
57
+ The CLI asks for your LumoAuth domain, organization slug and OAuth client ID. It writes them into
58
+ the project and runs `npm install`.
59
+
60
+ Open <http://localhost:3000> and sign in. Then ask the agent to do something, and approve the
61
+ request on your phone.
62
+
63
+ ## What you get
64
+
65
+ A Next.js 15 App Router project in TypeScript. It depends on the published `@lumoauth/react` and
66
+ `@lumoauth/client` packages.
67
+
68
+ | File | What it does |
69
+ |---|---|
70
+ | `app/providers.tsx` | Sets up `<LumoAuthProvider>` with your domain, organization and client ID. The redirect URI is `<current origin>/callback`. |
71
+ | `app/page.tsx` | The sign-in card (`<SignIn>`) and the agent demo |
72
+ | `app/callback/page.tsx` | Finishes sign-in with `<AuthCallback>` |
73
+ | `lib/lumo.ts` | A server-side `LumoAuth` client that authenticates **as the agent** with `LUMOAUTH_AGENT_TOKEN` |
74
+ | `app/api/agent/route.ts` | An agent endpoint. It checks `permissions.check('reports.send')` as the agent before it works, and answers `403` when the agent lacks the permission. |
75
+ | `app/api/approval/route.ts` | The approval demo. It sends an approval request to the user's phone, waits for the answer, and only then reports a "wire transfer" as done. |
76
+ | `.env.example` | The four variables below, filled in from your answers |
77
+
78
+ The project uses plain Next.js. You can read every file and change anything.
79
+
80
+ ## Configuration
81
+
82
+ Copy `.env.example` to `.env.local`. It holds these variables:
83
+
84
+ | Variable | Public? | Description |
85
+ |---|---|---|
86
+ | `NEXT_PUBLIC_LUMOAUTH_DOMAIN` | yes | Root URL of LumoAuth, not an `/orgs/…` path. For example `https://app.lumoauth.dev`, or `https://eu.app.lumoauth.dev` for the EU region. |
87
+ | `NEXT_PUBLIC_LUMOAUTH_ORG_ID` | yes | Organization slug, such as `acme-corp` |
88
+ | `NEXT_PUBLIC_LUMOAUTH_CLIENT_ID` | yes | OAuth client ID that the browser uses for sign-in |
89
+ | `LUMOAUTH_AGENT_TOKEN` | **no**, server only | An access token for your agent. The server uses it for permission checks and approvals. |
90
+
91
+ Never give the agent token a `NEXT_PUBLIC_` prefix. Next.js puts every `NEXT_PUBLIC_` value into
92
+ the browser bundle.
93
+
94
+ ## CLI reference
95
+
96
+ ```
97
+ npx create-lumo-agent [project-name] [options]
98
+
99
+ Options
100
+ -t, --template <name> Template to use (default: nextjs-agent)
101
+ --no-install Do not run npm install after creating the project
102
+ ```
103
+
104
+ The CLI asks for anything that you did not pass on the command line:
105
+
106
+ | Question | Default | Rule |
107
+ |---|---|---|
108
+ | Project name | `my-agent` | Lowercase letters, digits and dashes. The folder must be empty or must not exist. |
109
+ | Template | the only template | Asked only when there is more than one |
110
+ | LumoAuth domain | `https://app.lumoauth.dev` | Must be a URL |
111
+ | Organization ID | `your-org` | |
112
+ | OAuth client ID | empty | You can fill it in later in `.env.local`. |
113
+
114
+ Press Ctrl+C at any question to stop without creating files.
115
+
116
+ ## Templates
117
+
118
+ | Template | Stack | Status |
119
+ |---|---|---|
120
+ | `nextjs-agent` (default) | Next.js 15, React 18, TypeScript | Available |
121
+
122
+ Templates are in this package's `templates/` folder. The CLI replaces `{{projectName}}`,
123
+ `{{domain}}`, `{{orgId}}` and `{{clientId}}` in every file. A file named `gitignore` becomes
124
+ `.gitignore`.
125
+
126
+ ## Troubleshooting
127
+
128
+ | Symptom | Cause | Fix |
129
+ |---|---|---|
130
+ | `error: my-agent/ already exists and is not empty` | The target folder has files in it. | Choose another name, or empty the folder. |
131
+ | The app throws `NEXT_PUBLIC_LUMOAUTH_DOMAIN must be set` | `.env.local` is missing. | Copy `.env.example` to `.env.local`. |
132
+ | Sign-in fails with a redirect URI or CORS error | The OAuth client does not list `http://localhost:3000/callback` or `http://localhost:3000`. | Add them to the client in the dashboard. |
133
+ | `/api/agent` answers `403` | The agent does not hold `reports.send`. | Grant the permission to the agent, or change the permission in the route. |
134
+ | `/api/approval` fails with `403 test_token_not_accepted` | The agent token is a test token from the portal. Approvals do not accept test tokens. | Use a client-credentials access token for the agent. |
135
+ | `/api/approval` fails with an error while the user gets an email | The user in `onBehalfOf` has not enrolled the mobile app. LumoAuth emails that user a notification and returns no approval to wait on. | Enroll the LumoAuth mobile app for that user. |
136
+ | `npm install failed; you can run it manually` | The install step failed. | Run `npm install` in the project folder. |
137
+
138
+ ## Versioning
139
+
140
+ This package is version 0.1.0. The generated project depends on `@lumoauth/client` and
141
+ `@lumoauth/react` `^1.0.0`.
142
+
143
+ ## Related packages
144
+
145
+ | Package | Relationship |
146
+ |---|---|
147
+ | [`@lumoauth/react`](../react/README.md) | Provides sign-in in the generated app |
148
+ | [`@lumoauth/client`](../client/README.md) | Provides the agent's server-side client in the generated app |
149
+ | [`@lumoauth/agent`](../agent/README.md) | The full agent SDK: client-credentials sign-in, JIT, delegation and AAuth |
150
+ | [Workspace README](../../README.md) | How the packages fit together |
151
+
152
+ More: [Secure AI agents](https://docs.lumoauth.dev/quickstarts/ai-agent-security/),
153
+ [AAuth quickstart](https://docs.lumoauth.dev/agents/aauth-quickstart/) and the
154
+ [SDK overview](https://docs.lumoauth.dev/developer/sdks/).
155
+
156
+ ## Licence
157
+
158
+ See [LICENSE](./LICENSE).
package/dist/index.js ADDED
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
5
+ import { dirname, join, resolve } from "path";
6
+ import { fileURLToPath } from "url";
7
+ import { spawnSync } from "child_process";
8
+ import prompts from "prompts";
9
+ import kleur from "kleur";
10
+ var __dirname = dirname(fileURLToPath(import.meta.url));
11
+ var TEMPLATES_DIR = resolve(__dirname, "..", "templates");
12
+ function parseArgs(argv) {
13
+ const args = { install: true };
14
+ for (let i = 0; i < argv.length; i++) {
15
+ const a = argv[i];
16
+ if (a === "--no-install") args.install = false;
17
+ else if (a === "--template" || a === "-t") args.template = argv[++i];
18
+ else if (!a.startsWith("-") && !args.projectName) args.projectName = a;
19
+ }
20
+ return args;
21
+ }
22
+ async function main() {
23
+ const args = parseArgs(process.argv.slice(2));
24
+ console.log();
25
+ console.log(kleur.bold().cyan("LumoAuth") + kleur.gray(" \xB7 agent starter"));
26
+ console.log();
27
+ const availableTemplates = readdirSync(TEMPLATES_DIR).filter(
28
+ (d) => statSync(join(TEMPLATES_DIR, d)).isDirectory()
29
+ );
30
+ const responses = await prompts(
31
+ [
32
+ {
33
+ type: args.projectName ? null : "text",
34
+ name: "projectName",
35
+ message: "Project name",
36
+ initial: "my-agent",
37
+ validate: (v) => /^[a-z0-9][a-z0-9-]*$/.test(v) ? true : "lowercase letters, digits, and dashes only"
38
+ },
39
+ {
40
+ type: args.template || availableTemplates.length === 1 ? null : "select",
41
+ name: "template",
42
+ message: "Template",
43
+ choices: availableTemplates.map((t) => ({ title: t, value: t })),
44
+ initial: 0
45
+ },
46
+ {
47
+ type: "text",
48
+ name: "domain",
49
+ message: "LumoAuth domain (root host, not the /orgs/\u2026 path)",
50
+ initial: "https://app.lumoauth.dev",
51
+ validate: (v) => /^https?:\/\//.test(v) ? true : "must be a URL"
52
+ },
53
+ {
54
+ type: "text",
55
+ name: "orgId",
56
+ message: "Organization id (e.g. acme-corp)",
57
+ initial: "your-org"
58
+ },
59
+ {
60
+ type: "text",
61
+ name: "clientId",
62
+ message: "OAuth client_id (paste from your LumoAuth dashboard, or leave blank to fill later)",
63
+ initial: ""
64
+ }
65
+ ],
66
+ { onCancel: () => process.exit(1) }
67
+ );
68
+ const projectName = args.projectName ?? responses.projectName;
69
+ const template = args.template ?? responses.template ?? availableTemplates[0];
70
+ const domain = responses.domain ?? "https://app.lumoauth.dev";
71
+ const orgId = responses.orgId ?? "your-org";
72
+ const clientId = responses.clientId ?? "";
73
+ const projectDir = resolve(process.cwd(), projectName);
74
+ if (existsSync(projectDir) && readdirSync(projectDir).length > 0) {
75
+ console.error(kleur.red(`error: ${projectName}/ already exists and is not empty`));
76
+ process.exit(1);
77
+ }
78
+ const templateDir = join(TEMPLATES_DIR, template);
79
+ if (!existsSync(templateDir)) {
80
+ console.error(kleur.red(`error: template "${template}" not found in ${TEMPLATES_DIR}`));
81
+ process.exit(1);
82
+ }
83
+ console.log();
84
+ console.log(kleur.gray(`scaffolding ${projectName}/ from ${template}\u2026`));
85
+ copyDir(templateDir, projectDir, { projectName, domain, orgId, clientId });
86
+ console.log(kleur.green("\u2713") + " files written");
87
+ if (args.install) {
88
+ console.log(kleur.gray("installing dependencies (this can take a minute)\u2026"));
89
+ const r = spawnSync("npm", ["install"], { cwd: projectDir, stdio: "inherit" });
90
+ if (r.status !== 0) {
91
+ console.warn(kleur.yellow("npm install failed; you can run it manually"));
92
+ } else {
93
+ console.log(kleur.green("\u2713") + " dependencies installed");
94
+ }
95
+ }
96
+ console.log();
97
+ console.log(kleur.bold("Next steps:"));
98
+ console.log();
99
+ console.log(` ${kleur.cyan("cd")} ${projectName}`);
100
+ if (!args.install) console.log(` ${kleur.cyan("npm install")}`);
101
+ console.log(` ${kleur.cyan("npm run dev")}`);
102
+ console.log();
103
+ console.log(kleur.gray("Then visit ") + kleur.cyan("http://localhost:3000") + kleur.gray(" to see your agent in action."));
104
+ console.log();
105
+ console.log(kleur.gray("Docs: ") + kleur.cyan("https://docs.lumoauth.dev/quickstarts/create-lumo-agent"));
106
+ console.log();
107
+ }
108
+ function copyDir(src, dst, vars) {
109
+ mkdirSync(dst, { recursive: true });
110
+ for (const entry of readdirSync(src)) {
111
+ const sp = join(src, entry);
112
+ const dp = join(dst, entry === "gitignore" ? ".gitignore" : entry);
113
+ const stat = statSync(sp);
114
+ if (stat.isDirectory()) {
115
+ copyDir(sp, dp, vars);
116
+ } else {
117
+ let body = readFileSync(sp, "utf8");
118
+ if (/\.(json|ts|tsx|js|jsx|md|mdx|env|html)$/.test(entry) || entry === "package.json" || entry === ".env.example") {
119
+ body = body.replace(/\{\{projectName\}\}/g, vars.projectName).replace(/\{\{domain\}\}/g, vars.domain).replace(/\{\{orgId\}\}/g, vars.orgId).replace(/\{\{clientId\}\}/g, vars.clientId);
120
+ }
121
+ writeFileSync(dp, body);
122
+ }
123
+ }
124
+ }
125
+ main().catch((e) => {
126
+ console.error(kleur.red("failed:"), e);
127
+ process.exit(1);
128
+ });
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "create-lumo-agent",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Scaffold a working LumoAuth agent app in 60 seconds.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "provenance": true
10
+ },
11
+ "bin": {
12
+ "create-lumo-agent": "./dist/index.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "templates",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "dev": "tsx src/index.ts"
23
+ },
24
+ "dependencies": {
25
+ "kleur": "^4.1.5",
26
+ "prompts": "^2.4.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "@types/prompts": "^2.4.9",
31
+ "tsup": "^8.0.0",
32
+ "tsx": "^4.0.0",
33
+ "typescript": "^5.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "keywords": [
39
+ "lumoauth",
40
+ "ai-agent",
41
+ "agent",
42
+ "auth",
43
+ "starter",
44
+ "nextjs",
45
+ "scaffold"
46
+ ]
47
+ }
@@ -0,0 +1,14 @@
1
+ # LumoAuth instance domain — the ROOT host, not the /orgs/... path.
2
+ # Copy from your LumoAuth dashboard.
3
+ NEXT_PUBLIC_LUMOAUTH_DOMAIN={{domain}}
4
+
5
+ # Your organization id (e.g. "acme-corp").
6
+ NEXT_PUBLIC_LUMOAUTH_ORG_ID={{orgId}}
7
+
8
+ # OAuth client id (public — used by the browser to start the sign-in flow).
9
+ NEXT_PUBLIC_LUMOAUTH_CLIENT_ID={{clientId}}
10
+
11
+ # Agent access token (server-only). Used to call the LumoAuth API on the
12
+ # agent's behalf (permission checks + push approvals). Mint one from your
13
+ # dashboard: AI Agents → your agent → Token.
14
+ LUMOAUTH_AGENT_TOKEN=
@@ -0,0 +1,29 @@
1
+ # {{projectName}}
2
+
3
+ A LumoAuth-secured AI agent demo. Built with Next.js + `@lumoauth/react` + `@lumoauth/client`.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ cp .env.example .env.local
9
+ # fill in NEXT_PUBLIC_LUMOAUTH_DOMAIN, NEXT_PUBLIC_LUMOAUTH_ORG_ID,
10
+ # NEXT_PUBLIC_LUMOAUTH_CLIENT_ID, and LUMOAUTH_AGENT_TOKEN
11
+ npm install
12
+ npm run dev
13
+ ```
14
+
15
+ Visit `http://localhost:3000`.
16
+
17
+ ## What's wired up
18
+
19
+ - **`<SignIn>`** (from `@lumoauth/react`, inside `<LumoAuthProvider>`) on `/` — handles OAuth + PKCE + token storage
20
+ - **`/api/agent`** — server route that runs a `permissions.check()` for the agent, then performs a sample task
21
+ - **`/api/approval`** — endpoint that demos `agent.requireApproval()` for irreversible actions; the user's phone gets a push, they approve, the agent proceeds
22
+
23
+ ## Files of interest
24
+
25
+ - `app/page.tsx` — sign-in + agent demo UI
26
+ - `app/providers.tsx` — `<LumoAuthProvider>` wiring
27
+ - `app/callback/page.tsx` — OAuth redirect handler (`<AuthCallback>`)
28
+ - `app/api/agent/route.ts` — server-side agent invocation
29
+ - `lib/lumo.ts` — singleton SDK client
@@ -0,0 +1,25 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { lumo } from '@/lib/lumo';
3
+
4
+ /**
5
+ * Sample agent endpoint. The agent's access token carries its identity; the
6
+ * LumoAuth PDP enforces what the agent is allowed to do via the Zanzibar/ABAC
7
+ * policies you author in the dashboard.
8
+ *
9
+ * `permissions.check` returns a boolean — allow/deny for this agent + permission.
10
+ */
11
+ export async function POST(req: Request) {
12
+ const { task } = await req.json();
13
+
14
+ const allowed = await lumo.permissions.check('reports.send', { task });
15
+ if (!allowed) {
16
+ return NextResponse.json({ error: 'denied', permission: 'reports.send' }, { status: 403 });
17
+ }
18
+
19
+ // Pretend the agent did some work.
20
+ return NextResponse.json({
21
+ ok: true,
22
+ task,
23
+ message: 'Agent completed task without human-in-the-loop.',
24
+ });
25
+ }
@@ -0,0 +1,63 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { LumoAuthApprovalNotDeliveredError } from '@lumoauth/client';
3
+ import { lumo } from '@/lib/lumo';
4
+
5
+ /**
6
+ * Push-approval-for-agent-actions demo.
7
+ *
8
+ * The agent wants to do something irreversible (wire transfer). It calls
9
+ * `agent.requireApproval()` which:
10
+ * 1. sends a push to the user's phone with the action description
11
+ * 2. polls until the user taps approve/deny (or the request times out)
12
+ * 3. resolves with the approval status + a short-lived approval token
13
+ *
14
+ * When the user has no enrolled push device, no prompt is sent and it
15
+ * throws LumoAuthApprovalNotDeliveredError instead (never "approved").
16
+ *
17
+ * This is the demo nobody else has.
18
+ */
19
+ export async function POST(req: Request) {
20
+ const { action, amount, vendor, onBehalfOf } = await req.json();
21
+
22
+ const description = `Wire $${Number(amount).toLocaleString()} to vendor ${vendor}`;
23
+
24
+ let approval;
25
+ try {
26
+ approval = await lumo.agent.requireApproval({
27
+ taskId: `wire-${action}-${vendor}`,
28
+ reason: description,
29
+ impact: 'high',
30
+ // The user (subject) who must approve. In a real app this is the signed-in
31
+ // user the agent is acting for.
32
+ onBehalfOf: onBehalfOf ?? 'user@example.com',
33
+ meta: { action, amount, vendor },
34
+ });
35
+ } catch (err) {
36
+ if (err instanceof LumoAuthApprovalNotDeliveredError) {
37
+ // email_fallback_sent: the user was emailed and should enrol a device.
38
+ // no_enrolled_device: no device, and the email could not be sent.
39
+ return NextResponse.json(
40
+ { error: 'approval_not_delivered', reason: err.reason },
41
+ { status: 409 },
42
+ );
43
+ }
44
+ throw err;
45
+ }
46
+
47
+ if (approval.status !== 'approved') {
48
+ return NextResponse.json(
49
+ { error: 'denied', status: approval.status, reason: approval.reason },
50
+ { status: 403 },
51
+ );
52
+ }
53
+
54
+ // The approval token is short-lived and bound to this specific task.
55
+ // Use it as the auth header for the actual side-effecting call.
56
+ return NextResponse.json({
57
+ ok: true,
58
+ description,
59
+ approvalToken: approval.token,
60
+ approvedBy: approval.approvedBy,
61
+ respondedAt: approval.respondedAt,
62
+ });
63
+ }
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+
3
+ import { AuthCallback } from '@lumoauth/react';
4
+
5
+ /**
6
+ * OAuth redirect target. `<AuthCallback>` completes the PKCE exchange and
7
+ * sends the user back to the app.
8
+ */
9
+ export default function CallbackPage() {
10
+ return <AuthCallback />;
11
+ }
@@ -0,0 +1,25 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Providers } from './providers';
3
+
4
+ export const metadata = {
5
+ title: '{{projectName}} · LumoAuth agent',
6
+ description: 'A LumoAuth-secured AI agent demo.',
7
+ };
8
+
9
+ export default function RootLayout({ children }: { children: ReactNode }) {
10
+ return (
11
+ <html lang="en">
12
+ <body
13
+ style={{
14
+ margin: 0,
15
+ fontFamily: 'Inter, system-ui, sans-serif',
16
+ background: '#0a0b1e',
17
+ color: '#f3f4f6',
18
+ minHeight: '100vh',
19
+ }}
20
+ >
21
+ <Providers>{children}</Providers>
22
+ </body>
23
+ </html>
24
+ );
25
+ }
@@ -0,0 +1,141 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { SignIn, useAuth } from '@lumoauth/react';
5
+
6
+ export default function Home() {
7
+ const { user, isSignedIn, signOut } = useAuth();
8
+ const [result, setResult] = useState<string>('');
9
+ const [loading, setLoading] = useState(false);
10
+
11
+ async function callAgent() {
12
+ setLoading(true);
13
+ setResult('');
14
+ try {
15
+ const res = await fetch('/api/agent', {
16
+ method: 'POST',
17
+ headers: { 'Content-Type': 'application/json' },
18
+ body: JSON.stringify({ task: 'send-monthly-report' }),
19
+ });
20
+ const json = await res.json();
21
+ setResult(JSON.stringify(json, null, 2));
22
+ } catch (e) {
23
+ setResult(String(e));
24
+ } finally {
25
+ setLoading(false);
26
+ }
27
+ }
28
+
29
+ async function callApproval() {
30
+ setLoading(true);
31
+ setResult('Sending push to your phone — approve in the LumoAuth app…');
32
+ try {
33
+ const res = await fetch('/api/approval', {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ body: JSON.stringify({ action: 'wire-transfer', amount: 4500, vendor: 'INV-7741' }),
37
+ });
38
+ const json = await res.json();
39
+ setResult(JSON.stringify(json, null, 2));
40
+ } catch (e) {
41
+ setResult(String(e));
42
+ } finally {
43
+ setLoading(false);
44
+ }
45
+ }
46
+
47
+ return (
48
+ <main style={{ maxWidth: 720, margin: '0 auto', padding: '4rem 1.5rem' }}>
49
+ <h1 style={{ fontSize: '2rem', fontWeight: 700, marginBottom: '0.5rem' }}>
50
+ {{projectName}}
51
+ </h1>
52
+ <p style={{ color: '#9ca3af', marginBottom: '2rem' }}>
53
+ A LumoAuth-secured AI agent demo. Sign in, then ask the agent to do something.
54
+ </p>
55
+
56
+ {!isSignedIn ? (
57
+ <SignIn />
58
+ ) : (
59
+ <div>
60
+ <div
61
+ style={{
62
+ padding: '1rem 1.25rem',
63
+ borderRadius: 12,
64
+ background: 'rgba(99, 102, 241, 0.1)',
65
+ border: '1px solid rgba(99, 102, 241, 0.3)',
66
+ marginBottom: '1.5rem',
67
+ display: 'flex',
68
+ alignItems: 'center',
69
+ justifyContent: 'space-between',
70
+ }}
71
+ >
72
+ <span>
73
+ Signed in as <strong>{user?.email}</strong>
74
+ </span>
75
+ <button
76
+ onClick={() => signOut()}
77
+ style={{
78
+ padding: '0.4rem 0.875rem',
79
+ borderRadius: 8,
80
+ background: 'transparent',
81
+ color: '#a5b4fc',
82
+ border: '1px solid #4338ca',
83
+ cursor: 'pointer',
84
+ }}
85
+ >
86
+ Sign out
87
+ </button>
88
+ </div>
89
+
90
+ <div style={{ display: 'flex', gap: '0.75rem', marginBottom: '2rem' }}>
91
+ <button
92
+ onClick={callAgent}
93
+ disabled={loading}
94
+ style={{
95
+ padding: '0.75rem 1.25rem',
96
+ borderRadius: 10,
97
+ background: '#6366f1',
98
+ color: '#fff',
99
+ border: 0,
100
+ cursor: 'pointer',
101
+ fontWeight: 600,
102
+ }}
103
+ >
104
+ Run agent task (no approval needed)
105
+ </button>
106
+ <button
107
+ onClick={callApproval}
108
+ disabled={loading}
109
+ style={{
110
+ padding: '0.75rem 1.25rem',
111
+ borderRadius: 10,
112
+ background: '#a78bfa',
113
+ color: '#0a0b1e',
114
+ border: 0,
115
+ cursor: 'pointer',
116
+ fontWeight: 600,
117
+ }}
118
+ >
119
+ Run risky task (push to phone)
120
+ </button>
121
+ </div>
122
+
123
+ {result && (
124
+ <pre
125
+ style={{
126
+ padding: '1rem',
127
+ borderRadius: 10,
128
+ background: '#1f2037',
129
+ color: '#a5b4fc',
130
+ fontSize: '0.8125rem',
131
+ overflowX: 'auto',
132
+ }}
133
+ >
134
+ {result}
135
+ </pre>
136
+ )}
137
+ </div>
138
+ )}
139
+ </main>
140
+ );
141
+ }
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import { LumoAuthProvider } from '@lumoauth/react';
4
+ import { useEffect, useState, type ReactNode } from 'react';
5
+
6
+ /**
7
+ * Wraps the app in the LumoAuth context so `useAuth`, `<SignIn>`, etc. work.
8
+ * `redirectUri` must be an absolute URL registered on your OAuth client, so we
9
+ * derive it from the current origin after mount (avoids SSR/hydration issues).
10
+ */
11
+ export function Providers({ children }: { children: ReactNode }) {
12
+ const [origin, setOrigin] = useState<string | null>(null);
13
+ useEffect(() => setOrigin(window.location.origin), []);
14
+ if (!origin) return null;
15
+
16
+ return (
17
+ <LumoAuthProvider
18
+ domain={process.env.NEXT_PUBLIC_LUMOAUTH_DOMAIN!}
19
+ orgId={process.env.NEXT_PUBLIC_LUMOAUTH_ORG_ID!}
20
+ clientId={process.env.NEXT_PUBLIC_LUMOAUTH_CLIENT_ID!}
21
+ redirectUri={`${origin}/callback`}
22
+ >
23
+ {children}
24
+ </LumoAuthProvider>
25
+ );
26
+ }
@@ -0,0 +1,6 @@
1
+ node_modules/
2
+ .next/
3
+ .env
4
+ .env.local
5
+ .DS_Store
6
+ *.log
@@ -0,0 +1,17 @@
1
+ import { LumoAuth } from '@lumoauth/client';
2
+
3
+ // Server-side LumoAuth client, authenticated as the agent. The agent's access
4
+ // token carries its identity; the LumoAuth PDP enforces what it may do via the
5
+ // Zanzibar/ABAC policies you author in the dashboard.
6
+ //
7
+ // `baseUrl` is the ROOT domain (no /orgs/...). Org-scoped calls (like push
8
+ // approvals) use `orgId`; non-org calls (permission checks) are resolved from
9
+ // the agent token.
10
+ const baseUrl = process.env.NEXT_PUBLIC_LUMOAUTH_DOMAIN;
11
+ const orgId = process.env.NEXT_PUBLIC_LUMOAUTH_ORG_ID;
12
+ const token = process.env.LUMOAUTH_AGENT_TOKEN ?? '';
13
+
14
+ if (!baseUrl) throw new Error('NEXT_PUBLIC_LUMOAUTH_DOMAIN must be set');
15
+ if (!orgId) throw new Error('NEXT_PUBLIC_LUMOAUTH_ORG_ID must be set');
16
+
17
+ export const lumo = new LumoAuth({ baseUrl, orgId, token: () => token });
@@ -0,0 +1,5 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+
4
+ // NOTE: This file should not be edited
5
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -0,0 +1,4 @@
1
+ /** @type {import('next').NextConfig} */
2
+ module.exports = {
3
+ reactStrictMode: true,
4
+ };
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start"
9
+ },
10
+ "dependencies": {
11
+ "@lumoauth/client": "^1.0.0",
12
+ "@lumoauth/react": "^1.0.0",
13
+ "next": "^15.0.0",
14
+ "react": "^18.3.0",
15
+ "react-dom": "^18.3.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^20.0.0",
19
+ "@types/react": "^18.3.0",
20
+ "@types/react-dom": "^18.3.0",
21
+ "typescript": "^5.0.0"
22
+ }
23
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "module": "esnext",
6
+ "moduleResolution": "bundler",
7
+ "jsx": "preserve",
8
+ "esModuleInterop": true,
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "noEmit": true,
12
+ "incremental": true,
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "allowJs": false,
16
+ "plugins": [{ "name": "next" }],
17
+ "baseUrl": ".",
18
+ "paths": { "@/*": ["./*"] }
19
+ },
20
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
21
+ "exclude": ["node_modules"]
22
+ }