@basedchef/contextkit 0.1.3 → 0.1.4
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 +289 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,12 +4,6 @@ TypeScript SDK for ContextKit, a Bankr-hosted x402 context API for AI agents.
|
|
|
4
4
|
|
|
5
5
|
Use it when you are building a TypeScript integration that needs typed calls to ContextKit direct APIs, webhook verification, API-key credits, and optional x402 payment handling. For the simplest paid path, agents can still call the Bankr-hosted x402 endpoints directly without this SDK.
|
|
6
6
|
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @basedchef/contextkit
|
|
11
|
-
```
|
|
12
|
-
|
|
13
7
|
## What It Does
|
|
14
8
|
|
|
15
9
|
- Summarize long agent conversations into compact continuation state.
|
|
@@ -22,71 +16,294 @@ npm install @basedchef/contextkit
|
|
|
22
16
|
- Use account credits so SDK users can call paid endpoints without Bankr.
|
|
23
17
|
- Optionally attach an x402 payment handler when credits are not available.
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
ContextKit has two usage paths:
|
|
20
|
+
|
|
21
|
+
- **Bankr-hosted x402:** simplest paid path for users and agents. No SDK and no ContextKit API key required.
|
|
22
|
+
- **SDK + API key credits:** direct app integration. The user buys ContextKit credits, then your app calls ContextKit with an API key without requiring Bankr on every request.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @basedchef/contextkit
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Check
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
node --input-type=module -e 'import { ContextKit } from "@basedchef/contextkit"; console.log(typeof ContextKit)'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Expected:
|
|
37
|
+
|
|
38
|
+
```txt
|
|
39
|
+
function
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Create A Client
|
|
26
43
|
|
|
27
44
|
```ts
|
|
28
45
|
import { ContextKit } from "@basedchef/contextkit";
|
|
29
46
|
|
|
30
47
|
const client = new ContextKit({
|
|
31
|
-
apiKey:
|
|
48
|
+
apiKey: "ck_live_replace_me",
|
|
32
49
|
baseUrl: "https://91.107.248.223.sslip.io"
|
|
33
50
|
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API Key Credits
|
|
54
|
+
|
|
55
|
+
Paid direct endpoints use the API key owner's ContextKit credit balance first. If credits are available, no Bankr payment is needed per request.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const credits = await client.credits();
|
|
59
|
+
console.log(credits.balanceUsd);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Equivalent terminal test:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cat > credits.mjs <<'EOF'
|
|
66
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
67
|
+
|
|
68
|
+
const client = new ContextKit({
|
|
69
|
+
apiKey: "ck_live_replace_me",
|
|
70
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const result = await client.credits();
|
|
74
|
+
console.log(JSON.stringify(result, null, 2));
|
|
75
|
+
EOF
|
|
76
|
+
|
|
77
|
+
node credits.mjs
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If the balance is too low, direct paid routes return a normal HTTP 402 x402 challenge.
|
|
81
|
+
|
|
82
|
+
## Buy Credits
|
|
83
|
+
|
|
84
|
+
Users can top up credits from the ContextKit dashboard:
|
|
85
|
+
|
|
86
|
+
1. Sign in to the dashboard.
|
|
87
|
+
2. Open `/dashboard/credits`.
|
|
88
|
+
3. Create a USDC invoice.
|
|
89
|
+
4. Send the exact USDC amount on Base to the shown wallet.
|
|
90
|
+
5. Paste the transaction hash.
|
|
91
|
+
6. ContextKit verifies the transaction and credits the account automatically.
|
|
34
92
|
|
|
35
|
-
|
|
93
|
+
The backend verifies:
|
|
94
|
+
|
|
95
|
+
- the transaction exists on Base,
|
|
96
|
+
- the transaction succeeded,
|
|
97
|
+
- the Base USDC contract emitted a `Transfer`,
|
|
98
|
+
- the recipient is the ContextKit wallet,
|
|
99
|
+
- the amount is at least the invoice amount,
|
|
100
|
+
- the tx hash was not already used.
|
|
101
|
+
|
|
102
|
+
## Summarize
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
cat > summarize.mjs <<'EOF'
|
|
106
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
107
|
+
|
|
108
|
+
const client = new ContextKit({
|
|
109
|
+
apiKey: "ck_live_replace_me",
|
|
110
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const result = await client.summarize({
|
|
114
|
+
mode: "compact",
|
|
36
115
|
messages: [
|
|
37
116
|
{
|
|
38
117
|
role: "user",
|
|
39
|
-
content: "
|
|
118
|
+
content: "We are launching a night-bus pilot. Preserve current goal, blockers, constraints, and next actions for the next AI agent."
|
|
40
119
|
}
|
|
41
|
-
]
|
|
42
|
-
mode: "compact"
|
|
120
|
+
]
|
|
43
121
|
});
|
|
122
|
+
|
|
123
|
+
console.log(JSON.stringify(result, null, 2));
|
|
124
|
+
EOF
|
|
125
|
+
|
|
126
|
+
node summarize.mjs
|
|
44
127
|
```
|
|
45
128
|
|
|
46
|
-
|
|
129
|
+
Available summarize modes:
|
|
47
130
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
131
|
+
- `micro`: highest compression for agent memory.
|
|
132
|
+
- `compact`: default AI-to-AI transfer format.
|
|
133
|
+
- `extended`: human-readable continuation summary.
|
|
134
|
+
- `debug`: full diagnostic shape for development.
|
|
135
|
+
|
|
136
|
+
## Compress Context
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
cat > compress.mjs <<'EOF'
|
|
140
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
141
|
+
|
|
142
|
+
const client = new ContextKit({
|
|
143
|
+
apiKey: "ck_live_replace_me",
|
|
144
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const result = await client.compressContext({
|
|
148
|
+
messages: [
|
|
149
|
+
{
|
|
150
|
+
role: "user",
|
|
151
|
+
content: "Project Atlas is a transit analytics platform. Stack is Next.js, Postgres, Redis. Current issues are slow reports and missing operator onboarding. Deadline is beta in six weeks."
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log(JSON.stringify(result, null, 2));
|
|
157
|
+
EOF
|
|
158
|
+
|
|
159
|
+
node compress.mjs
|
|
55
160
|
```
|
|
56
161
|
|
|
57
|
-
##
|
|
162
|
+
## Handoff
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
cat > handoff.mjs <<'EOF'
|
|
166
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
58
167
|
|
|
59
|
-
|
|
168
|
+
const client = new ContextKit({
|
|
169
|
+
apiKey: "ck_live_replace_me",
|
|
170
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const result = await client.handoff({
|
|
174
|
+
messages: [
|
|
175
|
+
{
|
|
176
|
+
role: "user",
|
|
177
|
+
content: "ContextKit is live on Hetzner with Postgres, dashboard auth, API credits, webhooks, and Bankr-hosted x402. Next work is docs, SDK examples, credit top-up polish, and long-context demos."
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
console.log(JSON.stringify(result, null, 2));
|
|
183
|
+
EOF
|
|
184
|
+
|
|
185
|
+
node handoff.mjs
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Extract Profile
|
|
60
189
|
|
|
61
190
|
```bash
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
191
|
+
cat > profile.mjs <<'EOF'
|
|
192
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
193
|
+
|
|
194
|
+
const client = new ContextKit({
|
|
195
|
+
apiKey: "ck_live_replace_me",
|
|
196
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const result = await client.extractProfile({
|
|
200
|
+
messages: [
|
|
201
|
+
{
|
|
202
|
+
role: "user",
|
|
203
|
+
content: "I prefer short technical updates, direct debugging help, clear risks, and command-by-command deployment instructions."
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
console.log(JSON.stringify(result, null, 2));
|
|
209
|
+
EOF
|
|
210
|
+
|
|
211
|
+
node profile.mjs
|
|
65
212
|
```
|
|
66
213
|
|
|
67
|
-
|
|
214
|
+
## Memory Enrichment
|
|
68
215
|
|
|
69
|
-
|
|
216
|
+
`memoryEnrichment` is a direct API-key endpoint for evolving long-term memory. It is useful when your app already manages user accounts and wants durable memory without a per-request Bankr terminal flow.
|
|
70
217
|
|
|
71
|
-
|
|
218
|
+
```bash
|
|
219
|
+
cat > memory.mjs <<'EOF'
|
|
220
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
221
|
+
|
|
222
|
+
const client = new ContextKit({
|
|
223
|
+
apiKey: "ck_live_replace_me",
|
|
224
|
+
baseUrl: "https://91.107.248.223.sslip.io"
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const result = await client.memoryEnrichment({
|
|
228
|
+
messages: [
|
|
229
|
+
{
|
|
230
|
+
role: "user",
|
|
231
|
+
content: "I used to prefer long weekly reports, but now I want short risk-focused updates with clear next actions."
|
|
232
|
+
}
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
console.log(JSON.stringify(result, null, 2));
|
|
237
|
+
EOF
|
|
238
|
+
|
|
239
|
+
node memory.mjs
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Token Estimate
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
cat > estimate.mjs <<'EOF'
|
|
246
|
+
import { ContextKit } from "@basedchef/contextkit";
|
|
72
247
|
|
|
73
|
-
```ts
|
|
74
248
|
const client = new ContextKit({
|
|
75
|
-
apiKey:
|
|
249
|
+
apiKey: "ck_live_replace_me",
|
|
76
250
|
baseUrl: "https://91.107.248.223.sslip.io"
|
|
77
251
|
});
|
|
252
|
+
|
|
253
|
+
const result = await client.estimateTokens({
|
|
254
|
+
modelFamily: "openai",
|
|
255
|
+
input: [
|
|
256
|
+
{
|
|
257
|
+
role: "user",
|
|
258
|
+
content: "We need to preserve only goals, blockers, constraints, and next steps."
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
compressed: "Preserve goals, blockers, constraints, next steps."
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
console.log(JSON.stringify(result, null, 2));
|
|
265
|
+
EOF
|
|
266
|
+
|
|
267
|
+
node estimate.mjs
|
|
78
268
|
```
|
|
79
269
|
|
|
80
|
-
Optional x402
|
|
270
|
+
## Optional x402 Fallback
|
|
271
|
+
|
|
272
|
+
If an API key has no credits, ContextKit direct paid routes return HTTP 402. Advanced apps can provide an x402 payment handler.
|
|
81
273
|
|
|
82
274
|
```ts
|
|
83
275
|
const client = new ContextKit({
|
|
84
|
-
apiKey:
|
|
276
|
+
apiKey: "ck_live_replace_me",
|
|
85
277
|
baseUrl: "https://91.107.248.223.sslip.io",
|
|
86
|
-
x402: async (challenge) =>
|
|
278
|
+
x402: async (challenge, request) => {
|
|
279
|
+
return wallet.pay(challenge, request);
|
|
280
|
+
}
|
|
87
281
|
});
|
|
88
282
|
```
|
|
89
283
|
|
|
284
|
+
Most SDK integrations should instead top up credits from the dashboard and avoid per-request Bankr interaction.
|
|
285
|
+
|
|
286
|
+
## Bankr-Hosted x402 Without SDK
|
|
287
|
+
|
|
288
|
+
For simple users and autonomous agents, this is the main path:
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
bankr x402 call https://x402.bankr.bot/0xdace98cd605dd56b2edc66f0f4df3687f64fd824/contextkit-summarize \
|
|
292
|
+
-X POST \
|
|
293
|
+
-d '{"messages":[{"role":"user","content":"Summarize this context."}]}'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
This path requires:
|
|
297
|
+
|
|
298
|
+
- Bankr login
|
|
299
|
+
- USDC payment approval
|
|
300
|
+
|
|
301
|
+
This path does **not** require:
|
|
302
|
+
|
|
303
|
+
- ContextKit API key
|
|
304
|
+
- npm package
|
|
305
|
+
- SDK integration
|
|
306
|
+
|
|
90
307
|
## Webhook Verification
|
|
91
308
|
|
|
92
309
|
```ts
|
|
@@ -99,6 +316,45 @@ const valid = await verifyContextKitWebhook({
|
|
|
99
316
|
});
|
|
100
317
|
```
|
|
101
318
|
|
|
319
|
+
## Local SDK Development
|
|
320
|
+
|
|
321
|
+
From the repo root:
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
npm install
|
|
325
|
+
npm --workspace @basedchef/contextkit run typecheck
|
|
326
|
+
npm --workspace @basedchef/contextkit run build
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Publish a new SDK version:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
cd packages/sdk
|
|
333
|
+
npm version patch --no-git-tag-version
|
|
334
|
+
npm run build
|
|
335
|
+
npm publish --access public
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
If npm asks for browser auth or OTP, complete the npm prompt and retry with a fresh authenticator code.
|
|
339
|
+
|
|
340
|
+
## Troubleshooting
|
|
341
|
+
|
|
342
|
+
`ContextKit API request failed with 402`
|
|
343
|
+
|
|
344
|
+
Your API key has insufficient credits. Top up credits in `/dashboard/credits` or provide an x402 payment handler.
|
|
345
|
+
|
|
346
|
+
`ContextKit API request failed with 401`
|
|
347
|
+
|
|
348
|
+
The API key is invalid, revoked, or missing required scopes.
|
|
349
|
+
|
|
350
|
+
`npm publish` says version already exists
|
|
351
|
+
|
|
352
|
+
Increase `packages/sdk/package.json` version before publishing.
|
|
353
|
+
|
|
354
|
+
`npm publish` says OTP failed
|
|
355
|
+
|
|
356
|
+
Use the current six-digit authenticator code and make sure server time is synchronized.
|
|
357
|
+
|
|
102
358
|
## License
|
|
103
359
|
|
|
104
360
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basedchef/contextkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "TypeScript SDK for ContextKit, a Bankr-hosted x402 context API for AI agents, memory compression, handoffs, profiles, and webhooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|