@agent-native/core 0.59.1 → 0.60.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 (188) hide show
  1. package/dist/a2a/index.d.ts +2 -0
  2. package/dist/a2a/index.d.ts.map +1 -1
  3. package/dist/a2a/index.js +1 -0
  4. package/dist/a2a/index.js.map +1 -1
  5. package/dist/a2a/invoke.d.ts +63 -0
  6. package/dist/a2a/invoke.d.ts.map +1 -0
  7. package/dist/a2a/invoke.js +157 -0
  8. package/dist/a2a/invoke.js.map +1 -0
  9. package/dist/agent/run-store.d.ts +15 -0
  10. package/dist/agent/run-store.d.ts.map +1 -1
  11. package/dist/agent/run-store.js +28 -0
  12. package/dist/agent/run-store.js.map +1 -1
  13. package/dist/chat-threads/store.d.ts +21 -0
  14. package/dist/chat-threads/store.d.ts.map +1 -1
  15. package/dist/chat-threads/store.js +128 -0
  16. package/dist/chat-threads/store.js.map +1 -1
  17. package/dist/cli/agent.d.ts +23 -0
  18. package/dist/cli/agent.d.ts.map +1 -0
  19. package/dist/cli/agent.js +300 -0
  20. package/dist/cli/agent.js.map +1 -0
  21. package/dist/cli/agents.d.ts +14 -0
  22. package/dist/cli/agents.d.ts.map +1 -0
  23. package/dist/cli/agents.js +95 -0
  24. package/dist/cli/agents.js.map +1 -0
  25. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  26. package/dist/cli/code-agent-executor.js +264 -2
  27. package/dist/cli/code-agent-executor.js.map +1 -1
  28. package/dist/cli/create.d.ts +3 -2
  29. package/dist/cli/create.d.ts.map +1 -1
  30. package/dist/cli/create.js +154 -83
  31. package/dist/cli/create.js.map +1 -1
  32. package/dist/cli/index.js +50 -2
  33. package/dist/cli/index.js.map +1 -1
  34. package/dist/cli/invoke.d.ts +26 -0
  35. package/dist/cli/invoke.d.ts.map +1 -0
  36. package/dist/cli/invoke.js +227 -0
  37. package/dist/cli/invoke.js.map +1 -0
  38. package/dist/cli/templates-meta.d.ts +1 -1
  39. package/dist/cli/templates-meta.d.ts.map +1 -1
  40. package/dist/cli/templates-meta.js +9 -8
  41. package/dist/cli/templates-meta.js.map +1 -1
  42. package/dist/cli/workspacify.d.ts +1 -1
  43. package/dist/cli/workspacify.d.ts.map +1 -1
  44. package/dist/cli/workspacify.js +6 -6
  45. package/dist/cli/workspacify.js.map +1 -1
  46. package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
  47. package/dist/client/NewWorkspaceAppFlow.js +5 -4
  48. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  49. package/dist/client/blocks/library/diagram.d.ts.map +1 -1
  50. package/dist/client/blocks/library/diagram.js +23 -17
  51. package/dist/client/blocks/library/diagram.js.map +1 -1
  52. package/dist/client/blocks/types.d.ts +2 -0
  53. package/dist/client/blocks/types.d.ts.map +1 -1
  54. package/dist/client/blocks/types.js.map +1 -1
  55. package/dist/client/chat/index.d.ts +1 -1
  56. package/dist/client/chat/index.d.ts.map +1 -1
  57. package/dist/client/chat/index.js.map +1 -1
  58. package/dist/client/index.d.ts +1 -1
  59. package/dist/client/index.d.ts.map +1 -1
  60. package/dist/client/index.js.map +1 -1
  61. package/dist/client/use-chat-threads.d.ts +13 -0
  62. package/dist/client/use-chat-threads.d.ts.map +1 -1
  63. package/dist/client/use-chat-threads.js +41 -0
  64. package/dist/client/use-chat-threads.js.map +1 -1
  65. package/dist/integrations/plugin.d.ts.map +1 -1
  66. package/dist/integrations/plugin.js +2 -2
  67. package/dist/integrations/plugin.js.map +1 -1
  68. package/dist/onboarding/default-steps.d.ts.map +1 -1
  69. package/dist/onboarding/default-steps.js +102 -0
  70. package/dist/onboarding/default-steps.js.map +1 -1
  71. package/dist/provider-api/actions/github-repo-files.d.ts +84 -0
  72. package/dist/provider-api/actions/github-repo-files.d.ts.map +1 -0
  73. package/dist/provider-api/actions/github-repo-files.js +213 -0
  74. package/dist/provider-api/actions/github-repo-files.js.map +1 -0
  75. package/dist/provider-api/github-repo.d.ts +11 -0
  76. package/dist/provider-api/github-repo.d.ts.map +1 -0
  77. package/dist/provider-api/github-repo.js +553 -0
  78. package/dist/provider-api/github-repo.js.map +1 -0
  79. package/dist/provider-api/index.d.ts +184 -11
  80. package/dist/provider-api/index.d.ts.map +1 -1
  81. package/dist/provider-api/index.js +519 -0
  82. package/dist/provider-api/index.js.map +1 -1
  83. package/dist/scripts/docs/search.d.ts.map +1 -1
  84. package/dist/scripts/docs/search.js +38 -13
  85. package/dist/scripts/docs/search.js.map +1 -1
  86. package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
  87. package/dist/secrets/register-framework-secrets.js +11 -0
  88. package/dist/secrets/register-framework-secrets.js.map +1 -1
  89. package/dist/server/agent-chat-plugin.d.ts +32 -0
  90. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  91. package/dist/server/agent-chat-plugin.js +297 -2
  92. package/dist/server/agent-chat-plugin.js.map +1 -1
  93. package/dist/server/auth-marketing.d.ts.map +1 -1
  94. package/dist/server/auth-marketing.js +17 -7
  95. package/dist/server/auth-marketing.js.map +1 -1
  96. package/dist/server/auth.d.ts.map +1 -1
  97. package/dist/server/auth.js +6 -0
  98. package/dist/server/auth.js.map +1 -1
  99. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  100. package/dist/server/core-routes-plugin.js +18 -98
  101. package/dist/server/core-routes-plugin.js.map +1 -1
  102. package/dist/styles/blocks.css +30 -8
  103. package/dist/styles/rich-markdown-editor.css +10 -4
  104. package/dist/templates/{starter-shell-sync.spec.ts → chat-shell-sync.spec.ts} +21 -21
  105. package/dist/templates/default/.agents/skills/actions/SKILL.md +5 -5
  106. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +63 -0
  107. package/dist/templates/default/AGENTS.md +22 -1
  108. package/dist/templates/default/actions/hello.ts +1 -1
  109. package/dist/templates/default/actions/navigate.ts +1 -1
  110. package/dist/templates/default/actions/view-screen.ts +1 -1
  111. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +63 -0
  112. package/dist/templates/headless/.env.example +4 -0
  113. package/dist/templates/headless/.prettierrc +5 -0
  114. package/dist/templates/headless/AGENTS.md +58 -0
  115. package/dist/templates/headless/DEVELOPING.md +22 -0
  116. package/dist/templates/headless/_gitignore +36 -0
  117. package/dist/templates/headless/actions/hello.ts +14 -0
  118. package/dist/templates/headless/actions/run.ts +3 -0
  119. package/dist/templates/headless/package.json +22 -0
  120. package/dist/templates/headless/tsconfig.json +7 -0
  121. package/dist/templates/ui-primitives-sync.spec.ts +2 -2
  122. package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +5 -5
  123. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +63 -0
  124. package/dist/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +93 -0
  125. package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +1 -1
  126. package/dist/templates/workspace-core/AGENTS.md +20 -3
  127. package/dist/templates/workspace-core/src/server/index.ts +1 -1
  128. package/dist/templates/workspace-root/AGENTS.md +25 -5
  129. package/dist/templates/workspace-root/README.md +7 -7
  130. package/dist/triggers/dispatcher.d.ts +2 -3
  131. package/dist/triggers/dispatcher.d.ts.map +1 -1
  132. package/dist/triggers/dispatcher.js +2 -3
  133. package/dist/triggers/dispatcher.js.map +1 -1
  134. package/dist/triggers/routes.d.ts +38 -0
  135. package/dist/triggers/routes.d.ts.map +1 -0
  136. package/dist/triggers/routes.js +202 -0
  137. package/dist/triggers/routes.js.map +1 -0
  138. package/docs/AGENTS.md +57 -0
  139. package/docs/SKILL.md +40 -0
  140. package/docs/content/a2a-protocol.md +1 -1
  141. package/docs/content/actions.md +48 -8
  142. package/docs/content/agent-surfaces.md +76 -14
  143. package/docs/content/cli-adapters.md +1 -1
  144. package/docs/content/cloneable-saas.md +5 -4
  145. package/docs/content/code-agents-ui.md +1 -1
  146. package/docs/content/components.md +1 -1
  147. package/docs/content/context-awareness.md +1 -1
  148. package/docs/content/creating-templates.md +9 -7
  149. package/docs/content/drop-in-agent.md +1 -1
  150. package/docs/content/faq.md +6 -4
  151. package/docs/content/getting-started.md +63 -73
  152. package/docs/content/key-concepts.md +24 -24
  153. package/docs/content/native-chat-ui.md +4 -4
  154. package/docs/content/pure-agent-apps.md +34 -10
  155. package/docs/content/security.md +1 -1
  156. package/docs/content/server.md +1 -1
  157. package/docs/content/template-chat.md +85 -0
  158. package/docs/content/template-dispatch.md +1 -1
  159. package/docs/content/tracking.md +1 -1
  160. package/docs/content/what-is-agent-native.md +7 -6
  161. package/package.json +10 -1
  162. package/src/templates/{starter-shell-sync.spec.ts → chat-shell-sync.spec.ts} +21 -21
  163. package/src/templates/default/.agents/skills/actions/SKILL.md +5 -5
  164. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +63 -0
  165. package/src/templates/default/AGENTS.md +22 -1
  166. package/src/templates/default/actions/hello.ts +1 -1
  167. package/src/templates/default/actions/navigate.ts +1 -1
  168. package/src/templates/default/actions/view-screen.ts +1 -1
  169. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +63 -0
  170. package/src/templates/headless/.env.example +4 -0
  171. package/src/templates/headless/.prettierrc +5 -0
  172. package/src/templates/headless/AGENTS.md +58 -0
  173. package/src/templates/headless/DEVELOPING.md +22 -0
  174. package/src/templates/headless/_gitignore +36 -0
  175. package/src/templates/headless/actions/hello.ts +14 -0
  176. package/src/templates/headless/actions/run.ts +3 -0
  177. package/src/templates/headless/package.json +22 -0
  178. package/src/templates/headless/tsconfig.json +7 -0
  179. package/src/templates/ui-primitives-sync.spec.ts +2 -2
  180. package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +5 -5
  181. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +63 -0
  182. package/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +93 -0
  183. package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +1 -1
  184. package/src/templates/workspace-core/AGENTS.md +20 -3
  185. package/src/templates/workspace-core/src/server/index.ts +1 -1
  186. package/src/templates/workspace-root/AGENTS.md +25 -5
  187. package/src/templates/workspace-root/README.md +7 -7
  188. package/docs/content/template-starter.md +0 -78
@@ -0,0 +1,553 @@
1
+ import { canUseDeployCredentialFallbackForRequest, readDeployCredentialEnv, } from "../server/credential-provider.js";
2
+ import { getCredentialContext } from "../server/request-context.js";
3
+ import { createProviderApiRuntime, defaultProviderApiCredentialResolver, } from "./index.js";
4
+ const REPO_PART_RE = /^[A-Za-z0-9_.-]{1,100}$/;
5
+ function normalizePath(path, { allowEmpty = false } = {}) {
6
+ if (typeof path !== "string") {
7
+ if (allowEmpty)
8
+ return "";
9
+ throw new Error("path is required");
10
+ }
11
+ const trimmed = path.trim().replace(/^\/+/, "");
12
+ if (!trimmed) {
13
+ if (allowEmpty)
14
+ return "";
15
+ throw new Error("path is required");
16
+ }
17
+ const parts = trimmed.split("/");
18
+ if (parts.some((part) => !part || part === "." || part === "..")) {
19
+ throw new Error(`Invalid repository path "${path}"`);
20
+ }
21
+ return parts.join("/");
22
+ }
23
+ function encodePath(path) {
24
+ return path
25
+ .split("/")
26
+ .map((part) => encodeURIComponent(part))
27
+ .join("/");
28
+ }
29
+ function normalizeRepoPart(value, label) {
30
+ const normalized = value.trim();
31
+ if (!REPO_PART_RE.test(normalized)) {
32
+ throw new Error(`Invalid GitHub ${label} "${value}". Expected letters, numbers, dot, underscore, or hyphen.`);
33
+ }
34
+ return normalized;
35
+ }
36
+ function repoFromString(value) {
37
+ const [rawOwner, rawRepo, ...extra] = value.trim().split("/");
38
+ if (!rawOwner || !rawRepo || extra.length > 0) {
39
+ throw new Error(`Invalid GitHub repository "${value}". Expected "owner/repo".`);
40
+ }
41
+ const owner = normalizeRepoPart(rawOwner, "owner");
42
+ const repo = normalizeRepoPart(rawRepo, "repo");
43
+ return { owner, repo, repository: `${owner}/${repo}` };
44
+ }
45
+ async function resolveConfiguredRepository(options) {
46
+ const ctx = options.getCredentialContext?.() ?? getCredentialContext();
47
+ if (ctx?.userEmail) {
48
+ try {
49
+ const { resolveCredential } = await import("../credentials/index.js");
50
+ const configured = await resolveCredential("GITHUB_REPOSITORY", ctx);
51
+ if (configured)
52
+ return configured;
53
+ }
54
+ catch {
55
+ // Fall through to scoped secrets and single-tenant deploy/local env.
56
+ }
57
+ try {
58
+ const configured = await resolveScopedSecret("GITHUB_REPOSITORY", ctx);
59
+ if (configured)
60
+ return configured;
61
+ }
62
+ catch {
63
+ // Fall through to the authenticated missing-repository error below.
64
+ }
65
+ return undefined;
66
+ }
67
+ return readDeployCredentialEnv("GITHUB_REPOSITORY");
68
+ }
69
+ async function resolveScopedSecret(key, ctx) {
70
+ const { readAppSecret } = await import("../secrets/storage.js");
71
+ const refs = [{ scope: "user", scopeId: ctx.userEmail }];
72
+ if (ctx.orgId) {
73
+ refs.push({ scope: "org", scopeId: ctx.orgId }, { scope: "workspace", scopeId: ctx.orgId });
74
+ }
75
+ else {
76
+ refs.push({ scope: "workspace", scopeId: `solo:${ctx.userEmail}` });
77
+ }
78
+ for (const ref of refs) {
79
+ const secret = await readAppSecret({
80
+ key,
81
+ scope: ref.scope,
82
+ scopeId: ref.scopeId,
83
+ });
84
+ if (secret?.value)
85
+ return secret.value;
86
+ }
87
+ return undefined;
88
+ }
89
+ async function resolveRepo(args, options) {
90
+ const repository = typeof args.repository === "string" && args.repository.trim()
91
+ ? args.repository.trim()
92
+ : typeof args.owner === "string" &&
93
+ args.owner.trim() &&
94
+ typeof args.repo === "string" &&
95
+ args.repo.trim()
96
+ ? `${args.owner.trim()}/${args.repo.trim()}`
97
+ : await resolveConfiguredRepository(options);
98
+ if (!repository) {
99
+ throw new Error('GitHub repository is required. Pass repository="owner/repo" or configure GITHUB_REPOSITORY in setup.');
100
+ }
101
+ return repoFromString(repository);
102
+ }
103
+ function createRuntime(options) {
104
+ const resolver = async (lookup) => {
105
+ const custom = await options.resolveCredential?.(lookup);
106
+ if (custom?.value)
107
+ return custom;
108
+ const configured = await defaultProviderApiCredentialResolver(lookup);
109
+ if (configured?.value)
110
+ return configured;
111
+ const scopedSecret = await resolveScopedSecret(lookup.key, lookup.ctx);
112
+ if (scopedSecret) {
113
+ return {
114
+ key: lookup.key,
115
+ value: scopedSecret,
116
+ source: "app_secret",
117
+ provider: lookup.provider,
118
+ };
119
+ }
120
+ if (canUseDeployCredentialFallbackForRequest()) {
121
+ const value = readDeployCredentialEnv(lookup.key) ??
122
+ (lookup.key === "GITHUB_TOKEN"
123
+ ? readDeployCredentialEnv("GH_TOKEN")
124
+ : undefined);
125
+ if (value) {
126
+ return {
127
+ key: lookup.key,
128
+ value,
129
+ source: "deploy_env",
130
+ provider: lookup.provider,
131
+ scope: "deploy",
132
+ };
133
+ }
134
+ }
135
+ return null;
136
+ };
137
+ return createProviderApiRuntime({
138
+ appId: options.appId ?? "app",
139
+ providerIds: ["github"],
140
+ localCredentialSource: "github_repo",
141
+ getCredentialContext: options.getCredentialContext ?? getCredentialContext,
142
+ resolveCredential: resolver,
143
+ });
144
+ }
145
+ async function githubRequest(runtime, args) {
146
+ const result = (await runtime.executeRequest({
147
+ provider: "github",
148
+ ...args,
149
+ }));
150
+ return result;
151
+ }
152
+ function responseStatus(result) {
153
+ return Number(result.response?.status ?? 0);
154
+ }
155
+ function responseJson(result) {
156
+ return result.response?.json;
157
+ }
158
+ function assertOk(result, action) {
159
+ const status = responseStatus(result);
160
+ if (status >= 200 && status < 300)
161
+ return;
162
+ const payload = responseJson(result);
163
+ const message = payload && typeof payload === "object" && "message" in payload
164
+ ? String(payload.message)
165
+ : (result.response?.text ?? result.response?.statusText ?? "failed");
166
+ throw new Error(`GitHub ${action} failed (${status || "unknown"}): ${message}`);
167
+ }
168
+ function decodeGitHubContent(value) {
169
+ if (typeof value !== "string")
170
+ return "";
171
+ return Buffer.from(value.replace(/\s/g, ""), "base64").toString("utf8");
172
+ }
173
+ function entryResponse(value) {
174
+ return value;
175
+ }
176
+ async function readFileImpl(args, options) {
177
+ const repo = await resolveRepo(args, options);
178
+ const path = normalizePath(args.path);
179
+ const ref = typeof args.ref === "string" && args.ref.trim()
180
+ ? args.ref.trim()
181
+ : typeof args.branch === "string" && args.branch.trim()
182
+ ? args.branch.trim()
183
+ : undefined;
184
+ const runtime = createRuntime(options);
185
+ const result = await githubRequest(runtime, {
186
+ method: "GET",
187
+ path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,
188
+ query: ref ? { ref } : undefined,
189
+ });
190
+ assertOk(result, "read file");
191
+ const json = responseJson(result);
192
+ if (Array.isArray(json) || json.type !== "file") {
193
+ throw new Error(`GitHub path "${path}" is not a file.`);
194
+ }
195
+ return entryResponse({
196
+ repository: repo.repository,
197
+ path,
198
+ ref,
199
+ sha: typeof json.sha === "string" ? json.sha : undefined,
200
+ size: typeof json.size === "number" ? json.size : undefined,
201
+ encoding: json.encoding,
202
+ content: decodeGitHubContent(json.content),
203
+ htmlUrl: json.html_url,
204
+ downloadUrl: json.download_url,
205
+ });
206
+ }
207
+ async function getExistingFileSha(runtime, repo, path, ref) {
208
+ const result = await githubRequest(runtime, {
209
+ method: "GET",
210
+ path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,
211
+ query: ref ? { ref } : undefined,
212
+ });
213
+ const status = responseStatus(result);
214
+ if (status === 404)
215
+ return undefined;
216
+ assertOk(result, "load file sha");
217
+ const json = responseJson(result);
218
+ return typeof json.sha === "string" ? json.sha : undefined;
219
+ }
220
+ async function writeFileImpl(args, options) {
221
+ const repo = await resolveRepo(args, options);
222
+ const path = normalizePath(args.path);
223
+ const content = typeof args.content === "string"
224
+ ? args.content
225
+ : String(args.content ?? "");
226
+ const message = typeof args.message === "string" && args.message.trim()
227
+ ? args.message.trim()
228
+ : `Update ${path}`;
229
+ const branch = typeof args.branch === "string" && args.branch.trim()
230
+ ? args.branch.trim()
231
+ : undefined;
232
+ const runtime = createRuntime(options);
233
+ const explicitSha = typeof args.sha === "string" && args.sha.trim() ? args.sha.trim() : "";
234
+ const sha = explicitSha ||
235
+ (await getExistingFileSha(runtime, repo, path, branch).catch((error) => {
236
+ if (error instanceof Error &&
237
+ /GitHub load file sha failed \(404\)/.test(error.message)) {
238
+ return undefined;
239
+ }
240
+ throw error;
241
+ }));
242
+ if (args.overwrite === false && sha) {
243
+ throw new Error(`GitHub file "${path}" already exists. Pass overwrite=true or provide a different path.`);
244
+ }
245
+ const result = await githubRequest(runtime, {
246
+ method: "PUT",
247
+ path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,
248
+ body: {
249
+ message,
250
+ content: Buffer.from(content, "utf8").toString("base64"),
251
+ ...(branch ? { branch } : {}),
252
+ ...(sha ? { sha } : {}),
253
+ },
254
+ });
255
+ assertOk(result, "write file");
256
+ const json = responseJson(result);
257
+ const commit = json.commit;
258
+ const file = json.content;
259
+ return entryResponse({
260
+ repository: repo.repository,
261
+ path,
262
+ branch,
263
+ sha: file?.sha,
264
+ commitSha: commit?.sha,
265
+ htmlUrl: file?.html_url,
266
+ });
267
+ }
268
+ async function deleteFileImpl(args, options) {
269
+ const repo = await resolveRepo(args, options);
270
+ const path = normalizePath(args.path);
271
+ const message = typeof args.message === "string" && args.message.trim()
272
+ ? args.message.trim()
273
+ : `Delete ${path}`;
274
+ const branch = typeof args.branch === "string" && args.branch.trim()
275
+ ? args.branch.trim()
276
+ : undefined;
277
+ const runtime = createRuntime(options);
278
+ const sha = typeof args.sha === "string" && args.sha.trim()
279
+ ? args.sha.trim()
280
+ : await getExistingFileSha(runtime, repo, path, branch);
281
+ if (!sha)
282
+ throw new Error(`GitHub file "${path}" does not exist.`);
283
+ const result = await githubRequest(runtime, {
284
+ method: "DELETE",
285
+ path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,
286
+ body: {
287
+ message,
288
+ sha,
289
+ ...(branch ? { branch } : {}),
290
+ },
291
+ });
292
+ assertOk(result, "delete file");
293
+ const json = responseJson(result);
294
+ const commit = json.commit;
295
+ return entryResponse({
296
+ repository: repo.repository,
297
+ path,
298
+ branch,
299
+ deleted: true,
300
+ commitSha: commit?.sha,
301
+ });
302
+ }
303
+ async function listFilesImpl(args, options) {
304
+ const repo = await resolveRepo(args, options);
305
+ const path = normalizePath(args.path, { allowEmpty: true });
306
+ const ref = typeof args.ref === "string" && args.ref.trim()
307
+ ? args.ref.trim()
308
+ : typeof args.branch === "string" && args.branch.trim()
309
+ ? args.branch.trim()
310
+ : undefined;
311
+ const runtime = createRuntime(options);
312
+ const result = await githubRequest(runtime, {
313
+ method: "GET",
314
+ path: `/repos/${repo.owner}/${repo.repo}/contents${path ? `/${encodePath(path)}` : ""}`,
315
+ query: ref ? { ref } : undefined,
316
+ });
317
+ assertOk(result, "list files");
318
+ const json = responseJson(result);
319
+ const entries = (Array.isArray(json) ? json : [json])
320
+ .filter((item) => !!item)
321
+ .map((item) => ({
322
+ name: item.name,
323
+ path: item.path,
324
+ type: item.type,
325
+ sha: item.sha,
326
+ size: item.size,
327
+ htmlUrl: item.html_url,
328
+ }));
329
+ return entryResponse({
330
+ repository: repo.repository,
331
+ path,
332
+ ref,
333
+ entries,
334
+ total: entries.length,
335
+ });
336
+ }
337
+ async function searchCodeImpl(args, options) {
338
+ const repo = await resolveRepo(args, options);
339
+ const query = typeof args.query === "string" && args.query.trim()
340
+ ? args.query.trim()
341
+ : "";
342
+ if (!query)
343
+ throw new Error("query is required");
344
+ const path = typeof args.path === "string" && args.path.trim()
345
+ ? normalizePath(args.path)
346
+ : "";
347
+ const extension = typeof args.extension === "string" && args.extension.trim()
348
+ ? args.extension.trim().replace(/^\./, "")
349
+ : "";
350
+ const q = [
351
+ query,
352
+ `repo:${repo.repository}`,
353
+ path ? `path:${path}` : "",
354
+ extension ? `extension:${extension}` : "",
355
+ ]
356
+ .filter(Boolean)
357
+ .join(" ");
358
+ const runtime = createRuntime(options);
359
+ const result = await githubRequest(runtime, {
360
+ method: "GET",
361
+ path: "/search/code",
362
+ query: {
363
+ q,
364
+ per_page: typeof args.limit === "number"
365
+ ? Math.max(1, Math.min(100, Math.floor(args.limit)))
366
+ : 20,
367
+ },
368
+ });
369
+ assertOk(result, "search code");
370
+ const json = responseJson(result);
371
+ const items = Array.isArray(json.items) ? json.items : [];
372
+ return entryResponse({
373
+ repository: repo.repository,
374
+ query,
375
+ path,
376
+ extension,
377
+ totalCount: json.total_count,
378
+ incompleteResults: json.incomplete_results,
379
+ items: items.map((item) => {
380
+ const row = item;
381
+ const repository = row.repository;
382
+ return {
383
+ name: row.name,
384
+ path: row.path,
385
+ sha: row.sha,
386
+ htmlUrl: row.html_url,
387
+ repository: repository?.full_name,
388
+ };
389
+ }),
390
+ });
391
+ }
392
+ const repoParams = {
393
+ repository: {
394
+ type: "string",
395
+ description: "Optional owner/repo. Defaults to configured GITHUB_REPOSITORY.",
396
+ },
397
+ owner: {
398
+ type: "string",
399
+ description: "Optional repository owner when repository is not provided.",
400
+ },
401
+ repo: {
402
+ type: "string",
403
+ description: "Optional repository name when repository is not provided.",
404
+ },
405
+ };
406
+ export function createGitHubRepoToolEntries(options = {}) {
407
+ return {
408
+ "github-repo-list-files": {
409
+ readOnly: true,
410
+ parallelSafe: true,
411
+ tool: {
412
+ description: "List files or directories in the connected GitHub repository through the GitHub connector/token. Use this for cloud/headless repo context without cloning.",
413
+ parameters: {
414
+ type: "object",
415
+ properties: {
416
+ ...repoParams,
417
+ path: {
418
+ type: "string",
419
+ description: "Directory or file path to list. Defaults to repo root.",
420
+ },
421
+ ref: {
422
+ type: "string",
423
+ description: "Optional branch, tag, or commit SHA.",
424
+ },
425
+ branch: {
426
+ type: "string",
427
+ description: "Optional branch name alias for ref.",
428
+ },
429
+ },
430
+ },
431
+ },
432
+ run: (args) => listFilesImpl(args ?? {}, options),
433
+ },
434
+ "github-repo-read-file": {
435
+ readOnly: true,
436
+ parallelSafe: true,
437
+ tool: {
438
+ description: "Read a UTF-8 text file from the connected GitHub repository through the GitHub connector/token. Returns content plus SHA for later writes.",
439
+ parameters: {
440
+ type: "object",
441
+ properties: {
442
+ ...repoParams,
443
+ path: { type: "string", description: "Repository file path." },
444
+ ref: {
445
+ type: "string",
446
+ description: "Optional branch, tag, or commit SHA.",
447
+ },
448
+ branch: {
449
+ type: "string",
450
+ description: "Optional branch name alias for ref.",
451
+ },
452
+ },
453
+ required: ["path"],
454
+ },
455
+ },
456
+ run: (args) => readFileImpl(args ?? {}, options),
457
+ },
458
+ "github-repo-search-code": {
459
+ readOnly: true,
460
+ parallelSafe: true,
461
+ tool: {
462
+ description: "Search code in the connected GitHub repository through the GitHub connector/token. Use before reading likely files.",
463
+ parameters: {
464
+ type: "object",
465
+ properties: {
466
+ ...repoParams,
467
+ query: {
468
+ type: "string",
469
+ description: "GitHub code-search query text.",
470
+ },
471
+ path: {
472
+ type: "string",
473
+ description: "Optional path qualifier.",
474
+ },
475
+ extension: {
476
+ type: "string",
477
+ description: "Optional file extension qualifier.",
478
+ },
479
+ limit: {
480
+ type: "number",
481
+ description: "Maximum results, 1-100. Default 20.",
482
+ },
483
+ },
484
+ required: ["query"],
485
+ },
486
+ },
487
+ run: (args) => searchCodeImpl(args ?? {}, options),
488
+ },
489
+ "github-repo-write-file": {
490
+ needsApproval: true,
491
+ tool: {
492
+ description: "Create or update a file in the connected GitHub repository through the GitHub connector/token. Auto-loads the current SHA when updating an existing file.",
493
+ parameters: {
494
+ type: "object",
495
+ properties: {
496
+ ...repoParams,
497
+ path: { type: "string", description: "Repository file path." },
498
+ content: {
499
+ type: "string",
500
+ description: "New UTF-8 file content.",
501
+ },
502
+ message: {
503
+ type: "string",
504
+ description: "Commit message. Defaults to Update <path>.",
505
+ },
506
+ branch: {
507
+ type: "string",
508
+ description: "Optional branch to write to.",
509
+ },
510
+ sha: {
511
+ type: "string",
512
+ description: "Optional current file SHA. If omitted, the tool reads it first.",
513
+ },
514
+ overwrite: {
515
+ type: "boolean",
516
+ description: "Set false to fail instead of updating an existing file.",
517
+ },
518
+ },
519
+ required: ["path", "content"],
520
+ },
521
+ },
522
+ run: (args) => writeFileImpl(args ?? {}, options),
523
+ },
524
+ "github-repo-delete-file": {
525
+ needsApproval: true,
526
+ tool: {
527
+ description: "Delete a file from the connected GitHub repository through the GitHub connector/token. Auto-loads the current SHA when omitted.",
528
+ parameters: {
529
+ type: "object",
530
+ properties: {
531
+ ...repoParams,
532
+ path: { type: "string", description: "Repository file path." },
533
+ message: {
534
+ type: "string",
535
+ description: "Commit message. Defaults to Delete <path>.",
536
+ },
537
+ branch: {
538
+ type: "string",
539
+ description: "Optional branch to write to.",
540
+ },
541
+ sha: {
542
+ type: "string",
543
+ description: "Optional current file SHA. If omitted, the tool reads it first.",
544
+ },
545
+ },
546
+ required: ["path"],
547
+ },
548
+ },
549
+ run: (args) => deleteFileImpl(args ?? {}, options),
550
+ },
551
+ };
552
+ }
553
+ //# sourceMappingURL=github-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-repo.js","sourceRoot":"","sources":["../../src/provider-api/github-repo.ts"],"names":[],"mappings":"AACA,OAAO,EACL,wCAAwC,EACxC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EACL,wBAAwB,EACxB,oCAAoC,GAGrC,MAAM,YAAY,CAAC;AAwBpB,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C,SAAS,aAAa,CAAC,IAAa,EAAE,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,EAAE;IAC/D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,UAAU;YAAE,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,UAAU;YAAE,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CA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AAE,CAAC,MAAM,EAAE,SAAS,CAAC;iBAC9B;aACF;YACD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC;SAClD;QACD,yBAAyB,EAAE;YACzB,aAAa,EAAE,IAAI;YACnB,IAAI,EAAE;gBACJ,WAAW,EACT,iIAAiI;gBACnI,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,GAAG,UAAU;wBACb,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE;wBAC9D,OAAO,EAAE;4BACP,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,4CAA4C;yBAC1D;wBACD,MAAM,EAAE;4BACN,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,8BAA8B;yBAC5C;wBACD,GAAG,EAAE;4BACH,IAAI,EAAE,QAAQ;4BACd,WAAW,EACT,iEAAiE;yBACpE;qBACF;oBACD,QAAQ,EAAE,CAAC,MAAM,CAAC;iBACnB;aACF;YACD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC;SACnD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ActionEntry } from \"../agent/production-agent.js\";\nimport {\n canUseDeployCredentialFallbackForRequest,\n readDeployCredentialEnv,\n} from \"../server/credential-provider.js\";\nimport type { CredentialContext } from \"../credentials/index.js\";\nimport { getCredentialContext } from \"../server/request-context.js\";\nimport {\n createProviderApiRuntime,\n defaultProviderApiCredentialResolver,\n type ProviderApiCredentialResolver,\n type ProviderApiRequestArgs,\n} from \"./index.js\";\n\ninterface GitHubRepoToolOptions {\n appId?: string;\n getCredentialContext?: () => CredentialContext | null;\n resolveCredential?: ProviderApiCredentialResolver;\n}\n\ninterface ProviderApiResult {\n response?: {\n status?: number;\n statusText?: string;\n ok?: boolean;\n json?: unknown;\n text?: string;\n };\n}\n\ninterface ResolvedRepo {\n owner: string;\n repo: string;\n repository: string;\n}\n\nconst REPO_PART_RE = /^[A-Za-z0-9_.-]{1,100}$/;\n\nfunction normalizePath(path: unknown, { allowEmpty = false } = {}): string {\n if (typeof path !== \"string\") {\n if (allowEmpty) return \"\";\n throw new Error(\"path is required\");\n }\n const trimmed = path.trim().replace(/^\\/+/, \"\");\n if (!trimmed) {\n if (allowEmpty) return \"\";\n throw new Error(\"path is required\");\n }\n const parts = trimmed.split(\"/\");\n if (parts.some((part) => !part || part === \".\" || part === \"..\")) {\n throw new Error(`Invalid repository path \"${path}\"`);\n }\n return parts.join(\"/\");\n}\n\nfunction encodePath(path: string): string {\n return path\n .split(\"/\")\n .map((part) => encodeURIComponent(part))\n .join(\"/\");\n}\n\nfunction normalizeRepoPart(value: string, label: string): string {\n const normalized = value.trim();\n if (!REPO_PART_RE.test(normalized)) {\n throw new Error(\n `Invalid GitHub ${label} \"${value}\". Expected letters, numbers, dot, underscore, or hyphen.`,\n );\n }\n return normalized;\n}\n\nfunction repoFromString(value: string): ResolvedRepo {\n const [rawOwner, rawRepo, ...extra] = value.trim().split(\"/\");\n if (!rawOwner || !rawRepo || extra.length > 0) {\n throw new Error(\n `Invalid GitHub repository \"${value}\". Expected \"owner/repo\".`,\n );\n }\n const owner = normalizeRepoPart(rawOwner, \"owner\");\n const repo = normalizeRepoPart(rawRepo, \"repo\");\n return { owner, repo, repository: `${owner}/${repo}` };\n}\n\nasync function resolveConfiguredRepository(\n options: GitHubRepoToolOptions,\n): Promise<string | undefined> {\n const ctx = options.getCredentialContext?.() ?? getCredentialContext();\n if (ctx?.userEmail) {\n try {\n const { resolveCredential } = await import(\"../credentials/index.js\");\n const configured = await resolveCredential(\"GITHUB_REPOSITORY\", ctx);\n if (configured) return configured;\n } catch {\n // Fall through to scoped secrets and single-tenant deploy/local env.\n }\n try {\n const configured = await resolveScopedSecret(\"GITHUB_REPOSITORY\", ctx);\n if (configured) return configured;\n } catch {\n // Fall through to the authenticated missing-repository error below.\n }\n return undefined;\n }\n return readDeployCredentialEnv(\"GITHUB_REPOSITORY\");\n}\n\nasync function resolveScopedSecret(\n key: string,\n ctx: CredentialContext,\n): Promise<string | undefined> {\n const { readAppSecret } = await import(\"../secrets/storage.js\");\n const refs: Array<{\n scope: \"user\" | \"org\" | \"workspace\";\n scopeId: string;\n }> = [{ scope: \"user\", scopeId: ctx.userEmail }];\n if (ctx.orgId) {\n refs.push(\n { scope: \"org\", scopeId: ctx.orgId },\n { scope: \"workspace\", scopeId: ctx.orgId },\n );\n } else {\n refs.push({ scope: \"workspace\", scopeId: `solo:${ctx.userEmail}` });\n }\n for (const ref of refs) {\n const secret = await readAppSecret({\n key,\n scope: ref.scope,\n scopeId: ref.scopeId,\n });\n if (secret?.value) return secret.value;\n }\n return undefined;\n}\n\nasync function resolveRepo(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n): Promise<ResolvedRepo> {\n const repository =\n typeof args.repository === \"string\" && args.repository.trim()\n ? args.repository.trim()\n : typeof args.owner === \"string\" &&\n args.owner.trim() &&\n typeof args.repo === \"string\" &&\n args.repo.trim()\n ? `${args.owner.trim()}/${args.repo.trim()}`\n : await resolveConfiguredRepository(options);\n if (!repository) {\n throw new Error(\n 'GitHub repository is required. Pass repository=\"owner/repo\" or configure GITHUB_REPOSITORY in setup.',\n );\n }\n return repoFromString(repository);\n}\n\nfunction createRuntime(options: GitHubRepoToolOptions) {\n const resolver: ProviderApiCredentialResolver = async (lookup) => {\n const custom = await options.resolveCredential?.(lookup);\n if (custom?.value) return custom;\n\n const configured = await defaultProviderApiCredentialResolver(lookup);\n if (configured?.value) return configured;\n\n const scopedSecret = await resolveScopedSecret(lookup.key, lookup.ctx);\n if (scopedSecret) {\n return {\n key: lookup.key,\n value: scopedSecret,\n source: \"app_secret\",\n provider: lookup.provider,\n };\n }\n\n if (canUseDeployCredentialFallbackForRequest()) {\n const value =\n readDeployCredentialEnv(lookup.key) ??\n (lookup.key === \"GITHUB_TOKEN\"\n ? readDeployCredentialEnv(\"GH_TOKEN\")\n : undefined);\n if (value) {\n return {\n key: lookup.key,\n value,\n source: \"deploy_env\",\n provider: lookup.provider,\n scope: \"deploy\",\n };\n }\n }\n\n return null;\n };\n\n return createProviderApiRuntime({\n appId: options.appId ?? \"app\",\n providerIds: [\"github\"],\n localCredentialSource: \"github_repo\",\n getCredentialContext: options.getCredentialContext ?? getCredentialContext,\n resolveCredential: resolver,\n });\n}\n\nasync function githubRequest(\n runtime: ReturnType<typeof createProviderApiRuntime>,\n args: Omit<ProviderApiRequestArgs, \"provider\">,\n): Promise<ProviderApiResult> {\n const result = (await runtime.executeRequest({\n provider: \"github\",\n ...args,\n })) as ProviderApiResult;\n return result;\n}\n\nfunction responseStatus(result: ProviderApiResult): number {\n return Number(result.response?.status ?? 0);\n}\n\nfunction responseJson(result: ProviderApiResult): unknown {\n return result.response?.json;\n}\n\nfunction assertOk(result: ProviderApiResult, action: string): void {\n const status = responseStatus(result);\n if (status >= 200 && status < 300) return;\n const payload = responseJson(result);\n const message =\n payload && typeof payload === \"object\" && \"message\" in payload\n ? String((payload as { message?: unknown }).message)\n : (result.response?.text ?? result.response?.statusText ?? \"failed\");\n throw new Error(\n `GitHub ${action} failed (${status || \"unknown\"}): ${message}`,\n );\n}\n\nfunction decodeGitHubContent(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return Buffer.from(value.replace(/\\s/g, \"\"), \"base64\").toString(\"utf8\");\n}\n\nfunction entryResponse<T>(value: T): T {\n return value;\n}\n\nasync function readFileImpl(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n) {\n const repo = await resolveRepo(args, options);\n const path = normalizePath(args.path);\n const ref =\n typeof args.ref === \"string\" && args.ref.trim()\n ? args.ref.trim()\n : typeof args.branch === \"string\" && args.branch.trim()\n ? args.branch.trim()\n : undefined;\n const runtime = createRuntime(options);\n const result = await githubRequest(runtime, {\n method: \"GET\",\n path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,\n query: ref ? { ref } : undefined,\n });\n assertOk(result, \"read file\");\n const json = responseJson(result) as Record<string, unknown>;\n if (Array.isArray(json) || json.type !== \"file\") {\n throw new Error(`GitHub path \"${path}\" is not a file.`);\n }\n return entryResponse({\n repository: repo.repository,\n path,\n ref,\n sha: typeof json.sha === \"string\" ? json.sha : undefined,\n size: typeof json.size === \"number\" ? json.size : undefined,\n encoding: json.encoding,\n content: decodeGitHubContent(json.content),\n htmlUrl: json.html_url,\n downloadUrl: json.download_url,\n });\n}\n\nasync function getExistingFileSha(\n runtime: ReturnType<typeof createProviderApiRuntime>,\n repo: ResolvedRepo,\n path: string,\n ref?: string,\n): Promise<string | undefined> {\n const result = await githubRequest(runtime, {\n method: \"GET\",\n path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,\n query: ref ? { ref } : undefined,\n });\n const status = responseStatus(result);\n if (status === 404) return undefined;\n assertOk(result, \"load file sha\");\n const json = responseJson(result) as Record<string, unknown>;\n return typeof json.sha === \"string\" ? json.sha : undefined;\n}\n\nasync function writeFileImpl(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n) {\n const repo = await resolveRepo(args, options);\n const path = normalizePath(args.path);\n const content =\n typeof args.content === \"string\"\n ? args.content\n : String(args.content ?? \"\");\n const message =\n typeof args.message === \"string\" && args.message.trim()\n ? args.message.trim()\n : `Update ${path}`;\n const branch =\n typeof args.branch === \"string\" && args.branch.trim()\n ? args.branch.trim()\n : undefined;\n const runtime = createRuntime(options);\n const explicitSha =\n typeof args.sha === \"string\" && args.sha.trim() ? args.sha.trim() : \"\";\n const sha =\n explicitSha ||\n (await getExistingFileSha(runtime, repo, path, branch).catch((error) => {\n if (\n error instanceof Error &&\n /GitHub load file sha failed \\(404\\)/.test(error.message)\n ) {\n return undefined;\n }\n throw error;\n }));\n if (args.overwrite === false && sha) {\n throw new Error(\n `GitHub file \"${path}\" already exists. Pass overwrite=true or provide a different path.`,\n );\n }\n const result = await githubRequest(runtime, {\n method: \"PUT\",\n path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,\n body: {\n message,\n content: Buffer.from(content, \"utf8\").toString(\"base64\"),\n ...(branch ? { branch } : {}),\n ...(sha ? { sha } : {}),\n },\n });\n assertOk(result, \"write file\");\n const json = responseJson(result) as Record<string, unknown>;\n const commit = json.commit as Record<string, unknown> | undefined;\n const file = json.content as Record<string, unknown> | undefined;\n return entryResponse({\n repository: repo.repository,\n path,\n branch,\n sha: file?.sha,\n commitSha: commit?.sha,\n htmlUrl: file?.html_url,\n });\n}\n\nasync function deleteFileImpl(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n) {\n const repo = await resolveRepo(args, options);\n const path = normalizePath(args.path);\n const message =\n typeof args.message === \"string\" && args.message.trim()\n ? args.message.trim()\n : `Delete ${path}`;\n const branch =\n typeof args.branch === \"string\" && args.branch.trim()\n ? args.branch.trim()\n : undefined;\n const runtime = createRuntime(options);\n const sha =\n typeof args.sha === \"string\" && args.sha.trim()\n ? args.sha.trim()\n : await getExistingFileSha(runtime, repo, path, branch);\n if (!sha) throw new Error(`GitHub file \"${path}\" does not exist.`);\n const result = await githubRequest(runtime, {\n method: \"DELETE\",\n path: `/repos/${repo.owner}/${repo.repo}/contents/${encodePath(path)}`,\n body: {\n message,\n sha,\n ...(branch ? { branch } : {}),\n },\n });\n assertOk(result, \"delete file\");\n const json = responseJson(result) as Record<string, unknown>;\n const commit = json.commit as Record<string, unknown> | undefined;\n return entryResponse({\n repository: repo.repository,\n path,\n branch,\n deleted: true,\n commitSha: commit?.sha,\n });\n}\n\nasync function listFilesImpl(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n) {\n const repo = await resolveRepo(args, options);\n const path = normalizePath(args.path, { allowEmpty: true });\n const ref =\n typeof args.ref === \"string\" && args.ref.trim()\n ? args.ref.trim()\n : typeof args.branch === \"string\" && args.branch.trim()\n ? args.branch.trim()\n : undefined;\n const runtime = createRuntime(options);\n const result = await githubRequest(runtime, {\n method: \"GET\",\n path: `/repos/${repo.owner}/${repo.repo}/contents${path ? `/${encodePath(path)}` : \"\"}`,\n query: ref ? { ref } : undefined,\n });\n assertOk(result, \"list files\");\n const json = responseJson(result);\n const entries = (Array.isArray(json) ? json : [json])\n .filter((item): item is Record<string, unknown> => !!item)\n .map((item) => ({\n name: item.name,\n path: item.path,\n type: item.type,\n sha: item.sha,\n size: item.size,\n htmlUrl: item.html_url,\n }));\n return entryResponse({\n repository: repo.repository,\n path,\n ref,\n entries,\n total: entries.length,\n });\n}\n\nasync function searchCodeImpl(\n args: Record<string, unknown>,\n options: GitHubRepoToolOptions,\n) {\n const repo = await resolveRepo(args, options);\n const query =\n typeof args.query === \"string\" && args.query.trim()\n ? args.query.trim()\n : \"\";\n if (!query) throw new Error(\"query is required\");\n const path =\n typeof args.path === \"string\" && args.path.trim()\n ? normalizePath(args.path)\n : \"\";\n const extension =\n typeof args.extension === \"string\" && args.extension.trim()\n ? args.extension.trim().replace(/^\\./, \"\")\n : \"\";\n const q = [\n query,\n `repo:${repo.repository}`,\n path ? `path:${path}` : \"\",\n extension ? `extension:${extension}` : \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n const runtime = createRuntime(options);\n const result = await githubRequest(runtime, {\n method: \"GET\",\n path: \"/search/code\",\n query: {\n q,\n per_page:\n typeof args.limit === \"number\"\n ? Math.max(1, Math.min(100, Math.floor(args.limit)))\n : 20,\n },\n });\n assertOk(result, \"search code\");\n const json = responseJson(result) as Record<string, unknown>;\n const items = Array.isArray(json.items) ? json.items : [];\n return entryResponse({\n repository: repo.repository,\n query,\n path,\n extension,\n totalCount: json.total_count,\n incompleteResults: json.incomplete_results,\n items: items.map((item) => {\n const row = item as Record<string, unknown>;\n const repository = row.repository as Record<string, unknown> | undefined;\n return {\n name: row.name,\n path: row.path,\n sha: row.sha,\n htmlUrl: row.html_url,\n repository: repository?.full_name,\n };\n }),\n });\n}\n\nconst repoParams = {\n repository: {\n type: \"string\",\n description:\n \"Optional owner/repo. Defaults to configured GITHUB_REPOSITORY.\",\n },\n owner: {\n type: \"string\",\n description: \"Optional repository owner when repository is not provided.\",\n },\n repo: {\n type: \"string\",\n description: \"Optional repository name when repository is not provided.\",\n },\n} as const;\n\nexport function createGitHubRepoToolEntries(\n options: GitHubRepoToolOptions = {},\n): Record<string, ActionEntry> {\n return {\n \"github-repo-list-files\": {\n readOnly: true,\n parallelSafe: true,\n tool: {\n description:\n \"List files or directories in the connected GitHub repository through the GitHub connector/token. Use this for cloud/headless repo context without cloning.\",\n parameters: {\n type: \"object\",\n properties: {\n ...repoParams,\n path: {\n type: \"string\",\n description:\n \"Directory or file path to list. Defaults to repo root.\",\n },\n ref: {\n type: \"string\",\n description: \"Optional branch, tag, or commit SHA.\",\n },\n branch: {\n type: \"string\",\n description: \"Optional branch name alias for ref.\",\n },\n },\n },\n },\n run: (args) => listFilesImpl(args ?? {}, options),\n },\n \"github-repo-read-file\": {\n readOnly: true,\n parallelSafe: true,\n tool: {\n description:\n \"Read a UTF-8 text file from the connected GitHub repository through the GitHub connector/token. Returns content plus SHA for later writes.\",\n parameters: {\n type: \"object\",\n properties: {\n ...repoParams,\n path: { type: \"string\", description: \"Repository file path.\" },\n ref: {\n type: \"string\",\n description: \"Optional branch, tag, or commit SHA.\",\n },\n branch: {\n type: \"string\",\n description: \"Optional branch name alias for ref.\",\n },\n },\n required: [\"path\"],\n },\n },\n run: (args) => readFileImpl(args ?? {}, options),\n },\n \"github-repo-search-code\": {\n readOnly: true,\n parallelSafe: true,\n tool: {\n description:\n \"Search code in the connected GitHub repository through the GitHub connector/token. Use before reading likely files.\",\n parameters: {\n type: \"object\",\n properties: {\n ...repoParams,\n query: {\n type: \"string\",\n description: \"GitHub code-search query text.\",\n },\n path: {\n type: \"string\",\n description: \"Optional path qualifier.\",\n },\n extension: {\n type: \"string\",\n description: \"Optional file extension qualifier.\",\n },\n limit: {\n type: \"number\",\n description: \"Maximum results, 1-100. Default 20.\",\n },\n },\n required: [\"query\"],\n },\n },\n run: (args) => searchCodeImpl(args ?? {}, options),\n },\n \"github-repo-write-file\": {\n needsApproval: true,\n tool: {\n description:\n \"Create or update a file in the connected GitHub repository through the GitHub connector/token. Auto-loads the current SHA when updating an existing file.\",\n parameters: {\n type: \"object\",\n properties: {\n ...repoParams,\n path: { type: \"string\", description: \"Repository file path.\" },\n content: {\n type: \"string\",\n description: \"New UTF-8 file content.\",\n },\n message: {\n type: \"string\",\n description: \"Commit message. Defaults to Update <path>.\",\n },\n branch: {\n type: \"string\",\n description: \"Optional branch to write to.\",\n },\n sha: {\n type: \"string\",\n description:\n \"Optional current file SHA. If omitted, the tool reads it first.\",\n },\n overwrite: {\n type: \"boolean\",\n description:\n \"Set false to fail instead of updating an existing file.\",\n },\n },\n required: [\"path\", \"content\"],\n },\n },\n run: (args) => writeFileImpl(args ?? {}, options),\n },\n \"github-repo-delete-file\": {\n needsApproval: true,\n tool: {\n description:\n \"Delete a file from the connected GitHub repository through the GitHub connector/token. Auto-loads the current SHA when omitted.\",\n parameters: {\n type: \"object\",\n properties: {\n ...repoParams,\n path: { type: \"string\", description: \"Repository file path.\" },\n message: {\n type: \"string\",\n description: \"Commit message. Defaults to Delete <path>.\",\n },\n branch: {\n type: \"string\",\n description: \"Optional branch to write to.\",\n },\n sha: {\n type: \"string\",\n description:\n \"Optional current file SHA. If omitted, the tool reads it first.\",\n },\n },\n required: [\"path\"],\n },\n },\n run: (args) => deleteFileImpl(args ?? {}, options),\n },\n };\n}\n"]}