@hexis-ai/engram-sdk 0.11.0 → 0.11.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/dist/buffered.js +21 -25
- package/package.json +1 -1
package/dist/buffered.js
CHANGED
|
@@ -106,6 +106,12 @@ export class BufferedTelemetry {
|
|
|
106
106
|
class BufferedSession {
|
|
107
107
|
engram;
|
|
108
108
|
id;
|
|
109
|
+
/**
|
|
110
|
+
* Resolves to `true` when POST /v1/sessions acked, `false` on
|
|
111
|
+
* transport failure. Never rejects — preserves Bun's strict
|
|
112
|
+
* unhandled-rejection contract even when callers don't await
|
|
113
|
+
* the buffer (Langfuse-style fire-and-forget).
|
|
114
|
+
*/
|
|
109
115
|
ready;
|
|
110
116
|
inner;
|
|
111
117
|
ended = false;
|
|
@@ -113,14 +119,12 @@ class BufferedSession {
|
|
|
113
119
|
this.engram = engram;
|
|
114
120
|
this.id = init.id;
|
|
115
121
|
this.inner = new EngramSession(engram, init.id);
|
|
116
|
-
// Fire-and-forget POST /v1/sessions. The ready promise is awaited
|
|
117
|
-
// before the first flush so messages enqueued before the create
|
|
118
|
-
// ack don't race.
|
|
119
122
|
this.ready = engram
|
|
120
123
|
.startSessionWithoutHandle(init)
|
|
124
|
+
.then(() => true)
|
|
121
125
|
.catch((e) => {
|
|
122
126
|
engram.config.onError(e);
|
|
123
|
-
|
|
127
|
+
return false;
|
|
124
128
|
});
|
|
125
129
|
}
|
|
126
130
|
message(input) {
|
|
@@ -170,9 +174,6 @@ class BufferedSession {
|
|
|
170
174
|
* info and the host now has more (e.g. resolved channel later).
|
|
171
175
|
*/
|
|
172
176
|
update(input) {
|
|
173
|
-
// Only patch the fields callers might actually mutate post-creation;
|
|
174
|
-
// skip `participants` / `viewable_by` which are append-only via
|
|
175
|
-
// participant events.
|
|
176
177
|
const patch = {};
|
|
177
178
|
if (input.title !== undefined)
|
|
178
179
|
patch.title = input.title;
|
|
@@ -190,33 +191,28 @@ class BufferedSession {
|
|
|
190
191
|
patch.trigger_event_id = input.trigger_event_id;
|
|
191
192
|
if (Object.keys(patch).length === 0)
|
|
192
193
|
return;
|
|
193
|
-
void this.ready
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
void this.ready.then((ok) => {
|
|
195
|
+
if (!ok)
|
|
196
|
+
return;
|
|
197
|
+
return this.engram
|
|
198
|
+
.updateSession(this.id, patch)
|
|
199
|
+
.catch((e) => this.engram.config.onError(e));
|
|
200
|
+
});
|
|
196
201
|
}
|
|
197
202
|
async flush() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// failed (ready rejected).
|
|
201
|
-
try {
|
|
202
|
-
await this.ready;
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
203
|
+
const ok = await this.ready;
|
|
204
|
+
if (!ok)
|
|
205
205
|
return;
|
|
206
|
-
|
|
207
|
-
await this.inner.flush();
|
|
206
|
+
await this.inner.flush().catch((e) => this.engram.config.onError(e));
|
|
208
207
|
}
|
|
209
208
|
async shutdown() {
|
|
210
209
|
if (this.ended)
|
|
211
210
|
return;
|
|
212
211
|
this.ended = true;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
212
|
+
const ok = await this.ready;
|
|
213
|
+
if (!ok)
|
|
217
214
|
return;
|
|
218
|
-
|
|
219
|
-
await this.inner.end();
|
|
215
|
+
await this.inner.end().catch((e) => this.engram.config.onError(e));
|
|
220
216
|
}
|
|
221
217
|
}
|
|
222
218
|
// --- Helpers --------------------------------------------------------------
|