@lunora/svelte 1.0.0-alpha.65 → 1.0.0-alpha.67
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/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/agentChat-BmvA3u8B.mjs +1 -0
- package/dist/packem_shared/flag-5trRaaSv.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-s_5r8MQZ.mjs +1 -0
- package/dist/packem_shared/{voiceAgent-D-82ai_D.mjs → voiceAgent-CPQvbrxT.mjs} +1 -1
- package/package.json +5 -5
- package/dist/packem_shared/agentChat-DKfx2E6R.mjs +0 -1
- package/dist/packem_shared/flag-kAz4soTW.mjs +0 -1
- package/dist/packem_shared/infiniteQuery-Cqxcrhn9.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -325,7 +325,7 @@ interface AgentStateHandle<T> {
|
|
|
325
325
|
* `state` updates only on a real `setState`. The Svelte counterpart to React's
|
|
326
326
|
* `useAgentState`, re-expressed as stores you read with `$`.
|
|
327
327
|
*
|
|
328
|
-
* Generic over the app's state shape (`agentState
|
|
328
|
+
* Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
|
|
329
329
|
* record) — the reference is typed as an optional record because codegen cannot
|
|
330
330
|
* see the per-agent state type; the generic casts to `T`. The `state`/`error`
|
|
331
331
|
* stores are lazy, so the subscription opens on the first subscriber to `state`
|
|
@@ -762,7 +762,7 @@ interface PresenceHandle<L extends ListPresentReference> {
|
|
|
762
762
|
* Open a live presence handle.
|
|
763
763
|
*
|
|
764
764
|
* Pass `client` explicitly, or omit it to resolve the ambient client from the
|
|
765
|
-
* Svelte context (requires calling inside a component's
|
|
765
|
+
* Svelte context (requires calling inside a component's `<script>` block or
|
|
766
766
|
* inside a function called during component initialisation).
|
|
767
767
|
*
|
|
768
768
|
* Teardown (stop heartbeats, remove the visibility listener, release the
|
|
@@ -964,9 +964,9 @@ type CreateSpeaker = (config: {
|
|
|
964
964
|
audioFormat: VoiceAudioFormat;
|
|
965
965
|
}) => VoiceSpeaker;
|
|
966
966
|
/**
|
|
967
|
-
* The `agents
|
|
967
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
968
968
|
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
969
|
-
* generated member, so passing `api.agents
|
|
969
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
970
970
|
*/
|
|
971
971
|
type VoiceReference = FunctionReference<"stream", {
|
|
972
972
|
threadKey: string;
|
|
@@ -1008,7 +1008,7 @@ interface VoiceAgentOptions {
|
|
|
1008
1008
|
silenceThreshold?: number;
|
|
1009
1009
|
/** The thread to converse on — shared with the agent's text turns. */
|
|
1010
1010
|
threadKey: string;
|
|
1011
|
-
/** The generated `api.agents
|
|
1011
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
1012
1012
|
voice: VoiceReference;
|
|
1013
1013
|
}
|
|
1014
1014
|
interface VoiceAgentHandle {
|
|
@@ -1041,7 +1041,7 @@ interface VoiceAgentHandle {
|
|
|
1041
1041
|
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1042
1042
|
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1043
1043
|
* `audioLevel`) to Svelte readable stores you read with `$`. Pass the generated
|
|
1044
|
-
* `api.agents
|
|
1044
|
+
* `api.agents.<name>Voice` reference (never a string), matching `agentChat`'s
|
|
1045
1045
|
* reference-passing style. The Svelte counterpart to React's `useVoiceAgent`,
|
|
1046
1046
|
* re-expressed as stores; the per-call connection lives in a closure variable (a
|
|
1047
1047
|
* handle is created once per component, so no store-of-store indirection is
|
package/dist/index.d.ts
CHANGED
|
@@ -325,7 +325,7 @@ interface AgentStateHandle<T> {
|
|
|
325
325
|
* `state` updates only on a real `setState`. The Svelte counterpart to React's
|
|
326
326
|
* `useAgentState`, re-expressed as stores you read with `$`.
|
|
327
327
|
*
|
|
328
|
-
* Generic over the app's state shape (`agentState
|
|
328
|
+
* Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
|
|
329
329
|
* record) — the reference is typed as an optional record because codegen cannot
|
|
330
330
|
* see the per-agent state type; the generic casts to `T`. The `state`/`error`
|
|
331
331
|
* stores are lazy, so the subscription opens on the first subscriber to `state`
|
|
@@ -762,7 +762,7 @@ interface PresenceHandle<L extends ListPresentReference> {
|
|
|
762
762
|
* Open a live presence handle.
|
|
763
763
|
*
|
|
764
764
|
* Pass `client` explicitly, or omit it to resolve the ambient client from the
|
|
765
|
-
* Svelte context (requires calling inside a component's
|
|
765
|
+
* Svelte context (requires calling inside a component's `<script>` block or
|
|
766
766
|
* inside a function called during component initialisation).
|
|
767
767
|
*
|
|
768
768
|
* Teardown (stop heartbeats, remove the visibility listener, release the
|
|
@@ -964,9 +964,9 @@ type CreateSpeaker = (config: {
|
|
|
964
964
|
audioFormat: VoiceAudioFormat;
|
|
965
965
|
}) => VoiceSpeaker;
|
|
966
966
|
/**
|
|
967
|
-
* The `agents
|
|
967
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
968
968
|
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
969
|
-
* generated member, so passing `api.agents
|
|
969
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
970
970
|
*/
|
|
971
971
|
type VoiceReference = FunctionReference<"stream", {
|
|
972
972
|
threadKey: string;
|
|
@@ -1008,7 +1008,7 @@ interface VoiceAgentOptions {
|
|
|
1008
1008
|
silenceThreshold?: number;
|
|
1009
1009
|
/** The thread to converse on — shared with the agent's text turns. */
|
|
1010
1010
|
threadKey: string;
|
|
1011
|
-
/** The generated `api.agents
|
|
1011
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
1012
1012
|
voice: VoiceReference;
|
|
1013
1013
|
}
|
|
1014
1014
|
interface VoiceAgentHandle {
|
|
@@ -1041,7 +1041,7 @@ interface VoiceAgentHandle {
|
|
|
1041
1041
|
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1042
1042
|
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1043
1043
|
* `audioLevel`) to Svelte readable stores you read with `$`. Pass the generated
|
|
1044
|
-
* `api.agents
|
|
1044
|
+
* `api.agents.<name>Voice` reference (never a string), matching `agentChat`'s
|
|
1045
1045
|
* reference-passing style. The Svelte counterpart to React's `useVoiceAgent`,
|
|
1046
1046
|
* re-expressed as stores; the per-call connection lives in a closure variable (a
|
|
1047
1047
|
* handle is created once per component, so no store-of-store indirection is
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{agent as o}from"./packem_shared/agent-CddTbgxO.mjs";import{agentChat as a}from"./packem_shared/agentChat-
|
|
1
|
+
import{agent as o}from"./packem_shared/agent-CddTbgxO.mjs";import{agentChat as a}from"./packem_shared/agentChat-BmvA3u8B.mjs";import{agentState as f}from"./packem_shared/agentState-fc7KRCp9.mjs";import{agentToolEvents as n}from"./packem_shared/agentToolEvents-sOUvSZsy.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BWCPnv0n.mjs";import{connectionStatus as s}from"./packem_shared/connectionStatus-BHVAskxU.mjs";import{getLunoraClient as c,setLunoraClient as d}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as y,flags as C}from"./packem_shared/flag-5trRaaSv.mjs";import{hydratePreloaded as v}from"./packem_shared/hydratePreloaded-Bbm6vwbA.mjs";import{mutation as S}from"./packem_shared/mutation-fa0Bj5Bo.mjs";import{mutator as q}from"./packem_shared/mutator-cvH3UrNm.mjs";import{infiniteQuery as E,paginatedQuery as G}from"./packem_shared/infiniteQuery-s_5r8MQZ.mjs";import{presence as T}from"./packem_shared/presence-C2YC1KOc.mjs";import{query as k}from"./packem_shared/query-BEQBdOJ2.mjs";import{rateLimit as z}from"./packem_shared/rateLimit-DtykU7F_.mjs";import{stream as D}from"./packem_shared/stream-DItOnXt6.mjs";import{subscription as H}from"./packem_shared/subscription-Dbz9sy8N.mjs";import{voiceAgent as J}from"./packem_shared/voiceAgent-CPQvbrxT.mjs";export{o as agent,a as agentChat,f as agentState,n as agentToolEvents,i as auth,u as authGate,s as connectionStatus,y as flag,C as flags,c as getLunoraClient,v as hydratePreloaded,E as infiniteQuery,S as mutation,q as mutator,G as paginatedQuery,T as presence,k as query,z as rateLimit,d as setLunoraClient,D as stream,H as subscription,J as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as K,maxSeq as A}from"@lunora/client";import{writable as b}from"svelte/store";import{i as g}from"./is-browser-BEdfLJHK.mjs";import{isClient as Q,NO_MUTATION_REF as U}from"./agent-CddTbgxO.mjs";import{getLunoraClient as V}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-fa0Bj5Bo.mjs";import{stream as z}from"./stream-DItOnXt6.mjs";const G={__lunoraRef:""},J=(n,u)=>{const{api:r,cancel:m,limit:y,send:T,sendArgs:_,stream:f,threadKey:a}=u,j=h(n,T),q=h(n,m??U),O=h(n,r.agents.agentResolveApproval);let d,i=[],c=[],v=[],w=0;const l=b([]),k=b(),I=b(""),p=()=>{const t=K(c,i);if(t.length===0){l.set(i);return}const s=A(i);l.set([...i,...t.map((e,o)=>({content:e.content,optimistic:!0,role:"user",seq:s+1+o}))])},x=()=>{const t=i.filter(e=>e.role==="assistant").length,s=v.filter(e=>e.kind!=="progress"&&e.threadKey===a&&e.turn>=t).map(e=>e.text).join("");I.set(s)},R=f===void 0?"skip":{key:a},S=g()?z(n,f??G,R).chunks.subscribe(t=>{v=t,x()}):()=>{},E=y===void 0?{key:a}:{key:a,limit:y},N=g()?n.subscribe(r.agents.agentMessages,E,t=>{i=t,p(),x()}):()=>{},B=g()?n.subscribe(r.agents.agentThread,{key:a},t=>{d=t,k.set(d?.status)}):()=>{},D=async(t,s)=>{const e=w;w+=1;const o=A(i);c=[...K(c,i),{content:t,id:e,maxDurableSeqAtSend:o}],p();try{await j.mutate({input:t,threadKey:a,..._,...s})}catch(H){throw c=c.filter(P=>P.id!==e),p(),H}},C=async(t,s,e)=>{const o=d?.instanceId;if(o===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await O.mutate({decision:t,instanceId:o,threadKey:a,toolCallId:s,...e===void 0?{}:{note:e}})},F=async(t,s)=>C("approve",t,s),L=async(t,s)=>C("reject",t,s),M=async()=>{const t=d?.instanceId;m===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:a})},$=()=>{N(),B(),S()};return{approve:F,cancel:M,messages:{subscribe:l.subscribe},reject:L,send:D,status:{subscribe:k.subscribe},streamingText:{subscribe:I.subscribe},teardown:$}};function nt(n,u){const r=Q(n),m=r?n:V();return J(m,r?u:n)}export{nt as agentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as a}from"svelte/store";import{isClient as p}from"./agent-CddTbgxO.mjs";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";const g="__lunora_flags__:eval",y=r=>{const t=typeof r;return t==="boolean"||t==="number"||t==="string"?t:"object"},v={__lunoraRef:g},m=(r,t,e,n,o)=>{try{return r.subscribe(v,{context:n,default:e,key:t,type:y(e)},c=>{o(c)})}catch{return()=>{}}};function j(r,t,e,n){const o=p(r),c=o?r:b(),l=o?t:r,u=o?e:t,s=(o?n:e)??void 0;return a(u,f=>m(c,l,u,s,f))}function k(r,t,e){const n=p(r),o=n?r:b(),c=n?t:r,l=(n?e:t)??void 0;return a(c,u=>{let s={...c};const f=[];for(const[i,_]of Object.entries(c))f.push(m(o,i,_,l,d=>{s={...s,[i]:d},u(s)}));return()=>{for(const i of f)i()}})}export{j as flag,k as flags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as J,derivePaginationStatus as T,applyLoadMore as V,rebalance as q}from"@lunora/client/pagination";import{derived as S,writable as I,readable as G,get as k}from"svelte/store";import{getLunoraClient as Q}from"./getLunoraClient-DU7BmZy1.mjs";import{i as D}from"./is-function-reference-ByqJF30w.mjs";const H=(e,r)=>e<r?-1:e>r?1:0,F=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>F(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const s=e,b=Object.keys(s).toSorted(H),i=[];for(const t of b){const n=s[t];n!==void 0&&i.push(`${JSON.stringify(t)}:${F(n)}`)}return`{${i.join(",")}}`},E=e=>{let r="";for(let s=0;s<e.length;s+=32768)r+=String.fromCharCode(...e.subarray(s,s+32768));return btoa(r)},c="$lunora.wire$",K=64,X="__proto__",Y=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},M=(e,r=0)=>{if(r>K)throw new RangeError(`wire-codec: value nesting exceeds the ${K}-level limit`);if(e===void 0)return[c,"undefined"];if(e===null)return null;const s=typeof e;if(s==="bigint")return[c,"bigint",e.toString()];if(s==="number"){const t=e;return Number.isNaN(t)?[c,"nan"]:t===1/0?[c,"inf"]:t===-1/0?[c,"-inf"]:t}if(s!=="object")return e;if(e instanceof Date)return[c,"date",M(e.getTime(),r+1)];if(e instanceof Error){const t=e,n={};for(const a of Object.keys(t))t[a]!==void 0&&(n[a]=M(t[a],r+1));const o=[c,"error",t.name,t.message,n];return t.cause!==void 0&&o.push(M(t.cause,r+1)),o}if(e instanceof URL)return[c,"url",e.href];if(e instanceof Map)return[c,"map",[...e.entries()].map(([t,n])=>[M(t,r+1),M(n,r+1)])];if(e instanceof Set)return[c,"set",[...e].map(t=>M(t,r+1))];if(e instanceof ArrayBuffer)return[c,"bytes",E(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,n=t.constructor.name,o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return n==="Uint8Array"?[c,"bytes",E(o)]:[c,"bytes",E(o),n]}if(Array.isArray(e)){const t=e.map(n=>M(n,r+1));return t.length>0&&t[0]===c?[c,"arr",t]:t}if(!Y(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const b=e,i={};for(const t of Object.keys(b)){const n=b[t];if(n===void 0)continue;const o=M(n,r+1);t===X?Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):i[t]=o}return i},Z=e=>F(M(e)),A=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),L=(e,r)=>`${e}::${Z(r)}`,W=(e,r,s,b)=>{const{initialNumItems:i,shardKey:t}=b,n=I(J(i)),o=I([]),a=new Map,d=new Map,w=new Set,f=s,g=()=>{if(f==="skip"){o.set([]);return}const l=k(n).map(m=>{const v=L(r.__lunoraRef,A(m,f));return a.get(v)});o.set(l)},R=(l,m)=>{if(f==="skip")return;const v=u=>L(r.__lunoraRef,A(u,f));for(const u of m){const h=v(u);if(a.has(h))continue;const y=l.find(O=>O.lower===u.lower);if(y){const O=a.get(v(y));O&&a.set(h,O)}}},$=()=>{if(f==="skip"){for(const u of d.values())u();d.clear(),o.set([]);return}const l=f,m=k(n),v=new Set;for(const u of m)v.add(L(r.__lunoraRef,A(u,l)));for(const[u,h]of d)v.has(u)||(h(),d.delete(u),w.delete(u),a.delete(u));for(const u of m){const h=A(u,l),y=L(r.__lunoraRef,h);if(d.has(y))continue;w.add(y);const O=e.subscribe(r,h,x=>{if(a.set(y,x),w.delete(y),g(),w.size===0){const _=k(n),j=q(_,k(o));j&&(R(_,j),n.set(j),p(),g())}},{shardKey:t});d.set(y,O)}};let N=!1,P=!1;const p=()=>{if(N){P=!0;return}N=!0;try{do P=!1,$();while(P)}finally{N=!1}},C=()=>{for(const l of d.values())l();d.clear(),a.clear(),w.clear()},U=G([],l=>{const m=o.subscribe(l);return f!=="skip"&&(p(),g()),()=>{m(),C(),n.set(J(i)),o.set([])}}),z=S(U,l=>T(f==="skip",l).status);return{loadMore:l=>{if(f==="skip")return;const m=k(o),{nextCursor:v,status:u}=T(!1,m);if(u!=="CanLoadMore")return;const h=k(n),y=V(h,v,l);if(!y)return;const O=h.at(-1),x=y.at(-2);if(O&&x){const _=L(r.__lunoraRef,A(O,f)),j=L(r.__lunoraRef,A(x,f));if(_!==j){const B=a.get(_);B&&(a.set(j,B),a.delete(_))}}n.set(y),p(),g()},pageResults:U,status:z}};function oe(e,r,s,b){const i=!D(e),t=i?e:Q(),n=i?r:e,o=i?s:r,a=i?b:s,{loadMore:d,pageResults:w,status:f}=W(t,n,o,a),g=S(w,R=>R.flatMap($=>$?.page??[]));return{isLoading:S(f,R=>R==="LoadingFirstPage"||R==="LoadingMore"),loadMore:d,results:g,status:f}}function se(e,r,s,b){const i=!D(e),t=i?e:Q(),n=i?r:e,o=i?s:r,a=i?b:s,{initialNumItems:d}=a,{loadMore:w,pageResults:f,status:g}=W(t,n,o,a),R=S(f,p=>p.flatMap(C=>C?[C.page]:[])),$=S(g,p=>p==="LoadingFirstPage"),N=S(g,p=>p==="CanLoadMore"),P=S(g,p=>p==="LoadingMore");return{fetchNextPage:p=>{w(p??d)},hasNextPage:N,isFetchingNextPage:P,isLoading:$,pages:R,status:g}}export{se as infiniteQuery,oe as paginatedQuery};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{writable as w,get as L}from"svelte/store";import{isClient as R}from"./agent-CddTbgxO.mjs";import{getLunoraClient as W}from"./getLunoraClient-DU7BmZy1.mjs";const V=e=>{if(e.length===0)return 0;let o=0;for(const s of e)o+=s*s;return Math.sqrt(o/e.length)},B=(e,o)=>{const s=o/16e3,i=s>1?Math.floor(e.length/s):e.length,d=new ArrayBuffer(i*2),a=new DataView(d);for(let l=0;l<i;l+=1){const g=e[Math.floor(l*s)]??0,b=Math.max(-1,Math.min(1,g));a.setInt16(l*2,b<0?b*32768:b*32767,!0)}return new Uint8Array(d)},I=async e=>{const o=globalThis,s=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),i=o.AudioContext??o.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),a=new i,l=a.createMediaStreamSource(d),g=a.createScriptProcessor(4096,1,1);let b=!1,m=!1,f=0,n=0;return g.onaudioprocess=c=>{const p=c.inputBuffer.getChannelData(0),h=b?0:V(p);if(e.onLevel(h),b)return;if(e.onAudio(B(p,a.sampleRate)),e.isSpeaking()){n=h>=e.interruptThreshold?n+1:0,n>=e.interruptChunks&&(n=0,e.onInterrupt());return}n=0;const A=p.length/a.sampleRate*1e3;if(h>=e.silenceThreshold){m=!0,f=0;return}m&&(f+=A,f>=e.silenceDurationMs&&(m=!1,f=0,e.onSilence()))},l.connect(g),g.connect(a.destination),{setMuted:c=>{b=c},stop:()=>{g.disconnect(),l.disconnect();for(const c of d.getTracks())c.stop();a.close()}}},P=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new o,i=new Set;let d=0,a=Promise.resolve(),l=0;const g=async(f,n)=>{if(n!==l)return;let c;try{c=await s.decodeAudioData(f.buffer)}catch{return}if(n!==l)return;const p=s.createBufferSource();p.buffer=c,p.connect(s.destination);const h=Math.max(s.currentTime,d);p.start(h),d=h+c.duration,i.add(p),p.onended=()=>{i.delete(p)}},b=f=>{const n=Uint8Array.from(f),c=l;a=a.then(()=>g(n,c))},m=()=>{l+=1;for(const f of i)try{f.stop()}catch{}i.clear(),d=s.currentTime};return{enqueue:b,interrupt:m,stop:()=>{m(),s.close()}}},D=1,J=.01,K=1200,N=.15,O=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const o=e.__lunoraRef,s=o.startsWith("agents:")?o.slice(7):o;return s.endsWith("Voice")?s.slice(0,-5):s},H=(e,o,s)=>{const i=j(e),d=i.endsWith("/")?i.slice(0,-1):i,a=new URLSearchParams({threadKey:s});return`${d}/_lunora/voice/${encodeURIComponent(o)}?${a.toString()}`},G=(e,o)=>{const{createMicrophone:s=I,createSpeaker:i=P,createSocket:d,interruptChunks:a=O,interruptThreshold:l=N,silenceDurationMs:g=K,silenceThreshold:b=J,threadKey:m,voice:f}=o,n=w("idle"),c=w(!1),p=w(""),h=w(""),A=w(0),S=w(!1),v=w();let u,C=!1;const M=r=>{const t=u?.socket;return t?.readyState===D?(t.send(JSON.stringify(r)),!0):!1},x=()=>{const r=u;if(u=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}C=!1,c.set(!1),n.set("idle"),A.set(0)},U=
|
|
1
|
+
import{writable as w,get as L}from"svelte/store";import{isClient as R}from"./agent-CddTbgxO.mjs";import{getLunoraClient as W}from"./getLunoraClient-DU7BmZy1.mjs";const V=e=>{if(e.length===0)return 0;let o=0;for(const s of e)o+=s*s;return Math.sqrt(o/e.length)},B=(e,o)=>{const s=o/16e3,i=s>1?Math.floor(e.length/s):e.length,d=new ArrayBuffer(i*2),a=new DataView(d);for(let l=0;l<i;l+=1){const g=e[Math.floor(l*s)]??0,b=Math.max(-1,Math.min(1,g));a.setInt16(l*2,b<0?b*32768:b*32767,!0)}return new Uint8Array(d)},I=async e=>{const o=globalThis,s=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),i=o.AudioContext??o.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),a=new i,l=a.createMediaStreamSource(d),g=a.createScriptProcessor(4096,1,1);let b=!1,m=!1,f=0,n=0;return g.onaudioprocess=c=>{const p=c.inputBuffer.getChannelData(0),h=b?0:V(p);if(e.onLevel(h),b)return;if(e.onAudio(B(p,a.sampleRate)),e.isSpeaking()){n=h>=e.interruptThreshold?n+1:0,n>=e.interruptChunks&&(n=0,e.onInterrupt());return}n=0;const A=p.length/a.sampleRate*1e3;if(h>=e.silenceThreshold){m=!0,f=0;return}m&&(f+=A,f>=e.silenceDurationMs&&(m=!1,f=0,e.onSilence()))},l.connect(g),g.connect(a.destination),{setMuted:c=>{b=c},stop:()=>{g.disconnect(),l.disconnect();for(const c of d.getTracks())c.stop();a.close()}}},P=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new o,i=new Set;let d=0,a=Promise.resolve(),l=0;const g=async(f,n)=>{if(n!==l)return;let c;try{c=await s.decodeAudioData(f.buffer)}catch{return}if(n!==l)return;const p=s.createBufferSource();p.buffer=c,p.connect(s.destination);const h=Math.max(s.currentTime,d);p.start(h),d=h+c.duration,i.add(p),p.onended=()=>{i.delete(p)}},b=f=>{const n=Uint8Array.from(f),c=l;a=a.then(()=>g(n,c))},m=()=>{l+=1;for(const f of i)try{f.stop()}catch{}i.clear(),d=s.currentTime};return{enqueue:b,interrupt:m,stop:()=>{m(),s.close()}}},D=1,J=.01,K=1200,N=.15,O=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const o=e.__lunoraRef,s=o.startsWith("agents:")?o.slice(7):o;return s.endsWith("Voice")?s.slice(0,-5):s},H=(e,o,s)=>{const i=j(e),d=i.endsWith("/")?i.slice(0,-1):i,a=new URLSearchParams({threadKey:s});return`${d}/_lunora/voice/${encodeURIComponent(o)}?${a.toString()}`},G=(e,o)=>{const{createMicrophone:s=I,createSpeaker:i=P,createSocket:d,interruptChunks:a=O,interruptThreshold:l=N,silenceDurationMs:g=K,silenceThreshold:b=J,threadKey:m,voice:f}=o,n=w("idle"),c=w(!1),p=w(""),h=w(""),A=w(0),S=w(!1),v=w();let u,C=!1;const M=r=>{const t=u?.socket;return t?.readyState===D?(t.send(JSON.stringify(r)),!0):!1},x=()=>{const r=u;if(u=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}C=!1,c.set(!1),n.set("idle"),A.set(0)},U=x,$=r=>{const t=u;switch(r.type){case"assistant_delta":{t&&(t.speaking=!0),n.set("speaking"),h.update(y=>y+r.text);break}case"assistant_done":{t&&(t.speaking=!1),h.set(r.text),n.set("listening");break}case"error":{t&&(t.speaking=!1),v.set(new Error(r.message)),n.set("listening");break}case"interrupted":{t&&(t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),n.set("listening");break}case"ready":{t&&(t.audioFormat=r.audioFormat,t.suppressAudio=!1),c.set(!0),n.set("listening");break}case"user_transcript":{t&&(t.suppressAudio=!1),p.set(r.text),h.set(""),n.set("thinking");break}}},E=r=>{const t=u;!t||t.suppressAudio||(t.speaker??=i({audioFormat:t.audioFormat}),t.speaking=!0,n.set("speaking"),t.speaker.enqueue(r))},_=async()=>{if(!(u||C)){C=!0,v.set(void 0),p.set(""),h.set("");try{const r=H(e.url,z(f),m),t=(d??(k=>new globalThis.WebSocket(k)))(r);t.binaryType="arraybuffer";const y={audioFormat:"mp3",microphone:void 0,socket:t,speaker:void 0,speaking:!1,suppressAudio:!1};u=y,t.onmessage=k=>{if(typeof k.data=="string"){try{$(JSON.parse(k.data))}catch{}return}E(new Uint8Array(k.data))},t.onerror=()=>{v.set(new Error("voiceAgent: voice socket error"))},t.onclose=()=>{u===y&&x()};const T=await s({interruptChunks:a,interruptThreshold:l,isSpeaking:()=>u?.speaking??!1,onAudio:k=>{t.readyState===D&&t.send(k)},onInterrupt:()=>{M({type:"interrupt"}),u?.speaker?.interrupt(),u&&(u.speaking=!1,u.suppressAudio=!0),n.set("listening")},onLevel:k=>{A.set(k)},onSilence:()=>{M({type:"commit"}),n.set("thinking")},silenceDurationMs:g,silenceThreshold:b});u===y?(y.microphone=T,S.set(!1),n.set("listening")):T.stop()}catch(r){v.set(r instanceof Error?r:new Error(String(r))),x()}finally{C=!1}}},q=()=>{const r=!L(S);return u?.microphone?.setMuted(r),S.set(r),r},F=r=>{M({text:r,type:"text"})&&n.set("thinking")};return{audioLevel:{subscribe:A.subscribe},connected:{subscribe:c.subscribe},endCall:U,error:{subscribe:v.subscribe},interimTranscript:{subscribe:h.subscribe},isMuted:{subscribe:S.subscribe},sendText:F,startCall:_,status:{subscribe:n.subscribe},toggleMute:q,transcript:{subscribe:p.subscribe}}};function Z(e,o){const s=R(e),i=s?e:W();return G(i,s?o:e)}export{Z as voiceAgent};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/svelte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.67",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@lunora/client": "1.0.0-alpha.
|
|
62
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
63
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
64
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
61
|
+
"@lunora/client": "1.0.0-alpha.41",
|
|
62
|
+
"@lunora/errors": "1.0.0-alpha.15",
|
|
63
|
+
"@lunora/ratelimit": "1.0.0-alpha.18",
|
|
64
|
+
"@lunora/runtime": "1.0.0-alpha.54",
|
|
65
65
|
"@visulima/storage-client": "1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{reconcileOptimistic as x,maxSeq as j}from"@lunora/client";import{writable as h}from"svelte/store";import{i as b}from"./is-browser-BEdfLJHK.mjs";import{isClient as Q,NO_MUTATION_REF as U}from"./agent-CddTbgxO.mjs";import{getLunoraClient as V}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as g}from"./mutation-fa0Bj5Bo.mjs";import{stream as $}from"./stream-DItOnXt6.mjs";const z={__lunoraRef:""},G=(s,m)=>{const{api:o,cancel:d,limit:f,send:A,sendArgs:T,stream:y,threadKey:a}=m,_=g(s,A),q=g(s,d??U),v=g(s,o.agents.agentResolveApproval);let r,i=[],c=[],w=[],I=0;const u=h([]),k=h(),C=h(""),l=()=>{const t=x(c,i);if(t.length===0){u.set(i);return}const n=j(i);u.set([...i,...t.map((e,p)=>({content:e.content,optimistic:!0,role:"user",seq:n+1+p}))])},K=()=>{const t=i.filter(e=>e.role==="assistant").length,n=w.filter(e=>e.kind!=="progress"&&e.threadKey===a&&e.turn>=t).map(e=>e.text).join("");C.set(n)},E=y===void 0?"skip":{key:a},O=b()?$(s,y??z,E).chunks.subscribe(t=>{w=t,K()}):()=>{},R=f===void 0?{key:a}:{key:a,limit:f},S=b()?s.subscribe(o.agents.agentMessages,R,t=>{i=t,l(),K()}):()=>{},N=b()?s.subscribe(o.agents.agentThread,{key:a},t=>{r=t,k.set(r?.status)}):()=>{},D=async(t,n)=>{const e=I;I+=1;const p=j(i);c=[...x(c,i),{content:t,id:e,maxDurableSeqAtSend:p}],l();try{await _.mutate({input:t,threadKey:a,...T,...n})}catch(H){throw c=c.filter(P=>P.id!==e),l(),H}},F=async(t,n)=>{const e=r?.instanceId;if(e===void 0)throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");await v.mutate({decision:"approve",instanceId:e,threadKey:a,toolCallId:t,...n===void 0?{}:{note:n}})},L=async(t,n)=>{const e=r?.instanceId;if(e===void 0)throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");await v.mutate({decision:"reject",instanceId:e,threadKey:a,toolCallId:t,...n===void 0?{}:{note:n}})},M=async()=>{const t=r?.instanceId;d===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:a})},B=()=>{S(),N(),O()};return{approve:F,cancel:M,messages:{subscribe:u.subscribe},reject:L,send:D,status:{subscribe:k.subscribe},streamingText:{subscribe:C.subscribe},teardown:B}};function nt(s,m){const o=Q(s),d=o?s:V();return G(d,o?m:s)}export{nt as agentChat};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readable as a}from"svelte/store";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";const g="__lunora_flags__:eval",m=t=>{const o=typeof t;return o==="boolean"||o==="number"||o==="string"?o:"object"},j={__lunoraRef:g},p=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",_=(t,o,n,e,r)=>{try{return t.subscribe(j,{context:e,default:n,key:o,type:m(n)},c=>{r(c)})}catch{return()=>{}}};function h(t,o,n,e){const r=p(t),c=r?t:b(),i=r?o:t,s=r?n:o,u=(r?e:n)??void 0;return a(s,f=>_(c,i,s,u,f))}function C(t,o,n){const e=p(t),r=e?t:b(),c=e?o:t,i=(e?n:o)??void 0;return a(c,s=>{let u={...c};const f=[];for(const[l,y]of Object.entries(c))f.push(_(r,l,y,i,d=>{u={...u,[l]:d},s(u)}));return()=>{for(const l of f)l()}})}export{h as flag,C as flags};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{initialPages as K,derivePaginationStatus as T,applyLoadMore as V,rebalance as q}from"@lunora/client/pagination";import{derived as k,writable as B,readable as G,get as N}from"svelte/store";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{i as Q}from"./is-function-reference-ByqJF30w.mjs";const H=(e,r)=>e<r?-1:e>r?1:0,U=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>U(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const n=e,b=Object.keys(n).toSorted(H),i=[];for(const t of b){const o=n[t];o!==void 0&&i.push(`${JSON.stringify(t)}:${U(o)}`)}return`{${i.join(",")}}`},E=e=>{let r="";for(let n=0;n<e.length;n+=32768)r+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(r)},c="$lunora.wire$",D=64,X=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},S=(e,r=0)=>{if(r>D)throw new RangeError(`wire-codec: value nesting exceeds the ${D}-level limit`);if(e===void 0)return[c,"undefined"];if(e===null)return null;const n=typeof e;if(n==="bigint")return[c,"bigint",e.toString()];if(n==="number"){const t=e;return Number.isNaN(t)?[c,"nan"]:t===1/0?[c,"inf"]:t===-1/0?[c,"-inf"]:t}if(n!=="object")return e;if(e instanceof Date)return[c,"date",S(e.getTime(),r+1)];if(e instanceof Error){const t=e,o={};for(const s of Object.keys(t))t[s]!==void 0&&(o[s]=S(t[s],r+1));const a=[c,"error",t.name,t.message,o];return t.cause!==void 0&&a.push(S(t.cause,r+1)),a}if(e instanceof URL)return[c,"url",e.href];if(e instanceof Map)return[c,"map",[...e.entries()].map(([t,o])=>[S(t,r+1),S(o,r+1)])];if(e instanceof Set)return[c,"set",[...e].map(t=>S(t,r+1))];if(e instanceof ArrayBuffer)return[c,"bytes",E(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,a=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[c,"bytes",E(a)]:[c,"bytes",E(a),o]}if(Array.isArray(e)){const t=e.map(o=>S(o,r+1));return t.length>0&&t[0]===c?[c,"arr",t]:t}if(!X(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const b=e,i={};for(const t of Object.keys(b)){const o=b[t];o!==void 0&&(i[t]=S(o,r+1))}return i},Y=e=>U(S(e)),$=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),P=(e,r)=>`${e}::${Y(r)}`,W=(e,r,n,b)=>{const{initialNumItems:i,shardKey:t}=b,o=B(K(i)),a=B([]),s=new Map,y=new Map,w=new Set,f=n,g=()=>{if(f==="skip"){a.set([]);return}const l=N(o).map(m=>{const v=P(r.__lunoraRef,$(m,f));return s.get(v)});a.set(l)},O=(l,m)=>{if(f==="skip")return;const v=u=>P(r.__lunoraRef,$(u,f));for(const u of m){const h=v(u);if(s.has(h))continue;const d=l.find(R=>R.lower===u.lower);if(d){const R=s.get(v(d));R&&s.set(h,R)}}},A=()=>{if(f==="skip"){for(const u of y.values())u();y.clear(),a.set([]);return}const l=f,m=N(o),v=new Set;for(const u of m)v.add(P(r.__lunoraRef,$(u,l)));for(const[u,h]of y)v.has(u)||(h(),y.delete(u),w.delete(u),s.delete(u));for(const u of m){const h=$(u,l),d=P(r.__lunoraRef,h);if(y.has(d))continue;w.add(d);const R=e.subscribe(r,h,F=>{if(s.set(d,F),w.delete(d),g(),w.size===0){const L=N(o),M=q(L,N(a));M&&(O(L,M),o.set(M),p(),g())}},{shardKey:t});y.set(d,R)}};let j=!1,_=!1;const p=()=>{if(j){_=!0;return}j=!0;try{do _=!1,A();while(_)}finally{j=!1}},x=()=>{for(const l of y.values())l();y.clear(),s.clear(),w.clear()},C=G([],l=>{const m=a.subscribe(l);return f!=="skip"&&(p(),g()),()=>{m(),x(),o.set(K(i)),a.set([])}}),z=k(C,l=>T(f==="skip",l).status);return{loadMore:l=>{if(f==="skip")return;const m=N(a),{nextCursor:v,status:u}=T(!1,m);if(u!=="CanLoadMore")return;const h=N(o),d=V(h,v,l);if(!d)return;const R=h.at(-1),F=d.at(-2);if(R&&F){const L=P(r.__lunoraRef,$(R,f)),M=P(r.__lunoraRef,$(F,f));if(L!==M){const J=s.get(L);J&&(s.set(M,J),s.delete(L))}}o.set(d),p(),g()},pageResults:C,status:z}};function oe(e,r,n,b){const i=!Q(e),t=i?e:I(),o=i?r:e,a=i?n:r,s=i?b:n,{loadMore:y,pageResults:w,status:f}=W(t,o,a,s),g=k(w,O=>{const A=[];for(const j of O)j&&A.push(...j.page);return A});return{isLoading:k(f,O=>O==="LoadingFirstPage"||O==="LoadingMore"),loadMore:y,results:g,status:f}}function ne(e,r,n,b){const i=!Q(e),t=i?e:I(),o=i?r:e,a=i?n:r,s=i?b:n,{initialNumItems:y}=s,{loadMore:w,pageResults:f,status:g}=W(t,o,a,s),O=k(f,p=>{const x=[];for(const C of p)C&&x.push(C.page);return x}),A=k(g,p=>p==="LoadingFirstPage"),j=k(g,p=>p==="CanLoadMore"),_=k(g,p=>p==="LoadingMore");return{fetchNextPage:p=>{w(p??y)},hasNextPage:j,isFetchingNextPage:_,isLoading:A,pages:O,status:g}}export{ne as infiniteQuery,oe as paginatedQuery};
|