@jini-ai/integrations 0.6.19 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/api-connections/access-token.js +4 -14
  3. package/dist/api-connections/account-actions.d.ts +6 -1
  4. package/dist/api-connections/attempt-state.d.ts +2 -2
  5. package/dist/api-connections/attempt-state.js +10 -11
  6. package/dist/api-connections/authorization.js +13 -20
  7. package/dist/api-connections/budgets.d.ts +91 -0
  8. package/dist/api-connections/budgets.js +87 -0
  9. package/dist/api-connections/byo-client.d.ts +38 -0
  10. package/dist/api-connections/byo-client.js +28 -0
  11. package/dist/api-connections/connect.d.ts +87 -0
  12. package/dist/api-connections/connect.js +143 -0
  13. package/dist/api-connections/declarations.d.ts +68 -0
  14. package/dist/api-connections/declarations.js +178 -0
  15. package/dist/api-connections/deps.d.ts +4 -1
  16. package/dist/api-connections/descriptor.d.ts +15 -0
  17. package/dist/api-connections/descriptor.js +1 -5
  18. package/dist/api-connections/finish-authorization.d.ts +1 -1
  19. package/dist/api-connections/hook-http.d.ts +20 -0
  20. package/dist/api-connections/hook-http.js +27 -0
  21. package/dist/api-connections/host-ports.d.ts +244 -0
  22. package/dist/api-connections/host-ports.js +2 -0
  23. package/dist/api-connections/host.d.ts +81 -0
  24. package/dist/api-connections/host.js +320 -0
  25. package/dist/api-connections/hosted-mcp/contracts.d.ts +291 -0
  26. package/dist/api-connections/hosted-mcp/contracts.js +2 -0
  27. package/dist/api-connections/hosted-mcp/index.d.ts +5 -0
  28. package/dist/api-connections/hosted-mcp/index.js +3 -0
  29. package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +167 -0
  30. package/dist/api-connections/hosted-mcp/shared-sign-in.js +293 -0
  31. package/dist/api-connections/hosted-mcp/sign-in.d.ts +25 -0
  32. package/dist/api-connections/hosted-mcp/sign-in.js +889 -0
  33. package/dist/api-connections/hosted-sign-in.d.ts +48 -0
  34. package/dist/api-connections/hosted-sign-in.js +51 -0
  35. package/dist/api-connections/index.d.ts +23 -1
  36. package/dist/api-connections/index.js +15 -0
  37. package/dist/api-connections/install-credential.d.ts +1 -1
  38. package/dist/api-connections/oauth-capabilities.d.ts +63 -0
  39. package/dist/api-connections/oauth-capabilities.js +2 -0
  40. package/dist/api-connections/ports.d.ts +1 -1
  41. package/dist/api-connections/request-checks.d.ts +11 -1
  42. package/dist/api-connections/request-checks.js +2 -3
  43. package/dist/api-connections/shared.d.ts +79 -0
  44. package/dist/api-connections/shared.js +106 -0
  45. package/dist/api-connections/token-store/record.d.ts +2 -2
  46. package/dist/api-connections/token-store/vault-token-store.d.ts +30 -4
  47. package/dist/api-connections/token-store/vault-token-store.js +1 -4
  48. package/dist/credentialed-http/sets/host.d.ts +146 -0
  49. package/dist/credentialed-http/sets/host.js +2 -0
  50. package/dist/credentialed-http/sets/index.d.ts +24 -0
  51. package/dist/credentialed-http/sets/index.js +24 -0
  52. package/dist/credentialed-http/sets/store.d.ts +193 -0
  53. package/dist/credentialed-http/sets/store.js +489 -0
  54. package/dist/credentialed-http/sets/vault-repo.d.ts +81 -0
  55. package/dist/credentialed-http/sets/vault-repo.js +147 -0
  56. package/dist/credentialed-http/tools/credential-copy-tool.d.ts +34 -0
  57. package/dist/credentialed-http/tools/credential-copy-tool.js +132 -0
  58. package/dist/credentialed-http/tools/credential-tool-host.d.ts +152 -0
  59. package/dist/credentialed-http/tools/credential-tool-host.js +2 -0
  60. package/dist/credentialed-http/tools/credential-tool-operations.d.ts +370 -0
  61. package/dist/credentialed-http/tools/credential-tool-operations.js +2 -0
  62. package/dist/credentialed-http/tools/index.d.ts +7 -0
  63. package/dist/credentialed-http/tools/index.js +4 -0
  64. package/dist/credentialed-http/tools/tool-registrations.d.ts +55 -0
  65. package/dist/credentialed-http/tools/tool-registrations.js +729 -0
  66. package/package.json +34 -11
@@ -0,0 +1,291 @@
1
+ /** @agent-note Types only. Sign-in contracts for hosted MCP connections; the host fulfills every port and passes the same repository instance the store uses. */
2
+ import type { Clock as ClockPort, UUID } from '@jini-ai/core/primitives';
3
+ import type { KeyringPort, SecretSealerPort } from '@jini-ai/core/contracts/vault';
4
+ import type { AuthorizationCallbackParams, DeviceAuthorization, OAuthDiscoveryPolicy, OAuthFlowOperations, OAuthHttpPorts, OAuthMessages, OAuthProviderDescriptor, OAuthProviderRegistry, OAuthUrlGuard } from '@jini-ai/core/contracts/oauth';
5
+ import type { ExternalMcpAuthMode, ExternalMcpConnectStart, ExternalMcpOAuthStatus, ExternalMcpOAuthTokenResolverPort, ExternalMcpSealedOAuthPayload, ExternalMcpServerRecord, ExternalMcpServerRepoPort, SealedExternalMcpOAuth } from '@jini-ai/core/contracts/hosted-mcp';
6
+ /**
7
+ * One device authorization awaiting the operator's approval.
8
+ *
9
+ * `Promise`-returning so the host's durable adapter can persist and seal `deviceCode` through
10
+ * its sealer/keyring. The in-memory `createDeviceAuthorizationStore` is useful for tests and
11
+ * compositions where the entire handshake stays in one process.
12
+ * "Worthless after a restart" was never the reason durability matters: the agent daemon starts the
13
+ * handshake and the web server completes it in a different process, and a process-local Map cannot
14
+ * join those two legs. Memory stores remain useful only where the whole handshake stays in one process.
15
+ */
16
+ /** @agent-note Fulfilled by the host (durable store in production, memory only when one process runs the whole handshake). The service that starts a device grant and the one that polls it must share this store. Durable adapters seal the secret `deviceCode` with the host's sealer/keyring; it must never be persisted as plaintext. */
17
+ export interface DeviceAuthorizationStore {
18
+ /** @agent-note Replaces any pending authorization for the server id. */
19
+ put(serverId: string, authorization: DeviceAuthorization): Promise<void>;
20
+ /** @agent-note `undefined` when none is pending or it was deleted. */
21
+ get(serverId: string): Promise<DeviceAuthorization | undefined>;
22
+ /** @agent-note Idempotent. */
23
+ delete(serverId: string): Promise<void>;
24
+ }
25
+ /** @agent-note `Shared` is the host's shared-owner storage port (for example a desktop shared-owner storage type); absent keeps site-local sign-in. `repo` must be the store's repository instance; `httpPorts` is required guarded transport; `onConnected` runs once after durable success and its failure never fails sign-in. */
26
+ export interface ExternalMcpOAuthDeps<Shared = never> {
27
+ /** Host owner storage is optional; absence retains existing site-local sign-in. */
28
+ readonly shared?: Shared;
29
+ readonly workspaceId: UUID;
30
+ readonly repo: ExternalMcpServerRepoPort;
31
+ readonly sealer: SecretSealerPort;
32
+ readonly keyring: KeyringPort;
33
+ readonly clock: ClockPort;
34
+ /** @agent-note ONE device store per host composition, shared by the service that starts a device grant and the one that polls it. */
35
+ readonly devices: DeviceAuthorizationStore;
36
+ /** Required guarded transport and endpoint policy: no raw-fetch fallback can send a credential. */
37
+ readonly httpPorts: OAuthHttpPorts;
38
+ /** Host-owned registration; separate services do not mutate a process-wide provider map.
39
+ * @agent-note ONE registry per service instance, built by the host; never a process-wide map. */
40
+ readonly providers?: OAuthProviderRegistry;
41
+ /** Resolves a REGISTERED provider descriptor. Injected so a test can register its own without
42
+ * mutating another service's registry. Defaults to this service's host-owned instance. */
43
+ readonly lookupProvider?: (providerId: string) => OAuthProviderDescriptor;
44
+ /** Runs after a sign-in succeeds (redirect callback or device poll), once the token is durable.
45
+ * The host wires its post-connect defaults here. A throw is logged and never fails the
46
+ * sign-in: the connection itself already succeeded. */
47
+ /** @agent-note Called exactly ONCE per successful sign-in, after the token write is durable; its rejection is logged by the host and never changes the sign-in result. */
48
+ readonly onConnected?: (serverId: string) => Promise<void>;
49
+ }
50
+ /** @agent-note One instance per host composition; its `tokenResolver` is what the store receives. OAuth errors keep their original class identity; validation refusals are the canonical `ExternalMcpValidationError` from `@jini-ai/mcp/federation/hosted`.
51
+ * The host owns browser routes: authenticate the hosted sign-in hop, validate callback browser bindings, escape displayed content, check popup message origins and bound public callback traffic. Route inputs must not bypass these checks through the in-process unbound callback contract.
52
+ */
53
+ export interface ExternalMcpOAuthService {
54
+ /**
55
+ * Starts an authorization for one connection.
56
+ *
57
+ * @param input.redirectUri - The absolute public callback URL, built by the route from the
58
+ * request so a reverse-proxied deployment gets the origin the browser actually used.
59
+ *
60
+ * OPTIONAL, because whether one is needed at all is a property of the GRANT, and only this
61
+ * function knows the grant: `device_code` never uses a redirect URI (RFC 8628 — the human types
62
+ * a code at the provider; nothing redirects back), while `authorization_code` cannot proceed
63
+ * without one. Requiring it here pushed that decision up to every caller, and the caller with no
64
+ * live HTTP request to derive an origin from (`external_mcp_oauth_connect`) consequently refused
65
+ * EVERY grant whenever the host's public-URL setting was unset — including the one that needed nothing. So:
66
+ * omit it when there is genuinely no origin. Never pass one built from anything the CALLER
67
+ * supplied (a form field, a tool-call argument) — only from operator configuration or this
68
+ * process's own known bind origin, resolved by the host. A redirect URI the provider was
69
+ * not registered with still fails at the vendor with an error about the client, so this is not a
70
+ * license to guess from arbitrary caller input — it is what makes a value trustworthy enough to
71
+ * pass at all.
72
+ * @throws {ExternalMcpValidationError} When the server is unknown, is not OAuth-authenticated, or
73
+ * uses a grant that requires a redirect URI and none was supplied.
74
+ * @throws {OAuthError} Bounded, terminal, never retried — see this file's header.
75
+ * @param input.delivery - Browser-facing callers use `hosted`: only the authenticated host hop
76
+ * reveals the provider URL and sets the browser cookie. Device grants keep their existing shape.
77
+ * @param input.browserBinding - Host-issued cookie proof when that browser hop mints provider state.
78
+ */
79
+ /** @agent-note The redirect URI comes only from host configuration or its own bind origin, never from caller input. */
80
+ beginConnect(input: {
81
+ serverId: string;
82
+ redirectUri?: string;
83
+ delivery?: "hosted";
84
+ browserBinding?: string;
85
+ destination?: "shared";
86
+ actorId?: string;
87
+ }): Promise<ExternalMcpConnectStart>;
88
+ /**
89
+ * Finishes an authorization-code handshake from the public callback route.
90
+ *
91
+ * @param input.params - The callback's query parameters, already narrowed to strings. Untrusted.
92
+ * @param input.redirectUri - Canonical callback URI from the host's existing trusted origin policy.
93
+ * @param input.browserBinding - Public callbacks must supply the validated browser cookie.
94
+ * Direct in-process callers retain the legacy unbound contract; HTTP never falls back to it.
95
+ */
96
+ /** @agent-note Public callbacks must pass the host-validated browser binding. */
97
+ completeAuthorizationCallback(input: {
98
+ serverId: string;
99
+ redirectUri: string;
100
+ params: AuthorizationCallbackParams;
101
+ browserBinding?: string;
102
+ }, optionalArgs?: Record<string, never>): Promise<void>;
103
+ /**
104
+ * Polls a device authorization exactly once.
105
+ *
106
+ * @returns `"pending"` with the interval to wait, or `"connected"` once the token is stored.
107
+ * @throws {OAuthError} On any terminal outcome — declined, expired, or a provider failure.
108
+ */
109
+ /** @agent-note Exactly one provider poll per call. */
110
+ pollDeviceAuthorization(input: {
111
+ serverId: string;
112
+ }): Promise<{
113
+ readonly status: "pending";
114
+ readonly retryAfterSeconds: number;
115
+ } | {
116
+ readonly status: "connected";
117
+ }>;
118
+ /** Clears the stored token and returns the connection to `disconnected`. */
119
+ /** @agent-note Clears the stored token; the row stays. */
120
+ disconnect(input: {
121
+ serverId: string;
122
+ }): Promise<void>;
123
+ /**
124
+ * Reacts to a live federated call failing because the remote rejected our authorization (HTTP
125
+ * 401/403), discovered mid-session rather than at boot — wired as
126
+ * the federation's `FederationDeps.onAuthFailed`.
127
+ *
128
+ * For an OAuth-authenticated row this records `needs_reauth` durably, the same state
129
+ * `tokenResolver.resolveAccessToken` reaches at boot, so the NEXT call is refused cheaply by
130
+ * the host's connection-gate row read instead of reaching the network again — and
131
+ * replaces the transport-shaped error with the same terminal, non-retryable
132
+ * {@link ExternalMcpReauthRequiredError} that path already throws.
133
+ *
134
+ * A row that is not OAuth-authenticated (or no longer exists) has no reauth state to record;
135
+ * `error` propagates unchanged.
136
+ * @throws Always — either the original `error`, or {@link ExternalMcpReauthRequiredError}.
137
+ */
138
+ /** @agent-note Always throws: the original error, or the host's canonical re-authorization error. */
139
+ reportAuthFailure(serverId: string, error: Error): Promise<never>;
140
+ /** The port `readEnabledExternalMcpConfigs` takes, wired to this service's refresher. */
141
+ /** @agent-note The same object the store's token resolver port receives. */
142
+ readonly tokenResolver: ExternalMcpOAuthTokenResolverPort;
143
+ /** True when a shared binding was checked; throws if its current grant is unavailable. */
144
+ listSharedConnections?(input: {
145
+ serverId: string;
146
+ actorId: string;
147
+ }): Promise<{
148
+ available: boolean;
149
+ connections: readonly {
150
+ credentialId: string;
151
+ label: string;
152
+ }[];
153
+ current: {
154
+ credentialId: string;
155
+ status: string;
156
+ granted: boolean;
157
+ } | null;
158
+ }>;
159
+ assertSharedAuthorized?(input: {
160
+ serverId: string;
161
+ }): Promise<boolean>;
162
+ useLocalConnection?(input: {
163
+ serverId: string;
164
+ actorId: string;
165
+ }): Promise<void>;
166
+ useSharedConnection?(input: {
167
+ serverId: string;
168
+ credentialId: string;
169
+ actorId: string;
170
+ }): Promise<void>;
171
+ }
172
+ /** @agent-note The fields of a real OAuth error the sign-in reads after `isOAuthError` recognized it; never built by the sign-in itself. */
173
+ export interface HostedMcpOAuthFailure extends Error {
174
+ readonly code: string;
175
+ readonly retryable: boolean;
176
+ readonly providerErrorCode: string | undefined;
177
+ readonly retryAfterSeconds: number | undefined;
178
+ }
179
+ /** @agent-note Host wording for the sign-in's refusals and operator actions. Every string may be model- or operator-facing, so it never carries provider text, tokens or URLs; the host binds its exact current bytes. */
180
+ export interface HostedMcpSignInCopy {
181
+ /** Operator actions attached to the OAuth refusals, keyed by the refusal. */
182
+ readonly actions: {
183
+ readonly noProvider: string;
184
+ readonly noClientId: string;
185
+ readonly chooseGrant: string;
186
+ readonly noRegistration: string;
187
+ readonly restartDevice: string;
188
+ readonly restartShared: string;
189
+ };
190
+ /** The refusal message when discovery advertises no grant the sign-in implements. */
191
+ readonly noSupportedGrant: (input: {
192
+ readonly serverId: string;
193
+ readonly offered: readonly string[];
194
+ }) => string;
195
+ /** The validation message when an authorization-code grant has no callback origin. */
196
+ readonly noPublicOrigin: (input: {
197
+ readonly serverId: string;
198
+ }) => string;
199
+ /** Validation message when shared sign-in is asked for where the host has no shared owner. */
200
+ readonly sharedLocalOnly: string;
201
+ /** Message of the connection error for a shared connection that is not usable here. */
202
+ readonly sharedUnavailable: string;
203
+ /** Message of the access-denied error when the actor is not the shared owner. */
204
+ readonly sharedOwnerOnly: string;
205
+ }
206
+ /**
207
+ * Everything the hosted-MCP sign-in needs from its host, so the sign-in imports only core types.
208
+ * @agent-note Fulfilled by the host ONCE per composition (one object shared by the sign-in service and its shared-owner sign-in); members are the host's real implementations, never copies:
209
+ * `flow` = `@jini-ai/oauth`'s `oauthFlowOperations` (its errors are real `OAuthError`s); `errors.oauth` constructs a real `OAuthError` and `errors.isOAuthError` is that class's own predicate (identity, codes, retryability preserved, never matched by message);
210
+ * `errors.validation` constructs the canonical `ExternalMcpValidationError` and `errors.isUnconfigured` recognizes the canonical `ExternalMcpSecretStoreUnconfiguredError` (both from `@jini-ai/mcp/federation/hosted`), so `isSignInRefusal`/`classifyError` keep recognizing them;
211
+ * `errors.reauthRequired` is the host's ONE canonical re-authorization factory, the same function the connection gate receives.
212
+ * `store` is the same store module the host's repository was built with (same envelope instance); the repository itself is `deps.repo`, which MUST be the store's repo instance, and every find/upsert/lease/CAS call goes through it in the original order.
213
+ * `aad.format` produces the persisted `oauth-redirect-state` v1 AAD bytes; `registrationIdentity` is stable (changing it registers a new client at every provider); `signInLink` builds the host route link (routes and browser binding stay in the host).
214
+ */
215
+ export interface HostedMcpSignInPorts {
216
+ readonly flow: OAuthFlowOperations;
217
+ readonly errors: {
218
+ /** @agent-note Returns a real `OAuthError` instance built from exactly this input. */
219
+ readonly oauth: (input: {
220
+ readonly code: 'OAUTH_INVALID_REQUEST' | 'OAUTH_INVALID_STATE';
221
+ readonly message: string;
222
+ readonly operatorAction: string;
223
+ }) => Error;
224
+ /** @agent-note `instanceof` the real `OAuthError` class `flow` throws. */
225
+ readonly isOAuthError: (error: unknown) => error is HostedMcpOAuthFailure;
226
+ /** @agent-note Returns the canonical validation error; `field` names the refused input. */
227
+ readonly validation: (message: string, field: string) => Error;
228
+ /** @agent-note `instanceof` the canonical secret-store-unconfigured error the `store` members throw. */
229
+ readonly isUnconfigured: (error: unknown) => boolean;
230
+ /** @agent-note The canonical terminal, non-retryable re-authorization error; `cause` rides along unchanged. */
231
+ readonly reauthRequired: (input: {
232
+ readonly serverId: string;
233
+ readonly label?: string | null;
234
+ readonly cause?: unknown;
235
+ }) => Error;
236
+ };
237
+ readonly store: {
238
+ /** @agent-note Exactly one sealer open per call; `{}` when the row holds no blob. */
239
+ openPayload(sealer: Pick<SecretSealerPort, 'open'>, record: Pick<ExternalMcpServerRecord, 'sealedOAuth' | 'workspaceId' | 'serverId' | 'oauthAadVersion'>): Promise<ExternalMcpSealedOAuthPayload>;
240
+ /** @agent-note Exactly one seal; the result is staged for `deps.repo.upsert` in the same call sequence. */
241
+ sealPayload(deps: {
242
+ readonly sealer: SecretSealerPort;
243
+ readonly keyring: KeyringPort;
244
+ }, identity: {
245
+ readonly workspaceId: string;
246
+ readonly serverId: string;
247
+ }, payload: ExternalMcpSealedOAuthPayload): Promise<SealedExternalMcpOAuth>;
248
+ };
249
+ /** @agent-note Pure row projections (the canonical resolvers); no I/O. */
250
+ readonly projections: {
251
+ readonly authMode: (record: Pick<ExternalMcpServerRecord, 'authMode'>) => ExternalMcpAuthMode;
252
+ readonly oauthStatus: (record: Pick<ExternalMcpServerRecord, 'oauthStatus'>) => ExternalMcpOAuthStatus;
253
+ };
254
+ /** @agent-note Persisted AAD format; must stay byte-identical for already-issued state. */
255
+ readonly aad: {
256
+ readonly format: (input: {
257
+ readonly kind: string;
258
+ readonly version: string;
259
+ readonly parts: readonly string[];
260
+ }) => string;
261
+ };
262
+ /** @agent-note Host route link for the hosted browser hop; no provider URL leaves it. */
263
+ readonly signInLink: (input: {
264
+ readonly callbackUrl: string;
265
+ readonly workspaceId: string;
266
+ readonly serverId: string;
267
+ }) => string;
268
+ /** @agent-note Stable registration identity: `clientName` names a connection's own client, `sharedClientName` the shared-owner client. */
269
+ readonly registrationIdentity: {
270
+ readonly softwareId: string;
271
+ readonly clientName: (record: Pick<ExternalMcpServerRecord, 'label' | 'serverId'>) => string;
272
+ readonly sharedClientName: string;
273
+ };
274
+ /** @agent-note Host OAuth copy passed to `flow`, the issuer-bound discovery policy, and the wrapper that maps provider failures to host copy (it never adds retries). */
275
+ readonly oauthMessages: OAuthMessages;
276
+ readonly discoveryPolicy: (input: {
277
+ readonly guard: OAuthUrlGuard;
278
+ }) => OAuthDiscoveryPolicy;
279
+ readonly withCopy: <T>(input: {
280
+ readonly call: () => Promise<T>;
281
+ }) => Promise<T>;
282
+ readonly copy: HostedMcpSignInCopy;
283
+ /** @agent-note Operator diagnostics only; called when `onConnected` rejects, after which sign-in still succeeds. This logger MUST NOT throw or forward provider details to model-facing text. */
284
+ readonly log: {
285
+ readonly postConnectFailed: (input: {
286
+ readonly serverId: string;
287
+ readonly error: unknown;
288
+ }) => void;
289
+ };
290
+ }
291
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1,5 @@
1
+ /** @agent-note Sign-in contracts and values for hosted MCP connections; the host fulfills every port and passes the same repository instance the store uses. Imports only `@jini-ai/core` and this package. */
2
+ export type * from './contracts.js';
3
+ export { createHostedMcpSignInService, createDeviceAuthorizationStore } from './sign-in.js';
4
+ export { createSharedExternalMcpOAuth, type SharedExternalMcpOwner, type SharedSignInOwner, type SharedSignInBindings, type SharedSignInAttachments, type SharedSignInTransaction, type SharedSignInIssuingContext, type SharedMcpConfiguration } from './shared-sign-in.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { createHostedMcpSignInService, createDeviceAuthorizationStore } from './sign-in.js';
2
+ export { createSharedExternalMcpOAuth } from './shared-sign-in.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,167 @@
1
+ import { type ApiConnectionClientKind, type ApiConnectionDescriptor, type ApiConnectionRecordStore, type ApiConnectionTokenStore, type SharedOAuthConnection } from '../index.js';
2
+ import type { OAuthClient, OAuthProviderDescriptor } from '@jini-ai/core/contracts/oauth';
3
+ import type { VaultRecord } from '@jini-ai/core/contracts/vault';
4
+ import type { ExternalMcpConnectStart, ExternalMcpServerRecord } from '@jini-ai/core/contracts/hosted-mcp';
5
+ import type { ExternalMcpOAuthDeps, ExternalMcpOAuthService, HostedMcpSignInPorts } from './contracts.js';
6
+ /** @agent-note Issuing configuration sealed in the owner store; a consuming site's client cannot replace it.
7
+ * Storage MUST losslessly preserve the entire supplied context, including additional fields beyond this base interface.
8
+ * In particular, shared MCP sign-in persists `mcp: { provider: OAuthProviderDescriptor, scopes: readonly string[], url: string | null, grant: string | null }`.
9
+ * `saveContext` must seal those fields and `readContext` must return them unchanged after restart; projecting only the five declared fields breaks device polls and callbacks.
10
+ */
11
+ export interface SharedSignInIssuingContext {
12
+ readonly credentialId: string;
13
+ readonly identity: SharedOAuthConnection['identity'];
14
+ readonly client: OAuthClient;
15
+ readonly clientKind: ApiConnectionClientKind;
16
+ readonly descriptor: ApiConnectionDescriptor;
17
+ }
18
+ /** @agent-note Fulfilled by the host's shared-owner storage over the owner vault: `records` and `tokensFor` use the SAME vault/record store, `saveContext` refuses a changed issuing identity, `readConnection` checks the record against its context. */
19
+ export interface SharedSignInOwner {
20
+ readonly records: Pick<ApiConnectionRecordStore, 'read' | 'compareAndSet'>;
21
+ readContext(input: {
22
+ credentialId: string;
23
+ }): Promise<SharedSignInIssuingContext | null>;
24
+ saveContext(input: {
25
+ credentialId: string;
26
+ context: SharedSignInIssuingContext;
27
+ }): Promise<void>;
28
+ tokensFor(input: {
29
+ context: SharedSignInIssuingContext;
30
+ }): ApiConnectionTokenStore;
31
+ readConnection(input: {
32
+ credentialId: string;
33
+ }): Promise<SharedOAuthConnection | null>;
34
+ }
35
+ /** @agent-note Fulfilled by the host's site binding store: token-free consumer→credential references only; a live owner grant still authorizes every use. */
36
+ export interface SharedSignInBindings {
37
+ read(input: {
38
+ consumerId: string;
39
+ }): Promise<{
40
+ credentialId: string;
41
+ } | null>;
42
+ set(input: {
43
+ consumerId: string;
44
+ credentialId: string;
45
+ }): Promise<void>;
46
+ remove(input: {
47
+ consumerId: string;
48
+ }): Promise<void>;
49
+ }
50
+ /** @agent-note Fulfilled by the host's owner-grant attachments: the live owner grant, checked on every use (no cache). */
51
+ export interface SharedSignInAttachments {
52
+ attach(required: {
53
+ siteId: string;
54
+ keyId: string;
55
+ siteName: string;
56
+ }): Promise<void>;
57
+ detach(required: {
58
+ siteId: string;
59
+ keyId: string;
60
+ }): Promise<void>;
61
+ isAttached(required: {
62
+ siteId: string;
63
+ keyId: string;
64
+ }): Promise<boolean>;
65
+ }
66
+ /** @agent-note The host's owner transaction; binding and attachment writes inside one `run` commit together. Concurrent grant/removal operations must serialize so a completed removal cannot be undone by an older pending grant. */
67
+ export type SharedSignInTransaction = <T>(required: {
68
+ run: () => Promise<T>;
69
+ }) => Promise<T>;
70
+ /** @agent-note Host-owned storage and identity for shared sign-in. Owner records and tokens stay in the owner workspace; site bindings contain references only.
71
+ * Persisted protocol identifiers (`external-mcp`, `oauth`, `mcp:` and `shared`) stay stable across restarts and upgrades; they do not select a host workspace.
72
+ */
73
+ export interface SharedExternalMcpOwner {
74
+ /** @agent-note The workspace validated by `owner.records` and its vault, also used to derive credential keys. Distinct from the consuming site's workspace. */
75
+ readonly ownerWorkspaceId: string;
76
+ readonly owner: SharedSignInOwner;
77
+ readonly bindings: SharedSignInBindings;
78
+ readonly attachments: SharedSignInAttachments;
79
+ readonly transaction: SharedSignInTransaction;
80
+ readonly siteId: string;
81
+ readonly siteName: string;
82
+ /** @agent-note The authenticated owner identity; the host supplies actor ids from trusted authentication, never model or form input. */
83
+ readonly ownerPrincipalId: string | Promise<string>;
84
+ /** @agent-note Optional bounded owner inventory query; it returns metadata only, never token payloads. */
85
+ readonly inventory?: () => Promise<readonly VaultRecord[]>;
86
+ }
87
+ export interface SharedMcpConfiguration {
88
+ readonly record: ExternalMcpServerRecord;
89
+ readonly provider: OAuthProviderDescriptor;
90
+ readonly client: OAuthClient;
91
+ readonly scopes: readonly string[];
92
+ readonly resource?: string | undefined;
93
+ readonly issuer?: string | undefined;
94
+ }
95
+ /** Site-specific bindings over the existing owner vault. Every call checks live grants; no token is copied to the site.
96
+ * @complexity Selected-row reads per call; one cached refresher per selected owner credential, no timers or polling.
97
+ */
98
+ export declare function createSharedExternalMcpOAuth(required: {
99
+ deps: ExternalMcpOAuthDeps<SharedExternalMcpOwner>;
100
+ shared: SharedExternalMcpOwner;
101
+ /** The host's sign-in ports (the same object the sign-in service received). */
102
+ ports: HostedMcpSignInPorts;
103
+ resolveProvider: (record: ExternalMcpServerRecord) => OAuthProviderDescriptor;
104
+ configure: (input: {
105
+ serverId: string;
106
+ redirectUri?: string | undefined;
107
+ }) => Promise<SharedMcpConfiguration>;
108
+ }, _optional?: {}): {
109
+ list(input: {
110
+ serverId: string;
111
+ actorId: string;
112
+ }): Promise<{
113
+ available: boolean;
114
+ connections: {
115
+ credentialId: string;
116
+ label: string;
117
+ }[];
118
+ current: {
119
+ status: import("../types.js").ApiConnectionStatus;
120
+ granted: boolean;
121
+ credentialId: string;
122
+ } | null;
123
+ }>;
124
+ hasBinding: (input: {
125
+ serverId: string;
126
+ }) => Promise<boolean>;
127
+ getAccessToken(input: {
128
+ serverId: string;
129
+ }): Promise<string | undefined>;
130
+ assertAuthorized(input: {
131
+ serverId: string;
132
+ }): Promise<boolean>;
133
+ useSaved(input: {
134
+ serverId: string;
135
+ credentialId: string;
136
+ actorId: string;
137
+ }): Promise<void>;
138
+ useLocal(input: {
139
+ serverId: string;
140
+ actorId: string;
141
+ }): Promise<void>;
142
+ beginConnect(input: {
143
+ serverId: string;
144
+ redirectUri?: string;
145
+ delivery?: "hosted";
146
+ browserBinding?: string;
147
+ actorId?: string;
148
+ destination?: "shared";
149
+ }): Promise<ExternalMcpConnectStart>;
150
+ completeAuthorizationCallback(input: Parameters<ExternalMcpOAuthService["completeAuthorizationCallback"]>[0]): Promise<void>;
151
+ pollDeviceAuthorization(input: {
152
+ serverId: string;
153
+ }): Promise<{
154
+ status: "connected";
155
+ retryAfterSeconds?: never;
156
+ } | {
157
+ status: "pending";
158
+ retryAfterSeconds: number;
159
+ }>;
160
+ markNeedsReauth(input: {
161
+ serverId: string;
162
+ }): Promise<void>;
163
+ disconnect(input: {
164
+ serverId: string;
165
+ }): Promise<void>;
166
+ };
167
+ //# sourceMappingURL=shared-sign-in.d.ts.map