UNPKG

eve

Version:

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

1 lines 835 B
import{z}from"#compiled/zod/index.js";import{EVE_ACTIVITY_ROUTE_PATTERN}from"#protocol/routes.js";import{isReservedIpAddress}from"#shared/network-address.js";const schema=z.object({url:z.string().min(1),version:z.literal(1)}).strict();function parseActivitySink(e){if(e===void 0)return;let t=schema.safeParse(e);if(!t.success)throw Error(`Expected activitySink version 1.`);let n;try{n=new URL(t.data.url)}catch{throw Error(`Activity sink url must be absolute.`)}let r=EVE_ACTIVITY_ROUTE_PATTERN.slice(0,-6),i=n.pathname.slice(n.pathname.lastIndexOf(r)+r.length);if(n.pathname.lastIndexOf(r)<0||i.length<32)throw Error(`Activity sink url must contain an opaque activity token.`);if(isReservedIpAddress(n.hostname))throw Error(`Activity sink url host must not be a private or reserved address.`);return t.data}export{parseActivitySink};