@augmentcode/auggie-sdk 0.1.6 → 0.1.8
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/auggie/sdk-acp-client.d.ts +0 -102
- package/dist/auggie/sdk-acp-client.d.ts.map +1 -1
- package/dist/auggie/sdk-acp-client.js +1 -32
- package/dist/auggie/sdk-acp-client.js.map +1 -1
- package/dist/context/direct-context.d.ts +287 -0
- package/dist/context/direct-context.d.ts.map +1 -0
- package/dist/context/direct-context.js +624 -0
- package/dist/context/direct-context.js.map +1 -0
- package/dist/context/filesystem-context.d.ts +84 -0
- package/dist/context/filesystem-context.d.ts.map +1 -0
- package/dist/context/filesystem-context.js +198 -0
- package/dist/context/filesystem-context.js.map +1 -0
- package/dist/context/internal/__mocks__/api-client.d.ts +54 -0
- package/dist/context/internal/__mocks__/api-client.d.ts.map +1 -0
- package/dist/context/internal/__mocks__/api-client.js +96 -0
- package/dist/context/internal/__mocks__/api-client.js.map +1 -0
- package/dist/context/internal/api-client.d.ts +75 -0
- package/dist/context/internal/api-client.d.ts.map +1 -0
- package/dist/context/internal/api-client.js +218 -0
- package/dist/context/internal/api-client.js.map +1 -0
- package/dist/context/internal/blob-name-calculator.d.ts +14 -0
- package/dist/context/internal/blob-name-calculator.d.ts.map +1 -0
- package/dist/context/internal/blob-name-calculator.js +44 -0
- package/dist/context/internal/blob-name-calculator.js.map +1 -0
- package/dist/context/internal/retry-utils.d.ts +22 -0
- package/dist/context/internal/retry-utils.d.ts.map +1 -0
- package/dist/context/internal/retry-utils.js +88 -0
- package/dist/context/internal/retry-utils.js.map +1 -0
- package/dist/context/internal/search-utils.d.ts +8 -0
- package/dist/context/internal/search-utils.d.ts.map +1 -0
- package/dist/context/internal/search-utils.js +10 -0
- package/dist/context/internal/search-utils.js.map +1 -0
- package/dist/context/internal/session-reader.d.ts +17 -0
- package/dist/context/internal/session-reader.d.ts.map +1 -0
- package/dist/context/internal/session-reader.js +27 -0
- package/dist/context/internal/session-reader.js.map +1 -0
- package/dist/context/types.d.ts +113 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +5 -0
- package/dist/context/types.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { FileSystemContextOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* FileSystem Context - Local directory retrieval via MCP protocol
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ **EXPERIMENTAL API** - This API is experimental and may change without notice.
|
|
6
|
+
*
|
|
7
|
+
* @experimental
|
|
8
|
+
*
|
|
9
|
+
* This class spawns `auggie --mcp` and communicates with it via the MCP protocol
|
|
10
|
+
* to provide codebase retrieval from a local directory.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FileSystemContext {
|
|
13
|
+
private readonly auggiePath;
|
|
14
|
+
private readonly directory;
|
|
15
|
+
private readonly debug;
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly apiUrl;
|
|
18
|
+
private mcpClient;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new FileSystemContext instance
|
|
21
|
+
* @param options Configuration options
|
|
22
|
+
*/
|
|
23
|
+
constructor(options: FileSystemContextOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Create and initialize a new FileSystemContext instance
|
|
26
|
+
*/
|
|
27
|
+
static create(options: FileSystemContextOptions): Promise<FileSystemContext>;
|
|
28
|
+
/**
|
|
29
|
+
* Log a debug message if debug mode is enabled
|
|
30
|
+
*/
|
|
31
|
+
private log;
|
|
32
|
+
/**
|
|
33
|
+
* Connect to Auggie MCP server
|
|
34
|
+
*/
|
|
35
|
+
private connect;
|
|
36
|
+
/**
|
|
37
|
+
* Search the codebase using natural language and return formatted results.
|
|
38
|
+
*
|
|
39
|
+
* The results are returned as a formatted string designed for use in LLM prompts.
|
|
40
|
+
* The format includes file paths, line numbers, and code content in a structured,
|
|
41
|
+
* readable format that can be passed directly to LLM APIs like `generate()`.
|
|
42
|
+
*
|
|
43
|
+
* @param query - The search query describing what code you're looking for
|
|
44
|
+
* @returns A formatted string containing the search results, ready for LLM consumption
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const context = await FileSystemContext.create({ directory: "./my-project" });
|
|
49
|
+
* const results = await context.search("authentication logic");
|
|
50
|
+
* console.log(results); // Formatted string with file paths, line numbers, and code
|
|
51
|
+
*
|
|
52
|
+
* // Use directly with generate API
|
|
53
|
+
* const response = await generate(
|
|
54
|
+
* `Based on this code:\n\n${results}\n\nHow does authentication work?`,
|
|
55
|
+
* { model: "sonnet4.5" }
|
|
56
|
+
* );
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
search(query: string): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Search the indexed codebase and ask an LLM a question about the results.
|
|
62
|
+
*
|
|
63
|
+
* This is a convenience method that combines search() with an LLM call to answer
|
|
64
|
+
* questions about your codebase.
|
|
65
|
+
*
|
|
66
|
+
* @param searchQuery - The semantic search query to find relevant code (also used as the prompt if no separate prompt is provided)
|
|
67
|
+
* @param prompt - Optional prompt to ask the LLM about the search results. If not provided, searchQuery is used as the prompt.
|
|
68
|
+
* @returns The LLM's answer to your question
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const answer = await context.searchAndAsk(
|
|
73
|
+
* "How does the authentication flow work?"
|
|
74
|
+
* );
|
|
75
|
+
* console.log(answer);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
searchAndAsk(searchQuery: string, prompt?: string): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Close the MCP connection and cleanup resources
|
|
81
|
+
*/
|
|
82
|
+
close(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=filesystem-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem-context.d.ts","sourceRoot":"","sources":["../../src/context/filesystem-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAcxD;;;;;;;;;GASG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C,OAAO,CAAC,SAAS,CAA0B;IAE3C;;;OAGG;gBACS,OAAO,EAAE,wBAAwB;IAQ7C;;OAEG;WACU,MAAM,CACjB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,iBAAiB,CAAC;IAM7B;;OAEG;IACH,OAAO,CAAC,GAAG;IAMX;;OAEG;IACH,OAAO,CAAC,OAAO;IA6Cf;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyD5C;;;;;;;;;;;;;;;;;OAiBG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBzE;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAc7B"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { MCPClient } from "@mastra/mcp";
|
|
2
|
+
import { ContextAPIClient } from "./internal/api-client";
|
|
3
|
+
import { formatSearchPrompt } from "./internal/search-utils";
|
|
4
|
+
/**
|
|
5
|
+
* FileSystem Context - Local directory retrieval via MCP protocol
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ **EXPERIMENTAL API** - This API is experimental and may change without notice.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*
|
|
11
|
+
* This class spawns `auggie --mcp` and communicates with it via the MCP protocol
|
|
12
|
+
* to provide codebase retrieval from a local directory.
|
|
13
|
+
*/
|
|
14
|
+
export class FileSystemContext {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new FileSystemContext instance
|
|
17
|
+
* @param options Configuration options
|
|
18
|
+
*/
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.mcpClient = null;
|
|
21
|
+
this.auggiePath = options.auggiePath || "auggie";
|
|
22
|
+
this.directory = options.directory;
|
|
23
|
+
this.debug = options.debug ?? false;
|
|
24
|
+
this.apiKey = process.env.AUGMENT_API_TOKEN;
|
|
25
|
+
this.apiUrl = process.env.AUGMENT_API_URL;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create and initialize a new FileSystemContext instance
|
|
29
|
+
*/
|
|
30
|
+
static async create(options) {
|
|
31
|
+
const instance = new FileSystemContext(options);
|
|
32
|
+
await Promise.resolve(instance.connect());
|
|
33
|
+
return instance;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Log a debug message if debug mode is enabled
|
|
37
|
+
*/
|
|
38
|
+
log(message) {
|
|
39
|
+
if (this.debug) {
|
|
40
|
+
console.log(`[FileSystemContext] ${message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Connect to Auggie MCP server
|
|
45
|
+
*/
|
|
46
|
+
connect() {
|
|
47
|
+
this.log(`Starting MCP server for directory: ${this.directory}`);
|
|
48
|
+
const command = this.auggiePath.trim();
|
|
49
|
+
if (!command) {
|
|
50
|
+
throw new Error("Invalid auggiePath: cannot be empty");
|
|
51
|
+
}
|
|
52
|
+
const args = ["--mcp", "--workspace-root", this.directory];
|
|
53
|
+
// Build environment variables
|
|
54
|
+
const env = {};
|
|
55
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
56
|
+
if (value !== undefined) {
|
|
57
|
+
env[key] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (this.apiKey) {
|
|
61
|
+
env.AUGMENT_API_TOKEN = this.apiKey;
|
|
62
|
+
}
|
|
63
|
+
if (this.apiUrl) {
|
|
64
|
+
env.AUGMENT_API_URL = this.apiUrl;
|
|
65
|
+
}
|
|
66
|
+
// Create MCP client using MCPClient
|
|
67
|
+
this.mcpClient = new MCPClient({
|
|
68
|
+
servers: {
|
|
69
|
+
auggie: {
|
|
70
|
+
command,
|
|
71
|
+
args,
|
|
72
|
+
env,
|
|
73
|
+
logger: this.debug
|
|
74
|
+
? (logMessage) => {
|
|
75
|
+
console.log(`[MCP ${logMessage.level}] ${logMessage.message}`, logMessage.details);
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
this.log("Connected to Auggie MCP server");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Search the codebase using natural language and return formatted results.
|
|
85
|
+
*
|
|
86
|
+
* The results are returned as a formatted string designed for use in LLM prompts.
|
|
87
|
+
* The format includes file paths, line numbers, and code content in a structured,
|
|
88
|
+
* readable format that can be passed directly to LLM APIs like `generate()`.
|
|
89
|
+
*
|
|
90
|
+
* @param query - The search query describing what code you're looking for
|
|
91
|
+
* @returns A formatted string containing the search results, ready for LLM consumption
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const context = await FileSystemContext.create({ directory: "./my-project" });
|
|
96
|
+
* const results = await context.search("authentication logic");
|
|
97
|
+
* console.log(results); // Formatted string with file paths, line numbers, and code
|
|
98
|
+
*
|
|
99
|
+
* // Use directly with generate API
|
|
100
|
+
* const response = await generate(
|
|
101
|
+
* `Based on this code:\n\n${results}\n\nHow does authentication work?`,
|
|
102
|
+
* { model: "sonnet4.5" }
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
async search(query) {
|
|
107
|
+
if (!this.mcpClient) {
|
|
108
|
+
throw new Error("MCP client not initialized. Call create() first.");
|
|
109
|
+
}
|
|
110
|
+
this.log(`Searching for: "${query}"`);
|
|
111
|
+
try {
|
|
112
|
+
// Get the tools from the MCP client
|
|
113
|
+
// getTools() returns tools with server name prefix (auggie_codebase-retrieval)
|
|
114
|
+
const tools = await this.mcpClient.getTools();
|
|
115
|
+
const codebaseRetrievalTool = tools["auggie_codebase-retrieval"];
|
|
116
|
+
if (!codebaseRetrievalTool) {
|
|
117
|
+
throw new Error(`codebase-retrieval tool not found. Available tools: ${Object.keys(tools).join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
// Execute the MCP tool
|
|
120
|
+
//
|
|
121
|
+
// MCP Tool Input Format:
|
|
122
|
+
// Mastra MCP wraps tool parameters in a 'context' property:
|
|
123
|
+
// { context: { param1: value1, param2: value2, ... } }
|
|
124
|
+
//
|
|
125
|
+
// MCP Tool Output Format:
|
|
126
|
+
// MCP tools return results in the Model Context Protocol format:
|
|
127
|
+
// { content: [{ type: "text", text: "..." }, ...] }
|
|
128
|
+
// This allows tools to return multiple content blocks of different types.
|
|
129
|
+
const result = await codebaseRetrievalTool.execute({
|
|
130
|
+
context: {
|
|
131
|
+
information_request: query,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
// Extract text from MCP result (standard MCP format)
|
|
135
|
+
if (!(result?.content && Array.isArray(result.content))) {
|
|
136
|
+
throw new Error(`Unexpected MCP response format: expected { content: [...] }, got ${JSON.stringify(result)}`);
|
|
137
|
+
}
|
|
138
|
+
const text = result.content
|
|
139
|
+
.filter((item) => item.type === "text")
|
|
140
|
+
.map((item) => item.text || "")
|
|
141
|
+
.join("\n");
|
|
142
|
+
this.log(`Search completed (${text.length} characters)`);
|
|
143
|
+
return text;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
throw new Error(`Codebase retrieval failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Search the indexed codebase and ask an LLM a question about the results.
|
|
151
|
+
*
|
|
152
|
+
* This is a convenience method that combines search() with an LLM call to answer
|
|
153
|
+
* questions about your codebase.
|
|
154
|
+
*
|
|
155
|
+
* @param searchQuery - The semantic search query to find relevant code (also used as the prompt if no separate prompt is provided)
|
|
156
|
+
* @param prompt - Optional prompt to ask the LLM about the search results. If not provided, searchQuery is used as the prompt.
|
|
157
|
+
* @returns The LLM's answer to your question
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const answer = await context.searchAndAsk(
|
|
162
|
+
* "How does the authentication flow work?"
|
|
163
|
+
* );
|
|
164
|
+
* console.log(answer);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
async searchAndAsk(searchQuery, prompt) {
|
|
168
|
+
const results = await this.search(searchQuery);
|
|
169
|
+
const llmPrompt = formatSearchPrompt(prompt ?? searchQuery, results);
|
|
170
|
+
const apiKey = this.apiKey || process.env.AUGMENT_API_TOKEN;
|
|
171
|
+
if (!apiKey) {
|
|
172
|
+
throw new Error("API key is required for searchAndAsk(). Provide it via AUGMENT_API_TOKEN environment variable.");
|
|
173
|
+
}
|
|
174
|
+
const apiUrl = this.apiUrl || process.env.AUGMENT_API_URL;
|
|
175
|
+
if (!apiUrl) {
|
|
176
|
+
throw new Error("API URL is required for searchAndAsk(). Set AUGMENT_API_URL environment variable to your tenant-specific URL (e.g., 'https://your-tenant.api.augmentcode.com').");
|
|
177
|
+
}
|
|
178
|
+
const apiClient = new ContextAPIClient({ apiKey, apiUrl });
|
|
179
|
+
return await apiClient.chat(llmPrompt);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Close the MCP connection and cleanup resources
|
|
183
|
+
*/
|
|
184
|
+
async close() {
|
|
185
|
+
this.log("Closing MCP connection");
|
|
186
|
+
if (this.mcpClient) {
|
|
187
|
+
try {
|
|
188
|
+
await this.mcpClient.disconnect();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error("Error closing MCP client:", error);
|
|
192
|
+
}
|
|
193
|
+
this.mcpClient = null;
|
|
194
|
+
}
|
|
195
|
+
this.log("MCP connection closed");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=filesystem-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem-context.js","sourceRoot":"","sources":["../../src/context/filesystem-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAe7D;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAiB;IAS5B;;;OAGG;IACH,YAAY,OAAiC;QANrC,cAAS,GAAqB,IAAI,CAAC;QAOzC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,OAAiC;QAEjC,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACK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,iKAAiK,CAClK,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3D,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QAEnC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock implementation of ContextAPIClient for testing
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentCodebaseRetrievalResult, BatchUploadResult, CheckpointBlobsResult, FindMissingResult, UploadBlob } from "../api-client";
|
|
5
|
+
import type { Blobs } from "../../types";
|
|
6
|
+
export type MockAPIClientConfig = {
|
|
7
|
+
/** Blobs that the server knows about (uploaded) */
|
|
8
|
+
knownBlobs?: Set<string>;
|
|
9
|
+
/** Blobs that are indexed (subset of knownBlobs) */
|
|
10
|
+
indexedBlobs?: Set<string>;
|
|
11
|
+
/** Delay in ms for async operations (simulates network latency) */
|
|
12
|
+
delay?: number;
|
|
13
|
+
/** Should findMissing throw an error? */
|
|
14
|
+
shouldFailFindMissing?: boolean;
|
|
15
|
+
/** Should batchUpload throw an error? */
|
|
16
|
+
shouldFailBatchUpload?: boolean;
|
|
17
|
+
/** Should checkpointBlobs throw an error? */
|
|
18
|
+
shouldFailCheckpoint?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Mock implementation that provides the same public API as ContextAPIClient
|
|
22
|
+
* Note: Does not formally implement ContextAPIClient due to TypeScript limitations
|
|
23
|
+
* with private members, but provides all the same public methods for testing.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MockContextAPIClient {
|
|
26
|
+
private knownBlobs;
|
|
27
|
+
private indexedBlobs;
|
|
28
|
+
private delay;
|
|
29
|
+
private shouldFailFindMissing;
|
|
30
|
+
private shouldFailBatchUpload;
|
|
31
|
+
private shouldFailCheckpoint;
|
|
32
|
+
findMissingCalls: string[][];
|
|
33
|
+
batchUploadCalls: UploadBlob[][];
|
|
34
|
+
checkpointBlobsCalls: Blobs[];
|
|
35
|
+
agentCodebaseRetrievalCalls: Array<{
|
|
36
|
+
query: string;
|
|
37
|
+
blobs: Blobs;
|
|
38
|
+
maxOutputLength?: number;
|
|
39
|
+
}>;
|
|
40
|
+
chatCalls: string[];
|
|
41
|
+
constructor(config?: MockAPIClientConfig);
|
|
42
|
+
createRequestId(): string;
|
|
43
|
+
private simulateDelay;
|
|
44
|
+
findMissing(blobNames: string[]): Promise<FindMissingResult>;
|
|
45
|
+
batchUpload(blobs: UploadBlob[]): Promise<BatchUploadResult>;
|
|
46
|
+
checkpointBlobs(blobs: Blobs): Promise<CheckpointBlobsResult>;
|
|
47
|
+
agentCodebaseRetrieval(_requestId: string, query: string, blobs: Blobs, maxOutputLength?: number): Promise<AgentCodebaseRetrievalResult>;
|
|
48
|
+
chat(prompt: string): Promise<string>;
|
|
49
|
+
/** Mark blobs as indexed (simulates backend indexing completion) */
|
|
50
|
+
markAsIndexed(blobNames: string[]): void;
|
|
51
|
+
/** Reset all call tracking */
|
|
52
|
+
resetCalls(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sour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rB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsB5D,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkB5D,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAc7D,sBAAsB,CAC1B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,KAAK,EACZ,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,4BAA4B,CAAC;IAUlC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU3C,oEAAoE;IACpE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAMxC,8BAA8B;IAC9B,UAAU,IAAI,IAAI;CAOnB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock implementation of ContextAPIClient for testing
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Mock implementation that provides the same public API as ContextAPIClient
|
|
6
|
+
* Note: Does not formally implement ContextAPIClient due to TypeScript limitations
|
|
7
|
+
* with private members, but provides all the same public methods for testing.
|
|
8
|
+
*/
|
|
9
|
+
export class MockContextAPIClient {
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
// Track method calls for assertions
|
|
12
|
+
this.findMissingCalls = [];
|
|
13
|
+
this.batchUploadCalls = [];
|
|
14
|
+
this.checkpointBlobsCalls = [];
|
|
15
|
+
this.agentCodebaseRetrievalCalls = [];
|
|
16
|
+
this.chatCalls = [];
|
|
17
|
+
this.knownBlobs = config.knownBlobs || new Set();
|
|
18
|
+
this.indexedBlobs = config.indexedBlobs || new Set();
|
|
19
|
+
this.delay = config.delay || 0;
|
|
20
|
+
this.shouldFailFindMissing = config.shouldFailFindMissing || false;
|
|
21
|
+
this.shouldFailBatchUpload = config.shouldFailBatchUpload || false;
|
|
22
|
+
this.shouldFailCheckpoint = config.shouldFailCheckpoint || false;
|
|
23
|
+
}
|
|
24
|
+
createRequestId() {
|
|
25
|
+
return `mock-req-${Date.now()}`;
|
|
26
|
+
}
|
|
27
|
+
async simulateDelay() {
|
|
28
|
+
if (this.delay > 0) {
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, this.delay));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async findMissing(blobNames) {
|
|
33
|
+
this.findMissingCalls.push([...blobNames]);
|
|
34
|
+
if (this.shouldFailFindMissing) {
|
|
35
|
+
throw new Error("Mock findMissing error");
|
|
36
|
+
}
|
|
37
|
+
await this.simulateDelay();
|
|
38
|
+
const unknownBlobNames = blobNames.filter((name) => !this.knownBlobs.has(name));
|
|
39
|
+
const nonindexedBlobNames = blobNames.filter((name) => this.knownBlobs.has(name) && !this.indexedBlobs.has(name));
|
|
40
|
+
return {
|
|
41
|
+
unknownBlobNames,
|
|
42
|
+
nonindexedBlobNames,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async batchUpload(blobs) {
|
|
46
|
+
this.batchUploadCalls.push([...blobs]);
|
|
47
|
+
if (this.shouldFailBatchUpload) {
|
|
48
|
+
throw new Error("Mock batchUpload error");
|
|
49
|
+
}
|
|
50
|
+
await this.simulateDelay();
|
|
51
|
+
// Add uploaded blobs to known blobs (but not indexed yet)
|
|
52
|
+
const blobNames = blobs.map((b) => b.blobName);
|
|
53
|
+
for (const blobName of blobNames) {
|
|
54
|
+
this.knownBlobs.add(blobName);
|
|
55
|
+
}
|
|
56
|
+
return { blobNames };
|
|
57
|
+
}
|
|
58
|
+
async checkpointBlobs(blobs) {
|
|
59
|
+
this.checkpointBlobsCalls.push({ ...blobs });
|
|
60
|
+
if (this.shouldFailCheckpoint) {
|
|
61
|
+
throw new Error("Mock checkpointBlobs error");
|
|
62
|
+
}
|
|
63
|
+
await this.simulateDelay();
|
|
64
|
+
return {
|
|
65
|
+
newCheckpointId: `checkpoint-${Date.now()}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async agentCodebaseRetrieval(_requestId, query, blobs, maxOutputLength) {
|
|
69
|
+
this.agentCodebaseRetrievalCalls.push({ query, blobs, maxOutputLength });
|
|
70
|
+
await this.simulateDelay();
|
|
71
|
+
return {
|
|
72
|
+
formattedRetrieval: `Mock search results for: ${query}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async chat(prompt) {
|
|
76
|
+
this.chatCalls.push(prompt);
|
|
77
|
+
await this.simulateDelay();
|
|
78
|
+
return `Mock LLM response to: ${prompt}`;
|
|
79
|
+
}
|
|
80
|
+
// Helper methods for test setup
|
|
81
|
+
/** Mark blobs as indexed (simulates backend indexing completion) */
|
|
82
|
+
markAsIndexed(blobNames) {
|
|
83
|
+
for (const blobName of blobNames) {
|
|
84
|
+
this.indexedBlobs.add(blobName);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Reset all call tracking */
|
|
88
|
+
resetCalls() {
|
|
89
|
+
this.findMissingCalls = [];
|
|
90
|
+
this.batchUploadCalls = [];
|
|
91
|
+
this.checkpointBlobsCalls = [];
|
|
92
|
+
this.agentCodebaseRetrievalCalls = [];
|
|
93
|
+
this.chatCalls = [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../../../src/context/internal/__mocks__/api-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0BH;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAoB/B,YAAY,SAA8B,EAAE;QAX5C,oCAAoC;QAC7B,qBAAgB,GAAe,EAAE,CAAC;QAClC,qBAAgB,GAAmB,EAAE,CAAC;QACtC,yBAAoB,GAAY,EAAE,CAAC;QACnC,gCAA2B,GAI7B,EAAE,CAAC;QACD,cAAS,GAAa,EAAE,C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IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;QAEzE,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE3B,OAAO;YACL,kBAAkB,EAAE,4BAA4B,KAAK,EAAE;SACxD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAc;QACvB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE5B,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE3B,OAAO,yBAAyB,MAAM,EAAE,CAAC;IAC3C,CAAC;IAED,gCAAgC;IAEhC,oEAAoE;IACpE,aAAa,CAAC,SAAmB;QAC/B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,8BAA8B;IAC9B,UAAU;QACR,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,2BAA2B,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API client for Context operations
|
|
3
|
+
* Handles both indexing endpoints and LLM chat endpoint
|
|
4
|
+
*/
|
|
5
|
+
import type { Blobs } from "../types";
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when an API request fails
|
|
8
|
+
* Includes the HTTP status code to enable retry logic for transient failures
|
|
9
|
+
*/
|
|
10
|
+
export declare class APIError extends Error {
|
|
11
|
+
readonly status: number;
|
|
12
|
+
readonly statusText: string;
|
|
13
|
+
constructor(status: number, statusText: string, message: string);
|
|
14
|
+
}
|
|
15
|
+
export type UploadBlob = {
|
|
16
|
+
blobName: string;
|
|
17
|
+
pathName: string;
|
|
18
|
+
text: string;
|
|
19
|
+
metadata: string[];
|
|
20
|
+
};
|
|
21
|
+
export type FindMissingResult = {
|
|
22
|
+
unknownBlobNames: string[];
|
|
23
|
+
nonindexedBlobNames: string[];
|
|
24
|
+
};
|
|
25
|
+
export type CheckpointBlobsResult = {
|
|
26
|
+
newCheckpointId: string;
|
|
27
|
+
};
|
|
28
|
+
export type BatchUploadResult = {
|
|
29
|
+
blobNames: string[];
|
|
30
|
+
};
|
|
31
|
+
export type AgentCodebaseRetrievalResult = {
|
|
32
|
+
formattedRetrieval: string;
|
|
33
|
+
};
|
|
34
|
+
export type ContextAPIClientOptions = {
|
|
35
|
+
apiKey: string;
|
|
36
|
+
apiUrl: string;
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get user agent string for Context API requests
|
|
41
|
+
*/
|
|
42
|
+
export declare function getUserAgent(): string;
|
|
43
|
+
/**
|
|
44
|
+
* API client for Context operations
|
|
45
|
+
*/
|
|
46
|
+
export declare class ContextAPIClient {
|
|
47
|
+
private readonly apiKey;
|
|
48
|
+
private readonly apiUrl;
|
|
49
|
+
private readonly sessionId;
|
|
50
|
+
private readonly debug;
|
|
51
|
+
constructor(options: ContextAPIClientOptions);
|
|
52
|
+
private log;
|
|
53
|
+
createRequestId(): string;
|
|
54
|
+
private callApi;
|
|
55
|
+
findMissing(blobNames: string[]): Promise<FindMissingResult>;
|
|
56
|
+
batchUpload(blobs: UploadBlob[]): Promise<BatchUploadResult>;
|
|
57
|
+
checkpointBlobs(blobs: Blobs): Promise<CheckpointBlobsResult>;
|
|
58
|
+
agentCodebaseRetrieval(_requestId: string, query: string, blobs: Blobs, maxOutputLength?: number): Promise<AgentCodebaseRetrievalResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Parse a single JSON line from the stream and extract text if present
|
|
61
|
+
*/
|
|
62
|
+
private parseStreamLine;
|
|
63
|
+
/**
|
|
64
|
+
* Parse streaming response and accumulate text chunks
|
|
65
|
+
*/
|
|
66
|
+
private parseSSEStream;
|
|
67
|
+
/**
|
|
68
|
+
* Call the LLM chat streaming API with a formatted prompt
|
|
69
|
+
*
|
|
70
|
+
* @param prompt - The formatted prompt to send to the LLM
|
|
71
|
+
* @returns The LLM's response text
|
|
72
|
+
*/
|
|
73
|
+
chat(prompt: string): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../../src/context/internal/api-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMhE;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CA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