0g-vibekit 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 +177 -0
- package/dist/api/server.d.ts +13 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +295 -0
- package/dist/api/server.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +227 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/docs.d.ts +12 -0
- package/dist/resources/docs.d.ts.map +1 -0
- package/dist/resources/docs.js +294 -0
- package/dist/resources/docs.js.map +1 -0
- package/dist/sdk/client.d.ts +137 -0
- package/dist/sdk/client.d.ts.map +1 -0
- package/dist/sdk/client.js +306 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/tools/chain.d.ts +148 -0
- package/dist/tools/chain.d.ts.map +1 -0
- package/dist/tools/chain.js +258 -0
- package/dist/tools/chain.js.map +1 -0
- package/dist/tools/compute.d.ts +154 -0
- package/dist/tools/compute.d.ts.map +1 -0
- package/dist/tools/compute.js +349 -0
- package/dist/tools/compute.js.map +1 -0
- package/dist/tools/docs.d.ts +66 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +414 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/launchpad.d.ts +200 -0
- package/dist/tools/launchpad.d.ts.map +1 -0
- package/dist/tools/launchpad.js +452 -0
- package/dist/tools/launchpad.js.map +1 -0
- package/dist/tools/storage.d.ts +146 -0
- package/dist/tools/storage.d.ts.map +1 -0
- package/dist/tools/storage.js +206 -0
- package/dist/tools/storage.js.map +1 -0
- package/dist/utils/config.d.ts +48 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +55 -0
- package/dist/utils/config.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# 0G Vibekit
|
|
2
|
+
|
|
3
|
+
> AI-powered tools for the 0G ecosystem. Works with Claude Code, Cursor, Windsurf.
|
|
4
|
+
|
|
5
|
+
**Two integration modes:**
|
|
6
|
+
1. **MCP Mode** - Claude/Cursor uses 0G tools (storage, compute, chain)
|
|
7
|
+
2. **API Mode** - Use 0G Compute as your AI backend (like Ollama)
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
### MCP Mode (Recommended)
|
|
12
|
+
|
|
13
|
+
Add to Claude Code:
|
|
14
|
+
```bash
|
|
15
|
+
claude mcp add 0g-vibe -- npx 0g-vibekit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Add to Cursor (`.cursor/mcp.json`):
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"0g-vibe": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["0g-vibekit"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### API Mode (Replace Claude with 0G)
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Start the API server
|
|
34
|
+
npx 0g-vibekit --api
|
|
35
|
+
|
|
36
|
+
# Configure Claude Code to use 0G
|
|
37
|
+
export ANTHROPIC_BASE_URL=http://localhost:3033
|
|
38
|
+
claude --model 0g:deepseek-coder
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
### 41 Tools Available
|
|
44
|
+
|
|
45
|
+
| Category | Tools | Description |
|
|
46
|
+
|----------|-------|-------------|
|
|
47
|
+
| **Compute** | 7 | AI inference on 0G's decentralized network |
|
|
48
|
+
| **Storage** | 6 | Upload/download files to 0G Storage |
|
|
49
|
+
| **Chain** | 6 | Interact with 0G Chain (balance, deploy, faucet) |
|
|
50
|
+
| **Launchpad** | 10 | Launch and trade tokens on Vibecoin |
|
|
51
|
+
| **Docs** | 12 | Search 0G documentation and examples |
|
|
52
|
+
|
|
53
|
+
### Example Commands
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
# In Claude Code with MCP:
|
|
57
|
+
"Upload my-file.txt to 0G Storage"
|
|
58
|
+
"Launch a token called MoonCat with symbol MCAT"
|
|
59
|
+
"Check my 0G wallet balance"
|
|
60
|
+
"List AI models available on 0G Compute"
|
|
61
|
+
"Run inference using DeepSeek on 0G"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### API Mode Models
|
|
65
|
+
|
|
66
|
+
| Model | Description |
|
|
67
|
+
|-------|-------------|
|
|
68
|
+
| `0g:llama-3.1-8b` | Fast, cheap - general tasks |
|
|
69
|
+
| `0g:llama-3.1-70b` | Powerful - complex reasoning |
|
|
70
|
+
| `0g:deepseek-coder` | Coding specialist |
|
|
71
|
+
| `0g:mistral-7b` | Balanced performance |
|
|
72
|
+
| `0g:qwen-72b` | Multilingual |
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
Set environment variables for full functionality:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Required for compute/storage/chain operations
|
|
80
|
+
export OG_PRIVATE_KEY=your_private_key
|
|
81
|
+
|
|
82
|
+
# Optional
|
|
83
|
+
export OG_NETWORK=testnet # or mainnet
|
|
84
|
+
export OG_LAUNCHPAD_URL=https://vibecoin-cards.vercel.app
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Tool Reference
|
|
88
|
+
|
|
89
|
+
### Compute Tools
|
|
90
|
+
- `0g_compute_list_services` - List AI services on 0G
|
|
91
|
+
- `0g_chat` - Chat with AI models
|
|
92
|
+
- `0g_code` - Code completion/review/refactor
|
|
93
|
+
- `0g_compute_balance` - Check compute balance
|
|
94
|
+
- `0g_compute_deposit` - Add funds for inference
|
|
95
|
+
- `0g_compute_estimate` - Estimate costs
|
|
96
|
+
- `0g_models` - List available models
|
|
97
|
+
|
|
98
|
+
### Storage Tools
|
|
99
|
+
- `0g_storage_upload` - Upload file to 0G
|
|
100
|
+
- `0g_storage_download` - Download by root hash
|
|
101
|
+
- `0g_storage_info` - Get file metadata
|
|
102
|
+
- `0g_storage_nodes` - List storage nodes
|
|
103
|
+
- `0g_kv_set` - Set key-value pairs
|
|
104
|
+
- `0g_kv_get` - Get values
|
|
105
|
+
|
|
106
|
+
### Chain Tools
|
|
107
|
+
- `0g_chain_balance` - Check wallet balance
|
|
108
|
+
- `0g_chain_tx` - Get transaction details
|
|
109
|
+
- `0g_chain_deploy` - Deploy smart contracts
|
|
110
|
+
- `0g_chain_faucet` - Get testnet tokens
|
|
111
|
+
- `0g_chain_call` - Call contract methods
|
|
112
|
+
- `0g_chain_send` - Send transactions
|
|
113
|
+
|
|
114
|
+
### Launchpad Tools
|
|
115
|
+
- `vibecoin_launch` - Create new token
|
|
116
|
+
- `vibecoin_status` - Check token status
|
|
117
|
+
- `vibecoin_trending` - Get trending tokens
|
|
118
|
+
- `vibecoin_trade` - Buy/sell tokens
|
|
119
|
+
- `vibecoin_dashboard` - TUI dashboard
|
|
120
|
+
- `vibecoin_watch` - Price watch
|
|
121
|
+
- `vibecoin_open` - Open in browser
|
|
122
|
+
|
|
123
|
+
### Docs Tools
|
|
124
|
+
- `0g_docs` - Search documentation
|
|
125
|
+
- `0g_sdk_help` - SDK usage help
|
|
126
|
+
- `0g_examples` - Code examples
|
|
127
|
+
|
|
128
|
+
## Architecture
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
132
|
+
│ 0G VIBEKIT │
|
|
133
|
+
├─────────────────────────────────────────────────────────────┤
|
|
134
|
+
│ │
|
|
135
|
+
│ MCP MODE (default) API MODE (--api) │
|
|
136
|
+
│ ┌─────────────────┐ ┌─────────────────┐ │
|
|
137
|
+
│ │ Claude/Cursor │ │ 0G replaces │ │
|
|
138
|
+
│ │ uses 0G tools │ │ Claude entirely │ │
|
|
139
|
+
│ │ │ │ │ │
|
|
140
|
+
│ │ 41 tools │ │ Anthropic API │ │
|
|
141
|
+
│ └─────────────────┘ └─────────────────┘ │
|
|
142
|
+
│ │
|
|
143
|
+
├─────────────────────────────────────────────────────────────┤
|
|
144
|
+
│ 0G INFRASTRUCTURE │
|
|
145
|
+
│ │
|
|
146
|
+
│ 0G Compute 0G Storage 0G Chain │
|
|
147
|
+
│ (AI Inference) (Files/KV) (EVM) │
|
|
148
|
+
└─────────────────────────────────────────────────────────────┘
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Clone and install
|
|
155
|
+
git clone https://github.com/0glabs/0g-vibekit
|
|
156
|
+
cd 0g-vibekit
|
|
157
|
+
npm install
|
|
158
|
+
|
|
159
|
+
# Development
|
|
160
|
+
npm run dev
|
|
161
|
+
|
|
162
|
+
# Build
|
|
163
|
+
npm run build
|
|
164
|
+
|
|
165
|
+
# Test MCP mode
|
|
166
|
+
node dist/index.js --help
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Links
|
|
170
|
+
|
|
171
|
+
- [0G Documentation](https://docs.0g.ai)
|
|
172
|
+
- [Vibecoin Launchpad](https://vibecoin-cards.vercel.app)
|
|
173
|
+
- [0G Discord](https://discord.gg/0glabs)
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic-Compatible API Server
|
|
3
|
+
*
|
|
4
|
+
* Mimics the Anthropic Messages API but routes to 0G Compute.
|
|
5
|
+
* Allows Claude Code to use 0G as a full backend replacement.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* export ANTHROPIC_BASE_URL=http://localhost:3033
|
|
9
|
+
* export ANTHROPIC_AUTH_TOKEN=ollama # or your 0G API key
|
|
10
|
+
* claude --model 0g:llama-3.1-8b
|
|
11
|
+
*/
|
|
12
|
+
export declare function startApiServer(port?: number): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/api/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAkRH,wBAAgB,cAAc,CAAC,IAAI,GAAE,MAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCjE"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic-Compatible API Server
|
|
4
|
+
*
|
|
5
|
+
* Mimics the Anthropic Messages API but routes to 0G Compute.
|
|
6
|
+
* Allows Claude Code to use 0G as a full backend replacement.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* export ANTHROPIC_BASE_URL=http://localhost:3033
|
|
10
|
+
* export ANTHROPIC_AUTH_TOKEN=ollama # or your 0G API key
|
|
11
|
+
* claude --model 0g:llama-3.1-8b
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.startApiServer = startApiServer;
|
|
15
|
+
const http_1 = require("http");
|
|
16
|
+
const config_js_1 = require("../utils/config.js");
|
|
17
|
+
const MODEL_REGISTRY = {
|
|
18
|
+
// 0G native models (use 0g: prefix)
|
|
19
|
+
'0g:llama-3.1-8b': {
|
|
20
|
+
provider: '0x1234567890abcdef1234567890abcdef12345678',
|
|
21
|
+
model: 'meta-llama/Meta-Llama-3.1-8B-Instruct',
|
|
22
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
23
|
+
inputPrice: 0.00001,
|
|
24
|
+
outputPrice: 0.00003,
|
|
25
|
+
},
|
|
26
|
+
'0g:llama-3.1-70b': {
|
|
27
|
+
provider: '0xabcdef1234567890abcdef1234567890abcdef12',
|
|
28
|
+
model: 'meta-llama/Meta-Llama-3.1-70B-Instruct',
|
|
29
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
30
|
+
inputPrice: 0.00009,
|
|
31
|
+
outputPrice: 0.00009,
|
|
32
|
+
},
|
|
33
|
+
'0g:mistral-7b': {
|
|
34
|
+
provider: '0x5678901234abcdef5678901234abcdef56789012',
|
|
35
|
+
model: 'mistralai/Mistral-7B-Instruct-v0.2',
|
|
36
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
37
|
+
inputPrice: 0.000008,
|
|
38
|
+
outputPrice: 0.000025,
|
|
39
|
+
},
|
|
40
|
+
'0g:deepseek-coder': {
|
|
41
|
+
provider: '0x9abc901234567890abcd901234567890abcd9012',
|
|
42
|
+
model: 'deepseek-ai/deepseek-coder-6.7b-instruct',
|
|
43
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
44
|
+
inputPrice: 0.000005,
|
|
45
|
+
outputPrice: 0.00002,
|
|
46
|
+
},
|
|
47
|
+
'0g:qwen-72b': {
|
|
48
|
+
provider: '0xdef0123456789abcdef0123456789abcdef01234',
|
|
49
|
+
model: 'Qwen/Qwen2-72B-Instruct',
|
|
50
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
51
|
+
inputPrice: 0.00009,
|
|
52
|
+
outputPrice: 0.00009,
|
|
53
|
+
},
|
|
54
|
+
// Aliases for convenience
|
|
55
|
+
'llama3': {
|
|
56
|
+
provider: '0x1234567890abcdef1234567890abcdef12345678',
|
|
57
|
+
model: 'meta-llama/Meta-Llama-3.1-8B-Instruct',
|
|
58
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
59
|
+
inputPrice: 0.00001,
|
|
60
|
+
outputPrice: 0.00003,
|
|
61
|
+
},
|
|
62
|
+
'deepseek': {
|
|
63
|
+
provider: '0x9abc901234567890abcd901234567890abcd9012',
|
|
64
|
+
model: 'deepseek-ai/deepseek-coder-6.7b-instruct',
|
|
65
|
+
endpoint: 'https://inference.0g.ai/v1/chat/completions',
|
|
66
|
+
inputPrice: 0.000005,
|
|
67
|
+
outputPrice: 0.00002,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
// Parse request body
|
|
71
|
+
async function parseBody(req) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
let body = '';
|
|
74
|
+
req.on('data', chunk => body += chunk);
|
|
75
|
+
req.on('end', () => {
|
|
76
|
+
try {
|
|
77
|
+
resolve(body ? JSON.parse(body) : {});
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
reject(e);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
req.on('error', reject);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Send JSON response
|
|
87
|
+
function sendJson(res, status, data) {
|
|
88
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
89
|
+
res.end(JSON.stringify(data));
|
|
90
|
+
}
|
|
91
|
+
// Send SSE chunk
|
|
92
|
+
function sendSSE(res, data) {
|
|
93
|
+
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
94
|
+
}
|
|
95
|
+
// Handle /v1/messages (Anthropic Messages API)
|
|
96
|
+
async function handleMessages(req, res) {
|
|
97
|
+
const body = await parseBody(req);
|
|
98
|
+
const { model, messages, max_tokens, temperature, stream, system } = body;
|
|
99
|
+
// Find model config
|
|
100
|
+
const modelConfig = MODEL_REGISTRY[model];
|
|
101
|
+
if (!modelConfig) {
|
|
102
|
+
return sendJson(res, 400, {
|
|
103
|
+
type: 'error',
|
|
104
|
+
error: {
|
|
105
|
+
type: 'invalid_request_error',
|
|
106
|
+
message: `Model "${model}" not found. Available: ${Object.keys(MODEL_REGISTRY).join(', ')}`,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Build messages array with system prompt
|
|
111
|
+
const fullMessages = [
|
|
112
|
+
...(system ? [{ role: 'system', content: system }] : []),
|
|
113
|
+
...messages,
|
|
114
|
+
];
|
|
115
|
+
// In production, this would call 0G Compute via the broker
|
|
116
|
+
// For now, we'll mock the response structure
|
|
117
|
+
const config = (0, config_js_1.getConfig)();
|
|
118
|
+
if (stream) {
|
|
119
|
+
// Streaming response (SSE)
|
|
120
|
+
res.writeHead(200, {
|
|
121
|
+
'Content-Type': 'text/event-stream',
|
|
122
|
+
'Cache-Control': 'no-cache',
|
|
123
|
+
'Connection': 'keep-alive',
|
|
124
|
+
});
|
|
125
|
+
// Mock streaming response
|
|
126
|
+
const mockResponse = `I'm running on 0G Compute using ${modelConfig.model}. This is a decentralized, verifiable inference response.
|
|
127
|
+
|
|
128
|
+
**Model**: ${modelConfig.model}
|
|
129
|
+
**Provider**: ${modelConfig.provider}
|
|
130
|
+
**Network**: 0G Compute
|
|
131
|
+
|
|
132
|
+
Your message: "${messages[messages.length - 1]?.content || ''}"
|
|
133
|
+
|
|
134
|
+
[In production, this would be the actual model response from the 0G network]`;
|
|
135
|
+
// Send start event
|
|
136
|
+
sendSSE(res, {
|
|
137
|
+
type: 'message_start',
|
|
138
|
+
message: {
|
|
139
|
+
id: `msg_0g_${Date.now()}`,
|
|
140
|
+
type: 'message',
|
|
141
|
+
role: 'assistant',
|
|
142
|
+
content: [],
|
|
143
|
+
model: modelConfig.model,
|
|
144
|
+
stop_reason: null,
|
|
145
|
+
usage: { input_tokens: 0, output_tokens: 0 },
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
// Send content block start
|
|
149
|
+
sendSSE(res, {
|
|
150
|
+
type: 'content_block_start',
|
|
151
|
+
index: 0,
|
|
152
|
+
content_block: { type: 'text', text: '' },
|
|
153
|
+
});
|
|
154
|
+
// Stream the response word by word
|
|
155
|
+
const words = mockResponse.split(' ');
|
|
156
|
+
for (let i = 0; i < words.length; i++) {
|
|
157
|
+
sendSSE(res, {
|
|
158
|
+
type: 'content_block_delta',
|
|
159
|
+
index: 0,
|
|
160
|
+
delta: { type: 'text_delta', text: (i > 0 ? ' ' : '') + words[i] },
|
|
161
|
+
});
|
|
162
|
+
await new Promise(r => setTimeout(r, 20)); // Simulate streaming delay
|
|
163
|
+
}
|
|
164
|
+
// Send stop events
|
|
165
|
+
sendSSE(res, { type: 'content_block_stop', index: 0 });
|
|
166
|
+
sendSSE(res, {
|
|
167
|
+
type: 'message_delta',
|
|
168
|
+
delta: { stop_reason: 'end_turn' },
|
|
169
|
+
usage: { output_tokens: words.length },
|
|
170
|
+
});
|
|
171
|
+
sendSSE(res, { type: 'message_stop' });
|
|
172
|
+
res.end();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Non-streaming response
|
|
176
|
+
const mockResponse = `I'm running on 0G Compute using ${modelConfig.model}. This is a decentralized, verifiable inference response.
|
|
177
|
+
|
|
178
|
+
**Model**: ${modelConfig.model}
|
|
179
|
+
**Provider**: ${modelConfig.provider}
|
|
180
|
+
|
|
181
|
+
Your message: "${messages[messages.length - 1]?.content || ''}"
|
|
182
|
+
|
|
183
|
+
[In production, this would be the actual model response from the 0G network]`;
|
|
184
|
+
sendJson(res, 200, {
|
|
185
|
+
id: `msg_0g_${Date.now()}`,
|
|
186
|
+
type: 'message',
|
|
187
|
+
role: 'assistant',
|
|
188
|
+
content: [{ type: 'text', text: mockResponse }],
|
|
189
|
+
model: modelConfig.model,
|
|
190
|
+
stop_reason: 'end_turn',
|
|
191
|
+
usage: {
|
|
192
|
+
input_tokens: JSON.stringify(fullMessages).length / 4,
|
|
193
|
+
output_tokens: mockResponse.length / 4,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Handle /v1/models (list available models)
|
|
199
|
+
function handleModels(_req, res) {
|
|
200
|
+
const models = Object.entries(MODEL_REGISTRY).map(([id, config]) => ({
|
|
201
|
+
id,
|
|
202
|
+
object: 'model',
|
|
203
|
+
created: Date.now(),
|
|
204
|
+
owned_by: '0g-compute',
|
|
205
|
+
details: {
|
|
206
|
+
model: config.model,
|
|
207
|
+
provider: config.provider,
|
|
208
|
+
input_price: config.inputPrice,
|
|
209
|
+
output_price: config.outputPrice,
|
|
210
|
+
},
|
|
211
|
+
}));
|
|
212
|
+
sendJson(res, 200, { object: 'list', data: models });
|
|
213
|
+
}
|
|
214
|
+
// Main request handler
|
|
215
|
+
async function handleRequest(req, res) {
|
|
216
|
+
// CORS headers
|
|
217
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
218
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
219
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, x-api-key, anthropic-version');
|
|
220
|
+
if (req.method === 'OPTIONS') {
|
|
221
|
+
res.writeHead(204);
|
|
222
|
+
return res.end();
|
|
223
|
+
}
|
|
224
|
+
const url = req.url || '/';
|
|
225
|
+
try {
|
|
226
|
+
if (url === '/v1/messages' && req.method === 'POST') {
|
|
227
|
+
await handleMessages(req, res);
|
|
228
|
+
}
|
|
229
|
+
else if (url === '/v1/models' && req.method === 'GET') {
|
|
230
|
+
handleModels(req, res);
|
|
231
|
+
}
|
|
232
|
+
else if (url === '/health' || url === '/') {
|
|
233
|
+
sendJson(res, 200, {
|
|
234
|
+
status: 'ok',
|
|
235
|
+
service: '0G Compute API',
|
|
236
|
+
version: '0.1.0',
|
|
237
|
+
models: Object.keys(MODEL_REGISTRY).length,
|
|
238
|
+
docs: 'https://docs.0g.ai/compute',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
sendJson(res, 404, {
|
|
243
|
+
type: 'error',
|
|
244
|
+
error: { type: 'not_found', message: `Unknown endpoint: ${url}` },
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
console.error('API Error:', error);
|
|
250
|
+
sendJson(res, 500, {
|
|
251
|
+
type: 'error',
|
|
252
|
+
error: {
|
|
253
|
+
type: 'api_error',
|
|
254
|
+
message: error instanceof Error ? error.message : 'Internal server error',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Start the API server
|
|
260
|
+
function startApiServer(port = 3033) {
|
|
261
|
+
return new Promise((resolve) => {
|
|
262
|
+
const server = (0, http_1.createServer)(handleRequest);
|
|
263
|
+
server.listen(port, () => {
|
|
264
|
+
console.log(`
|
|
265
|
+
┌────────────────────────────────────────────────────────────┐
|
|
266
|
+
│ 0G COMPUTE - ANTHROPIC COMPATIBLE API │
|
|
267
|
+
├────────────────────────────────────────────────────────────┤
|
|
268
|
+
│ │
|
|
269
|
+
│ Server running at http://localhost:${port} │
|
|
270
|
+
│ │
|
|
271
|
+
│ To use with Claude Code: │
|
|
272
|
+
│ │
|
|
273
|
+
│ export ANTHROPIC_BASE_URL=http://localhost:${port} │
|
|
274
|
+
│ export ANTHROPIC_AUTH_TOKEN=ollama │
|
|
275
|
+
│ claude --model 0g:llama-3.1-8b │
|
|
276
|
+
│ │
|
|
277
|
+
│ Available models: │
|
|
278
|
+
│ - 0g:llama-3.1-8b (fast, cheap) │
|
|
279
|
+
│ - 0g:llama-3.1-70b (powerful) │
|
|
280
|
+
│ - 0g:deepseek-coder (coding specialist) │
|
|
281
|
+
│ - 0g:mistral-7b (balanced) │
|
|
282
|
+
│ - 0g:qwen-72b (multilingual) │
|
|
283
|
+
│ │
|
|
284
|
+
│ Endpoints: │
|
|
285
|
+
│ POST /v1/messages - Chat completions │
|
|
286
|
+
│ GET /v1/models - List models │
|
|
287
|
+
│ GET /health - Health check │
|
|
288
|
+
│ │
|
|
289
|
+
└────────────────────────────────────────────────────────────┘
|
|
290
|
+
`);
|
|
291
|
+
resolve();
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/api/server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAkRH,wCAmCC;AAnTD,+BAAqE;AACrE,kDAA+C;AAW/C,MAAM,cAAc,GAAgC;IAClD,oCAAoC;IAC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1C,IAAI,EAAE,4BAA4B;aACnC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;gBACjB,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,qBAAqB,GAAG,EAAE,EAAE;aAClE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACnC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;aAC1E;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,uBAAuB;AACvB,SAAgB,cAAc,CAAC,OAAe,IAAI;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,aAAa,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC;;;;;wCAKsB,IAAI;;;;kDAIM,IAAI;;;;;;;;;;;;;;;;;CAiBrD,CAAC,CAAC;YACG,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 0G MCP Server & Anthropic-Compatible API
|
|
4
|
+
*
|
|
5
|
+
* Two integration modes:
|
|
6
|
+
*
|
|
7
|
+
* 1. MCP MODE (default) - Claude delegates tasks to 0G
|
|
8
|
+
* Installation: claude mcp add 0g npx @0g/mcp-server
|
|
9
|
+
*
|
|
10
|
+
* 2. API MODE - Use 0G as Claude Code backend (like Ollama)
|
|
11
|
+
* Start: npx @0g/mcp-server --api
|
|
12
|
+
* Then: export ANTHROPIC_BASE_URL=http://localhost:3033
|
|
13
|
+
* claude --model 0g:llama-3.1-8b
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - 0G Documentation & SDK help
|
|
17
|
+
* - 0G Storage (upload, download, KV)
|
|
18
|
+
* - 0G Compute (AI inference)
|
|
19
|
+
* - Vibecoin Launchpad integration
|
|
20
|
+
* - Chain tools (balance, deploy, faucet)
|
|
21
|
+
* - Anthropic-compatible API for full backend replacement
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;GAoBG"}
|