@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.
- package/CHANGELOG.md +385 -336
- package/README.md +418 -264
- package/TOKEN_SPEC.md +243 -237
- 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 +402 -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 +533 -1
- package/dist/core/config.js +32 -12
- package/dist/core/hosted-upstream-check.d.ts +3 -0
- package/dist/core/hosted-upstream-check.js +35 -0
- 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 +26 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +16 -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/fixtures/token-conformance-vectors.json +26 -0
- package/package.json +94 -94
- 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/side-effects-review.test.d.ts +0 -1
- package/dist/core/side-effects-review.test.js +0 -28
- package/dist/core/token.test.d.ts +0 -1
- package/dist/core/token.test.js +0 -66
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — Prompt for coding agents (Claude Code, Cursor, Codex, …)
|
|
3
|
+
//
|
|
4
|
+
// When a codebase has no OpenAPI spec, the developer's own coding agent reads
|
|
5
|
+
// the code and fills duct/capabilities.json. Duct supplies the deterministic
|
|
6
|
+
// tools (`validate`, `test`) and the guardrails stay in duct/policy.ts.
|
|
7
|
+
// ============================================================
|
|
8
|
+
export function buildAgentPrompt(opts) {
|
|
9
|
+
const start = opts.hasProject
|
|
10
|
+
? "This repo already has a duct/ folder. Read duct/project.ts and duct/capabilities.json first."
|
|
11
|
+
: "Run `npx @duct-sdk/sdk setup --yes --source none` first. It creates duct/ with an empty capability list.";
|
|
12
|
+
return `You are connecting this codebase to Duct, a gateway that lets AI agents call this product's API under a policy the team controls.
|
|
13
|
+
|
|
14
|
+
${start}
|
|
15
|
+
|
|
16
|
+
Your job: list the HTTP endpoints this API exposes in duct/capabilities.json. Do not change application code.
|
|
17
|
+
|
|
18
|
+
1. Find the API routes (Express/Fastify/Nest routers, Next.js route handlers, FastAPI/Django/Rails routes, etc.).
|
|
19
|
+
2. For each endpoint a user or agent would reasonably call, add one entry to "actions":
|
|
20
|
+
{
|
|
21
|
+
"id": "snake_case_verb_noun", // e.g. list_orders, create_refund — unique
|
|
22
|
+
"name": "Human readable name",
|
|
23
|
+
"description": "One sentence: what it does and what it returns",
|
|
24
|
+
"method": "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
|
|
25
|
+
"path": "/api/orders/:id", // Express-style :params
|
|
26
|
+
"params": [{ "name": "id", "type": "string", "required": true, "description": "Order id" }],
|
|
27
|
+
"sideEffects": false, // true if it creates, changes, sends, charges, or deletes anything
|
|
28
|
+
"requiresAuth": true, // true if the endpoint needs a signed-in user
|
|
29
|
+
"sensitivityLevel": "low" // none | low | medium | high | critical (money, PII, auth, admin = high+)
|
|
30
|
+
}
|
|
31
|
+
3. Skip health checks, auth/session internals, webhooks, and admin-only endpoints.
|
|
32
|
+
4. Be conservative: when unsure, set sideEffects: true and a higher sensitivityLevel.
|
|
33
|
+
5. Do not edit duct/policy.ts beyond adding ids to agents.deny for anything destructive. The team owns the policy.
|
|
34
|
+
6. Run \`npx @duct-sdk/sdk validate\` and fix every error it reports.
|
|
35
|
+
7. Run \`npx @duct-sdk/sdk test\`. If it reports failures, fix capabilities.json (not the policy) and re-run.
|
|
36
|
+
8. Summarise what you added: how many actions, which ones have side effects, and anything you skipped.
|
|
37
|
+
|
|
38
|
+
Never invent endpoints that are not in the code. Never put secrets or real user data in these files.`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CapabilitiesFile } from "../core/project.js";
|
|
2
|
+
export type ApiSourceKind = "openapi" | "postman" | "curl";
|
|
3
|
+
export interface ApiSource {
|
|
4
|
+
kind: ApiSourceKind;
|
|
5
|
+
/** Path relative to the project root, or an absolute http(s) URL. */
|
|
6
|
+
location: string;
|
|
7
|
+
remote: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface LoadedApiSource {
|
|
10
|
+
source: ApiSource;
|
|
11
|
+
title?: string;
|
|
12
|
+
actions: CapabilitiesFile["actions"];
|
|
13
|
+
skipped: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const MAX_REMOTE_SPEC_BYTES: number;
|
|
16
|
+
/** Paths many frameworks serve their spec at, relative to the API origin. */
|
|
17
|
+
export declare const WELL_KNOWN_SPEC_PATHS: string[];
|
|
18
|
+
/** Find OpenAPI specs and Postman collections in the repo (bounded, skips build output). */
|
|
19
|
+
export declare function discoverLocalSources(root: string): Promise<ApiSource[]>;
|
|
20
|
+
export declare function classifySourceLocation(location: string): ApiSource;
|
|
21
|
+
/** Fetch a remote spec. Returns null when the URL does not serve an OpenAPI document. */
|
|
22
|
+
export declare function fetchRemoteSpec(url: string): Promise<string | null>;
|
|
23
|
+
/** Try the well-known spec paths on a running API. First hit wins. */
|
|
24
|
+
export declare function probeRemoteSpec(apiBaseUrl: string): Promise<string | null>;
|
|
25
|
+
/** Read a source and turn it into capability actions. Deterministic — no LLM. */
|
|
26
|
+
export declare function loadApiSource(root: string, source: ApiSource): Promise<LoadedApiSource>;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct-sdk/sdk — Find where your API is described (no LLM)
|
|
3
|
+
//
|
|
4
|
+
// OpenAPI / Swagger files in the repo, a spec your running API serves
|
|
5
|
+
// (FastAPI /openapi.json, Spring /v3/api-docs, NestJS /api-json, …),
|
|
6
|
+
// or a Postman collection / curl script.
|
|
7
|
+
// ============================================================
|
|
8
|
+
import * as fs from "fs/promises";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import { capabilityFromAction } from "../core/compile.js";
|
|
11
|
+
import { parseOpenApiSpec } from "./processors/openapi-parser.js";
|
|
12
|
+
import { parseCurlCollection } from "./processors/curl-parser.js";
|
|
13
|
+
const SKIP_DIRS = new Set([
|
|
14
|
+
"node_modules",
|
|
15
|
+
".git",
|
|
16
|
+
".next",
|
|
17
|
+
".nuxt",
|
|
18
|
+
".svelte-kit",
|
|
19
|
+
".turbo",
|
|
20
|
+
".vercel",
|
|
21
|
+
"dist",
|
|
22
|
+
"build",
|
|
23
|
+
"out",
|
|
24
|
+
"coverage",
|
|
25
|
+
"vendor",
|
|
26
|
+
"venv",
|
|
27
|
+
".venv",
|
|
28
|
+
"__pycache__",
|
|
29
|
+
"target",
|
|
30
|
+
"duct",
|
|
31
|
+
]);
|
|
32
|
+
const SPEC_NAME_RE = /^(openapi|swagger)([.\w-]*)\.(json|ya?ml)$/i;
|
|
33
|
+
const POSTMAN_RE = /\.postman_collection\.json$/i;
|
|
34
|
+
const MAX_WALK_DEPTH = 4;
|
|
35
|
+
const MAX_FILES_VISITED = 4000;
|
|
36
|
+
export const MAX_REMOTE_SPEC_BYTES = 5 * 1024 * 1024;
|
|
37
|
+
/** Paths many frameworks serve their spec at, relative to the API origin. */
|
|
38
|
+
export const WELL_KNOWN_SPEC_PATHS = [
|
|
39
|
+
"/openapi.json",
|
|
40
|
+
"/swagger.json",
|
|
41
|
+
"/v3/api-docs",
|
|
42
|
+
"/api-json",
|
|
43
|
+
"/api/openapi.json",
|
|
44
|
+
"/docs/openapi.json",
|
|
45
|
+
"/openapi.yaml",
|
|
46
|
+
"/swagger/v1/swagger.json",
|
|
47
|
+
];
|
|
48
|
+
async function looksLikeOpenApi(filePath) {
|
|
49
|
+
try {
|
|
50
|
+
const handle = await fs.open(filePath, "r");
|
|
51
|
+
try {
|
|
52
|
+
const buffer = Buffer.alloc(4096);
|
|
53
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
54
|
+
const head = buffer.subarray(0, bytesRead).toString("utf-8");
|
|
55
|
+
return /["']?(openapi|swagger)["']?\s*:/.test(head);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
await handle.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Find OpenAPI specs and Postman collections in the repo (bounded, skips build output). */
|
|
66
|
+
export async function discoverLocalSources(root) {
|
|
67
|
+
const found = [];
|
|
68
|
+
let visited = 0;
|
|
69
|
+
async function walk(dir, depth) {
|
|
70
|
+
if (depth > MAX_WALK_DEPTH || visited > MAX_FILES_VISITED)
|
|
71
|
+
return;
|
|
72
|
+
let entries;
|
|
73
|
+
try {
|
|
74
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
visited++;
|
|
81
|
+
if (visited > MAX_FILES_VISITED)
|
|
82
|
+
return;
|
|
83
|
+
const full = path.join(dir, entry.name);
|
|
84
|
+
if (entry.isDirectory()) {
|
|
85
|
+
if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith("."))
|
|
86
|
+
await walk(full, depth + 1);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!entry.isFile())
|
|
90
|
+
continue;
|
|
91
|
+
const relative = path.relative(root, full).split(path.sep).join("/");
|
|
92
|
+
if (POSTMAN_RE.test(entry.name)) {
|
|
93
|
+
found.push({ kind: "postman", location: relative, remote: false });
|
|
94
|
+
}
|
|
95
|
+
else if (SPEC_NAME_RE.test(entry.name) && (await looksLikeOpenApi(full))) {
|
|
96
|
+
found.push({ kind: "openapi", location: relative, remote: false });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
await walk(root, 0);
|
|
101
|
+
// Shallow paths first: the root spec is almost always the real one.
|
|
102
|
+
return found.sort((a, b) => a.location.split("/").length - b.location.split("/").length);
|
|
103
|
+
}
|
|
104
|
+
export function classifySourceLocation(location) {
|
|
105
|
+
const remote = /^https?:\/\//i.test(location);
|
|
106
|
+
const lower = location.toLowerCase();
|
|
107
|
+
if (!remote && (lower.endsWith(".sh") || lower.endsWith(".curl") || lower.endsWith(".txt"))) {
|
|
108
|
+
return { kind: "curl", location, remote };
|
|
109
|
+
}
|
|
110
|
+
if (POSTMAN_RE.test(lower) || (!remote && lower.endsWith(".json") && lower.includes("postman"))) {
|
|
111
|
+
return { kind: "postman", location, remote };
|
|
112
|
+
}
|
|
113
|
+
return { kind: "openapi", location, remote };
|
|
114
|
+
}
|
|
115
|
+
async function readCapped(response) {
|
|
116
|
+
const declared = Number(response.headers.get("content-length") ?? "0");
|
|
117
|
+
if (declared > MAX_REMOTE_SPEC_BYTES)
|
|
118
|
+
throw new Error("spec is larger than 5 MB");
|
|
119
|
+
const reader = response.body?.getReader();
|
|
120
|
+
if (!reader)
|
|
121
|
+
return "";
|
|
122
|
+
const chunks = [];
|
|
123
|
+
let total = 0;
|
|
124
|
+
for (;;) {
|
|
125
|
+
const { done, value } = await reader.read();
|
|
126
|
+
if (done)
|
|
127
|
+
break;
|
|
128
|
+
if (!value)
|
|
129
|
+
continue;
|
|
130
|
+
total += value.byteLength;
|
|
131
|
+
if (total > MAX_REMOTE_SPEC_BYTES) {
|
|
132
|
+
await reader.cancel();
|
|
133
|
+
throw new Error("spec is larger than 5 MB");
|
|
134
|
+
}
|
|
135
|
+
chunks.push(value);
|
|
136
|
+
}
|
|
137
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
138
|
+
}
|
|
139
|
+
/** Fetch a remote spec. Returns null when the URL does not serve an OpenAPI document. */
|
|
140
|
+
export async function fetchRemoteSpec(url) {
|
|
141
|
+
const parsed = new URL(url);
|
|
142
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:")
|
|
143
|
+
return null;
|
|
144
|
+
let response;
|
|
145
|
+
try {
|
|
146
|
+
response = await fetch(parsed, {
|
|
147
|
+
headers: { Accept: "application/json, application/yaml, text/yaml;q=0.9, */*;q=0.5" },
|
|
148
|
+
redirect: "follow",
|
|
149
|
+
signal: AbortSignal.timeout(6000),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
try {
|
|
157
|
+
await response.body?.cancel();
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
/* ignore */
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const body = await readCapped(response);
|
|
165
|
+
return /["']?(openapi|swagger)["']?\s*:/.test(body.slice(0, 4096)) ? body : null;
|
|
166
|
+
}
|
|
167
|
+
/** Try the well-known spec paths on a running API. First hit wins. */
|
|
168
|
+
export async function probeRemoteSpec(apiBaseUrl) {
|
|
169
|
+
let origin;
|
|
170
|
+
try {
|
|
171
|
+
const parsed = new URL(apiBaseUrl);
|
|
172
|
+
origin = `${parsed.origin}${parsed.pathname.replace(/\/$/, "")}`;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
for (const specPath of WELL_KNOWN_SPEC_PATHS) {
|
|
178
|
+
const candidate = `${origin}${specPath}`;
|
|
179
|
+
try {
|
|
180
|
+
if (await fetchRemoteSpec(candidate))
|
|
181
|
+
return candidate;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
/* try the next path */
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function toCapabilities(actions) {
|
|
190
|
+
const supported = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
191
|
+
const kept = actions.filter((action) => supported.has(action.method));
|
|
192
|
+
return {
|
|
193
|
+
actions: kept.map((action) => capabilityFromAction(action)),
|
|
194
|
+
skipped: actions.length - kept.length,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Read a source and turn it into capability actions. Deterministic — no LLM. */
|
|
198
|
+
export async function loadApiSource(root, source) {
|
|
199
|
+
let content;
|
|
200
|
+
let label;
|
|
201
|
+
if (source.remote) {
|
|
202
|
+
const fetched = await fetchRemoteSpec(source.location);
|
|
203
|
+
if (!fetched)
|
|
204
|
+
throw new Error(`${source.location} did not return an OpenAPI document`);
|
|
205
|
+
content = fetched;
|
|
206
|
+
const looksYaml = /^\s*(openapi|swagger)\s*:/m.test(fetched.slice(0, 512));
|
|
207
|
+
label = looksYaml ? "remote-openapi.yaml" : "remote-openapi.json";
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const full = path.resolve(root, source.location);
|
|
211
|
+
content = await fs.readFile(full, "utf-8");
|
|
212
|
+
label = source.location;
|
|
213
|
+
}
|
|
214
|
+
if (source.kind === "openapi") {
|
|
215
|
+
const parsed = await parseOpenApiSpec(content, label);
|
|
216
|
+
const { actions, skipped } = toCapabilities(parsed.actions);
|
|
217
|
+
return { source, title: parsed.title, actions, skipped };
|
|
218
|
+
}
|
|
219
|
+
const parsed = await parseCurlCollection(content, label);
|
|
220
|
+
const { actions, skipped } = toCapabilities(parsed.actions);
|
|
221
|
+
return { source, actions, skipped };
|
|
222
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export declare const DUCT_AUTH_FILE: string;
|
|
2
|
+
export interface DuctAuth {
|
|
3
|
+
token: string;
|
|
4
|
+
email: string;
|
|
5
|
+
companyId: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
apiBase?: string;
|
|
8
|
+
dashboardUrl?: string;
|
|
9
|
+
savedAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AccountShell {
|
|
12
|
+
id: string;
|
|
13
|
+
environment?: string;
|
|
14
|
+
status?: string;
|
|
15
|
+
registered_domain?: string;
|
|
16
|
+
registered_domains?: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare class CloudError extends Error {
|
|
19
|
+
readonly status?: number | undefined;
|
|
20
|
+
readonly code?: string | undefined;
|
|
21
|
+
readonly body?: unknown | undefined;
|
|
22
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined, body?: unknown | undefined);
|
|
23
|
+
}
|
|
24
|
+
export declare function readAuth(): Promise<DuctAuth | null>;
|
|
25
|
+
export declare function saveAuth(auth: DuctAuth): Promise<void>;
|
|
26
|
+
export declare function clearAuth(): Promise<void>;
|
|
27
|
+
/** API key for this run: DUCT_API_KEY (CI) wins over the saved login. */
|
|
28
|
+
export declare function resolveApiKey(auth: DuctAuth | null): string | null;
|
|
29
|
+
/** Validate a dk_live_ key against the first auth base that answers, then persist it. */
|
|
30
|
+
export declare function loginWithKey(rawKey: string, existing: DuctAuth | null): Promise<DuctAuth>;
|
|
31
|
+
export declare function listAccountShells(auth: DuctAuth | null, apiKey: string): Promise<AccountShell[]>;
|
|
32
|
+
export interface ProvisionedShell {
|
|
33
|
+
shell_id: string;
|
|
34
|
+
environment: string;
|
|
35
|
+
registered_domains?: string[];
|
|
36
|
+
/** Shown once; never logged or returned to an assistant. */
|
|
37
|
+
secret_key: string;
|
|
38
|
+
}
|
|
39
|
+
/** Create a shell. A duplicate name raises CloudError with code shell_exists (and the existing id in body). */
|
|
40
|
+
export declare function provisionShell(auth: DuctAuth | null, apiKey: string, name: string, domains: string[]): Promise<ProvisionedShell>;
|
|
41
|
+
/**
|
|
42
|
+
* The full live manifest (owner-only), or null when nothing has been pushed yet.
|
|
43
|
+
* The newest push-timeline entry is what is live (pushes, rollbacks and dashboard network
|
|
44
|
+
* changes all append to it); its snapshot carries every enforcement field, unlike the
|
|
45
|
+
* public GET /manifest view which drops policy fields such as approveIf and agentPermissions.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fetchLiveFullManifest(auth: DuctAuth | null, apiKey: string, shellId: string): Promise<Record<string, unknown> | null>;
|
|
48
|
+
/** Public live manifest (filtered view), or null when nothing has been pushed yet. */
|
|
49
|
+
export declare function fetchLiveManifest(auth: DuctAuth | null, apiKey: string, shellId: string): Promise<Record<string, unknown> | null>;
|
|
50
|
+
export interface PushResult {
|
|
51
|
+
config_checksum?: string;
|
|
52
|
+
push_hash?: string;
|
|
53
|
+
side_effect_review_warnings?: unknown[];
|
|
54
|
+
}
|
|
55
|
+
export declare function pushManifest(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown>, opts?: {
|
|
56
|
+
forceDashboardNetworkOverride?: boolean;
|
|
57
|
+
}): Promise<PushResult>;
|
|
58
|
+
/**
|
|
59
|
+
* A policy decision depends on the action being checked and the shell-wide settings, not on
|
|
60
|
+
* every other action. Sending only the actions the cases name keeps check requests small
|
|
61
|
+
* however large the API is.
|
|
62
|
+
*/
|
|
63
|
+
export declare function configForCases(config: Record<string, unknown>, cases: PolicyCheckCase[]): Record<string, unknown>;
|
|
64
|
+
/** The reachability probe only needs where the API lives. */
|
|
65
|
+
export declare function upstreamSlice(config: Record<string, unknown>): Record<string, unknown>;
|
|
66
|
+
export interface PolicyCheckCase {
|
|
67
|
+
name?: string;
|
|
68
|
+
as: "agent" | "user" | "guest";
|
|
69
|
+
action: string;
|
|
70
|
+
params?: Record<string, unknown>;
|
|
71
|
+
withUserConsent?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface PolicyCheckResult {
|
|
74
|
+
name?: string;
|
|
75
|
+
as: PolicyCheckCase["as"];
|
|
76
|
+
action: string;
|
|
77
|
+
decision: "allow" | "deny" | "approval" | "unknown_action";
|
|
78
|
+
reason: string;
|
|
79
|
+
source?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function checkPolicy(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown> | undefined, cases: PolicyCheckCase[]): Promise<PolicyCheckResult[]>;
|
|
82
|
+
export interface UpstreamCheckResult {
|
|
83
|
+
ok: boolean;
|
|
84
|
+
code: string;
|
|
85
|
+
origin?: string;
|
|
86
|
+
status?: number;
|
|
87
|
+
latencyMs?: number;
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
export declare function checkUpstream(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown> | undefined): Promise<UpstreamCheckResult>;
|
|
91
|
+
export interface ShellWebhooks {
|
|
92
|
+
deeplinkCallback: string;
|
|
93
|
+
eventStream: string;
|
|
94
|
+
consentCallback: string;
|
|
95
|
+
identityUrl: string;
|
|
96
|
+
secretConfigured: boolean;
|
|
97
|
+
secretPreview: string | null;
|
|
98
|
+
}
|
|
99
|
+
export declare function getShellWebhooks(auth: DuctAuth | null, apiKey: string, shellId: string): Promise<ShellWebhooks>;
|
|
100
|
+
export type WebhookPatch = Partial<Record<"deeplinkCallback" | "eventStream" | "consentCallback" | "identityUrl" | "secret", string>>;
|
|
101
|
+
export declare function patchShellWebhooks(auth: DuctAuth | null, apiKey: string, shellId: string, patch: WebhookPatch): Promise<ShellWebhooks>;
|
|
102
|
+
export interface ConnectionCheck {
|
|
103
|
+
target: "api" | "events" | "deeplinks" | "identity" | "consent";
|
|
104
|
+
label: string;
|
|
105
|
+
configured: boolean;
|
|
106
|
+
ok: boolean;
|
|
107
|
+
url?: string;
|
|
108
|
+
status?: number;
|
|
109
|
+
latency_ms?: number;
|
|
110
|
+
problem?: string;
|
|
111
|
+
fix?: string;
|
|
112
|
+
}
|
|
113
|
+
export declare function runConnectionChecks(auth: DuctAuth | null, apiKey: string, shellId: string, targets?: ConnectionCheck["target"][]): Promise<{
|
|
114
|
+
ok: boolean;
|
|
115
|
+
results: ConnectionCheck[];
|
|
116
|
+
}>;
|
|
117
|
+
export interface PartnerProfile {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
label: string;
|
|
121
|
+
scopes: string[];
|
|
122
|
+
active?: boolean;
|
|
123
|
+
last_issued_at?: string | null;
|
|
124
|
+
}
|
|
125
|
+
export declare function listPartnerProfiles(auth: DuctAuth | null, apiKey: string, shellId: string): Promise<PartnerProfile[]>;
|
|
126
|
+
export declare function createPartnerProfile(auth: DuctAuth | null, apiKey: string, shellId: string, profile: {
|
|
127
|
+
name: string;
|
|
128
|
+
label: string;
|
|
129
|
+
scopes: string[];
|
|
130
|
+
}): Promise<{
|
|
131
|
+
name: string;
|
|
132
|
+
profile_id: string;
|
|
133
|
+
}>;
|