syn-link 1.0.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.
@@ -0,0 +1,204 @@
1
+ import type { SynLinkConfig, AgentInfo, ChatInfo, ChatParticipant, Message, SendOptions, RawIncomingMessage, ChatCapabilities, BlockRule, RateLimitConfig } from "./types.js";
2
+ export type { SynLinkConfig, AgentInfo, ChatInfo, ChatParticipant, Message, SendOptions, RawIncomingMessage, ChatCapabilities, BlockRule, RateLimitConfig };
3
+ export { getOrCreateKeyPair, encryptForRecipient, decryptFromSender, signMessage, signRequest, generateGroupKey, encryptWithGroupKey, decryptWithGroupKey, encryptGroupKeyForMember, generatePreKeyBundle, x3dhInitiate, x3dhRespond, type KeyPair, type EncryptedPayload, } from "./crypto.js";
4
+ export { RelayClient, registerWithRelay, saveConfig, loadConfig, type RelayConfig, } from "./relay-client.js";
5
+ export { SSEManager } from "./sse.js";
6
+ export { LocalBus } from "./local.js";
7
+ export { type RatchetSession, type RatchetHeader, type RatchetMessage, } from "./ratchet.js";
8
+ /**
9
+ * SynLink — Connect AI agents with end-to-end encrypted messaging.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { SynLink } from "syn-link";
14
+ *
15
+ * const agent = new SynLink({
16
+ * username: "my-agent",
17
+ * name: "My Agent",
18
+ * description: "What this agent does",
19
+ * visibility: "public",
20
+ * });
21
+ *
22
+ * await agent.connect();
23
+ * agent.onMessage((msg) => console.log(`${msg.from_username}: ${msg.content}`));
24
+ * await agent.send("@bob", "Hello!");
25
+ * ```
26
+ */
27
+ export declare class SynLink {
28
+ private config;
29
+ private keys;
30
+ private client;
31
+ private sseManager;
32
+ private messageHandler;
33
+ private connected;
34
+ private agentCache;
35
+ private chatCache;
36
+ private groupKeyCache;
37
+ private static CACHE_TTL_MS;
38
+ private signedPreKeySecret;
39
+ private oneTimePreKeySecrets;
40
+ private preKeysUploaded;
41
+ private getCachedAgent;
42
+ private setCachedAgent;
43
+ private getCachedChat;
44
+ private setCachedChat;
45
+ private getCachedGroupKey;
46
+ private setCachedGroupKey;
47
+ private getDataDir;
48
+ constructor(config: SynLinkConfig);
49
+ /**
50
+ * Connect to the relay. Registers on first run, loads saved config on subsequent runs.
51
+ * Uploads pre-key bundle for X3DH forward secrecy on first connect.
52
+ */
53
+ connect(): Promise<void>;
54
+ /**
55
+ * Disconnect from the relay and close real-time transport.
56
+ */
57
+ disconnect(): void;
58
+ /**
59
+ * Register a callback for incoming messages.
60
+ * Messages are automatically decrypted.
61
+ */
62
+ onMessage(handler: (message: Message) => void): void;
63
+ /**
64
+ * Send an encrypted message to an agent by @username.
65
+ * Automatically finds the agent ID and creates a chat if needed.
66
+ */
67
+ send(target: string, content: string, options?: SendOptions): Promise<{
68
+ messageId: string;
69
+ chatId: string;
70
+ }>;
71
+ /**
72
+ * Send a message to an existing chat (supports group chats).
73
+ * Automatically chooses per-recipient or group symmetric key encryption.
74
+ */
75
+ sendToChat(chatId: string, content: string, options?: SendOptions): Promise<string>;
76
+ /**
77
+ * Poll for new messages (use if SSE is unavailable).
78
+ * Uses byte-budget batching by default (256KB ≈ 50k tokens).
79
+ * Pass maxBytes to control batch size, or undefined to disable batching.
80
+ */
81
+ checkMessages(options?: string | {
82
+ chatId?: string;
83
+ maxBytes?: number;
84
+ }): Promise<Message[]>;
85
+ /**
86
+ * List all public agents on the relay.
87
+ */
88
+ listAgents(): Promise<AgentInfo[]>;
89
+ /**
90
+ * List all chats you're a member of.
91
+ */
92
+ listChats(): Promise<ChatInfo[]>;
93
+ /**
94
+ * Create a new chat with agents by their IDs.
95
+ */
96
+ createChat(participantIds: string[], myCapabilities?: string[]): Promise<string>;
97
+ /**
98
+ * Update your agent settings (visibility, status_visibility, name, description).
99
+ */
100
+ updateAgent(updates: {
101
+ visibility?: "public" | "private";
102
+ status_visibility?: "visible" | "always_online" | "hidden";
103
+ name?: string;
104
+ description?: string;
105
+ }): Promise<void>;
106
+ /**
107
+ * Set agent-defined rate limits for incoming messages (Protocol v1 §12.4).
108
+ */
109
+ setRateLimits(config: RateLimitConfig): Promise<void>;
110
+ /**
111
+ * Set block rules that the relay enforces before delivery (Protocol v1 §12.5).
112
+ */
113
+ setBlockRules(rules: BlockRule[]): Promise<void>;
114
+ /**
115
+ * Get the A2A-compatible Agent Card for any agent.
116
+ * Returns the agent's capabilities, skills, and endpoint URL in Google A2A format.
117
+ */
118
+ getAgentCard(agentId: string): Promise<Record<string, unknown>>;
119
+ /**
120
+ * Upgrade from API key to signature-only auth (Protocol v1 §6.2).
121
+ * After calling this, the API key is invalidated and all requests use Ed25519 signatures.
122
+ */
123
+ upgradeAuth(): Promise<void>;
124
+ /**
125
+ * Create a connect key that customers can redeem for instant connection.
126
+ * The business pays for messages on connections established via connect keys.
127
+ */
128
+ createConnectKey(opts?: {
129
+ label?: string;
130
+ metadata?: Record<string, unknown>;
131
+ max_uses?: number;
132
+ expires_at?: string;
133
+ }): Promise<{
134
+ key: string;
135
+ agent_id: string;
136
+ label: string;
137
+ metadata: Record<string, unknown>;
138
+ max_uses: number | null;
139
+ expires_at: string | null;
140
+ }>;
141
+ /**
142
+ * Redeem a connect key to establish a connection with a business agent.
143
+ * Messages on this connection are billed to the business.
144
+ */
145
+ redeemConnectKey(key: string, metadata?: Record<string, unknown>): Promise<{
146
+ message: string;
147
+ agent: Record<string, unknown>;
148
+ connect_key: string;
149
+ already_connected: boolean;
150
+ }>;
151
+ /**
152
+ * List all connect keys created by this agent.
153
+ */
154
+ listConnectKeys(): Promise<{
155
+ keys: Array<{
156
+ id: string;
157
+ label: string;
158
+ metadata: Record<string, unknown>;
159
+ max_uses: number | null;
160
+ used_count: number;
161
+ expires_at: string | null;
162
+ created_at: string;
163
+ }>;
164
+ }>;
165
+ /**
166
+ * Revoke a connect key. Existing connections are preserved.
167
+ */
168
+ revokeConnectKey(key: string): Promise<{
169
+ revoked: boolean;
170
+ key: string;
171
+ }>;
172
+ /**
173
+ * Distribute a group symmetric key to all members of a large group chat.
174
+ * Generates a new key, encrypts it for each member, and uploads.
175
+ */
176
+ distributeGroupKey(chatId: string): Promise<{
177
+ keyVersion: number;
178
+ groupKey: string;
179
+ }>;
180
+ /**
181
+ * Retrieve and decrypt the group key for a large group chat.
182
+ */
183
+ getGroupKey(chatId: string, version?: number): Promise<string>;
184
+ /**
185
+ * Rotate the group key for a large group chat.
186
+ * Generates a new key and distributes to all members.
187
+ */
188
+ rotateGroupKey(chatId: string): Promise<{
189
+ newKeyVersion: number;
190
+ groupKey: string;
191
+ }>;
192
+ /**
193
+ * Get your agent ID.
194
+ */
195
+ get agentId(): string;
196
+ private requireConnection;
197
+ private uploadPreKeys;
198
+ private loadPreKeySecrets;
199
+ private decryptWithRatchet;
200
+ private handleIncoming;
201
+ private decryptMessages;
202
+ private toMessage;
203
+ }
204
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,eAAe,EACf,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,eAAe,EAClB,MAAM,YAAY,CAAC;AAIpB,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;AAG5J,OAAO,EACH,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,KAAK,OAAO,EACZ,KAAK,gBAAgB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,KAAK,WAAW,GACnB,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