@twoabove/cue 0.5.0 → 0.5.1
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/README.md +5 -1
- package/dist/runtime/Entity.d.ts.map +1 -1
- package/dist/runtime/Entity.js +24 -43
- package/dist/stream/reader.d.ts.map +1 -1
- package/dist/stream/reader.js +10 -6
- package/dist/stream/types.d.ts +9 -4
- package/dist/stream/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -220,10 +220,14 @@ Check stream status without consuming:
|
|
|
220
220
|
```typescript
|
|
221
221
|
const status = await manager.streamStatus(streamId);
|
|
222
222
|
// { state: 'running', seq: 42n }
|
|
223
|
-
// { state: 'complete', seq: 100n }
|
|
223
|
+
// { state: 'complete', seq: 100n, returnValue: { report: ... } }
|
|
224
224
|
// { state: 'error', seq: 50n, error: 'timeout' }
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
+
The `returnValue` field contains the generator's return value once complete.
|
|
228
|
+
|
|
229
|
+
**Note:** The entity is locked during stream execution (one operation at a time). Other commands to the same entity will queue until the stream finishes. This ensures consistency but means long streams block other operations on that entity.
|
|
230
|
+
|
|
227
231
|
This is essential for AI assistants, file processors, report generators - any operation that takes longer than a network timeout.
|
|
228
232
|
|
|
229
233
|
## Schema Evolution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../src/runtime/Entity.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,KAAK,EAGV,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEb,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAQ5C,qBAAa,MAAM,CAAC,MAAM,SAAS,MAAM;a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AM,OAAO,EAAE,KACd,SAAS,CAAC,OAAO,CAAC,CAsInB;IAEK,OAAO,QAAa,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAMpE;IAEK,SAAS,QAAa,OAAO,CAAC,IAAI,CAAC,CAKxC;IAEK,OAAO,GACZ,eAAe,MAAM,KACpB,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CA8CnD;YAEY,MAAM;YAkCN,YAAY;YASZ,OAAO;IAgER,aAAa,CAAC,KAAK,UAAQ;IA0BxC,OAAO,CAAC,OAAO,CAOb;IAEF,OAAO,CAAC,MAAM,CAIZ;IAEF,OAAO,CAAC,YAAY;CAOrB"}
|
package/dist/runtime/Entity.js
CHANGED
|
@@ -93,10 +93,9 @@ export class Entity {
|
|
|
93
93
|
const streamId = `${this.id}:${handlerName}:${newId()}`;
|
|
94
94
|
const channel = [];
|
|
95
95
|
let consumerWaiting = null;
|
|
96
|
-
let producerWaiting = null;
|
|
97
|
-
let aborted = false;
|
|
98
96
|
let currentSeq = 0n;
|
|
99
97
|
let isLive = true;
|
|
98
|
+
let producerDone = false;
|
|
100
99
|
function push(item) {
|
|
101
100
|
if (consumerWaiting) {
|
|
102
101
|
const resolve = consumerWaiting;
|
|
@@ -115,21 +114,6 @@ export class Entity {
|
|
|
115
114
|
consumerWaiting = resolve;
|
|
116
115
|
});
|
|
117
116
|
}
|
|
118
|
-
function signalProducerContinue() {
|
|
119
|
-
if (producerWaiting) {
|
|
120
|
-
const { resolve } = producerWaiting;
|
|
121
|
-
producerWaiting = null;
|
|
122
|
-
resolve();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function signalProducerAbort() {
|
|
126
|
-
aborted = true;
|
|
127
|
-
if (producerWaiting) {
|
|
128
|
-
const { reject } = producerWaiting;
|
|
129
|
-
producerWaiting = null;
|
|
130
|
-
reject(new Error("stream aborted"));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
117
|
async function commitStreamChunk(value) {
|
|
134
118
|
if (!self.store)
|
|
135
119
|
return;
|
|
@@ -143,14 +127,10 @@ export class Entity {
|
|
|
143
127
|
};
|
|
144
128
|
await self.store.commitEvent(streamId, currentSeq, serialize(envelope));
|
|
145
129
|
}
|
|
146
|
-
async function commitStreamEnd(
|
|
130
|
+
async function commitStreamEnd(payload) {
|
|
147
131
|
if (!self.store)
|
|
148
132
|
return;
|
|
149
133
|
currentSeq += 1n;
|
|
150
|
-
const payload = { state };
|
|
151
|
-
if (error) {
|
|
152
|
-
payload.error = error;
|
|
153
|
-
}
|
|
154
134
|
const envelope = {
|
|
155
135
|
entityDefName: STREAM_ENTITY_DEF_NAME,
|
|
156
136
|
schemaVersion: STREAM_SCHEMA_VERSION,
|
|
@@ -163,31 +143,32 @@ export class Entity {
|
|
|
163
143
|
const mailboxTask = self.mailbox.enqueue(async () => {
|
|
164
144
|
await self.ensureActive();
|
|
165
145
|
const stream = self.kernel.startStream(handlerName, args, self.buildContext());
|
|
146
|
+
let finalReturn;
|
|
166
147
|
try {
|
|
167
|
-
|
|
168
|
-
await
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
148
|
+
while (true) {
|
|
149
|
+
const result = await stream.generator.next();
|
|
150
|
+
if (result.done) {
|
|
151
|
+
finalReturn = result.value;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
await commitStreamChunk(result.value);
|
|
155
|
+
push({ type: "value", value: result.value });
|
|
173
156
|
}
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
producerDone = true;
|
|
158
|
+
push({ type: "done", returnValue: finalReturn });
|
|
159
|
+
await commitStreamEnd({ state: "complete", returnValue: finalReturn });
|
|
176
160
|
}
|
|
177
161
|
catch (e) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
// If aborted by consumer, still write end event
|
|
186
|
-
await commitStreamEnd("complete");
|
|
162
|
+
stream.discard();
|
|
163
|
+
producerDone = true;
|
|
164
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
165
|
+
await commitStreamEnd({ state: "error", error: errorMsg });
|
|
166
|
+
push({ type: "error", error: e });
|
|
167
|
+
return;
|
|
187
168
|
}
|
|
188
169
|
const { patches, nextState } = stream.finalize();
|
|
189
170
|
if (patches.length > 0) {
|
|
190
|
-
await self.commit(handlerName, args,
|
|
171
|
+
await self.commit(handlerName, args, finalReturn, patches, nextState);
|
|
191
172
|
}
|
|
192
173
|
});
|
|
193
174
|
async function* outerGenerator() {
|
|
@@ -203,13 +184,13 @@ export class Entity {
|
|
|
203
184
|
throw item.error;
|
|
204
185
|
}
|
|
205
186
|
yield item.value;
|
|
206
|
-
signalProducerContinue();
|
|
207
187
|
}
|
|
208
188
|
}
|
|
209
189
|
finally {
|
|
210
|
-
signalProducerAbort();
|
|
211
|
-
await mailboxTask;
|
|
212
190
|
isLive = false;
|
|
191
|
+
if (!producerDone) {
|
|
192
|
+
await mailboxTask;
|
|
193
|
+
}
|
|
213
194
|
}
|
|
214
195
|
}
|
|
215
196
|
const streamRun = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/stream/reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EACV,iBAAiB,EAGjB,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,wBAAsB,YAAY,CAChC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/stream/reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EACV,iBAAiB,EAGjB,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,wBAAsB,YAAY,CAChC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAoC9B;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,YAAY,CAAC,CAAC,CAAC,CAwCjB"}
|
package/dist/stream/reader.js
CHANGED
|
@@ -14,14 +14,18 @@ export async function streamStatus(store, streamId) {
|
|
|
14
14
|
}
|
|
15
15
|
if (envelope.handler === "end") {
|
|
16
16
|
const endPayload = envelope.payload[0];
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (endPayload.state === "error") {
|
|
18
|
+
return {
|
|
19
|
+
state: "error",
|
|
20
|
+
seq: BigInt(events.length - 1),
|
|
21
|
+
error: endPayload.error,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
state: "complete",
|
|
19
26
|
seq: BigInt(events.length - 1),
|
|
27
|
+
returnValue: endPayload.returnValue,
|
|
20
28
|
};
|
|
21
|
-
if (endPayload.error) {
|
|
22
|
-
status.error = endPayload.error;
|
|
23
|
-
}
|
|
24
|
-
return status;
|
|
25
29
|
}
|
|
26
30
|
return {
|
|
27
31
|
state: "running",
|
package/dist/stream/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface StreamStatus {
|
|
|
6
6
|
state: "running" | "complete" | "error";
|
|
7
7
|
seq: bigint;
|
|
8
8
|
error?: string;
|
|
9
|
+
returnValue?: unknown;
|
|
9
10
|
}
|
|
10
11
|
export interface StreamRun<T> extends AsyncIterable<T> {
|
|
11
12
|
readonly id: string;
|
|
@@ -25,14 +26,18 @@ export interface StreamChunkEnvelope {
|
|
|
25
26
|
payload: [unknown];
|
|
26
27
|
patches: readonly [];
|
|
27
28
|
}
|
|
29
|
+
export type StreamEndPayload = {
|
|
30
|
+
state: "complete";
|
|
31
|
+
returnValue?: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
state: "error";
|
|
34
|
+
error: string;
|
|
35
|
+
};
|
|
28
36
|
export interface StreamEndEnvelope {
|
|
29
37
|
entityDefName: "__stream__";
|
|
30
38
|
schemaVersion: 1;
|
|
31
39
|
handler: "end";
|
|
32
|
-
payload: [
|
|
33
|
-
state: "complete" | "error";
|
|
34
|
-
error?: string;
|
|
35
|
-
}];
|
|
40
|
+
payload: [StreamEndPayload];
|
|
36
41
|
patches: readonly [];
|
|
37
42
|
}
|
|
38
43
|
export type StreamEventEnvelope = StreamChunkEnvelope | StreamEndEnvelope;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;C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