@catchmexz/fedin-vibe-mcp-server 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/operations/codeup/files.js +84 -36
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { yunxiaoRequest, buildUrl, pathEscape } from "../../common/utils.js";
|
|
2
2
|
import { FileContentSchema, CreateFileResponseSchema, DeleteFileResponseSchema, FileInfoSchema } from "./types.js";
|
|
3
|
-
import * as fs from
|
|
4
|
-
import pkg from
|
|
5
|
-
import * as path from
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import pkg from "fs-extra";
|
|
5
|
+
import * as path from "path";
|
|
6
6
|
import minimatch from "minimatch";
|
|
7
7
|
const { removeSync } = pkg;
|
|
8
8
|
function readGitignore(projectPath) {
|
|
@@ -84,6 +84,8 @@ function getAllFiles(dir, ignorePatterns) {
|
|
|
84
84
|
if (!shouldIgnoreFile(fullPath, ignorePatterns)) {
|
|
85
85
|
try {
|
|
86
86
|
const relativePath = path.relative(dir, fullPath);
|
|
87
|
+
// 将Windows的反斜杠路径分隔符转换为正斜杠,以适配远程仓库
|
|
88
|
+
const normalizedPath = relativePath.replace(/\\/g, "/");
|
|
87
89
|
let content;
|
|
88
90
|
let encoding = "text";
|
|
89
91
|
if (isBinaryFile(fullPath)) {
|
|
@@ -97,7 +99,7 @@ function getAllFiles(dir, ignorePatterns) {
|
|
|
97
99
|
encoding = "text";
|
|
98
100
|
}
|
|
99
101
|
files.push({
|
|
100
|
-
path:
|
|
102
|
+
path: normalizedPath,
|
|
101
103
|
content: content,
|
|
102
104
|
encoding: encoding
|
|
103
105
|
});
|
|
@@ -248,33 +250,70 @@ export async function createFileFunc(organizationId, repositoryId, filePath, con
|
|
|
248
250
|
});
|
|
249
251
|
return CreateFileResponseSchema.parse(response);
|
|
250
252
|
}
|
|
253
|
+
async function getRepositoryDomain(projectId) {
|
|
254
|
+
const query = `
|
|
255
|
+
SELECT
|
|
256
|
+
ch.id as id,
|
|
257
|
+
ch.custom_domain as custom_domain,
|
|
258
|
+
ch.domain_certificate as domain_certificate
|
|
259
|
+
FROM
|
|
260
|
+
public.chat_history AS ch
|
|
261
|
+
WHERE
|
|
262
|
+
ch.id = '${projectId}'
|
|
263
|
+
`;
|
|
264
|
+
try {
|
|
265
|
+
const response = await fetch("https://ai.fedin.cn/api/supabase/query", {
|
|
266
|
+
method: "post",
|
|
267
|
+
body: JSON.stringify({
|
|
268
|
+
query
|
|
269
|
+
}),
|
|
270
|
+
headers: {
|
|
271
|
+
"Content-Type": "application/json"
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
const data = await response.json();
|
|
275
|
+
if (data.length > 0) {
|
|
276
|
+
return {
|
|
277
|
+
id: data[0].id,
|
|
278
|
+
custom_domain: data[0].custom_domain,
|
|
279
|
+
domain_certificate: data[0].domain_certificate
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
console.error("项目ID无效:未找到对应的项目");
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.error("获取项目信息失败", error);
|
|
289
|
+
return {};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
251
292
|
export async function pushFilesFunc(organizationId, repositoryId, commitMessage, projectPath, projectId) {
|
|
252
293
|
// 读取 .gitignore 模式
|
|
253
294
|
// const ignorePatterns = readGitignore(projectPath);
|
|
254
295
|
const ignorePatterns = [
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
296
|
+
"dist",
|
|
297
|
+
".next",
|
|
298
|
+
"node_modules",
|
|
299
|
+
".git",
|
|
300
|
+
".vercel",
|
|
301
|
+
".cache",
|
|
302
|
+
"build",
|
|
303
|
+
"out",
|
|
304
|
+
".nuxt",
|
|
305
|
+
".svelte-kit",
|
|
306
|
+
"package-lock.json",
|
|
307
|
+
".DS_Store"
|
|
267
308
|
];
|
|
268
309
|
// 获取所有文件
|
|
269
310
|
const files = getAllFiles(projectPath, ignorePatterns);
|
|
270
311
|
// 检测项目类型
|
|
271
312
|
let projectType = "default"; // 默认值
|
|
272
313
|
// 检查是否存在 Next.js 配置文件
|
|
273
|
-
const hasNextConfig = files.some(file => file.path ===
|
|
274
|
-
file.path === 'next.config.ts');
|
|
314
|
+
const hasNextConfig = files.some((file) => file.path === "next.config.js" || file.path === "next.config.ts");
|
|
275
315
|
// 检查是否存在 Vite 配置文件
|
|
276
|
-
const hasViteConfig = files.some(file => file.path ===
|
|
277
|
-
file.path === 'vite.config.ts');
|
|
316
|
+
const hasViteConfig = files.some((file) => file.path === "vite.config.js" || file.path === "vite.config.ts");
|
|
278
317
|
// 根据配置文件设置项目类型
|
|
279
318
|
if (hasNextConfig) {
|
|
280
319
|
projectType = "fc";
|
|
@@ -323,22 +362,31 @@ export async function pushFilesFunc(organizationId, repositoryId, commitMessage,
|
|
|
323
362
|
deleteFileErrors.push(error.message);
|
|
324
363
|
}
|
|
325
364
|
}
|
|
326
|
-
const
|
|
365
|
+
const pipelineBody = {
|
|
366
|
+
name: projectId,
|
|
367
|
+
projectId: projectId,
|
|
368
|
+
repoUrl: `https://codeup.aliyun.com/ctrod/fedin-ai-project/${projectId}.git`,
|
|
369
|
+
projectType,
|
|
370
|
+
organizationId: organizationId,
|
|
371
|
+
token: process.env.YUNXIAO_ACCESS_TOKEN
|
|
372
|
+
};
|
|
373
|
+
const projectInfo = await getRepositoryDomain(projectId);
|
|
374
|
+
if (projectInfo.custom_domain) {
|
|
375
|
+
pipelineBody.customDomain = projectInfo.custom_domain;
|
|
376
|
+
}
|
|
377
|
+
// 如果配置了证书,添加到请求体中
|
|
378
|
+
if (projectInfo.domain_certificate) {
|
|
379
|
+
pipelineBody.certificate = projectInfo.domain_certificate;
|
|
380
|
+
}
|
|
381
|
+
const pipelineResponse = await fetch("https://ai.fedin.cn/api/alicloud/create-pipeline-run", {
|
|
327
382
|
method: "POST",
|
|
328
|
-
body: JSON.stringify(
|
|
329
|
-
name: projectId,
|
|
330
|
-
projectId: projectId,
|
|
331
|
-
repoUrl: `https://codeup.aliyun.com/ctrod/fedin-ai-project/${projectId}.git`,
|
|
332
|
-
projectType,
|
|
333
|
-
organizationId: organizationId,
|
|
334
|
-
token: process.env.YUNXIAO_ACCESS_TOKEN
|
|
335
|
-
}),
|
|
383
|
+
body: JSON.stringify(pipelineBody),
|
|
336
384
|
headers: {
|
|
337
385
|
"Content-Type": "application/json",
|
|
338
386
|
token: "fedin_ac_9x7k2m8p4w6q1z5n3v7b9c2e8r4t6"
|
|
339
387
|
}
|
|
340
388
|
});
|
|
341
|
-
const pipelineResult = await pipelineResponse.json();
|
|
389
|
+
const pipelineResult = (await pipelineResponse.json());
|
|
342
390
|
let onlineUrl;
|
|
343
391
|
if (pipelineResult.success && pipelineResult.data?.onlineUrl) {
|
|
344
392
|
onlineUrl = pipelineResult.data.onlineUrl;
|
|
@@ -350,9 +398,9 @@ export async function pushFilesFunc(organizationId, repositoryId, commitMessage,
|
|
|
350
398
|
updateFilesSuccess,
|
|
351
399
|
updateFileErrors,
|
|
352
400
|
deleteFilesSuccess,
|
|
353
|
-
deleteFileErrors
|
|
401
|
+
deleteFileErrors
|
|
354
402
|
},
|
|
355
|
-
onlineUrl: onlineUrl ||
|
|
403
|
+
onlineUrl: onlineUrl || ""
|
|
356
404
|
};
|
|
357
405
|
}
|
|
358
406
|
/**
|
|
@@ -376,16 +424,16 @@ export async function pullFilesFunc(organizationId, repositoryId, currntProjectP
|
|
|
376
424
|
const fileDir = path.dirname(fullPath);
|
|
377
425
|
fs.mkdirSync(fileDir, { recursive: true });
|
|
378
426
|
// 根据编码写入文件
|
|
379
|
-
if (fileBlob.encoding ===
|
|
380
|
-
const buffer = Buffer.from(fileBlob.content ||
|
|
427
|
+
if (fileBlob.encoding === "base64") {
|
|
428
|
+
const buffer = Buffer.from(fileBlob.content || "", "base64");
|
|
381
429
|
fs.writeFileSync(fullPath, buffer);
|
|
382
430
|
}
|
|
383
431
|
else {
|
|
384
|
-
fs.writeFileSync(fullPath, fileBlob.content ||
|
|
432
|
+
fs.writeFileSync(fullPath, fileBlob.content || "", "utf-8");
|
|
385
433
|
}
|
|
386
434
|
}
|
|
387
435
|
catch (error) {
|
|
388
|
-
console.error(
|
|
436
|
+
console.error("[获取文件内容失败]:", error);
|
|
389
437
|
}
|
|
390
438
|
}
|
|
391
439
|
return allRemoteFilesPath;
|