@blockrun/cc 0.7.2 → 0.8.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/dist/proxy/server.js +71 -4
- package/package.json +1 -1
package/dist/proxy/server.js
CHANGED
|
@@ -1,13 +1,60 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
const LOG_FILE = path.join(os.homedir(), '.blockrun', 'brcc-debug.log');
|
|
3
7
|
function debug(options, ...args) {
|
|
4
|
-
if (options.debug)
|
|
5
|
-
|
|
8
|
+
if (!options.debug)
|
|
9
|
+
return;
|
|
10
|
+
const msg = `[${new Date().toISOString()}] ${args.map(String).join(' ')}\n`;
|
|
11
|
+
try {
|
|
12
|
+
fs.mkdirSync(path.dirname(LOG_FILE), { recursive: true });
|
|
13
|
+
fs.appendFileSync(LOG_FILE, msg);
|
|
14
|
+
}
|
|
15
|
+
catch { /* ignore */ }
|
|
6
16
|
}
|
|
7
17
|
const DEFAULT_MAX_TOKENS = 4096;
|
|
8
18
|
let lastOutputTokens = 0;
|
|
19
|
+
// Model shortcuts for quick switching
|
|
20
|
+
const MODEL_SHORTCUTS = {
|
|
21
|
+
'gpt': 'openai/gpt-5.4',
|
|
22
|
+
'gpt5': 'openai/gpt-5.4',
|
|
23
|
+
'gpt-5': 'openai/gpt-5.4',
|
|
24
|
+
'gpt-5.4': 'openai/gpt-5.4',
|
|
25
|
+
'sonnet': 'anthropic/claude-sonnet-4.6',
|
|
26
|
+
'claude': 'anthropic/claude-sonnet-4.6',
|
|
27
|
+
'opus': 'anthropic/claude-opus-4.6',
|
|
28
|
+
'haiku': 'anthropic/claude-haiku-4.5',
|
|
29
|
+
'deepseek': 'deepseek/deepseek-chat',
|
|
30
|
+
'gemini': 'google/gemini-2.5-pro',
|
|
31
|
+
'grok': 'xai/grok-3',
|
|
32
|
+
'free': 'nvidia/gpt-oss-120b',
|
|
33
|
+
'mini': 'openai/gpt-5-mini',
|
|
34
|
+
'glm': 'zai/glm-5',
|
|
35
|
+
};
|
|
36
|
+
function detectModelSwitch(parsed) {
|
|
37
|
+
if (!parsed.messages || parsed.messages.length === 0)
|
|
38
|
+
return null;
|
|
39
|
+
const last = parsed.messages[parsed.messages.length - 1];
|
|
40
|
+
if (last.role !== 'user' || typeof last.content !== 'string')
|
|
41
|
+
return null;
|
|
42
|
+
const content = last.content.trim().toLowerCase();
|
|
43
|
+
const match = content.match(/^use\s+(.+)$/);
|
|
44
|
+
if (!match)
|
|
45
|
+
return null;
|
|
46
|
+
const modelInput = match[1].trim();
|
|
47
|
+
// Check shortcuts first
|
|
48
|
+
if (MODEL_SHORTCUTS[modelInput])
|
|
49
|
+
return MODEL_SHORTCUTS[modelInput];
|
|
50
|
+
// If it contains a slash, treat as full model ID
|
|
51
|
+
if (modelInput.includes('/'))
|
|
52
|
+
return modelInput;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
9
55
|
export function createProxy(options) {
|
|
10
56
|
const chain = options.chain || 'base';
|
|
57
|
+
let currentModel = options.modelOverride || null;
|
|
11
58
|
let baseWallet = null;
|
|
12
59
|
let solanaWallet = null;
|
|
13
60
|
if (chain === 'base') {
|
|
@@ -38,8 +85,28 @@ export function createProxy(options) {
|
|
|
38
85
|
if (body) {
|
|
39
86
|
try {
|
|
40
87
|
const parsed = JSON.parse(body);
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
// Intercept "use <model>" commands for in-session model switching
|
|
89
|
+
const switchCmd = detectModelSwitch(parsed);
|
|
90
|
+
if (switchCmd) {
|
|
91
|
+
currentModel = switchCmd;
|
|
92
|
+
debug(options, `model switched to: ${currentModel}`);
|
|
93
|
+
const fakeResponse = {
|
|
94
|
+
id: `msg_brcc_${Date.now()}`,
|
|
95
|
+
type: 'message',
|
|
96
|
+
role: 'assistant',
|
|
97
|
+
model: currentModel,
|
|
98
|
+
content: [{ type: 'text', text: `Switched to **${currentModel}**. All subsequent requests will use this model.` }],
|
|
99
|
+
stop_reason: 'end_turn',
|
|
100
|
+
stop_sequence: null,
|
|
101
|
+
usage: { input_tokens: 0, output_tokens: 10 },
|
|
102
|
+
};
|
|
103
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
104
|
+
res.end(JSON.stringify(fakeResponse));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Apply model override
|
|
108
|
+
if ((currentModel || options.modelOverride) && parsed.model) {
|
|
109
|
+
parsed.model = currentModel || options.modelOverride;
|
|
43
110
|
}
|
|
44
111
|
if (parsed.max_tokens) {
|
|
45
112
|
const original = parsed.max_tokens;
|