import{Rt as e}from"./paths-C_0oH85Z.js";import{oc as t}from"./model-auth-BFP3sjhH.js";import n from"node:fs/promises";var r=class extends Error{constructor(e){super(e),this.status=400,this.name=`ToolInputError`}},i=class extends r{constructor(e){super(e),this.status=403,this.name=`ToolAuthorizationError`}};function a(e){return(t,n=!0)=>{let r=e?.[t];return r===void 0?n:r!==!1}}function o(e){return e.replace(/([A-Z]+)([A-Z][a-z])/g,`$1_$2`).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase()}function s(e,t){if(Object.hasOwn(e,t))return e[t];let n=o(t);if(n!==t&&Object.hasOwn(e,n))return e[n]}function c(e,t,n={}){let{required:i=!1,trim:a=!0,label:o=t,allowEmpty:c=!1}=n,l=s(e,t);if(typeof l!=`string`){if(i)throw new r(`${o} required`);return}let u=a?l.trim():l;if(!u&&!c){if(i)throw new r(`${o} required`);return}return u}function l(e,t,n={}){let{required:i=!1,label:a=t}=n,o=s(e,t);if(typeof o==`number`&&Number.isFinite(o))return String(o);if(typeof o==`string`){let e=o.trim();if(e)return e}if(i)throw new r(`${a} required`)}function u(e,t,n={}){let{required:i=!1,label:a=t,integer:o=!1,strict:c=!1}=n,l=s(e,t),u;if(typeof l==`number`&&Number.isFinite(l))u=l;else if(typeof l==`string`){let e=l.trim();if(e){let t=c?Number(e):Number.parseFloat(e);Number.isFinite(t)&&(u=t)}}if(u===void 0){if(i)throw new r(`${a} required`);return}return o?Math.trunc(u):u}function d(e,t,n={}){let{required:i=!1,label:a=t}=n,o=s(e,t);if(Array.isArray(o)){let e=o.filter(e=>typeof e==`string`).map(e=>e.trim()).filter(Boolean);if(e.length===0){if(i)throw new r(`${a} required`);return}return e}if(typeof o==`string`){let e=o.trim();if(!e){if(i)throw new r(`${a} required`);return}return[e]}if(i)throw new r(`${a} required`)}function f(e,t){let n=t.emojiKey??`emoji`,i=t.removeKey??`remove`,a=typeof e[i]==`boolean`?e[i]:!1,o=c(e,n,{required:!0,allowEmpty:!0});if(a&&!o)throw new r(t.removeErrorMessage);return{emoji:o,remove:a,isEmpty:!o}}function p(e){return{content:[{type:`text`,text:JSON.stringify(e,null,2)}],details:e}}async function m(e){return await t({content:[{type:`text`,text:e.extraText??`MEDIA:${e.path}`},{type:`image`,data:e.base64,mimeType:e.mimeType}],details:{path:e.path,...e.details}},e.label,e.imageSanitization)}async function h(t){let r=await n.readFile(t.path),i=await e({buffer:r.slice(0,256)})??`image/png`;return await m({label:t.label,path:t.path,base64:r.toString(`base64`),mimeType:i,extraText:t.extraText,details:t.details,imageSanitization:t.imageSanitization})}function g(e){if(e==null||!Array.isArray(e))return;let t=e.filter(e=>typeof e==`object`&&!!e&&typeof e.name==`string`).map(e=>({...e.id!==void 0&&typeof e.id==`string`?{id:e.id}:{},name:e.name,...typeof e.moderated==`boolean`?{moderated:e.moderated}:{},...e.emoji_id===null||typeof e.emoji_id==`string`?{emoji_id:e.emoji_id}:{},...e.emoji_name===null||typeof e.emoji_name==`string`?{emoji_name:e.emoji_name}:{}}));return t.length?t:void 0}function _(e,t){return`Delivering to ${e} requires target${C(t)}`}function v(e,t){return Error(_(e,t))}function y(e,t,n){return`Ambiguous target "${t}" for ${e}. Provide a unique name or an explicit id.${C(n,!0)}`}function b(e,t,n){return Error(y(e,t,n))}function x(e,t,n){return`Unknown target "${t}" for ${e}.${C(n,!0)}`}function S(e,t,n){return Error(x(e,t,n))}function C(e,t=!1){return e?t?` Hint: ${e}`:` ${e}`:``}export{r as a,h as c,u as d,f,c as h,i,p as l,l as m,v as n,a as o,d as p,S as r,m as s,b as t,g as u};
