@agent-native/core 0.15.3 → 0.15.5
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/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +7 -9
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/dev-mode.d.ts +14 -0
- package/dist/client/dev-mode.d.ts.map +1 -0
- package/dist/client/dev-mode.js +14 -0
- package/dist/client/dev-mode.js.map +1 -0
- package/dist/client/extensions/EmbeddedTool.d.ts +20 -0
- package/dist/client/extensions/EmbeddedTool.d.ts.map +1 -0
- package/dist/client/extensions/EmbeddedTool.js +199 -0
- package/dist/client/extensions/EmbeddedTool.js.map +1 -0
- package/dist/client/extensions/ToolEditor.d.ts +5 -0
- package/dist/client/extensions/ToolEditor.d.ts.map +1 -0
- package/dist/client/extensions/ToolEditor.js +129 -0
- package/dist/client/extensions/ToolEditor.js.map +1 -0
- package/dist/client/extensions/ToolViewer.d.ts +5 -0
- package/dist/client/extensions/ToolViewer.d.ts.map +1 -0
- package/dist/client/extensions/ToolViewer.js +400 -0
- package/dist/client/extensions/ToolViewer.js.map +1 -0
- package/dist/client/extensions/ToolViewerPage.d.ts +2 -0
- package/dist/client/extensions/ToolViewerPage.d.ts.map +1 -0
- package/dist/client/extensions/ToolViewerPage.js +24 -0
- package/dist/client/extensions/ToolViewerPage.js.map +1 -0
- package/dist/client/extensions/ToolsListPage.d.ts +2 -0
- package/dist/client/extensions/ToolsListPage.d.ts.map +1 -0
- package/dist/client/extensions/ToolsListPage.js +67 -0
- package/dist/client/extensions/ToolsListPage.js.map +1 -0
- package/dist/client/extensions/ToolsSidebarSection.d.ts +2 -0
- package/dist/client/extensions/ToolsSidebarSection.d.ts.map +1 -0
- package/dist/client/extensions/ToolsSidebarSection.js +236 -0
- package/dist/client/extensions/ToolsSidebarSection.js.map +1 -0
- package/dist/client/extensions/tool-order.d.ts +7 -0
- package/dist/client/extensions/tool-order.d.ts.map +1 -0
- package/dist/client/extensions/tool-order.js +47 -0
- package/dist/client/extensions/tool-order.js.map +1 -0
- package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
- package/dist/client/settings/useBuilderStatus.js +137 -20
- package/dist/client/settings/useBuilderStatus.js.map +1 -1
- package/dist/client/settings/useBuilderStatus.spec.js +28 -0
- package/dist/client/settings/useBuilderStatus.spec.js.map +1 -1
- package/dist/client/tools/EmbeddedTool.d.ts +20 -0
- package/dist/client/tools/EmbeddedTool.d.ts.map +1 -0
- package/dist/client/tools/EmbeddedTool.js +199 -0
- package/dist/client/tools/EmbeddedTool.js.map +1 -0
- package/dist/client/tools/ExtensionSlot.d.ts +27 -0
- package/dist/client/tools/ExtensionSlot.d.ts.map +1 -0
- package/dist/client/tools/ExtensionSlot.js +96 -0
- package/dist/client/tools/ExtensionSlot.js.map +1 -0
- package/dist/client/tools/ToolEditor.d.ts +5 -0
- package/dist/client/tools/ToolEditor.d.ts.map +1 -0
- package/dist/client/tools/ToolEditor.js +129 -0
- package/dist/client/tools/ToolEditor.js.map +1 -0
- package/dist/client/tools/ToolViewer.d.ts +5 -0
- package/dist/client/tools/ToolViewer.d.ts.map +1 -0
- package/dist/client/tools/ToolViewer.js +400 -0
- package/dist/client/tools/ToolViewer.js.map +1 -0
- package/dist/client/tools/ToolViewerPage.d.ts +2 -0
- package/dist/client/tools/ToolViewerPage.d.ts.map +1 -0
- package/dist/client/tools/ToolViewerPage.js +24 -0
- package/dist/client/tools/ToolViewerPage.js.map +1 -0
- package/dist/client/tools/ToolsListPage.d.ts +2 -0
- package/dist/client/tools/ToolsListPage.d.ts.map +1 -0
- package/dist/client/tools/ToolsListPage.js +67 -0
- package/dist/client/tools/ToolsListPage.js.map +1 -0
- package/dist/client/tools/ToolsSidebarSection.d.ts +2 -0
- package/dist/client/tools/ToolsSidebarSection.d.ts.map +1 -0
- package/dist/client/tools/ToolsSidebarSection.js +236 -0
- package/dist/client/tools/ToolsSidebarSection.js.map +1 -0
- package/dist/client/tools/iframe-bridge.d.ts +38 -0
- package/dist/client/tools/iframe-bridge.d.ts.map +1 -0
- package/dist/client/tools/iframe-bridge.js +207 -0
- package/dist/client/tools/iframe-bridge.js.map +1 -0
- package/dist/client/tools/index.d.ts +8 -0
- package/dist/client/tools/index.d.ts.map +1 -0
- package/dist/client/tools/index.js +8 -0
- package/dist/client/tools/index.js.map +1 -0
- package/dist/client/tools/tool-order.d.ts +7 -0
- package/dist/client/tools/tool-order.d.ts.map +1 -0
- package/dist/client/tools/tool-order.js +47 -0
- package/dist/client/tools/tool-order.js.map +1 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +20 -0
- package/dist/server/auth.js.map +1 -1
- package/dist/server/builder-browser.d.ts +14 -1
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +105 -5
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +77 -6
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/google-auth-mode.d.ts +3 -3
- package/dist/server/google-auth-mode.js.map +1 -1
- package/dist/server/google-auth-plugin.d.ts +3 -2
- package/dist/server/google-auth-plugin.d.ts.map +1 -1
- package/dist/server/google-auth-plugin.js +9 -2
- package/dist/server/google-auth-plugin.js.map +1 -1
- package/dist/server/local-migration.d.ts +41 -0
- package/dist/server/local-migration.d.ts.map +1 -0
- package/dist/server/local-migration.js +235 -0
- package/dist/server/local-migration.js.map +1 -0
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +9 -2
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/tools/actions.d.ts +3 -0
- package/dist/tools/actions.d.ts.map +1 -0
- package/dist/tools/actions.js +272 -0
- package/dist/tools/actions.js.map +1 -0
- package/dist/tools/fetch-tool.d.ts +23 -0
- package/dist/tools/fetch-tool.d.ts.map +1 -0
- package/dist/tools/fetch-tool.js +178 -0
- package/dist/tools/fetch-tool.js.map +1 -0
- package/dist/tools/html-shell.d.ts +45 -0
- package/dist/tools/html-shell.d.ts.map +1 -0
- package/dist/tools/html-shell.js +514 -0
- package/dist/tools/html-shell.js.map +1 -0
- package/dist/tools/proxy-security.d.ts +12 -0
- package/dist/tools/proxy-security.d.ts.map +1 -0
- package/dist/tools/proxy-security.js +158 -0
- package/dist/tools/proxy-security.js.map +1 -0
- package/dist/tools/routes.d.ts +2 -0
- package/dist/tools/routes.d.ts.map +1 -0
- package/dist/tools/routes.js +627 -0
- package/dist/tools/routes.js.map +1 -0
- package/dist/tools/schema.d.ts +664 -0
- package/dist/tools/schema.d.ts.map +1 -0
- package/dist/tools/schema.js +146 -0
- package/dist/tools/schema.js.map +1 -0
- package/dist/tools/slots/routes.d.ts +15 -0
- package/dist/tools/slots/routes.d.ts.map +1 -0
- package/dist/tools/slots/routes.js +94 -0
- package/dist/tools/slots/routes.js.map +1 -0
- package/dist/tools/slots/schema.d.ts +303 -0
- package/dist/tools/slots/schema.d.ts.map +1 -0
- package/dist/tools/slots/schema.js +76 -0
- package/dist/tools/slots/schema.js.map +1 -0
- package/dist/tools/slots/store.d.ts +66 -0
- package/dist/tools/slots/store.d.ts.map +1 -0
- package/dist/tools/slots/store.js +227 -0
- package/dist/tools/slots/store.js.map +1 -0
- package/dist/tools/store.d.ts +40 -0
- package/dist/tools/store.d.ts.map +1 -0
- package/dist/tools/store.js +193 -0
- package/dist/tools/store.js.map +1 -0
- package/dist/tools/theme.d.ts +2 -0
- package/dist/tools/theme.d.ts.map +1 -0
- package/dist/tools/theme.js +67 -0
- package/dist/tools/theme.js.map +1 -0
- package/dist/tools/url-safety.d.ts +24 -0
- package/dist/tools/url-safety.d.ts.map +1 -0
- package/dist/tools/url-safety.js +224 -0
- package/dist/tools/url-safety.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { createTool, getTool, updateTool, updateToolContent } from "./store.js";
|
|
2
|
+
import { addToolSlotTarget, installToolSlot, uninstallToolSlot, listToolsForSlot, listSlotsForTool, } from "./slots/store.js";
|
|
3
|
+
export function createToolActionEntries() {
|
|
4
|
+
return {
|
|
5
|
+
"create-tool": {
|
|
6
|
+
tool: {
|
|
7
|
+
description: "Create a sandboxed Alpine.js mini-app tool. Use this when the user asks to create, build, or make a tool/widget/dashboard/calculator. The content must be a self-contained Alpine.js HTML body snippet that can use appAction(), appFetch(), dbQuery(), dbExec(), toolFetch(), and toolData.",
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
name: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: 'Short display name for the tool. Do not include "app" — e.g. name a todo app "Todos", a weather app "Weather".',
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "One-sentence summary of what the tool does.",
|
|
18
|
+
},
|
|
19
|
+
content: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Self-contained Alpine.js HTML body snippet. The iframe body has no padding, so add p-4 or p-6 to the outermost element. Use semantic Tailwind colors (bg-background, text-foreground, bg-primary, etc.) for native theming. Do not include a full app build, React code, or source files.",
|
|
22
|
+
},
|
|
23
|
+
icon: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Optional icon name or short label.",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ["name", "content"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
run: async (args) => {
|
|
32
|
+
const name = String(args?.name ?? "").trim();
|
|
33
|
+
const content = String(args?.content ?? "").trim();
|
|
34
|
+
if (!name)
|
|
35
|
+
return "Error: name is required.";
|
|
36
|
+
if (!content)
|
|
37
|
+
return "Error: content is required.";
|
|
38
|
+
const tool = await createTool({
|
|
39
|
+
name,
|
|
40
|
+
description: String(args?.description ?? "").trim(),
|
|
41
|
+
content,
|
|
42
|
+
icon: args?.icon ? String(args.icon) : undefined,
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
tool,
|
|
47
|
+
next: `Navigate to /tools/${tool.id} or use the navigate action with --view=tools --toolId=${tool.id}.`,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"update-tool": {
|
|
52
|
+
tool: {
|
|
53
|
+
description: "Update an existing sandboxed Alpine.js mini-app tool. Prefer patches for surgical edits; use full content replacement only when necessary.",
|
|
54
|
+
parameters: {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
id: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Tool id to update.",
|
|
60
|
+
},
|
|
61
|
+
name: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Optional new display name.",
|
|
64
|
+
},
|
|
65
|
+
description: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Optional new description.",
|
|
68
|
+
},
|
|
69
|
+
content: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Optional full replacement Alpine.js HTML body snippet.",
|
|
72
|
+
},
|
|
73
|
+
patches: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: 'Optional JSON array of { "find": "...", "replace": "..." } patches to apply to the current content.',
|
|
76
|
+
},
|
|
77
|
+
icon: {
|
|
78
|
+
type: "string",
|
|
79
|
+
description: "Optional icon name or short label.",
|
|
80
|
+
},
|
|
81
|
+
visibility: {
|
|
82
|
+
type: "string",
|
|
83
|
+
description: "Optional sharing visibility.",
|
|
84
|
+
enum: ["private", "org", "public"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
required: ["id"],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
run: async (args) => {
|
|
91
|
+
const id = String(args?.id ?? "").trim();
|
|
92
|
+
if (!id)
|
|
93
|
+
return "Error: id is required.";
|
|
94
|
+
let result = null;
|
|
95
|
+
if (args?.content !== undefined || args?.patches !== undefined) {
|
|
96
|
+
const patches = parsePatches(args.patches);
|
|
97
|
+
if (args?.patches !== undefined && !patches) {
|
|
98
|
+
return "Error: patches must be a JSON array of { find, replace } objects.";
|
|
99
|
+
}
|
|
100
|
+
result = await updateToolContent(id, {
|
|
101
|
+
content: args?.content !== undefined ? String(args.content) : undefined,
|
|
102
|
+
patches,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const meta = {};
|
|
106
|
+
if (args?.name !== undefined)
|
|
107
|
+
meta.name = String(args.name).trim();
|
|
108
|
+
if (args?.description !== undefined) {
|
|
109
|
+
meta.description = String(args.description).trim();
|
|
110
|
+
}
|
|
111
|
+
if (args?.icon !== undefined)
|
|
112
|
+
meta.icon = String(args.icon);
|
|
113
|
+
if (args?.visibility !== undefined) {
|
|
114
|
+
meta.visibility = String(args.visibility);
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(meta).length > 0) {
|
|
117
|
+
result = await updateTool(id, meta);
|
|
118
|
+
}
|
|
119
|
+
if (!result)
|
|
120
|
+
result = await getTool(id);
|
|
121
|
+
if (!result)
|
|
122
|
+
return `Error: tool not found: ${id}`;
|
|
123
|
+
return { ok: true, tool: result };
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
"add-tool-slot-target": {
|
|
127
|
+
tool: {
|
|
128
|
+
description: 'Declare that a tool can render in a UI extension-point slot of an app (e.g. "mail.contact-sidebar.bottom"). Apps drop ExtensionSlot components in their UI; this action registers a tool as installable into one of those slots. Slot IDs follow the convention <app>.<area>.<position>. Caller must have editor access to the tool.',
|
|
129
|
+
parameters: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
toolId: { type: "string", description: "Tool id." },
|
|
133
|
+
slotId: {
|
|
134
|
+
type: "string",
|
|
135
|
+
description: 'Slot identifier — e.g. "mail.contact-sidebar.bottom".',
|
|
136
|
+
},
|
|
137
|
+
config: {
|
|
138
|
+
type: "string",
|
|
139
|
+
description: "Optional JSON string with slot-specific config (defaults, hints, etc.).",
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
required: ["toolId", "slotId"],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
run: async (args) => {
|
|
146
|
+
const toolId = String(args?.toolId ?? "").trim();
|
|
147
|
+
const slotId = String(args?.slotId ?? "").trim();
|
|
148
|
+
if (!toolId)
|
|
149
|
+
return "Error: toolId is required.";
|
|
150
|
+
if (!slotId)
|
|
151
|
+
return "Error: slotId is required.";
|
|
152
|
+
const row = await addToolSlotTarget(toolId, slotId, args?.config ? String(args.config) : undefined);
|
|
153
|
+
return { ok: true, slot: row };
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
"install-extension": {
|
|
157
|
+
tool: {
|
|
158
|
+
description: "Install a tool as a widget in an extension-point slot for the current user. The tool must already declare the slot via add-tool-slot-target. Per-user installation — only affects the calling user's view. Use after creating a tool that targets a slot, or when the user asks to add an existing widget to a slot.",
|
|
159
|
+
parameters: {
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: {
|
|
162
|
+
toolId: { type: "string", description: "Tool id to install." },
|
|
163
|
+
slotId: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: 'Slot identifier — e.g. "mail.contact-sidebar.bottom".',
|
|
166
|
+
},
|
|
167
|
+
position: {
|
|
168
|
+
type: "number",
|
|
169
|
+
description: "Optional integer position within the slot (lower = earlier). Defaults to end.",
|
|
170
|
+
},
|
|
171
|
+
config: {
|
|
172
|
+
type: "string",
|
|
173
|
+
description: "Optional JSON string with per-install config (overrides, settings).",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
required: ["toolId", "slotId"],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
run: async (args) => {
|
|
180
|
+
const toolId = String(args?.toolId ?? "").trim();
|
|
181
|
+
const slotId = String(args?.slotId ?? "").trim();
|
|
182
|
+
if (!toolId)
|
|
183
|
+
return "Error: toolId is required.";
|
|
184
|
+
if (!slotId)
|
|
185
|
+
return "Error: slotId is required.";
|
|
186
|
+
const position = args?.position !== undefined && args.position !== null
|
|
187
|
+
? Number(args.position)
|
|
188
|
+
: undefined;
|
|
189
|
+
const row = await installToolSlot(toolId, slotId, {
|
|
190
|
+
position: Number.isFinite(position) ? position : undefined,
|
|
191
|
+
config: args?.config ? String(args.config) : undefined,
|
|
192
|
+
});
|
|
193
|
+
return { ok: true, install: row };
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
"uninstall-extension": {
|
|
197
|
+
tool: {
|
|
198
|
+
description: "Remove a tool from an extension-point slot for the current user. Does not delete the tool itself.",
|
|
199
|
+
parameters: {
|
|
200
|
+
type: "object",
|
|
201
|
+
properties: {
|
|
202
|
+
toolId: { type: "string", description: "Tool id." },
|
|
203
|
+
slotId: { type: "string", description: "Slot identifier." },
|
|
204
|
+
},
|
|
205
|
+
required: ["toolId", "slotId"],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
run: async (args) => {
|
|
209
|
+
const toolId = String(args?.toolId ?? "").trim();
|
|
210
|
+
const slotId = String(args?.slotId ?? "").trim();
|
|
211
|
+
if (!toolId)
|
|
212
|
+
return "Error: toolId is required.";
|
|
213
|
+
if (!slotId)
|
|
214
|
+
return "Error: slotId is required.";
|
|
215
|
+
await uninstallToolSlot(toolId, slotId);
|
|
216
|
+
return { ok: true };
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
"list-tools-for-slot": {
|
|
220
|
+
tool: {
|
|
221
|
+
description: "List tools the current user has access to that declare a given extension-point slot. Use to discover what's available to install into a slot the user mentioned.",
|
|
222
|
+
parameters: {
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: {
|
|
225
|
+
slotId: { type: "string", description: "Slot identifier." },
|
|
226
|
+
},
|
|
227
|
+
required: ["slotId"],
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
run: async (args) => {
|
|
231
|
+
const slotId = String(args?.slotId ?? "").trim();
|
|
232
|
+
if (!slotId)
|
|
233
|
+
return "Error: slotId is required.";
|
|
234
|
+
return { tools: await listToolsForSlot(slotId) };
|
|
235
|
+
},
|
|
236
|
+
readOnly: true,
|
|
237
|
+
},
|
|
238
|
+
"list-tool-slots": {
|
|
239
|
+
tool: {
|
|
240
|
+
description: "List the extension-point slots a specific tool declares it can render in. Caller must have viewer access to the tool.",
|
|
241
|
+
parameters: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
toolId: { type: "string", description: "Tool id." },
|
|
245
|
+
},
|
|
246
|
+
required: ["toolId"],
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
run: async (args) => {
|
|
250
|
+
const toolId = String(args?.toolId ?? "").trim();
|
|
251
|
+
if (!toolId)
|
|
252
|
+
return "Error: toolId is required.";
|
|
253
|
+
return { slots: await listSlotsForTool(toolId) };
|
|
254
|
+
},
|
|
255
|
+
readOnly: true,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function parsePatches(value) {
|
|
260
|
+
if (value === undefined)
|
|
261
|
+
return undefined;
|
|
262
|
+
const parsed = typeof value === "string" ? JSON.parse(value) : value;
|
|
263
|
+
if (!Array.isArray(parsed))
|
|
264
|
+
return undefined;
|
|
265
|
+
if (parsed.some((patch) => !patch ||
|
|
266
|
+
typeof patch.find !== "string" ||
|
|
267
|
+
typeof patch.replace !== "string")) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
return parsed;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/tools/actions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAI1B,MAAM,UAAU,uBAAuB;IACrC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K,EAAE,EAAE,CACR,CAAC,KAAK;QACN,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CACpC,EACD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { ActionEntry } from \"../agent/production-agent.js\";\nimport { createTool, getTool, updateTool, updateToolContent } from \"./store.js\";\nimport {\n addToolSlotTarget,\n installToolSlot,\n uninstallToolSlot,\n listToolsForSlot,\n listSlotsForTool,\n} from \"./slots/store.js\";\n\ntype ToolPatch = { find: string; replace: string };\n\nexport function createToolActionEntries(): Record<string, ActionEntry> {\n return {\n \"create-tool\": {\n tool: {\n description:\n \"Create a sandboxed Alpine.js mini-app tool. Use this when the user asks to create, build, or make a tool/widget/dashboard/calculator. The content must be a self-contained Alpine.js HTML body snippet that can use appAction(), appFetch(), dbQuery(), dbExec(), toolFetch(), and toolData.\",\n parameters: {\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description:\n 'Short display name for the tool. Do not include \"app\" — e.g. name a todo app \"Todos\", a weather app \"Weather\".',\n },\n description: {\n type: \"string\",\n description: \"One-sentence summary of what the tool does.\",\n },\n content: {\n type: \"string\",\n description:\n \"Self-contained Alpine.js HTML body snippet. The iframe body has no padding, so add p-4 or p-6 to the outermost element. Use semantic Tailwind colors (bg-background, text-foreground, bg-primary, etc.) for native theming. Do not include a full app build, React code, or source files.\",\n },\n icon: {\n type: \"string\",\n description: \"Optional icon name or short label.\",\n },\n },\n required: [\"name\", \"content\"],\n },\n },\n run: async (args) => {\n const name = String(args?.name ?? \"\").trim();\n const content = String(args?.content ?? \"\").trim();\n if (!name) return \"Error: name is required.\";\n if (!content) return \"Error: content is required.\";\n\n const tool = await createTool({\n name,\n description: String(args?.description ?? \"\").trim(),\n content,\n icon: args?.icon ? String(args.icon) : undefined,\n });\n\n return {\n ok: true,\n tool,\n next: `Navigate to /tools/${tool.id} or use the navigate action with --view=tools --toolId=${tool.id}.`,\n };\n },\n },\n\n \"update-tool\": {\n tool: {\n description:\n \"Update an existing sandboxed Alpine.js mini-app tool. Prefer patches for surgical edits; use full content replacement only when necessary.\",\n parameters: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n description: \"Tool id to update.\",\n },\n name: {\n type: \"string\",\n description: \"Optional new display name.\",\n },\n description: {\n type: \"string\",\n description: \"Optional new description.\",\n },\n content: {\n type: \"string\",\n description:\n \"Optional full replacement Alpine.js HTML body snippet.\",\n },\n patches: {\n type: \"string\",\n description:\n 'Optional JSON array of { \"find\": \"...\", \"replace\": \"...\" } patches to apply to the current content.',\n },\n icon: {\n type: \"string\",\n description: \"Optional icon name or short label.\",\n },\n visibility: {\n type: \"string\",\n description: \"Optional sharing visibility.\",\n enum: [\"private\", \"org\", \"public\"],\n },\n },\n required: [\"id\"],\n },\n },\n run: async (args) => {\n const id = String(args?.id ?? \"\").trim();\n if (!id) return \"Error: id is required.\";\n\n let result = null;\n if (args?.content !== undefined || args?.patches !== undefined) {\n const patches = parsePatches((args as any).patches);\n if (args?.patches !== undefined && !patches) {\n return \"Error: patches must be a JSON array of { find, replace } objects.\";\n }\n result = await updateToolContent(id, {\n content:\n args?.content !== undefined ? String(args.content) : undefined,\n patches,\n });\n }\n\n const meta: Record<string, string> = {};\n if (args?.name !== undefined) meta.name = String(args.name).trim();\n if (args?.description !== undefined) {\n meta.description = String(args.description).trim();\n }\n if (args?.icon !== undefined) meta.icon = String(args.icon);\n if (args?.visibility !== undefined) {\n meta.visibility = String(args.visibility);\n }\n if (Object.keys(meta).length > 0) {\n result = await updateTool(id, meta as any);\n }\n\n if (!result) result = await getTool(id);\n if (!result) return `Error: tool not found: ${id}`;\n return { ok: true, tool: result };\n },\n },\n\n \"add-tool-slot-target\": {\n tool: {\n description:\n 'Declare that a tool can render in a UI extension-point slot of an app (e.g. \"mail.contact-sidebar.bottom\"). Apps drop ExtensionSlot components in their UI; this action registers a tool as installable into one of those slots. Slot IDs follow the convention <app>.<area>.<position>. Caller must have editor access to the tool.',\n parameters: {\n type: \"object\",\n properties: {\n toolId: { type: \"string\", description: \"Tool id.\" },\n slotId: {\n type: \"string\",\n description:\n 'Slot identifier — e.g. \"mail.contact-sidebar.bottom\".',\n },\n config: {\n type: \"string\",\n description:\n \"Optional JSON string with slot-specific config (defaults, hints, etc.).\",\n },\n },\n required: [\"toolId\", \"slotId\"],\n },\n },\n run: async (args) => {\n const toolId = String(args?.toolId ?? \"\").trim();\n const slotId = String(args?.slotId ?? \"\").trim();\n if (!toolId) return \"Error: toolId is required.\";\n if (!slotId) return \"Error: slotId is required.\";\n const row = await addToolSlotTarget(\n toolId,\n slotId,\n args?.config ? String(args.config) : undefined,\n );\n return { ok: true, slot: row };\n },\n },\n\n \"install-extension\": {\n tool: {\n description:\n \"Install a tool as a widget in an extension-point slot for the current user. The tool must already declare the slot via add-tool-slot-target. Per-user installation — only affects the calling user's view. Use after creating a tool that targets a slot, or when the user asks to add an existing widget to a slot.\",\n parameters: {\n type: \"object\",\n properties: {\n toolId: { type: \"string\", description: \"Tool id to install.\" },\n slotId: {\n type: \"string\",\n description:\n 'Slot identifier — e.g. \"mail.contact-sidebar.bottom\".',\n },\n position: {\n type: \"number\",\n description:\n \"Optional integer position within the slot (lower = earlier). Defaults to end.\",\n },\n config: {\n type: \"string\",\n description:\n \"Optional JSON string with per-install config (overrides, settings).\",\n },\n },\n required: [\"toolId\", \"slotId\"],\n },\n },\n run: async (args) => {\n const toolId = String(args?.toolId ?? \"\").trim();\n const slotId = String(args?.slotId ?? \"\").trim();\n if (!toolId) return \"Error: toolId is required.\";\n if (!slotId) return \"Error: slotId is required.\";\n const position =\n args?.position !== undefined && args.position !== null\n ? Number(args.position)\n : undefined;\n const row = await installToolSlot(toolId, slotId, {\n position: Number.isFinite(position as number) ? position : undefined,\n config: args?.config ? String(args.config) : undefined,\n });\n return { ok: true, install: row };\n },\n },\n\n \"uninstall-extension\": {\n tool: {\n description:\n \"Remove a tool from an extension-point slot for the current user. Does not delete the tool itself.\",\n parameters: {\n type: \"object\",\n properties: {\n toolId: { type: \"string\", description: \"Tool id.\" },\n slotId: { type: \"string\", description: \"Slot identifier.\" },\n },\n required: [\"toolId\", \"slotId\"],\n },\n },\n run: async (args) => {\n const toolId = String(args?.toolId ?? \"\").trim();\n const slotId = String(args?.slotId ?? \"\").trim();\n if (!toolId) return \"Error: toolId is required.\";\n if (!slotId) return \"Error: slotId is required.\";\n await uninstallToolSlot(toolId, slotId);\n return { ok: true };\n },\n },\n\n \"list-tools-for-slot\": {\n tool: {\n description:\n \"List tools the current user has access to that declare a given extension-point slot. Use to discover what's available to install into a slot the user mentioned.\",\n parameters: {\n type: \"object\",\n properties: {\n slotId: { type: \"string\", description: \"Slot identifier.\" },\n },\n required: [\"slotId\"],\n },\n },\n run: async (args) => {\n const slotId = String(args?.slotId ?? \"\").trim();\n if (!slotId) return \"Error: slotId is required.\";\n return { tools: await listToolsForSlot(slotId) };\n },\n readOnly: true,\n },\n\n \"list-tool-slots\": {\n tool: {\n description:\n \"List the extension-point slots a specific tool declares it can render in. Caller must have viewer access to the tool.\",\n parameters: {\n type: \"object\",\n properties: {\n toolId: { type: \"string\", description: \"Tool id.\" },\n },\n required: [\"toolId\"],\n },\n },\n run: async (args) => {\n const toolId = String(args?.toolId ?? \"\").trim();\n if (!toolId) return \"Error: toolId is required.\";\n return { slots: await listSlotsForTool(toolId) };\n },\n readOnly: true,\n },\n };\n}\n\nfunction parsePatches(value: unknown): ToolPatch[] | undefined {\n if (value === undefined) return undefined;\n const parsed = typeof value === \"string\" ? JSON.parse(value) : value;\n if (!Array.isArray(parsed)) return undefined;\n if (\n parsed.some(\n (patch) =>\n !patch ||\n typeof patch.find !== \"string\" ||\n typeof patch.replace !== \"string\",\n )\n ) {\n return undefined;\n }\n return parsed;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch tool — outbound HTTP for automations and agent use.
|
|
3
|
+
*
|
|
4
|
+
* Supports ${keys.NAME} reference substitution in URL, headers, and body.
|
|
5
|
+
* Values are resolved server-side AFTER the model emits the tool call —
|
|
6
|
+
* the raw secret never enters the model's context.
|
|
7
|
+
*/
|
|
8
|
+
import type { ActionEntry } from "../agent/production-agent.js";
|
|
9
|
+
export interface FetchToolOptions {
|
|
10
|
+
/** Resolve ${keys.NAME} references. Injected by the plugin at setup time. */
|
|
11
|
+
resolveKeys?: (text: string) => Promise<{
|
|
12
|
+
resolved: string;
|
|
13
|
+
usedKeys: string[];
|
|
14
|
+
secretValues?: string[];
|
|
15
|
+
}>;
|
|
16
|
+
/** Validate URL against per-key allowlists. */
|
|
17
|
+
validateUrl?: (url: string, usedKeys: string[]) => Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create the fetch tool entry for the agent tool registry.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createFetchToolEntry(opts?: FetchToolOptions): Record<string, ActionEntry>;
|
|
23
|
+
//# sourceMappingURL=fetch-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-tool.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAchE,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QACtC,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACzB,CAAC,CAAC;IACH,+CAA+C;IAC/C,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,GAAE,gBAAqB,GAC1B,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAgM7B"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch tool — outbound HTTP for automations and agent use.
|
|
3
|
+
*
|
|
4
|
+
* Supports ${keys.NAME} reference substitution in URL, headers, and body.
|
|
5
|
+
* Values are resolved server-side AFTER the model emits the tool call —
|
|
6
|
+
* the raw secret never enters the model's context.
|
|
7
|
+
*/
|
|
8
|
+
import { collectSecretValues, MAX_TOOL_PROXY_RESPONSE_SIZE, normalizeToolProxyMethod, readResponseTextWithLimit, redactSecrets, redactString, sanitizeOutboundHeaders, } from "./proxy-security.js";
|
|
9
|
+
import { isBlockedToolUrlWithDns } from "./url-safety.js";
|
|
10
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
11
|
+
/**
|
|
12
|
+
* Create the fetch tool entry for the agent tool registry.
|
|
13
|
+
*/
|
|
14
|
+
export function createFetchToolEntry(opts = {}) {
|
|
15
|
+
return {
|
|
16
|
+
"web-request": {
|
|
17
|
+
tool: {
|
|
18
|
+
description: `Make an outbound HTTP request to EXTERNAL APIs, webhooks, and services only. Supports \${keys.NAME} placeholders in url, headers, and body — these are resolved server-side from the user's saved keys (the raw value never enters your context). Example: \${keys.SLACK_WEBHOOK} in the url field. IMPORTANT: Never use this to call internal /_agent-native/ endpoints or localhost action URLs — use the registered action tools directly (e.g. \`log-meal\`, \`bigquery\`, \`hubspot-deals\`). Actions are already available as native tools; calling them via HTTP is slower and bypasses validation.`,
|
|
19
|
+
parameters: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
url: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: 'Full URL. May contain ${keys.NAME} references, e.g. "${keys.SLACK_WEBHOOK}".',
|
|
25
|
+
},
|
|
26
|
+
method: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "HTTP method. Default: GET.",
|
|
29
|
+
enum: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"],
|
|
30
|
+
},
|
|
31
|
+
headers: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: 'JSON object of headers. May contain ${keys.NAME} references. Example: \'{"Authorization": "Bearer ${keys.API_TOKEN}"}\'.',
|
|
34
|
+
},
|
|
35
|
+
body: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Request body (for POST/PUT/PATCH). May contain ${keys.NAME} references.",
|
|
38
|
+
},
|
|
39
|
+
timeout_ms: {
|
|
40
|
+
type: "number",
|
|
41
|
+
description: `Timeout in milliseconds. Default: ${DEFAULT_TIMEOUT_MS}. Max: 30000.`,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
required: ["url"],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
run: async (args) => {
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
const rawUrl = args.url;
|
|
50
|
+
const method = normalizeToolProxyMethod(args.method || "GET");
|
|
51
|
+
if (!method) {
|
|
52
|
+
return "Unsupported HTTP method. Allowed methods: GET, POST, PUT, PATCH, DELETE, HEAD.";
|
|
53
|
+
}
|
|
54
|
+
const rawHeaders = args.headers || "{}";
|
|
55
|
+
const rawBody = args.body;
|
|
56
|
+
const timeoutMs = Math.min(Number(args.timeout_ms) || DEFAULT_TIMEOUT_MS, 30_000);
|
|
57
|
+
// Resolve key references
|
|
58
|
+
let resolvedUrl = rawUrl;
|
|
59
|
+
let resolvedHeaders = rawHeaders;
|
|
60
|
+
let resolvedBody = rawBody;
|
|
61
|
+
const allUsedKeys = [];
|
|
62
|
+
const allSecretValues = [];
|
|
63
|
+
if (opts.resolveKeys) {
|
|
64
|
+
try {
|
|
65
|
+
const urlResult = await opts.resolveKeys(rawUrl);
|
|
66
|
+
resolvedUrl = urlResult.resolved;
|
|
67
|
+
allUsedKeys.push(...urlResult.usedKeys);
|
|
68
|
+
allSecretValues.push(...(urlResult.secretValues ?? []));
|
|
69
|
+
const headerResult = await opts.resolveKeys(rawHeaders);
|
|
70
|
+
resolvedHeaders = headerResult.resolved;
|
|
71
|
+
allUsedKeys.push(...headerResult.usedKeys);
|
|
72
|
+
allSecretValues.push(...(headerResult.secretValues ?? []));
|
|
73
|
+
if (rawBody) {
|
|
74
|
+
const bodyResult = await opts.resolveKeys(rawBody);
|
|
75
|
+
resolvedBody = bodyResult.resolved;
|
|
76
|
+
allUsedKeys.push(...bodyResult.usedKeys);
|
|
77
|
+
allSecretValues.push(...(bodyResult.secretValues ?? []));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
return `Error resolving key references: ${err?.message ?? err}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const secretValues = collectSecretValues(allSecretValues);
|
|
85
|
+
// Block SSRF targets regardless of key usage
|
|
86
|
+
if (await isBlockedToolUrlWithDns(resolvedUrl)) {
|
|
87
|
+
return `Requests to private/internal addresses are not allowed: "${rawUrl}".`;
|
|
88
|
+
}
|
|
89
|
+
// Validate URL against per-key allowlists
|
|
90
|
+
if (opts.validateUrl && allUsedKeys.length > 0) {
|
|
91
|
+
try {
|
|
92
|
+
const allowed = await opts.validateUrl(resolvedUrl, allUsedKeys);
|
|
93
|
+
if (!allowed) {
|
|
94
|
+
return `URL "${rawUrl}" is not in the allowlist for the referenced keys. Check your key settings.`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
return `URL validation error: ${err?.message ?? err}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Parse headers
|
|
102
|
+
let headers;
|
|
103
|
+
try {
|
|
104
|
+
headers = sanitizeOutboundHeaders(JSON.parse(resolvedHeaders));
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return `Invalid headers JSON: ${rawHeaders}`;
|
|
108
|
+
}
|
|
109
|
+
// Make the request
|
|
110
|
+
const controller = new AbortController();
|
|
111
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
112
|
+
try {
|
|
113
|
+
const fetchOpts = {
|
|
114
|
+
method,
|
|
115
|
+
headers,
|
|
116
|
+
signal: controller.signal,
|
|
117
|
+
redirect: "manual",
|
|
118
|
+
};
|
|
119
|
+
if (resolvedBody && ["POST", "PUT", "PATCH"].includes(method)) {
|
|
120
|
+
fetchOpts.body = resolvedBody;
|
|
121
|
+
if (!headers["content-type"] && !headers["Content-Type"]) {
|
|
122
|
+
headers["Content-Type"] = "application/json";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const response = await fetch(resolvedUrl, fetchOpts);
|
|
126
|
+
const elapsed = Date.now() - startTime;
|
|
127
|
+
if (response.status >= 300 && response.status < 400) {
|
|
128
|
+
const location = response.headers.get("location");
|
|
129
|
+
const redirectUrl = location
|
|
130
|
+
? new URL(location, resolvedUrl).href
|
|
131
|
+
: null;
|
|
132
|
+
if (redirectUrl && (await isBlockedToolUrlWithDns(redirectUrl))) {
|
|
133
|
+
return "Redirect to private/internal address blocked.";
|
|
134
|
+
}
|
|
135
|
+
if (redirectUrl && opts.validateUrl && allUsedKeys.length > 0) {
|
|
136
|
+
const allowed = await opts.validateUrl(redirectUrl, allUsedKeys);
|
|
137
|
+
if (!allowed) {
|
|
138
|
+
return "Redirect URL is not in the allowlist for the referenced keys.";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return `HTTP ${response.status} ${response.statusText}\n\nRedirect: ${redirectUrl ? redactString(redirectUrl, secretValues) : "(none)"}`;
|
|
142
|
+
}
|
|
143
|
+
let body;
|
|
144
|
+
try {
|
|
145
|
+
const result = await readResponseTextWithLimit(response, MAX_TOOL_PROXY_RESPONSE_SIZE);
|
|
146
|
+
body = result.text;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
body = "(could not read response body)";
|
|
150
|
+
}
|
|
151
|
+
body = redactString(body, secretValues);
|
|
152
|
+
// Truncate very long responses for the agent
|
|
153
|
+
if (body.length > 8000) {
|
|
154
|
+
body = body.slice(0, 8000) + "\n... (truncated)";
|
|
155
|
+
}
|
|
156
|
+
// Audit log
|
|
157
|
+
console.log(`[fetch-tool] ${method} ${rawUrl} → ${response.status} (${elapsed}ms, keys: ${allUsedKeys.join(",") || "none"})`);
|
|
158
|
+
return `HTTP ${response.status} ${response.statusText}\n\n${body}`;
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
const elapsed = Date.now() - startTime;
|
|
162
|
+
if (err?.name === "AbortError") {
|
|
163
|
+
console.log(`[fetch-tool] ${method} ${rawUrl} → TIMEOUT (${elapsed}ms)`);
|
|
164
|
+
return `Request timed out after ${timeoutMs}ms.`;
|
|
165
|
+
}
|
|
166
|
+
const message = redactSecrets(err?.message ?? String(err), secretValues);
|
|
167
|
+
console.log(`[fetch-tool] ${method} ${rawUrl} → ERROR: ${message} (${elapsed}ms)`);
|
|
168
|
+
return `Request failed: ${message}`;
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
clearTimeout(timeout);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
readOnly: true,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=fetch-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-tool.js","sourceRoot":"","sources":["../../src/tools/fetch-tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACb,YAAY,EACZ,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAalC;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAyB,EAAE;IAE3B,OAAO;Q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B,YAAY,CACb,CAAC;oBACF,OAAO,CAAC,GAAG,CACT,gBAAgB,MAAM,IAAI,MAAM,aAAa,OAAO,KAAK,OAAO,KAAK,CACtE,CAAC;oBACF,OAAO,mBAAmB,OAAO,EAAE,CAAC;gBACtC,CAAC;wBAAS,CAAC;oBACT,YAAY,CAAC,OAAO,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,QAAQ,EAAE,IAAI;SACf;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Fetch tool — outbound HTTP for automations and agent use.\n *\n * Supports ${keys.NAME} reference substitution in URL, headers, and body.\n * Values are resolved server-side AFTER the model emits the tool call —\n * the raw secret never enters the model's context.\n */\n\nimport type { ActionEntry } from \"../agent/production-agent.js\";\nimport {\n collectSecretValues,\n MAX_TOOL_PROXY_RESPONSE_SIZE,\n normalizeToolProxyMethod,\n readResponseTextWithLimit,\n redactSecrets,\n redactString,\n sanitizeOutboundHeaders,\n} from \"./proxy-security.js\";\nimport { isBlockedToolUrlWithDns } from \"./url-safety.js\";\n\nconst DEFAULT_TIMEOUT_MS = 15_000;\n\nexport interface FetchToolOptions {\n /** Resolve ${keys.NAME} references. Injected by the plugin at setup time. */\n resolveKeys?: (text: string) => Promise<{\n resolved: string;\n usedKeys: string[];\n secretValues?: string[];\n }>;\n /** Validate URL against per-key allowlists. */\n validateUrl?: (url: string, usedKeys: string[]) => Promise<boolean>;\n}\n\n/**\n * Create the fetch tool entry for the agent tool registry.\n */\nexport function createFetchToolEntry(\n opts: FetchToolOptions = {},\n): Record<string, ActionEntry> {\n return {\n \"web-request\": {\n tool: {\n description: `Make an outbound HTTP request to EXTERNAL APIs, webhooks, and services only. Supports \\${keys.NAME} placeholders in url, headers, and body — these are resolved server-side from the user's saved keys (the raw value never enters your context). Example: \\${keys.SLACK_WEBHOOK} in the url field. IMPORTANT: Never use this to call internal /_agent-native/ endpoints or localhost action URLs — use the registered action tools directly (e.g. \\`log-meal\\`, \\`bigquery\\`, \\`hubspot-deals\\`). Actions are already available as native tools; calling them via HTTP is slower and bypasses validation.`,\n parameters: {\n type: \"object\" as const,\n properties: {\n url: {\n type: \"string\",\n description:\n 'Full URL. May contain ${keys.NAME} references, e.g. \"${keys.SLACK_WEBHOOK}\".',\n },\n method: {\n type: \"string\",\n description: \"HTTP method. Default: GET.\",\n enum: [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"HEAD\"],\n },\n headers: {\n type: \"string\",\n description:\n 'JSON object of headers. May contain ${keys.NAME} references. Example: \\'{\"Authorization\": \"Bearer ${keys.API_TOKEN}\"}\\'.',\n },\n body: {\n type: \"string\",\n description:\n \"Request body (for POST/PUT/PATCH). May contain ${keys.NAME} references.\",\n },\n timeout_ms: {\n type: \"number\",\n description: `Timeout in milliseconds. Default: ${DEFAULT_TIMEOUT_MS}. Max: 30000.`,\n },\n },\n required: [\"url\"],\n },\n },\n run: async (args: Record<string, string>) => {\n const startTime = Date.now();\n const rawUrl = args.url;\n const method = normalizeToolProxyMethod(args.method || \"GET\");\n if (!method) {\n return \"Unsupported HTTP method. Allowed methods: GET, POST, PUT, PATCH, DELETE, HEAD.\";\n }\n const rawHeaders = args.headers || \"{}\";\n const rawBody = args.body;\n const timeoutMs = Math.min(\n Number(args.timeout_ms) || DEFAULT_TIMEOUT_MS,\n 30_000,\n );\n\n // Resolve key references\n let resolvedUrl = rawUrl;\n let resolvedHeaders = rawHeaders;\n let resolvedBody = rawBody;\n const allUsedKeys: string[] = [];\n const allSecretValues: string[] = [];\n\n if (opts.resolveKeys) {\n try {\n const urlResult = await opts.resolveKeys(rawUrl);\n resolvedUrl = urlResult.resolved;\n allUsedKeys.push(...urlResult.usedKeys);\n allSecretValues.push(...(urlResult.secretValues ?? []));\n\n const headerResult = await opts.resolveKeys(rawHeaders);\n resolvedHeaders = headerResult.resolved;\n allUsedKeys.push(...headerResult.usedKeys);\n allSecretValues.push(...(headerResult.secretValues ?? []));\n\n if (rawBody) {\n const bodyResult = await opts.resolveKeys(rawBody);\n resolvedBody = bodyResult.resolved;\n allUsedKeys.push(...bodyResult.usedKeys);\n allSecretValues.push(...(bodyResult.secretValues ?? []));\n }\n } catch (err: any) {\n return `Error resolving key references: ${err?.message ?? err}`;\n }\n }\n const secretValues = collectSecretValues(allSecretValues);\n\n // Block SSRF targets regardless of key usage\n if (await isBlockedToolUrlWithDns(resolvedUrl)) {\n return `Requests to private/internal addresses are not allowed: \"${rawUrl}\".`;\n }\n\n // Validate URL against per-key allowlists\n if (opts.validateUrl && allUsedKeys.length > 0) {\n try {\n const allowed = await opts.validateUrl(resolvedUrl, allUsedKeys);\n if (!allowed) {\n return `URL \"${rawUrl}\" is not in the allowlist for the referenced keys. Check your key settings.`;\n }\n } catch (err: any) {\n return `URL validation error: ${err?.message ?? err}`;\n }\n }\n\n // Parse headers\n let headers: Record<string, string>;\n try {\n headers = sanitizeOutboundHeaders(JSON.parse(resolvedHeaders));\n } catch {\n return `Invalid headers JSON: ${rawHeaders}`;\n }\n\n // Make the request\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n\n try {\n const fetchOpts: RequestInit = {\n method,\n headers,\n signal: controller.signal,\n redirect: \"manual\",\n };\n if (resolvedBody && [\"POST\", \"PUT\", \"PATCH\"].includes(method)) {\n fetchOpts.body = resolvedBody;\n if (!headers[\"content-type\"] && !headers[\"Content-Type\"]) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n }\n\n const response = await fetch(resolvedUrl, fetchOpts);\n const elapsed = Date.now() - startTime;\n\n if (response.status >= 300 && response.status < 400) {\n const location = response.headers.get(\"location\");\n const redirectUrl = location\n ? new URL(location, resolvedUrl).href\n : null;\n if (redirectUrl && (await isBlockedToolUrlWithDns(redirectUrl))) {\n return \"Redirect to private/internal address blocked.\";\n }\n if (redirectUrl && opts.validateUrl && allUsedKeys.length > 0) {\n const allowed = await opts.validateUrl(redirectUrl, allUsedKeys);\n if (!allowed) {\n return \"Redirect URL is not in the allowlist for the referenced keys.\";\n }\n }\n return `HTTP ${response.status} ${response.statusText}\\n\\nRedirect: ${\n redirectUrl ? redactString(redirectUrl, secretValues) : \"(none)\"\n }`;\n }\n\n let body: string;\n try {\n const result = await readResponseTextWithLimit(\n response,\n MAX_TOOL_PROXY_RESPONSE_SIZE,\n );\n body = result.text;\n } catch {\n body = \"(could not read response body)\";\n }\n body = redactString(body, secretValues);\n\n // Truncate very long responses for the agent\n if (body.length > 8000) {\n body = body.slice(0, 8000) + \"\\n... (truncated)\";\n }\n\n // Audit log\n console.log(\n `[fetch-tool] ${method} ${rawUrl} → ${response.status} (${elapsed}ms, keys: ${allUsedKeys.join(\",\") || \"none\"})`,\n );\n\n return `HTTP ${response.status} ${response.statusText}\\n\\n${body}`;\n } catch (err: any) {\n const elapsed = Date.now() - startTime;\n if (err?.name === \"AbortError\") {\n console.log(\n `[fetch-tool] ${method} ${rawUrl} → TIMEOUT (${elapsed}ms)`,\n );\n return `Request timed out after ${timeoutMs}ms.`;\n }\n const message = redactSecrets(\n err?.message ?? String(err),\n secretValues,\n );\n console.log(\n `[fetch-tool] ${method} ${rawUrl} → ERROR: ${message} (${elapsed}ms)`,\n );\n return `Request failed: ${message}`;\n } finally {\n clearTimeout(timeout);\n }\n },\n readOnly: true,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const TOOL_IFRAME_CSP = "default-src 'none'; script-src 'self' https://cdn.jsdelivr.net 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com; font-src https://fonts.gstatic.com; connect-src 'self'; img-src 'self' data: blob:; media-src 'self' data: blob:; frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'self';";
|
|
2
|
+
export declare const TOOL_IFRAME_META_CSP: string;
|
|
3
|
+
/**
|
|
4
|
+
* SECURITY — TOOL CONTENT IS UNTRUSTED.
|
|
5
|
+
*
|
|
6
|
+
* `${content}` (line ~Body) interpolates raw HTML/JS authored by a user. This
|
|
7
|
+
* file is the boundary between framework-controlled HTML and user-controlled
|
|
8
|
+
* HTML. Two non-negotiable invariants for every change here:
|
|
9
|
+
*
|
|
10
|
+
* 1. The iframe MUST be rendered with a `sandbox` attribute that does NOT
|
|
11
|
+
* include `allow-same-origin`. The viewer (`ToolViewer.tsx`,
|
|
12
|
+
* `EmbeddedTool.tsx`) sets `sandbox="allow-scripts allow-forms"` — and
|
|
13
|
+
* that is the only acceptable shape. Adding `allow-same-origin` would
|
|
14
|
+
* give the tool full DOM access to the parent window via cross-frame
|
|
15
|
+
* script.
|
|
16
|
+
*
|
|
17
|
+
* 2. Every reachable parent action must treat the postMessage payload as
|
|
18
|
+
* hostile. The bridge in `iframe-bridge.ts` enforces a path allowlist,
|
|
19
|
+
* header sanitization, and method allowlist; do not relax those gates
|
|
20
|
+
* for "convenience" in this file or any caller.
|
|
21
|
+
*
|
|
22
|
+
* For the trust model rationale, see audit 05-tools-sandbox.md (C1) and the
|
|
23
|
+
* `tools` skill. When in doubt, fail closed.
|
|
24
|
+
*/
|
|
25
|
+
export interface ToolRenderBinding {
|
|
26
|
+
/** Email of the user who authored / owns the tool. */
|
|
27
|
+
authorEmail: string;
|
|
28
|
+
/** Email of the user currently viewing/running the tool. */
|
|
29
|
+
viewerEmail: string;
|
|
30
|
+
/** True when viewer === author. */
|
|
31
|
+
isAuthor: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Resolved role for the viewer ("owner" | "admin" | "editor" | "viewer").
|
|
34
|
+
*
|
|
35
|
+
* TODO(security, audit H4): the host-side bridge does not yet gate any
|
|
36
|
+
* helper based on this value — every viewer gets the same powers as the
|
|
37
|
+
* author. The role is plumbed through so a follow-up PR can constrain
|
|
38
|
+
* `appAction` / `dbExec` / `toolFetch` for non-author viewers (and
|
|
39
|
+
* eventually require an explicit consent step before running a shared
|
|
40
|
+
* tool, audit C1). For now this is metadata only.
|
|
41
|
+
*/
|
|
42
|
+
role: "owner" | "admin" | "editor" | "viewer";
|
|
43
|
+
}
|
|
44
|
+
export declare function buildToolHtml(content: string, themeVars: string, isDark: boolean, toolId?: string, binding?: ToolRenderBinding): string;
|
|
45
|
+
//# sourceMappingURL=html-shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-shell.d.ts","sourceRoot":"","sources":["../../src/tools/html-shell.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,8YACiX,CAAC;AAE9Y,eAAO,MAAM,oBAAoB,QAGhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;;;;;OASG;IACH,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC/C;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,CA0fR"}
|