@jini-ai/agent-plugins 0.6.23 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +13 -0
  3. package/calendly/exports/booking-calendar.css +7 -0
  4. package/calendly/exports/booking-calendar.html +5 -0
  5. package/calendly/mcp.json +10 -0
  6. package/calendly/plugin.json +47 -0
  7. package/calendly/skills/calendly/SKILL.md +27 -0
  8. package/charts-echarts/plugin.json +2 -2
  9. package/charts-recharts/plugin.json +2 -2
  10. package/cloudflare/lib/cms-forms.mjs +57 -0
  11. package/cloudflare/lib/forms.mjs +78 -18
  12. package/cloudflare/lib/target.mjs +17 -4
  13. package/cloudflare/plugin.json +2 -2
  14. package/cloudflare/skills/cloudflare/SKILL.md +4 -4
  15. package/cloudflare/skills/cloudflare/references/workers.md +4 -4
  16. package/cloudflare/worker/forms-receiver.mjs +81 -41
  17. package/cloudflare/worker/portable-validation.mjs +220 -0
  18. package/commerce/plugin.json +17 -0
  19. package/commerce/skills/commerce/SKILL.md +23 -0
  20. package/composio/mcp.json +1 -1
  21. package/composio/plugin.json +2 -2
  22. package/composio/skills/composio/SKILL.md +4 -4
  23. package/core/commerce-server.d.ts +2 -0
  24. package/core/commerce-server.mjs +2 -0
  25. package/dist/admin-surfaces/connections/connections.d.ts +35 -0
  26. package/dist/admin-surfaces/connections/connections.js +135 -0
  27. package/dist/admin-surfaces/connections/index.d.ts +3 -0
  28. package/dist/admin-surfaces/connections/index.js +2 -0
  29. package/dist/admin-surfaces/connections/ports.d.ts +110 -0
  30. package/dist/admin-surfaces/connections/ports.js +2 -0
  31. package/dist/admin-surfaces/index.d.ts +2 -0
  32. package/dist/admin-surfaces/index.js +1 -0
  33. package/dist/admin-surfaces/plugin-state-persistence.d.ts +27 -0
  34. package/dist/admin-surfaces/plugin-state-persistence.js +2 -0
  35. package/dist/admin-surfaces/plugin-state.d.ts +51 -0
  36. package/dist/admin-surfaces/plugin-state.js +106 -0
  37. package/dist/connect/access-token-tool.d.ts +240 -0
  38. package/dist/connect/access-token-tool.js +213 -0
  39. package/dist/connect/apply-connect-defaults.d.ts +91 -0
  40. package/dist/connect/apply-connect-defaults.js +113 -0
  41. package/dist/connect/apply-tool-renames.d.ts +72 -0
  42. package/dist/connect/apply-tool-renames.js +105 -0
  43. package/dist/connect/connect-card-ui.d.ts +143 -0
  44. package/dist/connect/connect-card-ui.js +106 -0
  45. package/dist/connect/connect-destination.d.ts +35 -0
  46. package/dist/connect/connect-destination.js +45 -0
  47. package/dist/connect/connect-sign-in-wait.d.ts +31 -0
  48. package/dist/connect/connect-sign-in-wait.js +21 -0
  49. package/dist/connect/connect-tool.d.ts +314 -0
  50. package/dist/connect/connect-tool.js +431 -0
  51. package/dist/connect/connection-status.d.ts +33 -0
  52. package/dist/connect/connection-status.js +63 -0
  53. package/dist/connect/credential-cards.d.ts +15 -0
  54. package/dist/connect/credential-cards.js +49 -0
  55. package/dist/connect/credential-save-tool.d.ts +45 -0
  56. package/dist/connect/credential-save-tool.js +156 -0
  57. package/dist/connect/enable-access.d.ts +67 -0
  58. package/dist/connect/enable-access.js +74 -0
  59. package/dist/connect/executable/approval.d.ts +58 -0
  60. package/dist/connect/executable/approval.js +40 -0
  61. package/dist/connect/executable/host-capabilities.d.ts +76 -0
  62. package/dist/connect/executable/host-capabilities.js +100 -0
  63. package/dist/connect/executable/index.d.ts +10 -0
  64. package/dist/connect/executable/index.js +9 -0
  65. package/dist/connect/executable/ports.d.ts +189 -0
  66. package/dist/connect/executable/ports.js +2 -0
  67. package/dist/connect/executable/register.d.ts +21 -0
  68. package/dist/connect/executable/register.js +125 -0
  69. package/dist/connect/federate-mcp.d.ts +190 -0
  70. package/dist/connect/federate-mcp.js +440 -0
  71. package/dist/connect/grant-signed-in-defaults.d.ts +96 -0
  72. package/dist/connect/grant-signed-in-defaults.js +100 -0
  73. package/dist/connect/import-access-token.d.ts +114 -0
  74. package/dist/connect/import-access-token.js +103 -0
  75. package/dist/connect/index.d.ts +19 -0
  76. package/dist/connect/index.js +19 -0
  77. package/dist/connect/plugin-credential-card.d.ts +46 -0
  78. package/dist/connect/plugin-credential-card.js +63 -0
  79. package/dist/connect/plugin-host/index.d.ts +203 -0
  80. package/dist/connect/plugin-host/index.js +153 -0
  81. package/dist/connect/ports.d.ts +74 -0
  82. package/dist/connect/ports.js +2 -0
  83. package/dist/connect/switch-on-saved-token.d.ts +48 -0
  84. package/dist/connect/switch-on-saved-token.js +20 -0
  85. package/dist/connect/token-sign-in.d.ts +51 -0
  86. package/dist/connect/token-sign-in.js +43 -0
  87. package/dist/core/identity-namespace.d.ts +39 -0
  88. package/dist/core/identity-namespace.js +61 -3
  89. package/dist/folder-zip-node.js +3 -1
  90. package/dist/lifecycle/automatic-use.d.ts +12 -7
  91. package/dist/lifecycle/automatic-use.js +37 -28
  92. package/dist/lifecycle/capability-projection.js +5 -1
  93. package/dist/lifecycle/contribution-loader.d.ts +2 -7
  94. package/dist/lifecycle/contribution-types.d.ts +8 -0
  95. package/dist/lifecycle/contribution-types.js +2 -0
  96. package/dist/lifecycle/credential-card-metadata.d.ts +23 -0
  97. package/dist/lifecycle/credential-card-metadata.js +184 -0
  98. package/dist/lifecycle/exports.d.ts +11 -0
  99. package/dist/lifecycle/exports.js +64 -3
  100. package/dist/lifecycle/host-tools/identity.d.ts +38 -0
  101. package/dist/lifecycle/host-tools/identity.js +58 -0
  102. package/dist/lifecycle/host-tools/index.d.ts +20 -0
  103. package/dist/lifecycle/host-tools/index.js +20 -0
  104. package/dist/lifecycle/host-tools/memory-tools.d.ts +22 -0
  105. package/dist/lifecycle/host-tools/memory-tools.js +63 -0
  106. package/dist/lifecycle/host-tools/ports.d.ts +121 -0
  107. package/dist/lifecycle/host-tools/ports.js +2 -0
  108. package/dist/lifecycle/host-tools/provider-status-tool.d.ts +88 -0
  109. package/dist/lifecycle/host-tools/provider-status-tool.js +45 -0
  110. package/dist/lifecycle/host-tools/search-tool.d.ts +74 -0
  111. package/dist/lifecycle/host-tools/search-tool.js +282 -0
  112. package/dist/lifecycle/host-tools/skill-tool.d.ts +219 -0
  113. package/dist/lifecycle/host-tools/skill-tool.js +482 -0
  114. package/dist/lifecycle/host-tools/write-note-tool.d.ts +22 -0
  115. package/dist/lifecycle/host-tools/write-note-tool.js +47 -0
  116. package/dist/lifecycle/index.d.ts +2 -1
  117. package/dist/lifecycle/install.js +2 -1
  118. package/dist/lifecycle/installed-package-index.js +5 -8
  119. package/dist/lifecycle/mail/adapter-descriptors.d.ts +78 -0
  120. package/dist/lifecycle/mail/adapter-descriptors.js +155 -0
  121. package/dist/lifecycle/mail/catalog.d.ts +116 -0
  122. package/dist/lifecycle/mail/catalog.js +72 -0
  123. package/dist/lifecycle/mail/configuration.d.ts +25 -0
  124. package/dist/lifecycle/mail/configuration.js +62 -0
  125. package/dist/lifecycle/mail/contribution.d.ts +89 -0
  126. package/dist/lifecycle/mail/contribution.js +115 -0
  127. package/dist/lifecycle/mail/host-mailer.d.ts +24 -0
  128. package/dist/lifecycle/mail/host-mailer.js +10 -0
  129. package/dist/lifecycle/mail/index.d.ts +16 -0
  130. package/dist/lifecycle/mail/index.js +16 -0
  131. package/dist/lifecycle/mail/selection.d.ts +40 -0
  132. package/dist/lifecycle/mail/selection.js +86 -0
  133. package/dist/lifecycle/manifest.d.ts +7 -2
  134. package/dist/lifecycle/manifest.js +32 -9
  135. package/dist/lifecycle/metadata.d.ts +31 -0
  136. package/dist/lifecycle/metadata.js +80 -0
  137. package/dist/lifecycle/persistent-state.js +2 -1
  138. package/dist/lifecycle/ports.d.ts +2 -0
  139. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -1
  140. package/dist/lifecycle/resolve-agent-plugin-refs.js +14 -8
  141. package/dist/lifecycle/search-projection.d.ts +3 -4
  142. package/dist/lifecycle/search-projection.js +5 -7
  143. package/dist/lifecycle/search.js +3 -2
  144. package/fly/plugin.json +5 -5
  145. package/fly/skills/fly/SKILL.md +1 -1
  146. package/formspree/plugin.json +7 -0
  147. package/formspree/skills/formspree/SKILL.md +11 -0
  148. package/github/plugin.json +2 -2
  149. package/github/skills/github/SKILL.md +28 -28
  150. package/github/skills/github/references/actions.md +8 -8
  151. package/github/skills/github/references/auth-and-tokens.md +7 -7
  152. package/github/skills/github/references/repo-files.md +5 -5
  153. package/github/skills/github/references/site-backup.md +16 -16
  154. package/github/skills/github/references/source-control.md +17 -17
  155. package/github-pages/plugin.json +2 -2
  156. package/github-pages/skills/github-pages/SKILL.md +3 -3
  157. package/google-forms/plugin.json +7 -0
  158. package/google-forms/skills/google-forms/SKILL.md +15 -0
  159. package/google-login/plugin.json +3 -3
  160. package/google-login/skills/google-login/SKILL.md +17 -60
  161. package/google-workspace/plugin.json +6 -6
  162. package/google-workspace/skills/google-workspace/references/connection.md +1 -1
  163. package/google-workspace/skills/google-workspace/references/form-delivery.md +4 -4
  164. package/google-workspace/tovu-admin-surfaces.json +5 -5
  165. package/higgsfield-media/plugin.json +5 -5
  166. package/higgsfield-media/skills/higgsfield-media/SKILL.md +31 -33
  167. package/higgsfield-media/skills/higgsfield-media/references/failure-modes.md +7 -7
  168. package/higgsfield-media/skills/higgsfield-media/references/models-and-plan-gates.md +3 -3
  169. package/jev/plugin.json +2 -2
  170. package/langfuse/plugin.json +2 -2
  171. package/meilisearch/plugin.json +2 -2
  172. package/meilisearch/skills/meilisearch/SKILL.md +1 -1
  173. package/netlify/plugin.json +2 -2
  174. package/netlify/skills/netlify/SKILL.md +3 -3
  175. package/opentelemetry/plugin.json +2 -2
  176. package/opentelemetry/skills/opentelemetry/SKILL.md +7 -7
  177. package/package.json +92 -14
  178. package/posthog/plugin.json +2 -2
  179. package/posthog/skills/posthog/SKILL.md +7 -7
  180. package/railway/plugin.json +3 -3
  181. package/railway/skills/railway/SKILL.md +10 -11
  182. package/render/plugin.json +3 -3
  183. package/render/skills/render/SKILL.md +7 -8
  184. package/resend/NOTES.md +2 -2
  185. package/resend/mcp.json +1 -1
  186. package/resend/plugin.json +5 -5
  187. package/resend/skills/resend/SKILL.md +13 -13
  188. package/s3-compatible/plugin.json +2 -2
  189. package/s3-compatible/skills/s3-compatible/SKILL.md +4 -4
  190. package/sentry/plugin.json +2 -2
  191. package/sentry/skills/sentry/SKILL.md +7 -7
  192. package/shopify/plugin.json +2 -2
  193. package/site-compliance/plugin.json +2 -2
  194. package/site-compliance/skills/site-compliance/SKILL.md +3 -3
  195. package/site-compliance/skills/site-compliance/references/gdpr-eu-uk.md +1 -1
  196. package/site-import/plugin.json +2 -2
  197. package/slide-design/plugin.json +2 -2
  198. package/software-engineering/LICENSE +201 -0
  199. package/software-engineering/NOTICE +9 -0
  200. package/software-engineering/README.md +89 -0
  201. package/software-engineering/plugin.json +24 -0
  202. package/software-engineering/skills/software-engineering/SKILL.md +33 -0
  203. package/software-engineering/skills/software-engineering/references/debugging.md +54 -0
  204. package/software-engineering/skills/software-engineering/references/implementation.md +27 -0
  205. package/software-engineering/skills/software-engineering/references/planning.md +27 -0
  206. package/software-engineering/skills/software-engineering/references/prototyping.md +14 -0
  207. package/software-engineering/skills/software-engineering/references/security.md +47 -0
  208. package/software-engineering/skills/software-engineering/references/verification.md +53 -0
  209. package/stripe/plugin.json +2 -2
  210. package/supabase/mcp.json +4 -4
  211. package/supabase/plugin.json +3 -3
  212. package/supabase/skills/supabase/SKILL.md +8 -8
  213. package/supabase/skills/supabase/references/failure-modes.md +5 -5
  214. package/ui-ux-design/plugin.json +2 -2
  215. package/vercel/plugin.json +2 -2
  216. package/vercel/skills/vercel/SKILL.md +3 -3
  217. package/wordpress/plugin.json +2 -2
  218. package/wordpress/skills/wordpress/SKILL.md +3 -3
  219. package/wordpress/skills/wordpress/references/free-site-redirect.md +2 -2
  220. package/wordpress/skills/wordpress/references/subdomain.md +5 -5
@@ -0,0 +1,156 @@
1
+ import { loadPluginCredentialCardsSafely } from "./plugin-credential-card.js";
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,
14
+ sideEffects: 'mutates-durable-state',
15
+ authorization: { permission: 'resolved-per-kind' },
16
+ inputSchema: {
17
+ type: 'object', additionalProperties: false, required: ['kind'],
18
+ properties: {
19
+ kind: { type: 'string', enum: [...KINDS] },
20
+ target: { type: 'string', minLength: 1, description: 'Existing API credential label to rotate, media/source-control/publish/plugin provider id, or installed plugin id.' },
21
+ label: { type: 'string', description: 'Optional new API or source-control credential label; never a secret.' },
22
+ baseUrl: { type: 'string', description: 'API creation only: non-secret base URL prefill.' },
23
+ 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.' },
25
+ reason: { type: 'string', maxLength: 1000, description: 'Media only: non-secret reason shown on the form.' },
26
+ prefill: { type: 'object', additionalProperties: { type: 'string' }, description: 'Publish only: provider-declared non-secret credential fields. Never tokens, keys or passwords.' },
27
+ },
28
+ },
29
+ }];
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 });
55
+ }
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.' });
75
+ }
76
+ }
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 } };
95
+ }
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 } };
105
+ }
106
+ /** Register the sole credential save tool through the existing registry, forwarding options intact.
107
+ * @param required - Domain adapters, each retaining its own authorization, validation and save port.
108
+ * @returns One registration; no executable aliases for the retired tools.
109
+ * @example buildCredentialSaveRegistrations({ adapters });
110
+ * @complexity Registration O(1); each invocation performs O(k + f) routing before one domain save.
111
+ */
112
+ function buildCredentialSaveRegistrations({ adapters, loadPluginCredentialCards, authorizePluginProvider, adaptersForCards, savedResult }, _optional = {}) {
113
+ return buildDomainRegistrations({ metadata: toolMetadata,
114
+ domain: 'credential-save', catalogModule,
115
+ 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
+ } },
133
+ });
134
+ }
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
+ return { credentialSaveCatalog, credentialSaveDerivedRisk, buildCredentialSaveRegistrations };
155
+ }
156
+ //# sourceMappingURL=credential-save-tool.js.map
@@ -0,0 +1,67 @@
1
+ /** Bind Jini's grant plan to the existing external-MCP rows and plugin enable card. */
2
+ import { type AccessApprovalResource } from '@jini-ai/core';
3
+ import { type AgentPluginToolGrant, type AgentPluginDeclaredTools } from '../lifecycle/enable-grants.js';
4
+ import type { AgentPluginMcpRecord, AgentPluginMcpProjectionPorts, AgentPluginMcpProjections } from './ports.js';
5
+ import type { AgentPluginMcpPort } from './ports.js';
6
+ import { type AgentPluginMcpFederationMessages, type AgentPluginMcpTrustClassifier } from './federate-mcp.js';
7
+ import type { McpServerConfig } from '../lifecycle/manifest.js';
8
+ /** @agent-note Product copy for the enable preview's refusals. Host input: the text names the host's own
9
+ * settings screen; it must not echo a token (the connection id and nothing secret are passed). */
10
+ export interface AgentPluginEnableAccessMessages extends AgentPluginMcpFederationMessages {
11
+ /** @agent-note Host repair copy for a refused combined grant. Detail is already core-redacted;
12
+ * name your own selection tool or screen, never include credential material. */
13
+ combinedGrantRejected(required: {
14
+ readonly detail: string;
15
+ }): string;
16
+ /** The row was configured separately or points somewhere else; its saved sign-in was kept. */
17
+ sourceConfiguredSeparately(required: {
18
+ readonly connectionId: string;
19
+ }): string;
20
+ }
21
+ /** Translate persisted host columns to Jini's grant contract. O(n) in stored list bytes; no I/O. */
22
+ export declare function storedAgentPluginGrants({ row, projections }: {
23
+ row: Pick<AgentPluginMcpRecord, 'enabled' | 'allowedToolNames' | 'writeAllowedToolNames'> | null;
24
+ projections: AgentPluginMcpProjections;
25
+ }, _options?: {}): AgentPluginToolGrant;
26
+ /** Bind Jini's grant decision to the existing store's name and 64-tool bounds before card/write.
27
+ * Production callers pass the composed ports; only a host's legacy no-ports signature binds that host's pair.
28
+ * @throws ToolInputError with the store's validation reason (core-redacted) and a repair action.
29
+ * @complexity O(a+w) names; no I/O or schema changes.
30
+ */
31
+ export declare function validatedAgentPluginToolGrant(required: {
32
+ current: AgentPluginToolGrant;
33
+ declared: AgentPluginDeclaredTools;
34
+ }, options: {
35
+ reason?: 'sign-in' | 'owner-enable';
36
+ ports: AgentPluginMcpProjectionPorts;
37
+ messages: Pick<AgentPluginEnableAccessMessages, 'combinedGrantRejected'>;
38
+ }): AgentPluginToolGrant | null;
39
+ /** Read only this plugin's declared rows before and after approval. No credentials enter the
40
+ * card or fingerprint; the existing admission revision binds the source without copying secrets
41
+ * or making an ordinary OAuth token refresh invalidate an otherwise unchanged approval.
42
+ * @returns Exact resulting access and a stable comparison key for the existing approval identity.
43
+ * @throws ToolInputError for a conflicting endpoint/owner or unsupported declaration.
44
+ * @complexity O(s*(a+w)) in declared servers and tool lists; s point reads, no network calls.
45
+ */
46
+ export declare function previewAgentPluginEnableAccess({ workspaceId, pluginId, servers, repo, classifyTrust, messages, ...context }: AgentPluginMcpProjectionPorts & {
47
+ workspaceId: string;
48
+ pluginId: string;
49
+ servers: Readonly<Record<string, McpServerConfig>>;
50
+ repo: AgentPluginMcpPort['repo'];
51
+ classifyTrust: AgentPluginMcpTrustClassifier;
52
+ messages: AgentPluginEnableAccessMessages;
53
+ }, _options?: {}): Promise<{
54
+ key: string;
55
+ snapshots: {
56
+ pluginId: string;
57
+ connectionId: string;
58
+ url: string;
59
+ revision: string | null;
60
+ expected: import("@jini-ai/core/contracts/hosted-mcp").ExternalMcpAccessSnapshot | null;
61
+ current: AgentPluginToolGrant;
62
+ declared: import("../lifecycle/manifest.js").AgentPluginDefaultTools | null;
63
+ grant: AgentPluginToolGrant | null;
64
+ }[];
65
+ resources: Omit<AccessApprovalResource, "scope">[];
66
+ }>;
67
+ //# sourceMappingURL=enable-access.d.ts.map
@@ -0,0 +1,74 @@
1
+ /** Bind Jini's grant plan to the existing external-MCP rows and plugin enable card. */
2
+ import { ToolInputError, redactSecrets } from '@jini-ai/core';
3
+ import { planAgentPluginToolGrant } from '../lifecycle/enable-grants.js';
4
+ import { findAgentPluginMcpServerDefaults, planAgentPluginMcpFederation } from './federate-mcp.js';
5
+ /** Translate persisted host columns to Jini's grant contract. O(n) in stored list bytes; no I/O. */
6
+ export function storedAgentPluginGrants({ row, projections }, _options = {}) {
7
+ if (!row)
8
+ return { enabled: false, allow: [], write: [] };
9
+ const grants = projections.readToolGrants(row, { strict: true });
10
+ return { enabled: row.enabled, allow: grants.allowedToolNames, write: grants.writeAllowedToolNames };
11
+ }
12
+ /** Bind Jini's grant decision to the existing store's name and 64-tool bounds before card/write.
13
+ * Production callers pass the composed ports; only a host's legacy no-ports signature binds that host's pair.
14
+ * @throws ToolInputError with the store's validation reason (core-redacted) and a repair action.
15
+ * @complexity O(a+w) names; no I/O or schema changes.
16
+ */
17
+ export function validatedAgentPluginToolGrant(required, options) {
18
+ const ports = options.ports;
19
+ const grant = planAgentPluginToolGrant(required, options);
20
+ if (!grant)
21
+ return null;
22
+ try {
23
+ return { enabled: true, allow: ports.projections.validateToolNames({ names: grant.allow, field: 'allowedToolNames' }), write: ports.projections.validateToolNames({ names: grant.write, field: 'writeAllowedToolNames' }) };
24
+ }
25
+ catch (error) {
26
+ if (ports.classifyError({ error }) !== 'validation')
27
+ throw error;
28
+ throw new ToolInputError({ message: options.messages.combinedGrantRejected({ detail: redactSecrets({ input: error.message }, { redactPii: false }) }) });
29
+ }
30
+ }
31
+ /** Check the exact source identity, rather than inheriting grants from an id collision. O(1). */
32
+ function assertPluginSource({ row, pluginId, source, messages }) {
33
+ if (!row)
34
+ return;
35
+ const declaredSignIn = row.authMode === source.authMode || (source.acceptsAccessToken && row.authMode === 'static_env');
36
+ const matchesOwner = row.provisionedByPluginId === null || row.provisionedByPluginId === pluginId;
37
+ if (matchesOwner && row.url === source.url && row.transport === 'streamable_http' && declaredSignIn)
38
+ return;
39
+ throw new ToolInputError({ message: messages.sourceConfiguredSeparately({ connectionId: source.connectionId }) });
40
+ }
41
+ /** One indexed row lookup, with the same Jini grant decision used by the writer. O(a+w). */
42
+ async function previewSource({ workspaceId, pluginId, source, servers, repo, ports, messages }) {
43
+ const row = await repo.findByServerId({ workspaceId, serverId: source.connectionId });
44
+ assertPluginSource({ row, pluginId, source, messages });
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;
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
+ 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
+ return { snapshot, resource };
51
+ }
52
+ /** Read only this plugin's declared rows before and after approval. No credentials enter the
53
+ * card or fingerprint; the existing admission revision binds the source without copying secrets
54
+ * or making an ordinary OAuth token refresh invalidate an otherwise unchanged approval.
55
+ * @returns Exact resulting access and a stable comparison key for the existing approval identity.
56
+ * @throws ToolInputError for a conflicting endpoint/owner or unsupported declaration.
57
+ * @complexity O(s*(a+w)) in declared servers and tool lists; s point reads, no network calls.
58
+ */
59
+ export async function previewAgentPluginEnableAccess({ workspaceId, pluginId, servers, repo, classifyTrust, messages, ...context }, _options = {}) {
60
+ const ports = { projections: context.projections, classifyError: context.classifyError };
61
+ const planned = planAgentPluginMcpFederation({ servers }, { classifyTrust, messages });
62
+ if (planned.skipped.length)
63
+ throw new ToolInputError({ message: `The plugin connection cannot be enabled here: ${planned.skipped.map(entry => `${entry.serverKey}: ${entry.reason}`).join('; ')}` });
64
+ const snapshots = [];
65
+ const resources = [];
66
+ for (const source of planned.toUpsert) {
67
+ const preview = await previewSource({ workspaceId, pluginId, source, servers, repo, ports, messages });
68
+ snapshots.push(preview.snapshot);
69
+ if (preview.resource)
70
+ resources.push(preview.resource);
71
+ }
72
+ return { key: JSON.stringify(snapshots), snapshots, resources };
73
+ }
74
+ //# sourceMappingURL=enable-access.js.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @file How an executable Agent Plugin tool call is confirmed by the host, on the EXISTING approval
3
+ * owner (`assistant/assistant-tool-approval-policy.ts` families + `applyToolApprovalPolicy`).
4
+ * No second confirmation engine: this file only maps the plugin's declared effect to a reviewed
5
+ * family and computes the card's extra rows.
6
+ *
7
+ * Before a write or destructive call is shown, the disclosure step freezes what the human approves:
8
+ * the approval owner has already detached the input (request + target); this step reads the
9
+ * account each of the call's connections is signed in as and binds them all to the call, so
10
+ * execution refuses if a connection was switched to another account meanwhile, or if the call asks
11
+ * for a connection its approval did not show. Which connections a call has is the projection's
12
+ * answer (its validated top-level `connectionRef`), never a walk over the arguments here. Activation and authorization are rechecked by the
13
+ * plugin tool contract right before the handler runs.
14
+ */
15
+ import type { SurfaceCardDetail as SurfaceDetail } from '@jini-ai/core/contracts/cards';
16
+ import type { AgentPluginConnectionAccess, AgentPluginDisclosureMessages, FrozenConnectionAccounts } from './ports.js';
17
+ import type { ToolExecutionContext } from '@jini-ai/core';
18
+ import type { AgentPluginToolDisclosure } from '../../lifecycle/tools/projection.js';
19
+ /** The approval family each declared effect maps to (see the families' own comment). */
20
+ export declare const APPROVAL_FAMILY_BY_EFFECT: {
21
+ readonly read: "agent-plugin-read";
22
+ readonly write: "agent-plugin-write";
23
+ readonly destructive: "agent-plugin-destructive";
24
+ };
25
+ /** The projection's disclosure entry point (`createAgentPluginToolProjection().describeAffectedResources`). */
26
+ export interface AgentPluginDisclosureSource {
27
+ describeAffectedResources(required: {
28
+ readonly toolId: string;
29
+ readonly input: unknown;
30
+ }, optional?: Record<string, never>): Promise<AgentPluginToolDisclosure | null>;
31
+ }
32
+ /**
33
+ * Builds the card rows for one confirming call and freezes its account.
34
+ * @param required.source - The projection (validates input, asks the plugin what would change).
35
+ * @param required.connections - Host connection accessor, scoped to the calling plugin and workspace.
36
+ * @param required.frozen - Where the frozen accounts are bound for the capability port to enforce.
37
+ * @returns `disclose({ ctx, toolId, pluginId, workspaceId })` → one Account row per connection the call
38
+ * may use (the projection's `connections`, the same set Jini's capability session enforces) + one row
39
+ * per affected resource. The accounts are always bound, even when empty: a call naming no connection
40
+ * is then refused any token at execution.
41
+ * @throws Error when the tool was withdrawn or a connection is not connected (unless `skipUnconnected`:
42
+ * an admin action may sign one in, and an unconnected connection, left unbound, gets no token); ToolInputError for bad input.
43
+ * @complexity O(c + r) rows plus one disclosure hook call and one account read per connection.
44
+ */
45
+ export declare function createAgentPluginDisclosure(required: {
46
+ readonly source: AgentPluginDisclosureSource;
47
+ readonly connections: AgentPluginConnectionAccess;
48
+ readonly frozen: FrozenConnectionAccounts;
49
+ readonly messages: AgentPluginDisclosureMessages;
50
+ }, _optional?: Record<string, never>): ({ ctx, toolId, pluginId, workspaceId }: {
51
+ readonly ctx: ToolExecutionContext;
52
+ readonly toolId: string;
53
+ readonly pluginId: string;
54
+ readonly workspaceId: string;
55
+ }, optional?: {
56
+ readonly skipUnconnected?: boolean;
57
+ }) => Promise<readonly SurfaceDetail[]>;
58
+ //# sourceMappingURL=approval.d.ts.map
@@ -0,0 +1,40 @@
1
+ /** The approval family each declared effect maps to (see the families' own comment). */
2
+ export const APPROVAL_FAMILY_BY_EFFECT = {
3
+ read: 'agent-plugin-read', write: 'agent-plugin-write', destructive: 'agent-plugin-destructive',
4
+ };
5
+ /**
6
+ * Builds the card rows for one confirming call and freezes its account.
7
+ * @param required.source - The projection (validates input, asks the plugin what would change).
8
+ * @param required.connections - Host connection accessor, scoped to the calling plugin and workspace.
9
+ * @param required.frozen - Where the frozen accounts are bound for the capability port to enforce.
10
+ * @returns `disclose({ ctx, toolId, pluginId, workspaceId })` → one Account row per connection the call
11
+ * may use (the projection's `connections`, the same set Jini's capability session enforces) + one row
12
+ * per affected resource. The accounts are always bound, even when empty: a call naming no connection
13
+ * is then refused any token at execution.
14
+ * @throws Error when the tool was withdrawn or a connection is not connected (unless `skipUnconnected`:
15
+ * an admin action may sign one in, and an unconnected connection, left unbound, gets no token); ToolInputError for bad input.
16
+ * @complexity O(c + r) rows plus one disclosure hook call and one account read per connection.
17
+ */
18
+ export function createAgentPluginDisclosure(required, _optional = {}) {
19
+ return async ({ ctx, toolId, pluginId, workspaceId }, optional = {}) => {
20
+ const disclosure = await required.source.describeAffectedResources({ toolId, input: ctx.input });
21
+ if (!disclosure)
22
+ throw new Error(required.messages.withdrawn);
23
+ const rows = [];
24
+ const accounts = new Map();
25
+ for (const connectionRef of disclosure.connections) {
26
+ const account = await required.connections.readAccount({ workspaceId, pluginId, connectionRef });
27
+ if (!account && optional.skipUnconnected)
28
+ continue;
29
+ if (!account)
30
+ throw new Error(required.messages.notConnected);
31
+ accounts.set(connectionRef, account.accountId);
32
+ rows.push({ label: required.messages.accountLabel, value: account.displayName });
33
+ }
34
+ required.frozen.bind({ signal: ctx.signal, accounts });
35
+ for (const resource of disclosure.resources)
36
+ rows.push({ label: required.messages.affectsLabel, value: resource });
37
+ return rows;
38
+ };
39
+ }
40
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @file Host-scoped implementation of the capability ports an executable Agent Plugin tool receives
3
+ * (`AgentPluginToolCapabilitiesPort` from `@jini-ai/agent-plugins/lifecycle/tools`).
4
+ *
5
+ * Exists so plugin code is never handed a credential store, a raw network client or another plugin's
6
+ * budget: every capability is scoped here to the calling plugin and workspace. That is a scope, not a
7
+ * sandbox: plugin code runs in this process with the site's own access (`globalThis.fetch`, the
8
+ * environment), so it is trusted first-party code. The boundaries that hold are against the model's
9
+ * tool arguments: Jini's ref binding, the account frozen at confirmation (below) and the token scan on
10
+ * results and errors. Third-party executable plugins need a process sandbox first.
11
+ * - connections: delegated to the host's connection accessor, always with the calling plugin and
12
+ * workspace, so a plugin can only reach its own connections in this workspace. Jini's capability
13
+ * session already refuses any ref but the call's own top-level `connectionRef`; when the call was
14
+ * confirmed, the account shown on the card is required too (a switched account is refused).
15
+ * - http: the guarded outbound client (public addresses only, no redirects), HTTPS only, bounded,
16
+ * and only to the https origins the calling plugin's connections declare (`apiOrigins`), so a URL
17
+ * built from tool input can never carry the plugin's bearer token to another host.
18
+ * - limiter: the real http-kit limiter, keyed per workspace and plugin so budgets never mix.
19
+ * - artifacts: an optional writer; absent, the capability is absent too (Jini's port is optional), so a
20
+ * tool can check for it before doing work it could not save.
21
+ * - state: the plugin's own settings, read-only (`get` alone), from the store its admin surface
22
+ * writes, keyed by the same plugin and workspace.
23
+ * Nothing here names a provider.
24
+ */
25
+ import type { AgentPluginToolCapabilities, AgentPluginToolCapabilitiesPort } from '../../lifecycle/tools/capabilities.js';
26
+ import type { HttpClientPort } from '@jini-ai/core/primitives';
27
+ import type { AgentPluginConnectionAccess, AgentPluginArtifactWriter, AgentPluginRateLimiter, AgentPluginStateReaderFor, AgentPluginApiOriginsFor, FrozenConnectionAccounts } from './ports.js';
28
+ export declare const HTTPS_ONLY_MESSAGE = "Plugin tools may only call https:// addresses. Report this to the plugin author.";
29
+ export declare const UNDECLARED_ORIGIN_MESSAGE = "Plugin tools may only call the API addresses their plugin declares. Report this to the plugin author.";
30
+ export declare const RESPONSE_TOO_LARGE_MESSAGE = "The service returned more data than a plugin tool may read at once. Request a smaller range and retry.";
31
+ export declare const UNAPPROVED_CONNECTION_MESSAGE = "This call was approved for another connection, so it cannot use this one. Nothing was changed.";
32
+ /** Creates the frozen-account map. Weakly keyed: an execution's entry disappears with its signal. @complexity O(1). */
33
+ export declare function createFrozenConnectionAccounts(_required?: Record<string, never>, _optional?: Record<string, never>): FrozenConnectionAccounts;
34
+ /**
35
+ * The token options one call's connection gets from its confirmation: the frozen account, nothing for
36
+ * a call that was never confirmed, and a refusal for a connection its approval did not show. Shared by
37
+ * tool calls and assistant-dispatched admin-surface actions (`api-connections/surface-connections.ts`).
38
+ * @throws Error(UNAPPROVED_CONNECTION_MESSAGE) when the call was frozen without this connection. @complexity O(1).
39
+ */
40
+ export declare function confirmedTokenOptions(required: {
41
+ readonly frozen: FrozenConnectionAccounts;
42
+ readonly signal: AbortSignal | undefined;
43
+ readonly connectionRef: string;
44
+ }, _optional?: Record<string, never>): {
45
+ readonly expectedAccountId?: string;
46
+ };
47
+ /**
48
+ * The guarded `http` capability alone, for host code that hands plugin modules the same HTTP a tool
49
+ * gets (API-connection hooks read the signed-in account through it).
50
+ * @complexity O(1); each fetch is O(response size).
51
+ */
52
+ export declare function createGuardedPluginHttp(required: {
53
+ readonly http: HttpClientPort;
54
+ }, _optional?: Record<string, never>): AgentPluginToolCapabilities['http'];
55
+ /**
56
+ * Builds the capabilities port the tool projection calls once per invocation.
57
+ * @param required.connections - Host connection accessor (ownership enforced there and by the scope passed here).
58
+ * @param required.http - The guarded outbound HTTP client.
59
+ * @param required.limiter - The http-kit limiter sized for plugin budgets.
60
+ * @param required.frozen - Accounts frozen by the confirmation step.
61
+ * @param required.state - The plugin settings reader, scoped here to the calling plugin and workspace.
62
+ * @param required.apiOrigins - The calling plugin's declared API origins; its HTTP reaches no other host.
63
+ * @param optional.artifacts - File writer; omitted, the `artifacts` capability is omitted.
64
+ * @complexity O(1) per call; each capability is one delegated call.
65
+ */
66
+ export declare function createAgentPluginToolCapabilities(required: {
67
+ readonly connections: AgentPluginConnectionAccess;
68
+ readonly http: HttpClientPort;
69
+ readonly limiter: AgentPluginRateLimiter;
70
+ readonly frozen: FrozenConnectionAccounts;
71
+ readonly state: AgentPluginStateReaderFor;
72
+ readonly apiOrigins: AgentPluginApiOriginsFor;
73
+ }, optional?: {
74
+ readonly artifacts?: AgentPluginArtifactWriter;
75
+ }): AgentPluginToolCapabilitiesPort;
76
+ //# sourceMappingURL=host-capabilities.d.ts.map
@@ -0,0 +1,100 @@
1
+ /** Response bodies a plugin may read in one request; larger answers fail instead of truncating. */
2
+ const MAX_RESPONSE_BYTES = 1024 * 1024;
3
+ const IDLE_TIMEOUT_MS = 30_000;
4
+ export const HTTPS_ONLY_MESSAGE = 'Plugin tools may only call https:// addresses. Report this to the plugin author.';
5
+ export const UNDECLARED_ORIGIN_MESSAGE = 'Plugin tools may only call the API addresses their plugin declares. Report this to the plugin author.';
6
+ export const RESPONSE_TOO_LARGE_MESSAGE = 'The service returned more data than a plugin tool may read at once. Request a smaller range and retry.';
7
+ export const UNAPPROVED_CONNECTION_MESSAGE = 'This call was approved for another connection, so it cannot use this one. Nothing was changed.';
8
+ /** Creates the frozen-account map. Weakly keyed: an execution's entry disappears with its signal. @complexity O(1). */
9
+ export function createFrozenConnectionAccounts(_required = {}, _optional = {}) {
10
+ const bySignal = new WeakMap();
11
+ return {
12
+ bind: ({ signal, accounts }) => { bySignal.set(signal, accounts); },
13
+ lookup: ({ signal, connectionRef }) => {
14
+ const accounts = signal ? bySignal.get(signal) : undefined;
15
+ return accounts === undefined ? undefined : accounts.get(connectionRef) ?? null;
16
+ },
17
+ };
18
+ }
19
+ /**
20
+ * The token options one call's connection gets from its confirmation: the frozen account, nothing for
21
+ * a call that was never confirmed, and a refusal for a connection its approval did not show. Shared by
22
+ * tool calls and assistant-dispatched admin-surface actions (`api-connections/surface-connections.ts`).
23
+ * @throws Error(UNAPPROVED_CONNECTION_MESSAGE) when the call was frozen without this connection. @complexity O(1).
24
+ */
25
+ export function confirmedTokenOptions(required, _optional = {}) {
26
+ const expectedAccountId = required.frozen.lookup({ signal: required.signal, connectionRef: required.connectionRef });
27
+ // A confirmed call may only use the connections its approval froze, never an unpinned other one.
28
+ if (expectedAccountId === null)
29
+ throw new Error(UNAPPROVED_CONNECTION_MESSAGE);
30
+ return expectedAccountId === undefined ? {} : { expectedAccountId };
31
+ }
32
+ /** Plugin HTTP through the guarded client: HTTPS only, no redirects, bounded body, never truncated.
33
+ * @complexity O(response size). */
34
+ async function guardedPluginFetch(http, url, options = {}) {
35
+ if (new URL(url).protocol !== 'https:')
36
+ throw new Error(HTTPS_ONLY_MESSAGE);
37
+ const response = await http.send({ request: {
38
+ url, method: options.method ?? 'GET', headers: { ...options.headers }, idleTimeoutMs: IDLE_TIMEOUT_MS, maxResponseBytes: MAX_RESPONSE_BYTES,
39
+ ...(options.body === undefined ? {} : { body: options.body }), ...(options.signal === undefined ? {} : { signal: options.signal }),
40
+ } }, { redirect: 'error' });
41
+ if (response.bodyTruncated)
42
+ throw new Error(RESPONSE_TOO_LARGE_MESSAGE);
43
+ // Fetch forbids bodies on 204/205/304, even when the native port returns an empty string.
44
+ return new Response([204, 205, 304].includes(response.status) ? null : response.bodyText, { status: response.status, headers: { ...response.headers } });
45
+ }
46
+ /**
47
+ * The guarded `http` capability alone, for host code that hands plugin modules the same HTTP a tool
48
+ * gets (API-connection hooks read the signed-in account through it).
49
+ * @complexity O(1); each fetch is O(response size).
50
+ */
51
+ export function createGuardedPluginHttp(required, _optional = {}) {
52
+ return { fetch: ({ url }, options) => guardedPluginFetch(required.http, url, options) };
53
+ }
54
+ /**
55
+ * One plugin's HTTP: an https URL outside its declared origins is refused before anything is sent;
56
+ * the https rule itself stays in {@link guardedPluginFetch} so a plaintext URL keeps its own message.
57
+ * @complexity One origins lookup per fetch, then O(response size).
58
+ */
59
+ function declaredOriginsHttp(http, origins, toolSignal) {
60
+ return { async fetch({ url }, options = {}) {
61
+ const target = new URL(url);
62
+ if (target.protocol === 'https:' && !(await origins()).includes(target.origin))
63
+ throw new Error(UNDECLARED_ORIGIN_MESSAGE);
64
+ return guardedPluginFetch(http, url, { ...options, ...withToolSignal(toolSignal, options.signal) });
65
+ } };
66
+ }
67
+ /** Aborting the tool aborts its requests too, alongside any signal the plugin passed itself. @complexity O(1). */
68
+ function withToolSignal(toolSignal, pluginSignal) {
69
+ const signals = [toolSignal, pluginSignal].filter((signal) => signal !== undefined);
70
+ if (signals.length === 0)
71
+ return {};
72
+ return { signal: signals.length === 1 ? signals[0] : AbortSignal.any(signals) };
73
+ }
74
+ /**
75
+ * Builds the capabilities port the tool projection calls once per invocation.
76
+ * @param required.connections - Host connection accessor (ownership enforced there and by the scope passed here).
77
+ * @param required.http - The guarded outbound HTTP client.
78
+ * @param required.limiter - The http-kit limiter sized for plugin budgets.
79
+ * @param required.frozen - Accounts frozen by the confirmation step.
80
+ * @param required.state - The plugin settings reader, scoped here to the calling plugin and workspace.
81
+ * @param required.apiOrigins - The calling plugin's declared API origins; its HTTP reaches no other host.
82
+ * @param optional.artifacts - File writer; omitted, the `artifacts` capability is omitted.
83
+ * @complexity O(1) per call; each capability is one delegated call.
84
+ */
85
+ export function createAgentPluginToolCapabilities(required, optional = {}) {
86
+ const { connections, limiter, frozen, state, apiOrigins } = required;
87
+ const writer = optional.artifacts;
88
+ return ({ pluginId, workspaceId, signal }) => ({
89
+ connections: { async getAccessToken({ connectionRef }) {
90
+ return connections.getAccessToken({ workspaceId, pluginId, connectionRef }, confirmedTokenOptions({ frozen, signal, connectionRef }));
91
+ } },
92
+ http: declaredOriginsHttp(required.http, () => apiOrigins({ workspaceId, pluginId }), signal),
93
+ // NUL cannot appear in a workspace or plugin id, so one plugin's key can never name another's budget.
94
+ limiter: { check: ({ key }) => limiter.check({ key: `${workspaceId}\u0000${pluginId}\u0000${key}` }) },
95
+ ...(writer === undefined ? {} : { artifacts: { write: (input) => writer.write({ ...input, workspaceId, pluginId }) } }),
96
+ // A fresh object with `get` alone: whatever the store exposes, a tool can never write through it.
97
+ state: { get: (input) => state({ workspaceId, pluginId }).get(input) },
98
+ });
99
+ }
100
+ //# sourceMappingURL=host-capabilities.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @agent-note A host that imports this entry must install the optional peer `@cfworker/json-schema`.
3
+ * `register.ts` builds the tool projection from `../../lifecycle/tools/projection.js`, which imports
4
+ * it by value, so without it this import fails with ERR_MODULE_NOT_FOUND for `@cfworker/json-schema`.
5
+ */
6
+ export { registerAgentPluginExecutableTools } from './register.js';
7
+ export { createAgentPluginDisclosure, APPROVAL_FAMILY_BY_EFFECT, type AgentPluginDisclosureSource } from './approval.js';
8
+ export { createFrozenConnectionAccounts, confirmedTokenOptions, createGuardedPluginHttp, createAgentPluginToolCapabilities, HTTPS_ONLY_MESSAGE, UNDECLARED_ORIGIN_MESSAGE, RESPONSE_TOO_LARGE_MESSAGE, UNAPPROVED_CONNECTION_MESSAGE } from './host-capabilities.js';
9
+ export type { AgentPluginConnectionTarget, AgentPluginConnectionAccess, AgentPluginArtifactWriter, AgentPluginRateLimiter, AgentPluginStateReaderFor, AgentPluginApiOriginsFor, FrozenConnectionAccounts, AgentPluginExecutableContributionRegistry, AgentPluginExecutableContributions, AgentPluginExecutableRuntimeHost, ApplyAgentPluginApproval, AgentPluginApprovalFamily, ApplyAgentPluginPolicy, AgentPluginDisclosureMessages, AgentPluginExecutableRegistrationRequired } from './ports.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @agent-note A host that imports this entry must install the optional peer `@cfworker/json-schema`.
3
+ * `register.ts` builds the tool projection from `../../lifecycle/tools/projection.js`, which imports
4
+ * it by value, so without it this import fails with ERR_MODULE_NOT_FOUND for `@cfworker/json-schema`.
5
+ */
6
+ export { registerAgentPluginExecutableTools } from './register.js';
7
+ export { createAgentPluginDisclosure, APPROVAL_FAMILY_BY_EFFECT } from './approval.js';
8
+ export { createFrozenConnectionAccounts, confirmedTokenOptions, createGuardedPluginHttp, createAgentPluginToolCapabilities, HTTPS_ONLY_MESSAGE, UNDECLARED_ORIGIN_MESSAGE, RESPONSE_TOO_LARGE_MESSAGE, UNAPPROVED_CONNECTION_MESSAGE } from './host-capabilities.js';
9
+ //# sourceMappingURL=index.js.map