Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge #7447: Send the connected GitHub sign-in on skill import API requests

milind-sonia571394978a3
diff --cc server/index.ts
index dc688b6f74,f785eb71aa..68776a208a
--- a/server/index.ts
+++ b/server/index.ts
@@@ -114,7 -114,7 +114,7 @@@ import { boatCreateRecoverySnapshot } f
import { boatDeletionSnapshot } from "./boat-delete-journal.ts";
import { liveDecisionRefusal } from "../shared/live-approval.ts"; import type { PersonWaitKind } from "../shared/person-wait.ts";
import { vpsLeftBehindNotice, vpsNotChosenReason } from "./cloud-backend.ts";
- import * as composio from "./composio.ts"; import { createConnectorListingRoutes } from "./routes/connectors-listing.ts"; import { createGhTools } from "./github/gh-cli.ts"; import { createGithubSignIn } from "./github/sign-in.ts"; import { provideGithubSignIn } from "./github/token.ts"; import { createGitCredentialRoutes } from "./github/git-credential.ts"; import { createGithubSignInRoutes } from "./routes/github-sign-in.ts"; import { createGithubSignInCards, isGithubSignInCard } from "./host/github-sign-in-cards.ts"; import { provideGithubSignInCards } from "./github/sign-in-card.ts";
-import * as composio from "./composio.ts"; import { createConnectorListingRoutes } from "./routes/connectors-listing.ts"; import { createGhTools } from "./github/gh-cli.ts"; import { createGithubSignIn } from "./github/sign-in.ts"; import { provideGithubSignIn } from "./github/token.ts"; import { createGitCredentialRoutes } from "./github/git-credential.ts"; import { gitAudience } from "./github/git-access.ts"; import { createGithubSignInRoutes, githubAudience } from "./routes/github-sign-in.ts";
++import * as composio from "./composio.ts"; import { createConnectorListingRoutes } from "./routes/connectors-listing.ts"; import { createGhTools } from "./github/gh-cli.ts"; import { createGithubSignIn } from "./github/sign-in.ts"; import { provideGithubSignIn } from "./github/token.ts"; import { createGitCredentialRoutes } from "./github/git-credential.ts"; import { gitAudience } from "./github/git-access.ts"; import { createGithubSignInRoutes, githubAudience } from "./routes/github-sign-in.ts"; import { createGithubSignInCards, isGithubSignInCard } from "./host/github-sign-in-cards.ts"; import { provideGithubSignInCards } from "./github/sign-in-card.ts";
import { appSandboxRule, connectorCallFromFrame, connectorRefusalText, connectorScopeRefusalText, connectorUnrecognizedText, evaluateConnectorTools } from "./connector-verdict.ts";
import { signInCardText } from "./connector-card-text.ts";
import { BOT_HELD_CODE, BOT_PAUSED_CODE } from "../shared/bot-limit.ts"; import { createBotHolds } from "./host/bot-holds.ts"; import { createBotHoldRoutes } from "./routes/bot-holds.ts"; import { createCliLogin } from "./routes/cli-login.ts"; import { createStarterAwake } from "./host/starter-awake.ts"; import { createStarterCaps } from "./host/starter-caps.ts"; import { createStarterRoutineWake, workInFlight, type StarterRoutineWake } from "./host/starter-routine-wake.ts"; import { createStarterAwakeRoutes } from "./routes/starter-awake.ts"; import { chiefOfStaffPrompt, chiefOfStaffSystemPrompt } from "./chief-of-staff.ts"; import { coordinateMessageMax, coordinateTooLong, reportBackTooLong } from "./too-long.ts"; import { chiefAbsentFrom, createChiefRooms } from "./host/chief-rooms.ts"; import { chiefLevel, readTeamRolesWith } from "./chief-level.ts"; import { defaultBotRefusal, ensureDefaultBot } from "./default-bot.ts";
@@@ -11999,7 -12000,7 +11999,7 @@@ ROUTES.push(createBotLifecycleRoutes(
store, routines: () => routines, interruptAllDirectThreads, cancelDirectTurnDispatch, revokeInternalCapabilitiesForThread,
activeGroupTurnForBot, cancelGroupTurnOperations, runningTurnInstance, closeOpenApprovals, deleteBotWithLifecycle, deleteRefusal: (auth, botId) => memberDeleteRefusal(auth, store.bot(botId), Boolean(CLOUD_TEAM)),
}));
- const skillsRoutes = createBotSkillsRoutes({ store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing }); ROUTES.push(createSkillsForAllBotsRoutes({ store, host: allBotsSkills }), skillsRoutes);
-const skillsRoutes = createBotSkillsRoutes({ store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing, team: Boolean(CLOUD_TEAM) }); ROUTES.push(skillsRoutes);
++const skillsRoutes = createBotSkillsRoutes({ store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing, team: Boolean(CLOUD_TEAM) }); ROUTES.push(createSkillsForAllBotsRoutes({ store, host: allBotsSkills }), skillsRoutes);
ROUTES.push(createEmailRoutes({ service: emailService }));
ROUTES.push(phones.routes);
ROUTES.push(createSkillShareRoutes({ enabled: () => skillsHost.mode() !== "off", botExists: (id) => Boolean(store.bot(id)),
@@@ -13414,8 -13415,8 +13414,8 @@@ const handleRequest = async (req: Incom
if (!connectorThread(from.id, fromThreadId)) {
return json(res, 403, { error: "source conversation does not belong to sender" });
}
- const everywhere = await allBotsSkills.stage(from, fromThreadId, received, () => appliesDirectly(from.id, fromThreadId), (asked) => importedSkillRequest(asked, fetch, callSignal), () => internalCapabilityIsActive(internalCapability) && skillAuthoringEnabled(cfg), () => (CLOUD_TEAM ? actingPeople.requester(fromThreadId, internalCapability.generation) : null)); if (everywhere) return json(res, everywhere.status, everywhere.body); if (isSkillSwitchAction(received.action)) { const staged = skillSwitch.stage(from, fromThreadId, received.action, received, appliesDirectly(from.id, fromThreadId)); return json(res, staged.status, staged.body); }
- const body = await importedSkillRequest(received, fetch, callSignal); if ("importError" in body) return json(res, 422, { error: body.importError }); if (!internalCapabilityIsActive(internalCapability)) return json(res, 401, { error: TURN_ENDED_REFUSAL }); if (!skillAuthoringEnabled(cfg)) return json(res, 403, { error: "skill authoring is not enabled in Settings" });
- if (isSkillSwitchAction(received.action)) { const staged = skillSwitch.stage(from, fromThreadId, received.action, received, appliesDirectly(from.id, fromThreadId)); return json(res, staged.status, staged.body); }
++ const everywhere = await allBotsSkills.stage(from, fromThreadId, received, () => appliesDirectly(from.id, fromThreadId), (asked) => importedSkillRequest(asked, fetch, callSignal, () => skillImportToken(gitAudience(fromThreadId))), () => internalCapabilityIsActive(internalCapability) && skillAuthoringEnabled(cfg), () => (CLOUD_TEAM ? actingPeople.requester(fromThreadId, internalCapability.generation) : null)); if (everywhere) return json(res, everywhere.status, everywhere.body); if (isSkillSwitchAction(received.action)) { const staged = skillSwitch.stage(from, fromThreadId, received.action, received, appliesDirectly(from.id, fromThreadId)); return json(res, staged.status, staged.body); }
+ const body = await importedSkillRequest(received, fetch, callSignal, () => skillImportToken(gitAudience(fromThreadId))); if ("importError" in body) return json(res, 422, { error: body.importError }); if (!internalCapabilityIsActive(internalCapability)) return json(res, 401, { error: TURN_ENDED_REFUSAL }); if (!skillAuthoringEnabled(cfg)) return json(res, 403, { error: "skill authoring is not enabled in Settings" });
const direct = appliesDirectly(from.id, fromThreadId);
const persistence = skillProposalPersistence(from.id, fromThreadId, !direct);
if (!persistence.ok) return json(res, persistence.status, { error: persistence.error });
diff --cc server/routes/bot-skills.test.ts
index 35f1b7dda2,acd1158303..f837cd820b
--- a/server/routes/bot-skills.test.ts
+++ b/server/routes/bot-skills.test.ts
@@@ -5,11 -5,14 +5,14 @@@ import { dirname, join } from "node:pat
import { afterEach, describe, expect, it, vi } from "vitest";
import { DATA_DIR, type AppConfig } from "../config.ts";
+ import { provideGithubSignIn } from "../github/token.ts";
import { json, readBody } from "../harness/http.ts";
+ import { personKey } from "../person-key.ts";
import type { RequestAuth } from "../request-auth.ts";
+ import type { SessionRecord } from "../sessions.ts";
import { installLibrarySkill, readLibrarySkillFile, setLibrarySkillEveryBot } from "../skill-library.ts";
import type { Store } from "../store.ts";
-import { installSkill, listSkills, resolveBotSkills } from "../skills.ts";
+import { installSkill, listSkills, readSkillFile, resolveBotSkills, skillsSystemPrompt } from "../skills.ts";
import { fakeGitHub } from "../testing/fake-github.ts";
import { workspaceDir } from "../workspace.ts";
import { createBotSkillsRoutes } from "./bot-skills.ts";
@@@ -28,9 -32,10 +32,10 @@@ async function serve(botId: string)
const routes = [createBotSkillsRoutes({
store,
cfg: {} as AppConfig,
- listBotSkills: () => [],
- readBotSkillFile: () => null,
+ listBotSkills: (bot) => listSkills(bot.id),
+ readBotSkillFile: (bot, name) => readSkillFile(bot.id, name),
stagedSkillListing: (staged) => staged,
+ team: false,
})];
const server = createServer(async (req, res) => {
const url = new URL(req.url ?? "/", "http://localhost");
diff --cc server/routes/bot-skills.ts
index e43ced15c0,b18216a7bf..8a496920ff
--- a/server/routes/bot-skills.ts
+++ b/server/routes/bot-skills.ts
@@@ -13,7 -13,7 +13,8 @@@ import
type SkillListing, type StagedSkillWrite,
} from "../skills.ts";
import type { BotRecord, Store } from "../store.ts";
+ import { githubAudience } from "./github-sign-in.ts";
+import { withAllBotsOffer } from "./skills-for-all-bots.ts";
import { PASS, type RouteHandler } from "./table.ts";
export interface BotSkillsRouteDeps {
@@@ -25,8 -26,8 +27,8 @@@
}
export function createBotSkillsRoutes(deps: BotSkillsRouteDeps): RouteHandler {
- const { store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing } = deps;
+ const { store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing, team } = deps;
- return async ({ req, res, url, path, method, auth, json, readBody }) => {
+ return async ({ req, res, url, path, method, json, readBody, auth }) => {
let m: RegExpMatchArray | null = null;
// Imports land DISABLED: a person enables one after reading SKILL.md and its scan warnings.
m = path.match(/^\/api\/bots\/([\w-]+)\/skill-template$/);
diff --cc server/skill-fetch.ts
index 0ffedd498f,c19421e5ea..c4f0a574be
--- a/server/skill-fetch.ts
+++ b/server/skill-fetch.ts
@@@ -2,7 -2,8 +2,8 @@@ import { createHash } from "node:crypto
import { z } from "zod";
import type { GitHubSkillOrigin, SkippedSkillFile } from "../shared/skill-import.ts";
-import { SKILL_FILE_MAX_BYTES } from "../shared/skill-md.ts";
+import { readSkillFrontmatter, SKILL_FILE_MAX_BYTES } from "../shared/skill-md.ts";
+ import { githubToken, reportGithubAuthFailure } from "./github/token.ts";
import { planSkillFolder, SKILL_FOLDER_LIMITS, type FolderEntry, type SkillFolderFile } from "./skill-folder.ts";
const API = "https://api.github.com";
@@@ -223,12 -299,12 +299,12 @@@ const passThrough = (error: unknown) =
const toSkillSlug = (name: string) =>
name.toLowerCase().replace(/[\s_]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
- async function skillNameFrom(entries: ContentEntry[], fetcher: typeof fetch): Promise<string | undefined> {
- const skillMd = entries.find((entry) => entry.type === "file" && entry.name === "SKILL.md" && entry.download_url);
+ async function skillNameFrom(snapshot: Snapshot, entries: ContentEntry[], fetcher: typeof fetch): Promise<string | undefined> {
+ const skillMd = entries.find((entry) => entry.type === "file" && entry.name === "SKILL.md");
if (!skillMd) return undefined;
try {
- const text = (await fetchBytes(skillMd.download_url!, fetcher)).toString("utf8");
+ const text = (await fetchBytes(`https://${RAW_HOST}/${snapshot.owner}/${snapshot.repo}/${snapshot.commit}/${encodePath(skillMd.path)}`, fetcher)).toString("utf8");
- return text.match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1]?.match(/^name:\s*(.+)$/m)?.[1]?.trim();
+ return readSkillFrontmatter(text)?.fields.name;
} catch (error) {
if (passThrough(error)) throw error;
return undefined;