@polpo-ai/connect 0.15.144 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +207 -25
  2. package/dist/assignment-policy.d.ts +21 -0
  3. package/dist/assignment-policy.d.ts.map +1 -0
  4. package/dist/assignment-policy.js +93 -0
  5. package/dist/assignment-policy.js.map +1 -0
  6. package/dist/capability-resolver.d.ts +47 -3
  7. package/dist/capability-resolver.d.ts.map +1 -1
  8. package/dist/capability-resolver.js +197 -31
  9. package/dist/capability-resolver.js.map +1 -1
  10. package/dist/client/index.d.ts +97 -20
  11. package/dist/client/index.d.ts.map +1 -1
  12. package/dist/client/index.js +90 -4
  13. package/dist/client/index.js.map +1 -1
  14. package/dist/credential-requirement.d.ts +7 -0
  15. package/dist/credential-requirement.d.ts.map +1 -0
  16. package/dist/credential-requirement.js +7 -0
  17. package/dist/credential-requirement.js.map +1 -0
  18. package/dist/definition-store.d.ts +19 -0
  19. package/dist/definition-store.d.ts.map +1 -0
  20. package/dist/definition-store.js +2 -0
  21. package/dist/definition-store.js.map +1 -0
  22. package/dist/definitions.d.ts +54 -0
  23. package/dist/definitions.d.ts.map +1 -0
  24. package/dist/definitions.js +394 -0
  25. package/dist/definitions.js.map +1 -0
  26. package/dist/errors.d.ts +1 -1
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +3 -0
  29. package/dist/errors.js.map +1 -1
  30. package/dist/http-policy.d.ts +3 -1
  31. package/dist/http-policy.d.ts.map +1 -1
  32. package/dist/http-policy.js +55 -14
  33. package/dist/http-policy.js.map +1 -1
  34. package/dist/index.d.ts +8 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +8 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/mcp-oauth-commit.d.ts +11 -0
  39. package/dist/mcp-oauth-commit.d.ts.map +1 -0
  40. package/dist/mcp-oauth-commit.js +65 -0
  41. package/dist/mcp-oauth-commit.js.map +1 -0
  42. package/dist/oauth-reconnect.d.ts +5 -0
  43. package/dist/oauth-reconnect.d.ts.map +1 -0
  44. package/dist/oauth-reconnect.js +18 -0
  45. package/dist/oauth-reconnect.js.map +1 -0
  46. package/dist/registry.d.ts +6 -3
  47. package/dist/registry.d.ts.map +1 -1
  48. package/dist/registry.js +47 -9
  49. package/dist/registry.js.map +1 -1
  50. package/dist/setup-lifecycle.d.ts +9 -0
  51. package/dist/setup-lifecycle.d.ts.map +1 -0
  52. package/dist/setup-lifecycle.js +57 -0
  53. package/dist/setup-lifecycle.js.map +1 -0
  54. package/dist/types.d.ts +204 -5
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/verification.d.ts +55 -0
  57. package/dist/verification.d.ts.map +1 -0
  58. package/dist/verification.js +50 -0
  59. package/dist/verification.js.map +1 -0
  60. package/package.json +2 -2
package/README.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  Shared contracts and client SDK for Polpo Connect.
4
4
 
5
+ Custom tool slots support both `gateway` and `legacy_credentials` (the omitted
6
+ mode's compatibility meaning). Gateway code calls `require(slot).request()`;
7
+ approved direct code uses `getToken()`, `getKey()` or `getHeaders()`, for example
8
+ with Git or HMAC libraries. Host policies receive `connectionSlot: { name, mode }`
9
+ on authorization and rechecks and can require separate credential-export consent.
10
+ Declaring a mode never grants access or enables fallback after a denial. Direct
11
+ credentials retain their provider permissions; revocation stops future delivery
12
+ but cannot recall an already copied credential. Keep secrets out of tool results.
13
+
5
14
  Polpo Connect models external service connections as scoped, revocable capabilities that can be assigned to agents without exposing raw access tokens to the model.
6
15
 
7
16
  This package contains:
@@ -14,33 +23,206 @@ This package contains:
14
23
 
15
24
  Server-side OAuth/token lifecycle lives in `@polpo-ai/connect-server`.
16
25
 
17
- ## Application capabilities
26
+ ## Domain model
27
+
28
+ - A version 2 `ConnectorDefinition` declares `http_api` or `mcp`, supported
29
+ authentication methods, scopes, operations and policy. It contains no client
30
+ secret, API key or account token.
31
+ - A Connection selects one `authenticationId` and represents an authorized
32
+ account. Its owner, audience, scopes, binding and grants remain distinct.
33
+ - An OAuth Client is the registered application used to obtain authorization.
34
+ Operator/customer/managed ownership does not determine whether an account is
35
+ shared or belongs to an end user.
36
+
37
+ `normalizeConnectorDefinition` validates and copies authored definitions.
38
+ `createConnectorRegistry` accepts both old providers and version 2 definitions.
39
+ `catalog()` describes protocol and supported authentication separately. Legacy
40
+ generic API keys with no destination policy are classified as credentials.
41
+ `list()` remains a compatibility projection of each Connector's default method.
42
+
43
+ ## Creating static and MCP Connections
44
+
45
+ `createApiKeyConnection`, `createPublicConnection`, `createMcpConnection` and
46
+ `startMcpOAuth` accept trusted `audience`, `subject` and `binding`. Omitting
47
+ `audience` retains the shared default; a human owner does not implicitly make an
48
+ account personal. Set `personal` with a `user` owner or `end_user` with an
49
+ `external_user` owner containing both `namespace` and `id`. The service derives
50
+ the principal binding and rejects conflicting or malformed constraints before
51
+ storing credentials or starting consent. Shared accounts can still have narrower
52
+ tenant/resource bindings.
53
+
54
+ For Cloud, use `createProjectApiKeyConnection`, `createProjectPublicConnection`,
55
+ `createProjectMcpConnection` and `startProjectMcpOAuth`. For a self-hosted server,
56
+ the unsuffixed methods target `/v1/connect`; MCP OAuth requires an explicit
57
+ registered `redirectUri`. `inspectMcpOAuth` inspects a self-hosted endpoint's
58
+ OAuth configuration. All creation methods are authenticated control-plane calls,
59
+ not tools exposed to the model or unauthenticated application users.
60
+
61
+ Choose a custom MCP's `providerId` and `authenticationId` explicitly. Its selected
62
+ method determines credential injection, including the header name. Generic MCP
63
+ supports public, bearer or a validated `headerName` with `auth: "header"`.
64
+ Discovery inventory is recorded by the host: caller-supplied `discoveredTools`
65
+ and `lastDiscoveredAt` metadata cannot install callable tools.
66
+
67
+ CLI: `polpo connections create <public|api-key|mcp> ./connection.json` sends the
68
+ same request to the linked project. Store credential-bearing input in a private
69
+ file outside source control; the command prints only the non-secret result.
70
+ `polpo connections mcp connect` opens the dashboard for review and consent. It
71
+ accepts a catalog ID or clean HTTPS endpoint, with optional `--name`,
72
+ `--transport` and `--dashboard-url`. It rejects advanced authentication, owner,
73
+ audience, binding and scope flags because the handoff link cannot carry those
74
+ contracts. Use the session-authenticated MCP OAuth API or a trusted setup session
75
+ when that context is required.
76
+
77
+ ## Agent capabilities
78
+
79
+ HTTP action handlers receive an authorized `ConnectorActionGateway`. They pass
80
+ an operation and required scopes; the host binds the Connection, trusted user,
81
+ tenant and grants and injects credentials outside the model and tool arguments.
82
+ MCP uses its native transport and discovery. The presence of legacy token and
83
+ application-capability helpers is not an invitation to make Polpo a general
84
+ backend integration broker; the current product scope is agent capabilities.
85
+
86
+ The host can set the trusted selector's `audience` to select a shared, personal
87
+ or end-user account explicitly. Shared capabilities retain the caller's identity
88
+ for audit. They are not a fallback for a missing end-user match. Legacy records
89
+ without audience remain shared while retaining their binding restrictions.
90
+
91
+ For a distributed sandbox relay, `getConnectionCapabilitySelection(capability)`
92
+ returns a host-only selection snapshot from the acquired gateway capability.
93
+ Persist it in trusted server state and pass it as `selection` when constructing
94
+ the resolver for subsequent relay requests. Resume loads only that installation
95
+ and rechecks its identity, binding, audience, credential generation and live
96
+ permissions. The snapshot is kept in a WeakMap rather than capability properties;
97
+ never copy it into a tool's arguments, metadata or sandbox payload. A relay claim
98
+ without a selection must be reacquired, not resolved to a replacement account.
99
+
100
+ ## OAuth setup without a required hosted page
101
+
102
+ Create a setup session from a trusted backend, deriving `subject` and `binding`
103
+ from the application's authenticated user. Never copy an unverified browser
104
+ user ID into this context or put a Polpo API key in browser code.
105
+
106
+ For the generic OSS API, use `createSetupSession` then `startOAuthSetup(id)`.
107
+ For Cloud, use `createProjectSetupSession(projectId, input)` and
108
+ `startProjectOAuthSetup(token)`. These helpers intentionally target different
109
+ host routes. Cloud may also return a convenience `setupUrl`; opening that page
110
+ is optional. Both paths lead to the same provider-hosted consent.
111
+
112
+ Cloud control-plane methods use a platform API key supplied through the client's
113
+ `headers: { Authorization: "Bearer ..." }`; the constructor has no `apiKey` or
114
+ `projectId` option. Keep this key on the trusted backend.
115
+ `getSetupStatus`, `cancelSetupSession`, and `waitForSetupCompletion` work with
116
+ both hosts. The OSS router exposes `GET /connect/setup/:id/status` and
117
+ `POST /connect/setup/:id/cancel` under its existing authenticated API; Cloud
118
+ exposes the hosted bearer-link routes. Configure the client's base URL for its
119
+ host. A browser redirect alone never proves completion.
18
120
 
19
- Application backends should invoke a logical capability, not select or receive a
20
- physical Connection ID. Configure the mapping in the trusted control plane,
21
- then call it with a project API key:
121
+ Setup-link expiry limits when authorization can start. Once started, status uses
122
+ the OAuth authorization deadline. Cancellation is allowed only before start;
123
+ completed, cancelled and failed outcomes remain terminal after expiry.
124
+
125
+ Managed clients show the provider's registered Polpo app identity. Customer
126
+ clients show the customer's registered identity. In both cases the host handles
127
+ the provider callback, exchanges the code, and retains tokens server-side.
128
+ The approved application `returnUrl` is separate from that callback. Confirm
129
+ completion through setup status, not a success parameter supplied by a browser.
130
+
131
+ Cloud project administrators can configure application destinations independently
132
+ of OAuth app ownership using `configureProjectSetup(projectId, { returnOrigins:
133
+ ["https://app.example.com"] })` and inspect them with
134
+ `getProjectSetupConfiguration(projectId)`. Origins must use HTTPS and cannot include
135
+ paths or wildcards. The CLI equivalents are `polpo connections setup-config show`
136
+ and `polpo connections setup-config set --origin https://app.example.com` (or
137
+ `--clear`). This configures the application's completion destination, not the
138
+ provider's callback. Removing the last approval for an origin invalidates pending
139
+ flows using it; an OAuth client's or host's separate origin approvals still apply.
140
+
141
+ After setup, a trusted backend can list and revoke an external user's accounts:
22
142
 
23
143
  ```ts
24
- import { PolpoConnectClient } from "@polpo-ai/connect/client";
25
-
26
- const connect = new PolpoConnectClient({
27
- baseUrl: "https://api.polpo.sh",
28
- headers: { authorization: `Bearer ${process.env.POLPO_API_KEY}` },
29
- });
30
-
31
- const response = await connect.requestApplicationCapability(
32
- process.env.POLPO_PROJECT_ID!,
33
- "github.repositories",
34
- {
35
- invocation: {
36
- user: "customer-42",
37
- metadata: { tenantId: "tenant-7" },
38
- scope: { key: "workspace-9", version: "3" },
39
- },
40
- request: { method: "GET", path: "/user/repos" },
41
- },
42
- );
144
+ const owner = { namespace: "my-app", id: authenticatedUser.id };
145
+ const accounts = await connect.listProjectEndUserConnections(projectId, owner);
146
+ await connect.revokeProjectEndUserConnection(projectId, owner, connectionId);
43
147
  ```
44
148
 
45
- Unsafe methods require an idempotency key. Runtime request bodies never accept
46
- a physical Connection ID or provider credential.
149
+ Revocation targets one Connection within that exact project, namespace and user.
150
+ The CLI equivalents are `polpo connections end-users list <user-id> --namespace
151
+ my-app` and `polpo connections end-users revoke <user-id> <connection-id>
152
+ --namespace my-app`. These are authenticated management operations, not public
153
+ browser endpoints.
154
+
155
+ Agent runtime selection uses that same namespaced identity. Supply the trusted
156
+ principal as `{ type: "external_user", namespace: "my-app", id: userId }`; an ID
157
+ without its application namespace cannot authorize an end-user account. In Cloud
158
+ completion context, the trusted backend supplies `user` and
159
+ `metadata.connectionNamespace`, or the full principal in
160
+ `metadata.connectionScope.principal`. Never derive the namespace from the model,
161
+ provider, email address or an unverified browser parameter. Existing namespaced
162
+ owners remain usable even if their older stored binding omits the namespace;
163
+ records without a valid external-user owner require explicit correction or setup.
164
+
165
+ For a Connector with multiple authentication methods, pass `authenticationId`
166
+ when configuring a project or organization OAuth client. Pass the same method
167
+ as the optional third argument to `revokeProjectOAuthClient` or
168
+ `revokeOrganizationOAuthClient`. CLI `connections oauth-clients set` and `revoke`
169
+ accept `--authentication <id>`. Omitting it preserves the default method.
170
+
171
+ ## Custom definitions and verification
172
+
173
+ `registerConnectorDefinition` registers a validated custom definition on a host
174
+ with a `ConnectorDefinitionStore`. IDs are immutable: changing endpoint policy
175
+ requires a new definition and explicit setup, so existing secrets cannot be
176
+ silently redirected. `disableConnectorDefinition` blocks subsequent use.
177
+ The store must be scoped to the authorized tenant by the host.
178
+
179
+ For Cloud, use `listProjectCatalog(projectId)`,
180
+ `registerProjectConnectorDefinition(projectId, definition)`, and
181
+ `disableProjectConnectorDefinition(projectId, connectorId)`. The CLI exposes
182
+ `connections connectors register <file>` and `connections connectors disable <id>`.
183
+
184
+ `getSetupReadiness(input)` checks local prerequisites for the selected
185
+ authentication and OAuth Client mode. It reports configuration readiness only:
186
+ `consent_required` does not claim a working authorization, and
187
+ `credentials_required` does not validate a key. Use `verifyConnection` after
188
+ setup for a live check. The managed/own label describes app ownership, not
189
+ availability or connection health.
190
+
191
+ The Cloud variant is `getProjectSetupReadiness(projectId, { providerId,
192
+ authenticationId, oauthClientMode })`. Its CLI equivalent is `connections
193
+ setup-readiness <provider-id> --authentication <id> --oauth-client-mode managed`.
194
+ This checks setup prerequisites; `connections readiness` instead checks a
195
+ specific runtime slot's trusted selection and grants.
196
+
197
+ `verifyConnection(id)` returns `passed`, `failed`, `inconclusive`, or
198
+ `unsupported`, with check type, timestamp and configuration/credential versions.
199
+ A successful public operation does not verify a credential. MCP discovery does
200
+ not prove that every discovered tool works. Verification is independent of the
201
+ Connection lifecycle and must not silently revoke it. Project hosts use
202
+ `verifyProjectConnection(projectId, id)` and must implement the matching route.
203
+ ## Account assignment preflight
204
+
205
+ Hosts can validate account assignments for a logical capability with
206
+ `validateConnectionAssignments([{ connection, binding }])`. The optional binding
207
+ adds grant constraints to the Connection's own binding. The result is `{ ok:
208
+ true }` or a non-secret conflict with `reason` and `connectionIds`.
209
+
210
+ Different accounts need disjoint trusted contexts. Personal ownership constrains
211
+ the principal; missing fields do not disambiguate accounts. The host must select
212
+ the audience explicitly and must still enforce visibility, active status,
213
+ scopes, grants, and concurrent-write protection. This configuration check does
214
+ not replace the runtime resolver's exact-one-account authorization.
215
+
216
+
217
+ MCP reusable client configuration is described by `ResolvedMcpOAuthClient` and
218
+ `McpOAuthClientResolver`. These host-only contracts distinguish configuration
219
+ ownership from the protocol's three registration methods. They do not expose
220
+ provider secrets to the setup SDK. An OSS host with `mcpOAuthClients`, setup/link
221
+ stores and atomic embedded persistence supports MCP through `createSetupSession`:
222
+ pass `configurationId` to select the approved reusable configuration. The same
223
+ selector is available on `CreateConnectionSetupSessionRequest`, the OSS HTTP
224
+ setup endpoint, and `polpo connections setup-session --configuration <id>`.
225
+ The request assigns a trusted owner and audience; the browser receives a setup
226
+ token, not the client secret. Callback completion creates that owner's account,
227
+ its project link and both receipts atomically. Managed hosts must implement and
228
+ deploy the same server capability before accepting MCP on their setup route.
@@ -0,0 +1,21 @@
1
+ import type { ConnectionBindingAttributes, ConnectionRecord } from "./types.js";
2
+ /** A prospective assignment for one capability. Hosts supply only active,
3
+ * visible accounts and must also check scopes, grants and execution surfaces. */
4
+ export interface ConnectionAssignment {
5
+ connection: Pick<ConnectionRecord, "id" | "providerId" | "audience" | "owner" | "binding">;
6
+ /** Additional grant constraints. They never replace account constraints. */
7
+ binding?: ConnectionBindingAttributes;
8
+ }
9
+ export type ConnectionAssignmentValidation = {
10
+ ok: true;
11
+ } | {
12
+ ok: false;
13
+ reason: "invalid_context" | "provider_mismatch" | "overlapping_context";
14
+ connectionIds: string[];
15
+ };
16
+ /** Configuration preflight, not runtime authorization or a write lock. Distinct
17
+ * accounts may coexist only when no explicit trusted selector can match both.
18
+ * Hosts that cannot select an audience explicitly must additionally restrict
19
+ * assignments to one audience. Runtime must still reject ambiguous selection. */
20
+ export declare function validateConnectionAssignments(assignments: readonly ConnectionAssignment[]): ConnectionAssignmentValidation;
21
+ //# sourceMappingURL=assignment-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignment-policy.d.ts","sourceRoot":"","sources":["../src/assignment-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEhF;iFACiF;AACjF,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAC3F,4EAA4E;IAC5E,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC;AAED,MAAM,MAAM,8BAA8B,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAC1D,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,iBAAiB,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;IACxE,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;;iFAGiF;AACjF,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,GAAG,8BAA8B,CAiB1H"}
@@ -0,0 +1,93 @@
1
+ /** Configuration preflight, not runtime authorization or a write lock. Distinct
2
+ * accounts may coexist only when no explicit trusted selector can match both.
3
+ * Hosts that cannot select an audience explicitly must additionally restrict
4
+ * assignments to one audience. Runtime must still reject ambiguous selection. */
5
+ export function validateConnectionAssignments(assignments) {
6
+ const contexts = [];
7
+ for (const assignment of assignments) {
8
+ const fields = contextConstraints(assignment);
9
+ if (!fields)
10
+ return { ok: false, reason: "invalid_context", connectionIds: [assignment.connection.id] };
11
+ for (const previous of contexts) {
12
+ const ids = [previous.assignment.connection.id, assignment.connection.id];
13
+ if (previous.assignment.connection.providerId !== assignment.connection.providerId) {
14
+ return { ok: false, reason: "provider_mismatch", connectionIds: ids };
15
+ }
16
+ if (ids[0] === ids[1])
17
+ continue; // Several grants may authorize the same account.
18
+ const disjoint = [...fields].some(([key, value]) => previous.fields.has(key) && previous.fields.get(key) !== value);
19
+ if (!disjoint)
20
+ return { ok: false, reason: "overlapping_context", connectionIds: ids };
21
+ }
22
+ contexts.push({ assignment, fields });
23
+ }
24
+ return { ok: true };
25
+ }
26
+ const bindingParts = {
27
+ principal: ["type", "id", "namespace"],
28
+ tenant: ["namespace", "id"],
29
+ resource: ["namespace", "type", "id"],
30
+ };
31
+ function contextConstraints({ connection, binding }) {
32
+ const fields = new Map();
33
+ const audience = connection.audience ?? "shared";
34
+ if (!["personal", "shared", "end_user"].includes(audience))
35
+ return;
36
+ fields.set("audience", audience);
37
+ const add = (key, value) => {
38
+ // Selector normalization trims values; whitespace-bearing persisted values
39
+ // cannot reliably identify a reachable account.
40
+ if (typeof value !== "string" || !value || value.trim() !== value)
41
+ return false;
42
+ if (fields.has(key) && fields.get(key) !== value)
43
+ return false;
44
+ fields.set(key, value);
45
+ return true;
46
+ };
47
+ const merge = (value, requireConstraint) => {
48
+ if (value === undefined)
49
+ return true;
50
+ if (!plainObject(value) || (requireConstraint && Object.keys(value).length === 0))
51
+ return false;
52
+ for (const [key, part] of Object.entries(value)) {
53
+ if (key === "scopeEpoch") {
54
+ if (!add(key, part))
55
+ return false;
56
+ }
57
+ else {
58
+ if (!Object.hasOwn(bindingParts, key))
59
+ return false;
60
+ const allowed = bindingParts[key];
61
+ if (!allowed || !plainObject(part) || Object.keys(part).length === 0)
62
+ return false;
63
+ for (const [field, text] of Object.entries(part)) {
64
+ if (!allowed.includes(field) || !add(`${key}.${field}`, text))
65
+ return false;
66
+ }
67
+ }
68
+ }
69
+ return true;
70
+ };
71
+ if (!merge(connection.binding, true) || !merge(binding, false))
72
+ return;
73
+ if (audience === "personal") {
74
+ if (connection.owner?.type !== "user" || !add("principal.type", "user") || !add("principal.id", connection.owner.id))
75
+ return;
76
+ }
77
+ if (audience === "end_user") {
78
+ // End-user identity must be carried by the Connection itself, not rescued
79
+ // by a grant. Partial legacy fields still constrain shared installations.
80
+ const principal = connection.binding?.principal;
81
+ const owner = connection.owner;
82
+ if (owner?.type !== "external_user" || principal?.type !== "external_user" || principal.id !== owner.id
83
+ || !add("principal.type", "external_user") || !add("principal.id", owner.id)
84
+ || !add("principal.namespace", owner.namespace))
85
+ return;
86
+ }
87
+ return fields;
88
+ }
89
+ function plainObject(value) {
90
+ return value !== null && typeof value === "object"
91
+ && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
92
+ }
93
+ //# sourceMappingURL=assignment-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assignment-policy.js","sourceRoot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AAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,IAAI,UAAU,CAAC,KAAK,EAAE,IAAI,KAAK,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,OAAO;IAC/H,CAAC;IACD,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,0EAA0E;QAC1E,0EAA0E;QAC1E,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC;QAChD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAC/B,IAAI,KAAK,EAAE,IAAI,KAAK,eAAe,IAAI,SAAS,EAAE,IAAI,KAAK,eAAe,IAAI,SAAS,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE;eAClG,CAAC,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;eACzE,CAAC,GAAG,CAAC,qBAAqB,EAAE,KAAK,CAAC,SAAS,CAAC;YAAE,OAAO;IAC5D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;WAC7C,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AACpG,CAAC"}
@@ -1,16 +1,60 @@
1
- import { type ConnectionCapabilityResolver, type ConnectionCapabilityResolveInput, type ConnectionRequest, type ConnectionResponse, type ApplicationCapabilityResolveInput, type ApplicationCapabilityResolver } from "@polpo-ai/core";
2
- import type { ConnectionRecord, ConnectionSelectionSelector, ConnectPolicy, ConnectStore, ResolvedConnectionCredential } from "./types.js";
1
+ import { type AgentSnapshot, type ConnectionCapabilityResolver, type ConnectionCapabilityResolveInput, type ConnectionRequest, type ConnectionResponse, type ResolvedConnectionCapability, type ApplicationCapabilityResolveInput, type ApplicationCapabilityResolver } from "@polpo-ai/core";
2
+ import type { ConnectionBindingAttributes, ConnectionRecord, ConnectionSelectionSelector, ConnectPolicy, ConnectStore, ResolvedConnectionCredential } from "./types.js";
3
3
  export interface ConnectionCapabilityResolverOptions {
4
4
  store: ConnectStore;
5
+ /** Agent-scoped hosts must provide this live lookup. The expected identity
6
+ * comes only from the invocation captured with the execution config. */
7
+ getAgentSnapshot?(name: string): Promise<AgentSnapshot | undefined>;
8
+ /** Trusted host state for resuming an acquired capability. Never take this from tool arguments. */
9
+ selection?: ConnectionCapabilitySelection;
5
10
  resolveSelector(input: ConnectionCapabilityResolveInput): ConnectionSelectionSelector | Promise<ConnectionSelectionSelector>;
6
11
  materialize?(connection: ConnectionRecord, input: ConnectionCapabilityResolveInput): ResolvedConnectionCredential | Promise<ResolvedConnectionCredential>;
7
- request?<T = unknown>(connection: ConnectionRecord, input: ConnectionCapabilityResolveInput, request: ConnectionRequest): Promise<ConnectionResponse<T>>;
12
+ request?<T = unknown>(connection: ConnectionRecord, input: ConnectionCapabilityResolveInput, request: ConnectionRequest,
13
+ /** Call after refresh/DNS waits and before each credential-bearing dispatch. */
14
+ reauthorize: () => Promise<void>): Promise<ConnectionResponse<T>>;
8
15
  isConnectionVisible?(connection: ConnectionRecord, selector: ConnectionSelectionSelector): boolean | Promise<boolean>;
9
16
  policy?: ConnectPolicy;
10
17
  }
18
+ /** Stored only by the host. It is deliberately absent from tool-visible capability properties. */
19
+ export interface ConnectionCapabilitySelection {
20
+ readonly connectionId: string;
21
+ readonly providerId: string;
22
+ readonly audience: "personal" | "shared" | "end_user";
23
+ readonly secretRef?: string;
24
+ readonly credentialVersion?: string;
25
+ readonly bindingKey: string;
26
+ }
27
+ /** Host-only delivery guard. Rechecks the acquired account, grant, identity
28
+ * and credential installation without switching selection or rematerializing
29
+ * secrets. Never serialize this guard into a tool or sandbox capability. */
30
+ export declare function assertConnectionCapabilityAuthorized(capability: ResolvedConnectionCapability): Promise<void>;
31
+ export declare function getConnectionCapabilitySelection(capability: ResolvedConnectionCapability): ConnectionCapabilitySelection | undefined;
32
+ /** Host-only snapshot for durable delegation. Never expose this to tools or
33
+ * copy it into a sandbox: it includes credential installation references. */
34
+ export declare function snapshotConnectionCapabilitySelection(connection: ConnectionRecord): ConnectionCapabilitySelection;
35
+ export declare function matchesConnectionCapabilitySelection(connection: ConnectionRecord, expected: ConnectionCapabilitySelection): boolean;
11
36
  export interface ApplicationCapabilityResolverOptions extends Omit<ConnectionCapabilityResolverOptions, "resolveSelector"> {
12
37
  resolveSelector(input: ApplicationCapabilityResolveInput): ConnectionSelectionSelector | Promise<ConnectionSelectionSelector>;
13
38
  }
39
+ /** Legacy installations are shared; ownership is never inferred from binding fields. */
40
+ export declare function effectiveConnectionAudience(connection: ConnectionRecord): import("./types.js").ConnectionAudience;
41
+ /** Grant bindings are additional constraints, not standalone account identities. */
42
+ export declare function matchesConnectionBindingAttributes(binding: ConnectionBindingAttributes | undefined, selector: ConnectionSelectionSelector): boolean;
43
+ /** Match account ownership and binding against a host-created selector. No fallback is performed. */
44
+ export declare function matchesConnectionBinding(connection: ConnectionRecord, selector: ConnectionSelectionSelector): boolean;
45
+ /** Host-only authorization shared by HTTP and MCP. No credentials or protocol
46
+ * operations are exposed here; consumers must call current() before transport use. */
47
+ export interface SelectedConnectionAccess {
48
+ readonly input: ConnectionCapabilityResolveInput;
49
+ readonly connection: ConnectionRecord;
50
+ readonly selection: ConnectionCapabilitySelection;
51
+ current(): Promise<ConnectionRecord>;
52
+ dispose(): void;
53
+ }
54
+ export type ConnectionAccessResolverOptions = Pick<ConnectionCapabilityResolverOptions, "store" | "selection" | "resolveSelector" | "isConnectionVisible" | "policy" | "getAgentSnapshot">;
55
+ export declare function createConnectionAccessResolver(options: ConnectionAccessResolverOptions): {
56
+ acquire(input: ConnectionCapabilityResolveInput): Promise<SelectedConnectionAccess>;
57
+ };
14
58
  export declare function createConnectionCapabilityResolver(options: ConnectionCapabilityResolverOptions): ConnectionCapabilityResolver;
15
59
  export declare function createApplicationCapabilityResolver(options: ApplicationCapabilityResolverOptions): ApplicationCapabilityResolver;
16
60
  //# sourceMappingURL=capability-resolver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capability-resolver.d.ts","sourceRoot":"","sources":["../src/capability-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,gCAAgC,EACrC,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAEvB,KAAK,iCAAiC,EACtC,KAAK,6BAA6B,EAEnC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAEV,gBAAgB,EAChB,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mCAAmC;IAClD,KAAK,EAAE,YAAY,CAAC;IACpB,eAAe,CACb,KAAK,EAAE,gCAAgC,GACtC,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;IACtE,WAAW,CAAC,CACV,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,gCAAgC,GACtC,4BAA4B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACxE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,EAClB,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,gCAAgC,EACvC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,mBAAmB,CAAC,CAClB,UAAU,EAAE,gBAAgB,EAC5B,QAAQ,EAAE,2BAA2B,GACpC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,M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