UNPKG

agents

Version:

A home for your AI agents

46 lines (45 loc) • 1.53 kB
//#region src/experimental/channels/internal.ts const textEncoder = new TextEncoder(); function encodeUtf8(value) { return textEncoder.encode(value); } function utf8ByteLength(value) { return encodeUtf8(value).byteLength; } function isRecord(value) { return value !== null && typeof value === "object" && !Array.isArray(value); } function emptyIngressResponse(status = 200) { return { events: [], response: new Response(null, { status }) }; } function unsupported(code, message) { return { status: "failed", retryable: false, error: { code, message } }; } /** The agent object of a participant's own, namespaced so app routes cannot collide. */ function participantRoute(participant) { return `participant:${participant.id}`; } /** Check what an application's `participant` callback returned. */ function toParticipant(result, source) { if (result === null) return null; if (typeof result === "string") { if (result.length > 0) return { id: result }; } else if (isRecord(result) && typeof result.id === "string" && result.id.length > 0 && (result.name === void 0 || typeof result.name === "string")) return result.name === void 0 ? { id: result.id } : { id: result.id, name: result.name }; throw new Error(`${source} participant must return a non-empty id, a participant, or null`); } //#endregion export { toParticipant as a, participantRoute as i, encodeUtf8 as n, unsupported as o, isRecord as r, utf8ByteLength as s, emptyIngressResponse as t }; //# sourceMappingURL=internal-kmw70xwR.js.map