@lunora/solid 1.0.0-alpha.25 → 1.0.0-alpha.26

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,6 +1,6 @@
1
1
  export { LunoraContext, useLunora } from './packem_shared/LunoraContext-C59PzHhN.mjs';
2
2
  export { createAgent } from './packem_shared/createAgent-D7EZBeql.mjs';
3
- export { createAgentChat } from './packem_shared/createAgentChat-CsoyE3RE.mjs';
3
+ export { createAgentChat } from './packem_shared/createAgentChat-Bq-wzSxv.mjs';
4
4
  export { createAgentState } from './packem_shared/createAgentState-DckYu3G8.mjs';
5
5
  export { createAgentToolEvents } from './packem_shared/createAgentToolEvents-UavTO16u.mjs';
6
6
  export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/AuthLoading-u5QJoV-J.mjs';
@@ -8,7 +8,7 @@ export { default as createConnectionStatus } from './packem_shared/createConnect
8
8
  export { createFlag, createFlags } from './packem_shared/createFlag-DQoGdUMB.mjs';
9
9
  export { createMutation, createMutationForClient } from './packem_shared/createMutation-LkrbhItI.mjs';
10
10
  export { createMutator } from './packem_shared/createMutator-foSnPJPt.mjs';
11
- export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-DwajCO2G.mjs';
11
+ export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-CD2GT1_O.mjs';
12
12
  export { createPresence } from './packem_shared/createPresence-DM2cVkiG.mjs';
13
13
  export { createQuery } from './packem_shared/createQuery-BUldvZXj.mjs';
14
14
  export { createRateLimit } from './packem_shared/createRateLimit-BA2f8XyF.mjs';
@@ -8,12 +8,15 @@ const NO_STREAM_REF = {
8
8
  __lunoraRef: ""
9
9
  };
10
10
  const reconcileOptimistic = (optimistic, durable) => {
11
- const pool = durable.filter((message) => message.role === "user").map((message) => message.content);
11
+ const durableUserRows = durable.filter((message) => message.role === "user");
12
+ const consumed = /* @__PURE__ */ new Set();
12
13
  return optimistic.filter((pending) => {
13
- const index = pool.indexOf(pending.content);
14
- if (index !== -1) {
15
- pool.splice(index, 1);
16
- return false;
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
+ }
17
20
  }
18
21
  return true;
19
22
  });
@@ -68,12 +71,18 @@ const createAgentChat = (options) => {
68
71
  if (visible.length === 0) {
69
72
  return rows;
70
73
  }
74
+ let maxDurableSeq = -1;
75
+ for (const message of rows) {
76
+ if (message.seq > maxDurableSeq) {
77
+ maxDurableSeq = message.seq;
78
+ }
79
+ }
71
80
  return [...rows, ...visible.map((pending, index) => {
72
81
  return {
73
82
  content: pending.content,
74
83
  optimistic: true,
75
84
  role: "user",
76
- seq: rows.length + index
85
+ seq: maxDurableSeq + 1 + index
77
86
  };
78
87
  })];
79
88
  });
@@ -85,16 +94,23 @@ const createAgentChat = (options) => {
85
94
  const send = async (input, arguments_) => {
86
95
  const id = nextId;
87
96
  nextId += 1;
97
+ const durableUserCountAtSend = durable().filter((message) => message.role === "user").length;
88
98
  setOptimistic((previous) => [...reconcileOptimistic(previous, durable()), {
89
99
  content: input,
100
+ durableUserCountAtSend,
90
101
  id
91
102
  }]);
92
- await sendMutation.mutate({
93
- input,
94
- threadKey: resolveMaybe(threadKey),
95
- ...sendArgs,
96
- ...arguments_
97
- });
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
+ }
98
114
  };
99
115
  const approve = async (toolCallId, note) => {
100
116
  const instanceId = thread()?.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 { createMemo, createSignal, createEffect, on, onCleanup } from 'solid-js';
3
3
  import { s as stableStringify } from './stable-key-DePnevIy.mjs';
4
4
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
@@ -147,7 +147,7 @@ const createPaginatedCore = (function_, args, options) => {
147
147
  }
148
148
  }
149
149
  };
150
- const syncSubscriptions = (currentPages, baseArgs) => {
150
+ const syncPass = (currentPages, baseArgs) => {
151
151
  const wantedKeys = /* @__PURE__ */ new Set();
152
152
  for (const page of currentPages) {
153
153
  wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
@@ -189,6 +189,31 @@ const createPaginatedCore = (function_, args, options) => {
189
189
  activeSubs.set(key, unsub);
190
190
  }
191
191
  };
192
+ let syncing = false;
193
+ let resyncRequested = false;
194
+ const syncSubscriptions = (currentPages, baseArgs) => {
195
+ if (syncing) {
196
+ resyncRequested = true;
197
+ return;
198
+ }
199
+ syncing = true;
200
+ try {
201
+ let pagesToSync = currentPages;
202
+ let argsToSync = baseArgs;
203
+ do {
204
+ resyncRequested = false;
205
+ syncPass(pagesToSync, argsToSync);
206
+ const latestArgs = resolveArgs();
207
+ if (latestArgs === "skip") {
208
+ break;
209
+ }
210
+ pagesToSync = pages();
211
+ argsToSync = latestArgs;
212
+ } while (resyncRequested);
213
+ } finally {
214
+ syncing = false;
215
+ }
216
+ };
192
217
  const teardownAll = () => {
193
218
  for (const unsub of activeSubs.values()) {
194
219
  unsub();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/solid",
3
- "version": "1.0.0-alpha.25",
3
+ "version": "1.0.0-alpha.26",
4
4
  "description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/client": "1.0.0-alpha.23",
53
+ "@lunora/client": "1.0.0-alpha.24",
54
54
  "@lunora/errors": "1.0.0-alpha.5",
55
55
  "@lunora/ratelimit": "1.0.0-alpha.8"
56
56
  },