@lunora/svelte 1.0.0-alpha.320 → 1.0.0-alpha.322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/agentChat-B85Roxj3.mjs +1 -0
- package/dist/packem_shared/agentToolEvents-CDt_CXlT.mjs +1 -0
- package/package.json +2 -2
- package/dist/packem_shared/agentChat-DDtm3-N1.mjs +0 -1
- package/dist/packem_shared/agentToolEvents-D2DqjZ9V.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -164,6 +164,8 @@ declare function agent(client: LunoraClient, options: AgentOptions): AgentHandle
|
|
|
164
164
|
* `agent_messages` table in `packages/agent/src/component.ts`.
|
|
165
165
|
*/
|
|
166
166
|
interface AgentChatMessage {
|
|
167
|
+
/** On an `awaiting_approval` message: the slot its run waits under, which a decision must name. */
|
|
168
|
+
approvalSlot?: string;
|
|
167
169
|
content: string;
|
|
168
170
|
createdAt?: number;
|
|
169
171
|
/**
|
|
@@ -228,6 +230,7 @@ type AgentMessagesReference$1 = FunctionReference<"query", {
|
|
|
228
230
|
}, ReadonlyArray<Record<string, unknown>>>;
|
|
229
231
|
/** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
|
|
230
232
|
type AgentApprovalReference = FunctionReference<"mutation", {
|
|
233
|
+
approvalSlot: string;
|
|
231
234
|
decision: "approve" | "approve_for_thread" | "reject";
|
|
232
235
|
instanceId: string;
|
|
233
236
|
note?: string;
|
|
@@ -236,6 +239,11 @@ type AgentApprovalReference = FunctionReference<"mutation", {
|
|
|
236
239
|
}, {
|
|
237
240
|
resolved: boolean;
|
|
238
241
|
}>;
|
|
242
|
+
/**
|
|
243
|
+
* The pending approval a decision answers: its `awaiting_approval` message, its `awaiting-approval` tool event or its
|
|
244
|
+
* inbox item. A provider can reuse a tool-call id in a later turn, so a decision names the approval's slot as well.
|
|
245
|
+
*/
|
|
246
|
+
type AgentApprovalTarget = Pick<AgentChatMessage, "approvalSlot" | "toolCallId">;
|
|
239
247
|
/** The `agents:agentSupplySecret` reference — stores a person's value for a paused `requestSecretTool` call. */
|
|
240
248
|
type AgentSupplySecretReference = FunctionReference<"mutation", {
|
|
241
249
|
secret: string;
|
|
@@ -334,12 +342,12 @@ interface AgentChatHandle {
|
|
|
334
342
|
/** The tools approved for the rest of this thread, live. Read with `$approvalGrants`. */
|
|
335
343
|
approvalGrants: Readable<ReadonlyArray<AgentApprovalGrant>>;
|
|
336
344
|
/** Approve a paused human-in-the-loop tool call (optionally with a note). */
|
|
337
|
-
approve: (
|
|
345
|
+
approve: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
338
346
|
/**
|
|
339
347
|
* Approve a paused tool call and grant that tool for the rest of the thread, so
|
|
340
348
|
* later calls to it run without pausing. Undo with {@link AgentChatHandle.revokeGrant}.
|
|
341
349
|
*/
|
|
342
|
-
approveForThread: (
|
|
350
|
+
approveForThread: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
343
351
|
/**
|
|
344
352
|
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
345
353
|
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
@@ -350,7 +358,7 @@ interface AgentChatHandle {
|
|
|
350
358
|
/** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. Read with `$messages`. */
|
|
351
359
|
messages: Readable<ReadonlyArray<AgentChatMessage>>;
|
|
352
360
|
/** Reject a paused human-in-the-loop tool call (optionally with a reason). */
|
|
353
|
-
reject: (
|
|
361
|
+
reject: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
354
362
|
/** Remove a thread-scoped approval grant so the tool's gate applies again to later calls. */
|
|
355
363
|
revokeGrant: (toolName: string) => Promise<void>;
|
|
356
364
|
/** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
|
|
@@ -514,6 +522,7 @@ type AgentToolEvent = {
|
|
|
514
522
|
toolName?: string;
|
|
515
523
|
type: "result";
|
|
516
524
|
} | {
|
|
525
|
+
approvalSlot?: string;
|
|
517
526
|
seq: number;
|
|
518
527
|
toolCallId?: string;
|
|
519
528
|
toolName?: string;
|
|
@@ -1325,7 +1334,7 @@ interface VoiceAgentHandle {
|
|
|
1325
1334
|
*/
|
|
1326
1335
|
declare function voiceAgent(options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1327
1336
|
declare function voiceAgent(client: LunoraClient, options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1328
|
-
export { type ActionHandle, type AgentApi, type AgentApprovalGrant, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type LiveTopicState, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type ReactiveArgs, type ReactivePaginatedArgs, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, action, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags,
|
|
1337
|
+
export { type ActionHandle, type AgentApi, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type LiveTopicState, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type ReactiveArgs, type ReactivePaginatedArgs, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, action, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags,
|
|
1329
1338
|
/**
|
|
1330
1339
|
* Svelte adapter for Lunora (`@lunora/svelte`).
|
|
1331
1340
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -164,6 +164,8 @@ declare function agent(client: LunoraClient, options: AgentOptions): AgentHandle
|
|
|
164
164
|
* `agent_messages` table in `packages/agent/src/component.ts`.
|
|
165
165
|
*/
|
|
166
166
|
interface AgentChatMessage {
|
|
167
|
+
/** On an `awaiting_approval` message: the slot its run waits under, which a decision must name. */
|
|
168
|
+
approvalSlot?: string;
|
|
167
169
|
content: string;
|
|
168
170
|
createdAt?: number;
|
|
169
171
|
/**
|
|
@@ -228,6 +230,7 @@ type AgentMessagesReference$1 = FunctionReference<"query", {
|
|
|
228
230
|
}, ReadonlyArray<Record<string, unknown>>>;
|
|
229
231
|
/** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
|
|
230
232
|
type AgentApprovalReference = FunctionReference<"mutation", {
|
|
233
|
+
approvalSlot: string;
|
|
231
234
|
decision: "approve" | "approve_for_thread" | "reject";
|
|
232
235
|
instanceId: string;
|
|
233
236
|
note?: string;
|
|
@@ -236,6 +239,11 @@ type AgentApprovalReference = FunctionReference<"mutation", {
|
|
|
236
239
|
}, {
|
|
237
240
|
resolved: boolean;
|
|
238
241
|
}>;
|
|
242
|
+
/**
|
|
243
|
+
* The pending approval a decision answers: its `awaiting_approval` message, its `awaiting-approval` tool event or its
|
|
244
|
+
* inbox item. A provider can reuse a tool-call id in a later turn, so a decision names the approval's slot as well.
|
|
245
|
+
*/
|
|
246
|
+
type AgentApprovalTarget = Pick<AgentChatMessage, "approvalSlot" | "toolCallId">;
|
|
239
247
|
/** The `agents:agentSupplySecret` reference — stores a person's value for a paused `requestSecretTool` call. */
|
|
240
248
|
type AgentSupplySecretReference = FunctionReference<"mutation", {
|
|
241
249
|
secret: string;
|
|
@@ -334,12 +342,12 @@ interface AgentChatHandle {
|
|
|
334
342
|
/** The tools approved for the rest of this thread, live. Read with `$approvalGrants`. */
|
|
335
343
|
approvalGrants: Readable<ReadonlyArray<AgentApprovalGrant>>;
|
|
336
344
|
/** Approve a paused human-in-the-loop tool call (optionally with a note). */
|
|
337
|
-
approve: (
|
|
345
|
+
approve: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
338
346
|
/**
|
|
339
347
|
* Approve a paused tool call and grant that tool for the rest of the thread, so
|
|
340
348
|
* later calls to it run without pausing. Undo with {@link AgentChatHandle.revokeGrant}.
|
|
341
349
|
*/
|
|
342
|
-
approveForThread: (
|
|
350
|
+
approveForThread: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
343
351
|
/**
|
|
344
352
|
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
345
353
|
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
@@ -350,7 +358,7 @@ interface AgentChatHandle {
|
|
|
350
358
|
/** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. Read with `$messages`. */
|
|
351
359
|
messages: Readable<ReadonlyArray<AgentChatMessage>>;
|
|
352
360
|
/** Reject a paused human-in-the-loop tool call (optionally with a reason). */
|
|
353
|
-
reject: (
|
|
361
|
+
reject: (approval: AgentApprovalTarget, note?: string) => Promise<void>;
|
|
354
362
|
/** Remove a thread-scoped approval grant so the tool's gate applies again to later calls. */
|
|
355
363
|
revokeGrant: (toolName: string) => Promise<void>;
|
|
356
364
|
/** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
|
|
@@ -514,6 +522,7 @@ type AgentToolEvent = {
|
|
|
514
522
|
toolName?: string;
|
|
515
523
|
type: "result";
|
|
516
524
|
} | {
|
|
525
|
+
approvalSlot?: string;
|
|
517
526
|
seq: number;
|
|
518
527
|
toolCallId?: string;
|
|
519
528
|
toolName?: string;
|
|
@@ -1325,7 +1334,7 @@ interface VoiceAgentHandle {
|
|
|
1325
1334
|
*/
|
|
1326
1335
|
declare function voiceAgent(options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1327
1336
|
declare function voiceAgent(client: LunoraClient, options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1328
|
-
export { type ActionHandle, type AgentApi, type AgentApprovalGrant, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type LiveTopicState, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type ReactiveArgs, type ReactivePaginatedArgs, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, action, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags,
|
|
1337
|
+
export { type ActionHandle, type AgentApi, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type LiveTopicState, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type ReactiveArgs, type ReactivePaginatedArgs, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, action, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags,
|
|
1329
1338
|
/**
|
|
1330
1339
|
* Svelte adapter for Lunora (`@lunora/svelte`).
|
|
1331
1340
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{action as t}from"./packem_shared/action-BwzMXvK2.mjs";import{agent as m}from"./packem_shared/agent-CYV_xWD9.mjs";import{agentChat as a}from"./packem_shared/agentChat-
|
|
1
|
+
import{action as t}from"./packem_shared/action-BwzMXvK2.mjs";import{agent as m}from"./packem_shared/agent-CYV_xWD9.mjs";import{agentChat as a}from"./packem_shared/agentChat-B85Roxj3.mjs";import{agentState as n}from"./packem_shared/agentState-DUcWVYXr.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-CDt_CXlT.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-DLryMKMY.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-Ba3Y_I18.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-CIfxHhDm.mjs";import{flag as C,flags as L}from"./packem_shared/flag-CvPhqFko.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-GIJIIvjB.mjs";import{liveTopic as b}from"./packem_shared/liveTopic-zWCoweI3.mjs";import{mutation as A}from"./packem_shared/mutation-Cvnei0Ke.mjs";import{mutator as G}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as j,paginatedQuery as k}from"./packem_shared/infiniteQuery-D91H-yvI.mjs";import{presence as z}from"./packem_shared/presence-DYgABtvC.mjs";import{query as D}from"./packem_shared/query-DpzFJQyT.mjs";import{rateLimit as H}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as J}from"./packem_shared/stream-CMEivEKF.mjs";import{subscription as M}from"./packem_shared/subscription-DSyycrP7.mjs";import{voiceAgent as O}from"./packem_shared/voiceAgent-qByP7VDj.mjs";export{t as action,m as agent,a as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,C as flag,L as flags,h as getLunoraClient,S as hydratePreloaded,j as infiniteQuery,b as liveTopic,A as mutation,G as mutator,k as paginatedQuery,z as presence,D as query,H as rateLimit,y as setLunoraClient,J as stream,M as subscription,O as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as R,maxSeq as E}from"@lunora/client";import{writable as b}from"svelte/store";import{i as g}from"./is-browser-BEdfLJHK.mjs";import{isClient as tt,NO_MUTATION_REF as et}from"./agent-CYV_xWD9.mjs";import{getLunoraClient as st}from"./getLunoraClient-CIfxHhDm.mjs";import{mutation as i}from"./mutation-Cvnei0Ke.mjs";import{stream as nt}from"./stream-CMEivEKF.mjs";const at={__lunoraRef:""},rt=(n,v)=>{const{api:r,cancel:p,limit:h,onError:y,send:_,sendArgs:G,stream:k,threadKey:a}=v,q=i(n,_),j=i(n,p??et),D=i(n,r.agents.agentResolveApproval),F=i(n,r.agents.agentRevokeApprovalGrant),N=i(n,r.agents.agentSupplySecret),H=i(n,r.agents.agentDeclineSecret);let l,o=[],u=[],x=[],A=0;const f=b([]),C=b(),T=b([]),I=b(""),S=()=>{const t=R(u,o);if(t.length===0){f.set(o);return}const e=E(o);f.set([...o,...t.map((s,c)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+c}))])},M=()=>{const t=o.filter(s=>s.role==="assistant").length,e=x.filter(s=>s.kind!=="progress"&&s.threadKey===a&&s.turn>=t).map(s=>s.text).join("");I.set(e)},K=k===void 0?"skip":{key:a},$=g()?nt(n,k??at,K).chunks.subscribe(t=>{x=t,M()}):()=>{},B=h===void 0?{key:a}:{key:a,limit:h},L=g()?n.subscribe(r.agents.agentMessages,B,t=>{o=t,S(),M()},{onError:y}):()=>{},O=g()?n.subscribe(r.agents.agentThread,{key:a},t=>{l=t,C.set(l?.status)},{onError:y}):()=>{},U=g()?n.subscribe(r.agents.agentApprovalGrants,{key:a},t=>{T.set(t)},{onError:y}):()=>{},z=async(t,e)=>{const s=A;A+=1;const c=E(o);u=[...R(u,o),{content:t,id:s,maxDurableSeqAtSend:c}],S();try{await q.mutate({input:t,threadKey:a,...G,...e})}catch(m){throw u=u.filter(d=>d.id!==s),S(),m}},w=async(t,e,s)=>{const c=l?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);const{approvalSlot:m,toolCallId:d}=e;if(m===void 0||d===void 0)throw new Error(`agentChat: cannot ${t} — pass the pending approval, which carries its toolCallId and approvalSlot`);await D.mutate({approvalSlot:m,decision:t,instanceId:c,threadKey:a,toolCallId:d,...s===void 0?{}:{note:s}})},J=async(t,e)=>w("approve",t,e),P=async(t,e)=>w("approve_for_thread",t,e),Q=async(t,e)=>w("reject",t,e),V=async t=>{await F.mutate({threadKey:a,toolName:t})},W=async(t,e)=>{await N.mutate({secret:e,threadKey:a,toolCallId:t},{onlineOnly:!0})},X=async t=>{await H.mutate({threadKey:a,toolCallId:t})},Y=async()=>{const t=l?.instanceId;p===void 0||t===void 0||await j.mutate({instanceId:t,threadKey:a})},Z=()=>{L(),O(),U(),$()};return{approvalGrants:{subscribe:T.subscribe},approve:J,approveForThread:P,cancel:Y,declineSecret:X,messages:{subscribe:f.subscribe},reject:Q,revokeGrant:V,send:z,status:{subscribe:C.subscribe},streamingText:{subscribe:I.subscribe},supplySecret:W,teardown:Z}};function dt(n,v){const r=tt(n),p=r?n:st();return rt(p,r?v:n)}export{dt as agentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as y}from"svelte/store";import{isClient as E}from"./agent-CYV_xWD9.mjs";import{getLunoraClient as I}from"./getLunoraClient-CIfxHhDm.mjs";import{stream as N}from"./stream-CMEivEKF.mjs";import{subscription as _}from"./subscription-DSyycrP7.mjs";const h={__lunoraRef:""},k={awaiting_approval:"awaiting-approval",awaiting_secret:"awaiting-secret"},m=t=>{const o=t.status===void 0?void 0:k[t.status];if(o!==void 0)return{seq:t.seq,type:o,...t.approvalSlot===void 0?{}:{approvalSlot:t.approvalSlot},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}},q=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(r=>({input:r.input,seq:t.seq,toolCallId:r.id,toolName:r.name,type:"call"}));if(t.role!=="tool")return;const o=m(t);return o!==void 0?[o]:[{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}}]};function x(t,o){const r=E(t),a=r?t:I(),p=r?o:t,{api:u,limit:i,stream:e,threadKey:n}=p,s=i===void 0?{key:n}:{key:n,limit:i},{data:c}=_(a,u.agents.agentMessages,s),v=N(a,e??h,e===void 0?"skip":{key:n});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(l=>q(l)??[]);for(const l of C)l.kind==="progress"&&l.threadKey===n&&d.push({data:l.data,toolCallId:l.toolCallId,type:"progress"});return d})}}export{x as agentToolEvents};
|
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.322",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@lunora/client": "^1.0.0-alpha.288",
|
|
58
58
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
59
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
59
|
+
"@lunora/ratelimit": "^1.0.0-alpha.197",
|
|
60
60
|
"@lunora/wire": "1.0.0-alpha.6",
|
|
61
61
|
"@visulima/storage-client": "1.0.9"
|
|
62
62
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{reconcileOptimistic as R,maxSeq as _}from"@lunora/client";import{writable as l}from"svelte/store";import{i as b}from"./is-browser-BEdfLJHK.mjs";import{isClient as tt,NO_MUTATION_REF as et}from"./agent-CYV_xWD9.mjs";import{getLunoraClient as st}from"./getLunoraClient-CIfxHhDm.mjs";import{mutation as i}from"./mutation-Cvnei0Ke.mjs";import{stream as nt}from"./stream-CMEivEKF.mjs";const rt={__lunoraRef:""},at=(n,d)=>{const{api:a,cancel:p,limit:g,onError:v,send:C,sendArgs:E,stream:S,threadKey:r}=d,I=i(n,C),G=i(n,p??et),q=i(n,a.agents.agentResolveApproval),j=i(n,a.agents.agentRevokeApprovalGrant),D=i(n,a.agents.agentSupplySecret),F=i(n,a.agents.agentDeclineSecret);let m,o=[],u=[],w=[],k=0;const y=l([]),x=l(),A=l([]),T=l(""),h=()=>{const t=R(u,o);if(t.length===0){y.set(o);return}const e=_(o);y.set([...o,...t.map((s,c)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+c}))])},M=()=>{const t=o.filter(s=>s.role==="assistant").length,e=w.filter(s=>s.kind!=="progress"&&s.threadKey===r&&s.turn>=t).map(s=>s.text).join("");T.set(e)},N=S===void 0?"skip":{key:r},H=b()?nt(n,S??rt,N).chunks.subscribe(t=>{w=t,M()}):()=>{},K=g===void 0?{key:r}:{key:r,limit:g},B=b()?n.subscribe(a.agents.agentMessages,K,t=>{o=t,h(),M()},{onError:v}):()=>{},L=b()?n.subscribe(a.agents.agentThread,{key:r},t=>{m=t,x.set(m?.status)},{onError:v}):()=>{},O=b()?n.subscribe(a.agents.agentApprovalGrants,{key:r},t=>{A.set(t)},{onError:v}):()=>{},U=async(t,e)=>{const s=k;k+=1;const c=_(o);u=[...R(u,o),{content:t,id:s,maxDurableSeqAtSend:c}],h();try{await I.mutate({input:t,threadKey:r,...E,...e})}catch(Y){throw u=u.filter(Z=>Z.id!==s),h(),Y}},f=async(t,e,s)=>{const c=m?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await q.mutate({decision:t,instanceId:c,threadKey:r,toolCallId:e,...s===void 0?{}:{note:s}})},$=async(t,e)=>f("approve",t,e),z=async(t,e)=>f("approve_for_thread",t,e),J=async(t,e)=>f("reject",t,e),P=async t=>{await j.mutate({threadKey:r,toolName:t})},Q=async(t,e)=>{await D.mutate({secret:e,threadKey:r,toolCallId:t},{onlineOnly:!0})},V=async t=>{await F.mutate({threadKey:r,toolCallId:t})},W=async()=>{const t=m?.instanceId;p===void 0||t===void 0||await G.mutate({instanceId:t,threadKey:r})},X=()=>{B(),L(),O(),H()};return{approvalGrants:{subscribe:A.subscribe},approve:$,approveForThread:z,cancel:W,declineSecret:V,messages:{subscribe:y.subscribe},reject:J,revokeGrant:P,send:U,status:{subscribe:x.subscribe},streamingText:{subscribe:T.subscribe},supplySecret:Q,teardown:X}};function bt(n,d){const a=tt(n),p=a?n:st();return at(p,a?d:n)}export{bt as agentChat};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{derived as y}from"svelte/store";import{isClient as E}from"./agent-CYV_xWD9.mjs";import{getLunoraClient as I}from"./getLunoraClient-CIfxHhDm.mjs";import{stream as N}from"./stream-CMEivEKF.mjs";import{subscription as m}from"./subscription-DSyycrP7.mjs";const _={__lunoraRef:""},h={awaiting_approval:"awaiting-approval",awaiting_secret:"awaiting-secret"},k=t=>{const o=t.status===void 0?void 0:h[t.status];if(o!==void 0)return{seq:t.seq,type:o,...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}},q=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(r=>({input:r.input,seq:t.seq,toolCallId:r.id,toolName:r.name,type:"call"}));if(t.role!=="tool")return;const o=k(t);return o!==void 0?[o]:[{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}}]};function x(t,o){const r=E(t),a=r?t:I(),s=r?o:t,{api:u,limit:e,stream:i,threadKey:l}=s,p=e===void 0?{key:l}:{key:l,limit:e},{data:c}=m(a,u.agents.agentMessages,p),v=N(a,i??_,i===void 0?"skip":{key:l});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(n=>q(n)??[]);for(const n of C)n.kind==="progress"&&n.threadKey===l&&d.push({data:n.data,toolCallId:n.toolCallId,type:"progress"});return d})}}export{x as agentToolEvents};
|