cocoon-sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -117
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +18 -1
package/README.md
CHANGED
|
@@ -1,159 +1,117 @@
|
|
|
1
1
|
# Cocoon TypeScript SDK
|
|
2
2
|
|
|
3
|
-
OpenAI-
|
|
3
|
+
OpenAI-style TypeScript SDK for Telegram Cocoon.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- npm: `cocoon-sdk`
|
|
6
|
+
- repo: `https://github.com/indie-cto/telegram-cocoon-ts-sdk`
|
|
6
7
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
### Prerequisites
|
|
10
|
-
|
|
11
|
-
- Node.js `>=18`
|
|
12
|
-
- `openssl`
|
|
13
|
-
- TON wallet mnemonic (24 words)
|
|
14
|
-
- Small TON balance for one-time setup transactions
|
|
15
|
-
|
|
16
|
-
### TON Balance Requirements
|
|
17
|
-
|
|
18
|
-
Two different numbers matter:
|
|
19
|
-
|
|
20
|
-
1) **Setup transaction spend** (what setup sends from wallet by default):
|
|
21
|
-
- `REGISTER_TON=1.0` TON
|
|
22
|
-
- `CHANGE_SECRET_TON=0.7` TON
|
|
23
|
-
- plus network fees
|
|
24
|
-
|
|
25
|
-
2) **Protocol stake parameter** (`minClientStake`) from root config.
|
|
26
|
-
As of **February 22, 2026** on mainnet:
|
|
27
|
-
- `minClientStake = 15 TON`
|
|
28
|
-
|
|
29
|
-
So:
|
|
30
|
-
- **2-3 TON** is usually enough to complete setup transactions.
|
|
31
|
-
- For stable inference usage, plan for **~15-20 TON** total working balance (stake + buffer).
|
|
32
|
-
- Current live values can change; check with `npm run cocoon:discover`.
|
|
33
|
-
|
|
34
|
-
Optional for heavier usage:
|
|
35
|
-
|
|
36
|
-
- set `TOP_UP_TON` (for example `15` or `20`) to increase available client balance for inference traffic.
|
|
37
|
-
|
|
38
|
-
### 1) Install dependencies
|
|
8
|
+
## Install
|
|
39
9
|
|
|
40
10
|
```bash
|
|
41
|
-
npm
|
|
11
|
+
npm i cocoon-sdk
|
|
42
12
|
```
|
|
43
13
|
|
|
44
|
-
|
|
14
|
+
## Minimal Usage
|
|
45
15
|
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
```
|
|
16
|
+
```ts
|
|
17
|
+
import { Cocoon } from 'cocoon-sdk';
|
|
49
18
|
|
|
50
|
-
|
|
19
|
+
const client = new Cocoon({
|
|
20
|
+
wallet: process.env.MNEMONIC!, // 24 words
|
|
21
|
+
secretString: process.env.SECRET!, // from your setup flow
|
|
22
|
+
proxyUrl: process.env.PROXY_URL, // optional (discovery if omitted)
|
|
23
|
+
tonV4Endpoint: process.env.TON_V4_ENDPOINT,
|
|
24
|
+
});
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
26
|
+
const models = await client.models.list();
|
|
27
|
+
const model = models.data[0]!.id;
|
|
55
28
|
|
|
56
|
-
|
|
29
|
+
const result = await client.chat.completions.create({
|
|
30
|
+
model,
|
|
31
|
+
messages: [{ role: 'user', content: 'Say OK' }],
|
|
32
|
+
});
|
|
57
33
|
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
console.log(result.choices[0]?.message.content);
|
|
35
|
+
await client.disconnect();
|
|
60
36
|
```
|
|
61
37
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- generates TLS client cert/key automatically,
|
|
65
|
-
- performs long-auth registration if needed,
|
|
66
|
-
- sets on-chain secret hash,
|
|
67
|
-
- prints ready-to-paste `.env` values.
|
|
38
|
+
## Streaming
|
|
68
39
|
|
|
69
|
-
|
|
40
|
+
```ts
|
|
41
|
+
const stream = await client.chat.completions.create({
|
|
42
|
+
model: 'Qwen/Qwen3-32B',
|
|
43
|
+
messages: [{ role: 'user', content: 'Write one short sentence' }],
|
|
44
|
+
stream: true,
|
|
45
|
+
});
|
|
70
46
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
SECRET=...
|
|
75
|
-
PROXY_URL=91.108.4.11:8888
|
|
76
|
-
COCOON_TLS_CERT_PATH=/tmp/cocoon-client-xxxx.pem
|
|
77
|
-
COCOON_TLS_KEY_PATH=/tmp/cocoon-client-xxxx.key.pem
|
|
78
|
-
TON_V4_ENDPOINT=https://mainnet-v4.tonhubapi.com
|
|
47
|
+
for await (const chunk of stream) {
|
|
48
|
+
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
|
|
49
|
+
}
|
|
79
50
|
```
|
|
80
51
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Copy those lines exactly into `.env`.
|
|
52
|
+
## Important Defaults
|
|
84
53
|
|
|
85
|
-
|
|
86
|
-
|
|
54
|
+
- `autoRegisterOnLongAuth` default is `false` (safety-first).
|
|
55
|
+
- SDK does **not** submit on-chain registration tx unless you explicitly enable it.
|
|
56
|
+
- Recommended production path: run setup once, then use `SECRET` for short auth.
|
|
87
57
|
|
|
88
|
-
|
|
58
|
+
## One-Time Setup (Repo Helper Scripts)
|
|
89
59
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
You should see:
|
|
60
|
+
The npm package is a library.
|
|
61
|
+
If you want the fully automated setup flow (cert/key generation + register + secret hash), use repo scripts:
|
|
95
62
|
|
|
96
|
-
-
|
|
97
|
-
-
|
|
63
|
+
- `https://github.com/indie-cto/telegram-cocoon-ts-sdk`
|
|
64
|
+
- `scripts/setup.ts`
|
|
65
|
+
- `scripts/inference.ts`
|
|
98
66
|
|
|
99
|
-
|
|
67
|
+
Important for users integrating from another project:
|
|
100
68
|
|
|
101
|
-
|
|
102
|
-
|
|
69
|
+
- The intended path is to run `scripts/setup.ts` once and copy `SECRET` + TLS paths.
|
|
70
|
+
- Do **not** rely on ad-hoc certificate generation commands from agents.
|
|
71
|
+
- A generic command like `openssl req -x509 -newkey ec ...` is not the tested/default SDK path.
|
|
103
72
|
|
|
104
|
-
|
|
105
|
-
wallet: process.env.MNEMONIC!,
|
|
106
|
-
secretString: process.env.SECRET,
|
|
107
|
-
proxyUrl: process.env.PROXY_URL,
|
|
108
|
-
tonV4Endpoint: process.env.TON_V4_ENDPOINT,
|
|
109
|
-
});
|
|
73
|
+
If you cannot run `scripts/setup.ts`, use this tested certificate generation format:
|
|
110
74
|
|
|
111
|
-
|
|
112
|
-
|
|
75
|
+
```bash
|
|
76
|
+
openssl genpkey -algorithm ed25519 -out /tmp/cocoon-client.key.pem
|
|
77
|
+
openssl req -x509 \
|
|
78
|
+
-key /tmp/cocoon-client.key.pem \
|
|
79
|
+
-out /tmp/cocoon-client-cert.pem \
|
|
80
|
+
-days 1 \
|
|
81
|
+
-subj "/C=AE/ST=DUBAI/O=TDLib Development/OU=Security/CN=localhost"
|
|
82
|
+
```
|
|
113
83
|
|
|
114
|
-
|
|
115
|
-
model,
|
|
116
|
-
messages: [{ role: 'user', content: 'Say OK' }],
|
|
117
|
-
});
|
|
84
|
+
Then set:
|
|
118
85
|
|
|
119
|
-
|
|
120
|
-
|
|
86
|
+
```env
|
|
87
|
+
COCOON_TLS_CERT_PATH=/tmp/cocoon-client-cert.pem
|
|
88
|
+
COCOON_TLS_KEY_PATH=/tmp/cocoon-client.key.pem
|
|
121
89
|
```
|
|
122
90
|
|
|
123
|
-
|
|
91
|
+
Note: this only covers TLS material. You still need a valid `SECRET` (recommended via setup flow).
|
|
92
|
+
|
|
93
|
+
## TON Balance Guidance
|
|
124
94
|
|
|
125
|
-
|
|
126
|
-
- If long auth is required, SDK can auto-submit registration transaction.
|
|
127
|
-
- You usually should not change advanced auth options.
|
|
95
|
+
Two values matter:
|
|
128
96
|
|
|
129
|
-
|
|
97
|
+
1. Setup spend defaults:
|
|
98
|
+
- `REGISTER_TON=1.0`
|
|
99
|
+
- `CHANGE_SECRET_TON=0.7`
|
|
100
|
+
- plus fees
|
|
130
101
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
- Inference test:
|
|
134
|
-
- `npm run cocoon:inference`
|
|
135
|
-
- Discover proxies/models:
|
|
136
|
-
- `npm run cocoon:discover`
|
|
137
|
-
- Register only (advanced):
|
|
138
|
-
- `npm run cocoon:register`
|
|
139
|
-
- Create wallet helper:
|
|
140
|
-
- `npm run cocoon:create-wallet`
|
|
141
|
-
- Pure library example:
|
|
142
|
-
- `npx tsx --env-file=.env examples/basic.ts`
|
|
102
|
+
2. Network stake parameter (`minClientStake`) from root config:
|
|
103
|
+
- on mainnet, this can be much higher (for example 15 TON on Feb 22, 2026)
|
|
143
104
|
|
|
144
|
-
|
|
105
|
+
Practical guidance:
|
|
145
106
|
|
|
146
|
-
-
|
|
147
|
-
|
|
148
|
-
-
|
|
149
|
-
- verify `COCOON_TLS_CERT_PATH` and `COCOON_TLS_KEY_PATH` exist and match.
|
|
150
|
-
- TON RPC `429`:
|
|
151
|
-
- set `TON_V4_ENDPOINT=https://mainnet-v4.tonhubapi.com`.
|
|
107
|
+
- smoke setup: typically `2-3 TON` can be enough
|
|
108
|
+
- stable usage: plan around `15-20 TON` total working balance
|
|
109
|
+
- verify live values with repo helper: `scripts/discover.ts`
|
|
152
110
|
|
|
153
111
|
## Security
|
|
154
112
|
|
|
155
|
-
- Never commit
|
|
156
|
-
- Treat
|
|
113
|
+
- Never commit mnemonic, secrets, or private keys.
|
|
114
|
+
- Treat TLS key files as sensitive.
|
|
157
115
|
|
|
158
116
|
## License
|
|
159
117
|
|
package/dist/index.cjs
CHANGED
|
@@ -1364,7 +1364,7 @@ function buildHandshakeCloseError(stage, error) {
|
|
|
1364
1364
|
async function performLongAuth(conn, connected, nonce, onLongAuthRequired, missingHandlerMessage) {
|
|
1365
1365
|
if (!onLongAuthRequired) {
|
|
1366
1366
|
throw new AuthenticationError(
|
|
1367
|
-
`${missingHandlerMessage}. Provide SECRET for short auth, or
|
|
1367
|
+
`${missingHandlerMessage}. Provide SECRET for short auth, or explicitly enable automatic long-auth registration`
|
|
1368
1368
|
);
|
|
1369
1369
|
}
|
|
1370
1370
|
await onLongAuthRequired({
|
|
@@ -2434,7 +2434,8 @@ var Cocoon = class {
|
|
|
2434
2434
|
network: "mainnet",
|
|
2435
2435
|
timeout: 12e4,
|
|
2436
2436
|
useTls: true,
|
|
2437
|
-
|
|
2437
|
+
// Safety-first default for SDK consumers: don't submit on-chain tx implicitly.
|
|
2438
|
+
autoRegisterOnLongAuth: false,
|
|
2438
2439
|
longAuthRegisterAmountTon: "1",
|
|
2439
2440
|
...options
|
|
2440
2441
|
};
|