@jini-ai/integrations 0.7.2 → 0.7.3-next.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 (143) hide show
  1. package/CHANGELOG.md +2 -8
  2. package/README.md +1 -0
  3. package/dist/api-connections/access-token.js +4 -4
  4. package/dist/api-connections/account-actions.d.ts +10 -4
  5. package/dist/api-connections/account-actions.js +13 -13
  6. package/dist/api-connections/attempt-state.d.ts +11 -5
  7. package/dist/api-connections/attempt-state.js +4 -4
  8. package/dist/api-connections/authorization.d.ts +7 -3
  9. package/dist/api-connections/authorization.js +18 -18
  10. package/dist/api-connections/finish-authorization.d.ts +8 -4
  11. package/dist/api-connections/finish-authorization.js +9 -9
  12. package/dist/api-connections/host.d.ts +30 -32
  13. package/dist/api-connections/host.js +232 -205
  14. package/dist/api-connections/hosted-mcp/contracts.d.ts +1 -1
  15. package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +50 -0
  16. package/dist/api-connections/hosted-mcp/oauth-row-writes.js +38 -0
  17. package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +40 -40
  18. package/dist/api-connections/hosted-mcp/shared-sign-in.js +98 -22
  19. package/dist/api-connections/hosted-mcp/sign-in-configuration.d.ts +29 -0
  20. package/dist/api-connections/hosted-mcp/sign-in-configuration.js +127 -0
  21. package/dist/api-connections/hosted-mcp/sign-in-discovery.d.ts +72 -0
  22. package/dist/api-connections/hosted-mcp/sign-in-discovery.js +131 -0
  23. package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +42 -0
  24. package/dist/api-connections/hosted-mcp/sign-in-flow.js +50 -0
  25. package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +103 -0
  26. package/dist/api-connections/hosted-mcp/sign-in-provider.js +142 -0
  27. package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +19 -0
  28. package/dist/api-connections/hosted-mcp/sign-in-status.js +143 -0
  29. package/dist/api-connections/hosted-mcp/sign-in.d.ts +2 -9
  30. package/dist/api-connections/hosted-mcp/sign-in.js +219 -770
  31. package/dist/api-connections/index.js +1 -1
  32. package/dist/api-connections/install-credential.d.ts +4 -2
  33. package/dist/api-connections/install-credential.js +7 -7
  34. package/dist/api-connections/records.d.ts +17 -5
  35. package/dist/api-connections/records.js +5 -5
  36. package/dist/api-connections/request-checks.d.ts +29 -9
  37. package/dist/api-connections/request-checks.js +13 -13
  38. package/dist/api-connections/service.d.ts +1 -1
  39. package/dist/api-connections/service.js +6 -6
  40. package/dist/api-connections/status.d.ts +3 -1
  41. package/dist/api-connections/status.js +3 -3
  42. package/dist/api-connections/token-store/errors.d.ts +3 -1
  43. package/dist/api-connections/token-store/errors.js +1 -1
  44. package/dist/api-connections/token-store/vault-token-store.js +186 -173
  45. package/dist/args.d.ts +4 -1
  46. package/dist/args.js +1 -1
  47. package/dist/credentialed-http/credentialed-request.d.ts +5 -5
  48. package/dist/credentialed-http/credentialed-request.js +8 -8
  49. package/dist/credentialed-http/response-redaction.d.ts +18 -4
  50. package/dist/credentialed-http/response-redaction.js +7 -7
  51. package/dist/credentialed-http/sets/vault-repo.js +5 -1
  52. package/dist/credentialed-http/tools/credential-copy-tool.js +20 -15
  53. package/dist/credentialed-http/tools/tool-registrations.js +272 -249
  54. package/dist/media-providers/catalog.d.ts +1 -0
  55. package/dist/media-providers/catalog.js +1 -0
  56. package/dist/media-providers/dispatch/async-operation-store.d.ts +6 -4
  57. package/dist/media-providers/dispatch/async-operation-store.js +100 -88
  58. package/dist/media-providers/dispatch/context.js +1 -1
  59. package/dist/media-providers/dispatch/engine.d.ts +5 -1
  60. package/dist/media-providers/dispatch/engine.js +2 -2
  61. package/dist/media-providers/dispatch/index.d.ts +1 -1
  62. package/dist/media-providers/dispatch/index.js +1 -1
  63. package/dist/media-providers/dispatch/node.d.ts +1 -1
  64. package/dist/media-providers/dispatch/node.js +1 -1
  65. package/dist/media-providers/dispatch/openai-compatible.d.ts +50 -11
  66. package/dist/media-providers/dispatch/openai-compatible.js +21 -17
  67. package/dist/media-providers/dispatch/operation-runtime.js +18 -18
  68. package/dist/media-providers/dispatch/outbound.d.ts +2 -2
  69. package/dist/media-providers/dispatch/outbound.js +1 -1
  70. package/dist/media-providers/dispatch/polling-adapter.d.ts +1 -1
  71. package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +20 -6
  72. package/dist/media-providers/dispatch/providers/aihubmix-shared.js +8 -8
  73. package/dist/media-providers/dispatch/providers/aihubmix.js +12 -12
  74. package/dist/media-providers/dispatch/providers/custom-image.js +4 -4
  75. package/dist/media-providers/dispatch/providers/fishaudio.js +2 -9
  76. package/dist/media-providers/dispatch/providers/grok.js +5 -19
  77. package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +22 -20
  78. package/dist/media-providers/dispatch/providers/imagerouter.js +7 -21
  79. package/dist/media-providers/dispatch/providers/minimax.js +2 -9
  80. package/dist/media-providers/dispatch/providers/nanobanana.js +2 -2
  81. package/dist/media-providers/dispatch/providers/openai.js +6 -6
  82. package/dist/media-providers/dispatch/providers/openrouter.js +4 -4
  83. package/dist/media-providers/dispatch/providers/senseaudio.js +5 -19
  84. package/dist/media-providers/dispatch/providers/volcengine.js +5 -12
  85. package/dist/media-providers/dispatch/response-parsers.js +3 -3
  86. package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +1 -1
  87. package/dist/media-providers/dispatch/sqlite-async-operation-store.js +31 -5
  88. package/dist/media-providers/dispatch/ssrf-guard.js +5 -12
  89. package/dist/media-providers/dispatch/stub.js +2 -2
  90. package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
  91. package/dist/media-providers/image-model-ids.d.ts +36 -0
  92. package/dist/media-providers/image-model-ids.js +24 -0
  93. package/dist/media-providers/sqlite-driver.adapter.d.ts +1 -1
  94. package/dist/media-providers/sqlite-task-store.d.ts +2 -2
  95. package/dist/media-providers/sqlite-task-store.js +31 -4
  96. package/dist/media-providers/task-lifecycle.d.ts +17 -4
  97. package/dist/media-providers/task-lifecycle.js +4 -4
  98. package/dist/media-providers/task-store.js +28 -24
  99. package/dist/media-providers/ui-defaults.d.ts +7 -0
  100. package/dist/media-providers/ui-defaults.js +11 -17
  101. package/dist/saved-requests/types.d.ts +1 -1
  102. package/dist/webhooks/delivery.js +31 -27
  103. package/dist/webhooks/ports.d.ts +4 -1
  104. package/dist/webhooks/subscriptions.d.ts +7 -2
  105. package/dist/webhooks/subscriptions.js +30 -37
  106. package/dist/webhooks/tools/agent-tools.d.ts +82 -0
  107. package/dist/webhooks/tools/agent-tools.js +120 -0
  108. package/dist/webhooks/tools/index.d.ts +7 -0
  109. package/dist/webhooks/tools/index.js +5 -0
  110. package/dist/webhooks/tools/tool-handlers.d.ts +22 -0
  111. package/dist/webhooks/tools/tool-handlers.js +154 -0
  112. package/dist/webhooks/tools/tool-handlers.types.d.ts +64 -0
  113. package/dist/webhooks/tools/tool-handlers.types.js +2 -0
  114. package/dist/webhooks/tools/tool-registrations.d.ts +35 -0
  115. package/dist/webhooks/tools/tool-registrations.js +95 -0
  116. package/dist/webhooks/tools/tool-views.d.ts +62 -0
  117. package/dist/webhooks/tools/tool-views.js +50 -0
  118. package/dist/webhooks/types.d.ts +2 -0
  119. package/dist/webhooks/worker.d.ts +7 -4
  120. package/dist/webhooks/worker.js +22 -20
  121. package/package.json +16 -18
  122. package/dist/composio/bounded-data.d.ts +0 -36
  123. package/dist/composio/bounded-data.js +0 -181
  124. package/dist/composio/catalog.d.ts +0 -147
  125. package/dist/composio/catalog.js +0 -126
  126. package/dist/composio/composio-config.d.ts +0 -42
  127. package/dist/composio/composio-config.js +0 -145
  128. package/dist/composio/composio-descriptions.d.ts +0 -16
  129. package/dist/composio/composio-descriptions.js +0 -766
  130. package/dist/composio/composio.d.ts +0 -364
  131. package/dist/composio/composio.js +0 -1902
  132. package/dist/composio/errors.d.ts +0 -15
  133. package/dist/composio/errors.js +0 -16
  134. package/dist/composio/file-lock.d.ts +0 -13
  135. package/dist/composio/file-lock.js +0 -92
  136. package/dist/composio/index.d.ts +0 -18
  137. package/dist/composio/index.js +0 -7
  138. package/dist/composio/json-schema.d.ts +0 -93
  139. package/dist/composio/json-schema.js +0 -498
  140. package/dist/composio/output-protection.d.ts +0 -32
  141. package/dist/composio/output-protection.js +0 -105
  142. package/dist/composio/service.d.ts +0 -181
  143. package/dist/composio/service.js +0 -758
@@ -106,48 +106,12 @@ export declare function createSharedExternalMcpOAuth(required: {
106
106
  redirectUri?: string | undefined;
107
107
  }) => Promise<SharedMcpConfiguration>;
108
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: {
109
+ markNeedsReauth(input: {
134
110
  serverId: string;
135
- credentialId: string;
136
- actorId: string;
137
111
  }): Promise<void>;
138
- useLocal(input: {
112
+ disconnect(input: {
139
113
  serverId: string;
140
- actorId: string;
141
114
  }): 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
115
  pollDeviceAuthorization(input: {
152
116
  serverId: string;
153
117
  }): Promise<{
@@ -157,11 +121,47 @@ export declare function createSharedExternalMcpOAuth(required: {
157
121
  status: "pending";
158
122
  retryAfterSeconds: number;
159
123
  }>;
160
- markNeedsReauth(input: {
124
+ completeAuthorizationCallback(input: Parameters<ExternalMcpOAuthService["completeAuthorizationCallback"]>[0]): Promise<void>;
125
+ beginConnect(input: {
126
+ serverId: string;
127
+ redirectUri?: string;
128
+ delivery?: "hosted";
129
+ browserBinding?: string;
130
+ actorId?: string;
131
+ destination?: "shared";
132
+ }): Promise<ExternalMcpConnectStart>;
133
+ useSaved(input: {
161
134
  serverId: string;
135
+ credentialId: string;
136
+ actorId: string;
162
137
  }): Promise<void>;
163
- disconnect(input: {
138
+ useLocal(input: {
164
139
  serverId: string;
140
+ actorId: string;
165
141
  }): Promise<void>;
142
+ hasBinding: (input: {
143
+ serverId: string;
144
+ }) => Promise<boolean>;
145
+ getAccessToken(input: {
146
+ serverId: string;
147
+ }): Promise<string | undefined>;
148
+ assertAuthorized(input: {
149
+ serverId: string;
150
+ }): Promise<boolean>;
151
+ list(input: {
152
+ serverId: string;
153
+ actorId: string;
154
+ }): Promise<{
155
+ available: boolean;
156
+ connections: {
157
+ credentialId: string;
158
+ label: string;
159
+ }[];
160
+ current: {
161
+ status: import("../types.js").ApiConnectionStatus;
162
+ granted: boolean;
163
+ credentialId: string;
164
+ } | null;
165
+ }>;
166
166
  };
167
167
  //# sourceMappingURL=shared-sign-in.d.ts.map
@@ -6,6 +6,22 @@ const consumerId = (serverId) => `mcp:${serverId}`;
6
6
  * @complexity Selected-row reads per call; one cached refresher per selected owner credential, no timers or polling.
7
7
  */
8
8
  export function createSharedExternalMcpOAuth(required, _optional = {}) {
9
+ const access = createSharedSignInAccess(required);
10
+ const target = createSharedMcpTarget(access);
11
+ const consumer = createSharedMcpConsumer(access);
12
+ const selection = createSharedMcpSelection(access, target);
13
+ const attempts = createSharedMcpAttempts(access);
14
+ return {
15
+ ...createSharedMcpInventory(access),
16
+ ...createSharedMcpAccessMethods(selection, consumer, access.bindingFor),
17
+ ...createSharedMcpBindingMethods(access, selection, consumer),
18
+ ...createSharedMcpConnectMethod(access, selection, attempts),
19
+ ...createSharedMcpCallbackMethod(access, selection, attempts),
20
+ ...createSharedMcpPollingMethod(access, selection, attempts),
21
+ ...createSharedMcpDisconnectMethods(access, selection),
22
+ };
23
+ }
24
+ function createSharedSignInAccess(required) {
9
25
  const { deps, shared, configure, resolveProvider, ports } = required;
10
26
  const { owner, bindings, attachments, siteId } = shared;
11
27
  const unavailable = () => new ApiConnectionError({ code: 'connection-not-found', message: ports.copy.sharedUnavailable });
@@ -19,6 +35,15 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
19
35
  throw unavailable();
20
36
  return context;
21
37
  }
38
+ async function assertOwner(actorId) {
39
+ if (actorId !== await shared.ownerPrincipalId)
40
+ throw new ApiConnectionError({ code: 'access-denied', message: ports.copy.sharedOwnerOnly });
41
+ }
42
+ return { deps, shared, configure, resolveProvider, ports, owner, bindings, attachments, siteId,
43
+ unavailable, invalidState, refreshers, deviceKeyFor, bindingFor, contextFor, assertOwner };
44
+ }
45
+ function createSharedMcpTarget(access) {
46
+ const { resolveProvider, siteId, unavailable } = access;
22
47
  function optionalAuthorization(authorizationEndpoint) {
23
48
  return authorizationEndpoint === undefined ? {} : { authorizationEndpoint };
24
49
  }
@@ -41,6 +66,10 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
41
66
  return { siteId, consumerId: consumerId(record.serverId), identity: { pluginId: MCP_PLUGIN_ID, connectionId: 'oauth',
42
67
  ...endpointIdentity(record, context) }, requiredScopes: scopes };
43
68
  }
69
+ return target;
70
+ }
71
+ function createSharedMcpConsumer(access) {
72
+ const { deps, ports, owner, bindings, attachments, unavailable, refreshers, contextFor } = access;
44
73
  async function refreshFor(credentialId) {
45
74
  const cached = refreshers.get(credentialId);
46
75
  if (cached)
@@ -74,6 +103,10 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
74
103
  }
75
104
  } },
76
105
  });
106
+ return consumer;
107
+ }
108
+ function createSharedMcpSelection(access, target) {
109
+ const { deps, shared, owner, bindings, attachments, siteId, configure, unavailable, bindingFor, contextFor } = access;
77
110
  async function selected(serverId) {
78
111
  const binding = await bindingFor({ serverId });
79
112
  if (!binding)
@@ -83,25 +116,6 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
83
116
  throw unavailable();
84
117
  return { binding, context, record, target: target(record, context) };
85
118
  }
86
- async function assertAttempt(serverId, credentialId, generation) {
87
- const [binding, record, granted] = await Promise.all([bindingFor({ serverId }), owner.records.read({ key: credentialId }), attachments.isAttached({ siteId, keyId: credentialId })]);
88
- if (binding?.credentialId !== credentialId || !granted || !record)
89
- throw invalidState();
90
- if (record.generation !== generation || record.status === 'revocation-pending')
91
- throw invalidState();
92
- return record;
93
- }
94
- function stateFor(input) {
95
- const aad = ports.aad.format({ kind: 'oauth-redirect-state', version: 'v1', parts: [JSON.stringify(['shared', siteId, input.serverId, input.credentialId, input.generation, input.browserBinding])] });
96
- return ports.flow.createSealedAuthorizationState({ clock: deps.clock, workspaceId: siteId, serverId: input.serverId, codec: {
97
- seal: async ({ plaintext }) => Buffer.from(JSON.stringify(await deps.sealer.seal({ plaintext, key: await deps.keyring.activeKey({}), aad }))).toString('base64url'),
98
- open: async ({ state }) => deps.sealer.open({ sealed: JSON.parse(Buffer.from(state, 'base64url').toString()) }, { aad }),
99
- } });
100
- }
101
- async function assertOwner(actorId) {
102
- if (actorId !== await shared.ownerPrincipalId)
103
- throw new ApiConnectionError({ code: 'access-denied', message: ports.copy.sharedOwnerOnly });
104
- }
105
119
  async function createSelection(input) {
106
120
  const server = await deps.repo.findByServerId({ workspaceId: deps.workspaceId, serverId: input.serverId });
107
121
  if (!server || server.transport === 'stdio')
@@ -126,7 +140,27 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
126
140
  } });
127
141
  return { binding: { credentialId }, context };
128
142
  }
129
- async function install(serverId, context, generation, tokens) {
143
+ return { selected, createSelection, target };
144
+ }
145
+ function createSharedMcpAttempts(access) {
146
+ const { deps, ports, owner, attachments, siteId, invalidState, unavailable, bindingFor } = access;
147
+ async function assertAttempt(serverId, credentialId, generation) {
148
+ const [binding, record, granted] = await Promise.all([bindingFor({ serverId }), owner.records.read({ key: credentialId }), attachments.isAttached({ siteId, keyId: credentialId })]);
149
+ if (binding?.credentialId !== credentialId || !granted || !record)
150
+ throw invalidState();
151
+ if (record.generation !== generation || record.status === 'revocation-pending')
152
+ throw invalidState();
153
+ return record;
154
+ }
155
+ function stateFor(input) {
156
+ const aad = ports.aad.format({ kind: 'oauth-redirect-state', version: 'v1', parts: [JSON.stringify(['shared', siteId, input.serverId, input.credentialId, input.generation, input.browserBinding])] });
157
+ return ports.flow.createSealedAuthorizationState({ clock: deps.clock, workspaceId: siteId, serverId: input.serverId, codec: {
158
+ seal: async ({ plaintext }) => Buffer.from(JSON.stringify(await deps.sealer.seal({ plaintext, key: await deps.keyring.activeKey({}), aad }))).toString('base64url'),
159
+ open: async ({ state }) => deps.sealer.open({ sealed: JSON.parse(Buffer.from(state, 'base64url').toString()) }, { aad }),
160
+ } });
161
+ }
162
+ async function install(serverId, context, result) {
163
+ const { generation, tokens } = result;
130
164
  const grantedScopes = tokens.scopes.length ? tokens.scopes : context.mcp.scopes;
131
165
  if (context.mcp.scopes.some(scope => !grantedScopes.includes(scope)))
132
166
  throw unavailable();
@@ -138,6 +172,10 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
138
172
  await owner.tokensFor({ context }).install({ key: record.key, tokens: { ...tokens, scopes: [...grantedScopes] }, generation: next.generation });
139
173
  await assertAttempt(serverId, context.credentialId, next.generation);
140
174
  }
175
+ return { assertAttempt, stateFor, install };
176
+ }
177
+ function createSharedMcpInventory(access) {
178
+ const { deps, shared, owner, attachments, siteId, bindingFor, assertOwner } = access;
141
179
  async function connectionOption(credentialId, record) {
142
180
  const context = await owner.readContext({ credentialId });
143
181
  if (!context?.mcp || context.mcp.url !== record?.url)
@@ -166,6 +204,11 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
166
204
  }
167
205
  return { available: true, connections, current: await currentSelection(input) };
168
206
  },
207
+ };
208
+ }
209
+ function createSharedMcpAccessMethods(selection, consumer, bindingFor) {
210
+ const { selected } = selection;
211
+ return {
169
212
  hasBinding: async (input) => (await bindingFor(input)) !== null,
170
213
  async getAccessToken(input) {
171
214
  const found = await selected(input.serverId);
@@ -178,6 +221,12 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
178
221
  await consumer.assertAuthorized(found.target);
179
222
  return true;
180
223
  },
224
+ };
225
+ }
226
+ function createSharedMcpBindingMethods(access, selection, consumer) {
227
+ const { deps, shared, owner, bindings, attachments, siteId, unavailable, contextFor, bindingFor, assertOwner } = access;
228
+ const { target } = selection;
229
+ return {
181
230
  async useSaved(input) {
182
231
  await assertOwner(input.actorId);
183
232
  const context = await contextFor(input.credentialId);
@@ -204,6 +253,13 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
204
253
  await bindings.remove({ consumerId: consumerId(input.serverId) });
205
254
  } });
206
255
  },
256
+ };
257
+ }
258
+ function createSharedMcpConnectMethod(access, selection, attempts) {
259
+ const { deps, ports, owner, siteId, unavailable, assertOwner, deviceKeyFor } = access;
260
+ const { selected, createSelection } = selection;
261
+ const { assertAttempt, stateFor } = attempts;
262
+ return {
207
263
  async beginConnect(input) {
208
264
  await assertOwner(input.actorId);
209
265
  const found = input.destination === 'shared' ? await createSelection(input) : await selected(input.serverId) ?? await createSelection(input);
@@ -230,6 +286,13 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
230
286
  client: context.client, redirectUri: input.redirectUri, options: { clientDisplayName: ports.registrationIdentity.sharedClientName, softwareId: ports.registrationIdentity.softwareId, redirectUris: [input.redirectUri] } }, { scopes: context.mcp.scopes, ...(context.identity.resource === undefined ? {} : { resource: context.identity.resource }) });
231
287
  return { kind: 'redirect_required', authorizationUrl: started.authorizationUrl, expiresAt: started.expiresAt };
232
288
  },
289
+ };
290
+ }
291
+ function createSharedMcpCallbackMethod(access, selection, attempts) {
292
+ const { deps, ports, owner, siteId, invalidState } = access;
293
+ const { selected } = selection;
294
+ const { assertAttempt, stateFor, install } = attempts;
295
+ return {
233
296
  async completeAuthorizationCallback(input) {
234
297
  const found = await selected(input.serverId);
235
298
  if (!found)
@@ -242,8 +305,15 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
242
305
  const tokens = await ports.flow.completeAuthorizationCode({ ...deps.httpPorts, provider: context.mcp.provider, clock: deps.clock,
243
306
  stateless: stateFor({ ...input, credentialId: binding.credentialId, generation: record.generation }), redirectUri: input.redirectUri,
244
307
  ownerKey: JSON.stringify([siteId, input.serverId, binding.credentialId]), client: context.client, params: input.params }, { timeoutMs: 15_000 });
245
- await install(input.serverId, context, record.generation, tokens);
308
+ await install(input.serverId, context, { generation: record.generation, tokens });
246
309
  },
310
+ };
311
+ }
312
+ function createSharedMcpPollingMethod(access, selection, attempts) {
313
+ const { deps, ports, owner, invalidState, deviceKeyFor } = access;
314
+ const { selected } = selection;
315
+ const { assertAttempt, install } = attempts;
316
+ return {
247
317
  async pollDeviceAuthorization(input) {
248
318
  const found = await selected(input.serverId);
249
319
  if (!found)
@@ -261,7 +331,7 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
261
331
  const tokens = await ports.flow.pollDeviceAuthorizationOnce({ ...deps.httpPorts, provider: context.mcp.provider, clock: deps.clock,
262
332
  client: context.client, deviceCode: authorization.deviceCode, expiresAt: authorization.expiresAt }, { ...(context.identity.resource === undefined ? {} : { resource: context.identity.resource }), timeoutMs: 15_000 });
263
333
  await deps.devices.delete(deviceKey);
264
- await install(input.serverId, context, record.generation, tokens);
334
+ await install(input.serverId, context, { generation: record.generation, tokens });
265
335
  return { status: 'connected' };
266
336
  }
267
337
  catch (error) {
@@ -271,6 +341,12 @@ export function createSharedExternalMcpOAuth(required, _optional = {}) {
271
341
  throw error;
272
342
  }
273
343
  },
344
+ };
345
+ }
346
+ function createSharedMcpDisconnectMethods(access, selection) {
347
+ const { shared, owner, attachments, siteId, bindingFor } = access;
348
+ const { selected } = selection;
349
+ return {
274
350
  async markNeedsReauth(input) {
275
351
  const found = await selected(input.serverId);
276
352
  if (!found || !await attachments.isAttached({ siteId, keyId: found.binding.credentialId }))
@@ -0,0 +1,29 @@
1
+ import type { ExternalMcpServerRecord } from "@jini-ai/core/contracts/hosted-mcp";
2
+ import { type SignInDeps } from "./sign-in-provider.js";
3
+ /**
4
+ * Fills in whatever a connection is missing, persists it, and returns the row as it now stands.
5
+ *
6
+ * A no-op — and, importantly, ZERO outbound requests — for a connection that already names its
7
+ * endpoints, its grant AND its client id. That is what keeps every existing connection behaving
8
+ * exactly as it did: self-configuration is reached only by a row that could not have connected at
9
+ * all before, or that named everything except which grant to use.
10
+ *
11
+ * Nothing is written until every step has succeeded, so a failed registration leaves the row exactly
12
+ * as it was and the operator's retry is a clean retry rather than one over half-written state.
13
+ *
14
+ * @param redirectUri - The absolute callback URL this connect will use, registered verbatim.
15
+ * @returns The row, self-configured if it needed to be.
16
+ * @throws {OAuthError} From discovery, grant resolution, or registration; every one is terminal and
17
+ * nothing is retried.
18
+ * @complexity O(1) in row size; a bounded, small number of outbound requests, and none at all on the
19
+ * already-configured path.
20
+ */
21
+ export declare function selfConfigureConnection({ deps, record, redirectUri, options }: {
22
+ deps: SignInDeps;
23
+ record: ExternalMcpServerRecord;
24
+ redirectUri: string | undefined;
25
+ options?: {
26
+ readonly configurationOnly?: boolean;
27
+ } | undefined;
28
+ }, _optional?: {}): Promise<ExternalMcpServerRecord>;
29
+ //# sourceMappingURL=sign-in-configuration.d.ts.map
@@ -0,0 +1,127 @@
1
+ import { nowIso as readNowIso } from "@jini-ai/core/primitives";
2
+ import { updateRowOnce } from "./oauth-row-writes.js";
3
+ import { readStoredEndpoints, readStoredScopes, requireOAuthRecord, isStaleSelfRegisteredClient, withoutSelfRegisteredClient } from "./sign-in-provider.js";
4
+ import { needsEndpointDiscovery, toStoredEndpoints, discoverConnectionAuthorizationServer, resolveGrantFromDiscovery, mintClientForConnection } from "./sign-in-discovery.js";
5
+ /** Writes one connect's self-configuration onto the row, preserving anything already sealed beside it.
6
+ *
7
+ * Read-modify-write for the same reason {@link persistTokens} is: sealing `{ clientSecret }` alone
8
+ * would delete a token the connection is still holding.
9
+ * @complexity O(1) — one unseal, one seal, one conditional write. */
10
+ async function persistSelfConfiguration(deps, record, identity, options = {}) {
11
+ const build = async (current) => {
12
+ const existing = await deps.ports.store.openPayload(deps.sealer, current);
13
+ const clientSecret = identity.clientSecret === undefined ? existing.clientSecret : (identity.clientSecret ?? undefined);
14
+ const { sealedOAuth, oauthAadVersion } = await deps.ports.store.sealPayload(deps, current, {
15
+ ...(clientSecret === undefined ? {} : { clientSecret }),
16
+ ...(existing.tokens === undefined ? {} : { tokens: existing.tokens }),
17
+ });
18
+ return {
19
+ ...current,
20
+ oauthGrant: identity.grant,
21
+ oauthClientId: identity.clientId,
22
+ oauthEndpointsJson: JSON.stringify(identity.endpoints),
23
+ oauthScopesJson: JSON.stringify(identity.scopes),
24
+ sealedOAuth,
25
+ // Carried from the seal, never from `...current` — the spread holds the row's OLD version.
26
+ oauthAadVersion,
27
+ updatedAt: readNowIso({ clock: deps.clock }),
28
+ };
29
+ };
30
+ if (options.configurationOnly)
31
+ return build(record);
32
+ // Sign-in configuration is an editor-visible change: compared on version, retried once (M4).
33
+ return (await updateRowOnce({ repo: deps.repo, key: record, build })) ?? requireOAuthRecord(deps, record.serverId);
34
+ }
35
+ /**
36
+ * Fills in whatever a connection is missing, persists it, and returns the row as it now stands.
37
+ *
38
+ * A no-op — and, importantly, ZERO outbound requests — for a connection that already names its
39
+ * endpoints, its grant AND its client id. That is what keeps every existing connection behaving
40
+ * exactly as it did: self-configuration is reached only by a row that could not have connected at
41
+ * all before, or that named everything except which grant to use.
42
+ *
43
+ * Nothing is written until every step has succeeded, so a failed registration leaves the row exactly
44
+ * as it was and the operator's retry is a clean retry rather than one over half-written state.
45
+ *
46
+ * @param redirectUri - The absolute callback URL this connect will use, registered verbatim.
47
+ * @returns The row, self-configured if it needed to be.
48
+ * @throws {OAuthError} From discovery, grant resolution, or registration; every one is terminal and
49
+ * nothing is retried.
50
+ * @complexity O(1) in row size; a bounded, small number of outbound requests, and none at all on the
51
+ * already-configured path.
52
+ */
53
+ export async function selfConfigureConnection({ deps, record, redirectUri, options = {} }, _optional = {}) {
54
+ const stored = readStoredEndpoints(record);
55
+ const mustDiscover = needsEndpointDiscovery(record, stored);
56
+ const mustResolveGrant = record.oauthGrant === null;
57
+ const keepClient = record.oauthClientId !== null && !isStaleSelfRegisteredClient({ record, endpoints: stored, redirectUri });
58
+ if (!mustDiscover && !mustResolveGrant && keepClient)
59
+ return record;
60
+ const discovered = await discoverConnectionAuthorizationServer(deps, record);
61
+ const discoveredEndpoints = toStoredEndpoints(discovered);
62
+ const endpoints = selfConfiguredEndpoints({ mustDiscover, discoveredEndpoints, stored });
63
+ const grant = selfConfiguredGrant({ record, discovered, ports: deps.ports });
64
+ const scopes = selfConfiguredScopes({ record, discovered });
65
+ // Narrowed on the field rather than on `mustRegister`, so there is no fallback that could write an
66
+ // empty client id if the two ever disagreed.
67
+ if (keepClient && record.oauthClientId !== null) {
68
+ return persistSelfConfiguration(deps, record, { endpoints, scopes, grant, clientId: record.oauthClientId, clientSecret: undefined }, options);
69
+ }
70
+ const minted = await mintClientForConnection({ deps, record, discovered, input: { redirectUri, scopes, grant } });
71
+ return persistSelfConfiguration(deps, record, {
72
+ endpoints: withMintedClient({ endpoints, minted, redirectUri }),
73
+ scopes,
74
+ grant,
75
+ clientId: minted.clientId,
76
+ clientSecret: minted.clientSecret,
77
+ }, options);
78
+ }
79
+ /**
80
+ * The endpoints a self-configuring connect stores.
81
+ * Endpoints the operator typed win; discovery only fills the ones left blank (a typed token
82
+ * endpoint alone has no authorization endpoint to redirect to).
83
+ * @complexity O(1).
84
+ */
85
+ function selfConfiguredEndpoints({ mustDiscover, discoveredEndpoints, stored }) {
86
+ return mustDiscover ? discoveredEndpoints : { ...discoveredEndpoints, ...stored, resource: discoveredEndpoints.resource ?? stored.resource };
87
+ }
88
+ /**
89
+ * The grant a self-configuring connect uses. Resolved from the SAME discovery call that found the
90
+ * endpoints, on the same terms as those and the client id: an operator-named grant always wins, and
91
+ * only a row that left it blank asks the server what it actually supports rather than have
92
+ * `beginConnect` guess. The cast is safe: every non-null `oauthGrant` on a row was either validated by
93
+ * `assertOAuthGrant` at save time or written by a PRIOR call to this same resolver, so it is always one
94
+ * of `EXTERNAL_MCP_OAUTH_GRANTS` even though the column's declared type is a bare `string | null`.
95
+ * @throws {OAuthError} From {@link resolveGrantFromDiscovery}.
96
+ * @complexity O(n) in the number of advertised grant types.
97
+ */
98
+ function selfConfiguredGrant(required) {
99
+ const { record, discovered } = required;
100
+ return record.oauthGrant === null ? resolveGrantFromDiscovery({ grantTypesSupported: discovered.server.grantTypesSupported, serverId: record.serverId, ports: required.ports }) : record.oauthGrant;
101
+ }
102
+ /**
103
+ * The scopes a self-configuring connect requests. Scopes the operator named win; an empty list adopts
104
+ * what the resource itself asks for, because a resource that advertises `offline_access` is naming
105
+ * the scope that decides whether this connection can ever refresh.
106
+ * @complexity O(n) in the number of scopes.
107
+ */
108
+ function selfConfiguredScopes(required) {
109
+ const operatorScopes = readStoredScopes(required.record);
110
+ return operatorScopes.length > 0 ? operatorScopes : [...required.discovered.resourceScopes];
111
+ }
112
+ /**
113
+ * The endpoints blob for a freshly minted client: any previous self-registered client's marks
114
+ * dropped, then this client's own — its id, the callback it was registered with (none for a
115
+ * device-grant connect), and `clientAuth` only when the server issued a secret.
116
+ * @complexity O(1).
117
+ */
118
+ function withMintedClient(required) {
119
+ const { endpoints, minted, redirectUri } = required;
120
+ return {
121
+ ...withoutSelfRegisteredClient(endpoints),
122
+ ...(minted.clientSecret === null ? {} : { clientAuth: minted.tokenEndpointAuthMethod }),
123
+ dynamicClientId: minted.clientId,
124
+ ...(redirectUri === undefined ? {} : { registeredRedirectUri: redirectUri }),
125
+ };
126
+ }
127
+ //# sourceMappingURL=sign-in-configuration.js.map
@@ -0,0 +1,72 @@
1
+ import type { DiscoveredOAuthConfiguration } from "@jini-ai/core/contracts/oauth";
2
+ import type { ExternalMcpOAuthGrant, ExternalMcpServerRecord } from "@jini-ai/core/contracts/hosted-mcp";
3
+ import type { HostedMcpSignInPorts } from "./contracts.js";
4
+ import { type SignInDeps, type StoredOAuthEndpoints } from "./sign-in-provider.js";
5
+ /** Whether a row still has to be told where its authorization server is. @complexity O(1). */
6
+ export declare function needsEndpointDiscovery(record: ExternalMcpServerRecord, endpoints: StoredOAuthEndpoints): boolean;
7
+ /**
8
+ * Narrows a discovered authorization server into the blob shape the row stores.
9
+ *
10
+ * The `registration_endpoint` is deliberately NOT stored: nothing reads it once the client is minted,
11
+ * and a credential-adjacent URL kept for no reader is a liability rather than a convenience.
12
+ *
13
+ * @complexity O(1).
14
+ */
15
+ export declare function toStoredEndpoints(discovered: DiscoveredOAuthConfiguration & {
16
+ readonly resource?: string | null | undefined;
17
+ }): StoredOAuthEndpoints;
18
+ /**
19
+ * Runs RFC 9728 / RFC 8414 discovery against the connection's own MCP endpoint.
20
+ *
21
+ * @throws {OAuthError} `OAUTH_INVALID_REQUEST` when the row has no URL to discover from — a stdio
22
+ * connection, which the store still requires to name its provider explicitly. Same message the
23
+ * non-discovering path has always used, because from the operator's side it is the same problem.
24
+ * @complexity O(1) in row size; a bounded, small number of outbound requests.
25
+ */
26
+ export declare function discoverConnectionAuthorizationServer(deps: SignInDeps, record: ExternalMcpServerRecord): Promise<DiscoveredOAuthConfiguration>;
27
+ /**
28
+ * Resolves the sign-in method for a connection whose row names none, from what its OWN
29
+ * authorization server advertises — the same "ask the server, don't ask the operator" move as
30
+ * {@link discoverConnectionAuthorizationServer} makes for endpoints and {@link mintClientForConnection}
31
+ * makes for client identity.
32
+ *
33
+ * `authorization_code` wins whenever the server offers it: it is the redirect-based grant every
34
+ * browser-capable client uses, and it is what an operator would pick by default anyway.
35
+ * `device_code` exists specifically for the flow a browser cannot run (RFC 8628 — the human types a
36
+ * code at the provider instead of being redirected), so it is a fallback rather than a co-equal
37
+ * choice, taken only when the server names no other grant this sign-in implements.
38
+ *
39
+ * @throws {OAuthError} `OAUTH_INVALID_REQUEST` when the metadata names neither grant this sign-in
40
+ * implements — naming exactly what the server DID advertise, since an operator who only sees
41
+ * "connect failed" has no way to guess that from the failure alone.
42
+ * @complexity O(n) in the number of advertised grant types.
43
+ */
44
+ export declare function resolveGrantFromDiscovery({ grantTypesSupported, serverId, ports }: {
45
+ grantTypesSupported: readonly string[];
46
+ serverId: string;
47
+ ports: HostedMcpSignInPorts;
48
+ }, _optional?: {}): ExternalMcpOAuthGrant;
49
+ /**
50
+ * Mints a client for a connection that has none.
51
+ *
52
+ * @param input.redirectUri - Registered as this client's only callback. A server that pins redirect
53
+ * URIs will refuse an authorization whose `redirect_uri` was not registered, so the value used at
54
+ * authorization time is the value registered here — not a re-derived one. `undefined` registers no
55
+ * callback at all, which is correct (and the only honest option) for a device-grant client.
56
+ * @param input.grant - The RESOLVED grant — see {@link registrationGrantTypes} for why this must not
57
+ * be read back off `record`.
58
+ * @throws {OAuthError} `OAUTH_INVALID_REQUEST` when the authorization server offers no registration
59
+ * endpoint, which is the point at which an operator genuinely does have to supply a client id.
60
+ * @complexity O(1) — one bounded outbound request.
61
+ */
62
+ export declare function mintClientForConnection({ deps, record, discovered, input }: {
63
+ deps: SignInDeps;
64
+ record: ExternalMcpServerRecord;
65
+ discovered: DiscoveredOAuthConfiguration;
66
+ input: {
67
+ readonly redirectUri: string | undefined;
68
+ readonly scopes: readonly string[];
69
+ readonly grant: ExternalMcpOAuthGrant;
70
+ };
71
+ }, _optional?: {}): Promise<import("@jini-ai/oauth").RegisteredOAuthClient>;
72
+ //# sourceMappingURL=sign-in-discovery.d.ts.map