create-lumo-agent 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/index.js +128 -0
- package/package.json +45 -4
- package/templates/nextjs-agent/.env.example +14 -0
- package/templates/nextjs-agent/README.md +29 -0
- package/templates/nextjs-agent/app/api/agent/route.ts +25 -0
- package/templates/nextjs-agent/app/api/approval/route.ts +46 -0
- package/templates/nextjs-agent/app/callback/page.tsx +11 -0
- package/templates/nextjs-agent/app/layout.tsx +25 -0
- package/templates/nextjs-agent/app/page.tsx +141 -0
- package/templates/nextjs-agent/app/providers.tsx +26 -0
- package/templates/nextjs-agent/gitignore +6 -0
- package/templates/nextjs-agent/lib/lumo.ts +17 -0
- package/templates/nextjs-agent/next-env.d.ts +5 -0
- package/templates/nextjs-agent/next.config.js +4 -0
- package/templates/nextjs-agent/package.json +23 -0
- package/templates/nextjs-agent/tsconfig.json +22 -0
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,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-lumo-agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffold a working LumoAuth-secured AI agent application in **under 60 seconds**.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-lumo-agent my-agent
|
|
7
|
+
cd my-agent
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
What you get:
|
|
13
|
+
|
|
14
|
+
- **Next.js 15 (App Router)** with `<SignIn>` (from `@lumoauth/react`) ready out of the box
|
|
15
|
+
- An **agent identity** registered with your LumoAuth tenant
|
|
16
|
+
- **JIT permission requests** wired to a sample tool the agent calls on the user's behalf
|
|
17
|
+
- **Push approval** so a human approves on their phone before the agent does anything irreversible
|
|
18
|
+
- A working `npm run dev` demo: visit `/`, sign in, ask the agent to do something — watch the request hit your phone for approval, see it complete
|
|
19
|
+
|
|
20
|
+
## Templates
|
|
21
|
+
|
|
22
|
+
- `nextjs-agent` (default) — Next.js + React + TypeScript
|
|
23
|
+
|
|
24
|
+
> `python-agent` (FastAPI) and `langgraph-agent` starters are on the roadmap.
|
|
25
|
+
|
|
26
|
+
## Prerequisites
|
|
27
|
+
|
|
28
|
+
- Node 18+
|
|
29
|
+
- A LumoAuth tenant — sign up free at [https://lumoauth.dev](https://lumoauth.dev)
|
|
30
|
+
|
|
31
|
+
## CLI options
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
create-lumo-agent <project-name> [--template nextjs-agent] [--no-install]
|
|
35
|
+
```
|
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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.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,46 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { lumo } from '@/lib/lumo';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Push-approval-for-agent-actions demo.
|
|
6
|
+
*
|
|
7
|
+
* The agent wants to do something irreversible (wire transfer). It calls
|
|
8
|
+
* `agent.requireApproval()` which:
|
|
9
|
+
* 1. sends a push to the user's phone with the action description
|
|
10
|
+
* 2. polls until the user taps approve/deny (or the request times out)
|
|
11
|
+
* 3. resolves with the approval status + a short-lived approval token
|
|
12
|
+
*
|
|
13
|
+
* This is the demo nobody else has.
|
|
14
|
+
*/
|
|
15
|
+
export async function POST(req: Request) {
|
|
16
|
+
const { action, amount, vendor, onBehalfOf } = await req.json();
|
|
17
|
+
|
|
18
|
+
const description = `Wire $${Number(amount).toLocaleString()} to vendor ${vendor}`;
|
|
19
|
+
|
|
20
|
+
const approval = await lumo.agent.requireApproval({
|
|
21
|
+
taskId: `wire-${action}-${vendor}`,
|
|
22
|
+
reason: description,
|
|
23
|
+
impact: 'high',
|
|
24
|
+
// The user (subject) who must approve. In a real app this is the signed-in
|
|
25
|
+
// user the agent is acting for.
|
|
26
|
+
onBehalfOf: onBehalfOf ?? 'user@example.com',
|
|
27
|
+
meta: { action, amount, vendor },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (approval.status !== 'approved') {
|
|
31
|
+
return NextResponse.json(
|
|
32
|
+
{ error: 'denied', status: approval.status, reason: approval.reason },
|
|
33
|
+
{ status: 403 },
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The approval token is short-lived and bound to this specific task.
|
|
38
|
+
// Use it as the auth header for the actual side-effecting call.
|
|
39
|
+
return NextResponse.json({
|
|
40
|
+
ok: true,
|
|
41
|
+
description,
|
|
42
|
+
approvalToken: approval.token,
|
|
43
|
+
approvedBy: approval.approvedBy,
|
|
44
|
+
respondedAt: approval.respondedAt,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -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,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,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
|
+
}
|