openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
67 lines (66 loc) • 3.97 kB
JavaScript
import { n as containsAsciiControlCharacter } from "./string-normalization-DLmfYZXI.mjs";
import { Et as _enum, Jn as string, Lt as boolean, Pn as number, or as union, qn as strictObject } from "./schemas-Cy6abvsu.mjs";
import { r as BoardValidationError } from "./board-layout-C0d9b7cg.mjs";
//#region src/boards/github-actions-capability.ts
const GITHUB_ACTIONS_BINDING_ID = "github.actions.runs";
const GITHUB_ACTIONS_GRANT_PREFIX = `${GITHUB_ACTIONS_BINDING_ID}:`;
const GITHUB_ACTIONS_AUTHOR_GUIDANCE = "With a usable connected agent GitHub identity: await openclaw.data.read(\"github.actions.runs\",{repository:\"owner/repo\",perPage:20}); grant capabilities.tools:[\"github.actions.runs:owner/repo\"]. Uses the agent GitHub identity and cached server reads; direct fetch(api.github.com) is anonymous and rate limited. Identity is checked before save; reconnect in Settings if unavailable. Optional workflow (ID/filename), branch, status, created (ISO day/comparison/range), excludePullRequests=true (omits PR objects); perPage 1..30. Shares private Actions metadata with the widget/session audience; never preview or My GitHub auth. No netOrigins needed.";
const repositorySchema = string().regex(/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9_.-]{1,100}$/u).refine((e) => ![".", ".."].includes(e.split("/")[1])).transform((e) => e.toLowerCase());
const day = "\\d{4}-\\d{2}-\\d{2}";
const createdSchema = string().regex(new RegExp(`^(?:[<>]=?)?${day}$|^${day}\\.\\.${day}$`, "u")).refine((e) => (e.match(/\d{4}-\d{2}-\d{2}/gu) ?? []).every((e) => {
const t = /* @__PURE__ */ new Date(`${e}T00:00:00Z`);
return Number.isFinite(t.getTime()) && t.toISOString().startsWith(e);
}));
const paramsSchema = strictObject({
repository: repositorySchema,
workflow: union([number().int().positive().max(Number.MAX_SAFE_INTEGER), string().max(255).regex(/^(?:[1-9]\d*|[A-Za-z0-9_.-]+\.ya?ml)$/u).refine((e) => !/^\d+$/u.test(e) || Number.isSafeInteger(Number(e)))]).optional(),
perPage: number().int().min(1).max(30).default(20),
branch: string().min(1).max(255).refine((e) => !containsAsciiControlCharacter(e)).optional(),
status: _enum([
"completed",
"action_required",
"cancelled",
"failure",
"neutral",
"skipped",
"stale",
"success",
"timed_out",
"in_progress",
"queued",
"requested",
"waiting",
"pending"
]).optional(),
created: createdSchema.optional(),
excludePullRequests: boolean().default(true)
});
function normalizeGitHubActionsGrant(e) {
if (!e.startsWith("github.actions.runs:")) return e;
const t = repositorySchema.safeParse(e.slice(GITHUB_ACTIONS_GRANT_PREFIX.length));
if (!t.success) throw new BoardValidationError("invalid_operation", "GitHub Actions grant requires owner/repo");
return `${GITHUB_ACTIONS_GRANT_PREFIX}${t.data}`;
}
/** The same closed contract owns URL construction and the exact repository grant. */
function resolveGitHubActionsRequest(e) {
const t = paramsSchema.safeParse(e);
if (!t.success) throw new BoardValidationError("invalid_operation", "Invalid GitHub Actions parameters: use repository (owner/repo), workflow, perPage (1..30), branch, status, created, or excludePullRequests only");
const n = t.data;
const r = n.repository.split("/").map(encodeURIComponent).join("/");
const i = n.workflow === void 0 ? "runs" : `workflows/${encodeURIComponent(String(n.workflow))}/runs`;
const a = new URL(`https://api.github.com/repos/${r}/actions/${i}`);
a.searchParams.set("per_page", String(n.perPage));
a.searchParams.set("exclude_pull_requests", String(n.excludePullRequests));
for (const e of [
"branch",
"status",
"created"
]) if (n[e] !== void 0) a.searchParams.set(e, n[e]);
return {
...n,
url: a.href,
capability: `${GITHUB_ACTIONS_GRANT_PREFIX}${n.repository}`
};
}
//#endregion
export { resolveGitHubActionsRequest as a, normalizeGitHubActionsGrant as i, GITHUB_ACTIONS_BINDING_ID as n, GITHUB_ACTIONS_GRANT_PREFIX as r, GITHUB_ACTIONS_AUTHOR_GUIDANCE as t };