@lunora/svelte 1.0.0-alpha.37 → 1.0.0-alpha.39

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  export { agent } from './packem_shared/agent-KLsxO_Uw.mjs';
2
- export { agentChat } from './packem_shared/agentChat-CrFM8IGA.mjs';
2
+ export { agentChat } from './packem_shared/agentChat-BlwlNfDg.mjs';
3
3
  export { agentState } from './packem_shared/agentState-DBXc_3RM.mjs';
4
4
  export { agentToolEvents } from './packem_shared/agentToolEvents-qYM1CdTV.mjs';
5
5
  export { auth } from './packem_shared/auth-BeYqYP9S.mjs';
@@ -9,7 +9,7 @@ export { flag, flags } from './packem_shared/flag-CqMU07WH.mjs';
9
9
  export { hydratePreloaded } from './packem_shared/hydratePreloaded-Djsf_C8Q.mjs';
10
10
  export { mutation } from './packem_shared/mutation-BmkCZnTd.mjs';
11
11
  export { mutator } from './packem_shared/mutator-B5LchgMS.mjs';
12
- export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-DlnFVv-f.mjs';
12
+ export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-Bemu7Um1.mjs';
13
13
  export { presence } from './packem_shared/presence-BvChXqiB.mjs';
14
14
  export { query } from './packem_shared/query-B-Gu6KQw.mjs';
15
15
  export { rateLimit } from './packem_shared/rateLimit-Cdw1kp8t.mjs';
@@ -6,12 +6,15 @@ import { stream } from './stream-BebZbIaD.mjs';
6
6
 
7
7
  const NO_STREAM_REF = { __lunoraRef: "" };
8
8
  const reconcileOptimistic = (optimistic, durable) => {
9
- const pool = durable.filter((message) => message.role === "user").map((message) => message.content);
9
+ const durableUserRows = durable.filter((message) => message.role === "user");
10
+ const consumed = /* @__PURE__ */ new Set();
10
11
  return optimistic.filter((pending) => {
11
- const index = pool.indexOf(pending.content);
12
- if (index !== -1) {
13
- pool.splice(index, 1);
14
- return false;
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
+ }
15
18
  }
16
19
  return true;
17
20
  });
@@ -35,6 +38,12 @@ const createAgentChatHandle = (client, options) => {
35
38
  messagesStore.set(durable);
36
39
  return;
37
40
  }
41
+ let maxDurableSeq = -1;
42
+ for (const message of durable) {
43
+ if (message.seq > maxDurableSeq) {
44
+ maxDurableSeq = message.seq;
45
+ }
46
+ }
38
47
  messagesStore.set([
39
48
  ...durable,
40
49
  ...visible.map((pending, index) => {
@@ -42,7 +51,7 @@ const createAgentChatHandle = (client, options) => {
42
51
  content: pending.content,
43
52
  optimistic: true,
44
53
  role: "user",
45
- seq: durable.length + index
54
+ seq: maxDurableSeq + 1 + index
46
55
  };
47
56
  })
48
57
  ]);
@@ -71,9 +80,16 @@ const createAgentChatHandle = (client, options) => {
71
80
  const send = async (input, arguments_) => {
72
81
  const id = nextId;
73
82
  nextId += 1;
74
- optimistic = [...reconcileOptimistic(optimistic, durable), { content: input, id }];
83
+ const durableUserCountAtSend = durable.filter((message) => message.role === "user").length;
84
+ optimistic = [...reconcileOptimistic(optimistic, durable), { content: input, durableUserCountAtSend, id }];
75
85
  recompute();
76
- await sendMutation.mutate({ input, threadKey, ...sendArgs, ...arguments_ });
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
+ }
77
93
  };
78
94
  const approve = async (toolCallId, note) => {
79
95
  const instanceId = latestThread?.instanceId;
@@ -1,4 +1,4 @@
1
- import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
1
+ import { initialPages, derivePaginationStatus, applyLoadMore, rebalance } from '@lunora/client/pagination';
2
2
  import { derived, writable, readable, get } from 'svelte/store';
3
3
  import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
4
4
  import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
@@ -48,7 +48,7 @@ const createPaginatedEngine = (client, function_, baseArgs, options) => {
48
48
  }
49
49
  }
50
50
  };
51
- const syncSubscriptions = () => {
51
+ const syncPass = () => {
52
52
  if (currentBaseArgs === "skip") {
53
53
  for (const unsub of activeSubs.values()) {
54
54
  unsub();
@@ -101,6 +101,23 @@ const createPaginatedEngine = (client, function_, baseArgs, options) => {
101
101
  activeSubs.set(key, unsub);
102
102
  }
103
103
  };
104
+ let syncing = false;
105
+ let resyncRequested = false;
106
+ const syncSubscriptions = () => {
107
+ if (syncing) {
108
+ resyncRequested = true;
109
+ return;
110
+ }
111
+ syncing = true;
112
+ try {
113
+ do {
114
+ resyncRequested = false;
115
+ syncPass();
116
+ } while (resyncRequested);
117
+ } finally {
118
+ syncing = false;
119
+ }
120
+ };
104
121
  const teardownAll = () => {
105
122
  for (const unsub of activeSubs.values()) {
106
123
  unsub();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/svelte",
3
- "version": "1.0.0-alpha.37",
3
+ "version": "1.0.0-alpha.39",
4
4
  "description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,10 +54,10 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.21",
58
- "@lunora/errors": "1.0.0-alpha.4",
59
- "@lunora/ratelimit": "1.0.0-alpha.7",
60
- "@lunora/runtime": "1.0.0-alpha.27"
57
+ "@lunora/client": "1.0.0-alpha.24",
58
+ "@lunora/errors": "1.0.0-alpha.5",
59
+ "@lunora/ratelimit": "1.0.0-alpha.8",
60
+ "@lunora/runtime": "1.0.0-alpha.28"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "svelte": "^5.0.0"