@semiont/api-client 0.2.34-build.90 → 0.2.34-build.91
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.d.ts +7 -7
- package/dist/index.js +47 -55
- package/dist/index.js.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -297,7 +297,7 @@ declare class SSEClient {
|
|
|
297
297
|
* stream.close();
|
|
298
298
|
* ```
|
|
299
299
|
*/
|
|
300
|
-
detectReferences(resourceId: ResourceUri, request: DetectReferencesStreamRequest, options
|
|
300
|
+
detectReferences(resourceId: ResourceUri, request: DetectReferencesStreamRequest, options: SSERequestOptions): SSEStream;
|
|
301
301
|
/**
|
|
302
302
|
* Generate resource from annotation (streaming)
|
|
303
303
|
*
|
|
@@ -335,7 +335,7 @@ declare class SSEClient {
|
|
|
335
335
|
* stream.close();
|
|
336
336
|
* ```
|
|
337
337
|
*/
|
|
338
|
-
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options
|
|
338
|
+
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options: SSERequestOptions): SSEStream;
|
|
339
339
|
/**
|
|
340
340
|
* Detect highlights in a resource (streaming)
|
|
341
341
|
*
|
|
@@ -371,7 +371,7 @@ declare class SSEClient {
|
|
|
371
371
|
* stream.close();
|
|
372
372
|
* ```
|
|
373
373
|
*/
|
|
374
|
-
detectHighlights(resourceId: ResourceUri, request
|
|
374
|
+
detectHighlights(resourceId: ResourceUri, request: DetectHighlightsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
375
375
|
/**
|
|
376
376
|
* Detect assessments in a resource (streaming)
|
|
377
377
|
*
|
|
@@ -407,7 +407,7 @@ declare class SSEClient {
|
|
|
407
407
|
* stream.close();
|
|
408
408
|
* ```
|
|
409
409
|
*/
|
|
410
|
-
detectAssessments(resourceId: ResourceUri, request
|
|
410
|
+
detectAssessments(resourceId: ResourceUri, request: DetectAssessmentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
411
411
|
/**
|
|
412
412
|
* Detect comments in a resource (streaming)
|
|
413
413
|
*
|
|
@@ -447,7 +447,7 @@ declare class SSEClient {
|
|
|
447
447
|
* stream.close();
|
|
448
448
|
* ```
|
|
449
449
|
*/
|
|
450
|
-
detectComments(resourceId: ResourceUri, request
|
|
450
|
+
detectComments(resourceId: ResourceUri, request: DetectCommentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
451
451
|
/**
|
|
452
452
|
* Detect tags in a resource (streaming)
|
|
453
453
|
*
|
|
@@ -488,7 +488,7 @@ declare class SSEClient {
|
|
|
488
488
|
* stream.close();
|
|
489
489
|
* ```
|
|
490
490
|
*/
|
|
491
|
-
detectTags(resourceId: ResourceUri, request: DetectTagsStreamRequest, options
|
|
491
|
+
detectTags(resourceId: ResourceUri, request: DetectTagsStreamRequest, options: SSERequestOptions): SSEStream;
|
|
492
492
|
/**
|
|
493
493
|
* Subscribe to resource events (long-lived stream)
|
|
494
494
|
*
|
|
@@ -523,7 +523,7 @@ declare class SSEClient {
|
|
|
523
523
|
* stream.close();
|
|
524
524
|
* ```
|
|
525
525
|
*/
|
|
526
|
-
resourceEvents(resourceId: ResourceUri, options
|
|
526
|
+
resourceEvents(resourceId: ResourceUri, options: SSERequestOptions & {
|
|
527
527
|
onConnected?: () => void;
|
|
528
528
|
}): SSEStream;
|
|
529
529
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import { resourceUri } from '@semiont/core';
|
|
|
6
6
|
// src/sse/stream.ts
|
|
7
7
|
function createSSEStream(url, fetchOptions, config, logger) {
|
|
8
8
|
const abortController = new AbortController();
|
|
9
|
-
const customHandlers = /* @__PURE__ */ new Map();
|
|
10
9
|
let closed = false;
|
|
11
10
|
const connect = async () => {
|
|
12
11
|
try {
|
|
@@ -117,15 +116,14 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
117
116
|
event: eventType || "message",
|
|
118
117
|
hasData: !!data
|
|
119
118
|
});
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
119
|
+
if (typeof parsed === "object" && parsed !== null && "type" in parsed) {
|
|
120
|
+
config.eventBus.get(eventType).next(parsed);
|
|
121
|
+
config.eventBus.get("make-meaning:event").next(parsed);
|
|
122
|
+
} else {
|
|
123
|
+
config.eventBus.get(eventType).next(parsed);
|
|
126
124
|
}
|
|
127
|
-
if (config.
|
|
128
|
-
if (config.progressEvents.includes(eventType)) {
|
|
125
|
+
if (config.eventPrefix) {
|
|
126
|
+
if (config.progressEvents.includes("*") || config.progressEvents.includes(eventType)) {
|
|
129
127
|
config.eventBus.get(`${config.eventPrefix}:progress`).next(parsed);
|
|
130
128
|
}
|
|
131
129
|
if (config.completeEvent && eventType === config.completeEvent) {
|
|
@@ -149,10 +147,6 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
149
147
|
return {
|
|
150
148
|
close() {
|
|
151
149
|
abortController.abort();
|
|
152
|
-
},
|
|
153
|
-
// Internal method for custom event handlers (used by resourceEvents)
|
|
154
|
-
on(event, callback) {
|
|
155
|
-
customHandlers.set(event, callback);
|
|
156
150
|
}
|
|
157
151
|
};
|
|
158
152
|
}
|
|
@@ -230,14 +224,14 @@ var SSEClient = class {
|
|
|
230
224
|
url,
|
|
231
225
|
{
|
|
232
226
|
method: "POST",
|
|
233
|
-
headers: this.getHeaders(options
|
|
227
|
+
headers: this.getHeaders(options.auth),
|
|
234
228
|
body: JSON.stringify(request)
|
|
235
229
|
},
|
|
236
230
|
{
|
|
237
|
-
progressEvents: ["
|
|
238
|
-
completeEvent: "
|
|
239
|
-
errorEvent: "
|
|
240
|
-
eventBus: options
|
|
231
|
+
progressEvents: ["detection:started", "detection:progress"],
|
|
232
|
+
completeEvent: "detection:complete",
|
|
233
|
+
errorEvent: "detection:failed",
|
|
234
|
+
eventBus: options.eventBus,
|
|
241
235
|
eventPrefix: "detection"
|
|
242
236
|
},
|
|
243
237
|
this.logger
|
|
@@ -288,14 +282,14 @@ var SSEClient = class {
|
|
|
288
282
|
url,
|
|
289
283
|
{
|
|
290
284
|
method: "POST",
|
|
291
|
-
headers: this.getHeaders(options
|
|
285
|
+
headers: this.getHeaders(options.auth),
|
|
292
286
|
body: JSON.stringify(request)
|
|
293
287
|
},
|
|
294
288
|
{
|
|
295
|
-
progressEvents: ["generation
|
|
296
|
-
completeEvent: "generation
|
|
297
|
-
errorEvent: "generation
|
|
298
|
-
eventBus: options
|
|
289
|
+
progressEvents: ["generation:started", "generation:progress"],
|
|
290
|
+
completeEvent: "generation:complete",
|
|
291
|
+
errorEvent: "generation:failed",
|
|
292
|
+
eventBus: options.eventBus,
|
|
299
293
|
eventPrefix: "generation"
|
|
300
294
|
},
|
|
301
295
|
this.logger
|
|
@@ -343,14 +337,14 @@ var SSEClient = class {
|
|
|
343
337
|
url,
|
|
344
338
|
{
|
|
345
339
|
method: "POST",
|
|
346
|
-
headers: this.getHeaders(options
|
|
340
|
+
headers: this.getHeaders(options.auth),
|
|
347
341
|
body: JSON.stringify(request)
|
|
348
342
|
},
|
|
349
343
|
{
|
|
350
|
-
progressEvents: ["
|
|
351
|
-
completeEvent: "
|
|
352
|
-
errorEvent: "
|
|
353
|
-
eventBus: options
|
|
344
|
+
progressEvents: ["detection:started", "detection:progress"],
|
|
345
|
+
completeEvent: "detection:complete",
|
|
346
|
+
errorEvent: "detection:failed",
|
|
347
|
+
eventBus: options.eventBus,
|
|
354
348
|
eventPrefix: "detection"
|
|
355
349
|
},
|
|
356
350
|
this.logger
|
|
@@ -398,14 +392,14 @@ var SSEClient = class {
|
|
|
398
392
|
url,
|
|
399
393
|
{
|
|
400
394
|
method: "POST",
|
|
401
|
-
headers: this.getHeaders(options
|
|
395
|
+
headers: this.getHeaders(options.auth),
|
|
402
396
|
body: JSON.stringify(request)
|
|
403
397
|
},
|
|
404
398
|
{
|
|
405
|
-
progressEvents: ["
|
|
406
|
-
completeEvent: "
|
|
407
|
-
errorEvent: "
|
|
408
|
-
eventBus: options
|
|
399
|
+
progressEvents: ["detection:started", "detection:progress"],
|
|
400
|
+
completeEvent: "detection:complete",
|
|
401
|
+
errorEvent: "detection:failed",
|
|
402
|
+
eventBus: options.eventBus,
|
|
409
403
|
eventPrefix: "detection"
|
|
410
404
|
},
|
|
411
405
|
this.logger
|
|
@@ -457,14 +451,14 @@ var SSEClient = class {
|
|
|
457
451
|
url,
|
|
458
452
|
{
|
|
459
453
|
method: "POST",
|
|
460
|
-
headers: this.getHeaders(options
|
|
454
|
+
headers: this.getHeaders(options.auth),
|
|
461
455
|
body: JSON.stringify(request)
|
|
462
456
|
},
|
|
463
457
|
{
|
|
464
|
-
progressEvents: ["
|
|
465
|
-
completeEvent: "
|
|
466
|
-
errorEvent: "
|
|
467
|
-
eventBus: options
|
|
458
|
+
progressEvents: ["detection:started", "detection:progress"],
|
|
459
|
+
completeEvent: "detection:complete",
|
|
460
|
+
errorEvent: "detection:failed",
|
|
461
|
+
eventBus: options.eventBus,
|
|
468
462
|
eventPrefix: "detection"
|
|
469
463
|
},
|
|
470
464
|
this.logger
|
|
@@ -517,14 +511,14 @@ var SSEClient = class {
|
|
|
517
511
|
url,
|
|
518
512
|
{
|
|
519
513
|
method: "POST",
|
|
520
|
-
headers: this.getHeaders(options
|
|
514
|
+
headers: this.getHeaders(options.auth),
|
|
521
515
|
body: JSON.stringify(request)
|
|
522
516
|
},
|
|
523
517
|
{
|
|
524
|
-
progressEvents: ["
|
|
525
|
-
completeEvent: "
|
|
526
|
-
errorEvent: "
|
|
527
|
-
eventBus: options
|
|
518
|
+
progressEvents: ["detection:started", "detection:progress"],
|
|
519
|
+
completeEvent: "detection:complete",
|
|
520
|
+
errorEvent: "detection:failed",
|
|
521
|
+
eventBus: options.eventBus,
|
|
528
522
|
eventPrefix: "detection"
|
|
529
523
|
},
|
|
530
524
|
this.logger
|
|
@@ -571,24 +565,23 @@ var SSEClient = class {
|
|
|
571
565
|
url,
|
|
572
566
|
{
|
|
573
567
|
method: "GET",
|
|
574
|
-
headers: this.getHeaders(options
|
|
568
|
+
headers: this.getHeaders(options.auth)
|
|
575
569
|
},
|
|
576
570
|
{
|
|
577
571
|
progressEvents: ["*"],
|
|
578
|
-
// Accept all event types
|
|
572
|
+
// Accept all event types (long-lived stream)
|
|
579
573
|
completeEvent: null,
|
|
580
|
-
//
|
|
581
|
-
errorEvent:
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
// Use custom event handling
|
|
574
|
+
// Never completes (long-lived)
|
|
575
|
+
errorEvent: null,
|
|
576
|
+
// No error event (errors throw)
|
|
577
|
+
eventBus: options.eventBus
|
|
585
578
|
},
|
|
586
579
|
this.logger
|
|
587
580
|
);
|
|
588
|
-
if (options
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
581
|
+
if (options.onConnected) {
|
|
582
|
+
const sub = options.eventBus.get("stream-connected").subscribe(() => {
|
|
583
|
+
options.onConnected();
|
|
584
|
+
sub.unsubscribe();
|
|
592
585
|
});
|
|
593
586
|
}
|
|
594
587
|
return stream;
|
|
@@ -1723,7 +1716,6 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
|
1723
1716
|
const exactPreview = exact.length > 50 ? exact.substring(0, 50) + "..." : exact;
|
|
1724
1717
|
const textAtOffset = content.substring(aiStart, aiEnd);
|
|
1725
1718
|
if (textAtOffset === exact) {
|
|
1726
|
-
console.log(`[validateAndCorrectOffsets] \u2713 Offsets correct for: "${exactPreview}"`);
|
|
1727
1719
|
const context2 = extractContext(content, aiStart, aiEnd);
|
|
1728
1720
|
return {
|
|
1729
1721
|
start: aiStart,
|