@duct-sdk/sdk 0.1.7 → 0.1.13
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/README.md +3 -3
- package/dist/adapters/next/index.d.ts +1 -1
- package/dist/adapters/next/shell.d.ts +55 -1
- package/dist/adapters/next/shell.js +100 -17
- package/dist/adapters/react/index.d.ts +5 -1
- package/dist/adapters/react/index.js +2 -0
- package/dist/adapters/react/shell.d.ts +61 -1
- package/dist/adapters/react/shell.js +110 -16
- package/dist/adapters/react/use-page-context.d.ts +32 -0
- package/dist/adapters/react/use-page-context.js +99 -0
- package/dist/cli/agents/api-agent.d.ts +9 -3
- package/dist/cli/agents/api-agent.js +163 -69
- package/dist/cli/agents/auth-agent.d.ts +2 -1
- package/dist/cli/agents/auth-agent.js +38 -24
- package/dist/cli/agents/deeplink-agent.js +71 -49
- package/dist/cli/agents/llm.d.ts +1 -1
- package/dist/cli/agents/llm.js +48 -15
- package/dist/cli/agents/pipeline.d.ts +16 -0
- package/dist/cli/agents/pipeline.js +18 -5
- package/dist/cli/agents/reviewer-agent.js +46 -46
- package/dist/cli/agents/route-agent.d.ts +3 -1
- package/dist/cli/agents/route-agent.js +70 -44
- package/dist/cli/detectors/topology.d.ts +26 -0
- package/dist/cli/detectors/topology.js +310 -0
- package/dist/cli/drift.d.ts +11 -0
- package/dist/cli/drift.js +147 -2
- package/dist/cli/fs/sandbox.d.ts +2 -0
- package/dist/cli/fs/sandbox.js +22 -8
- package/dist/cli/generators/config.d.ts +13 -0
- package/dist/cli/generators/config.js +200 -50
- package/dist/cli/generators/receiver.js +728 -601
- package/dist/cli/generators/shell.js +532 -490
- package/dist/cli/index.js +502 -19
- package/dist/cli/init.d.ts +11 -1
- package/dist/cli/init.js +367 -31
- package/dist/cli/processors/postprocess.d.ts +22 -0
- package/dist/cli/processors/postprocess.js +107 -0
- package/dist/cli/processors/prisma-parser.d.ts +35 -0
- package/dist/cli/processors/prisma-parser.js +117 -0
- package/dist/cli/processors/zod-extractor.d.ts +27 -0
- package/dist/cli/processors/zod-extractor.js +153 -0
- package/dist/cli/prompts/review.d.ts +32 -0
- package/dist/cli/prompts/review.js +240 -0
- package/dist/cli/selectors/index.d.ts +22 -0
- package/dist/cli/selectors/index.js +274 -0
- package/dist/core/config.d.ts +18 -18
- package/dist/core/endpoints.d.ts +1 -0
- package/dist/core/endpoints.js +4 -0
- package/dist/core/introspect.d.ts +47 -0
- package/dist/core/introspect.js +94 -0
- package/dist/core/status.d.ts +39 -0
- package/dist/core/status.js +40 -0
- package/dist/core/token.d.ts +36 -1
- package/dist/core/token.js +43 -2
- package/dist/core/types.d.ts +114 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +6 -1
- package/package.json +84 -84
|
@@ -13,103 +13,140 @@ function generateReactShellComponent(config) {
|
|
|
13
13
|
const docsBase = config.product?.baseUrl
|
|
14
14
|
? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
|
|
15
15
|
: 'https://docs.duct.sh';
|
|
16
|
-
return `/**
|
|
17
|
-
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
18
|
-
*
|
|
19
|
-
* Mount this in your root layout. That's it.
|
|
20
|
-
* The shell is hosted by Duct. This component is a thin bridge.
|
|
21
|
-
* It renders the self-contained launcher, so do not add a second trigger.
|
|
22
|
-
*
|
|
23
|
-
* To customize: ${docsBase}/shell/customization
|
|
24
|
-
* To update: npx duct init --update
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
"use client"; // Required for Next.js App Router
|
|
28
|
-
|
|
29
|
-
import { DuctShell } from "@
|
|
30
|
-
|
|
31
|
-
export function DuctShellEmbed() {
|
|
32
|
-
const shellHost = process.env.NEXT_PUBLIC_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<DuctShell
|
|
36
|
-
shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID!}
|
|
37
|
-
shellHost={shellHost}
|
|
38
|
-
position="${position}"
|
|
39
|
-
// Optional: provide user context (not sensitive — this is metadata for the shell UI)
|
|
40
|
-
// userContext={{ theme: "light", locale: "en-US" }}
|
|
41
|
-
onTokenRequest={async (shellId) => {
|
|
42
|
-
// Called when the Duct shell needs to authenticate the current user.
|
|
43
|
-
// Your token endpoint (generated at /api/duct/token) returns a short-lived JWT.
|
|
44
|
-
const res = await fetch("/api/duct/token", {
|
|
45
|
-
method: "POST",
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
16
|
+
return `/**
|
|
17
|
+
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
18
|
+
*
|
|
19
|
+
* Mount this in your root layout. That's it.
|
|
20
|
+
* The shell is hosted by Duct. This component is a thin bridge.
|
|
21
|
+
* It renders the self-contained launcher, so do not add a second trigger.
|
|
22
|
+
*
|
|
23
|
+
* To customize: ${docsBase}/shell/customization
|
|
24
|
+
* To update: npx duct init --update
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
"use client"; // Required for Next.js App Router
|
|
28
|
+
|
|
29
|
+
import { DuctShell } from "@duct-sdk/sdk/react";
|
|
30
|
+
|
|
31
|
+
export function DuctShellEmbed() {
|
|
32
|
+
const shellHost = process.env.NEXT_PUBLIC_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<DuctShell
|
|
36
|
+
shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID!}
|
|
37
|
+
shellHost={shellHost}
|
|
38
|
+
position="${position}"
|
|
39
|
+
// Optional: provide user context (not sensitive — this is metadata for the shell UI)
|
|
40
|
+
// userContext={{ theme: "light", locale: "en-US" }}
|
|
41
|
+
onTokenRequest={async (shellId) => {
|
|
42
|
+
// Called when the Duct shell needs to authenticate the current user.
|
|
43
|
+
// Your token endpoint (generated at /api/duct/token) returns a short-lived JWT.
|
|
44
|
+
const res = await fetch("/api/duct/token", {
|
|
45
|
+
method: "POST",
|
|
46
|
+
credentials: "include",
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify({ shellId }),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
// Return empty string for unauthenticated/guest users
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const data = await res.json() as { token?: string };
|
|
57
|
+
return data.token ?? "";
|
|
58
|
+
}}
|
|
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
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Usage — add to your root layout:
|
|
71
|
+
//
|
|
72
|
+
// import { DuctShellEmbed } from "@/components/DuctShell";
|
|
73
|
+
//
|
|
74
|
+
// export default function RootLayout({ children }) {
|
|
75
|
+
// return (
|
|
76
|
+
// <html>
|
|
77
|
+
// <body>
|
|
78
|
+
// {children}
|
|
79
|
+
// <DuctShellEmbed />
|
|
80
|
+
// </body>
|
|
81
|
+
// </html>
|
|
82
|
+
// );
|
|
83
|
+
// }
|
|
84
|
+
//
|
|
85
|
+
// Shell ID: ${config.shellId}
|
|
86
|
+
// Welcome message: "${welcomeMessage}"
|
|
87
|
+
//
|
|
88
|
+
// ── Page Context Protocol (optional but recommended) ──────────────
|
|
89
|
+
//
|
|
90
|
+
// When users say "what does this mean?", "update that", or "why is there
|
|
91
|
+
// an error?" — the shell needs to know what they're looking at on screen.
|
|
92
|
+
//
|
|
93
|
+
// Add useDuctPageContext in each page-level component (NOT the layout).
|
|
94
|
+
// Return whatever structured data describes the current page state:
|
|
95
|
+
//
|
|
96
|
+
// // app/[resource]/[id]/page.tsx (adapt to your own routes)
|
|
97
|
+
// import { useDuctPageContext } from "@duct-sdk/sdk/react";
|
|
98
|
+
//
|
|
99
|
+
// export default function ResourcePage({ params }) {
|
|
100
|
+
// const item = useMyData(params.id); // your own data fetch
|
|
101
|
+
//
|
|
102
|
+
// useDuctPageContext(() => ({
|
|
103
|
+
// route: window.location.pathname,
|
|
104
|
+
// entity: {
|
|
105
|
+
// type: "your-entity-type", // what kind of thing is visible
|
|
106
|
+
// // Use your own key names — whatever your data model calls them:
|
|
107
|
+
// // ticketId: item.ticketId, sku: item.sku, ref: item.ref, ...
|
|
108
|
+
// ...item, // or spread the whole record
|
|
109
|
+
// },
|
|
110
|
+
// // errorState, selection, formState — add any that apply
|
|
111
|
+
// }), { shellHost: process.env.NEXT_PUBLIC_DUCT_SHELL_HOST });
|
|
112
|
+
//
|
|
113
|
+
// return <div>...</div>;
|
|
114
|
+
// }
|
|
115
|
+
//
|
|
116
|
+
// The hook listens for DUCT_REQUEST_CONTEXT from the Duct iframe and responds
|
|
117
|
+
// with the structured data. The shell uses this to resolve on-screen references
|
|
118
|
+
// without screenshots — grounded in your live data, not computer vision.
|
|
119
|
+
//
|
|
120
|
+
// Only add it on pages where users are likely to reference what they see.
|
|
121
|
+
// Pages without the hook return null — the shell still works, it just
|
|
122
|
+
// cannot resolve "this" or "that" when the parent doesn't respond.
|
|
86
123
|
`;
|
|
87
124
|
}
|
|
88
125
|
// ----------------------------------------------------------------
|
|
89
126
|
// Next.js App Router layout integration snippet
|
|
90
127
|
// ----------------------------------------------------------------
|
|
91
128
|
function generateNextLayoutSnippet(config) {
|
|
92
|
-
return `// Add to your app/layout.tsx:
|
|
93
|
-
// Generated by @duct/sdk
|
|
94
|
-
|
|
95
|
-
import { DuctShellEmbed } from "@/components/DuctShell";
|
|
96
|
-
|
|
97
|
-
// In your root layout component:
|
|
98
|
-
export default function RootLayout({
|
|
99
|
-
children,
|
|
100
|
-
}: {
|
|
101
|
-
children: React.ReactNode;
|
|
102
|
-
}) {
|
|
103
|
-
return (
|
|
104
|
-
<html lang="en">
|
|
105
|
-
<body>
|
|
106
|
-
{children}
|
|
107
|
-
{/* Duct shell — ${config.product.name} AI assistant */}
|
|
108
|
-
<DuctShellEmbed />
|
|
109
|
-
</body>
|
|
110
|
-
</html>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
129
|
+
return `// Add to your app/layout.tsx:
|
|
130
|
+
// Generated by @duct/sdk
|
|
131
|
+
|
|
132
|
+
import { DuctShellEmbed } from "@/components/DuctShell";
|
|
133
|
+
|
|
134
|
+
// In your root layout component:
|
|
135
|
+
export default function RootLayout({
|
|
136
|
+
children,
|
|
137
|
+
}: {
|
|
138
|
+
children: React.ReactNode;
|
|
139
|
+
}) {
|
|
140
|
+
return (
|
|
141
|
+
<html lang="en">
|
|
142
|
+
<body>
|
|
143
|
+
{children}
|
|
144
|
+
{/* Duct shell — ${config.product.name} AI assistant */}
|
|
145
|
+
<DuctShellEmbed />
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
113
150
|
`;
|
|
114
151
|
}
|
|
115
152
|
// ----------------------------------------------------------------
|
|
@@ -120,53 +157,54 @@ function generateRemixShellComponent(config) {
|
|
|
120
157
|
const docsBase = config.product?.baseUrl
|
|
121
158
|
? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
|
|
122
159
|
: 'https://docs.duct.sh';
|
|
123
|
-
return `/**
|
|
124
|
-
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
125
|
-
*
|
|
126
|
-
* Mount this in your root layout. That's it.
|
|
127
|
-
* The shell is hosted by Duct. This component is a thin bridge.
|
|
128
|
-
* It renders the self-contained launcher, so do not add a second trigger.
|
|
129
|
-
*
|
|
130
|
-
* To customize: ${docsBase}/shell/customization
|
|
131
|
-
* To update: npx duct init --update
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
import { DuctShell } from "@
|
|
135
|
-
|
|
136
|
-
export function DuctShellEmbed() {
|
|
137
|
-
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<DuctShell
|
|
141
|
-
shellId={import.meta.env.VITE_DUCT_SHELL_ID}
|
|
142
|
-
shellHost={shellHost}
|
|
143
|
-
position="${position}"
|
|
144
|
-
onTokenRequest={async (shellId) => {
|
|
145
|
-
const res = await fetch("/api/duct/token", {
|
|
146
|
-
method: "POST",
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
160
|
+
return `/**
|
|
161
|
+
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
162
|
+
*
|
|
163
|
+
* Mount this in your root layout. That's it.
|
|
164
|
+
* The shell is hosted by Duct. This component is a thin bridge.
|
|
165
|
+
* It renders the self-contained launcher, so do not add a second trigger.
|
|
166
|
+
*
|
|
167
|
+
* To customize: ${docsBase}/shell/customization
|
|
168
|
+
* To update: npx duct init --update
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
import { DuctShell } from "@duct-sdk/sdk/react";
|
|
172
|
+
|
|
173
|
+
export function DuctShellEmbed() {
|
|
174
|
+
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<DuctShell
|
|
178
|
+
shellId={import.meta.env.VITE_DUCT_SHELL_ID}
|
|
179
|
+
shellHost={shellHost}
|
|
180
|
+
position="${position}"
|
|
181
|
+
onTokenRequest={async (shellId) => {
|
|
182
|
+
const res = await fetch("/api/duct/token", {
|
|
183
|
+
method: "POST",
|
|
184
|
+
credentials: "include",
|
|
185
|
+
headers: { "Content-Type": "application/json" },
|
|
186
|
+
body: JSON.stringify({ shellId }),
|
|
187
|
+
});
|
|
188
|
+
if (!res.ok) return "";
|
|
189
|
+
const data = await res.json() as { token?: string };
|
|
190
|
+
return data.token ?? "";
|
|
191
|
+
}}
|
|
192
|
+
style={{
|
|
193
|
+
width: "380px",
|
|
194
|
+
height: "620px",
|
|
195
|
+
maxWidth: "calc(100vw - 32px)",
|
|
196
|
+
maxHeight: "calc(100vh - 110px)",
|
|
197
|
+
zIndex: 9999,
|
|
198
|
+
}}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Add to app/root.tsx:
|
|
204
|
+
// import { DuctShellEmbed } from "~/components/DuctShell";
|
|
205
|
+
// ... in your App component's return: <DuctShellEmbed />
|
|
206
|
+
//
|
|
207
|
+
// Shell ID: ${config.shellId}
|
|
170
208
|
`;
|
|
171
209
|
}
|
|
172
210
|
// ----------------------------------------------------------------
|
|
@@ -177,53 +215,54 @@ function generateViteShellComponent(config) {
|
|
|
177
215
|
const docsBase = config.product?.baseUrl
|
|
178
216
|
? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
|
|
179
217
|
: 'https://docs.duct.sh';
|
|
180
|
-
return `/**
|
|
181
|
-
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
182
|
-
*
|
|
183
|
-
* Mount this in your root layout. That's it.
|
|
184
|
-
* The shell is hosted by Duct. This component is a thin bridge.
|
|
185
|
-
* It renders the self-contained launcher, so do not add a second trigger.
|
|
186
|
-
*
|
|
187
|
-
* To customize: ${docsBase}/shell/customization
|
|
188
|
-
* To update: npx duct init --update
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
import { DuctShell } from "@
|
|
192
|
-
|
|
193
|
-
export function DuctShellEmbed() {
|
|
194
|
-
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
<DuctShell
|
|
198
|
-
shellId={import.meta.env.VITE_DUCT_SHELL_ID}
|
|
199
|
-
shellHost={shellHost}
|
|
200
|
-
position="${position}"
|
|
201
|
-
onTokenRequest={async (shellId) => {
|
|
202
|
-
const res = await fetch("/api/duct/token", {
|
|
203
|
-
method: "POST",
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
218
|
+
return `/**
|
|
219
|
+
* Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
220
|
+
*
|
|
221
|
+
* Mount this in your root layout. That's it.
|
|
222
|
+
* The shell is hosted by Duct. This component is a thin bridge.
|
|
223
|
+
* It renders the self-contained launcher, so do not add a second trigger.
|
|
224
|
+
*
|
|
225
|
+
* To customize: ${docsBase}/shell/customization
|
|
226
|
+
* To update: npx duct init --update
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
import { DuctShell } from "@duct-sdk/sdk/react";
|
|
230
|
+
|
|
231
|
+
export function DuctShellEmbed() {
|
|
232
|
+
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<DuctShell
|
|
236
|
+
shellId={import.meta.env.VITE_DUCT_SHELL_ID}
|
|
237
|
+
shellHost={shellHost}
|
|
238
|
+
position="${position}"
|
|
239
|
+
onTokenRequest={async (shellId) => {
|
|
240
|
+
const res = await fetch("/api/duct/token", {
|
|
241
|
+
method: "POST",
|
|
242
|
+
credentials: "include",
|
|
243
|
+
headers: { "Content-Type": "application/json" },
|
|
244
|
+
body: JSON.stringify({ shellId }),
|
|
245
|
+
});
|
|
246
|
+
if (!res.ok) return "";
|
|
247
|
+
const data = await res.json() as { token?: string };
|
|
248
|
+
return data.token ?? "";
|
|
249
|
+
}}
|
|
250
|
+
style={{
|
|
251
|
+
width: "380px",
|
|
252
|
+
height: "620px",
|
|
253
|
+
maxWidth: "calc(100vw - 32px)",
|
|
254
|
+
maxHeight: "calc(100vh - 110px)",
|
|
255
|
+
zIndex: 9999,
|
|
256
|
+
}}
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Add to src/App.tsx:
|
|
262
|
+
// import { DuctShellEmbed } from "./components/DuctShell";
|
|
263
|
+
// ... in your App component's return: <DuctShellEmbed />
|
|
264
|
+
//
|
|
265
|
+
// Shell ID: ${config.shellId}
|
|
227
266
|
`;
|
|
228
267
|
}
|
|
229
268
|
// ----------------------------------------------------------------
|
|
@@ -267,11 +306,11 @@ function getPublicShellHostEnvKey(framework) {
|
|
|
267
306
|
export function generateEnvTemplateForFramework(config, framework) {
|
|
268
307
|
const shellKey = getPublicShellEnvKey(framework);
|
|
269
308
|
const hostKey = getPublicShellHostEnvKey(framework);
|
|
270
|
-
return `# Duct credentials
|
|
271
|
-
${shellKey}=${config.shellId}
|
|
272
|
-
${hostKey}=http://localhost:3000
|
|
273
|
-
DUCT_SHELL_ID=${config.shellId}
|
|
274
|
-
DUCT_SECRET_KEY=<from-dashboard>
|
|
309
|
+
return `# Duct credentials
|
|
310
|
+
${shellKey}=${config.shellId}
|
|
311
|
+
${hostKey}=http://localhost:3000
|
|
312
|
+
DUCT_SHELL_ID=${config.shellId}
|
|
313
|
+
DUCT_SECRET_KEY=<from-dashboard>
|
|
275
314
|
`;
|
|
276
315
|
}
|
|
277
316
|
/** Returns the filename init.ts should write the env template to. */
|
|
@@ -292,99 +331,102 @@ function generateSvelteKitShellComponent(config) {
|
|
|
292
331
|
const docsBase = config.product?.baseUrl
|
|
293
332
|
? `https://docs.${new URL(config.product.baseUrl).hostname.split('.').slice(-2).join('.')}`
|
|
294
333
|
: 'https://docs.duct.sh';
|
|
295
|
-
return `<!--
|
|
296
|
-
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
297
|
-
|
|
298
|
-
Mount this in your root layout. That's it.
|
|
299
|
-
The shell is hosted by Duct. This component is a thin bridge.
|
|
300
|
-
|
|
301
|
-
To customize: ${docsBase}/shell/customization
|
|
302
|
-
To update: npx duct init --update
|
|
303
|
-
-->
|
|
304
|
-
|
|
305
|
-
<script lang="ts">
|
|
306
|
-
import { onMount } from "svelte";
|
|
307
|
-
import { env } from "$env/dynamic/public";
|
|
308
|
-
|
|
309
|
-
let open = false;
|
|
310
|
-
|
|
311
|
-
const shellId = env.PUBLIC_DUCT_SHELL_ID ?? "";
|
|
312
|
-
const shellHost = env.PUBLIC_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
313
|
-
const shellUrl = \`\${shellHost}/\${shellId}\`;
|
|
314
|
-
|
|
315
|
-
async function getToken(): Promise<string> {
|
|
316
|
-
const res = await fetch("/api/duct/token", {
|
|
317
|
-
method: "POST",
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
if (event.data?.type === "
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
334
|
+
return `<!--
|
|
335
|
+
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
336
|
+
|
|
337
|
+
Mount this in your root layout. That's it.
|
|
338
|
+
The shell is hosted by Duct. This component is a thin bridge.
|
|
339
|
+
|
|
340
|
+
To customize: ${docsBase}/shell/customization
|
|
341
|
+
To update: npx duct init --update
|
|
342
|
+
-->
|
|
343
|
+
|
|
344
|
+
<script lang="ts">
|
|
345
|
+
import { onMount } from "svelte";
|
|
346
|
+
import { env } from "$env/dynamic/public";
|
|
347
|
+
|
|
348
|
+
let open = false;
|
|
349
|
+
|
|
350
|
+
const shellId = env.PUBLIC_DUCT_SHELL_ID ?? "";
|
|
351
|
+
const shellHost = env.PUBLIC_DUCT_SHELL_HOST ?? "http://localhost:3000";
|
|
352
|
+
const shellUrl = \`\${shellHost}/\${shellId}\`;
|
|
353
|
+
|
|
354
|
+
async function getToken(): Promise<string> {
|
|
355
|
+
const res = await fetch("/api/duct/token", {
|
|
356
|
+
method: "POST",
|
|
357
|
+
credentials: "include",
|
|
358
|
+
headers: { "Content-Type": "application/json" },
|
|
359
|
+
body: JSON.stringify({ shellId }),
|
|
360
|
+
});
|
|
361
|
+
if (!res.ok) return "";
|
|
362
|
+
const data = await res.json();
|
|
363
|
+
return data.token ?? "";
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Listen for postMessage events from the shell iframe
|
|
367
|
+
onMount(() => {
|
|
368
|
+
const handleMessage = async (event: MessageEvent) => {
|
|
369
|
+
// Only handle messages from the configured shell host (prevents origin spoofing)
|
|
370
|
+
if (event.origin !== shellHost) return;
|
|
371
|
+
if (event.data?.type === "DUCT_REQUEST_TOKEN") {
|
|
372
|
+
const token = await getToken();
|
|
373
|
+
(event.source as Window)?.postMessage(
|
|
374
|
+
{ type: "DUCT_TOKEN_RESPONSE", token, requestId: event.data.requestId },
|
|
375
|
+
shellHost // Always target the known shell host, never echo event.origin
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
if (event.data?.type === "DUCT_CLOSE") {
|
|
379
|
+
open = false;
|
|
380
|
+
}
|
|
381
|
+
if (event.data?.type === "DUCT_DEEPLINK_NAVIGATE") {
|
|
382
|
+
window.location.href = event.data.url;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
window.addEventListener("message", handleMessage);
|
|
386
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
387
|
+
});
|
|
388
|
+
</script>
|
|
389
|
+
|
|
390
|
+
<!-- Trigger button -->
|
|
391
|
+
<button
|
|
392
|
+
on:click={() => (open = !open)}
|
|
393
|
+
style="position:fixed;bottom:24px;right:24px;z-index:10000;background:#f97316;color:#fff;border:none;border-radius:50%;width:52px;height:52px;cursor:pointer;font-size:22px;box-shadow:0 4px 14px rgba(0,0,0,0.18);"
|
|
394
|
+
aria-label="Open {${config.product.name}} assistant"
|
|
395
|
+
>
|
|
396
|
+
{#if open}✕{:else}💬{/if}
|
|
397
|
+
</button>
|
|
398
|
+
|
|
399
|
+
<!-- Slide-in animation for the shell panel -->
|
|
400
|
+
<style>
|
|
401
|
+
@keyframes duct-slidein {
|
|
402
|
+
from { opacity: 0; transform: translateY(100%); }
|
|
403
|
+
to { opacity: 1; transform: translateY(0); }
|
|
404
|
+
}
|
|
405
|
+
.duct-shell-panel {
|
|
406
|
+
animation: duct-slidein 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
407
|
+
}
|
|
408
|
+
</style>
|
|
409
|
+
|
|
410
|
+
<!-- Shell iframe -->
|
|
411
|
+
{#if open}
|
|
412
|
+
<div
|
|
413
|
+
class="duct-shell-panel"
|
|
414
|
+
style="position:fixed;bottom:86px;right:24px;width:380px;height:620px;max-width:calc(100vw - 32px);max-height:calc(100vh - 110px);border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.16);z-index:9999;overflow:hidden;"
|
|
415
|
+
>
|
|
416
|
+
<iframe
|
|
417
|
+
src={shellUrl}
|
|
418
|
+
title="${config.product.name} assistant"
|
|
419
|
+
style="width:100%;height:100%;border:none;display:block;"
|
|
420
|
+
allow="clipboard-write"
|
|
421
|
+
/>
|
|
422
|
+
</div>
|
|
423
|
+
{/if}
|
|
424
|
+
|
|
425
|
+
<!-- Usage: add to +layout.svelte
|
|
426
|
+
import DuctShell from "$lib/components/DuctShell.svelte";
|
|
427
|
+
<DuctShell />
|
|
428
|
+
Shell ID: ${config.shellId}
|
|
429
|
+
-->
|
|
388
430
|
`;
|
|
389
431
|
}
|
|
390
432
|
// ----------------------------------------------------------------
|
|
@@ -403,107 +445,107 @@ function generateVue3ShellComponent(config) {
|
|
|
403
445
|
const panelStyle = position === "bottom-left"
|
|
404
446
|
? "bottom: 86px; left: 24px;"
|
|
405
447
|
: "bottom: 86px; right: 24px;";
|
|
406
|
-
return `<!--
|
|
407
|
-
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
408
|
-
|
|
409
|
-
Mount this in your root App.vue (or a layout component).
|
|
410
|
-
The shell is hosted by Duct. This is a thin postMessage bridge.
|
|
411
|
-
|
|
412
|
-
To customize: ${docsBase}/shell/customization
|
|
413
|
-
To update: npx duct init --update
|
|
414
|
-
-->
|
|
415
|
-
|
|
416
|
-
<template>
|
|
417
|
-
<!-- Trigger button -->
|
|
418
|
-
<button
|
|
419
|
-
@click="open = !open"
|
|
420
|
-
:aria-label="\`Open ${config.product.name} assistant\`"
|
|
421
|
-
style="position:fixed;${positionStyle}z-index:10000;background:#f97316;color:#fff;border:none;border-radius:50%;width:52px;height:52px;cursor:pointer;font-size:22px;box-shadow:0 4px 14px rgba(0,0,0,0.18);"
|
|
422
|
-
>
|
|
423
|
-
{{ open ? '✕' : '💬' }}
|
|
424
|
-
</button>
|
|
425
|
-
|
|
426
|
-
<!-- Shell panel -->
|
|
427
|
-
<Transition name="duct-slide">
|
|
428
|
-
<div
|
|
429
|
-
v-if="open"
|
|
430
|
-
style="position:fixed;${panelStyle}width:${width}px;height:${height}px;max-width:calc(100vw - 32px);max-height:calc(100vh - 110px);border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.16);z-index:9999;overflow:hidden;"
|
|
431
|
-
>
|
|
432
|
-
<iframe
|
|
433
|
-
ref="iframeRef"
|
|
434
|
-
:src="shellUrl"
|
|
435
|
-
title="${config.product.name} assistant"
|
|
436
|
-
style="width:100%;height:100%;border:none;display:block;"
|
|
437
|
-
allow="clipboard-write"
|
|
438
|
-
/>
|
|
439
|
-
</div>
|
|
440
|
-
</Transition>
|
|
441
|
-
</template>
|
|
442
|
-
|
|
443
|
-
<script setup lang="ts">
|
|
444
|
-
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
|
445
|
-
|
|
446
|
-
const open = ref(false);
|
|
447
|
-
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
448
|
-
|
|
449
|
-
const shellId = import.meta.env.VITE_DUCT_SHELL_ID as string ?? '';
|
|
450
|
-
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST as string ?? 'http://localhost:3000';
|
|
451
|
-
const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
|
|
452
|
-
|
|
453
|
-
async function getToken(): Promise<string> {
|
|
454
|
-
try {
|
|
455
|
-
const res = await fetch('/api/duct/token', {
|
|
456
|
-
method: 'POST',
|
|
457
|
-
headers: { 'Content-Type': 'application/json' },
|
|
458
|
-
body: JSON.stringify({ shellId }),
|
|
459
|
-
});
|
|
460
|
-
if (!res.ok) return '';
|
|
461
|
-
const data = await res.json() as { token?: string };
|
|
462
|
-
return data.token ?? '';
|
|
463
|
-
} catch {
|
|
464
|
-
return '';
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
async function handleMessage(event: MessageEvent) {
|
|
469
|
-
if (event.data?.type === 'DUCT_REQUEST_TOKEN') {
|
|
470
|
-
const token = await getToken();
|
|
471
|
-
iframeRef.value?.contentWindow?.postMessage(
|
|
472
|
-
{ type: 'DUCT_TOKEN_RESPONSE', token, requestId: event.data.requestId },
|
|
473
|
-
shellHost
|
|
474
|
-
);
|
|
475
|
-
} else if (event.data?.type === 'DUCT_CLOSE') {
|
|
476
|
-
open.value = false;
|
|
477
|
-
} else if (event.data?.type === 'DUCT_DEEPLINK_NAVIGATE') {
|
|
478
|
-
window.location.href = event.data.url as string;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
onMounted(() => window.addEventListener('message', handleMessage));
|
|
483
|
-
onUnmounted(() => window.removeEventListener('message', handleMessage));
|
|
484
|
-
</script>
|
|
485
|
-
|
|
486
|
-
<style scoped>
|
|
487
|
-
.duct-slide-enter-active {
|
|
488
|
-
animation: duct-slidein 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
489
|
-
}
|
|
490
|
-
.duct-slide-leave-active {
|
|
491
|
-
animation: duct-slidein 0.2s cubic-bezier(0.16, 1, 0.3, 1) reverse both;
|
|
492
|
-
}
|
|
493
|
-
@keyframes duct-slidein {
|
|
494
|
-
from { opacity: 0; transform: translateY(100%); }
|
|
495
|
-
to { opacity: 1; transform: translateY(0); }
|
|
496
|
-
}
|
|
497
|
-
</style>
|
|
498
|
-
|
|
499
|
-
<!--
|
|
500
|
-
Usage — add to src/App.vue:
|
|
501
|
-
|
|
502
|
-
import DuctShell from './components/DuctShell.vue'
|
|
503
|
-
<DuctShell />
|
|
504
|
-
|
|
505
|
-
Shell ID: ${config.shellId}
|
|
506
|
-
-->
|
|
448
|
+
return `<!--
|
|
449
|
+
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
450
|
+
|
|
451
|
+
Mount this in your root App.vue (or a layout component).
|
|
452
|
+
The shell is hosted by Duct. This is a thin postMessage bridge.
|
|
453
|
+
|
|
454
|
+
To customize: ${docsBase}/shell/customization
|
|
455
|
+
To update: npx duct init --update
|
|
456
|
+
-->
|
|
457
|
+
|
|
458
|
+
<template>
|
|
459
|
+
<!-- Trigger button -->
|
|
460
|
+
<button
|
|
461
|
+
@click="open = !open"
|
|
462
|
+
:aria-label="\`Open ${config.product.name} assistant\`"
|
|
463
|
+
style="position:fixed;${positionStyle}z-index:10000;background:#f97316;color:#fff;border:none;border-radius:50%;width:52px;height:52px;cursor:pointer;font-size:22px;box-shadow:0 4px 14px rgba(0,0,0,0.18);"
|
|
464
|
+
>
|
|
465
|
+
{{ open ? '✕' : '💬' }}
|
|
466
|
+
</button>
|
|
467
|
+
|
|
468
|
+
<!-- Shell panel -->
|
|
469
|
+
<Transition name="duct-slide">
|
|
470
|
+
<div
|
|
471
|
+
v-if="open"
|
|
472
|
+
style="position:fixed;${panelStyle}width:${width}px;height:${height}px;max-width:calc(100vw - 32px);max-height:calc(100vh - 110px);border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.16);z-index:9999;overflow:hidden;"
|
|
473
|
+
>
|
|
474
|
+
<iframe
|
|
475
|
+
ref="iframeRef"
|
|
476
|
+
:src="shellUrl"
|
|
477
|
+
title="${config.product.name} assistant"
|
|
478
|
+
style="width:100%;height:100%;border:none;display:block;"
|
|
479
|
+
allow="clipboard-write"
|
|
480
|
+
/>
|
|
481
|
+
</div>
|
|
482
|
+
</Transition>
|
|
483
|
+
</template>
|
|
484
|
+
|
|
485
|
+
<script setup lang="ts">
|
|
486
|
+
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
|
487
|
+
|
|
488
|
+
const open = ref(false);
|
|
489
|
+
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
490
|
+
|
|
491
|
+
const shellId = import.meta.env.VITE_DUCT_SHELL_ID as string ?? '';
|
|
492
|
+
const shellHost = import.meta.env.VITE_DUCT_SHELL_HOST as string ?? 'http://localhost:3000';
|
|
493
|
+
const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
|
|
494
|
+
|
|
495
|
+
async function getToken(): Promise<string> {
|
|
496
|
+
try {
|
|
497
|
+
const res = await fetch('/api/duct/token', {
|
|
498
|
+
method: 'POST',
|
|
499
|
+
headers: { 'Content-Type': 'application/json' },
|
|
500
|
+
body: JSON.stringify({ shellId }),
|
|
501
|
+
});
|
|
502
|
+
if (!res.ok) return '';
|
|
503
|
+
const data = await res.json() as { token?: string };
|
|
504
|
+
return data.token ?? '';
|
|
505
|
+
} catch {
|
|
506
|
+
return '';
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async function handleMessage(event: MessageEvent) {
|
|
511
|
+
if (event.data?.type === 'DUCT_REQUEST_TOKEN') {
|
|
512
|
+
const token = await getToken();
|
|
513
|
+
iframeRef.value?.contentWindow?.postMessage(
|
|
514
|
+
{ type: 'DUCT_TOKEN_RESPONSE', token, requestId: event.data.requestId },
|
|
515
|
+
shellHost
|
|
516
|
+
);
|
|
517
|
+
} else if (event.data?.type === 'DUCT_CLOSE') {
|
|
518
|
+
open.value = false;
|
|
519
|
+
} else if (event.data?.type === 'DUCT_DEEPLINK_NAVIGATE') {
|
|
520
|
+
window.location.href = event.data.url as string;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
onMounted(() => window.addEventListener('message', handleMessage));
|
|
525
|
+
onUnmounted(() => window.removeEventListener('message', handleMessage));
|
|
526
|
+
</script>
|
|
527
|
+
|
|
528
|
+
<style scoped>
|
|
529
|
+
.duct-slide-enter-active {
|
|
530
|
+
animation: duct-slidein 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
531
|
+
}
|
|
532
|
+
.duct-slide-leave-active {
|
|
533
|
+
animation: duct-slidein 0.2s cubic-bezier(0.16, 1, 0.3, 1) reverse both;
|
|
534
|
+
}
|
|
535
|
+
@keyframes duct-slidein {
|
|
536
|
+
from { opacity: 0; transform: translateY(100%); }
|
|
537
|
+
to { opacity: 1; transform: translateY(0); }
|
|
538
|
+
}
|
|
539
|
+
</style>
|
|
540
|
+
|
|
541
|
+
<!--
|
|
542
|
+
Usage — add to src/App.vue:
|
|
543
|
+
|
|
544
|
+
import DuctShell from './components/DuctShell.vue'
|
|
545
|
+
<DuctShell />
|
|
546
|
+
|
|
547
|
+
Shell ID: ${config.shellId}
|
|
548
|
+
-->
|
|
507
549
|
`;
|
|
508
550
|
}
|
|
509
551
|
// ----------------------------------------------------------------
|
|
@@ -522,112 +564,112 @@ function generateNuxtShellComponent(config) {
|
|
|
522
564
|
const panelStyle = position === "bottom-left"
|
|
523
565
|
? "bottom: 86px; left: 24px;"
|
|
524
566
|
: "bottom: 86px; right: 24px;";
|
|
525
|
-
return `<!--
|
|
526
|
-
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
527
|
-
|
|
528
|
-
Mount this in your app.vue or a layouts file.
|
|
529
|
-
The shell is hosted by Duct. This is a thin postMessage bridge.
|
|
530
|
-
|
|
531
|
-
To customize: ${docsBase}/shell/customization
|
|
532
|
-
To update: npx duct init --update
|
|
533
|
-
-->
|
|
534
|
-
|
|
535
|
-
<template>
|
|
536
|
-
<!-- Trigger button -->
|
|
537
|
-
<button
|
|
538
|
-
@click="open = !open"
|
|
539
|
-
:aria-label="\`Open ${config.product.name} assistant\`"
|
|
540
|
-
style="position:fixed;${positionStyle}z-index:10000;background:#f97316;color:#fff;border:none;border-radius:50%;width:52px;height:52px;cursor:pointer;font-size:22px;box-shadow:0 4px 14px rgba(0,0,0,0.18);"
|
|
541
|
-
>
|
|
542
|
-
{{ open ? '✕' : '💬' }}
|
|
543
|
-
</button>
|
|
544
|
-
|
|
545
|
-
<!-- Shell panel -->
|
|
546
|
-
<Transition name="duct-slide">
|
|
547
|
-
<div
|
|
548
|
-
v-if="open"
|
|
549
|
-
style="position:fixed;${panelStyle}width:${width}px;height:${height}px;max-width:calc(100vw - 32px);max-height:calc(100vh - 110px);border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.16);z-index:9999;overflow:hidden;"
|
|
550
|
-
>
|
|
551
|
-
<iframe
|
|
552
|
-
ref="iframeRef"
|
|
553
|
-
:src="shellUrl"
|
|
554
|
-
title="${config.product.name} assistant"
|
|
555
|
-
style="width:100%;height:100%;border:none;display:block;"
|
|
556
|
-
allow="clipboard-write"
|
|
557
|
-
/>
|
|
558
|
-
</div>
|
|
559
|
-
</Transition>
|
|
560
|
-
</template>
|
|
561
|
-
|
|
562
|
-
<script setup lang="ts">
|
|
563
|
-
const open = ref(false);
|
|
564
|
-
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
565
|
-
|
|
566
|
-
// Nuxt uses NUXT_PUBLIC_ prefix in nuxt.config.ts runtimeConfig.public
|
|
567
|
-
const config = useRuntimeConfig();
|
|
568
|
-
const shellId = (config.public.ductShellId as string) ?? '';
|
|
569
|
-
const shellHost = (config.public.ductShellHost as string) ?? 'http://localhost:3000';
|
|
570
|
-
const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
|
|
571
|
-
|
|
572
|
-
async function getToken(): Promise<string> {
|
|
573
|
-
try {
|
|
574
|
-
const data = await $fetch<{ token?: string }>('/api/duct/token', {
|
|
575
|
-
method: 'POST',
|
|
576
|
-
body: { shellId },
|
|
577
|
-
});
|
|
578
|
-
return data.token ?? '';
|
|
579
|
-
} catch {
|
|
580
|
-
return '';
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
async function handleMessage(event: MessageEvent) {
|
|
585
|
-
if (event.data?.type === 'DUCT_REQUEST_TOKEN') {
|
|
586
|
-
const token = await getToken();
|
|
587
|
-
iframeRef.value?.contentWindow?.postMessage(
|
|
588
|
-
{ type: 'DUCT_TOKEN_RESPONSE', token, requestId: event.data.requestId },
|
|
589
|
-
shellHost
|
|
590
|
-
);
|
|
591
|
-
} else if (event.data?.type === 'DUCT_CLOSE') {
|
|
592
|
-
open.value = false;
|
|
593
|
-
} else if (event.data?.type === 'DUCT_DEEPLINK_NAVIGATE') {
|
|
594
|
-
await navigateTo(event.data.url as string, { external: true });
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
onMounted(() => window.addEventListener('message', handleMessage));
|
|
599
|
-
onUnmounted(() => window.removeEventListener('message', handleMessage));
|
|
600
|
-
</script>
|
|
601
|
-
|
|
602
|
-
<style scoped>
|
|
603
|
-
.duct-slide-enter-active {
|
|
604
|
-
animation: duct-slidein 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
605
|
-
}
|
|
606
|
-
.duct-slide-leave-active {
|
|
607
|
-
animation: duct-slidein 0.2s cubic-bezier(0.16, 1, 0.3, 1) reverse both;
|
|
608
|
-
}
|
|
609
|
-
@keyframes duct-slidein {
|
|
610
|
-
from { opacity: 0; transform: translateY(100%); }
|
|
611
|
-
to { opacity: 1; transform: translateY(0); }
|
|
612
|
-
}
|
|
613
|
-
</style>
|
|
614
|
-
|
|
615
|
-
<!--
|
|
616
|
-
Usage — add to app.vue or layouts/default.vue:
|
|
617
|
-
|
|
618
|
-
import DuctShell from '~/components/DuctShell.vue'
|
|
619
|
-
<DuctShell />
|
|
620
|
-
|
|
621
|
-
Add to nuxt.config.ts:
|
|
622
|
-
runtimeConfig: {
|
|
623
|
-
public: {
|
|
624
|
-
ductShellId: process.env.NUXT_PUBLIC_DUCT_SHELL_ID,
|
|
625
|
-
ductShellHost: process.env.NUXT_PUBLIC_DUCT_SHELL_HOST ?? 'http://localhost:3000',
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
Shell ID: ${config.shellId}
|
|
630
|
-
-->
|
|
567
|
+
return `<!--
|
|
568
|
+
Duct Shell Widget — auto-generated by \`npx duct init\`
|
|
569
|
+
|
|
570
|
+
Mount this in your app.vue or a layouts file.
|
|
571
|
+
The shell is hosted by Duct. This is a thin postMessage bridge.
|
|
572
|
+
|
|
573
|
+
To customize: ${docsBase}/shell/customization
|
|
574
|
+
To update: npx duct init --update
|
|
575
|
+
-->
|
|
576
|
+
|
|
577
|
+
<template>
|
|
578
|
+
<!-- Trigger button -->
|
|
579
|
+
<button
|
|
580
|
+
@click="open = !open"
|
|
581
|
+
:aria-label="\`Open ${config.product.name} assistant\`"
|
|
582
|
+
style="position:fixed;${positionStyle}z-index:10000;background:#f97316;color:#fff;border:none;border-radius:50%;width:52px;height:52px;cursor:pointer;font-size:22px;box-shadow:0 4px 14px rgba(0,0,0,0.18);"
|
|
583
|
+
>
|
|
584
|
+
{{ open ? '✕' : '💬' }}
|
|
585
|
+
</button>
|
|
586
|
+
|
|
587
|
+
<!-- Shell panel -->
|
|
588
|
+
<Transition name="duct-slide">
|
|
589
|
+
<div
|
|
590
|
+
v-if="open"
|
|
591
|
+
style="position:fixed;${panelStyle}width:${width}px;height:${height}px;max-width:calc(100vw - 32px);max-height:calc(100vh - 110px);border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.16);z-index:9999;overflow:hidden;"
|
|
592
|
+
>
|
|
593
|
+
<iframe
|
|
594
|
+
ref="iframeRef"
|
|
595
|
+
:src="shellUrl"
|
|
596
|
+
title="${config.product.name} assistant"
|
|
597
|
+
style="width:100%;height:100%;border:none;display:block;"
|
|
598
|
+
allow="clipboard-write"
|
|
599
|
+
/>
|
|
600
|
+
</div>
|
|
601
|
+
</Transition>
|
|
602
|
+
</template>
|
|
603
|
+
|
|
604
|
+
<script setup lang="ts">
|
|
605
|
+
const open = ref(false);
|
|
606
|
+
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
|
607
|
+
|
|
608
|
+
// Nuxt uses NUXT_PUBLIC_ prefix in nuxt.config.ts runtimeConfig.public
|
|
609
|
+
const config = useRuntimeConfig();
|
|
610
|
+
const shellId = (config.public.ductShellId as string) ?? '';
|
|
611
|
+
const shellHost = (config.public.ductShellHost as string) ?? 'http://localhost:3000';
|
|
612
|
+
const shellUrl = computed(() => \`\${shellHost}/\${shellId}\`);
|
|
613
|
+
|
|
614
|
+
async function getToken(): Promise<string> {
|
|
615
|
+
try {
|
|
616
|
+
const data = await $fetch<{ token?: string }>('/api/duct/token', {
|
|
617
|
+
method: 'POST',
|
|
618
|
+
body: { shellId },
|
|
619
|
+
});
|
|
620
|
+
return data.token ?? '';
|
|
621
|
+
} catch {
|
|
622
|
+
return '';
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
async function handleMessage(event: MessageEvent) {
|
|
627
|
+
if (event.data?.type === 'DUCT_REQUEST_TOKEN') {
|
|
628
|
+
const token = await getToken();
|
|
629
|
+
iframeRef.value?.contentWindow?.postMessage(
|
|
630
|
+
{ type: 'DUCT_TOKEN_RESPONSE', token, requestId: event.data.requestId },
|
|
631
|
+
shellHost
|
|
632
|
+
);
|
|
633
|
+
} else if (event.data?.type === 'DUCT_CLOSE') {
|
|
634
|
+
open.value = false;
|
|
635
|
+
} else if (event.data?.type === 'DUCT_DEEPLINK_NAVIGATE') {
|
|
636
|
+
await navigateTo(event.data.url as string, { external: true });
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
onMounted(() => window.addEventListener('message', handleMessage));
|
|
641
|
+
onUnmounted(() => window.removeEventListener('message', handleMessage));
|
|
642
|
+
</script>
|
|
643
|
+
|
|
644
|
+
<style scoped>
|
|
645
|
+
.duct-slide-enter-active {
|
|
646
|
+
animation: duct-slidein 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
647
|
+
}
|
|
648
|
+
.duct-slide-leave-active {
|
|
649
|
+
animation: duct-slidein 0.2s cubic-bezier(0.16, 1, 0.3, 1) reverse both;
|
|
650
|
+
}
|
|
651
|
+
@keyframes duct-slidein {
|
|
652
|
+
from { opacity: 0; transform: translateY(100%); }
|
|
653
|
+
to { opacity: 1; transform: translateY(0); }
|
|
654
|
+
}
|
|
655
|
+
</style>
|
|
656
|
+
|
|
657
|
+
<!--
|
|
658
|
+
Usage — add to app.vue or layouts/default.vue:
|
|
659
|
+
|
|
660
|
+
import DuctShell from '~/components/DuctShell.vue'
|
|
661
|
+
<DuctShell />
|
|
662
|
+
|
|
663
|
+
Add to nuxt.config.ts:
|
|
664
|
+
runtimeConfig: {
|
|
665
|
+
public: {
|
|
666
|
+
ductShellId: process.env.NUXT_PUBLIC_DUCT_SHELL_ID,
|
|
667
|
+
ductShellHost: process.env.NUXT_PUBLIC_DUCT_SHELL_HOST ?? 'http://localhost:3000',
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
Shell ID: ${config.shellId}
|
|
672
|
+
-->
|
|
631
673
|
`;
|
|
632
674
|
}
|
|
633
675
|
// ----------------------------------------------------------------
|