@duct-sdk/sdk 0.2.2 → 0.3.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 +45 -0
- package/README.md +9 -1
- package/dist/adapters/next/shell.d.ts +2 -141
- package/dist/adapters/next/shell.js +6 -342
- package/dist/adapters/react/shell.d.ts +23 -4
- package/dist/adapters/react/shell.js +185 -35
- package/dist/cli/agents/api-agent.js +1 -1
- package/dist/cli/agents/pipeline.js +128 -72
- package/dist/cli/generators/shell.js +9 -25
- package/dist/cli/index.js +2 -2
- package/dist/cli/init.js +5 -2
- package/dist/cli/processors/openapi-parser.d.ts +27 -0
- package/dist/cli/processors/openapi-parser.js +309 -0
- package/dist/cli/processors/postprocess.js +1 -1
- package/dist/core/config.d.ts +35 -0
- package/dist/core/config.js +7 -0
- package/dist/core/limits.d.ts +5 -0
- package/dist/core/limits.js +5 -0
- package/dist/core/types.d.ts +44 -2
- package/dist/core/types.js +23 -0
- package/package.json +3 -2
package/dist/cli/index.js
CHANGED
|
@@ -326,7 +326,7 @@ program
|
|
|
326
326
|
});
|
|
327
327
|
// Topological order for action dependsOn chains (max depth 4).
|
|
328
328
|
function buildDependsOnOrder(targetId, actions, visited = new Set()) {
|
|
329
|
-
if (visited.has(targetId) || visited.size >
|
|
329
|
+
if (visited.has(targetId) || visited.size > 8)
|
|
330
330
|
return [];
|
|
331
331
|
visited.add(targetId);
|
|
332
332
|
const action = actions.find((a) => a.id === targetId);
|
|
@@ -385,7 +385,7 @@ function computePrecomputedWorkflows(config) {
|
|
|
385
385
|
workflows.push({
|
|
386
386
|
id: wfId,
|
|
387
387
|
name: `Execute ${actionLabel}`,
|
|
388
|
-
steps: order.slice(0,
|
|
388
|
+
steps: order.slice(0, 8).map((id) => ({ action_id: id })),
|
|
389
389
|
intent_patterns: action.description ? [action.description] : [actionLabel],
|
|
390
390
|
});
|
|
391
391
|
}
|
package/dist/cli/init.js
CHANGED
|
@@ -598,7 +598,10 @@ export async function runInit(opts = {}) {
|
|
|
598
598
|
process.exit(1);
|
|
599
599
|
}
|
|
600
600
|
// ---- Step 0.5: Check LLM credentials and prompt if missing ----
|
|
601
|
-
|
|
601
|
+
// Skip the LLM check when --api-spec is provided: the deterministic parser
|
|
602
|
+
// does not require any LLM key, so the pipeline can run without credentials.
|
|
603
|
+
const hasApiSpec = Boolean(opts.apiSpec);
|
|
604
|
+
if (!noAgents && !hasApiSpec) {
|
|
602
605
|
const canRunAgents = await checkLlmCredentialsAndPrompt(noAgents, yes);
|
|
603
606
|
if (!canRunAgents) {
|
|
604
607
|
noAgents = true;
|
|
@@ -810,7 +813,7 @@ export async function runInit(opts = {}) {
|
|
|
810
813
|
if (apiSpecPath) {
|
|
811
814
|
try {
|
|
812
815
|
apiSpecContent = await fs.readFile(apiSpecPath, "utf-8");
|
|
813
|
-
console.log(chalk.gray(` Using OpenAPI spec: ${path.relative(cwd, apiSpecPath)} —
|
|
816
|
+
console.log(chalk.gray(` Using OpenAPI spec: ${path.relative(cwd, apiSpecPath)} — deterministic parse, no LLM needed\n`));
|
|
814
817
|
}
|
|
815
818
|
catch {
|
|
816
819
|
console.log(chalk.yellow(` ⚠ Could not read --api-spec file: ${opts.apiSpec}. Falling back to agent scan.\n`));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ActionManifest, RouteManifest } from "../../core/types.js";
|
|
2
|
+
export interface OpenApiParseResult {
|
|
3
|
+
actions: ActionManifest[];
|
|
4
|
+
routes: RouteManifest[];
|
|
5
|
+
/** Version string from the spec (e.g., "3.0.3" or "2.0") */
|
|
6
|
+
specVersion: string;
|
|
7
|
+
/** Total number of operations found in the spec */
|
|
8
|
+
operationCount: number;
|
|
9
|
+
/** Title from spec info block */
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parse an OpenAPI 3.x or Swagger 2.x spec file deterministically.
|
|
14
|
+
* No LLM is required — all results come directly from the spec structure.
|
|
15
|
+
*
|
|
16
|
+
* Rules applied:
|
|
17
|
+
* - GET operations → agentAccessible remains false (review step decides)
|
|
18
|
+
* - POST/PUT/PATCH/DELETE → sideEffects: true
|
|
19
|
+
* - Operations with operationId → confidence: 1.0
|
|
20
|
+
* - Operations without operationId → confidence: 0.95
|
|
21
|
+
* - Sensitivity inferred from path + description keywords
|
|
22
|
+
* - Internal Duct/NextAuth routes are excluded automatically
|
|
23
|
+
*
|
|
24
|
+
* @param content Raw spec content string (JSON or YAML)
|
|
25
|
+
* @param filePath File path — used for evidence labels and YAML detection
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseOpenApiSpec(content: string, filePath?: string): Promise<OpenApiParseResult>;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — Deterministic OpenAPI Spec Parser
|
|
3
|
+
// Parses OpenAPI 3.x / Swagger 2.x specs into ActionManifest[]
|
|
4
|
+
// and RouteManifest[] without requiring an LLM.
|
|
5
|
+
//
|
|
6
|
+
// Supported formats: JSON (.json) and YAML (.yaml / .yml)
|
|
7
|
+
// YAML requires the `yaml` npm package (listed in dependencies).
|
|
8
|
+
// ============================================================
|
|
9
|
+
// ----------------------------------------------------------------
|
|
10
|
+
// Constants
|
|
11
|
+
// ----------------------------------------------------------------
|
|
12
|
+
const SUPPORTED_METHODS = ["get", "post", "put", "patch", "delete", "head"];
|
|
13
|
+
const SIDE_EFFECT_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
14
|
+
const VALID_SENSITIVITY_LEVELS = new Set(["none", "low", "medium", "high", "critical"]);
|
|
15
|
+
// ----------------------------------------------------------------
|
|
16
|
+
// Helpers
|
|
17
|
+
// ----------------------------------------------------------------
|
|
18
|
+
function toSnakeCase(str) {
|
|
19
|
+
return str
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/[^a-z0-9]/g, "_")
|
|
22
|
+
.replace(/_+/g, "_")
|
|
23
|
+
.replace(/^_|_$/g, "");
|
|
24
|
+
}
|
|
25
|
+
function deriveActionId(operationId, method, path) {
|
|
26
|
+
if (operationId?.trim())
|
|
27
|
+
return toSnakeCase(operationId.trim());
|
|
28
|
+
// Derive from method + path: GET /users/{userId}/orders → get_users_user_id_orders
|
|
29
|
+
const pathPart = path
|
|
30
|
+
.replace(/\{([^}]+)\}/g, (_, name) => name)
|
|
31
|
+
.replace(/[^a-zA-Z0-9]+/g, "_")
|
|
32
|
+
.replace(/^_|_$/g, "");
|
|
33
|
+
return toSnakeCase(`${method}_${pathPart}`);
|
|
34
|
+
}
|
|
35
|
+
function inferSensitivityLevel(path, description, xDuctSensitivity) {
|
|
36
|
+
if (xDuctSensitivity && VALID_SENSITIVITY_LEVELS.has(xDuctSensitivity)) {
|
|
37
|
+
return xDuctSensitivity;
|
|
38
|
+
}
|
|
39
|
+
const combined = `${path} ${description}`.toLowerCase();
|
|
40
|
+
if (/password|secret|ssn|credit[-.]?card|billing|private.key|api.key/.test(combined))
|
|
41
|
+
return "high";
|
|
42
|
+
if (/admin|sudo|superuser|impersonate/.test(combined))
|
|
43
|
+
return "high";
|
|
44
|
+
if (/payment|bank|invoice|subscription|financial.?(data|record|statement|transaction)/.test(combined))
|
|
45
|
+
return "medium";
|
|
46
|
+
if (/email|phone|address|profile|personal|pii/.test(combined))
|
|
47
|
+
return "medium";
|
|
48
|
+
return "low";
|
|
49
|
+
}
|
|
50
|
+
function mapJsonType(type) {
|
|
51
|
+
const t = Array.isArray(type)
|
|
52
|
+
? (type.find((x) => x !== "null") ?? "string")
|
|
53
|
+
: (type ?? "string");
|
|
54
|
+
switch (t) {
|
|
55
|
+
case "integer":
|
|
56
|
+
case "number":
|
|
57
|
+
return "number";
|
|
58
|
+
case "boolean":
|
|
59
|
+
return "boolean";
|
|
60
|
+
case "object":
|
|
61
|
+
return "object";
|
|
62
|
+
case "array":
|
|
63
|
+
return "array";
|
|
64
|
+
default:
|
|
65
|
+
return "string";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function normalizePath(rawPath) {
|
|
69
|
+
return rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
|
|
70
|
+
}
|
|
71
|
+
function isInternalRoute(path) {
|
|
72
|
+
const p = path.toLowerCase();
|
|
73
|
+
return (p.startsWith("/api/auth/") ||
|
|
74
|
+
p.startsWith("/api/duct/") ||
|
|
75
|
+
p.startsWith("/_next/") ||
|
|
76
|
+
p === "/_next" ||
|
|
77
|
+
p.startsWith("/api/_"));
|
|
78
|
+
}
|
|
79
|
+
function isValidSpecPath(path) {
|
|
80
|
+
if (!path.startsWith("/"))
|
|
81
|
+
return false;
|
|
82
|
+
if (/\s/.test(path))
|
|
83
|
+
return false;
|
|
84
|
+
// Allow alphanumeric, hyphens, dots, slashes, colons, brackets (OpenAPI params)
|
|
85
|
+
return /^[\w\-./:{[\]()]+$/.test(path);
|
|
86
|
+
}
|
|
87
|
+
function operationHasSecurityRequirement(operation, spec) {
|
|
88
|
+
// Explicit empty array on operation = "no auth required" override
|
|
89
|
+
if (Array.isArray(operation.security)) {
|
|
90
|
+
return operation.security.length > 0;
|
|
91
|
+
}
|
|
92
|
+
// Fall back to global security definitions presence
|
|
93
|
+
const hasGlobalSchemes = (spec.components?.securitySchemes != null &&
|
|
94
|
+
Object.keys(spec.components.securitySchemes).length > 0) ||
|
|
95
|
+
(spec.securityDefinitions != null &&
|
|
96
|
+
Object.keys(spec.securityDefinitions).length > 0);
|
|
97
|
+
return hasGlobalSchemes;
|
|
98
|
+
}
|
|
99
|
+
function extractParams(parameters, requestBody) {
|
|
100
|
+
const params = [];
|
|
101
|
+
let inputSchema;
|
|
102
|
+
for (const param of parameters) {
|
|
103
|
+
if (param.in === "header" || param.in === "cookie")
|
|
104
|
+
continue;
|
|
105
|
+
// Swagger 2.x body/formData parameters — extract schema properties
|
|
106
|
+
if (param.in === "body" || param.in === "formData") {
|
|
107
|
+
if (param.schema?.properties) {
|
|
108
|
+
const requiredFields = new Set(param.schema.required ?? []);
|
|
109
|
+
inputSchema = param.schema;
|
|
110
|
+
for (const [name, propSchema] of Object.entries(param.schema.properties)) {
|
|
111
|
+
if (params.some((p) => p.name === name))
|
|
112
|
+
continue;
|
|
113
|
+
params.push({
|
|
114
|
+
name,
|
|
115
|
+
type: mapJsonType(propSchema.type),
|
|
116
|
+
required: requiredFields.has(name),
|
|
117
|
+
description: propSchema.description,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
params.push({
|
|
124
|
+
name: param.name,
|
|
125
|
+
type: mapJsonType(param.schema?.type ?? param.type),
|
|
126
|
+
required: param.required ?? (param.in === "path"),
|
|
127
|
+
description: param.description,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// OpenAPI 3.x requestBody
|
|
131
|
+
if (requestBody?.content) {
|
|
132
|
+
const jsonContent = requestBody.content["application/json"];
|
|
133
|
+
const schema = jsonContent?.schema;
|
|
134
|
+
if (schema) {
|
|
135
|
+
inputSchema = schema;
|
|
136
|
+
if (schema.properties) {
|
|
137
|
+
const requiredFields = new Set(schema.required ?? []);
|
|
138
|
+
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
139
|
+
if (params.some((p) => p.name === name))
|
|
140
|
+
continue;
|
|
141
|
+
params.push({
|
|
142
|
+
name,
|
|
143
|
+
type: mapJsonType(propSchema.type),
|
|
144
|
+
required: requiredFields.has(name) || (requestBody.required ?? false),
|
|
145
|
+
description: propSchema.description,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { params, inputSchema };
|
|
152
|
+
}
|
|
153
|
+
// ----------------------------------------------------------------
|
|
154
|
+
// YAML / JSON content parser
|
|
155
|
+
// ----------------------------------------------------------------
|
|
156
|
+
async function parseContent(content, filePath) {
|
|
157
|
+
const lowerPath = filePath.toLowerCase();
|
|
158
|
+
const isYaml = lowerPath.endsWith(".yaml") || lowerPath.endsWith(".yml");
|
|
159
|
+
if (isYaml) {
|
|
160
|
+
try {
|
|
161
|
+
// Dynamic import so the yaml package is only loaded when needed
|
|
162
|
+
const yamlModule = await import("yaml");
|
|
163
|
+
const parsed = yamlModule.parse(content);
|
|
164
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
165
|
+
return parsed;
|
|
166
|
+
}
|
|
167
|
+
throw new Error("YAML parse produced a non-object value");
|
|
168
|
+
}
|
|
169
|
+
catch (yamlErr) {
|
|
170
|
+
// Attempt JSON fallback in case the file extension is misleading
|
|
171
|
+
try {
|
|
172
|
+
return JSON.parse(content);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
// Re-throw the original YAML error for a clear message
|
|
176
|
+
throw yamlErr;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// JSON (or unrecognized extension — try JSON first)
|
|
181
|
+
return JSON.parse(content);
|
|
182
|
+
}
|
|
183
|
+
// ----------------------------------------------------------------
|
|
184
|
+
// parseOpenApiSpec — main entry point
|
|
185
|
+
// ----------------------------------------------------------------
|
|
186
|
+
/**
|
|
187
|
+
* Parse an OpenAPI 3.x or Swagger 2.x spec file deterministically.
|
|
188
|
+
* No LLM is required — all results come directly from the spec structure.
|
|
189
|
+
*
|
|
190
|
+
* Rules applied:
|
|
191
|
+
* - GET operations → agentAccessible remains false (review step decides)
|
|
192
|
+
* - POST/PUT/PATCH/DELETE → sideEffects: true
|
|
193
|
+
* - Operations with operationId → confidence: 1.0
|
|
194
|
+
* - Operations without operationId → confidence: 0.95
|
|
195
|
+
* - Sensitivity inferred from path + description keywords
|
|
196
|
+
* - Internal Duct/NextAuth routes are excluded automatically
|
|
197
|
+
*
|
|
198
|
+
* @param content Raw spec content string (JSON or YAML)
|
|
199
|
+
* @param filePath File path — used for evidence labels and YAML detection
|
|
200
|
+
*/
|
|
201
|
+
export async function parseOpenApiSpec(content, filePath = "openapi.json") {
|
|
202
|
+
let raw;
|
|
203
|
+
try {
|
|
204
|
+
raw = await parseContent(content, filePath);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
throw new Error(`Could not parse OpenAPI spec "${filePath}": ${err instanceof Error ? err.message : String(err)}`);
|
|
208
|
+
}
|
|
209
|
+
const spec = raw;
|
|
210
|
+
const specVersion = spec.openapi ?? spec.swagger ?? "unknown";
|
|
211
|
+
const title = spec.info?.title;
|
|
212
|
+
const actions = [];
|
|
213
|
+
const routes = [];
|
|
214
|
+
const seen = new Set(); // deduplicate by METHOD:path
|
|
215
|
+
let operationCount = 0;
|
|
216
|
+
const paths = (spec.paths ?? {});
|
|
217
|
+
for (const [rawPath, pathItem] of Object.entries(paths)) {
|
|
218
|
+
if (typeof pathItem !== "object" || pathItem === null)
|
|
219
|
+
continue;
|
|
220
|
+
const normalizedPath = normalizePath(rawPath);
|
|
221
|
+
if (!isValidSpecPath(normalizedPath))
|
|
222
|
+
continue;
|
|
223
|
+
if (isInternalRoute(normalizedPath))
|
|
224
|
+
continue;
|
|
225
|
+
// Path-level parameters are merged with each operation's own params
|
|
226
|
+
const pathLevelParams = Array.isArray(pathItem.parameters)
|
|
227
|
+
? pathItem.parameters
|
|
228
|
+
: [];
|
|
229
|
+
for (const method of SUPPORTED_METHODS) {
|
|
230
|
+
const operation = pathItem[method];
|
|
231
|
+
if (!operation || typeof operation !== "object")
|
|
232
|
+
continue;
|
|
233
|
+
operationCount++;
|
|
234
|
+
const upperMethod = method.toUpperCase();
|
|
235
|
+
// Merge path-level params (operation params override by name+in)
|
|
236
|
+
const opParams = Array.isArray(operation.parameters)
|
|
237
|
+
? operation.parameters
|
|
238
|
+
: [];
|
|
239
|
+
const mergedParams = [...pathLevelParams];
|
|
240
|
+
for (const p of opParams) {
|
|
241
|
+
const idx = mergedParams.findIndex((mp) => mp.name === p.name && mp.in === p.in);
|
|
242
|
+
if (idx >= 0)
|
|
243
|
+
mergedParams[idx] = p;
|
|
244
|
+
else
|
|
245
|
+
mergedParams.push(p);
|
|
246
|
+
}
|
|
247
|
+
const description = operation.summary ??
|
|
248
|
+
operation.description ??
|
|
249
|
+
`${upperMethod} ${normalizedPath}`;
|
|
250
|
+
const { params, inputSchema } = extractParams(mergedParams, operation.requestBody);
|
|
251
|
+
const id = deriveActionId(operation.operationId, method, normalizedPath);
|
|
252
|
+
const sideEffects = SIDE_EFFECT_METHODS.has(upperMethod);
|
|
253
|
+
const confidence = operation.operationId?.trim() ? 1.0 : 0.95;
|
|
254
|
+
const sensitivityLevel = inferSensitivityLevel(normalizedPath, description, operation["x-duct-sensitivity"]);
|
|
255
|
+
const requiresAuth = operationHasSecurityRequirement(operation, spec);
|
|
256
|
+
const dedupeKey = `${upperMethod}:${normalizedPath}`;
|
|
257
|
+
if (seen.has(dedupeKey))
|
|
258
|
+
continue;
|
|
259
|
+
seen.add(dedupeKey);
|
|
260
|
+
const actionName = operation.summary ??
|
|
261
|
+
id.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
262
|
+
actions.push({
|
|
263
|
+
id,
|
|
264
|
+
name: actionName,
|
|
265
|
+
description,
|
|
266
|
+
method: upperMethod,
|
|
267
|
+
path: normalizedPath,
|
|
268
|
+
agentAccessible: false, // always off by default; interactive review step sets this
|
|
269
|
+
sideEffects,
|
|
270
|
+
sensitivityLevel,
|
|
271
|
+
params,
|
|
272
|
+
inputSchema,
|
|
273
|
+
requiresAuth,
|
|
274
|
+
confidence,
|
|
275
|
+
evidence: [`${filePath}#/paths${rawPath}/${method}`],
|
|
276
|
+
});
|
|
277
|
+
// Emit a RouteManifest for GET endpoints (navigable by the shell)
|
|
278
|
+
if (upperMethod === "GET") {
|
|
279
|
+
routes.push({
|
|
280
|
+
path: normalizedPath,
|
|
281
|
+
name: actionName,
|
|
282
|
+
description,
|
|
283
|
+
params: mergedParams
|
|
284
|
+
.filter((p) => p.in === "path")
|
|
285
|
+
.map((p) => ({
|
|
286
|
+
name: p.name,
|
|
287
|
+
type: "string",
|
|
288
|
+
required: true,
|
|
289
|
+
description: p.description,
|
|
290
|
+
})),
|
|
291
|
+
queryParams: mergedParams
|
|
292
|
+
.filter((p) => p.in === "query")
|
|
293
|
+
.map((p) => ({
|
|
294
|
+
name: p.name,
|
|
295
|
+
type: "string",
|
|
296
|
+
required: p.required ?? false,
|
|
297
|
+
description: p.description,
|
|
298
|
+
})),
|
|
299
|
+
uiStateHint: "list",
|
|
300
|
+
requiresAuth,
|
|
301
|
+
deeplinkable: false,
|
|
302
|
+
confidence,
|
|
303
|
+
evidence: [`${filePath}#/paths${rawPath}/get`],
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return { actions, routes, specVersion, operationCount, title };
|
|
309
|
+
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -286,6 +286,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
286
286
|
launcherText: z.ZodOptional<z.ZodString>;
|
|
287
287
|
welcomeMessage: z.ZodOptional<z.ZodString>;
|
|
288
288
|
hideLauncher: z.ZodOptional<z.ZodBoolean>;
|
|
289
|
+
preset: z.ZodOptional<z.ZodEnum<["tall", "square", "large"]>>;
|
|
290
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
291
|
+
theme: z.ZodOptional<z.ZodEnum<["light", "dark", "system"]>>;
|
|
292
|
+
width: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
293
|
+
height: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
|
294
|
+
logoUrl: z.ZodOptional<z.ZodString>;
|
|
295
|
+
customCSS: z.ZodOptional<z.ZodString>;
|
|
289
296
|
}, "strip", z.ZodTypeAny, {
|
|
290
297
|
primaryColor?: string | undefined;
|
|
291
298
|
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left" | undefined;
|
|
@@ -293,6 +300,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
293
300
|
launcherText?: string | undefined;
|
|
294
301
|
welcomeMessage?: string | undefined;
|
|
295
302
|
hideLauncher?: boolean | undefined;
|
|
303
|
+
preset?: "tall" | "square" | "large" | undefined;
|
|
304
|
+
placeholder?: string | undefined;
|
|
305
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
306
|
+
width?: string | number | undefined;
|
|
307
|
+
height?: string | number | undefined;
|
|
308
|
+
logoUrl?: string | undefined;
|
|
309
|
+
customCSS?: string | undefined;
|
|
296
310
|
}, {
|
|
297
311
|
primaryColor?: string | undefined;
|
|
298
312
|
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left" | undefined;
|
|
@@ -300,6 +314,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
300
314
|
launcherText?: string | undefined;
|
|
301
315
|
welcomeMessage?: string | undefined;
|
|
302
316
|
hideLauncher?: boolean | undefined;
|
|
317
|
+
preset?: "tall" | "square" | "large" | undefined;
|
|
318
|
+
placeholder?: string | undefined;
|
|
319
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
320
|
+
width?: string | number | undefined;
|
|
321
|
+
height?: string | number | undefined;
|
|
322
|
+
logoUrl?: string | undefined;
|
|
323
|
+
customCSS?: string | undefined;
|
|
303
324
|
}>>;
|
|
304
325
|
}, "strip", z.ZodTypeAny, {
|
|
305
326
|
auth: {
|
|
@@ -391,6 +412,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
391
412
|
launcherText?: string | undefined;
|
|
392
413
|
welcomeMessage?: string | undefined;
|
|
393
414
|
hideLauncher?: boolean | undefined;
|
|
415
|
+
preset?: "tall" | "square" | "large" | undefined;
|
|
416
|
+
placeholder?: string | undefined;
|
|
417
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
418
|
+
width?: string | number | undefined;
|
|
419
|
+
height?: string | number | undefined;
|
|
420
|
+
logoUrl?: string | undefined;
|
|
421
|
+
customCSS?: string | undefined;
|
|
394
422
|
} | undefined;
|
|
395
423
|
}, {
|
|
396
424
|
auth: {
|
|
@@ -482,6 +510,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
482
510
|
launcherText?: string | undefined;
|
|
483
511
|
welcomeMessage?: string | undefined;
|
|
484
512
|
hideLauncher?: boolean | undefined;
|
|
513
|
+
preset?: "tall" | "square" | "large" | undefined;
|
|
514
|
+
placeholder?: string | undefined;
|
|
515
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
516
|
+
width?: string | number | undefined;
|
|
517
|
+
height?: string | number | undefined;
|
|
518
|
+
logoUrl?: string | undefined;
|
|
519
|
+
customCSS?: string | undefined;
|
|
485
520
|
} | undefined;
|
|
486
521
|
}>;
|
|
487
522
|
export type ValidatedDuctConfig = z.infer<typeof DuctConfigSchema>;
|
package/dist/core/config.js
CHANGED
|
@@ -134,6 +134,13 @@ const WidgetConfigSchema = z.object({
|
|
|
134
134
|
launcherText: z.string().optional(),
|
|
135
135
|
welcomeMessage: z.string().optional(),
|
|
136
136
|
hideLauncher: z.boolean().optional(),
|
|
137
|
+
preset: z.enum(["tall", "square", "large"]).optional(),
|
|
138
|
+
placeholder: z.string().optional(),
|
|
139
|
+
theme: z.enum(["light", "dark", "system"]).optional(),
|
|
140
|
+
width: z.union([z.number(), z.string()]).optional(),
|
|
141
|
+
height: z.union([z.number(), z.string()]).optional(),
|
|
142
|
+
logoUrl: z.string().optional(),
|
|
143
|
+
customCSS: z.string().optional(),
|
|
137
144
|
});
|
|
138
145
|
const ProductConfigSchema = z.object({
|
|
139
146
|
name: z.string().min(1),
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Default agent loop ceilings used in widget manifest defaults. */
|
|
2
|
+
export declare const DEFAULT_MAX_TOOL_ITERATIONS = 12;
|
|
3
|
+
export declare const DEFAULT_MAX_PLAN_STEPS = 8;
|
|
4
|
+
export declare const HARD_CEILING_TOOL_ITERATIONS = 25;
|
|
5
|
+
export declare const HARD_CEILING_PLAN_STEPS = 12;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -192,6 +192,31 @@ export interface AgentPermissions {
|
|
|
192
192
|
/** Allowed actions (action IDs) */
|
|
193
193
|
allowedActions?: string[];
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Shell panel size/shape presets.
|
|
197
|
+
* - 'tall' — vertical rectangle (default)
|
|
198
|
+
* - 'square' — squarish panel (Copilot-style)
|
|
199
|
+
* - 'large' — spacious desktop-first panel
|
|
200
|
+
*/
|
|
201
|
+
export type ShellPreset = 'tall' | 'square' | 'large';
|
|
202
|
+
/** Pixel dimensions for each shell preset. Single source of truth. */
|
|
203
|
+
export declare const SHELL_PRESET_DIMENSIONS: Record<ShellPreset, {
|
|
204
|
+
width: number;
|
|
205
|
+
height: number;
|
|
206
|
+
}>;
|
|
207
|
+
export declare const DEFAULT_SHELL_PRESET: ShellPreset;
|
|
208
|
+
/**
|
|
209
|
+
* Resolve the effective panel dimensions from a preset and/or explicit
|
|
210
|
+
* width/height. Explicit width/height win only when no preset is provided.
|
|
211
|
+
*/
|
|
212
|
+
export declare function resolveShellDimensions(opts: {
|
|
213
|
+
preset?: ShellPreset;
|
|
214
|
+
width?: number | string;
|
|
215
|
+
height?: number | string;
|
|
216
|
+
}): {
|
|
217
|
+
width: number | string;
|
|
218
|
+
height: number | string;
|
|
219
|
+
};
|
|
195
220
|
export interface WidgetConfig {
|
|
196
221
|
/** Primary brand color (hex) */
|
|
197
222
|
primaryColor?: string;
|
|
@@ -209,9 +234,17 @@ export interface WidgetConfig {
|
|
|
209
234
|
hideLauncher?: boolean;
|
|
210
235
|
/** Custom CSS injected into the shell iframe (scoped) */
|
|
211
236
|
customCSS?: string;
|
|
212
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* Size/shape preset for the shell panel. Preferred over raw width/height.
|
|
239
|
+
* - 'tall' — vertical rectangle (default), good for long chats
|
|
240
|
+
* - 'square' — Copilot-style squarish panel
|
|
241
|
+
* - 'large' — spacious panel for desktop-first products
|
|
242
|
+
* When omitted, falls back to width/height (or the 'tall' default).
|
|
243
|
+
*/
|
|
244
|
+
preset?: ShellPreset;
|
|
245
|
+
/** iframe width — default: 380. Ignored when `preset` is set. */
|
|
213
246
|
width?: number | string;
|
|
214
|
-
/** iframe height — default: 620 */
|
|
247
|
+
/** iframe height — default: 620. Ignored when `preset` is set. */
|
|
215
248
|
height?: number | string;
|
|
216
249
|
/** URL to your product logo (shown in empty state) */
|
|
217
250
|
logoUrl?: string;
|
|
@@ -221,6 +254,15 @@ export interface WidgetConfig {
|
|
|
221
254
|
* Set to 0 to disable compaction entirely.
|
|
222
255
|
*/
|
|
223
256
|
compactionTurns?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Max tool-call loop iterations per user turn (default 12, hard ceiling 25).
|
|
259
|
+
* Loop also stops on duplicate invocations, stagnation, or wall-clock budget.
|
|
260
|
+
*/
|
|
261
|
+
maxToolIterations?: number;
|
|
262
|
+
/**
|
|
263
|
+
* Max sequential plan / dependsOn steps per turn (default 8, hard ceiling 12).
|
|
264
|
+
*/
|
|
265
|
+
maxPlanSteps?: number;
|
|
224
266
|
/** Theme override — 'light' | 'dark' | 'system' */
|
|
225
267
|
theme?: 'light' | 'dark' | 'system';
|
|
226
268
|
}
|
package/dist/core/types.js
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
// @duct/sdk — Core Types
|
|
3
3
|
// All shared TypeScript types for the Duct platform
|
|
4
4
|
// ============================================================
|
|
5
|
+
/** Pixel dimensions for each shell preset. Single source of truth. */
|
|
6
|
+
export const SHELL_PRESET_DIMENSIONS = {
|
|
7
|
+
tall: { width: 400, height: 660 },
|
|
8
|
+
square: { width: 460, height: 500 },
|
|
9
|
+
large: { width: 560, height: 720 },
|
|
10
|
+
};
|
|
11
|
+
export const DEFAULT_SHELL_PRESET = 'tall';
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the effective panel dimensions from a preset and/or explicit
|
|
14
|
+
* width/height. Explicit width/height win only when no preset is provided.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveShellDimensions(opts) {
|
|
17
|
+
if (opts.preset && SHELL_PRESET_DIMENSIONS[opts.preset]) {
|
|
18
|
+
return SHELL_PRESET_DIMENSIONS[opts.preset];
|
|
19
|
+
}
|
|
20
|
+
if (opts.width !== undefined || opts.height !== undefined) {
|
|
21
|
+
return {
|
|
22
|
+
width: opts.width ?? SHELL_PRESET_DIMENSIONS[DEFAULT_SHELL_PRESET].width,
|
|
23
|
+
height: opts.height ?? SHELL_PRESET_DIMENSIONS[DEFAULT_SHELL_PRESET].height,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return SHELL_PRESET_DIMENSIONS[DEFAULT_SHELL_PRESET];
|
|
27
|
+
}
|
|
5
28
|
export const SESSION_TYPE_PREFIX = {
|
|
6
29
|
human: "h",
|
|
7
30
|
agent: "a",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duct-sdk/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"inquirer": "^9.0.0",
|
|
33
33
|
"zod": "^3.0.0",
|
|
34
34
|
"node-fetch": "^3.0.0",
|
|
35
|
-
"glob": "^10.0.0"
|
|
35
|
+
"glob": "^10.0.0",
|
|
36
|
+
"yaml": "^2.0.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"typescript": "^5.0.0",
|