@duct-sdk/sdk 0.2.3 → 0.3.1
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 +22 -0
- package/README.md +9 -1
- package/dist/adapters/next/shell.d.ts +2 -141
- package/dist/adapters/next/shell.js +6 -361
- package/dist/adapters/react/shell.d.ts +23 -4
- package/dist/adapters/react/shell.js +233 -41
- package/dist/cli/generators/shell.js +9 -25
- package/dist/core/config.d.ts +35 -0
- package/dist/core/config.js +7 -0
- package/dist/core/types.d.ts +35 -2
- package/dist/core/types.js +23 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## [0.3.1] — 2026-06-09
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Draggable open panel with viewport clamping — panel stays on-screen after free-drag via top handle
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Panel position clamped to viewport bounds on drag end
|
|
12
|
+
|
|
13
|
+
## [0.3.0] — 2026-06-09
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- **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.
|
|
17
|
+
- **Draggable launcher and panel** — the floating bubble can be dragged anywhere on the page (free drop, persisted per shell), and the opened panel can also be moved via its top handle. `position` now only sets the starting corner. Disable with `draggable={false}`.
|
|
18
|
+
- **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.
|
|
19
|
+
- `DUCT_PANEL_SIZE` postMessage now carries `preset`, so a shell's manifest can drive panel sizing on the host.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Launcher logo now uses the Duct word-mark (`duct-text-no-bg.png`) with the previous `duct-logo.png` kept as a fallback candidate.
|
|
23
|
+
- Generated framework embeds (`duct init` for Next/Remix/Vite) now emit `preset` + `position` and drop the fixed `width`/`height` style override.
|
|
24
|
+
- The Next.js adapter (`@duct-sdk/sdk/next`) now re-exports the React implementation to prevent the two adapters from drifting.
|
|
25
|
+
- `WidgetConfig` Zod schema widened to validate `preset`, `theme`, `placeholder`, `width`, `height`, `logoUrl`, and `customCSS` (previously stripped on `duct push`).
|
|
26
|
+
|
|
5
27
|
## [0.2.3] — 2026-06-08
|
|
6
28
|
|
|
7
29
|
### Added
|
package/README.md
CHANGED
|
@@ -55,12 +55,20 @@ export default function Layout({ children }) {
|
|
|
55
55
|
return (
|
|
56
56
|
<>
|
|
57
57
|
{children}
|
|
58
|
-
<DuctShell
|
|
58
|
+
<DuctShell
|
|
59
|
+
shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID}
|
|
60
|
+
preset="tall" // "tall" | "square" | "large"
|
|
61
|
+
position="bottom-right" // starting corner; bubble + opened panel are draggable
|
|
62
|
+
theme="system" // "system" | "light" | "dark"
|
|
63
|
+
/>
|
|
59
64
|
</>
|
|
60
65
|
);
|
|
61
66
|
}
|
|
62
67
|
```
|
|
63
68
|
|
|
69
|
+
The launcher bubble and opened panel are **draggable** (drop the bubble 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
|
-
|
|
2
|
-
export
|
|
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
|
|
3
|
-
//
|
|
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 and panel, size presets, theme-aware chrome). Re-export to avoid
|
|
6
|
+
// drift between the two adapters.
|
|
4
7
|
// ============================================================
|
|
5
8
|
"use client";
|
|
6
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// Floating launcher + iframe panel with postMessage bridge
|
|
4
4
|
// ============================================================
|
|
5
5
|
"use client";
|
|
6
|
-
import { jsx as _jsx,
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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,31 @@ 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
|
+
}
|
|
65
|
+
/** Keep a dragged panel visible inside the viewport. */
|
|
66
|
+
function clampPanel(x, y, width, height) {
|
|
67
|
+
if (typeof window === "undefined")
|
|
68
|
+
return { x, y };
|
|
69
|
+
const margin = 8;
|
|
70
|
+
const maxX = window.innerWidth - width - margin;
|
|
71
|
+
const maxY = window.innerHeight - height - margin;
|
|
72
|
+
return {
|
|
73
|
+
x: Math.min(Math.max(margin, x), Math.max(margin, maxX)),
|
|
74
|
+
y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
51
77
|
/**
|
|
52
78
|
* DuctShell — a self-contained floating launcher button + chat panel.
|
|
53
79
|
*
|
|
@@ -69,8 +95,9 @@ const DUCT_LAUNCHER_ICON_LOCAL_FALLBACK = "/assets/logo.png";
|
|
|
69
95
|
* />
|
|
70
96
|
* ```
|
|
71
97
|
*/
|
|
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, }) {
|
|
98
|
+
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
99
|
const iframeRef = useRef(null);
|
|
100
|
+
const panelRef = useRef(null);
|
|
74
101
|
const [isReady, setIsReady] = useState(false);
|
|
75
102
|
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
76
103
|
const [isAnimating, setIsAnimating] = useState(false);
|
|
@@ -79,6 +106,17 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
79
106
|
// Dynamic panel size — overridden by DUCT_PANEL_SIZE message from shell (manifest widget config)
|
|
80
107
|
const [dynamicWidth, setDynamicWidth] = useState(undefined);
|
|
81
108
|
const [dynamicHeight, setDynamicHeight] = useState(undefined);
|
|
109
|
+
const [dynamicPreset, setDynamicPreset] = useState(undefined);
|
|
110
|
+
// Free-drag bubble position (px from top-left of viewport). null = default corner.
|
|
111
|
+
const [bubblePos, setBubblePos] = useState(null);
|
|
112
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
113
|
+
const dragState = useRef(null);
|
|
114
|
+
// Open panel can also be dragged after launch. null = anchor near bubble/default corner.
|
|
115
|
+
const [panelPos, setPanelPos] = useState(null);
|
|
116
|
+
const [isPanelDragging, setIsPanelDragging] = useState(false);
|
|
117
|
+
const panelDragState = useRef(null);
|
|
118
|
+
// Resolve theme for the launcher chrome (light/dark surface).
|
|
119
|
+
const [isDarkChrome, setIsDarkChrome] = useState(theme === "dark");
|
|
82
120
|
// Shell liveness — only checked when readyCheck=true
|
|
83
121
|
const [shellLive, setShellLive] = useState(!readyCheck);
|
|
84
122
|
const pendingTokenRequests = useRef(new Map());
|
|
@@ -108,7 +146,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
108
146
|
})();
|
|
109
147
|
const iconCandidates = launcherIconSrc
|
|
110
148
|
? [launcherIconSrc]
|
|
111
|
-
: [`${shellOrigin}/duct-logo.png`, DUCT_LAUNCHER_ICON_LOCAL_FALLBACK];
|
|
149
|
+
: [`${shellOrigin}/duct-text-no-bg.png`, `${shellOrigin}/duct-logo.png`, DUCT_LAUNCHER_ICON_LOCAL_FALLBACK];
|
|
112
150
|
const currentIconSrc = iconCandidates[Math.min(iconCandidateIndex, iconCandidates.length - 1)];
|
|
113
151
|
// Send a message to the iframe
|
|
114
152
|
const postToShell = useCallback((message) => {
|
|
@@ -219,7 +257,9 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
219
257
|
break;
|
|
220
258
|
}
|
|
221
259
|
case "DUCT_PANEL_SIZE": {
|
|
222
|
-
// Shell communicates its preferred dimensions from manifest widget config.
|
|
260
|
+
// Shell communicates its preferred dimensions/preset from manifest widget config.
|
|
261
|
+
if (msg.preset !== undefined)
|
|
262
|
+
setDynamicPreset(msg.preset);
|
|
223
263
|
if (msg.width !== undefined)
|
|
224
264
|
setDynamicWidth(msg.width);
|
|
225
265
|
if (msg.height !== undefined)
|
|
@@ -265,6 +305,118 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
265
305
|
}
|
|
266
306
|
setIconLoadFailed(true);
|
|
267
307
|
}, [iconCandidateIndex, iconCandidates.length]);
|
|
308
|
+
// Resolve light/dark chrome for the bubble (follows system when theme="system").
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
if (theme === "dark") {
|
|
311
|
+
setIsDarkChrome(true);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (theme === "light") {
|
|
315
|
+
setIsDarkChrome(false);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
319
|
+
return;
|
|
320
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
321
|
+
setIsDarkChrome(mq.matches);
|
|
322
|
+
const handler = (e) => setIsDarkChrome(e.matches);
|
|
323
|
+
mq.addEventListener("change", handler);
|
|
324
|
+
return () => mq.removeEventListener("change", handler);
|
|
325
|
+
}, [theme]);
|
|
326
|
+
// Restore a previously dragged bubble position.
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
if (!draggable || typeof window === "undefined")
|
|
329
|
+
return;
|
|
330
|
+
try {
|
|
331
|
+
const raw = window.localStorage.getItem(`duct-shell-pos:${shellId}`);
|
|
332
|
+
if (raw) {
|
|
333
|
+
const parsed = JSON.parse(raw);
|
|
334
|
+
if (typeof parsed.x === "number" && typeof parsed.y === "number") {
|
|
335
|
+
setBubblePos(clampBubble(parsed.x, parsed.y));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch { /* ignore corrupt storage */ }
|
|
340
|
+
}, [shellId, draggable]);
|
|
341
|
+
// Free drag — pointer move/up handlers attached to window during a drag.
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
if (!isDragging)
|
|
344
|
+
return;
|
|
345
|
+
const onMove = (e) => {
|
|
346
|
+
const st = dragState.current;
|
|
347
|
+
if (!st)
|
|
348
|
+
return;
|
|
349
|
+
if (Math.abs(e.clientX - st.startX) > 4 || Math.abs(e.clientY - st.startY) > 4) {
|
|
350
|
+
st.moved = true;
|
|
351
|
+
}
|
|
352
|
+
setBubblePos(clampBubble(e.clientX - st.dx, e.clientY - st.dy));
|
|
353
|
+
};
|
|
354
|
+
const onUp = () => {
|
|
355
|
+
setIsDragging(false);
|
|
356
|
+
const st = dragState.current;
|
|
357
|
+
dragState.current = null;
|
|
358
|
+
if (st && !st.moved) {
|
|
359
|
+
// Treat as a click → open the panel.
|
|
360
|
+
openPanel();
|
|
361
|
+
}
|
|
362
|
+
else if (bubblePos) {
|
|
363
|
+
try {
|
|
364
|
+
window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(bubblePos));
|
|
365
|
+
}
|
|
366
|
+
catch { /* ignore */ }
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
window.addEventListener("pointermove", onMove);
|
|
370
|
+
window.addEventListener("pointerup", onUp);
|
|
371
|
+
return () => {
|
|
372
|
+
window.removeEventListener("pointermove", onMove);
|
|
373
|
+
window.removeEventListener("pointerup", onUp);
|
|
374
|
+
};
|
|
375
|
+
}, [isDragging, bubblePos, openPanel, shellId]);
|
|
376
|
+
// Free-drag the open panel using a top handle. The handle sits outside the
|
|
377
|
+
// iframe so dragging works without relying on iframe internals.
|
|
378
|
+
useEffect(() => {
|
|
379
|
+
if (!isPanelDragging)
|
|
380
|
+
return;
|
|
381
|
+
const onMove = (e) => {
|
|
382
|
+
const st = panelDragState.current;
|
|
383
|
+
if (!st)
|
|
384
|
+
return;
|
|
385
|
+
setPanelPos(clampPanel(e.clientX - st.dx, e.clientY - st.dy, st.width, st.height));
|
|
386
|
+
};
|
|
387
|
+
const onUp = () => {
|
|
388
|
+
setIsPanelDragging(false);
|
|
389
|
+
panelDragState.current = null;
|
|
390
|
+
};
|
|
391
|
+
window.addEventListener("pointermove", onMove);
|
|
392
|
+
window.addEventListener("pointerup", onUp);
|
|
393
|
+
return () => {
|
|
394
|
+
window.removeEventListener("pointermove", onMove);
|
|
395
|
+
window.removeEventListener("pointerup", onUp);
|
|
396
|
+
};
|
|
397
|
+
}, [isPanelDragging]);
|
|
398
|
+
const onBubblePointerDown = useCallback((e) => {
|
|
399
|
+
if (!draggable)
|
|
400
|
+
return;
|
|
401
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
402
|
+
dragState.current = { dx: e.clientX - rect.left, dy: e.clientY - rect.top, startX: e.clientX, startY: e.clientY, moved: false };
|
|
403
|
+
// Seed bubblePos from current rect so the first drag frame is smooth.
|
|
404
|
+
setBubblePos((prev) => prev ?? clampBubble(rect.left, rect.top));
|
|
405
|
+
setIsDragging(true);
|
|
406
|
+
}, [draggable]);
|
|
407
|
+
const onPanelPointerDown = useCallback((e) => {
|
|
408
|
+
if (!draggable || !panelRef.current)
|
|
409
|
+
return;
|
|
410
|
+
const rect = panelRef.current.getBoundingClientRect();
|
|
411
|
+
panelDragState.current = {
|
|
412
|
+
dx: e.clientX - rect.left,
|
|
413
|
+
dy: e.clientY - rect.top,
|
|
414
|
+
width: rect.width,
|
|
415
|
+
height: rect.height,
|
|
416
|
+
};
|
|
417
|
+
setPanelPos(clampPanel(rect.left, rect.top, rect.width, rect.height));
|
|
418
|
+
setIsPanelDragging(true);
|
|
419
|
+
}, [draggable]);
|
|
268
420
|
if (!shellId) {
|
|
269
421
|
console.error("[DuctShell] shellId prop is required");
|
|
270
422
|
return null;
|
|
@@ -274,67 +426,107 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
|
|
|
274
426
|
return null;
|
|
275
427
|
const isRight = position === "bottom-right";
|
|
276
428
|
const panelVisible = panelOpen || isAnimating;
|
|
277
|
-
//
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
429
|
+
// Resolve panel size. Priority: live DUCT_PANEL_SIZE (preset > width/height)
|
|
430
|
+
// from the shell's manifest, then the SDK preset/panelWidth props.
|
|
431
|
+
const sizePreset = dynamicPreset ?? preset;
|
|
432
|
+
const presetDims = resolveShellDimensions({
|
|
433
|
+
preset: sizePreset,
|
|
434
|
+
width: dynamicWidth ?? panelWidth,
|
|
435
|
+
height: dynamicHeight ?? panelHeight,
|
|
436
|
+
});
|
|
437
|
+
const widthVal = typeof presetDims.width === "number" ? `${presetDims.width}px` : presetDims.width;
|
|
438
|
+
const heightVal = typeof presetDims.height === "number" ? `${presetDims.height}px` : presetDims.height;
|
|
439
|
+
// Bubble + panel placement. When the bubble has been dragged we anchor the
|
|
440
|
+
// panel to the bubble; otherwise we use the default corner.
|
|
441
|
+
const dragged = bubblePos !== null;
|
|
442
|
+
const bubbleStyle = dragged
|
|
443
|
+
? { position: "fixed", left: `${bubblePos.x}px`, top: `${bubblePos.y}px` }
|
|
444
|
+
: { position: "fixed", bottom: "16px", [isRight ? "right" : "left"]: "16px" };
|
|
445
|
+
const panelAnchor = (() => {
|
|
446
|
+
if (!dragged) {
|
|
447
|
+
return { bottom: "80px", [isRight ? "right" : "left"]: "16px" };
|
|
448
|
+
}
|
|
449
|
+
// Open the panel toward whichever side has the most room.
|
|
450
|
+
const vw = typeof window !== "undefined" ? window.innerWidth : 1280;
|
|
451
|
+
const vh = typeof window !== "undefined" ? window.innerHeight : 800;
|
|
452
|
+
const openLeft = bubblePos.x > vw / 2;
|
|
453
|
+
const openUp = bubblePos.y > vh / 2;
|
|
454
|
+
const horiz = openLeft
|
|
455
|
+
? { right: `${Math.max(16, vw - (bubblePos.x + BUBBLE_SIZE))}px` }
|
|
456
|
+
: { left: `${Math.max(16, bubblePos.x)}px` };
|
|
457
|
+
const vert = openUp
|
|
458
|
+
? { bottom: `${Math.max(16, vh - bubblePos.y + 12)}px` }
|
|
459
|
+
: { top: `${Math.max(16, bubblePos.y + BUBBLE_SIZE + 12)}px` };
|
|
460
|
+
return { ...horiz, ...vert };
|
|
461
|
+
})();
|
|
284
462
|
const panelStyle = {
|
|
285
463
|
position: "fixed",
|
|
286
|
-
|
|
287
|
-
[isRight ? "right" : "left"]: "16px",
|
|
464
|
+
...(panelPos ? { left: `${panelPos.x}px`, top: `${panelPos.y}px` } : panelAnchor),
|
|
288
465
|
width: `min(${widthVal}, calc(100vw - 32px))`,
|
|
289
466
|
height: `min(${heightVal}, calc(100dvh - 96px))`,
|
|
290
467
|
zIndex: 9998,
|
|
291
468
|
borderRadius: "16px",
|
|
292
469
|
overflow: "hidden",
|
|
293
470
|
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
471
|
opacity: panelOpen && !isAnimating ? 1 : 0,
|
|
298
|
-
transform: panelOpen && !isAnimating
|
|
299
|
-
|
|
300
|
-
: "translateY(100%)",
|
|
301
|
-
transition: "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
472
|
+
transform: panelOpen && !isAnimating ? "translateY(0)" : "translateY(12px)",
|
|
473
|
+
transition: isPanelDragging ? "none" : "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
302
474
|
pointerEvents: panelOpen ? "auto" : "none",
|
|
303
475
|
visibility: panelVisible ? "visible" : "hidden",
|
|
304
476
|
...style,
|
|
305
477
|
};
|
|
478
|
+
// Theme-aware launcher chrome — light surface in light mode, dark in dark mode.
|
|
479
|
+
const bubbleBg = isDarkChrome ? "#0C0B09" : "#FFFFFF";
|
|
480
|
+
const bubbleBorder = isDarkChrome ? "1px solid rgba(255,255,255,0.08)" : "1px solid rgba(12,11,9,0.08)";
|
|
481
|
+
const bubbleShadow = isDarkChrome
|
|
482
|
+
? "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)"
|
|
483
|
+
: "0 4px 16px rgba(12,11,9,0.16), 0 2px 8px rgba(12,11,9,0.08)";
|
|
306
484
|
const buttonStyle = {
|
|
307
|
-
|
|
308
|
-
bottom: "16px",
|
|
309
|
-
[isRight ? "right" : "left"]: "16px",
|
|
485
|
+
...bubbleStyle,
|
|
310
486
|
zIndex: 9999,
|
|
311
|
-
width:
|
|
312
|
-
height:
|
|
487
|
+
width: `${BUBBLE_SIZE}px`,
|
|
488
|
+
height: `${BUBBLE_SIZE}px`,
|
|
313
489
|
borderRadius: "50%",
|
|
314
|
-
border:
|
|
315
|
-
cursor: "pointer",
|
|
490
|
+
border: bubbleBorder,
|
|
491
|
+
cursor: isDragging ? "grabbing" : "pointer",
|
|
316
492
|
display: "flex",
|
|
317
493
|
alignItems: "center",
|
|
318
494
|
justifyContent: "center",
|
|
319
|
-
backgroundColor:
|
|
320
|
-
boxShadow:
|
|
495
|
+
backgroundColor: bubbleBg,
|
|
496
|
+
boxShadow: bubbleShadow,
|
|
321
497
|
padding: 0,
|
|
322
|
-
|
|
498
|
+
touchAction: "none",
|
|
499
|
+
transition: isDragging ? "none" : "transform 150ms ease, box-shadow 150ms ease",
|
|
323
500
|
};
|
|
324
|
-
return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick:
|
|
501
|
+
return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: (e) => {
|
|
502
|
+
// Suppress click when a drag just happened.
|
|
503
|
+
if (dragState.current?.moved) {
|
|
504
|
+
e.preventDefault();
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (!draggable)
|
|
508
|
+
openPanel();
|
|
509
|
+
}, onPointerDown: onBubblePointerDown, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
|
|
510
|
+
if (isDragging)
|
|
511
|
+
return;
|
|
325
512
|
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
513
|
}, onMouseLeave: (e) => {
|
|
329
514
|
e.currentTarget.style.transform = "scale(1)";
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
515
|
+
}, 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" }) })) })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [_jsx("div", { onPointerDown: onPanelPointerDown, "aria-hidden": "true", title: "Drag Duct Shell", style: {
|
|
516
|
+
position: "absolute",
|
|
517
|
+
top: 0,
|
|
518
|
+
left: 0,
|
|
519
|
+
right: 44,
|
|
520
|
+
height: 44,
|
|
521
|
+
zIndex: 2,
|
|
522
|
+
cursor: isPanelDragging ? "grabbing" : "grab",
|
|
523
|
+
touchAction: "none",
|
|
524
|
+
} }), _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: {
|
|
525
|
+
width: "100%",
|
|
526
|
+
height: "100%",
|
|
527
|
+
border: "none",
|
|
528
|
+
display: "block",
|
|
529
|
+
} })] })] }));
|
|
338
530
|
}
|
|
339
531
|
/**
|
|
340
532
|
* Headless launch button — use when you want a custom trigger.
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
// ----------------------------------------------------------------
|
|
8
8
|
function generateReactShellComponent(config) {
|
|
9
9
|
const position = config.widget?.position ?? "bottom-right";
|
|
10
|
-
const
|
|
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 and opened panel are 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
|
-
//
|
|
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
|
}
|
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),
|
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;
|
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",
|