@theoremjs/web 0.3.5-next.1014.g14db6b7 → 0.3.5-next.1016.gc4ded01
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/package.json +2 -2
- package/server/conversation-core.js +30 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/web",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.1016.gc4ded01",
|
|
4
4
|
"description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"zod": "^4.6.5",
|
|
28
|
-
"@theoremjs/agents": "^0.3.5-next.
|
|
28
|
+
"@theoremjs/agents": "^0.3.5-next.1016.gc4ded01"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -118,33 +118,46 @@ function chatInbox(ctx, at, host, opened, ref) {
|
|
|
118
118
|
});
|
|
119
119
|
return { inbox, key: opened.conversation.id, leaseMs };
|
|
120
120
|
}
|
|
121
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* The values `produce` sends, as it sends them, then its end or what it threw. `send` settles once
|
|
123
|
+
* the consumer has taken the value and gone on past it, so the producer never runs ahead of what
|
|
124
|
+
* the consumer has handled. A producer awaits each `send`. When the consumer stops early, each
|
|
125
|
+
* `send` still waiting settles.
|
|
126
|
+
*/
|
|
122
127
|
async function* sent(produce) {
|
|
123
128
|
const queue = [];
|
|
124
129
|
let ended;
|
|
125
130
|
let wake = () => { };
|
|
126
|
-
produce((value) => {
|
|
127
|
-
queue.push(value);
|
|
131
|
+
produce((value) => new Promise((handled) => {
|
|
132
|
+
queue.push({ value, handled });
|
|
128
133
|
wake();
|
|
129
|
-
}).then((value) => {
|
|
134
|
+
})).then((value) => {
|
|
130
135
|
ended = { failed: false, value };
|
|
131
136
|
wake();
|
|
132
137
|
}, (failure) => {
|
|
133
138
|
ended = { failed: true, failure };
|
|
134
139
|
wake();
|
|
135
140
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
try {
|
|
142
|
+
for (;;) {
|
|
143
|
+
const next = queue.shift();
|
|
144
|
+
if (next) {
|
|
145
|
+
yield next.value;
|
|
146
|
+
next.handled();
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (ended?.failed)
|
|
150
|
+
throw ended.failure;
|
|
151
|
+
if (ended)
|
|
152
|
+
return ended.value;
|
|
153
|
+
await new Promise((resolve) => {
|
|
154
|
+
wake = resolve;
|
|
155
|
+
});
|
|
140
156
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
await new Promise((resolve) => {
|
|
146
|
-
wake = resolve;
|
|
147
|
-
});
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
for (const waiting of queue.splice(0))
|
|
160
|
+
waiting.handled();
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
163
|
function holdingOver(kept, chat) {
|
|
@@ -183,11 +196,11 @@ function holdingOver(kept, chat) {
|
|
|
183
196
|
const ref = chat.ref();
|
|
184
197
|
// why: The page moves a message it shows as waiting into the reply that reads it, as the reply starts.
|
|
185
198
|
if (run.opened.length > 0 && ref !== null) {
|
|
186
|
-
send({ type: 'conversation', ref, opened: run.opened.map((item) => item.id) });
|
|
199
|
+
await send({ type: 'conversation', ref, opened: run.opened.map((item) => item.id) });
|
|
187
200
|
}
|
|
188
201
|
for await (const line of lines(held)) {
|
|
189
202
|
chat.seen(line);
|
|
190
|
-
send(line);
|
|
203
|
+
await send(line);
|
|
191
204
|
}
|
|
192
205
|
},
|
|
193
206
|
gaveUp: kept.gaveUp,
|