@jini-ai/agent-plugins 0.6.23 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/README.md +13 -0
- package/calendly/exports/booking-calendar.css +7 -0
- package/calendly/exports/booking-calendar.html +5 -0
- package/calendly/mcp.json +10 -0
- package/calendly/plugin.json +47 -0
- package/calendly/skills/calendly/SKILL.md +27 -0
- package/charts-echarts/plugin.json +2 -2
- package/charts-recharts/plugin.json +2 -2
- package/cloudflare/lib/cms-forms.mjs +57 -0
- package/cloudflare/lib/forms.mjs +78 -18
- package/cloudflare/lib/target.mjs +17 -4
- package/cloudflare/plugin.json +2 -2
- package/cloudflare/skills/cloudflare/SKILL.md +4 -4
- package/cloudflare/skills/cloudflare/references/workers.md +4 -4
- package/cloudflare/worker/forms-receiver.mjs +81 -41
- package/cloudflare/worker/portable-validation.mjs +220 -0
- package/commerce/plugin.json +17 -0
- package/commerce/skills/commerce/SKILL.md +23 -0
- package/composio/mcp.json +1 -1
- package/composio/plugin.json +2 -2
- package/composio/skills/composio/SKILL.md +4 -4
- package/core/commerce-server.d.ts +2 -0
- package/core/commerce-server.mjs +2 -0
- package/dist/admin-surfaces/connections/connections.d.ts +35 -0
- package/dist/admin-surfaces/connections/connections.js +135 -0
- package/dist/admin-surfaces/connections/index.d.ts +3 -0
- package/dist/admin-surfaces/connections/index.js +2 -0
- package/dist/admin-surfaces/connections/ports.d.ts +110 -0
- package/dist/admin-surfaces/connections/ports.js +2 -0
- package/dist/admin-surfaces/index.d.ts +2 -0
- package/dist/admin-surfaces/index.js +1 -0
- package/dist/admin-surfaces/plugin-state-persistence.d.ts +27 -0
- package/dist/admin-surfaces/plugin-state-persistence.js +2 -0
- package/dist/admin-surfaces/plugin-state.d.ts +51 -0
- package/dist/admin-surfaces/plugin-state.js +106 -0
- package/dist/connect/access-token-tool.d.ts +240 -0
- package/dist/connect/access-token-tool.js +213 -0
- package/dist/connect/apply-connect-defaults.d.ts +91 -0
- package/dist/connect/apply-connect-defaults.js +113 -0
- package/dist/connect/apply-tool-renames.d.ts +72 -0
- package/dist/connect/apply-tool-renames.js +105 -0
- package/dist/connect/connect-card-ui.d.ts +143 -0
- package/dist/connect/connect-card-ui.js +106 -0
- package/dist/connect/connect-destination.d.ts +35 -0
- package/dist/connect/connect-destination.js +45 -0
- package/dist/connect/connect-sign-in-wait.d.ts +31 -0
- package/dist/connect/connect-sign-in-wait.js +21 -0
- package/dist/connect/connect-tool.d.ts +314 -0
- package/dist/connect/connect-tool.js +431 -0
- package/dist/connect/connection-status.d.ts +33 -0
- package/dist/connect/connection-status.js +63 -0
- package/dist/connect/credential-cards.d.ts +15 -0
- package/dist/connect/credential-cards.js +49 -0
- package/dist/connect/credential-save-tool.d.ts +45 -0
- package/dist/connect/credential-save-tool.js +156 -0
- package/dist/connect/enable-access.d.ts +67 -0
- package/dist/connect/enable-access.js +74 -0
- package/dist/connect/executable/approval.d.ts +58 -0
- package/dist/connect/executable/approval.js +40 -0
- package/dist/connect/executable/host-capabilities.d.ts +76 -0
- package/dist/connect/executable/host-capabilities.js +100 -0
- package/dist/connect/executable/index.d.ts +10 -0
- package/dist/connect/executable/index.js +9 -0
- package/dist/connect/executable/ports.d.ts +189 -0
- package/dist/connect/executable/ports.js +2 -0
- package/dist/connect/executable/register.d.ts +21 -0
- package/dist/connect/executable/register.js +125 -0
- package/dist/connect/federate-mcp.d.ts +190 -0
- package/dist/connect/federate-mcp.js +440 -0
- package/dist/connect/grant-signed-in-defaults.d.ts +96 -0
- package/dist/connect/grant-signed-in-defaults.js +100 -0
- package/dist/connect/import-access-token.d.ts +114 -0
- package/dist/connect/import-access-token.js +103 -0
- package/dist/connect/index.d.ts +19 -0
- package/dist/connect/index.js +19 -0
- package/dist/connect/plugin-credential-card.d.ts +46 -0
- package/dist/connect/plugin-credential-card.js +63 -0
- package/dist/connect/plugin-host/index.d.ts +203 -0
- package/dist/connect/plugin-host/index.js +153 -0
- package/dist/connect/ports.d.ts +74 -0
- package/dist/connect/ports.js +2 -0
- package/dist/connect/switch-on-saved-token.d.ts +48 -0
- package/dist/connect/switch-on-saved-token.js +20 -0
- package/dist/connect/token-sign-in.d.ts +51 -0
- package/dist/connect/token-sign-in.js +43 -0
- package/dist/core/identity-namespace.d.ts +39 -0
- package/dist/core/identity-namespace.js +61 -3
- package/dist/folder-zip-node.js +3 -1
- package/dist/lifecycle/automatic-use.d.ts +12 -7
- package/dist/lifecycle/automatic-use.js +37 -28
- package/dist/lifecycle/capability-projection.js +5 -1
- package/dist/lifecycle/contribution-loader.d.ts +2 -7
- package/dist/lifecycle/contribution-types.d.ts +8 -0
- package/dist/lifecycle/contribution-types.js +2 -0
- package/dist/lifecycle/credential-card-metadata.d.ts +23 -0
- package/dist/lifecycle/credential-card-metadata.js +184 -0
- package/dist/lifecycle/exports.d.ts +11 -0
- package/dist/lifecycle/exports.js +64 -3
- package/dist/lifecycle/host-tools/identity.d.ts +38 -0
- package/dist/lifecycle/host-tools/identity.js +58 -0
- package/dist/lifecycle/host-tools/index.d.ts +20 -0
- package/dist/lifecycle/host-tools/index.js +20 -0
- package/dist/lifecycle/host-tools/memory-tools.d.ts +22 -0
- package/dist/lifecycle/host-tools/memory-tools.js +63 -0
- package/dist/lifecycle/host-tools/ports.d.ts +121 -0
- package/dist/lifecycle/host-tools/ports.js +2 -0
- package/dist/lifecycle/host-tools/provider-status-tool.d.ts +88 -0
- package/dist/lifecycle/host-tools/provider-status-tool.js +45 -0
- package/dist/lifecycle/host-tools/search-tool.d.ts +74 -0
- package/dist/lifecycle/host-tools/search-tool.js +282 -0
- package/dist/lifecycle/host-tools/skill-tool.d.ts +219 -0
- package/dist/lifecycle/host-tools/skill-tool.js +482 -0
- package/dist/lifecycle/host-tools/write-note-tool.d.ts +22 -0
- package/dist/lifecycle/host-tools/write-note-tool.js +47 -0
- package/dist/lifecycle/index.d.ts +2 -1
- package/dist/lifecycle/install.js +2 -1
- package/dist/lifecycle/installed-package-index.js +5 -8
- package/dist/lifecycle/mail/adapter-descriptors.d.ts +78 -0
- package/dist/lifecycle/mail/adapter-descriptors.js +155 -0
- package/dist/lifecycle/mail/catalog.d.ts +116 -0
- package/dist/lifecycle/mail/catalog.js +72 -0
- package/dist/lifecycle/mail/configuration.d.ts +25 -0
- package/dist/lifecycle/mail/configuration.js +62 -0
- package/dist/lifecycle/mail/contribution.d.ts +89 -0
- package/dist/lifecycle/mail/contribution.js +115 -0
- package/dist/lifecycle/mail/host-mailer.d.ts +24 -0
- package/dist/lifecycle/mail/host-mailer.js +10 -0
- package/dist/lifecycle/mail/index.d.ts +16 -0
- package/dist/lifecycle/mail/index.js +16 -0
- package/dist/lifecycle/mail/selection.d.ts +40 -0
- package/dist/lifecycle/mail/selection.js +86 -0
- package/dist/lifecycle/manifest.d.ts +7 -2
- package/dist/lifecycle/manifest.js +32 -9
- package/dist/lifecycle/metadata.d.ts +31 -0
- package/dist/lifecycle/metadata.js +80 -0
- package/dist/lifecycle/persistent-state.js +2 -1
- package/dist/lifecycle/ports.d.ts +2 -0
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.js +14 -8
- package/dist/lifecycle/search-projection.d.ts +3 -4
- package/dist/lifecycle/search-projection.js +5 -7
- package/dist/lifecycle/search.js +3 -2
- package/fly/plugin.json +5 -5
- package/fly/skills/fly/SKILL.md +1 -1
- package/formspree/plugin.json +7 -0
- package/formspree/skills/formspree/SKILL.md +11 -0
- package/github/plugin.json +2 -2
- package/github/skills/github/SKILL.md +28 -28
- package/github/skills/github/references/actions.md +8 -8
- package/github/skills/github/references/auth-and-tokens.md +7 -7
- package/github/skills/github/references/repo-files.md +5 -5
- package/github/skills/github/references/site-backup.md +16 -16
- package/github/skills/github/references/source-control.md +17 -17
- package/github-pages/plugin.json +2 -2
- package/github-pages/skills/github-pages/SKILL.md +3 -3
- package/google-forms/plugin.json +7 -0
- package/google-forms/skills/google-forms/SKILL.md +15 -0
- package/google-login/plugin.json +3 -3
- package/google-login/skills/google-login/SKILL.md +17 -60
- package/google-workspace/plugin.json +6 -6
- package/google-workspace/skills/google-workspace/references/connection.md +1 -1
- package/google-workspace/skills/google-workspace/references/form-delivery.md +4 -4
- package/google-workspace/tovu-admin-surfaces.json +5 -5
- package/higgsfield-media/plugin.json +5 -5
- package/higgsfield-media/skills/higgsfield-media/SKILL.md +31 -33
- package/higgsfield-media/skills/higgsfield-media/references/failure-modes.md +7 -7
- package/higgsfield-media/skills/higgsfield-media/references/models-and-plan-gates.md +3 -3
- package/jev/plugin.json +2 -2
- package/langfuse/plugin.json +2 -2
- package/meilisearch/plugin.json +2 -2
- package/meilisearch/skills/meilisearch/SKILL.md +1 -1
- package/netlify/plugin.json +2 -2
- package/netlify/skills/netlify/SKILL.md +3 -3
- package/opentelemetry/plugin.json +2 -2
- package/opentelemetry/skills/opentelemetry/SKILL.md +7 -7
- package/package.json +92 -14
- package/posthog/plugin.json +2 -2
- package/posthog/skills/posthog/SKILL.md +7 -7
- package/railway/plugin.json +3 -3
- package/railway/skills/railway/SKILL.md +10 -11
- package/render/plugin.json +3 -3
- package/render/skills/render/SKILL.md +7 -8
- package/resend/NOTES.md +2 -2
- package/resend/mcp.json +1 -1
- package/resend/plugin.json +5 -5
- package/resend/skills/resend/SKILL.md +13 -13
- package/s3-compatible/plugin.json +2 -2
- package/s3-compatible/skills/s3-compatible/SKILL.md +4 -4
- package/sentry/plugin.json +2 -2
- package/sentry/skills/sentry/SKILL.md +7 -7
- package/shopify/plugin.json +2 -2
- package/site-compliance/plugin.json +2 -2
- package/site-compliance/skills/site-compliance/SKILL.md +3 -3
- package/site-compliance/skills/site-compliance/references/gdpr-eu-uk.md +1 -1
- package/site-import/plugin.json +2 -2
- package/slide-design/plugin.json +2 -2
- package/software-engineering/LICENSE +201 -0
- package/software-engineering/NOTICE +9 -0
- package/software-engineering/README.md +89 -0
- package/software-engineering/plugin.json +24 -0
- package/software-engineering/skills/software-engineering/SKILL.md +33 -0
- package/software-engineering/skills/software-engineering/references/debugging.md +54 -0
- package/software-engineering/skills/software-engineering/references/implementation.md +27 -0
- package/software-engineering/skills/software-engineering/references/planning.md +27 -0
- package/software-engineering/skills/software-engineering/references/prototyping.md +14 -0
- package/software-engineering/skills/software-engineering/references/security.md +47 -0
- package/software-engineering/skills/software-engineering/references/verification.md +53 -0
- package/stripe/plugin.json +2 -2
- package/supabase/mcp.json +4 -4
- package/supabase/plugin.json +3 -3
- package/supabase/skills/supabase/SKILL.md +8 -8
- package/supabase/skills/supabase/references/failure-modes.md +5 -5
- package/ui-ux-design/plugin.json +2 -2
- package/vercel/plugin.json +2 -2
- package/vercel/skills/vercel/SKILL.md +3 -3
- package/wordpress/plugin.json +2 -2
- package/wordpress/skills/wordpress/SKILL.md +3 -3
- package/wordpress/skills/wordpress/references/free-site-redirect.md +2 -2
- package/wordpress/skills/wordpress/references/subdomain.md +5 -5
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { adaptLegacyAuthorize } from "@jini-ai/core";
|
|
2
|
+
import {} from "@jini-ai/core";
|
|
3
|
+
import { requireToolPermission } from "@jini-ai/core";
|
|
4
|
+
import { ToolInputError, redactSecrets } from "@jini-ai/core";
|
|
5
|
+
import { deriveAgentPluginConnectionId, provisionAgentPluginMcpServers } from "./federate-mcp.js";
|
|
6
|
+
import { previewAgentPluginEnableAccess } from "./enable-access.js";
|
|
7
|
+
import { recordAgentPluginAccessDeclined } from "./apply-connect-defaults.js";
|
|
8
|
+
/**
|
|
9
|
+
* @file agent_plugin_connect connects an Agent Plugin's account through
|
|
10
|
+
* one shared host flow, so plugins do not need vendor-specific connect tools.
|
|
11
|
+
*
|
|
12
|
+
* Token-only plugins reuse a stored credential or the injected credential_save token card. The
|
|
13
|
+
* token card owns probing, sealing and cancellation; this module never handles a plaintext token.
|
|
14
|
+
* Explicit OAuth with token fallback retains the OAuth flow below.
|
|
15
|
+
*
|
|
16
|
+
* ## What one OAuth call does
|
|
17
|
+
*
|
|
18
|
+
* Given a `pluginId`, this provisions the plugin's declared OAuth-authenticated MCP server(s) as
|
|
19
|
+
* external-MCP rows (idempotently — `provisionAgentPluginMcpServers`, `federate-mcp.ts`), starts an
|
|
20
|
+
* authorization for whichever of them are not yet connected, shows a card with a sign-in link, and
|
|
21
|
+
* PARKS the call — polling the row for `oauth.status === "connected"` — until either the human
|
|
22
|
+
* finishes signing in, skips the card, or a bounded wait elapses. Skip releases only this sign-in
|
|
23
|
+
* wait so the assistant can continue the turn. It never returns a token, a URL, or a row id in its
|
|
24
|
+
* own result: only `{ status: "connected" }` or the resumable `{ status: "waiting-for-sign-in" }`
|
|
25
|
+
* (the plan's skill calls this again on "done" rather than looping on its own). A plugin-declared API
|
|
26
|
+
* connection's result also carries its opaque `connectionRef`, because that plugin's tools take it as
|
|
27
|
+
* input and chat has no other way to learn it; the host refuses it for every other plugin.
|
|
28
|
+
*
|
|
29
|
+
* ## Why polling alongside `exchange.receive()`
|
|
30
|
+
*
|
|
31
|
+
* The sign-in itself finishes on the PUBLIC OAuth callback route, not by the human clicking anything
|
|
32
|
+
* inside this card (`external-mcp-oauth.ts`'s `completeAuthorizationCallback`) — the card's one
|
|
33
|
+
* sign-in element is an outbound `openLink`, which (per `@jini-ai/ui`'s `outcome.ts` surface) is
|
|
34
|
+
* not a delivery through `mcp-ui-tool-calls-route.ts` at all. So there is nothing for this call to
|
|
35
|
+
* `receive()` to finish sign-in: that now observes Skip, while the callback is observed by reading the row this call already
|
|
36
|
+
* provisioned, which is exactly what `resolveExternalMcpOAuthStatus` (`features/external-mcp/external-mcp-store.ts`)
|
|
37
|
+
* is for.
|
|
38
|
+
*
|
|
39
|
+
* ## Deliberately narrow: one pending OAuth server per call
|
|
40
|
+
*
|
|
41
|
+
* A plugin declaring more than one OAuth-authenticated server that is not yet connected is refused
|
|
42
|
+
* with a plain `ToolInputError` naming the servers, rather than building a card with several sign-in
|
|
43
|
+
* links. No bundled plugin does this today (Supabase and Higgsfield each declare exactly one), and a
|
|
44
|
+
* multi-link card is a real design question (which one is "the" sign-in?) worth deferring to an
|
|
45
|
+
* actual second case rather than guessing at one now.
|
|
46
|
+
*/
|
|
47
|
+
const DEFAULT_POLL_INTERVAL_MS = 3000;
|
|
48
|
+
/** Matches `@jini-ai/daemon/surface-exchanges`'s `DEFAULT_SURFACE_IDLE_TTL_MS` — the same
|
|
49
|
+
* "long enough to read a card and go sign in, short enough not to hold a subprocess open forever"
|
|
50
|
+
* budget. The connection watcher and the card exchange have separate owners; neither may keep
|
|
51
|
+
* the call parked beyond its own deadline. */
|
|
52
|
+
const DEFAULT_WAIT_TIMEOUT_MS = 5 * 60 * 1000;
|
|
53
|
+
/** "supabase" -> "Supabase", "higgsfield-media" -> "Higgsfield Media". There is no separate
|
|
54
|
+
* display-name field in `plugin.json` (agent-plugins.org has none) — `uninstall-confirmation-ui.ts`'s
|
|
55
|
+
* own dialog makes the identical choice, naming the plugin by its id. */
|
|
56
|
+
export function titleCaseFromPluginId(required, _optional = {}) {
|
|
57
|
+
return required.pluginId
|
|
58
|
+
.split(/[-_]+/)
|
|
59
|
+
.filter((word) => word.length > 0)
|
|
60
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
61
|
+
.join(" ");
|
|
62
|
+
}
|
|
63
|
+
/** Only a remote server can carry `authMode` (`manifest.ts`); a stdio entry never needs a sign-in. */
|
|
64
|
+
function isOAuthServer(config) {
|
|
65
|
+
return config.type !== "stdio" && config.authMode === "oauth";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Starts the sign-in and returns the link the card shows.
|
|
69
|
+
*
|
|
70
|
+
* @throws {ToolInputError} The OAuth service refused the request, or OAuth discovery/registration failed,
|
|
71
|
+
* with the no-card note the model must relay.
|
|
72
|
+
* @throws {Error} A `device_code` grant: the card has no place for the user code, and nothing in this
|
|
73
|
+
* call polls `pollDeviceAuthorization`, so the row would never flip to connected. Provisioned rows
|
|
74
|
+
* always use `authorization_code` (`federate-mcp.ts`), so this is a fail-loud guard.
|
|
75
|
+
*/
|
|
76
|
+
async function beginSignIn({ oauth, serverId, derivedPublicOrigin, host }, _options = {}) {
|
|
77
|
+
let start;
|
|
78
|
+
try {
|
|
79
|
+
start = await oauth.beginConnect({ serverId, redirectUri: host.publicUrl.redirectUri({ serverId, derivedPublicOrigin }), delivery: 'hosted' });
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
// Discovery runs before rendering. A failed start must not leave chat promising a missing card.
|
|
83
|
+
if (!oauth.isSignInRefusal({ error: err }))
|
|
84
|
+
throw err;
|
|
85
|
+
// A matching classifier does not make the message safe: model text crosses core redaction.
|
|
86
|
+
throw new ToolInputError({ message: host.messages.signInRefused({ detail: redactSecrets({ input: err.message }, { redactPii: false }) }) });
|
|
87
|
+
}
|
|
88
|
+
if (start.kind !== "redirect_required") {
|
|
89
|
+
throw new Error(host.messages.unsupportedSignIn({ kind: start.kind }));
|
|
90
|
+
}
|
|
91
|
+
// Cards get a same-origin path: an absolute URL names whichever origin built it, which a tunnel or proxy may not serve.
|
|
92
|
+
return new URL(start.authorizationUrl).pathname;
|
|
93
|
+
}
|
|
94
|
+
function sleepOrAbort(ms, signal) {
|
|
95
|
+
if (signal.aborted)
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
const timer = setTimeout(() => {
|
|
99
|
+
signal.removeEventListener("abort", onAbort);
|
|
100
|
+
resolve();
|
|
101
|
+
}, ms);
|
|
102
|
+
function onAbort() {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
resolve();
|
|
105
|
+
}
|
|
106
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** This tool's one-entry catalog, built from host copy (tool id, permission, description and the
|
|
110
|
+
* pluginId schema text are product vocabulary).
|
|
111
|
+
* @agent-note Second host: pass your own tool id/permission/description bytes; the schema shape is fixed. */
|
|
112
|
+
export function agentPluginConnectAgentToolCatalogFor(required, _optional = {}) {
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
name: required.toolId,
|
|
116
|
+
description: required.description,
|
|
117
|
+
sideEffects: "mutates-durable-state",
|
|
118
|
+
authorization: { permission: required.permission },
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: "object",
|
|
121
|
+
additionalProperties: false,
|
|
122
|
+
required: ["pluginId"],
|
|
123
|
+
properties: {
|
|
124
|
+
pluginId: {
|
|
125
|
+
type: "string",
|
|
126
|
+
minLength: 1,
|
|
127
|
+
description: required.pluginIdDescription,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
/** @agent-note Second host: key by your own tool id. */
|
|
135
|
+
export function agentPluginConnectDerivedRiskFor(required, _optional = {}) {
|
|
136
|
+
return new Map([
|
|
137
|
+
[required.toolId, "mutates-durable-state"],
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
/** Whether a plugin's row already holds a credential: a finished sign-in, or a saved access token
|
|
141
|
+
* (`static_env` with the token sealed in `sealedOAuth` — what `agent_plugin_set_access_token`, the
|
|
142
|
+
* old env var's boot import, and create-site onboarding all write; `sealedEnv` is a stdio row's env
|
|
143
|
+
* block and never holds it). Such a row needs no sign-in, and a token import must never overwrite it.
|
|
144
|
+
* @agent-note Pass the canonical store's SAME pure projection pair; this check performs no I/O,
|
|
145
|
+
* opens no sealed material and must not replace an existing credential with a fresh grant. */
|
|
146
|
+
export function hasStoredAgentPluginCredential(required, _optional = {}) {
|
|
147
|
+
const { row, projections } = required;
|
|
148
|
+
return projections.oauthStatus(row) === "connected" || projections.hasStaticAccessToken(row);
|
|
149
|
+
}
|
|
150
|
+
/** Resolves which of a plugin's declared OAuth servers still need connecting, after provisioning
|
|
151
|
+
* every one of them as an external-MCP row (idempotent — a row already `connected` is left alone).
|
|
152
|
+
* @throws {ToolInputError} A declared OAuth server has no row owned by this plugin after provisioning (provisioning
|
|
153
|
+
* skipped or failed it — e.g. a legacy `sse` transport): there is nothing to sign in to. */
|
|
154
|
+
async function resolvePendingOAuthServers(routeDeps, pluginId, oauthServerKeys) {
|
|
155
|
+
const pending = [];
|
|
156
|
+
for (const serverKey of oauthServerKeys) {
|
|
157
|
+
const connectionId = deriveAgentPluginConnectionId({ serverKey });
|
|
158
|
+
const row = connectionId
|
|
159
|
+
? await routeDeps.mcp.repo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId: connectionId })
|
|
160
|
+
: null;
|
|
161
|
+
if (!connectionId || !row || row.provisionedByPluginId !== pluginId) {
|
|
162
|
+
throw new ToolInputError({ message: routeDeps.host.messages.connectionNotSetUp({ pluginId, serverKey }) });
|
|
163
|
+
}
|
|
164
|
+
// A saved access token counts too: starting a sign-in here would switch the row back to OAuth.
|
|
165
|
+
if (hasStoredAgentPluginCredential({ row, projections: routeDeps.mcp.projections }))
|
|
166
|
+
continue;
|
|
167
|
+
pending.push({ serverKey, connectionId });
|
|
168
|
+
}
|
|
169
|
+
return pending;
|
|
170
|
+
}
|
|
171
|
+
/** A stored credential is reusable only on the same plugin-owned endpoint. No I/O or mutation.
|
|
172
|
+
* @complexity O(1) time and space. */
|
|
173
|
+
function hasReusablePluginCredential({ row, pluginId, url }, optional) {
|
|
174
|
+
if (!row)
|
|
175
|
+
return false;
|
|
176
|
+
const reusableOwner = row.provisionedByPluginId === null || row.provisionedByPluginId === pluginId;
|
|
177
|
+
return reusableOwner && row.url === url && hasStoredAgentPluginCredential({ row, projections: optional.projections });
|
|
178
|
+
}
|
|
179
|
+
/** Connect a token-only declaration through the existing card, or retain the API-connection path.
|
|
180
|
+
* @returns Connected only for an existing credential or a successful save; preserves card failures.
|
|
181
|
+
* @throws {ToolInputError} Ambiguous token servers, invalid server id, or a missing save adapter.
|
|
182
|
+
* @complexity O(s) time/space in declared servers, one row read, then the card's bounded exchange. */
|
|
183
|
+
async function connectWithoutOAuth({ routeDeps, surfaces, ctx, pluginId, servers }, { saveToken, ...optional } = {}) {
|
|
184
|
+
const tokens = Object.entries(servers).filter((entry) => entry[1].type !== "stdio" && entry[1].tokenAuth !== undefined);
|
|
185
|
+
if (tokens.length === 0)
|
|
186
|
+
return connectDeclaredApiConnectionOrRefuse(routeDeps, surfaces, ctx, pluginId, optional);
|
|
187
|
+
if (tokens.length > 1)
|
|
188
|
+
throw new ToolInputError({ message: routeDeps.host.messages.multipleTokenServers({ pluginId }) });
|
|
189
|
+
const [serverKey, config] = tokens[0];
|
|
190
|
+
const serverId = deriveAgentPluginConnectionId({ serverKey });
|
|
191
|
+
if (!serverId)
|
|
192
|
+
throw new ToolInputError({ message: routeDeps.host.messages.connectionNotSetUp({ pluginId, serverKey }) });
|
|
193
|
+
ctx.signal.throwIfAborted();
|
|
194
|
+
const row = await routeDeps.mcp.repo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId });
|
|
195
|
+
ctx.signal.throwIfAborted();
|
|
196
|
+
if (hasReusablePluginCredential({ row, pluginId, url: config.url }, routeDeps.mcp)) {
|
|
197
|
+
const approved = await approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId, servers: { [serverKey]: config } }, optional);
|
|
198
|
+
if (!approved.approved)
|
|
199
|
+
return approved.result;
|
|
200
|
+
await provisionAgentPluginMcpServers(routeDeps.mcp, { workspaceId: routeDeps.workspaceId, pluginId, servers: { [serverKey]: config }, principalId: ctx.principal.id, ...routeDeps.host.federation });
|
|
201
|
+
return { status: 'connected' };
|
|
202
|
+
}
|
|
203
|
+
if (!saveToken)
|
|
204
|
+
throw new ToolInputError({ message: routeDeps.host.messages.noTokenCardAdapter() });
|
|
205
|
+
const result = await saveToken({ ctx, pluginId }, optional);
|
|
206
|
+
if (result.saved)
|
|
207
|
+
return { status: "connected", next: result.next };
|
|
208
|
+
return { status: "not-connected", reason: result.reason, ...(result.message ? { message: result.message } : {}) };
|
|
209
|
+
}
|
|
210
|
+
/** Deny an off plugin before provisioning or starting a sign-in.
|
|
211
|
+
* @throws ToolInputError naming the existing approval flow when activation is off/unverifiable.
|
|
212
|
+
* @complexity One activation-owner read; for an off plugin one declaration read, no connection writes.
|
|
213
|
+
*/
|
|
214
|
+
async function assertPluginCanConnect({ routeDeps, pluginId }, _options = {}) {
|
|
215
|
+
const active = await routeDeps.isPluginEnabled(pluginId);
|
|
216
|
+
if (active)
|
|
217
|
+
return;
|
|
218
|
+
// Declarations are read as data only, so a plugin with no sign-in is pointed at its key card.
|
|
219
|
+
const plugin = await routeDeps.resolveInstalledPlugin(pluginId).catch(() => null);
|
|
220
|
+
const signsIn = Object.values(plugin?.servers ?? {}).some(isOAuthServer);
|
|
221
|
+
throw new ToolInputError({ message: routeDeps.host.messages.pluginOff({ pluginId }, signsIn ? {} : { credentialCards: plugin?.credentialCards ?? [] }) });
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Runs `agent_plugin_connect`: permission, resolve, then the declared token, OAuth or API flow.
|
|
225
|
+
* @example runAgentPluginConnect({ routeDeps, surfaces, ctx, pluginId }, { saveToken });
|
|
226
|
+
*
|
|
227
|
+
* @returns Safe connection status; token-card failure reasons remain observable.
|
|
228
|
+
* @throws {import("@jini-ai/core").ToolInputError} An unknown `pluginId`, unsupported connection,
|
|
229
|
+
* ambiguous token servers or more than one still-unconnected OAuth server (see the header).
|
|
230
|
+
* @throws {Error} No `externalMcpOAuth` was wired, or this execution context has no `emitSurface` —
|
|
231
|
+
* both composition-root/transport gaps, not caller input.
|
|
232
|
+
* @complexity O(s) provisioning the plugin's declared servers, plus the poll loop (bounded by
|
|
233
|
+
* `waitTimeoutMs`); O(s) space for pending declarations.
|
|
234
|
+
* @agent-note Fulfill AgentPluginConnectDeps with one host's stores/approvals/activation owners.
|
|
235
|
+
* Permission and prepared-key rechecks stay in run; approval precedes provisioning/sign-in and
|
|
236
|
+
* the final access revalidation. Forward the caller's emitter and execution options unchanged.
|
|
237
|
+
*/
|
|
238
|
+
export async function runAgentPluginConnect({ routeDeps, surfaces, ctx, pluginId }, optional = {}) {
|
|
239
|
+
ctx = { ...ctx, principal: { ...ctx.principal }, run: { ...ctx.run }, input: structuredClone(ctx.input) };
|
|
240
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: routeDeps.host.permissions.connect }, { entityType: routeDeps.host.entityType, entityId: pluginId });
|
|
241
|
+
await assertPluginCanConnect({ routeDeps, pluginId });
|
|
242
|
+
const plugin = await routeDeps.resolveInstalledPlugin(pluginId);
|
|
243
|
+
if (!plugin) {
|
|
244
|
+
throw new ToolInputError({ message: routeDeps.host.messages.notInstalled({ pluginId }) });
|
|
245
|
+
}
|
|
246
|
+
const oauthServerKeys = Object.entries(plugin.servers)
|
|
247
|
+
.filter(([, config]) => isOAuthServer(config))
|
|
248
|
+
.map(([serverKey]) => serverKey);
|
|
249
|
+
if (oauthServerKeys.length === 0)
|
|
250
|
+
return connectWithoutOAuth({ routeDeps, surfaces, ctx, pluginId, servers: plugin.servers }, optional);
|
|
251
|
+
if (!routeDeps.externalMcpOAuth) {
|
|
252
|
+
throw new Error(routeDeps.host.messages.noOAuthService());
|
|
253
|
+
}
|
|
254
|
+
const externalMcpOAuth = routeDeps.externalMcpOAuth;
|
|
255
|
+
// A retained session may need new access, but declining that card must not provision other
|
|
256
|
+
// sources or adopt an operator's independently configured credential-bearing connection.
|
|
257
|
+
const signedIn = await retainedOAuthServers({ routeDeps, servers: plugin.servers, oauthServerKeys });
|
|
258
|
+
const access = await approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId, servers: signedIn }, optional);
|
|
259
|
+
if (!access.approved)
|
|
260
|
+
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
|
+
// A colliding row can survive a refused provisioning attempt; never start sign-in on it.
|
|
263
|
+
const refusal = [...provisioned.failed, ...provisioned.skipped]
|
|
264
|
+
.find(result => oauthServerKeys.includes(result.serverKey));
|
|
265
|
+
if (refusal) {
|
|
266
|
+
throw new ToolInputError({ message: routeDeps.host.messages.connectionNotSetUp({ pluginId, serverKey: refusal.serverKey }) });
|
|
267
|
+
}
|
|
268
|
+
const pending = await resolvePendingOAuthServers(routeDeps, pluginId, oauthServerKeys);
|
|
269
|
+
const [server] = pending;
|
|
270
|
+
// Every declared OAuth server is already connected: no sign-in to start.
|
|
271
|
+
if (!server)
|
|
272
|
+
return { status: "connected" };
|
|
273
|
+
if (pending.length > 1) {
|
|
274
|
+
throw new ToolInputError({ message: routeDeps.host.messages.multipleOAuthServers({ pluginId, serverKeys: pending.map((p) => p.serverKey) }) });
|
|
275
|
+
}
|
|
276
|
+
const credentialCard = await findPluginOAuthCard(routeDeps, pluginId);
|
|
277
|
+
return connectAndReviewMcp({ routeDeps, surfaces, ctx, pluginId, server, externalMcpOAuth, credentialCard, servers: plugin.servers }, optional);
|
|
278
|
+
}
|
|
279
|
+
/** Complete sign-in before reviewing defaults still missing from a prior access choice.
|
|
280
|
+
* @complexity The existing bounded sign-in wait, then two source previews and conditional writes. */
|
|
281
|
+
async function connectAndReviewMcp(input, optional = {}) {
|
|
282
|
+
const result = await waitAtMcpSignInCard(input, optional);
|
|
283
|
+
if (result.status !== 'connected')
|
|
284
|
+
return result;
|
|
285
|
+
const { routeDeps, surfaces, ctx, pluginId, server, servers } = input;
|
|
286
|
+
const reviewed = await approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId,
|
|
287
|
+
servers: { [server.serverKey]: servers[server.serverKey] } }, optional);
|
|
288
|
+
if (reviewed.approved)
|
|
289
|
+
return result;
|
|
290
|
+
const reviewEnd = reviewed.result.reason === 'expired' ? 'expired' : 'ended with the run';
|
|
291
|
+
const lifecycle = reviewed.result.reason
|
|
292
|
+
? ` The access review ${reviewEnd}. Do not retry or reopen it automatically. Wait for a new explicit request.` : '';
|
|
293
|
+
return { ...reviewed.result, note: `Your sign-in was saved. No additional tool access was granted.${lifecycle}` };
|
|
294
|
+
}
|
|
295
|
+
/** Inspect retained sign-ins before any provisioning; the access preview checks source ownership. */
|
|
296
|
+
async function retainedOAuthServers({ routeDeps, servers, oauthServerKeys }, _optional = {}) {
|
|
297
|
+
const retained = {};
|
|
298
|
+
for (const key of oauthServerKeys) {
|
|
299
|
+
const connectionId = deriveAgentPluginConnectionId({ serverKey: key });
|
|
300
|
+
const row = connectionId ? await routeDeps.mcp.repo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId: connectionId }) : null;
|
|
301
|
+
if (row && hasStoredAgentPluginCredential({ row, projections: routeDeps.mcp.projections }))
|
|
302
|
+
retained[key] = servers[key];
|
|
303
|
+
}
|
|
304
|
+
return retained;
|
|
305
|
+
}
|
|
306
|
+
/** A retained credential proves sign-in, never consent to new tool or write grants.
|
|
307
|
+
* The common card fixes the exact sources; the existing grant writer applies those snapshots.
|
|
308
|
+
* @complexity Two previews over the signed-in sources plus one conditional write per changed row. */
|
|
309
|
+
async function approveSignedInAccess({ routeDeps, surfaces, ctx, pluginId, servers }, optional = {}) {
|
|
310
|
+
const preview = () => previewAgentPluginEnableAccess({ workspaceId: routeDeps.workspaceId, pluginId, servers, repo: routeDeps.mcp.repo, projections: routeDeps.mcp.projections, classifyError: routeDeps.mcp.classifyError, ...routeDeps.host.federation });
|
|
311
|
+
const handler = routeDeps.host.approvals.accessApprovalHandler({ surfaces,
|
|
312
|
+
prepare: preview,
|
|
313
|
+
describe: ({ ctx: bound, prepared }) => ({ toolId: routeDeps.host.toolId, errorCode: routeDeps.host.approvalErrorCode, title: `Allow access for ${pluginId}?`,
|
|
314
|
+
...(prepared.resources.length ? { access: { resources: prepared.resources.map(resource => ({ ...resource, scope: { personId: bound.principal.id, siteId: routeDeps.workspaceId } })) } } : {}),
|
|
315
|
+
details: [], description: 'Your existing sign-in is reused. Only the listed access is turned on.', confirmLabel: 'Allow access' }),
|
|
316
|
+
run: async ({ ctx: bound, prepared }) => {
|
|
317
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: bound.principal.id, permission: routeDeps.host.permissions.connect }, { entityType: routeDeps.host.entityType, entityId: pluginId });
|
|
318
|
+
await assertPluginCanConnect({ routeDeps, pluginId });
|
|
319
|
+
const current = await currentSignedInAccess({ routeDeps, pluginId, servers });
|
|
320
|
+
if (current.preview.key !== prepared.key)
|
|
321
|
+
throw new ToolInputError({ message: 'The plugin access changed while this card was open. Request the access change again. Nothing was granted.' });
|
|
322
|
+
const granted = [];
|
|
323
|
+
try {
|
|
324
|
+
for (const source of prepared.snapshots) {
|
|
325
|
+
if (!source.grant || !source.expected)
|
|
326
|
+
continue;
|
|
327
|
+
if (bound.signal.aborted)
|
|
328
|
+
throw new ToolInputError({ message: 'The run ended. Other connections were not changed.' });
|
|
329
|
+
await routeDeps.mcp.applyAccess({
|
|
330
|
+
workspaceId: routeDeps.workspaceId, serverId: source.connectionId, expected: source.expected,
|
|
331
|
+
access: { enabled: source.grant.enabled, allowedToolNames: source.grant.allow, writeAllowedToolNames: source.grant.write }, principalId: bound.principal.id
|
|
332
|
+
});
|
|
333
|
+
granted.push(source.connectionId);
|
|
334
|
+
}
|
|
335
|
+
await routeDeps.mcp.notifyRosterChanged?.({}, {});
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (granted.length === 0)
|
|
339
|
+
throw error;
|
|
340
|
+
const detail = redactSecrets({ input: String(error) }).replace('Nothing was changed by this approval.', 'That connection was left unchanged.');
|
|
341
|
+
throw new ToolInputError({ message: `Access was saved for ${granted.join(', ')}. The remaining access update did not finish. ${detail} Ask to connect the plugin again to finish.` });
|
|
342
|
+
}
|
|
343
|
+
return { approved: true };
|
|
344
|
+
},
|
|
345
|
+
}, { ask: ({ prepared }) => prepared.resources.length > 0, declined: async ({ reason, prepared }) => {
|
|
346
|
+
if (reason === 'declined' && prepared)
|
|
347
|
+
await recordAgentPluginAccessDeclined({ applyAccess: routeDeps.mcp.applyAccess, workspaceId: routeDeps.workspaceId, accessKey: prepared.key, actorId: routeDeps.host.actors.connectDeclined });
|
|
348
|
+
return { approved: false, result: { status: 'not-connected', ...routeDeps.host.approvals.notConfirmedResult({ reason }) } };
|
|
349
|
+
} });
|
|
350
|
+
return await handler(ctx, optional);
|
|
351
|
+
}
|
|
352
|
+
/** Re-resolve the installed declarations: a closed-over manifest is not a fresh approval check. */
|
|
353
|
+
async function currentSignedInAccess({ routeDeps, pluginId, servers }, _optional = {}) {
|
|
354
|
+
const installed = await routeDeps.resolveInstalledPlugin(pluginId);
|
|
355
|
+
const current = {};
|
|
356
|
+
for (const key of Object.keys(servers)) {
|
|
357
|
+
const config = installed?.servers[key];
|
|
358
|
+
if (!config)
|
|
359
|
+
throw new ToolInputError({ message: `The '${pluginId}' connection declaration changed after approval. Request the access change again. Nothing was granted.` });
|
|
360
|
+
current[key] = config;
|
|
361
|
+
}
|
|
362
|
+
return { servers: current, preview: await previewAgentPluginEnableAccess({ workspaceId: routeDeps.workspaceId, pluginId, servers: current, repo: routeDeps.mcp.repo, projections: routeDeps.mcp.projections, classifyError: routeDeps.mcp.classifyError, ...routeDeps.host.federation }) };
|
|
363
|
+
}
|
|
364
|
+
/** Show one MCP sign-in and always release its surface exchange after the bounded wait. */
|
|
365
|
+
async function waitAtMcpSignInCard(input, optional = {}) {
|
|
366
|
+
const { routeDeps, surfaces, ctx, pluginId, server, externalMcpOAuth, credentialCard } = input;
|
|
367
|
+
if (!optional.emitSurface) {
|
|
368
|
+
throw new Error(routeDeps.host.messages.missingEmitter());
|
|
369
|
+
}
|
|
370
|
+
const signInUrl = await beginSignIn({ oauth: externalMcpOAuth, serverId: server.connectionId, derivedPublicOrigin: routeDeps.derivedPublicOrigin, host: routeDeps.host });
|
|
371
|
+
return routeDeps.host.waitAtSignInCard({ surfaces, ctx, pluginId, pluginDisplayName: titleCaseFromPluginId({ pluginId }), credentialCard,
|
|
372
|
+
connect: async ({ signal, showSignIn }) => {
|
|
373
|
+
await showSignIn({ signInUrl });
|
|
374
|
+
const connected = await waitForMcpConnection({ routeDeps, ctx: { ...ctx, signal }, server });
|
|
375
|
+
return { status: connected ? "connected" : "waiting-for-sign-in" };
|
|
376
|
+
},
|
|
377
|
+
}, optional);
|
|
378
|
+
}
|
|
379
|
+
/** Observe the MCP row until callback completion, timeout or cancellation. */
|
|
380
|
+
async function waitForMcpConnection(input, _options = {}) {
|
|
381
|
+
const { routeDeps, ctx, server } = input;
|
|
382
|
+
const pollIntervalMs = routeDeps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
383
|
+
const waitTimeoutMs = routeDeps.waitTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
384
|
+
const deadline = Date.now() + waitTimeoutMs;
|
|
385
|
+
while (Date.now() < deadline && !ctx.signal.aborted) {
|
|
386
|
+
const row = await routeDeps.mcp.repo.findByServerId({ workspaceId: routeDeps.workspaceId, serverId: server.connectionId });
|
|
387
|
+
if (row && routeDeps.mcp.projections.oauthStatus(row) === "connected") {
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
await sleepOrAbort(Math.min(pollIntervalMs, Math.max(deadline - Date.now(), 0)), ctx.signal);
|
|
391
|
+
}
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The API-connection branch (or the original "nothing to connect" refusal): same card and parked wait as the MCP
|
|
396
|
+
* branch, plus the opaque `connectionRef` the plugin's tools take, over Jini's api-connections lifecycle instead of an external-MCP row. One declared
|
|
397
|
+
* connection per call, for the same reason the MCP branch takes one pending server.
|
|
398
|
+
* @throws {ToolInputError} More than one declared connection, or a sign-in refusal (safe message).
|
|
399
|
+
* @throws {Error} No interactive channel to show the sign-in card on.
|
|
400
|
+
* @complexity One sign-in round trip bounded by `waitTimeoutMs`.
|
|
401
|
+
*/
|
|
402
|
+
/** The plugin's own `oauth` card copy for its sign-in card, shared by the MCP and API-connection branches. O(cards). */
|
|
403
|
+
async function findPluginOAuthCard(routeDeps, pluginId) {
|
|
404
|
+
const cards = await routeDeps.credentials.loadSafe({ workspaceId: routeDeps.workspaceId });
|
|
405
|
+
return cards.find(card => card.pluginId === pluginId && card.saveKind === "oauth");
|
|
406
|
+
}
|
|
407
|
+
async function connectDeclaredApiConnectionOrRefuse(routeDeps, surfaces, ctx, pluginId, optional) {
|
|
408
|
+
const apiConnections = routeDeps.apiConnections;
|
|
409
|
+
const declared = apiConnections ? await apiConnections.listConnections({ pluginId }) : [];
|
|
410
|
+
const [connection] = declared;
|
|
411
|
+
if (!apiConnections || !connection) {
|
|
412
|
+
throw new ToolInputError({ message: routeDeps.host.messages.noConnection({ pluginId }) });
|
|
413
|
+
}
|
|
414
|
+
if (declared.length > 1) {
|
|
415
|
+
throw new ToolInputError({ message: routeDeps.host.messages.multipleApiConnections({ pluginId, count: declared.length }) });
|
|
416
|
+
}
|
|
417
|
+
const destination = await routeDeps.host.chooseDestination({ surfaces, ctx, pluginDisplayName: titleCaseFromPluginId({ pluginId }),
|
|
418
|
+
available: apiConnections.sharingAvailable === true && ctx.principal.id === await routeDeps.ownerPrincipalId }, optional);
|
|
419
|
+
if (destination === null)
|
|
420
|
+
return { status: 'not-connected', reason: 'cancelled', next: 'Sign-in was cancelled. Continue without this connection.' };
|
|
421
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: routeDeps.host.permissions.apiConnectionWrite });
|
|
422
|
+
const credentialCard = await findPluginOAuthCard(routeDeps, pluginId);
|
|
423
|
+
return routeDeps.host.waitAtSignInCard({ surfaces, ctx, pluginId, pluginDisplayName: titleCaseFromPluginId({ pluginId }), credentialCard,
|
|
424
|
+
connect: ({ signal, showSignIn }) => apiConnections.connect({
|
|
425
|
+
destination, connection, actorId: ctx.principal.id, signal, showSignIn,
|
|
426
|
+
pollIntervalMs: routeDeps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
|
|
427
|
+
waitTimeoutMs: routeDeps.waitTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS,
|
|
428
|
+
}),
|
|
429
|
+
}, optional);
|
|
430
|
+
}
|
|
431
|
+
//# sourceMappingURL=connect-tool.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentPluginMcpRecord, AgentPluginMcpProjectionPorts } from './ports.js';
|
|
2
|
+
import type { LoadPluginCredentialCards } from './plugin-credential-card.js';
|
|
3
|
+
/** @agent-note The narrow slice of the host's API-connection owner this status read uses: its one
|
|
4
|
+
* declared-connection catalog and per-connection status reads (no provider HTTP, no sealed opens).
|
|
5
|
+
* A second host passes the same instance its connect flow uses. */
|
|
6
|
+
export interface AgentPluginApiConnectionStatusReads {
|
|
7
|
+
listConnections(input: Record<string, never>): Promise<readonly {
|
|
8
|
+
readonly pluginId: string;
|
|
9
|
+
}[]>;
|
|
10
|
+
statusOf(input: {
|
|
11
|
+
readonly connection: {
|
|
12
|
+
readonly pluginId: string;
|
|
13
|
+
};
|
|
14
|
+
}): Promise<{
|
|
15
|
+
readonly status: AgentPluginConnectionStatus | 'reconnect-required' | 'revocation-pending';
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
type ConnectionRow = Pick<AgentPluginMcpRecord, 'provisionedByPluginId' | 'authMode' | 'oauthStatus' | 'sealedOAuth'>;
|
|
19
|
+
export type AgentPluginConnectionStatus = 'connected' | 'disconnected' | 'pending' | 'needs_reauth';
|
|
20
|
+
/** Token-free read model for the Agent Plugins screen. Activation and account state are separate:
|
|
21
|
+
* disabled plugins retain their saved sign-in. One MCP roster read, one card catalog read and one
|
|
22
|
+
* API catalog read; API status reads are per declared connection, with no provider HTTP calls.
|
|
23
|
+
* @complexity O(m + c + a) time/space in MCP rows, credential cards and declared API connections. */
|
|
24
|
+
export declare function loadAgentPluginConnectionStatuses(required: Pick<AgentPluginMcpProjectionPorts, 'projections'> & {
|
|
25
|
+
workspaceId: string;
|
|
26
|
+
mcp: {
|
|
27
|
+
listByWorkspaceId: (workspaceId: string) => Promise<readonly ConnectionRow[]>;
|
|
28
|
+
};
|
|
29
|
+
loadCards?: LoadPluginCredentialCards;
|
|
30
|
+
apiConnections?: AgentPluginApiConnectionStatusReads;
|
|
31
|
+
}, _optional?: {}): Promise<ReadonlyMap<string, AgentPluginConnectionStatus>>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=connection-status.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Token-free read model for the Agent Plugins screen. Activation and account state are separate:
|
|
2
|
+
* disabled plugins retain their saved sign-in. One MCP roster read, one card catalog read and one
|
|
3
|
+
* API catalog read; API status reads are per declared connection, with no provider HTTP calls.
|
|
4
|
+
* @complexity O(m + c + a) time/space in MCP rows, credential cards and declared API connections. */
|
|
5
|
+
export async function loadAgentPluginConnectionStatuses(required, _optional = {}) {
|
|
6
|
+
const [rows, cards, connections] = await Promise.all([
|
|
7
|
+
required.mcp.listByWorkspaceId(required.workspaceId), required.loadCards?.(required.workspaceId) ?? [],
|
|
8
|
+
required.apiConnections?.listConnections({}) ?? [],
|
|
9
|
+
]);
|
|
10
|
+
const states = new Map();
|
|
11
|
+
addMcpStatuses({ rows, states, projections: required.projections });
|
|
12
|
+
await addApiStatuses({ connections, host: required.apiConnections, states });
|
|
13
|
+
// A never-provisioned sign-in is still visibly absent. Plugins with no account declaration
|
|
14
|
+
// (skills/local tools) get no badge; an unrelated manual MCP server cannot sign them in.
|
|
15
|
+
addUnconnectedCards({ cards, states });
|
|
16
|
+
return new Map([...states].map(([pluginId, statuses]) => [pluginId, summarizeStatus({ statuses })]));
|
|
17
|
+
}
|
|
18
|
+
/** Existing auth readers own credential classification; this projection never opens a token. */
|
|
19
|
+
function mcpSignInStatus({ row, projections }, _optional = {}) {
|
|
20
|
+
if (projections.hasStaticAccessToken(row))
|
|
21
|
+
return 'connected';
|
|
22
|
+
if (row.authMode !== 'oauth')
|
|
23
|
+
return undefined;
|
|
24
|
+
return projections.oauthStatus(row);
|
|
25
|
+
}
|
|
26
|
+
/** A partial sign-in must not claim that every connection needed by a plugin is ready. */
|
|
27
|
+
function summarizeStatus({ statuses }, _optional = {}) {
|
|
28
|
+
for (const status of ['needs_reauth', 'pending', 'disconnected'])
|
|
29
|
+
if (statuses.includes(status))
|
|
30
|
+
return status;
|
|
31
|
+
return 'connected';
|
|
32
|
+
}
|
|
33
|
+
/** Accumulate in locally owned groups, avoiding repeated array copies for multi-server plugins. */
|
|
34
|
+
function appendStatus({ states, pluginId, status }, _optional = {}) {
|
|
35
|
+
const group = states.get(pluginId) ?? [];
|
|
36
|
+
group.push(status);
|
|
37
|
+
states.set(pluginId, group);
|
|
38
|
+
}
|
|
39
|
+
function addMcpStatuses({ rows, states, projections }, _optional = {}) {
|
|
40
|
+
for (const row of rows) {
|
|
41
|
+
if (!row.provisionedByPluginId)
|
|
42
|
+
continue;
|
|
43
|
+
const status = mcpSignInStatus({ row, projections });
|
|
44
|
+
if (status)
|
|
45
|
+
appendStatus({ states, pluginId: row.provisionedByPluginId, status });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function addApiStatuses({ connections, host, states }, _optional = {}) {
|
|
49
|
+
if (!host)
|
|
50
|
+
return;
|
|
51
|
+
for (const connection of connections) {
|
|
52
|
+
const { status } = await host.statusOf({ connection });
|
|
53
|
+
appendStatus({ states, pluginId: connection.pluginId,
|
|
54
|
+
status: status === 'reconnect-required' || status === 'revocation-pending' ? 'needs_reauth' : status });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function addUnconnectedCards({ cards, states }, _optional = {}) {
|
|
58
|
+
for (const card of cards) {
|
|
59
|
+
if (card.pluginId && card.saveKind === 'oauth' && !states.has(card.pluginId))
|
|
60
|
+
states.set(card.pluginId, ['disconnected']);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=connection-status.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginContributionDefinition } from '../lifecycle/contribution-loader.js';
|
|
2
|
+
import type { PluginCredentialCard } from "@jini-ai/core/contracts/credentials";
|
|
3
|
+
export { parsePluginCredentialCards, parseCredentialCardUsedFor } from '../lifecycle/credential-card-metadata.js';
|
|
4
|
+
/** Reuse Jini's active, trusted-package gate and contained manifest read. */
|
|
5
|
+
export declare const credentialCardsContribution: PluginContributionDefinition<PluginCredentialCard, PluginCredentialCard>;
|
|
6
|
+
/** Preserve mail objects and ordering; duplicate targets retain mail priority, while conflicting
|
|
7
|
+
* API label owners are all refused. O(cards) time and space; no persistent ownership registry.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergePluginCredentialCards({ mailCards, manifestCards }: {
|
|
10
|
+
mailCards: readonly PluginCredentialCard[];
|
|
11
|
+
manifestCards: readonly PluginCredentialCard[];
|
|
12
|
+
}, options?: {
|
|
13
|
+
onRefusal?: (message: string) => void;
|
|
14
|
+
}): readonly PluginCredentialCard[];
|
|
15
|
+
//# sourceMappingURL=credential-cards.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { parsePluginCredentialCards } from '../lifecycle/credential-card-metadata.js';
|
|
2
|
+
// Declaration parsing stays here; the host binds trusted contributions and mail-card precedence.
|
|
3
|
+
export { parsePluginCredentialCards, parseCredentialCardUsedFor } from '../lifecycle/credential-card-metadata.js';
|
|
4
|
+
/** Reuse Jini's active, trusted-package gate and contained manifest read. */
|
|
5
|
+
export const credentialCardsContribution = {
|
|
6
|
+
filename: 'plugin.json', contribution: 'credential cards', kind: 'data',
|
|
7
|
+
parse: input => parsePluginCredentialCards(input), load: ({ descriptor, plugin }) => ({ ...descriptor, pluginId: plugin.pluginId }),
|
|
8
|
+
};
|
|
9
|
+
/** Preserve mail objects and ordering; duplicate targets retain mail priority, while conflicting
|
|
10
|
+
* API label owners are all refused. O(cards) time and space; no persistent ownership registry.
|
|
11
|
+
*/
|
|
12
|
+
export function mergePluginCredentialCards({ mailCards, manifestCards }, options = {}) {
|
|
13
|
+
const cards = [...mailCards, ...manifestCards];
|
|
14
|
+
const conflictingLabels = conflictingApiLabels({ cards });
|
|
15
|
+
const counts = new Map();
|
|
16
|
+
for (const card of cards)
|
|
17
|
+
counts.set(card.providerId, (counts.get(card.providerId) ?? 0) + 1);
|
|
18
|
+
const accepted = manifestCards.filter(card => {
|
|
19
|
+
if (counts.get(card.providerId) === 1)
|
|
20
|
+
return true;
|
|
21
|
+
(options.onRefusal ?? console.warn)(`duplicate plugin credential card target '${card.providerId}' was refused`);
|
|
22
|
+
return false;
|
|
23
|
+
});
|
|
24
|
+
return [...mailCards, ...accepted].filter(card => {
|
|
25
|
+
if (!isApiCard({ value: card }) || !conflictingLabels.has(card.label))
|
|
26
|
+
return true;
|
|
27
|
+
(options.onRefusal ?? console.warn)(`duplicate API credential label '${card.label}' from '${card.pluginId ?? card.providerId}' was refused`);
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Compare effective API labels, including descriptor-backed mail cards, before discarding targets.
|
|
32
|
+
* Distinct cards of one plugin may share its row; two plugins cannot. O(cards) time and space.
|
|
33
|
+
*/
|
|
34
|
+
function conflictingApiLabels({ cards }, _options = {}) {
|
|
35
|
+
const owners = new Map();
|
|
36
|
+
const conflicts = new Set();
|
|
37
|
+
for (const card of cards) {
|
|
38
|
+
if (!isApiCard({ value: card }))
|
|
39
|
+
continue;
|
|
40
|
+
const owner = card.pluginId ?? card.providerId;
|
|
41
|
+
if (owners.has(card.label) && owners.get(card.label) !== owner)
|
|
42
|
+
conflicts.add(card.label);
|
|
43
|
+
owners.set(card.label, owner);
|
|
44
|
+
}
|
|
45
|
+
return conflicts;
|
|
46
|
+
}
|
|
47
|
+
/** Missing saveKind retains the original API-card contract. */
|
|
48
|
+
function isApiCard({ value }, _options = {}) { return value.saveKind === undefined || value.saveKind === "api"; }
|
|
49
|
+
//# sourceMappingURL=credential-cards.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PluginCredentialCard } from '@jini-ai/core/contracts/credentials';
|
|
2
|
+
import type { ToolMetadataById } from '@jini-ai/core';
|
|
3
|
+
import { type AgentToolDefinition, type DerivedRiskByToolId, type ToolExecutionContext, type ToolHandler, type ToolRegistration } from '@jini-ai/core';
|
|
4
|
+
/** Host credential kinds delegate to the existing domain authorization and sealed-store owners.
|
|
5
|
+
* Jini owns the secret-card lifecycle; this module only routes non-secret model metadata.
|
|
6
|
+
*/
|
|
7
|
+
export interface CredentialSaveAdapters {
|
|
8
|
+
readonly apiCreate: ToolHandler;
|
|
9
|
+
readonly apiRotate: ToolHandler;
|
|
10
|
+
readonly mediaProvider: ToolHandler;
|
|
11
|
+
readonly sourceControl: ToolHandler;
|
|
12
|
+
readonly publishHost: ToolHandler;
|
|
13
|
+
readonly agentPluginToken: ToolHandler;
|
|
14
|
+
readonly pluginProvider: ToolHandler;
|
|
15
|
+
/** A provider plugin's settings card (`saveKind: "provider-settings"`); absent where no settings store is wired. */
|
|
16
|
+
readonly providerSettings?: ToolHandler;
|
|
17
|
+
}
|
|
18
|
+
/** @agent-note The host supplies its exact product description, including examples and tool navigation. No default description is selected here. */
|
|
19
|
+
export interface CredentialSaveMessages {
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly oauthRefusal: string;
|
|
22
|
+
}
|
|
23
|
+
/** @agent-note The host supplies its reviewed metadata, public tool id and credential categories. Save adapters keep authorization and persistence in that host. */
|
|
24
|
+
export declare function createCredentialSaveTools({ metadata: toolMetadata, toolId: CREDENTIAL_SAVE_TOOL_ID, categories: CUSTOM_CREDENTIAL_CATEGORIES, messages, catalogModule }: {
|
|
25
|
+
metadata: ToolMetadataById;
|
|
26
|
+
toolId: string;
|
|
27
|
+
categories: readonly string[];
|
|
28
|
+
messages: CredentialSaveMessages;
|
|
29
|
+
catalogModule: string;
|
|
30
|
+
}, _optional?: Record<string, never>): {
|
|
31
|
+
credentialSaveCatalog: AgentToolDefinition[];
|
|
32
|
+
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[];
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=credential-save-tool.d.ts.map
|