UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

168 lines (167 loc) • 5.8 kB
import { r as textResult } from "../../tool-results-CcV0sxnb.mjs"; import { t as definePluginEntry } from "../../plugin-entry-CiJdaHtx.mjs"; import { n as GITHUB_ITEM_PATH_PATTERN, s as parseGitHubReadParams, t as GITHUB_COMMIT_PATH_PATTERN } from "../../targets-CFNRMYXS.mjs"; import { t as parseGitHubSearchParams } from "../../search-params-BqoVzC8t.mjs"; //#region extensions/github/index.ts const GITHUB_READ_PARAMETERS = { type: "object", properties: { url: { type: "string", minLength: 1, maxLength: 4096, description: "Public github.com issue, pull request, commit, or Actions workflow-job URL." }, refresh: { type: "boolean", description: "Fetch current content instead of cached content." } }, required: ["url"], additionalProperties: false }; const GITHUB_SEARCH_PARAMETERS = { type: "object", properties: { repository: { type: "string", description: "Public github.com repository as owner/repo." }, query: { type: "string", maxLength: 256, description: "Plain-text keywords; up to 256 characters after each word is quoted. No qualifiers, quotes, backslashes, or parentheses. Omit to list matches for the filters." }, kind: { type: "string", enum: ["issue", "pull"] }, state: { type: "string", enum: [ "all", "open", "closed" ], default: "all" }, page: { type: "integer", minimum: 1, maximum: 50, default: 1 } }, required: ["repository", "kind"], additionalProperties: false }; async function wrappedGitHubResult(e, t, n) { const { wrapExternalContent: r } = await import("../../plugin-sdk/security-runtime.js"); t.assertInvocationCurrent(); n?.throwIfAborted(); return textResult(r(JSON.stringify(e, null, 2), { source: "api", includeWarning: false }), e); } var github_default = definePluginEntry({ id: "github", name: "GitHub", description: "Public GitHub link previews and document reader", register(e) { e.registerTool({ contextVersion: 2, create: (t) => ({ name: "github_read", label: "Read GitHub", description: "Read a known public GitHub issue, pull request, commit, or Actions workflow-job URL. Returns the description, bounded discussion and review comments, file changes, PR checks, or the bounded end of a completed job log with its run and commit identity. Inspect partial and truncation flags before treating the result as complete. The Gateway reads GitHub; no credentials or network access are needed in the sandbox. Does not search or modify GitHub.", parameters: GITHUB_READ_PARAMETERS, async execute(n, r, i) { t.assertInvocationCurrent(); i?.throwIfAborted(); const a = parseGitHubReadParams(r); if (!a) throw new Error("Provide a public github.com issue, pull request, commit, or Actions workflow-job URL."); return wrappedGitHubResult(await e.runtime.gateway.request("tools.github.read", { ...a.target, refresh: a.refresh }, { scopes: ["operator.sessions.read"], timeoutMs: 12e4, signal: i }), t, i); } }) }, { name: "github_read", workspaceAccess: false }); e.registerTool({ contextVersion: 2, create: (t) => ({ name: "github_search", label: "Search GitHub", description: "Find public issues or pull requests in one chosen GitHub repository. Choose kind=issue or kind=pull; search each separately when you need both. Returns up to 20 matches, newest updated first, and nextPage, incomplete, and limited flags. Returns item URLs for further reading. The Gateway searches; sandbox credentials and network access are not needed. Does not search private repositories or modify GitHub.", parameters: GITHUB_SEARCH_PARAMETERS, async execute(n, r, i) { t.assertInvocationCurrent(); i?.throwIfAborted(); const a = parseGitHubSearchParams(r); if (!a) throw new Error("Provide a public owner/repo repository, shorter plain-text keywords without search syntax, valid kind/state filters, and a page from 1 to 50."); return wrappedGitHubResult(await e.runtime.gateway.request("tools.github.search", a, { scopes: ["operator.sessions.read"], timeoutMs: 12e4, signal: i }), t, i); } }) }, { name: "github_search", workspaceAccess: false }); const registerReaders = (t, n = false) => { for (const [r, i] of [["", GITHUB_ITEM_PATH_PATTERN], ["-commit", GITHUB_COMMIT_PATH_PATTERN]]) e.session.controls.registerControlUiDescriptor({ surface: "link-reader", id: `github${n ? "-session" : ""}${r}`, label: "GitHub", icon: "github", requiredScopes: ["operator.read"], linkReader: { hosts: [t], pathPattern: i, progressive: true, ...n ? { sessionScoped: true, detailMethod: "github.sessionDetail", previewMethod: "github.sessionPreview" } : { detailMethod: "github.detail", previewMethod: "github.preview", imageMethod: "github.image" } } }); }; registerReaders("github.com"); const t = e.config.gateway?.github?.host?.trim().toLowerCase(); if (t && t !== "github.com") { registerReaders(t, true); for (const [n, r] of [["github.sessionPreview", "preview"], ["github.sessionDetail", "detail"]]) e.registerGatewayMethod(n, async (e) => { const { handleSessionGitHubRequest: n } = await import("../../handlers-DWDfjL-_.mjs"); await n(r, t, e); }, { scope: "operator.read" }); } for (const t of [ "github.preview", "github.detail", "github.image" ]) e.registerGatewayMethod(t, async (e) => { const { githubHandlers: n } = await import("../../handlers-DWDfjL-_.mjs"); await n[t](e); }, { scope: "operator.read", profileAccess: "independent" }); } }); //#endregion export { github_default as default };