@chatpanel/gateway 0.121.0 → 0.133.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native/darwin-arm64/chatpanel-apple-model +0 -0
- package/package.json +5 -4
- package/src/capabilities.js +1 -1
- package/src/capability-config.js +1 -0
- package/src/capability-proxy.js +1 -1
- package/src/configstore.js +1 -1
- package/src/egress.js +2 -2
- package/src/engine-tunings.js +1 -1
- package/src/gguf-meta.js +1 -0
- package/src/inference-engines.js +1 -1
- package/src/kb.js +2 -2
- package/src/llama-arch.js +1 -0
- package/src/llama-builds.js +1 -0
- package/src/model-pull.js +1 -1
- package/src/providers.js +1 -1
- package/src/router.js +1 -1
- package/src/runtime.js +6 -6
- package/src/server.js +26 -26
- package/src/transfer-rate.js +1 -0
- package/src/tts-remote.js +1 -1
- package/src/tts-voice-resolve.js +1 -1
- package/src/tts-voices.js +1 -1
- package/src/version.js +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const h=1e4,f=1e3;function S({total:u=0}={}){let t=[];return(a,{now:l=Date.now(),skipped:M=!1,total:s=u}={})=>{(M||t.length&&a<t.at(-1).bytes)&&(t=[]);const e=t.at(-1);for((!e||l-e.at>=1e3)&&t.push({at:l,bytes:a});t.length>2&&l-t[0].at>1e4;)t.shift();const r=t[0],o=(l-r.at)/1e3,n=o>=1?Math.max(0,(a-r.bytes)/o):null,c=n&&s>a?Math.round((s-a)/n):n&&s?0:null;return{rate:n===null?null:Math.round(n),etaS:c}}}export{S as transferRate};
|
package/src/tts-remote.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{secureFetch as k}from"./secure-fetch.js";import{redactSegments as w,segment as S}from"./redact.js";const
|
|
1
|
+
import{secureFetch as k}from"./secure-fetch.js";import{redactSegments as w,segment as S}from"./redact.js";import{primaryProvider as $}from"./capability-config.js";const _=["local","openai","elevenlabs"];function b(e){return _.includes(String(e||""))}function E(e={}){const r=e.tts||{},t=$(e.capabilities?.tts,"tts");if(t&&typeof t=="object"){if(t.provider==="embedded")return null;const n=t.adapter||"openai";if(t.url&&b(n)){const c=r.remote||{};return{kind:n,baseUrl:String(t.url).replace(/\/+$/,""),model:t.model||c.model||(n==="elevenlabs"?"eleven_multilingual_v2":"tts-1"),voice:c.voice||(n==="elevenlabs"?"21m00Tcm4TlvDq8ikWAM":"alloy"),redact:t.redact!==!1,token:t.token||""}}}const i=r.provider||"local";if(i==="local"||!b(i))return null;const a=r.remote||{};return{kind:i,baseUrl:String(a.baseUrl||(i==="elevenlabs"?"https://api.elevenlabs.io/v1":"https://api.openai.com/v1")).replace(/\/+$/,""),model:a.model||(i==="elevenlabs"?"eleven_multilingual_v2":"tts-1"),voice:a.voice||(i==="elevenlabs"?"21m00Tcm4TlvDq8ikWAM":"alloy"),redact:a.redact!==!1}}function U(e){return/^[A-Za-z0-9_-]{1,64}$/.test(String(e||""))}async function V({dest:e,text:r,voice:t,speed:i=1,auth:a,redaction:n,isPro:c=!0,onEgress:h=null,fetchImpl:y=null}={}){const l=a||e?.token||"";if(!e)throw new Error("no remote TTS destination configured");const u=t||e.voice;if(!U(u))throw new Error(`invalid remote voice id: ${u}`);let m=String(r),v=0;if(e.redact&&n){const o={text:m},T=await w([S(()=>o.text,g=>{o.text=g})],n,{isPro:c,onEgress:h});m=o.text,v=T?.count||0}const x=y||k,d={"Content-Type":"application/json"};let p,f;if(e.kind==="elevenlabs"){p=`${e.baseUrl}/text-to-speech/${encodeURIComponent(u)}`,f={text:m,model_id:e.model};const o=B(l);o&&(d["xi-api-key"]=o)}else p=`${e.baseUrl}/audio/speech`,f={model:e.model,input:m,voice:u,response_format:"wav",speed:i},l&&(d.Authorization=l.startsWith("Bearer ")?l:`Bearer ${l}`);const s=await x(p,{method:"POST",headers:d,body:JSON.stringify(f)});if(!s.ok){let o=`HTTP ${s.status}`;try{o=(await s.text()).slice(0,300)||o}catch{}throw new Error(`remote tts failed: ${o}`)}return{audio:Buffer.from(await s.arrayBuffer()),contentType:s.headers.get("content-type")||"audio/mpeg",redacted:v}}function B(e){const r=String(e||"").trim();return r.toLowerCase().startsWith("bearer ")?r.slice(7).trim():r}export{_ as TTS_PROVIDERS,U as isValidRemoteVoice,b as isValidTtsProvider,V as synthesizeRemote,E as ttsDestination};
|
package/src/tts-voice-resolve.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function v({requested:c=null,configured:d,engine:
|
|
1
|
+
function v({requested:c=null,configured:d,engine:n,voices:s,isPocketVoice:r,isKnownVoice:k,isValidVoiceId:m,defaultVoice:p,defaultPocketVoice:a}){const t=c||d,o=n.isPocket();let e=s.parseCustomVoice(t);if(o&&r(t))return{ok:!0,voice:t,customId:null,speakerEmbedding:null};if(n.supportsCustomVoices()){let u=e?s.getVoice(e):null;if(!u&&!c){if(o)return{ok:!0,voice:a,customId:null,speakerEmbedding:null};const l=s.listVoices();l.length&&(e=l[0].id,u=s.getVoice(e))}if(!u)return e?{ok:!1,status:404,type:"bad_voice",message:"no such saved voice"}:{ok:!1,status:400,type:"bad_voice",message:"this model speaks in a voice you record — add one in Settings → Text-to-speech"};let i;if(o){if(i=s.getPocketVoice(e),!i)return{ok:!1,status:409,type:"voice_kind_missing",message:"this voice was saved without a Pocket TTS conditioning — record it again with Pocket TTS selected"}}else if(i=u.vec,!i?.length)return{ok:!1,status:409,type:"voice_kind_missing",message:"this voice was saved for Pocket TTS only — select Pocket TTS to speak in it"};return{ok:!0,voice:`custom:${e}`,customId:e,speakerEmbedding:i}}return e?c?{ok:!1,status:409,type:"voice_unsupported",message:`the active model (${n.arch()}) cannot use a recorded voice — switch to SpeechT5`}:{ok:!0,voice:p,customId:null,speakerEmbedding:null}:o&&!r(t)?{ok:!0,voice:a,customId:null,speakerEmbedding:null}:n.supportsVoices()&&!o&&!(k(t)&&m(t))?{ok:!1,status:400,type:"bad_voice",message:"unknown or invalid voice"}:{ok:!0,voice:t,customId:null,speakerEmbedding:null}}export{v as resolveTtsVoice};
|
package/src/tts-voices.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as S,mkdirSync as O,readFileSync as A,writeFileSync as s,readdirSync as b,rmSync as y}from"node:fs";import{join as l}from"node:path";import{randomUUID as E}from"node:crypto";import N from"node:os";const T=512,V="wavlm-512",F="pocket-mimi",g=20,v=60;function d(){return process.env.CHATPANEL_TTS_VOICES||l(N.homedir(),".chatpanel","tts-voices")}function p(e){return/^[A-Za-z0-9_-]{1,64}$/.test(String(e||""))}function M(e){const n=String(e||"");if(!n.startsWith("custom:"))return null;const t=n.slice(7);return p(t)?t:null}function u(e){return l(d(),`${e}.json`)}function D(){const e=d();if(!S(e))return[];const n=[];for(const t of b(e))if(t.endsWith(".json"))try{const r=JSON.parse(A(l(e,t),"utf8"));r?.id&&r?.name&&n.push({id:r.id,name:r.name,createdAt:r.createdAt||0,updatedAt:r.updatedAt||0,dim:r.vec?.length||0,kinds:i(r)})}catch{}return n.sort((t,r)=>r.createdAt-t.createdAt)}function f(e){return l(d(),`${e}.pocket.bin`)}function m(e){if(!p(e))return null;try{const n=JSON.parse(A(u(e),"utf8"));return i(n).length?n:null}catch{return null}}function J(e){if(!p(e))return null;const n=m(e);if(!n?.pocketShape)return null;try{const t=A(f(e));return{data:new Float32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),shape:n.pocketShape}}catch{return null}}const x=e=>!!e&&e.length===T,i=e=>[...x(e?.vec)?[V]:[],...e?.pocketShape?[F]:[]];function K(e){const n=m(e);return n?i(n):[]}function w(e,n){const t=x(e),r=!!(n?.data?.length&&Array.isArray(n.shape));if(!t&&!r)throw new Error(P);return{t5:t,hasPocket:r}}const P="no voice engine here can use this recording — Pocket TTS is not installed, and SpeechT5 needs the wavlm speaker model (512 values); install Pocket TTS in Settings → Text-to-speech";function L({name:e,vec:n=null,pocket:t=null}){const r=String(e||"").trim().slice(0,v);if(!r)throw new Error("a name is required");const{t5:h}=w(n,t);if(D().length>=g)throw new Error(`at most ${g} saved voices — delete one first`);const a=d();O(a,{recursive:!0});const o={id:E(),name:r,createdAt:Date.now(),...h?{vec:Array.from(n,c=>Number(c)||0)}:{}};if(t?.data?.length&&Array.isArray(t.shape)){o.pocketShape=t.shape;const c=t.data instanceof Float32Array?t.data:Float32Array.from(t.data);s(f(o.id),Buffer.from(c.buffer,c.byteOffset,c.byteLength))}return s(u(o.id),JSON.stringify(o)),{id:o.id,name:o.name,createdAt:o.createdAt,dim:o.vec?.length||0,kinds:i(o)}}function $(e,n){const t=m(e);if(!t)return null;const r=String(n||"").trim().slice(0,v);if(!r)throw new Error("a name is required");return t.name=r,t.updatedAt=Date.now(),s(u(e),JSON.stringify(t)),{id:e,name:t.name,createdAt:t.createdAt||0,updatedAt:t.updatedAt,dim:t.vec?.length||0,kinds:i(t)}}function j(e,{vec:n=null,pocket:t=null}){const r=m(e);if(!r)return null;const{t5:h}=w(n,t);if(h?r.vec=Array.from(n,a=>Number(a)||0):delete r.vec,r.updatedAt=Date.now(),t?.data?.length&&Array.isArray(t.shape)){r.pocketShape=t.shape;const a=t.data instanceof Float32Array?t.data:Float32Array.from(t.data);s(f(e),Buffer.from(a.buffer,a.byteOffset,a.byteLength))}else r.pocketShape&&(delete r.pocketShape,y(f(e),{force:!0}));return s(u(e),JSON.stringify(r)),{id:e,name:r.name,createdAt:r.createdAt||0,updatedAt:r.updatedAt,dim:r.vec?.length||0,kinds:i(r)}}function B(e){if(!p(e))return!1;const n=u(e);return S(n)?(y(n,{force:!0}),y(f(e),{force:!0}),!0):!1}export{T as EMBED_DIM,F as KIND_POCKET,V as KIND_SPEECHT5,P as NO_PRINT,B as deleteVoice,J as getPocketVoice,m as getVoice,x as isSpeechT5Print,p as isValidVoiceRef,D as listVoices,M as parseCustomVoice,$ as renameVoice,j as replaceVoice,L as saveVoice,K as voiceKinds,d as voicesDir};
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.
|
|
1
|
+
const o="0.133.3";export{o as VERSION};
|