@loopstack/github-module 0.1.0

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.
Files changed (142) hide show
  1. package/README.md +67 -0
  2. package/dist/github-oauth.provider.d.ts +19 -0
  3. package/dist/github-oauth.provider.d.ts.map +1 -0
  4. package/dist/github-oauth.provider.js +91 -0
  5. package/dist/github-oauth.provider.js.map +1 -0
  6. package/dist/github.module.d.ts +3 -0
  7. package/dist/github.module.d.ts.map +1 -0
  8. package/dist/github.module.js +75 -0
  9. package/dist/github.module.js.map +1 -0
  10. package/dist/index.d.ts +28 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +44 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/tools/actions/github-get-workflow-run.tool.d.ts +13 -0
  15. package/dist/tools/actions/github-get-workflow-run.tool.d.ts.map +1 -0
  16. package/dist/tools/actions/github-get-workflow-run.tool.js +106 -0
  17. package/dist/tools/actions/github-get-workflow-run.tool.js.map +1 -0
  18. package/dist/tools/actions/github-list-workflow-runs.tool.d.ts +16 -0
  19. package/dist/tools/actions/github-list-workflow-runs.tool.d.ts.map +1 -0
  20. package/dist/tools/actions/github-list-workflow-runs.tool.js +129 -0
  21. package/dist/tools/actions/github-list-workflow-runs.tool.js.map +1 -0
  22. package/dist/tools/actions/github-trigger-workflow.tool.d.ts +15 -0
  23. package/dist/tools/actions/github-trigger-workflow.tool.d.ts.map +1 -0
  24. package/dist/tools/actions/github-trigger-workflow.tool.js +101 -0
  25. package/dist/tools/actions/github-trigger-workflow.tool.js.map +1 -0
  26. package/dist/tools/content/github-create-or-update-file.tool.d.ts +17 -0
  27. package/dist/tools/content/github-create-or-update-file.tool.d.ts.map +1 -0
  28. package/dist/tools/content/github-create-or-update-file.tool.js +115 -0
  29. package/dist/tools/content/github-create-or-update-file.tool.js.map +1 -0
  30. package/dist/tools/content/github-get-commit.tool.d.ts +13 -0
  31. package/dist/tools/content/github-get-commit.tool.d.ts.map +1 -0
  32. package/dist/tools/content/github-get-commit.tool.js +113 -0
  33. package/dist/tools/content/github-get-commit.tool.js.map +1 -0
  34. package/dist/tools/content/github-get-file-content.tool.d.ts +14 -0
  35. package/dist/tools/content/github-get-file-content.tool.d.ts.map +1 -0
  36. package/dist/tools/content/github-get-file-content.tool.js +107 -0
  37. package/dist/tools/content/github-get-file-content.tool.js.map +1 -0
  38. package/dist/tools/content/github-list-directory.tool.d.ts +14 -0
  39. package/dist/tools/content/github-list-directory.tool.d.ts.map +1 -0
  40. package/dist/tools/content/github-list-directory.tool.js +102 -0
  41. package/dist/tools/content/github-list-directory.tool.js.map +1 -0
  42. package/dist/tools/issues/github-create-issue-comment.tool.d.ts +14 -0
  43. package/dist/tools/issues/github-create-issue-comment.tool.d.ts.map +1 -0
  44. package/dist/tools/issues/github-create-issue-comment.tool.js +100 -0
  45. package/dist/tools/issues/github-create-issue-comment.tool.js.map +1 -0
  46. package/dist/tools/issues/github-create-issue.tool.d.ts +16 -0
  47. package/dist/tools/issues/github-create-issue.tool.d.ts.map +1 -0
  48. package/dist/tools/issues/github-create-issue.tool.js +112 -0
  49. package/dist/tools/issues/github-create-issue.tool.js.map +1 -0
  50. package/dist/tools/issues/github-get-issue.tool.d.ts +13 -0
  51. package/dist/tools/issues/github-get-issue.tool.d.ts.map +1 -0
  52. package/dist/tools/issues/github-get-issue.tool.js +106 -0
  53. package/dist/tools/issues/github-get-issue.tool.js.map +1 -0
  54. package/dist/tools/issues/github-list-issues.tool.d.ts +17 -0
  55. package/dist/tools/issues/github-list-issues.tool.d.ts.map +1 -0
  56. package/dist/tools/issues/github-list-issues.tool.js +115 -0
  57. package/dist/tools/issues/github-list-issues.tool.js.map +1 -0
  58. package/dist/tools/pull-requests/github-create-pull-request.tool.d.ts +17 -0
  59. package/dist/tools/pull-requests/github-create-pull-request.tool.d.ts.map +1 -0
  60. package/dist/tools/pull-requests/github-create-pull-request.tool.js +113 -0
  61. package/dist/tools/pull-requests/github-create-pull-request.tool.js.map +1 -0
  62. package/dist/tools/pull-requests/github-get-pull-request.tool.d.ts +13 -0
  63. package/dist/tools/pull-requests/github-get-pull-request.tool.d.ts.map +1 -0
  64. package/dist/tools/pull-requests/github-get-pull-request.tool.js +113 -0
  65. package/dist/tools/pull-requests/github-get-pull-request.tool.js.map +1 -0
  66. package/dist/tools/pull-requests/github-list-pr-reviews.tool.d.ts +13 -0
  67. package/dist/tools/pull-requests/github-list-pr-reviews.tool.d.ts.map +1 -0
  68. package/dist/tools/pull-requests/github-list-pr-reviews.tool.js +97 -0
  69. package/dist/tools/pull-requests/github-list-pr-reviews.tool.js.map +1 -0
  70. package/dist/tools/pull-requests/github-list-pull-requests.tool.d.ts +16 -0
  71. package/dist/tools/pull-requests/github-list-pull-requests.tool.d.ts.map +1 -0
  72. package/dist/tools/pull-requests/github-list-pull-requests.tool.js +113 -0
  73. package/dist/tools/pull-requests/github-list-pull-requests.tool.js.map +1 -0
  74. package/dist/tools/pull-requests/github-merge-pull-request.tool.d.ts +16 -0
  75. package/dist/tools/pull-requests/github-merge-pull-request.tool.d.ts.map +1 -0
  76. package/dist/tools/pull-requests/github-merge-pull-request.tool.js +108 -0
  77. package/dist/tools/pull-requests/github-merge-pull-request.tool.js.map +1 -0
  78. package/dist/tools/repos/github-create-repo.tool.d.ts +14 -0
  79. package/dist/tools/repos/github-create-repo.tool.d.ts.map +1 -0
  80. package/dist/tools/repos/github-create-repo.tool.js +108 -0
  81. package/dist/tools/repos/github-create-repo.tool.js.map +1 -0
  82. package/dist/tools/repos/github-get-repo.tool.d.ts +12 -0
  83. package/dist/tools/repos/github-get-repo.tool.d.ts.map +1 -0
  84. package/dist/tools/repos/github-get-repo.tool.js +107 -0
  85. package/dist/tools/repos/github-get-repo.tool.js.map +1 -0
  86. package/dist/tools/repos/github-list-branches.tool.d.ts +13 -0
  87. package/dist/tools/repos/github-list-branches.tool.d.ts.map +1 -0
  88. package/dist/tools/repos/github-list-branches.tool.js +97 -0
  89. package/dist/tools/repos/github-list-branches.tool.js.map +1 -0
  90. package/dist/tools/repos/github-list-repos.tool.d.ts +14 -0
  91. package/dist/tools/repos/github-list-repos.tool.d.ts.map +1 -0
  92. package/dist/tools/repos/github-list-repos.tool.js +107 -0
  93. package/dist/tools/repos/github-list-repos.tool.js.map +1 -0
  94. package/dist/tools/search/github-search-code.tool.d.ts +13 -0
  95. package/dist/tools/search/github-search-code.tool.d.ts.map +1 -0
  96. package/dist/tools/search/github-search-code.tool.js +100 -0
  97. package/dist/tools/search/github-search-code.tool.js.map +1 -0
  98. package/dist/tools/search/github-search-issues.tool.d.ts +14 -0
  99. package/dist/tools/search/github-search-issues.tool.d.ts.map +1 -0
  100. package/dist/tools/search/github-search-issues.tool.js +109 -0
  101. package/dist/tools/search/github-search-issues.tool.js.map +1 -0
  102. package/dist/tools/search/github-search-repos.tool.d.ts +14 -0
  103. package/dist/tools/search/github-search-repos.tool.d.ts.map +1 -0
  104. package/dist/tools/search/github-search-repos.tool.js +106 -0
  105. package/dist/tools/search/github-search-repos.tool.js.map +1 -0
  106. package/dist/tools/users/github-get-authenticated-user.tool.d.ts +9 -0
  107. package/dist/tools/users/github-get-authenticated-user.tool.d.ts.map +1 -0
  108. package/dist/tools/users/github-get-authenticated-user.tool.js +96 -0
  109. package/dist/tools/users/github-get-authenticated-user.tool.js.map +1 -0
  110. package/dist/tools/users/github-list-user-orgs.tool.d.ts +11 -0
  111. package/dist/tools/users/github-list-user-orgs.tool.d.ts.map +1 -0
  112. package/dist/tools/users/github-list-user-orgs.tool.js +95 -0
  113. package/dist/tools/users/github-list-user-orgs.tool.js.map +1 -0
  114. package/package.json +81 -0
  115. package/src/github-oauth.provider.ts +85 -0
  116. package/src/github.module.ts +63 -0
  117. package/src/index.ts +27 -0
  118. package/src/tools/actions/github-get-workflow-run.tool.ts +115 -0
  119. package/src/tools/actions/github-list-workflow-runs.tool.ts +141 -0
  120. package/src/tools/actions/github-trigger-workflow.tool.ts +97 -0
  121. package/src/tools/content/github-create-or-update-file.tool.ts +124 -0
  122. package/src/tools/content/github-get-commit.tool.ts +124 -0
  123. package/src/tools/content/github-get-file-content.tool.ts +112 -0
  124. package/src/tools/content/github-list-directory.tool.ts +105 -0
  125. package/src/tools/issues/github-create-issue-comment.tool.ts +100 -0
  126. package/src/tools/issues/github-create-issue.tool.ts +114 -0
  127. package/src/tools/issues/github-get-issue.tool.ts +115 -0
  128. package/src/tools/issues/github-list-issues.tool.ts +126 -0
  129. package/src/tools/pull-requests/github-create-pull-request.tool.ts +119 -0
  130. package/src/tools/pull-requests/github-get-pull-request.tool.ts +128 -0
  131. package/src/tools/pull-requests/github-list-pr-reviews.tool.ts +99 -0
  132. package/src/tools/pull-requests/github-list-pull-requests.tool.ts +124 -0
  133. package/src/tools/pull-requests/github-merge-pull-request.tool.ts +108 -0
  134. package/src/tools/repos/github-create-repo.tool.ts +111 -0
  135. package/src/tools/repos/github-get-repo.tool.ts +120 -0
  136. package/src/tools/repos/github-list-branches.tool.ts +97 -0
  137. package/src/tools/repos/github-list-repos.tool.ts +115 -0
  138. package/src/tools/search/github-search-code.tool.ts +105 -0
  139. package/src/tools/search/github-search-issues.tool.ts +120 -0
  140. package/src/tools/search/github-search-repos.tool.ts +115 -0
  141. package/src/tools/users/github-get-authenticated-user.tool.ts +98 -0
  142. package/src/tools/users/github-list-user-orgs.tool.ts +94 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-list-workflow-runs.tool.js","sourceRoot":"","sources":["../../../src/tools/actions/github-list-workflow-runs.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAgD;AAChD,6BAAwB;AACxB,8CAAuF;AACvF,0DAA0D;AAiBnD,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IACpB,MAAM,GAAG,IAAI,eAAM,CAAC,4BAA0B,CAAC,IAAI,CAAC,CAAC;IAG9D,UAAU,CAAkB;IA+BpC,IAAI,CAA6B;IAEjC,KAAK,CAAC,OAAO,CAAC,IAAgC,EAAE,GA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ACL,MAAM,EAAE,OAAC;aACN,MAAM,CAAC;YACN,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC7B,MAAM,EAAE,OAAC;iBACN,IAAI,CAAC;gBACJ,WAAW;gBACX,iBAAiB;gBACjB,WAAW;gBACX,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,OAAO;gBACP,SAAS;gBACT,WAAW;gBACX,aAAa;gBACb,QAAQ;gBACR,WAAW;gBACX,SAAS;gBACT,SAAS;aACV,CAAC;iBACD,QAAQ,EAAE;YACb,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;SAC5B,CAAC;aACD,MAAM,EAAE;KACZ,CAAC;;wDAC+B;qCAnCtB,0BAA0B;IANtC,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EACT,gHAAgH;SACnH;KACF,CAAC;GACW,0BAA0B,CAwHtC"}
@@ -0,0 +1,15 @@
1
+ import { RunContext, ToolInterface, ToolResult } from '@loopstack/common';
2
+ export type GitHubTriggerWorkflowArgs = {
3
+ owner: string;
4
+ repo: string;
5
+ workflowId: string;
6
+ ref: string;
7
+ inputs?: Record<string, string>;
8
+ };
9
+ export declare class GitHubTriggerWorkflowTool implements ToolInterface {
10
+ private readonly logger;
11
+ private tokenStore;
12
+ args: GitHubTriggerWorkflowArgs;
13
+ execute(args: GitHubTriggerWorkflowArgs, ctx: RunContext): Promise<ToolResult>;
14
+ }
15
+ //# sourceMappingURL=github-trigger-workflow.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-trigger-workflow.tool.d.ts","sourceRoot":"","sources":["../../../src/tools/actions/github-trigger-workflow.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,UAAU,EAAQ,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,qBAMa,yBAA0B,YAAW,aAAa;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;IAGrE,OAAO,CAAC,UAAU,CAAkB;IAapC,IAAI,EAAE,yBAAyB,CAAC;IAE1B,OAAO,CAAC,IAAI,EAAE,yBAAyB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CA0DrF"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var GitHubTriggerWorkflowTool_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GitHubTriggerWorkflowTool = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const zod_1 = require("zod");
16
+ const common_2 = require("@loopstack/common");
17
+ const oauth_module_1 = require("@loopstack/oauth-module");
18
+ let GitHubTriggerWorkflowTool = GitHubTriggerWorkflowTool_1 = class GitHubTriggerWorkflowTool {
19
+ logger = new common_1.Logger(GitHubTriggerWorkflowTool_1.name);
20
+ tokenStore;
21
+ args;
22
+ async execute(args, ctx) {
23
+ const accessToken = await this.tokenStore.getValidAccessToken(ctx.userId, 'github');
24
+ if (!accessToken) {
25
+ return {
26
+ data: {
27
+ error: 'unauthorized',
28
+ message: 'No valid GitHub token found. Please authenticate first.',
29
+ },
30
+ };
31
+ }
32
+ const requestBody = {
33
+ ref: args.ref,
34
+ };
35
+ if (args.inputs)
36
+ requestBody.inputs = args.inputs;
37
+ const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/actions/workflows/${encodeURIComponent(args.workflowId)}/dispatches`;
38
+ const response = await fetch(url, {
39
+ method: 'POST',
40
+ headers: {
41
+ Authorization: `Bearer ${accessToken}`,
42
+ Accept: 'application/vnd.github+json',
43
+ 'X-GitHub-Api-Version': '2022-11-28',
44
+ 'Content-Type': 'application/json',
45
+ },
46
+ body: JSON.stringify(requestBody),
47
+ });
48
+ if (response.status === 401 || response.status === 403) {
49
+ this.logger.warn(`GitHub API returned ${response.status} for user ${ctx.userId}`);
50
+ return {
51
+ data: {
52
+ error: '401',
53
+ message: 'GitHub token was rejected. Please re-authenticate.',
54
+ },
55
+ };
56
+ }
57
+ if (!response.ok && response.status !== 204) {
58
+ const body = await response.text();
59
+ this.logger.error(`GitHub API error: ${response.status} ${body}`);
60
+ return {
61
+ data: {
62
+ error: 'api_error',
63
+ message: `GitHub API error: ${response.statusText}`,
64
+ },
65
+ };
66
+ }
67
+ return {
68
+ data: {
69
+ triggered: true,
70
+ message: 'Workflow dispatch event triggered successfully.',
71
+ },
72
+ };
73
+ }
74
+ };
75
+ exports.GitHubTriggerWorkflowTool = GitHubTriggerWorkflowTool;
76
+ __decorate([
77
+ (0, common_1.Inject)(),
78
+ __metadata("design:type", oauth_module_1.OAuthTokenStore)
79
+ ], GitHubTriggerWorkflowTool.prototype, "tokenStore", void 0);
80
+ __decorate([
81
+ (0, common_2.Input)({
82
+ schema: zod_1.z
83
+ .object({
84
+ owner: zod_1.z.string(),
85
+ repo: zod_1.z.string(),
86
+ workflowId: zod_1.z.string(),
87
+ ref: zod_1.z.string(),
88
+ inputs: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
89
+ })
90
+ .strict(),
91
+ }),
92
+ __metadata("design:type", Object)
93
+ ], GitHubTriggerWorkflowTool.prototype, "args", void 0);
94
+ exports.GitHubTriggerWorkflowTool = GitHubTriggerWorkflowTool = GitHubTriggerWorkflowTool_1 = __decorate([
95
+ (0, common_2.Tool)({
96
+ config: {
97
+ description: 'Triggers a GitHub Actions workflow dispatch event. Returns 204 No Content on success. Returns { error: "unauthorized" } if no valid token is available.',
98
+ },
99
+ })
100
+ ], GitHubTriggerWorkflowTool);
101
+ //# sourceMappingURL=github-trigger-workflow.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-trigger-workflow.tool.js","sourceRoot":"","sources":["../../../src/tools/actions/github-trigger-workflow.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAgD;AAChD,6BAAwB;AACxB,8CAAuF;AACvF,0DAA0D;AAgBnD,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IACnB,MAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;IAG7D,UAAU,CAAkB;IAapC,IAAI,CAA4B;IAEhC,KAAK,CAAC,OAAO,CAAC,IAA+B,EAAE,GAAe;QAC5D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO;gBACL,IAAI,EAAE;oBACJ,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yDAAyD;iBACnE;aACF,CAAC;QACJ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J,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,qBAAqB,QAAQ,CAAC,UAAU,EAAE;iBACpD;aACF,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE;gBACJ,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,iDAAiD;aAC3D;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA7EY,8DAAyB;AAI5B;IADP,IAAA,eAAM,GAAE;8BACW,8BAAe;6DAAC;AAapC;IAXC,IAAA,cAAK,EAAC;QACL,MAAM,EAAE,OAAC;aACN,MAAM,CAAC;YACN,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;YACtB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;YACf,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;SACpD,CAAC;aACD,MAAM,EAAE;KACZ,CAAC;;uDAC8B;oCAjBrB,yBAAyB;IANrC,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EACT,yJAAyJ;SAC5J;KACF,CAAC;GACW,yBAAyB,CA6ErC"}
@@ -0,0 +1,17 @@
1
+ import { RunContext, ToolInterface, ToolResult } from '@loopstack/common';
2
+ export type GitHubCreateOrUpdateFileArgs = {
3
+ owner: string;
4
+ repo: string;
5
+ path: string;
6
+ content: string;
7
+ message: string;
8
+ sha?: string;
9
+ branch?: string;
10
+ };
11
+ export declare class GitHubCreateOrUpdateFileTool implements ToolInterface {
12
+ private readonly logger;
13
+ private tokenStore;
14
+ args: GitHubCreateOrUpdateFileArgs;
15
+ execute(args: GitHubCreateOrUpdateFileArgs, ctx: RunContext): Promise<ToolResult>;
16
+ }
17
+ //# sourceMappingURL=github-create-or-update-file.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-create-or-update-file.tool.d.ts","sourceRoot":"","sources":["../../../src/tools/content/github-create-or-update-file.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,UAAU,EAAQ,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,4BAA4B,GAAG;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAMa,4BAA6B,YAAW,aAAa;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiD;IAGxE,OAAO,CAAC,UAAU,CAAkB;IAepC,IAAI,EAAE,4BAA4B,CAAC;IAE7B,OAAO,CAAC,IAAI,EAAE,4BAA4B,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAiFxF"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var GitHubCreateOrUpdateFileTool_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GitHubCreateOrUpdateFileTool = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const zod_1 = require("zod");
16
+ const common_2 = require("@loopstack/common");
17
+ const oauth_module_1 = require("@loopstack/oauth-module");
18
+ let GitHubCreateOrUpdateFileTool = GitHubCreateOrUpdateFileTool_1 = class GitHubCreateOrUpdateFileTool {
19
+ logger = new common_1.Logger(GitHubCreateOrUpdateFileTool_1.name);
20
+ tokenStore;
21
+ args;
22
+ async execute(args, ctx) {
23
+ const accessToken = await this.tokenStore.getValidAccessToken(ctx.userId, 'github');
24
+ if (!accessToken) {
25
+ return {
26
+ data: {
27
+ error: 'unauthorized',
28
+ message: 'No valid GitHub token found. Please authenticate first.',
29
+ },
30
+ };
31
+ }
32
+ const requestBody = {
33
+ message: args.message,
34
+ content: Buffer.from(args.content).toString('base64'),
35
+ };
36
+ if (args.sha)
37
+ requestBody.sha = args.sha;
38
+ if (args.branch)
39
+ requestBody.branch = args.branch;
40
+ const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/contents/${args.path}`;
41
+ const response = await fetch(url, {
42
+ method: 'PUT',
43
+ headers: {
44
+ Authorization: `Bearer ${accessToken}`,
45
+ Accept: 'application/vnd.github+json',
46
+ 'X-GitHub-Api-Version': '2022-11-28',
47
+ 'Content-Type': 'application/json',
48
+ },
49
+ body: JSON.stringify(requestBody),
50
+ });
51
+ if (response.status === 401 || response.status === 403) {
52
+ this.logger.warn(`GitHub API returned ${response.status} for user ${ctx.userId}`);
53
+ return {
54
+ data: {
55
+ error: '401',
56
+ message: 'GitHub token was rejected. Please re-authenticate.',
57
+ },
58
+ };
59
+ }
60
+ if (!response.ok) {
61
+ const errorBody = await response.text();
62
+ this.logger.error(`GitHub API error: ${response.status} ${errorBody}`);
63
+ return {
64
+ data: {
65
+ error: 'api_error',
66
+ message: `GitHub API error: ${response.statusText}`,
67
+ },
68
+ };
69
+ }
70
+ const data = (await response.json());
71
+ return {
72
+ data: {
73
+ file: {
74
+ name: data.content.name,
75
+ path: data.content.path,
76
+ sha: data.content.sha,
77
+ htmlUrl: data.content.html_url,
78
+ },
79
+ commit: {
80
+ sha: data.commit.sha,
81
+ message: data.commit.message,
82
+ },
83
+ },
84
+ };
85
+ }
86
+ };
87
+ exports.GitHubCreateOrUpdateFileTool = GitHubCreateOrUpdateFileTool;
88
+ __decorate([
89
+ (0, common_1.Inject)(),
90
+ __metadata("design:type", oauth_module_1.OAuthTokenStore)
91
+ ], GitHubCreateOrUpdateFileTool.prototype, "tokenStore", void 0);
92
+ __decorate([
93
+ (0, common_2.Input)({
94
+ schema: zod_1.z
95
+ .object({
96
+ owner: zod_1.z.string(),
97
+ repo: zod_1.z.string(),
98
+ path: zod_1.z.string(),
99
+ content: zod_1.z.string(),
100
+ message: zod_1.z.string(),
101
+ sha: zod_1.z.string().optional(),
102
+ branch: zod_1.z.string().optional(),
103
+ })
104
+ .strict(),
105
+ }),
106
+ __metadata("design:type", Object)
107
+ ], GitHubCreateOrUpdateFileTool.prototype, "args", void 0);
108
+ exports.GitHubCreateOrUpdateFileTool = GitHubCreateOrUpdateFileTool = GitHubCreateOrUpdateFileTool_1 = __decorate([
109
+ (0, common_2.Tool)({
110
+ config: {
111
+ description: 'Creates or updates a file in a GitHub repository. Content is provided as plain text and encoded to base64 before sending. To update an existing file, provide the sha of the file being replaced. Returns { error: "unauthorized" } if no valid token is available.',
112
+ },
113
+ })
114
+ ], GitHubCreateOrUpdateFileTool);
115
+ //# sourceMappingURL=github-create-or-update-file.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-create-or-update-file.tool.js","sourceRoot":"","sources":["../../../src/tools/content/github-create-or-update-file.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAgD;AAChD,6BAAwB;AACxB,8CAAuF;AACvF,0DAA0D;AAkBnD,IAAM,4BAA4B,oCAAlC,MAAM,4BAA4B;IACtB,MAAM,GAAG,IAAI,eAAM,CAAC,8BAA4B,CAAC,IAAI,CAA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AAC,MAAM,EAAE;YACjB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;YACnB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;YACnB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YAC1B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAC9B,CAAC;aACD,MAAM,EAAE;KACZ,CAAC;;0DACiC;uCAnBxB,4BAA4B;IANxC,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EACT,qQAAqQ;SACxQ;KACF,CAAC;GACW,4BAA4B,CAsGxC"}
@@ -0,0 +1,13 @@
1
+ import { RunContext, ToolInterface, ToolResult } from '@loopstack/common';
2
+ export type GitHubGetCommitArgs = {
3
+ owner: string;
4
+ repo: string;
5
+ ref: string;
6
+ };
7
+ export declare class GitHubGetCommitTool implements ToolInterface {
8
+ private readonly logger;
9
+ private tokenStore;
10
+ args: GitHubGetCommitArgs;
11
+ execute(args: GitHubGetCommitArgs, ctx: RunContext): Promise<ToolResult>;
12
+ }
13
+ //# sourceMappingURL=github-get-commit.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-get-commit.tool.d.ts","sourceRoot":"","sources":["../../../src/tools/content/github-get-commit.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,UAAU,EAAQ,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,qBAMa,mBAAoB,YAAW,aAAa;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAG/D,OAAO,CAAC,UAAU,CAAkB;IAWpC,IAAI,EAAE,mBAAmB,CAAC;IAEpB,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAyF/E"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var GitHubGetCommitTool_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GitHubGetCommitTool = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const zod_1 = require("zod");
16
+ const common_2 = require("@loopstack/common");
17
+ const oauth_module_1 = require("@loopstack/oauth-module");
18
+ let GitHubGetCommitTool = GitHubGetCommitTool_1 = class GitHubGetCommitTool {
19
+ logger = new common_1.Logger(GitHubGetCommitTool_1.name);
20
+ tokenStore;
21
+ args;
22
+ async execute(args, ctx) {
23
+ const accessToken = await this.tokenStore.getValidAccessToken(ctx.userId, 'github');
24
+ if (!accessToken) {
25
+ return {
26
+ data: {
27
+ error: 'unauthorized',
28
+ message: 'No valid GitHub token found. Please authenticate first.',
29
+ },
30
+ };
31
+ }
32
+ const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/commits/${encodeURIComponent(args.ref)}`;
33
+ const response = await fetch(url, {
34
+ headers: {
35
+ Authorization: `Bearer ${accessToken}`,
36
+ Accept: 'application/vnd.github+json',
37
+ 'X-GitHub-Api-Version': '2022-11-28',
38
+ },
39
+ });
40
+ if (response.status === 401 || response.status === 403) {
41
+ this.logger.warn(`GitHub API returned ${response.status} for user ${ctx.userId}`);
42
+ return {
43
+ data: {
44
+ error: '401',
45
+ message: 'GitHub token was rejected. Please re-authenticate.',
46
+ },
47
+ };
48
+ }
49
+ if (!response.ok) {
50
+ const body = await response.text();
51
+ this.logger.error(`GitHub API error: ${response.status} ${body}`);
52
+ return {
53
+ data: {
54
+ error: 'api_error',
55
+ message: `GitHub API error: ${response.statusText}`,
56
+ },
57
+ };
58
+ }
59
+ const data = (await response.json());
60
+ return {
61
+ data: {
62
+ commit: {
63
+ sha: data.sha,
64
+ message: data.commit.message,
65
+ author: {
66
+ name: data.commit.author.name,
67
+ email: data.commit.author.email,
68
+ date: data.commit.author.date,
69
+ login: data.author?.login ?? null,
70
+ },
71
+ committer: {
72
+ name: data.commit.committer.name,
73
+ date: data.commit.committer.date,
74
+ },
75
+ htmlUrl: data.html_url,
76
+ stats: data.stats,
77
+ files: data.files.map((f) => ({
78
+ filename: f.filename,
79
+ status: f.status,
80
+ additions: f.additions,
81
+ deletions: f.deletions,
82
+ changes: f.changes,
83
+ })),
84
+ },
85
+ },
86
+ };
87
+ }
88
+ };
89
+ exports.GitHubGetCommitTool = GitHubGetCommitTool;
90
+ __decorate([
91
+ (0, common_1.Inject)(),
92
+ __metadata("design:type", oauth_module_1.OAuthTokenStore)
93
+ ], GitHubGetCommitTool.prototype, "tokenStore", void 0);
94
+ __decorate([
95
+ (0, common_2.Input)({
96
+ schema: zod_1.z
97
+ .object({
98
+ owner: zod_1.z.string(),
99
+ repo: zod_1.z.string(),
100
+ ref: zod_1.z.string(),
101
+ })
102
+ .strict(),
103
+ }),
104
+ __metadata("design:type", Object)
105
+ ], GitHubGetCommitTool.prototype, "args", void 0);
106
+ exports.GitHubGetCommitTool = GitHubGetCommitTool = GitHubGetCommitTool_1 = __decorate([
107
+ (0, common_2.Tool)({
108
+ config: {
109
+ description: 'Gets detailed information about a specific commit in a GitHub repository. Returns { error: "unauthorized" } if no valid token is available.',
110
+ },
111
+ })
112
+ ], GitHubGetCommitTool);
113
+ //# sourceMappingURL=github-get-commit.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-get-commit.tool.js","sourceRoot":"","sources":["../../../src/tools/content/github-get-commit.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAgD;AAChD,6BAAwB;AACxB,8CAAuF;AACvF,0DAA0D;AAcnD,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IACb,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAGvD,UAAU,CAAkB;IAWpC,IAAI,CAAsB;IAE1B,KAAK,CAAC,OAAO,CAAC,IAAyB,EAAE,GAAe;QACtD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO;gBACL,IAAI,EAAE;oBACJ,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yDAAyD;iBACnE;aACF,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAAG,gCAAgC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACtJ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;gBACtC,MAAM,EAAE,6BAA6B;gBACrC,sBAAsB,EAAE,YAAY;aACrC;SACF,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,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,OAAO,EAAE,IAAI,CAAC,QAAQ;oBACtB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;wBAC5B,QAAQ,EAAE,CAAC,CAAC,QAAQ;wBACpB,MAAM,EAAE,CAAC,CAAC,MAAM;wBAChB,SAAS,EAAE,CAAC,CAAC,SAAS;wBACtB,SAAS,EAAE,CAAC,CAAC,SAAS;wBACtB,OAAO,EAAE,CAAC,CAAC,OAAO;qBACnB,CAAC,CAAC;iBACJ;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA1GY,kDAAmB;AAItB;IADP,IAAA,eAAM,GAAE;8BACW,8BAAe;uDAAC;AAWpC;IATC,IAAA,cAAK,EAAC;QACL,MAAM,EAAE,OAAC;aACN,MAAM,CAAC;YACN,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;YACjB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;SAChB,CAAC;aACD,MAAM,EAAE;KACZ,CAAC;;iDACwB;8BAff,mBAAmB;IAN/B,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EACT,6IAA6I;SAChJ;KACF,CAAC;GACW,mBAAmB,CA0G/B"}
@@ -0,0 +1,14 @@
1
+ import { RunContext, ToolInterface, ToolResult } from '@loopstack/common';
2
+ export type GitHubGetFileContentArgs = {
3
+ owner: string;
4
+ repo: string;
5
+ path: string;
6
+ ref?: string;
7
+ };
8
+ export declare class GitHubGetFileContentTool implements ToolInterface {
9
+ private readonly logger;
10
+ private tokenStore;
11
+ args: GitHubGetFileContentArgs;
12
+ execute(args: GitHubGetFileContentArgs, ctx: RunContext): Promise<ToolResult>;
13
+ }
14
+ //# sourceMappingURL=github-get-file-content.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-get-file-content.tool.d.ts","sourceRoot":"","sources":["../../../src/tools/content/github-get-file-content.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,UAAU,EAAQ,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAMa,wBAAyB,YAAW,aAAa;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;IAGpE,OAAO,CAAC,UAAU,CAAkB;IAYpC,IAAI,EAAE,wBAAwB,CAAC;IAEzB,OAAO,CAAC,IAAI,EAAE,wBAAwB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CA2EpF"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var GitHubGetFileContentTool_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GitHubGetFileContentTool = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const zod_1 = require("zod");
16
+ const common_2 = require("@loopstack/common");
17
+ const oauth_module_1 = require("@loopstack/oauth-module");
18
+ let GitHubGetFileContentTool = GitHubGetFileContentTool_1 = class GitHubGetFileContentTool {
19
+ logger = new common_1.Logger(GitHubGetFileContentTool_1.name);
20
+ tokenStore;
21
+ args;
22
+ async execute(args, ctx) {
23
+ const accessToken = await this.tokenStore.getValidAccessToken(ctx.userId, 'github');
24
+ if (!accessToken) {
25
+ return {
26
+ data: {
27
+ error: 'unauthorized',
28
+ message: 'No valid GitHub token found. Please authenticate first.',
29
+ },
30
+ };
31
+ }
32
+ const params = new URLSearchParams();
33
+ if (args.ref)
34
+ params.set('ref', args.ref);
35
+ const url = `https://api.github.com/repos/${encodeURIComponent(args.owner)}/${encodeURIComponent(args.repo)}/contents/${args.path}${params.toString() ? `?${params.toString()}` : ''}`;
36
+ const response = await fetch(url, {
37
+ headers: {
38
+ Authorization: `Bearer ${accessToken}`,
39
+ Accept: 'application/vnd.github+json',
40
+ 'X-GitHub-Api-Version': '2022-11-28',
41
+ },
42
+ });
43
+ if (response.status === 401 || response.status === 403) {
44
+ this.logger.warn(`GitHub API returned ${response.status} for user ${ctx.userId}`);
45
+ return {
46
+ data: {
47
+ error: '401',
48
+ message: 'GitHub token was rejected. Please re-authenticate.',
49
+ },
50
+ };
51
+ }
52
+ if (!response.ok) {
53
+ const body = await response.text();
54
+ this.logger.error(`GitHub API error: ${response.status} ${body}`);
55
+ return {
56
+ data: {
57
+ error: 'api_error',
58
+ message: `GitHub API error: ${response.statusText}`,
59
+ },
60
+ };
61
+ }
62
+ const data = (await response.json());
63
+ let content = null;
64
+ if (data.content && data.encoding === 'base64') {
65
+ content = Buffer.from(data.content, 'base64').toString('utf-8');
66
+ }
67
+ return {
68
+ data: {
69
+ file: {
70
+ name: data.name,
71
+ path: data.path,
72
+ sha: data.sha,
73
+ size: data.size,
74
+ type: data.type,
75
+ content,
76
+ htmlUrl: data.html_url,
77
+ },
78
+ },
79
+ };
80
+ }
81
+ };
82
+ exports.GitHubGetFileContentTool = GitHubGetFileContentTool;
83
+ __decorate([
84
+ (0, common_1.Inject)(),
85
+ __metadata("design:type", oauth_module_1.OAuthTokenStore)
86
+ ], GitHubGetFileContentTool.prototype, "tokenStore", void 0);
87
+ __decorate([
88
+ (0, common_2.Input)({
89
+ schema: zod_1.z
90
+ .object({
91
+ owner: zod_1.z.string(),
92
+ repo: zod_1.z.string(),
93
+ path: zod_1.z.string(),
94
+ ref: zod_1.z.string().optional(),
95
+ })
96
+ .strict(),
97
+ }),
98
+ __metadata("design:type", Object)
99
+ ], GitHubGetFileContentTool.prototype, "args", void 0);
100
+ exports.GitHubGetFileContentTool = GitHubGetFileContentTool = GitHubGetFileContentTool_1 = __decorate([
101
+ (0, common_2.Tool)({
102
+ config: {
103
+ description: 'Gets the content of a file from a GitHub repository. Decodes base64-encoded content from the API. Returns { error: "unauthorized" } if no valid token is available.',
104
+ },
105
+ })
106
+ ], GitHubGetFileContentTool);
107
+ //# sourceMappingURL=github-get-file-content.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-get-file-content.tool.js","sourceRoot":"","sources":["../../../src/tools/content/github-get-file-content.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAgD;AAChD,6BAAwB;AACxB,8CAAuF;AACvF,0DAA0D;AAenD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAClB,MAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAG5D,UAAU,CAAkB;IAYpC,IAAI,CAA2B;IAE/B,KAAK,CAAC,OAAO,CAAC,IAA8B,EAAE,GAAe;QAC3D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO;gBACL,IAAI,EAAE;oBACJ,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yDAAyD;iBACnE;aACF,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,eAAe,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3
+ owner: string;
4
+ repo: string;
5
+ path?: string;
6
+ ref?: string;
7
+ };
8
+ export declare class GitHubListDirectoryTool implements ToolInterface {
9
+ private readonly logger;
10
+ private tokenStore;
11
+ args: GitHubListDirectoryArgs;
12
+ execute(args: GitHubListDirectoryArgs, ctx: RunContext): Promise<ToolResult>;
13
+ }
14
+ //# sourceMappingURL=github-list-directory.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-list-directory.tool.d.ts","sourceRoot":"","sources":["../../../src/tools/content/github-list-directory.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,UAAU,EAAQ,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGvF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAMa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IAGnE,OAAO,CAAC,UAAU,CAAkB;IAYpC,IAAI,EAAE,uBAAuB,CAAC;IAExB,OAAO,CAAC,IAAI,EAAE,uBAAuB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAoEnF"}