@qwickapps/qwickbrain-proxy 1.0.3 → 1.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/dist/lib/__tests__/connection-manager.test.js +2 -2
- package/dist/lib/__tests__/connection-manager.test.js.map +1 -1
- package/dist/lib/__tests__/qwickbrain-client.test.js +3 -1
- package/dist/lib/__tests__/qwickbrain-client.test.js.map +1 -1
- package/dist/lib/connection-manager.d.ts +7 -0
- package/dist/lib/connection-manager.d.ts.map +1 -1
- package/dist/lib/connection-manager.js +57 -8
- package/dist/lib/connection-manager.js.map +1 -1
- package/dist/lib/proxy-server.d.ts +7 -0
- package/dist/lib/proxy-server.d.ts.map +1 -1
- package/dist/lib/proxy-server.js +41 -10
- package/dist/lib/proxy-server.js.map +1 -1
- package/dist/lib/qwickbrain-client.d.ts.map +1 -1
- package/dist/lib/qwickbrain-client.js +26 -16
- package/dist/lib/qwickbrain-client.js.map +1 -1
- package/dist/lib/sse-invalidation-listener.d.ts +5 -1
- package/dist/lib/sse-invalidation-listener.d.ts.map +1 -1
- package/dist/lib/sse-invalidation-listener.js +24 -18
- package/dist/lib/sse-invalidation-listener.js.map +1 -1
- package/dist/lib/tools.d.ts.map +1 -1
- package/dist/lib/tools.js +29 -4
- package/dist/lib/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/__tests__/connection-manager.test.ts +2 -2
- package/src/lib/__tests__/qwickbrain-client.test.ts +3 -1
- package/src/lib/connection-manager.ts +67 -8
- package/src/lib/proxy-server.ts +49 -12
- package/src/lib/qwickbrain-client.ts +29 -15
- package/src/lib/sse-invalidation-listener.ts +32 -18
- package/src/lib/tools.ts +29 -4
- package/.claude/engineering/bugs/BUG-qwickbrain-proxy-cache-and-design.md +0 -840
- package/.github/workflows/publish.yml +0 -105
|
@@ -11,8 +11,13 @@ interface InvalidationEvent {
|
|
|
11
11
|
export class SSEInvalidationListener {
|
|
12
12
|
private eventSource: EventSource | null = null;
|
|
13
13
|
private reconnectTimeout: NodeJS.Timeout | null = null;
|
|
14
|
-
private reconnectDelay = 5000; // 5 seconds
|
|
15
14
|
private isActive = false;
|
|
15
|
+
private reconnectAttempts = 0;
|
|
16
|
+
|
|
17
|
+
// Exponential backoff config
|
|
18
|
+
private readonly initialDelay = 5000; // 5 seconds
|
|
19
|
+
private readonly maxDelay = 300000; // 5 minutes
|
|
20
|
+
private readonly multiplier = 2;
|
|
16
21
|
|
|
17
22
|
constructor(
|
|
18
23
|
private url: string,
|
|
@@ -29,6 +34,7 @@ export class SSEInvalidationListener {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
this.isActive = true;
|
|
37
|
+
this.reconnectAttempts = 0;
|
|
32
38
|
this.connect();
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -54,7 +60,7 @@ export class SSEInvalidationListener {
|
|
|
54
60
|
|
|
55
61
|
this.eventSource.onopen = () => {
|
|
56
62
|
console.error('SSE invalidation listener connected');
|
|
57
|
-
|
|
63
|
+
this.reconnectAttempts = 0; // Reset on successful connection
|
|
58
64
|
if (this.reconnectTimeout) {
|
|
59
65
|
clearTimeout(this.reconnectTimeout);
|
|
60
66
|
this.reconnectTimeout = null;
|
|
@@ -62,18 +68,12 @@ export class SSEInvalidationListener {
|
|
|
62
68
|
};
|
|
63
69
|
|
|
64
70
|
this.eventSource.onerror = (error: any) => {
|
|
65
|
-
console.error('SSE invalidation listener error:', error);
|
|
71
|
+
console.error('SSE invalidation listener error:', error?.message || 'connection failed');
|
|
66
72
|
this.eventSource?.close();
|
|
67
73
|
this.eventSource = null;
|
|
68
74
|
|
|
69
|
-
// Schedule reconnection
|
|
70
|
-
|
|
71
|
-
console.error(`SSE reconnecting in ${this.reconnectDelay}ms...`);
|
|
72
|
-
this.reconnectTimeout = setTimeout(() => {
|
|
73
|
-
this.reconnectTimeout = null;
|
|
74
|
-
this.connect();
|
|
75
|
-
}, this.reconnectDelay);
|
|
76
|
-
}
|
|
75
|
+
// Schedule reconnection with exponential backoff
|
|
76
|
+
this.scheduleReconnect();
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
// Listen for document invalidation events
|
|
@@ -92,14 +92,27 @@ export class SSEInvalidationListener {
|
|
|
92
92
|
});
|
|
93
93
|
} catch (error) {
|
|
94
94
|
console.error('Failed to connect SSE invalidation listener:', error);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
this.scheduleReconnect();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private scheduleReconnect(): void {
|
|
100
|
+
if (!this.isActive || this.reconnectTimeout) {
|
|
101
|
+
return;
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
const delay = Math.min(
|
|
105
|
+
this.initialDelay * Math.pow(this.multiplier, this.reconnectAttempts),
|
|
106
|
+
this.maxDelay
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
this.reconnectAttempts++;
|
|
110
|
+
console.error(`SSE reconnecting in ${Math.round(delay / 1000)}s (attempt ${this.reconnectAttempts})...`);
|
|
111
|
+
|
|
112
|
+
this.reconnectTimeout = setTimeout(() => {
|
|
113
|
+
this.reconnectTimeout = null;
|
|
114
|
+
this.connect();
|
|
115
|
+
}, delay);
|
|
103
116
|
}
|
|
104
117
|
|
|
105
118
|
private async handleInvalidationEvent(data: string): Promise<void> {
|
|
@@ -148,6 +161,7 @@ export class SSEInvalidationListener {
|
|
|
148
161
|
*/
|
|
149
162
|
stop(): void {
|
|
150
163
|
this.isActive = false;
|
|
164
|
+
this.reconnectAttempts = 0;
|
|
151
165
|
|
|
152
166
|
if (this.reconnectTimeout) {
|
|
153
167
|
clearTimeout(this.reconnectTimeout);
|
package/src/lib/tools.ts
CHANGED
|
@@ -97,13 +97,13 @@ export const QWICKBRAIN_TOOLS: ToolDefinition[] = [
|
|
|
97
97
|
},
|
|
98
98
|
{
|
|
99
99
|
name: 'search_codebase',
|
|
100
|
-
description: '
|
|
100
|
+
description: 'Search for specific code entities (functions, classes, methods) in the indexed codebase. Returns a list of matching code entities with their locations, signatures, and relevance scores. Use this when you need to FIND specific code elements or get a list of relevant code locations. Uses hybrid search (BM25 keyword matching + semantic embeddings) for accurate results. Output: Structured list of code entities with file paths, line numbers, signatures, and scores.',
|
|
101
101
|
inputSchema: {
|
|
102
102
|
type: 'object',
|
|
103
103
|
properties: {
|
|
104
104
|
query: {
|
|
105
105
|
type: 'string',
|
|
106
|
-
description: '
|
|
106
|
+
description: 'Search query describing what code to find. Examples: "function to parse JSON", "class that handles authentication", "async method for file upload", "error handling utilities"',
|
|
107
107
|
},
|
|
108
108
|
limit: {
|
|
109
109
|
type: 'integer',
|
|
@@ -112,8 +112,33 @@ export const QWICKBRAIN_TOOLS: ToolDefinition[] = [
|
|
|
112
112
|
},
|
|
113
113
|
min_score: {
|
|
114
114
|
type: 'number',
|
|
115
|
-
description: 'Minimum
|
|
116
|
-
default: 0.
|
|
115
|
+
description: 'Minimum relevance score threshold (default: 0.3)',
|
|
116
|
+
default: 0.3,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
required: ['query'],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'ask_qwickai',
|
|
124
|
+
description: 'Ask a question and get an AI-generated natural language answer about the codebase. The AI searches the codebase, analyzes relevant code, and explains it in plain English. Use this when you need to UNDERSTAND how something works or get an explanation. Powered by Llama LLM for intelligent analysis and natural language responses. Output: Natural language explanation with references to specific code locations.',
|
|
125
|
+
inputSchema: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
properties: {
|
|
128
|
+
query: {
|
|
129
|
+
type: 'string',
|
|
130
|
+
description: 'Question about the codebase in natural language. Examples: "How does the authentication system work?", "What happens when a user logs in?", "Explain how database connections are managed", "What files are involved in processing payments?"',
|
|
131
|
+
},
|
|
132
|
+
max_results: {
|
|
133
|
+
type: 'integer',
|
|
134
|
+
description: 'Maximum code entities to analyze (default: 5, max: 10)',
|
|
135
|
+
default: 5,
|
|
136
|
+
},
|
|
137
|
+
model: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
description: 'LLM model to use (default: llama-3.1-8b, options: llama-3.1-8b, qwen-2.5-14b)',
|
|
140
|
+
default: 'llama-3.1-8b',
|
|
141
|
+
enum: ['llama-3.1-8b', 'qwen-2.5-14b'],
|
|
117
142
|
},
|
|
118
143
|
},
|
|
119
144
|
required: ['query'],
|