@semiont/api-client 0.2.34-build.91 → 0.2.34-build.93
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 +33 -54
- package/dist/index.js +56 -109
- package/dist/index.js.map +1 -1
- package/dist/utils/index.js +0 -47
- 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
|
*
|
|
@@ -339,7 +318,7 @@ declare class SSEClient {
|
|
|
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
|
*
|
|
@@ -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
|
@@ -60,7 +60,8 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
60
60
|
while (true) {
|
|
61
61
|
const { done, value } = await reader.read();
|
|
62
62
|
if (done || closed) break;
|
|
63
|
-
|
|
63
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
64
|
+
buffer += chunk;
|
|
64
65
|
const lines = buffer.split("\n");
|
|
65
66
|
buffer = lines.pop() || "";
|
|
66
67
|
for (const line of lines) {
|
|
@@ -119,23 +120,15 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
119
120
|
if (typeof parsed === "object" && parsed !== null && "type" in parsed) {
|
|
120
121
|
config.eventBus.get(eventType).next(parsed);
|
|
121
122
|
config.eventBus.get("make-meaning:event").next(parsed);
|
|
122
|
-
|
|
123
|
-
config.eventBus.get(eventType).next(parsed);
|
|
123
|
+
return;
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
abortController.abort();
|
|
133
|
-
}
|
|
134
|
-
if (config.errorEvent && eventType === config.errorEvent) {
|
|
135
|
-
config.eventBus.get(`${config.eventPrefix}:failed`).next({ error: new Error(parsed.message || "Stream error") });
|
|
136
|
-
closed = true;
|
|
137
|
-
abortController.abort();
|
|
138
|
-
}
|
|
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();
|
|
139
132
|
}
|
|
140
133
|
} catch (error) {
|
|
141
134
|
console.error("[SSE] Failed to parse event data:", error);
|
|
@@ -152,6 +145,7 @@ function createSSEStream(url, fetchOptions, config, logger) {
|
|
|
152
145
|
}
|
|
153
146
|
|
|
154
147
|
// src/sse/index.ts
|
|
148
|
+
var SSE_STREAM_CONNECTED = "stream-connected";
|
|
155
149
|
var SSEClient = class {
|
|
156
150
|
baseUrl;
|
|
157
151
|
logger;
|
|
@@ -194,7 +188,7 @@ var SSEClient = class {
|
|
|
194
188
|
*
|
|
195
189
|
* @example
|
|
196
190
|
* ```typescript
|
|
197
|
-
* const stream = sseClient.
|
|
191
|
+
* const stream = sseClient.annotateReferences(
|
|
198
192
|
* 'http://localhost:4000/resources/doc-123',
|
|
199
193
|
* { entityTypes: ['Person', 'Organization'] },
|
|
200
194
|
* { auth: 'your-token' }
|
|
@@ -217,9 +211,9 @@ var SSEClient = class {
|
|
|
217
211
|
* stream.close();
|
|
218
212
|
* ```
|
|
219
213
|
*/
|
|
220
|
-
|
|
214
|
+
annotateReferences(resourceId, request, options) {
|
|
221
215
|
const id = this.extractId(resourceId);
|
|
222
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
216
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-references-stream`;
|
|
223
217
|
return createSSEStream(
|
|
224
218
|
url,
|
|
225
219
|
{
|
|
@@ -228,11 +222,11 @@ var SSEClient = class {
|
|
|
228
222
|
body: JSON.stringify(request)
|
|
229
223
|
},
|
|
230
224
|
{
|
|
231
|
-
progressEvents: ["
|
|
232
|
-
completeEvent: "
|
|
233
|
-
errorEvent: "
|
|
225
|
+
progressEvents: ["annotate:progress"],
|
|
226
|
+
completeEvent: "annotate:assist-finished",
|
|
227
|
+
errorEvent: "annotate:assist-failed",
|
|
234
228
|
eventBus: options.eventBus,
|
|
235
|
-
eventPrefix:
|
|
229
|
+
eventPrefix: void 0
|
|
236
230
|
},
|
|
237
231
|
this.logger
|
|
238
232
|
);
|
|
@@ -286,11 +280,11 @@ var SSEClient = class {
|
|
|
286
280
|
body: JSON.stringify(request)
|
|
287
281
|
},
|
|
288
282
|
{
|
|
289
|
-
progressEvents: ["
|
|
290
|
-
completeEvent: "
|
|
291
|
-
errorEvent: "
|
|
283
|
+
progressEvents: ["generate:progress"],
|
|
284
|
+
completeEvent: "generate:finished",
|
|
285
|
+
errorEvent: "generate:failed",
|
|
292
286
|
eventBus: options.eventBus,
|
|
293
|
-
eventPrefix:
|
|
287
|
+
eventPrefix: void 0
|
|
294
288
|
},
|
|
295
289
|
this.logger
|
|
296
290
|
);
|
|
@@ -298,7 +292,7 @@ var SSEClient = class {
|
|
|
298
292
|
/**
|
|
299
293
|
* Detect highlights in a resource (streaming)
|
|
300
294
|
*
|
|
301
|
-
* Streams highlight
|
|
295
|
+
* Streams highlight annotation progress via Server-Sent Events.
|
|
302
296
|
*
|
|
303
297
|
* @param resourceId - Resource URI or ID
|
|
304
298
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -307,7 +301,7 @@ var SSEClient = class {
|
|
|
307
301
|
*
|
|
308
302
|
* @example
|
|
309
303
|
* ```typescript
|
|
310
|
-
* const stream = sseClient.
|
|
304
|
+
* const stream = sseClient.annotateHighlights(
|
|
311
305
|
* 'http://localhost:4000/resources/doc-123',
|
|
312
306
|
* { instructions: 'Focus on key technical points' },
|
|
313
307
|
* { auth: 'your-token' }
|
|
@@ -330,9 +324,9 @@ var SSEClient = class {
|
|
|
330
324
|
* stream.close();
|
|
331
325
|
* ```
|
|
332
326
|
*/
|
|
333
|
-
|
|
327
|
+
annotateHighlights(resourceId, request = {}, options) {
|
|
334
328
|
const id = this.extractId(resourceId);
|
|
335
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
329
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-highlights-stream`;
|
|
336
330
|
return createSSEStream(
|
|
337
331
|
url,
|
|
338
332
|
{
|
|
@@ -341,11 +335,11 @@ var SSEClient = class {
|
|
|
341
335
|
body: JSON.stringify(request)
|
|
342
336
|
},
|
|
343
337
|
{
|
|
344
|
-
progressEvents: ["
|
|
345
|
-
completeEvent: "
|
|
346
|
-
errorEvent: "
|
|
338
|
+
progressEvents: ["annotate:progress"],
|
|
339
|
+
completeEvent: "annotate:assist-finished",
|
|
340
|
+
errorEvent: "annotate:assist-failed",
|
|
347
341
|
eventBus: options.eventBus,
|
|
348
|
-
eventPrefix:
|
|
342
|
+
eventPrefix: void 0
|
|
349
343
|
},
|
|
350
344
|
this.logger
|
|
351
345
|
);
|
|
@@ -353,7 +347,7 @@ var SSEClient = class {
|
|
|
353
347
|
/**
|
|
354
348
|
* Detect assessments in a resource (streaming)
|
|
355
349
|
*
|
|
356
|
-
* Streams assessment
|
|
350
|
+
* Streams assessment annotation progress via Server-Sent Events.
|
|
357
351
|
*
|
|
358
352
|
* @param resourceId - Resource URI or ID
|
|
359
353
|
* @param request - Detection configuration (optional instructions)
|
|
@@ -362,7 +356,7 @@ var SSEClient = class {
|
|
|
362
356
|
*
|
|
363
357
|
* @example
|
|
364
358
|
* ```typescript
|
|
365
|
-
* const stream = sseClient.
|
|
359
|
+
* const stream = sseClient.annotateAssessments(
|
|
366
360
|
* 'http://localhost:4000/resources/doc-123',
|
|
367
361
|
* { instructions: 'Evaluate claims for accuracy' },
|
|
368
362
|
* { auth: 'your-token' }
|
|
@@ -385,9 +379,9 @@ var SSEClient = class {
|
|
|
385
379
|
* stream.close();
|
|
386
380
|
* ```
|
|
387
381
|
*/
|
|
388
|
-
|
|
382
|
+
annotateAssessments(resourceId, request = {}, options) {
|
|
389
383
|
const id = this.extractId(resourceId);
|
|
390
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
384
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-assessments-stream`;
|
|
391
385
|
return createSSEStream(
|
|
392
386
|
url,
|
|
393
387
|
{
|
|
@@ -396,11 +390,11 @@ var SSEClient = class {
|
|
|
396
390
|
body: JSON.stringify(request)
|
|
397
391
|
},
|
|
398
392
|
{
|
|
399
|
-
progressEvents: ["
|
|
400
|
-
completeEvent: "
|
|
401
|
-
errorEvent: "
|
|
393
|
+
progressEvents: ["annotate:progress"],
|
|
394
|
+
completeEvent: "annotate:assist-finished",
|
|
395
|
+
errorEvent: "annotate:assist-failed",
|
|
402
396
|
eventBus: options.eventBus,
|
|
403
|
-
eventPrefix:
|
|
397
|
+
eventPrefix: void 0
|
|
404
398
|
},
|
|
405
399
|
this.logger
|
|
406
400
|
);
|
|
@@ -408,7 +402,7 @@ var SSEClient = class {
|
|
|
408
402
|
/**
|
|
409
403
|
* Detect comments in a resource (streaming)
|
|
410
404
|
*
|
|
411
|
-
* Streams comment
|
|
405
|
+
* Streams comment annotation progress via Server-Sent Events.
|
|
412
406
|
* Uses AI to identify passages that would benefit from explanatory comments
|
|
413
407
|
* and creates comment annotations with contextual information.
|
|
414
408
|
*
|
|
@@ -419,7 +413,7 @@ var SSEClient = class {
|
|
|
419
413
|
*
|
|
420
414
|
* @example
|
|
421
415
|
* ```typescript
|
|
422
|
-
* const stream = sseClient.
|
|
416
|
+
* const stream = sseClient.annotateComments(
|
|
423
417
|
* 'http://localhost:4000/resources/doc-123',
|
|
424
418
|
* {
|
|
425
419
|
* instructions: 'Focus on technical terminology',
|
|
@@ -444,9 +438,9 @@ var SSEClient = class {
|
|
|
444
438
|
* stream.close();
|
|
445
439
|
* ```
|
|
446
440
|
*/
|
|
447
|
-
|
|
441
|
+
annotateComments(resourceId, request = {}, options) {
|
|
448
442
|
const id = this.extractId(resourceId);
|
|
449
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
443
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-comments-stream`;
|
|
450
444
|
return createSSEStream(
|
|
451
445
|
url,
|
|
452
446
|
{
|
|
@@ -455,11 +449,11 @@ var SSEClient = class {
|
|
|
455
449
|
body: JSON.stringify(request)
|
|
456
450
|
},
|
|
457
451
|
{
|
|
458
|
-
progressEvents: ["
|
|
459
|
-
completeEvent: "
|
|
460
|
-
errorEvent: "
|
|
452
|
+
progressEvents: ["annotate:progress"],
|
|
453
|
+
completeEvent: "annotate:assist-finished",
|
|
454
|
+
errorEvent: "annotate:assist-failed",
|
|
461
455
|
eventBus: options.eventBus,
|
|
462
|
-
eventPrefix:
|
|
456
|
+
eventPrefix: void 0
|
|
463
457
|
},
|
|
464
458
|
this.logger
|
|
465
459
|
);
|
|
@@ -467,7 +461,7 @@ var SSEClient = class {
|
|
|
467
461
|
/**
|
|
468
462
|
* Detect tags in a resource (streaming)
|
|
469
463
|
*
|
|
470
|
-
* Streams tag
|
|
464
|
+
* Streams tag annotation progress via Server-Sent Events.
|
|
471
465
|
* Uses AI to identify passages serving specific structural roles
|
|
472
466
|
* (e.g., IRAC, IMRAD, Toulmin) and creates tag annotations with dual-body structure.
|
|
473
467
|
*
|
|
@@ -478,7 +472,7 @@ var SSEClient = class {
|
|
|
478
472
|
*
|
|
479
473
|
* @example
|
|
480
474
|
* ```typescript
|
|
481
|
-
* const stream = sseClient.
|
|
475
|
+
* const stream = sseClient.annotateTags(
|
|
482
476
|
* 'http://localhost:4000/resources/doc-123',
|
|
483
477
|
* {
|
|
484
478
|
* schemaId: 'legal-irac',
|
|
@@ -504,9 +498,9 @@ var SSEClient = class {
|
|
|
504
498
|
* stream.close();
|
|
505
499
|
* ```
|
|
506
500
|
*/
|
|
507
|
-
|
|
501
|
+
annotateTags(resourceId, request, options) {
|
|
508
502
|
const id = this.extractId(resourceId);
|
|
509
|
-
const url = `${this.baseUrl}/resources/${id}/
|
|
503
|
+
const url = `${this.baseUrl}/resources/${id}/annotate-tags-stream`;
|
|
510
504
|
return createSSEStream(
|
|
511
505
|
url,
|
|
512
506
|
{
|
|
@@ -515,11 +509,11 @@ var SSEClient = class {
|
|
|
515
509
|
body: JSON.stringify(request)
|
|
516
510
|
},
|
|
517
511
|
{
|
|
518
|
-
progressEvents: ["
|
|
519
|
-
completeEvent: "
|
|
520
|
-
errorEvent: "
|
|
512
|
+
progressEvents: ["annotate:progress"],
|
|
513
|
+
completeEvent: "annotate:assist-finished",
|
|
514
|
+
errorEvent: "annotate:assist-failed",
|
|
521
515
|
eventBus: options.eventBus,
|
|
522
|
-
eventPrefix:
|
|
516
|
+
eventPrefix: void 0
|
|
523
517
|
},
|
|
524
518
|
this.logger
|
|
525
519
|
);
|
|
@@ -579,7 +573,7 @@ var SSEClient = class {
|
|
|
579
573
|
this.logger
|
|
580
574
|
);
|
|
581
575
|
if (options.onConnected) {
|
|
582
|
-
const sub = options.eventBus.get(
|
|
576
|
+
const sub = options.eventBus.get(SSE_STREAM_CONNECTED).subscribe(() => {
|
|
583
577
|
options.onConnected();
|
|
584
578
|
sub.unsubscribe();
|
|
585
579
|
});
|
|
@@ -1406,15 +1400,10 @@ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
|
1406
1400
|
index = content.indexOf(exact, index + 1);
|
|
1407
1401
|
}
|
|
1408
1402
|
if (occurrences.length === 0) {
|
|
1409
|
-
console.warn(`[FuzzyAnchor] Exact text not found, trying fuzzy match: "${exact.substring(0, 50)}..."`);
|
|
1410
1403
|
const fuzzyMatch = findBestTextMatch(content, exact, positionHint);
|
|
1411
1404
|
if (fuzzyMatch) {
|
|
1412
|
-
console.warn(
|
|
1413
|
-
`[FuzzyAnchor] Found ${fuzzyMatch.matchQuality} match at position ${fuzzyMatch.start}`
|
|
1414
|
-
);
|
|
1415
1405
|
return { start: fuzzyMatch.start, end: fuzzyMatch.end };
|
|
1416
1406
|
}
|
|
1417
|
-
console.warn(`[FuzzyAnchor] No acceptable match found for: "${exact.substring(0, 50)}..."`);
|
|
1418
1407
|
return null;
|
|
1419
1408
|
}
|
|
1420
1409
|
if (occurrences.length === 1) {
|
|
@@ -1433,23 +1422,16 @@ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
|
1433
1422
|
return { start: pos2, end: pos2 + exact.length };
|
|
1434
1423
|
}
|
|
1435
1424
|
}
|
|
1436
|
-
console.warn(
|
|
1437
|
-
`[FuzzyAnchor] Multiple matches found but none match prefix/suffix exactly. Exact: "${exact.substring(0, 30)}...", Prefix: "${prefix?.substring(0, 20) || "none"}", Suffix: "${suffix?.substring(0, 20) || "none"}"`
|
|
1438
|
-
);
|
|
1439
1425
|
for (const pos2 of occurrences) {
|
|
1440
1426
|
const actualPrefix = content.substring(Math.max(0, pos2 - (prefix?.length || 0)), pos2);
|
|
1441
1427
|
const actualSuffix = content.substring(pos2 + exact.length, pos2 + exact.length + (suffix?.length || 0));
|
|
1442
1428
|
const fuzzyPrefixMatch = !prefix || actualPrefix.includes(prefix.trim());
|
|
1443
1429
|
const fuzzySuffixMatch = !suffix || actualSuffix.includes(suffix.trim());
|
|
1444
1430
|
if (fuzzyPrefixMatch && fuzzySuffixMatch) {
|
|
1445
|
-
console.warn(`[FuzzyAnchor] Using fuzzy context match at position ${pos2}`);
|
|
1446
1431
|
return { start: pos2, end: pos2 + exact.length };
|
|
1447
1432
|
}
|
|
1448
1433
|
}
|
|
1449
1434
|
}
|
|
1450
|
-
console.warn(
|
|
1451
|
-
`[FuzzyAnchor] Multiple matches but no context match. Using first occurrence. Exact: "${exact.substring(0, 30)}..."`
|
|
1452
|
-
);
|
|
1453
1435
|
const pos = occurrences[0];
|
|
1454
1436
|
return { start: pos, end: pos + exact.length };
|
|
1455
1437
|
}
|
|
@@ -1713,7 +1695,6 @@ function extractContext(content, start, end) {
|
|
|
1713
1695
|
return { prefix, suffix };
|
|
1714
1696
|
}
|
|
1715
1697
|
function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
1716
|
-
const exactPreview = exact.length > 50 ? exact.substring(0, 50) + "..." : exact;
|
|
1717
1698
|
const textAtOffset = content.substring(aiStart, aiEnd);
|
|
1718
1699
|
if (textAtOffset === exact) {
|
|
1719
1700
|
const context2 = extractContext(content, aiStart, aiEnd);
|
|
@@ -1727,47 +1708,13 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
|
1727
1708
|
matchQuality: "exact"
|
|
1728
1709
|
};
|
|
1729
1710
|
}
|
|
1730
|
-
const foundPreview = textAtOffset.length > 50 ? textAtOffset.substring(0, 50) + "..." : textAtOffset;
|
|
1731
|
-
console.warn(
|
|
1732
|
-
`[validateAndCorrectOffsets] \u26A0 AI offset mismatch:
|
|
1733
|
-
Expected text: "${exactPreview}"
|
|
1734
|
-
Found at AI offset (${aiStart}-${aiEnd}): "${foundPreview}"
|
|
1735
|
-
Attempting multi-strategy search...`
|
|
1736
|
-
);
|
|
1737
1711
|
const match = findBestTextMatch(content, exact, aiStart);
|
|
1738
1712
|
if (!match) {
|
|
1739
|
-
const exactLong = exact.length > 100 ? exact.substring(0, 100) + "..." : exact;
|
|
1740
|
-
console.error(
|
|
1741
|
-
`[validateAndCorrectOffsets] \u2717 No acceptable match found:
|
|
1742
|
-
AI offsets: start=${aiStart}, end=${aiEnd}
|
|
1743
|
-
AI text: "${exactLong}"
|
|
1744
|
-
Text at AI offset: "${foundPreview}"
|
|
1745
|
-
All search strategies (exact, case-insensitive, fuzzy) failed.
|
|
1746
|
-
This suggests the AI hallucinated text that doesn't exist in the document.`
|
|
1747
|
-
);
|
|
1748
1713
|
throw new Error(
|
|
1749
1714
|
"Cannot find acceptable match for text in content. All search strategies failed. Text may be hallucinated."
|
|
1750
1715
|
);
|
|
1751
1716
|
}
|
|
1752
1717
|
const actualText = content.substring(match.start, match.end);
|
|
1753
|
-
const actualPreview = actualText.length > 50 ? actualText.substring(0, 50) + "..." : actualText;
|
|
1754
|
-
const offsetDelta = match.start - aiStart;
|
|
1755
|
-
const matchSymbol = match.matchQuality === "exact" ? "\u2713" : match.matchQuality === "case-insensitive" ? "\u2248" : "~";
|
|
1756
|
-
console.warn(
|
|
1757
|
-
`[validateAndCorrectOffsets] ${matchSymbol} Found ${match.matchQuality} match:
|
|
1758
|
-
AI offsets: start=${aiStart}, end=${aiEnd}
|
|
1759
|
-
Corrected: start=${match.start}, end=${match.end}
|
|
1760
|
-
Offset delta: ${offsetDelta} characters
|
|
1761
|
-
Actual text: "${actualPreview}"`
|
|
1762
|
-
);
|
|
1763
|
-
if (match.matchQuality === "fuzzy") {
|
|
1764
|
-
console.warn(
|
|
1765
|
-
`[validateAndCorrectOffsets] Fuzzy match details:
|
|
1766
|
-
AI provided: "${exactPreview}"
|
|
1767
|
-
Found in doc: "${actualPreview}"
|
|
1768
|
-
Minor text differences detected - using document version`
|
|
1769
|
-
);
|
|
1770
|
-
}
|
|
1771
1718
|
const context = extractContext(content, match.start, match.end);
|
|
1772
1719
|
return {
|
|
1773
1720
|
start: match.start,
|
|
@@ -1869,6 +1816,6 @@ function getMimeCategory(mimeType) {
|
|
|
1869
1816
|
return "unsupported";
|
|
1870
1817
|
}
|
|
1871
1818
|
|
|
1872
|
-
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 };
|
|
1819
|
+
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 };
|
|
1873
1820
|
//# sourceMappingURL=index.js.map
|
|
1874
1821
|
//# sourceMappingURL=index.js.map
|