@absmartly/claude-code-bridge 1.1.2 → 1.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/index.js +49 -3
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const { JSDOM } = require('jsdom')
|
|
|
10
10
|
|
|
11
11
|
const PREFERRED_PORTS = [3000, 3001, 3002, 3003, 3004]
|
|
12
12
|
const PORT = process.env.PORT ? parseInt(process.env.PORT) : null
|
|
13
|
+
const MAX_LOG_LENGTH = 3000 // ~one page of text
|
|
13
14
|
|
|
14
15
|
const app = express()
|
|
15
16
|
app.use(cors())
|
|
@@ -26,6 +27,50 @@ const conversationModels = new Map() // Stores model selection per conversation
|
|
|
26
27
|
// Global JSON schema - set by extension on first conversation
|
|
27
28
|
let globalJsonSchema = null
|
|
28
29
|
|
|
30
|
+
function truncateForLog(data, maxLength = MAX_LOG_LENGTH) {
|
|
31
|
+
let output
|
|
32
|
+
|
|
33
|
+
if (typeof data === 'string') {
|
|
34
|
+
output = data
|
|
35
|
+
} else if (typeof data === 'object') {
|
|
36
|
+
output = JSON.stringify(data, null, 2)
|
|
37
|
+
} else {
|
|
38
|
+
output = String(data)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (output.length <= maxLength) {
|
|
42
|
+
return output
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const truncated = output.substring(0, maxLength)
|
|
46
|
+
const remaining = output.length - maxLength
|
|
47
|
+
const linesRemaining = (output.substring(maxLength).match(/\n/g) || []).length
|
|
48
|
+
|
|
49
|
+
return `${truncated}\n\n... [truncated ${remaining} characters, ~${linesRemaining} more lines]`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function truncateToolUseResponses(event, maxLength = MAX_LOG_LENGTH) {
|
|
53
|
+
// Deep clone the event to avoid mutating the original
|
|
54
|
+
const cloned = JSON.parse(JSON.stringify(event))
|
|
55
|
+
|
|
56
|
+
// Check if event has result.toolUses array
|
|
57
|
+
if (cloned.result && Array.isArray(cloned.result.toolUses)) {
|
|
58
|
+
cloned.result.toolUses = cloned.result.toolUses.map(toolUse => {
|
|
59
|
+
if (toolUse.response && typeof toolUse.response === 'string' && toolUse.response.length > maxLength) {
|
|
60
|
+
const truncated = toolUse.response.substring(0, maxLength)
|
|
61
|
+
const remaining = toolUse.response.length - maxLength
|
|
62
|
+
return {
|
|
63
|
+
...toolUse,
|
|
64
|
+
response: `${truncated}\n\n... [truncated ${remaining} characters]`
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return toolUse
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return cloned
|
|
72
|
+
}
|
|
73
|
+
|
|
29
74
|
function checkClaudeAuth() {
|
|
30
75
|
try {
|
|
31
76
|
const credentialsPath = path.join(os.homedir(), '.claude', '.credentials.json')
|
|
@@ -207,7 +252,8 @@ function spawnClaudeForConversation(conversationId, systemPrompt, sessionId, isR
|
|
|
207
252
|
const event = JSON.parse(line)
|
|
208
253
|
console.log(`[${conversationId}] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`)
|
|
209
254
|
console.log(`[${conversationId}] 📦 RAW EVENT FROM CLAUDE CLI:`)
|
|
210
|
-
|
|
255
|
+
const truncatedEvent = truncateToolUseResponses(event)
|
|
256
|
+
console.log(truncateForLog(truncatedEvent))
|
|
211
257
|
console.log(`[${conversationId}] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`)
|
|
212
258
|
|
|
213
259
|
const res = activeStreams.get(conversationId)
|
|
@@ -223,7 +269,7 @@ function spawnClaudeForConversation(conversationId, systemPrompt, sessionId, isR
|
|
|
223
269
|
// Check if it matches our schema (has required fields)
|
|
224
270
|
if (parsedJson.domChanges && parsedJson.response && parsedJson.action) {
|
|
225
271
|
console.log(`[${conversationId}] ✅ Parsed JSON schema response, forwarding as structured data`)
|
|
226
|
-
console.log(`[${conversationId}] Structured data:`,
|
|
272
|
+
console.log(`[${conversationId}] Structured data:`, truncateForLog(parsedJson))
|
|
227
273
|
// Send as tool_use-style event for compatibility
|
|
228
274
|
res.write(`data: ${JSON.stringify({ type: 'tool_use', data: parsedJson })}\n\n`)
|
|
229
275
|
// Also send the response text for display
|
|
@@ -241,7 +287,7 @@ function spawnClaudeForConversation(conversationId, systemPrompt, sessionId, isR
|
|
|
241
287
|
} else if (block.type === 'tool_use' && block.input) {
|
|
242
288
|
// Handle tool_use blocks (shouldn't happen with --json-schema, but keep for safety)
|
|
243
289
|
console.log(`[${conversationId}] ✅ Found tool_use block, forwarding to client`)
|
|
244
|
-
console.log(`[${conversationId}] Tool input:`,
|
|
290
|
+
console.log(`[${conversationId}] Tool input:`, truncateForLog(block.input))
|
|
245
291
|
const toolInput = block.input
|
|
246
292
|
res.write(`data: ${JSON.stringify({ type: 'tool_use', data: toolInput })}\n\n`)
|
|
247
293
|
if (toolInput.response) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absmartly/claude-code-bridge",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "HTTP bridge server for ABsmartly Extension to communicate with Claude Code CLI",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"author": "ABsmartly",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@acemir/cssom": "^0.9.31",
|
|
22
23
|
"cors": "^2.8.5",
|
|
23
24
|
"dotenv": "^16.3.1",
|
|
24
25
|
"express": "^4.18.2",
|