@duct-sdk/sdk 0.1.7 → 0.1.13

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.
Files changed (58) hide show
  1. package/README.md +3 -3
  2. package/dist/adapters/next/index.d.ts +1 -1
  3. package/dist/adapters/next/shell.d.ts +55 -1
  4. package/dist/adapters/next/shell.js +100 -17
  5. package/dist/adapters/react/index.d.ts +5 -1
  6. package/dist/adapters/react/index.js +2 -0
  7. package/dist/adapters/react/shell.d.ts +61 -1
  8. package/dist/adapters/react/shell.js +110 -16
  9. package/dist/adapters/react/use-page-context.d.ts +32 -0
  10. package/dist/adapters/react/use-page-context.js +99 -0
  11. package/dist/cli/agents/api-agent.d.ts +9 -3
  12. package/dist/cli/agents/api-agent.js +163 -69
  13. package/dist/cli/agents/auth-agent.d.ts +2 -1
  14. package/dist/cli/agents/auth-agent.js +38 -24
  15. package/dist/cli/agents/deeplink-agent.js +71 -49
  16. package/dist/cli/agents/llm.d.ts +1 -1
  17. package/dist/cli/agents/llm.js +48 -15
  18. package/dist/cli/agents/pipeline.d.ts +16 -0
  19. package/dist/cli/agents/pipeline.js +18 -5
  20. package/dist/cli/agents/reviewer-agent.js +46 -46
  21. package/dist/cli/agents/route-agent.d.ts +3 -1
  22. package/dist/cli/agents/route-agent.js +70 -44
  23. package/dist/cli/detectors/topology.d.ts +26 -0
  24. package/dist/cli/detectors/topology.js +310 -0
  25. package/dist/cli/drift.d.ts +11 -0
  26. package/dist/cli/drift.js +147 -2
  27. package/dist/cli/fs/sandbox.d.ts +2 -0
  28. package/dist/cli/fs/sandbox.js +22 -8
  29. package/dist/cli/generators/config.d.ts +13 -0
  30. package/dist/cli/generators/config.js +200 -50
  31. package/dist/cli/generators/receiver.js +728 -601
  32. package/dist/cli/generators/shell.js +532 -490
  33. package/dist/cli/index.js +502 -19
  34. package/dist/cli/init.d.ts +11 -1
  35. package/dist/cli/init.js +367 -31
  36. package/dist/cli/processors/postprocess.d.ts +22 -0
  37. package/dist/cli/processors/postprocess.js +107 -0
  38. package/dist/cli/processors/prisma-parser.d.ts +35 -0
  39. package/dist/cli/processors/prisma-parser.js +117 -0
  40. package/dist/cli/processors/zod-extractor.d.ts +27 -0
  41. package/dist/cli/processors/zod-extractor.js +153 -0
  42. package/dist/cli/prompts/review.d.ts +32 -0
  43. package/dist/cli/prompts/review.js +240 -0
  44. package/dist/cli/selectors/index.d.ts +22 -0
  45. package/dist/cli/selectors/index.js +274 -0
  46. package/dist/core/config.d.ts +18 -18
  47. package/dist/core/endpoints.d.ts +1 -0
  48. package/dist/core/endpoints.js +4 -0
  49. package/dist/core/introspect.d.ts +47 -0
  50. package/dist/core/introspect.js +94 -0
  51. package/dist/core/status.d.ts +39 -0
  52. package/dist/core/status.js +40 -0
  53. package/dist/core/token.d.ts +36 -1
  54. package/dist/core/token.js +43 -2
  55. package/dist/core/types.d.ts +114 -0
  56. package/dist/index.d.ts +9 -2
  57. package/dist/index.js +6 -1
  58. package/package.json +84 -84
@@ -66,13 +66,13 @@ function generateRoutes(routes, indentSpaces) {
66
66
  .map((p) => `${pad} { name: ${JSON.stringify(p.name)}, type: ${JSON.stringify(p.type)}, required: ${p.required}${p.description ? `, description: ${JSON.stringify(p.description)}` : ""}${p.defaultValue !== undefined ? `, defaultValue: ${JSON.stringify(p.defaultValue)}` : ""} }`)
67
67
  .join(",\n")}\n${pad} ],`
68
68
  : `\n${pad} queryParams: [],`;
69
- return `${pad} {
70
- ${pad} path: ${JSON.stringify(route.path)},
71
- ${pad} name: ${JSON.stringify(route.name)},
72
- ${pad} description: ${JSON.stringify(route.description)},${params}${queryParams}
73
- ${pad} uiStateHint: ${JSON.stringify(route.uiStateHint)},
74
- ${pad} requiresAuth: ${route.requiresAuth},
75
- ${pad} deeplinkable: ${route.deeplinkable},
69
+ return `${pad} {
70
+ ${pad} path: ${JSON.stringify(route.path)},
71
+ ${pad} name: ${JSON.stringify(route.name)},
72
+ ${pad} description: ${JSON.stringify(route.description)},${params}${queryParams}
73
+ ${pad} uiStateHint: ${JSON.stringify(route.uiStateHint)},
74
+ ${pad} requiresAuth: ${route.requiresAuth},
75
+ ${pad} deeplinkable: ${route.deeplinkable},
76
76
  ${pad} }`;
77
77
  });
78
78
  return `routes: [\n${routeBlocks.join(",\n")},\n${pad}],`;
@@ -88,23 +88,23 @@ function generateActions(actions, indentSpaces) {
88
88
  .map((p) => `${pad} { name: ${JSON.stringify(p.name)}, type: ${JSON.stringify(p.type)}, required: ${p.required}${p.description ? `, description: ${JSON.stringify(p.description)}` : ""} }`)
89
89
  .join(",\n")}\n${pad} ],`
90
90
  : `\n${pad} params: [],`;
91
- return `${pad} {
92
- ${pad} id: ${JSON.stringify(action.id)},
93
- ${pad} name: ${JSON.stringify(action.name)},
94
- ${pad} description: ${JSON.stringify(action.description)},
95
- ${pad} method: ${JSON.stringify(action.method)},
96
- ${pad} path: ${JSON.stringify(action.path)},
97
- ${pad} // Set agentAccessible: true to expose this action to AI agents via the Duct Agent API.
98
- ${pad} // Actions with sideEffects: true require a user consent token regardless.
99
- ${pad} // Default: false for all write operations (safe default).
100
- ${pad} agentAccessible: ${action.agentAccessible},
101
- ${pad} sideEffects: ${action.sideEffects},
102
- ${pad} // sensitivityLevel controls the minimum auth required for agent access.
103
- ${pad} // "low" — any authenticated shell
104
- ${pad} // "medium" — requires user consent token
105
- ${pad} // "high" — requires user consent token + explicit allowedCallers entry
106
- ${pad} sensitivityLevel: ${JSON.stringify(action.sensitivityLevel)},${params}
107
- ${pad} requiresAuth: ${action.requiresAuth},${action.rateLimit !== undefined ? `\n${pad} rateLimit: ${action.rateLimit},` : ""}
91
+ return `${pad} {
92
+ ${pad} id: ${JSON.stringify(action.id)},
93
+ ${pad} name: ${JSON.stringify(action.name)},
94
+ ${pad} description: ${JSON.stringify(action.description)},
95
+ ${pad} method: ${JSON.stringify(action.method)},
96
+ ${pad} path: ${JSON.stringify(action.path)},
97
+ ${pad} // Set agentAccessible: true to expose this action to AI agents via the Duct Agent API.
98
+ ${pad} // Actions with sideEffects: true require a user consent token regardless.
99
+ ${pad} // Default: false for all write operations (safe default).
100
+ ${pad} agentAccessible: ${action.agentAccessible},
101
+ ${pad} sideEffects: ${action.sideEffects},
102
+ ${pad} // sensitivityLevel controls the minimum auth required for agent access.
103
+ ${pad} // "low" — any authenticated shell
104
+ ${pad} // "medium" — requires user consent token
105
+ ${pad} // "high" — requires user consent token + explicit allowedCallers entry
106
+ ${pad} sensitivityLevel: ${JSON.stringify(action.sensitivityLevel)},${params}
107
+ ${pad} requiresAuth: ${action.requiresAuth},${action.rateLimit !== undefined ? `\n${pad} rateLimit: ${action.rateLimit},` : ""}
108
108
  ${pad} }`;
109
109
  });
110
110
  return `actions: [\n${actionBlocks.join(",\n")},\n${pad}],`;
@@ -136,13 +136,13 @@ function generateDeeplinks(deeplinks, indentSpaces) {
136
136
  .map((f) => `${pad} {\n${pad} key: ${JSON.stringify(f.key)},\n${pad} type: ${JSON.stringify(f.type)},\n${pad} required: ${f.required},${f.description ? `\n${pad} description: ${JSON.stringify(f.description)},` : ""}${f.sessionSource ? `\n${pad} sessionSource: ${JSON.stringify(f.sessionSource)},` : ""}\n${pad} }`)
137
137
  .join(",\n")}\n${pad} ],`
138
138
  : `\n${pad} stateFields: [],`;
139
- return `${pad} {
140
- ${pad} id: ${JSON.stringify(dl.id)},
141
- ${pad} name: ${JSON.stringify(dl.name)},
142
- ${pad} description: ${JSON.stringify(dl.description)},
143
- ${pad} targetRoute: ${JSON.stringify(dl.targetRoute)},${stateFields}
144
- ${pad} expirySeconds: ${dl.expirySeconds},
145
- ${pad} requiresAuth: ${dl.requiresAuth},${dl.intent ? `\n${pad} intent: ${JSON.stringify(dl.intent)},` : ""}
139
+ return `${pad} {
140
+ ${pad} id: ${JSON.stringify(dl.id)},
141
+ ${pad} name: ${JSON.stringify(dl.name)},
142
+ ${pad} description: ${JSON.stringify(dl.description)},
143
+ ${pad} targetRoute: ${JSON.stringify(dl.targetRoute)},${stateFields}
144
+ ${pad} expirySeconds: ${dl.expirySeconds},
145
+ ${pad} requiresAuth: ${dl.requiresAuth},${dl.intent ? `\n${pad} intent: ${JSON.stringify(dl.intent)},` : ""}
146
146
  ${pad} }`;
147
147
  });
148
148
  return `deeplinks: [\n${deeplinkBlocks.join(",\n")},\n${pad}],`;
@@ -182,6 +182,151 @@ function generateWidget(widget, indentSpaces) {
182
182
  return `widget: {\n${lines.join("\n")}\n${pad}},`;
183
183
  }
184
184
  // ----------------------------------------------------------------
185
+ // generateManualTemplate
186
+ // ----------------------------------------------------------------
187
+ /**
188
+ * Generate a heavily-commented `duct.config.ts` template for manual mode.
189
+ * Framework and auth are pre-filled from topology; routes/actions/deeplinks
190
+ * contain commented-out example entries so the developer can fill them in.
191
+ */
192
+ export function generateManualTemplate(opts) {
193
+ const { shellId, productName, baseUrl, authStrategy, framework, logoUrl } = opts;
194
+ const tokenEndpoint = framework === "next-app" || framework === "next-pages"
195
+ ? "/api/duct/token"
196
+ : framework === "remix"
197
+ ? "/api.duct.token"
198
+ : framework === "sveltekit"
199
+ ? "/api/duct/token"
200
+ : "/api/duct/token";
201
+ const logoLine = logoUrl ? `\n // logoUrl: ${JSON.stringify(logoUrl)},` : "";
202
+ return `/**
203
+ * Duct Shell Configuration — ${shellId}
204
+ *
205
+ * Generated in manual mode — no AI agents were used.
206
+ * Fill in the routes, actions, and deeplinks sections below, then run:
207
+ *
208
+ * npx duct push
209
+ *
210
+ * to sync this manifest with Duct cloud.
211
+ *
212
+ * Docs: https://docs.duct.sh/config
213
+ */
214
+
215
+ import { defineDuctConfig } from "@duct-sdk/sdk";
216
+
217
+ export default defineDuctConfig({
218
+ // Your Duct shell ID (assigned by Duct cloud — do not change)
219
+ shellId: ${JSON.stringify(shellId)},
220
+
221
+ // Product metadata
222
+ product: {
223
+ name: ${JSON.stringify(productName)},
224
+ description: ${JSON.stringify(`${productName} — AI-powered interaction shell`)},
225
+ baseUrl: ${JSON.stringify(baseUrl)},${logoLine}
226
+ },
227
+
228
+ // Authentication — detected: ${authStrategy}
229
+ // strategy: how Duct requests a short-lived token from your app
230
+ auth: {
231
+ strategy: ${JSON.stringify(authStrategy)},
232
+ // Fields from your session object that Duct may reference when building context
233
+ sessionFields: ["userId", "email"],
234
+ guestAllowed: false,
235
+ // How long (seconds) a Duct-issued execution token is valid
236
+ tokenExpirySeconds: 300,
237
+ // Route on your server that mints Duct execution tokens
238
+ tokenEndpoint: ${JSON.stringify(tokenEndpoint)},
239
+ },
240
+
241
+ // ── Routes ───────────────────────────────────────────────────
242
+ // Declare every navigable route in your app.
243
+ // Duct uses these for deeplink handoffs — when the shell needs to navigate
244
+ // the user to a specific page with pre-loaded state.
245
+ //
246
+ // Example:
247
+ // {
248
+ // path: "/orders/:orderId",
249
+ // name: "Order Detail",
250
+ // description: "Shows a single order with timeline, items, and actions",
251
+ // params: [{ name: "orderId", type: "string", required: true }],
252
+ // queryParams: [],
253
+ // uiStateHint: "entity",
254
+ // requiresAuth: true,
255
+ // deeplinkable: true,
256
+ // },
257
+ routes: [
258
+ // Add your routes here
259
+ ],
260
+
261
+ // ── Actions ──────────────────────────────────────────────────
262
+ // Declare API actions Duct can optionally invoke on a user's behalf.
263
+ // Only set agentAccessible: true for actions that are safe for AI agents.
264
+ // Actions with sideEffects: true always require a user consent token.
265
+ //
266
+ // Example:
267
+ // {
268
+ // id: "get_order",
269
+ // name: "Get Order",
270
+ // description: "Fetches a single order by ID",
271
+ // method: "GET",
272
+ // path: "/api/orders/:orderId",
273
+ // agentAccessible: true,
274
+ // sideEffects: false,
275
+ // sensitivityLevel: "low",
276
+ // params: [{ name: "orderId", type: "string", required: true, description: "Order ID" }],
277
+ // requiresAuth: true,
278
+ // },
279
+ // {
280
+ // id: "cancel_order",
281
+ // name: "Cancel Order",
282
+ // description: "Cancels an order — irreversible",
283
+ // method: "POST",
284
+ // path: "/api/orders/:orderId/cancel",
285
+ // agentAccessible: false, // set to true only after review
286
+ // sideEffects: true,
287
+ // sensitivityLevel: "high",
288
+ // params: [{ name: "orderId", type: "string", required: true }],
289
+ // requiresAuth: true,
290
+ // },
291
+ actions: [
292
+ // Add your actions here
293
+ ],
294
+
295
+ // ── Deeplinks ────────────────────────────────────────────────
296
+ // Deeplinks are signed URLs Duct issues to navigate your frontend.
297
+ // Your receiver route (app/api/duct/receive/route.ts) validates the JWT
298
+ // and applies the state before navigating the user.
299
+ //
300
+ // Example:
301
+ // {
302
+ // id: "view_order",
303
+ // name: "View Order",
304
+ // description: "Navigate to order detail page with order pre-loaded",
305
+ // targetRoute: "/orders/:orderId",
306
+ // stateFields: [
307
+ // { key: "orderId", type: "string", required: true, description: "Order ID to display" },
308
+ // ],
309
+ // expirySeconds: 300,
310
+ // requiresAuth: true,
311
+ // },
312
+ deeplinks: [
313
+ // Add your deeplinks here
314
+ ],
315
+
316
+ // Agent permission defaults — restrict what external AI shells can do
317
+ agentPermissions: {
318
+ defaultLevel: "none",
319
+ requireUserConsent: true,
320
+ },
321
+
322
+ // Shell widget appearance
323
+ widget: {
324
+ position: "bottom-right",
325
+ },
326
+ });
327
+ `;
328
+ }
329
+ // ----------------------------------------------------------------
185
330
  // generateConfigFile
186
331
  // ----------------------------------------------------------------
187
332
  /**
@@ -232,24 +377,29 @@ export function generateConfigFile(config) {
232
377
  if (config.widget) {
233
378
  sections.push("", `${i}// Shell widget display configuration`, `${i}${generateWidget(config.widget, 2)}`);
234
379
  }
235
- const docsBase = config.product?.baseUrl
236
- ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
237
- : 'https://docs.duct.sh';
238
- return `/**
239
- * Duct Shell Configuration — ${config.shellId}
240
- *
241
- * This file is the manifest Duct uses to understand your product.
242
- * It defines what routes exist, what actions agents can invoke,
243
- * and what deeplinks the shell can hand off to.
244
- *
245
- * Edit freely. Run \`npx duct init --update\` to regenerate from source.
246
- * Docs: ${docsBase}/config
247
- */
248
-
249
- import { defineDuctConfig } from "@shoryasethia/duct-sdk";
250
-
251
- export default defineDuctConfig({
252
- ${sections.join("\n")}
253
- });
380
+ let docsBase = 'https://docs.duct.sh';
381
+ if (config.product?.baseUrl) {
382
+ try {
383
+ const hostname = new URL(config.product.baseUrl).hostname;
384
+ docsBase = `https://docs.${hostname.split('.').slice(-2).join('.')}`;
385
+ }
386
+ catch { /* invalid URL — use default */ }
387
+ }
388
+ return `/**
389
+ * Duct Shell Configuration — ${config.shellId}
390
+ *
391
+ * This file is the manifest Duct uses to understand your product.
392
+ * It defines what routes exist, what actions agents can invoke,
393
+ * and what deeplinks the shell can hand off to.
394
+ *
395
+ * Edit freely. Run \`npx duct init --update\` to regenerate from source.
396
+ * Docs: ${docsBase}/config
397
+ */
398
+
399
+ import { defineDuctConfig } from "@duct-sdk/sdk";
400
+
401
+ export default defineDuctConfig({
402
+ ${sections.join("\n")}
403
+ });
254
404
  `;
255
405
  }