UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 3.01 kB
import{array,literal,object,string}from"../../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/schemas.js";import"../../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/index.js";import{runVercel,runVercelCaptureStdout}from"#setup/primitives/run-vercel.js";import{createPromptCommandOutput,withPhase}from"#setup/cli/index.js";import{replaceConnectTrigger}from"#setup/connect-provisioning.js";const GITHUB_TRIGGER_PATH=`/eve/v1/github`,GitHubConnectorRefSchema=object({id:string().min(1),uid:string().min(1),supportedSubjectTypes:array(string()).refine(e=>e.includes(`app`))}),GitHubConnectorDetailsSchema=object({data:object({appSlug:string().min(1)}),id:string().min(1),type:literal(`github`),uid:string().min(1)});function parseCreatedGitHubConnector(e){try{let t=GitHubConnectorRefSchema.safeParse(JSON.parse(e));return t.success?{id:t.data.id,uid:t.data.uid}:void 0}catch{return}}function parseGitHubConnectorDetails(e,t){try{let n=GitHubConnectorDetailsSchema.safeParse(JSON.parse(e));return!n.success||n.data.id!==t.id||n.data.uid!==t.uid?void 0:{...t,appSlug:n.data.data.appSlug}}catch{return}}async function provisionGitHubConnector(e){let t=e.deps??{runVercel,runVercelCaptureStdout},n=createPromptCommandOutput(e.log),r=await withPhase(e.log,`Creating GitHub connector...`,()=>t.runVercelCaptureStdout([`connect`,`create`,`github`,`--name`,e.slug,`--triggers`,...e.events.flatMap(e=>[`--trigger-event`,e]),`-F`,`json`,`--scope`,e.project.orgId],{cwd:e.projectRoot,nonInteractive:!0,onOutput:n,signal:e.signal}));if(e.signal?.throwIfAborted(),!r.ok){let e=[r.stderr,r.stdout].find(e=>e!==void 0&&e.trim().length>0);throw Error(e?`GitHub connector creation failed:\n${e}`:`GitHub connector creation failed.`)}let i=parseCreatedGitHubConnector(r.stdout);if(i===void 0)throw Error(`Vercel returned an invalid GitHub connector.`);let a=await withPhase(e.log,`Reading GitHub App details...`,()=>t.runVercelCaptureStdout([`api`,`/v1/connect/connectors/${encodeURIComponent(i.id)}`,`--scope`,e.project.orgId,`--raw`],{cwd:e.projectRoot,nonInteractive:!0,onOutput:n,signal:e.signal}));if(e.signal?.throwIfAborted(),!a.ok)throw Error(`Could not read the created GitHub connector.`);let o=parseGitHubConnectorDetails(a.stdout,i);if(o===void 0)throw Error(`Vercel returned invalid details for the GitHub connector.`);let s=await withPhase(e.log,`Connecting GitHub webhooks...`,()=>replaceConnectTrigger({connectorUid:o.uid,projectRoot:e.projectRoot,projectId:e.project.projectId,orgId:e.project.orgId,environment:`production`,triggerPath:GITHUB_TRIGGER_PATH,onOutput:n,signal:e.signal,deps:t}));if(e.signal?.throwIfAborted(),s.state!==`attached`)throw Error(`GitHub connector was created, but its trigger could not be attached. Run \`vercel connect attach ${o.uid} --project ${e.project.projectId} --environment production --triggers --trigger-path ${GITHUB_TRIGGER_PATH} --yes --scope ${e.project.orgId}\`.`);return o}export{GITHUB_TRIGGER_PATH,parseCreatedGitHubConnector,provisionGitHubConnector};