@basedchef/contextkit 0.1.1 → 0.1.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 basedchef
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,30 +1,96 @@
1
- # contextkit TypeScript SDK
1
+ # @basedchef/contextkit
2
2
 
3
- Typed SDK for ContextKit, the x402-powered context infrastructure API for AI agents.
3
+ TypeScript SDK for ContextKit, a Bankr-hosted x402 context API for AI agents.
4
+
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
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @basedchef/contextkit
11
+ ```
12
+
13
+ ## What It Does
14
+
15
+ - Summarize long agent conversations into compact continuation state.
16
+ - Compress project context into reusable machine-optimized memory.
17
+ - Generate agent-to-agent handoff payloads.
18
+ - Extract durable user profile memory.
19
+ - Estimate tokens for API-key workflows.
20
+ - Verify signed ContextKit webhook deliveries.
21
+ - Attach API keys for direct API integrations.
22
+ - Use account credits so SDK users can call paid endpoints without Bankr.
23
+ - Optionally attach an x402 payment handler when credits are not available.
24
+
25
+ ## Quick Start
4
26
 
5
27
  ```ts
6
- import { ContextKit } from "contextkit";
28
+ import { ContextKit } from "@basedchef/contextkit";
7
29
 
8
30
  const client = new ContextKit({
9
31
  apiKey: process.env.CONTEXTKIT_API_KEY!,
10
- x402: async (challenge) => wallet.pay(challenge)
32
+ baseUrl: "https://91.107.248.223.sslip.io"
11
33
  });
12
34
 
13
- const response = await client.summarize({ messages });
35
+ const response = await client.summarize({
36
+ messages: [
37
+ {
38
+ role: "user",
39
+ content: "Summarize this long project context for the next AI agent."
40
+ }
41
+ ],
42
+ mode: "compact"
43
+ });
44
+ ```
45
+
46
+ ## API Methods
47
+
48
+ ```ts
49
+ await client.summarize({ messages, mode: "micro" });
50
+ await client.compressContext({ messages });
51
+ await client.handoff({ messages });
52
+ await client.extractProfile({ messages });
53
+ await client.estimateTokens({ modelFamily: "openai", input: messages });
54
+ await client.credits();
55
+ ```
56
+
57
+ ## Bankr-Hosted x402 Path
58
+
59
+ Most users and agents do not need the SDK. They can call the hosted paid endpoint from a Bankr-authenticated terminal:
60
+
61
+ ```bash
62
+ bankr x402 call https://x402.bankr.bot/0xdace98cd605dd56b2edc66f0f4df3687f64fd824/contextkit-summarize \
63
+ -X POST \
64
+ -d '{"messages":[{"role":"user","content":"Summarize this context."}]}'
65
+ ```
66
+
67
+ That flow requires no ContextKit API key, no npm package, and no SDK.
68
+
69
+ ## Direct API Path
70
+
71
+ The SDK is for direct API integrations. If the API key owner has ContextKit credits, paid generation routes run without Bankr and deduct the endpoint price from the account balance. If credits are insufficient, the API falls back to the standard x402 payment challenge.
72
+
73
+ ```ts
74
+ const client = new ContextKit({
75
+ apiKey: process.env.CONTEXTKIT_API_KEY!,
76
+ baseUrl: "https://91.107.248.223.sslip.io"
77
+ });
14
78
  ```
15
79
 
16
- ## Methods
80
+ Optional x402 fallback:
17
81
 
18
- - `summarize(request)`
19
- - `compressContext(request)`
20
- - `handoff(request)`
21
- - `extractProfile(request)`
22
- - `estimateTokens(request)`
82
+ ```ts
83
+ const client = new ContextKit({
84
+ apiKey: process.env.CONTEXTKIT_API_KEY!,
85
+ baseUrl: "https://91.107.248.223.sslip.io",
86
+ x402: async (challenge) => wallet.pay(challenge)
87
+ });
88
+ ```
23
89
 
24
90
  ## Webhook Verification
25
91
 
26
92
  ```ts
27
- import { verifyContextKitWebhook } from "contextkit";
93
+ import { verifyContextKitWebhook } from "@basedchef/contextkit";
28
94
 
29
95
  const valid = await verifyContextKitWebhook({
30
96
  payload: rawBody,
@@ -33,9 +99,6 @@ const valid = await verifyContextKitWebhook({
33
99
  });
34
100
  ```
35
101
 
36
- ## Build
102
+ ## License
37
103
 
38
- ```bash
39
- npm install
40
- npm run build
41
- ```
104
+ MIT
package/dist/index.cjs CHANGED
@@ -60,6 +60,20 @@ var ContextKit = class {
60
60
  async estimateTokens(input) {
61
61
  return this.post("/api/tokens/estimate", input);
62
62
  }
63
+ credits() {
64
+ return this.get("/api/auth/credits");
65
+ }
66
+ async get(path) {
67
+ const response = await this.fetcher(`${this.baseUrl.replace(/\/$/, "")}${path}`, {
68
+ headers: {
69
+ Authorization: `Bearer ${this.options.apiKey}`
70
+ }
71
+ });
72
+ if (response.ok) {
73
+ return await response.json();
74
+ }
75
+ throw new ContextKitError(response.status, await response.text());
76
+ }
63
77
  async post(path, body) {
64
78
  const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
65
79
  const init = {
package/dist/index.d.cts CHANGED
@@ -191,6 +191,23 @@ type MemoryEnrichmentResponse = {
191
191
  deprecatedMemories: string[];
192
192
  confidence: number;
193
193
  };
194
+ type CreditEvent = {
195
+ id: string;
196
+ ownerId: string;
197
+ type: "grant" | "debit" | "refund";
198
+ amountUsd: number;
199
+ balanceAfterUsd: number;
200
+ route?: string;
201
+ requestId?: string;
202
+ apiKeyId?: string;
203
+ note?: string;
204
+ createdAt: string;
205
+ };
206
+ type CreditsResponse = {
207
+ ownerId: string;
208
+ balanceUsd: number;
209
+ events: CreditEvent[];
210
+ };
194
211
  type X402PaymentHandler = (challenge: unknown, request: RequestInit & {
195
212
  url: string;
196
213
  }) => Promise<string>;
@@ -219,6 +236,8 @@ declare class ContextKit {
219
236
  compressedTokens: number;
220
237
  reductionPercent: number;
221
238
  }>;
239
+ credits(): Promise<CreditsResponse>;
240
+ private get;
222
241
  private post;
223
242
  }
224
243
  declare class ContextKitError extends Error {
@@ -253,4 +272,4 @@ declare function getFirstX402Requirement(challenge: X402Challenge): {
253
272
  };
254
273
  declare function encodeX402Payment(payment: unknown): string;
255
274
 
256
- export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
275
+ export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type CreditEvent, type CreditsResponse, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
package/dist/index.d.ts CHANGED
@@ -191,6 +191,23 @@ type MemoryEnrichmentResponse = {
191
191
  deprecatedMemories: string[];
192
192
  confidence: number;
193
193
  };
194
+ type CreditEvent = {
195
+ id: string;
196
+ ownerId: string;
197
+ type: "grant" | "debit" | "refund";
198
+ amountUsd: number;
199
+ balanceAfterUsd: number;
200
+ route?: string;
201
+ requestId?: string;
202
+ apiKeyId?: string;
203
+ note?: string;
204
+ createdAt: string;
205
+ };
206
+ type CreditsResponse = {
207
+ ownerId: string;
208
+ balanceUsd: number;
209
+ events: CreditEvent[];
210
+ };
194
211
  type X402PaymentHandler = (challenge: unknown, request: RequestInit & {
195
212
  url: string;
196
213
  }) => Promise<string>;
@@ -219,6 +236,8 @@ declare class ContextKit {
219
236
  compressedTokens: number;
220
237
  reductionPercent: number;
221
238
  }>;
239
+ credits(): Promise<CreditsResponse>;
240
+ private get;
222
241
  private post;
223
242
  }
224
243
  declare class ContextKitError extends Error {
@@ -253,4 +272,4 @@ declare function getFirstX402Requirement(challenge: X402Challenge): {
253
272
  };
254
273
  declare function encodeX402Payment(payment: unknown): string;
255
274
 
256
- export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
275
+ export { type CompressContextResponse, ContextKit, ContextKitError, type ContextRequest, type ConversationMessage, type CreditEvent, type CreditsResponse, type HandoffResponse, type MemoryEnrichmentResponse, type ProfileResponse, type SummarizeResponse, type X402PaymentHandler, encodeX402Payment, getFirstX402Requirement, verifyContextKitWebhook };
package/dist/index.js CHANGED
@@ -30,6 +30,20 @@ var ContextKit = class {
30
30
  async estimateTokens(input) {
31
31
  return this.post("/api/tokens/estimate", input);
32
32
  }
33
+ credits() {
34
+ return this.get("/api/auth/credits");
35
+ }
36
+ async get(path) {
37
+ const response = await this.fetcher(`${this.baseUrl.replace(/\/$/, "")}${path}`, {
38
+ headers: {
39
+ Authorization: `Bearer ${this.options.apiKey}`
40
+ }
41
+ });
42
+ if (response.ok) {
43
+ return await response.json();
44
+ }
45
+ throw new ContextKitError(response.status, await response.text());
46
+ }
33
47
  async post(path, body) {
34
48
  const url = `${this.baseUrl.replace(/\/$/, "")}${path}`;
35
49
  const init = {
package/package.json CHANGED
@@ -1,14 +1,40 @@
1
1
  {
2
2
  "name": "@basedchef/contextkit",
3
- "version": "0.1.1",
4
- "description": "TypeScript SDK for ContextKit context infrastructure APIs.",
3
+ "version": "0.1.3",
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",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist",
11
- "README.md"
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "basedchef",
16
+ "homepage": "https://91.107.248.223.sslip.io",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/arsalang75523/contextkit.git",
20
+ "directory": "packages/sdk"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/arsalang75523/contextkit/issues"
24
+ },
25
+ "keywords": [
26
+ "contextkit",
27
+ "ai",
28
+ "ai-agents",
29
+ "agent-memory",
30
+ "context-compression",
31
+ "context-engineering",
32
+ "summarization",
33
+ "handoff",
34
+ "webhooks",
35
+ "x402",
36
+ "bankr",
37
+ "typescript-sdk"
12
38
  ],
13
39
  "sideEffects": false,
14
40
  "publishConfig": {