@kya-os/mcp-i 0.1.0-alpha.3.6 → 0.1.0-alpha.3.8
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 +16 -1
- package/dist/cjs/index.js +101 -24
- package/dist/cjs/platform-info.d.ts +36 -0
- package/dist/cjs/platform-info.js +274 -0
- package/dist/cjs/registry/knowthat.d.ts +6 -2
- package/dist/cjs/registry/knowthat.js +78 -7
- package/dist/cjs/transport.js +26 -4
- package/dist/cjs/types.d.ts +33 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +118 -28
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/platform-info.d.ts +74 -0
- package/dist/esm/platform-info.d.ts.map +1 -0
- package/dist/esm/platform-info.js +293 -0
- package/dist/esm/platform-info.js.map +1 -0
- package/dist/esm/registry/knowthat.d.ts +16 -3
- package/dist/esm/registry/knowthat.d.ts.map +1 -1
- package/dist/esm/registry/knowthat.js +101 -8
- package/dist/esm/registry/knowthat.js.map +1 -1
- package/dist/esm/transport.d.ts.map +1 -1
- package/dist/esm/transport.js +30 -4
- package/dist/esm/transport.js.map +1 -1
- package/dist/esm/types.d.ts +53 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ v1.0.0 will be released this week.
|
|
|
18
18
|
- **Build Reputation** - Every interaction is signed and verifiable
|
|
19
19
|
- **Future-Proof** - Ready for the decentralized agent ecosystem
|
|
20
20
|
- **Production-Ready** - Optimized for Lambda, Edge, Next.js, and traditional deployments
|
|
21
|
+
- **Fast Registration** - New CLI endpoint provides 100-200ms registration (10-50x faster!)
|
|
21
22
|
|
|
22
23
|
**For Directory Maintainers:**
|
|
23
24
|
|
|
@@ -48,7 +49,21 @@ import "@kya-os/mcp-i/auto";
|
|
|
48
49
|
// That's it! Your server now has cryptographic identity
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
### 2.
|
|
52
|
+
### 2. With Progress Tracking (CLI Tools)
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { enableMCPIdentity } from "@kya-os/mcp-i";
|
|
56
|
+
|
|
57
|
+
const identity = await enableMCPIdentity({
|
|
58
|
+
name: "My CLI Tool",
|
|
59
|
+
// Progress callback automatically triggers fast CLI endpoint (100-200ms)
|
|
60
|
+
onProgress: (event) => {
|
|
61
|
+
console.log(`${event.stage}: ${event.message}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Production Configuration
|
|
52
67
|
|
|
53
68
|
```typescript
|
|
54
69
|
import { enableMCPIdentity } from "@kya-os/mcp-i";
|
package/dist/cjs/index.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.enableMCPIdentity = enableMCPIdentity;
|
|
|
41
41
|
exports.createMCPMiddleware = createMCPMiddleware;
|
|
42
42
|
const crypto = __importStar(require("./crypto"));
|
|
43
43
|
const storage_1 = require("./storage");
|
|
44
|
+
const platform_info_1 = require("./platform-info");
|
|
44
45
|
const transport_1 = require("./transport");
|
|
45
46
|
const logger_1 = require("./logger");
|
|
46
47
|
const rotation_1 = require("./rotation");
|
|
@@ -89,15 +90,19 @@ class MCPIdentity {
|
|
|
89
90
|
this.timestampTolerance = options.timestampTolerance || 60000;
|
|
90
91
|
this.enableNonceTracking = options.enableNonceTracking !== false;
|
|
91
92
|
this.directories = identity.directories || 'verified';
|
|
92
|
-
this.storage =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
this.storage = (typeof options?.storage === 'object' && 'load' in options.storage)
|
|
94
|
+
? options.storage
|
|
95
|
+
: storage_1.StorageFactory.create({
|
|
96
|
+
storage: options.storage,
|
|
97
|
+
customPath: options.persistencePath,
|
|
98
|
+
memoryKey: options.memoryKey || this.did,
|
|
99
|
+
encryptionPassword: options.encryptionPassword
|
|
100
|
+
});
|
|
101
|
+
this.transport = (typeof options?.transport === 'object' && 'post' in options.transport)
|
|
102
|
+
? options.transport
|
|
103
|
+
: transport_1.TransportFactory.create({
|
|
104
|
+
transport: options.transport
|
|
105
|
+
});
|
|
101
106
|
this.precomputed = {
|
|
102
107
|
did: this.did,
|
|
103
108
|
publicKey: this.publicKey,
|
|
@@ -136,12 +141,14 @@ class MCPIdentity {
|
|
|
136
141
|
});
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
|
-
const storage =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
const storage = (typeof options?.storage === 'object' && 'load' in options.storage)
|
|
145
|
+
? options.storage
|
|
146
|
+
: storage_1.StorageFactory.create({
|
|
147
|
+
storage: options?.storage,
|
|
148
|
+
customPath: options?.persistencePath,
|
|
149
|
+
memoryKey: options?.memoryKey,
|
|
150
|
+
encryptionPassword: options?.encryptionPassword
|
|
151
|
+
});
|
|
145
152
|
if (!identity) {
|
|
146
153
|
identity = await storage.load();
|
|
147
154
|
}
|
|
@@ -157,9 +164,11 @@ class MCPIdentity {
|
|
|
157
164
|
return globalIdentity;
|
|
158
165
|
}
|
|
159
166
|
logger.info('No existing identity found, creating new identity...');
|
|
160
|
-
const transport =
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
const transport = (typeof options?.transport === 'object' && 'post' in options.transport)
|
|
168
|
+
? options.transport
|
|
169
|
+
: transport_1.TransportFactory.create({
|
|
170
|
+
transport: options?.transport
|
|
171
|
+
});
|
|
163
172
|
const apiEndpoint = options?.apiEndpoint || 'https://knowthat.ai';
|
|
164
173
|
logger.info('Registering with knowthat.ai...');
|
|
165
174
|
logger.info('Generating cryptographic keys...');
|
|
@@ -201,6 +210,8 @@ class MCPIdentity {
|
|
|
201
210
|
...registrationData,
|
|
202
211
|
apiEndpoint,
|
|
203
212
|
directories: options?.directories,
|
|
213
|
+
processingMode: options?.processingMode,
|
|
214
|
+
registryEndpoint: options?.registryEndpoint,
|
|
204
215
|
onProgress: options?.onProgress
|
|
205
216
|
});
|
|
206
217
|
options?.onProgress?.({
|
|
@@ -566,8 +577,73 @@ function patchMCPServer(identity) {
|
|
|
566
577
|
catch (error) {
|
|
567
578
|
}
|
|
568
579
|
}
|
|
580
|
+
function determineEndpoint(options) {
|
|
581
|
+
if (options.registryEndpoint === 'cli')
|
|
582
|
+
return true;
|
|
583
|
+
if (options.registryEndpoint === 'auto-register')
|
|
584
|
+
return false;
|
|
585
|
+
if (options.registryEndpoint === 'auto' || !options.registryEndpoint) {
|
|
586
|
+
if (options.onProgress)
|
|
587
|
+
return true;
|
|
588
|
+
if (options.processingMode === 'sync')
|
|
589
|
+
return true;
|
|
590
|
+
if (process.stdout?.isTTY)
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
async function registerViaCLI(transport, options) {
|
|
596
|
+
const logger = (0, logger_1.getLogger)();
|
|
597
|
+
logger.debug('Using fast CLI registration endpoint');
|
|
598
|
+
const response = await transport.post(`${options.apiEndpoint}/api/agents/cli-register`, {
|
|
599
|
+
name: options.name,
|
|
600
|
+
description: options.description,
|
|
601
|
+
repository: options.repository,
|
|
602
|
+
publicKey: options.publicKey
|
|
603
|
+
}, {
|
|
604
|
+
timeout: 5000,
|
|
605
|
+
headers: {
|
|
606
|
+
'Content-Type': 'application/json',
|
|
607
|
+
'User-Agent': `@kya-os/mcp-i/${(0, platform_info_1.generateClientInfo)().sdkVersion}`
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
logger.debug(`CLI registration completed in ${response.data.responseTime}ms`);
|
|
611
|
+
options.onProgress?.({
|
|
612
|
+
stage: 'registering',
|
|
613
|
+
progress: 80,
|
|
614
|
+
message: 'Registration successful',
|
|
615
|
+
data: {
|
|
616
|
+
did: response.data.did,
|
|
617
|
+
claimUrl: response.data.claimUrl
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
return {
|
|
621
|
+
success: response.data.success,
|
|
622
|
+
did: response.data.did,
|
|
623
|
+
agent: {
|
|
624
|
+
id: response.data.agent.id,
|
|
625
|
+
slug: response.data.agent.slug,
|
|
626
|
+
name: response.data.agent.name,
|
|
627
|
+
url: response.data.agent.url,
|
|
628
|
+
claimUrl: response.data.claimUrl
|
|
629
|
+
},
|
|
630
|
+
keys: response.data.keys || {
|
|
631
|
+
publicKey: options.publicKey || '',
|
|
632
|
+
privateKey: undefined
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
569
636
|
async function autoRegister(transport, options) {
|
|
570
637
|
const logger = (0, logger_1.getLogger)();
|
|
638
|
+
const shouldUseCLI = determineEndpoint(options);
|
|
639
|
+
if (shouldUseCLI) {
|
|
640
|
+
try {
|
|
641
|
+
return await registerViaCLI(transport, options);
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
logger.debug(`CLI registration failed: ${error.message}, falling back to auto-register`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
571
647
|
try {
|
|
572
648
|
const requestBody = {
|
|
573
649
|
metadata: {
|
|
@@ -579,18 +655,19 @@ async function autoRegister(transport, options) {
|
|
|
579
655
|
isDraft: options.isDraft,
|
|
580
656
|
directories: options.directories || 'verified'
|
|
581
657
|
},
|
|
582
|
-
clientInfo: {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
658
|
+
clientInfo: (0, platform_info_1.generateClientInfo)({
|
|
659
|
+
processingMode: options.processingMode === 'auto' ? undefined : options.processingMode,
|
|
660
|
+
customMetadata: {
|
|
661
|
+
source: 'auto-register'
|
|
662
|
+
}
|
|
663
|
+
})
|
|
587
664
|
};
|
|
588
665
|
logger.debug('Sending registration request to:', `${options.apiEndpoint}/api/agents/auto-register`);
|
|
589
666
|
const response = await transport.post(`${options.apiEndpoint}/api/agents/auto-register`, requestBody, {
|
|
590
667
|
timeout: 30000,
|
|
591
668
|
headers: {
|
|
592
669
|
'Content-Type': 'application/json',
|
|
593
|
-
'User-Agent':
|
|
670
|
+
'User-Agent': `@kya-os/mcp-i/${requestBody.clientInfo.sdkVersion}`
|
|
594
671
|
}
|
|
595
672
|
});
|
|
596
673
|
logger.debug('Registration response received:', {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface ClientInfo {
|
|
2
|
+
sdkVersion: string;
|
|
3
|
+
language: string;
|
|
4
|
+
platform: string;
|
|
5
|
+
runtime?: {
|
|
6
|
+
name: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
environment?: string;
|
|
9
|
+
};
|
|
10
|
+
processingMode?: 'sync' | 'async';
|
|
11
|
+
metadata?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export interface PlatformInfo {
|
|
14
|
+
platform: string;
|
|
15
|
+
runtime: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
environment?: string;
|
|
18
|
+
capabilities: {
|
|
19
|
+
fileSystem: boolean;
|
|
20
|
+
asyncRuntime: boolean;
|
|
21
|
+
persistentStorage: boolean;
|
|
22
|
+
longRunning: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function detectPlatform(): PlatformInfo;
|
|
26
|
+
export declare function generateClientInfo(options?: {
|
|
27
|
+
processingMode?: 'sync' | 'async';
|
|
28
|
+
customMetadata?: Record<string, any>;
|
|
29
|
+
}): ClientInfo;
|
|
30
|
+
export declare function getPlatformRecommendations(platformInfo?: PlatformInfo): {
|
|
31
|
+
storage: "file" | "memory" | "auto";
|
|
32
|
+
transport: "fetch" | "axios" | "auto";
|
|
33
|
+
processingMode: "sync" | "async";
|
|
34
|
+
logLevel: "debug" | "info" | "warn" | "error" | "silent";
|
|
35
|
+
};
|
|
36
|
+
export declare function getCachedPlatformInfo(): PlatformInfo;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.detectPlatform = detectPlatform;
|
|
37
|
+
exports.generateClientInfo = generateClientInfo;
|
|
38
|
+
exports.getPlatformRecommendations = getPlatformRecommendations;
|
|
39
|
+
exports.getCachedPlatformInfo = getCachedPlatformInfo;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
function getSdkVersion() {
|
|
43
|
+
try {
|
|
44
|
+
const strategies = [
|
|
45
|
+
() => {
|
|
46
|
+
if (typeof require !== 'undefined') {
|
|
47
|
+
try {
|
|
48
|
+
return require('../package.json').version;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
const packagePath = path.join(process.cwd(), 'node_modules', '@kya-os', 'mcp-i', 'package.json');
|
|
52
|
+
if (fs.existsSync(packagePath)) {
|
|
53
|
+
return JSON.parse(fs.readFileSync(packagePath, 'utf-8')).version;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw new Error('require not available');
|
|
58
|
+
},
|
|
59
|
+
() => {
|
|
60
|
+
const possiblePaths = [
|
|
61
|
+
path.join(__dirname, '..', 'package.json'),
|
|
62
|
+
path.join(__dirname, '..', '..', 'package.json'),
|
|
63
|
+
path.join(process.cwd(), 'packages', 'mcp-i', 'package.json')
|
|
64
|
+
];
|
|
65
|
+
for (const packagePath of possiblePaths) {
|
|
66
|
+
if (fs.existsSync(packagePath)) {
|
|
67
|
+
return JSON.parse(fs.readFileSync(packagePath, 'utf-8')).version;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error('package.json not found');
|
|
71
|
+
},
|
|
72
|
+
() => '0.1.0-alpha.3.6'
|
|
73
|
+
];
|
|
74
|
+
for (const strategy of strategies) {
|
|
75
|
+
try {
|
|
76
|
+
return strategy();
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
}
|
|
84
|
+
return '0.1.0';
|
|
85
|
+
}
|
|
86
|
+
function detectPlatform() {
|
|
87
|
+
try {
|
|
88
|
+
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
|
|
89
|
+
return {
|
|
90
|
+
platform: 'browser',
|
|
91
|
+
runtime: 'browser',
|
|
92
|
+
capabilities: {
|
|
93
|
+
fileSystem: false,
|
|
94
|
+
asyncRuntime: true,
|
|
95
|
+
persistentStorage: true,
|
|
96
|
+
longRunning: false
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
}
|
|
103
|
+
if (typeof Deno !== 'undefined') {
|
|
104
|
+
return {
|
|
105
|
+
platform: 'deno',
|
|
106
|
+
runtime: 'deno',
|
|
107
|
+
version: Deno.version?.deno,
|
|
108
|
+
capabilities: {
|
|
109
|
+
fileSystem: true,
|
|
110
|
+
asyncRuntime: true,
|
|
111
|
+
persistentStorage: true,
|
|
112
|
+
longRunning: true
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (typeof Bun !== 'undefined') {
|
|
117
|
+
return {
|
|
118
|
+
platform: 'bun',
|
|
119
|
+
runtime: 'bun',
|
|
120
|
+
version: Bun.version,
|
|
121
|
+
capabilities: {
|
|
122
|
+
fileSystem: true,
|
|
123
|
+
asyncRuntime: true,
|
|
124
|
+
persistentStorage: true,
|
|
125
|
+
longRunning: true
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
130
|
+
let environment;
|
|
131
|
+
if (process.env.VERCEL_EDGE || process.env.EDGE_RUNTIME) {
|
|
132
|
+
return {
|
|
133
|
+
platform: 'edge-light',
|
|
134
|
+
runtime: 'vercel-edge',
|
|
135
|
+
version: process.versions.node,
|
|
136
|
+
environment: 'vercel',
|
|
137
|
+
capabilities: {
|
|
138
|
+
fileSystem: false,
|
|
139
|
+
asyncRuntime: true,
|
|
140
|
+
persistentStorage: false,
|
|
141
|
+
longRunning: false
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (process.env.CF_WORKERS || (typeof globalThis !== 'undefined' && globalThis.caches)) {
|
|
146
|
+
return {
|
|
147
|
+
platform: 'edge-light',
|
|
148
|
+
runtime: 'cloudflare-workers',
|
|
149
|
+
environment: 'cloudflare',
|
|
150
|
+
capabilities: {
|
|
151
|
+
fileSystem: false,
|
|
152
|
+
asyncRuntime: true,
|
|
153
|
+
persistentStorage: true,
|
|
154
|
+
longRunning: false
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.LAMBDA_TASK_ROOT) {
|
|
159
|
+
environment = 'lambda';
|
|
160
|
+
return {
|
|
161
|
+
platform: 'node',
|
|
162
|
+
runtime: 'node',
|
|
163
|
+
version: process.versions.node,
|
|
164
|
+
environment,
|
|
165
|
+
capabilities: {
|
|
166
|
+
fileSystem: true,
|
|
167
|
+
asyncRuntime: true,
|
|
168
|
+
persistentStorage: false,
|
|
169
|
+
longRunning: false
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (process.env.VERCEL && !process.env.VERCEL_EDGE) {
|
|
174
|
+
environment = 'vercel-functions';
|
|
175
|
+
}
|
|
176
|
+
if (process.env.NETLIFY) {
|
|
177
|
+
environment = 'netlify-functions';
|
|
178
|
+
}
|
|
179
|
+
if (process.env.DOCKER_CONTAINER) {
|
|
180
|
+
environment = 'docker';
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
try {
|
|
184
|
+
if (fs.existsSync('/proc/1/cgroup') && fs.readFileSync('/proc/1/cgroup', 'utf-8').includes('docker')) {
|
|
185
|
+
environment = 'docker';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (process.env.NEXT_RUNTIME) {
|
|
192
|
+
environment = `nextjs-${process.env.NEXT_RUNTIME}`;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
platform: 'node',
|
|
196
|
+
runtime: 'node',
|
|
197
|
+
version: process.versions.node,
|
|
198
|
+
environment,
|
|
199
|
+
capabilities: {
|
|
200
|
+
fileSystem: true,
|
|
201
|
+
asyncRuntime: true,
|
|
202
|
+
persistentStorage: true,
|
|
203
|
+
longRunning: environment !== 'lambda' && environment !== 'vercel-functions'
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
platform: 'unknown',
|
|
209
|
+
runtime: 'unknown',
|
|
210
|
+
capabilities: {
|
|
211
|
+
fileSystem: false,
|
|
212
|
+
asyncRuntime: true,
|
|
213
|
+
persistentStorage: false,
|
|
214
|
+
longRunning: false
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function generateClientInfo(options) {
|
|
219
|
+
const platformInfo = detectPlatform();
|
|
220
|
+
const sdkVersion = getSdkVersion();
|
|
221
|
+
let defaultProcessingMode = 'sync';
|
|
222
|
+
if (!platformInfo.capabilities.longRunning || platformInfo.platform === 'edge-light') {
|
|
223
|
+
defaultProcessingMode = 'async';
|
|
224
|
+
}
|
|
225
|
+
const clientInfo = {
|
|
226
|
+
sdkVersion,
|
|
227
|
+
language: 'javascript',
|
|
228
|
+
platform: platformInfo.platform,
|
|
229
|
+
processingMode: options?.processingMode || defaultProcessingMode
|
|
230
|
+
};
|
|
231
|
+
if (platformInfo.runtime !== platformInfo.platform) {
|
|
232
|
+
clientInfo.runtime = {
|
|
233
|
+
name: platformInfo.runtime,
|
|
234
|
+
version: platformInfo.version,
|
|
235
|
+
environment: platformInfo.environment
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
if (options?.customMetadata) {
|
|
239
|
+
clientInfo.metadata = options.customMetadata;
|
|
240
|
+
}
|
|
241
|
+
return clientInfo;
|
|
242
|
+
}
|
|
243
|
+
function getPlatformRecommendations(platformInfo) {
|
|
244
|
+
const info = platformInfo || detectPlatform();
|
|
245
|
+
const recommendations = {
|
|
246
|
+
storage: 'auto',
|
|
247
|
+
transport: 'auto',
|
|
248
|
+
processingMode: 'sync',
|
|
249
|
+
logLevel: 'info'
|
|
250
|
+
};
|
|
251
|
+
if (!info.capabilities.fileSystem || !info.capabilities.persistentStorage) {
|
|
252
|
+
recommendations.storage = 'memory';
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
recommendations.storage = 'file';
|
|
256
|
+
}
|
|
257
|
+
if (info.platform === 'edge-light' || info.platform === 'browser') {
|
|
258
|
+
recommendations.transport = 'fetch';
|
|
259
|
+
}
|
|
260
|
+
if (!info.capabilities.longRunning) {
|
|
261
|
+
recommendations.processingMode = 'async';
|
|
262
|
+
}
|
|
263
|
+
if (info.environment === 'lambda' || info.platform === 'edge-light') {
|
|
264
|
+
recommendations.logLevel = 'error';
|
|
265
|
+
}
|
|
266
|
+
return recommendations;
|
|
267
|
+
}
|
|
268
|
+
let cachedPlatformInfo = null;
|
|
269
|
+
function getCachedPlatformInfo() {
|
|
270
|
+
if (!cachedPlatformInfo) {
|
|
271
|
+
cachedPlatformInfo = detectPlatform();
|
|
272
|
+
}
|
|
273
|
+
return cachedPlatformInfo;
|
|
274
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { RegistryAdapter, RegistryPublishData, RegistryPublishResult, RegistryStatus } from '../types';
|
|
1
|
+
import { RegistryAdapter, RegistryPublishData, RegistryPublishResult, RegistryStatus, MCPIdentityOptions } from '../types';
|
|
2
2
|
import { Transport } from '../transport';
|
|
3
3
|
export declare class KnowThatRegistry implements RegistryAdapter {
|
|
4
4
|
name: string;
|
|
5
5
|
type: 'primary' | 'secondary';
|
|
6
6
|
private endpoint;
|
|
7
7
|
private transport;
|
|
8
|
-
|
|
8
|
+
private options?;
|
|
9
|
+
constructor(endpoint?: string, transport?: Transport, options?: MCPIdentityOptions);
|
|
10
|
+
private publishViaCLI;
|
|
11
|
+
private shouldUseCLIEndpoint;
|
|
9
12
|
publish(data: RegistryPublishData): Promise<RegistryPublishResult>;
|
|
13
|
+
private publishViaAutoRegister;
|
|
10
14
|
verify(did: string): Promise<boolean>;
|
|
11
15
|
getStatus(did: string): Promise<RegistryStatus>;
|
|
12
16
|
private extractAgentSlug;
|
|
@@ -4,16 +4,89 @@ exports.KnowThatRegistry = void 0;
|
|
|
4
4
|
const transport_1 = require("../transport");
|
|
5
5
|
const polling_1 = require("../polling");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
|
+
const platform_info_1 = require("../platform-info");
|
|
7
8
|
class KnowThatRegistry {
|
|
8
|
-
constructor(endpoint = 'https://knowthat.ai', transport) {
|
|
9
|
+
constructor(endpoint = 'https://knowthat.ai', transport, options) {
|
|
9
10
|
this.name = 'knowthat';
|
|
10
11
|
this.type = 'primary';
|
|
11
12
|
this.endpoint = endpoint;
|
|
12
13
|
this.transport = transport || transport_1.TransportFactory.create();
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
async publishViaCLI(data) {
|
|
17
|
+
const logger = (0, logger_1.getLogger)();
|
|
18
|
+
try {
|
|
19
|
+
logger.debug('Using fast CLI registration endpoint');
|
|
20
|
+
const response = await this.transport.post(`${this.endpoint}/api/agents/cli-register`, {
|
|
21
|
+
name: data.name,
|
|
22
|
+
description: data.description,
|
|
23
|
+
repository: data.repository,
|
|
24
|
+
publicKey: data.publicKey
|
|
25
|
+
}, {
|
|
26
|
+
timeout: 5000,
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'User-Agent': `@kya-os/mcp-i/${(0, platform_info_1.generateClientInfo)().sdkVersion}`
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
logger.debug(`CLI registration completed in ${response.data.responseTime}ms`);
|
|
33
|
+
if (response.data.keys && !data.publicKey) {
|
|
34
|
+
logger.warn(response.data.keys.warning || 'Server generated keys - store them securely!');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
success: true,
|
|
38
|
+
registryAgentId: response.data.agent.id,
|
|
39
|
+
profileUrl: response.data.agent.url,
|
|
40
|
+
claimUrl: response.data.claimUrl,
|
|
41
|
+
claimToken: response.data.claimToken,
|
|
42
|
+
generatedKeys: response.data.keys
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
logger.debug(`CLI registration failed: ${error.message}`);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
shouldUseCLIEndpoint() {
|
|
51
|
+
if (this.options?.registryEndpoint === 'cli')
|
|
52
|
+
return true;
|
|
53
|
+
if (this.options?.registryEndpoint === 'auto-register')
|
|
54
|
+
return false;
|
|
55
|
+
if (this.options?.registryEndpoint === 'auto' || !this.options?.registryEndpoint) {
|
|
56
|
+
if (this.options?.onProgress)
|
|
57
|
+
return true;
|
|
58
|
+
if (this.options?.processingMode === 'sync')
|
|
59
|
+
return true;
|
|
60
|
+
if (process.stdout?.isTTY)
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
13
64
|
}
|
|
14
65
|
async publish(data) {
|
|
66
|
+
const logger = (0, logger_1.getLogger)();
|
|
67
|
+
const useCLI = this.shouldUseCLIEndpoint();
|
|
68
|
+
if (useCLI) {
|
|
69
|
+
try {
|
|
70
|
+
return await this.publishViaCLI(data);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger.debug('CLI endpoint failed, falling back to auto-register');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return await this.publishViaAutoRegister(data);
|
|
77
|
+
}
|
|
78
|
+
async publishViaAutoRegister(data) {
|
|
15
79
|
const logger = (0, logger_1.getLogger)();
|
|
16
80
|
try {
|
|
81
|
+
const clientInfo = (0, platform_info_1.generateClientInfo)({
|
|
82
|
+
processingMode: this.options?.processingMode === 'auto'
|
|
83
|
+
? undefined
|
|
84
|
+
: this.options?.processingMode || 'sync',
|
|
85
|
+
customMetadata: {
|
|
86
|
+
source: 'mcp-i-sdk'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
logger.debug(`Generated client info: ${JSON.stringify(clientInfo)}`);
|
|
17
90
|
const response = await this.transport.post(`${this.endpoint}/api/agents/auto-register`, {
|
|
18
91
|
metadata: {
|
|
19
92
|
name: data.name,
|
|
@@ -21,19 +94,17 @@ class KnowThatRegistry {
|
|
|
21
94
|
repository: data.repository,
|
|
22
95
|
version: '1.0.0'
|
|
23
96
|
},
|
|
24
|
-
clientInfo
|
|
25
|
-
sdkVersion: '0.2.0',
|
|
26
|
-
language: 'typescript',
|
|
27
|
-
platform: 'node'
|
|
28
|
-
},
|
|
97
|
+
clientInfo,
|
|
29
98
|
publicKey: data.publicKey || undefined
|
|
30
99
|
}, {
|
|
31
100
|
timeout: 30000,
|
|
32
101
|
headers: {
|
|
33
102
|
'Content-Type': 'application/json',
|
|
34
|
-
'User-Agent':
|
|
103
|
+
'User-Agent': `@kya-os/mcp-i/${clientInfo.sdkVersion}`
|
|
35
104
|
}
|
|
36
105
|
});
|
|
106
|
+
logger.debug(`Registration response status: ${response.status}`);
|
|
107
|
+
logger.debug(`Registration response data: ${JSON.stringify(response.data, null, 2)}`);
|
|
37
108
|
if (response.status === 202 && (0, polling_1.isAsyncRegistrationResponse)(response.data)) {
|
|
38
109
|
logger.debug('Got async registration response, polling for completion...');
|
|
39
110
|
const result = await (0, polling_1.pollRegistrationStatus)(response.data.status, this.transport, {
|