@lunora/solid 1.0.0-alpha.24 → 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,14 +1,14 @@
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';
7
7
  export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-1poqwqR9.mjs';
8
- export { createFlag, createFlags } from './packem_shared/createFlag-Bu9YfzcJ.mjs';
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-Dy9k7Px2.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,5 +1,5 @@
1
1
  import { createSignal, createEffect, on, onCleanup } from 'solid-js';
2
- import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
2
+ import { s as stableStringify } from './stable-key-DePnevIy.mjs';
3
3
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
4
4
 
5
5
  const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
@@ -1,8 +1,106 @@
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
- import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
3
+ import { s as stableStringify } from './stable-key-DePnevIy.mjs';
4
4
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
5
5
 
6
+ const toBase64 = (bytes) => {
7
+ let binary = "";
8
+ const chunk = 32768;
9
+ for (let index = 0; index < bytes.length; index += chunk) {
10
+ binary += String.fromCharCode(...bytes.subarray(index, index + chunk));
11
+ }
12
+ return btoa(binary);
13
+ };
14
+
15
+ const TAG = "$lunora.wire$";
16
+ const MAX_DEPTH = 64;
17
+ const encodeWire = (value, depth = 0) => {
18
+ if (depth > MAX_DEPTH) {
19
+ throw new RangeError(`wire-codec: value nesting exceeds the ${MAX_DEPTH}-level limit`);
20
+ }
21
+ if (value === void 0) {
22
+ return [TAG, "undefined"];
23
+ }
24
+ if (value === null) {
25
+ return null;
26
+ }
27
+ const kind = typeof value;
28
+ if (kind === "bigint") {
29
+ return [TAG, "bigint", value.toString()];
30
+ }
31
+ if (kind === "number") {
32
+ const numeric = value;
33
+ if (Number.isNaN(numeric)) {
34
+ return [TAG, "nan"];
35
+ }
36
+ if (numeric === Infinity) {
37
+ return [TAG, "inf"];
38
+ }
39
+ if (numeric === -Infinity) {
40
+ return [TAG, "-inf"];
41
+ }
42
+ return numeric;
43
+ }
44
+ if (kind !== "object") {
45
+ return value;
46
+ }
47
+ if (value instanceof Date) {
48
+ return [TAG, "date", encodeWire(value.getTime(), depth + 1)];
49
+ }
50
+ if (value instanceof Error) {
51
+ const error = value;
52
+ const properties = {};
53
+ for (const key of Object.keys(error)) {
54
+ if (error[key] !== void 0) {
55
+ properties[key] = encodeWire(error[key], depth + 1);
56
+ }
57
+ }
58
+ const encodedError = [TAG, "error", error.name, error.message, properties];
59
+ if (error.cause !== void 0) {
60
+ encodedError.push(encodeWire(error.cause, depth + 1));
61
+ }
62
+ return encodedError;
63
+ }
64
+ if (value instanceof URL) {
65
+ return [TAG, "url", value.href];
66
+ }
67
+ if (value instanceof Map) {
68
+ return [TAG, "map", [...value.entries()].map(([k, v]) => [encodeWire(k, depth + 1), encodeWire(v, depth + 1)])];
69
+ }
70
+ if (value instanceof Set) {
71
+ return [TAG, "set", [...value].map((item) => encodeWire(item, depth + 1))];
72
+ }
73
+ if (value instanceof ArrayBuffer) {
74
+ return [TAG, "bytes", toBase64(new Uint8Array(value)), "ArrayBuffer"];
75
+ }
76
+ if (ArrayBuffer.isView(value)) {
77
+ const view = value;
78
+ const ctorName = view.constructor.name;
79
+ const bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
80
+ return ctorName === "Uint8Array" ? [TAG, "bytes", toBase64(bytes)] : [TAG, "bytes", toBase64(bytes), ctorName];
81
+ }
82
+ if (Array.isArray(value)) {
83
+ const encoded = value.map((item) => encodeWire(item, depth + 1));
84
+ return encoded.length > 0 && encoded[0] === TAG ? [TAG, "arr", encoded] : encoded;
85
+ }
86
+ const proto = Object.getPrototypeOf(value);
87
+ if (proto !== null && proto !== Object.prototype) {
88
+ const name = value.constructor?.name ?? "value";
89
+ throw new TypeError(`wire-codec: cannot encode a ${name} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`);
90
+ }
91
+ const source = value;
92
+ const result = {};
93
+ for (const key of Object.keys(source)) {
94
+ const field = source[key];
95
+ if (field !== void 0) {
96
+ result[key] = encodeWire(field, depth + 1);
97
+ }
98
+ }
99
+ return result;
100
+ };
101
+
102
+ const stableWireKey = (value) => stableStringify(encodeWire(value));
103
+
6
104
  const buildPageArgs = (page, baseArgs) => {
7
105
  return {
8
106
  ...baseArgs,
@@ -13,7 +111,7 @@ const buildPageArgs = (page, baseArgs) => {
13
111
  }
14
112
  };
15
113
  };
16
- const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${stableStringify(pageArgs)}`;
114
+ const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${stableWireKey(pageArgs)}`;
17
115
  const createPaginatedCore = (function_, args, options) => {
18
116
  const client = useLunora();
19
117
  const {
@@ -49,7 +147,7 @@ const createPaginatedCore = (function_, args, options) => {
49
147
  }
50
148
  }
51
149
  };
52
- const syncSubscriptions = (currentPages, baseArgs) => {
150
+ const syncPass = (currentPages, baseArgs) => {
53
151
  const wantedKeys = /* @__PURE__ */ new Set();
54
152
  for (const page of currentPages) {
55
153
  wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
@@ -91,6 +189,31 @@ const createPaginatedCore = (function_, args, options) => {
91
189
  activeSubs.set(key, unsub);
92
190
  }
93
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
+ };
94
217
  const teardownAll = () => {
95
218
  for (const unsub of activeSubs.values()) {
96
219
  unsub();
@@ -9,7 +9,7 @@ const stableStringify = (value) => {
9
9
  return "null";
10
10
  }
11
11
  if (typeof value === "bigint") {
12
- throw new TypeError("stableStringify: cannot use a bigint in a cache key (query/subscription/shape args) — pass it as a string");
12
+ throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");
13
13
  }
14
14
  if (value === null || typeof value !== "object") {
15
15
  return JSON.stringify(value);
@@ -20,7 +20,7 @@ const stableStringify = (value) => {
20
20
  const proto = Object.getPrototypeOf(value);
21
21
  if (proto !== null && proto !== Object.prototype) {
22
22
  const name = value.constructor?.name ?? "value";
23
- throw new TypeError(`stableStringify: cannot use a ${name} in a cache key (query/subscription/shape args) — only plain objects, arrays, and JSON primitives are supported`);
23
+ throw new TypeError(`stableStringify: cannot use a ${name} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`);
24
24
  }
25
25
  const record = value;
26
26
  const keys = Object.keys(record).toSorted(compareKeys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/solid",
3
- "version": "1.0.0-alpha.24",
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,9 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/client": "1.0.0-alpha.21",
54
- "@lunora/errors": "1.0.0-alpha.4",
55
- "@lunora/ratelimit": "1.0.0-alpha.7"
53
+ "@lunora/client": "1.0.0-alpha.24",
54
+ "@lunora/errors": "1.0.0-alpha.5",
55
+ "@lunora/ratelimit": "1.0.0-alpha.8"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "solid-js": "^1.9.0"