add-ai-tools 1.2.3 → 1.2.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/index.mjs +33 -14
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import * as os from "os";
|
|
|
6
6
|
import { homedir } from "os";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { join } from "path";
|
|
9
|
+
import { execSync } from "node:child_process";
|
|
9
10
|
import { parse } from "yaml";
|
|
10
11
|
import { basename, dirname, join as join$1 } from "node:path";
|
|
11
12
|
import { exec } from "child_process";
|
|
@@ -488,9 +489,36 @@ var GitHubFetcher = class {
|
|
|
488
489
|
parser;
|
|
489
490
|
baseApiUrl = "https://api.github.com";
|
|
490
491
|
baseRawUrl = "https://raw.githubusercontent.com";
|
|
492
|
+
token;
|
|
491
493
|
concurrencyLimit = 10;
|
|
492
494
|
constructor() {
|
|
493
495
|
this.parser = new ResourceParser();
|
|
496
|
+
this.token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || this.getGhCliToken();
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* gh CLI에서 인증 토큰을 가져옵니다
|
|
500
|
+
*/
|
|
501
|
+
getGhCliToken() {
|
|
502
|
+
try {
|
|
503
|
+
return execSync("gh auth token", { stdio: [
|
|
504
|
+
"pipe",
|
|
505
|
+
"pipe",
|
|
506
|
+
"ignore"
|
|
507
|
+
] }).toString().trim() || void 0;
|
|
508
|
+
} catch {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* 인증 헤더를 포함한 공통 헤더를 반환합니다
|
|
514
|
+
*/
|
|
515
|
+
getHeaders() {
|
|
516
|
+
const headers = {
|
|
517
|
+
Accept: "application/vnd.github.v3+json",
|
|
518
|
+
"User-Agent": "ai-toolkit"
|
|
519
|
+
};
|
|
520
|
+
if (this.token) headers["Authorization"] = `Bearer ${this.token}`;
|
|
521
|
+
return headers;
|
|
494
522
|
}
|
|
495
523
|
/**
|
|
496
524
|
* GitHub 소스에서 리소스 목록을 가져옵니다
|
|
@@ -516,10 +544,7 @@ var GitHubFetcher = class {
|
|
|
516
544
|
async fetchTree(owner, repo, ref) {
|
|
517
545
|
const sha = await this.getRefSha(owner, repo, ref);
|
|
518
546
|
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
|
-
} });
|
|
547
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
523
548
|
if (!response.ok) this.handleHttpError(response.status, `tree/${sha}`);
|
|
524
549
|
const data = await response.json();
|
|
525
550
|
if (data.truncated) console.warn("Warning: Repository tree was truncated. Some files may be missing.");
|
|
@@ -530,10 +555,7 @@ var GitHubFetcher = class {
|
|
|
530
555
|
*/
|
|
531
556
|
async getDefaultBranch(owner, repo) {
|
|
532
557
|
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
|
-
} });
|
|
558
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
537
559
|
if (!response.ok) return "main";
|
|
538
560
|
return (await response.json()).default_branch || "main";
|
|
539
561
|
}
|
|
@@ -542,10 +564,7 @@ var GitHubFetcher = class {
|
|
|
542
564
|
*/
|
|
543
565
|
async getRefSha(owner, repo, ref) {
|
|
544
566
|
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
|
-
} });
|
|
567
|
+
const response = await fetch(branchUrl, { headers: this.getHeaders() });
|
|
549
568
|
if (response.ok) return (await response.json()).commit.sha;
|
|
550
569
|
if (response.status === 404) return ref;
|
|
551
570
|
this.handleHttpError(response.status, `branches/${ref}`);
|
|
@@ -588,7 +607,7 @@ var GitHubFetcher = class {
|
|
|
588
607
|
*/
|
|
589
608
|
async fetchFileContent(owner, repo, path, ref) {
|
|
590
609
|
const url = `${this.baseRawUrl}/${owner}/${repo}/${ref}/${path}`;
|
|
591
|
-
const response = await fetch(url);
|
|
610
|
+
const response = await fetch(url, { headers: this.getHeaders() });
|
|
592
611
|
if (!response.ok) this.handleHttpError(response.status, path);
|
|
593
612
|
return response.text();
|
|
594
613
|
}
|
|
@@ -683,7 +702,7 @@ var GitHubFetcher = class {
|
|
|
683
702
|
switch (status) {
|
|
684
703
|
case 404: throw new GitHubNotFoundError(path);
|
|
685
704
|
case 403: throw new GitHubRateLimitError(path);
|
|
686
|
-
case 401: throw new GitHubApiError("Authentication required", status, path);
|
|
705
|
+
case 401: throw new GitHubApiError("Authentication required. Set GITHUB_TOKEN or GH_TOKEN environment variable for private repos.", status, path);
|
|
687
706
|
case 500:
|
|
688
707
|
case 502:
|
|
689
708
|
case 503: throw new GitHubApiError("GitHub server error. Please try again later.", status, path);
|