meshsig 0.5.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/LICENSE +21 -0
- package/README.md +276 -0
- package/dist/crypto.d.ts +43 -0
- package/dist/crypto.js +108 -0
- package/dist/crypto.js.map +1 -0
- package/dist/dashboard.html +635 -0
- package/dist/demo.d.ts +2 -0
- package/dist/demo.js +107 -0
- package/dist/demo.js.map +1 -0
- package/dist/discovery.d.ts +24 -0
- package/dist/discovery.js +119 -0
- package/dist/discovery.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +459 -0
- package/dist/main.js.map +1 -0
- package/dist/peers.d.ts +35 -0
- package/dist/peers.js +227 -0
- package/dist/peers.js.map +1 -0
- package/dist/registry.d.ts +85 -0
- package/dist/registry.js +311 -0
- package/dist/registry.js.map +1 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.js +433 -0
- package/dist/server.js.map +1 -0
- package/dist/terminal.d.ts +17 -0
- package/dist/terminal.js +175 -0
- package/dist/terminal.js.map +1 -0
- package/package.json +51 -0
- package/scripts/install.sh +271 -0
- package/scripts/invoke-mesh.sh +190 -0
- package/scripts/register-agent.sh +89 -0
- package/scripts/uninstall.sh +25 -0
- package/scripts/unregister-agent.sh +23 -0
package/dist/demo.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// MeshSig Demo — Creates agents, connections, and live interactions.
|
|
3
|
+
// The "wow moment" — watch your network come alive.
|
|
4
|
+
// ============================================================================
|
|
5
|
+
const DEMO_AGENTS = [
|
|
6
|
+
{ name: 'Arlo', capabilities: [{ type: 'orchestration', confidence: 0.95 }, { type: 'strategy', confidence: 0.9 }] },
|
|
7
|
+
{ name: 'Vera', capabilities: [{ type: 'data-analysis', confidence: 0.93 }, { type: 'market-research', confidence: 0.85 }] },
|
|
8
|
+
{ name: 'Rex', capabilities: [{ type: 'code-review', confidence: 0.97 }, { type: 'qa', confidence: 0.88 }] },
|
|
9
|
+
{ name: 'Mia', capabilities: [{ type: 'writing', confidence: 0.92 }, { type: 'market-research', confidence: 0.9 }] },
|
|
10
|
+
{ name: 'Cipher', capabilities: [{ type: 'data-analysis', confidence: 0.96 }] },
|
|
11
|
+
{ name: 'Forge', capabilities: [{ type: 'code-review', confidence: 0.91 }, { type: 'strategy', confidence: 0.82 }] },
|
|
12
|
+
];
|
|
13
|
+
const DEMO_MESSAGES = [
|
|
14
|
+
{ from: 'Arlo', to: 'Vera', msg: 'Need Q1 market analysis for AI agents in LATAM' },
|
|
15
|
+
{ from: 'Vera', to: 'Arlo', msg: 'Starting analysis. Pulling data from 47 sources.' },
|
|
16
|
+
{ from: 'Arlo', to: 'Mia', msg: 'Draft executive summary once Vera delivers data' },
|
|
17
|
+
{ from: 'Mia', to: 'Arlo', msg: 'Ready. Waiting for data handoff from Vera.' },
|
|
18
|
+
{ from: 'Vera', to: 'Cipher', msg: 'Cross-check these funding numbers — some outliers detected' },
|
|
19
|
+
{ from: 'Cipher', to: 'Vera', msg: 'Confirmed. 3 data points were stale. Updated dataset attached.' },
|
|
20
|
+
{ from: 'Vera', to: 'Mia', msg: 'Analysis complete. 23 companies, 5 trends identified.' },
|
|
21
|
+
{ from: 'Mia', to: 'Rex', msg: 'Draft ready. Review for accuracy and formatting.' },
|
|
22
|
+
{ from: 'Rex', to: 'Mia', msg: 'Two factual corrections and formatting fixes applied.' },
|
|
23
|
+
{ from: 'Mia', to: 'Arlo', msg: 'Final report ready. 12 pages, reviewed and verified.' },
|
|
24
|
+
{ from: 'Arlo', to: 'Forge', msg: 'Package the report as API response for client dashboard' },
|
|
25
|
+
{ from: 'Forge', to: 'Arlo', msg: 'Done. Endpoint live, authentication configured.' },
|
|
26
|
+
{ from: 'Arlo', to: 'Vera', msg: 'New task: monitor competitor pricing changes daily' },
|
|
27
|
+
{ from: 'Rex', to: 'Forge', msg: 'Code review on dashboard endpoint — approved, clean.' },
|
|
28
|
+
{ from: 'Cipher', to: 'Arlo', msg: 'Anomaly detected in dataset #7. Flagging for review.' },
|
|
29
|
+
{ from: 'Arlo', to: 'Cipher', msg: 'Good catch. Route to Vera for deep analysis.' },
|
|
30
|
+
];
|
|
31
|
+
export async function runDemo(server) {
|
|
32
|
+
const agents = new Map();
|
|
33
|
+
const identities = new Map();
|
|
34
|
+
// Phase 1: Register agents one by one with delay
|
|
35
|
+
console.log(' Starting demo...\n');
|
|
36
|
+
for (let i = 0; i < DEMO_AGENTS.length; i++) {
|
|
37
|
+
const agent = DEMO_AGENTS[i];
|
|
38
|
+
await sleep(1500);
|
|
39
|
+
const { identity } = await server.registry.registerAgent(agent.name, agent.capabilities);
|
|
40
|
+
agent.identity = identity;
|
|
41
|
+
agents.set(agent.name, agent);
|
|
42
|
+
identities.set(agent.name, identity);
|
|
43
|
+
const caps = agent.capabilities.map(c => c.type).join(', ');
|
|
44
|
+
console.log(` 🟢 ${agent.name} joined — ${caps}`);
|
|
45
|
+
}
|
|
46
|
+
console.log(`\n ${DEMO_AGENTS.length} agents in the mesh. Forming connections...\n`);
|
|
47
|
+
await sleep(2000);
|
|
48
|
+
// Phase 2: Create connections with handshakes
|
|
49
|
+
const connectionPairs = [
|
|
50
|
+
['Arlo', 'Vera'], ['Arlo', 'Mia'], ['Arlo', 'Rex'], ['Arlo', 'Forge'],
|
|
51
|
+
['Vera', 'Cipher'], ['Vera', 'Mia'], ['Mia', 'Rex'], ['Rex', 'Forge'],
|
|
52
|
+
['Cipher', 'Arlo'],
|
|
53
|
+
];
|
|
54
|
+
for (const [a, b] of connectionPairs) {
|
|
55
|
+
await sleep(800);
|
|
56
|
+
const idA = identities.get(a);
|
|
57
|
+
const idB = identities.get(b);
|
|
58
|
+
// Emit handshake event manually for the dashboard
|
|
59
|
+
server.registry.emit('mesh-event', {
|
|
60
|
+
type: 'handshake:verify',
|
|
61
|
+
timestamp: new Date().toISOString(),
|
|
62
|
+
data: { fromDid: idA.did, toDid: idB.did, fromName: a, toName: b },
|
|
63
|
+
});
|
|
64
|
+
await sleep(400);
|
|
65
|
+
server.registry.createConnection(idA.did, idB.did);
|
|
66
|
+
console.log(` 🔗 ${a} ↔ ${b} — verified handshake`);
|
|
67
|
+
}
|
|
68
|
+
console.log(`\n ${connectionPairs.length} connections established. Messages flowing...\n`);
|
|
69
|
+
await sleep(2000);
|
|
70
|
+
// Phase 3: Simulate messages
|
|
71
|
+
for (const msg of DEMO_MESSAGES) {
|
|
72
|
+
await sleep(2000 + Math.random() * 2000);
|
|
73
|
+
const fromId = identities.get(msg.from);
|
|
74
|
+
const toId = identities.get(msg.to);
|
|
75
|
+
const { sign } = await import('./crypto.js');
|
|
76
|
+
const ts = new Date().toISOString();
|
|
77
|
+
const sig = await sign(`${msg.msg}|${ts}`, fromId.privateKey);
|
|
78
|
+
server.registry.logMessage(fromId.did, toId.did, msg.msg, sig, true);
|
|
79
|
+
console.log(` 💬 ${msg.from} → ${msg.to}: "${msg.msg}"`);
|
|
80
|
+
}
|
|
81
|
+
console.log('\n Demo messages complete. Network is alive.\n');
|
|
82
|
+
console.log(' The mesh continues running. Open the dashboard to watch.');
|
|
83
|
+
console.log(' Register new agents via the API. Connect more VPS instances.');
|
|
84
|
+
console.log(' The graph grows.\n');
|
|
85
|
+
// Phase 4: Keep alive with periodic heartbeats
|
|
86
|
+
setInterval(async () => {
|
|
87
|
+
for (const [name, id] of identities) {
|
|
88
|
+
server.registry.touchAgent(id.did);
|
|
89
|
+
}
|
|
90
|
+
}, 30000);
|
|
91
|
+
// Phase 5: Periodic random messages to keep it alive
|
|
92
|
+
setInterval(async () => {
|
|
93
|
+
const msg = DEMO_MESSAGES[Math.floor(Math.random() * DEMO_MESSAGES.length)];
|
|
94
|
+
const fromId = identities.get(msg.from);
|
|
95
|
+
const toId = identities.get(msg.to);
|
|
96
|
+
if (!fromId || !toId)
|
|
97
|
+
return;
|
|
98
|
+
const { sign } = await import('./crypto.js');
|
|
99
|
+
const ts = new Date().toISOString();
|
|
100
|
+
const sig = await sign(`${msg.msg}|${ts}`, fromId.privateKey);
|
|
101
|
+
server.registry.logMessage(fromId.did, toId.did, msg.msg, sig, true);
|
|
102
|
+
}, 8000 + Math.random() * 7000);
|
|
103
|
+
}
|
|
104
|
+
function sleep(ms) {
|
|
105
|
+
return new Promise(r => setTimeout(r, ms));
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=demo.js.map
|
package/dist/demo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,qEAAqE;AACrE,oDAAoD;AACpD,+EAA+E;AAW/E,MAAM,WAAW,GAAgB;IAC/B,EAAE,IAAI,EAAE,MAAM,EAAI,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE;IACtH,EAAE,IAAI,EAAE,MAAM,EAAI,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE;IAC9H,EAAE,IAAI,EAAE,KAAK,EAAK,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE;IAC/G,EAAE,IAAI,EAAE,KAAK,EAAK,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE;I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AAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
export interface DiscoveredPeer {
|
|
3
|
+
address: string;
|
|
4
|
+
port: number;
|
|
5
|
+
name: string;
|
|
6
|
+
agentCount: number;
|
|
7
|
+
firstSeen: string;
|
|
8
|
+
lastSeen: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class AutoDiscovery extends EventEmitter {
|
|
11
|
+
private socket;
|
|
12
|
+
private broadcastTimer;
|
|
13
|
+
private peers;
|
|
14
|
+
private serverName;
|
|
15
|
+
private serverPort;
|
|
16
|
+
private agentCount;
|
|
17
|
+
constructor(serverName: string, serverPort: number);
|
|
18
|
+
start(): void;
|
|
19
|
+
stop(): void;
|
|
20
|
+
setAgentCount(count: number): void;
|
|
21
|
+
getDiscoveredPeers(): DiscoveredPeer[];
|
|
22
|
+
private _broadcast;
|
|
23
|
+
private _handleMessage;
|
|
24
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// MeshSig — Auto-Discovery
|
|
3
|
+
// Find other MeshSig instances on the local network via UDP broadcast.
|
|
4
|
+
// No manual configuration needed on the same LAN.
|
|
5
|
+
// ============================================================================
|
|
6
|
+
import { createSocket } from 'node:dgram';
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
|
+
const DISCOVERY_PORT = 4889;
|
|
9
|
+
const BROADCAST_INTERVAL = 5000;
|
|
10
|
+
const MAGIC = 'MESHSIG';
|
|
11
|
+
export class AutoDiscovery extends EventEmitter {
|
|
12
|
+
socket = null;
|
|
13
|
+
broadcastTimer = null;
|
|
14
|
+
peers = new Map();
|
|
15
|
+
serverName;
|
|
16
|
+
serverPort;
|
|
17
|
+
agentCount = 0;
|
|
18
|
+
constructor(serverName, serverPort) {
|
|
19
|
+
super();
|
|
20
|
+
this.serverName = serverName;
|
|
21
|
+
this.serverPort = serverPort;
|
|
22
|
+
}
|
|
23
|
+
start() {
|
|
24
|
+
try {
|
|
25
|
+
this.socket = createSocket({ type: 'udp4', reuseAddr: true });
|
|
26
|
+
this.socket.on('message', (msg, rinfo) => {
|
|
27
|
+
this._handleMessage(msg, rinfo);
|
|
28
|
+
});
|
|
29
|
+
this.socket.on('error', () => {
|
|
30
|
+
// Discovery is best-effort, don't crash on errors
|
|
31
|
+
});
|
|
32
|
+
this.socket.bind(DISCOVERY_PORT, () => {
|
|
33
|
+
this.socket.setBroadcast(true);
|
|
34
|
+
// Start periodic broadcast
|
|
35
|
+
this.broadcastTimer = setInterval(() => this._broadcast(), BROADCAST_INTERVAL);
|
|
36
|
+
this._broadcast(); // Send immediately
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Discovery is optional — if UDP doesn't work, that's fine
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
stop() {
|
|
44
|
+
if (this.broadcastTimer)
|
|
45
|
+
clearInterval(this.broadcastTimer);
|
|
46
|
+
if (this.socket) {
|
|
47
|
+
try {
|
|
48
|
+
this.socket.close();
|
|
49
|
+
}
|
|
50
|
+
catch { }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
setAgentCount(count) {
|
|
54
|
+
this.agentCount = count;
|
|
55
|
+
}
|
|
56
|
+
getDiscoveredPeers() {
|
|
57
|
+
// Filter out peers not seen in last 15 seconds
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
const alive = [];
|
|
60
|
+
for (const [key, peer] of this.peers) {
|
|
61
|
+
if (now - new Date(peer.lastSeen).getTime() < 15_000) {
|
|
62
|
+
alive.push(peer);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.peers.delete(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return alive;
|
|
69
|
+
}
|
|
70
|
+
_broadcast() {
|
|
71
|
+
if (!this.socket)
|
|
72
|
+
return;
|
|
73
|
+
const msg = Buffer.from(JSON.stringify({
|
|
74
|
+
magic: MAGIC,
|
|
75
|
+
name: this.serverName,
|
|
76
|
+
port: this.serverPort,
|
|
77
|
+
agents: this.agentCount,
|
|
78
|
+
timestamp: new Date().toISOString(),
|
|
79
|
+
}));
|
|
80
|
+
try {
|
|
81
|
+
this.socket.send(msg, 0, msg.length, DISCOVERY_PORT, '255.255.255.255');
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Best effort
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
_handleMessage(msg, rinfo) {
|
|
88
|
+
try {
|
|
89
|
+
const data = JSON.parse(msg.toString());
|
|
90
|
+
if (data.magic !== MAGIC)
|
|
91
|
+
return;
|
|
92
|
+
if (data.name === this.serverName)
|
|
93
|
+
return; // Ignore self
|
|
94
|
+
const key = `${rinfo.address}:${data.port}`;
|
|
95
|
+
const now = new Date().toISOString();
|
|
96
|
+
const existing = this.peers.get(key);
|
|
97
|
+
if (existing) {
|
|
98
|
+
existing.lastSeen = now;
|
|
99
|
+
existing.agentCount = data.agents;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const peer = {
|
|
103
|
+
address: rinfo.address,
|
|
104
|
+
port: data.port,
|
|
105
|
+
name: data.name,
|
|
106
|
+
agentCount: data.agents,
|
|
107
|
+
firstSeen: now,
|
|
108
|
+
lastSeen: now,
|
|
109
|
+
};
|
|
110
|
+
this.peers.set(key, peer);
|
|
111
|
+
this.emit('discovered', peer);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Ignore malformed messages
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2BAA2B;AAC3B,uEAAuE;AACvE,kDAAkD;AAClD,+EAA+E;AAE/E,OAAO,EAAE,YAAY,EAAU,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,KAAK,GAAG,SAAS,CAAC;AAWxB,MAAM,OAAO,aAAc,SAAQ,YAAY;IACrC,MAAM,GAAkB,IAAI,CAAC;IAC7B,cAAc,GAA0C,IAAI,CAAC;IAC7D,KAAK,GAAgC,IAAI,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAS;IACnB,UAAU,CAAS;IACnB,UAAU,GAAW,CAAC,CAAC;IAE/B,YAAY,UAAkB,EAAE,UAAkB;QAChD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAE9D,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBACvC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBAC3B,kD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C;YACpC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAmB;oBAC3B,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,UAAU,EAAE,IAAI,CAAC,MAAM;oBACvB,SAAS,EAAE,GAAG;oBACd,QAAQ,EAAE,GAAG;iBACd,CAAC;gBACF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;gBAE1B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MeshServer } from './server.js';
|
|
2
|
+
export { Registry } from './registry.js';
|
|
3
|
+
export { PeerNetwork } from './peers.js';
|
|
4
|
+
export { AutoDiscovery } from './discovery.js';
|
|
5
|
+
export { TerminalDisplay } from './terminal.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,cAAc,aAAa,CAAC"}
|
package/dist/main.d.ts
ADDED