add-ai-tools 1.2.3 → 1.2.4
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/index.mjs +18 -14
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -488,9 +488,22 @@ var GitHubFetcher = class {
|
|
|
488
488
|
parser;
|
|
489
489
|
baseApiUrl = "https://api.github.com";
|
|
490
490
|
baseRawUrl = "https://raw.githubusercontent.com";
|
|
491
|
+
token;
|
|
491
492
|
concurrencyLimit = 10;
|
|
492
493
|
constructor() {
|
|
493
494
|
this.parser = new ResourceParser();
|
|
495
|
+
this.token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* 인증 헤더를 포함한 공통 헤더를 반환합니다
|
|
499
|
+
*/
|
|
500
|
+
getHeaders() {
|
|
501
|
+
const headers = {
|
|
502
|
+
Accept: "application/vnd.github.v3+json",
|
|
503
|
+
"User-Agent": "ai-toolkit"
|
|
504
|
+
};
|
|
505
|
+
if (this.token) headers["Authorization"] = `Bearer ${this.token}`;
|
|
506
|
+
return headers;
|
|
494
507
|
}
|
|
495
508
|
/**
|
|
496
509
|
* GitHub 소스에서 리소스 목록을 가져옵니다
|
|
@@ -516,10 +529,7 @@ var GitHubFetcher = class {
|
|
|
516
529
|
async fetchTree(owner, repo, ref) {
|
|
517
530
|
const sha = await this.getRefSha(owner, repo, ref);
|
|
518
531
|
const url = `${this.baseApiUrl}/repos/${owner}/${repo}/git/trees/${sha}?recursive=1`;
|
|
519
|
-
const response = await fetch(url, { headers:
|
|
520
|
-
Accept: "application/vnd.github.v3+json",
|
|
521
|
-
"User-Agent": "ai-toolkit"
|
|
522
|
-
} });
|
|
532
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
523
533
|
if (!response.ok) this.handleHttpError(response.status, `tree/${sha}`);
|
|
524
534
|
const data = await response.json();
|
|
525
535
|
if (data.truncated) console.warn("Warning: Repository tree was truncated. Some files may be missing.");
|
|
@@ -530,10 +540,7 @@ var GitHubFetcher = class {
|
|
|
530
540
|
*/
|
|
531
541
|
async getDefaultBranch(owner, repo) {
|
|
532
542
|
const url = `${this.baseApiUrl}/repos/${owner}/${repo}`;
|
|
533
|
-
const response = await fetch(url, { headers:
|
|
534
|
-
Accept: "application/vnd.github.v3+json",
|
|
535
|
-
"User-Agent": "ai-toolkit"
|
|
536
|
-
} });
|
|
543
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
537
544
|
if (!response.ok) return "main";
|
|
538
545
|
return (await response.json()).default_branch || "main";
|
|
539
546
|
}
|
|
@@ -542,10 +549,7 @@ var GitHubFetcher = class {
|
|
|
542
549
|
*/
|
|
543
550
|
async getRefSha(owner, repo, ref) {
|
|
544
551
|
const branchUrl = `${this.baseApiUrl}/repos/${owner}/${repo}/branches/${ref}`;
|
|
545
|
-
const response = await fetch(branchUrl, { headers:
|
|
546
|
-
Accept: "application/vnd.github.v3+json",
|
|
547
|
-
"User-Agent": "ai-toolkit"
|
|
548
|
-
} });
|
|
552
|
+
const response = await fetch(branchUrl, { headers: this.getHeaders() });
|
|
549
553
|
if (response.ok) return (await response.json()).commit.sha;
|
|
550
554
|
if (response.status === 404) return ref;
|
|
551
555
|
this.handleHttpError(response.status, `branches/${ref}`);
|
|
@@ -588,7 +592,7 @@ var GitHubFetcher = class {
|
|
|
588
592
|
*/
|
|
589
593
|
async fetchFileContent(owner, repo, path, ref) {
|
|
590
594
|
const url = `${this.baseRawUrl}/${owner}/${repo}/${ref}/${path}`;
|
|
591
|
-
const response = await fetch(url);
|
|
595
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
592
596
|
if (!response.ok) this.handleHttpError(response.status, path);
|
|
593
597
|
return response.text();
|
|
594
598
|
}
|
|
@@ -683,7 +687,7 @@ var GitHubFetcher = class {
|
|
|
683
687
|
switch (status) {
|
|
684
688
|
case 404: throw new GitHubNotFoundError(path);
|
|
685
689
|
case 403: throw new GitHubRateLimitError(path);
|
|
686
|
-
case 401: throw new GitHubApiError("Authentication required", status, path);
|
|
690
|
+
case 401: throw new GitHubApiError("Authentication required. Set GITHUB_TOKEN or GH_TOKEN environment variable for private repos.", status, path);
|
|
687
691
|
case 500:
|
|
688
692
|
case 502:
|
|
689
693
|
case 503: throw new GitHubApiError("GitHub server error. Please try again later.", status, path);
|