doer-agent 0.4.4 → 0.4.5
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/agent-fs-rpc.js +44 -13
- package/package.json +1 -1
package/dist/agent-fs-rpc.js
CHANGED
|
@@ -23,7 +23,7 @@ function normalizeFsRpcPath(workspaceRoot, rawPath) {
|
|
|
23
23
|
function parseFsRpcAction(value) {
|
|
24
24
|
if (value === "list" ||
|
|
25
25
|
value === "stat" ||
|
|
26
|
-
value === "
|
|
26
|
+
value === "upload_file" ||
|
|
27
27
|
value === "read_text" ||
|
|
28
28
|
value === "read_file" ||
|
|
29
29
|
value === "write_file" ||
|
|
@@ -184,27 +184,58 @@ async function executeFsRpc(args) {
|
|
|
184
184
|
size: archiveStat.size,
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
if (action === "
|
|
187
|
+
if (action === "upload_file") {
|
|
188
188
|
const entry = await stat(abs);
|
|
189
189
|
if (!entry.isFile()) {
|
|
190
190
|
throw new Error("path is not a file");
|
|
191
191
|
}
|
|
192
192
|
const uploadUrl = typeof args.request.uploadUrl === "string" ? args.request.uploadUrl : "";
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
const uploadMode = args.request.uploadMode === "multipart" ? "multipart" : "raw";
|
|
194
|
+
const uploadMethod = args.request.uploadMethod === "POST" ? "POST" : "PUT";
|
|
195
|
+
const uploadContentType = typeof args.request.uploadContentType === "string" && args.request.uploadContentType.trim()
|
|
196
|
+
? args.request.uploadContentType.trim()
|
|
197
|
+
: inferMimeType(abs);
|
|
198
|
+
const uploadFieldName = typeof args.request.uploadFieldName === "string" && args.request.uploadFieldName.trim()
|
|
199
|
+
? args.request.uploadFieldName.trim()
|
|
200
|
+
: "file";
|
|
201
|
+
if (!uploadUrl) {
|
|
202
|
+
throw new Error("uploadUrl is required");
|
|
196
203
|
}
|
|
197
204
|
const resolvedUploadUrl = new URL(uploadUrl, `${args.serverBaseUrl}/`).toString();
|
|
198
205
|
const data = await readFile(abs);
|
|
199
206
|
const fileName = path.basename(abs) || "file";
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
const serverOrigin = new URL(args.serverBaseUrl).origin;
|
|
208
|
+
const targetOrigin = new URL(resolvedUploadUrl).origin;
|
|
209
|
+
const headers = {};
|
|
210
|
+
if (targetOrigin === serverOrigin) {
|
|
211
|
+
headers.Authorization = `Bearer ${args.agentToken}`;
|
|
212
|
+
}
|
|
213
|
+
let response;
|
|
214
|
+
if (uploadMode === "multipart") {
|
|
215
|
+
const form = new FormData();
|
|
216
|
+
const formFields = args.request.formFields && typeof args.request.formFields === "object" && !Array.isArray(args.request.formFields)
|
|
217
|
+
? args.request.formFields
|
|
218
|
+
: {};
|
|
219
|
+
for (const [key, value] of Object.entries(formFields)) {
|
|
220
|
+
if (typeof value === "string") {
|
|
221
|
+
form.append(key, value);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
form.append(uploadFieldName, new File([data], fileName, { type: uploadContentType }));
|
|
225
|
+
response = await fetch(resolvedUploadUrl, {
|
|
226
|
+
method: uploadMethod,
|
|
227
|
+
headers,
|
|
228
|
+
body: form,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
headers["Content-Type"] = uploadContentType;
|
|
233
|
+
response = await fetch(resolvedUploadUrl, {
|
|
234
|
+
method: uploadMethod,
|
|
235
|
+
headers,
|
|
236
|
+
body: data,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
208
239
|
const text = await response.text();
|
|
209
240
|
let upload = {};
|
|
210
241
|
try {
|