@lunora/svelte 1.0.0-alpha.47 → 1.0.0-alpha.49
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.mjs +1 -18
- package/dist/packem_shared/agent-BEqcvTwb.mjs +1 -0
- package/dist/packem_shared/agentChat-3IXHbOEE.mjs +1 -0
- package/dist/packem_shared/agentState-ZGfPOSwK.mjs +1 -0
- package/dist/packem_shared/agentToolEvents-BYjBe2-X.mjs +1 -0
- package/dist/packem_shared/auth-DNOb_Wm7.mjs +1 -0
- package/dist/packem_shared/connectionStatus-BHVAskxU.mjs +1 -0
- package/dist/packem_shared/flag-kAz4soTW.mjs +1 -0
- package/dist/packem_shared/getLunoraClient-DU7BmZy1.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-Bbm6vwbA.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-CIxf7GMM.mjs +1 -0
- package/dist/packem_shared/is-function-reference-ByqJF30w.mjs +1 -0
- package/dist/packem_shared/mutation-fa0Bj5Bo.mjs +1 -0
- package/dist/packem_shared/mutator-cvH3UrNm.mjs +1 -0
- package/dist/packem_shared/presence-D-m3S1lu.mjs +1 -0
- package/dist/packem_shared/query-BEQBdOJ2.mjs +1 -0
- package/dist/packem_shared/rateLimit-CwhxlHqx.mjs +1 -0
- package/dist/packem_shared/stream-DItOnXt6.mjs +1 -0
- package/dist/packem_shared/subscription-Dbz9sy8N.mjs +1 -0
- package/dist/packem_shared/voiceAgent-BxIYZRin.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.mjs +1 -2
- package/dist/worker.mjs +1 -1
- package/package.json +5 -5
- package/dist/packem_shared/agent-KLsxO_Uw.mjs +0 -48
- package/dist/packem_shared/agentChat-BlwlNfDg.mjs +0 -138
- package/dist/packem_shared/agentState-DBXc_3RM.mjs +0 -15
- package/dist/packem_shared/agentToolEvents-qYM1CdTV.mjs +0 -60
- package/dist/packem_shared/auth-BeYqYP9S.mjs +0 -28
- package/dist/packem_shared/connectionStatus-BrICpw9d.mjs +0 -14
- package/dist/packem_shared/flag-CqMU07WH.mjs +0 -56
- package/dist/packem_shared/getLunoraClient-Prczj1gU.mjs +0 -17
- package/dist/packem_shared/hydratePreloaded-Djsf_C8Q.mjs +0 -21
- package/dist/packem_shared/infiniteQuery-Bemu7Um1.mjs +0 -227
- package/dist/packem_shared/is-function-reference-ycLAcI79.mjs +0 -3
- package/dist/packem_shared/mutation-BmkCZnTd.mjs +0 -31
- package/dist/packem_shared/mutator-B5LchgMS.mjs +0 -19
- package/dist/packem_shared/presence-BvChXqiB.mjs +0 -83
- package/dist/packem_shared/query-B-Gu6KQw.mjs +0 -42
- package/dist/packem_shared/rateLimit-Cdw1kp8t.mjs +0 -66
- package/dist/packem_shared/stream-BebZbIaD.mjs +0 -68
- package/dist/packem_shared/subscription-COqqiMPX.mjs +0 -43
- package/dist/packem_shared/voiceAgent-Cxib7eCK.mjs +0 -405
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { agentChat } from './packem_shared/agentChat-BlwlNfDg.mjs';
|
|
3
|
-
export { agentState } from './packem_shared/agentState-DBXc_3RM.mjs';
|
|
4
|
-
export { agentToolEvents } from './packem_shared/agentToolEvents-qYM1CdTV.mjs';
|
|
5
|
-
export { auth } from './packem_shared/auth-BeYqYP9S.mjs';
|
|
6
|
-
export { connectionStatus } from './packem_shared/connectionStatus-BrICpw9d.mjs';
|
|
7
|
-
export { getLunoraClient, setLunoraClient } from './packem_shared/getLunoraClient-Prczj1gU.mjs';
|
|
8
|
-
export { flag, flags } from './packem_shared/flag-CqMU07WH.mjs';
|
|
9
|
-
export { hydratePreloaded } from './packem_shared/hydratePreloaded-Djsf_C8Q.mjs';
|
|
10
|
-
export { mutation } from './packem_shared/mutation-BmkCZnTd.mjs';
|
|
11
|
-
export { mutator } from './packem_shared/mutator-B5LchgMS.mjs';
|
|
12
|
-
export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-Bemu7Um1.mjs';
|
|
13
|
-
export { presence } from './packem_shared/presence-BvChXqiB.mjs';
|
|
14
|
-
export { query } from './packem_shared/query-B-Gu6KQw.mjs';
|
|
15
|
-
export { rateLimit } from './packem_shared/rateLimit-Cdw1kp8t.mjs';
|
|
16
|
-
export { stream } from './packem_shared/stream-BebZbIaD.mjs';
|
|
17
|
-
export { subscription } from './packem_shared/subscription-COqqiMPX.mjs';
|
|
18
|
-
export { voiceAgent } from './packem_shared/voiceAgent-Cxib7eCK.mjs';
|
|
1
|
+
import{agent as t}from"./packem_shared/agent-BEqcvTwb.mjs";import{agentChat as m}from"./packem_shared/agentChat-3IXHbOEE.mjs";import{agentState as p}from"./packem_shared/agentState-ZGfPOSwK.mjs";import{agentToolEvents as n}from"./packem_shared/agentToolEvents-BYjBe2-X.mjs";import{auth as i}from"./packem_shared/auth-DNOb_Wm7.mjs";import{connectionStatus as g}from"./packem_shared/connectionStatus-BHVAskxU.mjs";import{getLunoraClient as l,setLunoraClient as c}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as y,flags as h}from"./packem_shared/flag-kAz4soTW.mjs";import{hydratePreloaded as L}from"./packem_shared/hydratePreloaded-Bbm6vwbA.mjs";import{mutation as Q}from"./packem_shared/mutation-fa0Bj5Bo.mjs";import{mutator as b}from"./packem_shared/mutator-cvH3UrNm.mjs";import{infiniteQuery as A,paginatedQuery as E}from"./packem_shared/infiniteQuery-CIxf7GMM.mjs";import{presence as T}from"./packem_shared/presence-D-m3S1lu.mjs";import{query as k}from"./packem_shared/query-BEQBdOJ2.mjs";import{rateLimit as z}from"./packem_shared/rateLimit-CwhxlHqx.mjs";import{stream as D}from"./packem_shared/stream-DItOnXt6.mjs";import{subscription as G}from"./packem_shared/subscription-Dbz9sy8N.mjs";import{voiceAgent as I}from"./packem_shared/voiceAgent-BxIYZRin.mjs";export{t as agent,m as agentChat,p as agentState,n as agentToolEvents,i as auth,g as connectionStatus,y as flag,h as flags,l as getLunoraClient,L as hydratePreloaded,A as infiniteQuery,Q as mutation,b as mutator,E as paginatedQuery,T as presence,k as query,z as rateLimit,c as setLunoraClient,D as stream,G as subscription,I as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as b}from"svelte/store";import{getLunoraClient as T}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as d}from"./mutation-fa0Bj5Bo.mjs";const _={__lunoraRef:""},A=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",C=(t,a)=>{const{api:e,cancel:s,run:l,runArgs:m,threadKey:i}=a,o=d(t,l),p=d(t,s??_);let r;const c=b(),u=b(),f=t.subscribe(e.agents.agentThread,{key:i},n=>{r=n,c.set(r),u.set(r?.status)}),y=async(n,w)=>{await o.mutate({input:n,threadKey:i,...m,...w})},g=async()=>{const n=r?.instanceId;s===void 0||n===void 0||await p.mutate({instanceId:n,threadKey:i})},h=()=>{f()};return{cancel:g,pending:o.pending,run:y,status:{subscribe:u.subscribe},teardown:h,thread:{subscribe:c.subscribe}}};function v(t,a){const e=A(t),s=e?t:T();return C(s,e?a:t)}export{_ as NO_MUTATION_REF,v as agent,A as isClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as v}from"svelte/store";import{isClient as $,NO_MUTATION_REF as B}from"./agent-BEqcvTwb.mjs";import{getLunoraClient as G}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as y}from"./mutation-fa0Bj5Bo.mjs";import{stream as H}from"./stream-DItOnXt6.mjs";const P={__lunoraRef:""},T=(s,l)=>{const r=l.filter(c=>c.role==="user"),i=new Set;return s.filter(c=>{for(let d=c.durableUserCountAtSend;d<r.length;d+=1){const m=r[d];if(m!==void 0&&!i.has(d)&&m.content===c.content)return i.add(d),!1}return!0})},z=(s,l)=>{const{api:r,cancel:i,limit:c,send:d,sendArgs:m,stream:w,threadKey:a}=l,_=y(s,d),q=y(s,i??B),I=y(s,r.agents.agentResolveApproval);let u,o=[],h=[],C=[],k=0;const f=v([]),A=v(),K=v(""),g=()=>{const e=T(h,o);if(e.length===0){f.set(o);return}let n=-1;for(const t of o)t.seq>n&&(n=t.seq);f.set([...o,...e.map((t,b)=>({content:t.content,optimistic:!0,role:"user",seq:n+1+b}))])},j=()=>{const e=o.filter(t=>t.role==="assistant").length,n=C.filter(t=>t.kind!=="progress"&&t.threadKey===a&&t.turn>=e).map(t=>t.text).join("");K.set(n)},x=H(s,w??P,w===void 0?"skip":{key:a}).chunks.subscribe(e=>{C=e,j()}),E=c===void 0?{key:a}:{key:a,limit:c},R=s.subscribe(r.agents.agentMessages,E,e=>{o=e,g(),j()}),S=s.subscribe(r.agents.agentThread,{key:a},e=>{u=e,A.set(u?.status)}),M=async(e,n)=>{const t=k;k+=1;const b=o.filter(p=>p.role==="user").length;h=[...T(h,o),{content:e,durableUserCountAtSend:b,id:t}],g();try{await _.mutate({input:e,threadKey:a,...m,...n})}catch(p){throw h=h.filter(N=>N.id!==t),g(),p}},O=async(e,n)=>{const t=u?.instanceId;if(t===void 0)throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");await I.mutate({decision:"approve",instanceId:t,threadKey:a,toolCallId:e,...n===void 0?{}:{note:n}})},U=async(e,n)=>{const t=u?.instanceId;if(t===void 0)throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");await I.mutate({decision:"reject",instanceId:t,threadKey:a,toolCallId:e,...n===void 0?{}:{note:n}})},F=async()=>{const e=u?.instanceId;i===void 0||e===void 0||await q.mutate({instanceId:e,threadKey:a})},L=()=>{R(),S(),x()};return{approve:O,cancel:F,messages:{subscribe:f.subscribe},reject:U,send:M,status:{subscribe:A.subscribe},streamingText:{subscribe:K.subscribe},teardown:L}};function X(s,l){const r=$(s),i=r?s:G();return z(i,r?l:s)}export{X as agentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as p}from"svelte/store";import{isClient as f}from"./agent-BEqcvTwb.mjs";import{getLunoraClient as d}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as g}from"./subscription-Dbz9sy8N.mjs";function C(r,o){const t=f(r),a=t?r:d(),e=t?o:r,{data:i,error:n}=g(a,e.api.agents.agentState,{key:e.threadKey}),s=p(i,m=>m);return{error:n,state:s}}export{C as agentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as c}from"svelte/store";import{isClient as g}from"./agent-BEqcvTwb.mjs";import{getLunoraClient as y}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as I}from"./stream-DItOnXt6.mjs";import{subscription as N}from"./subscription-Dbz9sy8N.mjs";const k={__lunoraRef:""},q=o=>{if(o.role==="assistant"&&o.toolCalls)return o.toolCalls.map(t=>({input:t.input,seq:o.seq,toolCallId:t.id,toolName:t.name,type:"call"}));if(o.role==="tool")return o.status==="awaiting_approval"?[{seq:o.seq,type:"awaiting-approval",...o.toolCallId===void 0?{}:{toolCallId:o.toolCallId},...o.toolName===void 0?{}:{toolName:o.toolName}}]:[{output:o.content,seq:o.seq,type:"result",...o.status==="approved"||o.status==="rejected"?{status:o.status}:{},...o.toolCallId===void 0?{}:{toolCallId:o.toolCallId},...o.toolName===void 0?{}:{toolName:o.toolName}}]};function M(o,t){const l=g(o),s=l?o:y(),p=l?t:o,{api:d,limit:r,stream:i,threadKey:e}=p,m=r===void 0?{key:e}:{key:e,limit:r},{data:u}=N(s,d.agents.agentMessages,m),C=I(s,i??k,i===void 0?"skip":{key:e});return{events:c([u,C.chunks],([f,v])=>{const n=(f??[]).flatMap(a=>q(a)??[]);for(const a of v)a.kind==="progress"&&a.threadKey===e&&n.push({data:a.data,toolCallId:a.toolCallId,type:"progress"});return n})}}export{M as agentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getIdentityStore as a}from"@lunora/client/auth";import{readable as r}from"svelte/store";import{getLunoraClient as h}from"./getLunoraClient-DU7BmZy1.mjs";const T=n=>{const e=n??h(),o=a(e),s=r(e.getAuthToken(),t=>(t(e.getAuthToken()),e.onAuthTokenChange(g=>{t(g)}))),u=r(o.getUser(),t=>(t(o.getUser()),o.subscribe(()=>{t(o.getUser())})));return{setToken:t=>{e.setAuthToken(t)},token:s,user:u}};export{T as auth};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as c}from"svelte/store";import{getLunoraClient as r}from"./getLunoraClient-DU7BmZy1.mjs";const s=o=>{const t=o??r();return c(t.connectionStatus(),n=>(n(t.connectionStatus()),t.onConnectionStatus(e=>{n(e)})))};export{s as connectionStatus};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as o}from"@lunora/errors";import{setContext as e,getContext as r}from"svelte";const n=Symbol("lunora.client"),a=t=>(e(n,t),t),c=()=>{const t=r(n);if(!t)throw new o("INTERNAL","getLunoraClient(): no LunoraClient in context — call setLunoraClient(client) in an ancestor component first.");return t};export{c as getLunoraClient,a as setLunoraClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as u}from"svelte/store";import{getLunoraClient as c}from"./getLunoraClient-DU7BmZy1.mjs";const m=(r,e)=>{const a=e??c(),{args:o,functionPath:t,shardKey:n,value:s}=r,d={__lunoraRef:t};return u(s,i=>a.subscribe(d,o,l=>{i(l)},{shardKey:n}))};export{m as hydratePreloaded};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as K,derivePaginationStatus as Q,applyLoadMore as j,rebalance as q}from"@lunora/client/pagination";import{derived as w,writable as $,readable as B,get as k}from"svelte/store";import{getLunoraClient as z}from"./getLunoraClient-DU7BmZy1.mjs";import{i as J}from"./is-function-reference-ByqJF30w.mjs";const C=(o,e)=>({...e,paginationOpts:{cursor:o.lower,endCursor:o.upper,numItems:o.numItems}}),F=(o,e)=>`${o}::${JSON.stringify(e)}`,T=(o,e,b,N)=>{const{initialNumItems:i,shardKey:v}=N,c=$(K(i)),l=$([]),n=new Map,u=new Map,m=new Set,s=b,d=()=>{if(s==="skip"){l.set([]);return}const r=k(c).map(p=>{const R=F(e.__lunoraRef,C(p,s));return n.get(R)});l.set(r)},M=(r,p)=>{if(s==="skip")return;const R=t=>F(e.__lunoraRef,C(t,s));for(const t of p){const g=R(t);if(n.has(g))continue;const f=r.find(h=>h.lower===t.lower);if(f){const h=n.get(R(f));h&&n.set(g,h)}}},L=()=>{if(s==="skip"){for(const t of u.values())t();u.clear(),l.set([]);return}const r=s,p=k(c),R=new Set;for(const t of p)R.add(F(e.__lunoraRef,C(t,r)));for(const[t,g]of u)R.has(t)||(g(),u.delete(t),m.delete(t),n.delete(t));for(const t of p){const g=C(t,r),f=F(e.__lunoraRef,g);if(u.has(f))continue;m.add(f);const h=o.subscribe(e,g,A=>{if(n.set(f,A),m.delete(f),d(),m.size===0){const P=k(c),y=q(P,k(l));y&&(M(P,y),c.set(y),a(),d())}},{shardKey:v});u.set(f,h)}};let _=!1,S=!1;const a=()=>{if(_){S=!0;return}_=!0;try{do S=!1,L();while(S)}finally{_=!1}},O=()=>{for(const r of u.values())r();u.clear(),n.clear(),m.clear()},x=B([],r=>{const p=l.subscribe(r);return s!=="skip"&&(a(),d()),()=>{p(),O(),c.set(K(i)),l.set([])}}),U=w(x,r=>Q(s==="skip",r).status);return{loadMore:r=>{if(s==="skip")return;const p=k(l),{nextCursor:R,status:t}=Q(!1,p);if(t!=="CanLoadMore")return;const g=k(c),f=j(g,R,r);if(!f)return;const h=g.at(-1),A=f.at(-2);if(h&&A){const P=F(e.__lunoraRef,C(h,s)),y=F(e.__lunoraRef,C(A,s));if(P!==y){const I=n.get(P);I&&(n.set(y,I),n.delete(P))}}c.set(f),a(),d()},pageResults:x,status:U}};function V(o,e,b,N){const i=!J(o),v=i?o:z(),c=i?e:o,l=i?b:e,n=i?N:b,{loadMore:u,pageResults:m,status:s}=T(v,c,l,n),d=w(m,M=>{const L=[];for(const _ of M)_&&L.push(..._.page);return L});return{isLoading:w(s,M=>M==="LoadingFirstPage"||M==="LoadingMore"),loadMore:u,results:d,status:s}}function W(o,e,b,N){const i=!J(o),v=i?o:z(),c=i?e:o,l=i?b:e,n=i?N:b,{initialNumItems:u}=n,{loadMore:m,pageResults:s,status:d}=T(v,c,l,n),M=w(s,a=>{const O=[];for(const x of a)x&&O.push(x.page);return O}),L=w(d,a=>a==="LoadingFirstPage"),_=w(d,a=>a==="CanLoadMore"),S=w(d,a=>a==="LoadingMore");return{fetchNextPage:a=>{m(a??u)},hasNextPage:_,isFetchingNextPage:S,isLoading:L,pages:M,status:d}}export{W as infiniteQuery,V as paginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=e=>typeof e=="object"&&e!==null&&typeof e.__lunoraRef=="string";export{o as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutationRunner as f}from"@lunora/client";import{writable as o}from"svelte/store";import{getLunoraClient as p}from"./getLunoraClient-DU7BmZy1.mjs";function g(n,s){const i=s!==void 0,u=i?n:p(),d=i?s:n,r=o(),e=o(),a=o(!1),m=f(u,d,{setError:t=>{e.set(t)},setPending:t=>{a.set(t)},setResult:t=>{r.set(t),e.set(void 0)}});return{data:r,error:e,mutate:m,pending:a,reset:()=>{r.set(void 0),e.set(void 0)}}}export{g as mutation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as m}from"@lunora/client";import{writable as o,derived as d}from"svelte/store";const c=s=>{const e=o(),t=o(!1),n=d(e,r=>r!==void 0),{mutate:a,reset:i}=m(s,{setError:r=>{e.set(r)},setPending:r=>{t.set(r)}});return{error:e,isError:n,mutate:a,pending:t,reset:i}};export{c as mutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{onDestroy as h}from"svelte";import{readable as g}from"svelte/store";import{getLunoraClient as D}from"./getLunoraClient-DU7BmZy1.mjs";const U=(t="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const e=crypto.getRandomValues(new Uint8Array(16));return`${t}-${Array.from(e,o=>o.toString(16).padStart(2,"0")).join("")}`}}return`${t}-${Date.now().toString(36)}`},$=1e4,C=(t,e,o)=>{const{heartbeat:r,intervalMs:i=$,listPresent:p,shardKey:a}=o,c=o.sessionId??U();let d=o.data;const s=()=>{const n={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(r,n,{shardKey:a}).catch(()=>{})},f=n=>{d=n,s()};s();const l=setInterval(s,i),u=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};typeof document<"u"&&document.addEventListener("visibilitychange",u);const v=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:a}),I=g(void 0,n=>t.subscribe(p,{roomId:e},b=>{n(b)},{shardKey:a}));let y=!1;const m=()=>{y||(y=!0,clearInterval(l),typeof document<"u"&&document.removeEventListener("visibilitychange",u),v())};try{h(m)}catch{}return{present:I,sessionId:c,setData:f,teardown:m}};function w(t,e,o){const r=typeof t!="string",i=r?t:D();return C(i,r?e:t,r?o:e)}export{w as presence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as s}from"@lunora/client/query";import{readable as c}from"svelte/store";import{getLunoraClient as d}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-ByqJF30w.mjs";function E(o,e,t,a){const r=!y(o),m=r?o:d(),u=r?e:o,f=r?t:e,n=(r?a:t)??{};return c(void 0,i=>s(m,u,f,{onData:p=>{i(p)},onError:n.onError,onReset:()=>{i(void 0)}},{shardKey:n.shardKey}))}export{E as query};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as v}from"@lunora/ratelimit";import{writable as I,derived as r}from"svelte/store";const x=(n,d={})=>{const a=d.now??Date.now,k=d.tickMs??1e3;let t;const f=I(0),u=()=>{f.update(e=>e+1)},s=r(f,()=>v(n,t,{consume:!1,count:1,now:a(),reserve:!1}).status);let o;const c=()=>{o!==void 0&&(clearInterval(o),o=void 0)};let l=!0;const w=s.subscribe(e=>{l=e.ok}),m=()=>{l||o!==void 0||(o=setInterval(()=>{u(),l&&c()},k))};m();const b=(e=1)=>{const i=v(n,t,{consume:!0,count:e,now:a(),reserve:!1});return i.value!==void 0&&(t=i.value),u(),m(),i.status},p=(e=1)=>v(n,t,{consume:!1,count:e,now:a(),reserve:!1}).status.ok,y=()=>{t=void 0,c(),u()},A=()=>{c(),w()};return{check:p,consume:b,disabled:r(s,e=>!e.ok),ok:r(s,e=>e.ok),reset:y,retryAfter:r(s,e=>e.retryAfter),teardown:A}};export{x as rateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as h,readable as E}from"svelte/store";import{getLunoraClient as K}from"./getLunoraClient-DU7BmZy1.mjs";import{i as R}from"./is-function-reference-ByqJF30w.mjs";function L(i,u,f,p){const t=!R(i),w=t?i:K(),y=t?u:i,m=t?f:u,g=(t?p:f)??{},{maxBuffer:k,shardKey:x}=g,r=h("idle"),a=h();let s;const b=()=>{s?.()},v=E([],l=>{if(l([]),a.set(void 0),m==="skip")return r.set("idle"),()=>{};r.set("streaming");let n=!0,c=[];const d=w.stream(y,m,{maxBuffer:k,shardKey:x}),o=()=>{d.cancel()};return s=o,(async()=>{try{for await(const e of d){if(!n)return;c=[...c,e],l(c)}n&&r.set("complete")}catch(e){if(!n)return;a.set(e instanceof Error?e:new Error(String(e))),r.set("error")}})().catch(()=>{}),()=>{n=!1,o(),s===o&&(s=void 0)}}),B=()=>{b()};return{cancel:b,chunks:v,error:{subscribe:a.subscribe},status:{subscribe:r.subscribe},teardown:B}}export{L as stream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as E}from"@lunora/client/query";import{writable as l,readable as y}from"svelte/store";import{getLunoraClient as g}from"./getLunoraClient-DU7BmZy1.mjs";import{i as h}from"./is-function-reference-ByqJF30w.mjs";function S(o,n,s,c){const r=!h(o),u=r?o:g(),b=r?n:o,d=r?s:n,m=(r?c:s)??{},{shardKey:p,onError:f}=m,e=l();return{data:y(void 0,i=>{const v=E(u,b,d,{onData:t=>{i(t),e.set(void 0)},onError:t=>{const a=new Error(t.message);e.set(a),f?.(a)},onReset:()=>{i(void 0)}},{shardKey:p});return()=>{v(),e.set(void 0)}}),error:{subscribe:e.subscribe}}}export{S as subscription};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as w,get as L}from"svelte/store";import{isClient as R}from"./agent-BEqcvTwb.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/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createServerClient as d,deserializePreloaded as l,getServerSession as a,preloadQuery as o,preloadedQueryResult as i,serializePreloaded as s}from"@lunora/client/ssr";export{d as createServerClient,l as deserializePreloaded,a as getServerSession,o as preloadQuery,i as preloadedQueryResult,s as serializePreloaded};
|
package/dist/upload.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createChunkedRestUpload, createFileInput, createMultipartUpload, createPasteUpload, createTusUpload, createUpload } from '@visulima/storage-client/svelte';
|
|
1
|
+
import{RestrictionError as o,UploadControl as t,UploadError as a}from"@visulima/storage-client";import{createChunkedRestUpload as l,createFileInput as d,createMultipartUpload as c,createPasteUpload as U,createTusUpload as i,createUpload as n}from"@visulima/storage-client/svelte";export{o as RestrictionError,t as UploadControl,a as UploadError,l as createChunkedRestUpload,d as createFileInput,c as createMultipartUpload,U as createPasteUpload,i as createTusUpload,n as createUpload};
|
package/dist/worker.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{withFrameworkWorker as a}from"@lunora/runtime";export{a as withLunora};
|
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.49",
|
|
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.29",
|
|
62
|
+
"@lunora/errors": "1.0.0-alpha.8",
|
|
63
|
+
"@lunora/ratelimit": "1.0.0-alpha.10",
|
|
64
|
+
"@lunora/runtime": "1.0.0-alpha.38",
|
|
65
65
|
"@visulima/storage-client": "1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
import { mutation } from './mutation-BmkCZnTd.mjs';
|
|
4
|
-
|
|
5
|
-
const NO_MUTATION_REF = { __lunoraRef: "" };
|
|
6
|
-
const isClient = (value) => typeof value === "object" && value !== null && typeof value.subscribe === "function";
|
|
7
|
-
const createAgentHandle = (client, options) => {
|
|
8
|
-
const { api, cancel: cancelReference, run: runReference, runArgs, threadKey } = options;
|
|
9
|
-
const runMutation = mutation(client, runReference);
|
|
10
|
-
const cancelMutation = mutation(client, cancelReference ?? NO_MUTATION_REF);
|
|
11
|
-
let latestThread;
|
|
12
|
-
const threadStore = writable();
|
|
13
|
-
const statusStore = writable();
|
|
14
|
-
const unsubscribe = client.subscribe(api.agents.agentThread, { key: threadKey }, (value) => {
|
|
15
|
-
latestThread = value;
|
|
16
|
-
threadStore.set(latestThread);
|
|
17
|
-
statusStore.set(latestThread?.status);
|
|
18
|
-
});
|
|
19
|
-
const run = async (input, arguments_) => {
|
|
20
|
-
await runMutation.mutate({ input, threadKey, ...runArgs, ...arguments_ });
|
|
21
|
-
};
|
|
22
|
-
const cancel = async () => {
|
|
23
|
-
const instanceId = latestThread?.instanceId;
|
|
24
|
-
if (cancelReference === void 0 || instanceId === void 0) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
await cancelMutation.mutate({ instanceId, threadKey });
|
|
28
|
-
};
|
|
29
|
-
const teardown = () => {
|
|
30
|
-
unsubscribe();
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
cancel,
|
|
34
|
-
pending: runMutation.pending,
|
|
35
|
-
run,
|
|
36
|
-
status: { subscribe: statusStore.subscribe },
|
|
37
|
-
teardown,
|
|
38
|
-
thread: { subscribe: threadStore.subscribe }
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
function agent(clientOrOptions, maybeOptions) {
|
|
42
|
-
const hasExplicitClient = isClient(clientOrOptions);
|
|
43
|
-
const client = hasExplicitClient ? clientOrOptions : getLunoraClient();
|
|
44
|
-
const options = hasExplicitClient ? maybeOptions : clientOrOptions;
|
|
45
|
-
return createAgentHandle(client, options);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { NO_MUTATION_REF, agent, isClient };
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
import { isClient, NO_MUTATION_REF } from './agent-KLsxO_Uw.mjs';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
import { mutation } from './mutation-BmkCZnTd.mjs';
|
|
5
|
-
import { stream } from './stream-BebZbIaD.mjs';
|
|
6
|
-
|
|
7
|
-
const NO_STREAM_REF = { __lunoraRef: "" };
|
|
8
|
-
const reconcileOptimistic = (optimistic, durable) => {
|
|
9
|
-
const durableUserRows = durable.filter((message) => message.role === "user");
|
|
10
|
-
const consumed = /* @__PURE__ */ new Set();
|
|
11
|
-
return optimistic.filter((pending) => {
|
|
12
|
-
for (let index = pending.durableUserCountAtSend; index < durableUserRows.length; index += 1) {
|
|
13
|
-
const row = durableUserRows[index];
|
|
14
|
-
if (row !== void 0 && !consumed.has(index) && row.content === pending.content) {
|
|
15
|
-
consumed.add(index);
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const createAgentChatHandle = (client, options) => {
|
|
23
|
-
const { api, cancel: cancelReference, limit, send: sendReference, sendArgs, stream: streamReference, threadKey } = options;
|
|
24
|
-
const sendMutation = mutation(client, sendReference);
|
|
25
|
-
const cancelMutation = mutation(client, cancelReference ?? NO_MUTATION_REF);
|
|
26
|
-
const approvalMutation = mutation(client, api.agents.agentResolveApproval);
|
|
27
|
-
let latestThread;
|
|
28
|
-
let durable = [];
|
|
29
|
-
let optimistic = [];
|
|
30
|
-
let liveEvents = [];
|
|
31
|
-
let nextId = 0;
|
|
32
|
-
const messagesStore = writable([]);
|
|
33
|
-
const statusStore = writable();
|
|
34
|
-
const streamingTextStore = writable("");
|
|
35
|
-
const recompute = () => {
|
|
36
|
-
const visible = reconcileOptimistic(optimistic, durable);
|
|
37
|
-
if (visible.length === 0) {
|
|
38
|
-
messagesStore.set(durable);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
let maxDurableSeq = -1;
|
|
42
|
-
for (const message of durable) {
|
|
43
|
-
if (message.seq > maxDurableSeq) {
|
|
44
|
-
maxDurableSeq = message.seq;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
messagesStore.set([
|
|
48
|
-
...durable,
|
|
49
|
-
...visible.map((pending, index) => {
|
|
50
|
-
return {
|
|
51
|
-
content: pending.content,
|
|
52
|
-
optimistic: true,
|
|
53
|
-
role: "user",
|
|
54
|
-
seq: maxDurableSeq + 1 + index
|
|
55
|
-
};
|
|
56
|
-
})
|
|
57
|
-
]);
|
|
58
|
-
};
|
|
59
|
-
const recomputeStreamingText = () => {
|
|
60
|
-
const assistantCount = durable.filter((message) => message.role === "assistant").length;
|
|
61
|
-
const text = liveEvents.filter((event) => event.kind !== "progress" && event.threadKey === threadKey && event.turn >= assistantCount).map((delta) => delta.text).join("");
|
|
62
|
-
streamingTextStore.set(text);
|
|
63
|
-
};
|
|
64
|
-
const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
|
|
65
|
-
const streamHandle = stream(client, streamReference ?? NO_STREAM_REF, streamArguments);
|
|
66
|
-
const unsubscribeStream = streamHandle.chunks.subscribe((value) => {
|
|
67
|
-
liveEvents = value;
|
|
68
|
-
recomputeStreamingText();
|
|
69
|
-
});
|
|
70
|
-
const historyArgs = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
|
|
71
|
-
const unsubscribeHistory = client.subscribe(api.agents.agentMessages, historyArgs, (value) => {
|
|
72
|
-
durable = value;
|
|
73
|
-
recompute();
|
|
74
|
-
recomputeStreamingText();
|
|
75
|
-
});
|
|
76
|
-
const unsubscribeThread = client.subscribe(api.agents.agentThread, { key: threadKey }, (value) => {
|
|
77
|
-
latestThread = value;
|
|
78
|
-
statusStore.set(latestThread?.status);
|
|
79
|
-
});
|
|
80
|
-
const send = async (input, arguments_) => {
|
|
81
|
-
const id = nextId;
|
|
82
|
-
nextId += 1;
|
|
83
|
-
const durableUserCountAtSend = durable.filter((message) => message.role === "user").length;
|
|
84
|
-
optimistic = [...reconcileOptimistic(optimistic, durable), { content: input, durableUserCountAtSend, id }];
|
|
85
|
-
recompute();
|
|
86
|
-
try {
|
|
87
|
-
await sendMutation.mutate({ input, threadKey, ...sendArgs, ...arguments_ });
|
|
88
|
-
} catch (error) {
|
|
89
|
-
optimistic = optimistic.filter((pending) => pending.id !== id);
|
|
90
|
-
recompute();
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const approve = async (toolCallId, note) => {
|
|
95
|
-
const instanceId = latestThread?.instanceId;
|
|
96
|
-
if (instanceId === void 0) {
|
|
97
|
-
throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");
|
|
98
|
-
}
|
|
99
|
-
await approvalMutation.mutate({ decision: "approve", instanceId, threadKey, toolCallId, ...note === void 0 ? {} : { note } });
|
|
100
|
-
};
|
|
101
|
-
const reject = async (toolCallId, note) => {
|
|
102
|
-
const instanceId = latestThread?.instanceId;
|
|
103
|
-
if (instanceId === void 0) {
|
|
104
|
-
throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");
|
|
105
|
-
}
|
|
106
|
-
await approvalMutation.mutate({ decision: "reject", instanceId, threadKey, toolCallId, ...note === void 0 ? {} : { note } });
|
|
107
|
-
};
|
|
108
|
-
const cancel = async () => {
|
|
109
|
-
const instanceId = latestThread?.instanceId;
|
|
110
|
-
if (cancelReference === void 0 || instanceId === void 0) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
await cancelMutation.mutate({ instanceId, threadKey });
|
|
114
|
-
};
|
|
115
|
-
const teardown = () => {
|
|
116
|
-
unsubscribeHistory();
|
|
117
|
-
unsubscribeThread();
|
|
118
|
-
unsubscribeStream();
|
|
119
|
-
};
|
|
120
|
-
return {
|
|
121
|
-
approve,
|
|
122
|
-
cancel,
|
|
123
|
-
messages: { subscribe: messagesStore.subscribe },
|
|
124
|
-
reject,
|
|
125
|
-
send,
|
|
126
|
-
status: { subscribe: statusStore.subscribe },
|
|
127
|
-
streamingText: { subscribe: streamingTextStore.subscribe },
|
|
128
|
-
teardown
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
function agentChat(clientOrOptions, maybeOptions) {
|
|
132
|
-
const hasExplicitClient = isClient(clientOrOptions);
|
|
133
|
-
const client = hasExplicitClient ? clientOrOptions : getLunoraClient();
|
|
134
|
-
const options = hasExplicitClient ? maybeOptions : clientOrOptions;
|
|
135
|
-
return createAgentChatHandle(client, options);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export { agentChat };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { derived } from 'svelte/store';
|
|
2
|
-
import { isClient } from './agent-KLsxO_Uw.mjs';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
import { subscription } from './subscription-COqqiMPX.mjs';
|
|
5
|
-
|
|
6
|
-
function agentState(clientOrOptions, maybeOptions) {
|
|
7
|
-
const hasExplicitClient = isClient(clientOrOptions);
|
|
8
|
-
const client = hasExplicitClient ? clientOrOptions : getLunoraClient();
|
|
9
|
-
const options = hasExplicitClient ? maybeOptions : clientOrOptions;
|
|
10
|
-
const { data, error } = subscription(client, options.api.agents.agentState, { key: options.threadKey });
|
|
11
|
-
const state = derived(data, (value) => value);
|
|
12
|
-
return { error, state };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { agentState };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { derived } from 'svelte/store';
|
|
2
|
-
import { isClient } from './agent-KLsxO_Uw.mjs';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
import { stream } from './stream-BebZbIaD.mjs';
|
|
5
|
-
import { subscription } from './subscription-COqqiMPX.mjs';
|
|
6
|
-
|
|
7
|
-
const NO_STREAM_REF = { __lunoraRef: "" };
|
|
8
|
-
const toDurableEvent = (message) => {
|
|
9
|
-
if (message.role === "assistant" && message.toolCalls) {
|
|
10
|
-
return message.toolCalls.map((call) => {
|
|
11
|
-
return { input: call.input, seq: message.seq, toolCallId: call.id, toolName: call.name, type: "call" };
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
if (message.role !== "tool") {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
if (message.status === "awaiting_approval") {
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
seq: message.seq,
|
|
21
|
-
type: "awaiting-approval",
|
|
22
|
-
...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
|
|
23
|
-
...message.toolName === void 0 ? {} : { toolName: message.toolName }
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
return [
|
|
28
|
-
{
|
|
29
|
-
output: message.content,
|
|
30
|
-
seq: message.seq,
|
|
31
|
-
type: "result",
|
|
32
|
-
...message.status === "approved" || message.status === "rejected" ? { status: message.status } : {},
|
|
33
|
-
...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
|
|
34
|
-
...message.toolName === void 0 ? {} : { toolName: message.toolName }
|
|
35
|
-
}
|
|
36
|
-
];
|
|
37
|
-
};
|
|
38
|
-
function agentToolEvents(clientOrOptions, maybeOptions) {
|
|
39
|
-
const hasExplicitClient = isClient(clientOrOptions);
|
|
40
|
-
const client = hasExplicitClient ? clientOrOptions : getLunoraClient();
|
|
41
|
-
const options = hasExplicitClient ? maybeOptions : clientOrOptions;
|
|
42
|
-
const { api, limit, stream: streamReference, threadKey } = options;
|
|
43
|
-
const historyArgs = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
|
|
44
|
-
const { data } = subscription(client, api.agents.agentMessages, historyArgs);
|
|
45
|
-
const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
|
|
46
|
-
const streamHandle = stream(client, streamReference ?? NO_STREAM_REF, streamArguments);
|
|
47
|
-
const events = derived([data, streamHandle.chunks], ([history, liveEvents]) => {
|
|
48
|
-
const durable = history ?? [];
|
|
49
|
-
const collected = durable.flatMap((message) => toDurableEvent(message) ?? []);
|
|
50
|
-
for (const event of liveEvents) {
|
|
51
|
-
if (event.kind === "progress" && event.threadKey === threadKey) {
|
|
52
|
-
collected.push({ data: event.data, toolCallId: event.toolCallId, type: "progress" });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return collected;
|
|
56
|
-
});
|
|
57
|
-
return { events };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { agentToolEvents };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getIdentityStore } from '@lunora/client/auth';
|
|
2
|
-
import { readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
|
|
5
|
-
const auth = (explicitClient) => {
|
|
6
|
-
const client = explicitClient ?? getLunoraClient();
|
|
7
|
-
const store = getIdentityStore(client);
|
|
8
|
-
const token = readable(client.getAuthToken(), (set) => {
|
|
9
|
-
set(client.getAuthToken());
|
|
10
|
-
const unsub = client.onAuthTokenChange((next) => {
|
|
11
|
-
set(next);
|
|
12
|
-
});
|
|
13
|
-
return unsub;
|
|
14
|
-
});
|
|
15
|
-
const user = readable(store.getUser(), (set) => {
|
|
16
|
-
set(store.getUser());
|
|
17
|
-
const unsub = store.subscribe(() => {
|
|
18
|
-
set(store.getUser());
|
|
19
|
-
});
|
|
20
|
-
return unsub;
|
|
21
|
-
});
|
|
22
|
-
const setToken = (next) => {
|
|
23
|
-
client.setAuthToken(next);
|
|
24
|
-
};
|
|
25
|
-
return { setToken, token, user };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { auth };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const connectionStatus = (client) => {
|
|
5
|
-
const resolved = client ?? getLunoraClient();
|
|
6
|
-
return readable(resolved.connectionStatus(), (set) => {
|
|
7
|
-
set(resolved.connectionStatus());
|
|
8
|
-
return resolved.onConnectionStatus((next) => {
|
|
9
|
-
set(next);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { connectionStatus };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
5
|
-
const flagKind = (value) => {
|
|
6
|
-
const kind = typeof value;
|
|
7
|
-
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
8
|
-
return kind;
|
|
9
|
-
}
|
|
10
|
-
return "object";
|
|
11
|
-
};
|
|
12
|
-
const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
|
|
13
|
-
const isClient = (value) => typeof value === "object" && value !== null && typeof value.subscribe === "function";
|
|
14
|
-
const subscribeFlag = (client, key, defaultValue, context, set) => {
|
|
15
|
-
try {
|
|
16
|
-
return client.subscribe(flagsReference, { context, default: defaultValue, key, type: flagKind(defaultValue) }, (next) => {
|
|
17
|
-
set(next);
|
|
18
|
-
});
|
|
19
|
-
} catch {
|
|
20
|
-
return () => {
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
function flag(clientOrKey, keyOrDefault, defaultOrContext, maybeContext) {
|
|
25
|
-
const hasExplicitClient = isClient(clientOrKey);
|
|
26
|
-
const client = hasExplicitClient ? clientOrKey : getLunoraClient();
|
|
27
|
-
const key = hasExplicitClient ? keyOrDefault : clientOrKey;
|
|
28
|
-
const defaultValue = hasExplicitClient ? defaultOrContext : keyOrDefault;
|
|
29
|
-
const context = (hasExplicitClient ? maybeContext : defaultOrContext) ?? void 0;
|
|
30
|
-
return readable(defaultValue, (set) => subscribeFlag(client, key, defaultValue, context, set));
|
|
31
|
-
}
|
|
32
|
-
function flags(clientOrFlags, flagsOrContext, maybeContext) {
|
|
33
|
-
const hasExplicitClient = isClient(clientOrFlags);
|
|
34
|
-
const client = hasExplicitClient ? clientOrFlags : getLunoraClient();
|
|
35
|
-
const flagDefaults = hasExplicitClient ? flagsOrContext : clientOrFlags;
|
|
36
|
-
const context = (hasExplicitClient ? maybeContext : flagsOrContext) ?? void 0;
|
|
37
|
-
return readable(flagDefaults, (set) => {
|
|
38
|
-
let current = { ...flagDefaults };
|
|
39
|
-
const unsubscribes = [];
|
|
40
|
-
for (const [key, defaultValue] of Object.entries(flagDefaults)) {
|
|
41
|
-
unsubscribes.push(
|
|
42
|
-
subscribeFlag(client, key, defaultValue, context, (next) => {
|
|
43
|
-
current = { ...current, [key]: next };
|
|
44
|
-
set(current);
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return () => {
|
|
49
|
-
for (const unsubscribe of unsubscribes) {
|
|
50
|
-
unsubscribe();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { flag, flags };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { setContext, getContext } from 'svelte';
|
|
3
|
-
|
|
4
|
-
const LUNORA_CONTEXT_KEY = /* @__PURE__ */ Symbol("lunora.client");
|
|
5
|
-
const setLunoraClient = (client) => {
|
|
6
|
-
setContext(LUNORA_CONTEXT_KEY, client);
|
|
7
|
-
return client;
|
|
8
|
-
};
|
|
9
|
-
const getLunoraClient = () => {
|
|
10
|
-
const client = getContext(LUNORA_CONTEXT_KEY);
|
|
11
|
-
if (!client) {
|
|
12
|
-
throw new LunoraError("INTERNAL", "getLunoraClient(): no LunoraClient in context — call setLunoraClient(client) in an ancestor component first.");
|
|
13
|
-
}
|
|
14
|
-
return client;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { getLunoraClient, setLunoraClient };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const hydratePreloaded = (preloaded, client) => {
|
|
5
|
-
const resolvedClient = client ?? getLunoraClient();
|
|
6
|
-
const { args, functionPath, shardKey, value } = preloaded;
|
|
7
|
-
const functionRef = { __lunoraRef: functionPath };
|
|
8
|
-
return readable(
|
|
9
|
-
value,
|
|
10
|
-
(set) => resolvedClient.subscribe(
|
|
11
|
-
functionRef,
|
|
12
|
-
args,
|
|
13
|
-
(next) => {
|
|
14
|
-
set(next);
|
|
15
|
-
},
|
|
16
|
-
{ shardKey }
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { hydratePreloaded };
|