@opencode/client 0.0.0-dev-19629 → 0.0.0-dev-19631

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.
Files changed (2) hide show
  1. package/dist/solid/data.js +47 -19
  2. package/package.json +4 -4
@@ -136,6 +136,7 @@ export function createData(config) {
136
136
  const messageIndex = new Map();
137
137
  const sync = createSync();
138
138
  let activeUpdates;
139
+ const pendingUpdates = new Map();
139
140
  function setSessionActive(sessionID, status) {
140
141
  activeUpdates?.set(sessionID, status);
141
142
  setStore("session", "active", sessionID, status);
@@ -143,6 +144,7 @@ export function createData(config) {
143
144
  function removePending(sessionID, inboxID) {
144
145
  if (!inboxID)
145
146
  return;
147
+ pendingUpdates.get(sessionID)?.set(inboxID, undefined);
146
148
  if (store.session.pending[sessionID]?.some((item) => item.id === inboxID))
147
149
  setStore("session", "pending", sessionID, (store.session.pending[sessionID] ?? []).filter((item) => item.id !== inboxID));
148
150
  }
@@ -185,6 +187,7 @@ export function createData(config) {
185
187
  function updatePending(sessionID, inboxID, delivery) {
186
188
  const index = store.session.pending[sessionID]?.findIndex((item) => item.id === inboxID) ?? -1;
187
189
  const item = store.session.pending[sessionID]?.[index];
190
+ pendingUpdates.get(sessionID)?.set(inboxID, item ? { ...item, delivery } : delivery);
188
191
  if (index < 0 || !item || item.delivery === delivery)
189
192
  return;
190
193
  setStore("session", "pending", sessionID, index, { ...item, delivery });
@@ -625,12 +628,14 @@ export function createData(config) {
625
628
  }
626
629
  case "session.inbox.enqueued": {
627
630
  outbox.delete(event.data.inboxID);
628
- admitLocal({
631
+ const item = {
629
632
  id: event.data.inboxID,
630
633
  sessionID: event.data.sessionID,
631
634
  time: { created: event.created },
632
635
  ...event.data.item,
633
- });
636
+ };
637
+ pendingUpdates.get(item.sessionID)?.set(item.id, item);
638
+ admitLocal(item);
634
639
  if (event.data.item.type === "compaction") {
635
640
  const active = compacting.get(event.data.sessionID);
636
641
  active?.observed.add(event.data.inboxID);
@@ -1238,23 +1243,46 @@ export function createData(config) {
1238
1243
  },
1239
1244
  sync(sessionID) {
1240
1245
  return sync.run(`session.pending:${sessionID}`, async () => {
1241
- const pending = await api().session.inbox.list({ sessionID });
1242
- // A positive read acknowledges admission even when its SSE echo is delayed.
1243
- pending.forEach((item) => outbox.delete(item.id));
1244
- // Compactions also coalesce by Session, not just by the proposed ID.
1245
- if (pending.some((item) => item.type === "compaction"))
1246
- store.session.pending[sessionID]
1247
- ?.filter((item) => item.type === "compaction")
1248
- .forEach((item) => outbox.delete(item.id));
1249
- // Keep optimistic rows still awaiting their echo: this fetch may
1250
- // have raced ahead of an in-flight admission the server does not
1251
- // know about yet.
1252
- const inflight = (store.session.pending[sessionID] ?? []).filter((item) => outbox.has(item.id));
1253
- const merged = inflight.length === 0 ? pending : [...pending, ...inflight];
1254
- batch(() => {
1255
- setStore("session", "pending", sessionID, reconcile(merged));
1256
- merged.forEach(materializeInboxMessage);
1257
- });
1246
+ const updates = new Map();
1247
+ pendingUpdates.set(sessionID, updates);
1248
+ try {
1249
+ const snapshot = await api().session.inbox.list({ sessionID });
1250
+ // Events can overtake this HTTP response on a remote connection.
1251
+ // Reconcile them before an older snapshot can resurrect delivered input.
1252
+ const current = new Map(snapshot.map((item) => [item.id, item]));
1253
+ updates.forEach((item, id) => {
1254
+ if (item === undefined)
1255
+ current.delete(id);
1256
+ else if (typeof item === "string") {
1257
+ const existing = current.get(id);
1258
+ if (existing)
1259
+ current.set(id, { ...existing, delivery: item });
1260
+ }
1261
+ else
1262
+ current.set(id, item);
1263
+ });
1264
+ const pending = [...current.values()];
1265
+ // A positive read acknowledges admission even when its SSE echo is delayed.
1266
+ pending.forEach((item) => outbox.delete(item.id));
1267
+ // Compactions also coalesce by Session, not just by the proposed ID.
1268
+ if (pending.some((item) => item.type === "compaction"))
1269
+ store.session.pending[sessionID]
1270
+ ?.filter((item) => item.type === "compaction")
1271
+ .forEach((item) => outbox.delete(item.id));
1272
+ // Keep optimistic rows still awaiting their echo: this fetch may
1273
+ // have raced ahead of an in-flight admission the server does not
1274
+ // know about yet.
1275
+ const inflight = (store.session.pending[sessionID] ?? []).filter((item) => outbox.has(item.id));
1276
+ const merged = inflight.length === 0 ? pending : [...pending, ...inflight];
1277
+ batch(() => {
1278
+ setStore("session", "pending", sessionID, reconcile(merged));
1279
+ merged.forEach(materializeInboxMessage);
1280
+ });
1281
+ }
1282
+ finally {
1283
+ if (pendingUpdates.get(sessionID) === updates)
1284
+ pendingUpdates.delete(sessionID);
1285
+ }
1258
1286
  });
1259
1287
  },
1260
1288
  invalidate(sessionID) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/client",
4
- "version": "0.0.0-dev-19629",
4
+ "version": "0.0.0-dev-19631",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -57,8 +57,8 @@
57
57
  "typecheck": "tsgo --noEmit"
58
58
  },
59
59
  "dependencies": {
60
- "@opencode/schema": "0.0.0-dev-19629",
61
- "@opencode/protocol": "0.0.0-dev-19629"
60
+ "@opencode/schema": "0.0.0-dev-19631",
61
+ "@opencode/protocol": "0.0.0-dev-19631"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "effect": "4.0.0-rc.112",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@effect/platform-node": "4.0.0-rc.112",
77
- "@opencode/httpapi-codegen": "0.0.0-dev-19629",
77
+ "@opencode/httpapi-codegen": "0.0.0-dev-19631",
78
78
  "@tsconfig/bun": "1.0.9",
79
79
  "@types/bun": "1.4.0",
80
80
  "@typescript/native-preview": "7.0.0-dev.20251207.1",