@semiont/api-client 0.2.34-build.90 → 0.2.34-build.92
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 +35 -56
- package/dist/index.js +80 -94
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _semiont_core from '@semiont/core';
|
|
2
|
-
import { BaseUrl, ResourceUri, EntityType, AccessToken, AnnotationUri, components, Email, paths, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, ResourceAnnotationUri, Motivation, UserDID, JobId } from '@semiont/core';
|
|
2
|
+
import { BaseUrl, Logger, ResourceUri, EntityType, AccessToken, AnnotationUri, components, Email, paths, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, ResourceAnnotationUri, Motivation, UserDID, JobId } from '@semiont/core';
|
|
3
|
+
export { Logger } from '@semiont/core';
|
|
3
4
|
export { BoundingBox, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, MatchQuality, Point, Selector, SvgSelector, TextPosition, TextPositionSelector, TextQuoteSelector, ValidatedAnnotation, ValidationFailure, ValidationResult, ValidationSuccess, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition } from './utils/index.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -12,7 +13,7 @@ export { BoundingBox, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, Mat
|
|
|
12
13
|
/**
|
|
13
14
|
* Progress event for reference/linking detection stream
|
|
14
15
|
*
|
|
15
|
-
* Sent by POST /resources/:id/
|
|
16
|
+
* Sent by POST /resources/:id/annotate-references-stream
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* ```typescript
|
|
@@ -134,37 +135,15 @@ interface SSEStream {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* This interface is intentionally framework-agnostic to work with any logger
|
|
140
|
-
* (winston, pino, bunyan, or simple console).
|
|
141
|
-
*
|
|
142
|
-
* Example usage:
|
|
143
|
-
* ```typescript
|
|
144
|
-
* import winston from 'winston';
|
|
145
|
-
*
|
|
146
|
-
* const logger = winston.createLogger({
|
|
147
|
-
* level: 'debug',
|
|
148
|
-
* transports: [new winston.transports.Console()]
|
|
149
|
-
* });
|
|
150
|
-
*
|
|
151
|
-
* const client = new SemiontApiClient({
|
|
152
|
-
* baseUrl: 'http://localhost:4000',
|
|
153
|
-
* logger
|
|
154
|
-
* });
|
|
155
|
-
* ```
|
|
138
|
+
* SSE meta event for stream connection lifecycle
|
|
139
|
+
* Internal to SSE infrastructure, not part of core event protocol
|
|
156
140
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
info(message: string, meta?: any): void;
|
|
160
|
-
warn(message: string, meta?: any): void;
|
|
161
|
-
error(message: string, meta?: any): void;
|
|
162
|
-
}
|
|
163
|
-
|
|
141
|
+
declare const SSE_STREAM_CONNECTED: "stream-connected";
|
|
142
|
+
type SSEStreamConnected = typeof SSE_STREAM_CONNECTED;
|
|
164
143
|
/**
|
|
165
|
-
* Request body for reference
|
|
144
|
+
* Request body for reference annotation stream
|
|
166
145
|
*/
|
|
167
|
-
interface
|
|
146
|
+
interface AnnotateReferencesStreamRequest {
|
|
168
147
|
entityTypes: EntityType[];
|
|
169
148
|
includeDescriptiveReferences?: boolean;
|
|
170
149
|
}
|
|
@@ -174,35 +153,35 @@ interface DetectReferencesStreamRequest {
|
|
|
174
153
|
*/
|
|
175
154
|
type GenerateResourceStreamRequest = components['schemas']['GenerateResourceStreamRequest'];
|
|
176
155
|
/**
|
|
177
|
-
* Request body for highlight
|
|
156
|
+
* Request body for highlight annotation stream
|
|
178
157
|
*/
|
|
179
|
-
interface
|
|
158
|
+
interface AnnotateHighlightsStreamRequest {
|
|
180
159
|
instructions?: string;
|
|
181
160
|
/** Desired number of highlights per 2000 words (1-15) */
|
|
182
161
|
density?: number;
|
|
183
162
|
}
|
|
184
163
|
/**
|
|
185
|
-
* Request body for assessment
|
|
164
|
+
* Request body for assessment annotation stream
|
|
186
165
|
*/
|
|
187
|
-
interface
|
|
166
|
+
interface AnnotateAssessmentsStreamRequest {
|
|
188
167
|
instructions?: string;
|
|
189
168
|
tone?: 'analytical' | 'critical' | 'balanced' | 'constructive';
|
|
190
169
|
/** Desired number of assessments per 2000 words (1-10) */
|
|
191
170
|
density?: number;
|
|
192
171
|
}
|
|
193
172
|
/**
|
|
194
|
-
* Request body for comment
|
|
173
|
+
* Request body for comment annotation stream
|
|
195
174
|
*/
|
|
196
|
-
interface
|
|
175
|
+
interface AnnotateCommentsStreamRequest {
|
|
197
176
|
instructions?: string;
|
|
198
177
|
tone?: 'scholarly' | 'explanatory' | 'conversational' | 'technical';
|
|
199
178
|
/** Desired number of comments per 2000 words (2-12) */
|
|
200
179
|
density?: number;
|
|
201
180
|
}
|
|
202
181
|
/**
|
|
203
|
-
* Request body for tag
|
|
182
|
+
* Request body for tag annotation stream
|
|
204
183
|
*/
|
|
205
|
-
interface
|
|
184
|
+
interface AnnotateTagsStreamRequest {
|
|
206
185
|
schemaId: string;
|
|
207
186
|
categories: string[];
|
|
208
187
|
}
|
|
@@ -235,7 +214,7 @@ interface SSERequestOptions {
|
|
|
235
214
|
* baseUrl: 'http://localhost:4000'
|
|
236
215
|
* });
|
|
237
216
|
*
|
|
238
|
-
* const stream = sseClient.
|
|
217
|
+
* const stream = sseClient.annotateReferences(
|
|
239
218
|
* 'http://localhost:4000/resources/doc-123',
|
|
240
219
|
* { entityTypes: ['Person', 'Organization'] },
|
|
241
220
|
* { auth: 'your-token' }
|
|
@@ -274,7 +253,7 @@ declare class SSEClient {
|
|
|
274
253
|
*
|
|
275
254
|
* @example
|
|
276
255
|
* ```typescript
|
|
277
|
-
* const stream = sseClient.
|
|
256
|
+
* const stream = sseClient.annotateReferences(
|
|
278
257
|
* 'http://localhost:4000/resources/doc-123',
|
|
279
258
|
* { entityTypes: ['Person', 'Organization'] },
|
|
280
259
|
* { auth: 'your-token' }
|
|
@@ -297,7 +276,7 @@ declare class SSEClient {
|
|
|
297
276
|
* stream.close();
|
|
298
277
|
* ```
|
|
299
278
|
*/
|
|
300
|
-
|
|
279
|
+
annotateReferences(resourceId: ResourceUri, request: AnnotateReferencesStreamRequest, options: SSERequestOptions): SSEStream;
|
|
301
280
|
/**
|
|
302
281
|
* Generate resource from annotation (streaming)
|
|
303
282
|
*
|
|
@@ -335,11 +314,11 @@ declare class SSEClient {
|
|
|
335
314
|
* stream.close();
|
|
336
315
|
* ```
|
|
337
316
|
*/
|
|
338
|
-
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options
|
|
317
|
+
generateResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: GenerateResourceStreamRequest, options: SSERequestOptions): SSEStream;
|
|
339
318
|
/**
|
|
340
319
|
* Detect highlights in a resource (streaming)
|
|
341
320
|
*
|
|
342
|
-
* Streams highlight
|
|
321
|
+
* Streams highlight annotation progress via Server-Sent Events.
|
|
343
322
|
*
|
|
344
323
|
* @param resourceId - Resource URI or ID
|
|
345
324
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -348,7 +327,7 @@ declare class SSEClient {
|
|
|
348
327
|
*
|
|
349
328
|
* @example
|
|
350
329
|
* ```typescript
|
|
351
|
-
* const stream = sseClient.
|
|
330
|
+
* const stream = sseClient.annotateHighlights(
|
|
352
331
|
* 'http://localhost:4000/resources/doc-123',
|
|
353
332
|
* { instructions: 'Focus on key technical points' },
|
|
354
333
|
* { auth: 'your-token' }
|
|
@@ -371,11 +350,11 @@ declare class SSEClient {
|
|
|
371
350
|
* stream.close();
|
|
372
351
|
* ```
|
|
373
352
|
*/
|
|
374
|
-
|
|
353
|
+
annotateHighlights(resourceId: ResourceUri, request: AnnotateHighlightsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
375
354
|
/**
|
|
376
355
|
* Detect assessments in a resource (streaming)
|
|
377
356
|
*
|
|
378
|
-
* Streams assessment
|
|
357
|
+
* Streams assessment annotation progress via Server-Sent Events.
|
|
379
358
|
*
|
|
380
359
|
* @param resourceId - Resource URI or ID
|
|
381
360
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -384,7 +363,7 @@ declare class SSEClient {
|
|
|
384
363
|
*
|
|
385
364
|
* @example
|
|
386
365
|
* ```typescript
|
|
387
|
-
* const stream = sseClient.
|
|
366
|
+
* const stream = sseClient.annotateAssessments(
|
|
388
367
|
* 'http://localhost:4000/resources/doc-123',
|
|
389
368
|
* { instructions: 'Evaluate claims for accuracy' },
|
|
390
369
|
* { auth: 'your-token' }
|
|
@@ -407,11 +386,11 @@ declare class SSEClient {
|
|
|
407
386
|
* stream.close();
|
|
408
387
|
* ```
|
|
409
388
|
*/
|
|
410
|
-
|
|
389
|
+
annotateAssessments(resourceId: ResourceUri, request: AnnotateAssessmentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
411
390
|
/**
|
|
412
391
|
* Detect comments in a resource (streaming)
|
|
413
392
|
*
|
|
414
|
-
* Streams comment
|
|
393
|
+
* Streams comment annotation progress via Server-Sent Events.
|
|
415
394
|
* Uses AI to identify passages that would benefit from explanatory comments
|
|
416
395
|
* and creates comment annotations with contextual information.
|
|
417
396
|
*
|
|
@@ -422,7 +401,7 @@ declare class SSEClient {
|
|
|
422
401
|
*
|
|
423
402
|
* @example
|
|
424
403
|
* ```typescript
|
|
425
|
-
* const stream = sseClient.
|
|
404
|
+
* const stream = sseClient.annotateComments(
|
|
426
405
|
* 'http://localhost:4000/resources/doc-123',
|
|
427
406
|
* {
|
|
428
407
|
* instructions: 'Focus on technical terminology',
|
|
@@ -447,11 +426,11 @@ declare class SSEClient {
|
|
|
447
426
|
* stream.close();
|
|
448
427
|
* ```
|
|
449
428
|
*/
|
|
450
|
-
|
|
429
|
+
annotateComments(resourceId: ResourceUri, request: AnnotateCommentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
|
|
451
430
|
/**
|
|
452
431
|
* Detect tags in a resource (streaming)
|
|
453
432
|
*
|
|
454
|
-
* Streams tag
|
|
433
|
+
* Streams tag annotation progress via Server-Sent Events.
|
|
455
434
|
* Uses AI to identify passages serving specific structural roles
|
|
456
435
|
* (e.g., IRAC, IMRAD, Toulmin) and creates tag annotations with dual-body structure.
|
|
457
436
|
*
|
|
@@ -462,7 +441,7 @@ declare class SSEClient {
|
|
|
462
441
|
*
|
|
463
442
|
* @example
|
|
464
443
|
* ```typescript
|
|
465
|
-
* const stream = sseClient.
|
|
444
|
+
* const stream = sseClient.annotateTags(
|
|
466
445
|
* 'http://localhost:4000/resources/doc-123',
|
|
467
446
|
* {
|
|
468
447
|
* schemaId: 'legal-irac',
|
|
@@ -488,7 +467,7 @@ declare class SSEClient {
|
|
|
488
467
|
* stream.close();
|
|
489
468
|
* ```
|
|
490
469
|
*/
|
|
491
|
-
|
|
470
|
+
annotateTags(resourceId: ResourceUri, request: AnnotateTagsStreamRequest, options: SSERequestOptions): SSEStream;
|
|
492
471
|
/**
|
|
493
472
|
* Subscribe to resource events (long-lived stream)
|
|
494
473
|
*
|
|
@@ -523,7 +502,7 @@ declare class SSEClient {
|
|
|
523
502
|
* stream.close();
|
|
524
503
|
* ```
|
|
525
504
|
*/
|
|
526
|
-
resourceEvents(resourceId: ResourceUri, options
|
|
505
|
+
resourceEvents(resourceId: ResourceUri, options: SSERequestOptions & {
|
|
527
506
|
onConnected?: () => void;
|
|
528
507
|
}): SSEStream;
|
|
529
508
|
}
|
|
@@ -813,4 +792,4 @@ declare function isPdfMimeType(mimeType: string): boolean;
|
|
|
813
792
|
type MimeCategory = 'text' | 'image' | 'unsupported';
|
|
814
793
|
declare function getMimeCategory(mimeType: string): MimeCategory;
|
|
815
794
|
|
|
816
|
-
export { APIError, type
|
|
795
|
+
export { APIError, type AnnotateReferencesStreamRequest, type GenerateResourceStreamRequest, type GenerationProgress, type MimeCategory, type ReferenceDetectionProgress, type RequestOptions, SSEClient, type SSEClientConfig, type SSEStream, type SSEStreamConnected, SSE_STREAM_CONNECTED, SemiontApiClient, type SemiontApiClientConfig, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };
|
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 {
|
|
@@ -61,7 +60,8 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
61
60
|
while (true) {
|
|
62
61
|
const { done, value } = await reader.read();
|
|
63
62
|
if (done || closed) break;
|
|
64
|
-
|
|
63
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
64
|
+
buffer += chunk;
|
|
65
65
|
const lines = buffer.split("\n");
|
|
66
66
|
buffer = lines.pop() || "";
|
|
67
67
|
for (const line of lines) {
|
|
@@ -117,27 +117,18 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
117
117
|
event: eventType || "message",
|
|
118
118
|
hasData: !!data
|
|
119
119
|
});
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
120
|
+
if (typeof parsed === "object" && parsed !== null && "type" in parsed) {
|
|
121
|
+
config.eventBus.get(eventType).next(parsed);
|
|
122
|
+
config.eventBus.get("make-meaning:event").next(parsed);
|
|
123
|
+
return;
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
abortController.abort();
|
|
135
|
-
}
|
|
136
|
-
if (config.errorEvent && eventType === config.errorEvent) {
|
|
137
|
-
config.eventBus.get(`${config.eventPrefix}:failed`).next({ error: new Error(parsed.message || "Stream error") });
|
|
138
|
-
closed = true;
|
|
139
|
-
abortController.abort();
|
|
140
|
-
}
|
|
125
|
+
config.eventBus.get(eventType).next(parsed);
|
|
126
|
+
if (config.completeEvent && eventType === config.completeEvent) {
|
|
127
|
+
closed = true;
|
|
128
|
+
abortController.abort();
|
|
129
|
+
} else if (config.errorEvent && eventType === config.errorEvent) {
|
|
130
|
+
closed = true;
|
|
131
|
+
abortController.abort();
|
|
141
132
|
}
|
|
142
133
|
} catch (error) {
|
|
143
134
|
console.error("[SSE] Failed to parse event data:", error);
|
|
@@ -149,15 +140,12 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
149
140
|
return {
|
|
150
141
|
close() {
|
|
151
142
|
abortController.abort();
|
|
152
|
-
},
|
|
153
|
-
// Internal method for custom event handlers (used by resourceEvents)
|
|
154
|
-
on(event, callback) {
|
|
155
|
-
customHandlers.set(event, callback);
|
|
156
143
|
}
|
|
157
144
|
};
|
|
158
145
|
}
|
|
159
146
|
|
|
160
147
|
// src/sse/index.ts
|
|
148
|
+
var SSE_STREAM_CONNECTED = "stream-connected";
|
|
161
149
|
var SSEClient = class {
|
|
162
150
|
baseUrl;
|
|
163
151
|
logger;
|
|
@@ -200,7 +188,7 @@ var SSEClient = class {
|
|
|
200
188
|
*
|
|
201
189
|
* @example
|
|
202
190
|
* ```typescript
|
|
203
|
-
* const stream = sseClient.
|
|
191
|
+
* const stream = sseClient.annotateReferences(
|
|
204
192
|
* 'http://localhost:4000/resources/doc-123',
|
|
205
193
|
* { entityTypes: ['Person', 'Organization'] },
|
|
206
194
|
* { auth: 'your-token' }
|
|
@@ -223,22 +211,22 @@ var SSEClient = class {
|
|
|
223
211
|
* stream.close();
|
|
224
212
|
* ```
|
|
225
213
|
*/
|
|
226
|
-
|
|
214
|
+
annotateReferences(resourceId, request, options) {
|
|
227
215
|
const id = this.extractId(resourceId);
|
|
228
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
216
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-references-stream`;
|
|
229
217
|
return createSSEStream(
|
|
230
218
|
url,
|
|
231
219
|
{
|
|
232
220
|
method: "POST",
|
|
233
|
-
headers: this.getHeaders(options
|
|
221
|
+
headers: this.getHeaders(options.auth),
|
|
234
222
|
body: JSON.stringify(request)
|
|
235
223
|
},
|
|
236
224
|
{
|
|
237
|
-
progressEvents: ["
|
|
238
|
-
completeEvent: "
|
|
239
|
-
errorEvent: "
|
|
240
|
-
eventBus: options
|
|
241
|
-
eventPrefix:
|
|
225
|
+
progressEvents: ["annotate:progress"],
|
|
226
|
+
completeEvent: "annotate:assist-finished",
|
|
227
|
+
errorEvent: "annotate:assist-failed",
|
|
228
|
+
eventBus: options.eventBus,
|
|
229
|
+
eventPrefix: void 0
|
|
242
230
|
},
|
|
243
231
|
this.logger
|
|
244
232
|
);
|
|
@@ -288,15 +276,15 @@ var SSEClient = class {
|
|
|
288
276
|
url,
|
|
289
277
|
{
|
|
290
278
|
method: "POST",
|
|
291
|
-
headers: this.getHeaders(options
|
|
279
|
+
headers: this.getHeaders(options.auth),
|
|
292
280
|
body: JSON.stringify(request)
|
|
293
281
|
},
|
|
294
282
|
{
|
|
295
|
-
progressEvents: ["
|
|
296
|
-
completeEvent: "
|
|
297
|
-
errorEvent: "
|
|
298
|
-
eventBus: options
|
|
299
|
-
eventPrefix:
|
|
283
|
+
progressEvents: ["generate:progress"],
|
|
284
|
+
completeEvent: "generate:finished",
|
|
285
|
+
errorEvent: "generate:failed",
|
|
286
|
+
eventBus: options.eventBus,
|
|
287
|
+
eventPrefix: void 0
|
|
300
288
|
},
|
|
301
289
|
this.logger
|
|
302
290
|
);
|
|
@@ -304,7 +292,7 @@ var SSEClient = class {
|
|
|
304
292
|
/**
|
|
305
293
|
* Detect highlights in a resource (streaming)
|
|
306
294
|
*
|
|
307
|
-
* Streams highlight
|
|
295
|
+
* Streams highlight annotation progress via Server-Sent Events.
|
|
308
296
|
*
|
|
309
297
|
* @param resourceId - Resource URI or ID
|
|
310
298
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -313,7 +301,7 @@ var SSEClient = class {
|
|
|
313
301
|
*
|
|
314
302
|
* @example
|
|
315
303
|
* ```typescript
|
|
316
|
-
* const stream = sseClient.
|
|
304
|
+
* const stream = sseClient.annotateHighlights(
|
|
317
305
|
* 'http://localhost:4000/resources/doc-123',
|
|
318
306
|
* { instructions: 'Focus on key technical points' },
|
|
319
307
|
* { auth: 'your-token' }
|
|
@@ -336,22 +324,22 @@ var SSEClient = class {
|
|
|
336
324
|
* stream.close();
|
|
337
325
|
* ```
|
|
338
326
|
*/
|
|
339
|
-
|
|
327
|
+
annotateHighlights(resourceId, request = {}, options) {
|
|
340
328
|
const id = this.extractId(resourceId);
|
|
341
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
329
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-highlights-stream`;
|
|
342
330
|
return createSSEStream(
|
|
343
331
|
url,
|
|
344
332
|
{
|
|
345
333
|
method: "POST",
|
|
346
|
-
headers: this.getHeaders(options
|
|
334
|
+
headers: this.getHeaders(options.auth),
|
|
347
335
|
body: JSON.stringify(request)
|
|
348
336
|
},
|
|
349
337
|
{
|
|
350
|
-
progressEvents: ["
|
|
351
|
-
completeEvent: "
|
|
352
|
-
errorEvent: "
|
|
353
|
-
eventBus: options
|
|
354
|
-
eventPrefix:
|
|
338
|
+
progressEvents: ["annotate:progress"],
|
|
339
|
+
completeEvent: "annotate:assist-finished",
|
|
340
|
+
errorEvent: "annotate:assist-failed",
|
|
341
|
+
eventBus: options.eventBus,
|
|
342
|
+
eventPrefix: void 0
|
|
355
343
|
},
|
|
356
344
|
this.logger
|
|
357
345
|
);
|
|
@@ -359,7 +347,7 @@ var SSEClient = class {
|
|
|
359
347
|
/**
|
|
360
348
|
* Detect assessments in a resource (streaming)
|
|
361
349
|
*
|
|
362
|
-
* Streams assessment
|
|
350
|
+
* Streams assessment annotation progress via Server-Sent Events.
|
|
363
351
|
*
|
|
364
352
|
* @param resourceId - Resource URI or ID
|
|
365
353
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -368,7 +356,7 @@ var SSEClient = class {
|
|
|
368
356
|
*
|
|
369
357
|
* @example
|
|
370
358
|
* ```typescript
|
|
371
|
-
* const stream = sseClient.
|
|
359
|
+
* const stream = sseClient.annotateAssessments(
|
|
372
360
|
* 'http://localhost:4000/resources/doc-123',
|
|
373
361
|
* { instructions: 'Evaluate claims for accuracy' },
|
|
374
362
|
* { auth: 'your-token' }
|
|
@@ -391,22 +379,22 @@ var SSEClient = class {
|
|
|
391
379
|
* stream.close();
|
|
392
380
|
* ```
|
|
393
381
|
*/
|
|
394
|
-
|
|
382
|
+
annotateAssessments(resourceId, request = {}, options) {
|
|
395
383
|
const id = this.extractId(resourceId);
|
|
396
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
384
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-assessments-stream`;
|
|
397
385
|
return createSSEStream(
|
|
398
386
|
url,
|
|
399
387
|
{
|
|
400
388
|
method: "POST",
|
|
401
|
-
headers: this.getHeaders(options
|
|
389
|
+
headers: this.getHeaders(options.auth),
|
|
402
390
|
body: JSON.stringify(request)
|
|
403
391
|
},
|
|
404
392
|
{
|
|
405
|
-
progressEvents: ["
|
|
406
|
-
completeEvent: "
|
|
407
|
-
errorEvent: "
|
|
408
|
-
eventBus: options
|
|
409
|
-
eventPrefix:
|
|
393
|
+
progressEvents: ["annotate:progress"],
|
|
394
|
+
completeEvent: "annotate:assist-finished",
|
|
395
|
+
errorEvent: "annotate:assist-failed",
|
|
396
|
+
eventBus: options.eventBus,
|
|
397
|
+
eventPrefix: void 0
|
|
410
398
|
},
|
|
411
399
|
this.logger
|
|
412
400
|
);
|
|
@@ -414,7 +402,7 @@ var SSEClient = class {
|
|
|
414
402
|
/**
|
|
415
403
|
* Detect comments in a resource (streaming)
|
|
416
404
|
*
|
|
417
|
-
* Streams comment
|
|
405
|
+
* Streams comment annotation progress via Server-Sent Events.
|
|
418
406
|
* Uses AI to identify passages that would benefit from explanatory comments
|
|
419
407
|
* and creates comment annotations with contextual information.
|
|
420
408
|
*
|
|
@@ -425,7 +413,7 @@ var SSEClient = class {
|
|
|
425
413
|
*
|
|
426
414
|
* @example
|
|
427
415
|
* ```typescript
|
|
428
|
-
* const stream = sseClient.
|
|
416
|
+
* const stream = sseClient.annotateComments(
|
|
429
417
|
* 'http://localhost:4000/resources/doc-123',
|
|
430
418
|
* {
|
|
431
419
|
* instructions: 'Focus on technical terminology',
|
|
@@ -450,22 +438,22 @@ var SSEClient = class {
|
|
|
450
438
|
* stream.close();
|
|
451
439
|
* ```
|
|
452
440
|
*/
|
|
453
|
-
|
|
441
|
+
annotateComments(resourceId, request = {}, options) {
|
|
454
442
|
const id = this.extractId(resourceId);
|
|
455
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
443
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-comments-stream`;
|
|
456
444
|
return createSSEStream(
|
|
457
445
|
url,
|
|
458
446
|
{
|
|
459
447
|
method: "POST",
|
|
460
|
-
headers: this.getHeaders(options
|
|
448
|
+
headers: this.getHeaders(options.auth),
|
|
461
449
|
body: JSON.stringify(request)
|
|
462
450
|
},
|
|
463
451
|
{
|
|
464
|
-
progressEvents: ["
|
|
465
|
-
completeEvent: "
|
|
466
|
-
errorEvent: "
|
|
467
|
-
eventBus: options
|
|
468
|
-
eventPrefix:
|
|
452
|
+
progressEvents: ["annotate:progress"],
|
|
453
|
+
completeEvent: "annotate:assist-finished",
|
|
454
|
+
errorEvent: "annotate:assist-failed",
|
|
455
|
+
eventBus: options.eventBus,
|
|
456
|
+
eventPrefix: void 0
|
|
469
457
|
},
|
|
470
458
|
this.logger
|
|
471
459
|
);
|
|
@@ -473,7 +461,7 @@ var SSEClient = class {
|
|
|
473
461
|
/**
|
|
474
462
|
* Detect tags in a resource (streaming)
|
|
475
463
|
*
|
|
476
|
-
* Streams tag
|
|
464
|
+
* Streams tag annotation progress via Server-Sent Events.
|
|
477
465
|
* Uses AI to identify passages serving specific structural roles
|
|
478
466
|
* (e.g., IRAC, IMRAD, Toulmin) and creates tag annotations with dual-body structure.
|
|
479
467
|
*
|
|
@@ -484,7 +472,7 @@ var SSEClient = class {
|
|
|
484
472
|
*
|
|
485
473
|
* @example
|
|
486
474
|
* ```typescript
|
|
487
|
-
* const stream = sseClient.
|
|
475
|
+
* const stream = sseClient.annotateTags(
|
|
488
476
|
* 'http://localhost:4000/resources/doc-123',
|
|
489
477
|
* {
|
|
490
478
|
* schemaId: 'legal-irac',
|
|
@@ -510,22 +498,22 @@ var SSEClient = class {
|
|
|
510
498
|
* stream.close();
|
|
511
499
|
* ```
|
|
512
500
|
*/
|
|
513
|
-
|
|
501
|
+
annotateTags(resourceId, request, options) {
|
|
514
502
|
const id = this.extractId(resourceId);
|
|
515
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
503
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-tags-stream`;
|
|
516
504
|
return createSSEStream(
|
|
517
505
|
url,
|
|
518
506
|
{
|
|
519
507
|
method: "POST",
|
|
520
|
-
headers: this.getHeaders(options
|
|
508
|
+
headers: this.getHeaders(options.auth),
|
|
521
509
|
body: JSON.stringify(request)
|
|
522
510
|
},
|
|
523
511
|
{
|
|
524
|
-
progressEvents: ["
|
|
525
|
-
completeEvent: "
|
|
526
|
-
errorEvent: "
|
|
527
|
-
eventBus: options
|
|
528
|
-
eventPrefix:
|
|
512
|
+
progressEvents: ["annotate:progress"],
|
|
513
|
+
completeEvent: "annotate:assist-finished",
|
|
514
|
+
errorEvent: "annotate:assist-failed",
|
|
515
|
+
eventBus: options.eventBus,
|
|
516
|
+
eventPrefix: void 0
|
|
529
517
|
},
|
|
530
518
|
this.logger
|
|
531
519
|
);
|
|
@@ -571,24 +559,23 @@ var SSEClient = class {
|
|
|
571
559
|
url,
|
|
572
560
|
{
|
|
573
561
|
method: "GET",
|
|
574
|
-
headers: this.getHeaders(options
|
|
562
|
+
headers: this.getHeaders(options.auth)
|
|
575
563
|
},
|
|
576
564
|
{
|
|
577
565
|
progressEvents: ["*"],
|
|
578
|
-
// Accept all event types
|
|
566
|
+
// Accept all event types (long-lived stream)
|
|
579
567
|
completeEvent: null,
|
|
580
|
-
//
|
|
581
|
-
errorEvent:
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
// Use custom event handling
|
|
568
|
+
// Never completes (long-lived)
|
|
569
|
+
errorEvent: null,
|
|
570
|
+
// No error event (errors throw)
|
|
571
|
+
eventBus: options.eventBus
|
|
585
572
|
},
|
|
586
573
|
this.logger
|
|
587
574
|
);
|
|
588
|
-
if (options
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
575
|
+
if (options.onConnected) {
|
|
576
|
+
const sub = options.eventBus.get(SSE_STREAM_CONNECTED).subscribe(() => {
|
|
577
|
+
options.onConnected();
|
|
578
|
+
sub.unsubscribe();
|
|
592
579
|
});
|
|
593
580
|
}
|
|
594
581
|
return stream;
|
|
@@ -1723,7 +1710,6 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
|
1723
1710
|
const exactPreview = exact.length > 50 ? exact.substring(0, 50) + "..." : exact;
|
|
1724
1711
|
const textAtOffset = content.substring(aiStart, aiEnd);
|
|
1725
1712
|
if (textAtOffset === exact) {
|
|
1726
|
-
console.log(`[validateAndCorrectOffsets] \u2713 Offsets correct for: "${exactPreview}"`);
|
|
1727
1713
|
const context2 = extractContext(content, aiStart, aiEnd);
|
|
1728
1714
|
return {
|
|
1729
1715
|
start: aiStart,
|
|
@@ -1877,6 +1863,6 @@ function getMimeCategory(mimeType) {
|
|
|
1877
1863
|
return "unsupported";
|
|
1878
1864
|
}
|
|
1879
1865
|
|
|
1880
|
-
export { APIError, JWTTokenSchema, LOCALES, SSEClient, SemiontApiClient, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getExtensionForMimeType, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getMimeCategory, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isImageMimeType, isPdfMimeType, isReference, isResolvedReference, isStubReference, isTag, isTextMimeType, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
|
|
1866
|
+
export { APIError, JWTTokenSchema, LOCALES, SSEClient, SSE_STREAM_CONNECTED, SemiontApiClient, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getExtensionForMimeType, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getMimeCategory, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isImageMimeType, isPdfMimeType, isReference, isResolvedReference, isStubReference, isTag, isTextMimeType, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
|
|
1881
1867
|
//# sourceMappingURL=index.js.map
|
|
1882
1868
|
//# sourceMappingURL=index.js.map
|