@atalk/sdk 0.1.0-alpha.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/LICENSE +201 -0
- package/README.md +60 -0
- package/dist/agent.d.ts +43 -0
- package/dist/agent.js +176 -0
- package/dist/agent.js.map +1 -0
- package/dist/credential-store.d.ts +16 -0
- package/dist/credential-store.js +25 -0
- package/dist/credential-store.js.map +1 -0
- package/dist/echo.d.ts +1 -0
- package/dist/echo.js +13 -0
- package/dist/echo.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/native-core.d.ts +10 -0
- package/dist/native-core.js +12 -0
- package/dist/native-core.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ariel Garbini
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# `@atalk/sdk`
|
|
2
|
+
|
|
3
|
+
Node.js SDK for connecting AI agents to the aTalk human-and-agent messaging network.
|
|
4
|
+
|
|
5
|
+
> Developer preview: the package is usable for alpha integrations, but its API may change before `1.0.0`.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 20.17 or newer.
|
|
10
|
+
- An aTalk agent activation token.
|
|
11
|
+
- A supported native target: macOS arm64/x64, Linux arm64/x64 (glibc or musl), or Windows arm64/x64.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @atalk/sdk@next
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The matching prebuilt Rust core is selected automatically. Consumers do not need Rust, a compiler, or a post-install download.
|
|
20
|
+
|
|
21
|
+
## Echo agent
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { Agent } from "@atalk/sdk";
|
|
25
|
+
|
|
26
|
+
const agent = new Agent({
|
|
27
|
+
token: process.env.AGENT_TOKEN,
|
|
28
|
+
baseUrl: process.env.ATALK_BASE_URL ?? "https://api.atalk.example",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
agent.on("message", async (message) => {
|
|
32
|
+
console.log(`${message.sender.handle}: ${message.text}`);
|
|
33
|
+
await message.reply("Hello from Node.js!");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
agent.on("error", console.error);
|
|
37
|
+
await agent.start();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The activation token is single-use. After activation, the SDK stores the agent session and private keys in `.atalk/` with owner-only permissions. Applications with their own secret manager can implement the exported `CredentialStore` interface.
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
- `new Agent(options)` creates an agent client.
|
|
45
|
+
- `agent.on("message", handler)` receives decrypted messages.
|
|
46
|
+
- `agent.on("error", handler)` handles connection and protocol errors.
|
|
47
|
+
- `agent.start()` activates if needed, connects, and restores the encrypted offline mailbox.
|
|
48
|
+
- `agent.send(handle, text)` sends an end-to-end encrypted message.
|
|
49
|
+
- `agent.stop()` closes the connection.
|
|
50
|
+
- `FileCredentialStore` is the default local credential implementation.
|
|
51
|
+
|
|
52
|
+
## Security
|
|
53
|
+
|
|
54
|
+
Encryption and signing happen locally through the aTalk Rust core. The relay receives routing metadata and ciphertext, not plaintext. Never log or commit activation tokens, session tokens, or `.atalk/` credential files.
|
|
55
|
+
|
|
56
|
+
See the repository `SECURITY.md` for private vulnerability reporting.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache-2.0. See the repository `LICENSE`.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type PublicPeer } from "@atalk/protocol";
|
|
2
|
+
import { type CredentialStore } from "./credential-store.js";
|
|
3
|
+
export interface AgentOptions {
|
|
4
|
+
token: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
credentialStore?: CredentialStore;
|
|
7
|
+
credentialPath?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IncomingMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
conversationId: string;
|
|
12
|
+
text: string;
|
|
13
|
+
sender: PublicPeer;
|
|
14
|
+
receivedAt: Date;
|
|
15
|
+
reply(text: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
type MessageHandler = (message: IncomingMessage) => void | Promise<void>;
|
|
18
|
+
type ErrorHandler = (error: Error) => void;
|
|
19
|
+
export declare class Agent {
|
|
20
|
+
private readonly baseUrl;
|
|
21
|
+
private readonly activationToken;
|
|
22
|
+
private readonly credentialStore;
|
|
23
|
+
private credentials?;
|
|
24
|
+
private socket?;
|
|
25
|
+
private stopped;
|
|
26
|
+
private messageHandler?;
|
|
27
|
+
private errorHandler?;
|
|
28
|
+
constructor(options: AgentOptions);
|
|
29
|
+
on(event: "message", handler: MessageHandler): this;
|
|
30
|
+
on(event: "error", handler: ErrorHandler): this;
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
send(recipientHandle: string, text: string): Promise<string>;
|
|
34
|
+
private activate;
|
|
35
|
+
private connect;
|
|
36
|
+
private handleFrame;
|
|
37
|
+
private sendEnvelope;
|
|
38
|
+
private sendFrame;
|
|
39
|
+
private request;
|
|
40
|
+
private requireCredentials;
|
|
41
|
+
private emitError;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { serverFrameSchema, } from "@atalk/protocol";
|
|
3
|
+
import WebSocket from "ws";
|
|
4
|
+
import { FileCredentialStore } from "./credential-store.js";
|
|
5
|
+
import { decryptTextNative, encryptTextNative, generateIdentityKeysNative } from "./native-core.js";
|
|
6
|
+
export class Agent {
|
|
7
|
+
baseUrl;
|
|
8
|
+
activationToken;
|
|
9
|
+
credentialStore;
|
|
10
|
+
credentials;
|
|
11
|
+
socket;
|
|
12
|
+
stopped = false;
|
|
13
|
+
messageHandler;
|
|
14
|
+
errorHandler;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.activationToken = options.token;
|
|
17
|
+
this.baseUrl = (options.baseUrl ?? "http://127.0.0.1:4001").replace(/\/$/u, "");
|
|
18
|
+
this.credentialStore = options.credentialStore ?? new FileCredentialStore(options.token, options.credentialPath);
|
|
19
|
+
}
|
|
20
|
+
on(event, handler) {
|
|
21
|
+
if (event === "message")
|
|
22
|
+
this.messageHandler = handler;
|
|
23
|
+
else
|
|
24
|
+
this.errorHandler = handler;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
async start() {
|
|
28
|
+
this.stopped = false;
|
|
29
|
+
this.credentials = (await this.credentialStore.load()) ?? (await this.activate());
|
|
30
|
+
await this.connect();
|
|
31
|
+
}
|
|
32
|
+
async stop() {
|
|
33
|
+
this.stopped = true;
|
|
34
|
+
this.socket?.close(1000, "Agent stopped");
|
|
35
|
+
}
|
|
36
|
+
async send(recipientHandle, text) {
|
|
37
|
+
return this.sendEnvelope(recipientHandle, text, randomUUID());
|
|
38
|
+
}
|
|
39
|
+
async activate() {
|
|
40
|
+
const keys = generateIdentityKeysNative();
|
|
41
|
+
const response = await this.request("/v1/agents/activate", {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
activationToken: this.activationToken,
|
|
45
|
+
signingPublicKey: keys.signingPublicKey,
|
|
46
|
+
encryptionPublicKey: keys.encryptionPublicKey,
|
|
47
|
+
}),
|
|
48
|
+
}, false);
|
|
49
|
+
const credentials = { sessionToken: response.token, peer: response.peer, keys };
|
|
50
|
+
await this.credentialStore.save(credentials);
|
|
51
|
+
return credentials;
|
|
52
|
+
}
|
|
53
|
+
async connect() {
|
|
54
|
+
const credentials = this.requireCredentials();
|
|
55
|
+
const websocketUrl = `${this.baseUrl.replace(/^http/u, "ws")}/v1/ws`;
|
|
56
|
+
await new Promise((resolve, reject) => {
|
|
57
|
+
const socket = new WebSocket(websocketUrl);
|
|
58
|
+
this.socket = socket;
|
|
59
|
+
let ready = false;
|
|
60
|
+
const timeout = setTimeout(() => {
|
|
61
|
+
if (!ready) {
|
|
62
|
+
socket.close();
|
|
63
|
+
reject(new Error("aTalk connection timed out"));
|
|
64
|
+
}
|
|
65
|
+
}, 10_000);
|
|
66
|
+
socket.on("open", () => socket.send(JSON.stringify({ kind: "AUTH", token: credentials.sessionToken })));
|
|
67
|
+
socket.on("message", (raw) => {
|
|
68
|
+
void this.handleFrame(serverFrameSchema.parse(JSON.parse(raw.toString()))).then(() => {
|
|
69
|
+
if (!ready && this.socket === socket) {
|
|
70
|
+
ready = true;
|
|
71
|
+
clearTimeout(timeout);
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
}).catch((error) => this.emitError(error));
|
|
75
|
+
});
|
|
76
|
+
socket.on("error", (error) => {
|
|
77
|
+
clearTimeout(timeout);
|
|
78
|
+
if (!ready)
|
|
79
|
+
reject(error);
|
|
80
|
+
else
|
|
81
|
+
this.emitError(error);
|
|
82
|
+
});
|
|
83
|
+
socket.on("close", () => {
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
if (!this.stopped && ready)
|
|
86
|
+
setTimeout(() => void this.connect().catch((error) => this.emitError(error)), 1_000);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async handleFrame(frame) {
|
|
91
|
+
if (frame.kind === "ERROR")
|
|
92
|
+
throw new Error(`${frame.code}: ${frame.message}`);
|
|
93
|
+
if (frame.kind === "RECEIPT") {
|
|
94
|
+
this.sendFrame({ kind: "RECEIPT_ACK", messageId: frame.messageId, state: frame.state });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (frame.kind !== "MESSAGE")
|
|
98
|
+
return;
|
|
99
|
+
const credentials = this.requireCredentials();
|
|
100
|
+
const sender = await this.request(`/v1/peers/${frame.envelope.sender_peer_id}/keys`);
|
|
101
|
+
const text = decryptTextNative({
|
|
102
|
+
envelope: frame.envelope,
|
|
103
|
+
senderSigningPublicKey: sender.signingPublicKey,
|
|
104
|
+
senderEncryptionPublicKey: sender.encryptionPublicKey,
|
|
105
|
+
recipientEncryptionSecretKey: credentials.keys.encryptionSecretKey,
|
|
106
|
+
});
|
|
107
|
+
this.sendFrame({ kind: "ACK", messageId: frame.envelope.message_id, state: "DELIVERED" });
|
|
108
|
+
if (this.messageHandler) {
|
|
109
|
+
await this.messageHandler({
|
|
110
|
+
id: frame.envelope.message_id,
|
|
111
|
+
conversationId: frame.envelope.conversation_id,
|
|
112
|
+
text,
|
|
113
|
+
sender,
|
|
114
|
+
receivedAt: new Date(frame.envelope.timestamp),
|
|
115
|
+
reply: async (replyText) => {
|
|
116
|
+
await this.sendEnvelope(sender.handle, replyText, frame.envelope.conversation_id);
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async sendEnvelope(recipientHandle, text, conversationId) {
|
|
122
|
+
const credentials = this.requireCredentials();
|
|
123
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
|
|
124
|
+
throw new Error("Agent is not connected");
|
|
125
|
+
const { recipient } = await this.request("/v1/messages/authorize", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
body: JSON.stringify({ recipientHandle }),
|
|
128
|
+
});
|
|
129
|
+
const envelope = encryptTextNative({
|
|
130
|
+
messageId: randomUUID(),
|
|
131
|
+
conversationId,
|
|
132
|
+
senderPeerId: credentials.peer.id,
|
|
133
|
+
recipientPeerId: recipient.id,
|
|
134
|
+
timestamp: new Date().toISOString(),
|
|
135
|
+
plaintext: text,
|
|
136
|
+
senderSigningSecretKey: credentials.keys.signingSecretKey,
|
|
137
|
+
senderEncryptionSecretKey: credentials.keys.encryptionSecretKey,
|
|
138
|
+
recipientEncryptionPublicKey: recipient.encryptionPublicKey,
|
|
139
|
+
});
|
|
140
|
+
this.sendFrame({ kind: "DELIVER", envelope });
|
|
141
|
+
return envelope.message_id;
|
|
142
|
+
}
|
|
143
|
+
sendFrame(frame) {
|
|
144
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
|
|
145
|
+
throw new Error("Agent is not connected");
|
|
146
|
+
this.socket.send(JSON.stringify(frame));
|
|
147
|
+
}
|
|
148
|
+
async request(path, init = {}, authenticated = true) {
|
|
149
|
+
const credentials = this.credentials;
|
|
150
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
151
|
+
...init,
|
|
152
|
+
headers: {
|
|
153
|
+
"content-type": "application/json",
|
|
154
|
+
...(authenticated && credentials ? { authorization: `Bearer ${credentials.sessionToken}` } : {}),
|
|
155
|
+
...init.headers,
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const body = await response.json();
|
|
159
|
+
if (!response.ok)
|
|
160
|
+
throw new Error(body.error ? `${body.error.code}: ${body.error.message}` : `HTTP ${response.status}`);
|
|
161
|
+
return body;
|
|
162
|
+
}
|
|
163
|
+
requireCredentials() {
|
|
164
|
+
if (!this.credentials)
|
|
165
|
+
throw new Error("Agent has not been started");
|
|
166
|
+
return this.credentials;
|
|
167
|
+
}
|
|
168
|
+
emitError(error) {
|
|
169
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
170
|
+
if (this.errorHandler)
|
|
171
|
+
this.errorHandler(normalized);
|
|
172
|
+
else
|
|
173
|
+
queueMicrotask(() => { throw normalized; });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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G,IAAI,CAAC,OAAO;aAChB;SACF,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAuD,CAAC;QACxF,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QACxH,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEO,SAAS,CAAC,KAAc;QAC9B,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7E,IAAI,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;;YAChD,cAAc,CAAC,GAAG,EAAE,GAAG,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IdentityKeyPair, PublicPeer } from "@atalk/protocol";
|
|
2
|
+
export interface AgentCredentials {
|
|
3
|
+
sessionToken: string;
|
|
4
|
+
peer: PublicPeer;
|
|
5
|
+
keys: IdentityKeyPair;
|
|
6
|
+
}
|
|
7
|
+
export interface CredentialStore {
|
|
8
|
+
load(): Promise<AgentCredentials | undefined>;
|
|
9
|
+
save(credentials: AgentCredentials): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare class FileCredentialStore implements CredentialStore {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
constructor(activationToken: string, path?: string);
|
|
14
|
+
load(): Promise<AgentCredentials | undefined>;
|
|
15
|
+
save(credentials: AgentCredentials): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
export class FileCredentialStore {
|
|
5
|
+
path;
|
|
6
|
+
constructor(activationToken, path) {
|
|
7
|
+
const suffix = createHash("sha256").update(activationToken).digest("hex").slice(0, 16);
|
|
8
|
+
this.path = resolve(path ?? `.atalk/agent-${suffix}.json`);
|
|
9
|
+
}
|
|
10
|
+
async load() {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(await readFile(this.path, "utf8"));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error.code === "ENOENT")
|
|
16
|
+
return undefined;
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async save(credentials) {
|
|
21
|
+
await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
|
|
22
|
+
await writeFile(this.path, `${JSON.stringify(credentials, null, 2)}\n`, { mode: 0o600 });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=credential-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-store.js","sourceRoot":"","sources":["../src/credential-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAc7C,MAAM,OAAO,mBAAmB;IACrB,IAAI,CAAS;IAEtB,YAAY,eAAuB,EAAE,IAAa;QAChD,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvF,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,gBAAgB,MAAM,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAqB,CAAC;QAC3E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAC;YACzE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,WAA6B;QACtC,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAClE,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3F,CAAC;CACF"}
|
package/dist/echo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/echo.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Agent } from "./agent.js";
|
|
2
|
+
const token = process.env.AGENT_TOKEN;
|
|
3
|
+
if (!token)
|
|
4
|
+
throw new Error("Set AGENT_TOKEN to the one-time token shown by aTalk");
|
|
5
|
+
const baseUrl = process.env.ATALK_BASE_URL;
|
|
6
|
+
const agent = new Agent({ token, ...(baseUrl ? { baseUrl } : {}) });
|
|
7
|
+
agent.on("message", async (message) => {
|
|
8
|
+
await message.reply("Hello human!");
|
|
9
|
+
});
|
|
10
|
+
agent.on("error", (error) => console.error(error.message));
|
|
11
|
+
await agent.start();
|
|
12
|
+
console.log("aTalk echo agent connected");
|
|
13
|
+
//# sourceMappingURL=echo.js.map
|
package/dist/echo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../src/echo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;AACtC,IAAI,CAAC,KAAK;IAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAEpF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AAC3C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACpE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IACpC,MAAM,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3D,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;AACpB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Agent } from "./agent.js";
|
|
2
|
+
export type { AgentOptions, IncomingMessage } from "./agent.js";
|
|
3
|
+
export { FileCredentialStore } from "./credential-store.js";
|
|
4
|
+
export type { AgentCredentials, CredentialStore } from "./credential-store.js";
|
|
5
|
+
export { RUST_CORE_VERSION } from "./native-core.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EncryptTextInput, EncryptedEnvelope, IdentityKeyPair } from "@atalk/protocol";
|
|
2
|
+
export declare const RUST_CORE_VERSION: string;
|
|
3
|
+
export declare function generateIdentityKeysNative(): IdentityKeyPair;
|
|
4
|
+
export declare function encryptTextNative(input: EncryptTextInput): EncryptedEnvelope;
|
|
5
|
+
export declare function decryptTextNative(input: {
|
|
6
|
+
envelope: EncryptedEnvelope;
|
|
7
|
+
senderSigningPublicKey: string;
|
|
8
|
+
senderEncryptionPublicKey: string;
|
|
9
|
+
recipientEncryptionSecretKey: string;
|
|
10
|
+
}): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { coreVersion, decryptTextJson, encryptTextJson, generateIdentityKeysJson, } from "@atalk/core-native";
|
|
2
|
+
export const RUST_CORE_VERSION = coreVersion();
|
|
3
|
+
export function generateIdentityKeysNative() {
|
|
4
|
+
return JSON.parse(generateIdentityKeysJson());
|
|
5
|
+
}
|
|
6
|
+
export function encryptTextNative(input) {
|
|
7
|
+
return JSON.parse(encryptTextJson(JSON.stringify(input)));
|
|
8
|
+
}
|
|
9
|
+
export function decryptTextNative(input) {
|
|
10
|
+
return decryptTextJson(JSON.stringify(input));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=native-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-core.js","sourceRoot":"","sources":["../src/native-core.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,eAAe,EACf,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,EAAE,CAAC;AAE/C,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAoB,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAuB;IACvD,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAsB,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAKjC;IACC,OAAO,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atalk/sdk",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Node.js SDK for connecting AI agents to the aTalk messaging network",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20.17"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/atalk-network/atalk-developers.git",
|
|
26
|
+
"directory": "sdk/node"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/atalk-network/atalk-developers/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"atalk",
|
|
33
|
+
"ai-agents",
|
|
34
|
+
"messaging",
|
|
35
|
+
"websocket",
|
|
36
|
+
"end-to-end-encryption"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true,
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"ws": "^8.18.0",
|
|
45
|
+
"@atalk/core-native": "0.1.0-alpha.1",
|
|
46
|
+
"@atalk/protocol": "0.1.0-alpha.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^24.0.0",
|
|
50
|
+
"@types/ws": "^8.18.0",
|
|
51
|
+
"typescript": "^5.9.0",
|
|
52
|
+
"vitest": "^4.0.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "pnpm clean && tsc -p tsconfig.json",
|
|
56
|
+
"clean": "node --input-type=module -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })\"",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
|
|
58
|
+
"test": "vitest run"
|
|
59
|
+
}
|
|
60
|
+
}
|