@duct-sdk/sdk 0.5.13 → 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.
- package/CHANGELOG.md +385 -344
- package/README.md +418 -264
- package/TOKEN_SPEC.md +243 -243
- package/dist/cli/add.d.ts +7 -0
- package/dist/cli/add.js +152 -0
- package/dist/cli/agent-prompt.d.ts +3 -0
- package/dist/cli/agent-prompt.js +39 -0
- package/dist/cli/api-sources.d.ts +26 -0
- package/dist/cli/api-sources.js +222 -0
- package/dist/cli/cloud.d.ts +133 -0
- package/dist/cli/cloud.js +298 -0
- package/dist/cli/config-loader.d.ts +14 -0
- package/dist/cli/config-loader.js +56 -7
- package/dist/cli/device-login.d.ts +17 -0
- package/dist/cli/device-login.js +75 -0
- package/dist/cli/drift.js +6 -6
- package/dist/cli/generators/any-stack.d.ts +3 -0
- package/dist/cli/generators/any-stack.js +97 -0
- package/dist/cli/generators/config.js +3 -2
- package/dist/cli/generators/receiver.js +7 -7
- package/dist/cli/generators/shell.js +12 -12
- package/dist/cli/generators/token-route.js +245 -245
- package/dist/cli/index.js +396 -611
- package/dist/cli/mcp-core.d.ts +42 -0
- package/dist/cli/mcp-core.js +161 -0
- package/dist/cli/mcp-setup.d.ts +4 -0
- package/dist/cli/mcp-setup.js +360 -0
- package/dist/cli/mcp.d.ts +2 -0
- package/dist/cli/mcp.js +457 -0
- package/dist/cli/migrate-intershell.js +5 -5
- package/dist/cli/policy-defaults.d.ts +37 -0
- package/dist/cli/policy-defaults.js +127 -0
- package/dist/cli/processors/integration-audit.js +2 -2
- package/dist/cli/processors/openapi-parser.d.ts +5 -0
- package/dist/cli/processors/openapi-parser.js +8 -3
- package/dist/cli/project-loader.d.ts +58 -0
- package/dist/cli/project-loader.js +198 -0
- package/dist/cli/project-writer.d.ts +23 -0
- package/dist/cli/project-writer.js +171 -0
- package/dist/cli/push.d.ts +43 -0
- package/dist/cli/push.js +276 -0
- package/dist/cli/safety-checks.d.ts +9 -0
- package/dist/cli/safety-checks.js +29 -0
- package/dist/cli/setup.d.ts +20 -0
- package/dist/cli/setup.js +349 -0
- package/dist/cli/shell-name.d.ts +8 -0
- package/dist/cli/shell-name.js +29 -0
- package/dist/cli/shells.d.ts +22 -0
- package/dist/cli/shells.js +122 -0
- package/dist/cli/split.d.ts +7 -0
- package/dist/cli/split.js +71 -0
- package/dist/cli/sync.d.ts +25 -0
- package/dist/cli/sync.js +120 -0
- package/dist/cli/test-runner.d.ts +21 -0
- package/dist/cli/test-runner.js +281 -0
- package/dist/core/compile.d.ts +43 -0
- package/dist/core/compile.js +510 -0
- package/dist/core/config.d.ts +464 -1
- package/dist/core/config.js +14 -14
- package/dist/core/login-handoff.d.ts +1 -1
- package/dist/core/login-handoff.js +1 -1
- package/dist/core/project.d.ts +1798 -0
- package/dist/core/project.js +278 -0
- package/dist/core/readiness-checks.js +2 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/project.d.ts +4 -0
- package/dist/project.js +8 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/package.json +94 -95
- package/dist/adapters/react/page-context-guard.test.d.ts +0 -1
- package/dist/adapters/react/page-context-guard.test.js +0 -15
- package/dist/cli/agents/api-agent.d.ts +0 -22
- package/dist/cli/agents/api-agent.js +0 -761
- package/dist/cli/agents/auth-agent.d.ts +0 -7
- package/dist/cli/agents/auth-agent.js +0 -212
- package/dist/cli/agents/deeplink-agent.d.ts +0 -6
- package/dist/cli/agents/deeplink-agent.js +0 -285
- package/dist/cli/agents/llm.d.ts +0 -33
- package/dist/cli/agents/llm.js +0 -309
- package/dist/cli/agents/pipeline.d.ts +0 -72
- package/dist/cli/agents/pipeline.js +0 -421
- package/dist/cli/agents/reviewer-agent.d.ts +0 -13
- package/dist/cli/agents/reviewer-agent.js +0 -450
- package/dist/cli/agents/route-agent.d.ts +0 -17
- package/dist/cli/agents/route-agent.js +0 -383
- package/dist/cli/config-loader.test.d.ts +0 -1
- package/dist/cli/config-loader.test.js +0 -63
- package/dist/cli/detectors/topology.d.ts +0 -46
- package/dist/cli/detectors/topology.js +0 -417
- package/dist/cli/generators/config.test.d.ts +0 -1
- package/dist/cli/generators/config.test.js +0 -222
- package/dist/cli/generators/shell.test.d.ts +0 -1
- package/dist/cli/generators/shell.test.js +0 -73
- package/dist/cli/generators/token-route.test.d.ts +0 -1
- package/dist/cli/generators/token-route.test.js +0 -53
- package/dist/cli/generators/wiring-snippets.test.d.ts +0 -1
- package/dist/cli/generators/wiring-snippets.test.js +0 -80
- package/dist/cli/init.d.ts +0 -32
- package/dist/cli/init.js +0 -1336
- package/dist/cli/manifest-diff.test.d.ts +0 -1
- package/dist/cli/manifest-diff.test.js +0 -144
- package/dist/cli/processors/curl-parser.test.d.ts +0 -1
- package/dist/cli/processors/curl-parser.test.js +0 -24
- package/dist/cli/processors/integration-audit.test.d.ts +0 -1
- package/dist/cli/processors/integration-audit.test.js +0 -154
- package/dist/cli/processors/postprocess.d.ts +0 -22
- package/dist/cli/processors/postprocess.js +0 -107
- package/dist/cli/processors/prisma-parser.d.ts +0 -35
- package/dist/cli/processors/prisma-parser.js +0 -117
- package/dist/cli/processors/verify-discovery.d.ts +0 -33
- package/dist/cli/processors/verify-discovery.js +0 -193
- package/dist/cli/processors/verify-discovery.test.d.ts +0 -1
- package/dist/cli/processors/verify-discovery.test.js +0 -153
- package/dist/cli/processors/zod-extractor.d.ts +0 -27
- package/dist/cli/processors/zod-extractor.js +0 -153
- package/dist/cli/prompts/review.d.ts +0 -61
- package/dist/cli/prompts/review.js +0 -410
- package/dist/cli/selectors/express.d.ts +0 -12
- package/dist/cli/selectors/express.js +0 -117
- package/dist/cli/selectors/fastapi.d.ts +0 -12
- package/dist/cli/selectors/fastapi.js +0 -122
- package/dist/cli/selectors/generic.d.ts +0 -10
- package/dist/cli/selectors/generic.js +0 -74
- package/dist/cli/selectors/index.d.ts +0 -37
- package/dist/cli/selectors/index.js +0 -315
- package/dist/cli/selectors/next.d.ts +0 -12
- package/dist/cli/selectors/next.js +0 -130
- package/dist/core/config-policy.test.d.ts +0 -1
- package/dist/core/config-policy.test.js +0 -101
- package/dist/core/config-roundtrip.test.d.ts +0 -1
- package/dist/core/config-roundtrip.test.js +0 -180
- package/dist/core/endpoint-guard.test.d.ts +0 -1
- package/dist/core/endpoint-guard.test.js +0 -57
- package/dist/core/env-diagnostics.test.d.ts +0 -1
- package/dist/core/env-diagnostics.test.js +0 -31
- package/dist/core/evidence-bundle.conformance.test.d.ts +0 -1
- package/dist/core/evidence-bundle.conformance.test.js +0 -110
- package/dist/core/evidence-bundle.test.d.ts +0 -1
- package/dist/core/evidence-bundle.test.js +0 -58
- package/dist/core/invariants.test.d.ts +0 -1
- package/dist/core/invariants.test.js +0 -217
- package/dist/core/login-handoff.test.d.ts +0 -1
- package/dist/core/login-handoff.test.js +0 -31
- package/dist/core/profile.test.d.ts +0 -1
- package/dist/core/profile.test.js +0 -95
- package/dist/core/readiness-checks.test.d.ts +0 -1
- package/dist/core/readiness-checks.test.js +0 -106
- package/dist/core/receipt.test.d.ts +0 -1
- package/dist/core/receipt.test.js +0 -75
- package/dist/core/sdk-entrypoint.test.d.ts +0 -1
- package/dist/core/sdk-entrypoint.test.js +0 -8
- package/dist/core/side-effects-review.test.d.ts +0 -1
- package/dist/core/side-effects-review.test.js +0 -28
- package/dist/core/token.conformance.test.d.ts +0 -1
- package/dist/core/token.conformance.test.js +0 -43
- package/dist/core/token.test.d.ts +0 -1
- 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', {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -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
|
|
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). */
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare class DuctSdkWrongEntrypointError extends Error {
|
|
|
4
4
|
}
|
|
5
5
|
export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
|
|
6
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";
|
|
7
9
|
export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
|
|
8
10
|
export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, DeeplinkReplayStore, RedisSetClient, } from "./core/token.js";
|
|
9
11
|
export { verifyReceipt, computeReceiptId } from "./core/receipt.js";
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ catch {
|
|
|
22
22
|
}
|
|
23
23
|
// Core config
|
|
24
24
|
export { defineDuctConfig, DuctConfigSchema, crossValidateDuctConfig, ManifestActionSchema, ActionManifestSchema, SensitivityLevelSchema, ErrorEnvelopeSchema, ConfirmationStateSchema, } from "./core/config.js";
|
|
25
|
+
export { defineProject, definePolicy, defineShell, defineTests } from "./core/project.js";
|
|
25
26
|
// Token utilities
|
|
26
27
|
export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, createDevReplayStore, InMemoryReplayStore, RedisReplayStore, } from "./core/token.js";
|
|
27
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";
|
package/dist/project.js
ADDED
|
@@ -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)
|
package/package.json
CHANGED
|
@@ -1,95 +1,94 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@duct-sdk/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Duct SDK —
|
|
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
|
-
"./
|
|
15
|
-
"./
|
|
16
|
-
"./
|
|
17
|
-
"./
|
|
18
|
-
"./
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"@
|
|
31
|
-
"jose": "^5.0.0",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"@types/
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
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 {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { shouldHandlePageContextRequest } from "./page-context-guard.js";
|
|
4
|
-
describe("shouldHandlePageContextRequest", () => {
|
|
5
|
-
it("refuses foreign origins when shellHost is configured", () => {
|
|
6
|
-
assert.equal(shouldHandlePageContextRequest("http://localhost:3000", "https://evil.example"), false);
|
|
7
|
-
});
|
|
8
|
-
it("allows the shell origin", () => {
|
|
9
|
-
assert.equal(shouldHandlePageContextRequest("http://localhost:3000", "http://localhost:3000"), true);
|
|
10
|
-
});
|
|
11
|
-
it("fails closed without shellHost", () => {
|
|
12
|
-
assert.equal(shouldHandlePageContextRequest(undefined, "http://localhost:3000"), false);
|
|
13
|
-
assert.equal(shouldHandlePageContextRequest(undefined, "https://evil.example"), false);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { SandboxFS } from "../fs/sandbox.js";
|
|
2
|
-
import type { ActionManifest } from "../../core/types.js";
|
|
3
|
-
export interface ApiScannerStrategy {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
detect(sandboxFs: SandboxFS): Promise<boolean>;
|
|
6
|
-
appendPromptContext(sandboxFs: SandboxFS, lines: string[]): Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Run the API Agent to produce ActionManifest[] from the project's API layer.
|
|
10
|
-
*
|
|
11
|
-
* Priority:
|
|
12
|
-
* 1. inlineSpecContent — spec passed directly from --api-spec flag (skips all discovery)
|
|
13
|
-
* 2. openapi.json / openapi.yaml at known paths
|
|
14
|
-
* 3. Filesystem scan of API route handlers
|
|
15
|
-
*
|
|
16
|
-
* @param hintFiles - Optional pre-selected file paths from the file selector.
|
|
17
|
-
* @param inlineSpecContent - Raw spec content passed via --api-spec (bypasses sandbox lookup).
|
|
18
|
-
* @param inlineSpecPath - Display path for the inline spec (used in prompt context).
|
|
19
|
-
*/
|
|
20
|
-
export declare function runApiAgent(sandboxFs: SandboxFS, hintFiles?: string[], inlineSpecContent?: string, inlineSpecPath?: string, options?: {
|
|
21
|
-
retry?: boolean;
|
|
22
|
-
}): Promise<ActionManifest[]>;
|