@kinotic-ai/core 1.8.1 → 1.9.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/index.cjs +32 -4
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +33 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -129,6 +129,7 @@ var EventConstants;
|
|
|
129
129
|
EventConstants2["CONNECTED_INFO_HEADER"] = "connected-info";
|
|
130
130
|
EventConstants2["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
|
|
131
131
|
EventConstants2["CORRELATION_ID_HEADER"] = "__correlation-id";
|
|
132
|
+
EventConstants2["ORIGIN_CRI_HEADER"] = "__origin-cri";
|
|
132
133
|
EventConstants2["ERROR_HEADER"] = "error";
|
|
133
134
|
EventConstants2["COMPLETE_HEADER"] = "complete";
|
|
134
135
|
EventConstants2["CONTROL_HEADER"] = "control";
|
|
@@ -144,6 +145,7 @@ var EventConstants;
|
|
|
144
145
|
EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
145
146
|
EventConstants2["CONTENT_JSON"] = "application/json";
|
|
146
147
|
EventConstants2["CONTENT_TEXT"] = "text/plain";
|
|
148
|
+
EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
147
149
|
EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
|
|
148
150
|
EventConstants2["TRACESTATE_HEADER"] = "tracestate";
|
|
149
151
|
})(EventConstants ||= {});
|
|
@@ -411,6 +413,9 @@ class EventBus {
|
|
|
411
413
|
requestRepliesObservable = null;
|
|
412
414
|
requestRepliesSubject = null;
|
|
413
415
|
requestRepliesSubscription = null;
|
|
416
|
+
activeCorrelationIds = new Set;
|
|
417
|
+
recentlyReaped = new Set;
|
|
418
|
+
static REAP_DEBOUNCE_MS = 5000;
|
|
414
419
|
constructor() {
|
|
415
420
|
this.stompConnectionManager.fatalErrors.subscribe(() => this.cleanup());
|
|
416
421
|
this.stompConnectionManager.replyToCriChangedHandler = (replyToCri) => {
|
|
@@ -485,11 +490,12 @@ class EventBus {
|
|
|
485
490
|
return new import_rxjs2.Observable((subscriber) => {
|
|
486
491
|
if (this.requestRepliesObservable == null) {
|
|
487
492
|
this.requestRepliesSubject = new import_rxjs2.Subject;
|
|
488
|
-
this.requestRepliesObservable = this._observe(this.replyToCri).pipe(import_operators.multicast(this.requestRepliesSubject));
|
|
493
|
+
this.requestRepliesObservable = this._observe(this.replyToCri).pipe(import_operators.tap((value) => this.cancelIfUnexpected(value)), import_operators.multicast(this.requestRepliesSubject));
|
|
489
494
|
this.requestRepliesSubscription = this.requestRepliesObservable.connect();
|
|
490
495
|
}
|
|
491
496
|
let serverSignaledCompletion = false;
|
|
492
497
|
const correlationId = import_uuid2.v4();
|
|
498
|
+
this.activeCorrelationIds.add(correlationId);
|
|
493
499
|
const defaultMessagesSubscription = this.requestRepliesObservable.pipe(import_operators.filter((value) => {
|
|
494
500
|
return value.headers.get("__correlation-id" /* CORRELATION_ID_HEADER */) === correlationId;
|
|
495
501
|
})).subscribe({
|
|
@@ -520,6 +526,7 @@ class EventBus {
|
|
|
520
526
|
event.setHeader("__correlation-id" /* CORRELATION_ID_HEADER */, correlationId);
|
|
521
527
|
this.send(event);
|
|
522
528
|
return () => {
|
|
529
|
+
this.activeCorrelationIds.delete(correlationId);
|
|
523
530
|
if (sendControlEvents && !serverSignaledCompletion) {
|
|
524
531
|
const controlEvent = new Event(event.cri);
|
|
525
532
|
controlEvent.setHeader("control" /* CONTROL_HEADER */, "cancel" /* CONTROL_VALUE_CANCEL */);
|
|
@@ -542,6 +549,24 @@ class EventBus {
|
|
|
542
549
|
this.resetRequestReplies("Connection disconnected");
|
|
543
550
|
this.serverInfo = null;
|
|
544
551
|
}
|
|
552
|
+
cancelIfUnexpected(value) {
|
|
553
|
+
const correlationId = value.getHeader("__correlation-id" /* CORRELATION_ID_HEADER */);
|
|
554
|
+
if (correlationId === undefined || this.activeCorrelationIds.has(correlationId)) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const originCri = value.getHeader("__origin-cri" /* ORIGIN_CRI_HEADER */);
|
|
558
|
+
if (originCri === undefined || this.recentlyReaped.has(correlationId)) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
const cancelEvent = new Event(originCri);
|
|
563
|
+
cancelEvent.setHeader("control" /* CONTROL_HEADER */, "cancel" /* CONTROL_VALUE_CANCEL */);
|
|
564
|
+
cancelEvent.setHeader("__correlation-id" /* CORRELATION_ID_HEADER */, correlationId);
|
|
565
|
+
this.send(cancelEvent);
|
|
566
|
+
this.recentlyReaped.add(correlationId);
|
|
567
|
+
setTimeout(() => this.recentlyReaped.delete(correlationId), EventBus.REAP_DEBOUNCE_MS);
|
|
568
|
+
} catch {}
|
|
569
|
+
}
|
|
545
570
|
resetRequestReplies(reason) {
|
|
546
571
|
if (this.requestRepliesSubject != null) {
|
|
547
572
|
this.requestRepliesSubject.error(new Error(reason));
|
|
@@ -551,6 +576,7 @@ class EventBus {
|
|
|
551
576
|
}
|
|
552
577
|
this.requestRepliesSubject = null;
|
|
553
578
|
this.requestRepliesObservable = null;
|
|
579
|
+
this.recentlyReaped.clear();
|
|
554
580
|
}
|
|
555
581
|
}
|
|
556
582
|
createSendUnavailableError() {
|
|
@@ -1010,7 +1036,7 @@ var import_operators2 = require("rxjs/operators");
|
|
|
1010
1036
|
// packages/core/package.json
|
|
1011
1037
|
var package_default = {
|
|
1012
1038
|
name: "@kinotic-ai/core",
|
|
1013
|
-
version: "1.
|
|
1039
|
+
version: "1.9.1",
|
|
1014
1040
|
type: "module",
|
|
1015
1041
|
files: [
|
|
1016
1042
|
"dist"
|
|
@@ -1215,10 +1241,12 @@ class ServiceProxy {
|
|
|
1215
1241
|
return eventBusToUse.requestStream(event, sendControlEvents).pipe(import_operators2.map((value) => {
|
|
1216
1242
|
const contentType = value.getHeader("content-type" /* CONTENT_TYPE_HEADER */);
|
|
1217
1243
|
if (contentType !== undefined) {
|
|
1218
|
-
if (contentType === "application/json") {
|
|
1244
|
+
if (contentType === "application/json" /* CONTENT_JSON */) {
|
|
1219
1245
|
return JSON.parse(value.getDataString());
|
|
1220
|
-
} else if (contentType === "text/plain") {
|
|
1246
|
+
} else if (contentType === "text/plain" /* CONTENT_TEXT */) {
|
|
1221
1247
|
return value.getDataString();
|
|
1248
|
+
} else if (contentType === "application/octet-stream" /* CONTENT_OCTET_STREAM */) {
|
|
1249
|
+
return value.data.orUndefined();
|
|
1222
1250
|
} else {
|
|
1223
1251
|
throw new Error("Content Type " + contentType + " is not supported");
|
|
1224
1252
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -266,6 +266,10 @@ declare enum EventConstants {
|
|
|
266
266
|
*/
|
|
267
267
|
CORRELATION_ID_HEADER = "__correlation-id",
|
|
268
268
|
/**
|
|
269
|
+
* Origin service CRI the server sends on stream replies so the client can route a cancel back to it.
|
|
270
|
+
*/
|
|
271
|
+
ORIGIN_CRI_HEADER = "__origin-cri",
|
|
272
|
+
/**
|
|
269
273
|
* Denotes that something caused an error. Will contain a brief message about the error
|
|
270
274
|
*/
|
|
271
275
|
ERROR_HEADER = "error",
|
|
@@ -292,6 +296,7 @@ declare enum EventConstants {
|
|
|
292
296
|
REPLY_DESTINATION_SCHEME = "reply",
|
|
293
297
|
CONTENT_JSON = "application/json",
|
|
294
298
|
CONTENT_TEXT = "text/plain",
|
|
299
|
+
CONTENT_OCTET_STREAM = "application/octet-stream",
|
|
295
300
|
/**
|
|
296
301
|
* The traceparent HTTP header field identifies the incoming request in a tracing system. It has four fields:
|
|
297
302
|
*
|
|
@@ -1067,6 +1072,9 @@ declare class EventBus implements IEventBus {
|
|
|
1067
1072
|
private requestRepliesObservable;
|
|
1068
1073
|
private requestRepliesSubject;
|
|
1069
1074
|
private requestRepliesSubscription;
|
|
1075
|
+
private readonly activeCorrelationIds;
|
|
1076
|
+
private readonly recentlyReaped;
|
|
1077
|
+
private static readonly REAP_DEBOUNCE_MS;
|
|
1070
1078
|
constructor();
|
|
1071
1079
|
get fatalErrors(): Observable3<Error>;
|
|
1072
1080
|
isConnectionActive(): boolean;
|
|
@@ -1082,6 +1090,12 @@ declare class EventBus implements IEventBus {
|
|
|
1082
1090
|
observe(cri: string): Observable3<IEvent>;
|
|
1083
1091
|
private cleanup;
|
|
1084
1092
|
/**
|
|
1093
|
+
* Cancels a server stream whose reply arrived for a correlationId we no longer track. The server can't
|
|
1094
|
+
* detect this itself since all requests share one reply destination, so the cancel is sent to the
|
|
1095
|
+
* originating service, whose CRI the server includes on each reply.
|
|
1096
|
+
*/
|
|
1097
|
+
private cancelIfUnexpected;
|
|
1098
|
+
/**
|
|
1085
1099
|
* Tears down the shared request-replies stream so the next request rebuilds it against the
|
|
1086
1100
|
* current {@link replyToCri}. Any in-flight requests are failed with the given reason since
|
|
1087
1101
|
* their replies can no longer be delivered.
|
package/dist/index.d.ts
CHANGED
|
@@ -266,6 +266,10 @@ declare enum EventConstants {
|
|
|
266
266
|
*/
|
|
267
267
|
CORRELATION_ID_HEADER = "__correlation-id",
|
|
268
268
|
/**
|
|
269
|
+
* Origin service CRI the server sends on stream replies so the client can route a cancel back to it.
|
|
270
|
+
*/
|
|
271
|
+
ORIGIN_CRI_HEADER = "__origin-cri",
|
|
272
|
+
/**
|
|
269
273
|
* Denotes that something caused an error. Will contain a brief message about the error
|
|
270
274
|
*/
|
|
271
275
|
ERROR_HEADER = "error",
|
|
@@ -292,6 +296,7 @@ declare enum EventConstants {
|
|
|
292
296
|
REPLY_DESTINATION_SCHEME = "reply",
|
|
293
297
|
CONTENT_JSON = "application/json",
|
|
294
298
|
CONTENT_TEXT = "text/plain",
|
|
299
|
+
CONTENT_OCTET_STREAM = "application/octet-stream",
|
|
295
300
|
/**
|
|
296
301
|
* The traceparent HTTP header field identifies the incoming request in a tracing system. It has four fields:
|
|
297
302
|
*
|
|
@@ -1067,6 +1072,9 @@ declare class EventBus implements IEventBus {
|
|
|
1067
1072
|
private requestRepliesObservable;
|
|
1068
1073
|
private requestRepliesSubject;
|
|
1069
1074
|
private requestRepliesSubscription;
|
|
1075
|
+
private readonly activeCorrelationIds;
|
|
1076
|
+
private readonly recentlyReaped;
|
|
1077
|
+
private static readonly REAP_DEBOUNCE_MS;
|
|
1070
1078
|
constructor();
|
|
1071
1079
|
get fatalErrors(): Observable3<Error>;
|
|
1072
1080
|
isConnectionActive(): boolean;
|
|
@@ -1082,6 +1090,12 @@ declare class EventBus implements IEventBus {
|
|
|
1082
1090
|
observe(cri: string): Observable3<IEvent>;
|
|
1083
1091
|
private cleanup;
|
|
1084
1092
|
/**
|
|
1093
|
+
* Cancels a server stream whose reply arrived for a correlationId we no longer track. The server can't
|
|
1094
|
+
* detect this itself since all requests share one reply destination, so the cancel is sent to the
|
|
1095
|
+
* originating service, whose CRI the server includes on each reply.
|
|
1096
|
+
*/
|
|
1097
|
+
private cancelIfUnexpected;
|
|
1098
|
+
/**
|
|
1085
1099
|
* Tears down the shared request-replies stream so the next request rebuilds it against the
|
|
1086
1100
|
* current {@link replyToCri}. Any in-flight requests are failed with the given reason since
|
|
1087
1101
|
* their replies can no longer be delivered.
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ var EventConstants;
|
|
|
28
28
|
EventConstants2["CONNECTED_INFO_HEADER"] = "connected-info";
|
|
29
29
|
EventConstants2["SESSION_KEEP_ALIVE_HEADER"] = "session-keep-alive";
|
|
30
30
|
EventConstants2["CORRELATION_ID_HEADER"] = "__correlation-id";
|
|
31
|
+
EventConstants2["ORIGIN_CRI_HEADER"] = "__origin-cri";
|
|
31
32
|
EventConstants2["ERROR_HEADER"] = "error";
|
|
32
33
|
EventConstants2["COMPLETE_HEADER"] = "complete";
|
|
33
34
|
EventConstants2["CONTROL_HEADER"] = "control";
|
|
@@ -43,6 +44,7 @@ var EventConstants;
|
|
|
43
44
|
EventConstants2["REPLY_DESTINATION_SCHEME"] = "reply";
|
|
44
45
|
EventConstants2["CONTENT_JSON"] = "application/json";
|
|
45
46
|
EventConstants2["CONTENT_TEXT"] = "text/plain";
|
|
47
|
+
EventConstants2["CONTENT_OCTET_STREAM"] = "application/octet-stream";
|
|
46
48
|
EventConstants2["TRACEPARENT_HEADER"] = "traceparent";
|
|
47
49
|
EventConstants2["TRACESTATE_HEADER"] = "tracestate";
|
|
48
50
|
})(EventConstants ||= {});
|
|
@@ -263,7 +265,7 @@ class StompConnectionManager {
|
|
|
263
265
|
// packages/core/src/api/event/EventBus.ts
|
|
264
266
|
import { context, propagation } from "@opentelemetry/api";
|
|
265
267
|
import { firstValueFrom, Observable as Observable2, Subject as Subject2, throwError } from "rxjs";
|
|
266
|
-
import { filter, map, multicast } from "rxjs/operators";
|
|
268
|
+
import { filter, map, multicast, tap } from "rxjs/operators";
|
|
267
269
|
import { Optional } from "typescript-optional";
|
|
268
270
|
import { v4 as uuidv42 } from "uuid";
|
|
269
271
|
class Event {
|
|
@@ -310,6 +312,9 @@ class EventBus {
|
|
|
310
312
|
requestRepliesObservable = null;
|
|
311
313
|
requestRepliesSubject = null;
|
|
312
314
|
requestRepliesSubscription = null;
|
|
315
|
+
activeCorrelationIds = new Set;
|
|
316
|
+
recentlyReaped = new Set;
|
|
317
|
+
static REAP_DEBOUNCE_MS = 5000;
|
|
313
318
|
constructor() {
|
|
314
319
|
this.stompConnectionManager.fatalErrors.subscribe(() => this.cleanup());
|
|
315
320
|
this.stompConnectionManager.replyToCriChangedHandler = (replyToCri) => {
|
|
@@ -384,11 +389,12 @@ class EventBus {
|
|
|
384
389
|
return new Observable2((subscriber) => {
|
|
385
390
|
if (this.requestRepliesObservable == null) {
|
|
386
391
|
this.requestRepliesSubject = new Subject2;
|
|
387
|
-
this.requestRepliesObservable = this._observe(this.replyToCri).pipe(multicast(this.requestRepliesSubject));
|
|
392
|
+
this.requestRepliesObservable = this._observe(this.replyToCri).pipe(tap((value) => this.cancelIfUnexpected(value)), multicast(this.requestRepliesSubject));
|
|
388
393
|
this.requestRepliesSubscription = this.requestRepliesObservable.connect();
|
|
389
394
|
}
|
|
390
395
|
let serverSignaledCompletion = false;
|
|
391
396
|
const correlationId = uuidv42();
|
|
397
|
+
this.activeCorrelationIds.add(correlationId);
|
|
392
398
|
const defaultMessagesSubscription = this.requestRepliesObservable.pipe(filter((value) => {
|
|
393
399
|
return value.headers.get("__correlation-id" /* CORRELATION_ID_HEADER */) === correlationId;
|
|
394
400
|
})).subscribe({
|
|
@@ -419,6 +425,7 @@ class EventBus {
|
|
|
419
425
|
event.setHeader("__correlation-id" /* CORRELATION_ID_HEADER */, correlationId);
|
|
420
426
|
this.send(event);
|
|
421
427
|
return () => {
|
|
428
|
+
this.activeCorrelationIds.delete(correlationId);
|
|
422
429
|
if (sendControlEvents && !serverSignaledCompletion) {
|
|
423
430
|
const controlEvent = new Event(event.cri);
|
|
424
431
|
controlEvent.setHeader("control" /* CONTROL_HEADER */, "cancel" /* CONTROL_VALUE_CANCEL */);
|
|
@@ -441,6 +448,24 @@ class EventBus {
|
|
|
441
448
|
this.resetRequestReplies("Connection disconnected");
|
|
442
449
|
this.serverInfo = null;
|
|
443
450
|
}
|
|
451
|
+
cancelIfUnexpected(value) {
|
|
452
|
+
const correlationId = value.getHeader("__correlation-id" /* CORRELATION_ID_HEADER */);
|
|
453
|
+
if (correlationId === undefined || this.activeCorrelationIds.has(correlationId)) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const originCri = value.getHeader("__origin-cri" /* ORIGIN_CRI_HEADER */);
|
|
457
|
+
if (originCri === undefined || this.recentlyReaped.has(correlationId)) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
const cancelEvent = new Event(originCri);
|
|
462
|
+
cancelEvent.setHeader("control" /* CONTROL_HEADER */, "cancel" /* CONTROL_VALUE_CANCEL */);
|
|
463
|
+
cancelEvent.setHeader("__correlation-id" /* CORRELATION_ID_HEADER */, correlationId);
|
|
464
|
+
this.send(cancelEvent);
|
|
465
|
+
this.recentlyReaped.add(correlationId);
|
|
466
|
+
setTimeout(() => this.recentlyReaped.delete(correlationId), EventBus.REAP_DEBOUNCE_MS);
|
|
467
|
+
} catch {}
|
|
468
|
+
}
|
|
444
469
|
resetRequestReplies(reason) {
|
|
445
470
|
if (this.requestRepliesSubject != null) {
|
|
446
471
|
this.requestRepliesSubject.error(new Error(reason));
|
|
@@ -450,6 +475,7 @@ class EventBus {
|
|
|
450
475
|
}
|
|
451
476
|
this.requestRepliesSubject = null;
|
|
452
477
|
this.requestRepliesObservable = null;
|
|
478
|
+
this.recentlyReaped.clear();
|
|
453
479
|
}
|
|
454
480
|
}
|
|
455
481
|
createSendUnavailableError() {
|
|
@@ -912,7 +938,7 @@ import { first, map as map2 } from "rxjs/operators";
|
|
|
912
938
|
// packages/core/package.json
|
|
913
939
|
var package_default = {
|
|
914
940
|
name: "@kinotic-ai/core",
|
|
915
|
-
version: "1.
|
|
941
|
+
version: "1.9.1",
|
|
916
942
|
type: "module",
|
|
917
943
|
files: [
|
|
918
944
|
"dist"
|
|
@@ -1117,10 +1143,12 @@ class ServiceProxy {
|
|
|
1117
1143
|
return eventBusToUse.requestStream(event, sendControlEvents).pipe(map2((value) => {
|
|
1118
1144
|
const contentType = value.getHeader("content-type" /* CONTENT_TYPE_HEADER */);
|
|
1119
1145
|
if (contentType !== undefined) {
|
|
1120
|
-
if (contentType === "application/json") {
|
|
1146
|
+
if (contentType === "application/json" /* CONTENT_JSON */) {
|
|
1121
1147
|
return JSON.parse(value.getDataString());
|
|
1122
|
-
} else if (contentType === "text/plain") {
|
|
1148
|
+
} else if (contentType === "text/plain" /* CONTENT_TEXT */) {
|
|
1123
1149
|
return value.getDataString();
|
|
1150
|
+
} else if (contentType === "application/octet-stream" /* CONTENT_OCTET_STREAM */) {
|
|
1151
|
+
return value.data.orUndefined();
|
|
1124
1152
|
} else {
|
|
1125
1153
|
throw new Error("Content Type " + contentType + " is not supported");
|
|
1126
1154
|
}
|