@jini-ai/core 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.
Files changed (60) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/approval.d.ts +34 -3
  3. package/dist/approval.js +27 -4
  4. package/dist/batch-tool-inputs.d.ts +13 -0
  5. package/dist/batch-tool-inputs.js +37 -6
  6. package/dist/contracts/cards.d.ts +382 -0
  7. package/dist/contracts/cards.js +2 -0
  8. package/dist/contracts/content-types.d.ts +32 -0
  9. package/dist/contracts/content-types.js +3 -0
  10. package/dist/contracts/credentials.d.ts +402 -0
  11. package/dist/contracts/credentials.js +2 -0
  12. package/dist/contracts/hosted-mcp/config.d.ts +253 -0
  13. package/dist/contracts/hosted-mcp/config.js +2 -0
  14. package/dist/contracts/hosted-mcp/record.d.ts +198 -0
  15. package/dist/contracts/hosted-mcp/record.js +2 -0
  16. package/dist/contracts/hosted-mcp/vocabulary.d.ts +14 -0
  17. package/dist/contracts/hosted-mcp/vocabulary.js +2 -0
  18. package/dist/contracts/hosted-mcp.d.ts +5 -0
  19. package/dist/contracts/hosted-mcp.js +2 -0
  20. package/dist/contracts/mail/adapter-module.d.ts +31 -0
  21. package/dist/contracts/mail/adapter-module.js +2 -0
  22. package/dist/contracts/mail/engine-contracts.d.ts +130 -0
  23. package/dist/contracts/mail/engine-contracts.js +2 -0
  24. package/dist/contracts/mail/ports.d.ts +93 -0
  25. package/dist/contracts/mail/ports.js +3 -0
  26. package/dist/contracts/mail/provider.d.ts +84 -0
  27. package/dist/contracts/mail/provider.js +2 -0
  28. package/dist/contracts/mail.d.ts +128 -0
  29. package/dist/contracts/mail.js +3 -0
  30. package/dist/contracts/oauth/details.d.ts +46 -0
  31. package/dist/contracts/oauth/details.js +2 -0
  32. package/dist/contracts/oauth/flow.d.ts +253 -0
  33. package/dist/contracts/oauth/flow.js +2 -0
  34. package/dist/contracts/oauth.d.ts +139 -0
  35. package/dist/contracts/oauth.js +2 -0
  36. package/dist/contracts/server.d.ts +84 -0
  37. package/dist/contracts/server.js +15 -0
  38. package/dist/contracts/vault/ports.d.ts +34 -0
  39. package/dist/contracts/vault/ports.js +2 -0
  40. package/dist/contracts/vault/records.d.ts +149 -0
  41. package/dist/contracts/vault/records.js +2 -0
  42. package/dist/contracts/vault/vendor-credential-sets.d.ts +75 -0
  43. package/dist/contracts/vault/vendor-credential-sets.js +7 -0
  44. package/dist/contracts/vault.d.ts +14 -0
  45. package/dist/contracts/vault.js +2 -0
  46. package/dist/index.d.ts +1 -0
  47. package/dist/primitives/http.d.ts +2 -0
  48. package/dist/settings/agent-value-write-tools.d.ts +3 -1
  49. package/dist/settings/agent-value-write-tools.js +11 -4
  50. package/dist/settings/tool-registrations.js +1 -1
  51. package/dist/surface-cards.d.ts +2 -0
  52. package/dist/surface-cards.js +2 -0
  53. package/dist/text/descriptor-i18n.d.ts +24 -0
  54. package/dist/text/descriptor-i18n.js +65 -0
  55. package/dist/text/index.d.ts +2 -0
  56. package/dist/text/index.js +1 -0
  57. package/dist/tool-metadata-types.d.ts +6 -0
  58. package/dist/user-facing-error.d.ts +28 -1
  59. package/dist/user-facing-error.js +87 -4
  60. package/package.json +50 -2
@@ -0,0 +1,253 @@
1
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
2
+ import type { ISODateTime } from '../../primitives/time.js';
3
+ import type { UUID } from '../../primitives/ids.js';
4
+ import type { SealedSecret } from '../vault.js';
5
+ import type { ExternalMcpAuthMode, ExternalMcpOAuthStatus, ExternalMcpTransport } from './vocabulary.js';
6
+ /** Supplies a current token per exchange. Undefined preserves configured headers. */
7
+ /** @agent-note Supplied by the host per exchange (re-exported by `@jini-ai/mcp/federation`); returning `undefined` keeps configured headers. A shared binding that is missing or revoked must throw, never fall back to launch headers. */
8
+ export type McpBearerTokenSupplier = (request: {
9
+ readonly url: string;
10
+ }, options?: {
11
+ readonly signal?: AbortSignal | undefined;
12
+ }) => string | undefined | Promise<string | undefined>;
13
+ /** The decrypted, validated domain shape. Only ever exists in memory. */
14
+ /**
15
+ * Where a resolved connection's credentials go, which is the one thing the two transports do
16
+ * genuinely differently.
17
+ *
18
+ * A union rather than a flat shape with an empty `command` on one arm and an empty `url` on the
19
+ * other: a config carrying both is not a degraded row to tolerate, it is a bug, and this makes it
20
+ * unrepresentable. It mirrors `@jini-ai/mcp/federation`'s `McpLaunchSpec` deliberately — this is
21
+ * the same distinction one layer earlier, before policy is attached.
22
+ */
23
+ /** @agent-note Built only by the store after credentials are resolved; never persisted. A target carrying both a command and a URL is unrepresentable on purpose. */
24
+ export type ExternalMcpServerTarget = {
25
+ readonly kind: "stdio";
26
+ readonly command: string;
27
+ readonly args: string[];
28
+ /**
29
+ * The child process's environment. For an `oauth` connection this ALREADY contains the
30
+ * resolved access token under the operator's chosen variable name — resolution happens before
31
+ * this shape exists, so nothing downstream needs to know whether a value came from a pasted
32
+ * block or a token endpoint.
33
+ */
34
+ readonly env: Record<string, string>;
35
+ } | {
36
+ readonly kind: "streamable_http";
37
+ readonly url: string;
38
+ /**
39
+ * Request headers, carrying the resolved access token as `Authorization: Bearer ...` for an
40
+ * `oauth` connection. The hosted analogue of `env` above, and resolved at the same point for
41
+ * the same reason.
42
+ */
43
+ readonly headers: Record<string, string>;
44
+ /** Captures the selected shared connection; missing/revoked bindings refuse instead of using launch headers. */
45
+ readonly bearerToken?: McpBearerTokenSupplier;
46
+ };
47
+ /** @agent-note Produced by the store from one saved row; `admissionRevision` must be the revision of that same row so the per-call gate compares like with like. */
48
+ export interface ExternalMcpServerConfig {
49
+ /** Retained for matching the reviewed plugin declaration when the roster is loaded. */
50
+ provisionedByPluginId?: string;
51
+ serverId: string;
52
+ label: string;
53
+ transport: ExternalMcpTransport;
54
+ authMode: ExternalMcpAuthMode;
55
+ enabled: boolean;
56
+ allowedToolNames: string[];
57
+ /** The operator's second, write-authorization list. See {@link ExternalMcpServerRecord
58
+ * .writeAllowedToolNames}. Passed through untouched for `trust.ts` to enforce. */
59
+ writeAllowedToolNames: string[];
60
+ target: ExternalMcpServerTarget;
61
+ /** {@link externalMcpAdmissionRevision} of the row this config was resolved from — carried onto
62
+ * {@link ResolvedFederatedConnection.config}'s `origin` by {@link toResolvedFederatedConnections}
63
+ * for the hosted-MCP per-call revocation gate. */
64
+ admissionRevision: string;
65
+ }
66
+ /** The OAuth half of {@link ExternalMcpServerView}. Non-secret by construction: no access token, no
67
+ * refresh token and no client secret appears here or in anything that builds it. */
68
+ /** @agent-note Built from plain-text columns only; nothing is unsealed to produce it and no secret may be added. */
69
+ export interface ExternalMcpOAuthView {
70
+ providerId: string | null;
71
+ grant: string | null;
72
+ clientId: string | null;
73
+ scopes: string[];
74
+ status: ExternalMcpOAuthStatus;
75
+ /** Plaintext expiry, straight off the row — nothing is unsealed to produce it. */
76
+ expiresAt: ISODateTime | null;
77
+ tokenEnvName: string | null;
78
+ /** Whether an access TOKEN is stored. Presence, never the value. Decided from
79
+ * PLAINTEXT columns only; see {@link externalMcpRecordHasStoredToken} for why it must not unseal
80
+ * and for the one state it under-reports. */
81
+ hasStoredToken: boolean;
82
+ }
83
+ /** The read model the admin tab renders — never carries env VALUES or any OAuth secret. */
84
+ /** @agent-note `TokenHint` is host input: the host binds its own credential-hint shape (for example the platform `CredentialTokenHint`). Never carries env values, tokens or client secrets. */
85
+ export interface ExternalMcpServerView<TokenHint = never> {
86
+ serverId: string;
87
+ label: string;
88
+ /** Which Agent Plugin auto-provisioned this row, or `null` for one an operator created by hand —
89
+ * what lets the admin tab (and a future uninstall flow) tell the two apart. */
90
+ provisionedByPluginId: string | null;
91
+ transport: string;
92
+ authMode: string;
93
+ enabled: boolean;
94
+ command: string;
95
+ url: string | null;
96
+ args: string[];
97
+ allowedToolNames: string[];
98
+ /** The operator's second, write-authorization list. See {@link ExternalMcpServerRecord
99
+ * .writeAllowedToolNames}. */
100
+ writeAllowedToolNames: string[];
101
+ /** Who last changed {@link writeAllowedToolNames}, and when — so the tab can render "authorized by
102
+ * X on Y". `null` until that list is ever touched. */
103
+ writeGrantsUpdatedByPrincipalId: string | null;
104
+ writeGrantsUpdatedAt: ISODateTime | null;
105
+ /** Variable names only. The tab masks values it never receives. */
106
+ envNames: string[];
107
+ /** Whether a `static_env` access token is stored. Presence only, decided from plaintext columns —
108
+ * see {@link externalMcpRecordHasStaticAccessToken}. */
109
+ hasAccessToken: boolean;
110
+ accessTokenHint?: TokenHint | null;
111
+ envTokenHints?: Readonly<Record<string, TokenHint>>;
112
+ /** For `stdio` + `static_env`: the child env variable that receives that token. A NAME, so plaintext. */
113
+ accessTokenEnvName: string | null;
114
+ oauth: ExternalMcpOAuthView;
115
+ }
116
+ /**
117
+ * The OAuth half of a save. Every field follows the same three-state rule `env` established:
118
+ * ABSENT keeps what is stored, a STRING replaces it, an EMPTY string clears it.
119
+ *
120
+ * Structural validation only happens here — charsets, lengths, required-when-oauth. Whether
121
+ * `providerId` names a registered descriptor, and whether the endpoints form a usable provider, is
122
+ * the sign-in service's call: resolving a descriptor is the flow module's job, and importing its
123
+ * registry here would put the store back in the business of the thing its header says it is not.
124
+ */
125
+ /** @agent-note Three-state per field: absent keeps, a string replaces, an empty string clears. Structural validation only; provider resolution belongs to the sign-in service. */
126
+ export interface SaveExternalMcpOAuthInput {
127
+ /** A registered provider id, or empty to define this connection's own endpoints below — or, on a
128
+ * REMOTE connection, to leave both to discovery at connect time. */
129
+ providerId?: string;
130
+ grant?: string;
131
+ /** Empty on a remote connection means "mint one by dynamic client registration at connect". */
132
+ clientId?: string;
133
+ /** SECRET. Sealed, never returned by any read model. */
134
+ clientSecret?: string;
135
+ /** Raw operator input, comma- or space-separated. */
136
+ scopes?: string;
137
+ /** For `stdio`: which child env variable receives the access token. */
138
+ tokenEnvName?: string;
139
+ authorizationEndpoint?: string;
140
+ tokenEndpoint?: string;
141
+ deviceAuthorizationEndpoint?: string;
142
+ }
143
+ /** @agent-note Raw operator input; the store validates and seals. `principalId` is host-supplied identity; `provisionedByPluginId` is set only by the plugin provisioning seam on the creating save. */
144
+ export interface SaveExternalMcpServerInput {
145
+ workspaceId: UUID;
146
+ serverId: string;
147
+ label?: string;
148
+ transport: string;
149
+ /** One of {@link EXTERNAL_MCP_AUTH_MODES}. Absent keeps an existing row's mode, or defaults a new
150
+ * row to `static_env` — the mode every row written before this field existed effectively had. */
151
+ authMode?: string;
152
+ enabled: boolean;
153
+ command: string;
154
+ /** Endpoint for a remote transport. Required for `streamable_http`, ignored for `stdio`. */
155
+ url?: string;
156
+ /** Raw operator input, space-separated. */
157
+ args: string;
158
+ /** Raw operator input, comma-separated remote tool names. */
159
+ allowedToolNames: string;
160
+ /** Raw operator input, comma-separated remote tool names the operator separately authorizes to
161
+ * write. Same shape and same "resent in full on every save" convention as {@link
162
+ * allowedToolNames} — this is NOT tri-state like {@link env}, because the admin tab shows this
163
+ * list in the clear and can always resend it. Rejected at save if it names a tool absent
164
+ * from {@link allowedToolNames}. Defaulted defensively to `""` if a caller omits it, so a route or
165
+ * test written before this field existed degrades to "no write grants" rather than throwing. */
166
+ writeAllowedToolNames: string;
167
+ /** Raw operator input, `KEY=VALUE` per line. `undefined` leaves an existing block untouched. */
168
+ env?: string;
169
+ /** SECRET, `static_env` only. Sealed, never returned by any read model. Three-state like {@link env}:
170
+ * `undefined` keeps the stored token, a string replaces it, `""` clears it. Delivered as
171
+ * {@link accessTokenEnvName} to a stdio child, or as `Authorization: Bearer` to a hosted server. */
172
+ accessToken?: string;
173
+ /** For `stdio` + `static_env`: which child env variable receives {@link accessToken}. `undefined`
174
+ * keeps the stored name. */
175
+ accessTokenEnvName?: string;
176
+ oauth?: SaveExternalMcpOAuthInput;
177
+ /**
178
+ * Set ONLY by the host's trusted plugin provisioner, on the ONE save that creates a brand-new
179
+ * plugin-provisioned row. Every other caller (including administrative routes and assistant
180
+ * tools) omits this field entirely, and an omitted field PRESERVES whatever the
181
+ * row already has — the same three-state rule `env` establishes, minus the "empty string clears
182
+ * it" arm: nothing should ever intentionally clear this column once set, so no clear signal is
183
+ * defined for it.
184
+ */
185
+ provisionedByPluginId?: string;
186
+ /**
187
+ * The principal performing this save, supplied by the host's authenticated request context. Used
188
+ * ONLY to attribute a change to {@link writeAllowedToolNames} — see {@link
189
+ * resolveWriteGrantAttribution}. Required so every new caller has to supply one; a caller that
190
+ * never touches the write list never reads it, so an un-migrated caller cannot crash on its
191
+ * absence (see that function's doc).
192
+ */
193
+ principalId: string;
194
+ }
195
+ /** @agent-note Saved payload v1 inside the sealed OAuth envelope. Member names and JSON serialization are the saved format: keep them byte-identical, add only optional members. */
196
+ export interface ExternalMcpSealedOAuthPayload {
197
+ /**
198
+ * A `static_env` row's operator-pasted access token — the only member such a row's blob ever holds
199
+ * (see {@link externalMcpRecordHasStaticAccessToken}). Additive to payload v1: the OAuth flow never
200
+ * reads a `static_env` row (`requireOAuthRecord` refuses it), so no older reader can mishandle it.
201
+ */
202
+ readonly staticAccessToken?: string;
203
+ readonly clientSecret?: string;
204
+ readonly tokens?: {
205
+ readonly accessToken: string;
206
+ readonly refreshToken: string | null;
207
+ readonly tokenType: string;
208
+ readonly scopes: readonly string[];
209
+ readonly expiresAt: ISODateTime | null;
210
+ };
211
+ }
212
+ /**
213
+ * Seals an OAuth payload, or resolves `null` when there is nothing worth sealing.
214
+ *
215
+ * An empty payload seals to `null` rather than to a blob containing `{}`, so `sealedOAuth !== null`
216
+ * is a truthful answer to "does this connection hold anything secret". It is NOT an answer to "does
217
+ * it hold a token" — a cleared connection keeps its client secret in that blob — which is why
218
+ * {@link externalMcpRecordHasStoredToken} reads the plaintext columns instead.
219
+ *
220
+ * @throws {ExternalMcpSecretStoreUnconfiguredError} When no site key is available.
221
+ * @complexity O(1) — one seal.
222
+ */
223
+ /**
224
+ * A sealed OAuth blob with its compatibility lineage. Vault identity travels with the opaque
225
+ * envelope so carried credentials keep the exact ID/context they were authenticated under.
226
+ * The server repository commits that vault row, its pointer, status and expiry together.
227
+ */
228
+ /** @agent-note Opaque envelope plus lineage; carry it unchanged so the exact vault identity/context it was sealed under is kept. */
229
+ export interface SealedExternalMcpOAuth {
230
+ readonly sealedOAuth: SealedSecret | null;
231
+ readonly oauthAadVersion: number;
232
+ }
233
+ /** What an authorization-code connect hands back to the route. Carries no secret. */
234
+ /** @agent-note Returned by the sign-in service to the host route; carries no secret. */
235
+ export interface ExternalMcpAuthorizationStart {
236
+ readonly kind: "redirect_required";
237
+ readonly authorizationUrl: string;
238
+ readonly expiresAt: string;
239
+ }
240
+ /** What a device-grant connect hands back. `deviceCode` is deliberately absent — it stays
241
+ * server-side, and the poll route looks it up by server id. */
242
+ /** @agent-note Returned by the sign-in service; the device code itself stays server-side. */
243
+ export interface ExternalMcpDeviceStart {
244
+ readonly kind: "device_code";
245
+ readonly userCode: string;
246
+ readonly verificationUri: string;
247
+ readonly verificationUriComplete: string | null;
248
+ readonly expiresAt: ISODateTime;
249
+ readonly intervalSeconds: number;
250
+ }
251
+ /** @agent-note Discriminated by `kind`; hosts render each arm, packages never build host links here. */
252
+ export type ExternalMcpConnectStart = ExternalMcpAuthorizationStart | ExternalMcpDeviceStart;
253
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,198 @@
1
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
2
+ import type { Clock as ClockPort, ISODateTime } from '../../primitives/time.js';
3
+ import type { UUID } from '../../primitives/ids.js';
4
+ import type { KeyringPort, SealedSecret, SecretSealerPort } from '../vault.js';
5
+ /** Exact source identity and prior access decision captured before an access-only update; no credential bytes. */
6
+ /** @agent-note Built only by `externalMcpAccessSnapshot` from the row the host just read; compared field-for-field by the repo's `updateAccessIfCurrent`. Contains no credential bytes; `admissionRevision` is the sha256 hex of the row's source identity. */
7
+ export interface ExternalMcpAccessSnapshot {
8
+ readonly admissionRevision: string;
9
+ readonly enabled: boolean;
10
+ readonly allowedToolNames: string | null;
11
+ readonly writeAllowedToolNames: string | null;
12
+ readonly writeGrantsUpdatedByPrincipalId: string | null;
13
+ readonly writeGrantsUpdatedAt: ISODateTime | null;
14
+ readonly provisionedByPluginId: string | null;
15
+ }
16
+ /** The access-only command accepted by the owner after a bound human approval. */
17
+ /** @agent-note The access-only command a host accepts after a bound human approval; `expected` must be the snapshot captured before the approval was shown, never re-read after. */
18
+ export interface ExternalMcpApprovedAccess {
19
+ readonly workspaceId: string;
20
+ readonly serverId: string;
21
+ readonly expected: ExternalMcpAccessSnapshot;
22
+ readonly access: {
23
+ readonly enabled: boolean;
24
+ readonly allowedToolNames: readonly string[];
25
+ readonly writeAllowedToolNames: readonly string[];
26
+ };
27
+ readonly principalId: string;
28
+ }
29
+ /** @agent-note The ONE canonical saved row. Fulfilled by the host's repository (SQL or memory). Field names, `null`s, sealed envelopes and plain-text JSON columns are the saved format: never normalize, reseal or rename on read; writes keep serialization/AAD/ids. `transport`/`authMode`/`oauthGrant`/`oauthStatus` stay `string` so unknown saved values load. Never copy this shape into a host type. */
30
+ export interface ExternalMcpServerRecord {
31
+ workspaceId: UUID;
32
+ serverId: string;
33
+ label: string | null;
34
+ /** The Agent Plugin id that auto-provisioned this row, or `null` for an operator-created one.
35
+ * @agent-note Only the trusted plugin provisioner sets this on creation; subsequent saves preserve it and never clear it. */
36
+ provisionedByPluginId: string | null;
37
+ transport: string;
38
+ /** How credentials are obtained. Independent of `transport` — see this file's header. */
39
+ authMode: string;
40
+ enabled: boolean;
41
+ command: string | null;
42
+ /** Endpoint for a remote transport. NULL for `stdio`, where `command` is used instead. */
43
+ url: string | null;
44
+ /** JSON array of argv strings, as stored. */
45
+ args: string | null;
46
+ /** JSON array of admissible remote tool names, as stored. */
47
+ allowedToolNames: string | null;
48
+ /**
49
+ * JSON array of remote tool names separately authorized to write, as stored. `trust.ts` R3's
50
+ * override — a tool declaring `readOnlyHint: false` is admitted only when it also appears in
51
+ * {@link allowedToolNames}. See `@jini-ai/mcp/federation`'s `FederatedMcpConnectionConfig
52
+ * .writeAllowedToolNames` for the full argument.
53
+ */
54
+ writeAllowedToolNames: string | null;
55
+ /** Principal who last CHANGED {@link writeAllowedToolNames}'s contents. `null` until that list is
56
+ * ever touched, or for a row written before this column existed. */
57
+ writeGrantsUpdatedByPrincipalId: string | null;
58
+ /** When {@link writeAllowedToolNames} was last changed. `null` under the same condition. */
59
+ writeGrantsUpdatedAt: ISODateTime | null;
60
+ /** JSON array of env variable names, as stored. Plaintext by design. */
61
+ envNames: string | null;
62
+ sealedEnv: SealedSecret | null;
63
+ /** Which registered provider descriptor this connection authorizes against. */
64
+ oauthProviderId: string | null;
65
+ oauthGrant: string | null;
66
+ /** Plaintext: a client id is not a secret — it travels in the authorization URL by design. */
67
+ oauthClientId: string | null;
68
+ /** JSON object of operator-typed endpoints, when this connection defines its own provider instead
69
+ * of naming a registered one. Non-secret. */
70
+ oauthEndpointsJson: string | null;
71
+ /** JSON array of requested scopes. Non-secret. */
72
+ oauthScopesJson: string | null;
73
+ oauthStatus: string | null;
74
+ /**
75
+ * PLAINTEXT absolute expiry of the stored access token, beside the sealed blob rather than inside
76
+ * it. Exactly the split this file already makes for `envNames` beside `sealedEnv`, and here it is
77
+ * load-bearing rather than merely convenient: expiry has to be checkable by a scheduler and
78
+ * displayable in the admin tab, and neither can afford a keyring round trip — nor should either be
79
+ * a code path that decrypts a live token to answer a question about when it dies.
80
+ */
81
+ oauthExpiresAt: ISODateTime | null;
82
+ /**
83
+ * For `stdio` + `oauth`: which child-process environment variable receives the access token.
84
+ * Plaintext because it is a NAME, exactly as `envNames` is.
85
+ */
86
+ oauthTokenEnvName: string | null;
87
+ /**
88
+ * Cross-process refresh lease. Held while one process is redeeming the refresh token, so the other
89
+ * — the admin web server and the agent daemon are separate processes with separate database
90
+ * handles — does not redeem the same single-use rotating token. Plaintext for the same reason as
91
+ * `oauthExpiresAt`: a lease you must decrypt to inspect is a lease you cannot break after a crash.
92
+ */
93
+ oauthRefreshLeaseUntil: ISODateTime | null;
94
+ /** Sealed `{ clientSecret?, tokens? }`.
95
+ * @agent-note Writers must open, update and reseal the whole payload, preserving members they did not explicitly change or clear; writing tokens alone would erase the client secret. */
96
+ sealedOAuth: SealedSecret | null;
97
+ /** Compatibility read field; normalized vault envelopes use lineage 1. */
98
+ aadVersion: number;
99
+ /** Compatibility read field; actual authenticated context lives on the vault row. */
100
+ oauthAadVersion: number;
101
+ createdAt: ISODateTime;
102
+ updatedAt: ISODateTime;
103
+ }
104
+ /** A conditional access-only write. Credential and connection configuration are never replaced. */
105
+ /** @agent-note Built by the host from an `ExternalMcpApprovedAccess`; the repository applies it atomically or returns `false`. Credential and connection columns are never part of it. */
106
+ export interface ExternalMcpAccessUpdate {
107
+ readonly workspaceId: UUID;
108
+ readonly serverId: string;
109
+ readonly expected: ExternalMcpAccessSnapshot;
110
+ readonly access: {
111
+ readonly enabled: boolean;
112
+ readonly allowedToolNames: string;
113
+ readonly writeAllowedToolNames: string;
114
+ };
115
+ readonly principalId: string;
116
+ readonly nowIso: ISODateTime;
117
+ }
118
+ /** Workspace-scoped persistence. Multi-row per workspace, so list/upsert/delete rather
119
+ * than a single-row find/upsert. */
120
+ /** @agent-note Fulfilled by the host (SQL or memory adapter). The store, the sign-in service and the plugin connect seam must receive the SAME repository instance, because sealed envelopes carry private repository context only that repository rebuilds. */
121
+ export interface ExternalMcpServerRepoPort {
122
+ /** @agent-note Workspace-scoped; returns whole saved rows, never views. */
123
+ listByWorkspaceId(workspaceId: UUID): Promise<ExternalMcpServerRecord[]>;
124
+ /** @agent-note Returns the whole saved row or `null`; at most one row read per call. */
125
+ findByServerId(input: {
126
+ workspaceId: UUID;
127
+ serverId: string;
128
+ }): Promise<ExternalMcpServerRecord | null>;
129
+ /** @agent-note Writes the whole row in one transaction (row, vault pointer, status and expiry together). */
130
+ upsert(record: ExternalMcpServerRecord): Promise<void>;
131
+ /** Compare the approved snapshot and update access atomically, preserving credential columns. */
132
+ /** @agent-note Compare-and-set against `expected`; `false` means the row changed since approval and nothing was written. */
133
+ updateAccessIfCurrent(required: ExternalMcpAccessUpdate, optional?: Record<string, never>): Promise<boolean>;
134
+ /** @agent-note Returns whether a row existed. */
135
+ deleteByServerId(input: {
136
+ workspaceId: UUID;
137
+ serverId: string;
138
+ }): Promise<boolean>;
139
+ /**
140
+ * Atomically claims the OAuth refresh lease for one row, iff nobody holds an unexpired one.
141
+ *
142
+ * A COMPARE-AND-SET, not a read-then-write, and that is the entire point: `upsert` cannot express
143
+ * it, because between reading "no lease" and writing "my lease" the other process does the same
144
+ * and both go on to redeem the same single-use rotating refresh token. One statement with the
145
+ * condition in its `WHERE` is what makes the loser observable.
146
+ *
147
+ * @returns `true` when this caller now holds the lease.
148
+ */
149
+ /** @agent-note Compare-and-set in one statement; only the caller that gets `true` may redeem the refresh token. */
150
+ tryClaimOAuthRefreshLease(input: {
151
+ workspaceId: UUID;
152
+ serverId: string;
153
+ /** Now, per the caller's clock. A lease at or before this instant is treated as abandoned. */
154
+ nowIso: ISODateTime;
155
+ /** When this claim expires, so a crashed holder cannot wedge the connection forever. */
156
+ leaseUntil: ISODateTime;
157
+ }): Promise<boolean>;
158
+ /** Releases the lease unconditionally. Safe when not held — the lease is advisory and
159
+ * time-bounded, so a spurious release costs at most one extra refresh attempt. */
160
+ /** @agent-note Unconditional and idempotent; call after every claimed refresh, success or failure. */
161
+ releaseOAuthRefreshLease(input: {
162
+ workspaceId: UUID;
163
+ serverId: string;
164
+ }): Promise<void>;
165
+ }
166
+ /** @agent-note Host-wired: `repo` is the same instance the sign-in service gets; `sealer`/`keyring` usually from `@jini-ai/platform/secrets`; `clock` from the host. */
167
+ export interface ExternalMcpStoreDeps {
168
+ repo: ExternalMcpServerRepoPort;
169
+ sealer: SecretSealerPort;
170
+ keyring: KeyringPort;
171
+ clock: ClockPort;
172
+ }
173
+ /**
174
+ * Resolves an `oauth` row's contribution to the child environment.
175
+ *
176
+ * Kept behind a port rather than inlined, so this store never imports a token endpoint, a refresher,
177
+ * or an OAuth implementation at all: the boot path asks for a token, and whoever wired the daemon decides where
178
+ * it comes from. That is also what keeps this module testable without a network.
179
+ */
180
+ /** @agent-note Fulfilled by the sign-in service's `tokenResolver`; the store calls it once per OAuth row read and never imports OAuth itself. */
181
+ export interface ExternalMcpOAuthTokenResolverPort {
182
+ /** Undefined identifies an existing local connection. Shared failures must throw, never fall back. */
183
+ /** @agent-note Optional; a shared-binding failure throws and never falls back to a local token. */
184
+ resolveSharedAccessToken?(input: {
185
+ serverId: string;
186
+ }): Promise<string | undefined>;
187
+ /**
188
+ * Returns the access token to inject, refreshing first when it is due.
189
+ *
190
+ * @throws When the connection needs re-authorization or the provider could not be reached. The
191
+ * caller turns that into a per-server failure entry rather than letting it abort the whole read.
192
+ */
193
+ /** @agent-note At most one leased refresh per call; throws a terminal error when re-authorization is needed. */
194
+ resolveAccessToken(input: {
195
+ serverId: string;
196
+ }): Promise<string>;
197
+ }
198
+ //# sourceMappingURL=record.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1,14 @@
1
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
2
+ /** @agent-note Saved as plain text in the row's `transport`; the record keeps `string` so an unknown saved value still loads. Runtime tuple: `SUPPORTED_EXTERNAL_MCP_TRANSPORTS` (`@jini-ai/mcp/federation/hosted`). Never rename a literal: saved rows and admission revisions carry it. */
3
+ export type ExternalMcpTransport = "stdio" | "streamable_http";
4
+ /** @agent-note Saved in `oauthGrant` as plain text (RFC 6749/8628 grant names). Runtime tuple: `EXTERNAL_MCP_OAUTH_GRANTS`. Never rename a literal. */
5
+ export type ExternalMcpOAuthGrant = "authorization_code" | "device_code";
6
+ /** @agent-note Saved in `authMode`; readers default an absent/unknown value to `static_env` via `resolveExternalMcpAuthMode` (host-wired from `@jini-ai/mcp/federation/hosted`). Part of the admission-revision hash input, so never rename a literal. */
7
+ export type ExternalMcpAuthMode = "none" | "static_env" | "oauth";
8
+ /** @agent-note Saved in `oauthStatus`; readers default an absent/unknown value to `disconnected` via `resolveExternalMcpOAuthStatus`. Never rename a literal. */
9
+ export type ExternalMcpOAuthStatus = "disconnected" | "pending" | "connected" | "needs_reauth";
10
+ /** Why an admitted federated tool is refused on THIS call. Every value pairs with one D3 message in
11
+ * {@link revocationMessage} — see that lookup for the exact, test-pinned wording. */
12
+ /** @agent-note Each value keys exactly one host-supplied refusal message; the host owns the wording and its tests pin it. Adding a value requires every host message table to add one. */
13
+ export type ExternalMcpRevocationReason = "removed" | "turned-off" | "disconnected" | "changed" | "tool-not-allowed" | "write-not-allowed" | "unverifiable";
14
+ //# sourceMappingURL=vocabulary.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vocabulary.js.map
@@ -0,0 +1,5 @@
1
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/mcp/federation/hosted` (values) and `@jini-ai/integrations/api-connections/hosted-mcp` (sign-in). */
2
+ export type * from './hosted-mcp/vocabulary.js';
3
+ export type * from './hosted-mcp/record.js';
4
+ export type * from './hosted-mcp/config.js';
5
+ //# sourceMappingURL=hosted-mcp.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hosted-mcp.js.map
@@ -0,0 +1,31 @@
1
+ import type { HttpClientPort } from '../../primitives/index.js';
2
+ import type { MailerPort } from './ports.js';
3
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
4
+ export interface MailAdapterCredential {
5
+ readonly token: string;
6
+ readonly baseUrl?: string;
7
+ readonly username?: string;
8
+ }
9
+ export interface MailAdapterKit {
10
+ /** Provider requests must use the guarded outbound HTTP seam so its egress policy applies. */
11
+ readonly httpClient: HttpClientPort;
12
+ }
13
+ export interface MailAdapterCreateContext {
14
+ readonly credential: MailAdapterCredential;
15
+ readonly kit: MailAdapterKit;
16
+ /** Sample at the point of use. Hosts normalize this to the real clock when omitted. */
17
+ readonly now?: () => Date;
18
+ /** Per-install configuration; only the provider module owns its schema and validation. */
19
+ readonly settings?: unknown;
20
+ }
21
+ /** Provider modules return the ordinary mail port; the shared contract names no vendor. */
22
+ export interface MailAdapterModule {
23
+ /** Optional host-resolved account connection for domain reads only. The host validates the
24
+ * HTTPS origin and plugin ownership; this credential must never replace the sending key. */
25
+ readonly domainReadConnection?: {
26
+ readonly serverId: string;
27
+ readonly baseUrl: string;
28
+ };
29
+ create(context: MailAdapterCreateContext): MailerPort;
30
+ }
31
+ //# sourceMappingURL=adapter-module.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=adapter-module.js.map
@@ -0,0 +1,130 @@
1
+ /** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/platform`. */
2
+ import type { MailAdapterCredential } from "./adapter-module.js";
3
+ import type { MailDomainState, MailProviderCapabilities, MailProviderRegistry, MailProviderSetting, MailStatus } from "./provider.js";
4
+ /** Metadata only: the host reads these facts before decrypting a credential. */
5
+ export interface MailCredentialFact {
6
+ readonly id: string;
7
+ readonly label: string;
8
+ readonly vaultRevision?: number;
9
+ readonly updatedAt: string;
10
+ }
11
+ /** Credential presence exposed in configuration reports; never a token or username. */
12
+ export interface MailProviderCredentialFacts {
13
+ readonly required: boolean;
14
+ readonly saved: boolean;
15
+ readonly label?: string;
16
+ readonly credentialId?: string;
17
+ readonly updatedAt?: string;
18
+ }
19
+ /** Declarative setup copy belongs to the host or plugin. */
20
+ export interface MailProviderField {
21
+ readonly key: string;
22
+ readonly label: string;
23
+ readonly type: "secret" | "text" | "url" | "email";
24
+ readonly required: boolean;
25
+ readonly defaultValue?: string;
26
+ readonly placeholder?: string;
27
+ readonly help?: string;
28
+ readonly helpUrl?: string;
29
+ }
30
+ export interface MailProviderSetup {
31
+ readonly fields: readonly MailProviderField[];
32
+ readonly helpUrl?: string;
33
+ }
34
+ /** Safe host-supplied projection; configuration building and product copy stay in the host. */
35
+ export interface MailProviderConfiguration {
36
+ readonly pluginId?: string;
37
+ readonly id: string;
38
+ readonly label: string;
39
+ readonly origin: "core" | "plugin";
40
+ readonly hosted: boolean;
41
+ readonly lanes: readonly ("transactional" | "bulk")[];
42
+ readonly capabilities: Pick<MailProviderCapabilities, "feedback" | "domainVerification" | "rateLimit">;
43
+ readonly credential: MailProviderCredentialFacts;
44
+ readonly selectable: boolean;
45
+ readonly refusal?: string;
46
+ readonly setup: MailProviderSetup;
47
+ }
48
+ export interface MailProviderConfigurationReport {
49
+ readonly setting: MailProviderSetting;
50
+ readonly providers: readonly MailProviderConfiguration[];
51
+ readonly refusals: readonly string[];
52
+ }
53
+ /** A provider failure safe for callers; contains neither credentials nor message bodies. */
54
+ export interface MailProviderError {
55
+ readonly at: string;
56
+ readonly providerId: string | null;
57
+ readonly source: "send" | "check";
58
+ readonly code?: string;
59
+ readonly message: string;
60
+ }
61
+ /** Alias the provider's existing verdict vocabulary instead of defining another taxonomy. */
62
+ export type ProviderDomainState = MailDomainState;
63
+ /** Provider verification is independent of DNS answers and credential presence. */
64
+ export type SenderDomainVerification = {
65
+ state: ProviderDomainState;
66
+ domain: string;
67
+ providerId: string;
68
+ } | {
69
+ state: "no_sender";
70
+ providerId: string | null;
71
+ } | {
72
+ state: "no_provider";
73
+ domain: string;
74
+ providerId: string | null;
75
+ } | {
76
+ state: "unsupported";
77
+ domain: string;
78
+ providerId: string;
79
+ } | {
80
+ state: "unknown";
81
+ domain?: string;
82
+ providerId: string | null;
83
+ reason: string;
84
+ };
85
+ export interface MailStatusReport extends MailStatus {
86
+ readonly senderDomainVerification?: SenderDomainVerification;
87
+ readonly providers: readonly MailProviderConfiguration[];
88
+ readonly refusals: readonly string[];
89
+ readonly checkedAt: string;
90
+ readonly lastError?: MailProviderError;
91
+ }
92
+ export type MailProviderCheck = {
93
+ ok: true;
94
+ label: string;
95
+ } | {
96
+ ok: false;
97
+ reason: string;
98
+ };
99
+ /** Host-built catalog: trusted loading, labels and setup copy remain outside the engine. */
100
+ export interface MailProviderCatalog {
101
+ readonly registry: MailProviderRegistry;
102
+ readonly pluginIds: readonly string[];
103
+ readonly refusals: readonly string[];
104
+ credentialLabelFor(required: {
105
+ id: string;
106
+ }): string | undefined;
107
+ setupFor(required: {
108
+ id: string;
109
+ }): MailProviderSetup;
110
+ }
111
+ /** Host settings adapter; reads do not infer provider selection from saved credentials. */
112
+ export interface MailProviderSettingPort {
113
+ read(required: Record<string, never>): Promise<MailProviderSetting | null>;
114
+ write(required: {
115
+ setting: MailProviderSetting;
116
+ }): Promise<void>;
117
+ }
118
+ /** Host owns metadata lookup and decryption. Metadata may fail independently of key resolution. */
119
+ export interface MailCredentialPort {
120
+ readFact(required: {
121
+ label: string;
122
+ }): Promise<MailCredentialFact | undefined>;
123
+ resolve(required: {
124
+ catalog: MailProviderCatalog;
125
+ id: string;
126
+ }): Promise<MailAdapterCredential | null>;
127
+ }
128
+ /** Read-only provider verdict; implementations return unknown on lookup/provider failures. */
129
+ export type SenderDomainVerificationPort = () => Promise<SenderDomainVerification>;
130
+ //# sourceMappingURL=engine-contracts.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=engine-contracts.js.map