@jini-ai/integrations 0.7.3-next.2 → 0.7.3-next.3

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 (187) hide show
  1. package/README.md +1 -0
  2. package/dist/api-connections/bundled-client-namespace.d.ts +24 -0
  3. package/dist/api-connections/bundled-client-namespace.js +22 -0
  4. package/dist/api-connections/connect.d.ts +2 -10
  5. package/dist/api-connections/contribution.d.ts +71 -0
  6. package/dist/api-connections/contribution.js +69 -0
  7. package/dist/api-connections/form-delivery-connection.d.ts +68 -0
  8. package/dist/api-connections/form-delivery-connection.js +73 -0
  9. package/dist/api-connections/hosted-mcp/contracts.d.ts +4 -171
  10. package/dist/api-connections/hosted-mcp/index.d.ts +2 -0
  11. package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +3 -1
  12. package/dist/api-connections/hosted-mcp/oauth-row-writes.js +6 -3
  13. package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +2 -1
  14. package/dist/api-connections/hosted-mcp/sign-in-configuration.js +1 -1
  15. package/dist/api-connections/hosted-mcp/sign-in-discovery.js +1 -1
  16. package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +9 -3
  17. package/dist/api-connections/hosted-mcp/sign-in-flow.js +6 -6
  18. package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +16 -4
  19. package/dist/api-connections/hosted-mcp/sign-in-provider.js +3 -3
  20. package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +13 -2
  21. package/dist/api-connections/hosted-mcp/sign-in-status.js +17 -4
  22. package/dist/api-connections/hosted-mcp/sign-in.d.ts +1 -1
  23. package/dist/api-connections/hosted-mcp/sign-in.js +28 -30
  24. package/dist/api-connections/shared-api.d.ts +87 -0
  25. package/dist/api-connections/shared-api.js +135 -0
  26. package/dist/api-connections/shared-oauth-disconnect.d.ts +73 -0
  27. package/dist/api-connections/shared-oauth-disconnect.js +41 -0
  28. package/dist/api-connections/shared-owner.d.ts +107 -0
  29. package/dist/api-connections/shared-owner.js +79 -0
  30. package/dist/api-connections/vault-stores.d.ts +110 -0
  31. package/dist/api-connections/vault-stores.js +202 -0
  32. package/dist/credentialed-http/auth-schemes.d.ts +2 -9
  33. package/dist/credentialed-http/tools/index.d.ts +30 -0
  34. package/dist/credentialed-http/tools/index.js +19 -0
  35. package/dist/credentialed-http/tools/tool-registrations.js +0 -1
  36. package/dist/custom-credentials/agent-tools.d.ts +79 -0
  37. package/dist/custom-credentials/agent-tools.js +98 -0
  38. package/dist/custom-credentials/card-token.d.ts +15 -0
  39. package/dist/custom-credentials/card-token.js +35 -0
  40. package/dist/custom-credentials/credential-ports.d.ts +70 -0
  41. package/dist/custom-credentials/credential-ports.js +41 -0
  42. package/dist/custom-credentials/credential-recovery.d.ts +20 -0
  43. package/dist/custom-credentials/credential-recovery.js +22 -0
  44. package/dist/custom-credentials/credentialed-request.d.ts +83 -0
  45. package/dist/custom-credentials/credentialed-request.js +93 -0
  46. package/dist/custom-credentials/custom-credential-create-ui.d.ts +106 -0
  47. package/dist/custom-credentials/custom-credential-create-ui.js +136 -0
  48. package/dist/custom-credentials/custom-credential-set-token-ui.d.ts +84 -0
  49. package/dist/custom-credentials/custom-credential-set-token-ui.js +104 -0
  50. package/dist/custom-credentials/delete-request-confirmation-ui.d.ts +33 -0
  51. package/dist/custom-credentials/delete-request-confirmation-ui.js +35 -0
  52. package/dist/custom-credentials/provider-settings-card.d.ts +109 -0
  53. package/dist/custom-credentials/provider-settings-card.js +166 -0
  54. package/dist/custom-credentials/write-files-validation.d.ts +102 -0
  55. package/dist/custom-credentials/write-files-validation.js +202 -0
  56. package/dist/media-providers/catalog-projection.d.ts +29 -0
  57. package/dist/media-providers/catalog-projection.js +45 -0
  58. package/dist/media-providers/catalog.d.ts +6 -3
  59. package/dist/media-providers/catalog.js +4 -3
  60. package/dist/media-providers/configurable-catalog.d.ts +9 -0
  61. package/dist/media-providers/configurable-catalog.js +70 -0
  62. package/dist/media-providers/dispatch/builtin-vendors.js +0 -2
  63. package/dist/media-providers/dispatch/credentials.d.ts +4 -1
  64. package/dist/media-providers/dispatch/credentials.js +3 -2
  65. package/dist/media-providers/dispatch/engine.d.ts +1 -1
  66. package/dist/media-providers/dispatch/engine.js +17 -5
  67. package/dist/media-providers/dispatch/index.d.ts +3 -2
  68. package/dist/media-providers/dispatch/index.js +2 -2
  69. package/dist/media-providers/dispatch/media-provider-registry.d.ts +23 -4
  70. package/dist/media-providers/dispatch/media-provider-registry.js +26 -11
  71. package/dist/media-providers/dispatch/media-wire.d.ts +14 -0
  72. package/dist/media-providers/dispatch/media-wire.js +22 -0
  73. package/dist/media-providers/dispatch/node.d.ts +5 -0
  74. package/dist/media-providers/dispatch/node.js +5 -1
  75. package/dist/media-providers/dispatch/openai-compatible.d.ts +3 -1
  76. package/dist/media-providers/dispatch/openai-compatible.js +1 -1
  77. package/dist/media-providers/dispatch/operation-runtime.js +5 -4
  78. package/dist/media-providers/dispatch/outbound.d.ts +28 -3
  79. package/dist/media-providers/dispatch/outbound.js +10 -3
  80. package/dist/media-providers/dispatch/providers/custom-image.js +1 -1
  81. package/dist/media-providers/dispatch/providers/imagerouter.js +1 -1
  82. package/dist/media-providers/dispatch/providers/nanobanana.js +1 -1
  83. package/dist/media-providers/dispatch/providers/openrouter.js +1 -1
  84. package/dist/media-providers/dispatch/ssrf-guard.js +2 -2
  85. package/dist/media-providers/dispatch/types.d.ts +13 -4
  86. package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
  87. package/dist/media-providers/index.d.ts +2 -0
  88. package/dist/media-providers/providers.d.ts +9 -5
  89. package/dist/media-providers/providers.js +9 -12
  90. package/dist/media-providers/sqlite-task-store.d.ts +4 -4
  91. package/dist/media-providers/task-store.d.ts +1 -1
  92. package/dist/media-providers/task-store.js +1 -1
  93. package/dist/media-providers/types.d.ts +0 -36
  94. package/dist/media-providers/ui-defaults.js +0 -4
  95. package/dist/react/admin-credentials/AdminByokKeyPanel.d.ts +130 -0
  96. package/dist/react/admin-credentials/AdminByokKeyPanel.js +115 -0
  97. package/dist/react/admin-credentials/byok-footer-status.d.ts +37 -0
  98. package/dist/react/admin-credentials/byok-footer-status.js +25 -0
  99. package/dist/react/credentials/OtherCredentialsSection.d.ts +36 -0
  100. package/dist/react/credentials/OtherCredentialsSection.hooks.d.ts +55 -0
  101. package/dist/react/credentials/OtherCredentialsSection.hooks.js +26 -0
  102. package/dist/react/credentials/OtherCredentialsSection.js +120 -0
  103. package/dist/react/credentials/access-token-forms.d.ts +219 -0
  104. package/dist/react/credentials/access-token-forms.js +114 -0
  105. package/dist/react/credentials/credential-copy.d.ts +17 -0
  106. package/dist/react/credentials/credential-copy.js +7 -0
  107. package/dist/react/credentials/other-credential-stores.d.ts +115 -0
  108. package/dist/react/credentials/other-credential-stores.js +76 -0
  109. package/dist/react/site-key/SiteKeyRecoveryCard.d.ts +16 -0
  110. package/dist/react/site-key/SiteKeyRecoveryCard.js +36 -0
  111. package/dist/react/site-key/SiteKeyTab.d.ts +100 -0
  112. package/dist/react/site-key/SiteKeyTab.js +127 -0
  113. package/dist/react/site-key/hooks/use-site-key-recovery.hooks.d.ts +77 -0
  114. package/dist/react/site-key/hooks/use-site-key-recovery.hooks.js +126 -0
  115. package/dist/react/site-key/hooks/use-site-key.hooks.d.ts +120 -0
  116. package/dist/react/site-key/hooks/use-site-key.hooks.js +95 -0
  117. package/dist/react/webhooks/IntegrationDeliveries.d.ts +41 -0
  118. package/dist/react/webhooks/IntegrationDeliveries.js +24 -0
  119. package/dist/react/webhooks/Integrations.d.ts +73 -0
  120. package/dist/react/webhooks/Integrations.js +97 -0
  121. package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.d.ts +59 -0
  122. package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.js +11 -0
  123. package/dist/react/webhooks/hooks/use-integrations.hooks.d.ts +119 -0
  124. package/dist/react/webhooks/hooks/use-integrations.hooks.js +129 -0
  125. package/dist/react/webhooks/rules.d.ts +118 -0
  126. package/dist/react/webhooks/rules.js +103 -0
  127. package/dist/saved-requests/execute.js +2 -3
  128. package/dist/saved-requests/types.d.ts +4 -1
  129. package/dist/secrets/index.d.ts +3 -0
  130. package/dist/secrets/index.js +3 -0
  131. package/dist/secrets/ports.d.ts +25 -0
  132. package/dist/secrets/ports.js +2 -0
  133. package/dist/secrets/types.d.ts +10 -0
  134. package/dist/secrets/types.js +2 -0
  135. package/dist/vendor-credentials/abort-guarded-repo.d.ts +14 -0
  136. package/dist/vendor-credentials/abort-guarded-repo.js +41 -0
  137. package/dist/vendor-credentials/project-scope.d.ts +43 -0
  138. package/dist/vendor-credentials/project-scope.js +32 -0
  139. package/dist/vendor-credentials/vault-adapter.d.ts +147 -0
  140. package/dist/vendor-credentials/vault-adapter.js +195 -0
  141. package/dist/web-screenshot/capture-files.d.ts +44 -0
  142. package/dist/web-screenshot/capture-files.js +62 -0
  143. package/dist/web-screenshot/capture-retention.d.ts +157 -0
  144. package/dist/web-screenshot/capture-retention.js +134 -0
  145. package/dist/web-screenshot/capture-root-file-lock.d.ts +20 -0
  146. package/dist/web-screenshot/capture-root-file-lock.js +15 -0
  147. package/dist/web-screenshot/desktop-page-capture.d.ts +37 -0
  148. package/dist/web-screenshot/desktop-page-capture.js +62 -0
  149. package/dist/web-screenshot/own-site-opener.d.ts +40 -0
  150. package/dist/web-screenshot/own-site-opener.js +27 -0
  151. package/dist/web-screenshot/screenshot-image.d.ts +11 -0
  152. package/dist/web-screenshot/screenshot-image.js +12 -0
  153. package/dist/web-screenshot/web-screenshot.d.ts +188 -0
  154. package/dist/web-screenshot/web-screenshot.js +329 -0
  155. package/dist/webhooks/delivery.d.ts +16 -0
  156. package/dist/webhooks/delivery.js +41 -1
  157. package/dist/webhooks/ports.d.ts +1 -29
  158. package/dist/webhooks/signing.keyring.d.ts +1 -1
  159. package/dist/webhooks/site/delivery.d.ts +60 -0
  160. package/dist/webhooks/site/delivery.js +45 -0
  161. package/dist/webhooks/site/http.memory.d.ts +51 -0
  162. package/dist/webhooks/site/http.memory.js +28 -0
  163. package/dist/webhooks/site/repo.memory.d.ts +136 -0
  164. package/dist/webhooks/site/repo.memory.js +215 -0
  165. package/dist/webhooks/site/seal-aad-invariant.d.ts +26 -0
  166. package/dist/webhooks/site/seal-aad-invariant.js +61 -0
  167. package/dist/webhooks/site/seal-aad-invariant.node.d.ts +42 -0
  168. package/dist/webhooks/site/seal-aad-invariant.node.js +52 -0
  169. package/dist/webhooks/site/signing.d.ts +28 -0
  170. package/dist/webhooks/site/signing.js +27 -0
  171. package/dist/webhooks/site/signing.keyring.d.ts +29 -0
  172. package/dist/webhooks/site/signing.keyring.js +30 -0
  173. package/dist/webhooks/site/subscriptions.d.ts +118 -0
  174. package/dist/webhooks/site/subscriptions.js +98 -0
  175. package/dist/webhooks/sql/index.d.ts +4 -0
  176. package/dist/webhooks/sql/index.js +2 -0
  177. package/dist/webhooks/sql/repo.rows.d.ts +47 -0
  178. package/dist/webhooks/sql/repo.rows.js +2 -0
  179. package/dist/webhooks/sql/webhook-repo.d.ts +152 -0
  180. package/dist/webhooks/sql/webhook-repo.js +308 -0
  181. package/dist/webhooks/subscriptions.d.ts +3 -1
  182. package/dist/webhooks/subscriptions.js +4 -1
  183. package/dist/webhooks/tools/tool-handlers.js +2 -1
  184. package/dist/webhooks/types.d.ts +6 -10
  185. package/package.json +517 -12
  186. package/dist/media-providers/dispatch/providers/grok.d.ts +0 -55
  187. package/dist/media-providers/dispatch/providers/grok.js +0 -116
package/README.md CHANGED
@@ -7,6 +7,7 @@ exports. Import the capability you need; each entry owns its dependencies and ru
7
7
  |---|---|---|
8
8
  | `./media-providers` | Node | Image/video/audio gateway, policy, staging and task stores |
9
9
  | `./media-providers/catalog` | Universal | Browser-safe provider/model catalog |
10
+ | `./api-connections/bundled-client-namespace` | Universal | Client-setting prefix reader over bundled plugin manifests; unselected ids are never read |
10
11
  | `./credentialed-http` | Node | Credential-origin binding, authentication, redacted responses and audit ports |
11
12
  | `./saved-requests` | Node | Fixed-target declarative requests, bounded schemas and typed public projections |
12
13
  | `./webhooks` | Node | Subscriptions, delivery/retries and signing through host ports |
@@ -0,0 +1,24 @@
1
+ import type { ClientNamespaceFor } from "@jini-ai/core/contracts/site/integrations-api-connections";
2
+ /**
3
+ * @file The client-setting prefix each BUNDLED plugin's own `plugin.json` declares
4
+ * (`extensions.jini.clientNamespace`). Vendor names live in those manifests, never in host code.
5
+ * Only bundled manifests are read: an installed plugin cannot choose a prefix, so it keeps the host's.
6
+ */
7
+ /**
8
+ * Builds the resolver the API-connection loader asks, one plugin at a time.
9
+ * @param required.pluginIds Ids of the bundled plugins; any other id resolves to `undefined`.
10
+ * @param required.readManifest Returns the parsed `plugin.json` of a bundled plugin, or `null` when it cannot be read.
11
+ * @param required.readClientNamespace Projects a parsed manifest to its declared client-setting prefix, or `undefined` when it declares none (or a malformed one).
12
+ * @returns A resolver; a missing, unreadable or invalid declaration resolves to `undefined` (the host's own prefix applies).
13
+ * @complexity O(1) per call, one manifest read.
14
+ */
15
+ export declare function createBundledClientNamespaceReader(required: {
16
+ readonly pluginIds: ReadonlySet<string>;
17
+ readonly readManifest: (input: {
18
+ readonly pluginId: string;
19
+ }) => unknown;
20
+ readonly readClientNamespace: (required: {
21
+ readonly value: unknown;
22
+ }) => string | undefined;
23
+ }, _optional?: Record<string, never>): ClientNamespaceFor;
24
+ //# sourceMappingURL=bundled-client-namespace.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file The client-setting prefix each BUNDLED plugin's own `plugin.json` declares
3
+ * (`extensions.jini.clientNamespace`). Vendor names live in those manifests, never in host code.
4
+ * Only bundled manifests are read: an installed plugin cannot choose a prefix, so it keeps the host's.
5
+ */
6
+ /**
7
+ * Builds the resolver the API-connection loader asks, one plugin at a time.
8
+ * @param required.pluginIds Ids of the bundled plugins; any other id resolves to `undefined`.
9
+ * @param required.readManifest Returns the parsed `plugin.json` of a bundled plugin, or `null` when it cannot be read.
10
+ * @param required.readClientNamespace Projects a parsed manifest to its declared client-setting prefix, or `undefined` when it declares none (or a malformed one).
11
+ * @returns A resolver; a missing, unreadable or invalid declaration resolves to `undefined` (the host's own prefix applies).
12
+ * @complexity O(1) per call, one manifest read.
13
+ */
14
+ export function createBundledClientNamespaceReader(required, _optional = {}) {
15
+ return async ({ pluginId }) => {
16
+ if (!required.pluginIds.has(pluginId))
17
+ return undefined;
18
+ const manifest = required.readManifest({ pluginId });
19
+ return manifest === null ? undefined : required.readClientNamespace({ value: manifest });
20
+ };
21
+ }
22
+ //# sourceMappingURL=bundled-client-namespace.js.map
@@ -2,6 +2,7 @@ import type { ApiConnectionIntent } from './types.js';
2
2
  import type { CompletedAuthorization } from './finish-authorization.js';
3
3
  import type { ApiConnectionSignInLink, ApiConnectionConnectMessages, DeclaredApiConnection } from './host-ports.js';
4
4
  import type { ApiConnectionHost } from "./host.js";
5
+ import type { ApiConnectionConnectStatus } from "@jini-ai/core/contracts/site/integrations-api-connections";
5
6
  /**
6
7
  * @file The plugin-declared API-connection branch of `agent_plugin_connect` (the single sign-in
7
8
  * entry point): start the generic sign-in, hand the card its link, and wait for the result.
@@ -18,15 +19,7 @@ import type { ApiConnectionHost } from "./host.js";
18
19
  export interface ApiConnectionConnectDeps {
19
20
  readonly host: ApiConnectionHost;
20
21
  }
21
- /**
22
- * `connectionRef` is the opaque, plugin-scoped key the plugin's tools take as input. It is not a
23
- * secret: the host refuses it for any plugin that does not declare the connection in this workspace.
24
- * Returned in both states so a later call can use it once the person finishes signing in.
25
- */
26
- export type ApiConnectionConnectStatus = {
27
- readonly status: "connected" | "waiting-for-sign-in";
28
- readonly connectionRef: string;
29
- };
22
+ export type { ApiConnectionConnectStatus } from "@jini-ai/core/contracts/site/integrations-api-connections";
30
23
  interface ConnectRun {
31
24
  readonly signInLink: ApiConnectionSignInLink;
32
25
  readonly messages: ApiConnectionConnectMessages;
@@ -83,5 +76,4 @@ interface SignInOptions {
83
76
  * @complexity One status read, one sign-in round trip bounded by `waitTimeoutMs`.
84
77
  */
85
78
  export declare function runApiConnectionConnect(required: ConnectRun, _optional?: Record<string, never>): Promise<ApiConnectionConnectStatus>;
86
- export {};
87
79
  //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1,71 @@
1
+ import { parseApiConnectionsFile as parseApiConnectionDeclarations, type ApiConnectionDeclaration, type ApiConnectionHooksModule } from './declarations.js';
2
+ import { type ApiConnectionCallbackFieldRules } from './descriptor.js';
3
+ import type { ClientNamespaceFor } from '@jini-ai/core/contracts/site/integrations-api-connections';
4
+ import type { DeclaredApiConnection } from './host-ports.js';
5
+ /**
6
+ * @file Loads the OAuth API connections Agent Plugins declare in {@link API_CONNECTIONS_FILENAME}:
7
+ * the provider descriptor Jini's api-connections service runs, the plugin's hooks module (scope
8
+ * sets, account identity, revocation) and the names of the host config that holds its client ids.
9
+ *
10
+ * TRUST RULE: hooks are plugin code running in this process, so they load through the lifecycle's
11
+ * one executable gate (ACTIVE plugin, bundled digest, contained `.mjs`), like mail adapters. The
12
+ * descriptor is untrusted until Jini's `parseApiConnectionDescriptor` accepts it. Client config is
13
+ * only ever NAMED by the plugin: names must sit in the host client namespace and the full plugin-id namespace, so a plugin can point
14
+ * at its own `…_CLIENT_ID` / `…_CLIENT_SECRET` and never at another secret of this host. Request
15
+ * budgets (`budgets`) are clamped to the host's maxima by `budgets.ts` and never reach the descriptor;
16
+ * nor do `scopeSets` (the plugin's scope-set ids, for status), `apiOrigins` (the https origins its
17
+ * API calls reach, for form delivery's host allowlist) and `byoClient` (whether a workspace admin may
18
+ * use their own OAuth client, `byo-client.ts`), which only the host reads.
19
+ */
20
+ export declare const API_CONNECTIONS_FILENAME = "jini-connections.json";
21
+ /**
22
+ * Every trusted API connection the workspace's active plugins declare, plus log-safe refusals.
23
+ * A descriptor Jini refuses drops only that connection.
24
+ * @complexity O(p + c) plugins and connections, one contained import per connection.
25
+ */
26
+ export declare function loadDeclaredApiConnections(required: {
27
+ readonly workspaceId: string;
28
+ readonly clientNamespace: string;
29
+ readonly callbackFieldRules: ApiConnectionCallbackFieldRules;
30
+ readonly loadContributions: (input: {
31
+ readonly workspaceId: string;
32
+ readonly definition: {
33
+ readonly filename: string;
34
+ readonly contribution: string;
35
+ readonly parse: (input: {
36
+ raw: string;
37
+ }) => ReturnType<typeof parseApiConnectionDeclarations>;
38
+ readonly modulePath: (input: {
39
+ descriptor: ApiConnectionDeclaration;
40
+ }) => string;
41
+ readonly validate: (input: {
42
+ exported: unknown;
43
+ }) => ApiConnectionHooksModule | string;
44
+ readonly refusal: (input: {
45
+ plugin: {
46
+ pluginId: string;
47
+ };
48
+ descriptor: ApiConnectionDeclaration;
49
+ reason: string;
50
+ }) => string;
51
+ };
52
+ readonly onReadError: (input: {
53
+ error: unknown;
54
+ }) => readonly string[] | undefined;
55
+ }, options: {
56
+ orderByPluginId: boolean;
57
+ }) => Promise<{
58
+ readonly items: readonly {
59
+ readonly pluginId: string;
60
+ readonly descriptor: ApiConnectionDeclaration;
61
+ readonly module: ApiConnectionHooksModule;
62
+ }[];
63
+ readonly refusals: readonly string[];
64
+ }>;
65
+ }, optional?: {
66
+ readonly clientNamespaceFor?: ClientNamespaceFor;
67
+ }): Promise<{
68
+ readonly connections: readonly DeclaredApiConnection[];
69
+ readonly refusals: readonly string[];
70
+ }>;
71
+ //# sourceMappingURL=contribution.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { asApiConnectionHooksModule, checkApiConnectionClientNamespace, parseApiConnectionsFile as parseApiConnectionDeclarations, } from './declarations.js';
2
+ import { parseApiConnectionDescriptor } from './descriptor.js';
3
+ /**
4
+ * @file Loads the OAuth API connections Agent Plugins declare in {@link API_CONNECTIONS_FILENAME}:
5
+ * the provider descriptor Jini's api-connections service runs, the plugin's hooks module (scope
6
+ * sets, account identity, revocation) and the names of the host config that holds its client ids.
7
+ *
8
+ * TRUST RULE: hooks are plugin code running in this process, so they load through the lifecycle's
9
+ * one executable gate (ACTIVE plugin, bundled digest, contained `.mjs`), like mail adapters. The
10
+ * descriptor is untrusted until Jini's `parseApiConnectionDescriptor` accepts it. Client config is
11
+ * only ever NAMED by the plugin: names must sit in the host client namespace and the full plugin-id namespace, so a plugin can point
12
+ * at its own `…_CLIENT_ID` / `…_CLIENT_SECRET` and never at another secret of this host. Request
13
+ * budgets (`budgets`) are clamped to the host's maxima by `budgets.ts` and never reach the descriptor;
14
+ * nor do `scopeSets` (the plugin's scope-set ids, for status), `apiOrigins` (the https origins its
15
+ * API calls reach, for form delivery's host allowlist) and `byoClient` (whether a workspace admin may
16
+ * use their own OAuth client, `byo-client.ts`), which only the host reads.
17
+ */
18
+ export const API_CONNECTIONS_FILENAME = 'jini-connections.json';
19
+ /** The first `_`-ended segment of the first declared client id setting (`VENDOR_` in `VENDOR_ACME_OAUTH_WEB_CLIENT_ID`), if the file names one. @complexity O(1). */
20
+ function declaredNamespace({ raw }, _optional = {}) {
21
+ try {
22
+ const first = JSON.parse(raw).connections?.[0]?.clients;
23
+ const id = Object.values(first ?? {})[0]?.clientIdEnv;
24
+ return typeof id === "string" ? /^[A-Z][A-Z0-9]*_/.exec(id)?.[0] : undefined;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ /**
31
+ * Every trusted API connection the workspace's active plugins declare, plus log-safe refusals.
32
+ * A descriptor Jini refuses drops only that connection.
33
+ * @complexity O(p + c) plugins and connections, one contained import per connection.
34
+ */
35
+ export async function loadDeclaredApiConnections(required, optional = {}) {
36
+ const CLIENT_NAMESPACE = required.clientNamespace;
37
+ const connectionContribution = {
38
+ filename: API_CONNECTIONS_FILENAME, contribution: "API connections",
39
+ parse: ({ raw }) => {
40
+ const parsed = parseApiConnectionDeclarations({ raw, clientNamespace: CLIENT_NAMESPACE });
41
+ if (parsed.ok)
42
+ return parsed;
43
+ // Shape only: a plugin may name settings under the prefix its manifest declares. Who may use which
44
+ // name is decided per plugin, by `checkApiConnectionClientNamespace` in the loader below.
45
+ const declared = declaredNamespace({ raw });
46
+ const alternate = declared === undefined ? parsed : parseApiConnectionDeclarations({ raw, clientNamespace: declared });
47
+ return alternate.ok ? alternate : parsed;
48
+ }, modulePath: ({ descriptor }) => descriptor.module,
49
+ validate: ({ exported }) => asApiConnectionHooksModule({ exported }),
50
+ refusal: ({ plugin, descriptor, reason }) => `API connection '${descriptor.id}' from '${plugin.pluginId}' was not loaded: ${reason}`,
51
+ };
52
+ const load = await required.loadContributions({ workspaceId: required.workspaceId, definition: connectionContribution,
53
+ onReadError: ({ error }) => (error?.code === "ENOENT" ? [] : undefined) }, { orderByPluginId: true });
54
+ const connections = [];
55
+ const refusals = [...load.refusals];
56
+ for (const item of load.items) {
57
+ try {
58
+ checkApiConnectionClientNamespace({ pluginId: item.pluginId, clients: item.descriptor.clients, clientNamespace: (await optional.clientNamespaceFor?.({ pluginId: item.pluginId })) ?? CLIENT_NAMESPACE });
59
+ const descriptor = parseApiConnectionDescriptor({ callbackFieldRules: required.callbackFieldRules, value: { ...item.descriptor.descriptor, pluginId: item.pluginId, connectionId: item.descriptor.id } });
60
+ const { clients, budgets, scopeSets, apiOrigins, byoClient } = item.descriptor;
61
+ connections.push({ pluginId: item.pluginId, descriptor, clients, budgets, scopeSets, apiOrigins, byoClient, module: item.module });
62
+ }
63
+ catch (error) {
64
+ refusals.push(`API connection '${item.descriptor.id}' from '${item.pluginId}' was not loaded: ${error instanceof Error ? error.message : "invalid descriptor"}`);
65
+ }
66
+ }
67
+ return { connections, refusals };
68
+ }
69
+ //# sourceMappingURL=contribution.js.map
@@ -0,0 +1,68 @@
1
+ import type { FormDeliveryConnectionPort, FormDeliveryErrorCode, FormDestinationCredential } from "@jini-ai/core/contracts/site/cms-forms";
2
+ import type { ApiConnectionHost } from "./host.js";
3
+ /**
4
+ * @file The OAuth implementation of the form-delivery `FormDeliveryConnectionPort`: a push
5
+ * destination's binding stores only a `connectionRef`; each delivery attempt resolves a fresh access
6
+ * token here, immediately before its HTTP call. Jobs never hold tokens. The site composes it ahead of
7
+ * the saved-custom-credential port (in the host's form-delivery deliverer). The ref
8
+ * must belong to the plugin that contributes the binding's adapter, so one plugin's destination can
9
+ * never spend another plugin's connection.
10
+ *
11
+ * A job freezes the account it was set up with: an OAuth binding names it as `config.accountId`, and
12
+ * the binding is frozen into every job at planning. After a confirmed account switch the same ref
13
+ * holds another account, and a frozen job is refused (`authorization-required`) instead of silently
14
+ * delivering there. A binding with no account is refused (`configuration-invalid`), so a job can
15
+ * never "follow" whatever account the ref holds today. `getAccessToken` reads a token per provider
16
+ * request so the connection's request budgets count every request, not one per delivery.
17
+ *
18
+ * Only a delivery code leaves this port on a refusal: the ledger keeps the bare code, so a refusal
19
+ * the person must act on (reconnect, sign in again, switch back) is `authorization-required` and
20
+ * not retried, and a refused budget charge is `rate-limited` with the host's wait.
21
+ */
22
+ /**
23
+ * A delivery credential plus the extra origins the push kit may reach with it (origins, like custom
24
+ * credentials). `token` is this attempt's read (the contract's field); `getAccessToken` is one read
25
+ * per provider request, on the same frozen account (its first call returns `token`).
26
+ */
27
+ export type OAuthFormDeliveryCredential = FormDestinationCredential & {
28
+ readonly additionalHosts: readonly string[];
29
+ readonly getAccessToken: () => Promise<string>;
30
+ };
31
+ /** The forms port, answering with the OAuth credential shape. */
32
+ export type OAuthFormDeliveryConnectionPort = (required: Parameters<FormDeliveryConnectionPort>[0], optional?: Parameters<FormDeliveryConnectionPort>[1]) => Promise<OAuthFormDeliveryCredential | null>;
33
+ /**
34
+ * The host's forms delivery error (`FormDeliveryError` from the forms ledger), built from a bare
35
+ * delivery code. Injected: the ledger owns the class this port's refusals must be instances of.
36
+ */
37
+ export type OAuthFormDeliveryErrorFactory = (required: {
38
+ readonly code: FormDeliveryErrorCode;
39
+ readonly retryable: boolean;
40
+ readonly retryAfterMs?: number;
41
+ readonly outcome: "not-applied";
42
+ }) => Error;
43
+ /** The two host reads this port makes: the declared connection for a ref, and a scoped token reader. */
44
+ export type OAuthFormDeliveryHost = Pick<ApiConnectionHost, "declaredFor" | "accessTokensFor">;
45
+ /**
46
+ * @param required.hostFor - The workspace's API-connection host, or null when it has none.
47
+ * @param required.adapterPluginId - Which plugin contributes a form-destination adapter id; null when none.
48
+ * @param required.deliveryError - Builds the host's forms delivery error for a refusal code.
49
+ * @returns null for a ref this port does not own (so a composite port can try static credentials);
50
+ * otherwise the access token as the credential, with the connection's declared `apiOrigins` as
51
+ * `baseUrl` (the first) and `additionalHosts` (the rest).
52
+ * @throws FormDeliveryError `configuration-invalid` for an owned ref whose binding names no account;
53
+ * `authorization-required` when the first read needs a person (see `NEEDS_A_PERSON`); `rate-limited`
54
+ * when the connection's budget refuses it. Later per-request reads throw the host's own errors,
55
+ * which the plugin maps itself.
56
+ * @complexity One contribution load plus one token read; each later request is one token read.
57
+ */
58
+ export declare function createOAuthFormDeliveryConnectionPort(required: {
59
+ readonly hostFor: (input: {
60
+ readonly workspaceId: string;
61
+ }) => OAuthFormDeliveryHost | null;
62
+ readonly adapterPluginId: (input: {
63
+ readonly workspaceId: string;
64
+ readonly adapterId: string;
65
+ }) => Promise<string | null>;
66
+ readonly deliveryError: OAuthFormDeliveryErrorFactory;
67
+ }, _optional?: Record<string, never>): OAuthFormDeliveryConnectionPort;
68
+ //# sourceMappingURL=form-delivery-connection.d.ts.map
@@ -0,0 +1,73 @@
1
+ import { ConnectionBudgetExceededError } from "./budgets.js";
2
+ import { ApiConnectionError } from "./errors.js";
3
+ /** API-connection refusals no retry can fix: a person reconnects, signs in or switches back first. */
4
+ const NEEDS_A_PERSON = new Set(["connection-not-found", "not-connected", "reconnect-required", "revocation-pending", "account-changed"]);
5
+ /**
6
+ * The delivery code a token-read failure is recorded as; any other failure is returned unchanged
7
+ * (the forms ledger turns it into a retryable `delivery-failed`, without its text).
8
+ * @complexity O(1).
9
+ */
10
+ function asDeliveryError({ error, deliveryError }, _optional = {}) {
11
+ if (error instanceof ConnectionBudgetExceededError)
12
+ return deliveryError({ code: "rate-limited", retryable: true, retryAfterMs: error.retryAfterMs, outcome: "not-applied" });
13
+ if (error instanceof ApiConnectionError && NEEDS_A_PERSON.has(error.code))
14
+ return deliveryError({ code: "authorization-required", retryable: false, outcome: "not-applied" });
15
+ return error;
16
+ }
17
+ /**
18
+ * The account the job's frozen binding was set up with.
19
+ * @throws FormDeliveryError `configuration-invalid` when the binding names none (fail closed).
20
+ * @complexity O(1).
21
+ */
22
+ function frozenAccountOf({ binding, deliveryError }, _optional = {}) {
23
+ const accountId = binding?.config.accountId;
24
+ if (typeof accountId !== "string" || accountId === "")
25
+ throw deliveryError({ code: "configuration-invalid", retryable: false, outcome: "not-applied" });
26
+ return accountId;
27
+ }
28
+ /** Hands out the attempt's first token once, then a fresh read per call. @complexity O(1) per call. */
29
+ function perRequestTokens({ first, read }, _optional = {}) {
30
+ let unused = first;
31
+ return async () => {
32
+ const token = unused;
33
+ unused = undefined;
34
+ return token ?? read();
35
+ };
36
+ }
37
+ /**
38
+ * @param required.hostFor - The workspace's API-connection host, or null when it has none.
39
+ * @param required.adapterPluginId - Which plugin contributes a form-destination adapter id; null when none.
40
+ * @param required.deliveryError - Builds the host's forms delivery error for a refusal code.
41
+ * @returns null for a ref this port does not own (so a composite port can try static credentials);
42
+ * otherwise the access token as the credential, with the connection's declared `apiOrigins` as
43
+ * `baseUrl` (the first) and `additionalHosts` (the rest).
44
+ * @throws FormDeliveryError `configuration-invalid` for an owned ref whose binding names no account;
45
+ * `authorization-required` when the first read needs a person (see `NEEDS_A_PERSON`); `rate-limited`
46
+ * when the connection's budget refuses it. Later per-request reads throw the host's own errors,
47
+ * which the plugin maps itself.
48
+ * @complexity One contribution load plus one token read; each later request is one token read.
49
+ */
50
+ export function createOAuthFormDeliveryConnectionPort(required, _optional = {}) {
51
+ /** The host and owning plugin when this port owns the ref (the adapter's plugin declares it here). */
52
+ async function owner({ workspaceId, connectionRef, adapterId }, _optional = {}) {
53
+ const host = required.hostFor({ workspaceId });
54
+ const pluginId = host ? await required.adapterPluginId({ workspaceId, adapterId }) : null;
55
+ const declared = host && pluginId ? await host.declaredFor({ pluginId, connectionRef }) : undefined;
56
+ return host && pluginId && declared ? { host, pluginId, declared } : null;
57
+ }
58
+ return async ({ workspaceId, connectionRef, adapterId }, optional = {}) => {
59
+ const owned = await owner({ workspaceId, connectionRef, adapterId });
60
+ if (!owned)
61
+ return null;
62
+ const { host, pluginId, declared } = owned;
63
+ const frozen = { expectedAccountId: frozenAccountOf({ binding: optional.binding, deliveryError: required.deliveryError }) };
64
+ const read = () => host.accessTokensFor({ pluginId }).getAccessToken({ connectionRef }, frozen);
65
+ const token = await read().catch((error) => Promise.reject(asDeliveryError({ error, deliveryError: required.deliveryError })));
66
+ // The push kit allows the base URL's origin plus each `additionalHosts` entry compared as an
67
+ // exact origin; an OAuth destination reaches only the https origins its plugin declared on the
68
+ // connection (none declared: nothing allowed).
69
+ const [baseUrl = "", ...additionalHosts] = declared.apiOrigins;
70
+ return { token, baseUrl, additionalHosts, getAccessToken: perRequestTokens({ first: token, read }) };
71
+ };
72
+ }
73
+ //# sourceMappingURL=form-delivery-connection.js.map
@@ -1,174 +1,7 @@
1
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
2
  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
- }
3
+ import type { OAuthDiscoveryPolicy, OAuthFlowOperations, OAuthMessages, OAuthUrlGuard } from '@jini-ai/core/contracts/oauth';
4
+ import type { ExternalMcpAuthMode, ExternalMcpOAuthStatus, ExternalMcpSealedOAuthPayload, ExternalMcpServerRecord, SealedExternalMcpOAuth } from '@jini-ai/core/contracts/hosted-mcp';
172
5
  /** @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
6
  export interface HostedMcpOAuthFailure extends Error {
174
7
  readonly code: string;
@@ -210,7 +43,7 @@ export interface HostedMcpSignInCopy {
210
43
  * `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
44
  * `errors.reauthRequired` is the host's ONE canonical re-authorization factory, the same function the connection gate receives.
212
45
  * `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).
46
+ * `aad.format` produces the configuration-bound `oauth-redirect-state` v2 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
47
  */
215
48
  export interface HostedMcpSignInPorts {
216
49
  readonly flow: OAuthFlowOperations;
@@ -251,7 +84,7 @@ export interface HostedMcpSignInPorts {
251
84
  readonly authMode: (record: Pick<ExternalMcpServerRecord, 'authMode'>) => ExternalMcpAuthMode;
252
85
  readonly oauthStatus: (record: Pick<ExternalMcpServerRecord, 'oauthStatus'>) => ExternalMcpOAuthStatus;
253
86
  };
254
- /** @agent-note Persisted AAD format; must stay byte-identical for already-issued state. */
87
+ /** @agent-note Redirect-state AAD format; v2 binds the saved creation time and version. */
255
88
  readonly aad: {
256
89
  readonly format: (input: {
257
90
  readonly kind: string;
@@ -1,5 +1,7 @@
1
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
2
  export type * from './contracts.js';
3
+ /** Deprecated re-export: import these from `@jini-ai/core/contracts/site/api-connections-hosted-mcp`; removed at the next major. */
4
+ export type { DeviceAuthorizationStore, ExternalMcpOAuthDeps, ExternalMcpOAuthService } from "@jini-ai/core/contracts/site/api-connections-hosted-mcp";
3
5
  export { createHostedMcpSignInService, createDeviceAuthorizationStore } from './sign-in.js';
4
6
  export { createSharedExternalMcpOAuth, type SharedExternalMcpOwner, type SharedSignInOwner, type SharedSignInBindings, type SharedSignInAttachments, type SharedSignInTransaction, type SharedSignInIssuingContext, type SharedMcpConfiguration } from './shared-sign-in.js';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -31,7 +31,9 @@ export declare function writeOAuthRuntime({ repo, ports, record, patch }: {
31
31
  ports: Pick<HostedMcpSignInPorts, "errors">;
32
32
  record: ExternalMcpServerRecord;
33
33
  patch: ExternalMcpOAuthRuntimePatch;
34
- }, _options?: {}): Promise<void>;
34
+ }, options?: {
35
+ expectedConfig?: Pick<ExternalMcpServerRecord, "createdAt" | "version">;
36
+ }): Promise<void>;
35
37
  /**
36
38
  * Re-reads the row, lets `build` derive its next state, and writes it conditionally on the version
37
39
  * and credentials it read; once more from a fresh read if that missed, then a conflict (M4).
@@ -12,9 +12,9 @@ export function runtimePatchOf(row) {
12
12
  * its replacement) and the connection reports that it must be authorized again.
13
13
  * @complexity O(1): one conditional write.
14
14
  */
15
- export async function writeOAuthRuntime({ repo, ports, record, patch }, _options = {}) {
15
+ export async function writeOAuthRuntime({ repo, ports, record, patch }, options = {}) {
16
16
  const key = { workspaceId: record.workspaceId, serverId: record.serverId };
17
- if (await repo.updateOAuthRuntime({ key, expectedSealedOAuth: record.sealedOAuth, patch }))
17
+ if (await repo.updateOAuthRuntime({ key, expectedSealedOAuth: record.sealedOAuth, patch, ...options }))
18
18
  return;
19
19
  throw ports.errors.reauthRequired({
20
20
  serverId: record.serverId,
@@ -32,7 +32,10 @@ export async function writeOAuthRuntime({ repo, ports, record, patch }, _options
32
32
  * @complexity O(1) writes; at most two reads and two builds.
33
33
  */
34
34
  export async function updateRowOnce({ repo, key, build }, _options = {}) {
35
- return applyInternalChange({ recordKind: "MCP server", recordId: key.serverId, read: () => repo.findByServerId(key), build,
35
+ return applyInternalChange({ recordKind: "MCP server", recordId: key.serverId, read: () => repo.findByServerId(key), build: async (current) => {
36
+ const next = await build(current);
37
+ return next === null ? null : { ...next, version: current.version + 1 };
38
+ },
36
39
  write: ({ current, next }) => repo.updateIfVersion({ record: next, expectedVersion: current.version, replaces: { sealedEnv: current.sealedEnv, sealedOAuth: current.sealedOAuth } }) });
37
40
  }
38
41
  //# sourceMappingURL=oauth-row-writes.js.map
@@ -2,7 +2,8 @@ import { type ApiConnectionClientKind, type ApiConnectionDescriptor, type ApiCon
2
2
  import type { OAuthClient, OAuthProviderDescriptor } from '@jini-ai/core/contracts/oauth';
3
3
  import type { VaultRecord } from '@jini-ai/core/contracts/vault';
4
4
  import type { ExternalMcpConnectStart, ExternalMcpServerRecord } from '@jini-ai/core/contracts/hosted-mcp';
5
- import type { ExternalMcpOAuthDeps, ExternalMcpOAuthService, HostedMcpSignInPorts } from './contracts.js';
5
+ import type { HostedMcpSignInPorts } from './contracts.js';
6
+ import type { ExternalMcpOAuthDeps, ExternalMcpOAuthService } from '@jini-ai/core/contracts/site/api-connections-hosted-mcp';
6
7
  /** @agent-note Issuing configuration sealed in the owner store; a consuming site's client cannot replace it.
7
8
  * Storage MUST losslessly preserve the entire supplied context, including additional fields beyond this base interface.
8
9
  * In particular, shared MCP sign-in persists `mcp: { provider: OAuthProviderDescriptor, scopes: readonly string[], url: string | null, grant: string | null }`.
@@ -30,7 +30,7 @@ async function persistSelfConfiguration(deps, record, identity, options = {}) {
30
30
  if (options.configurationOnly)
31
31
  return build(record);
32
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);
33
+ return (await updateRowOnce({ repo: deps.repo, key: record, build })) ?? requireOAuthRecord({ deps, serverId: record.serverId });
34
34
  }
35
35
  /**
36
36
  * Fills in whatever a connection is missing, persists it, and returns the row as it now stands.