@contextvm/sdk 0.1.15 → 0.1.17
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/dist/esm/relay/applesauce-relay-pool.d.ts +35 -0
- package/dist/esm/relay/applesauce-relay-pool.d.ts.map +1 -0
- package/dist/esm/relay/applesauce-relay-pool.js +172 -0
- package/dist/esm/relay/applesauce-relay-pool.js.map +1 -0
- package/dist/esm/relay/index.d.ts +1 -0
- package/dist/esm/relay/index.d.ts.map +1 -1
- package/dist/esm/relay/index.js +1 -0
- package/dist/esm/relay/index.js.map +1 -1
- package/dist/esm/relay/nostrify-relay-pool.d.ts +26 -0
- package/dist/esm/relay/nostrify-relay-pool.d.ts.map +1 -0
- package/dist/esm/relay/nostrify-relay-pool.js +124 -0
- package/dist/esm/relay/nostrify-relay-pool.js.map +1 -0
- package/dist/esm/relay/simple-relay-pool.d.ts +4 -2
- package/dist/esm/relay/simple-relay-pool.d.ts.map +1 -1
- package/dist/esm/relay/simple-relay-pool.js +69 -26
- package/dist/esm/relay/simple-relay-pool.js.map +1 -1
- package/package.json +3 -2
- package/dist/esm/proxy/proxy-server.d.ts +0 -3
- package/dist/esm/proxy/proxy-server.d.ts.map +0 -1
- package/dist/esm/proxy/proxy-server.js +0 -55
- package/dist/esm/proxy/proxy-server.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NostrEvent, Filter } from 'nostr-tools';
|
|
2
|
+
import { RelayHandler } from '../core/interfaces.js';
|
|
3
|
+
/**
|
|
4
|
+
* A RelayHandler implementation that uses the applesauce-relay library's RelayPool to manage connections and subscriptions.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApplesauceRelayPool implements RelayHandler {
|
|
7
|
+
private readonly pool;
|
|
8
|
+
private readonly relayUrls;
|
|
9
|
+
private readonly relayGroup;
|
|
10
|
+
private subscriptions;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new ApplesauceRelayPool instance.
|
|
13
|
+
* @param relayUrls - An array of relay URLs to connect to.
|
|
14
|
+
*/
|
|
15
|
+
constructor(relayUrls: string[]);
|
|
16
|
+
/**
|
|
17
|
+
* Sets up monitoring of relay connections and triggers resubscription when connections are lost
|
|
18
|
+
*/
|
|
19
|
+
private setupConnectionMonitoring;
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
publish(event: NostrEvent): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a simplified subscription wrapper around the RelayPool's subscription method.
|
|
25
|
+
* This provides a cleaner interface similar to other relay pool implementations.
|
|
26
|
+
*/
|
|
27
|
+
private createSubscription;
|
|
28
|
+
/**
|
|
29
|
+
* Resubscribes to all active subscriptions after relay reconnection
|
|
30
|
+
*/
|
|
31
|
+
private resubscribeAll;
|
|
32
|
+
subscribe(filters: Filter[], onEvent: (event: NostrEvent) => void, onEose?: () => void): Promise<void>;
|
|
33
|
+
unsubscribe(): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=applesauce-relay-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applesauce-relay-pool.d.ts","sourceRoot":"","sources":["../../../src/relay/applesauce-relay-pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAerD;;GAEG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IACtD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAGxC,OAAO,CAAC,aAAa,CAA+B;IAEpD;;;OAGG;gBACS,SAAS,EAAE,MAAM,EAAE;IAO/B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAY3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC/C;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAuC1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBhB,SAAS,CACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,IAAI,CAAC;IAoBhB,WAAW,IAAI,IAAI;CAcpB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { RelayPool } from 'applesauce-relay';
|
|
2
|
+
import { createLogger } from '../core/utils/logger.js';
|
|
3
|
+
const logger = createLogger('applesauce-relay');
|
|
4
|
+
/**
|
|
5
|
+
* A RelayHandler implementation that uses the applesauce-relay library's RelayPool to manage connections and subscriptions.
|
|
6
|
+
*/
|
|
7
|
+
export class ApplesauceRelayPool {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new ApplesauceRelayPool instance.
|
|
10
|
+
* @param relayUrls - An array of relay URLs to connect to.
|
|
11
|
+
*/
|
|
12
|
+
constructor(relayUrls) {
|
|
13
|
+
// Subscription management similar to other relay pools
|
|
14
|
+
this.subscriptions = [];
|
|
15
|
+
this.relayUrls = relayUrls;
|
|
16
|
+
this.pool = new RelayPool();
|
|
17
|
+
this.relayGroup = this.pool.group(relayUrls);
|
|
18
|
+
this.setupConnectionMonitoring();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets up monitoring of relay connections and triggers resubscription when connections are lost
|
|
22
|
+
*/
|
|
23
|
+
setupConnectionMonitoring() {
|
|
24
|
+
this.pool.relays$.subscribe((relays) => {
|
|
25
|
+
relays.forEach((relay) => {
|
|
26
|
+
relay.connected$.subscribe((connected) => {
|
|
27
|
+
if (!connected) {
|
|
28
|
+
this.resubscribeAll();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async connect() {
|
|
35
|
+
logger.info('Connecting to relays', { relayUrls: this.relayUrls });
|
|
36
|
+
// Validate URL format
|
|
37
|
+
for (const url of this.relayUrls) {
|
|
38
|
+
try {
|
|
39
|
+
new URL(url);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error('Invalid relay URL', { url, error });
|
|
43
|
+
throw new Error(`Invalid relay URL: ${url}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// The RelayPool automatically connects to relays when needed
|
|
47
|
+
logger.info('Relay pool initialized', { relayUrls: this.relayUrls });
|
|
48
|
+
}
|
|
49
|
+
async disconnect() {
|
|
50
|
+
logger.info('Disconnecting from relays');
|
|
51
|
+
// Close all active subscriptions
|
|
52
|
+
this.unsubscribe();
|
|
53
|
+
// Close the relay pool
|
|
54
|
+
// Note: RelayPool doesn't have a close method, connections are managed automatically
|
|
55
|
+
// We just need to clear our subscriptions
|
|
56
|
+
logger.info('Disconnected from all relays');
|
|
57
|
+
}
|
|
58
|
+
async publish(event) {
|
|
59
|
+
logger.debug('Publishing event', { eventId: event.id, kind: event.kind });
|
|
60
|
+
// Use the publish method which handles retries automatically
|
|
61
|
+
const publishObservable = this.relayGroup.publish(event);
|
|
62
|
+
// Subscribe to the publish observable to handle responses
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const subscription = publishObservable.subscribe({
|
|
65
|
+
next: (response) => {
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
logger.warn('Failed to publish event to relay', {
|
|
68
|
+
eventId: event.id,
|
|
69
|
+
relay: response.from,
|
|
70
|
+
message: response.message,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
error: (error) => {
|
|
75
|
+
logger.error('Failed to publish event', {
|
|
76
|
+
eventId: event.id,
|
|
77
|
+
error,
|
|
78
|
+
});
|
|
79
|
+
reject(error);
|
|
80
|
+
},
|
|
81
|
+
complete: () => {
|
|
82
|
+
logger.debug('Event publishing completed', { eventId: event.id });
|
|
83
|
+
subscription.unsubscribe();
|
|
84
|
+
resolve();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a simplified subscription wrapper around the RelayPool's subscription method.
|
|
91
|
+
* This provides a cleaner interface similar to other relay pool implementations.
|
|
92
|
+
*/
|
|
93
|
+
createSubscription(filters, onEvent, onEose) {
|
|
94
|
+
// Create a persistent subscription with automatic reconnection
|
|
95
|
+
const subscription = this.relayGroup.subscription(filters, {
|
|
96
|
+
retries: 3,
|
|
97
|
+
});
|
|
98
|
+
// Subscribe to the stream of events
|
|
99
|
+
const sub = subscription.subscribe({
|
|
100
|
+
next: (response) => {
|
|
101
|
+
if (response === 'EOSE') {
|
|
102
|
+
onEose === null || onEose === void 0 ? void 0 : onEose();
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
onEvent(response);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
error: (error) => {
|
|
109
|
+
logger.error('Subscription error', { error });
|
|
110
|
+
// Remove the subscription from the array if it fails
|
|
111
|
+
const index = this.subscriptions.findIndex((sub) => sub.onEvent === onEvent && sub.filters === filters);
|
|
112
|
+
if (index !== -1) {
|
|
113
|
+
this.subscriptions.splice(index, 1);
|
|
114
|
+
}
|
|
115
|
+
sub.unsubscribe();
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
unsubscribe: () => {
|
|
120
|
+
sub.unsubscribe();
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resubscribes to all active subscriptions after relay reconnection
|
|
126
|
+
*/
|
|
127
|
+
resubscribeAll() {
|
|
128
|
+
logger.debug('Resubscribing to all subscriptions after relay reconnection');
|
|
129
|
+
try {
|
|
130
|
+
this.subscriptions.forEach((sub) => {
|
|
131
|
+
if (sub.closer)
|
|
132
|
+
sub.closer.unsubscribe();
|
|
133
|
+
sub.closer = this.createSubscription(sub.filters, sub.onEvent, sub.onEose);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
logger.error('Failed to resubscribe to subscriptions', { error });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async subscribe(filters, onEvent, onEose) {
|
|
141
|
+
logger.debug('Creating subscription', { filters });
|
|
142
|
+
try {
|
|
143
|
+
// Create a subscription using our simplified wrapper
|
|
144
|
+
const closer = this.createSubscription(filters, onEvent, onEose);
|
|
145
|
+
// Store the subscription for cleanup
|
|
146
|
+
this.subscriptions.push({
|
|
147
|
+
filters,
|
|
148
|
+
onEvent,
|
|
149
|
+
onEose,
|
|
150
|
+
closer,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
logger.error('Failed to create subscription', { filters, error });
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
unsubscribe() {
|
|
159
|
+
logger.debug('Unsubscribing from all subscriptions');
|
|
160
|
+
try {
|
|
161
|
+
// Close all active subscriptions
|
|
162
|
+
for (const subscription of this.subscriptions) {
|
|
163
|
+
subscription.closer.unsubscribe();
|
|
164
|
+
}
|
|
165
|
+
this.subscriptions = [];
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
logger.error('Error while unsubscribing from subscriptions', { error });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=applesauce-relay-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applesauce-relay-pool.js","sourceRoot":"","sources":["../../../src/relay/applesauce-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,kBAAkB,CAAC;A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,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAClE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,WAAW;QACT,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAErD,IAAI,CAAC;YACH,iCAAiC;YACjC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBAC9C,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACpC,CAAC;YAED,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relay/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relay/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
package/dist/esm/relay/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relay/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relay/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NostrEvent, Filter } from 'nostr-tools';
|
|
2
|
+
import { RelayHandler } from '../core/interfaces.js';
|
|
3
|
+
/**
|
|
4
|
+
* A RelayHandler implementation that uses the nostrify library's NPool to manage connections and subscriptions.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NostrifyRelayPool implements RelayHandler {
|
|
7
|
+
private readonly pool;
|
|
8
|
+
private readonly relayUrls;
|
|
9
|
+
private subscriptions;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new NostrifyRelayPool instance.
|
|
12
|
+
* @param relayUrls - An array of relay URLs to connect to.
|
|
13
|
+
*/
|
|
14
|
+
constructor(relayUrls: string[]);
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
disconnect(): Promise<void>;
|
|
17
|
+
publish(event: NostrEvent): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a simplified subscription wrapper around the NPool's req method.
|
|
20
|
+
* This provides a cleaner interface similar to SimplePool's subscribeMany.
|
|
21
|
+
*/
|
|
22
|
+
private createSubscription;
|
|
23
|
+
subscribe(filters: Filter[], onEvent: (event: NostrEvent) => void, onEose?: () => void): Promise<void>;
|
|
24
|
+
unsubscribe(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=nostrify-relay-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nostrify-relay-pool.d.ts","sourceRoot":"","sources":["../../../src/relay/nostrify-relay-pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAKrD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IAGrC,OAAO,CAAC,aAAa,CAKb;IAER;;;OAGG;gBACS,SAAS,EAAE,MAAM,EAAE;IAkBzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/C;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA4CpB,SAAS,CACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,IAAI,CAAC;IAehB,WAAW,IAAI,IAAI;CAUpB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { NPool, NRelay1 } from '@nostrify/nostrify';
|
|
2
|
+
import { createLogger } from '../core/utils/logger.js';
|
|
3
|
+
const logger = createLogger('nostrify-relay');
|
|
4
|
+
/**
|
|
5
|
+
* A RelayHandler implementation that uses the nostrify library's NPool to manage connections and subscriptions.
|
|
6
|
+
*/
|
|
7
|
+
export class NostrifyRelayPool {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new NostrifyRelayPool instance.
|
|
10
|
+
* @param relayUrls - An array of relay URLs to connect to.
|
|
11
|
+
*/
|
|
12
|
+
constructor(relayUrls) {
|
|
13
|
+
// Subscription management similar to SimpleRelayPool
|
|
14
|
+
this.subscriptions = [];
|
|
15
|
+
this.relayUrls = relayUrls;
|
|
16
|
+
this.pool = new NPool({
|
|
17
|
+
open: (url) => new NRelay1(url),
|
|
18
|
+
reqRouter: (filters) => {
|
|
19
|
+
const relayMap = new Map();
|
|
20
|
+
relayUrls.forEach((url) => {
|
|
21
|
+
relayMap.set(url, filters);
|
|
22
|
+
});
|
|
23
|
+
return relayMap;
|
|
24
|
+
},
|
|
25
|
+
eventRouter: () => {
|
|
26
|
+
return relayUrls;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
logger.info('Connecting to relays', { relayUrls: this.relayUrls });
|
|
32
|
+
// The NPool automatically connects to relays when needed
|
|
33
|
+
// We don't need to explicitly connect here, but we could validate the relay URLs
|
|
34
|
+
for (const url of this.relayUrls) {
|
|
35
|
+
try {
|
|
36
|
+
// Validate URL format
|
|
37
|
+
new URL(url);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logger.error('Invalid relay URL', { url, error });
|
|
41
|
+
throw new Error(`Invalid relay URL: ${url}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
logger.info('Relay pool initialized', { relayUrls: this.relayUrls });
|
|
45
|
+
}
|
|
46
|
+
async disconnect() {
|
|
47
|
+
this.pool.close();
|
|
48
|
+
}
|
|
49
|
+
async publish(event) {
|
|
50
|
+
logger.debug('Publishing event', { eventId: event.id, kind: event.kind });
|
|
51
|
+
try {
|
|
52
|
+
await this.pool.event(event);
|
|
53
|
+
logger.debug('Event published successfully', { eventId: event.id });
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger.error('Failed to publish event', { eventId: event.id, error });
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a simplified subscription wrapper around the NPool's req method.
|
|
62
|
+
* This provides a cleaner interface similar to SimplePool's subscribeMany.
|
|
63
|
+
*/
|
|
64
|
+
createSubscription(filters, onEvent, onEose) {
|
|
65
|
+
const abortController = new AbortController();
|
|
66
|
+
// Start the subscription in the background
|
|
67
|
+
(async () => {
|
|
68
|
+
try {
|
|
69
|
+
const messageStream = this.pool.req(filters, {
|
|
70
|
+
signal: abortController.signal,
|
|
71
|
+
});
|
|
72
|
+
let eoseReceived = false;
|
|
73
|
+
for await (const message of messageStream) {
|
|
74
|
+
if (abortController.signal.aborted)
|
|
75
|
+
break;
|
|
76
|
+
if (message[0] === 'EVENT') {
|
|
77
|
+
const event = message[2];
|
|
78
|
+
onEvent(event);
|
|
79
|
+
}
|
|
80
|
+
else if (message[0] === 'EOSE' && !eoseReceived && onEose) {
|
|
81
|
+
eoseReceived = true;
|
|
82
|
+
onEose();
|
|
83
|
+
}
|
|
84
|
+
else if (message[0] === 'CLOSED') {
|
|
85
|
+
// Subscription was closed by the relay
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
92
|
+
logger.debug('Subscription aborted');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
logger.error('Subscription error', { error });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
})();
|
|
99
|
+
return {
|
|
100
|
+
close: () => abortController.abort(),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async subscribe(filters, onEvent, onEose) {
|
|
104
|
+
logger.debug('Creating subscription', { filters });
|
|
105
|
+
// Create a subscription using our simplified wrapper
|
|
106
|
+
const closer = this.createSubscription(filters, onEvent, onEose);
|
|
107
|
+
// Store the subscription for cleanup
|
|
108
|
+
this.subscriptions.push({
|
|
109
|
+
filters,
|
|
110
|
+
onEvent,
|
|
111
|
+
onEose,
|
|
112
|
+
closer,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
unsubscribe() {
|
|
116
|
+
logger.debug('Unsubscribing from all subscriptions');
|
|
117
|
+
// Close all active subscriptions
|
|
118
|
+
for (const subscription of this.subscriptions) {
|
|
119
|
+
subscription.closer.close();
|
|
120
|
+
}
|
|
121
|
+
this.subscriptions = [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=nostrify-relay-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nostrify-relay-pool.js","sourceRoot":"","sources":["../../../src/relay/nostrify-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,MAAM,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,OA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I,IAAI,CAAC,aAAa,EAAE,CAAC;YAC9C,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -8,9 +8,11 @@ import { RelayHandler } from '../core/interfaces.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class SimpleRelayPool implements RelayHandler {
|
|
10
10
|
private readonly relayUrls;
|
|
11
|
+
private readonly normalizedRelayUrls;
|
|
11
12
|
private pool;
|
|
12
|
-
private reconnectIntervals;
|
|
13
13
|
private reconnectTimer?;
|
|
14
|
+
private readonly maxRetries;
|
|
15
|
+
private relayStates;
|
|
14
16
|
private subscriptions;
|
|
15
17
|
constructor(relayUrls: string[]);
|
|
16
18
|
/**
|
|
@@ -21,7 +23,7 @@ export declare class SimpleRelayPool implements RelayHandler {
|
|
|
21
23
|
connect(): Promise<void>;
|
|
22
24
|
/**
|
|
23
25
|
* Handles a disconnected relay with exponential backoff strategy.
|
|
24
|
-
* @param
|
|
26
|
+
* @param normalizedUrl - The normalized relay URL to reconnect to
|
|
25
27
|
*/
|
|
26
28
|
private handleDisconnectedRelay;
|
|
27
29
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-relay-pool.d.ts","sourceRoot":"","sources":["../../../src/relay/simple-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"simple-relay-pool.d.ts","sourceRoot":"","sources":["../../../src/relay/simple-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAW;IAC/C,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,cAAc,CAAC,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAK;IAEhC,OAAO,CAAC,WAAW,CAOf;IAEJ,OAAO,CAAC,aAAa,CAKb;gBAEI,SAAS,EAAE,MAAM,EAAE;IAgB/B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAkBpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9B;;;OAGG;YACW,uBAAuB;IAmDrC;;OAEG;IACH,OAAO,CAAC,cAAc;IAchB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC/C,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,SAAS,CACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,IAAI,CAAC;IAQhB,WAAW,IAAI,IAAI;CAIpB"}
|
|
@@ -10,9 +10,20 @@ const logger = createLogger('relay');
|
|
|
10
10
|
*/
|
|
11
11
|
export class SimpleRelayPool {
|
|
12
12
|
constructor(relayUrls) {
|
|
13
|
-
this.
|
|
13
|
+
this.maxRetries = 5;
|
|
14
|
+
this.relayStates = new Map();
|
|
14
15
|
this.subscriptions = [];
|
|
15
16
|
this.relayUrls = relayUrls;
|
|
17
|
+
// Normalize URLs once during construction
|
|
18
|
+
this.normalizedRelayUrls = relayUrls.map((url) => new URL(url).href);
|
|
19
|
+
// Initialize relay states
|
|
20
|
+
this.normalizedRelayUrls.forEach((url) => {
|
|
21
|
+
this.relayStates.set(url, {
|
|
22
|
+
reconnectInterval: 1000,
|
|
23
|
+
retryCount: 0,
|
|
24
|
+
isReconnecting: false,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
16
27
|
this.pool = new SimplePool();
|
|
17
28
|
this.startReconnectLoop();
|
|
18
29
|
}
|
|
@@ -27,9 +38,9 @@ export class SimpleRelayPool {
|
|
|
27
38
|
}
|
|
28
39
|
// Check all relays every 5 seconds
|
|
29
40
|
this.reconnectTimer = setTimeout(() => {
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
if (!
|
|
41
|
+
const connectionStatus = this.pool.listConnectionStatus();
|
|
42
|
+
this.relayStates.forEach((_, url) => {
|
|
43
|
+
if (!connectionStatus.get(url)) {
|
|
33
44
|
this.handleDisconnectedRelay(url);
|
|
34
45
|
}
|
|
35
46
|
});
|
|
@@ -38,33 +49,56 @@ export class SimpleRelayPool {
|
|
|
38
49
|
}
|
|
39
50
|
async connect() {
|
|
40
51
|
// Connect to all relays with exponential backoff tracking
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!
|
|
52
|
+
const connectionStatus = this.pool.listConnectionStatus();
|
|
53
|
+
await Promise.all(this.normalizedRelayUrls.map(async (url) => {
|
|
54
|
+
if (!connectionStatus.get(url)) {
|
|
44
55
|
await this.handleDisconnectedRelay(url);
|
|
45
56
|
}
|
|
46
57
|
}));
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
60
|
* Handles a disconnected relay with exponential backoff strategy.
|
|
50
|
-
* @param
|
|
61
|
+
* @param normalizedUrl - The normalized relay URL to reconnect to
|
|
51
62
|
*/
|
|
52
|
-
async handleDisconnectedRelay(
|
|
53
|
-
|
|
54
|
-
const
|
|
63
|
+
async handleDisconnectedRelay(normalizedUrl) {
|
|
64
|
+
// Get the relay state
|
|
65
|
+
const relayState = this.relayStates.get(normalizedUrl);
|
|
66
|
+
if (!relayState)
|
|
67
|
+
return;
|
|
68
|
+
// Skip if already reconnecting to this relay
|
|
69
|
+
if (relayState.isReconnecting) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Check if we've exceeded the maximum retry count
|
|
73
|
+
if (relayState.retryCount >= this.maxRetries) {
|
|
74
|
+
logger.warn(`Maximum reconnection attempts (${this.maxRetries}) reached for relay ${normalizedUrl}. Giving up.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const currentInterval = relayState.reconnectInterval;
|
|
78
|
+
// Check if we should wait before attempting to reconnect
|
|
79
|
+
if (currentInterval > 1000) {
|
|
80
|
+
await sleep(currentInterval);
|
|
81
|
+
}
|
|
82
|
+
// Mark as reconnecting and increment retry count
|
|
83
|
+
relayState.isReconnecting = true;
|
|
84
|
+
relayState.retryCount++;
|
|
55
85
|
this.pool['relays'].delete(normalizedUrl);
|
|
56
86
|
try {
|
|
57
|
-
await this.pool.ensureRelay(
|
|
58
|
-
// Reset backoff interval on successful connection
|
|
59
|
-
|
|
87
|
+
await this.pool.ensureRelay(normalizedUrl, { connectionTimeout: 5000 });
|
|
88
|
+
// Reset backoff interval and retry count on successful connection
|
|
89
|
+
relayState.reconnectInterval = 1000;
|
|
90
|
+
relayState.retryCount = 0;
|
|
60
91
|
// Resubscribe to all active subscriptions after successful reconnection
|
|
61
92
|
this.resubscribeAll();
|
|
62
93
|
}
|
|
63
94
|
catch (error) {
|
|
64
|
-
logger.error(
|
|
95
|
+
logger.error(`Can't connect to relay ${normalizedUrl} (attempt ${relayState.retryCount}/${this.maxRetries})`, error);
|
|
65
96
|
// Double the interval for next attempt (exponential backoff), capped at 30 seconds
|
|
66
|
-
|
|
67
|
-
|
|
97
|
+
relayState.reconnectInterval = Math.min(currentInterval * 2, 30000);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
// Remove from reconnecting set
|
|
101
|
+
relayState.isReconnecting = false;
|
|
68
102
|
}
|
|
69
103
|
}
|
|
70
104
|
/**
|
|
@@ -74,7 +108,7 @@ export class SimpleRelayPool {
|
|
|
74
108
|
this.subscriptions.forEach((sub) => {
|
|
75
109
|
if (sub.closer)
|
|
76
110
|
sub.closer.close();
|
|
77
|
-
sub.closer = this.pool.subscribeMany(this.
|
|
111
|
+
sub.closer = this.pool.subscribeMany(this.normalizedRelayUrls, sub.filters, {
|
|
78
112
|
onevent: sub.onEvent,
|
|
79
113
|
oneose: sub.onEose,
|
|
80
114
|
});
|
|
@@ -83,8 +117,12 @@ export class SimpleRelayPool {
|
|
|
83
117
|
async disconnect(relayUrls) {
|
|
84
118
|
if (!relayUrls) {
|
|
85
119
|
relayUrls = this.relayUrls;
|
|
86
|
-
//
|
|
87
|
-
this.
|
|
120
|
+
// Reset all relay states when disconnecting all relays
|
|
121
|
+
this.relayStates.forEach((state) => {
|
|
122
|
+
state.reconnectInterval = 1000;
|
|
123
|
+
state.retryCount = 0;
|
|
124
|
+
state.isReconnecting = false;
|
|
125
|
+
});
|
|
88
126
|
// Clear the reconnect loop timer
|
|
89
127
|
if (this.reconnectTimer) {
|
|
90
128
|
clearTimeout(this.reconnectTimer);
|
|
@@ -92,20 +130,25 @@ export class SimpleRelayPool {
|
|
|
92
130
|
}
|
|
93
131
|
}
|
|
94
132
|
else {
|
|
95
|
-
//
|
|
96
|
-
relayUrls.
|
|
97
|
-
|
|
98
|
-
this.
|
|
133
|
+
// Reset relay states for specific relays
|
|
134
|
+
const normalizedUrls = relayUrls.map((url) => new URL(url).href);
|
|
135
|
+
normalizedUrls.forEach((url) => {
|
|
136
|
+
const state = this.relayStates.get(url);
|
|
137
|
+
if (state) {
|
|
138
|
+
state.reconnectInterval = 1000;
|
|
139
|
+
state.retryCount = 0;
|
|
140
|
+
state.isReconnecting = false;
|
|
141
|
+
}
|
|
99
142
|
});
|
|
100
143
|
}
|
|
101
144
|
this.pool.close(relayUrls);
|
|
102
145
|
await sleep(100);
|
|
103
146
|
}
|
|
104
147
|
async publish(event) {
|
|
105
|
-
await Promise.all(this.pool.publish(this.
|
|
148
|
+
await Promise.all(this.pool.publish(this.normalizedRelayUrls, event));
|
|
106
149
|
}
|
|
107
150
|
async subscribe(filters, onEvent, onEose) {
|
|
108
|
-
const closer = this.pool.subscribeMany(this.
|
|
151
|
+
const closer = this.pool.subscribeMany(this.normalizedRelayUrls, filters, {
|
|
109
152
|
onevent: onEvent,
|
|
110
153
|
oneose: onEose,
|
|
111
154
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-relay-pool.js","sourceRoot":"","sources":["../../../src/relay/simple-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"simple-relay-pool.js","sourceRoot":"","sources":["../../../src/relay/simple-relay-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAuB1B,YAAY,SAAmB;QAlBd,eAAU,GAAG,CAAC,CAAC;QAExB,gBAAW,GAAG,IAAI,GAAG,EAO1B,CAAC;QAEI,kBAAa,GAKhB,EAAE,CAAC;QAGN,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,0CAA0C;QAC1C,IAAI,CAAC,mBAAmB,GAAG,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EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,WAAW;QACT,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,KAAK,EAAE,CAAA,EAAA,CAAC,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contextvm/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "CtxVM SDK for JavaScript/TypeScript",
|
|
5
5
|
"license": "LGPL-3.0-1",
|
|
6
6
|
"author": "ContextVM",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && bun tsc -p tsconfig.prod.json",
|
|
43
43
|
"lint": "eslint src/",
|
|
44
44
|
"test": "bun tests",
|
|
45
|
-
"
|
|
45
|
+
"format": "bun prettier --write .",
|
|
46
46
|
"release": "bun run build && bun changeset publish"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@modelcontextprotocol/sdk": "^1.17.2",
|
|
62
|
+
"applesauce-relay": "^2.3.0",
|
|
62
63
|
"nostr-tools": "^2.16.2"
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-server.d.ts","sourceRoot":"","sources":["../../../src/proxy/proxy-server.ts"],"names":[],"mappings":""}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
-
import { NostrMCPProxy } from './index.js';
|
|
4
|
-
import { PrivateKeySigner } from '../signer/private-key-signer.js';
|
|
5
|
-
import { SimpleRelayPool } from '../relay/simple-relay-pool.js';
|
|
6
|
-
/**
|
|
7
|
-
* Proxy server that exposes a remote Nostr MCP server via stdio.
|
|
8
|
-
* This allows MCP clients to connect to remote servers through the Nostr network.
|
|
9
|
-
*/
|
|
10
|
-
async function main() {
|
|
11
|
-
// Get configuration from environment variables
|
|
12
|
-
const relayUrl = process.env.RELAY_URL || 'ws://localhost:7777';
|
|
13
|
-
const clientPrivateKey = process.env.CLIENT_PRIVATE_KEY;
|
|
14
|
-
const serverPubkey = process.env.SERVER_PUBKEY;
|
|
15
|
-
if (!clientPrivateKey) {
|
|
16
|
-
console.error('CLIENT_PRIVATE_KEY environment variable is required');
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
if (!serverPubkey) {
|
|
20
|
-
console.error('SERVER_PUBKEY environment variable is required');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
// Set up stdio transport for the server
|
|
24
|
-
const transport = new StdioServerTransport();
|
|
25
|
-
// Create Nostr components
|
|
26
|
-
const signer = new PrivateKeySigner(clientPrivateKey);
|
|
27
|
-
const relayPool = new SimpleRelayPool([relayUrl]);
|
|
28
|
-
// Create and start the proxy
|
|
29
|
-
const proxy = new NostrMCPProxy({
|
|
30
|
-
mcpHostTransport: transport,
|
|
31
|
-
nostrTransportOptions: {
|
|
32
|
-
signer,
|
|
33
|
-
relayHandler: relayPool,
|
|
34
|
-
serverPubkey,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
// Handle cleanup on process termination
|
|
38
|
-
process.on('SIGINT', async () => {
|
|
39
|
-
await proxy.stop();
|
|
40
|
-
process.exit(0);
|
|
41
|
-
});
|
|
42
|
-
process.on('SIGTERM', async () => {
|
|
43
|
-
await proxy.stop();
|
|
44
|
-
process.exit(0);
|
|
45
|
-
});
|
|
46
|
-
// Start the proxy
|
|
47
|
-
await proxy.start();
|
|
48
|
-
console.error('Proxy server started and connected to stdio');
|
|
49
|
-
}
|
|
50
|
-
// Run the server
|
|
51
|
-
main().catch((error) => {
|
|
52
|
-
console.error('Proxy server error:', error);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
});
|
|
55
|
-
//# sourceMappingURL=proxy-server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-server.js","sourceRoot":"","sources":["../../../src/proxy/proxy-server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,qBAAqB,CAAC;IAChE,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE/C,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,wCAAwC;IACxC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,0BAA0B;IAC1B,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,C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