@agent-native/core 0.15.1 → 0.15.2
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/dist/server/auth.d.ts +3 -4
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js.map +1 -1
- package/dist/server/google-auth-plugin.d.ts +2 -2
- package/dist/server/google-auth-plugin.d.ts.map +1 -1
- package/dist/server/google-auth-plugin.js +25 -3
- package/dist/server/google-auth-plugin.js.map +1 -1
- package/dist/server/onboarding-html.d.ts +2 -2
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +27 -7
- package/dist/server/onboarding-html.js.map +1 -1
- package/package.json +1 -1
- package/dist/client/dev-mode.d.ts +0 -14
- package/dist/client/dev-mode.d.ts.map +0 -1
- package/dist/client/dev-mode.js +0 -14
- package/dist/client/dev-mode.js.map +0 -1
- package/dist/client/extensions/EmbeddedTool.d.ts +0 -20
- package/dist/client/extensions/EmbeddedTool.d.ts.map +0 -1
- package/dist/client/extensions/EmbeddedTool.js +0 -199
- package/dist/client/extensions/EmbeddedTool.js.map +0 -1
- package/dist/client/extensions/ToolEditor.d.ts +0 -5
- package/dist/client/extensions/ToolEditor.d.ts.map +0 -1
- package/dist/client/extensions/ToolEditor.js +0 -129
- package/dist/client/extensions/ToolEditor.js.map +0 -1
- package/dist/client/extensions/ToolViewer.d.ts +0 -5
- package/dist/client/extensions/ToolViewer.d.ts.map +0 -1
- package/dist/client/extensions/ToolViewer.js +0 -400
- package/dist/client/extensions/ToolViewer.js.map +0 -1
- package/dist/client/extensions/ToolViewerPage.d.ts +0 -2
- package/dist/client/extensions/ToolViewerPage.d.ts.map +0 -1
- package/dist/client/extensions/ToolViewerPage.js +0 -24
- package/dist/client/extensions/ToolViewerPage.js.map +0 -1
- package/dist/client/extensions/ToolsListPage.d.ts +0 -2
- package/dist/client/extensions/ToolsListPage.d.ts.map +0 -1
- package/dist/client/extensions/ToolsListPage.js +0 -67
- package/dist/client/extensions/ToolsListPage.js.map +0 -1
- package/dist/client/extensions/ToolsSidebarSection.d.ts +0 -2
- package/dist/client/extensions/ToolsSidebarSection.d.ts.map +0 -1
- package/dist/client/extensions/ToolsSidebarSection.js +0 -236
- package/dist/client/extensions/ToolsSidebarSection.js.map +0 -1
- package/dist/client/extensions/tool-order.d.ts +0 -7
- package/dist/client/extensions/tool-order.d.ts.map +0 -1
- package/dist/client/extensions/tool-order.js +0 -47
- package/dist/client/extensions/tool-order.js.map +0 -1
- package/dist/client/tools/EmbeddedTool.d.ts +0 -20
- package/dist/client/tools/EmbeddedTool.d.ts.map +0 -1
- package/dist/client/tools/EmbeddedTool.js +0 -199
- package/dist/client/tools/EmbeddedTool.js.map +0 -1
- package/dist/client/tools/ExtensionSlot.d.ts +0 -27
- package/dist/client/tools/ExtensionSlot.d.ts.map +0 -1
- package/dist/client/tools/ExtensionSlot.js +0 -96
- package/dist/client/tools/ExtensionSlot.js.map +0 -1
- package/dist/client/tools/ToolEditor.d.ts +0 -5
- package/dist/client/tools/ToolEditor.d.ts.map +0 -1
- package/dist/client/tools/ToolEditor.js +0 -129
- package/dist/client/tools/ToolEditor.js.map +0 -1
- package/dist/client/tools/ToolViewer.d.ts +0 -5
- package/dist/client/tools/ToolViewer.d.ts.map +0 -1
- package/dist/client/tools/ToolViewer.js +0 -400
- package/dist/client/tools/ToolViewer.js.map +0 -1
- package/dist/client/tools/ToolViewerPage.d.ts +0 -2
- package/dist/client/tools/ToolViewerPage.d.ts.map +0 -1
- package/dist/client/tools/ToolViewerPage.js +0 -24
- package/dist/client/tools/ToolViewerPage.js.map +0 -1
- package/dist/client/tools/ToolsListPage.d.ts +0 -2
- package/dist/client/tools/ToolsListPage.d.ts.map +0 -1
- package/dist/client/tools/ToolsListPage.js +0 -67
- package/dist/client/tools/ToolsListPage.js.map +0 -1
- package/dist/client/tools/ToolsSidebarSection.d.ts +0 -2
- package/dist/client/tools/ToolsSidebarSection.d.ts.map +0 -1
- package/dist/client/tools/ToolsSidebarSection.js +0 -236
- package/dist/client/tools/ToolsSidebarSection.js.map +0 -1
- package/dist/client/tools/iframe-bridge.d.ts +0 -38
- package/dist/client/tools/iframe-bridge.d.ts.map +0 -1
- package/dist/client/tools/iframe-bridge.js +0 -207
- package/dist/client/tools/iframe-bridge.js.map +0 -1
- package/dist/client/tools/index.d.ts +0 -8
- package/dist/client/tools/index.d.ts.map +0 -1
- package/dist/client/tools/index.js +0 -8
- package/dist/client/tools/index.js.map +0 -1
- package/dist/client/tools/tool-order.d.ts +0 -7
- package/dist/client/tools/tool-order.d.ts.map +0 -1
- package/dist/client/tools/tool-order.js +0 -47
- package/dist/client/tools/tool-order.js.map +0 -1
- package/dist/server/local-migration.d.ts +0 -41
- package/dist/server/local-migration.d.ts.map +0 -1
- package/dist/server/local-migration.js +0 -235
- package/dist/server/local-migration.js.map +0 -1
- package/dist/tools/actions.d.ts +0 -3
- package/dist/tools/actions.d.ts.map +0 -1
- package/dist/tools/actions.js +0 -272
- package/dist/tools/actions.js.map +0 -1
- package/dist/tools/fetch-tool.d.ts +0 -23
- package/dist/tools/fetch-tool.d.ts.map +0 -1
- package/dist/tools/fetch-tool.js +0 -178
- package/dist/tools/fetch-tool.js.map +0 -1
- package/dist/tools/html-shell.d.ts +0 -45
- package/dist/tools/html-shell.d.ts.map +0 -1
- package/dist/tools/html-shell.js +0 -514
- package/dist/tools/html-shell.js.map +0 -1
- package/dist/tools/proxy-security.d.ts +0 -12
- package/dist/tools/proxy-security.d.ts.map +0 -1
- package/dist/tools/proxy-security.js +0 -158
- package/dist/tools/proxy-security.js.map +0 -1
- package/dist/tools/routes.d.ts +0 -2
- package/dist/tools/routes.d.ts.map +0 -1
- package/dist/tools/routes.js +0 -627
- package/dist/tools/routes.js.map +0 -1
- package/dist/tools/schema.d.ts +0 -664
- package/dist/tools/schema.d.ts.map +0 -1
- package/dist/tools/schema.js +0 -146
- package/dist/tools/schema.js.map +0 -1
- package/dist/tools/slots/routes.d.ts +0 -15
- package/dist/tools/slots/routes.d.ts.map +0 -1
- package/dist/tools/slots/routes.js +0 -94
- package/dist/tools/slots/routes.js.map +0 -1
- package/dist/tools/slots/schema.d.ts +0 -303
- package/dist/tools/slots/schema.d.ts.map +0 -1
- package/dist/tools/slots/schema.js +0 -76
- package/dist/tools/slots/schema.js.map +0 -1
- package/dist/tools/slots/store.d.ts +0 -66
- package/dist/tools/slots/store.d.ts.map +0 -1
- package/dist/tools/slots/store.js +0 -227
- package/dist/tools/slots/store.js.map +0 -1
- package/dist/tools/store.d.ts +0 -40
- package/dist/tools/store.d.ts.map +0 -1
- package/dist/tools/store.js +0 -193
- package/dist/tools/store.js.map +0 -1
- package/dist/tools/theme.d.ts +0 -2
- package/dist/tools/theme.d.ts.map +0 -1
- package/dist/tools/theme.js +0 -67
- package/dist/tools/theme.js.map +0 -1
- package/dist/tools/url-safety.d.ts +0 -24
- package/dist/tools/url-safety.d.ts.map +0 -1
- package/dist/tools/url-safety.js +0 -224
- package/dist/tools/url-safety.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolViewer.d.ts","sourceRoot":"","sources":["../../../src/client/tools/ToolViewer.tsx"],"names":[],"mappings":"AA8EA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB;AA4DD,wBAAgB,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,eAAe,2CA8YrD"}
|
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { agentNativePath } from "../api-path.js";
|
|
3
|
-
import { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
|
4
|
-
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
-
import { useNavigate } from "react-router";
|
|
6
|
-
import { IconDots, IconLoader2, IconPencil, IconRefresh, IconTrash, IconX, } from "@tabler/icons-react";
|
|
7
|
-
import { ShareButton } from "../sharing/ShareButton.js";
|
|
8
|
-
import { AgentToggleButton } from "../AgentPanel.js";
|
|
9
|
-
import { NotificationsBell } from "../notifications/NotificationsBell.js";
|
|
10
|
-
import { sendToAgentChat } from "../agent-chat.js";
|
|
11
|
-
import { PromptComposer } from "../composer/PromptComposer.js";
|
|
12
|
-
import { Popover, PopoverContent, PopoverTrigger, } from "../components/ui/popover.js";
|
|
13
|
-
import { isAllowedToolPath, sanitizeToolRequestOptions, checkBridgePolicy, } from "./iframe-bridge.js";
|
|
14
|
-
const THEME_CSS_VARS = [
|
|
15
|
-
"--background",
|
|
16
|
-
"--foreground",
|
|
17
|
-
"--card",
|
|
18
|
-
"--card-foreground",
|
|
19
|
-
"--popover",
|
|
20
|
-
"--popover-foreground",
|
|
21
|
-
"--primary",
|
|
22
|
-
"--primary-foreground",
|
|
23
|
-
"--secondary",
|
|
24
|
-
"--secondary-foreground",
|
|
25
|
-
"--muted",
|
|
26
|
-
"--muted-foreground",
|
|
27
|
-
"--accent",
|
|
28
|
-
"--accent-foreground",
|
|
29
|
-
"--destructive",
|
|
30
|
-
"--destructive-foreground",
|
|
31
|
-
"--border",
|
|
32
|
-
"--input",
|
|
33
|
-
"--ring",
|
|
34
|
-
"--radius",
|
|
35
|
-
"--sidebar-background",
|
|
36
|
-
"--sidebar-foreground",
|
|
37
|
-
"--sidebar-primary",
|
|
38
|
-
"--sidebar-primary-foreground",
|
|
39
|
-
"--sidebar-accent",
|
|
40
|
-
"--sidebar-accent-foreground",
|
|
41
|
-
"--sidebar-border",
|
|
42
|
-
"--sidebar-ring",
|
|
43
|
-
];
|
|
44
|
-
function getParentThemeVars() {
|
|
45
|
-
const computed = getComputedStyle(document.documentElement);
|
|
46
|
-
const vars = {};
|
|
47
|
-
for (const name of THEME_CSS_VARS) {
|
|
48
|
-
const val = computed.getPropertyValue(name).trim();
|
|
49
|
-
if (val)
|
|
50
|
-
vars[name] = val;
|
|
51
|
-
}
|
|
52
|
-
return vars;
|
|
53
|
-
}
|
|
54
|
-
function EditToolPopover({ tool }) {
|
|
55
|
-
const [open, setOpen] = useState(false);
|
|
56
|
-
// Radix's outside-click detection runs in the parent document, so a click
|
|
57
|
-
// inside the tool iframe (or any other iframe) never fires it. The browser
|
|
58
|
-
// does shift focus to the iframe though, which blurs the parent window — we
|
|
59
|
-
// hook that to close the popover so it behaves like a normal click-outside.
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (!open)
|
|
62
|
-
return;
|
|
63
|
-
const handleBlur = () => {
|
|
64
|
-
// Defer until after the focus actually lands so document.activeElement
|
|
65
|
-
// reflects the iframe (or whatever the user clicked on).
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
if (document.activeElement?.tagName === "IFRAME")
|
|
68
|
-
setOpen(false);
|
|
69
|
-
}, 0);
|
|
70
|
-
};
|
|
71
|
-
window.addEventListener("blur", handleBlur);
|
|
72
|
-
return () => window.removeEventListener("blur", handleBlur);
|
|
73
|
-
}, [open]);
|
|
74
|
-
const handleSubmit = (text) => {
|
|
75
|
-
const trimmed = text.trim();
|
|
76
|
-
if (!trimmed)
|
|
77
|
-
return;
|
|
78
|
-
sendToAgentChat({
|
|
79
|
-
message: trimmed,
|
|
80
|
-
context: `The user is viewing tool "${tool.name}" (id: ${tool.id}) and wants to edit it.`,
|
|
81
|
-
submit: true,
|
|
82
|
-
openSidebar: true,
|
|
83
|
-
});
|
|
84
|
-
setOpen(false);
|
|
85
|
-
};
|
|
86
|
-
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer", title: "Edit", children: _jsx(IconPencil, { className: "h-4 w-4" }) }) }), _jsxs(PopoverContent, { align: "end", sideOffset: 6, className: "w-[420px] p-3", children: [_jsx("p", { className: "px-1 pb-2 text-sm font-semibold text-foreground", children: "Edit tool" }), _jsx(PromptComposer, { autoFocus: true, placeholder: "What would you like to change?", draftScope: `tools:edit:${tool.id}`, onSubmit: handleSubmit })] })] }));
|
|
87
|
-
}
|
|
88
|
-
export function ToolViewer({ toolId }) {
|
|
89
|
-
const [isDark, setIsDark] = useState(false);
|
|
90
|
-
const [iframeReady, setIframeReady] = useState(false);
|
|
91
|
-
const iframeRef = useRef(null);
|
|
92
|
-
const toolRef = useRef(null);
|
|
93
|
-
const [isRenaming, setIsRenaming] = useState(false);
|
|
94
|
-
const [renameValue, setRenameValue] = useState("");
|
|
95
|
-
const [refreshKey, setRefreshKey] = useState(0);
|
|
96
|
-
const renameInputRef = useRef(null);
|
|
97
|
-
const queryClient = useQueryClient();
|
|
98
|
-
// (audit H4) Role plumbed through from the iframe's render binding. Until
|
|
99
|
-
// the iframe announces its role we deny non-trivial helper calls — that
|
|
100
|
-
// way a malicious tool body that races the announcement can't briefly
|
|
101
|
-
// operate at higher privilege than the viewer's actual role.
|
|
102
|
-
const bridgeContextRef = useRef({
|
|
103
|
-
role: "viewer",
|
|
104
|
-
isAuthor: false,
|
|
105
|
-
});
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
setIsDark(document.documentElement.classList.contains("dark"));
|
|
108
|
-
const observer = new MutationObserver(() => {
|
|
109
|
-
setIsDark(document.documentElement.classList.contains("dark"));
|
|
110
|
-
});
|
|
111
|
-
observer.observe(document.documentElement, {
|
|
112
|
-
attributes: true,
|
|
113
|
-
attributeFilter: ["class"],
|
|
114
|
-
});
|
|
115
|
-
return () => observer.disconnect();
|
|
116
|
-
}, []);
|
|
117
|
-
const sendThemeToIframe = () => {
|
|
118
|
-
const win = iframeRef.current?.contentWindow;
|
|
119
|
-
if (!win)
|
|
120
|
-
return;
|
|
121
|
-
win.postMessage({
|
|
122
|
-
type: "agent-native-theme-update",
|
|
123
|
-
isDark: document.documentElement.classList.contains("dark"),
|
|
124
|
-
vars: getParentThemeVars(),
|
|
125
|
-
}, "*");
|
|
126
|
-
};
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
if (!iframeReady)
|
|
129
|
-
return;
|
|
130
|
-
sendThemeToIframe();
|
|
131
|
-
}, [isDark, iframeReady]);
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
const handleMessage = async (event) => {
|
|
134
|
-
if (event.source !== iframeRef.current?.contentWindow)
|
|
135
|
-
return;
|
|
136
|
-
const message = event.data;
|
|
137
|
-
if (!message)
|
|
138
|
-
return;
|
|
139
|
-
if (message.type === "agent-native-tool-binding") {
|
|
140
|
-
// (audit H4) The iframe announced its render binding. Trust the role
|
|
141
|
-
// value because the iframe's binding is generated server-side in
|
|
142
|
-
// tools/routes.ts (resolveAccess), not by user-authored content.
|
|
143
|
-
const binding = message.binding ?? {};
|
|
144
|
-
const role = binding.role === "owner" ||
|
|
145
|
-
binding.role === "admin" ||
|
|
146
|
-
binding.role === "editor" ||
|
|
147
|
-
binding.role === "viewer"
|
|
148
|
-
? binding.role
|
|
149
|
-
: "viewer";
|
|
150
|
-
bridgeContextRef.current = {
|
|
151
|
-
role,
|
|
152
|
-
isAuthor: !!binding.isAuthor,
|
|
153
|
-
};
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (message.type === "agent-native-tool-consent-granted" ||
|
|
157
|
-
message.type === "agent-native-tool-consent-cancelled") {
|
|
158
|
-
// (audit C1) The consent stub fired; force a reload of the iframe so
|
|
159
|
-
// the next render returns the tool body (granted) or stays on the
|
|
160
|
-
// stub (cancelled — viewer can also navigate away).
|
|
161
|
-
if (message.type === "agent-native-tool-consent-granted") {
|
|
162
|
-
// Invalidate the cached tool record — author may have edited
|
|
163
|
-
// since the cache was warmed.
|
|
164
|
-
queryClient.invalidateQueries({ queryKey: ["tool", toolId] });
|
|
165
|
-
setRefreshKey((k) => k + 1);
|
|
166
|
-
}
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (message.type === "agent-native-tool-keydown") {
|
|
170
|
-
document.dispatchEvent(new KeyboardEvent("keydown", {
|
|
171
|
-
key: message.key,
|
|
172
|
-
code: message.code,
|
|
173
|
-
metaKey: !!message.metaKey,
|
|
174
|
-
ctrlKey: !!message.ctrlKey,
|
|
175
|
-
shiftKey: !!message.shiftKey,
|
|
176
|
-
altKey: !!message.altKey,
|
|
177
|
-
bubbles: true,
|
|
178
|
-
cancelable: true,
|
|
179
|
-
}));
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (message.type === "agent-native-tool-error-fix") {
|
|
183
|
-
const t = toolRef.current;
|
|
184
|
-
if (!t)
|
|
185
|
-
return;
|
|
186
|
-
const errors = message.errors || [];
|
|
187
|
-
const errorDetails = message.errorDetails || [];
|
|
188
|
-
const consoleLogs = message.consoleLogs || [];
|
|
189
|
-
const networkLogs = message.networkLogs || [];
|
|
190
|
-
const detailedTrace = errorDetails
|
|
191
|
-
.map((e) => (e.stack ? `${e.message}\n${e.stack}` : e.message))
|
|
192
|
-
.join("\n\n");
|
|
193
|
-
const contextParts = [
|
|
194
|
-
`The user is viewing tool "${t.name}" (id: ${t.id}) and there are runtime errors that need fixing.`,
|
|
195
|
-
`\nFull error details:\n${detailedTrace}`,
|
|
196
|
-
];
|
|
197
|
-
if (consoleLogs.length > 0) {
|
|
198
|
-
const consoleStr = consoleLogs
|
|
199
|
-
.map((l) => `[${l.level}] ${l.message}`)
|
|
200
|
-
.join("\n");
|
|
201
|
-
contextParts.push(`\nRecent console output:\n${consoleStr}`);
|
|
202
|
-
}
|
|
203
|
-
if (networkLogs.length > 0) {
|
|
204
|
-
const netStr = networkLogs
|
|
205
|
-
.map((l) => `${l.method} ${l.path} → ${l.ok ? l.status : "FAILED: " + (l.error || l.status)}`)
|
|
206
|
-
.join("\n");
|
|
207
|
-
contextParts.push(`\nRecent network requests:\n${netStr}`);
|
|
208
|
-
}
|
|
209
|
-
sendToAgentChat({
|
|
210
|
-
message: `Fix runtime errors in this tool:\n${errors.join("\n")}`,
|
|
211
|
-
context: contextParts.join("\n"),
|
|
212
|
-
submit: true,
|
|
213
|
-
openSidebar: true,
|
|
214
|
-
});
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (message.type !== "agent-native-tool-request")
|
|
218
|
-
return;
|
|
219
|
-
const requestId = String(message.requestId ?? "");
|
|
220
|
-
const path = String(message.path ?? "");
|
|
221
|
-
const respond = (payload) => {
|
|
222
|
-
iframeRef.current?.contentWindow?.postMessage({
|
|
223
|
-
type: "agent-native-tool-response",
|
|
224
|
-
requestId,
|
|
225
|
-
...payload,
|
|
226
|
-
}, "*");
|
|
227
|
-
};
|
|
228
|
-
if (!requestId || !isAllowedToolPath(path, toolId)) {
|
|
229
|
-
respond({ error: "Tool request path is not allowed" });
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
const options = sanitizeToolRequestOptions(message.options);
|
|
234
|
-
// (audit H4) Role-aware policy gate: viewer-shared tools can read
|
|
235
|
-
// but not write. Decided here in the parent before the request
|
|
236
|
-
// leaves; the server enforces a second layer.
|
|
237
|
-
const policy = checkBridgePolicy(path, options.method ?? "GET", bridgeContextRef.current);
|
|
238
|
-
if (!policy.ok) {
|
|
239
|
-
respond({
|
|
240
|
-
response: {
|
|
241
|
-
ok: false,
|
|
242
|
-
status: 403,
|
|
243
|
-
statusText: "Forbidden",
|
|
244
|
-
body: { error: policy.error },
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
// (audit H5) Tag every outbound bridge request with the
|
|
250
|
-
// X-Agent-Native-Tool-Bridge sentinel so the action-routes layer can
|
|
251
|
-
// enforce per-action `toolCallable` opt-in. The header is added by
|
|
252
|
-
// the parent — it is NOT taken from the iframe-supplied options
|
|
253
|
-
// (which were filtered by sanitizeToolRequestOptions).
|
|
254
|
-
const finalHeaders = new Headers(options.headers ?? undefined);
|
|
255
|
-
finalHeaders.set("X-Agent-Native-Tool-Bridge", "1");
|
|
256
|
-
finalHeaders.set("X-Agent-Native-Tool-Id", toolId);
|
|
257
|
-
const res = await fetch(agentNativePath(path), {
|
|
258
|
-
...options,
|
|
259
|
-
headers: finalHeaders,
|
|
260
|
-
credentials: "same-origin",
|
|
261
|
-
});
|
|
262
|
-
const text = await res.text();
|
|
263
|
-
let body = text;
|
|
264
|
-
if (text) {
|
|
265
|
-
try {
|
|
266
|
-
body = JSON.parse(text);
|
|
267
|
-
}
|
|
268
|
-
catch {
|
|
269
|
-
body = text;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
respond({
|
|
273
|
-
response: {
|
|
274
|
-
ok: res.ok,
|
|
275
|
-
status: res.status,
|
|
276
|
-
statusText: res.statusText,
|
|
277
|
-
body,
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
catch (err) {
|
|
282
|
-
respond({ error: err?.message ?? "Tool host request failed" });
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
window.addEventListener("message", handleMessage);
|
|
286
|
-
return () => window.removeEventListener("message", handleMessage);
|
|
287
|
-
}, [toolId, queryClient]);
|
|
288
|
-
const { data: tool, isLoading } = useQuery({
|
|
289
|
-
queryKey: ["tool", toolId],
|
|
290
|
-
queryFn: async () => {
|
|
291
|
-
const res = await fetch(agentNativePath(`/_agent-native/tools/${toolId}`));
|
|
292
|
-
if (!res.ok)
|
|
293
|
-
throw new Error("Failed to fetch tool");
|
|
294
|
-
return res.json();
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
toolRef.current = tool ?? null;
|
|
298
|
-
const iframeSrc = useMemo(() => agentNativePath(`/_agent-native/tools/${toolId}/render?dark=${document.documentElement.classList.contains("dark")}&v=${encodeURIComponent(tool?.updatedAt ?? "")}&r=${refreshKey}`), [toolId, tool?.updatedAt, refreshKey]);
|
|
299
|
-
useEffect(() => {
|
|
300
|
-
setIframeReady(false);
|
|
301
|
-
// Reset role to deny-by-default on every reload — the new render's
|
|
302
|
-
// binding announcement re-establishes the role before any helper call.
|
|
303
|
-
bridgeContextRef.current = { role: "viewer", isAuthor: false };
|
|
304
|
-
}, [toolId, tool?.updatedAt, refreshKey]);
|
|
305
|
-
const startRename = useCallback(() => {
|
|
306
|
-
if (!tool)
|
|
307
|
-
return;
|
|
308
|
-
setRenameValue(tool.name);
|
|
309
|
-
setIsRenaming(true);
|
|
310
|
-
requestAnimationFrame(() => renameInputRef.current?.select());
|
|
311
|
-
}, [tool]);
|
|
312
|
-
const submitRename = useCallback(async () => {
|
|
313
|
-
const trimmed = renameValue.trim();
|
|
314
|
-
if (!trimmed || !tool || trimmed === tool.name) {
|
|
315
|
-
setIsRenaming(false);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
queryClient.setQueryData(["tool", toolId], (old) => old ? { ...old, name: trimmed } : old);
|
|
319
|
-
queryClient.setQueryData(["tools"], (old) => (old ?? []).map((t) => (t.id === toolId ? { ...t, name: trimmed } : t)));
|
|
320
|
-
setIsRenaming(false);
|
|
321
|
-
try {
|
|
322
|
-
await fetch(agentNativePath(`/_agent-native/tools/${toolId}`), {
|
|
323
|
-
method: "PUT",
|
|
324
|
-
headers: { "Content-Type": "application/json" },
|
|
325
|
-
body: JSON.stringify({ name: trimmed }),
|
|
326
|
-
});
|
|
327
|
-
queryClient.invalidateQueries({ queryKey: ["tool", toolId] });
|
|
328
|
-
queryClient.invalidateQueries({ queryKey: ["tools"] });
|
|
329
|
-
}
|
|
330
|
-
catch {
|
|
331
|
-
queryClient.invalidateQueries({ queryKey: ["tool", toolId] });
|
|
332
|
-
queryClient.invalidateQueries({ queryKey: ["tools"] });
|
|
333
|
-
}
|
|
334
|
-
}, [renameValue, tool, toolId, queryClient]);
|
|
335
|
-
if (isLoading) {
|
|
336
|
-
return (_jsxs("div", { className: "flex h-full flex-col", children: [_jsxs("div", { className: "flex h-12 items-center gap-2 px-3 border-b shrink-0", children: [_jsx("div", { className: "h-3.5 w-3.5 rounded bg-muted animate-pulse" }), _jsx("div", { className: "h-3.5 w-24 rounded bg-muted animate-pulse" })] }), _jsx("div", { className: "flex-1 bg-muted/20 animate-pulse" })] }));
|
|
337
|
-
}
|
|
338
|
-
if (!tool) {
|
|
339
|
-
return (_jsx("div", { className: "flex h-full items-center justify-center text-sm text-muted-foreground", children: "Tool not found" }));
|
|
340
|
-
}
|
|
341
|
-
return (_jsxs("div", { className: "flex h-full w-full flex-col", children: [_jsxs("div", { className: "flex h-12 items-center justify-between border-b px-3 shrink-0", children: [_jsx("div", { className: "group/name flex items-center gap-1", children: isRenaming ? (_jsx("input", { ref: renameInputRef, value: renameValue, onChange: (e) => setRenameValue(e.target.value), onBlur: submitRename, onKeyDown: (e) => {
|
|
342
|
-
if (e.key === "Enter")
|
|
343
|
-
submitRename();
|
|
344
|
-
if (e.key === "Escape")
|
|
345
|
-
setIsRenaming(false);
|
|
346
|
-
}, className: "text-sm font-medium bg-transparent border-b border-primary outline-none py-0 px-0" })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-sm font-medium", children: tool.name }), _jsx("button", { type: "button", onClick: startRename, className: "cursor-pointer rounded p-0.5 text-muted-foreground/40 opacity-0 group-hover/name:opacity-100 hover:text-foreground", title: "Rename", children: _jsx(IconPencil, { className: "h-3 w-3" }) })] })) }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx("button", { type: "button", onClick: () => setRefreshKey((k) => k + 1), className: "inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer", title: "Refresh", children: _jsx(IconRefresh, { className: "h-4 w-4" }) }), _jsx(EditToolPopover, { tool: tool }), _jsx(ShareButton, { resourceType: "tool", resourceId: toolId, resourceTitle: tool.name }), _jsx(ToolMoreMenu, { toolId: toolId, toolName: tool.name }), _jsx(NotificationsBell, {}), _jsx(AgentToggleButton, { className: "h-8 w-8 rounded-md hover:bg-accent" })] })] }), _jsxs("div", { className: "relative flex-1 min-h-0", children: [!iframeReady && (_jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-background z-10", children: _jsx(IconLoader2, { className: "size-5 animate-spin text-muted-foreground", role: "status", "aria-label": "Loading" }) })), _jsx("iframe", { ref: iframeRef, src: iframeSrc, className: "h-full w-full border-0", sandbox: "allow-scripts allow-forms", title: tool.name, onLoad: () => {
|
|
347
|
-
sendThemeToIframe();
|
|
348
|
-
setTimeout(() => setIframeReady(true), 150);
|
|
349
|
-
} }, `${tool.updatedAt}-${refreshKey}`)] })] }));
|
|
350
|
-
}
|
|
351
|
-
function ToolMoreMenu({ toolId, toolName, }) {
|
|
352
|
-
const [open, setOpen] = useState(false);
|
|
353
|
-
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
|
354
|
-
const queryClient = useQueryClient();
|
|
355
|
-
const navigate = useNavigate();
|
|
356
|
-
const { data: slots = [] } = useQuery({
|
|
357
|
-
queryKey: ["tool-slots", toolId],
|
|
358
|
-
queryFn: async () => {
|
|
359
|
-
const res = await fetch(agentNativePath(`/_agent-native/slots/tool/${toolId}`));
|
|
360
|
-
if (!res.ok)
|
|
361
|
-
return [];
|
|
362
|
-
return res.json();
|
|
363
|
-
},
|
|
364
|
-
enabled: open,
|
|
365
|
-
});
|
|
366
|
-
const closeMenu = () => {
|
|
367
|
-
setOpen(false);
|
|
368
|
-
setConfirmingDelete(false);
|
|
369
|
-
};
|
|
370
|
-
const removeFromSlot = async (slotId) => {
|
|
371
|
-
try {
|
|
372
|
-
await fetch(agentNativePath(`/_agent-native/slots/${encodeURIComponent(slotId)}/install/${encodeURIComponent(toolId)}`), { method: "DELETE" });
|
|
373
|
-
}
|
|
374
|
-
finally {
|
|
375
|
-
queryClient.invalidateQueries({ queryKey: ["slot-installs", slotId] });
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const deleteTool = async () => {
|
|
379
|
-
closeMenu();
|
|
380
|
-
try {
|
|
381
|
-
await fetch(agentNativePath(`/_agent-native/tools/${toolId}`), {
|
|
382
|
-
method: "DELETE",
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
finally {
|
|
386
|
-
queryClient.invalidateQueries({ queryKey: ["tool", toolId] });
|
|
387
|
-
queryClient.invalidateQueries({ queryKey: ["tools"] });
|
|
388
|
-
slots.forEach((s) => queryClient.invalidateQueries({
|
|
389
|
-
queryKey: ["slot-installs", s.slotId],
|
|
390
|
-
}));
|
|
391
|
-
navigate("/tools");
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
return (_jsxs(Popover, { open: open, onOpenChange: (o) => {
|
|
395
|
-
setOpen(o);
|
|
396
|
-
if (!o)
|
|
397
|
-
setConfirmingDelete(false);
|
|
398
|
-
}, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer", title: "More options", "aria-label": "More options", children: _jsx(IconDots, { className: "h-4 w-4" }) }) }), _jsx(PopoverContent, { align: "end", sideOffset: 4, className: "w-72 p-0", children: !confirmingDelete ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "px-3 py-2 border-b border-border/40", children: [_jsx("p", { className: "text-[12px] font-medium", children: "Appears in" }), slots.length === 0 ? (_jsx("p", { className: "text-[11px] text-muted-foreground/70 mt-0.5", children: "Not installed in any widget areas. Ask the agent to add it somewhere." })) : (_jsxs("p", { className: "text-[11px] text-muted-foreground/70 mt-0.5", children: ["This tool can render in ", slots.length, " widget area", slots.length === 1 ? "" : "s", "."] }))] }), slots.length > 0 && (_jsx("div", { className: "max-h-48 overflow-y-auto py-1", children: slots.map((s) => (_jsxs("div", { className: "flex items-center gap-2 px-3 py-1.5 text-[12px]", children: [_jsx("span", { className: "flex-1 truncate font-mono text-[11px] text-muted-foreground", children: s.slotId }), _jsx("button", { type: "button", onClick: () => removeFromSlot(s.slotId), className: "rounded p-1 text-muted-foreground/60 hover:bg-accent hover:text-foreground cursor-pointer", title: "Remove from this widget area (for me)", "aria-label": "Remove from this widget area", children: _jsx(IconX, { className: "h-3.5 w-3.5" }) })] }, s.id))) })), _jsx("div", { className: "border-t border-border/40 p-1", children: _jsxs("button", { type: "button", onClick: () => setConfirmingDelete(true), className: "flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-[12px] text-destructive hover:bg-destructive/10 cursor-pointer text-left", children: [_jsx(IconTrash, { className: "h-3.5 w-3.5" }), _jsx("span", { children: "Delete tool\u2026" })] }) })] })) : (_jsxs("div", { className: "flex flex-col gap-2 p-3", children: [_jsxs("p", { className: "text-[12px]", children: ["Delete ", _jsx("span", { className: "font-medium", children: toolName }), "? This removes the tool everywhere, for everyone it's shared with."] }), _jsxs("div", { className: "flex justify-end gap-1", children: [_jsx("button", { type: "button", onClick: () => setConfirmingDelete(false), className: "rounded-md px-2 py-1 text-[12px] hover:bg-accent cursor-pointer", children: "Cancel" }), _jsx("button", { type: "button", onClick: deleteTool, className: "rounded-md bg-destructive px-2 py-1 text-[12px] text-destructive-foreground hover:bg-destructive/90 cursor-pointer", children: "Delete" })] })] })) })] }));
|
|
399
|
-
}
|
|
400
|
-
//# sourceMappingURL=ToolViewer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolViewer.js","sourceRoot":"","sources":["../../../src/client/tools/ToolViewer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,QAAQ,EACR,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,KAAK,GACN,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAA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","sourcesContent":["import { agentNativePath } from \"../api-path.js\";\nimport { useState, useEffect, useRef, useCallback, useMemo } from \"react\";\nimport { useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { useNavigate } from \"react-router\";\nimport {\n IconDots,\n IconLoader2,\n IconPencil,\n IconRefresh,\n IconTrash,\n IconX,\n} from \"@tabler/icons-react\";\nimport { ShareButton } from \"../sharing/ShareButton.js\";\nimport { AgentToggleButton } from \"../AgentPanel.js\";\nimport { NotificationsBell } from \"../notifications/NotificationsBell.js\";\nimport { sendToAgentChat } from \"../agent-chat.js\";\nimport { PromptComposer } from \"../composer/PromptComposer.js\";\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"../components/ui/popover.js\";\nimport {\n isAllowedToolPath,\n sanitizeToolRequestOptions,\n checkBridgePolicy,\n type ToolBridgeRole,\n} from \"./iframe-bridge.js\";\n\nconst THEME_CSS_VARS = [\n \"--background\",\n \"--foreground\",\n \"--card\",\n \"--card-foreground\",\n \"--popover\",\n \"--popover-foreground\",\n \"--primary\",\n \"--primary-foreground\",\n \"--secondary\",\n \"--secondary-foreground\",\n \"--muted\",\n \"--muted-foreground\",\n \"--accent\",\n \"--accent-foreground\",\n \"--destructive\",\n \"--destructive-foreground\",\n \"--border\",\n \"--input\",\n \"--ring\",\n \"--radius\",\n \"--sidebar-background\",\n \"--sidebar-foreground\",\n \"--sidebar-primary\",\n \"--sidebar-primary-foreground\",\n \"--sidebar-accent\",\n \"--sidebar-accent-foreground\",\n \"--sidebar-border\",\n \"--sidebar-ring\",\n];\n\nfunction getParentThemeVars(): Record<string, string> {\n const computed = getComputedStyle(document.documentElement);\n const vars: Record<string, string> = {};\n for (const name of THEME_CSS_VARS) {\n const val = computed.getPropertyValue(name).trim();\n if (val) vars[name] = val;\n }\n return vars;\n}\n\ninterface Tool {\n id: string;\n name: string;\n description?: string;\n content?: string;\n updatedAt?: string;\n}\n\nexport interface ToolViewerProps {\n toolId: string;\n}\n\nfunction EditToolPopover({ tool }: { tool: Tool }) {\n const [open, setOpen] = useState(false);\n\n // Radix's outside-click detection runs in the parent document, so a click\n // inside the tool iframe (or any other iframe) never fires it. The browser\n // does shift focus to the iframe though, which blurs the parent window — we\n // hook that to close the popover so it behaves like a normal click-outside.\n useEffect(() => {\n if (!open) return;\n const handleBlur = () => {\n // Defer until after the focus actually lands so document.activeElement\n // reflects the iframe (or whatever the user clicked on).\n setTimeout(() => {\n if (document.activeElement?.tagName === \"IFRAME\") setOpen(false);\n }, 0);\n };\n window.addEventListener(\"blur\", handleBlur);\n return () => window.removeEventListener(\"blur\", handleBlur);\n }, [open]);\n\n const handleSubmit = (text: string) => {\n const trimmed = text.trim();\n if (!trimmed) return;\n sendToAgentChat({\n message: trimmed,\n context: `The user is viewing tool \"${tool.name}\" (id: ${tool.id}) and wants to edit it.`,\n submit: true,\n openSidebar: true,\n });\n setOpen(false);\n };\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n className=\"inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer\"\n title=\"Edit\"\n >\n <IconPencil className=\"h-4 w-4\" />\n </button>\n </PopoverTrigger>\n <PopoverContent align=\"end\" sideOffset={6} className=\"w-[420px] p-3\">\n <p className=\"px-1 pb-2 text-sm font-semibold text-foreground\">\n Edit tool\n </p>\n <PromptComposer\n autoFocus\n placeholder=\"What would you like to change?\"\n draftScope={`tools:edit:${tool.id}`}\n onSubmit={handleSubmit}\n />\n </PopoverContent>\n </Popover>\n );\n}\n\nexport function ToolViewer({ toolId }: ToolViewerProps) {\n const [isDark, setIsDark] = useState(false);\n const [iframeReady, setIframeReady] = useState(false);\n const iframeRef = useRef<HTMLIFrameElement | null>(null);\n const toolRef = useRef<Tool | null>(null);\n const [isRenaming, setIsRenaming] = useState(false);\n const [renameValue, setRenameValue] = useState(\"\");\n const [refreshKey, setRefreshKey] = useState(0);\n const renameInputRef = useRef<HTMLInputElement | null>(null);\n const queryClient = useQueryClient();\n // (audit H4) Role plumbed through from the iframe's render binding. Until\n // the iframe announces its role we deny non-trivial helper calls — that\n // way a malicious tool body that races the announcement can't briefly\n // operate at higher privilege than the viewer's actual role.\n const bridgeContextRef = useRef<{\n role: ToolBridgeRole;\n isAuthor: boolean;\n }>({\n role: \"viewer\",\n isAuthor: false,\n });\n\n useEffect(() => {\n setIsDark(document.documentElement.classList.contains(\"dark\"));\n\n const observer = new MutationObserver(() => {\n setIsDark(document.documentElement.classList.contains(\"dark\"));\n });\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\"],\n });\n return () => observer.disconnect();\n }, []);\n\n const sendThemeToIframe = () => {\n const win = iframeRef.current?.contentWindow;\n if (!win) return;\n win.postMessage(\n {\n type: \"agent-native-theme-update\",\n isDark: document.documentElement.classList.contains(\"dark\"),\n vars: getParentThemeVars(),\n },\n \"*\",\n );\n };\n\n useEffect(() => {\n if (!iframeReady) return;\n sendThemeToIframe();\n }, [isDark, iframeReady]);\n\n useEffect(() => {\n const handleMessage = async (event: MessageEvent) => {\n if (event.source !== iframeRef.current?.contentWindow) return;\n const message = event.data;\n if (!message) return;\n\n if (message.type === \"agent-native-tool-binding\") {\n // (audit H4) The iframe announced its render binding. Trust the role\n // value because the iframe's binding is generated server-side in\n // tools/routes.ts (resolveAccess), not by user-authored content.\n const binding = message.binding ?? {};\n const role: ToolBridgeRole =\n binding.role === \"owner\" ||\n binding.role === \"admin\" ||\n binding.role === \"editor\" ||\n binding.role === \"viewer\"\n ? binding.role\n : \"viewer\";\n bridgeContextRef.current = {\n role,\n isAuthor: !!binding.isAuthor,\n };\n return;\n }\n\n if (\n message.type === \"agent-native-tool-consent-granted\" ||\n message.type === \"agent-native-tool-consent-cancelled\"\n ) {\n // (audit C1) The consent stub fired; force a reload of the iframe so\n // the next render returns the tool body (granted) or stays on the\n // stub (cancelled — viewer can also navigate away).\n if (message.type === \"agent-native-tool-consent-granted\") {\n // Invalidate the cached tool record — author may have edited\n // since the cache was warmed.\n queryClient.invalidateQueries({ queryKey: [\"tool\", toolId] });\n setRefreshKey((k) => k + 1);\n }\n return;\n }\n\n if (message.type === \"agent-native-tool-keydown\") {\n document.dispatchEvent(\n new KeyboardEvent(\"keydown\", {\n key: message.key,\n code: message.code,\n metaKey: !!message.metaKey,\n ctrlKey: !!message.ctrlKey,\n shiftKey: !!message.shiftKey,\n altKey: !!message.altKey,\n bubbles: true,\n cancelable: true,\n }),\n );\n return;\n }\n\n if (message.type === \"agent-native-tool-error-fix\") {\n const t = toolRef.current;\n if (!t) return;\n const errors: string[] = message.errors || [];\n const errorDetails: Array<{ message: string; stack: string }> =\n message.errorDetails || [];\n const consoleLogs: Array<{ level: string; message: string }> =\n message.consoleLogs || [];\n const networkLogs: Array<{\n path: string;\n method: string;\n ok?: boolean;\n status?: number;\n error?: string;\n }> = message.networkLogs || [];\n\n const detailedTrace = errorDetails\n .map((e) => (e.stack ? `${e.message}\\n${e.stack}` : e.message))\n .join(\"\\n\\n\");\n\n const contextParts = [\n `The user is viewing tool \"${t.name}\" (id: ${t.id}) and there are runtime errors that need fixing.`,\n `\\nFull error details:\\n${detailedTrace}`,\n ];\n\n if (consoleLogs.length > 0) {\n const consoleStr = consoleLogs\n .map((l) => `[${l.level}] ${l.message}`)\n .join(\"\\n\");\n contextParts.push(`\\nRecent console output:\\n${consoleStr}`);\n }\n\n if (networkLogs.length > 0) {\n const netStr = networkLogs\n .map(\n (l) =>\n `${l.method} ${l.path} → ${l.ok ? l.status : \"FAILED: \" + (l.error || l.status)}`,\n )\n .join(\"\\n\");\n contextParts.push(`\\nRecent network requests:\\n${netStr}`);\n }\n\n sendToAgentChat({\n message: `Fix runtime errors in this tool:\\n${errors.join(\"\\n\")}`,\n context: contextParts.join(\"\\n\"),\n submit: true,\n openSidebar: true,\n });\n return;\n }\n\n if (message.type !== \"agent-native-tool-request\") return;\n\n const requestId = String(message.requestId ?? \"\");\n const path = String(message.path ?? \"\");\n const respond = (payload: Record<string, unknown>) => {\n iframeRef.current?.contentWindow?.postMessage(\n {\n type: \"agent-native-tool-response\",\n requestId,\n ...payload,\n },\n \"*\",\n );\n };\n\n if (!requestId || !isAllowedToolPath(path, toolId)) {\n respond({ error: \"Tool request path is not allowed\" });\n return;\n }\n\n try {\n const options = sanitizeToolRequestOptions(message.options);\n // (audit H4) Role-aware policy gate: viewer-shared tools can read\n // but not write. Decided here in the parent before the request\n // leaves; the server enforces a second layer.\n const policy = checkBridgePolicy(\n path,\n options.method ?? \"GET\",\n bridgeContextRef.current,\n );\n if (!policy.ok) {\n respond({\n response: {\n ok: false,\n status: 403,\n statusText: \"Forbidden\",\n body: { error: policy.error },\n },\n });\n return;\n }\n // (audit H5) Tag every outbound bridge request with the\n // X-Agent-Native-Tool-Bridge sentinel so the action-routes layer can\n // enforce per-action `toolCallable` opt-in. The header is added by\n // the parent — it is NOT taken from the iframe-supplied options\n // (which were filtered by sanitizeToolRequestOptions).\n const finalHeaders = new Headers(options.headers ?? undefined);\n finalHeaders.set(\"X-Agent-Native-Tool-Bridge\", \"1\");\n finalHeaders.set(\"X-Agent-Native-Tool-Id\", toolId);\n const res = await fetch(agentNativePath(path), {\n ...options,\n headers: finalHeaders,\n credentials: \"same-origin\",\n });\n const text = await res.text();\n let body: unknown = text;\n if (text) {\n try {\n body = JSON.parse(text);\n } catch {\n body = text;\n }\n }\n respond({\n response: {\n ok: res.ok,\n status: res.status,\n statusText: res.statusText,\n body,\n },\n });\n } catch (err: any) {\n respond({ error: err?.message ?? \"Tool host request failed\" });\n }\n };\n\n window.addEventListener(\"message\", handleMessage);\n return () => window.removeEventListener(\"message\", handleMessage);\n }, [toolId, queryClient]);\n\n const { data: tool, isLoading } = useQuery<Tool>({\n queryKey: [\"tool\", toolId],\n queryFn: async () => {\n const res = await fetch(\n agentNativePath(`/_agent-native/tools/${toolId}`),\n );\n if (!res.ok) throw new Error(\"Failed to fetch tool\");\n return res.json();\n },\n });\n\n toolRef.current = tool ?? null;\n\n const iframeSrc = useMemo(\n () =>\n agentNativePath(\n `/_agent-native/tools/${toolId}/render?dark=${document.documentElement.classList.contains(\"dark\")}&v=${encodeURIComponent(tool?.updatedAt ?? \"\")}&r=${refreshKey}`,\n ),\n [toolId, tool?.updatedAt, refreshKey],\n );\n\n useEffect(() => {\n setIframeReady(false);\n // Reset role to deny-by-default on every reload — the new render's\n // binding announcement re-establishes the role before any helper call.\n bridgeContextRef.current = { role: \"viewer\", isAuthor: false };\n }, [toolId, tool?.updatedAt, refreshKey]);\n\n const startRename = useCallback(() => {\n if (!tool) return;\n setRenameValue(tool.name);\n setIsRenaming(true);\n requestAnimationFrame(() => renameInputRef.current?.select());\n }, [tool]);\n\n const submitRename = useCallback(async () => {\n const trimmed = renameValue.trim();\n if (!trimmed || !tool || trimmed === tool.name) {\n setIsRenaming(false);\n return;\n }\n queryClient.setQueryData<Tool>([\"tool\", toolId], (old) =>\n old ? { ...old, name: trimmed } : old,\n );\n queryClient.setQueryData<Tool[]>([\"tools\"], (old) =>\n (old ?? []).map((t) => (t.id === toolId ? { ...t, name: trimmed } : t)),\n );\n setIsRenaming(false);\n try {\n await fetch(agentNativePath(`/_agent-native/tools/${toolId}`), {\n method: \"PUT\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ name: trimmed }),\n });\n queryClient.invalidateQueries({ queryKey: [\"tool\", toolId] });\n queryClient.invalidateQueries({ queryKey: [\"tools\"] });\n } catch {\n queryClient.invalidateQueries({ queryKey: [\"tool\", toolId] });\n queryClient.invalidateQueries({ queryKey: [\"tools\"] });\n }\n }, [renameValue, tool, toolId, queryClient]);\n\n if (isLoading) {\n return (\n <div className=\"flex h-full flex-col\">\n <div className=\"flex h-12 items-center gap-2 px-3 border-b shrink-0\">\n <div className=\"h-3.5 w-3.5 rounded bg-muted animate-pulse\" />\n <div className=\"h-3.5 w-24 rounded bg-muted animate-pulse\" />\n </div>\n <div className=\"flex-1 bg-muted/20 animate-pulse\" />\n </div>\n );\n }\n\n if (!tool) {\n return (\n <div className=\"flex h-full items-center justify-center text-sm text-muted-foreground\">\n Tool not found\n </div>\n );\n }\n\n return (\n <div className=\"flex h-full w-full flex-col\">\n <div className=\"flex h-12 items-center justify-between border-b px-3 shrink-0\">\n <div className=\"group/name flex items-center gap-1\">\n {isRenaming ? (\n <input\n ref={renameInputRef}\n value={renameValue}\n onChange={(e) => setRenameValue(e.target.value)}\n onBlur={submitRename}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") submitRename();\n if (e.key === \"Escape\") setIsRenaming(false);\n }}\n className=\"text-sm font-medium bg-transparent border-b border-primary outline-none py-0 px-0\"\n />\n ) : (\n <>\n <span className=\"text-sm font-medium\">{tool.name}</span>\n <button\n type=\"button\"\n onClick={startRename}\n className=\"cursor-pointer rounded p-0.5 text-muted-foreground/40 opacity-0 group-hover/name:opacity-100 hover:text-foreground\"\n title=\"Rename\"\n >\n <IconPencil className=\"h-3 w-3\" />\n </button>\n </>\n )}\n </div>\n <div className=\"flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setRefreshKey((k) => k + 1)}\n className=\"inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer\"\n title=\"Refresh\"\n >\n <IconRefresh className=\"h-4 w-4\" />\n </button>\n <EditToolPopover tool={tool} />\n <ShareButton\n resourceType=\"tool\"\n resourceId={toolId}\n resourceTitle={tool.name}\n />\n <ToolMoreMenu toolId={toolId} toolName={tool.name} />\n <NotificationsBell />\n <AgentToggleButton className=\"h-8 w-8 rounded-md hover:bg-accent\" />\n </div>\n </div>\n <div className=\"relative flex-1 min-h-0\">\n {!iframeReady && (\n <div className=\"absolute inset-0 flex items-center justify-center bg-background z-10\">\n <IconLoader2\n className=\"size-5 animate-spin text-muted-foreground\"\n role=\"status\"\n aria-label=\"Loading\"\n />\n </div>\n )}\n <iframe\n ref={iframeRef}\n key={`${tool.updatedAt}-${refreshKey}`}\n src={iframeSrc}\n className=\"h-full w-full border-0\"\n sandbox=\"allow-scripts allow-forms\"\n title={tool.name}\n onLoad={() => {\n sendThemeToIframe();\n setTimeout(() => setIframeReady(true), 150);\n }}\n />\n </div>\n </div>\n );\n}\n\ninterface SlotDeclaration {\n id: string;\n toolId: string;\n slotId: string;\n}\n\nfunction ToolMoreMenu({\n toolId,\n toolName,\n}: {\n toolId: string;\n toolName: string;\n}) {\n const [open, setOpen] = useState(false);\n const [confirmingDelete, setConfirmingDelete] = useState(false);\n const queryClient = useQueryClient();\n const navigate = useNavigate();\n\n const { data: slots = [] } = useQuery<SlotDeclaration[]>({\n queryKey: [\"tool-slots\", toolId],\n queryFn: async () => {\n const res = await fetch(\n agentNativePath(`/_agent-native/slots/tool/${toolId}`),\n );\n if (!res.ok) return [];\n return res.json();\n },\n enabled: open,\n });\n\n const closeMenu = () => {\n setOpen(false);\n setConfirmingDelete(false);\n };\n\n const removeFromSlot = async (slotId: string) => {\n try {\n await fetch(\n agentNativePath(\n `/_agent-native/slots/${encodeURIComponent(slotId)}/install/${encodeURIComponent(toolId)}`,\n ),\n { method: \"DELETE\" },\n );\n } finally {\n queryClient.invalidateQueries({ queryKey: [\"slot-installs\", slotId] });\n }\n };\n\n const deleteTool = async () => {\n closeMenu();\n try {\n await fetch(agentNativePath(`/_agent-native/tools/${toolId}`), {\n method: \"DELETE\",\n });\n } finally {\n queryClient.invalidateQueries({ queryKey: [\"tool\", toolId] });\n queryClient.invalidateQueries({ queryKey: [\"tools\"] });\n slots.forEach((s) =>\n queryClient.invalidateQueries({\n queryKey: [\"slot-installs\", s.slotId],\n }),\n );\n navigate(\"/tools\");\n }\n };\n\n return (\n <Popover\n open={open}\n onOpenChange={(o) => {\n setOpen(o);\n if (!o) setConfirmingDelete(false);\n }}\n >\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n className=\"inline-flex items-center justify-center rounded-md h-8 w-8 text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer\"\n title=\"More options\"\n aria-label=\"More options\"\n >\n <IconDots className=\"h-4 w-4\" />\n </button>\n </PopoverTrigger>\n <PopoverContent align=\"end\" sideOffset={4} className=\"w-72 p-0\">\n {!confirmingDelete ? (\n <>\n <div className=\"px-3 py-2 border-b border-border/40\">\n <p className=\"text-[12px] font-medium\">Appears in</p>\n {slots.length === 0 ? (\n <p className=\"text-[11px] text-muted-foreground/70 mt-0.5\">\n Not installed in any widget areas. Ask the agent to add it\n somewhere.\n </p>\n ) : (\n <p className=\"text-[11px] text-muted-foreground/70 mt-0.5\">\n This tool can render in {slots.length} widget area\n {slots.length === 1 ? \"\" : \"s\"}.\n </p>\n )}\n </div>\n {slots.length > 0 && (\n <div className=\"max-h-48 overflow-y-auto py-1\">\n {slots.map((s) => (\n <div\n key={s.id}\n className=\"flex items-center gap-2 px-3 py-1.5 text-[12px]\"\n >\n <span className=\"flex-1 truncate font-mono text-[11px] text-muted-foreground\">\n {s.slotId}\n </span>\n <button\n type=\"button\"\n onClick={() => removeFromSlot(s.slotId)}\n className=\"rounded p-1 text-muted-foreground/60 hover:bg-accent hover:text-foreground cursor-pointer\"\n title=\"Remove from this widget area (for me)\"\n aria-label=\"Remove from this widget area\"\n >\n <IconX className=\"h-3.5 w-3.5\" />\n </button>\n </div>\n ))}\n </div>\n )}\n <div className=\"border-t border-border/40 p-1\">\n <button\n type=\"button\"\n onClick={() => setConfirmingDelete(true)}\n className=\"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-[12px] text-destructive hover:bg-destructive/10 cursor-pointer text-left\"\n >\n <IconTrash className=\"h-3.5 w-3.5\" />\n <span>Delete tool…</span>\n </button>\n </div>\n </>\n ) : (\n <div className=\"flex flex-col gap-2 p-3\">\n <p className=\"text-[12px]\">\n Delete <span className=\"font-medium\">{toolName}</span>? This\n removes the tool everywhere, for everyone it's shared with.\n </p>\n <div className=\"flex justify-end gap-1\">\n <button\n type=\"button\"\n onClick={() => setConfirmingDelete(false)}\n className=\"rounded-md px-2 py-1 text-[12px] hover:bg-accent cursor-pointer\"\n >\n Cancel\n </button>\n <button\n type=\"button\"\n onClick={deleteTool}\n className=\"rounded-md bg-destructive px-2 py-1 text-[12px] text-destructive-foreground hover:bg-destructive/90 cursor-pointer\"\n >\n Delete\n </button>\n </div>\n </div>\n )}\n </PopoverContent>\n </Popover>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolViewerPage.d.ts","sourceRoot":"","sources":["../../../src/client/tools/ToolViewerPage.tsx"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,4CAiB7B"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { agentNativePath } from "../api-path.js";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
import { useParams } from "react-router";
|
|
5
|
-
import { ToolViewer } from "./ToolViewer.js";
|
|
6
|
-
import { ToolsListPage } from "./ToolsListPage.js";
|
|
7
|
-
export function ToolViewerPage() {
|
|
8
|
-
const { id } = useParams();
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
fetch(agentNativePath("/_agent-native/application-state/navigation"), {
|
|
11
|
-
method: "PUT",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
body: JSON.stringify({ value: { view: "tools", toolId: id } }),
|
|
14
|
-
}).catch(() => { });
|
|
15
|
-
}, [id]);
|
|
16
|
-
if (id === "new") {
|
|
17
|
-
// No manual editor — tools are created via the agent
|
|
18
|
-
return _jsx(ToolsListPage, {});
|
|
19
|
-
}
|
|
20
|
-
if (!id)
|
|
21
|
-
return null;
|
|
22
|
-
return _jsx(ToolViewer, { toolId: id });
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=ToolViewerPage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolViewerPage.js","sourceRoot":"","sources":["../../../src/client/tools/ToolViewerPage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,UAAU,cAAc;IAC5B,MAAM,EAAE,EAAE,EAAE,GAAG,SAAS,EAAkB,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,eAAe,CAAC,6CAA6C,CAAC,EAAE;YACpE,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;SAC/D,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAET,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;QACjB,qDAAqD;QACrD,OAAO,KAAC,aAAa,KAAG,CAAC;IAC3B,CAAC;IACD,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,KAAC,UAAU,IAAC,MAAM,EAAE,EAAE,GAAI,CAAC;AACpC,CAAC","sourcesContent":["import { agentNativePath } from \"../api-path.js\";\nimport { useEffect } from \"react\";\nimport { useParams } from \"react-router\";\nimport { ToolViewer } from \"./ToolViewer.js\";\nimport { ToolsListPage } from \"./ToolsListPage.js\";\n\nexport function ToolViewerPage() {\n const { id } = useParams<{ id: string }>();\n\n useEffect(() => {\n fetch(agentNativePath(\"/_agent-native/application-state/navigation\"), {\n method: \"PUT\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ value: { view: \"tools\", toolId: id } }),\n }).catch(() => {});\n }, [id]);\n\n if (id === \"new\") {\n // No manual editor — tools are created via the agent\n return <ToolsListPage />;\n }\n if (!id) return null;\n return <ToolViewer toolId={id} />;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolsListPage.d.ts","sourceRoot":"","sources":["../../../src/client/tools/ToolsListPage.tsx"],"names":[],"mappings":"AAqDA,wBAAgB,aAAa,4CAsI5B"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { agentNativePath } from "../api-path.js";
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
4
|
-
import { useQuery } from "@tanstack/react-query";
|
|
5
|
-
import { Link } from "react-router";
|
|
6
|
-
import { IconPlus, IconTool } from "@tabler/icons-react";
|
|
7
|
-
import { cn } from "../utils.js";
|
|
8
|
-
import { AgentToggleButton } from "../AgentPanel.js";
|
|
9
|
-
import { NotificationsBell } from "../notifications/NotificationsBell.js";
|
|
10
|
-
import { sendToAgentChat } from "../agent-chat.js";
|
|
11
|
-
import { PromptComposer } from "../composer/PromptComposer.js";
|
|
12
|
-
import { Popover, PopoverContent, PopoverTrigger, } from "../components/ui/popover.js";
|
|
13
|
-
import { TOOLS_ORDER_CHANGE_EVENT, applyToolsOrder, getToolsOrder, } from "./tool-order.js";
|
|
14
|
-
function submitCreateTool(prompt) {
|
|
15
|
-
const trimmed = prompt.trim();
|
|
16
|
-
if (!trimmed)
|
|
17
|
-
return;
|
|
18
|
-
sendToAgentChat({
|
|
19
|
-
message: `Create a tool: ${trimmed}`,
|
|
20
|
-
submit: true,
|
|
21
|
-
openSidebar: true,
|
|
22
|
-
newTab: true,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function CreateToolInput({ className }) {
|
|
26
|
-
return (_jsxs("div", { className: cn("flex flex-col gap-2", className), children: [_jsx("p", { className: "text-sm font-semibold text-foreground", children: "New tool" }), _jsx(PromptComposer, { autoFocus: true, placeholder: "Describe what you'd like to build... e.g. a todo list, API dashboard, calculator", draftScope: "tools:create", onSubmit: (text) => submitCreateTool(text) })] }));
|
|
27
|
-
}
|
|
28
|
-
export function ToolsListPage() {
|
|
29
|
-
const [showCreate, setShowCreate] = useState(false);
|
|
30
|
-
const [toolOrderState, setToolOrderState] = useState(() => typeof window !== "undefined" ? getToolsOrder() : []);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
fetch(agentNativePath("/_agent-native/application-state/navigation"), {
|
|
33
|
-
method: "PUT",
|
|
34
|
-
headers: { "Content-Type": "application/json" },
|
|
35
|
-
body: JSON.stringify({ value: { view: "tools" } }),
|
|
36
|
-
}).catch(() => { });
|
|
37
|
-
}, []);
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (typeof window === "undefined")
|
|
40
|
-
return;
|
|
41
|
-
const syncOrder = () => setToolOrderState(getToolsOrder());
|
|
42
|
-
window.addEventListener(TOOLS_ORDER_CHANGE_EVENT, syncOrder);
|
|
43
|
-
window.addEventListener("storage", syncOrder);
|
|
44
|
-
return () => {
|
|
45
|
-
window.removeEventListener(TOOLS_ORDER_CHANGE_EVENT, syncOrder);
|
|
46
|
-
window.removeEventListener("storage", syncOrder);
|
|
47
|
-
};
|
|
48
|
-
}, []);
|
|
49
|
-
const { data: tools, isLoading } = useQuery({
|
|
50
|
-
queryKey: ["tools"],
|
|
51
|
-
queryFn: async () => {
|
|
52
|
-
const res = await fetch(agentNativePath("/_agent-native/tools"));
|
|
53
|
-
if (!res.ok)
|
|
54
|
-
return [];
|
|
55
|
-
return res.json();
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const toolList = toolOrderState.length > 0
|
|
59
|
-
? applyToolsOrder(tools ?? [], toolOrderState)
|
|
60
|
-
: (tools ?? []);
|
|
61
|
-
const handleCreate = (text) => {
|
|
62
|
-
submitCreateTool(text);
|
|
63
|
-
setShowCreate(false);
|
|
64
|
-
};
|
|
65
|
-
return (_jsxs("div", { className: "flex h-full w-full flex-col", children: [_jsxs("header", { className: "flex h-12 items-center justify-between border-b px-4 shrink-0", children: [_jsx("h1", { className: "text-sm font-semibold", children: "Tools" }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs(Popover, { open: showCreate, onOpenChange: setShowCreate, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "inline-flex cursor-pointer items-center justify-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90", children: [_jsx(IconPlus, { className: "h-4 w-4" }), "New Tool"] }) }), _jsxs(PopoverContent, { align: "end", sideOffset: 6, className: "w-[420px] p-3", children: [_jsx("p", { className: "px-1 pb-2 text-sm font-semibold text-foreground", children: "New tool" }), _jsx(PromptComposer, { autoFocus: true, placeholder: "Describe what you'd like to build...", draftScope: "tools:create-popover", onSubmit: handleCreate })] })] }), _jsx(NotificationsBell, {}), _jsx(AgentToggleButton, { className: "h-8 w-8 rounded-md hover:bg-accent" })] })] }), _jsx("div", { className: "flex-1 overflow-auto p-6", children: isLoading ? (_jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: Array.from({ length: 6 }).map((_, i) => (_jsxs("div", { className: "rounded-lg border border-border bg-card p-5", children: [_jsx("div", { className: "mb-3 h-10 w-10 rounded-lg bg-muted animate-pulse" }), _jsx("div", { className: "mb-2 h-4 w-2/3 rounded bg-muted animate-pulse" }), _jsx("div", { className: "h-3 w-4/5 rounded bg-muted animate-pulse" })] }, i))) })) : toolList.length === 0 ? (_jsxs("div", { className: "flex flex-col items-center justify-center gap-4 py-16 text-center", children: [_jsx(IconTool, { className: "h-10 w-10 text-muted-foreground/40" }), _jsxs("div", { children: [_jsx("p", { className: "text-sm font-medium", children: "No tools yet" }), _jsx("p", { className: "text-xs text-muted-foreground mt-1", children: "Describe what you'd like to build" })] }), _jsx(CreateToolInput, { className: "w-full max-w-sm" })] })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: toolList.map((tool) => (_jsxs(Link, { to: `/tools/${tool.id}`, className: cn("group cursor-pointer rounded-lg border border-border bg-card p-5", "hover:border-primary/30 hover:shadow-sm"), children: [_jsx("div", { className: "mb-3 flex h-10 w-10 items-center justify-center rounded-lg bg-muted text-muted-foreground group-hover:bg-primary/10 group-hover:text-primary", children: _jsx(IconTool, { className: "h-5 w-5" }) }), _jsx("h3", { className: "mb-1 text-sm font-semibold text-foreground", children: tool.name }), tool.description && (_jsx("p", { className: "line-clamp-2 text-xs text-muted-foreground", children: tool.description }))] }, tool.id))) })) })] }));
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=ToolsListPage.js.map
|