@jini-ai/agent-plugins 0.7.2 → 0.7.3-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/NOTICE +2 -0
  3. package/README.md +11 -15
  4. package/calendly/plugin.json +3 -3
  5. package/cloudflare/lib/forms.mjs +9 -10
  6. package/cloudflare/lib/target.mjs +1 -1
  7. package/cloudflare/plugin.json +3 -3
  8. package/cloudflare/worker/forms-receiver.mjs +9 -9
  9. package/composio/plugin.json +3 -3
  10. package/core/persistent-state.js +227 -163
  11. package/dist/admin-surfaces/connections/connections.d.ts +11 -6
  12. package/dist/admin-surfaces/connections/connections.js +102 -85
  13. package/dist/admin-surfaces/node.d.ts +27 -0
  14. package/dist/admin-surfaces/node.js +32 -0
  15. package/dist/admin-surfaces/plugin-state.js +21 -18
  16. package/dist/admin-surfaces/surface-client.d.ts +4 -0
  17. package/dist/admin-surfaces/surface-client.js +124 -117
  18. package/dist/admin-surfaces/surface-handlers.js +21 -17
  19. package/dist/admin-surfaces/theme.d.ts +5 -1
  20. package/dist/admin-surfaces/theme.js +3 -3
  21. package/dist/connect/access-token-tool.d.ts +3 -1
  22. package/dist/connect/access-token-tool.js +3 -2
  23. package/dist/connect/apply-connect-defaults.js +2 -2
  24. package/dist/connect/apply-tool-renames.js +9 -8
  25. package/dist/connect/connect-tool.d.ts +2 -0
  26. package/dist/connect/connect-tool.js +3 -2
  27. package/dist/connect/credential-cards.js +3 -2
  28. package/dist/connect/credential-save-tool.d.ts +14 -11
  29. package/dist/connect/credential-save-tool.js +128 -121
  30. package/dist/connect/enable-access.d.ts +2 -2
  31. package/dist/connect/enable-access.js +6 -6
  32. package/dist/connect/executable/register.js +40 -34
  33. package/dist/connect/federate-mcp.d.ts +21 -11
  34. package/dist/connect/federate-mcp.js +28 -21
  35. package/dist/connect/grant-signed-in-defaults.js +3 -3
  36. package/dist/connect/import-access-token.js +2 -1
  37. package/dist/connect/index.d.ts +1 -0
  38. package/dist/connect/index.js +1 -0
  39. package/dist/connect/plugin-credential-card.js +2 -1
  40. package/dist/connect/plugin-host/index.d.ts +10 -5
  41. package/dist/connect/plugin-host/index.js +113 -100
  42. package/dist/connect/ports.d.ts +1 -1
  43. package/dist/connect/row-update.d.ts +22 -0
  44. package/dist/connect/row-update.js +18 -0
  45. package/dist/connect/switch-on-saved-token.d.ts +4 -2
  46. package/dist/connect/switch-on-saved-token.js +1 -1
  47. package/dist/connect/token-map.d.ts +44 -0
  48. package/dist/connect/token-map.js +49 -0
  49. package/dist/core/identity-namespace.js +5 -0
  50. package/dist/folder-zip.d.ts +3 -1
  51. package/dist/folder-zip.js +2 -2
  52. package/dist/lifecycle/activation.d.ts +4 -4
  53. package/dist/lifecycle/activation.js +4 -5
  54. package/dist/lifecycle/automatic-use.js +236 -210
  55. package/dist/lifecycle/bundled-digests.d.ts +75 -12
  56. package/dist/lifecycle/bundled-digests.js +213 -212
  57. package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
  58. package/dist/lifecycle/bundled-source-archive.js +263 -264
  59. package/dist/lifecycle/capability-projection.d.ts +1 -1
  60. package/dist/lifecycle/capability-projection.js +1 -1
  61. package/dist/lifecycle/credential-card-metadata.d.ts +1 -1
  62. package/dist/lifecycle/credential-card-metadata.js +27 -3
  63. package/dist/lifecycle/exports.js +9 -4
  64. package/dist/lifecycle/fetch-archive.d.ts +1 -1
  65. package/dist/lifecycle/fetch-archive.js +1 -1
  66. package/dist/lifecycle/host-tools/identity.js +3 -2
  67. package/dist/lifecycle/host-tools/ports.d.ts +2 -0
  68. package/dist/lifecycle/host-tools/search-tool.d.ts +4 -2
  69. package/dist/lifecycle/host-tools/search-tool.js +9 -8
  70. package/dist/lifecycle/host-tools/skill-tool.d.ts +18 -2
  71. package/dist/lifecycle/host-tools/skill-tool.js +16 -8
  72. package/dist/lifecycle/index.d.ts +118 -110
  73. package/dist/lifecycle/index.js +45 -12
  74. package/dist/lifecycle/install-errors.d.ts +1 -1
  75. package/dist/lifecycle/install-from-url.d.ts +1 -1
  76. package/dist/lifecycle/install-from-url.js +1 -1
  77. package/dist/lifecycle/install.d.ts +7 -2
  78. package/dist/lifecycle/install.js +414 -396
  79. package/dist/lifecycle/installed-package-index.js +45 -42
  80. package/dist/lifecycle/layout.d.ts +1 -1
  81. package/dist/lifecycle/layout.js +1 -1
  82. package/dist/lifecycle/mail/catalog.d.ts +8 -32
  83. package/dist/lifecycle/mail/catalog.js +25 -20
  84. package/dist/lifecycle/mail/contribution.d.ts +2 -2
  85. package/dist/lifecycle/mail/contribution.js +34 -34
  86. package/dist/lifecycle/mail/selection.js +6 -2
  87. package/dist/lifecycle/manifest.d.ts +3 -3
  88. package/dist/lifecycle/manifest.js +4 -4
  89. package/dist/lifecycle/mcp-provisioning.d.ts +3 -3
  90. package/dist/lifecycle/mcp-provisioning.js +3 -3
  91. package/dist/lifecycle/package-paths.d.ts +1 -1
  92. package/dist/lifecycle/package-paths.js +1 -1
  93. package/dist/lifecycle/persistent-state.js +1 -2
  94. package/dist/lifecycle/ports.d.ts +5 -1
  95. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +30 -8
  96. package/dist/lifecycle/resolve-agent-plugin-refs.js +227 -228
  97. package/dist/lifecycle/retire-bundled.d.ts +1 -52
  98. package/dist/lifecycle/retire-bundled.js +134 -84
  99. package/dist/lifecycle/search.d.ts +2 -1
  100. package/dist/lifecycle/search.js +1 -1
  101. package/dist/lifecycle/seed-bundled.d.ts +1 -1
  102. package/dist/lifecycle/seed-bundled.js +154 -155
  103. package/dist/lifecycle/set-enabled.d.ts +1 -1
  104. package/dist/lifecycle/set-enabled.js +1 -1
  105. package/dist/lifecycle/skill-file-reader.js +53 -50
  106. package/dist/lifecycle/tools/projection.d.ts +4 -7
  107. package/dist/lifecycle/tools/projection.js +109 -108
  108. package/dist/lifecycle/trusted-plugin-files.d.ts +2 -2
  109. package/dist/lifecycle/trusted-plugin-files.js +1 -1
  110. package/dist/lifecycle/uninstall.d.ts +1 -1
  111. package/dist/lifecycle/uninstall.js +237 -241
  112. package/dist/lifecycle/update-store.js +20 -17
  113. package/dist/lifecycle/update.js +287 -281
  114. package/dist/lifecycle/yauzl-archive-reader.d.ts +2 -2
  115. package/dist/lifecycle/yauzl-archive-reader.js +8 -2
  116. package/dist/manifest.d.ts +11 -3
  117. package/dist/manifest.js +9 -9
  118. package/fly/jini-credential-schemes.json +11 -0
  119. package/fly/plugin.json +3 -4
  120. package/github/plugin.json +3 -3
  121. package/github/source-control/backup-push.mjs +11 -11
  122. package/github/source-control/commit-site.mjs +23 -13
  123. package/github/source-control/github.mjs +12 -6
  124. package/github/source-control/write-files.mjs +27 -28
  125. package/github-pages/{tovu-deploy-targets.json → jini-deploy-targets.json} +22 -22
  126. package/github-pages/plugin.json +3 -3
  127. package/github-pages/targets/github-pages.mjs +3 -3
  128. package/google-login/plugin.json +3 -3
  129. package/google-workspace/README.md +14 -14
  130. package/google-workspace/form-destinations/README.md +3 -3
  131. package/google-workspace/form-destinations/dedupe.mjs +1 -1
  132. package/google-workspace/form-destinations/mapping.mjs +8 -9
  133. package/google-workspace/form-destinations/sheets.mjs +1 -1
  134. package/google-workspace/{tovu-admin-surfaces.json → jini-admin-surfaces.json} +2 -2
  135. package/google-workspace/{tovu-agent-tools.json → jini-agent-tools.json} +28 -28
  136. package/google-workspace/{tovu-connections.json → jini-connections.json} +2 -2
  137. package/google-workspace/lib/auth.mjs +2 -2
  138. package/google-workspace/lib/form-destination-settings.mjs +1 -1
  139. package/google-workspace/lib/picker-flow.mjs +2 -2
  140. package/google-workspace/lib/request-policy.mjs +1 -1
  141. package/google-workspace/lib/surface-actions.mjs +1 -1
  142. package/google-workspace/plugin.json +3 -3
  143. package/google-workspace/tools/sheets/README.md +3 -3
  144. package/google-workspace/tools/sheets-admin/README.md +3 -3
  145. package/google-workspace/ui/README.md +4 -4
  146. package/google-workspace/ui/connection-panel.mjs +51 -51
  147. package/google-workspace/ui/destination-panel.mjs +34 -34
  148. package/google-workspace/ui/dom.mjs +15 -16
  149. package/google-workspace/ui/picker-flow.mjs +2 -2
  150. package/google-workspace/ui/picker.mjs +19 -19
  151. package/google-workspace/ui/surface-client.mjs +96 -69
  152. package/higgsfield-media/plugin.json +3 -3
  153. package/jev/plugin.json +3 -3
  154. package/kuinetic/CHANGELOG.md +12 -0
  155. package/kuinetic/mcp.json +4 -0
  156. package/kuinetic/plugin.json +27 -0
  157. package/kuinetic/skills/kuinetic/SKILL.md +120 -0
  158. package/kuinetic/skills/kuinetic/references/effects-by-family.md +32 -0
  159. package/kuinetic/skills/kuinetic/references/opt-in-tiers.md +12 -0
  160. package/kuinetic/skills/kuinetic/references/reserved-keys.md +36 -0
  161. package/meilisearch/plugin.json +5 -5
  162. package/netlify/plugin.json +3 -3
  163. package/netlify/targets/netlify.mjs +14 -4
  164. package/opentelemetry/plugin.json +3 -3
  165. package/package.json +27 -22
  166. package/posthog/plugin.json +3 -3
  167. package/railway/plugin.json +3 -3
  168. package/render/plugin.json +3 -3
  169. package/resend/NOTES.md +2 -2
  170. package/resend/adapters/resend.mjs +1 -1
  171. package/resend/{tovu-mail-adapters.json → jini-mail-adapters.json} +1 -1
  172. package/resend/lib/domains.mjs +8 -8
  173. package/resend/plugin.json +3 -3
  174. package/s3-compatible/{tovu-deploy-targets.json → jini-deploy-targets.json} +68 -68
  175. package/s3-compatible/jini-object-stores.json +29 -0
  176. package/s3-compatible/object-stores/s3-compatible.mjs +19 -13
  177. package/s3-compatible/plugin.json +3 -3
  178. package/s3-compatible/targets/s3-compatible.mjs +25 -25
  179. package/sentry/plugin.json +3 -3
  180. package/shadcn-ui/CHANGELOG.md +7 -0
  181. package/shadcn-ui/LICENSE +201 -0
  182. package/shadcn-ui/NOTICE +10 -0
  183. package/shadcn-ui/mcp.json +4 -0
  184. package/shadcn-ui/plugin.json +26 -0
  185. package/shopify/plugin.json +3 -3
  186. package/site-compliance/plugin.json +3 -3
  187. package/site-import/plugin.json +3 -3
  188. package/supabase/mcp.json +1 -4
  189. package/supabase/plugin.json +3 -3
  190. package/ui-ux-design/CHANGELOG.md +13 -0
  191. package/ui-ux-design/NOTICE +2 -0
  192. package/ui-ux-design/README.md +17 -7
  193. package/ui-ux-design/plugin.json +6 -3
  194. package/ui-ux-design/skills/ui-ux-design/SKILL.md +38 -152
  195. package/ui-ux-design/skills/ui-ux-design/references/full-workflow.md +156 -0
  196. package/ui-ux-design/skills/ui-ux-design/references/ui-animation.md +4 -4
  197. package/vercel/NOTES.md +1 -1
  198. package/vercel/object-stores/vercel-blob.mjs +12 -2
  199. package/vercel/plugin.json +3 -3
  200. package/vercel/targets/vercel.mjs +3 -3
  201. package/wordpress/plugin.json +3 -3
  202. package/dist/lifecycle/node.d.ts +0 -11
  203. package/dist/lifecycle/node.js +0 -38
  204. package/fly/tovu-credential-schemes.json +0 -11
  205. package/github/deployments/github.mjs +0 -415
  206. package/s3-compatible/tovu-object-stores.json +0 -29
  207. package/ui-ux-design/skills/ui-ux-design/references/kuinetic-reference.md +0 -184
  208. /package/cloudflare/{tovu-consent.json → jini-consent.json} +0 -0
  209. /package/cloudflare/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  210. /package/cloudflare/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  211. /package/fly/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  212. /package/fly/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  213. /package/github/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  214. /package/github/{tovu-source-control.json → jini-source-control.json} +0 -0
  215. /package/google-login/{tovu-login-providers.json → jini-login-providers.json} +0 -0
  216. /package/google-workspace/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
  217. /package/meilisearch/{tovu-search-providers.json → jini-search-providers.json} +0 -0
  218. /package/netlify/{tovu-consent.json → jini-consent.json} +0 -0
  219. /package/netlify/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  220. /package/railway/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  221. /package/railway/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  222. /package/render/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
  223. /package/render/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
  224. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/README.md +0 -0
  225. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/SKILL.md +0 -0
  226. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/auth-layout.tsx +0 -0
  227. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/data-table.tsx +0 -0
  228. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/form-pattern.tsx +0 -0
  229. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/component-catalog.md +0 -0
  230. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/customization-guide.md +0 -0
  231. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/migration-guide.md +0 -0
  232. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/setup-guide.md +0 -0
  233. /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/scripts/verify-setup.sh +0 -0
  234. /package/vercel/{tovu-consent.json → jini-consent.json} +0 -0
  235. /package/vercel/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
  236. /package/vercel/{tovu-object-stores.json → jini-object-stores.json} +0 -0
@@ -33,7 +33,11 @@ export interface AdminSurfaceThemeMessage {
33
33
  }
34
34
  /** Whether `value` is plain declaration text that cannot fetch anything or end its declaration.
35
35
  * @complexity O(n) in the value length. */
36
- export declare function isSafeAdminSurfaceThemeValue(value: unknown): value is string;
36
+ export declare function isSafeAdminSurfaceThemeValue(required: {
37
+ readonly value: unknown;
38
+ }, _optional?: Record<string, never>): required is {
39
+ readonly value: string;
40
+ };
37
41
  /**
38
42
  * Reads the shared tokens from the host's computed style.
39
43
  * @param required.style - Usually `getComputedStyle(element)` for the element the admin theme is on.
@@ -29,8 +29,8 @@ const MAX_VALUE_LENGTH = 200;
29
29
  const UNSAFE_VALUE = /url\(|image\(|image-set\(|[;{}<>\\@]/i;
30
30
  /** Whether `value` is plain declaration text that cannot fetch anything or end its declaration.
31
31
  * @complexity O(n) in the value length. */
32
- export function isSafeAdminSurfaceThemeValue(value) {
33
- return typeof value === 'string' && value.length > 0 && value.length <= MAX_VALUE_LENGTH && !UNSAFE_VALUE.test(value);
32
+ export function isSafeAdminSurfaceThemeValue(required, _optional = {}) {
33
+ return typeof required.value === 'string' && required.value.length > 0 && required.value.length <= MAX_VALUE_LENGTH && !UNSAFE_VALUE.test(required.value);
34
34
  }
35
35
  /**
36
36
  * Reads the shared tokens from the host's computed style.
@@ -44,7 +44,7 @@ export function readAdminSurfaceTheme(required, optional = {}) {
44
44
  const tokens = {};
45
45
  for (const token of ADMIN_SURFACE_THEME_TOKENS) {
46
46
  const value = required.style.getPropertyValue(optional.sources?.[token] ?? token).trim();
47
- if (isSafeAdminSurfaceThemeValue(value))
47
+ if (isSafeAdminSurfaceThemeValue({ value }))
48
48
  tokens[token] = value;
49
49
  }
50
50
  return { scheme: required.scheme, tokens };
@@ -1,6 +1,7 @@
1
1
  import type { PluginCredentialCard } from "@jini-ai/core/contracts/credentials";
2
2
  import type { SurfaceCardSecretForm, SurfaceCardsPort } from "@jini-ai/core/contracts/cards";
3
3
  import { type LegacyToolAuthorizeFn as AuthorizeFn } from "@jini-ai/core";
4
+ import { type Logger } from "@jini-ai/core/primitives";
4
5
  import { type ToolExecutionOptions, type ToolExecutionContext } from "@jini-ai/core";
5
6
  import type { SurfaceAskThenReport, SurfaceExchangeStore } from "@jini-ai/core";
6
7
  import { type AgentPluginMcpTrustClassifier, type AgentPluginMcpFederationMessages } from "./federate-mcp.js";
@@ -14,7 +15,7 @@ import { type ResolvedAgentPluginForConnect } from "./connect-tool.js";
14
15
  * remote server declares `tokenAuth { helpUrl, probeUrl }` in its `mcp.json` (`manifest.ts`).
15
16
  * Used when `agent_plugin_connect`'s sign-in cannot start.
16
17
  *
17
- * Moved here on 2026-09-29 from `features/supabase-connect/` (SPEC-052's `supabase_set_access_token`),
18
+ * Moved here on 2026-09-29 from `features/supabase-connect/` (`supabase_set_access_token`),
18
19
  * so no vendor code is left in core: the tokens page and the probe URL now come from the plugin.
19
20
  *
20
21
  * A Jini secret-card spec with domain copy from `connect-card-ui.ts`; the submitted token is probed with one GET to the declared
@@ -107,6 +108,7 @@ export interface AgentPluginTokenCredentialsPort {
107
108
  * your installed-declaration read (no filesystem default here); `federation` is your trust rule and
108
109
  * federation refusal copy, the same pair your connect tool passes. */
109
110
  export interface AgentPluginTokenTargetDeps {
111
+ readonly report?: Pick<Logger, 'warn'>;
110
112
  readonly workspaceId: string;
111
113
  readonly mcp: AgentPluginMcpProjectionPorts & Pick<AgentPluginMcpPort, "repo" | "saveServer"> & Partial<Pick<AgentPluginMcpPort, "notifyRosterChanged">>;
112
114
  readonly resolveInstalledPlugin: (pluginId: string) => Promise<ResolvedAgentPluginForConnect | null>;
@@ -1,9 +1,10 @@
1
1
  import { adaptLegacyAuthorize, requireToolPermission } from "@jini-ai/core";
2
+ import {} from "@jini-ai/core/primitives";
2
3
  import { requireInputRecord, ToolInputError } from "@jini-ai/core";
3
4
  import { deriveAgentPluginConnectionId, provisionAgentPluginMcpServers } from "./federate-mcp.js";
4
5
  import { buildAgentPluginAccessTokenFormWithPorts, buildAgentPluginAccessTokenOutcomeWithPorts, resolveAgentPluginCardIdentity, } from "./connect-card-ui.js";
5
6
  import { titleCaseFromPluginId } from "./connect-tool.js";
6
- /** Plain-language messages from SPEC-052's errors.spec.md. None ever carries a token or a vendor body. */
7
+ /** Plain-language messages from errors.spec.md. None ever carries a token or a vendor body. */
7
8
  const MESSAGES = {
8
9
  tokenInvalid: "The server rejected this token.",
9
10
  blankToken: "The access token cannot be blank. Nothing was saved.",
@@ -57,7 +58,7 @@ export async function resolveTarget({ routeDeps, pluginId, principalId }, option
57
58
  if (!connectionId)
58
59
  throw new ToolInputError({ message: routeDeps.messages.serverNotSetUp({ pluginId, serverKey }) });
59
60
  optional.signal?.throwIfAborted();
60
- await provisionAgentPluginMcpServers(routeDeps.mcp, { workspaceId: routeDeps.workspaceId, pluginId, servers: plugin.servers, principalId, ...routeDeps.federation });
61
+ await provisionAgentPluginMcpServers({ deps: routeDeps.mcp, workspaceId: routeDeps.workspaceId, pluginId, servers: plugin.servers, principalId, ...routeDeps.federation }, { report: routeDeps.report });
61
62
  return { pluginId, displayName: titleCaseFromPluginId({ pluginId }), connectionId, config };
62
63
  }
63
64
  /** Token sign-in keeps its input validation; Jini owns the GET, redirects and status classification.
@@ -13,11 +13,11 @@ async function readConnectGrant({ deps, serverId, resolveServers, approvedEnable
13
13
  return null;
14
14
  if (!approvedEnable && !allowsAutomaticConnectGrant(row))
15
15
  return null;
16
- const defaults = findAgentPluginMcpServerDefaults(await resolveServers({ workspaceId: deps.workspaceId, pluginId }), row);
16
+ const defaults = findAgentPluginMcpServerDefaults({ servers: await resolveServers({ workspaceId: deps.workspaceId, pluginId }), row });
17
17
  // A read-only declaration is classification, not permission to change sign-in grants.
18
18
  if (!defaults?.allow)
19
19
  return null;
20
- const grant = validatedAgentPluginToolGrant({ current: storedAgentPluginGrants({ row, projections: ports.projections }), declared: defaults }, { reason: approvedEnable ? 'owner-enable' : 'sign-in', ports, messages: deps });
20
+ const grant = validatedAgentPluginToolGrant({ current: storedAgentPluginGrants({ row, projections: ports.projections }), declared: defaults, ports, messages: deps }, { reason: approvedEnable ? 'owner-enable' : 'sign-in' });
21
21
  return grant ? { row, pluginId, grant } : null;
22
22
  }
23
23
  /** Existing choices and nonempty selections stay until a fresh access approval. O(n) list bytes. */
@@ -1,5 +1,7 @@
1
1
  import { nowIso as clockNowIso } from "@jini-ai/core/primitives";
2
+ import { describeErrorForLog } from "@jini-ai/core";
2
3
  import { deriveAgentPluginConnectionId } from "./federate-mcp.js";
4
+ import { updateAgentPluginMcpRow } from "./row-update.js";
3
5
  /** A stored JSON tool list as names, or `null` when it is not a JSON array of strings (left alone). */
4
6
  function readToolList(raw) {
5
7
  if (!raw)
@@ -55,22 +57,21 @@ async function applyServerToolRenames(input, _options = {}) {
55
57
  const serverId = deriveAgentPluginConnectionId({ serverKey });
56
58
  if (serverId === null)
57
59
  return false;
60
+ const { renamedTools } = config;
58
61
  const result = { changed: false };
59
62
  try {
60
- const row = await deps.externalMcpServerRepo.findByServerId({ workspaceId: deps.workspaceId, serverId });
61
- if (!row)
62
- return false;
63
- const renamed = renameRowTools({ row, renames: config.renamedTools, clock: deps.clock, actor: deps.actor, pluginId, url: config.url });
63
+ // Conditional on the version it read; a missed write re-reads and re-applies once (M4).
64
+ const renamed = await updateAgentPluginMcpRow({ repo: deps.externalMcpServerRepo, key: { workspaceId: deps.workspaceId, serverId },
65
+ build: row => renameRowTools({ row, renames: renamedTools, clock: deps.clock, actor: deps.actor, pluginId, url: config.url }) });
64
66
  if (!renamed)
65
67
  return false;
66
- await deps.externalMcpServerRepo.upsert(renamed);
67
68
  result.changed = true;
68
- const renames = Object.entries(config.renamedTools).map(([from, to]) => `${from} -> ${to}`).join(", ");
69
+ const renames = Object.entries(renamedTools).map(([from, to]) => `${from} -> ${to}`).join(", ");
69
70
  log.info(`[agent-plugins] '${serverId}': renamed saved tools to follow the '${pluginId}' plugin (${renames}).`);
70
71
  return true;
71
72
  }
72
73
  catch (err) {
73
- log.warn(`[agent-plugins] could not apply the '${pluginId}' plugin's tool renames to '${serverId}': ${err instanceof Error ? err.message : String(err)}`);
74
+ log.warn(`[agent-plugins] could not apply the '${pluginId}' plugin's tool renames to '${serverId}': ${describeErrorForLog({ err })}`);
74
75
  }
75
76
  return result.changed;
76
77
  }
@@ -89,7 +90,7 @@ export async function applyAgentPluginToolRenames(required, _optional = {}) {
89
90
  plugins = await deps.listPlugins();
90
91
  }
91
92
  catch (err) {
92
- log.warn(`[agent-plugins] could not list plugins to apply tool renames: ${err instanceof Error ? err.message : String(err)}`);
93
+ log.warn(`[agent-plugins] could not list plugins to apply tool renames: ${describeErrorForLog({ err })}`);
93
94
  return;
94
95
  }
95
96
  let changed = false;
@@ -1,5 +1,6 @@
1
1
  import type { PluginCredentialCard } from "@jini-ai/core/contracts/credentials";
2
2
  import type { ExternalMcpConnectStart } from "@jini-ai/core/contracts/hosted-mcp";
3
+ import { type Logger } from "@jini-ai/core/primitives";
3
4
  import { type DerivedRiskByToolId, type AgentToolDefinition, type AccessApprovalDescription, type ToolHandler } from "@jini-ai/core";
4
5
  import { type LegacyToolAuthorizeFn as AuthorizeFn } from "@jini-ai/core";
5
6
  import { type ToolExecutionOptions, type ToolExecutionContext } from "@jini-ai/core";
@@ -218,6 +219,7 @@ export interface AgentPluginConnectHost<Surfaces> {
218
219
  * and `resolveInstalledPlugin` are your fresh activation owner and installed-declaration read (no
219
220
  * filesystem default here). */
220
221
  export interface AgentPluginConnectDeps<Surfaces, Connection> {
222
+ readonly report?: Pick<Logger, 'warn'>;
221
223
  readonly ownerPrincipalId?: Promise<string>;
222
224
  /** Fresh activation owner; injected so OFF-plugin refusal needs no filesystem in unit tests. */
223
225
  readonly isPluginEnabled: (pluginId: string) => Promise<boolean>;
@@ -1,4 +1,5 @@
1
1
  import { adaptLegacyAuthorize } from "@jini-ai/core";
2
+ import {} from "@jini-ai/core/primitives";
2
3
  import {} from "@jini-ai/core";
3
4
  import { requireToolPermission } from "@jini-ai/core";
4
5
  import { ToolInputError, redactSecrets } from "@jini-ai/core";
@@ -197,7 +198,7 @@ async function connectWithoutOAuth({ routeDeps, surfaces, ctx, pluginId, servers
197
198
  const approved = await approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId, servers: { [serverKey]: config } }, optional);
198
199
  if (!approved.approved)
199
200
  return approved.result;
200
- await provisionAgentPluginMcpServers(routeDeps.mcp, { workspaceId: routeDeps.workspaceId, pluginId, servers: { [serverKey]: config }, principalId: ctx.principal.id, ...routeDeps.host.federation });
201
+ await provisionAgentPluginMcpServers({ deps: routeDeps.mcp, workspaceId: routeDeps.workspaceId, pluginId, servers: { [serverKey]: config }, principalId: ctx.principal.id, ...routeDeps.host.federation }, { report: routeDeps.report });
201
202
  return { status: 'connected' };
202
203
  }
203
204
  if (!saveToken)
@@ -258,7 +259,7 @@ export async function runAgentPluginConnect({ routeDeps, surfaces, ctx, pluginId
258
259
  const access = await approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId, servers: signedIn }, optional);
259
260
  if (!access.approved)
260
261
  return access.result;
261
- const provisioned = await provisionAgentPluginMcpServers(routeDeps.mcp, { workspaceId: routeDeps.workspaceId, pluginId, servers: plugin.servers, principalId: ctx.principal.id, ...routeDeps.host.federation });
262
+ const provisioned = await provisionAgentPluginMcpServers({ deps: routeDeps.mcp, workspaceId: routeDeps.workspaceId, pluginId, servers: plugin.servers, principalId: ctx.principal.id, ...routeDeps.host.federation }, { report: routeDeps.report });
262
263
  // A colliding row can survive a refused provisioning attempt; never start sign-in on it.
263
264
  const refusal = [...provisioned.failed, ...provisioned.skipped]
264
265
  .find(result => oauthServerKeys.includes(result.serverKey));
@@ -1,3 +1,4 @@
1
+ import { createConsoleLogger } from '@jini-ai/core/primitives';
1
2
  import { parsePluginCredentialCards } from '../lifecycle/credential-card-metadata.js';
2
3
  // Declaration parsing stays here; the host binds trusted contributions and mail-card precedence.
3
4
  export { parsePluginCredentialCards, parseCredentialCardUsedFor } from '../lifecycle/credential-card-metadata.js';
@@ -18,13 +19,13 @@ export function mergePluginCredentialCards({ mailCards, manifestCards }, options
18
19
  const accepted = manifestCards.filter(card => {
19
20
  if (counts.get(card.providerId) === 1)
20
21
  return true;
21
- (options.onRefusal ?? console.warn)(`duplicate plugin credential card target '${card.providerId}' was refused`);
22
+ (options.onRefusal ?? (message => createConsoleLogger({ prefix: '' }).warn({ message })))(`duplicate plugin credential card target '${card.providerId}' was refused`);
22
23
  return false;
23
24
  });
24
25
  return [...mailCards, ...accepted].filter(card => {
25
26
  if (!isApiCard({ value: card }) || !conflictingLabels.has(card.label))
26
27
  return true;
27
- (options.onRefusal ?? console.warn)(`duplicate API credential label '${card.label}' from '${card.pluginId ?? card.providerId}' was refused`);
28
+ (options.onRefusal ?? (message => createConsoleLogger({ prefix: '' }).warn({ message })))(`duplicate API credential label '${card.label}' from '${card.pluginId ?? card.providerId}' was refused`);
28
29
  return false;
29
30
  });
30
31
  }
@@ -20,6 +20,18 @@ export interface CredentialSaveMessages {
20
20
  readonly description: string;
21
21
  readonly oauthRefusal: string;
22
22
  }
23
+ /** What `buildCredentialSaveRegistrations` receives per host: the optional plugin-card hooks and result hook. */
24
+ interface CredentialSaveRegistrationInput {
25
+ readonly adapters: CredentialSaveAdapters;
26
+ readonly loadPluginCredentialCards?: () => Promise<readonly PluginCredentialCard[]>;
27
+ readonly authorizePluginProvider?: (ctx: ToolExecutionContext) => Promise<void>;
28
+ readonly adaptersForCards?: (required: {
29
+ cards: readonly PluginCredentialCard[];
30
+ }) => CredentialSaveAdapters;
31
+ readonly savedResult?: (input: {
32
+ result: unknown;
33
+ }) => Promise<unknown>;
34
+ }
23
35
  /** @agent-note The host supplies its reviewed metadata, public tool id and credential categories. Save adapters keep authorization and persistence in that host. */
24
36
  export declare function createCredentialSaveTools({ metadata: toolMetadata, toolId: CREDENTIAL_SAVE_TOOL_ID, categories: CUSTOM_CREDENTIAL_CATEGORIES, messages, catalogModule }: {
25
37
  metadata: ToolMetadataById;
@@ -30,16 +42,7 @@ export declare function createCredentialSaveTools({ metadata: toolMetadata, tool
30
42
  }, _optional?: Record<string, never>): {
31
43
  credentialSaveCatalog: AgentToolDefinition[];
32
44
  credentialSaveDerivedRisk: DerivedRiskByToolId;
33
- buildCredentialSaveRegistrations: ({ adapters, loadPluginCredentialCards, authorizePluginProvider, adaptersForCards, savedResult }: {
34
- savedResult?: (input: {
35
- result: unknown;
36
- }) => Promise<unknown>;
37
- adapters: CredentialSaveAdapters;
38
- loadPluginCredentialCards?: () => Promise<readonly PluginCredentialCard[]>;
39
- authorizePluginProvider?: (ctx: ToolExecutionContext) => Promise<void>;
40
- adaptersForCards?: (required: {
41
- cards: readonly PluginCredentialCard[];
42
- }) => CredentialSaveAdapters;
43
- }, _optional?: {}) => ToolRegistration[];
45
+ buildCredentialSaveRegistrations: (hooks: CredentialSaveRegistrationInput, _optional?: {}) => ToolRegistration[];
44
46
  };
47
+ export {};
45
48
  //# sourceMappingURL=credential-save-tool.d.ts.map
@@ -1,16 +1,15 @@
1
1
  import { loadPluginCredentialCardsSafely } from "./plugin-credential-card.js";
2
2
  import { buildDomainRegistrations, indexCatalogById, requireInputRecord, requireString, ToolInputError } from '@jini-ai/core';
3
- /** @agent-note The host supplies its reviewed metadata, public tool id and credential categories. Save adapters keep authorization and persistence in that host. */
4
- export function createCredentialSaveTools({ metadata: toolMetadata, toolId: CREDENTIAL_SAVE_TOOL_ID, categories: CUSTOM_CREDENTIAL_CATEGORIES, messages, catalogModule }, _optional = {}) {
5
- const KINDS = ['api', 'media-provider', 'source-control', 'publish-host', 'agent-plugin-token', 'plugin-provider', 'provider-settings'];
6
- /** Model input carries non-secret metadata only. Schema additionalProperties is descriptive:
7
- * selectSave and each domain handler enforce the allowed keys independently, so no model-issued
8
- * argument can smuggle a token into the human-form path. Creation and rotation have distinct
9
- * contracts: optional creation hints make a new row; target addresses an existing credential.
10
- */
11
- const credentialSaveCatalog = [{
12
- name: CREDENTIAL_SAVE_TOOL_ID,
13
- description: messages.description,
3
+ const KINDS = ['api', 'media-provider', 'source-control', 'publish-host', 'agent-plugin-token', 'plugin-provider', 'provider-settings'];
4
+ /** Model input carries non-secret metadata only. Schema additionalProperties is descriptive:
5
+ * selectSave and each domain handler enforce the allowed keys independently, so no model-issued
6
+ * argument can smuggle a token into the human-form path. Creation and rotation have distinct
7
+ * contracts: optional creation hints make a new row; target addresses an existing credential.
8
+ */
9
+ function buildCredentialSaveCatalog({ toolId, categories, description }) {
10
+ return [{
11
+ name: toolId,
12
+ description: description,
14
13
  sideEffects: 'mutates-durable-state',
15
14
  authorization: { permission: 'resolved-per-kind' },
16
15
  inputSchema: {
@@ -21,136 +20,144 @@ export function createCredentialSaveTools({ metadata: toolMetadata, toolId: CRED
21
20
  label: { type: 'string', description: 'Optional new API or source-control credential label; never a secret.' },
22
21
  baseUrl: { type: 'string', description: 'API creation only: non-secret base URL prefill.' },
23
22
  worksFor: { type: "array", items: { type: "string" }, description: "API creation only: explicit host or vendor IDs to preselect in the secure form." },
24
- category: { type: 'string', enum: [...CUSTOM_CREDENTIAL_CATEGORIES], description: 'API creation only: category prefill.' },
23
+ category: { type: 'string', enum: [...categories], description: 'API creation only: category prefill.' },
25
24
  reason: { type: 'string', maxLength: 1000, description: 'Media only: non-secret reason shown on the form.' },
26
25
  prefill: { type: 'object', additionalProperties: { type: 'string' }, description: 'Publish only: provider-declared non-secret credential fields. Never tokens, keys or passwords.' },
27
26
  },
28
27
  },
29
28
  }];
30
- const credentialSaveDerivedRisk = new Map([[CREDENTIAL_SAVE_TOOL_ID, 'mutates-durable-state']]);
31
- /** Select one domain owner without authorizing, opening a card, or inspecting secret fields.
32
- * @param required - Kind, non-secret metadata and injected domain handlers.
33
- * @returns The selected handler and its original input contract.
34
- * @throws ToolInputError for unknown kinds, cross-kind fields or malformed prefill.
35
- * @complexity Time/space O(k + f), input keys plus publish prefill fields.
36
- */
37
- function selectSave({ input, adapters }, _optional = {}) {
38
- const kind = requireString({ input, key: 'kind' });
39
- if (!KINDS.includes(kind))
40
- throw new ToolInputError({ message: 'Unknown credential kind. Use api, media-provider, source-control, publish-host, agent-plugin-token, plugin-provider or provider-settings.' });
41
- const selectedKind = kind;
42
- const { kind: _kind, ...metadata } = input;
43
- const targetOnly = ['plugin-provider', 'provider-settings'].includes(selectedKind);
44
- const providerFields = targetOnly ? ['target'] : ['target', 'prefill'];
45
- const fields = selectedKind === 'api'
46
- ? ['target', 'label', 'baseUrl', 'category', 'worksFor'] : providerFields;
47
- // A plugin card fixes its row on the server, so no label, base URL or category may ride along.
48
- const validateHere = selectedKind === 'publish-host' || targetOnly || (selectedKind === 'api' && !('target' in metadata));
49
- if (validateHere && Object.keys(metadata).some(key => !fields.includes(key))) {
50
- // Creation previously ignored unknown hints. Refuse them here; other owners already validate
51
- // their entire input and retain their exact per-kind errors. Never silently drop an extra key.
52
- throw new ToolInputError({ message: `${CREDENTIAL_SAVE_TOOL_ID} accepts only non-secret metadata for the selected kind; enter secrets in the human form.` });
53
- }
54
- return routeSave({ selectedKind, metadata, adapters });
29
+ }
30
+ /** Select one domain owner without authorizing, opening a card, or inspecting secret fields.
31
+ * @param required - Kind, non-secret metadata and injected domain handlers.
32
+ * @returns The selected handler and its original input contract.
33
+ * @throws ToolInputError for unknown kinds, cross-kind fields or malformed prefill.
34
+ * @complexity Time/space O(k + f), input keys plus publish prefill fields.
35
+ */
36
+ function selectSave({ input, adapters, toolId }, _optional = {}) {
37
+ const kind = requireString({ input, key: 'kind' });
38
+ if (!KINDS.includes(kind))
39
+ throw new ToolInputError({ message: 'Unknown credential kind. Use api, media-provider, source-control, publish-host, agent-plugin-token, plugin-provider or provider-settings.' });
40
+ const selectedKind = kind;
41
+ const { kind: _kind, ...metadata } = input;
42
+ const targetOnly = ['plugin-provider', 'provider-settings'].includes(selectedKind);
43
+ const providerFields = targetOnly ? ['target'] : ['target', 'prefill'];
44
+ const fields = selectedKind === 'api'
45
+ ? ['target', 'label', 'baseUrl', 'category', 'worksFor'] : providerFields;
46
+ // A plugin card fixes its row on the server, so no label, base URL or category may ride along.
47
+ const validateHere = selectedKind === 'publish-host' || targetOnly || (selectedKind === 'api' && !('target' in metadata));
48
+ if (validateHere && Object.keys(metadata).some(key => !fields.includes(key))) {
49
+ // Creation previously ignored unknown hints. Refuse them here; other owners already validate
50
+ // their entire input and retain their exact per-kind errors. Never silently drop an extra key.
51
+ throw new ToolInputError({ message: `${toolId} accepts only non-secret metadata for the selected kind; enter secrets in the human form.` });
55
52
  }
56
- function routeSave({ selectedKind, metadata, adapters }, _options = {}) {
57
- const { target: _target, ...hints } = metadata;
58
- // Forward the raw target under the owner's field name. Its validation retains the exact
59
- // per-kind error and ordering; a generic target validator would change both.
60
- switch (selectedKind) {
61
- case 'api': return selectApiSave({ metadata, hints, adapters });
62
- case 'media-provider':
63
- case 'source-control': return selectProviderSave({ selectedKind, metadata, hints, adapters });
64
- case 'agent-plugin-token': {
65
- if ('pluginId' in hints)
66
- throw new ToolInputError({ message: 'Use target for the installed plugin id.' });
67
- return { handler: adapters.agentPluginToken, input: { ...hints, pluginId: metadata.target } };
68
- }
69
- case 'publish-host': return selectPublishSave({ metadata, adapters });
70
- case 'provider-settings': return selectProviderSettingsSave({ adapters, target: metadata.target });
71
- case 'plugin-provider': return { handler: adapters.pluginProvider, input: { provider: metadata.target } };
72
- // selectSave refuses any kind outside KINDS before routing. The default protects the
73
- // internal boundary if a future caller bypasses that check.
74
- default: throw new ToolInputError({ message: 'Unknown credential kind.' });
53
+ return routeSave({ selectedKind, metadata, adapters });
54
+ }
55
+ function routeSave({ selectedKind, metadata, adapters }, _options = {}) {
56
+ const { target: _target, ...hints } = metadata;
57
+ // Forward the raw target under the owner's field name. Its validation retains the exact
58
+ // per-kind error and ordering; a generic target validator would change both.
59
+ switch (selectedKind) {
60
+ case 'api': return selectApiSave({ metadata, hints, adapters });
61
+ case 'media-provider':
62
+ case 'source-control': return selectProviderSave({ selectedKind, metadata, hints, adapters });
63
+ case 'agent-plugin-token': {
64
+ if ('pluginId' in hints)
65
+ throw new ToolInputError({ message: 'Use target for the installed plugin id.' });
66
+ return { handler: adapters.agentPluginToken, input: { ...hints, pluginId: metadata.target } };
75
67
  }
68
+ case 'publish-host': return selectPublishSave({ metadata, adapters });
69
+ case 'provider-settings': return selectProviderSettingsSave({ adapters, target: metadata.target });
70
+ case 'plugin-provider': return { handler: adapters.pluginProvider, input: { provider: metadata.target } };
71
+ // selectSave refuses any kind outside KINDS before routing. The default protects the
72
+ // internal boundary if a future caller bypasses that check.
73
+ default: throw new ToolInputError({ message: 'Unknown credential kind.' });
76
74
  }
77
- function selectProviderSettingsSave({ adapters, target }, _options = {}) {
78
- if (!adapters.providerSettings)
79
- throw new ToolInputError({ message: 'Provider settings are not available here.' });
80
- return { handler: adapters.providerSettings, input: { pluginId: target } };
81
- }
82
- /** Forward a provider target to its existing domain, retaining that domain's validation.
83
- * @throws ToolInputError on an attempted target override. @complexity O(k) metadata keys. */
84
- function selectProviderSave({ selectedKind, metadata, hints, adapters }, _options = {}) {
85
- if ('provider' in hints)
86
- throw new ToolInputError({ message: 'Use target for the credential provider.' });
87
- return { handler: selectedKind === 'media-provider' ? adapters.mediaProvider : adapters.sourceControl, input: { ...hints, provider: metadata.target } };
88
- }
89
- function selectApiSave({ metadata, hints, adapters }, _options = {}) {
90
- if (!('target' in metadata))
91
- return { handler: adapters.apiCreate, input: metadata };
92
- if ('label' in hints)
93
- throw new ToolInputError({ message: 'API token rotation accepts target rather than a creation label.' });
94
- return { handler: adapters.apiRotate, input: { ...hints, label: metadata.target } };
75
+ }
76
+ function selectProviderSettingsSave({ adapters, target }, _options = {}) {
77
+ if (!adapters.providerSettings)
78
+ throw new ToolInputError({ message: 'Provider settings are not available here.' });
79
+ return { handler: adapters.providerSettings, input: { pluginId: target } };
80
+ }
81
+ /** Forward a provider target to its existing domain, retaining that domain's validation.
82
+ * @throws ToolInputError on an attempted target override. @complexity O(k) metadata keys. */
83
+ function selectProviderSave({ selectedKind, metadata, hints, adapters }, _options = {}) {
84
+ if ('provider' in hints)
85
+ throw new ToolInputError({ message: 'Use target for the credential provider.' });
86
+ return { handler: selectedKind === 'media-provider' ? adapters.mediaProvider : adapters.sourceControl, input: { ...hints, provider: metadata.target } };
87
+ }
88
+ function selectApiSave({ metadata, hints, adapters }, _options = {}) {
89
+ if (!('target' in metadata))
90
+ return { handler: adapters.apiCreate, input: metadata };
91
+ if ('label' in hints)
92
+ throw new ToolInputError({ message: 'API token rotation accepts target rather than a creation label.' });
93
+ return { handler: adapters.apiRotate, input: { ...hints, label: metadata.target } };
94
+ }
95
+ function selectPublishSave({ metadata, adapters }, _options = {}) {
96
+ // requireInputRecord intentionally accepts arrays; publish prefill requires named fields.
97
+ if (Array.isArray(metadata.prefill))
98
+ throw new ToolInputError({ message: 'Credential prefill must be an object.' });
99
+ const prefill = metadata.prefill === undefined ? {} : requireInputRecord({ input: metadata.prefill });
100
+ // Keep the resolved target binding authoritative; provider validation owns all other field names.
101
+ if ('target' in prefill)
102
+ throw new ToolInputError({ message: 'Credential prefill cannot replace target.' });
103
+ return { handler: adapters.publishHost, input: { ...prefill, target: metadata.target } };
104
+ }
105
+ /** A declared destination reuses the existing permission, validation, probe and sealed-store owner. */
106
+ function routePluginCard({ card, selected, adapters, oauthRefusal }, _options = {}) {
107
+ if (!card)
108
+ return selected;
109
+ const target = card.saveTarget ?? card.providerId;
110
+ switch (card.saveKind) {
111
+ case 'publish-host': return { handler: adapters.publishHost, input: { target } };
112
+ case 'source-control': return { handler: adapters.sourceControl, input: { provider: target } };
113
+ case 'agent-plugin-token': return { handler: adapters.agentPluginToken, input: { pluginId: target } };
114
+ case 'provider-settings': return selectProviderSettingsSave({ adapters, target });
115
+ case 'oauth': throw new ToolInputError({ message: oauthRefusal });
116
+ default: return selected;
95
117
  }
96
- function selectPublishSave({ metadata, adapters }, _options = {}) {
97
- // requireInputRecord intentionally accepts arrays; publish prefill requires named fields.
98
- if (Array.isArray(metadata.prefill))
99
- throw new ToolInputError({ message: 'Credential prefill must be an object.' });
100
- const prefill = metadata.prefill === undefined ? {} : requireInputRecord({ input: metadata.prefill });
101
- // Keep the resolved target binding authoritative; provider validation owns all other field names.
102
- if ('target' in prefill)
103
- throw new ToolInputError({ message: 'Credential prefill cannot replace target.' });
104
- return { handler: adapters.publishHost, input: { ...prefill, target: metadata.target } };
118
+ }
119
+ /** Domain saves own the human exchange; one shared result hook attaches successful project saves. */
120
+ async function invokeSaveAdapter({ selected, ctx, options, savedResult }, _optional = {}) {
121
+ const result = await selected.handler({ ...ctx, input: selected.input }, options);
122
+ return savedResult ? savedResult({ result }) : result;
123
+ }
124
+ /** Route one save call to its domain owner; a plugin-provider save first resolves the plugin's declared card. */
125
+ async function runCredentialSave({ ctx, options, toolId, oauthRefusal, hooks }) {
126
+ const { adapters, loadPluginCredentialCards, authorizePluginProvider, adaptersForCards, savedResult } = hooks;
127
+ const selected = selectSave({ input: requireInputRecord({ input: ctx.input }), adapters, toolId });
128
+ if (selected.handler !== adapters.pluginProvider || !loadPluginCredentialCards) {
129
+ return invokeSaveAdapter({ selected, ctx, options, savedResult });
105
130
  }
106
- /** Register the sole credential save tool through the existing registry, forwarding options intact.
131
+ // A card can choose a domain, so require the entry permission before reading plugin data.
132
+ if (!authorizePluginProvider)
133
+ throw new ToolInputError({ message: 'Plugin credential card authorization is unavailable. Use the credential kind directly.' });
134
+ await authorizePluginProvider(ctx);
135
+ const cards = await loadPluginCredentialCardsSafely({ loadCards: loadPluginCredentialCards, workspaceId: '' });
136
+ const resolvedAdapters = adaptersForCards?.({ cards }) ?? adapters;
137
+ const card = cards.find(entry => entry.providerId === selected.input.provider);
138
+ const resolved = { ...selected, handler: resolvedAdapters.pluginProvider };
139
+ const routed = routePluginCard({ card, selected: resolved, adapters: resolvedAdapters, oauthRefusal });
140
+ const result = await routed.handler({ ...ctx, input: routed.input }, options);
141
+ return savedResult ? savedResult({ result }) : result;
142
+ }
143
+ /** @agent-note The host supplies its reviewed metadata, public tool id and credential categories. Save adapters keep authorization and persistence in that host. */
144
+ export function createCredentialSaveTools({ metadata: toolMetadata, toolId: CREDENTIAL_SAVE_TOOL_ID, categories: CUSTOM_CREDENTIAL_CATEGORIES, messages, catalogModule }, _optional = {}) {
145
+ const credentialSaveCatalog = buildCredentialSaveCatalog({ toolId: CREDENTIAL_SAVE_TOOL_ID, categories: CUSTOM_CREDENTIAL_CATEGORIES, description: messages.description });
146
+ const credentialSaveDerivedRisk = new Map([[CREDENTIAL_SAVE_TOOL_ID, 'mutates-durable-state']]);
147
+ /**
148
+ * Register the sole credential save tool through the existing registry, forwarding options intact.
107
149
  * @param required - Domain adapters, each retaining its own authorization, validation and save port.
108
150
  * @returns One registration; no executable aliases for the retired tools.
109
151
  * @example buildCredentialSaveRegistrations({ adapters });
110
152
  * @complexity Registration O(1); each invocation performs O(k + f) routing before one domain save.
111
153
  */
112
- function buildCredentialSaveRegistrations({ adapters, loadPluginCredentialCards, authorizePluginProvider, adaptersForCards, savedResult }, _optional = {}) {
154
+ function buildCredentialSaveRegistrations(hooks, _optional = {}) {
113
155
  return buildDomainRegistrations({ metadata: toolMetadata,
114
156
  domain: 'credential-save', catalogModule,
115
157
  catalog: indexCatalogById({ catalog: credentialSaveCatalog }), derivedRisk: credentialSaveDerivedRisk,
116
- handlers: { [CREDENTIAL_SAVE_TOOL_ID]: async (ctx, optional = {}) => {
117
- const selected = selectSave({ input: requireInputRecord({ input: ctx.input }), adapters });
118
- if (selected.handler !== adapters.pluginProvider || !loadPluginCredentialCards) {
119
- return invokeSaveAdapter({ selected, ctx, options: optional, savedResult });
120
- }
121
- // A card can choose a domain, so require the entry permission before reading plugin data.
122
- if (!authorizePluginProvider)
123
- throw new ToolInputError({ message: 'Plugin credential card authorization is unavailable. Use the credential kind directly.' });
124
- await authorizePluginProvider(ctx);
125
- const cards = await loadPluginCredentialCardsSafely({ loadCards: loadPluginCredentialCards, workspaceId: '' });
126
- const resolvedAdapters = adaptersForCards?.({ cards }) ?? adapters;
127
- const card = cards.find(entry => entry.providerId === selected.input.provider);
128
- const resolved = { ...selected, handler: resolvedAdapters.pluginProvider };
129
- const routed = routePluginCard({ card, selected: resolved, adapters: resolvedAdapters });
130
- const result = await routed.handler({ ...ctx, input: routed.input }, optional);
131
- return savedResult ? savedResult({ result }) : result;
132
- } },
158
+ handlers: { [CREDENTIAL_SAVE_TOOL_ID]: (ctx, optional = {}) => runCredentialSave({ ctx, options: optional, toolId: CREDENTIAL_SAVE_TOOL_ID, oauthRefusal: messages.oauthRefusal, hooks }) },
133
159
  });
134
160
  }
135
- /** A declared destination reuses the existing permission, validation, probe and sealed-store owner. */
136
- function routePluginCard({ card, selected, adapters }, _options = {}) {
137
- if (!card)
138
- return selected;
139
- const target = card.saveTarget ?? card.providerId;
140
- switch (card.saveKind) {
141
- case 'publish-host': return { handler: adapters.publishHost, input: { target } };
142
- case 'source-control': return { handler: adapters.sourceControl, input: { provider: target } };
143
- case 'agent-plugin-token': return { handler: adapters.agentPluginToken, input: { pluginId: target } };
144
- case 'provider-settings': return selectProviderSettingsSave({ adapters, target });
145
- case 'oauth': throw new ToolInputError({ message: messages.oauthRefusal });
146
- default: return selected;
147
- }
148
- }
149
- /** Domain saves own the human exchange; one shared result hook attaches successful project saves. */
150
- async function invokeSaveAdapter({ selected, ctx, options, savedResult }, _optional = {}) {
151
- const result = await selected.handler({ ...ctx, input: selected.input }, options);
152
- return savedResult ? savedResult({ result }) : result;
153
- }
154
161
  return { credentialSaveCatalog, credentialSaveDerivedRisk, buildCredentialSaveRegistrations };
155
162
  }
156
163
  //# sourceMappingURL=credential-save-tool.js.map
@@ -31,10 +31,10 @@ export declare function storedAgentPluginGrants({ row, projections }: {
31
31
  export declare function validatedAgentPluginToolGrant(required: {
32
32
  current: AgentPluginToolGrant;
33
33
  declared: AgentPluginDeclaredTools;
34
- }, options: {
35
- reason?: 'sign-in' | 'owner-enable';
36
34
  ports: AgentPluginMcpProjectionPorts;
37
35
  messages: Pick<AgentPluginEnableAccessMessages, 'combinedGrantRejected'>;
36
+ }, options?: {
37
+ reason?: 'sign-in' | 'owner-enable';
38
38
  }): AgentPluginToolGrant | null;
39
39
  /** Read only this plugin's declared rows before and after approval. No credentials enter the
40
40
  * card or fingerprint; the existing admission revision binds the source without copying secrets
@@ -14,8 +14,8 @@ export function storedAgentPluginGrants({ row, projections }, _options = {}) {
14
14
  * @throws ToolInputError with the store's validation reason (core-redacted) and a repair action.
15
15
  * @complexity O(a+w) names; no I/O or schema changes.
16
16
  */
17
- export function validatedAgentPluginToolGrant(required, options) {
18
- const ports = options.ports;
17
+ export function validatedAgentPluginToolGrant(required, options = {}) {
18
+ const ports = required.ports;
19
19
  const grant = planAgentPluginToolGrant(required, options);
20
20
  if (!grant)
21
21
  return null;
@@ -25,7 +25,7 @@ export function validatedAgentPluginToolGrant(required, options) {
25
25
  catch (error) {
26
26
  if (ports.classifyError({ error }) !== 'validation')
27
27
  throw error;
28
- throw new ToolInputError({ message: options.messages.combinedGrantRejected({ detail: redactSecrets({ input: error.message }, { redactPii: false }) }) });
28
+ throw new ToolInputError({ message: required.messages.combinedGrantRejected({ detail: redactSecrets({ input: error.message }, { redactPii: false }) }) });
29
29
  }
30
30
  }
31
31
  /** Check the exact source identity, rather than inheriting grants from an id collision. O(1). */
@@ -43,8 +43,8 @@ async function previewSource({ workspaceId, pluginId, source, servers, repo, por
43
43
  const row = await repo.findByServerId({ workspaceId, serverId: source.connectionId });
44
44
  assertPluginSource({ row, pluginId, source, messages });
45
45
  const current = storedAgentPluginGrants({ row, projections: ports.projections });
46
- const declared = findAgentPluginMcpServerDefaults(servers, { serverId: source.connectionId, url: source.url });
47
- const grant = declared ? validatedAgentPluginToolGrant({ current, declared }, { reason: 'owner-enable', ports, messages }) : null;
46
+ const declared = findAgentPluginMcpServerDefaults({ servers, row: { serverId: source.connectionId, url: source.url } });
47
+ const grant = declared ? validatedAgentPluginToolGrant({ current, declared, ports, messages }, { reason: 'owner-enable' }) : null;
48
48
  const snapshot = { pluginId, connectionId: source.connectionId, url: source.url, revision: row ? ports.projections.admissionRevision(row) : null, expected: row ? ports.projections.accessSnapshot({ record: row }) : null, current, declared, grant };
49
49
  const resource = grant ? { id: source.connectionId, label: `External MCP source: ${redactSecrets({ input: source.url }, { redactPii: false })}`, previous: current, proposed: grant, revision: snapshot.revision } : null;
50
50
  return { snapshot, resource };
@@ -58,7 +58,7 @@ async function previewSource({ workspaceId, pluginId, source, servers, repo, por
58
58
  */
59
59
  export async function previewAgentPluginEnableAccess({ workspaceId, pluginId, servers, repo, classifyTrust, messages, ...context }, _options = {}) {
60
60
  const ports = { projections: context.projections, classifyError: context.classifyError };
61
- const planned = planAgentPluginMcpFederation({ servers }, { classifyTrust, messages });
61
+ const planned = planAgentPluginMcpFederation({ servers, classifyTrust, messages });
62
62
  if (planned.skipped.length)
63
63
  throw new ToolInputError({ message: `The plugin connection cannot be enabled here: ${planned.skipped.map(entry => `${entry.serverKey}: ${entry.reason}`).join('; ')}` });
64
64
  const snapshots = [];