@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 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/detect-annotations-stream
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
- * Logger interface for API client observability
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
- interface Logger {
158
- debug(message: string, meta?: any): void;
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 detection stream
144
+ * Request body for reference annotation stream
166
145
  */
167
- interface DetectReferencesStreamRequest {
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 detection stream
156
+ * Request body for highlight annotation stream
178
157
  */
179
- interface DetectHighlightsStreamRequest {
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 detection stream
164
+ * Request body for assessment annotation stream
186
165
  */
187
- interface DetectAssessmentsStreamRequest {
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 detection stream
173
+ * Request body for comment annotation stream
195
174
  */
196
- interface DetectCommentsStreamRequest {
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 detection stream
182
+ * Request body for tag annotation stream
204
183
  */
205
- interface DetectTagsStreamRequest {
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.detectReferences(
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.detectReferences(
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
- detectReferences(resourceId: ResourceUri, request: DetectReferencesStreamRequest, options?: SSERequestOptions): SSEStream;
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?: SSERequestOptions): SSEStream;
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 detection progress via Server-Sent Events.
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.detectHighlights(
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
- detectHighlights(resourceId: ResourceUri, request?: DetectHighlightsStreamRequest, options?: SSERequestOptions): SSEStream;
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 detection progress via Server-Sent Events.
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.detectAssessments(
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
- detectAssessments(resourceId: ResourceUri, request?: DetectAssessmentsStreamRequest, options?: SSERequestOptions): SSEStream;
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 detection progress via Server-Sent Events.
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.detectComments(
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
- detectComments(resourceId: ResourceUri, request?: DetectCommentsStreamRequest, options?: SSERequestOptions): SSEStream;
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 detection progress via Server-Sent Events.
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.detectTags(
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
- detectTags(resourceId: ResourceUri, request: DetectTagsStreamRequest, options?: SSERequestOptions): SSEStream;
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?: SSERequestOptions & {
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 DetectReferencesStreamRequest, type GenerateResourceStreamRequest, type GenerationProgress, type Logger, type MimeCategory, type ReferenceDetectionProgress, type RequestOptions, SSEClient, type SSEClientConfig, type SSEStream, SemiontApiClient, type SemiontApiClientConfig, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };
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
- buffer += decoder.decode(value, { stream: true });
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 (config.customEventHandler) {
121
- const handler = customHandlers.get(eventType);
122
- if (handler) {
123
- handler(parsed);
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
- if (config.eventBus && config.eventPrefix) {
128
- if (config.progressEvents.includes(eventType)) {
129
- config.eventBus.get(`${config.eventPrefix}:progress`).next(parsed);
130
- }
131
- if (config.completeEvent && eventType === config.completeEvent) {
132
- config.eventBus.get(`${config.eventPrefix}:complete`).next(parsed);
133
- closed = true;
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.detectReferences(
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
- detectReferences(resourceId, request, options) {
214
+ annotateReferences(resourceId, request, options) {
227
215
  const id = this.extractId(resourceId);
228
- const url = `${this.baseUrl}/resources/${id}/detect-annotations-stream`;
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?.auth),
221
+ headers: this.getHeaders(options.auth),
234
222
  body: JSON.stringify(request)
235
223
  },
236
224
  {
237
- progressEvents: ["reference-detection-started", "reference-detection-progress"],
238
- completeEvent: "reference-detection-complete",
239
- errorEvent: "reference-detection-error",
240
- eventBus: options?.eventBus,
241
- eventPrefix: "detection"
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?.auth),
279
+ headers: this.getHeaders(options.auth),
292
280
  body: JSON.stringify(request)
293
281
  },
294
282
  {
295
- progressEvents: ["generation-started", "generation-progress"],
296
- completeEvent: "generation-complete",
297
- errorEvent: "generation-error",
298
- eventBus: options?.eventBus,
299
- eventPrefix: "generation"
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 detection progress via Server-Sent Events.
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.detectHighlights(
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
- detectHighlights(resourceId, request = {}, options) {
327
+ annotateHighlights(resourceId, request = {}, options) {
340
328
  const id = this.extractId(resourceId);
341
- const url = `${this.baseUrl}/resources/${id}/detect-highlights-stream`;
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?.auth),
334
+ headers: this.getHeaders(options.auth),
347
335
  body: JSON.stringify(request)
348
336
  },
349
337
  {
350
- progressEvents: ["highlight-detection-started", "highlight-detection-progress"],
351
- completeEvent: "highlight-detection-complete",
352
- errorEvent: "highlight-detection-error",
353
- eventBus: options?.eventBus,
354
- eventPrefix: "detection"
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 detection progress via Server-Sent Events.
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.detectAssessments(
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
- detectAssessments(resourceId, request = {}, options) {
382
+ annotateAssessments(resourceId, request = {}, options) {
395
383
  const id = this.extractId(resourceId);
396
- const url = `${this.baseUrl}/resources/${id}/detect-assessments-stream`;
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?.auth),
389
+ headers: this.getHeaders(options.auth),
402
390
  body: JSON.stringify(request)
403
391
  },
404
392
  {
405
- progressEvents: ["assessment-detection-started", "assessment-detection-progress"],
406
- completeEvent: "assessment-detection-complete",
407
- errorEvent: "assessment-detection-error",
408
- eventBus: options?.eventBus,
409
- eventPrefix: "detection"
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 detection progress via Server-Sent Events.
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.detectComments(
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
- detectComments(resourceId, request = {}, options) {
441
+ annotateComments(resourceId, request = {}, options) {
454
442
  const id = this.extractId(resourceId);
455
- const url = `${this.baseUrl}/resources/${id}/detect-comments-stream`;
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?.auth),
448
+ headers: this.getHeaders(options.auth),
461
449
  body: JSON.stringify(request)
462
450
  },
463
451
  {
464
- progressEvents: ["comment-detection-started", "comment-detection-progress"],
465
- completeEvent: "comment-detection-complete",
466
- errorEvent: "comment-detection-error",
467
- eventBus: options?.eventBus,
468
- eventPrefix: "detection"
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 detection progress via Server-Sent Events.
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.detectTags(
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
- detectTags(resourceId, request, options) {
501
+ annotateTags(resourceId, request, options) {
514
502
  const id = this.extractId(resourceId);
515
- const url = `${this.baseUrl}/resources/${id}/detect-tags-stream`;
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?.auth),
508
+ headers: this.getHeaders(options.auth),
521
509
  body: JSON.stringify(request)
522
510
  },
523
511
  {
524
- progressEvents: ["tag-detection-started", "tag-detection-progress"],
525
- completeEvent: "tag-detection-complete",
526
- errorEvent: "tag-detection-error",
527
- eventBus: options?.eventBus,
528
- eventPrefix: "detection"
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?.auth)
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
- // Long-lived stream - no completion
581
- errorEvent: "error",
582
- // Generic error event
583
- customEventHandler: true
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?.onConnected) {
589
- stream.on?.("stream-connected", options.onConnected);
590
- } else {
591
- stream.on?.("stream-connected", () => {
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