@blockrun/cc 0.6.1 → 0.7.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.
@@ -1,5 +1,7 @@
1
1
  import http from 'node:http';
2
2
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
3
+ const DEFAULT_MAX_TOKENS = 4096;
4
+ let lastOutputTokens = 0;
3
5
  export function createProxy(options) {
4
6
  const chain = options.chain || 'base';
5
7
  let baseWallet = null;
@@ -35,10 +37,18 @@ export function createProxy(options) {
35
37
  if (options.modelOverride && parsed.model) {
36
38
  parsed.model = options.modelOverride;
37
39
  }
38
- if (parsed.max_tokens && parsed.max_tokens > 8192) {
39
- const model = parsed.model || '';
40
- if (model.includes('deepseek') || model.includes('haiku')) {
41
- parsed.max_tokens = 8192;
40
+ if (parsed.max_tokens) {
41
+ const original = parsed.max_tokens;
42
+ const model = (parsed.model || '').toLowerCase();
43
+ const modelCap = (model.includes('deepseek') || model.includes('haiku') || model.includes('gpt-oss')) ? 8192 : 16384;
44
+ if (lastOutputTokens > 0) {
45
+ parsed.max_tokens = Math.min(lastOutputTokens, modelCap);
46
+ }
47
+ else {
48
+ parsed.max_tokens = Math.min(parsed.max_tokens, DEFAULT_MAX_TOKENS, modelCap);
49
+ }
50
+ if (original !== parsed.max_tokens) {
51
+ console.log(`[brcc] max_tokens: ${original} → ${parsed.max_tokens} (last output: ${lastOutputTokens || 'none'})`);
42
52
  }
43
53
  }
44
54
  body = JSON.stringify(parsed);
@@ -73,22 +83,44 @@ export function createProxy(options) {
73
83
  responseHeaders[k] = v;
74
84
  });
75
85
  res.writeHead(response.status, responseHeaders);
86
+ const isStreaming = responseHeaders['content-type']?.includes('text/event-stream');
76
87
  if (response.body) {
77
88
  const reader = response.body.getReader();
89
+ const decoder = new TextDecoder();
90
+ let lastChunkText = '';
78
91
  const pump = async () => {
79
92
  while (true) {
80
93
  const { done, value } = await reader.read();
81
94
  if (done) {
95
+ if (isStreaming && lastChunkText) {
96
+ const match = lastChunkText.match(/"output_tokens"\s*:\s*(\d+)/);
97
+ if (match) {
98
+ lastOutputTokens = parseInt(match[1], 10);
99
+ console.log(`[brcc] recorded output_tokens: ${lastOutputTokens} (stream)`);
100
+ }
101
+ }
82
102
  res.end();
83
103
  break;
84
104
  }
105
+ if (isStreaming) {
106
+ lastChunkText = decoder.decode(value, { stream: true });
107
+ }
85
108
  res.write(value);
86
109
  }
87
110
  };
88
111
  pump().catch(() => res.end());
89
112
  }
90
113
  else {
91
- res.end(await response.text());
114
+ const text = await response.text();
115
+ try {
116
+ const parsed = JSON.parse(text);
117
+ if (parsed.usage?.output_tokens) {
118
+ lastOutputTokens = parsed.usage.output_tokens;
119
+ console.log(`[brcc] recorded output_tokens: ${lastOutputTokens}`);
120
+ }
121
+ }
122
+ catch { /* not JSON */ }
123
+ res.end(text);
92
124
  }
93
125
  }
94
126
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/cc",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Run Claude Code with any model — no rate limits, no account locks, no phone verification. Pay per use with USDC.",
5
5
  "type": "module",
6
6
  "bin": {