@augmentcode/auggie-sdk 0.1.10 → 0.1.12

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.
Files changed (62) hide show
  1. package/README.md +56 -1
  2. package/dist/auggie/sdk-acp-client.d.ts +7 -6
  3. package/dist/auggie/sdk-acp-client.js +299 -332
  4. package/dist/auggie/sdk-mcp-server.d.ts +5 -3
  5. package/dist/auggie/sdk-mcp-server.js +102 -112
  6. package/dist/context/direct-context.d.ts +82 -22
  7. package/dist/context/direct-context.js +675 -562
  8. package/dist/context/filesystem-context.d.ts +5 -3
  9. package/dist/context/filesystem-context.js +187 -209
  10. package/dist/context/internal/__mocks__/api-client.d.ts +17 -11
  11. package/dist/context/internal/__mocks__/api-client.js +104 -91
  12. package/dist/context/internal/api-client.d.ts +14 -11
  13. package/dist/context/internal/api-client.js +234 -239
  14. package/dist/context/internal/blob-name-calculator.d.ts +5 -4
  15. package/dist/context/internal/blob-name-calculator.js +41 -38
  16. package/dist/context/internal/chat-utils.d.ts +6 -3
  17. package/dist/context/internal/chat-utils.js +5 -18
  18. package/dist/context/internal/credentials.d.ts +5 -4
  19. package/dist/context/internal/credentials.js +24 -38
  20. package/dist/context/internal/retry-utils.d.ts +5 -4
  21. package/dist/context/internal/retry-utils.js +60 -114
  22. package/dist/context/internal/search-utils.d.ts +3 -2
  23. package/dist/context/internal/search-utils.js +8 -9
  24. package/dist/context/internal/session-reader.d.ts +4 -3
  25. package/dist/context/internal/session-reader.js +14 -22
  26. package/dist/context/types.d.ts +132 -13
  27. package/dist/context/types.js +0 -5
  28. package/dist/index.d.ts +8 -7
  29. package/dist/index.js +14 -9
  30. package/dist/version.d.ts +3 -2
  31. package/dist/version.js +24 -38
  32. package/package.json +3 -2
  33. package/dist/auggie/sdk-acp-client.d.ts.map +0 -1
  34. package/dist/auggie/sdk-acp-client.js.map +0 -1
  35. package/dist/auggie/sdk-mcp-server.d.ts.map +0 -1
  36. package/dist/auggie/sdk-mcp-server.js.map +0 -1
  37. package/dist/context/direct-context.d.ts.map +0 -1
  38. package/dist/context/direct-context.js.map +0 -1
  39. package/dist/context/filesystem-context.d.ts.map +0 -1
  40. package/dist/context/filesystem-context.js.map +0 -1
  41. package/dist/context/internal/__mocks__/api-client.d.ts.map +0 -1
  42. package/dist/context/internal/__mocks__/api-client.js.map +0 -1
  43. package/dist/context/internal/api-client.d.ts.map +0 -1
  44. package/dist/context/internal/api-client.js.map +0 -1
  45. package/dist/context/internal/blob-name-calculator.d.ts.map +0 -1
  46. package/dist/context/internal/blob-name-calculator.js.map +0 -1
  47. package/dist/context/internal/chat-utils.d.ts.map +0 -1
  48. package/dist/context/internal/chat-utils.js.map +0 -1
  49. package/dist/context/internal/credentials.d.ts.map +0 -1
  50. package/dist/context/internal/credentials.js.map +0 -1
  51. package/dist/context/internal/retry-utils.d.ts.map +0 -1
  52. package/dist/context/internal/retry-utils.js.map +0 -1
  53. package/dist/context/internal/search-utils.d.ts.map +0 -1
  54. package/dist/context/internal/search-utils.js.map +0 -1
  55. package/dist/context/internal/session-reader.d.ts.map +0 -1
  56. package/dist/context/internal/session-reader.js.map +0 -1
  57. package/dist/context/types.d.ts.map +0 -1
  58. package/dist/context/types.js.map +0 -1
  59. package/dist/index.d.ts.map +0 -1
  60. package/dist/index.js.map +0 -1
  61. package/dist/version.d.ts.map +0 -1
  62. package/dist/version.js.map +0 -1
@@ -1,5 +1,6 @@
1
- import type { Tool } from "ai";
2
- export declare class AuggieMCPServer {
1
+ import { Tool } from 'ai';
2
+
3
+ declare class AuggieMCPServer {
3
4
  private readonly server;
4
5
  private httpServer;
5
6
  private PORT;
@@ -9,4 +10,5 @@ export declare class AuggieMCPServer {
9
10
  start(): Promise<string>;
10
11
  stop(): Promise<void>;
11
12
  }
12
- //# sourceMappingURL=sdk-mcp-server.d.ts.map
13
+
14
+ export { AuggieMCPServer };
@@ -1,123 +1,113 @@
1
- import { createServer as createHTTPServer, } from "node:http";
1
+ import {
2
+ createServer as createHTTPServer
3
+ } from "node:http";
2
4
  import { createServer } from "node:net";
3
5
  import { MCPServer } from "@mastra/mcp";
4
- /**
5
- * Find a free port by creating a temporary server on port 0
6
- * and getting the assigned port number
7
- */
8
6
  function findFreePort() {
9
- return new Promise((resolve, reject) => {
10
- const server = createServer();
11
- server.unref();
12
- server.on("error", reject);
13
- server.listen(0, () => {
14
- const address = server.address();
15
- if (address && typeof address !== "string") {
16
- const port = address.port;
17
- server.close(() => {
18
- resolve(port);
19
- });
20
- }
21
- else {
22
- reject(new Error("Failed to get port from server address"));
23
- }
7
+ return new Promise((resolve, reject) => {
8
+ const server = createServer();
9
+ server.unref();
10
+ server.on("error", reject);
11
+ server.listen(0, () => {
12
+ const address = server.address();
13
+ if (address && typeof address !== "string") {
14
+ const port = address.port;
15
+ server.close(() => {
16
+ resolve(port);
24
17
  });
18
+ } else {
19
+ reject(new Error("Failed to get port from server address"));
20
+ }
25
21
  });
22
+ });
26
23
  }
27
- export class AuggieMCPServer {
28
- constructor(tools, PORT) {
29
- this.httpServer = null;
30
- this.serverPATH = "/mcp";
31
- this.activeSockets = new Set();
32
- // Wrap AI SDK tools to match Mastra's expected signature
33
- // Mastra wraps the actual tool parameters in a 'context' property
34
- // AI SDK tools expect: execute({ param1, param2 })
35
- // Mastra passes: execute({ context: { param1, param2 }, runtimeContext, ... }, mcpContext)
36
- const wrappedTools = {};
37
- for (const [name, tool] of Object.entries(tools)) {
38
- wrappedTools[name] = {
39
- ...tool,
40
- execute: async (args, mcpContext) => {
41
- // Extract the actual tool parameters from the 'context' property
42
- const toolParams = args?.context || args;
43
- // Call the original AI SDK tool's execute with the unwrapped parameters
44
- // AI SDK tools may expect (params, options) signature
45
- if (tool.execute) {
46
- return await tool.execute(toolParams, mcpContext);
47
- }
48
- throw new Error(`Tool ${name} does not have an execute function`);
49
- },
50
- };
24
+ class AuggieMCPServer {
25
+ server;
26
+ httpServer = null;
27
+ PORT;
28
+ serverPATH = "/mcp";
29
+ activeSockets = /* @__PURE__ */ new Set();
30
+ constructor(tools, PORT) {
31
+ const wrappedTools = {};
32
+ for (const [name, tool] of Object.entries(tools)) {
33
+ wrappedTools[name] = {
34
+ ...tool,
35
+ execute: async (args, mcpContext) => {
36
+ const toolParams = args?.context || args;
37
+ if (tool.execute) {
38
+ return await tool.execute(
39
+ toolParams,
40
+ mcpContext
41
+ );
42
+ }
43
+ throw new Error(`Tool ${name} does not have an execute function`);
51
44
  }
52
- this.server = new MCPServer({
53
- name: "auggie-mcp",
54
- version: "1.0.0",
55
- tools: wrappedTools,
56
- });
57
- this.PORT = PORT;
45
+ };
58
46
  }
59
- async start() {
60
- // If PORT is undefined, find a free port
61
- if (this.PORT === undefined) {
62
- this.PORT = await findFreePort();
63
- }
64
- const httpServer = createHTTPServer(async (req, res) => {
65
- await this.server.startHTTP({
66
- url: new URL(req.url || "", `http://localhost:${this.PORT}`),
67
- httpPath: this.serverPATH,
68
- req,
69
- res,
70
- options: {
71
- sessionIdGenerator: undefined,
72
- },
73
- });
74
- });
75
- // Store the server instance
76
- this.httpServer = httpServer;
77
- // Track active connections for faster shutdown
78
- httpServer.on("connection", (socket) => {
79
- this.activeSockets.add(socket);
80
- socket.on("close", () => {
81
- this.activeSockets.delete(socket);
82
- });
83
- });
84
- // Wait for the server to start listening before returning
85
- await new Promise((resolve, reject) => {
86
- httpServer.listen(this.PORT, () => {
87
- resolve();
88
- });
89
- httpServer.on("error", reject);
90
- });
91
- const serverURL = new URL(this.serverPATH, `http://localhost:${this.PORT}`);
92
- return serverURL.toString();
47
+ this.server = new MCPServer({
48
+ name: "auggie-mcp",
49
+ version: "1.0.0",
50
+ tools: wrappedTools
51
+ });
52
+ this.PORT = PORT;
53
+ }
54
+ async start() {
55
+ if (this.PORT === void 0) {
56
+ this.PORT = await findFreePort();
93
57
  }
94
- async stop() {
95
- // Close the HTTP server first with a timeout
96
- if (this.httpServer) {
97
- await Promise.race([
98
- new Promise((resolve, reject) => {
99
- this.httpServer?.close((err) => {
100
- if (err)
101
- reject(err);
102
- else
103
- resolve();
104
- });
105
- }),
106
- // Timeout after 1 second
107
- new Promise((resolve) => setTimeout(resolve, 1000)),
108
- ]);
109
- // Force close by destroying all connections if still open
110
- if (this.httpServer.listening) {
111
- this.httpServer.closeAllConnections?.();
112
- }
113
- this.httpServer = null;
114
- }
115
- // Then close the MCP server with a timeout
116
- await Promise.race([
117
- this.server.close(),
118
- // Timeout after 1 second
119
- new Promise((resolve) => setTimeout(resolve, 1000)),
120
- ]);
58
+ const httpServer = createHTTPServer(
59
+ async (req, res) => {
60
+ await this.server.startHTTP({
61
+ url: new URL(req.url || "", `http://localhost:${this.PORT}`),
62
+ httpPath: this.serverPATH,
63
+ req,
64
+ res,
65
+ options: {
66
+ sessionIdGenerator: void 0
67
+ }
68
+ });
69
+ }
70
+ );
71
+ this.httpServer = httpServer;
72
+ httpServer.on("connection", (socket) => {
73
+ this.activeSockets.add(socket);
74
+ socket.on("close", () => {
75
+ this.activeSockets.delete(socket);
76
+ });
77
+ });
78
+ await new Promise((resolve, reject) => {
79
+ httpServer.listen(this.PORT, () => {
80
+ resolve();
81
+ });
82
+ httpServer.on("error", reject);
83
+ });
84
+ const serverURL = new URL(this.serverPATH, `http://localhost:${this.PORT}`);
85
+ return serverURL.toString();
86
+ }
87
+ async stop() {
88
+ if (this.httpServer) {
89
+ await Promise.race([
90
+ new Promise((resolve, reject) => {
91
+ this.httpServer?.close((err) => {
92
+ if (err) reject(err);
93
+ else resolve();
94
+ });
95
+ }),
96
+ // Timeout after 1 second
97
+ new Promise((resolve) => setTimeout(resolve, 1e3))
98
+ ]);
99
+ if (this.httpServer.listening) {
100
+ this.httpServer.closeAllConnections?.();
101
+ }
102
+ this.httpServer = null;
121
103
  }
104
+ await Promise.race([
105
+ this.server.close(),
106
+ // Timeout after 1 second
107
+ new Promise((resolve) => setTimeout(resolve, 1e3))
108
+ ]);
109
+ }
122
110
  }
123
- //# sourceMappingURL=sdk-mcp-server.js.map
111
+ export {
112
+ AuggieMCPServer
113
+ };
@@ -1,4 +1,5 @@
1
- import type { DirectContextOptions, DirectContextState, File, IndexingResult } from "./types";
1
+ import { DirectContextOptions, DirectContextState, File, AddToIndexOptions, IndexingResult, IndexingProgress, ExportOptions } from './types.js';
2
+
2
3
  /**
3
4
  * Direct Context - API-based indexing with import/export state
4
5
  *
@@ -42,6 +43,26 @@ import type { DirectContextOptions, DirectContextState, File, IndexingResult } f
42
43
  * await context.search("query"); // files are now indexed
43
44
  * ```
44
45
  *
46
+ * **Option 3: Set a timeout**
47
+ * ```typescript
48
+ * // By default, waits indefinitely. Set a timeout if needed:
49
+ * await context.addToIndex(files, { timeout: 10 * 60 * 1000 }); // 10 minutes
50
+ * // or
51
+ * await context.waitForIndexing(10 * 60 * 1000);
52
+ * ```
53
+ *
54
+ * **Option 4: Track progress during indexing**
55
+ * ```typescript
56
+ * await context.addToIndex(files, {
57
+ * onProgress: (progress) => {
58
+ * console.log(`[${progress.stage}] Uploaded: ${progress.uploaded}/${progress.total}, Indexed: ${progress.indexed}/${progress.total}`);
59
+ * if (progress.stage === 'uploading') {
60
+ * console.log(` Bytes uploaded: ${progress.bytesUploaded}`);
61
+ * }
62
+ * }
63
+ * });
64
+ * ```
65
+ *
45
66
  * Note: `search()` and `searchAndAsk()` do not wait for indexing automatically.
46
67
  *
47
68
  * ## State Persistence
@@ -58,7 +79,7 @@ import type { DirectContextOptions, DirectContextState, File, IndexingResult } f
58
79
  * const context = await DirectContext.importFromFile("state.json");
59
80
  * ```
60
81
  */
61
- export declare class DirectContext {
82
+ declare class DirectContext {
62
83
  private static readonly MAX_FILE_SIZE_BYTES;
63
84
  private static readonly MAX_BATCH_UPLOAD_SIZE;
64
85
  private static readonly MAX_BATCH_CONTENT_BYTES;
@@ -70,18 +91,23 @@ export declare class DirectContext {
70
91
  /**
71
92
  * State management:
72
93
  *
73
- * blobMap: Tracks all files that have been uploaded (path -> blobName).
94
+ * blobMap: Tracks all files that have been uploaded (path -> serverBlobId).
74
95
  * This includes both indexed and non-indexed blobs.
75
96
  * Also, includes both checkpointed and non-checkpointed blobs.
97
+ * The server blob ID is the authoritative identifier.
98
+ *
99
+ * clientBlobMap: Tracks client-computed blob IDs (path -> clientBlobId).
100
+ * Used for detecting unchanged files on the client side.
101
+ * May differ from serverBlobId due to encoding differences.
76
102
  *
77
103
  * checkpointId: The current checkpoint ID from the backend.
78
104
  * Checkpoints are named snapshots of the blob set for performance.
79
105
  * Updated after each successful checkpoint operation.
80
106
  *
81
- * pendingAdded: Blob names that have been uploaded but not yet checkpointed.
107
+ * pendingAdded: Blob IDs that have been uploaded but not yet checkpointed.
82
108
  * Accumulated until CHECKPOINT_THRESHOLD is reached.
83
109
  *
84
- * pendingDeleted: Blob names that have been removed but not yet checkpointed.
110
+ * pendingDeleted: Blob IDs that have been removed but not yet checkpointed.
85
111
  * Accumulated until CHECKPOINT_THRESHOLD is reached.
86
112
  *
87
113
  * Note: Checkpointing and indexing are independent operations.
@@ -89,9 +115,11 @@ export declare class DirectContext {
89
115
  * both, or neither.
90
116
  */
91
117
  private readonly blobMap;
118
+ private readonly clientBlobMap;
92
119
  private checkpointId?;
93
120
  private pendingAdded;
94
121
  private pendingDeleted;
122
+ private isSearchOnly;
95
123
  private readonly mutex;
96
124
  private readonly pollingMutex;
97
125
  /**
@@ -133,12 +161,18 @@ export declare class DirectContext {
133
161
  * Log a debug message if debug mode is enabled
134
162
  */
135
163
  private log;
164
+ /**
165
+ * Create a progress context for an operation
166
+ */
167
+ private createProgressContext;
136
168
  /**
137
169
  * Create a checkpoint if threshold is reached
138
170
  */
139
171
  private maybeCheckpoint;
140
172
  /**
141
173
  * Get the list of indexed file paths
174
+ *
175
+ * @throws Error if the context was imported from search-only state
142
176
  */
143
177
  getIndexedPaths(): string[];
144
178
  /**
@@ -151,22 +185,23 @@ export declare class DirectContext {
151
185
  * @param files - Array of files to add to the index
152
186
  * @param options - Optional configuration
153
187
  * @param options.waitForIndexing - If true (default), waits for the newly added files to be indexed before returning
188
+ * @param options.timeout - Timeout in milliseconds for indexing operation (default: undefined = no timeout)
189
+ * @param options.onProgress - Optional callback to receive progress updates
154
190
  * @returns Result indicating which files were newly uploaded vs already uploaded
191
+ * @throws Error if the context was imported from search-only state
155
192
  */
156
- addToIndex(files: File[], options?: {
157
- waitForIndexing?: boolean;
158
- }): Promise<IndexingResult>;
193
+ addToIndex(files: File[], options?: AddToIndexOptions): Promise<IndexingResult>;
159
194
  /**
160
- * Check which blobs are missing or not yet indexed on the server
195
+ * Find blobs that are missing or not yet indexed on the backend (detailed result)
196
+ * Batches requests in chunks of 1000
161
197
  *
162
198
  * @param blobNames - Array of blob names to check
163
- * @param includeNonIndexed - If true, includes blobs that are uploaded but not yet indexed.
164
- * If false, only returns blobs that need to be uploaded.
165
- * @returns Array of blob names that are either missing or not indexed (depending on flag)
199
+ * @returns Object with unknownBlobNames and nonindexedBlobNames arrays
166
200
  */
167
- private findMissingBlobs;
201
+ private findMissingBlobsDetailed;
168
202
  /**
169
203
  * Upload files in batches respecting backend limits
204
+ * Returns a map of client-computed blob IDs to backend-returned blob IDs
170
205
  */
171
206
  private batchUploadFiles;
172
207
  /**
@@ -182,16 +217,14 @@ export declare class DirectContext {
182
217
  * Handle replacing an existing blob (track deletion of old blob)
183
218
  */
184
219
  private handleBlobReplacement;
185
- /**
186
- * Categorize files into newly uploaded vs already on server based on server response
187
- */
188
- private categorizeFiles;
189
220
  /**
190
221
  * Internal implementation of addToIndex
191
222
  */
192
223
  private doAddToIndex;
193
224
  /**
194
225
  * Remove paths from the index
226
+ *
227
+ * @throws Error if the context was imported from search-only state
195
228
  */
196
229
  removeFromIndex(paths: string[]): Promise<void>;
197
230
  /**
@@ -211,6 +244,10 @@ export declare class DirectContext {
211
244
  *
212
245
  * This method is serialized via pollingMutex to prevent unbounded concurrent
213
246
  * polling requests to the backend.
247
+ *
248
+ * @param blobNames - Array of blob names to wait for
249
+ * @param timeoutMs - Timeout in milliseconds (default: undefined = no timeout)
250
+ * @param ctx - Progress context for reporting
214
251
  */
215
252
  private waitForSpecificBlobs;
216
253
  /**
@@ -219,10 +256,12 @@ export declare class DirectContext {
219
256
  * This method polls the backend until all files that have been added to the index
220
257
  * are confirmed to be indexed and searchable.
221
258
  *
259
+ * @param timeout - Timeout in milliseconds (default: undefined = no timeout)
260
+ * @param onProgress - Optional callback to receive progress updates
222
261
  * @returns Promise that resolves when all files are indexed
223
- * @throws Error if indexing times out (default: 10 minutes)
262
+ * @throws Error if indexing times out (only when timeout is specified)
224
263
  */
225
- waitForIndexing(): Promise<void>;
264
+ waitForIndexing(timeout?: number, onProgress?: (progress: IndexingProgress) => void): Promise<void>;
226
265
  /**
227
266
  * Search the codebase using natural language and return formatted results.
228
267
  *
@@ -269,15 +308,36 @@ export declare class DirectContext {
269
308
  searchAndAsk(searchQuery: string, prompt?: string): Promise<string>;
270
309
  /**
271
310
  * Export the current state to a JSON object
311
+ *
312
+ * @param options Export options
313
+ * @param options.mode Export mode - 'full' (default) includes all blob information,
314
+ * 'search-only' excludes blobs array for minimal storage
315
+ * @returns The exported state object
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // Full export (default) - supports all operations
320
+ * const fullState = context.export();
321
+ * const fullState = context.export({ mode: 'full' });
322
+ *
323
+ * // Search-only export - much smaller, only supports search operations
324
+ * const searchState = context.export({ mode: 'search-only' });
325
+ * ```
272
326
  */
273
- export(): DirectContextState;
327
+ export(options?: ExportOptions): DirectContextState;
274
328
  /**
275
329
  * Internal method to import state from a JSON object
276
330
  */
277
331
  private doImport;
278
332
  /**
279
333
  * Export state to a file (Node.js only)
334
+ *
335
+ * @param filePath Path to save the state file
336
+ * @param options Export options
337
+ * @param options.mode Export mode - 'full' (default) includes all blob information,
338
+ * 'search-only' excludes blobs array for minimal storage
280
339
  */
281
- exportToFile(filePath: string): Promise<void>;
340
+ exportToFile(filePath: string, options?: ExportOptions): Promise<void>;
282
341
  }
283
- //# sourceMappingURL=direct-context.d.ts.map
342
+
343
+ export { DirectContext };