eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.8 kB
JavaScript
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 PHOTON_CONNECT_SERVICE=`photon`,PHOTON_CONNECTOR_TYPE=`photon`,PHOTON_TRIGGER_PATH=`/eve/v1/photon`,PhotonConnectorRefSchema=object({id:string().min(1),uid:string().min(1),supportedSubjectTypes:array(string()).refine(e=>e.includes(`app`))});function parseCreatedPhotonConnector(e){try{let t=PhotonConnectorRefSchema.safeParse(JSON.parse(e));return t.success?{id:t.data.id,uid:t.data.uid}:void 0}catch{return}}function createData(e){return JSON.stringify({projectId:e.projectId.trim(),projectSecret:e.projectSecret.trim()})}function requireCreatedConnector(e){if(!e.ok){let t=[e.stderr,e.stdout].map(e=>e?.trim()).find(e=>e!==void 0&&e.length>0);throw Error(t?`Photon connector creation failed:\n${t}`:`Photon connector creation failed.`)}let t=parseCreatedPhotonConnector(e.stdout);if(t===void 0)throw Error(`Vercel returned an invalid Photon connector after creation.`);return t}async function provisionPhotonConnector(e){let t=e.deps??{runVercel,runVercelCaptureStdout},n=createPromptCommandOutput(e.log),r=await withPhase(e.log,`Creating Photon connector...`,()=>t.runVercelCaptureStdout([`connect`,`create`,PHOTON_CONNECT_SERVICE,`--connector-type`,PHOTON_CONNECTOR_TYPE,`--data`,`@-`,`--name`,e.slug,`--triggers`,`-F`,`json`,`--scope`,e.project.orgId],{cwd:e.projectRoot,nonInteractive:!0,onOutput:n,signal:e.signal,stdin:createData(e.credentials)}));e.signal?.throwIfAborted();let i=requireCreatedConnector(r),a=await withPhase(e.log,`Connecting Photon credentials...`,()=>replaceConnectTrigger({connectorUid:i.uid,projectRoot:e.projectRoot,projectId:e.project.projectId,orgId:e.project.orgId,environment:`production`,triggerPath:PHOTON_TRIGGER_PATH,onOutput:n,signal:e.signal,deps:t}));if(e.signal?.throwIfAborted(),a.state!==`attached`){let t=`vercel connect attach ${i.uid} --project ${e.project.projectId} --environment production --triggers --trigger-path ${PHOTON_TRIGGER_PATH} --yes --scope ${e.project.orgId}`;throw Error(a.state===`detach-failed`?`Photon connector was created, but its default trigger destination could not be removed. Run \`vercel connect detach ${i.uid} --project ${e.project.projectId} --yes --scope ${e.project.orgId}\`, then \`${t}\`.`:`Photon connector was created, but its credentials could not be attached. Run \`${t}\`.`)}return i}export{PHOTON_CONNECTOR_TYPE,PHOTON_CONNECT_SERVICE,PHOTON_TRIGGER_PATH,parseCreatedPhotonConnector,provisionPhotonConnector};