@semiont/api-client 0.2.46 → 0.3.0

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,5 @@
1
1
  import * as _semiont_core from '@semiont/core';
2
- import { EntityType, BaseUrl, Logger, ResourceUri, AccessToken, AnnotationUri, components, Email, paths, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, ResourceAnnotationUri, Motivation, UserDID, JobId, EventBus, ResourceId, AnnotationId, UserId } from '@semiont/core';
2
+ import { EntityType, GatheredContext, BaseUrl, Logger, ResourceId, AccessToken, AnnotationId, components, Email, paths, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, Motivation, UserDID, JobId, EventBus, UserId } from '@semiont/core';
3
3
  export { Logger, Selector, getFragmentSelector, getSvgSelector, getTextPositionSelector, validateSvgMarkup } from '@semiont/core';
4
4
  export { BoundingBox, ContentCache, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, MatchQuality, Point, SvgSelector, TextPosition, TextPositionSelector, TextQuoteSelector, ValidatedAnnotation, ValidationFailure, ValidationResult, ValidationSuccess, buildContentCache, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getTargetSelector, getTargetSource, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, verifyPosition } from './utils/index.js';
5
5
 
@@ -185,6 +185,15 @@ interface AnnotateTagsStreamRequest {
185
185
  schemaId: string;
186
186
  categories: string[];
187
187
  }
188
+ /**
189
+ * Request body for bind search stream
190
+ */
191
+ interface BindSearchStreamRequest {
192
+ referenceId: string;
193
+ context: GatheredContext;
194
+ limit?: number;
195
+ useSemanticScoring?: boolean;
196
+ }
188
197
  /**
189
198
  * SSE Client configuration
190
199
  */
@@ -233,14 +242,6 @@ declare class SSEClient {
233
242
  * Get common headers for SSE requests
234
243
  */
235
244
  private getHeaders;
236
- /**
237
- * Extract resource ID from URI
238
- *
239
- * Handles both full URIs and plain IDs:
240
- * - 'http://localhost:4000/resources/doc-123' -> 'doc-123'
241
- * - 'doc-123' -> 'doc-123'
242
- */
243
- private extractId;
244
245
  /**
245
246
  * Detect annotations in a resource (streaming)
246
247
  *
@@ -276,7 +277,7 @@ declare class SSEClient {
276
277
  * stream.close();
277
278
  * ```
278
279
  */
279
- annotateReferences(resourceId: ResourceUri, request: AnnotateReferencesStreamRequest, options: SSERequestOptions): SSEStream;
280
+ annotateReferences(resourceId: ResourceId, request: AnnotateReferencesStreamRequest, options: SSERequestOptions): SSEStream;
280
281
  /**
281
282
  * Generate resource from annotation (streaming)
282
283
  *
@@ -314,7 +315,7 @@ declare class SSEClient {
314
315
  * stream.close();
315
316
  * ```
316
317
  */
317
- yieldResourceFromAnnotation(resourceId: ResourceUri, annotationId: AnnotationUri, request: YieldResourceStreamRequest, options: SSERequestOptions): SSEStream;
318
+ yieldResourceFromAnnotation(resourceId: ResourceId, annotationId: AnnotationId, request: YieldResourceStreamRequest, options: SSERequestOptions): SSEStream;
318
319
  /**
319
320
  * Detect highlights in a resource (streaming)
320
321
  *
@@ -350,7 +351,7 @@ declare class SSEClient {
350
351
  * stream.close();
351
352
  * ```
352
353
  */
353
- annotateHighlights(resourceId: ResourceUri, request: AnnotateHighlightsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
354
+ annotateHighlights(resourceId: ResourceId, request: AnnotateHighlightsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
354
355
  /**
355
356
  * Detect assessments in a resource (streaming)
356
357
  *
@@ -386,7 +387,7 @@ declare class SSEClient {
386
387
  * stream.close();
387
388
  * ```
388
389
  */
389
- annotateAssessments(resourceId: ResourceUri, request: AnnotateAssessmentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
390
+ annotateAssessments(resourceId: ResourceId, request: AnnotateAssessmentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
390
391
  /**
391
392
  * Detect comments in a resource (streaming)
392
393
  *
@@ -426,7 +427,7 @@ declare class SSEClient {
426
427
  * stream.close();
427
428
  * ```
428
429
  */
429
- annotateComments(resourceId: ResourceUri, request: AnnotateCommentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
430
+ annotateComments(resourceId: ResourceId, request: AnnotateCommentsStreamRequest | undefined, options: SSERequestOptions): SSEStream;
430
431
  /**
431
432
  * Detect tags in a resource (streaming)
432
433
  *
@@ -467,7 +468,19 @@ declare class SSEClient {
467
468
  * stream.close();
468
469
  * ```
469
470
  */
470
- annotateTags(resourceId: ResourceUri, request: AnnotateTagsStreamRequest, options: SSERequestOptions): SSEStream;
471
+ annotateTags(resourceId: ResourceId, request: AnnotateTagsStreamRequest, options: SSERequestOptions): SSEStream;
472
+ /**
473
+ * Search for binding candidates (streaming)
474
+ *
475
+ * Bridges bind:search-requested to the backend Binder actor via SSE.
476
+ * Results emit as bind:search-results on the browser EventBus.
477
+ *
478
+ * @param resourceId - Resource the annotation belongs to
479
+ * @param request - Search configuration (referenceId, context, limit)
480
+ * @param options - Request options (auth token, eventBus)
481
+ * @returns SSE stream controller
482
+ */
483
+ bindSearch(resourceId: ResourceId, request: BindSearchStreamRequest, options: SSERequestOptions): SSEStream;
471
484
  /**
472
485
  * Subscribe to resource events (long-lived stream)
473
486
  *
@@ -502,7 +515,7 @@ declare class SSEClient {
502
515
  * stream.close();
503
516
  * ```
504
517
  */
505
- resourceEvents(resourceId: ResourceUri, options: SSERequestOptions & {
518
+ resourceEvents(resourceId: ResourceId, options: SSERequestOptions & {
506
519
  onConnected?: () => void;
507
520
  }): SSEStream;
508
521
  /**
@@ -652,7 +665,7 @@ declare class SemiontApiClient {
652
665
  }, options?: RequestOptions): Promise<{
653
666
  resourceId: string;
654
667
  }>;
655
- getResource(resourceUri: ResourceUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}']['get']>>;
668
+ getResource(id: ResourceId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}']['get']>>;
656
669
  /**
657
670
  * Get resource representation using W3C content negotiation
658
671
  * Returns raw binary content (images, PDFs, text, etc.) with content type
@@ -675,7 +688,7 @@ declare class SemiontApiClient {
675
688
  * const { data, contentType } = await client.getResourceRepresentation(rUri, { accept: 'application/pdf', auth: token });
676
689
  * ```
677
690
  */
678
- getResourceRepresentation(resourceUri: ResourceUri, options?: {
691
+ getResourceRepresentation(id: ResourceId, options?: {
679
692
  accept?: ContentFormat;
680
693
  auth?: AccessToken;
681
694
  }): Promise<{
@@ -718,7 +731,7 @@ declare class SemiontApiClient {
718
731
  * }
719
732
  * ```
720
733
  */
721
- getResourceRepresentationStream(resourceUri: ResourceUri, options?: {
734
+ getResourceRepresentationStream(id: ResourceId, options?: {
722
735
  accept?: ContentFormat;
723
736
  auth?: AccessToken;
724
737
  }): Promise<{
@@ -726,32 +739,32 @@ declare class SemiontApiClient {
726
739
  contentType: string;
727
740
  }>;
728
741
  listResources(limit?: number, archived?: boolean, query?: SearchQuery, options?: RequestOptions): Promise<ResponseContent<paths['/resources']['get']>>;
729
- updateResource(resourceUri: ResourceUri, data: RequestContent<paths['/resources/{id}']['patch']>, options?: RequestOptions): Promise<void>;
730
- getResourceEvents(resourceUri: ResourceUri, options?: RequestOptions): Promise<{
742
+ updateResource(id: ResourceId, data: RequestContent<paths['/resources/{id}']['patch']>, options?: RequestOptions): Promise<void>;
743
+ getResourceEvents(id: ResourceId, options?: RequestOptions): Promise<{
731
744
  events: any[];
732
745
  }>;
733
- getResourceAnnotations(resourceUri: ResourceUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
734
- getAnnotationLLMContext(resourceUri: ResourceUri, annotationId: string, options?: {
746
+ getResourceAnnotations(id: ResourceId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
747
+ getAnnotationLLMContext(resourceId: ResourceId, annotationId: AnnotationId, options?: {
735
748
  contextWindow?: number;
736
749
  auth?: AccessToken;
737
750
  }): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}/llm-context']['get']>>;
738
- getResourceReferencedBy(resourceUri: ResourceUri, options?: RequestOptions): Promise<{
751
+ getResourceReferencedBy(id: ResourceId, options?: RequestOptions): Promise<{
739
752
  referencedBy: any[];
740
753
  }>;
741
- generateCloneToken(resourceUri: ResourceUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/clone-with-token']['post']>>;
754
+ generateCloneToken(id: ResourceId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/clone-with-token']['post']>>;
742
755
  getResourceByToken(token: CloneToken, options?: RequestOptions): Promise<ResponseContent<paths['/api/clone-tokens/{token}']['get']>>;
743
756
  createResourceFromToken(data: RequestContent<paths['/api/clone-tokens/create-resource']['post']>, options?: RequestOptions): Promise<{
744
757
  resourceId: string;
745
758
  }>;
746
- createAnnotation(resourceUri: ResourceUri, data: RequestContent<paths['/resources/{id}/annotations']['post']>, options?: RequestOptions): Promise<{
759
+ createAnnotation(id: ResourceId, data: RequestContent<paths['/resources/{id}/annotations']['post']>, options?: RequestOptions): Promise<{
747
760
  annotationId: string;
748
761
  }>;
749
- getAnnotation(annotationUri: AnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/annotations/{id}']['get']>>;
750
- getResourceAnnotation(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}']['get']>>;
751
- listAnnotations(resourceUri: ResourceUri, motivation?: Motivation, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
752
- deleteAnnotation(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<void>;
753
- updateAnnotationBody(annotationUri: ResourceAnnotationUri, data: RequestContent<paths['/resources/{resourceId}/annotations/{annotationId}/body']['put']>, options?: RequestOptions): Promise<void>;
754
- getAnnotationHistory(annotationUri: ResourceAnnotationUri, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}/history']['get']>>;
762
+ getAnnotation(id: AnnotationId, options?: RequestOptions): Promise<ResponseContent<paths['/annotations/{id}']['get']>>;
763
+ getResourceAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}']['get']>>;
764
+ listAnnotations(id: ResourceId, motivation?: Motivation, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{id}/annotations']['get']>>;
765
+ deleteAnnotation(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<void>;
766
+ updateAnnotationBody(resourceId: ResourceId, annotationId: AnnotationId, data: RequestContent<paths['/resources/{resourceId}/annotations/{annotationId}/body']['put']>, options?: RequestOptions): Promise<void>;
767
+ getAnnotationHistory(resourceId: ResourceId, annotationId: AnnotationId, options?: RequestOptions): Promise<ResponseContent<paths['/resources/{resourceId}/annotations/{annotationId}/history']['get']>>;
755
768
  addEntityType(type: EntityType, options?: RequestOptions): Promise<void>;
756
769
  addEntityTypesBulk(types: EntityType[], options?: RequestOptions): Promise<void>;
757
770
  listEntityTypes(options?: RequestOptions): Promise<ResponseContent<paths['/api/entity-types']['get']>>;
@@ -763,6 +776,48 @@ declare class SemiontApiClient {
763
776
  */
764
777
  updateUser(id: UserDID, data: RequestContent<paths['/api/admin/users/{id}']['patch']>, options?: RequestOptions): Promise<ResponseContent<paths['/api/admin/users/{id}']['patch']>>;
765
778
  getOAuthConfig(options?: RequestOptions): Promise<ResponseContent<paths['/api/admin/oauth/config']['get']>>;
779
+ /**
780
+ * Create a backup of the knowledge base. Returns raw Response for streaming download.
781
+ * Caller should use response.blob() to trigger a file download.
782
+ */
783
+ backupKnowledgeBase(options?: RequestOptions): Promise<Response>;
784
+ /**
785
+ * Restore knowledge base from a backup file. Parses SSE progress events and calls onProgress.
786
+ * Returns the final SSE event (phase: 'complete' or 'error').
787
+ */
788
+ restoreKnowledgeBase(file: File, options?: RequestOptions & {
789
+ onProgress?: (event: {
790
+ phase: string;
791
+ message?: string;
792
+ result?: Record<string, unknown>;
793
+ }) => void;
794
+ }): Promise<{
795
+ phase: string;
796
+ message?: string;
797
+ result?: Record<string, unknown>;
798
+ }>;
799
+ /**
800
+ * Export the knowledge base as a JSON-LD Linked Data archive. Returns raw Response for streaming download.
801
+ * Caller should use response.blob() to trigger a file download.
802
+ */
803
+ exportKnowledgeBase(params?: {
804
+ includeArchived?: boolean;
805
+ }, options?: RequestOptions): Promise<Response>;
806
+ /**
807
+ * Import a JSON-LD Linked Data archive into the knowledge base. Parses SSE progress events and calls onProgress.
808
+ * Returns the final SSE event (phase: 'complete' or 'error').
809
+ */
810
+ importKnowledgeBase(file: File, options?: RequestOptions & {
811
+ onProgress?: (event: {
812
+ phase: string;
813
+ message?: string;
814
+ result?: Record<string, unknown>;
815
+ }) => void;
816
+ }): Promise<{
817
+ phase: string;
818
+ message?: string;
819
+ result?: Record<string, unknown>;
820
+ }>;
766
821
  getJobStatus(id: JobId, options?: RequestOptions): Promise<ResponseContent<paths['/api/jobs/{id}']['get']>>;
767
822
  /**
768
823
  * Poll a job until it completes or fails
@@ -776,7 +831,7 @@ declare class SemiontApiClient {
776
831
  onProgress?: (status: ResponseContent<paths['/api/jobs/{id}']['get']>) => void;
777
832
  auth?: AccessToken;
778
833
  }): Promise<ResponseContent<paths['/api/jobs/{id}']['get']>>;
779
- getResourceLLMContext(resourceUri: ResourceUri, options?: {
834
+ getResourceLLMContext(id: ResourceId, options?: {
780
835
  depth?: number;
781
836
  maxResources?: number;
782
837
  includeContent?: boolean;
@@ -844,12 +899,12 @@ declare class EventBusClient {
844
899
  resourceId: ResourceId;
845
900
  }>;
846
901
  getJobStatus(jobId: JobId): Promise<components['schemas']['JobStatusResponse']>;
847
- getAnnotationLLMContext(annotationUri: string, resourceUri: string, options?: {
902
+ getAnnotationLLMContext(annotationId: AnnotationId, resourceId: ResourceId, options?: {
848
903
  includeSourceContext?: boolean;
849
904
  includeTargetContext?: boolean;
850
905
  contextWindow?: number;
851
906
  }): Promise<components['schemas']['AnnotationLLMContextResponse']>;
852
- getResourceLLMContext(resourceUri: string, options: {
907
+ getResourceLLMContext(resourceId: ResourceId, options: {
853
908
  depth: number;
854
909
  maxResources: number;
855
910
  includeContent: boolean;
@@ -896,4 +951,4 @@ declare function isPdfMimeType(mimeType: string): boolean;
896
951
  type MimeCategory = 'text' | 'image' | 'unsupported';
897
952
  declare function getMimeCategory(mimeType: string): MimeCategory;
898
953
 
899
- export { APIError, type AnnotateReferencesStreamRequest, EventBusClient, type MimeCategory, type ReferenceDetectionProgress, type RequestOptions, SSEClient, type SSEClientConfig, type SSEStream, type SSEStreamConnected, SSE_STREAM_CONNECTED, SemiontApiClient, type SemiontApiClientConfig, type YieldProgress, type YieldResourceStreamRequest, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };
954
+ export { APIError, type AnnotateReferencesStreamRequest, type BindSearchStreamRequest, EventBusClient, type MimeCategory, type ReferenceDetectionProgress, type RequestOptions, SSEClient, type SSEClientConfig, type SSEStream, type SSEStreamConnected, SSE_STREAM_CONNECTED, SemiontApiClient, type SemiontApiClientConfig, type YieldProgress, type YieldResourceStreamRequest, getExtensionForMimeType, getMimeCategory, isImageMimeType, isPdfMimeType, isTextMimeType };