UNPKG

eve

Version:

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

1 lines 2.89 kB
import{array,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 LINEAR_TRIGGER_PATH=`/eve/v1/linear`,LinearConnectorRefSchema=object({id:string().min(1),uid:string().min(1),supportedSubjectTypes:array(string()).refine(e=>e.includes(`app`))});function parseCreatedLinearConnector(e){try{let t=LinearConnectorRefSchema.safeParse(JSON.parse(e));return t.success?{id:t.data.id,uid:t.data.uid}:void 0}catch{return}}async function findLinearConnector(e){let t=await(e.deps??{runVercel,runVercelCaptureStdout}).runVercelCaptureStdout([`connect`,`list`,`--all-projects`,`--service`,`linear`,`-F`,`json`,`--scope`,e.project.orgId],{cwd:e.projectRoot,nonInteractive:!0,signal:e.signal});if(t.ok)try{let n=JSON.parse(t.stdout);if(!Array.isArray(n.connectors))return;let r=`linear/${e.slug}`,i=n.connectors.find(e=>typeof e==`object`&&!!e&&e.uid===r);return typeof i?.id==`string`?{id:i.id,uid:r}:void 0}catch{return}}async function attachLinearConnector(e){let t=e.deps??{runVercel,runVercelCaptureStdout},n=createPromptCommandOutput(e.log),r=await withPhase(e.log,`Connecting Linear Agent Sessions...`,()=>replaceConnectTrigger({connectorUid:e.connector.uid,projectRoot:e.projectRoot,projectId:e.project.projectId,orgId:e.project.orgId,environment:`production`,triggerPath:LINEAR_TRIGGER_PATH,onOutput:n,signal:e.signal,deps:t}));if(e.signal?.throwIfAborted(),r.state!==`attached`)throw Error(`Linear connector was found, but its trigger could not be attached. Run \`vercel connect attach ${e.connector.uid} --project ${e.project.projectId} --environment production --triggers --trigger-path ${LINEAR_TRIGGER_PATH} --yes --scope ${e.project.orgId}\`.`)}async function provisionLinearConnector(e){let t=e.deps??{runVercel,runVercelCaptureStdout},n=createPromptCommandOutput(e.log),r=await withPhase(e.log,`Creating Linear connector...`,()=>t.runVercelCaptureStdout([`connect`,`create`,`linear`,`--name`,e.slug,`--triggers`,`--trigger-event`,`AgentSessionEvent`,`-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?`Linear connector creation failed:\n${e}`:`Linear connector creation failed.`)}let i=parseCreatedLinearConnector(r.stdout);if(i===void 0)throw Error(`Vercel returned an invalid Linear connector.`);return await attachLinearConnector({...e,connector:i,deps:t}),i}export{LINEAR_TRIGGER_PATH,attachLinearConnector,findLinearConnector,parseCreatedLinearConnector,provisionLinearConnector};