@agent-native/core 0.108.0 → 0.109.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.
- package/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +18 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/a2a/client.ts +140 -17
- package/corpus/core/src/a2a/handlers.ts +60 -0
- package/corpus/core/src/a2a/index.ts +6 -1
- package/corpus/core/src/a2a/invoke.ts +68 -1
- package/corpus/core/src/a2a/server.ts +13 -1
- package/corpus/core/src/a2a/types.ts +16 -0
- package/corpus/core/src/action.ts +3 -2
- package/corpus/core/src/agent/production-agent.ts +10 -4
- package/corpus/core/src/client/AssistantChat.tsx +648 -603
- package/corpus/core/src/client/MultiTabAssistantChat.tsx +31 -4
- package/corpus/core/src/client/agent-chat-adapter.ts +23 -37
- package/corpus/core/src/client/agent-sidebar-state.ts +4 -0
- package/corpus/core/src/client/analytics.ts +84 -0
- package/corpus/core/src/client/chat/message-components.tsx +94 -22
- package/corpus/core/src/client/chat/tool-call-display.tsx +170 -47
- package/corpus/core/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
- package/corpus/core/src/client/chat-thread-url.ts +11 -0
- package/corpus/core/src/client/error-capture.ts +12 -0
- package/corpus/core/src/client/extensions/ExtensionSlot.tsx +37 -1
- package/corpus/core/src/client/index.ts +2 -0
- package/corpus/core/src/client/route-chunk-recovery.ts +20 -8
- package/corpus/core/src/client/session-replay.ts +31 -0
- package/corpus/core/src/extensions/actions.ts +2 -14
- package/corpus/core/src/extensions/store.ts +1 -1
- package/corpus/core/src/localization/default-messages.ts +3 -0
- package/corpus/core/src/mcp/build-server.ts +2 -2
- package/corpus/core/src/progress/actions.ts +4 -2
- package/corpus/core/src/provider-api/index.ts +205 -105
- package/corpus/core/src/scripts/call-agent.ts +137 -17
- package/corpus/core/src/server/agent-chat/action-filters-a2a.ts +40 -0
- package/corpus/core/src/server/agent-chat-plugin.ts +31 -0
- package/corpus/core/src/styles/agent-conversation.css +7 -0
- package/corpus/core/src/templates/default/app/i18n/ar-SA.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/de-DE.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/en-US.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/es-ES.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/fr-FR.ts +21 -0
- package/corpus/core/src/templates/default/app/i18n/hi-IN.ts +19 -0
- package/corpus/core/src/templates/default/app/i18n/ja-JP.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/ko-KR.ts +19 -0
- package/corpus/core/src/templates/default/app/i18n/pt-BR.ts +20 -0
- package/corpus/core/src/templates/default/app/i18n/zh-CN.ts +19 -0
- package/corpus/core/src/templates/default/app/i18n/zh-TW.ts +19 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +28 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +5 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/performance/SKILL.md +13 -0
- package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +29 -10
- package/corpus/templates/analytics/.agents/skills/gong/SKILL.md +54 -23
- package/corpus/templates/analytics/.builder/skills/apollo/SKILL.md +19 -41
- package/corpus/templates/analytics/.builder/skills/commonroom/SKILL.md +20 -35
- package/corpus/templates/analytics/.builder/skills/github/SKILL.md +23 -67
- package/corpus/templates/analytics/.builder/skills/pylon/SKILL.md +25 -43
- package/corpus/templates/analytics/AGENTS.md +22 -13
- package/corpus/templates/analytics/actions/account-deep-dive.ts +1 -0
- package/corpus/templates/analytics/actions/configure-gong-native-insights.ts +29 -0
- package/corpus/templates/analytics/actions/content-calendar-schema.ts +8 -4
- package/corpus/templates/analytics/actions/content-calendar.ts +12 -4
- package/corpus/templates/analytics/actions/dashboard-mutation-api.ts +2 -1
- package/corpus/templates/analytics/actions/gong-calls.ts +113 -22
- package/corpus/templates/analytics/actions/gong-native-insights.ts +166 -0
- package/corpus/templates/analytics/actions/hubspot-deals.ts +190 -46
- package/corpus/templates/analytics/actions/pylon-issues.ts +123 -0
- package/corpus/templates/analytics/actions/slack-messages.ts +179 -27
- package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +48 -152
- package/corpus/templates/analytics/app/components/ui/chart.tsx +1 -1
- package/corpus/templates/analytics/app/hooks/use-chart-tooltip-flip.ts +21 -6
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +13 -0
- package/corpus/templates/analytics/app/i18n-data.ts +134 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/PanelEditorDialog.tsx +181 -30
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/SqlChartCard.tsx +6 -0
- package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +4 -3
- package/corpus/templates/analytics/changelog/2026-07-17-dashboard-editors-can-add-shared-extensions-or-opt-into-per-.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-dashboard-extensions-show-a-loading-skeleton.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-errors-now-group-repeat-failures-consistently-and-keep-priva.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-gong-transcript-reviews-now-batch-bounded-call-windows-for-f.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-hubspot-deal-filters-now-run-in-hubspot-before-paging-result.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-notion-content-calendars-now-discover-the-matching-database-.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-pylon-dashboard-reads-now-use-the-paginated-issue-search-api.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-17-slack-reads-no-longer-join-channels-and-report-pagination-coverage.md +6 -0
- package/corpus/templates/analytics/server/handlers/notion.ts +14 -3
- package/corpus/templates/analytics/server/handlers/slack.ts +182 -29
- package/corpus/templates/analytics/server/lib/agent-chat-plan-mode.ts +2 -6
- package/corpus/templates/analytics/server/lib/analytics-connector-catalog.ts +6 -2
- package/corpus/templates/analytics/server/lib/error-capture.ts +75 -8
- package/corpus/templates/analytics/server/lib/gong-native-policy.ts +72 -0
- package/corpus/templates/analytics/server/lib/gong.ts +54 -66
- package/corpus/templates/analytics/server/lib/hubspot.ts +40 -3
- package/corpus/templates/analytics/server/lib/notion.ts +83 -8
- package/corpus/templates/analytics/server/lib/real-data-actions.ts +4 -0
- package/corpus/templates/analytics/server/lib/slack.ts +242 -90
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +3 -3
- package/corpus/templates/analytics/server/routes/api/pylon/accounts.get.ts +42 -1
- package/corpus/templates/analytics/server/routes/api/pylon/issues.get.ts +71 -1
- package/corpus/templates/analytics/server/routes/api/test-connection.post.ts +44 -4
- package/corpus/templates/clips/app/components/library/bulk-action-toolbar.tsx +19 -1
- package/corpus/templates/clips/app/components/library/create-folder-dialog.tsx +123 -0
- package/corpus/templates/clips/app/components/library/library-grid.tsx +42 -4
- package/corpus/templates/clips/app/components/library/recording-card.tsx +30 -0
- package/corpus/templates/clips/app/entry.client.tsx +6 -1
- package/corpus/templates/clips/app/i18n/ar-SA.ts +12 -1
- package/corpus/templates/clips/app/i18n/de-DE.ts +12 -1
- package/corpus/templates/clips/app/i18n/en-US.ts +12 -1
- package/corpus/templates/clips/app/i18n/es-ES.ts +11 -1
- package/corpus/templates/clips/app/i18n/fr-FR.ts +11 -1
- package/corpus/templates/clips/app/i18n/hi-IN.ts +10 -1
- package/corpus/templates/clips/app/i18n/ja-JP.ts +12 -1
- package/corpus/templates/clips/app/i18n/ko-KR.ts +11 -1
- package/corpus/templates/clips/app/i18n/pt-BR.ts +11 -1
- package/corpus/templates/clips/app/i18n/zh-CN.ts +11 -1
- package/corpus/templates/clips/app/i18n/zh-TW.ts +11 -1
- package/corpus/templates/clips/app/routes/_app.settings._index.tsx +72 -1
- package/corpus/templates/clips/changelog/2026-07-17-choose-which-workspace-receives-new-clips-recordings-and-des.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-17-create-folders-directly-from-the-move-menu.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-17-failed-desktop-uploads-now-offer-a-direct-way-to-reopen-clip.md +6 -0
- package/corpus/templates/clips/desktop/src/app.tsx +1 -1
- package/corpus/templates/content/app/entry.client.tsx +6 -1
- package/corpus/templates/dispatch/AGENTS.md +5 -0
- package/corpus/templates/dispatch/changelog/2026-07-17-apps-page-links-to-other-available-apps.md +6 -0
- package/corpus/templates/dispatch/changelog/2026-07-17-curated-template-remixes.md +6 -0
- package/corpus/templates/mail/app/entry.client.tsx +6 -1
- package/corpus/templates/slides/.agents/skills/slide-images/SKILL.md +11 -7
- package/corpus/templates/slides/.env.example +0 -1
- package/corpus/templates/slides/AGENTS.md +4 -0
- package/corpus/templates/slides/DEVELOPING.md +2 -2
- package/corpus/templates/slides/actions/index-design-system-with-builder.ts +1 -1
- package/corpus/templates/slides/actions/logo-config.ts +6 -7
- package/corpus/templates/slides/actions/search-images.ts +11 -39
- package/corpus/templates/slides/actions/search-logos.ts +5 -52
- package/corpus/templates/slides/app/components/editor/ImageSearchPanel.tsx +1 -1
- package/corpus/templates/slides/app/components/editor/LogoSearchPanel.tsx +16 -26
- package/corpus/templates/slides/app/entry.client.tsx +6 -1
- package/corpus/templates/slides/server/lib/media-search-providers.ts +216 -0
- package/corpus/templates/slides/server/register-secrets.ts +30 -0
- package/dist/a2a/client.d.ts +38 -1
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +81 -12
- package/dist/a2a/client.js.map +1 -1
- package/dist/a2a/handlers.d.ts.map +1 -1
- package/dist/a2a/handlers.js +47 -0
- package/dist/a2a/handlers.js.map +1 -1
- package/dist/a2a/index.d.ts +4 -4
- package/dist/a2a/index.d.ts.map +1 -1
- package/dist/a2a/index.js +2 -2
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/invoke.d.ts +26 -2
- package/dist/a2a/invoke.d.ts.map +1 -1
- package/dist/a2a/invoke.js +30 -1
- package/dist/a2a/invoke.js.map +1 -1
- package/dist/a2a/server.d.ts.map +1 -1
- package/dist/a2a/server.js +14 -1
- package/dist/a2a/server.js.map +1 -1
- package/dist/a2a/types.d.ts +12 -0
- package/dist/a2a/types.d.ts.map +1 -1
- package/dist/a2a/types.js.map +1 -1
- package/dist/action.d.ts +3 -2
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js.map +1 -1
- package/dist/agent/production-agent.d.ts +5 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +5 -3
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/client/AssistantChat.d.ts +14 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +158 -136
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +27 -4
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +21 -39
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-sidebar-state.d.ts +1 -0
- package/dist/client/agent-sidebar-state.d.ts.map +1 -1
- package/dist/client/agent-sidebar-state.js +4 -0
- package/dist/client/agent-sidebar-state.js.map +1 -1
- package/dist/client/analytics.d.ts +14 -0
- package/dist/client/analytics.d.ts.map +1 -1
- package/dist/client/analytics.js +67 -0
- package/dist/client/analytics.js.map +1 -1
- package/dist/client/chat/message-components.d.ts +8 -0
- package/dist/client/chat/message-components.d.ts.map +1 -1
- package/dist/client/chat/message-components.js +62 -19
- package/dist/client/chat/message-components.js.map +1 -1
- package/dist/client/chat/tool-call-display.d.ts +6 -0
- package/dist/client/chat/tool-call-display.d.ts.map +1 -1
- package/dist/client/chat/tool-call-display.js +83 -14
- package/dist/client/chat/tool-call-display.js.map +1 -1
- package/dist/client/chat/use-agent-chat-lifecycle-tracking.d.ts +8 -0
- package/dist/client/chat/use-agent-chat-lifecycle-tracking.d.ts.map +1 -0
- package/dist/client/chat/use-agent-chat-lifecycle-tracking.js +51 -0
- package/dist/client/chat/use-agent-chat-lifecycle-tracking.js.map +1 -0
- package/dist/client/chat-thread-url.d.ts +2 -0
- package/dist/client/chat-thread-url.d.ts.map +1 -0
- package/dist/client/chat-thread-url.js +12 -0
- package/dist/client/chat-thread-url.js.map +1 -0
- package/dist/client/error-capture.d.ts.map +1 -1
- package/dist/client/error-capture.js +7 -0
- package/dist/client/error-capture.js.map +1 -1
- package/dist/client/extensions/ExtensionSlot.d.ts +3 -1
- package/dist/client/extensions/ExtensionSlot.d.ts.map +1 -1
- package/dist/client/extensions/ExtensionSlot.js +28 -3
- package/dist/client/extensions/ExtensionSlot.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/route-chunk-recovery.d.ts.map +1 -1
- package/dist/client/route-chunk-recovery.js +14 -9
- package/dist/client/route-chunk-recovery.js.map +1 -1
- package/dist/client/session-replay.d.ts +15 -0
- package/dist/client/session-replay.d.ts.map +1 -1
- package/dist/client/session-replay.js +20 -0
- package/dist/client/session-replay.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/extensions/actions.d.ts.map +1 -1
- package/dist/extensions/actions.js +2 -10
- package/dist/extensions/actions.js.map +1 -1
- package/dist/extensions/store.js +1 -1
- package/dist/extensions/store.js.map +1 -1
- package/dist/localization/default-messages.d.ts +3 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +3 -0
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/mcp/build-server.d.ts +2 -0
- package/dist/mcp/build-server.d.ts.map +1 -1
- package/dist/mcp/build-server.js +2 -2
- package/dist/mcp/build-server.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +1 -1
- package/dist/progress/actions.d.ts.map +1 -1
- package/dist/progress/actions.js +3 -2
- package/dist/progress/actions.js.map +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +91 -8
- package/dist/provider-api/index.js.map +1 -1
- package/dist/resources/handlers.d.ts +2 -2
- package/dist/scripts/call-agent.d.ts.map +1 -1
- package/dist/scripts/call-agent.js +107 -16
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/server/agent-chat/action-filters-a2a.d.ts +6 -0
- package/dist/server/agent-chat/action-filters-a2a.d.ts.map +1 -1
- package/dist/server/agent-chat/action-filters-a2a.js +27 -0
- package/dist/server/agent-chat/action-filters-a2a.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +27 -1
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/styles/agent-conversation.css +7 -0
- package/dist/templates/default/app/i18n/ar-SA.ts +20 -0
- package/dist/templates/default/app/i18n/de-DE.ts +20 -0
- package/dist/templates/default/app/i18n/en-US.ts +20 -0
- package/dist/templates/default/app/i18n/es-ES.ts +20 -0
- package/dist/templates/default/app/i18n/fr-FR.ts +21 -0
- package/dist/templates/default/app/i18n/hi-IN.ts +19 -0
- package/dist/templates/default/app/i18n/ja-JP.ts +20 -0
- package/dist/templates/default/app/i18n/ko-KR.ts +19 -0
- package/dist/templates/default/app/i18n/pt-BR.ts +20 -0
- package/dist/templates/default/app/i18n/zh-CN.ts +19 -0
- package/dist/templates/default/app/i18n/zh-TW.ts +19 -0
- package/dist/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +28 -0
- package/dist/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +5 -0
- package/dist/templates/workspace-core/.agents/skills/performance/SKILL.md +13 -0
- package/package.json +1 -1
- package/src/templates/default/app/i18n/ar-SA.ts +20 -0
- package/src/templates/default/app/i18n/de-DE.ts +20 -0
- package/src/templates/default/app/i18n/en-US.ts +20 -0
- package/src/templates/default/app/i18n/es-ES.ts +20 -0
- package/src/templates/default/app/i18n/fr-FR.ts +21 -0
- package/src/templates/default/app/i18n/hi-IN.ts +19 -0
- package/src/templates/default/app/i18n/ja-JP.ts +20 -0
- package/src/templates/default/app/i18n/ko-KR.ts +19 -0
- package/src/templates/default/app/i18n/pt-BR.ts +20 -0
- package/src/templates/default/app/i18n/zh-CN.ts +19 -0
- package/src/templates/default/app/i18n/zh-TW.ts +19 -0
- package/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +28 -0
- package/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +5 -0
- package/src/templates/workspace-core/.agents/skills/performance/SKILL.md +13 -0
- package/corpus/templates/analytics/server/handlers/github.ts +0 -200
- package/corpus/templates/analytics/server/handlers/pylon.ts +0 -43
- package/corpus/templates/analytics/server/lib/apollo.ts +0 -167
- package/corpus/templates/analytics/server/lib/commonroom.ts +0 -149
- package/corpus/templates/analytics/server/lib/github.ts +0 -660
- package/corpus/templates/analytics/server/lib/mixpanel.ts +0 -156
- package/corpus/templates/analytics/server/lib/posthog.ts +0 -194
- package/corpus/templates/analytics/server/lib/pylon.ts +0 -109
- package/corpus/templates/analytics/server/routes/api/github/graphql.post.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/github/issue.get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/github/org-prs.get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/github/pr.get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/github/prs.get.ts +0 -1
- package/corpus/templates/analytics/server/routes/api/github/search.get.ts +0 -1
- package/corpus/templates/slides/actions/fetch-logos.ts +0 -90
- package/corpus/templates/slides/actions/image-search.ts +0 -64
- package/corpus/templates/slides/actions/import-github.ts +0 -182
- package/corpus/templates/slides/actions/logo-lookup.ts +0 -113
|
@@ -1,660 +0,0 @@
|
|
|
1
|
-
// GitHub API client — REST v3 + GraphQL v4
|
|
2
|
-
// Auth: GITHUB_TOKEN (personal access token or GitHub App token)
|
|
3
|
-
// Mirrors patterns from server/lib/gong.ts
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
requireRequestCredentialContext,
|
|
7
|
-
scopedCredentialCacheKey,
|
|
8
|
-
} from "./credentials-context";
|
|
9
|
-
import { getGitHubAccessToken } from "./github-oauth";
|
|
10
|
-
|
|
11
|
-
const REST_BASE = "https://api.github.com";
|
|
12
|
-
const GRAPHQL_URL = "https://api.github.com/graphql";
|
|
13
|
-
|
|
14
|
-
const cache = new Map<string, { data: unknown; ts: number }>();
|
|
15
|
-
const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
16
|
-
const MAX_CACHE = 200;
|
|
17
|
-
|
|
18
|
-
async function getToken(): Promise<string> {
|
|
19
|
-
const ctx = requireRequestCredentialContext("GITHUB_TOKEN");
|
|
20
|
-
const { token } = await getGitHubAccessToken(ctx);
|
|
21
|
-
if (!token) throw new Error("GitHub is not connected");
|
|
22
|
-
return token;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function getHeaders(accept?: string): Promise<Record<string, string>> {
|
|
26
|
-
return {
|
|
27
|
-
Authorization: `Bearer ${await getToken()}`,
|
|
28
|
-
Accept: accept ?? "application/vnd.github+json",
|
|
29
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
30
|
-
"Content-Type": "application/json",
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function cacheSet(key: string, data: unknown) {
|
|
35
|
-
if (cache.size >= MAX_CACHE) {
|
|
36
|
-
const oldest = cache.keys().next().value;
|
|
37
|
-
if (oldest) cache.delete(oldest);
|
|
38
|
-
}
|
|
39
|
-
cache.set(key, { data, ts: Date.now() });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function restGet<T>(
|
|
43
|
-
path: string,
|
|
44
|
-
cacheKey?: string,
|
|
45
|
-
accept?: string,
|
|
46
|
-
): Promise<T> {
|
|
47
|
-
const key = scopedCredentialCacheKey(cacheKey ?? path, "GITHUB_TOKEN");
|
|
48
|
-
const cached = cache.get(key);
|
|
49
|
-
if (cached && Date.now() - cached.ts < CACHE_TTL_MS) return cached.data as T;
|
|
50
|
-
|
|
51
|
-
const res = await fetch(`${REST_BASE}${path}`, {
|
|
52
|
-
headers: await getHeaders(accept),
|
|
53
|
-
});
|
|
54
|
-
if (!res.ok) {
|
|
55
|
-
const text = await res.text();
|
|
56
|
-
throw new Error(`GitHub REST error ${res.status}: ${text}`);
|
|
57
|
-
}
|
|
58
|
-
const data = await res.json();
|
|
59
|
-
cacheSet(key, data);
|
|
60
|
-
return data as T;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function graphql<T>(
|
|
64
|
-
query: string,
|
|
65
|
-
variables?: Record<string, unknown>,
|
|
66
|
-
): Promise<T> {
|
|
67
|
-
const body = JSON.stringify({ query, variables });
|
|
68
|
-
const key = scopedCredentialCacheKey(
|
|
69
|
-
`gql:${query}:${JSON.stringify(variables)}`,
|
|
70
|
-
"GITHUB_TOKEN",
|
|
71
|
-
);
|
|
72
|
-
const cached = cache.get(key);
|
|
73
|
-
if (cached && Date.now() - cached.ts < CACHE_TTL_MS) return cached.data as T;
|
|
74
|
-
|
|
75
|
-
const res = await fetch(GRAPHQL_URL, {
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: await getHeaders(),
|
|
78
|
-
body,
|
|
79
|
-
});
|
|
80
|
-
if (!res.ok) {
|
|
81
|
-
const text = await res.text();
|
|
82
|
-
throw new Error(`GitHub GraphQL error ${res.status}: ${text}`);
|
|
83
|
-
}
|
|
84
|
-
const json = await res.json();
|
|
85
|
-
if (json.errors?.length) {
|
|
86
|
-
throw new Error(`GitHub GraphQL errors: ${JSON.stringify(json.errors)}`);
|
|
87
|
-
}
|
|
88
|
-
cacheSet(key, json.data);
|
|
89
|
-
return json.data as T;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
93
|
-
|
|
94
|
-
export interface GitHubPR {
|
|
95
|
-
number: number;
|
|
96
|
-
title: string;
|
|
97
|
-
state: "open" | "closed" | "merged";
|
|
98
|
-
url: string;
|
|
99
|
-
author: string;
|
|
100
|
-
createdAt: string;
|
|
101
|
-
updatedAt: string;
|
|
102
|
-
mergedAt?: string;
|
|
103
|
-
closedAt?: string;
|
|
104
|
-
body?: string;
|
|
105
|
-
labels: string[];
|
|
106
|
-
reviewState?: string; // APPROVED | CHANGES_REQUESTED | REVIEW_REQUIRED | etc.
|
|
107
|
-
draft: boolean;
|
|
108
|
-
baseRef: string;
|
|
109
|
-
headRef: string;
|
|
110
|
-
repo: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface GitHubIssue {
|
|
114
|
-
number: number;
|
|
115
|
-
title: string;
|
|
116
|
-
state: "open" | "closed";
|
|
117
|
-
url: string;
|
|
118
|
-
author: string;
|
|
119
|
-
createdAt: string;
|
|
120
|
-
updatedAt: string;
|
|
121
|
-
closedAt?: string;
|
|
122
|
-
body?: string;
|
|
123
|
-
labels: string[];
|
|
124
|
-
assignees: string[];
|
|
125
|
-
repo: string;
|
|
126
|
-
comments: number;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export interface GitHubPRDetail extends GitHubPR {
|
|
130
|
-
commits: { sha: string; message: string; author: string; date: string }[];
|
|
131
|
-
reviews: {
|
|
132
|
-
author: string;
|
|
133
|
-
state: string;
|
|
134
|
-
submittedAt: string;
|
|
135
|
-
body?: string;
|
|
136
|
-
}[];
|
|
137
|
-
files: {
|
|
138
|
-
filename: string;
|
|
139
|
-
status: string;
|
|
140
|
-
additions: number;
|
|
141
|
-
deletions: number;
|
|
142
|
-
}[];
|
|
143
|
-
comments: number;
|
|
144
|
-
additions: number;
|
|
145
|
-
deletions: number;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ─── Search ───────────────────────────────────────────────────────────────────
|
|
149
|
-
|
|
150
|
-
export interface SearchOptions {
|
|
151
|
-
/** GitHub search query — all qualifiers supported (org:, repo:, author:, etc.) */
|
|
152
|
-
query: string;
|
|
153
|
-
/** "pr" | "issue" (default: "pr") */
|
|
154
|
-
type?: "pr" | "issue";
|
|
155
|
-
/** max results to return (default: 30, max: 100) */
|
|
156
|
-
limit?: number;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
interface RawSearchItem {
|
|
160
|
-
number: number;
|
|
161
|
-
title: string;
|
|
162
|
-
state: string;
|
|
163
|
-
html_url: string;
|
|
164
|
-
user: { login: string };
|
|
165
|
-
created_at: string;
|
|
166
|
-
updated_at: string;
|
|
167
|
-
merged_at?: string;
|
|
168
|
-
closed_at?: string;
|
|
169
|
-
body?: string;
|
|
170
|
-
labels: { name: string }[];
|
|
171
|
-
draft?: boolean;
|
|
172
|
-
pull_request?: { merged_at?: string | null };
|
|
173
|
-
assignees?: { login: string }[];
|
|
174
|
-
comments?: number;
|
|
175
|
-
repository_url?: string;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function repoNameFromUrl(url?: string): string {
|
|
179
|
-
if (!url) return "";
|
|
180
|
-
return url.replace("https://api.github.com/repos/", "");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export async function searchPRs(opts: SearchOptions): Promise<GitHubPR[]> {
|
|
184
|
-
const limit = Math.min(opts.limit ?? 30, 100);
|
|
185
|
-
const q =
|
|
186
|
-
opts.type === "issue" ? `${opts.query} is:issue` : `${opts.query} is:pr`;
|
|
187
|
-
|
|
188
|
-
const data = await restGet<{ items: RawSearchItem[] }>(
|
|
189
|
-
`/search/issues?q=${encodeURIComponent(q)}&per_page=${limit}&sort=updated&order=desc`,
|
|
190
|
-
`search:${q}:${limit}`,
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
return (data.items ?? []).map((item) => ({
|
|
194
|
-
number: item.number,
|
|
195
|
-
title: item.title,
|
|
196
|
-
state: item.pull_request?.merged_at
|
|
197
|
-
? "merged"
|
|
198
|
-
: (item.state as "open" | "closed"),
|
|
199
|
-
url: item.html_url,
|
|
200
|
-
author: item.user?.login ?? "",
|
|
201
|
-
createdAt: item.created_at,
|
|
202
|
-
updatedAt: item.updated_at,
|
|
203
|
-
mergedAt: item.pull_request?.merged_at ?? item.merged_at,
|
|
204
|
-
closedAt: item.closed_at ?? undefined,
|
|
205
|
-
body: item.body ?? undefined,
|
|
206
|
-
labels: item.labels.map((l) => l.name),
|
|
207
|
-
draft: item.draft ?? false,
|
|
208
|
-
baseRef: "",
|
|
209
|
-
headRef: "",
|
|
210
|
-
repo: repoNameFromUrl(item.repository_url),
|
|
211
|
-
}));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export async function searchIssues(
|
|
215
|
-
opts: SearchOptions,
|
|
216
|
-
): Promise<GitHubIssue[]> {
|
|
217
|
-
const limit = Math.min(opts.limit ?? 30, 100);
|
|
218
|
-
const q = `${opts.query} is:issue`;
|
|
219
|
-
|
|
220
|
-
const data = await restGet<{ items: RawSearchItem[] }>(
|
|
221
|
-
`/search/issues?q=${encodeURIComponent(q)}&per_page=${limit}&sort=updated&order=desc`,
|
|
222
|
-
`search-issues:${q}:${limit}`,
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
return (data.items ?? []).map((item) => ({
|
|
226
|
-
number: item.number,
|
|
227
|
-
title: item.title,
|
|
228
|
-
state: item.state as "open" | "closed",
|
|
229
|
-
url: item.html_url,
|
|
230
|
-
author: item.user?.login ?? "",
|
|
231
|
-
createdAt: item.created_at,
|
|
232
|
-
updatedAt: item.updated_at,
|
|
233
|
-
closedAt: item.closed_at ?? undefined,
|
|
234
|
-
body: item.body ?? undefined,
|
|
235
|
-
labels: item.labels.map((l) => l.name),
|
|
236
|
-
assignees: (item.assignees ?? []).map((a) => a.login),
|
|
237
|
-
repo: repoNameFromUrl(item.repository_url),
|
|
238
|
-
comments: item.comments ?? 0,
|
|
239
|
-
}));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// ─── PR detail ────────────────────────────────────────────────────────────────
|
|
243
|
-
|
|
244
|
-
export async function getPR(
|
|
245
|
-
owner: string,
|
|
246
|
-
repo: string,
|
|
247
|
-
prNumber: number,
|
|
248
|
-
): Promise<GitHubPRDetail> {
|
|
249
|
-
const [pr, commits, reviews, files] = await Promise.all([
|
|
250
|
-
restGet<Record<string, unknown>>(
|
|
251
|
-
`/repos/${owner}/${repo}/pulls/${prNumber}`,
|
|
252
|
-
),
|
|
253
|
-
restGet<Record<string, unknown>[]>(
|
|
254
|
-
`/repos/${owner}/${repo}/pulls/${prNumber}/commits`,
|
|
255
|
-
),
|
|
256
|
-
restGet<Record<string, unknown>[]>(
|
|
257
|
-
`/repos/${owner}/${repo}/pulls/${prNumber}/reviews`,
|
|
258
|
-
),
|
|
259
|
-
restGet<Record<string, unknown>[]>(
|
|
260
|
-
`/repos/${owner}/${repo}/pulls/${prNumber}/files`,
|
|
261
|
-
),
|
|
262
|
-
]);
|
|
263
|
-
|
|
264
|
-
const state = pr.merged_at
|
|
265
|
-
? "merged"
|
|
266
|
-
: pr.state === "closed"
|
|
267
|
-
? "closed"
|
|
268
|
-
: "open";
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
number: pr.number as number,
|
|
272
|
-
title: pr.title as string,
|
|
273
|
-
state,
|
|
274
|
-
url: pr.html_url as string,
|
|
275
|
-
author: (pr.user as { login: string })?.login ?? "",
|
|
276
|
-
createdAt: pr.created_at as string,
|
|
277
|
-
updatedAt: pr.updated_at as string,
|
|
278
|
-
mergedAt: pr.merged_at as string | undefined,
|
|
279
|
-
closedAt: pr.closed_at as string | undefined,
|
|
280
|
-
body: pr.body as string | undefined,
|
|
281
|
-
labels: ((pr.labels as { name: string }[]) ?? []).map((l) => l.name),
|
|
282
|
-
draft: pr.draft as boolean,
|
|
283
|
-
baseRef: (pr.base as { ref: string })?.ref ?? "",
|
|
284
|
-
headRef: (pr.head as { ref: string })?.ref ?? "",
|
|
285
|
-
repo: `${owner}/${repo}`,
|
|
286
|
-
comments: (pr.comments as number) ?? 0,
|
|
287
|
-
additions: (pr.additions as number) ?? 0,
|
|
288
|
-
deletions: (pr.deletions as number) ?? 0,
|
|
289
|
-
commits: commits.map((c: Record<string, unknown>) => ({
|
|
290
|
-
sha: (c.sha as string).slice(0, 7),
|
|
291
|
-
message: (
|
|
292
|
-
((c.commit as Record<string, unknown>)?.message as string) ?? ""
|
|
293
|
-
).split("\n")[0],
|
|
294
|
-
author:
|
|
295
|
-
((c.commit as Record<string, unknown>)?.author as { name?: string })
|
|
296
|
-
?.name ??
|
|
297
|
-
(c.author as { login?: string })?.login ??
|
|
298
|
-
"",
|
|
299
|
-
date:
|
|
300
|
-
((c.commit as Record<string, unknown>)?.author as { date?: string })
|
|
301
|
-
?.date ?? "",
|
|
302
|
-
})),
|
|
303
|
-
reviews: reviews.map((r: Record<string, unknown>) => ({
|
|
304
|
-
author: (r.user as { login: string })?.login ?? "",
|
|
305
|
-
state: r.state as string,
|
|
306
|
-
submittedAt: r.submitted_at as string,
|
|
307
|
-
body: r.body as string | undefined,
|
|
308
|
-
})),
|
|
309
|
-
files: files.map((f: Record<string, unknown>) => ({
|
|
310
|
-
filename: f.filename as string,
|
|
311
|
-
status: f.status as string,
|
|
312
|
-
additions: f.additions as number,
|
|
313
|
-
deletions: f.deletions as number,
|
|
314
|
-
})),
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// ─── Issue detail ─────────────────────────────────────────────────────────────
|
|
319
|
-
|
|
320
|
-
export async function getIssue(
|
|
321
|
-
owner: string,
|
|
322
|
-
repo: string,
|
|
323
|
-
issueNumber: number,
|
|
324
|
-
): Promise<GitHubIssue> {
|
|
325
|
-
const issue = await restGet<Record<string, unknown>>(
|
|
326
|
-
`/repos/${owner}/${repo}/issues/${issueNumber}`,
|
|
327
|
-
);
|
|
328
|
-
return {
|
|
329
|
-
number: issue.number as number,
|
|
330
|
-
title: issue.title as string,
|
|
331
|
-
state: issue.state as "open" | "closed",
|
|
332
|
-
url: issue.html_url as string,
|
|
333
|
-
author: (issue.user as { login: string })?.login ?? "",
|
|
334
|
-
createdAt: issue.created_at as string,
|
|
335
|
-
updatedAt: issue.updated_at as string,
|
|
336
|
-
closedAt: issue.closed_at as string | undefined,
|
|
337
|
-
body: issue.body as string | undefined,
|
|
338
|
-
labels: ((issue.labels as { name: string }[]) ?? []).map((l) => l.name),
|
|
339
|
-
assignees: ((issue.assignees as { login: string }[]) ?? []).map(
|
|
340
|
-
(a) => a.login,
|
|
341
|
-
),
|
|
342
|
-
repo: `${owner}/${repo}`,
|
|
343
|
-
comments: (issue.comments as number) ?? 0,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// ─── List repo PRs ────────────────────────────────────────────────────────────
|
|
348
|
-
|
|
349
|
-
export async function listPRs(
|
|
350
|
-
owner: string,
|
|
351
|
-
repo: string,
|
|
352
|
-
opts: { state?: "open" | "closed" | "all"; limit?: number } = {},
|
|
353
|
-
): Promise<GitHubPR[]> {
|
|
354
|
-
const state = opts.state ?? "open";
|
|
355
|
-
const limit = Math.min(opts.limit ?? 30, 100);
|
|
356
|
-
const items = await restGet<Record<string, unknown>[]>(
|
|
357
|
-
`/repos/${owner}/${repo}/pulls?state=${state}&per_page=${limit}&sort=updated&direction=desc`,
|
|
358
|
-
`list-prs:${owner}/${repo}:${state}:${limit}`,
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
return items.map((pr) => ({
|
|
362
|
-
number: pr.number as number,
|
|
363
|
-
title: pr.title as string,
|
|
364
|
-
state: pr.merged_at ? "merged" : (pr.state as "open" | "closed"),
|
|
365
|
-
url: pr.html_url as string,
|
|
366
|
-
author: (pr.user as { login: string })?.login ?? "",
|
|
367
|
-
createdAt: pr.created_at as string,
|
|
368
|
-
updatedAt: pr.updated_at as string,
|
|
369
|
-
mergedAt: pr.merged_at as string | undefined,
|
|
370
|
-
closedAt: pr.closed_at as string | undefined,
|
|
371
|
-
body: pr.body as string | undefined,
|
|
372
|
-
labels: ((pr.labels as { name: string }[]) ?? []).map((l) => l.name),
|
|
373
|
-
draft: pr.draft as boolean,
|
|
374
|
-
baseRef: (pr.base as { ref: string })?.ref ?? "",
|
|
375
|
-
headRef: (pr.head as { ref: string })?.ref ?? "",
|
|
376
|
-
repo: `${owner}/${repo}`,
|
|
377
|
-
}));
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// ─── GraphQL — arbitrary query ────────────────────────────────────────────────
|
|
381
|
-
|
|
382
|
-
export async function runGraphQL<T = unknown>(
|
|
383
|
-
query: string,
|
|
384
|
-
variables?: Record<string, unknown>,
|
|
385
|
-
): Promise<T> {
|
|
386
|
-
return graphql<T>(query, variables);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// ─── Org-wide PR search (via GraphQL) ────────────────────────────────────────
|
|
390
|
-
|
|
391
|
-
export async function searchOrgPRs(opts: {
|
|
392
|
-
org: string;
|
|
393
|
-
query?: string;
|
|
394
|
-
state?: "OPEN" | "CLOSED" | "MERGED";
|
|
395
|
-
limit?: number;
|
|
396
|
-
}): Promise<GitHubPR[]> {
|
|
397
|
-
const { org, query = "", state, limit = 30 } = opts;
|
|
398
|
-
|
|
399
|
-
// Build search string
|
|
400
|
-
const stateQ = state ? ` is:${state.toLowerCase()}` : "";
|
|
401
|
-
const q = `org:${org} is:pr ${query}${stateQ}`.trim();
|
|
402
|
-
|
|
403
|
-
return searchPRs({ query: q, type: "pr", limit });
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// ─── Repositories and code search ───────────────────────────────────────────
|
|
407
|
-
|
|
408
|
-
export interface GitHubRepository {
|
|
409
|
-
name: string;
|
|
410
|
-
fullName: string;
|
|
411
|
-
owner: string;
|
|
412
|
-
private: boolean;
|
|
413
|
-
fork: boolean;
|
|
414
|
-
archived: boolean;
|
|
415
|
-
defaultBranch: string;
|
|
416
|
-
description?: string;
|
|
417
|
-
language?: string;
|
|
418
|
-
updatedAt: string;
|
|
419
|
-
url: string;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export interface GitHubCodeSearchResult {
|
|
423
|
-
repo: string;
|
|
424
|
-
path: string;
|
|
425
|
-
name: string;
|
|
426
|
-
sha: string;
|
|
427
|
-
url: string;
|
|
428
|
-
score: number;
|
|
429
|
-
textMatches: Array<{
|
|
430
|
-
fragment: string;
|
|
431
|
-
matches: Array<{ text: string; indices: [number, number] }>;
|
|
432
|
-
}>;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
export interface GitHubFileContent {
|
|
436
|
-
repo: string;
|
|
437
|
-
path: string;
|
|
438
|
-
ref?: string;
|
|
439
|
-
sha?: string;
|
|
440
|
-
size?: number;
|
|
441
|
-
encoding?: string;
|
|
442
|
-
content?: string;
|
|
443
|
-
truncated?: boolean;
|
|
444
|
-
entries?: Array<{
|
|
445
|
-
name: string;
|
|
446
|
-
path: string;
|
|
447
|
-
type: string;
|
|
448
|
-
size?: number;
|
|
449
|
-
sha?: string;
|
|
450
|
-
url?: string;
|
|
451
|
-
}>;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
interface RawRepo {
|
|
455
|
-
name: string;
|
|
456
|
-
full_name: string;
|
|
457
|
-
owner: { login: string };
|
|
458
|
-
private: boolean;
|
|
459
|
-
fork: boolean;
|
|
460
|
-
archived: boolean;
|
|
461
|
-
default_branch: string;
|
|
462
|
-
description?: string | null;
|
|
463
|
-
language?: string | null;
|
|
464
|
-
updated_at: string;
|
|
465
|
-
html_url: string;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
interface RawCodeSearchItem {
|
|
469
|
-
name: string;
|
|
470
|
-
path: string;
|
|
471
|
-
sha: string;
|
|
472
|
-
html_url: string;
|
|
473
|
-
score: number;
|
|
474
|
-
repository: { full_name: string };
|
|
475
|
-
text_matches?: Array<{
|
|
476
|
-
fragment?: string;
|
|
477
|
-
matches?: Array<{ text?: string; indices?: [number, number] }>;
|
|
478
|
-
}>;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
interface RawContentItem {
|
|
482
|
-
type?: string;
|
|
483
|
-
name?: string;
|
|
484
|
-
path?: string;
|
|
485
|
-
sha?: string;
|
|
486
|
-
size?: number;
|
|
487
|
-
html_url?: string;
|
|
488
|
-
encoding?: string;
|
|
489
|
-
content?: string;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function mapRepository(repo: RawRepo): GitHubRepository {
|
|
493
|
-
return {
|
|
494
|
-
name: repo.name,
|
|
495
|
-
fullName: repo.full_name,
|
|
496
|
-
owner: repo.owner?.login ?? repo.full_name.split("/")[0] ?? "",
|
|
497
|
-
private: repo.private,
|
|
498
|
-
fork: repo.fork,
|
|
499
|
-
archived: repo.archived,
|
|
500
|
-
defaultBranch: repo.default_branch,
|
|
501
|
-
description: repo.description ?? undefined,
|
|
502
|
-
language: repo.language ?? undefined,
|
|
503
|
-
updatedAt: repo.updated_at,
|
|
504
|
-
url: repo.html_url,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function parseRepo(repo: string): { owner: string; name: string } {
|
|
509
|
-
const [owner, name] = repo.split("/");
|
|
510
|
-
if (!owner || !name || repo.split("/").length !== 2) {
|
|
511
|
-
throw new Error("repo must be in owner/repo format");
|
|
512
|
-
}
|
|
513
|
-
return { owner, name };
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
function encodeRepoPath(path: string): string {
|
|
517
|
-
return path
|
|
518
|
-
.split("/")
|
|
519
|
-
.filter(Boolean)
|
|
520
|
-
.map((part) => encodeURIComponent(part))
|
|
521
|
-
.join("/");
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
export async function listRepos(
|
|
525
|
-
opts: {
|
|
526
|
-
query?: string;
|
|
527
|
-
visibility?: "all" | "public" | "private";
|
|
528
|
-
limit?: number;
|
|
529
|
-
} = {},
|
|
530
|
-
): Promise<GitHubRepository[]> {
|
|
531
|
-
const limit = Math.min(opts.limit ?? 50, 100);
|
|
532
|
-
const visibility = opts.visibility ?? "all";
|
|
533
|
-
const data = await restGet<RawRepo[]>(
|
|
534
|
-
`/user/repos?per_page=${limit}&sort=updated&direction=desc&visibility=${visibility}&affiliation=owner,collaborator,organization_member`,
|
|
535
|
-
`repos:${visibility}:${limit}`,
|
|
536
|
-
);
|
|
537
|
-
const repos = data.map(mapRepository);
|
|
538
|
-
const query = opts.query?.trim().toLowerCase();
|
|
539
|
-
if (!query) return repos;
|
|
540
|
-
return repos.filter((repo) => {
|
|
541
|
-
return (
|
|
542
|
-
repo.fullName.toLowerCase().includes(query) ||
|
|
543
|
-
repo.name.toLowerCase().includes(query) ||
|
|
544
|
-
(repo.description ?? "").toLowerCase().includes(query)
|
|
545
|
-
);
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
export async function getRepo(
|
|
550
|
-
owner: string,
|
|
551
|
-
repo: string,
|
|
552
|
-
): Promise<GitHubRepository> {
|
|
553
|
-
return mapRepository(
|
|
554
|
-
await restGet<RawRepo>(`/repos/${owner}/${repo}`, `repo:${owner}/${repo}`),
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export async function searchCode(opts: {
|
|
559
|
-
query: string;
|
|
560
|
-
repo?: string;
|
|
561
|
-
org?: string;
|
|
562
|
-
user?: string;
|
|
563
|
-
path?: string;
|
|
564
|
-
extension?: string;
|
|
565
|
-
filename?: string;
|
|
566
|
-
limit?: number;
|
|
567
|
-
}): Promise<GitHubCodeSearchResult[]> {
|
|
568
|
-
const limit = Math.min(opts.limit ?? 30, 100);
|
|
569
|
-
const parts = [opts.query.trim()];
|
|
570
|
-
if (!parts[0]) throw new Error("query is required");
|
|
571
|
-
if (opts.repo) parts.push(`repo:${opts.repo}`);
|
|
572
|
-
if (opts.org) parts.push(`org:${opts.org}`);
|
|
573
|
-
if (opts.user) parts.push(`user:${opts.user}`);
|
|
574
|
-
if (opts.path) parts.push(`path:${opts.path}`);
|
|
575
|
-
if (opts.extension) parts.push(`extension:${opts.extension}`);
|
|
576
|
-
if (opts.filename) parts.push(`filename:${opts.filename}`);
|
|
577
|
-
const q = parts.join(" ");
|
|
578
|
-
const data = await restGet<{ items: RawCodeSearchItem[] }>(
|
|
579
|
-
`/search/code?q=${encodeURIComponent(q)}&per_page=${limit}`,
|
|
580
|
-
`code:${q}:${limit}`,
|
|
581
|
-
"application/vnd.github.text-match+json",
|
|
582
|
-
);
|
|
583
|
-
|
|
584
|
-
return (data.items ?? []).map((item) => ({
|
|
585
|
-
repo: item.repository?.full_name ?? "",
|
|
586
|
-
path: item.path,
|
|
587
|
-
name: item.name,
|
|
588
|
-
sha: item.sha,
|
|
589
|
-
url: item.html_url,
|
|
590
|
-
score: item.score,
|
|
591
|
-
textMatches: (item.text_matches ?? []).map((match) => ({
|
|
592
|
-
fragment: match.fragment ?? "",
|
|
593
|
-
matches: (match.matches ?? []).map((m) => ({
|
|
594
|
-
text: m.text ?? "",
|
|
595
|
-
indices: m.indices ?? [0, 0],
|
|
596
|
-
})),
|
|
597
|
-
})),
|
|
598
|
-
}));
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
export async function getFileContent(opts: {
|
|
602
|
-
repo: string;
|
|
603
|
-
path: string;
|
|
604
|
-
ref?: string;
|
|
605
|
-
maxBytes?: number;
|
|
606
|
-
}): Promise<GitHubFileContent> {
|
|
607
|
-
const { owner, name } = parseRepo(opts.repo);
|
|
608
|
-
const encodedPath = encodeRepoPath(opts.path);
|
|
609
|
-
const refQuery = opts.ref ? `?ref=${encodeURIComponent(opts.ref)}` : "";
|
|
610
|
-
const data = await restGet<RawContentItem | RawContentItem[]>(
|
|
611
|
-
`/repos/${owner}/${name}/contents/${encodedPath}${refQuery}`,
|
|
612
|
-
`content:${opts.repo}:${opts.path}:${opts.ref ?? ""}`,
|
|
613
|
-
);
|
|
614
|
-
|
|
615
|
-
if (Array.isArray(data)) {
|
|
616
|
-
return {
|
|
617
|
-
repo: opts.repo,
|
|
618
|
-
path: opts.path,
|
|
619
|
-
ref: opts.ref,
|
|
620
|
-
entries: data.map((entry) => ({
|
|
621
|
-
name: entry.name ?? "",
|
|
622
|
-
path: entry.path ?? "",
|
|
623
|
-
type: entry.type ?? "",
|
|
624
|
-
size: entry.size,
|
|
625
|
-
sha: entry.sha,
|
|
626
|
-
url: entry.html_url,
|
|
627
|
-
})),
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
if (data.type !== "file") {
|
|
632
|
-
return {
|
|
633
|
-
repo: opts.repo,
|
|
634
|
-
path: opts.path,
|
|
635
|
-
ref: opts.ref,
|
|
636
|
-
sha: data.sha,
|
|
637
|
-
size: data.size,
|
|
638
|
-
encoding: data.encoding,
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
const rawContent =
|
|
643
|
-
data.encoding === "base64" && data.content
|
|
644
|
-
? Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8")
|
|
645
|
-
: (data.content ?? "");
|
|
646
|
-
const maxBytes = Math.min(opts.maxBytes ?? 80_000, 200_000);
|
|
647
|
-
const truncated = Buffer.byteLength(rawContent, "utf8") > maxBytes;
|
|
648
|
-
const content = truncated ? rawContent.slice(0, maxBytes) : rawContent;
|
|
649
|
-
|
|
650
|
-
return {
|
|
651
|
-
repo: opts.repo,
|
|
652
|
-
path: opts.path,
|
|
653
|
-
ref: opts.ref,
|
|
654
|
-
sha: data.sha,
|
|
655
|
-
size: data.size,
|
|
656
|
-
encoding: data.encoding,
|
|
657
|
-
content,
|
|
658
|
-
truncated,
|
|
659
|
-
};
|
|
660
|
-
}
|