@duct-sdk/sdk 0.3.9 → 0.3.12

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 CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.3.11] — 2026-06-16
6
+
7
+ ### Fixed
8
+ - **Panel drag handle (light theme)** — grab bar uses a solid mid-gray with subtle shadow instead of 20% black, so it stays visible on light shell headers.
9
+
10
+ ## [0.3.10] — 2026-06-16
11
+
12
+ ### Improved
13
+ - **`duct init` shell generator** — `DuctShellEmbed` now passes `theme` from `duct.config.ts` → `widget.theme`; Svelte/Vue/Nuxt iframe URLs include `?theme=` so the hosted shell matches before push.
14
+
5
15
  ## [0.3.9] — 2026-06-14
6
16
 
7
17
  ### Added
@@ -62,10 +62,16 @@ function clampBubble(x, y) {
62
62
  y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
63
63
  };
64
64
  }
65
+ /** Visible grab-bar on light panels (solid beats low-alpha rgba on variable iframe headers). */
66
+ function dragHandleBarColor(isDark, hovered) {
67
+ if (isDark)
68
+ return hovered ? "rgba(255,255,255,0.38)" : "rgba(255,255,255,0.32)";
69
+ return hovered ? "#524E48" : "#635F59";
70
+ }
65
71
  /** Top grab handle for the open panel — with theme-aware hover tooltip. */
66
72
  function ShellDragHandle({ onPointerDown, isDragging, isDark, label = "Drag to move", style, }) {
67
73
  const [hovered, setHovered] = useState(false);
68
- const barColor = isDark ? "rgba(255,255,255,0.28)" : "rgba(12,11,9,0.20)";
74
+ const barColor = dragHandleBarColor(isDark, hovered);
69
75
  const showTip = hovered && !isDragging;
70
76
  return (_jsxs("div", { role: "button", tabIndex: -1, onPointerDown: onPointerDown, "aria-label": label, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), style: {
71
77
  position: "absolute",
@@ -84,9 +90,10 @@ function ShellDragHandle({ onPointerDown, isDragging, isDark, label = "Drag to m
84
90
  ...style,
85
91
  }, children: [_jsx("div", { "aria-hidden": "true", style: {
86
92
  width: 32,
87
- height: 4,
93
+ height: isDark ? 4 : 5,
88
94
  borderRadius: 2,
89
95
  backgroundColor: barColor,
96
+ boxShadow: isDark ? undefined : "0 1px 2px rgba(12,11,9,0.12)",
90
97
  } }), showTip && (_jsx("div", { role: "tooltip", style: {
91
98
  position: "absolute",
92
99
  top: "100%",
@@ -2,12 +2,27 @@
2
2
  // @duct/sdk — Shell Component Generator
3
3
  // Generates framework-specific shell embed components
4
4
  // ============================================================
5
+ function widgetTheme(config) {
6
+ const t = config.widget?.theme;
7
+ if (t === "light" || t === "dark" || t === "system")
8
+ return t;
9
+ return "system";
10
+ }
11
+ /** DuctShell `theme` prop line — launcher chrome; chat surface uses manifest.widget.theme from duct push. */
12
+ function ductShellThemeProp(config, indent = " ") {
13
+ return `${indent}theme="${widgetTheme(config)}"`;
14
+ }
15
+ /** Iframe src query string so hosted shell matches widget.theme before/at push time. */
16
+ function shellThemeQuery(config) {
17
+ return `?theme=${widgetTheme(config)}`;
18
+ }
5
19
  // ----------------------------------------------------------------
6
20
  // Next.js / React shell component
7
21
  // ----------------------------------------------------------------
8
22
  function generateReactShellComponent(config) {
9
23
  const position = config.widget?.position ?? "bottom-right";
10
24
  const preset = config.widget?.preset ?? "tall";
25
+ const themeProp = ductShellThemeProp(config);
11
26
  const docsBase = config.product?.baseUrl
12
27
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
13
28
  : 'http://localhost:3005/docs';
@@ -35,6 +50,7 @@ export function DuctShellEmbed() {
35
50
  shellHost={shellHost}
36
51
  position="${position}"
37
52
  preset="${preset}"
53
+ ${themeProp}
38
54
  // Size preset: "tall" (vertical), "square" (Copilot-style), or "large".
39
55
  // The bubble and opened panel are draggable; \`position\` only sets the starting corner.
40
56
  // Optional: provide user context (not sensitive — this is metadata for the shell UI)
@@ -149,6 +165,7 @@ export default function RootLayout({
149
165
  function generateRemixShellComponent(config) {
150
166
  const position = config.widget?.position ?? "bottom-right";
151
167
  const preset = config.widget?.preset ?? "tall";
168
+ const themeProp = ductShellThemeProp(config);
152
169
  const docsBase = config.product?.baseUrl
153
170
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
154
171
  : 'http://localhost:3005/docs';
@@ -174,6 +191,7 @@ export function DuctShellEmbed() {
174
191
  shellHost={shellHost}
175
192
  position="${position}"
176
193
  preset="${preset}"
194
+ ${themeProp}
177
195
  onTokenRequest={async (shellId) => {
178
196
  const res = await fetch("/api/duct/token", {
179
197
  method: "POST",
@@ -202,6 +220,7 @@ export function DuctShellEmbed() {
202
220
  function generateViteShellComponent(config) {
203
221
  const position = config.widget?.position ?? "bottom-right";
204
222
  const preset = config.widget?.preset ?? "tall";
223
+ const themeProp = ductShellThemeProp(config);
205
224
  const docsBase = config.product?.baseUrl
206
225
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
207
226
  : 'http://localhost:3005/docs';
@@ -227,6 +246,7 @@ export function DuctShellEmbed() {
227
246
  shellHost={shellHost}
228
247
  position="${position}"
229
248
  preset="${preset}"
249
+ ${themeProp}
230
250
  onTokenRequest={async (shellId) => {
231
251
  const res = await fetch("/api/duct/token", {
232
252
  method: "POST",
@@ -312,6 +332,7 @@ export function getEnvTemplateName(framework) {
312
332
  // SvelteKit shell component
313
333
  // ----------------------------------------------------------------
314
334
  function generateSvelteKitShellComponent(config) {
335
+ const themeQuery = shellThemeQuery(config);
315
336
  const docsBase = config.product?.baseUrl
316
337
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
317
338
  : 'http://localhost:3005/docs';
@@ -333,7 +354,7 @@ function generateSvelteKitShellComponent(config) {
333
354
 
334
355
  const shellId = env.PUBLIC_DUCT_SHELL_ID ?? "";
335
356
  const shellHost = env.PUBLIC_DUCT_SHELL_HOST ?? "http://localhost:3000";
336
- const shellUrl = \`\${shellHost}/\${shellId}\`;
357
+ const shellUrl = \`\${shellHost}/\${shellId}${themeQuery}\`;
337
358
 
338
359
  async function getToken(): Promise<string> {
339
360
  const res = await fetch("/api/duct/token", {
@@ -420,6 +441,7 @@ function generateVue3ShellComponent(config) {
420
441
  const position = config.widget?.position ?? "bottom-right";
421
442
  const width = config.widget?.width ?? 380;
422
443
  const height = config.widget?.height ?? 620;
444
+ const themeQuery = shellThemeQuery(config);
423
445
  const docsBase = config.product?.baseUrl
424
446
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
425
447
  : 'http://localhost:3005/docs';
@@ -474,7 +496,7 @@ const iframeRef = ref<HTMLIFrameElement | null>(null);
474
496
 
475
497
  const shellId = import.meta.env.VITE_DUCT_SHELL_ID as string ?? '';
476
498
  const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST as string ?? 'http://localhost:3000';
477
- const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
499
+ const shellUrl = computed(() => \`\${shellHost}/\${shellId}${themeQuery}\`);
478
500
 
479
501
  async function getToken(): Promise<string> {
480
502
  try {
@@ -539,6 +561,7 @@ function generateNuxtShellComponent(config) {
539
561
  const position = config.widget?.position ?? "bottom-right";
540
562
  const width = config.widget?.width ?? 380;
541
563
  const height = config.widget?.height ?? 620;
564
+ const themeQuery = shellThemeQuery(config);
542
565
  const docsBase = config.product?.baseUrl
543
566
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
544
567
  : 'http://localhost:3005/docs';
@@ -593,7 +616,7 @@ const iframeRef = ref<HTMLIFrameElement | null>(null);
593
616
  const config = useRuntimeConfig();
594
617
  const shellId = (config.public.ductShellId as string) ?? '';
595
618
  const shellHost = (config.public.ductShellHost as string) ?? 'http://localhost:3000';
596
- const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
619
+ const shellUrl = computed(() => \`\${shellHost}/\${shellId}${themeQuery}\`);
597
620
 
598
621
  async function getToken(): Promise<string> {
599
622
  try {
@@ -229,6 +229,21 @@ export declare const DuctConfigSchema: z.ZodObject<{
229
229
  expirySeconds: z.ZodDefault<z.ZodNumber>;
230
230
  requiresAuth: z.ZodBoolean;
231
231
  intent: z.ZodOptional<z.ZodString>;
232
+ pageResolver: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
233
+ actionId: z.ZodString;
234
+ }, "strip", z.ZodTypeAny, {
235
+ actionId: string;
236
+ }, {
237
+ actionId: string;
238
+ }>, z.ZodObject<{
239
+ endpoint: z.ZodString;
240
+ }, "strip", z.ZodTypeAny, {
241
+ endpoint: string;
242
+ }, {
243
+ endpoint: string;
244
+ }>]>>;
245
+ allowFetch: z.ZodOptional<z.ZodBoolean>;
246
+ contentSelector: z.ZodOptional<z.ZodString>;
232
247
  }, "strip", z.ZodTypeAny, {
233
248
  id: string;
234
249
  name: string;
@@ -244,6 +259,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
244
259
  }[];
245
260
  expirySeconds: number;
246
261
  intent?: string | undefined;
262
+ pageResolver?: {
263
+ actionId: string;
264
+ } | {
265
+ endpoint: string;
266
+ } | undefined;
267
+ allowFetch?: boolean | undefined;
268
+ contentSelector?: string | undefined;
247
269
  }, {
248
270
  id: string;
249
271
  name: string;
@@ -259,6 +281,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
259
281
  }[] | undefined;
260
282
  expirySeconds?: number | undefined;
261
283
  intent?: string | undefined;
284
+ pageResolver?: {
285
+ actionId: string;
286
+ } | {
287
+ endpoint: string;
288
+ } | undefined;
289
+ allowFetch?: boolean | undefined;
290
+ contentSelector?: string | undefined;
262
291
  }>, "many">>;
263
292
  agentPermissions: z.ZodObject<{
264
293
  defaultLevel: z.ZodEnum<["none", "read", "write", "admin"]>;
@@ -399,6 +428,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
399
428
  }[];
400
429
  expirySeconds: number;
401
430
  intent?: string | undefined;
431
+ pageResolver?: {
432
+ actionId: string;
433
+ } | {
434
+ endpoint: string;
435
+ } | undefined;
436
+ allowFetch?: boolean | undefined;
437
+ contentSelector?: string | undefined;
402
438
  }[];
403
439
  agentPermissions: {
404
440
  defaultLevel: "none" | "read" | "write" | "admin";
@@ -506,6 +542,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
506
542
  }[] | undefined;
507
543
  expirySeconds?: number | undefined;
508
544
  intent?: string | undefined;
545
+ pageResolver?: {
546
+ actionId: string;
547
+ } | {
548
+ endpoint: string;
549
+ } | undefined;
550
+ allowFetch?: boolean | undefined;
551
+ contentSelector?: string | undefined;
509
552
  }[] | undefined;
510
553
  widget?: {
511
554
  primaryColor?: string | undefined;
@@ -99,6 +99,10 @@ const StateFieldSchema = z.object({
99
99
  description: z.string().optional(),
100
100
  sessionSource: z.string().optional(),
101
101
  });
102
+ const PageResolverSchema = z.union([
103
+ z.object({ actionId: z.string().min(1) }),
104
+ z.object({ endpoint: z.string().min(1).startsWith("/") }),
105
+ ]);
102
106
  const DeeplinkDefinitionSchema = z.object({
103
107
  id: z
104
108
  .string()
@@ -111,6 +115,9 @@ const DeeplinkDefinitionSchema = z.object({
111
115
  expirySeconds: z.number().positive().default(300),
112
116
  requiresAuth: z.boolean(),
113
117
  intent: z.string().optional(),
118
+ pageResolver: PageResolverSchema.optional(),
119
+ allowFetch: z.boolean().optional(),
120
+ contentSelector: z.string().optional(),
114
121
  });
115
122
  const AgentPermissionLevelSchema = z.enum([
116
123
  "none",
@@ -1,5 +1,5 @@
1
1
  /** Default agent loop ceilings used in widget manifest defaults. */
2
- export declare const DEFAULT_MAX_TOOL_ITERATIONS = 12;
2
+ export declare const DEFAULT_MAX_TOOL_ITERATIONS = 4;
3
3
  export declare const DEFAULT_MAX_PLAN_STEPS = 8;
4
4
  export declare const HARD_CEILING_TOOL_ITERATIONS = 25;
5
5
  export declare const HARD_CEILING_PLAN_STEPS = 12;
@@ -1,5 +1,5 @@
1
1
  /** Default agent loop ceilings used in widget manifest defaults. */
2
- export const DEFAULT_MAX_TOOL_ITERATIONS = 12;
2
+ export const DEFAULT_MAX_TOOL_ITERATIONS = 4;
3
3
  export const DEFAULT_MAX_PLAN_STEPS = 8;
4
4
  export const HARD_CEILING_TOOL_ITERATIONS = 25;
5
5
  export const HARD_CEILING_PLAN_STEPS = 12;
@@ -0,0 +1,49 @@
1
+ export interface DuctPageContext {
2
+ /** Human-readable page title */
3
+ title?: string;
4
+ /** Route or screen identifier in the host app */
5
+ route?: string;
6
+ /** Key fields visible on the page (entity snapshots, form values, etc.) */
7
+ fields?: Record<string, unknown>;
8
+ /** Optional structured sections (tables, lists) */
9
+ sections?: Array<{
10
+ id: string;
11
+ label?: string;
12
+ items?: unknown[];
13
+ }>;
14
+ [key: string]: unknown;
15
+ }
16
+ export interface PageResolveResult {
17
+ page_context: DuctPageContext;
18
+ data?: unknown;
19
+ }
20
+ export interface PageResolveContext {
21
+ deeplinkId: string;
22
+ state: Record<string, string>;
23
+ headers: Record<string, string | string[] | undefined>;
24
+ searchParams: Record<string, string>;
25
+ }
26
+ export type PageResolveResolver = (ctx: PageResolveContext) => Promise<PageResolveResult>;
27
+ export interface PageResolveHandlerOptions {
28
+ cacheTtlSeconds?: number;
29
+ noCache?: boolean;
30
+ }
31
+ export declare function createPageResolveHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: Request) => Promise<Response>;
32
+ export declare function createPageResolvePageHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: {
33
+ headers: Record<string, string | string[]>;
34
+ query: Record<string, string | string[]>;
35
+ }, res: {
36
+ status: (code: number) => {
37
+ json: (body: unknown) => void;
38
+ };
39
+ setHeader: (name: string, value: string) => void;
40
+ }) => Promise<void>;
41
+ export declare function createPageResolveExpressHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: {
42
+ headers: Record<string, string | string[] | undefined>;
43
+ query: Record<string, string | string[]>;
44
+ }, res: {
45
+ status: (code: number) => {
46
+ json: (body: unknown) => void;
47
+ };
48
+ setHeader: (name: string, value: string) => void;
49
+ }) => Promise<void>;
@@ -0,0 +1,87 @@
1
+ // ============================================================
2
+ // @duct/sdk — /duct/page-resolve handler factory
3
+ // Companies implement structured page context for agent deeplink
4
+ // resolution (parallel to /duct/introspect).
5
+ //
6
+ // Contract:
7
+ // GET /duct/page-resolve?deeplink_id=...&<state fields>
8
+ // → { page_context: { ... }, data?: unknown }
9
+ // ============================================================
10
+ async function runPageResolveResolver(resolver, ctx, options) {
11
+ const ttl = options.cacheTtlSeconds ?? 60;
12
+ const cacheControl = options.noCache
13
+ ? 'no-store'
14
+ : `private, max-age=${ttl}, stale-while-revalidate=30`;
15
+ try {
16
+ const result = await resolver(ctx);
17
+ return {
18
+ body: result,
19
+ headers: { 'Cache-Control': cacheControl, 'Content-Type': 'application/json' },
20
+ status: 200,
21
+ };
22
+ }
23
+ catch {
24
+ return {
25
+ body: { page_context: {} },
26
+ headers: { 'Cache-Control': 'no-store', 'Content-Type': 'application/json' },
27
+ status: 500,
28
+ };
29
+ }
30
+ }
31
+ function headersToRecord(headers) {
32
+ const out = {};
33
+ headers.forEach((value, key) => { out[key] = value; });
34
+ return out;
35
+ }
36
+ function extractPageResolveContext(req, searchParamsFromUrl) {
37
+ const searchParams = {};
38
+ if (searchParamsFromUrl) {
39
+ searchParamsFromUrl.forEach((v, k) => { searchParams[k] = v; });
40
+ }
41
+ else if (req.query) {
42
+ for (const [k, v] of Object.entries(req.query)) {
43
+ searchParams[k] = Array.isArray(v) ? v[0] ?? '' : v;
44
+ }
45
+ }
46
+ const deeplinkId = searchParams.deeplink_id ?? searchParams.deeplinkId ?? '';
47
+ const state = {};
48
+ for (const [k, v] of Object.entries(searchParams)) {
49
+ if (k === 'deeplink_id' || k === 'deeplinkId')
50
+ continue;
51
+ state[k] = v;
52
+ }
53
+ return {
54
+ deeplinkId,
55
+ state,
56
+ headers: req.headers,
57
+ searchParams,
58
+ };
59
+ }
60
+ export function createPageResolveHandler(resolver, options = {}) {
61
+ return async (req) => {
62
+ const url = new URL(req.url);
63
+ const ctx = extractPageResolveContext({ headers: headersToRecord(req.headers) }, url.searchParams);
64
+ const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
65
+ return new Response(JSON.stringify(body), { status, headers });
66
+ };
67
+ }
68
+ export function createPageResolvePageHandler(resolver, options = {}) {
69
+ return async (req, res) => {
70
+ const ctx = extractPageResolveContext({ headers: req.headers, query: req.query });
71
+ const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
72
+ for (const [key, value] of Object.entries(headers)) {
73
+ res.setHeader(key, value);
74
+ }
75
+ res.status(status).json(body);
76
+ };
77
+ }
78
+ export function createPageResolveExpressHandler(resolver, options = {}) {
79
+ return async (req, res) => {
80
+ const ctx = extractPageResolveContext({ headers: req.headers, query: req.query });
81
+ const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
82
+ for (const [key, value] of Object.entries(headers)) {
83
+ res.setHeader(key, value);
84
+ }
85
+ res.status(status).json(body);
86
+ };
87
+ }
@@ -158,6 +158,22 @@ export interface DeeplinkDefinition {
158
158
  openInNewTab?: boolean;
159
159
  /** Human-readable intent description (for agent use) */
160
160
  intent?: string;
161
+ /**
162
+ * Agent page resolution — invoke an action or company endpoint to return
163
+ * structured page context instead of a bare handoff URL.
164
+ */
165
+ pageResolver?: {
166
+ actionId: string;
167
+ } | {
168
+ endpoint: string;
169
+ };
170
+ /**
171
+ * When true (and pageResolver absent or insufficient), platform may fetch
172
+ * rendered HTML from the deeplink URL. Off by default — explicit opt-in.
173
+ */
174
+ allowFetch?: boolean;
175
+ /** CSS selector hints for generic HTML extraction when allowFetch is true */
176
+ contentSelector?: string;
161
177
  /** ISO 8601 timestamp of last update (set by duct push) */
162
178
  updatedAt?: string;
163
179
  }
package/dist/server.d.ts CHANGED
@@ -4,6 +4,8 @@ export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeepli
4
4
  export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, } from "./core/token.js";
5
5
  export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
6
6
  export type { IntrospectEntity, IntrospectResult, IntrospectContext, IntrospectResolver, IntrospectHandlerOptions, } from "./core/introspect.js";
7
+ export { createPageResolveHandler, createPageResolvePageHandler, createPageResolveExpressHandler, } from "./core/page-resolve.js";
8
+ export type { DuctPageContext, PageResolveResult, PageResolveContext, PageResolveResolver, PageResolveHandlerOptions, } from "./core/page-resolve.js";
7
9
  export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
8
10
  export type { ActionSearchEntry } from "./core/action.js";
9
11
  export { sendIntershellAction, sendIntershellQuery } from "./core/intershell.js";
package/dist/server.js CHANGED
@@ -15,6 +15,8 @@ export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
15
15
  export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, } from "./core/token.js";
16
16
  // Introspect handler factories
17
17
  export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
18
+ // Page-resolve handler factories (agent deeplink resolution)
19
+ export { createPageResolveHandler, createPageResolvePageHandler, createPageResolveExpressHandler, } from "./core/page-resolve.js";
18
20
  // Action utilities (permission checking, search index)
19
21
  export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
20
22
  // Cross-shell client (IS-29)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.3.9",
3
+ "version": "0.3.12",
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",