codebuff 1.0.198 → 1.0.200
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/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.js +13 -15
- package/dist/client.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +98 -98
- package/dist/common/advanced-analyzer.d.ts +19 -0
- package/dist/common/advanced-analyzer.js +140 -0
- package/dist/common/advanced-analyzer.js.map +1 -0
- package/dist/common/constants.d.ts +3 -1
- package/dist/common/constants.js +2 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/message-image-handling.d.ts +41 -0
- package/dist/common/message-image-handling.js +57 -0
- package/dist/common/message-image-handling.js.map +1 -0
- package/dist/common/types/agent-state.d.ts +12 -12
- package/dist/common/types/message.d.ts +8 -8
- package/dist/common/util/lru-cache.d.ts +23 -2
- package/dist/common/util/lru-cache.js +44 -18
- package/dist/common/util/lru-cache.js.map +1 -1
- package/dist/common/util/messages.d.ts +1 -0
- package/dist/common/util/messages.js +15 -0
- package/dist/common/util/messages.js.map +1 -1
- package/dist/common/util/min-heap.js +2 -2
- package/dist/common/util/min-heap.js.map +1 -1
- package/dist/common/util/process-stream.d.ts +8 -0
- package/dist/common/util/process-stream.js +102 -0
- package/dist/common/util/process-stream.js.map +1 -0
- package/dist/common/util/referral-credits.d.ts +1 -0
- package/dist/common/util/referral-credits.js +48 -0
- package/dist/common/util/referral-credits.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +176 -176
- package/dist/fingerprint.js +7 -2
- package/dist/fingerprint.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/menu.js +1 -1
- package/dist/menu.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrowserResponse } from './browser-actions';
|
|
2
|
+
/**
|
|
3
|
+
* Each detected issue includes a type, severity, detection reason,
|
|
4
|
+
* and an optional recommendation for the user.
|
|
5
|
+
*/
|
|
6
|
+
export interface AnalysisIssue {
|
|
7
|
+
type: string;
|
|
8
|
+
severity: 'low' | 'medium' | 'high';
|
|
9
|
+
message: string;
|
|
10
|
+
recommendation?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AnalysisResult {
|
|
13
|
+
issues: AnalysisIssue[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Entrypoint function to run a suite of heuristic checks over
|
|
17
|
+
* logs, network events, performance metrics, etc.
|
|
18
|
+
*/
|
|
19
|
+
export declare function analyzeBrowserData(response: BrowserResponse): AnalysisResult;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeBrowserData = analyzeBrowserData;
|
|
4
|
+
/**
|
|
5
|
+
* Entrypoint function to run a suite of heuristic checks over
|
|
6
|
+
* logs, network events, performance metrics, etc.
|
|
7
|
+
*/
|
|
8
|
+
function analyzeBrowserData(response) {
|
|
9
|
+
const issues = [];
|
|
10
|
+
// 1. Check logs for known error patterns or repeated errors
|
|
11
|
+
issues.push(...analyzeLogs(response));
|
|
12
|
+
// 2. Check network events for 4xx, 5xx, or suspicious patterns
|
|
13
|
+
issues.push(...analyzeNetwork(response));
|
|
14
|
+
// 3. Check performance metrics (TTFB, LCP, memory usage, etc.)
|
|
15
|
+
if (response.metrics) {
|
|
16
|
+
issues.push(...analyzePerformance(response.metrics));
|
|
17
|
+
}
|
|
18
|
+
// Return combined issues
|
|
19
|
+
return { issues };
|
|
20
|
+
}
|
|
21
|
+
function analyzeLogs(response) {
|
|
22
|
+
const issues = [];
|
|
23
|
+
const logs = response.logs || [];
|
|
24
|
+
// Check for high number of JavaScript errors
|
|
25
|
+
const jsErrors = logs.filter((log) => log.type === 'error');
|
|
26
|
+
if (jsErrors.length > 5) {
|
|
27
|
+
issues.push({
|
|
28
|
+
type: 'JS_ERROR_OVERFLOW',
|
|
29
|
+
severity: 'medium',
|
|
30
|
+
message: `Detected ${jsErrors.length} JavaScript errors in logs.`,
|
|
31
|
+
recommendation: 'Review the console logs for repeated error patterns. Fix the root cause or handle errors in code.'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Pattern-based error detection
|
|
35
|
+
const errorPatterns = {
|
|
36
|
+
'not defined': {
|
|
37
|
+
severity: 'medium',
|
|
38
|
+
recommendation: 'Check for missing script dependencies or undefined variables'
|
|
39
|
+
},
|
|
40
|
+
'Failed to fetch': {
|
|
41
|
+
severity: 'medium',
|
|
42
|
+
recommendation: 'Verify endpoint URLs and network connectivity'
|
|
43
|
+
},
|
|
44
|
+
'SSL': {
|
|
45
|
+
severity: 'high',
|
|
46
|
+
recommendation: 'SSL certificate error - check HTTPS configuration'
|
|
47
|
+
},
|
|
48
|
+
'ERR_NAME_NOT_RESOLVED': {
|
|
49
|
+
severity: 'medium',
|
|
50
|
+
recommendation: 'DNS resolution failed - check domain name'
|
|
51
|
+
},
|
|
52
|
+
'ERR_CONNECTION_TIMED_OUT': {
|
|
53
|
+
severity: 'medium',
|
|
54
|
+
recommendation: 'Connection timeout - check network or firewall'
|
|
55
|
+
},
|
|
56
|
+
'Navigation timeout': {
|
|
57
|
+
severity: 'medium',
|
|
58
|
+
recommendation: 'Page took too long to load - check performance or timeouts'
|
|
59
|
+
},
|
|
60
|
+
'Frame detached': {
|
|
61
|
+
severity: 'low',
|
|
62
|
+
recommendation: 'Target frame or element no longer exists'
|
|
63
|
+
},
|
|
64
|
+
'Node is detached': {
|
|
65
|
+
severity: 'low',
|
|
66
|
+
recommendation: 'Element was removed from DOM'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
for (const log of jsErrors) {
|
|
70
|
+
for (const [pattern, { severity, recommendation }] of Object.entries(errorPatterns)) {
|
|
71
|
+
if (log.message.includes(pattern)) {
|
|
72
|
+
issues.push({
|
|
73
|
+
type: 'JS_ERROR',
|
|
74
|
+
severity,
|
|
75
|
+
message: `Error detected: ${log.message}`,
|
|
76
|
+
recommendation
|
|
77
|
+
});
|
|
78
|
+
break; // Stop after first matching pattern
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return issues;
|
|
83
|
+
}
|
|
84
|
+
function analyzeNetwork(response) {
|
|
85
|
+
const issues = [];
|
|
86
|
+
const netEvents = response.networkEvents || [];
|
|
87
|
+
// Count 4xx / 5xx
|
|
88
|
+
const errorEvents = netEvents.filter((evt) => (evt.status && evt.status >= 400) || evt.errorText);
|
|
89
|
+
if (errorEvents.length > 0) {
|
|
90
|
+
issues.push({
|
|
91
|
+
type: 'NETWORK_ERRORS',
|
|
92
|
+
severity: 'medium',
|
|
93
|
+
message: `${errorEvents.length} network request(s) failed with 4xx/5xx error(s).`,
|
|
94
|
+
recommendation: 'Check your API endpoints and resource URLs. Verify server logs for possible configuration or routing issues.'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Detect repeated 404s
|
|
98
|
+
const fourOhFours = netEvents.filter((e) => e.status === 404);
|
|
99
|
+
if (fourOhFours.length > 2) {
|
|
100
|
+
issues.push({
|
|
101
|
+
type: 'MISSING_RESOURCES',
|
|
102
|
+
severity: 'low',
|
|
103
|
+
message: `${fourOhFours.length} resources returned 404 Not Found.`,
|
|
104
|
+
recommendation: 'Ensure static assets or pages exist at the requested path.'
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return issues;
|
|
108
|
+
}
|
|
109
|
+
function analyzePerformance(metrics) {
|
|
110
|
+
const issues = [];
|
|
111
|
+
// Check Time to First Byte
|
|
112
|
+
if ((metrics.ttfb ?? 0) > 1000) {
|
|
113
|
+
issues.push({
|
|
114
|
+
type: 'HIGH_TTFB',
|
|
115
|
+
severity: 'medium',
|
|
116
|
+
message: `Time to First Byte is ${metrics.ttfb}ms, which is high.`,
|
|
117
|
+
recommendation: 'Optimize server response times or check network constraints. Look for server-side bottlenecks.'
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Check memory usage
|
|
121
|
+
if (metrics.memoryUsage > 100_000_000) { // ~100MB in JS heap
|
|
122
|
+
issues.push({
|
|
123
|
+
type: 'HIGH_MEMORY_USAGE',
|
|
124
|
+
severity: 'medium',
|
|
125
|
+
message: `Memory usage reached ${metrics.memoryUsage} bytes in JS heap.`,
|
|
126
|
+
recommendation: 'Investigate potential memory leaks, unbounded data structures, or large on-page assets.'
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Check Largest Contentful Paint
|
|
130
|
+
if ((metrics.lcp ?? 0) > 4000) {
|
|
131
|
+
issues.push({
|
|
132
|
+
type: 'PERFORMANCE_LCP',
|
|
133
|
+
severity: 'medium',
|
|
134
|
+
message: `Largest Contentful Paint is ${metrics.lcp}ms (over 4s).`,
|
|
135
|
+
recommendation: 'Consider optimizing images, breaking up large bundle files, or deferring non-critical scripts.'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return issues;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=advanced-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced-analyzer.js","sourceRoot":"","sources":["../src/advanced-analyzer.ts"],"names":[],"mappings":";;AAqBA,gDAgBC;AApBD;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,QAAyB;IAC1D,MAAM,MAAM,GAAoB,EAAE,CAAA;IAElC,4DAA4D;IAC5D,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAA;IAErC,+DAA+D;IAC/D,MAAM,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAA;IAExC,+DAA+D;IAC/D,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC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@@ -37,7 +37,7 @@ export declare const PLAN_CONFIGS: Record<UsageLimits, PlanConfig>;
|
|
|
37
37
|
export declare const CREDITS_USAGE_LIMITS: Record<UsageLimits, number>;
|
|
38
38
|
export declare const costModes: readonly ["lite", "normal", "max"];
|
|
39
39
|
export type CostMode = (typeof costModes)[number];
|
|
40
|
-
export declare const getModelForMode: (costMode: CostMode, operation: "agent" | "file-requests" | "check-new-files") => "claude-3-5-sonnet-20241022" | "claude-3-5-haiku-20241022" | "gpt-4o-2024-11-20" | "gpt-4o-mini-2024-07-18";
|
|
40
|
+
export declare const getModelForMode: (costMode: CostMode, operation: "agent" | "file-requests" | "check-new-files") => "claude-3-5-sonnet-20241022" | "claude-3-5-haiku-20241022" | "gpt-4o-2024-11-20" | "gpt-4o-mini-2024-07-18" | "gemini-2.5-pro-exp-03-25";
|
|
41
41
|
export declare const claudeModels: {
|
|
42
42
|
readonly sonnet: "claude-3-5-sonnet-20241022";
|
|
43
43
|
readonly haiku: "claude-3-5-haiku-20241022";
|
|
@@ -52,6 +52,7 @@ export declare const openaiModels: {
|
|
|
52
52
|
export type OpenAIModel = (typeof openaiModels)[keyof typeof openaiModels];
|
|
53
53
|
export declare const geminiModels: {
|
|
54
54
|
readonly gemini2flash: "gemini-2.0-flash-001";
|
|
55
|
+
readonly gemini2_5_pro: "gemini-2.5-pro-exp-03-25";
|
|
55
56
|
};
|
|
56
57
|
export type GeminiModel = (typeof geminiModels)[keyof typeof geminiModels];
|
|
57
58
|
export declare const deepseekModels: {
|
|
@@ -63,6 +64,7 @@ export declare const models: {
|
|
|
63
64
|
readonly deepseekChat: "deepseek-chat";
|
|
64
65
|
readonly deepseekReasoner: "deepseek-reasoner";
|
|
65
66
|
readonly gemini2flash: "gemini-2.0-flash-001";
|
|
67
|
+
readonly gemini2_5_pro: "gemini-2.5-pro-exp-03-25";
|
|
66
68
|
readonly gpt4o: "gpt-4o-2024-11-20";
|
|
67
69
|
readonly gpt4omini: "gpt-4o-mini-2024-07-18";
|
|
68
70
|
readonly o3mini: "o3-mini-2025-01-31";
|
package/dist/common/constants.js
CHANGED
|
@@ -112,7 +112,7 @@ exports.CREDITS_USAGE_LIMITS = Object.fromEntries(Object.entries(exports.PLAN_CO
|
|
|
112
112
|
exports.costModes = ['lite', 'normal', 'max'];
|
|
113
113
|
const getModelForMode = (costMode, operation) => {
|
|
114
114
|
if (operation === 'agent') {
|
|
115
|
-
return costMode === 'lite' ? exports.claudeModels.haiku : exports.claudeModels.sonnet;
|
|
115
|
+
return costMode === 'max' ? exports.models.gemini2_5_pro : costMode === 'lite' ? exports.claudeModels.haiku : exports.claudeModels.sonnet;
|
|
116
116
|
}
|
|
117
117
|
if (operation === 'file-requests') {
|
|
118
118
|
return costMode === 'max' ? exports.claudeModels.sonnet : exports.claudeModels.haiku;
|
|
@@ -135,6 +135,7 @@ exports.openaiModels = {
|
|
|
135
135
|
};
|
|
136
136
|
exports.geminiModels = {
|
|
137
137
|
gemini2flash: 'gemini-2.0-flash-001',
|
|
138
|
+
gemini2_5_pro: 'gemini-2.5-pro-exp-03-25',
|
|
138
139
|
};
|
|
139
140
|
exports.deepseekModels = {
|
|
140
141
|
deepseekChat: 'deepseek-chat',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AA4CA,wCAKC;AAjDY,QAAA,WAAW,GAAG,GAAG,GAAG,MAAM,CAAA;AAC1B,QAAA,iBAAiB,GAAG,GAAG,GAAG,oBAAoB,CAAA;AAC9C,QAAA,oBAAoB,GAAG,oCAAoC,CAAA;AAE3D,QAAA,qBAAqB,GAAG;IACnC,MAAM;IACN,MAAM;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,SAAS;IACT,cAAc;IACd,MAAM;IACN,YAAY;IACZ,OAAO;IACP,aAAa;IACb,aAAa;IACb,aAAa;IACb,OAAO;IACP,WAAW;IACX,eAAe;IACf,aAAa;IACb,aAAa;IACb,OAAO;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;AAGG,QAAA,cAAc,GAAG;IAC5B,YAAY,EAAE,eAAe;IAC7B,gBAAgB,EAAE,mBAAmB;CAC7B,CAAA;AAGG,QAAA,MAAM,GAAG;IACpB,GAAG,oBAAY;IACf,GAAG,oBAAY;IACf,GAAG,oBAAY;IACf,GAAG,sBAAc;CACT,CAAA;AAIG,QAAA,YAAY,GAAG,cAAc,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Message } from './actions';
|
|
2
|
+
/**
|
|
3
|
+
* Contexts where message processing may occur
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ProcessingContext {
|
|
6
|
+
ModelCall = "model-call",
|
|
7
|
+
FileCache = "file-cache",
|
|
8
|
+
WarmCache = "warm-cache"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface for provider-specific image handling
|
|
12
|
+
*/
|
|
13
|
+
export interface IImageHandler {
|
|
14
|
+
/**
|
|
15
|
+
* Returns whether images should be passed along in the given context
|
|
16
|
+
*/
|
|
17
|
+
supportsImages(context: ProcessingContext): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Transform a message by either stripping, replacing, or modifying image blocks
|
|
20
|
+
*/
|
|
21
|
+
transformMessage(message: Message, context: ProcessingContext): Message;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base handler that removes all images unless explicitly allowed
|
|
25
|
+
*/
|
|
26
|
+
export declare class DefaultImageHandler implements IImageHandler {
|
|
27
|
+
supportsImages(context: ProcessingContext): boolean;
|
|
28
|
+
transformMessage(message: Message, context: ProcessingContext): Message;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register a new image handler for a provider
|
|
32
|
+
*/
|
|
33
|
+
export declare function registerImageHandler(provider: string, handler: IImageHandler): void;
|
|
34
|
+
/**
|
|
35
|
+
* Transform a message for a specific provider and context
|
|
36
|
+
*/
|
|
37
|
+
export declare function transformMessageForProvider(message: Message, provider: string, context: ProcessingContext): Message;
|
|
38
|
+
/**
|
|
39
|
+
* Transform an array of messages for a specific provider and context
|
|
40
|
+
*/
|
|
41
|
+
export declare function transformMessagesForProvider(messages: Message[], provider: string, context: ProcessingContext): Message[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultImageHandler = exports.ProcessingContext = void 0;
|
|
4
|
+
exports.registerImageHandler = registerImageHandler;
|
|
5
|
+
exports.transformMessageForProvider = transformMessageForProvider;
|
|
6
|
+
exports.transformMessagesForProvider = transformMessagesForProvider;
|
|
7
|
+
/**
|
|
8
|
+
* Contexts where message processing may occur
|
|
9
|
+
*/
|
|
10
|
+
var ProcessingContext;
|
|
11
|
+
(function (ProcessingContext) {
|
|
12
|
+
ProcessingContext["ModelCall"] = "model-call";
|
|
13
|
+
ProcessingContext["FileCache"] = "file-cache";
|
|
14
|
+
ProcessingContext["WarmCache"] = "warm-cache";
|
|
15
|
+
})(ProcessingContext || (exports.ProcessingContext = ProcessingContext = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Base handler that removes all images unless explicitly allowed
|
|
18
|
+
*/
|
|
19
|
+
class DefaultImageHandler {
|
|
20
|
+
supportsImages(context) {
|
|
21
|
+
return context === ProcessingContext.FileCache;
|
|
22
|
+
}
|
|
23
|
+
transformMessage(message, context) {
|
|
24
|
+
if (!this.supportsImages(context)) {
|
|
25
|
+
const transformed = Array.isArray(message.content)
|
|
26
|
+
? message.content.filter(block => typeof block === 'string' ? true : block.type !== 'image')
|
|
27
|
+
: message.content;
|
|
28
|
+
return { ...message, content: transformed };
|
|
29
|
+
}
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.DefaultImageHandler = DefaultImageHandler;
|
|
34
|
+
/**
|
|
35
|
+
* Registry mapping provider names to their image handlers
|
|
36
|
+
*/
|
|
37
|
+
const imageHandlerRegistry = {};
|
|
38
|
+
/**
|
|
39
|
+
* Register a new image handler for a provider
|
|
40
|
+
*/
|
|
41
|
+
function registerImageHandler(provider, handler) {
|
|
42
|
+
imageHandlerRegistry[provider] = handler;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Transform a message for a specific provider and context
|
|
46
|
+
*/
|
|
47
|
+
function transformMessageForProvider(message, provider, context) {
|
|
48
|
+
const handler = imageHandlerRegistry[provider] || new DefaultImageHandler();
|
|
49
|
+
return handler.transformMessage(message, context);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Transform an array of messages for a specific provider and context
|
|
53
|
+
*/
|
|
54
|
+
function transformMessagesForProvider(messages, provider, context) {
|
|
55
|
+
return messages.map(message => transformMessageForProvider(message, provider, context));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=message-image-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-image-handling.js","sourceRoot":"","sources":["../src/message-image-handling.ts"],"names":[],"mappings":";;;AAuDA,oDAEC;AAKD,kEAOC;AAKD,oEAMC;AA9ED;;GAEG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,6CAAwB,CAAA;IACxB,6CAAwB,CAAA;IACxB,6CAAwB,CAAA;AAC1B,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAiBD;;GAEG;AACH,MAAa,mBAAmB;IAC9B,cAAc,CAAC,OAA0B;QACvC,OAAO,OAAO,KAAK,iBAAiB,CAAC,SAAS,CAAC;IACjD,CAAC;IAED,gBAAgB,CAAC,OAAgB,EAAE,OAA0B;QAC3D,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;gBAChD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7B,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAC1D;gBACH,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;YACpB,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QAC9C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAhBD,kDAgBC;AAED;;GAEG;AACH,MAAM,oBAAoB,GAAkC,EAAE,CAAC;AAE/D;;GAEG;AACH,SAAgB,oBAAoB,CAAC,QAAgB,EAAE,OAAsB;IAC3E,oBAAoB,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CACzC,OAAgB,EAChB,QAAgB,EAChB,OAA0B;IAE1B,MAAM,OAAO,GAAG,oBAAoB,CAAC,QAAQ,CAAC,IAAI,IAAI,mBAAmB,EAAE,CAAC;IAC5E,OAAO,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,QAAmB,EACnB,QAAgB,EAChB,OAA0B;IAE1B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -176,16 +176,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
176
176
|
type: "ephemeral";
|
|
177
177
|
}>>;
|
|
178
178
|
}, "strip", z.ZodTypeAny, {
|
|
179
|
-
name: string;
|
|
180
179
|
type: "tool_use";
|
|
180
|
+
name: string;
|
|
181
181
|
id: string;
|
|
182
182
|
input: Record<string, any>;
|
|
183
183
|
cache_control?: {
|
|
184
184
|
type: "ephemeral";
|
|
185
185
|
} | undefined;
|
|
186
186
|
}, {
|
|
187
|
-
name: string;
|
|
188
187
|
type: "tool_use";
|
|
188
|
+
name: string;
|
|
189
189
|
id: string;
|
|
190
190
|
input: Record<string, any>;
|
|
191
191
|
cache_control?: {
|
|
@@ -203,15 +203,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
203
203
|
type: "ephemeral";
|
|
204
204
|
}>>;
|
|
205
205
|
}, "strip", z.ZodTypeAny, {
|
|
206
|
-
type: "tool_result";
|
|
207
206
|
content: string;
|
|
207
|
+
type: "tool_result";
|
|
208
208
|
tool_use_id: string;
|
|
209
209
|
cache_control?: {
|
|
210
210
|
type: "ephemeral";
|
|
211
211
|
} | undefined;
|
|
212
212
|
}, {
|
|
213
|
-
type: "tool_result";
|
|
214
213
|
content: string;
|
|
214
|
+
type: "tool_result";
|
|
215
215
|
tool_use_id: string;
|
|
216
216
|
cache_control?: {
|
|
217
217
|
type: "ephemeral";
|
|
@@ -267,16 +267,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
267
267
|
type: "ephemeral";
|
|
268
268
|
} | undefined;
|
|
269
269
|
} | {
|
|
270
|
-
name: string;
|
|
271
270
|
type: "tool_use";
|
|
271
|
+
name: string;
|
|
272
272
|
id: string;
|
|
273
273
|
input: Record<string, any>;
|
|
274
274
|
cache_control?: {
|
|
275
275
|
type: "ephemeral";
|
|
276
276
|
} | undefined;
|
|
277
277
|
} | {
|
|
278
|
-
type: "tool_result";
|
|
279
278
|
content: string;
|
|
279
|
+
type: "tool_result";
|
|
280
280
|
tool_use_id: string;
|
|
281
281
|
cache_control?: {
|
|
282
282
|
type: "ephemeral";
|
|
@@ -301,16 +301,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
301
301
|
type: "ephemeral";
|
|
302
302
|
} | undefined;
|
|
303
303
|
} | {
|
|
304
|
-
name: string;
|
|
305
304
|
type: "tool_use";
|
|
305
|
+
name: string;
|
|
306
306
|
id: string;
|
|
307
307
|
input: Record<string, any>;
|
|
308
308
|
cache_control?: {
|
|
309
309
|
type: "ephemeral";
|
|
310
310
|
} | undefined;
|
|
311
311
|
} | {
|
|
312
|
-
type: "tool_result";
|
|
313
312
|
content: string;
|
|
313
|
+
type: "tool_result";
|
|
314
314
|
tool_use_id: string;
|
|
315
315
|
cache_control?: {
|
|
316
316
|
type: "ephemeral";
|
|
@@ -366,16 +366,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
366
366
|
type: "ephemeral";
|
|
367
367
|
} | undefined;
|
|
368
368
|
} | {
|
|
369
|
-
name: string;
|
|
370
369
|
type: "tool_use";
|
|
370
|
+
name: string;
|
|
371
371
|
id: string;
|
|
372
372
|
input: Record<string, any>;
|
|
373
373
|
cache_control?: {
|
|
374
374
|
type: "ephemeral";
|
|
375
375
|
} | undefined;
|
|
376
376
|
} | {
|
|
377
|
-
type: "tool_result";
|
|
378
377
|
content: string;
|
|
378
|
+
type: "tool_result";
|
|
379
379
|
tool_use_id: string;
|
|
380
380
|
cache_control?: {
|
|
381
381
|
type: "ephemeral";
|
|
@@ -431,16 +431,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
431
431
|
type: "ephemeral";
|
|
432
432
|
} | undefined;
|
|
433
433
|
} | {
|
|
434
|
-
name: string;
|
|
435
434
|
type: "tool_use";
|
|
435
|
+
name: string;
|
|
436
436
|
id: string;
|
|
437
437
|
input: Record<string, any>;
|
|
438
438
|
cache_control?: {
|
|
439
439
|
type: "ephemeral";
|
|
440
440
|
} | undefined;
|
|
441
441
|
} | {
|
|
442
|
-
type: "tool_result";
|
|
443
442
|
content: string;
|
|
443
|
+
type: "tool_result";
|
|
444
444
|
tool_use_id: string;
|
|
445
445
|
cache_control?: {
|
|
446
446
|
type: "ephemeral";
|
|
@@ -35,16 +35,16 @@ declare const MessageContentObjectSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
35
35
|
}>>;
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
|
37
37
|
type: "tool_use";
|
|
38
|
-
name: string;
|
|
39
38
|
id: string;
|
|
39
|
+
name: string;
|
|
40
40
|
input: Record<string, any>;
|
|
41
41
|
cache_control?: {
|
|
42
42
|
type: "ephemeral";
|
|
43
43
|
} | undefined;
|
|
44
44
|
}, {
|
|
45
45
|
type: "tool_use";
|
|
46
|
-
name: string;
|
|
47
46
|
id: string;
|
|
47
|
+
name: string;
|
|
48
48
|
input: Record<string, any>;
|
|
49
49
|
cache_control?: {
|
|
50
50
|
type: "ephemeral";
|
|
@@ -155,16 +155,16 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
155
155
|
}>>;
|
|
156
156
|
}, "strip", z.ZodTypeAny, {
|
|
157
157
|
type: "tool_use";
|
|
158
|
-
name: string;
|
|
159
158
|
id: string;
|
|
159
|
+
name: string;
|
|
160
160
|
input: Record<string, any>;
|
|
161
161
|
cache_control?: {
|
|
162
162
|
type: "ephemeral";
|
|
163
163
|
} | undefined;
|
|
164
164
|
}, {
|
|
165
165
|
type: "tool_use";
|
|
166
|
-
name: string;
|
|
167
166
|
id: string;
|
|
167
|
+
name: string;
|
|
168
168
|
input: Record<string, any>;
|
|
169
169
|
cache_control?: {
|
|
170
170
|
type: "ephemeral";
|
|
@@ -238,6 +238,7 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
238
238
|
} | undefined;
|
|
239
239
|
}>]>, "many">]>;
|
|
240
240
|
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
role: "user" | "assistant";
|
|
241
242
|
content: string | ({
|
|
242
243
|
type: "text";
|
|
243
244
|
text: string;
|
|
@@ -246,8 +247,8 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
246
247
|
} | undefined;
|
|
247
248
|
} | {
|
|
248
249
|
type: "tool_use";
|
|
249
|
-
name: string;
|
|
250
250
|
id: string;
|
|
251
|
+
name: string;
|
|
251
252
|
input: Record<string, any>;
|
|
252
253
|
cache_control?: {
|
|
253
254
|
type: "ephemeral";
|
|
@@ -270,8 +271,8 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
270
271
|
type: "ephemeral";
|
|
271
272
|
} | undefined;
|
|
272
273
|
})[];
|
|
273
|
-
role: "user" | "assistant";
|
|
274
274
|
}, {
|
|
275
|
+
role: "user" | "assistant";
|
|
275
276
|
content: string | ({
|
|
276
277
|
type: "text";
|
|
277
278
|
text: string;
|
|
@@ -280,8 +281,8 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
280
281
|
} | undefined;
|
|
281
282
|
} | {
|
|
282
283
|
type: "tool_use";
|
|
283
|
-
name: string;
|
|
284
284
|
id: string;
|
|
285
|
+
name: string;
|
|
285
286
|
input: Record<string, any>;
|
|
286
287
|
cache_control?: {
|
|
287
288
|
type: "ephemeral";
|
|
@@ -304,7 +305,6 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
304
305
|
type: "ephemeral";
|
|
305
306
|
} | undefined;
|
|
306
307
|
})[];
|
|
307
|
-
role: "user" | "assistant";
|
|
308
308
|
}>;
|
|
309
309
|
export type Message = z.infer<typeof MessageSchema>;
|
|
310
310
|
export type MessageContentObject = z.infer<typeof MessageContentObjectSchema>;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple Least Recently Used (LRU) cache implementation using a Map.
|
|
3
|
+
* It leverages the fact that Map objects maintain insertion order.
|
|
4
|
+
*/
|
|
1
5
|
export declare class LRUCache<K, V> {
|
|
2
6
|
private maxSize;
|
|
3
7
|
private cache;
|
|
4
|
-
private heap;
|
|
5
|
-
private accessCounter;
|
|
6
8
|
constructor(maxSize: number);
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves an item from the cache. If found, marks it as recently used.
|
|
11
|
+
* @param key The key of the item to retrieve.
|
|
12
|
+
* @returns The value associated with the key, or undefined if not found.
|
|
13
|
+
*/
|
|
7
14
|
get(key: K): V | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Adds or updates an item in the cache. If the cache exceeds maxSize,
|
|
17
|
+
* the least recently used item is evicted.
|
|
18
|
+
* @param key The key of the item to set.
|
|
19
|
+
* @param value The value to associate with the key.
|
|
20
|
+
*/
|
|
8
21
|
set(key: K, value: V): void;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the current number of items in the cache.
|
|
24
|
+
*/
|
|
25
|
+
get size(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Clears all items from the cache.
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
9
30
|
}
|
|
@@ -1,41 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LRUCache = void 0;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A simple Least Recently Used (LRU) cache implementation using a Map.
|
|
6
|
+
* It leverages the fact that Map objects maintain insertion order.
|
|
7
|
+
*/
|
|
5
8
|
class LRUCache {
|
|
6
9
|
maxSize;
|
|
7
10
|
cache = new Map();
|
|
8
|
-
heap = new min_heap_1.MinHeap();
|
|
9
|
-
accessCounter = 0;
|
|
10
11
|
constructor(maxSize) {
|
|
11
12
|
this.maxSize = maxSize;
|
|
13
|
+
if (maxSize <= 0) {
|
|
14
|
+
throw new Error('LRUCache maxSize must be a positive number.');
|
|
15
|
+
}
|
|
12
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves an item from the cache. If found, marks it as recently used.
|
|
19
|
+
* @param key The key of the item to retrieve.
|
|
20
|
+
* @returns The value associated with the key, or undefined if not found.
|
|
21
|
+
*/
|
|
13
22
|
get(key) {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
return
|
|
23
|
+
const value = this.cache.get(key);
|
|
24
|
+
if (value !== undefined) {
|
|
25
|
+
// Mark as recently used by deleting and re-setting
|
|
26
|
+
this.cache.delete(key);
|
|
27
|
+
this.cache.set(key, value);
|
|
28
|
+
return value;
|
|
20
29
|
}
|
|
21
30
|
return undefined;
|
|
22
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Adds or updates an item in the cache. If the cache exceeds maxSize,
|
|
34
|
+
* the least recently used item is evicted.
|
|
35
|
+
* @param key The key of the item to set.
|
|
36
|
+
* @param value The value to associate with the key.
|
|
37
|
+
*/
|
|
23
38
|
set(key, value) {
|
|
24
|
-
// If key exists,
|
|
39
|
+
// If key already exists, delete it first to update its position
|
|
25
40
|
if (this.cache.has(key)) {
|
|
26
|
-
|
|
27
|
-
this.heap.insert(key, -this.accessCounter); // Dummy insert to replace old entry
|
|
41
|
+
this.cache.delete(key);
|
|
28
42
|
}
|
|
29
|
-
//
|
|
43
|
+
// Check if cache is full before adding the new item
|
|
30
44
|
else if (this.cache.size >= this.maxSize) {
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
// Evict the least recently used item (the first item in the Map's iteration order)
|
|
46
|
+
const oldestKey = this.cache.keys().next().value;
|
|
47
|
+
if (oldestKey !== undefined) { // Should always be defined if size >= maxSize > 0
|
|
33
48
|
this.cache.delete(oldestKey);
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
|
-
|
|
37
|
-
this.cache.set(key,
|
|
38
|
-
|
|
51
|
+
// Add the new item (or re-add the updated item)
|
|
52
|
+
this.cache.set(key, value);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the current number of items in the cache.
|
|
56
|
+
*/
|
|
57
|
+
get size() {
|
|
58
|
+
return this.cache.size;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clears all items from the cache.
|
|
62
|
+
*/
|
|
63
|
+
clear() {
|
|
64
|
+
this.cache.clear();
|
|
39
65
|
}
|
|
40
66
|
}
|
|
41
67
|
exports.LRUCache = LRUCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../src/util/lru-cache.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../src/util/lru-cache.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,QAAQ;I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