@kya-os/mcp-i-core 1.7.0 → 1.8.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.
- package/README.md +1 -1
- package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
- package/dist/conformance/capability-verifier-adapter.js +61 -0
- package/dist/conformance/index.d.ts +10 -0
- package/dist/conformance/index.js +19 -0
- package/dist/conformance/validate-level2.d.ts +203 -0
- package/dist/conformance/validate-level2.js +294 -0
- package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
- package/dist/conformance/vc-jwt-verifier.js +147 -0
- package/dist/delegation/did-web-resolver.d.ts +60 -0
- package/dist/delegation/did-web-resolver.js +129 -0
- package/dist/delegation/outbound-proof.d.ts +3 -2
- package/dist/delegation/outbound-proof.js +3 -2
- package/dist/delegation/utils.d.ts +3 -1
- package/dist/index.d.ts +9 -63
- package/dist/index.js +22 -161
- package/dist/utils/base58.d.ts +4 -28
- package/dist/utils/base58.js +18 -98
- package/dist/utils/base64.d.ts +4 -29
- package/dist/utils/base64.js +18 -167
- package/dist/utils/did-helpers.d.ts +4 -165
- package/dist/utils/did-helpers.js +18 -217
- package/package.json +5 -7
- package/dist/auth/handshake.d.ts +0 -119
- package/dist/auth/handshake.js +0 -250
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.js +0 -11
- package/dist/auth/types.d.ts +0 -46
- package/dist/auth/types.js +0 -10
- package/dist/cache/oauth-config-cache.d.ts +0 -69
- package/dist/cache/oauth-config-cache.js +0 -76
- package/dist/cache/tool-protection-cache.d.ts +0 -89
- package/dist/cache/tool-protection-cache.js +0 -118
- package/dist/compliance/index.d.ts +0 -8
- package/dist/compliance/index.js +0 -24
- package/dist/compliance/schema-registry.d.ts +0 -50
- package/dist/compliance/schema-registry.js +0 -438
- package/dist/compliance/schema-verifier.d.ts +0 -110
- package/dist/compliance/schema-verifier.js +0 -518
- package/dist/config/remote-config.d.ts +0 -173
- package/dist/config/remote-config.js +0 -253
- package/dist/config.d.ts +0 -182
- package/dist/config.js +0 -148
- package/dist/identity/idp-token-resolver.d.ts +0 -69
- package/dist/identity/idp-token-resolver.js +0 -136
- package/dist/identity/idp-token-storage.interface.d.ts +0 -80
- package/dist/identity/idp-token-storage.interface.js +0 -14
- package/dist/identity/user-did-manager.d.ts +0 -228
- package/dist/identity/user-did-manager.js +0 -356
- package/dist/logging/index.d.ts +0 -5
- package/dist/logging/index.js +0 -10
- package/dist/logging/logger.d.ts +0 -33
- package/dist/logging/logger.js +0 -104
- package/dist/proof/generator.d.ts +0 -109
- package/dist/proof/generator.js +0 -236
- package/dist/proof/index.d.ts +0 -5
- package/dist/proof/index.js +0 -11
- package/dist/providers/base.d.ts +0 -95
- package/dist/providers/base.js +0 -47
- package/dist/providers/memory.d.ts +0 -42
- package/dist/providers/memory.js +0 -121
- package/dist/runtime/audit-logger.d.ts +0 -37
- package/dist/runtime/audit-logger.js +0 -9
- package/dist/runtime/base.d.ts +0 -375
- package/dist/runtime/base.js +0 -1491
- package/dist/runtime/ext-apps-constants.d.ts +0 -14
- package/dist/runtime/ext-apps-constants.js +0 -17
- package/dist/services/access-control.service.d.ts +0 -138
- package/dist/services/access-control.service.js +0 -721
- package/dist/services/authorization/authorization-registry.d.ts +0 -29
- package/dist/services/authorization/authorization-registry.js +0 -58
- package/dist/services/authorization/types.d.ts +0 -53
- package/dist/services/authorization/types.js +0 -10
- package/dist/services/batch-delegation.service.d.ts +0 -53
- package/dist/services/batch-delegation.service.js +0 -95
- package/dist/services/crypto.service.d.ts +0 -69
- package/dist/services/crypto.service.js +0 -225
- package/dist/services/delegation-error-formatter.d.ts +0 -124
- package/dist/services/delegation-error-formatter.js +0 -214
- package/dist/services/errors.d.ts +0 -49
- package/dist/services/errors.js +0 -66
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -15
- package/dist/services/oauth-config.service.d.ts +0 -53
- package/dist/services/oauth-config.service.js +0 -141
- package/dist/services/oauth-provider-registry.d.ts +0 -88
- package/dist/services/oauth-provider-registry.js +0 -128
- package/dist/services/oauth-service.d.ts +0 -122
- package/dist/services/oauth-service.js +0 -442
- package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
- package/dist/services/oauth-token-retrieval.service.js +0 -150
- package/dist/services/policy.service.d.ts +0 -130
- package/dist/services/policy.service.js +0 -399
- package/dist/services/proof-verifier.d.ts +0 -98
- package/dist/services/proof-verifier.js +0 -319
- package/dist/services/provider-resolver.d.ts +0 -89
- package/dist/services/provider-resolver.js +0 -196
- package/dist/services/provider-validator.d.ts +0 -55
- package/dist/services/provider-validator.js +0 -135
- package/dist/services/session-registration.service.d.ts +0 -80
- package/dist/services/session-registration.service.js +0 -174
- package/dist/services/storage.service.d.ts +0 -116
- package/dist/services/storage.service.js +0 -411
- package/dist/services/tool-context-builder.d.ts +0 -74
- package/dist/services/tool-context-builder.js +0 -215
- package/dist/services/tool-protection.service.d.ts +0 -193
- package/dist/services/tool-protection.service.js +0 -736
- package/dist/session/index.d.ts +0 -5
- package/dist/session/index.js +0 -11
- package/dist/session/manager.d.ts +0 -113
- package/dist/session/manager.js +0 -273
- package/dist/types/oauth-required-error.d.ts +0 -46
- package/dist/types/oauth-required-error.js +0 -42
- package/dist/types/tool-protection.d.ts +0 -144
- package/dist/types/tool-protection.js +0 -48
- package/dist/utils/cors.d.ts +0 -44
- package/dist/utils/cors.js +0 -71
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -24
- package/dist/utils/storage-keys.d.ts +0 -120
- package/dist/utils/storage-keys.js +0 -217
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Provider Validator
|
|
4
|
-
*
|
|
5
|
-
* Validates OAuth provider configurations for custom IDP support.
|
|
6
|
-
* Ensures provider configurations are valid before registration.
|
|
7
|
-
*
|
|
8
|
-
* @package @kya-os/mcp-i-core
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ProviderValidator = exports.ProviderValidationError = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Reserved OAuth parameters that cannot be overridden by custom parameters
|
|
14
|
-
*/
|
|
15
|
-
const RESERVED_PARAMETERS = [
|
|
16
|
-
"response_type",
|
|
17
|
-
"client_id",
|
|
18
|
-
"redirect_uri",
|
|
19
|
-
"scope",
|
|
20
|
-
"state",
|
|
21
|
-
"code_challenge",
|
|
22
|
-
"code_challenge_method",
|
|
23
|
-
];
|
|
24
|
-
/**
|
|
25
|
-
* Validation error for provider configuration issues
|
|
26
|
-
*/
|
|
27
|
-
class ProviderValidationError extends Error {
|
|
28
|
-
field;
|
|
29
|
-
constructor(message, field) {
|
|
30
|
-
super(message);
|
|
31
|
-
this.field = field;
|
|
32
|
-
this.name = "ProviderValidationError";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.ProviderValidationError = ProviderValidationError;
|
|
36
|
-
/**
|
|
37
|
-
* Service for validating OAuth provider configurations
|
|
38
|
-
*/
|
|
39
|
-
class ProviderValidator {
|
|
40
|
-
/**
|
|
41
|
-
* Validate provider configuration
|
|
42
|
-
*
|
|
43
|
-
* @param provider - Provider configuration to validate
|
|
44
|
-
* @param name - Provider name (for error messages)
|
|
45
|
-
* @throws ProviderValidationError if validation fails
|
|
46
|
-
*/
|
|
47
|
-
validate(provider, name) {
|
|
48
|
-
// Validate required fields
|
|
49
|
-
if (!provider.clientId || provider.clientId.trim().length === 0) {
|
|
50
|
-
throw new ProviderValidationError(`Provider "${name}" must have a clientId`, "clientId");
|
|
51
|
-
}
|
|
52
|
-
if (!provider.authorizationUrl || provider.authorizationUrl.trim().length === 0) {
|
|
53
|
-
throw new ProviderValidationError(`Provider "${name}" must have an authorizationUrl`, "authorizationUrl");
|
|
54
|
-
}
|
|
55
|
-
if (!provider.tokenUrl || provider.tokenUrl.trim().length === 0) {
|
|
56
|
-
throw new ProviderValidationError(`Provider "${name}" must have a tokenUrl`, "tokenUrl");
|
|
57
|
-
}
|
|
58
|
-
// Validate URL formats
|
|
59
|
-
this.validateUrl(provider.authorizationUrl, name, "authorizationUrl");
|
|
60
|
-
this.validateUrl(provider.tokenUrl, name, "tokenUrl");
|
|
61
|
-
if (provider.userInfoUrl) {
|
|
62
|
-
this.validateUrl(provider.userInfoUrl, name, "userInfoUrl");
|
|
63
|
-
}
|
|
64
|
-
// Validate proxy mode requirements
|
|
65
|
-
if (provider.proxyMode && !provider.requiresClientSecret) {
|
|
66
|
-
throw new ProviderValidationError(`Provider "${name}" with proxyMode=true must have requiresClientSecret=true`, "proxyMode");
|
|
67
|
-
}
|
|
68
|
-
// Validate custom parameters don't conflict with reserved parameters
|
|
69
|
-
if (provider.customParams) {
|
|
70
|
-
this.validateCustomParams(provider.customParams, name);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Validate URL format
|
|
75
|
-
*
|
|
76
|
-
* @param url - URL to validate
|
|
77
|
-
* @param providerName - Provider name (for error messages)
|
|
78
|
-
* @param fieldName - Field name (for error messages)
|
|
79
|
-
* @throws ProviderValidationError if URL is invalid
|
|
80
|
-
*/
|
|
81
|
-
validateUrl(url, providerName, fieldName) {
|
|
82
|
-
try {
|
|
83
|
-
const parsedUrl = new URL(url);
|
|
84
|
-
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
85
|
-
throw new ProviderValidationError(`Provider "${providerName}" ${fieldName} must use HTTP or HTTPS protocol`, fieldName);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (error instanceof ProviderValidationError) {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
throw new ProviderValidationError(`Provider "${providerName}" ${fieldName} is not a valid URL: ${error instanceof Error ? error.message : String(error)}`, fieldName);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Validate custom parameters don't override reserved OAuth parameters
|
|
97
|
-
*
|
|
98
|
-
* @param customParams - Custom parameters to validate
|
|
99
|
-
* @param providerName - Provider name (for error messages)
|
|
100
|
-
* @throws ProviderValidationError if reserved parameter is overridden
|
|
101
|
-
*/
|
|
102
|
-
validateCustomParams(customParams, providerName) {
|
|
103
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
104
|
-
const normalizedKey = key.toLowerCase();
|
|
105
|
-
if (RESERVED_PARAMETERS.includes(normalizedKey)) {
|
|
106
|
-
throw new ProviderValidationError(`Provider "${providerName}" custom parameter "${key}" conflicts with reserved OAuth parameter. Reserved parameters: ${RESERVED_PARAMETERS.join(", ")}`, `customParams.${key}`);
|
|
107
|
-
}
|
|
108
|
-
if (!value || value.trim().length === 0) {
|
|
109
|
-
throw new ProviderValidationError(`Provider "${providerName}" custom parameter "${key}" has empty value`, `customParams.${key}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Test provider endpoint reachability (optional)
|
|
115
|
-
*
|
|
116
|
-
* @param provider - Provider configuration
|
|
117
|
-
* @param fetchProvider - Fetch implementation
|
|
118
|
-
* @returns True if endpoint is reachable, false otherwise
|
|
119
|
-
*/
|
|
120
|
-
async testProvider(provider, fetchProvider) {
|
|
121
|
-
try {
|
|
122
|
-
// Test authorization URL (HEAD request to avoid triggering OAuth flow)
|
|
123
|
-
const authResponse = await fetchProvider(provider.authorizationUrl, {
|
|
124
|
-
method: "HEAD",
|
|
125
|
-
signal: AbortSignal.timeout(5000), // 5 second timeout
|
|
126
|
-
});
|
|
127
|
-
return authResponse.ok || authResponse.status === 405; // 405 Method Not Allowed is OK
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.ProviderValidator = ProviderValidator;
|
|
135
|
-
//# sourceMappingURL=provider-validator.js.map
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Registration Service
|
|
3
|
-
*
|
|
4
|
-
* Registers MCP sessions with the AgentShield dashboard, enabling
|
|
5
|
-
* visibility into which MCP clients are connecting to agents.
|
|
6
|
-
*
|
|
7
|
-
* This is a fire-and-forget service - session registration should not
|
|
8
|
-
* block tool execution or affect the user experience.
|
|
9
|
-
*
|
|
10
|
-
* @package @kya-os/mcp-i-core
|
|
11
|
-
*/
|
|
12
|
-
import type { RegisterSessionRequest } from "@kya-os/contracts/agentshield-api";
|
|
13
|
-
import type { FetchProvider } from "../providers/base.js";
|
|
14
|
-
/**
|
|
15
|
-
* Configuration for the session registration service
|
|
16
|
-
*/
|
|
17
|
-
export interface SessionRegistrationServiceConfig {
|
|
18
|
-
/** Base URL for the AgentShield API (e.g., "https://kya.vouched.id") */
|
|
19
|
-
baseUrl: string;
|
|
20
|
-
/** API key for authentication */
|
|
21
|
-
apiKey: string;
|
|
22
|
-
/** Fetch provider for making HTTP requests (platform-agnostic) */
|
|
23
|
-
fetchProvider: FetchProvider;
|
|
24
|
-
/** Optional logger callback for diagnostics */
|
|
25
|
-
logger?: (message: string, data?: unknown) => void;
|
|
26
|
-
/** Timeout in milliseconds for the registration request (default: 5000) */
|
|
27
|
-
timeoutMs?: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Result of a session registration attempt
|
|
31
|
-
*/
|
|
32
|
-
export interface SessionRegistrationResult {
|
|
33
|
-
/** Whether registration was successful */
|
|
34
|
-
success: boolean;
|
|
35
|
-
/** Session ID that was registered */
|
|
36
|
-
sessionId: string;
|
|
37
|
-
/** Error message if registration failed */
|
|
38
|
-
error?: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Session Registration Service
|
|
42
|
-
*
|
|
43
|
-
* Registers MCP sessions with AgentShield for dashboard visibility.
|
|
44
|
-
* Designed to be non-blocking - failures are logged but don't throw.
|
|
45
|
-
*/
|
|
46
|
-
export declare class SessionRegistrationService {
|
|
47
|
-
private config;
|
|
48
|
-
constructor(config: SessionRegistrationServiceConfig);
|
|
49
|
-
/**
|
|
50
|
-
* Register a session with AgentShield
|
|
51
|
-
*
|
|
52
|
-
* This is a fire-and-forget operation. Failures are logged but don't throw.
|
|
53
|
-
* The method returns quickly and doesn't block the caller.
|
|
54
|
-
*
|
|
55
|
-
* @param request - Session registration request data
|
|
56
|
-
* @returns Result indicating success or failure
|
|
57
|
-
*/
|
|
58
|
-
registerSession(request: RegisterSessionRequest): Promise<SessionRegistrationResult>;
|
|
59
|
-
/**
|
|
60
|
-
* Fire-and-forget session registration
|
|
61
|
-
*
|
|
62
|
-
* Starts registration in the background without waiting for completion.
|
|
63
|
-
* Useful when you want to register a session but not delay the response.
|
|
64
|
-
*
|
|
65
|
-
* @param request - Session registration request data
|
|
66
|
-
*/
|
|
67
|
-
registerSessionAsync(request: RegisterSessionRequest): void;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Create a session registration service from common runtime config
|
|
71
|
-
*
|
|
72
|
-
* Helper function to create the service from typical environment config.
|
|
73
|
-
*/
|
|
74
|
-
export declare function createSessionRegistrationService(options: {
|
|
75
|
-
apiUrl: string;
|
|
76
|
-
apiKey: string;
|
|
77
|
-
fetchProvider: FetchProvider;
|
|
78
|
-
logger?: (message: string, data?: unknown) => void;
|
|
79
|
-
}): SessionRegistrationService | null;
|
|
80
|
-
//# sourceMappingURL=session-registration.service.d.ts.map
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Session Registration Service
|
|
4
|
-
*
|
|
5
|
-
* Registers MCP sessions with the AgentShield dashboard, enabling
|
|
6
|
-
* visibility into which MCP clients are connecting to agents.
|
|
7
|
-
*
|
|
8
|
-
* This is a fire-and-forget service - session registration should not
|
|
9
|
-
* block tool execution or affect the user experience.
|
|
10
|
-
*
|
|
11
|
-
* @package @kya-os/mcp-i-core
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SessionRegistrationService = void 0;
|
|
15
|
-
exports.createSessionRegistrationService = createSessionRegistrationService;
|
|
16
|
-
const agentshield_api_1 = require("@kya-os/contracts/agentshield-api");
|
|
17
|
-
/**
|
|
18
|
-
* Session Registration Service
|
|
19
|
-
*
|
|
20
|
-
* Registers MCP sessions with AgentShield for dashboard visibility.
|
|
21
|
-
* Designed to be non-blocking - failures are logged but don't throw.
|
|
22
|
-
*/
|
|
23
|
-
class SessionRegistrationService {
|
|
24
|
-
config;
|
|
25
|
-
constructor(config) {
|
|
26
|
-
this.config = {
|
|
27
|
-
baseUrl: config.baseUrl,
|
|
28
|
-
apiKey: config.apiKey,
|
|
29
|
-
fetchProvider: config.fetchProvider,
|
|
30
|
-
logger: config.logger || (() => { }),
|
|
31
|
-
timeoutMs: config.timeoutMs ?? 5000,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Register a session with AgentShield
|
|
36
|
-
*
|
|
37
|
-
* This is a fire-and-forget operation. Failures are logged but don't throw.
|
|
38
|
-
* The method returns quickly and doesn't block the caller.
|
|
39
|
-
*
|
|
40
|
-
* @param request - Session registration request data
|
|
41
|
-
* @returns Result indicating success or failure
|
|
42
|
-
*/
|
|
43
|
-
async registerSession(request) {
|
|
44
|
-
const sessionId = request.session_id;
|
|
45
|
-
try {
|
|
46
|
-
// Validate request
|
|
47
|
-
const validationResult = agentshield_api_1.registerSessionRequestSchema.safeParse(request);
|
|
48
|
-
if (!validationResult.success) {
|
|
49
|
-
const errorMsg = `Invalid session registration request: ${validationResult.error.message}`;
|
|
50
|
-
this.config.logger("[SessionRegistration] Validation failed", {
|
|
51
|
-
sessionId,
|
|
52
|
-
error: errorMsg,
|
|
53
|
-
});
|
|
54
|
-
return { success: false, sessionId, error: errorMsg };
|
|
55
|
-
}
|
|
56
|
-
const url = `${this.config.baseUrl}${agentshield_api_1.AGENTSHIELD_ENDPOINTS.SESSIONS}`;
|
|
57
|
-
// NOTE: This registers the SESSION with AgentShield for dashboard visibility
|
|
58
|
-
// This is NOT the same as agent registration with Know That AI (which happens during deploy)
|
|
59
|
-
this.config.logger("[SessionRegistration] Registering session for dashboard visibility", {
|
|
60
|
-
sessionId,
|
|
61
|
-
agentDid: request.agent_did,
|
|
62
|
-
clientName: request.client_info.name,
|
|
63
|
-
url,
|
|
64
|
-
});
|
|
65
|
-
// Make the request with timeout
|
|
66
|
-
const controller = new AbortController();
|
|
67
|
-
const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);
|
|
68
|
-
try {
|
|
69
|
-
const response = await this.config.fetchProvider.fetch(url, {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: {
|
|
72
|
-
"Content-Type": "application/json",
|
|
73
|
-
Authorization: `Bearer ${this.config.apiKey}`,
|
|
74
|
-
},
|
|
75
|
-
body: JSON.stringify(request),
|
|
76
|
-
signal: controller.signal,
|
|
77
|
-
});
|
|
78
|
-
clearTimeout(timeoutId);
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
// Log error but don't throw - this is fire-and-forget
|
|
81
|
-
const errorText = await response.text().catch(() => "Unknown error");
|
|
82
|
-
this.config.logger("[SessionRegistration] Registration failed", {
|
|
83
|
-
sessionId,
|
|
84
|
-
status: response.status,
|
|
85
|
-
error: errorText,
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
success: false,
|
|
89
|
-
sessionId,
|
|
90
|
-
error: `HTTP ${response.status}: ${errorText}`,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Parse response
|
|
94
|
-
const responseData = (await response.json());
|
|
95
|
-
const parseResult = agentshield_api_1.registerSessionResponseSchema.safeParse(responseData.data || responseData);
|
|
96
|
-
if (!parseResult.success) {
|
|
97
|
-
this.config.logger("[SessionRegistration] Invalid response format", {
|
|
98
|
-
sessionId,
|
|
99
|
-
response: responseData,
|
|
100
|
-
});
|
|
101
|
-
// Still consider it a success if we got a 200 OK
|
|
102
|
-
return { success: true, sessionId };
|
|
103
|
-
}
|
|
104
|
-
this.config.logger("[SessionRegistration] Session now visible in AgentShield dashboard", {
|
|
105
|
-
sessionId,
|
|
106
|
-
registered: parseResult.data.registered,
|
|
107
|
-
});
|
|
108
|
-
return { success: true, sessionId };
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
clearTimeout(timeoutId);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
// Handle abort/timeout
|
|
116
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
117
|
-
this.config.logger("[SessionRegistration] Request timed out", {
|
|
118
|
-
sessionId,
|
|
119
|
-
timeoutMs: this.config.timeoutMs,
|
|
120
|
-
});
|
|
121
|
-
return { success: false, sessionId, error: "Request timed out" };
|
|
122
|
-
}
|
|
123
|
-
// Log any other error
|
|
124
|
-
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
125
|
-
this.config.logger("[SessionRegistration] Unexpected error", {
|
|
126
|
-
sessionId,
|
|
127
|
-
error: errorMsg,
|
|
128
|
-
});
|
|
129
|
-
return { success: false, sessionId, error: errorMsg };
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Fire-and-forget session registration
|
|
134
|
-
*
|
|
135
|
-
* Starts registration in the background without waiting for completion.
|
|
136
|
-
* Useful when you want to register a session but not delay the response.
|
|
137
|
-
*
|
|
138
|
-
* @param request - Session registration request data
|
|
139
|
-
*/
|
|
140
|
-
registerSessionAsync(request) {
|
|
141
|
-
// Start registration in background - don't await
|
|
142
|
-
this.registerSession(request).catch((error) => {
|
|
143
|
-
// This should never happen since registerSession catches all errors,
|
|
144
|
-
// but just in case
|
|
145
|
-
this.config.logger("[SessionRegistration] Background registration failed", {
|
|
146
|
-
sessionId: request.session_id,
|
|
147
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
exports.SessionRegistrationService = SessionRegistrationService;
|
|
153
|
-
/**
|
|
154
|
-
* Create a session registration service from common runtime config
|
|
155
|
-
*
|
|
156
|
-
* Helper function to create the service from typical environment config.
|
|
157
|
-
*/
|
|
158
|
-
function createSessionRegistrationService(options) {
|
|
159
|
-
// Validate required config
|
|
160
|
-
if (!options.apiUrl || !options.apiKey) {
|
|
161
|
-
options.logger?.("[SessionRegistration] Missing required config - session registration disabled", {
|
|
162
|
-
hasApiUrl: !!options.apiUrl,
|
|
163
|
-
hasApiKey: !!options.apiKey,
|
|
164
|
-
});
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
return new SessionRegistrationService({
|
|
168
|
-
baseUrl: options.apiUrl,
|
|
169
|
-
apiKey: options.apiKey,
|
|
170
|
-
fetchProvider: options.fetchProvider,
|
|
171
|
-
logger: options.logger,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
//# sourceMappingURL=session-registration.service.js.map
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage Service Factory
|
|
3
|
-
*
|
|
4
|
-
* Auto-selects storage providers based on available configuration.
|
|
5
|
-
* Priority: Redis > Cloudflare KV > Cloudflare Durable Objects > Memory
|
|
6
|
-
*
|
|
7
|
-
* @package @kya-os/mcp-i-core
|
|
8
|
-
*/
|
|
9
|
-
import { StorageProvider, NonceCacheProvider } from "../providers/base.js";
|
|
10
|
-
/**
|
|
11
|
-
* Storage service configuration
|
|
12
|
-
*/
|
|
13
|
-
export interface StorageServiceConfig {
|
|
14
|
-
/** Redis URL (e.g., "redis://localhost:6379") */
|
|
15
|
-
redisUrl?: string;
|
|
16
|
-
/** Cloudflare KV namespace */
|
|
17
|
-
kvNamespace?: {
|
|
18
|
-
get(key: string): Promise<string | null>;
|
|
19
|
-
put(key: string, value: string, options?: {
|
|
20
|
-
expirationTtl?: number;
|
|
21
|
-
}): Promise<void>;
|
|
22
|
-
delete(key: string): Promise<void>;
|
|
23
|
-
list(options?: {
|
|
24
|
-
prefix?: string;
|
|
25
|
-
}): Promise<{
|
|
26
|
-
keys: Array<{
|
|
27
|
-
name: string;
|
|
28
|
-
}>;
|
|
29
|
-
}>;
|
|
30
|
-
};
|
|
31
|
-
/** Cloudflare Durable Object state */
|
|
32
|
-
durableObjectState?: {
|
|
33
|
-
storage: {
|
|
34
|
-
get(key: string): Promise<string | undefined>;
|
|
35
|
-
put(key: string, value: string): Promise<void>;
|
|
36
|
-
delete(key: string): Promise<void>;
|
|
37
|
-
list(options?: {
|
|
38
|
-
prefix?: string;
|
|
39
|
-
}): Promise<Map<string, string>>;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
/** Fallback to memory if no external storage configured (default: true) */
|
|
43
|
-
fallbackToMemory?: boolean;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Storage providers result
|
|
47
|
-
*/
|
|
48
|
-
export interface StorageProviders {
|
|
49
|
-
storageProvider: StorageProvider;
|
|
50
|
-
nonceCacheProvider: NonceCacheProvider;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Key helper functions for consistent key formatting
|
|
54
|
-
*/
|
|
55
|
-
export declare class StorageKeyHelpers {
|
|
56
|
-
/**
|
|
57
|
-
* Build delegation key using composite format
|
|
58
|
-
* Format: delegation:${userDid}:${agentDid}:${projectId}
|
|
59
|
-
*/
|
|
60
|
-
static buildDelegationKey(userDid: string, agentDid: string, projectId: string): string;
|
|
61
|
-
/**
|
|
62
|
-
* Build session key
|
|
63
|
-
* Format: session:${sessionId}
|
|
64
|
-
*/
|
|
65
|
-
static buildSessionKey(sessionId: string): string;
|
|
66
|
-
/**
|
|
67
|
-
* Build nonce key
|
|
68
|
-
* Format: nonce:${agentDid}:${nonce}
|
|
69
|
-
*/
|
|
70
|
-
static buildNonceKey(agentDid: string, nonce: string): string;
|
|
71
|
-
/**
|
|
72
|
-
* Parse delegation key back into components
|
|
73
|
-
*
|
|
74
|
-
* Format: delegation:${userDid}:${agentDid}:${projectId}
|
|
75
|
-
*
|
|
76
|
-
* Note: DIDs contain colons (e.g., did:key:z123), so we can't simply split by ":"
|
|
77
|
-
* Instead, we:
|
|
78
|
-
* 1. Check that key starts with "delegation:"
|
|
79
|
-
* 2. Take the last part as projectId (doesn't contain colons)
|
|
80
|
-
* 3. Find where agentDid starts (look for "did:" pattern)
|
|
81
|
-
* 4. Everything before agentDid is userDid, everything between agentDid and projectId is agentDid
|
|
82
|
-
*
|
|
83
|
-
* Strategy: Since DIDs always start with "did:", we can find the second occurrence of "did:"
|
|
84
|
-
* to determine where agentDid begins. However, this assumes userDid and agentDid both start with "did:".
|
|
85
|
-
*
|
|
86
|
-
* For keys like "delegation:did:key:user123:did:key:agent456:project-789":
|
|
87
|
-
* - Remove "delegation:" prefix → "did:key:user123:did:key:agent456:project-789"
|
|
88
|
-
* - Find last ":" → separates agentDid from projectId
|
|
89
|
-
* - projectId = "project-789"
|
|
90
|
-
* - Find second occurrence of "did:" → separates userDid from agentDid
|
|
91
|
-
* - userDid = "did:key:user123"
|
|
92
|
-
* - agentDid = "did:key:agent456"
|
|
93
|
-
*/
|
|
94
|
-
static parseDelegationKey(key: string): {
|
|
95
|
-
userDid: string;
|
|
96
|
-
agentDid: string;
|
|
97
|
-
projectId: string;
|
|
98
|
-
} | null;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Create storage providers based on configuration
|
|
102
|
-
*
|
|
103
|
-
* Priority order:
|
|
104
|
-
* 1. Redis (if redisUrl provided)
|
|
105
|
-
* 2. Cloudflare KV (if kvNamespace provided)
|
|
106
|
-
* 3. Cloudflare Durable Objects (if durableObjectState provided)
|
|
107
|
-
* 4. In-memory fallback (if fallbackToMemory is true, default)
|
|
108
|
-
*/
|
|
109
|
-
export declare function createStorageProviders(config: StorageServiceConfig): Promise<StorageProviders>;
|
|
110
|
-
/**
|
|
111
|
-
* Migration utility for legacy key formats
|
|
112
|
-
*
|
|
113
|
-
* Migrates keys from old format (e.g., `agent:${did}:delegation`) to new composite format
|
|
114
|
-
*/
|
|
115
|
-
export declare function migrateLegacyKeys(oldKeyPrefix: string, newKeyFormat: (oldKey: string) => string | null, storageProvider: StorageProvider, batchSize?: number): Promise<number>;
|
|
116
|
-
//# sourceMappingURL=storage.service.d.ts.map
|