@duct-sdk/sdk 0.2.3 → 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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.3.0] — 2026-06-09
6
+
7
+ ### Added
8
+ - **Shell size presets** — `widget.preset` and the `<DuctShell preset>` prop accept `'tall'` (vertical rectangle, default), `'square'` (Copilot-style), or `'large'`. Dimensions resolve from a single source of truth (`SHELL_PRESET_DIMENSIONS`, `resolveShellDimensions()`), replacing ad-hoc `width`/`height` guessing. Raw `width`/`height` still work as an override.
9
+ - **Draggable launcher** — the floating bubble can be dragged anywhere on the page (free drop); position is persisted per shell in `localStorage`. `position` now only sets the starting corner. Disable with `draggable={false}`.
10
+ - **Theme-aware bubble** — new `<DuctShell theme>` prop (`'light' | 'dark' | 'system'`, default `'system'`); the launcher chrome adapts to light/dark instead of a hardcoded dark circle.
11
+ - `DUCT_PANEL_SIZE` postMessage now carries `preset`, so a shell's manifest can drive panel sizing on the host.
12
+
13
+ ### Changed
14
+ - Launcher logo now uses the Duct word-mark (`duct-text-no-bg.png`) with the previous `duct-logo.png` kept as a fallback candidate.
15
+ - Generated framework embeds (`duct init` for Next/Remix/Vite) now emit `preset` + `position` and drop the fixed `width`/`height` style override.
16
+ - The Next.js adapter (`@duct-sdk/sdk/next`) now re-exports the React implementation to prevent the two adapters from drifting.
17
+ - `WidgetConfig` Zod schema widened to validate `preset`, `theme`, `placeholder`, `width`, `height`, `logoUrl`, and `customCSS` (previously stripped on `duct push`).
18
+
5
19
  ## [0.2.3] — 2026-06-08
6
20
 
7
21
  ### Added
package/README.md CHANGED
@@ -55,12 +55,20 @@ export default function Layout({ children }) {
55
55
  return (
56
56
  <>
57
57
  {children}
58
- <DuctShell shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID} />
58
+ <DuctShell
59
+ shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID}
60
+ preset="tall" // "tall" | "square" | "large"
61
+ position="bottom-right" // starting corner; the bubble is draggable
62
+ theme="system" // "system" | "light" | "dark"
63
+ />
59
64
  </>
60
65
  );
61
66
  }
62
67
  ```
63
68
 
69
+ The launcher bubble is **draggable** (drop it anywhere — position persists per shell) and **theme-aware**. Use `preset`
70
+ to size the panel, or pass `panelWidth`/`panelHeight` for a custom size. Set `draggable={false}` to pin the bubble.
71
+
64
72
  ---
65
73
 
66
74
  ## CLI reference
@@ -1,141 +1,2 @@
1
- import React, { type CSSProperties } from "react";
2
- export interface DuctPageContext {
3
- route?: string;
4
- /** Only `type` is required — use whatever key names your data model has */
5
- entity?: {
6
- type: string;
7
- [key: string]: unknown;
8
- };
9
- errorState?: {
10
- code?: string;
11
- message?: string;
12
- field?: string;
13
- };
14
- /** Only `type` is required — use whatever key your model uses for identifiers */
15
- selection?: {
16
- type: string;
17
- [key: string]: unknown;
18
- };
19
- formState?: Record<string, unknown>;
20
- meta?: Record<string, unknown>;
21
- }
22
- export interface DuctShellProps {
23
- /** Your Duct shell ID (e.g., "shell_acme_prod") */
24
- shellId: string;
25
- /**
26
- * User context to pass to the shell as public metadata.
27
- * Do NOT include sensitive data — this is not authenticated.
28
- */
29
- userContext?: Record<string, string | number | boolean | null>;
30
- /**
31
- * Called when the Duct shell requests an auth token.
32
- * Should call your /api/duct/token endpoint and return the JWT string.
33
- * Return empty string for unauthenticated/guest users.
34
- */
35
- onTokenRequest?: (shellId: string) => Promise<string>;
36
- /** Called when the shell requests navigation to a URL (deeplink handoff) */
37
- onNavigate?: (url: string) => void;
38
- /**
39
- * Page Context Protocol — called when the shell needs to understand what
40
- * the user is currently viewing (triggered by deictic references like "this",
41
- * "that order", "the error on screen"). Return structured data about the
42
- * current page state so the shell can resolve on-screen references without
43
- * screenshots or computer-use techniques.
44
- *
45
- * Alternatively, use the `useDuctPageContext` hook in page-level components
46
- * when this component is in a layout that doesn't have access to page state.
47
- */
48
- onPageContext?: () => DuctPageContext | Promise<DuctPageContext>;
49
- /** Controlled open state */
50
- open?: boolean;
51
- /** Called whenever shell open state changes */
52
- onOpenChange?: (open: boolean) => void;
53
- /** Whether the shell is initially open (default: false) */
54
- defaultOpen?: boolean;
55
- /**
56
- * Duct shell host URL.
57
- * For local dev: http://localhost:3000
58
- * For production: your Duct shell host URL (local default: http://localhost:3000)
59
- */
60
- shellHost?: string;
61
- /**
62
- * Position of the floating launcher.
63
- * @default "bottom-right"
64
- */
65
- position?: "bottom-right" | "bottom-left";
66
- /**
67
- * Panel width in pixels.
68
- * @default 420
69
- */
70
- panelWidth?: number;
71
- /**
72
- * Panel height in pixels.
73
- * @default 640
74
- */
75
- panelHeight?: number;
76
- /** Override container styles (wrapper div). */
77
- style?: CSSProperties;
78
- className?: string;
79
- /**
80
- * Optional launcher icon source.
81
- * When omitted, the SDK tries cloud-hosted icon first, then local /assets/logo.png.
82
- */
83
- launcherIconSrc?: string;
84
- /**
85
- * When true, the launcher is hidden until the shell status endpoint confirms
86
- * the shell is live. Prevents showing the button before `duct push` has been run.
87
- * @default false
88
- */
89
- readyCheck?: boolean;
90
- }
91
- export interface ShellStatusResult {
92
- status: 'live' | 'not_ready' | 'suspended' | 'loading';
93
- manifestReady: boolean;
94
- widget?: {
95
- welcomeMessage?: string;
96
- placeholder?: string;
97
- theme?: string;
98
- primaryColor?: string;
99
- width?: number | string;
100
- height?: number | string;
101
- };
102
- }
103
- /**
104
- * Hook that polls the shell status endpoint once on mount.
105
- * Use when you need to conditionally render UI based on shell liveness.
106
- */
107
- export declare function useShellStatus(shellId: string, shellHost?: string): ShellStatusResult;
108
- /**
109
- * DuctShell — a self-contained floating launcher button + chat panel.
110
- *
111
- * Drop this anywhere in your layout. It renders:
112
- * - A fixed bubble button (bottom-right by default)
113
- * - A full-height chat panel that opens when clicked
114
- *
115
- * @example
116
- * ```tsx
117
- * // app/layout.tsx
118
- * <DuctShell
119
- * shellId={process.env.DUCT_SHELL_ID!}
120
- * shellHost={process.env.DUCT_SHELL_HOST}
121
- * onTokenRequest={async () => {
122
- * const res = await fetch("/api/duct/token", { method: "POST" });
123
- * const { token } = await res.json();
124
- * return token;
125
- * }} />
126
- * ```
127
- */
128
- export declare function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen, shellHost, position, panelWidth, panelHeight, style, className, launcherIconSrc, readyCheck, }: DuctShellProps): React.ReactElement | null;
129
- export interface DuctShellButtonProps {
130
- shellId: string;
131
- children?: React.ReactNode;
132
- onToggle?: (open: boolean) => void;
133
- className?: string;
134
- style?: CSSProperties;
135
- open?: boolean;
136
- }
137
- /**
138
- * Headless launch button — use when you want a custom trigger.
139
- * Pair with DuctShell in controlled mode.
140
- */
141
- export declare function DuctShellButton({ children, onToggle, className, style, open: controlledOpen, }: DuctShellButtonProps): React.ReactElement | null;
1
+ export { DuctShell, DuctShellButton, useShellStatus, } from "../react/shell.js";
2
+ export type { DuctShellProps, DuctShellButtonProps, DuctPageContext, ShellStatusResult, } from "../react/shell.js";
@@ -1,364 +1,9 @@
1
1
  // ============================================================
2
- // @duct-sdk/sdk — DuctShell React Component
3
- // Floating launcher + iframe panel with postMessage bridge
2
+ // @duct/sdk/next — DuctShell
3
+ // The Next.js adapter shares the exact same client implementation as the
4
+ // React adapter (floating launcher + iframe panel + postMessage bridge,
5
+ // draggable bubble, size presets, theme-aware chrome). Re-export to avoid
6
+ // drift between the two adapters.
4
7
  // ============================================================
5
8
  "use client";
6
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
7
- import React, { useEffect, useRef, useCallback, useState, } from "react";
8
- /**
9
- * Hook that polls the shell status endpoint once on mount.
10
- * Use when you need to conditionally render UI based on shell liveness.
11
- */
12
- export function useShellStatus(shellId, shellHost) {
13
- const [result, setResult] = React.useState({ status: 'loading', manifestReady: false });
14
- React.useEffect(() => {
15
- if (!shellId)
16
- return;
17
- const host = (shellHost ?? DUCT_SHELL_HOST_DEFAULT).replace(/\/$/, '');
18
- let cancelled = false;
19
- fetch(`${host}/api/shell-status/${shellId}`)
20
- .then((r) => r.json())
21
- .then((data) => {
22
- if (!cancelled) {
23
- setResult({
24
- status: (data.status ?? 'live'),
25
- manifestReady: data.manifestReady ?? true,
26
- widget: data.widget,
27
- });
28
- }
29
- })
30
- .catch(() => {
31
- if (!cancelled)
32
- setResult({ status: 'live', manifestReady: true });
33
- });
34
- return () => { cancelled = true; };
35
- }, [shellId, shellHost]);
36
- return result;
37
- }
38
- // ----------------------------------------------------------------
39
- // DuctShell — floating launcher + panel
40
- // ----------------------------------------------------------------
41
- const DUCT_SHELL_HOST_DEFAULT = (typeof process !== "undefined" && process.env?.["DUCT_SHELL_HOST"]) ||
42
- "http://localhost:3000";
43
- const DUCT_LAUNCHER_ICON_LOCAL_FALLBACK = "/assets/logo.png";
44
- /**
45
- * DuctShell — a self-contained floating launcher button + chat panel.
46
- *
47
- * Drop this anywhere in your layout. It renders:
48
- * - A fixed bubble button (bottom-right by default)
49
- * - A full-height chat panel that opens when clicked
50
- *
51
- * @example
52
- * ```tsx
53
- * // app/layout.tsx
54
- * <DuctShell
55
- * shellId={process.env.DUCT_SHELL_ID!}
56
- * shellHost={process.env.DUCT_SHELL_HOST}
57
- * onTokenRequest={async () => {
58
- * const res = await fetch("/api/duct/token", { method: "POST" });
59
- * const { token } = await res.json();
60
- * return token;
61
- * }} />
62
- * ```
63
- */
64
- export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen = false, shellHost = DUCT_SHELL_HOST_DEFAULT, position = "bottom-right", panelWidth = 420, panelHeight = 640, style, className, launcherIconSrc, readyCheck = false, }) {
65
- const iframeRef = useRef(null);
66
- const [isReady, setIsReady] = useState(false);
67
- const [isOpen, setIsOpen] = useState(defaultOpen);
68
- const [isAnimating, setIsAnimating] = useState(false);
69
- const [iconCandidateIndex, setIconCandidateIndex] = useState(0);
70
- const [iconLoadFailed, setIconLoadFailed] = useState(false);
71
- // Dynamic panel size — overridden by DUCT_PANEL_SIZE message from shell (manifest widget config)
72
- const [dynamicWidth, setDynamicWidth] = useState(undefined);
73
- const [dynamicHeight, setDynamicHeight] = useState(undefined);
74
- // Shell liveness — only checked when readyCheck=true
75
- const [shellLive, setShellLive] = useState(!readyCheck);
76
- const pendingTokenRequests = useRef(new Map());
77
- // When readyCheck is enabled, poll status once on mount
78
- useEffect(() => {
79
- if (!readyCheck || !shellId)
80
- return;
81
- const host = shellHost.replace(/\/$/, '');
82
- fetch(`${host}/api/shell-status/${shellId}`)
83
- .then((r) => r.json())
84
- .then((data) => {
85
- if (data.status === 'live')
86
- setShellLive(true);
87
- })
88
- .catch(() => setShellLive(true)); // fail open
89
- }, [readyCheck, shellId, shellHost]);
90
- const controlled = open !== undefined;
91
- const panelOpen = controlled ? open : isOpen;
92
- const shellUrl = buildShellUrl(shellHost, shellId, userContext);
93
- const shellOrigin = (() => {
94
- try {
95
- return new URL(shellHost).origin;
96
- }
97
- catch {
98
- return shellHost;
99
- }
100
- })();
101
- const iconCandidates = launcherIconSrc
102
- ? [launcherIconSrc]
103
- : [`${shellOrigin}/duct-logo.png`, DUCT_LAUNCHER_ICON_LOCAL_FALLBACK];
104
- const currentIconSrc = iconCandidates[Math.min(iconCandidateIndex, iconCandidates.length - 1)];
105
- // Send a message to the iframe
106
- const postToShell = useCallback((message) => {
107
- iframeRef.current?.contentWindow?.postMessage(message, shellOrigin);
108
- }, [shellOrigin]);
109
- // Toggle open state
110
- const setOpen = useCallback((next) => {
111
- if (!controlled)
112
- setIsOpen(next);
113
- onOpenChange?.(next);
114
- }, [controlled, onOpenChange]);
115
- // Animate open
116
- const openPanel = useCallback(() => {
117
- setIsAnimating(true);
118
- setOpen(true);
119
- requestAnimationFrame(() => requestAnimationFrame(() => setIsAnimating(false)));
120
- }, [setOpen]);
121
- // Animate close
122
- const closePanel = useCallback(() => {
123
- setIsAnimating(true);
124
- setTimeout(() => {
125
- setOpen(false);
126
- setIsAnimating(false);
127
- }, 220);
128
- }, [setOpen]);
129
- const isAllowedDeeplinkUrl = useCallback((url) => {
130
- if (!url || url.startsWith("//"))
131
- return false;
132
- if (url.startsWith("/"))
133
- return true;
134
- try {
135
- const parsed = new URL(url);
136
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
137
- return false;
138
- return parsed.origin === window.location.origin;
139
- }
140
- catch {
141
- return false;
142
- }
143
- }, []);
144
- // Handle inbound messages from the iframe
145
- const handleMessage = useCallback(async (event) => {
146
- if (event.origin !== shellOrigin)
147
- return;
148
- if (event.source !== iframeRef.current?.contentWindow)
149
- return;
150
- if (typeof event.data !== "object" || !event.data?.type)
151
- return;
152
- const msg = event.data;
153
- switch (msg.type) {
154
- case "DUCT_READY": {
155
- setIsReady(true);
156
- if (userContext && Object.keys(userContext).length > 0) {
157
- postToShell({ type: "DUCT_USER_CONTEXT", context: userContext });
158
- }
159
- break;
160
- }
161
- case "DUCT_REQUEST_TOKEN": {
162
- const { requestId, shellId: reqShellId } = msg;
163
- if (!onTokenRequest) {
164
- postToShell({ type: "DUCT_TOKEN_RESPONSE", requestId, token: "" });
165
- break;
166
- }
167
- try {
168
- const token = await onTokenRequest(reqShellId);
169
- postToShell({ type: "DUCT_TOKEN_RESPONSE", requestId, token: token ?? "" });
170
- }
171
- catch {
172
- postToShell({ type: "DUCT_TOKEN_RESPONSE", requestId, token: "" });
173
- }
174
- pendingTokenRequests.current.delete(requestId);
175
- break;
176
- }
177
- case "DUCT_REQUEST_CONTEXT": {
178
- // Page Context Protocol — shell is asking what the user is currently viewing.
179
- const { requestId } = msg;
180
- if (!onPageContext) {
181
- postToShell({ type: "DUCT_PAGE_CONTEXT", requestId, context: null });
182
- break;
183
- }
184
- try {
185
- const context = await onPageContext();
186
- postToShell({ type: "DUCT_PAGE_CONTEXT", requestId, context });
187
- }
188
- catch {
189
- postToShell({ type: "DUCT_PAGE_CONTEXT", requestId, context: null });
190
- }
191
- break;
192
- }
193
- case "DUCT_DEEPLINK_NAVIGATE": {
194
- const { url } = msg;
195
- if (!isAllowedDeeplinkUrl(url))
196
- break;
197
- postToShell({ type: "DUCT_NAVIGATE_CONFIRMED", url });
198
- closePanel();
199
- // Delay navigation until after the close animation (220ms) so the panel
200
- // slides away before the page changes — avoids a jarring simultaneous transition.
201
- setTimeout(() => {
202
- if (onNavigate) {
203
- onNavigate(url);
204
- }
205
- else {
206
- window.location.href = url;
207
- }
208
- }, 230);
209
- break;
210
- }
211
- case "DUCT_PANEL_SIZE": {
212
- if (msg.width !== undefined)
213
- setDynamicWidth(msg.width);
214
- if (msg.height !== undefined)
215
- setDynamicHeight(msg.height);
216
- break;
217
- }
218
- case "DUCT_OPEN": {
219
- openPanel();
220
- break;
221
- }
222
- case "DUCT_CLOSE": {
223
- closePanel();
224
- break;
225
- }
226
- }
227
- }, [shellOrigin, isAllowedDeeplinkUrl, userContext, onTokenRequest, onPageContext, postToShell, onNavigate, openPanel, closePanel]);
228
- useEffect(() => {
229
- window.addEventListener("message", handleMessage);
230
- return () => window.removeEventListener("message", handleMessage);
231
- }, [handleMessage]);
232
- useEffect(() => {
233
- if (!isReady || !userContext)
234
- return;
235
- postToShell({ type: "DUCT_USER_CONTEXT", context: userContext });
236
- }, [isReady, userContext, postToShell]);
237
- // Sync controlled open
238
- useEffect(() => {
239
- if (open === undefined)
240
- return;
241
- if (open)
242
- openPanel();
243
- else
244
- closePanel();
245
- }, [open]); // eslint-disable-line react-hooks/exhaustive-deps
246
- useEffect(() => {
247
- setIconCandidateIndex(0);
248
- setIconLoadFailed(false);
249
- }, [launcherIconSrc, shellOrigin]);
250
- const handleIconError = useCallback(() => {
251
- if (iconCandidateIndex < iconCandidates.length - 1) {
252
- setIconCandidateIndex((prev) => prev + 1);
253
- return;
254
- }
255
- setIconLoadFailed(true);
256
- }, [iconCandidateIndex, iconCandidates.length]);
257
- if (!shellId) {
258
- console.error("[DuctShell] shellId prop is required");
259
- return null;
260
- }
261
- // Hide entirely until readyCheck confirms the shell is live
262
- if (!shellLive)
263
- return null;
264
- const isRight = position === "bottom-right";
265
- const panelVisible = panelOpen || isAnimating;
266
- // Responsive: full-screen on small viewports.
267
- // Dynamic size overrides prop-level size when the shell sends DUCT_PANEL_SIZE.
268
- const resolvedWidth = dynamicWidth ?? panelWidth;
269
- const resolvedHeight = dynamicHeight ?? panelHeight;
270
- const widthVal = typeof resolvedWidth === "number" ? `${resolvedWidth}px` : resolvedWidth;
271
- const heightVal = typeof resolvedHeight === "number" ? `${resolvedHeight}px` : resolvedHeight;
272
- const panelStyle = {
273
- position: "fixed",
274
- bottom: "80px",
275
- [isRight ? "right" : "left"]: "16px",
276
- width: `min(${widthVal}, calc(100vw - 32px))`,
277
- height: `min(${heightVal}, calc(100dvh - 96px))`,
278
- zIndex: 9998,
279
- borderRadius: "16px",
280
- overflow: "hidden",
281
- boxShadow: "0 24px 64px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.10)",
282
- // Slide-in / slide-out animation
283
- // Opens: slides up from below (translateY(100%) → translateY(0))
284
- // Closes: slides back down
285
- opacity: panelOpen && !isAnimating ? 1 : 0,
286
- transform: panelOpen && !isAnimating
287
- ? "translateY(0)"
288
- : "translateY(100%)",
289
- transition: "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
290
- pointerEvents: panelOpen ? "auto" : "none",
291
- visibility: panelVisible ? "visible" : "hidden",
292
- ...style,
293
- };
294
- const buttonStyle = {
295
- position: "fixed",
296
- bottom: "16px",
297
- [isRight ? "right" : "left"]: "16px",
298
- zIndex: 9999,
299
- width: "56px",
300
- height: "56px",
301
- borderRadius: "50%",
302
- border: "none",
303
- cursor: "pointer",
304
- display: "flex",
305
- alignItems: "center",
306
- justifyContent: "center",
307
- backgroundColor: "#0C0B09",
308
- boxShadow: "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)",
309
- padding: 0,
310
- transition: "transform 150ms ease, box-shadow 150ms ease",
311
- };
312
- return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: openPanel, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
313
- e.currentTarget.style.transform = "scale(1.07)";
314
- e.currentTarget.style.boxShadow =
315
- "0 6px 20px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.20)";
316
- }, onMouseLeave: (e) => {
317
- e.currentTarget.style.transform = "scale(1)";
318
- e.currentTarget.style.boxShadow =
319
- "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)";
320
- }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 28, height: 28, onError: handleIconError, style: { width: "28px", height: "28px", objectFit: "contain" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: "white" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: React.createElement("iframe", {
321
- ref: iframeRef,
322
- src: shellUrl,
323
- title: "Duct Shell",
324
- sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",
325
- allow: "clipboard-write",
326
- referrerPolicy: "no-referrer-when-downgrade",
327
- style: {
328
- width: "100%",
329
- height: "100%",
330
- border: "none",
331
- display: "block",
332
- },
333
- }) })] }));
334
- }
335
- /**
336
- * Headless launch button — use when you want a custom trigger.
337
- * Pair with DuctShell in controlled mode.
338
- */
339
- export function DuctShellButton({ children, onToggle, className, style, open: controlledOpen, }) {
340
- const [internalOpen, setInternalOpen] = useState(false);
341
- const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen;
342
- const handleClick = useCallback(() => {
343
- const next = !isOpen;
344
- if (controlledOpen === undefined)
345
- setInternalOpen(next);
346
- onToggle?.(next);
347
- }, [isOpen, controlledOpen, onToggle]);
348
- return (_jsx("button", { type: "button", onClick: handleClick, className: className, style: style, "aria-label": isOpen ? "Close Duct Shell" : "Open Duct Shell", children: children ?? (isOpen ? "✕" : "Ask AI") }));
349
- }
350
- // ----------------------------------------------------------------
351
- // Helpers
352
- // ----------------------------------------------------------------
353
- function buildShellUrl(shellHost, shellId, userContext) {
354
- const base = shellHost.replace(/\/$/, "");
355
- const url = new URL(`${base}/${shellId}`);
356
- if (userContext) {
357
- for (const [key, value] of Object.entries(userContext)) {
358
- if (value !== null && value !== undefined) {
359
- url.searchParams.set(`ctx_${key}`, String(value));
360
- }
361
- }
362
- }
363
- return url.toString();
364
- }
9
+ export { DuctShell, DuctShellButton, useShellStatus, } from "../react/shell.js";
@@ -1,4 +1,5 @@
1
1
  import React, { type CSSProperties } from "react";
2
+ import { type ShellPreset } from "../../core/types.js";
2
3
  export interface DuctPageContext {
3
4
  route?: string;
4
5
  /** Only `type` is required — use whatever key names your data model has */
@@ -59,17 +60,35 @@ export interface DuctShellProps {
59
60
  */
60
61
  shellHost?: string;
61
62
  /**
62
- * Position of the floating launcher.
63
+ * Initial position of the floating launcher. Users can drag the bubble
64
+ * anywhere; this only sets the starting corner.
63
65
  * @default "bottom-right"
64
66
  */
65
67
  position?: "bottom-right" | "bottom-left";
66
68
  /**
67
- * Panel width in pixels.
69
+ * Size/shape preset for the panel. Preferred over panelWidth/panelHeight.
70
+ * - 'tall' — vertical rectangle (default)
71
+ * - 'square' — Copilot-style squarish panel
72
+ * - 'large' — spacious panel
73
+ */
74
+ preset?: ShellPreset;
75
+ /**
76
+ * Theme for the launcher bubble chrome.
77
+ * @default "system"
78
+ */
79
+ theme?: "light" | "dark" | "system";
80
+ /**
81
+ * Allow the user to drag the bubble anywhere on screen (persisted per shell).
82
+ * @default true
83
+ */
84
+ draggable?: boolean;
85
+ /**
86
+ * Panel width in pixels. Ignored when `preset` is set.
68
87
  * @default 420
69
88
  */
70
89
  panelWidth?: number;
71
90
  /**
72
- * Panel height in pixels.
91
+ * Panel height in pixels. Ignored when `preset` is set.
73
92
  * @default 640
74
93
  */
75
94
  panelHeight?: number;
@@ -132,7 +151,7 @@ export declare function useShellStatus(shellId: string, shellHost?: string): She
132
151
  * />
133
152
  * ```
134
153
  */
135
- export declare function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen, shellHost, position, panelWidth, panelHeight, style, className, launcherIconSrc, readyCheck, }: DuctShellProps): React.ReactElement | null;
154
+ export declare function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen, shellHost, position, preset, theme, draggable, panelWidth, panelHeight, style, className, launcherIconSrc, readyCheck, }: DuctShellProps): React.ReactElement | null;
136
155
  export interface DuctShellButtonProps {
137
156
  shellId: string;
138
157
  children?: React.ReactNode;
@@ -5,6 +5,7 @@
5
5
  "use client";
6
6
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  import React, { useEffect, useRef, useCallback, useState, } from "react";
8
+ import { resolveShellDimensions, } from "../../core/types.js";
8
9
  /**
9
10
  * Hook that polls the shell status endpoint once on mount.
10
11
  * Use when you need to conditionally render UI based on shell liveness.
@@ -48,6 +49,19 @@ export function useShellStatus(shellId, shellHost) {
48
49
  const DUCT_SHELL_HOST_DEFAULT = (typeof process !== "undefined" && process.env?.["DUCT_SHELL_HOST"]) ||
49
50
  "http://localhost:3000";
50
51
  const DUCT_LAUNCHER_ICON_LOCAL_FALLBACK = "/assets/logo.png";
52
+ const BUBBLE_SIZE = 56;
53
+ /** Keep the bubble fully inside the viewport (with a small margin). */
54
+ function clampBubble(x, y) {
55
+ if (typeof window === "undefined")
56
+ return { x, y };
57
+ const margin = 8;
58
+ const maxX = window.innerWidth - BUBBLE_SIZE - margin;
59
+ const maxY = window.innerHeight - BUBBLE_SIZE - margin;
60
+ return {
61
+ x: Math.min(Math.max(margin, x), Math.max(margin, maxX)),
62
+ y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
63
+ };
64
+ }
51
65
  /**
52
66
  * DuctShell — a self-contained floating launcher button + chat panel.
53
67
  *
@@ -69,7 +83,7 @@ const DUCT_LAUNCHER_ICON_LOCAL_FALLBACK = "/assets/logo.png";
69
83
  * />
70
84
  * ```
71
85
  */
72
- export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen = false, shellHost = DUCT_SHELL_HOST_DEFAULT, position = "bottom-right", panelWidth = 420, panelHeight = 640, style, className, launcherIconSrc, readyCheck = false, }) {
86
+ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen = false, shellHost = DUCT_SHELL_HOST_DEFAULT, position = "bottom-right", preset, theme = "system", draggable = true, panelWidth = 420, panelHeight = 640, style, className, launcherIconSrc, readyCheck = false, }) {
73
87
  const iframeRef = useRef(null);
74
88
  const [isReady, setIsReady] = useState(false);
75
89
  const [isOpen, setIsOpen] = useState(defaultOpen);
@@ -79,6 +93,13 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
79
93
  // Dynamic panel size — overridden by DUCT_PANEL_SIZE message from shell (manifest widget config)
80
94
  const [dynamicWidth, setDynamicWidth] = useState(undefined);
81
95
  const [dynamicHeight, setDynamicHeight] = useState(undefined);
96
+ const [dynamicPreset, setDynamicPreset] = useState(undefined);
97
+ // Free-drag bubble position (px from top-left of viewport). null = default corner.
98
+ const [bubblePos, setBubblePos] = useState(null);
99
+ const [isDragging, setIsDragging] = useState(false);
100
+ const dragState = useRef(null);
101
+ // Resolve theme for the launcher chrome (light/dark surface).
102
+ const [isDarkChrome, setIsDarkChrome] = useState(theme === "dark");
82
103
  // Shell liveness — only checked when readyCheck=true
83
104
  const [shellLive, setShellLive] = useState(!readyCheck);
84
105
  const pendingTokenRequests = useRef(new Map());
@@ -108,7 +129,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
108
129
  })();
109
130
  const iconCandidates = launcherIconSrc
110
131
  ? [launcherIconSrc]
111
- : [`${shellOrigin}/duct-logo.png`, DUCT_LAUNCHER_ICON_LOCAL_FALLBACK];
132
+ : [`${shellOrigin}/duct-text-no-bg.png`, `${shellOrigin}/duct-logo.png`, DUCT_LAUNCHER_ICON_LOCAL_FALLBACK];
112
133
  const currentIconSrc = iconCandidates[Math.min(iconCandidateIndex, iconCandidates.length - 1)];
113
134
  // Send a message to the iframe
114
135
  const postToShell = useCallback((message) => {
@@ -219,7 +240,9 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
219
240
  break;
220
241
  }
221
242
  case "DUCT_PANEL_SIZE": {
222
- // Shell communicates its preferred dimensions from manifest widget config.
243
+ // Shell communicates its preferred dimensions/preset from manifest widget config.
244
+ if (msg.preset !== undefined)
245
+ setDynamicPreset(msg.preset);
223
246
  if (msg.width !== undefined)
224
247
  setDynamicWidth(msg.width);
225
248
  if (msg.height !== undefined)
@@ -265,6 +288,83 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
265
288
  }
266
289
  setIconLoadFailed(true);
267
290
  }, [iconCandidateIndex, iconCandidates.length]);
291
+ // Resolve light/dark chrome for the bubble (follows system when theme="system").
292
+ useEffect(() => {
293
+ if (theme === "dark") {
294
+ setIsDarkChrome(true);
295
+ return;
296
+ }
297
+ if (theme === "light") {
298
+ setIsDarkChrome(false);
299
+ return;
300
+ }
301
+ if (typeof window === "undefined" || !window.matchMedia)
302
+ return;
303
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
304
+ setIsDarkChrome(mq.matches);
305
+ const handler = (e) => setIsDarkChrome(e.matches);
306
+ mq.addEventListener("change", handler);
307
+ return () => mq.removeEventListener("change", handler);
308
+ }, [theme]);
309
+ // Restore a previously dragged bubble position.
310
+ useEffect(() => {
311
+ if (!draggable || typeof window === "undefined")
312
+ return;
313
+ try {
314
+ const raw = window.localStorage.getItem(`duct-shell-pos:${shellId}`);
315
+ if (raw) {
316
+ const parsed = JSON.parse(raw);
317
+ if (typeof parsed.x === "number" && typeof parsed.y === "number") {
318
+ setBubblePos(clampBubble(parsed.x, parsed.y));
319
+ }
320
+ }
321
+ }
322
+ catch { /* ignore corrupt storage */ }
323
+ }, [shellId, draggable]);
324
+ // Free drag — pointer move/up handlers attached to window during a drag.
325
+ useEffect(() => {
326
+ if (!isDragging)
327
+ return;
328
+ const onMove = (e) => {
329
+ const st = dragState.current;
330
+ if (!st)
331
+ return;
332
+ if (Math.abs(e.clientX - st.startX) > 4 || Math.abs(e.clientY - st.startY) > 4) {
333
+ st.moved = true;
334
+ }
335
+ setBubblePos(clampBubble(e.clientX - st.dx, e.clientY - st.dy));
336
+ };
337
+ const onUp = () => {
338
+ setIsDragging(false);
339
+ const st = dragState.current;
340
+ dragState.current = null;
341
+ if (st && !st.moved) {
342
+ // Treat as a click → open the panel.
343
+ openPanel();
344
+ }
345
+ else if (bubblePos) {
346
+ try {
347
+ window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(bubblePos));
348
+ }
349
+ catch { /* ignore */ }
350
+ }
351
+ };
352
+ window.addEventListener("pointermove", onMove);
353
+ window.addEventListener("pointerup", onUp);
354
+ return () => {
355
+ window.removeEventListener("pointermove", onMove);
356
+ window.removeEventListener("pointerup", onUp);
357
+ };
358
+ }, [isDragging, bubblePos, openPanel, shellId]);
359
+ const onBubblePointerDown = useCallback((e) => {
360
+ if (!draggable)
361
+ return;
362
+ const rect = e.currentTarget.getBoundingClientRect();
363
+ dragState.current = { dx: e.clientX - rect.left, dy: e.clientY - rect.top, startX: e.clientX, startY: e.clientY, moved: false };
364
+ // Seed bubblePos from current rect so the first drag frame is smooth.
365
+ setBubblePos((prev) => prev ?? clampBubble(rect.left, rect.top));
366
+ setIsDragging(true);
367
+ }, [draggable]);
268
368
  if (!shellId) {
269
369
  console.error("[DuctShell] shellId prop is required");
270
370
  return null;
@@ -274,62 +374,93 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
274
374
  return null;
275
375
  const isRight = position === "bottom-right";
276
376
  const panelVisible = panelOpen || isAnimating;
277
- // Responsive: full-screen on small viewports.
278
- // Dynamic size overrides prop-level size when the shell sends DUCT_PANEL_SIZE
279
- // (manifest widget.width / widget.height configured in Duct dashboard).
280
- const resolvedWidth = dynamicWidth ?? panelWidth;
281
- const resolvedHeight = dynamicHeight ?? panelHeight;
282
- const widthVal = typeof resolvedWidth === "number" ? `${resolvedWidth}px` : resolvedWidth;
283
- const heightVal = typeof resolvedHeight === "number" ? `${resolvedHeight}px` : resolvedHeight;
377
+ // Resolve panel size. Priority: live DUCT_PANEL_SIZE (preset > width/height)
378
+ // from the shell's manifest, then the SDK preset/panelWidth props.
379
+ const sizePreset = dynamicPreset ?? preset;
380
+ const presetDims = resolveShellDimensions({
381
+ preset: sizePreset,
382
+ width: dynamicWidth ?? panelWidth,
383
+ height: dynamicHeight ?? panelHeight,
384
+ });
385
+ const widthVal = typeof presetDims.width === "number" ? `${presetDims.width}px` : presetDims.width;
386
+ const heightVal = typeof presetDims.height === "number" ? `${presetDims.height}px` : presetDims.height;
387
+ // Bubble + panel placement. When the bubble has been dragged we anchor the
388
+ // panel to the bubble; otherwise we use the default corner.
389
+ const dragged = bubblePos !== null;
390
+ const bubbleStyle = dragged
391
+ ? { position: "fixed", left: `${bubblePos.x}px`, top: `${bubblePos.y}px` }
392
+ : { position: "fixed", bottom: "16px", [isRight ? "right" : "left"]: "16px" };
393
+ const panelAnchor = (() => {
394
+ if (!dragged) {
395
+ return { bottom: "80px", [isRight ? "right" : "left"]: "16px" };
396
+ }
397
+ // Open the panel toward whichever side has the most room.
398
+ const vw = typeof window !== "undefined" ? window.innerWidth : 1280;
399
+ const vh = typeof window !== "undefined" ? window.innerHeight : 800;
400
+ const openLeft = bubblePos.x > vw / 2;
401
+ const openUp = bubblePos.y > vh / 2;
402
+ const horiz = openLeft
403
+ ? { right: `${Math.max(16, vw - (bubblePos.x + BUBBLE_SIZE))}px` }
404
+ : { left: `${Math.max(16, bubblePos.x)}px` };
405
+ const vert = openUp
406
+ ? { bottom: `${Math.max(16, vh - bubblePos.y + 12)}px` }
407
+ : { top: `${Math.max(16, bubblePos.y + BUBBLE_SIZE + 12)}px` };
408
+ return { ...horiz, ...vert };
409
+ })();
284
410
  const panelStyle = {
285
411
  position: "fixed",
286
- bottom: "80px",
287
- [isRight ? "right" : "left"]: "16px",
412
+ ...panelAnchor,
288
413
  width: `min(${widthVal}, calc(100vw - 32px))`,
289
414
  height: `min(${heightVal}, calc(100dvh - 96px))`,
290
415
  zIndex: 9998,
291
416
  borderRadius: "16px",
292
417
  overflow: "hidden",
293
418
  boxShadow: "0 24px 64px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.10)",
294
- // Slide-in / slide-out animation
295
- // Opens: slides up from below (translateY(100%) → translateY(0))
296
- // Closes: slides back down
297
419
  opacity: panelOpen && !isAnimating ? 1 : 0,
298
- transform: panelOpen && !isAnimating
299
- ? "translateY(0)"
300
- : "translateY(100%)",
420
+ transform: panelOpen && !isAnimating ? "translateY(0)" : "translateY(12px)",
301
421
  transition: "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
302
422
  pointerEvents: panelOpen ? "auto" : "none",
303
423
  visibility: panelVisible ? "visible" : "hidden",
304
424
  ...style,
305
425
  };
426
+ // Theme-aware launcher chrome — light surface in light mode, dark in dark mode.
427
+ const bubbleBg = isDarkChrome ? "#0C0B09" : "#FFFFFF";
428
+ const bubbleBorder = isDarkChrome ? "1px solid rgba(255,255,255,0.08)" : "1px solid rgba(12,11,9,0.08)";
429
+ const bubbleShadow = isDarkChrome
430
+ ? "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)"
431
+ : "0 4px 16px rgba(12,11,9,0.16), 0 2px 8px rgba(12,11,9,0.08)";
306
432
  const buttonStyle = {
307
- position: "fixed",
308
- bottom: "16px",
309
- [isRight ? "right" : "left"]: "16px",
433
+ ...bubbleStyle,
310
434
  zIndex: 9999,
311
- width: "56px",
312
- height: "56px",
435
+ width: `${BUBBLE_SIZE}px`,
436
+ height: `${BUBBLE_SIZE}px`,
313
437
  borderRadius: "50%",
314
- border: "none",
315
- cursor: "pointer",
438
+ border: bubbleBorder,
439
+ cursor: isDragging ? "grabbing" : "pointer",
316
440
  display: "flex",
317
441
  alignItems: "center",
318
442
  justifyContent: "center",
319
- backgroundColor: "#0C0B09",
320
- boxShadow: "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)",
443
+ backgroundColor: bubbleBg,
444
+ boxShadow: bubbleShadow,
321
445
  padding: 0,
322
- transition: "transform 150ms ease, box-shadow 150ms ease",
446
+ touchAction: "none",
447
+ transition: isDragging ? "none" : "transform 150ms ease, box-shadow 150ms ease",
323
448
  };
324
- return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: openPanel, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
449
+ return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: (e) => {
450
+ // Suppress click when a drag just happened.
451
+ if (dragState.current?.moved) {
452
+ e.preventDefault();
453
+ return;
454
+ }
455
+ if (!draggable)
456
+ openPanel();
457
+ }, onPointerDown: onBubblePointerDown, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
458
+ if (isDragging)
459
+ return;
325
460
  e.currentTarget.style.transform = "scale(1.07)";
326
- e.currentTarget.style.boxShadow =
327
- "0 6px 20px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.20)";
328
461
  }, onMouseLeave: (e) => {
329
462
  e.currentTarget.style.transform = "scale(1)";
330
- e.currentTarget.style.boxShadow =
331
- "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)";
332
- }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 28, height: 28, onError: handleIconError, style: { width: "28px", height: "28px", objectFit: "contain" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: "white" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
463
+ }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 30, height: 30, draggable: false, onError: handleIconError, style: { width: "30px", height: "30px", objectFit: "contain", pointerEvents: "none" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: isDarkChrome ? "#E8622A" : "#E8622A" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
333
464
  width: "100%",
334
465
  height: "100%",
335
466
  border: "none",
@@ -7,9 +7,7 @@
7
7
  // ----------------------------------------------------------------
8
8
  function generateReactShellComponent(config) {
9
9
  const position = config.widget?.position ?? "bottom-right";
10
- const welcomeMessage = config.widget?.welcomeMessage ?? `Hi! I'm ${config.product.name}'s AI assistant.`;
11
- const width = config.widget?.width ?? 380;
12
- const height = config.widget?.height ?? 620;
10
+ const preset = config.widget?.preset ?? "tall";
13
11
  const docsBase = config.product?.baseUrl
14
12
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
15
13
  : 'http://localhost:3005/docs';
@@ -36,6 +34,9 @@ export function DuctShellEmbed() {
36
34
  shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID!}
37
35
  shellHost={shellHost}
38
36
  position="${position}"
37
+ preset="${preset}"
38
+ // Size preset: "tall" (vertical), "square" (Copilot-style), or "large".
39
+ // The bubble is draggable; \`position\` only sets the starting corner.
39
40
  // Optional: provide user context (not sensitive — this is metadata for the shell UI)
40
41
  // userContext={{ theme: "light", locale: "en-US" }}
41
42
  onTokenRequest={async (shellId) => {
@@ -56,13 +57,6 @@ export function DuctShellEmbed() {
56
57
  const data = await res.json() as { token?: string };
57
58
  return data.token ?? "";
58
59
  }}
59
- style={{
60
- width: typeof ${width} === "number" ? \`\${${width}}px\` : "${width}",
61
- height: typeof ${height} === "number" ? \`\${${height}}px\` : "${height}",
62
- maxWidth: "calc(100vw - 32px)",
63
- maxHeight: "calc(100vh - 110px)",
64
- zIndex: 9999,
65
- }}
66
60
  />
67
61
  );
68
62
  }
@@ -83,7 +77,7 @@ export function DuctShellEmbed() {
83
77
  // }
84
78
  //
85
79
  // Shell ID: ${config.shellId}
86
- // Welcome message: "${welcomeMessage}"
80
+ // Size preset: "${preset}" (configure welcome message, theme, etc. in duct.config.ts → widget)
87
81
  //
88
82
  // ── Page Context Protocol (optional but recommended) ──────────────
89
83
  //
@@ -154,6 +148,7 @@ export default function RootLayout({
154
148
  // ----------------------------------------------------------------
155
149
  function generateRemixShellComponent(config) {
156
150
  const position = config.widget?.position ?? "bottom-right";
151
+ const preset = config.widget?.preset ?? "tall";
157
152
  const docsBase = config.product?.baseUrl
158
153
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
159
154
  : 'http://localhost:3005/docs';
@@ -178,6 +173,7 @@ export function DuctShellEmbed() {
178
173
  shellId={import.meta.env.VITE_DUCT_SHELL_ID}
179
174
  shellHost={shellHost}
180
175
  position="${position}"
176
+ preset="${preset}"
181
177
  onTokenRequest={async (shellId) => {
182
178
  const res = await fetch("/api/duct/token", {
183
179
  method: "POST",
@@ -189,13 +185,6 @@ export function DuctShellEmbed() {
189
185
  const data = await res.json() as { token?: string };
190
186
  return data.token ?? "";
191
187
  }}
192
- style={{
193
- width: "380px",
194
- height: "620px",
195
- maxWidth: "calc(100vw - 32px)",
196
- maxHeight: "calc(100vh - 110px)",
197
- zIndex: 9999,
198
- }}
199
188
  />
200
189
  );
201
190
  }
@@ -212,6 +201,7 @@ export function DuctShellEmbed() {
212
201
  // ----------------------------------------------------------------
213
202
  function generateViteShellComponent(config) {
214
203
  const position = config.widget?.position ?? "bottom-right";
204
+ const preset = config.widget?.preset ?? "tall";
215
205
  const docsBase = config.product?.baseUrl
216
206
  ? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
217
207
  : 'http://localhost:3005/docs';
@@ -236,6 +226,7 @@ export function DuctShellEmbed() {
236
226
  shellId={import.meta.env.VITE_DUCT_SHELL_ID}
237
227
  shellHost={shellHost}
238
228
  position="${position}"
229
+ preset="${preset}"
239
230
  onTokenRequest={async (shellId) => {
240
231
  const res = await fetch("/api/duct/token", {
241
232
  method: "POST",
@@ -247,13 +238,6 @@ export function DuctShellEmbed() {
247
238
  const data = await res.json() as { token?: string };
248
239
  return data.token ?? "";
249
240
  }}
250
- style={{
251
- width: "380px",
252
- height: "620px",
253
- maxWidth: "calc(100vw - 32px)",
254
- maxHeight: "calc(100vh - 110px)",
255
- zIndex: 9999,
256
- }}
257
241
  />
258
242
  );
259
243
  }
@@ -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>;
@@ -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),
@@ -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
- /** iframe width — default: 380 */
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;
@@ -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.2.3",
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",