@lunora/solid 1.0.0-alpha.30 → 1.0.0-alpha.32
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 -19
- package/dist/packem_shared/AuthLoading-D6A1mBRs.mjs +1 -0
- package/dist/packem_shared/LunoraContext-CVOsskhY.mjs +1 -0
- package/dist/packem_shared/LunoraProvider-cifsrLab.mjs +1 -0
- package/dist/packem_shared/createAgent-BbHVxEpf.mjs +1 -0
- package/dist/packem_shared/createAgentChat-O-PgJtWE.mjs +1 -0
- package/dist/packem_shared/createAgentState-CbE2MP_H.mjs +1 -0
- package/dist/packem_shared/createAgentToolEvents-DOU_J3JT.mjs +1 -0
- package/dist/packem_shared/createConnectionStatus-B9ly5m1x.mjs +1 -0
- package/dist/packem_shared/createFlag-qBxuQ5hP.mjs +1 -0
- package/dist/packem_shared/createInfiniteQuery-CDLk3UVQ.mjs +1 -0
- package/dist/packem_shared/createMutation-9i34uh8U.mjs +1 -0
- package/dist/packem_shared/createMutator-zzxMk2QQ.mjs +1 -0
- package/dist/packem_shared/createPresence-DNVSvTzP.mjs +1 -0
- package/dist/packem_shared/createQuery-CFb7mUGW.mjs +1 -0
- package/dist/packem_shared/createRateLimit-BdVo3eNW.mjs +1 -0
- package/dist/packem_shared/createStream-DozkYNOc.mjs +1 -0
- package/dist/packem_shared/createSubscription-KbQk0ohZ.mjs +1 -0
- package/dist/packem_shared/createVoiceAgent-CzXF9acz.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-BbGFlPEb.mjs +1 -0
- package/dist/packem_shared/stable-key-BSG0zK_E.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.mjs +1 -2
- package/package.json +3 -3
- package/dist/packem_shared/AuthLoading-u5QJoV-J.mjs +0 -73
- package/dist/packem_shared/LunoraContext-C59PzHhN.mjs +0 -13
- package/dist/packem_shared/LunoraProvider-CzB3zGhy.mjs +0 -17
- package/dist/packem_shared/createAgent-D7EZBeql.mjs +0 -55
- package/dist/packem_shared/createAgentChat-Bq-wzSxv.mjs +0 -166
- package/dist/packem_shared/createAgentState-DckYu3G8.mjs +0 -21
- package/dist/packem_shared/createAgentToolEvents-UavTO16u.mjs +0 -99
- package/dist/packem_shared/createConnectionStatus-1poqwqR9.mjs +0 -14
- package/dist/packem_shared/createFlag-DQoGdUMB.mjs +0 -78
- package/dist/packem_shared/createInfiniteQuery-CD2GT1_O.mjs +0 -339
- package/dist/packem_shared/createMutation-LkrbhItI.mjs +0 -36
- package/dist/packem_shared/createMutator-foSnPJPt.mjs +0 -24
- package/dist/packem_shared/createPresence-DM2cVkiG.mjs +0 -85
- package/dist/packem_shared/createQuery-BUldvZXj.mjs +0 -28
- package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
- package/dist/packem_shared/createStream-D9ONbGAw.mjs +0 -70
- package/dist/packem_shared/createSubscription-D3HbChGe.mjs +0 -41
- package/dist/packem_shared/createVoiceAgent-hu59SaDl.mjs +0 -418
- package/dist/packem_shared/hydratePreloaded-CWny5-2J.mjs +0 -25
- package/dist/packem_shared/stable-key-DePnevIy.mjs +0 -38
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createAgent } from './packem_shared/createAgent-D7EZBeql.mjs';
|
|
3
|
-
export { createAgentChat } from './packem_shared/createAgentChat-Bq-wzSxv.mjs';
|
|
4
|
-
export { createAgentState } from './packem_shared/createAgentState-DckYu3G8.mjs';
|
|
5
|
-
export { createAgentToolEvents } from './packem_shared/createAgentToolEvents-UavTO16u.mjs';
|
|
6
|
-
export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/AuthLoading-u5QJoV-J.mjs';
|
|
7
|
-
export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-1poqwqR9.mjs';
|
|
8
|
-
export { createFlag, createFlags } from './packem_shared/createFlag-DQoGdUMB.mjs';
|
|
9
|
-
export { createMutation, createMutationForClient } from './packem_shared/createMutation-LkrbhItI.mjs';
|
|
10
|
-
export { createMutator } from './packem_shared/createMutator-foSnPJPt.mjs';
|
|
11
|
-
export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-CD2GT1_O.mjs';
|
|
12
|
-
export { createPresence } from './packem_shared/createPresence-DM2cVkiG.mjs';
|
|
13
|
-
export { createQuery } from './packem_shared/createQuery-BUldvZXj.mjs';
|
|
14
|
-
export { createRateLimit } from './packem_shared/createRateLimit-BA2f8XyF.mjs';
|
|
15
|
-
export { createStream } from './packem_shared/createStream-D9ONbGAw.mjs';
|
|
16
|
-
export { createSubscription } from './packem_shared/createSubscription-D3HbChGe.mjs';
|
|
17
|
-
export { createVoiceAgent } from './packem_shared/createVoiceAgent-hu59SaDl.mjs';
|
|
18
|
-
export { default as hydratePreloaded } from './packem_shared/hydratePreloaded-CWny5-2J.mjs';
|
|
19
|
-
export { LunoraProvider } from './packem_shared/LunoraProvider-CzB3zGhy.mjs';
|
|
1
|
+
import{LunoraContext as r,useLunora as o}from"./packem_shared/LunoraContext-CVOsskhY.mjs";import{createAgent as c}from"./packem_shared/createAgent-BbHVxEpf.mjs";import{createAgentChat as f}from"./packem_shared/createAgentChat-O-PgJtWE.mjs";import{createAgentState as p}from"./packem_shared/createAgentState-CbE2MP_H.mjs";import{createAgentToolEvents as u}from"./packem_shared/createAgentToolEvents-DOU_J3JT.mjs";import{AuthLoading as d,Authenticated as g,Unauthenticated as s,createAuth as A}from"./packem_shared/AuthLoading-D6A1mBRs.mjs";import{default as h}from"./packem_shared/createConnectionStatus-B9ly5m1x.mjs";import{createFlag as y,createFlags as C}from"./packem_shared/createFlag-qBxuQ5hP.mjs";import{createMutation as S,createMutationForClient as F}from"./packem_shared/createMutation-9i34uh8U.mjs";import{createMutator as Q}from"./packem_shared/createMutator-zzxMk2QQ.mjs";import{createInfiniteQuery as b,createPaginatedQuery as E}from"./packem_shared/createInfiniteQuery-CDLk3UVQ.mjs";import{createPresence as R}from"./packem_shared/createPresence-DNVSvTzP.mjs";import{createQuery as U}from"./packem_shared/createQuery-CFb7mUGW.mjs";import{createRateLimit as j}from"./packem_shared/createRateLimit-BdVo3eNW.mjs";import{createStream as q}from"./packem_shared/createStream-DozkYNOc.mjs";import{createSubscription as z}from"./packem_shared/createSubscription-KbQk0ohZ.mjs";import{createVoiceAgent as D}from"./packem_shared/createVoiceAgent-CzXF9acz.mjs";import{default as H}from"./packem_shared/hydratePreloaded-BbGFlPEb.mjs";import{LunoraProvider as K}from"./packem_shared/LunoraProvider-cifsrLab.mjs";export{d as AuthLoading,g as Authenticated,r as LunoraContext,K as LunoraProvider,s as Unauthenticated,c as createAgent,f as createAgentChat,p as createAgentState,u as createAgentToolEvents,A as createAuth,h as createConnectionStatus,y as createFlag,C as createFlags,b as createInfiniteQuery,S as createMutation,F as createMutationForClient,Q as createMutator,E as createPaginatedQuery,R as createPresence,U as createQuery,j as createRateLimit,q as createStream,z as createSubscription,D as createVoiceAgent,H as hydratePreloaded,o as useLunora};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createComponent as o,memo as u}from"solid-js/web";import{getIdentityStore as d}from"@lunora/client/auth";import{Show as l,createSignal as a,onCleanup as k}from"solid-js";import{useLunora as f}from"./LunoraContext-CVOsskhY.mjs";const s=()=>{const e=f(),t=d(e),[n,h]=a(e.getAuthToken()),[c,i]=a(t.getUser()),g=e.onAuthTokenChange(r=>{h(()=>r)}),m=t.subscribe(()=>{i(()=>t.getUser())});return k(()=>{g(),m()}),{setToken:r=>{e.setAuthToken(r)},token:n,user:c}},U=e=>{const{token:t,user:n}=s();return o(l,{get when(){return u(()=>t()===null)()?!1:n()!==null},get children(){return e.children}})},C=e=>{const{token:t,user:n}=s();return o(l,{get when(){return u(()=>t()===null)()?!1:n()===null},get children(){return e.children}})},S=e=>{const{token:t,user:n}=s();return o(l,{get when(){return u(()=>t()===null)()?n()===null:!1},get children(){return e.children}})};export{C as AuthLoading,U as Authenticated,S as Unauthenticated,s as createAuth};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as r}from"@lunora/errors";import{createContext as e,useContext as t}from"solid-js";const n=e(),a=()=>{const o=t(n);if(!o)throw new r("INTERNAL","useLunora must be used inside <LunoraProvider />");return o};export{n as LunoraContext,a as useLunora};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{LunoraContext as o}from"./LunoraContext-CVOsskhY.mjs";const i=r=>e(o.Provider,{get value(){return r.client},get children(){return r.children}});export{i as LunoraProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as c}from"solid-js";import{createMutation as i}from"./createMutation-9i34uh8U.mjs";import{createSubscription as l}from"./createSubscription-KbQk0ohZ.mjs";const A={__lunoraRef:""},r=t=>typeof t=="function"?t():t,I=t=>{const{api:u,cancel:s,run:d,runArgs:p,threadKey:e}=t,o=i(d),m=i(s??A),{data:y}=l(u.agents.agentThread,()=>({key:r(e)})),n=c(()=>y()),f=c(()=>n()?.status),g=async(a,h)=>{await o.mutate({input:a,threadKey:r(e),...p,...h})};return{cancel:async()=>{const a=n()?.instanceId;s===void 0||a===void 0||await m.mutate({instanceId:a,threadKey:r(e)})},pending:o.pending,run:g,status:f,thread:n}};export{A as NO_MUTATION_REF,I as createAgent,r as resolveMaybe};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as _,createMemo as m}from"solid-js";import{resolveMaybe as r,NO_MUTATION_REF as q}from"./createAgent-BbHVxEpf.mjs";import{createMutation as y}from"./createMutation-9i34uh8U.mjs";import{createStream as x}from"./createStream-DozkYNOc.mjs";import{createSubscription as A}from"./createSubscription-KbQk0ohZ.mjs";const N={__lunoraRef:""},k=(f,d)=>{const l=d.filter(i=>i.role==="user"),u=new Set;return f.filter(i=>{for(let o=i.durableUserCountAtSend;o<l.length;o+=1){const h=l[o];if(h!==void 0&&!u.has(o)&&h.content===i.content)return u.add(o),!1}return!0})},G=f=>{const{api:d,cancel:l,limit:u,send:i,sendArgs:o,stream:h,threadKey:a}=f,{data:C}=A(d.agents.agentMessages,()=>{const e=r(a);return u===void 0?{key:e}:{key:e,limit:u}}),{data:K}=A(d.agents.agentThread,()=>({key:r(a)})),S=h===void 0?"skip":()=>({key:r(a)}),{chunks:M}=x(h??N,S),b=y(i),T=y(l??q),v=y(d.agents.agentResolveApproval),[$,I]=_([]);let w=0;const g=m(()=>K()),j=m(()=>g()?.status),p=m(()=>C()??[]),E=m(()=>{const e=p(),n=k($(),e);if(n.length===0)return e;let t=-1;for(const c of e)c.seq>t&&(t=c.seq);return[...e,...n.map((c,s)=>({content:c.content,optimistic:!0,role:"user",seq:t+1+s}))]}),O=m(()=>{const e=r(a),n=p().filter(t=>t.role==="assistant").length;return M().filter(t=>t.kind!=="progress"&&t.threadKey===e&&t.turn>=n).map(t=>t.text).join("")});return{approve:async(e,n)=>{const t=g()?.instanceId;if(t===void 0)throw new Error("createAgentChat: cannot approve — no in-flight run (thread has no instanceId)");await v.mutate({decision:"approve",instanceId:t,threadKey:r(a),toolCallId:e,...n===void 0?{}:{note:n}})},cancel:async()=>{const e=g()?.instanceId;l===void 0||e===void 0||await T.mutate({instanceId:e,threadKey:r(a)})},messages:E,reject:async(e,n)=>{const t=g()?.instanceId;if(t===void 0)throw new Error("createAgentChat: cannot reject — no in-flight run (thread has no instanceId)");await v.mutate({decision:"reject",instanceId:t,threadKey:r(a),toolCallId:e,...n===void 0?{}:{note:n}})},send:async(e,n)=>{const t=w;w+=1;const c=p().filter(s=>s.role==="user").length;I(s=>[...k(s,p()),{content:e,durableUserCountAtSend:c,id:t}]);try{await b.mutate({input:e,threadKey:r(a),...o,...n})}catch(s){throw I(R=>R.filter(U=>U.id!==t)),s}},status:j,streamingText:O}};export{G as createAgentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as o}from"solid-js";import{resolveMaybe as s}from"./createAgent-BbHVxEpf.mjs";import{createSubscription as n}from"./createSubscription-KbQk0ohZ.mjs";const p=t=>{const{data:e,error:r}=n(t.api.agents.agentState,()=>({key:s(t.threadKey)})),a=o(()=>e());return{error:r,state:a}};export{p as createAgentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as c}from"solid-js";import{resolveMaybe as e}from"./createAgent-BbHVxEpf.mjs";import{createStream as v}from"./createStream-DozkYNOc.mjs";import{createSubscription as C}from"./createSubscription-KbQk0ohZ.mjs";const f={__lunoraRef:""},y=[],g=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(a=>({input:a.input,seq:t.seq,toolCallId:a.id,toolName:a.name,type:"call"}));if(t.role==="tool")return t.status==="awaiting_approval"?[{seq:t.seq,type:"awaiting-approval",...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]:[{output:t.content,seq:t.seq,type:"result",...t.status==="approved"||t.status==="rejected"?{status:t.status}:{},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]},h=t=>{const{api:a,limit:r,stream:i,threadKey:s}=t,n=()=>{const l=e(s);return r===void 0?{key:l}:{key:l,limit:r}},{data:d}=C(a.agents.agentMessages,n),m=i===void 0?"skip":()=>({key:e(s)}),{chunks:u}=v(i??f,m);return{events:c(()=>{const l=e(s),p=(d()??y).flatMap(o=>g(o)??[]);for(const o of u())o.kind==="progress"&&o.threadKey===l&&p.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return p})}};export{h as createAgentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as r,onCleanup as u}from"solid-js";import{useLunora as c}from"./LunoraContext-CVOsskhY.mjs";const m=()=>{const n=c(),[o,t]=r(n.connectionStatus()),e=n.onConnectionStatus(a=>{t(a)});return u(e),o};export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as p,createEffect as b,on as y,onCleanup as _}from"solid-js";import{e as m}from"./stable-key-BSG0zK_E.mjs";import{useLunora as g}from"./LunoraContext-CVOsskhY.mjs";const j="__lunora_flags__:eval",x=t=>{const o=typeof t;return o==="boolean"||o==="number"||o==="string"?o:"object"},d={__lunoraRef:j},e=t=>typeof t=="function"?t():t,h=t=>t===void 0?"":m(t),A=(t,o,n)=>{const f=g(),a=x(o),[l,s]=p(o);return b(y(()=>`${e(t)} ${h(e(n))}`,()=>{const u=e(t),r=e(n);s(()=>o);let c;try{c=f.subscribe(d,{context:r,default:o,key:u,type:a},i=>{s(()=>i)})}catch{return}_(c)})),l},E=(t,o)=>{const n=g(),[f,a]=p(t),l=m(t);return b(y(()=>`${l} ${h(e(o))}`,()=>{const s=e(o);a(()=>t);const u=[];for(const[r,c]of Object.entries(t))try{u.push(n.subscribe(d,{context:s,default:c,key:r,type:x(c)},i=>{a(k=>({...k,[r]:i}))}))}catch{}_(()=>{for(const r of u)r()})})),f};export{A as createFlag,E as createFlags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as U,derivePaginationStatus as E,applyLoadMore as G,rebalance as H}from"@lunora/client/pagination";import{createMemo as P,createSignal as F,createEffect as B,on as Q,onCleanup as V}from"solid-js";import{e as J}from"./stable-key-BSG0zK_E.mjs";import{useLunora as W}from"./LunoraContext-CVOsskhY.mjs";const j=e=>{let o="";for(let f=0;f<e.length;f+=32768)o+=String.fromCharCode(...e.subarray(f,f+32768));return btoa(o)},u="$lunora.wire$",D=64,h=(e,o=0)=>{if(o>D)throw new RangeError(`wire-codec: value nesting exceeds the ${D}-level limit`);if(e===void 0)return[u,"undefined"];if(e===null)return null;const f=typeof e;if(f==="bigint")return[u,"bigint",e.toString()];if(f==="number"){const t=e;return Number.isNaN(t)?[u,"nan"]:t===1/0?[u,"inf"]:t===-1/0?[u,"-inf"]:t}if(f!=="object")return e;if(e instanceof Date)return[u,"date",h(e.getTime(),o+1)];if(e instanceof Error){const t=e,n={};for(const c of Object.keys(t))t[c]!==void 0&&(n[c]=h(t[c],o+1));const l=[u,"error",t.name,t.message,n];return t.cause!==void 0&&l.push(h(t.cause,o+1)),l}if(e instanceof URL)return[u,"url",e.href];if(e instanceof Map)return[u,"map",[...e.entries()].map(([t,n])=>[h(t,o+1),h(n,o+1)])];if(e instanceof Set)return[u,"set",[...e].map(t=>h(t,o+1))];if(e instanceof ArrayBuffer)return[u,"bytes",j(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,n=t.constructor.name,l=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return n==="Uint8Array"?[u,"bytes",j(l)]:[u,"bytes",j(l),n]}if(Array.isArray(e)){const t=e.map(n=>h(n,o+1));return t.length>0&&t[0]===u?[u,"arr",t]:t}const w=Object.getPrototypeOf(e);if(w!==null&&w!==Object.prototype){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 m=e,g={};for(const t of Object.keys(m)){const n=m[t];n!==void 0&&(g[t]=h(n,o+1))}return g},X=e=>J(h(e)),v=(e,o)=>({...o,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),R=(e,o)=>`${e}::${X(o)}`,K=(e,o,f)=>{const w=W(),{initialNumItems:m,shardKey:g}=f,t=()=>typeof o=="function"?o():o,[n,l]=F(U(m)),c=new Map,[_,M]=F([]),y=new Map,A=new Set,S=(r,i)=>{const p=r.map(s=>{const a=R(e.__lunoraRef,v(s,i));return c.get(a)});M(p)},T=(r,i,p)=>{const s=a=>R(e.__lunoraRef,v(a,p));for(const a of i){const d=s(a);if(c.has(d))continue;const L=r.find(b=>b.lower===a.lower);if(L){const b=c.get(s(L));b&&c.set(d,b)}}},q=(r,i)=>{const p=new Set;for(const s of r)p.add(R(e.__lunoraRef,v(s,i)));for(const[s,a]of y)p.has(s)||(a(),y.delete(s),A.delete(s),c.delete(s));for(const s of r){const a=v(s,i),d=R(e.__lunoraRef,a);if(y.has(d))continue;A.add(d);const L=w.subscribe(e,a,b=>{c.set(d,b),A.delete(d);const k=t();if(k!=="skip"&&(S(n(),k),A.size===0)){const O=n(),$=H(O,_());$&&(T(O,$,k),l($))}},{shardKey:g});y.set(d,L)}};let C=!1,N=!1;const x=(r,i)=>{if(C){N=!0;return}C=!0;try{let p=r,s=i;do{N=!1,q(p,s);const a=t();if(a==="skip")break;p=n(),s=a}while(N)}finally{C=!1}},I=()=>{for(const r of y.values())r();y.clear(),c.clear(),A.clear()};B(Q(t,r=>{I(),l(U(m)),M([]),r!=="skip"&&(x(n(),r),S(n(),r)),V(I)})),B(Q(n,r=>{const i=t();i!=="skip"&&(x(r,i),S(r,i))}));const z=P(()=>{const r=t()==="skip";return E(r,_()).status});return{loadMore:r=>{const i=t();if(i==="skip")return;const{nextCursor:p,status:s}=E(!1,_());if(s!=="CanLoadMore")return;const a=G(n(),p,r);if(!a)return;const d=n().at(-1),L=a.at(-2);if(d&&L){const b=R(e.__lunoraRef,v(d,i)),k=R(e.__lunoraRef,v(L,i));if(b!==k){const O=c.get(b);O&&c.set(k,O)}}l(a)},pageResults:_,status:z}},ne=(e,o,f)=>{const{loadMore:w,pageResults:m,status:g}=K(e,o,f),t=P(()=>{const n=[];for(const l of m())l&&n.push(...l.page);return n});return{isLoading:P(()=>g()==="LoadingFirstPage"||g()==="LoadingMore"),loadMore:w,results:t,status:g}},oe=(e,o,f)=>{const{initialNumItems:w}=f,{loadMore:m,pageResults:g,status:t}=K(e,o,f),n=P(()=>{const M=[];for(const y of g())y&&M.push(y.page);return M}),l=P(()=>t()==="LoadingFirstPage"),c=P(()=>t()==="CanLoadMore"),_=P(()=>t()==="LoadingMore");return{fetchNextPage:M=>{m(M??w)},hasNextPage:c,isFetchingNextPage:_,isLoading:l,pages:n,status:t}};export{oe as createInfiniteQuery,ne as createPaginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutationRunner as d}from"@lunora/client";import{createSignal as a}from"solid-js";import{useLunora as p}from"./LunoraContext-CVOsskhY.mjs";const f=(e,r)=>{const[o,t]=a(void 0),[n,i]=a(void 0),[u,s]=a(!1),m=d(e,r,{setError:i,setPending:s,setResult:c=>{t(()=>c),i(void 0)}});return{data:o,error:n,mutate:m,pending:u,reset:()=>{t(()=>{}),i(void 0)}}},M=e=>{const r=p();return f({mutation:(o,t,n)=>r.mutation(o,t,n)},e)};export{M as createMutation,f as createMutationForClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as m}from"@lunora/client";import{createSignal as t}from"solid-js";const d=e=>{const[r,o]=t(void 0),[n,a]=t(!1),{mutate:i,reset:s}=m(e,{setError:o,setPending:a});return{error:r,isError:()=>r()!==void 0,mutate:i,pending:n,reset:s}};export{d as createMutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as g,onMount as h,onCleanup as b}from"solid-js";import{useLunora as S}from"./LunoraContext-CVOsskhY.mjs";const U=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},$=1e4,L=(e,t)=>{const o=S(),{heartbeat:d,intervalMs:u=$,listPresent:m,shardKey:s}=t,a=t.sessionId??U(),[y,p]=g(void 0);let i=t.data;const r=()=>{const n={roomId:e,sessionId:a,...i===void 0?{}:{data:i}};o.mutation(d,n,{shardKey:s}).catch(()=>{})},f=n=>{i=n,r()};return h(()=>{r();const n=setInterval(r,u),c=()=>{typeof document<"u"&&document.visibilityState==="visible"&&r()};typeof document<"u"&&document.addEventListener("visibilitychange",c);const l=o.acquireConnectionContext({roomId:e,sessionId:a},{shardKey:s}),v=o.subscribe(m,{roomId:e},I=>{p(()=>I)},{shardKey:s});b(()=>{clearInterval(n),typeof document<"u"&&document.removeEventListener("visibilitychange",c),l(),v()})}),{present:y,sessionId:a,setData:f}};export{L as createPresence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as u}from"@lunora/client/query";import{createSignal as p,createEffect as m,on as y,onCleanup as d}from"solid-js";import{useLunora as h}from"./LunoraContext-CVOsskhY.mjs";const S=(e,o,t={})=>{const n=h(),{shardKey:a}=t,[c,r]=p(void 0);return m(y(()=>typeof o=="function"?o():o,s=>{const f=u(n,e,s,{onData:i=>{r(()=>i)},onReset:()=>{r(()=>{})}},{shardKey:a});d(f)})),c};export{S as createQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as l}from"@lunora/ratelimit";import{createSignal as k,createMemo as w,onCleanup as p}from"solid-js";const I=(s,v={})=>{const n=v.now??Date.now,m=v.tickMs??1e3;let t;const[f,d]=k(0),a=()=>{d(e=>e+1)},o=w(()=>{const e=n()+f()*0;return l(s,t,{consume:!1,count:1,now:e,reserve:!1}).status});let r;const c=()=>{r!==void 0&&(clearInterval(r),r=void 0)},i=()=>{o().ok||r!==void 0||(r=setInterval(()=>{a(),o().ok&&c()},m))};return p(c),i(),{check:(e=1)=>l(s,t,{consume:!1,count:e,now:n(),reserve:!1}).status.ok,consume:(e=1)=>{const u=l(s,t,{consume:!0,count:e,now:n(),reserve:!1});return u.value!==void 0&&(t=u.value),a(),i(),u.status},disabled:()=>!o().ok,ok:()=>o().ok,reset:()=>{t=void 0,c(),a()},retryAfter:()=>o().retryAfter}};export{I as createRateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as c,createEffect as k,on as v,onCleanup as p}from"solid-js";import{useLunora as w}from"./LunoraContext-CVOsskhY.mjs";const K=(d,o,s={})=>{const y=w(),[h,f]=c([]),[g,i]=c(void 0),[S,e]=c("idle"),x=typeof o=="function"?o:()=>o;let t;const u=()=>{t?.()};return k(v(x,l=>{if(f(()=>[]),i(()=>{}),l==="skip"){e("idle");return}e("streaming");let n=!0;const m=y.stream(d,l,{maxBuffer:s.maxBuffer,shardKey:s.shardKey}),a=()=>{m.cancel()};t=a,(async()=>{try{for await(const r of m){if(!n)return;f(E=>[...E,r])}n&&e("complete")}catch(r){if(!n)return;i(()=>r instanceof Error?r:new Error(String(r))),e("error")}})().catch(()=>{}),p(()=>{n=!1,a(),t===a&&(t=void 0)})})),p(()=>{u()}),{cancel:u,chunks:h,error:g,status:S}};export{K as createStream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as d}from"@lunora/client/query";import{LunoraError as y}from"@lunora/errors";import{createSignal as a,createEffect as E,on as g,onCleanup as S}from"solid-js";import{useLunora as b}from"./LunoraContext-CVOsskhY.mjs";const K=(s,e,c={})=>{const i=b(),[p,o]=a(void 0),[u,t]=a(void 0);return E(g(typeof e=="function"?e:()=>e,n=>{if(n==="skip"){o(()=>{}),t(()=>{});return}const f=d(i,s,n,{onData:r=>{o(()=>r),t(()=>{})},onError:r=>{const m=r.code?new y(r.code,r.message):new Error(r.message);t(()=>m),o(()=>{})},onReset:()=>{o(()=>{})}},{shardKey:c.shardKey});S(f)})),{data:p,error:u}};export{K as createSubscription};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as w,onCleanup as N}from"solid-js";import{useLunora as O}from"./LunoraContext-CVOsskhY.mjs";import{resolveMaybe as J}from"./createAgent-BbHVxEpf.mjs";const K=t=>{if(t.length===0)return 0;let o=0;for(const n of t)o+=n*n;return Math.sqrt(o/t.length)},z=(t,o)=>{const n=o/16e3,a=n>1?Math.floor(t.length/n):t.length,l=new ArrayBuffer(a*2),i=new DataView(l);for(let u=0;u<a;u+=1){const g=t[Math.floor(u*n)]??0,h=Math.max(-1,Math.min(1,g));i.setInt16(u*2,h<0?h*32768:h*32767,!0)}return new Uint8Array(l)},G=async t=>{const o=globalThis,n=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),a=o.AudioContext??o.webkitAudioContext;if(!n||!a)throw new Error("createVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,u=i.createMediaStreamSource(l),g=i.createScriptProcessor(4096,1,1);let h=!1,y=!1,p=0,d=0;return g.onaudioprocess=s=>{const f=s.inputBuffer.getChannelData(0),k=h?0:K(f);if(t.onLevel(k),h)return;if(t.onAudio(z(f,i.sampleRate)),t.isSpeaking()){d=k>=t.interruptThreshold?d+1:0,d>=t.interruptChunks&&(d=0,t.onInterrupt());return}d=0;const C=f.length/i.sampleRate*1e3;if(k>=t.silenceThreshold){y=!0,p=0;return}y&&(p+=C,p>=t.silenceDurationMs&&(y=!1,p=0,t.onSilence()))},u.connect(g),g.connect(i.destination),{setMuted:s=>{h=s},stop:()=>{g.disconnect(),u.disconnect();for(const s of l.getTracks())s.stop();i.close()}}},H=()=>{const t=globalThis,o=t.AudioContext??t.webkitAudioContext;if(!o)throw new Error("createVoiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new o,a=new Set;let l=0,i=Promise.resolve(),u=0;const g=async(p,d)=>{if(d!==u)return;let s;try{s=await n.decodeAudioData(p.buffer)}catch{return}if(d!==u)return;const f=n.createBufferSource();f.buffer=s,f.connect(n.destination);const k=Math.max(n.currentTime,l);f.start(k),l=k+s.duration,a.add(f),f.onended=()=>{a.delete(f)}},h=p=>{const d=Uint8Array.from(p),s=u;i=i.then(()=>g(d,s))},y=()=>{u+=1;for(const p of a)try{p.stop()}catch{}a.clear(),l=n.currentTime};return{enqueue:h,interrupt:y,stop:()=>{y(),n.close()}}},W=1,Q=.01,X=1200,Y=.15,Z=3,j=t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,ee=t=>{const o=t.__lunoraRef,n=o.startsWith("agents:")?o.slice(7):o;return n.endsWith("Voice")?n.slice(0,-5):n},te=(t,o,n)=>{const a=j(t),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:n});return`${l}/_lunora/voice/${encodeURIComponent(o)}?${i.toString()}`},oe=t=>{const{createMicrophone:o=G,createSpeaker:n=H,createSocket:a,interruptChunks:l=Z,interruptThreshold:i=Y,silenceDurationMs:u=X,silenceThreshold:g=Q,threadKey:h,voice:y}=t,p=O(),[d,s]=w("idle"),[f,k]=w(!1),[C,T]=w(""),[_,A]=w(""),[F,D]=w(0),[U,E]=w(!1),[L,S]=w(void 0);let c,v=!1;const x=r=>{const e=c?.socket;return e?.readyState===W?(e.send(JSON.stringify(r)),!0):!1},M=()=>{const r=c;if(c=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}v=!1,k(!1),s("idle"),D(0)},R=()=>{M()},$=r=>{const e=c;switch(r.type){case"assistant_delta":{e&&(e.speaking=!0),s("speaking"),A(b=>b+r.text);break}case"assistant_done":{e&&(e.speaking=!1),A(r.text),s("listening");break}case"error":{e&&(e.speaking=!1),S(new Error(r.message)),s("listening");break}case"interrupted":{e&&(e.speaking=!1,e.suppressAudio=!1),e?.speaker?.interrupt(),s("listening");break}case"ready":{e&&(e.audioFormat=r.audioFormat,e.suppressAudio=!1),k(!0),s("listening");break}case"user_transcript":{e&&(e.suppressAudio=!1),T(r.text),A(""),s("thinking");break}}},q=r=>{const e=c;!e||e.suppressAudio||(e.speaker??=n({audioFormat:e.audioFormat}),e.speaking=!0,s("speaking"),e.speaker.enqueue(r))},I=async()=>{if(!(c||v)){v=!0,S(void 0),T(""),A("");try{const r=te(p.url,ee(y),J(h)),e=(a??(m=>new globalThis.WebSocket(m)))(r);e.binaryType="arraybuffer";const b={audioFormat:"mp3",microphone:void 0,socket:e,speaker:void 0,speaking:!1,suppressAudio:!1};c=b,e.onmessage=m=>{if(typeof m.data=="string"){try{$(JSON.parse(m.data))}catch{}return}q(new Uint8Array(m.data))},e.onerror=()=>{S(new Error("createVoiceAgent: voice socket error"))},e.onclose=()=>{c===b&&M()};const V=await o({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:m=>{e.readyState===W&&e.send(m)},onInterrupt:()=>{x({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),s("listening")},onLevel:m=>{D(m)},onSilence:()=>{x({type:"commit"}),s("thinking")},silenceDurationMs:u,silenceThreshold:g});c===b?(b.microphone=V,E(!1),s("listening")):V.stop()}catch(r){S(r instanceof Error?r:new Error(String(r))),M()}finally{v=!1}}},B=()=>{const r=!U();return c?.microphone?.setMuted(r),E(r),r},P=r=>{x({text:r,type:"text"})&&s("thinking")};return N(M),{audioLevel:F,connected:f,endCall:R,error:L,interimTranscript:_,isMuted:U,sendText:P,startCall:I,status:d,toggleMute:B,transcript:C}};export{oe as createVoiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as l,createEffect as m,onCleanup as p}from"solid-js";import{useLunora as d}from"./LunoraContext-CVOsskhY.mjs";const g=r=>{const e=d(),{args:a,functionPath:t,shardKey:o,value:n}=r,[s,u]=l(n),c={__lunoraRef:t};return m(()=>{const f=e.subscribe(c,a,i=>u(()=>i),{shardKey:o});p(f)}),s};export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const y=(e,t)=>e<t?-1:e>t?1:0,s=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(r=>s(r)).join(",")}]`;const t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype){const r=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${r} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const n=e,a=Object.keys(n).toSorted(y),i=[];for(const r of a){const o=n[r];o!==void 0&&i.push(`${JSON.stringify(r)}:${s(o)}`)}return`{${i.join(",")}}`};export{s as e};
|
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/solid';
|
|
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/solid";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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/solid",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.32",
|
|
4
4
|
"description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.30",
|
|
58
58
|
"@lunora/errors": "1.0.0-alpha.8",
|
|
59
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.11",
|
|
60
60
|
"@visulima/storage-client": "1.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { createComponent, memo } from 'solid-js/web';
|
|
2
|
-
import { getIdentityStore } from '@lunora/client/auth';
|
|
3
|
-
import { Show, createSignal, onCleanup } from 'solid-js';
|
|
4
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
5
|
-
|
|
6
|
-
const createAuth = () => {
|
|
7
|
-
const client = useLunora();
|
|
8
|
-
const store = getIdentityStore(client);
|
|
9
|
-
const [token, setTokenSignal] = createSignal(client.getAuthToken());
|
|
10
|
-
const [user, setUserSignal] = createSignal(store.getUser());
|
|
11
|
-
const unsubToken = client.onAuthTokenChange((next) => {
|
|
12
|
-
setTokenSignal(() => next);
|
|
13
|
-
});
|
|
14
|
-
const unsubUser = store.subscribe(() => {
|
|
15
|
-
setUserSignal(() => store.getUser());
|
|
16
|
-
});
|
|
17
|
-
onCleanup(() => {
|
|
18
|
-
unsubToken();
|
|
19
|
-
unsubUser();
|
|
20
|
-
});
|
|
21
|
-
const setToken = (next) => {
|
|
22
|
-
client.setAuthToken(next);
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
setToken,
|
|
26
|
-
token,
|
|
27
|
-
user
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const Authenticated = (props) => {
|
|
31
|
-
const {
|
|
32
|
-
token,
|
|
33
|
-
user
|
|
34
|
-
} = createAuth();
|
|
35
|
-
return createComponent(Show, {
|
|
36
|
-
get when() {
|
|
37
|
-
return memo(() => token() === null)() ? false : user() !== null;
|
|
38
|
-
},
|
|
39
|
-
get children() {
|
|
40
|
-
return props.children;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const AuthLoading = (props) => {
|
|
45
|
-
const {
|
|
46
|
-
token,
|
|
47
|
-
user
|
|
48
|
-
} = createAuth();
|
|
49
|
-
return createComponent(Show, {
|
|
50
|
-
get when() {
|
|
51
|
-
return memo(() => token() === null)() ? false : user() === null;
|
|
52
|
-
},
|
|
53
|
-
get children() {
|
|
54
|
-
return props.children;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const Unauthenticated = (props) => {
|
|
59
|
-
const {
|
|
60
|
-
token,
|
|
61
|
-
user
|
|
62
|
-
} = createAuth();
|
|
63
|
-
return createComponent(Show, {
|
|
64
|
-
get when() {
|
|
65
|
-
return memo(() => token() === null)() ? user() === null : false;
|
|
66
|
-
},
|
|
67
|
-
get children() {
|
|
68
|
-
return props.children;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export { AuthLoading, Authenticated, Unauthenticated, createAuth };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { createContext, useContext } from 'solid-js';
|
|
3
|
-
|
|
4
|
-
const LunoraContext = createContext();
|
|
5
|
-
const useLunora = () => {
|
|
6
|
-
const client = useContext(LunoraContext);
|
|
7
|
-
if (!client) {
|
|
8
|
-
throw new LunoraError("INTERNAL", "useLunora must be used inside <LunoraProvider />");
|
|
9
|
-
}
|
|
10
|
-
return client;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { LunoraContext, useLunora };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createComponent } from 'solid-js/web';
|
|
2
|
-
import { LunoraContext } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
-
|
|
4
|
-
const LunoraProvider = (props) => (
|
|
5
|
-
// `props.client` is read lazily inside the JSX so Solid tracks it: swapping
|
|
6
|
-
// the client prop re-provides the new value to descendants.
|
|
7
|
-
createComponent(LunoraContext.Provider, {
|
|
8
|
-
get value() {
|
|
9
|
-
return props.client;
|
|
10
|
-
},
|
|
11
|
-
get children() {
|
|
12
|
-
return props.children;
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export { LunoraProvider };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createMemo } from 'solid-js';
|
|
2
|
-
import { createMutation } from './createMutation-LkrbhItI.mjs';
|
|
3
|
-
import { createSubscription } from './createSubscription-D3HbChGe.mjs';
|
|
4
|
-
|
|
5
|
-
const NO_MUTATION_REF = {
|
|
6
|
-
__lunoraRef: ""
|
|
7
|
-
};
|
|
8
|
-
const resolveMaybe = (value) => typeof value === "function" ? value() : value;
|
|
9
|
-
const createAgent = (options) => {
|
|
10
|
-
const {
|
|
11
|
-
api,
|
|
12
|
-
cancel: cancelReference,
|
|
13
|
-
run: runReference,
|
|
14
|
-
runArgs,
|
|
15
|
-
threadKey
|
|
16
|
-
} = options;
|
|
17
|
-
const runMutation = createMutation(runReference);
|
|
18
|
-
const cancelMutation = createMutation(cancelReference ?? NO_MUTATION_REF);
|
|
19
|
-
const {
|
|
20
|
-
data: threadData
|
|
21
|
-
} = createSubscription(api.agents.agentThread, () => {
|
|
22
|
-
return {
|
|
23
|
-
key: resolveMaybe(threadKey)
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
const thread = createMemo(() => threadData());
|
|
27
|
-
const status = createMemo(() => thread()?.status);
|
|
28
|
-
const run = async (input, arguments_) => {
|
|
29
|
-
await runMutation.mutate({
|
|
30
|
-
input,
|
|
31
|
-
threadKey: resolveMaybe(threadKey),
|
|
32
|
-
...runArgs,
|
|
33
|
-
...arguments_
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const cancel = async () => {
|
|
37
|
-
const instanceId = thread()?.instanceId;
|
|
38
|
-
if (cancelReference === void 0 || instanceId === void 0) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
await cancelMutation.mutate({
|
|
42
|
-
instanceId,
|
|
43
|
-
threadKey: resolveMaybe(threadKey)
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
cancel,
|
|
48
|
-
pending: runMutation.pending,
|
|
49
|
-
run,
|
|
50
|
-
status,
|
|
51
|
-
thread
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export { NO_MUTATION_REF, createAgent, resolveMaybe };
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createSignal, createMemo } from 'solid-js';
|
|
2
|
-
import { resolveMaybe, NO_MUTATION_REF } from './createAgent-D7EZBeql.mjs';
|
|
3
|
-
import { createMutation } from './createMutation-LkrbhItI.mjs';
|
|
4
|
-
import { createStream } from './createStream-D9ONbGAw.mjs';
|
|
5
|
-
import { createSubscription } from './createSubscription-D3HbChGe.mjs';
|
|
6
|
-
|
|
7
|
-
const NO_STREAM_REF = {
|
|
8
|
-
__lunoraRef: ""
|
|
9
|
-
};
|
|
10
|
-
const reconcileOptimistic = (optimistic, durable) => {
|
|
11
|
-
const durableUserRows = durable.filter((message) => message.role === "user");
|
|
12
|
-
const consumed = /* @__PURE__ */ new Set();
|
|
13
|
-
return optimistic.filter((pending) => {
|
|
14
|
-
for (let index = pending.durableUserCountAtSend; index < durableUserRows.length; index += 1) {
|
|
15
|
-
const row = durableUserRows[index];
|
|
16
|
-
if (row !== void 0 && !consumed.has(index) && row.content === pending.content) {
|
|
17
|
-
consumed.add(index);
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
const createAgentChat = (options) => {
|
|
25
|
-
const {
|
|
26
|
-
api,
|
|
27
|
-
cancel: cancelReference,
|
|
28
|
-
limit,
|
|
29
|
-
send: sendReference,
|
|
30
|
-
sendArgs,
|
|
31
|
-
stream: streamReference,
|
|
32
|
-
threadKey
|
|
33
|
-
} = options;
|
|
34
|
-
const {
|
|
35
|
-
data: history
|
|
36
|
-
} = createSubscription(api.agents.agentMessages, () => {
|
|
37
|
-
const key = resolveMaybe(threadKey);
|
|
38
|
-
return limit === void 0 ? {
|
|
39
|
-
key
|
|
40
|
-
} : {
|
|
41
|
-
key,
|
|
42
|
-
limit
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
const {
|
|
46
|
-
data: threadData
|
|
47
|
-
} = createSubscription(api.agents.agentThread, () => {
|
|
48
|
-
return {
|
|
49
|
-
key: resolveMaybe(threadKey)
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
const streamArguments = streamReference === void 0 ? "skip" : () => {
|
|
53
|
-
return {
|
|
54
|
-
key: resolveMaybe(threadKey)
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
const {
|
|
58
|
-
chunks
|
|
59
|
-
} = createStream(streamReference ?? NO_STREAM_REF, streamArguments);
|
|
60
|
-
const sendMutation = createMutation(sendReference);
|
|
61
|
-
const cancelMutation = createMutation(cancelReference ?? NO_MUTATION_REF);
|
|
62
|
-
const approvalMutation = createMutation(api.agents.agentResolveApproval);
|
|
63
|
-
const [optimistic, setOptimistic] = createSignal([]);
|
|
64
|
-
let nextId = 0;
|
|
65
|
-
const thread = createMemo(() => threadData());
|
|
66
|
-
const status = createMemo(() => thread()?.status);
|
|
67
|
-
const durable = createMemo(() => history() ?? []);
|
|
68
|
-
const messages = createMemo(() => {
|
|
69
|
-
const rows = durable();
|
|
70
|
-
const visible = reconcileOptimistic(optimistic(), rows);
|
|
71
|
-
if (visible.length === 0) {
|
|
72
|
-
return rows;
|
|
73
|
-
}
|
|
74
|
-
let maxDurableSeq = -1;
|
|
75
|
-
for (const message of rows) {
|
|
76
|
-
if (message.seq > maxDurableSeq) {
|
|
77
|
-
maxDurableSeq = message.seq;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return [...rows, ...visible.map((pending, index) => {
|
|
81
|
-
return {
|
|
82
|
-
content: pending.content,
|
|
83
|
-
optimistic: true,
|
|
84
|
-
role: "user",
|
|
85
|
-
seq: maxDurableSeq + 1 + index
|
|
86
|
-
};
|
|
87
|
-
})];
|
|
88
|
-
});
|
|
89
|
-
const streamingText = createMemo(() => {
|
|
90
|
-
const key = resolveMaybe(threadKey);
|
|
91
|
-
const assistantCount = durable().filter((message) => message.role === "assistant").length;
|
|
92
|
-
return chunks().filter((event) => event.kind !== "progress" && event.threadKey === key && event.turn >= assistantCount).map((delta) => delta.text).join("");
|
|
93
|
-
});
|
|
94
|
-
const send = async (input, arguments_) => {
|
|
95
|
-
const id = nextId;
|
|
96
|
-
nextId += 1;
|
|
97
|
-
const durableUserCountAtSend = durable().filter((message) => message.role === "user").length;
|
|
98
|
-
setOptimistic((previous) => [...reconcileOptimistic(previous, durable()), {
|
|
99
|
-
content: input,
|
|
100
|
-
durableUserCountAtSend,
|
|
101
|
-
id
|
|
102
|
-
}]);
|
|
103
|
-
try {
|
|
104
|
-
await sendMutation.mutate({
|
|
105
|
-
input,
|
|
106
|
-
threadKey: resolveMaybe(threadKey),
|
|
107
|
-
...sendArgs,
|
|
108
|
-
...arguments_
|
|
109
|
-
});
|
|
110
|
-
} catch (error) {
|
|
111
|
-
setOptimistic((previous) => previous.filter((pending) => pending.id !== id));
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const approve = async (toolCallId, note) => {
|
|
116
|
-
const instanceId = thread()?.instanceId;
|
|
117
|
-
if (instanceId === void 0) {
|
|
118
|
-
throw new Error("createAgentChat: cannot approve — no in-flight run (thread has no instanceId)");
|
|
119
|
-
}
|
|
120
|
-
await approvalMutation.mutate({
|
|
121
|
-
decision: "approve",
|
|
122
|
-
instanceId,
|
|
123
|
-
threadKey: resolveMaybe(threadKey),
|
|
124
|
-
toolCallId,
|
|
125
|
-
...note === void 0 ? {} : {
|
|
126
|
-
note
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
const reject = async (toolCallId, note) => {
|
|
131
|
-
const instanceId = thread()?.instanceId;
|
|
132
|
-
if (instanceId === void 0) {
|
|
133
|
-
throw new Error("createAgentChat: cannot reject — no in-flight run (thread has no instanceId)");
|
|
134
|
-
}
|
|
135
|
-
await approvalMutation.mutate({
|
|
136
|
-
decision: "reject",
|
|
137
|
-
instanceId,
|
|
138
|
-
threadKey: resolveMaybe(threadKey),
|
|
139
|
-
toolCallId,
|
|
140
|
-
...note === void 0 ? {} : {
|
|
141
|
-
note
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
const cancel = async () => {
|
|
146
|
-
const instanceId = thread()?.instanceId;
|
|
147
|
-
if (cancelReference === void 0 || instanceId === void 0) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
await cancelMutation.mutate({
|
|
151
|
-
instanceId,
|
|
152
|
-
threadKey: resolveMaybe(threadKey)
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return {
|
|
156
|
-
approve,
|
|
157
|
-
cancel,
|
|
158
|
-
messages,
|
|
159
|
-
reject,
|
|
160
|
-
send,
|
|
161
|
-
status,
|
|
162
|
-
streamingText
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export { createAgentChat };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createMemo } from 'solid-js';
|
|
2
|
-
import { resolveMaybe } from './createAgent-D7EZBeql.mjs';
|
|
3
|
-
import { createSubscription } from './createSubscription-D3HbChGe.mjs';
|
|
4
|
-
|
|
5
|
-
const createAgentState = (options) => {
|
|
6
|
-
const {
|
|
7
|
-
data,
|
|
8
|
-
error
|
|
9
|
-
} = createSubscription(options.api.agents.agentState, () => {
|
|
10
|
-
return {
|
|
11
|
-
key: resolveMaybe(options.threadKey)
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
const state = createMemo(() => data());
|
|
15
|
-
return {
|
|
16
|
-
error,
|
|
17
|
-
state
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { createAgentState };
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { createMemo } from 'solid-js';
|
|
2
|
-
import { resolveMaybe } from './createAgent-D7EZBeql.mjs';
|
|
3
|
-
import { createStream } from './createStream-D9ONbGAw.mjs';
|
|
4
|
-
import { createSubscription } from './createSubscription-D3HbChGe.mjs';
|
|
5
|
-
|
|
6
|
-
const NO_STREAM_REF = {
|
|
7
|
-
__lunoraRef: ""
|
|
8
|
-
};
|
|
9
|
-
const EMPTY_MESSAGES = [];
|
|
10
|
-
const toDurableEvent = (message) => {
|
|
11
|
-
if (message.role === "assistant" && message.toolCalls) {
|
|
12
|
-
return message.toolCalls.map((call) => {
|
|
13
|
-
return {
|
|
14
|
-
input: call.input,
|
|
15
|
-
seq: message.seq,
|
|
16
|
-
toolCallId: call.id,
|
|
17
|
-
toolName: call.name,
|
|
18
|
-
type: "call"
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
if (message.role !== "tool") {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
if (message.status === "awaiting_approval") {
|
|
26
|
-
return [{
|
|
27
|
-
seq: message.seq,
|
|
28
|
-
type: "awaiting-approval",
|
|
29
|
-
...message.toolCallId === void 0 ? {} : {
|
|
30
|
-
toolCallId: message.toolCallId
|
|
31
|
-
},
|
|
32
|
-
...message.toolName === void 0 ? {} : {
|
|
33
|
-
toolName: message.toolName
|
|
34
|
-
}
|
|
35
|
-
}];
|
|
36
|
-
}
|
|
37
|
-
return [{
|
|
38
|
-
output: message.content,
|
|
39
|
-
seq: message.seq,
|
|
40
|
-
type: "result",
|
|
41
|
-
...message.status === "approved" || message.status === "rejected" ? {
|
|
42
|
-
status: message.status
|
|
43
|
-
} : {},
|
|
44
|
-
...message.toolCallId === void 0 ? {} : {
|
|
45
|
-
toolCallId: message.toolCallId
|
|
46
|
-
},
|
|
47
|
-
...message.toolName === void 0 ? {} : {
|
|
48
|
-
toolName: message.toolName
|
|
49
|
-
}
|
|
50
|
-
}];
|
|
51
|
-
};
|
|
52
|
-
const createAgentToolEvents = (options) => {
|
|
53
|
-
const {
|
|
54
|
-
api,
|
|
55
|
-
limit,
|
|
56
|
-
stream: streamReference,
|
|
57
|
-
threadKey
|
|
58
|
-
} = options;
|
|
59
|
-
const messagesArguments = () => {
|
|
60
|
-
const key = resolveMaybe(threadKey);
|
|
61
|
-
return limit === void 0 ? {
|
|
62
|
-
key
|
|
63
|
-
} : {
|
|
64
|
-
key,
|
|
65
|
-
limit
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
const {
|
|
69
|
-
data: history
|
|
70
|
-
} = createSubscription(api.agents.agentMessages, messagesArguments);
|
|
71
|
-
const streamArguments = streamReference === void 0 ? "skip" : () => {
|
|
72
|
-
return {
|
|
73
|
-
key: resolveMaybe(threadKey)
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const {
|
|
77
|
-
chunks
|
|
78
|
-
} = createStream(streamReference ?? NO_STREAM_REF, streamArguments);
|
|
79
|
-
const events = createMemo(() => {
|
|
80
|
-
const key = resolveMaybe(threadKey);
|
|
81
|
-
const durable = history() ?? EMPTY_MESSAGES;
|
|
82
|
-
const derived = durable.flatMap((message) => toDurableEvent(message) ?? []);
|
|
83
|
-
for (const event of chunks()) {
|
|
84
|
-
if (event.kind === "progress" && event.threadKey === key) {
|
|
85
|
-
derived.push({
|
|
86
|
-
data: event.data,
|
|
87
|
-
toolCallId: event.toolCallId,
|
|
88
|
-
type: "progress"
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return derived;
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
events
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export { createAgentToolEvents };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createSignal, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
-
|
|
4
|
-
const createConnectionStatus = () => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const [status, setStatus] = createSignal(client.connectionStatus());
|
|
7
|
-
const unsubscribe = client.onConnectionStatus((next) => {
|
|
8
|
-
setStatus(next);
|
|
9
|
-
});
|
|
10
|
-
onCleanup(unsubscribe);
|
|
11
|
-
return status;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { createConnectionStatus as default };
|