@adcp/client 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/adcp.js +536 -20
- package/dist/lib/agents/index.generated.d.ts +9 -1
- package/dist/lib/agents/index.generated.d.ts.map +1 -1
- package/dist/lib/agents/index.generated.js +12 -0
- package/dist/lib/agents/index.generated.js.map +1 -1
- package/dist/lib/auth/index.d.ts +1 -0
- package/dist/lib/auth/index.d.ts.map +1 -1
- package/dist/lib/auth/index.js +16 -0
- package/dist/lib/auth/index.js.map +1 -1
- package/dist/lib/auth/oauth/CLIFlowHandler.d.ts +61 -0
- package/dist/lib/auth/oauth/CLIFlowHandler.d.ts.map +1 -0
- package/dist/lib/auth/oauth/CLIFlowHandler.js +287 -0
- package/dist/lib/auth/oauth/CLIFlowHandler.js.map +1 -0
- package/dist/lib/auth/oauth/MCPOAuthProvider.d.ts +126 -0
- package/dist/lib/auth/oauth/MCPOAuthProvider.d.ts.map +1 -0
- package/dist/lib/auth/oauth/MCPOAuthProvider.js +236 -0
- package/dist/lib/auth/oauth/MCPOAuthProvider.js.map +1 -0
- package/dist/lib/auth/oauth/index.d.ts +104 -0
- package/dist/lib/auth/oauth/index.d.ts.map +1 -0
- package/dist/lib/auth/oauth/index.js +168 -0
- package/dist/lib/auth/oauth/index.js.map +1 -0
- package/dist/lib/auth/oauth/types.d.ts +114 -0
- package/dist/lib/auth/oauth/types.d.ts.map +1 -0
- package/dist/lib/auth/oauth/types.js +104 -0
- package/dist/lib/auth/oauth/types.js.map +1 -0
- package/dist/lib/core/TaskExecutor.d.ts +7 -0
- package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
- package/dist/lib/core/TaskExecutor.js +46 -10
- package/dist/lib/core/TaskExecutor.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +11 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/protocols/index.d.ts +2 -1
- package/dist/lib/protocols/index.d.ts.map +1 -1
- package/dist/lib/protocols/index.js +4 -1
- package/dist/lib/protocols/index.js.map +1 -1
- package/dist/lib/protocols/mcp.d.ts +80 -0
- package/dist/lib/protocols/mcp.d.ts.map +1 -1
- package/dist/lib/protocols/mcp.js +158 -0
- package/dist/lib/protocols/mcp.js.map +1 -1
- package/dist/lib/testing/agent-tester.d.ts +1 -1
- package/dist/lib/testing/agent-tester.d.ts.map +1 -1
- package/dist/lib/testing/agent-tester.js +39 -1
- package/dist/lib/testing/agent-tester.js.map +1 -1
- package/dist/lib/testing/index.d.ts +1 -1
- package/dist/lib/testing/index.d.ts.map +1 -1
- package/dist/lib/testing/index.js +11 -1
- package/dist/lib/testing/index.js.map +1 -1
- package/dist/lib/testing/scenarios/capabilities.d.ts +27 -0
- package/dist/lib/testing/scenarios/capabilities.d.ts.map +1 -0
- package/dist/lib/testing/scenarios/capabilities.js +250 -0
- package/dist/lib/testing/scenarios/capabilities.js.map +1 -0
- package/dist/lib/testing/scenarios/governance.d.ts +35 -0
- package/dist/lib/testing/scenarios/governance.d.ts.map +1 -0
- package/dist/lib/testing/scenarios/governance.js +428 -0
- package/dist/lib/testing/scenarios/governance.js.map +1 -0
- package/dist/lib/testing/scenarios/index.d.ts +3 -0
- package/dist/lib/testing/scenarios/index.d.ts.map +1 -1
- package/dist/lib/testing/scenarios/index.js +15 -1
- package/dist/lib/testing/scenarios/index.js.map +1 -1
- package/dist/lib/testing/scenarios/sponsored-intelligence.d.ts +34 -0
- package/dist/lib/testing/scenarios/sponsored-intelligence.d.ts.map +1 -0
- package/dist/lib/testing/scenarios/sponsored-intelligence.js +318 -0
- package/dist/lib/testing/scenarios/sponsored-intelligence.js.map +1 -0
- package/dist/lib/testing/types.d.ts +9 -1
- package/dist/lib/testing/types.d.ts.map +1 -1
- package/dist/lib/types/adcp.d.ts +47 -1
- package/dist/lib/types/adcp.d.ts.map +1 -1
- package/dist/lib/types/core.generated.d.ts +393 -164
- package/dist/lib/types/core.generated.d.ts.map +1 -1
- package/dist/lib/types/core.generated.js +2 -2
- package/dist/lib/types/core.generated.js.map +1 -1
- package/dist/lib/types/schemas.generated.d.ts +1275 -845
- package/dist/lib/types/schemas.generated.d.ts.map +1 -1
- package/dist/lib/types/schemas.generated.js +300 -198
- package/dist/lib/types/schemas.generated.js.map +1 -1
- package/dist/lib/types/tools.generated.d.ts +461 -167
- package/dist/lib/types/tools.generated.d.ts.map +1 -1
- package/dist/lib/types/tools.generated.js +1 -1
- package/dist/lib/types/tools.generated.js.map +1 -1
- package/dist/lib/version.d.ts +5 -5
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +5 -5
- package/dist/lib/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPOAuthProvider.d.ts","sourceRoot":"","sources":["../../../../src/lib/auth/oauth/MCPOAuthProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,gBAAiB,YAAW,mBAAmB;IAC1D,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;IAC/C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsB;gBAE1C,MAAM,EAAE,mBAAmB;IAOvC;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,KAAK,EAAE,WAAW,EAClB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,CAAC,EAAE,kBAAkB,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+1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP OAuth Provider
|
|
4
|
+
*
|
|
5
|
+
* Implements the MCP SDK's OAuthClientProvider interface
|
|
6
|
+
* using AgentConfig for token storage.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MCPOAuthProvider = void 0;
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
/**
|
|
13
|
+
* MCP OAuth Client Provider
|
|
14
|
+
*
|
|
15
|
+
* This provider stores OAuth tokens directly in the AgentConfig,
|
|
16
|
+
* using the same structure as static auth tokens.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const agent: AgentConfig = {
|
|
21
|
+
* id: 'my-agent',
|
|
22
|
+
* name: 'My Agent',
|
|
23
|
+
* agent_uri: 'https://agent.example.com/mcp',
|
|
24
|
+
* protocol: 'mcp',
|
|
25
|
+
* // OAuth tokens stored here after auth flow
|
|
26
|
+
* oauth_tokens: { access_token: '...', refresh_token: '...' }
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* const provider = new MCPOAuthProvider({
|
|
30
|
+
* agent,
|
|
31
|
+
* flowHandler: new CLIFlowHandler(),
|
|
32
|
+
* storage: myConfigStorage // Optional: persists tokens
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const transport = new StreamableHTTPClientTransport(url, {
|
|
36
|
+
* authProvider: provider
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class MCPOAuthProvider {
|
|
41
|
+
agent;
|
|
42
|
+
storage;
|
|
43
|
+
flowHandler;
|
|
44
|
+
_clientMetadata;
|
|
45
|
+
constructor(config) {
|
|
46
|
+
this.agent = config.agent;
|
|
47
|
+
this.storage = config.storage;
|
|
48
|
+
this.flowHandler = config.flowHandler;
|
|
49
|
+
this._clientMetadata = config.clientMetadata;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a provider for CLI usage
|
|
53
|
+
*/
|
|
54
|
+
static forCLI(agent, flowHandler, storage, clientMetadataOverrides) {
|
|
55
|
+
// Build complete client metadata with required fields
|
|
56
|
+
const clientMetadata = {
|
|
57
|
+
...types_1.DEFAULT_CLIENT_METADATA,
|
|
58
|
+
redirect_uris: [flowHandler.getRedirectUrl().toString()],
|
|
59
|
+
...clientMetadataOverrides,
|
|
60
|
+
};
|
|
61
|
+
return new MCPOAuthProvider({
|
|
62
|
+
agent,
|
|
63
|
+
flowHandler,
|
|
64
|
+
storage,
|
|
65
|
+
clientMetadata,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// ========================================
|
|
69
|
+
// OAuthClientProvider interface
|
|
70
|
+
// ========================================
|
|
71
|
+
get redirectUrl() {
|
|
72
|
+
return this.flowHandler.getRedirectUrl();
|
|
73
|
+
}
|
|
74
|
+
get clientMetadata() {
|
|
75
|
+
return this._clientMetadata;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate OAuth state parameter
|
|
79
|
+
*/
|
|
80
|
+
async state() {
|
|
81
|
+
return (0, crypto_1.randomBytes)(32).toString('base64url');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Load client information from agent config
|
|
85
|
+
*/
|
|
86
|
+
async clientInformation() {
|
|
87
|
+
if (this.agent.oauth_client) {
|
|
88
|
+
return (0, types_1.toMCPClientInfo)(this.agent.oauth_client);
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Save client information after dynamic registration
|
|
94
|
+
*/
|
|
95
|
+
async saveClientInformation(clientInfo) {
|
|
96
|
+
this.agent.oauth_client = (0, types_1.fromMCPClientInfo)(clientInfo);
|
|
97
|
+
await this.persistAgent();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Load existing tokens from agent config
|
|
101
|
+
*/
|
|
102
|
+
async tokens() {
|
|
103
|
+
if (this.agent.oauth_tokens) {
|
|
104
|
+
return (0, types_1.toMCPTokens)(this.agent.oauth_tokens);
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Save tokens after authorization
|
|
110
|
+
* Also cleans up the temporary code verifier
|
|
111
|
+
*/
|
|
112
|
+
async saveTokens(tokens) {
|
|
113
|
+
this.agent.oauth_tokens = (0, types_1.fromMCPTokens)(tokens);
|
|
114
|
+
// Clean up temporary code verifier after successful token exchange
|
|
115
|
+
delete this.agent.oauth_code_verifier;
|
|
116
|
+
await this.persistAgent();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Redirect user to authorization URL
|
|
120
|
+
*/
|
|
121
|
+
async redirectToAuthorization(authorizationUrl) {
|
|
122
|
+
await this.flowHandler.redirectToAuthorization(authorizationUrl);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Save PKCE code verifier
|
|
126
|
+
*/
|
|
127
|
+
async saveCodeVerifier(codeVerifier) {
|
|
128
|
+
this.agent.oauth_code_verifier = codeVerifier;
|
|
129
|
+
await this.persistAgent();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Load PKCE code verifier
|
|
133
|
+
* The MCP SDK calls saveCodeVerifier() before authorization and
|
|
134
|
+
* retrieves it here during token exchange.
|
|
135
|
+
*/
|
|
136
|
+
async codeVerifier() {
|
|
137
|
+
if (!this.agent.oauth_code_verifier) {
|
|
138
|
+
throw new Error('No PKCE code verifier found. The OAuth flow may have been interrupted or ' +
|
|
139
|
+
'the agent config was modified. Please try authenticating again.');
|
|
140
|
+
}
|
|
141
|
+
return this.agent.oauth_code_verifier;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Invalidate credentials when server indicates they're invalid
|
|
145
|
+
*/
|
|
146
|
+
async invalidateCredentials(scope) {
|
|
147
|
+
switch (scope) {
|
|
148
|
+
case 'all':
|
|
149
|
+
delete this.agent.oauth_tokens;
|
|
150
|
+
delete this.agent.oauth_client;
|
|
151
|
+
delete this.agent.oauth_code_verifier;
|
|
152
|
+
break;
|
|
153
|
+
case 'tokens':
|
|
154
|
+
delete this.agent.oauth_tokens;
|
|
155
|
+
break;
|
|
156
|
+
case 'client':
|
|
157
|
+
delete this.agent.oauth_client;
|
|
158
|
+
break;
|
|
159
|
+
case 'verifier':
|
|
160
|
+
delete this.agent.oauth_code_verifier;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
await this.persistAgent();
|
|
164
|
+
}
|
|
165
|
+
// ========================================
|
|
166
|
+
// Additional methods
|
|
167
|
+
// ========================================
|
|
168
|
+
/**
|
|
169
|
+
* Persist agent config to storage if configured
|
|
170
|
+
*/
|
|
171
|
+
async persistAgent() {
|
|
172
|
+
if (this.storage) {
|
|
173
|
+
await this.storage.saveAgent(this.agent);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Wait for the OAuth callback
|
|
178
|
+
* Call this after UnauthorizedError is thrown
|
|
179
|
+
*/
|
|
180
|
+
async waitForCallback() {
|
|
181
|
+
return this.flowHandler.waitForCallback();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Clean up resources
|
|
185
|
+
*/
|
|
186
|
+
async cleanup() {
|
|
187
|
+
await this.flowHandler.cleanup();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if we have valid, non-expired OAuth tokens
|
|
191
|
+
* @returns true if access_token exists and hasn't expired (with 5 minute buffer)
|
|
192
|
+
*/
|
|
193
|
+
hasValidTokens() {
|
|
194
|
+
const tokens = this.agent.oauth_tokens;
|
|
195
|
+
if (!tokens?.access_token)
|
|
196
|
+
return false;
|
|
197
|
+
// Check expiration if available
|
|
198
|
+
if (tokens.expires_at) {
|
|
199
|
+
const expiresAt = new Date(tokens.expires_at);
|
|
200
|
+
// Consider expired if within 5 minutes of expiration
|
|
201
|
+
if (expiresAt.getTime() - Date.now() < 5 * 60 * 1000) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if we have a refresh token available for token refresh
|
|
209
|
+
* @returns true if refresh_token is present
|
|
210
|
+
*/
|
|
211
|
+
hasRefreshToken() {
|
|
212
|
+
return !!this.agent.oauth_tokens?.refresh_token;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Clear all OAuth data for this agent
|
|
216
|
+
*/
|
|
217
|
+
async clearAuth() {
|
|
218
|
+
await this.invalidateCredentials('all');
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get the agent config this provider manages
|
|
222
|
+
* @returns The AgentConfig with OAuth tokens populated after successful auth
|
|
223
|
+
*/
|
|
224
|
+
getAgent() {
|
|
225
|
+
return this.agent;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get the agent identifier
|
|
229
|
+
* @returns The agent's unique ID
|
|
230
|
+
*/
|
|
231
|
+
getAgentId() {
|
|
232
|
+
return this.agent.id;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.MCPOAuthProvider = MCPOAuthProvider;
|
|
236
|
+
//# sourceMappingURL=MCPOAuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPOAuthProvider.js","sourceRoot":"","sources":["../../../../src/lib/auth/oauth/MCPOAuthProvider.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAaH,mCAAkH;AAClH,mCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,gBAAgB;IACnB,KAAK,CAAc;IACV,OAAO,CAAsB;IAC7B,WAAW,CAAmB;IAC9B,eAAe,CAAsB;IAEtD,YAAY,MAA2B;QACrC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAA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C;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IACvB,CAAC;CACF;AAlOD,4CAkOC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth module for MCP authentication
|
|
3
|
+
*
|
|
4
|
+
* OAuth tokens are stored directly in AgentConfig, same as static auth tokens.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { MCPOAuthProvider, CLIFlowHandler } from '@adcp/client';
|
|
9
|
+
*
|
|
10
|
+
* // Agent config - tokens will be stored here
|
|
11
|
+
* const agent: AgentConfig = {
|
|
12
|
+
* id: 'my-agent',
|
|
13
|
+
* name: 'My Agent',
|
|
14
|
+
* agent_uri: 'https://agent.example.com/mcp',
|
|
15
|
+
* protocol: 'mcp',
|
|
16
|
+
* // After OAuth flow completes:
|
|
17
|
+
* // oauth_tokens: { access_token: '...', refresh_token: '...' }
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* // Create provider with CLI flow handler
|
|
21
|
+
* const provider = new MCPOAuthProvider({
|
|
22
|
+
* agent,
|
|
23
|
+
* flowHandler: new CLIFlowHandler(),
|
|
24
|
+
* storage: myConfigStorage // Optional: persists tokens to file/db
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Use with MCP transport
|
|
28
|
+
* const transport = new StreamableHTTPClientTransport(url, {
|
|
29
|
+
* authProvider: provider
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type { OAuthFlowHandler, OAuthProviderConfig, OAuthConfigStorage, OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens, AgentConfig, AgentOAuthTokens, AgentOAuthClient, } from './types';
|
|
34
|
+
export { DEFAULT_CLIENT_METADATA, OAuthError, OAuthCancelledError, OAuthTimeoutError, toMCPTokens, fromMCPTokens, toMCPClientInfo, fromMCPClientInfo, } from './types';
|
|
35
|
+
export { CLIFlowHandler, type CLIFlowHandlerConfig } from './CLIFlowHandler';
|
|
36
|
+
export { MCPOAuthProvider } from './MCPOAuthProvider';
|
|
37
|
+
import { MCPOAuthProvider } from './MCPOAuthProvider';
|
|
38
|
+
import type { OAuthClientMetadata, OAuthConfigStorage, AgentConfig } from './types';
|
|
39
|
+
/**
|
|
40
|
+
* Create an OAuth provider for CLI usage
|
|
41
|
+
*
|
|
42
|
+
* @param agent Agent configuration (tokens stored here)
|
|
43
|
+
* @param options Optional configuration
|
|
44
|
+
* @returns Configured OAuth provider
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const agent: AgentConfig = {
|
|
49
|
+
* id: 'my-agent',
|
|
50
|
+
* name: 'My Agent',
|
|
51
|
+
* agent_uri: 'https://agent.example.com/mcp',
|
|
52
|
+
* protocol: 'mcp'
|
|
53
|
+
* };
|
|
54
|
+
*
|
|
55
|
+
* const provider = createCLIOAuthProvider(agent);
|
|
56
|
+
*
|
|
57
|
+
* const transport = new StreamableHTTPClientTransport(url, {
|
|
58
|
+
* authProvider: provider
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* try {
|
|
62
|
+
* await client.connect(transport);
|
|
63
|
+
* } catch (error) {
|
|
64
|
+
* if (error instanceof UnauthorizedError) {
|
|
65
|
+
* const code = await provider.waitForCallback();
|
|
66
|
+
* await transport.finishAuth(code);
|
|
67
|
+
* await client.connect(transport);
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* // After successful auth, agent.oauth_tokens is populated
|
|
72
|
+
* console.log(agent.oauth_tokens);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function createCLIOAuthProvider(agent: AgentConfig, options?: {
|
|
76
|
+
/** Callback port (default: 8766) */
|
|
77
|
+
callbackPort?: number;
|
|
78
|
+
/** Auth timeout in ms (default: 300000 = 5 min) */
|
|
79
|
+
timeout?: number;
|
|
80
|
+
/** Custom client metadata overrides */
|
|
81
|
+
clientMetadata?: Partial<OAuthClientMetadata>;
|
|
82
|
+
/** Suppress console output */
|
|
83
|
+
quiet?: boolean;
|
|
84
|
+
/** Storage for persisting agent config */
|
|
85
|
+
storage?: OAuthConfigStorage;
|
|
86
|
+
}): MCPOAuthProvider;
|
|
87
|
+
/**
|
|
88
|
+
* Check if an error indicates OAuth is required
|
|
89
|
+
*/
|
|
90
|
+
export declare function isOAuthRequired(error: unknown): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Check if an agent has valid OAuth tokens
|
|
93
|
+
*/
|
|
94
|
+
export declare function hasValidOAuthTokens(agent: AgentConfig): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Clear OAuth tokens from an agent config
|
|
97
|
+
*/
|
|
98
|
+
export declare function clearOAuthTokens(agent: AgentConfig): void;
|
|
99
|
+
/**
|
|
100
|
+
* Get the effective auth token for an agent
|
|
101
|
+
* Returns OAuth access_token if available, otherwise static auth_token
|
|
102
|
+
*/
|
|
103
|
+
export declare function getEffectiveAuthToken(agent: AgentConfig): string | undefined;
|
|
104
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/auth/oauth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;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D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAO5E"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OAuth module for MCP authentication
|
|
4
|
+
*
|
|
5
|
+
* OAuth tokens are stored directly in AgentConfig, same as static auth tokens.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { MCPOAuthProvider, CLIFlowHandler } from '@adcp/client';
|
|
10
|
+
*
|
|
11
|
+
* // Agent config - tokens will be stored here
|
|
12
|
+
* const agent: AgentConfig = {
|
|
13
|
+
* id: 'my-agent',
|
|
14
|
+
* name: 'My Agent',
|
|
15
|
+
* agent_uri: 'https://agent.example.com/mcp',
|
|
16
|
+
* protocol: 'mcp',
|
|
17
|
+
* // After OAuth flow completes:
|
|
18
|
+
* // oauth_tokens: { access_token: '...', refresh_token: '...' }
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* // Create provider with CLI flow handler
|
|
22
|
+
* const provider = new MCPOAuthProvider({
|
|
23
|
+
* agent,
|
|
24
|
+
* flowHandler: new CLIFlowHandler(),
|
|
25
|
+
* storage: myConfigStorage // Optional: persists tokens to file/db
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Use with MCP transport
|
|
29
|
+
* const transport = new StreamableHTTPClientTransport(url, {
|
|
30
|
+
* authProvider: provider
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.MCPOAuthProvider = exports.CLIFlowHandler = exports.fromMCPClientInfo = exports.toMCPClientInfo = exports.fromMCPTokens = exports.toMCPTokens = exports.OAuthTimeoutError = exports.OAuthCancelledError = exports.OAuthError = exports.DEFAULT_CLIENT_METADATA = void 0;
|
|
36
|
+
exports.createCLIOAuthProvider = createCLIOAuthProvider;
|
|
37
|
+
exports.isOAuthRequired = isOAuthRequired;
|
|
38
|
+
exports.hasValidOAuthTokens = hasValidOAuthTokens;
|
|
39
|
+
exports.clearOAuthTokens = clearOAuthTokens;
|
|
40
|
+
exports.getEffectiveAuthToken = getEffectiveAuthToken;
|
|
41
|
+
var types_1 = require("./types");
|
|
42
|
+
Object.defineProperty(exports, "DEFAULT_CLIENT_METADATA", { enumerable: true, get: function () { return types_1.DEFAULT_CLIENT_METADATA; } });
|
|
43
|
+
Object.defineProperty(exports, "OAuthError", { enumerable: true, get: function () { return types_1.OAuthError; } });
|
|
44
|
+
Object.defineProperty(exports, "OAuthCancelledError", { enumerable: true, get: function () { return types_1.OAuthCancelledError; } });
|
|
45
|
+
Object.defineProperty(exports, "OAuthTimeoutError", { enumerable: true, get: function () { return types_1.OAuthTimeoutError; } });
|
|
46
|
+
Object.defineProperty(exports, "toMCPTokens", { enumerable: true, get: function () { return types_1.toMCPTokens; } });
|
|
47
|
+
Object.defineProperty(exports, "fromMCPTokens", { enumerable: true, get: function () { return types_1.fromMCPTokens; } });
|
|
48
|
+
Object.defineProperty(exports, "toMCPClientInfo", { enumerable: true, get: function () { return types_1.toMCPClientInfo; } });
|
|
49
|
+
Object.defineProperty(exports, "fromMCPClientInfo", { enumerable: true, get: function () { return types_1.fromMCPClientInfo; } });
|
|
50
|
+
// Flow handlers
|
|
51
|
+
var CLIFlowHandler_1 = require("./CLIFlowHandler");
|
|
52
|
+
Object.defineProperty(exports, "CLIFlowHandler", { enumerable: true, get: function () { return CLIFlowHandler_1.CLIFlowHandler; } });
|
|
53
|
+
// Main provider
|
|
54
|
+
var MCPOAuthProvider_1 = require("./MCPOAuthProvider");
|
|
55
|
+
Object.defineProperty(exports, "MCPOAuthProvider", { enumerable: true, get: function () { return MCPOAuthProvider_1.MCPOAuthProvider; } });
|
|
56
|
+
// ========================================
|
|
57
|
+
// Convenience factory functions
|
|
58
|
+
// ========================================
|
|
59
|
+
const MCPOAuthProvider_2 = require("./MCPOAuthProvider");
|
|
60
|
+
const CLIFlowHandler_2 = require("./CLIFlowHandler");
|
|
61
|
+
const types_2 = require("./types");
|
|
62
|
+
/**
|
|
63
|
+
* Create an OAuth provider for CLI usage
|
|
64
|
+
*
|
|
65
|
+
* @param agent Agent configuration (tokens stored here)
|
|
66
|
+
* @param options Optional configuration
|
|
67
|
+
* @returns Configured OAuth provider
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const agent: AgentConfig = {
|
|
72
|
+
* id: 'my-agent',
|
|
73
|
+
* name: 'My Agent',
|
|
74
|
+
* agent_uri: 'https://agent.example.com/mcp',
|
|
75
|
+
* protocol: 'mcp'
|
|
76
|
+
* };
|
|
77
|
+
*
|
|
78
|
+
* const provider = createCLIOAuthProvider(agent);
|
|
79
|
+
*
|
|
80
|
+
* const transport = new StreamableHTTPClientTransport(url, {
|
|
81
|
+
* authProvider: provider
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* try {
|
|
85
|
+
* await client.connect(transport);
|
|
86
|
+
* } catch (error) {
|
|
87
|
+
* if (error instanceof UnauthorizedError) {
|
|
88
|
+
* const code = await provider.waitForCallback();
|
|
89
|
+
* await transport.finishAuth(code);
|
|
90
|
+
* await client.connect(transport);
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* // After successful auth, agent.oauth_tokens is populated
|
|
95
|
+
* console.log(agent.oauth_tokens);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
function createCLIOAuthProvider(agent, options) {
|
|
99
|
+
const flowConfig = {
|
|
100
|
+
callbackPort: options?.callbackPort,
|
|
101
|
+
timeout: options?.timeout,
|
|
102
|
+
quiet: options?.quiet,
|
|
103
|
+
};
|
|
104
|
+
const flowHandler = new CLIFlowHandler_2.CLIFlowHandler(flowConfig);
|
|
105
|
+
// Build complete client metadata
|
|
106
|
+
const clientMetadata = {
|
|
107
|
+
...types_2.DEFAULT_CLIENT_METADATA,
|
|
108
|
+
redirect_uris: [flowHandler.getRedirectUrl().toString()],
|
|
109
|
+
...options?.clientMetadata,
|
|
110
|
+
};
|
|
111
|
+
return new MCPOAuthProvider_2.MCPOAuthProvider({
|
|
112
|
+
agent,
|
|
113
|
+
flowHandler,
|
|
114
|
+
storage: options?.storage,
|
|
115
|
+
clientMetadata,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if an error indicates OAuth is required
|
|
120
|
+
*/
|
|
121
|
+
function isOAuthRequired(error) {
|
|
122
|
+
if (error instanceof Error) {
|
|
123
|
+
if (error.name === 'UnauthorizedError')
|
|
124
|
+
return true;
|
|
125
|
+
const msg = error.message.toLowerCase();
|
|
126
|
+
if (msg.includes('unauthorized') || msg.includes('authentication required') || msg.includes('oauth')) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if an agent has valid OAuth tokens
|
|
134
|
+
*/
|
|
135
|
+
function hasValidOAuthTokens(agent) {
|
|
136
|
+
const tokens = agent.oauth_tokens;
|
|
137
|
+
if (!tokens?.access_token)
|
|
138
|
+
return false;
|
|
139
|
+
if (tokens.expires_at) {
|
|
140
|
+
const expiresAt = new Date(tokens.expires_at);
|
|
141
|
+
// Expired if within 5 minutes of expiration
|
|
142
|
+
if (expiresAt.getTime() - Date.now() < 5 * 60 * 1000) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clear OAuth tokens from an agent config
|
|
150
|
+
*/
|
|
151
|
+
function clearOAuthTokens(agent) {
|
|
152
|
+
delete agent.oauth_tokens;
|
|
153
|
+
delete agent.oauth_client;
|
|
154
|
+
delete agent.oauth_code_verifier;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get the effective auth token for an agent
|
|
158
|
+
* Returns OAuth access_token if available, otherwise static auth_token
|
|
159
|
+
*/
|
|
160
|
+
function getEffectiveAuthToken(agent) {
|
|
161
|
+
// Prefer OAuth if available and valid
|
|
162
|
+
if (hasValidOAuthTokens(agent)) {
|
|
163
|
+
return agent.oauth_tokens.access_token;
|
|
164
|
+
}
|
|
165
|
+
// Fall back to static token
|
|
166
|
+
return agent.auth_token;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/auth/oauth/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AA8EH,wDAmCC;AAKD,0CASC;AAKD,kDAaC;AAKD,4CAIC;AAMD,sDAOC;AAvJD,iCASiB;AARf,gHAAA,uBAAuB,OAAA;AACvB,mGAAA,UAAU,OAAA;AACV,4GAAA,mBAAmB,OAAA;AACnB,0GAAA,iBAAiB,OAAA;AACjB,oGAAA,WAAW,OAAA;AACX,sGAAA,aAAa,OAAA;AACb,wGAAA,eAAe,OAAA;AACf,0GAAA,iBAAiB,OAAA;AAGnB,gBAAgB;AAChB,mDAA6E;AAApE,gHAAA,cAAc,OAAA;AAEvB,gBAAgB;AAChB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AAEzB,2CAA2C;AAC3C,gCAAgC;AAChC,2CAA2C;AAE3C,yDAAsD;AACtD,qDAA6E;AAE7E,mCAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,sBAAsB,CACpC,KAAkB,EAClB,OAWC;IAED,MAAM,UAAU,GAAyB;QACvC,YAAY,EAAE,OAAO,EAAE,YAAY;QACnC,OAAO,EAAE,OAAO,EAAE,OAAO;QACzB,KAAK,EAAE,OAAO,EAAE,KAAK;KACtB,CAAC;IACF,MAAM,WAAW,GAA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AAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,OAAO,KAAK,CAAC,YAAY,CAAC;IAC1B,OAAO,KAAK,CAAC,YAAY,CAAC;IAC1B,OAAO,KAAK,CAAC,mBAAmB,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,KAAkB;IACtD,sCAAsC;IACtC,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,YAAa,CAAC,YAAY,CAAC;IAC1C,CAAC;IACD,4BAA4B;IAC5B,OAAO,KAAK,CAAC,UAAU,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth types for MCP authentication
|
|
3
|
+
*
|
|
4
|
+
* These types support the pluggable OAuth architecture:
|
|
5
|
+
* - OAuthConfigStorage: Interface for reading/writing agent config with OAuth data
|
|
6
|
+
* - OAuthFlowHandler: Abstract interface for authorization flow (CLI vs web)
|
|
7
|
+
*/
|
|
8
|
+
import type { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
9
|
+
import type { AgentConfig, AgentOAuthTokens, AgentOAuthClient } from '../../types/adcp';
|
|
10
|
+
export type { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens };
|
|
11
|
+
export type { AgentConfig, AgentOAuthTokens, AgentOAuthClient };
|
|
12
|
+
/**
|
|
13
|
+
* Agent config storage interface
|
|
14
|
+
*
|
|
15
|
+
* Implement this to persist OAuth tokens back to agent configuration.
|
|
16
|
+
* This allows different storage backends (file, database, memory)
|
|
17
|
+
* while keeping tokens in the agent config structure.
|
|
18
|
+
*/
|
|
19
|
+
export interface OAuthConfigStorage {
|
|
20
|
+
/**
|
|
21
|
+
* Load agent configuration
|
|
22
|
+
* @param agentId The agent ID
|
|
23
|
+
* @returns Agent config or undefined if not found
|
|
24
|
+
*/
|
|
25
|
+
loadAgent(agentId: string): Promise<AgentConfig | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Save agent configuration (with updated OAuth data)
|
|
28
|
+
* @param agent The agent config to save
|
|
29
|
+
*/
|
|
30
|
+
saveAgent(agent: AgentConfig): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Authorization flow handler - implement this for different environments
|
|
34
|
+
*
|
|
35
|
+
* Examples:
|
|
36
|
+
* - CLIFlowHandler: Opens browser, starts callback server
|
|
37
|
+
* - WebFlowHandler: HTTP redirects
|
|
38
|
+
* - HeadlessFlowHandler: Device code flow (future)
|
|
39
|
+
*/
|
|
40
|
+
export interface OAuthFlowHandler {
|
|
41
|
+
/**
|
|
42
|
+
* Get the callback URL for OAuth redirects
|
|
43
|
+
*/
|
|
44
|
+
getRedirectUrl(): string | URL;
|
|
45
|
+
/**
|
|
46
|
+
* Redirect the user to the authorization URL
|
|
47
|
+
* For CLI: Opens browser
|
|
48
|
+
* For web: HTTP redirect or return URL for client-side redirect
|
|
49
|
+
*
|
|
50
|
+
* @param authorizationUrl The OAuth authorization URL
|
|
51
|
+
* @returns Promise that resolves when user is redirected
|
|
52
|
+
*/
|
|
53
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Wait for the authorization callback and extract the auth code
|
|
56
|
+
* For CLI: Starts a local HTTP server and waits
|
|
57
|
+
* For web: Called by the callback route handler
|
|
58
|
+
*
|
|
59
|
+
* @returns Promise resolving to the authorization code
|
|
60
|
+
*/
|
|
61
|
+
waitForCallback(): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Clean up any resources (e.g., callback server)
|
|
64
|
+
*/
|
|
65
|
+
cleanup(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for creating an OAuth provider
|
|
69
|
+
*/
|
|
70
|
+
export interface OAuthProviderConfig {
|
|
71
|
+
/** Agent configuration (tokens will be stored here) */
|
|
72
|
+
agent: AgentConfig;
|
|
73
|
+
/** Storage for persisting agent config changes */
|
|
74
|
+
storage?: OAuthConfigStorage;
|
|
75
|
+
/** Authorization flow handler */
|
|
76
|
+
flowHandler: OAuthFlowHandler;
|
|
77
|
+
/** OAuth client metadata (required - use DEFAULT_CLIENT_METADATA as base) */
|
|
78
|
+
clientMetadata: OAuthClientMetadata;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Default OAuth client metadata for ADCP clients
|
|
82
|
+
*/
|
|
83
|
+
export declare const DEFAULT_CLIENT_METADATA: OAuthClientMetadata;
|
|
84
|
+
/**
|
|
85
|
+
* OAuth error types
|
|
86
|
+
*/
|
|
87
|
+
export declare class OAuthError extends Error {
|
|
88
|
+
readonly code: string;
|
|
89
|
+
readonly agentId?: string | undefined;
|
|
90
|
+
constructor(message: string, code: string, agentId?: string | undefined);
|
|
91
|
+
}
|
|
92
|
+
export declare class OAuthCancelledError extends OAuthError {
|
|
93
|
+
constructor(agentId?: string);
|
|
94
|
+
}
|
|
95
|
+
export declare class OAuthTimeoutError extends OAuthError {
|
|
96
|
+
constructor(agentId?: string, timeoutMs?: number);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Convert AgentOAuthTokens to MCP SDK OAuthTokens format
|
|
100
|
+
*/
|
|
101
|
+
export declare function toMCPTokens(tokens: AgentOAuthTokens): OAuthTokens;
|
|
102
|
+
/**
|
|
103
|
+
* Convert MCP SDK OAuthTokens to AgentOAuthTokens format
|
|
104
|
+
*/
|
|
105
|
+
export declare function fromMCPTokens(tokens: OAuthTokens): AgentOAuthTokens;
|
|
106
|
+
/**
|
|
107
|
+
* Convert AgentOAuthClient to MCP SDK OAuthClientInformation format
|
|
108
|
+
*/
|
|
109
|
+
export declare function toMCPClientInfo(client: AgentOAuthClient): OAuthClientInformation;
|
|
110
|
+
/**
|
|
111
|
+
* Convert MCP SDK OAuthClientInformationFull to AgentOAuthClient format
|
|
112
|
+
*/
|
|
113
|
+
export declare function fromMCPClientInfo(info: OAuthClientInformationFull): AgentOAuthClient;
|
|
114
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/auth/oauth/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,WAAW,EACZ,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGxF,YAAY,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,WAAW,EAAE,CAAC;AAGrG,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAE7D;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,GAAG,CAAC;IAE/B;;;;;;;OAOG;IACH,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;;;;;OAMG;IACH,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnC;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,u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