@agent-native/core 0.7.82 → 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.
- package/dist/action.js +1 -1
- package/dist/action.js.map +1 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +8 -8
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +2 -0
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +44 -18
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/types.d.ts +1 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/cli/create.d.ts +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +87 -19
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/workspacify.d.ts.map +1 -1
- package/dist/cli/workspacify.js +12 -9
- package/dist/cli/workspacify.js.map +1 -1
- package/dist/client/AgentPanel.d.ts +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +22 -1
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/FeedbackButton.d.ts +3 -2
- package/dist/client/FeedbackButton.d.ts.map +1 -1
- package/dist/client/FeedbackButton.js +18 -14
- package/dist/client/FeedbackButton.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +254 -29
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-chat.d.ts +2 -0
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +11 -2
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/builder-frame.d.ts +11 -0
- package/dist/client/builder-frame.d.ts.map +1 -1
- package/dist/client/builder-frame.js +40 -9
- package/dist/client/builder-frame.js.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.js +1 -1
- package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
- package/dist/client/composer/PromptComposer.d.ts +2 -0
- package/dist/client/composer/PromptComposer.d.ts.map +1 -1
- package/dist/client/composer/PromptComposer.js +3 -3
- package/dist/client/composer/PromptComposer.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts +3 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +25 -13
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/composer/types.d.ts +1 -1
- package/dist/client/composer/types.d.ts.map +1 -1
- package/dist/client/composer/types.js.map +1 -1
- package/dist/client/extensions/EmbeddedExtension.d.ts +20 -0
- package/dist/client/extensions/EmbeddedExtension.d.ts.map +1 -0
- package/dist/client/{tools/EmbeddedTool.js → extensions/EmbeddedExtension.js} +41 -41
- package/dist/client/extensions/EmbeddedExtension.js.map +1 -0
- package/dist/client/extensions/ExtensionEditor.d.ts +5 -0
- package/dist/client/extensions/ExtensionEditor.d.ts.map +1 -0
- package/dist/client/extensions/ExtensionEditor.js +129 -0
- package/dist/client/extensions/ExtensionEditor.js.map +1 -0
- package/dist/client/{tools → extensions}/ExtensionSlot.d.ts +3 -3
- package/dist/client/extensions/ExtensionSlot.d.ts.map +1 -0
- package/dist/client/{tools → extensions}/ExtensionSlot.js +14 -14
- package/dist/client/extensions/ExtensionSlot.js.map +1 -0
- package/dist/client/extensions/ExtensionViewer.d.ts +5 -0
- package/dist/client/extensions/ExtensionViewer.d.ts.map +1 -0
- package/dist/client/{tools/ToolViewer.js → extensions/ExtensionViewer.js} +67 -65
- package/dist/client/extensions/ExtensionViewer.js.map +1 -0
- package/dist/client/extensions/ExtensionViewerPage.d.ts +2 -0
- package/dist/client/extensions/ExtensionViewerPage.d.ts.map +1 -0
- package/dist/client/{tools/ToolViewerPage.js → extensions/ExtensionViewerPage.js} +8 -8
- package/dist/client/extensions/ExtensionViewerPage.js.map +1 -0
- package/dist/client/extensions/ExtensionsListPage.d.ts +2 -0
- package/dist/client/extensions/ExtensionsListPage.d.ts.map +1 -0
- package/dist/client/extensions/ExtensionsListPage.js +67 -0
- package/dist/client/extensions/ExtensionsListPage.js.map +1 -0
- package/dist/client/extensions/ExtensionsSidebarSection.d.ts +2 -0
- package/dist/client/extensions/ExtensionsSidebarSection.d.ts.map +1 -0
- package/dist/client/{tools/ToolsSidebarSection.js → extensions/ExtensionsSidebarSection.js} +58 -58
- package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -0
- package/dist/client/{tools/tool-order.d.ts → extensions/extension-order.d.ts} +2 -2
- package/dist/client/extensions/extension-order.d.ts.map +1 -0
- package/dist/client/{tools/tool-order.js → extensions/extension-order.js} +3 -3
- package/dist/client/extensions/extension-order.js.map +1 -0
- package/dist/client/{tools → extensions}/iframe-bridge.d.ts +11 -11
- package/dist/client/extensions/iframe-bridge.d.ts.map +1 -0
- package/dist/client/{tools → extensions}/iframe-bridge.js +24 -24
- package/dist/client/extensions/iframe-bridge.js.map +1 -0
- package/dist/client/extensions/index.d.ts +14 -0
- package/dist/client/extensions/index.d.ts.map +1 -0
- package/dist/client/extensions/index.js +19 -0
- package/dist/client/extensions/index.js.map +1 -0
- package/dist/client/integrations/IntegrationsPanel.d.ts.map +1 -1
- package/dist/client/integrations/IntegrationsPanel.js +4 -1
- package/dist/client/integrations/IntegrationsPanel.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts +2 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +87 -6
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/extensions/actions.d.ts +3 -0
- package/dist/extensions/actions.d.ts.map +1 -0
- package/dist/{tools → extensions}/actions.js +54 -51
- package/dist/extensions/actions.js.map +1 -0
- package/dist/{tools → extensions}/fetch-tool.d.ts +4 -0
- package/dist/extensions/fetch-tool.d.ts.map +1 -0
- package/dist/{tools → extensions}/fetch-tool.js +12 -7
- package/dist/extensions/fetch-tool.js.map +1 -0
- package/dist/extensions/html-shell.d.ts +56 -0
- package/dist/extensions/html-shell.d.ts.map +1 -0
- package/dist/{tools → extensions}/html-shell.js +101 -83
- package/dist/extensions/html-shell.js.map +1 -0
- package/dist/{tools → extensions}/proxy-security.d.ts +2 -2
- package/dist/extensions/proxy-security.d.ts.map +1 -0
- package/dist/{tools → extensions}/proxy-security.js +3 -3
- package/dist/extensions/proxy-security.js.map +1 -0
- package/dist/extensions/routes.d.ts +2 -0
- package/dist/extensions/routes.d.ts.map +1 -0
- package/dist/{tools → extensions}/routes.js +73 -69
- package/dist/extensions/routes.js.map +1 -0
- package/dist/{tools → extensions}/schema.d.ts +44 -38
- package/dist/extensions/schema.d.ts.map +1 -0
- package/dist/{tools → extensions}/schema.js +41 -34
- package/dist/extensions/schema.js.map +1 -0
- package/dist/extensions/slots/routes.d.ts +15 -0
- package/dist/extensions/slots/routes.d.ts.map +1 -0
- package/dist/{tools → extensions}/slots/routes.js +26 -26
- package/dist/extensions/slots/routes.js.map +1 -0
- package/dist/{tools → extensions}/slots/schema.d.ts +24 -21
- package/dist/extensions/slots/schema.d.ts.map +1 -0
- package/dist/extensions/slots/schema.js +79 -0
- package/dist/extensions/slots/schema.js.map +1 -0
- package/dist/extensions/slots/store.d.ts +66 -0
- package/dist/extensions/slots/store.d.ts.map +1 -0
- package/dist/extensions/slots/store.js +238 -0
- package/dist/extensions/slots/store.js.map +1 -0
- package/dist/extensions/store.d.ts +40 -0
- package/dist/extensions/store.d.ts.map +1 -0
- package/dist/{tools → extensions}/store.js +59 -54
- package/dist/extensions/store.js.map +1 -0
- package/dist/extensions/theme.d.ts.map +1 -0
- package/dist/extensions/theme.js.map +1 -0
- package/dist/{tools → extensions}/url-safety.d.ts +5 -3
- package/dist/extensions/url-safety.d.ts.map +1 -0
- package/dist/{tools → extensions}/url-safety.js +11 -4
- package/dist/extensions/url-safety.js.map +1 -0
- package/dist/server/action-discovery.d.ts +15 -0
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +45 -0
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +12 -10
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/auth.d.ts +5 -4
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +80 -28
- package/dist/server/auth.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts +15 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +65 -13
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/csrf.d.ts +3 -2
- package/dist/server/csrf.d.ts.map +1 -1
- package/dist/server/csrf.js +3 -2
- package/dist/server/csrf.js.map +1 -1
- package/dist/server/google-oauth.d.ts.map +1 -1
- package/dist/server/google-oauth.js +15 -3
- package/dist/server/google-oauth.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/shared/workspace-app-id.d.ts +1 -1
- package/dist/shared/workspace-app-id.d.ts.map +1 -1
- package/dist/shared/workspace-app-id.js +5 -1
- package/dist/shared/workspace-app-id.js.map +1 -1
- package/dist/templates/workspace-root/README.md +5 -4
- package/dist/usage/store.d.ts +1 -1
- package/dist/usage/store.d.ts.map +1 -1
- package/dist/usage/store.js +1 -1
- package/dist/usage/store.js.map +1 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +17 -1
- package/dist/vite/client.js.map +1 -1
- package/docs/content/actions.md +10 -10
- package/docs/content/extensions.md +230 -0
- package/docs/content/key-concepts.md +2 -2
- package/docs/content/server.md +13 -13
- package/docs/content/sharing.md +2 -2
- package/docs/content/template-analytics.md +10 -0
- package/docs/content/template-calendar.md +10 -0
- package/docs/content/template-clips.md +10 -0
- package/docs/content/template-content.md +10 -0
- package/docs/content/template-dispatch.md +15 -0
- package/docs/content/template-forms.md +10 -0
- package/docs/content/template-mail.md +10 -0
- package/docs/content/template-slides.md +11 -1
- package/docs/content/template-starter.md +10 -0
- package/docs/content/template-video.md +10 -0
- package/docs/content/what-is-agent-native.md +1 -1
- package/package.json +22 -17
- package/src/templates/workspace-root/README.md +5 -4
- package/dist/client/tools/EmbeddedTool.d.ts +0 -20
- package/dist/client/tools/EmbeddedTool.d.ts.map +0 -1
- package/dist/client/tools/EmbeddedTool.js.map +0 -1
- package/dist/client/tools/ExtensionSlot.d.ts.map +0 -1
- package/dist/client/tools/ExtensionSlot.js.map +0 -1
- package/dist/client/tools/ToolEditor.d.ts +0 -5
- package/dist/client/tools/ToolEditor.d.ts.map +0 -1
- package/dist/client/tools/ToolEditor.js +0 -129
- package/dist/client/tools/ToolEditor.js.map +0 -1
- package/dist/client/tools/ToolViewer.d.ts +0 -5
- package/dist/client/tools/ToolViewer.d.ts.map +0 -1
- package/dist/client/tools/ToolViewer.js.map +0 -1
- package/dist/client/tools/ToolViewerPage.d.ts +0 -2
- package/dist/client/tools/ToolViewerPage.d.ts.map +0 -1
- package/dist/client/tools/ToolViewerPage.js.map +0 -1
- package/dist/client/tools/ToolsListPage.d.ts +0 -2
- package/dist/client/tools/ToolsListPage.d.ts.map +0 -1
- package/dist/client/tools/ToolsListPage.js +0 -67
- package/dist/client/tools/ToolsListPage.js.map +0 -1
- package/dist/client/tools/ToolsSidebarSection.d.ts +0 -2
- package/dist/client/tools/ToolsSidebarSection.d.ts.map +0 -1
- package/dist/client/tools/ToolsSidebarSection.js.map +0 -1
- package/dist/client/tools/iframe-bridge.d.ts.map +0 -1
- package/dist/client/tools/iframe-bridge.js.map +0 -1
- package/dist/client/tools/index.d.ts +0 -8
- package/dist/client/tools/index.d.ts.map +0 -1
- package/dist/client/tools/index.js +0 -8
- package/dist/client/tools/index.js.map +0 -1
- package/dist/client/tools/tool-order.d.ts.map +0 -1
- package/dist/client/tools/tool-order.js.map +0 -1
- package/dist/tools/actions.d.ts +0 -3
- package/dist/tools/actions.d.ts.map +0 -1
- package/dist/tools/actions.js.map +0 -1
- package/dist/tools/fetch-tool.d.ts.map +0 -1
- package/dist/tools/fetch-tool.js.map +0 -1
- package/dist/tools/html-shell.d.ts +0 -45
- package/dist/tools/html-shell.d.ts.map +0 -1
- package/dist/tools/html-shell.js.map +0 -1
- package/dist/tools/proxy-security.d.ts.map +0 -1
- package/dist/tools/proxy-security.js.map +0 -1
- package/dist/tools/routes.d.ts +0 -2
- package/dist/tools/routes.d.ts.map +0 -1
- package/dist/tools/routes.js.map +0 -1
- package/dist/tools/schema.d.ts.map +0 -1
- package/dist/tools/schema.js.map +0 -1
- package/dist/tools/slots/routes.d.ts +0 -15
- package/dist/tools/slots/routes.d.ts.map +0 -1
- package/dist/tools/slots/routes.js.map +0 -1
- package/dist/tools/slots/schema.d.ts.map +0 -1
- package/dist/tools/slots/schema.js +0 -76
- package/dist/tools/slots/schema.js.map +0 -1
- package/dist/tools/slots/store.d.ts +0 -66
- package/dist/tools/slots/store.d.ts.map +0 -1
- package/dist/tools/slots/store.js +0 -227
- package/dist/tools/slots/store.js.map +0 -1
- package/dist/tools/store.d.ts +0 -40
- package/dist/tools/store.d.ts.map +0 -1
- package/dist/tools/store.js.map +0 -1
- package/dist/tools/theme.d.ts.map +0 -1
- package/dist/tools/theme.js.map +0 -1
- package/dist/tools/url-safety.d.ts.map +0 -1
- package/dist/tools/url-safety.js.map +0 -1
- package/docs/content/tools.md +0 -205
- /package/dist/{tools → extensions}/theme.d.ts +0 -0
- /package/dist/{tools → extensions}/theme.js +0 -0
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP handler for tool extension-point slots.
|
|
3
|
-
*
|
|
4
|
-
* Mounted at `/_agent-native/slots`. Routes:
|
|
5
|
-
*
|
|
6
|
-
* GET /:slotId/installs — current user's installed widgets for a slot
|
|
7
|
-
* GET /:slotId/available — tools that declare this slot, scoped to user access
|
|
8
|
-
* POST /:slotId/install — install a tool into a slot (body: { toolId, position?, config? })
|
|
9
|
-
* DELETE /:slotId/install/:toolId — uninstall
|
|
10
|
-
* GET /tool/:toolId — list slot declarations for a specific tool
|
|
11
|
-
* POST /tool/:toolId — declare a slot target (body: { slotId, config? })
|
|
12
|
-
* DELETE /tool/:toolId/:slotId — remove a slot declaration
|
|
13
|
-
*/
|
|
14
|
-
export declare function createSlotsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<unknown>>;
|
|
15
|
-
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/tools/slots/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAuBH,wBAAgB,kBAAkB,2FAsBjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../src/tools/slots/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,iBAAiB,GAElB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,kBAAkB;IAChC,OAAO,kBAAkB,CAAC,KAAK,EAAE,KAAc,EAAE,EAAE;QACjD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,CAAC,KA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AQ,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAED,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * HTTP handler for tool extension-point slots.\n *\n * Mounted at `/_agent-native/slots`. Routes:\n *\n * GET /:slotId/installs — current user's installed widgets for a slot\n * GET /:slotId/available — tools that declare this slot, scoped to user access\n * POST /:slotId/install — install a tool into a slot (body: { toolId, position?, config? })\n * DELETE /:slotId/install/:toolId — uninstall\n * GET /tool/:toolId — list slot declarations for a specific tool\n * POST /tool/:toolId — declare a slot target (body: { slotId, config? })\n * DELETE /tool/:toolId/:slotId — remove a slot declaration\n */\n\nimport {\n defineEventHandler,\n getMethod,\n setResponseStatus,\n type H3Event,\n} from \"h3\";\nimport { readBody } from \"../../server/h3-helpers.js\";\nimport { getSession } from \"../../server/auth.js\";\nimport { recordChange } from \"../../server/poll.js\";\nimport { runWithRequestContext } from \"../../server/request-context.js\";\nimport { getOrgContext } from \"../../org/context.js\";\nimport {\n addToolSlotTarget,\n removeToolSlotTarget,\n listSlotsForTool,\n listToolsForSlot,\n installToolSlot,\n uninstallToolSlot,\n listSlotInstallsForUser,\n} from \"./store.js\";\n\nexport function createSlotsHandler() {\n return defineEventHandler(async (event: H3Event) => {\n const method = getMethod(event);\n const pathname = (event.url?.pathname || \"\")\n .replace(/^\\/+/, \"\")\n .replace(/\\/+$/, \"\");\n const parts = pathname ? pathname.split(\"/\") : [];\n\n const session = await getSession(event).catch(() => null);\n if (!session?.email) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const orgCtx = await getOrgContext(event).catch(() => null);\n const userEmail = session.email;\n const orgId = orgCtx?.orgId ?? undefined;\n\n return runWithRequestContext({ userEmail, orgId }, () =>\n dispatch(event, method, parts),\n );\n });\n}\n\nasync function dispatch(\n event: H3Event,\n method: string,\n parts: string[],\n): Promise<unknown> {\n // GET /tool/:toolId — list a tool's slot declarations\n if (method === \"GET\" && parts.length === 2 && parts[0] === \"tool\") {\n return listSlotsForTool(parts[1]);\n }\n\n // POST /tool/:toolId — declare a slot target { slotId, config? }\n if (method === \"POST\" && parts.length === 2 && parts[0] === \"tool\") {\n const body = await readBody(event);\n const slotId = String(body?.slotId ?? \"\").trim();\n if (!slotId) {\n setResponseStatus(event, 400);\n return { error: \"slotId is required\" };\n }\n const row = await addToolSlotTarget(parts[1], slotId, body?.config);\n recordChange({ source: \"action\", type: \"change\" });\n return row;\n }\n\n // DELETE /tool/:toolId/:slotId — remove a slot declaration\n if (method === \"DELETE\" && parts.length === 3 && parts[0] === \"tool\") {\n await removeToolSlotTarget(parts[1], parts[2]);\n recordChange({ source: \"action\", type: \"change\" });\n return { ok: true };\n }\n\n // GET /:slotId/installs — current user's installs in slot\n if (method === \"GET\" && parts.length === 2 && parts[1] === \"installs\") {\n return listSlotInstallsForUser(parts[0]);\n }\n\n // GET /:slotId/available — tools that declare this slot the user can install\n if (method === \"GET\" && parts.length === 2 && parts[1] === \"available\") {\n return listToolsForSlot(parts[0]);\n }\n\n // POST /:slotId/install — install { toolId, position?, config? }\n if (method === \"POST\" && parts.length === 2 && parts[1] === \"install\") {\n const body = await readBody(event);\n const toolId = String(body?.toolId ?? \"\").trim();\n if (!toolId) {\n setResponseStatus(event, 400);\n return { error: \"toolId is required\" };\n }\n const row = await installToolSlot(toolId, parts[0], {\n position: body?.position,\n config: body?.config,\n });\n recordChange({ source: \"action\", type: \"change\" });\n return row;\n }\n\n // DELETE /:slotId/install/:toolId — uninstall\n if (method === \"DELETE\" && parts.length === 3 && parts[1] === \"install\") {\n await uninstallToolSlot(parts[2], parts[0]);\n recordChange({ source: \"action\", type: \"change\" });\n return { ok: true };\n }\n\n setResponseStatus(event, 404);\n return { error: \"Not found\" };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/tools/slots/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMpB,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU3B,CAAC;AAEH,eAAO,MAAM,qBAAqB,iMAMhC,CAAC;AAEH,eAAO,MAAM,wBAAwB,qLAMnC,CAAC;AAEH,eAAO,MAAM,4BAA4B,8EAA8E,CAAC;AACxH,eAAO,MAAM,4BAA4B,8EAA8E,CAAC;AACxH,eAAO,MAAM,2BAA2B,6FAA6F,CAAC;AAEtI,eAAO,MAAM,6BAA6B,sVAUxC,CAAC;AAEH,eAAO,MAAM,gCAAgC,8TAU3C,CAAC;AAEH,eAAO,MAAM,yCAAyC,gHAAgH,CAAC;AACvK,eAAO,MAAM,mCAAmC,0HAA0H,CAAC"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drizzle schema for the tool extension-points system.
|
|
3
|
-
*
|
|
4
|
-
* Two tables:
|
|
5
|
-
*
|
|
6
|
-
* - `tool_slots` — declarations: "tool X can render in slot Y". Authored
|
|
7
|
-
* once per tool, regardless of installer.
|
|
8
|
-
* - `tool_slot_installs` — per-user installs: "user U wants tool X in slot Y at
|
|
9
|
-
* position N". Always scoped by owner_email.
|
|
10
|
-
*
|
|
11
|
-
* Neither table spreads `ownableColumns()` — they're not first-class shareable
|
|
12
|
-
* resources. Access to the underlying tool flows through the existing `tools`
|
|
13
|
-
* table sharing model; install rows are personal preferences scoped to the
|
|
14
|
-
* installing user.
|
|
15
|
-
*/
|
|
16
|
-
import { table, text, integer, now } from "../../db/schema.js";
|
|
17
|
-
export const toolSlots = table("tool_slots", {
|
|
18
|
-
id: text("id").primaryKey(),
|
|
19
|
-
toolId: text("tool_id").notNull(),
|
|
20
|
-
slotId: text("slot_id").notNull(),
|
|
21
|
-
config: text("config"),
|
|
22
|
-
createdAt: text("created_at").notNull().default(now()),
|
|
23
|
-
});
|
|
24
|
-
export const toolSlotInstalls = table("tool_slot_installs", {
|
|
25
|
-
id: text("id").primaryKey(),
|
|
26
|
-
toolId: text("tool_id").notNull(),
|
|
27
|
-
slotId: text("slot_id").notNull(),
|
|
28
|
-
ownerEmail: text("owner_email").notNull(),
|
|
29
|
-
orgId: text("org_id"),
|
|
30
|
-
position: integer("position").notNull().default(0),
|
|
31
|
-
config: text("config"),
|
|
32
|
-
createdAt: text("created_at").notNull().default(now()),
|
|
33
|
-
updatedAt: text("updated_at").notNull().default(now()),
|
|
34
|
-
});
|
|
35
|
-
export const TOOL_SLOTS_CREATE_SQL = `CREATE TABLE IF NOT EXISTS tool_slots (
|
|
36
|
-
id TEXT PRIMARY KEY,
|
|
37
|
-
tool_id TEXT NOT NULL,
|
|
38
|
-
slot_id TEXT NOT NULL,
|
|
39
|
-
config TEXT,
|
|
40
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
41
|
-
)`;
|
|
42
|
-
export const TOOL_SLOTS_CREATE_SQL_PG = `CREATE TABLE IF NOT EXISTS tool_slots (
|
|
43
|
-
id TEXT PRIMARY KEY,
|
|
44
|
-
tool_id TEXT NOT NULL,
|
|
45
|
-
slot_id TEXT NOT NULL,
|
|
46
|
-
config TEXT,
|
|
47
|
-
created_at TEXT NOT NULL DEFAULT now()
|
|
48
|
-
)`;
|
|
49
|
-
export const TOOL_SLOTS_BY_SLOT_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slots_by_slot_idx ON tool_slots (slot_id)`;
|
|
50
|
-
export const TOOL_SLOTS_BY_TOOL_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slots_by_tool_idx ON tool_slots (tool_id)`;
|
|
51
|
-
export const TOOL_SLOTS_UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS tool_slots_unique_idx ON tool_slots (tool_id, slot_id)`;
|
|
52
|
-
export const TOOL_SLOT_INSTALLS_CREATE_SQL = `CREATE TABLE IF NOT EXISTS tool_slot_installs (
|
|
53
|
-
id TEXT PRIMARY KEY,
|
|
54
|
-
tool_id TEXT NOT NULL,
|
|
55
|
-
slot_id TEXT NOT NULL,
|
|
56
|
-
owner_email TEXT NOT NULL,
|
|
57
|
-
org_id TEXT,
|
|
58
|
-
position INTEGER NOT NULL DEFAULT 0,
|
|
59
|
-
config TEXT,
|
|
60
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
61
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
62
|
-
)`;
|
|
63
|
-
export const TOOL_SLOT_INSTALLS_CREATE_SQL_PG = `CREATE TABLE IF NOT EXISTS tool_slot_installs (
|
|
64
|
-
id TEXT PRIMARY KEY,
|
|
65
|
-
tool_id TEXT NOT NULL,
|
|
66
|
-
slot_id TEXT NOT NULL,
|
|
67
|
-
owner_email TEXT NOT NULL,
|
|
68
|
-
org_id TEXT,
|
|
69
|
-
position INTEGER NOT NULL DEFAULT 0,
|
|
70
|
-
config TEXT,
|
|
71
|
-
created_at TEXT NOT NULL DEFAULT now(),
|
|
72
|
-
updated_at TEXT NOT NULL DEFAULT now()
|
|
73
|
-
)`;
|
|
74
|
-
export const TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slot_installs_by_user_slot_idx ON tool_slot_installs (owner_email, slot_id)`;
|
|
75
|
-
export const TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS tool_slot_installs_unique_idx ON tool_slot_installs (owner_email, tool_id, slot_id)`;
|
|
76
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/tools/slots/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,EAAE;IAC3C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACjC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACjC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;CACvD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,oBAAoB,EAAE;IAC1D,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACjC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACjC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;IACzC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAClD,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IACtD,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;CACvD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;EAMnC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;EAMtC,CAAC;AAEH,MAAM,CAAC,MAAM,4BAA4B,GAAG,2EAA2E,CAAC;AACxH,MAAM,CAAC,MAAM,4BAA4B,GAAG,2EAA2E,CAAC;AACxH,MAAM,CAAC,MAAM,2BAA2B,GAAG,0FAA0F,CAAC;AAEtI,MAAM,CAAC,MAAM,6BAA6B,GAAG;;;;;;;;;;EAU3C,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG;;;;;;;;;;EAU9C,CAAC;AAEH,MAAM,CAAC,MAAM,yCAAyC,GAAG,6GAA6G,CAAC;AACvK,MAAM,CAAC,MAAM,mCAAmC,GAAG,uHAAuH,CAAC","sourcesContent":["/**\n * Drizzle schema for the tool extension-points system.\n *\n * Two tables:\n *\n * - `tool_slots` — declarations: \"tool X can render in slot Y\". Authored\n * once per tool, regardless of installer.\n * - `tool_slot_installs` — per-user installs: \"user U wants tool X in slot Y at\n * position N\". Always scoped by owner_email.\n *\n * Neither table spreads `ownableColumns()` — they're not first-class shareable\n * resources. Access to the underlying tool flows through the existing `tools`\n * table sharing model; install rows are personal preferences scoped to the\n * installing user.\n */\n\nimport { table, text, integer, now } from \"../../db/schema.js\";\n\nexport const toolSlots = table(\"tool_slots\", {\n id: text(\"id\").primaryKey(),\n toolId: text(\"tool_id\").notNull(),\n slotId: text(\"slot_id\").notNull(),\n config: text(\"config\"),\n createdAt: text(\"created_at\").notNull().default(now()),\n});\n\nexport const toolSlotInstalls = table(\"tool_slot_installs\", {\n id: text(\"id\").primaryKey(),\n toolId: text(\"tool_id\").notNull(),\n slotId: text(\"slot_id\").notNull(),\n ownerEmail: text(\"owner_email\").notNull(),\n orgId: text(\"org_id\"),\n position: integer(\"position\").notNull().default(0),\n config: text(\"config\"),\n createdAt: text(\"created_at\").notNull().default(now()),\n updatedAt: text(\"updated_at\").notNull().default(now()),\n});\n\nexport const TOOL_SLOTS_CREATE_SQL = `CREATE TABLE IF NOT EXISTS tool_slots (\n id TEXT PRIMARY KEY,\n tool_id TEXT NOT NULL,\n slot_id TEXT NOT NULL,\n config TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now'))\n)`;\n\nexport const TOOL_SLOTS_CREATE_SQL_PG = `CREATE TABLE IF NOT EXISTS tool_slots (\n id TEXT PRIMARY KEY,\n tool_id TEXT NOT NULL,\n slot_id TEXT NOT NULL,\n config TEXT,\n created_at TEXT NOT NULL DEFAULT now()\n)`;\n\nexport const TOOL_SLOTS_BY_SLOT_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slots_by_slot_idx ON tool_slots (slot_id)`;\nexport const TOOL_SLOTS_BY_TOOL_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slots_by_tool_idx ON tool_slots (tool_id)`;\nexport const TOOL_SLOTS_UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS tool_slots_unique_idx ON tool_slots (tool_id, slot_id)`;\n\nexport const TOOL_SLOT_INSTALLS_CREATE_SQL = `CREATE TABLE IF NOT EXISTS tool_slot_installs (\n id TEXT PRIMARY KEY,\n tool_id TEXT NOT NULL,\n slot_id TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n position INTEGER NOT NULL DEFAULT 0,\n config TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n updated_at TEXT NOT NULL DEFAULT (datetime('now'))\n)`;\n\nexport const TOOL_SLOT_INSTALLS_CREATE_SQL_PG = `CREATE TABLE IF NOT EXISTS tool_slot_installs (\n id TEXT PRIMARY KEY,\n tool_id TEXT NOT NULL,\n slot_id TEXT NOT NULL,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n position INTEGER NOT NULL DEFAULT 0,\n config TEXT,\n created_at TEXT NOT NULL DEFAULT now(),\n updated_at TEXT NOT NULL DEFAULT now()\n)`;\n\nexport const TOOL_SLOT_INSTALLS_BY_USER_SLOT_INDEX_SQL = `CREATE INDEX IF NOT EXISTS tool_slot_installs_by_user_slot_idx ON tool_slot_installs (owner_email, slot_id)`;\nexport const TOOL_SLOT_INSTALLS_UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS tool_slot_installs_unique_idx ON tool_slot_installs (owner_email, tool_id, slot_id)`;\n"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export declare function ensureSlotTables(): Promise<void>;
|
|
2
|
-
export interface ToolSlotRow {
|
|
3
|
-
id: string;
|
|
4
|
-
toolId: string;
|
|
5
|
-
slotId: string;
|
|
6
|
-
config: string | null;
|
|
7
|
-
createdAt: string;
|
|
8
|
-
}
|
|
9
|
-
export interface ToolSlotInstallRow {
|
|
10
|
-
id: string;
|
|
11
|
-
toolId: string;
|
|
12
|
-
slotId: string;
|
|
13
|
-
ownerEmail: string;
|
|
14
|
-
orgId: string | null;
|
|
15
|
-
position: number;
|
|
16
|
-
config: string | null;
|
|
17
|
-
createdAt: string;
|
|
18
|
-
updatedAt: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Declare that a tool can render in a slot. Caller must have editor access on
|
|
22
|
-
* the tool (only people who can edit a tool can change its slot targets).
|
|
23
|
-
*/
|
|
24
|
-
export declare function addToolSlotTarget(toolId: string, slotId: string, config?: string): Promise<ToolSlotRow>;
|
|
25
|
-
export declare function removeToolSlotTarget(toolId: string, slotId: string): Promise<boolean>;
|
|
26
|
-
export declare function listSlotsForTool(toolId: string): Promise<ToolSlotRow[]>;
|
|
27
|
-
/**
|
|
28
|
-
* List tools that declare a slot — but only tools the current user has access
|
|
29
|
-
* to. Joins through the tools access filter.
|
|
30
|
-
*/
|
|
31
|
-
export declare function listToolsForSlot(slotId: string): Promise<Array<{
|
|
32
|
-
toolId: string;
|
|
33
|
-
name: string;
|
|
34
|
-
description: string;
|
|
35
|
-
icon: string | null;
|
|
36
|
-
config: string | null;
|
|
37
|
-
}>>;
|
|
38
|
-
/**
|
|
39
|
-
* Install a tool into a slot for the current user. Verifies the user has at
|
|
40
|
-
* least viewer access to the tool. Idempotent — re-installing returns the
|
|
41
|
-
* existing row.
|
|
42
|
-
*/
|
|
43
|
-
export declare function installToolSlot(toolId: string, slotId: string, opts?: {
|
|
44
|
-
position?: number;
|
|
45
|
-
config?: string;
|
|
46
|
-
}): Promise<ToolSlotInstallRow>;
|
|
47
|
-
export declare function uninstallToolSlot(toolId: string, slotId: string): Promise<boolean>;
|
|
48
|
-
/**
|
|
49
|
-
* List the current user's installs for a slot. Joins with `tools` so the
|
|
50
|
-
* caller gets tool name/description/icon/updatedAt without a second query.
|
|
51
|
-
* Tools the user has lost access to are silently skipped (lazy garbage
|
|
52
|
-
* collection).
|
|
53
|
-
*/
|
|
54
|
-
export declare function listSlotInstallsForUser(slotId: string): Promise<Array<{
|
|
55
|
-
installId: string;
|
|
56
|
-
toolId: string;
|
|
57
|
-
name: string;
|
|
58
|
-
description: string;
|
|
59
|
-
icon: string | null;
|
|
60
|
-
updatedAt: string;
|
|
61
|
-
position: number;
|
|
62
|
-
config: string | null;
|
|
63
|
-
}>>;
|
|
64
|
-
/** Delete every slot/install row referencing a tool. Called from deleteTool. */
|
|
65
|
-
export declare function cascadeDeleteToolSlots(toolId: string): Promise<void>;
|
|
66
|
-
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/tools/slots/store.ts"],"names":[],"mappings":"AA4BA,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAmBtD;AAED,MAA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AE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,kBAAkB,CAAC,CA+C7B;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAclB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CACpE,KAAK,CAAC;IACJ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC,CACH,CA4CA;AAED,gFAAgF;AAChF,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK1E"}
|
|
@@ -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,CAAC;YAC3B,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;YACxB,MAAM,MAAM,CAAC,OAAO,CAClB,EAAE,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,qBAAqB,CACtD,CAAC;YACF,MAAM,MAAM,CAAC,OAAO,CA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CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC,CAAC,EAAE;YACf,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM,EAAE,CAAC,CAAC,MAAM;SACjB,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAc;IACzD,MAAM,gBAAgB,EAAE,CAAC;IACzB,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/D,MAAM,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,gBAAgB;IACvB,MAAM,KAAK,GAAG,mBAAmB,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { and, eq, 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"]}
|
package/dist/tools/store.d.ts
DELETED
|
@@ -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,M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E,MAAM,CAAA;KAAE,CAAC,CAAC;CACpD;AAED,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAyBzB;AAED,wBAAsB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAe7D"}
|
package/dist/tools/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/tools/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EACL,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,4BAA4B,EAC5B,+BAA+B,EAC/B,qBAAqB,EACrB,mBAAmB,EACnB,8BAA8B,EAC9B,wBAAwB,EACxB,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,aAAa,CAAC;AAErB,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAEjD,IAAI,YAAuC,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,CAAC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IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;IACjE,MAAM,SAAS,EAAE,CAAC,OAAO,CAAC;QACxB,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"}
|
package/dist/tools/theme.js.map
DELETED
|
@@ -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,C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;4BACvB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;wBACrB,CAAC;oBACH,CAAC;oBACD,gEAAgE;oBAChE,4DAA4D;oBAC5D,iBAAiB;oBACjB,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;wBAC3B,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC;oBACrC,CAAC;oBACD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;oBACtB,OAAO,QAAQ,CAAC,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"]}
|