@agent-native/core 0.7.83 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/dist/action.js +1 -1
  2. package/dist/action.js.map +1 -1
  3. package/dist/agent/production-agent.d.ts.map +1 -1
  4. package/dist/agent/production-agent.js +8 -8
  5. package/dist/agent/production-agent.js.map +1 -1
  6. package/dist/agent/run-manager.d.ts +2 -0
  7. package/dist/agent/run-manager.d.ts.map +1 -1
  8. package/dist/agent/run-manager.js +44 -18
  9. package/dist/agent/run-manager.js.map +1 -1
  10. package/dist/agent/types.d.ts +1 -1
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/agent/types.js.map +1 -1
  13. package/dist/cli/create.d.ts.map +1 -1
  14. package/dist/cli/create.js +54 -11
  15. package/dist/cli/create.js.map +1 -1
  16. package/dist/cli/workspacify.d.ts.map +1 -1
  17. package/dist/cli/workspacify.js +12 -9
  18. package/dist/cli/workspacify.js.map +1 -1
  19. package/dist/client/AgentPanel.d.ts +1 -1
  20. package/dist/client/AgentPanel.d.ts.map +1 -1
  21. package/dist/client/AgentPanel.js +22 -1
  22. package/dist/client/AgentPanel.js.map +1 -1
  23. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  24. package/dist/client/agent-chat-adapter.js +254 -29
  25. package/dist/client/agent-chat-adapter.js.map +1 -1
  26. package/dist/client/agent-chat.d.ts +2 -0
  27. package/dist/client/agent-chat.d.ts.map +1 -1
  28. package/dist/client/agent-chat.js +11 -2
  29. package/dist/client/agent-chat.js.map +1 -1
  30. package/dist/client/composer/ComposerPlusMenu.js +1 -1
  31. package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
  32. package/dist/client/composer/PromptComposer.js +1 -1
  33. package/dist/client/composer/PromptComposer.js.map +1 -1
  34. package/dist/client/composer/TiptapComposer.js +8 -8
  35. package/dist/client/composer/TiptapComposer.js.map +1 -1
  36. package/dist/client/composer/types.d.ts +1 -1
  37. package/dist/client/composer/types.d.ts.map +1 -1
  38. package/dist/client/composer/types.js.map +1 -1
  39. package/dist/client/extensions/EmbeddedExtension.d.ts +20 -0
  40. package/dist/client/extensions/EmbeddedExtension.d.ts.map +1 -0
  41. package/dist/client/{tools/EmbeddedTool.js → extensions/EmbeddedExtension.js} +41 -41
  42. package/dist/client/extensions/EmbeddedExtension.js.map +1 -0
  43. package/dist/client/extensions/ExtensionEditor.d.ts +5 -0
  44. package/dist/client/extensions/ExtensionEditor.d.ts.map +1 -0
  45. package/dist/client/extensions/ExtensionEditor.js +129 -0
  46. package/dist/client/extensions/ExtensionEditor.js.map +1 -0
  47. package/dist/client/{tools → extensions}/ExtensionSlot.d.ts +3 -3
  48. package/dist/client/extensions/ExtensionSlot.d.ts.map +1 -0
  49. package/dist/client/{tools → extensions}/ExtensionSlot.js +14 -14
  50. package/dist/client/extensions/ExtensionSlot.js.map +1 -0
  51. package/dist/client/extensions/ExtensionViewer.d.ts +5 -0
  52. package/dist/client/extensions/ExtensionViewer.d.ts.map +1 -0
  53. package/dist/client/{tools/ToolViewer.js → extensions/ExtensionViewer.js} +67 -65
  54. package/dist/client/extensions/ExtensionViewer.js.map +1 -0
  55. package/dist/client/extensions/ExtensionViewerPage.d.ts +2 -0
  56. package/dist/client/extensions/ExtensionViewerPage.d.ts.map +1 -0
  57. package/dist/client/{tools/ToolViewerPage.js → extensions/ExtensionViewerPage.js} +8 -8
  58. package/dist/client/extensions/ExtensionViewerPage.js.map +1 -0
  59. package/dist/client/extensions/ExtensionsListPage.d.ts +2 -0
  60. package/dist/client/extensions/ExtensionsListPage.d.ts.map +1 -0
  61. package/dist/client/extensions/ExtensionsListPage.js +67 -0
  62. package/dist/client/extensions/ExtensionsListPage.js.map +1 -0
  63. package/dist/client/extensions/ExtensionsSidebarSection.d.ts +2 -0
  64. package/dist/client/extensions/ExtensionsSidebarSection.d.ts.map +1 -0
  65. package/dist/client/{tools/ToolsSidebarSection.js → extensions/ExtensionsSidebarSection.js} +58 -58
  66. package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -0
  67. package/dist/client/{tools/tool-order.d.ts → extensions/extension-order.d.ts} +2 -2
  68. package/dist/client/extensions/extension-order.d.ts.map +1 -0
  69. package/dist/client/{tools/tool-order.js → extensions/extension-order.js} +3 -3
  70. package/dist/client/extensions/extension-order.js.map +1 -0
  71. package/dist/client/{tools → extensions}/iframe-bridge.d.ts +11 -11
  72. package/dist/client/extensions/iframe-bridge.d.ts.map +1 -0
  73. package/dist/client/{tools → extensions}/iframe-bridge.js +24 -24
  74. package/dist/client/extensions/iframe-bridge.js.map +1 -0
  75. package/dist/client/extensions/index.d.ts +14 -0
  76. package/dist/client/extensions/index.d.ts.map +1 -0
  77. package/dist/client/extensions/index.js +19 -0
  78. package/dist/client/extensions/index.js.map +1 -0
  79. package/dist/client/sse-event-processor.d.ts +2 -1
  80. package/dist/client/sse-event-processor.d.ts.map +1 -1
  81. package/dist/client/sse-event-processor.js +87 -6
  82. package/dist/client/sse-event-processor.js.map +1 -1
  83. package/dist/extensions/actions.d.ts +3 -0
  84. package/dist/extensions/actions.d.ts.map +1 -0
  85. package/dist/{tools → extensions}/actions.js +54 -51
  86. package/dist/extensions/actions.js.map +1 -0
  87. package/dist/{tools → extensions}/fetch-tool.d.ts +4 -0
  88. package/dist/extensions/fetch-tool.d.ts.map +1 -0
  89. package/dist/{tools → extensions}/fetch-tool.js +12 -7
  90. package/dist/extensions/fetch-tool.js.map +1 -0
  91. package/dist/extensions/html-shell.d.ts +56 -0
  92. package/dist/extensions/html-shell.d.ts.map +1 -0
  93. package/dist/{tools → extensions}/html-shell.js +101 -83
  94. package/dist/extensions/html-shell.js.map +1 -0
  95. package/dist/{tools → extensions}/proxy-security.d.ts +2 -2
  96. package/dist/extensions/proxy-security.d.ts.map +1 -0
  97. package/dist/{tools → extensions}/proxy-security.js +3 -3
  98. package/dist/extensions/proxy-security.js.map +1 -0
  99. package/dist/extensions/routes.d.ts +2 -0
  100. package/dist/extensions/routes.d.ts.map +1 -0
  101. package/dist/{tools → extensions}/routes.js +73 -69
  102. package/dist/extensions/routes.js.map +1 -0
  103. package/dist/{tools → extensions}/schema.d.ts +44 -38
  104. package/dist/extensions/schema.d.ts.map +1 -0
  105. package/dist/{tools → extensions}/schema.js +41 -34
  106. package/dist/extensions/schema.js.map +1 -0
  107. package/dist/extensions/slots/routes.d.ts +15 -0
  108. package/dist/extensions/slots/routes.d.ts.map +1 -0
  109. package/dist/{tools → extensions}/slots/routes.js +26 -26
  110. package/dist/extensions/slots/routes.js.map +1 -0
  111. package/dist/{tools → extensions}/slots/schema.d.ts +24 -21
  112. package/dist/extensions/slots/schema.d.ts.map +1 -0
  113. package/dist/extensions/slots/schema.js +79 -0
  114. package/dist/extensions/slots/schema.js.map +1 -0
  115. package/dist/extensions/slots/store.d.ts +66 -0
  116. package/dist/extensions/slots/store.d.ts.map +1 -0
  117. package/dist/extensions/slots/store.js +238 -0
  118. package/dist/extensions/slots/store.js.map +1 -0
  119. package/dist/extensions/store.d.ts +40 -0
  120. package/dist/extensions/store.d.ts.map +1 -0
  121. package/dist/{tools → extensions}/store.js +59 -54
  122. package/dist/extensions/store.js.map +1 -0
  123. package/dist/extensions/theme.d.ts.map +1 -0
  124. package/dist/extensions/theme.js.map +1 -0
  125. package/dist/{tools → extensions}/url-safety.d.ts +5 -3
  126. package/dist/extensions/url-safety.d.ts.map +1 -0
  127. package/dist/{tools → extensions}/url-safety.js +11 -4
  128. package/dist/extensions/url-safety.js.map +1 -0
  129. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  130. package/dist/server/agent-chat-plugin.js +12 -10
  131. package/dist/server/agent-chat-plugin.js.map +1 -1
  132. package/dist/server/core-routes-plugin.d.ts +15 -0
  133. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  134. package/dist/server/core-routes-plugin.js +64 -10
  135. package/dist/server/core-routes-plugin.js.map +1 -1
  136. package/dist/server/csrf.d.ts +3 -2
  137. package/dist/server/csrf.d.ts.map +1 -1
  138. package/dist/server/csrf.js +3 -2
  139. package/dist/server/csrf.js.map +1 -1
  140. package/dist/shared/workspace-app-id.d.ts +1 -1
  141. package/dist/shared/workspace-app-id.d.ts.map +1 -1
  142. package/dist/shared/workspace-app-id.js +5 -1
  143. package/dist/shared/workspace-app-id.js.map +1 -1
  144. package/dist/templates/workspace-root/README.md +5 -4
  145. package/dist/usage/store.d.ts +1 -1
  146. package/dist/usage/store.d.ts.map +1 -1
  147. package/dist/usage/store.js +1 -1
  148. package/dist/usage/store.js.map +1 -1
  149. package/dist/vite/client.d.ts.map +1 -1
  150. package/dist/vite/client.js +10 -1
  151. package/dist/vite/client.js.map +1 -1
  152. package/docs/content/actions.md +10 -10
  153. package/docs/content/extensions.md +230 -0
  154. package/docs/content/key-concepts.md +2 -2
  155. package/docs/content/server.md +13 -13
  156. package/docs/content/sharing.md +2 -2
  157. package/docs/content/template-dispatch.md +5 -0
  158. package/docs/content/what-is-agent-native.md +1 -1
  159. package/package.json +22 -17
  160. package/src/templates/workspace-root/README.md +5 -4
  161. package/dist/client/tools/EmbeddedTool.d.ts +0 -20
  162. package/dist/client/tools/EmbeddedTool.d.ts.map +0 -1
  163. package/dist/client/tools/EmbeddedTool.js.map +0 -1
  164. package/dist/client/tools/ExtensionSlot.d.ts.map +0 -1
  165. package/dist/client/tools/ExtensionSlot.js.map +0 -1
  166. package/dist/client/tools/ToolEditor.d.ts +0 -5
  167. package/dist/client/tools/ToolEditor.d.ts.map +0 -1
  168. package/dist/client/tools/ToolEditor.js +0 -129
  169. package/dist/client/tools/ToolEditor.js.map +0 -1
  170. package/dist/client/tools/ToolViewer.d.ts +0 -5
  171. package/dist/client/tools/ToolViewer.d.ts.map +0 -1
  172. package/dist/client/tools/ToolViewer.js.map +0 -1
  173. package/dist/client/tools/ToolViewerPage.d.ts +0 -2
  174. package/dist/client/tools/ToolViewerPage.d.ts.map +0 -1
  175. package/dist/client/tools/ToolViewerPage.js.map +0 -1
  176. package/dist/client/tools/ToolsListPage.d.ts +0 -2
  177. package/dist/client/tools/ToolsListPage.d.ts.map +0 -1
  178. package/dist/client/tools/ToolsListPage.js +0 -67
  179. package/dist/client/tools/ToolsListPage.js.map +0 -1
  180. package/dist/client/tools/ToolsSidebarSection.d.ts +0 -2
  181. package/dist/client/tools/ToolsSidebarSection.d.ts.map +0 -1
  182. package/dist/client/tools/ToolsSidebarSection.js.map +0 -1
  183. package/dist/client/tools/iframe-bridge.d.ts.map +0 -1
  184. package/dist/client/tools/iframe-bridge.js.map +0 -1
  185. package/dist/client/tools/index.d.ts +0 -8
  186. package/dist/client/tools/index.d.ts.map +0 -1
  187. package/dist/client/tools/index.js +0 -8
  188. package/dist/client/tools/index.js.map +0 -1
  189. package/dist/client/tools/tool-order.d.ts.map +0 -1
  190. package/dist/client/tools/tool-order.js.map +0 -1
  191. package/dist/tools/actions.d.ts +0 -3
  192. package/dist/tools/actions.d.ts.map +0 -1
  193. package/dist/tools/actions.js.map +0 -1
  194. package/dist/tools/fetch-tool.d.ts.map +0 -1
  195. package/dist/tools/fetch-tool.js.map +0 -1
  196. package/dist/tools/html-shell.d.ts +0 -45
  197. package/dist/tools/html-shell.d.ts.map +0 -1
  198. package/dist/tools/html-shell.js.map +0 -1
  199. package/dist/tools/proxy-security.d.ts.map +0 -1
  200. package/dist/tools/proxy-security.js.map +0 -1
  201. package/dist/tools/routes.d.ts +0 -2
  202. package/dist/tools/routes.d.ts.map +0 -1
  203. package/dist/tools/routes.js.map +0 -1
  204. package/dist/tools/schema.d.ts.map +0 -1
  205. package/dist/tools/schema.js.map +0 -1
  206. package/dist/tools/slots/routes.d.ts +0 -15
  207. package/dist/tools/slots/routes.d.ts.map +0 -1
  208. package/dist/tools/slots/routes.js.map +0 -1
  209. package/dist/tools/slots/schema.d.ts.map +0 -1
  210. package/dist/tools/slots/schema.js +0 -76
  211. package/dist/tools/slots/schema.js.map +0 -1
  212. package/dist/tools/slots/store.d.ts +0 -66
  213. package/dist/tools/slots/store.d.ts.map +0 -1
  214. package/dist/tools/slots/store.js +0 -227
  215. package/dist/tools/slots/store.js.map +0 -1
  216. package/dist/tools/store.d.ts +0 -40
  217. package/dist/tools/store.d.ts.map +0 -1
  218. package/dist/tools/store.js.map +0 -1
  219. package/dist/tools/theme.d.ts.map +0 -1
  220. package/dist/tools/theme.js.map +0 -1
  221. package/dist/tools/url-safety.d.ts.map +0 -1
  222. package/dist/tools/url-safety.js.map +0 -1
  223. package/docs/content/tools.md +0 -205
  224. /package/dist/{tools → extensions}/theme.d.ts +0 -0
  225. /package/dist/{tools → extensions}/theme.js +0 -0
@@ -1,227 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { and, eq, inArray, sql } from "drizzle-orm";
3
- import { getDbExec, isPostgres } from "../../db/client.js";
4
- import { createGetDb } from "../../db/create-get-db.js";
5
- import { accessFilter, assertAccess } from "../../sharing/access.js";
6
- import { getRequestUserEmail, getRequestOrgId, } from "../../server/request-context.js";
7
- import { tools, toolShares } from "../schema.js";
8
- import { toolSlots, toolSlotInstalls, TOOL_SLOTS_CREATE_SQL, TOOL_SLOTS_CREATE_SQL_PG, TOOL_SLOTS_BY_SLOT_INDEX_SQL, TOOL_SLOTS_BY_TOOL_INDEX_SQL, TOOL_SLOTS_UNIQUE_INDEX_SQL, TOOL_SLOT_INSTALLS_CREATE_SQL, TOOL_SLOT_INSTALLS_CREATE_SQL_PG, TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL, TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL, } from "./schema.js";
9
- const getDb = createGetDb({ tools, toolShares, toolSlots, toolSlotInstalls });
10
- let _initPromise;
11
- export async function ensureSlotTables() {
12
- if (!_initPromise) {
13
- _initPromise = (async () => {
14
- const client = getDbExec();
15
- const pg = isPostgres();
16
- await client.execute(pg ? TOOL_SLOTS_CREATE_SQL_PG : TOOL_SLOTS_CREATE_SQL);
17
- await client.execute(TOOL_SLOTS_BY_SLOT_INDEX_SQL);
18
- await client.execute(TOOL_SLOTS_BY_TOOL_INDEX_SQL);
19
- await client.execute(TOOL_SLOTS_UNIQUE_INDEX_SQL);
20
- await client.execute(pg ? TOOL_SLOT_INSTALLS_CREATE_SQL_PG : TOOL_SLOT_INSTALLS_CREATE_SQL);
21
- await client.execute(TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL);
22
- await client.execute(TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL);
23
- })();
24
- }
25
- return _initPromise;
26
- }
27
- /**
28
- * Declare that a tool can render in a slot. Caller must have editor access on
29
- * the tool (only people who can edit a tool can change its slot targets).
30
- */
31
- export async function addToolSlotTarget(toolId, slotId, config) {
32
- await ensureSlotTables();
33
- await assertAccess("tool", toolId, "editor");
34
- const db = getDb();
35
- const id = randomUUID();
36
- const createdAt = new Date().toISOString();
37
- const row = {
38
- id,
39
- toolId,
40
- slotId,
41
- config: config ?? null,
42
- createdAt,
43
- };
44
- try {
45
- await db.insert(toolSlots).values(row);
46
- }
47
- catch (err) {
48
- // Unique index hit — already declared. Treat as idempotent: return existing.
49
- if (String(err?.message ?? err)
50
- .toLowerCase()
51
- .includes("unique")) {
52
- const existing = await db
53
- .select()
54
- .from(toolSlots)
55
- .where(and(eq(toolSlots.toolId, toolId), eq(toolSlots.slotId, slotId)));
56
- if (existing[0])
57
- return existing[0];
58
- }
59
- throw err;
60
- }
61
- return row;
62
- }
63
- export async function removeToolSlotTarget(toolId, slotId) {
64
- await ensureSlotTables();
65
- await assertAccess("tool", toolId, "editor");
66
- const db = getDb();
67
- await db
68
- .delete(toolSlots)
69
- .where(and(eq(toolSlots.toolId, toolId), eq(toolSlots.slotId, slotId)));
70
- return true;
71
- }
72
- export async function listSlotsForTool(toolId) {
73
- await ensureSlotTables();
74
- await assertAccess("tool", toolId, "viewer");
75
- const db = getDb();
76
- const rows = await db
77
- .select()
78
- .from(toolSlots)
79
- .where(eq(toolSlots.toolId, toolId));
80
- return rows;
81
- }
82
- /**
83
- * List tools that declare a slot — but only tools the current user has access
84
- * to. Joins through the tools access filter.
85
- */
86
- export async function listToolsForSlot(slotId) {
87
- await ensureSlotTables();
88
- const db = getDb();
89
- // Pull tools the user can see, then narrow to ones declaring this slot.
90
- const accessible = await db
91
- .select({
92
- id: tools.id,
93
- name: tools.name,
94
- description: tools.description,
95
- icon: tools.icon,
96
- })
97
- .from(tools)
98
- .where(accessFilter(tools, toolShares));
99
- if (accessible.length === 0)
100
- return [];
101
- const ids = accessible.map((t) => t.id);
102
- const declarations = await db
103
- .select()
104
- .from(toolSlots)
105
- .where(and(eq(toolSlots.slotId, slotId), inArray(toolSlots.toolId, ids)));
106
- const byId = new Map(accessible.map((t) => [t.id, t]));
107
- return declarations.map((d) => {
108
- const t = byId.get(d.toolId);
109
- return {
110
- toolId: d.toolId,
111
- name: t.name,
112
- description: t.description,
113
- icon: t.icon,
114
- config: d.config,
115
- };
116
- });
117
- }
118
- /**
119
- * Install a tool into a slot for the current user. Verifies the user has at
120
- * least viewer access to the tool. Idempotent — re-installing returns the
121
- * existing row.
122
- */
123
- export async function installToolSlot(toolId, slotId, opts) {
124
- await ensureSlotTables();
125
- await assertAccess("tool", toolId, "viewer");
126
- const userEmail = requireUserEmail();
127
- const orgId = getRequestOrgId();
128
- const db = getDb();
129
- const existing = await db
130
- .select()
131
- .from(toolSlotInstalls)
132
- .where(and(eq(toolSlotInstalls.ownerEmail, userEmail), eq(toolSlotInstalls.toolId, toolId), eq(toolSlotInstalls.slotId, slotId)));
133
- if (existing[0])
134
- return existing[0];
135
- const id = randomUUID();
136
- const now = new Date().toISOString();
137
- let position = opts?.position;
138
- if (position === undefined) {
139
- const rows = await db
140
- .select({ pos: sql `MAX(${toolSlotInstalls.position})` })
141
- .from(toolSlotInstalls)
142
- .where(and(eq(toolSlotInstalls.ownerEmail, userEmail), eq(toolSlotInstalls.slotId, slotId)));
143
- const maxPos = Number(rows[0]?.pos ?? -1);
144
- position = Number.isFinite(maxPos) ? maxPos + 1 : 0;
145
- }
146
- const row = {
147
- id,
148
- toolId,
149
- slotId,
150
- ownerEmail: userEmail,
151
- orgId: orgId ?? null,
152
- position,
153
- config: opts?.config ?? null,
154
- createdAt: now,
155
- updatedAt: now,
156
- };
157
- await db.insert(toolSlotInstalls).values(row);
158
- return row;
159
- }
160
- export async function uninstallToolSlot(toolId, slotId) {
161
- await ensureSlotTables();
162
- const userEmail = requireUserEmail();
163
- const db = getDb();
164
- await db
165
- .delete(toolSlotInstalls)
166
- .where(and(eq(toolSlotInstalls.ownerEmail, userEmail), eq(toolSlotInstalls.toolId, toolId), eq(toolSlotInstalls.slotId, slotId)));
167
- return true;
168
- }
169
- /**
170
- * List the current user's installs for a slot. Joins with `tools` so the
171
- * caller gets tool name/description/icon/updatedAt without a second query.
172
- * Tools the user has lost access to are silently skipped (lazy garbage
173
- * collection).
174
- */
175
- export async function listSlotInstallsForUser(slotId) {
176
- await ensureSlotTables();
177
- const userEmail = requireUserEmail();
178
- const db = getDb();
179
- const installs = await db
180
- .select()
181
- .from(toolSlotInstalls)
182
- .where(and(eq(toolSlotInstalls.ownerEmail, userEmail), eq(toolSlotInstalls.slotId, slotId)));
183
- if (installs.length === 0)
184
- return [];
185
- const accessible = await db
186
- .select({
187
- id: tools.id,
188
- name: tools.name,
189
- description: tools.description,
190
- icon: tools.icon,
191
- updatedAt: tools.updatedAt,
192
- })
193
- .from(tools)
194
- .where(accessFilter(tools, toolShares));
195
- const byId = new Map(accessible.map((t) => [t.id, t]));
196
- return installs
197
- .filter((i) => byId.has(i.toolId))
198
- .sort((a, b) => a.position - b.position)
199
- .map((i) => {
200
- const t = byId.get(i.toolId);
201
- return {
202
- installId: i.id,
203
- toolId: i.toolId,
204
- name: t.name,
205
- description: t.description,
206
- icon: t.icon,
207
- updatedAt: t.updatedAt,
208
- position: i.position,
209
- config: i.config,
210
- };
211
- });
212
- }
213
- /** Delete every slot/install row referencing a tool. Called from deleteTool. */
214
- export async function cascadeDeleteToolSlots(toolId) {
215
- await ensureSlotTables();
216
- const db = getDb();
217
- await db.delete(toolSlots).where(eq(toolSlots.toolId, toolId));
218
- await db.delete(toolSlotInstalls).where(eq(toolSlotInstalls.toolId, toolId));
219
- }
220
- function requireUserEmail() {
221
- const email = getRequestUserEmail();
222
- if (!email) {
223
- throw new Error("Slot operations require an authenticated user.");
224
- }
225
- return email;
226
- }
227
- //# sourceMappingURL=store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/tools/slots/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,4BAA4B,EAC5B,4BAA4B,EAC5B,2BAA2B,EAC3B,6BAA6B,EAC7B,gCAAgC,EAChC,yCAAyC,EACzC,mCAAmC,GACpC,MAAM,aAAa,CAAC;AAErB,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAE9E,IAAI,YAAuC,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,CAAC,KAAK,IAAI,EAAE;YACzB,MAAM,MAAM,GAAG,SAAS,EAAE,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q, inArray, sql } from \"drizzle-orm\";\nimport { getDbExec, isPostgres } from \"../../db/client.js\";\nimport { createGetDb } from \"../../db/create-get-db.js\";\nimport { accessFilter, assertAccess } from \"../../sharing/access.js\";\nimport {\n getRequestUserEmail,\n getRequestOrgId,\n} from \"../../server/request-context.js\";\nimport { tools, toolShares } from \"../schema.js\";\nimport {\n toolSlots,\n toolSlotInstalls,\n TOOL_SLOTS_CREATE_SQL,\n TOOL_SLOTS_CREATE_SQL_PG,\n TOOL_SLOTS_BY_SLOT_INDEX_SQL,\n TOOL_SLOTS_BY_TOOL_INDEX_SQL,\n TOOL_SLOTS_UNIQUE_INDEX_SQL,\n TOOL_SLOT_INSTALLS_CREATE_SQL,\n TOOL_SLOT_INSTALLS_CREATE_SQL_PG,\n TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL,\n TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL,\n} from \"./schema.js\";\n\nconst getDb = createGetDb({ tools, toolShares, toolSlots, toolSlotInstalls });\n\nlet _initPromise: Promise<void> | undefined;\n\nexport async function ensureSlotTables(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n const pg = isPostgres();\n await client.execute(\n pg ? TOOL_SLOTS_CREATE_SQL_PG : TOOL_SLOTS_CREATE_SQL,\n );\n await client.execute(TOOL_SLOTS_BY_SLOT_INDEX_SQL);\n await client.execute(TOOL_SLOTS_BY_TOOL_INDEX_SQL);\n await client.execute(TOOL_SLOTS_UNIQUE_INDEX_SQL);\n await client.execute(\n pg ? TOOL_SLOT_INSTALLS_CREATE_SQL_PG : TOOL_SLOT_INSTALLS_CREATE_SQL,\n );\n await client.execute(TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL);\n await client.execute(TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL);\n })();\n }\n return _initPromise;\n}\n\nexport interface ToolSlotRow {\n id: string;\n toolId: string;\n slotId: string;\n config: string | null;\n createdAt: string;\n}\n\nexport interface ToolSlotInstallRow {\n id: string;\n toolId: string;\n slotId: string;\n ownerEmail: string;\n orgId: string | null;\n position: number;\n config: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Declare that a tool can render in a slot. Caller must have editor access on\n * the tool (only people who can edit a tool can change its slot targets).\n */\nexport async function addToolSlotTarget(\n toolId: string,\n slotId: string,\n config?: string,\n): Promise<ToolSlotRow> {\n await ensureSlotTables();\n await assertAccess(\"tool\", toolId, \"editor\");\n const db = getDb();\n const id = randomUUID();\n const createdAt = new Date().toISOString();\n const row: ToolSlotRow = {\n id,\n toolId,\n slotId,\n config: config ?? null,\n createdAt,\n };\n try {\n await db.insert(toolSlots).values(row);\n } catch (err: any) {\n // Unique index hit — already declared. Treat as idempotent: return existing.\n if (\n String(err?.message ?? err)\n .toLowerCase()\n .includes(\"unique\")\n ) {\n const existing = await db\n .select()\n .from(toolSlots)\n .where(and(eq(toolSlots.toolId, toolId), eq(toolSlots.slotId, slotId)));\n if (existing[0]) return existing[0] as ToolSlotRow;\n }\n throw err;\n }\n return row;\n}\n\nexport async function removeToolSlotTarget(\n toolId: string,\n slotId: string,\n): Promise<boolean> {\n await ensureSlotTables();\n await assertAccess(\"tool\", toolId, \"editor\");\n const db = getDb();\n await db\n .delete(toolSlots)\n .where(and(eq(toolSlots.toolId, toolId), eq(toolSlots.slotId, slotId)));\n return true;\n}\n\nexport async function listSlotsForTool(toolId: string): Promise<ToolSlotRow[]> {\n await ensureSlotTables();\n await assertAccess(\"tool\", toolId, \"viewer\");\n const db = getDb();\n const rows = await db\n .select()\n .from(toolSlots)\n .where(eq(toolSlots.toolId, toolId));\n return rows as ToolSlotRow[];\n}\n\n/**\n * List tools that declare a slot — but only tools the current user has access\n * to. Joins through the tools access filter.\n */\nexport async function listToolsForSlot(slotId: string): Promise<\n Array<{\n toolId: string;\n name: string;\n description: string;\n icon: string | null;\n config: string | null;\n }>\n> {\n await ensureSlotTables();\n const db = getDb();\n // Pull tools the user can see, then narrow to ones declaring this slot.\n const accessible = await db\n .select({\n id: tools.id,\n name: tools.name,\n description: tools.description,\n icon: tools.icon,\n })\n .from(tools)\n .where(accessFilter(tools, toolShares));\n if (accessible.length === 0) return [];\n const ids = accessible.map((t: any) => t.id);\n const declarations = await db\n .select()\n .from(toolSlots)\n .where(and(eq(toolSlots.slotId, slotId), inArray(toolSlots.toolId, ids)));\n const byId = new Map(accessible.map((t: any) => [t.id, t]));\n return (declarations as ToolSlotRow[]).map((d) => {\n const t = byId.get(d.toolId)!;\n return {\n toolId: d.toolId,\n name: t.name,\n description: t.description,\n icon: t.icon,\n config: d.config,\n };\n });\n}\n\n/**\n * Install a tool into a slot for the current user. Verifies the user has at\n * least viewer access to the tool. Idempotent — re-installing returns the\n * existing row.\n */\nexport async function installToolSlot(\n toolId: string,\n slotId: string,\n opts?: { position?: number; config?: string },\n): Promise<ToolSlotInstallRow> {\n await ensureSlotTables();\n await assertAccess(\"tool\", toolId, \"viewer\");\n const userEmail = requireUserEmail();\n const orgId = getRequestOrgId();\n const db = getDb();\n const existing = await db\n .select()\n .from(toolSlotInstalls)\n .where(\n and(\n eq(toolSlotInstalls.ownerEmail, userEmail),\n eq(toolSlotInstalls.toolId, toolId),\n eq(toolSlotInstalls.slotId, slotId),\n ),\n );\n if (existing[0]) return existing[0] as ToolSlotInstallRow;\n\n const id = randomUUID();\n const now = new Date().toISOString();\n let position = opts?.position;\n if (position === undefined) {\n const rows = await db\n .select({ pos: sql<number>`MAX(${toolSlotInstalls.position})` })\n .from(toolSlotInstalls)\n .where(\n and(\n eq(toolSlotInstalls.ownerEmail, userEmail),\n eq(toolSlotInstalls.slotId, slotId),\n ),\n );\n const maxPos = Number((rows[0] as any)?.pos ?? -1);\n position = Number.isFinite(maxPos) ? maxPos + 1 : 0;\n }\n const row: ToolSlotInstallRow = {\n id,\n toolId,\n slotId,\n ownerEmail: userEmail,\n orgId: orgId ?? null,\n position,\n config: opts?.config ?? null,\n createdAt: now,\n updatedAt: now,\n };\n await db.insert(toolSlotInstalls).values(row);\n return row;\n}\n\nexport async function uninstallToolSlot(\n toolId: string,\n slotId: string,\n): Promise<boolean> {\n await ensureSlotTables();\n const userEmail = requireUserEmail();\n const db = getDb();\n await db\n .delete(toolSlotInstalls)\n .where(\n and(\n eq(toolSlotInstalls.ownerEmail, userEmail),\n eq(toolSlotInstalls.toolId, toolId),\n eq(toolSlotInstalls.slotId, slotId),\n ),\n );\n return true;\n}\n\n/**\n * List the current user's installs for a slot. Joins with `tools` so the\n * caller gets tool name/description/icon/updatedAt without a second query.\n * Tools the user has lost access to are silently skipped (lazy garbage\n * collection).\n */\nexport async function listSlotInstallsForUser(slotId: string): Promise<\n Array<{\n installId: string;\n toolId: string;\n name: string;\n description: string;\n icon: string | null;\n updatedAt: string;\n position: number;\n config: string | null;\n }>\n> {\n await ensureSlotTables();\n const userEmail = requireUserEmail();\n const db = getDb();\n\n const installs = await db\n .select()\n .from(toolSlotInstalls)\n .where(\n and(\n eq(toolSlotInstalls.ownerEmail, userEmail),\n eq(toolSlotInstalls.slotId, slotId),\n ),\n );\n if (installs.length === 0) return [];\n\n const accessible = await db\n .select({\n id: tools.id,\n name: tools.name,\n description: tools.description,\n icon: tools.icon,\n updatedAt: tools.updatedAt,\n })\n .from(tools)\n .where(accessFilter(tools, toolShares));\n const byId = new Map(accessible.map((t: any) => [t.id, t]));\n\n return (installs as ToolSlotInstallRow[])\n .filter((i) => byId.has(i.toolId))\n .sort((a, b) => a.position - b.position)\n .map((i) => {\n const t = byId.get(i.toolId)!;\n return {\n installId: i.id,\n toolId: i.toolId,\n name: t.name,\n description: t.description,\n icon: t.icon,\n updatedAt: t.updatedAt,\n position: i.position,\n config: i.config,\n };\n });\n}\n\n/** Delete every slot/install row referencing a tool. Called from deleteTool. */\nexport async function cascadeDeleteToolSlots(toolId: string): Promise<void> {\n await ensureSlotTables();\n const db = getDb();\n await db.delete(toolSlots).where(eq(toolSlots.toolId, toolId));\n await db.delete(toolSlotInstalls).where(eq(toolSlotInstalls.toolId, toolId));\n}\n\nfunction requireUserEmail(): string {\n const email = getRequestUserEmail();\n if (!email) {\n throw new Error(\"Slot operations require an authenticated user.\");\n }\n return email;\n}\n"]}
@@ -1,40 +0,0 @@
1
- export declare function ensureToolsTables(): Promise<void>;
2
- export declare function registerToolsShareable(): void;
3
- export interface ToolRow {
4
- id: string;
5
- name: string;
6
- description: string;
7
- content: string;
8
- icon: string | null;
9
- createdAt: string;
10
- updatedAt: string;
11
- ownerEmail: string;
12
- orgId: string | null;
13
- visibility: "private" | "org" | "public";
14
- }
15
- export declare function listTools(): Promise<ToolRow[]>;
16
- export declare function getTool(id: string): Promise<ToolRow | null>;
17
- export interface CreateToolData {
18
- name: string;
19
- description?: string;
20
- content?: string;
21
- icon?: string;
22
- }
23
- export declare function createTool(data: CreateToolData): Promise<ToolRow>;
24
- export interface UpdateToolData {
25
- name?: string;
26
- description?: string;
27
- icon?: string;
28
- visibility?: "private" | "org" | "public";
29
- }
30
- export declare function updateTool(id: string, data: UpdateToolData): Promise<ToolRow | null>;
31
- export interface UpdateToolContentOpts {
32
- content?: string;
33
- patches?: Array<{
34
- find: string;
35
- replace: string;
36
- }>;
37
- }
38
- export declare function updateToolContent(id: string, opts: UpdateToolContentOpts): Promise<ToolRow | null>;
39
- export declare function deleteTool(id: string): Promise<boolean>;
40
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/tools/store.ts"],"names":[],"mappings":"AAuCA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CA6CvD;AA4DD,wBAAgB,sBAAsB,SASrC;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,M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,GAAG,EAAE,yCAAyC;QAC9C,IAAI,EAAE,CAAC,EAAE,CAAC;KACX,CAAC,CAAC;IACH,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACpE,MAAM,sBAAsB,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { eq } from \"drizzle-orm\";\nimport { getDbExec, isPostgres, retryOnDdlRace } from \"../db/client.js\";\nimport { createGetDb } from \"../db/create-get-db.js\";\nimport {\n accessFilter,\n assertAccess,\n resolveAccess,\n} from \"../sharing/access.js\";\nimport {\n getRequestUserEmail,\n getRequestOrgId,\n} from \"../server/request-context.js\";\nimport { registerShareableResource } from \"../sharing/registry.js\";\nimport {\n tools,\n toolShares,\n TOOLS_CREATE_SQL,\n TOOLS_CREATE_SQL_PG,\n TOOL_SHARES_CREATE_SQL,\n TOOL_SHARES_CREATE_SQL_PG,\n TOOL_DATA_CREATE_SQL,\n TOOL_DATA_CREATE_SQL_PG,\n TOOL_DATA_ITEM_INDEX_SQL,\n TOOL_DATA_ITEM_INDEX_SQL_PG,\n TOOL_DATA_DROP_OLD_INDEX_SQL,\n TOOL_DATA_DROP_OLD_INDEX_SQL_PG,\n TOOLS_OWNER_INDEX_SQL,\n TOOLS_ORG_INDEX_SQL,\n TOOL_SHARES_RESOURCE_INDEX_SQL,\n TOOL_CONSENTS_CREATE_SQL,\n TOOL_CONSENTS_CREATE_SQL_PG,\n TOOL_CONSENTS_VIEWER_INDEX_SQL,\n} from \"./schema.js\";\n\nconst getDb = createGetDb({ tools, toolShares });\n\nlet _initPromise: Promise<void> | undefined;\n\nexport async function ensureToolsTables(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n const pg = isPostgres();\n await retryOnDdlRace(() =>\n client.execute(pg ? TOOLS_CREATE_SQL_PG : TOOLS_CREATE_SQL),\n );\n await retryOnDdlRace(() =>\n client.execute(pg ? TOOL_SHARES_CREATE_SQL_PG : TOOL_SHARES_CREATE_SQL),\n );\n await retryOnDdlRace(() =>\n client.execute(pg ? TOOL_DATA_CREATE_SQL_PG : TOOL_DATA_CREATE_SQL),\n );\n await ensureToolDataItemId(client, pg);\n await ensureToolDataScope(client, pg);\n await client.execute(\n pg ? TOOL_DATA_DROP_OLD_INDEX_SQL_PG : TOOL_DATA_DROP_OLD_INDEX_SQL,\n );\n await retryOnDdlRace(() =>\n client.execute(\n pg ? TOOL_DATA_ITEM_INDEX_SQL_PG : TOOL_DATA_ITEM_INDEX_SQL,\n ),\n );\n await retryOnDdlRace(() => client.execute(TOOLS_OWNER_INDEX_SQL));\n await retryOnDdlRace(() => client.execute(TOOLS_ORG_INDEX_SQL));\n await retryOnDdlRace(() =>\n client.execute(TOOL_SHARES_RESOURCE_INDEX_SQL),\n );\n // tool_consents was introduced for an audit-C1 per-viewer consent\n // gate that we removed once we settled on intra-org trust as the\n // baseline. The table is kept (additive — never drop) so deploys\n // that already created it stay healthy; the runtime consent code\n // is gone. Idempotent CREATE IF NOT EXISTS for fresh schemas.\n await retryOnDdlRace(() =>\n client.execute(\n pg ? TOOL_CONSENTS_CREATE_SQL_PG : TOOL_CONSENTS_CREATE_SQL,\n ),\n );\n await retryOnDdlRace(() =>\n client.execute(TOOL_CONSENTS_VIEWER_INDEX_SQL),\n );\n })();\n }\n return _initPromise;\n}\n\nasync function ensureToolDataItemId(\n client: ReturnType<typeof getDbExec>,\n pg: boolean,\n): Promise<void> {\n if (pg) {\n await client.execute(\n `ALTER TABLE tool_data ADD COLUMN IF NOT EXISTS item_id TEXT`,\n );\n return;\n }\n\n // Keep this additive: legacy rows with item_id=id are still read correctly\n // through COALESCE(item_id, id), so SQLite never needs a table rebuild here.\n try {\n await client.execute(`ALTER TABLE tool_data ADD COLUMN item_id TEXT`);\n } catch (err: any) {\n if (\n !String(err?.message ?? err)\n .toLowerCase()\n .includes(\"duplicate\")\n ) {\n throw err;\n }\n }\n}\n\nasync function ensureToolDataScope(\n client: ReturnType<typeof getDbExec>,\n pg: boolean,\n): Promise<void> {\n const addCol = (name: string, def: string) => {\n if (pg) {\n return client.execute(\n `ALTER TABLE tool_data ADD COLUMN IF NOT EXISTS ${name} ${def}`,\n );\n }\n return client\n .execute(`ALTER TABLE tool_data ADD COLUMN ${name} ${def}`)\n .catch((err: any) => {\n if (\n !String(err?.message ?? err)\n .toLowerCase()\n .includes(\"duplicate\")\n )\n throw err;\n });\n };\n await addCol(\"scope\", \"TEXT NOT NULL DEFAULT 'user'\");\n await addCol(\"org_id\", \"TEXT\");\n await addCol(\"scope_key\", \"TEXT NOT NULL DEFAULT 'local@localhost'\");\n // One-time backfill migration: replaces the dev-mode DEFAULT scope_key\n // with each row's real owner_email. Not a per-request fallback.\n await client.execute(\n // guard:allow-localhost-fallback — one-time backfill migration replacing dev-mode default scope_key with the row's real owner_email\n `UPDATE tool_data SET scope_key = owner_email WHERE scope_key = 'local@localhost' AND owner_email != 'local@localhost'`,\n );\n}\n\nexport function registerToolsShareable() {\n registerShareableResource({\n type: \"tool\",\n resourceTable: tools,\n sharesTable: toolShares,\n displayName: \"Tool\",\n titleColumn: \"name\",\n getDb: () => getDb(),\n });\n}\n\nexport interface ToolRow {\n id: string;\n name: string;\n description: string;\n content: string;\n icon: string | null;\n createdAt: string;\n updatedAt: string;\n ownerEmail: string;\n orgId: string | null;\n visibility: \"private\" | \"org\" | \"public\";\n}\n\nexport async function listTools(): Promise<ToolRow[]> {\n await ensureToolsTables();\n const db = getDb();\n return db\n .select()\n .from(tools)\n .where(accessFilter(tools, toolShares)) as Promise<ToolRow[]>;\n}\n\nexport async function getTool(id: string): Promise<ToolRow | null> {\n await ensureToolsTables();\n const access = await resolveAccess(\"tool\", id);\n return (access?.resource as ToolRow | undefined) ?? null;\n}\n\nexport interface CreateToolData {\n name: string;\n description?: string;\n content?: string;\n icon?: string;\n}\n\nexport async function createTool(data: CreateToolData): Promise<ToolRow> {\n await ensureToolsTables();\n const db = getDb();\n const userEmail = getRequestUserEmail();\n if (!userEmail) throw new Error(\"no authenticated user\");\n const orgId = getRequestOrgId();\n const id = randomUUID();\n const now = new Date().toISOString();\n const row: ToolRow = {\n id,\n name: data.name,\n description: data.description ?? \"\",\n content: data.content ?? \"\",\n icon: data.icon ?? null,\n createdAt: now,\n updatedAt: now,\n ownerEmail: userEmail,\n orgId: orgId ?? null,\n // Default to org-visibility when the user has an active organization so\n // teammates see the tool in their sidebar — matching how analytics\n // dashboards/analyses are scoped (`templates/analytics/server/lib/\n // dashboards-store.ts:356`). Solo users (no org) get the private\n // default. Owners can still flip back to private via update-tool.\n visibility: orgId ? \"org\" : \"private\",\n };\n await db.insert(tools).values(row);\n return row;\n}\n\nexport interface UpdateToolData {\n name?: string;\n description?: string;\n icon?: string;\n visibility?: \"private\" | \"org\" | \"public\";\n}\n\nexport async function updateTool(\n id: string,\n data: UpdateToolData,\n): Promise<ToolRow | null> {\n await ensureToolsTables();\n await assertAccess(\"tool\", id, \"editor\");\n const db = getDb();\n const updates: Record<string, unknown> = {\n updatedAt: new Date().toISOString(),\n };\n if (data.name !== undefined) updates.name = data.name;\n if (data.description !== undefined) updates.description = data.description;\n if (data.icon !== undefined) updates.icon = data.icon;\n if (data.visibility !== undefined) updates.visibility = data.visibility;\n await db.update(tools).set(updates).where(eq(tools.id, id));\n const rows = await db.select().from(tools).where(eq(tools.id, id));\n return (rows[0] as ToolRow) ?? null;\n}\n\nexport interface UpdateToolContentOpts {\n content?: string;\n patches?: Array<{ find: string; replace: string }>;\n}\n\nexport async function updateToolContent(\n id: string,\n opts: UpdateToolContentOpts,\n): Promise<ToolRow | null> {\n await ensureToolsTables();\n await assertAccess(\"tool\", id, \"editor\");\n const db = getDb();\n\n let newContent: string;\n if (opts.content !== undefined) {\n newContent = opts.content;\n } else if (opts.patches) {\n const rows = await db.select().from(tools).where(eq(tools.id, id));\n if (!rows[0]) return null;\n newContent = (rows[0] as ToolRow).content;\n for (const patch of opts.patches) {\n newContent = newContent.replace(patch.find, patch.replace);\n }\n } else {\n return null;\n }\n\n await db\n .update(tools)\n .set({ content: newContent, updatedAt: new Date().toISOString() })\n .where(eq(tools.id, id));\n const rows = await db.select().from(tools).where(eq(tools.id, id));\n return (rows[0] as ToolRow) ?? null;\n}\n\nexport async function deleteTool(id: string): Promise<boolean> {\n await ensureToolsTables();\n await assertAccess(\"tool\", id, \"admin\");\n const db = getDb();\n const rows = await db.select().from(tools).where(eq(tools.id, id));\n if (!rows[0]) return false;\n await db.delete(toolShares).where(eq(toolShares.resourceId, id));\n await getDbExec().execute({\n sql: `DELETE FROM tool_data WHERE tool_id = ?`,\n args: [id],\n });\n const { cascadeDeleteToolSlots } = await import(\"./slots/store.js\");\n await cascadeDeleteToolSlots(id);\n await db.delete(tools).where(eq(tools.id, id));\n return true;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/tools/theme.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAkErD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/tools/theme.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,MAAgB;IAC3C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BT,CAAC;IACD,CAAC;IAED,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BP,CAAC;AACH,CAAC","sourcesContent":["export function getThemeVars(isDark?: boolean): string {\n if (isDark) {\n return `\n:root {\n --background: 240 10% 3.9%;\n --foreground: 0 0% 98%;\n --card: 240 10% 3.9%;\n --card-foreground: 0 0% 98%;\n --popover: 240 10% 3.9%;\n --popover-foreground: 0 0% 98%;\n --primary: 0 0% 98%;\n --primary-foreground: 240 5.9% 10%;\n --secondary: 240 3.7% 15.9%;\n --secondary-foreground: 0 0% 98%;\n --muted: 240 3.7% 15.9%;\n --muted-foreground: 240 5% 64.9%;\n --accent: 240 3.7% 15.9%;\n --accent-foreground: 0 0% 98%;\n --destructive: 0 62.8% 30.6%;\n --destructive-foreground: 0 0% 98%;\n --border: 240 3.7% 15.9%;\n --input: 240 3.7% 15.9%;\n --ring: 240 4.9% 83.9%;\n --radius: 0.5rem;\n --sidebar-background: 240 5.9% 10%;\n --sidebar-foreground: 240 4.8% 95.9%;\n --sidebar-primary: 224.3 76.3% 48%;\n --sidebar-primary-foreground: 0 0% 100%;\n --sidebar-accent: 240 3.7% 15.9%;\n --sidebar-accent-foreground: 240 4.8% 95.9%;\n --sidebar-border: 240 3.7% 15.9%;\n --sidebar-ring: 240 4.9% 83.9%;\n}`;\n }\n\n return `\n:root {\n --background: 0 0% 100%;\n --foreground: 240 10% 3.9%;\n --card: 0 0% 100%;\n --card-foreground: 240 10% 3.9%;\n --popover: 0 0% 100%;\n --popover-foreground: 240 10% 3.9%;\n --primary: 240 5.9% 10%;\n --primary-foreground: 0 0% 98%;\n --secondary: 240 4.8% 95.9%;\n --secondary-foreground: 240 5.9% 10%;\n --muted: 240 4.8% 95.9%;\n --muted-foreground: 240 3.8% 46.1%;\n --accent: 240 4.8% 95.9%;\n --accent-foreground: 240 5.9% 10%;\n --destructive: 0 84.2% 60.2%;\n --destructive-foreground: 0 0% 98%;\n --border: 240 5.9% 90%;\n --input: 240 5.9% 90%;\n --ring: 240 5.9% 10%;\n --radius: 0.5rem;\n --sidebar-background: 0 0% 98%;\n --sidebar-foreground: 240 5.3% 26.1%;\n --sidebar-primary: 240 5.9% 10%;\n --sidebar-primary-foreground: 0 0% 98%;\n --sidebar-accent: 240 4.8% 95.9%;\n --sidebar-accent-foreground: 240 5.9% 10%;\n --sidebar-border: 220 13% 91%;\n --sidebar-ring: 240 5.9% 10%;\n}`;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"url-safety.d.ts","sourceRoot":"","sources":["../../src/tools/url-safety.ts"],"names":[],"mappings":"AA4FA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAoBrD;AASD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CA+DxE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"url-safety.js","sourceRoot":"","sources":["../../src/tools/url-safety.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG;IACrB,0BAA0B;IAC1B,2BAA2B;CAC5B,CAAC;AAEF,MAAM,mBAAmB,GAAG;IAC1B,SAAS;IACT,WAAW;IACX,SAAS;IACT,eAAe;IACf,SAAS;CACV,CAAC;AAEF,SAAS,aAAa,CAAC,CAAS,EAAE,CAAS,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;IACvD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzE,IAAI,CAAC,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;IACjD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,G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AC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBACrD,CAAC,CACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["const METADATA_HOSTS = [\n \"metadata.google.internal\",\n \"metadata.google.internal.\",\n];\n\nconst DNS_REBIND_SUFFIXES = [\n \".nip.io\",\n \".sslip.io\",\n \".xip.io\",\n \".localtest.me\",\n \".lvh.me\",\n];\n\nfunction isPrivateIpv4(a: number, b: number, c = 0, d = 0): boolean {\n if (![a, b, c, d].every((part) => part >= 0 && part <= 255)) return true;\n if (a === 127) return true;\n if (a === 10) return true;\n if (a === 172 && b >= 16 && b <= 31) return true;\n if (a === 192 && b === 168) return true;\n if (a === 169 && b === 254) return true;\n if (a === 0) return true;\n if (a === 100 && b >= 64 && b <= 127) return true;\n if (a === 192 && b === 0) return true;\n if (a === 198 && (b === 18 || b === 19)) return true;\n if (a === 192 && b === 0 && c === 2) return true;\n if (a === 198 && b === 51 && c === 100) return true;\n if (a === 203 && b === 0 && c === 113) return true;\n if (a >= 224) return true;\n return false;\n}\n\nfunction isPrivateIpv4MappedHex(host: string): boolean {\n const mapped = host.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);\n if (!mapped) return false;\n const high = Number.parseInt(mapped[1], 16);\n const low = Number.parseInt(mapped[2], 16);\n if (high < 0 || high > 0xffff || low < 0 || low > 0xffff) return false;\n const a = (high >> 8) & 0xff;\n const b = high & 0xff;\n const c = (low >> 8) & 0xff;\n const d = low & 0xff;\n return isPrivateIpv4(a, b, c, d);\n}\n\nfunction isPrivateHost(hostname: string): boolean {\n const host = hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n if (\n host === \"localhost\" ||\n host === \"::1\" ||\n host === \"::0\" ||\n host === \"::\"\n ) {\n return true;\n }\n if (METADATA_HOSTS.includes(host)) return true;\n\n // IPv6 ULA/link-local/multicast.\n if (/^f[cd]/.test(host) || /^fe[89ab]/.test(host)) return true;\n if (/^ff/i.test(host)) return true;\n\n // IPv4-mapped IPv6. URL parsing may preserve dotted form in some runtimes\n // or normalize it to hex, e.g. [::ffff:127.0.0.1] -> ::ffff:7f00:1.\n const v4mappedDotted = host.match(/^::ffff:(\\d+\\.\\d+\\.\\d+\\.\\d+)$/);\n if (v4mappedDotted) {\n const [a, b, c, d] = v4mappedDotted[1].split(\".\").map(Number);\n if (isPrivateIpv4(a, b, c, d)) return true;\n }\n if (isPrivateIpv4MappedHex(host)) return true;\n\n // Dotted IPv4. URL parsing normalizes shorthand/octal/hex IPv4 forms to\n // dotted decimal before we reach this point.\n const parts = host.split(\".\");\n if (parts.length === 4 && parts.every((p) => /^\\d+$/.test(p))) {\n const [a, b, c, d] = parts.map(Number);\n if (isPrivateIpv4(a, b, c, d)) return true;\n }\n\n // Decimal integer IPv4.\n if (/^\\d+$/.test(host)) {\n const num = Number(host);\n if (num >= 0 && num <= 0xffffffff) {\n const a = (num >>> 24) & 0xff;\n const b = (num >>> 16) & 0xff;\n const c = (num >>> 8) & 0xff;\n const d = num & 0xff;\n if (isPrivateIpv4(a, b, c, d)) return true;\n }\n }\n\n return false;\n}\n\nexport function isBlockedToolUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n return true;\n }\n const host = parsed.hostname.toLowerCase();\n if (isPrivateHost(host)) return true;\n if (\n DNS_REBIND_SUFFIXES.some((suffix) => {\n const bare = suffix.slice(1);\n return host === bare || host.endsWith(suffix);\n })\n ) {\n return true;\n }\n } catch {\n return true;\n }\n return false;\n}\n\nfunction isIpLiteralHost(hostname: string): boolean {\n const host = hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n if (host.includes(\":\")) return true;\n const parts = host.split(\".\");\n return parts.length === 4 && parts.every((p) => /^\\d+$/.test(p));\n}\n\n/**\n * Async SSRF guard for environments that can resolve DNS. The synchronous\n * guard catches literals and known rebinding domains; this closes the common\n * \"public hostname resolves to a private address\" gap before dispatch.\n */\nexport async function isBlockedToolUrlWithDns(url: string): Promise<boolean> {\n if (isBlockedToolUrl(url)) return true;\n\n let hostname: string;\n try {\n hostname = new URL(url).hostname.toLowerCase();\n } catch {\n return true;\n }\n if (!hostname || isIpLiteralHost(hostname)) return false;\n\n try {\n const { lookup } = await import(\"node:dns/promises\");\n const records = await lookup(hostname, { all: true, verbatim: true });\n return records.some((record) => isPrivateHost(record.address));\n } catch {\n // Some edge runtimes do not expose DNS lookup. Keep the deterministic\n // parser-based protections instead of failing every outbound request.\n return false;\n }\n}\n\n/**\n * Build an undici Dispatcher whose connect-time DNS lookup runs through a\n * private-IP guard. This closes the TOCTOU gap where:\n * 1. We resolve hostname → public IP and pass.\n * 2. Between that lookup and the actual connect, DNS rebinding flips the\n * record to a private IP.\n * 3. fetch() resolves again and connects to the private IP.\n *\n * With a custom dispatcher, the same lookup that produces the IP also gates\n * the connect: if the IP is in the private set, the connect throws.\n *\n * Returns `null` if undici / node:dns are not available (e.g. some edge\n * runtimes); the caller should fall back to the regular `fetch` path —\n * `isBlockedToolUrlWithDns` will still have caught most rebinding cases.\n */\nexport async function createSsrfSafeDispatcher(): Promise<unknown | null> {\n // Dynamic import + `any`: undici is not a direct dependency, so the type\n // declarations may not resolve. The runtime path is still safe — if the\n // import throws we return null and the caller falls back to plain fetch.\n let undici: any;\n let dnsModule: any;\n try {\n undici = await import(\"undici\" as string);\n dnsModule = await import(\"node:dns\");\n } catch {\n return null;\n }\n\n const { Agent } = undici;\n const { lookup } = dnsModule;\n if (!Agent || !lookup) return null;\n\n return new Agent({\n connect: {\n // Override DNS lookup at connect time so the IP we hand to undici's\n // socket is the one we authorized. Reject any record in the private\n // set BEFORE the TCP handshake.\n lookup: (\n hostname: string,\n options: any,\n callback: (\n err: NodeJS.ErrnoException | null,\n address?: string | { address: string; family: number }[],\n family?: number,\n ) => void,\n ) => {\n lookup(\n hostname,\n { all: true, verbatim: true },\n (err: NodeJS.ErrnoException | null, addresses: any) => {\n if (err) return callback(err);\n const list: { address: string; family: number }[] = Array.isArray(\n addresses,\n )\n ? addresses\n : [{ address: addresses, family: 4 }];\n for (const record of list) {\n if (isPrivateHost(record.address)) {\n const e = new Error(\n `Connect blocked: ${hostname} resolved to private address ${record.address}`,\n ) as NodeJS.ErrnoException;\n e.code = \"EAI_BLOCKED\";\n return callback(e);\n }\n }\n // Mirror Node's lookup behavior: when `all` is true, return the\n // array; otherwise the first entry. undici's connect honors\n // `options.all`.\n if (options && options.all) {\n return callback(null, list as any);\n }\n const first = list[0];\n return callback(null, first.address, first.family);\n },\n );\n },\n },\n });\n}\n"]}
@@ -1,205 +0,0 @@
1
- ---
2
- title: "Tools"
3
- description: "Lightweight interactive apps — dashboards, widgets, calculators, monitors — that the agent creates for you instantly, without changing your app's code."
4
- ---
5
-
6
- # Tools
7
-
8
- Tools are lightweight interactive apps that live inside your agent-native app. Think dashboards, widgets, calculators, API monitors, data lookups — anything you'd otherwise build by hand.
9
-
10
- The key difference from the rest of your app: **tools don't require code changes.** The agent creates and updates them at runtime, they're stored in the database, and they're ready to use immediately. No deploys, no builds, no pull requests.
11
-
12
- ## Tools vs. editing the app {#tools-vs-code}
13
-
14
- Your agent-native app has a full codebase — React components, routes, actions, styles. When the agent edits that code, it's changing the app itself. That's powerful, but it requires a build step and a deploy.
15
-
16
- Tools are different:
17
-
18
- | | App code | Tools |
19
- | --------------------- | --------------------------------------- | -------------------------------------------------- |
20
- | **Created by** | Developer or agent editing source files | Agent or user, instantly from chat |
21
- | **Stored in** | Git repository | Database |
22
- | **Requires a build** | Yes | No |
23
- | **Requires a deploy** | Yes | No |
24
- | **Scope** | Part of the app for all users | Private by default, shareable |
25
- | **Best for** | Core app features | Personal dashboards, utilities, quick integrations |
26
-
27
- Use app code for features that are core to the product. Use tools for everything else — one-off utilities, personal dashboards, quick integrations, monitors, and things you want to spin up in seconds.
28
-
29
- ## When to build a tool vs. a template feature {#when-to-build}
30
-
31
- A quick decision rubric:
32
-
33
- **Build a tool when:**
34
-
35
- - It's for one user or one team, not the whole product.
36
- - It's a quick utility, dashboard, or widget you want now, not next sprint.
37
- - No new database schema is needed (or per-tool key-value storage is enough).
38
- - You want to ship it inside a single chat turn, no deploy.
39
-
40
- **Add a template feature when:**
41
-
42
- - Every user of the template should get it.
43
- - It needs new SQL tables, migrations, or shared schema changes.
44
- - The UI is complex enough to warrant React components, routes, and proper testing.
45
- - It's part of the product surface — something you'd advertise on a landing page.
46
-
47
- When in doubt, start as a tool. Promoting a tool to a template feature later is straightforward; rolling back a half-shipped product feature is not.
48
-
49
- ## Creating a tool {#creating}
50
-
51
- ### From the sidebar
52
-
53
- Click the **+** button in the Tools section of the sidebar. Describe what you want in plain language — "a dashboard that shows my open GitHub PRs" — and the agent builds it for you.
54
-
55
- ### From chat
56
-
57
- Just ask: "Create a tool that monitors our API health" or "Make me a calculator for shipping costs." The agent handles the rest.
58
-
59
- ### Updating a tool
60
-
61
- Ask the agent: "Update my PR dashboard to also show draft PRs" or "Add a dark mode toggle to the weather widget." The agent makes surgical edits without regenerating the whole thing.
62
-
63
- ## What tools can do {#capabilities}
64
-
65
- Tools are fully capable despite being lightweight. They can:
66
-
67
- - **Call external APIs** — GitHub, Stripe, weather services, any REST API. Requests go through a secure server-side proxy that keeps your API keys safe.
68
- - **Call your app's actions** — anything your agent can do, a tool can trigger.
69
- - **Query your app's database** — read and write data directly.
70
- - **Store their own data** — each tool has built-in persistent storage, no setup required. Save notes, preferences, cached results — whatever the tool needs.
71
- - **Call any endpoint in your app** — hit custom API routes, webhooks, or internal services.
72
-
73
- All of this works out of the box. No configuration, no new files, no schema changes.
74
-
75
- ## Layout defaults {#layout}
76
-
77
- Tools render with modest canvas padding by default so simple widgets and dashboards do not hug the iframe edge. For full-bleed experiences such as maps, canvases, or custom editors, set `data-tool-layout="full-bleed"` or `data-tool-padding="none"` on the outermost element.
78
-
79
- ## Persistent storage {#persistent-storage}
80
-
81
- Every tool has access to a built-in key-value store via the `toolData` helper. Data is automatically scoped per tool and per user — your data stays yours.
82
-
83
- When you ask the agent to "add persistence" or "remember state" in a tool, it uses this built-in storage. No database tables to create, no migrations to run.
84
-
85
- ### Scopes
86
-
87
- All `toolData` methods accept an optional `{ scope }` option:
88
-
89
- - `'user'` (default) — private to the current user.
90
- - `'org'` — shared across the user's organization.
91
- - `'all'` — list/get only; returns both user-scoped and org-scoped items.
92
-
93
- ```html
94
- <script>
95
- // Private to me
96
- await toolData.set('notes', 'note-1', { title: 'My Note' });
97
-
98
- // Shared with my org
99
- await toolData.set('notes', 'team-note', { title: 'Team Note' }, { scope: 'org' });
100
-
101
- // List my notes (default)
102
- const mine = await toolData.list('notes');
103
-
104
- // List both mine and the org's
105
- const everything = await toolData.list('notes', { scope: 'all' });
106
- </script>
107
- ```
108
-
109
- ## API keys and secrets {#secrets}
110
-
111
- When a tool needs an API key (for GitHub, OpenAI, a weather service, etc.), the agent will tell you what's needed and where to get it. You add the key through the Settings UI in the agent sidebar.
112
-
113
- Keys are encrypted and stored securely. Each key is restricted to specific domains — a GitHub token can only be sent to `api.github.com`, never anywhere else.
114
-
115
- ### Secrets in tools {#secrets-in-tools}
116
-
117
- Tools reference secrets in `toolFetch()` calls using the `${keys.NAME}` template pattern. The proxy substitutes the encrypted value server-side; the actual key never reaches the browser.
118
-
119
- ```html
120
- <script>
121
- const res = await toolFetch('https://api.github.com/user', {
122
- headers: {
123
- Authorization: 'Bearer ${keys.GITHUB_TOKEN}',
124
- },
125
- });
126
- </script>
127
- ```
128
-
129
- When a tool needs a one-off key, the agent can register an ad-hoc secret via `POST /_agent-native/secrets/adhoc` with a `urlAllowlist` that pins which domains the secret may be sent to. A request to any other host is rejected before the proxy fires. Combined with SSRF and private-network protections, this means a leaked tool can't exfiltrate secrets to an attacker-controlled URL.
130
-
131
- ## Sharing {#sharing}
132
-
133
- Tools are **private by default** — only you can see and use a tool you create.
134
-
135
- You can share tools with your team:
136
-
137
- - **Org-visible** — everyone in your organization can use it.
138
- - **Per-user sharing** — grant access to specific people as viewers, editors, or admins.
139
-
140
- Shared tools have their own URLs, so you can link to them directly.
141
-
142
- Under the hood, tools use the same ownable-resource model as the rest of the framework — `ownableColumns()` on the `tools` table and a standard `createSharesTable()` for grants. That means tools plug into the same share dialog, access checks, and audit surfaces as documents, decks, dashboards, and any other shareable resource. See [Security](/docs/security) for the full access model.
143
-
144
- ## Security {#security}
145
-
146
- Tools run in a secure sandbox:
147
-
148
- - **Isolated** — tools can't access your app's cookies, session, or page content.
149
- - **API keys stay server-side** — secrets are injected by the server, never exposed to the browser.
150
- - **Domain-restricted secrets** — each API key can only be sent to its approved domains.
151
- - **Private network protection** — tools can't reach internal/private network addresses.
152
- - **Authentication required** — only logged-in users can use tools.
153
-
154
- ## Tool API reference {#api-reference}
155
-
156
- Every tool runs inside a sandboxed iframe with the following helpers injected on `window`. They are the complete surface area — anything else a tool needs has to go through one of these.
157
-
158
- | Helper | Purpose | Example |
159
- | ------------------------------------------- | ---------------------- | --------------------------------------------- |
160
- | `toolData.set(collection, id, data, opts?)` | Persist data per-tool | `toolData.set('notes', id, { text: '...' })` |
161
- | `toolData.list(collection, opts?)` | List persisted items | `toolData.list('notes', { scope: 'all' })` |
162
- | `toolData.get(collection, id, opts?)` | Get a single item | `toolData.get('notes', 'note-1')` |
163
- | `toolData.remove(collection, id, opts?)` | Delete persisted item | `toolData.remove('notes', 'note-1')` |
164
- | `appAction(name, params)` | Call any app action | `appAction('list-emails', { view: 'inbox' })` |
165
- | `dbQuery(sql, args)` | Read from SQL | `dbQuery('SELECT * FROM tools')` |
166
- | `dbExec(sql, args)` | Write to SQL | `dbExec('INSERT INTO ...')` |
167
- | `appFetch(path, options)` | Call any app endpoint | `appFetch('/api/settings')` |
168
- | `toolFetch(url, options)` | External API via proxy | `toolFetch('https://api.github.com/...')` |
169
-
170
- `appAction` is the preferred way to trigger app behavior — it routes through the same actions the agent and the frontend use, so authorization and access scoping happen automatically. Drop down to `dbQuery`/`dbExec` only when there's no action that fits.
171
-
172
- ### Routes {#routes}
173
-
174
- The framework mounts the following endpoints under `/_agent-native/tools/`. Tools themselves rarely call these directly — they're useful when integrating tools with external scripts or custom UI.
175
-
176
- | Method | Path | Purpose |
177
- | ------ | --------------------------------- | -------------------------------------------- |
178
- | GET | `/_agent-native/tools` | List tools (filtered by ownership + sharing) |
179
- | POST | `/_agent-native/tools` | Create a tool |
180
- | GET | `/_agent-native/tools/:id` | Get a single tool |
181
- | PUT | `/_agent-native/tools/:id` | Update (supports `patches` for diffing) |
182
- | DELETE | `/_agent-native/tools/:id` | Delete a tool |
183
- | GET | `/_agent-native/tools/:id/render` | Render the iframe HTML |
184
- | POST | `/_agent-native/tools/proxy` | Authenticated proxy with secret injection |
185
-
186
- ## Examples {#examples}
187
-
188
- Here are some things people build as tools:
189
-
190
- - **GitHub PR dashboard** — see open PRs, review status, and CI checks at a glance
191
- - **API health monitor** — check if your services are up with a single click
192
- - **Weather widget** — quick weather lookup for any city
193
- - **Stripe payment lookup** — search recent payments and refunds
194
- - **Database explorer** — browse and query your app's data
195
- - **Shipping cost calculator** — compute rates based on weight and destination
196
- - **Meeting notes summarizer** — paste notes, get action items
197
- - **Social media scheduler** — draft and schedule posts across platforms
198
-
199
- To create any of these, just describe what you want in the agent chat.
200
-
201
- ## What's next
202
-
203
- - [**Actions**](/docs/actions) — the operations that tools (and the agent) can call
204
- - [**Workspace**](/docs/workspace) — the broader workspace system tools live alongside
205
- - [**Security**](/docs/security) — the framework's data scoping and access control
File without changes
File without changes