@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
@@ -51,10 +51,45 @@ export interface VerifyTokenResult {
51
51
  * Returns the decoded payload if valid, or an error message if not.
52
52
  */
53
53
  export declare function verifyDuctToken(token: string, options: VerifyTokenOptions): Promise<VerifyTokenResult>;
54
+ export interface GenerateDeeplinkTokenOptions {
55
+ /** HMAC-SHA256 secret key */
56
+ secretKey: string;
57
+ /** Shell ID (issuer + audience) */
58
+ shellId: string;
59
+ /** Deeplink ID from manifest */
60
+ deeplinkId: string;
61
+ /** State to embed in the token (will be used to pre-fill the target page) */
62
+ state?: Record<string, unknown>;
63
+ /** Token expiry in seconds (default: 300 — 5 minutes) */
64
+ expirySeconds?: number;
65
+ /** Optional user subject */
66
+ sub?: string;
67
+ }
68
+ export interface GenerateDeeplinkTokenResult {
69
+ token: string;
70
+ expiresAt: Date;
71
+ }
72
+ /**
73
+ * Generate a signed deeplink JWT.
74
+ * Set as the `token` query param on the deeplink URL so the receiver can verify it.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * const { token } = await generateDeeplinkToken({
79
+ * secretKey: process.env.DUCT_SECRET_KEY!,
80
+ * shellId: 'shell_acme_prod',
81
+ * deeplinkId: 'view_order',
82
+ * state: { orderId: '1042' },
83
+ * expirySeconds: 300,
84
+ * });
85
+ * const url = `${baseUrl}/duct/receive?token=${encodeURIComponent(token)}`;
86
+ * ```
87
+ */
88
+ export declare function generateDeeplinkToken(options: GenerateDeeplinkTokenOptions): Promise<GenerateDeeplinkTokenResult>;
54
89
  export interface VerifyDeeplinkTokenOptions {
55
90
  /** HMAC-SHA256 secret key */
56
91
  secretKey: string;
57
- /** Expected issuer (shell ID) */
92
+ /** Expected issuer (shell ID) — also enforced as audience */
58
93
  expectedShellId?: string;
59
94
  /** Expected deeplink ID */
60
95
  expectedDeeplinkId?: string;
@@ -129,16 +129,57 @@ export async function verifyDuctToken(token, options) {
129
129
  };
130
130
  }
131
131
  }
132
+ /**
133
+ * Generate a signed deeplink JWT.
134
+ * Set as the `token` query param on the deeplink URL so the receiver can verify it.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const { token } = await generateDeeplinkToken({
139
+ * secretKey: process.env.DUCT_SECRET_KEY!,
140
+ * shellId: 'shell_acme_prod',
141
+ * deeplinkId: 'view_order',
142
+ * state: { orderId: '1042' },
143
+ * expirySeconds: 300,
144
+ * });
145
+ * const url = `${baseUrl}/duct/receive?token=${encodeURIComponent(token)}`;
146
+ * ```
147
+ */
148
+ export async function generateDeeplinkToken(options) {
149
+ const { secretKey, shellId, deeplinkId, state = {}, expirySeconds = 300, sub } = options;
150
+ if (!secretKey || secretKey.length < 16) {
151
+ throw new Error("DUCT_SECRET_KEY must be at least 16 characters.");
152
+ }
153
+ const now = Math.floor(Date.now() / 1000);
154
+ const exp = now + expirySeconds;
155
+ const jti = crypto.randomUUID();
156
+ let builder = new SignJWT({ deeplink_id: deeplinkId, state })
157
+ .setProtectedHeader({ alg: "HS256" })
158
+ .setIssuer(shellId)
159
+ .setAudience(shellId) // aud scoped to this shellId — prevents cross-shell replay
160
+ .setIssuedAt(now)
161
+ .setExpirationTime(exp)
162
+ .setJti(jti); // jti for replay protection
163
+ if (sub) {
164
+ builder = builder.setSubject(sub);
165
+ }
166
+ const token = await builder.sign(encodeSecret(secretKey));
167
+ return { token, expiresAt: new Date(exp * 1000) };
168
+ }
132
169
  /**
133
170
  * Verify a Duct deeplink token (received at the receiver endpoint).
134
171
  */
135
172
  export async function verifyDeeplinkToken(token, options) {
136
173
  const { secretKey, expectedShellId, expectedDeeplinkId } = options;
137
174
  try {
138
- const { payload } = await jwtVerify(token, encodeSecret(secretKey), {
175
+ // Only enforce audience if expectedShellId is provided.
176
+ // Tokens generated before aud was added will still verify without it.
177
+ const verifyOptions = {
139
178
  algorithms: ["HS256"],
140
179
  issuer: expectedShellId,
141
- });
180
+ ...(expectedShellId ? { audience: expectedShellId } : {}),
181
+ };
182
+ const { payload } = await jwtVerify(token, encodeSecret(secretKey), verifyOptions);
142
183
  const typedPayload = payload;
143
184
  if (!typedPayload.deeplink_id) {
144
185
  return {
@@ -32,6 +32,19 @@ export interface RouteManifest {
32
32
  methods?: string[];
33
33
  /** ISO 8601 timestamp of last update (set by duct push) */
34
34
  updatedAt?: string;
35
+ /** Agent detection confidence (0.0–1.0). */
36
+ confidence?: number;
37
+ /** Evidence for this detection: "file:line" format. */
38
+ evidence?: string;
39
+ /**
40
+ * Maps URL query params to an action for structured data access.
41
+ * Used by the shell to call a search action instead of scraping HTML.
42
+ * [NOT YET IMPLEMENTED in shell runtime]
43
+ */
44
+ searchAction?: {
45
+ actionId: string;
46
+ paramMap: Record<string, string>;
47
+ };
35
48
  }
36
49
  export type SensitivityLevel = "none" | "low" | "medium" | "high" | "critical";
37
50
  export interface ActionParam {
@@ -75,6 +88,28 @@ export interface ActionManifest {
75
88
  interruptBehavior?: "cancel" | "block";
76
89
  /** ISO 8601 timestamp of last update (set by duct push) */
77
90
  updatedAt?: string;
91
+ /** Agent detection confidence (0.0–1.0). */
92
+ confidence?: number;
93
+ /** Evidence for this detection: "file:line" format. */
94
+ evidence?: string;
95
+ /**
96
+ * Declares that this action depends on results from other actions.
97
+ * Forms a DAG; shell runtime traverses it via topological sort.
98
+ * [NOT YET IMPLEMENTED in shell runtime]
99
+ */
100
+ dependsOn?: Array<{
101
+ actionId: string;
102
+ /** Maps a key from the dependency's result to this action's param name */
103
+ paramMapping: Record<string, string>;
104
+ }>;
105
+ /** Semantic output type — drives generative UI component selection without a router round-trip. */
106
+ semanticType?: "list" | "entity" | "status" | "comparison" | "timeline" | "search_results";
107
+ /** Output schema (JSON Schema) for auto-rendering. */
108
+ outputSchema?: Record<string, unknown>;
109
+ /** Explicit entity→param mappings for reliable param auto-fill. */
110
+ paramMappings?: Record<string, string>;
111
+ /** Deeplink id to navigate to when the action result is a large list. */
112
+ navigatesTo?: string;
78
113
  }
79
114
  export type AuthStrategy = "nextauth" | "clerk" | "auth0" | "custom-jwt" | "session-cookie" | "none" | "unknown";
80
115
  export interface AuthSchema {
@@ -176,6 +211,14 @@ export interface WidgetConfig {
176
211
  height?: number | string;
177
212
  /** URL to your product logo (shown in empty state) */
178
213
  logoUrl?: string;
214
+ /**
215
+ * Number of conversation turns after which context is compacted into a summary.
216
+ * Lower = cheaper (less history sent to LLM). Default: 8.
217
+ * Set to 0 to disable compaction entirely.
218
+ */
219
+ compactionTurns?: number;
220
+ /** Theme override — 'light' | 'dark' | 'system' */
221
+ theme?: 'light' | 'dark' | 'system';
179
222
  }
180
223
  export interface ProductConfig {
181
224
  /** Company or product name */
@@ -191,6 +234,71 @@ export interface ProductConfig {
191
234
  /** Industry/category for the product */
192
235
  industry?: string;
193
236
  }
237
+ /**
238
+ * Structured data describing what the user is currently viewing on the page.
239
+ * Returned by `useDuctPageContext` or `DuctShell.onPageContext` when the shell
240
+ * sends a `DUCT_REQUEST_CONTEXT` postMessage.
241
+ *
242
+ * The shell uses this to answer deictic references ("this", "that order",
243
+ * "the error on screen") without screenshots or computer-use techniques.
244
+ */
245
+ export interface DuctPageContext {
246
+ /** Current client-side route path */
247
+ route?: string;
248
+ /**
249
+ * The primary entity visible on screen.
250
+ * Only `type` is required — use whatever key names your data model has.
251
+ * The shell forwards all fields to the router; the LLM reasons over them.
252
+ * e.g. { type: "ticket", ticketId: "T-42", priority: "high", state: "open" }
253
+ * e.g. { type: "product", sku: "ABC-123", title: "Widget", stock: 4 }
254
+ */
255
+ entity?: {
256
+ /** What kind of entity this is — used by the router to understand context */
257
+ type: string;
258
+ /** Any additional fields that describe the entity — use your own key names */
259
+ [key: string]: unknown;
260
+ };
261
+ /** Active error state shown to the user */
262
+ errorState?: {
263
+ code?: string;
264
+ message?: string;
265
+ field?: string;
266
+ };
267
+ /**
268
+ * Items the user has currently selected (e.g. checked rows in a table).
269
+ * Only `type` is required — use whatever key your data model uses for identifiers.
270
+ * e.g. { type: "file", fileIds: ["f1", "f2"] }
271
+ * e.g. { type: "record", refs: ["R-01", "R-02"] }
272
+ */
273
+ selection?: {
274
+ /** What kind of items are selected */
275
+ type: string;
276
+ /** Any additional fields — use your own key names for identifiers */
277
+ [key: string]: unknown;
278
+ };
279
+ /** Partial form values visible on screen */
280
+ formState?: Record<string, unknown>;
281
+ /** Any additional structured data useful for the shell's decision */
282
+ meta?: Record<string, unknown>;
283
+ }
284
+ export interface DataModelEntity {
285
+ /** Must match key returned by /duct/introspect */
286
+ id: string;
287
+ label: string;
288
+ /** Action that lists available entities (discoveryAction) */
289
+ discoveryAction: string;
290
+ /** Action that fetches a single entity by indexKey */
291
+ fetchAction: string;
292
+ /** Primary key field in discovery result items */
293
+ indexKey: string;
294
+ /** Human-readable label field in discovery result items */
295
+ labelKey: string;
296
+ /** Facet fields shell can filter/group by */
297
+ dimensions?: string[];
298
+ }
299
+ export interface DataModel {
300
+ entities: DataModelEntity[];
301
+ }
194
302
  export interface DuctConfig {
195
303
  /** Shell ID assigned by Duct cloud */
196
304
  shellId: string;
@@ -208,6 +316,12 @@ export interface DuctConfig {
208
316
  agentPermissions: AgentPermissions;
209
317
  /** Shell widget display config */
210
318
  widget?: WidgetConfig;
319
+ /**
320
+ * Backend data entity declarations for Backend Intelligence.
321
+ * Links entity types to their discovery/fetch actions.
322
+ * [NOT YET IMPLEMENTED in shell runtime — see BACKEND_INTELLIGENCE.md]
323
+ */
324
+ dataModel?: DataModel;
211
325
  }
212
326
  export interface ShellManifest {
213
327
  shellId: string;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
2
2
  export type { ValidatedDuctConfig } from "./core/config.js";
3
- export { generateDuctToken, verifyDuctToken, verifyDeeplinkToken, } from "./core/token.js";
4
- export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, } from "./core/token.js";
3
+ export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, } from "./core/token.js";
4
+ export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, } from "./core/token.js";
5
5
  export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
6
6
  export type { ActionSearchEntry } from "./core/action.js";
7
+ export { checkShellStatus } from "./core/status.js";
8
+ export type { ShellStatus, ShellStatusWidget, CheckShellStatusOptions } from "./core/status.js";
9
+ export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
10
+ export type { IntrospectEntity, IntrospectResult, IntrospectContext, IntrospectResolver, IntrospectHandlerOptions, } from "./core/introspect.js";
11
+ export type { DuctPageContext } from "./core/types.js";
12
+ export { useDuctPageContext } from "./adapters/react/use-page-context.js";
13
+ export type { UseDuctPageContextOptions } from "./adapters/react/use-page-context.js";
7
14
  export type { RouteManifest, RouteParam, QueryParam, UIStateHint, ActionManifest, ActionParam, SensitivityLevel, ActionRuntimeFields, ActionDef, BuiltActionDef, ActionValidationResult, AuthSchema, AuthStrategy, DeeplinkDefinition, StateField, ReviewResult, ReviewIssue, ReviewIssueSeverity, DuctConfig, ProductConfig, AgentPermissions, AgentPermissionLevel, WidgetConfig, ShellManifest, ModalityDecision, ScoredModalityDecision, ShellSessionPhase, ShellSessionState, ShellSessionType, ShellCallChain, ActionPermissionContext, ActionPermissionResult, PermissionDecision, PermissionRuleSource, SessionContext, Message, DuctTokenPayload, DeeplinkTokenPayload, DuctAdapter, ReceiverOptions, ShellOptions, } from "./core/types.js";
package/dist/index.js CHANGED
@@ -4,6 +4,11 @@
4
4
  // Core config
5
5
  export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
6
6
  // Token utilities
7
- export { generateDuctToken, verifyDuctToken, verifyDeeplinkToken, } from "./core/token.js";
7
+ export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, } from "./core/token.js";
8
8
  // Action factory
9
9
  export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
10
+ // Shell status (server-side)
11
+ export { checkShellStatus } from "./core/status.js";
12
+ // Introspect handler factory (/duct/introspect)
13
+ export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
14
+ export { useDuctPageContext } from "./adapters/react/use-page-context.js";
package/package.json CHANGED
@@ -1,84 +1,84 @@
1
- {
2
- "name": "@duct-sdk/sdk",
3
- "version": "0.1.7",
4
- "type": "module",
5
- "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "bin": {
9
- "duct": "dist/cli/index.js"
10
- },
11
- "exports": {
12
- ".": "./dist/index.js",
13
- "./next": "./dist/adapters/next/index.js",
14
- "./remix": "./dist/adapters/remix/index.js",
15
- "./vite": "./dist/adapters/vite/index.js",
16
- "./sveltekit": "./dist/adapters/sveltekit/index.js",
17
- "./react": "./dist/adapters/react/index.js"
18
- },
19
- "scripts": {
20
- "build": "tsc",
21
- "dev": "tsc --watch"
22
- },
23
- "dependencies": {
24
- "@anthropic-ai/sdk": "^0.24.0",
25
- "jose": "^5.0.0",
26
- "ignore": "^5.0.0",
27
- "commander": "^12.0.0",
28
- "chalk": "^5.0.0",
29
- "ora": "^8.0.0",
30
- "inquirer": "^9.0.0",
31
- "zod": "^3.0.0",
32
- "node-fetch": "^3.0.0",
33
- "glob": "^10.0.0"
34
- },
35
- "devDependencies": {
36
- "typescript": "^5.0.0",
37
- "@types/node": "^20.0.0",
38
- "@types/inquirer": "^9.0.0",
39
- "@types/react": "^18.0.0",
40
- "next": "^14.0.0",
41
- "react": "^18.0.0",
42
- "react-dom": "^18.0.0"
43
- },
44
- "peerDependencies": {
45
- "react": "^18.0.0 || ^19.0.0",
46
- "react-dom": "^18.0.0 || ^19.0.0",
47
- "next": ">=14.0.0"
48
- },
49
- "peerDependenciesMeta": {
50
- "react": {
51
- "optional": true
52
- },
53
- "react-dom": {
54
- "optional": true
55
- },
56
- "next": {
57
- "optional": true
58
- }
59
- },
60
- "files": [
61
- "dist",
62
- "README.md"
63
- ],
64
- "keywords": [
65
- "duct",
66
- "ai",
67
- "agent",
68
- "shell",
69
- "cli",
70
- "llm",
71
- "ai-agent",
72
- "deeplink",
73
- "next",
74
- "nextjs",
75
- "remix",
76
- "vite",
77
- "sveltekit",
78
- "sdk"
79
- ],
80
- "publishConfig": {
81
- "registry": "https://registry.npmjs.org",
82
- "access": "public"
83
- }
84
- }
1
+ {
2
+ "name": "@duct-sdk/sdk",
3
+ "version": "0.1.13",
4
+ "type": "module",
5
+ "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "duct": "dist/cli/index.js"
10
+ },
11
+ "exports": {
12
+ ".": "./dist/index.js",
13
+ "./next": "./dist/adapters/next/index.js",
14
+ "./remix": "./dist/adapters/remix/index.js",
15
+ "./vite": "./dist/adapters/vite/index.js",
16
+ "./sveltekit": "./dist/adapters/sveltekit/index.js",
17
+ "./react": "./dist/adapters/react/index.js"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "tsc --watch"
22
+ },
23
+ "dependencies": {
24
+ "@anthropic-ai/sdk": "^0.24.0",
25
+ "jose": "^5.0.0",
26
+ "ignore": "^5.0.0",
27
+ "commander": "^12.0.0",
28
+ "chalk": "^5.0.0",
29
+ "ora": "^8.0.0",
30
+ "inquirer": "^9.0.0",
31
+ "zod": "^3.0.0",
32
+ "node-fetch": "^3.0.0",
33
+ "glob": "^10.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "^5.0.0",
37
+ "@types/node": "^20.0.0",
38
+ "@types/inquirer": "^9.0.0",
39
+ "@types/react": "^18.0.0",
40
+ "next": "^14.0.0",
41
+ "react": "^18.0.0",
42
+ "react-dom": "^18.0.0"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^18.0.0 || ^19.0.0",
46
+ "react-dom": "^18.0.0 || ^19.0.0",
47
+ "next": ">=14.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "react": {
51
+ "optional": true
52
+ },
53
+ "react-dom": {
54
+ "optional": true
55
+ },
56
+ "next": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "files": [
61
+ "dist",
62
+ "README.md"
63
+ ],
64
+ "keywords": [
65
+ "duct",
66
+ "ai",
67
+ "agent",
68
+ "shell",
69
+ "cli",
70
+ "llm",
71
+ "ai-agent",
72
+ "deeplink",
73
+ "next",
74
+ "nextjs",
75
+ "remix",
76
+ "vite",
77
+ "sveltekit",
78
+ "sdk"
79
+ ],
80
+ "publishConfig": {
81
+ "registry": "https://registry.npmjs.org",
82
+ "access": "public"
83
+ }
84
+ }