@duct-sdk/sdk 0.6.0 → 0.7.1

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.
@@ -35,203 +35,203 @@ export function generateVerifyDuctTokenMiddlewareSnippet(framework, middlewarePa
35
35
  const target = middlewarePath ?? "your API auth middleware";
36
36
  const isExpress = framework.name === "vite-react";
37
37
  if (isExpress) {
38
- return `/**
39
- * Add to ${target} — verify Duct delegated tokens on proxied action calls.
40
- * Import from @duct-sdk/sdk/server (not the root @duct-sdk/sdk export).
41
- */
42
- import type { Request, Response, NextFunction } from "express";
43
- import { verifyDuctToken } from "@duct-sdk/sdk/server";
44
-
45
- export async function ductDelegatedAuth(req: Request, res: Response, next: NextFunction) {
46
- const authHeader = req.headers.authorization;
47
- if (!authHeader?.startsWith("Bearer ")) {
48
- return next();
49
- }
50
-
51
- const token = authHeader.slice(7);
52
- const secretKey = process.env.DUCT_SECRET_KEY;
53
- const shellId = process.env.DUCT_SHELL_ID;
54
- if (!secretKey || !shellId) {
55
- return res.status(500).json({ error: "Duct not configured" });
56
- }
57
-
58
- const result = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
59
- if (!result.valid) {
60
- return res.status(401).json({ error: result.error ?? "Invalid delegated token" });
61
- }
62
-
63
- (req as Request & { user?: Record<string, unknown> }).user = result.payload!.session;
64
- return next();
65
- }
38
+ return `/**
39
+ * Add to ${target} — verify Duct delegated tokens on proxied action calls.
40
+ * Import from @duct-sdk/sdk/server (not the root @duct-sdk/sdk export).
41
+ */
42
+ import type { Request, Response, NextFunction } from "express";
43
+ import { verifyDuctToken } from "@duct-sdk/sdk/server";
44
+
45
+ export async function ductDelegatedAuth(req: Request, res: Response, next: NextFunction) {
46
+ const authHeader = req.headers.authorization;
47
+ if (!authHeader?.startsWith("Bearer ")) {
48
+ return next();
49
+ }
50
+
51
+ const token = authHeader.slice(7);
52
+ const secretKey = process.env.DUCT_SECRET_KEY;
53
+ const shellId = process.env.DUCT_SHELL_ID;
54
+ if (!secretKey || !shellId) {
55
+ return res.status(500).json({ error: "Duct not configured" });
56
+ }
57
+
58
+ const result = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
59
+ if (!result.valid) {
60
+ return res.status(401).json({ error: result.error ?? "Invalid delegated token" });
61
+ }
62
+
63
+ (req as Request & { user?: Record<string, unknown> }).user = result.payload!.session;
64
+ return next();
65
+ }
66
66
  `;
67
67
  }
68
- return `/**
69
- * Add to ${target} — fall back to verifyDuctToken when native session auth is absent.
70
- * The agent proxy sends: Authorization: Bearer <duct_delegated>, X-Duct-Proxy: 1
71
- */
72
- import { verifyDuctToken } from "@duct-sdk/sdk/server";
73
-
74
- export async function resolveUserFromRequest(request: Request): Promise<Record<string, unknown> | null> {
75
- // 1) Try your native session/JWT first (NextAuth, Clerk, etc.)
76
- // const session = await auth();
77
- // if (session?.user) return session.user as Record<string, unknown>;
78
-
79
- const authHeader = request.headers.get("authorization");
80
- if (!authHeader?.startsWith("Bearer ")) {
81
- return null;
82
- }
83
-
84
- const token = authHeader.slice(7);
85
- const secretKey = process.env.DUCT_SECRET_KEY!;
86
- const shellId = process.env.DUCT_SHELL_ID ?? process.env.NEXT_PUBLIC_DUCT_SHELL_ID!;
87
-
88
- const result = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
89
- if (!result.valid) {
90
- throw new Error(result.error ?? "Invalid delegated token");
91
- }
92
-
93
- return result.payload.session;
94
- }
68
+ return `/**
69
+ * Add to ${target} — fall back to verifyDuctToken when native session auth is absent.
70
+ * The agent proxy sends: Authorization: Bearer <duct_delegated>, X-Duct-Proxy: 1
71
+ */
72
+ import { verifyDuctToken } from "@duct-sdk/sdk/server";
73
+
74
+ export async function resolveUserFromRequest(request: Request): Promise<Record<string, unknown> | null> {
75
+ // 1) Try your native session/JWT first (NextAuth, Clerk, etc.)
76
+ // const session = await auth();
77
+ // if (session?.user) return session.user as Record<string, unknown>;
78
+
79
+ const authHeader = request.headers.get("authorization");
80
+ if (!authHeader?.startsWith("Bearer ")) {
81
+ return null;
82
+ }
83
+
84
+ const token = authHeader.slice(7);
85
+ const secretKey = process.env.DUCT_SECRET_KEY!;
86
+ const shellId = process.env.DUCT_SHELL_ID ?? process.env.NEXT_PUBLIC_DUCT_SHELL_ID!;
87
+
88
+ const result = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
89
+ if (!result.valid) {
90
+ throw new Error(result.error ?? "Invalid delegated token");
91
+ }
92
+
93
+ return result.payload.session;
94
+ }
95
95
  `;
96
96
  }
97
97
  export function generateUctVerificationSnippet(framework) {
98
98
  const isExpress = framework.name === "vite-react";
99
99
  if (isExpress) {
100
- return `/**
101
- * Third-party agent user identity — verify Duct consent tokens (uct_).
102
- * POST \${DUCT_AUTH_URL}/v1/verify/consent-token
103
- *
104
- * Identity-only: { token } is enough to resolve user_ref.
105
- * Policy mode (recommended when Duct proxies the call): also send
106
- * target_shell + required_action from X-Duct-Shell-ID / X-Duct-Action-ID.
107
- *
108
- * On success, req.ductUserRef contains the opaque company user identifier you
109
- * supplied at consent-request time. Resolve mutable data (email, roles) from
110
- * YOUR own DB using that id — never trust the JWT payload for live attributes.
111
- */
112
- import type { Request, Response, NextFunction } from "express";
113
- import { verifyDuctToken } from "@duct-sdk/sdk/server";
114
-
115
- const DUCT_AUTH_URL = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
116
-
117
- interface UctVerifyResult {
118
- userRef?: string;
119
- allowedActions?: string[];
120
- }
121
-
122
- async function verifyUct(
123
- token: string,
124
- opts?: { targetShell?: string; requiredAction?: string },
125
- ): Promise<UctVerifyResult | null> {
126
- const body: Record<string, string> = { token };
127
- if (opts?.targetShell && opts?.requiredAction) {
128
- body.target_shell = opts.targetShell;
129
- body.required_action = opts.requiredAction;
130
- }
131
- const res = await fetch(\`\${DUCT_AUTH_URL}/v1/verify/consent-token\`, {
132
- method: "POST",
133
- headers: { "Content-Type": "application/json" },
134
- body: JSON.stringify(body),
135
- });
136
- if (!res.ok) return null;
137
- const parsed = (await res.json()) as { valid?: boolean; user_ref?: string; allowed_actions?: string[] };
138
- if (!parsed.valid) return null;
139
- return { userRef: parsed.user_ref, allowedActions: parsed.allowed_actions };
140
- }
141
-
142
- export async function ductOrConsentAuth(req: Request, res: Response, next: NextFunction) {
143
- const authHeader = req.headers.authorization;
144
- if (!authHeader?.startsWith("Bearer ")) return next();
145
-
146
- const token = authHeader.slice(7);
147
- if (token.startsWith("uct_")) {
148
- const shellId = typeof req.headers["x-duct-shell-id"] === "string" ? req.headers["x-duct-shell-id"] : undefined;
149
- const actionId = typeof req.headers["x-duct-action-id"] === "string" ? req.headers["x-duct-action-id"] : undefined;
150
- const result = await verifyUct(token, { targetShell: shellId, requiredAction: actionId });
151
- if (!result) return res.status(401).json({ success: false, message: "Invalid Duct user consent token" });
152
- (req as Request & { ductUserRef?: string }).ductUserRef = result.userRef;
153
- return next();
154
- }
155
-
156
- const secretKey = process.env.DUCT_SECRET_KEY;
157
- const shellId = process.env.DUCT_SHELL_ID;
158
- if (!secretKey || !shellId) {
159
- return res.status(500).json({ error: "Duct not configured" });
160
- }
161
-
162
- const delegated = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
163
- if (!delegated.valid) {
164
- return res.status(401).json({ error: delegated.error ?? "Invalid delegated token" });
165
- }
166
-
167
- (req as Request & { user?: Record<string, unknown> }).user = delegated.payload!.session;
168
- return next();
169
- }
100
+ return `/**
101
+ * Third-party agent user identity — verify Duct consent tokens (uct_).
102
+ * POST \${DUCT_AUTH_URL}/v1/verify/consent-token
103
+ *
104
+ * Identity-only: { token } is enough to resolve user_ref.
105
+ * Policy mode (recommended when Duct proxies the call): also send
106
+ * target_shell + required_action from X-Duct-Shell-ID / X-Duct-Action-ID.
107
+ *
108
+ * On success, req.ductUserRef contains the opaque company user identifier you
109
+ * supplied at consent-request time. Resolve mutable data (email, roles) from
110
+ * YOUR own DB using that id — never trust the JWT payload for live attributes.
111
+ */
112
+ import type { Request, Response, NextFunction } from "express";
113
+ import { verifyDuctToken } from "@duct-sdk/sdk/server";
114
+
115
+ const DUCT_AUTH_URL = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
116
+
117
+ interface UctVerifyResult {
118
+ userRef?: string;
119
+ allowedActions?: string[];
120
+ }
121
+
122
+ async function verifyUct(
123
+ token: string,
124
+ opts?: { targetShell?: string; requiredAction?: string },
125
+ ): Promise<UctVerifyResult | null> {
126
+ const body: Record<string, string> = { token };
127
+ if (opts?.targetShell && opts?.requiredAction) {
128
+ body.target_shell = opts.targetShell;
129
+ body.required_action = opts.requiredAction;
130
+ }
131
+ const res = await fetch(\`\${DUCT_AUTH_URL}/v1/verify/consent-token\`, {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/json" },
134
+ body: JSON.stringify(body),
135
+ });
136
+ if (!res.ok) return null;
137
+ const parsed = (await res.json()) as { valid?: boolean; user_ref?: string; allowed_actions?: string[] };
138
+ if (!parsed.valid) return null;
139
+ return { userRef: parsed.user_ref, allowedActions: parsed.allowed_actions };
140
+ }
141
+
142
+ export async function ductOrConsentAuth(req: Request, res: Response, next: NextFunction) {
143
+ const authHeader = req.headers.authorization;
144
+ if (!authHeader?.startsWith("Bearer ")) return next();
145
+
146
+ const token = authHeader.slice(7);
147
+ if (token.startsWith("uct_")) {
148
+ const shellId = typeof req.headers["x-duct-shell-id"] === "string" ? req.headers["x-duct-shell-id"] : undefined;
149
+ const actionId = typeof req.headers["x-duct-action-id"] === "string" ? req.headers["x-duct-action-id"] : undefined;
150
+ const result = await verifyUct(token, { targetShell: shellId, requiredAction: actionId });
151
+ if (!result) return res.status(401).json({ success: false, message: "Invalid Duct user consent token" });
152
+ (req as Request & { ductUserRef?: string }).ductUserRef = result.userRef;
153
+ return next();
154
+ }
155
+
156
+ const secretKey = process.env.DUCT_SECRET_KEY;
157
+ const shellId = process.env.DUCT_SHELL_ID;
158
+ if (!secretKey || !shellId) {
159
+ return res.status(500).json({ error: "Duct not configured" });
160
+ }
161
+
162
+ const delegated = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
163
+ if (!delegated.valid) {
164
+ return res.status(401).json({ error: delegated.error ?? "Invalid delegated token" });
165
+ }
166
+
167
+ (req as Request & { user?: Record<string, unknown> }).user = delegated.payload!.session;
168
+ return next();
169
+ }
170
170
  `;
171
171
  }
172
- return `/**
173
- * Third-party agent user identity — accept uct_ consent tokens OR duct_delegated JWTs.
174
- * Configure DUCT_AUTH_URL in server env (never NEXT_PUBLIC_* / VITE_*).
175
- *
176
- * Identity-only: { token } is enough to resolve user_ref.
177
- * When Duct proxies the call it also sends X-Duct-Shell-ID + X-Duct-Action-ID —
178
- * pass those as target_shell / required_action for policy-bound verification.
179
- *
180
- * When a uct_ token is present, verify returns user_ref — an opaque handle YOU assigned
181
- * at identity-resolution time (a Duct-facing alias; not necessarily a storage primary key).
182
- * Map it to the live user on your server. Do NOT store PII in the token itself.
183
- */
184
- import { verifyDuctToken } from "@duct-sdk/sdk/server";
185
-
186
- const DUCT_AUTH_URL = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
187
-
188
- interface ConsentVerifyResult {
189
- user_ref?: string;
190
- allowed_actions?: string[];
191
- }
192
-
193
- async function verifyConsentToken(
194
- token: string,
195
- opts?: { targetShell?: string; requiredAction?: string },
196
- ): Promise<ConsentVerifyResult | null> {
197
- const body: Record<string, string> = { token };
198
- if (opts?.targetShell && opts?.requiredAction) {
199
- body.target_shell = opts.targetShell;
200
- body.required_action = opts.requiredAction;
201
- }
202
- const res = await fetch(\`\${DUCT_AUTH_URL}/v1/verify/consent-token\`, {
203
- method: "POST",
204
- headers: { "Content-Type": "application/json" },
205
- body: JSON.stringify(body),
206
- });
207
- if (!res.ok) return null;
208
- const parsed = (await res.json()) as { valid?: boolean; user_ref?: string; allowed_actions?: string[] };
209
- if (!parsed.valid) return null;
210
- return { user_ref: parsed.user_ref, allowed_actions: parsed.allowed_actions };
211
- }
212
-
213
- export async function resolveAgentAwareUser(
214
- request: Request,
215
- ): Promise<{ userRef?: string; session?: Record<string, unknown> } | null> {
216
- const authHeader = request.headers.get("authorization");
217
- if (!authHeader?.startsWith("Bearer ")) return null;
218
-
219
- const token = authHeader.slice(7);
220
- if (token.startsWith("uct_")) {
221
- const result = await verifyConsentToken(token, {
222
- targetShell: request.headers.get("x-duct-shell-id") ?? undefined,
223
- requiredAction: request.headers.get("x-duct-action-id") ?? undefined,
224
- });
225
- if (!result) return null;
226
- // Map user_ref to the live user with your server-side lookup.
227
- return { userRef: result.user_ref };
228
- }
229
-
230
- const secretKey = process.env.DUCT_SECRET_KEY!;
231
- const shellId = process.env.DUCT_SHELL_ID ?? process.env.NEXT_PUBLIC_DUCT_SHELL_ID!;
232
- const delegated = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
233
- return delegated.valid ? { session: delegated.payload.session as Record<string, unknown> } : null;
234
- }
172
+ return `/**
173
+ * Third-party agent user identity — accept uct_ consent tokens OR duct_delegated JWTs.
174
+ * Configure DUCT_AUTH_URL in server env (never NEXT_PUBLIC_* / VITE_*).
175
+ *
176
+ * Identity-only: { token } is enough to resolve user_ref.
177
+ * When Duct proxies the call it also sends X-Duct-Shell-ID + X-Duct-Action-ID —
178
+ * pass those as target_shell / required_action for policy-bound verification.
179
+ *
180
+ * When a uct_ token is present, verify returns user_ref — an opaque handle YOU assigned
181
+ * at identity-resolution time (a Duct-facing alias; not necessarily a storage primary key).
182
+ * Map it to the live user on your server. Do NOT store PII in the token itself.
183
+ */
184
+ import { verifyDuctToken } from "@duct-sdk/sdk/server";
185
+
186
+ const DUCT_AUTH_URL = process.env.DUCT_AUTH_URL ?? "http://localhost:3001";
187
+
188
+ interface ConsentVerifyResult {
189
+ user_ref?: string;
190
+ allowed_actions?: string[];
191
+ }
192
+
193
+ async function verifyConsentToken(
194
+ token: string,
195
+ opts?: { targetShell?: string; requiredAction?: string },
196
+ ): Promise<ConsentVerifyResult | null> {
197
+ const body: Record<string, string> = { token };
198
+ if (opts?.targetShell && opts?.requiredAction) {
199
+ body.target_shell = opts.targetShell;
200
+ body.required_action = opts.requiredAction;
201
+ }
202
+ const res = await fetch(\`\${DUCT_AUTH_URL}/v1/verify/consent-token\`, {
203
+ method: "POST",
204
+ headers: { "Content-Type": "application/json" },
205
+ body: JSON.stringify(body),
206
+ });
207
+ if (!res.ok) return null;
208
+ const parsed = (await res.json()) as { valid?: boolean; user_ref?: string; allowed_actions?: string[] };
209
+ if (!parsed.valid) return null;
210
+ return { user_ref: parsed.user_ref, allowed_actions: parsed.allowed_actions };
211
+ }
212
+
213
+ export async function resolveAgentAwareUser(
214
+ request: Request,
215
+ ): Promise<{ userRef?: string; session?: Record<string, unknown> } | null> {
216
+ const authHeader = request.headers.get("authorization");
217
+ if (!authHeader?.startsWith("Bearer ")) return null;
218
+
219
+ const token = authHeader.slice(7);
220
+ if (token.startsWith("uct_")) {
221
+ const result = await verifyConsentToken(token, {
222
+ targetShell: request.headers.get("x-duct-shell-id") ?? undefined,
223
+ requiredAction: request.headers.get("x-duct-action-id") ?? undefined,
224
+ });
225
+ if (!result) return null;
226
+ // Map user_ref to the live user with your server-side lookup.
227
+ return { userRef: result.user_ref };
228
+ }
229
+
230
+ const secretKey = process.env.DUCT_SECRET_KEY!;
231
+ const shellId = process.env.DUCT_SHELL_ID ?? process.env.NEXT_PUBLIC_DUCT_SHELL_ID!;
232
+ const delegated = await verifyDuctToken(token, { secretKey, expectedShellId: shellId });
233
+ return delegated.valid ? { session: delegated.payload.session as Record<string, unknown> } : null;
234
+ }
235
235
  `;
236
236
  }
237
237
  export function buildWiringPlan(outputPaths, framework, authDetection, thirdPartyAgentMode) {
@@ -278,20 +278,11 @@ export function buildWiringPlan(outputPaths, framework, authDetection, thirdPart
278
278
  if (thirdPartyAgentMode === "duct-consent") {
279
279
  plan.uctSnippetPath = ".duct/snippets/uct-consent-auth.ts";
280
280
  plan.uctSnippet = generateUctVerificationSnippet(framework);
281
- plan.consentCallbackSnippetPath = ".duct/snippets/duct-consent-callback.ts";
282
- plan.consentCallbackSnippet = generateConsentCallbackSnippet(framework);
283
281
  items.push({
284
282
  path: middlewareTarget,
285
283
  action: "modify",
286
284
  summary: "Verify uct_ consent tokens for third-party agent /message calls",
287
285
  });
288
- items.push({
289
- path: framework.name === "next-app" || framework.name === "next-pages"
290
- ? "app/api/duct/callback/route.ts"
291
- : "routes/duct/callback.ts",
292
- action: "create",
293
- summary: "Consent callback — receives uct_ + user_ref after human approval, stores for agent",
294
- });
295
286
  }
296
287
  if (thirdPartyAgentMode === "oauth") {
297
288
  items.push({
@@ -302,114 +293,6 @@ export function buildWiringPlan(outputPaths, framework, authDetection, thirdPart
302
293
  }
303
294
  return plan;
304
295
  }
305
- /**
306
- * Scaffold for the consent callback route your app must expose when using
307
- * the duct-consent third-party agent mode.
308
- *
309
- * This route receives the redirect from Duct after a user approves an agent
310
- * consent request. It stores the uct_ token and user_ref so the agent can
311
- * retrieve them for subsequent calls.
312
- *
313
- * Replace the TODO sections with your own DB / queue / webhook logic.
314
- */
315
- export function generateConsentCallbackSnippet(framework) {
316
- const isNextJs = framework.name === "next-app" ||
317
- framework.name === "next-pages";
318
- if (isNextJs) {
319
- return `// app/api/duct/callback/route.ts
320
- // Receives the redirect from Duct after a user approves an agent consent request.
321
- import { NextRequest, NextResponse } from "next/server";
322
-
323
- export const dynamic = "force-dynamic";
324
-
325
- export async function GET(request: NextRequest) {
326
- const { searchParams } = new URL(request.url);
327
-
328
- const consentCode = searchParams.get("duct_consent_code");
329
- const error = searchParams.get("error");
330
-
331
- if (error) {
332
- return NextResponse.redirect(new URL("/agent-access-denied", request.url));
333
- }
334
-
335
- if (!consentCode) {
336
- return NextResponse.json({ error: "missing_code" }, { status: 400 });
337
- }
338
-
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);
365
- }
366
- `;
367
- }
368
- return `// routes/duct/callback.ts (Express)
369
- // Receives the redirect from Duct after a user approves an agent consent request.
370
- import { Router, Request, Response } from "express";
371
-
372
- const router = Router();
373
-
374
- router.get("/", async (req: Request, res: Response) => {
375
- const { duct_consent_code: consentCode, error } = req.query as Record<string, string>;
376
-
377
- if (error) {
378
- return res.redirect("/agent-access-denied");
379
- }
380
-
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" });
403
- }
404
-
405
- // TODO: store redeemData.user_consent_token + redeemData.user_ref server-side for the agent.
406
-
407
- return res.redirect("/agent-connected");
408
- });
409
-
410
- export default router;
411
- `;
412
- }
413
296
  export function sideEffectActionsApproved(config) {
414
297
  return (config.actions ?? []).some((action) => action.sideEffects);
415
298
  }
@@ -27,13 +27,11 @@ const WEBHOOK_FIELDS = {
27
27
  event_stream: "eventStream",
28
28
  deeplink_callback: "deeplinkCallback",
29
29
  identity_url: "identityUrl",
30
- consent_callback: "consentCallback",
31
30
  };
32
31
  const FIELD_LABEL = {
33
32
  event_stream: "Event stream (signed webhook)",
34
33
  deeplink_callback: "Deep link webhook (signed)",
35
34
  identity_url: "Sign-in page for agent access",
36
- consent_callback: "Page people return to after approving",
37
35
  };
38
36
  // ----------------------------------------------------------------
39
37
  // Helpers
@@ -139,7 +137,6 @@ const statusTool = {
139
137
  event_stream: webhooks.eventStream || null,
140
138
  deeplink_callback: webhooks.deeplinkCallback || null,
141
139
  identity_url: webhooks.identityUrl || null,
142
- consent_callback: webhooks.consentCallback || null,
143
140
  signing_secret: webhooks.secretConfigured,
144
141
  };
145
142
  const next = [];
@@ -147,8 +144,6 @@ const statusTool = {
147
144
  next.push("Generate a signing secret (setup_configure generate_signing_secret: true).");
148
145
  if (!set.identity_url)
149
146
  next.push("Agents acting for signed-in people need identity_url (the product's sign-in page for Duct).");
150
- if (set.identity_url && !set.consent_callback)
151
- next.push("Set consent_callback so people land back in the product after approving.");
152
147
  if (profiles.length === 0)
153
148
  next.push("Create a partner profile if outside agents will use this shell (setup_partner).");
154
149
  next.push("Run setup_check to confirm every URL answers.");
@@ -172,7 +167,6 @@ const configureTool = {
172
167
  event_stream: { type: "string", description: "HTTPS URL that receives signed events. Empty string clears it." },
173
168
  deeplink_callback: { type: "string", description: "HTTPS URL that receives signed deep link events." },
174
169
  identity_url: { type: "string", description: "Product page Duct sends people to so they sign in before approving an agent." },
175
- consent_callback: { type: "string", description: "Product page people return to after approving." },
176
170
  generate_signing_secret: { type: "boolean", description: "Create a new signing secret; it is saved to a git-ignored .env.duct.<shell> file." },
177
171
  confirm: { type: "boolean", description: "true only after the developer approved the preview." },
178
172
  preview_token: { type: "string", description: "The preview_token from the preview the developer approved." },
@@ -235,8 +229,6 @@ const configureTool = {
235
229
  touched.add("deeplinks");
236
230
  if (patch.identityUrl)
237
231
  touched.add("identity");
238
- if (patch.consentCallback)
239
- touched.add("consent");
240
232
  const checks = touched.size ? (await runConnectionChecks(auth, apiKey, shell.id, [...touched])).results : [];
241
233
  const secretNote = secretFile
242
234
  ? `\nSigning secret saved to ${secretFile} as DUCT_WEBHOOK_SECRET (git-ignored). Load it where the product verifies X-Duct-Signature.`
@@ -261,7 +253,7 @@ const checkTool = {
261
253
  shell: SHELL_ARG,
262
254
  targets: {
263
255
  type: "array",
264
- items: { type: "string", enum: ["api", "events", "deeplinks", "identity", "consent"] },
256
+ items: { type: "string", enum: ["api", "events", "deeplinks", "identity"] },
265
257
  description: "Only these. Default: all.",
266
258
  },
267
259
  },
@@ -0,0 +1,9 @@
1
+ import type { PolicyReplayResult } from "./cloud.js";
2
+ /**
3
+ * Plain lines for the push output, and whether the push should stop for confirmation:
4
+ * it stops when real calls that worked before would now be stopped or need approval.
5
+ */
6
+ export declare function formatPolicyReplay(r: PolicyReplayResult, maxRows?: number): {
7
+ lines: string[];
8
+ breaksCalls: boolean;
9
+ };
@@ -0,0 +1,46 @@
1
+ const WORD = {
2
+ allow: "allowed",
3
+ approval: "needs approval",
4
+ deny: "stopped",
5
+ unknown_action: "stopped (action removed)",
6
+ };
7
+ function who(c) {
8
+ if (c.caller === "agent")
9
+ return c.agent ? `agent "${c.agent}"` : "an agent";
10
+ if (c.caller === "guest")
11
+ return "guests";
12
+ return "people in the shell";
13
+ }
14
+ /**
15
+ * Plain lines for the push output, and whether the push should stop for confirmation:
16
+ * it stops when real calls that worked before would now be stopped or need approval.
17
+ */
18
+ export function formatPolicyReplay(r, maxRows = 8) {
19
+ const s = r.summary;
20
+ const lines = [];
21
+ if (r.calls_examined === 0) {
22
+ return { lines: [`No calls in the last ${r.window_days} days to compare against.`], breaksCalls: false };
23
+ }
24
+ if (r.changes.length === 0) {
25
+ lines.push(`All ${r.calls_examined} calls from the last ${r.window_days} days get the same answer under this version.`);
26
+ }
27
+ else {
28
+ const parts = [
29
+ s.newly_denied_calls ? `${s.newly_denied_calls} would be stopped` : "",
30
+ s.newly_need_approval_calls ? `${s.newly_need_approval_calls} would need approval` : "",
31
+ s.newly_allowed_calls ? `${s.newly_allowed_calls} would now be allowed` : "",
32
+ ].filter(Boolean);
33
+ lines.push(`Of ${r.calls_examined} calls in the last ${r.window_days} days: ${parts.join(", ")}.`);
34
+ for (const c of r.changes.slice(0, maxRows)) {
35
+ const consent = c.caller === "agent" && c.with_consent ? " with a person's approval" : "";
36
+ lines.push(` ${c.action} by ${who(c)}${consent}: ${WORD[c.before]} → ${WORD[c.after]} (${c.calls} call${c.calls === 1 ? "" : "s"})`);
37
+ }
38
+ if (r.changes.length > maxRows)
39
+ lines.push(` …and ${r.changes.length - maxRows} more`);
40
+ }
41
+ if (r.parameter_rules_not_replayed.length > 0) {
42
+ lines.push(`Rules that read parameter values were not replayed (values are not stored): ${r.parameter_rules_not_replayed.join(", ")}.`);
43
+ }
44
+ const breaksCalls = r.changes.some((c) => c.before !== "deny" && c.before !== "unknown_action" && (c.after === "deny" || c.after === "unknown_action" || (c.before === "allow" && c.after === "approval")));
45
+ return { lines, breaksCalls };
46
+ }
@@ -8,6 +8,8 @@ export interface OpenApiParseResult {
8
8
  operationCount: number;
9
9
  /** Title from spec info block */
10
10
  title?: string;
11
+ /** Description from spec info block */
12
+ description?: string;
11
13
  }
12
14
  /**
13
15
  * Leading slash + OpenAPI `{param}` → `:param`. The Duct gateway interpolates
@@ -257,6 +257,7 @@ export async function parseOpenApiSpec(content, filePath = "openapi.json") {
257
257
  const spec = raw;
258
258
  const specVersion = spec.openapi ?? spec.swagger ?? "unknown";
259
259
  const title = spec.info?.title;
260
+ const description = typeof spec.info?.description === "string" ? spec.info.description.trim() : undefined;
260
261
  const actions = [];
261
262
  const routes = [];
262
263
  const seen = new Set(); // deduplicate by METHOD:path
@@ -354,5 +355,5 @@ export async function parseOpenApiSpec(content, filePath = "openapi.json") {
354
355
  }
355
356
  }
356
357
  }
357
- return { actions, routes, specVersion, operationCount, title };
358
+ return { actions, routes, specVersion, operationCount, title, ...(description ? { description } : {}) };
358
359
  }