@duct-sdk/sdk 0.5.12 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +385 -336
  2. package/README.md +418 -264
  3. package/TOKEN_SPEC.md +243 -237
  4. package/dist/cli/add.d.ts +7 -0
  5. package/dist/cli/add.js +152 -0
  6. package/dist/cli/agent-prompt.d.ts +3 -0
  7. package/dist/cli/agent-prompt.js +39 -0
  8. package/dist/cli/api-sources.d.ts +26 -0
  9. package/dist/cli/api-sources.js +222 -0
  10. package/dist/cli/cloud.d.ts +133 -0
  11. package/dist/cli/cloud.js +298 -0
  12. package/dist/cli/config-loader.d.ts +14 -0
  13. package/dist/cli/config-loader.js +56 -7
  14. package/dist/cli/device-login.d.ts +17 -0
  15. package/dist/cli/device-login.js +75 -0
  16. package/dist/cli/drift.js +6 -6
  17. package/dist/cli/generators/any-stack.d.ts +3 -0
  18. package/dist/cli/generators/any-stack.js +97 -0
  19. package/dist/cli/generators/config.js +3 -2
  20. package/dist/cli/generators/receiver.js +7 -7
  21. package/dist/cli/generators/shell.js +12 -12
  22. package/dist/cli/generators/token-route.js +245 -245
  23. package/dist/cli/index.js +402 -611
  24. package/dist/cli/mcp-core.d.ts +42 -0
  25. package/dist/cli/mcp-core.js +161 -0
  26. package/dist/cli/mcp-setup.d.ts +4 -0
  27. package/dist/cli/mcp-setup.js +360 -0
  28. package/dist/cli/mcp.d.ts +2 -0
  29. package/dist/cli/mcp.js +457 -0
  30. package/dist/cli/migrate-intershell.js +5 -5
  31. package/dist/cli/policy-defaults.d.ts +37 -0
  32. package/dist/cli/policy-defaults.js +127 -0
  33. package/dist/cli/processors/integration-audit.js +2 -2
  34. package/dist/cli/processors/openapi-parser.d.ts +5 -0
  35. package/dist/cli/processors/openapi-parser.js +8 -3
  36. package/dist/cli/project-loader.d.ts +58 -0
  37. package/dist/cli/project-loader.js +198 -0
  38. package/dist/cli/project-writer.d.ts +23 -0
  39. package/dist/cli/project-writer.js +171 -0
  40. package/dist/cli/push.d.ts +43 -0
  41. package/dist/cli/push.js +276 -0
  42. package/dist/cli/safety-checks.d.ts +9 -0
  43. package/dist/cli/safety-checks.js +29 -0
  44. package/dist/cli/setup.d.ts +20 -0
  45. package/dist/cli/setup.js +349 -0
  46. package/dist/cli/shell-name.d.ts +8 -0
  47. package/dist/cli/shell-name.js +29 -0
  48. package/dist/cli/shells.d.ts +22 -0
  49. package/dist/cli/shells.js +122 -0
  50. package/dist/cli/split.d.ts +7 -0
  51. package/dist/cli/split.js +71 -0
  52. package/dist/cli/sync.d.ts +25 -0
  53. package/dist/cli/sync.js +120 -0
  54. package/dist/cli/test-runner.d.ts +21 -0
  55. package/dist/cli/test-runner.js +281 -0
  56. package/dist/core/compile.d.ts +43 -0
  57. package/dist/core/compile.js +510 -0
  58. package/dist/core/config.d.ts +533 -1
  59. package/dist/core/config.js +32 -12
  60. package/dist/core/hosted-upstream-check.d.ts +3 -0
  61. package/dist/core/hosted-upstream-check.js +35 -0
  62. package/dist/core/login-handoff.d.ts +1 -1
  63. package/dist/core/login-handoff.js +1 -1
  64. package/dist/core/project.d.ts +1798 -0
  65. package/dist/core/project.js +278 -0
  66. package/dist/core/readiness-checks.js +2 -2
  67. package/dist/core/types.d.ts +26 -1
  68. package/dist/index.d.ts +6 -0
  69. package/dist/index.js +16 -0
  70. package/dist/project.d.ts +4 -0
  71. package/dist/project.js +8 -0
  72. package/dist/server.d.ts +2 -0
  73. package/dist/server.js +1 -0
  74. package/fixtures/token-conformance-vectors.json +26 -0
  75. package/package.json +94 -94
  76. package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
  77. package/dist/adapters/react/page-context-guard.test.js +0 -15
  78. package/dist/cli/agents/api-agent.d.ts +0 -22
  79. package/dist/cli/agents/api-agent.js +0 -761
  80. package/dist/cli/agents/auth-agent.d.ts +0 -7
  81. package/dist/cli/agents/auth-agent.js +0 -212
  82. package/dist/cli/agents/deeplink-agent.d.ts +0 -6
  83. package/dist/cli/agents/deeplink-agent.js +0 -285
  84. package/dist/cli/agents/llm.d.ts +0 -33
  85. package/dist/cli/agents/llm.js +0 -309
  86. package/dist/cli/agents/pipeline.d.ts +0 -72
  87. package/dist/cli/agents/pipeline.js +0 -421
  88. package/dist/cli/agents/reviewer-agent.d.ts +0 -13
  89. package/dist/cli/agents/reviewer-agent.js +0 -450
  90. package/dist/cli/agents/route-agent.d.ts +0 -17
  91. package/dist/cli/agents/route-agent.js +0 -383
  92. package/dist/cli/config-loader.test.d.ts +0 -1
  93. package/dist/cli/config-loader.test.js +0 -63
  94. package/dist/cli/detectors/topology.d.ts +0 -46
  95. package/dist/cli/detectors/topology.js +0 -417
  96. package/dist/cli/generators/config.test.d.ts +0 -1
  97. package/dist/cli/generators/config.test.js +0 -222
  98. package/dist/cli/generators/shell.test.d.ts +0 -1
  99. package/dist/cli/generators/shell.test.js +0 -73
  100. package/dist/cli/generators/token-route.test.d.ts +0 -1
  101. package/dist/cli/generators/token-route.test.js +0 -53
  102. package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
  103. package/dist/cli/generators/wiring-snippets.test.js +0 -80
  104. package/dist/cli/init.d.ts +0 -32
  105. package/dist/cli/init.js +0 -1336
  106. package/dist/cli/manifest-diff.test.d.ts +0 -1
  107. package/dist/cli/manifest-diff.test.js +0 -144
  108. package/dist/cli/processors/curl-parser.test.d.ts +0 -1
  109. package/dist/cli/processors/curl-parser.test.js +0 -24
  110. package/dist/cli/processors/integration-audit.test.d.ts +0 -1
  111. package/dist/cli/processors/integration-audit.test.js +0 -154
  112. package/dist/cli/processors/postprocess.d.ts +0 -22
  113. package/dist/cli/processors/postprocess.js +0 -107
  114. package/dist/cli/processors/prisma-parser.d.ts +0 -35
  115. package/dist/cli/processors/prisma-parser.js +0 -117
  116. package/dist/cli/processors/verify-discovery.d.ts +0 -33
  117. package/dist/cli/processors/verify-discovery.js +0 -193
  118. package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
  119. package/dist/cli/processors/verify-discovery.test.js +0 -153
  120. package/dist/cli/processors/zod-extractor.d.ts +0 -27
  121. package/dist/cli/processors/zod-extractor.js +0 -153
  122. package/dist/cli/prompts/review.d.ts +0 -61
  123. package/dist/cli/prompts/review.js +0 -410
  124. package/dist/cli/selectors/express.d.ts +0 -12
  125. package/dist/cli/selectors/express.js +0 -117
  126. package/dist/cli/selectors/fastapi.d.ts +0 -12
  127. package/dist/cli/selectors/fastapi.js +0 -122
  128. package/dist/cli/selectors/generic.d.ts +0 -10
  129. package/dist/cli/selectors/generic.js +0 -74
  130. package/dist/cli/selectors/index.d.ts +0 -37
  131. package/dist/cli/selectors/index.js +0 -315
  132. package/dist/cli/selectors/next.d.ts +0 -12
  133. package/dist/cli/selectors/next.js +0 -130
  134. package/dist/core/config-policy.test.d.ts +0 -1
  135. package/dist/core/config-policy.test.js +0 -101
  136. package/dist/core/config-roundtrip.test.d.ts +0 -1
  137. package/dist/core/config-roundtrip.test.js +0 -180
  138. package/dist/core/endpoint-guard.test.d.ts +0 -1
  139. package/dist/core/endpoint-guard.test.js +0 -57
  140. package/dist/core/env-diagnostics.test.d.ts +0 -1
  141. package/dist/core/env-diagnostics.test.js +0 -31
  142. package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
  143. package/dist/core/evidence-bundle.conformance.test.js +0 -110
  144. package/dist/core/evidence-bundle.test.d.ts +0 -1
  145. package/dist/core/evidence-bundle.test.js +0 -58
  146. package/dist/core/invariants.test.d.ts +0 -1
  147. package/dist/core/invariants.test.js +0 -217
  148. package/dist/core/login-handoff.test.d.ts +0 -1
  149. package/dist/core/login-handoff.test.js +0 -31
  150. package/dist/core/profile.test.d.ts +0 -1
  151. package/dist/core/profile.test.js +0 -95
  152. package/dist/core/readiness-checks.test.d.ts +0 -1
  153. package/dist/core/readiness-checks.test.js +0 -106
  154. package/dist/core/receipt.test.d.ts +0 -1
  155. package/dist/core/receipt.test.js +0 -75
  156. package/dist/core/side-effects-review.test.d.ts +0 -1
  157. package/dist/core/side-effects-review.test.js +0 -28
  158. package/dist/core/token.test.d.ts +0 -1
  159. package/dist/core/token.test.js +0 -66
@@ -0,0 +1,278 @@
1
+ // ============================================================
2
+ // @duct-sdk/sdk — Project files (the split manifest)
3
+ //
4
+ // A Duct project is a `duct/` folder with one file per concern:
5
+ //
6
+ // duct/project.ts who you are: shell id, product, API origin, auth
7
+ // duct/capabilities.json what your API can do — generated by `duct sync`
8
+ // duct/policy.ts what agents may do — the guardrails you own
9
+ // duct/shell.ts optional: chat UI, routes, deeplinks, LLM hints
10
+ // duct/tests.ts optional: policy expectations checked by `duct test`
11
+ //
12
+ // `duct push` compiles these into the same manifest the Duct gateway has always
13
+ // enforced, so behaviour is identical to a hand-written duct.config.ts.
14
+ //
15
+ // Every .ts file is read statically (never executed): keep values literal.
16
+ // ============================================================
17
+ import { z } from "zod";
18
+ import { ManifestActionSchema, SensitivityLevelSchema, iso8601Schema, } from "@duct-sdk/contracts";
19
+ import { ApprovalStepUpConfigSchema, AuthSchemaSchema, DataModelSchema, DeeplinkDefinitionSchema, ProductConfigSchema, RouteManifestSchema, WebhooksConfigSchema, WidgetConfigSchema, } from "./config.js";
20
+ export const PROJECT_DIR = "duct";
21
+ export const PROJECT_FILES = {
22
+ project: "project.ts",
23
+ capabilities: "capabilities.json",
24
+ policy: "policy.ts",
25
+ shell: "shell.ts",
26
+ tests: "tests.ts",
27
+ };
28
+ /** Marker functions the static loader looks for in each .ts file. */
29
+ export const PROJECT_MARKERS = {
30
+ project: "defineProject(",
31
+ policy: "definePolicy(",
32
+ shell: "defineShell(",
33
+ tests: "defineTests(",
34
+ };
35
+ const ACTION_ID_RE = /^[a-z_][a-z0-9_]*$/;
36
+ // NOTE: schemas imported from @duct-sdk/contracts come from a separate zod copy.
37
+ // z.record(key, value) detects its value schema with `instanceof`, so contract schemas
38
+ // used as record values must be wrapped in z.lazy() or zod silently misreads them.
39
+ const PATTERN_RE = /^[a-z0-9_*]+$/;
40
+ /** Action id or glob over action ids, e.g. `get_*`, `*_order`, `*`. */
41
+ export const ActionPatternSchema = z
42
+ .string()
43
+ .min(1)
44
+ .regex(PATTERN_RE, "Patterns are snake_case action ids with * wildcards (e.g. get_*, refund_*, *)");
45
+ // ----------------------------------------------------------------
46
+ // duct/project.ts
47
+ // ----------------------------------------------------------------
48
+ export const ProjectNetworkSchema = z
49
+ .object({
50
+ registry_visibility: z.enum(["public", "private"]).optional(),
51
+ intershell_enabled: z.boolean().optional(),
52
+ allowedCallers: z.array(z.string()).optional(),
53
+ allowedCallees: z.array(z.string()).optional(),
54
+ })
55
+ .strict();
56
+ export const ProjectFileSchema = z
57
+ .object({
58
+ shellId: z
59
+ .string()
60
+ .min(1)
61
+ .regex(/^shell_[a-z0-9_]+$/, "Shell IDs must match pattern: shell_<company>_<env>"),
62
+ product: ProductConfigSchema,
63
+ /** How your app authenticates users. Only needed for user identity and the chat shell. */
64
+ auth: AuthSchemaSchema.optional(),
65
+ webhooks: WebhooksConfigSchema.optional(),
66
+ /** Cross-shell settings (early access, off by default). */
67
+ network: ProjectNetworkSchema.optional(),
68
+ })
69
+ .strict();
70
+ // ----------------------------------------------------------------
71
+ // duct/capabilities.json
72
+ // ----------------------------------------------------------------
73
+ export const CapabilityActionSchema = ManifestActionSchema.pick({
74
+ id: true,
75
+ name: true,
76
+ description: true,
77
+ method: true,
78
+ path: true,
79
+ sideEffects: true,
80
+ sideEffectsReviewAck: true,
81
+ params: true,
82
+ inputSchema: true,
83
+ responseSchema: true,
84
+ confidence: true,
85
+ evidence: true,
86
+ updatedAt: true,
87
+ })
88
+ .extend({
89
+ sensitivityLevel: SensitivityLevelSchema.default("low"),
90
+ requiresAuth: z.boolean().default(false),
91
+ })
92
+ .strict();
93
+ export const CapabilitySourceSchema = z
94
+ .object({
95
+ kind: z.enum(["openapi", "postman", "curl", "manual", "imported"]),
96
+ /** File path (relative to the project root) or URL the actions were generated from. */
97
+ location: z.string().optional(),
98
+ syncedAt: z.string().optional(),
99
+ })
100
+ .strict();
101
+ export const CapabilitiesFileSchema = z
102
+ .object({
103
+ $schema: z.string().optional(),
104
+ version: z.literal(1),
105
+ source: CapabilitySourceSchema,
106
+ actions: z.array(CapabilityActionSchema),
107
+ })
108
+ .strict()
109
+ .superRefine((value, ctx) => {
110
+ const seen = new Set();
111
+ value.actions.forEach((action, index) => {
112
+ if (seen.has(action.id)) {
113
+ ctx.addIssue({
114
+ code: z.ZodIssueCode.custom,
115
+ path: ["actions", index, "id"],
116
+ message: `Duplicate action id "${action.id}"`,
117
+ });
118
+ }
119
+ seen.add(action.id);
120
+ });
121
+ });
122
+ // ----------------------------------------------------------------
123
+ // duct/policy.ts
124
+ // ----------------------------------------------------------------
125
+ const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean()]);
126
+ /** One comparison on a param: `{ gt: 500 }`, `{ in: ["USD", "EUR"] }`, or a bare value for equality. */
127
+ export const ComparisonSchema = z.union([
128
+ PrimitiveSchema,
129
+ z
130
+ .object({
131
+ gt: PrimitiveSchema,
132
+ gte: PrimitiveSchema,
133
+ lt: PrimitiveSchema,
134
+ lte: PrimitiveSchema,
135
+ eq: PrimitiveSchema,
136
+ neq: PrimitiveSchema,
137
+ in: z.array(PrimitiveSchema).min(1),
138
+ })
139
+ .partial()
140
+ .strict()
141
+ .refine((value) => Object.keys(value).length === 1, {
142
+ message: "Use exactly one operator per comparison (gt, gte, lt, lte, eq, neq, in)",
143
+ }),
144
+ ]);
145
+ export const ConditionSchema = z.lazy(() => z.union([
146
+ z.object({ any: z.array(ConditionSchema).min(1) }).strict(),
147
+ z.object({ all: z.array(ConditionSchema).min(1) }).strict(),
148
+ z
149
+ .record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_.]*$/, "Param names must be identifiers"), ComparisonSchema)
150
+ .refine((value) => Object.keys(value).length > 0, { message: "Condition needs at least one param" }),
151
+ ]));
152
+ export const LimitSpecSchema = z
153
+ .object({
154
+ /** Requests per minute for this action (all callers). */
155
+ perMinute: z.number().int().positive().optional(),
156
+ perHour: z.number().int().positive().optional(),
157
+ perDay: z.number().int().positive().optional(),
158
+ /** Lifetime cap on executions. */
159
+ total: z.number().int().positive().optional(),
160
+ /** Custom rolling window. */
161
+ window: z
162
+ .object({ max: z.number().int().positive(), seconds: z.number().int().positive() })
163
+ .strict()
164
+ .optional(),
165
+ })
166
+ .strict()
167
+ .superRefine((value, ctx) => {
168
+ const windowed = ["perHour", "perDay", "total", "window"].filter((key) => value[key] !== undefined);
169
+ if (windowed.length > 1) {
170
+ ctx.addIssue({
171
+ code: z.ZodIssueCode.custom,
172
+ message: `Use only one of perHour, perDay, total, window per entry (got ${windowed.join(", ")})`,
173
+ });
174
+ }
175
+ if (Object.keys(value).length === 0) {
176
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Limit needs at least one field" });
177
+ }
178
+ });
179
+ export const AgentAccessSchema = z.enum(["none", "read", "write"]);
180
+ export const PolicyAgentsSchema = z
181
+ .object({
182
+ /** Default for agents: none = no access, read = read-only actions, write = all exposed actions. */
183
+ access: AgentAccessSchema.default("read"),
184
+ /** Actions agents may call. Omit to expose every action the access level permits. */
185
+ allow: z.array(ActionPatternSchema).optional(),
186
+ /** Actions agents may never call. Deny always wins. */
187
+ deny: z.array(ActionPatternSchema).optional(),
188
+ /** Per-action access level overrides (advanced). */
189
+ levels: z.record(z.string().regex(ACTION_ID_RE), z.enum(["none", "read", "write", "admin"])).optional(),
190
+ /** Require a user consent token for every agent call that acts for a user. */
191
+ userConsent: z.boolean().default(true),
192
+ /** Limit which actions a user's consent can cover (exact action ids). */
193
+ consentScope: z.array(z.string().regex(ACTION_ID_RE)).optional(),
194
+ validFrom: iso8601Schema.optional(),
195
+ validUntil: iso8601Schema.optional(),
196
+ })
197
+ .strict();
198
+ export const PolicyApproversSchema = z
199
+ .object({
200
+ /** Who gets notified when an agent request is waiting for approval. */
201
+ emails: z.array(z.string().email()).optional(),
202
+ reminderLeadMinutes: z.number().int().positive().nullable().optional(),
203
+ /** Re-authentication required to approve sensitive requests. */
204
+ stepUp: ApprovalStepUpConfigSchema.optional(),
205
+ })
206
+ .strict();
207
+ export const PolicyFileSchema = z
208
+ .object({
209
+ agents: PolicyAgentsSchema.default({}),
210
+ /** Require human approval when a call matches the condition. Later entries win. */
211
+ approveWhen: z.record(ActionPatternSchema, ConditionSchema).optional(),
212
+ /** Rate and count limits. Applied top to bottom; later entries override earlier fields. */
213
+ limits: z.record(ActionPatternSchema, LimitSpecSchema).optional(),
214
+ /** Raise or lower sensitivity for matching actions. Later entries win. */
215
+ sensitivity: z.record(ActionPatternSchema, z.lazy(() => SensitivityLevelSchema)).optional(),
216
+ /** Time windows during which matching actions are callable. */
217
+ windows: z
218
+ .record(ActionPatternSchema, z.object({ from: iso8601Schema.optional(), until: iso8601Schema.optional() }).strict())
219
+ .optional(),
220
+ approvers: PolicyApproversSchema.optional(),
221
+ })
222
+ .strict();
223
+ // ----------------------------------------------------------------
224
+ // duct/shell.ts
225
+ // ----------------------------------------------------------------
226
+ export const ShellActionHintsSchema = ManifestActionSchema.pick({
227
+ searchHint: true,
228
+ alwaysInclude: true,
229
+ interruptBehavior: true,
230
+ dependsOn: true,
231
+ semanticType: true,
232
+ outputSchema: true,
233
+ paramMappings: true,
234
+ navigatesTo: true,
235
+ }).strict();
236
+ export const ShellFileSchema = z
237
+ .object({
238
+ widget: WidgetConfigSchema.optional(),
239
+ routes: z.array(RouteManifestSchema).default([]),
240
+ deeplinks: z.array(DeeplinkDefinitionSchema).default([]),
241
+ dataModel: DataModelSchema.optional(),
242
+ /** Chat-only hints per action id: search hints, UI shape, chaining. */
243
+ actionHints: z.record(z.string().regex(ACTION_ID_RE), z.lazy(() => ShellActionHintsSchema)).optional(),
244
+ })
245
+ .strict();
246
+ // ----------------------------------------------------------------
247
+ // duct/tests.ts
248
+ // ----------------------------------------------------------------
249
+ export const PolicyExpectationSchema = z.enum(["allow", "deny", "approval", "blocked"]);
250
+ export const PolicyTestCaseSchema = z
251
+ .object({
252
+ name: z.string().optional(),
253
+ /** Who is calling: an external agent, a signed-in user in the shell, or a guest. */
254
+ as: z.enum(["agent", "user", "guest"]),
255
+ action: z.string().regex(ACTION_ID_RE),
256
+ params: z.record(z.unknown()).optional(),
257
+ withUserConsent: z.boolean().optional(),
258
+ /** `blocked` = must not run without a human (deny or approval). */
259
+ expect: PolicyExpectationSchema,
260
+ })
261
+ .strict();
262
+ export const TestsFileSchema = z
263
+ .object({
264
+ policy: z.array(PolicyTestCaseSchema).default([]),
265
+ })
266
+ .strict();
267
+ export function defineProject(project) {
268
+ return project;
269
+ }
270
+ export function definePolicy(policy) {
271
+ return policy;
272
+ }
273
+ export function defineShell(shell) {
274
+ return shell;
275
+ }
276
+ export function defineTests(tests) {
277
+ return tests;
278
+ }
@@ -41,7 +41,7 @@ export async function buildCliReadinessReport(options) {
41
41
  checks.push(makeCheck('env_duct_url', 'DUCT_URL', env.ductUrl ? 'pass' : 'warn', { message: env.ductUrl || 'Not set — using localhost defaults' }), makeCheck('env_shell_id', 'DUCT_SHELL_ID', env.shellId ? 'pass' : 'warn', { message: env.shellId || 'Not set' }), makeCheck('env_secret_key', 'DUCT_SECRET_KEY', env.secretKey ? 'pass' : 'warn', { message: env.secretKey ? `sk_...${env.secretKey.slice(-4)}` : 'Not set' }), makeCheck('auth_logged_in', 'CLI auth profile', env.authEmail ? 'pass' : 'warn', {
42
42
  message: env.authEmail
43
43
  ? `${env.authEmail} (${env.authSlug ?? 'unknown slug'})`
44
- : 'Not logged in — run: npx duct login',
44
+ : 'Not logged in — run: npx @duct-sdk/sdk login',
45
45
  }));
46
46
  const serviceChecks = [
47
47
  { id: 'auth_reachable', label: 'Auth service', url: endpoints.authHealthUrl },
@@ -132,7 +132,7 @@ export async function buildShellReadinessReport(input) {
132
132
  checks.push(makeCheck('manifest_pushed', 'Manifest pushed', input.manifestPushed ? 'pass' : 'fail', {
133
133
  message: input.manifestPushed
134
134
  ? 'Shell status is live'
135
- : 'Run npx duct push to publish your manifest',
135
+ : 'Run npx @duct-sdk/sdk push to publish your manifest',
136
136
  }));
137
137
  if (!input.productBaseUrl) {
138
138
  checks.push(makeCheck('product_base_url', 'Product base URL', 'warn', {
@@ -190,7 +190,7 @@ export interface AuthSchema {
190
190
  loginDeeplinkId?: string;
191
191
  /**
192
192
  * App route path for sign-in (e.g. `/login`). Used when no login deeplink is
193
- * declared — auto-detected from routes during `duct init` when possible.
193
+ * declared — auto-detected from routes by `duct add identity` when possible.
194
194
  */
195
195
  loginRoutePath?: string;
196
196
  /** Agent detection confidence (0.0–1.0). */
@@ -476,6 +476,25 @@ export interface DataModelEntity {
476
476
  export interface DataModel {
477
477
  entities: DataModelEntity[];
478
478
  }
479
+ /** Human approval policy — step-up password re-entry before operator approves. */
480
+ export interface ApprovalStepUpConfig {
481
+ /** Minimum sensitivity that always requires step-up (default high → high + critical). */
482
+ minSensitivity?: SensitivityLevel;
483
+ /** When true, side-effect actions can require step-up per sideEffectsMinSensitivity. */
484
+ requireForSideEffects?: boolean;
485
+ /** Side-effect actions at or above this level require step-up (default medium). */
486
+ sideEffectsMinSensitivity?: SensitivityLevel;
487
+ }
488
+ export interface ApprovalConfig {
489
+ stepUp?: ApprovalStepUpConfig;
490
+ }
491
+ /** Operator notifications for pending confirmations (dashboard-configured). */
492
+ export interface OperatorNotificationsConfig {
493
+ /** Email addresses to notify when a confirmation is created. */
494
+ approverEmails?: string[];
495
+ /** Minutes before expiry to send one reminder; omit or null = off. */
496
+ confirmationReminderLeadMinutes?: number | null;
497
+ }
479
498
  export interface DuctConfig {
480
499
  /** Shell ID assigned by Duct cloud */
481
500
  shellId: string;
@@ -505,6 +524,10 @@ export interface DuctConfig {
505
524
  intershell_enabled?: boolean;
506
525
  /** Identity/consent webhook wiring — required for cross-shell protected actions. */
507
526
  webhooks?: WebhooksConfig;
527
+ /** Gateway approval policy (step-up thresholds). */
528
+ approval?: ApprovalConfig;
529
+ /** Pending-confirmation operator notifications. */
530
+ operatorNotifications?: OperatorNotificationsConfig;
508
531
  }
509
532
  /**
510
533
  * Identity/consent webhook wiring for this shell. Read dynamically from manifest JSON
@@ -519,6 +542,8 @@ export interface WebhooksConfig {
519
542
  identityUrl?: string;
520
543
  /** Shared webhook signing secret (whsec_…) used to verify identity vouches + signed callbacks. */
521
544
  secret?: string;
545
+ deeplinkCallback?: string;
546
+ eventStream?: string;
522
547
  }
523
548
  export interface ShellManifest {
524
549
  shellId: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ export declare class DuctSdkWrongEntrypointError extends Error {
2
+ readonly name = "DuctSdkWrongEntrypointError";
3
+ constructor();
4
+ }
1
5
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
2
6
  export type { ValidatedDuctConfig, ManifestAction, ErrorEnvelope, ConfirmationState } from "./core/config.js";
7
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
8
+ export type { ProjectFile, CapabilitiesFile, PolicyFile, ShellFile, TestsFile } from "./core/project.js";
3
9
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
4
10
  export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, DeeplinkReplayStore, RedisSetClient, } from "./core/token.js";
5
11
  export { verifyReceipt, computeReceiptId } from "./core/receipt.js";
package/dist/index.js CHANGED
@@ -5,8 +5,24 @@
5
5
  // instead. The root export includes React adapters which crash
6
6
  // runtimes where React is not installed (e.g. plain Express).
7
7
  // ============================================================
8
+ import { createRequire } from 'node:module';
9
+ const require = createRequire(import.meta.url);
10
+ export class DuctSdkWrongEntrypointError extends Error {
11
+ name = 'DuctSdkWrongEntrypointError';
12
+ constructor() {
13
+ super('Import @duct-sdk/sdk/server in Node.js backends (Express, Fastify, etc.). ' +
14
+ 'The package root export includes React adapters and requires react/react-dom.');
15
+ }
16
+ }
17
+ try {
18
+ require.resolve('react');
19
+ }
20
+ catch {
21
+ throw new DuctSdkWrongEntrypointError();
22
+ }
8
23
  // Core config
9
24
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
25
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
10
26
  // Token utilities
11
27
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
12
28
  // Outcome receipt verification (crypto layer)
@@ -0,0 +1,4 @@
1
+ export { defineProject, definePolicy, defineShell, defineTests, PROJECT_DIR, PROJECT_FILES, ProjectFileSchema, CapabilitiesFileSchema, PolicyFileSchema, ShellFileSchema, TestsFileSchema, } from "./core/project.js";
2
+ export type { ProjectFile, CapabilitiesFile, CapabilityAction, PolicyFile, ShellFile, TestsFile, PolicyTestCase, PolicyExpectation, Condition, Comparison, LimitSpec, AgentAccess, } from "./core/project.js";
3
+ export { compileProject, splitDuctConfig, enforcementDiff, matchesPattern } from "./core/compile.js";
4
+ export type { CompileResult, ProjectInput, SplitResult } from "./core/compile.js";
@@ -0,0 +1,8 @@
1
+ // ============================================================
2
+ // @duct-sdk/sdk/project — typed helpers for duct/*.ts project files
3
+ //
4
+ // Dependency-light entry point: safe to import from any backend (no React,
5
+ // no Node-only APIs). The CLI reads these files statically and never runs them.
6
+ // ============================================================
7
+ export { defineProject, definePolicy, defineShell, defineTests, PROJECT_DIR, PROJECT_FILES, ProjectFileSchema, CapabilitiesFileSchema, PolicyFileSchema, ShellFileSchema, TestsFileSchema, } from "./core/project.js";
8
+ export { compileProject, splitDuctConfig, enforcementDiff, matchesPattern } from "./core/compile.js";
package/dist/server.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
2
2
  export type { ValidatedDuctConfig, ManifestAction, ErrorEnvelope, ConfirmationState } from "./core/config.js";
3
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
4
+ export type { ProjectFile, CapabilitiesFile, PolicyFile, ShellFile, TestsFile } from "./core/project.js";
3
5
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
4
6
  export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, DeeplinkReplayStore, RedisSetClient, } from "./core/token.js";
5
7
  export { verifyReceipt, computeReceiptId } from "./core/receipt.js";
package/dist/server.js CHANGED
@@ -11,6 +11,7 @@
11
11
  // ============================================================
12
12
  // Config
13
13
  export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
14
+ export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
14
15
  // Token utilities — mint delegated JWTs, verify them, handle deeplinks
15
16
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
16
17
  // Outcome receipt verification (crypto layer)
@@ -0,0 +1,26 @@
1
+ {
2
+ "version": 1,
3
+ "secret": "conformance-test-secret-32chars!!",
4
+ "shellId": "shell_conformance_test",
5
+ "delegated": {
6
+ "mint": {
7
+ "userSession": { "id": "user_42", "email": "user@example.com" },
8
+ "expirySeconds": 300,
9
+ "allowedActions": ["get_orders"]
10
+ },
11
+ "verify": {
12
+ "expectedShellId": "shell_conformance_test"
13
+ }
14
+ },
15
+ "deeplink": {
16
+ "mint": {
17
+ "deeplinkId": "view_order",
18
+ "state": { "orderId": "99" },
19
+ "expirySeconds": 300
20
+ }
21
+ },
22
+ "reject": [
23
+ { "id": "wrong_iss", "description": "issuer does not match shell", "token": "eyJhbGciOiJIUzI1NiJ9.eyJ0eXBlIjoiZHVjdF9kZWxlZ2F0ZWQiLCJpc3MiOiJzaGVsbF93cm9uZyIsInN1YiI6InVzZXJfNDIiLCJzZXNzaW9uIjp7fSwiaWF0IjoxNzAwMDAwMDAwLCJleHAiOjQxMDI0NDQ4MDB9.invalid" },
24
+ { "id": "alg_none", "description": "alg none must be rejected", "token": "eyJhbGciOiJub25lIn0.eyJ0eXBlIjoiZHVjdF9kZWxlZ2F0ZWQifQ." }
25
+ ]
26
+ }
package/package.json CHANGED
@@ -1,94 +1,94 @@
1
- {
2
- "name": "@duct-sdk/sdk",
3
- "version": "0.5.12",
4
- "type": "module",
5
- "description": "Duct SDK — manifest, CLI, and embed components for permissioned human and agent access to your product APIs.",
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
- "./server": "./dist/server.js",
14
- "./next": "./dist/adapters/next/index.js",
15
- "./remix": "./dist/adapters/remix/index.js",
16
- "./vite": "./dist/adapters/vite/index.js",
17
- "./sveltekit": "./dist/adapters/sveltekit/index.js",
18
- "./react": "./dist/adapters/react/index.js"
19
- },
20
- "scripts": {
21
- "build": "npm run build --prefix ../contracts && tsc",
22
- "dev": "tsc --watch",
23
- "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
- "verify:publish": "node scripts/verify-publish.mjs",
25
- "pack:release": "npm run build && npm run verify:publish && node scripts/pack-release.mjs",
26
- "prepublishOnly": "npm run build && npm run verify:publish"
27
- },
28
- "dependencies": {
29
- "@duct-sdk/contracts": "file:../contracts",
30
- "@anthropic-ai/sdk": "^0.24.0",
31
- "jose": "^5.0.0",
32
- "ignore": "^5.0.0",
33
- "commander": "^12.0.0",
34
- "chalk": "^5.0.0",
35
- "ora": "^8.0.0",
36
- "inquirer": "^9.0.0",
37
- "zod": "^3.0.0",
38
- "node-fetch": "^3.0.0",
39
- "glob": "^10.0.0",
40
- "yaml": "^2.0.0"
41
- },
42
- "devDependencies": {
43
- "typescript": "^5.0.0",
44
- "@types/node": "^20.0.0",
45
- "@types/inquirer": "^9.0.0",
46
- "@types/react": "^18.0.0",
47
- "next": "^14.0.0",
48
- "react": "^18.0.0",
49
- "react-dom": "^18.0.0"
50
- },
51
- "peerDependencies": {
52
- "react": "^18.0.0 || ^19.0.0",
53
- "react-dom": "^18.0.0 || ^19.0.0",
54
- "next": ">=14.0.0"
55
- },
56
- "peerDependenciesMeta": {
57
- "react": {
58
- "optional": true
59
- },
60
- "react-dom": {
61
- "optional": true
62
- },
63
- "next": {
64
- "optional": true
65
- }
66
- },
67
- "files": [
68
- "dist",
69
- "assets",
70
- "README.md",
71
- "CHANGELOG.md",
72
- "TOKEN_SPEC.md"
73
- ],
74
- "keywords": [
75
- "duct",
76
- "ai",
77
- "agent",
78
- "shell",
79
- "cli",
80
- "llm",
81
- "ai-agent",
82
- "deeplink",
83
- "next",
84
- "nextjs",
85
- "remix",
86
- "vite",
87
- "sveltekit",
88
- "sdk"
89
- ],
90
- "publishConfig": {
91
- "registry": "https://registry.npmjs.org",
92
- "access": "public"
93
- }
94
- }
1
+ {
2
+ "name": "@duct-sdk/sdk",
3
+ "version": "0.6.0",
4
+ "type": "module",
5
+ "description": "Duct SDK — CLI, project files, and embed components for policy-enforced agent access to your product APIs.",
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
+ "./server": "./dist/server.js",
14
+ "./project": "./dist/project.js",
15
+ "./next": "./dist/adapters/next/index.js",
16
+ "./remix": "./dist/adapters/remix/index.js",
17
+ "./vite": "./dist/adapters/vite/index.js",
18
+ "./sveltekit": "./dist/adapters/sveltekit/index.js",
19
+ "./react": "./dist/adapters/react/index.js"
20
+ },
21
+ "scripts": {
22
+ "build": "npm run build --prefix ../contracts && tsc",
23
+ "dev": "tsc --watch",
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 && node --test tests/*.test.mjs",
25
+ "verify:publish": "node scripts/verify-publish.mjs",
26
+ "pack:release": "npm run build && npm run verify:publish && node scripts/pack-release.mjs",
27
+ "prepublishOnly": "npm run build && npm run verify:publish"
28
+ },
29
+ "dependencies": {
30
+ "@duct-sdk/contracts": "file:../contracts",
31
+ "jose": "^5.0.0",
32
+ "commander": "^12.0.0",
33
+ "chalk": "^5.0.0",
34
+ "ora": "^8.0.0",
35
+ "inquirer": "^9.0.0",
36
+ "zod": "^3.0.0",
37
+ "glob": "^10.0.0",
38
+ "yaml": "^2.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.0.0",
42
+ "@types/node": "^20.0.0",
43
+ "@types/inquirer": "^9.0.0",
44
+ "@types/react": "^18.0.0",
45
+ "next": "^14.0.0",
46
+ "react": "^18.0.0",
47
+ "react-dom": "^18.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react": "^18.0.0 || ^19.0.0",
51
+ "react-dom": "^18.0.0 || ^19.0.0",
52
+ "next": ">=14.0.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "react": {
56
+ "optional": true
57
+ },
58
+ "react-dom": {
59
+ "optional": true
60
+ },
61
+ "next": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "files": [
66
+ "dist",
67
+ "!dist/**/*.test.*",
68
+ "assets",
69
+ "fixtures",
70
+ "README.md",
71
+ "CHANGELOG.md",
72
+ "TOKEN_SPEC.md"
73
+ ],
74
+ "keywords": [
75
+ "duct",
76
+ "ai",
77
+ "agent",
78
+ "shell",
79
+ "cli",
80
+ "llm",
81
+ "ai-agent",
82
+ "deeplink",
83
+ "next",
84
+ "nextjs",
85
+ "remix",
86
+ "vite",
87
+ "sveltekit",
88
+ "sdk"
89
+ ],
90
+ "publishConfig": {
91
+ "registry": "https://registry.npmjs.org",
92
+ "access": "public"
93
+ }
94
+ }
@@ -1 +0,0 @@
1
- export {};