@augmentcode/auggie-sdk 0.1.9 → 0.1.11
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 +7 -6
- package/dist/auggie/sdk-acp-client.js +299 -332
- package/dist/auggie/sdk-mcp-server.d.ts +5 -3
- package/dist/auggie/sdk-mcp-server.js +102 -112
- package/dist/context/direct-context.d.ts +19 -15
- package/dist/context/direct-context.js +556 -567
- package/dist/context/filesystem-context.d.ts +5 -3
- package/dist/context/filesystem-context.js +187 -209
- package/dist/context/internal/__mocks__/api-client.d.ts +17 -11
- package/dist/context/internal/__mocks__/api-client.js +104 -91
- package/dist/context/internal/api-client.d.ts +15 -15
- package/dist/context/internal/api-client.js +233 -224
- package/dist/context/internal/blob-name-calculator.d.ts +5 -4
- package/dist/context/internal/blob-name-calculator.js +41 -38
- package/dist/context/internal/chat-utils.d.ts +6 -3
- package/dist/context/internal/chat-utils.js +5 -18
- package/dist/context/internal/credentials.d.ts +5 -4
- package/dist/context/internal/credentials.js +24 -38
- package/dist/context/internal/retry-utils.d.ts +5 -4
- package/dist/context/internal/retry-utils.js +60 -114
- package/dist/context/internal/search-utils.d.ts +3 -2
- package/dist/context/internal/search-utils.js +8 -9
- package/dist/context/internal/session-reader.d.ts +4 -3
- package/dist/context/internal/session-reader.js +14 -22
- package/dist/context/types.d.ts +17 -12
- package/dist/context/types.js +0 -5
- package/dist/index.d.ts +8 -7
- package/dist/index.js +14 -9
- package/dist/version.d.ts +3 -2
- package/dist/version.js +24 -38
- package/package.json +3 -2
- package/dist/auggie/sdk-acp-client.d.ts.map +0 -1
- package/dist/auggie/sdk-acp-client.js.map +0 -1
- package/dist/auggie/sdk-mcp-server.d.ts.map +0 -1
- package/dist/auggie/sdk-mcp-server.js.map +0 -1
- package/dist/context/direct-context.d.ts.map +0 -1
- package/dist/context/direct-context.js.map +0 -1
- package/dist/context/filesystem-context.d.ts.map +0 -1
- package/dist/context/filesystem-context.js.map +0 -1
- package/dist/context/internal/__mocks__/api-client.d.ts.map +0 -1
- package/dist/context/internal/__mocks__/api-client.js.map +0 -1
- package/dist/context/internal/api-client.d.ts.map +0 -1
- package/dist/context/internal/api-client.js.map +0 -1
- package/dist/context/internal/blob-name-calculator.d.ts.map +0 -1
- package/dist/context/internal/blob-name-calculator.js.map +0 -1
- package/dist/context/internal/chat-utils.d.ts.map +0 -1
- package/dist/context/internal/chat-utils.js.map +0 -1
- package/dist/context/internal/credentials.d.ts.map +0 -1
- package/dist/context/internal/credentials.js.map +0 -1
- package/dist/context/internal/retry-utils.d.ts.map +0 -1
- package/dist/context/internal/retry-utils.js.map +0 -1
- package/dist/context/internal/search-utils.d.ts.map +0 -1
- package/dist/context/internal/search-utils.js.map +0 -1
- package/dist/context/internal/session-reader.d.ts.map +0 -1
- package/dist/context/internal/session-reader.js.map +0 -1
- package/dist/context/types.d.ts.map +0 -1
- package/dist/context/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
|
@@ -1,238 +1,247 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API client for Context operations
|
|
3
|
-
* Handles both indexing endpoints and LLM chat endpoint
|
|
4
|
-
*/
|
|
5
1
|
import { v4 as uuidv4 } from "uuid";
|
|
6
|
-
import { getSDKVersion } from "../../version";
|
|
7
|
-
import { retryChat, retryWithBackoff } from "./retry-utils";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.statusText = statusText;
|
|
18
|
-
}
|
|
2
|
+
import { getSDKVersion } from "../../version.js";
|
|
3
|
+
import { retryChat, retryWithBackoff } from "./retry-utils.js";
|
|
4
|
+
class APIError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
statusText;
|
|
7
|
+
constructor(status, statusText, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "APIError";
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.statusText = statusText;
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
export function getUserAgent() {
|
|
24
|
-
return `augment.sdk.context/${getSDKVersion()} (typescript)`;
|
|
14
|
+
function getUserAgent() {
|
|
15
|
+
return `augment.sdk.context/${getSDKVersion()} (typescript)`;
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
createRequestId() {
|
|
42
|
-
return uuidv4();
|
|
43
|
-
}
|
|
44
|
-
async callApi(endpoint, payload, requestId) {
|
|
45
|
-
// Remove trailing slash from apiUrl if present
|
|
46
|
-
const baseUrl = this.apiUrl.endsWith("/")
|
|
47
|
-
? this.apiUrl.slice(0, -1)
|
|
48
|
-
: this.apiUrl;
|
|
49
|
-
const url = `${baseUrl}/${endpoint}`;
|
|
50
|
-
this.log(`POST ${url}`);
|
|
51
|
-
this.log(`Request ID: ${requestId}`);
|
|
52
|
-
this.log(`Request: ${JSON.stringify(payload, null, 2)}`);
|
|
53
|
-
const response = await fetch(url, {
|
|
54
|
-
method: "POST",
|
|
55
|
-
headers: {
|
|
56
|
-
"Content-Type": "application/json",
|
|
57
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
58
|
-
"X-Request-Session-Id": this.sessionId,
|
|
59
|
-
"X-Request-Id": requestId,
|
|
60
|
-
"User-Agent": getUserAgent(),
|
|
61
|
-
},
|
|
62
|
-
body: JSON.stringify(payload),
|
|
63
|
-
});
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
const errorText = await response.text();
|
|
66
|
-
throw new APIError(response.status, response.statusText, `API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
67
|
-
}
|
|
68
|
-
const json = (await response.json());
|
|
69
|
-
this.log(`Response: ${JSON.stringify(json, null, 2)}`);
|
|
70
|
-
return json;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Call API with automatic retry logic and stable request ID across retries
|
|
74
|
-
*/
|
|
75
|
-
async callApiWithRetry(endpoint, payload) {
|
|
76
|
-
const requestId = this.createRequestId();
|
|
77
|
-
return await retryWithBackoff(() => this.callApi(endpoint, payload, requestId), this.debug);
|
|
78
|
-
}
|
|
79
|
-
async findMissing(blobNames) {
|
|
80
|
-
const result = await this.callApiWithRetry("find-missing", {
|
|
81
|
-
mem_object_names: blobNames,
|
|
82
|
-
});
|
|
83
|
-
return {
|
|
84
|
-
unknownBlobNames: result.unknown_memory_names || [],
|
|
85
|
-
nonindexedBlobNames: result.nonindexed_blob_names || [],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
async batchUpload(blobs) {
|
|
89
|
-
const result = await this.callApiWithRetry("batch-upload", {
|
|
90
|
-
blobs: blobs.map((blob) => ({
|
|
91
|
-
blob_name: blob.blobName,
|
|
92
|
-
path: blob.pathName,
|
|
93
|
-
content: blob.text,
|
|
94
|
-
})),
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
blobNames: result.blob_names || [],
|
|
98
|
-
};
|
|
17
|
+
class ContextAPIClient {
|
|
18
|
+
apiKey;
|
|
19
|
+
apiUrl;
|
|
20
|
+
sessionId;
|
|
21
|
+
debug;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.apiKey = options.apiKey;
|
|
24
|
+
this.apiUrl = options.apiUrl;
|
|
25
|
+
this.sessionId = uuidv4();
|
|
26
|
+
this.debug = options.debug ?? false;
|
|
27
|
+
}
|
|
28
|
+
log(message) {
|
|
29
|
+
if (this.debug) {
|
|
30
|
+
console.log(`[ContextAPI] ${message}`);
|
|
99
31
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
32
|
+
}
|
|
33
|
+
createRequestId() {
|
|
34
|
+
return uuidv4();
|
|
35
|
+
}
|
|
36
|
+
async callApi(endpoint, payload, requestId) {
|
|
37
|
+
const baseUrl = this.apiUrl.endsWith("/") ? this.apiUrl.slice(0, -1) : this.apiUrl;
|
|
38
|
+
const url = `${baseUrl}/${endpoint}`;
|
|
39
|
+
this.log(`POST ${url}`);
|
|
40
|
+
this.log(`Request ID: ${requestId}`);
|
|
41
|
+
this.log(`Request: ${JSON.stringify(payload, null, 2)}`);
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
47
|
+
"X-Request-Session-Id": this.sessionId,
|
|
48
|
+
"X-Request-Id": requestId,
|
|
49
|
+
"User-Agent": getUserAgent()
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(payload)
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const errorText = await response.text();
|
|
55
|
+
throw new APIError(
|
|
56
|
+
response.status,
|
|
57
|
+
response.statusText,
|
|
58
|
+
`API request failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
59
|
+
);
|
|
111
60
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
61
|
+
const json = await response.json();
|
|
62
|
+
this.log(`Response: ${JSON.stringify(json, null, 2)}`);
|
|
63
|
+
return json;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Call API with automatic retry logic and stable request ID across retries
|
|
67
|
+
*/
|
|
68
|
+
async callApiWithRetry(endpoint, payload) {
|
|
69
|
+
const requestId = this.createRequestId();
|
|
70
|
+
return await retryWithBackoff(
|
|
71
|
+
() => this.callApi(endpoint, payload, requestId),
|
|
72
|
+
this.debug
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
async findMissing(blobNames) {
|
|
76
|
+
const result = await this.callApiWithRetry("find-missing", {
|
|
77
|
+
mem_object_names: blobNames
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
unknownBlobNames: result.unknown_memory_names || [],
|
|
81
|
+
nonindexedBlobNames: result.nonindexed_blob_names || []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async batchUpload(blobs) {
|
|
85
|
+
const result = await this.callApiWithRetry(
|
|
86
|
+
"batch-upload",
|
|
87
|
+
{
|
|
88
|
+
blobs: blobs.map((blob) => ({
|
|
89
|
+
blob_name: blob.blobName,
|
|
90
|
+
path: blob.pathName,
|
|
91
|
+
content: blob.text
|
|
92
|
+
}))
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
blobNames: result.blob_names || []
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async checkpointBlobs(blobs) {
|
|
100
|
+
const result = await this.callApiWithRetry(
|
|
101
|
+
"checkpoint-blobs",
|
|
102
|
+
{
|
|
103
|
+
blobs: {
|
|
104
|
+
checkpoint_id: blobs.checkpointId ?? null,
|
|
105
|
+
added_blobs: blobs.addedBlobs,
|
|
106
|
+
deleted_blobs: blobs.deletedBlobs
|
|
124
107
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
return {
|
|
111
|
+
newCheckpointId: result.new_checkpoint_id
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async agentCodebaseRetrieval(query, blobs, maxOutputLength) {
|
|
115
|
+
const requestBody = {
|
|
116
|
+
information_request: query,
|
|
117
|
+
blobs: {
|
|
118
|
+
checkpoint_id: blobs.checkpointId ?? null,
|
|
119
|
+
added_blobs: blobs.addedBlobs,
|
|
120
|
+
deleted_blobs: blobs.deletedBlobs
|
|
121
|
+
},
|
|
122
|
+
dialog: []
|
|
123
|
+
};
|
|
124
|
+
if (maxOutputLength !== void 0) {
|
|
125
|
+
requestBody.max_output_length = maxOutputLength;
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
const result = await this.callApiWithRetry(
|
|
128
|
+
"agents/codebase-retrieval",
|
|
129
|
+
requestBody
|
|
130
|
+
);
|
|
131
|
+
return {
|
|
132
|
+
formattedRetrieval: result.formatted_retrieval
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Parse streaming response and accumulate text chunks
|
|
137
|
+
* Uses a buffer to handle JSON objects that span multiple lines or chunks
|
|
138
|
+
*/
|
|
139
|
+
async parseSSEStream(body) {
|
|
140
|
+
const reader = body.getReader();
|
|
141
|
+
const decoder = new TextDecoder();
|
|
142
|
+
let accumulatedText = "";
|
|
143
|
+
let textBuffer = "";
|
|
144
|
+
try {
|
|
145
|
+
while (true) {
|
|
146
|
+
const { done, value } = await reader.read();
|
|
147
|
+
if (done) break;
|
|
148
|
+
textBuffer += decoder.decode(value, { stream: true });
|
|
149
|
+
while (textBuffer.includes("\n")) {
|
|
150
|
+
const newLineIndex = textBuffer.indexOf("\n");
|
|
151
|
+
const line = textBuffer.substring(0, newLineIndex);
|
|
152
|
+
textBuffer = textBuffer.substring(newLineIndex + 1);
|
|
153
|
+
const trimmed = line.trim();
|
|
154
|
+
if (trimmed) {
|
|
155
|
+
try {
|
|
156
|
+
const parsed = JSON.parse(trimmed);
|
|
157
|
+
if (parsed.text) {
|
|
158
|
+
accumulatedText += parsed.text;
|
|
159
|
+
}
|
|
160
|
+
} catch (e) {
|
|
161
|
+
this.log(`JSON parse failed for line: ${trimmed}`);
|
|
142
162
|
}
|
|
163
|
+
}
|
|
143
164
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Parse streaming response and accumulate text chunks
|
|
152
|
-
*/
|
|
153
|
-
async parseSSEStream(body) {
|
|
154
|
-
const reader = body.getReader();
|
|
155
|
-
const decoder = new TextDecoder();
|
|
156
|
-
let accumulatedText = "";
|
|
165
|
+
}
|
|
166
|
+
const finalChunk = decoder.decode();
|
|
167
|
+
if (finalChunk) {
|
|
168
|
+
textBuffer += finalChunk;
|
|
169
|
+
}
|
|
170
|
+
if (textBuffer.trim()) {
|
|
157
171
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for (const line of lines) {
|
|
165
|
-
const text = this.parseStreamLine(line);
|
|
166
|
-
if (text) {
|
|
167
|
-
accumulatedText += text;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
finally {
|
|
173
|
-
reader.releaseLock();
|
|
172
|
+
const parsed = JSON.parse(textBuffer.trim());
|
|
173
|
+
if (parsed.text) {
|
|
174
|
+
accumulatedText += parsed.text;
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
this.log(`JSON parse failed for remaining buffer: ${textBuffer.trim()}`);
|
|
174
178
|
}
|
|
175
|
-
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
reader.releaseLock();
|
|
176
182
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
id: 0,
|
|
201
|
-
type: 0, // ChatRequestNodeType.TEXT = 0
|
|
202
|
-
text_node: {
|
|
203
|
-
content: prompt,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
chat_history: [],
|
|
208
|
-
conversation_id: this.sessionId,
|
|
209
|
-
};
|
|
210
|
-
this.log(`Request: ${JSON.stringify(payload, null, 2)}`);
|
|
211
|
-
const response = await fetch(url, {
|
|
212
|
-
method: "POST",
|
|
213
|
-
headers: {
|
|
214
|
-
"Content-Type": "application/json",
|
|
215
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
216
|
-
"X-Request-Session-Id": this.sessionId,
|
|
217
|
-
"X-Request-Id": requestId,
|
|
218
|
-
"conversation-id": this.sessionId,
|
|
219
|
-
"X-Mode": "sdk",
|
|
220
|
-
"User-Agent": getUserAgent(),
|
|
221
|
-
},
|
|
222
|
-
body: JSON.stringify(payload),
|
|
223
|
-
});
|
|
224
|
-
if (!response.ok) {
|
|
225
|
-
const errorText = await response.text();
|
|
226
|
-
throw new APIError(response.status, response.statusText, `API request failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
183
|
+
return accumulatedText;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Call the LLM chat streaming API with a formatted prompt
|
|
187
|
+
*
|
|
188
|
+
* @param prompt - The formatted prompt to send to the LLM
|
|
189
|
+
* @returns The LLM's response text
|
|
190
|
+
*/
|
|
191
|
+
async chat(prompt) {
|
|
192
|
+
const requestId = this.createRequestId();
|
|
193
|
+
return await retryChat(async () => {
|
|
194
|
+
const baseUrl = this.apiUrl.endsWith("/") ? this.apiUrl.slice(0, -1) : this.apiUrl;
|
|
195
|
+
const url = `${baseUrl}/chat-stream`;
|
|
196
|
+
this.log(`POST ${url}`);
|
|
197
|
+
this.log(`Request ID: ${requestId}`);
|
|
198
|
+
const payload = {
|
|
199
|
+
nodes: [
|
|
200
|
+
{
|
|
201
|
+
id: 0,
|
|
202
|
+
type: 0,
|
|
203
|
+
// ChatRequestNodeType.TEXT = 0
|
|
204
|
+
text_node: {
|
|
205
|
+
content: prompt
|
|
227
206
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
chat_history: [],
|
|
210
|
+
conversation_id: this.sessionId
|
|
211
|
+
};
|
|
212
|
+
this.log(`Request: ${JSON.stringify(payload, null, 2)}`);
|
|
213
|
+
const response = await fetch(url, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers: {
|
|
216
|
+
"Content-Type": "application/json",
|
|
217
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
218
|
+
"X-Request-Session-Id": this.sessionId,
|
|
219
|
+
"X-Request-Id": requestId,
|
|
220
|
+
"conversation-id": this.sessionId,
|
|
221
|
+
"X-Mode": "sdk",
|
|
222
|
+
"User-Agent": getUserAgent()
|
|
223
|
+
},
|
|
224
|
+
body: JSON.stringify(payload)
|
|
225
|
+
});
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
const errorText = await response.text();
|
|
228
|
+
throw new APIError(
|
|
229
|
+
response.status,
|
|
230
|
+
response.statusText,
|
|
231
|
+
`API request failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (!response.body) {
|
|
235
|
+
throw new Error("Response body is null");
|
|
236
|
+
}
|
|
237
|
+
const accumulatedText = await this.parseSSEStream(response.body);
|
|
238
|
+
this.log(`Response: ${accumulatedText}`);
|
|
239
|
+
return accumulatedText;
|
|
240
|
+
}, this.debug);
|
|
241
|
+
}
|
|
237
242
|
}
|
|
238
|
-
|
|
243
|
+
export {
|
|
244
|
+
APIError,
|
|
245
|
+
ContextAPIClient,
|
|
246
|
+
getUserAgent
|
|
247
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const blobNamingVersion = 2023102300;
|
|
2
|
+
declare class BlobTooLargeError extends Error {
|
|
3
3
|
constructor(maxBlobSize: number);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
declare class BlobNameCalculator {
|
|
6
6
|
private readonly _textEncoder;
|
|
7
7
|
readonly maxBlobSize: number;
|
|
8
8
|
constructor(maxBlobSize: number);
|
|
@@ -11,4 +11,5 @@ export declare class BlobNameCalculator {
|
|
|
11
11
|
calculate(path: string, contents: string | Uint8Array): string | undefined;
|
|
12
12
|
calculateNoThrow(path: string, contents: string | Uint8Array): string;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
export { BlobNameCalculator, BlobTooLargeError, blobNamingVersion };
|
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const blobNamingVersion = 2023102300;
|
|
3
|
+
class BlobTooLargeError extends Error {
|
|
4
|
+
constructor(maxBlobSize) {
|
|
5
|
+
super(`content exceeds maximum size of ${maxBlobSize}`);
|
|
6
|
+
}
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (checkFileSize && contentsBytes.length > this.maxBlobSize) {
|
|
28
|
-
throw new BlobTooLargeError(this.maxBlobSize);
|
|
29
|
-
}
|
|
30
|
-
return this._hash(path, contentsBytes);
|
|
8
|
+
class BlobNameCalculator {
|
|
9
|
+
_textEncoder = new TextEncoder();
|
|
10
|
+
maxBlobSize;
|
|
11
|
+
constructor(maxBlobSize) {
|
|
12
|
+
this.maxBlobSize = maxBlobSize;
|
|
13
|
+
}
|
|
14
|
+
_hash(path, contents) {
|
|
15
|
+
const hash = createHash("sha256");
|
|
16
|
+
hash.update(path);
|
|
17
|
+
hash.update(contents);
|
|
18
|
+
return hash.digest("hex");
|
|
19
|
+
}
|
|
20
|
+
calculateOrThrow(path, contents, checkFileSize = true) {
|
|
21
|
+
let contentsBytes;
|
|
22
|
+
if (typeof contents === "string") {
|
|
23
|
+
contentsBytes = this._textEncoder.encode(contents);
|
|
24
|
+
} else {
|
|
25
|
+
contentsBytes = contents;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.calculateOrThrow(path, contents, true);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
27
|
+
if (checkFileSize && contentsBytes.length > this.maxBlobSize) {
|
|
28
|
+
throw new BlobTooLargeError(this.maxBlobSize);
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
return this._hash(path, contentsBytes);
|
|
31
|
+
}
|
|
32
|
+
calculate(path, contents) {
|
|
33
|
+
try {
|
|
34
|
+
return this.calculateOrThrow(path, contents, true);
|
|
35
|
+
} catch {
|
|
36
|
+
return;
|
|
42
37
|
}
|
|
38
|
+
}
|
|
39
|
+
calculateNoThrow(path, contents) {
|
|
40
|
+
return this.calculateOrThrow(path, contents, false);
|
|
41
|
+
}
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
export {
|
|
44
|
+
BlobNameCalculator,
|
|
45
|
+
BlobTooLargeError,
|
|
46
|
+
blobNamingVersion
|
|
47
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ContextAPIClient } from './api-client.js';
|
|
2
|
+
import '../types.js';
|
|
3
|
+
|
|
2
4
|
/**
|
|
3
5
|
* Call the chat API with retry logic for transient failures
|
|
4
6
|
*
|
|
@@ -14,5 +16,6 @@ import type { ContextAPIClient } from "./api-client";
|
|
|
14
16
|
* @param _debug - Whether to log debug messages (unused, kept for compatibility)
|
|
15
17
|
* @returns The LLM's response text
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
declare function chatWithRetry(apiClient: ContextAPIClient, prompt: string, _debug?: boolean): Promise<string>;
|
|
20
|
+
|
|
21
|
+
export { chatWithRetry };
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* This function wraps the ContextAPIClient.chat() method with automatic
|
|
5
|
-
* retry logic for transient failures, including chat-specific status codes
|
|
6
|
-
* like 429 (rate limit) and 529 (overloaded).
|
|
7
|
-
*
|
|
8
|
-
* Note: The retry logic is now handled internally by the chat() method,
|
|
9
|
-
* so this function is just a simple wrapper for backwards compatibility.
|
|
10
|
-
*
|
|
11
|
-
* @param apiClient - The API client to use for the chat request
|
|
12
|
-
* @param prompt - The formatted prompt to send to the LLM
|
|
13
|
-
* @param _debug - Whether to log debug messages (unused, kept for compatibility)
|
|
14
|
-
* @returns The LLM's response text
|
|
15
|
-
*/
|
|
16
|
-
export async function chatWithRetry(apiClient, prompt, _debug = false) {
|
|
17
|
-
return await apiClient.chat(prompt);
|
|
1
|
+
async function chatWithRetry(apiClient, prompt, _debug = false) {
|
|
2
|
+
return await apiClient.chat(prompt);
|
|
18
3
|
}
|
|
19
|
-
|
|
4
|
+
export {
|
|
5
|
+
chatWithRetry
|
|
6
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options for credential resolution
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
type CredentialOptions = {
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
apiUrl?: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Resolved credentials
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
type ResolvedCredentials = {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
apiUrl: string;
|
|
14
14
|
};
|
|
@@ -24,5 +24,6 @@ export type ResolvedCredentials = {
|
|
|
24
24
|
* @returns Resolved credentials
|
|
25
25
|
* @throws Error if credentials cannot be resolved
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
declare function resolveCredentials(options?: CredentialOptions): Promise<ResolvedCredentials>;
|
|
28
|
+
|
|
29
|
+
export { type CredentialOptions, type ResolvedCredentials, resolveCredentials };
|