cocoon-sdk 0.1.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/README.md +160 -0
- package/dist/index.cjs +2634 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +462 -0
- package/dist/index.d.ts +462 -0
- package/dist/index.js +2588 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Cocoon TypeScript SDK
|
|
2
|
+
|
|
3
|
+
OpenAI-compatible TypeScript SDK for Telegram Cocoon.
|
|
4
|
+
|
|
5
|
+
This guide is intentionally step-by-step so you can get to a working request without reading Cocoon docs.
|
|
6
|
+
|
|
7
|
+
## Quickstart (From Zero to First Response)
|
|
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
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2) Create `.env`
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cp .env.example .env
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Edit `.env` and set only:
|
|
51
|
+
|
|
52
|
+
```env
|
|
53
|
+
MNEMONIC=your 24 words here
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3) Run one-time setup
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run cocoon:setup
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
What setup does for you:
|
|
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.
|
|
68
|
+
|
|
69
|
+
Example final output:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
=== Setup Complete ===
|
|
73
|
+
Put these into your .env:
|
|
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
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4) Paste setup output into `.env`
|
|
82
|
+
|
|
83
|
+
Copy those lines exactly into `.env`.
|
|
84
|
+
|
|
85
|
+
Important: you do not need to find or create certificates manually.
|
|
86
|
+
`scripts/setup.ts` creates them and gives you the file paths.
|
|
87
|
+
|
|
88
|
+
### 5) Run inference
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm run cocoon:inference
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
You should see:
|
|
95
|
+
|
|
96
|
+
- connected models list,
|
|
97
|
+
- generated model output.
|
|
98
|
+
|
|
99
|
+
## Minimal SDK Usage
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { Cocoon } from 'cocoon-sdk';
|
|
103
|
+
|
|
104
|
+
const client = new Cocoon({
|
|
105
|
+
wallet: process.env.MNEMONIC!,
|
|
106
|
+
secretString: process.env.SECRET,
|
|
107
|
+
proxyUrl: process.env.PROXY_URL,
|
|
108
|
+
tonV4Endpoint: process.env.TON_V4_ENDPOINT,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const models = await client.models.list();
|
|
112
|
+
const model = models.data[0]!.id;
|
|
113
|
+
|
|
114
|
+
const res = await client.chat.completions.create({
|
|
115
|
+
model,
|
|
116
|
+
messages: [{ role: 'user', content: 'Say OK' }],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
console.log(res.choices[0]?.message.content);
|
|
120
|
+
await client.disconnect();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Defaults (Designed for the Common Path)
|
|
124
|
+
|
|
125
|
+
- `autoRegisterOnLongAuth` is enabled by default.
|
|
126
|
+
- If long auth is required, SDK can auto-submit registration transaction.
|
|
127
|
+
- You usually should not change advanced auth options.
|
|
128
|
+
|
|
129
|
+
## Useful Commands
|
|
130
|
+
|
|
131
|
+
- Setup once:
|
|
132
|
+
- `npm run cocoon:setup`
|
|
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`
|
|
143
|
+
|
|
144
|
+
## Troubleshooting
|
|
145
|
+
|
|
146
|
+
- `Proxy requires long auth` or secret mismatch:
|
|
147
|
+
- run `npm run cocoon:setup` again and update `.env` with fresh output.
|
|
148
|
+
- TLS handshake closes immediately:
|
|
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`.
|
|
152
|
+
|
|
153
|
+
## Security
|
|
154
|
+
|
|
155
|
+
- Never commit `.env`, mnemonics, secrets, or private keys.
|
|
156
|
+
- Treat `/tmp/cocoon-client-*.key.pem` as sensitive.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|