@duct-sdk/sdk 0.5.2 → 0.5.4
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/CHANGELOG.md +13 -0
- package/README.md +145 -136
- package/assets/duct-wordmark.png +0 -0
- package/assets/duct-wordmark.svg +16 -0
- package/assets/duct.png +0 -0
- package/dist/adapters/react/shell.js +33 -1
- package/dist/cli/generators/wiring-snippets.js +53 -35
- package/dist/core/auth-boundaries.d.ts +6 -2
- package/dist/core/auth-boundaries.js +3 -0
- package/dist/core/types.d.ts +2 -2
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog — @duct-sdk/sdk
|
|
2
2
|
|
|
3
|
+
## [0.5.4] — 2026-07-17
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Host panel close (loading)** — `DuctShell` renders a close control on the panel chrome until the iframe posts `DUCT_READY`, so users can dismiss the panel while the shell is still connecting. After the shell is live, close stays inside the embedded shell UI (`DUCT_CLOSE`).
|
|
7
|
+
|
|
8
|
+
## [0.5.3] — 2026-07-17
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
- **Consent callback scaffold (v2)** — `duct init` consent-callback routes receive `duct_consent_code` in the redirect (90s TTL) and exchange it server-to-server via `POST /v1/consent/redeem` with shell credentials. Long-lived consent tokens are never placed in browser URLs or query strings.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Generated consent callback snippets (Next.js App Router + Express) updated for the authorization-code delivery flow; store redeemed tokens server-side for agent retrieval.
|
|
15
|
+
|
|
3
16
|
## [0.5.2] — 2026-07-12
|
|
4
17
|
|
|
5
18
|
### Added
|
package/README.md
CHANGED
|
@@ -1,55 +1,87 @@
|
|
|
1
|
+
```
|
|
2
|
+
██████╗ ██╗ ██╗ ╔██████ ████████╗
|
|
3
|
+
██╔══██╗ ██║ ██║ ╚════╗██ ╚══██╔══╝
|
|
4
|
+
██║ ██║ ██║ ██║ ║██ ██║
|
|
5
|
+
██║ ██║ ██║ ██║ ║██ ██║
|
|
6
|
+
██████╔╝ ╚██████╔╝ ╔██████╝ ██║
|
|
7
|
+
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝
|
|
8
|
+
```
|
|
9
|
+
|
|
1
10
|
# @duct-sdk/sdk
|
|
2
11
|
|
|
3
12
|
**Let agents use your product safely.**
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
[npm version](https://www.npmjs.com/package/@duct-sdk/sdk) | [Node 20+](https://nodejs.org/)
|
|
15
|
+
|
|
16
|
+
The official Duct SDK and CLI. Scan your codebase, declare a manifest, push it to Duct, and embed a permissioned chat shell — so humans and AI agents call your **existing APIs** through one audited surface.
|
|
17
|
+
|
|
6
18
|
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
| Audience | What you get |
|
|
20
|
+
| ------------- | ----------------------------------------------------------------------------------------------- |
|
|
21
|
+
| **Humans** | Embedded chat shell, structured results, signed deeplink handoff into your app |
|
|
22
|
+
| **Agents** | Permissioned API access from the same manifest — no scraping or screen automation |
|
|
23
|
+
| **Operators** | Shell credentials, action tiers, and usage from the [Duct dashboard](https://ductai.vercel.app) |
|
|
9
24
|
|
|
10
|
-
Credentials and shell provisioning are managed by the Duct dashboard.
|
|
11
25
|
|
|
12
26
|
---
|
|
13
27
|
|
|
14
|
-
##
|
|
28
|
+
## Documentation
|
|
15
29
|
|
|
16
|
-
Duct does not replace your API or rewrite your product. You wire four things in your codebase, and Duct does the rest:
|
|
17
30
|
|
|
18
|
-
|
|
|
19
|
-
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
31
|
+
| Resource | Description |
|
|
32
|
+
| -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
33
|
+
| [Developer docs](https://ductai.vercel.app/docs) | Quickstart, CLI, frameworks, agents, threat model |
|
|
34
|
+
| [AI integration prompt](https://ductai.vercel.app/docs/integration-prompt) | Full `DUCT_CONFIG_PROMPT.md` — copy into Cursor, Claude Code, Codex, or any agentic IDE |
|
|
35
|
+
| [TOKEN_SPEC.md](./TOKEN_SPEC.md) | Token prefixes, claims, TTLs, and cross-language verify snippets |
|
|
36
|
+
| [Changelog](https://ductai.vercel.app/changelog) | Platform release notes (includes SDK) |
|
|
24
37
|
|
|
25
|
-
The manifest (`duct.config.ts`) declares which routes, actions, and deeplinks exist. `duct push` uploads it to Duct. Your API stays unchanged.
|
|
26
38
|
|
|
27
39
|
---
|
|
28
40
|
|
|
29
|
-
##
|
|
41
|
+
## AI-assisted integration
|
|
42
|
+
|
|
43
|
+
Duct ships a single integration prompt (`DUCT_CONFIG_PROMPT.md`) for greenfield setup or auditing an existing `duct.config.ts`. Paste it into your coding assistant with the product repo open; the agent generates or reviews manifest fields, the four wiring points, env vars, and a ship checklist.
|
|
30
44
|
|
|
31
|
-
**
|
|
45
|
+
**Get the prompt:** [ductai.vercel.app/docs/integration-prompt](https://ductai.vercel.app/docs/integration-prompt) — expandable, copy-ready, with URLs resolved for your environment.
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
Typical flow:
|
|
48
|
+
|
|
49
|
+
1. Run `duct init` or `duct init --manual` for a first draft.
|
|
50
|
+
2. Paste `DUCT_CONFIG_PROMPT.md` from the docs page to audit wiring and permissions.
|
|
51
|
+
3. `duct push`, embed `<DuctShell>`, smoke-test in the dashboard playground.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Install
|
|
34
56
|
|
|
35
57
|
```bash
|
|
36
|
-
|
|
58
|
+
npm install @duct-sdk/sdk
|
|
59
|
+
# or run without installing:
|
|
60
|
+
npx @duct-sdk/sdk <command>
|
|
37
61
|
```
|
|
38
62
|
|
|
39
|
-
|
|
40
|
-
> `node --experimental-require-module $(npx --no which duct) <command>` or install the
|
|
41
|
-
> package globally with `npm i -g @duct-sdk/sdk` and use `duct <command>`.
|
|
63
|
+
Global CLI (optional): `npm i -g @duct-sdk/sdk` → `duct <command>`.
|
|
42
64
|
|
|
43
|
-
**
|
|
65
|
+
> **Node 22+:** if the CLI exits with `ERR_REQUIRE_ESM`, use
|
|
66
|
+
> `node --experimental-require-module $(npx --no which duct) <command>` or install globally.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quickstart
|
|
71
|
+
|
|
72
|
+
**1. Create a shell** in the Duct dashboard and copy your API key.
|
|
73
|
+
|
|
74
|
+
**2. Log in:**
|
|
44
75
|
|
|
45
76
|
```bash
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
npx @duct-sdk/sdk login
|
|
78
|
+
```
|
|
48
79
|
|
|
49
|
-
|
|
50
|
-
npx @duct-sdk/sdk init
|
|
80
|
+
**3. Generate a manifest:**
|
|
51
81
|
|
|
52
|
-
|
|
82
|
+
```bash
|
|
83
|
+
npx @duct-sdk/sdk init --manual # instant template (recommended first run)
|
|
84
|
+
npx @duct-sdk/sdk init # AI-assisted scan when your API is stable
|
|
53
85
|
npx @duct-sdk/sdk init --api-spec openapi.yaml
|
|
54
86
|
```
|
|
55
87
|
|
|
@@ -59,10 +91,9 @@ npx @duct-sdk/sdk init --api-spec openapi.yaml
|
|
|
59
91
|
npx @duct-sdk/sdk push
|
|
60
92
|
```
|
|
61
93
|
|
|
62
|
-
**5. Embed
|
|
94
|
+
**5. Embed** (Next.js App Router example):
|
|
63
95
|
|
|
64
96
|
```tsx
|
|
65
|
-
// Next.js App Router (root layout)
|
|
66
97
|
import { DuctShell } from '@duct-sdk/sdk/next';
|
|
67
98
|
|
|
68
99
|
export default function RootLayout({ children }) {
|
|
@@ -74,12 +105,15 @@ export default function RootLayout({ children }) {
|
|
|
74
105
|
shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID!}
|
|
75
106
|
shellHost={process.env.NEXT_PUBLIC_DUCT_SHELL_HOST}
|
|
76
107
|
onTokenRequest={async () => {
|
|
77
|
-
const res = await fetch('/api/duct/token', {
|
|
108
|
+
const res = await fetch('/api/duct/token', {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
credentials: 'include',
|
|
111
|
+
});
|
|
78
112
|
return (await res.json()).token ?? '';
|
|
79
113
|
}}
|
|
80
|
-
preset="tall"
|
|
81
|
-
position="bottom-right"
|
|
82
|
-
theme="system"
|
|
114
|
+
preset="tall"
|
|
115
|
+
position="bottom-right"
|
|
116
|
+
theme="system"
|
|
83
117
|
/>
|
|
84
118
|
</body>
|
|
85
119
|
</html>
|
|
@@ -87,78 +121,84 @@ export default function RootLayout({ children }) {
|
|
|
87
121
|
}
|
|
88
122
|
```
|
|
89
123
|
|
|
124
|
+
### Four wiring points
|
|
125
|
+
|
|
126
|
+
Duct does not replace your API. You add four integration points in **your** codebase:
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
| # | What | Where |
|
|
130
|
+
| --- | ----------------- | ----------------------------------------------------------------- |
|
|
131
|
+
| 1 | Token minting | `POST /api/duct/token` → `generateDuctToken` |
|
|
132
|
+
| 2 | API auth | Existing middleware also accepts `verifyDuctToken` delegated JWTs |
|
|
133
|
+
| 3 | Deeplink receiver | `POST /api/duct/receive` → `verifyDeeplinkToken` |
|
|
134
|
+
| 4 | Widget embed | `<DuctShell>` in root layout with `onTokenRequest` |
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
`duct.config.ts` declares routes, actions, deeplinks, and agent permissions. `duct push` uploads it; your business logic stays unchanged.
|
|
138
|
+
|
|
90
139
|
---
|
|
91
140
|
|
|
92
|
-
## Import guide
|
|
141
|
+
## Import guide
|
|
142
|
+
|
|
143
|
+
Use the **subpath** that matches your runtime. The root export pulls React adapters and will crash plain Node servers.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
| Import | Use when |
|
|
147
|
+
| ------------------------- | ------------------------------------------------------------------- |
|
|
148
|
+
| `@duct-sdk/sdk/server` | **Any Node / Edge backend** — tokens, config, introspect. No React. |
|
|
149
|
+
| `@duct-sdk/sdk/next` | Next.js App Router (React) |
|
|
150
|
+
| `@duct-sdk/sdk/react` | React without Next |
|
|
151
|
+
| `@duct-sdk/sdk/vite` | Vite + Express (React) |
|
|
152
|
+
| `@duct-sdk/sdk/remix` | Remix (React) |
|
|
153
|
+
| `@duct-sdk/sdk/sveltekit` | SvelteKit |
|
|
154
|
+
| `@duct-sdk/sdk` | React SSR frontends only — **not** Express/Fastify APIs |
|
|
93
155
|
|
|
94
|
-
| Import | Use when |
|
|
95
|
-
|---|---|
|
|
96
|
-
| `@duct-sdk/sdk/server` | **Any Node.js / Edge backend** — token helpers, config, introspect. No React. Safe in Express, Fastify, Next.js API routes, Remix loaders, SvelteKit hooks. |
|
|
97
|
-
| `@duct-sdk/sdk/next` | Next.js App Router frontend (requires React) |
|
|
98
|
-
| `@duct-sdk/sdk/react` | Plain React or non-Next frameworks (requires React) |
|
|
99
|
-
| `@duct-sdk/sdk/vite` | Vite + Express (requires React) |
|
|
100
|
-
| `@duct-sdk/sdk/remix` | Remix (requires React) |
|
|
101
|
-
| `@duct-sdk/sdk/sveltekit` | SvelteKit |
|
|
102
|
-
| `@duct-sdk/sdk` (root) | Full bundle — only in React SSR frontends where React is already installed. **Crashes plain Express/Fastify backends.** |
|
|
103
156
|
|
|
104
157
|
```ts
|
|
105
|
-
//
|
|
158
|
+
// Server route (Express, Next.js route handler, Remix loader, …)
|
|
106
159
|
import { generateDuctToken, verifyDuctToken } from '@duct-sdk/sdk/server';
|
|
107
|
-
|
|
108
|
-
// ❌ Wrong — pulls in React adapters, crashes if React is not installed
|
|
109
|
-
import { generateDuctToken } from '@duct-sdk/sdk';
|
|
110
160
|
```
|
|
111
161
|
|
|
112
162
|
---
|
|
113
163
|
|
|
114
|
-
## CLI
|
|
164
|
+
## CLI
|
|
115
165
|
|
|
116
|
-
| Command | Description |
|
|
117
|
-
|---|---|
|
|
118
|
-
| `duct login` | Authenticate with your Duct API key |
|
|
119
|
-
| `duct init` | AI-assisted scan — generates config + shell files |
|
|
120
|
-
| `duct init --manual` | Instant template without LLM (recommended first run) |
|
|
121
|
-
| `duct init --update` | Re-scan only files changed since last push |
|
|
122
|
-
| `duct init --api-spec <path>` | Generate manifest from OpenAPI / Swagger spec |
|
|
123
|
-
| `duct init --no-agents` | Skip AI scan; blank template |
|
|
124
|
-
| `duct push` | Push `duct.config.ts` to Duct |
|
|
125
|
-
| `duct pull <hash>` | Restore a manifest version from push history |
|
|
126
|
-
| `duct promote --from <id> --to <id>` | Copy manifest to another environment shell |
|
|
127
|
-
| `duct scan` | Detect drift between live API and manifest |
|
|
128
|
-
| `duct checkup` | Check env config and service connectivity |
|
|
129
166
|
|
|
130
|
-
|
|
167
|
+
| Command | Description |
|
|
168
|
+
| ------------------------------------ | ---------------------------------------- |
|
|
169
|
+
| `duct login` | Authenticate with your Duct API key |
|
|
170
|
+
| `duct init` | AI-assisted scan → config + shell files |
|
|
171
|
+
| `duct init --manual` | Template without LLM |
|
|
172
|
+
| `duct init --update` | Re-scan files changed since last push |
|
|
173
|
+
| `duct init --api-spec <path>` | Manifest from OpenAPI / Swagger |
|
|
174
|
+
| `duct push` | Upload `duct.config.ts` to Duct |
|
|
175
|
+
| `duct pull <hash>` | Restore a manifest version from history |
|
|
176
|
+
| `duct promote --from <id> --to <id>` | Copy manifest between environment shells |
|
|
177
|
+
| `duct scan` | Drift between live API and manifest |
|
|
178
|
+
| `duct checkup` | Env config and service connectivity |
|
|
131
179
|
|
|
132
|
-
---
|
|
133
180
|
|
|
134
|
-
|
|
181
|
+
---
|
|
135
182
|
|
|
136
|
-
|
|
137
|
-
|---|---|---|
|
|
138
|
-
| Next.js (App Router) | `@duct-sdk/sdk/next` | `NEXT_PUBLIC_DUCT_SHELL_ID`, `NEXT_PUBLIC_DUCT_SHELL_HOST` |
|
|
139
|
-
| Vite | `@duct-sdk/sdk/vite` | `VITE_DUCT_SHELL_ID`, `VITE_DUCT_SHELL_HOST` |
|
|
140
|
-
| Remix | `@duct-sdk/sdk/remix` | `VITE_DUCT_SHELL_ID`, `VITE_DUCT_SHELL_HOST` |
|
|
141
|
-
| SvelteKit | `@duct-sdk/sdk/sveltekit` | `PUBLIC_DUCT_SHELL_ID`, `PUBLIC_DUCT_SHELL_HOST` |
|
|
142
|
-
| React (generic) | `@duct-sdk/sdk/react` | any |
|
|
143
|
-
| Express / Fastify / other Node | `@duct-sdk/sdk/server` | — (server only) |
|
|
183
|
+
## Frameworks
|
|
144
184
|
|
|
145
|
-
### Vite + Express
|
|
146
185
|
|
|
147
|
-
|
|
186
|
+
| Framework | Import | Client env vars |
|
|
187
|
+
| ------------------------ | ------------------------- | ---------------------------------------------------------- |
|
|
188
|
+
| Next.js (App Router) | `@duct-sdk/sdk/next` | `NEXT_PUBLIC_DUCT_SHELL_ID`, `NEXT_PUBLIC_DUCT_SHELL_HOST` |
|
|
189
|
+
| Vite | `@duct-sdk/sdk/vite` | `VITE_DUCT_SHELL_ID`, `VITE_DUCT_SHELL_HOST` |
|
|
190
|
+
| Remix | `@duct-sdk/sdk/remix` | `VITE_DUCT_SHELL_ID`, `VITE_DUCT_SHELL_HOST` |
|
|
191
|
+
| SvelteKit | `@duct-sdk/sdk/sveltekit` | `PUBLIC_DUCT_SHELL_ID`, `PUBLIC_DUCT_SHELL_HOST` |
|
|
192
|
+
| React (generic) | `@duct-sdk/sdk/react` | framework-specific |
|
|
193
|
+
| Express / Fastify / Node | `@duct-sdk/sdk/server` | — (server only) |
|
|
148
194
|
|
|
149
|
-
```
|
|
150
|
-
/.env → DUCT_SECRET_KEY, DUCT_SHELL_ID (server, never commit)
|
|
151
|
-
/backend/.env → same values for the Express process if run separately
|
|
152
|
-
/frontend/.env → VITE_DUCT_SHELL_ID, VITE_DUCT_SHELL_HOST (public)
|
|
153
|
-
```
|
|
154
195
|
|
|
155
|
-
|
|
196
|
+
### Vite + Express
|
|
156
197
|
|
|
157
198
|
```ts
|
|
158
199
|
import express from 'express';
|
|
159
|
-
import { generateDuctToken } from '@duct-sdk/sdk/server';
|
|
200
|
+
import { generateDuctToken, verifyDuctToken } from '@duct-sdk/sdk/server';
|
|
160
201
|
|
|
161
|
-
const router = express.Router();
|
|
162
202
|
router.post('/api/duct/token', express.json(), async (req, res) => {
|
|
163
203
|
if (!req.user) return res.status(401).json({ error: 'unauthenticated' });
|
|
164
204
|
const { token } = await generateDuctToken({
|
|
@@ -171,85 +211,54 @@ router.post('/api/duct/token', express.json(), async (req, res) => {
|
|
|
171
211
|
});
|
|
172
212
|
```
|
|
173
213
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
import { verifyDuctToken } from '@duct-sdk/sdk/server';
|
|
178
|
-
|
|
179
|
-
app.use(async (req, res, next) => {
|
|
180
|
-
const header = req.headers.authorization ?? '';
|
|
181
|
-
if (!header.startsWith('Bearer ')) return res.status(401).end();
|
|
182
|
-
const raw = header.slice(7);
|
|
183
|
-
// Try your own JWT first
|
|
184
|
-
const mine = await verifyMyJwt(raw).catch(() => null);
|
|
185
|
-
if (mine) { req.user = mine; return next(); }
|
|
186
|
-
// Fall back to Duct delegated token
|
|
187
|
-
const duct = await verifyDuctToken(raw, {
|
|
188
|
-
secretKey: process.env.DUCT_SECRET_KEY!,
|
|
189
|
-
expectedShellId: process.env.DUCT_SHELL_ID!,
|
|
190
|
-
});
|
|
191
|
-
if (duct.valid) { req.user = duct.payload!.session; return next(); }
|
|
192
|
-
res.status(401).end();
|
|
193
|
-
});
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
|
-
## Webhook configuration
|
|
199
|
-
|
|
200
|
-
Webhook URLs (deeplink callback, event stream) and the signing secret are **not** part of `duct.config.ts` and are **not** pushed via `duct push`. Configure them in the **Duct dashboard → Shell → Settings → Webhooks**.
|
|
201
|
-
|
|
202
|
-
Your endpoint receives a POST with an `X-Duct-Signature` HMAC-SHA256 header for verification. Webhooks are optional — the shell, widget, and action flow work without them.
|
|
214
|
+
Keep secrets in server `.env` only (`DUCT_SECRET_KEY`, `DUCT_SHELL_ID`). Client bundles use public `VITE_*` shell ID / host vars.
|
|
203
215
|
|
|
204
216
|
---
|
|
205
217
|
|
|
206
|
-
## Deeplinks
|
|
207
|
-
|
|
208
|
-
Before declaring deeplinks, inventory every navigable page in your app:
|
|
209
|
-
|
|
210
|
-
1. List all routes where a user lands with identity-specific state (order ID, document ID, profile slug).
|
|
211
|
-
2. Mark which of those a conversation could meaningfully route to.
|
|
212
|
-
3. Declare only those in `deeplinks[]` with matching `stateFields`.
|
|
218
|
+
## Deeplinks & replay protection
|
|
213
219
|
|
|
214
|
-
|
|
220
|
+
Declare deeplinks only for routes you have inventoried in `routes[]`. The receiver must verify signed tokens server-side — never trust raw query params.
|
|
215
221
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Deeplink JWTs include a unique `jti` (JWT ID) claim. Each token is **single-use**: after your receiver verifies it successfully, pass a `replayStore` to `verifyDeeplinkToken` so the same `jti` cannot be accepted again within the TTL window.
|
|
222
|
+
Deeplink JWTs include a `jti` claim. Pass a `replayStore` to `verifyDeeplinkToken` so each token is single-use:
|
|
219
223
|
|
|
220
224
|
```ts
|
|
221
225
|
import {
|
|
222
226
|
verifyDeeplinkToken,
|
|
223
227
|
createDevReplayStore,
|
|
224
228
|
RedisReplayStore,
|
|
225
|
-
} from
|
|
226
|
-
|
|
227
|
-
// Dev / single-instance only:
|
|
228
|
-
const replayStore = createDevReplayStore();
|
|
229
|
+
} from '@duct-sdk/sdk/server';
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
// const replayStore = new RedisReplayStore(redisClient,
|
|
231
|
+
const replayStore = createDevReplayStore(); // dev / single instance
|
|
232
|
+
// const replayStore = new RedisReplayStore(redisClient, 'duct:jti:'); // production
|
|
232
233
|
|
|
233
234
|
const result = await verifyDeeplinkToken(token, {
|
|
234
235
|
secretKey: process.env.DUCT_SECRET_KEY!,
|
|
235
236
|
expectedShellId: ductConfig.shellId,
|
|
236
237
|
replayStore,
|
|
237
238
|
});
|
|
238
|
-
|
|
239
|
-
if (!result.valid && result.error === "Token already used") {
|
|
240
|
-
return res.status(409).json({ error: "Token already used" });
|
|
241
|
-
}
|
|
242
239
|
```
|
|
243
240
|
|
|
244
|
-
|
|
241
|
+
Details: [TOKEN_SPEC.md](./TOKEN_SPEC.md).
|
|
245
242
|
|
|
246
|
-
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Webhooks
|
|
246
|
+
|
|
247
|
+
Webhook URLs and signing secrets are configured in the **dashboard → Shell → Settings → Webhooks**, not in `duct.config.ts`. Your endpoint verifies `X-Duct-Signature` (HMAC-SHA256). Webhooks are optional for chat and actions.
|
|
247
248
|
|
|
248
249
|
---
|
|
249
250
|
|
|
250
251
|
## Security
|
|
251
252
|
|
|
252
|
-
- Keep `DUCT_SECRET_KEY` server-side
|
|
253
|
-
-
|
|
254
|
-
- `sideEffects: true` on any action that creates, updates, deletes, or charges
|
|
253
|
+
- Keep `DUCT_SECRET_KEY` server-side — never in `NEXT_PUBLIC_*`, `VITE_*`, or client bundles
|
|
254
|
+
- Default mutations to `agentAccessible: false` and `sideEffects: true` where appropriate
|
|
255
255
|
- Rotate keys in the dashboard if credentials are exposed
|
|
256
|
+
- Review agent-accessible actions before production — use the [integration prompt](https://ductai.vercel.app/docs/integration-prompt) audit checklist
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Support
|
|
261
|
+
|
|
262
|
+
- Docs: [ductai.vercel.app/docs](https://ductai.vercel.app/docs)
|
|
263
|
+
- npm: [@duct-sdk/sdk](https://www.npmjs.com/package/@duct-sdk/sdk)
|
|
264
|
+
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" role="img" aria-label="DUCT" viewBox="0 0 380 98">
|
|
2
|
+
<text
|
|
3
|
+
fill="#E8622A"
|
|
4
|
+
font-family="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace"
|
|
5
|
+
font-size="13"
|
|
6
|
+
font-weight="700"
|
|
7
|
+
xml:space="preserve"
|
|
8
|
+
>
|
|
9
|
+
<tspan x="0" y="14">??????? ??? ??? ??????? ?????????</tspan>
|
|
10
|
+
<tspan x="0" dy="14">???????? ??? ??? ???????? ?????????</tspan>
|
|
11
|
+
<tspan x="0" dy="14">??? ??? ??? ??? ??? ???</tspan>
|
|
12
|
+
<tspan x="0" dy="14">??? ??? ??? ??? ??? ???</tspan>
|
|
13
|
+
<tspan x="0" dy="14">???????? ????????? ???????? ???</tspan>
|
|
14
|
+
<tspan x="0" dy="14">??????? ??????? ??????? ???</tspan>
|
|
15
|
+
</text>
|
|
16
|
+
</svg>
|
package/assets/duct.png
ADDED
|
Binary file
|
|
@@ -116,6 +116,34 @@ function ShellDragHandle({ onPointerDown, isDragging, isDark, label = "Drag to m
|
|
|
116
116
|
: "0 8px 24px rgba(12,11,9,0.12)",
|
|
117
117
|
}, children: label }))] }));
|
|
118
118
|
}
|
|
119
|
+
/** Close control on the host panel chrome — visible until the iframe posts DUCT_READY. */
|
|
120
|
+
function ShellPanelCloseButton({ onClick, isDark, }) {
|
|
121
|
+
const [hovered, setHovered] = useState(false);
|
|
122
|
+
const color = isDark ? (hovered ? "#C4BFB8" : "#9C9790") : (hovered ? "#524E48" : "#635F59");
|
|
123
|
+
const bg = hovered ? (isDark ? "rgba(255,255,255,0.06)" : "rgba(12,11,9,0.06)") : "transparent";
|
|
124
|
+
return (_jsx("button", { type: "button", "aria-label": "Close shell", onClick: onClick, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), style: {
|
|
125
|
+
position: "absolute",
|
|
126
|
+
top: 8,
|
|
127
|
+
right: 8,
|
|
128
|
+
zIndex: 3,
|
|
129
|
+
width: 28,
|
|
130
|
+
height: 28,
|
|
131
|
+
padding: 0,
|
|
132
|
+
margin: 0,
|
|
133
|
+
border: "none",
|
|
134
|
+
borderRadius: 8,
|
|
135
|
+
cursor: "pointer",
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
justifyContent: "center",
|
|
139
|
+
fontSize: 18,
|
|
140
|
+
lineHeight: 1,
|
|
141
|
+
color,
|
|
142
|
+
background: bg,
|
|
143
|
+
boxShadow: "none",
|
|
144
|
+
transition: "color 150ms ease, background-color 150ms ease",
|
|
145
|
+
}, children: "\u00D7" }));
|
|
146
|
+
}
|
|
119
147
|
function shellLayoutStorageKey(shellId) {
|
|
120
148
|
return `duct-shell-pos:${shellId}`;
|
|
121
149
|
}
|
|
@@ -291,6 +319,10 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
291
319
|
// userContext is delivered via postMessage on DUCT_READY — embedding it in the
|
|
292
320
|
// URL would reload the iframe whenever the host page context changes.
|
|
293
321
|
const shellUrl = useMemo(() => buildShellUrl(shellHost, shellId), [shellHost, shellId]);
|
|
322
|
+
// Reset liveness when the embedded shell identity or URL changes.
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
setIsReady(false);
|
|
325
|
+
}, [shellId, shellUrl]);
|
|
294
326
|
const shellOrigin = (() => {
|
|
295
327
|
try {
|
|
296
328
|
return new URL(shellHost).origin;
|
|
@@ -778,7 +810,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
778
810
|
e.currentTarget.style.transform = "scale(1.07)";
|
|
779
811
|
}, onMouseLeave: (e) => {
|
|
780
812
|
e.currentTarget.style.transform = "scale(1)";
|
|
781
|
-
}, children: bubbleIcon })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [draggable && panelOpen && (_jsx(ShellDragHandle, { onPointerDown: onPanelPointerDown, isDragging: isPanelDragging, isDark: isDarkChrome, label: "Drag to move" })), _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
|
|
813
|
+
}, children: bubbleIcon })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [draggable && panelOpen && (_jsx(ShellDragHandle, { onPointerDown: onPanelPointerDown, isDragging: isPanelDragging, isDark: isDarkChrome, label: "Drag to move" })), panelOpen && !isReady && (_jsx(ShellPanelCloseButton, { onClick: closePanel, isDark: isDarkChrome })), _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
|
|
782
814
|
width: "100%",
|
|
783
815
|
height: "100%",
|
|
784
816
|
border: "none",
|
|
@@ -325,34 +325,43 @@ export const dynamic = "force-dynamic";
|
|
|
325
325
|
export async function GET(request: NextRequest) {
|
|
326
326
|
const { searchParams } = new URL(request.url);
|
|
327
327
|
|
|
328
|
-
const
|
|
329
|
-
const userRef = searchParams.get("user_ref"); // opaque id you supplied at /consent/request
|
|
328
|
+
const consentCode = searchParams.get("duct_consent_code");
|
|
330
329
|
const error = searchParams.get("error");
|
|
331
330
|
|
|
332
331
|
if (error) {
|
|
333
|
-
// User denied — redirect to a graceful error page
|
|
334
332
|
return NextResponse.redirect(new URL("/agent-access-denied", request.url));
|
|
335
333
|
}
|
|
336
334
|
|
|
337
|
-
if (!
|
|
338
|
-
return NextResponse.json({ error: "
|
|
335
|
+
if (!consentCode) {
|
|
336
|
+
return NextResponse.json({ error: "missing_code" }, { status: 400 });
|
|
339
337
|
}
|
|
340
338
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
339
|
+
const authUrl = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
|
|
340
|
+
const redeemResp = await fetch(\`\${authUrl}/v1/consent/redeem\`, {
|
|
341
|
+
method: "POST",
|
|
342
|
+
headers: { "Content-Type": "application/json" },
|
|
343
|
+
body: JSON.stringify({
|
|
344
|
+
shellId: process.env.DUCT_SHELL_ID,
|
|
345
|
+
clientSecret: process.env.DUCT_SECRET_KEY,
|
|
346
|
+
code: consentCode,
|
|
347
|
+
}),
|
|
348
|
+
cache: "no-store",
|
|
349
|
+
});
|
|
350
|
+
const redeemData = (await redeemResp.json()) as {
|
|
351
|
+
user_consent_token?: string;
|
|
352
|
+
user_ref?: string;
|
|
353
|
+
error?: string;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
if (!redeemResp.ok || !redeemData.user_consent_token) {
|
|
357
|
+
return NextResponse.json({ error: redeemData.error ?? "redeem_failed" }, { status: 400 });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// TODO: store { userConsentToken: redeemData.user_consent_token, userRef: redeemData.user_ref }
|
|
361
|
+
// server-side so the agent can retrieve it — never keep uct_ in the browser URL.
|
|
362
|
+
|
|
363
|
+
const clean = new URL("/agent-connected", request.url);
|
|
364
|
+
return NextResponse.redirect(clean);
|
|
356
365
|
}
|
|
357
366
|
`;
|
|
358
367
|
}
|
|
@@ -363,28 +372,37 @@ import { Router, Request, Response } from "express";
|
|
|
363
372
|
const router = Router();
|
|
364
373
|
|
|
365
374
|
router.get("/", async (req: Request, res: Response) => {
|
|
366
|
-
const {
|
|
375
|
+
const { duct_consent_code: consentCode, error } = req.query as Record<string, string>;
|
|
367
376
|
|
|
368
377
|
if (error) {
|
|
369
|
-
// User denied — redirect to a graceful error page
|
|
370
378
|
return res.redirect("/agent-access-denied");
|
|
371
379
|
}
|
|
372
380
|
|
|
373
|
-
if (!
|
|
374
|
-
return res.status(400).json({ error: "
|
|
381
|
+
if (!consentCode) {
|
|
382
|
+
return res.status(400).json({ error: "missing_code" });
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const authUrl = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
|
|
386
|
+
const redeemResp = await fetch(\`\${authUrl}/v1/consent/redeem\`, {
|
|
387
|
+
method: "POST",
|
|
388
|
+
headers: { "Content-Type": "application/json" },
|
|
389
|
+
body: JSON.stringify({
|
|
390
|
+
shellId: process.env.DUCT_SHELL_ID,
|
|
391
|
+
clientSecret: process.env.DUCT_SECRET_KEY,
|
|
392
|
+
code: consentCode,
|
|
393
|
+
}),
|
|
394
|
+
});
|
|
395
|
+
const redeemData = (await redeemResp.json()) as {
|
|
396
|
+
user_consent_token?: string;
|
|
397
|
+
user_ref?: string;
|
|
398
|
+
error?: string;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
if (!redeemResp.ok || !redeemData.user_consent_token) {
|
|
402
|
+
return res.status(400).json({ error: redeemData.error ?? "redeem_failed" });
|
|
375
403
|
}
|
|
376
404
|
|
|
377
|
-
// TODO: store
|
|
378
|
-
// Options:
|
|
379
|
-
// • Push to a webhook/queue your agent is listening on
|
|
380
|
-
// • Write to DB: INSERT INTO agent_grants (user_ref, uct, granted_at) VALUES (...)
|
|
381
|
-
// • Cache in Redis with a short TTL for the agent to poll
|
|
382
|
-
//
|
|
383
|
-
// Example DB insert:
|
|
384
|
-
// await db.query(
|
|
385
|
-
// "INSERT INTO agent_grants (user_ref, uct, granted_at) VALUES ($1, $2, NOW()) ON CONFLICT (user_ref) DO UPDATE SET uct = $2, granted_at = NOW()",
|
|
386
|
-
// [userRef, userConsentToken],
|
|
387
|
-
// );
|
|
405
|
+
// TODO: store redeemData.user_consent_token + redeemData.user_ref server-side for the agent.
|
|
388
406
|
|
|
389
407
|
return res.redirect("/agent-connected");
|
|
390
408
|
});
|
|
@@ -3,8 +3,12 @@ export interface ActionDefinitionGrant {
|
|
|
3
3
|
actionId: string;
|
|
4
4
|
definitionHash: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function computeActionDefinitionFingerprint(action: Pick<ActionManifest, "method" | "path" | "sideEffects" | "sensitivityLevel">
|
|
7
|
-
|
|
6
|
+
export declare function computeActionDefinitionFingerprint(action: Pick<ActionManifest, "method" | "path" | "sideEffects" | "sensitivityLevel"> & {
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function buildActionDefinitionGrants(actionIds: string[], actionsById: Record<string, Pick<ActionManifest, "method" | "path" | "sideEffects" | "sensitivityLevel"> & {
|
|
10
|
+
endpoint?: string;
|
|
11
|
+
}>): ActionDefinitionGrant[];
|
|
8
12
|
export type ActionRiskTier = "read" | "write" | "delete";
|
|
9
13
|
export declare function classifyActionRiskTier(action: Pick<ActionManifest, "method" | "sideEffects">): ActionRiskTier;
|
|
10
14
|
export declare function checkAgentScope(scopes: string[], action: Pick<ActionManifest, "id" | "method" | "path" | "sideEffects" | "sensitivityLevel">, params?: Record<string, unknown>): {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
export function computeActionDefinitionFingerprint(action) {
|
|
3
|
+
const effectiveTarget = action.endpoint ?? action.path ?? "";
|
|
4
|
+
// Keep canonical key set aligned with server-side action definition fingerprints.
|
|
3
5
|
const canonical = JSON.stringify({
|
|
4
6
|
method: (action.method ?? "GET").toUpperCase(),
|
|
5
7
|
path: action.path ?? "",
|
|
8
|
+
endpoint: effectiveTarget,
|
|
6
9
|
sideEffects: Boolean(action.sideEffects),
|
|
7
10
|
sensitivityLevel: action.sensitivityLevel ?? "low",
|
|
8
11
|
});
|
package/dist/core/types.d.ts
CHANGED
|
@@ -289,8 +289,8 @@ export interface AgentPermissions {
|
|
|
289
289
|
validUntil?: string;
|
|
290
290
|
/**
|
|
291
291
|
* Explicit action IDs third-party consent (`uct_`) may authorize per request.
|
|
292
|
-
* When set,
|
|
293
|
-
*
|
|
292
|
+
* When set, each grant must list actions from this set. Enforced at consent
|
|
293
|
+
* issuance (auth service) and the Duct gateway on invoke.
|
|
294
294
|
*/
|
|
295
295
|
consentActionScope?: string[];
|
|
296
296
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duct-sdk/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Duct SDK —
|
|
5
|
+
"description": "Duct SDK — manifest, CLI, and embed components for permissioned human and agent access to your product APIs.",
|
|
6
|
+
"homepage": "https://ductai.vercel.app/docs",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"bin": {
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"scripts": {
|
|
21
22
|
"build": "tsc",
|
|
22
23
|
"dev": "tsc --watch",
|
|
23
|
-
"test": "npm run build && node --test dist/core
|
|
24
|
+
"test": "npm run build && node --test dist/core/*.test.js dist/adapters/react/*.test.js dist/cli/*.test.js dist/cli/generators/*.test.js dist/cli/processors/*.test.js",
|
|
24
25
|
"verify:publish": "node scripts/verify-publish.mjs",
|
|
25
26
|
"prepublishOnly": "npm run build && npm run verify:publish"
|
|
26
27
|
},
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
},
|
|
65
66
|
"files": [
|
|
66
67
|
"dist",
|
|
68
|
+
"assets",
|
|
67
69
|
"README.md",
|
|
68
70
|
"CHANGELOG.md",
|
|
69
71
|
"TOKEN_SPEC.md"
|